diff --git a/src/components/PromptInput.client.test.tsx b/src/components/PromptInput.client.test.tsx index be032f127..9b6bcce67 100644 --- a/src/components/PromptInput.client.test.tsx +++ b/src/components/PromptInput.client.test.tsx @@ -8,11 +8,14 @@ import { afterEach, describe, expect, it, vi } from 'vitest'; import { PromptInput } from './PromptInput'; import { getAgentOutputTail, + isPanelFocused, onAgentReady, registerAction, registerFocusFn, sendPrompt, + setTaskFocusedPanel, showNotification, + concealTaskPromptInput, } from '../store/store'; import { NOTIFICATION_ERROR_MS } from '../store/notification'; @@ -21,6 +24,7 @@ const { storeMock, setTaskPromptDraft, taskUsesAgentChat } = vi.hoisted(() => ({ tasks: {} as Record, agents: {} as Record, mcpOrchestrationEnabled: true, + showPromptInput: true, }, setTaskPromptDraft: vi.fn(), taskUsesAgentChat: vi.fn(() => false), @@ -56,7 +60,9 @@ vi.mock('../store/store', () => ({ isAgentAskingQuestion: () => false, isAgentIdle: () => true, setTaskLastInputAt: vi.fn(), - isPanelFocused: () => false, + isPanelFocused: vi.fn(() => false), + setTaskFocusedPanel: vi.fn(), + concealTaskPromptInput: vi.fn(), setTaskControl: vi.fn(), markTaskUserActivity: vi.fn(), setTaskPromptDraftActive: vi.fn(), @@ -77,9 +83,13 @@ afterEach(() => { document.body.replaceChildren(); storeMock.tasks = {}; storeMock.agents = {}; + storeMock.showPromptInput = true; + vi.mocked(isPanelFocused).mockReturnValue(false); vi.mocked(getAgentOutputTail).mockReturnValue(''); storeMock.mcpOrchestrationEnabled = true; setTaskPromptDraft.mockClear(); + vi.mocked(concealTaskPromptInput).mockClear(); + vi.mocked(setTaskFocusedPanel).mockClear(); taskUsesAgentChat.mockReturnValue(false); vi.mocked(registerFocusFn).mockClear(); vi.mocked(registerAction).mockClear(); @@ -182,6 +192,36 @@ describe('PromptInput draft persistence', () => { expect(textarea.value).toBe(''); }); + it('hides a prompt box shown only for a staged draft once it is sent', async () => { + storeMock.showPromptInput = false; + storeMock.tasks = { + 'task-1': { + id: 'task-1', + agentIds: ['agent-1'], + promptDraft: 'staged by the canvas', + promptInputRevealed: true, + }, + }; + vi.mocked(isPanelFocused).mockReturnValue(true); + const textarea = mount('task-1'); + + textarea.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true })); + await waitFor(() => vi.mocked(concealTaskPromptInput).mock.calls.length > 0); + + expect(concealTaskPromptInput).toHaveBeenCalledWith('task-1'); + expect(setTaskFocusedPanel).toHaveBeenCalledWith('task-1', 'ai-terminal'); + }); + + it('leaves the prompt box alone after a send when the setting shows it', async () => { + storeMock.tasks = { 'task-1': { id: 'task-1', agentIds: ['agent-1'], promptDraft: 'send me' } }; + const textarea = mount('task-1'); + + textarea.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true })); + await waitFor(() => setTaskPromptDraft.mock.calls.some(([, text]) => text === '')); + + expect(concealTaskPromptInput).not.toHaveBeenCalled(); + }); + it('clears the stored draft when the prompt box closes while the prompt is sent', async () => { let finishSend = (): void => {}; vi.mocked(sendPrompt).mockImplementationOnce( diff --git a/src/components/PromptInput.tsx b/src/components/PromptInput.tsx index f96b4a512..ea03c1b88 100644 --- a/src/components/PromptInput.tsx +++ b/src/components/PromptInput.tsx @@ -36,8 +36,10 @@ import { markTaskUserActivity, setTaskPromptDraft, setTaskPromptDraftActive, + setTaskFocusedPanel, setTaskTerminalInputPending, showNotification, + concealTaskPromptInput, } from '../store/store'; import { clearStagedNotification, @@ -943,6 +945,15 @@ export function PromptInput(props: PromptInputProps) { } props.onSend?.(val); setText(''); + // A box shown only for a staged draft goes once that draft is sent, + // back to the terminal-only layout the user chose in Settings. + if (mode === 'manual' && !store.showPromptInput) { + const wasRevealed = store.tasks[props.taskId]?.promptInputRevealed === true; + concealTaskPromptInput(props.taskId); + if (wasRevealed && isPanelFocused(props.taskId, 'prompt')) { + setTaskFocusedPanel(props.taskId, 'ai-terminal'); + } + } } catch (e) { console.error('Failed to send prompt:', e); // The text stays in the field for a retry; without a notice the agent just looks like it ignored the prompt. diff --git a/src/components/TaskPanel.reasoning.client.test.tsx b/src/components/TaskPanel.reasoning.client.test.tsx index 4baf2a74b..093868d58 100644 --- a/src/components/TaskPanel.reasoning.client.test.tsx +++ b/src/components/TaskPanel.reasoning.client.test.tsx @@ -106,6 +106,8 @@ vi.mock('../store/store', () => { setTaskBriefs: (on: boolean) => setStore('taskBriefs', on), setTaskContext: (on: boolean) => setStore('taskContext', on), setShowPromptInput: (on: boolean) => setStore('showPromptInput', on), + isTaskPromptInputShown: (task?: { promptInputRevealed?: boolean }) => + store.showPromptInput || task?.promptInputRevealed === true, showCanvasContext: vi.fn(), }; }); diff --git a/src/components/TaskPanel.tsx b/src/components/TaskPanel.tsx index 80314f61c..5f9739401 100644 --- a/src/components/TaskPanel.tsx +++ b/src/components/TaskPanel.tsx @@ -29,6 +29,7 @@ import { isTaskCanvasVisible, referenceTourCard, openCanvasDocument, + isTaskPromptInputShown, } from '../store/store'; import { markFeatureHintSeen } from '../store/onboarding'; import { useFocusRegistration } from '../lib/focus-registration'; @@ -543,7 +544,7 @@ export function TaskPanel(props: TaskPanelProps) { autoFocusTimer = setTimeout(() => { autoFocusTimer = undefined; if (!store.focusedPanel[id] && !panelRef.contains(document.activeElement)) { - if (store.showPromptInput && !isAgentChat(props.task, firstAgentId())) { + if (isTaskPromptInputShown(props.task) && !isAgentChat(props.task, firstAgentId())) { promptRef?.focus(); } else { setTaskFocusedPanel(id, 'ai-terminal'); @@ -769,7 +770,7 @@ export function TaskPanel(props: TaskPanelProps) { // question, so the prompt box appears for it even when turned off. const promptBoxShown = () => !isAgentChat(props.task, firstAgentId()) && - (store.showPromptInput || + (isTaskPromptInputShown(props.task) || autoSendChildUpdates() || (contextOn() && needsYouNow(props.task) !== '')); const promptInputEl = ( @@ -1202,7 +1203,7 @@ export function TaskPanel(props: TaskPanelProps) { props.task, message, promptHandle, - store.showPromptInput && !isAgentChat(props.task, firstAgentId()), + isTaskPromptInputShown(props.task) && !isAgentChat(props.task, firstAgentId()), ) } onUseComposer={(message) => @@ -1210,7 +1211,7 @@ export function TaskPanel(props: TaskPanelProps) { props.task, message, promptHandle, - store.showPromptInput && !isAgentChat(props.task, firstAgentId()), + isTaskPromptInputShown(props.task) && !isAgentChat(props.task, firstAgentId()), ) } /> diff --git a/src/store/canvas.client.test.tsx b/src/store/canvas.client.test.tsx index f0a04c49d..a04b32303 100644 --- a/src/store/canvas.client.test.tsx +++ b/src/store/canvas.client.test.tsx @@ -161,7 +161,7 @@ it('stages a scoped branch request with saved context and preserves the existing expect(prompt).toContain('reasoning_update'); expect(prompt).toContain('Otherwise, suggest additions in chat'); expect(store.tasks['task-1'].promptDraftActive).toBe(true); - expect(store.showPromptInput).toBe(true); + expect(store.tasks['task-1'].promptInputRevealed).toBe(true); expect(vi.mocked(invoke).mock.calls.some(([channel]) => channel === IPC.WriteToAgent)).toBe( false, ); @@ -495,7 +495,9 @@ describe('browser canvas', () => { 'Make this smaller\n\nSelected element #save\n\nSelected element #cancel', ); expect(store.tasks['task-1'].promptDraftActive).toBe(true); - expect(store.showPromptInput).toBe(true); + // The draft shows for this task only; the setting the user turned off stays off. + expect(store.tasks['task-1'].promptInputRevealed).toBe(true); + expect(store.showPromptInput).toBe(false); expect(invoke).not.toHaveBeenCalledWith(IPC.WriteToAgent, expect.anything()); }); }); diff --git a/src/store/canvas.ts b/src/store/canvas.ts index 7ee3544b2..26a7fcb3e 100644 --- a/src/store/canvas.ts +++ b/src/store/canvas.ts @@ -15,6 +15,7 @@ import { setPlanContent, setPrefillPrompt, setTaskPromptDraftActive } from './ta import { setActiveTask } from './navigation'; import { saveState } from './persistence'; import { aiTerminalPanels, setTaskFocusedPanel } from './focused-panel'; +import { revealTaskPromptInput } from './prompt-input-visibility'; import type { CanvasTab, Task } from './types'; import type { ReasoningProfile } from '../investigation/profiles'; import type { ReasoningWorkspace } from '../investigation/editing'; @@ -71,7 +72,7 @@ export function stageCanvasRequest(taskId: string, request: string): void { if (!task || task.closingStatus) return; const text = [task.prefillPrompt ?? task.promptDraft ?? '', request].filter(Boolean).join('\n\n'); setTaskPromptDraftActive(taskId, true); - setStore('showPromptInput', true); + revealTaskPromptInput(taskId); setPrefillPrompt(taskId, text); queueMicrotask(() => { if (store.tasks[taskId]) setTaskFocusedPanel(taskId, 'prompt'); @@ -278,6 +279,6 @@ export function appendBrowserReference(taskId: string, reference: string): void const text = draft ? `${draft}\n\n${reference}` : reference; batch(() => { setStore('tasks', taskId, { promptDraft: text, prefillPrompt: text, promptDraftActive: true }); - setStore('showPromptInput', true); + revealTaskPromptInput(taskId); }); } diff --git a/src/store/focus.test.ts b/src/store/focus.test.ts index 558254e71..c8e27cec1 100644 --- a/src/store/focus.test.ts +++ b/src/store/focus.test.ts @@ -319,6 +319,16 @@ describe('focus navigation neighbor map', () => { expect(mockStore.focusedPanel['task-1']).toBe('changed-files'); }); + it('reaches a prompt box shown for a staged draft while the setting hides it', () => { + setTask('task-1', { promptInputRevealed: true }); + mockStore.showPromptInput = false; + mockStore.focusedPanel['task-1'] = 'ai-terminal'; + + navigateRow('down'); + + expect(mockStore.focusedPanel['task-1']).toBe('prompt'); + }); + it('falls back from vanished focused panels before navigating', () => { setTask('task-1'); mockStore.focusedPanel['task-1'] = 'removed-panel'; diff --git a/src/store/focus.ts b/src/store/focus.ts index b0c9cf914..39f7355ac 100644 --- a/src/store/focus.ts +++ b/src/store/focus.ts @@ -1,6 +1,7 @@ import { isDocumentAgentTaskId } from '../documents/task-id'; import { batch } from 'solid-js'; import { store, setStore } from './core'; +import { isTaskPromptInputShown } from './prompt-input-visibility'; import { openPanelOrder, setActiveTask } from './navigation'; import { showNotification } from './notification'; import { computeSidebarTaskOrder } from './sidebar-order'; @@ -148,7 +149,7 @@ function buildMainGrid(panelId: string): string[][] { // whatever's at the bottom-right, so → from prompt jumps into the shell // section instead of falling off to the next task. Left cells are padded // to the AI pane count so the right column keeps one column index. - const leftBottom = store.showPromptInput ? 'prompt' : aiCols[0]; + const leftBottom = isTaskPromptInputShown(task) ? 'prompt' : aiCols[0]; const bottomCols = aiCols.map(() => leftBottom); const rows = shellRows(panelId, task.shellAgentIds.length); if (rows.length > 0) { @@ -167,7 +168,7 @@ function buildMainGrid(panelId: string): string[][] { grid.push(toolbarCols); grid.push(...shellRows(panelId, task.shellAgentIds.length)); grid.push(aiCols); - if (store.showPromptInput) { + if (isTaskPromptInputShown(task)) { grid.push(['prompt']); } return grid; @@ -372,7 +373,7 @@ export function navigateRow(direction: 'up' | 'down'): void { } if (store.taskSplitMode[taskId]) { - if (direction === 'down' && isAiTerminalPanel(current) && store.showPromptInput) { + if (direction === 'down' && isAiTerminalPanel(current) && isTaskPromptInputShown(task)) { setTaskFocusedPanel(taskId, 'prompt'); return; } diff --git a/src/store/persistence.test.ts b/src/store/persistence.test.ts index d67b802a7..3edb350d2 100644 --- a/src/store/persistence.test.ts +++ b/src/store/persistence.test.ts @@ -1261,6 +1261,8 @@ describe('prompt draft persistence', () => { await loadState(); expect(store.tasks['task-1'].promptDraft).toBe('remember to check the migration'); + // Visible even when the user keeps the prompt box turned off. + expect(store.tasks['task-1'].promptInputRevealed).toBe(true); }); it('restores an unsent prompt draft on a collapsed task', async () => { diff --git a/src/store/persistence.ts b/src/store/persistence.ts index fce7c9e19..cda13e484 100644 --- a/src/store/persistence.ts +++ b/src/store/persistence.ts @@ -1334,6 +1334,9 @@ export async function loadState(): Promise { prBabysit: restoredPrBabysit(pt.prBabysit), notes: pt.notes, promptDraft: typeof pt.promptDraft === 'string' ? pt.promptDraft : undefined, + // An unsent draft stays visible even when the prompt box is turned off. + promptInputRevealed: + typeof pt.promptDraft === 'string' && pt.promptDraft.trim() !== '' ? true : undefined, browserUrl: typeof pt.browserUrl === 'string' ? pt.browserUrl : undefined, lastPrompt: pt.lastPrompt, promptHistory: restoredPromptHistory(pt.promptHistory), @@ -1490,6 +1493,9 @@ export async function loadState(): Promise { shellAgentIds: [], notes: pt.notes, promptDraft: typeof pt.promptDraft === 'string' ? pt.promptDraft : undefined, + // An unsent draft stays visible even when the prompt box is turned off. + promptInputRevealed: + typeof pt.promptDraft === 'string' && pt.promptDraft.trim() !== '' ? true : undefined, browserUrl: typeof pt.browserUrl === 'string' ? pt.browserUrl : undefined, lastPrompt: pt.lastPrompt, promptHistory: restoredPromptHistory(pt.promptHistory), diff --git a/src/store/prompt-input-visibility.ts b/src/store/prompt-input-visibility.ts new file mode 100644 index 000000000..d6a9e366c --- /dev/null +++ b/src/store/prompt-input-visibility.ts @@ -0,0 +1,24 @@ +import { setStore, store } from './core'; +import type { Task } from './types'; + +/** + * Shows one task's prompt box for a draft the app staged (a canvas request, + * a browser reference, a review), without touching the user's "Show prompt + * input box" preference. Sending the prompt hides it again. + */ +export function revealTaskPromptInput(taskId: string): void { + if (!store.tasks[taskId] || store.tasks[taskId].promptInputRevealed) return; + setStore('tasks', taskId, 'promptInputRevealed', true); +} + +export function concealTaskPromptInput(taskId: string): void { + if (!store.tasks[taskId]?.promptInputRevealed) return; + setStore('tasks', taskId, 'promptInputRevealed', undefined); +} + +/** Whether the task's prompt box shows: the preference, or a staged draft. */ +export function isTaskPromptInputShown( + task: Pick | undefined, +): boolean { + return store.showPromptInput || task?.promptInputRevealed === true; +} diff --git a/src/store/review.test.ts b/src/store/review.test.ts index c53f539e1..16253303f 100644 --- a/src/store/review.test.ts +++ b/src/store/review.test.ts @@ -70,7 +70,8 @@ describe('stageRework', () => { expect(store.tasks.t1.prefillPrompt).toMatch( /^Please rework this task based on my review:\n\n- Address this risk: No real provider\.\n/, ); - expect(store.showPromptInput).toBe(true); + expect(store.tasks.t1.promptInputRevealed).toBe(true); + expect(store.showPromptInput).toBe(false); }); }); diff --git a/src/store/staged-prompt.ts b/src/store/staged-prompt.ts index fd2fbd456..24b784d05 100644 --- a/src/store/staged-prompt.ts +++ b/src/store/staged-prompt.ts @@ -1,5 +1,6 @@ -import { setStore, store } from './core'; +import { store } from './core'; import { setTaskFocusedPanel } from './focused-panel'; +import { revealTaskPromptInput } from './prompt-input-visibility'; import { setPrefillPrompt, setTaskPromptDraftActive } from './tasks'; /** @@ -11,7 +12,7 @@ export function stageTaskPrompt(taskId: string, text: string): void { if (!task) return; const draft = task.prefillPrompt ?? task.promptDraft ?? ''; setTaskPromptDraftActive(taskId, true); - setStore('showPromptInput', true); + revealTaskPromptInput(taskId); setPrefillPrompt(taskId, [draft, text].filter(Boolean).join('\n\n')); queueMicrotask(() => { if (store.tasks[taskId]) setTaskFocusedPanel(taskId, 'prompt'); diff --git a/src/store/store.ts b/src/store/store.ts index 49fb370a1..c047c3a58 100644 --- a/src/store/store.ts +++ b/src/store/store.ts @@ -206,6 +206,7 @@ export { setReviewModel, setDefaultPropagateSkipPermissions, } from './ui'; +export { concealTaskPromptInput, isTaskPromptInputShown } from './prompt-input-visibility'; export { getTaskDotStatus, getTaskAttentionState, diff --git a/src/store/types.ts b/src/store/types.ts index e64baca20..0bfb6d853 100644 --- a/src/store/types.ts +++ b/src/store/types.ts @@ -394,6 +394,9 @@ export interface Task { * restart (app or machine) doesn't discard what the user typed but never * sent. Cleared on send. */ promptDraft?: string; + /** Shows the prompt box for a staged draft while the user keeps it hidden + * in Settings; cleared on send. Restored from a non-empty draft. */ + promptInputRevealed?: boolean; terminalInputPending?: boolean; terminalInputPendingFromQuestion?: boolean; delegationParent?: boolean;