Changed files under each reply, with a turn footer

This commit is contained in:
Callum Alpass committed 2026-11-03 00:46:30 +11:00
1 parent b70099f23f
commit 49b04f9012
6 files changed
+215 -9

No files matched your search

+18 -1
View File
@@ -1,11 +1,13 @@
import { turnTargets, type TurnTarget } from "./turns.ts";
import type { OrchestrationV2ThreadProjection, RunAttemptId, RunId } from "@t3tools/contracts";
import * as DateTime from "effect/DateTime";
import {
deriveRunlessWorkStartedAt,
deriveThreadActivityRun,
deriveThreadStructureRuntime,
} from "@t3tools/client-runtime/state/thread-execution";
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.
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 { 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 {
readonly rows: readonly MessagesTimelineRow[];
readonly pending: PendingThreadRequests;
@@ -33,6 +41,8 @@ export interface Timeline {
readonly isWorking: boolean;
/** When the current run started working, for "Working for 12s". */
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. */
readonly cache: TimelineCache;
}
@@ -92,7 +102,7 @@ export function buildTimeline(
isWorking,
runlessWorkActive: runlessStartedAt !== null,
activeTurnStartedAt: workStartedAt,
turnDiffSummaries: [],
turnDiffSummaries: deriveThreadCheckpointSummaries(projection),
supportsConversationRollback: false,
},
cache?.rows ?? null,
@@ -104,6 +114,13 @@ export function buildTimeline(
turns: turnTargets(projection, entries.entries, isWorking ? runtime?.activeRunId ?? null : null, options.historyComplete),
isWorking,
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 },
};
}
+3
View File
@@ -921,6 +921,7 @@ export function App(props: { readonly session: T3Session; readonly config: Tui3C
),
loadEarlier: useEvent(() => loadEarlier()),
menu: useEvent((target: ConversationTarget) => openConversationMenu(target)),
openTurnDiff: useEvent((checkpointTurnCount: number) => turns.openTurnDiff(checkpointTurnCount)),
};
const copy = (label: string, text: string) => {
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) },
...(target.checkpointTurnCount !== undefined ? [{ id: "turn-diff", title: "View changes from this turn", run: () => turns.openTurnDiff(target.checkpointTurnCount!) }] : []),
...(target.role === "user" ? turns.menuFor(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"}
error={thread?.error}
workspaceRoot={threadShell?.worktreePath ?? undefined}
timestampFormat={config.timestampFormat}
now={now}
scrollRef={scrollRef}
parent={parent}
+107 -4
View File
@@ -8,6 +8,9 @@ import { findThreadSearchOccurrences } from "@t3tools/shared/threadSearch";
import type { OrchestrationV2SearchThreadResult } from "@t3tools/contracts";
import { FindText } from "./FindText.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 { BAR } from "./edges.ts";
@@ -19,7 +22,7 @@ import { colors, getMarkdownStyle, toneColor } from "./theme.ts";
/** What a right-click in the conversation was on. */
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. */
| { 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 loadEarlier: () => 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). */
@@ -45,6 +50,7 @@ export function ThreadView(props: {
readonly loading: boolean;
readonly error?: string | undefined;
readonly workspaceRoot: string | undefined;
readonly timestampFormat: Tui3Config["timestampFormat"];
readonly now: number;
readonly scrollRef: RefObject<ScrollBoxRenderable | null>;
/** 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}
pending={row.kind === "event" && pendingIds.has(eventRequestId(row) ?? "")}
workspaceRoot={props.workspaceRoot}
footer={assistantFooter(row, timeline, props.timestampFormat, props.now)}
now={row.kind === "working" ? props.now : 0}
workStartedAt={timeline.workStartedAt}
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 }) {
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} />;
@@ -119,6 +159,8 @@ const Row = memo(function Row(props: {
readonly activeOccurrence: number | null;
readonly pending: boolean;
readonly workspaceRoot: string | undefined;
/** The turn footer's text for this row, or "" for none. */
readonly footer: string;
readonly now: number;
readonly workStartedAt: string | null;
readonly onOpenThread: (threadId: ThreadId) => void;
@@ -132,15 +174,20 @@ const Row = memo(function Row(props: {
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} />;
}
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 === "system") return <text marginTop={1} fg={colors.muted} onMouseDown={(event: MouseEvent) => isRightClick(event) && mouse.menu(menu)}>{message.text}</text>;
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 />
{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>
);
}
case "assistant-meta":
return props.footer ? <text marginTop={1} fg={colors.faint}>{props.footer}</text> : null;
case "turn-fold":
case "attempt-fold":
// The finished turn's work, folded: the web's turn separator.
@@ -209,11 +256,67 @@ const Row = memo(function Row(props: {
</text>
);
default:
// assistant-meta, html-render, mcp-app: nothing a terminal can show.
// html-render, mcp-app: nothing a terminal can show.
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_CHARS = 600;
+8 -3
View File
@@ -54,8 +54,13 @@ export function useTurns(input: {
const checkpoint = fullThread
? turns.map((turn) => turn.checkpoint).filter((checkpoint): checkpoint is TurnCheckpoint => checkpoint?.status === "ready").sort((a, b) => b.checkpointTurnCount - a.checkpointTurnCount)[0]
: diffTurn(turns, messageId);
if (!input.threadId || !input.cwd || !checkpoint) return input.say("No changes from this turn.");
const toTurnCount = checkpoint.checkpointTurnCount;
if (!checkpoint) return input.say("No changes from this turn.");
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" };
input.setDiff(state);
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); }