token-pilot 0.29.0 → 0.30.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 (50) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +39 -390
  3. package/agents/tp-api-surface-tracker.md +1 -1
  4. package/agents/tp-audit-scanner.md +1 -1
  5. package/agents/tp-commit-writer.md +1 -1
  6. package/agents/tp-context-engineer.md +1 -1
  7. package/agents/tp-dead-code-finder.md +1 -1
  8. package/agents/tp-debugger.md +1 -1
  9. package/agents/tp-dep-health.md +1 -1
  10. package/agents/tp-doc-writer.md +1 -1
  11. package/agents/tp-history-explorer.md +1 -1
  12. package/agents/tp-impact-analyzer.md +1 -1
  13. package/agents/tp-incident-timeline.md +1 -1
  14. package/agents/tp-incremental-builder.md +1 -1
  15. package/agents/tp-migration-scout.md +1 -1
  16. package/agents/tp-onboard.md +1 -1
  17. package/agents/tp-performance-profiler.md +1 -1
  18. package/agents/tp-pr-reviewer.md +1 -1
  19. package/agents/tp-refactor-planner.md +1 -1
  20. package/agents/tp-review-impact.md +1 -1
  21. package/agents/tp-run.md +1 -1
  22. package/agents/tp-session-restorer.md +1 -1
  23. package/agents/tp-ship-coordinator.md +1 -1
  24. package/agents/tp-spec-writer.md +1 -1
  25. package/agents/tp-test-coverage-gapper.md +1 -1
  26. package/agents/tp-test-triage.md +1 -1
  27. package/agents/tp-test-writer.md +1 -1
  28. package/dist/cli/tool-audit.d.ts +5 -0
  29. package/dist/cli/tool-audit.js +9 -1
  30. package/dist/core/policy-engine.d.ts +1 -5
  31. package/dist/core/policy-engine.js +9 -24
  32. package/dist/hooks/pre-bash.d.ts +2 -1
  33. package/dist/hooks/pre-bash.js +3 -1
  34. package/dist/hooks/pre-grep.d.ts +2 -1
  35. package/dist/hooks/pre-grep.js +3 -1
  36. package/dist/index.js +4 -2
  37. package/dist/server/enforcement-mode.d.ts +47 -0
  38. package/dist/server/enforcement-mode.js +59 -0
  39. package/dist/server/tool-definitions.d.ts +20 -0
  40. package/dist/server/tool-definitions.js +111 -8
  41. package/dist/server/tool-profiles.d.ts +19 -1
  42. package/dist/server/tool-profiles.js +38 -4
  43. package/dist/server.d.ts +2 -0
  44. package/dist/server.js +68 -16
  45. package/docs/agents.md +82 -0
  46. package/docs/configuration.md +117 -0
  47. package/docs/hooks.md +99 -0
  48. package/docs/installation.md +143 -0
  49. package/docs/tools.md +61 -0
  50. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -5,6 +5,41 @@ All notable changes to Token Pilot will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.30.0] - 2026-04-19
9
+
10
+ ### Added — `minimal` profile (5 tools, near-zero overhead)
11
+
12
+ New `TOKEN_PILOT_PROFILE=minimal` for context-budget-constrained sessions. Advertises only 5 core tools (`smart_read`, `read_symbol`, `find_usages`, `smart_diff`, `smart_log`) — no META tools, no editing extras. Instructions are ~80 tokens vs ~350 for `full`. Use when the agent's context window is nearly full and you only need to navigate code.
13
+
14
+ ### Added — profile-specific MCP instructions (PR #1)
15
+
16
+ Each profile now receives instructions that only mention its own advertised tools. Previously, a `nav` session received `read_for_edit` and `code_audit` instructions even though those tools weren't in `tools/list` — causing hallucinated tool calls. Now:
17
+
18
+ - `minimal` → 80-token instruction block, 5 tools only
19
+ - `nav` → exploration-only rules, no edit-prep or audit mentions
20
+ - `edit` → full read+write workflow (DEFAULT since v0.30.0)
21
+ - `full` → all 22 tools including audit tools
22
+
23
+ Added `getMcpInstructions(profile)` export in `tool-definitions.ts`. The deprecated `MCP_INSTRUCTIONS` constant is kept as a `full`-alias for backward compatibility.
24
+
25
+ ### Changed — default profile `full` → `edit` (PR #2)
26
+
27
+ `TOKEN_PILOT_PROFILE` now defaults to `edit` instead of `full`. Rationale: the `full` profile was advertising 22 tools + ~350-token instructions on every session, costing ~3 k context tokens before any work. `edit` (16 tools) covers 99% of development workflows. Switch to `full` explicitly only when audit tools (`code_audit`, `find_unused`, `test_summary`) are needed.
28
+
29
+ Unknown `TOKEN_PILOT_PROFILE` values now fall back to `edit` (was `full`).
30
+
31
+ ### Fixed — removed dead code in policy-engine (PR #7)
32
+
33
+ `requireReadForEditBeforeEdit` in `PolicyConfig` was permanently dead: `editTargetPath` was never set in the `PolicyCheckContext` passed by `server.ts`, so the advisory could never fire. Removed:
34
+
35
+ - `PolicyConfig.requireReadForEditBeforeEdit` field
36
+ - `PolicyCheckContext.editTargetPath` field
37
+ - `PolicyCheckContext.readForEditCalled` field
38
+ - The corresponding `checkPolicy` branch (case 4)
39
+ - Dead `readForEditCalled` Set tracking in `server.ts`
40
+
41
+ ---
42
+
8
43
  ## [0.29.0] - 2026-04-19
