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.
This commit is contained in:
committed by
brooklyn!
parent
07ed2fdb60
commit
2960bf37ab
@@ -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<ChatBarProps['onSubmit']>(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)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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<QueueEditState | null>
|
||||
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<boolean> => {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 (
|
||||
<StatusRow
|
||||
@@ -93,6 +100,21 @@ export function QueuePanel({
|
||||
<Pencil className={iconSize.xs} />
|
||||
</Button>
|
||||
</Tip>
|
||||
{canSteer && (
|
||||
<Tip label={c.queueSteer}>
|
||||
<Button
|
||||
aria-label={c.queueSteer}
|
||||
className="size-5 rounded-md"
|
||||
disabled={isEditing}
|
||||
onClick={() => onSteerNow?.(entry.id)}
|
||||
size="icon-xs"
|
||||
type="button"
|
||||
variant="ghost"
|
||||
>
|
||||
<SteeringWheel className={iconSize.xs} />
|
||||
</Button>
|
||||
</Tip>
|
||||
)}
|
||||
<Tip label={busy ? c.queueSendNext : c.queueSend}>
|
||||
<Button
|
||||
aria-label={busy ? c.queueSendNext : c.queueSend}
|
||||
|
||||
@@ -1730,6 +1730,7 @@ export const ar = defineLocale({
|
||||
editingQueuedInComposer: 'جار تحرير رسالة في الطابور',
|
||||
queueEdit: 'تحرير الرسالة المجدولة',
|
||||
queueSendNext: 'إرسالها تاليا',
|
||||
queueSteer: 'توجيه — تصحيح الدور الجاري فورا',
|
||||
queueSend: 'إرسالها الآن',
|
||||
queueDelete: 'حذف من الطابور',
|
||||
queueStuckTitle: 'لم تُرسل الرسالة في قائمة الانتظار',
|
||||
|
||||
@@ -2093,6 +2093,7 @@ export const en: Translations = {
|
||||
editingQueuedInComposer: 'Editing queued turn in composer',
|
||||
queueEdit: 'Edit',
|
||||
queueSendNext: 'Next',
|
||||
queueSteer: 'Steer — redirect the live turn now',
|
||||
queueSend: 'Send',
|
||||
queueDelete: 'Delete',
|
||||
queueResume: 'Resume',
|
||||
|
||||
@@ -1906,6 +1906,7 @@ export const ja = defineLocale({
|
||||
editingQueuedInComposer: 'コンポーザーでキュー済みターンを編集中',
|
||||
queueEdit: '編集',
|
||||
queueSendNext: '次に送信',
|
||||
queueSteer: 'ステア — 現在のターンを今すぐ修正',
|
||||
queueSend: '送信',
|
||||
queueDelete: '削除',
|
||||
queueResume: '再開',
|
||||
|
||||
@@ -1751,6 +1751,7 @@ export interface Translations {
|
||||
queueEdit: string
|
||||
queueSendNext: string
|
||||
queueSend: string
|
||||
queueSteer: string
|
||||
queueDelete: string
|
||||
queueResume: string
|
||||
queueResumeTip: string
|
||||
|
||||
@@ -1848,6 +1848,7 @@ export const zhHant = defineLocale({
|
||||
editingQueuedInComposer: '在輸入框中編輯排隊回合',
|
||||
queueEdit: '編輯',
|
||||
queueSendNext: '下一個',
|
||||
queueSteer: '引導 — 立即修正目前回合',
|
||||
queueSend: '傳送',
|
||||
queueDelete: '刪除',
|
||||
queueResume: '繼續',
|
||||
|
||||
@@ -2284,6 +2284,7 @@ export const zh: Translations = {
|
||||
editingQueuedInComposer: '正在输入框中编辑排队回合',
|
||||
queueEdit: '编辑',
|
||||
queueSendNext: '下一个',
|
||||
queueSteer: '引导 — 立即修正当前回合',
|
||||
queueSend: '发送',
|
||||
queueDelete: '删除',
|
||||
queueResume: '继续',
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { atom } from 'nanostores'
|
||||
|
||||
import { SLASH_COMMAND_RE } from '@/lib/chat-runtime'
|
||||
|
||||
import type { ComposerAttachment } from './composer'
|
||||
|
||||
export interface QueuedPromptEntry {
|
||||
@@ -13,6 +15,15 @@ export interface QueuedPromptEntry {
|
||||
queuedAt: number
|
||||
}
|
||||
|
||||
/** Whether a queued entry can ride a mid-turn redirect: text-only, non-empty,
|
||||
* not a slash command — the same gate `steerDraft` applies to the live draft
|
||||
* (attachments can't ride a redirect; slash commands execute, not steer). */
|
||||
export const isSteerableEntry = (entry: Pick<QueuedPromptEntry, 'attachments' | 'text'>): boolean => {
|
||||
const text = entry.text.trim()
|
||||
|
||||
return Boolean(text) && entry.attachments.length === 0 && !SLASH_COMMAND_RE.test(text)
|
||||
}
|
||||
|
||||
type QueueState = Record<string, QueuedPromptEntry[]>
|
||||
|
||||
const STORAGE_KEY = 'hermes.desktop.composerQueue.v1'
|
||||
|
||||
Reference in New Issue
Block a user