Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.
TypeScript antigravity-skillsbusiness-knowledgeclaude-codeclaude-skillscodebase-analysiscodexcodex-skillsdeveloper-tools-ai-agentgemini-cli-skillskarpathy-llm-wikiknowledge-baseknowledge-graphmemoryopencode-skillspi-agentunderstandcodevibe-coding
fix(incremental): reject deletion claims with unresolved source names
Lum1104f95ff9b922c4
diff --git a/tests/skill/understand/test_incremental_symbols.test.mjs b/tests/skill/understand/test_incremental_symbols.test.mjsindex 0f1f5886..8da66e0e 100644--- a/tests/skill/understand/test_incremental_symbols.test.mjs+++ b/tests/skill/understand/test_incremental_symbols.test.mjs@@ -101,6 +101,9 @@ describe('incremental symbol matching', () => {['empty extraction', '// everything removed'],['unextracted arrow method', 'class A { run = () => {}; }'],['computed method', 'class A { ["run"]() {} }'],+ ['computed name fragments', 'class A { ["r" + "un"]() {} keep() {} }'],+ ['escaped identifier', String.raw`class A { r\u0075n() {} keep() {} }`],+ ['escaped string method name', String.raw`class A { "r\u0075n"() {} keep() {} }`],['moved method', 'class B { run() {} }'],])('treats %s as unknown, never deletion', (_label, code) => {expect(compare([node('A.run')], [], 'class A { run() {} }', code).missing[0].status).toBe('unknown');@@ -113,6 +116,16 @@ describe('incremental symbol matching', () => {}});+ it('does not confirm deletion when escaped names disappear or strict-parser evidence is outdated', () => {+ const escaped = String.raw`A.r\u0075n`;+ expect(compare([node(escaped)], [], String.raw`class A { r\u0075n() {} }`, 'class A { run() {} keep() {} }')+ .missing[0].status).toBe('unknown');+ const outdated = { ...parse('class A { keep() {} }') };+ delete outdated.hasUnresolvedNames;+ const result = compareFileSymbols(graph([node('A.run')]), graph([]), parse('class A { run() {} }'), outdated);+ expect(result.missing[0].status).toBe('unknown');+ });+it('cannot use one new node to replace two old nodes with the same source identity', () => {const code = 'function f() {}';const result = compare([node('f', { id: 'old:one' }), node('f', { id: 'old:two' })],diff --git a/tests/skill/understand/test_prepare_incremental.test.mjs b/tests/skill/understand/test_prepare_incremental.test.mjsindex 7eb23a1f..2e5e4852 100644--- a/tests/skill/understand/test_prepare_incremental.test.mjs+++ b/tests/skill/understand/test_prepare_incremental.test.mjs@@ -232,6 +232,23 @@ afterEach(async () => {});describe('incremental symbol publication gate', { timeout: 30_000 }, () => {+ it('does not publish a missing method whose computed source name still denotes the old symbol', () => {+ const f = symbolFixture(2);+ const source = 'export class Service { ["method" + "0"]() { return 1; } method1() {} }\n';+ expect(Object.hasOwn(class { ['method' + '0']() {} }.prototype, 'method0')).toBe(true);+ writeProjectFile(f.root, 'src/a.ts', source);+ commit(f.root, 'use a computed method name');+ const before = f.persisted();+ prepare(f.root, f.baseCommit);+ f.write('batch-1.json', { nodes: [f.fileNode, f.classNode, f.methodNodes[1]], edges: [] });+ expect(spawnSync(python, [mergeScript, f.root]).status).toBe(1);+ expect(f.read('incremental-symbol-report.json').files[0].missing[0]).toMatchObject({+ id: f.methodNodes[0].id, status: 'unknown',+ });+ expect(spawnSync(process.execPath, [finalizeScript, f.root]).status).toBe(1);+ expect(f.persisted()).toEqual(before);+ });+it('checks generic method identity against source when both graphs omit every class node', () => {const f = symbolFixture(2, { 'src/a.ts': 'export class A { run() {} }\n' });const generic = { ...f.methodNodes[0], id: 'function:src/a.ts:run', name: 'run', lineRange: [1, 1] };diff --git a/understand-anything-plugin/packages/core/src/plugins/tree-sitter-plugin.test.ts b/understand-anything-plugin/packages/core/src/plugins/tree-sitter-plugin.test.tsindex a0a324c5..b94231d9 100644--- a/understand-anything-plugin/packages/core/src/plugins/tree-sitter-plugin.test.ts+++ b/understand-anything-plugin/packages/core/src/plugins/tree-sitter-plugin.test.ts@@ -376,6 +376,21 @@ export class Greeter {expect(strict.structure).toEqual(plugin.analyzeFile("test.ts", code));expect(strict.structure?.classes[0].methods).toEqual(["run"]);expect(strict.leafTexts).toContain("callback");+ expect(strict.hasUnresolvedNames).toBe(false);+ });++ it("exposes unresolved computed and escaped declaration names", () => {+ for (const code of [+ 'class A { ["r" + "un"]() {} keep() {} }',+ String.raw`class A { r\u0075n() {} keep() {} }`,+ String.raw`class A { "r\u0075n"() {} keep() {} }`,+ ]) {+ const result = plugin.analyzeFileStrict("test.js", code);+ expect(result.status).toBe("succeeded");+ expect(result.hasUnresolvedNames).toBe(true);+ }+ expect(plugin.analyzeFileStrict("test.js", String.raw`function keep(r\u0075n) { return r\u0075n; }`)+ .hasUnresolvedNames).toBe(false);});});diff --git a/understand-anything-plugin/packages/core/src/plugins/tree-sitter-plugin.ts b/understand-anything-plugin/packages/core/src/plugins/tree-sitter-plugin.tsindex 3c3f7c34..c9986bab 100644--- a/understand-anything-plugin/packages/core/src/plugins/tree-sitter-plugin.ts+++ b/understand-anything-plugin/packages/core/src/plugins/tree-sitter-plugin.ts@@ -277,6 +277,7 @@ export class TreeSitterPlugin implements AnalyzerPlugin {status: "succeeded" | "unsupported" | "failed";structure: StructuralAnalysis | null;leafTexts: string[];+ hasUnresolvedNames: boolean;} {let tree: ReturnType<TreeSitterParser["parse"]> = null;try {@@ -284,26 +285,45 @@ export class TreeSitterPlugin implements AnalyzerPlugin {const langKey = this.languageKeyFromPath(filePath);const extractor = langKey ? this.getExtractor(langKey) : null;if (!parser || !extractor) {- return { status: "unsupported", structure: null, leafTexts: [] };+ return { status: "unsupported", structure: null, leafTexts: [], hasUnresolvedNames: false };}tree = parser.parse(content);if (!tree || tree.rootNode.hasError) {- return { status: "failed", structure: null, leafTexts: [] };+ return { status: "failed", structure: null, leafTexts: [], hasUnresolvedNames: false };}const leafTexts = new Set<string>();+ const structure = extractor.extractStructure(tree.rootNode);+ const declarationNames = [+ ...structure.functions.map(fn => fn.name),+ ...structure.classes.flatMap(cls => [cls.name, ...cls.methods, ...cls.properties]),+ ];+ let hasUnresolvedNames = declarationNames.some(name =>+ name.includes("\\") || name.includes("`") || name.startsWith("@")+ || name.startsWith("r#") || name.normalize("NFKC") !== name,+ );const pending = [tree.rootNode];while (pending.length > 0) {const node = pending.pop()!;+ const methodName = ["method_definition", "method_signature", "abstract_method_signature"].includes(node.type)+ ? node.childForFieldName("name") : null;+ // Valid syntax is not necessarily a name the extractor can resolve.+ // Computed members and escaped spellings can denote an old symbol+ // without its literal name appearing anywhere among the AST leaves.+ if (node.type === "computed_property_name"+ || (methodName?.type === "string" && methodName.text.includes("\\"))) {+ hasUnresolvedNames = true;+ }if (node.childCount === 0) leafTexts.add(node.text);else pending.push(...node.children);}return {status: "succeeded",- structure: extractor.extractStructure(tree.rootNode),+ structure,leafTexts: [...leafTexts],+ hasUnresolvedNames,};} catch {- return { status: "failed", structure: null, leafTexts: [] };+ return { status: "failed", structure: null, leafTexts: [], hasUnresolvedNames: false };} finally {tree?.delete();}diff --git a/understand-anything-plugin/skills/understand/SKILL.md b/understand-anything-plugin/skills/understand/SKILL.mdindex 7cbb203a..96b02c13 100644--- a/understand-anything-plugin/skills/understand/SKILL.md+++ b/understand-anything-plugin/skills/understand/SKILL.md@@ -416,6 +416,8 @@ Before dropping dangling endpoints, merge records normalized edge candidates froCandidate endpoints use the current analysis's node and ownership descriptors before any baseline alias is applied: an ID reused by a different current symbol must keep its current meaning. During repair, incoming edges are deferred outside the ordinary retained batch until those original HEAD descriptors can be matched against replacement nodes, so temporary ID reuse cannot create a false edge during merge.+A syntactically valid parse is insufficient to prove deletion when declaration names remain computed or escaped. The strict parser marks this uncertainty, and missing symbols remain `unknown` rather than being treated as deleted merely because their literal spelling is absent.+When the report has `unresolvedFiles`, prepare exactly one repair:```bashdiff --git a/understand-anything-plugin/skills/understand/validate-incremental-symbols.mjs b/understand-anything-plugin/skills/understand/validate-incremental-symbols.mjsindex 0159b3f2..ec495b65 100644--- a/understand-anything-plugin/skills/understand/validate-incremental-symbols.mjs+++ b/understand-anything-plugin/skills/understand/validate-incremental-symbols.mjs@@ -168,6 +168,10 @@ export function compareFileSymbols(previous, current, baseEvidence, headEvidenceentry.reason = 'Current source has ambiguous same-name symbols';} else if (headSource.length === 0) {entry.reason = 'Empty structural extraction is not proof of deletion';+ } else if (typeof baseEvidence.hasUnresolvedNames !== 'boolean' || typeof headEvidence.hasUnresolvedNames !== 'boolean') {+ entry.reason = 'Strict parser lacks name-resolution evidence; rebuild the core package';+ } else if (baseEvidence.hasUnresolvedNames || headEvidence.hasUnresolvedNames) {+ entry.reason = 'Computed or escaped declaration names prevent confirming source deletion';} else if (headSource.some(symbol => symbol.name === old.name)|| (headEvidence.leafTexts ?? []).some(text => qualifiedName(text.replace(/^['"`]|['"`]$/g, '')) === qualifiedName(old.name))) {entry.reason = 'Name remains in source; moved or unsupported syntax cannot be ruled out';