Skip to content

Commit 167ae67

Browse files
shivamhwpclaude
andcommitted
fix(clients): keep hosted links for ids Markdown would mangle
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4c4c913 commit 167ae67

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

‎packages/shared/src/composerContextReferences.test.ts‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -521,21 +521,24 @@ describe("threadLinkContextReferences", () => {
521521
() => "Here",
522522
);
523523
expect(pasted.records).toEqual([copied, threadContextRecord(thread("env-9", "t9"), "Here")]);
524-
for (const [environmentId, threadId, carried] of [
525-
["env-1", "a)b", true],
526-
["env-1", "a b", true],
527-
["env-1", "a>b", true],
528-
["env-1", "a%29b", true],
529-
["env-1", "..", true],
530-
["source/machine", "t1", true],
524+
for (const [environmentId, threadId, form] of [
525+
["env-1", "a)b", "https://"],
526+
["env-1", "a(b", "https://"],
527+
["env-1", "a b", "https://"],
528+
["env-1", "a>b", "https://"],
529+
["env-1", "a\\!b", "https://"],
530+
["env-1", "a%29b", "t3-thread://"],
531+
["env-1", "..", "t3-thread://"],
532+
["source/machine", "t1", "https://"],
531533
// No link form carries both: a hosted URL drops the dot segment.
532-
[".", "a b", false],
534+
[".", "a b", null],
533535
] as const) {
534536
const record = threadContextRecord(thread(environmentId, threadId), "Copied title");
535537
const link = unreadableThreadContextLink(record);
536-
if (!carried) expect(link).toBe("Copied title");
538+
if (form === null) expect(link).toBe("Copied title");
539+
else expect(link).toContain(`](${form}`);
537540
expect(threadLinkContextReferences(link, [], () => undefined).records).toEqual(
538-
carried ? [record] : [],
541+
form === null ? [] : [record],
539542
);
540543
}
541544
expect(

‎packages/shared/src/composerContextReferences.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ export function threadContextsOutsideEnvironment(input: {
434434

435435
/** A thread this agent can't read stays a link naming its machine, so the ids survive without attaching it. */
436436
export function unreadableThreadContextLink(record: ThreadContextRecord): string {
437-
// Ids may hold `/`, `)`, spaces or be dot segments, which some link forms lose; keep a form that parses back.
438437
const namesRecord = (markdown: string) => {
439438
let links = 0;
440439
let exact = false;
@@ -446,7 +445,9 @@ export function unreadableThreadContextLink(record: ThreadContextRecord): string
446445
return links === 1 && exact;
447446
};
448447
const link = formatThreadLink(record, record.title);
449-
if (namesRecord(link)) return link;
448+
// Markdown mangles a v2 link with these characters; `/` and dot segments are caught by parsing back.
449+
if (!/[\s()<>\\]/.test(`${record.environmentId}/${record.threadId}`) && namesRecord(link))
450+
return link;
450451
try {
451452
const hosted = formatHostedThreadLink(record, record.title);
452453
if (namesRecord(hosted)) return hosted;

0 commit comments

Comments
 (0)