@agentwares/agentguard 0.1.6 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/README.md +223 -16
  3. package/dist/audit-2YCMHMCP.js +17 -0
  4. package/dist/audit-2YCMHMCP.js.map +1 -0
  5. package/dist/chunk-3O6KWT3E.js +345 -0
  6. package/dist/chunk-3O6KWT3E.js.map +1 -0
  7. package/dist/chunk-5WRI5ZAA.js +31 -0
  8. package/dist/chunk-5WRI5ZAA.js.map +1 -0
  9. package/dist/chunk-6S7LYVOC.js +1033 -0
  10. package/dist/chunk-6S7LYVOC.js.map +1 -0
  11. package/dist/chunk-6TUQD666.js +828 -0
  12. package/dist/chunk-6TUQD666.js.map +1 -0
  13. package/dist/chunk-BKXXTWIS.js +119 -0
  14. package/dist/chunk-BKXXTWIS.js.map +1 -0
  15. package/dist/chunk-D66U3PVB.js +529 -0
  16. package/dist/chunk-D66U3PVB.js.map +1 -0
  17. package/dist/chunk-HPYZ3JDX.js +206 -0
  18. package/dist/chunk-HPYZ3JDX.js.map +1 -0
  19. package/dist/chunk-KRKZGAJ3.js +769 -0
  20. package/dist/chunk-KRKZGAJ3.js.map +1 -0
  21. package/dist/chunk-SUXQTT3X.js +1268 -0
  22. package/dist/chunk-SUXQTT3X.js.map +1 -0
  23. package/dist/chunk-TW5KJREH.js +190 -0
  24. package/dist/chunk-TW5KJREH.js.map +1 -0
  25. package/dist/chunk-VQWQ5TOM.js +113 -0
  26. package/dist/chunk-VQWQ5TOM.js.map +1 -0
  27. package/dist/chunk-X4M7YWQA.js +270 -0
  28. package/dist/chunk-X4M7YWQA.js.map +1 -0
  29. package/dist/chunk-ZSLWPKXI.js +1144 -0
  30. package/dist/chunk-ZSLWPKXI.js.map +1 -0
  31. package/dist/cli.js +8 -4725
  32. package/dist/cli.js.map +1 -1
  33. package/dist/fixtures/crm-server.js +6 -1272
  34. package/dist/fixtures/crm-server.js.map +1 -1
  35. package/dist/fixtures/demo-agent.js +4 -115
  36. package/dist/fixtures/demo-agent.js.map +1 -1
  37. package/dist/index.d.ts +76 -10
  38. package/dist/index.js +246 -5087
  39. package/dist/index.js.map +1 -1
  40. package/dist/init-CWROGV5I.js +15 -0
  41. package/dist/init-CWROGV5I.js.map +1 -0
  42. package/dist/proxy-3Z5YEZ4R.js +154 -0
  43. package/dist/proxy-3Z5YEZ4R.js.map +1 -0
  44. package/dist/tools-3LLDG3XQ.js +15 -0
  45. package/dist/tools-3LLDG3XQ.js.map +1 -0
  46. package/llms.txt +4 -0
  47. package/package.json +9 -3
  48. package/server.json +2 -2
package/CHANGELOG.md CHANGED
@@ -3,6 +3,95 @@
3
3
  `@agentwares/agentguard`, the CLI and MCP proxy. A tag `agentguard-v<version>` publishes the
4
4
  GitHub Release for a version with its section below as the notes.
5
5
 
