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
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Configuration & Tool Profiles
|
|
2
|
+
|
|
3
|
+
## .token-pilot.json
|
|
4
|
+
|
|
5
|
+
Drop `.token-pilot.json` in your project root. All fields are optional.
|
|
6
|
+
|
|
7
|
+
```json
|
|
8
|
+
{
|
|
9
|
+
"hooks": { "mode": "deny-enhanced", "denyThreshold": 300 },
|
|
10
|
+
"sessionStart": { "enabled": true, "showStats": false, "maxReminderTokens": 250 },
|
|
11
|
+
"agents": { "scope": null, "reminder": true },
|
|
12
|
+
"smartRead": { "smallFileThreshold": 200 },
|
|
13
|
+
"cache": { "maxSizeMB": 100, "watchFiles": true },
|
|
14
|
+
"policies": { "maxFullFileReads": 10, "largeReadThreshold": 2000 },
|
|
15
|
+
"astIndex": { "binaryPath": null },
|
|
16
|
+
"updates": { "checkOnStartup": true, "autoUpdate": false },
|
|
17
|
+
"ignore": ["node_modules/**", "dist/**", ".git/**"]
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
| Option | Default | What it does |
|
|
22
|
+
|--------|---------|--------------|
|
|
23
|
+
| `hooks.mode` | `"deny-enhanced"` | Read hook mode: `off` / `advisory` / `deny-enhanced` |
|
|
24
|
+
| `hooks.denyThreshold` | `300` | Line count above which the hook intervenes on unbounded `Read` |
|
|
25
|
+
| `sessionStart.enabled` | `true` | Re-inject MCP-rules reminder at every new session / `/clear` / `/compact` |
|
|
26
|
+
| `agents.scope` | `null` | Persisted scope of last `install-agents` run; reused silently |
|
|
27
|
+
| `agents.reminder` | `true` | Show the "agents not installed" startup nudge |
|
|
28
|
+
| `smartRead.smallFileThreshold` | `200` | Files with fewer lines bypass AST overhead and are returned in full |
|
|
29
|
+
| `cache.maxSizeMB` | `100` | File cache ceiling (LRU eviction) |
|
|
30
|
+
| `policies.maxFullFileReads` | `10` | Warn after N full-file reads in session |
|
|
31
|
+
| `policies.largeReadThreshold` | `2000` | Token threshold above which a read is flagged as "large" in analytics |
|
|
32
|
+
|
|
33
|
+
## Tool Profiles
|
|
34
|
+
|
|
35
|
+
Trim the advertised `tools/list` to save ~2 k tokens per session. Set via `TOKEN_PILOT_PROFILE` in your MCP server env block.
|
|
36
|
+
|
|
37
|
+
| Profile | Tools | ~Tokens | Use when |
|
|
38
|
+
|---------|------:|--------:|----------|
|
|
39
|
+
| `full` *(default)* | 22 | ~4 150 | All capabilities |
|
|
40
|
+
| `edit` | 16 | ~3 120 | Code-change workflows (nav + batch reads + `read_for_edit`) |
|
|
41
|
+
| `nav` | 10 | ~1 910 | Read-only exploration / subagents that only navigate |
|
|
42
|
+
|
|
43
|
+
Handlers remain active regardless of profile — a subagent that explicitly names a filtered-out tool still gets served. The profile only controls what appears in `tools/list` at session start.
|
|
44
|
+
|
|
45
|
+
### Setting a profile
|
|
46
|
+
|
|
47
|
+
**In `.mcp.json`:**
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"mcpServers": {
|
|
51
|
+
"token-pilot": {
|
|
52
|
+
"command": "npx",
|
|
53
|
+
"args": ["-y", "token-pilot"],
|
|
54
|
+
"env": { "TOKEN_PILOT_PROFILE": "nav" }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Via shell:**
|
|
61
|
+
```bash
|
|
62
|
+
TOKEN_PILOT_PROFILE=edit npx token-pilot
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## CLI Reference
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
token-pilot # start MCP server
|
|
69
|
+
token-pilot init # create/merge .mcp.json; prompt about subagents
|
|
70
|
+
token-pilot install-agents [--scope=user|project] [--force]
|
|
71
|
+
token-pilot uninstall-agents --scope=user|project
|
|
72
|
+
token-pilot bless-agents # extend third-party agents with token-pilot MCP
|
|
73
|
+
token-pilot unbless-agents <name>... | --all
|
|
74
|
+
token-pilot install-hook # install PreToolUse hooks
|
|
75
|
+
token-pilot uninstall-hook
|
|
76
|
+
token-pilot stats # totals + top files from hook-events.jsonl
|
|
77
|
+
token-pilot stats --session[=<id>] | --by-agent
|
|
78
|
+
token-pilot tool-audit # per-tool savings distribution
|
|
79
|
+
token-pilot tool-audit --json
|
|
80
|
+
token-pilot doctor # diagnostics (ast-index, config, upstream drift)
|
|
81
|
+
token-pilot doctor --check=env # env var check only
|
|
82
|
+
token-pilot install-ast-index # download ast-index binary (auto on first run)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Architecture
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
src/
|
|
89
|
+
index.ts — CLI entry + MCP server bootstrap
|
|
90
|
+
server.ts — MCP server: 22 tool definitions + enforcement mode
|
|
91
|
+
server/
|
|
92
|
+
enforcement-mode.ts — TOKEN_PILOT_MODE parsing (advisory / deny / strict)
|
|
93
|
+
ast-index/ — ast-index binary client + auto-install
|
|
94
|
+
core/
|
|
95
|
+
event-log.ts — hook-events.jsonl + rotation + retention
|
|
96
|
+
session-analytics.ts, policy-engine.ts, intent-classifier.ts
|
|
97
|
+
hooks/
|
|
98
|
+
installer.ts — hook install/uninstall for Claude Code
|
|
99
|
+
pre-bash.ts — PreToolUse:Bash advisor (Bash/sh/eval/loop patterns)
|
|
100
|
+
pre-grep.ts — PreToolUse:Grep advisor (symbol-like pattern detection)
|
|
101
|
+
session-start.ts — SessionStart reminder handler
|
|
102
|
+
summary-pipeline.ts — ast-index → regex → head+tail → pass-through
|
|
103
|
+
cli/
|
|
104
|
+
install-agents.ts, uninstall-agents.ts
|
|
105
|
+
bless-agents.ts, unbless-agents.ts, doctor-drift.ts
|
|
106
|
+
stats.ts, tool-audit.ts
|
|
107
|
+
templates/agent-builder.ts
|
|
108
|
+
config/loader.ts, defaults.ts
|
|
109
|
+
handlers/ — 22 MCP tool handlers
|
|
110
|
+
git/ — HEAD + file watchers (cache invalidation)
|
|
111
|
+
|
|
112
|
+
scripts/
|
|
113
|
+
build-agents.mjs — render templates/ → dist/agents/
|
|
114
|
+
bench-hook.mjs — hook latency benchmark
|
|
115
|
+
|
|
116
|
+
templates/agents/ — source for tp-* family + shared preamble + contract
|
|
117
|
+
```
|
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,169 @@
|
|
|
1
|
+
# Installation Guide
|
|
2
|
+
|
|
3
|
+
## TL;DR
|
|
4
|
+
|
|
5
|
+
**Claude Code — plugin (recommended):**
|
|
6
|
+
```bash
|
|
7
|
+
# New machine:
|
|
8
|
+
claude plugin marketplace add https://github.com/Digital-Threads/token-pilot
|
|
9
|
+
claude plugin install token-pilot@token-pilot
|
|
10
|
+
|
|
11
|
+
# Update:
|
|
12
|
+
claude plugin update token-pilot
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**Other clients (Cursor, Codex, Cline, …):**
|
|
16
|
+
```bash
|
|
17
|
+
# New machine:
|
|
18
|
+
npx -y token-pilot init
|
|
19
|
+
|
|
20
|
+
# Update — npx always pulls fresh, just restart your client.
|
|
21
|
+
# Or if installed globally:
|
|
22
|
+
npm i -g token-pilot@latest
|
|
23
|
+
npx token-pilot install-hook
|
|
24
|
+
npx token-pilot install-agents --scope=user --force
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## First-time setup (full walkthrough)
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx -y token-pilot init
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
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.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Claude Code
|
|
40
|
+
|
|
41
|
+
Three paths — pick one, they're mutually exclusive.
|
|
42
|
+
|
|
43
|
+
### A. Plugin (one-step: hooks + MCP registered together)
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
claude plugin marketplace add https://github.com/Digital-Threads/token-pilot
|
|
47
|
+
claude plugin install token-pilot@token-pilot
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
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.
|
|
51
|
+
|
|
52
|
+
### B. MCP config (npm-based, no plugin system)
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
claude mcp add token-pilot -- npx -y token-pilot
|
|
56
|
+
# or for a specific scope:
|
|
57
|
+
claude mcp add --scope user token-pilot -- npx -y token-pilot
|
|
58
|
+
claude mcp add --scope project token-pilot -- npx -y token-pilot
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Or edit `.mcp.json` (project-level) / `~/.mcp.json` (user-level) directly:
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"mcpServers": {
|
|
66
|
+
"token-pilot": { "command": "npx", "args": ["-y", "token-pilot"] },
|
|
67
|
+
"context-mode": { "command": "npx", "args": ["-y", "claude-context-mode"] }
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Then:
|
|
73
|
+
```bash
|
|
74
|
+
npx token-pilot install-hook # register PreToolUse hooks
|
|
75
|
+
npx token-pilot install-agents --scope=user # install tp-* subagents
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### C. One-liner
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
npx -y token-pilot init
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Writes path B config for you, then prompts about subagents.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Cursor
|
|
89
|
+
|
|
90
|
+
Cursor reads `.cursor/mcp.json` (project) or `~/.cursor/mcp.json` (global):
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"mcpServers": {
|
|
95
|
+
"token-pilot": { "command": "npx", "args": ["-y", "token-pilot"] }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Codex CLI
|
|
103
|
+
|
|
104
|
+
Codex reads `~/.codex/config.toml`:
|
|
105
|
+
|
|
106
|
+
```toml
|
|
107
|
+
[mcp_servers.token-pilot]
|
|
108
|
+
command = "npx"
|
|
109
|
+
args = ["-y", "token-pilot"]
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Cline (VS Code)
|
|
115
|
+
|
|
116
|
+
Cline reads `cline_mcp_settings.json` (accessible via Cline panel → MCP Servers → Edit):
|
|
117
|
+
|
|
118
|
+
```json
|
|
119
|
+
{
|
|
120
|
+
"mcpServers": {
|
|
121
|
+
"token-pilot": { "command": "npx", "args": ["-y", "token-pilot"] }
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Gemini CLI
|
|
129
|
+
|
|
130
|
+
Add to `~/.gemini/settings.json` or follow Gemini CLI MCP documentation for your version.
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Any MCP-compatible client
|
|
135
|
+
|
|
136
|
+
The server is a plain stdio process:
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
command: npx
|
|
140
|
+
args: -y token-pilot
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
No env vars required. Common optional overrides:
|
|
144
|
+
|
|
145
|
+
| Env var | Default | Purpose |
|
|
146
|
+
|---------|---------|---------|
|
|
147
|
+
| `TOKEN_PILOT_MODE` | `deny` | `advisory` / `deny` / `strict` — enforcement level |
|
|
148
|
+
| `TOKEN_PILOT_PROFILE` | `full` | `nav` / `edit` / `full` — trims `tools/list` payload |
|
|
149
|
+
| `TOKEN_PILOT_DENY_THRESHOLD` | `300` | Line count above which the Read hook intervenes |
|
|
150
|
+
| `TOKEN_PILOT_ADAPTIVE_THRESHOLD` | `false` | Enable adaptive curve as session burns |
|
|
151
|
+
| `TOKEN_PILOT_BYPASS` | unset | Set to `1` to disable the Read hook for one session |
|
|
152
|
+
| `TOKEN_PILOT_SKIP_POSTINSTALL` | unset | Skip `ast-index` safety-net install at `npm install` time |
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## From source (contributors / vendored installs)
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
git clone https://github.com/Digital-Threads/token-pilot.git
|
|
160
|
+
cd token-pilot && npm install && npm run build
|
|
161
|
+
# Point your client's config at dist/index.js:
|
|
162
|
+
# "command": "node", "args": ["/abs/path/to/token-pilot/dist/index.js"]
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Non-Claude clients
|
|
168
|
+
|
|
169
|
+
`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/hooks/hooks.json
CHANGED
|
@@ -19,6 +19,24 @@
|
|
|
19
19
|
}
|
|
20
20
|
]
|
|
21
21
|
},
|
|
22
|
+
{
|
|
23
|
+
"matcher": "MultiEdit",
|
|
24
|
+
"hooks": [
|
|
25
|
+
{
|
|
26
|
+
"type": "command",
|
|
27
|
+
"command": "node ${CLAUDE_PLUGIN_ROOT}/dist/index.js hook-edit"
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"matcher": "Write",
|
|
33
|
+
"hooks": [
|
|
34
|
+
{
|
|
35
|
+
"type": "command",
|
|
36
|
+
"command": "node ${CLAUDE_PLUGIN_ROOT}/dist/index.js hook-edit"
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
},
|
|
22
40
|
{
|
|
23
41
|
"matcher": "Bash",
|
|
24
42
|
"hooks": [
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "token-pilot",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Save up to 80% tokens when AI reads code
|
|
3
|
+
"version": "0.30.1",
|
|
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": {
|
package/start.sh
CHANGED
|
@@ -5,24 +5,34 @@
|
|
|
5
5
|
set -e
|
|
6
6
|
|
|
7
7
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
8
|
+
|
|
9
|
+
# Capture user's working directory BEFORE `cd $SCRIPT_DIR` — this is the
|
|
10
|
+
# project root fallback when CLAUDE_PROJECT_DIR is not set. Without this,
|
|
11
|
+
# `$(pwd)` below would resolve to the plugin cache dir and every relative
|
|
12
|
+
# file path would be resolved inside the plugin install, not the project.
|
|
13
|
+
USER_CWD="${PWD:-$(pwd)}"
|
|
14
|
+
|
|
8
15
|
cd "$SCRIPT_DIR"
|
|
9
16
|
|
|
10
17
|
# 1. Install runtime dependencies when the package is incomplete.
|
|
11
18
|
if [ ! -f "node_modules/@modelcontextprotocol/sdk/package.json" ]; then
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
echo "[token-pilot] Installing runtime dependencies..." >&2
|
|
20
|
+
npm install --production --no-audit --no-fund 2>&1 >&2
|
|
14
21
|
fi
|
|
15
22
|
|
|
16
23
|
# 2. Build if dist/ is missing.
|
|
17
24
|
if [ ! -f "dist/index.js" ]; then
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
echo "[token-pilot] Building..." >&2
|
|
26
|
+
if [ ! -f "node_modules/typescript/bin/tsc" ]; then
|
|
27
|
+
npm install --no-audit --no-fund 2>&1 >&2
|
|
28
|
+
fi
|
|
29
|
+
npm run build 2>&1 >&2
|
|
23
30
|
fi
|
|
24
31
|
|
|
25
32
|
# 3. Start the MCP server.
|
|
26
|
-
#
|
|
27
|
-
|
|
33
|
+
# Priority for project root:
|
|
34
|
+
# 1. CLAUDE_PROJECT_DIR — set by Claude Code for the active workspace
|
|
35
|
+
# 2. USER_CWD — the user's shell working directory (captured pre-cd)
|
|
36
|
+
# Passing the plugin cache dir here would poison every relative path lookup.
|
|
37
|
+
PROJECT_ROOT="${CLAUDE_PROJECT_DIR:-$USER_CWD}"
|
|
28
38
|
exec node "$SCRIPT_DIR/dist/index.js" "$PROJECT_ROOT"
|