Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion src/components/PromptInput.client.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -21,6 +24,7 @@ const { storeMock, setTaskPromptDraft, taskUsesAgentChat } = vi.hoisted(() => ({
tasks: {} as Record<string, unknown>,
agents: {} as Record<string, unknown>,
mcpOrchestrationEnabled: true,
showPromptInput: true,
},
setTaskPromptDraft: vi.fn(),
taskUsesAgentChat: vi.fn(() => false),
Expand Down Expand Up @@ -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(),
Expand All @@ -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();
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions src/components/PromptInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ import {
markTaskUserActivity,
setTaskPromptDraft,
setTaskPromptDraftActive,
setTaskFocusedPanel,
setTaskTerminalInputPending,
showNotification,
concealTaskPromptInput,
} from '../store/store';
import {
clearStagedNotification,
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/components/TaskPanel.reasoning.client.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
});
Expand Down
9 changes: 5 additions & 4 deletions src/components/TaskPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
isTaskCanvasVisible,
referenceTourCard,
openCanvasDocument,
isTaskPromptInputShown,
} from '../store/store';
import { markFeatureHintSeen } from '../store/onboarding';
import { useFocusRegistration } from '../lib/focus-registration';
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -1202,15 +1203,15 @@ export function TaskPanel(props: TaskPanelProps) {
props.task,
message,
promptHandle,
store.showPromptInput && !isAgentChat(props.task, firstAgentId()),
isTaskPromptInputShown(props.task) && !isAgentChat(props.task, firstAgentId()),
)
}
onUseComposer={(message) =>
usePeerComposer(
props.task,
message,
promptHandle,
store.showPromptInput && !isAgentChat(props.task, firstAgentId()),
isTaskPromptInputShown(props.task) && !isAgentChat(props.task, firstAgentId()),
)
}
/>
Expand Down
6 changes: 4 additions & 2 deletions src/store/canvas.client.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down Expand Up @@ -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());
});
});
5 changes: 3 additions & 2 deletions src/store/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);
});
}
10 changes: 10 additions & 0 deletions src/store/focus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 4 additions & 3 deletions src/store/focus.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/store/persistence.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
6 changes: 6 additions & 0 deletions src/store/persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,9 @@ export async function loadState(): Promise<void> {
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),
Expand Down Expand Up @@ -1490,6 +1493,9 @@ export async function loadState(): Promise<void> {
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),
Expand Down
24 changes: 24 additions & 0 deletions src/store/prompt-input-visibility.ts
Original file line number Diff line number Diff line change
@@ -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<Task, 'promptInputRevealed'> | undefined,
): boolean {
return store.showPromptInput || task?.promptInputRevealed === true;
}
3 changes: 2 additions & 1 deletion src/store/review.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down
5 changes: 3 additions & 2 deletions src/store/staged-prompt.ts
Original file line number Diff line number Diff line change
@@ -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';

/**
Expand All @@ -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');
Expand Down
1 change: 1 addition & 0 deletions src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ export {
setReviewModel,
setDefaultPropagateSkipPermissions,
} from './ui';
export { concealTaskPromptInput, isTaskPromptInputShown } from './prompt-input-visibility';
export {
getTaskDotStatus,
getTaskAttentionState,
Expand Down
3 changes: 3 additions & 0 deletions src/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down