Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(chat): keep trailing URL punctuation outside links

vastsa413509cd2abd
diff --git a/apps/desktop/src/lib/chat-links.ts b/apps/desktop/src/lib/chat-links.ts
index fc8f10904..8dc8e2bc6 100644
--- a/apps/desktop/src/lib/chat-links.ts
+++ b/apps/desktop/src/lib/chat-links.ts
@@ -260,9 +260,9 @@ function scanUrl(text: string, start: number): string {
depth -= 1;
}
}
- // Punctuation after a parenthesized destination belongs to the sentence.
- // Preserve extensions such as "(draft).html" and existing non-parenthesized URLs.
- return text.slice(start, end).replace(/(?<=\))[.,!?;:,。!?;:]+$/u, "");
+ // Sentence punctuation belongs to the surrounding prose, regardless of
+ // whether the URL itself ends with a parenthesized path segment.
+ return text.slice(start, end).replace(/[.,!?;:,。!?;:]+$/u, "");
}
/**
diff --git a/apps/desktop/test/chat-links.test.mjs b/apps/desktop/test/chat-links.test.mjs
index 3a079dc10..baa302d98 100644
--- a/apps/desktop/test/chat-links.test.mjs
+++ b/apps/desktop/test/chat-links.test.mjs
@@ -324,17 +324,24 @@ test("a prose wrapper does not swallow the next URL or file reference", () => {
});
-test("sentence punctuation after a parenthesized URL stays outside the link", () => {
- const url = "https://en.wikipedia.org/wiki/React_(software)";
- for (const suffix of [".", ",", "!", "?", ";", ":", "。", ",", "!", "?", "..."]) {
- const source = `See ${url}${suffix}`;
- const segments = splitChatText(source, ROOT);
- assert.equal(segments.find(s => s.kind === "target").target.url, url);
- assert.equal(segments.at(-1).text, suffix);
- assert.equal(segments.map(s => s.text).join(""), source);
+test("sentence punctuation after URLs stays outside the link", () => {
+ for (const url of [
+ "https://example.com",
+ "https://en.wikipedia.org/wiki/React_(software)",
+ "https://example.com/report_(draft).html?q=(one)#part(2)",
+ ]) {
+ for (const suffix of [".", ",", "!", "?", ";", ":", "。", ",", "!", "?", "..."]) {
+ const source = `See ${url}${suffix}`;
+ const segments = splitChatText(source, ROOT);
+ assert.equal(segments.find(s => s.kind === "target").target.url, url);
+ assert.equal(segments.at(-1).text, suffix);
+ assert.equal(segments.map(s => s.text).join(""), source);
+ }
}
- const urlWithExtension = "https://example.com/report_(draft).html?q=(one)#part(2)";
- assert.equal(splitChatText(urlWithExtension, ROOT)[0].target.url, urlWithExtension);
+ assert.equal(
+ splitChatText("See https://example.com/report_(draft).html, next", ROOT)[1].target.url,
+ "https://example.com/report_(draft).html",
+ );
});
test("adjacent parenthesis-wrapped URLs all remain independently linkable", () => {