Skip to content

Commit ef84bc9

Browse files
fix(chat): smooth worktree setup status (pingdotgg#8922)
1 parent 4a9d2d0 commit ef84bc9

16 files changed

Lines changed: 397 additions & 69 deletions

‎apps/mobile/src/features/threads/NewTaskDraftScreen.tsx‎

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { ProviderIcon } from "../../components/ProviderIcon";
3939
import { SymbolView } from "../../components/AppSymbol";
4040
import { AppText as Text } from "../../components/AppText";
4141
import { COMPOSER_LAYOUT_TRANSITION, ComposerSurface } from "./ThreadComposer";
42+
import { ShimmeringWorkContent } from "./thread-work-log";
4243
import { ComposerCommandPopover } from "./ComposerCommandPopover";
4344
import { useComposerCommandMenu } from "./use-composer-command-menu";
4445
import {
@@ -380,7 +381,8 @@ export function NewTaskDraftScreen(props: {
380381
};
381382
}, [props.pendingTaskId, cancelEditingPendingTask]);
382383

383-
const foregroundColor = useUniwindTheme()["--color-foreground"];
384+
const theme = useUniwindTheme();
385+
const foregroundColor = theme["--color-foreground"];
384386
const regularFontFamily = useFontFamily("regular");
385387
const bodyText = useScaledTextRole("body");
386388

@@ -1110,31 +1112,50 @@ export function NewTaskDraftScreen(props: {
11101112

11111113
const workspaceControls = (
11121114
<View className="flex-row items-center gap-1 px-2">
1113-
<ComposerInlineControl
1114-
accessibilityHint={`Switches to ${flow.workspaceMode === "local" ? "a new worktree" : "the current checkout"}`}
1115-
accessibilityLabel={workspaceLabel}
1116-
disabled={isComposerInteractionLocked || voiceInput.isBusy}
1117-
iconNode={
1118-
<NewTaskWorkspaceIcon
1119-
workspaceMode={flow.workspaceMode}
1120-
worktreePath={flow.selectedWorktreePath}
1115+
{flow.submitting && environmentConnected && flow.workspaceMode === "worktree" ? (
1116+
<View
1117+
accessible
1118+
accessibilityLabel="Setting up worktree…"
1119+
className="h-11 w-full max-w-[260px] flex-row items-center px-2"
1120+
>
1121+
<ShimmeringWorkContent
1122+
icon="arrow.triangle.branch"
1123+
iconSubtleColor={theme["--color-icon-subtle"]}
1124+
label="Setting up worktree…"
1125+
showIcon
1126+
/>
1127+
</View>
1128+
) : (
1129+
<>
1130+
<ComposerInlineControl
1131+
accessibilityHint={`Switches to ${flow.workspaceMode === "local" ? "a new worktree" : "the current checkout"}`}
1132+
accessibilityLabel={workspaceLabel}
1133+
disabled={isComposerInteractionLocked || voiceInput.isBusy}
1134+
iconNode={
1135+
<NewTaskWorkspaceIcon
1136+
workspaceMode={flow.workspaceMode}
1137+
worktreePath={flow.selectedWorktreePath}
1138+
/>
1139+
}
1140+
label={workspaceLabel}
1141+
maxWidth={flow.workspaceMode === "local" ? 220 : 148}
1142+
onPress={() =>
1143+
flow.setWorkspaceMode(flow.workspaceMode === "local" ? "worktree" : "local")
1144+
}
1145+
showChevron={false}
11211146
/>
1122-
}
1123-
label={workspaceLabel}
1124-
maxWidth={flow.workspaceMode === "local" ? 220 : 148}
1125-
onPress={() => flow.setWorkspaceMode(flow.workspaceMode === "local" ? "worktree" : "local")}
1126-
showChevron={false}
1127-
/>
11281147

1129-
<ComposerInlineControl
1130-
accessibilityLabel={`${flow.workspaceMode === "worktree" ? "Base branch" : "Branch"}: ${selectedBranchLabel}`}
1131-
chevronDirection="right"
1132-
disabled={isComposerInteractionLocked}
1133-
icon="arrow.triangle.branch"
1134-
label={showBranchLoading ? "Loading branches…" : selectedBranchLabel}
1135-
maxWidth={190}
1136-
onPress={() => openContextPicker("NewTaskBranch")}
1137-
/>
1148+
<ComposerInlineControl
1149+
accessibilityLabel={`${flow.workspaceMode === "worktree" ? "Base branch" : "Branch"}: ${selectedBranchLabel}`}
1150+
chevronDirection="right"
1151+
disabled={isComposerInteractionLocked}
1152+
icon="arrow.triangle.branch"
1153+
label={showBranchLoading ? "Loading branches…" : selectedBranchLabel}
1154+
maxWidth={190}
1155+
onPress={() => openContextPicker("NewTaskBranch")}
1156+
/>
1157+
</>
1158+
)}
11381159
</View>
11391160
);
11401161

‎apps/mobile/src/features/threads/thread-work-log.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function ShimmerWorkContent(props: {
7979
);
8080
}
8181

82-
function ShimmeringWorkContent(props: {
82+
export function ShimmeringWorkContent(props: {
8383
readonly icon: AppSymbolName;
8484
readonly iconSubtleColor: ColorValue;
8585
readonly label: string;

‎apps/mobile/src/lib/threadActivity.test.ts‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,83 @@ function makeThread(
234234
}
235235

236236
describe("buildThreadFeed", () => {
237+
it("keeps setup failures visible without routine setup notices before or after a turn", () => {
238+
const thread = makeThread({
239+
id: ThreadId.make("thread-worktree-setup"),
240+
projectId: ProjectId.make("project-1"),
241+
title: "Worktree setup",
242+
activities: [
243+
makeActivity({
244+
id: EventId.make("setup-requested"),
245+
kind: "setup-script.requested",
246+
summary: "Starting setup script",
247+
createdAt: "2026-08-30T00:00:00.000Z",
248+
}),
249+
makeActivity({
250+
id: EventId.make("setup-started"),
251+
kind: "setup-script.started",
252+
summary: "Setup script started",
253+
createdAt: "2026-08-30T00:00:01.000Z",
254+
}),
255+
makeActivity({
256+
id: EventId.make("setup-failed"),
257+
kind: "setup-script.failed",
258+
summary: "Setup script failed to start",
259+
createdAt: "2026-08-30T00:00:02.000Z",
260+
tone: "error",
261+
payload: { detail: "Setup command was not found" },
262+
}),
263+
],
264+
});
265+
const latestTurn = {
266+
turnId: TurnId.make("turn-after-setup"),
267+
state: "running" as const,
268+
requestedAt: "2026-08-30T00:00:03.000Z",
269+
startedAt: "2026-08-30T00:00:04.000Z",
270+
completedAt: null,
271+
assistantMessageId: null,
272+
};
273+
274+
for (const currentTurn of [null, latestTurn]) {
275+
const feed = buildThreadFeed({ ...thread, latestTurn: currentTurn });
276+
expect(feed).toMatchObject([
277+
{
278+
type: "activity-group",
279+
activities: [{ id: "setup-failed", status: "failure" }],
280+
},
281+
]);
282+
const group = feed[0];
283+
if (group?.type !== "activity-group") throw new Error("Expected the setup failure group");
284+
expect(group.activities[0]?.getCopyText()).toContain("Setup command was not found");
285+
}
286+
});
287+
288+
it.each(["setup-script.requested", "setup-script.started"])(
289+
"keeps error-toned %s notices visible",
290+
(kind) => {
291+
const feed = buildThreadFeed(
292+
makeThread({
293+
id: ThreadId.make("thread-setup-error"),
294+
projectId: ProjectId.make("project-1"),
295+
title: "Setup error",
296+
activities: [
297+
makeActivity({
298+
id: EventId.make("setup-error"),
299+
kind,
300+
summary: "Setup failed",
301+
createdAt: "2026-08-30T00:00:00.000Z",
302+
tone: "error",
303+
}),
304+
],
305+
}),
306+
);
307+
308+
expect(feed).toMatchObject([
309+
{ type: "activity-group", activities: [{ id: "setup-error", status: "failure" }] },
310+
]);
311+
},
312+
);
313+
237314
it("keeps older local feedback before newer messages returned by the server", () => {
238315
const submission = {
239316
id: MessageId.make("feedback-command-ordering"),

‎apps/mobile/src/lib/threadActivity.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
} from "@t3tools/contracts";
1515
import { formatDuration } from "@t3tools/shared/orchestrationTiming";
1616
import {
17+
isWorktreeSetupActivity,
1718
normalizeCompactToolLabel,
1819
omitSupersededLifecycleMarkers,
1920
summarizeToolGroup,
@@ -343,6 +344,7 @@ function deriveWorkLogEntries(
343344
const ordered = Arr.sort(activities, activityOrder);
344345
const entries: DerivedWorkLogEntry[] = [];
345346
for (const activity of ordered) {
347+
if (activity.tone !== "error" && isWorktreeSetupActivity(activity.kind)) continue;
346348
if (activity.kind === "tool.started") continue;
347349
if (activity.kind === "task.started") continue;
348350
// Terminal bypassed updates pass: Codex children's only terminal signal.

‎apps/web/src/components/ChatView.logic.test.ts‎

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ describe("draft hero submission transition", () => {
115115
expect(
116116
resolveDraftPromotionNavigationTarget({
117117
serverThreadRef: { environmentId, threadId },
118-
serverThreadStarted: true,
118+
serverThread: makeThread({ latestTurn: completedTurn }),
119119
backgroundSubmissionPending: true,
120120
}),
121121
).toBeNull();
@@ -316,6 +316,66 @@ const readySession = {
316316
updatedAt: "2026-03-29T00:00:10.000Z",
317317
};
318318

319+
describe("draft promotion during worktree setup", () => {
320+
const serverThreadRef = { environmentId, threadId };
321+
322+
it.each([null, "idle", "starting", "ready"] as const)(
323+
"keeps the draft mounted while the first turn waits with session %s",
324+
(status) => {
325+
const serverThread = makeThread({
326+
messages: [
327+
{
328+
id: MessageId.make("submitted-message"),
329+
role: "user",
330+
text: "Start in a new worktree",
331+
turnId: null,
332+
createdAt: now,
333+
updatedAt: now,
334+
streaming: false,
335+
},
336+
],
337+
session: status ? { ...readySession, status } : null,
338+
});
339+
340+
expect(
341+
resolveDraftPromotionNavigationTarget({
342+
serverThreadRef,
343+
serverThread,
344+
backgroundSubmissionPending: false,
345+
}),
346+
).toBeNull();
347+
},
348+
);
349+
350+
it("promotes when the provider starts the first turn", () => {
351+
const latestTurn = { ...completedTurn, state: "running" as const, completedAt: null };
352+
353+
expect(
354+
resolveDraftPromotionNavigationTarget({
355+
serverThreadRef,
356+
serverThread: makeThread({
357+
latestTurn,
358+
session: { ...readySession, status: "running", activeTurnId: latestTurn.turnId },
359+
}),
360+
backgroundSubmissionPending: false,
361+
}),
362+
).toEqual(serverThreadRef);
363+
});
364+
365+
it.each(["error", "stopped", "interrupted"] as const)(
366+
"promotes a startup that ends as %s before a turn starts",
367+
(status) => {
368+
expect(
369+
resolveDraftPromotionNavigationTarget({
370+
serverThreadRef,
371+
serverThread: makeThread({ session: { ...readySession, status } }),
372+
backgroundSubmissionPending: false,
373+
}),
374+
).toEqual(serverThreadRef);
375+
},
376+
);
377+
});
378+
319379
describe("buildLoadingThreadFromShell", () => {
320380
it("preserves shell metadata and supplies empty detail collections", () => {
321381
const shell = {

‎apps/web/src/components/ChatView.logic.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,19 @@ export function resolveDraftHeroState(input: {
110110

111111
export function resolveDraftPromotionNavigationTarget(input: {
112112
serverThreadRef: ScopedThreadRef | null;
113-
serverThreadStarted: boolean;
113+
serverThread: Pick<Thread, "latestTurn" | "session"> | null | undefined;
114114
backgroundSubmissionPending: boolean;
115115
}): ScopedThreadRef | null {
116116
if (input.backgroundSubmissionPending) {
117117
return null;
118118
}
119-
return input.serverThreadStarted ? input.serverThreadRef : null;
119+
const sessionStatus = input.serverThread?.session?.status;
120+
const turnStarted = input.serverThread?.latestTurn?.startedAt != null;
121+
const startupStopped =
122+
sessionStatus === "error" || sessionStatus === "stopped" || sessionStatus === "interrupted";
123+
// Keep local preparation feedback mounted until the server can render the
124+
// running turn or its startup error on the canonical thread route.
125+
return turnStarted || startupStopped ? input.serverThreadRef : null;
120126
}
121127

122128
export function scheduleEnvironmentReconnectWarning(showWarning: () => void): () => void {

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import {
5353
createModelSelection,
5454
resolvePromptInjectedEffort,
5555
} from "@t3tools/shared/model";
56-
import { CHAT_LIST_ANCHOR_OFFSET } from "@t3tools/shared/chatList";
5756
import { projectScriptCwd, projectScriptRuntimeEnv } from "@t3tools/shared/projectScripts";
5857
import { truncate } from "@t3tools/shared/String";
5958
import {
@@ -108,7 +107,11 @@ import {
108107
isLatestTurnSettled,
109108
} from "../session-logic";
110109
import { type LegendListRef } from "@legendapp/list/react";
111-
import { getAnchoredTurnMetrics, type TimelineScrollMode } from "./chat/timelineScrollAnchoring";
110+
import {
111+
CHAT_TIMELINE_ANCHOR_OFFSET,
112+
getAnchoredTurnMetrics,
113+
type TimelineScrollMode,
114+
} from "./chat/timelineScrollAnchoring";
112115
import {
113116
buildPendingUserInputAnswers,
114117
derivePendingUserInputProgress,
@@ -4110,7 +4113,7 @@ function ChatViewContent(props: ChatViewProps) {
41104113
state,
41114114
anchorIndex,
41124115
composerOverlayHeight,
4113-
anchorOffset: CHAT_LIST_ANCHOR_OFFSET,
4116+
anchorOffset: CHAT_TIMELINE_ANCHOR_OFFSET,
41144117
});
41154118
},
41164119
[composerOverlayHeight],
@@ -4138,7 +4141,7 @@ function ChatViewContent(props: ChatViewProps) {
41384141
const realContentBottom = lastRowTop + Math.max(1, lastRowHeight);
41394142
const visibleScrollLength = Math.max(
41404143
0,
4141-
(state.scrollLength ?? 0) - composerOverlayHeight - CHAT_LIST_ANCHOR_OFFSET,
4144+
(state.scrollLength ?? 0) - composerOverlayHeight - CHAT_TIMELINE_ANCHOR_OFFSET,
41424145
);
41434146
return realContentBottom > visibleScrollLength;
41444147
},
@@ -4326,7 +4329,7 @@ function ChatViewContent(props: ChatViewProps) {
43264329
index: anchorIndex,
43274330
animated: true,
43284331
viewPosition: 0,
4329-
viewOffset: CHAT_LIST_ANCHOR_OFFSET,
4332+
viewOffset: CHAT_TIMELINE_ANCHOR_OFFSET,
43304333
})
43314334
.then(() => {
43324335
if (positionedTimelineAnchorRef.current !== messageId) {
@@ -6146,7 +6149,6 @@ function ChatViewContent(props: ChatViewProps) {
61466149
: {}),
61476150
}
61486151
: undefined;
6149-
beginLocalDispatch({ preparingWorktree: false });
61506152
const backgroundThreadRef =
61516153
resolvedSubmissionIntent === "background"
61526154
? scopeThreadRef(activeThread.environmentId, threadIdForSend)
@@ -7225,6 +7227,7 @@ function ChatViewContent(props: ChatViewProps) {
72257227
onOpenAgents={addAgentsSurface}
72267228
key={activeThread.id}
72277229
isWorking={isWorking}
7230+
isPreparingWorktree={isPreparingWorktree}
72287231
activeTurnStartedAt={activeWorkStartedAt}
72297232
listRef={legendListRef}
72307233
timelineEntries={timelineEntries}

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,6 @@ const ComposerFooterPrimaryActions = memo(function ComposerFooterPrimaryActions(
537537
compactDisabledReason={props.compactDisabledReason}
538538
/>
539539
) : null}
540-
{props.isPreparingWorktree ? (
541-
<span className="text-secondary-label text-xs">Preparing worktree...</span>
542-
) : null}
543540
<ComposerPrimaryActions
544541
compact={props.compact}
545542
pendingAction={props.pendingAction}

0 commit comments

Comments
 (0)