token-pilot 0.19.1 → 0.19.2

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/CHANGELOG.md CHANGED
@@ -1,580 +1,607 @@
1
- # Changelog
2
-
3
- All notable changes to Token Pilot will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [0.19.1] - 2026-04-15
9
-
10
- ### Added
11
- - **`decisions` field in `session_snapshot`** stores key decisions with reasoning (e.g., "removed sysfee step caused double counting"). Prevents the model from revisiting rejected approaches after context compaction.
12
-
13
- ## [0.19.0] - 2026-04-15
14
-
15
- ### Added
16
- - **`session_snapshot` tool** capture current session state (goal, confirmed facts, files, blockers, next step) as a compact markdown block (<200 tokens). Call before context compaction or when switching direction in long sessions.
17
- - **`max_tokens` parameter** on `smart_read` and `smart_read_many` token budget per read. Output auto-downgrades through three levels: full content structural outline compact (symbol names + line ranges only). Enables context-constrained sessions.
18
- - **Session compaction advisory** — policy engine now tracks total tool calls and tokens returned. Advises calling `session_snapshot()` when thresholds are reached (default: every 15 calls or after 8,000 tokens). Configurable via `compactionCallThreshold` and `compactionTokenThreshold`.
19
- - **"Why This Approach Works"** section in README explaining the 3-level optimization strategy.
20
-
21
- ### Changed
22
- - **21 tools** (was 20)added `session_snapshot`.
23
- - **MCP instructions** updated with `session_snapshot` workflow and `max_tokens` guidance.
24
- - Benchmark numbers updated: 55 files, 102K raw → 9K outline tokens (91% savings).
25
-
26
- ## [0.18.0] - 2026-04-05
27
-
28
- ### Added
29
- - **`read_section` tool** — read a specific section from Markdown, YAML, JSON, or CSV files. Markdown: by heading name. YAML/JSON: by top-level key. CSV: by row range (`rows:1-50`). Much cheaper than reading the whole file.
30
- - **`read_for_edit` section parameter** — prepare edit context for non-code file sections. Works with all 4 formats.
31
- - **Markdown outline with line ranges** — `smart_read` on `.md` files now shows `[L5-20]` ranges and hints for `read_section`.
32
- - **YAML/JSON section ranges** — `smart_read` on `.yaml`/`.json` shows top-level key ranges.
33
- - **CSV smart_read** — shows columns, row count, sample rows, and hints for row-range reading.
34
- - **4 section parsers**`markdown-sections.ts`, `yaml-sections.ts`, `json-sections.ts`, `csv-sections.ts`.
35
-
36
- ### Changed
37
- - **20 tools** (was 19) — added `read_section`.
38
- - **492 tests** (was 441).
39
-
40
- ### Fixed
41
- - `npm audit` resolved brace-expansion, path-to-regexp, picomatch vulnerabilities.
42
-
43
- ## [0.17.0] - 2026-04-02
44
-
45
- ### Added
46
- - **`smart_read` scope parameter** — `scope="nav"` returns names + line ranges only (2-3x smaller), `scope="exports"` shows only public API. Default `scope="full"` unchanged.
47
- - **`smart_read` auto-delta** — when a file changed since last load (within 120s), shows ADDED/REMOVED/UNCHANGED symbols instead of full re-read. Config: `smartRead.autoDelta.enabled`.
48
- - **`read_symbol` include_edit_context** — optional `include_edit_context=true` appends raw code block (max 60 lines) to save a separate `read_for_edit` call. Large symbols fall back to `read_for_edit`.
49
- - **`find_usages` mode=list** — compact `file:line` output for initial discovery, 5-10x smaller than full mode.
50
- - **`smart_read_many` per-file dedup** — skips files already in context and unchanged, returns compact reminder instead.
51
- - **Actionable hints** `read_for_edit` suggests `read_diff` after editing. Config: `display.actionableHints`.
52
- - **`symbol-display-constants.ts`** — shared display constants for symbol rendering.
53
-
54
- ### Changed
55
- - **441 tests** (was 427) — new tests for scope, list mode, include_edit_context, dedup.
56
- - **MCP instructions** updated with scope/mode/include_edit_context guidance.
57
- - **find_usages context rendering** — sequential instead of concurrent to prevent shared cache race condition.
58
-
59
- ## [0.16.1] - 2026-03-21
60
-
61
- ### Added
62
- - **Hook interception tracking** — PreToolUse hook now records denied Read calls (file path, line count, estimated tokens) to `.token-pilot/hook-denied.jsonl`. Session analytics shows how many tokens the hook saved by intercepting unbounded reads on large code files.
63
- - **`session_analytics` hook savings** — compact report adds "Hook: intercepted N reads, saved ~X tokens" line. Verbose mode shows per-file breakdown of intercepted reads.
64
-
65
- ## [0.16.0] - 2026-03-21
66
-
67
- ### Added
68
- - **`read_symbols` tool**batch read multiple symbols from one file in a single call (max 10). File is read once, AST resolved once. Saves N-1 round-trips vs calling `read_symbol` N times.
69
- - **`read_for_edit` batch mode** — new `symbols` array parameter reads multiple symbol edit contexts in one call. Each symbol returns raw code ready for Edit tool's `old_string`.
70
- - **`find_usages` context_lines** — new `context_lines` parameter (0-10) shows surrounding source code for each match. Eliminates follow-up `read_symbol` calls after finding usages.
71
- - **`smart_diff` affected symbols summary** — consolidated "AFFECTED SYMBOLS" section at the top of diff output, grouped by MODIFIED/ADDED/REMOVED. See all changed functions/classes at a glance.
72
-
73
- ### Changed
74
- - **19 tools** (was 18) added `read_symbols`.
75
- - **MCP instructions** — added batch read_symbols to decision rules and refactor workflow.
76
- - **427 tests** (unchanged all pass with new features).
77
-
78
- ## [0.15.0] - 2026-03-19
79
-
80
- ### Added
81
- - **Regex fallback parser (TS/JS)** — `smart_read` now works for TypeScript/JavaScript files even without ast-index binary. Parses classes, functions, interfaces, types, enums, and class methods via regex. Zero dependencies, 130 lines. Covers ~80% of new users who fail to download ast-index.
82
- - **Regex fallback parser (Python)**`smart_read` now works for Python files without ast-index. Parses classes, functions, async functions, decorators (`@dataclass`, `@app.route`), module constants (`UPPER_CASE`), methods with visibility detection (`_private`, `__dunder__`). 150 lines.
83
- - **Benchmark script** `scripts/benchmark.ts` measures real token savings on public repos (express, fastify, flask). 92% average savings across 97 files ≥50 lines. Run: `npx tsx scripts/benchmark.ts`.
84
- - **Guide skill** — `/guide` command shows a quick-reference table of all Token Pilot tools with usage examples and recommended workflow.
85
- - **`hooks.denyThreshold` config** — hook deny threshold is now configurable in `.token-pilot.json` (default: 300, was hardcoded 500). Intercepts ~2x more native Read calls.
86
-
87
- ### Changed
88
- - **Compact session analytics** — `session_analytics` report reduced from ~30 lines to ~5 lines. Shows calls, tokens saved, top 5 tools, top 3 files, cache hit rate on a single screen. Verbose mode (`verbose=true`) restores full breakdown.
89
- - **`server.ts` refactor** — extracted tool definitions to `server/tool-definitions.ts` and token estimate helpers to `server/token-estimates.ts` (−500 lines from server.ts).
90
- - **`find_usages` output** — results grouped by file with compact rendering. Single match per file on one line, multiple matches indented under file header.
91
- - **Stale references** — all `grep_search` hints updated to `Grep` (code-audit, find-unused, find-usages).
92
- - **README** — benchmark table with real data from 4 public repos. Updated savings claims from 80% to 90% (backed by benchmark).
93
- - **427 tests** (was 393).
94
-
95
- ### Fixed
96
- - **`npx token-pilot` CLI** — symlink path resolution in `isDirectRun` check. All CLI commands now work correctly via npx.
97
- - **Regex fallback was dead code** parsers existed but weren't wired into `client.ts` `outline()` method. Now properly called as fallback when ast-index unavailable.
98
-
99
- ## [0.14.1] - 2026-03-14
100
-
101
- ### Fixed
102
- - **CI: Node.js 24 runtime** — opted into `FORCE_JAVASCRIPT_ACTIONS_TO_NODE24` for GitHub Actions, resolving deprecation warnings for `actions/checkout@v4` and `actions/setup-node@v4`.
103
- - **CI: test matrix** — updated from Node 18+22 to Node 20+22 (Node 18 is EOL).
104
- - **Test: git commit in CI** — `read-for-edit` tests now pass `-c user.name` / `-c user.email` to `git commit`, fixing failures in environments without global git config.
105
-
106
- ## [0.14.0] - 2026-03-14
107
-
108
- ### Added
109
- - **R&D Track 0: Instrumentation** — per-call decision trace capturing file size, context state, estimated vs actual cost, and cheaper alternative suggestions. Integrated into all 18 tool handlers via `recordWithTrace()`.
110
- - **R&D Track 1: Budget Planner** — advisory layer suggesting cheaper tool alternatives (e.g. `smart_read` `read_diff` when file already in context, `read_symbol` when symbol known). Analytics-only, no blocking.
111
- - **R&D Track 2: Intent Router** classifies tool calls into 7 intents (edit/debug/explore/review/analyze/search/read). Per-intent breakdown in session analytics.
112
- - **R&D Track 3: Edit Prep Mode** `read_for_edit` with `include_callers`, `include_tests`, `include_changes` enrichment options.
113
- - **R&D Track 4: Session Cache** — tool-result-level caching with file/AST/git invalidation.
114
- - **R&D Track 5: Confidence-Based Escalation** — confidence metadata (high/medium/low) appended to `smart_read`, `read_symbol`, `read_for_edit`, `find_usages` responses. Shows known unknowns and suggested next steps.
115
- - **R&D Track 6: Working Set / Dedup** compact reminders for already-loaded files and symbols.
116
- - **R&D Track 7: Related Files Ranking** — scored ranking with 6 signals (test +5, import +4, importer +3, same-dir +2, recently-changed +2, multi-ref +1). HIGH VALUE / MEDIUM / LOW buckets.
117
- - **R&D Track 8: Architecture Fingerprint** caches architecture in `.token-pilot-fingerprint.json` (24h TTL). Amortizes `project_overview` cost across sessions.
118
- - **R&D Track 9: Verified Savings Dashboard** savings breakdown by category (compression/cache/dedup), session cache hit rate, dedup stats.
119
- - **R&D Track 10: Team Policy Mode** configurable policies: `preferCheapReads`, `maxFullFileReads`, `warnOnLargeReads`, `requireReadForEditBeforeEdit`.
120
- - **7 new core modules** `confidence.ts`, `intent-classifier.ts`, `budget-planner.ts`, `decision-trace.ts`, `session-cache.ts`, `architecture-fingerprint.ts`, `policy-engine.ts`.
121
- - **35 new tests** — confidence (11), architecture-fingerprint (11), policy-engine (13). Total: 393 tests.
122
-
123
- ### Changed
124
- - **`session_analytics`**per-intent breakdown, decision insights, savings by category.
125
- - **`project_overview`** — saves/loads architecture fingerprint for cross-session caching.
126
- - **Config** added `policies` section to `TokenPilotConfig`.
127
-
128
- ## [0.13.0] - 2026-03-14
129
-
130
- ### Added
131
- - **Version check for all components** — on startup, checks token-pilot (npm), ast-index (GitHub releases), and context-mode (npm) in parallel. Non-blocking, fire-and-forget. Shows update notifications in stderr.
132
- - **`autoUpdate` config flag** — `updates.autoUpdate: true` in `.token-pilot.json` auto-downloads new ast-index binary on startup. Default: `false` (notify only). token-pilot and context-mode only notify (separate processes).
133
- - **`checkBinaryUpdate()`** compares installed ast-index version vs latest GitHub release.
134
- - **`isNewerVersion()` utility** — semver comparison: strip `v` prefix, compare segments. Handles different lengths (`1.0` vs `1.0.1`).
135
- - **Common Lisp extensions** — `.lisp`, `.lsp`, `.cl`, `.asd` added to `CODE_EXTENSIONS` for ast-index v3.28+ compatibility.
136
- - **9 new tests** — `isNewerVersion()` covering major/minor/patch, same version, older, `v` prefix, different segment lengths, large numbers, real-world versions. Total: 217 tests.
137
-
138
- ### Changed
139
- - **`doctor` command** now shows 3 sections: token-pilot (installed/latest), ast-index (installed/latest/auto-update status), context-mode (detected/latest npm). Previously only showed ast-index binary status.
140
- - **`install-ast-index` command** now also updates existing binary if newer version available on GitHub.
141
- - **`printHelp()`** fixed tool count: 18 (was incorrectly showing 12 since v0.8.0).
142
- - **Startup update check** replaced single `checkLatestVersion()` with `checkAllUpdates()` covering all 3 components via `Promise.allSettled`.
143
-
144
- ### Fixed
145
- - **`test_summary` PHPUnit parser** — now counts both `Failures:` and `Errors:` (was only counting failures).
146
- - **`test_summary` cargo parser** correctly identifies failure name-list section (no `----` markers) vs detail section.
147
- - **`test_summary` token estimation** — uses shared `estimateTokens()` instead of local duplicate.
148
- - **`smart_log` category detection** — `documentation` now matches docs pattern, `tests` (plural) matches test pattern, `optimize`/`optimization` match perf pattern.
149
- - **`explore_area` path boundary** — `startsWith(path + '/')` prevents `src/auth` matching `src/authorize/`.
150
- - **Validation consistency** — `validateSmartLogArgs` and `validateTestSummaryArgs` now use `optionalString`/`optionalNumber` helpers, reject empty strings, check integers.
151
-
152
- ## [0.11.0] - 2026-03-14
153
-
154
- ### Added
155
- - **`smart_log` tool** — structured git log with commit category detection (feat/fix/refactor/docs/test/chore/style/perf). Shows author breakdown, file stats (+/-), per-commit file list. Filters by path and ref. Raw git log → compact summary.
156
- - **`test_summary` tool** — runs test command and returns structured summary: total/passed/failed/skipped + failure details. Parsers for vitest, jest, pytest, phpunit, go test, cargo test, rspec, mocha + generic fallback. 200 lines of raw output → 10-15 lines.
157
- - **38 new tests** — smart_log parser (5), categorizer (4), test_summary parsers (17), runner detection (8), validation (4). Total: 208 tests (was 170).
158
-
159
- ### Changed
160
- - **18 tools** (was 16) — added `smart_log`, `test_summary`
161
- - **MCP instructions** — added smart_log and test_summary to workflow guidance
162
-
163
- ## [0.10.0] - 2026-03-14
164
-
165
- ### Added
166
- - **`smart_diff` tool** — structural git diff with AST symbol mapping. Shows which functions/classes were modified/added/removed instead of raw patch output. Supports scopes: `unstaged`, `staged`, `commit` (ref required), `branch` (ref required). Small diffs (<=30 lines) include actual hunks, large diffs show summary. Returns `rawTokens` for precise savings analytics.
167
- - **`explore_area` tool** — one-call directory exploration combining outline + imports + tests + git changes. Replaces 3-5 separate tool calls when starting work on an area. Sections: `outline` (recursive depth 2), `imports` (external deps + who imports this area), `tests` (matching test/spec files), `changes` (recent git log). All sections run in parallel via `Promise.allSettled`.
168
- - **26 new tests** smart_diff parser (10), symbol mapping (5), validation (11). Total: 170 tests (was 144).
169
-
170
- ### Changed
171
- - **16 tools** (was 14) — added `smart_diff`, `explore_area`
172
- - **MCP instructions** — updated workflow: `project_overview explore_area smart_read read_symbol → read_for_edit → edit → smart_diff`
173
- - **`outlineDir` and `CODE_EXTENSIONS` exported** from outline.ts for reuse by explore_area
174
-
175
- ## [0.9.0] - 2026-03-08
176
-
177
- ### Added
178
- - **`module_info` tool** — analyze module dependencies, dependents, public API, and unused deps. Uses ast-index v3.27.0 module commands (`modules`, `module-deps`, `module-dependents`, `module-api`, `unused-deps`). Includes degradation check when ast-index is unavailable.
179
- - **`project_overview` dual-detection** — shows BOTH ast-index type detection AND config-file detection (package.json, composer.json, Cargo.toml, pyproject.toml, go.mod) with CONFIDENCE scoring (high/medium/low/unknown). Detects frameworks, quality tools (PHPStan, ESLint, Vitest, Jest, Biome, etc.), CI pipelines (GitHub Actions, GitLab CI, Jenkins), and Docker.
180
- - **`project_overview` `include` parameter** — filter sections: `["stack"]` for quick type check, `["quality","ci"]` for tooling overview. Default: all sections.
181
- - **`find_usages` post-filters** — `scope` (path prefix), `kind` (definitions/imports/usages), `lang` (14 languages by extension), `limit` (per category, 1-500). All filters optional, backward compatible.
182
- - **`outline` recursive mode** — `recursive=true` with `max_depth` (default 2, max 5) recurses into subdirectories. At max depth shows file counts only.
183
- - **`src/core/project-detector.ts`**extracted config-based detection logic into reusable module. Framework detection maps for PHP (7), JS (10), Python (5). Quality tools scanner (13 tools). CI pipeline detector (6 platforms).
184
- - **ast-index client: 5 module methods** — `modules()`, `moduleDeps()`, `moduleDependents()`, `unusedDeps()`, `moduleApi()` with JSON-first + text fallback parsing.
185
- - **ast-index types: 4 module interfaces** — `AstIndexModuleEntry`, `AstIndexModuleDep`, `AstIndexUnusedDep`, `AstIndexModuleApi`.
186
-
187
- ### Fixed
188
- - **`module_info` token savings** — `tokensWouldBe` was equal to `tokensReturned` (0% savings). Now estimates manual analysis cost correctly.
189
- - **`outline` recursive overflow** — added `MAX_OUTLINE_LINES=500` guard to prevent runaway output on large projects with `recursive=true`.
190
- - **`project_overview` "frontend" label** — removed hardcoded "frontend" suffix for secondary stacks (Node.js is not always frontend).
191
- - **Ruff detection** — no longer double-reads `pyproject.toml`. Checks `ruff.toml`/`.ruff.toml` first, falls back to `pyproject.toml [tool.ruff]` only if needed.
192
- - **44 new tests** — validators (23) + project-detector (21). Total: 144 tests (was 100).
193
-
194
- ### Changed
195
- - **14 tools** (was 13) added `module_info`
196
- - **Tool descriptions** — updated with `(v1.1: ...)` version hints for enhanced tools
197
- - **MCP instructions** — added module_info to "COMBINE BOTH" workflow section
198
- - **Version sync** package.json, plugin.json, marketplace.json all at 0.9.0
199
-
200
- ## [0.8.3] - 2026-03-08
201
-
202
- ### Fixed
203
- - **code_audit pattern search — root cause fix** — `ast-index agrep` does not support `--limit` flag. Token Pilot was passing `--limit 50` which caused the command to fail silently, returning 0 results across v0.8.0–v0.8.2. Removed the flag; results are now limited via `.slice()` after parsing.
204
-
205
- ## [0.8.2] - 2026-03-08
206
-
207
- ### Fixed
208
- - **code_audit pattern search** — inject `node_modules/.bin` into PATH so `ast-index agrep` can find `sg` (ast-grep) when it's installed as optional dependency but not in system PATH.
209
- - **code_audit annotations** — strip `@` prefix from annotation names (`@Injectable` `Injectable`). ast-index expects names without `@`.
210
-
211
- ## [0.8.1] - 2026-03-08
212
-
213
- ### Added
214
- - **ast-grep auto-install** — `@ast-grep/cli` added as optional dependency. `code_audit(check="pattern")` now works out-of-the-box without manual `brew install ast-grep`.
215
- - **MCP instructions: security audit guidance** — instructions now recommend Grep for security patterns (password, token, secret, credential) and `find_unused` for dead code detection.
216
-
217
- ### Changed
218
- - **ast-index stats JSON parsing** `--format json` for reliable file count extraction instead of regex on text output.
219
-
220
- ## [0.8.0] - 2026-03-07
221
-
222
- ### Added
223
- - **`code_audit` tool** — find code quality issues in one call: TODO/FIXME comments (`check="todo"`), deprecated symbols (`check="deprecated"`), structural code patterns via ast-grep (`check="pattern"`), decorator search (`check="annotations"`), or combined audit (`check="all"`).
224
- - **Incremental index update on file changes** — file watcher now triggers `ast-index update` (debounced 2s) after edits. Keeps index fresh for find_usages, find_unused, code_audit.
225
- - **ast-index client methods** — `agrep()`, `todo()`, `deprecated()`, `annotations()`, `incrementalUpdate()`.
226
-
227
- ### Fixed
228
- - **smart_read on directories** — now returns helpful message instead of EISDIR crash.
229
- - **MCP instructions** — added "COMBINE BOTH" section for audit tasks (Token Pilot + Grep).
230
-
231
- ## [0.7.6] - 2026-03-07
232
-
233
- ### Added
234
- - **`npx token-pilot init`** — one command creates `.mcp.json` with both token-pilot and context-mode configured. Idempotent — safely updates existing configs without overwriting.
235
- - **MCP Server Instructions** — protocol-level `instructions` field tells AI agents WHEN to use Token Pilot tools instead of built-in defaults. Works universally on all MCP clients.
236
- - **Improved tool descriptions** — each tool explicitly states what built-in tool it replaces (e.g. "Use INSTEAD OF Read/cat").
237
-
238
- ### Fixed
239
- - **3 high severity vulnerabilities** — updated hono and express-rate-limit.
240
- - **npm package size** — excluded source maps from package. 505 kB → 286 kB (−43%).
241
- - **Accurate thresholds** — README and instructions now correctly state smallFileThreshold=200 (was 80).
242
- - **read_diff documentation** — clarified that smart_read must be called BEFORE editing to create baseline snapshot.
243
-
244
- ### Changed
245
- - **README** — honest metrics (60-80%), Quick Start with `init` command, MCP instructions section, Codex/Antigravity support.
246
- - **npm keywords** — added `codex`, `cline`, `model-context-protocol`, `token-savings`.
247
-
248
- ## [0.7.4] - 2026-03-07
249
-
250
- ### Added
251
- - **MCP Server Instructions** protocol-level `instructions` field tells AI agents WHEN to use Token Pilot tools instead of built-in Read/cat/Grep. Works universally on Claude Code, Cursor, Codex, Antigravity, and any MCP-compatible client. Includes rules for when NOT to use Token Pilot (regex search, raw content copy-paste).
252
- - **Improved tool descriptions** — each tool now explicitly states what built-in tool it replaces (e.g. "Use INSTEAD OF Read/cat", "Use INSTEAD OF Grep/ripgrep"). Agents can make informed decisions from description alone, without needing project-level rules files.
253
-
254
- ## [0.7.3] - 2026-03-07
255
-
256
- ### Fixed
257
- - **read_diff diagnostic** — when cache miss occurs, now shows resolved absolute path and all cached file paths. This reveals path mismatches between smart_read and read_diff calls (e.g. different relative paths resolving to different absolute paths).
258
-
259
- ## [0.7.2] - 2026-03-07
260
-
261
- ### Fixed
262
- - **read_diff on small files** — `smart_read` small-file pass-through (≤150 lines) returned content without caching in fileCache. `read_diff` always showed "No previous read" for small files because the baseline was never stored. Now all files are cached regardless of size.
263
-
264
- ## [0.7.1] - 2026-03-07
265
-
266
- ### Fixed
267
- - **read_diff after read_for_edit** — `read_for_edit` now caches the full file content, so `read_diff` can use it as baseline after edits. Previously returned "No previous read" because read_for_edit didn't populate the file cache.
268
- - **outline on intermediate directories** — directories with only subdirectories (no direct code files) now show subdirectory listing with recursive code file counts instead of "No code files found". Enables progressive drill-down: `outline("module/") → outline("module/infrastructure/")`.
269
-
270
- ## [0.7.0] - 2026-03-07
271
-
272
- ### Fixed
273
- - **Project root detection** — complete rewrite of how token-pilot discovers the working project:
274
- 1. **MCP roots** (new, primary) — uses MCP protocol `listRoots()` to get workspace root from Claude Code. Works for all tools including `find_usages`, `find_unused`, `project_overview` (no file path needed).
275
- 2. **INIT_CWD/PWD env vars** (new) — when started via `npx`, npm sets `INIT_CWD` to the invoking directory. Catches cases where `process.cwd()` is `/` but the real project root is available in env.
276
- 3. **Git detect from file path** (improved) — now triggers from any tool call args (`path`, `paths`, `file`, `module`), not just `smart_read`.
277
- - **ast-index tools always disabled** — `find_usages`, `find_unused`, `project_overview` never triggered auto-detect because they have no `path` argument. Now all tools trigger detection via MCP roots.
278
- - **Error messages** — changed "project root is too broad" to actionable "call smart_read() on any project file first" when MCP roots unavailable.
279
- - **`isDangerousRoot`**moved to shared `core/validation.ts` (was duplicated in `index.ts`).
280
-
281
- ## [0.6.5] - 2026-03-07
282
-
283
- ### Fixed
284
- - **AST index rebuild race condition** — concurrent tool calls no longer trigger multiple simultaneous rebuilds. `ensureIndex()` now deduplicates via shared promise. If rebuild fails due to lock file (another process running), falls back to existing index if available instead of throwing.
285
- - **Rebuild timeout** — increased from 60s to 120s for large projects where indexing takes longer.
286
-
287
- ## [0.6.4] - 2026-03-07
288
-
289
- ### Fixed
290
- - **CRITICAL: Hook installer** — malformed `settings.json` no longer silently destroyed. Distinguishes ENOENT (create fresh) from JSON parse error (abort with message). Uninstall also reports specific errors.
291
- - **CRITICAL: Server startup** — `startServer()` now has `.catch()` handler. Unhandled promise rejections no longer crash the process silently.
292
- - **Non-code handler** — removed `.xml` and `.csv` from `isNonCodeStructured` (no handler existed for them, fell through to null).
293
- - **Symbol resolver** — removed dangerous basename-only fallback in `pathMatches` (`index.ts` no longer matches any `index.ts`). Fixed hardcoded `endLine = start_line + 10` → uses `end_line` from ast-index or 50-line fallback.
294
- - **Config loader** — added prototype pollution guard (`__proto__`, `constructor`, `prototype` keys skipped in deepMerge). Parse errors now logged instead of silently swallowed.
295
- - **File cache** — size tracking now uses `Buffer.byteLength()` instead of `string.length` (chars bytes for non-ASCII). Removed dead `isSmallFile()` method.
296
- - **Validation** — `optionalNumber` now rejects `NaN` and `Infinity`.
297
- - **Token estimation** — `smart_read_many` now uses `estimateTokens()` instead of `length/4`.
298
- - **Analytics** — `project_overview` calls now tracked in session analytics.
299
- - **read_for_edit** — raised `MAX_EDIT_LINES` from 20 to 60 (20 was too aggressive, truncated most functions).
300
- - **related_files** — raised symbol search limit from 5 to 10 for reverse import detection.
301
-
302
- ### Removed
303
- - Dead config options `cache.ttlMinutes` and `context.autoForgetMinutes` (declared but never used).
304
-
305
- ## [0.6.3] - 2026-03-03
306
-
307
- ### Changed
308
- - **Hook deny threshold** — raised from 200 to 500 lines. Files ≤500 lines pass through Read without denial roundtrip. Eliminates token overhead on medium files where hook denial costs more than outline saves.
309
- - **Adaptive fallback** — lowered from 90% to 70%. If outline ≥70% of raw file size, returns raw content. More aggressive at avoiding outlines that barely save tokens.
310
- - **Tool descriptions** — trimmed marketing language, percentages, and cross-references. ~250 fewer tokens in tool list per session.
311
- - **Outline cap** — top-level symbols capped at 40, class members at 30. Prevents outline explosion on files with 100+ methods.
312
-
313
- ## [0.6.2] - 2026-03-02
314
-
315
- ### Removed
316
- - **Dead handler files** — deleted `changed-symbols.ts` (removed in v0.5.0) and `find-callers.ts` (removed in v0.4.0). Were never registered in server but lingered as dead code.
317
-
318
- ## [0.6.1] - 2026-03-02
319
-
320
- ### Changed
321
- - **`smallFileThreshold`**raised from 80 to 200 lines. Benchmark showed medium files (100-300 lines) had negative savings (-25%) because AST outline was larger than the raw file. Files ≤200 lines now pass through as raw content.
322
- - **`smart_read` adaptive fallback** — after generating outline, compares token count vs raw file. If outline ≥ 90% of raw size, returns raw content instead. Eliminates negative savings on any file size, regardless of language or threshold.
323
- - **`session_analytics` honest metrics** — replaced all hardcoded multipliers (`*5`, `*3`) with real full-file token counts from file cache. `tokensWouldBe` now reflects actual file size, not fabricated numbers. Non-file tools (related_files, outline, find_usages) report 1:1 (no savings claim).
324
-
325
- ## [0.6.0] - 2026-03-02
326
-
327
- ### Changed
328
- - **Read hook** — upgraded from advisory (`decision: "suggest"`) to blocking (`permissionDecision: "deny"`) for unbounded Read calls on large code files (>200 lines). Bounded Read (with offset/limit) is still allowed. Uses official `hookSpecificOutput` format per Claude Code docs.
329
- - **`read_for_edit` output** — already includes exact `Read(path, offset, limit)` command that passes through the hook, giving AI a clear path: `read_for_edit` → bounded `Read` → `Edit`.
330
-
331
- ### Added
332
- - **Edit hook** — new PreToolUse hook matching Edit tool. Adds `additionalContext` suggesting `read_for_edit` for minimal code context. Doesn't block Edit — just provides a hint.
333
- - **Hook installer** — now installs and manages both Read and Edit hooks. Uninstall removes all Token Pilot hooks.
334
-
335
- ## [0.5.3] - 2026-03-02
336
-
337
- ### Changed
338
- - **`find_unused`**completely rewritten with universal approach. Removed 60+ hardcoded framework-specific names. Now uses ast-index data: constructors filtered by name (`constructor`/`__init__`), Python dunder methods by `__*__` pattern, decorated symbols detected via `outline()` and shown separately with their decorators. No framework-specific knowledge.
339
- - **`formatFrameworkInfo`** (smart_read display) — removed hardcoded TypeORM (`Column`, `PrimaryGeneratedColumn`) and class-validator (`IsEmail`, `MinLength`) parsing. Now only detects standard HTTP verbs (GET/POST/PUT/DELETE/PATCH) which are protocol-level, not framework-specific. All other decorators shown as-is (`@DecoratorName`).
340
- - **`outline`** — route detection now universal. Instead of hardcoding `@Controller`, detects any class decorator with a path argument as route prefix. HTTP verb detection uses same universal pattern. Non-HTTP decorators shown as-is.
341
-
342
- ## [0.5.2] - 2026-03-02
343
-
344
- ### Fixed
345
- - **`project_overview`** HINT no longer references deleted `search_code()`, now suggests `find_usages()` and `outline()`
346
- - **`related_files` imported_by** — now searches both `imports` AND `usages` from refs (not just imports), with increased limit (30). Cross-language filtering preserves same-family matches while removing false positives.
347
- - **`find_unused`** — excludes framework-implicit symbols (replaced by universal approach in 0.5.3)
348
- - **README**updated handler file list (removed deleted handlers, added new ones)
349
-
350
- ## [0.5.1] - 2026-03-02
351
-
352
- ### Fixed
353
- - **`read_for_edit` symbol mode** — large symbols (>20 lines) now return only the first 20 lines instead of the entire method. Prevents returning 300+ lines when only a signature is needed for editing.
354
- - **`related_files` imported_by** — filter cross-language false positives. A TypeScript file no longer shows Python/Go/Rust files as importers. Refs are filtered by language family (JS/TS, Python, Go, JVM, etc.).
355
- - **`session_analytics`**honest savings metric for `read_for_edit`. Reduced multiplier from 30x to 3x (realistic comparison vs `Read` with offset/limit, not vs full file).
356
-
357
- ## [0.5.0] - 2026-03-02
358
-
359
- ### Added
360
- - **`read_for_edit`**killer feature for edit workflow. Returns RAW code (no line numbers) around a symbol or line, ready to copy as `old_string` for Edit. 97% fewer tokens than reading full file before editing.
361
- - **`related_files`** — import graph for any file: what it imports, what imports it, test files. Saves 3-5 Read calls per task.
362
- - **`outline`** — compact overview of all code files in a directory. One call instead of 5-6 smart_read calls. Framework-aware: shows HTTP routes for NestJS controllers.
363
- - **`read_symbol` show parameter** — `show: "full"|"head"|"tail"|"outline"` controls truncation. Default: auto (full ≤300 lines, outline >300).
364
- - **Framework-aware decorators** — smart_read/outline parse NestJS (`@Controller`+`@Get` → HTTP routes), TypeORM (`@Column` → types), class-validator (`@IsEmail` → constraints).
365
-
366
- ### Removed
367
- - **`search_code`** — worse than Grep in practice, find_usages + Grep cover all use cases
368
- - **`export_ast_index`** — never used in real work, infrastructure tool only
369
- - **`context_status`** debugging tool, not user-facing
370
- - **`forget`** — manual context management = poor design, should be automatic
371
- - **`changed_symbols`** — git diff + smart_read covers this use case
372
-
373
- ### Changed
374
- - **12 focused tools** instead of 14 removed 5 low-value, added 3 high-impact
375
- - Edit-heavy sessions: 5-10% 40-50% token savings (via read_for_edit)
376
- - Average sessions: 20-25% → 45-55% token savings
377
-
378
- ## [0.4.1] - 2026-03-02
379
-
380
- ### Added
381
- - **Auto-install PreToolUse hook**: hook installs automatically on server start (Claude Code), no manual `install-hook` needed
382
- - **AI instructions template**: README includes ready-to-copy block for `.cursorrules` / `CLAUDE.md`
383
-
384
- ### Changed
385
- - **Tool descriptions rewritten** — explicit "ALWAYS use instead of Read/cat", "use instead of Grep" for AI prioritization
386
- - README updated: PreToolUse hook section, MCP Tools table with "Instead of" column
387
-
388
- ## [0.4.0] - 2026-03-02
389
-
390
- ### Added
391
- - **Python class method parser**: smart_read/read_symbol shows all methods inside Python classes with visibility, decorators, async detection
392
- - **PHP class method parser**: same for PHP classes with public/private/protected, static
393
- - **Version display**: `project_overview` and `session_analytics` show `TOKEN PILOT v{version}`
394
-
395
- ### Changed
396
- - **Removed find_callers** did not save tokens vs grep, ast-index limitation with `this.method()` calls
397
- - **Removed find_implementations** did not save tokens vs grep, ast-index limitation with decorators
398
- - **Removed class_hierarchy** did not save tokens vs grep, poor results from ast-index
399
- - **14 focused tools** instead of 17 — only tools that actually save tokens or provide unique value
400
-
401
- ### Fixed
402
- - **Mega-symbol truncation**: symbols >300 lines show head (50) + tail (30) + method outline instead of 71KB overflow
403
- - **Recursive findFlat**: unqualified method names (`run`, `_build_summary`) found inside class children
404
-
405
- ## [0.3.2] - 2026-03-01
406
-
407
- ### Fixed
408
- - **Python class methods**: smart_read now shows all methods inside Python classes (ast-index only returns class-level, token-pilot parses `def` methods with visibility, decorators, async detection)
409
- - **read_symbol Python**: `Orchestrator.run`, `Orchestrator._build_summary` qualified and unqualified method access works (was returning entire 829-line class)
410
- - **Mega-symbol truncation**: symbols >300 lines show head (50) + tail (30) + method outline instead of 71KB overflow
411
- - **findFlat recursive**: unqualified method names (`run`, `_build_summary`) now found inside class children
412
-
413
- ## [0.3.1] - 2026-03-01
414
-
415
- ### Fixed
416
- - **find_usages**: combine `refs` + `search` with exact word boundary filtering — 0% result loss vs grep (was 40% loss with refs-only)
417
- - **read_symbol**: fix `Class.method` qualified names for flat outlines (ast-index lists methods as siblings, not children)
418
- - **read_symbol**: filter ast-index leaf name fallback by requested file (was returning symbols from wrong files)
419
- - **YAML smart_read**: 3-level nested parser with scalar values, array counts (was only showing top-level keys)
420
- - Removed all "Use Grep as fallback" hints token-pilot gives complete results on its own
421
-
422
- ## [0.3.0] - 2026-03-01
423
-
424
- ### Added
425
- - **find_callers** tool find all callers of a function, with optional call hierarchy tree (depth parameter)
426
- - **changed_symbols** toolshow symbol-level git changes (added/modified/removed) vs a base branch
427
- - **find_unused** tool — detect potentially unused/dead symbols in the project
428
- - 8 new ast-index client methods: `refs`, `map`, `conventions`, `callers`, `callTree`, `changed`, `unusedSymbols`, `fileImports`
429
- - Incremental index updates via `ast-index update` (fast) instead of full rebuild
430
-
431
- ### Fixed
432
- - **find_usages**: rewritten to use `ast-index refs` — returns definitions + imports + usages in one call (was losing ~66% of results)
433
- - **project_overview**: rewritten to use `ast-index map` + `conventions` — shows architecture, frameworks, naming patterns, directory map with symbol kinds
434
- - **search_code**: deduplication of results (removes duplicate file:line entries)
435
- - **read_symbol**: structure-first lookup for `Class.method` qualified names with ast-index leaf fallback
436
- - **export_ast_index**: `all_indexed=true` option exports all files from ast-index, not just cached ones
437
- - **YAML smart_read**: expand one level of nesting (shows nested keys under top-level sections)
438
-
439
- ### Changed
440
- - Total MCP tools: 14 → 17
441
- - ast-index commands used: 8 → 16
442
- - Index updates are now incremental by default (falls back to full rebuild only when needed)
443
-
444
- ## [0.2.4] - 2026-03-01
445
-
446
- ### Fixed
447
- - **search_code**: filter out garbage entries with empty file paths or `:undefined` lines
448
- - **read_symbol**: support `Class.method` and `Class::method` qualified names (structure-first lookup, ast-index leaf fallback)
449
- - **export_ast_index**: `all_indexed=true` option exports all files from ast-index, not just cached ones
450
- - **YAML smart_read**: expand one level of nesting (shows service names, nested keys under top-level sections)
451
- - Improved empty-cache message in export_ast_index with hint about `all_indexed`
452
-
453
- ## [0.2.3] - 2026-03-01
454
-
455
- ### Fixed
456
- - **ensureIndex**: plain rebuild first (indexes full monorepo), fallback to `--sub-projects` only if <5 files
457
- - **smart_read**: non-code files (YAML, JSON, Markdown, TOML) use structural summary instead of raw content dump
458
- - **smart_read**: unsupported files return truncated 60-line preview instead of full raw content
459
- - **class_hierarchy**: proper parser for ast-index text output (Parents/Children sections)
460
- - **project_overview**: uses directory name when package.json has no `name` field
461
-
462
- ## [0.2.2] - 2026-03-01
463
-
464
- ### Fixed
465
- - Published 0.2.1 contained stale Haiku files in dist/ (tsc doesn't clean old outputs)
466
- - Added `prebuild` script (`rm -rf dist`) to prevent stale artifacts
467
- - Added `chmod +x` in prepublishOnly to ensure bin is executable
468
-
469
- ## [0.2.1] - 2026-03-01
470
-
471
- ### Fixed
472
- - **RC3**: `search_code` now merges all ast-index result types (content_matches + symbols + files + references) — previously only used content_matches which was often empty
473
- - **RC4**: `class_hierarchy` and `implementations` parse text format as fallback when JSON parse fails
474
- - **RC6**: `read_symbol` auto-fetches outline from ast-index if no cached structure no longer requires prior smart_read
475
- - `ensureIndex` uses `--sub-projects` flag for monorepo indexing
476
-
477
- ### Removed
478
- - Reverted Haiku v0.2.1 removed broken PersistentFileCache, DiffEngine, RealTokenEstimator, ContextWindowTracker, smart-read-xml, context-markup
479
- - Removed 3 heavy native dependencies: `better-sqlite3`, `js-tiktoken`, `diff`
480
-
481
- ### Added
482
- - `start.sh` — bootstrap script for Claude Code plugin system
483
-
484
- ## [0.2.0] - 2026-03-01
485
-
486
- ### Fixed
487
- - **P0**: ast-index errors no longer silently swallowed all search/usages/implementations/hierarchy/outline/symbol log errors to stderr
488
- - **P0**: `exec()` now captures and logs ast-index subprocess stderr
489
- - **P0**: `projectRoot` detected via `git rev-parse --show-toplevel` instead of `process.cwd()` (fixes wrong index root)
490
- - **P1**: `forget(all=true)` now clears both ContextRegistry and FileCache (fixes stale export_ast_index/read_diff after forget)
491
- - **P1**: `forget(path=X)` also invalidates FileCache for that path
492
- - **P2**: `read_symbol` supports PHP `::` separator (e.g. `RefundProcessor::refund`)
493
- - **P2**: `findInStructure` recursion fixed supports 3+ level nesting (Namespace::Class::method)
494
- - `ensureIndex()`: verify index has content after `stats` force rebuild if 0 files indexed
495
-
496
- ### Changed
497
- - `project_overview`: now shows directory listing + ast-index stats (files, symbols, references) instead of stub
498
- - `project_overview`: added PHP (`composer.json`) detection
499
-
500
- ## [0.1.6] - 2026-03-01 (unpublished)
501
-
502
- ### Fixed
503
- - `ensureIndex()`: verify index has content after `stats` — force rebuild if 0 files indexed (fixes empty search results on first run)
504
-
505
- ## [0.1.5] - 2026-03-01
506
-
507
- ### Fixed
508
- - PreToolUse hook: read file path from stdin (Claude Code hook format) instead of `$FILE_PATH` env var
509
- - Hook now auto-suggests `smart_read` for large code files when Claude tries to use `Read`
510
- - `session_analytics`: now tracks all tools (read_symbol, read_range, read_diff, smart_read_many, search_code, find_usages, find_implementations, class_hierarchy) — previously only tracked smart_read
511
- - Empty search/usages/implementations results now show diagnostic hints (ast-index status, fallback suggestions)
512
- - `ensureIndex()` now logs build progress and errors to stderr
513
-
514
- ## [0.1.4] - 2026-03-01
515
-
516
- ### Fixed
517
- - Lazy file watcher: watch only loaded files instead of entire project root (fixes crash on Docker volumes, home dir, WSL)
518
-
519
- ## [0.1.3] - 2026-03-01
520
-
521
- ### Fixed
522
- - Chokidar file watcher error handler (partial fix, superseded by 0.1.4)
523
-
524
- ## [0.1.2] - 2026-03-01
525
-
526
- ### Fixed
527
- - ast-index integration: `outline` now parses text output (JSON format not supported in v3.24.0)
528
- - ast-index `symbol` response: handle array format, normalize field names (`line`→`start_line`, `path`→`file`)
529
- - ast-index `search` response: handle `{content_matches: [...]}` wrapper
530
- - ast-index `usages` response: map `context`→`text`, `path`→`file`
531
- - Server version now read dynamically from package.json
532
-
533
- ### Added
534
- - `token-pilot doctor` — diagnostics command (checks ast-index, Node.js, config, updates)
535
- - `token-pilot --version` print current version
536
- - Update check on server startup (non-blocking, logs to stderr)
537
- - `/mcp add` installation method documented for Claude Code chat
538
- - Troubleshooting section in README
539
-
540
- ## [0.1.1] - 2026-03-01
541
-
542
- ### Added
543
- - `npx -y token-pilot` — zero-install for any MCP client (Cursor, Cline, Continue, etc.)
544
- - Claude Code plugin marketplace support (`.claude-plugin/marketplace.json`)
545
- - `start.sh` bootstrap script — auto `npm install` + `npm run build` on first run
546
- - `npm publish` ready (`files` field, `prepublishOnly` script)
547
- - Universal install instructions in README for Claude Code, Cursor, Cline
548
-
549
- ### Changed
550
- - `.mcp.json` now uses `start.sh` for reliable bootstrap
551
- - README reorganized: npx as primary install, from-source as fallback
552
-
553
- ## [0.1.0] - 2026-03-01
554
-
555
- ### Added
556
-
557
- - **Core Reading Tools**: `smart_read`, `read_symbol`, `read_range`, `read_diff`, `smart_read_many`
558
- - AST-based structural overviews saving 80-95% tokens
559
- - Small file pass-through (< 80 lines returned in full)
560
- - O(n) diff algorithm for re-reads
561
- - Advisory context registry with compact reminders
562
- - **Search & Navigation**: `search_code`, `find_usages`, `find_implementations`, `class_hierarchy`, `project_overview`
563
- - Powered by ast-index (tree-sitter + SQLite FTS5)
564
- - Cross-file symbol resolution
565
- - **Context Management**: `session_analytics`, `context_status`, `forget`
566
- - Token savings tracking per tool and per file
567
- - Advisory (non-blocking) context tracking
568
- - **Integration**: `export_ast_index`
569
- - context-mode detection and complementary architecture
570
- - AST data export for BM25 cross-indexing
571
- - **Infrastructure**
572
- - Git HEAD watcher with selective cache invalidation on branch switch
573
- - File watcher (chokidar) for automatic cache invalidation
574
- - LRU file cache with configurable size limit
575
- - Input validation for all tools (path traversal protection)
576
- - Auto-download of ast-index binary from GitHub releases
577
- - PreToolUse hook installer for Claude Code
578
- - Claude Code plugin format (.claude-plugin/)
579
- - Non-code structural summaries (JSON, YAML, Markdown, TOML)
580
- - Configurable via `.token-pilot.json`
1
+ # Changelog
2
+
3
+ All notable changes to Token Pilot will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.19.2] - 2026-04-15
9
+
10
+ ### Added
11
+ - **npm-first binary install**`install-ast-index` now tries `npm install -g @ast-index/cli` before falling back to GitHub download. Works on all platforms including Windows (no more "ZIP extraction not supported" error).
12
+ - **npm binary discovery** — `findBinary` now checks the npm global prefix (`npm config get prefix`) as a 3rd resolution strategy: config → system PATH → npm global → managed install.
13
+
14
+ ### Fixed
15
+ - **Hook installer uses absolute paths** — hooks now write `<node> <script> hook-read` instead of bare `token-pilot hook-read`. Fixes `token-pilot: not found` in `/bin/sh` environments (nvm, npx, non-login shells).
16
+ - **Skip auto-install when running as plugin** when `CLAUDE_PLUGIN_ROOT` is set, the MCP server no longer writes duplicate hooks into `.claude/settings.json`.
17
+ - **Auto-upgrade broken hooks**old hooks with bare `token-pilot` commands are automatically replaced with absolute-path versions on next server start.
18
+
19
+ ### Changed
20
+ - **`BinaryStatus.source`** now includes `'npm'` as a value (shown in `doctor` and `session_analytics`).
21
+ - **`search()` supports `--type` filter** — filter results by symbol type (`class`, `function`, `interface`, etc.). Leverages ast-index ≥3.30.0.
22
+ - **`hierarchy()` supports `--in-file` / `--module` filters** scope class hierarchy queries by filename or module path. Leverages ast-index ≥3.30.0.
23
+ - **498 tests** (was 492).
24
+
25
+ ## [0.19.1] - 2026-04-15
26
+
27
+ ### Added
28
+ - **`decisions` field in `session_snapshot`** — stores key decisions with reasoning (e.g., "removed sysfee step — caused double counting"). Prevents the model from revisiting rejected approaches after context compaction.
29
+
30
+ ## [0.19.0] - 2026-04-15
31
+
32
+ ### Added
33
+ - **`session_snapshot` tool** — capture current session state (goal, confirmed facts, files, blockers, next step) as a compact markdown block (<200 tokens). Call before context compaction or when switching direction in long sessions.
34
+ - **`max_tokens` parameter** on `smart_read` and `smart_read_many` token budget per read. Output auto-downgrades through three levels: full content → structural outline → compact (symbol names + line ranges only). Enables context-constrained sessions.
35
+ - **Session compaction advisory** — policy engine now tracks total tool calls and tokens returned. Advises calling `session_snapshot()` when thresholds are reached (default: every 15 calls or after 8,000 tokens). Configurable via `compactionCallThreshold` and `compactionTokenThreshold`.
36
+ - **"Why This Approach Works"** section in README explaining the 3-level optimization strategy.
37
+
38
+ ### Changed
39
+ - **21 tools** (was 20) — added `session_snapshot`.
40
+ - **MCP instructions** updated with `session_snapshot` workflow and `max_tokens` guidance.
41
+ - Benchmark numbers updated: 55 files, 102K raw → 9K outline tokens (91% savings).
42
+
43
+ ## [0.18.1] - 2026-04-13
44
+
45
+ ### Fixed
46
+ - **Hook installer uses absolute paths** — hooks now write `<node> <script> hook-read` instead of bare `token-pilot hook-read`. Fixes `token-pilot: not found` errors in `/bin/sh` environments (nvm, npx, non-login shells).
47
+ - **Skip auto-install when running as plugin** — when `CLAUDE_PLUGIN_ROOT` is set, the MCP server no longer writes duplicate hooks into `.claude/settings.json` (the plugin system handles this via `hooks.json`).
48
+ - **Auto-upgrade broken hooks** — old hooks with bare `token-pilot` commands are automatically replaced with absolute-path versions on next server start.
49
+
50
+ ### Changed
51
+ - **495 tests** (was 492).
52
+
53
+ ## [0.18.0] - 2026-04-05
54
+
55
+ ### Added
56
+ - **`read_section` tool** read a specific section from Markdown, YAML, JSON, or CSV files. Markdown: by heading name. YAML/JSON: by top-level key. CSV: by row range (`rows:1-50`). Much cheaper than reading the whole file.
57
+ - **`read_for_edit` section parameter** — prepare edit context for non-code file sections. Works with all 4 formats.
58
+ - **Markdown outline with line ranges** — `smart_read` on `.md` files now shows `[L5-20]` ranges and hints for `read_section`.
59
+ - **YAML/JSON section ranges** — `smart_read` on `.yaml`/`.json` shows top-level key ranges.
60
+ - **CSV smart_read** — shows columns, row count, sample rows, and hints for row-range reading.
61
+ - **4 section parsers** — `markdown-sections.ts`, `yaml-sections.ts`, `json-sections.ts`, `csv-sections.ts`.
62
+
63
+ ### Changed
64
+ - **20 tools** (was 19) — added `read_section`.
65
+ - **492 tests** (was 441).
66
+
67
+ ### Fixed
68
+ - `npm audit` — resolved brace-expansion, path-to-regexp, picomatch vulnerabilities.
69
+
70
+ ## [0.17.0] - 2026-04-02
71
+
72
+ ### Added
73
+ - **`smart_read` scope parameter** — `scope="nav"` returns names + line ranges only (2-3x smaller), `scope="exports"` shows only public API. Default `scope="full"` unchanged.
74
+ - **`smart_read` auto-delta** — when a file changed since last load (within 120s), shows ADDED/REMOVED/UNCHANGED symbols instead of full re-read. Config: `smartRead.autoDelta.enabled`.
75
+ - **`read_symbol` include_edit_context** — optional `include_edit_context=true` appends raw code block (max 60 lines) to save a separate `read_for_edit` call. Large symbols fall back to `read_for_edit`.
76
+ - **`find_usages` mode=list** — compact `file:line` output for initial discovery, 5-10x smaller than full mode.
77
+ - **`smart_read_many` per-file dedup** — skips files already in context and unchanged, returns compact reminder instead.
78
+ - **Actionable hints** — `read_for_edit` suggests `read_diff` after editing. Config: `display.actionableHints`.
79
+ - **`symbol-display-constants.ts`** — shared display constants for symbol rendering.
80
+
81
+ ### Changed
82
+ - **441 tests** (was 427) — new tests for scope, list mode, include_edit_context, dedup.
83
+ - **MCP instructions** updated with scope/mode/include_edit_context guidance.
84
+ - **find_usages context rendering** — sequential instead of concurrent to prevent shared cache race condition.
85
+
86
+ ## [0.16.1] - 2026-03-21
87
+
88
+ ### Added
89
+ - **Hook interception tracking** — PreToolUse hook now records denied Read calls (file path, line count, estimated tokens) to `.token-pilot/hook-denied.jsonl`. Session analytics shows how many tokens the hook saved by intercepting unbounded reads on large code files.
90
+ - **`session_analytics` hook savings** — compact report adds "Hook: intercepted N reads, saved ~X tokens" line. Verbose mode shows per-file breakdown of intercepted reads.
91
+
92
+ ## [0.16.0] - 2026-03-21
93
+
94
+ ### Added
95
+ - **`read_symbols` tool** — batch read multiple symbols from one file in a single call (max 10). File is read once, AST resolved once. Saves N-1 round-trips vs calling `read_symbol` N times.
96
+ - **`read_for_edit` batch mode** — new `symbols` array parameter reads multiple symbol edit contexts in one call. Each symbol returns raw code ready for Edit tool's `old_string`.
97
+ - **`find_usages` context_lines** new `context_lines` parameter (0-10) shows surrounding source code for each match. Eliminates follow-up `read_symbol` calls after finding usages.
98
+ - **`smart_diff` affected symbols summary** — consolidated "AFFECTED SYMBOLS" section at the top of diff output, grouped by MODIFIED/ADDED/REMOVED. See all changed functions/classes at a glance.
99
+
100
+ ### Changed
101
+ - **19 tools** (was 18) — added `read_symbols`.
102
+ - **MCP instructions** — added batch read_symbols to decision rules and refactor workflow.
103
+ - **427 tests** (unchanged all pass with new features).
104
+
105
+ ## [0.15.0] - 2026-03-19
106
+
107
+ ### Added
108
+ - **Regex fallback parser (TS/JS)** — `smart_read` now works for TypeScript/JavaScript files even without ast-index binary. Parses classes, functions, interfaces, types, enums, and class methods via regex. Zero dependencies, 130 lines. Covers ~80% of new users who fail to download ast-index.
109
+ - **Regex fallback parser (Python)** — `smart_read` now works for Python files without ast-index. Parses classes, functions, async functions, decorators (`@dataclass`, `@app.route`), module constants (`UPPER_CASE`), methods with visibility detection (`_private`, `__dunder__`). 150 lines.
110
+ - **Benchmark script** — `scripts/benchmark.ts` measures real token savings on public repos (express, fastify, flask). 92% average savings across 97 files ≥50 lines. Run: `npx tsx scripts/benchmark.ts`.
111
+ - **Guide skill** `/guide` command shows a quick-reference table of all Token Pilot tools with usage examples and recommended workflow.
112
+ - **`hooks.denyThreshold` config** hook deny threshold is now configurable in `.token-pilot.json` (default: 300, was hardcoded 500). Intercepts ~2x more native Read calls.
113
+
114
+ ### Changed
115
+ - **Compact session analytics** `session_analytics` report reduced from ~30 lines to ~5 lines. Shows calls, tokens saved, top 5 tools, top 3 files, cache hit rate on a single screen. Verbose mode (`verbose=true`) restores full breakdown.
116
+ - **`server.ts` refactor** — extracted tool definitions to `server/tool-definitions.ts` and token estimate helpers to `server/token-estimates.ts` (−500 lines from server.ts).
117
+ - **`find_usages` output** results grouped by file with compact rendering. Single match per file on one line, multiple matches indented under file header.
118
+ - **Stale references** all `grep_search` hints updated to `Grep` (code-audit, find-unused, find-usages).
119
+ - **README** benchmark table with real data from 4 public repos. Updated savings claims from 80% to 90% (backed by benchmark).
120
+ - **427 tests** (was 393).
121
+
122
+ ### Fixed
123
+ - **`npx token-pilot` CLI** — symlink path resolution in `isDirectRun` check. All CLI commands now work correctly via npx.
124
+ - **Regex fallback was dead code** parsers existed but weren't wired into `client.ts` `outline()` method. Now properly called as fallback when ast-index unavailable.
125
+
126
+ ## [0.14.1] - 2026-03-14
127
+
128
+ ### Fixed
129
+ - **CI: Node.js 24 runtime** — opted into `FORCE_JAVASCRIPT_ACTIONS_TO_NODE24` for GitHub Actions, resolving deprecation warnings for `actions/checkout@v4` and `actions/setup-node@v4`.
130
+ - **CI: test matrix** — updated from Node 18+22 to Node 20+22 (Node 18 is EOL).
131
+ - **Test: git commit in CI** — `read-for-edit` tests now pass `-c user.name` / `-c user.email` to `git commit`, fixing failures in environments without global git config.
132
+
133
+ ## [0.14.0] - 2026-03-14
134
+
135
+ ### Added
136
+ - **R&D Track 0: Instrumentation** — per-call decision trace capturing file size, context state, estimated vs actual cost, and cheaper alternative suggestions. Integrated into all 18 tool handlers via `recordWithTrace()`.
137
+ - **R&D Track 1: Budget Planner** — advisory layer suggesting cheaper tool alternatives (e.g. `smart_read` → `read_diff` when file already in context, → `read_symbol` when symbol known). Analytics-only, no blocking.
138
+ - **R&D Track 2: Intent Router** — classifies tool calls into 7 intents (edit/debug/explore/review/analyze/search/read). Per-intent breakdown in session analytics.
139
+ - **R&D Track 3: Edit Prep Mode** `read_for_edit` with `include_callers`, `include_tests`, `include_changes` enrichment options.
140
+ - **R&D Track 4: Session Cache** tool-result-level caching with file/AST/git invalidation.
141
+ - **R&D Track 5: Confidence-Based Escalation** — confidence metadata (high/medium/low) appended to `smart_read`, `read_symbol`, `read_for_edit`, `find_usages` responses. Shows known unknowns and suggested next steps.
142
+ - **R&D Track 6: Working Set / Dedup** compact reminders for already-loaded files and symbols.
143
+ - **R&D Track 7: Related Files Ranking** — scored ranking with 6 signals (test +5, import +4, importer +3, same-dir +2, recently-changed +2, multi-ref +1). HIGH VALUE / MEDIUM / LOW buckets.
144
+ - **R&D Track 8: Architecture Fingerprint** — caches architecture in `.token-pilot-fingerprint.json` (24h TTL). Amortizes `project_overview` cost across sessions.
145
+ - **R&D Track 9: Verified Savings Dashboard** — savings breakdown by category (compression/cache/dedup), session cache hit rate, dedup stats.
146
+ - **R&D Track 10: Team Policy Mode** configurable policies: `preferCheapReads`, `maxFullFileReads`, `warnOnLargeReads`, `requireReadForEditBeforeEdit`.
147
+ - **7 new core modules** — `confidence.ts`, `intent-classifier.ts`, `budget-planner.ts`, `decision-trace.ts`, `session-cache.ts`, `architecture-fingerprint.ts`, `policy-engine.ts`.
148
+ - **35 new tests** — confidence (11), architecture-fingerprint (11), policy-engine (13). Total: 393 tests.
149
+
150
+ ### Changed
151
+ - **`session_analytics`** — per-intent breakdown, decision insights, savings by category.
152
+ - **`project_overview`** — saves/loads architecture fingerprint for cross-session caching.
153
+ - **Config** — added `policies` section to `TokenPilotConfig`.
154
+
155
+ ## [0.13.0] - 2026-03-14
156
+
157
+ ### Added
158
+ - **Version check for all components** — on startup, checks token-pilot (npm), ast-index (GitHub releases), and context-mode (npm) in parallel. Non-blocking, fire-and-forget. Shows update notifications in stderr.
159
+ - **`autoUpdate` config flag** — `updates.autoUpdate: true` in `.token-pilot.json` auto-downloads new ast-index binary on startup. Default: `false` (notify only). token-pilot and context-mode only notify (separate processes).
160
+ - **`checkBinaryUpdate()`**compares installed ast-index version vs latest GitHub release.
161
+ - **`isNewerVersion()` utility** — semver comparison: strip `v` prefix, compare segments. Handles different lengths (`1.0` vs `1.0.1`).
162
+ - **Common Lisp extensions** — `.lisp`, `.lsp`, `.cl`, `.asd` added to `CODE_EXTENSIONS` for ast-index v3.28+ compatibility.
163
+ - **9 new tests** — `isNewerVersion()` covering major/minor/patch, same version, older, `v` prefix, different segment lengths, large numbers, real-world versions. Total: 217 tests.
164
+
165
+ ### Changed
166
+ - **`doctor` command** — now shows 3 sections: token-pilot (installed/latest), ast-index (installed/latest/auto-update status), context-mode (detected/latest npm). Previously only showed ast-index binary status.
167
+ - **`install-ast-index` command** — now also updates existing binary if newer version available on GitHub.
168
+ - **`printHelp()`** fixed tool count: 18 (was incorrectly showing 12 since v0.8.0).
169
+ - **Startup update check** — replaced single `checkLatestVersion()` with `checkAllUpdates()` covering all 3 components via `Promise.allSettled`.
170
+
171
+ ### Fixed
172
+ - **`test_summary` PHPUnit parser** — now counts both `Failures:` and `Errors:` (was only counting failures).
173
+ - **`test_summary` cargo parser** correctly identifies failure name-list section (no `----` markers) vs detail section.
174
+ - **`test_summary` token estimation** — uses shared `estimateTokens()` instead of local duplicate.
175
+ - **`smart_log` category detection** — `documentation` now matches docs pattern, `tests` (plural) matches test pattern, `optimize`/`optimization` match perf pattern.
176
+ - **`explore_area` path boundary** — `startsWith(path + '/')` prevents `src/auth` matching `src/authorize/`.
177
+ - **Validation consistency** — `validateSmartLogArgs` and `validateTestSummaryArgs` now use `optionalString`/`optionalNumber` helpers, reject empty strings, check integers.
178
+
179
+ ## [0.11.0] - 2026-03-14
180
+
181
+ ### Added
182
+ - **`smart_log` tool** — structured git log with commit category detection (feat/fix/refactor/docs/test/chore/style/perf). Shows author breakdown, file stats (+/-), per-commit file list. Filters by path and ref. Raw git log → compact summary.
183
+ - **`test_summary` tool** runs test command and returns structured summary: total/passed/failed/skipped + failure details. Parsers for vitest, jest, pytest, phpunit, go test, cargo test, rspec, mocha + generic fallback. 200 lines of raw output → 10-15 lines.
184
+ - **38 new tests** — smart_log parser (5), categorizer (4), test_summary parsers (17), runner detection (8), validation (4). Total: 208 tests (was 170).
185
+
186
+ ### Changed
187
+ - **18 tools** (was 16) — added `smart_log`, `test_summary`
188
+ - **MCP instructions** — added smart_log and test_summary to workflow guidance
189
+
190
+ ## [0.10.0] - 2026-03-14
191
+
192
+ ### Added
193
+ - **`smart_diff` tool** — structural git diff with AST symbol mapping. Shows which functions/classes were modified/added/removed instead of raw patch output. Supports scopes: `unstaged`, `staged`, `commit` (ref required), `branch` (ref required). Small diffs (<=30 lines) include actual hunks, large diffs show summary. Returns `rawTokens` for precise savings analytics.
194
+ - **`explore_area` tool** — one-call directory exploration combining outline + imports + tests + git changes. Replaces 3-5 separate tool calls when starting work on an area. Sections: `outline` (recursive depth 2), `imports` (external deps + who imports this area), `tests` (matching test/spec files), `changes` (recent git log). All sections run in parallel via `Promise.allSettled`.
195
+ - **26 new tests** — smart_diff parser (10), symbol mapping (5), validation (11). Total: 170 tests (was 144).
196
+
197
+ ### Changed
198
+ - **16 tools** (was 14) added `smart_diff`, `explore_area`
199
+ - **MCP instructions** — updated workflow: `project_overview → explore_area → smart_read → read_symbol → read_for_edit → edit → smart_diff`
200
+ - **`outlineDir` and `CODE_EXTENSIONS` exported** from outline.ts for reuse by explore_area
201
+
202
+ ## [0.9.0] - 2026-03-08
203
+
204
+ ### Added
205
+ - **`module_info` tool** — analyze module dependencies, dependents, public API, and unused deps. Uses ast-index v3.27.0 module commands (`modules`, `module-deps`, `module-dependents`, `module-api`, `unused-deps`). Includes degradation check when ast-index is unavailable.
206
+ - **`project_overview` dual-detection** — shows BOTH ast-index type detection AND config-file detection (package.json, composer.json, Cargo.toml, pyproject.toml, go.mod) with CONFIDENCE scoring (high/medium/low/unknown). Detects frameworks, quality tools (PHPStan, ESLint, Vitest, Jest, Biome, etc.), CI pipelines (GitHub Actions, GitLab CI, Jenkins), and Docker.
207
+ - **`project_overview` `include` parameter** — filter sections: `["stack"]` for quick type check, `["quality","ci"]` for tooling overview. Default: all sections.
208
+ - **`find_usages` post-filters** — `scope` (path prefix), `kind` (definitions/imports/usages), `lang` (14 languages by extension), `limit` (per category, 1-500). All filters optional, backward compatible.
209
+ - **`outline` recursive mode** — `recursive=true` with `max_depth` (default 2, max 5) recurses into subdirectories. At max depth shows file counts only.
210
+ - **`src/core/project-detector.ts`** — extracted config-based detection logic into reusable module. Framework detection maps for PHP (7), JS (10), Python (5). Quality tools scanner (13 tools). CI pipeline detector (6 platforms).
211
+ - **ast-index client: 5 module methods** — `modules()`, `moduleDeps()`, `moduleDependents()`, `unusedDeps()`, `moduleApi()` with JSON-first + text fallback parsing.
212
+ - **ast-index types: 4 module interfaces** — `AstIndexModuleEntry`, `AstIndexModuleDep`, `AstIndexUnusedDep`, `AstIndexModuleApi`.
213
+
214
+ ### Fixed
215
+ - **`module_info` token savings** — `tokensWouldBe` was equal to `tokensReturned` (0% savings). Now estimates manual analysis cost correctly.
216
+ - **`outline` recursive overflow** — added `MAX_OUTLINE_LINES=500` guard to prevent runaway output on large projects with `recursive=true`.
217
+ - **`project_overview` "frontend" label** — removed hardcoded "frontend" suffix for secondary stacks (Node.js is not always frontend).
218
+ - **Ruff detection** no longer double-reads `pyproject.toml`. Checks `ruff.toml`/`.ruff.toml` first, falls back to `pyproject.toml [tool.ruff]` only if needed.
219
+ - **44 new tests** — validators (23) + project-detector (21). Total: 144 tests (was 100).
220
+
221
+ ### Changed
222
+ - **14 tools** (was 13) — added `module_info`
223
+ - **Tool descriptions** — updated with `(v1.1: ...)` version hints for enhanced tools
224
+ - **MCP instructions** — added module_info to "COMBINE BOTH" workflow section
225
+ - **Version sync** — package.json, plugin.json, marketplace.json all at 0.9.0
226
+
227
+ ## [0.8.3] - 2026-03-08
228
+
229
+ ### Fixed
230
+ - **code_audit pattern search — root cause fix** — `ast-index agrep` does not support `--limit` flag. Token Pilot was passing `--limit 50` which caused the command to fail silently, returning 0 results across v0.8.0–v0.8.2. Removed the flag; results are now limited via `.slice()` after parsing.
231
+
232
+ ## [0.8.2] - 2026-03-08
233
+
234
+ ### Fixed
235
+ - **code_audit pattern search** — inject `node_modules/.bin` into PATH so `ast-index agrep` can find `sg` (ast-grep) when it's installed as optional dependency but not in system PATH.
236
+ - **code_audit annotations** — strip `@` prefix from annotation names (`@Injectable` `Injectable`). ast-index expects names without `@`.
237
+
238
+ ## [0.8.1] - 2026-03-08
239
+
240
+ ### Added
241
+ - **ast-grep auto-install** — `@ast-grep/cli` added as optional dependency. `code_audit(check="pattern")` now works out-of-the-box without manual `brew install ast-grep`.
242
+ - **MCP instructions: security audit guidance** — instructions now recommend Grep for security patterns (password, token, secret, credential) and `find_unused` for dead code detection.
243
+
244
+ ### Changed
245
+ - **ast-index stats → JSON parsing** — `--format json` for reliable file count extraction instead of regex on text output.
246
+
247
+ ## [0.8.0] - 2026-03-07
248
+
249
+ ### Added
250
+ - **`code_audit` tool** — find code quality issues in one call: TODO/FIXME comments (`check="todo"`), deprecated symbols (`check="deprecated"`), structural code patterns via ast-grep (`check="pattern"`), decorator search (`check="annotations"`), or combined audit (`check="all"`).
251
+ - **Incremental index update on file changes** file watcher now triggers `ast-index update` (debounced 2s) after edits. Keeps index fresh for find_usages, find_unused, code_audit.
252
+ - **ast-index client methods** — `agrep()`, `todo()`, `deprecated()`, `annotations()`, `incrementalUpdate()`.
253
+
254
+ ### Fixed
255
+ - **smart_read on directories** — now returns helpful message instead of EISDIR crash.
256
+ - **MCP instructions** — added "COMBINE BOTH" section for audit tasks (Token Pilot + Grep).
257
+
258
+ ## [0.7.6] - 2026-03-07
259
+
260
+ ### Added
261
+ - **`npx token-pilot init`** — one command creates `.mcp.json` with both token-pilot and context-mode configured. Idempotent — safely updates existing configs without overwriting.
262
+ - **MCP Server Instructions** — protocol-level `instructions` field tells AI agents WHEN to use Token Pilot tools instead of built-in defaults. Works universally on all MCP clients.
263
+ - **Improved tool descriptions** — each tool explicitly states what built-in tool it replaces (e.g. "Use INSTEAD OF Read/cat").
264
+
265
+ ### Fixed
266
+ - **3 high severity vulnerabilities** — updated hono and express-rate-limit.
267
+ - **npm package size** — excluded source maps from package. 505 kB 286 kB (−43%).
268
+ - **Accurate thresholds** — README and instructions now correctly state smallFileThreshold=200 (was 80).
269
+ - **read_diff documentation** — clarified that smart_read must be called BEFORE editing to create baseline snapshot.
270
+
271
+ ### Changed
272
+ - **README** — honest metrics (60-80%), Quick Start with `init` command, MCP instructions section, Codex/Antigravity support.
273
+ - **npm keywords** — added `codex`, `cline`, `model-context-protocol`, `token-savings`.
274
+
275
+ ## [0.7.4] - 2026-03-07
276
+
277
+ ### Added
278
+ - **MCP Server Instructions** — protocol-level `instructions` field tells AI agents WHEN to use Token Pilot tools instead of built-in Read/cat/Grep. Works universally on Claude Code, Cursor, Codex, Antigravity, and any MCP-compatible client. Includes rules for when NOT to use Token Pilot (regex search, raw content copy-paste).
279
+ - **Improved tool descriptions** each tool now explicitly states what built-in tool it replaces (e.g. "Use INSTEAD OF Read/cat", "Use INSTEAD OF Grep/ripgrep"). Agents can make informed decisions from description alone, without needing project-level rules files.
280
+
281
+ ## [0.7.3] - 2026-03-07
282
+
283
+ ### Fixed
284
+ - **read_diff diagnostic** — when cache miss occurs, now shows resolved absolute path and all cached file paths. This reveals path mismatches between smart_read and read_diff calls (e.g. different relative paths resolving to different absolute paths).
285
+
286
+ ## [0.7.2] - 2026-03-07
287
+
288
+ ### Fixed
289
+ - **read_diff on small files** — `smart_read` small-file pass-through (≤150 lines) returned content without caching in fileCache. `read_diff` always showed "No previous read" for small files because the baseline was never stored. Now all files are cached regardless of size.
290
+
291
+ ## [0.7.1] - 2026-03-07
292
+
293
+ ### Fixed
294
+ - **read_diff after read_for_edit** — `read_for_edit` now caches the full file content, so `read_diff` can use it as baseline after edits. Previously returned "No previous read" because read_for_edit didn't populate the file cache.
295
+ - **outline on intermediate directories** — directories with only subdirectories (no direct code files) now show subdirectory listing with recursive code file counts instead of "No code files found". Enables progressive drill-down: `outline("module/") outline("module/infrastructure/")`.
296
+
297
+ ## [0.7.0] - 2026-03-07
298
+
299
+ ### Fixed
300
+ - **Project root detection** — complete rewrite of how token-pilot discovers the working project:
301
+ 1. **MCP roots** (new, primary) — uses MCP protocol `listRoots()` to get workspace root from Claude Code. Works for all tools including `find_usages`, `find_unused`, `project_overview` (no file path needed).
302
+ 2. **INIT_CWD/PWD env vars** (new) — when started via `npx`, npm sets `INIT_CWD` to the invoking directory. Catches cases where `process.cwd()` is `/` but the real project root is available in env.
303
+ 3. **Git detect from file path** (improved) — now triggers from any tool call args (`path`, `paths`, `file`, `module`), not just `smart_read`.
304
+ - **ast-index tools always disabled** — `find_usages`, `find_unused`, `project_overview` never triggered auto-detect because they have no `path` argument. Now all tools trigger detection via MCP roots.
305
+ - **Error messages** — changed "project root is too broad" to actionable "call smart_read() on any project file first" when MCP roots unavailable.
306
+ - **`isDangerousRoot`** — moved to shared `core/validation.ts` (was duplicated in `index.ts`).
307
+
308
+ ## [0.6.5] - 2026-03-07
309
+
310
+ ### Fixed
311
+ - **AST index rebuild race condition** — concurrent tool calls no longer trigger multiple simultaneous rebuilds. `ensureIndex()` now deduplicates via shared promise. If rebuild fails due to lock file (another process running), falls back to existing index if available instead of throwing.
312
+ - **Rebuild timeout** — increased from 60s to 120s for large projects where indexing takes longer.
313
+
314
+ ## [0.6.4] - 2026-03-07
315
+
316
+ ### Fixed
317
+ - **CRITICAL: Hook installer** — malformed `settings.json` no longer silently destroyed. Distinguishes ENOENT (create fresh) from JSON parse error (abort with message). Uninstall also reports specific errors.
318
+ - **CRITICAL: Server startup** — `startServer()` now has `.catch()` handler. Unhandled promise rejections no longer crash the process silently.
319
+ - **Non-code handler** — removed `.xml` and `.csv` from `isNonCodeStructured` (no handler existed for them, fell through to null).
320
+ - **Symbol resolver** — removed dangerous basename-only fallback in `pathMatches` (`index.ts` no longer matches any `index.ts`). Fixed hardcoded `endLine = start_line + 10` → uses `end_line` from ast-index or 50-line fallback.
321
+ - **Config loader** added prototype pollution guard (`__proto__`, `constructor`, `prototype` keys skipped in deepMerge). Parse errors now logged instead of silently swallowed.
322
+ - **File cache** — size tracking now uses `Buffer.byteLength()` instead of `string.length` (chars bytes for non-ASCII). Removed dead `isSmallFile()` method.
323
+ - **Validation** — `optionalNumber` now rejects `NaN` and `Infinity`.
324
+ - **Token estimation** — `smart_read_many` now uses `estimateTokens()` instead of `length/4`.
325
+ - **Analytics** `project_overview` calls now tracked in session analytics.
326
+ - **read_for_edit** — raised `MAX_EDIT_LINES` from 20 to 60 (20 was too aggressive, truncated most functions).
327
+ - **related_files** — raised symbol search limit from 5 to 10 for reverse import detection.
328
+
329
+ ### Removed
330
+ - Dead config options `cache.ttlMinutes` and `context.autoForgetMinutes` (declared but never used).
331
+
332
+ ## [0.6.3] - 2026-03-03
333
+
334
+ ### Changed
335
+ - **Hook deny threshold** — raised from 200 to 500 lines. Files ≤500 lines pass through Read without denial roundtrip. Eliminates token overhead on medium files where hook denial costs more than outline saves.
336
+ - **Adaptive fallback** — lowered from 90% to 70%. If outline ≥70% of raw file size, returns raw content. More aggressive at avoiding outlines that barely save tokens.
337
+ - **Tool descriptions** — trimmed marketing language, percentages, and cross-references. ~250 fewer tokens in tool list per session.
338
+ - **Outline cap** top-level symbols capped at 40, class members at 30. Prevents outline explosion on files with 100+ methods.
339
+
340
+ ## [0.6.2] - 2026-03-02
341
+
342
+ ### Removed
343
+ - **Dead handler files** — deleted `changed-symbols.ts` (removed in v0.5.0) and `find-callers.ts` (removed in v0.4.0). Were never registered in server but lingered as dead code.
344
+
345
+ ## [0.6.1] - 2026-03-02
346
+
347
+ ### Changed
348
+ - **`smallFileThreshold`**raised from 80 to 200 lines. Benchmark showed medium files (100-300 lines) had negative savings (-25%) because AST outline was larger than the raw file. Files ≤200 lines now pass through as raw content.
349
+ - **`smart_read` adaptive fallback** — after generating outline, compares token count vs raw file. If outline ≥ 90% of raw size, returns raw content instead. Eliminates negative savings on any file size, regardless of language or threshold.
350
+ - **`session_analytics` honest metrics** — replaced all hardcoded multipliers (`*5`, `*3`) with real full-file token counts from file cache. `tokensWouldBe` now reflects actual file size, not fabricated numbers. Non-file tools (related_files, outline, find_usages) report 1:1 (no savings claim).
351
+
352
+ ## [0.6.0] - 2026-03-02
353
+
354
+ ### Changed
355
+ - **Read hook** upgraded from advisory (`decision: "suggest"`) to blocking (`permissionDecision: "deny"`) for unbounded Read calls on large code files (>200 lines). Bounded Read (with offset/limit) is still allowed. Uses official `hookSpecificOutput` format per Claude Code docs.
356
+ - **`read_for_edit` output** — already includes exact `Read(path, offset, limit)` command that passes through the hook, giving AI a clear path: `read_for_edit` → bounded `Read` → `Edit`.
357
+
358
+ ### Added
359
+ - **Edit hook** — new PreToolUse hook matching Edit tool. Adds `additionalContext` suggesting `read_for_edit` for minimal code context. Doesn't block Edit — just provides a hint.
360
+ - **Hook installer** now installs and manages both Read and Edit hooks. Uninstall removes all Token Pilot hooks.
361
+
362
+ ## [0.5.3] - 2026-03-02
363
+
364
+ ### Changed
365
+ - **`find_unused`** — completely rewritten with universal approach. Removed 60+ hardcoded framework-specific names. Now uses ast-index data: constructors filtered by name (`constructor`/`__init__`), Python dunder methods by `__*__` pattern, decorated symbols detected via `outline()` and shown separately with their decorators. No framework-specific knowledge.
366
+ - **`formatFrameworkInfo`** (smart_read display) — removed hardcoded TypeORM (`Column`, `PrimaryGeneratedColumn`) and class-validator (`IsEmail`, `MinLength`) parsing. Now only detects standard HTTP verbs (GET/POST/PUT/DELETE/PATCH) which are protocol-level, not framework-specific. All other decorators shown as-is (`@DecoratorName`).
367
+ - **`outline`** — route detection now universal. Instead of hardcoding `@Controller`, detects any class decorator with a path argument as route prefix. HTTP verb detection uses same universal pattern. Non-HTTP decorators shown as-is.
368
+
369
+ ## [0.5.2] - 2026-03-02
370
+
371
+ ### Fixed
372
+ - **`project_overview`** — HINT no longer references deleted `search_code()`, now suggests `find_usages()` and `outline()`
373
+ - **`related_files` imported_by** — now searches both `imports` AND `usages` from refs (not just imports), with increased limit (30). Cross-language filtering preserves same-family matches while removing false positives.
374
+ - **`find_unused`** excludes framework-implicit symbols (replaced by universal approach in 0.5.3)
375
+ - **README** updated handler file list (removed deleted handlers, added new ones)
376
+
377
+ ## [0.5.1] - 2026-03-02
378
+
379
+ ### Fixed
380
+ - **`read_for_edit` symbol mode** — large symbols (>20 lines) now return only the first 20 lines instead of the entire method. Prevents returning 300+ lines when only a signature is needed for editing.
381
+ - **`related_files` imported_by** — filter cross-language false positives. A TypeScript file no longer shows Python/Go/Rust files as importers. Refs are filtered by language family (JS/TS, Python, Go, JVM, etc.).
382
+ - **`session_analytics`** honest savings metric for `read_for_edit`. Reduced multiplier from 30x to 3x (realistic comparison vs `Read` with offset/limit, not vs full file).
383
+
384
+ ## [0.5.0] - 2026-03-02
385
+
386
+ ### Added
387
+ - **`read_for_edit`** — killer feature for edit workflow. Returns RAW code (no line numbers) around a symbol or line, ready to copy as `old_string` for Edit. 97% fewer tokens than reading full file before editing.
388
+ - **`related_files`** — import graph for any file: what it imports, what imports it, test files. Saves 3-5 Read calls per task.
389
+ - **`outline`** — compact overview of all code files in a directory. One call instead of 5-6 smart_read calls. Framework-aware: shows HTTP routes for NestJS controllers.
390
+ - **`read_symbol` show parameter** — `show: "full"|"head"|"tail"|"outline"` controls truncation. Default: auto (full ≤300 lines, outline >300).
391
+ - **Framework-aware decorators** smart_read/outline parse NestJS (`@Controller`+`@Get` HTTP routes), TypeORM (`@Column` → types), class-validator (`@IsEmail` → constraints).
392
+
393
+ ### Removed
394
+ - **`search_code`** — worse than Grep in practice, find_usages + Grep cover all use cases
395
+ - **`export_ast_index`** — never used in real work, infrastructure tool only
396
+ - **`context_status`**debugging tool, not user-facing
397
+ - **`forget`**manual context management = poor design, should be automatic
398
+ - **`changed_symbols`**git diff + smart_read covers this use case
399
+
400
+ ### Changed
401
+ - **12 focused tools** instead of 14 — removed 5 low-value, added 3 high-impact
402
+ - Edit-heavy sessions: 5-10% 40-50% token savings (via read_for_edit)
403
+ - Average sessions: 20-25% 45-55% token savings
404
+
405
+ ## [0.4.1] - 2026-03-02
406
+
407
+ ### Added
408
+ - **Auto-install PreToolUse hook**: hook installs automatically on server start (Claude Code), no manual `install-hook` needed
409
+ - **AI instructions template**: README includes ready-to-copy block for `.cursorrules` / `CLAUDE.md`
410
+
411
+ ### Changed
412
+ - **Tool descriptions rewritten** — explicit "ALWAYS use instead of Read/cat", "use instead of Grep" for AI prioritization
413
+ - README updated: PreToolUse hook section, MCP Tools table with "Instead of" column
414
+
415
+ ## [0.4.0] - 2026-03-02
416
+
417
+ ### Added
418
+ - **Python class method parser**: smart_read/read_symbol shows all methods inside Python classes with visibility, decorators, async detection
419
+ - **PHP class method parser**: same for PHP classes with public/private/protected, static
420
+ - **Version display**: `project_overview` and `session_analytics` show `TOKEN PILOT v{version}`
421
+
422
+ ### Changed
423
+ - **Removed find_callers** — did not save tokens vs grep, ast-index limitation with `this.method()` calls
424
+ - **Removed find_implementations** — did not save tokens vs grep, ast-index limitation with decorators
425
+ - **Removed class_hierarchy** — did not save tokens vs grep, poor results from ast-index
426
+ - **14 focused tools** instead of 17 only tools that actually save tokens or provide unique value
427
+
428
+ ### Fixed
429
+ - **Mega-symbol truncation**: symbols >300 lines show head (50) + tail (30) + method outline instead of 71KB overflow
430
+ - **Recursive findFlat**: unqualified method names (`run`, `_build_summary`) found inside class children
431
+
432
+ ## [0.3.2] - 2026-03-01
433
+
434
+ ### Fixed
435
+ - **Python class methods**: smart_read now shows all methods inside Python classes (ast-index only returns class-level, token-pilot parses `def` methods with visibility, decorators, async detection)
436
+ - **read_symbol Python**: `Orchestrator.run`, `Orchestrator._build_summary` qualified and unqualified method access works (was returning entire 829-line class)
437
+ - **Mega-symbol truncation**: symbols >300 lines show head (50) + tail (30) + method outline instead of 71KB overflow
438
+ - **findFlat recursive**: unqualified method names (`run`, `_build_summary`) now found inside class children
439
+
440
+ ## [0.3.1] - 2026-03-01
441
+
442
+ ### Fixed
443
+ - **find_usages**: combine `refs` + `search` with exact word boundary filtering — 0% result loss vs grep (was 40% loss with refs-only)
444
+ - **read_symbol**: fix `Class.method` qualified names for flat outlines (ast-index lists methods as siblings, not children)
445
+ - **read_symbol**: filter ast-index leaf name fallback by requested file (was returning symbols from wrong files)
446
+ - **YAML smart_read**: 3-level nested parser with scalar values, array counts (was only showing top-level keys)
447
+ - Removed all "Use Grep as fallback" hints token-pilot gives complete results on its own
448
+
449
+ ## [0.3.0] - 2026-03-01
450
+
451
+ ### Added
452
+ - **find_callers** tool — find all callers of a function, with optional call hierarchy tree (depth parameter)
453
+ - **changed_symbols** tool — show symbol-level git changes (added/modified/removed) vs a base branch
454
+ - **find_unused** tool — detect potentially unused/dead symbols in the project
455
+ - 8 new ast-index client methods: `refs`, `map`, `conventions`, `callers`, `callTree`, `changed`, `unusedSymbols`, `fileImports`
456
+ - Incremental index updates via `ast-index update` (fast) instead of full rebuild
457
+
458
+ ### Fixed
459
+ - **find_usages**: rewritten to use `ast-index refs` returns definitions + imports + usages in one call (was losing ~66% of results)
460
+ - **project_overview**: rewritten to use `ast-index map` + `conventions` — shows architecture, frameworks, naming patterns, directory map with symbol kinds
461
+ - **search_code**: deduplication of results (removes duplicate file:line entries)
462
+ - **read_symbol**: structure-first lookup for `Class.method` qualified names with ast-index leaf fallback
463
+ - **export_ast_index**: `all_indexed=true` option exports all files from ast-index, not just cached ones
464
+ - **YAML smart_read**: expand one level of nesting (shows nested keys under top-level sections)
465
+
466
+ ### Changed
467
+ - Total MCP tools: 14 17
468
+ - ast-index commands used: 8 → 16
469
+ - Index updates are now incremental by default (falls back to full rebuild only when needed)
470
+
471
+ ## [0.2.4] - 2026-03-01
472
+
473
+ ### Fixed
474
+ - **search_code**: filter out garbage entries with empty file paths or `:undefined` lines
475
+ - **read_symbol**: support `Class.method` and `Class::method` qualified names (structure-first lookup, ast-index leaf fallback)
476
+ - **export_ast_index**: `all_indexed=true` option exports all files from ast-index, not just cached ones
477
+ - **YAML smart_read**: expand one level of nesting (shows service names, nested keys under top-level sections)
478
+ - Improved empty-cache message in export_ast_index with hint about `all_indexed`
479
+
480
+ ## [0.2.3] - 2026-03-01
481
+
482
+ ### Fixed
483
+ - **ensureIndex**: plain rebuild first (indexes full monorepo), fallback to `--sub-projects` only if <5 files
484
+ - **smart_read**: non-code files (YAML, JSON, Markdown, TOML) use structural summary instead of raw content dump
485
+ - **smart_read**: unsupported files return truncated 60-line preview instead of full raw content
486
+ - **class_hierarchy**: proper parser for ast-index text output (Parents/Children sections)
487
+ - **project_overview**: uses directory name when package.json has no `name` field
488
+
489
+ ## [0.2.2] - 2026-03-01
490
+
491
+ ### Fixed
492
+ - Published 0.2.1 contained stale Haiku files in dist/ (tsc doesn't clean old outputs)
493
+ - Added `prebuild` script (`rm -rf dist`) to prevent stale artifacts
494
+ - Added `chmod +x` in prepublishOnly to ensure bin is executable
495
+
496
+ ## [0.2.1] - 2026-03-01
497
+
498
+ ### Fixed
499
+ - **RC3**: `search_code` now merges all ast-index result types (content_matches + symbols + files + references) — previously only used content_matches which was often empty
500
+ - **RC4**: `class_hierarchy` and `implementations` parse text format as fallback when JSON parse fails
501
+ - **RC6**: `read_symbol` auto-fetches outline from ast-index if no cached structure — no longer requires prior smart_read
502
+ - `ensureIndex` uses `--sub-projects` flag for monorepo indexing
503
+
504
+ ### Removed
505
+ - Reverted Haiku v0.2.1 — removed broken PersistentFileCache, DiffEngine, RealTokenEstimator, ContextWindowTracker, smart-read-xml, context-markup
506
+ - Removed 3 heavy native dependencies: `better-sqlite3`, `js-tiktoken`, `diff`
507
+
508
+ ### Added
509
+ - `start.sh` bootstrap script for Claude Code plugin system
510
+
511
+ ## [0.2.0] - 2026-03-01
512
+
513
+ ### Fixed
514
+ - **P0**: ast-index errors no longer silently swallowed — all search/usages/implementations/hierarchy/outline/symbol log errors to stderr
515
+ - **P0**: `exec()` now captures and logs ast-index subprocess stderr
516
+ - **P0**: `projectRoot` detected via `git rev-parse --show-toplevel` instead of `process.cwd()` (fixes wrong index root)
517
+ - **P1**: `forget(all=true)` now clears both ContextRegistry and FileCache (fixes stale export_ast_index/read_diff after forget)
518
+ - **P1**: `forget(path=X)` also invalidates FileCache for that path
519
+ - **P2**: `read_symbol` supports PHP `::` separator (e.g. `RefundProcessor::refund`)
520
+ - **P2**: `findInStructure` recursion fixed — supports 3+ level nesting (Namespace::Class::method)
521
+ - `ensureIndex()`: verify index has content after `stats` — force rebuild if 0 files indexed
522
+
523
+ ### Changed
524
+ - `project_overview`: now shows directory listing + ast-index stats (files, symbols, references) instead of stub
525
+ - `project_overview`: added PHP (`composer.json`) detection
526
+
527
+ ## [0.1.6] - 2026-03-01 (unpublished)
528
+
529
+ ### Fixed
530
+ - `ensureIndex()`: verify index has content after `stats` force rebuild if 0 files indexed (fixes empty search results on first run)
531
+
532
+ ## [0.1.5] - 2026-03-01
533
+
534
+ ### Fixed
535
+ - PreToolUse hook: read file path from stdin (Claude Code hook format) instead of `$FILE_PATH` env var
536
+ - Hook now auto-suggests `smart_read` for large code files when Claude tries to use `Read`
537
+ - `session_analytics`: now tracks all tools (read_symbol, read_range, read_diff, smart_read_many, search_code, find_usages, find_implementations, class_hierarchy) — previously only tracked smart_read
538
+ - Empty search/usages/implementations results now show diagnostic hints (ast-index status, fallback suggestions)
539
+ - `ensureIndex()` now logs build progress and errors to stderr
540
+
541
+ ## [0.1.4] - 2026-03-01
542
+
543
+ ### Fixed
544
+ - Lazy file watcher: watch only loaded files instead of entire project root (fixes crash on Docker volumes, home dir, WSL)
545
+
546
+ ## [0.1.3] - 2026-03-01
547
+
548
+ ### Fixed
549
+ - Chokidar file watcher error handler (partial fix, superseded by 0.1.4)
550
+
551
+ ## [0.1.2] - 2026-03-01
552
+
553
+ ### Fixed
554
+ - ast-index integration: `outline` now parses text output (JSON format not supported in v3.24.0)
555
+ - ast-index `symbol` response: handle array format, normalize field names (`line`→`start_line`, `path`→`file`)
556
+ - ast-index `search` response: handle `{content_matches: [...]}` wrapper
557
+ - ast-index `usages` response: map `context`→`text`, `path`→`file`
558
+ - Server version now read dynamically from package.json
559
+
560
+ ### Added
561
+ - `token-pilot doctor` diagnostics command (checks ast-index, Node.js, config, updates)
562
+ - `token-pilot --version` print current version
563
+ - Update check on server startup (non-blocking, logs to stderr)
564
+ - `/mcp add` installation method documented for Claude Code chat
565
+ - Troubleshooting section in README
566
+
567
+ ## [0.1.1] - 2026-03-01
568
+
569
+ ### Added
570
+ - `npx -y token-pilot` — zero-install for any MCP client (Cursor, Cline, Continue, etc.)
571
+ - Claude Code plugin marketplace support (`.claude-plugin/marketplace.json`)
572
+ - `start.sh` bootstrap script auto `npm install` + `npm run build` on first run
573
+ - `npm publish` ready (`files` field, `prepublishOnly` script)
574
+ - Universal install instructions in README for Claude Code, Cursor, Cline
575
+
576
+ ### Changed
577
+ - `.mcp.json` now uses `start.sh` for reliable bootstrap
578
+ - README reorganized: npx as primary install, from-source as fallback
579
+
580
+ ## [0.1.0] - 2026-03-01
581
+
582
+ ### Added
583
+
584
+ - **Core Reading Tools**: `smart_read`, `read_symbol`, `read_range`, `read_diff`, `smart_read_many`
585
+ - AST-based structural overviews saving 80-95% tokens
586
+ - Small file pass-through (< 80 lines returned in full)
587
+ - O(n) diff algorithm for re-reads
588
+ - Advisory context registry with compact reminders
589
+ - **Search & Navigation**: `search_code`, `find_usages`, `find_implementations`, `class_hierarchy`, `project_overview`
590
+ - Powered by ast-index (tree-sitter + SQLite FTS5)
591
+ - Cross-file symbol resolution
592
+ - **Context Management**: `session_analytics`, `context_status`, `forget`
593
+ - Token savings tracking per tool and per file
594
+ - Advisory (non-blocking) context tracking
595
+ - **Integration**: `export_ast_index`
596
+ - context-mode detection and complementary architecture
597
+ - AST data export for BM25 cross-indexing
598
+ - **Infrastructure**
599
+ - Git HEAD watcher with selective cache invalidation on branch switch
600
+ - File watcher (chokidar) for automatic cache invalidation
601
+ - LRU file cache with configurable size limit
602
+ - Input validation for all tools (path traversal protection)
603
+ - Auto-download of ast-index binary from GitHub releases
604
+ - PreToolUse hook installer for Claude Code
605
+ - Claude Code plugin format (.claude-plugin/)
606
+ - Non-code structural summaries (JSON, YAML, Markdown, TOML)
607
+ - Configurable via `.token-pilot.json`