Skip to content

Commit 90dab34

Browse files
committed
fix(mobile): fit compact widget rows and fill large with unsettled threads
1 parent 0e64cf4 commit 90dab34

9 files changed

Lines changed: 384 additions & 47 deletions

‎apps/mobile/src/widgets/AgentActivityWidget.test.mjs‎

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,52 @@ it("embeds an Agent Activity Home Screen layout and initial data independently o
113113
status: "Working",
114114
})),
115115
};
116+
for (const widgetFamily of ["systemSmall", "systemMedium", "systemLarge"]) {
117+
const supplemented = JSON.stringify(
118+
context.__expoWidgetRender(
119+
{
120+
...aggregate,
121+
supplementalActivities: [
122+
aggregate.activities[0],
123+
...Array.from({ length: 7 }, (_, i) => ({
124+
...props.activities[0],
125+
threadId: `local-${i}`,
126+
threadTitle: `Local task ${i + 1}`,
127+
phase: "completed",
128+
status: "Done",
129+
deepLink: `/threads/environment/local%3A${i + 1}`,
130+
})),
131+
],
132+
},
133+
{ widgetFamily, colorScheme: "light", widgetRenderingMode: "fullColor" },
134+
),
135+
);
136+
expect(supplemented).toContain("10 active");
137+
if (widgetFamily === "systemLarge") {
138+
expect(supplemented).toContain("Local task 2");
139+
expect(supplemented).not.toContain("Local task 3");
140+
expect(supplemented).toContain("t3code-dev:///threads/environment/local%3A2");
141+
} else {
142+
expect(supplemented).not.toContain("Local task");
143+
}
144+
}
145+
const localOnly = JSON.stringify(
146+
context.__expoWidgetRender(
147+
{
148+
...props,
149+
activeCount: 0,
150+
activities: [],
151+
supplementalActivities: [props.activities[0]],
152+
},
153+
{ widgetFamily: "systemLarge", colorScheme: "light", widgetRenderingMode: "fullColor" },
154+
),
155+
);
156+
expect(localOnly).toContain("Review the task");
157+
expect(localOnly).toContain("0 active");
116158
for (const [widgetFamily, dynamicTypeSize, visibleRows] of [
117-
["systemMedium", "large", 2],
118-
["systemMedium", "xxLarge", 2],
119-
["systemMedium", "xxxLarge", 1],
159+
["systemMedium", "large", 5],
160+
["systemMedium", "xxLarge", 4],
161+
["systemMedium", "xxxLarge", 3],
120162
["systemMedium", "accessibility5", 1],
121163
["systemLarge", "large", 5],
122164
["systemLarge", "xLarge", 4],

‎apps/mobile/src/widgets/AgentActivityWidget.tsx‎

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HStack, Image, Link, Spacer, Text, VStack } from "@expo/ui/swift-ui";
1+
import { Divider, HStack, Image, Link, Spacer, Text, VStack } from "@expo/ui/swift-ui";
22
import {
33
fixedSize,
44
font,
@@ -27,6 +27,7 @@ export interface AgentActivityWidgetProps {
2727
| "deepLink"
2828
>
2929
>;
30+
readonly supplementalActivities?: AgentActivityWidgetProps["activities"];
3031
readonly baseUrl?: string;
3132
readonly freshUntil?: number;
3233
readonly updatedAt?: string;
@@ -39,7 +40,21 @@ function AgentActivityWidget(props: AgentActivityWidgetProps, environment: Widge
3940
"widget";
4041
const now = Math.max(environment.date?.getTime() ?? 0, Date.now());
4142
const expired = (props.freshUntil ?? Infinity) <= now;
42-
const rows = (props.activities ?? []).map((row) =>
43+
const large = environment.widgetFamily === "systemLarge";
44+
const activityRows = [...(props.activities ?? [])];
45+
if (large && props.source === "snapshot") {
46+
for (const row of props.supplementalActivities ?? []) {
47+
if (
48+
!activityRows.some(
49+
(existing) =>
50+
existing.environmentId === row.environmentId && existing.threadId === row.threadId,
51+
)
52+
) {
53+
activityRows.push(row);
54+
}
55+
}
56+
}
57+
const rows = activityRows.map((row) =>
4358
expired && row.phase !== "completed" && row.phase !== "failed"
4459
? { ...row, phase: "stale" as const, status: "Out of date" }
4560
: row,
@@ -48,8 +63,7 @@ function AgentActivityWidget(props: AgentActivityWidgetProps, environment: Widge
4863
const activeCount = props.activeCount ?? 0;
4964
const accessory = environment.widgetFamily === "accessoryRectangular";
5065
const small = environment.widgetFamily === "systemSmall";
51-
const large = environment.widgetFamily === "systemLarge";
52-
const roomier = !small && !accessory;
66+
const listLayout = !small && !accessory;
5367
const textSize = environment.dynamicTypeSize ?? "large";
5468
const accessibility = textSize.startsWith("accessibility");
5569
const enlarged = textSize === "xxxLarge";
@@ -60,12 +74,16 @@ function AgentActivityWidget(props: AgentActivityWidgetProps, environment: Widge
6074
? 3
6175
: textSize === "xLarge" || textSize === "xxLarge"
6276
? 4
63-
: 5
64-
: accessibility || enlarged
77+
: 7
78+
: accessibility
6579
? 1
66-
: 2;
80+
: enlarged
81+
? 3
82+
: textSize === "xLarge" || textSize === "xxLarge"
83+
? 4
84+
: 5;
6785
const hero = rows[0];
68-
const showRows = roomier && rows.length > 0;
86+
const showRows = listLayout && rows.length > 0;
6987
const monochrome =
7088
environment.widgetRenderingMode !== "fullColor" || environment.isLuminanceReduced;
7189
const statusColor = (row: AgentActivityWidgetProps["activities"][number]) => {
@@ -102,7 +120,7 @@ function AgentActivityWidget(props: AgentActivityWidgetProps, environment: Widge
102120
const text = (
103121
<Text
104122
modifiers={[
105-
font(roomier ? { textStyle: "caption2" } : { size: 11, weight: "medium" }),
123+
font(listLayout ? { textStyle: "caption2" } : { size: 11, weight: "medium" }),
106124
foregroundStyle(color),
107125
lineLimit(1),
108126
...(horizontal ? [layoutPriority(1)] : []),
@@ -126,33 +144,41 @@ function AgentActivityWidget(props: AgentActivityWidgetProps, environment: Widge
126144
return (
127145
<VStack
128146
alignment="leading"
129-
spacing={accessory ? 5 : showRows ? 8 : 10}
147+
spacing={accessory ? 5 : showRows ? (large ? 8 : 4) : 10}
130148
modifiers={[
131149
frame({ maxWidth: Infinity, maxHeight: Infinity, alignment: "topLeading" }),
132150
...(props.baseUrl ? [widgetURL(`${props.baseUrl}${hero?.deepLink.slice(1) ?? ""}`)] : []),
133151
]}
134152
>
135153
{showRows ? (
136-
rows.slice(0, rowLimit).map((row) => {
154+
rows.slice(0, rowLimit).flatMap((row, index) => {
137155
const content = (
138-
<HStack key={`${row.environmentId}:${row.threadId}`} spacing={10} alignment="center">
156+
<HStack
157+
key={`${row.environmentId}:${row.threadId}`}
158+
spacing={10}
159+
alignment="center"
160+
modifiers={large ? [] : [frame({ maxHeight: Infinity })]}
161+
>
139162
{!accessibility ? (
140163
<Image
141164
systemName={statusSymbols[row.phase]}
142-
modifiers={[font({ textStyle: "body" }), foregroundStyle(statusColor(row))]}
165+
modifiers={[
166+
font({ textStyle: large ? "body" : "subheadline" }),
167+
foregroundStyle(statusColor(row)),
168+
]}
143169
/>
144170
) : null}
145171
<VStack alignment="leading" spacing={3}>
146172
<Text
147173
modifiers={[
148174
font({ textStyle: "subheadline", weight: "semibold" }),
149175
foregroundStyle("primary"),
150-
lineLimit(large && !accessibility ? 2 : 1),
176+
lineLimit(large && rows.length <= 5 && !accessibility ? 2 : 1),
151177
]}
152178
>
153179
{row.threadTitle}
154180
</Text>
155-
{!accessibility || large ? (
181+
{large ? (
156182
<Text
157183
modifiers={[
158184
font({ textStyle: "caption2" }),
@@ -168,7 +194,7 @@ function AgentActivityWidget(props: AgentActivityWidgetProps, environment: Widge
168194
{renderStatus(row, true)}
169195
</HStack>
170196
);
171-
return props.baseUrl ? (
197+
const linked = props.baseUrl ? (
172198
<Link
173199
key={`${row.environmentId}:${row.threadId}`}
174200
destination={`${props.baseUrl}${row.deepLink.slice(1)}`}
@@ -178,6 +204,9 @@ function AgentActivityWidget(props: AgentActivityWidgetProps, environment: Widge
178204
) : (
179205
content
180206
);
207+
return large && index > 0 && index === (props.activities?.length ?? 0)
208+
? [<Divider key="activity-sections" />, linked]
209+
: [linked];
181210
})
182211
) : hero ? (
183212
<VStack alignment="leading" spacing={accessory ? 3 : 8}>
@@ -206,11 +235,11 @@ function AgentActivityWidget(props: AgentActivityWidgetProps, environment: Widge
206235
<Text
207236
modifiers={[
208237
font(
209-
roomier
238+
listLayout
210239
? { textStyle: "headline" }
211240
: { size: accessory ? 13 : 17, weight: "semibold" },
212241
),
213-
lineLimit(accessory || (roomier && !large) ? 1 : 2),
242+
lineLimit(accessory || (listLayout && !large) ? 1 : 2),
214243
]}
215244
>
216245
{props.source === "loading"
@@ -223,10 +252,10 @@ function AgentActivityWidget(props: AgentActivityWidgetProps, environment: Widge
223252
? "Ready when you are"
224253
: "Open T3 Code"}
225254
</Text>
226-
{!(roomier && accessibility && !large) ? (
255+
{!(listLayout && accessibility && !large) ? (
227256
<Text
228257
modifiers={[
229-
font(roomier ? { textStyle: "caption2" } : { size: 12 }),
258+
font(listLayout ? { textStyle: "caption2" } : { size: 12 }),
230259
foregroundStyle("secondary"),
231260
lineLimit(accessory ? 1 : 3),
232261
]}
@@ -236,12 +265,12 @@ function AgentActivityWidget(props: AgentActivityWidgetProps, environment: Widge
236265
) : null}
237266
</VStack>
238267
)}
239-
{!accessory ? <Spacer minLength={0} /> : null}
268+
{!accessory && !(showRows && !large) ? <Spacer minLength={0} /> : null}
240269
<HStack>
241270
<Spacer minLength={0} />
242271
<Text
243272
modifiers={[
244-
font(roomier ? { textStyle: "caption2" } : { size: 11, weight: "medium" }),
273+
font(listLayout ? { textStyle: "caption2" } : { size: 11, weight: "medium" }),
245274
foregroundStyle("secondary"),
246275
lineLimit(1),
247276
fixedSize({ horizontal: false, vertical: true }),
@@ -250,7 +279,7 @@ function AgentActivityWidget(props: AgentActivityWidgetProps, environment: Widge
250279
>
251280
{outOfDate
252281
? "Out of date"
253-
: activeCount > 0
282+
: activeCount > 0 || (large && (props.supplementalActivities?.length ?? 0) > 0)
254283
? `${activeCount} active`
255284
: rows.some((row) => row.phase === "failed")
256285
? "Failed"
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { expect, it } from "vite-plus/test";
2+
import { EnvironmentId, RunId, ThreadId } from "@t3tools/contracts";
3+
import { makeThreadShellFixture } from "../test-fixtures";
4+
import { buildWidgetUnsettledRows } from "./agentActivityWidgetThreads";
5+
6+
it("fills from the app's Unsettled list, excluding relay duplicates and hidden threads", () => {
7+
const thread = makeThreadShellFixture({
8+
id: ThreadId.make("local:done"),
9+
title: "Review the result",
10+
runtime: null,
11+
});
12+
const other = {
13+
...thread,
14+
environmentId: EnvironmentId.make("other"),
15+
pinnedAt: "2026-01-01T00:00:00Z",
16+
};
17+
const rows = buildWidgetUnsettledRows({
18+
threads: [
19+
thread,
20+
other,
21+
{ ...thread, id: ThreadId.make("settled"), settledOverride: "settled" },
22+
{ ...thread, id: ThreadId.make("archived"), archivedAt: "2026-01-01T00:00:00Z" },
23+
{ ...thread, id: ThreadId.make("deleted"), deletedAt: "2026-01-01T00:00:00Z" },
24+
{ ...thread, id: ThreadId.make("snoozed"), snoozedUntil: "2027-01-01T00:00:00Z" },
25+
...Array.from({ length: 8 }, (_, i) => ({
26+
...thread,
27+
id: ThreadId.make(`extra-${i}`),
28+
...(i === 0
29+
? {
30+
pinnedAt: "2026-01-01T00:00:00Z",
31+
latestRun: {
32+
runId: RunId.make("done"),
33+
status: "completed" as const,
34+
requestedAt: null,
35+
startedAt: null,
36+
completedAt: "2026-01-01T00:00:00Z",
37+
assistantMessageId: null,
38+
},
39+
}
40+
: {}),
41+
})),
42+
],
43+
projects: [{ environmentId: other.environmentId, id: other.projectId, title: "Other project" }],
44+
excluded: [
45+
{
46+
environmentId: thread.environmentId,
47+
threadId: thread.id,
48+
projectTitle: "Project",
49+
threadTitle: thread.title,
50+
phase: "running",
51+
status: "Working",
52+
deepLink: "/",
53+
},
54+
],
55+
now: "2026-11-03T00:00:00Z",
56+
settlementEnvironmentIds: new Set([thread.environmentId, other.environmentId]),
57+
queuedThreadKeys: new Set(),
58+
});
59+
expect(rows).toHaveLength(7);
60+
expect(rows).toContainEqual(
61+
expect.objectContaining({ threadId: "extra-0", phase: "completed", status: "Done" }),
62+
);
63+
for (const id of ["settled", "archived", "deleted", "snoozed"]) {
64+
expect(rows.map((row) => row.threadId)).not.toContain(id);
65+
}
66+
expect(rows.filter((row) => row.threadId === thread.id)).toEqual([
67+
expect.objectContaining({
68+
environmentId: other.environmentId,
69+
projectTitle: "Other project",
70+
status: "Ready",
71+
deepLink: "/threads/other/local%3Adone",
72+
}),
73+
]);
74+
});

0 commit comments

Comments
 (0)