diff --git a/packages/web-shell/client/components/ChatPane.module.css b/packages/web-shell/client/components/ChatPane.module.css index 9e502a92127..b08a96e10fe 100644 --- a/packages/web-shell/client/components/ChatPane.module.css +++ b/packages/web-shell/client/components/ChatPane.module.css @@ -10,10 +10,6 @@ overflow: hidden; } -.paneCurrent { - border-color: color-mix(in srgb, var(--primary) 60%, var(--border)); -} - .header { display: flex; align-items: center; @@ -52,16 +48,6 @@ color: var(--foreground); } -.currentBadge { - flex: 0 0 auto; - padding: 1px 7px; - border-radius: 999px; - font-size: 11px; - font-weight: 600; - color: var(--primary); - background: color-mix(in srgb, var(--primary) 14%, transparent); -} - .closeButton { flex: 0 0 auto; display: inline-flex; diff --git a/packages/web-shell/client/components/ChatPane.test.tsx b/packages/web-shell/client/components/ChatPane.test.tsx index 32923397e2b..970cace7dfc 100644 --- a/packages/web-shell/client/components/ChatPane.test.tsx +++ b/packages/web-shell/client/components/ChatPane.test.tsx @@ -21,6 +21,7 @@ let latestOnSubmit: | undefined; let sendPromptResolve: (() => void) | undefined; let sendPromptReject: ((e: unknown) => void) | undefined; +let sendPromptAdmit: (() => void) | undefined; const sendPrompt = vi.fn(async () => ({}) as any); const submitPermission = vi.fn(async () => {}); const cancel = vi.fn(async () => {}); @@ -55,7 +56,9 @@ vi.mock('./StreamingStatus', () => ({ StreamingStatus: (props: any) => (
), @@ -121,10 +124,13 @@ beforeEach(() => { latestOnSubmit = undefined; sendPrompt.mockReset(); // Each sendPrompt returns a promise the test controls, so we can assert the - // draft is committed only after the prompt is accepted. + // draft is committed on admission (onAdmitted) rather than on turn completion + // (promise resolution). `sendPromptAdmit` captures the options.onAdmitted hook. + sendPromptAdmit = undefined; sendPrompt.mockImplementation( - () => + (_text?: string, options?: { onAdmitted?: () => void }) => new Promise((resolve, reject) => { + sendPromptAdmit = options?.onAdmitted; sendPromptResolve = () => resolve({}); sendPromptReject = (e) => reject(e); }), @@ -182,16 +188,26 @@ describe('ChatPane', () => { expect((sendPrompt.mock.calls[0] as unknown[])[0]).toBe('hello there'); }); - it('commits the draft only after the prompt is accepted', async () => { + it('commits the draft on admission, without waiting for the turn to finish', async () => { render(); const commit = vi.fn(); let returned: boolean | undefined; act(() => { returned = latestOnSubmit!('hi', undefined, commit); }); - // Returns false (keep the draft) and does NOT commit before acceptance. + // Returns false (keep the draft) and does NOT commit before admission. expect(returned).toBe(false); expect(commit).not.toHaveBeenCalled(); + // The daemon admits the prompt (onAdmitted). The draft clears now, even + // though the turn promise is still pending — a long response must not strand + // the sent text in the composer until the turn ends. + await act(async () => { + sendPromptAdmit!(); + await Promise.resolve(); + }); + expect(commit).toHaveBeenCalledTimes(1); + // The turn finishing later must NOT commit again — guards against regressing + // to committing on promise resolution (turn end) instead of admission. await act(async () => { sendPromptResolve!(); await Promise.resolve(); @@ -212,6 +228,29 @@ describe('ChatPane', () => { expect(commit).not.toHaveBeenCalled(); }); + it('keeps the draft cleared and still reports the error when the turn fails after admission', async () => { + const onError = vi.fn(); + render({ onError }); + const commit = vi.fn(); + act(() => { + latestOnSubmit!('hi', undefined, commit); + }); + // Admission clears the draft. + await act(async () => { + sendPromptAdmit!(); + await Promise.resolve(); + }); + expect(commit).toHaveBeenCalledTimes(1); + // The turn then fails mid-flight: the draft stays cleared (no second commit) + // and the failure is still surfaced to onError. + await act(async () => { + sendPromptReject!(new Error('turn crashed')); + await Promise.resolve(); + }); + expect(commit).toHaveBeenCalledTimes(1); + expect(onError).toHaveBeenCalled(); + }); + it('keeps pane approvals click-only (no global keyboard shortcuts)', () => { pendingPermission = { id: 'perm-1', toolName: 'write_file', rawInput: {} }; render(); @@ -237,7 +276,11 @@ describe('ChatPane', () => { new MouseEvent('click', { bubbles: true }), ), ); - expect(submitPermission).toHaveBeenCalledWith('perm-1', 'proceed', undefined); + expect(submitPermission).toHaveBeenCalledWith( + 'perm-1', + 'proceed', + undefined, + ); }); it('routes an AskUserQuestion permission to the AskUserQuestion overlay', () => { diff --git a/packages/web-shell/client/components/ChatPane.tsx b/packages/web-shell/client/components/ChatPane.tsx index f7f7e1c1390..a640e694ce5 100644 --- a/packages/web-shell/client/components/ChatPane.tsx +++ b/packages/web-shell/client/components/ChatPane.tsx @@ -30,8 +30,6 @@ const EMPTY_TOOLBAR: never[] = []; export interface ChatPaneProps { /** Header label; falls back to the session's own display name / id. */ title?: string; - /** Marks the pane bound to the window's primary (sidebar-selected) session. */ - isCurrent?: boolean; onClose?: () => void; onError?: (error: unknown, fallback: string) => void; } @@ -43,7 +41,7 @@ export interface ChatPaneProps { * state, approvals, and composer, and the browser scopes keyboard focus to the * pane the user clicks into — so there is no cross-pane approval arbitration. */ -export function ChatPane({ title, isCurrent, onClose, onError }: ChatPaneProps) { +export function ChatPane({ title, onClose, onError }: ChatPaneProps) { const { t } = useI18n(); const connection = useConnection(); const actions = useActions(); @@ -92,13 +90,19 @@ export function ChatPane({ title, isCurrent, onClose, onError }: ChatPaneProps) ): boolean => { const trimmed = text.trim(); if (!trimmed) return false; - // Keep the draft (return false) until the prompt is actually accepted: - // sendPrompt can reject (transcript still loading, session disconnected, - // or a turn already active), and committing first would silently drop the - // user's text. Commit only once it resolves. + // Keep the draft (return false) and clear it only once the daemon ADMITS + // the prompt. `onAdmitted` fires at acceptance; the sendPrompt promise + // itself resolves only when the whole (possibly long) turn finishes, so + // committing on resolution would strand the sent text in the composer for + // the entire response. If the prompt is rejected before admission + // (transcript still loading, session disconnected, or a turn already + // active) onAdmitted never fires, so the draft is preserved and the error + // is surfaced. actions - .sendPrompt(trimmed, images && images.length ? { images } : undefined) - .then(() => commitAccepted?.()) + .sendPrompt(trimmed, { + ...(images && images.length ? { images } : {}), + onAdmitted: commitAccepted, + }) .catch((error: unknown) => reportError(error, 'Failed to send prompt')); return false; }, @@ -119,7 +123,9 @@ export function ChatPane({ title, isCurrent, onClose, onError }: ChatPaneProps) const handleCancel = useCallback(() => { actions .cancel() - .catch((error: unknown) => reportError(error, 'Failed to cancel request')); + .catch((error: unknown) => + reportError(error, 'Failed to cancel request'), + ); }, [actions, reportError]); const headerLabel = @@ -127,9 +133,7 @@ export function ChatPane({ title, isCurrent, onClose, onError }: ChatPaneProps) return (
@@ -137,11 +141,6 @@ export function ChatPane({ title, isCurrent, onClose, onError }: ChatPaneProps) {headerLabel} - {isCurrent && ( - - {t('sessionsOverview.current')} - - )} {onClose && (