From 21bee839279063445bf3f6097e374ddd93f84316 Mon Sep 17 00:00:00 2001 From: Jie Tan <30162706+J-TN@users.noreply.github.com> Date: Mon, 7 Sep 2026 14:15:04 +1000 Subject: [PATCH 1/4] fix(codex): apply Chat launch permission settings --- .../codex-structured-app-server-args.test.ts | 29 +++++++++++++++++++ .../codex/codex-structured-app-server-args.ts | 26 ++++++++++++++--- ...codex-structured-launch-resolution.test.ts | 23 +++++++++++++++ .../codex-structured-launch-resolution.ts | 3 +- 4 files changed, 76 insertions(+), 5 deletions(-) diff --git a/src/main/codex/codex-structured-app-server-args.test.ts b/src/main/codex/codex-structured-app-server-args.test.ts index f76305cf7c1e..ffeb0a036024 100644 --- a/src/main/codex/codex-structured-app-server-args.test.ts +++ b/src/main/codex/codex-structured-app-server-args.test.ts @@ -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( diff --git a/src/main/codex/codex-structured-app-server-args.ts b/src/main/codex/codex-structured-app-server-args.ts index af83c46c8a2c..89e9dec4db28 100644 --- a/src/main/codex/codex-structured-app-server-args.ts +++ b/src/main/codex/codex-structured-app-server-args.ts @@ -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( @@ -59,10 +65,19 @@ export function resolveCodexStructuredAppServerArgs( if (divergent) { throw configuredArgsError(configuredArgs.slice(divergent.start, divergent.end)) } + return resolveCodexStructuredAppServerArgv(parsed.tokens) +} + +export function resolveCodexStructuredAppServerArgv(tokens: readonly string[]): string[] { const result: string[] = [] - for (let index = 0; index < parsed.tokens.length; index += 1) { - const token = parsed.tokens[index] + for (let index = 0; index < tokens.length; index += 1) { + const token = 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 @@ -70,11 +85,14 @@ export function resolveCodexStructuredAppServerArgs( if (!VALUE_FLAGS.has(flag)) { throw configuredArgsError(token || 'an empty positional argument') } - const value = inlineValue ?? parsed.tokens[++index] + const value = inlineValue ?? tokens[++index] 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) diff --git a/src/main/codex/codex-structured-launch-resolution.test.ts b/src/main/codex/codex-structured-launch-resolution.test.ts index 484f7c1ee804..07cc3bed814a 100644 --- a/src/main/codex/codex-structured-launch-resolution.test.ts +++ b/src/main/codex/codex-structured-launch-resolution.test.ts @@ -105,6 +105,29 @@ describe('codex structured launch resolution', () => { ]) }) + it.each(['git-worktree', 'folder'] as const)( + 'translates a saved YOLO flag when reopening a %s Chat session', + async (workspaceKind) => { + const saved = record({ + launchArgs: ['--dangerously-bypass-approvals-and-sandbox'], + providerHandleChain: [ + { handle: { provider: 'codex', threadId: 'thread-current' } } + ] as AgentSessionRecord['providerHandleChain'] + }) + saved.location.workspaceKind = workspaceKind + const launch = await resolverFor(saved)({ identity: IDENTITY }) + + expect(launch.args).toEqual([ + '-c', + 'approval_policy="never"', + '-c', + 'sandbox_mode="danger-full-access"', + 'app-server' + ]) + expect(launch.resumeThreadId).toBe('thread-current') + } + ) + it('pins resume to the rollout file that proved the durable thread', async () => { const resolveRollout = vi.fn(async () => '/home/work/.codex/sessions/rollout.jsonl') const launch = await resolverFor( diff --git a/src/main/codex/codex-structured-launch-resolution.ts b/src/main/codex/codex-structured-launch-resolution.ts index b1cc7854808b..22a71aea7caf 100644 --- a/src/main/codex/codex-structured-launch-resolution.ts +++ b/src/main/codex/codex-structured-launch-resolution.ts @@ -13,6 +13,7 @@ import { resolveCodexCommand } from '../codex-cli/command' import type { AgentSessionRecordStore } from '../runtime/agent-session-record-store' import type { CodexStructuredLaunch } from './codex-structured-session-adapter' import { resolvePinnedCodexRolloutProof } from './codex-tui-rollout-proof' +import { resolveCodexStructuredAppServerArgv } from './codex-structured-app-server-args' export type CodexStructuredLaunchResolverDeps = { store: AgentSessionRecordStore @@ -56,7 +57,7 @@ export function createCodexStructuredLaunchResolver( pathEnv, ...(homePath ? { homePath } : {}) }) - const args = [...(record.launchArgs ?? []), 'app-server'] + const args = [...resolveCodexStructuredAppServerArgv(record.launchArgs ?? []), 'app-server'] const head = agentSessionProviderHandleChainHead(record.providerHandleChain) const resumeThreadId = head?.handle.provider === 'codex' ? head.handle.threadId : null return { From 096b20366011b25e69363c0bc6423f2e7745da4b Mon Sep 17 00:00:00 2001 From: Jie Tan <30162706+J-TN@users.noreply.github.com> Date: Mon, 7 Sep 2026 18:53:07 +1000 Subject: [PATCH 2/4] fix(codex): limit permission conversion to new Chat configuration --- .../codex/codex-structured-app-server-args.ts | 10 +++----- ...codex-structured-launch-resolution.test.ts | 23 ------------------- .../codex-structured-launch-resolution.ts | 3 +-- 3 files changed, 4 insertions(+), 32 deletions(-) diff --git a/src/main/codex/codex-structured-app-server-args.ts b/src/main/codex/codex-structured-app-server-args.ts index 89e9dec4db28..43025aa742d7 100644 --- a/src/main/codex/codex-structured-app-server-args.ts +++ b/src/main/codex/codex-structured-app-server-args.ts @@ -65,13 +65,9 @@ export function resolveCodexStructuredAppServerArgs( if (divergent) { throw configuredArgsError(configuredArgs.slice(divergent.start, divergent.end)) } - return resolveCodexStructuredAppServerArgv(parsed.tokens) -} - -export function resolveCodexStructuredAppServerArgv(tokens: readonly string[]): string[] { const result: string[] = [] - for (let index = 0; index < tokens.length; index += 1) { - const token = tokens[index] + 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) { @@ -85,7 +81,7 @@ export function resolveCodexStructuredAppServerArgv(tokens: readonly string[]): if (!VALUE_FLAGS.has(flag)) { throw configuredArgsError(token || 'an empty positional argument') } - const value = inlineValue ?? tokens[++index] + const value = inlineValue ?? parsed.tokens[++index] if (value === undefined || value.length === 0) { throw configuredArgsError(`${flag} requires a value`) } diff --git a/src/main/codex/codex-structured-launch-resolution.test.ts b/src/main/codex/codex-structured-launch-resolution.test.ts index 07cc3bed814a..484f7c1ee804 100644 --- a/src/main/codex/codex-structured-launch-resolution.test.ts +++ b/src/main/codex/codex-structured-launch-resolution.test.ts @@ -105,29 +105,6 @@ describe('codex structured launch resolution', () => { ]) }) - it.each(['git-worktree', 'folder'] as const)( - 'translates a saved YOLO flag when reopening a %s Chat session', - async (workspaceKind) => { - const saved = record({ - launchArgs: ['--dangerously-bypass-approvals-and-sandbox'], - providerHandleChain: [ - { handle: { provider: 'codex', threadId: 'thread-current' } } - ] as AgentSessionRecord['providerHandleChain'] - }) - saved.location.workspaceKind = workspaceKind - const launch = await resolverFor(saved)({ identity: IDENTITY }) - - expect(launch.args).toEqual([ - '-c', - 'approval_policy="never"', - '-c', - 'sandbox_mode="danger-full-access"', - 'app-server' - ]) - expect(launch.resumeThreadId).toBe('thread-current') - } - ) - it('pins resume to the rollout file that proved the durable thread', async () => { const resolveRollout = vi.fn(async () => '/home/work/.codex/sessions/rollout.jsonl') const launch = await resolverFor( diff --git a/src/main/codex/codex-structured-launch-resolution.ts b/src/main/codex/codex-structured-launch-resolution.ts index 22a71aea7caf..b1cc7854808b 100644 --- a/src/main/codex/codex-structured-launch-resolution.ts +++ b/src/main/codex/codex-structured-launch-resolution.ts @@ -13,7 +13,6 @@ import { resolveCodexCommand } from '../codex-cli/command' import type { AgentSessionRecordStore } from '../runtime/agent-session-record-store' import type { CodexStructuredLaunch } from './codex-structured-session-adapter' import { resolvePinnedCodexRolloutProof } from './codex-tui-rollout-proof' -import { resolveCodexStructuredAppServerArgv } from './codex-structured-app-server-args' export type CodexStructuredLaunchResolverDeps = { store: AgentSessionRecordStore @@ -57,7 +56,7 @@ export function createCodexStructuredLaunchResolver( pathEnv, ...(homePath ? { homePath } : {}) }) - const args = [...resolveCodexStructuredAppServerArgv(record.launchArgs ?? []), 'app-server'] + const args = [...(record.launchArgs ?? []), 'app-server'] const head = agentSessionProviderHandleChainHead(record.providerHandleChain) const resumeThreadId = head?.handle.provider === 'codex' ? head.handle.threadId : null return { From 9e0409ddce9f585ea768aac45eeeab7b5c5ee72f Mon Sep 17 00:00:00 2001 From: Jie Tan Date: Tue, 8 Sep 2026 09:55:01 +1000 Subject: [PATCH 3/4] test(codex): route permission assertions through a documented helper Satisfies CodeRabbit's docstring-coverage pre-merge check on the touched test functions and removes the duplicated expected-config arrays. Co-Authored-By: Claude Fable 5.1 --- .../codex-structured-app-server-args.test.ts | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/main/codex/codex-structured-app-server-args.test.ts b/src/main/codex/codex-structured-app-server-args.test.ts index ffeb0a036024..b09c8a62339b 100644 --- a/src/main/codex/codex-structured-app-server-args.test.ts +++ b/src/main/codex/codex-structured-app-server-args.test.ts @@ -1,35 +1,39 @@ import { describe, expect, it } from 'vitest' import { resolveCodexStructuredAppServerArgs } from './codex-structured-app-server-args' import { YOLO_TUI_AGENT_ARGS } from '../../shared/tui-agent-permissions' +import type { AgentStartupShell } from '../../shared/tui-agent-startup-shell' + +/** Asserts the configured CLI permission flags become explicit app-server config assignments. */ +function expectPermissionConfig( + configured: string, + shell: AgentStartupShell, + approvalPolicy: string, + sandboxMode: string +): void { + expect(resolveCodexStructuredAppServerArgs(configured, shell)).toEqual([ + '-c', + `approval_policy="${approvalPolicy}"`, + '-c', + `sandbox_mode="${sandboxMode}"` + ]) +} 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"' - ]) - } + (shell) => + expectPermissionConfig(YOLO_TUI_AGENT_ARGS.codex!, shell, 'never', '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"' - ]) - }) + ])('preserves explicit restricted permissions: %s', (configured) => + expectPermissionConfig(configured, 'posix', 'on-request', 'workspace-write') + ) - it('does not grant bypass permissions when YOLO is disabled', () => { - expect(resolveCodexStructuredAppServerArgs('', 'posix')).toEqual([]) - }) + 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( From 98abea07049b8ae8f3e3ac99a7d9af54a96b594b Mon Sep 17 00:00:00 2001 From: Jie Tan Date: Tue, 8 Sep 2026 10:04:53 +1000 Subject: [PATCH 4/4] test(codex): name and document the permission test callbacks CodeRabbit's docstring-coverage check counts anonymous callbacks in the touched test block, so the new cases run through documented functions. Co-Authored-By: Claude Fable 5.1 --- .../codex-structured-app-server-args.test.ts | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/codex/codex-structured-app-server-args.test.ts b/src/main/codex/codex-structured-app-server-args.test.ts index b09c8a62339b..61eb84cc969e 100644 --- a/src/main/codex/codex-structured-app-server-args.test.ts +++ b/src/main/codex/codex-structured-app-server-args.test.ts @@ -18,22 +18,33 @@ function expectPermissionConfig( ]) } +/** The YOLO default must reach app-server as config, since it ignores the TUI bypass flag. */ +function expectYoloDefaultTranslated(shell: AgentStartupShell): void { + expectPermissionConfig(YOLO_TUI_AGENT_ARGS.codex!, shell, 'never', 'danger-full-access') +} + +/** Restricted flags must keep their configured values in either short or long spelling. */ +function expectRestrictedPermissionsPreserved(configured: string): void { + expectPermissionConfig(configured, 'posix', 'on-request', 'workspace-write') +} + +/** An empty configuration must not grant bypass permissions implicitly. */ +function expectNoBypassWhenDisabled(): void { + expect(resolveCodexStructuredAppServerArgs('', 'posix')).toEqual([]) +} + 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) => - expectPermissionConfig(YOLO_TUI_AGENT_ARGS.codex!, shell, 'never', 'danger-full-access') + expectYoloDefaultTranslated ) it.each([ '-a on-request -s workspace-write', '--ask-for-approval=on-request --sandbox=workspace-write' - ])('preserves explicit restricted permissions: %s', (configured) => - expectPermissionConfig(configured, 'posix', 'on-request', 'workspace-write') - ) + ])('preserves explicit restricted permissions: %s', expectRestrictedPermissionsPreserved) - it('does not grant bypass permissions when YOLO is disabled', () => - expect(resolveCodexStructuredAppServerArgs('', 'posix')).toEqual([])) + it('does not grant bypass permissions when YOLO is disabled', expectNoBypassWhenDisabled) it('keeps configuration flags and converts effort to the app-server config contract', () => { expect(