Skip to content

Commit 782029c

Browse files
only21milclaude
andcommitted
Merge upstream main into fix/c047-01-disconnect-clears-notification-baselines
Resolve the append conflict in ThreadNotificationCoordinator.badge.browser.test.tsx by keeping upstream's compaction notification test and this branch's disconnect test, in that order. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 parents f2fdc5a + 3afb9b3 commit 782029c

52 files changed

Lines changed: 1870 additions & 198 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/deps/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
The Enriched Markdown tarball comes from [`feat/t3chat-markdown-parity-v2`](https://github.com/pingdotgg/enriched-markdown/tree/feat/t3chat-markdown-parity-v2), based on Julius's [`fork/t3-mobile` branch](https://github.com/pingdotgg/enriched-markdown/tree/fork/t3-mobile). Its `t3-fork.json` records the exact source commit and upstream base. File/skill link recognition, back navigation from horizontal blocks, table-image presses, and code-block headers use upstream implementations. The fork retains clipboard metadata, parsed asset manifests, signed image source resolution, React media slots, and development-host autolinks. The fork retains native math parsing, scrolling and copying, table layout and gestures, and inline-code layout. Character-reference decoding, iOS intrinsic-width measurement, and HTML clipboard round trips now use the upstream fixes included in Julius's base. RaTeX uses the upstream-released 0.1.15 dependency.
1+
The Enriched Markdown tarball comes from Julius's [`fork/t3-mobile` branch](https://github.com/pingdotgg/enriched-markdown/tree/fork/t3-mobile). Its `t3-fork.json` records the exact source commit and upstream base. React block renderers and signed image sources (`renderers`, `resolveImageSource`) are upstream. The fork carries only changes with an open upstream PR: the `onLinksChange` link list that link pills and iOS link menus read ([#1088](https://github.com/software-mansion/enriched-markdown/pull/1088)), Android inline image alignment ([#1089](https://github.com/software-mansion/enriched-markdown/pull/1089)), clipboard link metadata ([#962](https://github.com/software-mansion/enriched-markdown/pull/962)), and development-host autolinks ([#961](https://github.com/software-mansion/enriched-markdown/pull/961)).
22

3-
To replace it, commit the fork changes, run `yarn install --immutable` and `yarn workspace react-native-enriched-markdown prepare` in the fork checkout, then `node scripts/pack-t3.mjs /path/to/t3code/apps/mobile/deps`. Keep the package version aligned with Julius's `fork/t3-mobile` branch. Rename the archive to include the first eight characters of the source commit, such as `react-native-enriched-markdown-1.2.0-t3.15-fee84114.tgz`, so each build has a distinct dependency path without version bumps. Update the tarball path in `apps/mobile/package.json` and `pnpm-workspace.yaml`'s `allowBuilds`, and run `vp i` to update the lockfile. Native clients need rebuilding when this dependency changes.
3+
To replace it, commit the fork changes, run `yarn install --immutable` and `yarn workspace react-native-enriched-markdown prepare` in the fork checkout, then `node scripts/pack-t3.mjs /path/to/t3code/apps/mobile/deps`. Keep the package version aligned with Julius's `fork/t3-mobile` branch. Rename the archive to include the first eight characters of the source commit, such as `react-native-enriched-markdown-1.2.0-t3.16-8d2f84a8.tgz`, so each build has a distinct dependency path without version bumps. Update the tarball path in `apps/mobile/package.json` and `pnpm-workspace.yaml`'s `allowBuilds`, and run `vp i` to update the lockfile. Native clients need rebuilding when this dependency changes.
Binary file not shown.
Binary file not shown.

‎apps/mobile/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
"react-dom": "catalog:",
128128
"react-native": "0.88.0",
129129
"react-native-blob-util": "0.25.1",
130-
"react-native-enriched-markdown": "file:deps/react-native-enriched-markdown-1.2.0-t3.15-fee84114.tgz",
130+
"react-native-enriched-markdown": "file:deps/react-native-enriched-markdown-1.2.0-t3.16-8d2f84a8.tgz",
131131
"react-native-gesture-handler": "~3.3.0",
132132
"react-native-image-viewing": "^0.2.2",
133133
"react-native-keyboard-controller": "1.22.7",

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

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ import { KeyboardAwareLegendList } from "@legendapp/list/keyboard";
2828
import { useViewabilityAmount, type LegendListRef } from "@legendapp/list/react-native";
2929
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
3030
import type { HandoffEndpoints } from "@t3tools/client-runtime/handoff";
31-
import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message";
31+
import {
32+
IDLE_COMPACTING_LABELS,
33+
resolveUserMessagePresentation,
34+
} from "@t3tools/client-runtime/user-message";
3235
import { canForkProjectedAssistantItem } from "@t3tools/client-runtime/state/thread-workflows";
3336
import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints";
3437
import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
3538
import type { WorkflowOpening } from "@t3tools/client-runtime/state/subagentRuntime";
3639
import {
3740
AuthFilesystemReadScope,
41+
idleCompactionOf,
3842
type OrchestrationMessageContext,
3943
ThreadId,
4044
type ChatAttachment,
@@ -195,6 +199,7 @@ import {
195199
} from "../../lib/markdownLinks";
196200
import {
197201
createThreadFeedCache,
202+
threadFeedCompactionLabels,
198203
failedFeedRunIds,
199204
deriveThreadFeedPresentation,
200205
threadFeedRunIsUnsettled,
@@ -224,7 +229,11 @@ import {
224229
ThreadWorkLog,
225230
WORK_GROUP_TOGGLE_HEIGHT,
226231
} from "./thread-work-log";
227-
import { appendPendingThreadMessages, type PendingThreadFeedEntry } from "./pending-thread-feed";
232+
import {
233+
appendPendingThreadMessages,
234+
isCompactionCommandFeedEntry,
235+
type PendingThreadFeedEntry,
236+
} from "./pending-thread-feed";
228237
import type { QueuedThreadMessage } from "../../state/thread-outbox-model";
229238
import { resolveThreadFeedFixedItemSize } from "./thread-feed-item-size";
230239
import { htmlRenderFrameHeight } from "@t3tools/shared/htmlRender";
@@ -1192,6 +1201,13 @@ function ThreadAutomationMessageRow(props: {
11921201
);
11931202
}
11941203

1204+
/** Leads with why T3 Code compacted, when it did so without being asked. */
1205+
function compactionLabel(label: string, title: string | undefined) {
1206+
return title !== undefined && label.startsWith("Context compacted")
1207+
? title + label.slice("Context compacted".length)
1208+
: label;
1209+
}
1210+
11951211
function renderFeedEntry(
11961212
info: { item: PendingThreadFeedEntry; index: number },
11971213
props: Pick<
@@ -1210,6 +1226,7 @@ function renderFeedEntry(
12101226
readonly workGroupScrollPositions: Map<string, ThreadWorkGroupScrollPosition>;
12111227
readonly terminalAssistantMessageIds: ReadonlySet<string>;
12121228
readonly unsettledTurnId: RunId | null;
1229+
readonly compactionLabelsByEntryId: ReadonlyMap<string, { title: string; compacting: string }>;
12131230
readonly failedRunIds: ReadonlySet<RunId>;
12141231
readonly onCopyWorkRow: (rowId: string, value: string) => void;
12151232
readonly onToggleWorkGroup: (groupId: string, anchorKey?: string) => void;
@@ -1361,16 +1378,29 @@ function renderFeedEntry(
13611378

13621379
if (entry.type === "activity-group" && isContextCompactionActivityGroup(entry)) {
13631380
const label = entry.activities[0]!.summary;
1381+
const item = entry.activities[0]!.projectedItem.item;
13641382
const active =
13651383
props.unsettledTurnId !== null &&
13661384
entry.runId === props.unsettledTurnId &&
1367-
entry.activities[0]!.projectedItem.item.status === "running";
1385+
item.status === "running";
1386+
const labels = props.compactionLabelsByEntryId.get(entry.id);
1387+
const failure =
1388+
item.type === "compaction" && item.status === "failed" ? item.summary?.trim() : undefined;
13681389
return (
13691390
<ThreadContextDivider
1370-
label={label}
1371-
icon="arrow.down.right.and.arrow.up.left"
1391+
label={
1392+
failure
1393+
? `${label} · ${failure}`
1394+
: active && labels
1395+
? labels.compacting
1396+
: compactionLabel(label, labels?.title)
1397+
}
1398+
icon={
1399+
item.status === "failed" ? "exclamationmark.circle" : "arrow.down.right.and.arrow.up.left"
1400+
}
13721401
iconColor={iconSubtleColor}
13731402
active={active}
1403+
failed={item.status === "failed"}
13741404
/>
13751405
);
13761406
}
@@ -1409,6 +1439,25 @@ function renderFeedEntry(
14091439
/>
14101440
);
14111441
}
1442+
if (isCompactionCommandFeedEntry(entry)) {
1443+
// Stands in for the compaction item until the provider reports it.
1444+
const active = props.unsettledTurnId !== null && message.runId === props.unsettledTurnId;
1445+
const reason = idleCompactionOf(message);
1446+
return (
1447+
<ThreadContextDivider
1448+
label={
1449+
!active
1450+
? "Context compaction"
1451+
: reason === undefined
1452+
? "Compacting context"
1453+
: IDLE_COMPACTING_LABELS[reason]
1454+
}
1455+
icon="arrow.down.right.and.arrow.up.left"
1456+
iconColor={iconSubtleColor}
1457+
active={active}
1458+
/>
1459+
);
1460+
}
14121461
if (isUser && presentation.attribution === "automation") {
14131462
const rowId = `automation:${message.id}`;
14141463
return (
@@ -2505,6 +2554,10 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
25052554
);
25062555
const reviewCommentColors = useReviewCommentColors();
25072556
const unsettledTurnId = threadFeedRunIsUnsettled(props.latestRun) ? props.latestRun.runId : null;
2557+
const compactionLabelsByEntryId = useMemo(
2558+
() => threadFeedCompactionLabels(props.feed),
2559+
[props.feed],
2560+
);
25082561
// LegendList does not invalidate visible rows when only the renderItem closure changes.
25092562
// Include turn completion so unchanged message rows reveal their footer and spacing
25102563
// even when the final message update arrives before the turn settles.
@@ -2987,6 +3040,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
29873040
workGroupScrollPositions,
29883041
terminalAssistantMessageIds,
29893042
unsettledTurnId,
3043+
compactionLabelsByEntryId,
29903044
failedRunIds,
29913045
onCopyWorkRow,
29923046
onToggleWorkGroup,
@@ -3124,6 +3178,7 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
31243178
keyExtractor={(entry) => entry.id}
31253179
getItemType={(entry) => {
31263180
if (entry.type !== "message") return entry.type;
3181+
if (isCompactionCommandFeedEntry(entry)) return "message:compaction";
31273182
const { attribution } = resolveUserMessagePresentation(entry.message);
31283183
return attribution === "automation" || attribution === "agent"
31293184
? `message:${attribution}`

‎apps/mobile/src/features/threads/pending-thread-feed.test.ts‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
ThreadId,
99
} from "@t3tools/contracts";
1010
import type { QueuedThreadMessage } from "../../state/thread-outbox-model";
11-
import { appendPendingThreadMessages } from "./pending-thread-feed";
11+
import { appendPendingThreadMessages, isCompactionCommandFeedEntry } from "./pending-thread-feed";
1212

1313
const pending = (id: string): QueuedThreadMessage => ({
1414
environmentId: EnvironmentId.make("env"),
@@ -21,6 +21,35 @@ const pending = (id: string): QueuedThreadMessage => ({
2121
});
2222

2323
describe("pending timeline messages", () => {
24+
it.each([false, true])(
25+
"keeps a queued compact command in the pending message row (attachment: %s)",
26+
(withAttachment) => {
27+
const queued = {
28+
...pending("compact"),
29+
text: "/compact",
30+
attachments: withAttachment
31+
? [
32+
{
33+
id: "image-1",
34+
type: "image" as const,
35+
name: "photo.png",
36+
mimeType: "image/png",
37+
sizeBytes: 3,
38+
fileUri: "file:///documents/photo.png",
39+
previewUri: "file:///documents/photo.png",
40+
},
41+
]
42+
: [],
43+
};
44+
const entry = appendPendingThreadMessages([], [], [queued])[0]!;
45+
expect(isCompactionCommandFeedEntry(entry)).toBe(false);
46+
expect(entry.pendingMessage).toEqual(queued);
47+
if (!withAttachment) {
48+
expect(isCompactionCommandFeedEntry({ ...entry, pendingMessage: undefined })).toBe(true);
49+
}
50+
},
51+
);
52+
2453
it("marks the synthetic creation prompt pending without duplicating it", () => {
2554
const queued = {
2655
...pending("creation"),

‎apps/mobile/src/features/threads/pending-thread-feed.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isCompactionCommandMessage } from "@t3tools/contracts";
12
import type { ThreadFeedEntry } from "../../lib/threadActivity";
23
import type { QueuedThreadMessage } from "../../state/thread-outbox-model";
34

@@ -45,3 +46,11 @@ export function appendPendingThreadMessages(
4546
})),
4647
];
4748
}
49+
50+
export function isCompactionCommandFeedEntry(entry: PendingThreadFeedEntry): boolean {
51+
return (
52+
entry.type === "message" &&
53+
entry.pendingMessage === undefined &&
54+
isCompactionCommandMessage(entry.message)
55+
);
56+
}

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

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { describe, expect, it } from "vite-plus/test";
2424

2525
import {
2626
buildThreadFeed,
27+
threadFeedCompactionLabels,
2728
createThreadFeedCache,
2829
deriveThreadFeedPresentation,
2930
messageFoldRunId,
@@ -76,6 +77,144 @@ it("keeps historical plan detail accessible from its paged turn item", () => {
7677
expect(presented[2]).toMatchObject({ activities: [{ projectedItem: { item } }] });
7778
});
7879

80+
it("shows a compact command as one mobile divider before, during, and after compaction", () => {
81+
const startedAt = "2026-06-20T00:00:01.000Z";
82+
const prompt = projected({ ...userMessage(), text: "/compact", idleCompaction: "onReturn" }, 0);
83+
const latestRun = { runId, status: "running" as const, startedAt, completedAt: null };
84+
const present = (items: OrchestrationV2ProjectedTurnItem[]) =>
85+
deriveThreadFeedPresentation(
86+
buildThreadFeed(items),
87+
latestRun,
88+
new Set(),
89+
new Set(),
90+
startedAt,
91+
);
92+
93+
const waiting = present([prompt]);
94+
expect(waiting.map((entry) => entry.type)).toEqual(["message"]);
95+
expect(waiting[0]?.type === "message" ? waiting[0].message.idleCompaction : null).toBe(
96+
"onReturn",
97+
);
98+
for (const status of ["running", "completed", "failed"] as const) {
99+
const compaction = projected(
100+
{
101+
...base("compaction", "2026-06-20T00:00:02.000Z", 1),
102+
type: "compaction",
103+
driver: ProviderDriverKind.make("claude"),
104+
status,
105+
beforeTokenCount: 100_000,
106+
...(status === "completed" ? { afterTokenCount: 20_000 } : {}),
107+
...(status === "failed" ? { summary: "Not enough messages to compact." } : {}),
108+
},
109+
1,
110+
);
111+
const rows = present([prompt, compaction]);
112+
expect(rows.map((entry) => entry.type)).toEqual(["activity-group"]);
113+
expect(
114+
rows[0]?.type === "activity-group" ? rows[0].activities[0]?.projectedItem.item : null,
115+
).toMatchObject({ type: "compaction", status });
116+
}
117+
});
118+
119+
it.each(["/compact", "Continue"])(
120+
"keeps a completed compaction divider visible while other settled work folds for %s",
121+
(promptText) => {
122+
const rows = deriveThreadFeedPresentation(
123+
buildThreadFeed([
124+
projected({ ...userMessage(), text: promptText }, 0),
125+
projected(command(), 1),
126+
projected(
127+
{
128+
...base("compaction", "2026-06-20T00:00:03.000Z", 2),
129+
type: "compaction",
130+
driver: ProviderDriverKind.make("claude"),
131+
status: "completed",
132+
beforeTokenCount: 100_000,
133+
afterTokenCount: 20_000,
134+
},
135+
2,
136+
),
137+
]),
138+
{
139+
runId,
140+
status: "completed",
141+
startedAt: "2026-06-20T00:00:01.000Z",
142+
completedAt: "2026-06-20T00:00:03.000Z",
143+
},
144+
new Set(),
145+
);
146+
expect(rows.filter((entry) => entry.type === "run-fold")).toHaveLength(1);
147+
const activities = rows.flatMap((entry) =>
148+
entry.type === "activity-group" ? entry.activities : [],
149+
);
150+
expect(activities.map((activity) => activity.projectedItem.item)).toMatchObject([
151+
{
152+
type: "compaction",
153+
status: "completed",
154+
beforeTokenCount: 100_000,
155+
afterTokenCount: 20_000,
156+
},
157+
]);
158+
if (promptText === "/compact") {
159+
expect(rows.some((entry) => entry.type === "message")).toBe(false);
160+
}
161+
},
162+
);
163+
164+
it("binds a persisted resume answer only to the next compaction in its run", () => {
165+
const requestId = RuntimeRequestId.make("resume-compaction");
166+
const question = projected(
167+
{
168+
...base("resume-question", "2026-06-20T00:00:02.000Z", 1),
169+
type: "user_input_request",
170+
requestId,
171+
questions: [],
172+
questionAnswer: {
173+
requestId,
174+
questionTextById: {
175+
resume:
176+
"This session is 2h 10m old and uses 200,000 tokens. Compact it before continuing?",
177+
},
178+
answers: { resume: "Compact and continue" },
179+
attachmentsByQuestionId: {},
180+
},
181+
},
182+
1,
183+
);
184+
const compaction = (id: string, position: number, status: "running" | "completed") =>
185+
projected(
186+
{
187+
...base(id, `2026-06-20T00:00:0${position + 1}.000Z`, position),
188+
type: "compaction",
189+
driver: ProviderDriverKind.make("claude"),
190+
status,
191+
beforeTokenCount: 200_000,
192+
},
193+
position,
194+
);
195+
for (const status of ["running", "completed"] as const) {
196+
// Rebuild from persisted items, without a live question or prior feed cache.
197+
const feed = buildThreadFeed([
198+
projected(userMessage(), 0),
199+
question,
200+
compaction("resume-compact", 2, "completed"),
201+
compaction("auto-compact", 3, status),
202+
]);
203+
const labels = threadFeedCompactionLabels(feed);
204+
const compactRows = feed.filter(
205+
(entry) =>
206+
entry.type === "activity-group" &&
207+
entry.activities[0]?.projectedItem.item.type === "compaction",
208+
);
209+
expect(compactRows).toHaveLength(2);
210+
expect(labels.get(compactRows[0]!.id)).toEqual({
211+
title: "Context compacted after 2h 10m idle",
212+
compacting: "Compacting after 2h 10m idle…",
213+
});
214+
expect(labels.get(compactRows[1]!.id)).toBeUndefined();
215+
}
216+
});
217+
79218
function base(id: string, updatedAt: string, ordinal: number) {
80219
const timestamp = DateTime.makeUnsafe(updatedAt);
81220
return {

0 commit comments

Comments
 (0)