@ajdev0/token-shrink 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -131,6 +131,16 @@ ROOT=/path/to/project token-shrink-mcp
131
131
  cd /path/to/project && token-shrink-mcp
132
132
  ```
133
133
 
134
+ > **Zero-config auto-detect**: `--root` is optional. When neither `--root` nor
135
+ > `ROOT` is set, the server finds the project itself — it walks up for VCS
136
+ > directories (`.git`/`.hg`/`.svn`) or project manifests (`package.json`,
137
+ > `pyproject.toml`, `go.mod`, `Cargo.toml`, …), first around the directory the
138
+ > client launched it from, and otherwise lazily from the `activeFilePath` of the
139
+ > first `get_compressed_code_context` call (re-pointing if a later call opens a
140
+ > different project). The config examples below keep `--root` so the behavior is
141
+ > pinned and the index is already warm before the first request — but you may
142
+ > simply drop the `--root` argument entirely.
143
+
134
144
  **Cursor MCP config** (`.cursor/mcp.json`):
135
145
 
136
146
  ```json
@@ -200,30 +210,58 @@ token-shrink-mcp --root /path/to/project --no-create-rule
200
210
 
201
211
  Opt out also via `--create-rule=false` or `TOKEN_SHRINK_CREATE_RULE=0`.
202
212
 
203
- **Tool:** `get_compressed_code_context`
213
+ **MCP tools**
214
+
215
+ `get_compressed_code_context` — compressed context for one or more active files (Ring 0 full, Ring 1 pruned):
216
+
217
+ | Argument | Type | Required | Description |
218
+ | ---------------- | ---------- | -------- | -------------------------------------------------- |
219
+ | `activeFilePath` | `string` | no* | Single file the agent is working on |
220
+ | `activeFiles` | `string[]` | no* | Multiple Ring-0 files (combined Ring 1) |
221
+ | `maxSkeletons` | `number` | no | Cap on Ring-1 files (default `50`, max `200`) |
222
+ | `maxTokens` | `number` | no | Hard token budget; Ring 1 is relevance-packed to fit |
223
+ | `includeStats` | `boolean` | no | Append approximate token counts |
224
+
225
+ \* Provide exactly one of `activeFilePath` / `activeFiles`. Ring 0 stays full; Ring 1 is the union of each file's local imports, minus files already in Ring 0.
204
226
 
227
+ `expand_symbol({ filePath, symbolName, maxMatches? })` — when a skeleton isn't enough, returns the **full, un-pruned definition** (function/class/method/… bodies included) for the named symbol in that file. Overloads and same-named members are all returned.
205
228
 
206
- | Argument | Type | Required | Description |
207
- | ---------------- | --------- | -------- | --------------------------------------------- |
208
- | `activeFilePath` | `string` | yes | The file the agent is working on |
209
- | `maxSkeletons` | `number` | no | Cap on Ring-1 files (default `50`, max `200`) |
210
- | `includeStats` | `boolean` | no | Append approximate token counts |
229
+ `git_diff_context({ scope?, base?, head?, includeUntracked?, maxFiles?, maxImporters?, maxSkeletons?, maxTokens? })` — impact analysis for changed code:
230
+ - `scope`: `worktree` (default) · `staged` · `branch` (`base...head`, defaults `HEAD~1...HEAD`)
231
+ - changed files are emitted in full as Ring 0; their imports **and** the files that import them (file-level callers) are attached as pruned skeletons. Great for PR reviews and multi-file regressions where there is no single active file.
211
232
 
233
+ `search_symbol_signatures({ query, maxResults?, kind? })` — repo-wide lookup of definitions backed by an in-memory index of the tree-sitter symbol pass. Returns compact `` `file:line — signature` `` lines (not raw file dumps), ranked exact → prefix → substring.
212
234
 
213
- Returns a Markdown payload with the active file fully inlined (Ring 0) and the pruned skeletons of its direct imports (Ring 1).
235
+ **Project config (`.tokenshrinkrc.json`)** at the repository root hot-reloaded:
236
+
237
+ ```json
238
+ {
239
+ "ignorePatterns": ["**/dist/**", "**/generated/**"],
240
+ "keepUnpruned": ["src/types/global.d.ts", "lib/models/*.dart"],
241
+ "preserveAnnotations": ["@keepContext", "@api"]
242
+ }
243
+ ```
244
+
245
+ - `ignorePatterns` — globs that are never indexed or watched.
246
+ - `keepUnpruned` — files that are indexed but never pruned (always full text).
247
+ - `preserveAnnotations` — definitions (and everything nested in them) preceded by `@marker` are kept fully un-pruned.
248
+ - `autoWorkflow` — `true` (default) writes **auto-workflow rules** that make the agent run the right tool automatically on each task: context for the active file → symbol search for identifiers it doesn't already know → expand pruned bodies it must modify → git impact for dirty/multi-file work. Set to `false` for lightweight rules where the model decides on its own.
249
+
250
+ Invalid JSON logs a warning and falls back to defaults; editing the file while the server runs re-indexes automatically.
251
+
252
+ **Automatic workflows & event hooks:** the generated rules (Cursor / Claude Code / Cline) choreograph the tools per task, and existing installs **self-upgrade to the newest rule text on the next server start** via the rule version marker. Claude Code additionally supports real event automation — see [`hooks/claude/README.md`](hooks/claude/README.md) for sample `SessionStart`/`Stop` hooks that auto-inject a compact git-impact summary into every session.
214
253
 
215
254
  ### 2. HTTP server (Fastify)
216
255
 
217
256
  ```bash
218
- token-shrink --root /path/to/project --port 3000
257
+ token-shrink --root /path/to/project --port 3000 --max-tokens 4000
219
258
  # env equivalents: ROOT=… PORT=… HOST=…
220
259
  ```
221
260
 
222
-
223
- | Route | Method | Body | Returns |
224
- | ------------- | ------ | -------------------------------------------------- | -------------------------------- |
225
- | `/health` | `GET` | | status, root, indexed file count |
226
- | `/v1/context` | `POST` | `{ activeFilePath, maxSkeletons?, includeStats? }` | assembled Markdown + deps |
261
+ | Route | Method | Body | Returns |
262
+ | ------------- | ------ | ------------------------------------------------------ | -------------------------------- |
263
+ | `/health` | `GET` | | status, root, indexed file count |
264
+ | `/v1/context` | `POST` | `{ activeFilePath? \| activeFiles?, maxSkeletons?, maxTokens?, includeStats? }` | assembled Markdown + deps + stats |
227
265
 
228
266
 
229
267
  ```bash
@@ -232,7 +270,7 @@ curl -s http://localhost:3000/health
232
270
 
233
271
  curl -s -X POST http://localhost:3000/v1/context \
234
272
  -H 'Content-Type: application/json' \
235
- -d '{"activeFilePath":"./src/page.ts","includeStats":true}'
273
+ -d '{"activeFiles":["./src/page.ts","./src/api.ts"],"includeStats":true}'
236
274
  ```
237
275
 
238
276