agent-token-sentinel 0.1.0 → 0.2.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +37 -1
  2. package/README.md +101 -10
  3. package/README.zh-TW.md +101 -10
  4. package/SKILL.md +19 -4
  5. package/dist/circuit-breaker/breaker.js +1 -0
  6. package/dist/circuit-breaker/breaker.js.map +1 -1
  7. package/dist/circuit-breaker/detector.d.ts +12 -0
  8. package/dist/circuit-breaker/detector.js +72 -16
  9. package/dist/circuit-breaker/detector.js.map +1 -1
  10. package/dist/cli/hooks.d.ts +16 -2
  11. package/dist/cli/hooks.js +73 -4
  12. package/dist/cli/hooks.js.map +1 -1
  13. package/dist/cli/index.js +62 -6
  14. package/dist/cli/index.js.map +1 -1
  15. package/dist/cli/install.d.ts +7 -0
  16. package/dist/cli/install.js +25 -11
  17. package/dist/cli/install.js.map +1 -1
  18. package/dist/cli/uninstall.d.ts +23 -0
  19. package/dist/cli/uninstall.js +176 -0
  20. package/dist/cli/uninstall.js.map +1 -0
  21. package/dist/config.d.ts +4 -0
  22. package/dist/config.js +12 -0
  23. package/dist/config.js.map +1 -1
  24. package/dist/mcp/server.js +17 -1
  25. package/dist/mcp/server.js.map +1 -1
  26. package/dist/sentinel.d.ts +14 -1
  27. package/dist/sentinel.js +61 -5
  28. package/dist/sentinel.js.map +1 -1
  29. package/dist/token-guard/compactor.d.ts +21 -2
  30. package/dist/token-guard/compactor.js +106 -33
  31. package/dist/token-guard/compactor.js.map +1 -1
  32. package/dist/token-guard/distiller.d.ts +16 -0
  33. package/dist/token-guard/distiller.js +40 -9
  34. package/dist/token-guard/distiller.js.map +1 -1
  35. package/dist/token-guard/log-store.d.ts +23 -0
  36. package/dist/token-guard/log-store.js +101 -0
  37. package/dist/token-guard/log-store.js.map +1 -0
  38. package/dist/types.d.ts +18 -0
  39. package/dist/utils/state-store.d.ts +1 -0
  40. package/dist/utils/state-store.js +3 -0
  41. package/dist/utils/state-store.js.map +1 -1
  42. package/package.json +7 -5
