layermap 0.1.22 → 0.1.25

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 CHANGED
@@ -143,9 +143,9 @@ This adds LayerMap to every dsh profile. Each session maps the project dsh was s
143
143
 
144
144
  In every agent, start a new session in a Git repository and ask as usual. LayerMap tells the agent
145
145
  when the map helps. A session started in a folder holding several repositories, or one that moves
146
- to another repository, works too: each map tool call maps the repository its path names. On first
147
- launch, npx downloads the pinned `layermap` package from npm; later
148
- launches use the cached copy, even offline.
146
+ to another repository, works too: each map tool call maps the repository its path names. The first
147
+ time a session starts a version of LayerMap, npm installs that pinned `layermap` package into
148
+ LayerMap's cache; later sessions start it from there, even offline.
149
149
 
150
150
  Claude Code asks once before each map tool runs in a project. Choose "don't ask again", or run
151
151
  `npx layermap allow claude` to allow the plugin's read-only tools everywhere.
@@ -162,7 +162,9 @@ request that path: a frontend's fetch, a generated API client, a redirect or a l
162
162
  an import between two modules of the project overview, it names it, and says when the two now
163
163
  depend on each other; whether that direction suits the project's layers is for the agent to judge. When a
164
164
  declaration the change adds reads almost the same as code the project already has, it names both, so
165
- the agent can use the existing code instead of a copy. It never writes or runs tests. In Claude Code and
165
+ the agent can use the existing code instead of a copy. When the change takes away the last call to a
166
+ declaration, as when new code replaces old, it names that declaration, so the agent can delete what
167
+ the change left behind. It never writes or runs tests. In Claude Code and
166
168
  CodeBuddy Code the plugin asks the agent once, before it finishes, to run this check for each repository it edited code in
167
169
  and has not checked since, whether through its edit tools or shell commands (changes another session makes in the same
168
170
  work tree do not count); the Pi extension does the same after the agent's own edits. Set `LAYERMAP_STOP_CHECK=0` to turn that
@@ -175,8 +177,9 @@ things:
175
177
  - lets its read-only tools run without a prompt;
176
178
  - adds one marked sentence to the agent's instructions file.
177
179
 
178
- Use `--scope project` to set it up for a whole team, and `npx layermap remove …` to undo it. For any
179
- other MCP client, run `npx -y layermap mcp` as a stdio server in the repository.
180
+ Setup is for one machine; for a whole team, have each member install the plugin. `npx layermap
181
+ remove …` undoes it. For any other MCP client, run `npx -y layermap mcp` as a stdio server in the
182
+ repository.
180
183
 
181
184
  **Requirements:**
182
185
 
package/dist/cli.mjs CHANGED
@@ -21,7 +21,7 @@ import { fileURLToPath } from "node:url";
21
21
 
22
22
  // src/layermap.ts
23
23
  import { createHash as createHash4 } from "node:crypto";
24
- import { mkdirSync } from "node:fs";
24
+ import { mkdirSync, statSync } from "node:fs";
25
25
  import { lstat as lstat2, realpath as realpath2 } from "node:fs/promises";
26
26
  import path10 from "node:path";
27
27
  import { DatabaseSync } from "@photostructure/sqlite";
@@ -153,17 +153,55 @@ function gitEnvironment() {
153
153
  });
154
154
  }
155
155
  var defaultGit = () => process.platform === "win32" ? findExecutable("git") ?? "git.exe" : "/usr/bin/git";
