GeezerVison is showing github.com — feat(web,mobile): Copy thread copies a chip that works on linked mach… · pingdotgg/t3code@0affd28
File treeExpand file treeCollapse file tree Open diff view settings modules/t3-native-controls/ios
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/mobile/modules/t3-native-controls/ios/T3KeyboardCommandsModule.swift +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -53,7 +53,7 @@ public final class T3KeyboardCommandsView: ExpoView { | 53 | 53 | input: "c", | 54 | 54 | modifiers: [.command, .shift], | 55 | 55 | action: #selector(copyThreadReference), | 56 | | - title: "Copy PR Link or Thread ID" | | 56 | + title: "Copy PR Link or Thread" | 57 | 57 | ), | 58 | 58 | enabledCommand("toggleSidebar", input: "\\", modifiers: .command, action: #selector(handleToggleSidebar), title: "Toggle Sidebar"), | 59 | 59 | enabledCommand("cycleHost", input: "h", modifiers: [.command, .shift], action: #selector(cycleHost), title: "Next Machine"), | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/keyboard/CommandPalette.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -393,7 +393,7 @@ export function CommandPalette(props: { | 393 | 393 | ["files", "Go to file", ["open", "files", "browse", "search"]], | 394 | 394 | ["terminal", "Open terminal", ["shell", "console"]], | 395 | 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 | 397 | ] as const; | 398 | 398 | actions.push( | 399 | 399 | ...threadActions.map(([command, title, searchTerms]) => ({ | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/keyboard/HardwareKeyboardCommandProvider.tsx +5-6Lines changed: 5 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,7 +14,7 @@ import { | 14 | 14 | type ReactNode, | 15 | 15 | } from "react"; | 16 | 16 |
| 17 | | -import { tryCopyTextWithHaptic } from "../../lib/copyTextWithHaptic"; | | 17 | +import { copyThreadReference } from "../../lib/copyThreadReference"; | 18 | 18 | import { | 19 | 19 | firstWorkspaceDetailOpen, | 20 | 20 | workspaceHasColumns, | @@ -62,7 +62,8 @@ export function HardwareKeyboardCommandProvider({ | 62 | 62 | activeThreadRef === null | 63 | 63 | ? null | 64 | 64 | : resolveThreadReferenceCopyTarget({ | 65 | | - threadId: activeThread?.id ?? activeThreadRef.threadId, | | 65 | + threadRef: activeThreadRef, | | 66 | + title: activeThread?.title ?? "", | 66 | 67 | pullRequests: activeThread?.pullRequests, | 67 | 68 | linkedPullRequestUrl: | 68 | 69 | (activeThread?.linkedPullRequest ?? activeThread?.branchPullRequest)?.url ?? null, | @@ -134,16 +135,14 @@ export function HardwareKeyboardCommandProvider({ | 134 | 135 | if (command === "copyThreadReference") { | 135 | 136 | if (copyTarget === null) return; | 136 | 137 | const requestId = ++copyRequestIdRef.current; | 137 | | - void tryCopyTextWithHaptic(copyTarget.value, { | 138 | | - target: copyTarget.clipboardTarget, | 139 | | - }).then((didCopy) => { | | 138 | + void copyThreadReference(copyTarget).then((didCopy) => { | 140 | 139 | if (requestId !== copyRequestIdRef.current) return; | 141 | 140 | showCopyFeedback( | 142 | 141 | didCopy | 143 | 142 | ? { | 144 | 143 | phase: "success", | 145 | 144 | label: copyTarget.successTitle, | 146 | | - description: copyTarget.value, | | 145 | + description: copyTarget.description, | 147 | 146 | } | 148 | 147 | : { | 149 | 148 | phase: "error", | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/thread-list-v2-items.tsx +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,6 +27,7 @@ import { | 27 | 27 | } from "@t3tools/client-runtime/state/models"; | 28 | 28 | import { AuthOrchestrationOperateScope, type EnvironmentMachineKind } from "@t3tools/contracts"; | 29 | 29 | import { canSnooze } from "@t3tools/client-runtime/state/thread-settled"; | | 30 | +import { threadChipCopyTarget } from "@t3tools/client-runtime/thread-reference"; | 30 | 31 | import type { MenuAction } from "@react-native-menu/menu"; | 31 | 32 | import { memo, useCallback, useMemo, useState, type ComponentProps } from "react"; | 32 | 33 | import { Pressable, useWindowDimensions, View } from "react-native"; | @@ -42,6 +43,7 @@ import { ProviderIcon, ProviderInstanceIcon } from "../../components/ProviderIco | 42 | 43 | import { useNowAfter } from "../../lib/clock"; | 43 | 44 | import { cn } from "../../lib/cn"; | 44 | 45 | import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic"; | | 46 | +import { copyThreadReference } from "../../lib/copyThreadReference"; | 45 | 47 | import { useUniwindTheme } from "../../lib/useUniwindTheme"; | 46 | 48 | import { useEnvironmentScope } from "../../state/session"; | 47 | 49 | import type { PendingNewTask } from "../../state/use-pending-new-tasks"; | @@ -918,6 +920,15 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { | 918 | 920 | if (nativeEvent.event === "archive") handleArchive(); | 919 | 921 | if (nativeEvent.event === "rename") handleRename(); | 920 | 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 | + } | 921 | 932 | if (nativeEvent.event === "copy-thread-id") { | 922 | 933 | copyTextWithHaptic(thread.id, { target: "thread-id" }); | 923 | 934 | } | @@ -1406,6 +1417,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: { | 1406 | 1417 | }, | 1407 | 1418 | ] | 1408 | 1419 | : []), | | 1420 | + { id: "copy-thread", title: "Copy thread", image: "text.bubble" }, | 1409 | 1421 | { id: "copy-thread-id", title: "Copy thread ID", image: "doc.on.doc" }, | 1410 | 1422 | ...(snoozedRow | 1411 | 1423 | ? snoozedMenuActions | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/use-composer-command-menu.ts +5-6Lines changed: 5 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,12 +18,11 @@ const EMPTY_THREAD_SHELLS: ReadonlyArray<EnvironmentThreadShell> = []; | 18 | 18 | const EMPTY_ENVIRONMENTS: ReadonlyArray<ComposerEnvironmentCandidate> = []; | 19 | 19 | const NO_LINKED_ENVIRONMENTS: ReadonlyMap<EnvironmentId, string> = new Map(); | 20 | 20 | import { COMPOSER_CONTEXT_MAX_RECORDS } from "@t3tools/contracts"; | 21 | | -import { formatComposerContextReference } from "@t3tools/shared/composerContextReferences"; | 22 | 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"; | 27 | 26 | import { uuidv4 } from "../../lib/uuid"; | 28 | 27 | import { | 29 | 28 | getComposerDraftSnapshot, | @@ -528,7 +527,7 @@ export function useComposerCommandMenu({ | 528 | 527 | candidate.id === item.thread.threadId, | 529 | 528 | ); | 530 | 529 | if (!shell) return; | 531 | | - const record = threadComposerContext(item.thread, shell.title); | | 530 | + const record = threadContextRecord(item.thread, shell.title); | 532 | 531 | const existing = getComposerDraftSnapshot(ownerKey).context?.records ?? []; | 533 | 532 | const alreadyAttached = existing.some((entry) => entry.contextId === record.contextId); | 534 | 533 | if (!alreadyAttached && existing.length >= COMPOSER_CONTEXT_MAX_RECORDS) { | |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/lib/composerContext.test.ts -20Lines changed: 0 additions & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | ProjectId, | 5 | 5 | ProviderInstanceId, | 6 | 6 | ComposerContextId, | 7 | | - EnvironmentId, | 8 | | - ThreadId, | 9 | 7 | type OrchestrationMessageContext, | 10 | 8 | type ServerProviderSkill, | 11 | 9 | } from "@t3tools/contracts"; | @@ -28,7 +26,6 @@ import { | 28 | 26 | uploadedComposerContext, | 29 | 27 | serializeComposerMessageForServer, | 30 | 28 | pullRequestComposerContext, | 31 | | - threadComposerContext, | 32 | 29 | } from "./composerContext"; | 33 | 30 |
| 34 | 31 | const terminal = { | @@ -397,20 +394,3 @@ describe("host context compatibility", () => { | 397 | 394 | expect(context.records).toEqual([terminal, review, pr]); | 398 | 395 | }); | 399 | 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 | | -}); |
Collapse file Copy file name to clipboardExpand all lines: apps/mobile/src/lib/composerContext.ts -17Lines changed: 0 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,9 +11,7 @@ import { | 11 | 11 | OrchestrationMessageContext, | 12 | 12 | type PullRequestContextMetadata, | 13 | 13 | type ReviewCommentContextRecord, | 14 | | - type ScopedThreadRef, | 15 | 14 | type ServerProviderSkill, | 16 | | - type ThreadContextRecord, | 17 | 15 | type EnvironmentContextRecord, | 18 | 16 | type EnvironmentId, | 19 | 17 | } from "@t3tools/contracts"; | @@ -25,7 +23,6 @@ import { | 25 | 23 | isImageReferencesOnly, | 26 | 24 | replaceComposerContextReferences, | 27 | 25 | sanitizeComposerContextLabel, | 28 | | - toKindScopedComposerContextId, | 29 | 26 | } from "@t3tools/shared/composerContextReferences"; | 30 | 27 | import { | 31 | 28 | collectComposerInlineTokens, | @@ -103,20 +100,6 @@ export function createComposerContextHistory() { | 103 | 100 | }; | 104 | 101 | } | 105 | 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 | | - | 120 | 103 | /** Same identity as web: one record per machine, so mentioning it again reuses the chip. */ | 121 | 104 | export function environmentComposerContext( | 122 | 105 | environmentId: EnvironmentId, | |
Collapse file Copy file name to clipboard +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | +} |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ChatView.tsx +7-26Lines changed: 7 additions & 26 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -140,7 +140,7 @@ import { useWorkspaceMutationRefresh } from "../hooks/useWorkspaceMutationRefres | 140 | 140 | import { DEFAULT_INTERACTION_MODE, type ChatMessage } from "../types"; | 141 | 141 | import { buildThreadRouteParams } from "../threadRoutes"; | 142 | 142 | import { useTheme } from "../hooks/useTheme"; | 143 | | -import { writeTextToClipboard } from "../hooks/useCopyToClipboard"; | | 143 | +import { copyThreadReference } from "../lib/copyThreadReference"; | 144 | 144 | import { subscribeSnapShotComposerFocus } from "../lib/desktopSnapShot"; | 145 | 145 | import { useMediaQuery } from "../hooks/useMediaQuery"; | 146 | 146 | import { FileMetadataThreadProvider } from "../hooks/FileMetadataThreadProvider"; | @@ -179,7 +179,7 @@ import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings"; | 179 | 179 | import { shortcutLabelForCommand } from "../keybindings"; | 180 | 180 | import { cn } from "~/lib/utils"; | 181 | 181 | import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "~/workspaceTitlebar"; | 182 | | -import { stackedThreadToast, toastManager } from "./ui/toast"; | | 182 | +import { toastManager } from "./ui/toast"; | 183 | 183 | import { projectScriptIdFromCommand } from "~/projectScripts"; | 184 | 184 | import { newMessageId } from "~/lib/utils"; | 185 | 185 | import { | @@ -2288,37 +2288,18 @@ export default function ChatView(props: ChatViewProps) { | 2288 | 2288 | ]); | 2289 | 2289 | const openPanelPullRequestUrl = useOpenPanelPullRequestUrl(activeThreadRef); | 2290 | 2290 | const activeThreadReferenceCopyTarget = | 2291 | | - activeThreadId === null || !isServerThread | | 2291 | + activeThreadRef === null || !isServerThread | 2292 | 2292 | ? null | 2293 | 2293 | : resolveThreadReferenceCopyTarget({ | 2294 | | - threadId: activeThreadId, | | 2294 | + threadRef: activeThreadRef, | | 2295 | + title: activeThread?.title ?? "", | 2295 | 2296 | openPanelPullRequestUrl, | 2296 | 2297 | pullRequests: activeThread?.pullRequests, | 2297 | 2298 | linkedPullRequestUrl: linkedThreadPullRequest?.url ?? null, | 2298 | 2299 | }); | 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); | 2322 | 2303 | }; | 2323 | 2304 | const pullRequestPanelTarget = activeThread | 2324 | 2305 | ? threadPullRequestPanelTarget({ | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/CommandPalette.tsx +8-25Lines changed: 8 additions & 25 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -88,7 +88,7 @@ import { isDesktopLocalConnectionTarget } from "../connection/desktopLocal"; | 88 | 88 | import { useDesktopLocalBootstraps } from "../connection/useDesktopLocalBootstraps"; | 89 | 89 | import { useHandleNewThread } from "../hooks/useHandleNewThread"; | 90 | 90 | import { useOpenPanelPullRequestUrl } from "../hooks/useOpenPanelPullRequestUrl"; | 91 | | -import { writeTextToClipboard } from "../hooks/useCopyToClipboard"; | | 91 | +import { copyThreadReference } from "../lib/copyThreadReference"; | 92 | 92 | import { | 93 | 93 | composerPromptLink, | 94 | 94 | copyPromptLink, | @@ -446,33 +446,16 @@ function OpenCommandPaletteDialog(props: { | 446 | 446 | referenceThreadRef === null || (pathname === "/pull-requests" && !openPanelPullRequestUrl) | 447 | 447 | ? null | 448 | 448 | : resolveThreadReferenceCopyTarget({ | 449 | | - threadId: referenceThreadRef.threadId, | | 449 | + threadRef: referenceThreadRef, | | 450 | + title: activeThread?.title ?? "", | 450 | 451 | openPanelPullRequestUrl, | 451 | 452 | pullRequests: activeThread?.pullRequests, | 452 | 453 | linkedPullRequestUrl: | 453 | 454 | activeThread?.linkedPullRequest?.url ?? activeThread?.branchPullRequest?.url ?? null, | 454 | 455 | }); | 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); | 476 | 459 | }; | 477 | 460 | const threads = useThreadShells(); | 478 | 461 | const keybindings = useAtomValue(primaryServerKeybindingsAtom); | @@ -1299,10 +1282,10 @@ function OpenCommandPaletteDialog(props: { | 1299 | 1282 | searchTerms: | 1300 | 1283 | activeThreadReferenceCopyTarget.kind === "pull-request" | 1301 | 1284 | ? ["copy", "pull request", "link", "reference"] | 1302 | | - : ["copy", "thread id", "reference"], | | 1285 | + : ["copy", "thread", "thread id", "reference"], | 1303 | 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, | 1306 | 1289 | icon: <LinkIcon className={ITEM_ICON_CLASS} />, | 1307 | 1290 | shortcutCommand: "thread.copyReference", | 1308 | 1291 | run: copyActiveThreadReference, | |
|