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): match receiver methods without type-range containment
Lum11046c7262bf9aab
diff --git a/tests/skill/understand/test_incremental_symbols.test.mjs b/tests/skill/understand/test_incremental_symbols.test.mjsindex 8da66e0e..31aad9de 100644--- a/tests/skill/understand/test_incremental_symbols.test.mjs+++ b/tests/skill/understand/test_incremental_symbols.test.mjs@@ -1,10 +1,10 @@import { beforeAll, describe, expect, it } from 'vitest';-import { TreeSitterPlugin } from '../../../understand-anything-plugin/packages/core/dist/index.js';+import { TreeSitterPlugin, builtinLanguageConfigs } from '../../../understand-anything-plugin/packages/core/dist/index.js';import { compareFileSymbols } from '../../../understand-anything-plugin/skills/understand/validate-incremental-symbols.mjs';let parser;beforeAll(async () => {- parser = new TreeSitterPlugin();+ parser = new TreeSitterPlugin(builtinLanguageConfigs.filter(config => config.treeSitter));await parser.init();});@@ -18,6 +18,46 @@ const compare = (oldNodes, newNodes, oldSource, newSource) => compareFileSymbols);describe('incremental symbol matching', () => {+ it.each([+ ['go', 'Run', 'package p\ntype A struct{}\ntype B struct{}\n', owner => `func (x ${owner}) Run() {}\n`, 'func Run() {}\n'],+ ['rs', 'run', 'struct A;\nstruct B;\n', owner => `impl ${owner} { fn run(&self) {} }\n`, 'fn run() {}\n'],+ ['cpp', 'run', 'struct A { void run(); };\nstruct B { void run(); };\n', owner => `void ${owner}::run() {}\n`, 'void run() {}\n'],+ ])('keeps %s receiver methods distinct from each other and a free function', (extension, name, types, method, free) => {+ const filePath = `src/a.${extension}`;+ const evidence = source => parser.analyzeFileStrict(filePath, source);+ const descriptor = line => node(name, { id: `function:${filePath}:${name}`, filePath, lineRange: [line, line] });+ const check = (oldSource, headSource, oldLine, newLine) => {+ const base = evidence(oldSource);+ const head = evidence(headSource);+ expect(base.status).toBe('succeeded');+ expect(head.status).toBe('succeeded');+ return compareFileSymbols(graph([descriptor(oldLine)]), graph([descriptor(newLine)]), base, head);+ };+ const start = types.split('\n').length;+ const both = types + method('A') + method('B') + free;+ expect(check(both, both, start, start + 1).missing[0].status).toBe('still-present');+ expect(check(both, both, start, start).missing).toEqual([]);+ expect(check(both, both, start + 2, start + 2).missing).toEqual([]);+ // A receiver-only file has no class range available for deduplication.+ const prefix = extension === 'go' ? 'package p\n' : '';+ const first = prefix.split('\n').length;+ expect(check(prefix + method('A'), prefix + method('B'), first, first).missing[0].status).toBe('unknown');+ });++ it('does not treat legacy or unresolved receiver metadata as a free function', () => {+ const code = 'package p\ntype A struct{}\nfunc (x A) Run() {}\n';+ const evidence = parser.analyzeFileStrict('a.go', code);+ const nodes = graph([node('Run', { lineRange: [3, 3] })]);+ for (const owner of [undefined, null]) {+ const old = structuredClone(evidence);+ old.structure.functions[0].owner = owner;+ expect(compareFileSymbols(nodes, nodes, old, evidence).missing[0].status).toBe('unknown');+ }+ const trait = parser.analyzeFileStrict('a.rs', 'struct A; impl Trait for A { fn run(&self) {} }');+ expect(compareFileSymbols(graph([node('A.run')]), graph([node('A.run')]), trait, trait)+ .missing[0].status).toBe('unknown');+ });+it('detects an omitted old method even when total node counts stay the same', () => {const result = compare([node('A.keep'), node('A.lost')], [node('A.keep'), node('A.added')],'class A { keep() {} lost() {} }', 'class A { keep() {} lost() {} added() {} }');diff --git a/tests/skill/understand/test_prepare_incremental.test.mjs b/tests/skill/understand/test_prepare_incremental.test.mjsindex 2e5e4852..5632e88a 100644--- a/tests/skill/understand/test_prepare_incremental.test.mjs+++ b/tests/skill/understand/test_prepare_incremental.test.mjs@@ -358,6 +358,36 @@ describe('incremental symbol publication gate', { timeout: 30_000 }, () => {expect(f.persisted()).toEqual(before);});+ it.each([+ ['go', 'Run', 'package p\n', owner => `func (x ${owner}) Run() {}\n`],+ ['rs', 'run', '', owner => `impl ${owner} { fn run(&self) {} }\n`],+ ['cpp', 'run', '', owner => `void ${owner}::run() {}\n`],+ ])('blocks a substituted %s receiver in merge and finalize when the type is in another file', (extension, name, prefix, method) => {+ const path = `src/method.${extension}`;+ const source = prefix + method('A') + method('B');+ const f = symbolFixture(2, { [path]: source });+ const first = prefix.split('\n').length;+ const generic = { ...f.methodNodes[0], id: `function:${path}:${name}`, name, filePath: path, lineRange: [first, first] };+ const previous = JSON.parse(f.persisted()[0]);+ previous.nodes.push(generic);+ writeFileSync(join(f.dataDir, 'knowledge-graph.json'), JSON.stringify(previous));+ writeProjectFile(f.root, path, source + method('C'));+ commit(f.root, 'add receiver method');+ const before = f.persisted();+ prepare(f.root, f.baseCommit);+ expect(f.read('incremental-plan.json').filesToReanalyze).toContain(path);+ f.write('batch-1.json', {+ nodes: [previous.nodes.find(node => node.id === `file:${path}`), { ...generic, lineRange: [first + 1, first + 1] }],+ edges: [],+ });+ const merged = spawnSync(python, [mergeScript, f.root], { encoding: 'utf8' });+ expect(merged.status, merged.stderr).toBe(1);+ expect(f.read('incremental-symbol-report.json').files.find(file => file.filePath === path).missing)+ .toContainEqual(expect.objectContaining({ id: generic.id, status: 'still-present' }));+ expect(spawnSync(process.execPath, [finalizeScript, f.root]).status).toBe(1);+ expect(f.persisted()).toEqual(before);+ });+it('reconciles accepted replacement IDs on the first pass without requiring a retry', () => {const f = symbolFixture(2, { 'src/b.ts': 'export function b() {}\n' });const oldSource = { ...f.methodNodes[0], id: 'func:src/b.ts:b', filePath: 'src/b.ts', name: 'b' };diff --git a/understand-anything-plugin/skills/understand/SKILL.md b/understand-anything-plugin/skills/understand/SKILL.mdindex 96b02c13..c892277c 100644--- a/understand-anything-plugin/skills/understand/SKILL.md+++ b/understand-anything-plugin/skills/understand/SKILL.md@@ -418,6 +418,8 @@ Candidate endpoints use the current analysis's node and ownership descriptors beA 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.+Go receiver methods, Rust inherent impl methods, and C++ out-of-class definitions retain explicit type ownership and their own source ranges. Their duplicate entries in `classes[].methods` are reconciled without assuming the method body is inside the type declaration. Free functions with the same name stay distinct; unresolved receivers and Rust trait impl identities remain `unknown`. Receiver changes also affect structural fingerprints when the type declaration is in another file.+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 ec495b65..3f08c090 100644--- a/understand-anything-plugin/skills/understand/validate-incremental-symbols.mjs+++ b/understand-anything-plugin/skills/understand/validate-incremental-symbols.mjs@@ -56,23 +56,38 @@ function symbolKey(symbol) {}function sourceSymbols(evidence) {- if (evidence?.status !== 'succeeded' || !evidence.structure) return [];+ if (evidence?.status !== 'succeeded' || !evidence.structure || !evidence.language) return [];const { functions, classes } = evidence.structure;const symbols = [];+ for (const fn of functions) {+ let owner = fn.owner;+ if (owner === undefined) {+ const possibleOwners = classes.filter(cls => cls.methods.includes(fn.name));+ const enclosing = possibleOwners.filter(cls => fn.lineRange[0] >= cls.lineRange[0]+ && fn.lineRange[1] <= cls.lineRange[1]);+ // These extractors emit out-of-type method definitions; only their+ // explicit receiver metadata can distinguish those from free functions.+ owner = ['go', 'rust', 'cpp', 'c'].includes(evidence.language) ? null+ : enclosing.length === 1 ? enclosing[0].name : enclosing.length ? null : '';+ }+ symbols.push({ kind: 'callable', owner, name: fn.name, lineRange: fn.lineRange });+ }for (const cls of classes) {symbols.push({ kind: 'class', owner: '', name: cls.name, lineRange: cls.lineRange });+ const used = new Map();for (const name of cls.methods) {- symbols.push({ kind: 'callable', owner: cls.name, name, lineRange: cls.lineRange });+ const count = used.get(name) ?? 0;+ used.set(name, count + 1);+ const detailed = symbols.filter(symbol => symbol.kind === 'callable'+ && symbol.owner === cls.name && symbol.name === name);+ // Prefer method-definition ranges (Go receivers, Rust impls, C++ out-of-+ // class definitions). Retain additional overloads and ambiguous classes.+ if (classes.filter(other => other.name === cls.name).length === 1 && count < detailed.length) continue;+ const unknownOwner = symbols.some(symbol => symbol.kind === 'callable'+ && symbol.name === name && symbol.owner === null);+ symbols.push({ kind: 'callable', owner: unknownOwner ? null : cls.name, name, lineRange: cls.lineRange });}}- for (const fn of functions) {- // Some extractors emit methods in both functions and classes[].methods.- // Keep overloads ambiguous, but avoid counting that dual representation.- const owners = classes.filter(cls => cls.methods.includes(fn.name)- && fn.lineRange[0] >= cls.lineRange[0] && fn.lineRange[1] <= cls.lineRange[1]);- if (owners.length > 0) continue;- symbols.push({ kind: 'callable', owner: '', name: fn.name, lineRange: fn.lineRange });- }return symbols;}@@ -130,7 +145,7 @@ function resolveSymbol(node, graph, symbols) {&& node.lineRange[1] <= symbol.lineRange[1]);if (located.length === 1) candidates = located;}- return candidates.length === 1 ? candidates[0] : null;+ return candidates.length === 1 && candidates[0].owner !== null ? candidates[0] : null;}export function compareFileSymbols(previous, current, baseEvidence, headEvidence, sameRevision = false) {