156
+ var FILTERING = /* @__PURE__ */ new Set(["diff", "status", "hash-object", "add", "stash", "update-index"]);
157
+ var subcommand = (args) => {
158
+ for (let index = 0; index < args.length; index++) {
159
+ if (args[index] === "-c" || args[index] === "-C") index++;
160
+ else if (!args[index]?.startsWith("-")) return args[index];
161
+ }
162
+ return void 0;
163
+ };
156
164
  var GitRunner = class {
157
165
  constructor(executable = defaultGit()) {
158
166
  this.executable = executable;
159
167
  }
160
168
  executable;
161
- run(args, options) {
162
- if (options.signal?.aborted) {
163
- return Promise.reject(new GitCommandError("Git command aborted."));
164
- }
169
+ async run(args, options) {
170
+ if (options.signal?.aborted) throw new GitCommandError("Git command aborted.");
165
171
  const readOnly = options.readOnly !== false;
166
- const finalArgs = readOnly ? ["--no-optional-locks", ...CONSTRAINED_CONFIG, ...args] : [...CONSTRAINED_CONFIG, ...args];
172
+ const config2 = [
173
+ ...CONSTRAINED_CONFIG,
174
+ ...FILTERING.has(subcommand(args) ?? "") ? await this.blankedFilters(options) : []
175
+ ];
176
+ return this.spawn(
177
+ readOnly ? ["--no-optional-locks", ...config2, ...args] : [...config2, ...args],
178
+ options
179
+ );
180
+ }
181
+ // Every filter driver the repository's config names, left with no program to run. Git reads its
182
+ // config without running anything; it lists none with status 1.
183
+ async blankedFilters(options) {
184
+ let listed;
185
+ try {
186
+ listed = (await this.spawn(
187
+ [...CONSTRAINED_CONFIG, "config", "--name-only", "--get-regexp", "^filter\\."],
188
+ { ...options, input: void 0 }
189
+ )).stdout.toString("utf8");
190
+ } catch (error51) {
191
+ if (error51 instanceof GitCommandError && error51.exitCode === 1) return [];
192
+ throw error51;
193
+ }
194
+ const drivers = new Set(
195
+ listed.split("\n").flatMap((key) => /^filter\.(.+)\.[^.]+$/su.exec(key)?.[1] ?? [])
196
+ );
197
+ return [...drivers].flatMap(
198
+ (driver) => ["clean=", "process=", "required=false"].flatMap((setting) => [
199
+ "-c",
200
+ `filter.${driver}.${setting}`
201
+ ])
202
+ );
203
+ }
204
+ spawn(finalArgs, options) {
167
205
  const timeoutMs = options.timeoutMs === void 0 ? 5e3 : options.timeoutMs;
168
206
  const maxOutputBytes = options.maxOutputBytes === void 0 ? 2 * 1024 * 1024 : options.maxOutputBytes;
169
207
  return new Promise((resolve, reject) => {
@@ -15481,7 +15519,11 @@ var excludedSegments = Object.freeze([
15481
15519
  "vendor",
15482
15520
  ".venv",
15483
15521
  "__pycache__",
15484
- "site-packages"
15522
+ "site-packages",
15523
+ ".claude",
15524
+ ".codex",
15525
+ ".cursor",
15526
+ ".pi"
15485
15527
  ]);
15486
15528
  var SOURCE_POLICY = Object.freeze({
15487
15529
  sourceExtensions,
@@ -15507,6 +15549,7 @@ var SOURCE_POLICY = Object.freeze({
15507
15549
  });
15508
15550
  var extensions = new Set(sourceExtensions);
15509
15551
  var excluded = new Set(excludedSegments);
15552
+ var inExcludedDirectory = (relativePath) => relativePath.toLowerCase().split("/").slice(0, -1).some((segment) => excluded.has(segment));
15510
15553
  var includesInitialEvidencePath = (relativePath, scope) => {
15511
15554
  try {
15512
15555
  assertProjectEvidencePathNotSensitive(relativePath);
@@ -15517,10 +15560,9 @@ var includesInitialEvidencePath = (relativePath, scope) => {
15517
15560
  (prefix) => prefix === "." || relativePath === prefix || relativePath.startsWith(`${prefix}/`)
15518
15561
  ))
15519
15562
  return false;
15520
- if (isProjectEvidenceTraversalExcluded(relativePath)) return false;
15521
- const segments2 = relativePath.toLowerCase().split("/");
15522
- if (segments2.slice(0, -1).some((segment) => excluded.has(segment))) return false;
15523
- const basename = segments2.at(-1) ?? "";
15563
+ if (isProjectEvidenceTraversalExcluded(relativePath) || inExcludedDirectory(relativePath))
15564
+ return false;
15565
+ const basename = relativePath.toLowerCase().split("/").at(-1) ?? "";
15524
15566
  return extensions.has(path6.posix.extname(basename)) || SOURCE_POLICY.documentationFiles.includes(basename) || SOURCE_POLICY.configurationFiles.includes(basename) || SOURCE_POLICY.workspaceFiles.includes(relativePath);
15525
15567
  };
15526
15568
 
@@ -22580,14 +22622,14 @@ async function readMapChanges(project, base, signal) {
22580
22622
  ],
22581
22623
  gitOptions(project, signal)
22582
22624
  )).stdout.toString("utf8");
22583
- const files = parseMapDiff(diff);
22625
+ const files = parseMapDiff(diff).filter((file2) => !inExcludedDirectory(file2.path));
22584
22626
  for (const [index, file2] of files.entries())
22585
22627
  if (file2.basePath && file2.status !== "ADDED" && !file2.binary && testCode(file2.basePath))
22586
22628
  files[index] = {
22587
22629
  ...file2,
22588
22630
  baseText: (await git.run(["show", `${commit}:${file2.basePath}`], gitOptions(project, signal))).stdout.toString("utf8")
22589
22631
  };
22590
- const untracked = (await git.run(["ls-files", "--others", "--exclude-standard", "-z"], gitOptions(project, signal))).stdout.toString("utf8").split("\0").filter(Boolean);
22632
+ const untracked = (await git.run(["ls-files", "--others", "--exclude-standard", "-z"], gitOptions(project, signal))).stdout.toString("utf8").split("\0").filter((path14) => path14 && !inExcludedDirectory(path14));
22591
22633
  for (const path14 of untracked)
22592
22634
  files.push({ path: path14, status: "ADDED", lines: [EVERYTHING], baseLines: [], binary: false });
22593
22635
  const stranded = await strandedNames(
@@ -22670,6 +22712,11 @@ var NON_CODE = [
22670
22712
  var nonCodeKind = (path14) => NON_CODE.find(([pattern]) => pattern.test(path14))?.[1];
22671
22713
  var LIMITS = Object.freeze({ depth: 8, declarations: 800, changed: 200, chain: 3, byName: 40 });
22672
22714
  var CALLER_KINDS = /* @__PURE__ */ new Set(["CALLS", "REFERENCES"]);
22715
+ var USED_BY = {
22716
+ EXTENDS: "extended",
22717
+ IMPLEMENTS: "implemented",
22718
+ OVERRIDES: "overridden"
22719
+ };
22673
22720
  var IMPORT_KINDS3 = /* @__PURE__ */ new Set(["IMPORTS", "TEST_IMPORTS"]);
22674
22721
  var ROUTE2 = /^(?:[A-Z]+(?:\|[A-Z]+)* +)?\/\S*$/u;
22675
22722
  var areaOf = (file2) => /\.(?:go|java|kt)$/u.test(file2) ? file2.slice(0, file2.lastIndexOf("/") + 1) || "./" : file2;
@@ -22766,13 +22813,38 @@ var Tracer = class {
22766
22813
  if (this.callerCount.get(reached.ref) !== 0) continue;
22767
22814
  const object2 = this.graph.object(reached.ref);
22768
22815
  if (testCode(object2.anchor.path) || this.routes.has(reached.ref)) continue;
22769
- if (reached.depth === 0)
22816
+ if (reached.depth === 0) {
22817
+ const uses = this.usesWithoutCalls(reached.ref);
22770
22818
  this.unclear.push(
22771
- `${this.where(reached.ref)} has no callers in the map: it may be wired by a framework, called dynamically, or unused`
22819
+ uses.length ? `${this.where(reached.ref)} has no callers in the map, and is used without a call: ${uses.join("; ")}` : `${this.where(reached.ref)} has no callers in the map: it may be wired by a framework, called dynamically, or unused`
22772
22820
  );
22773
- else this.entry(this.where(reached.ref), false, reached, void 0, reached.certain, true);
22821
+ } else this.entry(this.where(reached.ref), false, reached, void 0, reached.certain, true);
22774
22822
  }
22775
22823
  }
22824
+ /**
22825
+ * The uses outside tests the map sees of a declaration besides calls: a class others extend or
22826
+ * implement, a member that overrides another or that others override, and a decorator that may
22827
+ * wire it to be run (a route, a task, a registry). A decorator of the language's own library
22828
+ * (dataclass, staticmethod) only shapes the declaration. Reading a value is a reference, so a
22829
+ * caller; writing one is not a use, as a value nothing reads is unused.
22830
+ */
22831
+ usesWithoutCalls(ref) {
22832
+ const uses = [];
22833
+ for (const relation of this.graph.relationsTo([ref])) {
22834
+ const verb = USED_BY[relation.kind];
22835
+ const owner = this.graph.owner(relation.from);
22836
+ if (verb && owner !== ref && !testCode(this.graph.object(owner).anchor.path))
22837
+ uses.push(`${verb} by ${this.where(owner)}`);
22838
+ }
22839
+ for (const relation of this.graph.relationsFrom([ref]))
22840
+ if (relation.kind === "OVERRIDES")
22841
+ uses.push(
22842
+ `overrides ${relation.to === void 0 ? relation.target : this.where(this.graph.owner(relation.to))}`
22843
+ );
22844
+ else if (relation.kind === "DECORATED_BY" && relation.unresolvedReason !== "COMPILER_LIBRARY")
22845
+ uses.push(`decorated by ${relation.target}`);
22846
+ return [...new Set(uses)];
22847
+ }
22776
22848
  callers(ref) {
22777
22849
  const callers = [];
22778
22850
  for (const relation of this.graph.relationsTo([ref]))
@@ -22939,6 +23011,7 @@ function mapChangeImpact(store, working, base, changes, project) {
22939
23011
  supportTests(store, working, tracer);
22940
23012
  const rewrittenTests = [];
22941
23013
  const removedRoutes = [];
23014
+ const uncalled = [];
22942
23015
  if (base) {
22943
23016
  const before = new MapViewGraph(store, base);
22944
23017
  const registered = /* @__PURE__ */ new Set();
@@ -22997,6 +23070,40 @@ function mapChangeImpact(store, working, base, changes, project) {
22997
23070
  unclear.push(...beforeTracer.unclear.filter((line) => !line.includes("has no callers")));
22998
23071
  if (beforeTracer.truncated) tracer.truncated = true;
22999
23072
  }
23073
+ const moved = new Map(
23074
+ changes.files.flatMap(
23075
+ (file2) => file2.basePath ? [[file2.basePath, file2.status === "DELETED" ? void 0 : file2.path]] : []
23076
+ )
23077
+ );
23078
+ const called = /* @__PURE__ */ new Set();
23079
+ for (const file2 of changes.files) {
23080
+ if (!file2.basePath || !file2.baseLines.length || file2.binary || testCode(file2.basePath))
23081
+ continue;
23082
+ for (const relation of before.relationsFrom(
23083
+ before.objectsAt(file2.basePath).map((object2) => object2.id)
23084
+ ))
23085
+ if (CALLER_KINDS.has(relation.kind) && relation.to !== void 0 && overlaps(file2.baseLines, relation.anchor.startLine, relation.anchor.endLine))
23086
+ called.add(before.owner(relation.to));
23087
+ }
23088
+ const outsideTests = (callers, g) => callers.filter((caller) => !testCode(g.object(caller.ref).anchor.path));
23089
+ for (const ref of called) {
23090
+ const object2 = before.object(ref);
23091
+ if (mapIsModule(object2) || testCode(object2.anchor.path) || gone.includes(ref)) continue;
23092
+ const path14 = moved.has(object2.anchor.path) ? moved.get(object2.anchor.path) : object2.anchor.path;
23093
+ if (path14 === void 0) continue;
23094
+ const name = before.qualifiedName(ref);
23095
+ const now = declarations2(graph, path14).find(
23096
+ (candidate) => candidate.kind === object2.kind && graph.qualifiedName(candidate.id) === name
23097
+ );
23098
+ if (!now || outsideTests(tracer.callers(now.id), graph).length || tracer.usesWithoutCalls(now.id).length)
23099
+ continue;
23100
+ if (!outsideTests(beforeTracer.callers(ref), before).length) continue;
23101
+ const tested = tracer.callers(now.id).length > 0;
23102
+ uncalled.push(
23103
+ `${path14}: ${name} ${mapDeclarationLabel(now)}${tested ? " (only tests call it now)" : ""}`
23104
+ );
23105
+ }
23106
+ uncalled.sort();
23000
23107
  }
23001
23108
  return {
23002
23109
  changed,
@@ -23020,6 +23127,7 @@ function mapChangeImpact(store, working, base, changes, project) {
23020
23127
  })).sort((left, right) => right.tests.length - left.tests.length),
23021
23128
  unclear: [.../* @__PURE__ */ new Set([...unclear, ...tracer.unclear])],
23022
23129
  removedRoutes,
23130
+ uncalled,
23023
23131
  dependencies: newModuleDependencies(store, cache, working, base, changes.files),
23024
23132
  truncated: tracer.truncated
23025
23133
  };
@@ -23242,6 +23350,15 @@ Nothing changed against ${changes.base}.`;
23242
23350
  impact.removed,
23243
23351
  LIST.changed
23244
23352
  );
23353
+ list(
23354
+ "LEFT WITHOUT CALLERS (the diff removed or changed their last callers; nothing outside tests calls or otherwise uses them now)",
23355
+ impact.uncalled,
23356
+ LIST.changed
23357
+ );
23358
+ if (impact.uncalled.length)
23359
+ lines.push(
23360
+ "If the change replaced them, delete them and the tests that only test them; keep them only if something the map cannot see uses them, such as another package, a framework or a dynamic call."
23361
+ );
23245
23362
  if (changes.stranded.length) {
23246
23363
  list(
23247
23364
  "NAMES STILL USED ELSEWHERE (environment variables and configuration keys the diff removed from a file, found by text)",
@@ -23382,11 +23499,13 @@ Nothing changed against ${changes.base}.`;
23382
23499
  // src/layermap.ts
23383
23500
  var SCHEMA_VERSION = 2;
23384
23501
  var KEEP_VERSIONS = 3;
23502
+ var BUSY_TIMEOUT = "PRAGMA busy_timeout = 30000;";
23503
+ var JOURNAL_LIMIT = 32 * 1024 * 1024;
23385
23504
  function openMapDatabase(file2) {
23386
23505
  mkdirSync(path10.dirname(file2), { recursive: true, mode: 448 });
23387
23506
  const database = new DatabaseSync(file2);
23388
23507
  try {
23389
- database.exec("PRAGMA busy_timeout = 30000;");
23508
+ database.exec(BUSY_TIMEOUT);
23390
23509
  const version2 = Number(database.prepare("PRAGMA user_version").get()?.user_version ?? 0);
23391
23510
  if (version2 > SCHEMA_VERSION) throw new ProjectEvidenceError("LAYERMAP_DATABASE_NEWER", false);
23392
23511
  if (version2 === 0) database.exec("PRAGMA auto_vacuum = INCREMENTAL;");
@@ -23427,18 +23546,20 @@ var mapDatabasePath = (cacheDirectory2, canonicalProject) => path10.join(
23427
23546
  "map.sqlite"
23428
23547
  );
23429
23548
  var LayerMap = class _LayerMap {
23430
- constructor(project, source, store, index, budget) {
23549
+ constructor(project, source, store, index, budget, journal) {
23431
23550
  this.project = project;
23432
23551
  this.source = source;
23433
23552
  this.store = store;
23434
23553
  this.index = index;
23435
23554
  this.budget = budget;
23555
+ this.journal = journal;
23436
23556
  }
23437
23557
  project;
23438
23558
  source;
23439
23559
  store;
23440
23560
  index;
23441
23561
  budget;
23562
+ journal;
23442
23563
  refreshing;
23443
23564
  static async open(options) {
23444
23565
  const project = await realpath2(options.project);
@@ -23449,10 +23570,9 @@ var LayerMap = class _LayerMap {
23449
23570
  projectRef: `layermap:${createHash4("sha256").update(project).digest("hex").slice(0, 24)}`,
23450
23571
  directory: { canonicalPath: project, device: String(stat3.dev), inode: String(stat3.ino) }
23451
23572
  };
23573
+ const file2 = mapDatabasePath(options.cacheDirectory, project);
23452
23574
  const store = new CodeIndexStore(
23453
- openMapDatabase(
23454
- mapDatabasePath(options.cacheDirectory, project)
23455
- )
23575
+ openMapDatabase(file2)
23456
23576
  );
23457
23577
  const { typescript, go, python, java } = options.analyzers;
23458
23578
  const index = new CodeIndex(
@@ -23465,10 +23585,14 @@ var LayerMap = class _LayerMap {
23465
23585
  new JavaMapAnalyzer(java)
23466
23586
  ])
23467
23587
  );
23468
- return new _LayerMap(project, source, store, index, {
23469
- maxBytes: options.maxOutputBytes ?? 96 * 1024,
23470
- envelopeBytes: 0
23471
- });
23588
+ return new _LayerMap(
23589
+ project,
23590
+ source,
23591
+ store,
23592
+ index,
23593
+ { maxBytes: options.maxOutputBytes ?? 96 * 1024, envelopeBytes: 0 },
23594
+ `${file2}-wal`
23595
+ );
23472
23596
  }
23473
23597
  /** The map version of the directory as it is now, built or updated if needed. */
23474
23598
  refresh(signal) {
@@ -23477,6 +23601,7 @@ var LayerMap = class _LayerMap {
23477
23601
  initialScope: DEFAULT_INITIAL_EVIDENCE_SCOPE
23478
23602
  });
23479
23603
  this.prune(version2);
23604
+ this.tidyJournal();
23480
23605
  return version2.version;
23481
23606
  });
23482
23607
  }
@@ -23507,6 +23632,20 @@ var LayerMap = class _LayerMap {
23507
23632
  ]);
23508
23633
  this.store.database.exec("PRAGMA incremental_vacuum;");
23509
23634
  }
23635
+ // SQLite leaves the write-ahead log at the size of the largest capture written through it, often
23636
+ // hundreds of megabytes after a build. Once that capture is in the database the log is emptied,
23637
+ // unless another process is reading or writing the map, in which case a later capture empties it.
23638
+ tidyJournal() {
23639
+ if ((statSync(this.journal, { throwIfNoEntry: false })?.size ?? 0) <= JOURNAL_LIMIT) return;
23640
+ const database = this.store.database;
23641
+ database.exec("PRAGMA busy_timeout = 0;");
23642
+ try {
23643
+ database.prepare("PRAGMA wal_checkpoint(TRUNCATE)").get();
23644
+ } catch {
23645
+ } finally {
23646
+ database.exec(BUSY_TIMEOUT);
23647
+ }
23648
+ }
23510
23649
  async explore(input, signal) {
23511
23650
  const version2 = await this.refresh(signal);
23512
23651
  return this.index.query.viewMap(
@@ -23679,7 +23818,7 @@ async function resolveAnalyzers(cache, log2, env = process.env) {
23679
23818
  return await readAnalyzers(directory);
23680
23819
  }
23681
23820
  var DAY = 24 * 60 * 60 * 1e3;
23682
- async function pruneCache(cache, project, now = Date.now()) {
23821
+ async function pruneCache(cache, project, now = Date.now(), installed = packageRoot, env = process.env) {
23683
23822
  const used = path11.join(path11.dirname(mapDatabasePath(cache, project)), "last-used");
23684
23823
  await mkdir(path11.dirname(used), { recursive: true, mode: 448 });
23685
23824
  await writeFile(used, "");
@@ -23700,6 +23839,52 @@ async function pruneCache(cache, project, now = Date.now()) {
23700
23839
  if (built !== void 0 && now - built > (name.includes(".") ? DAY / 24 : DAY))
23701
23840
  await rm(path11.join(builds, name), { recursive: true, force: true });
23702
23841
  }
23842
+ const own = path11.dirname(path11.dirname(installed));
23843
+ const versions = path11.join(cache, "versions");
23844
+ const launched = path11.dirname(own) === versions;
23845
+ if (launched) await pruneVersions(versions, own, now);
23846
+ const npx = launched ? path11.join(
23847
+ env.npm_config_cache || (process.platform === "win32" ? path11.join(env.LOCALAPPDATA || path11.join(homedir(), "AppData", "Local"), "npm-cache") : path11.join(homedir(), ".npm")),
23848
+ "_npx"
23849
+ ) : path11.dirname(own);
23850
+ if (path11.basename(path11.dirname(installed)) === "node_modules" && path11.basename(npx) === "_npx")
23851
+ await pruneNpxInstalls(npx, installed, now);
23852
+ }
23853
+ async function pruneVersions(versions, own, now) {
23854
+ const used = path11.join(own, "last-used");
23855
+ await writeFile(used, "");
23856
+ await utimes(used, now / 1e3, now / 1e3);
23857
+ for (const name of await readdir(versions).catch(() => [])) {
23858
+ const directory = path11.join(versions, name);
23859
+ const marker = path11.join(directory, "last-used");
23860
+ const last = (await stat(existsSync5(marker) ? marker : directory).catch(() => void 0))?.mtimeMs;
23861
+ if (last !== void 0 && now - last > (name.startsWith(".") ? DAY / 24 : 7 * DAY))
23862
+ await rm(directory, { recursive: true, force: true });
23863
+ }
23864
+ }
23865
+ async function pruneNpxInstalls(npx, installed, now) {
23866
+ const own = path11.dirname(path11.dirname(installed));
23867
+ const manifest = async (file2) => JSON.parse(await readFile2(file2, "utf8").catch(() => "{}"));
23868
+ const parts = (version2) => version2?.split(".").map(Number) ?? [];
23869
+ const current = parts((await manifest(path11.join(installed, "package.json"))).version);
23870
+ const older = (version2) => {
23871
+ for (let index = 0; index < 3; index++)
23872
+ if (version2[index] !== current[index]) return (version2[index] ?? 0) < (current[index] ?? 0);
23873
+ return false;
23874
+ };
23875
+ for (const name of await readdir(npx).catch(() => [])) {
23876
+ const directory = path11.join(npx, name);
23877
+ if (directory === own) continue;
23878
+ const requested = (await manifest(path11.join(directory, "package.json"))).dependencies ?? {};
23879
+ if (Object.keys(requested).join() !== "layermap") continue;
23880
+ const version2 = parts(
23881
+ (await manifest(path11.join(directory, "node_modules", "layermap", "package.json"))).version
23882
+ );
23883
+ if (version2.length !== 3 || version2.some(Number.isNaN) || !older(version2)) continue;
23884
+ const at = (await stat(directory).catch(() => void 0))?.mtimeMs;
23885
+ if (at !== void 0 && now - at > 7 * DAY)
23886
+ await rm(directory, { recursive: true, force: true });
23887
+ }
23703
23888
  }
23704
23889
 
23705
23890
  // src/agent/mcp.ts
@@ -23791,7 +23976,7 @@ var mapToolDescriptions = (host) => {
23791
23976
  return Object.freeze({
23792
23977
  search: `${lead("search")}Find declarations and files whose names, paths or source documentation match query terms. ANY (default) matches any term, ALL requires every term, LITERAL matches the exact text. Results are ranked by relevance and grouped by file with the declaration name, kind, 1-based line range and matched fields (${MAP_KINDS_LEGEND}). Zoom into a result with project_explore_map({path,name}) or ${host.readResult}. This is not a full-text search and does not prove absence; ${host.textSearch}. Continue with offset and unchanged conditions.`,
23793
23978
  explore: `${lead("explore")}Read the static project map, zooming from the whole project to one declaration. path "." or a directory lists modules, module imports, external packages and its files: with exported declarations when the listing is small, as file names and line counts by directory when larger, and as modules only when very large. Start here to see what exists before searching or reading. A file path lists its declarations and members, imports, importers and top-level statements. A file path with name (or Container.member), optionally narrowed by its start line, or with a line alone, shows that declaration's calls, callers (including uses as a value), writes, heritage, decorators and members, aggregated per related declaration with @line sites; closures and locals are folded into their named container. depth also expands the related declarations hop by hop: up to 8 in one direction, which traces callers up to entry points (INCOMING) or callees down (OUTGOING), and up to 3 for BOTH. To find what a change affects, select the declaration with direction INCOMING and a depth up to 8, continue from any NOT EXPANDED declarations the view names, then confirm the entry points in source. Test files and standard-library call targets are hidden and counted by default; includeTests and includeUnresolved show them. Views use ${MAP_KINDS_LEGEND}. In a declaration view, ${MAP_DECLARATION_LEGEND} ${host.readSource} The map is static: trace stops, possible callers by name, framework wiring and unresolved targets need source reading, and a missing relationship does not prove absence. When a page reports more entries, continue with offset and otherwise unchanged arguments.`,
23794
- check: `${lead("check")}Compares the working tree with a commit (HEAD by default, so uncommitted and untracked changes), finds the declarations the diff changed, removed or renamed, and follows their callers up to 8 levels. It reports, conclusion first: AFFECTED ENTRY POINTS reached through resolved calls, each route with its HTTP methods and full path and the chain to the change; POSSIBLY AFFECTED ones reached only through a call on an interface or base member; REQUESTED BY, the code and templates outside the tests that request the path of a route whose handler the change reaches or a route it removed, found by text; EXISTING TESTS CHANGED, the tests that existed before the diff and whose code it changed or removed; SHARED BY, when tests reach the changed code through more than one area (package or module), so a change meant for one feature may change others; NAMES STILL USED ELSEWHERE, environment variables and configuration keys the diff removed from a file that other files still read or set, found by text; NEW MODULE DEPENDENCIES, imports between the modules of the project overview that the base did not have, and those that make two modules depend on each other, for you to judge against the project's layers; EXISTING CODE LIKE THE NEW CODE, declarations the diff adds whose code reads almost the same as code the project already has; CHECK BY HAND for what a static map cannot follow (changed configuration, templates, migrations or dependency files, changed route registrations, declarations with no callers, calls by name on receivers of unknown type); and RELATED TESTS, the existing test files that call the changed code, import a changed file or sit beside it. It does not run or write tests: run the related ones if the change needs verifying; a failing or rewritten test of a feature the request is not about means the change leaked, so restore the test and narrow the change; a new dependency that runs against the layers or closes a cycle means moving what both modules need down rather than importing upward; new code like existing code means using the existing code, or removing the old if the new replaces it; call it once when the edits are done; and confirm the entry points in source, since an empty list does not prove a change safe.`,
23979
+ check: `${lead("check")}Compares the working tree with a commit (HEAD by default, so uncommitted and untracked changes), finds the declarations the diff changed, removed or renamed, and follows their callers up to 8 levels. It reports, conclusion first: AFFECTED ENTRY POINTS reached through resolved calls, each route with its HTTP methods and full path and the chain to the change; POSSIBLY AFFECTED ones reached only through a call on an interface or base member; REQUESTED BY, the code and templates outside the tests that request the path of a route whose handler the change reaches or a route it removed, found by text; EXISTING TESTS CHANGED, the tests that existed before the diff and whose code it changed or removed; SHARED BY, when tests reach the changed code through more than one area (package or module), so a change meant for one feature may change others; NAMES STILL USED ELSEWHERE, environment variables and configuration keys the diff removed from a file that other files still read or set, found by text; NEW MODULE DEPENDENCIES, imports between the modules of the project overview that the base did not have, and those that make two modules depend on each other, for you to judge against the project's layers; EXISTING CODE LIKE THE NEW CODE, declarations the diff adds whose code reads almost the same as code the project already has; LEFT WITHOUT CALLERS, declarations whose last callers outside the tests the diff removed or changed, and that nothing extends, implements, overrides or wires with a decorator; CHECK BY HAND for what a static map cannot follow (changed configuration, templates, migrations or dependency files, changed route registrations, declarations with no callers, calls by name on receivers of unknown type); and RELATED TESTS, the existing test files that call the changed code, import a changed file or sit beside it. It does not run or write tests: run the related ones if the change needs verifying; a failing or rewritten test of a feature the request is not about means the change leaked, so restore the test and narrow the change; a new dependency that runs against the layers or closes a cycle means moving what both modules need down rather than importing upward; new code like existing code means using the existing code, or removing the old if the new replaces it; code left without callers means deleting it, with the tests that only test it, when the change replaced it; call it once when the edits are done; and confirm the entry points in source, since an empty list does not prove a change safe.`,
23795
23980
  references: `${lead("references")}Compute usages of a mapped declaration from current source, including aliases, re-exports and non-call references. Select it with symbol {path,name,line?} as printed by project_explore_map or project_search_map (line is its start line when names repeat), or with an entityRef or locator {path,start,kind}. Broader and more expensive than the cached callers in project_explore_map; file or unsupported declarations may lack a reference target. path and kinds filter usage locations before paging. ${host.grantRules}objects contains compact declarations; targetRef and reference ownerRef identify them. ${host.readReference} A file that several compiler contexts read (such as packages of one workspace) lists its references once per context, each with that context's configPath. Continue with nextCursor and unchanged conditions, including after an empty partial page. Filtered exhaustion and missing results do not prove absence.`
23796
23981
  });
23797
23982
  };
@@ -24130,7 +24315,7 @@ ${text}` : text
24130
24315
  // src/agent/setup.ts
24131
24316
  import { execFile as execFile2 } from "node:child_process";
24132
24317
  import { existsSync as existsSync7 } from "node:fs";
24133
- import { mkdir as mkdir2, readFile as readFile3, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
24318
+ import { mkdir as mkdir2, readFile as readFile3, rename as rename2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
24134
24319
  import { homedir as homedir2 } from "node:os";
24135
24320
  import path13 from "node:path";
24136
24321
  var SERVER = "layermap";
@@ -24138,16 +24323,13 @@ var SETUP_RULE = `mcp__${SERVER}`;
24138
24323
  var PLUGIN_RULE = `mcp__plugin_${SERVER}_${SERVER}`;
24139
24324
  var BEGIN = "<!-- layermap:begin -->";
24140
24325
  var END = "<!-- layermap:end -->";
24141
- var npxServerArgs = (version2) => [
24142
- "--prefer-offline",
24143
- "-y",
24144
- `layermap@${version2}`,
24145
- "mcp"
24146
- ];
24147
- var mcpLaunchCommand = (version2, platform = process.platform) => {
24326
+ var launcherScript = (template, version2) => `// Generated from scripts/launcher.mjs.
24327
+ ${template.replace("__VERSION__", JSON.stringify(version2))}`;
24328
+ var PUBLISHED_LAUNCHER = path13.join(packageRoot, "dist", "launcher.mjs");
24329
+ var launcherFile = (env = process.env) => path13.join(cacheDirectory(env), "server.mjs");
24330
+ var mcpLaunchCommand = (env = process.env, published = existsSync7(PUBLISHED_LAUNCHER)) => {
24331
+ if (published) return ["node", launcherFile(env)];
24148
24332
  const script = path13.resolve(process.argv[1] ?? "");
24149
- if (script.includes(`${path13.sep}_npx${path13.sep}`))
24150
- return [...platform === "win32" ? ["cmd", "/c"] : [], "npx", ...npxServerArgs(version2)];
24151
24333
  const execArgv = [];
24152
24334
  for (let index = 0; index < process.execArgv.length; index++) {
24153
24335
  const argument = process.execArgv[index];
@@ -24196,6 +24378,7 @@ async function configureCodexServer(file2) {
24196
24378
  while (end < lines.length && !lines[end]?.trim().startsWith("[")) end++;
24197
24379
  const wanted = {
24198
24380
  default_tools_approval_mode: '"approve"',
24381
+ startup_timeout_sec: "120",
24199
24382
  tool_timeout_sec: "120"
24200
24383
  };
24201
24384
  const present = new Set(
@@ -24245,13 +24428,10 @@ async function disallowInClaudeSettings(file2) {
24245
24428
  }
24246
24429
  var YAML_BEGIN = "# layermap:begin";
24247
24430
  var YAML_END = "# layermap:end";
24248
- var nodeDirectory = (env = process.env) => (env.PATH ?? "").split(path13.delimiter).find(
24249
- (directory) => path13.isAbsolute(directory) && existsSync7(path13.join(directory, "node")) && existsSync7(path13.join(directory, "npx"))
24250
- ) ?? path13.dirname(process.execPath);
24431
+ var nodeDirectory = (env = process.env) => (env.PATH ?? "").split(path13.delimiter).find((directory) => path13.isAbsolute(directory) && existsSync7(path13.join(directory, "node"))) ?? path13.dirname(process.execPath);
24251
24432
  var dshPatchBlock = (command, env) => {
24252
24433
  const node = nodeDirectory(env);
24253
- const npx = path13.join(node, "npx");
24254
- const [program = "", ...args] = command[0] === "npx" && existsSync7(npx) ? [npx, ...command.slice(1)] : command;
24434
+ const [program = "", ...args] = command[0] === "node" ? [path13.join(node, "node"), ...command.slice(1)] : command;
24255
24435
  const searchPath2 = `${JSON.stringify(`${node}${path13.delimiter}`)} + process.env.PATH`;
24256
24436
  return [
24257
24437
  `${YAML_BEGIN} (written by \`layermap setup dsh\`; \`layermap remove dsh\` deletes it)`,
@@ -24335,10 +24515,28 @@ var agentFiles = (options) => {
24335
24515
  async function setupAgent(options) {
24336
24516
  const env = options.env ?? process.env;
24337
24517
  const { log: log2 } = options;
24338
- const command = mcpLaunchCommand(options.version);
24518
+ if (options.scope === "project") {
24519
+ log2(
24520
+ "Setup registers this machine's launcher, so it does not write a project's shared settings. Have each machine run setup (--scope user or local), or install the plugin; `layermap remove claude --scope project` still removes an earlier project setup."
24521
+ );
24522
+ return false;
24523
+ }
24524
+ const published = existsSync7(PUBLISHED_LAUNCHER);
24525
+ const command = mcpLaunchCommand(env, published);
24339
24526
  const quoted = command.map((part) => /^[\w./:@=-]+$/u.test(part) ? part : JSON.stringify(part));
24340
24527
  const { settings, instructions } = agentFiles(options);
24341
24528
  const note = options.instructions !== false;
24529
+ const writeLauncher = async () => {
24530
+ if (!published) return;
24531
+ const file2 = launcherFile(env);
24532
+ await mkdir2(path13.dirname(file2), { recursive: true, mode: 448 });
24533
+ await writeFile2(
24534
+ `${file2}.${process.pid}`,
24535
+ launcherScript(await readFile3(PUBLISHED_LAUNCHER, "utf8"), options.version)
24536
+ );
24537
+ await rename2(`${file2}.${process.pid}`, file2);
24538
+ };
24539
+ if (published) log2(`write the launcher of LayerMap ${options.version} to ${launcherFile(env)}`);
24342
24540
  if (options.agent === "dsh") {
24343
24541
  if (options.scope !== "user") {
24344
24542
  log2("DeepSeek Harness is set up for all its profiles at once; --scope does not apply.");
@@ -24347,6 +24545,7 @@ async function setupAgent(options) {
24347
24545
  log2(`add the ${SERVER} MCP server to ${settings}`);
24348
24546
  if (note) log2(`add a note naming the map tools to ${instructions}`);
24349
24547
  if (options.dryRun) return true;
24548
+ await writeLauncher();
24350
24549
  await writeDshPatch(settings, dshPatchBlock(command, env));
24351
24550
  if (note) await writeInstructionNote(instructions);
24352
24551
  log2(
@@ -24360,10 +24559,13 @@ async function setupAgent(options) {
24360
24559
  log2(`allow ${SETUP_RULE} in ${settings}`);
24361
24560
  } else {
24362
24561
  log2(`codex mcp add ${SERVER} -- ${quoted.join(" ")}`);
24363
- log2(`set default_tools_approval_mode = "approve" and tool_timeout_sec = 120 in ${settings}`);
24562
+ log2(
24563
+ `set default_tools_approval_mode = "approve", startup_timeout_sec = 120 and tool_timeout_sec = 120 in ${settings}`
24564
+ );
24364
24565
  }
24365
24566
  if (note) log2(`add a note naming the map tools to ${instructions}`);
24366
24567
  if (options.dryRun) return true;
24568
+ await writeLauncher();
24367
24569
  const agentCommand = options.agent;
24368
24570
  const scope = options.agent === "claude" ? ["--scope", options.scope] : [];
24369
24571
  await run(agentCommand, ["mcp", "remove", SERVER, ...scope], env);
@@ -24424,7 +24626,7 @@ async function removeAgent(options) {
24424
24626
  var USAGE = `LayerMap \u2014 a layered map of a codebase for coding agents.
24425
24627
 
24426
24628
  Usage:
24427
- layermap setup claude|codex|dsh [--scope user|project|local] [--no-instructions] [--dry-run]
24629
+ layermap setup claude|codex|dsh [--scope user|local] [--no-instructions] [--dry-run]
24428
24630
  layermap allow claude [--scope user|project|local] [--dry-run]
24429
24631
  let the plugin's read-only tools run without a prompt
24430
24632
  layermap remove claude|codex|dsh [--scope user|project|local] [--dry-run]
@@ -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.22",
3
+ "version": "0.1.25",
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 node in the session's directory; its
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("node", [CLI, "mcp"], {
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
- git(repository, [
145
- "-c",
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) {
@@ -178,7 +185,7 @@ const fingerprint = (changed) =>
178
185
  : "";
179
186
 
180
187
  // How long a command runs (ms) before only the files it names count as its changes.
181
- const LONG_COMMAND = 60_000;
188
+ const LONG_COMMAND = 10_000;
182
189
 
183
190
  // The folders a shell command names that exist, relative to the directory it runs in.
184
191
  async function namedFolders(cwd, command) {
@@ -213,8 +220,9 @@ export default function layermap(pi) {
213
220
  // It compares a repository's uncommitted code changes with those it had before the session's
214
221
  // first such tool there and those the agent last checked in it, and all of them with those it
215
222
  // was last asked about; changes another session makes while this one reads do not count. A
216
- // command that ran longer than a minute (tests, builds, scripts) leaves time for another session
217
- // to change the same work tree, so only the files it names count.
223
+ // command that ran longer than ten seconds (tests, builds, scripts) leaves time for another
224
+ // session to change the same work tree, so only the files it names count; one that writes code
225
+ // without naming the file, such as a generator or formatter, takes a few seconds.
218
226
  const edited = new Set();
219
227
  const before = new Map();
220
228
  const checked = new Map();
@@ -227,7 +235,7 @@ export default function layermap(pi) {
227
235
  if (server && !server.dead) return server;
228
236
  starting ??= (async () => {
229
237
  const next = new MapServer(cwd);
230
- const tools = await next.start("0.1.22");
238
+ const tools = await next.start("0.1.25");
231
239
  for (const tool of tools) {
232
240
  if (registered.has(tool.name)) continue;
233
241
  registered.add(tool.name);