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/docs/hooks.md ADDED
@@ -0,0 +1,99 @@
1
+ # Hooks & Enforcement Modes
2
+
3
+ Token Pilot installs two categories of PreToolUse hooks in Claude Code:
4
+
5
+ 1. **Read hook** — intercepts large `Read` calls (configurable threshold, default 300 lines) and returns a structural summary in the denial reason.
6
+ 2. **Grep / Bash hooks** — block heavy recursive patterns (`grep -r`, `find /`, `cat <file.ts>`, unbounded `git log`, bare `git diff`) and redirect to token-pilot MCP equivalents.
7
+
8
+ ## TOKEN_PILOT_MODE — Enforcement Mode
9
+
10
+ Controls how aggressively both hook categories behave:
11
+
12
+ | Value | Grep/Bash hooks | MCP output |
13
+ |-------|----------------|------------|
14
+ | `advisory` | Pass all through (no blocking) | No caps |
15
+ | `deny` *(default)* | Block heavy patterns, allow bounded variants | No caps |
16
+ | `strict` | Same as deny, plus auto-cap MCP output (see below) | Capped |
17
+
18
+ ```bash
19
+ # Set in your MCP server env block or shell profile:
20
+ TOKEN_PILOT_MODE=strict npx token-pilot
21
+ ```
22
+
23
+ ### Strict-mode MCP output caps
24
+
25
+ When `TOKEN_PILOT_MODE=strict` and the caller has not set the parameter explicitly:
26
+
27
+ | Tool | Auto-injected default | Note appended |
28
+ |------|-----------------------|---------------|
29
+ | `smart_read` | `max_tokens: 2000` | Yes |
30
+ | `explore_area` | `include: ["outline"]` | Yes |
31
+ | `find_usages` | `mode: "list"` | Yes |
32
+ | `smart_log` | `count: 20` | Yes |
33
+
34
+ Pass the parameter explicitly to override the cap.
35
+
36
+ ## Read Hook Modes
37
+
38
+ The PreToolUse:Read hook has its own mode (separate from enforcement mode). Set in `.token-pilot.json`:
39
+
40
+ | Mode | Behaviour |
41
+ |------|-----------|
42
+ | `off` | Hook is inert — all `Read` calls pass through |
43
+ | `advisory` | Denies unbounded Read with a short tip pointing at `smart_read` / `read_for_edit` |
44
+ | `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. |
45
+
46
+ ```json
47
+ { "hooks": { "mode": "deny-enhanced", "denyThreshold": 300 } }
48
+ ```
49
+
50
+ ## Grep / Bash Hook Rules
51
+
52
+ The Grep hook redirects symbol-like patterns to `find_usages`. The Bash hook blocks:
53
+
54
+ | Pattern | Blocked when | Allowed when |
55
+ |---------|-------------|--------------|
56
+ | `grep -r`/`-R` | Always (unbounded) | Has `-m N` bound |
57
+ | `find /`, `find ~` | No `-maxdepth` | Has `-maxdepth N` |
58
+ | `cat <file.ts>` | Code file, no pipeline | In pipeline (`cat … \| head`) or non-code file |
59
+ | `git log` | No count limit | Has `-n N`, `--max-count`, or `\| head` |
60
+ | `git diff` | Bare (no path/flag) | Has path arg or `--stat` |
61
+ | `bash -c "…"`, `eval "…"` | Inner command is heavy | Inner command is benign |
62
+
63
+ ## Installing / Removing Hooks
64
+
65
+ ```bash
66
+ npx token-pilot install-hook # register PreToolUse hooks in Claude Code
67
+ npx token-pilot uninstall-hook # remove hooks
68
+ ```
69
+
70
+ Hooks are auto-installed on first server start inside Claude Code. The Claude Code plugin path installs hooks automatically:
71
+
72
+ ```bash
73
+ claude plugin marketplace add https://github.com/Digital-Threads/token-pilot
74
+ claude plugin install token-pilot@token-pilot
75
+ ```
76
+
77
+ ## Environment Variables
78
+
79
+ | Var | Effect |
80
+ |-----|--------|
81
+ | `TOKEN_PILOT_MODE` | `advisory` / `deny` (default) / `strict` — enforcement level for Grep/Bash hooks and MCP output caps |
82
+ | `TOKEN_PILOT_BYPASS=1` | Pass every Read through (Read hook only) |
83
+ | `TOKEN_PILOT_DENY_THRESHOLD=<n>` | Override `hooks.denyThreshold` (default 300) |
84
+ | `TOKEN_PILOT_ADAPTIVE_THRESHOLD=true` | Enable adaptive curve as session burns |
85
+ | `TOKEN_PILOT_DEBUG=1` | Verbose hook logging to stderr |
86
+ | `TOKEN_PILOT_NO_AGENT_REMINDER=1` | Suppress the "tp-* not installed" stderr nudge |
87
+ | `TOKEN_PILOT_SUBAGENT=1` | Mark the MCP server as running inside a subagent |
88
+
89
+ ## Analytics & Audit
90
+
91
+ ```bash
92
+ token-pilot stats # totals + top files from hook-events.jsonl
93
+ token-pilot stats --session[=<id>] # filter by session
94
+ token-pilot stats --by-agent # grouped by agent
95
+ token-pilot tool-audit # per-tool savings distribution (cumulative)
96
+ token-pilot tool-audit --json # machine-readable output
97
+ ```
98
+
99
+ Hook events accumulate in `.token-pilot/hook-events.jsonl`. The `session_analytics` MCP tool provides per-tool breakdown within the current session.
@@ -0,0 +1,143 @@
1
+ # Installation Guide
2
+
3
+ ## Quickest path
4
+
5
+ ```bash
6
+ npx -y token-pilot init
7
+ ```
8
+
9
+ Writes `.mcp.json` (or merges into an existing one), adds `token-pilot` + [`context-mode`](https://github.com/mksglu/claude-context-mode), then prompts to install `tp-*` subagents. Restart your AI assistant to activate.
10
+
11
+ ---
12
+
13
+ ## Claude Code
14
+
15
+ Three paths — pick one, they're mutually exclusive.
16
+
17
+ ### A. Plugin (one-step: hooks + MCP registered together)
18
+
19
+ ```bash
20
+ claude plugin marketplace add https://github.com/Digital-Threads/token-pilot
21
+ claude plugin install token-pilot@token-pilot
22
+ ```
23
+
24
+ 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. Run `install-agents` separately for the `tp-*` subagents.
25
+
26
+ ### B. MCP config (npm-based, no plugin system)
27
+
28
+ ```bash
29
+ claude mcp add token-pilot -- npx -y token-pilot
30
+ # or for a specific scope:
31
+ claude mcp add --scope user token-pilot -- npx -y token-pilot
32
+ claude mcp add --scope project token-pilot -- npx -y token-pilot
33
+ ```
34
+
35
+ Or edit `.mcp.json` (project-level) / `~/.mcp.json` (user-level) directly:
36
+
37
+ ```json
38
+ {
39
+ "mcpServers": {
40
+ "token-pilot": { "command": "npx", "args": ["-y", "token-pilot"] },
41
+ "context-mode": { "command": "npx", "args": ["-y", "claude-context-mode"] }
42
+ }
43
+ }
44
+ ```
45
+
46
+ Then:
47
+ ```bash
48
+ npx token-pilot install-hook # register PreToolUse hooks
49
+ npx token-pilot install-agents --scope=user # install tp-* subagents
50
+ ```
51
+
52
+ ### C. One-liner
53
+
54
+ ```bash
55
+ npx -y token-pilot init
56
+ ```
57
+
58
+ Writes path B config for you, then prompts about subagents.
59
+
60
+ ---
61
+
62
+ ## Cursor
63
+
64
+ Cursor reads `.cursor/mcp.json` (project) or `~/.cursor/mcp.json` (global):
65
+
66
+ ```json
67
+ {
68
+ "mcpServers": {
69
+ "token-pilot": { "command": "npx", "args": ["-y", "token-pilot"] }
70
+ }
71
+ }
72
+ ```
73
+
74
+ ---
75
+
76
+ ## Codex CLI
77
+
78
+ Codex reads `~/.codex/config.toml`:
79
+
80
+ ```toml
81
+ [mcp_servers.token-pilot]
82
+ command = "npx"
83
+ args = ["-y", "token-pilot"]
84
+ ```
85
+
86
+ ---
87
+
88
+ ## Cline (VS Code)
89
+
90
+ Cline reads `cline_mcp_settings.json` (accessible via Cline panel → MCP Servers → Edit):
91
+
92
+ ```json
93
+ {
94
+ "mcpServers": {
95
+ "token-pilot": { "command": "npx", "args": ["-y", "token-pilot"] }
96
+ }
97
+ }
98
+ ```
99
+
100
+ ---
101
+
102
+ ## Gemini CLI
103
+
104
+ Add to `~/.gemini/settings.json` or follow Gemini CLI MCP documentation for your version.
105
+
106
+ ---
107
+
108
+ ## Any MCP-compatible client
109
+
110
+ The server is a plain stdio process:
111
+
112
+ ```
113
+ command: npx
114
+ args: -y token-pilot
115
+ ```
116
+
117
+ No env vars required. Common optional overrides:
118
+
119
+ | Env var | Default | Purpose |
120
+ |---------|---------|---------|
121
+ | `TOKEN_PILOT_MODE` | `deny` | `advisory` / `deny` / `strict` — enforcement level |
122
+ | `TOKEN_PILOT_PROFILE` | `full` | `nav` / `edit` / `full` — trims `tools/list` payload |
123
+ | `TOKEN_PILOT_DENY_THRESHOLD` | `300` | Line count above which the Read hook intervenes |
124
+ | `TOKEN_PILOT_ADAPTIVE_THRESHOLD` | `false` | Enable adaptive curve as session burns |
125
+ | `TOKEN_PILOT_BYPASS` | unset | Set to `1` to disable the Read hook for one session |
126
+ | `TOKEN_PILOT_SKIP_POSTINSTALL` | unset | Skip `ast-index` safety-net install at `npm install` time |
127
+
128
+ ---
129
+
130
+ ## From source (contributors / vendored installs)
131
+
132
+ ```bash
133
+ git clone https://github.com/Digital-Threads/token-pilot.git
134
+ cd token-pilot && npm install && npm run build
135
+ # Point your client's config at dist/index.js:
136
+ # "command": "node", "args": ["/abs/path/to/token-pilot/dist/index.js"]
137
+ ```
138
+
139
+ ---
140
+
141
+ ## Non-Claude clients
142
+
143
+ `install-agents` detects non-Claude clients via env vars + filesystem markers (`CURSOR_TRACE_ID`, `~/.codex/`, `~/.gemini/`, etc.) and **skips installing subagents** unless you pass `--scope=user|project` explicitly. Cursor, Codex, Gemini, and Cline users get all 22 MCP tools + PreToolUse hooks without the `tp-*` agents.
package/docs/tools.md ADDED
@@ -0,0 +1,61 @@
1
+ # MCP Tools Reference
2
+
3
+ Token Pilot exposes 22 MCP tools. All handlers remain active regardless of [tool profile](configuration.md#tool-profiles) — the profile only trims what appears in `tools/list` at session start.
4
+
5
+ ## Reading
6
+
7
+ | Tool | Instead of | Purpose |
8
+ |------|-----------|---------|
9
+ | `smart_read` | `Read` | AST outline; 90% fewer tokens on large files |
10
+ | `read_symbol` | `Read` + scroll | One class/function by name (`Class.method` supported) |
11
+ | `read_symbols` | N × `read_symbol` | Batch up to 10 symbols from one file |
12
+ | `read_for_edit` | `Read` before `Edit` | Minimal raw code around a symbol — copy directly as `old_string` |
13
+ | `read_range` | `Read` offset | Specific line range |
14
+ | `read_section` | `Read` | Section by heading (Markdown) or key (YAML/JSON/CSV) |
15
+ | `read_diff` | re-`Read` after edit | Changed hunks since last `smart_read` |
16
+ | `smart_read_many` | multiple `Read` | Batch smart_read for up to 20 files |
17
+
18
+ ## Search & Navigation
19
+
20
+ | Tool | Instead of | Purpose |
21
+ |------|-----------|---------|
22
+ | `find_usages` | `Grep` (refs) | All usages of a symbol; filters by scope/kind/lang/mode |
23
+ | `project_overview` | `ls` + explore | Project type, frameworks, architecture, directory map |
24
+ | `related_files` | manual | Import graph: imports, importers, test files |
25
+ | `outline` | multiple `smart_read` | Compact symbol overview of all code in a directory |
26
+ | `find_unused` | manual | Dead code detection — unreferenced exported symbols |
27
+ | `code_audit` | multiple `Grep` | TODOs, deprecated symbols, structural patterns |
28
+ | `module_info` | manual | Deps, dependents, public API, unused deps |
29
+ | `smart_diff` | raw `git diff` | Structural diff with symbol mapping |
30
+ | `explore_area` | 3–5 calls | Structure + imports + tests + recent changes in one call |
31
+ | `smart_log` | raw `git log` | Structured commits with category detection |
32
+ | `test_summary` | raw test output | Run tests → pass/fail summary + failure details |
33
+
34
+ ## Session
35
+
36
+ | Tool | Purpose |
37
+ |------|---------|
38
+ | `session_snapshot` | Compact markdown snapshot (<200 tokens) of goal, decisions, facts, blockers, next step. Auto-persisted to `.token-pilot/snapshots/latest.md`. |
39
+ | `session_budget` | Hook-suppression pressure for this session: saved tokens, burn fraction, effective denyThreshold, time-to-compact projection. |
40
+ | `session_analytics` | Token savings: per-tool breakdown, top files, policy advisories. |
41
+
42
+ ## `find_usages` modes
43
+
44
+ `find_usages` accepts a `mode` parameter:
45
+
46
+ | Mode | Output | Tokens |
47
+ |------|--------|--------|
48
+ | `full` | Symbol usages with surrounding code context | ~5–20× more |
49
+ | `list` *(strict default)* | File:line pairs only — 5–10× smaller | smallest |
50
+
51
+ In `TOKEN_PILOT_MODE=strict`, `mode` defaults to `"list"` when not set by the caller. Pass `mode: "full"` explicitly to override.
52
+
53
+ ## `smart_read` scopes
54
+
55
+ | Scope | Output |
56
+ |-------|--------|
57
+ | *(default)* | Full AST outline with types, signatures, docs |
58
+ | `nav` | Names + line numbers only (2–3× smaller) |
59
+ | `exports` | Public API surface only |
60
+
61
+ In `TOKEN_PILOT_MODE=strict`, `max_tokens` defaults to 2 000 when not set by the caller.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "token-pilot",
3
- "version": "0.29.0",
4
- "description": "Save up to 80% tokens when AI reads code \u2014 MCP server for token-efficient code navigation, AST-aware structural reading instead of dumping full files into context window",
3
+ "version": "0.30.0",
4
+ "description": "Save up to 80% tokens when AI reads code MCP server for token-efficient code navigation, AST-aware structural reading instead of dumping full files into context window",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "bin": {