Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/main/codex/codex-structured-app-server-args.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
import { describe, expect, it } from 'vitest'
import { resolveCodexStructuredAppServerArgs } from './codex-structured-app-server-args'
import { YOLO_TUI_AGENT_ARGS } from '../../shared/tui-agent-permissions'

describe('structured Codex app-server arguments', () => {
it.each(['posix', 'powershell', 'cmd'] as const)(
'translates the configured YOLO default into app-server permissions on %s',
(shell) => {
expect(resolveCodexStructuredAppServerArgs(YOLO_TUI_AGENT_ARGS.codex!, shell)).toEqual([
'-c',
'approval_policy="never"',
'-c',
'sandbox_mode="danger-full-access"'
])
}
)

it.each([
'-a on-request -s workspace-write',
'--ask-for-approval=on-request --sandbox=workspace-write'
])('preserves explicit restricted permissions: %s', (configured) => {
expect(resolveCodexStructuredAppServerArgs(configured, 'posix')).toEqual([
'-c',
'approval_policy="on-request"',
'-c',
'sandbox_mode="workspace-write"'
])
})

it('does not grant bypass permissions when YOLO is disabled', () => {
expect(resolveCodexStructuredAppServerArgs('', 'posix')).toEqual([])
})

it('keeps configuration flags and converts effort to the app-server config contract', () => {
expect(
resolveCodexStructuredAppServerArgs(
Expand Down
16 changes: 15 additions & 1 deletion src/main/codex/codex-structured-app-server-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ const BOOLEAN_FLAGS = new Set([
])

const EFFORT_FLAGS = new Set(['--effort', '--reasoning-effort'])
const PERMISSION_CONFIG_KEYS = new Map([
['-a', 'approval_policy'],
['--ask-for-approval', 'approval_policy'],
['-s', 'sandbox_mode'],
['--sandbox', 'sandbox_mode']
])

function configuredArgsError(detail: string): Error {
return new Error(
Expand Down Expand Up @@ -63,6 +69,11 @@ export function resolveCodexStructuredAppServerArgs(
for (let index = 0; index < parsed.tokens.length; index += 1) {
const token = parsed.tokens[index]
const { flag, inlineValue } = splitOption(token)
// Codex accepts the TUI bypass flag before app-server but does not apply it.
if (flag === '--dangerously-bypass-approvals-and-sandbox' && inlineValue === undefined) {
result.push('-c', 'approval_policy="never"', '-c', 'sandbox_mode="danger-full-access"')
continue
}
if (BOOLEAN_FLAGS.has(flag) && inlineValue === undefined) {
result.push(flag)
continue
Expand All @@ -74,7 +85,10 @@ export function resolveCodexStructuredAppServerArgs(
if (value === undefined || value.length === 0) {
throw configuredArgsError(`${flag} requires a value`)
}
if (EFFORT_FLAGS.has(flag)) {
const permissionKey = PERMISSION_CONFIG_KEYS.get(flag)
if (permissionKey) {
result.push('-c', `${permissionKey}=${JSON.stringify(value)}`)
} else if (EFFORT_FLAGS.has(flag)) {
result.push('-c', `model_reasoning_effort=${value}`)
} else {
result.push(flag, value)
Expand Down
Loading