diff --git a/electron/cua.mjs b/electron/cua.mjs index 50c035c9f2d..7724a2de4f4 100644 --- a/electron/cua.mjs +++ b/electron/cua.mjs @@ -83,6 +83,12 @@ export function setCuaStateListener(listener) { stateListener = typeof listener === "function" ? listener : () => {}; } +function persistAndNotify(next) { + const connection = connectionStore.persist(next); + stateListener(connection); + return connection; +} + export function resolveDriverBinary() { if (process.env.CUA_DRIVER_PATH) return process.env.CUA_DRIVER_PATH; if (app.isPackaged) { @@ -124,6 +130,29 @@ async function loadEmbeddedSdk() { return import(pathToFileURL(path.join(process.resourcesPath, "cua-sdk", "cua-sdk.mjs")).href); } +async function attachStandalone() { + const driver = fs.existsSync(INSTALLED_DRIVER) ? INSTALLED_DRIVER : null; + if (!driver) return null; + if (!(await socketAlive(STANDALONE_SOCKET))) { + // Launch CuaDriver.app through LaunchServices so Accessibility / + // Screen Recording stay on com.trycua.driver — the identity this + // machine already granted — instead of the freshly signed OpenMausBot. + spawnSync("open", ["-a", "CuaDriver"], { timeout: 8000 }); + for (let i = 0; i < 25; i++) { + if (await socketAlive(STANDALONE_SOCKET)) break; + await new Promise((resolve) => setTimeout(resolve, 200)); + } + } + if (!(await socketAlive(STANDALONE_SOCKET))) return null; + return { + mode: "standalone", + socketPath: STANDALONE_SOCKET, + mcpCommand: driver, + mcpArgs: ["mcp"], + mcpEnv: { ...CUA_ENV }, + }; +} + async function startEmbedded(binary) { // Import from the staged Resources tree in production. The app intentionally // excludes general node_modules, so a bare package import only works in dev. @@ -139,22 +168,33 @@ async function startEmbedded(binary) { ].filter(Boolean).join(" and "); throw new Error(`${missing || "macOS permissions"} required; grant access in System Settings and restart OpenMausBot`); } - embeddedHost = new sdk.EmbeddedCuaDriverHost(binary, HOST_BUNDLE_ID); - const conn = await embeddedHost.start(); - return { - mode: "embedded", - socketPath: conn.socketPath, - mcpCommand: binary, - mcpArgs: ["mcp", "--embedded", "--socket", conn.socketPath], - mcpEnv: { ...CUA_ENV, CUA_DRIVER_EMBEDDED: "1", CUA_DRIVER_HOST_BUNDLE_ID: HOST_BUNDLE_ID }, - }; + const host = new sdk.EmbeddedCuaDriverHost(binary, HOST_BUNDLE_ID); + try { + const conn = await host.start(); + embeddedHost = host; + return { + mode: "embedded", + socketPath: conn.socketPath, + mcpCommand: binary, + mcpArgs: ["mcp", "--embedded", "--socket", conn.socketPath], + mcpEnv: { ...CUA_ENV, CUA_DRIVER_EMBEDDED: "1", CUA_DRIVER_HOST_BUNDLE_ID: HOST_BUNDLE_ID }, + }; + } catch (err) { + try { + await host.stop(); + } catch { + // startup already failed; stop is best-effort before destroy + } + host.uniffiDestroy?.(); + throw err; + } } export async function startCua() { if (process.platform === "linux") return ensureLinuxRuntime().initialize(); const binary = resolveDriverBinary(); if (!binary) { - return connectionStore.persist({ + return persistAndNotify({ mode: "unavailable", reason: "cua-driver binary not found", }); @@ -168,10 +208,13 @@ export async function startCua() { try { nextConnection = await startEmbedded(binary); } catch (err) { - nextConnection = { - mode: "unavailable", - reason: `embedded host failed: ${err?.message ?? err}`, - }; + nextConnection = await attachStandalone(); + if (!nextConnection) { + nextConnection = { + mode: "unavailable", + reason: `embedded host failed: ${err?.message ?? err}`, + }; + } } } else if (await socketAlive(STANDALONE_SOCKET)) { // Dev machine with CuaDriver.app's daemon already running. @@ -190,7 +233,7 @@ export async function startCua() { }; } - return connectionStore.persist(nextConnection); + return persistAndNotify(nextConnection); } export function cuaPermissionsStatus() { @@ -227,7 +270,7 @@ export async function stopCua() { embeddedHost = null; } if (connectionStore.get()) { - connectionStore.persist({ mode: "unavailable", reason: "desktop-host-stopped" }); + persistAndNotify({ mode: "unavailable", reason: "desktop-host-stopped" }); } } @@ -262,6 +305,27 @@ export function registerCuaIpc() { return ensureLinuxRuntime().getStatus(); }); ipcMain.handle("cua:linux-retry", async () => { + if (process.platform === "darwin") { + try { + await stopCua(); + const connection = await startCua(); + const ready = connection?.mode === "embedded" || connection?.mode === "standalone"; + return { + enabled: ready, + status: ready ? "ready" : "error", + reasonCode: ready ? undefined : "permissions-required", + message: connection?.reason, + }; + } catch (error) { + console.error("[cua] macOS retry failed:", error); + return { + enabled: false, + status: "error", + reasonCode: "permissions-required", + message: error instanceof Error ? error.message : String(error), + }; + } + } if (process.platform !== "linux") { return { enabled: false, status: "unavailable", reasonCode: "unsupported-platform" }; } diff --git a/electron/main.mjs b/electron/main.mjs index 0b1df61872e..d5e2363b7be 100644 --- a/electron/main.mjs +++ b/electron/main.mjs @@ -668,6 +668,7 @@ ipcMain.handle("perm:open-settings", (_event, pane) => { mic: "Privacy_Microphone", screen: "Privacy_ScreenCapture", speech: "Privacy_SpeechRecognition", + accessibility: "Privacy_Accessibility", }; // own-property lookup only — a renderer-supplied "__proto__"/"constructor" // would otherwise resolve up the prototype chain to a truthy object diff --git a/scripts/cua-mac-arches.mjs b/scripts/cua-mac-arches.mjs new file mode 100644 index 00000000000..3a52d147e6f --- /dev/null +++ b/scripts/cua-mac-arches.mjs @@ -0,0 +1,24 @@ +export const DEFAULT_MAC_ARCHES = ["arm64", "x64"]; + +/** Which darwin CUA trees to stage. electron-builder packages both arches + * unless the caller opts into a one-arch local stage. An empty override + * is never a silent no-op. */ +export function resolveCuaMacArches(env = process.env) { + const raw = env.OPENMAUSBOT_CUA_ARCHES; + if (raw === undefined) return [...DEFAULT_MAC_ARCHES]; + const arches = raw.split(",").map((arch) => arch.trim()).filter(Boolean); + if (arches.length === 0) { + throw new Error( + "OPENMAUSBOT_CUA_ARCHES is empty; omit the variable to stage arm64 and x64", + ); + } + if (env.OPENMAUSBOT_CUA_ARCHES_PARTIAL !== "1") { + const missing = DEFAULT_MAC_ARCHES.filter((arch) => !arches.includes(arch)); + if (missing.length) { + throw new Error( + `OPENMAUSBOT_CUA_ARCHES omits ${missing.join(", ")} but electron-builder packages both arm64 and x64. Set OPENMAUSBOT_CUA_ARCHES_PARTIAL=1 for a one-arch local stage.`, + ); + } + } + return arches; +} diff --git a/scripts/cua-mac-arches.test.mjs b/scripts/cua-mac-arches.test.mjs new file mode 100644 index 00000000000..f2573ee74bb --- /dev/null +++ b/scripts/cua-mac-arches.test.mjs @@ -0,0 +1,24 @@ +import { describe, expect, it } from "vitest"; +import { DEFAULT_MAC_ARCHES, resolveCuaMacArches } from "./cua-mac-arches.mjs"; + +describe("resolveCuaMacArches", () => { + it("defaults to both packaging targets", () => { + expect(resolveCuaMacArches({})).toEqual(DEFAULT_MAC_ARCHES); + }); + + it("rejects an empty override even when PARTIAL=1", () => { + expect(() => resolveCuaMacArches({ OPENMAUSBOT_CUA_ARCHES: "", OPENMAUSBOT_CUA_ARCHES_PARTIAL: "1" })).toThrow( + /OPENMAUSBOT_CUA_ARCHES is empty/, + ); + expect(() => resolveCuaMacArches({ OPENMAUSBOT_CUA_ARCHES: " , ", OPENMAUSBOT_CUA_ARCHES_PARTIAL: "1" })).toThrow( + /OPENMAUSBOT_CUA_ARCHES is empty/, + ); + }); + + it("rejects a one-arch override unless PARTIAL=1", () => { + expect(() => resolveCuaMacArches({ OPENMAUSBOT_CUA_ARCHES: "arm64" })).toThrow(/omits x64/); + expect(resolveCuaMacArches({ OPENMAUSBOT_CUA_ARCHES: "arm64", OPENMAUSBOT_CUA_ARCHES_PARTIAL: "1" })).toEqual([ + "arm64", + ]); + }); +}); diff --git a/scripts/prepare-cua.mjs b/scripts/prepare-cua.mjs index 4b00f79dbab..0a25a8cab0f 100644 --- a/scripts/prepare-cua.mjs +++ b/scripts/prepare-cua.mjs @@ -11,6 +11,7 @@ import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; import { promisify } from "node:util"; import { build } from "esbuild"; +import { resolveCuaMacArches } from "./cua-mac-arches.mjs"; if (process.platform !== "darwin") throw new Error("prepare-cua is macOS-only"); @@ -107,7 +108,7 @@ if (!details.isFile() || (details.mode & 0o111) === 0) { // not on a user's Intel Mac); the SDK's dylib/.node are genuinely per-arch, // pulled from the two darwin native packages that pnpm installs because of // supportedArchitectures in package.json. -const MAC_ARCHES = ["arm64", "x64"]; +const MAC_ARCHES = resolveCuaMacArches(process.env); const { stdout: archList } = await run("/usr/bin/lipo", ["-archs", binary]); for (const arch of MAC_ARCHES) { diff --git a/server/auto-approve.test.ts b/server/auto-approve.test.ts index a015b60bdae..17bad4eb816 100644 --- a/server/auto-approve.test.ts +++ b/server/auto-approve.test.ts @@ -112,9 +112,16 @@ describe("autoDecision", () => { expect(autoDecision({ alwaysAllow: ["Bash"] }, "Bash", "sudo rm -rf /var")).toBeNull(); }); - it("never delegates a local-computer request to auto or remembered grants", () => { + it("auto-approves a local-computer request when Auto mode is on", () => { + expect( + autoDecision({ autoApprove: true }, "mcp__computer__click", "Click the Submit button", { + scope: "local-computer", + }), + ).toBe("auto-approved mcp__computer__click"); + }); + + it("does not let always-allow cover host control without Auto mode", () => { const bot = { - autoApprove: true, alwaysAllow: ["mcp__computer__click", "local-computer:mcp__computer__click"], }; expect( diff --git a/server/auto-approve.ts b/server/auto-approve.ts index a90b2074404..bf83565fad1 100644 --- a/server/auto-approve.ts +++ b/server/auto-approve.ts @@ -144,11 +144,10 @@ export function autoVerdict( if (sensitive) return { approve: null, source: "sensitive-guard", rule: sensitive }; return { approve: null, source: "no-grant" }; } - if (context?.scope === "local-computer") { - // The user's active desktop is never delegated to bot auto mode or a - // remembered cloud/tool grant in the Linux beta. Same attribution rule - // as the unattended block: a guard that would have carded anyway keeps - // its own name, the block is the story only when it changed the outcome. + if (context?.scope === "local-computer" && !bot.autoApprove) { + // Host control is not covered by a remembered always-allow grant. + // After the Auto-on-this-computer warning, unclassified GUI actions + // (click/type) may auto-approve; destructive/sensitive still card. if (grant) return { approve: null, source: "local-computer-block", rule: grant.rule }; if (destructive) return { approve: null, source: "destructive-guard", rule: destructive }; if (sensitive) return { approve: null, source: "sensitive-guard", rule: sensitive }; diff --git a/server/drivers/acp/kimi.ts b/server/drivers/acp/kimi.ts index a3d2a3759af..43d3d1fa6d4 100644 --- a/server/drivers/acp/kimi.ts +++ b/server/drivers/acp/kimi.ts @@ -69,21 +69,28 @@ function stripTomlLineComment(line: string): string { return line; } -/** Decode a TOML basic-string escape at `text[i]` (`i` points at the `\\`). */ -function takeTomlBasicEscape(text: string, i: number): { value: string; next: number } { +/** Decode a TOML basic-string escape at `text[i]` (`i` points at the `\\`). + * Invalid / unknown / surrogate / out-of-range sequences return ok:false so + * the heading is not canonicalized to a colliding alias. */ +function takeTomlBasicEscape( + text: string, + i: number, +): { ok: true; value: string; next: number } | { ok: false } { const code = text[i + 1]; + if (code === undefined) return { ok: false }; if (code === "u") { const hex = text.slice(i + 2, i + 6); - if (/^[0-9a-fA-F]{4}$/.test(hex)) { - return { value: String.fromCharCode(parseInt(hex, 16)), next: i + 6 }; - } + if (!/^[0-9a-fA-F]{4}$/.test(hex)) return { ok: false }; + const point = parseInt(hex, 16); + if (point >= 0xd800 && point <= 0xdfff) return { ok: false }; + return { ok: true, value: String.fromCharCode(point), next: i + 6 }; } if (code === "U") { const hex = text.slice(i + 2, i + 10); - if (/^[0-9a-fA-F]{8}$/.test(hex)) { - const point = parseInt(hex, 16); - return { value: point <= 0x10ffff ? String.fromCodePoint(point) : "", next: i + 10 }; - } + if (!/^[0-9a-fA-F]{8}$/.test(hex)) return { ok: false }; + const point = parseInt(hex, 16); + if (point > 0x10ffff || (point >= 0xd800 && point <= 0xdfff)) return { ok: false }; + return { ok: true, value: String.fromCodePoint(point), next: i + 10 }; } const named: Record = { b: "\b", @@ -94,7 +101,8 @@ function takeTomlBasicEscape(text: string, i: number): { value: string; next: nu '"': '"', "\\": "\\", }; - return { value: named[code ?? ""] ?? code ?? "", next: i + 2 }; + if (!(code in named)) return { ok: false }; + return { ok: true, value: named[code]!, next: i + 2 }; } /** Canonical `a.b.c` form of a `[table]` heading, quotes and comments removed. */ @@ -117,6 +125,7 @@ function canonicalizeTomlHeading(heading: string): string | null { while (i < inner.length && inner[i] !== q) { if (q === '"' && inner[i] === "\\") { const taken = takeTomlBasicEscape(inner, i); + if (!taken.ok) return null; value += taken.value; i = taken.next; continue; @@ -185,6 +194,11 @@ function tomlTables(text: string): Array<{ name: string; headingStart: number; b continue; } if (mode === "basic") { + if (text[i] === "\n") { + mode = "out"; + i += 1; + continue; + } if (text[i] === "\\") { i += 2; continue; @@ -194,6 +208,11 @@ function tomlTables(text: string): Array<{ name: string; headingStart: number; b continue; } if (mode === "literal") { + if (text[i] === "\n") { + mode = "out"; + i += 1; + continue; + } if (text[i] === "'") mode = "out"; i += 1; continue; diff --git a/server/drivers/claude-catalog.test.ts b/server/drivers/claude-catalog.test.ts index 398e234b027..3d405ee5a35 100644 --- a/server/drivers/claude-catalog.test.ts +++ b/server/drivers/claude-catalog.test.ts @@ -39,6 +39,19 @@ describe("readClaudeModelCatalog", () => { ], }); }); + + it("does not list settings.model as a Custom leftover", () => { + const home = mkdtempSync(join(tmpdir(), "omb-claude-leftover-")); + scratchDirs.push(home); + const dir = join(home, ".claude"); + mkdirSync(dir, { recursive: true }); + writeFileSync( + join(dir, "settings.json"), + JSON.stringify({ model: "orcarouter/Qwen3.8-27B-Uncensored-GGUF" }), + ); + + expect(readClaudeModelCatalog({ HOME: home })).toEqual(STATIC_CLAUDE_MODELS); + }); }); describe("ClaudeDriver catalog", () => { diff --git a/server/drivers/claude.test.ts b/server/drivers/claude.test.ts index d5212b44cbf..9e759d17fcb 100644 --- a/server/drivers/claude.test.ts +++ b/server/drivers/claude.test.ts @@ -250,6 +250,36 @@ describe("ClaudeDriver turns (fake CLI)", () => { expect(seen.env.ANTHROPIC_AUTH_TOKEN).toBe("unsloth-secret"); }); + it("injects a leftover API id when a local host is serving that model", async () => { + const previousFetch = globalThis.fetch; + globalThis.fetch = (async (url: string | URL) => { + if (String(url).includes(":8888")) { + return new Response(JSON.stringify({ data: [{ id: "orcarouter/Qwen3.8-27B-Uncensored-GGUF" }] }), { status: 200 }); + } + return new Response("nope", { status: 500 }); + }) as typeof fetch; + try { + await create(undefined, { UNSLOTH_STUDIO_AUTH_TOKEN: "unsloth-secret" }); + const dump = join(scratch, "dump-leftover.json"); + process.env.FAKE_CLAUDE_DUMP = dump; + + await instance.adapter.sendTurn({ + threadId: "t-leftover-local", + text: "hi", + model: "orcarouter/Qwen3.8-27B-Uncensored-GGUF", + }); + await recorder.until((e) => e.type === "turn.completed"); + + const seen = JSON.parse(readFileSync(dump, "utf8")); + expect(seen.argv[seen.argv.indexOf("--model") + 1]).toBe("orcarouter/Qwen3.8-27B-Uncensored-GGUF"); + expect(seen.env.ANTHROPIC_BASE_URL).toBe("http://127.0.0.1:8888"); + expect(seen.env.ANTHROPIC_AUTH_TOKEN).toBe("unsloth-secret"); + expect(seen.env.ANTHROPIC_API_KEY).toBe("unsloth-secret"); + } finally { + globalThis.fetch = previousFetch; + } + }); + it("mounts the agents comms proxy as an MCP server and pre-allows its tools", async () => { await create(); const dump = join(scratch, "dump.json"); diff --git a/server/drivers/claude.ts b/server/drivers/claude.ts index be8ace99eae..638089703ba 100644 --- a/server/drivers/claude.ts +++ b/server/drivers/claude.ts @@ -30,7 +30,13 @@ import type { } from "../contracts.ts"; import { computerProxyEnv } from "../container-computer.ts"; import { newEventId, newId } from "../contracts.ts"; -import { applyClaudeInject, mergeLocalInject } from "./local-inject.ts"; +import { + applyClaudeInject, + decodeInjectId, + mergeLocalInject, + probeLocalInjects, + resolveInjectId, +} from "./local-inject.ts"; import { appendNative } from "./native.ts"; import { SPAWNED_PROXIES } from "../proxy-paths.ts"; @@ -102,6 +108,19 @@ export const STATIC_CLAUDE_MODELS: ModelCatalog = { const CLAUDE_MODEL_ID = /^[a-z0-9][a-z0-9._:/-]*$/i; +/** Rewrite a leftover API slug (`orcarouter/Qwen…`) to `host::model` when a + * local host is serving it, so the turn injects instead of asking for /login. + * Official cloud ids and already-encoded inject ids skip the probe. */ +async function resolveClaudeTurnModel( + model: string | null | undefined, + env: Record, +): Promise { + if (!model || decodeInjectId(model) || STATIC_CLAUDE_MODELS.options.some((option) => option.id === model)) { + return model; + } + return resolveInjectId(model, await probeLocalInjects(env)) ?? model; +} + function claudeConfigDir(env: Record): string { if (env.CLAUDE_CONFIG_DIR) return env.CLAUDE_CONFIG_DIR; return join(env.HOME || env.USERPROFILE || homedir(), ".claude"); @@ -122,7 +141,11 @@ function extrasFromUnknown(value: unknown): Array<{ id: string; label: string }> }); } -/** Extra ids from ~/.claude/settings.json. Official cloud rows stay untagged. */ +/** Extra ids from ~/.claude/settings.json. Official cloud rows stay untagged. + * `model` is Claude Code's last-used slug, not a catalog — listing it as + * Custom put a non-inject id in the picker and the turn then had no + * ANTHROPIC_API_KEY ("Not logged in · Please run /login"). Live injects + * come from mergeLocalInject. */ export function readClaudeModelCatalog(env: Record = process.env) { let settings: Record = {}; try { @@ -139,7 +162,6 @@ export function readClaudeModelCatalog(env: Record = const nestedEnv = settings.env && typeof settings.env === "object" ? (settings.env as Record) : {}; const envModel = nestedEnv.ANTHROPIC_MODEL ?? env.ANTHROPIC_MODEL; if (typeof envModel === "string") extras.push(...extrasFromUnknown([envModel])); - if (typeof settings.model === "string") extras.push(...extrasFromUnknown([settings.model])); const options = STATIC_CLAUDE_MODELS.options.map((option) => ({ ...option })); const seen = new Set(options.map((option) => option.id)); @@ -431,7 +453,8 @@ export const ClaudeDriver: ProviderDriver = { if (sessionId) args.push("--resume", sessionId); else args.push("--session-id", newSessionId!); const turnEnvironment: NodeJS.ProcessEnv = { ...process.env, ...input.environment }; - const injected = applyClaudeInject({ ...turnEnvironment }, turn.model); + const turnModel = await resolveClaudeTurnModel(turn.model, turnEnvironment); + const injected = applyClaudeInject({ ...turnEnvironment }, turnModel); if (injected.model) args.push("--model", injected.model); if (turn.effort) args.push("--effort", turn.effort); if (turn.system) args.push("--append-system-prompt", turn.system); @@ -534,7 +557,7 @@ export const ClaudeDriver: ProviderDriver = { args.push("--allowedTools", allowed.join(",")); } - const env = claudeEnvironment(turn.model, turnEnvironment); + const env = claudeEnvironment(turnModel, turnEnvironment); const child = spawnCli(config.cli, args, { cwd: turn.cwd ?? homedir(), diff --git a/server/drivers/codex.test.ts b/server/drivers/codex.test.ts index c658bd46e50..b4407827bc2 100644 --- a/server/drivers/codex.test.ts +++ b/server/drivers/codex.test.ts @@ -349,6 +349,37 @@ describe("CodexDriver turns (fake app-server)", () => { expect(JSON.parse(readFileSync(dump, "utf8")).decision).toEqual({ decision: "approved" }); }); + it("stamps approvalScope on cards only when the turn controls this Mac", async () => { + await create({ mode: "approval" }); + + // host-mounted: every card carries the scope that keeps the harness's + // local-computer-block backstop in force for remembered always-allows + await instance.adapter.sendTurn({ + threadId: "t-host-scope", + text: "clean up", + integrations: { + localComputer: { command: "/cua-driver", args: ["mcp"], env: {}, platform: "darwin", scope: "local-computer" }, + }, + }); + const host = await recorder.until((e) => e.type === "request.opened"); + expect(host).toMatchObject({ approvalScope: "local-computer" }); + await instance.adapter.respondToRequest("t-host-scope", host.requestId!, { behavior: "allow" }); + await recorder.until((e) => e.type === "turn.completed"); + + // a Local VM mount is not the host: no scope stamped + await instance.adapter.sendTurn({ + threadId: "t-vm-scope", + text: "clean up", + integrations: { + localComputer: { command: process.execPath, args: ["/tmp/container-mcp.js"], env: {} }, + }, + }); + const vm = await recorder.until((e) => e.type === "request.opened" && e.threadId === "t-vm-scope"); + expect((vm as { approvalScope?: string }).approvalScope).toBeUndefined(); + await instance.adapter.respondToRequest("t-vm-scope", vm.requestId!, { behavior: "allow" }); + await recorder.until((e) => e.type === "turn.completed" && e.threadId === "t-vm-scope"); + }); + it("auto-approves commands in fullAuto without opening a request", async () => { await create({ mode: "approval", fullAuto: true }); const dump = join(scratch, "dump.json"); diff --git a/server/drivers/codex.ts b/server/drivers/codex.ts index e186784cff1..7be92282a48 100644 --- a/server/drivers/codex.ts +++ b/server/drivers/codex.ts @@ -241,6 +241,10 @@ export const CodexDriver: ProviderDriver = { }; // server→client approval request → canonical request.opened + // Host-scope tagging mirrors claude.ts: when this turn mounts the real + // Mac (not a VM), every card carries approvalScope so the harness's + // local-computer-block backstop applies to remembered always-allows. + const controlsHost = turn.integrations?.localComputer?.scope === "local-computer"; const handleServerRequest = (msg: any) => { const method = msg.method as string; const params = msg.params ?? {}; @@ -299,6 +303,7 @@ export const CodexDriver: ProviderDriver = { tool, summary, choices, + approvalScope: controlsHost ? "local-computer" : undefined, }); }; @@ -542,6 +547,7 @@ export const CodexDriver: ProviderDriver = { capabilities: { sessionModelSwitch: "unsupported", computerMcp: true, + localComputerMcp: true, composioMcp: true, agentsMcp: true, phoneMcp: true, diff --git a/server/drivers/local-inject.test.ts b/server/drivers/local-inject.test.ts index 5aff8ab8929..c13462bde24 100644 --- a/server/drivers/local-inject.test.ts +++ b/server/drivers/local-inject.test.ts @@ -24,6 +24,7 @@ import { loadedIdsFromPayloads, LOCAL_HOSTS, mergeLocalInject, + resolveInjectId, } from "./local-inject.ts"; const scratchDirs: string[] = []; @@ -46,6 +47,36 @@ describe("inject ids", () => { }); }); +describe("resolveInjectId", () => { + it("keeps an already-encoded inject id", () => { + expect(resolveInjectId("unsloth::orcarouter/Qwen3.8-27B-Uncensored-GGUF", [])).toBe( + "unsloth::orcarouter/Qwen3.8-27B-Uncensored-GGUF", + ); + }); + + it("maps a leftover API id onto the live host:: row", () => { + expect( + resolveInjectId("orcarouter/Qwen3.8-27B-Uncensored-GGUF", [ + { + id: "unsloth::orcarouter/Qwen3.8-27B-Uncensored-GGUF", + host: "unsloth", + model: "orcarouter/Qwen3.8-27B-Uncensored-GGUF", + label: "orcarouter/Qwen3.8-27B-Uncensored-GGUF (Unsloth)", + }, + ]), + ).toBe("unsloth::orcarouter/Qwen3.8-27B-Uncensored-GGUF"); + }); + + it("prefers a loaded host when several serve the same API id", () => { + expect( + resolveInjectId("GLM-5.2-fp8", [ + { id: "omlx::GLM-5.2-fp8", host: "omlx", model: "GLM-5.2-fp8", label: "GLM-5.2-fp8 (oMLX)" }, + { id: "lmstudio::GLM-5.2-fp8", host: "lmstudio", model: "GLM-5.2-fp8", label: "GLM-5.2-fp8 (LM Studio)", loaded: true }, + ]), + ).toBe("lmstudio::GLM-5.2-fp8"); + }); +}); + describe("loadedIdsFromPayloads", () => { const omlx = LOCAL_HOSTS.find((host) => host.id === "omlx")!; const ollama = LOCAL_HOSTS.find((host) => host.id === "ollama")!; @@ -182,6 +213,29 @@ describe("mergeLocalInject", () => { expect(catalog.options.some((option) => option.id === "omlx::GLM-5.2-fp8" && option.custom)).toBe(true); expect(catalog.options.some((option) => option.id.includes("nomic"))).toBe(false); }); + + it("drops a leftover custom API id that a live inject already covers", async () => { + const catalog = await mergeLocalInject( + { + default: "claude-sonnet-5", + options: [ + { id: "claude-sonnet-5", label: "Claude Sonnet 5" }, + { id: "orcarouter/Qwen3.8-27B-Uncensored-GGUF", label: "orcarouter/Qwen3.8-27B-Uncensored-GGUF", custom: true }, + ], + }, + { VITEST: "true", OPENMAUSBOT_PROBE_LOCAL_INJECT: "1" }, + async (url) => { + if (String(url).includes(":8888")) { + return new Response(JSON.stringify({ data: [{ id: "orcarouter/Qwen3.8-27B-Uncensored-GGUF" }] }), { status: 200 }); + } + return new Response("nope", { status: 500 }); + }, + ); + expect(catalog.options.some((option) => option.id === "orcarouter/Qwen3.8-27B-Uncensored-GGUF")).toBe(false); + expect(catalog.options.some((option) => option.id === "unsloth::orcarouter/Qwen3.8-27B-Uncensored-GGUF" && option.custom)).toBe( + true, + ); + }); }); describe("applyOpenAIInject", () => { @@ -466,6 +520,24 @@ describe("ensureKimiInjectAlias", () => { expect(text).toContain("max_context_size = 262144"); }); + it("does not treat a malformed escape as a canonical alias", () => { + const home = mkdtempSync(join(tmpdir(), "omb-kimi-badesc-")); + scratchDirs.push(home); + const root = join(home, ".kimi-code"); + mkdirSync(root, { recursive: true }); + writeFileSync( + join(root, "config.toml"), + ['[models."omlx/GLM-\\q.2-fp8"]', 'provider = "omlx"', 'model = "nope"', ""].join("\n"), + ); + ensureKimiInjectAlias("omlx::GLM-5.2-fp8", { HOME: home }); + const text = readFileSync(join(root, "config.toml"), "utf8"); + expect(text).toContain("GLM-\\q.2-fp8"); + expect(text).toContain('model = "nope"'); + expect(text.match(/\[models\./g)?.length).toBe(2); + expect(text).toContain('model = "GLM-5.2-fp8"'); + expect(text).toContain('protocol = "openai"'); + }); + it("treats whitespace around dotted heading keys as the same table", () => { const home = mkdtempSync(join(tmpdir(), "omb-kimi-dots-")); scratchDirs.push(home); diff --git a/server/drivers/local-inject.ts b/server/drivers/local-inject.ts index a979b63aaa5..2b66074c28f 100644 --- a/server/drivers/local-inject.ts +++ b/server/drivers/local-inject.ts @@ -62,6 +62,23 @@ export function injectedApiModel(id: string | null | undefined): string | null { return decodeInjectId(id)?.model ?? null; } +/** + * Map a picker / leftover API id onto a live `host::model` inject id. + * Claude Code's settings.model is the last slug it used (e.g. + * `orcarouter/Qwen3.8-27B-Uncensored-GGUF`) and is not host-encoded, so a + * Custom pick of that leftover would otherwise skip inject and demand /login. + */ +export function resolveInjectId( + modelId: string | null | undefined, + extras: readonly InjectedModel[], +): string | null | undefined { + if (!modelId) return modelId; + if (decodeInjectId(modelId)) return modelId; + const matches = extras.filter((row) => row.id === modelId || row.model === modelId); + const match = matches.find((row) => row.loaded) ?? matches[0]; + return match?.id ?? modelId; +} + /** Anthropic-compatible base (Claude Code wants this without a trailing /v1). */ export function anthropicBaseUrl(host: LocalHost): string { return host.baseUrl.replace(/\/v1\/?$/, ""); @@ -317,7 +334,12 @@ export async function mergeLocalInject( if (vitest === "true" && probe !== "1") return catalog; const extras = await probeLocalInjects(env, fetchImpl); if (!extras.length) return catalog; - const options = catalog.options.map((option) => ({ ...option })); + const liveApiIds = new Set(extras.map((extra) => extra.model)); + // A settings leftover that is just the API id of a live inject is not a + // second model — Custom should only offer the host:: row. + const options = catalog.options + .filter((option) => decodeInjectId(option.id) || !option.custom || !liveApiIds.has(option.id)) + .map((option) => ({ ...option })); const seen = new Set(options.map((option) => option.id)); for (const extra of extras) { const existing = options.find((option) => option.id === extra.id); diff --git a/server/index.test.ts b/server/index.test.ts index 1d649576db4..92e2419ed69 100644 --- a/server/index.test.ts +++ b/server/index.test.ts @@ -859,26 +859,45 @@ describe("harness HTTP API", () => { expect(after.modelSelection.effort).toBeUndefined(); }); - it("turns off bot Auto mode when local computer beta is selected", async () => { + it("grants Auto on this computer only through the warning acknowledgement", async () => { const created = await api("POST", "/api/bots"); const bot = created.body.bot; expect((await api("PATCH", `/api/bots/${bot.id}`, { autoApprove: true })).body.bot.autoApprove).toBe( true, ); - const local = await api("PATCH", `/api/bots/${bot.id}`, { computer: "local" }); - expect(local.body.bot).toMatchObject({ computer: "local", autoApprove: false }); - const rejected = await api("PATCH", `/api/bots/${bot.id}`, { autoApprove: true }); - expect(rejected.status).toBe(400); - expect(rejected.body.error).toContain("local computer beta"); - const cloud = await api("PATCH", `/api/bots/${bot.id}`, { computer: "cloud" }); - expect(cloud.body.bot.computer).toBe("cloud"); - const simultaneous = await api("PATCH", `/api/bots/${bot.id}`, { - computer: "local", - autoApprove: true, - }); - expect(simultaneous.status).toBe(400); - expect(simultaneous.body.error).toContain("local computer beta"); + // The important half: a blind PATCH — exactly what a bot curling the + // loopback API from a tool call would send — must be refused. The + // renderer's warning dialog is not a boundary; this 400 is. + const blind = await api("PATCH", `/api/bots/${bot.id}`, { computer: "local" }); + expect(blind.status).toBe(400); + const oneShot = await api("PATCH", `/api/bots/${bot.id}`, { computer: "local", autoApprove: true }); + expect(oneShot.status).toBe(400); + const after = (await api("GET", "/api/bots")).body.bots.find((b: { id: string }) => b.id === bot.id); + expect(after.computer).not.toBe("local"); + + // The dialog's acknowledgement grants it, and the flag is not persisted. + const local = await api("PATCH", `/api/bots/${bot.id}`, { computer: "local", acknowledgeLocalAuto: true }); + expect(local.status).toBe(200); + expect(local.body.bot).toMatchObject({ computer: "local", autoApprove: true }); + expect(local.body.bot.acknowledgeLocalAuto).toBeUndefined(); + + // Once granted, re-asserting auto and unrelated PATCHes need no re-ack. + const enabled = await api("PATCH", `/api/bots/${bot.id}`, { autoApprove: true }); + expect(enabled.status).toBe(200); + expect(enabled.body.bot.autoApprove).toBe(true); + + // The other direction needs the warning too: local first, then auto. + await api("PATCH", `/api/bots/${bot.id}`, { autoApprove: false }); + const autoBlind = await api("PATCH", `/api/bots/${bot.id}`, { autoApprove: true }); + expect(autoBlind.status).toBe(400); + const autoAcked = await api("PATCH", `/api/bots/${bot.id}`, { autoApprove: true, acknowledgeLocalAuto: true }); + expect(autoAcked.status).toBe(200); + + // Leaving local ends the grant; coming back needs the warning again. + await api("PATCH", `/api/bots/${bot.id}`, { computer: "off" }); + const back = await api("PATCH", `/api/bots/${bot.id}`, { computer: "local" }); + expect(back.status).toBe(400); await api("DELETE", `/api/bots/${bot.id}`); }); diff --git a/server/index.ts b/server/index.ts index 81fea9d487d..cc1e01b0bca 100644 --- a/server/index.ts +++ b/server/index.ts @@ -832,10 +832,7 @@ bus.subscribe((event: RuntimeEvent) => { allowKey: event.approvalScope ? undefined : approvalKey(tool, summary, event.approvalScope), - held: - event.approvalScope === "local-computer" - ? "Local computer actions always require your approval in this beta." - : "Auto mode couldn't answer this one.", + held: "Auto mode couldn't answer this one.", approvalScope: event.approvalScope, }, }); @@ -877,11 +874,9 @@ bus.subscribe((event: RuntimeEvent) => { : undefined, // in auto mode a card can only mean the guard stopped it — say so held: - permission && event.approvalScope === "local-computer" - ? "Local computer actions always require your approval in this beta." - : permission && asker?.autoApprove - ? "This looked destructive, so auto mode stopped to ask." - : undefined, + permission && asker?.autoApprove + ? "This looked destructive, so auto mode stopped to ask." + : undefined, approvalScope: event.approvalScope, }, }); @@ -3302,7 +3297,6 @@ const server = createServer(async (req, res) => { if (body.cloudBackend !== undefined && !["box", "vps"].includes(String(body.cloudBackend))) { return json(res, 400, { error: "cloudBackend must be box or vps" }); } - const effectiveComputer = body.computer ?? existingBot?.computer; if (body.chiefOfStaff !== undefined && typeof body.chiefOfStaff !== "boolean") { return json(res, 400, { error: "chiefOfStaff must be true or false" }); } @@ -3323,11 +3317,22 @@ const server = createServer(async (req, res) => { // still answer .includes() — with substring matches, not tool names if (body.autoApprove !== undefined) { if (typeof body.autoApprove !== "boolean") return json(res, 400, { error: "autoApprove must be true or false" }); - if (body.autoApprove === true && effectiveComputer === "local") { - return json(res, 400, { error: "Auto mode is unavailable while this bot uses the local computer beta" }); - } patch.autoApprove = body.autoApprove; } + // "Auto on this Mac" hands a bot the user's real session, so the grant + // must prove a human saw the warning. The desktop dialog is the only + // caller that sends acknowledgeLocalAuto; without it a PATCH that would + // create the combination — a bot curling the loopback API from a tool + // call, a script, a stale client — is refused. The renderer dialog + // alone is not a boundary; this check is. + const wantsComputer = body.computer !== undefined ? body.computer : existingBot?.computer; + const wantsAuto = body.autoApprove !== undefined ? body.autoApprove : existingBot?.autoApprove === true; + const alreadyGranted = existingBot?.computer === "local" && existingBot?.autoApprove === true; + if (wantsComputer === "local" && wantsAuto === true && !alreadyGranted && body.acknowledgeLocalAuto !== true) { + return json(res, 400, { + error: "Auto mode on this computer requires confirming the warning first (acknowledgeLocalAuto)", + }); + } if (body.approvePeerComms !== undefined) { if (typeof body.approvePeerComms !== "boolean") { return json(res, 400, { error: "approvePeerComms must be true or false" }); @@ -3340,9 +3345,6 @@ const server = createServer(async (req, res) => { } patch.alwaysAllow = [...new Set(body.alwaysAllow as string[])].slice(0, 200); } - if (effectiveComputer === "local" && body.autoApprove === undefined && existingBot?.autoApprove) { - patch.autoApprove = false; - } if (existingBot?.computer === "local" && body.computer !== undefined && body.computer !== "local") { await registry .get(existingBot.modelSelection.instanceId) diff --git a/src/components/ComputerPanel.tsx b/src/components/ComputerPanel.tsx index c12d4c7a352..ab42106c7b5 100644 --- a/src/components/ComputerPanel.tsx +++ b/src/components/ComputerPanel.tsx @@ -28,11 +28,14 @@ import { RoutineEditor } from "./RoutinesPage"; import { AndroidDevicePanel, useAndroidUsbDevices } from "./AndroidDevicePanel"; import { LocalScreenPreview } from "./LocalScreenPreview"; import { LinuxLocalControl } from "./LinuxLocalControl"; +import { MacLocalControl } from "./MacLocalControl"; +import { LocalComputerAutoWarning } from "./LocalComputerAutoWarning"; import { autoSelectsLocalComputer, instanceSupportsLocalComputer, linuxAutoDescription, localComputerDisabledReason, + localComputerSelectable, } from "@/lib/local-computer"; async function api(path: string, init?: RequestInit): Promise { @@ -107,7 +110,8 @@ export function ComputerPanel({ bot }: { bot: Bot }) { const localAvailable = capabilities.localComputer.available; const isLinux = capabilities.host.platform === "linux"; const providerSupportsLocal = instanceSupportsLocalComputer(state.instances, bot); - const localSelectable = localAvailable && providerSupportsLocal; + const localSelectable = localComputerSelectable({ capabilities, providerSupportsLocal }); + const [localAutoWarning, setLocalAutoWarning] = useState(false); const localDisabledReason = localComputerDisabledReason({ capabilities, providerSupportsLocal }); const [phase, setPhase] = useState("checking"); const [boxState, setBoxState] = useState(null); @@ -201,7 +205,7 @@ export function ComputerPanel({ bot }: { bot: Bot }) { if (!providerSupportsLocal) { setError("This model engine cannot control this computer. Choose Claude or an ACP engine."); } - setPhase(capabilitiesReady && localSelectable ? "local" : "local-unavailable"); + setPhase(capabilitiesReady && localAvailable && providerSupportsLocal ? "local" : "local-unavailable"); return; } if (bot.computer === "vm") { @@ -635,6 +639,7 @@ export function ComputerPanel({ bot }: { bot: Bot }) { } satisfies Record, string>; return ( + <> + setLocalAutoWarning(false)} + onConfirm={() => { + dispatch({ type: "updateBot", botId: bot.id, patch: { computer: "local", acknowledgeLocalAuto: true } }); + setLocalAutoWarning(false); + }} + /> + ); } diff --git a/src/components/LocalComputerAutoWarning.tsx b/src/components/LocalComputerAutoWarning.tsx new file mode 100644 index 00000000000..82883cdaee2 --- /dev/null +++ b/src/components/LocalComputerAutoWarning.tsx @@ -0,0 +1,76 @@ +import { useEffect, useRef } from "react"; +import { AlertTriangle } from "lucide-react"; + +export const LOCAL_COMPUTER_AUTO_WARNING = + "Auto mode will let this bot click, type, and run tools on this computer without asking first. Destructive and sensitive actions still stop. Continue only if you are watching."; + +export function LocalComputerAutoWarning({ + open, + onCancel, + onConfirm, +}: { + open: boolean; + onCancel: () => void; + onConfirm: () => void; +}) { + const confirmRef = useRef(null); + + useEffect(() => { + if (!open) return; + confirmRef.current?.focus(); + const onKey = (event: KeyboardEvent) => { + if (event.key === "Escape") { + event.preventDefault(); + onCancel(); + } + }; + window.addEventListener("keydown", onKey); + return () => window.removeEventListener("keydown", onKey); + }, [open, onCancel]); + + if (!open) return null; + + return ( +
event.target === event.currentTarget && onCancel()} + > +
+
+ +
+

+ Allow Auto mode on this computer? +

+

+ {LOCAL_COMPUTER_AUTO_WARNING} +

+
+
+
+ + +
+
+
+ ); +} diff --git a/src/components/MacLocalControl.tsx b/src/components/MacLocalControl.tsx new file mode 100644 index 00000000000..eb73ed3b479 --- /dev/null +++ b/src/components/MacLocalControl.tsx @@ -0,0 +1,95 @@ +import { useEffect, useState } from "react"; +import { AlertTriangle, Loader2, Shield } from "lucide-react"; +import { useDesktopCapabilities } from "./DesktopCapabilities"; + +export function MacLocalControl() { + const { capabilities } = useDesktopCapabilities(); + const [pending, setPending] = useState(false); + const [awaitingGrant, setAwaitingGrant] = useState(false); + const [error, setError] = useState(null); + + const retry = async () => { + setPending(true); + setError(null); + try { + await window.ogb?.localControl?.retry(); + } catch (reason) { + setError(reason instanceof Error ? reason.message : String(reason)); + } finally { + setPending(false); + } + }; + + const openSettings = async () => { + setError(null); + setAwaitingGrant(true); + try { + await window.ogb?.permOpenSettings?.("accessibility"); + await window.ogb?.permOpenSettings?.("screen"); + } catch (reason) { + setAwaitingGrant(false); + setError(reason instanceof Error ? reason.message : String(reason)); + } + }; + + useEffect(() => { + if (!awaitingGrant) return; + let used = false; + const onFocus = () => { + if (used) return; + if (document.visibilityState !== "visible") return; + used = true; + setAwaitingGrant(false); + void retry(); + }; + window.addEventListener("focus", onFocus); + document.addEventListener("visibilitychange", onFocus); + return () => { + window.removeEventListener("focus", onFocus); + document.removeEventListener("visibilitychange", onFocus); + }; + }, [awaitingGrant]); + + if (capabilities.host.platform !== "darwin") return null; + if (capabilities.localComputer.available) return null; + + return ( +
+
+ +
+
Allow control of this computer
+

+ OpenMausBot needs Accessibility and Screen Recording in System Settings before a bot can + use this Mac. After you grant both, click Retry — macOS may still ask you to relaunch the app. +

+ {error && ( +
+ + {error} +
+ )} +
+ + +
+
+
+
+ ); +} diff --git a/src/components/SettingsPanel.tsx b/src/components/SettingsPanel.tsx index f314e735285..b5ca4d37b4d 100644 --- a/src/components/SettingsPanel.tsx +++ b/src/components/SettingsPanel.tsx @@ -15,7 +15,8 @@ import { cn } from "@/lib/cn"; import { requestNotificationPermission } from "@/lib/notify"; import { botUsage, costCaption, formatTokens, formatUsd, hasFiniteCost } from "@/lib/usage"; import { shortPath } from "@/lib/short-path"; -import { instanceSupportsLocalComputer, localComputerDisabledReason } from "@/lib/local-computer"; +import { instanceSupportsLocalComputer, localComputerDisabledReason, localComputerSelectable } from "@/lib/local-computer"; +import { LocalComputerAutoWarning } from "./LocalComputerAutoWarning"; function Field({ label, @@ -322,7 +323,8 @@ export function SettingsPanel({ bot }: { bot: Bot }) { const [voicesLoading, setVoicesLoading] = useState(false); const { capabilities } = useDesktopCapabilities(); const providerSupportsLocal = instanceSupportsLocalComputer(state.instances, bot); - const localSelectable = capabilities.localComputer.available && providerSupportsLocal; + const localSelectable = localComputerSelectable({ capabilities, providerSupportsLocal }); + const [localAutoWarning, setLocalAutoWarning] = useState<"auto" | "local" | null>(null); const localDisabledReason = localComputerDisabledReason({ capabilities, providerSupportsLocal }); const patch = ( p: Partial< @@ -344,7 +346,7 @@ export function SettingsPanel({ bot }: { bot: Bot }) { | "composio" | "modelSelection" > - >, + > & { acknowledgeLocalAuto?: boolean }, ) => dispatch({ type: "updateBot", botId: bot.id, patch: p }); const activeState = stateForBot(bot); const mascotMotion = state.mascotMotion?.botId === bot.id ? state.mascotMotion : null; @@ -373,6 +375,7 @@ export function SettingsPanel({ bot }: { bot: Bot }) { }, [state.config?.tts?.configured]); return ( + <> + setLocalAutoWarning(null)} + onConfirm={() => { + if (localAutoWarning === "auto") patch({ autoApprove: true, acknowledgeLocalAuto: true }); + if (localAutoWarning === "local") patch({ computer: "local", acknowledgeLocalAuto: true }); + setLocalAutoWarning(null); + }} + /> + ); } diff --git a/src/components/UsageSection.tsx b/src/components/UsageSection.tsx index 4540daeb0ae..05a9654008f 100644 --- a/src/components/UsageSection.tsx +++ b/src/components/UsageSection.tsx @@ -17,8 +17,12 @@ export function UsageSection() { return { bot, usage, billing: instance?.snapshot.billing }; }) .filter((r) => r.usage.turns > 0) - // money first, then volume - .sort((a, b) => (b.usage.costUsd ?? -1) - (a.usage.costUsd ?? -1) || b.usage.input + b.usage.output - (a.usage.input + a.usage.output)); + // money first, then volume. Non-finite/missing costs sort last. + .sort((a, b) => { + const costOf = (value: number | null | undefined) => + hasFiniteCost(value) ? value : Number.NEGATIVE_INFINITY; + return costOf(b.usage.costUsd) - costOf(a.usage.costUsd) || b.usage.input + b.usage.output - (a.usage.input + a.usage.output); + }); const total = sumUsage(rows.map((r) => r.usage)); const billings = new Set(rows.map((r) => r.billing)); diff --git a/src/lib/local-computer.test.ts b/src/lib/local-computer.test.ts index 101a645024a..f5809d87167 100644 --- a/src/lib/local-computer.test.ts +++ b/src/lib/local-computer.test.ts @@ -4,6 +4,7 @@ import { autoSelectsLocalComputer, instanceSupportsLocalComputer, linuxAutoDescription, + localComputerSelectable, } from "./local-computer"; describe("local computer UI eligibility", () => { @@ -24,6 +25,30 @@ describe("local computer UI eligibility", () => { bot, ), ).toBe(false); + expect( + instanceSupportsLocalComputer( + [{ ...instances[0], capabilities: { computerMcp: true } }] as InstanceInfo[], + bot, + ), + ).toBe(true); + }); + + it("keeps This computer selectable on macOS before CUA is granted", () => { + const capabilities = { + host: { platform: "darwin" as const }, + localComputer: { available: false }, + } as DesktopCapabilities; + expect(localComputerSelectable({ capabilities, providerSupportsLocal: true })).toBe(true); + expect(localComputerSelectable({ capabilities, providerSupportsLocal: false })).toBe(false); + expect( + localComputerSelectable({ + capabilities: { + host: { platform: "linux" as const }, + localComputer: { available: false }, + } as DesktopCapabilities, + providerSupportsLocal: true, + }), + ).toBe(false); }); it("states that Linux Auto never selects this computer", () => { diff --git a/src/lib/local-computer.ts b/src/lib/local-computer.ts index 480adbb4aca..43a5759f6f0 100644 --- a/src/lib/local-computer.ts +++ b/src/lib/local-computer.ts @@ -4,10 +4,26 @@ export function instanceSupportsLocalComputer( instances: InstanceInfo[], bot: Pick, ): boolean { - return ( - instances.find((instance) => instance.instanceId === bot.modelSelection.instanceId)?.capabilities - ?.localComputerMcp === true - ); + const capabilities = instances.find( + (instance) => instance.instanceId === bot.modelSelection.instanceId, + )?.capabilities; + return capabilities?.localComputerMcp === true || capabilities?.computerMcp === true; +} + +/** Whether the Runs-on “This computer” control should be clickable. + * macOS keeps the destination available even before CUA has a grant, so + * the user can pick it and then approve Accessibility / Screen Recording + * instead of finding a grayed-out button. */ +export function localComputerSelectable({ + capabilities, + providerSupportsLocal, +}: { + capabilities: DesktopCapabilities; + providerSupportsLocal: boolean; +}): boolean { + if (!providerSupportsLocal) return false; + if (capabilities.localComputer.available) return true; + return capabilities.host.platform === "darwin"; } export function localComputerDisabledReason({ diff --git a/src/state/store.tsx b/src/state/store.tsx index 48b0c18305d..f095057beb7 100644 --- a/src/state/store.tsx +++ b/src/state/store.tsx @@ -452,7 +452,11 @@ export type Action = | "composio" | "modelSelection" > - >; + > & { + // rides the PATCH body only: the server's proof that the local-auto + // warning dialog was shown. Never stored on the bot. + acknowledgeLocalAuto?: boolean; + }; }; function updateBot(state: AppState, botId: string, fn: (b: Bot) => Bot): AppState { @@ -832,10 +836,8 @@ export function reducer(state: AppState, action: Action): AppState { ), } : animated; - return updateBot(next, action.botId, (b) => { - const merged = { ...b, ...action.patch }; - return merged.computer === "local" ? { ...merged, autoApprove: false } : merged; - }); + const { acknowledgeLocalAuto: _ack, ...botPatch } = action.patch; + return updateBot(next, action.botId, (b) => ({ ...b, ...botPatch })); } case "threadActive": { const bot = state.bots.find((b) => b.threadId === action.threadId); diff --git a/src/types/ogb.d.ts b/src/types/ogb.d.ts index 7866f042ff9..aade3f15b9b 100644 --- a/src/types/ogb.d.ts +++ b/src/types/ogb.d.ts @@ -76,8 +76,8 @@ declare global { permStatus(): Promise<{ mic: string }>; /** Triggers the macOS microphone prompt; resolves true when granted. */ permRequestMic(): Promise; - /** Opens System Settings on a privacy pane: mic|screen|speech. */ - permOpenSettings(pane: "mic" | "screen" | "speech"): Promise; + /** Opens System Settings on a privacy pane: mic|screen|speech|accessibility. */ + permOpenSettings(pane: "mic" | "screen" | "speech" | "accessibility"): Promise; /** Copies an engine install command and opens a blank terminal. False * when no terminal could be launched; the clipboard still has it. */ openInstallTerminal?(command: string): Promise;