The best way to control Claude Code, Codex and more from any computer or phone
fix(mobile): don't send or paste attached threads a machine can't read (#18322)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Nikita Maximilian Grimm committed
Oct 20, 2026 at 07:37 UTC
2777514fc8f22192fe6919c00e7dc7e401e4de02
5 files changed
+210
-6
apps/mobile/src/components/ComposerEditor.tsx
+12
-2
@@ -97,6 +97,7 @@ export function ComposerEditor({
97
retained.attachments.length,
98
controller.signal,
99
retained.context?.records.length ?? 0,
100
+ environmentId,
101
);
102
if (!result) {
103
insertComposerDraftText(draftKey, clipboard.text, insertion);
@@ -109,10 +110,19 @@ export function ComposerEditor({
110
);
111
return;
112
}
113
+ const warnings: string[] = [];
114
if (result.failures.length > 0)
115
+ warnings.push(
116
+ "Some attachments could not be copied. Reconnect to the source environment and copy them again.",
117
+ );
118
+ if (result.skippedThreads.length > 0)
119
+ warnings.push(
120
+ `${result.skippedThreads.map((title) => `"${title}"`).join(", ")} ${result.skippedThreads.length === 1 ? "is" : "are"} on another machine.`,
121
+ );
122
+ if (warnings.length > 0)
123
Dialog.alert(
114
- "Some attachments could not be copied",
115
- "Reconnect to the source environment and copy them again. References without their files are marked unavailable.",
124
+ "Some context is unavailable",
125
+ [...warnings, "Those references are marked unavailable."].join("\n\n"),
126
);
127
});
128
setComposerContextImporting(draftKey, false);
apps/mobile/src/features/threads/NewTaskDraftScreen.tsx
+17
@@ -71,6 +71,7 @@ import { ProviderIcon } from "../../components/ProviderIcon";
71
import { SymbolView } from "../../components/ui/AppSymbol";
72
import { AppText as Text } from "../../components/ui/AppText";
73
import { hasProviderUsageLimits, isUsageLimitsCommand } from "@t3tools/shared/usageLimits";
74
+import { threadContextsOutsideEnvironment } from "@t3tools/shared/composerContextReferences";
75
import { COMPOSER_LAYOUT_TRANSITION, ComposerSurface } from "./ThreadComposer";
76
import { ComposerCommandPopover } from "./ComposerCommandPopover";
77
import { useComposerCommandMenu } from "./use-composer-command-menu";
@@ -1248,6 +1249,22 @@ export function NewTaskDraftScreen(props: {
1249
Dialog.alert("Too much context", contextBlockReason);
1250
return;
1251
}
1252
+ const strandedThread = threadContextsOutsideEnvironment({
1253
+ text: draft.text,
1254
+ records: draft.context?.records ?? [],
1255
+ environmentId: selectedProject.environmentId,
1256
+ })[0];
1257
+ if (strandedThread) {
1258
+ const owner =
1259
+ flow.environments.find(
1260
+ (environment) => environment.environmentId === strandedThread.environmentId,
1261
+ )?.environmentLabel ?? "its machine";
1262
+ Dialog.alert(
1263
+ "Attached thread unavailable",
1264
+ `"${strandedThread.title}" is on another machine. Switch back to ${owner} or remove it from the draft.`,
1265
+ );
1266
+ return;
1267
+ }
1268
1269
const editingPendingTask = flow.editingPendingTask;
1270
apps/mobile/src/features/threads/new-task-flow-provider.tsx
+10
@@ -24,6 +24,7 @@ import {
24
ThreadId,
25
} from "@t3tools/contracts";
26
import { sanitizeNewRefName } from "@t3tools/shared/git";
27
+import { threadContextsOutsideEnvironment } from "@t3tools/shared/composerContextReferences";
28
import { resolveNewThreadEnvMode, resolveProjectSettings } from "@t3tools/shared/projectSettings";
29
import { parseT3ProjectFile } from "@t3tools/shared/t3ProjectFile";
30
import * as Arr from "effect/Array";
@@ -961,6 +962,15 @@ export function NewTaskFlowProvider(props: React.PropsWithChildren) {
962
if ((text.length === 0 && draft.attachments.length === 0) || !draftModelSelection) {
963
return null;
964
}
965
+ if (
966
+ threadContextsOutsideEnvironment({
967
+ text: draft.text,
968
+ records: draft.context?.records ?? [],
969
+ environmentId: selectedProject.environmentId,
970
+ }).length > 0
971
+ ) {
972
+ return null;
973
+ }
974
const workspaceSelection = canChooseWorkspace ? draft.workspaceSelection : undefined;
975
const mode = workspaceSelection?.mode ?? workspaceMode;
976
// When the selection is the stand-in built from the queued snapshot,
apps/mobile/src/lib/composerContextClipboard.test.ts
+155
-1
@@ -1,6 +1,15 @@
1
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
2
-import { ComposerContextId, EnvironmentId } from "@t3tools/contracts";
2
+import {
3
+ COMPOSER_CONTEXT_MAX_RECORDS,
4
+ ComposerContextId,
5
+ EnvironmentId,
6
+ ThreadId,
7
+} from "@t3tools/contracts";
8
import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard";
9
+import {
10
+ collectComposerContextReferences,
11
+ formatComposerContextReference,
12
+} from "@t3tools/shared/composerContextReferences";
13
14
const mocks = vi.hoisted(() => ({
15
execute: vi.fn(),
@@ -44,6 +53,7 @@ vi.mock("./composerImages", () => ({
53
vi.mock("./uuid", () => ({ uuidv4: () => `import-${++mocks.sequence}` }));
54
55
import { importComposerContextClipboard } from "./composerContextClipboard";
56
+import { createComposerContextHistory } from "./composerContext";
57
58
const image = {
59
version: 1 as const,
@@ -76,6 +86,42 @@ const clipboard = {
86
html: "",
87
};
88
89
+const localThread = {
90
+ version: 1 as const,
91
+ kind: "thread" as const,
92
+ contextId: ComposerContextId.make("thread_local-thread"),
93
+ label: "Local discussion",
94
+ environmentId: EnvironmentId.make("destination"),
95
+ threadId: ThreadId.make("local-thread"),
96
+ title: "Local discussion",
97
+};
98
+const foreignThread = {
99
+ ...localThread,
100
+ contextId: ComposerContextId.make("thread_foreign-thread"),
101
+ label: "Remote discussion",
102
+ environmentId: EnvironmentId.make("source"),
103
+ threadId: ThreadId.make("foreign-thread"),
104
+ title: "Remote discussion",
105
+};
106
+const mixedRecords = [foreignThread, localThread, terminal, image];
107
+const mixedClipboard = {
108
+ text: `Compare these findings: ${mixedRecords.map(formatComposerContextReference).join(" ")} before changing anything.`,
109
+ fragment: encodeComposerContextFragment({
110
+ version: 1,
111
+ source: { environmentId: EnvironmentId.make("source") },
112
+ records: [
113
+ ...mixedRecords,
114
+ {
115
+ ...foreignThread,
116
+ contextId: ComposerContextId.make("thread_uncopied-thread"),
117
+ threadId: ThreadId.make("uncopied-thread"),
118
+ title: "Not in the copied selection",
119
+ },
120
+ ],
121
+ })!,
122
+ html: "",
123
+};
124
+
125
beforeEach(() => {
126
vi.clearAllMocks();
127
mocks.sequence = 0;
@@ -142,6 +188,114 @@ describe("mobile context clipboard imports", () => {
188
expect(mocks.download).not.toHaveBeenCalled();
189
});
190
191
+ it("pastes local threads, text context and files at the cap after excluding foreign threads", async () => {
192
+ const result = await importComposerContextClipboard(
193
+ mixedClipboard,
194
+ 0,
195
+ new AbortController().signal,
196
+ COMPOSER_CONTEXT_MAX_RECORDS - 3,
197
+ EnvironmentId.make("destination"),
198
+ );
199
+ expect(result).not.toBeNull();
200
+ expect(result!.context.records).toEqual([
201
+ { ...localThread, contextId: expect.any(String) },
202
+ { ...terminal, contextId: expect.any(String) },
203
+ { ...image, contextId: expect.any(String), attachmentId: result!.attachments[0]!.id },
204
+ ]);
205
+ expect(result!.attachments).toEqual([
206
+ expect.objectContaining({ name: image.name, fileUri: "file:///owned.png" }),
207
+ ]);
208
+ expect(result!.failures).toEqual([]);
209
+ expect(result!.skippedThreads).toEqual([foreignThread.title]);
210
+ const references = collectComposerContextReferences(result!.text);
211
+ expect(references.map((reference) => reference.label)).toEqual(
212
+ mixedRecords.map((record) => record.label),
213
+ );
214
+ expect(result!.context.records.map((record) => record.contextId)).toEqual(
215
+ references.slice(1).map((reference) => reference.contextId),
216
+ );
217
+ expect(
218
+ references.every(
219
+ (reference) => !mixedRecords.some((record) => record.contextId === reference.contextId),
220
+ ),
221
+ ).toBe(true);
222
+ expect(
223
+ result!.context.records.some((record) => record.contextId === references[0]!.contextId),
224
+ ).toBe(false);
225
+ expect(result!.text).toMatch(/^Compare these findings: .* before changing anything\.$/);
226
+
227
+ const restoreHistory = createComposerContextHistory();
228
+ restoreHistory(formatComposerContextReference(foreignThread), {
229
+ version: 1,
230
+ records: [foreignThread],
231
+ });
232
+ expect(restoreHistory(`${result!.text} Next step`, result!.context)).toEqual(result!.context);
233
+
234
+ mocks.download.mockClear();
235
+ await expect(
236
+ importComposerContextClipboard(
237
+ mixedClipboard,
238
+ 0,
239
+ new AbortController().signal,
240
+ COMPOSER_CONTEXT_MAX_RECORDS - 2,
241
+ EnvironmentId.make("destination"),
242
+ ),
243
+ ).rejects.toThrow("Remove some context");
244
+ expect(mocks.download).not.toHaveBeenCalled();
245
+ });
246
+
247
+ it("reports foreign threads and failed files together while keeping the rest of a paste", async () => {
248
+ mocks.download.mockRejectedValueOnce(new Error("source disconnected"));
249
+ const result = await importComposerContextClipboard(
250
+ mixedClipboard,
251
+ 0,
252
+ new AbortController().signal,
253
+ 0,
254
+ EnvironmentId.make("destination"),
255
+ );
256
+ expect(result).not.toBeNull();
257
+ expect(result!.context.records).toEqual([
258
+ { ...localThread, contextId: expect.any(String) },
259
+ { ...terminal, contextId: expect.any(String) },
260
+ ]);
261
+ expect(result!.attachments).toEqual([]);
262
+ expect(result!.failures).toEqual([image.name]);
263
+ expect(result!.skippedThreads).toEqual([foreignThread.title]);
264
+ const references = collectComposerContextReferences(result!.text);
265
+ expect(references.map((reference) => reference.label)).toEqual(
266
+ mixedRecords.map((record) => record.label),
267
+ );
268
+ expect(
269
+ references
270
+ .filter(
271
+ (reference) =>
272
+ !result!.context.records.some((record) => record.contextId === reference.contextId),
273
+ )
274
+ .map((reference) => reference.label),
275
+ ).toEqual([foreignThread.label, image.label]);
276
+ expect(result!.text).toMatch(/^Compare these findings: .* before changing anything\.$/);
277
+ });
278
+
279
+ it("preserves both machines' thread references when pasting without a destination", async () => {
280
+ const result = await importComposerContextClipboard(
281
+ mixedClipboard,
282
+ 0,
283
+ new AbortController().signal,
284
+ );
285
+ expect(result).not.toBeNull();
286
+ expect(result!.context.records).toEqual([
287
+ { ...foreignThread, contextId: expect.any(String) },
288
+ { ...localThread, contextId: expect.any(String) },
289
+ { ...terminal, contextId: expect.any(String) },
290
+ { ...image, contextId: expect.any(String), attachmentId: result!.attachments[0]!.id },
291
+ ]);
292
+ expect(result!.attachments).toHaveLength(1);
293
+ expect(result!.failures).toEqual([]);
294
+ expect(
295
+ collectComposerContextReferences(result!.text).map((reference) => reference.contextId),
296
+ ).toEqual(result!.context.records.map((record) => record.contextId));
297
+ });
298
+
299
it("refuses an overflowing context paste before copying files", async () => {
300
await expect(
301
importComposerContextClipboard(clipboard, 0, new AbortController().signal, 200),
apps/mobile/src/lib/composerContextClipboard.ts
+16
-3
@@ -13,6 +13,7 @@ import {
13
decodeComposerContextFragment,
14
encodeComposerContextFragment,
15
} from "@t3tools/shared/composerContextClipboard";
16
+import { threadContextsOutsideEnvironment } from "@t3tools/shared/composerContextReferences";
17
import { executeAtomQuery, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
18
import { resolveAssetUrl } from "@t3tools/client-runtime/state/assets";
19
import * as Option from "effect/Option";
@@ -65,19 +66,30 @@ export async function importComposerContextClipboard(
66
existingCount: number,
67
signal: AbortSignal,
68
existingContextCount = 0,
69
+ destinationEnvironmentId?: EnvironmentId,
70
) {
71
const fragment =
72
decodeComposerContextFragment(input.fragment) ?? decodeComposerContextClipboardHtml(input.html);
73
if (!fragment) return null;
74
const selected = referencedComposerContext(input.text, { version: 1, records: fragment.records });
73
- if (existingContextCount + (selected?.records.length ?? 0) > COMPOSER_CONTEXT_MAX_RECORDS)
74
- throw new Error("Remove some context items from the draft before pasting more.");
75
const imported = reidentifyComposerContext(input.text, selected?.records ?? [], uuidv4);
76
+ const skippedThreads =
77
+ destinationEnvironmentId === undefined
78
+ ? []
79
+ : threadContextsOutsideEnvironment({
80
+ text: imported.text,
81
+ records: imported.context.records,
82
+ environmentId: destinationEnvironmentId,
83
+ });
84
+ const skippedIds = new Set(skippedThreads.map((record) => record.contextId));
85
+ const retained = imported.context.records.filter((record) => !skippedIds.has(record.contextId));
86
+ if (existingContextCount + retained.length > COMPOSER_CONTEXT_MAX_RECORDS)
87
+ throw new Error("Remove some context items from the draft before pasting more.");
88
const attachments: DraftComposerAttachment[] = [];
89
const records: ComposerContextRecord[] = [];
90
const failures: string[] = [];
91
try {
80
- for (const record of imported.context.records) {
92
+ for (const record of retained) {
93
checkAborted(signal);
94
if (!("attachmentId" in record)) {
95
records.push(record);
@@ -99,6 +111,7 @@ export async function importComposerContextClipboard(
111
context: { version: 1 as const, records },
112
attachments,
113
failures,
114
+ skippedThreads: skippedThreads.map((record) => record.title),
115
};
116
} catch (error) {
117
await Promise.all(