graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix: do not autolink sentence-final words as domains
Cursor Agentd1ba47080e37
diff --git a/apps/native/lib/browser-links.test.ts b/apps/native/lib/browser-links.test.tsindex 3730afe9..48d9d05d 100644--- a/apps/native/lib/browser-links.test.ts+++ b/apps/native/lib/browser-links.test.ts@@ -65,6 +65,17 @@ describe("browserLinkSegments", () => {]) assert.deepEqual(browserLinkSegments(text), [{ kind: "text", value: text }]);});+ it("does not treat a missing space after a sentence period as a bare domain", () => {+ const text = "I will finish.The next step is verification.";+ assert.equal(normalizeBrowserTarget("finish.The"), null);+ assert.deepEqual(browserLinkSegments(text), [{ kind: "text", value: text }]);+ assert.deepEqual(browserLinkSegments("See example.com after finish.The check."), [+ { kind: "text", value: "See " },+ { kind: "link", label: "example.com", href: "https://example.com/" },+ { kind: "text", value: " after finish.The check." },+ ]);+ });+it("recognizes the reported local preview URL and bare IPv6 destinations exactly", () => {const url = "http://localhost:3090/visual-tests/radius-preview";assert.deepEqual(browserLinkSegments(url), [{ kind: "link", label: url, href: url }]);diff --git a/apps/native/lib/browser-links.ts b/apps/native/lib/browser-links.tsindex 85d0f28d..3a3022a4 100644--- a/apps/native/lib/browser-links.ts+++ b/apps/native/lib/browser-links.ts@@ -60,6 +60,15 @@ function looksFilelikeHostname(hostname: string, raw: string, explicit: boolean)return FILELIKE_SUFFIXES.has(labels.at(-1) ?? "");}+/** Unprefixed `word.Word` after a missing space is sentence punctuation, not a host. */+function looksSentenceHostname(raw: string, explicit: boolean): boolean {+ if (explicit || raw.toLowerCase().startsWith("www.")) return false;+ const host = raw.split(/[/:?#]/)[0] ?? raw;+ const labels = host.split(".");+ const tld = labels.at(-1) ?? "";+ return /[A-Z]/.test(tld);+}+/** Turn text that clearly names a browser destination into a safe HTTP(S) href.* Bare public hosts use HTTPS; localhost and numeric addresses use HTTP. */export function normalizeBrowserTarget(raw: string): string | null {@@ -72,7 +81,7 @@ export function normalizeBrowserTarget(raw: string): string | null {try {const url = new URL(explicit ? value : `${local ? "http" : "https"}://${value}`);if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || !url.hostname) return null;- if (!hasValidIpv4(url.hostname) || looksFilelikeHostname(url.hostname, value, explicit)) return null;+ if (!hasValidIpv4(url.hostname) || looksFilelikeHostname(url.hostname, value, explicit) || looksSentenceHostname(value, explicit)) return null;return url.href;} catch {return null;