layermap 0.1.8 → 0.1.10

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
@@ -9,7 +9,7 @@
9
9
  [![npm downloads](https://img.shields.io/npm/dm/layermap)](https://www.npmjs.com/package/layermap)
10
10
  [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](https://github.com/coffeecoproject/layermap/blob/main/LICENSE)
11
11
 
12
- **LayerMap tells your coding agent what calls a function and what changing it affects, up to the HTTP routes, in one call.** With at most 15 requests, agents found **97.9%** of affected endpoints with LayerMap vs 58.8% without; with no limit, Claude Code cost **32% less** ([benchmark](https://github.com/coffeecoproject/layermap/blob/main/docs/benchmark.md)).
12
+ **LayerMap tells your coding agent what calls a function and what changing it affects, up to the HTTP routes, in one call.** With at most 15 requests, agents found **97.9%** of affected endpoints with LayerMap vs 58.8% without; with no limit, Claude Code cost **33% less** in the 0.1.5 re-run ([benchmark](https://github.com/coffeecoproject/layermap/blob/main/docs/benchmark.md)).
13
13
 
14
14
  **Resolved by each language's compiler or type checker, not guessed from names by tree-sitter:** calls through interfaces, base classes, templates and decorators link as the compiler links them, for TypeScript, JavaScript, Go, Python and Java.
15
15
 
@@ -66,19 +66,19 @@ projects, graded blind against truth sets cross-checked with each language's own
66
66
  | Endpoints found, at most 15 requests (`gpt-5.5`, 6 tasks × 3 runs) | **97.9%** | 58.8% |
67
67
  | Used unprompted by Claude Code / Codex (plugin installed, two rounds) | **12 of 12 / 12 of 12** | — |
68
68
  | Endpoints found, no request limit (Claude Code / Codex, 0.1.5) | 100% / 100% | 99.0% / 100% |
69
- | Claude Code cost, no request limit | **−33%** | |
69
+ | Claude Code cost, no request limit (0.1.5 re-run; first round −32%) | **−33%** | |
70
70
  | Codex input tokens, no request limit (current defaults) | +14% | |
71
71
  | Time, no request limit (Claude Code / Codex) | +25% / +20% | |
72
- | Failing tests the change check lists (Go / Python, functions made to fail) | **100% / 83–88%** | — |
73
- | Ripple tasks: runs leaving other features' tests passing (Codex / Claude Code, 4 tasks × 3 runs) | **11 of 12 / 7 of 12** | 3 of 12 / 4 of 12 |
72
+ | Failing tests the change check lists (Go / Python, functions made to fail) | **100% / 94–98%** | — |
73
+ | Ripple tasks: runs leaving other features' tests passing (Codex / Claude Code, 4 tasks × 6 runs with, × 3 without) | **23 of 24** / 11 of 24 | 3 of 12 / 4 of 12 |
74
74
 
75
75
  With a tight budget, the map finds far more of the affected code, at about 24% more tokens. With
76
76
  no limit, both agents find nearly everything either way. Claude Code costs a third less with the
77
77
  map. Codex's current defaults already search lean, so the map no longer saves it tokens; at
78
78
  reasoning effort max, in the first round, it saved 55%. Agents with the map explore more widely,
79
79
  which takes longer. On requests whose obvious change breaks another feature, the change check
80
- helped Codex keep to the requested feature; for Claude Code the gap could be chance, and both took
81
- longer. These are small samples on tasks written by LayerMap's authors.
80
+ helped Codex keep to the requested feature. Claude Code saw which tests of other features it had
81
+ changed but often kept the broader change on purpose, so it showed no clear difference. These are small samples on tasks written by LayerMap's authors.
82
82
  The [report](https://github.com/coffeecoproject/layermap/blob/main/docs/benchmark.md) has the
83
83
  setup, the published tasks and the limitations.
84
84
 
@@ -136,8 +136,8 @@ Claude Code asks once before each map tool runs in a project. Choose "don't ask
136
136
  **After an edit.** When the agent changes code, `project_check_changes` lists what the change
137
137
  affects: the routes, jobs and commands that reach the changed functions, what the map cannot see,
138
138
  and the existing tests related to the change. When the changed code serves several areas (packages
139
- or modules), it names each one with its tests, so a change meant for one feature does not quietly
140
- change the others. It never writes or runs tests. In Claude Code the
139
+ or modules), it names each one with its tests, and it names the existing tests the diff rewrote, so
140
+ a change meant for one feature does not quietly change the others. It never writes or runs tests. In Claude Code the
141
141
  plugin asks the agent once, before it finishes, to run this check if it edited code in the repository
142
142
  and has not checked since (changes another session makes in the same work tree do not count); set
143
143
  `LAYERMAP_STOP_CHECK=0` to turn that off. Codex and DeepSeek Harness are told to run it.
@@ -199,6 +199,14 @@ relationship does not prove absence.
199
199
 
200
200
  **Windows?** Not yet.
201
201
 
202
+ **Claude Code in print mode (`claude -p`)?** Print mode, as of Claude Code 2.1, does not start the
203
+ servers that installed plugins bring, so the map tools are missing there while the plugin's hooks
204
+ still run. Pass the server yourself:
205
+
206
+ ```bash
207
+ claude -p "..." --mcp-config '{"mcpServers":{"layermap":{"command":"npx","args":["-y","layermap","mcp"]}}}'
208
+ ```
209
+
202
210
  **How do I remove it?**
203
211
 
204
212
  - Claude Code: `/plugin uninstall layermap@layermap`.
@@ -120983,8 +120983,11 @@ var Extraction = class {
120983
120983
  this.classes = /* @__PURE__ */ new Map();
120984
120984
  // Lambdas assigned to one variable or attribute take that object's identity.
120985
120985
  this.carriers = /* @__PURE__ */ new Map();
120986
- // Names of project functions and methods: only such names can be a function used as a value.
120986
+ // Names of project functions, methods and classes: only such names can be a callable used as a
120987
+ // value.
120987
120988
  this.callableNames = /* @__PURE__ */ new Set();
120989
+ // Names of module-level variables: only such names can be a read of module state.
120990
+ this.stateNames = /* @__PURE__ */ new Set();
120988
120991
  this.fileObjects = /* @__PURE__ */ new Map();
120989
120992
  this.nodePaths = /* @__PURE__ */ new Map();
120990
120993
  }
@@ -121271,6 +121274,7 @@ var Declarer = class extends ParseTreeWalker {
121271
121274
  exported: isPublic(name) && outer.node.nodeType === 36 /* Module */
121272
121275
  });
121273
121276
  this.x.setClass(id, node);
121277
+ this.x.callableNames.add(name);
121274
121278
  if (outer.node.nodeType === 10 /* Class */) this.x.setMember(outer.id, name, id);
121275
121279
  if (outer.node.nodeType === 36 /* Module */) this.x.setGlobal(this.path, name, id);
121276
121280
  const doc = docstring(node.d.suite.d.statements);
@@ -121361,6 +121365,7 @@ var Declarer = class extends ParseTreeWalker {
121361
121365
  ...execution
121362
121366
  });
121363
121367
  this.x.setGlobal(this.path, name.d.value, id);
121368
+ this.x.stateNames.add(name.d.value);
121364
121369
  if (closure) this.x.setCarrier(closure, id);
121365
121370
  } else if (scope.node.nodeType === 10 /* Class */) {
121366
121371
  if (this.x.member(scope.id, name.d.value) !== void 0) return;
@@ -121413,6 +121418,25 @@ var Declarer = class extends ParseTreeWalker {
121413
121418
  }
121414
121419
  }
121415
121420
  };
121421
+ function inAnnotation(node) {
121422
+ for (let child = node, parent = node.parent; parent; child = parent, parent = parent.parent)
121423
+ switch (parent.nodeType) {
121424
+ case 54 /* TypeAnnotation */:
121425
+ if (parent.d.annotation === child) return true;
121426
+ break;
121427
+ case 41 /* Parameter */: {
121428
+ const parameter = parent;
121429
+ return parameter.d.annotation === child || parameter.d.annotationComment === child;
121430
+ }
121431
+ case 31 /* Function */:
121432
+ return parent.d.returnAnnotation === child;
121433
+ case 47 /* StatementList */:
121434
+ case 50 /* Suite */:
121435
+ case 33 /* Lambda */:
121436
+ return false;
121437
+ }
121438
+ return false;
121439
+ }
121416
121440
  var Relater = class extends ParseTreeWalker {
121417
121441
  constructor(x2, path3, file2, module) {
121418
121442
  super();
@@ -121654,6 +121678,7 @@ var Relater = class extends ParseTreeWalker {
121654
121678
  switch (parent.nodeType) {
121655
121679
  case 1 /* Argument */:
121656
121680
  if (parent.d.name === node) return false;
121681
+ if (parent.parent?.nodeType === 10 /* Class */) return false;
121657
121682
  break;
121658
121683
  case 31 /* Function */:
121659
121684
  case 10 /* Class */:
@@ -121669,13 +121694,20 @@ var Relater = class extends ParseTreeWalker {
121669
121694
  this.valueUse(node, node);
121670
121695
  return false;
121671
121696
  }
121672
- // A project function or method used as a value: passed, stored or returned.
121697
+ // A project function, method or class used as a value (passed, stored or returned, as
121698
+ // functools.partial(Client, ...) passes a class), or a module-level variable read: a change to
121699
+ // either changes what the user does. A class named in a type annotation is not a use.
121673
121700
  valueUse(name, expression) {
121674
- if (!this.x.callableNames.has(name.d.value)) return;
121701
+ const callable = this.x.callableNames.has(name.d.value);
121702
+ const state = this.x.stateNames.has(name.d.value);
121703
+ if (!callable && !state) return;
121675
121704
  for (const declaration of this.x.declarations(name)) {
121676
- if (declaration.type !== 5 /* Function */) continue;
121705
+ const read = state && declaration.type === 1 /* Variable */;
121706
+ const value = callable && (declaration.type === 5 /* Function */ || declaration.type === 6 /* Class */ && !inAnnotation(expression));
121707
+ if (!read && !value) continue;
121677
121708
  const to = this.x.objectOf(declaration);
121678
121709
  if (to === void 0) continue;
121710
+ if (read && this.x.global(this.x.object(to).path, name.d.value) !== to) continue;
121679
121711
  this.relation({
121680
121712
  kind: "REFERENCES",
121681
121713
  from: this.top(this.declared),
@@ -4832,6 +4832,9 @@ function isCatchClause(node) {
4832
4832
  function isBlock(node) {
4833
4833
  return node.kind === SyntaxKind.Block;
4834
4834
  }
4835
+ function isVariableStatement(node) {
4836
+ return node.kind === SyntaxKind.VariableStatement;
4837
+ }
4835
4838
  function isVariableDeclaration(node) {
4836
4839
  return node.kind === SyntaxKind.VariableDeclaration;
4837
4840
  }
@@ -4868,6 +4871,12 @@ function isImportDeclaration(node) {
4868
4871
  return false;
4869
4872
  }
4870
4873
  }
4874
+ function isNamespaceImport(node) {
4875
+ return node.kind === SyntaxKind.NamespaceImport;
4876
+ }
4877
+ function isNamedImports(node) {
4878
+ return node.kind === SyntaxKind.NamedImports;
4879
+ }
4871
4880
  function isMethodDeclaration(node) {
4872
4881
  return node.kind === SyntaxKind.MethodDeclaration;
4873
4882
  }
@@ -16053,6 +16062,7 @@ var MapTargetResolver = class {
16053
16062
  input;
16054
16063
  mapDeclaration;
16055
16064
  cache = /* @__PURE__ */ new Map();
16065
+ mappedCache = /* @__PURE__ */ new Map();
16056
16066
  async resolve(symbol2) {
16057
16067
  if (this.input.syntaxOnly) return { objects: [], unresolvedReason: "SYNTAX_ONLY" };
16058
16068
  if (!symbol2) return { objects: [], unresolvedReason: "SYMBOL_NOT_RESOLVED" };
@@ -16096,6 +16106,24 @@ var MapTargetResolver = class {
16096
16106
  this.cache.set(original, result);
16097
16107
  return result;
16098
16108
  }
16109
+ // The module-level variables a read resolves to, among those already mapped: a read of anything
16110
+ // else (a local, a parameter, a library value) links nothing and materializes nothing.
16111
+ async resolveMapped(symbol2, mapped) {
16112
+ if (this.input.syntaxOnly || !symbol2) return [];
16113
+ const cached2 = this.mappedCache.get(symbol2.id);
16114
+ if (cached2) return cached2;
16115
+ const target = symbol2.flags & SymbolFlags.Alias ? await this.project.checker.getAliasedSymbol(symbol2) : symbol2;
16116
+ const objects = [];
16117
+ if (target.flags & SymbolFlags.Variable)
16118
+ for (const handle of target.declarations) {
16119
+ if (mapRelativePath(handle.path) === void 0) continue;
16120
+ const node = await handle.resolve(this.project);
16121
+ const object2 = node && mapped(node);
16122
+ if (object2) objects.push(object2);
16123
+ }
16124
+ this.mappedCache.set(symbol2.id, objects);
16125
+ return objects;
16126
+ }
16099
16127
  // A value links only a function, a method or a binding initialized with a function expression.
16100
16128
  // Other values stay unlinked, so resolving them never materializes locals.
16101
16129
  async resolveCallable(symbol2) {
@@ -31039,6 +31067,36 @@ var declarationName = (node) => {
31039
31067
  const name = mapDeclarationName(node);
31040
31068
  return execution?.name ?? (name ? mapNodeLabel(name) : "");
31041
31069
  };
31070
+ var NOT_STATE_READS = /* @__PURE__ */ new Set([
31071
+ SyntaxKind.PropertyAssignment,
31072
+ SyntaxKind.ImportClause,
31073
+ SyntaxKind.ExportSpecifier,
31074
+ SyntaxKind.TypeReference,
31075
+ SyntaxKind.TypeQuery,
31076
+ SyntaxKind.QualifiedName,
31077
+ SyntaxKind.ExpressionWithTypeArguments,
31078
+ SyntaxKind.JsxOpeningElement,
31079
+ SyntaxKind.JsxSelfClosingElement,
31080
+ SyntaxKind.JsxClosingElement
31081
+ ]);
31082
+ function moduleStateNames(file2) {
31083
+ const names = /* @__PURE__ */ new Set();
31084
+ const namespaces = /* @__PURE__ */ new Set();
31085
+ for (const statement of file2.statements) {
31086
+ if (isVariableStatement(statement)) {
31087
+ for (const declaration of statement.declarationList.declarations)
31088
+ if (isIdentifier(declaration.name)) names.add(declaration.name.text);
31089
+ } else if (isImportDeclaration(statement) && statement.importClause) {
31090
+ const clause = statement.importClause;
31091
+ if (clause.name) names.add(clause.name.text);
31092
+ const bindings = clause.namedBindings;
31093
+ if (bindings && isNamespaceImport(bindings)) namespaces.add(bindings.name.text);
31094
+ else if (bindings && isNamedImports(bindings))
31095
+ for (const element of bindings.elements) names.add(element.name.text);
31096
+ }
31097
+ }
31098
+ return { names, namespaces };
31099
+ }
31042
31100
  async function extractProjectMap(project, input, trace) {
31043
31101
  const output = {
31044
31102
  contexts: [],
@@ -31067,6 +31125,7 @@ async function extractProjectMap(project, input, trace) {
31067
31125
  const declarations = [];
31068
31126
  const exportedSymbols = /* @__PURE__ */ new Map();
31069
31127
  const pending = [];
31128
+ const moduleVariables = /* @__PURE__ */ new Set();
31070
31129
  const contracts = [];
31071
31130
  const callableHolders = /* @__PURE__ */ new Set();
31072
31131
  const valueNames = /* @__PURE__ */ new Set();
@@ -31149,6 +31208,7 @@ async function extractProjectMap(project, input, trace) {
31149
31208
  const fileObject = addObject(file2, file2, "FILE", path6);
31150
31209
  if (!owned.has(path6)) continue;
31151
31210
  exportedSymbols.set(file2.fileName, exports);
31211
+ const state = moduleStateNames(file2);
31152
31212
  trace.phase = "TRAVERSAL";
31153
31213
  const stack = [
31154
31214
  { node: file2, owner: fileObject, execution: fileObject, declarationExecution: fileObject }
@@ -31183,6 +31243,8 @@ async function extractProjectMap(project, input, trace) {
31183
31243
  basis: "SYNTAX_DECLARED"
31184
31244
  });
31185
31245
  if (owned.has(path6) && name) declarations.push({ object: object2, name, node, file: file2 });
31246
+ if (object2.kind === "VARIABLE" && !object2.execution && item.owner.kind === "FILE")
31247
+ moduleVariables.add(object2.id);
31186
31248
  owner = object2;
31187
31249
  if (kind === "INTERFACE" && owned.has(path6)) {
31188
31250
  const note = {
@@ -31246,6 +31308,14 @@ async function extractProjectMap(project, input, trace) {
31246
31308
  holder: mapValueProperty(node),
31247
31309
  ...route ? { argument: route } : {}
31248
31310
  };
31311
+ } else if (isPropertyAccessExpression(node) && isIdentifier(node.expression) && state.namespaces.has(node.expression.text)) {
31312
+ reference = {
31313
+ node,
31314
+ lookup: node.name,
31315
+ kind: "REFERENCES",
31316
+ target: node.name.text,
31317
+ state: true
31318
+ };
31249
31319
  }
31250
31320
  } else if (isIdentifier(node) && mapDeclarationName(node.parent) !== node) {
31251
31321
  const parent = node.parent;
@@ -31262,7 +31332,8 @@ async function extractProjectMap(project, input, trace) {
31262
31332
  holder: mapValueProperty(node),
31263
31333
  ...route ? { argument: route } : {}
31264
31334
  };
31265
- }
31335
+ } else if (state.names.has(node.text) && !(isPropertyAccessExpression(parent) && parent.name === node) && !NOT_STATE_READS.has(parent.kind) && !isImportSpecifier(parent))
31336
+ reference = { node, lookup: node, kind: "REFERENCES", target: node.text, state: true };
31266
31337
  }
31267
31338
  } else if (isShorthandPropertyAssignment(node)) {
31268
31339
  reference = {
@@ -31384,10 +31455,14 @@ async function extractProjectMap(project, input, trace) {
31384
31455
  return object2;
31385
31456
  };
31386
31457
  const targets = new MapTargetResolver(project, input, materialize);
31458
+ const moduleVariable = (node) => {
31459
+ const object2 = declared.get(key(node));
31460
+ return object2 && moduleVariables.has(object2.id) ? object2 : void 0;
31461
+ };
31387
31462
  for (const object2 of declared.values())
31388
31463
  if (object2.execution && object2.execution !== "MODULE") valueNames.add(object2.name);
31389
31464
  const linkable = pending.filter(
31390
- (item) => item.kind !== "REFERENCES" || valueNames.has(item.target) || isPropertyAccessExpression(item.node) && isIdentifier(item.node.expression) && namespaces.has(item.node.expression.text)
31465
+ (item) => item.kind !== "REFERENCES" || item.state || valueNames.has(item.target) || isPropertyAccessExpression(item.node) && isIdentifier(item.node.expression) && namespaces.has(item.node.expression.text)
31391
31466
  );
31392
31467
  for (let start = 0; start < linkable.length; start += 128) {
31393
31468
  const batch = linkable.slice(start, start + 128);
@@ -31395,6 +31470,18 @@ async function extractProjectMap(project, input, trace) {
31395
31470
  const symbols = await project.checker.getSymbolAtLocation(batch.map((item) => item.lookup));
31396
31471
  trace.phase = "RELATION_TARGETS";
31397
31472
  for (const [index, item] of batch.entries()) {
31473
+ if (item.state) {
31474
+ for (const destination of await targets.resolveMapped(symbols[index], moduleVariable))
31475
+ collect.relation({
31476
+ from: item.owner,
31477
+ to: destination.id,
31478
+ kind: "REFERENCES",
31479
+ anchor: item.anchor,
31480
+ target: item.target,
31481
+ basis: "TYPE_RESOLVED"
31482
+ });
31483
+ continue;
31484
+ }
31398
31485
  if (item.kind === "REFERENCES") {
31399
31486
  const symbol2 = isShorthandPropertyAssignment(item.node) ? await project.checker.getShorthandAssignmentValueSymbol(item.node) : symbols[index];
31400
31487
  const callable = await targets.resolveCallable(symbol2);