Open History to see the last commit
1import * as Equal from "effect/Equal";
2import {
3 formatDuration,
4 workEntryIndicatesToolNeutralStatus,
5 workLogEntryIsToolLike,
6 type TimelineEntry,
7 type TurnPlanEntry,
8 type WorkLogEntry,
9} from "../../session-logic";
10import { type ChatMessage, type ProposedPlan, type TurnDiffSummary } from "../../types";
11import { type MessageId, type OrchestrationLatestTurn, type TurnId } from "@t3tools/contracts";
12
13export const MAX_VISIBLE_WORK_LOG_ENTRIES = 1;
14export const TIMELINE_MINIMAP_ITEM_SPACING = 8;
15export const TIMELINE_MINIMAP_MIN_ITEMS = 2;
16export const TIMELINE_MINIMAP_MAX_HEIGHT_CSS = "calc(100vh - 18rem)";
17export const TIMELINE_CONTENT_MAX_WIDTH = 768;
18export const TIMELINE_MINIMAP_PERSISTENT_GUTTER = 48;
19
20export interface TimelineEndState {
21 readonly isAtEnd?: boolean;
22 readonly contentLength?: number;
23 readonly scroll?: number;
24 readonly scrollLength?: number;
25}
26
27/**
28 * Follow re-arm band above the hard bottom. Strict on purpose: LegendList's
29 * isNearEnd fires within half a viewport, which re-armed live-follow while the
30 * user was reading history and yanked them back down on the next stream chunk.
31 * A small pixel band (instead of the 1px isAtEnd epsilon alone) keeps re-arming
32 * reliable while streaming content is still growing under the viewport.
33 */
34export const TIMELINE_FOLLOW_REARM_THRESHOLD_PX = 40;
35
36export function resolveTimelineIsAtEnd(
37 state: TimelineEndState | undefined,
38 endInset = 0,
39): boolean | undefined {
40 if (!state) {
41 return undefined;
42 }
43 if (state.isAtEnd) {
44 return true;
45 }
46 const { contentLength, scroll, scrollLength } = state;
47 if (contentLength === undefined || scroll === undefined || scrollLength === undefined) {
48 return state.isAtEnd;
49 }
50 // contentLength includes the end inset (composer overlay), so subtract it to
51 // measure the distance to the real content bottom.
52 return contentLength - scroll - scrollLength - endInset <= TIMELINE_FOLLOW_REARM_THRESHOLD_PX;
53}
54
55export function shouldPreserveAssistantLineBreaks(text: string): boolean {
56 return /^★ Insight(?:\s|─)/mu.test(text);
57}
58
59export function resolveTimelineMinimapHeightStyle(itemCount: number): string {
60 const naturalHeight = Math.max(1, (itemCount - 1) * TIMELINE_MINIMAP_ITEM_SPACING);
61 return `min(${naturalHeight}px, ${TIMELINE_MINIMAP_MAX_HEIGHT_CSS})`;
62}
63
64export function resolveTimelineMinimapTopPercent(index: number, itemCount: number): number {
65 if (itemCount <= 1) {
66 return 0;
67 }
68 return (Math.max(0, Math.min(index, itemCount - 1)) / (itemCount - 1)) * 100;
69}
70
71export function resolveTimelineMinimapIndexFromPointer(input: {
72 readonly itemCount: number;
73 readonly railTop: number;
74 readonly railHeight: number;
75 readonly pointerY: number;
76}): number | null {
77 if (input.itemCount <= 0 || input.railHeight <= 0) {
78 return null;
79 }
80 if (input.itemCount === 1) {
81 return 0;
82 }
83
84 const progress = Math.max(0, Math.min(1, (input.pointerY - input.railTop) / input.railHeight));
85 return Math.max(0, Math.min(input.itemCount - 1, Math.round(progress * (input.itemCount - 1))));
86}
87
88export function resolveTimelineMinimapHasPersistentGutter(viewportWidth: number): boolean {
89 if (!Number.isFinite(viewportWidth) || viewportWidth <= 0) {
90 return false;
91 }
92
93 const contentWidth = Math.min(viewportWidth, TIMELINE_CONTENT_MAX_WIDTH);
94 const sideGutter = Math.max(0, (viewportWidth - contentWidth) / 2);
95 return sideGutter >= TIMELINE_MINIMAP_PERSISTENT_GUTTER;
96}
97
98export const TIMELINE_MINIMAP_HIT_STRIP_LEFT = 12;
99export const TIMELINE_MINIMAP_HIT_STRIP_MAX_WIDTH = 40;
100export const TIMELINE_MINIMAP_EXPANDED_HIT_STRIP_WIDTH = "22rem";
101
102/**
103 * The minimap overlays the viewport's left edge while the content column is
104 * centered, so the side gutter between them shrinks under browser zoom or a
105 * narrow pane. A fixed-width hover strip would then sit on top of the message
106 * text and swallow its pointer events. Cap the strip's width so it never
107 * extends past the gutter into the content column; 0 disables the strip.
108 */
109export function resolveTimelineMinimapHitStripWidth(viewportWidth: number): number {
110 if (!Number.isFinite(viewportWidth) || viewportWidth <= 0) {
111 return 0;
112 }
113
114 const contentWidth = Math.min(viewportWidth, TIMELINE_CONTENT_MAX_WIDTH);
115 const sideGutter = Math.max(0, (viewportWidth - contentWidth) / 2);
116 return Math.max(
117 0,
118 Math.min(
119 TIMELINE_MINIMAP_HIT_STRIP_MAX_WIDTH,
120 Math.floor(sideGutter) - TIMELINE_MINIMAP_HIT_STRIP_LEFT,
121 ),
122 );
123}
124
125/**
126 * Once the preview is open, keep the full preview and the space leading to it
127 * interactive. The collapsed strip remains gutter-capped so it cannot block
128 * selecting message text.
129 */
130export function resolveTimelineMinimapInteractiveWidth(
131 collapsedWidth: number,
132 expanded: boolean,
133): number | string {
134 return expanded ? TIMELINE_MINIMAP_EXPANDED_HIT_STRIP_WIDTH : collapsedWidth;
135}
136
137function computeElapsedMs(startIso: string, endIso: string): number | null {
138 const start = Date.parse(startIso);
139 const end = Date.parse(endIso);
140 if (!Number.isFinite(start) || !Number.isFinite(end)) return null;
141 return Math.max(0, end - start);
142}
143
144function maxIsoTimestamp(a: string | null, b: string | null): string | null {
145 if (a === null) return b;
146 if (b === null) return a;
147 const aMs = Date.parse(a);
148 const bMs = Date.parse(b);
149 if (!Number.isFinite(aMs)) return b;
150 if (!Number.isFinite(bMs)) return a;
151 return bMs > aMs ? b : a;
152}
153
154export interface TimelineDurationMessage {
155 id: string;
156 role: "user" | "assistant" | "system";
157 createdAt: string;
158 updatedAt: string;
159 streaming: boolean;
160}
161
162export type TimelineLatestTurn = Pick<
163 OrchestrationLatestTurn,
164 "turnId" | "state" | "startedAt" | "completedAt"
165>;
166
167export type MessagesTimelineRow =
168 | {
169 kind: "work";
170 id: string;
171 createdAt: string;
172 groupedEntries: WorkLogEntry[];
173 }
174 | {
175 kind: "work-toggle";
176 id: string;
177 createdAt: string;
178 groupId: string;
179 hiddenCount: number;
180 expanded: boolean;
181 onlyToolEntries: boolean;
182 }
183 | {
184 kind: "turn-fold";
185 id: string;
186 createdAt: string;
187 turnId: TurnId;
188 label: string;
189 expanded: boolean;
190 }
191 | {
192 kind: "message";
193 id: string;
194 createdAt: string;
195 message: ChatMessage;
196 durationStart: string;
197 showAssistantMeta: boolean;
198 showAssistantCopyButton: boolean;
199 assistantCopyStreaming: boolean;
200 assistantTurnDiffSummary?: TurnDiffSummary | undefined;
201 revertTurnCount?: number | undefined;
202 }
203 | {
204 kind: "proposed-plan";
205 id: string;
206 createdAt: string;
207 proposedPlan: ProposedPlan;
208 }
209 | {
210 kind: "turn-plan";
211 id: string;
212 createdAt: string;
213 turnPlan: TurnPlanEntry;
214 }
215 | { kind: "working"; id: string; createdAt: string | null };
216
217export interface StableMessagesTimelineRowsState {
218 byId: Map<string, MessagesTimelineRow>;
219 result: MessagesTimelineRow[];
220}
221
222export function computeMessageDurationStart(
223 messages: ReadonlyArray<TimelineDurationMessage>,
224): Map<string, string> {
225 const result = new Map<string, string>();
226 let lastBoundary: string | null = null;
227
228 for (const message of messages) {
229 if (message.role === "user") {
230 lastBoundary = message.createdAt;
231 }
232 result.set(message.id, lastBoundary ?? message.createdAt);
233 if (message.role === "assistant" && !message.streaming) {
234 lastBoundary = message.updatedAt;
235 }
236 }
237
238 return result;
239}
240
241export function normalizeCompactToolLabel(value: string): string {
242 return value.replace(/\s+(?:complete|completed)\s*$/i, "").trim();
243}
244
245export function resolveAssistantMessageCopyState({
246 text,
247 showCopyButton,
248 streaming,
249}: {
250 text: string | null;
251 showCopyButton: boolean;
252 streaming: boolean;
253}) {
254 const hasText = text !== null && text.trim().length > 0;
255 return {
256 text: hasText ? text : null,
257 visible: showCopyButton && hasText && !streaming,
258 };
259}
260
261function deriveTerminalAssistantMessageIds(timelineEntries: ReadonlyArray<TimelineEntry>) {
262 const lastAssistantMessageIdByResponseKey = new Map<string, string>();
263 let nullTurnResponseIndex = 0;
264
265 for (const timelineEntry of timelineEntries) {
266 if (timelineEntry.kind !== "message") {
267 continue;
268 }
269 const { message } = timelineEntry;
270 if (message.role === "user") {
271 nullTurnResponseIndex += 1;
272 continue;
273 }
274 if (message.role !== "assistant") {
275 continue;
276 }
277
278 const responseKey = message.turnId
279 ? `turn:${message.turnId}`
280 : `unkeyed:${nullTurnResponseIndex}`;
281 lastAssistantMessageIdByResponseKey.set(responseKey, message.id);
282 }
283
284 return new Set(lastAssistantMessageIdByResponseKey.values());
285}
286
287interface TurnFold {
288 turnId: TurnId;
289 anchorEntryId: string;
290 createdAt: string;
291 hiddenEntryIds: ReadonlySet<string>;
292 label: string;
293}
294
295/**
296 * The session's running turn is authoritative when latestTurn briefly lags or
297 * regresses behind it. Otherwise, the latest turn counts as unsettled while it
298 * is still running (or has not recorded a completion). This is deliberately
299 * keyed on turn lifecycle rather than transient working state: right after the
300 * user sends a message, the previous turn is still the "active" one until the
301 * server creates the new turn, and folding must not flicker through that window.
302 */
303function deriveUnsettledTurnId(
304 latestTurn: TimelineLatestTurn | null,
305 runningTurnId: TurnId | null,
306): TurnId | null {
307 if (runningTurnId !== null) {
308 return runningTurnId;
309 }
310 if (!latestTurn) {
311 return null;
312 }
313 const isSettled = latestTurn.completedAt !== null && latestTurn.state !== "running";
314 return isSettled ? null : latestTurn.turnId;
315}
316
317/**
318 * Settled turns fold their commentary and tool activity behind a
319 * "Worked for ..." row anchored at the turn's first foldable entry; the
320 * terminal assistant message stays visible below the fold.
321 */
322function deriveTurnFolds(input: {
323 timelineEntries: ReadonlyArray<TimelineEntry>;
324 terminalAssistantMessageIds: ReadonlySet<string>;
325 latestTurn: TimelineLatestTurn | null;
326 unsettledTurnId: TurnId | null;
327}): ReadonlyMap<string, TurnFold> {
328 interface TurnGroup {
329 entries: Array<TimelineEntry>;
330 terminalEntry: Extract<TimelineEntry, { kind: "message" }> | null;
331 hasStreamingMessage: boolean;
332 /**
333 * The user message that kicked the turn off. Entry timestamps alone
334 * undercount the duration (the first entry appears only once the
335 * provider starts producing output), and a turn cut short by a steer may
336 * hold a single instantaneous commentary message.
337 */
338 startBoundary: string | null;
339 }
340 const groupsByTurnId = new Map<TurnId, TurnGroup>();
341
342 let pendingUserBoundary: string | null = null;
343 for (const entry of input.timelineEntries) {
344 if (entry.kind === "message" && entry.message.role === "user") {
345 pendingUserBoundary = entry.message.createdAt;
346 continue;
347 }
348 const turnId =
349 entry.kind === "message" && entry.message.role === "assistant"
350 ? (entry.message.turnId ?? null)
351 : entry.kind === "work"
352 ? (entry.entry.turnId ?? null)
353 : null;
354 if (!turnId) {
355 continue;
356 }
357 let group = groupsByTurnId.get(turnId);
358 if (!group) {
359 group = {
360 entries: [],
361 terminalEntry: null,
362 hasStreamingMessage: false,
363 // Each user boundary starts at most one turn; a second turn after the
364 // same user message (e.g. a steer-superseded continuation) falls back
365 // to its own first entry.
366 startBoundary: pendingUserBoundary,
367 };
368 pendingUserBoundary = null;
369 groupsByTurnId.set(turnId, group);
370 }
371 group.entries.push(entry);
372 if (entry.kind === "message") {
373 if (input.terminalAssistantMessageIds.has(entry.message.id)) {
374 group.terminalEntry = entry;
375 }
376 if (entry.message.streaming) {
377 group.hasStreamingMessage = true;
378 }
379 }
380 }
381
382 const foldsByAnchorEntryId = new Map<string, TurnFold>();
383 for (const [turnId, group] of groupsByTurnId) {
384 if (turnId === input.unsettledTurnId) {
385 continue;
386 }
387 if (group.hasStreamingMessage) {
388 continue;
389 }
390 const hiddenEntryIds = new Set<string>();
391 for (const entry of group.entries) {
392 if (entry.id === group.terminalEntry?.id) {
393 continue;
394 }
395 // Agent-spawn CTA rows never fold: workflows outlive their launching
396 // turn (dynamic spawns, background execution), and folding the CTA
397 // when the turn settles makes a still-running fleet invisible.
398 if (entry.kind === "work" && entry.entry.agentSpawn !== undefined) {
399 continue;
400 }
401 hiddenEntryIds.add(entry.id);
402 }
403 if (hiddenEntryIds.size === 0) {
404 continue;
405 }
406
407 const firstEntry = group.entries[0];
408 const lastEntry = group.entries.at(-1);
409 if (!firstEntry || !lastEntry) {
410 continue;
411 }
412
413 const isLatestInterruptedTurn =
414 input.latestTurn?.turnId === turnId && input.latestTurn.state === "interrupted";
415 // A turn cut short by a steer leaves trailing work entries behind its
416 // terminal message — take whichever ended last.
417 const lastEntryEnd =
418 lastEntry.kind === "message" ? lastEntry.message.updatedAt : lastEntry.createdAt;
419 const elapsedMs =
420 input.latestTurn?.turnId === turnId &&
421 input.latestTurn.startedAt &&
422 input.latestTurn.completedAt
423 ? computeElapsedMs(input.latestTurn.startedAt, input.latestTurn.completedAt)
424 : computeElapsedMs(
425 group.startBoundary ?? firstEntry.createdAt,
426 maxIsoTimestamp(group.terminalEntry?.message.updatedAt ?? null, lastEntryEnd) ??
427 lastEntryEnd,
428 );
429 const duration = elapsedMs !== null ? formatDuration(elapsedMs) : null;
430 const label = isLatestInterruptedTurn
431 ? duration
432 ? `You stopped after ${duration}`
433 : "You stopped this response"
434 : duration
435 ? `Worked for ${duration}`
436 : "Worked";
437
438 foldsByAnchorEntryId.set(firstEntry.id, {
439 turnId,
440 anchorEntryId: firstEntry.id,
441 createdAt: firstEntry.createdAt,
442 hiddenEntryIds,
443 label,
444 });
445 }
446 return foldsByAnchorEntryId;
447}
448
449export function deriveMessagesTimelineRows(input: {
450 timelineEntries: ReadonlyArray<TimelineEntry>;
451 latestTurn?: TimelineLatestTurn | null;
452 runningTurnId?: TurnId | null;
453 expandedTurnIds?: ReadonlySet<TurnId>;
454 expandedWorkGroupIds?: ReadonlySet<string>;
455 isWorking: boolean;
456 activeTurnStartedAt: string | null;
457 turnDiffSummaryByAssistantMessageId: ReadonlyMap<MessageId, TurnDiffSummary>;
458 revertTurnCountByUserMessageId: ReadonlyMap<MessageId, number>;
459}): MessagesTimelineRow[] {
460 const nextRows: MessagesTimelineRow[] = [];
461 const durationStartByMessageId = computeMessageDurationStart(
462 input.timelineEntries.flatMap((entry) => (entry.kind === "message" ? [entry.message] : [])),
463 );
464 const terminalAssistantMessageIds = deriveTerminalAssistantMessageIds(input.timelineEntries);
465 const unsettledTurnId = deriveUnsettledTurnId(
466 input.latestTurn ?? null,
467 input.runningTurnId ?? null,
468 );
469 const foldsByAnchorEntryId = deriveTurnFolds({
470 timelineEntries: input.timelineEntries,
471 terminalAssistantMessageIds,
472 latestTurn: input.latestTurn ?? null,
473 unsettledTurnId,
474 });
475 const collapsedEntryIds = new Set<string>();
476 for (const fold of foldsByAnchorEntryId.values()) {
477 if (!input.expandedTurnIds?.has(fold.turnId)) {
478 for (const entryId of fold.hiddenEntryIds) {
479 collapsedEntryIds.add(entryId);
480 }
481 }
482 }
483
484 for (let index = 0; index < input.timelineEntries.length; index += 1) {
485 const timelineEntry = input.timelineEntries[index];
486 if (!timelineEntry) {
487 continue;
488 }
489
490 const turnFold = foldsByAnchorEntryId.get(timelineEntry.id);
491 if (turnFold) {
492 nextRows.push({
493 kind: "turn-fold",
494 id: `turn-fold:${turnFold.turnId}`,
495 createdAt: turnFold.createdAt,
496 turnId: turnFold.turnId,
497 label: turnFold.label,
498 expanded: input.expandedTurnIds?.has(turnFold.turnId) ?? false,
499 });
500 }
501
502 if (collapsedEntryIds.has(timelineEntry.id)) {
503 continue;
504 }
505
506 if (timelineEntry.kind === "work") {
507 const groupedEntries = [timelineEntry.entry];
508 let cursor = index + 1;
509 while (cursor < input.timelineEntries.length) {
510 const nextEntry = input.timelineEntries[cursor];
511 if (
512 !nextEntry ||
513 nextEntry.kind !== "work" ||
514 collapsedEntryIds.has(nextEntry.id) ||
515 foldsByAnchorEntryId.has(nextEntry.id)
516 ) {
517 break;
518 }
519 groupedEntries.push(nextEntry.entry);
520 cursor += 1;
521 }
522 const visibleGroupedEntries = groupedEntries.filter(
523 (entry) => !workEntryIndicatesToolNeutralStatus(entry),
524 );
525 if (visibleGroupedEntries.length > 0) {
526 if (visibleGroupedEntries.length <= MAX_VISIBLE_WORK_LOG_ENTRIES) {
527 nextRows.push({
528 kind: "work",
529 id: timelineEntry.id,
530 createdAt: timelineEntry.createdAt,
531 groupedEntries: visibleGroupedEntries,
532 });
533 } else {
534 const groupId = `work-group:${timelineEntry.id}`;
535 const expanded = input.expandedWorkGroupIds?.has(groupId) ?? false;
536 // Agent-spawn CTA rows are always visible: a running fleet must
537 // never hide behind a "+N tool calls" toggle. Selection is by
538 // membership (spawn OR recent-tail), preserving the group's
539 // chronological order in both collapsed and expanded states
540 // (review finding: concatenating two filtered lists moved a
541 // mid-group spawn row above earlier tool rows).
542 const overflowCandidates = visibleGroupedEntries.filter(
543 (entry) => entry.agentSpawn === undefined,
544 );
545 const hiddenEntries = overflowCandidates.slice(0, -MAX_VISIBLE_WORK_LOG_ENTRIES);
546 const hiddenIds = new Set(hiddenEntries.map((entry) => entry.id));
547 const visibleEntries = visibleGroupedEntries.filter(
548 (entry) => entry.agentSpawn !== undefined || !hiddenIds.has(entry.id),
549 );
550 const renderedEntries = expanded ? visibleGroupedEntries : visibleEntries;
551
552 for (const workEntry of renderedEntries) {
553 nextRows.push({
554 kind: "work",
555 id: workEntry.id,
556 createdAt: workEntry.createdAt,
557 groupedEntries: [workEntry],
558 });
559 }
560
561 if (hiddenEntries.length > 0) {
562 nextRows.push({
563 kind: "work-toggle",
564 id: `work-toggle:${timelineEntry.id}`,
565 createdAt: timelineEntry.createdAt,
566 groupId,
567 hiddenCount: hiddenEntries.length,
568 expanded,
569 onlyToolEntries: visibleGroupedEntries.every((entry) =>
570 workLogEntryIsToolLike(entry),
571 ),
572 });
573 }
574 }
575 }
576 index = cursor - 1;
577 continue;
578 }
579
580 if (timelineEntry.kind === "proposed-plan") {
581 nextRows.push({
582 kind: "proposed-plan",
583 id: timelineEntry.id,
584 createdAt: timelineEntry.createdAt,
585 proposedPlan: timelineEntry.proposedPlan,
586 });
587 continue;
588 }
589
590 if (timelineEntry.kind === "turn-plan") {
591 nextRows.push({
592 kind: "turn-plan",
593 id: timelineEntry.id,
594 createdAt: timelineEntry.createdAt,
595 turnPlan: timelineEntry.turnPlan,
596 });
597 continue;
598 }
599
600 const assistantTurnStillInProgress =
601 timelineEntry.message.role === "assistant" &&
602 unsettledTurnId !== null &&
603 timelineEntry.message.turnId === unsettledTurnId;
604
605 const durationStart =
606 durationStartByMessageId.get(timelineEntry.message.id) ?? timelineEntry.message.createdAt;
607
608 // While the turn is still running, the latest assistant message is only
609 // provisionally terminal — withhold the metadata row until the turn
610 // settles so commentary doesn't flash timestamps mid-work.
611 const showAssistantMeta =
612 timelineEntry.message.role === "assistant" &&
613 terminalAssistantMessageIds.has(timelineEntry.message.id) &&
614 !assistantTurnStillInProgress;
615
616 nextRows.push({
617 kind: "message",
618 id: timelineEntry.id,
619 createdAt: timelineEntry.createdAt,
620 message: timelineEntry.message,
621 durationStart,
622 showAssistantMeta,
623 showAssistantCopyButton: showAssistantMeta,
624 assistantCopyStreaming: timelineEntry.message.streaming || assistantTurnStillInProgress,
625 assistantTurnDiffSummary:
626 timelineEntry.message.role === "assistant"
627 ? input.turnDiffSummaryByAssistantMessageId.get(timelineEntry.message.id)
628 : undefined,
629 revertTurnCount:
630 timelineEntry.message.role === "user"
631 ? input.revertTurnCountByUserMessageId.get(timelineEntry.message.id)
632 : undefined,
633 });
634 }
635
636 if (input.isWorking) {
637 nextRows.push({
638 kind: "working",
639 id: "working-indicator-row",
640 createdAt: input.activeTurnStartedAt,
641 });
642 }
643
644 return nextRows;
645}
646
647export function computeStableMessagesTimelineRows(
648 rows: MessagesTimelineRow[],
649 previous: StableMessagesTimelineRowsState,
650): StableMessagesTimelineRowsState {
651 const next = new Map<string, MessagesTimelineRow>();
652 let anyChanged = rows.length !== previous.byId.size;
653
654 const result = rows.map((row, index) => {
655 const prevRow = previous.byId.get(row.id);
656 const nextRow = prevRow && isRowUnchanged(prevRow, row) ? prevRow : row;
657 next.set(row.id, nextRow);
658 if (!anyChanged && previous.result[index] !== nextRow) {
659 anyChanged = true;
660 }
661 return nextRow;
662 });
663
664 return anyChanged ? { byId: next, result } : previous;
665}
666
667/** Shallow field comparison per row variant — avoids deep equality cost. */
668function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean {
669 if (a.kind !== b.kind || a.id !== b.id) return false;
670
671 switch (a.kind) {
672 case "working":
673 return a.createdAt === (b as typeof a).createdAt;
674
675 case "turn-fold": {
676 const bf = b as typeof a;
677 return a.createdAt === bf.createdAt && a.label === bf.label && a.expanded === bf.expanded;
678 }
679
680 case "proposed-plan":
681 return a.proposedPlan === (b as typeof a).proposedPlan;
682
683 case "turn-plan": {
684 const bp = b as typeof a;
685 // Plans rewrite in place: compare the snapshot's identity fields so an
686 // unchanged plan keeps its row reference (virtualization stability).
687 return a.createdAt === bp.createdAt && a.turnPlan.plan === bp.turnPlan.plan;
688 }
689
690 case "work":
691 return Equal.equals(a.groupedEntries, (b as typeof a).groupedEntries);
692
693 case "work-toggle": {
694 const bw = b as typeof a;
695 return (
696 a.createdAt === bw.createdAt &&
697 a.groupId === bw.groupId &&
698 a.hiddenCount === bw.hiddenCount &&
699 a.expanded === bw.expanded &&
700 a.onlyToolEntries === bw.onlyToolEntries
701 );
702 }
703
704 case "message": {
705 const bm = b as typeof a;
706 return (
707 a.message === bm.message &&
708 a.durationStart === bm.durationStart &&
709 a.showAssistantMeta === bm.showAssistantMeta &&
710 a.showAssistantCopyButton === bm.showAssistantCopyButton &&
711 a.assistantCopyStreaming === bm.assistantCopyStreaming &&
712 a.assistantTurnDiffSummary === bm.assistantTurnDiffSummary &&
713 a.revertTurnCount === bm.revertTurnCount
714 );
715 }
716 }
717}