layermap 0.1.9 → 0.1.11

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
@@ -69,8 +69,9 @@ projects, graded blind against truth sets cross-checked with each language's own
69
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%** | — |
72
+ | Failing tests the change check lists (Go / Python, functions made to fail) | **100% / 94–98%** | — |
73
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
+ | Everyday tasks, no impact analysis needed: done right / time (Claude Code and Codex, 8 tasks × 2 runs) | 32 of 32 / +20–22% | 32 of 32 |
74
75
 
75
76
  With a tight budget, the map finds far more of the affected code, at about 24% more tokens. With
76
77
  no limit, both agents find nearly everything either way. Claude Code costs a third less with the
@@ -78,7 +79,8 @@ map. Codex's current defaults already search lean, so the map no longer saves it
78
79
  reasoning effort max, in the first round, it saved 55%. Agents with the map explore more widely,
79
80
  which takes longer. On requests whose obvious change breaks another feature, the change check
80
81
  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
+ changed but often kept the broader change on purpose, so it showed no clear difference. On small
83
+ local tasks the map changed nothing but cost about a fifth more time and money. These are small samples on tasks written by LayerMap's authors.
82
84
  The [report](https://github.com/coffeecoproject/layermap/blob/main/docs/benchmark.md) has the
83
85
  setup, the published tasks and the limitations.
84
86
 
@@ -199,6 +201,14 @@ relationship does not prove absence.
199
201
 
200
202
  **Windows?** Not yet.
201
203
 
204
+ **Claude Code in print mode (`claude -p`)?** Print mode, as of Claude Code 2.1, does not start the
205
+ servers that installed plugins bring, so the map tools are missing there while the plugin's hooks
206
+ still run. Pass the server yourself:
207
+
208
+ ```bash
209
+ claude -p "..." --mcp-config '{"mcpServers":{"layermap":{"command":"npx","args":["-y","layermap","mcp"]}}}'
210
+ ```
211
+
202
212
  **How do I remove it?**
203
213
 
204
214
  - Claude Code: `/plugin uninstall layermap@layermap`.
Binary file
Binary file
Binary file
Binary file
@@ -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,11 +121418,32 @@ 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();
121419
121443
  this.x = x2;
121420
121444
  this.path = path3;
121445
+ // Module variables each declaration reads, recorded once.
121446
+ this.reads = /* @__PURE__ */ new Set();
121421
121447
  this.scopes = [];
121422
121448
  this.callees = /* @__PURE__ */ new Set();
121423
121449
  // Names a function declares global.
@@ -121654,6 +121680,7 @@ var Relater = class extends ParseTreeWalker {
121654
121680
  switch (parent.nodeType) {
121655
121681
  case 1 /* Argument */:
121656
121682
  if (parent.d.name === node) return false;
121683
+ if (parent.parent?.nodeType === 10 /* Class */) return false;
121657
121684
  break;
121658
121685
  case 31 /* Function */:
121659
121686
  case 10 /* Class */:
@@ -121669,16 +121696,29 @@ var Relater = class extends ParseTreeWalker {
121669
121696
  this.valueUse(node, node);
121670
121697
  return false;
121671
121698
  }
121672
- // A project function or method used as a value: passed, stored or returned.
121699
+ // A project function, method or class used as a value (passed, stored or returned, as
121700
+ // functools.partial(Client, ...) passes a class), or a module-level variable read: a change to
121701
+ // either changes what the user does. A class named in a type annotation is not a use.
121673
121702
  valueUse(name, expression) {
121674
- if (!this.x.callableNames.has(name.d.value)) return;
121703
+ const callable = this.x.callableNames.has(name.d.value);
121704
+ const state = this.x.stateNames.has(name.d.value);
121705
+ if (!callable && !state) return;
121675
121706
  for (const declaration of this.x.declarations(name)) {
121676
- if (declaration.type !== 5 /* Function */) continue;
121707
+ const read = state && declaration.type === 1 /* Variable */;
121708
+ const value = callable && (declaration.type === 5 /* Function */ || declaration.type === 6 /* Class */ && !inAnnotation(expression));
121709
+ if (!read && !value) continue;
121677
121710
  const to = this.x.objectOf(declaration);
121678
121711
  if (to === void 0) continue;
121712
+ if (read && this.x.global(this.x.object(to).path, name.d.value) !== to) continue;
121713
+ const from = this.top(this.declared);
121714
+ if (read && !value) {
121715
+ const key = `${from}\0${to}`;
121716
+ if (this.reads.has(key)) return;
121717
+ this.reads.add(key);
121718
+ }
121679
121719
  this.relation({
121680
121720
  kind: "REFERENCES",
121681
- from: this.top(this.declared),
121721
+ from,
121682
121722
  to,
121683
121723
  start: expression.start,
121684
121724
  end: end(expression),
@@ -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,8 @@ 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();
31129
+ const stateReads = /* @__PURE__ */ new Set();
31070
31130
  const contracts = [];
31071
31131
  const callableHolders = /* @__PURE__ */ new Set();
31072
31132
  const valueNames = /* @__PURE__ */ new Set();
@@ -31149,6 +31209,7 @@ async function extractProjectMap(project, input, trace) {
31149
31209
  const fileObject = addObject(file2, file2, "FILE", path6);
31150
31210
  if (!owned.has(path6)) continue;
31151
31211
  exportedSymbols.set(file2.fileName, exports);
31212
+ const state = moduleStateNames(file2);
31152
31213
  trace.phase = "TRAVERSAL";
31153
31214
  const stack = [
31154
31215
  { node: file2, owner: fileObject, execution: fileObject, declarationExecution: fileObject }
@@ -31183,6 +31244,8 @@ async function extractProjectMap(project, input, trace) {
31183
31244
  basis: "SYNTAX_DECLARED"
31184
31245
  });
31185
31246
  if (owned.has(path6) && name) declarations.push({ object: object2, name, node, file: file2 });
31247
+ if (object2.kind === "VARIABLE" && !object2.execution && item.owner.kind === "FILE")
31248
+ moduleVariables.add(object2.id);
31186
31249
  owner = object2;
31187
31250
  if (kind === "INTERFACE" && owned.has(path6)) {
31188
31251
  const note = {
@@ -31246,6 +31309,14 @@ async function extractProjectMap(project, input, trace) {
31246
31309
  holder: mapValueProperty(node),
31247
31310
  ...route ? { argument: route } : {}
31248
31311
  };
31312
+ } else if (isPropertyAccessExpression(node) && isIdentifier(node.expression) && state.namespaces.has(node.expression.text)) {
31313
+ reference = {
31314
+ node,
31315
+ lookup: node.name,
31316
+ kind: "REFERENCES",
31317
+ target: node.name.text,
31318
+ state: true
31319
+ };
31249
31320
  }
31250
31321
  } else if (isIdentifier(node) && mapDeclarationName(node.parent) !== node) {
31251
31322
  const parent = node.parent;
@@ -31262,7 +31333,8 @@ async function extractProjectMap(project, input, trace) {
31262
31333
  holder: mapValueProperty(node),
31263
31334
  ...route ? { argument: route } : {}
31264
31335
  };
31265
- }
31336
+ } else if (state.names.has(node.text) && !(isPropertyAccessExpression(parent) && parent.name === node) && !NOT_STATE_READS.has(parent.kind) && !isImportSpecifier(parent))
31337
+ reference = { node, lookup: node, kind: "REFERENCES", target: node.text, state: true };
31266
31338
  }
31267
31339
  } else if (isShorthandPropertyAssignment(node)) {
31268
31340
  reference = {
@@ -31384,10 +31456,14 @@ async function extractProjectMap(project, input, trace) {
31384
31456
  return object2;
31385
31457
  };
31386
31458
  const targets = new MapTargetResolver(project, input, materialize);
31459
+ const moduleVariable = (node) => {
31460
+ const object2 = declared.get(key(node));
31461
+ return object2 && moduleVariables.has(object2.id) ? object2 : void 0;
31462
+ };
31387
31463
  for (const object2 of declared.values())
31388
31464
  if (object2.execution && object2.execution !== "MODULE") valueNames.add(object2.name);
31389
31465
  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)
31466
+ (item) => item.kind !== "REFERENCES" || item.state || valueNames.has(item.target) || isPropertyAccessExpression(item.node) && isIdentifier(item.node.expression) && namespaces.has(item.node.expression.text)
31391
31467
  );
31392
31468
  for (let start = 0; start < linkable.length; start += 128) {
31393
31469
  const batch = linkable.slice(start, start + 128);
@@ -31395,6 +31471,22 @@ async function extractProjectMap(project, input, trace) {
31395
31471
  const symbols = await project.checker.getSymbolAtLocation(batch.map((item) => item.lookup));
31396
31472
  trace.phase = "RELATION_TARGETS";
31397
31473
  for (const [index, item] of batch.entries()) {
31474
+ if (item.state) {
31475
+ for (const destination of await targets.resolveMapped(symbols[index], moduleVariable)) {
31476
+ const read = `${item.owner}\0${destination.id}`;
31477
+ if (stateReads.has(read)) continue;
31478
+ stateReads.add(read);
31479
+ collect.relation({
31480
+ from: item.owner,
31481
+ to: destination.id,
31482
+ kind: "REFERENCES",
31483
+ anchor: item.anchor,
31484
+ target: item.target,
31485
+ basis: "TYPE_RESOLVED"
31486
+ });
31487
+ }
31488
+ continue;
31489
+ }
31398
31490
  if (item.kind === "REFERENCES") {
31399
31491
  const symbol2 = isShorthandPropertyAssignment(item.node) ? await project.checker.getShorthandAssignmentValueSymbol(item.node) : symbols[index];
31400
31492
  const callable = await targets.resolveCallable(symbol2);
package/dist/cli.mjs CHANGED
@@ -17765,7 +17765,7 @@ function runMapOperation(resources, input, schema, signal, observeTiming) {
17765
17765
  var goModule = /(?:^|\/)go\.mod$/u;
17766
17766
  var codeHosts = /* @__PURE__ */ new Set(["github.com", "gitlab.com", "bitbucket.org"]);
17767
17767
  var GO_MAP_LANGUAGE = Object.freeze({
17768
- id: "go-1.24-map-v8",
17768
+ id: "go-1.24-map-v9",
17769
17769
  claims: (path11) => path11.endsWith(".go"),
17770
17770
  reads: (path11) => goModule.test(path11),
17771
17771
  // A module path, or the standard library, whose first path element has no dot.
@@ -17918,7 +17918,7 @@ var nameOf = (path11) => path11.slice(path11.lastIndexOf("/") + 1);
17918
17918
  var DEFAULT_RELEASE = 21;
17919
17919
  var platformPackage = /^(?:java|jdk|sun|com\.sun|javax\.(?:annotation\.processing|crypto|imageio|lang\.model|management|naming|net|print|script|security|sound|sql|swing|tools|transaction\.xa|xml))(?:\.|$)/u;
17920
17920
  var JAVA_MAP_LANGUAGE = Object.freeze({
17921
- id: "javac-lombok-1.18.48-map-v6",
17921
+ id: "javac-lombok-1.18.48-map-v8",
17922
17922
  claims: (path11) => path11.endsWith(".java"),
17923
17923
  reads: (path11) => buildFile.test(path11),
17924
17924
  // A package of the Java platform, or a library named by its first two package segments.
@@ -18470,7 +18470,7 @@ var pythonConfig = /(?:^|\/)(?:pyrightconfig\.json|pyproject\.toml|setup\.cfg)$/
18470
18470
  var directoryOf2 = (path11) => path11.slice(0, path11.lastIndexOf("/") + 1);
18471
18471
  var DEFAULT_PYTHON = { major: 3, minor: 13 };
18472
18472
  var PYTHON_MAP_LANGUAGE = Object.freeze({
18473
- id: "pyright-1.1.414-map-v10",
18473
+ id: "pyright-1.1.414-map-v13",
18474
18474
  claims: (path11) => /\.pyi?$/u.test(path11),
18475
18475
  reads: (path11) => pythonConfig.test(path11),
18476
18476
  // An absolute import names the standard library or a distribution's top-level package.
@@ -18625,7 +18625,7 @@ var PythonMapAnalyzer = class {
18625
18625
 
18626
18626
  // src/project-map-language-typescript.ts
18627
18627
  var TYPESCRIPT_MAP_LANGUAGE = Object.freeze({
18628
- id: "typescript-7.0.2-map-v15",
18628
+ id: "typescript-7.0.2-map-v17",
18629
18629
  claims: (path11) => /\.[cm]?[jt]sx?$/u.test(path11),
18630
18630
  reads: (path11) => path11.endsWith(".json") || path11 === "pnpm-workspace.yaml",
18631
18631
  create: () => new TypeScriptMapAnalyzer()
@@ -22133,7 +22133,11 @@ var Tracer = class {
22133
22133
  if (CALLER_KINDS.has(relation.kind)) {
22134
22134
  const owner = this.graph.owner(relation.from);
22135
22135
  if (owner !== ref && owner !== parent)
22136
- callers.push({ ref: owner, relation, certain: constructs });
22136
+ callers.push({
22137
+ ref: owner,
22138
+ relation,
22139
+ certain: constructs && relation.kind === "CALLS"
22140
+ });
22137
22141
  }
22138
22142
  }
22139
22143
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "layermap",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
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",