From 2960bf37ab5863e6b2b6d1bdb70fa5d6c823c60b Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Wed, 12 Aug 2026 21:05:47 -0500 Subject: [PATCH] feat(desktop): steer a queued prompt into the live turn Queued turns could only wait for the settle or interrupt the turn to jump the line. Text-only queue entries now carry a steer action while the agent is busy: the entry rides the existing mid-turn redirect (no interrupt, no drain lock), is consumed only when the gateway accepts it, and lifts a park so the rest of the queue keeps flowing. Slash commands and entries with attachments keep their existing semantics. --- .../hooks/use-composer-queue.test.tsx | 72 ++++++++++++++++++- .../chat/composer/hooks/use-composer-queue.ts | 44 ++++++++++++ apps/desktop/src/app/chat/composer/index.tsx | 3 + .../src/app/chat/composer/queue-panel.tsx | 26 ++++++- apps/desktop/src/i18n/ar.ts | 1 + apps/desktop/src/i18n/en.ts | 1 + apps/desktop/src/i18n/ja.ts | 1 + apps/desktop/src/i18n/types.ts | 1 + apps/desktop/src/i18n/zh-hant.ts | 1 + apps/desktop/src/i18n/zh.ts | 1 + apps/desktop/src/store/composer-queue.ts | 11 +++ 11 files changed, 159 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.test.tsx index ad0f62e4a5..c39af052ee 100644 --- a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.test.tsx +++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.test.tsx @@ -23,9 +23,12 @@ import { useComposerQueue } from './use-composer-queue' const SESSION_KEY = 'stored-session-queue-hook' -function renderQueueHook(overrides: { busy?: boolean; onCancel?: () => void } = {}) { +function renderQueueHook( + overrides: { busy?: boolean; onCancel?: () => void; onSteer?: ChatBarProps['onSteer'] } = {} +) { const onSubmit = vi.fn(async () => true) const onCancel = overrides.onCancel ?? vi.fn() + const onSteer = overrides.onSteer const queueEditRef: { current: QueueEditState | null } = { current: null } const hook = renderHook( @@ -39,6 +42,7 @@ function renderQueueHook(overrides: { busy?: boolean; onCancel?: () => void } = focusInput: () => undefined, loadIntoComposer: () => undefined, onCancel, + onSteer, onSubmit, queueEditRef, queueSessionKey: SESSION_KEY, @@ -127,4 +131,70 @@ describe('useComposerQueue park integration', () => { await waitFor(() => expect(onSubmit).toHaveBeenCalledTimes(1)) expect(onSubmit.mock.calls[0]?.[0]).toBe('send me now') }) + + it('steerQueuedNow delivers via onSteer without cancelling and removes the entry', async () => { + const entry = enqueueQueuedPrompt(SESSION_KEY, { attachments: [], text: 'steer me' }) + const onSteer = vi.fn(async () => true) + const { hook, onCancel, onSubmit } = renderQueueHook({ busy: true, onSteer }) + + await act(async () => { + expect(await hook.result.current.steerQueuedNow(entry!.id)).toBe(true) + }) + + expect(onSteer).toHaveBeenCalledWith('steer me') + // A redirect rides the live turn: no interrupt, no submit. + expect(onCancel).not.toHaveBeenCalled() + expect(onSubmit).not.toHaveBeenCalled() + expect(getQueuedPrompts(SESSION_KEY)).toHaveLength(0) + }) + + it('a rejected steer leaves the entry queued so the settle drain still sends it', async () => { + const entry = enqueueQueuedPrompt(SESSION_KEY, { attachments: [], text: 'kept on reject' }) + const onSteer = vi.fn(async () => false) + const { hook, onSubmit } = renderQueueHook({ busy: true, onSteer }) + + await act(async () => { + expect(await hook.result.current.steerQueuedNow(entry!.id)).toBe(false) + }) + + expect(getQueuedPrompts(SESSION_KEY)).toHaveLength(1) + + // Turn settles → the surviving entry drains normally. + hook.rerender({ busy: false }) + await waitFor(() => expect(onSubmit).toHaveBeenCalledTimes(1)) + expect(onSubmit.mock.calls[0]?.[0]).toBe('kept on reject') + }) + + it('steerQueuedNow refuses unsteerable entries (slash commands execute, never steer)', async () => { + const slash = enqueueQueuedPrompt(SESSION_KEY, { attachments: [], text: '/compress' }) + const onSteer = vi.fn(async () => true) + + // Busy, but a slash command never steers. (Idle needs no case of its own: + // an idle session auto-drains its queue, so there is never an entry left + // to steer — asserting that here would just re-test auto-drain.) + const busy = renderQueueHook({ busy: true, onSteer }) + + await act(async () => { + expect(await busy.hook.result.current.steerQueuedNow(slash!.id)).toBe(false) + }) + + expect(onSteer).not.toHaveBeenCalled() + expect(getQueuedPrompts(SESSION_KEY)).toHaveLength(1) + }) + + it('a delivered steer lifts the park so the rest of the queue flows', async () => { + const steerable = enqueueQueuedPrompt(SESSION_KEY, { attachments: [], text: 'redirect' }) + enqueueQueuedPrompt(SESSION_KEY, { attachments: [], text: 'follows after' }) + parkQueuedPrompts(SESSION_KEY) + + const onSteer = vi.fn(async () => true) + const { hook } = renderQueueHook({ busy: true, onSteer }) + + await act(async () => { + expect(await hook.result.current.steerQueuedNow(steerable!.id)).toBe(true) + }) + + expect(isQueueParked(SESSION_KEY)).toBe(false) + expect(getQueuedPrompts(SESSION_KEY)).toHaveLength(1) + }) }) diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.ts index e1bb5442fe..d1731aaf6e 100644 --- a/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.ts +++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-queue.ts @@ -11,6 +11,7 @@ import { $queuedPromptsBySession, enqueueQueuedPrompt, getQueuedPrompts, + isSteerableEntry, MAX_AUTO_DRAIN_ATTEMPTS, migrateQueuedPrompts, promoteQueuedPrompt, @@ -35,6 +36,7 @@ interface UseComposerQueueArgs { focusInput: () => void loadIntoComposer: (text: string, attachments: ComposerAttachment[]) => void onCancel: ChatBarProps['onCancel'] + onSteer: ChatBarProps['onSteer'] onSubmit: ChatBarProps['onSubmit'] queueEditRef: RefObject queueSessionKey: ChatBarProps['queueSessionKey'] @@ -59,6 +61,7 @@ export function useComposerQueue({ focusInput, loadIntoComposer, onCancel, + onSteer, onSubmit, queueEditRef, queueSessionKey, @@ -283,6 +286,46 @@ export function useComposerQueue({ [activeQueueSessionKey, busy, onCancel, queueEdit, runDrain] ) + // Deliver a queued entry as a mid-turn redirect — the queue-panel sibling of + // the composer's steer-on-Enter. No interrupt, no drain lock: a redirect + // rides the live turn (the gateway either restarts the active request with + // its displayed context or waits for the current tool boundary), so the turn + // keeps flowing and the remaining queue is untouched. Only meaningful while + // busy — idle has no turn to redirect, and `sendQueuedNow` already covers it. + const steerQueuedNow = useCallback( + async (id: string): Promise => { + if (!onSteer || !busy || !activeQueueSessionKey || id === queueEditRef.current?.entryId) { + return false + } + + const entry = getQueuedPrompts(activeQueueSessionKey).find(e => e.id === id) + + if (!entry || !isSteerableEntry(entry)) { + return false + } + + triggerHaptic('submit') + + const accepted = await Promise.resolve(onSteer(entry.text)) + + // Rejected (turn already settling, gateway said no): leave the entry + // queued exactly where it was — the settle drain picks it up, so the + // words are never lost. Only a delivered redirect consumes the entry. + if (!accepted) { + return false + } + + drainFailuresRef.current.delete(id) + removeQueuedPrompt(activeQueueSessionKey, id) + // A steer is the same "keep it moving" intent as a manual send — a park + // from an earlier Stop must not hold back what's left of the queue. + unparkQueuedPrompts(activeQueueSessionKey) + + return true + }, + [activeQueueSessionKey, busy, onSteer, queueEditRef] + ) + // Edge-independent auto-drain: send the head whenever the session is idle and // the queue is non-empty, bounding retries so a thrown/rejected onSubmit (e.g. // a stale-session 404) can't strand the entry permanently nor spin-loop. The @@ -378,6 +421,7 @@ export function useComposerQueue({ queueParked, queuedPrompts, sendQueuedNow, + steerQueuedNow, stepQueuedEdit } } diff --git a/apps/desktop/src/app/chat/composer/index.tsx b/apps/desktop/src/app/chat/composer/index.tsx index 5711255d0b..56e0bf9c2f 100644 --- a/apps/desktop/src/app/chat/composer/index.tsx +++ b/apps/desktop/src/app/chat/composer/index.tsx @@ -279,6 +279,7 @@ export function ChatBar({ queueParked, queuedPrompts, sendQueuedNow, + steerQueuedNow, stepQueuedEdit } = useComposerQueue({ activeQueueSessionKey, @@ -289,6 +290,7 @@ export function ChatBar({ focusInput, loadIntoComposer, onCancel, + onSteer, onSubmit, queueEditRef, queueSessionKey, @@ -1132,6 +1134,7 @@ export function ChatBar({ } }} onSendNow={id => void sendQueuedNow(id)} + onSteerNow={id => void steerQueuedNow(id)} parked={queueParked} /> ) : null diff --git a/apps/desktop/src/app/chat/composer/queue-panel.tsx b/apps/desktop/src/app/chat/composer/queue-panel.tsx index 2f5612efd1..6e568dd624 100644 --- a/apps/desktop/src/app/chat/composer/queue-panel.tsx +++ b/apps/desktop/src/app/chat/composer/queue-panel.tsx @@ -4,9 +4,9 @@ import { Button } from '@/components/ui/button' import { Codicon } from '@/components/ui/codicon' import { Tip } from '@/components/ui/tooltip' import { type Translations, useI18n } from '@/i18n' -import { CornerDownLeft, iconSize, Pencil, Trash2 } from '@/lib/icons' +import { CornerDownLeft, iconSize, Pencil, SteeringWheel, Trash2 } from '@/lib/icons' import { cn } from '@/lib/utils' -import type { QueuedPromptEntry } from '@/store/composer-queue' +import { isSteerableEntry, type QueuedPromptEntry } from '@/store/composer-queue' interface QueuePanelProps { busy: boolean @@ -17,6 +17,9 @@ interface QueuePanelProps { /** Lift a park (explicit Stop/Esc halt) and let the queue flow again. */ onResume: () => void onSendNow: (id: string) => void + /** Deliver an entry as a mid-turn redirect (no interrupt). Absent when the + * host has no steer path — the affordance hides rather than dead-clicks. */ + onSteerNow?: (id: string) => void /** True after an explicit halt: entries wait until resumed / sent / edited. */ parked: boolean } @@ -32,6 +35,7 @@ export function QueuePanel({ onEdit, onResume, onSendNow, + onSteerNow, parked }: QueuePanelProps) { const { t } = useI18n() @@ -70,6 +74,9 @@ export function QueuePanel({ {entries.map(entry => { const isEditing = editingId === entry.id const attachmentsCount = entry.attachments.length + // Steer only surfaces where it can actually deliver: a live turn to + // redirect and an entry the redirect can carry (text-only, no slash). + const canSteer = busy && Boolean(onSteerNow) && isSteerableEntry(entry) return ( + {canSteer && ( + + + + )}