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(core): retain class expression and Ruby alias evidence
Lum110453d2e1f13524
diff --git a/docs/incremental/symbol-loss-validation.md b/docs/incremental/symbol-loss-validation.mdindex ae9558d6..03bab426 100644--- a/docs/incremental/symbol-loss-validation.md+++ b/docs/incremental/symbol-loss-validation.md@@ -29,7 +29,7 @@ Each source transition is checked independently from publication mechanics.| Identity | stable ID; alternate ID; reused ID; same name across owners; free function versus method; duplicate/overloaded source identities; moved lines || Supplemental names | exact same/different name; unknown name; reader/writer suffix; quoted/symbol spelling; escapes/interpolation || Scope | same class; another class; free scope; unresolved/shadowed/reassigned receiver; unrelated local/import aliases; bound installer alias; arbitrary evaluation |-| Syntax | JS/TS/JSX/TSX methods/properties/assignments/property APIs; Ruby accessors/method installers; Python attributes/installers; Go/Rust/C++ receiver extraction |+| Syntax | JS/TS/JSX/TSX methods/properties/class expressions/assignments/property APIs; Ruby accessors/alias declarations/method installers; Python attributes/installers; Go/Rust/C++ receiver extraction || Negative evidence | unrelated string, parameter, normal read/call; static installer for another symbol; another owner's accessor || Invalid evidence | unsupported parser, parse recovery/error, empty extraction, missing evidence version, ambiguous old mapping || Publication | 20-to-1 omission; equal counts; merge/direct-finalize refusal; retry success/failure; stable prepare baseline; stale shards; deleted/excluded files; both data directories; current edge endpoint reuse |diff --git a/tests/skill/understand/test_symbol_evidence_matrix.test.mjs b/tests/skill/understand/test_symbol_evidence_matrix.test.mjsindex 03c8bddb..c59db9aa 100644--- a/tests/skill/understand/test_symbol_evidence_matrix.test.mjs+++ b/tests/skill/understand/test_symbol_evidence_matrix.test.mjs@@ -239,4 +239,34 @@ describe('scoped symbol evidence contract', () => {beforeSource: `void ${qualified}() {}`, name: qualified.replace(/^::/, ''),}).result.missing[0].status).toBe('unknown');});++ it.each(['ts', 'tsx', 'js', 'jsx'])('retains classes and methods rewritten as %s class expressions', extension => {+ for (const binding of ['A', 'B']) for (const expression of ['class A', 'class B', 'class']) {+ const code = `const ${binding} = ${expression} { run() {} }; function keep() {}`;+ const status = binding === 'A' ? 'unknown' : 'deleted';+ expect(classify(extension, code, { beforeSource: 'class A {}', name: 'A', oldExtra: {type: 'class'} })+ .result.missing[0].status).toBe(status);+ expect(classify(extension, code).result.missing[0].status).toBe(status);+ }+ expect(classify(extension, 'const A = (class Named { run() {} }); function keep() {}')+ .result.missing[0].status).toBe('unknown');+ expect(classify(extension, 'A = class Named { run() {} }; function keep() {}')+ .result.missing[0].status).toBe('unknown');+ });++ it.each(['run keep', ':run :keep', ':"run" :"keep"', ':"r#{suffix}" :keep'])('scopes Ruby alias %s to its declaring class', declaration => {+ for (const owner of ['A', 'B']) {+ const code = `${shells.rb}class ${owner}\n alias ${declaration}\nend`;+ expect(classify('rb', code).result.missing[0].status).toBe(owner === 'A' ? 'unknown' : 'deleted');+ }+ });++ it('distinguishes Ruby alias writer names, source names and global-variable aliases', () => {+ for (const declaration of ['keep run', ':"run=" :"keep="', '$run $keep']) {+ expect(classify('rb', `${shells.rb}class A\n alias ${declaration}\nend`).result.missing[0].status).toBe('deleted');+ }+ expect(classify('rb', 'class A\n def keep; end\n alias :"run=" :"keep="\nend', {+ beforeSource: 'class A\n def run=(value); end\nend', name: 'A.run=',+ }).result.missing[0].status).toBe('unknown');+ });});diff --git a/understand-anything-plugin/packages/core/src/plugins/symbol-evidence.ts b/understand-anything-plugin/packages/core/src/plugins/symbol-evidence.tsindex fa6e9f99..297057df 100644--- a/understand-anything-plugin/packages/core/src/plugins/symbol-evidence.ts+++ b/understand-anything-plugin/packages/core/src/plugins/symbol-evidence.ts@@ -60,9 +60,23 @@ function unwrap(node: Node | null): Node | null {&& node.namedChildren.length === 1) node = node.namedChildren[0];return node;}+function classExpression(node: Node): boolean {+ return node.type === "class" && node.childForFieldName("body")?.type === "class_body";+}+function expressionOwner(node: Node): string | null {+ let value = node;+ while (value.parent?.type === "parenthesized_expression") value = value.parent;+ const parent = value.parent;+ if (parent?.type === "variable_declarator") return identifier(parent.childForFieldName("name"));+ if (parent?.type === "assignment_expression" && parent.childForFieldName("right")?.id === value.id) {+ return identifier(parent.childForFieldName("left"));+ }+ return null;+}function lexicalOwner(node: Node): string | null {for (let parent = node.parent; parent; parent = parent.parent) {if (parent.type === "singleton_class") return null;+ if (classExpression(parent)) return expressionOwner(parent);if (parent.parent && CLASS_NODES.has(parent.type)) return identifier(parent.childForFieldName("name"));}return "";@@ -252,6 +266,12 @@ export function collectSymbolEvidence(root: Node, structure: StructuralAnalysis,const declaredName = declared?.type === "computed_property_name" ? literal(declared.namedChildren[0]) : declarationName(declared);const objectMethod = isJS && node.type === "method_definition" && node.parent?.type === "object";const localDeclaration = FUNCTION_NODES.has(node.type) && localBinding(node);+ if (isJS && classExpression(node)) {+ add(node, "", expressionOwner(node), "Unextracted class expression", "class");+ }+ if (isJS && node.type === "method_definition" && node.parent?.parent && classExpression(node.parent.parent)) {+ add(node, owner, declaredName, "Unextracted class expression method");+ }if (node !== root && CLASS_NODES.has(node.type) && declaredName) {let qualifiedScope = false;for (let parent = node.parent; parent; parent = parent.parent) {@@ -318,6 +338,9 @@ export function collectSymbolEvidence(root: Node, structure: StructuralAnalysis,};if (target) inspect(target);}+ if (isRuby && node.type === "alias" && declared?.type !== "global_variable") {+ add(node, owner, declarationName(declared), "Ruby alias declaration");+ }if (isRuby && node.type === "call") {const methodNode = node.childForFieldName("method");const method = methodNode?.text;