@devries-cameron20 / t3code Mirror · read-only / commits / 9e672d0974
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 20:45 UTC

refactor(web): timeline work group and live activity rows live in their own file (#22675)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 21, 2026 at 01:12 UTC 9e672d0974640171c8576468d2db93d2f2975a58
3 files changed +667 -633
apps/web/src/components/chat/MessagesTimeline.tsx
+7 -633
@@ -4,16 +4,11 @@ import { shallow } from "zustand/vanilla/shallow";
4 import { shouldPreserveAssistantLineBreaks } from "@t3tools/shared/markdownPipeline";
5 import { MarkdownFindContext, findRevealRef } from "./markdownFindContext";
6 import { useChatCanvas } from "./ChatCanvasContext";
7 -import { WorkLogBlock, WorkLogButton, WorkLogList, WorkLogRow } from "./WorkLog";
7 +import { WorkLogBlock } from "./WorkLog";
8 import { PullRequestGlyph } from "../pullRequest/pullRequestIcons";
9 import type { WorktreeSetupSnapshot } from "@t3tools/contracts";
10 import { ReadOnlySourcePreview } from "../files/AttachmentFilePreview";
11 import { useRightPanelStore } from "~/rightPanelStore";
12 -import {
13 - getQuestionAnswerPreview,
14 - getQuestionTextPreview,
15 - hasQuestionAnswer,
16 -} from "@t3tools/client-runtime/work-log/user-input";
12 import { deriveTimelineMinimapItems } from "./timelineMinimapItems";
13 import {
14 COMPOSER_CONTEXT_KINDS,
@@ -25,7 +20,6 @@ import {
20 type ServerProviderSkill,
21 type RunId,
22 ThreadId,
28 - type ToolActivityIcon,
23 } from "@t3tools/contracts";
24 import { parseScopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment";
25 import { useAtomValue } from "@effect/atom-react";
@@ -34,7 +28,6 @@ import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-mes
28 import { Link } from "@tanstack/react-router";
29 import { canForkProjectedAssistantItem } from "@t3tools/client-runtime/state/thread-workflows";
30 import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
37 -import { liveThoughtLine } from "@t3tools/client-runtime/work-log/presentation";
31 import { resolveWorkGroupScrollAnchor } from "@t3tools/client-runtime/work-log/scroll-anchor";
32 import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
33 import {
@@ -49,7 +42,6 @@ const NOOP_USE_ARTIFACT_TEMPLATE = () => {};
42 const NOOP_OPEN_ATTACHMENT = (_attachment: ChatFileAttachment) => {};
43
44 import { resolveChatListAnchoredEndSpace } from "@t3tools/shared/chatList";
52 -import { formatDuration } from "@t3tools/shared/orchestrationTiming";
45 import { observeVisibleAnimation } from "../../lib/visibleAnimation";
46 import {
47 memo,
@@ -73,7 +65,6 @@ import {
65 providerErrorPresentation,
66 createMessageAttachmentPreviewProjector,
67 selectMessageImageResources,
76 - workEntryDisplayIndicatesToolFailure,
68 } from "../../session-logic";
69 import type { CodexArtifactTemplate } from "@t3tools/shared/codexArtifactTemplates";
70 import {
@@ -125,7 +116,6 @@ import { MorphIcon } from "~/components/MorphIcon";
116 import { useAssetUrlRefresh, useAssetUrls, useAssetUrlState } from "../../assets/assetUrls";
117 import { AttachmentImage } from "../media/AttachmentImage";
118 import { MediaVideoPlayer } from "../media/MediaVideoPlayer";
128 -import { getVirtualizedScrollFadeClassName } from "../ui/scroll-area";
119 import {
120 buildAttachmentVideoAsset,
121 buildAttachmentVideoPreview,
@@ -161,7 +151,6 @@ import {
151 computeStableMessagesTimelineRows,
152 deriveMessagesTimelineRowsWithState,
153 type MessagesTimelineRowsProjection,
164 - liveWorkEntryLabel,
154 resolveAssistantMessageCopyState,
155 resolveTimelineIsAtEnd,
156 resolveTimelineMinimapHasPersistentGutter,
@@ -169,11 +158,8 @@ import {
158 isTimelineMinimapRowVisible,
159 resolveTimelineMinimapVisibleRange,
160 resolveTimelineMinimapHitStripWidth,
172 - resolveWorkGroupScrollIndex,
161 shouldCollapseUserMessage,
174 - shouldFollowWorkGroupAppend,
162 timelineTurnFoldRunIdsByEntryId,
176 - workEntryIsVisibleInGroup,
163 worktreeSetupAgentStarted,
164 type StableMessagesTimelineRowsState,
165 type MessagesTimelineRow,
@@ -184,8 +170,6 @@ import { useThreadFindNavigation } from "./useThreadFindNavigation";
170 import { readThreadFindPosition } from "./threadFindPosition";
171 import type { ThreadFindPositionReader } from "./threadFind";
172 import { TerminalContextInlineChip } from "./TerminalContextInlineChip";
187 -import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
188 -import { Spinner } from "../ui/spinner";
173 import { Tooltip, TooltipPopup, TooltipTrigger, TooltipScrollDismissArea } from "../ui/tooltip";
174 import { WorktreeSetupCard } from "./WorktreeSetupCard";
175 import {
@@ -256,8 +240,6 @@ import {
240 TimelineRowCtx,
241 TimelineRowActivityCtx,
242 type WorkGroupViewState,
259 - WorkGroupViewCtx,
260 - type TimelineWorkEntry,
243 type TimelineRow,
244 } from "./timelineRowContext";
245 import {
@@ -267,23 +249,12 @@ import {
249 ActivityShimmerOverlay,
250 } from "./TimelineRowParts";
251 import {
270 - failedToolIconClassName,
271 - toolIconAcceptsTint,
272 - type WorkEntryIconName,
273 - ToolActivityIconView,
274 -} from "./TimelineToolActivityIcon";
275 -import {
276 - useThreadReadTarget,
277 - threadReadLabel,
278 - ThreadReadLabel,
279 - ReasoningTraceContent,
280 - SimpleWorkEntryRow,
281 -} from "./TimelineWorkEntryRow";
282 -import {
283 - remarkThoughtPreview,
284 - toolGroupSummaryIconName,
285 - workEntryIconName,
286 -} from "./TimelineWorkEntryRow.logic";
252 + WorkGroupSection,
253 + WorkingTimelineRow,
254 + ThinkingTimelineRow,
255 + LiveWorkEntryTimelineRow,
256 + WorkGroupToggleTimelineRow,
257 +} from "./TimelineWorkGroupRows";
258
259 function timelineListStateFor(identity: string): {
260 readonly identity: string;
@@ -2871,603 +2842,6 @@ const V2SubagentGroup = memo(function V2SubagentGroup({
2842 );
2843 });
2844
2874 -const WorkGroupSection = memo(function WorkGroupSection({
2875 - anchorKey,
2876 - disclosureAnchorKey = anchorKey,
2877 - groupedEntries,
2878 - isExpandedToolGroup,
2879 - displayLabel,
2880 -}: {
2881 - anchorKey: string;
2882 - disclosureAnchorKey?: string;
2883 - groupedEntries: Extract<MessagesTimelineRow, { kind: "work" }>["groupedEntries"];
2884 - isExpandedToolGroup: boolean;
2885 - displayLabel?: string | undefined;
2886 -}) {
2887 - const { workspaceRoot, routeThreadKey, onToggleWorkEntry } = use(TimelineRowCtx);
2888 - const onToggleStandaloneEntry = (collapsed: boolean) =>
2889 - onToggleWorkEntry(disclosureAnchorKey, collapsed);
2890 - const nonEmptyEntries = groupedEntries.filter((entry) =>
2891 - workEntryIsVisibleInGroup(entry, isExpandedToolGroup),
2892 - );
2893 -
2894 - if (nonEmptyEntries.length === 0) return null;
2895 - if (isExpandedToolGroup && nonEmptyEntries.every((entry) => entry.itemType === "reasoning")) {
2896 - return <ReasoningTraceContent entries={nonEmptyEntries} />;
2897 - }
2898 - if (isExpandedToolGroup) {
2899 - return (
2900 - <ExpandedWorkGroupEntries
2901 - key={`${routeThreadKey}:${anchorKey}`}
2902 - anchorKey={anchorKey}
2903 - disclosureAnchorKey={disclosureAnchorKey}
2904 - entries={nonEmptyEntries}
2905 - workspaceRoot={workspaceRoot}
2906 - />
2907 - );
2908 - }
2909 -
2910 - return (
2911 - <section aria-label="Activity">
2912 - {nonEmptyEntries.map((workEntry) => (
2913 - <SimpleWorkEntryRow
2914 - key={workEntry.id}
2915 - workEntry={workEntry}
2916 - workspaceRoot={workspaceRoot}
2917 - displayLabel={displayLabel}
2918 - onToggleEntry={onToggleStandaloneEntry}
2919 - />
2920 - ))}
2921 - </section>
2922 - );
2923 -});
2924 -
2925 -function formatWorkingTimer(startIso: string, endIso: string): string | null {
2926 - const startedAtMs = Date.parse(startIso);
2927 - const endedAtMs = Date.parse(endIso);
2928 - if (!Number.isFinite(startedAtMs) || !Number.isFinite(endedAtMs)) {
2929 - return null;
2930 - }
2931 -
2932 - const elapsedSeconds = Math.max(0, Math.floor((endedAtMs - startedAtMs) / 1000));
2933 - if (elapsedSeconds < 60) {
2934 - return `${elapsedSeconds}s`;
2935 - }
2936 -
2937 - return formatDuration(elapsedSeconds * 1_000);
2938 -}
2939 -
2940 -function formatWorkingTimerNow(startIso: string): string {
2941 - return formatWorkingTimer(startIso, new Date().toISOString()) ?? "0s";
2942 -}
2943 -
2944 -function WorkingTimer({ createdAt }: { createdAt: string }) {
2945 - const textRef = useRef<HTMLSpanElement>(null);
2946 - const initialText = formatWorkingTimerNow(createdAt);
2947 -
2948 - useEffect(() => {
2949 - const updateText = () => {
2950 - if (textRef.current) {
2951 - textRef.current.textContent = formatWorkingTimerNow(createdAt);
2952 - }
2953 - };
2954 - updateText();
2955 - const id = setInterval(updateText, 1000);
2956 - return () => clearInterval(id);
2957 - }, [createdAt]);
2958 -
2959 - return (
2960 - <span ref={textRef} className="tabular-nums">
2961 - {initialText}
2962 - </span>
2963 - );
2964 -}
2965 -
2966 -const compactWorkEntryHeight = 24;
2967 -
2968 -function ExpandedWorkGroupEntries({
2969 - anchorKey,
2970 - disclosureAnchorKey,
2971 - entries,
2972 - workspaceRoot,
2973 -}: {
2974 - anchorKey: string;
2975 - disclosureAnchorKey: string;
2976 - entries: TimelineWorkEntry[];
2977 - workspaceRoot: string | undefined;
2978 -}) {
2979 - const { workGroupViewState: viewState, onToggleWorkEntry } = use(TimelineRowCtx);
2980 - const [initialScrollIndex] = useState(() =>
2981 - resolveWorkGroupScrollIndex(entries, viewState.scrollPositions.get(anchorKey)),
2982 - );
2983 - const [restoringPosition, setRestoringPosition] = useState(initialScrollIndex !== undefined);
2984 - const listRef = useRef<LegendListRef>(null);
2985 - const [expandedContentHeight, setExpandedContentHeight] = useState(0);
2986 - const [fades, setFades] = useState({ top: false, bottom: false, viewportHeight: 0 });
2987 - const [appendState, setAppendState] = useState({ entries, follow: false });
2988 - // Capture the pre-change edge once per incoming array, before new layout
2989 - // metrics arrive. Edge/viewport changes never turn a status update into a follow.
2990 - if (appendState.entries !== entries) {
2991 - setAppendState({
2992 - entries,
2993 - follow:
2994 - fades.viewportHeight > 0 &&
2995 - shouldFollowWorkGroupAppend(appendState.entries, entries, fades.bottom ? Infinity : 0),
2996 - });
2997 - }
2998 -
2999 - const groupView = {
3000 - state: viewState,
3001 - onToggleEntry: (collapsed: boolean) => onToggleWorkEntry(disclosureAnchorKey, collapsed),
3002 - };
3003 - const updateScrollFades = () => {
3004 - const element = listRef.current?.getScrollableNode();
3005 - if (!element) return;
3006 - const distanceFromEnd = element.scrollHeight - element.clientHeight - element.scrollTop;
3007 - const viewportHeight = element.clientHeight;
3008 - const top = element.scrollTop > 1;
3009 - const bottom = distanceFromEnd > 1;
3010 - setFades((previous) =>
3011 - previous.top === top &&
3012 - previous.bottom === bottom &&
3013 - previous.viewportHeight === viewportHeight
3014 - ? previous
3015 - : { top, bottom, viewportHeight },
3016 - );
3017 - };
3018 -
3019 - const handleScroll = () => {
3020 - const state = listRef.current?.getState();
3021 - const position = state && resolveWorkGroupScrollAnchor(state);
3022 - if (position) {
3023 - viewState.scrollPositions.set(anchorKey, {
3024 - entryId: position.rowId,
3025 - offset: position.offsetWithinRow,
3026 - });
3027 - }
3028 - updateScrollFades();
3029 - };
3030 -
3031 - const handleLoad = () => {
3032 - const list = listRef.current;
3033 - const element = list?.getScrollableNode();
3034 - if (initialScrollIndex && list && element) {
3035 - // Bootstrap can report the restored target before the DOM has applied it.
3036 - // Reconcile once at load, before releasing the measured anchor row.
3037 - const offset = Math.max(
3038 - 0,
3039 - Math.min(list.getState().scroll, element.scrollHeight - element.clientHeight),
3040 - );
3041 - if (Math.abs(element.scrollTop - offset) > 1) {
3042 - void list.scrollToOffset({ offset, animated: false });
3043 - }
3044 - }
3045 - setRestoringPosition(false);
3046 - };
3047 -
3048 - useLayoutEffect(() => {
3049 - const element = listRef.current?.getScrollableNode();
3050 - if (!element) return;
3051 - updateScrollFades();
3052 - const content = element.firstElementChild;
3053 - return observeResize(content ? [element, content] : element, updateScrollFades);
3054 - }, [updateScrollFades]);
3055 -
3056 - const renderEntry = ({ item }: { item: TimelineWorkEntry }) => (
3057 - <SimpleWorkEntryRow key={item.id} workEntry={item} workspaceRoot={workspaceRoot} />
3058 - );
3059 -
3060 - const updateExpandedContentHeight = () => {
3061 - const state = listRef.current?.getState();
3062 - let height = 0;
3063 - for (const entryId of viewState.expandedEntries) {
3064 - if (state?.indexByKey(entryId) === undefined) continue;
3065 - height += Math.max(
3066 - 0,
3067 - (state.sizes.get(entryId) ?? compactWorkEntryHeight) - compactWorkEntryHeight,
3068 - );
3069 - }
3070 - setExpandedContentHeight(height);
3071 - };
3072 -
3073 - useLayoutEffect(updateExpandedContentHeight, [entries, updateExpandedContentHeight]);
3074 -
3075 - return (
3076 - <WorkGroupViewCtx value={groupView}>
3077 - <WorkLogList>
3078 - <LegendList
3079 - ref={listRef}
3080 - data={entries}
3081 - extraData={workspaceRoot}
3082 - keyExtractor={workEntryKey}
3083 - renderItem={renderEntry}
3084 - estimatedItemSize={compactWorkEntryHeight}
3085 - drawDistance={240}
3086 - recycleItems
3087 - {...(initialScrollIndex ? { initialScrollIndex } : {})}
3088 - maintainScrollAtEnd={
3089 - appendState.follow ? { animated: false, on: { dataChange: true } } : false
3090 - }
3091 - maintainScrollAtEndThreshold={1 / Math.max(1, fades.viewportHeight)}
3092 - // Measure the restored row even when an intra-row offset puts its
3093 - // estimated bounds outside the list's small bootstrap render window.
3094 - {...(restoringPosition && initialScrollIndex
3095 - ? { alwaysRender: { indices: [initialScrollIndex.index] } }
3096 - : {})}
3097 - maintainVisibleContentPosition
3098 - onLoad={handleLoad}
3099 - onScroll={handleScroll}
3100 - onLayout={updateScrollFades}
3101 - onItemSizeChanged={updateExpandedContentHeight}
3102 - tabIndex={0}
3103 - role="region"
3104 - aria-label="Tool calls"
3105 - data-tool-group-scroll
3106 - style={{ maxHeight: `calc(min(18rem, 50dvh) + ${expandedContentHeight}px)` }}
3107 - className={cn(
3108 - "scrollbar-gutter-stable scroll-py-6 overflow-x-hidden rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70",
3109 - getVirtualizedScrollFadeClassName(fades),
3110 - )}
3111 - />
3112 - </WorkLogList>
3113 - </WorkGroupViewCtx>
3114 - );
3115 -}
3116 -
3117 -const workEntryKey = (entry: TimelineWorkEntry) => entry.id;
3118 -
3119 -function WorkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "working" }> }) {
3120 - const { isCompacting, isPreparingWorktree, backgroundWorktreeSetup } =
3121 - use(TimelineRowActivityCtx);
3122 - const shimmer = isPreparingWorktree || isCompacting;
3123 - const label = isPreparingWorktree ? (
3124 - "Setting up worktree…"
3125 - ) : isCompacting ? (
3126 - <CompactingLabel />
3127 - ) : row.createdAt ? (
3128 - <>
3129 - Working for <WorkingTimer createdAt={row.createdAt} />
3130 - </>
3131 - ) : (
3132 - "Working..."
3133 - );
3134 - return (
3135 - <div className="border-b border-border/60 pb-2 pt-1">
3136 - <div className="flex h-6 min-w-0 items-baseline gap-2 px-1 text-sm leading-relaxed text-muted-foreground tabular-nums">
3137 - <span
3138 - ref={shimmer ? observeVisibleAnimation : undefined}
3139 - className="relative shrink-0 overflow-hidden whitespace-nowrap"
3140 - >
3141 - {label}
3142 - {shimmer ? <ActivityShimmerOverlay>{label}</ActivityShimmerOverlay> : null}
3143 - </span>
3144 - {backgroundWorktreeSetup ? (
3145 - <BackgroundWorktreeSetupChip snapshot={backgroundWorktreeSetup} />
3146 - ) : null}
3147 - </div>
3148 - </div>
3149 - );
3150 -}
3151 -
3152 -function BackgroundWorktreeSetupChip({ snapshot }: { snapshot: WorktreeSetupSnapshot }) {
3153 - const ctx = use(TimelineRowCtx);
3154 - const terminalId = snapshot.setupScript?.terminalId ?? null;
3155 - const openTerminal = ctx.onOpenWorktreeSetupTerminal;
3156 - const onOpenTerminal = openTerminal && terminalId ? () => openTerminal(terminalId) : null;
3157 - const scriptName = snapshot.setupScript?.name ?? "Setup script";
3158 - return (
3159 - <Popover>
3160 - <PopoverTrigger
3161 - render={
3162 - <Button
3163 - variant="ghost-muted"
3164 - size="micro"
3165 - className="ml-auto min-w-0 shrink-0"
3166 - aria-label={`${scriptName} is still running. Show setup progress.`}
3167 - />
3168 - }
3169 - >
3170 - <Spinner className="size-3 shrink-0" />
3171 - <span className="truncate">{scriptName}</span>
3172 - </PopoverTrigger>
3173 - <PopoverPopup side="bottom" align="end" width="lg" padding="compact">
3174 - <WorktreeSetupCard
3175 - snapshot={snapshot}
3176 - embedded
3177 - onCancel={null}
3178 - onWorkLocally={null}
3179 - onOpenTerminal={onOpenTerminal}
3180 - />
3181 - </PopoverPopup>
3182 - </Popover>
3183 - );
3184 -}
3185 -
3186 -function CompactingLabel() {
3187 - return (
3188 - <span className="inline-flex items-center gap-1.5">
3189 - <Minimize2Icon aria-hidden="true" className="size-3" />
3190 - Compacting…
3191 - </span>
3192 - );
3193 -}
3194 -
3195 -function ThinkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "thinking" }> }) {
3196 - const ctx = use(TimelineRowCtx);
3197 - const { isCompacting, isPreparingWorktree } = use(TimelineRowActivityCtx);
3198 - if (isPreparingWorktree || isCompacting) return <WorkLogRow label="" />;
3199 - const activity = <LiveActivityRow label="Thinking" iconName="brain" active shimmer />;
3200 - const { groupId } = row;
3201 - if (groupId === undefined) return activity;
3202 - return (
3203 - <button
3204 - type="button"
3205 - className="group/live-work flex min-h-6 w-full max-w-full cursor-pointer items-center rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
3206 - aria-expanded={row.expanded === true}
3207 - onClick={() => ctx.onToggleWorkGroup(groupId, row.id)}
3208 - >
3209 - {activity}
3210 - </button>
3211 - );
3212 -}
3213 -
3214 -function LiveActivityRow({
3215 - label,
3216 - iconName,
3217 - toolIcon,
3218 - failed = false,
3219 - active = false,
3220 - shimmer = false,
3221 -}: {
3222 - label: ReactNode;
3223 - iconName?: WorkEntryIconName;
3224 - toolIcon?: ToolActivityIcon | undefined;
3225 - failed?: boolean;
3226 - active?: boolean;
3227 - shimmer?: boolean;
3228 -}) {
3229 - const animated = active && !failed;
3230 - const showShimmer = animated && shimmer;
3231 - return (
3232 - <div
3233 - ref={animated ? observeVisibleAnimation : undefined}
3234 - className="relative min-h-6 w-fit max-w-full min-w-0 overflow-hidden rounded-md text-sm leading-relaxed"
3235 - >
3236 - <LiveActivityContent
3237 - label={label}
3238 - iconName={iconName}
3239 - toolIcon={toolIcon}
3240 - failed={failed}
3241 - announceFailure={failed}
3242 - active={animated && !shimmer}
3243 - />
3244 - {showShimmer ? (
3245 - <ActivityShimmerOverlay>
3246 - <LiveActivityContent label={label} iconName={iconName} toolIcon={toolIcon} highlighted />
3247 - </ActivityShimmerOverlay>
3248 - ) : null}
3249 - </div>
3250 - );
3251 -}
3252 -
3253 -function LiveActivityContent({
3254 - label,
3255 - iconName,
3256 - toolIcon,
3257 - failed = false,
3258 - announceFailure = false,
3259 - active = false,
3260 - highlighted = false,
3261 -}: {
3262 - label: ReactNode;
3263 - iconName: WorkEntryIconName | undefined;
3264 - toolIcon?: ToolActivityIcon | undefined;
3265 - failed?: boolean;
3266 - announceFailure?: boolean;
3267 - active?: boolean;
3268 - highlighted?: boolean;
3269 -}) {
3270 - const showTrailingFailureMark =
3271 - failed && iconName !== undefined && !toolIconAcceptsTint(toolIcon);
3272 -
3273 - return (
3274 - <WorkLogRow
3275 - icon={
3276 - iconName ? (
3277 - <span
3278 - className={cn(
3279 - "flex size-4 items-center justify-center",
3280 - failed
3281 - ? failedToolIconClassName
3282 - : highlighted
3283 - ? "text-foreground"
3284 - : "text-icon-muted",
3285 - )}
3286 - role={announceFailure ? "img" : undefined}
3287 - aria-label={announceFailure ? "Tool call failed" : undefined}
3288 - >
3289 - <ToolActivityIconView
3290 - icon={toolIcon}
3291 - fallbackName={iconName}
3292 - className="block size-4 shrink-0 stroke-2"
3293 - muted={!highlighted}
3294 - />
3295 - </span>
3296 - ) : null
3297 - }
3298 - label={
3299 - <span
3300 - className={cn(
3301 - "block truncate",
3302 - highlighted && "text-foreground",
3303 - active && "live-tool-shine",
3304 - )}
3305 - >
3306 - {label}
3307 - </span>
3308 - }
3309 - trailing={
3310 - showTrailingFailureMark ? (
3311 - <XIcon aria-hidden className={cn("size-3 shrink-0", failedToolIconClassName)} />
3312 - ) : null
3313 - }
3314 - />
3315 - );
3316 -}
3317 -
3318 -function LiveWorkEntryTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "work-live" }> }) {
3319 - const ctx = use(TimelineRowCtx);
3320 - const threadTarget = useThreadReadTarget(row.entry, ctx.activeThreadEnvironmentId);
3321 - const questionHeading = row.entry.questionAnswer
3322 - ? getQuestionTextPreview(row.entry.questionAnswer)
3323 - : "";
3324 - const label = questionHeading || liveWorkEntryLabel(row.entry, ctx.workspaceRoot, row.active);
3325 - const threadLabel = threadReadLabel(label, threadTarget);
3326 -
3327 - const failed = workEntryDisplayIndicatesToolFailure(row.entry);
3328 - const thoughtLine = row.thought && !row.expanded ? liveThoughtLine(row.thought.detail ?? "") : "";
3329 - const thoughtIsStatus = thoughtLine !== "" && row.entry === row.thought;
3330 -
3331 - return (
3332 - <button
3333 - type="button"
3334 - className={cn(
3335 - "group/live-work flex w-full max-w-full cursor-pointer rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70",
3336 - thoughtLine ? "flex-col items-start" : "min-h-6 items-center",
3337 - )}
3338 - aria-label={
3339 - failed
3340 - ? `${thoughtLine ? `${thoughtLine} ` : ""}${threadLabel?.text ?? label}, tool call failed`
3341 - : undefined
3342 - }
3343 - aria-expanded={row.expanded}
3344 - onClick={() => ctx.onToggleWorkGroup(row.groupId, row.id)}
3345 - >
3346 - {thoughtLine ? (
3347 - <WorkLogRow
3348 - icon={
3349 - <span className="flex size-4 items-center justify-center text-icon-muted">
3350 - <ToolActivityIconView
3351 - icon={undefined}
3352 - fallbackName="brain"
3353 - className="block size-4 shrink-0 stroke-2"
3354 - muted
3355 - />
3356 - </span>
3357 - }
3358 - label={
3359 - <span className="line-clamp-4">
3360 - <ChatMarkdown
3361 - inline
3362 - text={thoughtLine}
3363 - cwd={ctx.markdownCwd}
3364 - parseRawHtml={false}
3365 - extraRemarkPlugins={[[remarkThoughtPreview, "Thought"]]}
3366 - />
3367 - </span>
3368 - }
3369 - wrapLabel
3370 - />
3371 - ) : null}
3372 - <LiveActivityRow
3373 - label={
3374 - thoughtIsStatus ? (
3375 - row.active ? (
3376 - "Thinking"
3377 - ) : (
3378 - "Thought"
3379 - )
3380 - ) : row.entry.questionAnswer && hasQuestionAnswer(row.entry.questionAnswer) ? (
3381 - <span className="flex min-w-0 gap-1.5">
3382 - <span className="min-w-0 truncate">{label}</span>
3383 - <span className="min-w-0 truncate text-foreground">
3384 - {getQuestionAnswerPreview(row.entry.questionAnswer)}
3385 - </span>
3386 - </span>
3387 - ) : row.entry.itemType === "reasoning" ? (
3388 - <ChatMarkdown
3389 - inline
3390 - text={row.entry.detail ?? label}
3391 - cwd={ctx.markdownCwd}
3392 - parseRawHtml={false}
3393 - extraRemarkPlugins={[[remarkThoughtPreview, row.active ? "Thinking" : "Thought"]]}
3394 - />
3395 - ) : threadLabel ? (
3396 - <ThreadReadLabel
3397 - label={threadLabel}
3398 - environmentId={ctx.activeThreadEnvironmentId}
3399 - linked={false}
3400 - />
3401 - ) : (
3402 - label
3403 - )
3404 - }
3405 - iconName={workEntryIconName(row.entry)}
3406 - toolIcon={row.entry.toolIcon ?? row.entry.toolSource?.icon}
3407 - failed={failed}
3408 - active={row.active}
3409 - />
3410 - </button>
3411 - );
3412 -}
3413 -
3414 -function WorkGroupToggleTimelineRow({
3415 - row,
3416 -}: {
3417 - row: Extract<TimelineRow, { kind: "work-toggle" }>;
3418 -}) {
3419 - const ctx = use(TimelineRowCtx);
3420 - return (
3421 - <WorkGroupHeader
3422 - label={row.summary}
3423 - iconName={row.summaryToolIcon ?? row.toolSurface ?? toolGroupSummaryIconName(row.summaryKind)}
3424 - toolIcon={row.toolIcon}
3425 - failed={row.hasFailure}
3426 - expanded={row.expanded}
3427 - createdAt={row.createdAt}
3428 - timestampFormat={ctx.timestampFormat}
3429 - onToggle={() => ctx.onToggleWorkGroup(row.groupId, row.id)}
3430 - />
3431 - );
3432 -}
3433 -
3434 -function WorkGroupHeader(props: {
3435 - label: string;
3436 - iconName: WorkEntryIconName;
3437 - toolIcon?: ToolActivityIcon | undefined;
3438 - failed?: boolean | undefined;
3439 - active?: boolean | undefined;
3440 - expanded: boolean;
3441 - createdAt: string;
3442 - timestampFormat: TimestampFormat;
3443 - onToggle: () => void;
3444 -}) {
3445 - return (
3446 - <WorkLogButton
3447 - ref={props.active && !props.failed ? observeVisibleAnimation : undefined}
3448 - aria-label={props.failed ? `${props.label}, tool call failed` : props.label}
3449 - aria-expanded={props.expanded}
3450 - onClick={props.onToggle}
3451 - icon={
3452 - <ToolActivityIconView
3453 - icon={props.toolIcon}
3454 - fallbackName={props.iconName}
3455 - className="size-4 shrink-0 stroke-2 text-icon-muted"
3456 - muted
3457 - />
3458 - }
3459 - label={
3460 - <span className={cn("block truncate", props.active && !props.failed && "live-tool-shine")}>
3461 - {props.label}
3462 - </span>
3463 - }
3464 - trailing={
3465 - <TimelineRowTimestamp createdAt={props.createdAt} timestampFormat={props.timestampFormat} />
3466 - }
3467 - />
3468 - );
3469 -}
3470 -
2845 /** Subscribes directly to the UI state store for expand/collapse state,
2846 * so toggling re-renders only this component — not the entire list. */
2847 const AssistantChangedFilesSection = memo(function AssistantChangedFilesSection({
apps/web/src/components/chat/TimelineWorkGroupRows.logic.ts new
+20
@@ -0,0 +1,20 @@
1 +import { formatDuration } from "@t3tools/shared/orchestrationTiming";
2 +
3 +function formatWorkingTimer(startIso: string, endIso: string): string | null {
4 + const startedAtMs = Date.parse(startIso);
5 + const endedAtMs = Date.parse(endIso);
6 + if (!Number.isFinite(startedAtMs) || !Number.isFinite(endedAtMs)) {
7 + return null;
8 + }
9 +
10 + const elapsedSeconds = Math.max(0, Math.floor((endedAtMs - startedAtMs) / 1000));
11 + if (elapsedSeconds < 60) {
12 + return `${elapsedSeconds}s`;
13 + }
14 +
15 + return formatDuration(elapsedSeconds * 1_000);
16 +}
17 +
18 +export function formatWorkingTimerNow(startIso: string): string {
19 + return formatWorkingTimer(startIso, new Date().toISOString()) ?? "0s";
20 +}
apps/web/src/components/chat/TimelineWorkGroupRows.tsx new
+640
@@ -0,0 +1,640 @@
1 +import { WorkLogButton, WorkLogList, WorkLogRow } from "./WorkLog";
2 +import type { WorktreeSetupSnapshot } from "@t3tools/contracts";
3 +import {
4 + getQuestionAnswerPreview,
5 + getQuestionTextPreview,
6 + hasQuestionAnswer,
7 +} from "@t3tools/client-runtime/work-log/user-input";
8 +import { type ToolActivityIcon } from "@t3tools/contracts";
9 +import { liveThoughtLine } from "@t3tools/client-runtime/work-log/presentation";
10 +import { resolveWorkGroupScrollAnchor } from "@t3tools/client-runtime/work-log/scroll-anchor";
11 +import { observeResize } from "~/lib/observeResize";
12 +import { observeVisibleAnimation } from "../../lib/visibleAnimation";
13 +import { memo, use, useEffect, useLayoutEffect, useRef, useState, type ReactNode } from "react";
14 +import { LegendList, type LegendListRef } from "@legendapp/list/react";
15 +import { workEntryDisplayIndicatesToolFailure } from "../../session-logic";
16 +import ChatMarkdown from "../ChatMarkdown";
17 +import { Minimize2Icon, XIcon } from "lucide-react";
18 +import { Button } from "../ui/button";
19 +import { getVirtualizedScrollFadeClassName } from "../ui/scroll-area";
20 +import {
21 + liveWorkEntryLabel,
22 + resolveWorkGroupScrollIndex,
23 + shouldFollowWorkGroupAppend,
24 + workEntryIsVisibleInGroup,
25 + type MessagesTimelineRow,
26 +} from "./MessagesTimeline.logic";
27 +import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
28 +import { Spinner } from "../ui/spinner";
29 +import { WorktreeSetupCard } from "./WorktreeSetupCard";
30 +import { cn } from "~/lib/utils";
31 +import { type TimestampFormat } from "@t3tools/contracts/settings";
32 +import {
33 + TimelineRowCtx,
34 + TimelineRowActivityCtx,
35 + WorkGroupViewCtx,
36 + type TimelineWorkEntry,
37 + type TimelineRow,
38 +} from "./timelineRowContext";
39 +import { TimelineRowTimestamp, ActivityShimmerOverlay } from "./TimelineRowParts";
40 +import {
41 + failedToolIconClassName,
42 + toolIconAcceptsTint,
43 + type WorkEntryIconName,
44 + ToolActivityIconView,
45 +} from "./TimelineToolActivityIcon";
46 +import {
47 + useThreadReadTarget,
48 + threadReadLabel,
49 + ThreadReadLabel,
50 + ReasoningTraceContent,
51 + SimpleWorkEntryRow,
52 +} from "./TimelineWorkEntryRow";
53 +import {
54 + remarkThoughtPreview,
55 + toolGroupSummaryIconName,
56 + workEntryIconName,
57 +} from "./TimelineWorkEntryRow.logic";
58 +import { formatWorkingTimerNow } from "./TimelineWorkGroupRows.logic";
59 +
60 +export const WorkGroupSection = memo(function WorkGroupSection({
61 + anchorKey,
62 + disclosureAnchorKey = anchorKey,
63 + groupedEntries,
64 + isExpandedToolGroup,
65 + displayLabel,
66 +}: {
67 + anchorKey: string;
68 + disclosureAnchorKey?: string;
69 + groupedEntries: Extract<MessagesTimelineRow, { kind: "work" }>["groupedEntries"];
70 + isExpandedToolGroup: boolean;
71 + displayLabel?: string | undefined;
72 +}) {
73 + const { workspaceRoot, routeThreadKey, onToggleWorkEntry } = use(TimelineRowCtx);
74 + const onToggleStandaloneEntry = (collapsed: boolean) =>
75 + onToggleWorkEntry(disclosureAnchorKey, collapsed);
76 + const nonEmptyEntries = groupedEntries.filter((entry) =>
77 + workEntryIsVisibleInGroup(entry, isExpandedToolGroup),
78 + );
79 +
80 + if (nonEmptyEntries.length === 0) return null;
81 + if (isExpandedToolGroup && nonEmptyEntries.every((entry) => entry.itemType === "reasoning")) {
82 + return <ReasoningTraceContent entries={nonEmptyEntries} />;
83 + }
84 + if (isExpandedToolGroup) {
85 + return (
86 + <ExpandedWorkGroupEntries
87 + key={`${routeThreadKey}:${anchorKey}`}
88 + anchorKey={anchorKey}
89 + disclosureAnchorKey={disclosureAnchorKey}
90 + entries={nonEmptyEntries}
91 + workspaceRoot={workspaceRoot}
92 + />
93 + );
94 + }
95 +
96 + return (
97 + <section aria-label="Activity">
98 + {nonEmptyEntries.map((workEntry) => (
99 + <SimpleWorkEntryRow
100 + key={workEntry.id}
101 + workEntry={workEntry}
102 + workspaceRoot={workspaceRoot}
103 + displayLabel={displayLabel}
104 + onToggleEntry={onToggleStandaloneEntry}
105 + />
106 + ))}
107 + </section>
108 + );
109 +});
110 +
111 +function WorkingTimer({ createdAt }: { createdAt: string }) {
112 + const textRef = useRef<HTMLSpanElement>(null);
113 + const initialText = formatWorkingTimerNow(createdAt);
114 +
115 + useEffect(() => {
116 + const updateText = () => {
117 + if (textRef.current) {
118 + textRef.current.textContent = formatWorkingTimerNow(createdAt);
119 + }
120 + };
121 + updateText();
122 + const id = setInterval(updateText, 1000);
123 + return () => clearInterval(id);
124 + }, [createdAt]);
125 +
126 + return (
127 + <span ref={textRef} className="tabular-nums">
128 + {initialText}
129 + </span>
130 + );
131 +}
132 +
133 +const compactWorkEntryHeight = 24;
134 +
135 +function ExpandedWorkGroupEntries({
136 + anchorKey,
137 + disclosureAnchorKey,
138 + entries,
139 + workspaceRoot,
140 +}: {
141 + anchorKey: string;
142 + disclosureAnchorKey: string;
143 + entries: TimelineWorkEntry[];
144 + workspaceRoot: string | undefined;
145 +}) {
146 + const { workGroupViewState: viewState, onToggleWorkEntry } = use(TimelineRowCtx);
147 + const [initialScrollIndex] = useState(() =>
148 + resolveWorkGroupScrollIndex(entries, viewState.scrollPositions.get(anchorKey)),
149 + );
150 + const [restoringPosition, setRestoringPosition] = useState(initialScrollIndex !== undefined);
151 + const listRef = useRef<LegendListRef>(null);
152 + const [expandedContentHeight, setExpandedContentHeight] = useState(0);
153 + const [fades, setFades] = useState({ top: false, bottom: false, viewportHeight: 0 });
154 + const [appendState, setAppendState] = useState({ entries, follow: false });
155 + // Capture the pre-change edge once per incoming array, before new layout
156 + // metrics arrive. Edge/viewport changes never turn a status update into a follow.
157 + if (appendState.entries !== entries) {
158 + setAppendState({
159 + entries,
160 + follow:
161 + fades.viewportHeight > 0 &&
162 + shouldFollowWorkGroupAppend(appendState.entries, entries, fades.bottom ? Infinity : 0),
163 + });
164 + }
165 +
166 + const groupView = {
167 + state: viewState,
168 + onToggleEntry: (collapsed: boolean) => onToggleWorkEntry(disclosureAnchorKey, collapsed),
169 + };
170 + const updateScrollFades = () => {
171 + const element = listRef.current?.getScrollableNode();
172 + if (!element) return;
173 + const distanceFromEnd = element.scrollHeight - element.clientHeight - element.scrollTop;
174 + const viewportHeight = element.clientHeight;
175 + const top = element.scrollTop > 1;
176 + const bottom = distanceFromEnd > 1;
177 + setFades((previous) =>
178 + previous.top === top &&
179 + previous.bottom === bottom &&
180 + previous.viewportHeight === viewportHeight
181 + ? previous
182 + : { top, bottom, viewportHeight },
183 + );
184 + };
185 +
186 + const handleScroll = () => {
187 + const state = listRef.current?.getState();
188 + const position = state && resolveWorkGroupScrollAnchor(state);
189 + if (position) {
190 + viewState.scrollPositions.set(anchorKey, {
191 + entryId: position.rowId,
192 + offset: position.offsetWithinRow,
193 + });
194 + }
195 + updateScrollFades();
196 + };
197 +
198 + const handleLoad = () => {
199 + const list = listRef.current;
200 + const element = list?.getScrollableNode();
201 + if (initialScrollIndex && list && element) {
202 + // Bootstrap can report the restored target before the DOM has applied it.
203 + // Reconcile once at load, before releasing the measured anchor row.
204 + const offset = Math.max(
205 + 0,
206 + Math.min(list.getState().scroll, element.scrollHeight - element.clientHeight),
207 + );
208 + if (Math.abs(element.scrollTop - offset) > 1) {
209 + void list.scrollToOffset({ offset, animated: false });
210 + }
211 + }
212 + setRestoringPosition(false);
213 + };
214 +
215 + useLayoutEffect(() => {
216 + const element = listRef.current?.getScrollableNode();
217 + if (!element) return;
218 + updateScrollFades();
219 + const content = element.firstElementChild;
220 + return observeResize(content ? [element, content] : element, updateScrollFades);
221 + }, [updateScrollFades]);
222 +
223 + const renderEntry = ({ item }: { item: TimelineWorkEntry }) => (
224 + <SimpleWorkEntryRow key={item.id} workEntry={item} workspaceRoot={workspaceRoot} />
225 + );
226 +
227 + const updateExpandedContentHeight = () => {
228 + const state = listRef.current?.getState();
229 + let height = 0;
230 + for (const entryId of viewState.expandedEntries) {
231 + if (state?.indexByKey(entryId) === undefined) continue;
232 + height += Math.max(
233 + 0,
234 + (state.sizes.get(entryId) ?? compactWorkEntryHeight) - compactWorkEntryHeight,
235 + );
236 + }
237 + setExpandedContentHeight(height);
238 + };
239 +
240 + useLayoutEffect(updateExpandedContentHeight, [entries, updateExpandedContentHeight]);
241 +
242 + return (
243 + <WorkGroupViewCtx value={groupView}>
244 + <WorkLogList>
245 + <LegendList
246 + ref={listRef}
247 + data={entries}
248 + extraData={workspaceRoot}
249 + keyExtractor={workEntryKey}
250 + renderItem={renderEntry}
251 + estimatedItemSize={compactWorkEntryHeight}
252 + drawDistance={240}
253 + recycleItems
254 + {...(initialScrollIndex ? { initialScrollIndex } : {})}
255 + maintainScrollAtEnd={
256 + appendState.follow ? { animated: false, on: { dataChange: true } } : false
257 + }
258 + maintainScrollAtEndThreshold={1 / Math.max(1, fades.viewportHeight)}
259 + // Measure the restored row even when an intra-row offset puts its
260 + // estimated bounds outside the list's small bootstrap render window.
261 + {...(restoringPosition && initialScrollIndex
262 + ? { alwaysRender: { indices: [initialScrollIndex.index] } }
263 + : {})}
264 + maintainVisibleContentPosition
265 + onLoad={handleLoad}
266 + onScroll={handleScroll}
267 + onLayout={updateScrollFades}
268 + onItemSizeChanged={updateExpandedContentHeight}
269 + tabIndex={0}
270 + role="region"
271 + aria-label="Tool calls"
272 + data-tool-group-scroll
273 + style={{ maxHeight: `calc(min(18rem, 50dvh) + ${expandedContentHeight}px)` }}
274 + className={cn(
275 + "scrollbar-gutter-stable scroll-py-6 overflow-x-hidden rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70",
276 + getVirtualizedScrollFadeClassName(fades),
277 + )}
278 + />
279 + </WorkLogList>
280 + </WorkGroupViewCtx>
281 + );
282 +}
283 +
284 +const workEntryKey = (entry: TimelineWorkEntry) => entry.id;
285 +
286 +export function WorkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "working" }> }) {
287 + const { isCompacting, isPreparingWorktree, backgroundWorktreeSetup } =
288 + use(TimelineRowActivityCtx);
289 + const shimmer = isPreparingWorktree || isCompacting;
290 + const label = isPreparingWorktree ? (
291 + "Setting up worktree…"
292 + ) : isCompacting ? (
293 + <CompactingLabel />
294 + ) : row.createdAt ? (
295 + <>
296 + Working for <WorkingTimer createdAt={row.createdAt} />
297 + </>
298 + ) : (
299 + "Working..."
300 + );
301 + return (
302 + <div className="border-b border-border/60 pb-2 pt-1">
303 + <div className="flex h-6 min-w-0 items-baseline gap-2 px-1 text-sm leading-relaxed text-muted-foreground tabular-nums">
304 + <span
305 + ref={shimmer ? observeVisibleAnimation : undefined}
306 + className="relative shrink-0 overflow-hidden whitespace-nowrap"
307 + >
308 + {label}
309 + {shimmer ? <ActivityShimmerOverlay>{label}</ActivityShimmerOverlay> : null}
310 + </span>
311 + {backgroundWorktreeSetup ? (
312 + <BackgroundWorktreeSetupChip snapshot={backgroundWorktreeSetup} />
313 + ) : null}
314 + </div>
315 + </div>
316 + );
317 +}
318 +
319 +function BackgroundWorktreeSetupChip({ snapshot }: { snapshot: WorktreeSetupSnapshot }) {
320 + const ctx = use(TimelineRowCtx);
321 + const terminalId = snapshot.setupScript?.terminalId ?? null;
322 + const openTerminal = ctx.onOpenWorktreeSetupTerminal;
323 + const onOpenTerminal = openTerminal && terminalId ? () => openTerminal(terminalId) : null;
324 + const scriptName = snapshot.setupScript?.name ?? "Setup script";
325 + return (
326 + <Popover>
327 + <PopoverTrigger
328 + render={
329 + <Button
330 + variant="ghost-muted"
331 + size="micro"
332 + className="ml-auto min-w-0 shrink-0"
333 + aria-label={`${scriptName} is still running. Show setup progress.`}
334 + />
335 + }
336 + >
337 + <Spinner className="size-3 shrink-0" />
338 + <span className="truncate">{scriptName}</span>
339 + </PopoverTrigger>
340 + <PopoverPopup side="bottom" align="end" width="lg" padding="compact">
341 + <WorktreeSetupCard
342 + snapshot={snapshot}
343 + embedded
344 + onCancel={null}
345 + onWorkLocally={null}
346 + onOpenTerminal={onOpenTerminal}
347 + />
348 + </PopoverPopup>
349 + </Popover>
350 + );
351 +}
352 +
353 +function CompactingLabel() {
354 + return (
355 + <span className="inline-flex items-center gap-1.5">
356 + <Minimize2Icon aria-hidden="true" className="size-3" />
357 + Compacting…
358 + </span>
359 + );
360 +}
361 +
362 +export function ThinkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "thinking" }> }) {
363 + const ctx = use(TimelineRowCtx);
364 + const { isCompacting, isPreparingWorktree } = use(TimelineRowActivityCtx);
365 + if (isPreparingWorktree || isCompacting) return <WorkLogRow label="" />;
366 + const activity = <LiveActivityRow label="Thinking" iconName="brain" active shimmer />;
367 + const { groupId } = row;
368 + if (groupId === undefined) return activity;
369 + return (
370 + <button
371 + type="button"
372 + className="group/live-work flex min-h-6 w-full max-w-full cursor-pointer items-center rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
373 + aria-expanded={row.expanded === true}
374 + onClick={() => ctx.onToggleWorkGroup(groupId, row.id)}
375 + >
376 + {activity}
377 + </button>
378 + );
379 +}
380 +
381 +function LiveActivityRow({
382 + label,
383 + iconName,
384 + toolIcon,
385 + failed = false,
386 + active = false,
387 + shimmer = false,
388 +}: {
389 + label: ReactNode;
390 + iconName?: WorkEntryIconName;
391 + toolIcon?: ToolActivityIcon | undefined;
392 + failed?: boolean;
393 + active?: boolean;
394 + shimmer?: boolean;
395 +}) {
396 + const animated = active && !failed;
397 + const showShimmer = animated && shimmer;
398 + return (
399 + <div
400 + ref={animated ? observeVisibleAnimation : undefined}
401 + className="relative min-h-6 w-fit max-w-full min-w-0 overflow-hidden rounded-md text-sm leading-relaxed"
402 + >
403 + <LiveActivityContent
404 + label={label}
405 + iconName={iconName}
406 + toolIcon={toolIcon}
407 + failed={failed}
408 + announceFailure={failed}
409 + active={animated && !shimmer}
410 + />
411 + {showShimmer ? (
412 + <ActivityShimmerOverlay>
413 + <LiveActivityContent label={label} iconName={iconName} toolIcon={toolIcon} highlighted />
414 + </ActivityShimmerOverlay>
415 + ) : null}
416 + </div>
417 + );
418 +}
419 +
420 +function LiveActivityContent({
421 + label,
422 + iconName,
423 + toolIcon,
424 + failed = false,
425 + announceFailure = false,
426 + active = false,
427 + highlighted = false,
428 +}: {
429 + label: ReactNode;
430 + iconName: WorkEntryIconName | undefined;
431 + toolIcon?: ToolActivityIcon | undefined;
432 + failed?: boolean;
433 + announceFailure?: boolean;
434 + active?: boolean;
435 + highlighted?: boolean;
436 +}) {
437 + const showTrailingFailureMark =
438 + failed && iconName !== undefined && !toolIconAcceptsTint(toolIcon);
439 +
440 + return (
441 + <WorkLogRow
442 + icon={
443 + iconName ? (
444 + <span
445 + className={cn(
446 + "flex size-4 items-center justify-center",
447 + failed
448 + ? failedToolIconClassName
449 + : highlighted
450 + ? "text-foreground"
451 + : "text-icon-muted",
452 + )}
453 + role={announceFailure ? "img" : undefined}
454 + aria-label={announceFailure ? "Tool call failed" : undefined}
455 + >
456 + <ToolActivityIconView
457 + icon={toolIcon}
458 + fallbackName={iconName}
459 + className="block size-4 shrink-0 stroke-2"
460 + muted={!highlighted}
461 + />
462 + </span>
463 + ) : null
464 + }
465 + label={
466 + <span
467 + className={cn(
468 + "block truncate",
469 + highlighted && "text-foreground",
470 + active && "live-tool-shine",
471 + )}
472 + >
473 + {label}
474 + </span>
475 + }
476 + trailing={
477 + showTrailingFailureMark ? (
478 + <XIcon aria-hidden className={cn("size-3 shrink-0", failedToolIconClassName)} />
479 + ) : null
480 + }
481 + />
482 + );
483 +}
484 +
485 +export function LiveWorkEntryTimelineRow({
486 + row,
487 +}: {
488 + row: Extract<TimelineRow, { kind: "work-live" }>;
489 +}) {
490 + const ctx = use(TimelineRowCtx);
491 + const threadTarget = useThreadReadTarget(row.entry, ctx.activeThreadEnvironmentId);
492 + const questionHeading = row.entry.questionAnswer
493 + ? getQuestionTextPreview(row.entry.questionAnswer)
494 + : "";
495 + const label = questionHeading || liveWorkEntryLabel(row.entry, ctx.workspaceRoot, row.active);
496 + const threadLabel = threadReadLabel(label, threadTarget);
497 +
498 + const failed = workEntryDisplayIndicatesToolFailure(row.entry);
499 + const thoughtLine = row.thought && !row.expanded ? liveThoughtLine(row.thought.detail ?? "") : "";
500 + const thoughtIsStatus = thoughtLine !== "" && row.entry === row.thought;
501 +
502 + return (
503 + <button
504 + type="button"
505 + className={cn(
506 + "group/live-work flex w-full max-w-full cursor-pointer rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70",
507 + thoughtLine ? "flex-col items-start" : "min-h-6 items-center",
508 + )}
509 + aria-label={
510 + failed
511 + ? `${thoughtLine ? `${thoughtLine} ` : ""}${threadLabel?.text ?? label}, tool call failed`
512 + : undefined
513 + }
514 + aria-expanded={row.expanded}
515 + onClick={() => ctx.onToggleWorkGroup(row.groupId, row.id)}
516 + >
517 + {thoughtLine ? (
518 + <WorkLogRow
519 + icon={
520 + <span className="flex size-4 items-center justify-center text-icon-muted">
521 + <ToolActivityIconView
522 + icon={undefined}
523 + fallbackName="brain"
524 + className="block size-4 shrink-0 stroke-2"
525 + muted
526 + />
527 + </span>
528 + }
529 + label={
530 + <span className="line-clamp-4">
531 + <ChatMarkdown
532 + inline
533 + text={thoughtLine}
534 + cwd={ctx.markdownCwd}
535 + parseRawHtml={false}
536 + extraRemarkPlugins={[[remarkThoughtPreview, "Thought"]]}
537 + />
538 + </span>
539 + }
540 + wrapLabel
541 + />
542 + ) : null}
543 + <LiveActivityRow
544 + label={
545 + thoughtIsStatus ? (
546 + row.active ? (
547 + "Thinking"
548 + ) : (
549 + "Thought"
550 + )
551 + ) : row.entry.questionAnswer && hasQuestionAnswer(row.entry.questionAnswer) ? (
552 + <span className="flex min-w-0 gap-1.5">
553 + <span className="min-w-0 truncate">{label}</span>
554 + <span className="min-w-0 truncate text-foreground">
555 + {getQuestionAnswerPreview(row.entry.questionAnswer)}
556 + </span>
557 + </span>
558 + ) : row.entry.itemType === "reasoning" ? (
559 + <ChatMarkdown
560 + inline
561 + text={row.entry.detail ?? label}
562 + cwd={ctx.markdownCwd}
563 + parseRawHtml={false}
564 + extraRemarkPlugins={[[remarkThoughtPreview, row.active ? "Thinking" : "Thought"]]}
565 + />
566 + ) : threadLabel ? (
567 + <ThreadReadLabel
568 + label={threadLabel}
569 + environmentId={ctx.activeThreadEnvironmentId}
570 + linked={false}
571 + />
572 + ) : (
573 + label
574 + )
575 + }
576 + iconName={workEntryIconName(row.entry)}
577 + toolIcon={row.entry.toolIcon ?? row.entry.toolSource?.icon}
578 + failed={failed}
579 + active={row.active}
580 + />
581 + </button>
582 + );
583 +}
584 +
585 +export function WorkGroupToggleTimelineRow({
586 + row,
587 +}: {
588 + row: Extract<TimelineRow, { kind: "work-toggle" }>;
589 +}) {
590 + const ctx = use(TimelineRowCtx);
591 + return (
592 + <WorkGroupHeader
593 + label={row.summary}
594 + iconName={row.summaryToolIcon ?? row.toolSurface ?? toolGroupSummaryIconName(row.summaryKind)}
595 + toolIcon={row.toolIcon}
596 + failed={row.hasFailure}
597 + expanded={row.expanded}
598 + createdAt={row.createdAt}
599 + timestampFormat={ctx.timestampFormat}
600 + onToggle={() => ctx.onToggleWorkGroup(row.groupId, row.id)}
601 + />
602 + );
603 +}
604 +
605 +function WorkGroupHeader(props: {
606 + label: string;
607 + iconName: WorkEntryIconName;
608 + toolIcon?: ToolActivityIcon | undefined;
609 + failed?: boolean | undefined;
610 + active?: boolean | undefined;
611 + expanded: boolean;
612 + createdAt: string;
613 + timestampFormat: TimestampFormat;
614 + onToggle: () => void;
615 +}) {
616 + return (
617 + <WorkLogButton
618 + ref={props.active && !props.failed ? observeVisibleAnimation : undefined}
619 + aria-label={props.failed ? `${props.label}, tool call failed` : props.label}
620 + aria-expanded={props.expanded}
621 + onClick={props.onToggle}
622 + icon={
623 + <ToolActivityIconView
624 + icon={props.toolIcon}
625 + fallbackName={props.iconName}
626 + className="size-4 shrink-0 stroke-2 text-icon-muted"
627 + muted
628 + />
629 + }
630 + label={
631 + <span className={cn("block truncate", props.active && !props.failed && "live-tool-shine")}>
632 + {props.label}
633 + </span>
634 + }
635 + trailing={
636 + <TimelineRowTimestamp createdAt={props.createdAt} timestampFormat={props.timestampFormat} />
637 + }
638 + />
639 + );
640 +}