layermap 0.1.1 → 0.1.2
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 +129 -57
- package/analyzers/project-map-java/java-map.jar +0 -0
- package/dist/cli.mjs +30 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,28 +1,97 @@
|
|
|
1
|
+
<p align="center"><img src="https://raw.githubusercontent.com/coffeecoproject/layermap/main/assets/icon.png" alt="LayerMap" width="120"></p>
|
|
2
|
+
|
|
1
3
|
# LayerMap
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
**English** · [中文](https://github.com/coffeecoproject/layermap/blob/main/README.zh-CN.md)
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/layermap)
|
|
8
|
+
[](https://github.com/coffeecoproject/layermap/blob/main/LICENSE)
|
|
9
|
+
|
|
10
|
+
A layered map of your codebase for coding agents. LayerMap gives Claude Code, Codex and other MCP
|
|
11
|
+
clients three read-only tools that answer, in one call, what an agent otherwise works out with
|
|
12
|
+
dozens of searches:
|
|
6
13
|
|
|
7
|
-
- **What calls this, and what does changing it affect?**
|
|
8
|
-
|
|
14
|
+
- **What calls this, and what does changing it affect?** Callers traced up to 8 levels, to the
|
|
15
|
+
HTTP routes, handlers, jobs and commands they start from.
|
|
9
16
|
- **What does it call?** Callees down to 8 levels.
|
|
10
|
-
- **What is here?**
|
|
17
|
+
- **What is here?** Modules, each file's declarations, and every usage of a symbol.
|
|
18
|
+
|
|
19
|
+
It maps **TypeScript, JavaScript, Go, Python and Java** with each language's own compiler, so calls
|
|
20
|
+
through interfaces, base classes, templates and decorators resolve as the compiler resolves them,
|
|
21
|
+
including the ones text search misses.
|
|
22
|
+
|
|
23
|
+
## Example
|
|
24
|
+
|
|
25
|
+
In [Miniflux](https://github.com/miniflux/v2), one call on `Storage.MarkFeedAsRead` finds all four
|
|
26
|
+
ways a request reaches it, each with its route:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
DECLARATION internal/storage/entry.go: Storage.MarkFeedAsRead m656-680 exported
|
|
30
|
+
← called by internal/api/feed.go: handler.markFeedAsRead m140-155 @149
|
|
31
|
+
← called by internal/fever/handler.go: handler.handleWriteFeeds m492-519 @508
|
|
32
|
+
← called by internal/googlereader/handler.go: handler.markAllAsReadHandler m1261-1338 @1311
|
|
33
|
+
← called by internal/ui/feed_mark_as_read.go: handler.markFeedAsRead m14-30 @24
|
|
34
|
+
[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"
|
|
36
|
+
[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"
|
|
38
|
+
[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"
|
|
40
|
+
… (the Fever API, then on down to main.go: main)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`m` and `f` mark methods and functions with their lines; `@` is the line of the call, and the quoted
|
|
44
|
+
path is the route it is registered under.
|
|
45
|
+
|
|
46
|
+
## Results
|
|
47
|
+
|
|
48
|
+
Impact questions ("which HTTP endpoints does changing this affect?") on public Go, Python and Java
|
|
49
|
+
projects, graded blind against truth sets cross-checked with each language's own toolchain:
|
|
50
|
+
|
|
51
|
+
| | With LayerMap | Without |
|
|
52
|
+
|---|---|---|
|
|
53
|
+
| 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) | **6 of 6 / 6 of 6** | — |
|
|
55
|
+
| Endpoints found, no request limit (Claude Code / Codex) | 99.3% / 98.0% | 99.0% / 98.6% |
|
|
56
|
+
| Cost, no request limit (Claude Code in USD / Codex in input tokens) | **−32% / −55%** | |
|
|
57
|
+
| Time, no request limit | +24% / +17% | |
|
|
58
|
+
|
|
59
|
+
With a tight budget, the map finds far more of the affected code, at about 24% more tokens. With
|
|
60
|
+
no limit, both agents get there either way. The map makes the run cheaper, and the agents explore
|
|
61
|
+
more widely, which takes longer. These are small samples on tasks written by LayerMap's authors.
|
|
62
|
+
The [report](https://github.com/coffeecoproject/layermap/blob/main/docs/benchmark.md) has the
|
|
63
|
+
setup, the published tasks and the limitations.
|
|
64
|
+
|
|
65
|
+
## How LayerMap differs
|
|
66
|
+
|
|
67
|
+
Other tools give agents part of this. LayerMap combines compiler accuracy with whole-chain traces
|
|
68
|
+
in one local map:
|
|
69
|
+
|
|
70
|
+
| | Tree-sitter code graphs (codegraph, GitNexus, …) | Language servers and IDEs (Claude Code's LSP tool, Serena, JetBrains) | Embedding search (Claude Context, Augment) | **LayerMap** |
|
|
71
|
+
|---|---|---|---|---|
|
|
72
|
+
| How calls are linked | Matched by names, imports and framework rules, often with confidence scores | The compiler's own resolution | Not linked; similar code is retrieved | **Resolved by each language's compiler or type checker** |
|
|
73
|
+
| Callers traced to routes and handlers | In several tools, at varying depth | One level per request (JetBrains: 5 by default) | — | **Up to 8 levels in one call** |
|
|
74
|
+
| Kept as a map | Yes, with file watching | No, answered live by a running server | An index of code chunks | **Yes, brought up to date on every call** |
|
|
75
|
+
| Runs on your machine | Yes; some send anonymous telemetry | Yes | Usually with cloud embeddings | **Yes, and sends nothing** |
|
|
11
76
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
77
|
+
Another tool fits better if you need:
|
|
78
|
+
|
|
79
|
+
- more languages, since tree-sitter graphs cover 30 or more;
|
|
80
|
+
- Windows;
|
|
81
|
+
- renaming and refactoring, from language servers;
|
|
82
|
+
- search by meaning, from embedding search;
|
|
83
|
+
- search across many repositories, with Sourcegraph.
|
|
15
84
|
|
|
16
85
|
## Install
|
|
17
86
|
|
|
18
|
-
|
|
87
|
+
**Claude Code**
|
|
19
88
|
|
|
20
89
|
```
|
|
21
90
|
/plugin marketplace add coffeecoproject/layermap
|
|
22
91
|
/plugin install layermap@layermap
|
|
23
92
|
```
|
|
24
93
|
|
|
25
|
-
|
|
94
|
+
**Codex**
|
|
26
95
|
|
|
27
96
|
```
|
|
28
97
|
codex plugin marketplace add coffeecoproject/layermap
|
|
@@ -30,77 +99,80 @@ codex plugin add layermap@layermap
|
|
|
30
99
|
```
|
|
31
100
|
|
|
32
101
|
Start a new session in a Git repository and ask as usual. The plugin tells the agent when the map
|
|
33
|
-
helps
|
|
102
|
+
helps. On first launch, npx downloads the pinned `layermap` package from npm. Claude Code asks once
|
|
103
|
+
before each map tool runs in a project; choose "don't ask again", or run `npx layermap allow claude`
|
|
104
|
+
to allow the plugin's read-only tools everywhere.
|
|
34
105
|
|
|
35
|
-
|
|
106
|
+
**Without plugins:** run `npx layermap setup claude` or `npx layermap setup codex`. Setup does three
|
|
107
|
+
things:
|
|
36
108
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
109
|
+
- registers the server;
|
|
110
|
+
- lets its read-only tools run without a prompt;
|
|
111
|
+
- adds one marked sentence to the agent's instructions file.
|
|
40
112
|
|
|
41
|
-
`
|
|
42
|
-
|
|
43
|
-
`~/.codex/AGENTS.md`) saying when to use the map; `--no-instructions` leaves that file alone, but
|
|
44
|
-
Codex then rarely finds the tools. `--scope project` writes the configuration into the repository
|
|
45
|
-
for a whole team. `npx layermap remove claude|codex` undoes it.
|
|
113
|
+
Use `--scope project` to set it up for a whole team, and `npx layermap remove …` to undo it. For any
|
|
114
|
+
other MCP client, run `npx -y layermap mcp` as a stdio server in the repository.
|
|
46
115
|
|
|
47
|
-
|
|
116
|
+
**Requirements:**
|
|
48
117
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
- **Git**: LayerMap maps a Git work tree, the one around the directory the agent starts in.
|
|
54
|
-
- **Java projects only:** a JDK 21 or later (found through `LAYERMAP_JAVA_HOME`, `JAVA_HOME`, `PATH`,
|
|
55
|
-
Homebrew or SDKMAN). Without one, Java files are listed but have no declarations or calls.
|
|
118
|
+
- Node.js 22.22 or later.
|
|
119
|
+
- macOS or Linux (x64 or arm64).
|
|
120
|
+
- A Git repository.
|
|
121
|
+
- For Java projects, a JDK 21 or later.
|
|
56
122
|
|
|
57
123
|
## How it works
|
|
58
124
|
|
|
59
|
-
The first
|
|
60
|
-
|
|
61
|
-
files first and re-analyzes only what changed, so the map always matches the working tree.
|
|
62
|
-
|
|
63
|
-
Maps live in your user cache (`~/Library/Caches/layermap` on macOS, `$XDG_CACHE_HOME/layermap`
|
|
64
|
-
or `~/.cache/layermap` on Linux, or `LAYERMAP_CACHE`), never in the repository. A project keeps
|
|
65
|
-
its three latest map versions; a map unused for 30 days is removed.
|
|
125
|
+
The first call in a repository builds its map: seconds for a small project, a few minutes for a
|
|
126
|
+
large one. Later calls re-analyze only what changed, so the map always matches the working tree.
|
|
66
127
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
128
|
+
Maps stay in your user cache (`~/Library/Caches/layermap`, `~/.cache/layermap` or
|
|
129
|
+
`LAYERMAP_CACHE`), never in the repository. LayerMap runs entirely on your machine and sends
|
|
130
|
+
nothing anywhere ([privacy](https://github.com/coffeecoproject/layermap/blob/main/PRIVACY.md),
|
|
131
|
+
[security](https://github.com/coffeecoproject/layermap/blob/main/SECURITY.md)).
|
|
71
132
|
|
|
72
133
|
| Tool | Use |
|
|
73
134
|
|---|---|
|
|
74
|
-
| `project_explore_map` |
|
|
135
|
+
| `project_explore_map` | A directory, a file, or a declaration's callers and callees (`direction` INCOMING or OUTGOING, `depth` up to 8). |
|
|
75
136
|
| `project_search_map` | Find declarations by words in their names, paths or documentation. |
|
|
76
137
|
| `project_find_references` | Every usage of a declaration, compiled from current source. |
|
|
77
138
|
|
|
78
|
-
The
|
|
79
|
-
dynamic dispatch, framework wiring, reflection and computed names need source reading, and a
|
|
80
|
-
missing relationship does not prove absence. The tools say where a trace stops.
|
|
81
|
-
|
|
82
|
-
## Command line
|
|
139
|
+
The same from the command line:
|
|
83
140
|
|
|
84
141
|
```
|
|
85
|
-
npx layermap index # build or update the map now
|
|
86
142
|
npx layermap explore src/api/users.ts --name createUser --direction INCOMING --depth 8
|
|
87
143
|
npx layermap search "invoice total"
|
|
88
144
|
npx layermap refs src/billing/tax.ts calculateTax
|
|
89
145
|
```
|
|
90
146
|
|
|
147
|
+
## FAQ
|
|
148
|
+
|
|
149
|
+
**How long does the first map take?** On a recent Mac:
|
|
150
|
+
|
|
151
|
+
- Miniflux (400 Go files): about 3 s.
|
|
152
|
+
- Polar's server (1,900 Python files): about a minute.
|
|
153
|
+
- Conductor (1,500 Java and 1,300 TypeScript files): under two minutes.
|
|
154
|
+
|
|
155
|
+
**What can't it see?** Calls the compiler cannot resolve statically: dependency injection, unknown
|
|
156
|
+
framework routing, reflection and computed names. The tools say where a trace stops, and a missing
|
|
157
|
+
relationship does not prove absence.
|
|
158
|
+
|
|
159
|
+
**Windows?** Not yet.
|
|
160
|
+
|
|
161
|
+
**How do I remove it?**
|
|
162
|
+
|
|
163
|
+
- Claude Code: `/plugin uninstall layermap@layermap`.
|
|
164
|
+
- Codex: `codex plugin remove layermap@layermap`.
|
|
165
|
+
- Then delete the cache directory.
|
|
166
|
+
|
|
91
167
|
## Development
|
|
92
168
|
|
|
93
|
-
|
|
94
|
-
analyzer; a missing toolchain leaves its language unanalyzed.
|
|
169
|
+
You need pnpm, Go 1.24 and a JDK 21+. A missing toolchain leaves its language unanalyzed.
|
|
95
170
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
pnpm
|
|
99
|
-
pnpm typecheck
|
|
100
|
-
pnpm lint
|
|
101
|
-
pnpm package # the npm package, into .pack/
|
|
102
|
-
```
|
|
171
|
+
Run `pnpm install`, then `pnpm test`, `pnpm typecheck` or `pnpm lint`.
|
|
172
|
+
|
|
173
|
+
`pnpm package` builds the npm package.
|
|
103
174
|
|
|
104
175
|
## License
|
|
105
176
|
|
|
106
|
-
Apache-2.0. See [LICENSE](LICENSE) and
|
|
177
|
+
Apache-2.0. See [LICENSE](https://github.com/coffeecoproject/layermap/blob/main/LICENSE) and
|
|
178
|
+
[NOTICE](https://github.com/coffeecoproject/layermap/blob/main/NOTICE).
|
|
Binary file
|
package/dist/cli.mjs
CHANGED
|
@@ -22394,7 +22394,13 @@ function serveMcp(options) {
|
|
|
22394
22394
|
title,
|
|
22395
22395
|
description,
|
|
22396
22396
|
inputSchema,
|
|
22397
|
-
annotations: {
|
|
22397
|
+
annotations: {
|
|
22398
|
+
title,
|
|
22399
|
+
readOnlyHint: true,
|
|
22400
|
+
destructiveHint: false,
|
|
22401
|
+
idempotentHint: true,
|
|
22402
|
+
openWorldHint: false
|
|
22403
|
+
}
|
|
22398
22404
|
}))
|
|
22399
22405
|
}
|
|
22400
22406
|
});
|
|
@@ -22436,6 +22442,8 @@ import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from
|
|
|
22436
22442
|
import { homedir as homedir2 } from "node:os";
|
|
22437
22443
|
import path9 from "node:path";
|
|
22438
22444
|
var SERVER = "layermap";
|
|
22445
|
+
var SETUP_RULE = `mcp__${SERVER}`;
|
|
22446
|
+
var PLUGIN_RULE = `mcp__plugin_${SERVER}_${SERVER}`;
|
|
22439
22447
|
var BEGIN = "<!-- layermap:begin -->";
|
|
22440
22448
|
var END = "<!-- layermap:end -->";
|
|
22441
22449
|
var mcpLaunchCommand = (version2) => {
|
|
@@ -22461,8 +22469,7 @@ var run = (command, args, env) => new Promise(
|
|
|
22461
22469
|
(error51, stdout, stderr) => resolve({ ok: !error51, output: `${stdout}${stderr}`.trim() })
|
|
22462
22470
|
)
|
|
22463
22471
|
);
|
|
22464
|
-
async function allowInClaudeSettings(file2) {
|
|
22465
|
-
const rule = `mcp__${SERVER}`;
|
|
22472
|
+
async function allowInClaudeSettings(file2, rule = SETUP_RULE) {
|
|
22466
22473
|
const settings = existsSync5(file2) ? JSON.parse(await readFile2(file2, "utf8")) : {};
|
|
22467
22474
|
if (typeof settings !== "object" || settings === null || Array.isArray(settings))
|
|
22468
22475
|
throw new Error(`${file2} is not a settings object.`);
|
|
@@ -22522,8 +22529,9 @@ async function disallowInClaudeSettings(file2) {
|
|
|
22522
22529
|
if (!existsSync5(file2)) return;
|
|
22523
22530
|
const settings = JSON.parse(await readFile2(file2, "utf8"));
|
|
22524
22531
|
const allow = settings?.permissions?.allow;
|
|
22525
|
-
|
|
22526
|
-
|
|
22532
|
+
const ours = (rule) => rule === SETUP_RULE || rule === PLUGIN_RULE;
|
|
22533
|
+
if (!Array.isArray(allow) || !allow.some(ours)) return;
|
|
22534
|
+
settings.permissions.allow = allow.filter((rule) => !ours(rule));
|
|
22527
22535
|
if (!settings.permissions.allow.length) delete settings.permissions.allow;
|
|
22528
22536
|
if (!Object.keys(settings.permissions).length) delete settings.permissions;
|
|
22529
22537
|
await writeFile2(file2, `${JSON.stringify(settings, null, 2)}
|
|
@@ -22562,7 +22570,7 @@ async function setupAgent(options) {
|
|
|
22562
22570
|
if (options.agent === "claude") {
|
|
22563
22571
|
const scope2 = ["--scope", options.scope];
|
|
22564
22572
|
log2(`claude mcp add ${scope2.join(" ")} ${SERVER} -- ${quoted.join(" ")}`);
|
|
22565
|
-
log2(`allow
|
|
22573
|
+
log2(`allow ${SETUP_RULE} in ${settings}`);
|
|
22566
22574
|
} else {
|
|
22567
22575
|
log2(`codex mcp add ${SERVER} -- ${quoted.join(" ")}`);
|
|
22568
22576
|
log2(`set default_tools_approval_mode = "approve" and tool_timeout_sec = 120 in ${settings}`);
|
|
@@ -22587,6 +22595,18 @@ async function setupAgent(options) {
|
|
|
22587
22595
|
);
|
|
22588
22596
|
return true;
|
|
22589
22597
|
}
|
|
22598
|
+
async function allowAgent(options) {
|
|
22599
|
+
if (options.agent !== "claude") {
|
|
22600
|
+
options.log("The Codex plugin already runs LayerMap's read-only tools without a prompt.");
|
|
22601
|
+
return true;
|
|
22602
|
+
}
|
|
22603
|
+
const { settings } = agentFiles(options);
|
|
22604
|
+
options.log(`allow ${PLUGIN_RULE} in ${settings}`);
|
|
22605
|
+
if (options.dryRun) return true;
|
|
22606
|
+
await allowInClaudeSettings(settings, PLUGIN_RULE);
|
|
22607
|
+
options.log("Done. Claude Code runs the LayerMap plugin's map tools without asking.");
|
|
22608
|
+
return true;
|
|
22609
|
+
}
|
|
22590
22610
|
async function removeAgent(options) {
|
|
22591
22611
|
const env = options.env ?? process.env;
|
|
22592
22612
|
const { settings, instructions } = agentFiles(options);
|
|
@@ -22606,6 +22626,8 @@ var USAGE = `LayerMap \u2014 a layered map of a codebase for coding agents.
|
|
|
22606
22626
|
|
|
22607
22627
|
Usage:
|
|
22608
22628
|
layermap setup claude|codex [--scope user|project|local] [--no-instructions] [--dry-run]
|
|
22629
|
+
layermap allow claude [--scope user|project|local] [--dry-run]
|
|
22630
|
+
let the plugin's read-only tools run without a prompt
|
|
22609
22631
|
layermap remove claude|codex [--scope user|project|local] [--dry-run]
|
|
22610
22632
|
layermap mcp [--project DIR] serve the map tools over MCP (stdio)
|
|
22611
22633
|
layermap index [--project DIR] build or update the map now
|
|
@@ -22669,11 +22691,11 @@ async function main(argv) {
|
|
|
22669
22691
|
);
|
|
22670
22692
|
return map3;
|
|
22671
22693
|
};
|
|
22672
|
-
if (command === "setup" || command === "remove") {
|
|
22694
|
+
if (command === "setup" || command === "allow" || command === "remove") {
|
|
22673
22695
|
const agent = rest[0];
|
|
22674
22696
|
if (agent !== "claude" && agent !== "codex") return usage(1);
|
|
22675
22697
|
if (!["user", "project", "local"].includes(values.scope)) return usage(1);
|
|
22676
|
-
const done = await
|
|
22698
|
+
const done = await { setup: setupAgent, allow: allowAgent, remove: removeAgent }[command]({
|
|
22677
22699
|
agent,
|
|
22678
22700
|
scope: values.scope,
|
|
22679
22701
|
project,
|
package/package.json
CHANGED