Skip to content
TypeScript

refactor(web): timeline work entry rows and tool icons live in their own files (#22674)

Julius Marmingebea879025deb
diff --git a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
index df846a5e7bf..ddf8d87049f 100644
--- a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+++ b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
@@ -6,7 +6,8 @@ import { describe, expect, it, vi } from "vite-plus/test";
import "~/index.css";
import { act, render } from "../../../test/render";
-import { MessagesTimeline, remarkThoughtPreview } from "./MessagesTimeline";
+import { MessagesTimeline } from "./MessagesTimeline";
+import { remarkThoughtPreview } from "./TimelineWorkEntryRow.logic";
import { parseMarkdownWithMath } from "@t3tools/shared/markdownMath";
const pullRequestQuery = vi.hoisted(() => ({ error: "Pull request not found" }));
diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx
index bb7f613602f..2bcd94805f2 100644
--- a/apps/web/src/components/chat/MessagesTimeline.tsx
+++ b/apps/web/src/components/chat/MessagesTimeline.tsx
@@ -1,31 +1,27 @@
import { useRenderedAppearance } from "../../hooks/useTheme";
-import type { Root, RootContent } from "mdast";
import { ThreadFindTimelineContext } from "./ThreadFindProvider";
import { shallow } from "zustand/vanilla/shallow";
import { shouldPreserveAssistantLineBreaks } from "@t3tools/shared/markdownPipeline";
import { MarkdownFindContext, findRevealRef } from "./markdownFindContext";
import { useChatCanvas } from "./ChatCanvasContext";
-import { WorkLogBlock, WorkLogButton, WorkLogDetails, WorkLogList, WorkLogRow } from "./WorkLog";
+import { WorkLogBlock, WorkLogButton, WorkLogList, WorkLogRow } from "./WorkLog";
import { PullRequestGlyph } from "../pullRequest/pullRequestIcons";
import type { WorktreeSetupSnapshot } from "@t3tools/contracts";
import { ReadOnlySourcePreview } from "../files/AttachmentFilePreview";
import { useRightPanelStore } from "~/rightPanelStore";
import {
getQuestionAnswerPreview,
- getQuestionAnswerText,
getQuestionTextPreview,
hasQuestionAnswer,
} from "@t3tools/client-runtime/work-log/user-input";
import { deriveTimelineMinimapItems } from "./timelineMinimapItems";
import {
COMPOSER_CONTEXT_KINDS,
- ORCHESTRATION_V2_WORKSPACE_PREPARATION_FAILURE_CODE,
type AssistantCitation,
type EnvironmentId,
type MessageId,
type OrchestrationV2TurnItem,
type RunAttemptId,
- type ScopedThreadRef,
type ServerProviderSkill,
type RunId,
ThreadId,
@@ -37,19 +33,9 @@ import { environmentThreadDetails } from "../../state/threads";
import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message";
import { Link } from "@tanstack/react-router";
import { canForkProjectedAssistantItem } from "@t3tools/client-runtime/state/thread-workflows";
-import { notificationChildThreadId } from "@t3tools/client-runtime/state/thread-execution";
import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
-import {
- liveThoughtLine,
- resolveWorkEntryToolPresentation,
- resolveViewedImageAsset,
- workEntryViewedImagePath,
-} from "@t3tools/client-runtime/work-log/presentation";
+import { liveThoughtLine } from "@t3tools/client-runtime/work-log/presentation";
import { resolveWorkGroupScrollAnchor } from "@t3tools/client-runtime/work-log/scroll-anchor";
-import {
- turnItemHasDetail,
- turnItemNeedsDetailFetch,
-} from "@t3tools/client-runtime/work-log/item-detail";
import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
import {
subagentGroupSummary,
@@ -63,13 +49,9 @@ const NOOP_USE_ARTIFACT_TEMPLATE = () => {};
const NOOP_OPEN_ATTACHMENT = (_attachment: ChatFileAttachment) => {};
import { resolveChatListAnchoredEndSpace } from "@t3tools/shared/chatList";
-import { toolActivityFaviconUrl } from "@t3tools/shared/favicon";
import { formatDuration } from "@t3tools/shared/orchestrationTiming";
-import { getProjectFaviconCacheKey } from "@t3tools/shared/projectFavicon";
-import { claudeSkillInvocation, isJavaScriptReplTool } from "@t3tools/shared/toolActivity";
import { observeVisibleAnimation } from "../../lib/visibleAnimation";
import {
- createContext,
memo,
use,
useContext,
@@ -77,8 +59,6 @@ import {
useLayoutEffect,
useRef,
useState,
- type KeyboardEvent,
- type MouseEvent,
type ReactNode,
} from "react";
import {
@@ -94,8 +74,6 @@ import {
createMessageAttachmentPreviewProjector,
selectMessageImageResources,
workEntryDisplayIndicatesToolFailure,
- workEntrySignalsSevereFailure,
- workLogEntryIsToolLike,
} from "../../session-logic";
import type { CodexArtifactTemplate } from "@t3tools/shared/codexArtifactTemplates";
import {
@@ -113,21 +91,17 @@ import {
resolveFileDiffPath,
} from "../../lib/diffRendering";
import { PREFERRED_HIGHLIGHTER } from "../../lib/syntaxHighlighting";
-import ChatMarkdown, { ChatMarkdownAssetImage } from "../ChatMarkdown";
-import { T3Wordmark } from "../T3Wordmark";
+import ChatMarkdown from "../ChatMarkdown";
import { ThreadContextChip } from "../ThreadContextChip";
import {
ArrowRightIcon,
BotIcon,
- BrainIcon,
CheckIcon,
ChevronDownIcon,
- ChevronRightIcon,
CircleAlertIcon,
DownloadIcon,
EyeIcon,
GitForkIcon,
- GlobeIcon,
type LucideIcon,
MessageCircleIcon,
MousePointerClickIcon,
@@ -135,17 +109,10 @@ import {
MinusIcon,
Redo2Icon,
Minimize2Icon,
- SearchIcon,
- SmartphoneIcon,
- SquarePenIcon,
- TerminalIcon,
Undo2Icon,
- HammerIcon,
WrenchIcon,
- Code2Icon,
XIcon,
ZapIcon,
- RotateCcwIcon,
} from "lucide-react";
import { ChevronDown, ChevronRight, Link as LinkIconNode } from "lucide";
import type {
@@ -188,11 +155,7 @@ import { PierreEntryIcon } from "./PierreEntryIcon";
import { WorkspaceEntryIcon, WorkspaceEntryTooltip } from "./WorkspaceEntryIcon";
import { AssistantSelectionToolbar } from "./AssistantSelectionToolbar";
import type { AssistantCitationSourceAnchor } from "~/lib/assistantTextSelection";
-import {
- AssistantCitationSource,
- type AssistantCitationRequest,
- type AssistantCitationTarget,
-} from "./AssistantCitationSource";
+import { AssistantCitationSource, type AssistantCitationRequest } from "./AssistantCitationSource";
import { useAssistantCitationTarget, type CitationHistoryPage } from "./useAssistantCitationTarget";
import {
computeStableMessagesTimelineRows,
@@ -210,18 +173,11 @@ import {
shouldCollapseUserMessage,
shouldFollowWorkGroupAppend,
timelineTurnFoldRunIdsByEntryId,
- threadReadLabelPrefix,
- threadReadTargetId,
- threadReadTargetTitle,
- toolGroupAction,
- workEntryDisplayLabel,
- workEntryReadOutput,
workEntryIsVisibleInGroup,
worktreeSetupAgentStarted,
type StableMessagesTimelineRowsState,
type MessagesTimelineRow,
type TimelineLatestRun,
- type WorkGroupScrollAnchor,
} from "./MessagesTimeline.logic";
import { type ThreadFindMatch } from "./threadFind";
import { useThreadFindNavigation } from "./useThreadFindNavigation";
@@ -269,19 +225,14 @@ import { useMediaQuery } from "~/hooks/useMediaQuery";
import { cn } from "~/lib/utils";
import { useUiStateStore } from "~/uiStateStore";
import { type TimestampFormat } from "@t3tools/contracts/settings";
-import {
- formatChatTimestampTooltip,
- formatDayAwareTimestamp,
- formatUpcomingTimestamp,
-} from "../../timestampFormat";
-import { FetchedToolOutput, V2ItemInspector } from "./V2ItemInspector";
+import { formatChatTimestampTooltip, formatDayAwareTimestamp } from "../../timestampFormat";
+import { V2ItemInspector } from "./V2ItemInspector";
import { useV2ItemSupport } from "../../state/v2ItemSupport";
import { Collapsible, CollapsibleTrigger, CollapsiblePanel } from "../ui/collapsible";
import {
isV2LifecycleItem,
EnvironmentSubagentAvatar,
SubagentElapsed,
- SubagentNotificationLink,
V2LifecycleRow,
type HandoffTimelineRun,
} from "./V2LifecycleRow";
@@ -299,76 +250,41 @@ import {
type ReviewCommentContext,
} from "../../reviewCommentContext";
import { TimelineMinimap } from "./TimelineMinimap";
+import {
+ type TimelineRowSharedState,
+ type TimelineRowActivityState,
+ TimelineRowCtx,
+ TimelineRowActivityCtx,
+ type WorkGroupViewState,
+ WorkGroupViewCtx,
+ type TimelineWorkEntry,
+ type TimelineRow,
+} from "./timelineRowContext";
+import {
+ MESSAGE_HEADING_LEVEL,
+ MessageAuthorHeading,
+ TimelineRowTimestamp,
+ ActivityShimmerOverlay,
+} from "./TimelineRowParts";
+import {
+ failedToolIconClassName,
+ toolIconAcceptsTint,
+ type WorkEntryIconName,
+ ToolActivityIconView,
+} from "./TimelineToolActivityIcon";
+import {
+ useThreadReadTarget,
+ threadReadLabel,
+ ThreadReadLabel,
+ ReasoningTraceContent,
+ SimpleWorkEntryRow,
+} from "./TimelineWorkEntryRow";
+import {
+ remarkThoughtPreview,
+ toolGroupSummaryIconName,
+ workEntryIconName,
+} from "./TimelineWorkEntryRow.logic";
-interface TimelineRowSharedState {
- citationRequest: AssistantCitationTarget | null;
- listRef: React.RefObject<LegendListRef | null>;
- timestampFormat: TimestampFormat;
- routeThreadKey: string;
- threadRef: ScopedThreadRef | null;
- markdownCwd: string | undefined;
- resolvedTheme: "light" | "dark";
- workspaceRoot: string | undefined;
- skills: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>;
- runs: ReadonlyArray<HandoffTimelineRun>;
- activeThreadEnvironmentId: EnvironmentId;
- onRevertToTurnCount: (targetTurnCount: number, messageId: MessageId) => void;
- onUseArtifactTemplate: (template: CodexArtifactTemplate) => void;
- onSendAppMessage: ((text: string) => Promise<void>) | undefined;
- onAppFullscreenChange: (rowId: string, fullscreen: boolean) => void;
- onRunShellCommand: ((command: string) => void) | undefined;
- findActive: boolean;
- onImageExpand: (preview: ExpandedImagePreview) => void;
- displayThreadKey?: string;
- onOpenTurnDiff: (runId: RunId, filePath?: string) => void;
- onOpenThread: (threadId: OrchestrationV2TurnItem["threadId"]) => void;
- workflowOpening: WorkflowOpening | null;
- onForkFromRun: (input: {
- readonly sourceThreadId: ThreadId;
- readonly runId: RunId;
- }) => Promise<void>;
- onRollbackCheckpoint: (input: {
- readonly checkpointId: string;
- readonly scopeId: string;
- }) => void;
- onToggleTurnFold: (runId: RunId) => void;
- onToggleAttemptFold: (attemptId: RunAttemptId) => void;
- onFileOpen: (attachment: ChatFileAttachment) => void;
- onFileDownload: (attachment: ChatFileAttachment) => void;
- openPullRequest: (event: MouseEvent<HTMLElement>, url: string) => void;
- onToggleWorkGroup: (groupId: string, anchorKey: string) => void;
- onToggleWorkEntry: (anchorKey: string, collapsed: boolean) => void;
- onCancelWorktreeSetup: (() => void) | null;
- retryableWorkspacePreparationRunIds: ReadonlySet<RunId>;
- onRetryWorkspacePreparation: ((runId: RunId) => void) | null;
- onWorktreeSetupWorkLocally: (() => void) | null;
- onOpenWorktreeSetupTerminal: ((terminalId: string) => void) | null;
- workGroupViewState: WorkGroupViewState;
-}
-
-interface TimelineRowActivityState {
- isWorking: boolean;
- isCompacting: boolean;
- isRevertingCheckpoint: boolean;
- activeTurnInProgress: boolean;
- awaitingUser: boolean;
- isPreparingWorktree: boolean;
- latestRunId: RunId | null;
- backgroundWorktreeSetup: WorktreeSetupSnapshot | null;
-}
-
-const TimelineRowCtx = createContext<TimelineRowSharedState>(null!);
-const TimelineRowActivityCtx = createContext<TimelineRowActivityState>(null!);
-
-interface WorkGroupViewState {
- scrollPositions: Map<string, WorkGroupScrollAnchor>;
- expandedEntries: Set<string>;
-}
-
-const WorkGroupViewCtx = createContext<{
- state: WorkGroupViewState;
- onToggleEntry: (collapsed: boolean) => void;
-} | null>(null);
function timelineListStateFor(identity: string): {
readonly identity: string;
readonly rememberedPosition: RememberedTimelinePosition | undefined;
@@ -1620,9 +1536,6 @@ function getItemType(item: MessagesTimelineRow) {
return `message:${item.message.role}:${lengthBucket}`;
}
-type TimelineWorkEntry = Extract<MessagesTimelineRow, { kind: "work" }>["groupedEntries"][number];
-type TimelineRow = MessagesTimelineRow;
-
const TimelineRowContent = memo(function TimelineRowContent({ row }: { row: TimelineRow }) {
const isExpandedToolGroup = row.kind === "work" && row.isExpandedToolGroup;
const isSubagentGroup = row.kind === "event" && row.projectedItem.item.type === "subagent";
@@ -1810,12 +1723,6 @@ function UserVideoAttachment({ file }: { readonly file: ChatFileAttachment }) {
);
}
-const MESSAGE_HEADING_LEVEL = 3;
-
-function MessageAuthorHeading({ children }: { children: string }) {
- return <h3 className="sr-only select-none">{children}</h3>;
-}
-
function UserMessageRow({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
const ctx = use(TimelineRowCtx);
return ctx.workflowOpening?.messageId === row.message.id ? (
@@ -2253,37 +2160,6 @@ function RevertUserMessageButton({
);
}
-function TimelineRowTimestamp({
- createdAt,
- timestampFormat,
- className,
- alwaysVisible = false,
-}: {
- createdAt: string;
- timestampFormat: TimestampFormat;
- className?: string;
- alwaysVisible?: boolean;
-}) {
- return (
- <Tooltip>
- <TooltipTrigger
- render={
- <span
- className={cn(
- "pointer-events-none absolute me-1 shrink-0 whitespace-nowrap rounded-md text-muted-foreground text-xs tabular-nums opacity-0 group-hover/timeline-row:pointer-events-auto group-hover/timeline-row:static group-hover/timeline-row:opacity-100 group-focus-within/timeline-row:pointer-events-auto group-focus-within/timeline-row:static group-focus-within/timeline-row:opacity-100",
- alwaysVisible && "pointer-events-auto static opacity-100",
- className,
- )}
- />
- }
- >
- {formatDayAwareTimestamp(createdAt, timestampFormat)}
- </TooltipTrigger>
- <TooltipPopup>{formatChatTimestampTooltip(createdAt, timestampFormat)}</TooltipPopup>
- </Tooltip>
- );
-}
-
function TurnFoldTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "turn-fold" }> }) {
const ctx = use(TimelineRowCtx);
@@ -3240,25 +3116,6 @@ function ExpandedWorkGroupEntries({
const workEntryKey = (entry: TimelineWorkEntry) => entry.id;
-function ActivityShimmerOverlay({ children }: { children: ReactNode }) {
- return (
- <span
- aria-hidden
- className="live-activity-focus pointer-events-none absolute inset-y-0 select-none"
- >
- <span className="live-activity-focus-counter block">
- <span className="live-activity-focus-aligned block text-foreground">{children}</span>
- </span>
- </span>
- );
-}
-
-const failedToolIconClassName = "text-tool-error-icon/40";
-
-function toolIconAcceptsTint(toolIcon: ToolActivityIcon | undefined): boolean {
- return toolIcon === undefined;
-}
-
function WorkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "working" }> }) {
const { isCompacting, isPreparingWorktree, backgroundWorktreeSetup } =
use(TimelineRowActivityCtx);
@@ -3458,49 +3315,6 @@ function LiveActivityContent({
);
}
-function useThreadReadTarget(entry: TimelineWorkEntry, environmentId: EnvironmentId) {
- const rawThreadId = threadReadTargetId(entry);
- const threadId = rawThreadId === null ? null : ThreadId.make(rawThreadId);
- const shell = useThreadShell(threadId ? scopeThreadRef(environmentId, threadId) : null);
- const title = threadReadTargetTitle(shell);
- return threadId && title ? { threadId, title } : null;
-}
-
-function threadReadLabel(label: string, target: ReturnType<typeof useThreadReadTarget>) {
- const prefix = target && threadReadLabelPrefix(label);
- return prefix ? { ...target, prefix, text: `${prefix} “${target.title}”` } : null;
-}
-
-function ThreadReadLabel({
- label,
- environmentId,
- linked,
-}: {
- label: NonNullable<ReturnType<typeof threadReadLabel>>;
- environmentId: EnvironmentId;
- linked: boolean;
-}) {
- return (
- <span className="flex min-w-0">
- <span className="shrink-0">{label.prefix} “</span>
- {linked ? (
- <Link
- to="/$environmentId/$threadId"
- params={{ environmentId, threadId: label.threadId }}
- className="min-w-0 truncate rounded-sm text-foreground underline-offset-2 hover:underline focus-visible:outline-2 focus-visible:outline-ring"
- onClick={stopRowToggle}
- onKeyDown={stopRowToggle}
- >
- {label.title}
- </Link>
- ) : (
- <span className="min-w-0 truncate">{label.title}</span>
- )}
- <span className="shrink-0">”</span>
- </span>
- );
-}
-
function LiveWorkEntryTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "work-live" }> }) {
const ctx = use(TimelineRowCtx);
const threadTarget = useThreadReadTarget(row.entry, ctx.activeThreadEnvironmentId);
@@ -3597,49 +3411,6 @@ function LiveWorkEntryTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "
);
}
-function toolGroupSummaryIconName(
- kind: Extract<TimelineRow, { kind: "work-toggle" }>["summaryKind"],
-): WorkEntryIconName {
- switch (kind) {
- case "pull-request":
- case "link-pr":
- case "unlink-pr":
- case "list-prs":
- case "watch-pr":
- case "unwatch-pr":
- return "pull-request";
- case "read":
- return "eye";
- case "edit":
- return "square-pen";
- case "command":
- return "terminal";
- case "thread-create":
- return "t3-code";
- case "browser":
- return "browser";
- case "device":
- return "device";
- case "search":
- return "globe";
- case "code-search":
- return "search";
- case "other":
- return "wrench";
- case "dynamic-tool":
- return "hammer";
- case "reasoning":
- return "brain";
- case "agent-tool":
- return "bot";
- case "tone-tool":
- return "zap";
- case "update":
- case "mixed":
- return "hammer";
- }
-}
-
function WorkGroupToggleTimelineRow({
row,
}: {
@@ -4506,936 +4277,3 @@ function useStableRows(rows: MessagesTimelineRow[], identity: string): MessagesT
setState({ identity, source: rows, stable });
return stable.result;
}
-
-type WorkEntryIconName =
- | "bot"
- | "brain"
- | "browser"
- | "check"
- | "circle-alert"
- | "computer"
- | "code"
- | "device"
- | "eye"
- | "globe"
- | "hammer"
- | "message-circle"
- | "search"
- | "square-pen"
- | "terminal"
- | "pull-request"
- | "t3-code"
- | "wrench"
- | "x"
- | "zap";
-
-function BrowserAppIcon({ className }: { className: string }) {
- return (
- <svg
- viewBox="0 0 24 24"
- fill="none"
- stroke="currentColor"
- strokeWidth="1.9"
- strokeLinecap="round"
- strokeLinejoin="round"
- className={className}
- aria-hidden
- >
- <path d="M8.5 19H7.2C4.4 19 3 17.5 3 14.6V7.4C3 4.5 4.5 3 7.4 3h8.2C18.5 3 20 4.5 20 7.4v2.4" />
- <circle cx="7.4" cy="7.2" r="0.75" fill="currentColor" stroke="none" />
- <path d="M11.2 7.2h4.3" />
- <path d="m12.4 11.4 7.5 2.6-3.4 1.6-1.5 3.6z" fill="currentColor" stroke="none" />
- </svg>
- );
-}
-
-function ToolActivityIconView(props: {
- icon: ToolActivityIcon | undefined;
- fallbackName: WorkEntryIconName;
- className: string;
- muted: boolean;
-}) {
- const { resolvedTheme } = use(TimelineRowCtx);
- const fallbackClassName = cn(props.className, props.muted && "opacity-70 light:brightness-60");
- if (!props.icon) {
- return <WorkEntryIcon name={props.fallbackName} className={fallbackClassName} />;
- }
- if (props.icon._tag === "website") {
- const src = toolActivityFaviconUrl(props.icon, resolvedTheme, 32);
- return src ? (
- <ToolActivityImageIcon
- key={src}
- cacheKey={src}
- src={src}
- fallbackName={props.fallbackName}
- className={props.className}
- muted={props.muted}
- />
- ) : (
- <WorkEntryIcon name={props.fallbackName} className={fallbackClassName} />
- );
- }
- if (props.icon._tag === "themed-logo") {
- const src =
- resolvedTheme === "dark"
- ? (props.icon.logoUrlDark ?? props.icon.logoUrl)
- : props.icon.logoUrl;
- return (
- <ToolActivityImageIcon
- key={src}
- cacheKey={src}
- src={src}
- fallbackName={props.fallbackName}
- className={props.className}
- muted={props.muted}
- />
- );
- }
- return (
- <NativeAppToolActivityIcon
- app={props.icon.app}
- fallbackName={props.fallbackName}
- className={cn(props.className, "size-5")}
- muted={props.muted}
- />
- );
-}
-
-function NativeAppToolActivityIcon(props: {
- app: Extract<ToolActivityIcon, { readonly _tag: "native-app" }>["app"];
- fallbackName: WorkEntryIconName;
- className: string;
- muted: boolean;
-}) {
- const { activeThreadEnvironmentId } = use(TimelineRowCtx);
- const asset = useAssetUrlState(activeThreadEnvironmentId, {
- _tag: "native-app-icon",
- app: props.app,
- });
- if (asset._tag !== "Success") {
- return (
- <WorkEntryIcon
- name={props.fallbackName}
- className={cn(props.className, props.muted && "opacity-70 light:brightness-60")}
- />
- );
- }
- const cacheKey = getProjectFaviconCacheKey(
- activeThreadEnvironmentId,
- JSON.stringify(props.app),
- asset.url,
- );
- return (
- <ToolActivityImageIcon
- key={cacheKey}
- cacheKey={cacheKey}
- src={asset.url}
- fallbackName={props.fallbackName}
- className={props.className}
- muted={props.muted}
- />
- );
-}
-
-const loadedToolActivityIconSrcs = new Map<string, string>();
-
-function ToolActivityImageIcon(props: {
- cacheKey: string;
- src: string;
- fallbackName: WorkEntryIconName;
- className: string;
- muted: boolean;
-}) {
- const [displayedSrc, setDisplayedSrc] = useState<string | null>(
- () => loadedToolActivityIconSrcs.get(props.cacheKey) ?? null,
- );
- const isLoading = displayedSrc !== props.src;
- const handleLoadError = (failedSrc: string) => {
- if (loadedToolActivityIconSrcs.get(props.cacheKey) === failedSrc) {
- loadedToolActivityIconSrcs.delete(props.cacheKey);
- }
- setDisplayedSrc((currentSrc) => (currentSrc === failedSrc ? null : currentSrc));
- };
- return (
- <>
- {displayedSrc === null ? (
- <WorkEntryIcon
- name={props.fallbackName}
- className={cn(props.className, props.muted && "opacity-70 light:brightness-60")}
- />
- ) : null}
- {displayedSrc ? (
- <span
- className={cn(
- props.className,
- "inline-block overflow-hidden rounded-xs bg-background",
- props.muted && "opacity-70",
- )}
- >
- <img
- src={displayedSrc}
- alt=""
- aria-hidden
- decoding="async"
- referrerPolicy="no-referrer"
- className={cn("block size-full object-contain", props.muted && "light:brightness-60")}
- onError={() => handleLoadError(displayedSrc)}
- />
- </span>
- ) : null}
- {isLoading ? (
- <img
- src={props.src}
- alt=""
- aria-hidden
- decoding="async"
- referrerPolicy="no-referrer"
- className="hidden"
- onLoad={() => {
- loadedToolActivityIconSrcs.set(props.cacheKey, props.src);
- setDisplayedSrc(props.src);
- }}
- onError={() => handleLoadError(props.src)}
- />
- ) : null}
- </>
- );
-}
-
-function WorkEntryIcon({ name, className }: { name: WorkEntryIconName; className: string }) {
- switch (name) {
- case "pull-request":
- return <PullRequestGlyph.pullRequest className={className} aria-hidden />;
- case "bot":
- return <BotIcon className={className} aria-hidden />;
- case "brain":
- return <BrainIcon className={className} aria-hidden />;
- case "browser":
- case "computer":
- return <BrowserAppIcon className={className} />;
- case "code":
- return <Code2Icon className={className} aria-hidden />;
- case "device":
- return <SmartphoneIcon className={className} aria-hidden />;
- case "t3-code":
- return <T3Wordmark className={className} aria-hidden />;
- case "check":
- return <CheckIcon className={className} aria-hidden />;
- case "circle-alert":
- return <CircleAlertIcon className={className} aria-hidden />;
- case "eye":
- return <EyeIcon className={className} aria-hidden />;
- case "globe":
- return <GlobeIcon className={className} aria-hidden />;
- case "hammer":
- return <HammerIcon className={className} aria-hidden />;
- case "search":
- return <SearchIcon className={className} aria-hidden />;
- case "message-circle":
- return <MessageCircleIcon className={className} aria-hidden />;
- case "square-pen":
- return <SquarePenIcon className={className} aria-hidden />;
- case "terminal":
- return <TerminalIcon className={className} aria-hidden />;
- case "wrench":
- return <WrenchIcon className={className} aria-hidden />;
- case "x":
- return <XIcon className={className} aria-hidden />;
- case "zap":
- return <ZapIcon className={className} aria-hidden />;
- }
-}
-
-function workToneIcon(tone: TimelineWorkEntry["tone"]): {
- iconName: WorkEntryIconName;
- className: string;
-} {
- if (tone === "error") {
- return {
- iconName: "circle-alert",
- className: "text-foreground/92",
- };
- }
- if (tone === "thinking") {
- return {
- iconName: "brain",
- className: "text-icon-muted",
- };
- }
- if (tone === "info") {
- return {
- iconName: "check",
- className: "text-muted-foreground",
- };
- }
- return {
- iconName: "zap",
- className: "text-foreground/92",
- };
-}
-
-function workEntryRawCommand(
- workEntry: Pick<TimelineWorkEntry, "command" | "rawCommand">,
-): string | null {
- const rawCommand = workEntry.rawCommand?.trim();
- if (!rawCommand || !workEntry.command) {
- return null;
- }
- return rawCommand === workEntry.command.trim() ? null : rawCommand;
-}
-
-function buildToolCallExpandedBody(
- workEntry: TimelineWorkEntry,
- workspaceRoot: string | undefined,
- visibleLabel: string,
- viewedImagePath: string | null,
-): string | null {
- const blocks: string[] = [];
- const seen = new Set<string>([visibleLabel.trim()]);
- const addBlock = (value: string | null | undefined) => {
- const text = value?.trim();
- if (!text || seen.has(text)) return;
- seen.add(text);
- blocks.push(text);
- };
- if (workEntry.itemType === "dynamic_tool" && workEntry.toolData !== undefined) {
- const input =
- workEntry.structuredPayload?.type === "dynamic_tool"
- ? workEntry.structuredPayload.input
- : workEntry.toolData !== null &&
- typeof workEntry.toolData === "object" &&
- "input" in workEntry.toolData
- ? workEntry.toolData.input
- : undefined;
- if (input !== undefined) addBlock(`Tool input\n${JSON.stringify(input, null, 2)}`);
- }
- const command = workEntry.command?.trim();
- const raw = workEntryRawCommand(workEntry);
- if (command === visibleLabel.trim()) {
- seen.add(command);
- } else {
- addBlock(raw ?? command);
- }
- const detail = workEntry.detail?.trim();
- if (detail !== viewedImagePath?.trim()) {
- addBlock(detail);
- }
- const viewedImagePaths = new Set(
- viewedImagePath
- ? [viewedImagePath.trim(), formatWorkspaceRelativePath(viewedImagePath, workspaceRoot)]
- : [],
- );
- const changedFiles = (workEntry.changedFiles ?? []).flatMap((filePath) => {
- const formattedPath = formatWorkspaceRelativePath(filePath, workspaceRoot);
- return viewedImagePaths.has(filePath) ||
- viewedImagePaths.has(formattedPath) ||
- filePath.trim() === detail ||
- formattedPath === detail
- ? []
- : [formattedPath];
- });
- if (changedFiles.length > 0) {
- addBlock([...new Set(changedFiles)].join("\n"));
- }
- return blocks.length > 0 ? blocks.join("\n\n") : null;
-}
-
-const toolCallExpandedBodyClassName =
- "max-h-64 cursor-text overflow-auto whitespace-pre-wrap break-words font-mono text-secondary-label text-(length:--font-size-code,var(--text-2xs)) leading-relaxed select-text";
-
-function workEntryIconName(workEntry: TimelineWorkEntry): WorkEntryIconName {
- if (workEntry.structuredPayload?.type === "notification") {
- if (workEntry.structuredPayload.outcome === "failed") return "circle-alert";
- const source = workEntry.structuredPayload.source;
- switch (source.kind) {
- case "subagent":
- case "delegated_task":
- return "bot";
- case "command":
- return "terminal";
- case "monitor":
- return "eye";
- case "background_task":
- return "zap";
- case "system":
- return "t3-code";
- default:
- source satisfies never;
- return "zap";
- }
- }
- if (workEntry.itemType === "user_input_request" || workEntry.itemType === "approval_request") {
- return "message-circle";
- }
- if (workEntry.toolSurface) return workEntry.toolSurface;
- if (
- workEntry.structuredPayload?.type === "dynamic_tool" &&
- isJavaScriptReplTool(workEntry.structuredPayload.toolName)
- )
- return "code";
- const toolPresentation = resolveWorkEntryToolPresentation(workEntry);
- if (toolPresentation) return toolPresentation.icon;
- const action = toolGroupAction(workEntry);
- if (action !== "other") return toolGroupSummaryIconName(action);
-
- switch (workEntry.itemType) {
- case "dynamic_tool":
- return "wrench";
- case "subagent":
- return "bot";
- }
-
- return workToneIcon(workEntry.tone).iconName;
-}
-
-const stopRowToggle = (e: { stopPropagation: () => void }) => e.stopPropagation();
-
-/** Compact reasoning keeps formulas while flattening other Markdown into label text. */
-export function remarkThoughtPreview(fallback: string) {
- return (tree: Root) => {
- const children: RootContent[] = [];
- const append = (value: string) => {
- const last = children.at(-1);
- const text = value.replace(/\s+/g, " ");
- if (last?.type === "text") last.value = (last.value + text).replace(/\s+/g, " ");
- else children.push({ type: "text", value: text });
- };
- const visit = (node: Root | RootContent) => {
- if (node.type === "html" || node.type === "definition") return;
- if (node.type === "math" || node.type === "inlineMath") {
- children.push({
- type: "inlineMath",
- value: node.value,
- position: node.position,
- data: {
- hName: "code",
- hProperties: { className: ["language-math", "math-inline"] },
- hChildren: [{ type: "text", value: node.value }],
- },
- });
- } else if ("alt" in node) append(node.alt ?? "");
- else if ("value" in node) append(node.value);
- else if ("children" in node) {
- node.children.forEach((child, index) => {
- if (
- index &&
- ["root", "blockquote", "list", "listItem", "table", "tableRow"].includes(node.type)
- )
- append(" ");
- visit(child);
- });
- } else if (node.type === "break") append(" ");
- };
- visit(tree);
- const first = children[0];
- const last = children.at(-1);
- if (first?.type === "text") first.value = first.value.trimStart();
- if (last?.type === "text") last.value = last.value.trimEnd();
- tree.children = children.some((child) => child.type !== "text" || child.value)
- ? children
- : [{ type: "text", value: fallback }];
- };
-}
-
-function ReasoningTraceContent({ entries }: { entries: ReadonlyArray<TimelineWorkEntry> }) {
- const ctx = use(TimelineRowCtx);
- const { isWorking, latestRunId } = use(TimelineRowActivityCtx);
- const isStreaming = (entry: TimelineWorkEntry) =>
- isWorking && entry.runId === latestRunId && entry.toolLifecycleStatus === "inProgress";
- return (
- <WorkLogDetails followLive={entries.some(isStreaming)}>
- {entries.map((entry) => (
- <ChatMarkdown
- key={entry.id}
- className="text-foreground"
- text={entry.detail ?? ""}
- cwd={ctx.markdownCwd}
- threadRef={ctx.threadRef ?? undefined}
- skills={ctx.skills}
- isStreaming={isStreaming(entry)}
- headingLevelOffset={MESSAGE_HEADING_LEVEL}
- onUseArtifactTemplate={ctx.onUseArtifactTemplate}
- onImageExpand={ctx.onImageExpand}
- lineBreaks
- />
- ))}
- </WorkLogDetails>
- );
-}
-
-type WorkEntryRowProps = {
- workEntry: TimelineWorkEntry;
- workspaceRoot: string | undefined;
- displayLabel?: string | undefined;
- onToggleEntry?: ((collapsed: boolean) => void) | undefined;
-};
-
-const SimpleWorkEntryRow = memo(function SimpleWorkEntryRow(props: WorkEntryRowProps) {
- const ctx = use(TimelineRowCtx);
- const item = props.workEntry.projectedItem?.item;
- const childThreadId =
- item?.type === "notification" ? notificationChildThreadId(item.source) : undefined;
- if (item?.type !== "notification" || childThreadId === undefined) {
- return <WorkEntryLogRow {...props} />;
- }
- return (
- <SubagentNotificationLink
- parentRef={scopeThreadRef(ctx.activeThreadEnvironmentId, item.threadId)}
- childThreadId={childThreadId}
- outcome={item.outcome}
- createdAt={props.workEntry.createdAt}
- timestampFormat={ctx.timestampFormat}
- onOpenThread={ctx.onOpenThread}
- fallback={<WorkEntryLogRow {...props} />}
- />
- );
-});
-
-function WorkEntryLogRow(props: WorkEntryRowProps) {
- const { workEntry, workspaceRoot, displayLabel } = props;
- const ctx = use(TimelineRowCtx);
- const { threadRef, onImageExpand, timestampFormat } = ctx;
- const { retryableWorkspacePreparationRunIds, onRetryWorkspacePreparation } = ctx;
- const threadTarget = useThreadReadTarget(workEntry, ctx.activeThreadEnvironmentId);
- const createdThread =
- workEntry.projectedItem?.item.type === "thread_created"
- ? workEntry.projectedItem.item
- : undefined;
- const notifiedSubagentThreadId =
- workEntry.projectedItem?.item.type === "notification"
- ? notificationChildThreadId(workEntry.projectedItem.item.source)
- : undefined;
- const groupView = use(WorkGroupViewCtx);
- const [expanded, setExpanded] = useState(
- () => groupView?.state.expandedEntries.has(workEntry.id) ?? false,
- );
- const toggleExpanded = () => {
- const next = !expanded;
- if (groupView) {
- groupView.onToggleEntry(!next);
- if (next) groupView.state.expandedEntries.add(workEntry.id);
- else groupView.state.expandedEntries.delete(workEntry.id);
- } else {
- props.onToggleEntry?.(!next);
- }
- setExpanded(next);
- };
- const failureItem = workEntry.projectedItem?.item;
- if (failureItem?.type === "error" && failureItem.status === "failed") {
- const warning = failureItem.failure.class === "usage_limit";
- const resetAt = failureItem.failure.resetAt;
- const resetTime = resetAt ? formatUpcomingTimestamp(resetAt, timestampFormat) : null;
- const label = warning
- ? `Usage limit reached.${resetTime ? ` Retry after ${resetTime}.` : ""}`
- : workEntry.label;
- const retryRunId =
- failureItem.runId !== null &&
- retryableWorkspacePreparationRunIds.has(failureItem.runId) &&
- failureItem.failure.code === ORCHESTRATION_V2_WORKSPACE_PREPARATION_FAILURE_CODE
- ? failureItem.runId
- : null;
- return (
- <WorkLogRow
- data-v2-item-type="error"
- data-v2-item-visibility={workEntry.projectedItem?.visibility}
- wrapLabel
- icon={
- <CircleAlertIcon
- className={cn("size-4", warning ? "text-warning" : "text-destructive")}
- />
- }
- label={
- <span
- className={cn("text-sm font-medium", warning ? "text-warning" : "text-destructive")}
- >
- {label}
- </span>
- }
- trailing={
- <TimelineRowTimestamp
- createdAt={workEntry.createdAt}
- timestampFormat={timestampFormat}
- alwaysVisible
- />
- }
- >
- {!warning ? (
- <p className="ms-7 whitespace-pre-wrap break-words py-1 text-sm leading-relaxed text-foreground/80">
- {failureItem.failure.message}
- </p>
- ) : null}
- {retryRunId !== null && onRetryWorkspacePreparation ? (
- <div className="ms-7 pb-1">
- <Button
- type="button"
- size="xs"
- variant="outline"
- onClick={() => onRetryWorkspacePreparation(retryRunId)}
- >
- <RotateCcwIcon aria-hidden />
- Retry
- </Button>
- </div>
- ) : null}
- </WorkLogRow>
- );
- }
- const iconConfig = workToneIcon(workEntry.tone);
- const showWarningIndicator = workEntry.sourceActivityKind === "runtime.warning";
- const showFailedIndicator =
- !showWarningIndicator && workEntryDisplayIndicatesToolFailure(workEntry);
- const showDestructiveRowStyle =
- !showWarningIndicator &&
- showFailedIndicator &&
- (workEntrySignalsSevereFailure(workEntry) || !workLogEntryIsToolLike(workEntry));
- const entryIconName =
- showWarningIndicator || showDestructiveRowStyle ? "circle-alert" : workEntryIconName(workEntry);
- const entryToolIcon =
- showWarningIndicator || showDestructiveRowStyle
- ? undefined
- : (workEntry.toolIcon ?? workEntry.toolSource?.icon);
- const isReasoning = workEntry.itemType === "reasoning";
- const questionHeading = workEntry.questionAnswer
- ? getQuestionTextPreview(workEntry.questionAnswer)
- : "";
- const previewText =
- isReasoning && expanded
- ? workEntry.toolLifecycleStatus === "inProgress"
- ? "Thinking"
- : "Thought"
- : questionHeading || (displayLabel ?? workEntryDisplayLabel(workEntry, workspaceRoot));
- const answerPreview =
- workEntry.questionAnswer && hasQuestionAnswer(workEntry.questionAnswer)
- ? getQuestionAnswerPreview(workEntry.questionAnswer)
- : null;
- const viewedImagePath = workEntryViewedImagePath(workEntry);
- const payload = workEntry.structuredPayload;
- const skill =
- payload?.type === "dynamic_tool"
- ? claudeSkillInvocation(payload.toolName, payload.input)
- : undefined;
- const plainOutput =
- toolGroupAction(workEntry) === "read"
- ? workEntryReadOutput(workEntry, workspaceRoot)
- : skill
- ? (skill.args ?? null)
- : undefined;
- const viewedImage =
- viewedImagePath && threadRef
- ? resolveViewedImageAsset(viewedImagePath, {
- threadId: threadRef.threadId,
- workspaceRoot,
- })
- : null;
- const canExpand =
- previewText.trim().length > 0 ||
- (workEntry.itemType === "dynamic_tool" && workEntry.toolData !== undefined) ||
- Boolean(
- workEntryRawCommand(workEntry) ||
- workEntry.command?.trim() ||
- workEntry.detail?.trim() ||
- workEntry.changedFiles?.length ||
- viewedImage,
- );
- const expandedBody =
- expanded && !isReasoning
- ? plainOutput !== undefined
- ? plainOutput
- : buildToolCallExpandedBody(
- workEntry,
- workspaceRoot,
- previewText,
- viewedImage ? viewedImagePath : null,
- )
- : null;
- const plainOutputFetches =
- plainOutput !== undefined &&
- workEntry.projectedItem !== undefined &&
- turnItemNeedsDetailFetch(workEntry.projectedItem.item);
- const canExpandProjectedItem =
- plainOutput !== undefined
- ? Boolean(plainOutput || viewedImage || workEntry.questionAnswer || plainOutputFetches)
- : workEntry.projectedItem === undefined
- ? canExpand
- : isReasoning
- ? Boolean(workEntry.detail?.trim())
- : Boolean(
- viewedImage ||
- workEntry.questionAnswer ||
- turnItemHasDetail(workEntry.projectedItem.item),
- );
- const iconWrapperClass = cn(
- "flex size-4 items-center justify-center",
- showWarningIndicator
- ? "text-warning"
- : showDestructiveRowStyle
- ? "text-destructive"
- : showFailedIndicator
- ? failedToolIconClassName
- : workEntry.tone === "tool"
- ? "text-icon-muted"
- : iconConfig.className,
- );
- const headingClass = showWarningIndicator
- ? "font-medium text-warning"
- : showDestructiveRowStyle
- ? "font-medium text-destructive"
- : workLogEntryIsToolLike(workEntry)
- ? "text-secondary-label"
- : "text-foreground/80";
- const threadLabel = isReasoning ? null : threadReadLabel(previewText, threadTarget);
- const accessiblePreview = [threadLabel?.text ?? previewText, answerPreview]
- .filter(Boolean)
- .join(": ");
- const accessibleDisplayText = showFailedIndicator
- ? `${accessiblePreview}, tool call failed`
- : accessiblePreview;
- const rowToggleProps = canExpandProjectedItem
- ? {
- role: "button" as const,
- tabIndex: 0 as const,
- "aria-label": accessibleDisplayText,
- "aria-expanded": expanded,
- onClick: toggleExpanded,
- onKeyDown: (e: KeyboardEvent<HTMLDivElement>) => {
- if (e.target === e.currentTarget && (e.key === "Enter" || e.key === " ")) {
- e.preventDefault();
- toggleExpanded();
- }
- },
- }
- : {};
-
- return (
- <WorkLogRow
- data-v2-item-type={workEntry.projectedItem?.item.type}
- data-v2-item-visibility={workEntry.projectedItem?.visibility}
- {...rowToggleProps}
- icon={
- <span
- className={iconWrapperClass}
- role={showFailedIndicator ? "img" : undefined}
- aria-label={showFailedIndicator ? "Tool call failed" : undefined}
- >
- <ToolActivityIconView
- icon={entryToolIcon}
- fallbackName={entryIconName}
- className="block size-4 shrink-0 stroke-2"
- muted
- />
- </span>
- }
- label={
- <div className="min-w-0 flex-1 overflow-hidden">
- <p className="flex min-w-0 w-full items-baseline gap-1.5 text-sm leading-relaxed">
- <span
- className={cn(answerPreview ? "min-w-0" : "min-w-0 flex-1", "truncate", headingClass)}
- >
- {isReasoning && !expanded ? (
- <ChatMarkdown
- inline
- text={workEntry.detail ?? previewText}
- cwd={ctx.markdownCwd}
- parseRawHtml={false}
- extraRemarkPlugins={[
- [
- remarkThoughtPreview,
- workEntry.toolLifecycleStatus === "inProgress" ? "Thinking" : "Thought",
- ],
- ]}
- />
- ) : threadLabel ? (
- <ThreadReadLabel
- label={threadLabel}
- environmentId={ctx.activeThreadEnvironmentId}
- linked
- />
- ) : (
- previewText
- )}
- </span>
- {answerPreview ? (
- <span
- className={cn(
- "min-w-0 truncate",
- !expanded &&
- workEntry.questionAnswer &&
- hasQuestionAnswer(workEntry.questionAnswer)
- ? "text-foreground"
- : "text-muted-foreground",
- )}
- >
- {answerPreview}
- </span>
- ) : null}
- </p>
- </div>
- }
- trailing={
- <>
- {createdThread ? (
- <button
- type="button"
- className="shrink-0 rounded-sm text-sm text-primary hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
- aria-label={`Open ${createdThread.title ?? "created thread"}`}
- onClick={(event) => {
- event.stopPropagation();
- ctx.onOpenThread(createdThread.targetThreadId);
- }}
- onKeyDown={stopRowToggle}
- >
- Open chat
- </button>
- ) : null}
- {notifiedSubagentThreadId ? (
- <InlineButton
- aria-label="Open subagent thread"
- onClick={(event) => {
- event.stopPropagation();
- ctx.onOpenThread(notifiedSubagentThreadId);
- }}
- onKeyDown={stopRowToggle}
- >
- Open subagent
- </InlineButton>
- ) : null}
- {showFailedIndicator &&
- !showDestructiveRowStyle &&
- !toolIconAcceptsTint(entryToolIcon) ? (
- <XIcon aria-hidden className={cn("size-3 shrink-0", failedToolIconClassName)} />
- ) : null}
- <TimelineRowTimestamp createdAt={workEntry.createdAt} timestampFormat={timestampFormat} />
- <span
- className={cn(
- "flex size-4 shrink-0 items-center justify-center",
- !canExpandProjectedItem && "invisible",
- )}
- aria-hidden
- >
- <ChevronRightIcon
- className={cn(
- "size-3 shrink-0 text-icon-muted opacity-70 transition-transform duration-200",
- expanded && "rotate-90",
- )}
- />
- </span>
- </>
- }
- >
- {expanded && viewedImage && threadRef ? (
- <WorkLogDetails kind="media">
- <ChatMarkdownAssetImage
- environmentId={threadRef.environmentId}
- resource={viewedImage.resource}
- alt={viewedImage.alt}
- srcFragment={viewedImage.srcFragment}
- workspaceRoot={workspaceRoot}
- maxHeightRem={16}
- onImageExpand={onImageExpand}
- />
- </WorkLogDetails>
- ) : null}
- {expanded && workEntry.questionAnswer ? (
- <QuestionAnswerHistory answer={workEntry.questionAnswer} />
- ) : null}
- {expanded && isReasoning ? <ReasoningTraceContent entries={[workEntry]} /> : null}
- {expanded &&
- !isReasoning &&
- !workEntry.questionAnswer &&
- canExpandProjectedItem &&
- (expandedBody ||
- plainOutputFetches ||
- (workEntry.projectedItem && plainOutput === undefined)) ? (
- <WorkLogDetails kind="panel">
- {workEntry.projectedItem && plainOutput === undefined ? (
- <V2ItemInspector
- projectedItem={workEntry.projectedItem}
- environmentId={ctx.activeThreadEnvironmentId}
- cwd={ctx.markdownCwd}
- workspaceRoot={workspaceRoot}
- onOpenThread={ctx.onOpenThread}
- onOpenTurnDiff={ctx.onOpenTurnDiff}
- onRollbackCheckpoint={ctx.onRollbackCheckpoint}
- onImageExpand={ctx.onImageExpand}
- />
- ) : (
- <>
- {expandedBody ? (
- <pre className={toolCallExpandedBodyClassName}>{expandedBody}</pre>
- ) : null}
- {plainOutputFetches && workEntry.projectedItem ? (
- <FetchedToolOutput
- projectedItem={workEntry.projectedItem}
- environmentId={ctx.activeThreadEnvironmentId}
- onImageExpand={onImageExpand}
- />
- ) : null}
- </>
- )}
- </WorkLogDetails>
- ) : null}
- </WorkLogRow>
- );
-}
-
-function QuestionAnswerHistory({
- answer,
-}: {
- answer: import("@t3tools/contracts").UserInputAttachmentAnswerPayload;
-}) {
- const { activeThreadEnvironmentId } = use(TimelineRowCtx);
- const attachments = Object.values(answer.attachmentsByQuestionId).flat();
- const resources = attachments.map((attachment) => ({
- _tag: "attachment" as const,
- attachmentId: attachment.id,
- }));
- const urls = useAssetUrls(activeThreadEnvironmentId, resources);
- return (
- <div className="ms-7 mt-2 space-y-2" onClick={stopRowToggle}>
- {[
- ...new Set([
- ...Object.keys(answer.questionTextById ?? {}),
- ...Object.keys(answer.answers),
- ...Object.keys(answer.attachmentsByQuestionId),
- ]),
- ].map((questionId) => (
- <div key={questionId} className="space-y-1">
- {answer.questionTextById?.[questionId] ? (
- <p className="whitespace-pre-wrap text-sm text-muted-foreground">
- {answer.questionTextById[questionId]}
- </p>
- ) : null}
- {getQuestionAnswerText(answer.answers[questionId]) ? (
- <p className="ms-3 whitespace-pre-wrap text-sm text-muted-foreground">
- {getQuestionAnswerText(answer.answers[questionId])}
- </p>
- ) : null}
- <div className="flex flex-wrap gap-2">
- {(answer.attachmentsByQuestionId[questionId] ?? []).map((attachment) => {
- const url = urls[attachments.indexOf(attachment)];
- return (
- <a
- key={attachment.id}
- href={url ?? undefined}
- target="_blank"
- rel="noreferrer"
- className="text-sm underline"
- >
- {attachment.type === "image" && url ? (
- <img
- src={url}
- alt={attachment.name}
- className="h-20 max-w-32 rounded object-contain"
- />
- ) : (
- attachment.name
- )}
- </a>
- );
- })}
- </div>
- </div>
- ))}
- </div>
- );
-}
diff --git a/apps/web/src/components/chat/TimelineRowParts.tsx b/apps/web/src/components/chat/TimelineRowParts.tsx
new file mode 100644
index 00000000000..549b9c7a422
--- /dev/null
+++ b/apps/web/src/components/chat/TimelineRowParts.tsx
@@ -0,0 +1,55 @@
+import { type ReactNode } from "react";
+import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
+import { cn } from "~/lib/utils";
+import { type TimestampFormat } from "@t3tools/contracts/settings";
+import { formatChatTimestampTooltip, formatDayAwareTimestamp } from "../../timestampFormat";
+
+export const MESSAGE_HEADING_LEVEL = 3;
+
+export function MessageAuthorHeading({ children }: { children: string }) {
+ return <h3 className="sr-only select-none">{children}</h3>;
+}
+
+export function TimelineRowTimestamp({
+ createdAt,
+ timestampFormat,
+ className,
+ alwaysVisible = false,
+}: {
+ createdAt: string;
+ timestampFormat: TimestampFormat;
+ className?: string;
+ alwaysVisible?: boolean;
+}) {
+ return (
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <span
+ className={cn(
+ "pointer-events-none absolute me-1 shrink-0 whitespace-nowrap rounded-md text-muted-foreground text-xs tabular-nums opacity-0 group-hover/timeline-row:pointer-events-auto group-hover/timeline-row:static group-hover/timeline-row:opacity-100 group-focus-within/timeline-row:pointer-events-auto group-focus-within/timeline-row:static group-focus-within/timeline-row:opacity-100",
+ alwaysVisible && "pointer-events-auto static opacity-100",
+ className,
+ )}
+ />
+ }
+ >
+ {formatDayAwareTimestamp(createdAt, timestampFormat)}
+ </TooltipTrigger>
+ <TooltipPopup>{formatChatTimestampTooltip(createdAt, timestampFormat)}</TooltipPopup>
+ </Tooltip>
+ );
+}
+
+export function ActivityShimmerOverlay({ children }: { children: ReactNode }) {
+ return (
+ <span
+ aria-hidden
+ className="live-activity-focus pointer-events-none absolute inset-y-0 select-none"
+ >
+ <span className="live-activity-focus-counter block">
+ <span className="live-activity-focus-aligned block text-foreground">{children}</span>
+ </span>
+ </span>
+ );
+}
diff --git a/apps/web/src/components/chat/TimelineToolActivityIcon.tsx b/apps/web/src/components/chat/TimelineToolActivityIcon.tsx
new file mode 100644
index 00000000000..8d85ed2eefd
--- /dev/null
+++ b/apps/web/src/components/chat/TimelineToolActivityIcon.tsx
@@ -0,0 +1,272 @@
+import { PullRequestGlyph } from "../pullRequest/pullRequestIcons";
+import { type ToolActivityIcon } from "@t3tools/contracts";
+import { toolActivityFaviconUrl } from "@t3tools/shared/favicon";
+import { getProjectFaviconCacheKey } from "@t3tools/shared/projectFavicon";
+import { use, useState } from "react";
+import { T3Wordmark } from "../T3Wordmark";
+import {
+ BotIcon,
+ BrainIcon,
+ CheckIcon,
+ CircleAlertIcon,
+ EyeIcon,
+ GlobeIcon,
+ MessageCircleIcon,
+ SearchIcon,
+ SmartphoneIcon,
+ SquarePenIcon,
+ TerminalIcon,
+ HammerIcon,
+ WrenchIcon,
+ Code2Icon,
+ XIcon,
+ ZapIcon,
+} from "lucide-react";
+import { useAssetUrlState } from "../../assets/assetUrls";
+import { cn } from "~/lib/utils";
+import { TimelineRowCtx } from "./timelineRowContext";
+
+export const failedToolIconClassName = "text-tool-error-icon/40";
+
+export function toolIconAcceptsTint(toolIcon: ToolActivityIcon | undefined): boolean {
+ return toolIcon === undefined;
+}
+
+export type WorkEntryIconName =
+ | "bot"
+ | "brain"
+ | "browser"
+ | "check"
+ | "circle-alert"
+ | "computer"
+ | "code"
+ | "device"
+ | "eye"
+ | "globe"
+ | "hammer"
+ | "message-circle"
+ | "search"
+ | "square-pen"
+ | "terminal"
+ | "pull-request"
+ | "t3-code"
+ | "wrench"
+ | "x"
+ | "zap";
+
+function BrowserAppIcon({ className }: { className: string }) {
+ return (
+ <svg
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ strokeWidth="1.9"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ className={className}
+ aria-hidden
+ >
+ <path d="M8.5 19H7.2C4.4 19 3 17.5 3 14.6V7.4C3 4.5 4.5 3 7.4 3h8.2C18.5 3 20 4.5 20 7.4v2.4" />
+ <circle cx="7.4" cy="7.2" r="0.75" fill="currentColor" stroke="none" />
+ <path d="M11.2 7.2h4.3" />
+ <path d="m12.4 11.4 7.5 2.6-3.4 1.6-1.5 3.6z" fill="currentColor" stroke="none" />
+ </svg>
+ );
+}
+
+export function ToolActivityIconView(props: {
+ icon: ToolActivityIcon | undefined;
+ fallbackName: WorkEntryIconName;
+ className: string;
+ muted: boolean;
+}) {
+ const { resolvedTheme } = use(TimelineRowCtx);
+ const fallbackClassName = cn(props.className, props.muted && "opacity-70 light:brightness-60");
+ if (!props.icon) {
+ return <WorkEntryIcon name={props.fallbackName} className={fallbackClassName} />;
+ }
+ if (props.icon._tag === "website") {
+ const src = toolActivityFaviconUrl(props.icon, resolvedTheme, 32);
+ return src ? (
+ <ToolActivityImageIcon
+ key={src}
+ cacheKey={src}
+ src={src}
+ fallbackName={props.fallbackName}
+ className={props.className}
+ muted={props.muted}
+ />
+ ) : (
+ <WorkEntryIcon name={props.fallbackName} className={fallbackClassName} />
+ );
+ }
+ if (props.icon._tag === "themed-logo") {
+ const src =
+ resolvedTheme === "dark"
+ ? (props.icon.logoUrlDark ?? props.icon.logoUrl)
+ : props.icon.logoUrl;
+ return (
+ <ToolActivityImageIcon
+ key={src}
+ cacheKey={src}
+ src={src}
+ fallbackName={props.fallbackName}
+ className={props.className}
+ muted={props.muted}
+ />
+ );
+ }
+ return (
+ <NativeAppToolActivityIcon
+ app={props.icon.app}
+ fallbackName={props.fallbackName}
+ className={cn(props.className, "size-5")}
+ muted={props.muted}
+ />
+ );
+}
+
+function NativeAppToolActivityIcon(props: {
+ app: Extract<ToolActivityIcon, { readonly _tag: "native-app" }>["app"];
+ fallbackName: WorkEntryIconName;
+ className: string;
+ muted: boolean;
+}) {
+ const { activeThreadEnvironmentId } = use(TimelineRowCtx);
+ const asset = useAssetUrlState(activeThreadEnvironmentId, {
+ _tag: "native-app-icon",
+ app: props.app,
+ });
+ if (asset._tag !== "Success") {
+ return (
+ <WorkEntryIcon
+ name={props.fallbackName}
+ className={cn(props.className, props.muted && "opacity-70 light:brightness-60")}
+ />
+ );
+ }
+ const cacheKey = getProjectFaviconCacheKey(
+ activeThreadEnvironmentId,
+ JSON.stringify(props.app),
+ asset.url,
+ );
+ return (
+ <ToolActivityImageIcon
+ key={cacheKey}
+ cacheKey={cacheKey}
+ src={asset.url}
+ fallbackName={props.fallbackName}
+ className={props.className}
+ muted={props.muted}
+ />
+ );
+}
+
+const loadedToolActivityIconSrcs = new Map<string, string>();
+
+function ToolActivityImageIcon(props: {
+ cacheKey: string;
+ src: string;
+ fallbackName: WorkEntryIconName;
+ className: string;
+ muted: boolean;
+}) {
+ const [displayedSrc, setDisplayedSrc] = useState<string | null>(
+ () => loadedToolActivityIconSrcs.get(props.cacheKey) ?? null,
+ );
+ const isLoading = displayedSrc !== props.src;
+ const handleLoadError = (failedSrc: string) => {
+ if (loadedToolActivityIconSrcs.get(props.cacheKey) === failedSrc) {
+ loadedToolActivityIconSrcs.delete(props.cacheKey);
+ }
+ setDisplayedSrc((currentSrc) => (currentSrc === failedSrc ? null : currentSrc));
+ };
+ return (
+ <>
+ {displayedSrc === null ? (
+ <WorkEntryIcon
+ name={props.fallbackName}
+ className={cn(props.className, props.muted && "opacity-70 light:brightness-60")}
+ />
+ ) : null}
+ {displayedSrc ? (
+ <span
+ className={cn(
+ props.className,
+ "inline-block overflow-hidden rounded-xs bg-background",
+ props.muted && "opacity-70",
+ )}
+ >
+ <img
+ src={displayedSrc}
+ alt=""
+ aria-hidden
+ decoding="async"
+ referrerPolicy="no-referrer"
+ className={cn("block size-full object-contain", props.muted && "light:brightness-60")}
+ onError={() => handleLoadError(displayedSrc)}
+ />
+ </span>
+ ) : null}
+ {isLoading ? (
+ <img
+ src={props.src}
+ alt=""
+ aria-hidden
+ decoding="async"
+ referrerPolicy="no-referrer"
+ className="hidden"
+ onLoad={() => {
+ loadedToolActivityIconSrcs.set(props.cacheKey, props.src);
+ setDisplayedSrc(props.src);
+ }}
+ onError={() => handleLoadError(props.src)}
+ />
+ ) : null}
+ </>
+ );
+}
+
+function WorkEntryIcon({ name, className }: { name: WorkEntryIconName; className: string }) {
+ switch (name) {
+ case "pull-request":
+ return <PullRequestGlyph.pullRequest className={className} aria-hidden />;
+ case "bot":
+ return <BotIcon className={className} aria-hidden />;
+ case "brain":
+ return <BrainIcon className={className} aria-hidden />;
+ case "browser":
+ case "computer":
+ return <BrowserAppIcon className={className} />;
+ case "code":
+ return <Code2Icon className={className} aria-hidden />;
+ case "device":
+ return <SmartphoneIcon className={className} aria-hidden />;
+ case "t3-code":
+ return <T3Wordmark className={className} aria-hidden />;
+ case "check":
+ return <CheckIcon className={className} aria-hidden />;
+ case "circle-alert":
+ return <CircleAlertIcon className={className} aria-hidden />;
+ case "eye":
+ return <EyeIcon className={className} aria-hidden />;
+ case "globe":
+ return <GlobeIcon className={className} aria-hidden />;
+ case "hammer":
+ return <HammerIcon className={className} aria-hidden />;
+ case "search":
+ return <SearchIcon className={className} aria-hidden />;
+ case "message-circle":
+ return <MessageCircleIcon className={className} aria-hidden />;
+ case "square-pen":
+ return <SquarePenIcon className={className} aria-hidden />;
+ case "terminal":
+ return <TerminalIcon className={className} aria-hidden />;
+ case "wrench":
+ return <WrenchIcon className={className} aria-hidden />;
+ case "x":
+ return <XIcon className={className} aria-hidden />;
+ case "zap":
+ return <ZapIcon className={className} aria-hidden />;
+ }
+}
diff --git a/apps/web/src/components/chat/TimelineWorkEntryRow.logic.ts b/apps/web/src/components/chat/TimelineWorkEntryRow.logic.ts
new file mode 100644
index 00000000000..dc077090e43
--- /dev/null
+++ b/apps/web/src/components/chat/TimelineWorkEntryRow.logic.ts
@@ -0,0 +1,236 @@
+import type { Root, RootContent } from "mdast";
+import { resolveWorkEntryToolPresentation } from "@t3tools/client-runtime/work-log/presentation";
+import { isJavaScriptReplTool } from "@t3tools/shared/toolActivity";
+import { toolGroupAction } from "./MessagesTimeline.logic";
+import { formatWorkspaceRelativePath } from "../../filePathDisplay";
+import { type TimelineWorkEntry, type TimelineRow } from "./timelineRowContext";
+import { type WorkEntryIconName } from "./TimelineToolActivityIcon";
+
+export function toolGroupSummaryIconName(
+ kind: Extract<TimelineRow, { kind: "work-toggle" }>["summaryKind"],
+): WorkEntryIconName {
+ switch (kind) {
+ case "pull-request":
+ case "link-pr":
+ case "unlink-pr":
+ case "list-prs":
+ case "watch-pr":
+ case "unwatch-pr":
+ return "pull-request";
+ case "read":
+ return "eye";
+ case "edit":
+ return "square-pen";
+ case "command":
+ return "terminal";
+ case "thread-create":
+ return "t3-code";
+ case "browser":
+ return "browser";
+ case "device":
+ return "device";
+ case "search":
+ return "globe";
+ case "code-search":
+ return "search";
+ case "other":
+ return "wrench";
+ case "dynamic-tool":
+ return "hammer";
+ case "reasoning":
+ return "brain";
+ case "agent-tool":
+ return "bot";
+ case "tone-tool":
+ return "zap";
+ case "update":
+ case "mixed":
+ return "hammer";
+ }
+}
+
+export function workToneIcon(tone: TimelineWorkEntry["tone"]): {
+ iconName: WorkEntryIconName;
+ className: string;
+} {
+ if (tone === "error") {
+ return {
+ iconName: "circle-alert",
+ className: "text-foreground/92",
+ };
+ }
+ if (tone === "thinking") {
+ return {
+ iconName: "brain",
+ className: "text-icon-muted",
+ };
+ }
+ if (tone === "info") {
+ return {
+ iconName: "check",
+ className: "text-muted-foreground",
+ };
+ }
+ return {
+ iconName: "zap",
+ className: "text-foreground/92",
+ };
+}
+
+export function workEntryRawCommand(
+ workEntry: Pick<TimelineWorkEntry, "command" | "rawCommand">,
+): string | null {
+ const rawCommand = workEntry.rawCommand?.trim();
+ if (!rawCommand || !workEntry.command) {
+ return null;
+ }
+ return rawCommand === workEntry.command.trim() ? null : rawCommand;
+}
+
+export function buildToolCallExpandedBody(
+ workEntry: TimelineWorkEntry,
+ workspaceRoot: string | undefined,
+ visibleLabel: string,
+ viewedImagePath: string | null,
+): string | null {
+ const blocks: string[] = [];
+ const seen = new Set<string>([visibleLabel.trim()]);
+ const addBlock = (value: string | null | undefined) => {
+ const text = value?.trim();
+ if (!text || seen.has(text)) return;
+ seen.add(text);
+ blocks.push(text);
+ };
+ if (workEntry.itemType === "dynamic_tool" && workEntry.toolData !== undefined) {
+ const input =
+ workEntry.structuredPayload?.type === "dynamic_tool"
+ ? workEntry.structuredPayload.input
+ : workEntry.toolData !== null &&
+ typeof workEntry.toolData === "object" &&
+ "input" in workEntry.toolData
+ ? workEntry.toolData.input
+ : undefined;
+ if (input !== undefined) addBlock(`Tool input\n${JSON.stringify(input, null, 2)}`);
+ }
+ const command = workEntry.command?.trim();
+ const raw = workEntryRawCommand(workEntry);
+ if (command === visibleLabel.trim()) {
+ seen.add(command);
+ } else {
+ addBlock(raw ?? command);
+ }
+ const detail = workEntry.detail?.trim();
+ if (detail !== viewedImagePath?.trim()) {
+ addBlock(detail);
+ }
+ const viewedImagePaths = new Set(
+ viewedImagePath
+ ? [viewedImagePath.trim(), formatWorkspaceRelativePath(viewedImagePath, workspaceRoot)]
+ : [],
+ );
+ const changedFiles = (workEntry.changedFiles ?? []).flatMap((filePath) => {
+ const formattedPath = formatWorkspaceRelativePath(filePath, workspaceRoot);
+ return viewedImagePaths.has(filePath) ||
+ viewedImagePaths.has(formattedPath) ||
+ filePath.trim() === detail ||
+ formattedPath === detail
+ ? []
+ : [formattedPath];
+ });
+ if (changedFiles.length > 0) {
+ addBlock([...new Set(changedFiles)].join("\n"));
+ }
+ return blocks.length > 0 ? blocks.join("\n\n") : null;
+}
+
+export function workEntryIconName(workEntry: TimelineWorkEntry): WorkEntryIconName {
+ if (workEntry.structuredPayload?.type === "notification") {
+ if (workEntry.structuredPayload.outcome === "failed") return "circle-alert";
+ const source = workEntry.structuredPayload.source;
+ switch (source.kind) {
+ case "subagent":
+ case "delegated_task":
+ return "bot";
+ case "command":
+ return "terminal";
+ case "monitor":
+ return "eye";
+ case "background_task":
+ return "zap";
+ case "system":
+ return "t3-code";
+ default:
+ source satisfies never;
+ return "zap";
+ }
+ }
+ if (workEntry.itemType === "user_input_request" || workEntry.itemType === "approval_request") {
+ return "message-circle";
+ }
+ if (workEntry.toolSurface) return workEntry.toolSurface;
+ if (
+ workEntry.structuredPayload?.type === "dynamic_tool" &&
+ isJavaScriptReplTool(workEntry.structuredPayload.toolName)
+ )
+ return "code";
+ const toolPresentation = resolveWorkEntryToolPresentation(workEntry);
+ if (toolPresentation) return toolPresentation.icon;
+ const action = toolGroupAction(workEntry);
+ if (action !== "other") return toolGroupSummaryIconName(action);
+
+ switch (workEntry.itemType) {
+ case "dynamic_tool":
+ return "wrench";
+ case "subagent":
+ return "bot";
+ }
+
+ return workToneIcon(workEntry.tone).iconName;
+}
+
+/** Compact reasoning keeps formulas while flattening other Markdown into label text. */
+export function remarkThoughtPreview(fallback: string) {
+ return (tree: Root) => {
+ const children: RootContent[] = [];
+ const append = (value: string) => {
+ const last = children.at(-1);
+ const text = value.replace(/\s+/g, " ");
+ if (last?.type === "text") last.value = (last.value + text).replace(/\s+/g, " ");
+ else children.push({ type: "text", value: text });
+ };
+ const visit = (node: Root | RootContent) => {
+ if (node.type === "html" || node.type === "definition") return;
+ if (node.type === "math" || node.type === "inlineMath") {
+ children.push({
+ type: "inlineMath",
+ value: node.value,
+ position: node.position,
+ data: {
+ hName: "code",
+ hProperties: { className: ["language-math", "math-inline"] },
+ hChildren: [{ type: "text", value: node.value }],
+ },
+ });
+ } else if ("alt" in node) append(node.alt ?? "");
+ else if ("value" in node) append(node.value);
+ else if ("children" in node) {
+ node.children.forEach((child, index) => {
+ if (
+ index &&
+ ["root", "blockquote", "list", "listItem", "table", "tableRow"].includes(node.type)
+ )
+ append(" ");
+ visit(child);
+ });
+ } else if (node.type === "break") append(" ");
+ };
+ visit(tree);
+ const first = children[0];
+ const last = children.at(-1);
+ if (first?.type === "text") first.value = first.value.trimStart();
+ if (last?.type === "text") last.value = last.value.trimEnd();
+ tree.children = children.some((child) => child.type !== "text" || child.value)
+ ? children
+ : [{ type: "text", value: fallback }];
+ };
+}
diff --git a/apps/web/src/components/chat/TimelineWorkEntryRow.tsx b/apps/web/src/components/chat/TimelineWorkEntryRow.tsx
new file mode 100644
index 00000000000..cf72597f43e
--- /dev/null
+++ b/apps/web/src/components/chat/TimelineWorkEntryRow.tsx
@@ -0,0 +1,617 @@
+import { WorkLogDetails, WorkLogRow } from "./WorkLog";
+import {
+ getQuestionAnswerPreview,
+ getQuestionAnswerText,
+ getQuestionTextPreview,
+ hasQuestionAnswer,
+} from "@t3tools/client-runtime/work-log/user-input";
+import {
+ ORCHESTRATION_V2_WORKSPACE_PREPARATION_FAILURE_CODE,
+ type EnvironmentId,
+ ThreadId,
+} from "@t3tools/contracts";
+import { scopeThreadRef } from "@t3tools/client-runtime/environment";
+import { Link } from "@tanstack/react-router";
+import { notificationChildThreadId } from "@t3tools/client-runtime/state/thread-execution";
+import {
+ resolveViewedImageAsset,
+ workEntryViewedImagePath,
+} from "@t3tools/client-runtime/work-log/presentation";
+import {
+ turnItemHasDetail,
+ turnItemNeedsDetailFetch,
+} from "@t3tools/client-runtime/work-log/item-detail";
+import { claudeSkillInvocation } from "@t3tools/shared/toolActivity";
+import { memo, use, useState, type KeyboardEvent } from "react";
+import {
+ workEntryDisplayIndicatesToolFailure,
+ workEntrySignalsSevereFailure,
+ workLogEntryIsToolLike,
+} from "../../session-logic";
+import ChatMarkdown, { ChatMarkdownAssetImage } from "../ChatMarkdown";
+import { ChevronRightIcon, CircleAlertIcon, XIcon, RotateCcwIcon } from "lucide-react";
+import { Button, InlineButton } from "../ui/button";
+import { useAssetUrls } from "../../assets/assetUrls";
+import { useThreadShell } from "../../state/entities";
+import {
+ threadReadLabelPrefix,
+ threadReadTargetId,
+ threadReadTargetTitle,
+ toolGroupAction,
+ workEntryDisplayLabel,
+ workEntryReadOutput,
+} from "./MessagesTimeline.logic";
+import { cn } from "~/lib/utils";
+import { formatUpcomingTimestamp } from "../../timestampFormat";
+import { FetchedToolOutput, V2ItemInspector } from "./V2ItemInspector";
+import { SubagentNotificationLink } from "./V2LifecycleRow";
+import {
+ TimelineRowCtx,
+ TimelineRowActivityCtx,
+ WorkGroupViewCtx,
+ type TimelineWorkEntry,
+} from "./timelineRowContext";
+import { MESSAGE_HEADING_LEVEL, TimelineRowTimestamp } from "./TimelineRowParts";
+import {
+ failedToolIconClassName,
+ toolIconAcceptsTint,
+ ToolActivityIconView,
+} from "./TimelineToolActivityIcon";
+import {
+ workToneIcon,
+ workEntryRawCommand,
+ buildToolCallExpandedBody,
+ workEntryIconName,
+ remarkThoughtPreview,
+} from "./TimelineWorkEntryRow.logic";
+
+export function useThreadReadTarget(entry: TimelineWorkEntry, environmentId: EnvironmentId) {
+ const rawThreadId = threadReadTargetId(entry);
+ const threadId = rawThreadId === null ? null : ThreadId.make(rawThreadId);
+ const shell = useThreadShell(threadId ? scopeThreadRef(environmentId, threadId) : null);
+ const title = threadReadTargetTitle(shell);
+ return threadId && title ? { threadId, title } : null;
+}
+
+export function threadReadLabel(label: string, target: ReturnType<typeof useThreadReadTarget>) {
+ const prefix = target && threadReadLabelPrefix(label);
+ return prefix ? { ...target, prefix, text: `${prefix} “${target.title}”` } : null;
+}
+
+export function ThreadReadLabel({
+ label,
+ environmentId,
+ linked,
+}: {
+ label: NonNullable<ReturnType<typeof threadReadLabel>>;
+ environmentId: EnvironmentId;
+ linked: boolean;
+}) {
+ return (
+ <span className="flex min-w-0">
+ <span className="shrink-0">{label.prefix} “</span>
+ {linked ? (
+ <Link
+ to="/$environmentId/$threadId"
+ params={{ environmentId, threadId: label.threadId }}
+ className="min-w-0 truncate rounded-sm text-foreground underline-offset-2 hover:underline focus-visible:outline-2 focus-visible:outline-ring"
+ onClick={stopRowToggle}
+ onKeyDown={stopRowToggle}
+ >
+ {label.title}
+ </Link>
+ ) : (
+ <span className="min-w-0 truncate">{label.title}</span>
+ )}
+ <span className="shrink-0">”</span>
+ </span>
+ );
+}
+
+const toolCallExpandedBodyClassName =
+ "max-h-64 cursor-text overflow-auto whitespace-pre-wrap break-words font-mono text-secondary-label text-(length:--font-size-code,var(--text-2xs)) leading-relaxed select-text";
+
+const stopRowToggle = (e: { stopPropagation: () => void }) => e.stopPropagation();
+
+export function ReasoningTraceContent({ entries }: { entries: ReadonlyArray<TimelineWorkEntry> }) {
+ const ctx = use(TimelineRowCtx);
+ const { isWorking, latestRunId } = use(TimelineRowActivityCtx);
+ const isStreaming = (entry: TimelineWorkEntry) =>
+ isWorking && entry.runId === latestRunId && entry.toolLifecycleStatus === "inProgress";
+ return (
+ <WorkLogDetails followLive={entries.some(isStreaming)}>
+ {entries.map((entry) => (
+ <ChatMarkdown
+ key={entry.id}
+ className="text-foreground"
+ text={entry.detail ?? ""}
+ cwd={ctx.markdownCwd}
+ threadRef={ctx.threadRef ?? undefined}
+ skills={ctx.skills}
+ isStreaming={isStreaming(entry)}
+ headingLevelOffset={MESSAGE_HEADING_LEVEL}
+ onUseArtifactTemplate={ctx.onUseArtifactTemplate}
+ onImageExpand={ctx.onImageExpand}
+ lineBreaks
+ />
+ ))}
+ </WorkLogDetails>
+ );
+}
+
+type WorkEntryRowProps = {
+ workEntry: TimelineWorkEntry;
+ workspaceRoot: string | undefined;
+ displayLabel?: string | undefined;
+ onToggleEntry?: ((collapsed: boolean) => void) | undefined;
+};
+
+export const SimpleWorkEntryRow = memo(function SimpleWorkEntryRow(props: WorkEntryRowProps) {
+ const ctx = use(TimelineRowCtx);
+ const item = props.workEntry.projectedItem?.item;
+ const childThreadId =
+ item?.type === "notification" ? notificationChildThreadId(item.source) : undefined;
+ if (item?.type !== "notification" || childThreadId === undefined) {
+ return <WorkEntryLogRow {...props} />;
+ }
+ return (
+ <SubagentNotificationLink
+ parentRef={scopeThreadRef(ctx.activeThreadEnvironmentId, item.threadId)}
+ childThreadId={childThreadId}
+ outcome={item.outcome}
+ createdAt={props.workEntry.createdAt}
+ timestampFormat={ctx.timestampFormat}
+ onOpenThread={ctx.onOpenThread}
+ fallback={<WorkEntryLogRow {...props} />}
+ />
+ );
+});
+
+function WorkEntryLogRow(props: WorkEntryRowProps) {
+ const { workEntry, workspaceRoot, displayLabel } = props;
+ const ctx = use(TimelineRowCtx);
+ const { threadRef, onImageExpand, timestampFormat } = ctx;
+ const { retryableWorkspacePreparationRunIds, onRetryWorkspacePreparation } = ctx;
+ const threadTarget = useThreadReadTarget(workEntry, ctx.activeThreadEnvironmentId);
+ const createdThread =
+ workEntry.projectedItem?.item.type === "thread_created"
+ ? workEntry.projectedItem.item
+ : undefined;
+ const notifiedSubagentThreadId =
+ workEntry.projectedItem?.item.type === "notification"
+ ? notificationChildThreadId(workEntry.projectedItem.item.source)
+ : undefined;
+ const groupView = use(WorkGroupViewCtx);
+ const [expanded, setExpanded] = useState(
+ () => groupView?.state.expandedEntries.has(workEntry.id) ?? false,
+ );
+ const toggleExpanded = () => {
+ const next = !expanded;
+ if (groupView) {
+ groupView.onToggleEntry(!next);
+ if (next) groupView.state.expandedEntries.add(workEntry.id);
+ else groupView.state.expandedEntries.delete(workEntry.id);
+ } else {
+ props.onToggleEntry?.(!next);
+ }
+ setExpanded(next);
+ };
+ const failureItem = workEntry.projectedItem?.item;
+ if (failureItem?.type === "error" && failureItem.status === "failed") {
+ const warning = failureItem.failure.class === "usage_limit";
+ const resetAt = failureItem.failure.resetAt;
+ const resetTime = resetAt ? formatUpcomingTimestamp(resetAt, timestampFormat) : null;
+ const label = warning
+ ? `Usage limit reached.${resetTime ? ` Retry after ${resetTime}.` : ""}`
+ : workEntry.label;
+ const retryRunId =
+ failureItem.runId !== null &&
+ retryableWorkspacePreparationRunIds.has(failureItem.runId) &&
+ failureItem.failure.code === ORCHESTRATION_V2_WORKSPACE_PREPARATION_FAILURE_CODE
+ ? failureItem.runId
+ : null;
+ return (
+ <WorkLogRow
+ data-v2-item-type="error"
+ data-v2-item-visibility={workEntry.projectedItem?.visibility}
+ wrapLabel
+ icon={
+ <CircleAlertIcon
+ className={cn("size-4", warning ? "text-warning" : "text-destructive")}
+ />
+ }
+ label={
+ <span
+ className={cn("text-sm font-medium", warning ? "text-warning" : "text-destructive")}
+ >
+ {label}
+ </span>
+ }
+ trailing={
+ <TimelineRowTimestamp
+ createdAt={workEntry.createdAt}
+ timestampFormat={timestampFormat}
+ alwaysVisible
+ />
+ }
+ >
+ {!warning ? (
+ <p className="ms-7 whitespace-pre-wrap break-words py-1 text-sm leading-relaxed text-foreground/80">
+ {failureItem.failure.message}
+ </p>
+ ) : null}
+ {retryRunId !== null && onRetryWorkspacePreparation ? (
+ <div className="ms-7 pb-1">
+ <Button
+ type="button"
+ size="xs"
+ variant="outline"
+ onClick={() => onRetryWorkspacePreparation(retryRunId)}
+ >
+ <RotateCcwIcon aria-hidden />
+ Retry
+ </Button>
+ </div>
+ ) : null}
+ </WorkLogRow>
+ );
+ }
+ const iconConfig = workToneIcon(workEntry.tone);
+ const showWarningIndicator = workEntry.sourceActivityKind === "runtime.warning";
+ const showFailedIndicator =
+ !showWarningIndicator && workEntryDisplayIndicatesToolFailure(workEntry);
+ const showDestructiveRowStyle =
+ !showWarningIndicator &&
+ showFailedIndicator &&
+ (workEntrySignalsSevereFailure(workEntry) || !workLogEntryIsToolLike(workEntry));
+ const entryIconName =
+ showWarningIndicator || showDestructiveRowStyle ? "circle-alert" : workEntryIconName(workEntry);
+ const entryToolIcon =
+ showWarningIndicator || showDestructiveRowStyle
+ ? undefined
+ : (workEntry.toolIcon ?? workEntry.toolSource?.icon);
+ const isReasoning = workEntry.itemType === "reasoning";
+ const questionHeading = workEntry.questionAnswer
+ ? getQuestionTextPreview(workEntry.questionAnswer)
+ : "";
+ const previewText =
+ isReasoning && expanded
+ ? workEntry.toolLifecycleStatus === "inProgress"
+ ? "Thinking"
+ : "Thought"
+ : questionHeading || (displayLabel ?? workEntryDisplayLabel(workEntry, workspaceRoot));
+ const answerPreview =
+ workEntry.questionAnswer && hasQuestionAnswer(workEntry.questionAnswer)
+ ? getQuestionAnswerPreview(workEntry.questionAnswer)
+ : null;
+ const viewedImagePath = workEntryViewedImagePath(workEntry);
+ const payload = workEntry.structuredPayload;
+ const skill =
+ payload?.type === "dynamic_tool"
+ ? claudeSkillInvocation(payload.toolName, payload.input)
+ : undefined;
+ const plainOutput =
+ toolGroupAction(workEntry) === "read"
+ ? workEntryReadOutput(workEntry, workspaceRoot)
+ : skill
+ ? (skill.args ?? null)
+ : undefined;
+ const viewedImage =
+ viewedImagePath && threadRef
+ ? resolveViewedImageAsset(viewedImagePath, {
+ threadId: threadRef.threadId,
+ workspaceRoot,
+ })
+ : null;
+ const canExpand =
+ previewText.trim().length > 0 ||
+ (workEntry.itemType === "dynamic_tool" && workEntry.toolData !== undefined) ||
+ Boolean(
+ workEntryRawCommand(workEntry) ||
+ workEntry.command?.trim() ||
+ workEntry.detail?.trim() ||
+ workEntry.changedFiles?.length ||
+ viewedImage,
+ );
+ const expandedBody =
+ expanded && !isReasoning
+ ? plainOutput !== undefined
+ ? plainOutput
+ : buildToolCallExpandedBody(
+ workEntry,
+ workspaceRoot,
+ previewText,
+ viewedImage ? viewedImagePath : null,
+ )
+ : null;
+ const plainOutputFetches =
+ plainOutput !== undefined &&
+ workEntry.projectedItem !== undefined &&
+ turnItemNeedsDetailFetch(workEntry.projectedItem.item);
+ const canExpandProjectedItem =
+ plainOutput !== undefined
+ ? Boolean(plainOutput || viewedImage || workEntry.questionAnswer || plainOutputFetches)
+ : workEntry.projectedItem === undefined
+ ? canExpand
+ : isReasoning
+ ? Boolean(workEntry.detail?.trim())
+ : Boolean(
+ viewedImage ||
+ workEntry.questionAnswer ||
+ turnItemHasDetail(workEntry.projectedItem.item),
+ );
+ const iconWrapperClass = cn(
+ "flex size-4 items-center justify-center",
+ showWarningIndicator
+ ? "text-warning"
+ : showDestructiveRowStyle
+ ? "text-destructive"
+ : showFailedIndicator
+ ? failedToolIconClassName
+ : workEntry.tone === "tool"
+ ? "text-icon-muted"
+ : iconConfig.className,
+ );
+ const headingClass = showWarningIndicator
+ ? "font-medium text-warning"
+ : showDestructiveRowStyle
+ ? "font-medium text-destructive"
+ : workLogEntryIsToolLike(workEntry)
+ ? "text-secondary-label"
+ : "text-foreground/80";
+ const threadLabel = isReasoning ? null : threadReadLabel(previewText, threadTarget);
+ const accessiblePreview = [threadLabel?.text ?? previewText, answerPreview]
+ .filter(Boolean)
+ .join(": ");
+ const accessibleDisplayText = showFailedIndicator
+ ? `${accessiblePreview}, tool call failed`
+ : accessiblePreview;
+ const rowToggleProps = canExpandProjectedItem
+ ? {
+ role: "button" as const,
+ tabIndex: 0 as const,
+ "aria-label": accessibleDisplayText,
+ "aria-expanded": expanded,
+ onClick: toggleExpanded,
+ onKeyDown: (e: KeyboardEvent<HTMLDivElement>) => {
+ if (e.target === e.currentTarget && (e.key === "Enter" || e.key === " ")) {
+ e.preventDefault();
+ toggleExpanded();
+ }
+ },
+ }
+ : {};
+
+ return (
+ <WorkLogRow
+ data-v2-item-type={workEntry.projectedItem?.item.type}
+ data-v2-item-visibility={workEntry.projectedItem?.visibility}
+ {...rowToggleProps}
+ icon={
+ <span
+ className={iconWrapperClass}
+ role={showFailedIndicator ? "img" : undefined}
+ aria-label={showFailedIndicator ? "Tool call failed" : undefined}
+ >
+ <ToolActivityIconView
+ icon={entryToolIcon}
+ fallbackName={entryIconName}
+ className="block size-4 shrink-0 stroke-2"
+ muted
+ />
+ </span>
+ }
+ label={
+ <div className="min-w-0 flex-1 overflow-hidden">
+ <p className="flex min-w-0 w-full items-baseline gap-1.5 text-sm leading-relaxed">
+ <span
+ className={cn(answerPreview ? "min-w-0" : "min-w-0 flex-1", "truncate", headingClass)}
+ >
+ {isReasoning && !expanded ? (
+ <ChatMarkdown
+ inline
+ text={workEntry.detail ?? previewText}
+ cwd={ctx.markdownCwd}
+ parseRawHtml={false}
+ extraRemarkPlugins={[
+ [
+ remarkThoughtPreview,
+ workEntry.toolLifecycleStatus === "inProgress" ? "Thinking" : "Thought",
+ ],
+ ]}
+ />
+ ) : threadLabel ? (
+ <ThreadReadLabel
+ label={threadLabel}
+ environmentId={ctx.activeThreadEnvironmentId}
+ linked
+ />
+ ) : (
+ previewText
+ )}
+ </span>
+ {answerPreview ? (
+ <span
+ className={cn(
+ "min-w-0 truncate",
+ !expanded &&
+ workEntry.questionAnswer &&
+ hasQuestionAnswer(workEntry.questionAnswer)
+ ? "text-foreground"
+ : "text-muted-foreground",
+ )}
+ >
+ {answerPreview}
+ </span>
+ ) : null}
+ </p>
+ </div>
+ }
+ trailing={
+ <>
+ {createdThread ? (
+ <button
+ type="button"
+ className="shrink-0 rounded-sm text-sm text-primary hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
+ aria-label={`Open ${createdThread.title ?? "created thread"}`}
+ onClick={(event) => {
+ event.stopPropagation();
+ ctx.onOpenThread(createdThread.targetThreadId);
+ }}
+ onKeyDown={stopRowToggle}
+ >
+ Open chat
+ </button>
+ ) : null}
+ {notifiedSubagentThreadId ? (
+ <InlineButton
+ aria-label="Open subagent thread"
+ onClick={(event) => {
+ event.stopPropagation();
+ ctx.onOpenThread(notifiedSubagentThreadId);
+ }}
+ onKeyDown={stopRowToggle}
+ >
+ Open subagent
+ </InlineButton>
+ ) : null}
+ {showFailedIndicator &&
+ !showDestructiveRowStyle &&
+ !toolIconAcceptsTint(entryToolIcon) ? (
+ <XIcon aria-hidden className={cn("size-3 shrink-0", failedToolIconClassName)} />
+ ) : null}
+ <TimelineRowTimestamp createdAt={workEntry.createdAt} timestampFormat={timestampFormat} />
+ <span
+ className={cn(
+ "flex size-4 shrink-0 items-center justify-center",
+ !canExpandProjectedItem && "invisible",
+ )}
+ aria-hidden
+ >
+ <ChevronRightIcon
+ className={cn(
+ "size-3 shrink-0 text-icon-muted opacity-70 transition-transform duration-200",
+ expanded && "rotate-90",
+ )}
+ />
+ </span>
+ </>
+ }
+ >
+ {expanded && viewedImage && threadRef ? (
+ <WorkLogDetails kind="media">
+ <ChatMarkdownAssetImage
+ environmentId={threadRef.environmentId}
+ resource={viewedImage.resource}
+ alt={viewedImage.alt}
+ srcFragment={viewedImage.srcFragment}
+ workspaceRoot={workspaceRoot}
+ maxHeightRem={16}
+ onImageExpand={onImageExpand}
+ />
+ </WorkLogDetails>
+ ) : null}
+ {expanded && workEntry.questionAnswer ? (
+ <QuestionAnswerHistory answer={workEntry.questionAnswer} />
+ ) : null}
+ {expanded && isReasoning ? <ReasoningTraceContent entries={[workEntry]} /> : null}
+ {expanded &&
+ !isReasoning &&
+ !workEntry.questionAnswer &&
+ canExpandProjectedItem &&
+ (expandedBody ||
+ plainOutputFetches ||
+ (workEntry.projectedItem && plainOutput === undefined)) ? (
+ <WorkLogDetails kind="panel">
+ {workEntry.projectedItem && plainOutput === undefined ? (
+ <V2ItemInspector
+ projectedItem={workEntry.projectedItem}
+ environmentId={ctx.activeThreadEnvironmentId}
+ cwd={ctx.markdownCwd}
+ workspaceRoot={workspaceRoot}
+ onOpenThread={ctx.onOpenThread}
+ onOpenTurnDiff={ctx.onOpenTurnDiff}
+ onRollbackCheckpoint={ctx.onRollbackCheckpoint}
+ onImageExpand={ctx.onImageExpand}
+ />
+ ) : (
+ <>
+ {expandedBody ? (
+ <pre className={toolCallExpandedBodyClassName}>{expandedBody}</pre>
+ ) : null}
+ {plainOutputFetches && workEntry.projectedItem ? (
+ <FetchedToolOutput
+ projectedItem={workEntry.projectedItem}
+ environmentId={ctx.activeThreadEnvironmentId}
+ onImageExpand={onImageExpand}
+ />
+ ) : null}
+ </>
+ )}
+ </WorkLogDetails>
+ ) : null}
+ </WorkLogRow>
+ );
+}
+
+function QuestionAnswerHistory({
+ answer,
+}: {
+ answer: import("@t3tools/contracts").UserInputAttachmentAnswerPayload;
+}) {
+ const { activeThreadEnvironmentId } = use(TimelineRowCtx);
+ const attachments = Object.values(answer.attachmentsByQuestionId).flat();
+ const resources = attachments.map((attachment) => ({
+ _tag: "attachment" as const,
+ attachmentId: attachment.id,
+ }));
+ const urls = useAssetUrls(activeThreadEnvironmentId, resources);
+ return (
+ <div className="ms-7 mt-2 space-y-2" onClick={stopRowToggle}>
+ {[
+ ...new Set([
+ ...Object.keys(answer.questionTextById ?? {}),
+ ...Object.keys(answer.answers),
+ ...Object.keys(answer.attachmentsByQuestionId),
+ ]),
+ ].map((questionId) => (
+ <div key={questionId} className="space-y-1">
+ {answer.questionTextById?.[questionId] ? (
+ <p className="whitespace-pre-wrap text-sm text-muted-foreground">
+ {answer.questionTextById[questionId]}
+ </p>
+ ) : null}
+ {getQuestionAnswerText(answer.answers[questionId]) ? (
+ <p className="ms-3 whitespace-pre-wrap text-sm text-muted-foreground">
+ {getQuestionAnswerText(answer.answers[questionId])}
+ </p>
+ ) : null}
+ <div className="flex flex-wrap gap-2">
+ {(answer.attachmentsByQuestionId[questionId] ?? []).map((attachment) => {
+ const url = urls[attachments.indexOf(attachment)];
+ return (
+ <a
+ key={attachment.id}
+ href={url ?? undefined}
+ target="_blank"
+ rel="noreferrer"
+ className="text-sm underline"
+ >
+ {attachment.type === "image" && url ? (
+ <img
+ src={url}
+ alt={attachment.name}
+ className="h-20 max-w-32 rounded object-contain"
+ />
+ ) : (
+ attachment.name
+ )}
+ </a>
+ );
+ })}
+ </div>
+ </div>
+ ))}
+ </div>
+ );
+}
diff --git a/apps/web/src/components/chat/timelineRowContext.ts b/apps/web/src/components/chat/timelineRowContext.ts
new file mode 100644
index 00000000000..fdfb833ecc6
--- /dev/null
+++ b/apps/web/src/components/chat/timelineRowContext.ts
@@ -0,0 +1,99 @@
+import type { WorktreeSetupSnapshot } from "@t3tools/contracts";
+import {
+ type EnvironmentId,
+ type MessageId,
+ type OrchestrationV2TurnItem,
+ type RunAttemptId,
+ type ScopedThreadRef,
+ type ServerProviderSkill,
+ type RunId,
+ ThreadId,
+} from "@t3tools/contracts";
+import type { WorkflowOpening } from "@t3tools/client-runtime/state/subagentRuntime";
+import { createContext, type MouseEvent } from "react";
+import { type LegendListRef } from "@legendapp/list/react";
+import type { CodexArtifactTemplate } from "@t3tools/shared/codexArtifactTemplates";
+import { type ChatFileAttachment } from "../../types";
+import { ExpandedImagePreview } from "./ExpandedImagePreview";
+import { type AssistantCitationTarget } from "./AssistantCitationSource";
+import { type MessagesTimelineRow, type WorkGroupScrollAnchor } from "./MessagesTimeline.logic";
+import { type TimestampFormat } from "@t3tools/contracts/settings";
+import { type HandoffTimelineRun } from "./V2LifecycleRow";
+
+export interface TimelineRowSharedState {
+ citationRequest: AssistantCitationTarget | null;
+ listRef: React.RefObject<LegendListRef | null>;
+ timestampFormat: TimestampFormat;
+ routeThreadKey: string;
+ threadRef: ScopedThreadRef | null;
+ markdownCwd: string | undefined;
+ resolvedTheme: "light" | "dark";
+ workspaceRoot: string | undefined;
+ skills: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>;
+ runs: ReadonlyArray<HandoffTimelineRun>;
+ activeThreadEnvironmentId: EnvironmentId;
+ onRevertToTurnCount: (targetTurnCount: number, messageId: MessageId) => void;
+ onUseArtifactTemplate: (template: CodexArtifactTemplate) => void;
+ onSendAppMessage: ((text: string) => Promise<void>) | undefined;
+ onAppFullscreenChange: (rowId: string, fullscreen: boolean) => void;
+ onRunShellCommand: ((command: string) => void) | undefined;
+ findActive: boolean;
+ onImageExpand: (preview: ExpandedImagePreview) => void;
+ displayThreadKey?: string;
+ onOpenTurnDiff: (runId: RunId, filePath?: string) => void;
+ onOpenThread: (threadId: OrchestrationV2TurnItem["threadId"]) => void;
+ workflowOpening: WorkflowOpening | null;
+ onForkFromRun: (input: {
+ readonly sourceThreadId: ThreadId;
+ readonly runId: RunId;
+ }) => Promise<void>;
+ onRollbackCheckpoint: (input: {
+ readonly checkpointId: string;
+ readonly scopeId: string;
+ }) => void;
+ onToggleTurnFold: (runId: RunId) => void;
+ onToggleAttemptFold: (attemptId: RunAttemptId) => void;
+ onFileOpen: (attachment: ChatFileAttachment) => void;
+ onFileDownload: (attachment: ChatFileAttachment) => void;
+ openPullRequest: (event: MouseEvent<HTMLElement>, url: string) => void;
+ onToggleWorkGroup: (groupId: string, anchorKey: string) => void;
+ onToggleWorkEntry: (anchorKey: string, collapsed: boolean) => void;
+ onCancelWorktreeSetup: (() => void) | null;
+ retryableWorkspacePreparationRunIds: ReadonlySet<RunId>;
+ onRetryWorkspacePreparation: ((runId: RunId) => void) | null;
+ onWorktreeSetupWorkLocally: (() => void) | null;
+ onOpenWorktreeSetupTerminal: ((terminalId: string) => void) | null;
+ workGroupViewState: WorkGroupViewState;
+}
+
+export interface TimelineRowActivityState {
+ isWorking: boolean;
+ isCompacting: boolean;
+ isRevertingCheckpoint: boolean;
+ activeTurnInProgress: boolean;
+ awaitingUser: boolean;
+ isPreparingWorktree: boolean;
+ latestRunId: RunId | null;
+ backgroundWorktreeSetup: WorktreeSetupSnapshot | null;
+}
+
+export const TimelineRowCtx = createContext<TimelineRowSharedState>(null!);
+
+export const TimelineRowActivityCtx = createContext<TimelineRowActivityState>(null!);
+
+export interface WorkGroupViewState {
+ scrollPositions: Map<string, WorkGroupScrollAnchor>;
+ expandedEntries: Set<string>;
+}
+
+export const WorkGroupViewCtx = createContext<{
+ state: WorkGroupViewState;
+ onToggleEntry: (collapsed: boolean) => void;
+} | null>(null);
+
+export type TimelineWorkEntry = Extract<
+ MessagesTimelineRow,
+ { kind: "work" }
+>["groupedEntries"][number];
+
+export type TimelineRow = MessagesTimelineRow;