mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 19:07:41 +00:00
feat(native-chat): DS-39 rewind polish — file list, files-only restore, focus ring
- 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.
This commit is contained in:
@@ -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:
|
||||
|
||||
+6
-1
@@ -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')
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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({
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
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<ConfirmationDialogOptions['itemList']>
|
||||
/** 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 (
|
||||
<div className={indented ? 'space-y-1 pl-6' : 'space-y-1'}>
|
||||
<ul aria-label={list.label} className="space-y-0.5 font-mono text-xs text-muted-foreground">
|
||||
{shown.map((item) => (
|
||||
<li key={item} className="truncate" title={item}>
|
||||
{item}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{list.total > COLLAPSED_ITEMS ? (
|
||||
<button
|
||||
type="button"
|
||||
className="rounded-sm text-xs text-muted-foreground underline-offset-2 hover:text-foreground hover:underline focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-focus-ring"
|
||||
aria-expanded={expanded}
|
||||
onClick={() => setExpanded((value) => !value)}
|
||||
>
|
||||
{expanded
|
||||
? t('components.confirmation.itemList.showFewer', 'Show fewer')
|
||||
: t('components.confirmation.itemList.showMore', 'Show {{count}} more', {
|
||||
count: hidden,
|
||||
defaultValue_one: 'Show {{count}} more'
|
||||
})}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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 ? (
|
||||
<ConfirmationDialogItemList
|
||||
key={activeRequest?.id}
|
||||
indented={Boolean(displayedRequest.options.option)}
|
||||
list={displayedRequest.options.itemList}
|
||||
/>
|
||||
) : null}
|
||||
{displayedRequest?.options.fields ? (
|
||||
<div className="space-y-3">
|
||||
{displayedRequest.options.fields.inputs.map((field) => (
|
||||
|
||||
@@ -19,7 +19,7 @@ export function NativeChatRewindAction({
|
||||
<TooltipTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
className="flex size-6 shrink-0 items-center justify-center rounded-md text-chat-foreground-faint transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring aria-disabled:opacity-50"
|
||||
className="flex size-6 shrink-0 items-center justify-center rounded-md text-chat-foreground-faint transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-focus-ring aria-disabled:opacity-50"
|
||||
aria-label={label}
|
||||
aria-description={rewind.disabledReason ?? undefined}
|
||||
aria-disabled={Boolean(rewind.disabledReason)}
|
||||
|
||||
+44
-1
@@ -4,6 +4,7 @@ import { ConfirmationDialogProvider } from '@/components/confirmation-dialog'
|
||||
import { useConfirmationDialog } from '@/components/confirmation-dialog-context'
|
||||
import type { AgentSessionCheckpointPreview } from '../../../../../../shared/agent-session/lifecycle/agent-session-checkpoint'
|
||||
import { nativeChatRewindPrompt } from './native-chat-rewind-files'
|
||||
import { restoreNativeChatFilesOnly } from './native-chat-restore-files-only'
|
||||
|
||||
function OpenRewindPrompt({ preview }: { preview: AgentSessionCheckpointPreview | null }) {
|
||||
const confirm = useConfirmationDialog()
|
||||
@@ -37,7 +38,15 @@ function prompt(preview: AgentSessionCheckpointPreview | null) {
|
||||
/** A: a snapshot exists and files differ. */
|
||||
export const restoreFiles = prompt({
|
||||
available: true,
|
||||
changedFiles: 3,
|
||||
changedFiles: 6,
|
||||
paths: [
|
||||
'src/app.ts',
|
||||
'src/features/billing/invoice.ts',
|
||||
'src/features/billing/invoice.test.ts',
|
||||
'notes/todo.md',
|
||||
'package.json',
|
||||
'README.md'
|
||||
],
|
||||
headMoved: true,
|
||||
createdAt: 0
|
||||
})
|
||||
@@ -65,3 +74,37 @@ export const filesMatch = prompt({
|
||||
})
|
||||
/** C: no snapshot (older message, older host, or not git). */
|
||||
export const noSnapshot = prompt({ available: false, reason: 'none' })
|
||||
|
||||
/** Files only, from a user message's menu: the chat stays as it is. */
|
||||
export const restoreFilesOnly = defineFixture({
|
||||
width: 560,
|
||||
render: () => (
|
||||
<div className="h-[340px]">
|
||||
<ConfirmationDialogProvider>
|
||||
<OpenFilesOnlyPrompt />
|
||||
</ConfirmationDialogProvider>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
|
||||
function OpenFilesOnlyPrompt() {
|
||||
const confirm = useConfirmationDialog()
|
||||
useEffect(() => {
|
||||
void restoreNativeChatFilesOnly(
|
||||
{
|
||||
preview: async () => ({
|
||||
available: true,
|
||||
changedFiles: 2,
|
||||
paths: ['src/app.ts', 'notes/todo.md'],
|
||||
headMoved: false,
|
||||
createdAt: 0
|
||||
}),
|
||||
restore: async () => ({ changedFiles: 2, headMoved: false, undoId: '0-00000000' }),
|
||||
undo: async () => ({ changedFiles: 2, headMoved: false, undoId: '0-00000001' })
|
||||
},
|
||||
'item',
|
||||
confirm
|
||||
)
|
||||
}, [confirm])
|
||||
return null
|
||||
}
|
||||
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
import { toast } from 'sonner'
|
||||
import { translate } from '@/i18n/i18n'
|
||||
import type { ConfirmationDialogContextValue } from '@/components/confirmation-dialog-context'
|
||||
import {
|
||||
changedFilesList,
|
||||
checkedDetail,
|
||||
previewNativeChatRewindFiles,
|
||||
restoreNativeChatRewindFiles,
|
||||
type NativeChatCheckpointClient
|
||||
} from './native-chat-rewind-files'
|
||||
|
||||
/** "Restore files to here": puts the files back to how they were when this message was sent and
|
||||
* leaves the conversation as it is (Claude Code's code-only rewind). Undo is offered after. */
|
||||
export async function restoreNativeChatFilesOnly(
|
||||
client: NativeChatCheckpointClient,
|
||||
itemId: string,
|
||||
confirm: ConfirmationDialogContextValue
|
||||
): Promise<void> {
|
||||
const preview = await previewNativeChatRewindFiles(client, itemId)
|
||||
if (!preview?.available) {
|
||||
toast.message(
|
||||
translate(
|
||||
'components.native-chat.rewind.filesOnlyUnavailable',
|
||||
"Orca doesn't have the files saved for this message, so there is nothing to restore."
|
||||
)
|
||||
)
|
||||
return
|
||||
}
|
||||
if (preview.changedFiles === 0) {
|
||||
toast.message(
|
||||
translate(
|
||||
'components.native-chat.rewind.filesAlreadyMatch',
|
||||
'Files on disk already match this message.'
|
||||
)
|
||||
)
|
||||
return
|
||||
}
|
||||
if (preview.busy) {
|
||||
toast.message(
|
||||
translate(
|
||||
'components.native-chat.rewind.restoreFilesBusy',
|
||||
"Files can't be restored while the agent is working."
|
||||
)
|
||||
)
|
||||
return
|
||||
}
|
||||
const confirmed = await confirm({
|
||||
title: translate('components.native-chat.rewind.filesOnlyTitle', 'Restore files to here?'),
|
||||
description: `${translate(
|
||||
'components.native-chat.rewind.filesOnlyDescription',
|
||||
'The chat stays as it is.'
|
||||
)} ${checkedDetail(preview.headMoved)}`,
|
||||
...changedFilesList(preview),
|
||||
confirmLabel: translate('components.native-chat.rewind.filesOnlyConfirm', 'Restore files'),
|
||||
cancelLabel: translate('components.native-chat.rewind.cancel', 'Cancel'),
|
||||
confirmVariant: 'destructive',
|
||||
cancelVariant: 'ghost',
|
||||
initialFocus: 'cancel'
|
||||
})
|
||||
if (confirmed) {
|
||||
await restoreNativeChatRewindFiles(client, itemId, false)
|
||||
}
|
||||
}
|
||||
+108
-30
@@ -55,7 +55,7 @@ function filesLabel(count: number): string {
|
||||
)
|
||||
}
|
||||
|
||||
function checkedDetail(headMoved: boolean): string {
|
||||
export function checkedDetail(headMoved: boolean): string {
|
||||
const detail = translate(
|
||||
'components.native-chat.rewind.restoreFilesOutcome',
|
||||
'Files go back to how they were when this message was sent. Later changes are discarded. You can undo the file restore afterwards.'
|
||||
@@ -68,15 +68,31 @@ function checkedDetail(headMoved: boolean): string {
|
||||
: detail
|
||||
}
|
||||
|
||||
/** The changed paths, when the host named them (older hosts send only the count). */
|
||||
export function changedFilesList(
|
||||
preview: Extract<AgentSessionCheckpointPreview, { available: true }>
|
||||
): Pick<ConfirmationDialogOptions, 'itemList'> {
|
||||
return preview.paths && preview.paths.length > 0
|
||||
? {
|
||||
itemList: {
|
||||
label: translate('components.native-chat.rewind.changedFilesList', 'Changed files'),
|
||||
items: preview.paths,
|
||||
total: preview.changedFiles
|
||||
}
|
||||
}
|
||||
: {}
|
||||
}
|
||||
|
||||
/** The prompt's wording and files choice; `choose` hears whether to restore files, on confirm. */
|
||||
export function nativeChatRewindPrompt(
|
||||
preview: AgentSessionCheckpointPreview | null,
|
||||
choose: (restoreFiles: boolean) => void
|
||||
): Pick<ConfirmationDialogOptions, 'description' | 'option'> {
|
||||
): Pick<ConfirmationDialogOptions, 'description' | 'option' | 'itemList'> {
|
||||
if (preview?.available && preview.changedFiles > 0) {
|
||||
const busy = preview.busy === true
|
||||
return {
|
||||
description: BASE(),
|
||||
...changedFilesList(preview),
|
||||
option: {
|
||||
label: filesLabel(preview.changedFiles),
|
||||
detail: busy
|
||||
@@ -120,35 +136,90 @@ function restoredText(count: number): string {
|
||||
})
|
||||
}
|
||||
|
||||
function failureText(error: unknown): string {
|
||||
/** Why files weren't restored. `chatRewound` says whether the chat already went back (after a
|
||||
* rewind) or stays as it is (restoring files only). */
|
||||
export function failureText(error: unknown, chatRewound = true): string {
|
||||
const say = (rewound: () => string, only: () => string) => (chatRewound ? rewound() : only())
|
||||
switch (agentSessionCheckpointRefusalOf(error)) {
|
||||
case 'busy':
|
||||
return translate(
|
||||
'components.native-chat.rewind.chatRewoundBusy',
|
||||
"The chat was rewound, but files weren't restored because the agent is still working. Nothing on disk changed."
|
||||
return say(
|
||||
() =>
|
||||
translate(
|
||||
'components.native-chat.rewind.chatRewoundBusy',
|
||||
"The chat was rewound, but files weren't restored because the agent is still working. Nothing on disk changed."
|
||||
),
|
||||
() =>
|
||||
translate(
|
||||
'components.native-chat.rewind.filesOnlyBusy',
|
||||
"Files weren't restored because the agent is still working. Nothing on disk changed."
|
||||
)
|
||||
)
|
||||
case 'merge-conflicts':
|
||||
return translate(
|
||||
'components.native-chat.rewind.chatRewoundConflicts',
|
||||
"The chat was rewound, but files weren't restored because this workspace has unresolved merge conflicts. Nothing on disk changed."
|
||||
return say(
|
||||
() =>
|
||||
translate(
|
||||
'components.native-chat.rewind.chatRewoundConflicts',
|
||||
"The chat was rewound, but files weren't restored because this workspace has unresolved merge conflicts. Nothing on disk changed."
|
||||
),
|
||||
() =>
|
||||
translate(
|
||||
'components.native-chat.rewind.filesOnlyConflicts',
|
||||
"Files weren't restored because this workspace has unresolved merge conflicts. Nothing on disk changed."
|
||||
)
|
||||
)
|
||||
case 'blocked-path':
|
||||
return translate(
|
||||
'components.native-chat.rewind.chatRewoundBlocked',
|
||||
"The chat was rewound, but files weren't restored because a folder now sits where a restored file goes. Nothing on disk changed."
|
||||
return say(
|
||||
() =>
|
||||
translate(
|
||||
'components.native-chat.rewind.chatRewoundBlocked',
|
||||
"The chat was rewound, but files weren't restored because a folder now sits where a restored file goes. Nothing on disk changed."
|
||||
),
|
||||
() =>
|
||||
translate(
|
||||
'components.native-chat.rewind.filesOnlyBlocked',
|
||||
"Files weren't restored because a folder now sits where a restored file goes. Nothing on disk changed."
|
||||
)
|
||||
)
|
||||
case 'none':
|
||||
return translate(
|
||||
'components.native-chat.rewind.chatRewoundMissing',
|
||||
"The chat was rewound, but files weren't restored because Orca no longer has the files saved for this message. Nothing on disk changed."
|
||||
return say(
|
||||
() =>
|
||||
translate(
|
||||
'components.native-chat.rewind.chatRewoundMissing',
|
||||
"The chat was rewound, but files weren't restored because Orca no longer has the files saved for this message. Nothing on disk changed."
|
||||
),
|
||||
() =>
|
||||
translate(
|
||||
'components.native-chat.rewind.filesOnlyMissing',
|
||||
"Files weren't restored because Orca no longer has the files saved for this message. Nothing on disk changed."
|
||||
)
|
||||
)
|
||||
case 'partial':
|
||||
return say(
|
||||
() =>
|
||||
translate(
|
||||
'components.native-chat.rewind.chatRewoundPartial',
|
||||
"The chat was rewound, but some files couldn't be restored. Undo puts back the files Orca changed."
|
||||
),
|
||||
() =>
|
||||
translate(
|
||||
'components.native-chat.rewind.filesOnlyPartial',
|
||||
"Some files couldn't be restored. Undo puts back the files Orca changed."
|
||||
)
|
||||
)
|
||||
case 'not-a-repo':
|
||||
case 'unsafe-path':
|
||||
case null:
|
||||
return translate(
|
||||
'components.native-chat.rewind.chatRewoundFailed',
|
||||
"The chat was rewound, but some files couldn't be restored. Check Source Control before you continue."
|
||||
return say(
|
||||
() =>
|
||||
translate(
|
||||
'components.native-chat.rewind.chatRewoundFailed',
|
||||
"The chat was rewound, but some files couldn't be restored. Check Source Control before you continue."
|
||||
),
|
||||
() =>
|
||||
translate(
|
||||
'components.native-chat.rewind.filesOnlyFailed',
|
||||
"Some files couldn't be restored. Check Source Control before you continue."
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -156,7 +227,8 @@ function failureText(error: unknown): string {
|
||||
/** Restores after the chat rewound, then offers Undo for the files. */
|
||||
export async function restoreNativeChatRewindFiles(
|
||||
client: NativeChatCheckpointClient,
|
||||
itemId: string
|
||||
itemId: string,
|
||||
chatRewound = true
|
||||
): Promise<void> {
|
||||
let result: AgentSessionCheckpointRestoreResult
|
||||
try {
|
||||
@@ -165,37 +237,43 @@ export async function restoreNativeChatRewindFiles(
|
||||
console.warn('[native-chat-rewind] file restore failed', error)
|
||||
const undoId = agentSessionCheckpointPartialUndoIdOf(error)
|
||||
toast.error(
|
||||
failureText(error),
|
||||
undoId ? { action: undoAction(client, undoId), duration: Infinity } : undefined
|
||||
failureText(error, chatRewound),
|
||||
undoId ? { action: undoAction(client, undoId, chatRewound), duration: Infinity } : undefined
|
||||
)
|
||||
return
|
||||
}
|
||||
toast.success(restoredText(result.changedFiles), {
|
||||
action: undoAction(client, result.undoId)
|
||||
action: undoAction(client, result.undoId, chatRewound)
|
||||
})
|
||||
}
|
||||
|
||||
function undoAction(client: NativeChatCheckpointClient, undoId: string) {
|
||||
function undoAction(client: NativeChatCheckpointClient, undoId: string, chatRewound: boolean) {
|
||||
return {
|
||||
label: translate('components.native-chat.rewind.undoRestore', 'Undo'),
|
||||
onClick: () => void undoNativeChatRewindFiles(client, undoId)
|
||||
onClick: () => void undoNativeChatRewindFiles(client, undoId, chatRewound)
|
||||
}
|
||||
}
|
||||
|
||||
async function undoNativeChatRewindFiles(
|
||||
client: NativeChatCheckpointClient,
|
||||
undoId: string
|
||||
undoId: string,
|
||||
chatRewound: boolean
|
||||
): Promise<void> {
|
||||
try {
|
||||
await client.undo(undoId)
|
||||
toast.success(
|
||||
translate(
|
||||
'components.native-chat.rewind.undoneRestore',
|
||||
'Files are back to how they were before the rewind.'
|
||||
)
|
||||
chatRewound
|
||||
? translate(
|
||||
'components.native-chat.rewind.undoneRestore',
|
||||
'Files are back to how they were before the rewind.'
|
||||
)
|
||||
: translate(
|
||||
'components.native-chat.rewind.undoneFilesOnly',
|
||||
'Files are back to how they were before the restore.'
|
||||
)
|
||||
)
|
||||
} catch (error) {
|
||||
console.warn('[native-chat-rewind] file restore undo failed', error)
|
||||
toast.error(failureText(error))
|
||||
toast.error(failureText(error, chatRewound))
|
||||
}
|
||||
}
|
||||
|
||||
+46
@@ -175,4 +175,50 @@ describe('rewind with file restore', () => {
|
||||
expect(toast.error.mock.calls[0]?.[0]).toContain('unresolved merge conflicts')
|
||||
expect(toast.success).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('lists the changed files under the choice', async () => {
|
||||
const shown: ConfirmationDialogOptions[] = []
|
||||
const checkpoints = client({
|
||||
available: true,
|
||||
changedFiles: 5,
|
||||
paths: ['a.ts', 'b.ts', 'c.ts', 'd.ts', 'e.ts'],
|
||||
headMoved: false,
|
||||
createdAt: 1
|
||||
})
|
||||
const view = renderHook(() => useNativeChatRewind(input(checkpoints)))
|
||||
await act(() => view.result.current.request('user', answer(false, shown)))
|
||||
expect(shown[0]?.itemList).toEqual({
|
||||
label: 'Changed files',
|
||||
items: ['a.ts', 'b.ts', 'c.ts', 'd.ts', 'e.ts'],
|
||||
total: 5
|
||||
})
|
||||
})
|
||||
|
||||
it('restores files only, leaving the chat alone', async () => {
|
||||
const checkpoints = client({
|
||||
available: true,
|
||||
changedFiles: 2,
|
||||
paths: ['a', 'b'],
|
||||
headMoved: false,
|
||||
createdAt: 1
|
||||
})
|
||||
const props = input(checkpoints)
|
||||
const view = renderHook(() => useNativeChatRewind(props))
|
||||
const shown: ConfirmationDialogOptions[] = []
|
||||
await act(() => view.result.current.surface!.restoreFiles!('user', answer(true, shown)))
|
||||
expect(shown[0]).toMatchObject({
|
||||
title: 'Restore files to here?',
|
||||
confirmLabel: 'Restore files',
|
||||
initialFocus: 'cancel'
|
||||
})
|
||||
expect(shown[0]?.description).toContain('The chat stays as it is.')
|
||||
expect(props.send).not.toHaveBeenCalled()
|
||||
expect(checkpoints.restore).toHaveBeenCalledWith('user')
|
||||
expect(toast.success.mock.calls[0]?.[0]).toBe('Restored 3 files')
|
||||
checkpoints.restore.mockRejectedValueOnce(new Error('agent_session_checkpoint_merge-conflicts'))
|
||||
await act(() => view.result.current.surface!.restoreFiles!('user', answer(true, [])))
|
||||
expect(toast.error.mock.calls.at(-1)?.[0]).toBe(
|
||||
"Files weren't restored because this workspace has unresolved merge conflicts. Nothing on disk changed."
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
+2
@@ -9,6 +9,8 @@ export type NativeChatRewindSurface = {
|
||||
disabledReason: string | null
|
||||
eligibleItemIds?: ReadonlySet<string>
|
||||
request: (itemId: string, confirm: ConfirmationDialogContextValue) => Promise<void>
|
||||
/** Restore this message's files without rewinding the chat; absent without host checkpoints. */
|
||||
restoreFiles?: (itemId: string, confirm: ConfirmationDialogContextValue) => Promise<void>
|
||||
}
|
||||
|
||||
export type NativeChatRewindHost = {
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
restoreNativeChatRewindFiles,
|
||||
type NativeChatCheckpointClient
|
||||
} from './native-chat-rewind-files'
|
||||
import { restoreNativeChatFilesOnly } from './native-chat-restore-files-only'
|
||||
|
||||
export type RewindInput = Omit<
|
||||
AgentSessionRewindInput,
|
||||
@@ -99,9 +100,17 @@ export function useNativeChatRewind(input: RewindInput) {
|
||||
[checkpoints, sharedRequest]
|
||||
)
|
||||
const shared = rewind.surface
|
||||
const restoreFiles = useMemo(
|
||||
() =>
|
||||
checkpoints
|
||||
? (itemId: string, confirm: ConfirmationDialogContextValue) =>
|
||||
restoreNativeChatFilesOnly(checkpoints, itemId, confirm)
|
||||
: undefined,
|
||||
[checkpoints]
|
||||
)
|
||||
const surface = useMemo<NativeChatRewindSurface | undefined>(
|
||||
() => shared && { ...shared, request },
|
||||
[shared, request]
|
||||
() => shared && { ...shared, request, ...(restoreFiles ? { restoreFiles } : {}) },
|
||||
[shared, request, restoreFiles]
|
||||
)
|
||||
return { ...rewind, request, surface }
|
||||
}
|
||||
|
||||
+22
-1
@@ -1,4 +1,4 @@
|
||||
import { Copy, ExternalLink, FileText, Globe, Quote, Search, Undo2 } from 'lucide-react'
|
||||
import { Copy, ExternalLink, FileClock, FileText, Globe, Quote, Search, Undo2 } from 'lucide-react'
|
||||
import { DropdownMenuItem, DropdownMenuShortcut } from '@/components/ui/dropdown-menu'
|
||||
import { formatOptionalPrimaryShortcutLabel } from '@/hooks/useShortcutLabel'
|
||||
import { useAppStore } from '@/store'
|
||||
@@ -65,6 +65,9 @@ export function NativeChatContextMenuTargetItems({
|
||||
{rewindItemId && rewind ? (
|
||||
<NativeChatRewindMenuItem itemId={rewindItemId} rewind={rewind} />
|
||||
) : null}
|
||||
{rewindItemId && rewind?.restoreFiles ? (
|
||||
<NativeChatRestoreFilesMenuItem itemId={rewindItemId} restore={rewind.restoreFiles} />
|
||||
) : null}
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -111,6 +114,24 @@ function NativeChatRewindMenuItem({
|
||||
)
|
||||
}
|
||||
|
||||
/** Files only: the chat stays as it is (Claude Code's code-only rewind). */
|
||||
function NativeChatRestoreFilesMenuItem({
|
||||
itemId,
|
||||
restore
|
||||
}: {
|
||||
itemId: string
|
||||
restore: NonNullable<NativeChatRewindSurface['restoreFiles']>
|
||||
}): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
const confirm = useConfirmationDialog()
|
||||
return (
|
||||
<DropdownMenuItem onSelect={() => void restore(itemId, confirm)}>
|
||||
<FileClock />
|
||||
{t('components.native-chat.rewind.restoreFilesAction', 'Restore files to here')}
|
||||
</DropdownMenuItem>
|
||||
)
|
||||
}
|
||||
|
||||
function LinkActionIcon({ action }: { action: LinkAction }): React.JSX.Element {
|
||||
if (action.external === true) {
|
||||
return <ExternalLink />
|
||||
|
||||
@@ -16,7 +16,7 @@ function Checkbox({
|
||||
data-slot="checkbox"
|
||||
checked={checked}
|
||||
className={cn(
|
||||
'peer size-4 shrink-0 rounded-[4px] border border-input bg-background shadow-xs outline-none transition-shadow focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-focus-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground dark:data-[state=unchecked]:border-muted-foreground/60',
|
||||
'peer size-4 shrink-0 rounded-[4px] border border-input bg-background shadow-xs outline-none transition-shadow focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-focus-ring disabled:cursor-not-allowed disabled:opacity-50 disabled:data-[state=unchecked]:bg-muted disabled:data-[state=unchecked]:opacity-100 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground data-[state=indeterminate]:border-primary data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground dark:data-[state=unchecked]:border-muted-foreground/60',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
|
||||
+6
@@ -2131,6 +2131,12 @@
|
||||
"discarded_other": "Unsaved edits in {{count}} files will be discarded:"
|
||||
}
|
||||
}
|
||||
},
|
||||
"confirmation": {
|
||||
"itemList": {
|
||||
"showMore_one": "Show {{count}} more",
|
||||
"showMore_other": "Show {{count}} more"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dashboard": {
|
||||
|
||||
@@ -21891,7 +21891,21 @@
|
||||
"chatRewoundConflicts": "The chat was rewound, but files weren't restored because this workspace has unresolved merge conflicts. Nothing on disk changed.",
|
||||
"chatRewoundBlocked": "The chat was rewound, but files weren't restored because a folder now sits where a restored file goes. Nothing on disk changed.",
|
||||
"chatRewoundMissing": "The chat was rewound, but files weren't restored because Orca no longer has the files saved for this message. Nothing on disk changed.",
|
||||
"chatRewoundFailed": "The chat was rewound, but some files couldn't be restored. Check Source Control before you continue."
|
||||
"chatRewoundFailed": "The chat was rewound, but some files couldn't be restored. Check Source Control before you continue.",
|
||||
"filesOnlyUnavailable": "Orca doesn't have the files saved for this message, so there is nothing to restore.",
|
||||
"filesOnlyTitle": "Restore files to here?",
|
||||
"filesOnlyDescription": "The chat stays as it is.",
|
||||
"filesOnlyConfirm": "Restore files",
|
||||
"changedFilesList": "Changed files",
|
||||
"filesOnlyBusy": "Files weren't restored because the agent is still working. Nothing on disk changed.",
|
||||
"filesOnlyConflicts": "Files weren't restored because this workspace has unresolved merge conflicts. Nothing on disk changed.",
|
||||
"filesOnlyBlocked": "Files weren't restored because a folder now sits where a restored file goes. Nothing on disk changed.",
|
||||
"filesOnlyMissing": "Files weren't restored because Orca no longer has the files saved for this message. Nothing on disk changed.",
|
||||
"chatRewoundPartial": "The chat was rewound, but some files couldn't be restored. Undo puts back the files Orca changed.",
|
||||
"filesOnlyPartial": "Some files couldn't be restored. Undo puts back the files Orca changed.",
|
||||
"filesOnlyFailed": "Some files couldn't be restored. Check Source Control before you continue.",
|
||||
"undoneFilesOnly": "Files are back to how they were before the restore.",
|
||||
"restoreFilesAction": "Restore files to here"
|
||||
},
|
||||
"drop": {
|
||||
"messageTitle": "Drop to attach to this message",
|
||||
@@ -23231,6 +23245,13 @@
|
||||
"notFoundOnHostNothingSaved": "It was moved or deleted on the remote host. Nothing was saved on this computer.",
|
||||
"savedName": "Saved {{name}}",
|
||||
"noAppForType": "No app on this computer opens this file type. Reveal it to choose one."
|
||||
},
|
||||
"confirmation": {
|
||||
"itemList": {
|
||||
"showFewer": "Show fewer",
|
||||
"showMore_one": "Show {{count}} more",
|
||||
"showMore_other": "Show {{count}} more"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dashboardPopout": {
|
||||
|
||||
@@ -18,6 +18,8 @@ export type AgentSessionCheckpointPreview =
|
||||
/** Commits were made after the snapshot; they stay on the branch. */
|
||||
headMoved: boolean
|
||||
createdAt: number
|
||||
/** The changed paths, sorted, at most AGENT_SESSION_CHECKPOINT_PREVIEW_PATHS of them. */
|
||||
paths?: string[]
|
||||
/** An agent is working in this workspace now, so a restore would refuse. */
|
||||
busy?: boolean
|
||||
}
|
||||
@@ -29,6 +31,8 @@ export type AgentSessionCheckpointRestoreResult = {
|
||||
undoId: string
|
||||
}
|
||||
|
||||
export const AGENT_SESSION_CHECKPOINT_PREVIEW_PATHS = 200
|
||||
|
||||
/** Why a restore refused before changing any file. */
|
||||
export const AGENT_SESSION_CHECKPOINT_RESTORE_REFUSALS = [
|
||||
'none',
|
||||
|
||||
Reference in New Issue
Block a user