9
44
 
10
45
  Consolidation release based on Sonnet 4.6 + Opus 4.7 verification findings. Closes the short-tail issues that came out of the two live runs before the weekly-quota window reopens.
package/README.md CHANGED
@@ -5,8 +5,8 @@
5
5
  Three layers, each useful on its own, stronger together:
6
6
 
7
7
  1. **MCP tools** — structural reads (`smart_read`, `read_symbol`, `read_for_edit`, …). Ask for an outline or load one function by name instead of the whole file.
8
- 2. **Read hook** — intercepts large raw `Read` calls and answers with a structural summary in the denial reason itself. Works for every agent, including ones that only have basic tools.
9
- 3. **`tp-*` subagents** — Claude Code delegates with MCP-first behaviour and tight response budgets. Tier 1 workhorses (`tp-run`, `tp-onboard`, `tp-pr-reviewer`, `tp-impact-analyzer`, `tp-refactor-planner`, `tp-test-triage`) plus Tier 2 specialists (`tp-debugger`, `tp-migration-scout`, `tp-test-writer`, `tp-dead-code-finder`, `tp-commit-writer`).
8
+ 2. **PreToolUse hooks** — intercept heavy native tool calls (`Read` on large files, recursive `Grep`, unbounded `git diff`) and redirect to token-efficient alternatives.
9
+ 3. **`tp-*` subagents** — Claude Code delegates with MCP-first behaviour and tight response budgets.
10
10
 
11
11
  ## How It Works
12
12
 
@@ -17,7 +17,7 @@ Token Pilot: smart_read("user-service.ts") → 15-line outline → ~200 tok
17
17
  After edit: read_diff("user-service.ts") → ~20 tokens
18
18
  ```
19
19
 
20
- Files under 200 lines are returned in full (zero overhead for small files).
20
+ Files under 200 lines are returned in full zero overhead for small files.
21
21
 
22
22
  ### Benchmarks
23
23
 
@@ -31,7 +31,7 @@ Measured on public open-source repos. Files ≥50 lines only:
31
31
  | [flask](https://github.com/pallets/flask) (Python) | 20 | 78,236 | 7,418 | **91%** |
32
32
  | **Total** | **104** | **244,743** | **19,764** | **92%** |
33
33
 
34
- > Measures `smart_read` outline savings only. Real sessions additionally benefit from session cache, `read_symbol` targeted loading, and `read_for_edit` minimal edit context. Reproduce: `npx tsx scripts/benchmark.ts`.
34
+ > `smart_read` outline savings only. Real sessions additionally benefit from session cache, `read_symbol`, and `read_for_edit`. Reproduce: `npx tsx scripts/benchmark.ts`.
35
35
 
36
36
  ## Quick Start
37
37
 
@@ -39,362 +39,53 @@ Measured on public open-source repos. Files ≥50 lines only:
39
39
  npx -y token-pilot init
40
40
  ```
41
41
 
