From 6a60b8fe1249056b8083c6649c51d89cd6fd2325 Mon Sep 17 00:00:00 2001 From: forrestlinfeng Date: Tue, 24 Nov 2026 00:11:00 +0800 Subject: [PATCH 1/4] fix(recall): end a link at the first character a URL cannot hold MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit promptTextOf drops links from the prompt before recall. The pattern ran to the next whitespace, and Chinese is written right after a link with no space, so the rest of the sentence went with the link: "官网(https://canary.evomap.work/zh)本周上线,帮我做一条 20 秒的展示视频" was recalled as "官网( 20 秒的展示视频". A link now stops at the first character RFC 3986 does not allow in a URL. Co-Authored-By: Claude Opus 5.5 --- lib/recall.js | 6 ++++-- test/recall.test.js | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/recall.js b/lib/recall.js index 5b2eed72..a3f08cfc 100644 --- a/lib/recall.js +++ b/lib/recall.js @@ -52,10 +52,12 @@ export function isPersonPrompt(origin) { // Engine reminders, task markup and links are not what the person asked: // a session notification is nothing but a ``, and a link's -// host and path words matched assets that only shared a domain. +// host and path words matched assets that only shared a domain. A link ends at +// the first character a URL cannot hold, because Chinese is written right +// after a link with no space: `官网(https://…/zh)本周上线` keeps `本周上线`. const REMINDER_BLOCK = /[\s\S]*?(?:<\/system-reminder>|$)/g; const MARKUP_TAG = /<\/?[a-z][\w-]*(?:\s[^<>]*)?>/gi; -const LINK = /\b(?:https?:\/\/|www\.)\S+/gi; +const LINK = /\b(?:https?:\/\/|www\.)[A-Za-z0-9\-._~:/?#[\]@!$&'()*+,;=%]+/gi; export function promptTextOf(text, maxChars = PROMPT_MAX_CHARS) { if (typeof text !== 'string') return ''; diff --git a/test/recall.test.js b/test/recall.test.js index a1d73785..e0fcf208 100644 --- a/test/recall.test.js +++ b/test/recall.test.js @@ -301,6 +301,15 @@ test('four steps is the least a strategy needs', async () => { assert.deepEqual((await recallStrategy(four.proxyFetch, 'add a retry to the uploader')).ids, ['sha256:four']); }); +test('a link ends where the Chinese text written right after it begins', () => { + assert.equal( + promptTextOf('我们新官网(https://canary.evomap.work/zh)本周上线,帮我做一条 20 秒的展示视频'), + '我们新官网( 本周上线,帮我做一条 20 秒的展示视频', + ); + assert.equal(promptTextOf('看 https://example.com/a?b=1,帮我总结这篇文章'), '看 ,帮我总结这篇文章'); + assert.equal(promptTextOf('参考 www.example.com/page这个页面的布局'), '参考 这个页面的布局'); +}); + test('engine reminders, markup and links are not matched, and a bare reminder recalls nothing', async () => { assert.equal( promptTextOf('Triage the open Sentry issues see https://example.sentry.io/issues/?project=1'), From 46eab582805d1fde26e22afd95cf151af7a87bee Mon Sep 17 00:00:00 2001 From: forrestlinfeng Date: Tue, 24 Nov 2026 00:47:21 +0800 Subject: [PATCH 2/4] fix(recall): keep a link's non-ASCII host and path segments where URL structure follows them MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ASCII-only link pattern stopped at the first non-ASCII character, so an IDN host (`https://例子.测试/docs`) was not removed at all. A Unicode path (`https://example.com/患者张三/病例?access_code=ABC123`) lost only its ASCII prefix, and its segments and query went into the recall text and the Hub's task context. A non-ASCII run now stays in the link when URL structure follows it: `/`, `?`, `#`, `:`, or a dot and a letter of any script. The Chinese sentence written right after a link has none of that, so it is still kept (`…/abc123/复刻一条…`, `evomap.ai这个网站`). A non-ASCII last segment with nothing after it (`/wiki/中文`) cannot be told from that sentence, and is kept as the person's text. The two alternatives use disjoint character sets, so the pattern stays linear: 200k CJK characters after a link take a few milliseconds. Co-Authored-By: Claude Opus 5.5 --- lib/recall.js | 15 +++++++++++---- test/recall.test.js | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/recall.js b/lib/recall.js index a3f08cfc..c38540fd 100644 --- a/lib/recall.js +++ b/lib/recall.js @@ -52,12 +52,19 @@ export function isPersonPrompt(origin) { // Engine reminders, task markup and links are not what the person asked: // a session notification is nothing but a ``, and a link's -// host and path words matched assets that only shared a domain. A link ends at -// the first character a URL cannot hold, because Chinese is written right -// after a link with no space: `官网(https://…/zh)本周上线` keeps `本周上线`. +// host and path words matched assets that only shared a domain. Chinese is +// written right after a link with no space, so a link ends where its ASCII URL +// characters do: `官网(https://…/zh)本周上线` keeps `本周上线`. A non-ASCII run +// stays in the link only where URL structure follows it (`/`, `?`, `#`, `:`, or +// a dot and a letter of any script): an IDN host `例子.测试/docs` or a path segment +// `/患者/病例?id=1` goes with the link, and its path or query never reaches the +// Hub. A non-ASCII last segment with nothing after it, `/wiki/中文`, cannot be +// told from the sentence that follows a link, and is kept as the person's text. const REMINDER_BLOCK = /[\s\S]*?(?:<\/system-reminder>|$)/g; const MARKUP_TAG = /<\/?[a-z][\w-]*(?:\s[^<>]*)?>/gi; -const LINK = /\b(?:https?:\/\/|www\.)[A-Za-z0-9\-._~:/?#[\]@!$&'()*+,;=%]+/gi; +const URL_ASCII_RUN = "[A-Za-z0-9\\-._~:/?#[\\]@!$&'()*+,;=%]+"; +const URL_NON_ASCII_SEGMENT = '[^\\x00-\\x7F\\s\\u3000-\\u303F\\uFF00-\\uFFEF]+(?=[/?#:]|\\.[\\p{L}\\p{N}])'; +const LINK = new RegExp(`\\b(?:https?:\\/\\/|www\\.)(?:${URL_ASCII_RUN}|${URL_NON_ASCII_SEGMENT})+`, 'giu'); export function promptTextOf(text, maxChars = PROMPT_MAX_CHARS) { if (typeof text !== 'string') return ''; diff --git a/test/recall.test.js b/test/recall.test.js index e0fcf208..bf2859ce 100644 --- a/test/recall.test.js +++ b/test/recall.test.js @@ -310,6 +310,21 @@ test('a link ends where the Chinese text written right after it begins', () => { assert.equal(promptTextOf('参考 www.example.com/page这个页面的布局'), '参考 这个页面的布局'); }); +test('a link keeps a non-ASCII host or path segment that URL structure follows, so its path and query never reach the Hub', () => { + assert.equal(promptTextOf('分析 https://example.com/患者张三/病例?access_code=ABC123 并给建议'), '分析 并给建议'); + assert.equal(promptTextOf('阅读 https://例子.测试/docs 并总结'), '阅读 并总结'); + assert.equal(promptTextOf('打开 https://例子.测试/文档.html 看看'), '打开 看看'); + assert.equal(promptTextOf('照着这个视频https://v.douyin.com/abc123/复刻一条我们瑜伽App的版本'), '照着这个视频 复刻一条我们瑜伽App的版本'); + assert.equal(promptTextOf('看下https://evomap.ai这个网站'), '看下 这个网站'); + assert.equal(promptTextOf('阅读 https://zh.wikipedia.org/wiki/中文'), '阅读 中文', 'a last segment with nothing after it reads as the sentence'); +}); + +test('a long non-ASCII run after a link is cleaned in linear time', () => { + const started = performance.now(); + promptTextOf(`https://a.com/${'中'.repeat(200_000)}`); + assert.ok(performance.now() - started < 1_000); +}); + test('engine reminders, markup and links are not matched, and a bare reminder recalls nothing', async () => { assert.equal( promptTextOf('Triage the open Sentry issues see https://example.sentry.io/issues/?project=1'), From 74a294c55e70c7e889d4322f17318e1065e9df55 Mon Sep 17 00:00:00 2001 From: forrestlinfeng Date: Tue, 24 Nov 2026 00:53:23 +0800 Subject: [PATCH 3/4] fix(recall): take an IDN host whole, so a link ending in a Unicode TLD leaves nothing behind MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `https://例子.测试` and `https://sub.例子.测试` left their last label in the recall text: after the host there was no `/`, `?` or `.` to keep it in the link. The host is now matched on its own as dot-joined labels of any script, so an IDN host goes whole. A single label is only ASCII, so a Chinese sentence written right after an ASCII host (`https://evomap.ai这个网站`) is still kept. Co-Authored-By: Claude Opus 5.5 --- lib/recall.js | 22 ++++++++++++++-------- test/recall.test.js | 5 +++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/recall.js b/lib/recall.js index c38540fd..cddf749c 100644 --- a/lib/recall.js +++ b/lib/recall.js @@ -53,18 +53,24 @@ export function isPersonPrompt(origin) { // Engine reminders, task markup and links are not what the person asked: // a session notification is nothing but a ``, and a link's // host and path words matched assets that only shared a domain. Chinese is -// written right after a link with no space, so a link ends where its ASCII URL -// characters do: `官网(https://…/zh)本周上线` keeps `本周上线`. A non-ASCII run -// stays in the link only where URL structure follows it (`/`, `?`, `#`, `:`, or -// a dot and a letter of any script): an IDN host `例子.测试/docs` or a path segment +// written right after a link with no space, so a link ends where its URL +// characters do: `官网(https://…/zh)本周上线` keeps `本周上线`. A host may be an +// IDN of dot-joined labels in any script, `sub.例子.测试`, and goes whole; a +// single label is only ASCII, so `https://evomap.ai这个网站` keeps `这个网站`. +// After the host, a non-ASCII run stays in the link only where URL structure +// follows it (`/`, `?`, `#`, `:`, or a dot and a letter of any script): a path // `/患者/病例?id=1` goes with the link, and its path or query never reaches the -// Hub. A non-ASCII last segment with nothing after it, `/wiki/中文`, cannot be -// told from the sentence that follows a link, and is kept as the person's text. +// Hub. A non-ASCII last path segment with nothing after it, `/wiki/中文`, +// cannot be told from the sentence that follows a link, and is kept as the +// person's text. const REMINDER_BLOCK = /[\s\S]*?(?:<\/system-reminder>|$)/g; const MARKUP_TAG = /<\/?[a-z][\w-]*(?:\s[^<>]*)?>/gi; +const NON_ASCII_RUN = '[^\\x00-\\x7F\\s\\u3000-\\u303F\\uFF00-\\uFFEF]+'; +const HOST_LABEL = `(?:[A-Za-z0-9-]+|${NON_ASCII_RUN})`; +const DOTTED_HOST = `${HOST_LABEL}(?:\\.${HOST_LABEL})+`; const URL_ASCII_RUN = "[A-Za-z0-9\\-._~:/?#[\\]@!$&'()*+,;=%]+"; -const URL_NON_ASCII_SEGMENT = '[^\\x00-\\x7F\\s\\u3000-\\u303F\\uFF00-\\uFFEF]+(?=[/?#:]|\\.[\\p{L}\\p{N}])'; -const LINK = new RegExp(`\\b(?:https?:\\/\\/|www\\.)(?:${URL_ASCII_RUN}|${URL_NON_ASCII_SEGMENT})+`, 'giu'); +const URL_NON_ASCII_SEGMENT = `${NON_ASCII_RUN}(?=[/?#:]|\\.[\\p{L}\\p{N}])`; +const LINK = new RegExp(`\\b(?:https?:\\/\\/|www\\.)(?:${DOTTED_HOST})?(?:${URL_ASCII_RUN}|${URL_NON_ASCII_SEGMENT})*`, 'giu'); export function promptTextOf(text, maxChars = PROMPT_MAX_CHARS) { if (typeof text !== 'string') return ''; diff --git a/test/recall.test.js b/test/recall.test.js index bf2859ce..99e20cf5 100644 --- a/test/recall.test.js +++ b/test/recall.test.js @@ -313,6 +313,10 @@ test('a link ends where the Chinese text written right after it begins', () => { test('a link keeps a non-ASCII host or path segment that URL structure follows, so its path and query never reach the Hub', () => { assert.equal(promptTextOf('分析 https://example.com/患者张三/病例?access_code=ABC123 并给建议'), '分析 并给建议'); assert.equal(promptTextOf('阅读 https://例子.测试/docs 并总结'), '阅读 并总结'); + assert.equal(promptTextOf('访问 https://例子.测试'), '访问'); + assert.equal(promptTextOf('参考 https://sub.例子.测试,然后总结'), '参考 ,然后总结'); + assert.equal(promptTextOf('打开 www.例子.测试 看看'), '打开 看看'); + assert.equal(promptTextOf('跑 http://localhost:3000/api 看看'), '跑 看看'); assert.equal(promptTextOf('打开 https://例子.测试/文档.html 看看'), '打开 看看'); assert.equal(promptTextOf('照着这个视频https://v.douyin.com/abc123/复刻一条我们瑜伽App的版本'), '照着这个视频 复刻一条我们瑜伽App的版本'); assert.equal(promptTextOf('看下https://evomap.ai这个网站'), '看下 这个网站'); @@ -322,6 +326,7 @@ test('a link keeps a non-ASCII host or path segment that URL structure follows, test('a long non-ASCII run after a link is cleaned in linear time', () => { const started = performance.now(); promptTextOf(`https://a.com/${'中'.repeat(200_000)}`); + promptTextOf(`https://${'中.'.repeat(50_000)}`); assert.ok(performance.now() - started < 1_000); }); From a791c742998c2d0389de563bb6c1cf84cb695370 Mon Sep 17 00:00:00 2001 From: forrestlinfeng Date: Tue, 24 Nov 2026 00:58:39 +0800 Subject: [PATCH 4/4] fix(recall): keep a Unicode query value or fragment in the link MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `?q=患者张三` and `#章节名称` at the end of a link were cut after `=` or `#`, and the value went into the recall text. A non-ASCII run right after `=`, `?`, `#` or `&` is a query value or fragment and stays in the link. Text after an ASCII value (`?b=1帮我总结`) is still the person's. Co-Authored-By: Claude Opus 5.5 --- lib/recall.js | 15 ++++++++------- test/recall.test.js | 3 +++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/recall.js b/lib/recall.js index cddf749c..105d96b0 100644 --- a/lib/recall.js +++ b/lib/recall.js @@ -57,19 +57,20 @@ export function isPersonPrompt(origin) { // characters do: `官网(https://…/zh)本周上线` keeps `本周上线`. A host may be an // IDN of dot-joined labels in any script, `sub.例子.测试`, and goes whole; a // single label is only ASCII, so `https://evomap.ai这个网站` keeps `这个网站`. -// After the host, a non-ASCII run stays in the link only where URL structure -// follows it (`/`, `?`, `#`, `:`, or a dot and a letter of any script): a path -// `/患者/病例?id=1` goes with the link, and its path or query never reaches the -// Hub. A non-ASCII last path segment with nothing after it, `/wiki/中文`, -// cannot be told from the sentence that follows a link, and is kept as the -// person's text. +// After the host, a non-ASCII run stays in the link where it is a query value +// or fragment (right after `=`, `?`, `#` or `&`: `?q=中文`, `#章节`) or where URL +// structure follows it (`/`, `?`, `#`, `:`, or a dot and a letter of any +// script): a path `/患者/病例?id=1` goes with the link, and its path or query +// never reaches the Hub. A non-ASCII last path segment with nothing after it, +// `/wiki/中文`, cannot be told from the sentence that follows a link, and is +// kept as the person's text. const REMINDER_BLOCK = /[\s\S]*?(?:<\/system-reminder>|$)/g; const MARKUP_TAG = /<\/?[a-z][\w-]*(?:\s[^<>]*)?>/gi; const NON_ASCII_RUN = '[^\\x00-\\x7F\\s\\u3000-\\u303F\\uFF00-\\uFFEF]+'; const HOST_LABEL = `(?:[A-Za-z0-9-]+|${NON_ASCII_RUN})`; const DOTTED_HOST = `${HOST_LABEL}(?:\\.${HOST_LABEL})+`; const URL_ASCII_RUN = "[A-Za-z0-9\\-._~:/?#[\\]@!$&'()*+,;=%]+"; -const URL_NON_ASCII_SEGMENT = `${NON_ASCII_RUN}(?=[/?#:]|\\.[\\p{L}\\p{N}])`; +const URL_NON_ASCII_SEGMENT = `(?:(?<=[=?#&])${NON_ASCII_RUN}|${NON_ASCII_RUN}(?=[/?#:]|\\.[\\p{L}\\p{N}]))`; const LINK = new RegExp(`\\b(?:https?:\\/\\/|www\\.)(?:${DOTTED_HOST})?(?:${URL_ASCII_RUN}|${URL_NON_ASCII_SEGMENT})*`, 'giu'); export function promptTextOf(text, maxChars = PROMPT_MAX_CHARS) { diff --git a/test/recall.test.js b/test/recall.test.js index 99e20cf5..d75d0b54 100644 --- a/test/recall.test.js +++ b/test/recall.test.js @@ -314,6 +314,9 @@ test('a link keeps a non-ASCII host or path segment that URL structure follows, assert.equal(promptTextOf('分析 https://example.com/患者张三/病例?access_code=ABC123 并给建议'), '分析 并给建议'); assert.equal(promptTextOf('阅读 https://例子.测试/docs 并总结'), '阅读 并总结'); assert.equal(promptTextOf('访问 https://例子.测试'), '访问'); + assert.equal(promptTextOf('搜 https://example.com/search?q=患者张三 看结果'), '搜 看结果'); + assert.equal(promptTextOf('跳到 https://example.com/doc#章节名称,再总结'), '跳到 ,再总结'); + assert.equal(promptTextOf('看 https://example.com/a?b=1帮我总结'), '看 帮我总结'); assert.equal(promptTextOf('参考 https://sub.例子.测试,然后总结'), '参考 ,然后总结'); assert.equal(promptTextOf('打开 www.例子.测试 看看'), '打开 看看'); assert.equal(promptTextOf('跑 http://localhost:3000/api 看看'), '跑 看看');