diff --git a/src/renderer/src/components/native-chat/composer/submit/use-native-chat-structured-composer-send.test.tsx b/src/renderer/src/components/native-chat/composer/submit/use-native-chat-structured-composer-send.test.tsx index 8103102fa2c..8d49dedaef3 100644 --- a/src/renderer/src/components/native-chat/composer/submit/use-native-chat-structured-composer-send.test.tsx +++ b/src/renderer/src/components/native-chat/composer/submit/use-native-chat-structured-composer-send.test.tsx @@ -241,7 +241,7 @@ describe('a conversation command leaves the composer once it is sent', () => { clearNativeChatComposerDraftsForTests() }) - it('clears /compact while the host is still answering', async () => { + async function sendCompactWhileHostAnswers() { const host = Promise.withResolvers< StructuredAgentSessionWriteOutcome @@ -311,9 +311,26 @@ describe('a conversation command leaves the composer once it is sent', () => { sending = hook.result.current.send('/compact', []) }) await act(async () => {}) + return { host, hook, settled: () => act(async () => sending) } + } + + it('clears /compact while the host is still answering', async () => { + const { host, hook, settled } = await sendCompactWhileHostAnswers() expect(hook.result.current.draft).toBe('') host.resolve({ kind: 'done', value: { command: 'compact', state: 'completed' } }) - await act(async () => sending) + await settled() expect(hook.result.current.draft).toBe('') }) + + it('keeps a command typed while a refused /compact was answering', async () => { + const { host, hook, settled } = await sendCompactWhileHostAnswers() + act(() => hook.result.current.setDraft('/clear')) + host.resolve({ + kind: 'not-done', + notice: 'Codex could not compact.', + failure: { kind: 'failed' } + }) + await settled() + expect(readNativeChatComposerDraft(scope).text).toBe('/clear') + }) }) diff --git a/src/renderer/src/components/native-chat/composer/submit/use-native-chat-structured-composer-send.ts b/src/renderer/src/components/native-chat/composer/submit/use-native-chat-structured-composer-send.ts index c6180c52c0a..ca973f6f6fa 100644 --- a/src/renderer/src/components/native-chat/composer/submit/use-native-chat-structured-composer-send.ts +++ b/src/renderer/src/components/native-chat/composer/submit/use-native-chat-structured-composer-send.ts @@ -191,6 +191,9 @@ export function useNativeChatStructuredComposerSend({ setCaret(composing ? 0 : left.text.length) clearSkillOrigin() } + // A refused command returns only to an empty composer; a lone command typed since would be replaced. + const recoversDraft = () => + consumed && (!hostCommand || readNativeChatComposerDraft(draftScopeKey).text.trim() === '') const prepareAttachments: StructuredAgentSessionAttachmentPreparation | undefined = stagedInput ? (input) => stagedInput.prepare(input, structuredTransport) : undefined return dispatchNativeChatStructuredComposerText( @@ -211,7 +214,7 @@ export function useNativeChatStructuredComposerSend({ structuredTransport.onError(error, refusedWhile ? { refusedWhile } : undefined) } if (!accepted) { - finishNativeChatComposerSubmission(draftScopeKey, submission, consumed) + finishNativeChatComposerSubmission(draftScopeKey, submission, recoversDraft()) return false } transferred = true @@ -224,7 +227,7 @@ export function useNativeChatStructuredComposerSend({ return true }) .catch((error) => { - finishNativeChatComposerSubmission(draftScopeKey, submission, consumed) + finishNativeChatComposerSubmission(draftScopeKey, submission, recoversDraft()) if (hostCommand && !isCurrent()) { return false }