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): list callers apart from other incoming relationships, with readable totals (C2)
Bernhard Jackiewicz7b19d3c25bb5
diff --git a/graph-ui/src/browser-ai/BrowserChatDock.test.tsx b/graph-ui/src/browser-ai/BrowserChatDock.test.tsxindex f86a99316..e372c07ea 100644--- a/graph-ui/src/browser-ai/BrowserChatDock.test.tsx+++ b/graph-ui/src/browser-ai/BrowserChatDock.test.tsx@@ -909,9 +909,10 @@ describe('graph answers and answer limits', () => {expect(runtime.chat).not.toHaveBeenCalled();const answer = container.querySelector('.cbm-chat-answer-text')!.textContent!;for (const name of JSONB_AGG_CALLERS) expect(answer).toContain(name);- expect(answer).toMatch(/CALLS from 11/);- expect(answer).toMatch(/TESTS from 11/);- expect(answer).toMatch(/DEFINES from 1/);+ expect(answer).toContain('CALLS (11):');+ expect(answer).toContain('Other incoming relationships:');+ expect(answer).toContain('TESTS (11):');+ expect(answer).toContain('DEFINES (1): general.py, the file that defines JSONBAgg');expect(answer).toContain('not generated by the model');expect(container.querySelector('.cbm-chat-answer .cbm-chat-source-content')?.textContent).toContain('Incoming relationships: 23 from 12 symbols.');expect([...container.querySelectorAll('button')].some(item => item.textContent === 'Retry')).toBe(false);diff --git a/graph-ui/src/browser-ai/galaxy-evidence.ts b/graph-ui/src/browser-ai/galaxy-evidence.tsindex c55bc2d96..b277a8e0a 100644--- a/graph-ui/src/browser-ai/galaxy-evidence.ts+++ b/graph-ui/src/browser-ai/galaxy-evidence.ts@@ -103,11 +103,12 @@ export function fairShares(natural: readonly number[], budget: number): number[]return shares;}-/** One edge type: complete count, then names until the budget, then an explicit "+N more". */+/** One edge type: complete count, then names until the budget, then an explicit "+N more".+ * A listed answer heads it "**TESTS (11):**", the prompt "TESTS from 11:" (C2). */export function relationshipLine(group: RelationshipGroup, side: 'incoming' | 'outgoing', budget: number,words: RelationshipWords, markdown = false): { text: string; listed: number } {const quote = (value: string) => markdown ? `\`${value.replace(/`/g, "'")}\`` : value;- const head = `- ${markdown ? `**${group.type}**` : group.type} ${side === 'incoming' ? words.from : words.to} ${group.count}: `;+ const head = markdown ? `- **${words.typeCount(group.type, group.count)}:** ` : `- ${group.type} ${side === 'incoming' ? words.from : words.to} ${group.count}: `;let body = '', listed = 0;const more = (shown: number) => group.count > shown ? `${body ? '; ' : ''}${words.more(group.count - shown)}` : '';if (head.length + more(0).length > budget) return { text: '', listed: 0 };diff --git a/graph-ui/src/browser-ai/relationship-answer.test.ts b/graph-ui/src/browser-ai/relationship-answer.test.tsindex 34a12ae43..fd7ef7dc2 100644--- a/graph-ui/src/browser-ai/relationship-answer.test.ts+++ b/graph-ui/src/browser-ai/relationship-answer.test.ts@@ -3,7 +3,7 @@ import { selectionEvidenceContext } from '../galaxy/selection-evidence';import { JSONB_AGG_CALLERS, jsonbAggEvidence, jsonbAggRenderLimited, largeFolderScope } from './galaxy-evidence.fixture';import { correctRelationWords, relationshipAnswer, relationshipQuestion, relationshipSuggestion } from './relationship-answer';-const line = (markdown: string, type: string) => markdown.split('\n').find(item => item.startsWith(`- **${type}** `)) ?? '';+const line = (markdown: string, type: string) => markdown.split('\n').find(item => item.startsWith(`- **${type} (`)) ?? '';describe('caller and callee questions', () => {it.each([@@ -47,18 +47,21 @@ describe('caller and callee questions', () => {});describe('listed relationship answers', () => {- it('lists every incoming relationship of JSONBAgg by edge type, CALLS first, with complete counts', () => {+ it('lists the callers first with their count and every other incoming relationship under its own heading (C2)', () => {const answer = relationshipAnswer('Who calls JSONBAgg? List every caller and the edge type.', [jsonbAggEvidence()])!;- expect(answer.markdown).toContain('Callers of `JSONBAgg` in the loaded graph. Incoming relationships: 23 from 12 symbols.');+ expect(answer.markdown).toContain('Callers of `JSONBAgg` in the loaded graph. 23 incoming relationships from 12 symbols.');const calls = line(answer.markdown, 'CALLS'), tests = line(answer.markdown, 'TESTS');- expect(answer.markdown.indexOf(calls)).toBeLessThan(answer.markdown.indexOf(tests));- for (const text of [calls, tests]) {- expect(text).toMatch(/from 11: /);+ // TESTS and DEFINES are no callers: they follow under their own heading.+ expect(answer.markdown.indexOf(calls)).toBeLessThan(answer.markdown.indexOf('Other incoming relationships:'));+ expect(answer.markdown.indexOf('Other incoming relationships:')).toBeLessThan(answer.markdown.indexOf(tests));+ for (const [text, type] of [[calls, 'CALLS'], [tests, 'TESTS']]) {+ expect(text.startsWith(`- **${type} (11):** `)).toBe(true);for (const name of JSONB_AGG_CALLERS) expect(text).toContain(`\`${name}\``);expect(text).toContain('(Method, `tests/postgres_tests/test_aggregates.py`)');expect(text).not.toContain('more');}- expect(line(answer.markdown, 'DEFINES')).toBe('- **DEFINES** from 1: `general.py` (File, `django/contrib/postgres/aggregates/general.py`)');+ expect(line(answer.markdown, 'DEFINES')).toBe('- **DEFINES (1):** `general.py`, the file that defines `JSONBAgg`');+ expect(answer.markdown).not.toMatch(/\bfrom 11\b/);// The outgoing INHERITS edges answer another question.expect(answer.markdown).not.toContain('INHERITS');expect(answer.markdown).toContain('complete for the indexed graph');@@ -67,16 +70,24 @@ describe('listed relationship answers', () => {it('answers callee questions with the outgoing side only and says when no CALLS edge exists', () => {const answer = relationshipAnswer('What does JSONBAgg call?', [jsonbAggEvidence()])!;- expect(answer.markdown).toContain('Outgoing relationships: 2 to 2 symbols.');+ expect(answer.markdown).toContain('What `JSONBAgg` calls in the loaded graph. 2 outgoing relationships to 2 symbols.');expect(answer.markdown).toContain('`JSONBAgg` has no outgoing CALLS edge in this scope.');- expect(line(answer.markdown, 'INHERITS')).toMatch(/to 2: `OrderableAggMixin`.*`Aggregate`/);+ expect(answer.markdown).toContain('Other outgoing relationships:');+ expect(line(answer.markdown, 'INHERITS')).toMatch(/^- \*\*INHERITS \(2\):\*\* `OrderableAggMixin`.*`Aggregate`/);expect(answer.markdown).not.toContain('test_jsonb_agg');});it('answers in German for a German question', () => {const answer = relationshipAnswer('Wer ruft JSONBAgg auf?', [jsonbAggEvidence()])!;- expect(answer.markdown).toContain('Aufrufer von `JSONBAgg` im geladenen Graphen. Eingehende Beziehungen: 23 von 12 Symbolen.');- expect(line(answer.markdown, 'CALLS')).toMatch(/^- \*\*CALLS\*\* von 11: /);+ expect(answer.markdown).toContain('Aufrufer von `JSONBAgg` im geladenen Graphen. 23 eingehende Beziehungen aus 12 Symbolen.');+ expect(line(answer.markdown, 'CALLS')).toMatch(/^- \*\*CALLS \(11\):\*\* `test_default_argument`/);+ expect(answer.markdown.indexOf('Weitere eingehende Beziehungen:')).toBeGreaterThan(answer.markdown.indexOf(line(answer.markdown, 'CALLS')));+ expect(line(answer.markdown, 'TESTS')).toMatch(/^- \*\*TESTS \(11\):\*\* /);+ expect(line(answer.markdown, 'DEFINES')).toBe('- **DEFINES (1):** `general.py`, die Datei, die `JSONBAgg` definiert');+ expect(answer.markdown).not.toMatch(/\bvon 1[12]\b/);+ const callees = relationshipAnswer('Was ruft JSONBAgg auf?', [jsonbAggEvidence()])!.markdown;+ expect(callees).toContain('Was `JSONBAgg` im geladenen Graphen aufruft. 2 ausgehende Beziehungen zu 2 Symbolen.');+ expect(callees).toContain('Weitere ausgehende Beziehungen:');expect(answer.markdown).toContain('Ausschnitt: 1 Schritt in beide Richtungen');});@@ -100,13 +111,13 @@ describe('listed relationship answers', () => {it('lists a bounded sample with an explicit remainder when the evidence names fewer than the count', () => {const many = Array.from({ length: 40 }, (_, index) => ({ source: 2000 + index, target: 32360, type: 'CALLS' }));const answer = relationshipAnswer('Who calls JSONBAgg?', [jsonbAggEvidence({ edges: many })])!;- expect(line(answer.markdown, 'CALLS')).toMatch(/^- \*\*CALLS\*\* from 40: .*; \+16 more$/);+ expect(line(answer.markdown, 'CALLS')).toMatch(/^- \*\*CALLS \(40\):\*\* .*; \+16 more$/);});it('answers for a large documented scope with complete counts and every edge type', () => {const markdown = relationshipAnswer('What does postgres call?', [selectionEvidenceContext(largeFolderScope())])!.markdown;- expect(markdown).toContain('Outgoing relationships: 150 to 150 symbols.');- for (const type of ['CALLS', 'TESTS', 'USAGE', 'IMPORTS', 'DEFINES_METHOD']) expect(line(markdown, type)).toMatch(/^- \*\*\w+\*\* to 30: .*; \+\d+ more$/);+ expect(markdown).toContain('150 outgoing relationships to 150 symbols.');+ for (const type of ['CALLS', 'TESTS', 'USAGE', 'IMPORTS', 'DEFINES_METHOD']) expect(line(markdown, type)).toMatch(/^- \*\*\w+ \(30\):\*\* .*; \+\d+ more$/);expect(markdown).toContain('complete for the indexed graph.');});@@ -116,7 +127,7 @@ describe('listed relationship answers', () => {const markdown = relationshipAnswer('What does postgres call?', [cut])!.markdown;expect(markdown).not.toMatch(/to 0 symbols/);expect(markdown).toContain('the snapshot left part of its relationships out, so counts and names can be incomplete');- expect(markdown).toMatch(/Outgoing relationships: left out of this snapshot\.|Outgoing relationships: \d+\./);+ expect(markdown).toMatch(/Outgoing relationships: left out of this snapshot\.|\d+ outgoing relationships?\./);});it('leaves questions about another symbol, attached non-Galaxy evidence and other questions to the model', () => {@@ -184,7 +195,7 @@ describe('tolerant caller and callee questions (K16)', () => {expect(suggestion.markdown).toContain(language === 'de'? `Meintest du: ${side === 'incoming' ? 'Aufrufer von' : 'von'} \`JSONBAgg\`` : `Did you mean: ${side === 'incoming' ? 'callers of' : 'what'} \`JSONBAgg\``);expect(relationshipAnswer(suggestion.question, [jsonbAggEvidence()])?.markdown)- .toContain(side === 'incoming' ? (language === 'de' ? 'Aufrufer von `JSONBAgg`' : 'Callers of `JSONBAgg`') : (language === 'de' ? 'Von `JSONBAgg` aufgerufen' : 'Called by `JSONBAgg`'));+ .toContain(side === 'incoming' ? (language === 'de' ? 'Aufrufer von `JSONBAgg`' : 'Callers of `JSONBAgg`') : (language === 'de' ? 'Was `JSONBAgg` im geladenen Graphen aufruft' : 'What `JSONBAgg` calls in the loaded graph'));});it.each([@@ -301,7 +312,7 @@ describe('caller questions with a misspelled selection or a free word order (K16// The suggested question lists the selection when chosen.expect(relationshipAnswer(suggestion!.question, evidence())?.markdown).toContain(expected === 'incoming'? language === 'de' ? 'Aufrufer von `JSONBAgg` im geladenen Graphen' : 'Callers of `JSONBAgg` in the loaded graph'- : language === 'de' ? 'Von `JSONBAgg` aufgerufen' : 'Called by `JSONBAgg`');+ : language === 'de' ? 'Was `JSONBAgg` im geladenen Graphen aufruft' : 'What `JSONBAgg` calls in the loaded graph');});it.each([diff --git a/graph-ui/src/browser-ai/relationship-answer.ts b/graph-ui/src/browser-ai/relationship-answer.tsindex 2b6c4c86a..f56453ea3 100644--- a/graph-ui/src/browser-ai/relationship-answer.ts+++ b/graph-ui/src/browser-ai/relationship-answer.ts@@ -1,7 +1,8 @@import { identifierNamesIn, mentionsIn, quotedNamesIn } from '../compiler/question-classifier';import type { BrowserChatContext } from './chat-model';+import type { RelationshipGroup } from '../galaxy/selection-evidence';import { readGalaxyEvidence, relationshipLine, scopeSentence, sideLoaded, type GalaxyEvidence } from './galaxy-evidence';-import { relationshipWords } from './strings';+import { relationshipWords, type RelationshipWords } from './strings';type Side = 'incoming' | 'outgoing';export interface RelationshipQuestion {@@ -158,6 +159,24 @@ function aboutSelection(prompt: string, question: RelationshipQuestion, evidenceconst quote = (value: string) => `\`${value.replace(/`/g, "'")}\``;+/** Kinds whose incoming DEFINES edge is where the selection is defined, not a use of it. */+const DEFINERS = new Set(['file', 'module', 'class', 'interface']);+/** One edge type of a listed answer. An incoming DEFINES from a file names it as the file that+ * defines the selection: "`general.py`, the file that defines `JSONBAgg`" (C2). */+function listedLine(group: RelationshipGroup, side: Side, words: RelationshipWords, name: string): string {+ const symbols = group.files.flatMap(file => file.symbols);+ const kinds = new Set(symbols.map(symbol => symbol.kind));+ const [kind] = kinds;+ if (side === 'incoming' && /^DEFINES/.test(group.type) && kinds.size === 1 && kind && DEFINERS.has(kind.toLowerCase())) {+ const more = group.count > symbols.length ? `; ${words.more(group.count - symbols.length)}` : '';+ return `- **${words.typeCount(group.type, group.count)}:** ${symbols.map(symbol => quote(symbol.name)).join(', ')}, ${words.definer(kind, group.count, name)}${more}`;+ }+ return relationshipLine(group, side, Infinity, words, true).text;+}++/** Callers are the CALLS edges: they come first with their count. Every other edge type of+ * the same direction follows under its own heading, so a test or the defining file never+ * reads as a caller (C2). */function listed(question: RelationshipQuestion, evidence: GalaxyEvidence): string {const words = relationshipWords[question.language];const name = quote(evidence.label);@@ -171,11 +190,10 @@ function listed(question: RelationshipQuestion, evidence: GalaxyEvidence): strinconst symbols = side === 'incoming' ? evidence.relationships.incomingSymbols : evidence.relationships.outgoingSymbols;const total = groups.reduce((sum, group) => sum + group.count, 0);const calls = groups.find(group => group.type === 'CALLS');- // A caller question is answered with CALLS first; other edge types follow, never hidden.- const ordered = calls ? [calls, ...groups.filter(group => group !== calls)] : groups;- sections.push(`${heading}. ${side === 'incoming' ? words.incoming(total, symbols) : words.outgoing(total, symbols)}`- + (calls ? '' : ` ${words.noCalls(name, side)} ${words.otherRelationships}`),- ordered.map(group => relationshipLine(group, side, Infinity, words, true).text).join('\n'));+ const others = groups.filter(group => group !== calls);+ sections.push(`${heading}. ${words.total(side, total, symbols)}${calls ? '' : ` ${words.noCalls(name, side)}`}`);+ if (calls) sections.push(listedLine(calls, side, words, name));+ if (others.length) sections.push(`${words.otherRelationships(side)}\n${others.map(group => listedLine(group, side, words, name)).join('\n')}`);}sections.push(scopeSentence(evidence, words));if (evidence.state === 'loading') sections.push(words.stillLoading);diff --git a/graph-ui/src/browser-ai/strings.ts b/graph-ui/src/browser-ai/strings.tsindex 5aabfea7b..480ab5bf1 100644--- a/graph-ui/src/browser-ai/strings.ts+++ b/graph-ui/src/browser-ai/strings.ts@@ -64,10 +64,17 @@ const englishRelationshipWords = {internal: (summary: string) => `Between the selected symbols: ${summary}.`,beyond: (summary: string) => `Further out in the scope: ${summary}.`,callersOf: (name: string) => `Callers of ${name} in the loaded graph`,- calleesOf: (name: string) => `Called by ${name} in the loaded graph`,+ calleesOf: (name: string) => `What ${name} calls in the loaded graph`,+ /** The total of a listed answer: "23 incoming relationships from 12 symbols", never "23 from 12" (C2). */+ total: (side: 'incoming' | 'outgoing', total: number, symbols?: number) => `${en(total)} ${side} ${total === 1 ? 'relationship' : 'relationships'}`+ + `${symbols === undefined ? '' : ` ${side === 'incoming' ? 'from' : 'to'} ${en(symbols)} ${symbols === 1 ? 'symbol' : 'symbols'}`}.`,+ /** One edge type of a listed answer with the number of its symbols: "TESTS (11)". */+ typeCount: (type: string, count: number) => `${type} (${en(count)})`,+ /** What an incoming DEFINES edge from a file, module or class says about the selection. */+ definer: (kind: string, count: number, name: string) => count === 1 ? `the ${kind.toLowerCase()} that defines ${name}` : `the ${kind.toLowerCase()}s that define ${name}`,noCalls: (name: string, side: 'incoming' | 'outgoing') => side === 'incoming'? `No CALLS edge reaches ${name} in this scope.` : `${name} has no outgoing CALLS edge in this scope.`,- otherRelationships: 'Other relationships in the same direction:',+ otherRelationships: (side: 'incoming' | 'outgoing') => `Other ${side} relationships:`,noRelationships: 'None in this scope.',notLoaded: (side: 'incoming' | 'outgoing'): string => side === 'incoming'? 'The current scope does not follow incoming relationships. Trace incoming or both directions, then ask again.'@@ -102,7 +109,7 @@ export const relationshipWords: { en: RelationshipWords; de: RelationshipWords }+ (layer > 1 ? 'Anzahlen und Namen weiter außen können daher fehlen' : 'Anzahlen und Namen können daher fehlen, auch bei den direkten Beziehungen'),exhausted: 'dahinter folgt nichts mehr',scope: (shape: string, size: string, state: string) => `Ausschnitt: ${shape}; ${size}; ${state}.`,- incoming: (total: number, symbols?: number) => `Eingehende Beziehungen: ${de(total)}${symbols === undefined ? '' : ` von ${de(symbols)} ${symbols === 1 ? 'Symbol' : 'Symbolen'}`}.`,+ incoming: (total: number, symbols?: number) => `Eingehende Beziehungen: ${de(total)}${symbols === undefined ? '' : ` aus ${de(symbols)} ${symbols === 1 ? 'Symbol' : 'Symbolen'}`}.`,outgoing: (total: number, symbols?: number) => `Ausgehende Beziehungen: ${de(total)}${symbols === undefined ? '' : ` zu ${de(symbols)} ${symbols === 1 ? 'Symbol' : 'Symbolen'}`}.`,noIncoming: 'Eingehende Beziehungen: keine in diesem Ausschnitt.',noOutgoing: 'Ausgehende Beziehungen: keine in diesem Ausschnitt.',@@ -114,10 +121,18 @@ export const relationshipWords: { en: RelationshipWords; de: RelationshipWords }internal: (summary: string) => `Zwischen den ausgewählten Symbolen: ${summary}.`,beyond: (summary: string) => `Weiter außen im Ausschnitt: ${summary}.`,callersOf: (name: string) => `Aufrufer von ${name} im geladenen Graphen`,- calleesOf: (name: string) => `Von ${name} aufgerufen, im geladenen Graphen`,+ calleesOf: (name: string) => `Was ${name} im geladenen Graphen aufruft`,+ total: (side: 'incoming' | 'outgoing', total: number, symbols?: number) => `${de(total)} ${side === 'incoming' ? 'eingehende' : 'ausgehende'} ${total === 1 ? 'Beziehung' : 'Beziehungen'}`+ + `${symbols === undefined ? '' : ` ${side === 'incoming' ? 'aus' : 'zu'} ${de(symbols)} ${symbols === 1 ? 'Symbol' : 'Symbolen'}`}.`,+ typeCount: (type: string, count: number) => `${type} (${de(count)})`,+ definer: (kind: string, count: number, name: string) => {+ const noun = ({ file: ['die Datei', 'die Dateien'], module: ['das Modul', 'die Module'], class: ['die Klasse', 'die Klassen'] } as Record<string, string[]>)[kind.toLowerCase()]+ ?? [`${kind}`, `${kind}`];+ return count === 1 ? `${noun[0]}, ${noun[0].startsWith('das') ? 'das' : 'die'} ${name} definiert` : `${noun[1]}, die ${name} definieren`;+ },noCalls: (name: string, side: 'incoming' | 'outgoing') => side === 'incoming'? `Keine CALLS-Kante führt in diesem Ausschnitt zu ${name}.` : `${name} hat in diesem Ausschnitt keine ausgehende CALLS-Kante.`,- otherRelationships: 'Weitere Beziehungen in derselben Richtung:',+ otherRelationships: (side: 'incoming' | 'outgoing') => `Weitere ${side === 'incoming' ? 'eingehende' : 'ausgehende'} Beziehungen:`,noRelationships: 'Keine in diesem Ausschnitt.',notLoaded: (side: 'incoming' | 'outgoing') => side === 'incoming'? 'Der aktuelle Ausschnitt folgt keinen eingehenden Beziehungen. Verfolge eingehend oder beide Richtungen und frage noch einmal.'