@devries-cameron20 / t3code-1 / commits / 05d32e55d3
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(chat): open thread links across connected environments (#21505)

Co-authored-by: Sil Veltman <52583398+silveltman@users.noreply.github.com>

Julius Marminge committed Oct 19, 2026 at 16:21 UTC 05d32e55d3272396ee68a7dfd48a839df2ad3af9
6 files changed +105 -15
apps/mobile/src/features/threads/ThreadFeed.tsx
+7 -3
@@ -34,7 +34,7 @@ import {
34 } from "@t3tools/contracts";
35 import { renderAssistantCitationsAsText } from "@t3tools/shared/assistantCitations";
36 import { encodeComposerContextFragment } from "@t3tools/shared/composerContextClipboard";
37 -import { parseThreadLinkHref } from "@t3tools/shared/threadLinks";
37 +import { parseThreadLinkHref, resolveThreadLinkRef } from "@t3tools/shared/threadLinks";
38 import { PROMPT_LINK_MAX_PROMPT_LENGTH } from "@t3tools/shared/promptLinks";
39 import {
40 parseComposerContextHref,
@@ -1788,9 +1788,13 @@ export const ThreadFeed = memo(function ThreadFeed(props: ThreadFeedProps) {
1788 const onMarkdownLinkPress = (href: string, imageEmbed = false) => {
1789 const linkedThreadId = parseThreadLinkHref(href);
1790 if (linkedThreadId) {
1791 + const source = scopeThreadRef(props.environmentId, linkedThreadId);
1792 + const target =
1793 + resolveThreadLinkRef(source, appAtomRegistry.get(environmentThreadShells.threadRefsAtom)) ??
1794 + source;
1795 navigation.navigate("Thread", {
1792 - environmentId: String(props.environmentId),
1793 - threadId: String(linkedThreadId),
1796 + environmentId: String(target.environmentId),
1797 + threadId: String(target.threadId),
1798 });
1799 return;
1800 }
apps/web/src/components/chat/MarkdownThreadLink.tsx
+17 -5
@@ -1,10 +1,14 @@
1 import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";
2 import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
3 -import { formatThreadLink, percentDecodedThreadLinkId } from "@t3tools/shared/threadLinks";
3 +import {
4 + formatThreadLink,
5 + percentDecodedThreadLinkId,
6 + resolveThreadLinkRef,
7 +} from "@t3tools/shared/threadLinks";
8 import { Link } from "@tanstack/react-router";
9 import { MessageSquareTextIcon } from "lucide-react";
10
7 -import { useProject, useThreadShell } from "../../state/entities";
11 +import { useProject, useThreadRefs, useThreadShell } from "../../state/entities";
12 import { ProjectFavicon } from "../ProjectFavicon";
13
14 export function MarkdownThreadLink(props: {
@@ -17,16 +21,24 @@ export function MarkdownThreadLink(props: {
21 const decoded = useThreadShell(
22 written === null && decodedId !== null ? scopeThreadRef(props.environmentId, decodedId) : null,
23 );
20 - const thread = written ?? decoded;
24 + const local = written ?? decoded;
25 + const refs = useThreadRefs(local === null);
26 + const remote = useThreadShell(
27 + local === null
28 + ? resolveThreadLinkRef(scopeThreadRef(props.environmentId, props.threadId), refs)
29 + : null,
30 + );
31 + const thread = local ?? remote;
32 + const environmentId = thread?.environmentId ?? props.environmentId;
33 const threadId = thread?.id ?? props.threadId;
34 const project = useProject(
23 - thread === null ? null : scopeProjectRef(props.environmentId, thread.projectId),
35 + thread === null ? null : scopeProjectRef(environmentId, thread.projectId),
36 );
37 const title = thread?.title.trim() || props.label;
38 return (
39 <Link
40 to="/$environmentId/$threadId"
29 - params={{ environmentId: props.environmentId, threadId }}
41 + params={{ environmentId, threadId }}
42 title={thread === null ? "Thread no longer available" : project?.title}
43 data-markdown-copy={formatThreadLink(threadId, title)}
44 >
apps/web/src/state/entities.ts
+2 -2
@@ -79,8 +79,8 @@ export function setActiveEnvironmentId(environmentId: EnvironmentId | null): voi
79 appAtomRegistry.set(activeEnvironmentIdAtom, environmentId);
80 }
81
82 -export function useThreadRefs(): ReadonlyArray<ScopedThreadRef> {
83 - return useAtomValue(environmentThreadShells.threadRefsAtom);
82 +export function useThreadRefs(enabled = true): ReadonlyArray<ScopedThreadRef> {
83 + return useAtomValue(enabled ? environmentThreadShells.threadRefsAtom : EMPTY_THREAD_REFS_ATOM);
84 }
85
86 export function useEnvironmentThreadRefs(
docs/orchestration-v2/orchestrator-mcp-server.md
+4 -3
@@ -375,9 +375,10 @@ Actor and ingress are separate so agent-authored user-role messages remain
375 distinguishable from human-authored messages.
376
377 Agents mention another thread as `[title](t3-thread://v1/<threadId>)`. The
378 -link carries only the id, which resolves in the environment of the message that
379 -holds it. Clients show the thread's current title rather than the label, so a
380 -rename never leaves a stale link.
378 +link carries only the id. Clients first resolve it in the message's environment,
379 +then use a unique match in another enabled environment. Ambiguous matches stay
380 +unresolved. Web and desktop show the resolved thread’s current title. Mobile
381 +relabels local matches; cross-environment links can retain the written label.
382
383 List and read results report `snoozed` and `snoozedUntil`, and
384 `t3_thread_list` filters on `snoozed`. The server's `isSnoozed` follows the
packages/shared/src/threadLinks.test.ts
+50 -1
@@ -1,6 +1,55 @@
1 import { describe, expect, it } from "vite-plus/test";
2 +import { EnvironmentId, ThreadId } from "@t3tools/contracts";
3
3 -import { formatThreadLink, parseThreadLinkHref, relabelThreadLinks } from "./threadLinks.ts";
4 +import {
5 + formatThreadLink,
6 + parseThreadLinkHref,
7 + relabelThreadLinks,
8 + resolveThreadLinkRef,
9 +} from "./threadLinks.ts";
10 +
11 +const ref = (environmentId: string, threadId = "chat-1") => ({
12 + environmentId: EnvironmentId.make(environmentId),
13 + threadId: ThreadId.make(threadId),
14 +});
15 +
16 +describe("thread link destinations", () => {
17 + it("prefers the local literal id, then the local decoded id, over remote matches", () => {
18 + const source = ref("local", "provider%3A1");
19 + const decoded = ref("local", "provider:1");
20 + const remote = ref("remote", "provider%3A1");
21 + expect(resolveThreadLinkRef(source, [remote, decoded, source])).toEqual(source);
22 + expect(resolveThreadLinkRef(source, [remote, decoded])).toEqual(decoded);
23 + });
24 +
25 + it("opens the unique matching chat in another environment", () => {
26 + const destination = ref("remote");
27 + expect(resolveThreadLinkRef(ref("local"), [ref("local", "other-chat"), destination])).toEqual(
28 + destination,
29 + );
30 + });
31 +
32 + it("preserves a remote literal id and decodes only when that id is absent", () => {
33 + const source = ref("local", "provider%3A1");
34 + const literal = ref("remote", "provider%3A1");
35 + const decoded = ref("other-remote", "provider:1");
36 + expect(resolveThreadLinkRef(source, [decoded, literal])).toEqual(literal);
37 + expect(resolveThreadLinkRef(source, [decoded])).toEqual(decoded);
38 + });
39 +
40 + it("leaves ambiguous or missing destinations unresolved", () => {
41 + const source = ref("local", "provider%3A1");
42 + const literal = ref("remote", "provider%3A1");
43 + const decoded = ref("remote", "provider:1");
44 + expect(
45 + resolveThreadLinkRef(source, [literal, ref("other-remote", literal.threadId), decoded]),
46 + ).toBeNull();
47 + expect(
48 + resolveThreadLinkRef(source, [decoded, ref("other-remote", decoded.threadId)]),
49 + ).toBeNull();
50 + expect(resolveThreadLinkRef(source, [ref("remote", "other-chat")])).toBeNull();
51 + });
52 +});
53
54 describe("thread links", () => {
55 it("takes the thread id verbatim, percent escapes included", () => {
packages/shared/src/threadLinks.ts
+25 -1
@@ -1,4 +1,4 @@
1 -import { ThreadId } from "@t3tools/contracts";
1 +import { ThreadId, type ScopedThreadRef } from "@t3tools/contracts";
2 import * as Option from "effect/Option";
3 import * as Schema from "effect/Schema";
4
@@ -25,6 +25,30 @@ export function percentDecodedThreadLinkId(threadId: ThreadId): ThreadId | null
25 }
26 }
27
28 +export function resolveThreadLinkRef(
29 + source: ScopedThreadRef,
30 + refs: ReadonlyArray<ScopedThreadRef>,
31 +): ScopedThreadRef | null {
32 + const decodedId = percentDecodedThreadLinkId(source.threadId);
33 + const ids = decodedId === null ? [source.threadId] : [source.threadId, decodedId];
34 + for (const threadId of ids) {
35 + const local = refs.find(
36 + (ref) => ref.environmentId === source.environmentId && ref.threadId === threadId,
37 + );
38 + if (local) return local;
39 + }
40 + for (const threadId of ids) {
41 + let match: ScopedThreadRef | null = null;
42 + for (const ref of refs) {
43 + if (ref.threadId !== threadId) continue;
44 + if (match !== null) return null;
45 + match = ref;
46 + }
47 + if (match !== null) return match;
48 + }
49 + return null;
50 +}
51 +
52 export function formatThreadLink(threadId: string, label: string): string {
53 const cleaned = label
54 .replace(/[[\]\\\r\n]/g, " ")