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): scope Ruby accessor evidence to installed names
Lum11043e6af3636b17
diff --git a/tests/skill/understand/test_incremental_symbols.test.mjs b/tests/skill/understand/test_incremental_symbols.test.mjsindex 6312c94d..51d32d75 100644--- a/tests/skill/understand/test_incremental_symbols.test.mjs+++ b/tests/skill/understand/test_incremental_symbols.test.mjs@@ -18,9 +18,29 @@ const compare = (oldNodes, newNodes, oldSource, newSource) => compareFileSymbols);describe('incremental symbol matching', () => {+ it.each(['attr :name', 'attr "name"', 'attr :"name"', 'attr :name, true', 'attr_reader :name',+ 'attr_writer :name', 'attr_accessor :name', 'obj.attr'])('allows unrelated Ruby deletion beside %s', accessor => {+ const before = parser.analyzeFileStrict('a.rb', 'class A\n def run; end\nend');+ const after = parser.analyzeFileStrict('a.rb', `class A\n def keep; end\n ${accessor}\nend`);+ expect(after.hasUnresolvedNames).toBe(false);+ expect(compareFileSymbols(graph([node('A.run')]), graph([]), before, after).missing[0].status).toBe('deleted');+ });++ it.each([+ ['run', 'attr :run'], ['run=', 'attr :run, true'], ['run=', 'attr_writer :run'],+ ['run', 'attr_accessor :run'], ['run=', 'attr_accessor :run'], ['run', 'attr_reader :run'],+ ])('does not confirm deletion of Ruby %s still installed by %s', (name, accessor) => {+ const before = parser.analyzeFileStrict('a.rb', `class A\n def ${name}${name.endsWith('=') ? '(value)' : ''}; end\nend`);+ const after = parser.analyzeFileStrict('a.rb', `class A\n def keep; end\n ${accessor}\nend`);+ expect(before.status).toBe('succeeded');+ expect(after.hasUnresolvedNames).toBe(false);+ expect(compareFileSymbols(graph([node(`A.${name}`)]), graph([]), before, after).missing[0].status).toBe('unknown');+ });+it.each([['rb', 'class A\n def run; end\nend\n', 'class A\n def keep; end\n define_method(("r" + "un").to_sym) { 1 }\nend\n'],['rb', 'class A\n def run; end\nend\n', 'class A\n def keep; end\n attr(("r" + "un").to_sym)\nend\n'],+ ['rb', 'class A\n def run; end\nend\n', 'class A\n def keep; end\n install = method(:attr)\n install.call(("r" + "un").to_sym)\nend\n'],['rb', 'class A\n def run; end\nend\n', 'class A\n def keep; end\n send(:define_method, ("r" + "un").to_sym) { 1 }\nend\n'],['py', 'class A:\n def run(self): pass\n', 'class A:\n def keep(self): pass\nsetattr(A, "r" + "un", lambda self: None)\n'],['py', 'class A:\n def run(self): pass\n', 'class A:\n def keep(self): pass\ninstall = setattr\ninstall(A, "r" + "un", lambda self: None)\n'],diff --git a/tests/skill/understand/test_prepare_incremental.test.mjs b/tests/skill/understand/test_prepare_incremental.test.mjsindex 480e34f5..ebfe1193 100644--- a/tests/skill/understand/test_prepare_incremental.test.mjs+++ b/tests/skill/understand/test_prepare_incremental.test.mjs@@ -232,6 +232,24 @@ afterEach(async () => {});describe('incremental symbol publication gate', { timeout: 30_000 }, () => {+ it('publishes genuine Ruby method deletion beside a static attr and an ordinary attr call', () => {+ const path = 'src/accessor.rb';+ const f = symbolFixture(2, { [path]: 'class A\n def run; end\n attr :name\nend\nobj.attr\n' });+ const previous = JSON.parse(f.persisted()[0]);+ const method = { ...f.methodNodes[0], id: `function:${path}:A.run`, name: 'A.run', filePath: path };+ previous.nodes.push(method);+ writeFileSync(join(f.dataDir, 'knowledge-graph.json'), JSON.stringify(previous));+ writeProjectFile(f.root, path, 'class A\n def keep; end\n attr :name\nend\nobj.attr\n');+ const head = commit(f.root, 'delete method beside static accessor');+ prepare(f.root, f.baseCommit);+ f.write('batch-1.json', { nodes: [previous.nodes.find(node => node.id === `file:${path}`)], edges: [] });+ run(python, [mergeScript, f.root], f.root);+ run(process.execPath, [finalizeScript, f.root], f.root);+ const published = JSON.parse(f.persisted()[0]);+ expect(published.project.gitCommitHash).toBe(head);+ expect(published.nodes.some(node => node.id === method.id)).toBe(false);+ });+it.each([['rb', 'class A\n def run; end\nend\n', 'class A\n def keep; end\n define_method(("r" + "un").to_sym) { 1 }\nend\n'],['rb', 'class A\n def run; end\nend\n', 'class A\n def keep; end\n attr(("r" + "un").to_sym)\nend\n'],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 eb13b613..97e4c704 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@@ -7,7 +7,7 @@ import type {CallGraphEntry,} from "../types.js";import type { LanguageConfig } from "../languages/types.js";-import type { LanguageExtractor } from "./extractors/types.js";+import type { LanguageExtractor, TreeSitterNode } from "./extractors/types.js";import { builtinExtractors } from "./extractors/index.js";// web-tree-sitter uses CJS internally; we need createRequire for .wasm resolution@@ -16,6 +16,42 @@ const require = createRequire(import.meta.url);type TreeSitterParser = import("web-tree-sitter").Parser;type TreeSitterLanguage = import("web-tree-sitter").Language;+const RUBY_ACCESSORS = new Set(["attr", "attr_accessor", "attr_reader", "attr_writer"]);++function rubyLiteralName(arg: TreeSitterNode): string | null {+ if (arg.type === "simple_symbol" && !arg.text.includes("\\")) return arg.text.slice(1) || null;+ if (["string", "delimited_symbol"].includes(arg.type)+ && arg.namedChildren.every(child => child.type === "string_content")) {+ return arg.namedChildren.map(child => child.text).join("") || null;+ }+ return null;+}++function rubyAccessorEvidence(node: TreeSitterNode): { unresolved: boolean; names: string[] } | null {+ if (node.type !== "call") return null;+ const method = node.childForFieldName("method")?.text;+ const args = [...(node.childForFieldName("arguments")?.namedChildren ?? [])];+ if (method && ["method", "public_method", "instance_method", "public_instance_method", "singleton_method"].includes(method)+ && args.length) {+ const target = rubyLiteralName(args[0]);+ // Retrieving an accessor for a later call loses its argument evidence.+ if (!target || RUBY_ACCESSORS.has(target)) return { unresolved: true, names: [] };+ }+ if (!method || !RUBY_ACCESSORS.has(method)) return null;+ let writer = method === "attr_writer" || method === "attr_accessor";+ if (method === "attr" && args.length === 2 && ["true", "false"].includes(args[1].type)) {+ writer = args.pop()!.type === "true";+ }+ const names = [];+ for (const arg of args) {+ const name = rubyLiteralName(arg);+ if (!name) return { unresolved: true, names: [] };+ if (method !== "attr_writer") names.push(name);+ if (writer) names.push(`${name}=`);+ }+ return { unresolved: false, names };+}+/*** Config-driven tree-sitter plugin.*@@ -303,14 +339,15 @@ export class TreeSitterPlugin implements AnalyzerPlugin {|| name.startsWith("r#") || name.normalize("NFKC") !== name,);const isJavaScriptExtractor = extractor.languageIds.some(id => id === "typescript" || id === "javascript");+ const isRubyExtractor = extractor.languageIds.includes("ruby");const propertyDefinitionNames = new Set(["defineProperty", "defineProperties", "__defineGetter__", "__defineSetter__"]);const runtimeInstallers = new Set<string>();if (isJavaScriptExtractor) {for (const name of ["eval", "Function"]) runtimeInstallers.add(name);}- if (extractor.languageIds.includes("ruby")) {- for (const name of ["define_method", "define_singleton_method", "alias_method", "attr", "attr_accessor", "attr_reader",- "attr_writer", "class_eval", "module_eval", "instance_eval", "class_exec", "module_exec", "instance_exec",+ if (isRubyExtractor) {+ for (const name of ["define_method", "define_singleton_method", "alias_method",+ "class_eval", "module_eval", "instance_eval", "class_exec", "module_exec", "instance_exec","eval", "send", "public_send", "__send__"]) runtimeInstallers.add(name);}if (extractor.languageIds.includes("python")) {@@ -321,6 +358,13 @@ export class TreeSitterPlugin implements AnalyzerPlugin {const pending = [tree.rootNode];while (pending.length > 0) {const node = pending.pop()!;+ if (isRubyExtractor) {+ const accessor = rubyAccessorEvidence(node);+ if (accessor?.unresolved) hasUnresolvedNames = true;+ // Static readers/writers only prevent deleting those exact names;+ // an unrelated attr token or accessor cannot taint the entire file.+ for (const name of accessor?.names ?? []) leafTexts.add(name);+ }// Name references also cover local aliases and dynamic dispatch. These// languages can install methods without any structural declaration.if (node.childCount === 0 && runtimeInstallers.has(node.text)) hasUnresolvedNames = true;diff --git a/understand-anything-plugin/skills/understand/SKILL.md b/understand-anything-plugin/skills/understand/SKILL.mdindex 6bcd19bf..e64aa27a 100644--- a/understand-anything-plugin/skills/understand/SKILL.md+++ b/understand-anything-plugin/skills/understand/SKILL.md@@ -422,6 +422,8 @@ Runtime property-definition APIs (including `Object.defineProperty`, `Reflect`,The same conservative rule applies to Ruby method installers/dynamic dispatch (such as `define_method`, `alias_method`, `send`, and class evaluation), Python attribute/class installers (such as `setattr`, `__dict__`, and `type`), and dynamic code evaluation. References to these APIs can establish uncertainty even through local aliases; ordinary source-confirmed Ruby/Python method deletions remain supported.+Ruby `attr`/`attr_*` calls with plain symbol or string arguments record the exact reader/writer names they install. They only make those names unconfirmed; unrelated genuine deletions and ordinary no-argument `obj.attr` calls do not taint the file. Dynamic, interpolated, or escaped accessor arguments remain unresolved.+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: