diff --git a/src/model/timeline.ts b/src/model/timeline.ts index 5babea2..74844cf 100644 --- a/src/model/timeline.ts +++ b/src/model/timeline.ts @@ -47,14 +47,22 @@ export interface Timeline { readonly cache: TimelineCache; } +type TurnDiffSummaries = ReturnType; + interface TimelineCache { readonly entries: TimelineEntriesProjection; readonly rows: { readonly input: MessagesTimelineRowsInput; readonly rows: MessagesTimelineRow[] }; readonly stable: StableMessagesTimelineRowsState; readonly expandAll: boolean; readonly expanded: ReadonlySet; + /** The last summaries and what they were derived from, so unchanged replies keep their row identity. */ + readonly turnDiffSummaries: TurnDiffSummaries; + readonly checkpoints: OrchestrationV2ThreadProjection["checkpoints"]; + readonly checkpointMessages: OrchestrationV2ThreadProjection["messages"]; } +const sameItems = (a: readonly T[], b: readonly T[]): boolean => a.length === b.length && a.every((item, index) => item === b[index]); + /** Answers yes for every id: "expand everything" without knowing the group ids up front. */ class EverySet extends Set { override has(): boolean { @@ -88,6 +96,11 @@ export function buildTimeline( const isWorking = derivePhase(runtime) === "running" || runlessStartedAt !== null; const workStartedAt = deriveActiveWorkStartedAt(latestRun, runtime, null) ?? runlessStartedAt; const pending = derivePendingThreadRequests(projection); + const previousCache = previous?.cache; + const turnDiffSummaries = + previousCache && sameItems(previousCache.checkpoints, projection.checkpoints) && sameItems(previousCache.checkpointMessages, projection.messages) + ? previousCache.turnDiffSummaries + : deriveThreadCheckpointSummaries(projection); const expanded = options.expandAll ? EVERYTHING : opened; const rows = deriveMessagesTimelineRowsWithState( { @@ -102,7 +115,7 @@ export function buildTimeline( isWorking, runlessWorkActive: runlessStartedAt !== null, activeTurnStartedAt: workStartedAt, - turnDiffSummaries: deriveThreadCheckpointSummaries(projection), + turnDiffSummaries, supportsConversationRollback: false, }, cache?.rows ?? null, @@ -121,6 +134,6 @@ export function buildTimeline( 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, turnDiffSummaries, checkpoints: projection.checkpoints, checkpointMessages: projection.messages }, }; } diff --git a/src/ui/ThreadView.tsx b/src/ui/ThreadView.tsx index f756cb2..ff502f5 100644 --- a/src/ui/ThreadView.tsx +++ b/src/ui/ThreadView.tsx @@ -281,9 +281,10 @@ function ChangedFiles({ summary, onOpenTurnDiff }: { readonly summary: ThreadChe function ChangedFile({ path, additions, deletions, onPress }: { readonly path: string; readonly additions: number; readonly deletions: number; readonly onPress: () => void }) { const [hover, hoverProps] = useHover(); + const counts = (additions > 0 ? `+${additions}`.length : 0) + (deletions > 0 ? `−${deletions}`.length : 0) + (additions > 0 && deletions > 0 ? 1 : 0); return ( isLeftClick(event) && onPress()}> - {path} + {truncate(path, CONTENT_WIDTH - 2 - (counts ? counts + 2 : 0))}