Changed files under each reply, with a turn footer
This commit is contained in:
1 parent
b70099f23f
commit
49b04f9012
6 files changed
+215
-9
No files matched your search
+18
-1
@@ -1,11 +1,13 @@
|
|||||||
import { turnTargets, type TurnTarget } from "./turns.ts";
|
import { turnTargets, type TurnTarget } from "./turns.ts";
|
||||||
import type { OrchestrationV2ThreadProjection, RunAttemptId, RunId } from "@t3tools/contracts";
|
import type { OrchestrationV2ThreadProjection, RunAttemptId, RunId } from "@t3tools/contracts";
|
||||||
|
import * as DateTime from "effect/DateTime";
|
||||||
import {
|
import {
|
||||||
deriveRunlessWorkStartedAt,
|
deriveRunlessWorkStartedAt,
|
||||||
deriveThreadActivityRun,
|
deriveThreadActivityRun,
|
||||||
deriveThreadStructureRuntime,
|
deriveThreadStructureRuntime,
|
||||||
} from "@t3tools/client-runtime/state/thread-execution";
|
} from "@t3tools/client-runtime/state/thread-execution";
|
||||||
import { derivePendingThreadRequests, type PendingThreadRequests } from "@t3tools/client-runtime/state/thread-requests";
|
import { derivePendingThreadRequests, type PendingThreadRequests } from "@t3tools/client-runtime/state/thread-requests";
|
||||||
|
import { deriveThreadCheckpointSummaries } from "@t3tools/client-runtime/state/thread-checkpoints";
|
||||||
|
|
||||||
// The web app's own timeline derivation: tui3 shows the same rows, folds and labels.
|
// The web app's own timeline derivation: tui3 shows the same rows, folds and labels.
|
||||||
import {
|
import {
|
||||||
@@ -26,6 +28,12 @@ export type { MessagesTimelineRow } from "../../vendor/t3code/apps/web/src/compo
|
|||||||
export type { WorkLogEntry } from "../../vendor/t3code/apps/web/src/session-logic.ts";
|
export type { WorkLogEntry } from "../../vendor/t3code/apps/web/src/session-logic.ts";
|
||||||
export { liveWorkEntryLabel, workEntryDisplayLabel } from "../../vendor/t3code/apps/web/src/components/chat/MessagesTimeline.logic.ts";
|
export { liveWorkEntryLabel, workEntryDisplayLabel } from "../../vendor/t3code/apps/web/src/components/chat/MessagesTimeline.logic.ts";
|
||||||
|
|
||||||
|
/** What a turn footer needs of its run: the model, and how long it ran. */
|
||||||
|
export interface RunMeta {
|
||||||
|
readonly model: string;
|
||||||
|
readonly durationMs: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
export interface Timeline {
|
export interface Timeline {
|
||||||
readonly rows: readonly MessagesTimelineRow[];
|
readonly rows: readonly MessagesTimelineRow[];
|
||||||
readonly pending: PendingThreadRequests;
|
readonly pending: PendingThreadRequests;
|
||||||
@@ -33,6 +41,8 @@ export interface Timeline {
|
|||||||
readonly isWorking: boolean;
|
readonly isWorking: boolean;
|
||||||
/** When the current run started working, for "Working for 12s". */
|
/** When the current run started working, for "Working for 12s". */
|
||||||
readonly workStartedAt: string | null;
|
readonly workStartedAt: string | null;
|
||||||
|
/** Footers by run, keyed as messages key their runs. */
|
||||||
|
readonly runMeta: ReadonlyMap<string, RunMeta>;
|
||||||
/** Carried into the next build so unchanged rows keep their identity. */
|
/** Carried into the next build so unchanged rows keep their identity. */
|
||||||
readonly cache: TimelineCache;
|
readonly cache: TimelineCache;
|
||||||
}
|
}
|
||||||
@@ -92,7 +102,7 @@ export function buildTimeline(
|
|||||||
isWorking,
|
isWorking,
|
||||||
runlessWorkActive: runlessStartedAt !== null,
|
runlessWorkActive: runlessStartedAt !== null,
|
||||||
activeTurnStartedAt: workStartedAt,
|
activeTurnStartedAt: workStartedAt,
|
||||||
turnDiffSummaries: [],
|
turnDiffSummaries: deriveThreadCheckpointSummaries(projection),
|
||||||
supportsConversationRollback: false,
|
supportsConversationRollback: false,
|
||||||
},
|
},
|
||||||
cache?.rows ?? null,
|
cache?.rows ?? null,
|
||||||
@@ -104,6 +114,13 @@ export function buildTimeline(
|
|||||||
turns: turnTargets(projection, entries.entries, isWorking ? runtime?.activeRunId ?? null : null, options.historyComplete),
|
turns: turnTargets(projection, entries.entries, isWorking ? runtime?.activeRunId ?? null : null, options.historyComplete),
|
||||||
isWorking,
|
isWorking,
|
||||||
workStartedAt,
|
workStartedAt,
|
||||||
|
runMeta: new Map(
|
||||||
|
projection.runs.map((run) => {
|
||||||
|
const started = run.workStartedAt ?? run.startedAt ?? run.requestedAt;
|
||||||
|
const durationMs = run.completedAt ? DateTime.toEpochMillis(run.completedAt) - DateTime.toEpochMillis(started) : null;
|
||||||
|
return [run.id as string, { model: run.modelSelection.model, durationMs: durationMs !== null && durationMs >= 0 ? durationMs : null }] as const;
|
||||||
|
}),
|
||||||
|
),
|
||||||
cache: { entries, rows, stable, expandAll: options.expandAll, expanded: opened },
|
cache: { entries, rows, stable, expandAll: options.expandAll, expanded: opened },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -921,6 +921,7 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
|
|||||||
),
|
),
|
||||||
loadEarlier: useEvent(() => loadEarlier()),
|
loadEarlier: useEvent(() => loadEarlier()),
|
||||||
menu: useEvent((target: ConversationTarget) => openConversationMenu(target)),
|
menu: useEvent((target: ConversationTarget) => openConversationMenu(target)),
|
||||||
|
openTurnDiff: useEvent((checkpointTurnCount: number) => turns.openTurnDiff(checkpointTurnCount)),
|
||||||
};
|
};
|
||||||
const copy = (label: string, text: string) => {
|
const copy = (label: string, text: string) => {
|
||||||
copyText(renderer, text);
|
copyText(renderer, text);
|
||||||
@@ -944,6 +945,7 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
|
|||||||
]
|
]
|
||||||
: [
|
: [
|
||||||
{ id: "copy-message", title: "Copy message", run: () => copy("the message", target.text) },
|
{ id: "copy-message", title: "Copy message", run: () => copy("the message", target.text) },
|
||||||
|
...(target.checkpointTurnCount !== undefined ? [{ id: "turn-diff", title: "View changes from this turn", run: () => turns.openTurnDiff(target.checkpointTurnCount!) }] : []),
|
||||||
...(target.role === "user" ? turns.menuFor(target.messageId) : []),
|
...(target.role === "user" ? turns.menuFor(target.messageId) : []),
|
||||||
];
|
];
|
||||||
if (target.kind === "message" && target.role === "user") turns.select(target.messageId);
|
if (target.kind === "message" && target.role === "user") turns.select(target.messageId);
|
||||||
@@ -1122,6 +1124,7 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
|
|||||||
loading={watchedId !== threadId || thread?.status === "loading"}
|
loading={watchedId !== threadId || thread?.status === "loading"}
|
||||||
error={thread?.error}
|
error={thread?.error}
|
||||||
workspaceRoot={threadShell?.worktreePath ?? undefined}
|
workspaceRoot={threadShell?.worktreePath ?? undefined}
|
||||||
|
timestampFormat={config.timestampFormat}
|
||||||
now={now}
|
now={now}
|
||||||
scrollRef={scrollRef}
|
scrollRef={scrollRef}
|
||||||
parent={parent}
|
parent={parent}
|
||||||
|
|||||||
+107
-4
@@ -8,6 +8,9 @@ import { findThreadSearchOccurrences } from "@t3tools/shared/threadSearch";
|
|||||||
import type { OrchestrationV2SearchThreadResult } from "@t3tools/contracts";
|
import type { OrchestrationV2SearchThreadResult } from "@t3tools/contracts";
|
||||||
import { FindText } from "./FindText.tsx";
|
import { FindText } from "./FindText.tsx";
|
||||||
import { Button, Buttons, isLeftClick, isRightClick, useHover } from "./Button.tsx";
|
import { Button, Buttons, isLeftClick, isRightClick, useHover } from "./Button.tsx";
|
||||||
|
import { checkpointFileTotals, type ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints";
|
||||||
|
import { formatDuration } from "@t3tools/shared/orchestrationTiming";
|
||||||
|
import type { Tui3Config } from "../config.ts";
|
||||||
|
|
||||||
import { CommandOutput } from "./CommandOutput.tsx";
|
import { CommandOutput } from "./CommandOutput.tsx";
|
||||||
import { BAR } from "./edges.ts";
|
import { BAR } from "./edges.ts";
|
||||||
@@ -19,7 +22,7 @@ import { colors, getMarkdownStyle, toneColor } from "./theme.ts";
|
|||||||
|
|
||||||
/** What a right-click in the conversation was on. */
|
/** What a right-click in the conversation was on. */
|
||||||
export type ConversationTarget =
|
export type ConversationTarget =
|
||||||
| { readonly kind: "message"; readonly messageId: string; readonly role: "user" | "assistant" | "system"; readonly text: string }
|
| { readonly kind: "message"; readonly messageId: string; readonly role: "user" | "assistant" | "system"; readonly text: string; readonly checkpointTurnCount?: number }
|
||||||
/** `omitted`: the server left the output out of the thread; `source` is where to fetch it. */
|
/** `omitted`: the server left the output out of the thread; `source` is where to fetch it. */
|
||||||
| { readonly kind: "command"; readonly command: string; readonly output: string; readonly omitted: boolean; readonly source: { readonly threadId: ThreadId; readonly itemId: TurnItemId } | null };
|
| { readonly kind: "command"; readonly command: string; readonly output: string; readonly omitted: boolean; readonly source: { readonly threadId: ThreadId; readonly itemId: TurnItemId } | null };
|
||||||
|
|
||||||
@@ -31,6 +34,8 @@ export interface ConversationMouse {
|
|||||||
readonly toggleFold: (id: string) => void;
|
readonly toggleFold: (id: string) => void;
|
||||||
readonly loadEarlier: () => void;
|
readonly loadEarlier: () => void;
|
||||||
readonly menu: (target: ConversationTarget) => void;
|
readonly menu: (target: ConversationTarget) => void;
|
||||||
|
/** A click on a changed file: that turn's diff. */
|
||||||
|
readonly openTurnDiff: (checkpointTurnCount: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The conversation, row for row as the web app derives it (MessagesTimeline.logic). */
|
/** The conversation, row for row as the web app derives it (MessagesTimeline.logic). */
|
||||||
@@ -45,6 +50,7 @@ export function ThreadView(props: {
|
|||||||
readonly loading: boolean;
|
readonly loading: boolean;
|
||||||
readonly error?: string | undefined;
|
readonly error?: string | undefined;
|
||||||
readonly workspaceRoot: string | undefined;
|
readonly workspaceRoot: string | undefined;
|
||||||
|
readonly timestampFormat: Tui3Config["timestampFormat"];
|
||||||
readonly now: number;
|
readonly now: number;
|
||||||
readonly scrollRef: RefObject<ScrollBoxRenderable | null>;
|
readonly scrollRef: RefObject<ScrollBoxRenderable | null>;
|
||||||
/** For a subagent or fork: the thread it came from, shown as a link in the header. */
|
/** For a subagent or fork: the thread it came from, shown as a link in the header. */
|
||||||
@@ -79,6 +85,7 @@ export function ThreadView(props: {
|
|||||||
activeOccurrence={props.findMatch?.entryId === row.id ? props.findMatch.occurrence : null}
|
activeOccurrence={props.findMatch?.entryId === row.id ? props.findMatch.occurrence : null}
|
||||||
pending={row.kind === "event" && pendingIds.has(eventRequestId(row) ?? "")}
|
pending={row.kind === "event" && pendingIds.has(eventRequestId(row) ?? "")}
|
||||||
workspaceRoot={props.workspaceRoot}
|
workspaceRoot={props.workspaceRoot}
|
||||||
|
footer={assistantFooter(row, timeline, props.timestampFormat, props.now)}
|
||||||
now={row.kind === "working" ? props.now : 0}
|
now={row.kind === "working" ? props.now : 0}
|
||||||
workStartedAt={timeline.workStartedAt}
|
workStartedAt={timeline.workStartedAt}
|
||||||
onOpenThread={props.onOpenThread}
|
onOpenThread={props.onOpenThread}
|
||||||
@@ -90,6 +97,39 @@ export function ThreadView(props: {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The turn footer's text: model, how long the run took, and when the reply
|
||||||
|
* landed, day-aware as the web's is. Parts a row doesn't carry are left out;
|
||||||
|
* only a finished turn's last reply (or its detached meta row) gets one.
|
||||||
|
*/
|
||||||
|
function assistantFooter(row: MessagesTimelineRow, timeline: Timeline, timestampFormat: Tui3Config["timestampFormat"], now: number): string {
|
||||||
|
const message = row.kind === "assistant-meta" ? row.message : row.kind === "message" && row.showAssistantMeta ? row.message : null;
|
||||||
|
if (message?.role !== "assistant" || message.streaming) return "";
|
||||||
|
const meta = message.runId ? timeline.runMeta.get(message.runId) : undefined;
|
||||||
|
const projected = row.kind === "message" || row.kind === "assistant-meta" ? row.projectedItem : undefined;
|
||||||
|
const status = projected && projected.item.status !== "completed" ? projected.item.status : "";
|
||||||
|
const parts = [
|
||||||
|
meta?.model && meta.model !== "default" ? meta.model : "",
|
||||||
|
meta?.durationMs !== null && meta?.durationMs !== undefined ? formatDuration(meta.durationMs) : "",
|
||||||
|
dayAwareTime(message.updatedAt, timestampFormat, now),
|
||||||
|
status,
|
||||||
|
];
|
||||||
|
return parts.filter(Boolean).join(" · ");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The web's day-aware timestamp: a time today, "yesterday at …", then a short date. */
|
||||||
|
function dayAwareTime(iso: string, format: Tui3Config["timestampFormat"], now: number): string {
|
||||||
|
const date = new Date(iso);
|
||||||
|
if (Number.isNaN(date.getTime())) return "";
|
||||||
|
const time = date.toLocaleTimeString(undefined, { hour: "numeric", minute: "2-digit", ...(format === "locale" ? {} : { hour12: format === "12-hour" }) });
|
||||||
|
const today = new Date(now);
|
||||||
|
const dayDiff = Math.round((new Date(today.getFullYear(), today.getMonth(), today.getDate()).getTime() - new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime()) / 86_400_000);
|
||||||
|
if (dayDiff <= 0) return time;
|
||||||
|
if (dayDiff === 1) return `yesterday at ${time}`;
|
||||||
|
const day = date.toLocaleDateString(undefined, { month: "numeric", day: "numeric", ...(date.getFullYear() === today.getFullYear() ? {} : { year: "numeric" as const }) });
|
||||||
|
return `${day} ${time}`;
|
||||||
|
}
|
||||||
|
|
||||||
function LoadEarlier({ history, onLoad }: { readonly history: ThreadHistory; readonly onLoad: () => void }) {
|
function LoadEarlier({ history, onLoad }: { readonly history: ThreadHistory; readonly onLoad: () => void }) {
|
||||||
const label = history.loading ? "Loading earlier turns…" : history.error ? `Could not load earlier turns: ${history.error} (o to retry)` : "Load earlier turns (o)";
|
const label = history.loading ? "Loading earlier turns…" : history.error ? `Could not load earlier turns: ${history.error} (o to retry)` : "Load earlier turns (o)";
|
||||||
return <Divider label={label} color={history.error ? colors.bad : colors.accent} onPress={history.loading ? undefined : onLoad} />;
|
return <Divider label={label} color={history.error ? colors.bad : colors.accent} onPress={history.loading ? undefined : onLoad} />;
|
||||||
@@ -119,6 +159,8 @@ const Row = memo(function Row(props: {
|
|||||||
readonly activeOccurrence: number | null;
|
readonly activeOccurrence: number | null;
|
||||||
readonly pending: boolean;
|
readonly pending: boolean;
|
||||||
readonly workspaceRoot: string | undefined;
|
readonly workspaceRoot: string | undefined;
|
||||||
|
/** The turn footer's text for this row, or "" for none. */
|
||||||
|
readonly footer: string;
|
||||||
readonly now: number;
|
readonly now: number;
|
||||||
readonly workStartedAt: string | null;
|
readonly workStartedAt: string | null;
|
||||||
readonly onOpenThread: (threadId: ThreadId) => void;
|
readonly onOpenThread: (threadId: ThreadId) => void;
|
||||||
@@ -132,15 +174,20 @@ const Row = memo(function Row(props: {
|
|||||||
const segments = findTextSegments(message.text, message.role === "user");
|
const segments = findTextSegments(message.text, message.role === "user");
|
||||||
if (segments.some((segment) => findThreadSearchOccurrences(segment, props.findQuery).length > 0)) return <FindText segments={segments} query={props.findQuery} activeOccurrence={props.activeOccurrence} scrollRef={props.scrollRef} />;
|
if (segments.some((segment) => findThreadSearchOccurrences(segment, props.findQuery).length > 0)) return <FindText segments={segments} query={props.findQuery} activeOccurrence={props.activeOccurrence} scrollRef={props.scrollRef} />;
|
||||||
}
|
}
|
||||||
const menu = { kind: "message", messageId: message.id, role: message.role, text: message.text } as const;
|
const summary = row.assistantTurnDiffSummary;
|
||||||
|
const menu = { kind: "message", messageId: message.id, role: message.role, text: message.text, ...(summary && summary.files.length > 0 ? { checkpointTurnCount: summary.checkpointTurnCount } : {}) } as const;
|
||||||
if (message.role === "user") return <UserMessage text={message.text} messageId={message.id} selected={props.selected} onSelect={() => mouse.selectTurn(message.id)} onMenu={() => mouse.menu(menu)} />;
|
if (message.role === "user") return <UserMessage text={message.text} messageId={message.id} selected={props.selected} onSelect={() => mouse.selectTurn(message.id)} onMenu={() => mouse.menu(menu)} />;
|
||||||
if (message.role === "system") return <text marginTop={1} fg={colors.muted} onMouseDown={(event: MouseEvent) => isRightClick(event) && mouse.menu(menu)}>{message.text}</text>;
|
if (message.role === "system") return <text marginTop={1} fg={colors.muted} onMouseDown={(event: MouseEvent) => isRightClick(event) && mouse.menu(menu)}>{message.text}</text>;
|
||||||
return (
|
return (
|
||||||
<box marginTop={1} onMouseDown={(event: MouseEvent) => isRightClick(event) && mouse.menu(menu)}>
|
<box marginTop={1} flexDirection="column" onMouseDown={(event: MouseEvent) => isRightClick(event) && mouse.menu(menu)}>
|
||||||
<markdown content={message.text || "…"} syntaxStyle={getMarkdownStyle()} streaming={message.streaming} conceal />
|
<markdown content={message.text || "…"} syntaxStyle={getMarkdownStyle()} streaming={message.streaming} conceal />
|
||||||
|
{summary && summary.files.length > 0 ? <ChangedFiles summary={summary} onOpenTurnDiff={mouse.openTurnDiff} /> : null}
|
||||||
|
{props.footer ? <text marginTop={1} fg={colors.faint}>{props.footer}</text> : null}
|
||||||
</box>
|
</box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
case "assistant-meta":
|
||||||
|
return props.footer ? <text marginTop={1} fg={colors.faint}>{props.footer}</text> : null;
|
||||||
case "turn-fold":
|
case "turn-fold":
|
||||||
case "attempt-fold":
|
case "attempt-fold":
|
||||||
// The finished turn's work, folded: the web's turn separator.
|
// The finished turn's work, folded: the web's turn separator.
|
||||||
@@ -209,11 +256,67 @@ const Row = memo(function Row(props: {
|
|||||||
</text>
|
</text>
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
// assistant-meta, html-render, mcp-app: nothing a terminal can show.
|
// html-render, mcp-app: nothing a terminal can show.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** The files a turn changed, folded to one line; a file opens that turn's diff. */
|
||||||
|
function ChangedFiles({ summary, onOpenTurnDiff }: { readonly summary: ThreadCheckpointSummary; readonly onOpenTurnDiff: (checkpointTurnCount: number) => void }) {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const [hover, hoverProps] = useHover();
|
||||||
|
const totals = checkpointFileTotals(summary);
|
||||||
|
const hidden = totals.count - summary.files.length;
|
||||||
|
const openDiff = () => onOpenTurnDiff(summary.checkpointTurnCount);
|
||||||
|
return (
|
||||||
|
<box marginTop={1} flexDirection="column">
|
||||||
|
<box flexDirection="row" {...hoverProps} onMouseDown={(event: MouseEvent) => isLeftClick(event) && setOpen(!open)}>
|
||||||
|
<text fg={hover ? colors.text : colors.muted} selectable={false}>
|
||||||
|
<span fg={hover ? colors.text : colors.faint}>✎</span>
|
||||||
|
{` ${totals.count} ${totals.count === 1 ? "file" : "files"} `}
|
||||||
|
</text>
|
||||||
|
<DiffCounts additions={totals.additions} deletions={totals.deletions} />
|
||||||
|
<text fg={colors.faint} selectable={false}>{` ${open ? "⌄" : "›"}`}</text>
|
||||||
|
</box>
|
||||||
|
{open ? (
|
||||||
|
<box flexDirection="column" paddingLeft={2}>
|
||||||
|
{summary.files.map((file) => (
|
||||||
|
<ChangedFile key={file.path} path={file.path} additions={file.additions} deletions={file.deletions} onPress={openDiff} />
|
||||||
|
))}
|
||||||
|
{hidden > 0 ? (
|
||||||
|
<box flexDirection="row" onMouseDown={(event: MouseEvent) => isLeftClick(event) && openDiff()}>
|
||||||
|
<text fg={colors.faint} selectable={false}>{`… ${hidden} more ${hidden === 1 ? "file" : "files"}`}</text>
|
||||||
|
</box>
|
||||||
|
) : null}
|
||||||
|
</box>
|
||||||
|
) : null}
|
||||||
|
</box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ChangedFile({ path, additions, deletions, onPress }: { readonly path: string; readonly additions: number; readonly deletions: number; readonly onPress: () => void }) {
|
||||||
|
const [hover, hoverProps] = useHover();
|
||||||
|
return (
|
||||||
|
<box flexDirection="row" {...hoverProps} onMouseDown={(event: MouseEvent) => isLeftClick(event) && onPress()}>
|
||||||
|
<text fg={hover ? colors.text : colors.muted} selectable={false} wrapMode="none">{path}</text>
|
||||||
|
<box flexGrow={1} />
|
||||||
|
<DiffCounts additions={additions} deletions={deletions} />
|
||||||
|
</box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** `+42 −7`, each count in its own colour; a zero count is left out. */
|
||||||
|
function DiffCounts({ additions, deletions }: { readonly additions: number; readonly deletions: number }) {
|
||||||
|
if (additions === 0 && deletions === 0) return null;
|
||||||
|
return (
|
||||||
|
<text selectable={false} flexShrink={0}>
|
||||||
|
{additions > 0 ? <span fg={colors.good}>{`+${additions}`}</span> : null}
|
||||||
|
{additions > 0 && deletions > 0 ? " " : ""}
|
||||||
|
{deletions > 0 ? <span fg={colors.bad}>{`−${deletions}`}</span> : null}
|
||||||
|
</text>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const USER_FOLD_LINES = 8;
|
const USER_FOLD_LINES = 8;
|
||||||
const USER_FOLD_CHARS = 600;
|
const USER_FOLD_CHARS = 600;
|
||||||
|
|
||||||
|
|||||||
+8
-3
@@ -54,8 +54,13 @@ export function useTurns(input: {
|
|||||||
const checkpoint = fullThread
|
const checkpoint = fullThread
|
||||||
? turns.map((turn) => turn.checkpoint).filter((checkpoint): checkpoint is TurnCheckpoint => checkpoint?.status === "ready").sort((a, b) => b.checkpointTurnCount - a.checkpointTurnCount)[0]
|
? turns.map((turn) => turn.checkpoint).filter((checkpoint): checkpoint is TurnCheckpoint => checkpoint?.status === "ready").sort((a, b) => b.checkpointTurnCount - a.checkpointTurnCount)[0]
|
||||||
: diffTurn(turns, messageId);
|
: diffTurn(turns, messageId);
|
||||||
if (!input.threadId || !input.cwd || !checkpoint) return input.say("No changes from this turn.");
|
if (!checkpoint) return input.say("No changes from this turn.");
|
||||||
const toTurnCount = checkpoint.checkpointTurnCount;
|
showDiff(checkpoint.checkpointTurnCount, fullThread);
|
||||||
|
};
|
||||||
|
/** The changed-files line's diff: it already knows its checkpoint's turn count. */
|
||||||
|
const openTurnDiff = (checkpointTurnCount: number) => showDiff(checkpointTurnCount, false);
|
||||||
|
const showDiff = (toTurnCount: number, fullThread: boolean) => {
|
||||||
|
if (!input.threadId || !input.cwd) return input.say("No changes from this turn.");
|
||||||
const state: DiffState = { cwd: input.cwd, path: null, title: fullThread ? "Changes" : `Turn ${toTurnCount}`, status: "loading" };
|
const state: DiffState = { cwd: input.cwd, path: null, title: fullThread ? "Changes" : `Turn ${toTurnCount}`, status: "loading" };
|
||||||
input.setDiff(state);
|
input.setDiff(state);
|
||||||
input.showConversation();
|
input.showConversation();
|
||||||
@@ -134,7 +139,7 @@ export function useTurns(input: {
|
|||||||
] : []),
|
] : []),
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
return { selectedMessageId, bindings, diffContext, select, menuFor };
|
return { selectedMessageId, bindings, diffContext, select, menuFor, openTurnDiff };
|
||||||
}
|
}
|
||||||
|
|
||||||
function messageOf(error: unknown): string { return error instanceof Error ? error.message : String(error); }
|
function messageOf(error: unknown): string { return error instanceof Error ? error.message : String(error); }
|
||||||
+26
-1
@@ -1,6 +1,6 @@
|
|||||||
import { afterEach, describe, expect, test } from "bun:test";
|
import { afterEach, describe, expect, test } from "bun:test";
|
||||||
|
|
||||||
import { omittedCommand, withApproval, withOmittedOutput, withQuestion } from "./fixtures.ts";
|
import { omittedCommand, withApproval, withCompletedTurn, withOmittedOutput, withQuestion } from "./fixtures.ts";
|
||||||
import { loadLayout } from "../../src/layout.ts";
|
import { loadLayout } from "../../src/layout.ts";
|
||||||
import { fakeSession, renderApp, v2ThreadId } from "./harness.tsx";
|
import { fakeSession, renderApp, v2ThreadId } from "./harness.tsx";
|
||||||
|
|
||||||
@@ -138,6 +138,31 @@ describe("palette and pickers", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("a finished turn", () => {
|
||||||
|
test("its changed files fold out under the reply, and a file opens the turn's diff", async () => {
|
||||||
|
const patch = "diff --git a/src/index.ts b/src/index.ts\n--- a/src/index.ts\n+++ b/src/index.ts\n@@ -1 +1 @@\n-old\n+new\n";
|
||||||
|
const app = await open({ session: fakeSession({ projection: withCompletedTurn(), results: { turnDiff: { diff: patch } } }) });
|
||||||
|
expect(app.frame()).toContain("✎ 3 files +42 −7 ›");
|
||||||
|
expect(app.frame()).not.toContain("src/util.ts");
|
||||||
|
const line = app.find("3 files");
|
||||||
|
await app.click(line.x, line.y);
|
||||||
|
expect(app.frame()).toContain("src/index.ts");
|
||||||
|
expect(app.frame()).toContain("src/util.ts");
|
||||||
|
expect(app.frame()).toContain("+30 −5");
|
||||||
|
const file = app.find("src/util.ts");
|
||||||
|
await app.click(file.x, file.y);
|
||||||
|
await app.settle(50);
|
||||||
|
expect(app.calls("turnDiff").map((call) => call.args[0])).toEqual([{ threadId: v2ThreadId, toTurnCount: 1, ignoreWhitespace: true, fromTurnCount: 0 }]);
|
||||||
|
expect(app.frame()).toContain("Turn 1");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("its footer names the model, the duration and the time", async () => {
|
||||||
|
const app = await open({ session: fakeSession({ projection: withCompletedTurn() }) });
|
||||||
|
// The date half is locale- and timezone-shaped; the model and duration are not.
|
||||||
|
expect(app.frame()).toMatch(/gpt-5\.4 · 3m 12s · /);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("approvals", () => {
|
describe("approvals", () => {
|
||||||
test("y, Y and n answer the request", async () => {
|
test("y, Y and n answer the request", async () => {
|
||||||
const app = await open({ session: fakeSession({ projection: withApproval() }) });
|
const app = await open({ session: fakeSession({ projection: withApproval() }) });
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import * as DateTime from "effect/DateTime";
|
|||||||
import { v2Projection } from "../../vendor/t3code/packages/client-runtime/src/state/orchestrationV2TestFixtures.ts";
|
import { v2Projection } from "../../vendor/t3code/packages/client-runtime/src/state/orchestrationV2TestFixtures.ts";
|
||||||
|
|
||||||
const at = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z");
|
const at = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z");
|
||||||
|
/** `seconds` after the fixture's start. */
|
||||||
|
const after = (seconds: number) => DateTime.makeUnsafe(DateTime.toEpochMillis(at) + seconds * 1_000);
|
||||||
|
|
||||||
/** The thread with a command waiting for approval. */
|
/** The thread with a command waiting for approval. */
|
||||||
export function withApproval(supportsFeedback = false): OrchestrationV2ThreadProjection {
|
export function withApproval(supportsFeedback = false): OrchestrationV2ThreadProjection {
|
||||||
@@ -54,6 +56,57 @@ export const omittedCommand = {
|
|||||||
exitCode: 0,
|
exitCode: 0,
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
/** A finished turn: one prompt, one reply 3m 12s later, and a checkpoint of three changed files. */
|
||||||
|
export function withCompletedTurn(): OrchestrationV2ThreadProjection {
|
||||||
|
const base = {
|
||||||
|
threadId: v2Projection.thread.id,
|
||||||
|
runId: "run-1",
|
||||||
|
nodeId: null,
|
||||||
|
providerThreadId: null,
|
||||||
|
providerTurnId: null,
|
||||||
|
nativeItemRef: null,
|
||||||
|
parentItemId: null,
|
||||||
|
title: null,
|
||||||
|
};
|
||||||
|
const turnItems = [
|
||||||
|
{ ...base, id: "item-user", ordinal: 0, status: "completed", startedAt: at, completedAt: at, updatedAt: at, type: "user_message", createdBy: "user", creationSource: "web", messageId: "msg-user-1", inputIntent: "turn_start", text: "Do the thing", attachments: [] },
|
||||||
|
{ ...base, id: "item-edit", ordinal: 1, status: "completed", startedAt: after(60), completedAt: after(65), updatedAt: after(65), type: "file_change", fileName: "src/index.ts", additions: 30, deletions: 5 },
|
||||||
|
{ ...base, id: "item-assistant", ordinal: 2, status: "completed", startedAt: after(192), completedAt: after(192), updatedAt: after(192), type: "assistant_message", messageId: "msg-assistant-1", text: "Done — the thing is done.", streaming: false },
|
||||||
|
];
|
||||||
|
return {
|
||||||
|
...v2Projection,
|
||||||
|
runs: [
|
||||||
|
{ id: "run-1", threadId: v2Projection.thread.id, ordinal: 1, providerInstanceId: "codex", modelSelection: { instanceId: "codex", model: "gpt-5.4" }, providerThreadId: null, userMessageId: "msg-user-1", rootNodeId: null, activeAttemptId: null, status: "completed", requestedAt: at, startedAt: at, completedAt: after(192), checkpointId: "checkpoint-1", contextHandoffId: null },
|
||||||
|
],
|
||||||
|
messages: [
|
||||||
|
{ createdBy: "user", creationSource: "web", id: "msg-user-1", threadId: v2Projection.thread.id, runId: "run-1", nodeId: null, role: "user", text: "Do the thing", attachments: [], streaming: false, createdAt: at, updatedAt: at },
|
||||||
|
{ createdBy: "user", creationSource: "web", id: "msg-assistant-1", threadId: v2Projection.thread.id, runId: "run-1", nodeId: null, role: "assistant", text: "Done — the thing is done.", attachments: [], streaming: false, createdAt: after(192), updatedAt: after(192) },
|
||||||
|
],
|
||||||
|
checkpoints: [
|
||||||
|
{
|
||||||
|
id: "checkpoint-1",
|
||||||
|
threadId: v2Projection.thread.id,
|
||||||
|
scopeId: "scope-1",
|
||||||
|
runId: "run-1",
|
||||||
|
nodeId: null,
|
||||||
|
parentCheckpointId: null,
|
||||||
|
ordinalWithinScope: 0,
|
||||||
|
appRunOrdinal: 1,
|
||||||
|
ref: "refs/t3/checkpoint-1",
|
||||||
|
status: "ready",
|
||||||
|
files: [
|
||||||
|
{ path: "src/index.ts", kind: "modified", additions: 30, deletions: 5 },
|
||||||
|
{ path: "src/util.ts", kind: "modified", additions: 10, deletions: 2 },
|
||||||
|
{ path: "README.md", kind: "modified", additions: 2, deletions: 0 },
|
||||||
|
],
|
||||||
|
capturedAt: after(192),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
turnItems,
|
||||||
|
visibleTurnItems: turnItems.map((item, position) => ({ position, visibility: "local", sourceThreadId: v2Projection.thread.id, sourceItemId: item.id, item })),
|
||||||
|
} as unknown as OrchestrationV2ThreadProjection;
|
||||||
|
}
|
||||||
|
|
||||||
export function withOmittedOutput(): OrchestrationV2ThreadProjection {
|
export function withOmittedOutput(): OrchestrationV2ThreadProjection {
|
||||||
return {
|
return {
|
||||||
...v2Projection,
|
...v2Projection,
|
||||||
|
|||||||
Reference in new issue
Block a user