Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(digest): never cut the turn reply inside an emoji
AdityaUmalecc3f0150be36
diff --git a/server/digest.test.ts b/server/digest.test.tsindex c4126fd681..883ab55ef2 100644--- a/server/digest.test.ts+++ b/server/digest.test.ts@@ -124,6 +124,15 @@ describe("buildTurnDigest", () => {expect(long.reply).toHaveLength(200);});+ it("never cuts the reply inside an emoji when there is no sentence end before the cap", () => {+ const reply = `${"汇".repeat(199)}🔴之后还有很多内容`;+ const d = buildTurnDigest({ ...base, reply, activities: [], memory: [] });+ expect(d.reply).toBe("汇".repeat(199));+ const loneSurrogate = /[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/;+ expect(d.reply).not.toMatch(loneSurrogate);+ expect(renderDigest(d)).not.toMatch(loneSurrogate);+ });+it("masks a credential the reply repeats, as the stored reply is masked", () => {const secret = `${"whsec" + "_"}${"a1B2c3D4".repeat(5)}`;const d = buildTurnDigest({ ...base, activities: [], memory: [], reply: `Connected the watcher to http://127.0.0.1:8800/hooks/wh_abc/${secret}. Done.` });diff --git a/server/digest.ts b/server/digest.tsindex c3a771510b..a64580dc2b 100644--- a/server/digest.ts+++ b/server/digest.ts@@ -6,6 +6,7 @@ import type { Message } from "./store.ts";import type { DigestFiles, DigestTool, HookCoverage, TurnDigest } from "../shared/digest.ts";import { redactSecretsInText } from "../shared/redact.ts";import { toolIdentity } from "../shared/tool-name.ts";+import { toolResultPrefix } from "./tool-results.ts";export type { DigestFiles, DigestTool, HookCoverage, TurnDigest } from "../shared/digest.ts";/** Evidence is observed, never inferred from a provider's brand. */@@ -99,7 +100,7 @@ function firstSentence(reply: string): string {const flat = reply.replace(/\s+/g, " ").trim();const end = flat.search(/[.!?](\s|$)/);const sentence = end === -1 ? flat : flat.slice(0, end + 1);- return sentence.slice(0, REPLY_CHARS);+ return toolResultPrefix(sentence, REPLY_CHARS);}export function renderDigest(d: TurnDigest): string {