Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Recognize CJK punctuation in auto-recall terms

focuspointsbd554ec0d053
diff --git a/server/message-db.test.ts b/server/message-db.test.ts
index 2ffab07456..5d6de448ce 100644
--- a/server/message-db.test.ts
+++ b/server/message-db.test.ts
@@ -213,6 +213,23 @@ describe("message-db", () => {
expect(recallMessages("audit", ["own-a", "own-b"])).toEqual([]);
});
+ it("recalls exact Han tokens with CJK punctuation only in the requested threads and range", () => {
+ const text = "本季度预算审批结果:已通过";
+ insertMessage("own-a", msg("m1", text, { at: 2000 }));
+ insertMessage("own-a", msg("old", text, { at: 1000 }));
+ insertMessage("other-bot", msg("private", text, { at: 2000 }));
+ insertMessage("own-a", msg("chip", text, { kind: "activity", at: 2000 }));
+
+ const recall = (query: string) => recallMessages(query, ["own-a"], 12, { since: 1500 }, "any");
+ expect(recall("本季度预算审批结果?").map((hit) => hit.messageId)).toEqual(["m1"]);
+ for (const query of ["本季度预算审批结果?", "「本季度预算审批结果」", "预算、本季度预算审批结果;进度"]) {
+ const hits = recall(query);
+ expect(hits.map((hit) => hit.messageId)).toEqual(["m1"]);
+ expect(hits[0]?.snippet).toContain("[本季度预算审批结果]");
+ }
+ expect(recallMessages("本季度预算审批结果?", [], 12, undefined, "any")).toEqual([]);
+ });
+
it("recall by time: a window on ranked hits, a newest-first listing without words", () => {
const day = 86_400_000;
const now = Date.UTC(2026, 8, 16, 12);
diff --git a/server/message-db.ts b/server/message-db.ts
index 8248994175..3377a3ceff 100644
--- a/server/message-db.ts
+++ b/server/message-db.ts
@@ -764,7 +764,7 @@ const RECALL_FILLER = new Set(
export function recallTerms(query: string): string[] {
const out: string[] = [];
- for (const raw of query.split(/\s+|(?<=\p{L})[/,;:.—–-]+(?=\p{L})/u)) {
+ for (const raw of query.split(/[\s、。!?;:,()【】《》〈〉「」『』]+|(?<=\p{L})[/,;:.—–-]+(?=\p{L})/u)) {
const token = raw.replace(/"/g, "").replace(/^[\s.,;:!?()[\]{}'`“”‘’]+|[\s.,;:!?()[\]{}'`“”‘’]+$/g, "").toLowerCase();
if (token.length < 2 && !/\d/.test(token)) continue;
if (!/[\p{L}\p{N}]/u.test(token)) continue;
diff --git a/server/recall.test.ts b/server/recall.test.ts
index e01e6c5505..53dbaccfe0 100644
--- a/server/recall.test.ts
+++ b/server/recall.test.ts
@@ -26,6 +26,12 @@ describe("recall terms and query", () => {
expect(recallTerms("What is my balance, -10 or 10? Do you remember C++ v2.1!")).toEqual(["balance", "-10", "10", "c++", "v2.1"]);
});
+ it("splits selected CJK punctuation without breaking signs, symbols or versions", () => {
+ expect(recallTerms("「本季度预算审批结果?」、【采购计划】;《项目安排》:(预算,审批。进度!)-10、C++、v2.1")).toEqual([
+ "本季度预算审批结果", "采购计划", "项目安排", "预算", "审批", "进度", "-10", "c++", "v2.1",
+ ]);
+ });
+
it("drops greetings, so a hello never recalls a bot's own greeting", () => {
expect(recallTerms("Hi! Quick intro: I'm Omkar")).toEqual(["intro", "omkar"]);
expect(recallQuery("hello there, thanks!")).toBeNull();