Skip to content

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.

fix(ui): let the input limit decide how much evidence a question carries

Bernhard Jackiewiczfdb8142473bf
diff --git a/graph-ui/src/browser-ai/BrowserChatDock.test.tsx b/graph-ui/src/browser-ai/BrowserChatDock.test.tsx
index 602f913b6..a91444d92 100644
--- a/graph-ui/src/browser-ai/BrowserChatDock.test.tsx
+++ b/graph-ui/src/browser-ai/BrowserChatDock.test.tsx
@@ -961,6 +961,25 @@ describe('graph answers and answer limits', () => {
expect(capacityNote()).toBeUndefined();
});
+ it('gives a manual question more evidence when the input limit is raised', async () => {
+ const { props, runtime } = fixture();
+ await render({ ...props, proactiveSelection: longCallers() }); await click('Download & load');
+ await type('Explain this class'); await click('Send ↑');
+ const shown = (note?: string) => Number(/showing (\d+)$/.exec(note ?? '')?.[1] ?? 24);
+ const before = shown(capacityNote());
+ await models();
+ const input = document.querySelector<HTMLInputElement>('#cbm-chat-input-tokens')!;
+ await act(async () => {
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!.set!.call(input, '6144');
+ input.dispatchEvent(new Event('input', { bubbles: true }));
+ });
+ await act(async () => input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true })));
+ await type('Explain this class'); await click('Send ↑');
+ expect(runtime.chat.mock.calls[1][0].at(-1)!.content.length).toBeGreaterThan(runtime.chat.mock.calls[0][0].at(-1)!.content.length);
+ expect(before).toBeLessThan(24);
+ expect(capacityNote()).toBeUndefined();
+ });
+
it('releases the loaded worker when another tab chooses another model', async () => {
const { props, runtime } = fixture(); await render(props); await click('Download & load');
const raw = JSON.stringify({ version: 1, preferences: { modelId: BROWSER_MODELS[1].id, automatic: true, limits: {} } });
@@ -1068,6 +1087,10 @@ describe('agent configuration limits', () => {
expect(document.querySelector('.cbm-chat-token-limits legend')?.textContent).toBe(`Token limits for ${first.displayName}`);
expect(field('cbm-chat-input-tokens')).toMatchObject({ value: '2048', min: '512', max: String(first.contextTokens - first.maxOutputTokens) });
expect(field('cbm-chat-output-tokens')).toMatchObject({ value: String(first.maxOutputTokens), min: '32', max: String(first.maxOutputTokens) });
+ // Every default and every suggested value is a valid step, so the arrows reach them.
+ expect(field('cbm-chat-input-tokens')?.step).toBe('64');
+ expect(field('cbm-chat-output-tokens')?.step).toBe('32');
+ expect(field('cbm-chat-output-tokens')?.validity.stepMismatch).toBe(false);
await setLimit('cbm-chat-output-tokens', 99_999);
expect(field('cbm-chat-output-tokens')?.value).toBe(String(first.maxOutputTokens));
await setLimit('cbm-chat-output-tokens', 128);
diff --git a/graph-ui/src/browser-ai/BrowserChatDock.tsx b/graph-ui/src/browser-ai/BrowserChatDock.tsx
index dae4bb41e..50287daff 100644
--- a/graph-ui/src/browser-ai/BrowserChatDock.tsx
+++ b/graph-ui/src/browser-ai/BrowserChatDock.tsx
@@ -84,7 +84,7 @@ function PacketSource({ packet, citation }: { packet: PreparedExplanationContext
}
/** A typed limit applies on blur or Enter, clamped into the model policy. */
-function TokenLimitField({ id, label, value, min, max, onCommit }: { id: string; label: string; value: number; min: number; max: number; onCommit: (value: number) => void }): JSX.Element {
+function TokenLimitField({ id, label, value, min, max, step, onCommit }: { id: string; label: string; value: number; min: number; max: number; step: number; onCommit: (value: number) => void }): JSX.Element {
const [text, setText] = useState(String(value));
useEffect(() => { setText(String(value)); }, [value]);
const commit = (): void => {
@@ -95,7 +95,7 @@ function TokenLimitField({ id, label, value, min, max, onCommit }: { id: string;
};
return <div className="cbm-chat-token-limit">
<label htmlFor={id}>{label}</label>
- <input id={id} type="number" inputMode="numeric" min={min} max={max} step={64} value={text} aria-describedby={`${id}-range`}
+ <input id={id} type="number" inputMode="numeric" min={min} max={max} step={step} value={text} aria-describedby={`${id}-range`}
onChange={event => setText(event.target.value)} onBlur={commit} onKeyDown={event => { if (event.key === 'Enter') { event.preventDefault(); commit(); } }} />
<small id={`${id}-range`}>{browserChatText.limitRange(min, max)}</small>
</div>;
@@ -128,6 +128,9 @@ export default function BrowserChatDock({ proactiveSelection, selectionScope = "
// Short automatic explanations never exceed the configured limits either.
const autoOutput = Math.min(AUTO_OUTPUT_TOKENS, limits.outputTokens);
const autoInput = Math.min(AUTO_INPUT_TOKENS, limits.inputTokens, model.contextTokens - autoOutput);
+ // Evidence for a manual question grows with the input limit: about 1.5 characters per
+ // token leave room for the question, history and instructions (2048 tokens: 3200).
+ const chatEvidence = Math.max(800, Math.floor(limits.inputTokens * 25 / 16));
const [phase, setPhase] = useState<Phase>('off');
const { draft, setDraft, turns, setTurns, ready: historyReady, historyNotice, clearHistory } = useChatHistory<ChatTurn>(historyKey);
const [error, setError] = useState<string>();
@@ -383,7 +386,7 @@ export default function BrowserChatDock({ proactiveSelection, selectionScope = "
const listed = !retry && !source ? relationshipAnswer(prompt, [...currentGraph, ...extra]) : undefined;
if (listed) {
setTurns(previous => [...previous, { id: `local-turn-${crypto.randomUUID()}`, prompt, context: extra,
- evidence: prepareExplanationContext(undefined, listed.context, 3200), modelId: model.id, request: [],
+ evidence: prepareExplanationContext(undefined, listed.context, chatEvidence), modelId: model.id, request: [],
answer: listed.markdown, status: 'complete', answeredFrom: 'graph' }]);
consume();
return;
@@ -391,7 +394,7 @@ export default function BrowserChatDock({ proactiveSelection, selectionScope = "
const earlier = ask ? turns.filter(item => item.id !== retry.id) : turns;
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, 3200);
+ if (!retry && ((reader?.source?.text.length ?? 0) > 5000 || currentGraph.length)) packet = prepareExplanationContext(reader, currentGraph, chatEvidence);
let request = retry && !ask ? retry.request.map(message => ({ ...message })) : makeRequest();
const queued = { cancelled: false }; manualRequest.current = queued;
const waitingEpoch = epoch.current;
@@ -419,7 +422,7 @@ export default function BrowserChatDock({ proactiveSelection, selectionScope = "
request = makeRequest(); count = await currentRuntime.countTokens(request);
if (epoch.current !== ticket || stopRequested.current) return;
}
- for (let budget = packet ? 1900 : 3200; !retry && count > limit && (reader?.source || currentGraph.length) && budget >= 300; budget = Math.floor(budget * .6)) {
+ for (let budget = packet ? Math.floor(chatEvidence * .6) : chatEvidence; !retry && count > limit && (reader?.source || currentGraph.length) && budget >= 300; budget = Math.floor(budget * .6)) {
packet = prepareExplanationContext(reader, currentGraph, budget);
request = makeRequest(); count = await currentRuntime.countTokens(request);
if (epoch.current !== ticket || stopRequested.current) return;
@@ -494,9 +497,9 @@ export default function BrowserChatDock({ proactiveSelection, selectionScope = "
{model.compatibilityNote && <p>{model.compatibilityNote}</p>}
<fieldset className="cbm-chat-token-limits">
<legend>{browserChatText.tokenLimits(model.displayName)}</legend>
- <TokenLimitField id="cbm-chat-input-tokens" label={browserChatText.inputLimit} value={limits.inputTokens} {...tokenLimitBounds(model, limits.outputTokens).input}
+ <TokenLimitField id="cbm-chat-input-tokens" label={browserChatText.inputLimit} value={limits.inputTokens} {...tokenLimitBounds(model, limits.outputTokens).input} step={64}
onCommit={inputTokens => setPreferences(current => ({ limits: { ...current.limits, [model.id]: clampTokenLimits(model, limits, { inputTokens }) } }))} />
- <TokenLimitField id="cbm-chat-output-tokens" label={browserChatText.outputLimit} value={limits.outputTokens} {...tokenLimitBounds(model, limits.outputTokens).output}
+ <TokenLimitField id="cbm-chat-output-tokens" label={browserChatText.outputLimit} value={limits.outputTokens} {...tokenLimitBounds(model, limits.outputTokens).output} step={32}
onCommit={outputTokens => setPreferences(current => ({ limits: { ...current.limits, [model.id]: clampTokenLimits(model, limits, { outputTokens }) } }))} />
<p>{browserChatText.limitsNote(autoInput, autoOutput)}</p>
</fieldset>