Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(code): label cross-file call edges as unresolved (cross-file, matched by name) (#5001)

time-attack151839d1e611
diff --git a/src/commands/code-callees.ts b/src/commands/code-callees.ts
index 99ed17f4b0..6ac8c35585 100644
--- a/src/commands/code-callees.ts
+++ b/src/commands/code-callees.ts
@@ -16,7 +16,7 @@
import type { BrainEngine } from '../core/engine.ts';
import { errorFor, serializeError } from '../core/errors.ts';
-import { resolveCliCodeScope, positionalArgs, parseFlag } from './code-scope.ts';
+import { resolveCliCodeScope, positionalArgs, parseFlag, UNRESOLVED_CALL_LABEL } from './code-scope.ts';
import { resolveCodeReadiness, readinessHint } from '../core/code-graph-readiness.ts';
import { legacyNestedErrorDocument } from '../core/agent-output.ts';
@@ -91,7 +91,7 @@ export async function runCodeCallees(engine: BrainEngine, args: string[]): Promi
} else {
console.log(`${edges.length} callee(s) for "${sym}":`);
for (const e of edges) {
- const res = e.resolved ? 'resolved' : 'unresolved';
+ const res = e.resolved ? 'resolved' : UNRESOLVED_CALL_LABEL;
console.log(` ${e.from_symbol_qualified} → ${e.to_symbol_qualified} [${res}]`);
}
if (hint) console.log(hint);
diff --git a/src/commands/code-callers.ts b/src/commands/code-callers.ts
index 7f8a0072b7..a6b44c4ac5 100644
--- a/src/commands/code-callers.ts
+++ b/src/commands/code-callers.ts
@@ -28,7 +28,7 @@
import type { BrainEngine } from '../core/engine.ts';
import { errorFor, serializeError } from '../core/errors.ts';
-import { resolveCliCodeScope, positionalArgs, parseFlag } from './code-scope.ts';
+import { resolveCliCodeScope, positionalArgs, parseFlag, UNRESOLVED_CALL_LABEL } from './code-scope.ts';
import { resolveCodeReadiness, readinessHint } from '../core/code-graph-readiness.ts';
import { legacyNestedErrorDocument } from '../core/agent-output.ts';
@@ -103,7 +103,7 @@ export async function runCodeCallers(engine: BrainEngine, args: string[]): Promi
} else {
console.log(`${edges.length} caller(s) for "${sym}":`);
for (const e of edges) {
- const res = e.resolved ? 'resolved' : 'unresolved';
+ const res = e.resolved ? 'resolved' : UNRESOLVED_CALL_LABEL;
console.log(` ${e.from_symbol_qualified} → ${e.to_symbol_qualified} [${res}]`);
}
if (hint) console.log(hint);
diff --git a/src/commands/code-scope.ts b/src/commands/code-scope.ts
index 226cf62584..93c7834021 100644
--- a/src/commands/code-scope.ts
+++ b/src/commands/code-scope.ts
@@ -33,6 +33,12 @@ const VALUE_FLAGS = new Set(['--source', '--limit', '--lang']);
/** Positional args, skipping both value-taking flags and their values.
* The inline `name=value` flag spelling is one token starting with a double
* dash, so the generic branch skips it without consuming a following token. */
+/**
+ * #5001: the symbol resolver links calls within one file, so every cross-file call stays unresolved and is
+ * matched by short name only (it can name a different symbol with the same name).
+ */
+export const UNRESOLVED_CALL_LABEL = 'unresolved (cross-file, matched by name)';
+
export function positionalArgs(args: string[]): string[] {
const out: string[] = [];
for (let i = 0; i < args.length; i++) {
diff --git a/src/core/operations-descriptions.ts b/src/core/operations-descriptions.ts
index 9c96426544..a604de7fd1 100644
--- a/src/core/operations-descriptions.ts
+++ b/src/core/operations-descriptions.ts
@@ -105,7 +105,8 @@ export const CODE_CALLERS_DESCRIPTION =
"every caller (the people who'd be affected by your change). Returns direct " +
"callers from the tree-sitter call graph. Use during plan-mode to size " +
"the change. Defaults to source-scoped; for multi-source brains pass source_id " +
- "or all_sources=true. " +
+ "or all_sources=true. `resolved:false` marks a call matched by name only: the resolver links calls within one " +
+ "file, so a cross-file call stays unresolved and may name a different symbol with the same name. " +
"Returns: `{symbol, count, callers: [{from_symbol_qualified, to_symbol_qualified, edge_type, resolved}]}`. " +
"Example: `{symbol:'parseMarkdown', count:4, callers:[{from_symbol_qualified:'callerInA', " +
"to_symbol_qualified:'parseMarkdown', edge_type:'calls', resolved:true}]}`.";
diff --git a/test/code-callers-unresolved-label-5001.test.ts b/test/code-callers-unresolved-label-5001.test.ts
new file mode 100644
index 0000000000..f971dfb7fd
--- /dev/null
+++ b/test/code-callers-unresolved-label-5001.test.ts
@@ -0,0 +1,41 @@
+/**
+ * #5001: a cross-file call is never resolved (the symbol resolver is within-file), so code-callers and
+ * code-callees label it "unresolved (cross-file, matched by name)" instead of a bare "unresolved".
+ */
+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
+import { importCodeFile } from '../src/core/import-file.ts';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { runCodeCallers } from '../src/commands/code-callers.ts';
+import { runCodeCallees } from '../src/commands/code-callees.ts';
+
+let engine: PGLiteEngine;
+
+beforeAll(async () => {
+ engine = new PGLiteEngine();
+ await engine.connect({});
+ await engine.initSchema();
+ await importCodeFile(engine, 'src/helper-example.ts', 'export function helperExample(n: number) {\n return n + 1;\n}\n', { noEmbed: true });
+ await importCodeFile(engine, 'src/use-example.ts', "import { helperExample } from './helper-example.ts';\nexport function useExample() {\n return helperExample(1);\n}\n", { noEmbed: true });
+}, 60_000);
+
+afterAll(async () => { await engine.disconnect(); });
+
+async function captured(run: () => Promise<void>): Promise<string> {
+ const lines: string[] = [];
+ const original = console.log;
+ console.log = (...args: unknown[]) => { lines.push(args.map(String).join(' ')); };
+ try { await run(); } finally { console.log = original; }
+ return lines.join('\n');
+}
+
+describe('#5001 cross-file call label', () => {
+ test('code-callers labels a cross-file caller as matched by name', async () => {
+ const out = await captured(() => runCodeCallers(engine, ['helperExample', '--all-sources', '--no-json']));
+ expect(out).toContain('useExample → helperExample [unresolved (cross-file, matched by name)]');
+ });
+
+ test('code-callees labels the same edge the same way', async () => {
+ const out = await captured(() => runCodeCallees(engine, ['useExample', '--all-sources', '--no-json']));
+ expect(out).toContain('useExample → helperExample [unresolved (cross-file, matched by name)]');
+ });
+});