@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 +52 -14
- package/dist/chunk-FYCLLG7F.js +847 -0
- package/dist/chunk-FYCLLG7F.js.map +1 -0
- package/dist/{chunk-KN4YKUZM.js → chunk-RI64PBQ5.js} +17 -7
- package/dist/chunk-RI64PBQ5.js.map +1 -0
- package/dist/chunk-RLHEIKPR.js +894 -0
- package/dist/chunk-RLHEIKPR.js.map +1 -0
- package/dist/cli-DzY7l7Rr.d.cts +182 -0
- package/dist/cli-DzY7l7Rr.d.ts +182 -0
- package/dist/cli.cjs +391 -119
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +2 -1
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +2 -2
- package/dist/index.cjs +1189 -152
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +160 -20
- package/dist/index.d.ts +160 -20
- package/dist/index.js +37 -3
- package/dist/index.js.map +1 -1
- package/dist/mcp.cjs +1126 -136
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.d.cts +21 -6
- package/dist/mcp.d.ts +21 -6
- package/dist/mcp.js +6 -2
- package/hooks/claude/README.md +29 -0
- package/hooks/claude/git-impact.mjs +47 -0
- package/hooks/claude/settings.example.json +24 -0
- package/package.json +2 -1
- package/dist/chunk-HBYIAFR4.js +0 -204
- package/dist/chunk-HBYIAFR4.js.map +0 -1
- package/dist/chunk-HRF3BIOV.js +0 -518
- package/dist/chunk-HRF3BIOV.js.map +0 -1
- package/dist/chunk-KN4YKUZM.js.map +0 -1
- package/dist/cli-EpVqinpB.d.cts +0 -96
- package/dist/cli-EpVqinpB.d.ts +0 -96
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
|
-
**
|
|
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
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
|
|
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
|
-
|
|
|
224
|
-
|
|
|
225
|
-
| `/
|
|
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 '{"
|
|
273
|
+
-d '{"activeFiles":["./src/page.ts","./src/api.ts"],"includeStats":true}'
|
|
236
274
|
```
|
|
237
275
|
|
|
238
276
|
|