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): keep earlier answers about another file or selection out of a prompt
Bernhard Jackiewiczfbed70a4342a
diff --git a/graph-ui/src/browser-ai/BrowserChatDock.test.tsx b/graph-ui/src/browser-ai/BrowserChatDock.test.tsxindex 18b13afb9..c06b9a009 100644--- a/graph-ui/src/browser-ai/BrowserChatDock.test.tsx+++ b/graph-ui/src/browser-ai/BrowserChatDock.test.tsx@@ -367,7 +367,9 @@ describe('persistent local browser chat', () => {expect(requests[2][0].content).toContain('WHOLE_SECOND_FILE');expect(requests[2].map(message => message.content).join('\n')).not.toContain('WHOLE_FIRST_FILE');expect(requests[2].map(message => message.content).join('\n')).not.toContain(selection.text);- expect(requests[2].filter(message => message.role === 'user').map(message => message.content)).toEqual(['Explain the file', 'Explain the marked code', 'Explain this other file']);+ // The marked code is in the same file and keeps the conversation; another file starts a new topic (K17).+ expect(requests[1].filter(message => message.role === 'user').map(message => message.content)).toEqual(['Explain the file', 'Explain the marked code']);+ expect(requests[2].filter(message => message.role === 'user').map(message => message.content)).toEqual(['Explain this other file']);expect(props.onAttachmentConsumed).not.toHaveBeenCalled();expect(container.querySelectorAll('.cbm-chat-answer .cbm-chat-attachment')).toHaveLength(3);await render(props); await type('Ask from another workspace'); await click('Send ↑');@@ -745,7 +747,7 @@ describe('live-browser regressions', () => {const textarea = container.querySelector('textarea')!;expect(textarea.rows).toBe(1);expect(textarea.parentElement?.querySelector('[aria-label="Send ↑"]')).not.toBeNull();- expect(container.querySelector('.cbm-chat-clear')).toBeNull();+ expect(container.querySelector('.cbm-chat-new')).toBeNull();expect(container.querySelector('.cbm-chat-reader-source')).toBeNull();expect(container.querySelector('[aria-label="Remove graph selection"]')).not.toBeNull();await type('Explain the source'); await click('Send ↑');@@ -762,7 +764,7 @@ describe('live-browser regressions', () => {expect(source.querySelector('pre')?.textContent).toBe('ORIGINAL_SOURCE');expect(source.textContent).not.toContain('NEW_SOURCE');expect(container.querySelector('.cbm-chat-composer pre')).toBeNull();- expect(container.querySelector('.cbm-chat-clear')).not.toBeNull();+ expect(container.querySelector('.cbm-chat-header .cbm-chat-new')).not.toBeNull();expect(runtime.chat.mock.calls[0][0][0].content).toContain('ORIGINAL_SOURCE');});@@ -963,6 +965,28 @@ describe('graph answers and answer limits', () => {expect(runtime.chat.mock.calls[0][0].some(message => /Wähle einen Knoten|Select a node in Galaxy/.test(message.content))).toBe(false);});+ it('does not resend earlier answers about another file or selection and marks the new topic (K17)', async () => {+ const { props, runtime } = fixture();+ runtime.chat.mockResolvedValueOnce('This runs the flake8 linter on Python files.');+ const workflow = reader('name: New contributor message', 'file', '.github/workflows/new_contributor_pr.yml');+ await render({ ...props, selectionScope: 'django-demo:explore', readerContext: workflow }); await click('Download & load');+ await type('was kannst du mir über dieses File sagen'); await click('Send ↑');+ expect(container.querySelector('.cbm-chat-header')?.textContent).toContain('New conversation');+ await render({ ...props, selectionScope: 'django-demo:galaxy', proactiveSelection: jsonbAggEvidence() });+ await type('What does JSONBAgg do?'); await click('Send ↑');+ const request = runtime.chat.mock.calls[1][0];+ const text = request.map(message => message.content).join('\n');+ expect(text).not.toContain('flake8');+ expect(text).not.toContain('was kannst du mir');+ expect(request.filter(message => message.role === 'assistant')).toHaveLength(0);+ expect(container.querySelector('.cbm-chat-topic-break')?.textContent).toBe('New topic: JSONBAgg. Earlier messages are not sent with these questions.');+ // A follow-up on the same selection keeps its own history.+ await type('Which tests use it?'); await click('Send ↑');+ expect(runtime.chat.mock.calls[2][0].filter(message => message.role === 'user').map(message => message.content.split('\n').at(-1)))+ .toEqual(['What does JSONBAgg do?', 'Which tests use it?']);+ expect(runtime.chat.mock.calls[2][0].map(message => message.content).join('\n')).not.toContain('flake8');+ });+it('hands a listed answer to the model on request, with its evidence and without the list as history', async () => {const { props, runtime } = fixture();await render({ ...props, proactiveSelection: jsonbAggEvidence() }); await click('Download & load');diff --git a/graph-ui/src/browser-ai/BrowserChatDock.tsx b/graph-ui/src/browser-ai/BrowserChatDock.tsxindex ea11c7946..4fd5b53d7 100644--- a/graph-ui/src/browser-ai/BrowserChatDock.tsx+++ b/graph-ui/src/browser-ai/BrowserChatDock.tsx@@ -445,7 +445,9 @@ export default function BrowserChatDock({ proactiveSelection, selectionScope = "consume();return;}- const earlier = ask ? turns.filter(item => item.id !== retry.id) : turns;+ // Answers about another file or selection stay out: an earlier wrong answer must not+ // become evidence for this one (K17).+ const earlier = (ask ? turns.filter(item => item.id !== retry.id) : turns).filter(item => item.topic?.key === topic?.key);let history: ChatTurn[] = earlier;const makeRequest = () => buildChatMessages(history, prompt, source, extra, reader, currentGraph, packet ? formatExplanationEvidence(packet) : undefined);if (!retry && ((reader?.source?.text.length ?? 0) > 5000 || currentGraph.length)) packet = prepareExplanationContext(reader, currentGraph, chatEvidence);@@ -587,6 +589,7 @@ export default function BrowserChatDock({ proactiveSelection, selectionScope = "</aside> : <aside className="cbm-chat-dock" hidden={!open} aria-label="Local chat"><header className="cbm-chat-header"><h2>Chat</h2>+ {turns.length > 0 && <button type="button" className="cbm-chat-new" disabled={busy} onClick={clear}>{browserChatText.newConversation}</button>}<button type="button" className="cbm-chat-icon" aria-label="Collapse local chat" title="Collapse chat; keep conversation" onClick={onClose}>›</button></header>{needsEnable && <div className="cbm-chat-enable"><p>Enable the local agent to explain selections and chat.</p><button type="button" onClick={() => setSettingsOpen(true)}>Enable agent</button></div>}@@ -615,6 +618,8 @@ export default function BrowserChatDock({ proactiveSelection, selectionScope = "</section>}{turns.length === 0 && !(proactive && automatic && selected) && <div className="cbm-chat-empty"><span aria-hidden="true">⌁</span><h3>Ask about the code.</h3><p>{readerContext ? 'The current file is included automatically. Mark code to focus your next message on that exact selection.' : 'Ask a question, or add source and graph context to your next message.'}</p></div>}{turns.map((turn, index) => <article className="cbm-chat-turn" key={turn.id}>+ {turn.topic && index > 0 && turn.topic.key !== turns.slice(0, index).reverse().find(item => item.topic)?.topic?.key+ && <p className="cbm-chat-topic-break">{browserChatText.topicBreak(turn.topic.label)}</p>}<div className="cbm-chat-question"><span className="cbm-chat-speaker">You</span><ChatMarkdown text={turn.prompt} /></div><div className="cbm-chat-answer"><SourceDisclosure>{turn.evidence || turn.attachment || turn.readerContext?.source || turn.context?.length ? <>@@ -652,7 +657,6 @@ export default function BrowserChatDock({ proactiveSelection, selectionScope = "}} />{(phase === 'counting' || phase === 'generating') && !(autoRun.current && !manualRequest.current && draft.trim() && !stopping) ? <button type="button" className="cbm-chat-send" aria-label={stopping ? 'Stopping…' : 'Stop'} title="Stop generating" disabled={stopping} onClick={stop}>■</button> : <button className="cbm-chat-primary cbm-chat-send" type="submit" aria-label="Send ↑" title="Send message" disabled={!historyReady || (!autoRun.current && phase !== 'ready') || !!manualRequest.current || !draft.trim() || readerContext?.status === 'loading'}>↑</button>}</div>- {turns.length > 0 && <div className="cbm-chat-compose-actions"><button type="button" className="cbm-chat-clear" disabled={busy} onClick={clear}>New conversation</button></div>}</>}</form>diff --git a/graph-ui/src/browser-ai/browser-chat.css b/graph-ui/src/browser-ai/browser-chat.cssindex 9d6470594..2bce66802 100644--- a/graph-ui/src/browser-ai/browser-chat.css+++ b/graph-ui/src/browser-ai/browser-chat.css@@ -70,8 +70,6 @@.cbm-chat-composer textarea { display: block; flex: 1 1 auto; width: 100%; min-width: 0; resize: none; min-height: 32px; max-height: 104px; overflow-y: auto; border: 0; border-radius: 5px; color: #e8f2ed; background: transparent; padding: 6px 8px; line-height: 1.5; }.cbm-chat-composer textarea::placeholder { color: #789587; }.cbm-chat-dock .cbm-chat-send { flex: 0 0 32px; width: 32px; height: 32px; padding: 0; border-radius: 6px; font-size: 18px; line-height: 1; }-.cbm-chat-compose-actions { display: flex; justify-content: flex-end; align-items: center; margin-top: 2px; }-.cbm-chat-dock .cbm-chat-clear { border-color: transparent; background: transparent; color: var(--chat-muted); padding: 2px 0; font-size: 10px; }.cbm-chat-context { color: #789587; font-size: 10px; margin-top: 10px !important; }.cbm-chat-context-options { margin-bottom: 9px; color: var(--chat-muted); font-size: 11px; }.cbm-chat-context-options summary { cursor: pointer; }@@ -125,3 +123,7 @@.cbm-chat-limit-note > p { margin: 6px 0 !important; }.cbm-chat-limit-note > ul { margin: 4px 0 0; padding-left: 18px; }.cbm-chat-dock .cbm-chat-limit-note > button { margin: 2px 0 4px; padding: 3px 8px; font-size: 11px; }+.cbm-chat-header h2 { margin-right: auto !important; }+.cbm-chat-dock .cbm-chat-new { padding: 4px 9px; font-size: 11px; color: #d0e8d8; }+.cbm-chat-topic-break { display: flex; align-items: center; gap: 8px; margin: 0 0 10px !important; color: var(--chat-muted); font-size: 10px; }+.cbm-chat-topic-break::before, .cbm-chat-topic-break::after { content: ""; flex: 1 1 16px; border-top: 1px solid var(--chat-border); }diff --git a/graph-ui/src/browser-ai/strings.ts b/graph-ui/src/browser-ai/strings.tsindex 7005fdc24..4cee2ae8c 100644--- a/graph-ui/src/browser-ai/strings.ts+++ b/graph-ui/src/browser-ai/strings.ts@@ -131,6 +131,9 @@ export const browserChatText = {changeOutputLimit: 'Change the output limit',largerModels: 'A larger model may stay closer to the question. Each needs a one-time download, and its memory use is higher than the download:',modelDownload: (name: string, size: string) => `${name} · ${size} download`,+ newConversation: 'New conversation',+ /** Above the first question about another file or selection (K17). */+ topicBreak: (label: string) => `New topic: ${label}. Earlier messages are not sent with these questions.`,/** Offered under a listed answer, which the model did not write. */askModel: 'Ask the model',capacity: (nodes: number, edges: number, model: string, shown: number) =>