Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
ACP: keep the card's tool from the request; merge only its text, never a question's
RGB-loopa52947e7bfa7
diff --git a/server/drivers/acp/acp.test.ts b/server/drivers/acp/acp.test.tsindex 0881e9fb34..8f683a7967 100644--- a/server/drivers/acp/acp.test.ts+++ b/server/drivers/acp/acp.test.ts@@ -1689,7 +1689,7 @@ describe("ACP turns (fake CLI)", () => {it("shows the earlier tool_call on a permission request that names the call only by toolCallId", async () => {const { opened } = await permissionCard("t-acp-card-id-only", [touch], { toolCallId: "call_1" });- expect(opened).toMatchObject({ requestType: "permission", tool: "shell", summary: "touch marker" });+ expect(opened).toMatchObject({ requestType: "permission", tool: "tool", summary: "touch marker" }); // tool stays the request's: it drives policyexpect(opened).toHaveProperty("command", undefined);expect(opened).toHaveProperty("requiresExplicitApproval", undefined);});@@ -1699,7 +1699,7 @@ describe("ACP turns (fake CLI)", () => {{ sessionUpdate: "tool_call", toolCallId: "call_1", title: "Bash", kind: "execute", status: "pending" },{ sessionUpdate: "tool_call_update", toolCallId: "call_1", title: null, kind: null, rawInput: { command: "ls -la" } },], { toolCallId: "call_1", title: "Bash" });- expect(opened).toMatchObject({ tool: "shell", summary: "ls -la" });+ expect(opened).toMatchObject({ tool: "tool", summary: "ls -la" });});it("lets the permission request's own fields win over the earlier tool_call", async () => {@@ -1722,11 +1722,30 @@ describe("ACP turns (fake CLI)", () => {const shell = await permissionCard("t-acp-card-sandbox", [sandbox], { toolCallId: "call_1", kind: "execute" });expect(shell.opened).toHaveProperty("command", undefined);expect(shell.opened).toHaveProperty("requiresExplicitApproval", undefined);+ for (const kind of ["web_search", "mcp__notes__read_note"]) {+ const earlier = { sessionUpdate: "tool_call", toolCallId: "call_1", title: "lookup", kind, status: "pending", rawInput: {} };+ const card = await permissionCard(`t-acp-card-kind-${kind}`, [earlier], { toolCallId: "call_1" });+ expect(card.opened).toMatchObject({ requestType: "permission", tool: "tool", summary: "lookup" });+ }+ });++ it("keeps a question's own text when an earlier tool_call with the same id ran a command", async () => {+ const earlier = { sessionUpdate: "tool_call", toolCallId: "interaction_1", title: "bash", kind: "execute", status: "pending", rawInput: { command: "echo something" } };+ const { opened } = await permissionCard("t-acp-card-question", [earlier], { toolCallId: "interaction_1", title: "Which folder?" });+ expect(opened).toMatchObject({ requestType: "question", summary: "Which folder?" });+ });++ it("starts afresh when a new tool_call reuses a toolCallId in the same turn", async () => {+ const { opened } = await permissionCard("t-acp-card-reused-id", [+ touch,+ { sessionUpdate: "tool_call", toolCallId: "call_1", title: "read notes.md", kind: "read", status: "pending" },+ ], { toolCallId: "call_1" });+ expect(opened).toMatchObject({ tool: "tool", summary: "read notes.md" });});it("forgets a turn's tool calls when the next turn asks about the same toolCallId", async () => {const first = await permissionCard("t-acp-card-turns", [touch], { toolCallId: "call_1" });- expect(first.opened).toMatchObject({ tool: "shell", summary: "touch marker" });+ expect(first.opened).toMatchObject({ tool: "tool", summary: "touch marker" });const { turnId } = await instance.adapter.sendTurn({ threadId: "t-acp-card-turns", text: "again", cwd: scratch });const second = await recorder.until((event) => event.type === "request.opened" && event.turnId === turnId);expect(second).toMatchObject({ tool: "tool", summary: "tool" });diff --git a/server/drivers/acp/core.ts b/server/drivers/acp/core.tsindex f52cfac2b5..b6bdde14db 100644--- a/server/drivers/acp/core.ts+++ b/server/drivers/acp/core.ts@@ -589,7 +589,7 @@ export function createAcpDriver(support: AcpSupport): ProviderDriver<AcpConfig>if (!allow) missing("allow");return send({ jsonrpc: "2.0", id: msg.id, result: allow ? { outcome: { outcome: "selected", optionId: allow } } : cancelled });}- const kind = String(toolCall.kind ?? ""), shown = current.toolDetails.merged(toolCall), shownKind = String(shown.kind ?? "");+ const kind = String(toolCall.kind ?? ""), shown = isQuestion ? toolCall : current.toolDetails.merged(toolCall); // shown: card text onlyconst operationKey = isQuestion || current.controlsHost ? null : acpSessionOperationKey(toolCall);if (operationKey && acpAnswersAlone(toolCall.rawInput) && sessionAllows.get(threadId)?.has(operationKey)) {const allow = optionFor("allow");@@ -598,7 +598,7 @@ export function createAcpDriver(support: AcpSupport): ProviderDriver<AcpConfig>}}const mcpTitle = !isQuestion && !/^(?:execute|edit|delete|move)$/.test(kind) && typeof toolCall.title === "string" && /^mcp__[\w-]+__[\w.-]+$/.test(toolCall.title) ? toolCall.title : undefined; // an MCP call keeps its name, so a saved grant finds it- const tool = mcpTitle ?? (shownKind === "execute" ? "shell" : shownKind === "edit" ? "edit" : shownKind || "tool");+ const tool = mcpTitle ?? (kind === "execute" ? "shell" : kind === "edit" ? "edit" : kind || "tool");const isShellCommand = !isQuestion && kind === "execute" && !/^mcp(?:__|[.:])/i.test(String(toolCall.title ?? ""));const rawSummary = String(shown.rawInput?.command ?? shown.title ?? tool);const summary = rawSummary.slice(0, isQuestion ? MAX_QUESTION_TEXT : 200) + (!isQuestion && typeof shown.rawInput?.justification === "string" ? `\nReason: ${shown.rawInput.justification.slice(0, 300)}` : "");@@ -750,7 +750,7 @@ export function createAcpDriver(support: AcpSupport): ProviderDriver<AcpConfig>}case "tool_call": {current.flushAssistantText();- trackRunningTool(current, u, "pending"); current.toolDetails.record(u);+ trackRunningTool(current, u, "pending"); current.toolDetails.record(u, true);// ACP can send a tool_call already marked completed or failed (e.g. on a denied permission) with no// tool_call_update after it.const itemId = (typeof u.toolCallId === "string" && u.toolCallId) ? u.toolCallIddiff --git a/server/drivers/acp/tool-call-details.ts b/server/drivers/acp/tool-call-details.tsindex 75e814317e..0989628991 100644--- a/server/drivers/acp/tool-call-details.ts+++ b/server/drivers/acp/tool-call-details.ts@@ -11,18 +11,18 @@ export type ToolCallFields = { [field in (typeof FIELDS)[number]]?: any };export class ToolCallDetails {private readonly calls = new Map<string, ToolCallFields>();- /** A field left out or null keeps its earlier value. */- record(update: Record<string, any>): void {+ /** A tool_call starts the call afresh; in a tool_call_update a field left out or null keeps its earlier value. */+ record(update: Record<string, any>, isNewCall = false): void {const id = update.toolCallId;if (typeof id !== "string" || !id) return;- const known = this.calls.get(id) ?? {};+ const known = isNewCall ? {} : this.calls.get(id) ?? {};this.calls.delete(id);for (const field of FIELDS) if (update[field] !== undefined && update[field] !== null) known[field] = update[field];this.calls.set(id, known);if (this.calls.size > MAX_CALLS) this.calls.delete(this.calls.keys().next().value!);}- /** The call as known so far, with the request's own fields over it. */+ /** The call as known so far, with the request's own fields over it. For the card's text, never its policy. */merged(toolCall: Record<string, any>): ToolCallFields {const known = typeof toolCall.toolCallId === "string" ? this.calls.get(toolCall.toolCallId) : undefined;const merged: ToolCallFields = { ...known };