layermap 0.1.24 → 0.1.26
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 +6 -5
- package/analyzers/project-map-java/java-map.jar +0 -0
- package/analyzers/project-map-worker.mjs +17 -6
- package/dist/cli.mjs +600 -234
- package/dist/launcher.mjs +105 -0
- package/package.json +1 -1
- package/pi/layermap.mjs +29 -22
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Starts one LayerMap version's MCP server in this process. The version is installed once into
|
|
2
|
+
// LayerMap's cache, from where every later start runs without npm or a network. The agent starts
|
|
3
|
+
// this in the project, which stays the working directory the server maps; npm runs in the cache,
|
|
4
|
+
// so the project's own npm settings and packages play no part in what gets installed.
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
import {
|
|
7
|
+
existsSync,
|
|
8
|
+
mkdirSync,
|
|
9
|
+
mkdtempSync,
|
|
10
|
+
readFileSync,
|
|
11
|
+
renameSync,
|
|
12
|
+
rmSync,
|
|
13
|
+
writeFileSync,
|
|
14
|
+
} from "node:fs";
|
|
15
|
+
import { homedir } from "node:os";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import { pathToFileURL } from "node:url";
|
|
18
|
+
|
|
19
|
+
const VERSION = __VERSION__;
|
|
20
|
+
|
|
21
|
+
// The same directory as cacheDirectory in src/agent/environment.ts.
|
|
22
|
+
const env = process.env;
|
|
23
|
+
const cache = env.LAYERMAP_CACHE
|
|
24
|
+
? path.resolve(env.LAYERMAP_CACHE)
|
|
25
|
+
: process.platform === "darwin"
|
|
26
|
+
? path.join(homedir(), "Library", "Caches", "layermap")
|
|
27
|
+
: process.platform === "win32"
|
|
28
|
+
? path.join(env.LOCALAPPDATA || path.join(homedir(), "AppData", "Local"), "layermap", "Cache")
|
|
29
|
+
: path.join(env.XDG_CACHE_HOME || path.join(homedir(), ".cache"), "layermap");
|
|
30
|
+
const versions = path.join(cache, "versions");
|
|
31
|
+
const home = path.join(versions, VERSION);
|
|
32
|
+
const installed = path.join(home, "node_modules", "layermap");
|
|
33
|
+
const manifest = path.join(installed, "package.json");
|
|
34
|
+
|
|
35
|
+
// The npm of the Node running this, else the one on PATH.
|
|
36
|
+
const npm = () => {
|
|
37
|
+
const directory = path.dirname(process.execPath);
|
|
38
|
+
for (const cli of [
|
|
39
|
+
path.join(directory, "node_modules", "npm", "bin", "npm-cli.js"),
|
|
40
|
+
path.join(directory, "..", "lib", "node_modules", "npm", "bin", "npm-cli.js"),
|
|
41
|
+
])
|
|
42
|
+
if (existsSync(cli)) return [process.execPath, [cli]];
|
|
43
|
+
if (process.platform === "win32") throw new Error(`no npm beside ${process.execPath}`);
|
|
44
|
+
return ["npm", []];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// npm installs into a directory of its own, renamed into place once complete, so no server starts
|
|
48
|
+
// from half an install, and two starting at once both end up with the one that was renamed first.
|
|
49
|
+
// --prefer-online has npm ask the registry for the versions it has, which a cached list may lack.
|
|
50
|
+
async function install() {
|
|
51
|
+
mkdirSync(versions, { recursive: true, mode: 0o700 });
|
|
52
|
+
const staging = mkdtempSync(path.join(versions, `.${VERSION}-`));
|
|
53
|
+
process.stderr.write(`layermap: installing layermap@${VERSION} with npm\n`);
|
|
54
|
+
const [command, prefix] = npm();
|
|
55
|
+
const args = [
|
|
56
|
+
...prefix,
|
|
57
|
+
"install",
|
|
58
|
+
`layermap@${VERSION}`,
|
|
59
|
+
"--prefix",
|
|
60
|
+
staging,
|
|
61
|
+
"--prefer-online",
|
|
62
|
+
"--omit=dev",
|
|
63
|
+
"--no-audit",
|
|
64
|
+
"--no-fund",
|
|
65
|
+
"--no-update-notifier",
|
|
66
|
+
"--loglevel=error",
|
|
67
|
+
];
|
|
68
|
+
await new Promise((resolve, reject) => {
|
|
69
|
+
const child = spawn(command, args, {
|
|
70
|
+
cwd: staging,
|
|
71
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
72
|
+
windowsHide: true,
|
|
73
|
+
});
|
|
74
|
+
let output = "";
|
|
75
|
+
child.stdout.on("data", (data) => (output += data));
|
|
76
|
+
child.stderr.on("data", (data) => (output += data));
|
|
77
|
+
child.on("error", reject);
|
|
78
|
+
child.on("close", (code) =>
|
|
79
|
+
code === 0 ? resolve() : reject(new Error(`npm exited with ${code}\n${output.trim()}`)),
|
|
80
|
+
);
|
|
81
|
+
}).catch((error) => {
|
|
82
|
+
rmSync(staging, { recursive: true, force: true });
|
|
83
|
+
throw error;
|
|
84
|
+
});
|
|
85
|
+
try {
|
|
86
|
+
renameSync(staging, home);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
rmSync(staging, { recursive: true, force: true });
|
|
89
|
+
if (!existsSync(manifest)) throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
if (!existsSync(manifest)) await install();
|
|
95
|
+
// LayerMap removes a version from its cache once nothing has started it for a week.
|
|
96
|
+
writeFileSync(path.join(home, "last-used"), "");
|
|
97
|
+
const entry = path.join(installed, JSON.parse(readFileSync(manifest, "utf8")).bin.layermap);
|
|
98
|
+
process.argv = [process.argv[0], entry, "mcp"];
|
|
99
|
+
await import(pathToFileURL(entry).href);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
process.stderr.write(
|
|
102
|
+
`layermap: could not start LayerMap ${VERSION}: ${error?.message ?? error}\n`,
|
|
103
|
+
);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "layermap",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.26",
|
|
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",
|
package/pi/layermap.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// LayerMap for Pi. scripts/plugins.ts fills in the notes and writes plugins/pi/layermap.mjs, which
|
|
3
3
|
// the npm package ships as its Pi extension (`pi install npm:layermap`).
|
|
4
4
|
//
|
|
5
|
-
// The map runs in LayerMap's own MCP server, started with
|
|
5
|
+
// The map runs in LayerMap's own MCP server, started with Pi's Node in the session's directory; its
|
|
6
6
|
// tools become Pi tools of the same names. Like the Claude Code plugin's stop hook, the extension
|
|
7
7
|
// asks the agent once, before it settles, to check what its code edits affect.
|
|
8
8
|
import { execFile, spawn } from "node:child_process";
|
|
@@ -36,7 +36,7 @@ class MapServer {
|
|
|
36
36
|
constructor(cwd) {
|
|
37
37
|
this.pending = new Map();
|
|
38
38
|
this.next = 1;
|
|
39
|
-
this.child = spawn(
|
|
39
|
+
this.child = spawn(process.execPath, [CLI, "mcp"], {
|
|
40
40
|
cwd,
|
|
41
41
|
stdio: ["pipe", "pipe", "ignore"],
|
|
42
42
|
windowsHide: true,
|
|
@@ -108,6 +108,30 @@ const git = (cwd, args) =>
|
|
|
108
108
|
),
|
|
109
109
|
);
|
|
110
110
|
|
|
111
|
+
// Git in a repository with no program its own config names: no fsmonitor, and no filter its
|
|
112
|
+
// attributes would put a changed file's content through.
|
|
113
|
+
async function repositoryGit(repository, args) {
|
|
114
|
+
const drivers = new Set(
|
|
115
|
+
(await git(repository, ["config", "--name-only", "--get-regexp", "^filter\\."]))
|
|
116
|
+
.split("\n")
|
|
117
|
+
.flatMap((key) => /^filter\.(.+)\.[^.]+$/su.exec(key)?.[1] ?? []),
|
|
118
|
+
);
|
|
119
|
+
const blank = [...drivers].flatMap((driver) =>
|
|
120
|
+
["clean=", "process=", "required=false"].flatMap((setting) => [
|
|
121
|
+
"-c",
|
|
122
|
+
`filter.${driver}.${setting}`,
|
|
123
|
+
]),
|
|
124
|
+
);
|
|
125
|
+
return git(repository, [
|
|
126
|
+
"-c",
|
|
127
|
+
"core.fsmonitor=false",
|
|
128
|
+
"-c",
|
|
129
|
+
"core.quotePath=false",
|
|
130
|
+
...blank,
|
|
131
|
+
...args,
|
|
132
|
+
]);
|
|
133
|
+
}
|
|
134
|
+
|
|
111
135
|
// The Git repository around a path, or the nearest directory of it that exists; empty outside one.
|
|
112
136
|
async function repositoryAt(given) {
|
|
113
137
|
let directory = given;
|
|
@@ -141,25 +165,8 @@ async function changedCode(repository) {
|
|
|
141
165
|
const changed = new Map();
|
|
142
166
|
if (!(await git(repository, ["rev-parse", "--verify", "--quiet", "HEAD"]))) return changed;
|
|
143
167
|
const listed = await Promise.all([
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
"core.quotePath=false",
|
|
147
|
-
"diff",
|
|
148
|
-
"HEAD",
|
|
149
|
-
"--name-only",
|
|
150
|
-
"--no-renames",
|
|
151
|
-
"--",
|
|
152
|
-
...CODE_GLOBS,
|
|
153
|
-
]),
|
|
154
|
-
git(repository, [
|
|
155
|
-
"-c",
|
|
156
|
-
"core.quotePath=false",
|
|
157
|
-
"ls-files",
|
|
158
|
-
"--others",
|
|
159
|
-
"--exclude-standard",
|
|
160
|
-
"--",
|
|
161
|
-
...CODE_GLOBS,
|
|
162
|
-
]),
|
|
168
|
+
repositoryGit(repository, ["diff", "HEAD", "--name-only", "--no-renames", "--", ...CODE_GLOBS]),
|
|
169
|
+
repositoryGit(repository, ["ls-files", "--others", "--exclude-standard", "--", ...CODE_GLOBS]),
|
|
163
170
|
]);
|
|
164
171
|
const files = [...new Set(listed.join("\n").split("\n").filter(Boolean))].sort();
|
|
165
172
|
for (const file of files) {
|
|
@@ -228,7 +235,7 @@ export default function layermap(pi) {
|
|
|
228
235
|
if (server && !server.dead) return server;
|
|
229
236
|
starting ??= (async () => {
|
|
230
237
|
const next = new MapServer(cwd);
|
|
231
|
-
const tools = await next.start("0.1.
|
|
238
|
+
const tools = await next.start("0.1.26");
|
|
232
239
|
for (const tool of tools) {
|
|
233
240
|
if (registered.has(tool.name)) continue;
|
|
234
241
|
registered.add(tool.name);
|