token-pilot 0.7.4 → 0.7.5
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/README.md +39 -52
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Token Pilot
|
|
2
2
|
|
|
3
|
-
MCP server that reduces token consumption in AI coding assistants by **80
|
|
3
|
+
MCP server that reduces token consumption in AI coding assistants by **60-80%** via AST-aware lazy file reading.
|
|
4
4
|
|
|
5
5
|
Instead of dumping entire files into the LLM context, Token Pilot returns structural overviews (classes, functions, signatures, line ranges) and lets the AI load only the specific symbols it needs.
|
|
6
6
|
|
|
@@ -13,11 +13,11 @@ Token Pilot: smart_read("user-service.ts") → 15-line outline → ~200 tok
|
|
|
13
13
|
After edit: read_diff("user-service.ts") → ~20 tokens
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
**~80% reduction** in this example. Files under 80 lines are returned in full automatically (no overhead for small files).
|
|
17
17
|
|
|
18
18
|
## Installation
|
|
19
19
|
|
|
20
|
-
### npx — Any AI Assistant
|
|
20
|
+
### npx — Any MCP-compatible AI Assistant
|
|
21
21
|
|
|
22
22
|
Zero install. Add to your `.mcp.json` (project-level or `~/.mcp.json` for global):
|
|
23
23
|
|
|
@@ -34,21 +34,15 @@ Zero install. Add to your `.mcp.json` (project-level or `~/.mcp.json` for global
|
|
|
34
34
|
|
|
35
35
|
**That's it.** npx downloads the package, ast-index binary is fetched automatically on first run. No Rust, no Cargo, no manual setup.
|
|
36
36
|
|
|
37
|
+
Works with: **Cursor**, **Cline**, **Continue**, **Codex**, **Antigravity**, and any MCP-compatible client.
|
|
38
|
+
|
|
37
39
|
#### Cursor
|
|
38
40
|
|
|
39
41
|
Settings → MCP Servers → Add:
|
|
40
42
|
- Command: `npx`
|
|
41
43
|
- Args: `-y token-pilot`
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
From inside a Claude Code chat session:
|
|
46
|
-
|
|
47
|
-
```
|
|
48
|
-
/mcp add token-pilot -- npx -y token-pilot
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
Or from the terminal:
|
|
45
|
+
#### Claude Code
|
|
52
46
|
|
|
53
47
|
```bash
|
|
54
48
|
# Current project only
|
|
@@ -61,8 +55,6 @@ claude mcp add --scope user token-pilot -- npx -y token-pilot
|
|
|
61
55
|
claude mcp add --scope project token-pilot -- npx -y token-pilot
|
|
62
56
|
```
|
|
63
57
|
|
|
64
|
-
This registers the MCP server. The PreToolUse hook auto-suggests `smart_read` for large files.
|
|
65
|
-
|
|
66
58
|
### From Source
|
|
67
59
|
|
|
68
60
|
```bash
|
|
@@ -94,60 +86,55 @@ brew tap defendend/ast-index && brew install ast-index
|
|
|
94
86
|
npx token-pilot install-ast-index
|
|
95
87
|
```
|
|
96
88
|
|
|
97
|
-
### PreToolUse Hook (
|
|
89
|
+
### PreToolUse Hook (Claude Code only)
|
|
98
90
|
|
|
99
|
-
|
|
91
|
+
Optional hook that intercepts `Read` calls for large code files (>500 lines) and suggests `smart_read`. Claude Code only.
|
|
100
92
|
|
|
101
93
|
```bash
|
|
102
|
-
npx token-pilot install-hook #
|
|
94
|
+
npx token-pilot install-hook # Install
|
|
103
95
|
npx token-pilot uninstall-hook # Remove
|
|
104
96
|
```
|
|
105
97
|
|
|
106
|
-
|
|
98
|
+
> **Note:** With v0.7.4+ MCP instructions, the hook is less critical — AI agents already know to prefer Token Pilot tools.
|
|
107
99
|
|
|
108
|
-
|
|
100
|
+
## How AI Agents Know to Use Token Pilot
|
|
109
101
|
|
|
110
|
-
**
|
|
102
|
+
**No configuration needed.** Token Pilot uses the MCP protocol's `instructions` field to automatically tell AI agents when to use its tools instead of built-in defaults (Read, cat, Grep).
|
|
111
103
|
|
|
112
|
-
|
|
104
|
+
When connected, every MCP client receives rules like:
|
|
113
105
|
|
|
114
106
|
```
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
- Use smart_read_many() instead of multiple Read calls when reading 2+ files.
|
|
124
|
-
- After editing a file, use read_diff() instead of re-reading — shows only changed hunks.
|
|
125
|
-
|
|
126
|
-
## Navigation
|
|
127
|
-
- Use outline("src/modules/users/") to see all files in a directory at once — one call instead of 5-6 smart_read.
|
|
128
|
-
- Use related_files("file.ts") to see import graph: what it imports, what imports it, test files.
|
|
129
|
-
- Use find_usages() instead of Grep when looking for where a symbol is used.
|
|
130
|
-
|
|
131
|
-
## Workflow
|
|
132
|
-
1. project_overview() — start here for unfamiliar projects
|
|
133
|
-
2. outline("src/modules/users/") — overview of a module directory
|
|
134
|
-
3. smart_read("file.ts") — see structure of a file
|
|
135
|
-
4. read_symbol("file.ts", "ClassName.methodName") — read specific code
|
|
136
|
-
5. read_for_edit("file.ts", symbol="methodName") — get raw code for editing
|
|
137
|
-
6. read_diff("file.ts") — after edits, see only changes
|
|
107
|
+
WHEN TO USE TOKEN PILOT (saves 60-80% tokens):
|
|
108
|
+
• Reading code files → smart_read (returns structure, not raw content)
|
|
109
|
+
• Need one function/class → read_symbol (loads only that symbol)
|
|
110
|
+
• Exploring a directory → outline (all symbols in one call)
|
|
111
|
+
...
|
|
112
|
+
WHEN TO USE DEFAULT TOOLS (Token Pilot adds no value):
|
|
113
|
+
• Regex/pattern search → use Grep/ripgrep, NOT find_usages
|
|
114
|
+
• You need exact raw content for copy-paste → use Read
|
|
138
115
|
```
|
|
139
116
|
|
|
117
|
+
This works on **Claude Code, Cursor, Codex, Antigravity**, and any MCP-compatible client — no project-level rules files needed.
|
|
118
|
+
|
|
119
|
+
### Optional: Project-Level Rules
|
|
120
|
+
|
|
121
|
+
For more control, you can add rules to your project:
|
|
122
|
+
|
|
123
|
+
- **Claude Code** → `CLAUDE.md` in project root
|
|
124
|
+
- **Cursor** → `.cursorrules` in project root
|
|
125
|
+
- **Codex** → `AGENTS.md` in project root
|
|
126
|
+
|
|
140
127
|
## MCP Tools (12)
|
|
141
128
|
|
|
142
129
|
### Core Reading
|
|
143
130
|
|
|
144
131
|
| Tool | Instead of | Description |
|
|
145
132
|
|------|-----------|-------------|
|
|
146
|
-
| `smart_read` | `Read` | AST structural overview: classes, functions, methods with signatures. 80
|
|
133
|
+
| `smart_read` | `Read` | AST structural overview: classes, functions, methods with signatures. 60-80% savings. Framework-aware: shows HTTP routes, column types, validation rules. |
|
|
147
134
|
| `read_symbol` | `Read` + scroll | Load source of a specific symbol. Supports `Class.method`. `show` param: full/head/tail/outline. |
|
|
148
|
-
| `read_for_edit` | `Read` before `Edit` |
|
|
135
|
+
| `read_for_edit` | `Read` before `Edit` | Minimal RAW code around a symbol — copy directly as `old_string` for Edit tool. |
|
|
149
136
|
| `read_range` | `Read` offset | Read a specific line range from a file. |
|
|
150
|
-
| `read_diff` | re-`Read` | Show only what changed since last smart_read.
|
|
137
|
+
| `read_diff` | re-`Read` | Show only what changed since last smart_read. Saves tokens on re-reads. |
|
|
151
138
|
| `smart_read_many` | multiple `Read` | Batch smart_read for up to 20 files in one call. |
|
|
152
139
|
|
|
153
140
|
### Search & Navigation
|
|
@@ -156,8 +143,8 @@ You have Token Pilot MCP server connected. ALWAYS use it instead of default tool
|
|
|
156
143
|
|------|-----------|-------------|
|
|
157
144
|
| `find_usages` | `Grep` (refs) | All usages of a symbol: definitions, imports, references. |
|
|
158
145
|
| `project_overview` | `ls` + explore | Project type, architecture, frameworks, directory map. |
|
|
159
|
-
| `related_files` | manual explore |
|
|
160
|
-
| `outline` | multiple `smart_read` |
|
|
146
|
+
| `related_files` | manual explore | Import graph: what a file imports, what imports it, test files. |
|
|
147
|
+
| `outline` | multiple `smart_read` | Compact overview of all code files in a directory. One call instead of 5-6. |
|
|
161
148
|
| `find_unused` | manual | Detect dead code — unused functions, classes, variables. |
|
|
162
149
|
|
|
163
150
|
### Analytics
|
|
@@ -247,7 +234,7 @@ When both are configured, Token Pilot automatically:
|
|
|
247
234
|
- Shows combined architecture info in `session_analytics`
|
|
248
235
|
- Provides `export_ast_index` to feed AST data into context-mode's BM25 index
|
|
249
236
|
|
|
250
|
-
**Combined savings:
|
|
237
|
+
**Combined savings: 60-80%** in a typical coding session.
|
|
251
238
|
|
|
252
239
|
## Supported Languages
|
|
253
240
|
|
|
@@ -262,7 +249,7 @@ Plus structural summaries for non-code files: JSON, YAML, Markdown, TOML, XML, C
|
|
|
262
249
|
### Verify installation
|
|
263
250
|
|
|
264
251
|
```bash
|
|
265
|
-
npx token-pilot --help # Should print CLI help
|
|
252
|
+
npx token-pilot --help # Should print CLI help
|
|
266
253
|
npx token-pilot --version # Should print current version
|
|
267
254
|
npx token-pilot doctor # Run diagnostics (checks ast-index, config, etc.)
|
|
268
255
|
```
|
|
@@ -302,7 +289,7 @@ npm run dev # TypeScript watch mode
|
|
|
302
289
|
```
|
|
303
290
|
src/
|
|
304
291
|
index.ts — CLI entry point (6 commands)
|
|
305
|
-
server.ts — MCP server
|
|
292
|
+
server.ts — MCP server setup, tool definitions, instructions
|
|
306
293
|
types.ts — Core domain types
|
|
307
294
|
ast-index/
|
|
308
295
|
client.ts — ast-index CLI wrapper
|