layermap 0.1.34 → 0.1.36

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/dist/cli.mjs CHANGED
@@ -12,7 +12,6 @@ import path16 from "node:path";
12
12
  import { parseArgs } from "node:util";
13
13
 
14
14
  // src/agent/environment.ts
15
- import { execFile } from "node:child_process";
16
15
  import { createHash as createHash6 } from "node:crypto";
17
16
  import { existsSync as existsSync6, readFileSync as readFileSync5 } from "node:fs";
18
17
  import { mkdir, readdir, readFile as readFile2, rename, rm, stat, utimes, writeFile } from "node:fs/promises";
@@ -21,20 +20,6 @@ import { homedir } from "node:os";
21
20
  import path13 from "node:path";
22
21
  import { fileURLToPath } from "node:url";
23
22
 
24
- // src/layermap.ts
25
- import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypto";
26
- import { mkdirSync, statSync } from "node:fs";
27
- import { lstat as lstat3, realpath as realpath2 } from "node:fs/promises";
28
- import path12 from "node:path";
29
- import { DatabaseSync } from "@photostructure/sqlite";
30
-
31
- // src/capture-policy.ts
32
- import path3 from "node:path";
33
-
34
- // src/file-universe.ts
35
- import { lstat } from "node:fs/promises";
36
- import path2 from "node:path";
37
-
38
23
  // src/git-runner.ts
39
24
  import { spawn } from "node:child_process";
40
25
 
@@ -301,7 +286,19 @@ var GitRunner = class {
301
286
  }
302
287
  };
303
288
 
289
+ // src/layermap.ts
290
+ import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypto";
291
+ import { mkdirSync, statSync } from "node:fs";
292
+ import { lstat as lstat3, realpath as realpath2 } from "node:fs/promises";
293
+ import path12 from "node:path";
294
+ import { DatabaseSync } from "@photostructure/sqlite";
295
+
296
+ // src/capture-policy.ts
297
+ import path3 from "node:path";
298
+
304
299
  // src/file-universe.ts
