layermap 0.1.3 → 0.1.5
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 +32 -11
- 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 +38 -24
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -5,8 +5,17 @@
|
|
|
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
20
|
Harness and other MCP clients three read-only tools that answer, in one call, what an agent otherwise works out with
|
|
12
21
|
dozens of searches:
|
|
@@ -32,16 +41,18 @@ DECLARATION internal/storage/entry.go: Storage.MarkFeedAsRead m656-680 exported
|
|
|
32
41
|
← called by internal/googlereader/handler.go: handler.markAllAsReadHandler m1261-1338 @1311
|
|
33
42
|
← called by internal/ui/feed_mark_as_read.go: handler.markFeedAsRead m14-30 @24
|
|
34
43
|
[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"
|
|
44
|
+
← used as value by internal/api/api.go: Serve f25-84 @61 "PUT /v1/feeds/{feedID}/mark-all-as-read"
|
|
36
45
|
[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"
|
|
46
|
+
← used as value by internal/googlereader/handler.go: Serve f44-64 @62 "POST /reader/api/0/mark-all-as-read"
|
|
38
47
|
[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"
|
|
48
|
+
← used as value by internal/ui/ui.go: Serve f18-180 @77 "POST /feed/{feedID}/mark-all-as-read"
|
|
40
49
|
… (the Fever API, then on down to main.go: main)
|
|
41
50
|
```
|
|
42
51
|
|
|
43
52
|
`m` and `f` mark methods and functions with their lines; `@` is the line of the call, and the quoted
|
|
44
|
-
|
|
53
|
+
route is what it is registered under: the HTTP method and the full path, with the `/v1` prefix its
|
|
54
|
+
subrouter adds. In Java, Python and TypeScript the route shows on the handler itself, as in
|
|
55
|
+
`@GetMapping("/{id}") route "GET /api/tasks/{id}"`.
|
|
45
56
|
|
|
46
57
|
## Results
|
|
47
58
|
|
|
@@ -51,14 +62,17 @@ projects, graded blind against truth sets cross-checked with each language's own
|
|
|
51
62
|
| | With LayerMap | Without |
|
|
52
63
|
|---|---|---|
|
|
53
64
|
| 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
|
-
|
|
|
65
|
+
| Used unprompted by Claude Code / Codex (plugin installed, two rounds) | **12 of 12 / 12 of 12** | — |
|
|
66
|
+
| Endpoints found, no request limit (Claude Code / Codex, 0.1.5) | 100% / 100% | 99.0% / 100% |
|
|
67
|
+
| Claude Code cost, no request limit | **−33%** | |
|
|
68
|
+
| Codex input tokens, no request limit (current defaults) | +14% | |
|
|
69
|
+
| Time, no request limit (Claude Code / Codex) | +25% / +20% | |
|
|
58
70
|
|
|
59
71
|
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
|
-
|
|
72
|
+
no limit, both agents find nearly everything either way. Claude Code costs a third less with the
|
|
73
|
+
map. Codex's current defaults already search lean, so the map no longer saves it tokens; at
|
|
74
|
+
reasoning effort max, in the first round, it saved 55%. Agents with the map explore more widely,
|
|
75
|
+
which takes longer. These are small samples on tasks written by LayerMap's authors.
|
|
62
76
|
The [report](https://github.com/coffeecoproject/layermap/blob/main/docs/benchmark.md) has the
|
|
63
77
|
setup, the published tasks and the limitations.
|
|
64
78
|
|
|
@@ -178,7 +192,14 @@ relationship does not prove absence.
|
|
|
178
192
|
|
|
179
193
|
You need pnpm, Go 1.24 and a JDK 21+. A missing toolchain leaves its language unanalyzed.
|
|
180
194
|
|
|
181
|
-
Run `pnpm install
|
|
195
|
+
Run `pnpm install`. On the first install pnpm asks which dependencies may run build scripts; allow
|
|
196
|
+
esbuild only, since the SQLite package ships prebuilt binaries:
|
|
197
|
+
|
|
198
|
+
```
|
|
199
|
+
pnpm approve-builds esbuild '!@photostructure/sqlite'
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Then run `pnpm test`, `pnpm typecheck` or `pnpm lint`.
|
|
182
203
|
|
|
183
204
|
`pnpm package` builds the npm package.
|
|
184
205
|
|
|
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);
|