Skip to content

Commit 77e4f56

Browse files
authored
fix(mobile): show plans and fold settled progress notes (pingdotgg#21393)
1 parent 0dc38c7 commit 77e4f56

5 files changed

Lines changed: 209 additions & 30 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import { useAtomValue } from "@effect/atom-react";
2+
import {
3+
isAtomCommandInterrupted,
4+
squashAtomCommandFailure,
5+
} from "@t3tools/client-runtime/state/runtime";
6+
import type { EnvironmentId } from "@t3tools/contracts";
7+
import { proposedPlanTitle, stripDisplayedPlanMarkdown } from "@t3tools/shared/proposedPlanText";
8+
import { useRef, useState, type ReactNode } from "react";
9+
import { View } from "react-native";
10+
11+
import { AppText as Text } from "../../components/ui/AppText";
12+
import { Button } from "../../components/ui/Button";
13+
import * as Dialog from "../../components/ui/Dialog";
14+
import { projectEnvironment } from "../../state/projects";
15+
import { useAtomCommand } from "../../state/use-atom-command";
16+
import { CopyTextButton } from "./CopyTextButton";
17+
18+
export function ProposedPlanCard(props: {
19+
readonly environmentId: EnvironmentId;
20+
readonly workspaceRoot: string | null | undefined;
21+
readonly markdown: string;
22+
readonly renderMarkdown: (text: string) => ReactNode;
23+
}) {
24+
const canWrite = useAtomValue(projectEnvironment.writeFile.permissionAtom(props.environmentId));
25+
const writeFile = useAtomCommand(projectEnvironment.writeFile, { reportFailure: false });
26+
const inFlight = useRef(false);
27+
const [saving, setSaving] = useState(false);
28+
const [lastPath, setLastPath] = useState("plan.md");
29+
const contents = `${props.markdown.trimEnd()}\n`;
30+
31+
const save = async (path: string) => {
32+
const relativePath = path.trim();
33+
if (!canWrite || !props.workspaceRoot || inFlight.current) return;
34+
if (!relativePath) {
35+
Dialog.alert("Enter a workspace path");
36+
return;
37+
}
38+
inFlight.current = true;
39+
setSaving(true);
40+
setLastPath(relativePath);
41+
const result = await writeFile({
42+
environmentId: props.environmentId,
43+
input: { cwd: props.workspaceRoot, relativePath, contents },
44+
}).finally(() => {
45+
inFlight.current = false;
46+
setSaving(false);
47+
});
48+
if (result._tag === "Success") {
49+
Dialog.alert("Plan saved to workspace", result.value.relativePath);
50+
} else if (!isAtomCommandInterrupted(result)) {
51+
const error = squashAtomCommandFailure(result);
52+
Dialog.alert("Could not save plan", error instanceof Error ? error.message : String(error));
53+
}
54+
};
55+
56+
return (
57+
<View className="mb-3 gap-3 rounded-[20px] border border-border bg-card-alt p-4">
58+
<View className="flex-row items-center gap-2">
59+
<Text accessibilityRole="header" className="flex-1 font-t3-bold text-base text-foreground">
60+
{proposedPlanTitle(props.markdown) ?? "Proposed plan"}
61+
</Text>
62+
<CopyTextButton accessibilityLabel="Copy plan" text={contents} />
63+
</View>
64+
{props.renderMarkdown(stripDisplayedPlanMarkdown(props.markdown))}
65+
<View className="flex-row">
66+
<Button
67+
label={saving ? "Saving..." : "Save to workspace"}
68+
tone="secondary"
69+
disabled={!canWrite || !props.workspaceRoot || saving}
70+
onPress={() =>
71+
Dialog.prompt({
72+
title: "Save plan to workspace",
73+
// The write replaces an existing file, and the RPC has no create-only mode.
74+
message:
75+
"Enter a path relative to the thread's workspace. A file already at that path is replaced.",
76+
initialValue: lastPath,
77+
confirmText: "Save",
78+
onConfirm: (path) => void save(path),
79+
})
80+
}
81+
/>
82+
</View>
83+
</View>
84+
);
85+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,7 @@ function renderFeedEntry(
14451445
activities={entry.activities}
14461446
continuesWorkLog={entry.continuesWorkLog}
14471447
environmentId={props.environmentId}
1448+
workspaceRoot={props.workspaceRoot}
14481449
anchorKey={entry.id}
14491450
copiedRowId={props.copiedRowId}
14501451
expandedRows={props.expandedWorkRows}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Button } from "../../components/ui/Button";
22
import { SubagentStatusDot } from "./SubagentStatusDot";
33
import { ThreadSubagentGroup } from "./thread-subagent-group";
4+
import { ProposedPlanCard } from "./ProposedPlanCard";
45
import {
56
WorkLogLabel,
67
WorkLogBlock,
@@ -483,6 +484,7 @@ interface ThreadWorkLogProps {
483484
readonly activities: ReadonlyArray<ThreadFeedActivity>;
484485
readonly anchorKey: string;
485486
readonly environmentId: EnvironmentId;
487+
readonly workspaceRoot?: string | null | undefined;
486488
readonly copiedRowId: string | null;
487489
readonly expandedRows: Readonly<Record<string, boolean>>;
488490
readonly rowSizing: ReturnType<typeof deriveThreadWorkLogSizing>;
@@ -521,6 +523,18 @@ export function ThreadWorkLog(props: ThreadWorkLogProps) {
521523
return null;
522524
}
523525

526+
const plan = props.activities[0]?.projectedItem.item;
527+
if (plan?.type === "proposed_plan") {
528+
return (
529+
<ProposedPlanCard
530+
environmentId={props.environmentId}
531+
workspaceRoot={props.workspaceRoot}
532+
markdown={plan.markdown}
533+
renderMarkdown={props.renderReasoning}
534+
/>
535+
);
536+
}
537+
524538
if (props.activities[0]?.projectedItem.item.type === "subagent") {
525539
return <ThreadSubagentGroup {...props} />;
526540
}

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

Lines changed: 91 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,26 @@ it("keeps historical plan detail accessible from its paged turn item", () => {
6060
entry.type === "activity-group" ? entry.activities : [],
6161
)[0];
6262
expect(activity?.detail).toBe("Full historical plan text");
63-
expect(activity?.getFullDetail()).toContain("Full historical plan text");
63+
expect(activity?.getFullDetail()).toBe("Full historical plan text");
64+
expect(activity?.getCopyText()).toBe("Full historical plan text\n");
65+
expect(activity?.prominent).toBe(true);
66+
const presented = deriveThreadFeedPresentation(
67+
buildThreadFeed([
68+
projected(userMessage(), 0),
69+
projected(command(), 1),
70+
projected(item, 2),
71+
projected(assistantMessage(), 3),
72+
]),
73+
null,
74+
new Set(),
75+
);
76+
expect(presented.map((entry) => entry.type)).toEqual([
77+
"message",
78+
"run-fold",
79+
"activity-group",
80+
"message",
81+
]);
82+
expect(presented[2]).toMatchObject({ activities: [{ projectedItem: { item } }] });
6483
});
6584

6685
it("shows only the structured path in expanded mobile read details", () => {
@@ -245,6 +264,56 @@ describe("buildThreadFeed", () => {
245264
expect(buildThreadFeed([projected(reply, 0)])[0]?.type).toBe("message");
246265
});
247266

267+
it.each([false, true])(
268+
"keeps answered questions outside settled work (attachments only: %s)",
269+
(attachmentsOnly) => {
270+
const requestId = RuntimeRequestId.make("answered-question");
271+
const question: OrchestrationV2TurnItem = {
272+
...base("answered-question", "2026-06-20T00:00:02.500Z", 2),
273+
type: "user_input_request",
274+
requestId,
275+
questions: [],
276+
questionAnswer: {
277+
requestId,
278+
questionTextById: { color: "Which color?" },
279+
answers: { color: attachmentsOnly ? "" : "Blue" },
280+
attachmentsByQuestionId: attachmentsOnly
281+
? {
282+
color: [
283+
{
284+
type: "file",
285+
id: "color-file",
286+
name: "color.txt",
287+
mimeType: "text/plain",
288+
sizeBytes: 4,
289+
},
290+
],
291+
}
292+
: {},
293+
},
294+
};
295+
const feed = buildThreadFeed([
296+
projected(userMessage(), 0),
297+
projected(command(), 1),
298+
projected(question, 2),
299+
projected(assistantMessage(), 3),
300+
]);
301+
const presented = deriveThreadFeedPresentation(feed, null, new Set());
302+
expect(presented.map((entry) => entry.type)).toEqual([
303+
"message",
304+
"run-fold",
305+
"activity-group",
306+
"message",
307+
]);
308+
expect(presented[2]).toMatchObject({
309+
activities: [{ workEntry: { questionAnswer: question.questionAnswer } }],
310+
});
311+
expect(
312+
deriveThreadFeedPresentation(feed, null, new Set([runId])).map((entry) => entry.type),
313+
).toEqual(["message", "run-fold", "activity-group", "activity-group", "message"]);
314+
},
315+
);
316+
248317
it("does not create a work group for a message and checkpoint", () => {
249318
const checkpoint: OrchestrationV2TurnItem = {
250319
...base("checkpoint", "2026-06-20T00:00:04.000Z", 3),
@@ -844,7 +913,7 @@ describe("buildThreadFeed", () => {
844913
).toBe(false);
845914
});
846915

847-
it("keeps opening and final assistant messages around the first hidden work", () => {
916+
it("folds progress messages while keeping the final assistant answer visible", () => {
848917
const opening = {
849918
...assistantMessage("2026-06-20T00:00:01.500Z"),
850919
id: TurnItemId.make("item-opening"),
@@ -874,30 +943,40 @@ describe("buildThreadFeed", () => {
874943
const collapsed = deriveThreadFeedPresentation(feed, latestRun, new Set());
875944
expect(collapsed.map((entry) => entry.id)).toEqual([
876945
"message-user",
877-
"message-opening",
878946
"run-fold:run-1",
879947
"message-assistant",
880948
]);
881-
expect(collapsed[1]).toMatchObject({ message: { text: opening.text } });
882-
expect(collapsed[2]).toMatchObject({
949+
expect(collapsed[1]).toMatchObject({
883950
type: "run-fold",
884-
createdAt: "2026-06-20T00:00:02.000Z",
951+
createdAt: "2026-06-20T00:00:01.500Z",
885952
label: "Worked for 2.0s",
886953
});
887954

888955
const expanded = deriveThreadFeedPresentation(feed, latestRun, new Set([runId]));
889956
expect(expanded.map((entry) => entry.type)).toEqual([
890-
"message",
891957
"message",
892958
"run-fold",
959+
"message",
893960
"activity-group",
894961
"message",
895962
"message",
896963
]);
897964
expect(expanded[4]).toMatchObject({ message: { id: middle.messageId, text: middle.text } });
965+
966+
const active = deriveThreadFeedPresentation(
967+
feed,
968+
{ ...latestRun, status: "running", completedAt: null },
969+
new Set(),
970+
);
971+
expect(active.filter((entry) => entry.type === "message").map((entry) => entry.id)).toEqual([
972+
"message-user",
973+
"message-opening",
974+
"message-middle",
975+
"message-assistant",
976+
]);
898977
});
899978

900-
it("does not fold a response that only has opening and final messages", () => {
979+
it("folds progress even when a response has no tool calls", () => {
901980
const feed = buildThreadFeed([
902981
projected(userMessage(), 0),
903982
projected(
@@ -915,7 +994,7 @@ describe("buildThreadFeed", () => {
915994
const presented = deriveThreadFeedPresentation(feed, null, new Set());
916995
expect(presented.map((entry) => entry.id)).toEqual([
917996
"message-user",
918-
"message-opening",
997+
"run-fold:run-1",
919998
"message-assistant",
920999
]);
9211000
});
@@ -1230,7 +1309,7 @@ describe("buildThreadFeed", () => {
12301309
new Set(),
12311310
"2026-06-20T00:01:00.000Z",
12321311
)
1233-
.slice(0, 4)
1312+
.slice(0, 3)
12341313
.map((entry) => (entry.type === "message" ? entry.message.role : entry.type));
12351314

12361315
expect(
@@ -1239,7 +1318,7 @@ describe("buildThreadFeed", () => {
12391318
id: TurnItemId.make("new-prompt"),
12401319
messageId: MessageId.make("new-prompt"),
12411320
}),
1242-
).toEqual(["user", "assistant", "run-fold", "assistant"]);
1321+
).toEqual(["user", "run-fold", "assistant"]);
12431322
expect(
12441323
presented({
12451324
...base("wake", "2026-06-20T00:01:00.000Z", 4),
@@ -1248,7 +1327,7 @@ describe("buildThreadFeed", () => {
12481327
outcome: "completed",
12491328
summary: "Background task finished",
12501329
}),
1251-
).toEqual(["user", "assistant", "run-fold", "assistant"]);
1330+
).toEqual(["user", "run-fold", "assistant"]);
12521331
});
12531332

12541333
it("keeps a provider-native subagent's runless tool call live while it works", () => {
@@ -2247,7 +2326,6 @@ describe("subagent continued by a later turn", () => {
22472326
"answer-1",
22482327
"prompt-2",
22492328
`run-fold:${run2}`,
2250-
"answer-2",
22512329
"closing-2",
22522330
]);
22532331
});

0 commit comments

Comments
 (0)