The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): composer text sent past a setup card is the next user turn
alt-glitch7cc7e1036e9c
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsxindex d6656774fc7..832c7df5204 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx@@ -13,6 +13,7 @@ import {import { clearQueuedPrompts, getQueuedPrompts } from '@/store/composer-queue'import { $connectionRequests, type ConnectionRequest } from '@/store/connection-request'import { $gateway } from '@/store/gateway'+import { $onboardingSession } from '@/store/onboarding-session'import {clearAllPrompts,hasBlockingPromptRequest,@@ -21,6 +22,7 @@ import {setSudoRequest} from '@/store/prompts'import { hasOpenServerRequest, rememberServerRequest, resetServerRequestsForTests } from '@/store/server-requests'+import { $setupBeatRequests, parkSetupBeat } from '@/store/setup-beat'import { type ComposerTarget, requestComposerSubmit } from '../focus'import { ComposerScopeProvider, ComposerSurfaceProvider, MAIN_COMPOSER_SCOPE } from '../scope'@@ -881,3 +883,67 @@ describe('useComposerSubmit with a blocking prompt parked on the session', () =>expect(hasBlockingPromptRequest('runtime-session')).toBe(true)})})++describe('useComposerSubmit with a setup card waiting in the onboarding chat', () => {+ // The card is a live setup_beat server request; its answer is that request's response frame.+ const parkCard = (beat: 'layout' | 'name') => {+ const respond = vi.fn()++ rememberServerRequest({ fail: vi.fn(), id: `srq-${beat}`, method: 'setup_beat', params: {}, respond })+ parkSetupBeat({+ beat,+ card: {},+ question: 'Which layout?',+ requestId: `srq-${beat}`,+ sessionId: 'runtime-session',+ toolCallId: `call-${beat}`+ })++ return respond+ }++ afterEach(() => {+ cleanup()+ resetServerRequestsForTests()+ $setupBeatRequests.set({})+ $onboardingSession.set(null)+ })++ it('closes the card unanswered and sends the words as the next turn, never into the card turn', () => {+ $onboardingSession.set({ runId: 'run-1', runtimeId: 'runtime-session', storedId: 'stored-session' })+ const respond = parkCard('layout')++ const { hook, onSteer, onSubmit, queueCurrentDraft } = renderSubmitHook({+ busy: true,+ text: 'can ya look around and take a wild guess which one id like? :D'+ })++ act(() => {+ hook.result.current.submitDraft()+ })++ expect(respond).toHaveBeenCalledWith({ wrote_instead: true })+ expect($setupBeatRequests.get()['runtime-session']).toBeUndefined()+ // The backend ends the card turn on that result; the queued message runs as the next user turn.+ expect(queueCurrentDraft).toHaveBeenCalledTimes(1)+ expect(onSteer).not.toHaveBeenCalled()+ expect(onSubmit).not.toHaveBeenCalled()+ })++ it('takes words typed on the name card as the name, and sends no message', () => {+ $onboardingSession.set({ runId: 'run-1', runtimeId: 'runtime-session', storedId: 'stored-session' })+ const respond = parkCard('name')++ const { clearDraft, hook, onSteer, onSubmit, queueCurrentDraft } = renderSubmitHook({ busy: true, text: 'Sid' })++ act(() => {+ hook.result.current.submitDraft()+ })++ expect(respond).toHaveBeenCalledWith({ said: 'Sid' })+ expect(clearDraft).toHaveBeenCalledTimes(1)+ expect(queueCurrentDraft).not.toHaveBeenCalled()+ expect(onSteer).not.toHaveBeenCalled()+ expect(onSubmit).not.toHaveBeenCalled()+ })+})diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.tsindex 145ee907149..73ad18fa960 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts@@ -17,7 +17,7 @@ import { resetBrowseState } from '@/store/composer-input-history'import { enqueueQueuedPrompt, type QueuedPromptEntry } from '@/store/composer-queue'import { hasConnectionRequest, skipConnectionRequest } from '@/store/connection-request'import { notify } from '@/store/notifications'-import { answerParkedCard, skipParkedCards } from '@/store/parked-card-answers'+import { answerParkedCard, skipParkedCards, yieldParkedCardsToMessage } from '@/store/parked-card-answers'import { hasBlockingPromptRequest } from '@/store/prompts'import { cloneAttachments, type QueueEditState } from '../composer-utils'@@ -271,15 +271,18 @@ export function useComposerSubmit({return true}- // True when the draft was consumed as a parked card's answer.- const answerParkedCardWithDraft = (text: string, payloadPresent: boolean) => {+ // 'answered': the draft was a parked card's answer. 'yielded': a card closed for it, so it runs as+ // the next turn.+ const answerParkedCardWithDraft = (text: string, payloadPresent: boolean): 'answered' | 'yielded' | null => {// A card parked on this session owns the turn: the agent is blocked inside// its tool batch, so a steer or queued follow-up would sit undelivered until// the card's own timeout. Plain text answers the card instead (a clarify// takes it as its next question's answer) and is not sent again.//// A slash command or attachments cannot be an answer: the card is skipped- // and the draft routes normally. The skip is fire-and-forget, not awaited:+ // and the draft routes normally. An onboarding setup card the message+ // moves past instead closes as unanswered and its turn ends there, so the+ // message runs as the next turn. The skip is fire-and-forget, not awaited:// it clears the card synchronously and both RPCs ride the same socket in// call order, so the gateway resolves the clarify before it sees the// follow-up. Awaiting first would leave the draft live for a tick, long@@ -290,6 +293,7 @@ export function useComposerSubmit({// command, so it falls back to the ordinary-message behavior.const isSideQuestion = !attachments.length && isSideTaskSlashCommand(text)const routable = payloadPresent && !queueEdit && !isSideQuestion+ const slashCommand = !attachments.length && SLASH_COMMAND_RE.test(text.trim())// Like dispatchSubmit's restore: an answer that never reached the backend gives the words back.const answeredScope = draftScopeRef.current@@ -302,20 +306,17 @@ export function useComposerSubmit({}}- if (- routable &&- !attachments.length &&- !SLASH_COMMAND_RE.test(text.trim()) &&- answerParkedCard(sessionId ?? '', text.trim(), restore)- ) {+ if (routable && !attachments.length && !slashCommand && answerParkedCard(sessionId ?? '', text.trim(), restore)) {triggerHaptic('submit')resetBrowseState(sessionId)clearDraft()focusInput()- return true+ return 'answered'}+ const yielded = routable && !slashCommand && yieldParkedCardsToMessage(sessionId ?? '')+if (routable && hasClarifyRequest(sessionId)) {void skipClarifyRequest(sessionId)}@@ -329,6 +330,8 @@ export function useComposerSubmit({if (routable) {skipParkedCards(sessionId ?? '')}++ return yielded ? 'yielded' : null}const submitDraft = () => {@@ -361,7 +364,9 @@ export function useComposerSubmit({const text = pathifyRefs(draftRef.current)const payloadPresent = text.trim().length > 0 || attachments.length > 0- if (answerParkedCardWithDraft(text, payloadPresent)) {+ const parked = answerParkedCardWithDraft(text, payloadPresent)++ if (parked === 'answered') {return}@@ -371,8 +376,9 @@ export function useComposerSubmit({// sit undelivered behind the blocked prompt, and stopping the turn to force// it through resolves the prompt to empty and ends the turn as "Operation// interrupted." — the message looks eaten. Queue the words as the next turn- // instead; the prompt stays answerable and the queue drains on settle.- const blockingPrompt = !queueEdit && hasBlockingPromptRequest(sessionId)+ // instead; the prompt stays answerable and the queue drains on settle. A+ // setup card that just closed for this message ends its turn the same way.+ const blockingPrompt = !queueEdit && (parked === 'yielded' || hasBlockingPromptRequest(sessionId))if (queueEdit) {exitQueuedEdit('save')diff --git a/apps/desktop/src/components/assistant-ui/setup-beat/receipt.tsx b/apps/desktop/src/components/assistant-ui/setup-beat/receipt.tsxindex fc938840921..014d517c1fd 100644--- a/apps/desktop/src/components/assistant-ui/setup-beat/receipt.tsx+++ b/apps/desktop/src/components/assistant-ui/setup-beat/receipt.tsx@@ -51,7 +51,8 @@ export function setupBeatOutcome(result: SetupBeatToolResult): null | SetupBeatOreturn { answer: result.answer, beat, kind: 'answer' }}- return result.timed_out ? { beat, kind: 'timed_out' } : null+ // A message sent instead: it shows as its own bubble in the next turn, so the card reads unanswered.+ return result.timed_out || result.wrote_instead ? { beat, kind: 'timed_out' } : null}interface AnswerNames {diff --git a/apps/desktop/src/store/parked-card-answers.ts b/apps/desktop/src/store/parked-card-answers.tsindex 29b3428cc8c..4e77031a199 100644--- a/apps/desktop/src/store/parked-card-answers.ts+++ b/apps/desktop/src/store/parked-card-answers.ts@@ -15,6 +15,9 @@ export interface ParkedCardKind {onboardingOnly?: boolean/** Closes the card unanswered, so a message that cannot answer it (attachments, a slash command) runs. */skip?: (sessionId: string) => boolean+ /** Closes the card unanswered because the user sent a message instead. The card's turn ends on that+ * answer, so the message runs as the next turn. True when a card closed. */+ yieldToMessage?: (sessionId: string) => booleanwaiting: (sessionId: string) => boolean}@@ -71,6 +74,20 @@ export function answerParkedCard(sessionId: string, text: string, onFailed: () =return false}+/** Close every card waiting on `sessionId` that gives its turn to a message sent instead of an answer. True+ * when one closed: the message then waits for that turn to end and runs as the next one, never a steer. */+export function yieldParkedCardsToMessage(sessionId: string): boolean {+ let yielded = false++ for (const kind of kindsFor(sessionId)) {+ if (kind.waiting(sessionId) && kind.yieldToMessage?.(sessionId)) {+ yielded = true+ }+ }++ return yielded+}+/** Close every card waiting on `sessionId` that a message cannot answer (attachments, a slash command). */export function skipParkedCards(sessionId: string): void {for (const kind of kindsFor(sessionId)) {diff --git a/apps/desktop/src/store/setup-beat.test.ts b/apps/desktop/src/store/setup-beat.test.tsindex dc7d852c25e..e692cccd416 100644--- a/apps/desktop/src/store/setup-beat.test.ts+++ b/apps/desktop/src/store/setup-beat.test.ts@@ -4,21 +4,32 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { setupBeatOutcome } from '@/components/assistant-ui/setup-beat/receipt'import { $onboardingSession } from './onboarding-session'-import { answerParkedCard, parkedCardWaiting, sessionOnboardingCardWaiting } from './parked-card-answers'+import {+ answerParkedCard,+ parkedCardWaiting,+ sessionOnboardingCardWaiting,+ yieldParkedCardsToMessage+} from './parked-card-answers'import { rememberServerRequest, resetServerRequestsForTests } from './server-requests'import { $setupBeatRequests, answerSetupBeat, clearSetupBeat, parkSetupBeat } from './setup-beat'-function parkNameCard(requestId: string, open = true) {+function parkCard(requestId: string, open = true, beat: 'layout' | 'name' = 'name') {const respond = vi.fn()- const request: ServerRequest = { fail: vi.fn(), id: requestId, method: 'setup_beat', params: { session_id: 'rt-1' }, respond }+ const request: ServerRequest = {+ fail: vi.fn(),+ id: requestId,+ method: 'setup_beat',+ params: { session_id: 'rt-1' },+ respond+ }if (open) {rememberServerRequest(request)}parkSetupBeat({- beat: 'name',+ beat,card: {},question: 'What should I call you?',requestId,@@ -41,11 +52,11 @@ afterEach(() => {describe('setup_beat card', () => {it('takes composer text as the user words and closes, and a stale cancel leaves a newer card', () => {- parkNameCard('srq-1')+ parkCard('srq-1')clearSetupBeat('srq-old', 'rt-1')expect($setupBeatRequests.get()['rt-1']?.requestId).toBe('srq-1')- const respond = parkNameCard('srq-2')+ const respond = parkCard('srq-2')expect(answerParkedCard('rt-1', ' Sid ')).toBe(true)expect(respond).toHaveBeenCalledWith({ said: 'Sid' })@@ -59,7 +70,7 @@ describe('setup_beat card', () => {const off = $waiting.subscribe(value => seen.push(value))expect(parkedCardWaiting('rt-1')).toBe(false)- parkNameCard('srq-3')+ parkCard('srq-3')expect(parkedCardWaiting('rt-1')).toBe(true)expect(parkedCardWaiting('rt-2')).toBe(false)expect(answerParkedCard('rt-1', 'Sid')).toBe(true)@@ -68,8 +79,19 @@ describe('setup_beat card', () => {off()})+ it('leaves a message sent past any other card to the composer, and closes the card for it', () => {+ const respond = parkCard('srq-5', true, 'layout')++ expect(answerParkedCard('rt-1', 'can ya look around and take a wild guess?')).toBe(false)+ expect(respond).not.toHaveBeenCalled()+ expect(yieldParkedCardsToMessage('rt-1')).toBe(true)+ expect(respond).toHaveBeenCalledWith({ wrote_instead: true })+ expect($setupBeatRequests.get()['rt-1']).toBeUndefined()+ expect(yieldParkedCardsToMessage('rt-1')).toBe(false)+ })+it('keeps a card whose answer could not be sent', () => {- parkNameCard('srq-4', false)+ parkCard('srq-4', false)expect(answerSetupBeat('rt-1', { name: 'Sid' })).toBe(false)expect($setupBeatRequests.get()['rt-1']?.requestId).toBe('srq-4')@@ -80,6 +102,7 @@ describe('setup_beat card', () => {expect(setupBeatOutcome({ beat: 'theme', said: 'make it violet' })).toMatchObject({ kind: 'said' })expect(setupBeatOutcome({ answer: { name: 'Ada' }, beat: 'name', said: 'Ada' })).toMatchObject({ kind: 'said' })expect(setupBeatOutcome({ beat: 'layout', timed_out: true })).toMatchObject({ kind: 'timed_out' })+ expect(setupBeatOutcome({ beat: 'layout', wrote_instead: true })).toMatchObject({ kind: 'timed_out' })expect(setupBeatOutcome({ skipped_all: true })).toMatchObject({ kind: 'skipped_all' })expect(setupBeatOutcome({ beat: 'build', error: 'not accepted' })).toMatchObject({ kind: 'refused' })expect(setupBeatOutcome({ completed: true })).toBeNull()diff --git a/apps/desktop/src/store/setup-beat.ts b/apps/desktop/src/store/setup-beat.tsindex 582a28c7132..5d725f29eae 100644--- a/apps/desktop/src/store/setup-beat.ts+++ b/apps/desktop/src/store/setup-beat.ts@@ -2,9 +2,11 @@* Open `setup_beat` requests: the onboarding chat's card for one beat, one per session.** The setup_beat tool row reads this to draw the beat's card. A pick answers the request with- * `{answer}`; composer text answers it with `{said}` (the backend treats words on the name card as- * the name). The backend's `request.cancel` (timeout, Stop, Skip setup) clears the entry by request- * id, so a late cancel never erases a newer card the same session raised; the setup_beat call's+ * `{answer}`. Composer text answers only the name card, with `{said}` (the words are the name); a+ * message sent while any other card waits closes it with `{wrote_instead}`, the backend ends that+ * turn, and the composer sends the message as the next turn. The backend's `request.cancel`+ * (timeout, Stop, Skip setup) clears the entry by request id, so a late cancel never erases a newer+ * card the same session raised; the setup_beat call's* completion clears it by tool call id, which covers a card answered in another window.*/@@ -52,6 +54,7 @@ export interface SetupBeatToolResult {said?: stringskipped_all?: booleantimed_out?: boolean+ wrote_instead?: boolean}/** A setup_beat tool row's result: the object a live row carries, or the JSON text of a reloaded one. */@@ -101,7 +104,7 @@ export function dropSetupBeat(sessionId: string): void {// The card clears only once the answer is sent, so a failed send leaves it on screen to answer again.function respond(sessionId: string,- result: { answer: SetupBeatAnswer } | Record<string, never> | { said: string }+ result: { answer: SetupBeatAnswer } | Record<string, never> | { said: string } | { wrote_instead: true }): boolean {const request = $setupBeatRequests.get()[sessionId]@@ -119,18 +122,24 @@ export function answerSetupBeat(sessionId: string, answer: SetupBeatAnswer): booreturn respond(sessionId, { answer })}-/** Composer text typed while a card waits answers it as the user's words. */+/** Composer text typed while the name card waits is the name. No other card takes typed words. */export function sayToSetupBeat(sessionId: string, text: string): null | Promise<boolean> {- return text.trim() && $setupBeatRequests.get()[sessionId]+ return text.trim() && $setupBeatRequests.get()[sessionId]?.beat === 'name'? Promise.resolve(respond(sessionId, { said: text.trim() })): null}+/** A message sent instead of an answer closes the card; the backend ends its turn on that result. */+export function yieldSetupBeatToMessage(sessionId: string): boolean {+ return respond(sessionId, { wrote_instead: true })+}+registerParkedCardAnswer('setup_beat', {onboardingOnly: true,$requests: $setupBeatRequests,answer: sayToSetupBeat,- // An empty answer closes the card unanswered, so an attachment or a slash command can run.+ // An empty answer closes the card unanswered, so a slash command can run.skip: sessionId => respond(sessionId, {}),- waiting: sessionId => Boolean($setupBeatRequests.get()[sessionId])+ waiting: sessionId => Boolean($setupBeatRequests.get()[sessionId]),+ yieldToMessage: yieldSetupBeatToMessage})