package/CHANGELOG.md CHANGED
@@ -4,7 +4,43 @@ All notable changes to this project are documented here. The format follows
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
5
5
  [Semantic Versioning](https://semver.org/).
6
6
 
7
- ## [0.1.0] - Unreleased
7
+ ## [0.2.0] - 2026-10-12
8
+
9
+ Theme: save tokens **without** starving the model of information.
10
+
11
+ ### Added
12
+ - **Raw logs are kept** (`.sentinel/logs/`, last `maxLogs` = 30) and can be pulled on demand with the new
13
+ `sentinel_expand_log` MCP tool / `sentinel log` CLI: a specific failure block, grep matches with context,
14
+ or a line range. Distilled output ends with the run id to expand.
15
+ - **Multi-failure distillation**: every failing test in a run is listed (one line each), not just the first.
16
+ - **Dynamic budget**: +30 tokens per extra failure, and +50% budget / +2 source-context lines each time the
17
+ *same* failure repeats (capped by `distillMaxBudget` = 600). A stuck model gets more evidence, not less.
18
+ - **Claude Code auto-wrap** (`autoWrapTests`, default on): a PreToolUse hook transparently routes build/test
19
+ Bash commands through `sentinel run` via `updatedInput`. It never sets a permission decision, so the user's
20
+ permission rules still apply. Watch/dev/serve, background, heredoc and `# sentinel:raw` commands are left alone.
21
+ - **Memory that survives compaction**: a `SessionStart` hook (startup | resume | clear | compact) re-injects the
22
+ open problem, already-tried approaches, the latest dead end and log pointers (`memoryTokenBudget` = 400).
23
+ Silent when nothing is pending.
24
+ - **Structured episodes**: compacted history keeps status (unresolved / reverted / resolved), the exact error
25
+ message and failing test names, not only a one-line summary.
26
+ - **A/B benchmark** (`bench/`): 5 debugging tasks × {baseline, sentinel} with Claude Code headless; isolated
27
+ temp repos, per-trial spend cap, tests restored before scoring, report with 95% CIs and a significance test.
28
+ `npm run bench:check` validates fixtures and plumbing for free (runs in CI).
29
+
30
+ ### Changed
31
+ - `install --claude` also registers PreToolUse for `Bash` and a `SessionStart` hook (re-run `install` to upgrade).
32
+ - `sentinel run --shell <sh>` runs a single command string through the given shell.
33
+
34
+ ## [0.1.1] - 2026-10-10
35
+
36
+ ### Added
37
+ - `sentinel uninstall [--claude|--cursor|--windsurf|--git|--all] [--global] [--purge] [--dry-run]`:
38
+ removes only what `install` added. Your own hooks, MCP servers and settings are
39
+ preserved, and a config file is deleted only if nothing but sentinel content was in it.
40
+ Recovery data (`.sentinel/`, `refs/sentinel/*` snapshots and rollback backups)
41
+ is kept unless `--purge` is given. Foreign git hooks and unparseable files are never touched.
42
+
43
+ ## [0.1.0] - 2026-10-10
8
44
 
9
45
  ### Added
10
46
  - Circuit breaker: line-reciprocity flip-flop detection, SHA-256 error
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  **English** | [繁體中文](./README.zh-TW.md)
4
4
 
5
- [![CI](https://github.com/T5A111/Token-Sentinel/actions/workflows/ci.yml/badge.svg)](https://github.com/T5A111/Token-Sentinel/actions/workflows/ci.yml)
5
+ [![CI](https://github.com/T5A111/Agent-Token-Sentinel/actions/workflows/ci.yml/badge.svg)](https://github.com/T5A111/Agent-Token-Sentinel/actions/workflows/ci.yml)
6
6
  [![npm](https://img.shields.io/npm/v/agent-token-sentinel.svg)](https://www.npmjs.com/package/agent-token-sentinel)
7
7
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
8
8
  ![Node](https://img.shields.io/badge/node-%E2%89%A520-339933)
@@ -13,7 +13,7 @@
13
13
  Everything runs on your machine: no external API calls, no telemetry. State lives in `.sentinel/` (git-ignored automatically).
14
14
 
15
15
  > **Status: beta (v0.1).** The core engine, MCP server, CLI and the Claude Code integration are covered by the test suite on Linux, macOS and Windows.
16
- > The **Cursor and Windsurf hook adapters are beta**: they are built against the published hook formats and tested with simulated payloads, but not yet verified end-to-end in those editors. Please [open an issue](https://github.com/T5A111/Token-Sentinel/issues) with your editor version if something doesn't trigger.
16
+ > The **Cursor and Windsurf hook adapters are beta**: they are built against the published hook formats and tested with simulated payloads, but not yet verified end-to-end in those editors. Please [open an issue](https://github.com/T5A111/Agent-Token-Sentinel/issues) with your editor version if something doesn't trigger.
17
17
 
18
18
  ---
19
19
 
@@ -32,11 +32,16 @@ Coding agents fail in two expensive ways:
32
32
  - 🧬 **Error fingerprints**: SHA-256 of `ErrorName + normalized message + project stack + failing test`, after stripping timestamps, absolute paths, `line:col`, memory addresses, UUIDs, durations, ports and temp dirs. Detects `A→A→A`, `A→B→A` and `A→B→A→B`.
33
33
  - ⚡ **Circuit breaker**: CLOSED → OPEN → HALF_OPEN, with manual reset (requires a new hypothesis) or a single probe after a cool-down.
34
34
  - ⏪ **Safe rollback**: git snapshots via a *temporary index* under `refs/sentinel/*`. Your branch, HEAD, index and stash are never touched. Only agent-touched files are restored, and a backup ref is taken first, so the rollback is itself undoable.
35
- - 🧪 **Log Distiller**: ANSI stripped; `node_modules`, `node:internal`, Vite/Rollup/Webpack/esbuild/Vitest/Jest frames dropped; keeps the error, the failing test, expected/received, and the **first project call site ±3 lines**. Typical reduction is 95%+.
35
+ - 🧪 **Log Distiller**: ANSI stripped; `node_modules`, `node:internal`, Vite/Rollup/Webpack/esbuild/Vitest/Jest frames dropped; keeps the error, the failing test, expected/received, the **first project call site ±3 lines**, and a one-line entry for **every other failing test**. Typical reduction is 95%+.
36
+ - 📈 **Dynamic budget, nothing lost**: the budget grows with the number of failures, and **widens each time the same failure repeats** (a stuck model needs more evidence, not less). Every raw log is stored; `sentinel_expand_log` pulls a specific failure block, a grep or a line range on demand, instead of re-running the command.
37
+ - 🔀 **Automatic in Claude Code**: build/test Bash commands are transparently routed through `sentinel run`, so the savings do not depend on the model remembering a rule. Same exit code, your permission rules still apply, `# sentinel:raw` opts out.
36
38
  - 🌳 **AST Pruner**: uses the TypeScript compiler API to keep target functions, classes or methods plus the same-file types and imports they reference; everything else becomes `// ... [omitted N lines of unrelated logic]`. Original line numbers are preserved. Other languages fall back to a brace/indent heuristic.
37
39
  - 🗜️ **Episodic History Compactor**: every 3 debug rounds →
38
40
  `[Compacted]: Rounds 1-3 attempted null-checks at src/auth.ts#login, failed with TypeError ×3. Reverted.`
41
+ Each episode also keeps its **status (unresolved / reverted / resolved), the exact error and the failing test**, so what was tried survives.
42
+ - 🧠 **Memory that survives compaction**: when Claude Code compacts, resumes or clears a session, a `SessionStart` hook re-injects the open problem, what was already tried and the latest dead end (≤ 400 tokens). Silent when nothing is pending.
39
43
  - 🔌 **Hard enforcement**: pre-write hooks for Claude Code, Cursor and Windsurf exit with code 2 to block writes while the circuit is OPEN. A git pre-commit hook rejects commits.
44
+ - 🧹 **Safe one-command uninstall**: `uninstall --all` removes only what `install` added; your own settings stay byte-for-byte unchanged, and recovery data is kept unless you ask for `--purge`. See [Uninstall](#uninstall).
40
45
 
41
46
  ## Architecture
42
47
 
@@ -79,7 +84,7 @@ npm install -g agent-token-sentinel && sentinel install --all
79
84
  **Option B: from source**
80
85
 
81
86
  ```bash
82
- git clone https://github.com/T5A111/Token-Sentinel.git && cd Token-Sentinel
87
+ git clone https://github.com/T5A111/Agent-Token-Sentinel.git && cd Agent-Token-Sentinel
83
88
  npm install && npm run build && npm link # `npm link` puts `sentinel` on your PATH
84
89
  cd ~/my-project && sentinel install --all
85
90
  ```
@@ -95,6 +100,8 @@ sentinel run -- npm test # or: npx agent-token-sentinel run -- npm test
95
100
 
96
101
  The exit code passes through unchanged, and a distilled failure is printed instead of the raw log.
97
102
 
103
+ > **Changed your mind?** `npx -y agent-token-sentinel uninstall --all` removes it again in one line and leaves your project as it was. Add `--dry-run` first to preview. See [Uninstall](#uninstall).
104
+
98
105
  ## Integration
99
106
 
100
107
  ### Claude Code
@@ -106,13 +113,17 @@ The exit code passes through unchanged, and a distilled failure is printed inste
106
113
  { "mcpServers": { "token-sentinel": { "command": "node", "args": ["/abs/path/dist/mcp/server.js"] } } }
107
114
  ```
108
115
 
109
- **`.claude/settings.json`** (hooks: PreToolUse blocks writes with exit 2 while OPEN; PostToolUse records edits and test runs)
116
+ **`.claude/settings.json`**. The hooks:
117
+ - **PreToolUse** blocks writes with exit 2 while OPEN, and routes build/test Bash commands through `sentinel run`.
118
+ - **PostToolUse** records edits and test runs.
119
+ - **SessionStart** re-injects the debugging memory after a compact, resume or clear.
110
120
  ```json
111
121
  {
112
122
  "hooks": {
113
- "PreToolUse": [{ "matcher": "Edit|MultiEdit|Write|NotebookEdit", "hooks": [{ "type": "command", "command": "node \"/abs/path/dist/cli/index.js\" hook claude", "timeout": 30 }] }],
123
+ "PreToolUse": [{ "matcher": "Edit|MultiEdit|Write|NotebookEdit|Bash", "hooks": [{ "type": "command", "command": "node \"/abs/path/dist/cli/index.js\" hook claude", "timeout": 30 }] }],
114
124
  "PostToolUse": [{ "matcher": "Edit|MultiEdit|Write|NotebookEdit|Bash", "hooks": [{ "type": "command", "command": "node \"/abs/path/dist/cli/index.js\" hook claude", "timeout": 30 }] }],
115
- "PostToolUseFailure": [{ "matcher": "Bash", "hooks": [{ "type": "command", "command": "node \"/abs/path/dist/cli/index.js\" hook claude", "timeout": 30 }] }]
125
+ "PostToolUseFailure": [{ "matcher": "Bash", "hooks": [{ "type": "command", "command": "node \"/abs/path/dist/cli/index.js\" hook claude", "timeout": 30 }] }],
126
+ "SessionStart": [{ "matcher": "startup|resume|clear|compact", "hooks": [{ "type": "command", "command": "node \"/abs/path/dist/cli/index.js\" hook claude", "timeout": 30 }] }]
116
127
  }
117
128
  }
118
129
  ```
@@ -164,7 +175,7 @@ Windsurf reads MCP servers only from the user-global `~/.codeium/windsurf/mcp_co
164
175
 
165
176
  | Client | MCP tools | Hard write block | Auto-record edits | Auto-record test runs |
166
177
  |---|---|---|---|---|
167
- | Claude Code | ✅ | ✅ PreToolUse exit 2 | ✅ PostToolUse | ✅ (`sentinel run` for exact exit codes) |
178
+ | Claude Code | ✅ | ✅ PreToolUse exit 2 | ✅ PostToolUse | ✅ auto-routed through `sentinel run` (exact exit codes, distilled output) |
168
179
  | Cursor *(beta)* | ✅ | ✅ preToolUse exit 2 / `deny` | ✅ afterFileEdit | ✅ afterShellExecution |
169
180
  | Windsurf *(beta)* | ✅ (global config) | ✅ pre_write_code exit 2 | ✅ post_write_code | ✅ post_run_command |
170
181
  | Other MCP clients | ✅ | advisory (`sentinel_guard_edit`) | `sentinel_record_edit` | `sentinel_record_run` / `sentinel run` |
@@ -172,6 +183,61 @@ Windsurf reads MCP servers only from the user-global `~/.codeium/windsurf/mcp_co
172
183
 
173
184
  > Hook payload fields differ between clients and versions, so they are parsed tolerantly. When a client does not report a command's exit code, failure is inferred from the output (`FAIL`, `error TS…`, `Traceback`, …). For exact results, run tests through `sentinel run -- <cmd>`; those runs are recorded once and skipped by the post-command hooks.
174
185
 
186
+ ## Uninstall
187
+
188
+ > Requires v0.1.1 or later. Check with `npx -y agent-token-sentinel version`.
189
+
190
+ **Step 1: preview** (changes nothing):
191
+
192
+ ```bash
193
+ npx -y agent-token-sentinel uninstall --all --dry-run
194
+ ```
195
+
196
+ **Step 2: remove**, then **restart** Claude Code / Cursor / Windsurf so they stop loading the hooks and MCP server:
197
+
198
+ ```bash
199
+ npx -y agent-token-sentinel uninstall --all
200
+ ```
201
+
202
+ Run the command in each project where you ran `install`. If you installed globally or from source, `sentinel uninstall --all` does the same.
203
+
204
+ ### Common cases
205
+
206
+ | I want to… | Command |
207
+ |---|---|
208
+ | Preview what would be removed | `npx -y agent-token-sentinel uninstall --all --dry-run` |
209
+ | Remove everything from this project (keep recovery data) | `npx -y agent-token-sentinel uninstall --all` |
210
+ | Remove from one editor only | `npx -y agent-token-sentinel uninstall --claude` (or `--cursor`, `--windsurf`, `--git`, combinable) |
211
+ | Also delete `.sentinel/` and all git snapshots / rollback backups | `npx -y agent-token-sentinel uninstall --all --purge` |
212
+ | Also clean Windsurf's user-global MCP config | `npx -y agent-token-sentinel uninstall --windsurf --global` |
213
+ | Uninstall a project other than the current directory | `npx -y agent-token-sentinel uninstall --all --root /path/to/project` |
214
+ | Remove the package itself (global install) | `npm uninstall -g agent-token-sentinel` |
215
+ | Remove the package itself (installed from source with `npm link`) | `npm unlink -g agent-token-sentinel`, then delete the cloned folder |
216
+
217
+ Run `uninstall` in your projects **before** removing the package itself; otherwise the `sentinel` command is no longer available (`npx -y agent-token-sentinel …` still works).
218
+
219
+ ### What it does, and what it never does
220
+
221
+ - **Removes only what `install` added**: sentinel hook entries, the `token-sentinel` MCP server, `SKILL.md`, the Cursor/Windsurf rules files and the sentinel `pre-commit` hook.
222
+ - **Your own hooks, MCP servers and settings stay byte-for-byte unchanged.** A config file is deleted only if nothing else was in it, and a folder only if it ends up empty.
223
+ - **Recovery data is kept by default**: `.sentinel/` (state, Dead-End logs) and the `refs/sentinel/*` git snapshots. These include the rollback backups of any agent edits the breaker reverted. Use `--purge` only once you are sure you don't need them.
224
+ - **Foreign git hooks and unparseable config files are never touched.** They are listed as warnings, and the command exits with code 1 so you notice.
225
+ - It never commits, never touches your branch, HEAD, index or stash, and never edits your source code. Uninstalling leaves your project exactly as it was.
226
+
227
+ <details>
228
+ <summary>Manual removal (if you cannot run the command)</summary>
229
+
230
+ | Location | What to remove |
231
+ |---|---|
232
+ | `.claude/settings.json`, `.cursor/hooks.json`, `.windsurf/hooks.json` | Only the entries whose command contains `hook claude`, `hook cursor` or `hook windsurf` |
233
+ | `.mcp.json`, `.cursor/mcp.json`, `~/.codeium/windsurf/mcp_config.json` | The `token-sentinel` entry under `mcpServers` |
234
+ | `.claude/skills/token-sentinel/`, `.cursor/rules/token-sentinel.mdc`, `.windsurf/rules/token-sentinel.md` | Delete |
235
+ | `.git/hooks/pre-commit` | Delete only if it contains `# agent-token-sentinel pre-commit` |
236
+ | `.sentinel/` | Delete (optional; state and Dead-End logs) |
237
+ | `refs/sentinel/*` | `git for-each-ref --format="%(refname)" refs/sentinel/` lists them; delete each with `git update-ref -d <ref>` (optional; includes rollback backups) |
238
+
239
+ </details>
240
+
175
241
  ## MCP interface
176
242
 
177
243
  | Tool | Purpose |
@@ -183,6 +249,7 @@ Windsurf reads MCP servers only from the user-global `~/.codeium/windsurf/mcp_co
183
249
  | `sentinel_reset_circuit {hypothesis}` | Close the circuit; requires a new root-cause hypothesis (≥ 15 chars). |
184
250
  | `sentinel_checkpoint {label?}` | Snapshot the working tree as a rollback target. |
185
251
  | `sentinel_distill_log {log, tokenBudget?}` | Compress a log. |
252
+ | `sentinel_expand_log {run?, failure?, grep?, from?, to?}` | Pull part of a stored raw log (a failure block, matching lines, a range) instead of re-running. |
186
253
  | `sentinel_prune_file {file, targets[], lineNumbers?}` | Read only the needed symbols. |
187
254
  | `sentinel_compact_history {}` | Fold old rounds into `[Compacted]` lines. |
188
255
 
@@ -193,8 +260,10 @@ Resources: `sentinel://state`, `sentinel://dead-ends`, `sentinel://history`.
193
260
  ```
194
261
  sentinel run [--raw] -- <cmd...> sentinel status [--json] sentinel reset [--hypothesis "..."]
195
262
  sentinel checkpoint [label] sentinel rollback [id] sentinel distill [file|-] [--budget N]
263
+ sentinel log [run-id] [--failure N] [--grep RE] [--from N --to M]
196
264
  sentinel prune <file> <symbol...> sentinel compact | history sentinel dead-ends
197
265
  sentinel install [--claude|--cursor|--windsurf|--git|--all] [--global] [--command "..."] [--dry-run]
266
+ sentinel uninstall [--claude|--cursor|--windsurf|--git|--all] [--global] [--purge] [--dry-run]
198
267
  sentinel hook <claude|cursor|windsurf|git-pre-commit> [--event name]
199
268
  sentinel mcp
200
269
  ```
@@ -214,7 +283,11 @@ All fields are optional. An invalid file falls back to the defaults and shows a
214
283
  | `hotspotRounds` | `3` | Consecutive failing rounds editing the same function → HIGH-risk warning. |
215
284
  | `cooldownMs` | `300000` | Time OPEN before one HALF_OPEN probe is allowed. |
216
285
  | `autoRollback` | `true` | Restore agent-touched files on trip (`false` = block only). |
217
- | `distillTokenBudget` | `150` | Max tokens of a distilled log. |
286
+ | `distillTokenBudget` | `150` | Base budget of a distilled log (one failure, first sighting). |
287
+ | `distillMaxBudget` | `600` | Ceiling after scaling: +30 tokens per extra failure, +50% per repeat of the same failure. |
288
+ | `maxLogs` | `30` | Raw logs kept in `.sentinel/logs/` for `sentinel_expand_log`. |
289
+ | `autoWrapTests` | `true` | Claude Code: route build/test Bash commands through `sentinel run`. |
290
+ | `memoryTokenBudget` | `400` | Max size of the memory re-injected after compaction / resume. |
218
291
  | `compactEvery` | `3` | Debug rounds per compacted episode. |
219
292
  | `contextLines` | `3` | Source lines shown around the call site. |
220
293
  | `maxCheckpoints` | `20` | Checkpoint refs kept. |
@@ -241,9 +314,25 @@ The suite (`tests/self-test.ts`) covers the four required scenarios plus rollbac
241
314
  | 4 | 4 consecutive failures | OPEN, Dead-End JSON+MD, writes blocked (Claude/Cursor/Windsurf hooks exit 2), HALF_OPEN, reset |
242
315
  | 5 | real git repo | agent files restored, new file removed, human edit untouched, HEAD/index/stash untouched, backup ref |
243
316
  | 6 | 252-line TS file | target + transitively referenced types + used import kept; the rest folded |
244
- | 7 | 6 debug rounds | auto `[Compacted]` after round 4; ≥ 70% of history tokens freed (82.6%) |
317
+ | 7 | 6 debug rounds | auto `[Compacted]` after round 4 with status + error evidence; ≥ 70% of recorded history tokens saved (82%) |
245
318
  | 8 | MCP client ↔ server | all tools listed and callable; validation and path-traversal errors are tool errors |
246
319
  | 9 | `sentinel run`, `install --all`, git pre-commit | exit code passthrough, distilled output, idempotent config merge, commit rejected while OPEN |
320
+ | 10 | install over existing user configs → `uninstall` | dry-run changes nothing; user files byte-identical afterwards; `.sentinel/` + refs kept until `--purge`; foreign hooks and broken files untouched |
321
+ | 11 | 4 failing tests in one log | all 4 listed; budget scales; raw log stored, failure #3 / grep / ranges expandable; old logs pruned |
322
+ | 12 | same failure 3× | budget and source context widen each time (±3 → ±5 → ±7 lines); a new failure resets it |
323
+ | 13 | Claude Code Bash `npm test` | rewritten via `updatedInput` without auto-approval; watch/dev/background/heredoc/opt-out untouched; quoting + exit code identical under bash |
324
+ | 14 | compact/resume after 4 failures | open problem, tried approaches and log pointer injected within budget; silent on clean projects and once green |
325
+
326
+ ### A/B benchmark (does it actually help?)
327
+
328
+ The self-tests prove the mechanisms work. They do **not** prove that a model solves more tasks or spends less. For that, `bench/` holds 5 debugging tasks, each built around a typical agent failure mode: off-by-one, a shared root cause that invites whack-a-mole, an async cache bug, 4 independent bugs, and a misleading stack trace. The runner executes the same model on the same tasks **with and without** the sentinel:
329
+
330
+ ```bash
331
+ npm run bench:check # free: validates fixtures + plumbing with a stub (also in CI)
332
+ npm run bench -- --repeats 5 --model <model-id> # real run with Claude Code headless: costs your Claude usage
333
+ ```
334
+
335
+ Each trial runs in an isolated temp git repo. The user's global settings and MCP servers are excluded in both arms, and spend is capped per trial (`--max-budget-usd`, default $2). The original tests are restored before scoring, so editing the tests never counts as a fix. The report lists success rate with 95% CIs, cost, input tokens (cache included), turns, breaker trips and a two-proportion significance test. With few repeats it says plainly that the result is a smoke test, not proof.
247
336
 
248
337
  ## Project layout
249
338
 
@@ -263,6 +352,8 @@ SKILL.md rules for the agent
263
352
  ## Limitations
264
353
 
265
354
  - Token counts are estimated offline (~4 chars/token, CJK ≈ 1 token/char), with roughly ±15% error.
355
+ - The history compactor cannot delete anything from the agent's own transcript; the client manages that. The "tokens saved" figure is accounting over recorded history. It becomes real when the model works from the compacted view: after Claude Code compacts or resumes (the memory is injected automatically), or when the model reads `sentinel://history`.
356
+ - Measured savings depend on your model, tasks and prompt caching. Run the A/B benchmark on your own workload before relying on a number.
266
357
  - Rollback needs a git repository. Without one, the sentinel runs in block-only mode.
267
358
  - Precise AST pruning covers TS/JS (`.ts .tsx .js .jsx .mts .cts .mjs .cjs`). Other languages use a heuristic.
268
359
  - An agent determined to bypass the guard (e.g. writing files through the shell) can still do so. The hooks gate the editor's write tools, and the git hook gates commits.
package/README.zh-TW.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [English](./README.md) | **繁體中文**
4
4
 
5
- [![CI](https://github.com/T5A111/Token-Sentinel/actions/workflows/ci.yml/badge.svg)](https://github.com/T5A111/Token-Sentinel/actions/workflows/ci.yml)
5
+ [![CI](https://github.com/T5A111/Agent-Token-Sentinel/actions/workflows/ci.yml/badge.svg)](https://github.com/T5A111/Agent-Token-Sentinel/actions/workflows/ci.yml)
6
6
  [![npm](https://img.shields.io/npm/v/agent-token-sentinel.svg)](https://www.npmjs.com/package/agent-token-sentinel)
7
7
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
8
8
  ![Node](https://img.shields.io/badge/node-%E2%89%A520-339933)
@@ -13,7 +13,7 @@
13
13
  所有分析都在本機完成:不呼叫任何外部 API,也沒有遙測。狀態存放在 `.sentinel/`,並自動排除在 git 之外。
14
14
 
15
15
  > **狀態:Beta(v0.1)。** 核心引擎、MCP Server、CLI 與 Claude Code 整合都有測試覆蓋,並在 Linux、macOS、Windows 上執行。
16
- > **Cursor 與 Windsurf 的 Hook 整合為 Beta**:依照官方公布的 Hook 格式實作,並用模擬資料測試過,但還沒在這兩個編輯器中做過完整的實機驗證。如果 Hook 沒有觸發,歡迎[開 Issue](https://github.com/T5A111/Token-Sentinel/issues) 並附上編輯器版本。
16
+ > **Cursor 與 Windsurf 的 Hook 整合為 Beta**:依照官方公布的 Hook 格式實作,並用模擬資料測試過,但還沒在這兩個編輯器中做過完整的實機驗證。如果 Hook 沒有觸發,歡迎[開 Issue](https://github.com/T5A111/Agent-Token-Sentinel/issues) 並附上編輯器版本。
17
17
 
18
18
  ---
19
19
 
@@ -32,11 +32,16 @@ Coding Agent 最常在兩件事上浪費最多:
32
32
  - 🧬 **報錯指紋**:先剝離時間戳、絕對路徑、`行:列`、記憶體位址、UUID、耗時、port、暫存目錄,再對 `ErrorName + 正規化訊息 + 專案內 stack + 失敗測試名` 計算 SHA-256。可偵測 `A→A→A`、`A→B→A`、`A→B→A→B` 三種模式。
33
33
  - ⚡ **熔斷器**:CLOSED → OPEN → HALF_OPEN 三態。可手動重置(必須提出新的假設),或在冷卻後給一次試探機會。
34
34
  - ⏪ **安全回滾**:用「暫存 index」建立 git 快照,存在 `refs/sentinel/*`。**絕不動**你的分支、HEAD、index 和 stash。只還原 Agent 動過的檔案,回滾前會先建立備份 ref,所以回滾本身也能復原。
35
- - 🧪 **日誌蒸餾**:去除 ANSI 碼;剔除 `node_modules`、`node:internal`、Vite/Rollup/Webpack/esbuild/Vitest/Jest 內部 frame;保留錯誤訊息、失敗的測試、expected/received,以及**第一個專案呼叫點前後 3 行**。壓縮率通常在 95% 以上。
35
+ - 🧪 **日誌蒸餾**:去除 ANSI 碼;剔除 `node_modules`、`node:internal`、Vite/Rollup/Webpack/esbuild/Vitest/Jest 內部 frame;保留錯誤訊息、失敗的測試、expected/received、**第一個專案呼叫點前後 3 行**,並把**其他每個失敗的測試**各列成一行。壓縮率通常在 95% 以上。
36
+ - 📈 **動態預算,資訊不遺失**:失敗越多預算越大,**同一個錯誤每重複一次預算就再加大**,因為卡住的模型需要更多線索,而不是更少。每份原始日誌都會保存,`sentinel_expand_log` 可以按需取出指定的失敗區塊、搜尋結果或行數範圍,不必重跑指令。
37
+ - 🔀 **Claude Code 上自動生效**:建置/測試的 Bash 指令會自動改走 `sentinel run`,省 Token 不必靠模型記得規則。exit code 不變,你的權限設定照樣有效;指令裡加上 `# sentinel:raw` 就會略過。
36
38
  - 🌳 **AST 局部裁剪**:用 TypeScript Compiler API 只保留目標函式、類別或方法,加上它們引用到的同檔型別與 import。其餘程式碼摺疊為 `// ... [omitted N lines of unrelated logic]`,並保留原始行號。其他語言改用大括號或縮排的啟發式方法。
37
39
  - 🗜️ **歷史斷代壓縮**:每 3 輪除錯自動產生一行摘要,例如:
38
40
  `[Compacted]: Rounds 1-3 attempted null-checks at src/auth.ts#login, failed with TypeError ×3. Reverted.`
41
+ 每段摘要也會保留**狀態(未解決/已回滾/已解決)、確切的錯誤訊息和失敗的測試名稱**,讓「試過什麼」不會遺失。
42
+ - 🧠 **對話壓縮後記憶仍在**:Claude Code 壓縮、恢復或清除對話時,`SessionStart` Hook 會重新注入目前的問題、已經試過的方法和最近的 Dead-End(≤ 400 Token)。沒有待處理的問題時不會輸出任何內容。
39
43
  - 🔌 **硬性攔截**:Claude Code、Cursor、Windsurf 的寫入前 Hook 在熔斷 OPEN 時以 exit code 2 阻擋寫入;git pre-commit hook 會拒絕提交。
44
+ - 🧹 **一鍵安全移除**:`uninstall --all` 只移除 `install` 加入的東西,你自己的設定一個字都不動;除非加 `--purge`,否則會保留復原資料。詳見[移除](#移除)。
40
45
 
41
46
  ## 架構
42
47
 
@@ -79,7 +84,7 @@ npm install -g agent-token-sentinel && sentinel install --all
79
84
  **方式 B:從原始碼安裝**
80
85
 
81
86
  ```bash
82
- git clone https://github.com/T5A111/Token-Sentinel.git && cd Token-Sentinel
87
+ git clone https://github.com/T5A111/Agent-Token-Sentinel.git && cd Agent-Token-Sentinel
83
88
  npm install && npm run build && npm link # `npm link` 會把 `sentinel` 指令加入 PATH
84
89
  cd ~/my-project && sentinel install --all
85
90
  ```
@@ -95,6 +100,8 @@ sentinel run -- npm test # 或:npx agent-token-sentinel run -- npm test
95
100
 
96
101
  exit code 會原樣傳回;失敗時印出蒸餾後的錯誤,而不是原始日誌。
97
102
 
103
+ > **試用後不想要了?** 執行 `npx -y agent-token-sentinel uninstall --all` 就能一行移除,專案會恢復成安裝前的樣子。建議先加 `--dry-run` 預覽。詳見[移除](#移除)。
104
+
98
105
  ## 整合設定
99
106
 
100
107
  ### Claude Code
@@ -106,13 +113,17 @@ exit code 會原樣傳回;失敗時印出蒸餾後的錯誤,而不是原始
106
113
  { "mcpServers": { "token-sentinel": { "command": "node", "args": ["/abs/path/dist/mcp/server.js"] } } }
107
114
  ```
108
115
 
109
- **`.claude/settings.json`**:PreToolUse 在 OPEN 時以 exit 2 阻擋寫入;PostToolUse 記錄每次修改與測試結果。
116
+ **`.claude/settings.json`** 裡的 Hook:
117
+ - **PreToolUse**:OPEN 時以 exit 2 阻擋寫入,並把建置/測試的 Bash 指令改走 `sentinel run`。
118
+ - **PostToolUse**:記錄每次修改與測試結果。
119
+ - **SessionStart**:對話被壓縮、恢復或清除後,重新注入除錯記憶。
110
120
  ```json
111
121
  {
112
122
  "hooks": {
113
- "PreToolUse": [{ "matcher": "Edit|MultiEdit|Write|NotebookEdit", "hooks": [{ "type": "command", "command": "node \"/abs/path/dist/cli/index.js\" hook claude", "timeout": 30 }] }],
123
+ "PreToolUse": [{ "matcher": "Edit|MultiEdit|Write|NotebookEdit|Bash", "hooks": [{ "type": "command", "command": "node \"/abs/path/dist/cli/index.js\" hook claude", "timeout": 30 }] }],
114
124
  "PostToolUse": [{ "matcher": "Edit|MultiEdit|Write|NotebookEdit|Bash", "hooks": [{ "type": "command", "command": "node \"/abs/path/dist/cli/index.js\" hook claude", "timeout": 30 }] }],
115
- "PostToolUseFailure": [{ "matcher": "Bash", "hooks": [{ "type": "command", "command": "node \"/abs/path/dist/cli/index.js\" hook claude", "timeout": 30 }] }]
125
+ "PostToolUseFailure": [{ "matcher": "Bash", "hooks": [{ "type": "command", "command": "node \"/abs/path/dist/cli/index.js\" hook claude", "timeout": 30 }] }],
126
+ "SessionStart": [{ "matcher": "startup|resume|clear|compact", "hooks": [{ "type": "command", "command": "node \"/abs/path/dist/cli/index.js\" hook claude", "timeout": 30 }] }]
116
127
  }
117
128
  }
118
129
  ```
@@ -164,7 +175,7 @@ Windsurf 的 MCP 設定**只有全域檔** `~/.codeium/windsurf/mcp_config.json`
164
175
 
165
176
  | 客戶端 | MCP 工具 | 硬性阻擋寫入 | 自動記錄修改 | 自動記錄測試 |
166
177
  |---|---|---|---|---|
167
- | Claude Code | ✅ | ✅ PreToolUse exit 2 | ✅ PostToolUse | ✅(要精確的 exit code,請用 `sentinel run`) |
178
+ | Claude Code | ✅ | ✅ PreToolUse exit 2 | ✅ PostToolUse | ✅ 自動改走 `sentinel run`(exit code 精確、輸出已蒸餾) |
168
179
  | Cursor *(Beta)* | ✅ | ✅ preToolUse exit 2 / `deny` | ✅ afterFileEdit | ✅ afterShellExecution |
169
180
  | Windsurf *(Beta)* | ✅(全域設定) | ✅ pre_write_code exit 2 | ✅ post_write_code | ✅ post_run_command |
170
181
  | 其他 MCP 客戶端 | ✅ | 僅勸導(`sentinel_guard_edit`) | `sentinel_record_edit` | `sentinel_record_run` / `sentinel run` |
@@ -172,6 +183,61 @@ Windsurf 的 MCP 設定**只有全域檔** `~/.codeium/windsurf/mcp_config.json`
172
183
 
173
184
  > 各客戶端、各版本送給 Hook 的 payload 欄位都不同,因此採用寬鬆解析。若客戶端沒有提供指令的 exit code,會從輸出內容(`FAIL`、`error TS…`、`Traceback` 等)推斷是否失敗。需要精確結果時,請用 `sentinel run -- <cmd>` 執行測試;這類執行只會記錄一次,post-command hook 會自動略過。
174
185
 
186
+ ## 移除
187
+
188
+ > 需要 v0.1.1 以上版本。可以用 `npx -y agent-token-sentinel version` 確認。
189
+
190
+ **第 1 步:預覽**(不會改動任何檔案)
191
+
192
+ ```bash
193
+ npx -y agent-token-sentinel uninstall --all --dry-run
194
+ ```
195
+
196
+ **第 2 步:正式移除**,完成後**重開** Claude Code/Cursor/Windsurf,它們才會停止載入 Hook 與 MCP server:
197
+
198
+ ```bash
199
+ npx -y agent-token-sentinel uninstall --all
200
+ ```
201
+
202
+ 每個執行過 `install` 的專案都要各自執行一次。如果是全域安裝或從原始碼安裝,也可以用 `sentinel uninstall --all`,效果相同。
203
+
204
+ ### 常見情境
205
+
206
+ | 我想要… | 指令 |
207
+ |---|---|
208
+ | 先預覽會移除哪些東西 | `npx -y agent-token-sentinel uninstall --all --dry-run` |
209
+ | 從目前專案移除全部(保留復原資料) | `npx -y agent-token-sentinel uninstall --all` |
210
+ | 只移除某一個編輯器的設定 | `npx -y agent-token-sentinel uninstall --claude`(或 `--cursor`、`--windsurf`、`--git`,可以同時加多個) |
211
+ | 連 `.sentinel/` 和所有 git 快照、回滾備份一起刪除 | `npx -y agent-token-sentinel uninstall --all --purge` |
212
+ | 一併清理 Windsurf 的全域 MCP 設定 | `npx -y agent-token-sentinel uninstall --windsurf --global` |
213
+ | 移除不在目前資料夾的專案 | `npx -y agent-token-sentinel uninstall --all --root C:\path\to\project` |
214
+ | 移除套件本身(全域安裝) | `npm uninstall -g agent-token-sentinel` |
215
+ | 移除套件本身(從原始碼用 `npm link` 安裝) | `npm unlink -g agent-token-sentinel`,再刪除 clone 下來的資料夾 |
216
+
217
+ 請**先**在各專案執行 `uninstall`,**再**移除套件本身。順序反過來的話,`sentinel` 指令已經不在了,不過 `npx -y agent-token-sentinel …` 仍然可以用。
218
+
219
+ ### 會做什麼、絕對不會做什麼
220
+
221
+ - **只移除 `install` 加入的東西**:Sentinel 的 Hook 項目、`token-sentinel` MCP server、`SKILL.md`、Cursor/Windsurf 規則檔,以及 Sentinel 的 `pre-commit` hook。
222
+ - **你自己的 Hook、MCP server 和其他設定一個字都不動。** 設定檔只有在裡面沒有其他內容時才會刪除,資料夾也只有在變成空的時候才會刪除。
223
+ - **預設保留復原資料**:`.sentinel/`(狀態與 Dead-End 紀錄)和 `refs/sentinel/*` 這些 git 快照,其中包含熔斷器回滾 Agent 修改前的備份。確定用不到了,再加 `--purge` 刪除。
224
+ - **不是 Sentinel 建立的 git hook,以及無法解析的設定檔,一律不動。** 它們會列在警告裡,指令也會以 exit code 1 結束,提醒你注意。
225
+ - 不會 commit,不會動你的分支、HEAD、index、stash,也不會修改你的原始碼。移除後專案會和安裝前完全一樣。
226
+
227
+ <details>
228
+ <summary>手動移除(無法執行指令時的備案)</summary>
229
+
230
+ | 位置 | 要刪除的內容 |
231
+ |---|---|
232
+ | `.claude/settings.json`、`.cursor/hooks.json`、`.windsurf/hooks.json` | 只刪指令含 `hook claude`、`hook cursor` 或 `hook windsurf` 的項目 |
233
+ | `.mcp.json`、`.cursor/mcp.json`、`~/.codeium/windsurf/mcp_config.json` | `mcpServers` 底下的 `token-sentinel` 這一項 |
234
+ | `.claude/skills/token-sentinel/`、`.cursor/rules/token-sentinel.mdc`、`.windsurf/rules/token-sentinel.md` | 直接刪除 |
235
+ | `.git/hooks/pre-commit` | 檔案內含 `# agent-token-sentinel pre-commit` 才刪除 |
236
+ | `.sentinel/` | 刪除(選擇性;狀態與 Dead-End 紀錄) |
237
+ | `refs/sentinel/*` | 用 `git for-each-ref --format="%(refname)" refs/sentinel/` 列出,再逐一執行 `git update-ref -d <ref>` 刪除(選擇性;包含回滾備份) |
238
+
239
+ </details>
240
+
175
241
  ## MCP 介面
176
242
 
177
243
  | Tool | 用途 |
@@ -183,6 +249,7 @@ Windsurf 的 MCP 設定**只有全域檔** `~/.codeium/windsurf/mcp_config.json`
183
249
  | `sentinel_reset_circuit {hypothesis}` | 關閉熔斷;必須提出新的根因假設(至少 15 字元)。 |
184
250
  | `sentinel_checkpoint {label?}` | 建立工作區快照,作為回滾目標。 |
185
251
  | `sentinel_distill_log {log, tokenBudget?}` | 壓縮日誌。 |
252
+ | `sentinel_expand_log {run?, failure?, grep?, from?, to?}` | 取出已保存原始日誌的一部分(某個失敗區塊、符合的行、行數範圍),不必重跑。 |
186
253
  | `sentinel_prune_file {file, targets[], lineNumbers?}` | 只讀取需要的符號。 |
187
254
  | `sentinel_compact_history {}` | 把舊回合濃縮成 `[Compacted]` 摘要。 |
188
255
 
@@ -193,8 +260,10 @@ Resources:`sentinel://state`、`sentinel://dead-ends`、`sentinel://history`
193
260
  ```
194
261
  sentinel run [--raw] -- <cmd...> sentinel status [--json] sentinel reset [--hypothesis "..."]
195
262
  sentinel checkpoint [label] sentinel rollback [id] sentinel distill [file|-] [--budget N]
263
+ sentinel log [run-id] [--failure N] [--grep RE] [--from N --to M]
196
264
  sentinel prune <file> <symbol...> sentinel compact | history sentinel dead-ends
197
265
  sentinel install [--claude|--cursor|--windsurf|--git|--all] [--global] [--command "..."] [--dry-run]
266
+ sentinel uninstall [--claude|--cursor|--windsurf|--git|--all] [--global] [--purge] [--dry-run]
198
267
  sentinel hook <claude|cursor|windsurf|git-pre-commit> [--event name]
199
268
  sentinel mcp
200
269
  ```
@@ -214,7 +283,11 @@ sentinel mcp
214
283
  | `hotspotRounds` | `3` | 同一函式連續幾輪被修改且失敗,就發出 HIGH 風險警告。 |
215
284
  | `cooldownMs` | `300000` | OPEN 多久之後允許一次 HALF_OPEN 試探。 |
216
285
  | `autoRollback` | `true` | 熔斷時是否還原 Agent 動過的檔案(設為 `false` 則只阻擋寫入)。 |
217
- | `distillTokenBudget` | `150` | 蒸餾後日誌的 Token 上限。 |
286
+ | `distillTokenBudget` | `150` | 蒸餾後日誌的基本預算(單一失敗、第一次出現時)。 |
287
+ | `distillMaxBudget` | `600` | 放大後的上限:每多一個失敗 +30 Token,同一個錯誤每重複一次 +50%。 |
288
+ | `maxLogs` | `30` | `.sentinel/logs/` 保留幾份原始日誌供 `sentinel_expand_log` 使用。 |
289
+ | `autoWrapTests` | `true` | Claude Code:把建置/測試的 Bash 指令改走 `sentinel run`。 |
290
+ | `memoryTokenBudget` | `400` | 對話壓縮或恢復後注入的記憶大小上限。 |
218
291
  | `compactEvery` | `3` | 每幾輪除錯壓縮成一段摘要。 |
219
292
  | `contextLines` | `3` | 呼叫點前後顯示幾行原始碼。 |
220
293
  | `maxCheckpoints` | `20` | 最多保留幾個 checkpoint ref。 |
@@ -246,9 +319,25 @@ CI 會在 Linux、macOS、Windows 上,以 Node 20、22、24 執行以上兩組
246
319
  | 4 | 連續失敗 4 次 | 進入 OPEN、產出 Dead-End JSON+MD、寫入被阻擋(三家 Hook 皆 exit 2)、HALF_OPEN 試探、重置成功 |
247
320
  | 5 | 真實 git repo | Agent 改的檔案被還原、新建檔案被移除、人工修改不受影響、HEAD/index/stash 未被動到、備份 ref 存在 |
248
321
  | 6 | 252 行 TS 檔 | 保留目標函式、遞移引用的型別與用到的 import,其餘摺疊 |
249
- | 7 | 6 輪除錯 | 第 4 輪後自動產生 `[Compacted]` 摘要;釋放 ≥ 70% 歷史 Token(實測 82.6%) |
322
+ | 7 | 6 輪除錯 | 第 4 輪後自動產生含狀態與錯誤證據的 `[Compacted]` 摘要;已記錄的歷史省下 ≥ 70% Token(實測 82%) |
250
323
  | 8 | MCP client ↔ server | 所有工具都能列出並呼叫;參數驗證失敗與路徑穿越都以 tool error 回傳 |
251
324
  | 9 | `sentinel run`、`install --all`、git pre-commit | exit code 原樣傳回、輸出已蒸餾、設定合併可重複執行、OPEN 時拒絕提交 |
325
+ | 10 | 在使用者既有設定上安裝後再 `uninstall` | 預覽模式不改任何檔案;使用者檔案逐字還原;`.sentinel/` 與快照保留到 `--purge`;別人的 hook 與壞掉的設定檔不受影響 |
326
+ | 11 | 一份日誌裡有 4 個失敗測試 | 4 個全部列出;預算隨之放大;原始日誌已保存,可取出第 3 個失敗、搜尋或指定範圍;舊日誌自動清理 |
327
+ | 12 | 同一個錯誤出現 3 次 | 預算與原始碼上下文逐次加大(±3 → ±5 → ±7 行);出現新錯誤時重置 |
328
+ | 13 | Claude Code 執行 `npm test` | 透過 `updatedInput` 改寫且不自動允許;watch/dev/背景執行/heredoc/明確略過的指令不動;在 bash 下引號與 exit code 完全一致 |
329
+ | 14 | 4 次失敗後壓縮或恢復對話 | 在預算內注入目前的問題、試過的方法和日誌位置;乾淨的專案和測試通過後不輸出 |
330
+
331
+ ### A/B Benchmark(實際上到底有沒有幫助?)
332
+
333
+ 自我測試只能證明機制正確運作,**不能**證明模型因此解出更多題目或花得更少。`bench/` 裡有 5 個除錯任務,各自對應一種常見的 Agent 失敗模式:差一錯誤(off-by-one)、容易打地鼠的共同根因、非同步快取錯誤、4 個獨立 bug、誤導性的堆疊。執行器會讓同一個模型在**有裝和沒裝** Sentinel 的情況下,跑同樣的任務:
334
+
335
+ ```bash
336
+ npm run bench:check # 免費:用替身驗證任務與流程(CI 也會跑)
337
+ npm run bench -- --repeats 5 --model <model-id> # 以 Claude Code 非互動模式實際執行:會花你的 Claude 用量
338
+ ```
339
+
340
+ 每次試驗都在獨立的臨時 git repo 裡執行。兩組都排除你的全域設定和 MCP server,每次花費有上限(`--max-budget-usd`,預設 $2)。計分前會還原原本的測試檔,改測試永遠不算修好。報告會列出成功率(含 95% 信賴區間)、花費、輸入 Token(含快取)、回合數、熔斷次數,以及雙比例顯著性檢定。重複次數太少時,報告會直接寫明這只是初步檢查,不能當作證明。
252
341
 
253
342
  ## 目錄結構
254
343
 
@@ -268,6 +357,8 @@ SKILL.md 給 Agent 的規則
268
357
  ## 已知限制
269
358
 
270
359
  - Token 數是離線估算(約 4 字元算 1 Token,中日韓文字約 1 字算 1 Token),誤差約 ±15%。
360
+ - 歷史壓縮器無法刪除 Agent 自己對話紀錄裡的內容,那是由客戶端管理的。「省下的 Token」是針對已記錄歷史的計算,只有在模型改用壓縮後的版本時才會真正生效:例如 Claude Code 壓縮或恢復對話之後(記憶會自動注入),或模型主動讀取 `sentinel://history`。
361
+ - 實際省多少取決於你用的模型、任務類型和提示快取。依賴任何數字之前,請先用 A/B Benchmark 在自己的工作上實測。
271
362
  - 回滾需要 git repo;沒有 git 時只會阻擋寫入,不會回滾。
272
363
  - 精確的 AST 裁剪只支援 TS/JS(`.ts .tsx .js .jsx .mts .cts .mjs .cjs`),其他語言改用啟發式方法。
273
364
  - 刻意繞過的 Agent(例如直接用 shell 寫檔)仍然擋不住。Hook 只能管住編輯器的寫入工具,git hook 只能管住 commit。
package/SKILL.md CHANGED
@@ -14,7 +14,8 @@ already enforce some of these rules; follow them anyway.
14
14
 
15
15
  | Moment | Do this | Why |
16
16
  |---|---|---|
17
- | Running a build / test / type-check | `sentinel run -- <cmd>` (preferred) **or** run it, then `sentinel_record_run {command, exitCode, log}` | Records the exit code, fingerprints the error, returns a ≈150-token distilled failure. |
17
+ | Running a build / test / type-check | Just run it. In Claude Code it is routed through `sentinel run` automatically; elsewhere use `sentinel run -- <cmd>` **or** call `sentinel_record_run {command, exitCode, log}` afterwards | Records the exit code, fingerprints the error, returns a distilled failure listing **every** failing test. |
18
+ | The distilled failure is not enough | `sentinel_expand_log {run, failure: N}` / `{grep: "…"}` / `{from, to}` | Pulls exactly the raw lines you need from the stored log. Never re-run a slow test suite just to see more output. |
18
19
  | Before editing a file while fixing a failure | `sentinel_guard_edit {file, intent}` | Snapshots the file; answers ALLOW / WARN / BLOCK. |
19
20
  | After editing (only if no editor hook is installed) | `sentinel_record_edit {file}` | Feeds the flip-flop detector. |
20
21
  | A log longer than ~40 lines | `sentinel_distill_log {log}` | Strips ANSI, node_modules and bundler frames; keeps error + first project call site ±3 lines. |
@@ -28,7 +29,8 @@ already enforce some of these rules; follow them anyway.
28
29
  around: do not switch tools, shell redirection (`cat > file`), or another
29
30
  path to write anyway.
30
31
  2. **Never paste a raw log** into your reasoning or into a reply when a
31
- distilled version is available.
32
+ distilled version is available. If you need more, expand the specific
33
+ part with `sentinel_expand_log`; use `# sentinel:raw` only as a last resort.
32
34
  3. **Never rewrite a whole file** to change a few lines. Prune, then edit
33
35
  the numbered lines.
34
36
  4. **Never retry an approach listed under "Rejected approaches"** in a
@@ -49,7 +51,8 @@ already enforce some of these rules; follow them anyway.
49
51
  | `hotspotRounds` | 3 | Same function edited in 3 consecutive failing rounds → **HIGH risk warning** |
50
52
  | `cooldownMs` | 300000 | After 5 min OPEN, one HALF_OPEN probe attempt is allowed |
51
53
  | `autoRollback` | true | On trip, agent-touched files are restored to the last clean checkpoint |
52
- | `distillTokenBudget` | 150 | Max tokens of a distilled log |
54
+ | `distillTokenBudget` | 150 | Base tokens of a distilled log; grows with the number of failures and when the same failure repeats (up to `distillMaxBudget` 600) |
55
+ | `autoWrapTests` | true | Claude Code routes build/test commands through `sentinel run`; add `# sentinel:raw` to a command to see raw output instead |
53
56
  | `compactEvery` | 3 | Rounds per `[Compacted]` episode |
54
57
  | `contextLines` | 3 | Source lines around the call site |
55
58
 
@@ -89,10 +92,22 @@ clean checkpoint (a backup of your edits is kept under
89
92
  one probe attempt. Edits are allowed until the next recorded run: pass →
90
93
  CLOSED, fail → OPEN again.
91
94
 
92
- ## 5. Reading sentinel output
95
+ ## 5. After the conversation is compacted
96
+
97
+ If you see a block starting with `[agent-token-sentinel memory · after compact]`,
98
+ it is the authoritative record of this debugging session: the open problem,
99
+ what was already tried (do not retry it) and where the full logs are. Continue
100
+ from it rather than re-discovering the same facts.
101
+
102
+ ## 6. Reading sentinel output
93
103
 
94
104
  - `✖ TypeError: … / at fn (src/x.ts:42:7) / > 42 | code` — the distilled
95
105
  error; the `>` line is the first project call site.
106
+ - `also failing (3): • test — Error: …` — the other failures in the same run.
107
+ Fix them together when they share a cause; otherwise expect them next.
108
+ - `[sentinel: … · full log: sentinel_expand_log run=run-12]` — where the raw
109
+ log is. `escalated ×N` means you have hit this exact failure N+1 times: the
110
+ extra context is there to make you look wider, not to patch the same line.
96
111
  - `[Compacted]: Rounds 1-3 attempted null-checks at src/auth.ts#login, failed with TypeError ×3. Reverted.`
97
112
  — everything you need to remember about those rounds; drop the details.
98
113
  - `⚠️ Hotspot: …` — you keep patching the same function; widen the view.
@@ -122,6 +122,7 @@ export class CircuitBreaker {
122
122
  fingerprint: fingerprint?.hash,
123
123
  errorName: fingerprint?.errorName,
124
124
  message: fingerprint?.message.slice(0, 160),
125
+ failingTest: fingerprint?.failingTest?.slice(0, 160),
125
126
  rawTokens: estimateTokens(log),
126
127
  source: input.source,
127
128
  };
@@ -1 +1 @@
1
- {"version":3,"file":"breaker.js","sourceRoot":"","sources":["../../src/circuit-breaker/breaker.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE7D,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,QAAQ,GAAG,GAAG,CAAC;AA0CrB,MAAM,OAAO,cAAc;IAGI;IAFZ,GAAG,CAAe;IAEnC,YAA6B,IAAiB;QAAjB,SAAI,GAAJ,IAAI,CAAa;QAC5C,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC;IAClC,CAAC;IAED,IAAY,MAAM;QAChB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