Skip to content
Closed
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
25 changes: 25 additions & 0 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ import {
} from "../composerDraftStore";
import {
appendTerminalContextsToPrompt,
deriveDisplayedUserMessageState,
formatTerminalContextLabel,
type TerminalContextDraft,
type TerminalContextSelection,
Expand Down Expand Up @@ -3490,6 +3491,29 @@ export default function ChatView(props: ChatViewProps) {
void onRevertToTurnCountRef.current(targetTurnCount);
}, []);

const onEditUserMessage = useCallback(
async (messageId: MessageId, text: string) => {
const targetTurnCount = revertTurnCountRef.current.get(messageId);
if (typeof targetTurnCount !== "number") {
return;
}

const displayedMessage = deriveDisplayedUserMessageState(text);
const draftText = displayedMessage.visibleText || text;
clearComposerDraftContent(composerDraftTarget);
setComposerDraftPrompt(composerDraftTarget, draftText);
Comment thread
macroscopeapp[bot] marked this conversation as resolved.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High components/ChatView.tsx:3504

onEditUserMessage clears the composer draft and replaces it with the edited message text before onRevertToTurnCountRef.current runs. If the revert bails out (user cancels confirmation dialog, isRevertingCheckpoint already true, environment unavailable, or turn running), the original composer content (prompt, images, terminal contexts) is already destroyed and cannot be recovered.

🤖 Copy this AI Prompt to have your agent fix this:
In file apps/web/src/components/ChatView.tsx around line 3504:

`onEditUserMessage` clears the composer draft and replaces it with the edited message text before `onRevertToTurnCountRef.current` runs. If the revert bails out (user cancels confirmation dialog, `isRevertingCheckpoint` already true, environment unavailable, or turn running), the original composer content (prompt, images, terminal contexts) is already destroyed and cannot be recovered.

Evidence trail:
ChatView.tsx lines 3494-3516: onEditUserMessage clears composer then awaits revert. ChatView.tsx lines 2552-2605: onRevertToTurnCount has multiple early-return bail-out paths (isRevertingCheckpoint, environment unavailable, phase running, user cancels dialog). composerDraftStore.ts lines 2863-2890: clearComposerContent destroys prompt, images, terminalContexts, persistedAttachments.

promptRef.current = draftText;
composerRef.current?.resetCursorState({
cursor: draftText.length,
prompt: draftText,
detectTrigger: true,
});
composerRef.current?.focusAtEnd();
await onRevertToTurnCountRef.current(targetTurnCount);
},
[clearComposerDraftContent, composerDraftTarget, composerRef, setComposerDraftPrompt],
);

// Empty state: no active thread
if (!activeThread) {
return <NoActiveThreadState />;
Expand Down Expand Up @@ -3568,6 +3592,7 @@ export default function ChatView(props: ChatViewProps) {
onOpenTurnDiff={onOpenTurnDiff}
revertTurnCountByUserMessageId={revertTurnCountByUserMessageId}
onRevertUserMessage={onRevertUserMessage}
onEditUserMessage={onEditUserMessage}
isRevertingCheckpoint={isRevertingCheckpoint}
onImageExpand={onExpandTimelineImage}
markdownCwd={gitCwd ?? undefined}
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/chat/MessagesTimeline.browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function buildProps() {
onOpenTurnDiff: vi.fn(),
revertTurnCountByUserMessageId: new Map(),
onRevertUserMessage: vi.fn(),
onEditUserMessage: vi.fn(),
isRevertingCheckpoint: false,
onImageExpand: vi.fn(),
activeThreadEnvironmentId: EnvironmentId.make("environment-local"),
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/chat/MessagesTimeline.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function buildProps() {
onOpenTurnDiff: () => {},
revertTurnCountByUserMessageId: new Map(),
onRevertUserMessage: () => {},
onEditUserMessage: () => {},
isRevertingCheckpoint: false,
onImageExpand: () => {},
activeThreadEnvironmentId: ACTIVE_THREAD_ENVIRONMENT_ID,
Expand Down
37 changes: 27 additions & 10 deletions apps/web/src/components/chat/MessagesTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ interface TimelineRowSharedState {
workspaceRoot: string | undefined;
activeThreadEnvironmentId: EnvironmentId;
onRevertUserMessage: (messageId: MessageId) => void;
onEditUserMessage: (messageId: MessageId, text: string) => void;
onImageExpand: (preview: ExpandedImagePreview) => void;
onOpenTurnDiff: (turnId: TurnId, filePath?: string) => void;
}
Expand All @@ -106,6 +107,7 @@ interface MessagesTimelineProps {
onOpenTurnDiff: (turnId: TurnId, filePath?: string) => void;
revertTurnCountByUserMessageId: Map<MessageId, number>;
onRevertUserMessage: (messageId: MessageId) => void;
onEditUserMessage: (messageId: MessageId, text: string) => void;
isRevertingCheckpoint: boolean;
onImageExpand: (preview: ExpandedImagePreview) => void;
activeThreadEnvironmentId: EnvironmentId;
Expand Down Expand Up @@ -134,6 +136,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
onOpenTurnDiff,
revertTurnCountByUserMessageId,
onRevertUserMessage,
onEditUserMessage,
isRevertingCheckpoint,
onImageExpand,
activeThreadEnvironmentId,
Expand Down Expand Up @@ -205,6 +208,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
workspaceRoot,
activeThreadEnvironmentId,
onRevertUserMessage,
onEditUserMessage,
onImageExpand,
onOpenTurnDiff,
}),
Expand All @@ -221,6 +225,7 @@ export const MessagesTimeline = memo(function MessagesTimeline({
workspaceRoot,
activeThreadEnvironmentId,
onRevertUserMessage,
onEditUserMessage,
onImageExpand,
onOpenTurnDiff,
],
Expand Down Expand Up @@ -355,16 +360,28 @@ function TimelineRowContent({ row }: { row: TimelineRow }) {
<MessageCopyButton text={displayedUserMessage.copyText} />
)}
{canRevertAgentWork && (
<Button
type="button"
size="xs"
variant="outline"
disabled={ctx.isRevertingCheckpoint || ctx.isWorking}
onClick={() => ctx.onRevertUserMessage(row.message.id)}
title="Revert to this message"
>
<Undo2Icon className="size-3" />
</Button>
<>
<Button
type="button"
size="xs"
variant="outline"
disabled={ctx.isRevertingCheckpoint || ctx.isWorking}
onClick={() => ctx.onEditUserMessage(row.message.id, row.message.text)}
title="Edit message and revert to this point"
>
<SquarePenIcon className="size-3" />
</Button>
<Button
type="button"
size="xs"
variant="outline"
disabled={ctx.isRevertingCheckpoint || ctx.isWorking}
onClick={() => ctx.onRevertUserMessage(row.message.id)}
title="Revert to this message"
>
<Undo2Icon className="size-3" />
</Button>
</>
)}
</div>
<p className="text-right text-xs text-muted-foreground/50">
Expand Down
Loading