graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Fix queued follow-up steering with Cmd+Enter
yxlyxe8616dc494b0
diff --git a/apps/native/components/primitives/PromptBar.tsx b/apps/native/components/primitives/PromptBar.tsxindex 4917aa62..7fbe1c25 100644--- a/apps/native/components/primitives/PromptBar.tsx+++ b/apps/native/components/primitives/PromptBar.tsx@@ -35,7 +35,7 @@ export default function PromptBar({demo = true,tall = false,placeholder,- onSend, onSetting,+ onSend, onSetting, onSteerQueued,models,commands,modelKey,@@ -53,6 +53,8 @@ export default function PromptBar({tall?: boolean;placeholder?: string;onSend?: (text: string) => void; onSetting?: (text: string) => Promise<void>;+ /** Steer the next queued message without consuming the current draft. */+ onSteerQueued?: () => void;models?: PromptModel[];/** The slash commands the agent advertised. Empty until it answers —* an empty menu beats inventing commands this build may not service. */@@ -482,9 +484,16 @@ export default function PromptBar({void attachFiles(files);}}onKeyDown={(event) => {- // IME candidate keys belong to the input method. Modified keys- // belong to desktop shortcuts, never completion or submission.- if (event.nativeEvent.isComposing || event.keyCode === 229 || event.metaKey || event.ctrlKey || event.altKey) return;+ // IME candidate keys always belong to the input method.+ if (event.nativeEvent.isComposing || event.keyCode === 229) return;+ if (event.key === "Enter" && (event.metaKey || event.ctrlKey) && !event.shiftKey && !event.altKey && busy && !disabled && onSteerQueued) {+ event.preventDefault();+ event.stopPropagation();+ if (!event.repeat) onSteerQueued();+ return;+ }+ // Other modified keys belong to desktop shortcuts.+ if (event.metaKey || event.ctrlKey || event.altKey) return;if (menu && rows.length > 0) {if (!event.shiftKey && (event.key === "ArrowDown" || event.key === "ArrowUp")) {event.preventDefault();diff --git a/apps/native/components/site/GraffHarness.tsx b/apps/native/components/site/GraffHarness.tsxindex 54a194e6..59347080 100644--- a/apps/native/components/site/GraffHarness.tsx+++ b/apps/native/components/site/GraffHarness.tsx@@ -406,6 +406,12 @@ export default function GraffHarness() {wait: settings.wait, take: takeQueuedPrompt, run: runPrompt,});+ const steerQueued = (chat: number, item: number) => steerer.steer(chat, item, () => {+ const session = sessionsRef.current.get(chat);+ if (!session) return Promise.reject(new Error("Session unavailable"));+ return cancel(handleOf(chat), session);+ });+const columnBody = (thread: Chat) => <ChatColumn key={thread.id} thread={thread}compact={columnIds.length > 1} following={tailing[thread.id] ?? true} register={paneRef(thread.id)}onOpenPath={openPath} onReview={openChanges}@@ -421,6 +427,10 @@ export default function GraffHarness() {root: cwdOf(thread), modelKey: thread.model ?? model ?? undefined,onModelChange: key => changeModel(key, thread.id), onSend: text => void send(text, thread.id),onSetting: text => settings.change(thread.id, text),+ onSteerQueued: queues[thread.id]?.length ? () => {+ const next = queuesRef.current[thread.id]?.[0];+ if (runningRef.current.has(thread.id) && next) steerQueued(thread.id, next.id);+ } : undefined,history: mergeHistory(history, thread.messages.flatMap(m => m.role === "user" ? [m.text] : [])),busy: busyIds.has(thread.id), onStop: () => {const live = sessionsRef.current.get(thread.id);@@ -435,11 +445,7 @@ export default function GraffHarness() {onChangeEdit: (item, draft) => changeEdit(thread.id, item, draft),onEdit: (item, text) => { editQueued(thread.id, item, text); resumeQueue(thread.id); },onCancelEdit: item => { cancelEdit(thread.id, item); resumeQueue(thread.id); },- onRemove: item => { removeQueued(thread.id, item); resumeQueue(thread.id); }, onSteer: item => steerer.steer(thread.id, item, () => {- const session = sessionsRef.current.get(thread.id);- if (!session) return Promise.reject(new Error("Session unavailable"));- return cancel(handleOf(thread.id), session);- }),+ onRemove: item => { removeQueued(thread.id, item); resumeQueue(thread.id); }, onSteer: item => steerQueued(thread.id, item),}}pins={(pinsByChat[thread.id] ?? []).length}onShowPins={() => { focusChat(thread.id); setFilesOpen(false); setBrowserOpen(true); }}diff --git a/apps/native/components/site/useDesktopShortcuts.ts b/apps/native/components/site/useDesktopShortcuts.tsindex dac58b43..a47fedba 100644--- a/apps/native/components/site/useDesktopShortcuts.ts+++ b/apps/native/components/site/useDesktopShortcuts.ts@@ -31,7 +31,7 @@ export function useDesktopShortcuts(actions: Actions) {const native=(event:Event)=>dispatch((event as CustomEvent<string>).detail);const onKey=(e:KeyboardEvent)=>{// Dialogs own their typing and navigation. Escape and Tab remain local.- if(e.isComposing)return;+ if(e.isComposing||e.keyCode===229)return;if(e.target instanceof Element&&e.target.closest('[data-workspace-terminal]')&&!e.metaKey)return;if(document.querySelector('[role="dialog"]'))return;const a=ref.current,k=e.key.toLowerCase();let handled=false;diff --git a/apps/native/electron/composer-interaction-visual.cjs b/apps/native/electron/composer-interaction-visual.cjsindex fff31a50..1213362c 100644--- a/apps/native/electron/composer-interaction-visual.cjs+++ b/apps/native/electron/composer-interaction-visual.cjs@@ -130,6 +130,83 @@ async function runComposerInteractions({ win, origin, output }) {await pointer(`[data-chat="${split}"] textarea`);assert.equal(await js(`!!document.querySelector('[data-composer-menu]')`), false, 'Switching composers closes the old completion portal');+ // Hold real ACP response streams locally: the gallery adapter acknowledges+ // cancellation without ending its stream, so it cannot exercise queue drain.+ const actionsBeforeSteering = windowActions.length;+ await js(`(()=>{+ const original=window.fetch;+ const state=window.composerSteering={requests:[],cancels:[],live:new Map()};+ state.finish=(chat,stopReason='end_turn')=>{+ const controller=state.live.get(chat);if(!controller)throw Error('No controlled prompt to finish');+ state.live.delete(chat);+ controller.enqueue(new TextEncoder().encode(JSON.stringify({jsonrpc:'2.0',id:1,result:{stopReason}})+'\\n'));+ controller.close();+ };+ state.restore=()=>{window.fetch=original;};+ window.fetch=async(input,options)=>{+ if(String(input).includes('/api/acp')&&options?.body){+ const body=JSON.parse(options.body);+ if(body.method==='session/prompt'){+ state.requests.push(body);+ return new Response(new ReadableStream({start(controller){+ state.live.set(body.chat,controller);+ controller.enqueue(new TextEncoder().encode(JSON.stringify({jsonrpc:'2.0',method:'session/update',params:{update:{sessionUpdate:'agent_message_chunk',content:{type:'text',text:'Working'}}}})+'\\n'));+ }}),{headers:{'content-type':'application/x-ndjson'}});+ }+ if(body.method==='session/cancel'){+ state.cancels.push(body);state.finish(body.chat,'cancelled');+ return new Response(JSON.stringify({result:{}}),{headers:{'content-type':'application/json'}});+ }+ }+ return original(input,options);+ };+ })()`);+ try {+ const nativeEnter = async modifiers => {+ await testDesktop.testInput(wc, { type: 'keyDown', keyCode: 'Enter', modifiers });+ await testDesktop.testInput(wc, { type: 'keyUp', keyCode: 'Enter', modifiers });+ await frames();+ };+ const queued = `[data-chat="${split}"] [data-queued-prompt]`;+ // Exercise both platform modifiers, including an empty composer and a+ // separate unsent draft. Each turn stays busy until explicitly finished.+ for (const [index, modifier] of ['meta', 'control'].entries()) {+ const payload = `Steered queued payload ${index}`;+ const keptDraft = index ? 'Do not submit this unsent draft' : '';+ const base = await js('window.composerSteering.requests.length');+ await input(`Controlled active turn ${index}`);+ await nativeEnter([]);+ await wait(`window.composerSteering.requests.length===${base + 1} && !!document.querySelector('[data-chat="${split}"] [aria-label="Stop"]')`);+ await input(payload);+ await nativeEnter([]);+ await wait(`document.querySelector(${JSON.stringify(queued)})?.textContent.includes(${JSON.stringify(payload)})`);+ assert.equal(await draft(split), '', 'Plain Enter transfers the draft into the queue');+ assert.equal(await js('window.composerSteering.cancels.length'), index, 'Plain Enter while busy must not cancel');+ assert.equal(await js('window.composerSteering.requests.length'), base + 1, 'Queued text must not dispatch before steering');+ await input(keptDraft);+ for (const guard of [{ repeat: true }, { isComposing: true }, { keyCode: 229 }]) {+ await key('Enter', { [modifier === 'meta' ? 'metaKey' : 'ctrlKey']: true, ...guard });+ }+ assert.equal(await js('window.composerSteering.cancels.length'), index, 'Repeat and IME shortcuts must not steer');+ await nativeEnter([modifier]);+ await wait(`window.composerSteering.requests.length===${base + 2}`);+ assert.equal(await js('window.composerSteering.cancels.length'), index + 1, 'Steering cancels exactly once');+ assert.equal(windowActions.length, actionsBeforeSteering, 'Busy queue shortcuts must not toggle fullscreen');+ assert.equal(await draft(split), keptDraft, 'Steering preserves the current unsent draft');+ assert.deepEqual(await js(`window.composerSteering.requests[${base + 1}].params.prompt`), [{ type: 'text', text: payload }], 'Queue drain dispatches the queued payload, not the draft');+ assert.equal(await js(`window.composerSteering.cancels[${index}].chat===window.composerSteering.requests[${base + 1}].chat`), true, 'Cancellation and queue dispatch belong to the same chat');+ assert.equal(await draft(first), '/', 'Steering must not alter another visible composer');+ assert.equal(await js(`!!document.querySelector('[data-chat="${first}"] [data-queued-prompt]')`), false, 'Queue state must not leak into another chat');+ await js(`window.composerSteering.finish(window.composerSteering.requests[${base + 1}].chat)`);+ await wait(`!document.querySelector('[data-chat="${split}"] [aria-label="Stop"]') && !document.querySelector(${JSON.stringify(queued)})`);+ await frames();+ assert.equal(await js('window.composerSteering.requests.length'), base + 2, 'The queued payload is dispatched exactly once after completion');+ assert.equal(await draft(split), keptDraft, 'Completing the steered turn preserves the draft');+ }+ } finally {+ await js('window.composerSteering.restore()');+ }+await js('window.galleryBenchmark=true');await input('Start a scripted response');await key('Enter');