layermap 0.1.9 → 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
|
@@ -69,7 +69,7 @@ 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% /
|
|
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
74
|
|
|
75
75
|
With a tight budget, the map finds far more of the affected code, at about 24% more tokens. With
|
|
@@ -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`.
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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);
|
package/dist/cli.mjs
CHANGED
|
@@ -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-
|
|
17921
|
+
id: "javac-lombok-1.18.48-map-v7",
|
|
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-
|
|
18473
|
+
id: "pyright-1.1.414-map-v12",
|
|
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-
|
|
18628
|
+
id: "typescript-7.0.2-map-v16",
|
|
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({
|
|
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.
|
|
3
|
+
"version": "0.1.10",
|
|
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",
|