layermap 0.1.15 → 0.1.17
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 +22 -6
- package/analyzers/project-map-java/java-map.jar +0 -0
- package/dist/cli.mjs +31 -19
- package/package.json +18 -3
- package/pi/layermap.mjs +203 -0
package/README.md
CHANGED
|
@@ -16,8 +16,8 @@
|
|
|
16
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
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
18
|
|
|
19
|
-
A layered map of your codebase for coding agents. LayerMap gives Claude Code, Codex,
|
|
20
|
-
Harness and other MCP clients read-only tools that answer, in one call, what an agent otherwise works out
|
|
19
|
+
A layered map of your codebase for coding agents. LayerMap gives Claude Code, Codex, CodeBuddy
|
|
20
|
+
Code, Pi, DeepSeek Harness and other MCP clients read-only tools that answer, in one call, what an agent otherwise works out
|
|
21
21
|
with dozens of searches:
|
|
22
22
|
|
|
23
23
|
- **What calls this, and what does changing it affect?** Callers traced up to 8 levels, to the
|
|
@@ -119,6 +119,19 @@ codex plugin marketplace add coffeecoproject/layermap
|
|
|
119
119
|
codex plugin add layermap@layermap
|
|
120
120
|
```
|
|
121
121
|
|
|
122
|
+
**CodeBuddy Code**
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
codebuddy plugin marketplace add coffeecoproject/layermap
|
|
126
|
+
codebuddy plugin install layermap@layermap
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Pi**
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
pi install npm:layermap
|
|
133
|
+
```
|
|
134
|
+
|
|
122
135
|
**DeepSeek Harness**
|
|
123
136
|
|
|
124
137
|
```
|
|
@@ -142,10 +155,11 @@ a change meant for one feature does not quietly change the others. Environment v
|
|
|
142
155
|
configuration keys are linked by name only, which no compiler sees, so when the diff removes one
|
|
143
156
|
from a file, the check names the files that still read or set the old name. In the same way, when
|
|
144
157
|
the change reaches a route's handler or renames a route, it names the code and templates that
|
|
145
|
-
request that path: a frontend's fetch, a generated API client, a redirect or a link. It never writes or runs tests. In Claude Code
|
|
146
|
-
plugin asks the agent once, before it finishes, to run this check if it edited code in the repository
|
|
147
|
-
and has not checked since (changes another session makes in the same work tree do not count);
|
|
148
|
-
|
|
158
|
+
request that path: a frontend's fetch, a generated API client, a redirect or a link. It never writes or runs tests. In Claude Code and
|
|
159
|
+
CodeBuddy Code the plugin asks the agent once, before it finishes, to run this check if it edited code in the repository
|
|
160
|
+
and has not checked since (changes another session makes in the same work tree do not count); the
|
|
161
|
+
Pi extension does the same after the agent's own edits. Set `LAYERMAP_STOP_CHECK=0` to turn that
|
|
162
|
+
off. Codex and DeepSeek Harness are told to run it.
|
|
149
163
|
|
|
150
164
|
**Without plugins:** run `npx layermap setup claude` or `npx layermap setup codex`. Setup does three
|
|
151
165
|
things:
|
|
@@ -220,6 +234,8 @@ claude -p "..." --mcp-config '{"mcpServers":{"layermap":{"command":"npx","args":
|
|
|
220
234
|
|
|
221
235
|
- Claude Code: `/plugin uninstall layermap@layermap`.
|
|
222
236
|
- Codex: `codex plugin remove layermap@layermap`.
|
|
237
|
+
- CodeBuddy Code: `codebuddy plugin uninstall layermap@layermap`.
|
|
238
|
+
- Pi: `pi remove npm:layermap`.
|
|
223
239
|
- Then delete the cache directory.
|
|
224
240
|
|
|
225
241
|
## Development
|
|
Binary file
|
package/dist/cli.mjs
CHANGED
|
@@ -22606,11 +22606,10 @@ function mapChangeImpact(store, working, base, changes, project) {
|
|
|
22606
22606
|
if (file2.status !== "DELETED") tracer.test(file2.path, void 0, "changed in this diff", 1);
|
|
22607
22607
|
continue;
|
|
22608
22608
|
}
|
|
22609
|
-
|
|
22610
|
-
|
|
22611
|
-
|
|
22612
|
-
|
|
22613
|
-
}
|
|
22609
|
+
const analyzed = objects2.length > 0 && mapLanguageOf(file2.path) !== void 0;
|
|
22610
|
+
if (!analyzed && file2.status !== "DELETED" && kind)
|
|
22611
|
+
unclear.push(`${file2.path} changed (${kind}): its effects are not mapped`);
|
|
22612
|
+
if (!objects2.length) continue;
|
|
22614
22613
|
const hits = /* @__PURE__ */ new Set();
|
|
22615
22614
|
let topLevel = false;
|
|
22616
22615
|
const inFile = declarations(graph, file2.path);
|
|
@@ -22641,7 +22640,7 @@ function mapChangeImpact(store, working, base, changes, project) {
|
|
|
22641
22640
|
unclear.push(
|
|
22642
22641
|
`the registration of ${JSON.stringify(relation.argument)} at ${relation.anchor.path}:${relation.anchor.startLine} changed; check that the route still reaches the right handler`
|
|
22643
22642
|
);
|
|
22644
|
-
if (topLevel && file2.status !== "ADDED")
|
|
22643
|
+
if (analyzed && topLevel && file2.status !== "ADDED")
|
|
22645
22644
|
unclear.push(`top-level code of ${file2.path} changed (imports, constants or registrations)`);
|
|
22646
22645
|
importerTests(graph, objects2, tracer);
|
|
22647
22646
|
sameDirectoryTests(store, working, file2.path, tracer);
|
|
@@ -22887,6 +22886,22 @@ function routesIn(graph, path13) {
|
|
|
22887
22886
|
return routes;
|
|
22888
22887
|
}
|
|
22889
22888
|
var routePath = (route) => route.slice(route.indexOf("/"));
|
|
22889
|
+
async function checkMapChanges(input, signal) {
|
|
22890
|
+
const { index, project, working } = input;
|
|
22891
|
+
const changes = await readMapChanges(project, input.base, signal);
|
|
22892
|
+
await index.ensureIndex(working, signal);
|
|
22893
|
+
const base = changes.files.some(
|
|
22894
|
+
(file2) => file2.basePath !== void 0 && (file2.baseLines.length || file2.baseText !== void 0)
|
|
22895
|
+
) ? await input.baseVersion(changes.commit, signal) : void 0;
|
|
22896
|
+
const impact = mapChangeImpact(index.store, working, base, changes, project);
|
|
22897
|
+
return {
|
|
22898
|
+
text: mapChangesText(
|
|
22899
|
+
changes,
|
|
22900
|
+
impact,
|
|
22901
|
+
await mapRouteClients(project, index.store, working, impact, signal)
|
|
22902
|
+
)
|
|
22903
|
+
};
|
|
22904
|
+
}
|
|
22890
22905
|
async function mapRouteClients(project, store, working, impact, signal) {
|
|
22891
22906
|
const affected = impact.entries.filter(
|
|
22892
22907
|
(entry) => entry.route && entry.certain && entry.chain.length <= 2
|
|
@@ -23176,19 +23191,16 @@ var LayerMap = class _LayerMap {
|
|
|
23176
23191
|
* see. The base commit's map is built only when the diff removes or changes lines there.
|
|
23177
23192
|
*/
|
|
23178
23193
|
async checkChanges(input, signal) {
|
|
23179
|
-
|
|
23180
|
-
|
|
23181
|
-
|
|
23182
|
-
|
|
23183
|
-
|
|
23184
|
-
|
|
23185
|
-
|
|
23186
|
-
|
|
23187
|
-
|
|
23188
|
-
|
|
23189
|
-
await mapRouteClients(this.project, this.store, working, impact, signal)
|
|
23190
|
-
)
|
|
23191
|
-
};
|
|
23194
|
+
return checkMapChanges(
|
|
23195
|
+
{
|
|
23196
|
+
index: this.index,
|
|
23197
|
+
project: this.project,
|
|
23198
|
+
working: await this.refresh(signal),
|
|
23199
|
+
base: input.base ?? "HEAD",
|
|
23200
|
+
baseVersion: (commit, baseSignal) => this.versionAt(commit, baseSignal)
|
|
23201
|
+
},
|
|
23202
|
+
signal
|
|
23203
|
+
);
|
|
23192
23204
|
}
|
|
23193
23205
|
/**
|
|
23194
23206
|
* Builds the map of a base commit (HEAD by default) ahead of a change check, so the check after an
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "layermap",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"mcpName": "io.github.coffeecoproject/layermap",
|
|
5
5
|
"description": "A layered map of a codebase for coding agents: directories, modules and call chains across TypeScript, JavaScript, Go, Python and Java.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"files": [
|
|
12
12
|
"dist",
|
|
13
13
|
"analyzers",
|
|
14
|
+
"pi",
|
|
14
15
|
"LICENSE",
|
|
15
16
|
"NOTICE",
|
|
16
17
|
"README.md"
|
|
@@ -38,6 +39,20 @@
|
|
|
38
39
|
"impact-analysis",
|
|
39
40
|
"mcp",
|
|
40
41
|
"claude-code",
|
|
41
|
-
"codex"
|
|
42
|
-
|
|
42
|
+
"codex",
|
|
43
|
+
"pi-package"
|
|
44
|
+
],
|
|
45
|
+
"pi": {
|
|
46
|
+
"extensions": [
|
|
47
|
+
"./pi/layermap.mjs"
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"typebox": "*"
|
|
52
|
+
},
|
|
53
|
+
"peerDependenciesMeta": {
|
|
54
|
+
"typebox": {
|
|
55
|
+
"optional": true
|
|
56
|
+
}
|
|
57
|
+
}
|
|
43
58
|
}
|
package/pi/layermap.mjs
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
// Generated by scripts/plugins.ts from scripts/pi-extension.mjs.
|
|
2
|
+
// LayerMap for Pi. scripts/plugins.ts fills in the notes and writes plugins/pi/layermap.mjs, which
|
|
3
|
+
// the npm package ships as its Pi extension (`pi install npm:layermap`).
|
|
4
|
+
//
|
|
5
|
+
// The map runs in LayerMap's own MCP server, started with node in the session's directory; its
|
|
6
|
+
// tools become Pi tools of the same names. Like the Claude Code plugin's stop hook, the extension
|
|
7
|
+
// asks the agent once, before it settles, to check what its code edits affect.
|
|
8
|
+
import { execFile, spawn } from "node:child_process";
|
|
9
|
+
import { createHash } from "node:crypto";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { createInterface } from "node:readline";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
import { Type } from "typebox";
|
|
14
|
+
|
|
15
|
+
const MAP_NOTE = "The layermap MCP server is available here. When a task needs to know what calls a function, what a change could affect beyond the code you are editing, or where code is used, use its project_explore_map tool (direction INCOMING, depth up to 8) instead of grep, then confirm in source; a change confined to code you have read does not need it. When the edits are done, call its project_check_changes tool once before reporting the work done.";
|
|
16
|
+
const STOP_CHECK = "Code changed in this session. Before finishing, call the LayerMap tool project_check_changes: it lists the routes, jobs and commands the changes reach and the existing tests related to them. Check the affected entry points in source, and run the related tests if the change needs verifying. If it lists EXISTING TESTS CHANGED or code SHARED BY several areas, decide which of them the request is about; for the others, restore their tests and narrow the change. If you already checked these changes, say so briefly and finish.";
|
|
17
|
+
const CHECK_TOOL = "project_check_changes";
|
|
18
|
+
const CLI = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "dist", "cli.mjs");
|
|
19
|
+
// Tools that only read; any other tool call (edit, write, apply_patch, bash, …) may change files.
|
|
20
|
+
const READS = new Set(["read", "grep", "find", "ls"]);
|
|
21
|
+
const CODE_GLOBS = ["ts", "tsx", "mts", "cts", "js", "jsx", "mjs", "cjs", "go", "py", "java"].map(
|
|
22
|
+
(e) => `*.${e}`,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// LayerMap's MCP server over stdio: one JSON-RPC message per line.
|
|
26
|
+
class MapServer {
|
|
27
|
+
constructor(cwd) {
|
|
28
|
+
this.pending = new Map();
|
|
29
|
+
this.next = 1;
|
|
30
|
+
this.child = spawn("node", [CLI, "mcp"], {
|
|
31
|
+
cwd,
|
|
32
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
33
|
+
windowsHide: true,
|
|
34
|
+
});
|
|
35
|
+
this.exited = new Promise((resolve) => this.child.once("exit", resolve));
|
|
36
|
+
this.child.once("error", (error) => this.fail(error));
|
|
37
|
+
this.child.once("exit", () => this.fail(new Error("The LayerMap server stopped.")));
|
|
38
|
+
createInterface({ input: this.child.stdout }).on("line", (line) => {
|
|
39
|
+
let message;
|
|
40
|
+
try {
|
|
41
|
+
message = JSON.parse(line);
|
|
42
|
+
} catch {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const waiter = this.pending.get(message.id);
|
|
46
|
+
if (!waiter) return;
|
|
47
|
+
this.pending.delete(message.id);
|
|
48
|
+
if (message.error) waiter.reject(new Error(message.error.message));
|
|
49
|
+
else waiter.resolve(message.result);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
fail(error) {
|
|
53
|
+
for (const waiter of this.pending.values()) waiter.reject(error);
|
|
54
|
+
this.pending.clear();
|
|
55
|
+
this.dead = true;
|
|
56
|
+
}
|
|
57
|
+
send(message) {
|
|
58
|
+
this.child.stdin.write(`${JSON.stringify({ jsonrpc: "2.0", ...message })}\n`);
|
|
59
|
+
}
|
|
60
|
+
request(method, params, signal) {
|
|
61
|
+
if (this.dead) return Promise.reject(new Error("The LayerMap server is not running."));
|
|
62
|
+
const id = this.next++;
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
this.pending.set(id, { resolve, reject });
|
|
65
|
+
signal?.addEventListener(
|
|
66
|
+
"abort",
|
|
67
|
+
() => {
|
|
68
|
+
if (!this.pending.delete(id)) return;
|
|
69
|
+
this.send({ method: "notifications/cancelled", params: { requestId: id } });
|
|
70
|
+
reject(new Error("Cancelled."));
|
|
71
|
+
},
|
|
72
|
+
{ once: true },
|
|
73
|
+
);
|
|
74
|
+
this.send({ id, method, params });
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async start(version) {
|
|
78
|
+
await this.request("initialize", {
|
|
79
|
+
protocolVersion: "2025-06-18",
|
|
80
|
+
capabilities: {},
|
|
81
|
+
clientInfo: { name: "layermap-pi", version },
|
|
82
|
+
});
|
|
83
|
+
// The server starts building the map as soon as it is told the client is ready.
|
|
84
|
+
this.send({ method: "notifications/initialized" });
|
|
85
|
+
return (await this.request("tools/list", {})).tools;
|
|
86
|
+
}
|
|
87
|
+
async stop() {
|
|
88
|
+
this.child.stdin.end();
|
|
89
|
+
const timer = setTimeout(() => this.child.kill(), 3000);
|
|
90
|
+
await this.exited;
|
|
91
|
+
clearTimeout(timer);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const git = (cwd, args) =>
|
|
96
|
+
new Promise((resolve) =>
|
|
97
|
+
execFile("git", ["-C", cwd, ...args], { maxBuffer: 64 * 1024 * 1024 }, (error, stdout) =>
|
|
98
|
+
resolve(error ? "" : stdout),
|
|
99
|
+
),
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// The uncommitted code changes as one hash, empty when there are none or no repository.
|
|
103
|
+
async function codeChanges(cwd) {
|
|
104
|
+
if (!(await git(cwd, ["rev-parse", "--verify", "--quiet", "HEAD"]))) return "";
|
|
105
|
+
const diff = await git(cwd, ["diff", "HEAD", "--no-ext-diff", "--no-color", "--", ...CODE_GLOBS]);
|
|
106
|
+
const untracked = (
|
|
107
|
+
await git(cwd, ["ls-files", "--others", "--exclude-standard", "--", ...CODE_GLOBS])
|
|
108
|
+
).trim();
|
|
109
|
+
const listed = untracked ? await git(cwd, ["hash-object", "--", ...untracked.split("\n")]) : "";
|
|
110
|
+
if (!diff && !untracked) return "";
|
|
111
|
+
return createHash("sha256").update(diff).update(untracked).update(listed).digest("hex");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default function layermap(pi) {
|
|
115
|
+
let server;
|
|
116
|
+
let starting;
|
|
117
|
+
let cwd;
|
|
118
|
+
const registered = new Set();
|
|
119
|
+
// The stop check compares the uncommitted code changes with those the session began with, those
|
|
120
|
+
// the agent last checked and those it was last asked about. It asks only when the agent used a
|
|
121
|
+
// tool that can change files, so changes another session makes while this one reads do not count.
|
|
122
|
+
let startChanges = "";
|
|
123
|
+
let checkedChanges = "";
|
|
124
|
+
let askedAbout = "";
|
|
125
|
+
let mayHaveEdited = false;
|
|
126
|
+
|
|
127
|
+
const ensureServer = async () => {
|
|
128
|
+
if (server && !server.dead) return server;
|
|
129
|
+
starting ??= (async () => {
|
|
130
|
+
const next = new MapServer(cwd);
|
|
131
|
+
const tools = await next.start("0.1.17");
|
|
132
|
+
for (const tool of tools) {
|
|
133
|
+
if (registered.has(tool.name)) continue;
|
|
134
|
+
registered.add(tool.name);
|
|
135
|
+
pi.registerTool({
|
|
136
|
+
name: tool.name,
|
|
137
|
+
label: tool.title ?? tool.name,
|
|
138
|
+
description: tool.description,
|
|
139
|
+
promptSnippet: tool.title,
|
|
140
|
+
promptGuidelines: tool.name === "project_explore_map" ? [MAP_NOTE] : [],
|
|
141
|
+
parameters: Type.Unsafe(tool.inputSchema),
|
|
142
|
+
async execute(_id, params, signal) {
|
|
143
|
+
const running = await ensureServer();
|
|
144
|
+
const result = await running.request(
|
|
145
|
+
"tools/call",
|
|
146
|
+
{ name: tool.name, arguments: params ?? {} },
|
|
147
|
+
signal,
|
|
148
|
+
);
|
|
149
|
+
const text = (result.content ?? []).map((part) => part.text ?? "").join("\n");
|
|
150
|
+
if (result.isError) throw new Error(text);
|
|
151
|
+
if (tool.name === CHECK_TOOL) checkedChanges = await codeChanges(cwd);
|
|
152
|
+
return { content: [{ type: "text", text }], details: {} };
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
server = next;
|
|
157
|
+
return next;
|
|
158
|
+
})().finally(() => {
|
|
159
|
+
starting = undefined;
|
|
160
|
+
});
|
|
161
|
+
return starting;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
165
|
+
cwd = ctx.cwd;
|
|
166
|
+
startChanges = await codeChanges(cwd);
|
|
167
|
+
checkedChanges = "";
|
|
168
|
+
askedAbout = "";
|
|
169
|
+
mayHaveEdited = false;
|
|
170
|
+
await ensureServer().catch((error) =>
|
|
171
|
+
ctx.ui?.notify?.(`LayerMap could not start: ${error.message}`, "warning"),
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
pi.on("tool_call", async (event) => {
|
|
176
|
+
if (!READS.has(event.toolName) && !registered.has(event.toolName)) mayHaveEdited = true;
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
pi.on("agent_before_settle", async (event) => {
|
|
180
|
+
if (process.env.LAYERMAP_STOP_CHECK === "0" || !mayHaveEdited || !cwd) return;
|
|
181
|
+
const changes = await codeChanges(cwd);
|
|
182
|
+
if (!changes || [startChanges, checkedChanges, askedAbout].includes(changes)) return;
|
|
183
|
+
askedAbout = changes;
|
|
184
|
+
return {
|
|
185
|
+
entries: [
|
|
186
|
+
...event.entries,
|
|
187
|
+
{
|
|
188
|
+
type: "custom_message",
|
|
189
|
+
customType: "layermap-check",
|
|
190
|
+
content: STOP_CHECK,
|
|
191
|
+
display: false,
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
continue: true,
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
pi.on("session_shutdown", async () => {
|
|
199
|
+
const running = server;
|
|
200
|
+
server = undefined;
|
|
201
|
+
await running?.stop();
|
|
202
|
+
});
|
|
203
|
+
}
|