@raymondchins/agentmap 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +24 -0
- package/README.md +75 -47
- package/agentmap.mjs +894 -0
- package/hooks/INSTALL.md +211 -0
- package/hooks/agentmap-nudge.mjs +90 -0
- package/hooks/post-commit +61 -0
- package/mcp.mjs +206 -0
- package/package.json +11 -6
- package/repomap.mjs +0 -461
package/NOTICE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
agentmap — Credits & attribution
|
|
2
|
+
================================
|
|
3
|
+
|
|
4
|
+
agentmap is copyright 2026 Raymond Surya Chin and contributors,
|
|
5
|
+
licensed under the MIT License (see LICENSE).
|
|
6
|
+
|
|
7
|
+
-------------------------------------------------------------------------------
|
|
8
|
+
Algorithm credit
|
|
9
|
+
-------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
agentmap's repo-map ranking — personalized PageRank importance scoring and the
|
|
12
|
+
identifier-graph symbol ranking — is an independent reimplementation, in
|
|
13
|
+
JavaScript, of the approach introduced by Aider's repo map
|
|
14
|
+
(https://github.com/Aider-AI/aider) by Paul Gauthier and contributors.
|
|
15
|
+
|
|
16
|
+
No Aider source code is copied or included here: PageRank is a public, textbook
|
|
17
|
+
algorithm, agentmap implements it from scratch (a dependency-free power
|
|
18
|
+
iteration in agentmap.mjs), and Aider itself relies on the networkx library
|
|
19
|
+
rather than hand-written ranking code. This NOTICE is a courtesy credit to the
|
|
20
|
+
project that pioneered applying that ranking approach to a coding-agent repo
|
|
21
|
+
map — not a statement of derivative authorship.
|
|
22
|
+
|
|
23
|
+
Aider is licensed under the Apache License, Version 2.0
|
|
24
|
+
(http://www.apache.org/licenses/LICENSE-2.0).
|
package/README.md
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="assets/hero.png" alt="agentmap — ~98% token savings to understand a codebase (up to 99.9% per task)" width="100%">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
# agentmap
|
|
2
6
|
|
|
3
|
-
**The repo map your coding agent is _forced_ to use.**
|
|
7
|
+
**The repo map your coding agent is _forced_ to use — ~98% fewer tokens to understand your TS/JS codebase.**
|
|
4
8
|
|
|
5
|
-
A queryable, ranked code-relationship map for TypeScript/JavaScript repos
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
A queryable, ranked code-relationship map for TypeScript/JavaScript repos that answers
|
|
10
|
+
"understand the codebase" questions in **~98% fewer tokens on average** (up to **99.9%
|
|
11
|
+
per task**) vs reading raw files. Personalized PageRank importance, Aider-style symbol
|
|
12
|
+
ranking, a token-budgeted digest, and a single `--any` router (file → symbol → feature →
|
|
13
|
+
live git-grep) — wired straight into the agent loop so it actually gets used, not just
|
|
14
|
+
published.
|
|
9
15
|
|
|
10
|
-
<!-- badges (placeholder — wire up once published) -->
|
|
11
16
|
[](https://www.npmjs.com/package/@raymondchins/agentmap)
|
|
12
|
-
[](https://github.com/raymondchins/agentmap/actions/workflows/ci.yml)
|
|
13
18
|
[](./LICENSE)
|
|
14
19
|
[](#)
|
|
15
20
|
|
|
16
|
-
> One file, one dependency (`ts-morph
|
|
21
|
+
> One file, one runtime dependency (`ts-morph`, which bundles the TypeScript compiler — ~10 MB installed). No vector DB, no embedding API, no server.
|
|
17
22
|
> `npx @raymondchins/agentmap --any <query>` and you have a ranked answer.
|
|
18
23
|
|
|
19
24
|
---
|
|
@@ -53,10 +58,10 @@ npx @raymondchins/agentmap --any <query>
|
|
|
53
58
|
…or run it directly from a checkout:
|
|
54
59
|
|
|
55
60
|
```bash
|
|
56
|
-
node
|
|
61
|
+
node agentmap.mjs --any <query>
|
|
57
62
|
```
|
|
58
63
|
|
|
59
|
-
The first run builds and caches the map to `.claude/
|
|
64
|
+
The first run builds and caches the map to `.claude/agentmap.json` (add it to
|
|
60
65
|
`.gitignore`). Subsequent runs serve the cache when the tree is clean and `HEAD` is
|
|
61
66
|
unchanged, and silently rebuild from disk when there are uncommitted `.ts/.tsx/.js/...`
|
|
62
67
|
edits — so queries always reflect your in-flight work.
|
|
@@ -64,8 +69,8 @@ edits — so queries always reflect your in-flight work.
|
|
|
64
69
|
Run with no flag to build + print a one-line summary:
|
|
65
70
|
|
|
66
71
|
```
|
|
67
|
-
$ node
|
|
68
|
-
|
|
72
|
+
$ node agentmap.mjs
|
|
73
|
+
agentmap: 154 files | 4 features | top hub: lib/utils.ts (deg 52, pr 0.105171)
|
|
69
74
|
```
|
|
70
75
|
|
|
71
76
|
---
|
|
@@ -91,7 +96,7 @@ graph never indexes still resolve instead of coming up empty.
|
|
|
91
96
|
**Symbol hit** (query resolved to a symbol → full block):
|
|
92
97
|
|
|
93
98
|
```
|
|
94
|
-
$ node
|
|
99
|
+
$ node agentmap.mjs --any cn
|
|
95
100
|
[structure] 1 symbol, 0 feature match for "cn"
|
|
96
101
|
lib/utils.ts → cn (FunctionDeclaration)
|
|
97
102
|
```
|
|
@@ -99,7 +104,7 @@ $ node repomap.mjs --any cn
|
|
|
99
104
|
**Ambiguous file hit** (query matched multiple files → narrow it):
|
|
100
105
|
|
|
101
106
|
```
|
|
102
|
-
$ node
|
|
107
|
+
$ node agentmap.mjs --any utils
|
|
103
108
|
[structure] "utils" matched 3 files — narrow it:
|
|
104
109
|
lib/utils.ts
|
|
105
110
|
lib/db/utils.ts
|
|
@@ -109,7 +114,7 @@ $ node repomap.mjs --any utils
|
|
|
109
114
|
**Content fallback** (no file/symbol/feature match → live git-grep):
|
|
110
115
|
|
|
111
116
|
```
|
|
112
|
-
$ node
|
|
117
|
+
$ node agentmap.mjs --any streamText
|
|
113
118
|
[content] 13 lines:
|
|
114
119
|
app/(chat)/api/chat/route.ts:8: streamText,
|
|
115
120
|
app/(chat)/api/chat/route.ts:194: const result = streamText({
|
|
@@ -124,7 +129,7 @@ artifacts/sheet/server.ts:11: const { fullStream } = streamText({
|
|
|
124
129
|
|
|
125
130
|
## Commands
|
|
126
131
|
|
|
127
|
-
Every snippet below is **
|
|
132
|
+
Every snippet below is **representative output** (long lists trimmed) from running agentmap against the public
|
|
128
133
|
154-file Next.js repo [vercel/ai-chatbot](https://github.com/vercel/ai-chatbot) (sha 2becdb4).
|
|
129
134
|
|
|
130
135
|
### `--any <q>` — the router (file → symbol → feature → live content)
|
|
@@ -138,7 +143,7 @@ Find every exported symbol whose name contains the query. Use it before writing
|
|
|
138
143
|
or component to check what already exists.
|
|
139
144
|
|
|
140
145
|
```
|
|
141
|
-
$ node
|
|
146
|
+
$ node agentmap.mjs --find Message
|
|
142
147
|
find "Message": 55 match
|
|
143
148
|
hooks/use-messages.tsx → useMessages (FunctionDeclaration)
|
|
144
149
|
lib/errors.ts → getMessageByErrorCode (FunctionDeclaration)
|
|
@@ -159,7 +164,7 @@ relevance list (personalized PageRank on the bidirectional import graph) — the
|
|
|
159
164
|
related to the target, transitively, not just its direct importers.
|
|
160
165
|
|
|
161
166
|
```
|
|
162
|
-
$ node
|
|
167
|
+
$ node agentmap.mjs --relates lib/db/schema.ts
|
|
163
168
|
relates: lib/db/schema.ts (pr 0.073744)
|
|
164
169
|
exports (14): user(VariableDeclaration), User(TypeAliasDeclaration), chat(VariableDeclaration), Chat(TypeAliasDeclaration), message(VariableDeclaration), DBMessage(TypeAliasDeclaration), …
|
|
165
170
|
imports (0): —
|
|
@@ -181,7 +186,7 @@ Resolves a Next.js `app/`-router feature to its file set, plus the external file
|
|
|
181
186
|
depend on it.
|
|
182
187
|
|
|
183
188
|
```
|
|
184
|
-
$ node
|
|
189
|
+
$ node agentmap.mjs --feature api
|
|
185
190
|
feature "api": 11 files
|
|
186
191
|
app/(chat)/api/chat/route.ts
|
|
187
192
|
app/(chat)/api/chat/schema.ts
|
|
@@ -200,7 +205,7 @@ external dependents (0): —
|
|
|
200
205
|
### `--features` — list features by size
|
|
201
206
|
|
|
202
207
|
```
|
|
203
|
-
$ node
|
|
208
|
+
$ node agentmap.mjs --features
|
|
204
209
|
features (4):
|
|
205
210
|
api (11 files)
|
|
206
211
|
login (1 files)
|
|
@@ -214,8 +219,8 @@ The files that matter most, ranked by PageRank importance (raw dependent degree
|
|
|
214
219
|
alongside).
|
|
215
220
|
|
|
216
221
|
```
|
|
217
|
-
$ node
|
|
218
|
-
|
|
222
|
+
$ node agentmap.mjs --hubs
|
|
223
|
+
agentmap: 154 files (sha 2becdb4)
|
|
219
224
|
hubs (PageRank importance):
|
|
220
225
|
lib/utils.ts (deg 52, pr 0.105171)
|
|
221
226
|
lib/db/schema.ts (deg 21, pr 0.073744)
|
|
@@ -233,7 +238,7 @@ The most important individual symbols across the repo, ranked by the identifier
|
|
|
233
238
|
(defaults to 30).
|
|
234
239
|
|
|
235
240
|
```
|
|
236
|
-
$ node
|
|
241
|
+
$ node agentmap.mjs --symbols 10
|
|
237
242
|
top 10 ranked symbols (Aider-style):
|
|
238
243
|
0.109902 lib/utils.ts → cn (FunctionDeclaration)
|
|
239
244
|
0.036013 lib/types.ts → ChatMessage (TypeAliasDeclaration)
|
|
@@ -254,8 +259,8 @@ that fits a token budget. Default budget is 8192 (1024 with `--focus`). `--focus
|
|
|
254
259
|
personalizes the ranking toward a file you're working on.
|
|
255
260
|
|
|
256
261
|
```
|
|
257
|
-
$ node
|
|
258
|
-
#
|
|
262
|
+
$ node agentmap.mjs --map --tokens 400
|
|
263
|
+
# agentmap (154 files, sha 2becdb4) — focus: global, budget ~400 tok
|
|
259
264
|
|
|
260
265
|
lib/utils.ts:
|
|
261
266
|
cn (FunctionDeclaration)
|
|
@@ -287,8 +292,8 @@ lib/db/schema.ts:
|
|
|
287
292
|
Focused on a working file — the ranking re-centers on what `lib/db/queries.ts` actually touches:
|
|
288
293
|
|
|
289
294
|
```
|
|
290
|
-
$ node
|
|
291
|
-
#
|
|
295
|
+
$ node agentmap.mjs --map --focus lib/db/queries.ts --tokens 350
|
|
296
|
+
# agentmap (154 files, sha 2becdb4) — focus: lib/db/queries.ts, budget ~350 tok
|
|
292
297
|
|
|
293
298
|
lib/utils.ts:
|
|
294
299
|
cn (FunctionDeclaration)
|
|
@@ -320,13 +325,25 @@ lib/errors.ts:
|
|
|
320
325
|
### `--print` — full map as JSON
|
|
321
326
|
|
|
322
327
|
Dumps the cached map (`hubs`, `features`, `rankedSymbols`, `files`) as one JSON object —
|
|
323
|
-
for piping into other tools.
|
|
328
|
+
for piping into other tools. Also includes a top-level `fileCount`.
|
|
324
329
|
|
|
325
330
|
```
|
|
326
|
-
$ node
|
|
331
|
+
$ node agentmap.mjs --print | jq '.hubs[0]'
|
|
327
332
|
"lib/utils.ts (deg 52, pr 0.105171)"
|
|
328
333
|
```
|
|
329
334
|
|
|
335
|
+
### Global flags
|
|
336
|
+
|
|
337
|
+
| Flag | Description |
|
|
338
|
+
|------|-------------|
|
|
339
|
+
| `--help` / `-h` | Print a usage block listing every flag and exit 0. |
|
|
340
|
+
| `--version` / `-v` | Print the version from `package.json` and exit 0. |
|
|
341
|
+
| `--json` | **Global modifier.** When present, every command prints exactly one JSON object to stdout (no prose). Shapes vary per command: `--json --hubs` → `{command,fileCount,sha,hubs:[string]}`, `--json --find X` → `{command,query,matches:[{file,name,kind}]}`, `--json --relates X` → `{command,file,pagerank,exports,imports,dependents,related}`, `--json --any X` → `{command,query,kind,…payload}`, etc. Bare `--json` (no query flag) → `{command:"build",fileCount,features,topHub}`. |
|
|
342
|
+
| `--install-hooks` | Copy `hooks/post-commit` into `.git/hooks/` (chmod 0755), ensure `.claude/agentmap.json` is in `.gitignore`, and print the Claude Code `settings.json` `PreToolUse` snippet. Exit 0 on success, stderr + exit 1 on failure. |
|
|
343
|
+
| `--mcp` | Start agentmap as a **stdio MCP server** so non-Claude-Code agents (Cursor, Cline, any MCP client) can call every flag as a first-class tool. |
|
|
344
|
+
|
|
345
|
+
**Exit-code contract:** `0` = success / match / help / version; `1` = query returned zero results (`--any`, `--find`, `--relates`, `--feature` with no match); `2` = usage error (missing required arg, unknown flag). Any token starting with `-` that matches no known flag prints an error to stderr and exits 2.
|
|
346
|
+
|
|
330
347
|
---
|
|
331
348
|
|
|
332
349
|
## The agent loop (the actual point)
|
|
@@ -337,22 +354,32 @@ to query the map before it serial-greps.
|
|
|
337
354
|
|
|
338
355
|
### 1. Auto-refresh on commit
|
|
339
356
|
|
|
340
|
-
[`hooks/post-commit`](./hooks/post-commit) rebuilds `.claude/
|
|
357
|
+
[`hooks/post-commit`](./hooks/post-commit) rebuilds `.claude/agentmap.json` after each
|
|
341
358
|
commit, detached + silenced so it never slows the commit. It skips during
|
|
342
359
|
rebase/merge/cherry-pick and no-ops if Node is missing.
|
|
343
360
|
|
|
361
|
+
The hooks ship inside the npm package. The simplest setup:
|
|
362
|
+
|
|
363
|
+
```bash
|
|
364
|
+
npx @raymondchins/agentmap --install-hooks
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
This copies `hooks/post-commit` into `.git/hooks/`, sets it executable, ensures
|
|
368
|
+
`.claude/agentmap.json` is in `.gitignore`, and prints the `.claude/settings.json`
|
|
369
|
+
snippet for the `PreToolUse` nudge hook (below). Manual alternative:
|
|
370
|
+
|
|
344
371
|
```bash
|
|
345
372
|
# from your repo root
|
|
346
373
|
cp hooks/post-commit .git/hooks/post-commit
|
|
347
374
|
chmod +x .git/hooks/post-commit
|
|
348
375
|
```
|
|
349
376
|
|
|
350
|
-
The hook auto-locates the builder: a local `
|
|
351
|
-
the installed `agentmap` binary, then `npx @raymondchins/agentmap`.
|
|
377
|
+
The hook auto-locates the builder: a local `agentmap.mjs`, then `scripts/agentmap.mjs`, then
|
|
378
|
+
the installed `agentmap` binary, then `npx --no-install @raymondchins/agentmap`.
|
|
352
379
|
|
|
353
380
|
### 2. Force the agent to use it — `PreToolUse` hook
|
|
354
381
|
|
|
355
|
-
[`hooks/
|
|
382
|
+
[`hooks/agentmap-nudge.mjs`](./hooks/agentmap-nudge.mjs) is a **non-blocking** `PreToolUse(Grep)`
|
|
356
383
|
hook for Claude Code. When a `Grep` looks like a dependency / who-imports / component-usage /
|
|
357
384
|
reuse search, it injects a reminder steering the agent to `agentmap --any` first. It never
|
|
358
385
|
denies the grep, and stays silent for raw-string / Tailwind-class / lowercase-HTML-tag
|
|
@@ -367,7 +394,7 @@ Wire it up in `.claude/settings.json`:
|
|
|
367
394
|
{
|
|
368
395
|
"matcher": "Grep",
|
|
369
396
|
"hooks": [
|
|
370
|
-
{ "type": "command", "command": "node ./hooks/
|
|
397
|
+
{ "type": "command", "command": "node ./hooks/agentmap-nudge.mjs" }
|
|
371
398
|
]
|
|
372
399
|
}
|
|
373
400
|
]
|
|
@@ -385,7 +412,8 @@ agent is steered to it the moment it reaches for a dependency-shaped grep.
|
|
|
385
412
|
Honesty first — this is deliberately a small, sharp tool, not a universal code-graph.
|
|
386
413
|
|
|
387
414
|
- **TS/JS only, by design.** Built on `ts-morph`. No Python, Go, Rust, etc. If your repo
|
|
388
|
-
isn't TypeScript/JavaScript, use a tree-sitter-based tool instead.
|
|
415
|
+
isn't TypeScript/JavaScript, use a tree-sitter-based tool instead. Support for other
|
|
416
|
+
languages is a possible future direction.
|
|
389
417
|
- **File-level import graph, not a full reference graph.** Edges come from static
|
|
390
418
|
`import` / re-export declarations and the named symbols crossing them. It does **not**
|
|
391
419
|
do call-site or full reference resolution — `--relates` tells you which files import a
|
|
@@ -407,19 +435,19 @@ Honesty first — this is deliberately a small, sharp tool, not a universal code
|
|
|
407
435
|
|
|
408
436
|
## Benchmark
|
|
409
437
|
|
|
410
|
-
|
|
438
|
+
Measured across **7 agent tasks on 3 real public repos** — reproducible with `node benchmark/bench.mjs <repo>`:
|
|
439
|
+
|
|
440
|
+
| Repo | Files | Tokens saved |
|
|
441
|
+
|------|------:|-------------:|
|
|
442
|
+
| [vercel/ai-chatbot](https://github.com/vercel/ai-chatbot) | 154 | **98.3%** |
|
|
443
|
+
| [colinhacks/zod](https://github.com/colinhacks/zod) | 367 | **99.2%** |
|
|
444
|
+
| [shadcn-ui/taxonomy](https://github.com/shadcn-ui/taxonomy) | 125 | **96.0%** |
|
|
411
445
|
|
|
412
|
-
- **
|
|
413
|
-
- **A. Understand file deps** (`lib/utils.ts`): baseline 583 tok → agentmap 517 tok (11.3% saved)
|
|
414
|
-
- **B. Find symbol** (`ChatMessage`): baseline 1950 tok → agentmap 20 tok (99% saved)
|
|
415
|
-
- **C. Repo overview** (tree + 3 hub files): baseline 3065 tok → agentmap 1127 tok (63.2% saved)
|
|
416
|
-
- Cold build (parse + PageRank + symbol graph): **~1.2s**. Warm cached query (`--hubs`,
|
|
417
|
-
clean tree): **~0.2s**.
|
|
446
|
+
Per-task peaks (real, across the three repos): **whole-repo map 99.8%**, **reuse-before-rebuild lookup 99.9%**, **blast-radius 99.2%**, **find-symbol 99%**. Cold build (parse + PageRank + symbol graph) **~1.2s**; warm cached query **~0.2s**.
|
|
418
447
|
|
|
419
|
-
|
|
420
|
-
end-to-end retrieval accuracy — there's no "did the agent fix the bug faster" eval yet.
|
|
448
|
+
Honest notes: the win scales with repo size — a *trivial single-file* `--any` lookup can actually cost **more** than `cat`+`grep` (taxonomy showed −313% on that one task; we leave it in). Numbers measure **context-token volume**, not end-to-end retrieval accuracy. Token est = `chars / 4`, applied to both sides.
|
|
421
449
|
|
|
422
|
-
Full methodology,
|
|
450
|
+
Full methodology, per-repo tables, and all caveats: **[`./benchmark/RESULTS.md`](./benchmark/RESULTS.md)**.
|
|
423
451
|
|
|
424
452
|
---
|
|
425
453
|
|
|
@@ -431,8 +459,8 @@ Issues and PRs welcome. High-value directions:
|
|
|
431
459
|
- A real tokenizer behind the `--map` budget.
|
|
432
460
|
- Hardening feature detection for non-`app/`-router layouts.
|
|
433
461
|
|
|
434
|
-
Keep the dependency footprint minimal — `ts-morph` is the only runtime
|
|
435
|
-
feature.
|
|
462
|
+
Keep the dependency footprint minimal — `ts-morph` is the only runtime dependency (it bundles
|
|
463
|
+
the TypeScript compiler, ~10 MB installed), and keeping it that way is a feature.
|
|
436
464
|
|
|
437
465
|
## License
|
|
438
466
|
|