Skip to content

feat(agent-audit): per-rule allow/ask/deny ledger across Claude Code, Codex, Cursor CLI and Gemini CLI, with a baseline - #1121

Merged
sandstream merged 3 commits into
mainfrom
claude/web-kit-status-sync-p6fg9a-protected-agent-rule-ledger
Nov 27, 2026
Merged

sandstream merged 3 commits into
mainfrom
claude/web-kit-status-sync-p6fg9a-protected-agent-rule-ledger

Conversation

@sandstream

@sandstream sandstream commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Protected — owner merges. The branch is under the protected- prefix; it changes no protected path (src/agent-audit.ts is untouched), but it adds a new audit and a new acceptance command, which the owner approved as a feature.

Found by kit-research#239 (prismor-always-allowed-rules-vs-kit), Measurement §1 and §2 and the Innovation section. A reply to a permission prompt can add allow rules and remove deny rules in a settings file, and the change outlives whoever sent it. kit read Claude Code's allow rules only as trifecta legs, never listed one, read no Codex, Cursor or Gemini rule, and removing five of kit's own deny rules changed no row of kit check.

What changes

kit agent-audit lists one row per saved rule: harness, scope (user, project, local or managed), file, rule, kind (allow, ask, deny, or unparsed), class, and first-seen date. --json adds rules and ledger: { read, notCovered }.

Harness Store read Kinds
Claude Code ~/.claude/settings.json (or $CLAUDE_CONFIG_DIR), .claude/settings.json, .claude/settings.local.json, managed managed-settings.json + managed-settings.d/*.json in /etc/claude-code, /Library/Application Support/ClaudeCode, C:\Program Files\ClaudeCode allow / ask / deny
Codex prefix_rule(...) in $CODEX_HOME/rules/*.rules and .codex/rules/*.rules allow / prompt→ask / forbidden→deny; allow is marked unsandboxed
Cursor CLI ~/.cursor/cli-config.json, .cursor/cli.json allow / deny
Gemini CLI tools.allowed, tools.exclude, tools.autoAccept / autoAccept, general.defaultApprovalMode: auto_edit in user, project and system settings (per OS) allow / deny
  • Codex rules are parsed as text, never evaluated (src/codex-rules.ts). A statement is accepted only as a literal prefix_rule(...) with keyword arguments that are string literals or lists of them. A variable, load(), concatenation, positional argument, unknown keyword or triple-quoted string becomes an unparsed row and a warning. A settings file that is not a JSON object, or a non-string rule entry, does the same. Nothing is dropped, so nothing unreadable counts as narrow.

  • The class is kit's existing classification, not a new score. grantClass() in src/agent-trifecta.ts runs legsOf and writeGrants on the rule, mapped to Claude Code's grant shape (Shell(x) → Bash(x:*), run_shell_command(x) → Bash(x:*), a Codex prefix → Bash(prefix:*)). So Read(~/.ssh/**) is private data, a Codex prefix_rule(pattern=["bash"]) is all three legs, writes, unsandboxed, and a curl to an internal host is untrusted input, way out.

  • The baseline is ~/.kit/agent-rules.json, next to user-surfaces.json under the trail-guarded ~/.kit. It is recorded on the first run (not in read-only mode). After that, on every run of kit agent-audit and kit check:

    • a removed deny or ask rule is reported as warn with severity high;
    • a new allow rule is reported as warn with severity medium.

    Both stay until a person runs kit agent-audit --accept-rules. trail-guard refuses that command from an agent, the same way it refuses --accept-user-surfaces. First-seen dates are kept in the same file, because agents store no dates.

  • An allow rule outside Claude Code whose class is all three legs gets a warning. Claude Code's are already reported by the trifecta row.

  • Trifecta ✓ text. It used to say "no agent holds…". It now says "no Claude Code session or subagent holds…", names the files it read, and points to the ledger for the other harnesses.

Not covered, printed in the output: Antigravity (Prismor's store is not verified against Google's docs, and kit has no fixture for it), Copilot CLI (docs not read), Amazon Q, AWS Kiro, Factory Droid, Augment, OpenCode, Cline, Continue, Codex team and system config layers, Gemini CLI policy files, and Claude Code MDM, registry and server-managed policy.

Before / after

scripts/ledger-demo.sh (scratch): .claude/settings.json denies Read(~/.ssh/**) and Bash(git push --force:*), .codex/rules/default.rules allows bash, and ~/.cursor/cli-config.json allows Shell(bash). Run 2 removes the ssh deny and adds Read(~/.ssh/**) to settings.local.json.

Before (origin/main), both runs:

✓ lethal trifecta  no agent holds untrusted input, private data and a way out together in the declared grants (1 unit(s) checked). ...

After, run 2:

✓ lethal trifecta  no Claude Code session or subagent holds untrusted input, private data and a way out together in its declared grants (1 unit(s) checked: ~/.claude/settings.json, .claude/settings.json, .claude/settings.local.json and the agents in .claude/agents). ...
! agent rules: allow rules that hold all three legs  Codex .codex/rules/default.rules: prefix_rule: bash; Cursor CLI ~/.cursor/cli-config.json: Shell(bash). ...
! agent rules since last accepted: deny or ask rules removed  1 rule(s) that blocked or prompted are gone: deny Claude Code .claude/settings.json: Read(~/.ssh/**)
! agent rules since last accepted: new allow rules  1 allow rule(s) not in the accepted baseline: Claude Code .claude/settings.local.json: Read(~/.ssh/**) [private data]
agent rules (4) read from Claude Code, Codex, Cursor CLI, Gemini CLI
  deny     Claude Code project .claude/settings.json  Bash(git push --force:*)  [narrow]  first seen 2026-11-27
  allow    Claude Code local   .claude/settings.local.json  Read(~/.ssh/**)  [private data]  first seen 2026-11-27
  allow    Codex       project .codex/rules/default.rules  prefix_rule: bash  [all three legs, writes, unsandboxed]  first seen 2026-11-27
  allow    Cursor CLI  user    ~/.cursor/cli-config.json  Shell(bash)  [all three legs, writes]  first seen 2026-11-27
not covered: Antigravity (...), Copilot CLI (...), Amazon Q, ...

Tests: src/agent-rule-ledger.test.ts, src/agent-rule-sources.test.ts and src/codex-rules.test.ts. They reuse the note's fixtures. On main they fail with ERR_MODULE_NOT_FOUND: dist/agent-rule-ledger.js; on this branch, 11/11 pass.

Cross-platform

  • Paths are built with node:path. The managed and system directories per OS come from claudeManagedDir / geminiSystemFiles (win32/posix join) and are unit-tested for Linux, macOS and Windows.
  • The baseline is written with mode 0o600, which is ignored on Windows, the same as user-surfaces.json.
  • macOS is unverified: no CI job runs it, and the /Library/Application Support/... paths are checked only as strings.

Choices for the owner

  • kit check reports the drift, unparsed and three-legs rows too, through check-agent-config.ts. It does not show the per-rule listing.
  • The ledger does not yet check that KIT_DENY_RULES are present where agent-config wrote them (Plan step 3), and it does not change gate-self-edit (Plan step 4).
  • The docs/FEATURES.md Codex-allowlist sentence is left to docs: Codex has a command allowlist (prefix_rule) #1112, to avoid a conflict.
  • Flag contract: agent-audit now has an explicit entry in contracts/command-flags.json: --accept-rules, --accept-user-surfaces and --json. The fallback scan had been giving --accept-rules to every handler in commands/info.ts (status, health, supply-chain), and that pushed the generated src/flag-surface.ts past its 700-line cap. As a result, agent-audit no longer accepts --attest, --mode and --no-auto-install. It picked those up from sibling handlers and never read them.

Generated by Claude Code

kit agent-audit now lists every saved permission rule it can read, one row
per rule (harness, scope, file, rule, kind, class, first-seen date), for
Claude Code (user, project, local, managed), Codex prefix_rule (user and
project, parsed as text and never evaluated), Cursor CLI and Gemini CLI.
The class comes from the trifecta tables (grantClass). ~/.kit/agent-rules.json
records the accepted rules; new allow rules and removed deny or ask rules
are reported by agent-audit and kit check until a person runs
`kit agent-audit --accept-rules`, which trail-guard refuses from an agent.
Unparsed rules are reported, never dropped. --json adds `rules`.

The trifecta pass row now names the Claude Code files it read instead of
"no agent holds ...", and FEATURES.md no longer says Codex has no command
allowlist.

Found by kit-research#239 (prismor-always-allowed-rules-vs-kit).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Docker image built, scanned, and smoke-tested in CI. The PR image is local to this run and is not published.

The fallback flag scan gave --accept-rules to every handler in
commands/info.ts (status, health, supply-chain), which pushed the generated
src/flag-surface.ts past its 700-line cap. agent-audit now declares its own
flags (--accept-rules, --accept-user-surfaces, --json) in
contracts/command-flags.json, and info.ts reads the acceptance flag through
a constant, so the sibling handlers keep the flags they had. --attest,
--mode and --no-auto-install were picked up from siblings and never read by
agent-audit. The ledger test now runs --accept-rules through the CLI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Docker image built, scanned, and smoke-tested in CI. The PR image is local to this run and is not published.

@sandstream-kit-reviewer sandstream-kit-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kit review gate at e0790c1620ba: gates passed. All 33 checks passed on this commit, no file is in a protected class, 17 files and 1320 lines changed. This approval is deterministic; it does not judge what the change is for.

@sandstream
sandstream merged commit 8e03094 into main Nov 27, 2026
34 checks passed
@sandstream
sandstream deleted the claude/web-kit-status-sync-p6fg9a-protected-agent-rule-ledger branch November 27, 2026 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants