From 8c8ebdf10c4cf2c702539a57efbbaec4d016ff8c Mon Sep 17 00:00:00 2001 From: Elliot Drel Date: Wed, 4 Nov 2026 01:24:57 -0500 Subject: [PATCH 01/41] fix(shared): preserve code shielding and titled Markdown links --- packages/shared/src/threadLinks.test.ts | 15 +++++++++++++++ packages/shared/src/threadLinks.ts | 8 ++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/shared/src/threadLinks.test.ts b/packages/shared/src/threadLinks.test.ts index e8ced79531f0a..3af0194ec9dfa 100644 --- a/packages/shared/src/threadLinks.test.ts +++ b/packages/shared/src/threadLinks.test.ts @@ -178,6 +178,21 @@ describe("thread links", () => { }); describe("hosted thread links", () => { + it("does not consume a code span's opening backtick as an ordinary link label", () => { + const markdown = "[before `](https://example.com) https://app.t3.codes/threads/one/same`"; + expect(relabelThreadLinks(markdown, local, () => "Title")).toBe(markdown); + expect(threadLinkRefs(markdown, local)).toEqual([]); + }); + + it.each(['"title"', "'title'", "(title)"])( + "leaves a link with Markdown title %s intact", + (title) => { + const markdown = `[label](https://app.t3.codes/threads/one/same ${title})`; + expect(relabelThreadLinks(markdown, local, () => "Title")).toBe(markdown); + expect(threadLinkRefs(markdown, local)).toEqual([]); + }, + ); + it("escapes every id character a sentence or path could claim, and reads it back", () => { const thread = ref("env.1", "thread:delegated/mcp%3A1."); const link = hostedThreadLink(thread); diff --git a/packages/shared/src/threadLinks.ts b/packages/shared/src/threadLinks.ts index 9085f8725a939..4f5ffc5fe306a 100644 --- a/packages/shared/src/threadLinks.ts +++ b/packages/shared/src/threadLinks.ts @@ -14,7 +14,7 @@ const HOSTED_LINK = `${HOSTED_PREFIX.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&")}${H // Every inline link is taken whole, so a hosted URL in another link's label or href stays as written. // Neither part may hold `[`, which keeps the scan linear: no match attempt runs past the next `[`. const THREAD_LINK_OUTSIDE_CODE = new RegExp( - String.raw`(?(\`{3,}|~{3,})[\s\S]*?(?:\2|$))|(?(\`+)[^\n]*?\4)|\[(?