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): head explanation evidence with words instead of numbered ids
Bernhard Jackiewicz2651fbcb89c2
diff --git a/graph-ui/src/browser-ai/explanation-response.test.ts b/graph-ui/src/browser-ai/explanation-response.test.tsindex 57da84db3..3a69e3f41 100644--- a/graph-ui/src/browser-ai/explanation-response.test.ts+++ b/graph-ui/src/browser-ai/explanation-response.test.ts@@ -1,5 +1,7 @@import { describe, expect, it } from 'vitest';-import { citedInterpretation, explanationMessages, parseExplanationResponse } from './explanation-response';+import { citedInterpretation, explanationMessages, formatExplanationEvidence, parseExplanationResponse } from './explanation-response';+import { prepareExplanationContext } from './explanation-context';+import { jsonbAggEvidence } from './galaxy-evidence.fixture';const packet = { label: 'file.c', evidence: [{ id: 'E1', text: 'u.i = (uintptr_t)CBM_NOT_FOUND;', source: 'code' as const, location: { path: 'file.c', startLine: 103, startColumn: 5, endLine: 103, endColumn: 36, sourceVersion: 'v1' } }], limitations: [], fallback: 'Source excerpt', characterCount: 50 };describe('explanation attribution', () => {it('keeps evidence in the user request and requires a current exact citation', () => {@@ -82,3 +84,17 @@ describe('generated explanation response', () => {expect(messages[1].content).toContain('do not guess from names');});});++describe('evidence sections in the prompt', () => {+ it('heads sections with meaningful words, never numbered ids the model could echo as "Graph 1" (K4)', () => {+ const reader = { project: 'django-demo', path: 'django/contrib/postgres/aggregates/general.py', status: 'ready' as const, source: { id: 'file:1', kind: 'file' as const,+ project: 'django-demo', path: 'django/contrib/postgres/aggregates/general.py', text: 'class JSONBAgg(OrderableAggMixin, Aggregate):\n function = "JSONB_AGG"',+ startLine: 50, startColumn: 1, endLine: 51, endColumn: 31, sourceVersion: 'v1' } };+ const packet = prepareExplanationContext(reader, jsonbAggEvidence(), 3200);+ const prompt = [formatExplanationEvidence(packet), ...explanationMessages(packet).map(message => message.content)].join('\n');+ expect(prompt).not.toMatch(/\[(?:graph|source)-\d+\]/);+ expect(prompt).not.toMatch(/\b(?:graph|source)[- ]\d+\b/i);+ expect(formatExplanationEvidence(packet)).toMatch(/^Source django\/contrib\/postgres\/aggregates\/general\.py:50-51:$/m);+ expect(formatExplanationEvidence(packet)).toContain('Incoming relationships: 23 from 12 symbols.');+ });+});diff --git a/graph-ui/src/browser-ai/explanation-response.ts b/graph-ui/src/browser-ai/explanation-response.tsindex 251f3f9de..d266b6bd7 100644--- a/graph-ui/src/browser-ai/explanation-response.ts+++ b/graph-ui/src/browser-ai/explanation-response.ts@@ -5,9 +5,13 @@ export const AUTO_INPUT_TOKENS = 1536;export const AUTO_OUTPUT_TOKENS = 128;export const CHAT_INPUT_TOKENS = 2048;+/** Code sections are headed by where they come from; graph facts already begin with+ * their own words ("Selected:", "Incoming relationships:"). Numbered ids such as+ * "[graph-1]" stay out: a small model repeats them as "Graph 1" in its answer. */export function formatExplanationEvidence(packet: PreparedExplanationContext): string {- return [packet.label, ...packet.evidence.map(item => `[${item.id}]${item.location ? ` ${item.location.path}:${item.location.startLine}-${item.location.endLine}` : ''}\n${item.text}`),- ...packet.limitations.map(limit => `Limit: ${limit}`)].join('\n\n');+ return [packet.label, ...packet.evidence.map(item => item.source === 'code'+ ? `Source${item.location ? ` ${item.location.path}:${item.location.startLine}-${item.location.endLine}` : ''}:\n${item.text}` : item.text),+ ...packet.limitations.map(limit => `Limit: ${limit}`)].join('\n\n');}export function explanationMessages(packet: PreparedExplanationContext): BrowserChatMessage[] {