@devries-cameron20 / t3code Mirror · read-only / commits / 82afb28794
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 21, 09:45 UTC

fix(mobile): worktree setup after hand-off follows web (#37811)

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

Julius Marminge committed Nov 16, 2026 at 15:59 UTC 82afb28794b1edca1b67f1f16c0074ff426001be
2 files changed +185 -68
apps/mobile/src/features/threads/ThreadFeed.tsx
+54 -2
@@ -39,6 +39,9 @@ import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
39 import {
40 WorktreePreparingHeader,
41 WorktreeSetupCard,
42 + WorktreeSetupDetails,
43 + WorktreeSetupFoldChip,
44 + worktreeSetupHandedOff,
45 type WorktreeSetupCardProps,
46 } from "./worktree-setup-card";
47 import * as Haptics from "expo-haptics";
@@ -1818,7 +1821,12 @@ function renderFeedEntry(
1821 | "onEditPendingMessage"
1822 | "threadId"
1823 | "workspaceRoot"
1824 + | "worktreeSetup"
1825 > & {
1826 + /** The fold row of the turn the worktree setup handed off to. */
1827 + readonly setupFoldRowId: string | null;
1828 + readonly setupDetailsOpen: boolean;
1829 + readonly onOpenSetupDetails: () => void;
1830 readonly pendingFoldMessageId: string | null;
1831 readonly formatMessageTime: (input: string) => string;
1832 readonly copiedRowId: string | null;
@@ -1920,6 +1928,13 @@ function renderFeedEntry(
1928 iconColor={iconSubtleColor}
1929 />
1930 )}
1931 + {props.worktreeSetup && entry.id === props.setupFoldRowId ? (
1932 + <WorktreeSetupFoldChip
1933 + {...props.worktreeSetup}
1934 + detailsOpen={props.setupDetailsOpen}
1935 + onOpenDetails={props.onOpenSetupDetails}
1936 + />
1937 + ) : null}
1938 {entry.checkpointSummary ? (
1939 <TurnDiffStat
1940 checkpoint={entry.checkpointSummary}
@@ -3548,7 +3563,12 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
3563 // LegendList does not invalidate visible rows when only the renderItem closure changes.
3564 // Include turn completion so unchanged message rows reveal their footer and spacing
3565 // even when the final message update arrives before the turn settles.
3566 + // One sheet for the setup's card, chip, and summary row, so it stays open as setup moves between them.
3567 + const [setupDetailsThreadId, setSetupDetailsThreadId] = useState<string | null>(null);
3568 + const setupDetailsOpen = setupDetailsThreadId === props.threadId && !!props.worktreeSetup;
3569 + const openSetupDetails = () => setSetupDetailsThreadId(props.threadId);
3570 const listAppearanceData = {
3571 + setupDetailsOpen,
3572 disclosureLayout,
3573 reduceMotion,
3574 formatMessageTime,
@@ -3664,6 +3684,18 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
3684 const setupAnchorIndex = presentedFeed.findIndex(
3685 (entry) => entry.type === "message" && entry.message.role === "user",
3686 );
3687 + // As on web, setup still running after the agent took the turn rides on the live Working row.
3688 + const setupFoldRowId =
3689 + props.worktreeSetup &&
3690 + worktreeSetupHandedOff(props.worktreeSetup) &&
3691 + props.worktreeSetup.snapshot.phase === "running"
3692 + ? (presentedFeed.find(
3693 + (entry, index) =>
3694 + index > setupAnchorIndex &&
3695 + entry.type === "run-fold" &&
3696 + entry.workingSince !== undefined,
3697 + )?.id ?? null)
3698 + : null;
3699 const [groupFeed] = useState(createThreadFeedGrouping);
3700 const groupedFeed = groupFeed(presentedFeed, {
3701 workflowOpeningMessageId: workflowOpening?.messageId,
@@ -4001,6 +4033,10 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
4033 environmentId: props.environmentId,
4034 dispatchingMessageId: props.dispatchingMessageId,
4035 pendingFoldMessageId,
4036 + setupFoldRowId,
4037 + worktreeSetup: props.worktreeSetup,
4038 + setupDetailsOpen,
4039 + onOpenSetupDetails: openSetupDetails,
4040 onEditPendingMessage: props.onEditPendingMessage,
4041 onUseArtifactTemplate: props.onUseArtifactTemplate,
4042 threadId: props.threadId,
@@ -4041,7 +4077,12 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
4077 workflowOpening,
4078 })}
4079 {props.worktreeSetup && info.index === setupAnchorIndex ? (
4044 - <WorktreeSetupCard key={props.threadId} {...props.worktreeSetup} />
4080 + <WorktreeSetupCard
4081 + key={props.threadId}
4082 + {...props.worktreeSetup}
4083 + detailsOpen={setupDetailsOpen}
4084 + onOpenDetails={openSetupDetails}
4085 + />
4086 ) : props.preparingWorktree && info.index === setupAnchorIndex ? (
4087 <WorktreePreparingHeader />
4088 ) : null}
@@ -4144,7 +4185,12 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
4185 <>
4186 {usesNativeAutomaticInsets ? null : <View style={{ height: topContentInset }} />}
4187 {setupAnchorIndex < 0 && props.worktreeSetup ? (
4147 - <WorktreeSetupCard key={props.threadId} {...props.worktreeSetup} />
4188 + <WorktreeSetupCard
4189 + key={props.threadId}
4190 + {...props.worktreeSetup}
4191 + detailsOpen={setupDetailsOpen}
4192 + onOpenDetails={openSetupDetails}
4193 + />
4194 ) : setupAnchorIndex < 0 && props.preparingWorktree ? (
4195 <WorktreePreparingHeader />
4196 ) : null}
@@ -4197,6 +4243,12 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
4243 </View>
4244 ) : null}
4245 <VideoPreviewModal source={expandedVideo} onRequestClose={closeVideoPreview} />
4246 + {setupDetailsOpen && props.worktreeSetup ? (
4247 + <WorktreeSetupDetails
4248 + {...props.worktreeSetup}
4249 + onClose={() => setSetupDetailsThreadId(null)}
4250 + />
4251 + ) : null}
4252 <FilePreviewModal source={expandedFile} onRequestClose={closeFilePreview} />
4253 </View>
4254 </PresentationSource>
apps/mobile/src/features/threads/worktree-setup-card.tsx
+131 -66
@@ -7,7 +7,6 @@ import {
7 } from "@t3tools/contracts";
8 import { worktreeSetupAgentStarted } from "@t3tools/client-runtime/worktree-setup";
9 import { formatDuration } from "@t3tools/shared/orchestrationTiming";
10 -import { useState } from "react";
10 import { Platform, Pressable, ScrollView, View } from "react-native";
11 import { useSafeAreaInsets } from "react-native-safe-area-context";
12 import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator";
@@ -38,21 +37,29 @@ const icons: Record<WorktreeSetupStage["status"], AppSymbolName> = {
37 warning: "exclamationmark.triangle",
38 };
39
41 -export function WorktreeSetupCard(props: WorktreeSetupCardProps) {
42 - const { snapshot, turnStarted } = props;
43 - const handedOff = turnStarted && worktreeSetupAgentStarted(snapshot);
40 +/** The feed owns whether the details sheet is open, so it survives the card turning into a chip or summary. */
41 +interface SetupDetailsControl {
42 + readonly detailsOpen: boolean;
43 + readonly onOpenDetails: () => void;
44 +}
45 +
46 +export function WorktreeSetupCard(props: WorktreeSetupCardProps & SetupDetailsControl) {
47 + // Once the agent has the turn, running setup is a chip on the live Working row.
48 + if (worktreeSetupHandedOff(props)) {
49 + // As on web, only a setup that went wrong stays in view.
50 + return setupWentWrong(props.snapshot) ? <WorktreeSetupSummaryRow {...props} /> : null;
51 + }
52 + return <WorktreeSetupHeaderCard {...props} />;
53 +}
54 +
55 +function WorktreeSetupHeaderCard(props: WorktreeSetupCardProps & SetupDetailsControl) {
56 + const { snapshot, detailsOpen } = props;
57 const running = snapshot.phase === "running";
45 - const backgroundSetup = handedOff && running;
46 - const scriptName = snapshot.setupScript?.name ?? "Setup script";
47 - const [detailsOpen, setDetailsOpen] = useState(false);
58 const now = useVisibleSecondClock(running);
59 const failed =
60 snapshot.phase === "failed" || snapshot.stages.some((stage) => stage.status === "failed");
51 - // Once the agent has the turn, its own fold row carries the working timer.
61 const label = running
53 - ? handedOff
54 - ? "Setup continues…"
55 - : "Setting up worktree…"
62 + ? "Setting up worktree…"
63 : snapshot.phase === "cancelled"
64 ? "Worktree setup cancelled"
65 : snapshot.phase === "failed"
@@ -65,43 +72,21 @@ export function WorktreeSetupCard(props: WorktreeSetupCardProps) {
72 <View accessibilityLabel="Worktree setup" className="py-1">
73 <View className="min-h-11 flex-row items-center gap-2 border-b border-border px-1">
74 <HeaderLabel label={label} active={running && !detailsOpen} failed={failed} />
68 - {!handedOff ? (
69 - <Text
70 - className="text-2xs text-foreground-secondary"
71 - style={{ fontVariant: ["tabular-nums"] }}
72 - >
73 - {elapsed(snapshot.startedAt, snapshot.endedAt, now)}
74 - </Text>
75 - ) : null}
75 + <Text
76 + className="text-2xs text-foreground-secondary"
77 + style={{ fontVariant: ["tabular-nums"] }}
78 + >
79 + {elapsed(snapshot.startedAt, snapshot.endedAt, now)}
80 + </Text>
81 <Pressable
82 accessibilityRole="button"
78 - accessibilityLabel={
79 - backgroundSetup
80 - ? `Background setup is still running: ${scriptName}. Show setup progress.`
81 - : "Worktree setup details"
82 - }
83 + accessibilityLabel="Worktree setup details"
84 accessibilityState={{ expanded: detailsOpen }}
84 - onPress={() => setDetailsOpen(true)}
85 + onPress={props.onOpenDetails}
86 className="min-h-11 max-w-[55%] justify-center px-2"
87 >
87 - <View
88 - className={
89 - backgroundSetup
90 - ? "min-w-0 flex-row items-center gap-1 rounded-full border border-border px-2 py-1"
91 - : "flex-row items-center gap-1"
92 - }
93 - >
94 - {backgroundSetup ? (
95 - <AppActivityIndicator
96 - size={Platform.OS === "android" ? 12 : "small"}
97 - colorClassName="accent-icon-muted"
98 - style={{
99 - width: 12,
100 - height: 12,
101 - transform: Platform.OS === "android" ? undefined : [{ scale: 0.65 }],
102 - }}
103 - />
104 - ) : failed ? (
88 + <View className="flex-row items-center gap-1">
89 + {failed ? (
90 <SymbolView
91 name="exclamationmark.circle"
92 size={12}
@@ -109,37 +94,117 @@ export function WorktreeSetupCard(props: WorktreeSetupCardProps) {
94 />
95 ) : null}
96 <Text numberOfLines={1} className="shrink text-2xs text-foreground-secondary">
112 - {backgroundSetup ? "Background setup" : "Details"}
97 + Details
98 </Text>
114 - {!backgroundSetup ? (
115 - <SymbolView name="chevron.right" size={10} tintColorClassName="accent-icon-muted" />
116 - ) : null}
99 + <SymbolView name="chevron.right" size={10} tintColorClassName="accent-icon-muted" />
100 </View>
101 </Pressable>
102 </View>
120 - {!handedOff ? (
121 - <View className="pt-1 pb-2">
122 - {snapshot.stages
123 - .filter((stage) => stage.id !== "agent")
124 - .map((stage) => (
125 - <StageRow
126 - key={stage.id}
127 - stage={stage}
128 - scriptName={snapshot.setupScript?.name ?? null}
129 - now={now}
130 - compact
131 - animate={!detailsOpen}
132 - />
133 - ))}
134 - </View>
135 - ) : null}
136 - {detailsOpen ? (
137 - <SetupDetailsSheet {...props} now={now} onClose={() => setDetailsOpen(false)} />
138 - ) : null}
103 + <View className="pt-1 pb-2">
104 + {snapshot.stages
105 + .filter((stage) => stage.id !== "agent")
106 + .map((stage) => (
107 + <StageRow
108 + key={stage.id}
109 + stage={stage}
110 + scriptName={snapshot.setupScript?.name ?? null}
111 + now={now}
112 + compact
113 + animate={!detailsOpen}
114 + />
115 + ))}
116 + </View>
117 </View>
118 );
119 }
120
121 +/** True once the agent has the turn; the turn's fold row then carries the setup instead of the card. */
122 +export function worktreeSetupHandedOff(props: WorktreeSetupCardProps): boolean {
123 + return props.turnStarted && worktreeSetupAgentStarted(props.snapshot);
124 +}
125 +
126 +/** The card's state on the turn's fold row: setup still running, or a failure to look at. */
127 +export function WorktreeSetupFoldChip(props: WorktreeSetupCardProps & SetupDetailsControl) {
128 + const scriptName = props.snapshot.setupScript?.name ?? "Setup script";
129 + return (
130 + <Pressable
131 + accessibilityRole="button"
132 + accessibilityLabel={`Background setup is still running: ${scriptName}. Show setup progress.`}
133 + onPress={props.onOpenDetails}
134 + hitSlop={8}
135 + className="ml-2 min-w-0 max-w-[55%] flex-row items-center gap-1 rounded-full border border-border px-2 py-1 active:opacity-70"
136 + >
137 + <AppActivityIndicator
138 + size={Platform.OS === "android" ? 12 : "small"}
139 + colorClassName="accent-icon-muted"
140 + style={{
141 + width: 12,
142 + height: 12,
143 + transform: Platform.OS === "android" ? undefined : [{ scale: 0.65 }],
144 + }}
145 + />
146 + <Text numberOfLines={1} className="shrink text-2xs text-foreground-secondary">
147 + Background setup
148 + </Text>
149 + </Pressable>
150 + );
151 +}
152 +
153 +/**
154 + * Setup that ended after the agent took the turn, as one row under the prompt, like web's
155 + * collapsed summary. Tapping it opens the details.
156 + */
157 +function setupWentWrong(snapshot: WorktreeSetupSnapshot): boolean {
158 + return (
159 + snapshot.phase === "failed" ||
160 + snapshot.phase === "cancelled" ||
161 + (snapshot.phase === "done" &&
162 + snapshot.stages.some((stage) => stage.id === "setup-script" && stage.status === "failed"))
163 + );
164 +}
165 +
166 +function WorktreeSetupSummaryRow(props: WorktreeSetupCardProps & SetupDetailsControl) {
167 + const { snapshot } = props;
168 + const now = useVisibleSecondClock(false);
169 + const label =
170 + snapshot.phase === "failed"
171 + ? "Worktree setup failed"
172 + : snapshot.phase === "cancelled"
173 + ? "Worktree setup cancelled"
174 + : "Worktree ready, setup script failed";
175 + return (
176 + <Pressable
177 + accessibilityRole="button"
178 + accessibilityLabel={`${label}. Show setup details.`}
179 + onPress={props.onOpenDetails}
180 + className="mb-1 min-h-8 flex-row items-center px-1 active:opacity-70"
181 + style={{ columnGap: 8 }}
182 + >
183 + <View className="w-6 items-center">
184 + <SymbolView name="xmark" size={14} tintColorClassName="accent-danger-foreground" />
185 + </View>
186 + <Text numberOfLines={1} className="flex-1 text-sm text-danger-foreground">
187 + {label}
188 + </Text>
189 + <Text
190 + className="text-2xs text-foreground-secondary"
191 + style={{ fontVariant: ["tabular-nums"] }}
192 + >
193 + {elapsed(snapshot.startedAt, snapshot.endedAt, now)}
194 + </Text>
195 + <SymbolView name="chevron.right" size={10} tintColorClassName="accent-icon-muted" />
196 + </Pressable>
197 + );
198 +}
199 +
200 +/** The one setup details sheet, opened from the card, the chip, or the summary row. */
201 +export function WorktreeSetupDetails(
202 + props: WorktreeSetupCardProps & { readonly onClose: () => void },
203 +) {
204 + const now = useVisibleSecondClock(props.snapshot.phase === "running");
205 + return <SetupDetailsSheet {...props} now={now} />;
206 +}
207 +
208 /** Holds the card's place until the server publishes the first setup snapshot. */
209 // Same rows the first snapshot brings, so the card keeps its height when that snapshot lands.
210 const PREPARING_STAGES: ReadonlyArray<WorktreeSetupStage> = WORKTREE_SETUP_STAGE_ORDER.filter(