Skip to content

Commit 913c39e

Browse files
committed
fix(web): edit-from-here skips file revert when no files changed
- Show a single Revert button instead of the file-revert choices when no run after the message changed files. - Add runsChangedFiles to decide this. A run with no ready checkpoint (stopped, failed capture) still counts as possibly changed.
1 parent 1da41f9 commit 913c39e

4 files changed

Lines changed: 83 additions & 7 deletions

File tree

‎apps/web/src/components/chat/ChatOverlayHosts.tsx‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export function BranchRestoreConfirmHost(props: {
182182
interface PendingRevert {
183183
readonly turnCount: number;
184184
readonly messageId: MessageId;
185+
readonly hasFileChanges: boolean;
185186
}
186187

187188
const revertConfirmAtom = makeThreadOverlayAtom<PendingRevert>("revert-confirm");
@@ -212,15 +213,23 @@ export function RevertConfirmHost(props: {
212213
<AlertDialogTitle>Edit from here?</AlertDialogTitle>
213214
<AlertDialogDescription>
214215
Rewind chat to before this message. Your prompt and attachments return to the composer.
215-
“Revert files too” also undoes your own edits.
216+
{pending?.hasFileChanges === false
217+
? " No files have changed since."
218+
: " “Revert files too” also undoes your own edits."}
216219
</AlertDialogDescription>
217220
</AlertDialogHeader>
218221
<AlertDialogFooter>
219222
<AlertDialogClose render={<Button variant="outline" />}>Cancel</AlertDialogClose>
220-
<Button variant="destructive-outline" onClick={() => confirm(true)}>
221-
Revert files too
222-
</Button>
223-
<Button onClick={() => confirm(false)}>Revert and keep changes</Button>
223+
{pending?.hasFileChanges === false ? (
224+
<Button onClick={() => confirm(false)}>Revert</Button>
225+
) : (
226+
<>
227+
<Button variant="destructive-outline" onClick={() => confirm(true)}>
228+
Revert files too
229+
</Button>
230+
<Button onClick={() => confirm(false)}>Revert and keep changes</Button>
231+
</>
232+
)}
224233
</AlertDialogFooter>
225234
</AlertDialogPopup>
226235
</AlertDialog>

‎apps/web/src/components/chat/useTimelineRewind.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
squashAtomCommandFailure,
1919
} from "@t3tools/client-runtime/state/runtime";
2020
import { readLocalApi } from "../../localApi";
21-
import { findRevertCheckpoint } from "../../session-logic";
21+
import { findRevertCheckpoint, runsChangedFiles } from "../../session-logic";
2222
import { type ChatMessage } from "../../types";
2323
import { newThreadId } from "~/lib/utils";
2424
import { buildThreadRouteParams } from "../../threadRoutes";
@@ -125,7 +125,18 @@ export function useTimelineRewind(input: TimelineRewindInput) {
125125
return;
126126
}
127127
if (restoreFiles === undefined) {
128-
openRevertConfirm(routeThreadKey, { turnCount, messageId });
128+
openRevertConfirm(routeThreadKey, {
129+
turnCount,
130+
messageId,
131+
hasFileChanges: runsChangedFiles(
132+
serverProjection?.checkpoints ?? [],
133+
new Set(
134+
timelineMessages
135+
.slice(timelineMessages.indexOf(message))
136+
.flatMap((later) => (later.runId === null ? [] : [later.runId])),
137+
),
138+
),
139+
});
129140
return;
130141
}
131142

‎apps/web/src/session-logic.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
ThreadId,
1414
TurnItemId,
1515
type OrchestrationV2ProjectedTurnItem,
16+
type OrchestrationV2Checkpoint,
1617
type OrchestrationV2ExecutionNode,
1718
type OrchestrationV2RunAttempt,
1819
type OrchestrationV2TurnItem,
@@ -33,6 +34,7 @@ import {
3334
selectMessageImageResources,
3435
createMessageAttachmentPreviewProjector,
3536
providerErrorPresentation,
37+
runsChangedFiles,
3638
type TimelineEntry,
3739
workEntryIndicatesToolFailure,
3840
workEntryDisplayIndicatesToolFailure,
@@ -1787,3 +1789,42 @@ it("renders automatic completion as a work entry instead of a user bubble", () =
17871789
})[0]?.kind,
17881790
).toBe("message");
17891791
});
1792+
1793+
describe("runsChangedFiles", () => {
1794+
const checkpoint = (
1795+
run: string,
1796+
overrides: Partial<OrchestrationV2Checkpoint> = {},
1797+
): OrchestrationV2Checkpoint => ({
1798+
id: CheckpointId.make(`checkpoint-${run}`),
1799+
threadId: ThreadId.make("thread"),
1800+
scopeId: CheckpointScopeId.make("scope"),
1801+
runId: RunId.make(run),
1802+
nodeId: NodeId.make("node"),
1803+
parentCheckpointId: null,
1804+
ordinalWithinScope: 1,
1805+
appRunOrdinal: 1,
1806+
ref: "ref" as never,
1807+
status: "ready",
1808+
files: [],
1809+
capturedAt: DateTime.makeUnsafe("2026-06-20T00:00:00.000Z"),
1810+
...overrides,
1811+
});
1812+
const file = { path: "a.ts", kind: "modified", additions: 1, deletions: 0 };
1813+
const runs = (...ids: string[]) => ids.map((id) => RunId.make(id));
1814+
1815+
it("is false only when every run has a ready checkpoint with no files", () => {
1816+
expect(runsChangedFiles([checkpoint("a"), checkpoint("b")], runs("a", "b"))).toBe(false);
1817+
expect(
1818+
runsChangedFiles([checkpoint("a"), checkpoint("b", { files: [file] })], runs("a", "b")),
1819+
).toBe(true);
1820+
expect(
1821+
runsChangedFiles(
1822+
[checkpoint("a", { filesTotal: { count: 3, additions: 1, deletions: 1 } })],
1823+
runs("a"),
1824+
),
1825+
).toBe(true);
1826+
// A stopped run without a checkpoint, or a failed capture, may still have edited files.
1827+
expect(runsChangedFiles([checkpoint("a")], runs("a", "b"))).toBe(true);
1828+
expect(runsChangedFiles([checkpoint("a", { status: "error" })], runs("a"))).toBe(true);
1829+
});
1830+
});

‎apps/web/src/session-logic.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,21 @@ export function findRevertCheckpoint(
11211121
);
11221122
}
11231123

1124+
/** A run with no ready checkpoint (stopped, failed capture) may have touched files. */
1125+
export function runsChangedFiles(
1126+
checkpoints: ReadonlyArray<OrchestrationV2Checkpoint>,
1127+
runIds: Iterable<RunId>,
1128+
): boolean {
1129+
for (const runId of runIds) {
1130+
const checkpoint = checkpoints.findLast(
1131+
(candidate) => candidate.runId === runId && candidate.status === "ready",
1132+
);
1133+
if (checkpoint === undefined) return true;
1134+
if (checkpoint.files.length > 0 || (checkpoint.filesTotal?.count ?? 0) > 0) return true;
1135+
}
1136+
return false;
1137+
}
1138+
11241139
export function derivePhase(runtime: ThreadStructureRuntime | null): SessionPhase {
11251140
if (runtime === null) return "disconnected";
11261141
if (

0 commit comments

Comments
 (0)