Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(acp,routines): forward non-shell rawInput, resolve generic MCP outbound checks, and preserve held reason on timeout
Will Ren65780d818f68
diff --git a/packages/phone-protocol/src/outbound.ts b/packages/phone-protocol/src/outbound.tsindex a0f57d2060..d6accf6368 100644--- a/packages/phone-protocol/src/outbound.ts+++ b/packages/phone-protocol/src/outbound.ts@@ -90,15 +90,29 @@ export function isReadOnlyTool(name: string): boolean {/** The built-in agents server's X research tools only read X: x_post reads a post, it does not post one. */const AGENTS_X_READS = /^(?:mcp__agents__|agents__|agents_)?x_(?:search|user_posts|post|profile)$/;+const GENERIC_SUMMARY_MCP = /^Run\s+(mcp_[A-Za-z0-9_.:-]+)\b/i;++/** Resolves the underlying MCP tool name when an ACP driver reports `tool: "other"` with `summary: "Run mcp_..."`. */+export function effectiveToolName(name: string, summary?: string): string {+ const trimmed = name.trim();+ if (trimmed && trimmed.toLowerCase() !== "other") return name;+ if (summary) {+ const match = GENERIC_SUMMARY_MCP.exec(summary.trim());+ if (match?.[1]) return match[1];+ }+ return name;+}+/** Does this tool send something to someone, or move money? */-export function isOutboundTool(name: string): boolean {+export function isOutboundTool(name: string, summary?: string): boolean {+ const resolved = effectiveToolName(name, summary);// A raw API call from the workbench can do anything an app tool can, and// nothing here can read which; it is treated as a send.- if (name === "COMPOSIO_PROXY_EXECUTE" || RAW_API_ACTION.test(name)) return true;- if (AGENTS_X_READS.test(name)) return false;- const tokens = actionTokens(name);+ if (resolved === "COMPOSIO_PROXY_EXECUTE" || resolved.endsWith("_COMPOSIO_PROXY_EXECUTE") || RAW_API_ACTION.test(resolved)) return true;+ if (AGENTS_X_READS.test(resolved)) return false;+ const tokens = actionTokens(resolved);if (tokens.length === 0) return false;- if (isReadOnlyTool(name)) return false;+ if (isReadOnlyTool(resolved)) return false;if (tokens.some((token) => SEND_VERBS.has(token))) return true;if (tokens.includes("DRAFT")) return false;return tokens.some((token) => CREATE_VERBS.has(token)) && tokens.some((token) => SENT_NOUNS.has(token));diff --git a/packages/phone-protocol/src/runtime-events.ts b/packages/phone-protocol/src/runtime-events.tsindex ccfde4896f..d7be3e5fde 100644--- a/packages/phone-protocol/src/runtime-events.ts+++ b/packages/phone-protocol/src/runtime-events.ts@@ -147,6 +147,8 @@ export type RuntimeEvent = RuntimeEventBase &/** The files a read tool's ask reads (absolute): a request that reads only the bot's own files is answered* without the person. Like `command`, never broadcast. */reads?: string[];+ /** Raw structured tool input forwarded by ACP drivers for non-question permission prompts; never broadcast. */+ rawInput?: unknown;choices?: string[];/** A provider's structured ask (Claude's AskUserQuestion): the whole* set of questions, each with its own options, so the card can offer@@ -180,6 +182,8 @@ export type RuntimeEvent = RuntimeEventBase &* was already gone and the action never ran */source: "user" | "auto" | "timeout" | "system" | "unavailable" | "peer";approvalScope?: "local-computer";+ /** Optional reason attached to the approval card while waiting, preserved on timeout. */+ heldReason?: string;}| {type: "thread.token-usage.updated"; input: number; output: number; cachedInput?: number;diff --git a/server/auto-approve.ts b/server/auto-approve.tsindex 4461f92b02..8027fb3ab5 100644--- a/server/auto-approve.ts+++ b/server/auto-approve.ts@@ -103,6 +103,8 @@ export function autoVerdict(toolAllowed?: boolean;/** The request only reads the bot's own files: its SOUL.md, skills, memory and conversation folders. */ownFilesRead?: boolean;+ /** Optional prompt summary used to resolve generic ACP tool placeholders such as `tool: "other"`. */+ summary?: string;},): AutoVerdict {if (ASKS_A_PERSON.has(bareToolName(tool))) {@@ -111,7 +113,7 @@ export function autoVerdict(// Full's promise is literal, sandbox widening included; entering Full is consent-gated by the bot PATCH endpoint.if (mode === "full") return { approve: `approved ${tool} (full access)`, source: "full-access" };if (context?.requiresExplicitApproval) return { approve: null, source: "explicit-approval-block" };- if (isOutboundTool(tool)) return { approve: null, source: "outbound-guard" };+ if (isOutboundTool(tool, context?.summary)) return { approve: null, source: "outbound-guard" };if (context?.commandAllowed) return { approve: `approved ${tool} (saved command)`, source: "command-allowlist" };if (context?.toolAllowed) return { approve: `approved ${tool} (always allowed)`, source: "tool-allowlist" };if (context?.ownFilesRead) return { approve: `approved ${tool} (its own files)`, source: "own-files" };diff --git a/server/drivers/acp/core.ts b/server/drivers/acp/core.tsindex 21d6a96a32..376f580835 100644--- a/server/drivers/acp/core.ts+++ b/server/drivers/acp/core.ts@@ -688,7 +688,7 @@ export function createAcpDriver(support: AcpSupport): ProviderDriver<AcpConfig>choices: askQuestions?.[0]?.options.map(option => option.label) ?? (isQuestion ? questionChoices : undefined),...(askQuestions ? { questions: askQuestions } : {}),approvalScope: current.controlsHost ? "local-computer" : undefined,- allowSession: !isQuestion && !current.controlsHost ? true : undefined,+ allowSession: !isQuestion && !current.controlsHost ? true : undefined, ...(!isQuestion && toolCall.rawInput !== undefined ? { rawInput: toolCall.rawInput } : {}),});};diff --git a/server/drivers/antigravity-native-cli.test.ts b/server/drivers/antigravity-native-cli.test.tsindex aa4458ba4c..64ea5c31aa 100644--- a/server/drivers/antigravity-native-cli.test.ts+++ b/server/drivers/antigravity-native-cli.test.ts@@ -606,13 +606,13 @@ describe.skipIf(WINDOWS)("a native CLI set as the engine's own path", () => {const first = await recorder.until((event) => event.turnId === turnId && (event.type === "request.opened" || event.type === "turn.completed"));if (first.type === "request.opened") await instance.adapter.respondToRequest(name, (first as { requestId: string }).requestId, { behavior: "deny" });await recorder.until((event) => event.type === "turn.completed" && event.turnId === turnId);- const opened = recorder.events.find((event) => event.type === "request.opened") as { commandLine?: string } | undefined;- return { card: opened !== undefined, commandLine: opened?.commandLine, answer: readFileSync(answer, "utf8") };+ const opened = recorder.events.find((event) => event.type === "request.opened") as { commandLine?: string; rawInput?: unknown } | undefined;+ return { card: opened !== undefined, commandLine: opened?.commandLine, rawInput: opened?.rawInput, answer: readFileSync(answer, "utf8") };}it("answers a file edit inside the turn's folder itself on Auto-accept edits", async () => {expect(await asked("edits-inside", "edits", (directory) => ({ kind: "edit", title: "Edit notes.md", locations: [{ path: join(directory, "notes.md") }] })))- .toEqual({ card: false, commandLine: undefined, answer: "allow-once" });+ .toEqual({ card: false, commandLine: undefined, rawInput: undefined, answer: "allow-once" });expect(await asked("edits-new-folder", "edits", (directory) => ({ kind: "edit", title: "Edit", locations: [{ path: join(directory, "new", "deep", "notes.md") }] }))).toMatchObject({ card: false, answer: "allow-once" });}, 90_000);@@ -642,4 +642,9 @@ describe.skipIf(WINDOWS)("a native CLI set as the engine's own path", () => {expect(await asked("full-other-kind", "full", () => ({ kind: "other", rawInput: { CommandLine: "rm -rf ~" }, title: "Tool" }))).toMatchObject({ card: true, commandLine: "rm -rf ~" });}, 90_000);+ it("forwards structured rawInput on non-shell ACP permission prompts", async () => {+ const raw = { pid: 100, steps: [{ tool: "click", args: { x: 10, y: 20 } }] };+ expect(await asked("full-non-shell-raw", "full", () => ({ kind: "other", rawInput: raw, title: "Run mcp_computer_run_steps" })))+ .toMatchObject({ card: true, commandLine: undefined, rawInput: raw });+ }, 90_000);});diff --git a/server/index.ts b/server/index.tsindex 6062126e74..4ce56f3876 100644--- a/server/index.ts+++ b/server/index.ts@@ -49,7 +49,7 @@ import { signInCardResumePrompt, signInCardWaits, signInOutcome } from "../shareimport { createRoomTurnLevels } from "./room-turn-level.ts";import { createSignInSettle } from "./host/sign-in-settle.ts"; import { createNoTerminal } from "./host/no-terminal.ts"; import { createPlaceMoves, type ComputerSelection } from "./host/place-move.ts"; import { createPersonLanguages, THIS_COMPUTER } from "./host/person-languages.ts"; import "./server-line-packs.ts"; import { conversationLanguage, serverLine, setConversationLanguage } from "./server-lines.ts";import { RoomMemberLock } from "./room-member-lock.ts";-import { approvalHeldNote, approvalHeldReason, approvalModeForOrigin, autoVerdict, deliverFullAccessApproval, undeliveredApprovalTool } from "./auto-approve.ts"; import { readsOwnFiles } from "./own-file-reads.ts";+import { approvalHeldNote, approvalHeldReason, approvalModeForOrigin, autoVerdict, deliverFullAccessApproval, undeliveredApprovalTool } from "./auto-approve.ts"; import { readsOwnFiles } from "./own-file-reads.ts"; import { recordHeldReason, withHeldReason } from "./routine-held-reasons.ts";import { bindSafetyFloor, denyAtSafetyFloor, heldAtSafetyFloor, safetyFloorOn } from "./safety-floor-gate.ts";import { CommandAllowlistStore, commandAllowlistCandidate } from "./command-allowlist.ts";import { providerMcpTool, providerToolAllowKey, providerToolConfig, savedToolGrant } from "./provider-tool-allow.ts";@@ -6303,10 +6303,10 @@ bus.subscribe((event: RuntimeEvent) => {const privateImageEvent = event.type === "item.completed" && event.itemType === "assistant_image";if (!privateImageEvent) {// Exact executable input is internal; the bus's persistence redactor does not scrub the live event.- const publicEvent = event.type === "request.opened" ? { ...event, command: undefined, commandLine: undefined, reads: undefined } : publicReplyEvent(event, groupSpeakers.get(event.threadId)?.botId);+ const publicEvent = event.type === "request.opened" ? { ...event, command: undefined, commandLine: undefined, reads: undefined, rawInput: undefined } : publicReplyEvent(event, groupSpeakers.get(event.threadId)?.botId);broadcast({ kind: "runtime", event: publicEvent });}- if (event.type === "turn.completed") { const note = runComputers.turnEnded(event.threadId, event.ok); if (note) store.appendMessage(event.threadId, { role: "bot", kind: "activity", tool: { name: `recovery: ${note}`, ok: true } }); } const routineRun = privateImageEvent ? null : (routines?.handleRuntimeEvent(event) ?? null);+ if (event.type === "turn.completed") { const note = runComputers.turnEnded(event.threadId, event.ok); if (note) store.appendMessage(event.threadId, { role: "bot", kind: "activity", tool: { name: `recovery: ${note}`, ok: true } }); } const routineRun = privateImageEvent ? null : (routines?.handleRuntimeEvent(withHeldReason(event)) ?? null);const replayed = savedSteps.dispatch.answering(event); limitClock.noteRuntimeEvent(replayed ? undefined : runningTurnEngines.get(event.threadId)?.instanceId, event);const ownerBot = store.botByThread(event.threadId); // A quick route's model is the one this turn ran on, so its holds and its working turns are that model's.const bot = ownerBot ? botForThread(ownerBot.id, event.threadId) ?? undefined : undefined; if (bot && !replayed) limitTakeover.noteRuntimeEvent(bot.id, { ...bot.modelSelection, model: quickFallback.routedModel(event.threadId) ?? bot.modelSelection.model }, event);@@ -6459,7 +6459,7 @@ bus.subscribe((event: RuntimeEvent) => {? heldAtSafetyFloor(event, autoVerdict(effectiveApprovalMode, event.tool, {requiresExplicitApproval: event.requiresExplicitApproval,commandAllowed: Boolean(command && commandAllowlist.matches(asker.id, command)),- toolAllowed: savedToolGrant(toolAllowKey, asker.alwaysAllow, store.bot(asker.id)?.alwaysAllow), ownFilesRead: !guestDriven && !linkHeld && readsOwnFiles(DATA_DIR, asker.id, event), // never in a guest's turn: the folder holds its owner's memory+ summary: event.summary, toolAllowed: savedToolGrant(toolAllowKey, asker.alwaysAllow, store.bot(asker.id)?.alwaysAllow), ownFilesRead: !guestDriven && !linkHeld && readsOwnFiles(DATA_DIR, asker.id, event), // never in a guest's turn: the folder holds its owner's memory})): null;// Claude accepts --permission-mode auto for any model but silently starts in Manual where auto is unavailable (Haiku 4.5, Sonnet 4.5, an org that disabled it).@@ -6541,7 +6541,7 @@ bus.subscribe((event: RuntimeEvent) => {: "Your bot has a question",...runtimeRequestCardFields(event, {permission, guestDriven, commandAllowlist: command ?? undefined, allowKey: toolAllowKey ?? undefined,- held: approvalHeldReason(heldContext) ?? (permission && guestDriven && routineRun ? confinedWhy(event.threadId) : undefined),+ held: recordHeldReason(event.threadId, event.requestId, approvalHeldReason(heldContext) ?? (permission && guestDriven && routineRun ? confinedWhy(event.threadId) : undefined)),heldCode: approvalHeldNote(heldContext),}),},diff --git a/server/routine-held-reasons.ts b/server/routine-held-reasons.tsnew file mode 100644index 0000000000..a8aeadf269--- /dev/null+++ b/server/routine-held-reasons.ts@@ -0,0 +1,28 @@+import type { RuntimeEvent } from "../shared/runtime-events.ts";++const MAX_HELD_REASONS = 500;+const heldReasonsByRequest = new Map<string, string>();++/** Records why an approval card was held so routine timeouts can surface that reason later. Returns `reason`. */+export function recordHeldReason(threadId: string, requestId: string | undefined, reason: string | undefined): string | undefined {+ if (!requestId || !reason) return reason;+ if (heldReasonsByRequest.size >= MAX_HELD_REASONS) {+ const oldest = heldReasonsByRequest.keys().next().value;+ if (oldest !== undefined) heldReasonsByRequest.delete(oldest);+ }+ heldReasonsByRequest.set(`${threadId}:${requestId}`, reason);+ return reason;+}++/** Attaches and clears any recorded held reason when a permission request resolves. */+export function withHeldReason<T extends RuntimeEvent>(event: T): T {+ if (event.type !== "request.resolved" || !event.requestId) return event;+ const key = `${event.threadId}:${event.requestId}`;+ const heldReason = heldReasonsByRequest.get(key);+ heldReasonsByRequest.delete(key);+ return heldReason ? { ...event, heldReason } : event;+}++export function clearHeldReasons(): void {+ heldReasonsByRequest.clear();+}diff --git a/server/routine-waits.test.ts b/server/routine-waits.test.tsnew file mode 100644index 0000000000..7d74db3bc8--- /dev/null+++ b/server/routine-waits.test.ts@@ -0,0 +1,61 @@+import { beforeEach, describe, expect, it } from "vitest";++import { clearHeldReasons, recordHeldReason, withHeldReason } from "./routine-held-reasons.ts";+import { settleAsk } from "./routine-waits.ts";+import type { RoutineRun } from "./routines.ts";++describe("routine-waits heldReason propagation", () => {+ beforeEach(() => {+ clearHeldReasons();+ });++ it("keeps the plain timeout error when no held reason was recorded", () => {+ const run = {+ asked: { requestId: "req-1", approval: true, subject: "for “Run mcp_computer_run_steps”", since: 1_000 },+ waitedMs: 0,+ } as RoutineRun;+ const resolved = withHeldReason({+ eventId: "e1",+ provider: "antigravityAgent",+ threadId: "t-1",+ createdAt: "2026-11-26T00:00:00Z",+ type: "request.resolved",+ requestId: "req-1",+ behavior: "deny",+ source: "timeout",+ });+ expect(settleAsk(run, resolved, 2_000)).toBe("Stopped: nobody answered the approval for “Run mcp_computer_run_steps”");+ });++ it("preserves the approval card held reason on routine timeout and clears it afterwards", () => {+ recordHeldReason("t-2", "req-2", "This sends something on your behalf, so it asks you first.");+ const run = {+ asked: { requestId: "req-2", approval: true, subject: "for “Run mcp_composio_GMAIL_SEND_EMAIL”", since: 1_000 },+ waitedMs: 0,+ } as RoutineRun;+ const resolved = withHeldReason({+ eventId: "e2",+ provider: "antigravityAgent",+ threadId: "t-2",+ createdAt: "2026-11-26T00:00:00Z",+ type: "request.resolved",+ requestId: "req-2",+ behavior: "deny",+ source: "timeout",+ });+ expect(settleAsk(run, resolved, 5_000)).toBe(+ "Stopped: nobody answered the approval for “Run mcp_composio_GMAIL_SEND_EMAIL” (This sends something on your behalf, so it asks you first.)",+ );+ const repeat = withHeldReason({+ eventId: "e3",+ provider: "antigravityAgent",+ threadId: "t-2",+ createdAt: "2026-11-26T00:01:00Z",+ type: "request.resolved",+ requestId: "req-2",+ behavior: "deny",+ source: "timeout",+ });+ expect(repeat.heldReason).toBeUndefined();+ });+});diff --git a/server/routine-waits.ts b/server/routine-waits.tsindex cc1d51cbf6..f3ddb8faa4 100644--- a/server/routine-waits.ts+++ b/server/routine-waits.ts@@ -53,7 +53,7 @@ export function settleAsk(run: RoutineRun, event: Resolved | undefined, now: numif (!ask || (event && ask.requestId && event.requestId && event.requestId !== ask.requestId)) return null;run.waitedMs = (run.waitedMs ?? 0) + Math.max(0, now - ask.since);delete run.asked;- return ask.approval && event?.source === "timeout" ? `Stopped: nobody answered the approval ${ask.subject}` : null;+ return ask.approval && event?.source === "timeout" ? `Stopped: nobody answered the approval ${ask.subject}${event.heldReason ? ` (${event.heldReason})` : ""}` : null;}/** Time the run has worked: waiting on the person never counts toward its limit. */diff --git a/shared/outbound.test.ts b/shared/outbound.test.tsindex 5a05dfc929..66e676df92 100644--- a/shared/outbound.test.ts+++ b/shared/outbound.test.ts@@ -1,6 +1,6 @@import { describe, expect, it } from "vitest";-import { connectorCallsIn, effectiveOutboundPolicy, isOutboundTool, isReadOnlyTool, normalizeOutboundPolicy, outboundCallsIn, trimOutboundPolicy } from "./outbound.ts";+import { connectorCallsIn, effectiveOutboundPolicy, effectiveToolName, isOutboundTool, isReadOnlyTool, normalizeOutboundPolicy, outboundCallsIn, trimOutboundPolicy } from "./outbound.ts";describe("isOutboundTool", () => {it("flags tools that send, reply, post, publish, invite, share, or move money", () => {@@ -210,4 +210,11 @@ describe("outboundCallsIn", () => {expect(outboundCallsIn("GMAIL_FETCH_EMAILS", {})).toEqual([]);expect(isOutboundTool("COMPOSIO_PROXY_EXECUTE")).toBe(true);});+ it("resolves generic ACP tool placeholders from Run mcp_* summaries", () => {+ expect(effectiveToolName("other", "Run mcp_composio_GMAIL_SEND_EMAIL")).toBe("mcp_composio_GMAIL_SEND_EMAIL");+ expect(effectiveToolName("bash", "Run mcp_composio_GMAIL_SEND_EMAIL")).toBe("bash");+ expect(isOutboundTool("other", "Run mcp_composio_GMAIL_SEND_EMAIL")).toBe(true);+ expect(isOutboundTool("other", "Run mcp_composio_COMPOSIO_PROXY_EXECUTE")).toBe(true);+ expect(isOutboundTool("other", "Run mcp_computer_click")).toBe(false);+ });});