42
- This does two things:
42
+ Creates (or merges into) `.mcp.json` with `token-pilot` + [`context-mode`](https://github.com/mksglu/claude-context-mode), then prompts to install `tp-*` subagents. Restart your AI assistant to activate.
43
43
 
44
- 1. Creates (or merges into) `.mcp.json` with `token-pilot` + [`context-mode`](https://github.com/mksglu/claude-context-mode).
45
- 2. If you're on a TTY, asks whether to install the `tp-*` subagents now — pick `user` (available in every project) or `project` scope.
44
+ ## What You Get
46
45
 
47
- Restart your AI assistant to activate. The Read hook auto-installs the first time `token-pilot` starts inside Claude Code. Works with **Claude Code, Cursor, Codex, Antigravity, Cline**, and any MCP-compatible client — though support varies (see matrix below).
46
+ - **22 MCP tools** structural reads, symbol search, git analysis, session analytics [tools reference](docs/tools.md)
47
+ - **PreToolUse hooks** — block heavy `Grep`/`Bash`/`Read` calls; redirect to efficient alternatives → [hooks & modes](docs/hooks.md)
48
+ - **25 `tp-*` subagents** (Claude Code only) — MCP-first delegates with haiku/sonnet model tiers and budget enforcement → [agents reference](docs/agents.md)
49
+ - **Tool profiles** — trim advertised `tools/list` to save ~2 k tokens per session → [profiles & config](docs/configuration.md)
48
50
 
49
- ## Client support matrix
51
+ ## Client Support Matrix
50
52
 
51
- Not every capability works in every client. Subagents are a Claude Code concept; other clients still get the MCP tools + Read hook but won't auto-invoke `tp-*` agents.
53
+ | Client | MCP tools | PreToolUse hooks | `tp-*` subagents |
54
+ |--------|:---------:|:----------------:|:----------------:|
55
+ | Claude Code | ✅ | ✅ | ✅ |
56
+ | Cursor | ✅ | ✅ | ❌ |
57
+ | Codex CLI | ✅ | ✅ | ❌ |
58
+ | Gemini CLI | ✅ | ✅ | ❌ |
59
+ | Cline (VS Code) | ✅ | ✅ | ❌ |
60
+ | Antigravity | ✅ | ✅ | ❌ |
52
61
 
53
- | Client | MCP tools | Read hook (context-mode) | `tp-*` subagents (25) | `model:` frontmatter (haiku) | Budget watchdog |
54
- |-----------------|:---------:|:------------------------:|:---------------------:|:----------------------------:|:---------------:|
55
- | Claude Code | ✅ | ✅ | ✅ | ✅ | ✅ |
56
- | Cursor | ✅ | ✅ | ❌ | ❌ (ignored) | ❌ |
57
- | Codex CLI | ✅ | ✅ | ❌ | ❌ | ❌ |
58
- | Gemini CLI | ✅ | ✅ | ❌ | ❌ | ❌ |
59
- | Cline (VS Code) | ✅ | ✅ | ❌ | ❌ | ❌ |
60
- | Antigravity | ✅ | ✅ | ❌ | ❌ | ❌ |
62
+ Manual config snippets for each client [installation guide](docs/installation.md)
61
63
 
62
- **What non-Claude users get (~60% of the package):**
63
- - All 22 MCP tools: `smart_read`, `read_symbol`, `find_usages`, `smart_diff`, `code_audit`, `session_analytics`, etc.
64
- - The Read hook that blocks oversized reads and suggests token-saving alternatives.
64
+ ## Enforcement Mode
65
65
 
66
- **What needs Claude Code to work:**
67
- - 19 `tp-*` subagents invoked via the `Task` tool.
68
- - `model: claude-haiku-4-5` frontmatter on format-bound agents (commit-writer, session-restorer, onboard) — cheaper runs.
69
- - `PostToolUse:Task` budget watchdog — logs agent runs exceeding their declared budget to `.token-pilot/over-budget.log`.
66
+ `TOKEN_PILOT_MODE` controls how aggressively Token Pilot redirects heavy native tool calls:
70
67
 
71
- `install-agents` detects non-Claude clients via env vars + filesystem markers (`CURSOR_TRACE_ID`, `~/.codex/`, `~/.gemini/`, etc.) and **skips installing** unless you pass `--scope=user|project` explicitly.
72
-
73
- ## Manual MCP install (per-client examples)
74
-
75
- If `init` isn't right for your setup — CI, non-TTY environments, editing a shared team config, or a client without an interactive installer — add Token Pilot as an MCP server directly. The server command is `npx -y token-pilot` on every client; only the config file shape differs.
76
-
77
- ### Claude Code
78
-
79
- Three paths — pick one, they're mutually exclusive.
80
-
81
- **A. As a Claude Code plugin (one-step install — hooks + MCP registered together):**
82
-
83
- ```bash
84
- claude plugin marketplace add https://github.com/Digital-Threads/token-pilot
85
- claude plugin install token-pilot@token-pilot
86
- ```
87
-
88
- Claude Code clones the repo into `~/.claude/plugins/cache/token-pilot/`, sets `CLAUDE_PLUGIN_ROOT`, and registers the MCP server + all hooks declared in `.claude-plugin/hooks/hooks.json`. No `install-hook` call needed. `install-agents` still applies for the tp-* subagents (they're separate from plugin hooks).
89
-
90
- **B. Via MCP config (npm-based, no plugin system):**
91
-
92
- ```bash
93
- claude mcp add token-pilot -- npx -y token-pilot
94
- claude mcp add --scope user token-pilot -- npx -y token-pilot
95
- claude mcp add --scope project token-pilot -- npx -y token-pilot
96
-
97
- # Or edit .mcp.json directly (project-level) / ~/.mcp.json (user-level)
98
- ```
99
-
100
- ```json
101
- {
102
- "mcpServers": {
103
- "token-pilot": { "command": "npx", "args": ["-y", "token-pilot"] },
104
- "context-mode": { "command": "npx", "args": ["-y", "claude-context-mode"] }
105
- }
106
- }
107
- ```
108
-
109
- Then `npx token-pilot install-hook` to register the PreToolUse Read/Edit hooks and `npx token-pilot install-agents --scope=user` to install the 25 tp-* subagents.
110
-
111
- **C. One-liner `init`:** `npx -y token-pilot init` — writes path B config for you, then prompts about subagents.
112
-
113
- ### Cursor
114
-
115
- Cursor reads `.cursor/mcp.json` (project) or `~/.cursor/mcp.json` (global):
116
-
117
- ```json
118
- {
119
- "mcpServers": {
120
- "token-pilot": { "command": "npx", "args": ["-y", "token-pilot"] }
121
- }
122
- }
123
- ```
124
-
125
- ### Codex CLI
126
-
127
- Codex reads `~/.codex/config.toml`:
128
-
129
- ```toml
130
- [mcp_servers.token-pilot]
131
- command = "npx"
132
- args = ["-y", "token-pilot"]
133
- ```
134
-
135
- ### Cline (VS Code)
136
-
137
- Cline reads `cline_mcp_settings.json` (accessible via Cline panel → MCP Servers → Edit):
138
-
139
- ```json
140
- {
141
- "mcpServers": {
142
- "token-pilot": { "command": "npx", "args": ["-y", "token-pilot"] }
143
- }
144
- }
145
- ```
146
-
147
- ### Any MCP-compatible client
148
-
149
- Use the generic MCP protocol — the server is a plain stdio process:
150
-
151
- ```
152
- command: npx
153
- args: -y token-pilot
154
- ```
155
-
156
- No env vars required. Optional overrides:
157
-
158
- | Env var | Default | Purpose |
159
- |---|---|---|
160
- | `TOKEN_PILOT_PROFILE` | `full` | `nav`/`edit`/`full` — trims the advertised `tools/list` payload to save ~2 k tokens per session (see "Tool profiles" below) |
161
- | `TOKEN_PILOT_DENY_THRESHOLD` | `300` | Line count above which the Read hook intervenes |
162
- | `TOKEN_PILOT_ADAPTIVE_THRESHOLD` | `false` | Enable the adaptive curve as the session burns |
163
- | `TOKEN_PILOT_BYPASS` | unset | Set to `1` to disable the Read hook for one session |
164
- | `TOKEN_PILOT_SKIP_POSTINSTALL` | unset | Skip the `ast-index` safety-net install at `npm install` time |
165
-
166
- ### Tool profiles
167
-
168
- | Profile | Tools | ~Tokens | Use when |
169
- |---------|------:|--------:|----------|
170
- | `full` *(default)* | 22 | ~4 150 | All capabilities |
171
- | `edit` | 16 | ~3 120 | Code-change workflows (nav + batch reads + `read_for_edit`) |
172
- | `nav` | 10 | ~1 910 | Read-only exploration / subagents that only navigate |
173
-
174
- Set via `TOKEN_PILOT_PROFILE` in your MCP server env block. Handlers stay live regardless — a subagent that explicitly names a filtered-out tool still gets served. The profile only trims what we advertise in `tools/list` at session start.
175
-
176
- ### Subagents (Claude Code only)
177
-
178
- `tp-*` subagents are a Claude Code feature. Other clients use only the MCP tools + Read hook. To install on a target scope explicitly:
179
-
180
- ```bash
181
- npx token-pilot install-agents --scope=user # all projects
182
- npx token-pilot install-agents --scope=project # this repo only
183
- npx token-pilot install-agents --scope=user --force # re-apply after an update
184
- ```
185
-
186
- ### From source (contributors / vendored installs)
68
+ | Value | Behaviour |
69
+ |-------|-----------|
70
+ | `advisory` | Allow all — hooks pass through, advisory notes only |
71
+ | `deny` *(default)* | Block heavy `Grep`/`Bash` patterns; intercept large `Read` calls |
72
+ | `strict` | Deny + auto-cap MCP output (`smart_read` 2 000 tokens, `find_usages` list mode, `smart_log` 20 commits) |
187
73
 
188
74
  ```bash
189
- git clone https://github.com/Digital-Threads/token-pilot.git
190
- cd token-pilot && npm install && npm run build
191
- # Point your client's config at dist/index.js:
192
- # "command": "node", "args": ["/abs/path/to/token-pilot/dist/index.js"]
75
+ TOKEN_PILOT_MODE=strict npx token-pilot
193
76
  ```
194
77
 
195
- ## Modes
196
-
197
- The Read hook has three modes. Set in `.token-pilot.json`:
198
-
199
- | Mode | Behaviour |
200
- |------|-----------|
201
- | `off` | Hook is inert. |
202
- | `advisory` | Denies unbounded Read with a short tip pointing at `smart_read` / `read_for_edit`. |
203
- | `deny-enhanced` *(default)* | Denies the Read and returns a full structural summary (imports, exports, declarations) **inside** the denial reason. Works for subagents that lack MCP access. |
204
-
205
- ```json
206
- { "hooks": { "mode": "deny-enhanced", "denyThreshold": 300 } }
207
- ```
208
-
209
- Env var overrides: `TOKEN_PILOT_MODE=off`, `TOKEN_PILOT_DENY_THRESHOLD=500`, `TOKEN_PILOT_BYPASS=1`.
210
-
211
- ## Subagents
212
-
213
- Claude Code subagents guarantee MCP-first behaviour with tight response budgets and verdict-first output. **Tier 1** are everyday workhorses invoked proactively; **Tier 2** are focused specialists you reach for when a specific kind of work comes up (debugging, migration, test authoring, cleanup, commits).
214
-
215
- **Tier 1 — workhorses:**
216
-
217
- | Agent | When to invoke | Budget |
218
- |-------|---------------|-------:|
219
- | `tp-run` | General MCP-first workhorse; use proactively when no specialised agent fits | 800 |
220
- | `tp-onboard` | Orient to an unfamiliar repo (layout, entry points, modules) | 600 |
221
- | `tp-pr-reviewer` | Review a diff / PR / changeset; verdict-first, Critical/Important tiers | 600 |
222
- | `tp-impact-analyzer` | Trace blast-radius of a change (callers, transitive deps) | 400 |
223
- | `tp-refactor-planner` | Plan a refactor with exact edit context per step | 500 |
224
- | `tp-test-triage` | Investigate test failures → root cause → minimal fix | 500 |
225
-
226
- **Tier 2 — specialists:**
227
-
228
- | Agent | When to invoke | Budget |
229
- |-------|---------------|-------:|
230
- | `tp-debugger` | Stack trace / error → root-cause line via call-tree traversal | 700 |
231
- | `tp-migration-scout` | Pre-migration impact map grouped by effort class | 800 |
232
- | `tp-test-writer` | Write tests for ONE symbol, mirrors project style, runs tests | 900 |
233
- | `tp-dead-code-finder` | Cross-checked dead-code detection, output-only (never deletes) | 600 |
234
- | `tp-commit-writer` | Draft Conventional-Commit from staged diff; refuses failing tests | 400 |
235
- | `tp-history-explorer` | "Why is this like this?" — minimum commit chain explaining current state | 600 |
236
- | `tp-audit-scanner` | Read-only security / quality audit; Critical / Important / Minor findings | 800 |
237
- | `tp-session-restorer` | Rehydrate state after /clear or compaction from latest snapshot | 400 |
238
-
239
- **Tier 3 — combo / workflow:**
240
-
241
- | Agent | When to invoke | Budget |
242
- |-------|---------------|-------:|
243
- | `tp-review-impact` | Pre-merge blast-radius review (diff × dependents × API surface) | 700 |
244
- | `tp-test-coverage-gapper` | Find symbols with zero test references, prioritised | 500 |
245
- | `tp-api-surface-tracker` | Public API diff vs last release → MAJOR / MINOR / PATCH verdict | 600 |
246
- | `tp-dep-health` | Dep audit: stale × heavily-used × removable | 600 |
247
- | `tp-incident-timeline` | Correlate an incident window with commits, rank likely culprits | 700 |
248
-
249
- **Tier 4 — methodology (v0.27.0, inspired by @addyosmani/agent-skills):**
250
-
251
- | Agent | When to invoke | Budget |
252
- |-------|---------------|-------:|
253
- | `tp-context-engineer` | Audit / write CLAUDE.md / AGENTS.md rules files per project | 800 |
254
- | `tp-spec-writer` | Pre-code spec with gated workflow; surfaces assumptions before code | 900 |
255
- | `tp-performance-profiler` | Measure → identify → fix → verify → guard; refuses to optimize without data | 800 |
256
- | `tp-incremental-builder` | Multi-file feature work in thin vertical slices, test between each | 900 |
257
- | `tp-doc-writer` | ADRs + READMEs + API docs; documents *why* not *what* | 700 |
258
- | `tp-ship-coordinator` | 5-pillar pre-launch checklist (quality / security / observability / rollback / rollout) | 800 |
259
-
260
- ### Model tiers
261
-
262
- Every agent carries an explicit `model:` field in its frontmatter. Default dispatch:
263
- - **haiku** (9 agents) — structured / format-bound output (commit messages, onboarding maps, ADRs, session briefings)
264
- - **sonnet** (15 agents) — reasoning tasks (review, debug, test, plan, audit, spec, profile, ship)
265
- - **inherit** (1 agent) — deep correlation needing whatever the main thread uses (`tp-incident-timeline`)
266
-
267
- Effect: under Opus 4.7's +35% tokenizer tax, keeping the majority of agent spawns on haiku / sonnet saves 5-10× model cost vs an all-Opus baseline.
268
-
269
- Every agent's budget is enforced post-response — overshoots beyond 10 % land in `.token-pilot/over-budget.log`.
270
-
271
- `init` offers to install these; to do it later or add them to another project, run `npx token-pilot install-agents`. Remove with `npx token-pilot uninstall-agents --scope=user|project`.
272
-
273
- For third-party agents (e.g. `acc-*` plugins) whose tool allowlist excludes token-pilot MCP, `npx token-pilot bless-agents` creates project-level overrides that add the missing tools. `doctor` warns when the original agent has changed since blessing; `unbless-agents` reverses.
274
-
275
- ## MCP Tools
276
-
277
- ### Reading
278
-
279
- | Tool | Instead of | Purpose |
280
- |------|-----------|---------|
281
- | `smart_read` | `Read` | AST outline; 90% fewer tokens on large files |
282
- | `read_symbol` | `Read`+scroll | One class/function by name (`Class.method` supported) |
283
- | `read_symbols` | N × `read_symbol` | Batch up to 10 symbols from one file |
284
- | `read_for_edit` | `Read` before `Edit` | Minimal raw code around a symbol — copy directly as `old_string` |
285
- | `read_range` | `Read` offset | Specific line range |
286
- | `read_section` | `Read` | Section by heading (Markdown) or key (YAML/JSON/CSV) |
287
- | `read_diff` | re-`Read` | Changed hunks since last `smart_read` |
288
- | `smart_read_many` | multiple `Read` | Batch smart_read for up to 20 files |
289
-
290
- ### Search & Navigation
291
-
292
- | Tool | Instead of | Purpose |
293
- |------|-----------|---------|
294
- | `find_usages` | `Grep` (refs) | All usages of a symbol; filters by scope/kind/lang |
295
- | `project_overview` | `ls` + explore | Project type, frameworks, architecture, directory map |
296
- | `related_files` | manual | Import graph: imports, importers, test files |
297
- | `outline` | multiple `smart_read` | Compact overview of all code in a directory |
298
- | `find_unused` | manual | Dead code detection |
299
- | `code_audit` | multiple `Grep` | TODOs, deprecated symbols, structural patterns |
300
- | `module_info` | manual | Deps, dependents, public API, unused deps |
301
- | `smart_diff` | raw `git diff` | Structural diff with symbol mapping |
302
- | `explore_area` | 3-5 calls | Structure + imports + tests + recent changes |
303
- | `smart_log` | raw `git log` | Structured commits with category detection |
304
- | `test_summary` | raw test output | Run tests → pass/fail summary + failure details |
305
-
306
- ### Session
307
-
308
- | Tool | Purpose |
309
- |------|---------|
310
- | `session_snapshot` | Compact markdown snapshot (<200 tokens) of goal, decisions, facts, blockers, next step. Auto-persisted to `.token-pilot/snapshots/latest.md`; SessionStart surfaces a pointer when recent. |
311
- | `session_budget` | Hook-suppression pressure for this session: saved tokens, burn fraction, effective denyThreshold, time-to-compact projection |
312
- | `session_analytics` | Token savings: per-tool breakdown, top files, policy advisories |
313
-
314
- ## CLI
315
-
316
- ```bash
317
- token-pilot # Start MCP server
318
- token-pilot init # Create/merge .mcp.json; offers to install subagents
319
- token-pilot install-agents [--scope=user|project] [--force]
320
- token-pilot uninstall-agents --scope=user|project
321
- token-pilot bless-agents # Extend third-party agents with token-pilot MCP
322
- token-pilot unbless-agents <name>... | --all
323
- token-pilot install-hook # Install PreToolUse hook
324
- token-pilot uninstall-hook
325
- token-pilot stats # Totals + top files from hook-events.jsonl
326
- token-pilot stats --session[=<id>] | --by-agent
327
- token-pilot tool-audit # Per-tool savings distribution (cumulative across sessions)
328
- token-pilot tool-audit --json # Same, machine-readable
329
- token-pilot doctor # Diagnostics (ast-index, config, upstream drift)
330
- token-pilot install-ast-index # Download ast-index binary (auto on first run)
331
- ```
332
-
333
- ### Environment variables
334
-
335
- | Var | Effect |
336
- |-----|--------|
337
- | `TOKEN_PILOT_MODE=off` | Disable the hook for this process |
338
- | `TOKEN_PILOT_BYPASS=1` | Pass every Read through |
339
- | `TOKEN_PILOT_DENY_THRESHOLD=<n>` | Override `hooks.denyThreshold` |
340
- | `TOKEN_PILOT_DEBUG=1` | Verbose hook logging to stderr |
341
- | `TOKEN_PILOT_NO_AGENT_REMINDER=1` | Suppress the "tp-* not installed" stderr nudge |
342
- | `TOKEN_PILOT_SUBAGENT=1` | Mark the MCP server as running inside a subagent |
343
-
344
- ## Configuration
345
-
346
- Drop `.token-pilot.json` in your project root. All fields optional.
347
-
348
- ```json
349
- {
350
- "hooks": { "mode": "deny-enhanced", "denyThreshold": 300 },
351
- "sessionStart": { "enabled": true, "showStats": false, "maxReminderTokens": 250 },
352
- "agents": { "scope": null, "reminder": true },
353
- "smartRead": { "smallFileThreshold": 200 },
354
- "cache": { "maxSizeMB": 100, "watchFiles": true },
355
- "policies": { "maxFullFileReads": 10, "largeReadThreshold": 2000 },
356
- "ignore": ["node_modules/**", "dist/**", ".git/**"]
357
- }
358
- ```
359
-
360
- | Option | Default | What it does |
361
- |--------|---------|--------------|
362
- | `hooks.mode` | `"deny-enhanced"` | `off` / `advisory` / `deny-enhanced` |
363
- | `hooks.denyThreshold` | `300` | Line count above which the hook starts denying unbounded Read |
364
- | `sessionStart.enabled` | `true` | Re-inject MCP-rules reminder at every new session / `/clear` / `/compact` |
365
- | `agents.scope` | `null` | Persisted scope of last `install-agents` run; reused silently |
366
- | `agents.reminder` | `true` | Show the "agents not installed" startup nudge |
367
- | `smartRead.smallFileThreshold` | `200` | Files with fewer lines bypass AST overhead |
368
- | `cache.maxSizeMB` | `100` | File cache ceiling (LRU eviction) |
369
- | `policies.maxFullFileReads` | `10` | Warn after N full-file reads in session |
78
+ [Full hook & mode docs](docs/hooks.md)
370
79
 
371
80
  ## Ecosystem
372
81
 
373
- Token Pilot sits in a small toolkit of three orthogonal pieces. Each has a single job; none overlaps with another.
374
-
375
- ```
376
- Agent
377
- ├─ Read code file → smart_read / read_symbol (Token Pilot MCP)
378
- │ └→ ast-index (structural backend)
379
- ├─ Need a fresh Read? → force: true (Token Pilot MCP)
380
- ├─ Run code / inspect logs → execute (context-mode MCP)
381
- └─ Bash agent, no MCP? → ast-index <subcmd> (CLI binary)
382
- ```
383
-
384
- | Tool | Role | When it fires |
385
- |------|------|---------------|
386
- | **[Token Pilot](.)** | Enforcement layer — Read hook, MCP structural reads, dedup, snapshots, subagents | Every code Read / Edit / session |
387
- | **[ast-index](https://github.com/defendend/Claude-ast-index-search)** | Structural indexer. Symbols, usages, hierarchy. Used by Token Pilot under the hood; also a standalone CLI for bash-only agents. | Auto-installed by Token Pilot; CLI available as `ast-index` |
388
- | **[context-mode](https://github.com/mksglu/claude-context-mode)** | Sandbox executor — runs shell / python / js, only stdout enters the window. Orthogonal: not for reading source. | Large `Bash` outputs, `execute(language, code)` calls |
389
-
390
- **Rules of thumb:**
82
+ | Tool | Role |
83
+ |------|------|
84
+ | **Token Pilot** | Enforcement layer — hooks, MCP structural reads, subagents |
85
+ | **[ast-index](https://github.com/defendend/Claude-ast-index-search)** | Structural indexer. Auto-installed by Token Pilot; also a standalone CLI for bash-only agents |
86
+ | **[context-mode](https://github.com/mksglu/claude-context-mode)** | Sandbox executor — runs shell/python/js, only stdout enters the context window |
391
87
 
392
- - Read code → Token Pilot `smart_read` / `read_symbol` (automatic via hook or MCP).
393
- - Execute code that produces big output → context-mode `execute`.
394
- - Bash agent or pre-flight shell command → `ast-index` CLI directly.
395
- - Never all three in `CLAUDE.md` — Token Pilot's `doctor` warns when `CLAUDE.md` exceeds 60 lines for this reason.
396
-
397
- `npx token-pilot init` wires Token Pilot + context-mode into `.mcp.json`; ast-index installs on first run. If any single tool is missing, the other two still work standalone.
88
+ Rules of thumb: read code → `smart_read`/`read_symbol`; execute code with big output → context-mode `execute`; bash-only agent → `ast-index` CLI. Never copy all three into `CLAUDE.md` Token Pilot's `doctor` warns when `CLAUDE.md` exceeds 60 lines.
398
89
 
399
90
  ## Supported Languages
400
91
 
@@ -403,56 +94,14 @@ TypeScript, JavaScript, Python, Go, Rust, Java, Kotlin, C#, C/C++, PHP, Ruby. No
403
94
  ## Troubleshooting
404
95
 
405
96
  ```bash
406
- # Verify installation
407
- npx token-pilot doctor
408
-
409
- # Common issues:
410
- # - "ast-index not found" → npx token-pilot install-ast-index
411
- # - "hooks not firing" → restart your AI assistant
412
- # - "stats shows No events" → hook events accumulate in .token-pilot/hook-events.jsonl after the first denied Read
413
-
414
- # Update everything
415
- npm i -g token-pilot@latest
416
- ```
417
-
418
- ## Architecture
419
-
420
- ```
421
- src/
422
- index.ts — CLI entry + MCP server bootstrap
423
- server.ts — MCP server setup, 21 tool definitions
424
- ast-index/ — ast-index binary client + auto-install
425
- core/
426
- event-log.ts — hook-events.jsonl + rotation + retention
427
- session-analytics.ts, policy-engine.ts, intent-classifier.ts
428
- hooks/
429
- installer.ts — Hook install/uninstall for Claude Code
430
- session-start.ts — SessionStart reminder handler
431
- summary-pipeline.ts — ast-index → regex → head+tail → pass-through
432
- cli/
433
- install-agents.ts, uninstall-agents.ts
434
- bless-agents.ts, unbless-agents.ts, doctor-drift.ts
435
- stats.ts
436
- templates/agent-builder.ts
437
- config/loader.ts, defaults.ts
438
- handlers/ — 21 MCP tool handlers
439
- git/ — HEAD + file watchers (cache invalidation)
440
-
441
- scripts/
442
- build-agents.mjs — Render templates/ → dist/agents/
443
- bench-hook.mjs — Hook latency benchmark
444
-
445
- templates/agents/ — Source for tp-* family + shared preamble + contract
97
+ npx token-pilot doctor # diagnose: ast-index, config, upstream drift
98
+ # "ast-index not found" → npx token-pilot install-ast-index
99
+ # "hooks not firing" → restart your AI assistant
446
100
  ```
447
101
 
448
102
  ## Credits
449
103
 
450
- Built on top of:
451
-
452
- - [ast-index](https://github.com/defendend/ast-index) — Tree-sitter AST indexer in Rust (auto-installed)
453
- - [@ast-grep/cli](https://ast-grep.github.io/) — Structural code pattern search
454
- - [MCP SDK](https://github.com/modelcontextprotocol/typescript-sdk) — Model Context Protocol
455
- - [chokidar](https://github.com/paulmillr/chokidar) — File watching
104
+ Built on [ast-index](https://github.com/defendend/ast-index) · [@ast-grep/cli](https://ast-grep.github.io/) · [MCP SDK](https://github.com/modelcontextprotocol/typescript-sdk) · [chokidar](https://github.com/paulmillr/chokidar)
456
105
 
457
106
  ## License
458
107
 
@@ -9,7 +9,7 @@ tools:
9
9
  - mcp__token-pilot__read_symbol
10
10
  - Bash
11
11
  model: haiku
12
- token_pilot_version: "0.29.0"
12
+ token_pilot_version: "0.30.0"
13
13
  token_pilot_body_hash: c9d33476fdf70c8a7a493ec8720f54792eda2f81585996246e94c130ff3ec356
14
14
  ---
15
15
 
@@ -11,7 +11,7 @@ tools:
11
11
  - Grep
12
12
  - Read
13
13
  model: sonnet
14
- token_pilot_version: "0.29.0"
14
+ token_pilot_version: "0.30.0"
15
15
  token_pilot_body_hash: 7095ffab66aca2e424f00875933e3f63bc10651eef2fde6a59f08bbbdbf86f7c
16
16
  ---
17
17
 
@@ -8,7 +8,7 @@ tools:
8
8
  - mcp__token-pilot__test_summary
9
9
  - mcp__token-pilot__outline
10
10
  - Bash
11
- token_pilot_version: "0.29.0"
11
+ token_pilot_version: "0.30.0"
12
12
  token_pilot_body_hash: b6831f11c61a9b255c2b6ffa04837130242fd02843463a7d30f109c1a06b3e3f
13
13
  ---
14
14
 
@@ -13,7 +13,7 @@ tools:
13
13
  - Edit
14
14
  - Glob
15
15
  model: sonnet
16
- token_pilot_version: "0.29.0"
16
+ token_pilot_version: "0.30.0"
17
17
  token_pilot_body_hash: 43f9364ce722ff76daf0f8720ddaf9f77e18d4c4ed8bee3e15f12d207798e778
18
18
  ---
19
19
 
@@ -11,7 +11,7 @@ tools:
11
11
  - Grep
12
12
  - Read
13
13
  model: sonnet
14
- token_pilot_version: "0.29.0"
14
+ token_pilot_version: "0.30.0"
15
15
  token_pilot_body_hash: 386760aed26df6c3595d3267954605565fad08afa8761e016079ae60c19887a8
16
16
  ---
17
17
 
@@ -12,7 +12,7 @@ tools:
12
12
  - Read
13
13
  - Bash
14
14
  model: sonnet
15
- token_pilot_version: "0.29.0"
15
+ token_pilot_version: "0.30.0"
16
16
  token_pilot_body_hash: 71738830d025e86c70988e046a2f7f30b4590f3d284291a18609ed5fdd732321
17
17
  ---
18
18
 
@@ -9,7 +9,7 @@ tools:
9
9
  - Bash
10
10
  - Read
11
11
  model: haiku
12
- token_pilot_version: "0.29.0"
12
+ token_pilot_version: "0.30.0"
13
13
  token_pilot_body_hash: 12634cd28889d0a0ef1b4a6b994ba978353e14f3cb349011c393076e7e2b5c96
14
14
  ---
15
15
 
@@ -13,7 +13,7 @@ tools:
13
13
  - Edit
14
14
  - Glob
15
15
  model: haiku
16
- token_pilot_version: "0.29.0"
16
+ token_pilot_version: "0.30.0"
17
17
  token_pilot_body_hash: 8e29d07dd8f58adeb9530ec477a59a6e42de6c624f322d2c6cfa8da66456b46a
18
18
  ---
19
19
 
@@ -10,7 +10,7 @@ tools:
10
10
  - Bash
11
11
  - Read
12
12
  model: haiku
13
- token_pilot_version: "0.29.0"
13
+ token_pilot_version: "0.30.0"
14
14
  token_pilot_body_hash: 260197bc31531352f5eda3b70cf114c7c57bb7e9373f68ca76161dd68a804b0d
15
15
  ---
16
16
 
@@ -12,7 +12,7 @@ tools:
12
12
  - mcp__token-pilot__read_symbols
13
13
  - Read
14
14
  model: sonnet
15
- token_pilot_version: "0.29.0"
15
+ token_pilot_version: "0.30.0"
16
16
  token_pilot_body_hash: 1da6936cc117a7627640fae3cc85bf13a17f0b0b0d0d533423dfb4b7c0b4b1c2
17
17
  ---
18
18
 
@@ -8,7 +8,7 @@ tools:
8
8
  - mcp__token-pilot__read_symbol
9
9
  - Bash
10
10
  model: inherit
11
- token_pilot_version: "0.29.0"
11
+ token_pilot_version: "0.30.0"
12
12
  token_pilot_body_hash: 213746bab7acb6730a6edb16e1ff7b2c56572c3adf4f94990799f1c168cfa2ad
13
13
  ---
14
14
 
@@ -13,7 +13,7 @@ tools:
13
13
  - Edit
14
14
  - Bash
15
15
  model: sonnet
16
- token_pilot_version: "0.29.0"
16
+ token_pilot_version: "0.30.0"
17
17
  token_pilot_body_hash: 14c9adcabfb772c77a467a5fbfa682abbd5adc87e22d7fbe5d1329ffd790dde5
18
18
  ---
19
19
 
@@ -11,7 +11,7 @@ tools:
11
11
  - Grep
12
12
  - Glob
13
13
  model: sonnet
14
- token_pilot_version: "0.29.0"
14
+ token_pilot_version: "0.30.0"
15
15
  token_pilot_body_hash: 62893e448e943d0e1b928a670823ec3e152de395e487564862f145bd82161fcb
16
16
  ---
17
17