@devries-cameron20 / t3code-1 / commits / 66ec37079a
Fork 0

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

fix(shared): hosted thread URLs inside other links stay as written (#36298)

Julius Marminge committed Nov 13, 2026 at 12:13 UTC 66ec37079a8fa14cd9a1a850a4f6fced36c459b8
2 files changed +41 -3
packages/shared/src/threadLinks.test.ts
+25
@@ -261,4 +261,29 @@ describe("hosted thread links", () => {
261 ref("there", "t:1"),
262 ]);
263 });
264 +
265 + it("leaves a hosted link that is part of another link as written", () => {
266 + const hosted = "https://app.t3.codes/threads/there/t1";
267 + const relabeled = "[There](t3-thread://v2/there/t1)";
268 + const title = titlesIn({ there: { t1: "There" } });
269 + for (const [markdown, expected] of [
270 + [`https://example.com/?next=${hosted}`],
271 + [`[Example](https://example.com/?next=${hosted})`],
272 + [`[ ${hosted} ](https://example.com)`],
273 + [`[${hosted}](<https://example.com/a b> "Title")`],
274 + [`[a](https://example.com/x_(y)) ${hosted}`, `[a](https://example.com/x_(y)) ${relabeled}`],
275 + [`(${hosted}) **${hosted}**`, `(${relabeled}) **${relabeled}**`],
276 + [`[[[ [old](${hosted})`, `[[[ ${relabeled}`],
277 + [`\\\\[old](${hosted})`, `\\\\${relabeled}`],
278 + [`\\\\\\\\[old](${hosted})`, `\\\\\\\\${relabeled}`],
279 + [`\\[old](${hosted})`, `\\[old](${relabeled})`],
280 + [`\\[ ${hosted} ](https://example.com)`, `\\[ ${relabeled} ](https://example.com)`],
281 + ["\\[old](t3-thread://v2/there/t1) \\<t3-thread://v2/there/t1>"],
282 + ] as const) {
283 + expect(relabelThreadLinks(markdown, local, title)).toBe(expected ?? markdown);
284 + expect(threadLinkRefs(markdown, local)).toEqual(
285 + expected === undefined ? [] : [ref("there", "t1")],
286 + );
287 + }
288 + });
289 });
packages/shared/src/threadLinks.ts
+16 -3
@@ -10,10 +10,23 @@ const V2_PREFIX = `${THREAD_LINK_PROTOCOL}://v2/`;
10 const HOSTED_PREFIX = `${DEFAULT_HOSTED_APP_URL}/threads/`;
11 const HOSTED_SEGMENT = "[A-Za-z0-9_%-]+";
12 const HOSTED_LINK = `${HOSTED_PREFIX.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&")}${HOSTED_SEGMENT}/${HOSTED_SEGMENT}`;
13 -// Code comes first in the alternation so a link written inside a code span or fence is skipped.
14 -// A labeled link's destination may be angle-bracketed, as CommonMark allows: [label](<href>).
13 +const THREAD_HREF = String.raw`t3-thread:\/\/v[12]\/`;
14 +// A label stops at any bracket, so a run of unclosed brackets is scanned once, not once per bracket.
15 +const LABEL = String.raw`[^[\]\n]*`;
16 +// Earlier alternatives claim text so later ones cannot match inside it: an escaped character opens
17 +// nothing, code is literal, and a link to anywhere else keeps a thread URL in its label or href.
18 const THREAD_LINK_OUTSIDE_CODE = new RegExp(
16 - String.raw`(?<fence>(\`{3,}|~{3,})[\s\S]*?(?:\2|$))|(?<span>(\`+)[^\n]*?\4)|\[(?<label>[^\]\n]*)\]\((?:<(?<angleHref>t3-thread:\/\/v[12]\/[^\s<>]+|${HOSTED_LINK})>|(?<href>t3-thread:\/\/v[12]\/[^\s>)]+|${HOSTED_LINK}))\)|<(?<autolink>t3-thread:\/\/v[12]\/[^\s<>]+|${HOSTED_LINK})>|(?<bare>${HOSTED_LINK})(?![\w%/?#-])`,
19 + [
20 + String.raw`\\[!-/:-@[-\`{-~]`,
21 + String.raw`(?<fence>(\`{3,}|~{3,})[\s\S]*?(?:\2|$))`,
22 + String.raw`(?<span>(\`+)[^\n]*?\4)`,
23 + // A labeled link's destination may be angle-bracketed, as CommonMark allows: [label](<href>).
24 + String.raw`\[(?<label>${LABEL})\]\((?:<(?<angleHref>${THREAD_HREF}[^\s<>]+|${HOSTED_LINK})>|(?<href>${THREAD_HREF}[^\s>)]+|${HOSTED_LINK}))\)`,
25 + String.raw`\[${LABEL}\]\((?:<[^<>\n]*>|[^\s()]*(?:\([^\s()]*\)[^\s()]*)*)(?:[ \t]+(?:"[^"\n]*"|'[^'\n]*'))?\)`,
26 + String.raw`<(?<autolink>${THREAD_HREF}[^\s<>]+|${HOSTED_LINK})>`,
27 + // After a URL character the hosted link is part of a longer URL, such as a redirect target.
28 + String.raw`(?<![A-Za-z0-9%/?#=&@+-])(?<bare>${HOSTED_LINK})(?![\w%/?#-])`,
29 + ].join("|"),
30 "g",
31 );
32