From bcfa0cffe7eec4016c0b7dcccb0899acc848abd3 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 10 Nov 2026 02:39:24 -0800 Subject: [PATCH] =?UTF-8?q?feat(native-chat):=20DS-39=20rewind=20polish=20?= =?UTF-8?q?=E2=80=94=20file=20list,=20files-only=20restore,=20focus=20ring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Rewind confirm lists the changed files under the choice (three, then Show N more); the host preview returns up to 200 sorted paths. - 'Restore files to here' in a user message's menu restores files without rewinding the chat (Claude Code's code-only rewind), with Undo. - Rewind hover action uses the --focus-ring outline token. - Disabled unchecked checkboxes keep a full-strength --input border on a muted fill. - Fixture: NativeChatRewindConfirm:restoreFilesOnly; restoreFiles shows six paths. --- .../checkpoints/agent-session-checkpoints.ts | 4 + ...uctured-agent-session-rewind-files.test.ts | 7 +- .../components/confirmation-dialog-context.ts | 3 + .../components/confirmation-dialog-option.tsx | 46 +++++- .../components/confirmation-dialog.test.tsx | 15 ++ .../src/components/confirmation-dialog.tsx | 12 +- .../actions/NativeChatRewindAction.tsx | 2 +- .../NativeChatRewindConfirm.fixture.tsx | 45 +++++- .../actions/native-chat-restore-files-only.ts | 63 ++++++++ .../actions/native-chat-rewind-files.ts | 138 ++++++++++++++---- .../use-native-chat-rewind-files.test.tsx | 46 ++++++ .../actions/use-native-chat-rewind-host.ts | 2 + .../actions/use-native-chat-rewind.ts | 13 +- .../actions/NativeChatContextMenuItems.tsx | 23 ++- src/renderer/src/components/ui/checkbox.tsx | 2 +- .../src/i18n/en-runtime-required.json | 6 + src/renderer/src/i18n/locales/en.json | 23 ++- .../lifecycle/agent-session-checkpoint.ts | 4 + 18 files changed, 414 insertions(+), 40 deletions(-) create mode 100644 src/renderer/src/components/native-chat/messages/actions/native-chat-restore-files-only.ts diff --git a/src/main/native-chat/agent-session-wire/checkpoints/agent-session-checkpoints.ts b/src/main/native-chat/agent-session-wire/checkpoints/agent-session-checkpoints.ts index 23b48dd9af6..c372aa82751 100644 --- a/src/main/native-chat/agent-session-wire/checkpoints/agent-session-checkpoints.ts +++ b/src/main/native-chat/agent-session-wire/checkpoints/agent-session-checkpoints.ts @@ -5,6 +5,7 @@ import { createHash, randomBytes } from 'node:crypto' import type { AgentSessionRecord } from '../../../../shared/agent-session/lifecycle/agent-session-record' import { + AGENT_SESSION_CHECKPOINT_PREVIEW_PATHS, AGENT_SESSION_CHECKPOINT_UNDO_ID, agentSessionCheckpointPartialMessage, agentSessionCheckpointRefusalMessage, @@ -157,6 +158,9 @@ export function createAgentSessionCheckpoints(deps: AgentSessionCheckpointsDeps) return { available: true, changedFiles: changes.length, + paths: [...new Set(changes.map((change) => change.path))] + .sort() + .slice(0, AGENT_SESSION_CHECKPOINT_PREVIEW_PATHS), headMoved, createdAt: found.checkpoint.createdAt, busy: diff --git a/src/main/native-chat/agent-session-wire/host/testing/structured-agent-session-rewind-files.test.ts b/src/main/native-chat/agent-session-wire/host/testing/structured-agent-session-rewind-files.test.ts index 98586ac9d60..135597e3748 100644 --- a/src/main/native-chat/agent-session-wire/host/testing/structured-agent-session-rewind-files.test.ts +++ b/src/main/native-chat/agent-session-wire/host/testing/structured-agent-session-rewind-files.test.ts @@ -180,7 +180,12 @@ describe('rewind with file restore', () => { expect(await git('stash', 'list')).toBe('') const preview = await hostAgentSessionCheckpoints(host).preview(HOST_TEST_SESSION, second) - expect(preview).toMatchObject({ available: true, changedFiles: 3, headMoved: false }) + expect(preview).toMatchObject({ + available: true, + changedFiles: 3, + paths: ['app.ts', 'feature.ts', 'refactor/util.ts'], + headMoved: false + }) const restored = await hostAgentSessionCheckpoints(host).restore(HOST_TEST_SESSION, second) expect(restored.changedFiles).toBe(3) expect(await read('app.ts')).toBe('v1\n') diff --git a/src/renderer/src/components/confirmation-dialog-context.ts b/src/renderer/src/components/confirmation-dialog-context.ts index fba1252b34d..5f57d0832e6 100644 --- a/src/renderer/src/components/confirmation-dialog-context.ts +++ b/src/renderer/src/components/confirmation-dialog-context.ts @@ -41,6 +41,9 @@ export type ConfirmationDialogOptions = { disabled?: boolean onConfirmed: (checked: boolean) => void } + /** Names what the action touches (file paths, say), under the option or the description; + * the first three show, the rest behind "Show N more". `total` may exceed `items`. */ + itemList?: { label: string; items: string[]; total: number } /** Runs when the cancel button settles the prompt, unlike Esc, an outside press or an abort. */ onCancelClicked?: () => void /** Renders text inputs; Enter in one confirms. `onConfirmed` gets their values, only on confirm. */ diff --git a/src/renderer/src/components/confirmation-dialog-option.tsx b/src/renderer/src/components/confirmation-dialog-option.tsx index 744f5bdf55e..c6d9670a4a1 100644 --- a/src/renderer/src/components/confirmation-dialog-option.tsx +++ b/src/renderer/src/components/confirmation-dialog-option.tsx @@ -1,4 +1,5 @@ -import React from 'react' +import React, { useState } from 'react' +import { useTranslate } from '@/i18n/use-translate' import { Checkbox } from '@/components/ui/checkbox' import { Label } from '@/components/ui/label' import type { ConfirmationDialogOptions } from '@/components/confirmation-dialog-context' @@ -44,3 +45,46 @@ export function ConfirmationDialogOption({ ) } + +const COLLAPSED_ITEMS = 3 + +/** The paths (or other names) an action touches: three, then the rest on request. */ +export function ConfirmationDialogItemList({ + list, + indented +}: { + list: NonNullable + /** Lines up under an option's label. */ + indented: boolean +}): React.JSX.Element { + const t = useTranslate() + const [expanded, setExpanded] = useState(false) + const shown = expanded ? list.items : list.items.slice(0, COLLAPSED_ITEMS) + const hidden = list.total - shown.length + return ( +
+
    + {shown.map((item) => ( +
  • + {item} +
  • + ))} +
+ {list.total > COLLAPSED_ITEMS ? ( + + ) : null} +
+ ) +} diff --git a/src/renderer/src/components/confirmation-dialog.test.tsx b/src/renderer/src/components/confirmation-dialog.test.tsx index 09e1c694f9c..c6545e5b89e 100644 --- a/src/renderer/src/components/confirmation-dialog.test.tsx +++ b/src/renderer/src/components/confirmation-dialog.test.tsx @@ -134,6 +134,21 @@ describe('ConfirmationDialogProvider', () => { await waitFor(() => expect(onSettled).toHaveBeenCalledWith(true)) }) + it('shows three listed items, then the rest on request', async () => { + renderDialog({ + title: 'Rewind to here?', + itemList: { label: 'Changed files', items: ['a', 'b', 'c', 'd', 'e'], total: 7 } + }) + await userEvent.click(screen.getByRole('button', { name: 'ask' })) + const list = await screen.findByRole('list', { name: 'Changed files' }) + expect(list.querySelectorAll('li')).toHaveLength(3) + await userEvent.click(screen.getByRole('button', { name: 'Show 4 more' })) + expect(list.querySelectorAll('li')).toHaveLength(5) + expect(screen.getByRole('button', { name: 'Show fewer' }).getAttribute('aria-expanded')).toBe( + 'true' + ) + }) + it('never saves the preference when the user backs out', async () => { const onConfirmed = vi.fn() const { onSettled } = renderDialog({ diff --git a/src/renderer/src/components/confirmation-dialog.tsx b/src/renderer/src/components/confirmation-dialog.tsx index 1404855494a..45d4fe4a146 100644 --- a/src/renderer/src/components/confirmation-dialog.tsx +++ b/src/renderer/src/components/confirmation-dialog.tsx @@ -20,7 +20,10 @@ import { import { useAppStore } from '@/store' import { useTranslate } from '@/i18n/use-translate' import { cn } from '@/lib/utils' -import { ConfirmationDialogOption } from '@/components/confirmation-dialog-option' +import { + ConfirmationDialogItemList, + ConfirmationDialogOption +} from '@/components/confirmation-dialog-option' type ConfirmationDialogRequest = { id: number @@ -197,6 +200,13 @@ export function ConfirmationDialogProvider({ onCheckedChange={setOptionChecked} /> ) : null} + {displayedRequest?.options.itemList ? ( + + ) : null} {displayedRequest?.options.fields ? (
{displayedRequest.options.fields.inputs.map((field) => ( diff --git a/src/renderer/src/components/native-chat/messages/actions/NativeChatRewindAction.tsx b/src/renderer/src/components/native-chat/messages/actions/NativeChatRewindAction.tsx index a3092677604..26900727d1b 100644 --- a/src/renderer/src/components/native-chat/messages/actions/NativeChatRewindAction.tsx +++ b/src/renderer/src/components/native-chat/messages/actions/NativeChatRewindAction.tsx @@ -19,7 +19,7 @@ export function NativeChatRewindAction({