@shidesheng0218/agentguard 0.8.1 β†’ 0.9.0

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.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # πŸ›‘οΈ agent-guard (formerly kimi-guard)
4
4
 
5
- **A runtime behavior guard for coding agents β€” [Kimi Code CLI](https://github.com/MoonshotAI/kimi-code) and [Claude Code](https://code.claude.com) β€” stop runaway agent loops before they burn your quota.**
5
+ **A runtime behavior guard for coding agents β€” [Kimi Code CLI](https://github.com/MoonshotAI/kimi-code), [Claude Code](https://code.claude.com) and [Codex CLI](https://github.com/openai/codex) β€” stop runaway agent loops before they burn your quota.**
6
6
 
7
7
  `npm i -g @shidesheng0218/agentguard && agentguard install` β†’ done. (Existing users: your installed `kimi-guard` keeps working β€” its `kguard` bin and hook entries stay live.)
8
8
 
@@ -10,13 +10,13 @@
10
10
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](/LICENSE)
11
11
  [![CI](https://img.shields.io/github/actions/workflow/status/shidesheng0218/kimi-guard/ci.yml?style=flat-square&label=CI)](/.github/workflows/ci.yml)
12
12
 
13
- <img src="https://raw.githubusercontent.com/shidesheng0218/kimi-guard/main/assets/banner.svg" alt="kimi-guard banner" width="100%"/>
13
+ <img src="https://raw.githubusercontent.com/shidesheng0218/kimi-guard/main/assets/banner.svg?v=0.8.1" alt="agent-guard banner" width="100%"/>
14
14
 
15
15
  **[English](README.md) Β· [δΈ­ζ–‡ζ–‡ζ‘£](docs/README.zh-CN.md)**
16
16
 
17
17
  <div align="center">
18
18
 
19
- ![kimi-guard demo](https://raw.githubusercontent.com/shidesheng0218/kimi-guard/main/assets/demo.gif?v=0.6.1)
19
+ ![agent-guard demo](https://raw.githubusercontent.com/shidesheng0218/kimi-guard/main/assets/demo.gif?v=0.8.1)
20
20
 
21
21
  *Real terminal session: install β†’ verify β†’ a supervised run where the circuit breaker catches a looping tool call β†’ live status & budget panels. Recorded with [vhs](https://github.com/charmbracelet/vhs) from actual commands ([demo.tape](assets/demo.tape)).*
22
22
 
@@ -34,19 +34,19 @@ Kimi Code CLI is a great open-source coding agent, but its subagent system has k
34
34
  - All subagents share **one API key**, so a burst of parallel dispatches exhausts TPM/RPM and everything hangs.
35
35
  - A mid-batch quota error leaves **half-written workspaces** that poison the whole run.
36
36
 
37
- kimi-guard is a local, zero-daemon guard that sits on the CLI's official [hooks system](https://www.kimi.com/code/docs/en/kimi-code-cli/customization/hooks.html) and enforces hard caps β€” no source forking, no proxy, no account access.
37
+ agent-guard is a local, zero-daemon guard that sits on the CLI's official [hooks system](https://www.kimi.com/code/docs/en/kimi-code-cli/customization/hooks.html) and enforces hard caps β€” no source forking, no proxy, no account access.
38
38
 
39
39
  Since v0.8 the same engine also guards **Claude Code** via its [hooks system](https://code.claude.com/docs/en/hooks) (`agentguard install` auto-detects installed harnesses). Wire-mode supervision (`agentguard run`), mid-turn steering and official-API quota metering remain Kimi-exclusive; loop/churn/explore detection, quota gates, the completion gate, kill switch and checkpoints work on both.
40
40
 
41
41
  ## Features
42
42
 
43
- kimi-guard is not a preset pack β€” it is a **runtime behavior analysis and enforcement engine**. Every tool call flows through a normalization layer, a set of pure analyzers, and a policy engine that maps findings to actions (observe / warn / block / full stop).
43
+ agent-guard is not a preset pack β€” it is a **runtime behavior analysis and enforcement engine**. Every tool call flows through a normalization layer, a set of pure analyzers, and a policy engine that maps findings to actions (observe / warn / block / full stop).
44
44
 
45
45
  | Guard | Signal it detects | Action |
46
46
  |---|---|---|
47
47
  | πŸ” **Repetition** | same `(tool, args)` signature re-run N times (whitespace-tolerant fingerprinting) | block |
48
48
  | πŸ”„ **Cycle detection** | oscillating loops: `Aβ†’Bβ†’Aβ†’B…` up to period-3, regardless of tool | block |
49
- | πŸ“‰ **No-information-gain** | different arguments, byte-identical output β€” the model is spinning without new data (the real root cause of upstream [#2142](https://github.com/MoonshotAI/kimi-cli/issues/2142) Case B) | warn β†’ block |
49
+ | πŸ“‰ **No-information-gain** | different arguments, byte-identical output β€” the model is spinning without new data (the real root cause of upstream [#2142](https://github.com/MoonshotAI/kimi-cli/issues/2142) Case B). Fuzzy variant catches near-identical outputs (trigram similarity) | warn β†’ block |
50
50
  | ✏️ **Edit churn** | the same file edited over and over without converging ("thrashing") | warn β†’ block |
51
51
  | 🐒 **No-progress stretch** | long run of tool calls with no successful edit landing β€” motion without progress | warn β†’ block |
52
52
  | πŸ”­ **Exploration drift** | long streak of read/search calls with no action in between β€” exploring without implementing | warn β†’ block |
@@ -62,7 +62,7 @@ kimi-guard is not a preset pack β€” it is a **runtime behavior analysis and enfo
62
62
 
63
63
  Warn-level findings are injected into the model's context (official hooks stdout mechanism) so the agent can correct itself *before* a block becomes necessary. Blocks feed a structured reason back to the model (official exit-code-2 mechanism).
64
64
 
65
- Everything is **fail-open**: if kimi-guard itself errors, the agent keeps working. It is a safety net, not a single point of failure.
65
+ Everything is **fail-open**: if agent-guard itself errors, the agent keeps working. It is a safety net, not a single point of failure.
66
66
 
67
67
  ## Install
68
68
 
@@ -86,13 +86,14 @@ Claude Code users can also install via the plugin channel (this repo is a self-h
86
86
 
87
87
  ### Harness support
88
88
 
89
- | Capability | Kimi Code CLI | Claude Code |
90
- |---|---|---|
91
- | Loop / churn / explore detection, kill switch | βœ… hooks | βœ… hooks |
92
- | Quota gates | βœ… event-based + official-API precise (`[budget] precise`) | βœ… event-based estimates |
93
- | Completion gate (claim vs evidence) | βœ… | βœ… |
94
- | Checkpoints / resume, feedback loop, reports | βœ… | βœ… |
95
- | `agentguard run` Wire supervision, mid-turn steer | βœ… | β€” (hooks only) |
89
+ | Capability | Kimi Code CLI | Claude Code | Codex CLI |
90
+ |---|---|---|---|
91
+ | Loop / churn / explore detection, kill switch | βœ… hooks | βœ… hooks | βœ… hooks (shell + `apply_patch`; hosted tools like WebSearch are not observable) |
92
+ | Quota gates | βœ… event-based + official-API precise (`[budget] precise`) | βœ… event-based estimates | βœ… event-based estimates |
93
+ | Completion gate (claim vs evidence) | βœ… | βœ… | βœ… |
94
+ | Checkpoints / resume, feedback loop, reports | βœ… | βœ… | βœ… |
95
+ | `agentguard run` supervised headless runs | βœ… Wire protocol | βœ… stream-json supervision | β€” |
96
+ | Mid-turn steer, exact per-step token metering | βœ… | β€” | β€” |
96
97
 
97
98
  <details>
98
99
  <summary>What <code>agentguard install</code> writes</summary>
@@ -161,17 +162,20 @@ kguard config init|show|get <key> # manage ~/.kimi-guard/config.toml
161
162
  kguard hook <event> # (used by the CLI, reads JSON from stdin)
162
163
  ```
163
164
 
164
- ### `kguard run` β€” supervised headless runs
165
+ ### `agentguard run` β€” supervised headless runs
165
166
 
166
167
  This is the tool for CI, cron jobs and unattended agents β€” the exact scenario where a
167
168
  repeating tool call burns the full timeout (upstream issue #2142 was a headless run).
168
169
 
169
170
  ```sh
170
- kguard run "refactor the auth module and make tests pass" \
171
+ agentguard run "refactor the auth module and make tests pass" \
171
172
  --max-steps 100 --max-minutes 20 --auto-resume 1 --json
173
+
174
+ # Claude Code headless supervision (stream-json driver):
175
+ agentguard run "migrate the test suite to vitest" --harness claude --max-steps 50
172
176
  ```
173
177
 
174
- What the supervisor does in-process (no shell hooks, no exit codes):
178
+ What the supervisor does (Kimi, Wire protocol β€” in-process, no exit codes):
175
179
 
176
180
  - subscribes to `PreToolUse` over the Wire protocol and returns `allow/block` decisions β€” the same analyzers, zero-latency
177
181
  - **steers** the agent mid-turn (`steer`) when a warn-level pattern appears, before a hard block is needed
@@ -180,9 +184,15 @@ What the supervisor does in-process (no shell hooks, no exit codes):
180
184
  - enforces hard caps: `--max-steps` (cancel via official `cancel` method), `--max-minutes`
181
185
  - **kill switch**: after N blocks it cancels the turn and checkpoints
182
186
  - approval policy: default rejects with feedback (headless-safe), `--yolo` approves
183
- - writes a run report (`report.json`) + raw wire log (`wire.jsonl`) under `~/.kimi-guard/runs/`
187
+ - writes a run report (`report.json`) + raw wire log (`wire.jsonl`) under `~/.agent-guard/runs/`
184
188
  - exit code 0 on clean finish, 2 on any intervention-triggered end β€” CI-friendly
185
189
 
190
+ The Claude driver (`--harness claude`) spawns `claude -p --output-format stream-json` and supervises the
191
+ event stream: same analyzers and state db (shared with the installed hooks, which do the actual blocking),
192
+ hard caps via `--max-turns` + wall clock, kill switch (SIGINT β†’ SIGKILL), verify rounds and auto-resume
193
+ via `--resume`, exact token metering from `result.usage`. Mid-turn steer is not available (the stream is
194
+ read-only) β€” blocks still reach the model through the installed hooks in real time.
195
+
186
196
  ## Configuration
187
197
 
188
198
  `~/.kimi-guard/config.toml` (see `kguard config init`; full annotated template included):
@@ -263,7 +273,7 @@ flowchart LR
263
273
  subgraph KIMI["Kimi Code CLI"]
264
274
  A["tool call"] -->|"hook event / Wire msg"| B
265
275
  end
266
- subgraph GUARD["kimi-guard"]
276
+ subgraph GUARD["agent-guard"]
267
277
  B["Normalization layer<br/>schema-variant tolerant<br/>+ output hashing"] --> C["Analyzers (pure functions)<br/>repeat Β· cycle Β· no-gain Β· churn<br/>no-progress Β· near-repeat Β· explore"]
268
278
  M["Budget engine<br/>5h/weekly windows<br/>burn-rate projection"] --> C
269
279
  C --> D["Policy engine<br/>findings β†’ action<br/>+ kill switch"]
@@ -279,7 +289,7 @@ The completion gate adds a claim-vs-evidence loop on top:
279
289
  ```mermaid
280
290
  sequenceDiagram
281
291
  participant A as Agent
282
- participant G as kimi-guard
292
+ participant G as agent-guard
283
293
  participant DB as local evidence (state.db)
284
294
  A->>A: runs tools (Shell, edits...)
285
295
  A->>G: turn ends, claims "all tests pass"
@@ -328,17 +338,17 @@ Kimi Code CLI ──hook event──▢ kguard hook <event> (JSON on stdin)
328
338
 
329
339
  ## Ecosystem fit
330
340
 
331
- The agent-runtime tooling space is crowded, and pretending every tool competes with every other one helps nobody. kimi-guard occupies one specific layer β€” here is the honest map:
341
+ The agent-runtime tooling space is crowded, and pretending every tool competes with every other one helps nobody. agent-guard occupies one specific layer β€” here is the honest map:
332
342
 
333
343
  ```
334
344
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
335
- β”‚ your agent (Kimi Code CLI) β”‚
345
+ β”‚ your agent (Kimi Code CLI Β· Claude Code) β”‚
336
346
  β”‚ β”‚
337
347
  β”‚ built-in loop_control step/attempt caps + compaction β”‚
338
348
  β”‚ β”œβ”€ mechanical counter β€” stops the loop, explains nothing β”‚
339
349
  β”‚ β”‚
340
350
  β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
341
- β”‚ β”‚ kimi-guard (this project) β€” the enforcement layer β”‚ β”‚
351
+ β”‚ β”‚ agent-guard (this project) β€” the enforcement layer β”‚ β”‚
342
352
  β”‚ β”‚ semantic loop detection Β· quota gates Β· steering Β· β”‚ β”‚
343
353
  β”‚ β”‚ checkpoints Β· goal anchoring β€” the agent cannot bypass β”‚ β”‚
344
354
  β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
@@ -350,7 +360,7 @@ The agent-runtime tooling space is crowded, and pretending every tool competes w
350
360
  β”‚ kimi-boost security preset installer β”‚
351
361
  β”‚ β”œβ”€ dangerous-command guards, branch protection, skills β”‚
352
362
  β”‚ β”œβ”€ WHAT the agent may do (security) β€” different axis from β”‚
353
- β”‚ β”‚ kimi-guard's HOW it behaves (runtime loops/budget) β”‚
363
+ β”‚ β”‚ agent-guard's HOW it behaves (runtime loops/budget) β”‚
354
364
  β”‚ β”‚
355
365
  β”‚ cli-agent-runner lifecycle supervisor β”‚
356
366
  β”‚ β”œβ”€ 7Γ—24 restart loops, log-level anomaly detection β”‚
@@ -363,24 +373,24 @@ The agent-runtime tooling space is crowded, and pretending every tool competes w
363
373
 
364
374
  **Three lines of positioning:**
365
375
 
366
- 1. **Monitors are plentiful, voluntary orchestrators exist β€” but a non-bypassable enforcement layer, kimi-guard is the first in the Kimi ecosystem.** (ccusage-family tools are read-only; kimi-session-orchestrator relies on the agent choosing to call it; kimi-guard intercepts.)
376
+ 1. **Monitors are plentiful, voluntary orchestrators exist β€” but a non-bypassable enforcement layer, agent-guard is the first in the Kimi ecosystem.** (ccusage-family tools are read-only; kimi-session-orchestrator relies on the agent choosing to call it; agent-guard intercepts.)
367
377
  2. **Mid-turn steering is an intervention outside the hook-lifecycle boundary β€” no verified analog does it: external supervisors (e.g. [loop-eng/loopguard](https://github.com/loop-eng/loopguard)) can only SIGSTOP-pause the process and post a desktop notification; in-process detector libraries ([LoopBuster](https://github.com/liuchunwei732-cmyk/loopbuster)) need the host app to honor them; security-hook suites (cc-safety-net) act pre-execution only. We do it natively over the official Wire protocol.**
368
378
  3. **The budget model understands Kimi's subscription semantics: 5h/weekly request windows, reserved headroom, burn-rate projection β€” USD-billing competitors don't reconcile against plan-based users.**
369
379
 
370
380
  **What we deliberately do NOT do** (so you know where to look):
371
381
 
372
382
  - Security scanning / destructive-command guards β†’ use **kimi-boost** presets (different axis: authorization vs behavior). `kguard doctor` detects whether a security layer is present and points you there if not.
373
- - Completion verification exists in kimi-guard as a **deterministic claim-vs-evidence gate** (no LLM in the loop), with an *opt-in* single-vote LLM veto for false positives (`VETO: yes|no` protocol, per-session budget cap, fail-closed on any error). For richer semantic verification (refute-by-default judges, LLM grading), see kimi-session-orchestrator's `grade_step` or the refute-by-default pattern in multi-runtime governance suites.
374
- - Multi-runtime portability (Claude Code / Codex / Gemini) β†’ by design, our leverage is Kimi's Wire protocol. The analyzer core (`src/analysis.ts`) is pure functions and reusable if you want to build adapters
383
+ - Completion verification exists in agent-guard as a **deterministic claim-vs-evidence gate** (no LLM in the loop), with an *opt-in* single-vote LLM veto for false positives (`VETO: yes|no` protocol, per-session budget cap, fail-closed on any error). For richer semantic verification (refute-by-default judges, LLM grading), see kimi-session-orchestrator's `grade_step` or the refute-by-default pattern in multi-runtime governance suites.
384
+ - Multi-runtime portability: βœ… shipped for Claude Code (v0.8) and Codex CLI (v0.9) β€” see the harness matrix. Next adapters (Gemini etc.) reuse the pure-function analyzer core ([PORTING.md](docs/PORTING.md))
375
385
  - Daemon-style process supervision (SIGSTOP/SIGCONT, systemd) β†’ **cli-agent-runner** owns that layer; ours is semantic in-harness intervention
376
386
 
377
- Related Kimi-ecosystem projects worth knowing: [kimi-session-orchestrator](https://github.com/FirenzeClaw/kimi-session-orchestrator) (multi-session orchestration), [oh-my-kimi](https://github.com/xz1220/oh-my-kimi) (skill/hook presets), [cli-agent-runner](https://github.com/wan9yu/cli-agent-runner) (lifecycle supervision with a kimi preset), [kimi-code-usage](https://github.com/Golden0Voyager/kimi-code-usage) (read-only usage reporting). kimi-guard and [kimi-boost](https://github.com/shidesheng0218/kimi-boost) come from the same author and are designed as a pair: boost covers the authorization axis, guard the behavior axis.
387
+ Related Kimi-ecosystem projects worth knowing: [kimi-session-orchestrator](https://github.com/FirenzeClaw/kimi-session-orchestrator) (multi-session orchestration), [oh-my-kimi](https://github.com/xz1220/oh-my-kimi) (skill/hook presets), [cli-agent-runner](https://github.com/wan9yu/cli-agent-runner) (lifecycle supervision with a kimi preset), [kimi-code-usage](https://github.com/Golden0Voyager/kimi-code-usage) (read-only usage reporting). agent-guard and [kimi-boost](https://github.com/shidesheng0218/kimi-boost) come from the same author and are designed as a pair: boost covers the authorization axis, guard the behavior axis.
378
388
 
379
389
  ### The cross-ecosystem landscape (verified 2026-09)
380
390
 
381
391
  The behavioral-enforcement niche is not just empty in the Kimi ecosystem β€” a survey of the wider coding-agent tooling space found no shipped equivalent:
382
392
 
383
- | Tool | Mechanism | What it can/cannot do vs kimi-guard |
393
+ | Tool | Mechanism | What it can/cannot do vs agent-guard |
384
394
  |---|---|---|
385
395
  | [cc-safety-net](https://github.com/kenryu42/cc-safety-net) (1.5kβ˜…, 13 CLIs incl. Kimi Code) | pre-execution hooks | Blocks dangerous commands/secret access β€” the authorization axis. No loop detection, no quotas, no steering. Proves multi-runtime hooks appetite. |
386
396
  | [ccusage](https://github.com/ccusage/ccusage) (18kβ˜…) | log analytics | Read-only cost/token reports over 18 agent CLIs. Never blocks. The usage-data layer is commoditized; enforcement is the open layer. |
@@ -390,7 +400,7 @@ The behavioral-enforcement niche is not just empty in the Kimi ecosystem β€” a s
390
400
  | [ralph](https://github.com/frankbria/ralph-claude-code) (9.6kβ˜…) | shell wrapper loop | Exit gates and rate limits at iteration boundaries only β€” works around runaway agents by restarting, doesn't govern them. |
391
401
  | NeMo Guardrails / Guardrails AI / Langfuse / LangSmith / Helicone | content rails / SDK / proxy / SaaS | Structurally cannot intercept a local CLI's tool calls: proxies see only model HTTP traffic, content validators see text, observability is after-the-fact. |
392
402
 
393
- **The takeaway:** monitors are commoditized, security hooks are crowded, orchestration is well-served β€” behavioral, semantic, mid-run enforcement of a local coding CLI is the layer nobody ships. kimi-guard's moat is the combination, not any single feature: hook/Wire access point Γ— semantic detectors Γ— subscription-aware budgeting. The main strategic risk is single-runtime binding; the analyzer core is pure functions ([PORTING.md](docs/PORTING.md)) precisely so adapters can widen it.
403
+ **The takeaway:** monitors are commoditized, security hooks are crowded, orchestration is well-served β€” behavioral, semantic, mid-run enforcement of a local coding CLI is the layer nobody else ships. agent-guard's moat is the combination, not any single feature: hook/Wire access point Γ— semantic detectors Γ— subscription-aware budgeting β€” now running on two harnesses (Kimi Code + Claude Code), with the pure-function analyzer core ([PORTING.md](docs/PORTING.md)) ready for more.
394
404
 
395
405
  ## Compatibility
396
406