The best way to control Claude Code, Codex and more from any computer or phone
feat(web,mobile): Copy thread copies a chip that works on linked machines (#26202)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 27, 2026 at 18:39 UTC
0affd28db295b552e13017002af76d1efbfeb465
29 files changed
+262
-146
apps/mobile/modules/t3-native-controls/ios/T3KeyboardCommandsModule.swift
+1
-1
@@ -53,7 +53,7 @@ public final class T3KeyboardCommandsView: ExpoView {
53
input: "c",
54
modifiers: [.command, .shift],
55
action: #selector(copyThreadReference),
56
- title: "Copy PR Link or Thread ID"
56
+ title: "Copy PR Link or Thread"
57
),
58
enabledCommand("toggleSidebar", input: "\\", modifiers: .command, action: #selector(handleToggleSidebar), title: "Toggle Sidebar"),
59
enabledCommand("cycleHost", input: "h", modifiers: [.command, .shift], action: #selector(cycleHost), title: "Next Machine"),
apps/mobile/src/features/keyboard/CommandPalette.tsx
+1
-1
@@ -393,7 +393,7 @@ export function CommandPalette(props: {
393
["files", "Go to file", ["open", "files", "browse", "search"]],
394
["terminal", "Open terminal", ["shell", "console"]],
395
["review", "Review changes", ["diff", "git", "pull request"]],
396
- ["copyThreadReference", "Copy PR link or thread ID", ["reference", "clipboard"]],
396
+ ["copyThreadReference", "Copy PR link or thread", ["reference", "clipboard"]],
397
] as const;
398
actions.push(
399
...threadActions.map(([command, title, searchTerms]) => ({
apps/mobile/src/features/keyboard/HardwareKeyboardCommandProvider.tsx
+5
-6
@@ -14,7 +14,7 @@ import {
14
type ReactNode,
15
} from "react";
16
17
-import { tryCopyTextWithHaptic } from "../../lib/copyTextWithHaptic";
17
+import { copyThreadReference } from "../../lib/copyThreadReference";
18
import {
19
firstWorkspaceDetailOpen,
20
workspaceHasColumns,
@@ -62,7 +62,8 @@ export function HardwareKeyboardCommandProvider({
62
activeThreadRef === null
63
? null
64
: resolveThreadReferenceCopyTarget({
65
- threadId: activeThread?.id ?? activeThreadRef.threadId,
65
+ threadRef: activeThreadRef,
66
+ title: activeThread?.title ?? "",
67
pullRequests: activeThread?.pullRequests,
68
linkedPullRequestUrl:
69
(activeThread?.linkedPullRequest ?? activeThread?.branchPullRequest)?.url ?? null,
@@ -134,16 +135,14 @@ export function HardwareKeyboardCommandProvider({
135
if (command === "copyThreadReference") {
136
if (copyTarget === null) return;
137
const requestId = ++copyRequestIdRef.current;
137
- void tryCopyTextWithHaptic(copyTarget.value, {
138
- target: copyTarget.clipboardTarget,
139
- }).then((didCopy) => {
138
+ void copyThreadReference(copyTarget).then((didCopy) => {
139
if (requestId !== copyRequestIdRef.current) return;
140
showCopyFeedback(
141
didCopy
142
? {
143
phase: "success",
144
label: copyTarget.successTitle,
146
- description: copyTarget.value,
145
+ description: copyTarget.description,
146
}
147
: {
148
phase: "error",
apps/mobile/src/features/threads/thread-list-v2-items.tsx
+12
@@ -27,6 +27,7 @@ import {
27
} from "@t3tools/client-runtime/state/models";
28
import { AuthOrchestrationOperateScope, type EnvironmentMachineKind } from "@t3tools/contracts";
29
import { canSnooze } from "@t3tools/client-runtime/state/thread-settled";
30
+import { threadChipCopyTarget } from "@t3tools/client-runtime/thread-reference";
31
import type { MenuAction } from "@react-native-menu/menu";
32
import { memo, useCallback, useMemo, useState, type ComponentProps } from "react";
33
import { Pressable, useWindowDimensions, View } from "react-native";
@@ -42,6 +43,7 @@ import { ProviderIcon, ProviderInstanceIcon } from "../../components/ProviderIco
43
import { useNowAfter } from "../../lib/clock";
44
import { cn } from "../../lib/cn";
45
import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
46
+import { copyThreadReference } from "../../lib/copyThreadReference";
47
import { useUniwindTheme } from "../../lib/useUniwindTheme";
48
import { useEnvironmentScope } from "../../state/session";
49
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
@@ -918,6 +920,15 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
920
if (nativeEvent.event === "archive") handleArchive();
921
if (nativeEvent.event === "rename") handleRename();
922
if (nativeEvent.event === "regenerate-title") handleRegenerateTitle();
923
+ if (nativeEvent.event === "copy-thread") {
924
+ const target = threadChipCopyTarget(
925
+ { environmentId: thread.environmentId, threadId: thread.id },
926
+ thread.title,
927
+ );
928
+ void copyThreadReference(target).then((didCopy) => {
929
+ if (!didCopy) Dialog.alert(target.failureTitle, "Try copying this thread again.");
930
+ });
931
+ }
932
if (nativeEvent.event === "copy-thread-id") {
933
copyTextWithHaptic(thread.id, { target: "thread-id" });
934
}
@@ -1406,6 +1417,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
1417
},
1418
]
1419
: []),
1420
+ { id: "copy-thread", title: "Copy thread", image: "text.bubble" },
1421
{ id: "copy-thread-id", title: "Copy thread ID", image: "doc.on.doc" },
1422
...(snoozedRow
1423
? snoozedMenuActions
apps/mobile/src/features/threads/use-composer-command-menu.ts
+5
-6
@@ -18,12 +18,11 @@ const EMPTY_THREAD_SHELLS: ReadonlyArray<EnvironmentThreadShell> = [];
18
const EMPTY_ENVIRONMENTS: ReadonlyArray<ComposerEnvironmentCandidate> = [];
19
const NO_LINKED_ENVIRONMENTS: ReadonlyMap<EnvironmentId, string> = new Map();
20
import { COMPOSER_CONTEXT_MAX_RECORDS } from "@t3tools/contracts";
21
-import { formatComposerContextReference } from "@t3tools/shared/composerContextReferences";
21
import {
23
- environmentComposerContext,
24
- pullRequestComposerContext,
25
- threadComposerContext,
26
-} from "../../lib/composerContext";
22
+ formatComposerContextReference,
23
+ threadContextRecord,
24
+} from "@t3tools/shared/composerContextReferences";
25
+import { environmentComposerContext, pullRequestComposerContext } from "../../lib/composerContext";
26
import { uuidv4 } from "../../lib/uuid";
27
import {
28
getComposerDraftSnapshot,
@@ -528,7 +527,7 @@ export function useComposerCommandMenu({
527
candidate.id === item.thread.threadId,
528
);
529
if (!shell) return;
531
- const record = threadComposerContext(item.thread, shell.title);
530
+ const record = threadContextRecord(item.thread, shell.title);
531
const existing = getComposerDraftSnapshot(ownerKey).context?.records ?? [];
532
const alreadyAttached = existing.some((entry) => entry.contextId === record.contextId);
533
if (!alreadyAttached && existing.length >= COMPOSER_CONTEXT_MAX_RECORDS) {
apps/mobile/src/lib/composerContext.test.ts
-20
@@ -4,8 +4,6 @@ import {
4
ProjectId,
5
ProviderInstanceId,
6
ComposerContextId,
7
- EnvironmentId,
8
- ThreadId,
7
type OrchestrationMessageContext,
8
type ServerProviderSkill,
9
} from "@t3tools/contracts";
@@ -28,7 +26,6 @@ import {
26
uploadedComposerContext,
27
serializeComposerMessageForServer,
28
pullRequestComposerContext,
31
- threadComposerContext,
29
} from "./composerContext";
30
31
const terminal = {
@@ -397,20 +394,3 @@ describe("host context compatibility", () => {
394
expect(context.records).toEqual([terminal, review, pr]);
395
});
396
});
400
-
401
-describe("threadComposerContext", () => {
402
- it("mints a schema-valid, stable id for agent-spawned thread ids", () => {
403
- const environmentId = EnvironmentId.make("env-1");
404
- const ref = {
405
- environmentId,
406
- threadId: ThreadId.make(`thread:mcp:${encodeURIComponent("3f2b:delegate")}:review:0`),
407
- };
408
- const contextId = threadComposerContext(ref, "Review").contextId;
409
-
410
- expect(() => ComposerContextId.make(contextId)).not.toThrow();
411
- expect(threadComposerContext(ref, "Renamed").contextId).toBe(contextId);
412
- expect(
413
- threadComposerContext({ environmentId, threadId: ThreadId.make("abc-123") }, "t").contextId,
414
- ).toBe("thread_abc-123");
415
- });
416
-});
apps/mobile/src/lib/composerContext.ts
-17
@@ -11,9 +11,7 @@ import {
11
OrchestrationMessageContext,
12
type PullRequestContextMetadata,
13
type ReviewCommentContextRecord,
14
- type ScopedThreadRef,
14
type ServerProviderSkill,
16
- type ThreadContextRecord,
15
type EnvironmentContextRecord,
16
type EnvironmentId,
17
} from "@t3tools/contracts";
@@ -25,7 +23,6 @@ import {
23
isImageReferencesOnly,
24
replaceComposerContextReferences,
25
sanitizeComposerContextLabel,
28
- toKindScopedComposerContextId,
26
} from "@t3tools/shared/composerContextReferences";
27
import {
28
collectComposerInlineTokens,
@@ -103,20 +100,6 @@ export function createComposerContextHistory() {
100
};
101
}
102
106
-/** Same identity as web: one record per thread, so re-attaching reuses the chip. */
107
-export function threadComposerContext(ref: ScopedThreadRef, title: string): ThreadContextRecord {
108
- const label = sanitizeComposerContextLabel(title, "thread");
109
- return {
110
- version: 1,
111
- kind: "thread",
112
- contextId: toKindScopedComposerContextId("thread", ref.threadId),
113
- label,
114
- environmentId: ref.environmentId,
115
- threadId: ref.threadId,
116
- title: label,
117
- };
118
-}
119
-
103
/** Same identity as web: one record per machine, so mentioning it again reuses the chip. */
104
export function environmentComposerContext(
105
environmentId: EnvironmentId,
apps/mobile/src/lib/copyThreadReference.ts
new
+19
@@ -0,0 +1,19 @@
1
+import type { ThreadReferenceCopyTarget } from "@t3tools/client-runtime/thread-reference";
2
+import * as Haptics from "expo-haptics";
3
+
4
+import { writeComposerContextClipboard } from "./composerContextClipboard";
5
+import { tryCopyTextWithHaptic } from "./copyTextWithHaptic";
6
+
7
+/** Resolves false, after logging why, when the clipboard write fails. */
8
+export async function copyThreadReference(target: ThreadReferenceCopyTarget): Promise<boolean> {
9
+ if (!target.fragment)
10
+ return tryCopyTextWithHaptic(target.value, { target: target.clipboardTarget });
11
+ try {
12
+ await writeComposerContextClipboard(target.value, target.fragment);
13
+ } catch (error) {
14
+ console.error(`Failed to copy ${target.clipboardTarget} to the clipboard.`, error);
15
+ return false;
16
+ }
17
+ void Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light).catch(() => {});
18
+ return true;
19
+}
apps/web/src/components/ChatView.tsx
+7
-26
@@ -140,7 +140,7 @@ import { useWorkspaceMutationRefresh } from "../hooks/useWorkspaceMutationRefres
140
import { DEFAULT_INTERACTION_MODE, type ChatMessage } from "../types";
141
import { buildThreadRouteParams } from "../threadRoutes";
142
import { useTheme } from "../hooks/useTheme";
143
-import { writeTextToClipboard } from "../hooks/useCopyToClipboard";
143
+import { copyThreadReference } from "../lib/copyThreadReference";
144
import { subscribeSnapShotComposerFocus } from "../lib/desktopSnapShot";
145
import { useMediaQuery } from "../hooks/useMediaQuery";
146
import { FileMetadataThreadProvider } from "../hooks/FileMetadataThreadProvider";
@@ -179,7 +179,7 @@ import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings";
179
import { shortcutLabelForCommand } from "../keybindings";
180
import { cn } from "~/lib/utils";
181
import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar";
182
-import { stackedThreadToast, toastManager } from "./ui/toast";
182
+import { toastManager } from "./ui/toast";
183
import { projectScriptIdFromCommand } from "~/projectScripts";
184
import { newMessageId } from "~/lib/utils";
185
import {
@@ -2288,37 +2288,18 @@ export default function ChatView(props: ChatViewProps) {
2288
]);
2289
const openPanelPullRequestUrl = useOpenPanelPullRequestUrl(activeThreadRef);
2290
const activeThreadReferenceCopyTarget =
2291
- activeThreadId === null || !isServerThread
2291
+ activeThreadRef === null || !isServerThread
2292
? null
2293
: resolveThreadReferenceCopyTarget({
2294
- threadId: activeThreadId,
2294
+ threadRef: activeThreadRef,
2295
+ title: activeThread?.title ?? "",
2296
openPanelPullRequestUrl,
2297
pullRequests: activeThread?.pullRequests,
2298
linkedPullRequestUrl: linkedThreadPullRequest?.url ?? null,
2299
});
2300
const copyActiveThreadReference = () => {
2300
- const target = activeThreadReferenceCopyTarget;
2301
- if (target === null) return;
2302
- void writeTextToClipboard(target.value, target.clipboardTarget).then(
2303
- (didCopy) => {
2304
- if (!didCopy) return;
2305
- toastManager.add({
2306
- type: "success",
2307
- title: target.successTitle,
2308
- description: target.value,
2309
- });
2310
- },
2311
- (error) => {
2312
- console.error(error);
2313
- toastManager.add(
2314
- stackedThreadToast({
2315
- type: "error",
2316
- title: target.failureTitle,
2317
- description: error instanceof Error ? error.message : "An error occurred.",
2318
- }),
2319
- );
2320
- },
2321
- );
2301
+ if (activeThreadReferenceCopyTarget === null) return;
2302
+ void copyThreadReference(activeThreadReferenceCopyTarget);
2303
};
2304
const pullRequestPanelTarget = activeThread
2305
? threadPullRequestPanelTarget({
apps/web/src/components/CommandPalette.tsx
+8
-25
@@ -88,7 +88,7 @@ import { isDesktopLocalConnectionTarget } from "../connection/desktopLocal";
88
import { useDesktopLocalBootstraps } from "../connection/useDesktopLocalBootstraps";
89
import { useHandleNewThread } from "../hooks/useHandleNewThread";
90
import { useOpenPanelPullRequestUrl } from "../hooks/useOpenPanelPullRequestUrl";
91
-import { writeTextToClipboard } from "../hooks/useCopyToClipboard";
91
+import { copyThreadReference } from "../lib/copyThreadReference";
92
import {
93
composerPromptLink,
94
copyPromptLink,
@@ -446,33 +446,16 @@ function OpenCommandPaletteDialog(props: {
446
referenceThreadRef === null || (pathname === "/pull-requests" && !openPanelPullRequestUrl)
447
? null
448
: resolveThreadReferenceCopyTarget({
449
- threadId: referenceThreadRef.threadId,
449
+ threadRef: referenceThreadRef,
450
+ title: activeThread?.title ?? "",
451
openPanelPullRequestUrl,
452
pullRequests: activeThread?.pullRequests,
453
linkedPullRequestUrl:
454
activeThread?.linkedPullRequest?.url ?? activeThread?.branchPullRequest?.url ?? null,
455
});
456
const copyActiveThreadReference = async () => {
456
- const target = activeThreadReferenceCopyTarget;
457
- if (target === null) return;
458
- try {
459
- const didCopy = await writeTextToClipboard(target.value, target.clipboardTarget);
460
- if (!didCopy) return;
461
- toastManager.add({
462
- type: "success",
463
- title: target.successTitle,
464
- description: target.value,
465
- });
466
- } catch (error) {
467
- console.error(error);
468
- toastManager.add(
469
- stackedThreadToast({
470
- type: "error",
471
- title: target.failureTitle,
472
- description: error instanceof Error ? error.message : "An error occurred.",
473
- }),
474
- );
475
- }
457
+ if (activeThreadReferenceCopyTarget === null) return;
458
+ await copyThreadReference(activeThreadReferenceCopyTarget);
459
};
460
const threads = useThreadShells();
461
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
@@ -1299,10 +1282,10 @@ function OpenCommandPaletteDialog(props: {
1282
searchTerms:
1283
activeThreadReferenceCopyTarget.kind === "pull-request"
1284
? ["copy", "pull request", "link", "reference"]
1302
- : ["copy", "thread id", "reference"],
1285
+ : ["copy", "thread", "thread id", "reference"],
1286
title:
1304
- activeThreadReferenceCopyTarget.kind === "pull-request" ? "Copy PR link" : "Copy thread ID",
1305
- description: activeThreadReferenceCopyTarget.value,
1287
+ activeThreadReferenceCopyTarget.kind === "pull-request" ? "Copy PR link" : "Copy thread",
1288
+ description: activeThreadReferenceCopyTarget.description,
1289
icon: <LinkIcon className={ITEM_ICON_CLASS} />,
1290
shortcutCommand: "thread.copyReference",
1291
run: copyActiveThreadReference,
apps/web/src/components/LegacySidebar.tsx
+7
@@ -141,6 +141,8 @@ import { readUnloadedThreadCount } from "../state/olderSettledShelf";
141
import { useEnvironment, useEnvironments, usePrimaryEnvironmentId } from "../state/environments";
142
import { buildThreadRouteParams, resolveActiveThreadRouteRef } from "../threadRoutes";
143
import { stackedThreadToast, toastManager } from "./ui/toast";
144
+import { copyThreadReference } from "../lib/copyThreadReference";
145
+import { threadChipCopyTarget } from "@t3tools/client-runtime/thread-reference";
146
import { RelativeTime } from "./RelativeTime";
147
import { Kbd } from "./ui/kbd";
148
import {
@@ -2182,6 +2184,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
2184
: []),
2185
{ id: "mark-unread", label: "Mark unread" },
2186
{ id: "copy-path", label: "Copy Path" },
2187
+ { id: "copy-thread", label: "Copy Thread" },
2188
{ id: "copy-thread-id", label: "Copy Thread ID" },
2189
{ id: "project-settings", label: "Project settings" },
2190
{
@@ -2253,6 +2256,10 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
2256
copyPathToClipboard(threadWorkspacePath, { path: threadWorkspacePath });
2257
return;
2258
}
2259
+ if (clicked === "copy-thread") {
2260
+ void copyThreadReference(threadChipCopyTarget(threadRef, thread.title));
2261
+ return;
2262
+ }
2263
if (clicked === "copy-thread-id") {
2264
copyThreadIdToClipboard(thread.id, { threadId: thread.id });
2265
return;
apps/web/src/components/Sidebar.tsx
+5
@@ -214,6 +214,8 @@ import {
214
useActiveRowReveal,
215
} from "./sidebar/routeReveal";
216
import { stackedThreadToast, toastManager } from "./ui/toast";
217
+import { copyThreadReference } from "../lib/copyThreadReference";
218
+import { threadChipCopyTarget } from "@t3tools/client-runtime/thread-reference";
219
import { Button } from "./ui/button";
220
import {
221
Combobox,
@@ -2587,6 +2589,9 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2589
copyBranchToClipboard(thread.branch, { branch: thread.branch });
2590
}
2591
return;
2592
+ case "copy-thread":
2593
+ void copyThreadReference(threadChipCopyTarget(threadRef, thread.title));
2594
+ return;
2595
case "copy-thread-id":
2596
copyThreadIdToClipboard(thread.id, { threadId: thread.id });
2597
return;
apps/web/src/components/chat/ChatComposer.tsx
+4
-2
@@ -134,7 +134,10 @@ import {
134
type TerminalContextDraft,
135
type TerminalContextSelection,
136
} from "../../lib/terminalContext";
137
-import { toKindScopedComposerContextId } from "@t3tools/shared/composerContextReferences";
137
+import {
138
+ threadContextRecord,
139
+ toKindScopedComposerContextId,
140
+} from "@t3tools/shared/composerContextReferences";
141
import {
142
shouldUseCompactComposerPrimaryActions,
143
shouldUseCompactComposerFooter,
@@ -168,7 +171,6 @@ import {
171
reviewCommentContextRecord,
172
terminalContextReference,
173
terminalContextRecord,
171
- threadContextRecord,
174
threadContextReference,
175
environmentContextRecord,
176
environmentContextReference,
apps/web/src/components/chat/composerSend.logic.test.ts
+2
-1
@@ -2,7 +2,8 @@ import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
3
import { describe, expect, it } from "vite-plus/test";
4
import { formatInlineContextReference } from "../../lib/composerContextReferences";
5
-import { threadContextRecord, threadContextReference } from "../../lib/composerContextRecords";
5
+import { threadContextReference } from "../../lib/composerContextRecords";
6
+import { threadContextRecord } from "@t3tools/shared/composerContextReferences";
7
import {
8
approvalRedirectNotice,
9
loadBalancingSendWarning,
apps/web/src/components/settings/KeybindingsSettings.logic.ts
+1
-1
@@ -362,7 +362,7 @@ export function commandLabel(command: KeybindingCommand): string {
362
if (command === "composer.sendAndNewThread") return "Composer: Send and Start New Thread";
363
if (command === "thread.steerQueuedMessage") return "Queue: Send First Queued Message";
364
if (command === "thread.editQueuedMessage") return "Queue: Edit Last Queued Message";
365
- if (command === "thread.copyReference") return "Pull Request: Copy Link or Thread ID";
365
+ if (command === "thread.copyReference") return "Pull Request: Copy Link or Thread";
366
const usageMetric = METRIC_OPTIONS.find((option) => option.command === command);
367
if (usageMetric) return `Usage: ${usageMetric.label}`;
368
const usagePeriod = WINDOW_OPTIONS.find((option) => option.command === command);
apps/web/src/components/threadActionMenu.logic.ts
+3
@@ -22,6 +22,7 @@ export type ThreadActionMenuId =
22
| "copy"
23
| "copy-path"
24
| "copy-branch"
25
+ | "copy-thread"
26
| "copy-thread-id"
27
| "archive"
28
| "delete";
@@ -101,6 +102,7 @@ export function threadActionRequiresOperate(action: ThreadActionMenuId): boolean
102
"copy",
103
"copy-path",
104
"copy-branch",
105
+ "copy-thread",
106
"copy-thread-id",
107
].includes(action);
108
}
@@ -208,6 +210,7 @@ export function buildThreadActionMenuItems(
210
...(state.branch
211
? [{ id: "copy-branch" as const, label: "Branch", icon: "git-branch" }]
212
: []),
213
+ { id: "copy-thread", label: "Thread", icon: "message-square" },
214
{ id: "copy-thread-id", label: "Thread ID", icon: "hash" },
215
],
216
},
apps/web/src/composerDraftStore.test.ts
+1
-1
@@ -99,8 +99,8 @@ import {
99
buildMessageContext,
100
environmentContextRecord,
101
terminalContextReference,
102
- threadContextRecord,
102
} from "./lib/composerContextRecords";
103
+import { threadContextRecord } from "@t3tools/shared/composerContextReferences";
104
import {
105
copiedComposerAttachmentFile,
106
rememberCopiedComposerAttachments,
apps/web/src/contextMenuFallback.ts
+8
@@ -65,6 +65,14 @@ const ICON_PATHS: Record<string, ReadonlyArray<{ tag: string; attrs: Record<stri
65
},
66
{ tag: "path", attrs: { d: "m22 10-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 10" } },
67
],
68
+ "message-square": [
69
+ {
70
+ tag: "path",
71
+ attrs: {
72
+ d: "M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",
73
+ },
74
+ },
75
+ ],
76
"message-square-plus": [
77
{
78
tag: "path",
apps/web/src/hooks/useThreadActionMenu.ts
+5
@@ -22,6 +22,8 @@ import {
22
type ThreadActionMenuId,
23
} from "../components/threadActionMenu.logic";
24
import { stackedThreadToast, toastManager } from "../components/ui/toast";
25
+import { copyThreadReference } from "../lib/copyThreadReference";
26
+import { threadChipCopyTarget } from "@t3tools/client-runtime/thread-reference";
27
import { threadEnvironment } from "../state/threads";
28
import { useOrchestrationCommand } from "../state/use-orchestration-command";
29
import { readEnvironmentScope } from "../state/session";
@@ -269,6 +271,9 @@ export function useThreadActionMenu(input: {
271
copyBranchToClipboard(thread.branch, { branch: thread.branch });
272
}
273
return;
274
+ case "copy-thread":
275
+ void copyThreadReference(threadChipCopyTarget(threadRef, thread.title));
276
+ return;
277
case "copy-thread-id":
278
copyThreadIdToClipboard(thread.id, { threadId: thread.id });
279
return;
apps/web/src/lib/composerContextRecords.ts
-18
@@ -19,7 +19,6 @@ import type {
19
PreviewAnnotationContextRecord,
20
PreviewAnnotationPayload,
21
ReviewCommentContextRecord,
22
- ScopedThreadRef,
22
TerminalContextRecord,
23
ThreadContextRecord,
24
ThreadId,
@@ -154,27 +153,10 @@ export function previewAnnotationContextReference(
153
};
154
}
155
157
-function threadContextId(threadId: ThreadId): ComposerContextId {
158
- return toKindScopedComposerContextId("thread", threadId);
159
-}
160
-
156
export function threadContextReference(record: ThreadContextRecord): ComposerContextReference {
157
return { kind: "thread", contextId: record.contextId, label: record.label };
158
}
159
165
-export function threadContextRecord(ref: ScopedThreadRef, title: string): ThreadContextRecord {
166
- const label = sanitizeComposerContextLabel(title, "thread");
167
- return {
168
- version: 1,
169
- kind: "thread",
170
- contextId: threadContextId(ref.threadId),
171
- label,
172
- environmentId: ref.environmentId,
173
- threadId: ref.threadId,
174
- title: label,
175
- };
176
-}
177
-
160
/** One record per machine: mentioning the same machine twice reuses the chip. */
161
export function environmentContextReference(
162
record: EnvironmentContextRecord,
apps/web/src/lib/copyThreadReference.ts
new
+34
@@ -0,0 +1,34 @@
1
+import type { ThreadReferenceCopyTarget } from "@t3tools/client-runtime/thread-reference";
2
+import {
3
+ COMPOSER_CONTEXT_CLIPBOARD_MIME,
4
+ encodeComposerContextFragment,
5
+} from "@t3tools/shared/composerContextClipboard";
6
+
7
+import { stackedThreadToast, toastManager } from "../components/ui/toast";
8
+import { writeTextToClipboard } from "../hooks/useCopyToClipboard";
9
+
10
+export async function copyThreadReference(target: ThreadReferenceCopyTarget): Promise<void> {
11
+ const fragment = target.fragment ? encodeComposerContextFragment(target.fragment) : null;
12
+ try {
13
+ const didCopy = await writeTextToClipboard(
14
+ target.value,
15
+ target.clipboardTarget,
16
+ fragment ? { [COMPOSER_CONTEXT_CLIPBOARD_MIME]: fragment } : undefined,
17
+ );
18
+ if (!didCopy) return;
19
+ toastManager.add({
20
+ type: "success",
21
+ title: target.successTitle,
22
+ description: target.description,
23
+ });
24
+ } catch (error) {
25
+ console.error(error);
26
+ toastManager.add(
27
+ stackedThreadToast({
28
+ type: "error",
29
+ title: target.failureTitle,
30
+ description: error instanceof Error ? error.message : "An error occurred.",
31
+ }),
32
+ );
33
+ }
34
+}
apps/web/src/pendingUserInput.test.ts
+2
-1
@@ -1,7 +1,8 @@
1
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
2
import { describe, expect, it } from "vite-plus/test";
3
import { formatInlineContextReference } from "./lib/composerContextReferences";
4
-import { threadContextRecord, threadContextReference } from "./lib/composerContextRecords";
4
+import { threadContextReference } from "./lib/composerContextRecords";
5
+import { threadContextRecord } from "@t3tools/shared/composerContextReferences";
6
7
import {
8
buildPendingUserInputAnswers,
docs/user/composer.md
+3
-2
@@ -283,8 +283,9 @@ the repository by text. Choose a result to insert it as a chip.
283
Another thread can be context too. Type `@` followed by part of its title to pick one from
284
the same server, or from a machine it links to while the Linked environments beta is on; those
285
show the machine's name. On web and desktop you can also drag a thread out of the sidebar and
286
-drop it on the composer; a multi-selection drops together. The chip shows the thread's current title and
287
-opens it when selected. Your prompt only carries a reference: the agent reads the thread's
286
+drop it on the composer; a multi-selection drops together. On any client, **Copy thread** puts a
287
+thread on the clipboard that pastes into a composer as its chip. The chip shows the thread's
288
+current title and opens it when selected. Your prompt only carries a reference: the agent reads the thread's
289
history on demand, so attaching a long thread costs nothing until the agent looks. Attaching a
290
thread does not change it, and the agent cannot send messages to it unless you ask.
291
docs/user/keybindings.md
+3
-1
@@ -48,8 +48,10 @@ in Settings.
48
49
With a PR open in the right panel or on the Pull requests page, use `mod+shift+c`
50
to copy its URL and `mod+shift+k` to copy its number with a `#` prefix.
51
-Both shortcuts can be changed in Settings. Search for “Copy Link or Thread ID”
51
+Both shortcuts can be changed in Settings. Search for “Copy Link or Thread”
52
or “Copy Number”. They copy the selected PR and leave terminal input alone.
53
+Without a PR, `mod+shift+c` copies the thread itself, which pastes into a
54
+composer as a thread chip.
55
56
## Find in a diff
57
docs/user/thread-sidebar.md
+5
-2
@@ -210,8 +210,11 @@ palette.
210
211
Use **Settings → Keybindings** to find or customize shortcuts for searching files
212
and copying a thread reference. A copied reference uses the thread's pull request
213
-link when available, otherwise its thread ID. See [keybindings](./keybindings.md)
214
-for custom configuration.
213
+link when available, otherwise the thread itself, which pastes into a composer as
214
+a thread chip. To copy the thread even when it has a PR, choose **Copy → Thread**
215
+from its context menu, or **Copy thread** from its long-press menu on mobile.
216
+**Thread ID** copies the bare ID for scripts and the `t3` CLI. See
217
+[keybindings](./keybindings.md) for custom configuration.
218
219
## Inspect agent work
220
packages/client-runtime/src/threadReference.test.ts
+46
-5
@@ -1,8 +1,18 @@
1
-import type { ThreadPullRequestLink } from "@t3tools/contracts";
1
+import { EnvironmentId, ThreadId, type ThreadPullRequestLink } from "@t3tools/contracts";
2
+import {
3
+ decodeComposerContextFragment,
4
+ encodeComposerContextFragment,
5
+} from "@t3tools/shared/composerContextClipboard";
6
+import { collectComposerContextReferences } from "@t3tools/shared/composerContextReferences";
7
import { describe, expect, it } from "vite-plus/test";
8
9
import { resolveThreadReferenceCopyTarget } from "./threadReference.ts";
10
11
+const thread = {
12
+ threadRef: { environmentId: EnvironmentId.make("env-1"), threadId: ThreadId.make("thread-1") },
13
+ title: "Fix the login flow",
14
+};
15
+
16
const crossRepositoryPullRequest: ThreadPullRequestLink = {
17
host: "github.com",
18
repository: "other/repo",
@@ -18,7 +28,7 @@ describe("resolveThreadReferenceCopyTarget", () => {
28
it("does not copy another reference while the open panel URL is unavailable", () => {
29
expect(
30
resolveThreadReferenceCopyTarget({
21
- threadId: "thread-1",
31
+ ...thread,
32
openPanelPullRequestUrl: null,
33
pullRequests: [crossRepositoryPullRequest],
34
linkedPullRequestUrl: "https://github.com/t3/pr/12",
@@ -29,7 +39,7 @@ describe("resolveThreadReferenceCopyTarget", () => {
39
it("prefers the open panel pull request over the thread pull request", () => {
40
expect(
41
resolveThreadReferenceCopyTarget({
32
- threadId: "thread-1",
42
+ ...thread,
43
openPanelPullRequestUrl: "https://github.com/t3/pr/14",
44
pullRequests: [crossRepositoryPullRequest],
45
linkedPullRequestUrl: "https://github.com/t3/pr/12",
@@ -46,7 +56,7 @@ describe("resolveThreadReferenceCopyTarget", () => {
56
(linkedPullRequestUrl) => {
57
expect(
58
resolveThreadReferenceCopyTarget({
49
- threadId: "thread-1",
59
+ ...thread,
60
pullRequests: [crossRepositoryPullRequest],
61
linkedPullRequestUrl,
62
}),
@@ -60,10 +70,41 @@ describe("resolveThreadReferenceCopyTarget", () => {
70
it("uses the fallback URL when native links are dismissed", () => {
71
expect(
72
resolveThreadReferenceCopyTarget({
63
- threadId: "thread-1",
73
+ ...thread,
74
pullRequests: [{ ...crossRepositoryPullRequest, source: "stack-dismissed" }],
75
linkedPullRequestUrl: "https://github.com/t3/pr/12",
76
}),
77
).toMatchObject({ kind: "pull-request", value: "https://github.com/t3/pr/12" });
78
});
79
+
80
+ it("copies a thread chip that pastes back as the same thread on its machine", () => {
81
+ const target = resolveThreadReferenceCopyTarget({ ...thread, linkedPullRequestUrl: null });
82
+
83
+ expect(target).toMatchObject({
84
+ kind: "thread",
85
+ description: "Fix the login flow",
86
+ successTitle: "Thread copied",
87
+ });
88
+ const pasted = decodeComposerContextFragment(encodeComposerContextFragment(target!.fragment!));
89
+ expect(pasted).toEqual({
90
+ version: 1,
91
+ source: { environmentId: "env-1" },
92
+ records: [
93
+ expect.objectContaining({
94
+ kind: "thread",
95
+ environmentId: "env-1",
96
+ threadId: "thread-1",
97
+ title: "Fix the login flow",
98
+ }),
99
+ ],
100
+ });
101
+ // A paste keeps only the records its plain text references.
102
+ expect(collectComposerContextReferences(target!.value)).toEqual([
103
+ expect.objectContaining({
104
+ kind: "thread",
105
+ contextId: pasted!.records[0]!.contextId,
106
+ label: "Fix the login flow",
107
+ }),
108
+ ]);
109
+ });
110
});
packages/client-runtime/src/threadReference.ts
+35
-9
@@ -1,17 +1,48 @@
1
-import type { ThreadPullRequestLink } from "@t3tools/contracts";
1
+import type {
2
+ ComposerContextClipboardFragment,
3
+ ScopedThreadRef,
4
+ ThreadPullRequestLink,
5
+} from "@t3tools/contracts";
6
+import {
7
+ formatComposerContextReference,
8
+ threadContextRecord,
9
+} from "@t3tools/shared/composerContextReferences";
10
11
import { resolveThreadCurrentPullRequestLink } from "./threadPullRequests.ts";
12
13
export interface ThreadReferenceCopyTarget {
14
readonly kind: "pull-request" | "thread";
15
+ /** The plain text: a PR URL, or a thread chip's reference link. */
16
readonly value: string;
17
+ /** What a toast or palette row shows for the copy. */
18
+ readonly description: string;
19
+ /** T3's clipboard format, which pastes a thread back into a composer as a chip. */
20
+ readonly fragment?: ComposerContextClipboardFragment;
21
readonly clipboardTarget: string;
22
readonly successTitle: string;
23
readonly failureTitle: string;
24
}
25
26
+/** A thread chip pastes into any composer whose agent reads that thread's machine. */
27
+export function threadChipCopyTarget(
28
+ threadRef: ScopedThreadRef,
29
+ title: string,
30
+): ThreadReferenceCopyTarget {
31
+ const record = threadContextRecord(threadRef, title);
32
+ return {
33
+ kind: "thread",
34
+ value: formatComposerContextReference(record),
35
+ description: record.title,
36
+ fragment: { version: 1, source: { environmentId: threadRef.environmentId }, records: [record] },
37
+ clipboardTarget: "thread",
38
+ successTitle: "Thread copied",
39
+ failureTitle: "Failed to copy thread",
40
+ };
41
+}
42
+
43
export function resolveThreadReferenceCopyTarget(input: {
14
- readonly threadId: string;
44
+ readonly threadRef: ScopedThreadRef;
45
+ readonly title: string;
46
/** Undefined means no PR panel; null means its URL is not available yet. */
47
readonly openPanelPullRequestUrl?: string | null | undefined;
48
readonly pullRequests?: ReadonlyArray<ThreadPullRequestLink> | undefined;
@@ -26,15 +57,10 @@ export function resolveThreadReferenceCopyTarget(input: {
57
? {
58
kind: "pull-request",
59
value: pullRequestUrl,
60
+ description: pullRequestUrl,
61
clipboardTarget: "pull request link",
62
successTitle: "PR link copied",
63
failureTitle: "Failed to copy PR link",
64
}
33
- : {
34
- kind: "thread",
35
- value: input.threadId,
36
- clipboardTarget: "thread ID",
37
- successTitle: "Thread ID copied",
38
- failureTitle: "Failed to copy thread ID",
39
- };
65
+ : threadChipCopyTarget(input.threadRef, input.title);
66
}
packages/shared/src/composerContextReferences.test.ts
+25
-1
@@ -1,5 +1,5 @@
1
import {
2
- type ComposerContextId,
2
+ ComposerContextId,
3
type ComposerContextRecord,
4
EnvironmentId,
5
ThreadId,
@@ -12,6 +12,7 @@ import {
12
isImageReferencesOnly,
13
parseComposerContextHref,
14
projectComposerContextForProvider,
15
+ threadContextRecord,
16
threadContextsOutsideEnvironment,
17
toComposerContextId,
18
toKindScopedComposerContextId,
@@ -382,3 +383,26 @@ describe("toComposerContextId", () => {
383
expect(first.length).toBeLessThanOrEqual(128);
384
});
385
});
386
+
387
+describe("threadContextRecord", () => {
388
+ it("mints a schema-valid id that survives a rename, for agent-spawned thread ids too", () => {
389
+ const environmentId = EnvironmentId.make("env-1");
390
+ const ref = {
391
+ environmentId,
392
+ threadId: ThreadId.make(`thread:mcp:${encodeURIComponent("3f2b:delegate")}:review:0`),
393
+ };
394
+ const record = threadContextRecord(ref, "Review [draft]\nnotes");
395
+
396
+ expect(() => ComposerContextId.make(record.contextId)).not.toThrow();
397
+ expect(threadContextRecord(ref, "Renamed").contextId).toBe(record.contextId);
398
+ expect(record).toMatchObject({
399
+ environmentId,
400
+ threadId: ref.threadId,
401
+ label: "Review draft notes",
402
+ title: "Review draft notes",
403
+ });
404
+ expect(
405
+ threadContextRecord({ environmentId, threadId: ThreadId.make("abc-123") }, "").contextId,
406
+ ).toBe("thread_abc-123");
407
+ });
408
+});
packages/shared/src/composerContextReferences.ts
+15
@@ -6,6 +6,7 @@ import {
6
type ElementContextDetails,
7
type EnvironmentId,
8
type KnownComposerContextRecord,
9
+ type ScopedThreadRef,
10
type ThreadContextRecord,
11
} from "@t3tools/contracts";
12
@@ -74,6 +75,20 @@ export function sanitizeComposerContextLabel(label: string, kind: ComposerContex
75
return cleaned.length > 0 ? cleaned : kind;
76
}
77
78
+/** One record per thread, so re-attaching a renamed thread reuses its chip. */
79
+export function threadContextRecord(ref: ScopedThreadRef, title: string): ThreadContextRecord {
80
+ const label = sanitizeComposerContextLabel(title, "thread");
81
+ return {
82
+ version: 1,
83
+ kind: "thread",
84
+ contextId: toKindScopedComposerContextId("thread", ref.threadId),
85
+ label,
86
+ environmentId: ref.environmentId,
87
+ threadId: ref.threadId,
88
+ title: label,
89
+ };
90
+}
91
+
92
export function formatComposerContextReference(reference: {
93
kind: ComposerContextKind;
94
contextId: ComposerContextId;