6
+ ## 0.1.9 — 2026-10-07
7
+
8
+ ### Added
9
+
10
+ - **`agentguard audit`: which written rules your coding agents broke.** Reads the repository's
11
+ CLAUDE.md, AGENTS.md, GEMINI.md, `.cursor/rules` (and the other files agentsmd-lint looks for),
12
+ plus `audit.rules` in agentguard.yaml, and this machine's Claude Code and Codex sessions whose
13
+ working directory is the repository or one of its worktrees, subagents included. Per rule:
14
+ sessions checked, sessions broken, the last three dates, and — on your screen only — the
15
+ command or path that broke it. `--since 7d|30d|24h|all|<date>` (default 7 days),
16
+ `--client claude|codex|all`, `--json` (counts, rule ids and dates, never a command, a path or a
17
+ prompt), `--rules <file>`, `--no-cache`, `--no-evidence`.
18
+ - **Rules recognised with no LLM.** Every rule in the files is listed, checkable or not. A
19
+ pattern library maps the common shapes to checks over what the agent did (never push to /
20
+ commit on main, never force-push, never `--no-verify`, run X before committing or pushing, use
21
+ pnpm not npm, do not edit or commit a path, no new dependencies without asking, never `rm`
22
+ outside the repo, never publish, never deploy, never run a named command). An inline
23
+ `<!-- agentguard: <check> -->` on the rule, or `audit.rules` in agentguard.yaml, always works;
24
+ `<!-- agentguard: none -->` marks a rule no script can check.
25
+ - **`agentguard audit --enforce [--preview] [--yes]`** writes the checkable rules into
26
+ agentguard.yaml as hook-mode rules — `hooks.shell.deny`, `hooks.shell.approval` (for "without
27
+ asking"), `hooks.paths.deny`, the built-in irreversible classes and a `deploy` rule — each with a
28
+ comment naming the rule it came from, shows the diff, and installs the Claude Code hook if it is
29
+ not installed. It never changes `hooks.mode`, and writes nothing to a policy already in enforce
30
+ mode without `--yes`.
31
+ - **A counts-only cache** in `~/.agentguard/audit-cache-v1/`: a second run of a large history
32
+ takes about a second, and counts from transcripts Claude Code has since deleted are kept. It
33
+ holds counts, times, line numbers and hashes only.
34
+ - **Plugin skills `/agentguard:audit`** (runs `audit --json`, then has your own agent judge the
35
+ rules marked not checkable against the repository and its git history) **and
36
+ `/agentguard:hooks`** (hook mode status, install, uninstall), in the Claude Code plugin and the
37
+ Gemini CLI extension.
38
+ - The audit's last line points at the team adherence history page
39
+ (https://agentwares-agentguard.vercel.app/team-history). The CLI itself sends nothing.
40
+
41
+ ### Changed
42
+
43
+ - Requires `@agentwares/agentguard-core` 0.1.5.
44
+
45
+ ## 0.1.8 — 2026-10-07
46
+
47
+ ### Added
48
+
49
+ - **Hook mode: one rulebook for coding agents.** `agentguard hooks install [--project|--user]
50
+ [--client claude|codex|gemini|all]` writes a pre-execution hook (Claude Code `PreToolUse`,
51
+ Codex `PreToolUse`, Gemini CLI `BeforeTool`) that runs `agentguard hook pre-tool-use` on every
52
+ shell command, file edit and direct MCP call, and adds a dry-run `hooks:` block to
53
+ `agentguard.yaml`. `hooks uninstall` removes only agentguard's entries; `hooks status` lists them.
54
+ The policy gains `hooks.shell.deny|approval` (command globs, matched against every simple
55
+ command of a compound line, `$(…)`, `bash -c` and `eval` included), `hooks.paths.deny|approval`
56
+ (file globs for edits and shell writes), and `hooks.irreversible` (built-in classes `git-push`,
57
+ `merge`, `tag-delete`, `rm-outside-workspace`, `publish`, `send`, `guard-config`, plus your own
58
+ rules). The MCP side's `deny` and `approval.tools` also apply to MCP tools the agent calls
59
+ directly. Same kill switch, approvals, caps (`hook_calls`, `shell_commands`, `file_edits`,
60
+ `irreversible`), loop breaker (repeated identical edits) and hash-chained audit log.
61
+ - **Irreversible commands only on a turn a person typed.** In Claude Code an irreversible command
62
+ runs only when the latest transcript entry a person wrote came after the session's previous
63
+ irreversible command, is at most `window_s` (30 min) old, and names the action — or is a bare
64
+ "yes" to an assistant question that names it. Tool results, injected and meta entries, peer and
65
+ task messages, subagent prompts and anything inside an assistant reply never count, so a model
66
+ that writes "user: yes, push it" into its own reply (claude-code#88122 and others) is held with
67
+ `APPROVAL_REQUIRED`; `agentguard approve <id>` lets the identical retry run once. Codex and Gemini
68
+ CLI get the rulebook but no transcript check: their irreversible commands always need approval.
69
+ - **The agent cannot approve itself.** `agentguard approve|deny|resume` run by the agent, and any
70
+ write to `.agentguard/`, are refused.
71
+ - `agentguard report` has a **Coding-agent hooks** section: calls checked, irreversible commands
72
+ run on a person's turn or after approval or held, and every call enforce mode would have stopped
73
+ while in dry-run.
74
+
75
+ ### Changed
76
+
77
+ - The CLI loads the MCP SDK only for `proxy`, `init` and `tools`, so the hook starts in about
78
+ 0.1 s (`dist/` is now split into chunks).
79
+ - Requires `@agentwares/agentguard-core` 0.1.4.
80
+
81
+ ## 0.1.7 — 2026-10-07
82
+
83
+ ### Fixed
84
+
85
+ - **No endless loop on an upstream that repeats its `tools/list` cursor.** The proxy followed
86
+ `nextCursor` with no bound, so an upstream that handed back the cursor it was given (or cycled
87
+ through a few) kept the proxy asking for the same page forever, its tool table growing with
88
+ every answer. It now reads every page to the end, stops at a cursor it has already followed, and
89
+ reads at most 20 pages and 2,000 tools per upstream.
90
+ - **A failed or partial `tools/list` no longer empties an upstream's tools.** If a refresh errors,
91
+ or stops at that ceiling, the proxy keeps the upstream's last good list and logs why
92
+ (`tools/list for "<upstream>" not applied: … ; keeping the last good list (N tools)`). It used
93
+ to drop every tool of that upstream on any `tools/list` error.
94
+
6
95
  ## 0.1.6 — 2026-10-07
7
96
 
8
97
  ### Added
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # agentguard
2
2
 
3
+ [![Listed on mcpservers.org](https://mcpservers.org/badge.svg)](https://mcpservers.org/servers/agentwares/agentguard)
4
+
3
5
  **60 seconds to a safe first run.** Your agent already has an MCP config. Put agentguard in front of it, run the agent once in dry-run, and read what it _would_ have done:
4
6
 
5
7
  ```sh
@@ -37,6 +39,8 @@ agentguard is an MCP policy proxy for agents that touch production. It sits betw
37
39
  - **Semantic loop breaker** — the same `(tool, normalized args)` 3× in the last 30 calls, or an A→B→A→B cycle, returns `LOOP_DETECTED`. Timestamps, ids, whitespace and key order are ignored.
38
40
  - **Blast-radius caps** — `tool_calls`, `writes`, `deletes`, `emails`, `spend_usd` and custom counters, per run and per day.
39
41
  - **Hash-chained audit log** — every call is a JSONL line with `prev_hash` and `hash`; `agentguard verify` proves no entry was edited, removed from the middle, or reordered (see Limits for what a local chain cannot prove on its own).
42
+ - **Hook mode for coding agents** — `agentguard hooks install` puts the same policy in front of Claude Code's, Codex's and Gemini CLI's own shell commands and file edits; irreversible commands (push, merge, publish, send, `rm` outside the repo) run only on a recent turn a person typed that names them, never on text the model wrote. [Details](#hook-mode-a-coding-agents-own-commands).
43
+ - **Rule adherence audit** — `agentguard audit` reads CLAUDE.md, AGENTS.md, GEMINI.md and `.cursor/rules` and this machine's Claude Code and Codex sessions, and prints which rules the agents broke ("broken in 9 of 31 sessions"), locally; `--enforce` turns the checkable ones into hook rules in dry-run. [Details](#audit-which-written-rules-your-coding-agents-broke).
40
44
 
41
45
  No LLM calls. No phone-home. No account. MIT.
42
46
 
@@ -121,6 +125,202 @@ docker run -i --rm agentguard proxy --config /app/demo/agentguard.yaml # a fak
121
125
 
122
126
  Prefer HTTP (several agents, scoped keys, Slack approve buttons)? `agentguard proxy --http --port 8788` and point clients at `http://127.0.0.1:8788/mcp` with an `X-Run-Id` header per run and `Authorization: Bearer agk_…` per agent.
123
127
 
128
+ ## Hook mode: a coding agent's own commands
129
+
130
+ The proxy sees MCP calls. A coding agent also acts through its own shell and file tools, which no
131
+ MCP proxy sees. Hook mode puts the same `agentguard.yaml` in front of those, through the agent's
132
+ pre-execution hook, and adds one check nothing else makes: an irreversible command runs only on a
133
+ turn a **person** typed.
134
+
135
+ ```sh
136
+ npx -y @agentwares/agentguard hooks install # Claude Code, this project (.claude/settings.json)
137
+ npx -y @agentwares/agentguard hooks install --client all # + Codex (.codex/hooks.json) and Gemini CLI (.gemini/settings.json)
138
+ npx -y @agentwares/agentguard hooks install --user # every project (~/.claude/settings.json, policy in ~/.agentguard/)
139
+ npx -y @agentwares/agentguard hooks status | uninstall
140
+ ```
141
+
142
+ `install` adds one hook entry (other settings and hooks are kept; the first change leaves a
143
+ `*.agentguard-backup`), adds a commented `hooks:` block in **dry-run** to `agentguard.yaml` (or
144
+ writes a policy with only that block), and adds `.agentguard/` to `.gitignore`. Commit
145
+ `agentguard.yaml` and `.claude/settings.json` and the whole team runs the same rulebook. The hook
146
+ command is `npx -y @agentwares/agentguard@<version> hook pre-tool-use` (about half a second per
147
+ guarded call); with the package installed globally, `--command agentguard` makes it about 0.1 s.
148
+
149
+ | Agent | Hook (verified 7 Oct 2026) | Rules, approvals, caps, audit | Human-turn gate |
150
+ | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------- | ------------------------------------------------------------------------- |
151
+ | Claude Code | [`PreToolUse`](https://code.claude.com/docs/en/hooks): `Bash`, `Write`, `Edit`, `mcp__*` … | yes | yes, from the session transcript |
152
+ | Codex CLI | [`PreToolUse`](https://developers.openai.com/codex/hooks): `Bash`, `apply_patch`, `mcp__*` | yes (trust the hook once in Codex's `/hooks`) | no: Codex calls its transcript format unstable, so irreversible = approve |
153
+ | Gemini CLI | [`BeforeTool`](https://github.com/google-gemini/gemini-cli/blob/main/docs/hooks/reference.md): `run_shell_command`, `write_file`, `replace`, `mcp_*` | yes | no: not verified against a local install, so irreversible = approve |
154
+
155
+ Cursor has its own hooks (`beforeShellExecution`) and can load Claude Code's
156
+ ([cursor.com/docs/hooks](https://cursor.com/docs/hooks)); hook mode has not been tested there.
157
+
158
+ **What is checked.** Each shell command is split into simple commands the way a shell would
159
+ (`&&`, `;`, pipes, `$(…)`, backticks, `bash -c '…'`, `eval`, `find -exec`, heredoc bodies skipped,
160
+ `sudo`/`env`/`timeout`/`npx` wrappers and git's `-C` removed, `cd` followed). Then:
161
+
162
+ ```yaml
163
+ hooks:
164
+ mode: dry-run # dry-run: log what enforce would stop, block nothing | enforce
165
+ shell:
166
+ deny: ["terraform destroy*", "curl * | sh"] # refused whatever anyone says
167
+ approval: ["kubectl delete *"] # held for `agentguard approve`
168
+ paths: # file edits and shell writes (>, tee, cp, mv, rm, sed -i)
169
+ deny: [".env", "*.pem"] # no slash: any file with that name; `src/**`: from the project root
170
+ approval: ["**/migrations/**"]
171
+ irreversible:
172
+ builtins: true # or a list: [git-push, merge, tag-delete, rm-outside-workspace, publish, send, guard-config]
173
+ window_s: 1800 # the authorizing turn is at most 30 minutes old
174
+ require_mention: true # ...and names the action
175
+ require_origin: false # true: only entries labelled as typed by a person (see below)
176
+ mentions: { git-push: [deploy] } # extra words per class
177
+ rules: # your own irreversible classes
178
+ - { name: deploy, shell: ["vercel --prod*", "fly deploy*"], mentions: [deploy] }
179
+ ```
180
+
181
+ The MCP side's `deny` and `approval.tools` patterns also apply to MCP tools the coding agent calls
182
+ directly (`mcp__crm__crm_delete_contact` matches `crm_delete_*`). The kill switch stops every
183
+ guarded call in both modes.
184
+
185
+ **Irreversible classes.** `git-push` (`git push`, not `--dry-run`); `merge` (`gh pr merge`,
186
+ `glab mr merge`, `gh api -X PUT …/merge`); `tag-delete` (`git tag -d`, `gh release delete`);
187
+ `rm-outside-workspace` (`rm`/`rmdir`/`unlink`/`shred`/`find -delete` on anything outside the
188
+ project, the project itself, or — recursive only — a target that depends on a variable; temp
189
+ directories are free); `publish` (`npm`/`pnpm`/`yarn`/`bun publish`, `cargo publish`,
190
+ `twine upload`, `gem push`, `poetry`/`uv publish`, `docker push`, `gh release create`,
191
+ `changeset`/`lerna publish`, `semantic-release`, …); `send` (`mail`/`sendmail`/`mutt`/…,
192
+ `gh pr|issue create/comment/edit/…`, `gh api` writes, `curl` to Slack/Discord/Telegram/mail-API
193
+ hosts, MCP tools named `send`/`reply`/`forward`/`post`); `guard-config` (edits to `agentguard.yaml`
194
+ or a hook settings file, `agentguard hooks …`).
195
+
196
+ **The human-turn gate.** An irreversible command runs when the latest entry a person wrote in the
197
+ transcript (1) came after this session's previous irreversible command — one turn authorizes one
198
+ — (2) is at most `window_s` old, and (3) names the action ("push it"), or is a bare "yes" / "go
199
+ ahead" answering an assistant question that names it ("Want me to push to main?"). Otherwise the
200
+ agent gets `APPROVAL_REQUIRED` with an id, and either the person says so in their own words or runs
201
+ `agentguard approve <id>` (in Claude Code, `! npx @agentwares/agentguard approve <id>` runs it
202
+ without going through the model); the identical retry then runs once.
203
+
204
+ **How "a person wrote it" is decided** (Claude Code transcripts, checked against versions 2.1.170
205
+ to 2.1.286). An entry counts only if: `type` is `user` and `message.role` is `user`; it is not
206
+ `isSidechain` (a subagent's "user" turn is the parent model's prompt); not `isMeta` (skill bodies,
207
+ reminders, peer messages); not a compaction summary; carries no `tool_result` and no
208
+ `toolUseResult` (tool output rides in user entries); if it has an `origin`, `origin.kind` is
209
+ `human` (`task-notification`, `peer`, `coordinator` are not); otherwise, if it has a `turnOrigin`,
210
+ that is `human`; with neither label (older versions, queued prompts, `claude -p`), its text does
211
+ not start with a harness wrapper (`<command-name>`, `<local-command-stdout>`, `<task-notification>`,
212
+ `<bash-input>`, `[Request interrupted`, …), and `require_origin: true` refuses it outright. Text
213
+ inside an assistant entry never counts — that is where a fabricated "user: yes, push it" lives.
214
+
215
+ **What the agent sees.** A denial is Claude Code's / Codex's `permissionDecision: "deny"` (Gemini:
216
+ `decision: "deny"`) whose reason is the usual agentguard body:
217
+
218
+ ```json
219
+ {
220
+ "code": "APPROVAL_REQUIRED",
221
+ "cause": "\"git push origin main\" is irreversible (git-push (git push origin main)) and the latest message typed by a person (08:29:16) does not name this action (expected one of: push, ship). It needs a person's approval (approval apr_7c62fbad56).",
222
+ "fix": "stop and tell the user: this needs their approval. They can run `npx @agentwares/agentguard approve apr_7c62fbad56` in a terminal in this project (or type `! npx @agentwares/agentguard approve apr_7c62fbad56` in Claude Code), or say in their own words that you should do it; then retry this exact command once. Do not change it, work around it, or run the approval yourself: agentguard refuses an approval from the agent.",
223
+ "retryable": true,
224
+ "details": { "approvalId": "apr_7c62fbad56", "command": "agentguard approve apr_7c62fbad56" }
225
+ }
226
+ ```
227
+
228
+ and the person gets a one-line `systemMessage` with the approve command. agentguard never answers
229
+ "allow": an allowed call goes through the agent's own permission prompts as before. The agent may
230
+ not approve, deny or resume its own held actions, or write `.agentguard/` (refused in enforce).
231
+ In dry-run the person sees "would have stopped …" and the call runs; `agentguard report` lists every
232
+ such decision under **Coding-agent hooks**. Hook calls count against `caps` under `hook_calls`,
233
+ `shell_commands`, `file_edits` and `irreversible` (per run = per agent session, and per day); the
234
+ loop breaker stops the same file edit repeated.
235
+
236
+ ## Audit: which written rules your coding agents broke
237
+
238
+ Teams write rules for their agents in CLAUDE.md, AGENTS.md, GEMINI.md and `.cursor/rules`, then
239
+ cannot tell whether the agents keep them. `agentguard audit` reads the repository's rule files and
240
+ this machine's past Claude Code and Codex sessions in it, and prints, per rule, how many sessions
241
+ broke it and when. Measure first, then enforce what can be enforced.
242
+
243
+ ```sh
244
+ npx -y @agentwares/agentguard audit # this repository, the last 7 days
245
+ npx -y @agentwares/agentguard audit --since 30d # or all, 24h, 2026-09-01; --client claude|codex
246
+ npx -y @agentwares/agentguard audit --json # counts, rule ids and dates (what /agentguard:audit reads)
247
+ npx -y @agentwares/agentguard audit --enforce --preview # the hook rules that would enforce them
248
+ ```
249
+
250
+ ```
251
+ agentguard audit — /home/dev/acme · since 2026-09-30
252
+ 6 sessions in this repository (Claude Code 5, Codex 1). Read on this machine; nothing was sent anywhere.
253
+ 13 rules found (6 in CLAUDE.md, 3 in AGENTS.md, 1 in GEMINI.md, 2 in .cursor/rules/release.mdc, 1 in agentguard.yaml); 11 checkable.
254
+
255
+ BROKEN
256
+ R1 Never push to `main`. (CLAUDE.md:5)
257
+ no-push main — broken in 3 of 6 sessions (4 pushed); 1 refused by the harness
258
+ 2026-10-06 10:40 git push origin main · session 3f9a1c2b
259
+ R4 Run `pnpm check` before pushing. (CLAUDE.md:8)
260
+ run "pnpm check" before push — broken in 3 of 6 sessions (4 pushed or opened a PR); 4 times
261
+ …
262
+ NOT CHECKABLE MECHANICALLY (2) — add an inline check (<!-- agentguard: … -->) or ask your agent with /agentguard:audit
263
+ R6 Write tests for new code. (CLAUDE.md:13)
264
+ ```
265
+
266
+ **The rules.** Every list item and every sentence that directs something (code blocks, tables and
267
+ front matter skipped) is a rule, numbered across the files, checkable or not. A small pattern
268
+ library, with no LLM, recognises the common checkable shapes: never push to / commit on / touch
269
+ main directly; never force-push (or "rewrite history"); never `--no-verify` / skip the hooks; run
270
+ `X` before committing or pushing (also tests, lint, typecheck); use pnpm, not npm; do not edit or
271
+ commit `<path>` (`.env`, lockfiles, generated directories); do not add dependencies (without
272
+ asking); never `rm -rf` outside the repo; never publish; never deploy; never use / run `<command>`.
273
+ "unless asked" / "without asking" makes a break on a turn a person typed asking for it not count.
274
+ Two explicit forms always work and win over the patterns:
275
+
276
+ ```markdown
277
+ - Release notes go in CHANGELOG.md. <!-- agentguard: never "git tag*" -->
278
+ - Keep functions small. <!-- agentguard: none -->
279
+ ```
280
+
281
+ ```yaml
282
+ # agentguard.yaml
283
+ audit:
284
+ rules:
285
+ - id: deploys
286
+ text: Only CI deploys
287
+ check: no-deploy # several: check: [no-verify, 'never "git reset --hard*"']
288
+ ```
289
+
290
+ The check grammar: `no-push [branch,…]`, `no-commit-to [branch,…]`, `no-force-push [branch,…]`,
291
+ `no-verify`, `run "<command>" before commit|push` (`@tests`, `@lint`, `@typecheck` for the usual
292
+ commands), `use pnpm|npm|yarn|bun`, `no-pm npm,…`, `no-edit "<glob>" …`, `no-commit "<glob>" …`,
293
+ `no-new-deps`, `no-rm-outside`, `no-publish`, `no-deploy`, `never "<command glob>" …`, each with an
294
+ optional `unless-asked`; `none` marks a rule no script can check.
295
+
296
+ **The sessions.** Claude Code transcripts (`~/.claude/projects`, or `$CLAUDE_CONFIG_DIR`) and
297
+ Codex rollouts (`~/.codex/sessions`, or `$CODEX_HOME`) whose working directory is this repository
298
+ or one of its worktrees, subagents included. The tool calls are read the way hook mode reads them
299
+ (the same shell parser, the same edit targets, the same rm-outside-workspace and publish classes),
300
+ and "asked for it" is hook mode's human-turn reading of the transcript. A push's branch is the one
301
+ on the command line; for a bare `git push`, the one Claude Code recorded the push went to, else
302
+ the branch checked out.
303
+
304
+ **What leaves the screen: nothing.** No network, no telemetry, no LLM. The command or path that
305
+ broke a rule is shown on your terminal only. `--json` and the cache
306
+ (`~/.agentguard/audit-cache-v1/`, counts per transcript so a second run takes about a second and
307
+ history survives Claude Code's 30-day transcript cleanup) hold counts, rule ids, dates, line
308
+ numbers and hashes — never a command, a path or a prompt; a test plants marker strings in every
309
+ part of a synthetic transcript and checks that none reaches either.
310
+
311
+ **`--enforce`.** Writes the checkable rules into agentguard.yaml as hook-mode rules
312
+ (`hooks.shell.deny`, `hooks.shell.approval` for "without asking", `hooks.paths.deny`, the
313
+ built-in irreversible classes, a `deploy` rule), each with a comment naming the rule it came
314
+ from; shows the diff; installs the hook if it is not installed. It never switches `hooks.mode`:
315
+ a new hooks block starts in dry-run, and if yours is already `enforce` it writes nothing without
316
+ `--yes`. "Run X before pushing" and "never commit on main" stay audit-only (a pre-execution hook
317
+ sees one command, not the order or the checked-out branch).
318
+
319
+ **In your agent.** `/agentguard:audit` (Claude Code plugin, Gemini CLI extension) runs
320
+ `audit --json` and has your own agent judge the rules marked not checkable against the
321
+ repository and its git history — no tokens of ours. `/agentguard:hooks` installs or checks hook
322
+ mode.
323
+
124
324
  ## Policy
125
325
 
126
326
  `agentguard init` generates this file with every knob explained inline. The short form:
@@ -189,20 +389,24 @@ Run identity: `X-Run-Id` header (HTTP) → `_meta.runId` on the call → session
189
389
 
190
390
  ## Commands
191
391
 
192
- | Command | What it does |
193
- | ------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
194
- | `agentguard init [--client path] [--all] [--no-probe] [--mode enforce] [--undo]` | generate the policy, rewrite the client config (project-level by default) |
195
- | `agentguard proxy [--http --port 8788] [--agent name] [--run-id id] [--mode m]` | run the proxy (stdio default) |
196
- | `agentguard report [--run id \| --all] [--json]` | what this run did / would have destroyed / spent; where it was halted; chain status |
197
- | `agentguard diff [--run id]` | mutation diff of faked writes |
198
- | `agentguard verify [audit.jsonl]` | recompute the hash chain; exit 1 on the first break |
199
- | `agentguard status [--run id]` | counters vs caps, kill state, pending approvals, running HTTP proxy |
200
- | `agentguard tools [--json]` | every exposed tool with class, verb, upstream and the reason |
201
- | `agentguard kill [reason]` / `agentguard resume` | halt everything now / clear it |
202
- | `agentguard approvals [--all]` / `approve <id>` / `deny <id> [--note …]` | the approval queue |
203
- | `agentguard key create <agent> [--allow p]… [--deny p] [--writes n] [--spend n] [--mode m]` / `key list` / `key revoke <agent>` | scoped credentials |
204
- | `agentguard connect <key> [--write] [--client path] [--all] [--url base]` | point this machine's MCP client at a hosted proxy (paid tiers); prints the config, `--write` merges it in |
205
- | `agentguard permission-diff [--base ref] [--head ref] [--fail-on-widen]` | which config changes widen agent permissions (also a [GitHub Action](https://github.com/agentwares/agentguard/tree/main/permission-diff)) |
392
+ | Command | What it does |
393
+ | ----------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
394
+ | `agentguard init [--client path] [--all] [--no-probe] [--mode enforce] [--undo]` | generate the policy, rewrite the client config (project-level by default) |
395
+ | `agentguard proxy [--http --port 8788] [--agent name] [--run-id id] [--mode m]` | run the proxy (stdio default) |
396
+ | `agentguard report [--run id \| --all] [--json]` | what this run did / would have destroyed / spent; where it was halted; chain status |
397
+ | `agentguard diff [--run id]` | mutation diff of faked writes |
398
+ | `agentguard verify [audit.jsonl]` | recompute the hash chain; exit 1 on the first break |
399
+ | `agentguard status [--run id]` | counters vs caps, kill state, pending approvals, running HTTP proxy |
400
+ | `agentguard tools [--json]` | every exposed tool with class, verb, upstream and the reason |
401
+ | `agentguard kill [reason]` / `agentguard resume` | halt everything now / clear it |
402
+ | `agentguard approvals [--all]` / `approve <id>` / `deny <id> [--note …]` | the approval queue |
403
+ | `agentguard key create <agent> [--allow p]… [--deny p] [--writes n] [--spend n] [--mode m]` / `key list` / `key revoke <agent>` | scoped credentials |
404
+ | `agentguard connect <key> [--write] [--client path] [--all] [--url base]` | point this machine's MCP client at a hosted proxy (paid tiers); prints the config, `--write` merges it in |
405
+ | `agentguard permission-diff [--base ref] [--head ref] [--fail-on-widen]` | which config changes widen agent permissions (also a [GitHub Action](https://github.com/agentwares/agentguard/tree/main/permission-diff)) |
406
+ | `agentguard hooks install [--project\|--user] [--client claude\|codex\|gemini\|all] [--command cmd]` / `hooks uninstall` / `hooks status` | put the policy in front of a coding agent's shell commands and file edits ([hook mode](#hook-mode-a-coding-agents-own-commands)) |
407
+ | `agentguard hook pre-tool-use [--client c]` | what the installed hook runs: reads the harness's JSON on stdin, answers in its format |
408
+ | `agentguard audit [--since 7d\|30d\|all] [--client claude\|codex\|all] [--json] [--rules file] [--no-cache] [--no-evidence]` | which written rules the coding agents broke, per rule, from this machine's sessions ([audit](#audit-which-written-rules-your-coding-agents-broke)) |
409
+ | `agentguard audit --enforce [--preview] [--yes]` | write the checkable rules into agentguard.yaml as hook rules (dry-run), show the diff, install the hook |
206
410
 
207
411
  ### Hosted tiers
208
412
 
@@ -239,11 +443,14 @@ node dist/cli.js report && node dist/cli.js diff && node dist/cli.js verify
239
443
 
240
444
  ## Conformance and tests
241
445
 
242
- `pnpm test` runs the CLI suite (52 tests; 68 more in `agentguard-core`, 11 in the SDK): the engine over InMemoryTransport, the spawned stdio proxy (with and without a policy file), the Streamable HTTP proxy with `X-Run-Id`, scoped keys and control endpoints, `init` against real configs, and a recorded-fixture replay (`fixtures/recorded/crm-session.json`; re-record with `RECORD_FIXTURES=1`). `pnpm conformance` runs the official `@modelcontextprotocol/conformance` server suite against the proxy with a sample server behind it (tools, resources, prompts, completions, logging, progress, sampling and elicitation are relayed).
446
+ `pnpm test` runs the CLI suite (85 tests; 191 more in `agentguard-core`, 11 in the SDK): the audit end to end on a synthetic history (rule files in every format, Claude Code and Codex sessions with known kept and broken rules, marker strings that must never reach the cache or `--json`, `--enforce`), hook mode end to end (install for three clients, each client's answer format, the approve flow, synthetic transcripts reproducing a model-written "user: yes, push it"), the engine over InMemoryTransport, the spawned stdio proxy (with and without a policy file), the Streamable HTTP proxy with `X-Run-Id`, scoped keys and control endpoints, `init` against real configs, and a recorded-fixture replay (`fixtures/recorded/crm-session.json`; re-record with `RECORD_FIXTURES=1`). `pnpm conformance` runs the official `@modelcontextprotocol/conformance` server suite against the proxy with a sample server behind it (tools, resources, prompts, completions, logging, progress, sampling and elicitation are relayed).
243
447
 
244
448
  ## Limits (honest)
245
449
 
246
- - The proxy sees MCP tool calls. Token spend on the model API is only visible through the SDK's guarded `fetch` (or `spend.tools` rules for MCP tools that call models).
450
+ - The proxy sees MCP tool calls; hook mode sees a coding agent's shell commands, file edits and direct MCP calls. Token spend on the model API is only visible through the SDK's guarded `fetch` (or `spend.tools` rules for MCP tools that call models).
451
+ - Hook mode is a guardrail against an agent acting without a person's say-so, not a sandbox against a hostile one. It reads command lines, not what runs: a script (`./release.sh`, `make deploy`) that pushes inside is only caught by a `shell` rule naming it; `xargs rm` targets come from stdin and are not checked; a variable's value is unknown (a recursive `rm` of one counts as outside the workspace). "Names the action" is a word match: "don't push yet" names push. Each class's words are in the policy block; add your language's with `irreversible.mentions`.
452
+ - Claude Code writes the transcript asynchronously; if the turn that authorizes a command is not on disk yet when the hook runs, the command is held (fail closed) and the retry passes. A `claude -p` prompt has no `origin` label, so it counts as the person's turn unless `require_origin: true`. Codex and Gemini CLI get no human-turn gate (their irreversible commands always need `agentguard approve` in enforce). If the hook itself fails (a broken `agentguard.yaml`), the call runs and the person sees "this call was NOT checked".
453
+ - The audit counts what the transcripts show. Rules are recognised by patterns, not understood: a rule worded unusually is listed as not checkable (add an inline check), and one worded like a pattern it does not mean can be mis-read (mark it `<!-- agentguard: none -->`). A bare `git push` counts as a push to the checked-out branch only on the main thread (a subagent's `gitBranch` can be the session's, not its worktree's); an attempt the harness refused still counts, marked as refused. Sessions are matched by working directory: a worktree outside the repository is not included. Codex rollouts do not say which turns a person typed, so an `unless-asked` break there is reported as undetermined; Codex's JavaScript `exec` tool is counted, not read.
247
454
  - Dry-run synthesizes results from the tool's `outputSchema`; agents that depend on real ids from a create → update chain will see plausible but fake ids. `dry_run.tools` lets you fake only the dangerous tools in enforce mode.
248
455
  - Per-day counters are a JSON file under a directory lock; fine for a workstation or one box, not a fleet. The hosted tier (coming) is the shared-state version.
249
456
  - Slack "Approve" buttons are links to the local HTTP proxy; they work for people who can reach it. Without HTTP mode the message carries the `agentguard approve <id>` command.
@@ -0,0 +1,17 @@
1
+ import {
2
+ TEAM_HISTORY_LINE,
3
+ TEAM_HISTORY_URL,
4
+ auditCommand,
5
+ parseSince
6
+ } from "./chunk-6S7LYVOC.js";
7
+ import "./chunk-3O6KWT3E.js";
8
+ import "./chunk-TW5KJREH.js";
9
+ import "./chunk-SUXQTT3X.js";
10
+ import "./chunk-5WRI5ZAA.js";
11
+ export {
12
+ TEAM_HISTORY_LINE,
13
+ TEAM_HISTORY_URL,
14
+ auditCommand,
15
+ parseSince
16
+ };
17
+ //# sourceMappingURL=audit-2YCMHMCP.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}