Skip to content
TypeScript

fix(chat): smooth worktree setup status (#8922)

Julius Marmingeef84bc9873a6
diff --git a/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx b/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx
index 50e2413d2af..96ce039b5e0 100644
--- a/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx
+++ b/apps/mobile/src/features/threads/NewTaskDraftScreen.tsx
@@ -39,6 +39,7 @@ import { ProviderIcon } from "../../components/ProviderIcon";
import { SymbolView } from "../../components/AppSymbol";
import { AppText as Text } from "../../components/AppText";
import { COMPOSER_LAYOUT_TRANSITION, ComposerSurface } from "./ThreadComposer";
+import { ShimmeringWorkContent } from "./thread-work-log";
import { ComposerCommandPopover } from "./ComposerCommandPopover";
import { useComposerCommandMenu } from "./use-composer-command-menu";
import {
@@ -380,7 +381,8 @@ export function NewTaskDraftScreen(props: {
};
}, [props.pendingTaskId, cancelEditingPendingTask]);
- const foregroundColor = useUniwindTheme()["--color-foreground"];
+ const theme = useUniwindTheme();
+ const foregroundColor = theme["--color-foreground"];
const regularFontFamily = useFontFamily("regular");
const bodyText = useScaledTextRole("body");
@@ -1110,31 +1112,50 @@ export function NewTaskDraftScreen(props: {
const workspaceControls = (
<View className="flex-row items-center gap-1 px-2">
- <ComposerInlineControl
- accessibilityHint={`Switches to ${flow.workspaceMode === "local" ? "a new worktree" : "the current checkout"}`}
- accessibilityLabel={workspaceLabel}
- disabled={isComposerInteractionLocked || voiceInput.isBusy}
- iconNode={
- <NewTaskWorkspaceIcon
- workspaceMode={flow.workspaceMode}
- worktreePath={flow.selectedWorktreePath}
+ {flow.submitting && environmentConnected && flow.workspaceMode === "worktree" ? (
+ <View
+ accessible
+ accessibilityLabel="Setting up worktree…"
+ className="h-11 w-full max-w-[260px] flex-row items-center px-2"
+ >
+ <ShimmeringWorkContent
+ icon="arrow.triangle.branch"
+ iconSubtleColor={theme["--color-icon-subtle"]}
+ label="Setting up worktree…"
+ showIcon
+ />
+ </View>
+ ) : (
+ <>
+ <ComposerInlineControl
+ accessibilityHint={`Switches to ${flow.workspaceMode === "local" ? "a new worktree" : "the current checkout"}`}
+ accessibilityLabel={workspaceLabel}
+ disabled={isComposerInteractionLocked || voiceInput.isBusy}
+ iconNode={
+ <NewTaskWorkspaceIcon
+ workspaceMode={flow.workspaceMode}
+ worktreePath={flow.selectedWorktreePath}
+ />
+ }
+ label={workspaceLabel}
+ maxWidth={flow.workspaceMode === "local" ? 220 : 148}
+ onPress={() =>
+ flow.setWorkspaceMode(flow.workspaceMode === "local" ? "worktree" : "local")
+ }
+ showChevron={false}
/>
- }
- label={workspaceLabel}
- maxWidth={flow.workspaceMode === "local" ? 220 : 148}
- onPress={() => flow.setWorkspaceMode(flow.workspaceMode === "local" ? "worktree" : "local")}
- showChevron={false}
- />
- <ComposerInlineControl
- accessibilityLabel={`${flow.workspaceMode === "worktree" ? "Base branch" : "Branch"}: ${selectedBranchLabel}`}
- chevronDirection="right"
- disabled={isComposerInteractionLocked}
- icon="arrow.triangle.branch"
- label={showBranchLoading ? "Loading branches…" : selectedBranchLabel}
- maxWidth={190}
- onPress={() => openContextPicker("NewTaskBranch")}
- />
+ <ComposerInlineControl
+ accessibilityLabel={`${flow.workspaceMode === "worktree" ? "Base branch" : "Branch"}: ${selectedBranchLabel}`}
+ chevronDirection="right"
+ disabled={isComposerInteractionLocked}
+ icon="arrow.triangle.branch"
+ label={showBranchLoading ? "Loading branches…" : selectedBranchLabel}
+ maxWidth={190}
+ onPress={() => openContextPicker("NewTaskBranch")}
+ />
+ </>
+ )}
</View>
);
diff --git a/apps/mobile/src/features/threads/thread-work-log.tsx b/apps/mobile/src/features/threads/thread-work-log.tsx
index dec1742d826..7e167f82eb4 100644
--- a/apps/mobile/src/features/threads/thread-work-log.tsx
+++ b/apps/mobile/src/features/threads/thread-work-log.tsx
@@ -79,7 +79,7 @@ function ShimmerWorkContent(props: {
);
}
-function ShimmeringWorkContent(props: {
+export function ShimmeringWorkContent(props: {
readonly icon: AppSymbolName;
readonly iconSubtleColor: ColorValue;
readonly label: string;
diff --git a/apps/mobile/src/lib/threadActivity.test.ts b/apps/mobile/src/lib/threadActivity.test.ts
index 28deeb384e5..136b01190e3 100644
--- a/apps/mobile/src/lib/threadActivity.test.ts
+++ b/apps/mobile/src/lib/threadActivity.test.ts
@@ -234,6 +234,83 @@ function makeThread(
}
describe("buildThreadFeed", () => {
+ it("keeps setup failures visible without routine setup notices before or after a turn", () => {
+ const thread = makeThread({
+ id: ThreadId.make("thread-worktree-setup"),
+ projectId: ProjectId.make("project-1"),
+ title: "Worktree setup",
+ activities: [
+ makeActivity({
+ id: EventId.make("setup-requested"),
+ kind: "setup-script.requested",
+ summary: "Starting setup script",
+ createdAt: "2026-08-30T00:00:00.000Z",
+ }),
+ makeActivity({
+ id: EventId.make("setup-started"),
+ kind: "setup-script.started",
+ summary: "Setup script started",
+ createdAt: "2026-08-30T00:00:01.000Z",
+ }),
+ makeActivity({
+ id: EventId.make("setup-failed"),
+ kind: "setup-script.failed",
+ summary: "Setup script failed to start",
+ createdAt: "2026-08-30T00:00:02.000Z",
+ tone: "error",
+ payload: { detail: "Setup command was not found" },
+ }),
+ ],
+ });
+ const latestTurn = {
+ turnId: TurnId.make("turn-after-setup"),
+ state: "running" as const,
+ requestedAt: "2026-08-30T00:00:03.000Z",
+ startedAt: "2026-08-30T00:00:04.000Z",
+ completedAt: null,
+ assistantMessageId: null,
+ };
+
+ for (const currentTurn of [null, latestTurn]) {
+ const feed = buildThreadFeed({ ...thread, latestTurn: currentTurn });
+ expect(feed).toMatchObject([
+ {
+ type: "activity-group",
+ activities: [{ id: "setup-failed", status: "failure" }],
+ },
+ ]);
+ const group = feed[0];
+ if (group?.type !== "activity-group") throw new Error("Expected the setup failure group");
+ expect(group.activities[0]?.getCopyText()).toContain("Setup command was not found");
+ }
+ });
+
+ it.each(["setup-script.requested", "setup-script.started"])(
+ "keeps error-toned %s notices visible",
+ (kind) => {
+ const feed = buildThreadFeed(
+ makeThread({
+ id: ThreadId.make("thread-setup-error"),
+ projectId: ProjectId.make("project-1"),
+ title: "Setup error",
+ activities: [
+ makeActivity({
+ id: EventId.make("setup-error"),
+ kind,
+ summary: "Setup failed",
+ createdAt: "2026-08-30T00:00:00.000Z",
+ tone: "error",
+ }),
+ ],
+ }),
+ );
+
+ expect(feed).toMatchObject([
+ { type: "activity-group", activities: [{ id: "setup-error", status: "failure" }] },
+ ]);
+ },
+ );
+
it("keeps older local feedback before newer messages returned by the server", () => {
const submission = {
id: MessageId.make("feedback-command-ordering"),
diff --git a/apps/mobile/src/lib/threadActivity.ts b/apps/mobile/src/lib/threadActivity.ts
index 28f4fc76061..367042448da 100644
--- a/apps/mobile/src/lib/threadActivity.ts
+++ b/apps/mobile/src/lib/threadActivity.ts
@@ -14,6 +14,7 @@ import type {
} from "@t3tools/contracts";
import { formatDuration } from "@t3tools/shared/orchestrationTiming";
import {
+ isWorktreeSetupActivity,
normalizeCompactToolLabel,
omitSupersededLifecycleMarkers,
summarizeToolGroup,
@@ -343,6 +344,7 @@ function deriveWorkLogEntries(
const ordered = Arr.sort(activities, activityOrder);
const entries: DerivedWorkLogEntry[] = [];
for (const activity of ordered) {
+ if (activity.tone !== "error" && isWorktreeSetupActivity(activity.kind)) continue;
if (activity.kind === "tool.started") continue;
if (activity.kind === "task.started") continue;
// Terminal bypassed updates pass: Codex children's only terminal signal.
diff --git a/apps/web/src/components/ChatView.logic.test.ts b/apps/web/src/components/ChatView.logic.test.ts
index 719d7b00013..6e391ab79e9 100644
--- a/apps/web/src/components/ChatView.logic.test.ts
+++ b/apps/web/src/components/ChatView.logic.test.ts
@@ -115,7 +115,7 @@ describe("draft hero submission transition", () => {
expect(
resolveDraftPromotionNavigationTarget({
serverThreadRef: { environmentId, threadId },
- serverThreadStarted: true,
+ serverThread: makeThread({ latestTurn: completedTurn }),
backgroundSubmissionPending: true,
}),
).toBeNull();
@@ -316,6 +316,66 @@ const readySession = {
updatedAt: "2026-03-29T00:00:10.000Z",
};
+describe("draft promotion during worktree setup", () => {
+ const serverThreadRef = { environmentId, threadId };
+
+ it.each([null, "idle", "starting", "ready"] as const)(
+ "keeps the draft mounted while the first turn waits with session %s",
+ (status) => {
+ const serverThread = makeThread({
+ messages: [
+ {
+ id: MessageId.make("submitted-message"),
+ role: "user",
+ text: "Start in a new worktree",
+ turnId: null,
+ createdAt: now,
+ updatedAt: now,
+ streaming: false,
+ },
+ ],
+ session: status ? { ...readySession, status } : null,
+ });
+
+ expect(
+ resolveDraftPromotionNavigationTarget({
+ serverThreadRef,
+ serverThread,
+ backgroundSubmissionPending: false,
+ }),
+ ).toBeNull();
+ },
+ );
+
+ it("promotes when the provider starts the first turn", () => {
+ const latestTurn = { ...completedTurn, state: "running" as const, completedAt: null };
+
+ expect(
+ resolveDraftPromotionNavigationTarget({
+ serverThreadRef,
+ serverThread: makeThread({
+ latestTurn,
+ session: { ...readySession, status: "running", activeTurnId: latestTurn.turnId },
+ }),
+ backgroundSubmissionPending: false,
+ }),
+ ).toEqual(serverThreadRef);
+ });
+
+ it.each(["error", "stopped", "interrupted"] as const)(
+ "promotes a startup that ends as %s before a turn starts",
+ (status) => {
+ expect(
+ resolveDraftPromotionNavigationTarget({
+ serverThreadRef,
+ serverThread: makeThread({ session: { ...readySession, status } }),
+ backgroundSubmissionPending: false,
+ }),
+ ).toEqual(serverThreadRef);
+ },
+ );
+});
+
describe("buildLoadingThreadFromShell", () => {
it("preserves shell metadata and supplies empty detail collections", () => {
const shell = {
diff --git a/apps/web/src/components/ChatView.logic.ts b/apps/web/src/components/ChatView.logic.ts
index ae0b9885969..a12bacad50d 100644
--- a/apps/web/src/components/ChatView.logic.ts
+++ b/apps/web/src/components/ChatView.logic.ts
@@ -110,13 +110,19 @@ export function resolveDraftHeroState(input: {
export function resolveDraftPromotionNavigationTarget(input: {
serverThreadRef: ScopedThreadRef | null;
- serverThreadStarted: boolean;
+ serverThread: Pick<Thread, "latestTurn" | "session"> | null | undefined;
backgroundSubmissionPending: boolean;
}): ScopedThreadRef | null {
if (input.backgroundSubmissionPending) {
return null;
}
- return input.serverThreadStarted ? input.serverThreadRef : null;
+ const sessionStatus = input.serverThread?.session?.status;
+ const turnStarted = input.serverThread?.latestTurn?.startedAt != null;
+ const startupStopped =
+ sessionStatus === "error" || sessionStatus === "stopped" || sessionStatus === "interrupted";
+ // Keep local preparation feedback mounted until the server can render the
+ // running turn or its startup error on the canonical thread route.
+ return turnStarted || startupStopped ? input.serverThreadRef : null;
}
export function scheduleEnvironmentReconnectWarning(showWarning: () => void): () => void {
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx
index e2b82e5a5f8..be978a8cc0c 100644
--- a/apps/web/src/components/ChatView.tsx
+++ b/apps/web/src/components/ChatView.tsx
@@ -53,7 +53,6 @@ import {
createModelSelection,
resolvePromptInjectedEffort,
} from "@t3tools/shared/model";
-import { CHAT_LIST_ANCHOR_OFFSET } from "@t3tools/shared/chatList";
import { projectScriptCwd, projectScriptRuntimeEnv } from "@t3tools/shared/projectScripts";
import { truncate } from "@t3tools/shared/String";
import {
@@ -108,7 +107,11 @@ import {
isLatestTurnSettled,
} from "../session-logic";
import { type LegendListRef } from "@legendapp/list/react";
-import { getAnchoredTurnMetrics, type TimelineScrollMode } from "./chat/timelineScrollAnchoring";
+import {
+ CHAT_TIMELINE_ANCHOR_OFFSET,
+ getAnchoredTurnMetrics,
+ type TimelineScrollMode,
+} from "./chat/timelineScrollAnchoring";
import {
buildPendingUserInputAnswers,
derivePendingUserInputProgress,
@@ -4110,7 +4113,7 @@ function ChatViewContent(props: ChatViewProps) {
state,
anchorIndex,
composerOverlayHeight,
- anchorOffset: CHAT_LIST_ANCHOR_OFFSET,
+ anchorOffset: CHAT_TIMELINE_ANCHOR_OFFSET,
});
},
[composerOverlayHeight],
@@ -4138,7 +4141,7 @@ function ChatViewContent(props: ChatViewProps) {
const realContentBottom = lastRowTop + Math.max(1, lastRowHeight);
const visibleScrollLength = Math.max(
0,
- (state.scrollLength ?? 0) - composerOverlayHeight - CHAT_LIST_ANCHOR_OFFSET,
+ (state.scrollLength ?? 0) - composerOverlayHeight - CHAT_TIMELINE_ANCHOR_OFFSET,
);
return realContentBottom > visibleScrollLength;
},
@@ -4326,7 +4329,7 @@ function ChatViewContent(props: ChatViewProps) {
index: anchorIndex,
animated: true,
viewPosition: 0,
- viewOffset: CHAT_LIST_ANCHOR_OFFSET,
+ viewOffset: CHAT_TIMELINE_ANCHOR_OFFSET,
})
.then(() => {
if (positionedTimelineAnchorRef.current !== messageId) {
@@ -6146,7 +6149,6 @@ function ChatViewContent(props: ChatViewProps) {
: {}),
}
: undefined;
- beginLocalDispatch({ preparingWorktree: false });
const backgroundThreadRef =
resolvedSubmissionIntent === "background"
? scopeThreadRef(activeThread.environmentId, threadIdForSend)
@@ -7225,6 +7227,7 @@ function ChatViewContent(props: ChatViewProps) {
onOpenAgents={addAgentsSurface}
key={activeThread.id}
isWorking={isWorking}
+ isPreparingWorktree={isPreparingWorktree}
activeTurnStartedAt={activeWorkStartedAt}
listRef={legendListRef}
timelineEntries={timelineEntries}
diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx
index 6972f1de41a..cd69eceb7ef 100644
--- a/apps/web/src/components/chat/ChatComposer.tsx
+++ b/apps/web/src/components/chat/ChatComposer.tsx
@@ -537,9 +537,6 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
compactDisabledReason={props.compactDisabledReason}
/>
) : null}
- {props.isPreparingWorktree ? (
- <span className="text-secondary-label text-xs">Preparing worktree...</span>
- ) : null}
<ComposerPrimaryActions
compact={props.compact}
pendingAction={props.pendingAction}
diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts
index 3cd8d338d36..9e18f8f0044 100644
--- a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts
+++ b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts
@@ -1,4 +1,5 @@
import { describe, expect, it } from "vite-plus/test";
+import { MessageId, TurnId } from "@t3tools/contracts";
import {
computeStableMessagesTimelineRows,
computeMessageDurationStart,
@@ -828,6 +829,7 @@ describe("deriveMessagesTimelineRows", () => {
]);
const finalRow = rows.find((row) => row.id === "assistant-final-entry");
expect(finalRow?.kind === "message" && finalRow.showAssistantMeta).toBe(true);
+ expect(rows.find((row) => row.kind === "working")).toMatchObject({ showThinking: true });
});
it("does not fold the active in-progress turn", () => {
@@ -942,6 +944,7 @@ describe("deriveMessagesTimelineRows", () => {
});
expect(rows.map((row) => row.kind)).toEqual(["working", "work-live"]);
+ expect(rows.find((row) => row.kind === "working")).toMatchObject({ showThinking: false });
expect(rows.find((row) => row.kind === "work-live")).toMatchObject({
entry: { id: "running-command" },
groupedEntries: [
@@ -1375,6 +1378,7 @@ describe("deriveMessagesTimelineRows", () => {
expect(assistantRow?.showAssistantMeta).toBe(false);
expect(assistantRow?.showAssistantCopyButton).toBe(false);
+ expect(rows.find((row) => row.kind === "working")).toMatchObject({ showThinking: false });
});
it.each([
@@ -1543,6 +1547,54 @@ describe("deriveMessagesTimelineRows", () => {
});
describe("computeStableMessagesTimelineRows", () => {
+ it.each(["", " \n"])("replaces Thinking when assistant content grows from %j", (text) => {
+ const startedAt = "2026-01-01T00:00:00Z";
+ const turnId = TurnId.make("turn-1");
+ const input = {
+ runningTurnId: turnId,
+ isWorking: true,
+ activeTurnStartedAt: startedAt,
+ turnDiffSummaryByAssistantMessageId: new Map(),
+ revertTurnCountByUserMessageId: new Map(),
+ };
+ const assistantEntry = {
+ id: "assistant-entry",
+ kind: "message" as const,
+ createdAt: startedAt,
+ message: {
+ id: MessageId.make("assistant-1"),
+ role: "assistant" as const,
+ text,
+ turnId,
+ createdAt: startedAt,
+ updatedAt: startedAt,
+ streaming: true,
+ },
+ };
+ const initial = computeStableMessagesTimelineRows(
+ deriveMessagesTimelineRows({ ...input, timelineEntries: [assistantEntry] }),
+ { byId: new Map(), result: [] },
+ );
+ const updated = computeStableMessagesTimelineRows(
+ deriveMessagesTimelineRows({
+ ...input,
+ timelineEntries: [
+ {
+ ...assistantEntry,
+ message: { ...assistantEntry.message, text: "I will inspect the repository." },
+ },
+ ],
+ }),
+ initial,
+ );
+
+ const initialWorking = initial.byId.get("working-indicator-row");
+ const updatedWorking = updated.byId.get("working-indicator-row");
+ expect(initialWorking).toMatchObject({ showThinking: true });
+ expect(updatedWorking).toMatchObject({ showThinking: false });
+ expect(updatedWorking).not.toBe(initialWorking);
+ });
+
it("returns the previous result when row order and content are unchanged", () => {
const firstUserMessage = {
id: "user-1" as never,
diff --git a/apps/web/src/components/chat/MessagesTimeline.test.tsx b/apps/web/src/components/chat/MessagesTimeline.test.tsx
index b339aab9544..9a8ad8f6c03 100644
--- a/apps/web/src/components/chat/MessagesTimeline.test.tsx
+++ b/apps/web/src/components/chat/MessagesTimeline.test.tsx
@@ -520,7 +520,7 @@ describe("MessagesTimeline", () => {
);
expect(markup).toContain('data-anchor-index="0"');
- expect(markup).toContain('data-anchor-offset="16"');
+ expect(markup).toContain('data-anchor-offset="24"');
expect(markup).toContain('data-anchor-on-ready="true"');
expect(markup).not.toContain("data-anchor-max-size=");
expect(markup).toContain('data-content-inset-end="144"');
diff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsx
index 1fd5f5a7562..81ab67f6ffe 100644
--- a/apps/web/src/components/chat/MessagesTimeline.tsx
+++ b/apps/web/src/components/chat/MessagesTimeline.tsx
@@ -84,7 +84,10 @@ import { buildExpandedImagePreview, ExpandedImagePreview } from "./ExpandedImage
import { ProposedPlanCard } from "./ProposedPlanCard";
import { ChangedFilesCard } from "./ChangedFilesTree";
import { shouldAutoExpandChangedFiles } from "./changedFilesPresentation";
-import { keepTimelineEndVisibleAfterOverlayGrowth } from "./timelineScrollAnchoring";
+import {
+ CHAT_TIMELINE_ANCHOR_OFFSET,
+ keepTimelineEndVisibleAfterOverlayGrowth,
+} from "./timelineScrollAnchoring";
import { MessageCopyButton } from "./MessageCopyButton";
import {
computeStableMessagesTimelineRows,
@@ -169,6 +172,7 @@ interface TimelineRowSharedState {
interface TimelineRowActivityState {
isWorking: boolean;
+ isPreparingWorktree: boolean;
isRevertingCheckpoint: boolean;
latestTurnId: TurnId | null;
}
@@ -225,6 +229,7 @@ interface MessagesTimelineProps {
agentPanelModel?: AgentPanelModel;
onOpenAgents?: () => void;
isWorking: boolean;
+ isPreparingWorktree?: boolean;
activeTurnStartedAt: string | null;
listRef: React.RefObject<LegendListRef | null>;
timelineEntries: ReturnType<typeof deriveTimelineEntries>;
@@ -270,6 +275,7 @@ interface MessagesTimelineProps {
export const MessagesTimeline = memo(function MessagesTimeline({
isWorking,
+ isPreparingWorktree = false,
activeTurnStartedAt,
agentPanelModel = EMPTY_AGENT_PANEL_MODEL,
onOpenAgents = NOOP_OPEN_AGENTS,
@@ -467,8 +473,11 @@ export const MessagesTimeline = memo(function MessagesTimeline({
[anchorMessageId, onAnchorReady],
);
const anchoredEndSpace = useMemo(() => {
- const config = resolveChatListAnchoredEndSpace(rows, anchorMessageId, (row) =>
- row.kind === "message" && row.message.role === "user" ? row.message.id : null,
+ const config = resolveChatListAnchoredEndSpace(
+ rows,
+ anchorMessageId,
+ (row) => (row.kind === "message" && row.message.role === "user" ? row.message.id : null),
+ { anchorOffset: CHAT_TIMELINE_ANCHOR_OFFSET },
);
return config ? { ...config, onReady: handleAnchorReady } : undefined;
}, [anchorMessageId, handleAnchorReady, rows]);
@@ -577,10 +586,11 @@ export const MessagesTimeline = memo(function MessagesTimeline({
const activityState = useMemo<TimelineRowActivityState>(
() => ({
isWorking,
+ isPreparingWorktree,
isRevertingCheckpoint,
latestTurnId: latestTurn?.turnId ?? null,
}),
- [isRevertingCheckpoint, isWorking, latestTurn?.turnId],
+ [isRevertingCheckpoint, isWorking, isPreparingWorktree, latestTurn?.turnId],
);
// Stable renderItem — no closure deps. Row components read shared state
@@ -1318,12 +1328,21 @@ function ProposedPlanTimelineRow({
}
function WorkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "working" }> }) {
+ const { isPreparingWorktree } = use(TimelineRowActivityCtx);
return (
<div>
<div className="border-b border-border/60 pb-2 pt-1">
- <div className="flex min-w-0 items-baseline px-1 text-sm leading-relaxed text-muted-foreground tabular-nums">
- <span className="shrink-0 whitespace-nowrap">
- {row.createdAt ? (
+ <div className="flex h-6 min-w-0 items-baseline px-1 text-sm leading-relaxed text-muted-foreground tabular-nums">
+ <span
+ key={isPreparingWorktree ? "setup" : "working"}
+ className="relative shrink-0 overflow-hidden whitespace-nowrap transition-opacity duration-150 starting:opacity-0 motion-reduce:transition-none"
+ >
+ {isPreparingWorktree ? (
+ <>
+ Setting up worktree…
+ <ActivityShimmerOverlay>Setting up worktree…</ActivityShimmerOverlay>
+ </>
+ ) : row.createdAt ? (
<>
Working for <WorkingTimer createdAt={row.createdAt} />
</>
@@ -1334,8 +1353,9 @@ function WorkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "workin
</div>
</div>
{row.showThinking ? (
- <div className="mt-1">
- <ThinkingActivityRow />
+ // Reserve the activity row during setup so the handoff keeps the same height.
+ <div className="mt-1 min-h-7">
+ {isPreparingWorktree ? null : <LiveActivityRow label="Thinking" />}
</div>
) : null}
</div>
@@ -1412,6 +1432,19 @@ const WorkGroupSection = memo(function WorkGroupSection({
);
});
+function ActivityShimmerOverlay({ children }: { children: ReactNode }) {
+ return (
+ <span
+ aria-hidden
+ className="live-activity-focus pointer-events-none absolute inset-y-0 select-none"
+ >
+ <span className="live-activity-focus-counter block">
+ <span className="live-activity-focus-aligned block text-foreground">{children}</span>
+ </span>
+ </span>
+ );
+}
+
function LiveActivityRow({
label,
iconName,
@@ -1429,24 +1462,13 @@ function LiveActivityRow({
failed={failed}
announceFailure={failed}
/>
- <div
- aria-hidden
- className="live-activity-focus pointer-events-none absolute inset-y-0 select-none"
- >
- <div className="live-activity-focus-counter">
- <div className="live-activity-focus-aligned">
- <LiveActivityContent label={label} iconName={iconName} failed={failed} highlighted />
- </div>
- </div>
- </div>
+ <ActivityShimmerOverlay>
+ <LiveActivityContent label={label} iconName={iconName} failed={failed} highlighted />
+ </ActivityShimmerOverlay>
</div>
);
}
-function ThinkingActivityRow() {
- return <LiveActivityRow label="Thinking" />;
-}
-
function LiveActivityContent({
label,
iconName,
@@ -1463,7 +1485,7 @@ function LiveActivityContent({
const resolvedIconName = failed ? "circle-alert" : iconName;
return (
- <div
+ <span
className={cn(
"flex min-h-6 min-w-0 items-center gap-1.5 py-0.5",
resolvedIconName ? "px-0.5" : "px-1",
@@ -1486,7 +1508,7 @@ function LiveActivityContent({
</span>
) : null}
<span className="min-w-0 flex-1 truncate">{label}</span>
- </div>
+ </span>
);
}
diff --git a/apps/web/src/components/chat/timelineScrollAnchoring.ts b/apps/web/src/components/chat/timelineScrollAnchoring.ts
index f38d0920b28..505efef29d2 100644
--- a/apps/web/src/components/chat/timelineScrollAnchoring.ts
+++ b/apps/web/src/components/chat/timelineScrollAnchoring.ts
@@ -1,3 +1,6 @@
+// Match the titlebar fade inset so draft promotion preserves the first row's position.
+export const CHAT_TIMELINE_ANCHOR_OFFSET = 24;
+
export type TimelineScrollMode = "following-end" | "anchoring-new-turn" | "free-scrolling";
export interface TimelineListMeasurementState {
diff --git a/apps/web/src/routes/_chat.draft.$draftId.tsx b/apps/web/src/routes/_chat.draft.$draftId.tsx
index d067c6a8da9..04cdf3ce8c9 100644
--- a/apps/web/src/routes/_chat.draft.$draftId.tsx
+++ b/apps/web/src/routes/_chat.draft.$draftId.tsx
@@ -1,10 +1,7 @@
import { createFileRoute, useNavigate } from "@tanstack/react-router";
import { useEffect } from "react";
import ChatView from "../components/ChatView";
-import {
- resolveDraftPromotionNavigationTarget,
- threadHasStarted,
-} from "../components/ChatView.logic";
+import { resolveDraftPromotionNavigationTarget } from "../components/ChatView.logic";
import {
DraftId,
markPromotedDraftThreadByRef,
@@ -31,11 +28,10 @@ function DraftChatThreadRouteView() {
: null;
const serverThreadRef = draftSession?.promotedTo ?? inferredThreadRef;
const serverThread = useThread(serverThreadRef);
- const serverThreadStarted = threadHasStarted(serverThread);
const backgroundSubmissionPending = useBackgroundDraftSubmissionPending(serverThreadRef);
const canonicalThreadRef = resolveDraftPromotionNavigationTarget({
serverThreadRef,
- serverThreadStarted,
+ serverThread,
backgroundSubmissionPending,
});
diff --git a/apps/web/src/session-logic.test.ts b/apps/web/src/session-logic.test.ts
index 762ee3fae03..dc32f84b1e5 100644
--- a/apps/web/src/session-logic.test.ts
+++ b/apps/web/src/session-logic.test.ts
@@ -894,6 +894,89 @@ describe("deriveWorkLogEntries", () => {
expect(entries.map((entry) => entry.id)).toEqual(["tool-complete"]);
});
+ it("omits routine setup updates before work starts and after later turn activity", () => {
+ const setupActivities = [
+ makeActivity({
+ id: "setup-requested",
+ kind: "setup-script.requested",
+ summary: "Preparing setup script",
+ tone: "info",
+ sequence: 1,
+ }),
+ makeActivity({
+ id: "setup-started",
+ kind: "setup-script.started",
+ summary: "Setup script started",
+ tone: "info",
+ sequence: 2,
+ }),
+ ];
+
+ expect(deriveWorkLogEntries(setupActivities)).toEqual([]);
+ expect(
+ deriveWorkLogEntries([
+ ...setupActivities,
+ makeActivity({
+ id: "first-turn-tool",
+ kind: "tool.completed",
+ summary: "Read project files",
+ turnId: "turn-1",
+ sequence: 3,
+ }),
+ makeActivity({
+ id: "later-turn-tool",
+ kind: "tool.completed",
+ summary: "Ran tests",
+ turnId: "turn-2",
+ sequence: 4,
+ }),
+ ]).map((entry) => entry.id),
+ ).toEqual(["first-turn-tool", "later-turn-tool"]);
+ });
+
+ it("preserves setup failures and unrelated info without a turn id", () => {
+ const entries = deriveWorkLogEntries([
+ makeActivity({
+ id: "setup-requested",
+ kind: "setup-script.requested",
+ summary: "Preparing setup script",
+ tone: "info",
+ sequence: 1,
+ }),
+ makeActivity({
+ id: "setup-failed",
+ kind: "setup-script.failed",
+ summary: "Setup script failed to start",
+ tone: "error",
+ payload: { detail: "Could not start the setup terminal" },
+ sequence: 2,
+ }),
+ makeActivity({
+ id: "runtime-notice",
+ kind: "runtime.warning",
+ summary: "Reconnecting to provider",
+ tone: "info",
+ sequence: 3,
+ }),
+ ]);
+
+ expect(entries).toMatchObject([
+ {
+ id: "setup-failed",
+ label: "Setup script failed to start",
+ tone: "error",
+ detail: "Could not start the setup terminal",
+ turnId: null,
+ },
+ {
+ id: "runtime-notice",
+ label: "Reconnecting to provider",
+ tone: "info",
+ turnId: null,
+ },
+ ]);
+ });
+
it("drops runtime warnings with no displayable content, keeps ones with a preview", () => {
const activities: OrchestrationThreadActivity[] = [
makeActivity({
diff --git a/apps/web/src/session-logic.ts b/apps/web/src/session-logic.ts
index ffde1b0c041..6d853dc3ea1 100644
--- a/apps/web/src/session-logic.ts
+++ b/apps/web/src/session-logic.ts
@@ -2,6 +2,7 @@ import * as Option from "effect/Option";
import * as Arr from "effect/Array";
import * as Schema from "effect/Schema";
import { isBackgroundTaskActivity } from "@t3tools/client-runtime/state/subagentRuntime";
+import { isWorktreeSetupActivity } from "@t3tools/client-runtime/work-log/presentation";
import {
ApprovalRequestId,
isToolLifecycleItemType,
@@ -809,6 +810,7 @@ export function deriveWorkLogEntries(
const ordered = [...activities].toSorted(compareActivitiesByOrder);
const entries: DerivedWorkLogEntry[] = [];
for (const activity of ordered) {
+ if (activity.tone !== "error" && isWorktreeSetupActivity(activity.kind)) continue;
if (activity.kind === "tool.started") continue;
// Agent task.started rows are CTA seeds: they carry the true spawn turn,
// which is the batch key (completions of background subagents arrive
diff --git a/packages/client-runtime/src/work-log/presentation.ts b/packages/client-runtime/src/work-log/presentation.ts
index 61ee4770e60..4834c037bb4 100644
--- a/packages/client-runtime/src/work-log/presentation.ts
+++ b/packages/client-runtime/src/work-log/presentation.ts
@@ -1,5 +1,9 @@
import { isToolLifecycleItemType, type ToolLifecycleItemType } from "@t3tools/contracts";
+export function isWorktreeSetupActivity(kind: string): boolean {
+ return kind === "setup-script.requested" || kind === "setup-script.started";
+}
+
export interface WorkLogPresentationEntry {
readonly label: string;
readonly toolTitle?: string;