layermap 0.1.37 → 0.1.38

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
@@ -23146,7 +23146,14 @@ async function readMapChanges(project, base, signal) {
23146
23146
  };
23147
23147
  const untracked = (await git.run(["ls-files", "--others", "--exclude-standard", "-z"], gitOptions(project, signal))).stdout.toString("utf8").split("\0").filter((path17) => path17 && !inExcludedDirectory(path17));
23148
23148
  for (const path17 of untracked)
23149
- files.push({ path: path17, status: "ADDED", lines: [EVERYTHING], baseLines: [], binary: false });
23149
+ files.push({
23150
+ path: path17,
23151
+ status: "ADDED",
23152
+ lines: [EVERYTHING],
23153
+ baseLines: [],
23154
+ hunks: [],
23155
+ binary: false
23156
+ });
23150
23157
  const stranded = await strandedNames(
23151
23158
  project,
23152
23159
  diff,
@@ -23175,6 +23182,7 @@ function parseMapDiff(text) {
23175
23182
  status: "MODIFIED",
23176
23183
  lines: [],
23177
23184
  baseLines: [],
23185
+ hunks: [],
23178
23186
  binary: false
23179
23187
  };
23180
23188
  continue;
@@ -23200,6 +23208,12 @@ function parseMapDiff(text) {
23200
23208
  Number(hunk[3]),
23201
23209
  hunk[4] === void 0 ? 1 : Number(hunk[4])
23202
23210
  ];
23211
+ current.hunks.push({
23212
+ baseStart: oldStart,
23213
+ baseCount: oldCount,
23214
+ start: newStart,
23215
+ count: newCount
23216
+ });
23203
23217
  if (oldCount > 0) current.baseLines.push([oldStart, oldStart + oldCount - 1]);
23204
23218
  current.lines.push(
23205
23219
  newCount > 0 ? [newStart, newStart + newCount - 1] : [newStart + 1, newStart]
@@ -23211,6 +23225,14 @@ function parseMapDiff(text) {
23211
23225
  }
23212
23226
  var testCode = (file2) => mapTestPath(file2) || /(?:^|\/)testFixtures\//u.test(file2);
23213
23227
  var overlaps = (lines, start, end) => lines.some(([from, to]) => from <= end && start <= to);
23228
+ var workingLine = (file2, line) => {
23229
+ let shift = 0;
23230
+ for (const hunk of file2?.hunks ?? []) {
23231
+ if ((hunk.baseCount ? hunk.baseStart : hunk.baseStart + 1) > line) break;
23232
+ shift += hunk.count - hunk.baseCount;
23233
+ }
23234
+ return line + shift;
23235
+ };
23214
23236
  var NON_CODE = [
23215
23237
  [
23216
23238
  /(?:^|\/)(?:package-lock\.json|pnpm-lock\.yaml|yarn\.lock|go\.sum|poetry\.lock|Pipfile\.lock|uv\.lock|Cargo\.lock|gradle\.lockfile)$/u,
@@ -23757,18 +23779,35 @@ async function mapChangeImpact(store, working, base, changes, shapes, until, pro
23757
23779
  const changedIn = new Map(
23758
23780
  changes.files.flatMap((file2) => file2.basePath ? [[file2.basePath, file2]] : [])
23759
23781
  );
23760
- const same2 = (g, ref) => `${g.object(ref).kind}\0${g.qualifiedName(ref)}`;
23761
- const stillUses = (relation, user) => {
23762
- const file2 = changedIn.get(relation.anchor.path);
23763
- if (file2 && (file2.status === "DELETED" || overlaps(file2.baseLines, relation.anchor.startLine, relation.anchor.endLine)))
23764
- return false;
23765
- const name = same2(before, user);
23766
- const now = graph.objectsAt(file2?.path ?? relation.anchor.path).find((object2) => same2(graph, object2.id) === name);
23767
- if (!now || relation.to === void 0) return true;
23768
- const used = same2(before, relation.to);
23769
- const tag = mapIsModule(before.object(relation.to));
23770
- return !graph.relationsFrom(graph.scope(now.id).refs).some(
23771
- (use) => NAMING_KINDS.has(use.kind) && use.to !== void 0 && (tag ? use.target === relation.target : same2(graph, use.to) === used)
23782
+ const nowAt = (anchor) => {
23783
+ const file2 = changedIn.get(anchor.path);
23784
+ if (file2 && (file2.status === "DELETED" || overlaps(file2.baseLines, anchor.startLine, anchor.endLine)))
23785
+ return void 0;
23786
+ return {
23787
+ path: file2?.path ?? anchor.path,
23788
+ startLine: workingLine(file2, anchor.startLine),
23789
+ endLine: workingLine(file2, anchor.endLine)
23790
+ };
23791
+ };
23792
+ const samePlace = (anchor, place) => anchor.path === place.path && anchor.startLine === place.startLine && anchor.endLine === place.endLine;
23793
+ const replaces = (now, removed2) => now.kind === removed2.kind && now.name === removed2.name;
23794
+ const relationsNow = /* @__PURE__ */ new Map();
23795
+ const relationsIn = (path17) => {
23796
+ let found = relationsNow.get(path17);
23797
+ if (!found) {
23798
+ found = graph.relationsFrom(graph.objectsAt(path17).map((object2) => object2.id));
23799
+ relationsNow.set(path17, found);
23800
+ }
23801
+ return found;
23802
+ };
23803
+ const stillUses = (relation) => {
23804
+ const place = nowAt(relation.anchor);
23805
+ if (!place) return false;
23806
+ if (relation.to === void 0) return true;
23807
+ const used = before.object(relation.to);
23808
+ const tag = mapIsModule(used);
23809
+ return !relationsIn(place.path).some(
23810
+ (use) => NAMING_KINDS.has(use.kind) && use.to !== void 0 && samePlace(use.anchor, place) && (tag ? use.target === relation.target : replaces(graph.object(use.to), used))
23772
23811
  );
23773
23812
  };
23774
23813
  const gone = [];
@@ -23797,8 +23836,7 @@ async function mapChangeImpact(store, working, base, changes, shapes, until, pro
23797
23836
  before.objectsAt(file2.basePath).filter((member) => inside(member.id)).map((member) => member.id)
23798
23837
  )) {
23799
23838
  const owner = before.owner(relation.from);
23800
- if (!NAMING_KINDS.has(relation.kind) || inside(owner) || !stillUses(relation, owner))
23801
- continue;
23839
+ if (!NAMING_KINDS.has(relation.kind) || inside(owner) || !stillUses(relation)) continue;
23802
23840
  const user = before.object(owner);
23803
23841
  usedBy.add(
23804
23842
  mapIsModule(user) ? `${user.anchor.path}${mapMiniprogramTemplate(user.anchor.path) ? " (template)" : ": top-level code"}` : `${user.anchor.path}: ${before.qualifiedName(owner)}`
@@ -23816,28 +23854,56 @@ async function mapChangeImpact(store, working, base, changes, shapes, until, pro
23816
23854
  }
23817
23855
  }
23818
23856
  await beforeTracer.shapes.read(goneShapes.flatMap((item) => item.shapes));
23819
- const nowDeclared = new Set(
23820
- changes.files.flatMap(
23821
- (file2) => file2.status === "DELETED" ? [] : graph.objectsAt(file2.path).map((object2) => same2(graph, object2.id))
23857
+ const declared = /* @__PURE__ */ new Map();
23858
+ for (const file2 of changes.files)
23859
+ if (file2.status !== "DELETED") {
23860
+ for (const object2 of graph.objectsAt(file2.path))
23861
+ if (mapIsShape(object2)) {
23862
+ const key = `${object2.kind}\0${object2.name}`;
23863
+ declared.set(key, [...declared.get(key) ?? [], object2]);
23864
+ }
23865
+ }
23866
+ const successors = (shape) => {
23867
+ const removed2 = before.object(shape);
23868
+ return declared.get(`${removed2.kind}\0${removed2.name}`) ?? [];
23869
+ };
23870
+ await tracer.shapes.read(
23871
+ goneShapes.flatMap(
23872
+ (item) => item.shapes.flatMap((shape) => successors(shape).map((object2) => object2.id))
23822
23873
  )
23823
23874
  );
23875
+ const unfollowed = /* @__PURE__ */ new Set();
23824
23876
  for (const { shapes: inRemoved, inside, usedBy } of goneShapes)
23825
23877
  for (const shape of inRemoved) {
23826
- if (nowDeclared.has(same2(before, shape))) continue;
23827
23878
  if (beforeTracer.shapes.unread.has(shape))
23828
23879
  unclear.push(
23829
23880
  `${before.object(shape).anchor.path}: ${before.qualifiedName(shape)} was removed, and who used it was not read; search the code for its name`
23830
23881
  );
23882
+ const now = successors(shape);
23831
23883
  for (const { owner, anchor } of beforeTracer.shapes.uses.get(shape) ?? []) {
23832
- const file2 = changedIn.get(anchor.path);
23833
- if (inside(owner) || file2 && (file2.status === "DELETED" || overlaps(file2.baseLines, anchor.startLine, anchor.endLine)))
23884
+ const place = nowAt(anchor);
23885
+ if (inside(owner) || !place || now.some(
23886
+ (object2) => tracer.shapes.uses.get(object2.id)?.some((use) => samePlace(use.anchor, place))
23887
+ ))
23888
+ continue;
23889
+ if (now.some((object2) => tracer.shapes.unread.has(object2.id))) {
23890
+ unfollowed.add(`${before.object(shape).anchor.path}: ${before.qualifiedName(shape)}`);
23834
23891
  continue;
23892
+ }
23835
23893
  const user = before.object(owner);
23836
23894
  usedBy.add(
23837
23895
  mapIsModule(user) ? `${user.anchor.path}: top-level code` : `${user.anchor.path}: ${before.qualifiedName(owner)}`
23838
23896
  );
23839
23897
  }
23840
23898
  }
23899
+ if (unfollowed.size)
23900
+ unclear.push(
23901
+ `${unfollowed.size} removed fields or types are used on lines the diff left alone, and whether that code now uses what took their place was not read (${[
23902
+ ...unfollowed
23903
+ ].sort().slice(0, LIST.names).join(
23904
+ ", "
23905
+ )}${unfollowed.size > LIST.names ? ", \u2026" : ""}); project_find_references lists their uses`
23906
+ );
23841
23907
  const removedAt = (ref) => {
23842
23908
  for (let at = ref; at !== void 0; at = before.parent(at))
23843
23909
  if (gone.includes(at)) return true;
@@ -23888,7 +23954,11 @@ async function mapChangeImpact(store, working, base, changes, shapes, until, pro
23888
23954
  if (gone.length) {
23889
23955
  await beforeTracer.trace(gone, gone);
23890
23956
  for (const entry of beforeTracer.entries.values())
23891
- if (!tracer.entries.has(entry.label)) tracer.entries.set(entry.label, entry);
23957
+ if (!tracer.entries.has(entry.label))
23958
+ tracer.entries.set(
23959
+ entry.label,
23960
+ entry.route && removedRoutes.includes(entry.label) ? { ...entry, removed: true } : entry
23961
+ );
23892
23962
  for (const [path17, test] of beforeTracer.tests) {
23893
23963
  const known = tracer.tests.get(path17);
23894
23964
  if (known) for (const name of test.names) known.names.add(name);
@@ -24471,7 +24541,7 @@ Nothing changed against ${changes.base}.`;
24471
24541
  "Use the existing code rather than a copy, or, if the new code replaces it, remove the old; keep both only when they are meant to differ. Code that does the same in other words is not found."
24472
24542
  );
24473
24543
  }
24474
- const entry = (item) => `${item.route ? JSON.stringify(item.label) : item.label}${item.chain.length ? ` \u2192 ${item.chain.join(" \u2192 ")}` : ""}${item.site ? ` (registered at ${item.site})` : ""}`;
24544
+ const entry = (item) => `${item.route ? JSON.stringify(item.label) : item.label}${item.chain.length ? ` \u2192 ${item.chain.join(" \u2192 ")}` : ""}${item.removed ? ` (the diff removes it${item.site ? `; registered at ${item.site} before` : ""})` : item.site ? ` (registered at ${item.site})` : ""}`;
24475
24545
  list(
24476
24546
  "AFFECTED ENTRY POINTS (through resolved calls)",
24477
24547
  impact.entries.filter((e) => e.certain).map(entry),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "layermap",
3
- "version": "0.1.37",
3
+ "version": "0.1.38",
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
@@ -293,7 +293,7 @@ function layermap(pi) {
293
293
  if (server && !server.dead) return server;
294
294
  starting ??= (async () => {
295
295
  const next = new MapServer(cwd);
296
- const tools = await next.start("0.1.37");
296
+ const tools = await next.start("0.1.38");
297
297
  for (const tool of tools) {
298
298
  if (registered.has(tool.name)) continue;
299
299
  registered.add(tool.name);