token-pilot 0.29.0 → 0.30.1
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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +2 -4
- package/CHANGELOG.md +35 -0
- package/README.md +57 -384
- package/agents/tp-api-surface-tracker.md +1 -1
- package/agents/tp-audit-scanner.md +1 -1
- package/agents/tp-commit-writer.md +1 -1
- package/agents/tp-context-engineer.md +1 -1
- package/agents/tp-dead-code-finder.md +1 -1
- package/agents/tp-debugger.md +1 -1
- package/agents/tp-dep-health.md +1 -1
- package/agents/tp-doc-writer.md +1 -1
- package/agents/tp-history-explorer.md +1 -1
- package/agents/tp-impact-analyzer.md +1 -1
- package/agents/tp-incident-timeline.md +1 -1
- package/agents/tp-incremental-builder.md +1 -1
- package/agents/tp-migration-scout.md +1 -1
- package/agents/tp-onboard.md +1 -1
- package/agents/tp-performance-profiler.md +1 -1
- package/agents/tp-pr-reviewer.md +1 -1
- package/agents/tp-refactor-planner.md +1 -1
- package/agents/tp-review-impact.md +1 -1
- package/agents/tp-run.md +1 -1
- package/agents/tp-session-restorer.md +1 -1
- package/agents/tp-ship-coordinator.md +1 -1
- package/agents/tp-spec-writer.md +1 -1
- package/agents/tp-test-coverage-gapper.md +1 -1
- package/agents/tp-test-triage.md +1 -1
- package/agents/tp-test-writer.md +1 -1
- package/dist/ast-index/client.d.ts +17 -2
- package/dist/ast-index/client.js +233 -107
- package/dist/cli/tool-audit.d.ts +5 -0
- package/dist/cli/tool-audit.js +9 -1
- package/dist/core/edit-prep-state.d.ts +42 -0
- package/dist/core/edit-prep-state.js +108 -0
- package/dist/core/policy-engine.d.ts +1 -5
- package/dist/core/policy-engine.js +9 -24
- package/dist/handlers/explore-area.js +6 -1
- package/dist/handlers/read-for-edit.d.ts +5 -5
- package/dist/handlers/read-for-edit.js +188 -110
- package/dist/hooks/installer.js +18 -0
- package/dist/hooks/pre-bash.d.ts +11 -1
- package/dist/hooks/pre-bash.js +51 -1
- package/dist/hooks/pre-edit.d.ts +69 -0
- package/dist/hooks/pre-edit.js +104 -0
- package/dist/hooks/pre-grep.d.ts +12 -1
- package/dist/hooks/pre-grep.js +39 -1
- package/dist/index.d.ts +30 -0
- package/dist/index.js +87 -22
- package/dist/server/enforcement-mode.d.ts +47 -0
- package/dist/server/enforcement-mode.js +59 -0
- package/dist/server/tool-definitions.d.ts +20 -0
- package/dist/server/tool-definitions.js +127 -12
- package/dist/server/tool-profiles.d.ts +19 -1
- package/dist/server/tool-profiles.js +38 -4
- package/dist/server.d.ts +2 -0
- package/dist/server.js +89 -21
- package/docs/agents.md +82 -0
- package/docs/configuration.md +117 -0
- package/docs/hooks.md +99 -0
- package/docs/installation.md +169 -0
- package/docs/tools.md +61 -0
- package/hooks/hooks.json +18 -0
- package/package.json +2 -2
- package/start.sh +19 -9
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
},
|
|
7
7
|
"metadata": {
|
|
8
8
|
"description": "Token Pilot \u2014 save 60-90% tokens when AI reads code",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.30.1"
|
|
10
10
|
},
|
|
11
11
|
"plugins": [
|
|
12
12
|
{
|
|
13
13
|
"name": "token-pilot",
|
|
14
14
|
"source": "./",
|
|
15
15
|
"description": "Reduces token consumption by 60-90% via AST-aware lazy file reading, structural symbol navigation, and cross-session tool-usage analytics. 22 MCP tools + 19 subagents + budget watchdog hooks.",
|
|
16
|
-
"version": "0.
|
|
16
|
+
"version": "0.30.1",
|
|
17
17
|
"author": {
|
|
18
18
|
"name": "Digital-Threads"
|
|
19
19
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "token-pilot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.1",
|
|
4
4
|
"description": "Saves 60-90% tokens when AI reads code. AST-aware lazy reading, symbol navigation, cross-session tool-usage analytics, 22 subagents (haiku/sonnet/opus-tiered) with budget watchdog.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Digital-Threads",
|
|
@@ -21,9 +21,7 @@
|
|
|
21
21
|
"mcpServers": {
|
|
22
22
|
"token-pilot": {
|
|
23
23
|
"command": "sh",
|
|
24
|
-
"args": [
|
|
25
|
-
"${CLAUDE_PLUGIN_ROOT}/start.sh"
|
|
26
|
-
]
|
|
24
|
+
"args": ["${CLAUDE_PLUGIN_ROOT}/start.sh"]
|
|
27
25
|
}
|
|
28
26
|
},
|
|
29
27
|
"skills": "./skills/"
|
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. **
|
|
9
|
-
3. **`tp-*` subagents** — Claude Code delegates with MCP-first behaviour and tight response budgets.
|
|
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
|
|
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
|
-
>
|
|
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,420 +39,93 @@ Measured on public open-source repos. Files ≥50 lines only:
|
|
|
39
39
|
npx -y token-pilot init
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
51
|
+
## Client Support Matrix
|
|
50
52
|
|
|
51
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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):**
|
|
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) |
|
|
82
73
|
|
|
83
74
|
```bash
|
|
84
|
-
|
|
85
|
-
claude plugin install token-pilot@token-pilot
|
|
75
|
+
TOKEN_PILOT_MODE=strict npx token-pilot
|
|
86
76
|
```
|
|
87
77
|
|
|
88
|
-
|
|
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
|
|
78
|
+
→ [Full hook & mode docs](docs/hooks.md)
|
|
96
79
|
|
|
97
|
-
|
|
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 |
|
|
80
|
+
## Ecosystem
|
|
173
81
|
|
|
174
|
-
|
|
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 |
|
|
175
87
|
|
|
176
|
-
|
|
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.
|
|
177
89
|
|
|
178
|
-
|
|
90
|
+
## Supported Languages
|
|
179
91
|
|
|
180
|
-
|
|
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
|
-
```
|
|
92
|
+
TypeScript, JavaScript, Python, Go, Rust, Java, Kotlin, C#, C/C++, PHP, Ruby. Non-code (JSON/YAML/Markdown/TOML) gets structural summaries. Regex fallback handles most other languages.
|
|
185
93
|
|
|
186
|
-
|
|
94
|
+
## Update / New Machine
|
|
187
95
|
|
|
96
|
+
**Claude Code (plugin — recommended):**
|
|
188
97
|
```bash
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
# "command": "node", "args": ["/abs/path/to/token-pilot/dist/index.js"]
|
|
193
|
-
```
|
|
194
|
-
|
|
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. |
|
|
98
|
+
# Install on a new machine:
|
|
99
|
+
claude plugin marketplace add https://github.com/Digital-Threads/token-pilot
|
|
100
|
+
claude plugin install token-pilot@token-pilot
|
|
204
101
|
|
|
205
|
-
|
|
206
|
-
|
|
102
|
+
# Update to latest:
|
|
103
|
+
claude plugin update token-pilot
|
|
207
104
|
```
|
|
208
105
|
|
|
209
|
-
|
|
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
|
-
|
|
106
|
+
**Other clients (Cursor, Codex, Cline, …):**
|
|
316
107
|
```bash
|
|
317
|
-
|
|
318
|
-
token-pilot init
|
|
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 |
|
|
370
|
-
|
|
371
|
-
## Ecosystem
|
|
372
|
-
|
|
373
|
-
Token Pilot sits in a small toolkit of three orthogonal pieces. Each has a single job; none overlaps with another.
|
|
108
|
+
# Install on a new machine:
|
|
109
|
+
npx -y token-pilot init
|
|
374
110
|
|
|
111
|
+
# Update to latest — npx always pulls fresh, just restart your client.
|
|
112
|
+
# Or if installed globally:
|
|
113
|
+
npm i -g token-pilot@latest
|
|
114
|
+
npx token-pilot install-hook
|
|
115
|
+
npx token-pilot install-agents --scope=user --force
|
|
375
116
|
```
|
|
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:**
|
|
391
|
-
|
|
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.
|
|
398
|
-
|
|
399
|
-
## Supported Languages
|
|
400
|
-
|
|
401
|
-
TypeScript, JavaScript, Python, Go, Rust, Java, Kotlin, C#, C/C++, PHP, Ruby. Non-code (JSON/YAML/Markdown/TOML) gets structural summaries. Regex fallback handles most other languages.
|
|
402
117
|
|
|
403
118
|
## Troubleshooting
|
|
404
119
|
|
|
405
120
|
```bash
|
|
406
|
-
#
|
|
407
|
-
npx token-pilot
|
|
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
|
|
121
|
+
npx token-pilot doctor # diagnose: ast-index, config, upstream drift
|
|
122
|
+
# "ast-index not found" → npx token-pilot install-ast-index
|
|
123
|
+
# "hooks not firing" → restart your AI assistant
|
|
446
124
|
```
|
|
447
125
|
|
|
448
126
|
## Credits
|
|
449
127
|
|
|
450
|
-
Built on
|
|
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
|
|
128
|
+
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
129
|
|
|
457
130
|
## License
|
|
458
131
|
|
package/agents/tp-debugger.md
CHANGED