300
+ import { lstat } from "node:fs/promises";
301
+ import path2 from "node:path";
305
302
  var FILE_UNIVERSE_ARGS = Object.freeze([
306
303
  "ls-files",
307
304
  "-z",
@@ -16772,6 +16769,9 @@ var mapQuerySelection = (input, knownKinds) => {
16772
16769
  return { path: path17, kinds: [...new Set(kinds)].sort() };
16773
16770
  };
16774
16771
  var mapQueryPathMatches = (path17, prefix) => prefix === "." || path17 === prefix || path17.startsWith(`${prefix}/`);
16772
+ var MAP_RELATION_TARGET_JOIN = `LEFT JOIN project_map_unit_objects t ON t.entity_ref = r.to_ref
16773
+ AND EXISTS (SELECT 1 FROM project_map_version_units target
16774
+ WHERE target.version_ref = r.version_ref AND target.unit_ref = t.unit_ref AND target.path = t.path)`;
16775
16775
  var mapQueryPathSql = (column) => `(? = '.' OR ${column} = ? OR substr(${column}, 1, length(?) + 1) = ? || '/')`;
16776
16776
 
16777
16777
  // src/project-map-search-focus.ts
@@ -17003,7 +17003,7 @@ function mapSearchRows(store, input, query, scope, offset, signal) {
17003
17003
  )
17004
17004
  SELECT object.object_json,
17005
17005
  (SELECT count(*) FROM project_map_relations r
17006
- LEFT JOIN project_map_objects t ON t.version_ref = r.version_ref AND t.entity_ref = r.to_ref
17006
+ ${MAP_RELATION_TARGET_JOIN}
17007
17007
  WHERE r.version_ref = object.version_ref AND r.from_ref = object.entity_ref
17008
17008
  AND ${mapSearchAllowedSql("r.path")}
17009
17009
  AND (r.to_ref IS NULL OR ${mapSearchAllowedSql("t.path")})) +
@@ -17122,25 +17122,17 @@ async function mapExploreTraversal(store, input, signal) {
17122
17122
  assertActive();
17123
17123
  };
17124
17124
  await checkpoint();
17125
- const statement = store.database.prepare(`
17125
+ const relations = (seeded, order) => store.database.prepare(`
17126
17126
  SELECT r.relation_ref, r.from_ref, r.to_ref, json_extract(r.relation_json, '$.kind') AS kind
17127
17127
  FROM project_map_relations r
17128
17128
  JOIN project_map_objects f ON f.version_ref = r.version_ref AND f.entity_ref = r.from_ref
17129
- LEFT JOIN project_map_objects t ON t.version_ref = r.version_ref AND t.entity_ref = r.to_ref
17129
+ ${MAP_RELATION_TARGET_JOIN}
17130
17130
  WHERE r.version_ref = ? AND ${allowed("r.path")} AND ${allowed("f.path")}
17131
17131
  AND (r.to_ref IS NULL OR ${allowed("t.path")})
17132
17132
  AND ${mapQueryPathSql("r.path")}
17133
17133
  AND json_extract(r.relation_json, '$.kind') IN (SELECT value FROM json_each(?))
17134
- ${input.scope === "PROJECT" ? `ORDER BY ${relationOrder}` : ""}`);
17135
- const relationRefs = [];
17136
- const adjacency = /* @__PURE__ */ new Map();
17137
- const connect = (ref, edge) => {
17138
- const existing = adjacency.get(ref);
17139
- if (existing) existing.push(edge);
17140
- else adjacency.set(ref, [edge]);
17141
- };
17142
- let inspected = 0;
17143
- for (const row of statement.iterate(
17134
+ ${seeded} ${order}`);
17135
+ const filters = [
17144
17136
  input.version,
17145
17137
  input.authorizationScope,
17146
17138
  input.authorizationScope,
@@ -17150,29 +17142,22 @@ async function mapExploreTraversal(store, input, signal) {
17150
17142
  input.selection.path,
17151
17143
  input.selection.path,
17152
17144
  canonicalJson(input.selection.kinds)
17153
- )) {
17154
- if (++inspected % 256 === 0) await checkpoint();
17155
- const relation = {
17156
- id: String(row.relation_ref),
17157
- from: String(row.from_ref),
17158
- ...row.to_ref === null ? {} : { to: String(row.to_ref) },
17159
- kind: row.kind
17160
- };
17161
- if (input.scope === "PROJECT") {
17162
- relationRefs.push(relation.id);
17163
- continue;
17164
- }
17165
- if (input.direction !== "INCOMING") connect(relation.from, relation);
17166
- if (input.direction !== "OUTGOING" && relation.to && relation.to !== relation.from)
17167
- connect(relation.to, relation);
17168
- else if (input.direction === "INCOMING" && relation.to === relation.from)
17169
- connect(relation.to, relation);
17170
- }
17145
+ ];
17146
+ const relationRefs = [];
17147
+ let inspected = 0;
17171
17148
  if (input.scope === "PROJECT") {
17149
+ for (const row of relations("", `ORDER BY ${relationOrder}`).iterate(...filters)) {
17150
+ if (++inspected % 256 === 0) await checkpoint();
17151
+ relationRefs.push(String(row.relation_ref));
17152
+ }
17172
17153
  assertActive();
17173
17154
  return { relationRefs, frontier: [] };
17174
17155
  }
17175
17156
  if (!input.entityRef) throw new ProjectEvidenceError("PROJECT_READ_INPUT_INVALID", false);
17157
+ const ends = [
17158
+ ...input.direction === "INCOMING" ? [] : ["r.from_ref"],
17159
+ ...input.direction === "OUTGOING" ? [] : ["r.to_ref"]
17160
+ ].map((end) => relations(`AND ${end} IN (SELECT value FROM json_each(?))`, ""));
17176
17161
  const known = /* @__PURE__ */ new Set([input.entityRef]);
17177
17162
  const seenRelations = /* @__PURE__ */ new Set();
17178
17163
  const frontier = [];
@@ -17182,10 +17167,18 @@ async function mapExploreTraversal(store, input, signal) {
17182
17167
  await checkpoint();
17183
17168
  depth++;
17184
17169
  const candidates = /* @__PURE__ */ new Map();
17185
- for (const ref of seeds) {
17186
- for (const edge of adjacency.get(ref) ?? []) {
17170
+ const seedRefs = canonicalJson(seeds);
17171
+ for (const end of ends) {
17172
+ for (const row of end.iterate(...filters, seedRefs)) {
17187
17173
  if (++inspected % 256 === 0) await checkpoint();
17188
- if (!seenRelations.has(edge.id)) candidates.set(edge.id, edge);
17174
+ const id2 = String(row.relation_ref);
17175
+ if (seenRelations.has(id2)) continue;
17176
+ candidates.set(id2, {
17177
+ id: id2,
17178
+ from: String(row.from_ref),
17179
+ ...row.to_ref === null ? {} : { to: String(row.to_ref) },
17180
+ kind: row.kind
17181
+ });
17189
17182
  }
17190
17183
  }
17191
17184
  const next = [];
@@ -19330,7 +19323,7 @@ function loadImports(store, version2) {
19330
19323
  return store.database.prepare(`SELECT r.path AS source, t.path AS target,
19331
19324
  json_extract(r.relation_json, '$.target') AS specifier, count(*) AS count
19332
19325
  FROM project_map_relations r NOT INDEXED
19333
- LEFT JOIN project_map_objects t ON t.version_ref = r.version_ref AND t.entity_ref = r.to_ref
19326
+ ${MAP_RELATION_TARGET_JOIN}
19334
19327
  WHERE r.version_ref = ? AND json_extract(r.relation_json, '$.kind') IN ('IMPORTS', 'TEST_IMPORTS')
19335
19328
  GROUP BY source, target, specifier`).all(version2).map((row) => ({
19336
19329
  source: String(row.source),
@@ -24947,16 +24940,17 @@ var cacheDirectory = (env = process.env) => {
24947
24940
  );
24948
24941
  return path13.join(env.XDG_CACHE_HOME || path13.join(homedir(), ".cache"), "layermap");
24949
24942
  };
24950
- var projectDirectory = (directory) => new Promise(
24951
- (resolve) => execFile(
24952
- "git",
24953
- ["rev-parse", "--show-toplevel"],
24954
- { cwd: directory, timeout: 1e4 },
24955
- (error51, stdout) => resolve(
24956
- error51 ? { directory: path13.resolve(directory), git: false } : { directory: stdout.trim(), git: true }
24957
- )
24958
- )
24959
- );
24943
+ var projectDirectory = async (directory) => {
24944
+ try {
24945
+ const { stdout } = await new GitRunner().run(["rev-parse", "--show-toplevel"], {
24946
+ cwd: directory,
24947
+ timeoutMs: 1e4
24948
+ });
24949
+ return { directory: stdout.toString().trim(), git: true };
24950
+ } catch {
24951
+ return { directory: path13.resolve(directory), git: false };
24952
+ }
24953
+ };
24960
24954
  var relativeTo = (directory, value) => Object.fromEntries(
24961
24955
  Object.entries(value).map(([language, resources]) => [
24962
24956
  language,
@@ -25557,7 +25551,7 @@ ${text}` : text
25557
25551
  }
25558
25552
 
25559
25553
  // src/agent/setup.ts
25560
- import { execFile as execFile2 } from "node:child_process";
25554
+ import { execFile } from "node:child_process";
25561
25555
  import { existsSync as existsSync8 } from "node:fs";
25562
25556
  import { mkdir as mkdir2, readFile as readFile3, rename as rename2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
25563
25557
  import { homedir as homedir2 } from "node:os";
@@ -25587,7 +25581,7 @@ var mcpLaunchCommand = (env = process.env, published = existsSync8(PUBLISHED_LAU
25587
25581
  };
25588
25582
  var run = (command, args, env) => new Promise((resolve) => {
25589
25583
  const invocation = commandInvocation(command, args, env);
25590
- execFile2(
25584
+ execFile(
25591
25585
  invocation.file,
25592
25586
  invocation.args,
25593
25587
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "layermap",
3
- "version": "0.1.34",
3
+ "version": "0.1.36",
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
@@ -1,7 +1,7 @@
1
1
  // Generated by scripts/plugins.ts from scripts/pi-extension.mjs.
2
2
  // scripts/pi-extension.mjs
3
3
  import { spawn } from "node:child_process";
4
- import path2 from "node:path";
4
+ import path3 from "node:path";
5
5
  import { createInterface } from "node:readline";
6
6
  import { fileURLToPath } from "node:url";
7
7
  import { Type } from "typebox";
@@ -174,18 +174,35 @@ function checkedRepository(result, depth = 0) {
174
174
  return void 0;
175
175
  }
176
176
 
177
+ // src/platform.ts
178
+ import { existsSync } from "node:fs";
179
+ import path2 from "node:path";
180
+ var executableName = (name, platform = process.platform) => platform === "win32" ? `${name}.exe` : name;
181
+ var searchPath = (env) => env.PATH ?? Object.entries(env).find(([name]) => name.toUpperCase() === "PATH")?.[1] ?? "";
182
+ function findOnPath(files, env, platform) {
183
+ const join = platform === "win32" ? path2.win32.join : path2.posix.join;
184
+ for (const directory of searchPath(env).split(platform === "win32" ? ";" : ":"))
185
+ for (const file of files)
186
+ if (directory && existsSync(join(directory, file))) return join(directory, file);
187
+ return void 0;
188
+ }
189
+ var findExecutable = (name, env = process.env, platform = process.platform) => findOnPath([executableName(name, platform)], env, platform);
190
+
177
191
  // scripts/pi-extension.mjs
178
192
  var CHECK_TOOL = "project_check_changes";
179
- var CLI = path2.join(path2.dirname(fileURLToPath(import.meta.url)), "..", "dist", "cli.mjs");
193
+ var CLI = path3.join(path3.dirname(fileURLToPath(import.meta.url)), "..", "dist", "cli.mjs");
180
194
  var READS = /* @__PURE__ */ new Set(["read", "grep", "find", "ls"]);
181
195
  var WRITES = /* @__PURE__ */ new Set(["edit", "write"]);
182
196
  var PATCH = "apply_patch";
183
197
  var PATCH_FILES = /^\*\*\* (?:(?:Add|Update|Delete) File|Move to): (.+)$/gm;
198
+ var NODE = process.versions.bun ? findExecutable("node") : process.execPath;
199
+ var START_TIMEOUT_MS = 3e4;
184
200
  var MapServer = class {
185
201
  constructor(cwd) {
202
+ if (!NODE) throw new Error("The server runs on Node, and none is on PATH.");
186
203
  this.pending = /* @__PURE__ */ new Map();
187
204
  this.next = 1;
188
- this.child = spawn(process.execPath, [CLI, "mcp"], {
205
+ this.child = spawn(NODE, [CLI, "mcp"], {
189
206
  cwd,
190
207
  stdio: ["pipe", "pipe", "ignore"],
191
208
  windowsHide: true
@@ -234,11 +251,19 @@ var MapServer = class {
234
251
  });
235
252
  }
236
253
  async start(version) {
237
- await this.request("initialize", {
238
- protocolVersion: "2025-06-18",
239
- capabilities: {},
240
- clientInfo: { name: "layermap-pi", version }
241
- });
254
+ const timer = setTimeout(() => {
255
+ this.fail(new Error(`The server did not answer within ${START_TIMEOUT_MS / 1e3} seconds.`));
256
+ this.child.kill();
257
+ }, START_TIMEOUT_MS);
258
+ try {
259
+ await this.request("initialize", {
260
+ protocolVersion: "2025-06-18",
261
+ capabilities: {},
262
+ clientInfo: { name: "layermap-pi", version }
263
+ });
264
+ } finally {
265
+ clearTimeout(timer);
266
+ }
242
267
  this.send({ method: "notifications/initialized" });
243
268
  return (await this.request("tools/list", {})).tools;
244
269
  }
@@ -268,7 +293,7 @@ function layermap(pi) {
268
293
  if (server && !server.dead) return server;
269
294
  starting ??= (async () => {
270
295
  const next = new MapServer(cwd);
271
- const tools = await next.start("0.1.34");
296
+ const tools = await next.start("0.1.36");
272
297
  for (const tool of tools) {
273
298
  if (registered.has(tool.name)) continue;
274
299
  registered.add(tool.name);
@@ -322,7 +347,7 @@ function layermap(pi) {
322
347
  if (!cwd) return;
323
348
  const before = running.get(event.toolCallId);
324
349
  running.delete(event.toolCallId);
325
- const files = before ? changedFiles(before, await fileStates(Object.keys(before))) : event.isError ? [] : namedFiles(event).map((file) => path2.resolve(cwd, file));
350
+ const files = before ? changedFiles(before, await fileStates(Object.keys(before))) : event.isError ? [] : namedFiles(event).map((file) => path3.resolve(cwd, file));
326
351
  changes.push(...await codeEdits(files));
327
352
  });
328
353
  pi.on("agent_before_settle", async (event) => {