Add turn navigation, checkpoint diffs and confirmed rewind

This commit is contained in:
Callum Alpass committed 2026-11-02 20:42:55 +11:00
1 parent 43347d1d58
commit 7eb976f7ac
16 files changed
+634 -39

No files matched your search

+22 -5
View File
@@ -39,6 +39,7 @@ import { attachTerminal } from "./terminalAttach.ts";
import { copyText, desktopNotify, ring } from "./terminalOut.ts";
import { colors } from "./theme.ts";
import { ThreadList } from "./ThreadList.tsx";
import { useTurns } from "./useTurns.ts";
import { ThreadView } from "./ThreadView.tsx";
/**
@@ -171,6 +172,8 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
const threadRow = allRows.find((row) => row.thread.id === threadId);
const threadShell = threadRow?.thread ?? shell.snapshot?.threads.find((thread) => thread.id === threadId) ?? (threadId ? familyShells.get(threadId) : undefined);
const composerKey: string = draft ? DRAFT_KEY : (threadId ?? "");
const activeComposerKey = useRef(composerKey);
activeComposerKey.current = composerKey;
// Pin the initial selection to a thread, or it would follow whatever sorts first.
useEffect(() => {
if (selectedId === undefined && rows[0]) setSelectedId(rows[0].thread.id);
@@ -213,10 +216,10 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
const timeline = useMemo(() => {
if (!thread?.projection || !watchedId) return null;
const previous = previousTimeline.current?.id === watchedId ? previousTimeline.current.timeline : null;
const next = buildTimeline(thread.projection, { expandAll }, previous);
const next = buildTimeline(thread.projection, { expandAll, historyComplete: !thread.history.hasMore }, previous);
previousTimeline.current = { id: watchedId, timeline: next };
return next;
}, [thread?.projection, watchedId, expandAll]);
}, [thread?.projection, thread?.history.hasMore, watchedId, expandAll]);
const current = watchedId === threadId ? timeline : null;
const pendingApproval = current?.pending.approvals[0];
const pendingInput = current?.pending.userInputs[0];
@@ -360,7 +363,7 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
const cwd = vcsCwd;
setDiff({ cwd, path, status: "loading" });
session.workingTreeDiff(cwd, path ?? undefined, config.diffIgnoreWhitespace).then(
(source) => setDiff((value) => (value?.cwd === cwd && value.path === path ? { cwd, path, status: "ready", patch: source?.diff ?? "", truncated: source?.truncated ?? false } : value)),
(source) => setDiff((value) => (value?.cwd === cwd && value.path === path ? { cwd, path, status: "ready", patch: source?.diff ?? "", ...(source ? { source: { cwd, sourceKind: source.kind, baseRef: source.baseRef, headRef: source.headRef } } : {}), truncated: source?.truncated ?? false } : value)),
(error) => setDiff((value) => (value?.cwd === cwd && value.path === path ? { cwd, path, status: "error", error: messageOf(error) } : value)),
);
};
@@ -920,8 +923,18 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
const scrollPage = (direction: 1 | -1) => scrollRef.current?.scrollBy(direction * Math.max(1, height - 10));
const turns = useTurns({ session, threadId, projection, timeline: current, config: providerConfig, cwd: vcsCwd, ignoreWhitespace: config.diffIgnoreWhitespace, enabled: draft === null, diff, setDiff, scrollRef, confirm, say,
showConversation: () => { setMode("nav"); setDetailsPref((value) => width < MIN_CONVERSATION_WIDTH + DETAILS_WIDTH ? false : value); },
restorePrompt: (id, text) => {
const previous = id === activeComposerKey.current ? composerRef.current?.plainText ?? "" : drafts.current.get(id) ?? "";
const next = text ? previous ? `${previous}\n\n${text}` : text : previous;
drafts.current.set(id, next);
if (id === activeComposerKey.current) { composerRef.current?.setText(next); setMode("input"); }
},
});
// The command palette: everything the keys do, plus what the details panel offers.
const commands: (PaletteCommand & { readonly run: () => void })[] = [];
const commands: (PaletteCommand & { readonly run: () => void })[] = [...turns.commands];
const command = (id: string, label: string, action: () => void, extra: Omit<PaletteCommand, "id" | "title"> = {}) => commands.push({ id, title: label, run: action, ...extra });
if (pendingApproval) {
command("approve", "Approve request", () => respond("accept"), { shortcut: "y" });
@@ -1176,6 +1189,7 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
return setMode("nav");
}
}
if (mode === "nav" && turns.onKey(key)) return key.preventDefault();
switch (key.name) {
case "q":
if (diff) return setDiff(null);
@@ -1351,7 +1365,7 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
}}
/>
) : diff ? (
<DiffView diff={diff} scrollRef={scrollRef} />
<DiffView diff={diff} scrollRef={scrollRef} selected={turns.diffContext.selected} expanded={turns.diffContext.expanded} />
) : draft ? (
<DraftView lines={draftLines} />
) : threadId && detailsInPlace ? (
@@ -1365,6 +1379,9 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
title={title}
detail={threadShell?.branch ?? ""}
timeline={current}
selectedMessageId={turns.selectedMessageId}
session={session}
streamCommandOutput={live && providerConfig?.environment.capabilities.commandOutputStreaming === true}
history={watchedId === threadId ? (thread?.history ?? null) : null}
loading={watchedId !== threadId || thread?.status === "loading"}
error={thread?.error}