Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Recover unfinished Chinese action announcements in API-model turns
focuspoints4e7199b744f2
diff --git a/server/drivers/chat-announcement.ts b/server/drivers/chat-announcement.tsnew file mode 100644index 0000000000..a855d2a3d5--- /dev/null+++ b/server/drivers/chat-announcement.ts@@ -0,0 +1,30 @@+import { blankCode } from "../../shared/skill-command.ts";++const CHINESE_WAIT = /(?:确认|確認|授权|授權|批准|同意|许可|許可)之?[后後]|(?:等(?:待)?|待)[你您]|(?:需要|请|請|须|須)[你您]先?(?:确认|確認|授权|授權|批准|同意)/u;++function announcesChineseAction(prose: string): boolean {+ const tail = prose.trim().split(/\n\s*\n/).at(-1)!.trim();+ if (tail.length > 400) return false;+ const opening = /^(?:(?:好的|收到)[,,。]\s*)?(?:(?:接下[来來]|下一步)[,,]?\s*)?(?:我(?:[会會将將]|先|[现現]在|[马馬]上|立刻)|[让讓]我)(?:[会會将將]|先|立即|直接|就|去|[来來]|[开開]始){0,3}\s*/u.exec(tail);+ if (!opening) return false;+ const action = tail.slice(opening[0].length);+ const match = /^(?:在[^。!??,、\n]{1,40}?(?:里|裡|中|上))?(?:打[开開]|開啟|[读讀]取|查[询詢看找]|[检檢]查|[执執]行|[运運]行|[创創]建|生成|整理|保存|[写寫]入|搜[索尋]|[获獲]取|[调調]用|[处處]理|核[对對实實]|[制製]作|建立|更新|拉取|同步|导出|匯出|汇总|彙總|[发發]送|把[^。!??\n]{1,160}?(?:放[到进進入]|做成|整理|保存|[写寫]入|[制製]作|生成|汇总|彙總))/u.exec(action);+ return Boolean(match && !/^[了过過完]/u.test(action.slice(match[0].length)));+}++export function announcesAction(text: string): boolean {+ const reply = text.trim();+ if (!reply || reply.length > 4_000 || reply.includes("?")) return false;+ if (/[?\p{Script=Han}]/u.test(reply)) {+ const prose = blankCode(text);+ if (prose.includes("?") || CHINESE_WAIT.test(prose)) return false;+ if (announcesChineseAction(prose)) return true;+ }+ if (reply.length > 400) {+ const tail = reply.split(/\n\s*\n/).at(-1)!.trim();+ return tail.length <= 400 && /^(?:let me|i['\u2019]ll|i will|i(?:['\u2019]m| am) going to)\s+(?:now\s+)?(?:execute|send|type|press|launch|open|check|inspect|read|fetch|run|create|write|verify)\b/i.test(tail);+ }+ return /(?:[:\u2014\u2013]|\.\.\.|\u2026)$/.test(reply) ||+ /^(?:checking|let me(?! know\b)|i'll|i will|i'm going to|i am going to|opening|pulling|looking|searching|navigating|reading|fetching|loading|now (?:i'll|let me|opening|checking|pulling|reading))\b/i.test(reply) ||+ /^i(?:['\u2019]m| am)\b[^.!?\n]*\band (?:i )?will\s+(?:launch|open|check|pull|look|search|navigate|read|fetch|load|run|inspect)\b/i.test(reply);+}diff --git a/server/drivers/openai-chat-announcement.test.ts b/server/drivers/openai-chat-announcement.test.tsindex 792a9401b4..df51d7d0f7 100644--- a/server/drivers/openai-chat-announcement.test.ts+++ b/server/drivers/openai-chat-announcement.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from "vitest";-import { announcesAction } from "./openai-chat.ts";+import { announcesAction } from "./chat-announcement.ts";describe("announcesAction", () => {it.each([@@ -13,6 +13,41 @@ describe("announcesAction", () => {expect(announcesAction(text)).toBe(true);});+ it.each([+ "我会把 Google Tasks 里的未完成事项和已同步的日历节点放到同一个看板,分开显示截止日、评审和无日期待办。",+ "我先查看文件:",+ "我现在去核对运行记录。",+ "我将在内置浏览器里打开页面。",+ "我會先查詢三台電腦,再製作看板。",+ "我會開啟瀏覽器。",+ "好的,我先读取文件。",+ "当前只拿到了任务编号。\n\n我会读取工具回执。",+ "I'll run `grep '错误?' app.log`.",+ "我会运行 `grep '错误?' app.log`。",+ `${"上次只拿到了任务编号,不能据此判断完成。".repeat(30)}\n\n接下來我會讀取工具回執。`,+ ])("recognizes a Chinese action announcement: %s", text => {+ expect(announcesAction(text)).toBe(true);+ });++ it.each([+ "我会先读取文件,你要哪个版本?",+ "我先查看文件,可以吗?…",+ "我会在你确认后执行。",+ "我會等你授權後再執行。",+ "我会说明如何创建看板。",+ "我已经生成看板。",+ "我先检查了文件,确认没有问题。",+ "我会在获得你的明确许可后执行命令。",+ "我会先执行命令,但需要你先授权。",+ "我会用一个例子解释如何创建看板。打开设置,点击新建即可。",+ " 我会先运行命令。",+ `${"先前检查的实际结果如下。".repeat(50)}\n\n 我会先运行命令。`,+ "> 我会读取文件。",+ `检查已完成。${"这里是核对结果。".repeat(70)}\n\n检查结果:`,+ ])("does not nudge Chinese questions, waits, quotes or final replies: %s", text => {+ expect(announcesAction(text)).toBe(false);+ });+it("recognizes Qwen's next action after an explanation of the missing terminal output", () => {expect(announcesAction("The screenshot shows the terminal is open with a blank prompt, but I don't see the expected output text from the file creation and readback commands. The terminal appears to have been launched fresh, and the command to create the file and read it back hasn't executed yet or hasn't been completed.\n\nI need to explicitly send a command to the terminal to create the file and then read it back. Since the terminal is running with PID 171, I'll send commands through it.\n\nLet me execute the commands: create the file with the required content and then cat it to verify.")).toBe(true);});diff --git a/server/drivers/openai-chat-tools.test.ts b/server/drivers/openai-chat-tools.test.tsindex f543ff5a73..04696d101e 100644--- a/server/drivers/openai-chat-tools.test.ts+++ b/server/drivers/openai-chat-tools.test.ts@@ -164,6 +164,30 @@ async function fixture(script: Script, provider: Provider = "openai-compat", apidescribe("bounded action announcement recovery", () => {const later = `${"The terminal output is absent; the launch receipt only confirms the process. ".repeat(7)}\n\nLet me execute the commands to create the file and read it back.`;+ it.each(["我会先运行命令,保存并核对回执。", "我會先執行命令,保存並核對回執。"])("continues a Chinese announcement into one real tool effect: %s", async (announcement) => {+ const f = await fixture((_body, response, round) => {+ if (round === 1) answer(response, announcement);+ else if (round === 2) sse(response, [chunk({ tool_calls: [toolCall()] }, "tool_calls")]);+ else answer(response, "回执已保存并核对。");+ });+ await f.start({ approvalMode: "full" });+ expect(await f.completed()).toMatchObject({ ok: true });+ expect(f.requests).toHaveLength(3);+ expect(f.effects()).toHaveLength(1);+ });++ it.each([+ "我会先执行命令,你确认吗?…",+ "我会在收到你的许可后发送邮件。",+ "我先检查了文件,确认没有问题。",+ ])("does not continue a Chinese clarification, approval wait, or completed report: %s", async (reply) => {+ const f = await fixture((_body, response) => answer(response, reply));+ await f.start({ approvalMode: "ask" });+ expect(await f.completed()).toMatchObject({ ok: true });+ expect(f.requests).toHaveLength(1);+ expect(f.effects()).toEqual([]);+ });+it("recovers a later long announcement after the first nudge and preserves earlier results", async () => {const f = await fixture((_body, response, round) => {if (round === 1) answer(response, "I'll open the terminal.");diff --git a/server/drivers/openai-chat.ts b/server/drivers/openai-chat.tsindex 3afc3a1fd0..fef87eb3ac 100644--- a/server/drivers/openai-chat.ts+++ b/server/drivers/openai-chat.ts@@ -35,6 +35,7 @@ import { toolSchemaProfileFor } from "../tool-schema-profile.ts";import { classifyContinuable, writeTurnHandoff } from "../turn-continuation.ts";import { KEY_REJECTED_REASON, keyRejected, noteKeyAccepted, noteKeyRejected, rejectsKey } from "../key-rejections.ts";import { FETCH_LIMIT_MS, fetchPastLimit } from "./openai-chat-fetch.ts";+import { announcesAction } from "./chat-announcement.ts";export interface OpenAIChatMessage {role: "system" | "user" | "assistant" | "tool";@@ -186,18 +187,6 @@ function replayDelivered(const CORRECTIVE_ROUND = "[OpenMausBot: a tool call in this turn failed (its result is marked ok:false). Re-run the failed operations with corrected inputs where possible, check the results, then give your final answer. Do not report results you did not get.]";const NUDGE_ANNOUNCED_ACTION = "You said what you would do next but called no tool. Use your tools for only the remaining work, or reply with verified results if nothing is left to do. Never repeat an operation that succeeded, was denied, or may already have taken effect; inspect its state instead. Do not retry a destructive operation.";-export function announcesAction(text: string): boolean {- const reply = text.trim();- if (!reply || reply.length > 4_000 || reply.includes("?")) return false;- if (reply.length > 400) {- const tail = reply.split(/\n\s*\n/).at(-1)!.trim();- return tail.length <= 400 && /^(?:let me|i['\u2019]ll|i will|i(?:['\u2019]m| am) going to)\s+(?:now\s+)?(?:execute|send|type|press|launch|open|check|inspect|read|fetch|run|create|write|verify)\b/i.test(tail);- }- return /(?:[:\u2014\u2013]|\.\.\.|\u2026)$/.test(reply) ||- /^(?:checking|let me(?! know\b)|i'll|i will|i'm going to|i am going to|opening|pulling|looking|searching|navigating|reading|fetching|loading|now (?:i'll|let me|opening|checking|pulling|reading))\b/i.test(reply) ||- /^i(?:['\u2019]m| am)\b[^.!?\n]*\band (?:i )?will\s+(?:launch|open|check|pull|look|search|navigate|read|fetch|load|run|inspect)\b/i.test(reply);-}-const UNREADABLE_CALL = "[OpenMausBot: your last tool call could not be read, so nothing ran. Call the tool again using only the tools you were given, with valid JSON arguments.]";const LOCAL_CORRECTIVE_ROUNDS = 2;