@devries-cameron20 / t3code Mirror · read-only / commits / 476e2c3e30
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 assistant and orchestration event rows live in their own files (#22677)

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

Julius Marminge committed Oct 21, 2026 at 01:12 UTC 476e2c3e3044ec431bf2d65337e0713b40fa8142
4 files changed +831 -808
apps/web/src/components/chat/MessagesTimeline.tsx
+16 -808
@@ -1,6 +1,5 @@
1 import { ThreadFindTimelineContext } from "./ThreadFindProvider";
2 import { shallow } from "zustand/vanilla/shallow";
3 -import { shouldPreserveAssistantLineBreaks } from "@t3tools/shared/markdownPipeline";
3 import { MarkdownFindContext } from "./markdownFindContext";
4 import { useChatCanvas } from "./ChatCanvasContext";
5 import { WorkLogBlock } from "./WorkLog";
@@ -16,15 +15,8 @@ import {
15 type RunId,
16 ThreadId,
17 } from "@t3tools/contracts";
19 -import { parseScopedThreadKey, scopeThreadRef } from "@t3tools/client-runtime/environment";
20 -import { useAtomValue } from "@effect/atom-react";
21 -import { environmentThreadDetails } from "../../state/threads";
22 -import { canForkProjectedAssistantItem } from "@t3tools/client-runtime/state/thread-workflows";
18 +import { parseScopedThreadKey } from "@t3tools/client-runtime/environment";
19 import { resolveWorkGroupScrollAnchor } from "@t3tools/client-runtime/work-log/scroll-anchor";
24 -import {
25 - subagentGroupSummary,
26 - summarizeSubagentStatuses,
27 -} from "@t3tools/client-runtime/state/subagent-display";
20 import type { WorkflowOpening } from "@t3tools/client-runtime/state/subagentRuntime";
21 import { observeResize } from "~/lib/observeResize";
22 import { useStableCallback } from "~/hooks/useStableCallback";
@@ -49,34 +41,13 @@ import {
41 type LegendListRef,
42 type MaintainScrollAtEndOptions,
43 } from "@legendapp/list/react";
52 -import { type TimelineEntry, providerErrorPresentation } from "../../session-logic";
44 +import { type TimelineEntry } from "../../session-logic";
45 import type { CodexArtifactTemplate } from "@t3tools/shared/codexArtifactTemplates";
54 -import { type ChatMessage, type ChatFileAttachment, type TurnDiffSummary } from "../../types";
55 -import ChatMarkdown from "../ChatMarkdown";
56 -import {
57 - ArrowRightIcon,
58 - BotIcon,
59 - CheckIcon,
60 - ChevronDownIcon,
61 - CircleAlertIcon,
62 - GitForkIcon,
63 - type LucideIcon,
64 - MinusIcon,
65 - Minimize2Icon,
66 - WrenchIcon,
67 - XIcon,
68 - ZapIcon,
69 -} from "lucide-react";
46 +import { type ChatFileAttachment, type TurnDiffSummary } from "../../types";
47 +import { ArrowRightIcon, BotIcon, Minimize2Icon } from "lucide-react";
48 import { ChevronDown, ChevronRight } from "lucide";
71 -import { Button } from "../ui/button";
49 import { MorphIcon } from "~/components/MorphIcon";
50 import { ExpandedImagePreview } from "./ExpandedImagePreview";
74 -import { ProposedPlanCard } from "./ProposedPlanCard";
75 -import { HtmlRenderFrame } from "./HtmlRenderFrame";
76 -import { McpAppFrame } from "./McpAppFrame";
77 -import { ChangedFilesCard } from "./ChangedFilesTree";
78 -import { useFileContextMenuHandler } from "../../fileContextMenu";
79 -import { useProject, useThreadShell } from "../../state/entities";
51 import {
52 CHAT_TIMELINE_ANCHOR_OFFSET,
53 readTimelinePosition,
@@ -84,16 +55,14 @@ import {
55 rememberTimelinePosition,
56 timelineContentOverflowsViewport,
57 } from "./timelineScrollAnchoring";
87 -import { MessageCopyButton } from "./MessageCopyButton";
58 import { AssistantSelectionToolbar } from "./AssistantSelectionToolbar";
59 import type { AssistantCitationSourceAnchor } from "~/lib/assistantTextSelection";
90 -import { AssistantCitationSource, type AssistantCitationRequest } from "./AssistantCitationSource";
60 +import { type AssistantCitationRequest } from "./AssistantCitationSource";
61 import { useAssistantCitationTarget, type CitationHistoryPage } from "./useAssistantCitationTarget";
62 import {
63 computeStableMessagesTimelineRows,
64 deriveMessagesTimelineRowsWithState,
65 type MessagesTimelineRowsProjection,
96 - resolveAssistantMessageCopyState,
66 resolveTimelineIsAtEnd,
67 resolveTimelineMinimapHasPersistentGutter,
68 resolveTimelineMinimapCurrentIndex,
@@ -110,29 +79,16 @@ import { type ThreadFindMatch } from "./threadFind";
79 import { useThreadFindNavigation } from "./useThreadFindNavigation";
80 import { readThreadFindPosition } from "./threadFindPosition";
81 import type { ThreadFindPositionReader } from "./threadFind";
113 -import { Tooltip, TooltipPopup, TooltipTrigger, TooltipScrollDismissArea } from "../ui/tooltip";
82 +import { TooltipScrollDismissArea } from "../ui/tooltip";
83 import { WorktreeSetupCard } from "./WorktreeSetupCard";
84 import { useOpenPrLink } from "~/lib/openPullRequestLink";
85 import { useClientSettings } from "~/hooks/useSettings";
86 import { useMediaQuery } from "~/hooks/useMediaQuery";
87 import { cn } from "~/lib/utils";
119 -import { useUiStateStore } from "~/uiStateStore";
88 import { type TimestampFormat } from "@t3tools/contracts/settings";
121 -import { formatChatTimestampTooltip, formatDayAwareTimestamp } from "../../timestampFormat";
122 -import { V2ItemInspector } from "./V2ItemInspector";
123 -import { useV2ItemSupport } from "../../state/v2ItemSupport";
124 -import { Collapsible, CollapsibleTrigger, CollapsiblePanel } from "../ui/collapsible";
125 -import {
126 - isV2LifecycleItem,
127 - EnvironmentSubagentAvatar,
128 - SubagentElapsed,
129 - V2LifecycleRow,
130 - type HandoffTimelineRun,
131 -} from "./V2LifecycleRow";
132 -import { SecretRequestCard } from "./SecretRequestCard";
89 +import { type HandoffTimelineRun } from "./V2LifecycleRow";
90 import { TimelineSystemDivider } from "./TimelineSystemDivider";
91
135 -import * as DateTime from "effect/DateTime";
92 import { forwardWheelToTimeline } from "./timelineMinimapWheel";
93 import { TimelineMinimap } from "./TimelineMinimap";
94 import {
@@ -143,12 +99,7 @@ import {
99 type WorkGroupViewState,
100 type TimelineRow,
101 } from "./timelineRowContext";
146 -import {
147 - MESSAGE_HEADING_LEVEL,
148 - MessageAuthorHeading,
149 - TimelineRowTimestamp,
150 - ActivityShimmerOverlay,
151 -} from "./TimelineRowParts";
102 +import { TimelineRowTimestamp, ActivityShimmerOverlay } from "./TimelineRowParts";
103 import {
104 WorkGroupSection,
105 WorkingTimelineRow,
@@ -157,6 +108,14 @@ import {
108 WorkGroupToggleTimelineRow,
109 } from "./TimelineWorkGroupRows";
110 import { UserMessageRow } from "./TimelineUserMessageRow";
111 +import {
112 + AssistantTimelineRow,
113 + AssistantMetaTimelineRow,
114 + ProposedPlanTimelineRow,
115 + HtmlRenderTimelineRow,
116 + McpAppTimelineRow,
117 +} from "./TimelineAssistantRows";
118 +import { V2EventTimelineRow } from "./TimelineV2EventRow";
119
120 function timelineListStateFor(identity: string): {
121 readonly identity: string;
@@ -1598,757 +1557,6 @@ function AttemptFoldTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "at
1557 );
1558 }
1559
1601 -function AssistantTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
1602 - const ctx = use(TimelineRowCtx);
1603 - const messageText = row.message.text || (row.message.streaming ? "" : "(empty response)");
1604 -
1605 - return (
1606 - <>
1607 - <div className="relative min-w-0 px-1 py-0.5">
1608 - <MessageAuthorHeading>T3 Code</MessageAuthorHeading>
1609 - <div data-thread-find-text="true">
1610 - <AssistantCitationSource
1611 - messageId={row.message.id}
1612 - {...(ctx.threadRef ? { threadRef: ctx.threadRef } : {})}
1613 - itemKey={row.id}
1614 - request={ctx.citationRequest}
1615 - listRef={ctx.listRef}
1616 - >
1617 - <ChatMarkdown
1618 - text={messageText}
1619 - cwd={ctx.markdownCwd}
1620 - threadRef={ctx.threadRef ?? undefined}
1621 - isStreaming={Boolean(row.message.streaming)}
1622 - lineBreaks={shouldPreserveAssistantLineBreaks(messageText)}
1623 - skills={ctx.skills}
1624 - headingLevelOffset={MESSAGE_HEADING_LEVEL}
1625 - onUseArtifactTemplate={ctx.onUseArtifactTemplate}
1626 - onRunShellCommand={ctx.onRunShellCommand}
1627 - onImageExpand={ctx.onImageExpand}
1628 - />
1629 - </AssistantCitationSource>
1630 - </div>
1631 - <AssistantChangedFilesSection
1632 - turnSummary={row.assistantTurnDiffSummary}
1633 - routeThreadKey={ctx.routeThreadKey}
1634 - resolvedTheme={ctx.resolvedTheme}
1635 - onOpenTurnDiff={ctx.onOpenTurnDiff}
1636 - />
1637 - {row.showAssistantMeta ? (
1638 - <AssistantMessageMeta
1639 - className="mt-1.5"
1640 - projectedItem={row.projectedItem}
1641 - message={row.message}
1642 - showCopyButton={row.showAssistantCopyButton}
1643 - copyStreaming={row.assistantCopyStreaming}
1644 - />
1645 - ) : null}
1646 - </div>
1647 - </>
1648 - );
1649 -}
1650 -
1651 -function AssistantForkButton({
1652 - projectedItem,
1653 -}: {
1654 - readonly projectedItem: NonNullable<Extract<TimelineRow, { kind: "message" }>["projectedItem"]>;
1655 -}) {
1656 - const ctx = use(TimelineRowCtx);
1657 - const [busy, setBusy] = useState(false);
1658 - const support = useV2ItemSupport({
1659 - environmentId: ctx.activeThreadEnvironmentId,
1660 - sourceThreadId: projectedItem.sourceThreadId,
1661 - sourceItemId: projectedItem.sourceItemId,
1662 - });
1663 - const canFork = canForkProjectedAssistantItem({
1664 - projectedItem,
1665 - capabilities: support.providerSession?.capabilities,
1666 - });
1667 -
1668 - if (!canFork || projectedItem.item.runId === null) return null;
1669 - const runId = projectedItem.item.runId;
1670 -
1671 - return (
1672 - <Tooltip>
1673 - <TooltipTrigger
1674 - render={
1675 - <Button
1676 - type="button"
1677 - size="xs"
1678 - variant="ghost"
1679 - disabled={busy}
1680 - onClick={() => {
1681 - setBusy(true);
1682 - void ctx
1683 - .onForkFromRun({ sourceThreadId: projectedItem.sourceThreadId, runId })
1684 - .finally(() => setBusy(false));
1685 - }}
1686 - aria-label="Fork from this response"
1687 - />
1688 - }
1689 - >
1690 - <GitForkIcon className={cn("size-3", busy && "animate-pulse")} />
1691 - </TooltipTrigger>
1692 - <TooltipPopup side="top">Fork from this response</TooltipPopup>
1693 - </Tooltip>
1694 - );
1695 -}
1696 -
1697 -function AssistantMetaTimelineRow({
1698 - row,
1699 -}: {
1700 - row: Extract<TimelineRow, { kind: "assistant-meta" }>;
1701 -}) {
1702 - return (
1703 - <div className="px-1">
1704 - <AssistantMessageMeta
1705 - className="mt-0.5"
1706 - projectedItem={row.projectedItem}
1707 - message={row.message}
1708 - showCopyButton={row.showAssistantCopyButton}
1709 - copyStreaming={row.assistantCopyStreaming}
1710 - alwaysVisible
1711 - />
1712 - </div>
1713 - );
1714 -}
1715 -
1716 -function AssistantMessageMeta({
1717 - className,
1718 - projectedItem,
1719 - message,
1720 - showCopyButton,
1721 - copyStreaming,
1722 - alwaysVisible = false,
1723 -}: {
1724 - className?: string;
1725 - projectedItem?: Extract<TimelineRow, { kind: "message" }>["projectedItem"];
1726 - message: ChatMessage;
1727 - showCopyButton: boolean;
1728 - copyStreaming: boolean;
1729 - alwaysVisible?: boolean;
1730 -}) {
1731 - const ctx = use(TimelineRowCtx);
1732 -
1733 - return (
1734 - <div
1735 - className={cn(
1736 - "flex items-center gap-2 text-xs tabular-nums transition-opacity duration-200",
1737 - alwaysVisible
1738 - ? "opacity-100"
1739 - : "opacity-0 pointer-coarse:opacity-100 focus-within:opacity-100 group-hover/assistant:opacity-100",
1740 - className,
1741 - )}
1742 - >
1743 - {projectedItem && projectedItem.item.status !== "completed" ? (
1744 - <span className="rounded-full border border-border/70 px-1.5 py-0.5 font-mono text-3xs text-muted-foreground">
1745 - {projectedItem.item.status}
1746 - </span>
1747 - ) : null}
1748 - <AssistantCopyButton
1749 - message={message}
1750 - showCopyButton={showCopyButton}
1751 - streaming={copyStreaming}
1752 - />
1753 - {projectedItem?.item.type === "assistant_message" ? (
1754 - <AssistantForkButton projectedItem={projectedItem} />
1755 - ) : null}
1756 - {!message.streaming && (
1757 - <Tooltip>
1758 - <TooltipTrigger render={<p className="text-muted-foreground text-xs tabular-nums" />}>
1759 - {formatDayAwareTimestamp(message.updatedAt, ctx.timestampFormat)}
1760 - </TooltipTrigger>
1761 - <TooltipPopup>
1762 - {formatChatTimestampTooltip(message.updatedAt, ctx.timestampFormat)}
1763 - </TooltipPopup>
1764 - </Tooltip>
1765 - )}
1766 - </div>
1767 - );
1768 -}
1769 -
1770 -function AssistantCopyButton({
1771 - message,
1772 - showCopyButton,
1773 - streaming,
1774 -}: {
1775 - message: ChatMessage;
1776 - showCopyButton: boolean;
1777 - streaming: boolean;
1778 -}) {
1779 - const assistantCopyState = resolveAssistantMessageCopyState({
1780 - text: message.text ?? null,
1781 - showCopyButton,
1782 - streaming,
1783 - });
1784 -
1785 - if (!assistantCopyState.visible) {
1786 - return null;
1787 - }
1788 -
1789 - return <MessageCopyButton text={assistantCopyState.text ?? ""} variant="ghost" />;
1790 -}
1791 -
1792 -function ProposedPlanTimelineRow({
1793 - row,
1794 -}: {
1795 - row: Extract<TimelineRow, { kind: "proposed-plan" }>;
1796 -}) {
1797 - const ctx = use(TimelineRowCtx);
1798 -
1799 - return (
1800 - <div className="min-w-0 px-1 py-0.5">
1801 - <ProposedPlanCard
1802 - planMarkdown={row.proposedPlan.planMarkdown}
1803 - environmentId={ctx.activeThreadEnvironmentId}
1804 - threadRef={ctx.threadRef ?? undefined}
1805 - cwd={ctx.markdownCwd}
1806 - workspaceRoot={ctx.workspaceRoot}
1807 - findActive={ctx.findActive}
1808 - />
1809 - </div>
1810 - );
1811 -}
1812 -
1813 -function HtmlRenderTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "html-render" }> }) {
1814 - const ctx = use(TimelineRowCtx);
1815 - const { onAppFullscreenChange } = ctx;
1816 - const onFullscreenChange = (fullscreen: boolean) => onAppFullscreenChange(row.id, fullscreen);
1817 -
1818 - return (
1819 - <div className="min-w-0 px-1">
1820 - <HtmlRenderFrame
1821 - key={row.htmlRender.attachmentId}
1822 - environmentId={ctx.activeThreadEnvironmentId}
1823 - htmlRender={row.htmlRender}
1824 - threadRef={ctx.threadRef ?? undefined}
1825 - onFullscreenChange={onFullscreenChange}
1826 - />
1827 - </div>
1828 - );
1829 -}
1830 -
1831 -function McpAppTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "mcp-app" }> }) {
1832 - const ctx = use(TimelineRowCtx);
1833 - const { awaitingUser } = use(TimelineRowActivityCtx);
1834 -
1835 - return (
1836 - <div className="min-w-0 px-1">
1837 - <McpAppFrame
1838 - key={row.mcpApp.attachmentId}
1839 - environmentId={ctx.activeThreadEnvironmentId}
1840 - threadId={row.sourceThreadId}
1841 - conversationThreadId={ctx.threadRef?.threadId ?? row.sourceThreadId}
1842 - itemId={row.itemId}
1843 - revision={row.revision}
1844 - app={row.mcpApp}
1845 - onSendMessage={ctx.onSendAppMessage}
1846 - awaitingUser={awaitingUser}
1847 - onFullscreenChange={(fullscreen) => ctx.onAppFullscreenChange(row.id, fullscreen)}
1848 - />
1849 - </div>
1850 - );
1851 -}
1852 -
1853 -type V2EventTone = "muted" | "warning" | "danger" | "success";
1854 -
1855 -function v2EventPresentation(item: OrchestrationV2TurnItem): {
1856 - readonly label: string;
1857 - readonly detail: string | null;
1858 - readonly tone: V2EventTone;
1859 - readonly icon: LucideIcon;
1860 -} {
1861 - switch (item.type) {
1862 - case "error": {
1863 - const presentation = providerErrorPresentation(item);
1864 - return {
1865 - ...presentation,
1866 - tone:
1867 - item.status === "completed"
1868 - ? "success"
1869 - : item.status === "running" || item.failure.class === "usage_limit"
1870 - ? "warning"
1871 - : "danger",
1872 - icon: CircleAlertIcon,
1873 - };
1874 - }
1875 - case "run_interrupt_request":
1876 - return {
1877 - label: "Interrupt requested",
1878 - detail: item.message,
1879 - tone: "warning",
1880 - icon: CircleAlertIcon,
1881 - };
1882 - case "run_interrupt_result":
1883 - return {
1884 - label: "Run interrupted",
1885 - detail: item.message,
1886 - tone: "danger",
1887 - icon: XIcon,
1888 - };
1889 - case "handoff":
1890 - return {
1891 - label: "Context handoff",
1892 - detail:
1893 - item.summary ??
1894 - `${item.fromProviderInstanceIds.join(", ")} → ${item.toProviderInstanceId}`,
1895 - tone: item.status === "failed" ? "danger" : "muted",
1896 - icon: ZapIcon,
1897 - };
1898 - case "fork":
1899 - return {
1900 - label: "Conversation fork",
1901 - detail: `Continues in ${item.targetThreadId}`,
1902 - tone: "muted",
1903 - icon: GitForkIcon,
1904 - };
1905 - case "compaction": {
1906 - const tokenSummary =
1907 - item.beforeTokenCount === undefined && item.afterTokenCount === undefined
1908 - ? null
1909 - : `${item.beforeTokenCount ?? "?"} → ${item.afterTokenCount ?? "?"} tokens`;
1910 - return {
1911 - label: "Context compacted",
1912 - detail: item.summary ?? tokenSummary,
1913 - tone: item.status === "failed" ? "danger" : "muted",
1914 - icon: MinusIcon,
1915 - };
1916 - }
1917 - case "todo_list": {
1918 - const steps = item.steps.map((step) => `${step.status}: ${step.text}`).join("\n");
1919 - return {
1920 - label: "Plan updated",
1921 - detail: [item.explanation, steps].filter(Boolean).join("\n\n") || null,
1922 - tone: item.status === "failed" ? "danger" : "success",
1923 - icon: CheckIcon,
1924 - };
1925 - }
1926 - default:
1927 - return {
1928 - label: item.title?.trim() || item.type.replaceAll("_", " "),
1929 - detail: null,
1930 - tone: item.status === "failed" ? "danger" : "muted",
1931 - icon: WrenchIcon,
1932 - };
1933 - }
1934 -}
1935 -
1936 -function V2EventTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "event" }> }) {
1937 - const ctx = use(TimelineRowCtx);
1938 - const { item, visibility, sourceThreadId } = row.projectedItem;
1939 - if (item.type === "subagent" && (row.subagents?.length ?? 1) > 1) {
1940 - return <V2SubagentGroup key={row.id} row={row} />;
1941 - }
1942 - if (item.type === "secret_request") {
1943 - return (
1944 - <SecretRequestCard
1945 - environmentId={ctx.activeThreadEnvironmentId}
1946 - item={item}
1947 - visibility={visibility}
1948 - />
1949 - );
1950 - }
1951 - if (isV2LifecycleItem(item)) {
1952 - return (
1953 - <V2LifecycleRow
1954 - environmentId={ctx.activeThreadEnvironmentId}
1955 - item={item}
1956 - resourceSummary={row.resourceSummary}
1957 - createdAt={row.createdAt}
1958 - timestampFormat={ctx.timestampFormat}
1959 - runs={ctx.runs}
1960 - onOpenThread={ctx.onOpenThread}
1961 - />
1962 - );
1963 - }
1964 - const presentation = v2EventPresentation(item);
1965 - const Icon = presentation.icon;
1966 - if (item.type === "error") {
1967 - return (
1968 - <details
1969 - className={cn(
1970 - "group rounded-md border",
1971 - presentation.tone === "warning" && "border-warning/25 bg-warning/5",
1972 - presentation.tone === "danger" && "border-destructive/25 bg-destructive/5",
1973 - presentation.tone === "success" && "border-success/20 bg-success/5",
1974 - )}
1975 - data-v2-item-type={item.type}
1976 - data-v2-item-visibility={visibility}
1977 - data-v2-event-disclosure="true"
1978 - >
1979 - <summary className="flex min-w-0 cursor-pointer list-none items-center gap-2 px-2.5 py-1.5 text-xs [&::-webkit-details-marker]:hidden">
1980 - <Icon
1981 - className={cn(
1982 - "size-3.5 shrink-0",
1983 - presentation.tone === "warning" && "text-warning",
1984 - presentation.tone === "danger" && "text-destructive",
1985 - presentation.tone === "success" && "text-success",
1986 - )}
1987 - />
1988 - <span className="shrink-0 font-medium text-foreground/90">{presentation.label}</span>
1989 - {item.status !== "completed" ? (
1990 - <span
1991 - className={cn(
1992 - "shrink-0 rounded-full border px-1.5 py-0.5 font-mono text-3xs",
1993 - item.status === "failed"
1994 - ? "border-destructive/40 text-destructive"
1995 - : "border-border/70 text-muted-foreground",
1996 - )}
1997 - >
1998 - {item.status}
1999 - </span>
2000 - ) : null}
2001 - {presentation.detail ? (
2002 - <span className="min-w-0 flex-1 truncate text-muted-foreground/65">
2003 - {presentation.detail}
2004 - </span>
2005 - ) : null}
2006 - {visibility !== "local" ? (
2007 - <span className="shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-3xs text-muted-foreground">
2008 - {visibility === "inherited" ? "Inherited" : "Synthetic"}
2009 - </span>
2010 - ) : null}
2011 - <ChevronDownIcon className="size-3 shrink-0 text-muted-foreground/60 transition-transform group-open:rotate-180" />
2012 - </summary>
2013 - <div className="border-t border-border/45 px-3 py-2 ps-8">
2014 - {presentation.detail ? (
2015 - <div className="text-xs leading-relaxed text-muted-foreground">
2016 - <ChatMarkdown
2017 - text={presentation.detail}
2018 - cwd={ctx.markdownCwd}
2019 - threadRef={ctx.threadRef ?? undefined}
2020 - skills={ctx.skills}
2021 - lineBreaks
2022 - />
2023 - </div>
2024 - ) : null}
2025 - {visibility === "inherited" ? (
2026 - <p className="mt-1 font-mono text-3xs text-muted-foreground/65">
2027 - From {sourceThreadId}
2028 - </p>
2029 - ) : null}
2030 - <div className={presentation.detail ? "mt-2" : undefined}>
2031 - <V2ItemInspector
2032 - projectedItem={row.projectedItem}
2033 - environmentId={ctx.activeThreadEnvironmentId}
2034 - cwd={ctx.markdownCwd}
2035 - workspaceRoot={ctx.workspaceRoot}
2036 - onOpenThread={ctx.onOpenThread}
2037 - onOpenTurnDiff={ctx.onOpenTurnDiff}
2038 - onRollbackCheckpoint={ctx.onRollbackCheckpoint}
2039 - onImageExpand={ctx.onImageExpand}
2040 - />
2041 - </div>
2042 - </div>
2043 - </details>
2044 - );
2045 - }
2046 - return (
2047 - <section
2048 - className={cn(
2049 - "rounded-lg border px-3 py-2",
2050 - presentation.tone === "warning" && "border-warning/25 bg-warning/5",
2051 - presentation.tone === "danger" && "border-destructive/25 bg-destructive/5",
2052 - presentation.tone === "success" && "border-success/20 bg-success/5",
2053 - presentation.tone === "muted" && "border-border/60 bg-card/30",
2054 - )}
2055 - data-v2-item-type={item.type}
2056 - data-v2-item-visibility={visibility}
2057 - >
2058 - <div className="flex items-start gap-2.5">
2059 - <Icon
2060 - className={cn(
2061 - "mt-0.5 size-3.5 shrink-0",
2062 - presentation.tone === "warning" && "text-warning",
2063 - presentation.tone === "danger" && "text-destructive",
2064 - presentation.tone === "success" && "text-success",
2065 - presentation.tone === "muted" && "text-muted-foreground",
2066 - )}
2067 - />
2068 - <div className="min-w-0 flex-1">
2069 - <div className="flex flex-wrap items-center gap-x-2 gap-y-1">
2070 - <span className="text-xs font-medium text-foreground/90">{presentation.label}</span>
2071 - {item.status !== "completed" ? (
2072 - <span
2073 - className={cn(
2074 - "rounded-full border px-1.5 py-0.5 font-mono text-3xs",
2075 - item.status === "failed"
2076 - ? "border-destructive/40 text-destructive"
2077 - : "border-border/70 text-muted-foreground",
2078 - )}
2079 - >
2080 - {item.status}
2081 - </span>
2082 - ) : null}
2083 - {visibility !== "local" ? (
2084 - <span className="rounded-full bg-muted px-1.5 py-0.5 text-3xs text-muted-foreground">
2085 - {visibility === "inherited" ? "Inherited" : "Synthetic"}
2086 - </span>
2087 - ) : null}
2088 - </div>
2089 - {presentation.detail ? (
2090 - <div className="mt-1 text-xs leading-relaxed text-muted-foreground">
2091 - <ChatMarkdown
2092 - text={presentation.detail}
2093 - cwd={ctx.markdownCwd}
2094 - threadRef={ctx.threadRef ?? undefined}
2095 - skills={ctx.skills}
2096 - lineBreaks
2097 - />
2098 - </div>
2099 - ) : null}
2100 - {visibility === "inherited" ? (
2101 - <p className="mt-1 font-mono text-3xs text-muted-foreground/65">
2102 - From {sourceThreadId}
2103 - </p>
2104 - ) : null}
2105 - <div className="mt-2">
2106 - <V2ItemInspector
2107 - projectedItem={row.projectedItem}
2108 - environmentId={ctx.activeThreadEnvironmentId}
2109 - cwd={ctx.markdownCwd}
2110 - workspaceRoot={ctx.workspaceRoot}
2111 - onOpenThread={ctx.onOpenThread}
2112 - onOpenTurnDiff={ctx.onOpenTurnDiff}
2113 - onRollbackCheckpoint={ctx.onRollbackCheckpoint}
2114 - onImageExpand={ctx.onImageExpand}
2115 - />
2116 - </div>
2117 - </div>
2118 - </div>
2119 - </section>
2120 - );
2121 -}
2122 -
2123 -function subagentGroupTiming(
2124 - agents: ReadonlyArray<{
2125 - status: OrchestrationV2TurnItem["status"];
2126 - startedAt: DateTime.Utc | null;
2127 - completedAt: DateTime.Utc | null;
2128 - }>,
2129 -) {
2130 - let startMs: number | null = null;
2131 - let endMs: number | null = null;
2132 - let endUnknown = false;
2133 - for (const agent of agents) {
2134 - if (agent.startedAt) {
2135 - const ms = DateTime.toEpochMillis(agent.startedAt);
2136 - startMs = startMs === null ? ms : Math.min(startMs, ms);
2137 - }
2138 - if (agent.completedAt) {
2139 - const ms = DateTime.toEpochMillis(agent.completedAt);
2140 - endMs = endMs === null ? ms : Math.max(endMs, ms);
2141 - } else {
2142 - endUnknown = true;
2143 - }
2144 - }
2145 - const live = agents.some(
2146 - ({ status }) => status === "pending" || status === "running" || status === "waiting",
2147 - );
2148 - return {
2149 - status: live ? ("running" as const) : ("completed" as const),
2150 - startedAt: startMs === null ? null : new Date(startMs).toISOString(),
2151 - completedAt: live || endUnknown || endMs === null ? null : new Date(endMs).toISOString(),
2152 - };
2153 -}
2154 -
2155 -const V2SubagentGroup = memo(function V2SubagentGroup({
2156 - row,
2157 -}: {
2158 - row: Extract<TimelineRow, { kind: "event" }>;
2159 -}) {
2160 - const ctx = use(TimelineRowCtx);
2161 - const groupId = `subagent-group:${row.id}`;
2162 - const [expanded, setExpanded] = useState(() =>
2163 - ctx.workGroupViewState.expandedEntries.has(groupId),
2164 - );
2165 - const members = (row.subagents ?? [row.projectedItem]).flatMap(({ item }) =>
2166 - item.type === "subagent" ? [item] : [],
2167 - );
2168 - const liveAgents = useAtomValue(
2169 - environmentThreadDetails.threadAtom(
2170 - scopeThreadRef(ctx.activeThreadEnvironmentId, row.projectedItem.item.threadId),
2171 - ),
2172 - (thread) => thread?.projection.subagents,
2173 - );
2174 - const agents = members.map((item) => {
2175 - const live = liveAgents?.find((agent) => agent.id === item.subagentId);
2176 - return {
2177 - item,
2178 - status: live?.status ?? item.status,
2179 - startedAt: live?.startedAt ?? item.startedAt,
2180 - completedAt: live?.completedAt ?? item.completedAt,
2181 - };
2182 - });
2183 - const summary = subagentGroupSummary(agents);
2184 - const label = `${members.length} ${members.length === 1 ? "subagent" : "subagents"}`;
2185 - const statusSummary = summarizeSubagentStatuses(agents.map(({ status }) => status));
2186 - const toggleExpanded = (open: boolean) => {
2187 - ctx.onToggleWorkEntry(row.id, expanded);
2188 - if (open) ctx.workGroupViewState.expandedEntries.add(groupId);
2189 - else ctx.workGroupViewState.expandedEntries.delete(groupId);
2190 - setExpanded(open);
2191 - };
2192 - return (
2193 - <WorkLogBlock continues={row.continuesWorkLog}>
2194 - <Collapsible open={expanded} onOpenChange={toggleExpanded} data-subagent-group>
2195 - <CollapsibleTrigger
2196 - aria-label={label}
2197 - aria-description={statusSummary}
2198 - className={cn(
2199 - "flex w-full min-w-0 items-center gap-3 py-2 text-left transition-opacity hover:opacity-100",
2200 - expanded || summary.active
2201 - ? "text-foreground opacity-100"
2202 - : "text-muted-foreground opacity-55",
2203 - )}
2204 - >
2205 - <span className="flex shrink-0 items-center -space-x-1.5" aria-hidden>
2206 - {agents.slice(0, 3).map(({ item, status }) => (
2207 - <EnvironmentSubagentAvatar
2208 - key={item.id}
2209 - environmentId={ctx.activeThreadEnvironmentId}
2210 - providerInstanceId={item.providerInstanceId}
2211 - driver={item.driver}
2212 - status={agents.length === 1 ? status : undefined}
2213 - />
2214 - ))}
2215 - {agents.length > 3 ? (
2216 - <span className="relative inline-flex size-6 items-center justify-center rounded-full bg-muted text-3xs font-medium text-muted-foreground ring-2 ring-background">
2217 - +{agents.length - 3}
2218 - </span>
2219 - ) : null}
2220 - </span>
2221 - <span className="min-w-0 flex-1">
2222 - <span className="block text-xs font-semibold">{label}</span>
2223 - <span
2224 - className={cn(
2225 - "block truncate text-3xs text-muted-foreground",
2226 - summary.active ? "text-info" : summary.failed && "text-destructive",
2227 - )}
2228 - >
2229 - {statusSummary}
2230 - </span>
2231 - </span>
2232 - <span className="shrink-0 text-xs text-muted-foreground tabular-nums">
2233 - <SubagentElapsed agent={subagentGroupTiming(agents)} />
2234 - </span>
2235 - <ChevronDownIcon
2236 - aria-hidden
2237 - className={cn(
2238 - "size-3.5 shrink-0 text-muted-foreground transition-transform",
2239 - expanded && "rotate-180",
2240 - )}
2241 - />
2242 - </CollapsibleTrigger>
2243 - {/* Virtualized rows must settle before disclosure scroll anchoring resumes. */}
2244 - <CollapsiblePanel animate={false}>
2245 - {expanded ? (
2246 - <div className="mt-1 mb-1 rounded-lg border border-border/60 bg-card/30 p-1">
2247 - {members.map((item) => (
2248 - <V2LifecycleRow
2249 - environmentId={ctx.activeThreadEnvironmentId}
2250 - key={item.id}
2251 - item={item}
2252 - createdAt={row.createdAt}
2253 - timestampFormat={ctx.timestampFormat}
2254 - runs={ctx.runs}
2255 - onOpenThread={ctx.onOpenThread}
2256 - />
2257 - ))}
2258 - </div>
2259 - ) : null}
2260 - </CollapsiblePanel>
2261 - </Collapsible>
2262 - </WorkLogBlock>
2263 - );
2264 -});
2265 -
2266 -/** Subscribes directly to the UI state store for expand/collapse state,
2267 - * so toggling re-renders only this component — not the entire list. */
2268 -const AssistantChangedFilesSection = memo(function AssistantChangedFilesSection({
2269 - turnSummary,
2270 - routeThreadKey,
2271 - resolvedTheme,
2272 - onOpenTurnDiff,
2273 -}: {
2274 - turnSummary: TurnDiffSummary | undefined;
2275 - routeThreadKey: string;
2276 - resolvedTheme: "light" | "dark";
2277 - displayThreadKey?: string;
2278 - onOpenTurnDiff: (runId: RunId, filePath?: string) => void;
2279 -}) {
2280 - if (!turnSummary) return null;
2281 - const checkpointFiles = turnSummary.files;
2282 - if (checkpointFiles.length === 0) return null;
2283 -
2284 - return (
2285 - <AssistantChangedFilesSectionInner
2286 - turnSummary={turnSummary}
2287 - checkpointFiles={checkpointFiles}
2288 - routeThreadKey={routeThreadKey}
2289 - resolvedTheme={resolvedTheme}
2290 - onOpenTurnDiff={onOpenTurnDiff}
2291 - />
2292 - );
2293 -});
2294 -
2295 -function AssistantChangedFilesSectionInner({
2296 - turnSummary,
2297 - checkpointFiles,
2298 - routeThreadKey,
2299 - resolvedTheme,
2300 - onOpenTurnDiff,
2301 -}: {
2302 - turnSummary: TurnDiffSummary;
2303 - checkpointFiles: TurnDiffSummary["files"];
2304 - routeThreadKey: string;
2305 - resolvedTheme: "light" | "dark";
2306 - displayThreadKey?: string;
2307 - onOpenTurnDiff: (runId: RunId, filePath?: string) => void;
2308 -}) {
2309 - const ctx = use(TimelineRowCtx);
2310 - const persistedExpanded = useUiStateStore(
2311 - (store) => store.threadChangedFilesExpandedById[routeThreadKey]?.[turnSummary.runId],
2312 - );
2313 - const setExpanded = useUiStateStore((store) => store.setThreadChangedFilesExpanded);
2314 - const allDirectoriesExpanded = persistedExpanded ?? false;
2315 -
2316 - const thread = useThreadShell(ctx.threadRef);
2317 - const activeProject = useProject(
2318 - thread && thread.projectId
2319 - ? { environmentId: thread.environmentId, projectId: thread.projectId }
2320 - : null,
2321 - );
2322 - const onFileContextMenu = useFileContextMenuHandler(ctx.activeThreadEnvironmentId);
2323 -
2324 - return (
2325 - <ChangedFilesCard
2326 - runId={turnSummary.runId}
2327 - files={checkpointFiles}
2328 - allDirectoriesExpanded={allDirectoriesExpanded}
2329 - resolvedTheme={resolvedTheme}
2330 - onToggleAllDirectories={() =>
2331 - setExpanded(routeThreadKey, turnSummary.runId, !allDirectoriesExpanded)
2332 - }
2333 - onOpenTurnDiff={onOpenTurnDiff}
2334 - onFileContextMenu={(filePath, event) =>
2335 - onFileContextMenu(
2336 - {
2337 - environmentId: ctx.activeThreadEnvironmentId,
2338 - filePath,
2339 - workspaceRoot: ctx.workspaceRoot,
2340 - repositoryRoot:
2341 - thread?.worktreePath == null
2342 - ? activeProject?.repositoryIdentity?.rootPath
2343 - : undefined,
2344 - },
2345 - event,
2346 - )
2347 - }
2348 - />
2349 - );
2350 -}
2351 -
1560 function handoffRunsSignature(runs: ReadonlyArray<HandoffTimelineRun>): string {
1561 return runs
1562 .map(
apps/web/src/components/chat/TimelineAssistantRows.tsx new
+366
@@ -0,0 +1,366 @@
1 +import { shouldPreserveAssistantLineBreaks } from "@t3tools/shared/markdownPipeline";
2 +import { type RunId } from "@t3tools/contracts";
3 +import { canForkProjectedAssistantItem } from "@t3tools/client-runtime/state/thread-workflows";
4 +import { memo, use, useState } from "react";
5 +import { type ChatMessage, type TurnDiffSummary } from "../../types";
6 +import ChatMarkdown from "../ChatMarkdown";
7 +import { GitForkIcon } from "lucide-react";
8 +import { Button } from "../ui/button";
9 +import { ProposedPlanCard } from "./ProposedPlanCard";
10 +import { HtmlRenderFrame } from "./HtmlRenderFrame";
11 +import { McpAppFrame } from "./McpAppFrame";
12 +import { ChangedFilesCard } from "./ChangedFilesTree";
13 +import { useFileContextMenuHandler } from "../../fileContextMenu";
14 +import { useProject, useThreadShell } from "../../state/entities";
15 +import { MessageCopyButton } from "./MessageCopyButton";
16 +import { AssistantCitationSource } from "./AssistantCitationSource";
17 +import { resolveAssistantMessageCopyState } from "./MessagesTimeline.logic";
18 +import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
19 +import { cn } from "~/lib/utils";
20 +import { useUiStateStore } from "~/uiStateStore";
21 +import { formatChatTimestampTooltip, formatDayAwareTimestamp } from "../../timestampFormat";
22 +import { useV2ItemSupport } from "../../state/v2ItemSupport";
23 +import { TimelineRowCtx, TimelineRowActivityCtx, type TimelineRow } from "./timelineRowContext";
24 +import { MESSAGE_HEADING_LEVEL, MessageAuthorHeading } from "./TimelineRowParts";
25 +
26 +export function AssistantTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message" }> }) {
27 + const ctx = use(TimelineRowCtx);
28 + const messageText = row.message.text || (row.message.streaming ? "" : "(empty response)");
29 +
30 + return (
31 + <>
32 + <div className="relative min-w-0 px-1 py-0.5">
33 + <MessageAuthorHeading>T3 Code</MessageAuthorHeading>
34 + <div data-thread-find-text="true">
35 + <AssistantCitationSource
36 + messageId={row.message.id}
37 + {...(ctx.threadRef ? { threadRef: ctx.threadRef } : {})}
38 + itemKey={row.id}
39 + request={ctx.citationRequest}
40 + listRef={ctx.listRef}
41 + >
42 + <ChatMarkdown
43 + text={messageText}
44 + cwd={ctx.markdownCwd}
45 + threadRef={ctx.threadRef ?? undefined}
46 + isStreaming={Boolean(row.message.streaming)}
47 + lineBreaks={shouldPreserveAssistantLineBreaks(messageText)}
48 + skills={ctx.skills}
49 + headingLevelOffset={MESSAGE_HEADING_LEVEL}
50 + onUseArtifactTemplate={ctx.onUseArtifactTemplate}
51 + onRunShellCommand={ctx.onRunShellCommand}
52 + onImageExpand={ctx.onImageExpand}
53 + />
54 + </AssistantCitationSource>
55 + </div>
56 + <AssistantChangedFilesSection
57 + turnSummary={row.assistantTurnDiffSummary}
58 + routeThreadKey={ctx.routeThreadKey}
59 + resolvedTheme={ctx.resolvedTheme}
60 + onOpenTurnDiff={ctx.onOpenTurnDiff}
61 + />
62 + {row.showAssistantMeta ? (
63 + <AssistantMessageMeta
64 + className="mt-1.5"
65 + projectedItem={row.projectedItem}
66 + message={row.message}
67 + showCopyButton={row.showAssistantCopyButton}
68 + copyStreaming={row.assistantCopyStreaming}
69 + />
70 + ) : null}
71 + </div>
72 + </>
73 + );
74 +}
75 +
76 +function AssistantForkButton({
77 + projectedItem,
78 +}: {
79 + readonly projectedItem: NonNullable<Extract<TimelineRow, { kind: "message" }>["projectedItem"]>;
80 +}) {
81 + const ctx = use(TimelineRowCtx);
82 + const [busy, setBusy] = useState(false);
83 + const support = useV2ItemSupport({
84 + environmentId: ctx.activeThreadEnvironmentId,
85 + sourceThreadId: projectedItem.sourceThreadId,
86 + sourceItemId: projectedItem.sourceItemId,
87 + });
88 + const canFork = canForkProjectedAssistantItem({
89 + projectedItem,
90 + capabilities: support.providerSession?.capabilities,
91 + });
92 +
93 + if (!canFork || projectedItem.item.runId === null) return null;
94 + const runId = projectedItem.item.runId;
95 +
96 + return (
97 + <Tooltip>
98 + <TooltipTrigger
99 + render={
100 + <Button
101 + type="button"
102 + size="xs"
103 + variant="ghost"
104 + disabled={busy}
105 + onClick={() => {
106 + setBusy(true);
107 + void ctx
108 + .onForkFromRun({ sourceThreadId: projectedItem.sourceThreadId, runId })
109 + .finally(() => setBusy(false));
110 + }}
111 + aria-label="Fork from this response"
112 + />
113 + }
114 + >
115 + <GitForkIcon className={cn("size-3", busy && "animate-pulse")} />
116 + </TooltipTrigger>
117 + <TooltipPopup side="top">Fork from this response</TooltipPopup>
118 + </Tooltip>
119 + );
120 +}
121 +
122 +export function AssistantMetaTimelineRow({
123 + row,
124 +}: {
125 + row: Extract<TimelineRow, { kind: "assistant-meta" }>;
126 +}) {
127 + return (
128 + <div className="px-1">
129 + <AssistantMessageMeta
130 + className="mt-0.5"
131 + projectedItem={row.projectedItem}
132 + message={row.message}
133 + showCopyButton={row.showAssistantCopyButton}
134 + copyStreaming={row.assistantCopyStreaming}
135 + alwaysVisible
136 + />
137 + </div>
138 + );
139 +}
140 +
141 +function AssistantMessageMeta({
142 + className,
143 + projectedItem,
144 + message,
145 + showCopyButton,
146 + copyStreaming,
147 + alwaysVisible = false,
148 +}: {
149 + className?: string;
150 + projectedItem?: Extract<TimelineRow, { kind: "message" }>["projectedItem"];
151 + message: ChatMessage;
152 + showCopyButton: boolean;
153 + copyStreaming: boolean;
154 + alwaysVisible?: boolean;
155 +}) {
156 + const ctx = use(TimelineRowCtx);
157 +
158 + return (
159 + <div
160 + className={cn(
161 + "flex items-center gap-2 text-xs tabular-nums transition-opacity duration-200",
162 + alwaysVisible
163 + ? "opacity-100"
164 + : "opacity-0 pointer-coarse:opacity-100 focus-within:opacity-100 group-hover/assistant:opacity-100",
165 + className,
166 + )}
167 + >
168 + {projectedItem && projectedItem.item.status !== "completed" ? (
169 + <span className="rounded-full border border-border/70 px-1.5 py-0.5 font-mono text-3xs text-muted-foreground">
170 + {projectedItem.item.status}
171 + </span>
172 + ) : null}
173 + <AssistantCopyButton
174 + message={message}
175 + showCopyButton={showCopyButton}
176 + streaming={copyStreaming}
177 + />
178 + {projectedItem?.item.type === "assistant_message" ? (
179 + <AssistantForkButton projectedItem={projectedItem} />
180 + ) : null}
181 + {!message.streaming && (
182 + <Tooltip>
183 + <TooltipTrigger render={<p className="text-muted-foreground text-xs tabular-nums" />}>
184 + {formatDayAwareTimestamp(message.updatedAt, ctx.timestampFormat)}
185 + </TooltipTrigger>
186 + <TooltipPopup>
187 + {formatChatTimestampTooltip(message.updatedAt, ctx.timestampFormat)}
188 + </TooltipPopup>
189 + </Tooltip>
190 + )}
191 + </div>
192 + );
193 +}
194 +
195 +function AssistantCopyButton({
196 + message,
197 + showCopyButton,
198 + streaming,
199 +}: {
200 + message: ChatMessage;
201 + showCopyButton: boolean;
202 + streaming: boolean;
203 +}) {
204 + const assistantCopyState = resolveAssistantMessageCopyState({
205 + text: message.text ?? null,
206 + showCopyButton,
207 + streaming,
208 + });
209 +
210 + if (!assistantCopyState.visible) {
211 + return null;
212 + }
213 +
214 + return <MessageCopyButton text={assistantCopyState.text ?? ""} variant="ghost" />;
215 +}
216 +
217 +export function ProposedPlanTimelineRow({
218 + row,
219 +}: {
220 + row: Extract<TimelineRow, { kind: "proposed-plan" }>;
221 +}) {
222 + const ctx = use(TimelineRowCtx);
223 +
224 + return (
225 + <div className="min-w-0 px-1 py-0.5">
226 + <ProposedPlanCard
227 + planMarkdown={row.proposedPlan.planMarkdown}
228 + environmentId={ctx.activeThreadEnvironmentId}
229 + threadRef={ctx.threadRef ?? undefined}
230 + cwd={ctx.markdownCwd}
231 + workspaceRoot={ctx.workspaceRoot}
232 + findActive={ctx.findActive}
233 + />
234 + </div>
235 + );
236 +}
237 +
238 +export function HtmlRenderTimelineRow({
239 + row,
240 +}: {
241 + row: Extract<TimelineRow, { kind: "html-render" }>;
242 +}) {
243 + const ctx = use(TimelineRowCtx);
244 + const { onAppFullscreenChange } = ctx;
245 + const onFullscreenChange = (fullscreen: boolean) => onAppFullscreenChange(row.id, fullscreen);
246 +
247 + return (
248 + <div className="min-w-0 px-1">
249 + <HtmlRenderFrame
250 + key={row.htmlRender.attachmentId}
251 + environmentId={ctx.activeThreadEnvironmentId}
252 + htmlRender={row.htmlRender}
253 + threadRef={ctx.threadRef ?? undefined}
254 + onFullscreenChange={onFullscreenChange}
255 + />
256 + </div>
257 + );
258 +}
259 +
260 +export function McpAppTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "mcp-app" }> }) {
261 + const ctx = use(TimelineRowCtx);
262 + const { awaitingUser } = use(TimelineRowActivityCtx);
263 +
264 + return (
265 + <div className="min-w-0 px-1">
266 + <McpAppFrame
267 + key={row.mcpApp.attachmentId}
268 + environmentId={ctx.activeThreadEnvironmentId}
269 + threadId={row.sourceThreadId}
270 + conversationThreadId={ctx.threadRef?.threadId ?? row.sourceThreadId}
271 + itemId={row.itemId}
272 + revision={row.revision}
273 + app={row.mcpApp}
274 + onSendMessage={ctx.onSendAppMessage}
275 + awaitingUser={awaitingUser}
276 + onFullscreenChange={(fullscreen) => ctx.onAppFullscreenChange(row.id, fullscreen)}
277 + />
278 + </div>
279 + );
280 +}
281 +
282 +/** Subscribes directly to the UI state store for expand/collapse state,
283 + * so toggling re-renders only this component — not the entire list. */
284 +const AssistantChangedFilesSection = memo(function AssistantChangedFilesSection({
285 + turnSummary,
286 + routeThreadKey,
287 + resolvedTheme,
288 + onOpenTurnDiff,
289 +}: {
290 + turnSummary: TurnDiffSummary | undefined;
291 + routeThreadKey: string;
292 + resolvedTheme: "light" | "dark";
293 + displayThreadKey?: string;
294 + onOpenTurnDiff: (runId: RunId, filePath?: string) => void;
295 +}) {
296 + if (!turnSummary) return null;
297 + const checkpointFiles = turnSummary.files;
298 + if (checkpointFiles.length === 0) return null;
299 +
300 + return (
301 + <AssistantChangedFilesSectionInner
302 + turnSummary={turnSummary}
303 + checkpointFiles={checkpointFiles}
304 + routeThreadKey={routeThreadKey}
305 + resolvedTheme={resolvedTheme}
306 + onOpenTurnDiff={onOpenTurnDiff}
307 + />
308 + );
309 +});
310 +
311 +function AssistantChangedFilesSectionInner({
312 + turnSummary,
313 + checkpointFiles,
314 + routeThreadKey,
315 + resolvedTheme,
316 + onOpenTurnDiff,
317 +}: {
318 + turnSummary: TurnDiffSummary;
319 + checkpointFiles: TurnDiffSummary["files"];
320 + routeThreadKey: string;
321 + resolvedTheme: "light" | "dark";
322 + displayThreadKey?: string;
323 + onOpenTurnDiff: (runId: RunId, filePath?: string) => void;
324 +}) {
325 + const ctx = use(TimelineRowCtx);
326 + const persistedExpanded = useUiStateStore(
327 + (store) => store.threadChangedFilesExpandedById[routeThreadKey]?.[turnSummary.runId],
328 + );
329 + const setExpanded = useUiStateStore((store) => store.setThreadChangedFilesExpanded);
330 + const allDirectoriesExpanded = persistedExpanded ?? false;
331 +
332 + const thread = useThreadShell(ctx.threadRef);
333 + const activeProject = useProject(
334 + thread && thread.projectId
335 + ? { environmentId: thread.environmentId, projectId: thread.projectId }
336 + : null,
337 + );
338 + const onFileContextMenu = useFileContextMenuHandler(ctx.activeThreadEnvironmentId);
339 +
340 + return (
341 + <ChangedFilesCard
342 + runId={turnSummary.runId}
343 + files={checkpointFiles}
344 + allDirectoriesExpanded={allDirectoriesExpanded}
345 + resolvedTheme={resolvedTheme}
346 + onToggleAllDirectories={() =>
347 + setExpanded(routeThreadKey, turnSummary.runId, !allDirectoriesExpanded)
348 + }
349 + onOpenTurnDiff={onOpenTurnDiff}
350 + onFileContextMenu={(filePath, event) =>
351 + onFileContextMenu(
352 + {
353 + environmentId: ctx.activeThreadEnvironmentId,
354 + filePath,
355 + workspaceRoot: ctx.workspaceRoot,
356 + repositoryRoot:
357 + thread?.worktreePath == null
358 + ? activeProject?.repositoryIdentity?.rootPath
359 + : undefined,
360 + },
361 + event,
362 + )
363 + }
364 + />
365 + );
366 +}
apps/web/src/components/chat/TimelineV2EventRow.logic.ts new
+128
@@ -0,0 +1,128 @@
1 +import { type OrchestrationV2TurnItem } from "@t3tools/contracts";
2 +import { providerErrorPresentation } from "../../session-logic";
3 +import {
4 + CheckIcon,
5 + CircleAlertIcon,
6 + GitForkIcon,
7 + type LucideIcon,
8 + MinusIcon,
9 + WrenchIcon,
10 + XIcon,
11 + ZapIcon,
12 +} from "lucide-react";
13 +import * as DateTime from "effect/DateTime";
14 +
15 +type V2EventTone = "muted" | "warning" | "danger" | "success";
16 +
17 +export function v2EventPresentation(item: OrchestrationV2TurnItem): {
18 + readonly label: string;
19 + readonly detail: string | null;
20 + readonly tone: V2EventTone;
21 + readonly icon: LucideIcon;
22 +} {
23 + switch (item.type) {
24 + case "error": {
25 + const presentation = providerErrorPresentation(item);
26 + return {
27 + ...presentation,
28 + tone:
29 + item.status === "completed"
30 + ? "success"
31 + : item.status === "running" || item.failure.class === "usage_limit"
32 + ? "warning"
33 + : "danger",
34 + icon: CircleAlertIcon,
35 + };
36 + }
37 + case "run_interrupt_request":
38 + return {
39 + label: "Interrupt requested",
40 + detail: item.message,
41 + tone: "warning",
42 + icon: CircleAlertIcon,
43 + };
44 + case "run_interrupt_result":
45 + return {
46 + label: "Run interrupted",
47 + detail: item.message,
48 + tone: "danger",
49 + icon: XIcon,
50 + };
51 + case "handoff":
52 + return {
53 + label: "Context handoff",
54 + detail:
55 + item.summary ??
56 + `${item.fromProviderInstanceIds.join(", ")} → ${item.toProviderInstanceId}`,
57 + tone: item.status === "failed" ? "danger" : "muted",
58 + icon: ZapIcon,
59 + };
60 + case "fork":
61 + return {
62 + label: "Conversation fork",
63 + detail: `Continues in ${item.targetThreadId}`,
64 + tone: "muted",
65 + icon: GitForkIcon,
66 + };
67 + case "compaction": {
68 + const tokenSummary =
69 + item.beforeTokenCount === undefined && item.afterTokenCount === undefined
70 + ? null
71 + : `${item.beforeTokenCount ?? "?"} → ${item.afterTokenCount ?? "?"} tokens`;
72 + return {
73 + label: "Context compacted",
74 + detail: item.summary ?? tokenSummary,
75 + tone: item.status === "failed" ? "danger" : "muted",
76 + icon: MinusIcon,
77 + };
78 + }
79 + case "todo_list": {
80 + const steps = item.steps.map((step) => `${step.status}: ${step.text}`).join("\n");
81 + return {
82 + label: "Plan updated",
83 + detail: [item.explanation, steps].filter(Boolean).join("\n\n") || null,
84 + tone: item.status === "failed" ? "danger" : "success",
85 + icon: CheckIcon,
86 + };
87 + }
88 + default:
89 + return {
90 + label: item.title?.trim() || item.type.replaceAll("_", " "),
91 + detail: null,
92 + tone: item.status === "failed" ? "danger" : "muted",
93 + icon: WrenchIcon,
94 + };
95 + }
96 +}
97 +
98 +export function subagentGroupTiming(
99 + agents: ReadonlyArray<{
100 + status: OrchestrationV2TurnItem["status"];
101 + startedAt: DateTime.Utc | null;
102 + completedAt: DateTime.Utc | null;
103 + }>,
104 +) {
105 + let startMs: number | null = null;
106 + let endMs: number | null = null;
107 + let endUnknown = false;
108 + for (const agent of agents) {
109 + if (agent.startedAt) {
110 + const ms = DateTime.toEpochMillis(agent.startedAt);
111 + startMs = startMs === null ? ms : Math.min(startMs, ms);
112 + }
113 + if (agent.completedAt) {
114 + const ms = DateTime.toEpochMillis(agent.completedAt);
115 + endMs = endMs === null ? ms : Math.max(endMs, ms);
116 + } else {
117 + endUnknown = true;
118 + }
119 + }
120 + const live = agents.some(
121 + ({ status }) => status === "pending" || status === "running" || status === "waiting",
122 + );
123 + return {
124 + status: live ? ("running" as const) : ("completed" as const),
125 + startedAt: startMs === null ? null : new Date(startMs).toISOString(),
126 + completedAt: live || endUnknown || endMs === null ? null : new Date(endMs).toISOString(),
127 + };
128 +}
apps/web/src/components/chat/TimelineV2EventRow.tsx new
+321
@@ -0,0 +1,321 @@
1 +import { WorkLogBlock } from "./WorkLog";
2 +import { scopeThreadRef } from "@t3tools/client-runtime/environment";
3 +import { useAtomValue } from "@effect/atom-react";
4 +import { environmentThreadDetails } from "../../state/threads";
5 +import {
6 + subagentGroupSummary,
7 + summarizeSubagentStatuses,
8 +} from "@t3tools/client-runtime/state/subagent-display";
9 +import { memo, use, useState } from "react";
10 +import ChatMarkdown from "../ChatMarkdown";
11 +import { ChevronDownIcon } from "lucide-react";
12 +import { cn } from "~/lib/utils";
13 +import { V2ItemInspector } from "./V2ItemInspector";
14 +import { Collapsible, CollapsibleTrigger, CollapsiblePanel } from "../ui/collapsible";
15 +import {
16 + isV2LifecycleItem,
17 + EnvironmentSubagentAvatar,
18 + SubagentElapsed,
19 + V2LifecycleRow,
20 +} from "./V2LifecycleRow";
21 +import { SecretRequestCard } from "./SecretRequestCard";
22 +import { TimelineRowCtx, type TimelineRow } from "./timelineRowContext";
23 +import { v2EventPresentation, subagentGroupTiming } from "./TimelineV2EventRow.logic";
24 +
25 +export function V2EventTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "event" }> }) {
26 + const ctx = use(TimelineRowCtx);
27 + const { item, visibility, sourceThreadId } = row.projectedItem;
28 + if (item.type === "subagent" && (row.subagents?.length ?? 1) > 1) {
29 + return <V2SubagentGroup key={row.id} row={row} />;
30 + }
31 + if (item.type === "secret_request") {
32 + return (
33 + <SecretRequestCard
34 + environmentId={ctx.activeThreadEnvironmentId}
35 + item={item}
36 + visibility={visibility}
37 + />
38 + );
39 + }
40 + if (isV2LifecycleItem(item)) {
41 + return (
42 + <V2LifecycleRow
43 + environmentId={ctx.activeThreadEnvironmentId}
44 + item={item}
45 + resourceSummary={row.resourceSummary}
46 + createdAt={row.createdAt}
47 + timestampFormat={ctx.timestampFormat}
48 + runs={ctx.runs}
49 + onOpenThread={ctx.onOpenThread}
50 + />
51 + );
52 + }
53 + const presentation = v2EventPresentation(item);
54 + const Icon = presentation.icon;
55 + if (item.type === "error") {
56 + return (
57 + <details
58 + className={cn(
59 + "group rounded-md border",
60 + presentation.tone === "warning" && "border-warning/25 bg-warning/5",
61 + presentation.tone === "danger" && "border-destructive/25 bg-destructive/5",
62 + presentation.tone === "success" && "border-success/20 bg-success/5",
63 + )}
64 + data-v2-item-type={item.type}
65 + data-v2-item-visibility={visibility}
66 + data-v2-event-disclosure="true"
67 + >
68 + <summary className="flex min-w-0 cursor-pointer list-none items-center gap-2 px-2.5 py-1.5 text-xs [&::-webkit-details-marker]:hidden">
69 + <Icon
70 + className={cn(
71 + "size-3.5 shrink-0",
72 + presentation.tone === "warning" && "text-warning",
73 + presentation.tone === "danger" && "text-destructive",
74 + presentation.tone === "success" && "text-success",
75 + )}
76 + />
77 + <span className="shrink-0 font-medium text-foreground/90">{presentation.label}</span>
78 + {item.status !== "completed" ? (
79 + <span
80 + className={cn(
81 + "shrink-0 rounded-full border px-1.5 py-0.5 font-mono text-3xs",
82 + item.status === "failed"
83 + ? "border-destructive/40 text-destructive"
84 + : "border-border/70 text-muted-foreground",
85 + )}
86 + >
87 + {item.status}
88 + </span>
89 + ) : null}
90 + {presentation.detail ? (
91 + <span className="min-w-0 flex-1 truncate text-muted-foreground/65">
92 + {presentation.detail}
93 + </span>
94 + ) : null}
95 + {visibility !== "local" ? (
96 + <span className="shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-3xs text-muted-foreground">
97 + {visibility === "inherited" ? "Inherited" : "Synthetic"}
98 + </span>
99 + ) : null}
100 + <ChevronDownIcon className="size-3 shrink-0 text-muted-foreground/60 transition-transform group-open:rotate-180" />
101 + </summary>
102 + <div className="border-t border-border/45 px-3 py-2 ps-8">
103 + {presentation.detail ? (
104 + <div className="text-xs leading-relaxed text-muted-foreground">
105 + <ChatMarkdown
106 + text={presentation.detail}
107 + cwd={ctx.markdownCwd}
108 + threadRef={ctx.threadRef ?? undefined}
109 + skills={ctx.skills}
110 + lineBreaks
111 + />
112 + </div>
113 + ) : null}
114 + {visibility === "inherited" ? (
115 + <p className="mt-1 font-mono text-3xs text-muted-foreground/65">
116 + From {sourceThreadId}
117 + </p>
118 + ) : null}
119 + <div className={presentation.detail ? "mt-2" : undefined}>
120 + <V2ItemInspector
121 + projectedItem={row.projectedItem}
122 + environmentId={ctx.activeThreadEnvironmentId}
123 + cwd={ctx.markdownCwd}
124 + workspaceRoot={ctx.workspaceRoot}
125 + onOpenThread={ctx.onOpenThread}
126 + onOpenTurnDiff={ctx.onOpenTurnDiff}
127 + onRollbackCheckpoint={ctx.onRollbackCheckpoint}
128 + onImageExpand={ctx.onImageExpand}
129 + />
130 + </div>
131 + </div>
132 + </details>
133 + );
134 + }
135 + return (
136 + <section
137 + className={cn(
138 + "rounded-lg border px-3 py-2",
139 + presentation.tone === "warning" && "border-warning/25 bg-warning/5",
140 + presentation.tone === "danger" && "border-destructive/25 bg-destructive/5",
141 + presentation.tone === "success" && "border-success/20 bg-success/5",
142 + presentation.tone === "muted" && "border-border/60 bg-card/30",
143 + )}
144 + data-v2-item-type={item.type}
145 + data-v2-item-visibility={visibility}
146 + >
147 + <div className="flex items-start gap-2.5">
148 + <Icon
149 + className={cn(
150 + "mt-0.5 size-3.5 shrink-0",
151 + presentation.tone === "warning" && "text-warning",
152 + presentation.tone === "danger" && "text-destructive",
153 + presentation.tone === "success" && "text-success",
154 + presentation.tone === "muted" && "text-muted-foreground",
155 + )}
156 + />
157 + <div className="min-w-0 flex-1">
158 + <div className="flex flex-wrap items-center gap-x-2 gap-y-1">
159 + <span className="text-xs font-medium text-foreground/90">{presentation.label}</span>
160 + {item.status !== "completed" ? (
161 + <span
162 + className={cn(
163 + "rounded-full border px-1.5 py-0.5 font-mono text-3xs",
164 + item.status === "failed"
165 + ? "border-destructive/40 text-destructive"
166 + : "border-border/70 text-muted-foreground",
167 + )}
168 + >
169 + {item.status}
170 + </span>
171 + ) : null}
172 + {visibility !== "local" ? (
173 + <span className="rounded-full bg-muted px-1.5 py-0.5 text-3xs text-muted-foreground">
174 + {visibility === "inherited" ? "Inherited" : "Synthetic"}
175 + </span>
176 + ) : null}
177 + </div>
178 + {presentation.detail ? (
179 + <div className="mt-1 text-xs leading-relaxed text-muted-foreground">
180 + <ChatMarkdown
181 + text={presentation.detail}
182 + cwd={ctx.markdownCwd}
183 + threadRef={ctx.threadRef ?? undefined}
184 + skills={ctx.skills}
185 + lineBreaks
186 + />
187 + </div>
188 + ) : null}
189 + {visibility === "inherited" ? (
190 + <p className="mt-1 font-mono text-3xs text-muted-foreground/65">
191 + From {sourceThreadId}
192 + </p>
193 + ) : null}
194 + <div className="mt-2">
195 + <V2ItemInspector
196 + projectedItem={row.projectedItem}
197 + environmentId={ctx.activeThreadEnvironmentId}
198 + cwd={ctx.markdownCwd}
199 + workspaceRoot={ctx.workspaceRoot}
200 + onOpenThread={ctx.onOpenThread}
201 + onOpenTurnDiff={ctx.onOpenTurnDiff}
202 + onRollbackCheckpoint={ctx.onRollbackCheckpoint}
203 + onImageExpand={ctx.onImageExpand}
204 + />
205 + </div>
206 + </div>
207 + </div>
208 + </section>
209 + );
210 +}
211 +
212 +const V2SubagentGroup = memo(function V2SubagentGroup({
213 + row,
214 +}: {
215 + row: Extract<TimelineRow, { kind: "event" }>;
216 +}) {
217 + const ctx = use(TimelineRowCtx);
218 + const groupId = `subagent-group:${row.id}`;
219 + const [expanded, setExpanded] = useState(() =>
220 + ctx.workGroupViewState.expandedEntries.has(groupId),
221 + );
222 + const members = (row.subagents ?? [row.projectedItem]).flatMap(({ item }) =>
223 + item.type === "subagent" ? [item] : [],
224 + );
225 + const liveAgents = useAtomValue(
226 + environmentThreadDetails.threadAtom(
227 + scopeThreadRef(ctx.activeThreadEnvironmentId, row.projectedItem.item.threadId),
228 + ),
229 + (thread) => thread?.projection.subagents,
230 + );
231 + const agents = members.map((item) => {
232 + const live = liveAgents?.find((agent) => agent.id === item.subagentId);
233 + return {
234 + item,
235 + status: live?.status ?? item.status,
236 + startedAt: live?.startedAt ?? item.startedAt,
237 + completedAt: live?.completedAt ?? item.completedAt,
238 + };
239 + });
240 + const summary = subagentGroupSummary(agents);
241 + const label = `${members.length} ${members.length === 1 ? "subagent" : "subagents"}`;
242 + const statusSummary = summarizeSubagentStatuses(agents.map(({ status }) => status));
243 + const toggleExpanded = (open: boolean) => {
244 + ctx.onToggleWorkEntry(row.id, expanded);
245 + if (open) ctx.workGroupViewState.expandedEntries.add(groupId);
246 + else ctx.workGroupViewState.expandedEntries.delete(groupId);
247 + setExpanded(open);
248 + };
249 + return (
250 + <WorkLogBlock continues={row.continuesWorkLog}>
251 + <Collapsible open={expanded} onOpenChange={toggleExpanded} data-subagent-group>
252 + <CollapsibleTrigger
253 + aria-label={label}
254 + aria-description={statusSummary}
255 + className={cn(
256 + "flex w-full min-w-0 items-center gap-3 py-2 text-left transition-opacity hover:opacity-100",
257 + expanded || summary.active
258 + ? "text-foreground opacity-100"
259 + : "text-muted-foreground opacity-55",
260 + )}
261 + >
262 + <span className="flex shrink-0 items-center -space-x-1.5" aria-hidden>
263 + {agents.slice(0, 3).map(({ item, status }) => (
264 + <EnvironmentSubagentAvatar
265 + key={item.id}
266 + environmentId={ctx.activeThreadEnvironmentId}
267 + providerInstanceId={item.providerInstanceId}
268 + driver={item.driver}
269 + status={agents.length === 1 ? status : undefined}
270 + />
271 + ))}
272 + {agents.length > 3 ? (
273 + <span className="relative inline-flex size-6 items-center justify-center rounded-full bg-muted text-3xs font-medium text-muted-foreground ring-2 ring-background">
274 + +{agents.length - 3}
275 + </span>
276 + ) : null}
277 + </span>
278 + <span className="min-w-0 flex-1">
279 + <span className="block text-xs font-semibold">{label}</span>
280 + <span
281 + className={cn(
282 + "block truncate text-3xs text-muted-foreground",
283 + summary.active ? "text-info" : summary.failed && "text-destructive",
284 + )}
285 + >
286 + {statusSummary}
287 + </span>
288 + </span>
289 + <span className="shrink-0 text-xs text-muted-foreground tabular-nums">
290 + <SubagentElapsed agent={subagentGroupTiming(agents)} />
291 + </span>
292 + <ChevronDownIcon
293 + aria-hidden
294 + className={cn(
295 + "size-3.5 shrink-0 text-muted-foreground transition-transform",
296 + expanded && "rotate-180",
297 + )}
298 + />
299 + </CollapsibleTrigger>
300 + {/* Virtualized rows must settle before disclosure scroll anchoring resumes. */}
301 + <CollapsiblePanel animate={false}>
302 + {expanded ? (
303 + <div className="mt-1 mb-1 rounded-lg border border-border/60 bg-card/30 p-1">
304 + {members.map((item) => (
305 + <V2LifecycleRow
306 + environmentId={ctx.activeThreadEnvironmentId}
307 + key={item.id}
308 + item={item}
309 + createdAt={row.createdAt}
310 + timestampFormat={ctx.timestampFormat}
311 + runs={ctx.runs}
312 + onOpenThread={ctx.onOpenThread}
313 + />
314 + ))}
315 + </div>
316 + ) : null}
317 + </CollapsiblePanel>
318 + </Collapsible>
319 + </WorkLogBlock>
320 + );
321 +});