A desktop coding agent with free access to frontier models.
TypeScript
feat: permission modes
Samrat Talukdar06a000c9a519
diff --git a/apps/server/src/approval-mode.ts b/apps/server/src/approval-mode.tsindex 441324ce..208b2f66 100644--- a/apps/server/src/approval-mode.ts+++ b/apps/server/src/approval-mode.ts@@ -1,12 +1,18 @@/*** Approval mode of the desktop engine.*- * guarded (default) the git workflow rules ask for write and destructive- * commands; everything else follows the engine defaults.- * full every engine permission is allowed without a prompt; the- * organization's deny rules from Den still apply.+ * careful ("Careful" in the app) asks before every file change, every+ * command and every MCP tool; reading and searching run freely.+ * guarded ("Normal", the default) asks only before risky actions: the+ * shared rules (permissions/permission-modes.json, the same file+ * as the CLI's) plus the git workflow rules.+ * full ("Auto") every engine permission is allowed without a prompt;+ * the organization's deny rules from Den still apply.*- * Precedence, highest first: OMNIRUSH_APPROVALS=full|guarded in the server+ * The stored values stay "guarded" and "full" so settings saved by earlier+ * versions keep their meaning; "normal" and "auto" are accepted as aliases.+ *+ * Precedence, highest first: OMNIRUSH_APPROVALS=careful|guarded|full in the server* (desktop) process environment, then the user setting persisted in the* global runtime config row, then guarded. The server resolves the mode; the* managed-policy engine plugin learns it from every /managed-policy/evaluate@@ -16,7 +22,7 @@* Shared by the server and the engine plugins (imported with "../"), so it* must stay free of server-only dependencies.*/-export type ApprovalMode = "guarded" | "full";+export type ApprovalMode = "careful" | "guarded" | "full";export type ApprovalModeSource = "environment" | "settings" | "default";export const APPROVAL_MODE_ENV = "OMNIRUSH_APPROVALS";@@ -32,7 +38,10 @@ export interface ResolvedApprovalMode {export function parseApprovalMode(value: unknown): ApprovalMode | null {if (typeof value !== "string") return null;const mode = value.trim().toLowerCase();- return mode === "full" || mode === "guarded" ? mode : null;+ if (mode === "careful" || mode === "guarded" || mode === "full") return mode;+ if (mode === "normal") return "guarded";+ if (mode === "auto") return "full";+ return null;}export function approvalModeFromEnv(env: NodeJS.ProcessEnv = process.env): ApprovalMode | null {diff --git a/apps/server/src/effective-permissions.e2e.test.ts b/apps/server/src/effective-permissions.e2e.test.tsindex 401ebd33..4c2dbe8d 100644--- a/apps/server/src/effective-permissions.e2e.test.ts+++ b/apps/server/src/effective-permissions.e2e.test.ts@@ -104,7 +104,8 @@ describe("effective permissions route", () => {expect(rows.shell).toMatchObject({ action: "allow", source: "engine", exceptions: 0 });expect(rows.edit).toMatchObject({ action: "deny", source: "workspace" });expect(rows.outside_folders).toMatchObject({ action: "ask", source: "engine", exceptions: 1 });- expect(rows.env_files).toMatchObject({ action: "ask", source: "engine" });+ // Normal's shared rules ask before reading secret files (.env among them) themselves.+ expect(rows.env_files).toMatchObject({ action: "ask", source: "omnirush" });expect(rows.doom_loop).toMatchObject({ action: "ask", source: "engine" });expect(isRecord(body.files) ? body.files.workspace : null).toBe(join(root, "opencode.json"));diff --git a/apps/server/src/git-command-policy.test.ts b/apps/server/src/git-command-policy.test.tsindex 0f5ad0d3..3d777474 100644--- a/apps/server/src/git-command-policy.test.ts+++ b/apps/server/src/git-command-policy.test.ts@@ -214,6 +214,16 @@ describe("git workflow command classification", () => {});});+/** Session approvals the engine appends after the configured rules (a key both use moves to the end). */+function appended(bash: Record<string, string>, rules: Record<string, string>): Record<string, string> {+ const out = { ...bash };+ for (const [pattern, action] of Object.entries(rules)) {+ delete out[pattern];+ out[pattern] = action;+ }+ return out;+}+describe("git workflow permission rules", () => {const bash = legacyExecutionPermissions(undefined).bash;@@ -231,7 +241,7 @@ describe("git workflow permission rules", () => {expect({ command, action: engineAction(bash, command) }).toEqual({ command, action: "ask" });}// "Allow for session" on `git push origin f` makes the engine append an allow rule for the family.- const approved = { ...bash, "git push *": "allow" };+ const approved = appended(bash, { "git push *": "allow" });expect(engineAction(approved, "git push origin f")).toBe("allow");expect(engineAction(approved, "git push --force origin f")).toBe("ask");// The engine walks the commands inside compound statements; the marked ones still ask.@@ -252,7 +262,7 @@ describe("git workflow permission rules", () => {"cat list | xargs rm -rf", "sudo bash -c 'rm -rf /x'"]) {expect({ command, asks: /(^|,)ask$/.test(engineAction(bash, command)) }).toEqual({ command, asks: true });}- const approved = { ...bash, "bash *": "allow", "eval *": "allow", "xargs *": "allow" };+ const approved = appended(bash, { "bash *": "allow", "eval *": "allow", "xargs *": "allow" });expect(engineAction(approved, "bash -c 'git commit -m x'")).toBe("allow");expect(engineAction(approved, "bash -c 'git push --force origin f'")).toBe("ask");expect(engineAction(approved, "eval 'git push --force'")).toBe("ask");@@ -265,7 +275,8 @@ describe("git workflow permission rules", () => {const user = { "*": "ask" as const };expect(engineAction({ ...user, ...bash }, "git status")).toBe("allow");expect(engineAction({ ...user, ...bash }, "git commit -m x")).toBe("ask");- expect(engineAction({ ...user, ...bash }, "echo hi")).toBe("ask");+ // Normal's shared bash rules start with their own catch-all allow.+ expect(engineAction({ ...user, ...bash }, "echo hi")).toBe("allow");});test("organization rules come last and win over workflow allows", () => {diff --git a/apps/server/src/managed-policy-rules.ts b/apps/server/src/managed-policy-rules.tsindex 726d89a5..06638d56 100644--- a/apps/server/src/managed-policy-rules.ts+++ b/apps/server/src/managed-policy-rules.ts@@ -2,6 +2,7 @@ import type { DesktopConfig, DesktopExecutionPolicy, DesktopPolicyKey } from "@oimport { z } from "zod";import type { ApprovalMode } from "./approval-mode.js";import { gitWorkflowPermissionRules } from "./git-command-policy.js";+import permissionModes from "./permissions/permission-modes.json" with { type: "json" };export const managedPolicyActionSchema = z.enum(["sync", "shell", "terminal", "saved_command", "file_write", "engine_config", "browser_external",@@ -40,32 +41,84 @@ export function executionRules(policy: DesktopExecutionPolicy | undefined): Engi}return rules;}-type LegacyExecutionPermissions = {- bash: Record<string, "allow" | "ask" | "deny">;- /** Full mode only: a catch-all allow appended after the engine's default `read *.env: ask` / `read *.env.*: ask` rules. */- read?: Record<string, "allow">;- webfetch?: "allow" | "deny";- websearch?: "allow" | "deny";- edit?: "allow";- doom_loop?: "allow";+type PermissionAction = "allow" | "ask" | "deny";+export type LegacyExecutionPermissions = {+ bash: Record<string, PermissionAction>;+ /** Full mode: a catch-all allow after the engine's default `read *.env` asks; careful and guarded: the shared secret-file asks. */+ read?: Record<string, PermissionAction>;+ webfetch?: PermissionAction;+ websearch?: PermissionAction;+ edit?: PermissionAction;+ doom_loop?: PermissionAction;external_directory?: "allow";+ /** Careful's catch-all, plain tool names and per-MCP-server rules (`<server>_*`). */+ [permission: string]: PermissionAction | Record<string, PermissionAction> | undefined;};++type SharedModeRules = Record<string, PermissionAction | Record<string, PermissionAction>>;+const SHARED_MODES = permissionModes.rules as unknown as { careful: SharedModeRules; normal: SharedModeRules };++function cloneRules(rules: SharedModeRules): SharedModeRules {+ return JSON.parse(JSON.stringify(rules)) as SharedModeRules;+}++/** The engine's MCP tool-name sanitizer: a server's tools are `<sanitized server>_<tool>`. */+export function mcpToolPermissionKey(server: string): string {+ return `${server.replace(/[^a-zA-Z0-9_-]/g, "_")}_*`;+}+/**- * Engine permission block for every managed desktop: in guarded mode the- * built-in git and PR workflow rules (read-only commands run, write commands- * ask once per session per command family, destructive commands always ask);- * in full mode a single catch-all allow for bash, a catch-all allow for read- * (the engine's own defaults ask before reading `*.env` and `*.env.*`; the- * later `read *` allow wins) and allow for every other permission category- * the pinned engine exposes, so nothing asks. Both are- * followed by the organization's execution policy. The engine picks the last- * matching rule, so an organization deny always wins over a workflow or- * full-mode allow.+ * Engine permission block for every managed desktop, by approval mode:+ *+ * full a single catch-all allow for bash, a catch-all allow for read+ * (the engine's own defaults ask before reading `*.env` and+ * `*.env.*`; the later `read *` allow wins) and allow for every+ * other permission category the pinned engine exposes, so nothing+ * asks.+ * guarded (Normal) the shared Normal rules for bash and read+ * (permissions/permission-modes.json, the CLI's file), then the+ * built-in git and PR workflow rules (read-only commands run,+ * write commands ask once per session per command family,+ * destructive commands always ask), plus an ask rule for every+ * configured MCP server not on the shared allowlist. The shared+ * top-level catch-all and external_directory rules are left out:+ * the engine's own external_directory handling and the+ * authorized-folder grants stay in charge of other folders.+ * careful the shared Careful rules without external_directory: a "*" ask+ * catch-all (the runtime config moves it ahead of the user's+ * rules) with reads and searches allowed, every edit and command+ * asking.+ *+ * All are followed by the organization's execution policy. The engine picks+ * the last matching rule, so an organization deny always wins over a+ * workflow or mode allow.*/-export function legacyExecutionPermissions(policy: DesktopExecutionPolicy | undefined, mode: ApprovalMode = "guarded"): LegacyExecutionPermissions {- const permissions: LegacyExecutionPermissions = mode === "full"- ? { bash: { "*": "allow" }, read: { "*": "allow" }, edit: "allow", webfetch: "allow", websearch: "allow", doom_loop: "allow", external_directory: "allow" }- : { bash: gitWorkflowPermissionRules() };+export function legacyExecutionPermissions(+ policy: DesktopExecutionPolicy | undefined,+ mode: ApprovalMode = "guarded",+ mcpServers: readonly string[] = [],+): LegacyExecutionPermissions {+ let permissions: LegacyExecutionPermissions;+ if (mode === "full") {+ permissions = { bash: { "*": "allow" }, read: { "*": "allow" }, edit: "allow", webfetch: "allow", websearch: "allow", doom_loop: "allow", external_directory: "allow" };+ } else if (mode === "careful") {+ const { external_directory: _external, ...careful } = cloneRules(SHARED_MODES.careful);+ permissions = { ...careful, bash: { ...(careful.bash as Record<string, PermissionAction>) } } as LegacyExecutionPermissions;+ } else {+ const normal = cloneRules(SHARED_MODES.normal);+ const bash = { ...(normal.bash as Record<string, PermissionAction>) };+ // Re-insert every git workflow rule after the shared ones, so a pattern+ // both lists use keeps the git rules' own order (the last match wins).+ for (const [pattern, action] of Object.entries(gitWorkflowPermissionRules())) {+ delete bash[pattern];+ bash[pattern] = action;+ }+ permissions = { bash, read: normal.read as Record<string, PermissionAction> };+ const allowlist = new Set<string>(permissionModes.mcpAllowlist as string[]);+ for (const server of mcpServers) {+ if (!allowlist.has(server)) permissions[mcpToolPermissionKey(server)] = "ask";+ }+ }for (const rule of executionRules(policy)) {if (rule.action === "shell") {// Re-insert so a pattern the workflow rules already use moves after them.diff --git a/apps/server/src/omnirush-runtime-config.test.ts b/apps/server/src/omnirush-runtime-config.test.tsindex 4f60eabd..2fa5fea7 100644--- a/apps/server/src/omnirush-runtime-config.test.ts+++ b/apps/server/src/omnirush-runtime-config.test.ts@@ -34,7 +34,10 @@ import {writeOmniRushModelCatalog,type OmniRushModelCatalog,} from "./omnirush-model-catalog.js";-import { gitWorkflowPermissionRules } from "./git-command-policy.js";+import { legacyExecutionPermissions } from "./managed-policy-rules.js";++/** The default (Normal) injected permission block: shared Normal bash/read rules, then the git workflow rules. */+const GUARDED = { ...legacyExecutionPermissions(undefined, "guarded"), "mcp.*": "deny" };import { OMNIRUSH_AGENT_PROMPT } from "./omnirush-agent-prompt.js";import { BestPracticesEngineReloads, OMNIRUSH_BEST_PRACTICES, omnirushBestPracticesSkillsDir, waitForBestPracticesReady } from "./best-practices.js";import type { ServerConfig } from "./types.js";@@ -115,14 +118,15 @@ describe("omnirush runtime config file", () => {},},});- // The built-in git workflow rules come first; the organization's execution- // rules are appended last so the engine's last-match-wins evaluation keeps them.- const permission = { bash: { ...gitWorkflowPermissionRules(), "*": "deny", "curl *": "deny" }, webfetch: "deny", websearch: "deny" };+ // Normal's shared rules and the built-in git workflow rules come first; the organization's+ // execution rules are appended last so the engine's last-match-wins evaluation keeps them.+ const { "*": _allow, ...guardedBash } = legacyExecutionPermissions(undefined).bash;+ const permission = { bash: { ...guardedBash, "*": "deny", "curl *": "deny" }, read: GUARDED.read, webfetch: "deny", websearch: "deny" };expect(parsed.permission).toEqual(permission);expect(Object.keys((parsed.permission as { bash: Record<string, string> }).bash).slice(-2)).toEqual(["*", "curl *"]);expect(parsed.agent).toMatchObject({ omnirush: { permission } });expect(parsed.managedPolicy).toBeUndefined();- expect(buildOmniRushRuntimeConfigObjectFromSnapshot({}).permission).toEqual({ bash: gitWorkflowPermissionRules() });+ expect(buildOmniRushRuntimeConfigObjectFromSnapshot({}).permission).toEqual(GUARDED);});test("full approval mode allows every permission category; the environment overrides the setting", () => {@@ -138,7 +142,7 @@ describe("omnirush runtime config file", () => {expect(full.approvals).toBeUndefined();// The engine asks before reading .env files by default and appends the injected block after its- // own rules; the full-mode catch-all read allow wins, the guarded block leaves the default alone.+ // own rules; the full-mode catch-all read allow wins, the guarded block keeps asking.const engineEnvDefaults = [{ permission: "read", pattern: "*.env", action: "ask" as const }, { permission: "read", pattern: "*.env.*", action: "ask" as const }];const guarded = buildOmniRushRuntimeConfigObjectFromSnapshot({}, undefined, {});for (const file of ["/workspace/.env", "/workspace/.env.local"]) {@@ -155,9 +159,9 @@ describe("omnirush runtime config file", () => {// OMNIRUSH_APPROVALS on the server process wins in both directions; the default stays guarded.expect(buildOmniRushRuntimeConfigObjectFromSnapshot({ approvals: { mode: "full" } }, undefined, { OMNIRUSH_APPROVALS: "guarded" }).permission)- .toEqual({ bash: gitWorkflowPermissionRules() });+ .toEqual(GUARDED);expect(buildOmniRushRuntimeConfigObjectFromSnapshot({}, undefined, { OMNIRUSH_APPROVALS: "full" }).permission).toEqual(permission);- expect(buildOmniRushRuntimeConfigObjectFromSnapshot({}, undefined, {}).permission).toEqual({ bash: gitWorkflowPermissionRules() });+ expect(buildOmniRushRuntimeConfigObjectFromSnapshot({}, undefined, {}).permission).toEqual(GUARDED);});test("omits global-row MCPs while writing omnirush defaults into the file", async () => {@@ -210,7 +214,8 @@ describe("omnirush runtime config file", () => {env: ["OMNIRUSH_ACCESS_TOKEN"],options: { baseURL: "http://127.0.0.1:8090/omnirush/v1" },});- expect(JSON.stringify(parsed)).not.toContain("access-token");+ // The permission rules name commands that print access tokens; no token value is anywhere else.+ expect(JSON.stringify({ ...parsed, permission: undefined, agent: undefined })).not.toContain("access-token");});test("exposes every omnirush.ai model with the shared effort levels, default first", () => {diff --git a/apps/server/src/omnirush-runtime-config.ts b/apps/server/src/omnirush-runtime-config.tsindex 9b3ed74f..4f76b720 100644--- a/apps/server/src/omnirush-runtime-config.ts+++ b/apps/server/src/omnirush-runtime-config.ts@@ -230,7 +230,10 @@ export function buildOmniRushRuntimeConfigObjectFromSnapshot(): Record<string, unknown> {const disabledProviders = runtimeDisabledProviderList(runtimeConfig);// OMNIRUSH_APPROVALS in the server environment wins over the persisted setting.- const permissions = legacyExecutionPermissions(runtimeConfig.managedPolicy?.execution, resolveApprovalMode(runtimeConfig, env).mode);+ const { "*": catchAll, ...permissions } = legacyExecutionPermissions(runtimeConfig.managedPolicy?.execution, resolveApprovalMode(runtimeConfig, env).mode);+ // A top-level `task` rule would reach every sub-agent (explore must not+ // delegate): Careful's task allow goes to the main agent only.+ const { task: mainAgentTask, ...topLevelPermissions } = permissions;// The global row's MCP entries are the account-linked Connect server, which// this app does not run; a project's own servers reach the engine through// its config files and the MCP plugin (opencode-plugins/omnirush-mcp-policy.ts).@@ -266,7 +269,11 @@ export function buildOmniRushRuntimeConfigObjectFromSnapshot(...ownProviders,...(runtimeConfig.managedPolicy.allowZenModel !== false ? ["opencode"] : []),] } : onlyOwnProviders ? { enabled_providers: ownProviders } : {}),- permission: { ...engineConfig.permission, ...permissions },+ // Careful's "*" ask goes first: after the engine's own allow-everything+ // default, but before the user's rules (authorized-folder grants) and+ // ours, which all stay in force. The main agent's own block below leaves+ // it out, or it would come after (and override) the user's grants.+ permission: { ...(catchAll ? { "*": catchAll } : {}), ...engineConfig.permission, ...topLevelPermissions },// omnirush.ai's own on-demand skills (the swarm procedure)....(skillPaths.length ? { skills: { paths: skillPaths } } : {}),default_agent: runtimeConfig.default_agent ?? "omnirush",@@ -281,7 +288,8 @@ export function buildOmniRushRuntimeConfigObjectFromSnapshot(temperature: 0.2,prompt: enabled ? `${OMNIRUSH_AGENT_PROMPT}\n\n${OMNIRUSH_BEST_PRACTICES.systemPrompt}` : OMNIRUSH_AGENT_PROMPT,permission: {- ...permissions,+ ...topLevelPermissions,+ ...(mainAgentTask ? { task: mainAgentTask } : {}),skill: {// OmniRush.ai supplies its own current skill routing and no longer// supports these engine or legacy workspace skills.diff --git a/apps/server/src/permissions/PARITY.sha256 b/apps/server/src/permissions/PARITY.sha256new file mode 100644index 00000000..96c03e01--- /dev/null+++ b/apps/server/src/permissions/PARITY.sha256@@ -0,0 +1,3 @@+# permission-modes.json is the same file in omnirush-cli (src/permissions/) and omnirush-gui (apps/server/src/permissions/).+# A change to one must be ported to the other and this list updated in both.+253b9498654f6a9e293a4028f72bb3ebe3d891d6c4b59e931a6acf9ca46b4ac8 permission-modes.jsondiff --git a/apps/server/src/permissions/permission-modes.json b/apps/server/src/permissions/permission-modes.jsonnew file mode 100644index 00000000..de710a30--- /dev/null+++ b/apps/server/src/permissions/permission-modes.json@@ -0,0 +1,718 @@+{+ "$comment": "Permission modes shared by the CLI (src/permissions/) and the desktop app (apps/server/src/permissions/): engine permission rules per mode, in evaluation order (the engine takes the LAST matching rule). Keep the two copies byte-identical (PARITY.sha256).",+ "version": 1,+ "modes": [+ "careful",+ "normal",+ "auto"+ ],+ "default": "normal",+ "headless": "auto",+ "labels": {+ "careful": {+ "title": "Careful",+ "summary": "Asks before every file change and every command. Reading and searching run freely."+ },+ "normal": {+ "title": "Normal",+ "summary": "Asks only before risky actions: recursive deletes, sudo, git push or hard resets, changes outside the project, reading secrets, piping downloads into a shell, publishing packages."+ },+ "auto": {+ "title": "Auto",+ "summary": "Never asks. The agent runs everything it decides to run."+ }+ },+ "tempDirs": [+ "/tmp",+ "/private/tmp",+ "/var/folders"+ ],+ "mcpAllowlist": [],+ "rules": {+ "careful": {+ "*": "ask",+ "read": {+ "*": "allow",+ "*.env": "ask",+ "*.env.*": "ask",+ "*.env.example": "allow",+ "*.env.sample": "allow",+ "*.env.template": "allow",+ "*.env.dist": "allow",+ "*.env.defaults": "allow",+ "*.pem": "ask",+ "*.key": "ask",+ "*.p12": "ask",+ "*.pfx": "ask",+ "*.keystore": "ask",+ "*.jks": "ask",+ "*id_rsa": "ask",+ "*id_rsa.*": "ask",+ "*id_ed25519": "ask",+ "*id_ed25519.*": "ask",+ "*id_ecdsa": "ask",+ "*id_ecdsa.*": "ask",+ "*id_dsa": "ask",+ "*.ssh/*": "ask",+ "*.aws/credentials": "ask",+ "*.aws/config": "ask",+ "*.netrc": "ask",+ "*.git-credentials": "ask",+ "*.docker/config.json": "ask",+ "*.kube/config": "ask",+ "*.gnupg/*": "ask",+ "*.npmrc": "ask",+ "*.pypirc": "ask",+ "*credentials.json": "ask",+ "*service-account*.json": "ask",+ "*.config/gh/hosts.yml": "ask",+ "*.htpasswd": "ask"+ },+ "glob": "allow",+ "grep": "allow",+ "list": "allow",+ "lsp": "allow",+ "codesearch": "allow",+ "webfetch": "allow",+ "websearch": "allow",+ "todowrite": "allow",+ "todoread": "allow",+ "question": "allow",+ "plan_enter": "allow",+ "plan_exit": "allow",+ "skill": "allow",+ "task": "allow",+ "edit": "ask",+ "bash": {+ "*": "ask"+ },+ "external_directory": {+ "*": "ask"+ },+ "doom_loop": "ask"+ },+ "normal": {+ "*": "allow",+ "bash": {+ "*": "allow",+ "rm -r*": "ask",+ "rm -R*": "ask",+ "rm -fr*": "ask",+ "rm -fR*": "ask",+ "rm -vr*": "ask",+ "rm -vR*": "ask",+ "rm -dr*": "ask",+ "rm -dR*": "ask",+ "rm -ir*": "ask",+ "rm -iR*": "ask",+ "rm -fvr*": "ask",+ "rm -fvR*": "ask",+ "rm -vfr*": "ask",+ "rm -vfR*": "ask",+ "rm -fdr*": "ask",+ "rm -fdR*": "ask",+ "rm -dfr*": "ask",+ "rm -dfR*": "ask",+ "rm -dvr*": "ask",+ "rm -dvR*": "ask",+ "rm -vdr*": "ask",+ "rm -vdR*": "ask",+ "rm -fir*": "ask",+ "rm -fiR*": "ask",+ "rm -ifr*": "ask",+ "rm -ifR*": "ask",+ "rm * -r*": "ask",+ "rm * -R*": "ask",+ "rm * -fr*": "ask",+ "rm * -fR*": "ask",+ "rm * -vr*": "ask",+ "rm * -vR*": "ask",+ "rm * -dr*": "ask",+ "rm * -dR*": "ask",+ "rm * -ir*": "ask",+ "rm * -iR*": "ask",+ "rm * -fvr*": "ask",+ "rm * -fvR*": "ask",+ "rm * -vfr*": "ask",+ "rm * -vfR*": "ask",+ "rm * -fdr*": "ask",+ "rm * -fdR*": "ask",+ "rm * -dfr*": "ask",+ "rm * -dfR*": "ask",+ "rm * -dvr*": "ask",+ "rm * -dvR*": "ask",+ "rm * -vdr*": "ask",+ "rm * -vdR*": "ask",+ "rm * -fir*": "ask",+ "rm * -fiR*": "ask",+ "rm * -ifr*": "ask",+ "rm * -ifR*": "ask",+ "rm --recursive*": "ask",+ "rm * --recursive*": "ask",+ "rm -f -r*": "ask",+ "rm -f -R*": "ask",+ "find * -delete*": "ask",+ "find * -exec rm *": "ask",+ "find * -execdir rm *": "ask",+ "Remove-Item -Recurse*": "ask",+ "Remove-Item * -Recurse*": "ask",+ "rm -Recurse*": "ask",+ "rm * -Recurse*": "ask",+ "ri -Recurse*": "ask",+ "ri * -Recurse*": "ask",+ "rmdir /s*": "ask",+ "rmdir * /s*": "ask",+ "rd /s*": "ask",+ "rd * /s*": "ask",+ "del /s*": "ask",+ "del * /s*": "ask",+ "shred *": "ask",+ "mkfs*": "ask",+ "dd * of=/dev/*": "ask",+ "/bin/rm -r*": "ask",+ "/usr/bin/rm -r*": "ask",+ "command rm -r*": "ask",+ "/bin/rm -R*": "ask",+ "/usr/bin/rm -R*": "ask",+ "command rm -R*": "ask",+ "/bin/rm -fr*": "ask",+ "/usr/bin/rm -fr*": "ask",+ "command rm -fr*": "ask",+ "/bin/rm -fR*": "ask",+ "/usr/bin/rm -fR*": "ask",+ "command rm -fR*": "ask",+ "/bin/rm -vr*": "ask",+ "/usr/bin/rm -vr*": "ask",+ "command rm -vr*": "ask",+ "/bin/rm -vR*": "ask",+ "/usr/bin/rm -vR*": "ask",+ "command rm -vR*": "ask",+ "/bin/rm -dr*": "ask",+ "/usr/bin/rm -dr*": "ask",+ "command rm -dr*": "ask",+ "/bin/rm -dR*": "ask",+ "/usr/bin/rm -dR*": "ask",+ "command rm -dR*": "ask",+ "/bin/rm -ir*": "ask",+ "/usr/bin/rm -ir*": "ask",+ "command rm -ir*": "ask",+ "/bin/rm -iR*": "ask",+ "/usr/bin/rm -iR*": "ask",+ "command rm -iR*": "ask",+ "/bin/rm -fvr*": "ask",+ "/usr/bin/rm -fvr*": "ask",+ "command rm -fvr*": "ask",+ "/bin/rm -fvR*": "ask",+ "/usr/bin/rm -fvR*": "ask",+ "command rm -fvR*": "ask",+ "/bin/rm -vfr*": "ask",+ "/usr/bin/rm -vfr*": "ask",+ "command rm -vfr*": "ask",+ "/bin/rm -vfR*": "ask",+ "/usr/bin/rm -vfR*": "ask",+ "command rm -vfR*": "ask",+ "/bin/rm -fdr*": "ask",+ "/usr/bin/rm -fdr*": "ask",+ "command rm -fdr*": "ask",+ "/bin/rm -fdR*": "ask",+ "/usr/bin/rm -fdR*": "ask",+ "command rm -fdR*": "ask",+ "/bin/rm -dfr*": "ask",+ "/usr/bin/rm -dfr*": "ask",+ "command rm -dfr*": "ask",+ "/bin/rm -dfR*": "ask",+ "/usr/bin/rm -dfR*": "ask",+ "command rm -dfR*": "ask",+ "/bin/rm -dvr*": "ask",+ "/usr/bin/rm -dvr*": "ask",+ "command rm -dvr*": "ask",+ "/bin/rm -dvR*": "ask",+ "/usr/bin/rm -dvR*": "ask",+ "command rm -dvR*": "ask",+ "/bin/rm -vdr*": "ask",+ "/usr/bin/rm -vdr*": "ask",+ "command rm -vdr*": "ask",+ "/bin/rm -vdR*": "ask",+ "/usr/bin/rm -vdR*": "ask",+ "command rm -vdR*": "ask",+ "/bin/rm -fir*": "ask",+ "/usr/bin/rm -fir*": "ask",+ "command rm -fir*": "ask",+ "/bin/rm -fiR*": "ask",+ "/usr/bin/rm -fiR*": "ask",+ "command rm -fiR*": "ask",+ "/bin/rm -ifr*": "ask",+ "/usr/bin/rm -ifr*": "ask",+ "command rm -ifr*": "ask",+ "/bin/rm -ifR*": "ask",+ "/usr/bin/rm -ifR*": "ask",+ "command rm -ifR*": "ask",+ "/bin/rm * -r*": "ask",+ "/usr/bin/rm * -r*": "ask",+ "command rm * -r*": "ask",+ "/bin/rm * -R*": "ask",+ "/usr/bin/rm * -R*": "ask",+ "command rm * -R*": "ask",+ "/bin/rm * -fr*": "ask",+ "/usr/bin/rm * -fr*": "ask",+ "command rm * -fr*": "ask",+ "/bin/rm * -fR*": "ask",+ "/usr/bin/rm * -fR*": "ask",+ "command rm * -fR*": "ask",+ "/bin/rm * -vr*": "ask",+ "/usr/bin/rm * -vr*": "ask",+ "command rm * -vr*": "ask",+ "/bin/rm * -vR*": "ask",+ "/usr/bin/rm * -vR*": "ask",+ "command rm * -vR*": "ask",+ "/bin/rm * -dr*": "ask",+ "/usr/bin/rm * -dr*": "ask",+ "command rm * -dr*": "ask",+ "/bin/rm * -dR*": "ask",+ "/usr/bin/rm * -dR*": "ask",+ "command rm * -dR*": "ask",+ "/bin/rm * -ir*": "ask",+ "/usr/bin/rm * -ir*": "ask",+ "command rm * -ir*": "ask",+ "/bin/rm * -iR*": "ask",+ "/usr/bin/rm * -iR*": "ask",+ "command rm * -iR*": "ask",+ "/bin/rm * -fvr*": "ask",+ "/usr/bin/rm * -fvr*": "ask",+ "command rm * -fvr*": "ask",+ "/bin/rm * -fvR*": "ask",+ "/usr/bin/rm * -fvR*": "ask",+ "command rm * -fvR*": "ask",+ "/bin/rm * -vfr*": "ask",+ "/usr/bin/rm * -vfr*": "ask",+ "command rm * -vfr*": "ask",+ "/bin/rm * -vfR*": "ask",+ "/usr/bin/rm * -vfR*": "ask",+ "command rm * -vfR*": "ask",+ "/bin/rm * -fdr*": "ask",+ "/usr/bin/rm * -fdr*": "ask",+ "command rm * -fdr*": "ask",+ "/bin/rm * -fdR*": "ask",+ "/usr/bin/rm * -fdR*": "ask",+ "command rm * -fdR*": "ask",+ "/bin/rm * -dfr*": "ask",+ "/usr/bin/rm * -dfr*": "ask",+ "command rm * -dfr*": "ask",+ "/bin/rm * -dfR*": "ask",+ "/usr/bin/rm * -dfR*": "ask",+ "command rm * -dfR*": "ask",+ "/bin/rm * -dvr*": "ask",+ "/usr/bin/rm * -dvr*": "ask",+ "command rm * -dvr*": "ask",+ "/bin/rm * -dvR*": "ask",+ "/usr/bin/rm * -dvR*": "ask",+ "command rm * -dvR*": "ask",+ "/bin/rm * -vdr*": "ask",+ "/usr/bin/rm * -vdr*": "ask",+ "command rm * -vdr*": "ask",+ "/bin/rm * -vdR*": "ask",+ "/usr/bin/rm * -vdR*": "ask",+ "command rm * -vdR*": "ask",+ "/bin/rm * -fir*": "ask",+ "/usr/bin/rm * -fir*": "ask",+ "command rm * -fir*": "ask",+ "/bin/rm * -fiR*": "ask",+ "/usr/bin/rm * -fiR*": "ask",+ "command rm * -fiR*": "ask",+ "/bin/rm * -ifr*": "ask",+ "/usr/bin/rm * -ifr*": "ask",+ "command rm * -ifr*": "ask",+ "/bin/rm * -ifR*": "ask",+ "/usr/bin/rm * -ifR*": "ask",+ "command rm * -ifR*": "ask",+ "/bin/rm --recursive*": "ask",+ "/usr/bin/rm --recursive*": "ask",+ "command rm --recursive*": "ask",+ "/bin/rm * --recursive*": "ask",+ "/usr/bin/rm * --recursive*": "ask",+ "command rm * --recursive*": "ask",+ "/bin/rm -f -r*": "ask",+ "/usr/bin/rm -f -r*": "ask",+ "command rm -f -r*": "ask",+ "/bin/rm -f -R*": "ask",+ "/usr/bin/rm -f -R*": "ask",+ "command rm -f -R*": "ask",+ "/bin/rm -Recurse*": "ask",+ "/usr/bin/rm -Recurse*": "ask",+ "command rm -Recurse*": "ask",+ "/bin/rm * -Recurse*": "ask",+ "/usr/bin/rm * -Recurse*": "ask",+ "command rm * -Recurse*": "ask",+ "sudo": "ask",+ "sudo *": "ask",+ "doas *": "ask",+ "su": "ask",+ "su *": "ask",+ "pkexec *": "ask",+ "gsudo *": "ask",+ "runas *": "ask",+ "Start-Process * -Verb RunAs*": "ask",+ "git push": "ask",+ "git push *": "ask",+ "git reset --hard*": "ask",+ "git reset * --hard*": "ask",+ "git clean -*f*": "ask",+ "git clean --force*": "ask",+ "git checkout -f*": "ask",+ "git checkout --force*": "ask",+ "git checkout -- *": "ask",+ "git checkout . *": "ask",+ "git checkout .": "ask",+ "git restore *": "ask",+ "git stash drop*": "ask",+ "git stash clear*": "ask",+ "git branch -D *": "ask",+ "git branch * -D*": "ask",+ "git branch --delete --force*": "ask",+ "git filter-branch*": "ask",+ "git filter-repo*": "ask",+ "git update-ref -d *": "ask",+ "git reflog expire*": "ask",+ "git -C * push": "ask",+ "git -C * push *": "ask",+ "git -C * reset --hard*": "ask",+ "git -C * reset * --hard*": "ask",+ "git -C * clean -*f*": "ask",+ "git -C * clean --force*": "ask",+ "git -C * checkout -f*": "ask",+ "git -C * checkout --force*": "ask",+ "git -C * checkout -- *": "ask",+ "git -C * checkout . *": "ask",+ "git -C * checkout .": "ask",+ "git -C * restore *": "ask",+ "git -C * stash drop*": "ask",+ "git -C * stash clear*": "ask",+ "git -C * branch -D *": "ask",+ "git -C * branch * -D*": "ask",+ "git -C * branch --delete --force*": "ask",+ "git -C * filter-branch*": "ask",+ "git -C * filter-repo*": "ask",+ "git -C * update-ref -d *": "ask",+ "git -C * reflog expire*": "ask",+ "git -c * push": "ask",+ "git -c * push *": "ask",+ "git -c * reset --hard*": "ask",+ "git -c * reset * --hard*": "ask",+ "git -c * clean -*f*": "ask",+ "git -c * clean --force*": "ask",+ "git -c * checkout -f*": "ask",+ "git -c * checkout --force*": "ask",+ "git -c * checkout -- *": "ask",+ "git -c * checkout . *": "ask",+ "git -c * checkout .": "ask",+ "git -c * restore *": "ask",+ "git -c * stash drop*": "ask",+ "git -c * stash clear*": "ask",+ "git -c * branch -D *": "ask",+ "git -c * branch * -D*": "ask",+ "git -c * branch --delete --force*": "ask",+ "git -c * filter-branch*": "ask",+ "git -c * filter-repo*": "ask",+ "git -c * update-ref -d *": "ask",+ "git -c * reflog expire*": "ask",+ "git --no-pager push": "ask",+ "git --no-pager push *": "ask",+ "git --no-pager reset --hard*": "ask",+ "git --no-pager reset * --hard*": "ask",+ "git --no-pager clean -*f*": "ask",+ "git --no-pager clean --force*": "ask",+ "git --no-pager checkout -f*": "ask",+ "git --no-pager checkout --force*": "ask",+ "git --no-pager checkout -- *": "ask",+ "git --no-pager checkout . *": "ask",+ "git --no-pager checkout .": "ask",+ "git --no-pager restore *": "ask",+ "git --no-pager stash drop*": "ask",+ "git --no-pager stash clear*": "ask",+ "git --no-pager branch -D *": "ask",+ "git --no-pager branch * -D*": "ask",+ "git --no-pager branch --delete --force*": "ask",+ "git --no-pager filter-branch*": "ask",+ "git --no-pager filter-repo*": "ask",+ "git --no-pager update-ref -d *": "ask",+ "git --no-pager reflog expire*": "ask",+ "git restore --staged *": "allow",+ "git -C * restore --staged *": "allow",+ "git push --dry-run*": "allow",+ "git push -n *": "allow",+ "gh repo delete*": "ask",+ "gh release create*": "ask",+ "gh release delete*": "ask",+ "gh release upload*": "ask",+ "gh pr merge*": "ask",+ "gh secret *": "ask",+ "gh auth token*": "ask",+ "sh": "ask",+ "bash": "ask",+ "zsh": "ask",+ "dash": "ask",+ "ksh": "ask",+ "fish": "ask",+ "sh -": "ask",+ "bash -": "ask",+ "zsh -": "ask",+ "sh -s*": "ask",+ "bash -s*": "ask",+ "zsh -s*": "ask",+ "python": "ask",+ "python3": "ask",+ "python -": "ask",+ "python3 -": "ask",+ "node": "ask",+ "node -": "ask",+ "perl": "ask",+ "ruby": "ask",+ "php": "ask",+ "sh <(*": "ask",+ "bash <(*": "ask",+ "zsh <(*": "ask",+ "source <(*": "ask",+ ". <(*": "ask",+ "sh -c *curl *": "ask",+ "sh -c *wget *": "ask",+ "bash -c *curl *": "ask",+ "bash -c *wget *": "ask",+ "zsh -c *curl *": "ask",+ "zsh -c *wget *": "ask",+ "eval *curl *": "ask",+ "eval *wget *": "ask",+ "iex": "ask",+ "iex *": "ask",+ "Invoke-Expression*": "ask",+ "powershell * iex *": "ask",+ "pwsh * iex *": "ask",+ "powershell * Invoke-Expression*": "ask",+ "pwsh * Invoke-Expression*": "ask",+ "npm publish*": "ask",+ "npm unpublish*": "ask",+ "npm deprecate*": "ask",+ "pnpm publish*": "ask",+ "yarn publish*": "ask",+ "yarn npm publish*": "ask",+ "bun publish*": "ask",+ "npx * publish*": "ask",+ "lerna publish*": "ask",+ "changeset publish*": "ask",+ "semantic-release*": "ask",+ "npx semantic-release*": "ask",+ "cargo publish*": "ask",+ "cargo yank*": "ask",+ "twine upload*": "ask",+ "poetry publish*": "ask",+ "uv publish*": "ask",+ "hatch publish*": "ask",+ "flit publish*": "ask",+ "python -m twine upload*": "ask",+ "python3 -m twine upload*": "ask",+ "gem push*": "ask",+ "gem yank*": "ask",+ "dotnet nuget push*": "ask",+ "nuget push*": "ask",+ "mvn deploy*": "ask",+ "mvn * deploy*": "ask",+ "gradle publish*": "ask",+ "./gradlew publish*": "ask",+ "gradlew publish*": "ask",+ "docker push*": "ask",+ "podman push*": "ask",+ "helm push*": "ask",+ "pod trunk push*": "ask",+ "deno publish*": "ask",+ "vsce publish*": "ask",+ "ovsx publish*": "ask",+ "jsr publish*": "ask",+ "mix hex.publish*": "ask",+ "dart pub publish*": "ask",+ "flutter pub publish*": "ask",+ "swift package-registry publish*": "ask",+ "* .env": "ask",+ "* .env *": "ask",+ "* */.env": "ask",+ "* */.env *": "ask",+ "* .env.*": "ask",+ "* */.env.*": "ask",+ "*/.ssh/*": "ask",+ "* ~/.ssh*": "ask",+ "* $HOME/.ssh*": "ask",+ "*id_rsa*": "ask",+ "*id_ed25519*": "ask",+ "*id_ecdsa*": "ask",+ "*id_dsa*": "ask",+ "*.pem": "ask",+ "*.pem *": "ask",+ "*.key": "ask",+ "*.key *": "ask",+ "*.p12*": "ask",+ "*.pfx*": "ask",+ "*.keystore*": "ask",+ "*.jks*": "ask",+ "*/.aws/*": "ask",+ "* ~/.aws*": "ask",+ "*/.netrc*": "ask",+ "* ~/.netrc*": "ask",+ "*.git-credentials*": "ask",+ "*/.docker/config.json*": "ask",+ "*/.kube/config*": "ask",+ "* ~/.kube*": "ask",+ "*/.gnupg/*": "ask",+ "* ~/.gnupg*": "ask",+ "* ~/.npmrc*": "ask",+ "*/.npmrc": "ask",+ "* ~/.pypirc*": "ask",+ "*/.pypirc*": "ask",+ "*/.config/gh/hosts.yml*": "ask",+ "*/environ*": "ask",+ "printenv*": "ask",+ "env": "ask",+ "set": "ask",+ "Get-ChildItem env:*": "ask",+ "gci env:*": "ask",+ "dir env:*": "ask",+ "security find-generic-password*": "ask",+ "security find-internet-password*": "ask",+ "security dump-keychain*": "ask",+ "gcloud auth print-access-token*": "ask",+ "gcloud auth print-identity-token*": "ask",+ "aws configure get*": "ask",+ "aws configure export-credentials*": "ask",+ "az account get-access-token*": "ask",+ "rm -r /tmp/*": "allow",+ "rm -r /private/tmp/*": "allow",+ "rm -r /var/folders/*": "allow",+ "rm -r $TMPDIR/*": "allow",+ "rm -r ${TMPDIR}/*": "allow",+ "rm -r \"$TMPDIR\"/*": "allow",+ "rm -r \"$TMPDIR/*": "allow",+ "rm -R /tmp/*": "allow",+ "rm -R /private/tmp/*": "allow",+ "rm -R /var/folders/*": "allow",+ "rm -R $TMPDIR/*": "allow",+ "rm -R ${TMPDIR}/*": "allow",+ "rm -R \"$TMPDIR\"/*": "allow",+ "rm -R \"$TMPDIR/*": "allow",+ "rm -rf /tmp/*": "allow",+ "rm -rf /private/tmp/*": "allow",+ "rm -rf /var/folders/*": "allow",+ "rm -rf $TMPDIR/*": "allow",+ "rm -rf ${TMPDIR}/*": "allow",+ "rm -rf \"$TMPDIR\"/*": "allow",+ "rm -rf \"$TMPDIR/*": "allow",+ "rm -fr /tmp/*": "allow",+ "rm -fr /private/tmp/*": "allow",+ "rm -fr /var/folders/*": "allow",+ "rm -fr $TMPDIR/*": "allow",+ "rm -fr ${TMPDIR}/*": "allow",+ "rm -fr \"$TMPDIR\"/*": "allow",+ "rm -fr \"$TMPDIR/*": "allow",+ "rm -Rf /tmp/*": "allow",+ "rm -Rf /private/tmp/*": "allow",+ "rm -Rf /var/folders/*": "allow",+ "rm -Rf $TMPDIR/*": "allow",+ "rm -Rf ${TMPDIR}/*": "allow",+ "rm -Rf \"$TMPDIR\"/*": "allow",+ "rm -Rf \"$TMPDIR/*": "allow",+ "rm -fR /tmp/*": "allow",+ "rm -fR /private/tmp/*": "allow",+ "rm -fR /var/folders/*": "allow",+ "rm -fR $TMPDIR/*": "allow",+ "rm -fR ${TMPDIR}/*": "allow",+ "rm -fR \"$TMPDIR\"/*": "allow",+ "rm -fR \"$TMPDIR/*": "allow",+ "rm -r /tmp/* ?*": "ask",+ "rm -r /private/tmp/* ?*": "ask",+ "rm -r /var/folders/* ?*": "ask",+ "rm -r $TMPDIR/* ?*": "ask",+ "rm -r ${TMPDIR}/* ?*": "ask",+ "rm -r \"$TMPDIR\"/* ?*": "ask",+ "rm -r \"$TMPDIR/* ?*": "ask",+ "rm -R /tmp/* ?*": "ask",+ "rm -R /private/tmp/* ?*": "ask",+ "rm -R /var/folders/* ?*": "ask",+ "rm -R $TMPDIR/* ?*": "ask",+ "rm -R ${TMPDIR}/* ?*": "ask",+ "rm -R \"$TMPDIR\"/* ?*": "ask",+ "rm -R \"$TMPDIR/* ?*": "ask",+ "rm -rf /tmp/* ?*": "ask",+ "rm -rf /private/tmp/* ?*": "ask",+ "rm -rf /var/folders/* ?*": "ask",+ "rm -rf $TMPDIR/* ?*": "ask",+ "rm -rf ${TMPDIR}/* ?*": "ask",+ "rm -rf \"$TMPDIR\"/* ?*": "ask",+ "rm -rf \"$TMPDIR/* ?*": "ask",+ "rm -fr /tmp/* ?*": "ask",+ "rm -fr /private/tmp/* ?*": "ask",+ "rm -fr /var/folders/* ?*": "ask",+ "rm -fr $TMPDIR/* ?*": "ask",+ "rm -fr ${TMPDIR}/* ?*": "ask",+ "rm -fr \"$TMPDIR\"/* ?*": "ask",+ "rm -fr \"$TMPDIR/* ?*": "ask",+ "rm -Rf /tmp/* ?*": "ask",+ "rm -Rf /private/tmp/* ?*": "ask",+ "rm -Rf /var/folders/* ?*": "ask",+ "rm -Rf $TMPDIR/* ?*": "ask",+ "rm -Rf ${TMPDIR}/* ?*": "ask",+ "rm -Rf \"$TMPDIR\"/* ?*": "ask",+ "rm -Rf \"$TMPDIR/* ?*": "ask",+ "rm -fR /tmp/* ?*": "ask",+ "rm -fR /private/tmp/* ?*": "ask",+ "rm -fR /var/folders/* ?*": "ask",+ "rm -fR $TMPDIR/* ?*": "ask",+ "rm -fR ${TMPDIR}/* ?*": "ask",+ "rm -fR \"$TMPDIR\"/* ?*": "ask",+ "rm -fR \"$TMPDIR/* ?*": "ask",+ "rm *..*": "ask",+ "rm *$(*": "ask",+ "rm *`*": "ask",+ "rm *;*": "ask",+ "rm *&*": "ask",+ "rm *|*": "ask"+ },+ "read": {+ "*": "allow",+ "*.env": "ask",+ "*.env.*": "ask",+ "*.env.example": "allow",+ "*.env.sample": "allow",+ "*.env.template": "allow",+ "*.env.dist": "allow",+ "*.env.defaults": "allow",+ "*.pem": "ask",+ "*.key": "ask",+ "*.p12": "ask",+ "*.pfx": "ask",+ "*.keystore": "ask",+ "*.jks": "ask",+ "*id_rsa": "ask",+ "*id_rsa.*": "ask",+ "*id_ed25519": "ask",+ "*id_ed25519.*": "ask",+ "*id_ecdsa": "ask",+ "*id_ecdsa.*": "ask",+ "*id_dsa": "ask",+ "*.ssh/*": "ask",+ "*.aws/credentials": "ask",+ "*.aws/config": "ask",+ "*.netrc": "ask",+ "*.git-credentials": "ask",+ "*.docker/config.json": "ask",+ "*.kube/config": "ask",+ "*.gnupg/*": "ask",+ "*.npmrc": "ask",+ "*.pypirc": "ask",+ "*credentials.json": "ask",+ "*service-account*.json": "ask",+ "*.config/gh/hosts.yml": "ask",+ "*.htpasswd": "ask"+ },+ "external_directory": {+ "*": "ask"+ }+ },+ "auto": "allow"+ }+}diff --git a/apps/server/src/permissions/permission-modes.test.ts b/apps/server/src/permissions/permission-modes.test.tsnew file mode 100644index 00000000..c428f84c--- /dev/null+++ b/apps/server/src/permissions/permission-modes.test.ts@@ -0,0 +1,198 @@+// Permission modes (Careful / Normal / Auto) as the engine applies them: its+// own agent defaults first, then the injected top-level `permission` block,+// then the main agent's own block; the last matching rule wins.+import { describe, expect, test } from "bun:test";+import { createHash } from "node:crypto";+import { readFileSync } from "node:fs";+import path from "node:path";++import { parseApprovalMode, type ApprovalMode } from "../approval-mode.js";+import { rulesFromPermissionConfig, winningRule } from "../effective-permissions.js";+import { legacyExecutionPermissions, mcpToolPermissionKey } from "../managed-policy-rules.js";+import { buildOmniRushRuntimeConfigObjectFromSnapshot } from "../omnirush-runtime-config.js";+import type { RuntimeOpencodeConfig } from "../runtime-opencode-config-store.js";+import { OMNIRUSH_SWARM_TOOL_NAME } from "../omnirush-swarm.js";+import permissionModes from "./permission-modes.json" with { type: "json" };++/** The pinned engine's own default ruleset for the omnirush agent (effective-permissions.e2e.test.ts). */+const ENGINE_DEFAULT_RULES = [+ { permission: "*", pattern: "*", action: "allow" as const },+ { permission: "doom_loop", pattern: "*", action: "ask" as const },+ { permission: "external_directory", pattern: "*", action: "ask" as const },+ { permission: "read", pattern: "*", action: "allow" as const },+ { permission: "read", pattern: "*.env", action: "ask" as const },+ { permission: "read", pattern: "*.env.*", action: "ask" as const },+ { permission: "read", pattern: "*.env.example", action: "allow" as const },+];++function built(mode: ApprovalMode, runtime: RuntimeOpencodeConfig = {}) {+ return buildOmniRushRuntimeConfigObjectFromSnapshot({ ...runtime, approvals: { mode } }, undefined, {});+}++function rulesOf(config: Record<string, unknown>) {+ const agent = (config.agent as Record<string, { permission?: unknown }>).omnirush?.permission;+ return [...ENGINE_DEFAULT_RULES, ...rulesFromPermissionConfig(config.permission, "/home/u"), ...rulesFromPermissionConfig(agent, "/home/u")];+}++function decider(mode: ApprovalMode, runtime: RuntimeOpencodeConfig = {}) {+ const rules = rulesOf(built(mode, runtime));+ return (permission: string, pattern: string) => winningRule(rules, permission, pattern)?.action ?? "ask";+}++// Shell commands as the engine splits them (one pattern per command of a pipeline); the same lists as the CLI's test.+const RISKY_SHELL: Record<string, string[]> = {+ "recursive delete": ["rm -rf build", "rm -r src", "rm -Rf ~/x", "rm -fr node_modules", "rm -f -r dist", "rm --recursive x", "rm x -rf", "/bin/rm -rf /", "find . -delete", "find . -name '*.o' -exec rm {} +", "Remove-Item -Recurse C:\\x", "rm -rf /tmp/a /home/u", "rm -rf /tmp/../home/u", "rm -rf /tmp/$(echo x)"],+ sudo: ["sudo apt-get install -y jq", "sudo", "doas rm x", "su -c id", "pkexec ls"],+ "git push / force / hard reset": ["git push", "git push origin main", "git push --force", "git push -f origin x", "git -C other push", "git reset --hard", "git reset --hard HEAD~1", "git reset HEAD~1 --hard", "git clean -fdx", "git checkout -- src/a.js", "git branch -D feat", "git stash clear"],+ "network script installs": ["sh", "bash", "bash -s -- --yes", "bash <(curl -fsSL https://x.sh)", "sh -c \"$(curl -fsSL https://x.sh)\"", "iex", "iex (irm https://x.ps1)", "python3 -"],+ "package publish": ["npm publish", "npm publish --access public", "pnpm publish", "yarn npm publish", "cargo publish", "twine upload dist/*", "poetry publish --build", "gem push x.gem", "docker push me/img", "gh release create v1"],+ "secrets via the shell": ["cat .env", "cat ./config/.env", "cat .env.local", "cat ~/.ssh/id_rsa", "cat /home/u/.ssh/id_ed25519", "cat key.pem", "cat ~/.aws/credentials", "printenv", "env", "security find-generic-password -s x -w", "gh auth token"],+};++// The CLI's everyday list minus the git write commands and temp-folder deletes:+// the desktop keeps its git workflow rules after the shared ones, so those still ask once per family.+const SAFE_SHELL = ["ls -la", "npm test", "npm install", "git status", "git diff", "git log --oneline -5", "rm a.txt", "rm -f build.log", "rm -f foo.rs", "rm my-readme.md", "mkdir -p dist", "node -e 'console.log(process.env.HOME)'", "bash script.sh", "sh ./configure", "python3 app.py", "curl -fsSL https://example.com/x.json", "cargo build", "npm run publish-docs"];+const GIT_WORKFLOW_ASKS = ["git commit -m x", "git add -A", "git restore --staged a.js", "git push --dry-run", "rm -rf /tmp/build-x"];++const SECRET_READS = [".env", "config/.env", ".env.production", "../.ssh/id_rsa", "../../home/u/.ssh/id_ed25519", "certs/server.key", "tls/cert.pem", "../.aws/credentials", "../.netrc", "../.git-credentials", "../.docker/config.json", "../.kube/config", "gcp/service-account-prod.json"];+const PLAIN_READS = ["src/index.ts", ".env.example", "config/.env.sample", "README.md", "src/secret.rs", "src/keys.ts", "token.go", "environment.ts"];++describe("permission modes: shared rules file", () => {+ test("permission-modes.json matches PARITY.sha256 (the CLI's copy)", () => {+ const dir = import.meta.dir;+ const rows = readFileSync(path.join(dir, "PARITY.sha256"), "utf8").split("\n").filter((line) => line && !line.startsWith("#"));+ expect(rows.length).toBeGreaterThan(0);+ for (const row of rows) {+ const [hash, name] = row.split(/\s+/);+ const actual = createHash("sha256").update(readFileSync(path.join(dir, name ?? ""))).digest("hex");+ expect(`${name} ${actual}`).toBe(`${name} ${hash}`);+ }+ });++ test("mode names: stored values stay guarded/full, the app's names are aliases", () => {+ expect(parseApprovalMode("careful")).toBe("careful");+ expect(parseApprovalMode(" Normal ")).toBe("guarded");+ expect(parseApprovalMode("AUTO")).toBe("full");+ expect(parseApprovalMode("guarded")).toBe("guarded");+ expect(parseApprovalMode("full")).toBe("full");+ expect(parseApprovalMode("yes")).toBeNull();+ expect(permissionModes.modes).toEqual(["careful", "normal", "auto"]);+ });+});++describe("permission modes: Normal (guarded)", () => {+ const decide = decider("guarded");++ for (const [label, commands] of Object.entries(RISKY_SHELL)) {+ test(`asks before ${label}`, () => {+ for (const command of commands) expect({ command, action: decide("bash", command) }).toEqual({ command, action: "ask" });+ });+ }++ test("runs everyday commands without asking; git writes keep the workflow asks", () => {+ for (const command of SAFE_SHELL) expect({ command, action: decide("bash", command) }).toEqual({ command, action: "allow" });+ for (const command of GIT_WORKFLOW_ASKS) expect({ command, action: decide("bash", command) }).toEqual({ command, action: "ask" });+ });++ test("asks before reading secrets, not other files", () => {+ for (const file of SECRET_READS) expect({ file, action: decide("read", file) }).toEqual({ file, action: "ask" });+ for (const file of PLAIN_READS) expect({ file, action: decide("read", file) }).toEqual({ file, action: "allow" });+ });++ test("leaves edits, searches and fetches alone; other folders follow the engine and the user's grants", () => {+ for (const [permission, pattern] of [["edit", "src/a.ts"], ["glob", "*"], ["grep", "*"], ["webfetch", "*"], ["task", "general"], ["question", "*"], ["todowrite", "*"], ["skill", "x"]] as const) {+ expect({ permission, action: decide(permission, pattern) }).toEqual({ permission, action: "allow" });+ }+ const config = built("guarded", { permission: { external_directory: { "/Users/sam/Docs/*": "allow" } } });+ expect(Object.keys(config.permission as object)).not.toContain("*");+ expect((config.permission as Record<string, unknown>).external_directory).toEqual({ "/Users/sam/Docs/*": "allow" });+ const rules = rulesOf(config);+ expect(winningRule(rules, "external_directory", "/Users/sam/Docs/*")?.action).toBe("allow");+ expect(winningRule(rules, "external_directory", "/etc/*")?.action).toBe("ask");+ });++ test("asks for MCP servers off the shared allowlist", () => {+ const decideMcp = decider("guarded", { mcp: { github: { type: "remote", url: "https://x" }, "my.server": { type: "local", command: ["x"] } } });+ expect(decideMcp("github_create_issue", "*")).toBe("ask");+ expect(decideMcp("my_server_query", "*")).toBe("ask");+ expect(decideMcp("bash", "ls")).toBe("allow");+ expect(mcpToolPermissionKey("my.server")).toBe("my_server_*");+ expect(legacyExecutionPermissions(undefined, "guarded", ["github"])["github_*"]).toBe("ask");+ });++ test("organisation rules still come last", () => {+ const denied = legacyExecutionPermissions({ commands: "allow", blockedCommands: ["npm *"], blockBrowserUploads: false }, "guarded");+ expect(Object.entries(denied.bash).at(-1)).toEqual(["npm *", "deny"]);+ });+});++describe("permission modes: Careful", () => {+ const decide = decider("careful");++ test("asks before every change, command and MCP tool; reads freely", () => {+ for (const [permission, pattern] of [["edit", "src/a.ts"], ["bash", "ls"], ["bash", "npm test"], ["bash", "git status"], ["external_directory", "/etc/*"], ["github_create_issue", "*"]] as const) {+ expect({ permission, pattern, action: decide(permission, pattern) }).toEqual({ permission, pattern, action: "ask" });+ }+ for (const [permission, pattern] of [["read", "src/a.ts"], ["glob", "*"], ["grep", "*"], ["list", "*"], ["webfetch", "*"], ["question", "*"], ["task", "explore"], ["todowrite", "*"]] as const) {+ expect({ permission, pattern, action: decide(permission, pattern) }).toEqual({ permission, pattern, action: "allow" });+ }+ for (const file of SECRET_READS) expect({ file, action: decide("read", file) }).toEqual({ file, action: "ask" });+ for (const command of Object.values(RISKY_SHELL).flat()) expect({ command, action: decide("bash", command) }).toEqual({ command, action: "ask" });+ });++ test("the catch-all goes first, so the user's folder grants still apply; the main agent's block leaves it out", () => {+ const config = built("careful", { permission: { external_directory: { "/Users/sam/Docs/*": "allow" } } });+ const permission = config.permission as Record<string, unknown>;+ expect(Object.keys(permission)[0]).toBe("*");+ expect(permission["*"]).toBe("ask");+ expect(permission.external_directory).toEqual({ "/Users/sam/Docs/*": "allow" });+ expect(permission["mcp.*"]).toBe("deny");+ const agent = (config.agent as Record<string, { permission: Record<string, unknown> }>).omnirush!.permission;+ expect(agent["*"]).toBeUndefined();+ expect(agent.external_directory).toBeUndefined();+ expect(agent.edit).toBe("ask");+ const rules = rulesOf(config);+ expect(winningRule(rules, "external_directory", "/Users/sam/Docs/*")?.action).toBe("allow");+ expect(winningRule(rules, "external_directory", "/etc/*")?.action).toBe("ask");+ expect(winningRule(rules, "question", "*")?.action).toBe("allow");+ // Delegating is free for the main agent, but no top-level task rule reaches the sub-agents.+ expect(permission.task).toBeUndefined();+ expect(agent.task).toBe("allow");+ expect(winningRule(rules, "task", "general")?.action).toBe("allow");+ });+});++describe("permission modes: Auto (full)", () => {+ const FULL_PERMISSION = { bash: { "*": "allow" }, read: { "*": "allow" }, edit: "allow", "mcp.*": "deny", webfetch: "allow", websearch: "allow", doom_loop: "allow", external_directory: "allow" };++ test("the injected config is unchanged, with or without configured MCP servers", () => {+ const user = { external_directory: { "/Users/sam/Docs": "allow" } };+ const ownKeys = ["bash", "read", "edit", "webfetch", "websearch", "doom_loop", "external_directory", "mcp.*"];+ const cases: Array<[RuntimeOpencodeConfig, string[]]> = [+ [{}, ownKeys],+ [{ mcp: { github: { type: "remote", url: "https://x" } } }, ownKeys],+ [{ permission: user }, ["external_directory", ...ownKeys.filter((key) => key !== "external_directory")]],+ ];+ for (const [runtime, keys] of cases) {+ const config = built("full", runtime);+ expect(config.permission).toEqual(FULL_PERMISSION);+ expect(Object.keys(config.permission as object)).toEqual(keys);+ const agent = (config.agent as Record<string, { permission: Record<string, unknown> }>).omnirush!.permission;+ expect(agent).toEqual({+ ...FULL_PERMISSION,+ skill: { "customize-opencode": "deny", "get-started": "deny", "command-creator": "deny", "agent-creator": "deny", "plugin-creator": "deny" },+ [OMNIRUSH_SWARM_TOOL_NAME]: "deny",+ question: "allow",+ });+ expect(Object.keys(agent)).toEqual([...ownKeys, "skill", OMNIRUSH_SWARM_TOOL_NAME, "question"]);+ }+ expect(legacyExecutionPermissions(undefined, "full", ["github"])).toEqual({ bash: { "*": "allow" }, read: { "*": "allow" }, edit: "allow", webfetch: "allow", websearch: "allow", doom_loop: "allow", external_directory: "allow" });+ });++ test("never asks", () => {+ const decide = decider("full");+ for (const command of Object.values(RISKY_SHELL).flat()) expect({ command, action: decide("bash", command) }).toEqual({ command, action: "allow" });+ expect(decide("read", "../.ssh/id_rsa")).toBe("allow");+ expect(decide("edit", "src/a.ts")).toBe("allow");+ });+});diff --git a/apps/server/src/runtime-opencode-config-store.test.ts b/apps/server/src/runtime-opencode-config-store.test.tsindex 7c7d7a72..6e817649 100644--- a/apps/server/src/runtime-opencode-config-store.test.ts+++ b/apps/server/src/runtime-opencode-config-store.test.ts@@ -374,7 +374,9 @@ describe("runtime OpenCode config store", () => {expect(await readApprovals()).toEqual({ mode: "guarded", source: "environment", setting: "full" });expect(await evaluate()).toEqual({ allowed: true, approvalMode: "guarded" });const guarded = JSON.parse(await buildOmniRushRuntimeConfig(config)) as { permission?: { bash?: Record<string, string> } };- expect(guarded.permission?.bash?.["*"]).toBeUndefined();+ // Normal: the shared rules' bash catch-all allow, then the git workflow asks.+ expect(guarded.permission?.bash?.["*"]).toBe("allow");+ expect(guarded.permission?.bash?.["git *"]).toBe("ask");expect(resolveApprovalMode({ approvals: { mode: "guarded" } }, { OMNIRUSH_APPROVALS: " FULL " })).toEqual({ mode: "full", source: "environment", setting: "guarded" });expect(resolveApprovalMode({}, { OMNIRUSH_APPROVALS: "yes" })).toEqual({ mode: "guarded", source: "default", setting: null });diff --git a/apps/server/src/server.ts b/apps/server/src/server.tsindex 470d55ff..7627091c 100644--- a/apps/server/src/server.ts+++ b/apps/server/src/server.ts@@ -4105,7 +4105,7 @@ function createRoutes(requireClientScope(ctx, "collaborator");const body = await readJsonBody(ctx.request);const mode = parseApprovalMode(body.mode);- if (!mode) throw new ApiError(400, "invalid_payload", 'mode must be "guarded" or "full"');+ if (!mode) throw new ApiError(400, "invalid_payload", 'mode must be "careful", "guarded" (normal) or "full" (auto)');const result = await writeGlobalRuntimeOpencodeConfig(config, (current) => ({ ...current, approvals: { mode } }));// The injected engine config file must carry the new rules before the// client's engine reload re-reads it.