@devries-cameron20 / t3code-1 / commits / 841f98d4d8
Fork 0

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

fix(mobile): a steer splits a settled turn's "Worked for" fold (#35408)

Julius Marminge committed Nov 12, 2026 at 10:01 UTC 841f98d4d80f88ce7218dc1d8dd388cd1e13aee4
3 files changed +177 -48
apps/mobile/src/features/threads/ThreadFeed.tsx
+1 -1
@@ -3326,7 +3326,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
3326 const jumpRunId =
3327 jumpReady &&
3328 !presentedFeed.some((entry) => entry.type === "message" && entry.id === jumpToMessageId)
3329 - ? messageFoldRunId(props.feed, jumpToMessageId)
3329 + ? messageFoldRunId(props.feed, jumpToMessageId, presentedFeed)
3330 : null;
3331 if (jumpRunId && !expandedTurnIds.has(jumpRunId)) {
3332 setInteractionState((current) => ({
apps/mobile/src/lib/threadActivity.test.ts
+69 -5
@@ -896,16 +896,20 @@ describe("buildThreadFeed", () => {
896 projected(runless ? { ...item, runId: null } : item, position),
897 ),
898 );
899 - const foldRunId = messageFoldRunId(feed, "message-middle");
900 - expect(foldRunId, String(runless)).toBe(runless ? "runless:message-user" : runId);
899 const ids = (expanded: ReadonlySet<RunId>) =>
900 deriveThreadFeedPresentation(feed, null, expanded).map((entry) => entry.id);
901 + const foldRunId = messageFoldRunId(
902 + feed,
903 + "message-middle",
904 + deriveThreadFeedPresentation(feed, null, new Set()),
905 + );
906 + expect(foldRunId, String(runless)).toBe(runless ? "runless:message-user" : runId);
907 expect(ids(new Set())).not.toContain("message-middle");
908 expect(ids(new Set([foldRunId!]))).toContain("message-middle");
909 }
906 - expect(messageFoldRunId(buildThreadFeed([projected(userMessage(), 0)]), "message-user")).toBe(
907 - null,
908 - );
910 + expect(
911 + messageFoldRunId(buildThreadFeed([projected(userMessage(), 0)]), "message-user", []),
912 + ).toBe(null);
913 });
914
915 it("folds progress messages while keeping the final assistant answer visible", () => {
@@ -1010,6 +1014,66 @@ describe("buildThreadFeed", () => {
1014 ]);
1015 });
1016
1017 + it("splits a settled turn's work fold at a steer", () => {
1018 + const steer = {
1019 + ...userMessage("2026-06-20T00:00:04.000Z"),
1020 + id: TurnItemId.make("item-steer"),
1021 + messageId: MessageId.make("message-steer"),
1022 + inputIntent: "steer" as const,
1023 + };
1024 + const after = { ...command("2026-06-20T00:00:06.000Z"), id: TurnItemId.make("item-after") };
1025 + const progress = {
1026 + ...assistantMessage("2026-06-20T00:00:07.000Z"),
1027 + id: TurnItemId.make("item-progress"),
1028 + messageId: MessageId.make("message-progress"),
1029 + };
1030 + const feed = buildThreadFeed(
1031 + [
1032 + userMessage(),
1033 + command(),
1034 + steer,
1035 + after,
1036 + progress,
1037 + assistantMessage("2026-06-20T00:00:09.000Z"),
1038 + ].map((item, position) => projected(item, position)),
1039 + );
1040 +
1041 + expect(
1042 + deriveThreadFeedPresentation(feed, null, new Set()).map((entry) =>
1043 + entry.type === "message" ? entry.id : entry.type,
1044 + ),
1045 + ).toEqual(["message-user", "run-fold", "message-steer", "run-fold", "message-assistant"]);
1046 + const foldRunId = messageFoldRunId(
1047 + feed,
1048 + "message-progress",
1049 + deriveThreadFeedPresentation(feed, null, new Set()),
1050 + );
1051 + expect(
1052 + deriveThreadFeedPresentation(feed, null, new Set([foldRunId!])).map((entry) =>
1053 + entry.type === "message" ? entry.id : entry.type,
1054 + ),
1055 + ).toEqual([
1056 + "message-user",
1057 + "run-fold",
1058 + "message-steer",
1059 + "run-fold",
1060 + "activity-group",
1061 + "message-progress",
1062 + "message-assistant",
1063 + ]);
1064 +
1065 + // Hiding tools leaves no output before the steer, so nothing splits there.
1066 + const hideAll = (expanded: ReadonlySet<RunId>) =>
1067 + deriveThreadFeedPresentation(feed, null, expanded, new Set(), null, false, undefined, {
1068 + toolCallVisibility: "hideAll",
1069 + revealedMessageId: null,
1070 + });
1071 + const hiddenToolsFoldRunId = messageFoldRunId(feed, "message-progress", hideAll(new Set()));
1072 + expect(hideAll(new Set([hiddenToolsFoldRunId!])).map((entry) => entry.id)).toContain(
1073 + "message-progress",
1074 + );
1075 + });
1076 +
1077 it("folds subagents while keeping created-thread and fork cards visible", () => {
1078 const { providerThreadId: _providerThreadId, ...forkBase } = base(
1079 "item-fork",
apps/mobile/src/lib/threadActivity.ts
+107 -42
@@ -1058,25 +1058,51 @@ export function failedFeedRunIds(
1058 /**
1059 * The key a run fold uses for the message `entryId`: its run, or for an
1060 * imported message with no run, the runless key of the user message before
1061 - * it. Null for user messages, which never fold.
1061 + * it, or the segment after its run's last steer when `presented` shows that
1062 + * fold. Null for user messages, which never fold.
1063 */
1064 export function messageFoldRunId(
1065 feed: ReadonlyArray<ThreadFeedEntry>,
1066 entryId: string,
1067 + presented: ReadonlyArray<{ readonly type: string; readonly runId?: RunId | null }>,
1068 ): RunId | null {
1069 let runlessKey: RunId | null = null;
1070 + const lastSteerIdByRunId = new Map<RunId, string>();
1071 for (const entry of feed) {
1072 if (entry.type !== "message") continue;
1073 if (entry.message.role === "user") {
1074 if (entry.id === entryId) return null;
1075 + if (isSteerMessage(entry.message) && entry.message.runId != null) {
1076 + lastSteerIdByRunId.set(entry.message.runId, entry.id);
1077 + }
1078 runlessKey = entry.message.runId == null ? RunId.make(`runless:${entry.id}`) : null;
1079 } else if (entry.id === entryId) {
1074 - return entry.message.runId ?? runlessKey;
1080 + const runId = entry.message.runId ?? runlessKey;
1081 + const steerId = runId === null ? undefined : lastSteerIdByRunId.get(runId);
1082 + if (runId === null || steerId === undefined) return runId;
1083 + // Tool visibility can drop all output before the steer, leaving no split.
1084 + const steerKey = steerFoldRunId(runId, steerId);
1085 + return presented.some((row) => row.type === "run-fold" && row.runId === steerKey)
1086 + ? steerKey
1087 + : runId;
1088 }
1089 }
1090 return null;
1091 }
1092
1093 +function steerFoldRunId(runId: RunId, steerEntryId: string): RunId {
1094 + return RunId.make(`${runId}:steer:${steerEntryId}`);
1095 +}
1096 +
1097 +function feedEntryFoldRunId(entry: ThreadFeedEntry, runlessKey: RunId | null): RunId | null {
1098 + if (entry.type === "message") {
1099 + return entry.message.role === "assistant" ? (entry.message.runId ?? runlessKey) : null;
1100 + }
1101 + return entry.type === "activity-group" || entry.type === "html-render" || entry.type === "mcp-app"
1102 + ? (entry.runId ?? runlessKey)
1103 + : null;
1104 +}
1105 +
1106 function answersBeforeSteers(feed: ReadonlyArray<ThreadFeedEntry>): ReadonlySet<MessageId> {
1107 const ids = new Set<MessageId>();
1108 let previous: ThreadFeedEntry | undefined;
@@ -1121,26 +1147,35 @@ function deriveThreadFeedRunFolds(
1147 }
1148 const groupsByRunId = new Map<
1149 RunId,
1124 - { entries: ThreadFeedEntry[]; startBoundary: string | null }
1150 + {
1151 + entries: ThreadFeedEntry[];
1152 + startBoundary: string | null;
1153 + /** Each steer after the run has output starts a segment at this index into `entries`. */
1154 + steerSegments: Array<{ startIndex: number; steer: ThreadFeedEntry }>;
1155 + }
1156 >();
1157 let runlessKey: RunId | null = null;
1158 let responseKey: RunId | null = null;
1159 let pendingUserBoundary: string | null = null;
1160 for (const [index, entry] of feed.entries()) {
1161 if (entry.type === "message" && entry.message.role === "user") {
1162 + const steerGroup =
1163 + isSteerMessage(entry.message) && entry.message.runId != null
1164 + ? groupsByRunId.get(entry.message.runId)
1165 + : undefined;
1166 + if (steerGroup && steerGroup.entries.length > 0) {
1167 + // Back-to-back steers split once, after the last of them.
1168 + if (steerGroup.steerSegments.at(-1)?.startIndex === steerGroup.entries.length) {
1169 + steerGroup.steerSegments.pop();
1170 + }
1171 + steerGroup.steerSegments.push({ startIndex: steerGroup.entries.length, steer: entry });
1172 + }
1173 pendingUserBoundary = entry.message.createdAt;
1174 runlessKey = entry.message.runId == null ? RunId.make(`runless:${entry.id}`) : null;
1175 responseKey = entry.message.runId ?? runlessKey;
1176 continue;
1177 }
1136 - const ownRunId =
1137 - entry.type === "message" && entry.message.role === "assistant"
1138 - ? (entry.message.runId ?? runlessKey)
1139 - : entry.type === "activity-group" ||
1140 - entry.type === "html-render" ||
1141 - entry.type === "mcp-app"
1142 - ? (entry.runId ?? runlessKey)
1143 - : null;
1178 + const ownRunId = feedEntryFoldRunId(entry, runlessKey);
1179 if (!ownRunId) continue;
1180 // Resumed subagents keep their original turn position and fold, leaving later run folds under their own prompts.
1181 const runId =
@@ -1149,7 +1184,7 @@ function deriveThreadFeedRunFolds(
1184 : ownRunId;
1185 let group = groupsByRunId.get(runId);
1186 if (!group) {
1152 - group = { entries: [], startBoundary: pendingUserBoundary };
1187 + group = { entries: [], startBoundary: pendingUserBoundary, steerSegments: [] };
1188 pendingUserBoundary = null;
1189 groupsByRunId.set(runId, group);
1190 }
@@ -1215,15 +1250,15 @@ function deriveThreadFeedRunFolds(
1250 .map((entry) => entry.id),
1251 );
1252 const firstEntry = group.entries[0];
1218 - const firstHiddenEntry = group.entries.find((entry) => hiddenEntryIds.has(entry.id));
1253 const lastEntry = group.entries.at(-1);
1220 - if (!firstHiddenEntry || !firstEntry || !lastEntry) continue;
1221 - const hidesNonCompactionWork = group.entries.some(
1222 - (entry) =>
1223 - hiddenEntryIds.has(entry.id) &&
1224 - !(entry.type === "activity-group" && isContextCompactionActivityGroup(entry)),
1225 - );
1226 - if (!hidesNonCompactionWork) continue;
1254 + if (!firstEntry || !lastEntry) continue;
1255 + const hidesNonCompactionWork = (entries: ReadonlyArray<ThreadFeedEntry>) =>
1256 + entries.some(
1257 + (entry) =>
1258 + hiddenEntryIds.has(entry.id) &&
1259 + !(entry.type === "activity-group" && isContextCompactionActivityGroup(entry)),
1260 + );
1261 + if (!hidesNonCompactionWork(group.entries)) continue;
1262 const terminalEntry = terminalAssistantId
1263 ? group.entries.find((entry) => entry.id === terminalAssistantId)
1264 : null;
@@ -1243,28 +1278,58 @@ function deriveThreadFeedRunFolds(
1278 const duration = elapsedMs === null ? null : formatDuration(elapsedMs);
1279 const interrupted =
1280 latestRunMatches && (latestRun.status === "interrupted" || latestRun.status === "cancelled");
1246 - const deferredWorkItemIds = group.entries.flatMap((entry) =>
1247 - entry.type === "activity-group"
1248 - ? entry.activities.flatMap((activity) =>
1249 - activity.projectedItem.item.deferredWork
1250 - ? [String(activity.projectedItem.sourceItemId)]
1251 - : [],
1252 - )
1253 - : [],
1254 - );
1255 - foldsByAnchorId.set(firstHiddenEntry.id, {
1256 - ...(deferredWorkItemIds.length > 0 ? { deferredWorkItemIds } : {}),
1257 - runId,
1258 - createdAt: firstHiddenEntry.createdAt,
1259 - hiddenEntryIds,
1260 - label: interrupted
1261 - ? duration
1262 - ? `You stopped after ${duration}`
1263 - : "You stopped this response"
1264 - : duration
1265 - ? `Worked for ${duration}`
1266 - : "Worked",
1267 - });
1281 + const label = interrupted
1282 + ? duration
1283 + ? `You stopped after ${duration}`
1284 + : "You stopped this response"
1285 + : duration
1286 + ? `Worked for ${duration}`
1287 + : "Worked";
1288 + // The top row keeps the whole turn's time. Work after a steer folds under
1289 + // its own row below that steer, keyed apart so each segment opens alone.
1290 + const segments = [
1291 + {
1292 + runId,
1293 + entries: group.entries.slice(0, group.steerSegments[0]?.startIndex),
1294 + label,
1295 + },
1296 + ...group.steerSegments.map(({ startIndex, steer }, index) => {
1297 + const entries = group.entries.slice(startIndex, group.steerSegments[index + 1]?.startIndex);
1298 + const segmentMs = computeElapsedMs(
1299 + steer.createdAt,
1300 + entries
1301 + .map((entry) => (entry.type === "message" ? entry.message.updatedAt : entry.createdAt))
1302 + .reduce<string | null>(maxIsoTimestamp, null) ?? steer.createdAt,
1303 + );
1304 + return {
1305 + runId: steerFoldRunId(runId, steer.id),
1306 + entries,
1307 + label: segmentMs !== null ? `Continued for ${formatDuration(segmentMs)}` : "Continued",
1308 + };
1309 + }),
1310 + ];
1311 + for (const segment of segments) {
1312 + const firstHiddenEntry = segment.entries.find((entry) => hiddenEntryIds.has(entry.id));
1313 + if (!firstHiddenEntry || !hidesNonCompactionWork(segment.entries)) continue;
1314 + const deferredWorkItemIds = segment.entries.flatMap((entry) =>
1315 + entry.type === "activity-group"
1316 + ? entry.activities.flatMap((activity) =>
1317 + activity.projectedItem.item.deferredWork
1318 + ? [String(activity.projectedItem.sourceItemId)]
1319 + : [],
1320 + )
1321 + : [],
1322 + );
1323 + foldsByAnchorId.set(firstHiddenEntry.id, {
1324 + ...(deferredWorkItemIds.length > 0 ? { deferredWorkItemIds } : {}),
1325 + runId: segment.runId,
1326 + createdAt: firstHiddenEntry.createdAt,
1327 + hiddenEntryIds: new Set(
1328 + segment.entries.flatMap((entry) => (hiddenEntryIds.has(entry.id) ? [entry.id] : [])),
1329 + ),
1330 + label: segment.label,
1331 + });
1332 + }
1333 }
1334 const covered = new Set(
1335 [...foldsByAnchorId.values()].flatMap((fold) => [...fold.hiddenEntryIds]),