Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
fix(ui): name the function each Behavior call reaches in its facts
Bernhard Jackiewicz169f6a55103a
diff --git a/graph-ui/src/browser-ai/architecture-evidence.ts b/graph-ui/src/browser-ai/architecture-evidence.tsindex e0998d634..c41bccf08 100644--- a/graph-ui/src/browser-ai/architecture-evidence.ts+++ b/graph-ui/src/browser-ai/architecture-evidence.ts@@ -101,6 +101,19 @@ function spatialFacts(selected: Row, relationships: Row | undefined, scope: Rowreturn { facts, target: targetOf(symbol) };}+/** The function a call site reaches, read from its source line: the call whose arguments+ * begin with the recorded first argument, or an empty call when none is recorded. The+ * calls carry only the target's id, so the line is the only name at hand. */+function calleeAt(source: string | undefined, start: number | undefined, line: number, first: string | undefined): string | undefined {+ const code = source && start ? source.split('\n')[line - start] : undefined;+ if (!code) return undefined;+ for (const match of code.matchAll(/([A-Za-z_][\w.]*)\s*\(\s*/g)) {+ const rest = code.slice(match.index + match[0].length);+ if (first ? rest.startsWith(first) : rest.startsWith(')')) return text(match[1], 80);+ }+ return undefined;+}+/** Behavior: the starting operation, the selected call and the calls it makes. */function behaviorFacts(selected: Row, relationships: Row | undefined): ArchitectureFacts {const facts: string[] = [];@@ -109,13 +122,17 @@ function behaviorFacts(selected: Row, relationships: Row | undefined): Architectconst call = record(selected.call);const site = record(call?.callsite);if (caller && callee && caller.name !== callee.name) facts.push(words.call(quote(caller.name), quote(callee.name), site ? `${text(site.file_path, 240) ?? ''}${lines(site.line, undefined)}` : undefined));+ const current = record(record(selected.currentSource)?.source);+ const sourceText = typeof current?.source === 'string' ? current.source : undefined;+ const from = count(current?.start_line), to = count(current?.end_line);const calls = rows(relationships?.calls);if (calls.length) {facts.push(words.directCalls(count(relationships?.count) ?? calls.length, calls.slice(0, 6).flatMap(item => {const where = record(item.callsite);const line = count(where?.line);const args = rows(item.arguments).flatMap(argument => text(argument.e, 60) ?? []).slice(0, 3);- return line ? [words.callAt(line, args)] : [];+ const name = line ? calleeAt(sourceText, from, line, args[0]) : undefined;+ return line ? [words.callAt(line, args, name ? quote(name) : undefined)] : [];})));}const path = rows(relationships?.nodes);@@ -123,9 +140,6 @@ function behaviorFacts(selected: Row, relationships: Row | undefined): Architectconst component = record(selected.component);const label = text(component?.label, 160);if (label) facts.push(words.component(quote(label), count(component?.member_count), count(component?.file_count)));- const current = record(record(selected.currentSource)?.source);- const sourceText = typeof current?.source === 'string' ? current.source : undefined;- const from = count(current?.start_line), to = count(current?.end_line);const sourcePath = text(current?.file_path, 400);const symbol = callee ?? operation;return { facts, target: targetOf(operation ?? symbol),diff --git a/graph-ui/src/browser-ai/grounded-explanation.test.ts b/graph-ui/src/browser-ai/grounded-explanation.test.tsindex a9eb344be..01f18c010 100644--- a/graph-ui/src/browser-ai/grounded-explanation.test.ts+++ b/graph-ui/src/browser-ai/grounded-explanation.test.ts@@ -37,6 +37,16 @@ describe('Architecture selections as readable facts (K7)', () => {expect(sourceTargetOf(context)).toBeUndefined();expect(sourceTargetOf(behaviorMainEvidence())).toMatchObject({ qualifiedName: 'django-demo.django.conf.project_template.manage.main', path: 'django/conf/project_template/manage.py-tpl' });});++ it('names the function each Behavior call reaches, read from the call-site line of the source', () => {+ const main = ['def main():', ' """Run administrative tasks."""', " os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{{ project_name }}.settings')", ' try:',+ ' from django.core.management import execute_from_command_line', ' except ImportError as exc:', ' raise ImportError(', ' "Could not import Django. Is it installed and"',+ ' "available on your PYTHONPATH? Did you"', ' "forget to activate a virtual environment?"', ' ) from exc', ' execute_from_command_line(sys.argv)'].join('\n');+ const facts = selectionSummary(behaviorMainEvidence(main));+ expect(facts).toContain("2 direct calls with call-site evidence: line 9 calls `os.environ.setdefault` with 'DJANGO_SETTINGS_MODULE', '{{ project_name }}.settings'; line 18 calls `execute_from_command_line` with sys.argv.");+ // A line that does not hold the call's arguments names nothing.+ expect(selectionSummary(behaviorMainEvidence('def main():\n pass'))).toContain("2 direct calls with call-site evidence: line 9 with 'DJANGO_SETTINGS_MODULE', '{{ project_name }}.settings'; line 18 with sys.argv.");+ });});describe('the selected symbol source in a Galaxy explanation (K14)', () => {diff --git a/graph-ui/src/browser-ai/strings.ts b/graph-ui/src/browser-ai/strings.tsindex 374e3c0a8..c8ba2427b 100644--- a/graph-ui/src/browser-ai/strings.ts+++ b/graph-ui/src/browser-ai/strings.ts@@ -208,7 +208,7 @@ export const architectureWords = {examples: (items: readonly string[]) => `For example: ${items.join('; ')}.`,operation: (symbol: string) => `Starting operation: ${symbol}.`,call: (caller: string, callee: string, where?: string) => `Selected call: ${caller} calls ${callee}${where ? ` at ${where}` : ''}.`,- callAt: (line: number, args: readonly string[]) => `line ${line}${args.length ? ` with ${args.join(', ')}` : ''}`,+ callAt: (line: number, args: readonly string[], callee?: string) => `line ${line}${callee ? ` calls ${callee}` : ''}${args.length ? ` with ${args.join(', ')}` : ''}`,directCalls: (total: number, calls: readonly string[]) => `${plural(total, 'direct call', 'direct calls')} with call-site evidence${calls.length ? `: ${calls.join('; ')}` : ''}.`,path: (names: readonly string[]) => `Call chain: ${names.join(' → ')}.`,component: (name: string, members?: number, files?: number) => `Component: ${name}${members !== undefined ? `, ${plural(members, 'member', 'members')}` : ''}${files !== undefined ? ` in ${plural(files, 'file', 'files')}` : ''}.`,