Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

New Harness picks a permission mode, not just auto-approve on or off

dee1b682758f9bb
diff --git a/cli/src/backendSocket.spec.ts b/cli/src/backendSocket.spec.ts
index b73b95db8..9270c5b78 100644
--- a/cli/src/backendSocket.spec.ts
+++ b/cli/src/backendSocket.spec.ts
@@ -752,7 +752,7 @@ describe('BackendSocket outbound queue', () => {
source: null, title: null, model: null, cliVersion: null, processIdentity: null,
registeredAt: 1, updatedAt: 1, lastHookAt: 1, lastTranscriptAt: 1,
})
- const create = vi.fn(async (input: { bypassPermission: boolean }) => ({ ok: true as const, session: pending(`b-${create.mock.calls.length}`) }))
+ const create = vi.fn(async (input: { bypassPermission: boolean; permissionMode: string | null }) => ({ ok: true as const, session: pending(`b-${create.mock.calls.length}`) }))
socket.onCreateAgent = create
const ask = (requestId: string, extra: Record<string, unknown>) => socket.handleLocalFrame('local:bypass', {
type: 'agent_create', payload: { requestId, engine: 'claude', cwd: '/tmp/work', ...extra },
@@ -763,6 +763,17 @@ describe('BackendSocket outbound queue', () => {
ask('off', { bypassPermission: false })
await vi.waitFor(() => expect(create).toHaveBeenCalledTimes(3))
expect(create.mock.calls.map(([input]) => input.bypassPermission)).toEqual([true, true, false])
+
+ // A mode decides, whatever bypassPermission says; one the engine lacks is refused.
+ ask('plan', { permissionMode: 'plan', bypassPermission: true })
+ ask('full', { permissionMode: 'full', bypassPermission: false })
+ await vi.waitFor(() => expect(create).toHaveBeenCalledTimes(5))
+ expect(create.mock.calls.slice(3).map(([input]) => [input.permissionMode, input.bypassPermission]))
+ .toEqual([['plan', false], ['full', true]])
+ ask('bogus', { permissionMode: 'readOnly' })
+ ask('shape', { permissionMode: 7 })
+ await vi.waitFor(() => expect(frames.filter((frame) => (frame.payload as { error?: string } | undefined)?.error === 'INVALID_PERMISSION_MODE')).toHaveLength(2))
+ expect(create).toHaveBeenCalledTimes(5)
} finally {
await socket.unregisterLocalClient('local:bypass')
await socket.stop()
diff --git a/cli/src/backendSocket.ts b/cli/src/backendSocket.ts
index 1f0b21171..bd782b808 100644
--- a/cli/src/backendSocket.ts
+++ b/cli/src/backendSocket.ts
@@ -31,7 +31,7 @@ import { gridCliPresence } from './lib/gridExec.js'
import { gridCapableEngines, parseGridLaunchOverride, type GridLaunchOverride } from './lib/gridLaunch.js'
import { listGridModels, resolveGridTarget } from './lib/gridModels.js'
import { deriveHarnessGridName } from './lib/gridDerive.js'
-import { AGENT_NAME_RE, FirstPromptUnsupportedError, MAX_FIRST_PROMPT_CHARS, NamedAgentUnsupportedError, supportsFirstPrompt, supportsNamedAgent } from './lib/engineLaunch.js'
+import { AGENT_NAME_RE, FirstPromptUnsupportedError, MAX_FIRST_PROMPT_CHARS, NamedAgentUnsupportedError, permissionModeApproves, permissionModeFlags, supportsFirstPrompt, supportsNamedAgent } from './lib/engineLaunch.js'
import { readAccountUsage, type AccountUsageReading } from './lib/accountUsage.js'
import { probeEngines } from './lib/engineProbe.js'
import { AgentCreationReceipts, AgentCreationReceiptError, creationFingerprint, validCreationId, type AgentCreationStatus } from './lib/agentCreationReceipt.js'
@@ -366,6 +366,9 @@ export class BackendSocket {
* `--agent <name>`); null for a general session. Validated here — shape, and that the engine has
* a contract for it. Unlike `prompt`, kept on the row so a relaunch opens as it again. */
agent: string | null
+ /** A mode from `PERMISSION_MODES` for this engine; null when the client sent only
+ * `bypassPermission`, which then decides. Validated here (`INVALID_PERMISSION_MODE`). */
+ permissionMode: string | null
}) =>
Promise<{ ok: true; session: RegisteredSession } | { ok: false; error: string; detail?: string }>) | null = null
/** Called on `dsh_install` — cli.ts clones/sets up/doctors the harness and reports each phase. */
@@ -1823,11 +1826,22 @@ export class BackendSocket {
}
agent = payload.agent
}
+ // A permission mode picked in New Harness. A client that predates the choice sends only
+ // `bypassPermission`; one that sends a mode this engine does not have is refused rather than
+ // quietly launched in some other mode.
+ let permissionMode: string | null = null
+ if (payload.permissionMode !== undefined && payload.permissionMode !== null) {
+ if (typeof payload.permissionMode !== 'string' || !permissionModeFlags(engine, payload.permissionMode)) {
+ reply(type, requestId, { error: 'INVALID_PERMISSION_MODE', detail: `${engine} has no permission mode ${JSON.stringify(payload.permissionMode)}` }); return
+ }
+ permissionMode = payload.permissionMode
+ }
const input = {
engine,
cwd: typeof cwd === 'string' ? cwd : '',
// On unless a client says otherwise: a harness works without stopping to ask for each command.
- bypassPermission: payload.bypassPermission !== false,
+ bypassPermission: permissionMode ? permissionModeApproves(permissionMode) : payload.bypassPermission !== false,
+ permissionMode,
grid: grid.state === 'ok' ? grid.override : null,
codexHome,
dsh,
diff --git a/cli/src/cli.ts b/cli/src/cli.ts
index 6c4ddf5e2..a9f551419 100644
--- a/cli/src/cli.ts
+++ b/cli/src/cli.ts
@@ -3740,6 +3740,7 @@ async function runForeground(session: AuthSession): Promise<void> {
const argv = buildEngineLaunchArgv(entry.engine, {
...opts,
bypassPermission: entry.bypassPermission === true,
+ ...(entry.permissionMode ? { permissionMode: entry.permissionMode } : {}),
installIfMissing: enginePathOverride(entry.engine) ? undefined : engineInstallRecipe(entry.engine),
...(entry.cwd ? { cwd: entry.cwd } : {}),
...(extraArgs.length ? { extraArgs } : {}),
@@ -3915,7 +3916,7 @@ async function runForeground(session: AuthSession): Promise<void> {
* pass can miss it — retry `triggerHint` a few times with backoff before giving up.
*/
- backend.onCreateAgent = async ({ engine, cwd, bypassPermission, grid, codexHome, dsh, prompt, name, agent }) => {
+ backend.onCreateAgent = async ({ engine, cwd, bypassPermission, permissionMode, grid, codexHome, dsh, prompt, name, agent }) => {
if (!tmuxBackend) return { ok: false, error: 'TMUX_UNAVAILABLE' }
try {
if (!statSync(cwd).isDirectory()) return { ok: false, error: 'CWD_NOT_FOUND' }
@@ -4027,7 +4028,7 @@ async function runForeground(session: AuthSession): Promise<void> {
const extraArgs = [...(gridLaunch?.args ?? []), ...dshArgs, ...(agent ? namedAgentArgs(engine, agent) : [])]
// The first prompt is a launch option only — never part of `extraArgs`, which the registry row
// carries into a relaunch (engineLaunch.ts, `firstPrompt`).
- const launchOptions = { bypassPermission, extraArgs: extraArgs.length ? extraArgs : undefined, installIfMissing, clearEnv, cwd, harnessNode: dsh ? true : undefined, ...(prompt ? { firstPrompt: prompt } : {}) }
+ const launchOptions = { bypassPermission, ...(permissionMode ? { permissionMode } : {}), extraArgs: extraArgs.length ? extraArgs : undefined, installIfMissing, clearEnv, cwd, harnessNode: dsh ? true : undefined, ...(prompt ? { firstPrompt: prompt } : {}) }
const command = buildEngineCommandArgv(engine, launchOptions)
const argv = buildEngineLaunchArgv(engine, launchOptions)
// A tmux route is enough to stream its screen. Register it before looking for a process so both
@@ -4054,6 +4055,7 @@ async function runForeground(session: AuthSession): Promise<void> {
dsh,
agent,
bypassPermission,
+ permissionMode,
defaultName: name,
label: dshLabel,
})
@@ -4171,6 +4173,9 @@ async function runForeground(session: AuthSession): Promise<void> {
},
buildArgv: (opts) => buildEngineLaunchArgv(session.engine, {
...opts,
+ // The mode picked at create outranks what the live argv said: `bypassPermission` is a yes/no, and
+ // Plan or Accept edits would come back as Ask without it.
+ ...(session.permissionMode ? { permissionMode: session.permissionMode } : {}),
...(session.cwd ? { cwd: session.cwd } : {}),
...(launch.extraArgs?.length ? { extraArgs: launch.extraArgs } : {}),
// A pane swap onto a grid has to clear the same vendor credentials a fresh create does, for the
diff --git a/cli/src/lib/createAgentPane.ts b/cli/src/lib/createAgentPane.ts
index 33d439a07..5370cde5c 100644
--- a/cli/src/lib/createAgentPane.ts
+++ b/cli/src/lib/createAgentPane.ts
@@ -34,12 +34,15 @@ export interface CreateAgentPaneDeps {
dsh?: string | null
agent?: string | null
bypassPermission?: boolean
+ permissionMode?: string | null
defaultName?: string | null
label?: string | null
}) => RegisteredSession | null }
engine: AgentEngine
cwd?: string | null
bypassPermission?: boolean
+ /** The permission mode it was launched in (`PERMISSION_MODES`), kept so a relaunch reapplies it. */
+ permissionMode?: string | null
/** The name the creator asked for (`agent_create`'s `name`); without one the registry names the agent. */
defaultName?: string | null
/** Who the agent is when a DSH says ("Blender") — the name the registry gives is built from it. */
@@ -95,6 +98,7 @@ export async function createAndRegisterPane(deps: CreateAgentPaneDeps): Promise<
dsh: deps.dsh,
agent: deps.agent,
bypassPermission: deps.bypassPermission,
+ permissionMode: deps.permissionMode,
defaultName: deps.defaultName,
label: deps.label,
})
diff --git a/cli/src/lib/engineLaunch.spec.ts b/cli/src/lib/engineLaunch.spec.ts
index 382ccd7ab..f7744529e 100644
--- a/cli/src/lib/engineLaunch.spec.ts
+++ b/cli/src/lib/engineLaunch.spec.ts
@@ -11,6 +11,7 @@ import {
LAUNCH_RESUME_FLAG,
NAMED_AGENT_ARGS,
NamedAgentUnsupportedError,
+ PERMISSION_MODES,
buildEngineCommandArgv,
buildEngineLaunchArgv,
commandAvailableInInteractiveShell,
@@ -218,6 +219,32 @@ describe('buildEngineLaunchArgv', () => {
.toEqual([engineBin('opencode'), '--auto'])
})
+ it('launches each permission mode with its own flags, and a mode outranks bypassPermission', () => {
+ expect(buildEngineCommandArgv('claude', { permissionMode: 'plan' }))
+ .toEqual([engineBin('claude'), '--permission-mode', 'plan'])
+ expect(buildEngineCommandArgv('claude', { permissionMode: 'acceptEdits', bypassPermission: true }))
+ .toEqual([engineBin('claude'), '--permission-mode', 'acceptEdits'])
+ expect(buildEngineCommandArgv('claude', { permissionMode: 'ask', bypassPermission: true }))
+ .toEqual([engineBin('claude')])
+ expect(buildEngineCommandArgv('claude', { permissionMode: 'full' }))
+ .toEqual([engineBin('claude'), '--dangerously-skip-permissions'])
+ expect(buildEngineCommandArgv('codex', { permissionMode: 'readOnly' }))
+ .toEqual([engineBin('codex'), '--sandbox', 'read-only'])
+ expect(buildEngineCommandArgv('codex', { permissionMode: 'full' }))
+ .toEqual([engineBin('codex'), '--dangerously-bypass-approvals-and-sandbox'])
+ // A mode the engine lacks falls back to the yes/no.
+ expect(buildEngineCommandArgv('opencode', { permissionMode: 'plan', bypassPermission: true }))
+ .toEqual([engineBin('opencode'), '--auto'])
+ expect(buildEngineCommandArgv('pi', { permissionMode: 'auto' })).toEqual([engineBin('pi')])
+ })
+
+ it('makes auto the same flags as bypassPermission, for every engine with modes', () => {
+ for (const [engine, modes] of Object.entries(PERMISSION_MODES)) {
+ expect(modes?.auto, engine).toEqual(BYPASS_PERMISSION_FLAGS[engine as keyof typeof BYPASS_PERMISSION_FLAGS])
+ expect(modes?.ask, engine).toEqual([])
+ }
+ })
+
it('is a no-op for engines with no confirmed flag, even when bypass is requested', () => {
expect(buildEngineCommandArgv('pi', { bypassPermission: true })).toEqual([engineBin('pi')])
expect(buildEngineCommandArgv('hermes', { bypassPermission: true })).toEqual([engineBin('hermes')])
diff --git a/cli/src/lib/engineLaunch.ts b/cli/src/lib/engineLaunch.ts
index 20c341245..fc974173f 100644
--- a/cli/src/lib/engineLaunch.ts
+++ b/cli/src/lib/engineLaunch.ts
@@ -35,6 +35,44 @@ export const BYPASS_PERMISSION_FLAGS: Readonly<Record<AgentEngine, string[] | nu
copilot: null,
}
+/**
+ * The permission modes a person can pick for a new agent (New Harness ▸ Advanced), per engine, and the
+ * argv each one launches with. `auto` is the default and is exactly [BYPASS_PERMISSION_FLAGS]; `ask`
+ * adds nothing, so the engine behaves as its own settings say; the rest are the engines' documented
+ * modes (`claude --help`: `--permission-mode acceptEdits|plan`; `codex --help`: `--sandbox read-only`,
+ * `--dangerously-bypass-approvals-and-sandbox`). An engine absent here offers no choice.
+ *
+ * The desktop mirrors this table in `lib/core/permission_modes.dart` — keep both in step.
+ */
+export const PERMISSION_MODES: Readonly<Partial<Record<AgentEngine, Readonly<Record<string, readonly string[]>>>>> = {
+ claude: {
+ auto: ['--permission-mode', 'auto'],
+ acceptEdits: ['--permission-mode', 'acceptEdits'],
+ plan: ['--permission-mode', 'plan'],
+ ask: [],
+ full: ['--dangerously-skip-permissions'],
+ },
+ codex: {
+ auto: ['--approve-for-me'],
+ readOnly: ['--sandbox', 'read-only'],
+ ask: [],
+ full: ['--dangerously-bypass-approvals-and-sandbox'],
+ },
+ cursor: { auto: ['--force'], ask: [] },
+ opencode: { auto: ['--auto'], ask: [] },
+}
+
+/** The argv of [mode] for [engine], or null when the engine has no such mode. */
+export function permissionModeFlags(engine: AgentEngine, mode: string): readonly string[] | null {
+ const modes = PERMISSION_MODES[engine]
+ return modes && Object.hasOwn(modes, mode) ? modes[mode] : null
+}
+
+/** Whether [mode] lets the agent act without stopping to ask — what `bypassPermission` records. */
+export function permissionModeApproves(mode: string): boolean {
+ return mode === 'auto' || mode === 'full'
+}
+
/**
* How each engine takes a FIRST prompt on launch: the interactive session opens with that message
* already submitted, so the pane's first visible thing is the agent's answer rather than an empty
@@ -148,6 +186,9 @@ export function namedAgentArgs(engine: AgentEngine, agent: string): string[] {
export interface LaunchCommandOptions {
bypassPermission?: boolean
+ /** A mode from [PERMISSION_MODES]; when the engine has it, it decides the flags and
+ * `bypassPermission` is ignored. */
+ permissionMode?: string
/** Resume this engine session id on launch, when a launch-resume flag is known for the engine. */
resumeSessionId?: string
/**
@@ -259,7 +300,10 @@ export function buildEngineCommandArgv(engine: AgentEngine, opts: LaunchCommandO
if (resumeIsSubcommand && resumeFlag && opts.resumeSessionId) {
argv.push(...resumeFlag, opts.resumeSessionId)
}
- if (opts.bypassPermission) {
+ const modeFlags = opts.permissionMode ? permissionModeFlags(engine, opts.permissionMode) : null
+ if (modeFlags) {
+ argv.push(...modeFlags)
+ } else if (opts.bypassPermission) {
const flags = BYPASS_PERMISSION_FLAGS[engine]
if (flags) argv.push(...flags)
}
diff --git a/cli/src/lib/registry.spec.ts b/cli/src/lib/registry.spec.ts
index 606c7c20e..b73606005 100644
--- a/cli/src/lib/registry.spec.ts
+++ b/cli/src/lib/registry.spec.ts
@@ -1329,6 +1329,35 @@ describe('registry across a reboot and pane loss', () => {
expect(registry.byProcess('claude', processIdentity(4242))?.agentId).toBe('agent-a')
})
+ it('keeps the permission mode from agent_create through a bind and a reload', async () => {
+ const transcriptPath = join(dataDir, 'session-p.jsonl')
+ writeFileSync(transcriptPath, '{}\n')
+ const { registry } = await loadRegistryModule()
+ registry.load()
+
+ const pending = registry.openPendingAgent({
+ engine: 'claude',
+ runtimes: [{ backend: 'tmux', paneId: '%7' }],
+ cwd: '/tmp/demo',
+ permissionMode: 'plan',
+ })
+ expect(pending?.permissionMode).toBe('plan')
+ const bound = registry.register({ sessionId: 'session-p', transcriptPath, tmuxPane: '%7', cwd: '/tmp/demo' })
+ expect(bound?.entry.permissionMode).toBe('plan')
+
+ const again = await loadRegistryModule()
+ again.registry.load()
+ expect(again.registry.byAgent(pending!.agentId)?.permissionMode).toBe('plan')
+
+ const bogus = registry.openPendingAgent({
+ engine: 'claude',
+ runtimes: [{ backend: 'tmux', paneId: '%8' }],
+ cwd: '/tmp/demo',
+ permissionMode: '--dangerously-skip-permissions',
+ })
+ expect(bogus).not.toHaveProperty('permissionMode')
+ })
+
it('carries bypassPermission from agent_create through the first hook bind', async () => {
const transcriptPath = join(dataDir, 'session-b.jsonl')
writeFileSync(transcriptPath, '{}\n')
diff --git a/cli/src/lib/registry.ts b/cli/src/lib/registry.ts
index 6873618e5..bd4d0daa5 100644
--- a/cli/src/lib/registry.ts
+++ b/cli/src/lib/registry.ts
@@ -162,6 +162,13 @@ export interface RegisteredSession {
* to read it from. Like `codexHome`, chosen at launch and carried forward, never re-derived.
*/
bypassPermission?: boolean
+ /**
+ * The permission mode picked in New Harness (`PERMISSION_MODES` in engineLaunch.ts: `auto`, `ask`,
+ * `acceptEdits`, `plan`, `readOnly`, `full`). Recorded at launch and reapplied on every relaunch, so
+ * an agent started in Plan stays in Plan across a restart. Absent on rows from before the choice
+ * existed and on agents Harness did not launch; those relaunch from `bypassPermission`.
+ */
+ permissionMode?: string
/** Legacy launcher-owned snapshots may still contain this field. New records never write it. */
launcherId?: string
transcriptPath: string | null
@@ -264,6 +271,12 @@ function normalizedAgentName(value: unknown): string | null {
return typeof value === 'string' && AGENT_NAME_RE.test(value) ? value : null
}
+/** A persisted permission mode, or null. Only its shape is checked here — the launch looks it up per
+ * engine (`permissionModeFlags`), and a name the engine lacks launches as `bypassPermission` says. */
+function permissionModeName(value: unknown): value is string {
+ return typeof value === 'string' && /^[A-Za-z]{1,24}$/.test(value)
+}
+
function normalizedAgentEngine(value: unknown): AgentEngine {
return typeof value === 'string' && AGENT_ENGINES.has(value)
? value as AgentEngine
@@ -840,6 +853,7 @@ class Registry {
? { subscriptionModel: raw.subscriptionModel }
: {}),
...(raw.bypassPermission === true ? { bypassPermission: true } : {}),
+ ...(permissionModeName(raw.permissionMode) ? { permissionMode: raw.permissionMode } : {}),
transcriptPath,
defaultName: normalizedDefaultName(raw.defaultName),
title: titleDisplayName(typeof raw.title === 'string' ? raw.title : null),
@@ -1067,6 +1081,7 @@ class Registry {
/** The engine's named agent the pane was opened as (`agent_create`'s `agent`), validated upstream. */
agent?: string | null
bypassPermission?: boolean
+ permissionMode?: string | null
/** The name the creator asked for. Blank or absent means Harness names it (agentNames.ts). */
defaultName?: string | null
/** Who the agent is, for the name Harness gives it: a DSH's own name ("Blender"); the engine's by default. */
@@ -1095,6 +1110,7 @@ class Registry {
dsh: input.dsh ?? null,
agent: normalizedAgentName(input.agent),
...(input.bypassPermission ? { bypassPermission: true } : {}),
+ ...(permissionModeName(input.permissionMode) ? { permissionMode: input.permissionMode } : {}),
transcriptPath: null,
projectDir: basename(input.cwd ?? '') || agentId,
cwd: input.cwd ?? null,
@@ -1286,6 +1302,7 @@ class Registry {
dsh: existing?.dsh ?? null,
agent: existing?.agent ?? null,
...(existing?.bypassPermission ? { bypassPermission: true } : {}),
+ ...(existing?.permissionMode ? { permissionMode: existing.permissionMode } : {}),
processIdentity: validProcessIdentity(input.processIdentity) ? input.processIdentity : existing?.processIdentity ?? null,
registeredAt: existing?.registeredAt ?? now,
updatedAt: now,
diff --git a/desktop/lib/analytics/analytics_events.dart b/desktop/lib/analytics/analytics_events.dart
index 135a07629..4b2e51c33 100644
--- a/desktop/lib/analytics/analytics_events.dart
+++ b/desktop/lib/analytics/analytics_events.dart
@@ -81,11 +81,18 @@ extension AnalyticsEvents on Analytics {
///
/// The working folder is deliberately absent: it is an absolute path, which
/// this stream never carries.
- void agentCreated({required String engine, required bool bypassPermission}) =>
- track(
- 'agent_created',
- params: {'engine': engine, 'bypass_permission': bypassPermission},
- );
+ void agentCreated({
+ required String engine,
+ required bool bypassPermission,
+ String? permissionMode,
+ }) => track(
+ 'agent_created',
+ params: {
+ 'engine': engine,
+ 'bypass_permission': bypassPermission,
+ 'permission_mode': ?permissionMode,
+ },
+ );
/// The first message of a signed-in session — how long it took this person to
/// get from being logged in to actually talking to an agent, whichever agent
diff --git a/desktop/lib/core/permission_modes.dart b/desktop/lib/core/permission_modes.dart
new file mode 100644
index 000000000..5d1c81315
--- /dev/null
+++ b/desktop/lib/core/permission_modes.dart
@@ -0,0 +1,91 @@
+/// How far a new agent may go without asking — the choice in New Harness ▸ Advanced.
+///
+/// Mirrors the CLI's `PERMISSION_MODES` (cli/src/lib/engineLaunch.ts) mode for mode: this is the
+/// menu, the CLI is what turns a mode into flags and refuses one an engine lacks. An engine absent
+/// here offers no choice. Keep both tables in step.
+library;
+
+class PermissionMode {
+ const PermissionMode(this.id, this.label, this.detail, {this.risky = false});
+
+ /// What the machine is sent (`agent_create`'s `permissionMode`).
+ final String id;
+ final String label;
+ final String detail;
+
+ /// Turns off the engine's own safety net; worded as such in the menu.
+ final bool risky;
+}
+
+/// The default for every engine that has modes.
+const kDefaultPermissionMode = 'auto';
+
+const _auto = 'auto';
+const _ask = 'ask';
+
+const Map<String, List<PermissionMode>> kEnginePermissionModes = {
+ 'claude': [
+ PermissionMode(
+ _auto,
+ 'Auto-approve',
+ 'Approves routine actions, checks risky ones',
+ ),
+ PermissionMode(
+ 'acceptEdits',
+ 'Accept edits',
+ 'Edits files freely, asks before commands',
+ ),
+ PermissionMode(
+ 'plan',
+ 'Plan first',
+ 'Reads and plans, changes nothing until you agree',
+ ),
+ PermissionMode(
+ _ask,
+ 'Ask first',
+ 'Asks before acting, as Claude Code does',
+ ),
+ PermissionMode(
+ 'full',
+ 'Skip all checks',
+ 'No approvals and no safety checks. Risky',
+ risky: true,
+ ),
+ ],
+ 'codex': [
+ PermissionMode(
+ _auto,
+ 'Auto-approve',
+ 'Reviews each approval automatically, in the sandbox',
+ ),
+ PermissionMode(
+ 'readOnly',
+ 'Read only',
+ 'Reads and suggests, asks before any change',
+ ),
+ PermissionMode(_ask, 'Ask first', 'Asks before acting, as Codex does'),
+ PermissionMode(
+ 'full',
+ 'Full access',
+ 'No approvals and no sandbox. Risky',
+ risky: true,
+ ),
+ ],
+ 'cursor': [
+ PermissionMode(_auto, 'Auto-approve', 'Runs commands without asking'),
+ PermissionMode(_ask, 'Ask first', 'Asks before running commands'),
+ ],
+ 'opencode': [
+ PermissionMode(_auto, 'Auto-approve', 'Approves actions on its own'),
+ PermissionMode(_ask, 'Ask first', 'Asks before acting'),
+ ],
+};
+
+/// The modes [engine] offers, or empty when it has none to choose between.
+List<PermissionMode> permissionModesOf(String engine) =>
+ kEnginePermissionModes[engine] ?? const [];
+
+/// Whether [mode] lets the agent act without stopping to ask — the yes/no a daemon that predates
+/// modes understands (`bypassPermission`). Plan and Read only read as no, so an older machine asks
+/// rather than approving on their behalf; Skip all checks reads as yes and gets Auto-approve there.
+bool permissionModeApproves(String mode) => mode == _auto || mode == 'full';
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index 1269e0474..06fa2faa2 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -4725,6 +4725,7 @@ class AppNotifier extends ChangeNotifier {
required String folder,
ProjectFolderRequest? projectFolder,
bool bypassPermission = true,
+ String? permissionMode,
String? codexHome,
String? dsh,
String? prompt,
@@ -4740,6 +4741,10 @@ class AppNotifier extends ChangeNotifier {
if (projectFolder == null) 'cwd': folder,
...?projectFolder?.payload,
'bypassPermission': bypassPermission,
+ // The mode picked in New Harness (`permission_modes.dart`). A daemon that
+ // predates modes ignores it and goes by `bypassPermission`, which the
+ // dialog derives from the same choice.
+ 'permissionMode': ?permissionMode,
'codexHome': ?codexHome,
// The harness this agent is created from. `engine` above is its BASE —
// the machine refuses the pair when they disagree (`INVALID_DSH`).
diff --git a/desktop/lib/widgets/new_agent_dialog.dart b/desktop/lib/widgets/new_agent_dialog.dart
index 28e3b1878..111b9886b 100644
--- a/desktop/lib/widgets/new_agent_dialog.dart
+++ b/desktop/lib/widgets/new_agent_dialog.dart
@@ -11,10 +11,10 @@ import '../state/pane_arrangement.dart';
import '../core/engine_availability.dart';
import '../core/codex_profiles.dart';
import '../core/dsh_catalog.dart';
+import '../core/permission_modes.dart';
import '../core/project_folder.dart';
import '../core/repository_clone.dart';
import '../shared/theme/app_theme.dart' as grid;
-import '../shared/widgets/app_checkbox.dart';
import '../shared/widgets/app_icon_button.dart';
import '../shared/widgets/app_choice_picker.dart';
import '../shared/widgets/app_dialog.dart';
@@ -28,17 +28,6 @@ import 'new_agent_project_picker.dart';
import 'new_harness_help.dart';
import 'dsh_install_panel.dart';
-/// Mirrors the harness CLI's `BYPASS_PERMISSION_FLAGS`
-/// (autonomous-harness/cli/src/lib/engineLaunch.ts) 1:1 — this is UI-only display + gating, the CLI
-/// is the actual enforcement point. An engine absent here shows no checkbox at all rather than
-/// guessing a flag for a CLI we haven't verified. Keep both maps in sync.
-const Map<String, String> kEngineBypassPermissionFlag = {
- 'claude': '--permission-mode auto',
- 'codex': '--approve-for-me',
- 'cursor': '--force',
- 'opencode': '--auto',
-};
-
enum NewAgentDialogResult { created, findExisting, backToSearch }
enum _FolderSource { newProject, local, remote }
@@ -63,9 +52,11 @@ Future<NewAgentDialogResult?> showNewAgentDialog(
Future<void>? initialEngineProbe,
bool offerFindExisting = false,
bool offerBackToSearch = false,
+
/// Open with this engine or harness already chosen — the store's Get and
/// Open buttons, which know exactly which one the person is looking at.
String? initialEngine,
+
/// The harness's first message, sent as it starts — the store's "Try this prompt".
String? initialPrompt,
}) {
@@ -151,9 +142,19 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
late String? _folder = widget.initialFolder;
LocalCodexProfile? _codexProfile;
bool _codexProfilesBusy = true;
- /// On unless the person turns it off: a new harness works without stopping to ask for each
- /// command — Claude Code's manual mode was what every harness opened in before.
- bool _bypassPermission = true;
+
+ /// Auto-approve unless the person picks otherwise: a new harness works without stopping to ask
+ /// for each command — Claude Code's manual mode was what every harness opened in before. Kept
+ /// across engine changes; an engine without the picked mode uses its default instead.
+ String _permissionMode = kDefaultPermissionMode;
+
+ /// The mode [engine] launches in: the picked one when it has it.
+ String _permissionModeFor(String engine) {
+ final modes = permissionModesOf(engine);
+ return modes.any((mode) => mode.id == _permissionMode)
+ ? _permissionMode
+ : kDefaultPermissionMode;
+ }
/// Whether the fold is open. Closed on every open of the dialog, deliberately:
/// it is shut for the case it exists to serve, and a drawer that remembers
@@ -180,7 +181,8 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
final remembered = widget.notifier.agentPreference.value;
final asked = widget.initialEngine;
if (asked != null &&
- (isHarnessId(asked) || allEngines.any((identity) => identity.id == asked))) {
+ (isHarnessId(asked) ||
+ allEngines.any((identity) => identity.id == asked))) {
// Chosen before the dialog opened: counts as the person's choice, so no
// probe or remembered preference moves it.
_engine = asked;
@@ -394,7 +396,6 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
}
bool _picking = false;
- bool _bypassHovered = false;
String? _error;
/// Whether the machine this agent will run on is the computer the app is
@@ -458,8 +459,10 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
final harness = _engineIsHarness ? choice : null;
final engine = _baseEngine(choice);
final profile = _codexProfile;
+ final hasModes = permissionModesOf(engine).isNotEmpty;
+ final permissionMode = hasModes ? _permissionModeFor(engine) : null;
final bypassPermission =
- _bypassPermission && kEngineBypassPermissionFlag.containsKey(engine);
+ permissionMode != null && permissionModeApproves(permissionMode);
if (!_confirmationPending) _creation = AgentCreationAttempt();
setState(() {
_checkingCreation = _confirmationPending;
@@ -518,6 +521,7 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
swarmId: widget.swarmId,
split: widget.split,
bypassPermission: bypassPermission,
+ permissionMode: permissionMode,
// Keep the explicit choice even if machine discovery changes mid-submit.
// The notifier must reject a now-remote target, never use its default login.
codexHome: engine == 'codex' ? profile?.path : null,
@@ -544,7 +548,11 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
});
return;
}
- analytics.agentCreated(engine: choice, bypassPermission: bypassPermission);
+ analytics.agentCreated(
+ engine: choice,
+ bypassPermission: bypassPermission,
+ permissionMode: permissionMode,
+ );
Navigator.of(context).pop(NewAgentDialogResult.created);
}
@@ -579,7 +587,6 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
Widget _buildDialog(BuildContext context) {
final edgePadding = MediaQuery.sizeOf(context).width < 700 ? 24.0 : 36.0;
final compactHeight = MediaQuery.sizeOf(context).height < 800;
- final bypassFlag = kEngineBypassPermissionFlag[_baseEngine(_engine)];
final canCreate =
(_preparedFolder != null ||
(_folderSource == _FolderSource.local
@@ -822,7 +829,7 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
children: [
Flexible(
fit: stacked ? FlexFit.loose : FlexFit.tight,
- child: _settingsRow(bypassFlag),
+ child: _settingsRow(),
),
SizedBox(width: stacked ? 0 : 16, height: stacked ? 12 : 0),
Align(alignment: Alignment.centerRight, child: actions),
@@ -1131,7 +1138,7 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
),
);
- Widget _settingsRow(String? bypassFlag) => Wrap(
+ Widget _settingsRow() => Wrap(
spacing: 12,
runSpacing: 8,
crossAxisAlignment: WrapCrossAlignment.center,
@@ -1151,20 +1158,48 @@ class _NewAgentDialogState extends State<_NewAgentDialog> {
),
),
),
- _setting(
- _BypassCheck(
- value: bypassFlag != null && _bypassPermission,
- hovered: _bypassHovered,
- onHover: (value) => setState(() => _bypassHovered = value),
- onChanged: bypassFlag == null
- ? null
- : (value) => setState(() => _bypassPermission = value),
- ),
- ),
+ if (permissionModesOf(_baseEngine(_engine)) case final modes
+ when modes.isNotEmpty)
+ _setting(_permissionModeField(modes)),
if (_baseEngine(_engine) == 'codex') _setting(_profileOptions()),
],
);
+ /// How far the agent may go without asking. The field shows the mode; the menu says what each
+ /// one does, since "Accept edits" and "Plan first" mean little on their own.
+ Widget _permissionModeField(List<PermissionMode> modes) => SizedBox(
+ width: 156 * math.min(1.4, MediaQuery.textScalerOf(context).scale(13) / 13),
+ height: 34,
+ child: AppSelectField<String>(
+ key: const Key('new-agent-permission-mode'),
+ height: 34,
+ menuWidth: 340,
+ value: _permissionModeFor(_baseEngine(_engine)),
+ options: [
+ for (final mode in modes)
+ SelectOption(
+ value: mode.id,
+ label: mode.label,
+ detail: mode.detail,
+ leading: () => Icon(
+ mode.risky
+ ? LucideIcons.shieldOff
+ : mode.id == kDefaultPermissionMode
+ ? LucideIcons.shieldCheck
+ : LucideIcons.shield,
+ size: 16,
+ color: mode.risky
+ ? grid.AppPalette.dangerFill
+ : grid.AppPalette.textSecondary,
+ ),
+ ),
+ ],
+ onChanged: (mode) {
+ if (!_choicesLocked) setState(() => _permissionMode = mode);
+ },
+ ),
+ );
+
Widget _setting(Widget child) => Offstage(
offstage: !_advancedOpen,
child: ExcludeFocus(
@@ -1258,51 +1293,3 @@ const double _dialogWidth = 1080;
/// Blocks inside one card: the command, the facts, the reason.
const double _gapBlock = 12;
-
-class _BypassCheck extends StatelessWidget {
- const _BypassCheck({
- required this.value,
- required this.hovered,
- required this.onHover,
- required this.onChanged,
- });
- final bool value;
- final bool hovered;
- final ValueChanged<bool> onHover;
- final ValueChanged<bool>? onChanged;
-
- @override
- Widget build(BuildContext context) {
- grid.AppTheme.watch(context);
- return MouseRegion(
- cursor: onChanged == null
- ? SystemMouseCursors.basic
- : SystemMouseCursors.click,
- onEnter: (_) => onHover(true),
- onExit: (_) => onHover(false),
- child: GestureDetector(
- onTap: onChanged == null ? null : () => onChanged!(!value),
- behavior: HitTestBehavior.opaque,
- child: Padding(
- padding: const EdgeInsets.symmetric(vertical: 10),
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- AppCheckbox(value: value, hovered: hovered, onChanged: onChanged),
- const SizedBox(width: 10),
- Text(
- 'Auto-approve',
- style: TextStyle(
- fontSize: 13,
- color: onChanged == null
- ? grid.AppPalette.textFaint
- : grid.AppPalette.textPrimary,
- ),
- ),
- ],
- ),
- ),
- ),
- );
- }
-}
diff --git a/desktop/test/agent_events_test.dart b/desktop/test/agent_events_test.dart
index a8d34bd4e..7442fb934 100644
--- a/desktop/test/agent_events_test.dart
+++ b/desktop/test/agent_events_test.dart
@@ -62,6 +62,7 @@ class FakeCreateAgentNotifier extends AppNotifier {
required String folder,
ProjectFolderRequest? projectFolder,
bool bypassPermission = false,
+ String? permissionMode,
String? codexHome,
String? dsh,
String? prompt,
@@ -184,10 +185,11 @@ void main() {
testWidgets('carries the engine and the bypass flag', (tester) async {
await create(tester);
- // Auto-approve is on unless the person turns it off.
+ // Auto-approve unless the person picks another mode.
expect(tracked.paramsOf('agent_created'), {
'engine': 'claude',
'bypass_permission': true,
+ 'permission_mode': 'auto',
});
});
diff --git a/desktop/test/first_workspace_test.dart b/desktop/test/first_workspace_test.dart
index b528cfb9b..d8e32c64f 100644
--- a/desktop/test/first_workspace_test.dart
+++ b/desktop/test/first_workspace_test.dart
@@ -77,6 +77,7 @@ class _FirstUseApp extends AppNotifier {
required String folder,
ProjectFolderRequest? projectFolder,
bool bypassPermission = false,
+ String? permissionMode,
String? codexHome,
String? dsh,
String? prompt,
diff --git a/desktop/test/new_agent_choices_layout_test.dart b/desktop/test/new_agent_choices_layout_test.dart
index f49f57122..7ab7e1550 100644
--- a/desktop/test/new_agent_choices_layout_test.dart
+++ b/desktop/test/new_agent_choices_layout_test.dart
@@ -59,6 +59,7 @@ class _ChoicesApp extends AppNotifier {
required String folder,
ProjectFolderRequest? projectFolder,
bool bypassPermission = false,
+ String? permissionMode,
String? codexHome,
String? swarmId,
PaneSplitRequest? split,
diff --git a/desktop/test/new_agent_codex_profile_test.dart b/desktop/test/new_agent_codex_profile_test.dart
index e0137c80d..81127f058 100644
--- a/desktop/test/new_agent_codex_profile_test.dart
+++ b/desktop/test/new_agent_codex_profile_test.dart
@@ -127,6 +127,7 @@ class _Notifier extends AppNotifier {
required String folder,
ProjectFolderRequest? projectFolder,
bool bypassPermission = false,
+ String? permissionMode,
String? codexHome,
String? dsh,
String? prompt,
diff --git a/desktop/test/new_agent_dsh_test.dart b/desktop/test/new_agent_dsh_test.dart
index 4e3e08be8..e46a3d7c8 100644
--- a/desktop/test/new_agent_dsh_test.dart
+++ b/desktop/test/new_agent_dsh_test.dart
@@ -100,6 +100,7 @@ class _Notifier extends AppNotifier {
required String engine,
required String folder,
bool bypassPermission = false,
+ String? permissionMode,
String? codexHome,
String? dsh,
String? prompt,
diff --git a/desktop/test/new_agent_engine_check_test.dart b/desktop/test/new_agent_engine_check_test.dart
index a2667057b..b09b93542 100644
--- a/desktop/test/new_agent_engine_check_test.dart
+++ b/desktop/test/new_agent_engine_check_test.dart
@@ -144,9 +144,13 @@ void main() {
await tester.ensureVisible(find.byKey(const Key('new-agent-advanced')));
await tester.tap(find.byKey(const Key('new-agent-advanced')));
await tester.pumpAndSettle();
- await tester.ensureVisible(find.text('Auto-approve'));
- await tester.tap(find.text('Auto-approve'));
- await tester.pump();
+ await tester.ensureVisible(
+ find.byKey(const Key('new-agent-permission-mode')),
+ );
+ await tester.tap(find.byKey(const Key('new-agent-permission-mode')));
+ await tester.pumpAndSettle();
+ await tester.tap(find.text('Ask first').last);
+ await tester.pumpAndSettle();
final retry = find.byKey(const Key('new-agent-retry-check'));
await tester.ensureVisible(retry);
final pending = app.pending['machine-1'] = Completer<void>();
@@ -200,7 +204,7 @@ void main() {
'machine': 'machine-1',
'engine': 'codex',
'folder': pickedFolder,
- // On by default; the click above turned it off, and the retry kept that choice.
+ // Auto-approve by default; Ask first was picked above, and the retry kept that choice.
'bypass': false,
});
expect(tester.takeException(), isNull);
@@ -316,6 +320,7 @@ class _RetryNotifier extends AppNotifier {
required String folder,
ProjectFolderRequest? projectFolder,
bool bypassPermission = false,
+ String? permissionMode,
String? codexHome,
String? dsh,
String? prompt,
diff --git a/desktop/test/new_agent_permission_mode_test.dart b/desktop/test/new_agent_permission_mode_test.dart
new file mode 100644
index 000000000..54fa5d930
--- /dev/null
+++ b/desktop/test/new_agent_permission_mode_test.dart
@@ -0,0 +1,269 @@
+// New Harness ▸ Advanced picks how far the agent may go without asking: Auto-approve by default, and
+// each engine's own modes beside it. The machine is sent the mode, and the yes/no an older daemon reads.
+import 'package:file_selector_platform_interface/file_selector_platform_interface.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/auth/auth_session.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/core/engine_availability.dart';
+import 'package:harness/core/models.dart';
+import 'package:harness/core/permission_modes.dart';
+import 'package:harness/core/project_folder.dart';
+import 'package:harness/state/app_state.dart';
+import 'package:harness/state/pane_arrangement.dart';
+import 'package:harness/widgets/new_agent_dialog.dart';
+
+class _Folders extends FileSelectorPlatform {
+ @override
+ Future<String?> getDirectoryPath({
+ String? initialDirectory,
+ String? confirmButtonText,
+ }) async => '/work/demo';
+}
+
+class _Notifier extends AppNotifier {
+ _Notifier()
+ : super(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ );
+
+ final launches = <Map<String, Object?>>[];
+
+ @override
+ Future<void> probeEngines(String machineId, {bool force = false}) async {}
+
+ @override
+ Future<void> probeDsh(String machineId, {bool force = false}) async {}
+
+ @override
+ Future<Map<String, dynamic>> listCodexProfiles(
+ String machineId, {
+ Set<String> observedPaths = const {},
+ }) async => {'profiles': <dynamic>[]};
+
+ @override
+ Future<String?> createAgent(
+ String machineId, {
+ required String engine,
+ required String folder,
+ bool bypassPermission = false,
+ String? permissionMode,
+ String? codexHome,
+ String? dsh,
+ String? prompt,
+ String? name,
+ String? agent,
+ ProjectFolderRequest? projectFolder,
+ String? swarmId,
+ PaneSplitRequest? split,
+ AgentCreationAttempt? attempt,
+ }) async {
+ launches.add({
+ 'engine': engine,
+ 'mode': permissionMode,
+ 'bypass': bypassPermission,
+ });
+ return 'Test launch refused.';
+ }
+}
+
+void main() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+ setUp(() => FileSelectorPlatform.instance = _Folders());
+
+ Future<_Notifier> open(
+ WidgetTester tester, {
+ String engine = 'claude',
+ }) async {
+ tester.view.devicePixelRatio = 1;
+ tester.view.physicalSize = const Size(1400, 1000);
+ addTearDown(tester.view.reset);
+ final notifier = _Notifier();
+ addTearDown(notifier.dispose);
+ const machine = Machine(
+ machineId: 'machine-1',
+ authMode: MachineAuthMode.remote,
+ name: 'harness-remote-box',
+ );
+ final state = MachineState(machine)..localOnly = true;
+ state.engines.replace(const [
+ EngineAvailability(engine: 'claude', installed: true),
+ EngineAvailability(engine: 'codex', installed: true),
+ EngineAvailability(engine: 'pi', installed: true),
+ ]);
+ notifier.machineStates['machine-1'] = state;
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Builder(
+ builder: (context) => Scaffold(
+ body: TextButton(
+ onPressed: () => showNewAgentDialog(
+ context,
+ notifier,
+ 'machine-1',
+ source: 'machine_row',
+ initialEngine: engine,
+ ),
+ child: const Text('open'),
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.tap(find.text('open'));
+ await tester.pumpAndSettle();
+ final newProject = find.byKey(
+ const ValueKey('new-agent-folder-newProject'),
+ );
+ await tester.ensureVisible(newProject);
+ await tester.tap(newProject);
+ await tester.pumpAndSettle();
+ await tester.ensureVisible(find.byKey(const Key('new-agent-advanced')));
+ await tester.tap(find.byKey(const Key('new-agent-advanced')));
+ await tester.pumpAndSettle();
+ return notifier;
+ }
+
+ final field = find.byKey(const Key('new-agent-permission-mode'));
+
+ Future<void> pickMode(WidgetTester tester, String label) async {
+ await tester.ensureVisible(field);
+ await tester.tap(field);
+ await tester.pumpAndSettle();
+ await tester.tap(find.text(label).last);
+ await tester.pumpAndSettle();
+ }
+
+ Future<void> create(WidgetTester tester) async {
+ await tester.ensureVisible(
+ find.byKey(const ValueKey('create-agent-submit')),
+ );
+ await tester.tap(find.byKey(const ValueKey('create-agent-submit')));
+ await tester.pump();
+ }
+
+ testWidgets('Auto-approve is the default', (tester) async {
+ final app = await open(tester);
+ expect(
+ find.descendant(of: field, matching: find.text('Auto-approve')),
+ findsOneWidget,
+ );
+ await create(tester);
+ expect(app.launches.single, {
+ 'engine': 'claude',
+ 'mode': 'auto',
+ 'bypass': true,
+ });
+ });
+
+ testWidgets('the menu says what each Claude Code mode does', (tester) async {
+ await open(tester);
+ await tester.ensureVisible(field);
+ await tester.tap(field);
+ await tester.pumpAndSettle();
+ for (final mode in permissionModesOf('claude')) {
+ expect(find.text(mode.label), findsWidgets);
+ expect(find.text(mode.detail), findsOneWidget);
+ }
+ });
+
+ testWidgets('Plan first is sent as a mode, and as no to an older machine', (
+ tester,
+ ) async {
+ final app = await open(tester);
+ await pickMode(tester, 'Plan first');
+ expect(
+ find.descendant(of: field, matching: find.text('Plan first')),
+ findsOneWidget,
+ );
+ await create(tester);
+ expect(app.launches.single, {
+ 'engine': 'claude',
+ 'mode': 'plan',
+ 'bypass': false,
+ });
+ });
+
+ testWidgets('Skip all checks reads as yes to an older machine', (
+ tester,
+ ) async {
+ final app = await open(tester);
+ await pickMode(tester, 'Skip all checks');
+ await create(tester);
+ expect(app.launches.single, {
+ 'engine': 'claude',
+ 'mode': 'full',
+ 'bypass': true,
+ });
+ });
+
+ testWidgets('Codex offers its own modes', (tester) async {
+ final app = await open(tester, engine: 'codex');
+ await pickMode(tester, 'Read only');
+ await create(tester);
+ expect(app.launches.single, {
+ 'engine': 'codex',
+ 'mode': 'readOnly',
+ 'bypass': false,
+ });
+ });
+
+ testWidgets('a mode the next engine lacks falls back to its default', (
+ tester,
+ ) async {
+ final app = await open(tester);
+ await pickMode(tester, 'Plan first');
+ await tester.ensureVisible(
+ find.byKey(const ValueKey('new-agent-quick-codex')),
+ );
+ await tester.tap(find.byKey(const ValueKey('new-agent-quick-codex')));
+ await tester.pumpAndSettle();
+ expect(
+ find.descendant(of: field, matching: find.text('Auto-approve')),
+ findsOneWidget,
+ );
+ await create(tester);
+ expect(app.launches.single, {
+ 'engine': 'codex',
+ 'mode': 'auto',
+ 'bypass': true,
+ });
+ });
+
+ testWidgets('a mode both engines have is kept across the switch', (
+ tester,
+ ) async {
+ final app = await open(tester);
+ await pickMode(tester, 'Ask first');
+ await tester.ensureVisible(
+ find.byKey(const ValueKey('new-agent-quick-codex')),
+ );
+ await tester.tap(find.byKey(const ValueKey('new-agent-quick-codex')));
+ await tester.pumpAndSettle();
+ await create(tester);
+ expect(app.launches.single, {
+ 'engine': 'codex',
+ 'mode': 'ask',
+ 'bypass': false,
+ });
+ });
+
+ test('every engine with modes starts on Auto-approve and can ask', () {
+ for (final MapEntry(key: engine, value: modes)
+ in kEnginePermissionModes.entries) {
+ expect(modes.first.id, kDefaultPermissionMode, reason: engine);
+ expect(modes.map((mode) => mode.id), contains('ask'), reason: engine);
+ expect(
+ modes.map((mode) => mode.id).toSet(),
+ hasLength(modes.length),
+ reason: engine,
+ );
+ }
+ expect(permissionModeApproves('auto'), isTrue);
+ expect(permissionModeApproves('full'), isTrue);
+ expect(permissionModeApproves('plan'), isFalse);
+ expect(permissionModeApproves('ask'), isFalse);
+ });
+}
diff --git a/desktop/test/new_agent_project_picker_test.dart b/desktop/test/new_agent_project_picker_test.dart
index 1b0545d29..c851efe87 100644
--- a/desktop/test/new_agent_project_picker_test.dart
+++ b/desktop/test/new_agent_project_picker_test.dart
@@ -63,6 +63,7 @@ class _App extends AppNotifier {
required String folder,
ProjectFolderRequest? projectFolder,
bool bypassPermission = false,
+ String? permissionMode,
String? codexHome,
String? swarmId,
PaneSplitRequest? split,
diff --git a/desktop/test/remote_folder_picker_test.dart b/desktop/test/remote_folder_picker_test.dart
index d5ad7da5a..c65754713 100644
--- a/desktop/test/remote_folder_picker_test.dart
+++ b/desktop/test/remote_folder_picker_test.dart
@@ -46,6 +46,7 @@ class _Folders extends AppNotifier {
required String folder,
ProjectFolderRequest? projectFolder,
bool bypassPermission = false,
+ String? permissionMode,
String? codexHome,
String? dsh,
String? prompt,
diff --git a/desktop/test/store_showcase_test.dart b/desktop/test/store_showcase_test.dart
index 485df1904..ea05fe443 100644
--- a/desktop/test/store_showcase_test.dart
+++ b/desktop/test/store_showcase_test.dart
@@ -75,6 +75,7 @@ class _Notifier extends AppNotifier {
required String engine,
required String folder,
bool bypassPermission = false,
+ String? permissionMode,
String? codexHome,
String? dsh,
String? prompt,