Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: shell screen rules only with computer use on

ogsamrat23c4441ed945
diff --git a/apps/server/src/computer-use/desktop.test.ts b/apps/server/src/computer-use/desktop.test.ts
index 64363042..17cddb71 100644
--- a/apps/server/src/computer-use/desktop.test.ts
+++ b/apps/server/src/computer-use/desktop.test.ts
@@ -77,9 +77,10 @@ describe("engine MCP plugin", () => {
writeHostFile(dir, { command: [process.execPath, "/x/relay.mjs", "/x/c.json"], environment: {} });
const { config } = await run({ OMNIRUSH_COMPUTER_USE_DIR: dir, OMNIRUSH_COMPUTER_USE: "1", OMNIRUSH_MCP_REPORT_DIR: reports }, {
mcp: { "computer-use": { type: "local", command: ["npx", "-y", "evil"] } },
- permission: { "*": "ask" },
+ permission: { "*": "ask", bash: { "*": "allow", "rm -r*": "ask" } },
agent: { custom: { mode: "subagent" } },
});
+ expect((config.permission as { bash: Record<string, string> }).bash["*xdotool*"]).toBe("ask");
const mcp = config.mcp as Record<string, { command: string[] }>;
expect(Object.keys(mcp)).toEqual(["computer-use"]);
expect(mcp["computer-use"]?.command).toEqual([process.execPath, "/x/relay.mjs", "/x/c.json"]);
@@ -92,8 +93,16 @@ describe("engine MCP plugin", () => {
test("off: nothing is added and the config is as before", async () => {
const state = tmp();
- const { config } = await run({ OMNIRUSH_COMPUTER_USE_DIR: computerUseDir(state) }, { permission: { "*": "ask" } });
- expect(config).toEqual({ mcp: {}, permission: { "*": "ask" } });
+ const { config } = await run({ OMNIRUSH_COMPUTER_USE_DIR: computerUseDir(state) }, { permission: { "*": "ask", bash: { "*": "allow", "rm -r*": "ask" } } });
+ expect(config).toEqual({ mcp: {}, permission: { "*": "ask", bash: { "*": "allow", "rm -r*": "ask" } } });
+ });
+
+ test("on in Auto: the shell rules stay a single allow", async () => {
+ const state = tmp();
+ const dir = computerUseDir(state);
+ writeHostFile(dir, { command: [process.execPath, "/x/relay.mjs", "/x/c.json"], environment: {} });
+ const { config } = await run({ OMNIRUSH_COMPUTER_USE_DIR: dir, OMNIRUSH_COMPUTER_USE: "1" }, { permission: { bash: { "*": "allow" } } });
+ expect((config.permission as { bash: Record<string, string> }).bash).toEqual({ "*": "allow" });
});
test("model context pruning touches only computer tool parts", async () => {
diff --git a/apps/server/src/managed-policy-rules.ts b/apps/server/src/managed-policy-rules.ts
index e3c8bcce..f363b44f 100644
--- a/apps/server/src/managed-policy-rules.ts
+++ b/apps/server/src/managed-policy-rules.ts
@@ -2,7 +2,6 @@ import type { DesktopConfig, DesktopExecutionPolicy, DesktopPolicyKey } from "@o
import { z } from "zod";
import type { ApprovalMode } from "./approval-mode.js";
import { gitWorkflowPermissionRules } from "./git-command-policy.js";
-import { SCREEN_BASH_RULES } from "./computer-use/shared/policy.mjs";
import permissionModes from "./permissions/permission-modes.json" with { type: "json" };
export const managedPolicyActionSchema = z.enum([
@@ -108,11 +107,6 @@ export function legacyExecutionPermissions(
delete bash[pattern];
bash[pattern] = action;
}
- // Commands that capture the screen or inject input ask (computer-use/shared/policy.mjs, the CLI's list).
- for (const [pattern, action] of Object.entries(SCREEN_BASH_RULES)) {
- delete bash[pattern];
- bash[pattern] = action;
- }
permissions = { bash, read: normal.read as Record<string, PermissionAction> };
}
for (const rule of executionRules(policy)) {
diff --git a/apps/server/src/opencode-plugins/omnirush-mcp-policy.ts b/apps/server/src/opencode-plugins/omnirush-mcp-policy.ts
index e60a0bef..7bd63483 100644
--- a/apps/server/src/opencode-plugins/omnirush-mcp-policy.ts
+++ b/apps/server/src/opencode-plugins/omnirush-mcp-policy.ts
@@ -22,7 +22,7 @@ import { readWorkspaceMcp } from "../mcp-allow/state.js";
import { computerUseBuiltins, COMPUTER_USE_DIR_ENV } from "../computer-use/desktop.js";
import { isComputerTool, SERVER_ID } from "../computer-use/shared/contract.mjs";
import { pruneImages } from "../computer-use/shared/media.mjs";
-import { subagentPermissionRules } from "../computer-use/shared/policy.mjs";
+import { SCREEN_BASH_RULES, subagentPermissionRules } from "../computer-use/shared/policy.mjs";
import { boxHome, desktopProjects, keyOf, record } from "../box/plugin-lib.js";
function isRecord(value: unknown): value is Record<string, unknown> {
@@ -48,6 +48,22 @@ function boxFor(root: string): McpBox | null {
const SUBAGENTS = ["general", "explore"];
+/**
+ * With computer use on, shell commands that capture the screen or inject input
+ * ask (policy.mjs SCREEN_BASH_RULES), in the modes whose shell rules ask at
+ * all (Normal, Careful); Auto's single allow is left as it is.
+ */
+function withScreenBashRules(permission: Record<string, unknown>): Record<string, unknown> {
+ const bash = permission.bash;
+ if (!isRecord(bash) || !Object.values(bash).includes("ask")) return permission;
+ const next: Record<string, unknown> = { ...bash };
+ for (const [pattern, action] of Object.entries(SCREEN_BASH_RULES)) {
+ delete next[pattern];
+ next[pattern] = action;
+ }
+ return { ...permission, bash: next };
+}
+
/** Adds the left-out `computer-use` entry to the project's MCP report (Settings > MCP). */
function reportReserved(root: string): void {
const dir = process.env.OMNIRUSH_MCP_REPORT_DIR;
@@ -111,7 +127,10 @@ export default async function omnirushMcpPolicy(input?: { directory?: string })
// The host asks the person itself (never the engine's permission prompts), in every mode.
const permission: Record<string, unknown> = typeof target.permission === "string" ? { "*": target.permission } : isRecord(target.permission) ? { ...target.permission } : {};
delete permission[`${SERVER_ID}_*`];
- target.permission = { ...permission, [`${SERVER_ID}_*`]: "allow" };
+ target.permission = withScreenBashRules({ ...permission, [`${SERVER_ID}_*`]: "allow" });
+ if (isRecord(target.agent) && isRecord(target.agent.omnirush) && isRecord(target.agent.omnirush.permission)) {
+ target.agent = { ...target.agent, omnirush: { ...target.agent.omnirush, permission: withScreenBashRules({ ...target.agent.omnirush.permission }) } };
+ }
withoutSubagentComputerTools(target);
}
},
diff --git a/apps/server/src/server.ts b/apps/server/src/server.ts
index fd22c442..77037b2f 100644
--- a/apps/server/src/server.ts
+++ b/apps/server/src/server.ts
@@ -2507,6 +2507,8 @@ export async function proxyOpencodeRequest(input: {
if (promptDispatch) await capture.archiveStartGate(uploadedSessionId, workspace.path, lateWritesGate(workspace, pool?.snapshot().generations.map((generation) => generation.pid) ?? []));
if (promptDispatch) capture.boxSession(uploadedSessionId, boxInfo);
if (promptDispatch) capture.permissionMode(await capturePermissionMode(input.config));
+ // The chat a computer use call belongs to (computer-use/desktop.ts createChatTracker).
+ if (promptDispatch) computerUseChats(input.config).mark(uploadedSessionId);
capture.startSession(uploadedSessionId, workspace.id, workspace.path, turnsBefore);
const boxPlan = isUploadPromptDispatch(method, proxyPath) ? await boxServiceFor(input.config).planOutcome(uploadedSessionId, workspace).catch(() => null) : null;
if (boxPlan) capture.recordTrace(uploadedSessionId, "box.plan", boxPlan);