layermap 0.1.4 → 0.1.6
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 +37 -12
- package/analyzers/go/darwin-arm64/go-map +0 -0
- package/analyzers/go/darwin-x64/go-map +0 -0
- package/analyzers/go/linux-arm64/go-map +0 -0
- package/analyzers/go/linux-x64/go-map +0 -0
- package/analyzers/project-map-java/java-map.jar +0 -0
- package/analyzers/project-map-python-worker.mjs +68 -1
- package/analyzers/project-map-worker.mjs +267 -150
- package/dist/cli.mjs +968 -307
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,16 +5,27 @@
|
|
|
5
5
|
**English** · [中文](https://github.com/coffeecoproject/layermap/blob/main/README.zh-CN.md)
|
|
6
6
|
|
|
7
7
|
[](https://www.npmjs.com/package/layermap)
|
|
8
|
+
[](https://github.com/coffeecoproject/layermap/stargazers)
|
|
9
|
+
[](https://www.npmjs.com/package/layermap)
|
|
8
10
|
[](https://github.com/coffeecoproject/layermap/blob/main/LICENSE)
|
|
9
11
|
|
|
12
|
+
**LayerMap tells your coding agent what calls a function and what changing it affects, up to the HTTP routes, in one call.** With at most 15 requests, agents found **97.9%** of affected endpoints with LayerMap vs 58.8% without; with no limit, Claude Code cost **32% less** ([benchmark](https://github.com/coffeecoproject/layermap/blob/main/docs/benchmark.md)).
|
|
13
|
+
|
|
14
|
+
**Resolved by each language's compiler or type checker, not guessed from names by tree-sitter:** calls through interfaces, base classes, templates and decorators link as the compiler links them, for TypeScript, JavaScript, Go, Python and Java.
|
|
15
|
+
|
|
16
|
+
<p align="center"><img src="https://raw.githubusercontent.com/coffeecoproject/layermap/main/assets/demo.svg" alt="Claude Code asks which HTTP endpoints changing Storage.MarkFeedAsRead affects; one LayerMap call returns all four callers with their routes" width="100%"></p>
|
|
17
|
+
<p align="center"><sub>A real Claude Code session on <a href="https://github.com/miniflux/v2">Miniflux</a>, replayed: one map call finds every endpoint, then the agent confirms them in source.</sub></p>
|
|
18
|
+
|
|
10
19
|
A layered map of your codebase for coding agents. LayerMap gives Claude Code, Codex, DeepSeek
|
|
11
|
-
Harness and other MCP clients
|
|
12
|
-
dozens of searches:
|
|
20
|
+
Harness and other MCP clients read-only tools that answer, in one call, what an agent otherwise works out
|
|
21
|
+
with dozens of searches:
|
|
13
22
|
|
|
14
23
|
- **What calls this, and what does changing it affect?** Callers traced up to 8 levels, to the
|
|
15
24
|
HTTP routes, handlers, jobs and commands they start from.
|
|
16
25
|
- **What does it call?** Callees down to 8 levels.
|
|
17
26
|
- **What is here?** Modules, each file's declarations, and every usage of a symbol.
|
|
27
|
+
- **What did my edit affect?** The routes, jobs and commands the uncommitted changes reach, and the
|
|
28
|
+
existing tests related to them.
|
|
18
29
|
|
|
19
30
|
It maps **TypeScript, JavaScript, Go, Python and Java** with each language's own compiler, so calls
|
|
20
31
|
through interfaces, base classes, templates and decorators resolve as the compiler resolves them,
|
|
@@ -32,16 +43,18 @@ DECLARATION internal/storage/entry.go: Storage.MarkFeedAsRead m656-680 exported
|
|
|
32
43
|
← called by internal/googlereader/handler.go: handler.markAllAsReadHandler m1261-1338 @1311
|
|
33
44
|
← called by internal/ui/feed_mark_as_read.go: handler.markFeedAsRead m14-30 @24
|
|
34
45
|
[1] internal/api/feed.go: handler.markFeedAsRead m140-155
|
|
35
|
-
← used as value by internal/api/api.go: Serve f25-84 @61 "/feeds/{feedID}/mark-all-as-read"
|
|
46
|
+
← used as value by internal/api/api.go: Serve f25-84 @61 "PUT /v1/feeds/{feedID}/mark-all-as-read"
|
|
36
47
|
[1] internal/googlereader/handler.go: handler.markAllAsReadHandler m1261-1338
|
|
37
|
-
← used as value by internal/googlereader/handler.go: Serve f44-64 @62 "/mark-all-as-read"
|
|
48
|
+
← used as value by internal/googlereader/handler.go: Serve f44-64 @62 "POST /reader/api/0/mark-all-as-read"
|
|
38
49
|
[1] internal/ui/feed_mark_as_read.go: handler.markFeedAsRead m14-30
|
|
39
|
-
← used as value by internal/ui/ui.go: Serve f18-180 @77 "/feed/{feedID}/mark-all-as-read"
|
|
50
|
+
← used as value by internal/ui/ui.go: Serve f18-180 @77 "POST /feed/{feedID}/mark-all-as-read"
|
|
40
51
|
… (the Fever API, then on down to main.go: main)
|
|
41
52
|
```
|
|
42
53
|
|
|
43
54
|
`m` and `f` mark methods and functions with their lines; `@` is the line of the call, and the quoted
|
|
44
|
-
|
|
55
|
+
route is what it is registered under: the HTTP method and the full path, with the `/v1` prefix its
|
|
56
|
+
subrouter adds. In Java, Python and TypeScript the route shows on the handler itself, as in
|
|
57
|
+
`@GetMapping("/{id}") route "GET /api/tasks/{id}"`.
|
|
45
58
|
|
|
46
59
|
## Results
|
|
47
60
|
|
|
@@ -51,14 +64,18 @@ projects, graded blind against truth sets cross-checked with each language's own
|
|
|
51
64
|
| | With LayerMap | Without |
|
|
52
65
|
|---|---|---|
|
|
53
66
|
| Endpoints found, at most 15 requests (`gpt-5.5`, 6 tasks × 3 runs) | **97.9%** | 58.8% |
|
|
54
|
-
| Used unprompted by Claude Code / Codex (plugin installed) | **
|
|
55
|
-
| Endpoints found, no request limit (Claude Code / Codex) |
|
|
56
|
-
|
|
|
57
|
-
|
|
|
67
|
+
| Used unprompted by Claude Code / Codex (plugin installed, two rounds) | **12 of 12 / 12 of 12** | — |
|
|
68
|
+
| Endpoints found, no request limit (Claude Code / Codex, 0.1.5) | 100% / 100% | 99.0% / 100% |
|
|
69
|
+
| Claude Code cost, no request limit | **−33%** | |
|
|
70
|
+
| Codex input tokens, no request limit (current defaults) | +14% | |
|
|
71
|
+
| Time, no request limit (Claude Code / Codex) | +25% / +20% | |
|
|
72
|
+
| Failing tests the change check lists (Go / Python, functions made to fail) | **100% / 83–88%** | — |
|
|
58
73
|
|
|
59
74
|
With a tight budget, the map finds far more of the affected code, at about 24% more tokens. With
|
|
60
|
-
no limit, both agents
|
|
61
|
-
|
|
75
|
+
no limit, both agents find nearly everything either way. Claude Code costs a third less with the
|
|
76
|
+
map. Codex's current defaults already search lean, so the map no longer saves it tokens; at
|
|
77
|
+
reasoning effort max, in the first round, it saved 55%. Agents with the map explore more widely,
|
|
78
|
+
which takes longer. These are small samples on tasks written by LayerMap's authors.
|
|
62
79
|
The [report](https://github.com/coffeecoproject/layermap/blob/main/docs/benchmark.md) has the
|
|
63
80
|
setup, the published tasks and the limitations.
|
|
64
81
|
|
|
@@ -113,6 +130,12 @@ when the map helps. On first launch, npx downloads the pinned `layermap` package
|
|
|
113
130
|
Claude Code asks once before each map tool runs in a project. Choose "don't ask again", or run
|
|
114
131
|
`npx layermap allow claude` to allow the plugin's read-only tools everywhere.
|
|
115
132
|
|
|
133
|
+
**After an edit.** When the agent changes code, `project_check_changes` lists what the change
|
|
134
|
+
affects: the routes, jobs and commands that reach the changed functions, what the map cannot see,
|
|
135
|
+
and the existing tests related to the change. It never writes or runs tests. In Claude Code the
|
|
136
|
+
plugin asks the agent once, before it finishes, to run this check if it has not; set
|
|
137
|
+
`LAYERMAP_STOP_CHECK=0` to turn that off. Codex and DeepSeek Harness are told to run it.
|
|
138
|
+
|
|
116
139
|
**Without plugins:** run `npx layermap setup claude` or `npx layermap setup codex`. Setup does three
|
|
117
140
|
things:
|
|
118
141
|
|
|
@@ -145,6 +168,7 @@ nothing anywhere ([privacy](https://github.com/coffeecoproject/layermap/blob/mai
|
|
|
145
168
|
| `project_explore_map` | A directory, a file, or a declaration's callers and callees (`direction` INCOMING or OUTGOING, `depth` up to 8). |
|
|
146
169
|
| `project_search_map` | Find declarations by words in their names, paths or documentation. |
|
|
147
170
|
| `project_find_references` | Every usage of a declaration, compiled from current source. |
|
|
171
|
+
| `project_check_changes` | What the uncommitted changes (or those since `base`) affect: changed and removed declarations, the routes, jobs and commands they reach, what to check by hand, and related tests. |
|
|
148
172
|
|
|
149
173
|
The same from the command line:
|
|
150
174
|
|
|
@@ -152,6 +176,7 @@ The same from the command line:
|
|
|
152
176
|
npx layermap explore src/api/users.ts --name createUser --direction INCOMING --depth 8
|
|
153
177
|
npx layermap search "invoice total"
|
|
154
178
|
npx layermap refs src/billing/tax.ts calculateTax
|
|
179
|
+
npx layermap check --base main
|
|
155
180
|
```
|
|
156
181
|
|
|
157
182
|
## FAQ
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -120950,6 +120950,18 @@ function literal2(node) {
|
|
|
120950
120950
|
const value = parts.map((part) => part.d.value).join("");
|
|
120951
120951
|
return value.length > 0 && value.length <= 256 ? value : void 0;
|
|
120952
120952
|
}
|
|
120953
|
+
var HTTP_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "TRACE"]);
|
|
120954
|
+
function routeText(node) {
|
|
120955
|
+
if (node?.nodeType !== 48 /* StringList */) return void 0;
|
|
120956
|
+
const parts = node.d.strings;
|
|
120957
|
+
if (!parts.every((part) => part.nodeType === 49 /* String */)) return void 0;
|
|
120958
|
+
const value = parts.map((part) => part.d.value).join("");
|
|
120959
|
+
return value.length <= 256 ? value : void 0;
|
|
120960
|
+
}
|
|
120961
|
+
function joinRoute(prefix, path3) {
|
|
120962
|
+
const joined = !prefix ? path3 : !path3 ? prefix : `${prefix.replace(/\/+$/u, "")}/${path3.replace(/^\/+/u, "")}`;
|
|
120963
|
+
return joined.startsWith("/") || joined.startsWith("$") ? joined : `/${joined}`;
|
|
120964
|
+
}
|
|
120953
120965
|
function docstring(statements) {
|
|
120954
120966
|
const first = statements[0];
|
|
120955
120967
|
if (first?.nodeType !== 47 /* StatementList */) return void 0;
|
|
@@ -121432,6 +121444,59 @@ var Relater = class extends ParseTreeWalker {
|
|
|
121432
121444
|
relation(fact) {
|
|
121433
121445
|
this.x.relation({ ...fact, path: this.path });
|
|
121434
121446
|
}
|
|
121447
|
+
routerPrefix(name) {
|
|
121448
|
+
if (!this.routers) {
|
|
121449
|
+
const prefixes = /* @__PURE__ */ new Map();
|
|
121450
|
+
const assigned = /* @__PURE__ */ new Map();
|
|
121451
|
+
for (const statement of this.scopes[0].d.statements) {
|
|
121452
|
+
if (statement.nodeType !== 47 /* StatementList */) continue;
|
|
121453
|
+
for (const inner of statement.d.statements) {
|
|
121454
|
+
if (inner.nodeType !== 3 /* Assignment */) continue;
|
|
121455
|
+
const { leftExpr, rightExpr } = inner.d;
|
|
121456
|
+
const target = leftExpr.nodeType === 54 /* TypeAnnotation */ ? leftExpr.d.valueExpr : leftExpr;
|
|
121457
|
+
if (target.nodeType !== 38 /* Name */) continue;
|
|
121458
|
+
const name2 = target.d.value;
|
|
121459
|
+
assigned.set(name2, (assigned.get(name2) ?? 0) + 1);
|
|
121460
|
+
if (rightExpr.nodeType !== 9 /* Call */) continue;
|
|
121461
|
+
for (const argument of rightExpr.d.args) {
|
|
121462
|
+
const keyword = argument.d.name?.d.value;
|
|
121463
|
+
const prefix = routeText(argument.d.valueExpr);
|
|
121464
|
+
if ((keyword === "prefix" || keyword === "url_prefix") && prefix !== void 0)
|
|
121465
|
+
prefixes.set(name2, prefix);
|
|
121466
|
+
}
|
|
121467
|
+
}
|
|
121468
|
+
}
|
|
121469
|
+
for (const [name2, count] of assigned) if (count > 1) prefixes.delete(name2);
|
|
121470
|
+
this.routers = prefixes;
|
|
121471
|
+
}
|
|
121472
|
+
return this.routers.get(name) ?? "";
|
|
121473
|
+
}
|
|
121474
|
+
// The route a decorator registers its function under, when it says more than the decorator's
|
|
121475
|
+
// argument: router.put("/{id}") or app.route("/items", methods=["GET", "POST"]) on a router
|
|
121476
|
+
// whose prefix this module sets.
|
|
121477
|
+
route(call, argument) {
|
|
121478
|
+
const callee = call.d.leftExpr;
|
|
121479
|
+
if (callee.nodeType !== 35 /* MemberAccess */) return void 0;
|
|
121480
|
+
const member = callee.d.member.d.value;
|
|
121481
|
+
const methods = HTTP_METHODS.has(member.toUpperCase()) ? [member.toUpperCase()] : [];
|
|
121482
|
+
let path3;
|
|
121483
|
+
for (const item of call.d.args) {
|
|
121484
|
+
const keyword = item.d.name?.d.value;
|
|
121485
|
+
if (keyword === void 0) path3 ??= routeText(item.d.valueExpr);
|
|
121486
|
+
else if (keyword === "path" || keyword === "rule") path3 ??= routeText(item.d.valueExpr);
|
|
121487
|
+
else if (keyword === "methods" && (item.d.valueExpr.nodeType === 34 /* List */ || item.d.valueExpr.nodeType === 52 /* Tuple */))
|
|
121488
|
+
for (const method of item.d.valueExpr.d.items) {
|
|
121489
|
+
const text = routeText(method)?.toUpperCase();
|
|
121490
|
+
if (text && HTTP_METHODS.has(text)) methods.push(text);
|
|
121491
|
+
}
|
|
121492
|
+
}
|
|
121493
|
+
if (path3 === void 0 || !methods.length && member !== "route" && member !== "api_route")
|
|
121494
|
+
return void 0;
|
|
121495
|
+
const receiver = callee.d.leftExpr;
|
|
121496
|
+
const prefix = receiver.nodeType === 38 /* Name */ ? this.routerPrefix(receiver.d.value) : "";
|
|
121497
|
+
const route = `${methods.length ? `${methods.join("|")} ` : ""}${joinRoute(prefix, path3)}`;
|
|
121498
|
+
return route.length <= 256 && route !== argument ? route : void 0;
|
|
121499
|
+
}
|
|
121435
121500
|
decorate(owner, decorators, executing) {
|
|
121436
121501
|
for (const decorator of decorators) {
|
|
121437
121502
|
const expression = decorator.d.expr;
|
|
@@ -121439,6 +121504,7 @@ var Relater = class extends ParseTreeWalker {
|
|
|
121439
121504
|
const target = call ? call.d.leftExpr : expression;
|
|
121440
121505
|
const first = call?.d.args.find((argument2) => !argument2.d.name);
|
|
121441
121506
|
const argument = literal2(first?.d.valueExpr);
|
|
121507
|
+
const route = call && this.route(call, argument);
|
|
121442
121508
|
this.relation({
|
|
121443
121509
|
kind: "DECORATED_BY",
|
|
121444
121510
|
from: owner,
|
|
@@ -121446,7 +121512,8 @@ var Relater = class extends ParseTreeWalker {
|
|
|
121446
121512
|
end: end(decorator),
|
|
121447
121513
|
target: label(target),
|
|
121448
121514
|
...this.x.resolve(target),
|
|
121449
|
-
...argument ? { argument } : {}
|
|
121515
|
+
...argument ? { argument } : {},
|
|
121516
|
+
...route ? { route } : {}
|
|
121450
121517
|
});
|
|
121451
121518
|
this.push(executing, owner, this.scopes[this.scopes.length - 1]);
|
|
121452
121519
|
if (call) for (const item of call.d.args) this.walk(item.d.valueExpr);
|