Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): keep composer attachments when a message task is canceled (STORY-38)
M091f3e062821
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsxindex 61b024077..e5112a762 100644--- a/desktop-app/ui/src/App.tsx+++ b/desktop-app/ui/src/App.tsx@@ -2547,7 +2547,7 @@ export function App() {onToggleChatDrawer={toggleChatDrawer}/></TitlebarActionsPortal>- <ToastStack items={vm.toasts} />+ <ToastStack items={vm.toasts} onDismiss={vm.dismissToast} />{/* Single global strip: driven by the universalstore, visible on every route above theper-kind seam so any tab is reachable from any@@ -2764,7 +2764,7 @@ export function App() {)}{environmentSetupConfirmationDialog}{environmentSetupSuccessDialog}- <ToastStack items={vm.toasts} />+ <ToastStack items={vm.toasts} onDismiss={vm.dismissToast} /></>)}</div>diff --git a/desktop-app/ui/src/components/Common/ToastStack/__tests__/ToastStack.test.tsx b/desktop-app/ui/src/components/Common/ToastStack/__tests__/ToastStack.test.tsxnew file mode 100644index 000000000..5d2996d07--- /dev/null+++ b/desktop-app/ui/src/components/Common/ToastStack/__tests__/ToastStack.test.tsx@@ -0,0 +1,70 @@+// @vitest-environment jsdom+import { afterEach, describe, expect, it, vi } from 'vitest'+import { cleanup, fireEvent, render, screen } from '@testing-library/react'+import { ToastStack } from '../index'++afterEach(() => {+ cleanup()+ vi.restoreAllMocks()+})++describe('ToastStack', () => {+ it('renders nothing without items', () => {+ const { container } = render(<ToastStack items={[]} />)+ expect(container.firstChild).toBeNull()+ })++ it('renders each toast with its tone role and no action button by default', () => {+ render(+ <ToastStack+ items={[+ { id: 1, tone: 'info', text: 'Saved.' },+ { id: 2, tone: 'error', text: 'Boom.' },+ ]}+ />+ )+ expect(screen.getByRole('status').textContent).toContain('Saved.')+ expect(screen.getByRole('alert').textContent).toContain('Boom.')+ expect(screen.queryByRole('button')).toBeNull()+ })++ it('runs the toast action and dismisses through onDismiss when clicked', () => {+ const onAction = vi.fn()+ const onDismiss = vi.fn()+ render(+ <ToastStack+ items={[+ {+ id: 7,+ tone: 'info',+ text: 'Attachments kept',+ action: { label: 'Discard all', onAction },+ },+ ]}+ onDismiss={onDismiss}+ />+ )+ const action = screen.getByRole('button', { name: 'Discard all' })+ fireEvent.click(action)+ expect(onAction).toHaveBeenCalledTimes(1)+ expect(onDismiss).toHaveBeenCalledWith(7)+ })++ it('runs the action without an onDismiss handler', () => {+ const onAction = vi.fn()+ render(+ <ToastStack+ items={[+ {+ id: 8,+ tone: 'info',+ text: 'Attachments kept',+ action: { label: 'Discard all', onAction },+ },+ ]}+ />+ )+ fireEvent.click(screen.getByRole('button', { name: 'Discard all' }))+ expect(onAction).toHaveBeenCalledTimes(1)+ })+})diff --git a/desktop-app/ui/src/components/Common/ToastStack/index.tsx b/desktop-app/ui/src/components/Common/ToastStack/index.tsxindex 5828476bf..e3f7c96cf 100644--- a/desktop-app/ui/src/components/Common/ToastStack/index.tsx+++ b/desktop-app/ui/src/components/Common/ToastStack/index.tsx@@ -5,7 +5,7 @@ import type { ToastStackProps } from './types'// (polite for status, assertive for alert), so we do NOT set aria-live on// the container -- duplicating it caused double-announcements on screen// readers for error toasts.-export function ToastStack({ items }: ToastStackProps) {+export function ToastStack({ items, onDismiss }: ToastStackProps) {if (!items.length) return nullreturn (@@ -19,7 +19,19 @@ export function ToastStack({ items }: ToastStackProps) {<span aria-hidden className="toast-icon">{item.tone === 'success' ? '●' : item.tone === 'error' ? '!' : 'i'}</span>- <span>{item.text}</span>+ <span className="toast-body">{item.text}</span>+ {item.action ? (+ <button+ type="button"+ className="toast-action"+ onClick={() => {+ item.action?.onAction()+ onDismiss?.(item.id)+ }}+ >+ {item.action.label}+ </button>+ ) : null}</div>))}</aside>diff --git a/desktop-app/ui/src/components/Common/ToastStack/types.ts b/desktop-app/ui/src/components/Common/ToastStack/types.tsindex 6b5f17079..8cf5884c7 100644--- a/desktop-app/ui/src/components/Common/ToastStack/types.ts+++ b/desktop-app/ui/src/components/Common/ToastStack/types.ts@@ -2,4 +2,6 @@ import type { ToastMessage } from '@/uiTypes'export type ToastStackProps = {items: ToastMessage[]+ /** Removes a toast before its auto-dismiss (e.g. after its action ran). */+ onDismiss?: (id: number) => void}diff --git a/desktop-app/ui/src/components/agents/ComposerPanel.tsx b/desktop-app/ui/src/components/agents/ComposerPanel.tsxindex f455c01d2..03e18d1cd 100644--- a/desktop-app/ui/src/components/agents/ComposerPanel.tsx+++ b/desktop-app/ui/src/components/agents/ComposerPanel.tsx@@ -129,6 +129,7 @@ export function ComposerPanel({ inline = false, agentSelector }: ComposerPanelPrhandleRemoveComposerImageAttachment: onRemoveComposerImageAttachment,handleAddComposerReferenceAttachments: onAddComposerReferenceAttachments,handleRemoveComposerReferenceAttachment: onRemoveComposerReferenceAttachment,+ handleClearComposerAttachments: onClearComposerAttachments,handleSendAgentMessage: onSend,handleRetryFailedAgentSend: onRetryFailedSend,handleRecoverFailedAgentSend: onRecoverFailedSend,@@ -1005,6 +1006,13 @@ export function ComposerPanel({ inline = false, agentSelector }: ComposerPanelPr</span>{hasComposerAttachments ? (<span className="composer-attachments-list composer-attachments-list--inline">+ <span+ className="composer-attachments-count"+ data-testid="composer-attachments-count"+ >+ {composerAttachmentItems.length}{' '}+ {composerAttachmentItems.length === 1 ? 'attachment' : 'attachments'}+ </span>{composerAttachmentItems.map(item => {if (item.kind === 'reference') {const attachment = item.attachment@@ -1066,6 +1074,14 @@ export function ComposerPanel({ inline = false, agentSelector }: ComposerPanelPr</span>)})}+ <button+ type="button"+ className="composer-attachments-clear"+ onClick={onClearComposerAttachments}+ aria-label="Clear all attachments"+ >+ Clear all+ </button></span>) : null}</span>diff --git a/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx b/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsxindex 2e9b9aaef..b233c97a6 100644--- a/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx+++ b/desktop-app/ui/src/components/agents/__tests__/ComposerPanel.test.tsx@@ -17,7 +17,11 @@ import {imageInputBlockMessage,} from '../../../../../src/imageInputDecision'import type { WorkflowRecipeListResult } from '../../../../../src/types'-import type { ComposerImageAttachment, FailedAgentSend } from '../../../uiTypes'+import type {+ ComposerImageAttachment,+ ComposerReferenceAttachment,+ FailedAgentSend,+} from '../../../uiTypes'import { ComposerPanel } from '../ComposerPanel'// Resolve the stylesheet relative to THIS test file (not process.cwd()) so the@@ -47,6 +51,7 @@ const actionsMock = {handleRemoveComposerImageAttachment: vi.fn(),handleAddComposerReferenceAttachments: vi.fn(),handleRemoveComposerReferenceAttachment: vi.fn(),+ handleClearComposerAttachments: vi.fn(),handleSendAgentMessage: vi.fn(),handleRetryFailedAgentSend: vi.fn(),handleRecoverFailedAgentSend: vi.fn(),@@ -949,6 +954,70 @@ describe('ComposerPanel with a pending image after a model switch', () => {})})+describe('ComposerPanel attachments chip row (STORY-38)', () => {+ const firstImage: ComposerImageAttachment = {+ id: 'kept-image-1',+ name: 'kept-a.png',+ mimeType: 'image/png',+ dataBase64: 'iVBORw0KGgo=',+ sizeBytes: 8,+ previewDataUrl: 'data:image/png;base64,iVBORw0KGgo=',+ }+ const secondImage: ComposerImageAttachment = {+ id: 'kept-image-2',+ name: 'kept-b.png',+ mimeType: 'image/png',+ dataBase64: 'iVBORw0KGgoB',+ sizeBytes: 9,+ previewDataUrl: 'data:image/png;base64,iVBORw0KGgoB',+ }+ const pluginReference: ComposerReferenceAttachment = {+ id: 'kept-ref-1',+ type: 'plugin',+ namespace: 'ns',+ name: 'helper',+ label: 'helper plugin',+ }++ it('shows no count or clear control while the composer has no attachments', () => {+ render(<ComposerPanel inline />)+ expect(screen.queryByTestId('composer-attachments-count')).toBeNull()+ expect(screen.queryByRole('button', { name: 'Clear all attachments' })).toBeNull()+ })++ it('counts every pending attachment, singular and plural, with per-file remove buttons', () => {+ composerState.composerImageAttachments = [firstImage]+ const { rerender } = render(<ComposerPanel inline />)+ expect(screen.getByTestId('composer-attachments-count').textContent).toBe('1 attachment')+ expect(screen.getByRole('button', { name: 'Remove kept-a.png' })).toBeTruthy()++ composerState.composerImageAttachments = [firstImage, secondImage]+ composerState.composerReferenceAttachments = [pluginReference]+ rerender(<ComposerPanel inline />)+ expect(screen.getByTestId('composer-attachments-count').textContent).toBe('3 attachments')+ expect(screen.getByRole('button', { name: 'Remove kept-b.png' })).toBeTruthy()+ expect(screen.getByRole('button', { name: 'Remove helper plugin' })).toBeTruthy()+ })++ it('clears every pending attachment through the explicit clear control', () => {+ composerState.composerImageAttachments = [firstImage, secondImage]+ composerState.composerReferenceAttachments = [pluginReference]+ render(<ComposerPanel inline />)++ fireEvent.click(screen.getByRole('button', { name: 'Clear all attachments' }))+ expect(actionsMock.handleClearComposerAttachments).toHaveBeenCalledTimes(1)+ expect(actionsMock.handleRemoveComposerImageAttachment).not.toHaveBeenCalled()+ expect(actionsMock.handleRemoveComposerReferenceAttachment).not.toHaveBeenCalled()+ })++ it('styles the clear control and the count as part of the inline chip row', () => {+ composerState.composerImageAttachments = [firstImage]+ render(<ComposerPanel inline />)+ expect(cssRule('.composer-attachments-count')).toContain('white-space: nowrap')+ expect(cssRule('.composer-attachments-clear')).toContain('cursor: pointer')+ })+})+describe('ComposerPanel failed-send recovery actions', () => {const failedSend: FailedAgentSend = {content: 'inspect this image',diff --git a/desktop-app/ui/src/contexts/AgentChatActionsContext/types.ts b/desktop-app/ui/src/contexts/AgentChatActionsContext/types.tsindex be847729f..5e0baf8b6 100644--- a/desktop-app/ui/src/contexts/AgentChatActionsContext/types.ts+++ b/desktop-app/ui/src/contexts/AgentChatActionsContext/types.ts@@ -33,6 +33,7 @@ export interface AgentChatActionsContextValue {handleRemoveComposerImageAttachment: (attachmentId: string) => voidhandleAddComposerReferenceAttachments: (attachments: ComposerReferenceAttachment[]) => voidhandleRemoveComposerReferenceAttachment: (attachmentId: string) => void+ handleClearComposerAttachments: () => voidhandleSendAgentMessage: (text: string) => Promise<void>handleRetryFailedAgentSend: () => Promise<void>handleRecoverFailedAgentSend: () => voiddiff --git a/desktop-app/ui/src/hooks/domain/__tests__/cancelKeepsAttachments.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/cancelKeepsAttachments.test.tsxnew file mode 100644index 000000000..d8dee505e--- /dev/null+++ b/desktop-app/ui/src/hooks/domain/__tests__/cancelKeepsAttachments.test.tsx@@ -0,0 +1,174 @@+// @vitest-environment jsdom+/**+ * STORY-38 — canceling an in-flight task keeps the canceled message's+ * attachments available: they return to the in-memory composer state (never+ * GFS or another persisted store) and an "Attachments kept" toast offers an+ * explicit "Discard all" action. The retained send snapshot itself is still+ * released (a cancel stays terminal for delivery), and a cancel that fails+ * upstream restores nothing.+ */+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { act, waitFor } from '@testing-library/react'+import { loadHostModels, resetHostModelSelectionStore } from '@lib/hostModelSelectionStore'+import type { HostModelsResult } from '../../../../../src/types'+import type {+ ComposerImageAttachment,+ ComposerPluginReference,+ ToastMessageAction,+} from '../../../uiTypes'+import { renderController } from './__fixtures__/controllerHarness'+import { type MockClerum, installMockClerum, uninstallMockClerum } from './__fixtures__/mockClerum'++let clerum: MockClerum+const image: ComposerImageAttachment = {+ id: 'input-image',+ name: 'input.png',+ mimeType: 'image/png',+ dataBase64: 'YWJj',+ sizeBytes: 3,+ previewDataUrl: 'data:image/png;base64,YWJj',+}+const pluginReference: ComposerPluginReference = {+ id: 'plugin-ref',+ type: 'plugin',+ namespace: 'ns',+ name: 'helper',+ label: 'helper plugin',+}+const catalog: HostModelsResult = {+ provider: 'zai',+ hostDefault: 'glm-5.3-flash',+ sessionModel: null,+ degraded: false,+ modelSelectionRevision: 0,+ models: [{ name: 'glm-5.3-flash', imageInput: { state: 'supported', reason: 'supported' } }],+}++const modelTransport = {+ getHostModels: vi.fn(async () => catalog),+ setHostModel: vi.fn(async (_host: string, _chat: string, model: string) => ({+ effective: 'next-task' as const,+ provider: 'zai',+ model,+ modelSelectionRevision: 1,+ })),+}++;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true++beforeEach(() => {+ clerum = installMockClerum()+ Object.assign(clerum.rpc, modelTransport)+})++afterEach(() => {+ vi.restoreAllMocks()+ resetHostModelSelectionStore()+ uninstallMockClerum()+})++function keptToastAction(+ spies: ReturnType<typeof renderController>['spies']+): ToastMessageAction | undefined {+ const call = spies.pushToast.mock.calls.find(([message]) => message === 'Attachments kept')+ return call?.[2]?.action+}++/** Mounts with a capable model catalog, then attaches an image + a reference. */+async function mountedControllerWithAttachments() {+ const rendered = renderController()+ await waitFor(() => expect(clerum.chat.getIndex).toHaveBeenCalled())+ await act(async () => {+ await loadHostModels(modelTransport, 'agent-x', null)+ })+ act(() => rendered.result.current.handleAddComposerImageAttachments([image]))+ act(() => rendered.result.current.handleAddComposerReferenceAttachments([pluginReference]))+ return rendered+}++/** Sends the pending payload as an async task and waits for its progress handler. */+async function sendAsync(result: ReturnType<typeof renderController>['result'], taskId: string) {+ clerum.rpc.invokeHostMessage.mockResolvedValue({ taskId })+ const send = act(async () => {+ await result.current.handleSendAgentMessage('cancel me')+ })+ await waitFor(() => expect(clerum.hasProgressHandler(taskId)).toBe(true))+ await send+}++describe('STORY-38 — attachments survive message cancel', () => {+ it('returns the canceled message attachments to the composer with a Discard all toast', async () => {+ const { result, spies } = await mountedControllerWithAttachments()+ await sendAsync(result, 'task-cancel')+ // The accepted send cleared the composer.+ expect(result.current.composerImageAttachments).toHaveLength(0)+ expect(result.current.composerReferenceAttachments).toHaveLength(0)++ await act(async () => {+ await result.current.cancelTask('task-cancel')+ })++ expect(clerum.rpc.cancelTask).toHaveBeenCalledWith('agent-x', 'task-cancel')+ expect(result.current.composerImageAttachments[0]).toMatchObject({+ id: image.id,+ dataBase64: image.dataBase64,+ previewDataUrl: 'data:image/png;base64,YWJj',+ })+ expect(result.current.composerReferenceAttachments[0]).toMatchObject({+ id: pluginReference.id,+ })+ const action = keptToastAction(spies)+ expect(action?.label).toBe('Discard all')++ act(() => action?.onAction())+ expect(result.current.composerImageAttachments).toHaveLength(0)+ expect(result.current.composerReferenceAttachments).toHaveLength(0)+ })++ it('restores the attachments when the task is already gone upstream', async () => {+ clerum.rpc.cancelTask.mockRejectedValue(new Error('404 Not Found'))+ const { result, spies } = await mountedControllerWithAttachments()+ await sendAsync(result, 'task-gone')++ await act(async () => {+ await result.current.cancelTask('task-gone')+ })++ expect(result.current.composerImageAttachments).toHaveLength(1)+ expect(result.current.composerReferenceAttachments).toHaveLength(1)+ expect(keptToastAction(spies)?.label).toBe('Discard all')+ })++ it('restores nothing and toasts nothing for a text-only canceled message', async () => {+ const rendered = renderController()+ const { result, spies } = rendered+ await waitFor(() => expect(clerum.chat.getIndex).toHaveBeenCalled())+ await sendAsync(result, 'task-text')++ await act(async () => {+ await result.current.cancelTask('task-text')+ })++ expect(result.current.composerImageAttachments).toHaveLength(0)+ expect(result.current.composerReferenceAttachments).toHaveLength(0)+ expect(keptToastAction(spies)).toBeUndefined()+ })++ it('restores nothing when the cancel itself fails upstream', async () => {+ clerum.rpc.cancelTask.mockRejectedValue(new Error('500 upstream exploded'))+ const { result, spies } = await mountedControllerWithAttachments()+ await sendAsync(result, 'task-fail')++ await act(async () => {+ await result.current.cancelTask('task-fail')+ })++ expect(result.current.composerImageAttachments).toHaveLength(0)+ expect(result.current.composerReferenceAttachments).toHaveLength(0)+ expect(keptToastAction(spies)).toBeUndefined()+ expect(spies.pushToast).toHaveBeenCalledWith(+ expect.stringContaining('Failed to cancel task'),+ 'error'+ )+ })+})diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useToastController.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useToastController.test.tsxnew file mode 100644index 000000000..3b18ea1db--- /dev/null+++ b/desktop-app/ui/src/hooks/domain/__tests__/useToastController.test.tsx@@ -0,0 +1,65 @@+// @vitest-environment jsdom+import { afterEach, describe, expect, it, vi } from 'vitest'+import { act, renderHook } from '@testing-library/react'+import { useToastController } from '../useToastController'++afterEach(() => {+ vi.restoreAllMocks()+ vi.useRealTimers()+})++describe('useToastController', () => {+ it('pushes a toast with an inline action', () => {+ const onAction = vi.fn()+ const { result } = renderHook(() => useToastController())++ act(() => {+ result.current.pushToast('Attachments kept', 'info', {+ action: { label: 'Discard all', onAction },+ })+ })++ expect(result.current.toasts).toHaveLength(1)+ expect(result.current.toasts[0]).toMatchObject({+ text: 'Attachments kept',+ tone: 'info',+ action: { label: 'Discard all', onAction },+ })+ })++ it('dismissToast removes the toast immediately', async () => {+ const onAction = vi.fn()+ const { result } = renderHook(() => useToastController())+ act(() => {+ result.current.pushToast('Attachments kept', 'info', {+ action: { label: 'Discard all', onAction },+ })+ })+ const id = result.current.toasts[0]!.id++ act(() => {+ result.current.dismissToast(id)+ })++ expect(result.current.toasts).toHaveLength(0)+ // Dismissing before the auto-dismiss timer must not resurrect the toast.+ await act(async () => {+ await new Promise(resolve => setTimeout(resolve, 0))+ })+ expect(result.current.toasts).toHaveLength(0)+ })++ it('still auto-dismisses toasts without an action', async () => {+ vi.useFakeTimers()+ const { result } = renderHook(() => useToastController())+ act(() => {+ result.current.pushToast('Saved.', 'success')+ })+ expect(result.current.toasts).toHaveLength(1)++ await act(async () => {+ await vi.advanceTimersByTimeAsync(10_000)+ })+ expect(result.current.toasts).toHaveLength(0)+ })+})diff --git a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts b/desktop-app/ui/src/hooks/domain/useAgentChatController.tsindex dca0f7034..03afb4785 100644--- a/desktop-app/ui/src/hooks/domain/useAgentChatController.ts+++ b/desktop-app/ui/src/hooks/domain/useAgentChatController.ts@@ -95,6 +95,7 @@ import {import { type ActiveChatVisibility, useChatNotifications } from './useChatNotifications'import { useChatScroll } from './useChatScroll'import { useComposerAttachments } from './useComposerAttachments'+import type { PushToastOptions } from './useToastController'// Re-exported from `useChatListController` (§4.4) so external importers// (useWorkspaceController, useActivityController) keep their import site.@@ -344,7 +345,7 @@ interface UseAgentChatControllerParams {isAuthenticated: booleanloadMenuData: booleannavItem: NavItem- pushToast: (msg: string, tone: Tone) => void+ pushToast: (msg: string, tone: Tone, options?: PushToastOptions) => voidpushNotification: (n: PushNotificationInput) => void/*** Human-visible name for an agent identifier (catalog `spec.host` display@@ -552,6 +553,7 @@ export function useAgentChatController({releaseRetainedFailuresForChat,releaseSucceededRetainedSend,releaseSucceededRetainedSendsForTask,+ getRetainedSendsForTask,markRetainedSendReason,failRetainedSend,} = retainedSends@@ -3494,6 +3496,38 @@ export function useAgentChatController({handleDiscardFailedAgentSend,])+ /**+ * STORY-38 — a cancel is terminal for DELIVERY (the snapshot below is still+ * released), but the attachments of the canceled message return to the+ * composer so the user can reuse them. In-memory only: the composer state,+ * not GFS or any persisted store, owns the kept attachments.+ */+ const restoreComposerAttachmentsAfterCancel = useCallback(+ (taskId: string) => {+ const snapshots = getRetainedSendsForTask(taskId)+ const images = snapshots.flatMap(snapshot => snapshot.attachments)+ const references = snapshots.flatMap(snapshot => snapshot.references)+ if (!images.length && !references.length) return+ handleAddComposerImageAttachments(+ images.map(attachment => ({+ ...attachment,+ previewDataUrl: `data:${attachment.mimeType};base64,${attachment.dataBase64}`,+ }))+ )+ handleAddComposerReferenceAttachments(references)+ pushToast('Attachments kept', 'info', {+ action: { label: 'Discard all', onAction: resetComposerAttachments },+ })+ },+ [+ getRetainedSendsForTask,+ handleAddComposerImageAttachments,+ handleAddComposerReferenceAttachments,+ pushToast,+ resetComposerAttachments,+ ]+ )+const cancelTask = useCallback(async (taskId: string) => {const hostRef = selectedAgent@@ -3542,7 +3576,10 @@ export function useAgentChatController({await window.clerum.rpc.cancelTask(hostRef, taskId)markCancelled('Cancelled by user.')// #654 M6 — a cancel is terminal by intent: the user does not want this- // payload resent, so nothing will read the retained snapshot again.+ // payload resent, so nothing will read the retained snapshot again. The+ // attachments themselves return to the composer (STORY-38) before the+ // snapshot that carried them is released.+ restoreComposerAttachmentsAfterCancel(taskId)releaseRetainedSendsForTask(taskId)} catch (err) {const message = err instanceof Error ? err.message : String(err)@@ -3550,6 +3587,7 @@ export function useAgentChatController({markCancelled('Task already finished or is no longer active.')// The task is gone upstream, so it can no longer produce a terminal// event — same reasoning as the successful cancel above.+ restoreComposerAttachmentsAfterCancel(taskId)releaseRetainedSendsForTask(taskId)pushToast('That task is no longer active.', 'info')return@@ -3558,7 +3596,7 @@ export function useAgentChatController({pushToast(`Failed to cancel task: ${message}`, 'error')}},- [pushToast, selectedAgent, releaseRetainedSendsForTask]+ [pushToast, selectedAgent, releaseRetainedSendsForTask, restoreComposerAttachmentsAfterCancel])const setPendingChatSelection = useCallback(@@ -3712,6 +3750,7 @@ export function useAgentChatController({handleRemoveComposerImageAttachment,handleAddComposerReferenceAttachments,handleRemoveComposerReferenceAttachment,+ handleClearComposerAttachments: resetComposerAttachments,cancelTask,}}diff --git a/desktop-app/ui/src/hooks/domain/useToastController.ts b/desktop-app/ui/src/hooks/domain/useToastController.tsindex 7a3939897..063d58bba 100644--- a/desktop-app/ui/src/hooks/domain/useToastController.ts+++ b/desktop-app/ui/src/hooks/domain/useToastController.ts@@ -1,23 +1,31 @@import { useCallback, useEffect, useState } from 'react'import { DEFAULT_TOAST_DURATION_MS, ERROR_TOAST_DURATION_MS } from '@constants/toasts'-import type { ToastMessage, Tone } from '../../uiTypes'+import type { ToastMessage, ToastMessageAction, Tone } from '../../uiTypes'++export interface PushToastOptions {+ durationMs?: number+ action?: ToastMessageAction+}export function useToastController() {const [toasts, setToasts] = useState<ToastMessage[]>([])- const pushToast = useCallback(- (message: string, tone: Tone, options: { durationMs?: number } = {}) => {- if (!message.trim()) return- const toast: ToastMessage = {- id: Date.now() + Math.floor(Math.random() * 1000),- text: message,- tone,- durationMs: options.durationMs,- }- setToasts(previous => [...previous.slice(-2), toast])- },- []- )+ const pushToast = useCallback((message: string, tone: Tone, options: PushToastOptions = {}) => {+ if (!message.trim()) return+ const toast: ToastMessage = {+ id: Date.now() + Math.floor(Math.random() * 1000),+ text: message,+ tone,+ durationMs: options.durationMs,+ action: options.action,+ }+ setToasts(previous => [...previous.slice(-2), toast])+ }, [])++ /** Removes a toast immediately (used after its inline action ran). */+ const dismissToast = useCallback((id: number) => {+ setToasts(previous => previous.filter(toast => toast.id !== id))+ }, [])useEffect(() => {if (!toasts.length) return@@ -33,5 +41,5 @@ export function useToastController() {return () => window.clearTimeout(timeoutId)}, [toasts])- return { toasts, pushToast }+ return { toasts, pushToast, dismissToast }}diff --git a/desktop-app/ui/src/hooks/useAgentChatActionsValue.ts b/desktop-app/ui/src/hooks/useAgentChatActionsValue.tsindex 49a6826ea..d79891e84 100644--- a/desktop-app/ui/src/hooks/useAgentChatActionsValue.ts+++ b/desktop-app/ui/src/hooks/useAgentChatActionsValue.ts@@ -36,6 +36,7 @@ export function useAgentChatActionsValue(vm: AppVm): AgentChatActionsContextValuconst handleRemoveComposerReferenceAttachment = useStableCallback(vm.handleRemoveComposerReferenceAttachment)+ const handleClearComposerAttachments = useStableCallback(vm.handleClearComposerAttachments)const handleSendAgentMessage = useStableCallback(vm.handleSendAgentMessage)const handleRetryFailedAgentSend = useStableCallback(vm.handleRetryFailedAgentSend)const handleRecoverFailedAgentSend = useStableCallback(vm.handleRecoverFailedAgentSend)@@ -58,6 +59,7 @@ export function useAgentChatActionsValue(vm: AppVm): AgentChatActionsContextValuhandleRemoveComposerImageAttachment,handleAddComposerReferenceAttachments,handleRemoveComposerReferenceAttachment,+ handleClearComposerAttachments,handleSendAgentMessage,handleRetryFailedAgentSend,handleRecoverFailedAgentSend,@@ -79,6 +81,7 @@ export function useAgentChatActionsValue(vm: AppVm): AgentChatActionsContextValuhandleRemoveComposerImageAttachment,handleAddComposerReferenceAttachments,handleRemoveComposerReferenceAttachment,+ handleClearComposerAttachments,handleSendAgentMessage,handleRetryFailedAgentSend,handleRecoverFailedAgentSend,diff --git a/desktop-app/ui/src/hooks/useAppController.ts b/desktop-app/ui/src/hooks/useAppController.tsindex 57b371f67..1eecf6e4f 100644--- a/desktop-app/ui/src/hooks/useAppController.ts+++ b/desktop-app/ui/src/hooks/useAppController.ts@@ -1498,6 +1498,7 @@ export function useAppController() {unreadNotificationCount: notif.unreadNotificationCount,toasts,pushToast,+ dismissToast: toastCtrl.dismissToast,markNotificationsRead: notif.markNotificationsRead,clearNotifications: notif.clearNotifications,removeNotification: notif.removeNotification,@@ -1565,6 +1566,7 @@ export function useAppController() {handleRemoveComposerImageAttachment: chat.handleRemoveComposerImageAttachment,handleAddComposerReferenceAttachments: chat.handleAddComposerReferenceAttachments,handleRemoveComposerReferenceAttachment: chat.handleRemoveComposerReferenceAttachment,+ handleClearComposerAttachments: chat.handleClearComposerAttachments,cancelTask: chat.cancelTask,// MCP Serverdiff --git a/desktop-app/ui/src/lib/retainedSendStore.ts b/desktop-app/ui/src/lib/retainedSendStore.tsindex e12d7d4ea..84b438060 100644--- a/desktop-app/ui/src/lib/retainedSendStore.ts+++ b/desktop-app/ui/src/lib/retainedSendStore.ts@@ -83,6 +83,11 @@ export function createRetainedSendStore(changed: () => void) {return latest}+ /** All snapshots currently held for a task (copy; caller decides what next). */+ function getRetainedSendsForTask(taskId: string): RetainedSendSnapshot[] {+ return [...snapshots.values()].filter(snapshot => snapshot.taskId === taskId)+ }+/** Attaches the task id once the async task is accepted (still retained). */function attachTaskIdToRetainedSend(agentRef: string,@@ -204,6 +209,7 @@ export function createRetainedSendStore(changed: () => void) {retainSendSnapshot,getRetainedSendSnapshot,getLatestRetainedSendSnapshotForChat,+ getRetainedSendsForTask,attachTaskIdToRetainedSend,releaseRetainedSend,releaseRetainedSendsForTask,diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.cssindex 661811eba..4f76b41ce 100644--- a/desktop-app/ui/src/styles.css+++ b/desktop-app/ui/src/styles.css@@ -7996,6 +7996,42 @@ h3 {scrollbar-width: thin;}+.composer-attachments-count {+ flex: 0 0 auto;+ align-self: center;+ color: var(--text-dim);+ font-size: var(--font-size-xs);+ line-height: 1.2;+ white-space: nowrap;+}++.composer-attachments-clear {+ appearance: none;+ flex: 0 0 auto;+ align-self: center;+ height: 24px;+ border: none;+ border-radius: var(--radius-sm);+ background: transparent;+ color: var(--text-dim);+ font: inherit;+ font-size: var(--font-size-xs);+ line-height: 1;+ padding: 0 var(--space-1);+ cursor: pointer;+ white-space: nowrap;+}++.composer-attachments-clear:hover {+ color: var(--danger);+ background: rgba(var(--danger-rgb), 0.08);+}++.composer-attachments-clear:focus-visible {+ outline: 2px solid rgba(var(--focus-rgb), 0.56);+ outline-offset: 1px;+}+.composer-attachment-chip {display: inline-flex;align-items: center;@@ -10561,6 +10597,37 @@ button.page-breadcrumb-link--plain-action:hover:enabled {margin-top: 1px;}+.toast-body {+ flex: 1 1 auto;+ min-width: 0;+}++.toast-action {+ appearance: none;+ flex: 0 0 auto;+ align-self: center;+ border: 1px solid rgba(var(--edge-rgb), 0.3);+ border-radius: var(--radius-control);+ background: transparent;+ color: var(--text-dim);+ font: inherit;+ font-size: var(--font-size-xs);+ line-height: 1;+ padding: var(--space-1) var(--space-1-5);+ cursor: pointer;+ white-space: nowrap;+}++.toast-action:hover {+ border-color: rgba(var(--danger-rgb), 0.5);+ color: var(--danger);+}++.toast-action:focus-visible {+ outline: 2px solid rgba(var(--focus-rgb), 0.56);+ outline-offset: 1px;+}+.toast.tone-success {border-color: rgba(var(--success-rgb), 0.5);}diff --git a/desktop-app/ui/src/uiTypes.ts b/desktop-app/ui/src/uiTypes.tsindex 0cca0a293..1d774be1a 100644--- a/desktop-app/ui/src/uiTypes.ts+++ b/desktop-app/ui/src/uiTypes.ts@@ -105,6 +105,13 @@ export type ToastMessage = {tone: Tonetext: stringdurationMs?: number+ /** Optional inline action (e.g. "Discard all" after a kept-payload event). */+ action?: ToastMessageAction+}++export type ToastMessageAction = {+ label: string+ onAction: () => void}export type AppNotificationKind =