The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 13:00 UTC
fix(mobile): agent-spawned threads can be mentioned from the @ picker (#15841)
Co-authored-by: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Lars Nieuwenhuis committed
Oct 15, 2026 at 19:01 UTC
38d9760ccaeadfba345f0bab160086e88f625518
11 files changed
+104
-80
apps/mobile/src/lib/composerContext.test.ts
+20
@@ -4,6 +4,8 @@ import {
4
ProjectId,
5
ProviderInstanceId,
6
ComposerContextId,
7
+ EnvironmentId,
8
+ ThreadId,
9
type OrchestrationMessageContext,
10
} from "@t3tools/contracts";
11
import { collectComposerInlineTokens } from "@t3tools/shared/composerInlineTokens";
@@ -24,6 +26,7 @@ import {
26
uploadedComposerContext,
27
serializeComposerMessageForServer,
28
pullRequestComposerContext,
29
+ threadComposerContext,
30
} from "./composerContext";
31
32
const terminal = {
@@ -318,3 +321,20 @@ describe("host context compatibility", () => {
321
expect(context.records).toEqual([terminal, review, pr]);
322
});
323
});
324
+
325
+describe("threadComposerContext", () => {
326
+ it("mints a schema-valid, stable id for agent-spawned thread ids", () => {
327
+ const environmentId = EnvironmentId.make("env-1");
328
+ const ref = {
329
+ environmentId,
330
+ threadId: ThreadId.make(`thread:mcp:${encodeURIComponent("3f2b:delegate")}:review:0`),
331
+ };
332
+ const contextId = threadComposerContext(ref, "Review").contextId;
333
+
334
+ expect(() => ComposerContextId.make(contextId)).not.toThrow();
335
+ expect(threadComposerContext(ref, "Renamed").contextId).toBe(contextId);
336
+ expect(
337
+ threadComposerContext({ environmentId, threadId: ThreadId.make("abc-123") }, "t").contextId,
338
+ ).toBe("thread_abc-123");
339
+ });
340
+});
apps/mobile/src/lib/composerContext.ts
+2
-1
@@ -20,6 +20,7 @@ import {
20
isImageReferencesOnly,
21
replaceComposerContextReferences,
22
sanitizeComposerContextLabel,
23
+ toKindScopedComposerContextId,
24
} from "@t3tools/shared/composerContextReferences";
25
import {
26
collectComposerInlineTokens,
@@ -110,7 +111,7 @@ export function threadComposerContext(ref: ScopedThreadRef, title: string): Thre
111
return {
112
version: 1,
113
kind: "thread",
113
- contextId: ComposerContextId.make(`thread_${ref.threadId}`),
114
+ contextId: toKindScopedComposerContextId("thread", ref.threadId),
115
label,
116
environmentId: ref.environmentId,
117
threadId: ref.threadId,
apps/web/src/components/chat/ChatComposer.tsx
+4
-2
@@ -199,7 +199,10 @@ import {
199
type TerminalContextSelection,
200
} from "../../lib/terminalContext";
201
import { useComposerPathSearch } from "../../lib/composerPathSearchState";
202
-import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
202
+import {
203
+ replaceComposerContextReferences,
204
+ toKindScopedComposerContextId,
205
+} from "@t3tools/shared/composerContextReferences";
206
import {
207
getRestingComposerImagePreviewCounts,
208
resolveRestingComposerControlsLayout,
@@ -228,7 +231,6 @@ import {
231
formatInlineContextReference,
232
insertInlineContextReference,
233
inlineContextReferenceReplacement,
231
- toKindScopedComposerContextId,
234
} from "~/lib/composerContextReferences";
235
import {
236
asKnownContextRecord,
apps/web/src/composerDraftStore.ts
+5
-3
@@ -60,8 +60,6 @@ import {
60
ensureInlineContextReferences,
61
formatInlineContextReference,
62
removeInlineContextReference,
63
- toComposerContextId,
64
- toKindScopedComposerContextId,
63
} from "./lib/composerContextReferences";
64
import {
65
fileContextReference,
@@ -77,7 +75,11 @@ import { persist, type PersistStorage, type StorageValue } from "zustand/middlew
75
import { useShallow } from "zustand/react/shallow";
76
import { createDeferredStorage, createMemoryStorage } from "./lib/storage";
77
import { getDefaultServerModel } from "./providerModels";
80
-import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
78
+import {
79
+ replaceComposerContextReferences,
80
+ toComposerContextId,
81
+ toKindScopedComposerContextId,
82
+} from "@t3tools/shared/composerContextReferences";
83
import { UnifiedSettings } from "@t3tools/contracts/settings";
84
import { ReviewCommentContextSchema, type ReviewCommentContext } from "./reviewCommentContext";
85
const isRuntimeMode = Schema.is(RuntimeMode);
apps/web/src/lib/composerContextRecords.ts
+1
-1
@@ -24,12 +24,12 @@ import { encodeComposerContextFragment } from "@t3tools/shared/composerContextCl
24
import {
25
collectComposerContextReferences,
26
sanitizeComposerContextLabel,
27
+ toKindScopedComposerContextId,
28
} from "@t3tools/shared/composerContextReferences";
29
30
import {
31
type ComposerContextReference,
32
producerIdFromComposerContextId,
32
- toKindScopedComposerContextId,
33
} from "./composerContextReferences";
34
import type { ComposerFileAttachment, ComposerImageAttachment } from "~/composerDraftStore";
35
import type { AttachmentUploadState } from "./attachmentUploadState";
apps/web/src/lib/composerContextReferences.test.ts
-26
@@ -9,8 +9,6 @@ import {
9
inlineContextReferenceReplacement,
10
removeInlineContextReference,
11
stripInlineContextReferences,
12
- toComposerContextId,
13
- toKindScopedComposerContextId,
12
} from "./composerContextReferences";
13
14
const review = { kind: "review-comment", contextId: "rc-1", label: "a.ts L4" };
@@ -63,27 +61,3 @@ describe("composerContextReferences", () => {
61
expect(ensureInlineContextReferences(reviewLink, [review])).toBe(reviewLink);
62
});
63
});
66
-
67
-describe("toComposerContextId", () => {
68
- it("keeps same-kind raw IDs distinct when one contains the namespace prefix", () => {
69
- expect(toKindScopedComposerContextId("image", "x")).toBe("image_x");
70
- expect(toKindScopedComposerContextId("image", "image_x")).toBe("image_image_x");
71
- });
72
- it("keeps ids that already fit the grammar and folds the rest deterministically", () => {
73
- expect(toComposerContextId("file-comment-1700-1")).toBe("file-comment-1700-1");
74
- const folded = toComposerContextId("pull-request-selection:src/a.ts:4-9");
75
- expect(folded).toMatch(/^pull-request-selection-src-a-ts-4-9-[0-9a-f]{16}$/);
76
- expect(toComposerContextId("pull-request-selection:src/a.ts:4-9")).toBe(folded);
77
- expect(toComposerContextId("pull-request-selection:src/b.ts:4-9")).not.toBe(folded);
78
- expect(toComposerContextId("::")).toMatch(/^ctx-[0-9a-f]{16}$/);
79
- });
80
- it("tells apart producer ids that agree past the slug's truncation point", () => {
81
- // The slug keeps 48 characters, so only the digest distinguishes these two.
82
- const shared = `pull-request-finding:${"a".repeat(60)}`;
83
- const first = toComposerContextId(`${shared}:1`);
84
- const second = toComposerContextId(`${shared}:2`);
85
-
86
- expect(first).not.toBe(second);
87
- expect(first.length).toBeLessThanOrEqual(128);
88
- });
89
-});
apps/web/src/lib/composerContextReferences.ts
-43
@@ -17,49 +17,6 @@ export interface ComposerContextReference {
17
label: string;
18
}
19
20
-const CONTEXT_ID_PATTERN = /^[a-z0-9_-]{1,128}$/i;
21
-
22
-/**
23
- * Two independent FNV-1a passes, one forward and one with a different offset basis over the
24
- * reversed input. 64 bits of digest, because the slug in front of it is truncated: two long
25
- * producer ids that agree on their first 48 characters are told apart by this alone.
26
- */
27
-function fnv1a64(value: string): string {
28
- let forward = 0x811c9dc5;
29
- let reverse = 0x9dc5811c;
30
- for (let index = 0; index < value.length; index += 1) {
31
- forward ^= value.charCodeAt(index);
32
- forward = Math.imul(forward, 0x01000193) >>> 0;
33
- reverse ^= value.charCodeAt(value.length - 1 - index);
34
- reverse = Math.imul(reverse, 0x01000193) >>> 0;
35
- }
36
- return `${forward.toString(16).padStart(8, "0")}${reverse.toString(16).padStart(8, "0")}`;
37
-}
38
-
39
-/**
40
- * Producers mint ids in their own grammars (`pull-request-finding:42`,
41
- * `file-comment-<ms>-<n>`). A context id must survive a Markdown link and the wire
42
- * schema, so anything outside `[a-z0-9_-]` is folded into a readable slug plus a hash of
43
- * the original. Deterministic, so the same producer id always maps to the same context id.
44
- */
45
-export function toComposerContextId(producerId: string): ComposerContextId {
46
- if (CONTEXT_ID_PATTERN.test(producerId)) return producerId as ComposerContextId;
47
- const slug = producerId
48
- .replace(/[^a-z0-9_-]+/gi, "-")
49
- .replace(/^-+|-+$/g, "")
50
- .slice(0, 48);
51
- return `${slug || "ctx"}-${fnv1a64(producerId)}` as ComposerContextId;
52
-}
53
-
54
-/** Raw producer IDs are always scoped, even when they already start with the kind name. */
55
-export function toKindScopedComposerContextId(
56
- kind: ComposerContextKind,
57
- producerId: string,
58
-): ComposerContextId {
59
- const prefix = `${kind}_`;
60
- return toComposerContextId(`${prefix}${producerId}`);
61
-}
62
-
20
/** Only for importing canonical records: undo one namespace before rebuilding a draft. */
21
export function producerIdFromComposerContextId(
22
kind: ComposerContextKind,
apps/web/src/lib/terminalContext.ts
+4
-2
@@ -1,6 +1,8 @@
1
import type { ThreadId } from "@t3tools/contracts";
2
-import { formatComposerContextReference } from "@t3tools/shared/composerContextReferences";
3
-import { toKindScopedComposerContextId } from "./composerContextReferences";
2
+import {
3
+ formatComposerContextReference,
4
+ toKindScopedComposerContextId,
5
+} from "@t3tools/shared/composerContextReferences";
6
7
export interface TerminalContextSelection {
8
terminalId: string;
apps/web/src/lib/threadContextAttachment.ts
+1
-2
@@ -1,9 +1,8 @@
1
import type { EnvironmentId, OrchestrationV2ThreadTranscript } from "@t3tools/contracts";
2
+import { toKindScopedComposerContextId } from "@t3tools/shared/composerContextReferences";
3
import { threadTranscriptHeader } from "@t3tools/shared/threadTranscript";
4
import * as DateTime from "effect/DateTime";
5
5
-import { toKindScopedComposerContextId } from "./composerContextReferences";
6
-
6
export function threadContextAttachment(
7
environmentId: EnvironmentId,
8
transcript: OrchestrationV2ThreadTranscript,
packages/shared/src/composerContextReferences.test.ts
+26
@@ -11,6 +11,8 @@ import {
11
projectComposerContextForProvider,
12
replaceComposerContextReferences,
13
sanitizeComposerContextLabel,
14
+ toComposerContextId,
15
+ toKindScopedComposerContextId,
16
} from "./composerContextReferences.ts";
17
18
const ctx = (value: string) => value as ComposerContextId;
@@ -298,3 +300,27 @@ describe("provider projection", () => {
300
expect(projected).not.toContain("boom");
301
});
302
});
303
+
304
+describe("toComposerContextId", () => {
305
+ it("keeps same-kind raw IDs distinct when one contains the namespace prefix", () => {
306
+ expect(toKindScopedComposerContextId("image", "x")).toBe("image_x");
307
+ expect(toKindScopedComposerContextId("image", "image_x")).toBe("image_image_x");
308
+ });
309
+ it("keeps ids that already fit the grammar and folds the rest deterministically", () => {
310
+ expect(toComposerContextId("file-comment-1700-1")).toBe("file-comment-1700-1");
311
+ const folded = toComposerContextId("pull-request-selection:src/a.ts:4-9");
312
+ expect(folded).toMatch(/^pull-request-selection-src-a-ts-4-9-[0-9a-f]{16}$/);
313
+ expect(toComposerContextId("pull-request-selection:src/a.ts:4-9")).toBe(folded);
314
+ expect(toComposerContextId("pull-request-selection:src/b.ts:4-9")).not.toBe(folded);
315
+ expect(toComposerContextId("::")).toMatch(/^ctx-[0-9a-f]{16}$/);
316
+ });
317
+ it("tells apart producer ids that agree past the slug's truncation point", () => {
318
+ // The slug keeps 48 characters, so only the digest distinguishes these two.
319
+ const shared = `pull-request-finding:${"a".repeat(60)}`;
320
+ const first = toComposerContextId(`${shared}:1`);
321
+ const second = toComposerContextId(`${shared}:2`);
322
+
323
+ expect(first).not.toBe(second);
324
+ expect(first.length).toBeLessThanOrEqual(128);
325
+ });
326
+});
packages/shared/src/composerContextReferences.ts
+41
@@ -23,6 +23,47 @@ const CONTEXT_LINK = new RegExp(
23
"g",
24
);
25
26
+/**
27
+ * Two independent FNV-1a passes, one forward and one with a different offset basis over the
28
+ * reversed input. 64 bits of digest, because the slug in front of it is truncated: two long
29
+ * producer ids that agree on their first 48 characters are told apart by this alone.
30
+ */
31
+function fnv1a64(value: string): string {
32
+ let forward = 0x811c9dc5;
33
+ let reverse = 0x9dc5811c;
34
+ for (let index = 0; index < value.length; index += 1) {
35
+ forward ^= value.charCodeAt(index);
36
+ forward = Math.imul(forward, 0x01000193) >>> 0;
37
+ reverse ^= value.charCodeAt(value.length - 1 - index);
38
+ reverse = Math.imul(reverse, 0x01000193) >>> 0;
39
+ }
40
+ return `${forward.toString(16).padStart(8, "0")}${reverse.toString(16).padStart(8, "0")}`;
41
+}
42
+
43
+/**
44
+ * Producers mint ids in their own grammars (`pull-request-finding:42`,
45
+ * `file-comment-<ms>-<n>`). A context id must survive a Markdown link and the wire
46
+ * schema, so anything outside `[a-z0-9_-]` is folded into a readable slug plus a hash of
47
+ * the original. Deterministic, so the same producer id always maps to the same context id.
48
+ */
49
+export function toComposerContextId(producerId: string): ComposerContextId {
50
+ if (CONTEXT_ID_PATTERN.test(producerId)) return producerId as ComposerContextId;
51
+ const slug = producerId
52
+ .replace(/[^a-z0-9_-]+/gi, "-")
53
+ .replace(/^-+|-+$/g, "")
54
+ .slice(0, 48);
55
+ return `${slug || "ctx"}-${fnv1a64(producerId)}` as ComposerContextId;
56
+}
57
+
58
+/** Raw producer IDs are always scoped, even when they already start with the kind name. */
59
+export function toKindScopedComposerContextId(
60
+ kind: ComposerContextKind,
61
+ producerId: string,
62
+): ComposerContextId {
63
+ const prefix = `${kind}_`;
64
+ return toComposerContextId(`${prefix}${producerId}`);
65
+}
66
+
67
export function formatComposerContextHref(kind: ComposerContextKind, contextId: ComposerContextId) {
68
return `${COMPOSER_CONTEXT_HREF_PREFIX}${kind}/${contextId}`;
69
}