@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 +40 -30
- package/dist/chunk-SACTXNYK.js +1450 -0
- package/dist/claude-ZFYJRREP.js +262 -0
- package/dist/cli.js +173 -1284
- package/package.json +3 -2
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)
|
|
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)
|
|
11
11
|
[](/.github/workflows/ci.yml)
|
|
12
12
|
|
|
13
|
-
<img src="https://raw.githubusercontent.com/shidesheng0218/kimi-guard/main/assets/banner.svg" alt="
|
|
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
|
-

|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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`
|
|
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
|
-
### `
|
|
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
|
-
|
|
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
|
|
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 `~/.
|
|
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["
|
|
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
|
|
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.
|
|
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
|
-
β β
|
|
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
|
-
β β
|
|
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,
|
|
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
|
|
374
|
-
- Multi-runtime portability
|
|
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).
|
|
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
|
|
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.
|
|
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
|
|