Skip to content
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7c0ddb9
feat(agents): store a typed permission mode instead of reading it fro…
brennanb2025 Oct 2, 2026
09d2264
fix(agents): keep migrated permission text lossless and read bypass a…
brennanb2025 Oct 2, 2026
4672b6f
fix(agents): second review pass on the typed permission mode
brennanb2025 Oct 2, 2026
bc71699
fix(agents): third review pass on the typed permission mode
brennanb2025 Oct 2, 2026
3df3cc7
fix(agents): fourth review pass and changed-code casting gate
brennanb2025 Oct 2, 2026
8a6c882
fix(agents): read Gemini and Qwen Code -y / --yolo / --approval-mode …
brennanb2025 Oct 2, 2026
81f12f5
fix(agents): read typed permission Arguments through one classifier
brennanb2025 Oct 3, 2026
e8cfcce
fix(agents): read quoted options as the CLI does and keep one lift
brennanb2025 Oct 3, 2026
ec202ed
fix(agents): save explicit empty launch text so a downgrade stays Manual
brennanb2025 Oct 3, 2026
b463a8f
fix(agents): keep per-agent choices on the switch; caller args follow…
brennanb2025 Oct 3, 2026
0760be8
fix(agents): one effective-mode reading; list and clear every own choice
brennanb2025 Oct 3, 2026
a279c30
fix(agents): read typed Arguments with the shell that launches them
brennanb2025 Oct 3, 2026
c15ebae
fix(agents): cut the stored bypass flag only where every shell agrees
brennanb2025 Oct 4, 2026
74f48d3
fix(agents): refuse a lift that would change any other word
brennanb2025 Oct 4, 2026
9004978
Merge origin/main into brennanb2025/sta-8902-typed-permission-mode
brennanb2025 Oct 4, 2026
195e22d
fix(settings): say why each agent doesn't follow the permissions switch
brennanb2025 Oct 4, 2026
c05100f
fix(settings): keep permission line links honest for undetected agents
brennanb2025 Oct 4, 2026
3b05c51
fix(settings): show the focus ring where a permission line link lands
brennanb2025 Oct 4, 2026
5d1b991
Merge commit '9c6702bb074813cfe338ed4162c59d0a8d178c6b' into brennanb…
brennanb2025 Oct 7, 2026
3d61a8b
Merge pinned main into typed agent permission settings
brennanb2025 Oct 7, 2026
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
15 changes: 11 additions & 4 deletions mobile/src/session/ai-vault-resume-launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { isResumableTuiAgent } from '../../../src/shared/agent-session-resume'
import type { SleepingAgentLaunchConfig } from '../../../src/shared/agent-session-resume'
import { buildAgentResumeStartupPlan } from '../../../src/shared/tui-agent-startup'
import {
resolveTuiAgentLaunchArgs,
resolveTuiAgentLaunchEnv
resolveComposedTuiAgentLaunchArgs,
resolveComposedTuiAgentLaunchEnv
} from '../../../src/shared/tui-agent-launch-defaults'
import { normalizeAiVaultResumeFilePath } from '../../../src/shared/ai-vault-resume-path'
import type { TuiAgent } from '../../../src/shared/tui-agent'
Expand Down Expand Up @@ -49,6 +49,7 @@ export function buildMobileAiVaultResumeCommand(args: {
})
}

/** The host's `settings.get` projection: launch arguments arrive with the permission flag inline. */
export type MobileAiVaultResumeSettings = {
agentCmdOverrides?: Partial<Record<TuiAgent, string | null>>
agentDefaultArgs?: Partial<Record<TuiAgent, string>>
Expand Down Expand Up @@ -87,8 +88,14 @@ export function buildMobileAiVaultResumeLaunch(args: {
cmdOverrides,
platform: args.hostPlatform,
shell,
agentArgs: resolveTuiAgentLaunchArgs(args.session.agent, args.settings?.agentDefaultArgs),
agentEnv: resolveTuiAgentLaunchEnv(args.session.agent, args.settings?.agentDefaultEnv),
agentArgs: resolveComposedTuiAgentLaunchArgs(
args.session.agent,
args.settings?.agentDefaultArgs
),
agentEnv: resolveComposedTuiAgentLaunchEnv(
args.session.agent,
args.settings?.agentDefaultEnv
),
...(args.session.agent === 'omp' && resumeFilePath
? { ompResumeFilePath: resumeFilePath }
: {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('hasClaudeAuthEnvConflict matches the strip it guards', () => {
// record -> launch env -> the predicate the terminal preflight gates on.
it('admits a blanked variable all the way from the settings record', () => {
const configured = normalizeTuiAgentEnvRecord({ claude: { ANTHROPIC_API_KEY: '' } })
const launchEnv = resolveTuiAgentLaunchEnv('claude', configured)
const launchEnv = resolveTuiAgentLaunchEnv('claude', { agentDefaultEnv: configured })

expect(launchEnv).toEqual({ ANTHROPIC_API_KEY: '' })
expect(hasClaudeAuthEnvConflict(launchEnv, 'linux')).toBe(false)
Expand Down
27 changes: 21 additions & 6 deletions src/main/claude/claude-structured-launch-resolution.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { chmodSync, mkdtempSync, mkdirSync, writeFileSync } from 'node:fs'
import type { AgentLaunchProfileSettings } from '../../shared/tui-agent-launch-defaults'
import { tmpdir } from 'node:os'
import { delimiter, join } from 'node:path'
import { describe, expect, it, vi } from 'vitest'
Expand Down Expand Up @@ -53,20 +54,25 @@ function makeExecutable(path: string): void {
}
}

/** Manual, with these Claude arguments typed into Settings. */
function manualWithArgs(claude: string): AgentLaunchProfileSettings {
return { agentPermissionMode: 'ask', agentDefaultArgs: { claude } }
}

function resolverFor(
value: AgentSessionRecord | null,
resolveEnv?: () => Record<string, string>,
stripAuthEnv = false,
// Manual by default so a test that is not about permissions is not silently about them.
agentDefaultArgs: Record<string, string> = { claude: '' },
permissionSettings: AgentLaunchProfileSettings = { agentPermissionMode: 'ask' },
hasTranscript: () => Promise<boolean> = async () => true
) {
return createClaudeStructuredLaunchResolver({
store: { getRecord: () => value } as unknown as AgentSessionRecordStore,
resolveWorkspacePath: async (id) => `/repos/${id}`,
resolveCommand: () => '/usr/local/bin/claude',
resolveAuthPolicy: () => ({ stripAuthEnv }),
resolvePermissionMode: () => claudeStructuredPermissionModeForSettings({ agentDefaultArgs }),
resolvePermissionMode: () => claudeStructuredPermissionModeForSettings(permissionSettings),
hasTranscript,
...(resolveEnv ? { resolveEnv } : {})
})
Expand Down Expand Up @@ -231,7 +237,7 @@ describe('claude structured launch resolution', () => {
}),
undefined,
false,
{ claude: '' },
{ agentPermissionMode: 'ask' },
hasTranscript
)({ identity: identityAt(null) })

Expand All @@ -257,7 +263,12 @@ describe('claude structured launch resolution', () => {
['--dangerously-skip-permissions --model Opus'],
['--model Opus --dangerously-skip-permissions']
])('starts a Yolo session in bypassPermissions for args %s', async (claude) => {
const launch = await resolverFor(record(), undefined, false, { claude })({ identity: IDENTITY })
const launch = await resolverFor(
record(),
undefined,
false,
manualWithArgs(claude)
)({ identity: IDENTITY })

expect(launch.options.extraArgs).toEqual({
'replay-user-messages': null,
Expand All @@ -279,11 +290,15 @@ describe('claude structured launch resolution', () => {
})
})

// Manual is stored as an empty string, which owns the key and so beats the shipped default.
it.each([[''], ['--model Opus']])(
'leaves a Manual session prompting for args %s',
async (claude) => {
const launch = await resolverFor(record(), undefined, false, { claude })({
const launch = await resolverFor(
record(),
undefined,
false,
manualWithArgs(claude)
)({
identity: IDENTITY
})

Expand Down
43 changes: 31 additions & 12 deletions src/main/claude/claude-structured-permission-mode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { describe, expect, it } from 'vitest'
import { claudeStructuredPermissionModeForSettings } from './claude-structured-permission-mode'

describe('claudeStructuredPermissionModeForSettings', () => {
// The three states the Agent Permissions toggle can leave behind. The untouched case is the
// common one and the easiest to get wrong: the toggle writes nothing until it is used, and the
// default Orca ships for the key it did not write is the bypass flag — which is what a terminal
// launch has always applied to an untouched profile.
// The untouched case is the common one and the easiest to get wrong: a profile with no stored
// mode gets the default Orca ships, which is bypass — what a terminal launch has always applied.
it('bypasses when the user has never opened Agent settings', () => {
expect(claudeStructuredPermissionModeForSettings({ agentDefaultArgs: {} })).toBe(
'bypassPermissions'
Expand All @@ -17,29 +15,50 @@ describe('claudeStructuredPermissionModeForSettings', () => {
)
})

it('bypasses when Yolo wrote the flag, alone or beside other tokens', () => {
it('bypasses in Yolo with or without extra arguments', () => {
expect(
claudeStructuredPermissionModeForSettings({
agentPermissionMode: 'bypass',
agentDefaultArgs: { claude: '--model Opus' }
})
).toBe('bypassPermissions')
})

// A terminal launch honours a bypass flag typed into Arguments, so the structured path does too.
it('bypasses when the flag is typed into Arguments under Manual', () => {
for (const claude of [
'--dangerously-skip-permissions',
'--dangerously-skip-permissions --model Opus',
'--model Opus --dangerously-skip-permissions'
]) {
expect(
claudeStructuredPermissionModeForSettings({ agentDefaultArgs: { claude } }),
claudeStructuredPermissionModeForSettings({
agentPermissionMode: 'ask',
agentDefaultArgs: { claude }
}),
claude
).toBe('bypassPermissions')
}
})

// Manual is stored as an empty string, which owns the key and so beats the shipped default.
it('prompts when Manual cleared the flag', () => {
expect(claudeStructuredPermissionModeForSettings({ agentDefaultArgs: { claude: '' } })).toBe(
it('prompts in Manual, globally or for Claude alone', () => {
expect(claudeStructuredPermissionModeForSettings({ agentPermissionMode: 'ask' })).toBe(
'default'
)
expect(
claudeStructuredPermissionModeForSettings({
agentPermissionModeOverrides: { claude: 'ask' },
agentDefaultArgs: { claude: '--model Opus' }
})
).toBe('default')
})

it('prompts when the user replaced the flag with something else', () => {
it('follows a Claude-only Yolo choice under a Manual default', () => {
expect(
claudeStructuredPermissionModeForSettings({ agentDefaultArgs: { claude: '--model Opus' } })
).toBe('default')
claudeStructuredPermissionModeForSettings({
agentPermissionMode: 'ask',
agentPermissionModeOverrides: { claude: 'bypass' }
})
).toBe('bypassPermissions')
})
})
19 changes: 12 additions & 7 deletions src/main/claude/claude-structured-permission-mode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { PermissionMode } from '@anthropic-ai/claude-agent-sdk'
import type { GlobalSettings } from '../../shared/global-settings-types'
import { resolvedTuiAgentArgsBypassPermissions } from '../../shared/tui-agent-launch-defaults'
import type { AgentLaunchProfileSettings } from '../../shared/tui-agent-launch-defaults'
import { resolveAgentPermissionPosture } from '../../shared/tui-agent-permission-args'
import { resolveLocalAgentLaunchTarget } from '../../shared/windows-terminal-shell'

/**
* The Agent Permissions setting as the SDK's own permission mode.
Expand All @@ -9,18 +11,21 @@ import { resolvedTuiAgentArgsBypassPermissions } from '../../shared/tui-agent-la
* latched into the session record: the setting is the one copy of this fact, so nothing can
* disagree with it and a failed restore cannot silently downgrade a session to prompting.
*
* Yolo still stores itself as the agent's bypass flag inside the launch arguments, which is also
* what a terminal launch acts on, so presence of that flag is the fact to read — resolved through
* the same default fallback the terminal uses, which is why an untouched profile bypasses. The
* rest of the arguments string is a terminal concern this path does not interpret.
* Reads the agent's typed permission mode — the same field a terminal launch turns into its
* flag — plus a bypass flag typed into Arguments, which a terminal launch also honours. The rest
* of the arguments string is a terminal concern this path does not interpret.
*/
export function claudeStructuredPermissionModeForSettings(
settings:
| Partial<Pick<GlobalSettings, 'agentDefaultArgs' | 'terminalWindowsShell'>>
| (AgentLaunchProfileSettings & Partial<Pick<GlobalSettings, 'terminalWindowsShell'>>)
| null
| undefined
): PermissionMode {
return resolvedTuiAgentArgsBypassPermissions('claude', settings, process.platform)
return resolveAgentPermissionPosture(
'claude',
settings,
resolveLocalAgentLaunchTarget(process.platform, settings?.terminalWindowsShell)
).effectiveBypass
? 'bypassPermissions'
: 'default'
}
9 changes: 5 additions & 4 deletions src/main/codex/codex-structured-launch-resolution.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { describe, expect, it, vi } from 'vitest'
import type { AgentLaunchProfileSettings } from '../../shared/tui-agent-launch-defaults'
import type { AgentSessionRecord } from '../../shared/agent-session-record'
import type { AgentSessionProviderHandleLink } from '../../shared/agent-session-provider-handle'
import { LOCAL_EXECUTION_HOST_ID } from '../../shared/execution-host'
Expand Down Expand Up @@ -41,15 +42,15 @@ function resolverFor(
value: AgentSessionRecord | null,
resolveWorkspacePath: (workspaceId: string) => Promise<string> = async (id) => `/repos/${id}`,
resolveRollout: () => Promise<string | null> = async () => null,
agentDefaultArgs: Record<string, string> = { codex: '' }
permissionSettings: AgentLaunchProfileSettings = { agentPermissionMode: 'ask' }
) {
return createCodexStructuredLaunchResolver({
store: { getRecord: () => value } as unknown as AgentSessionRecordStore,
resolveWorkspacePath,
resolveCommand: () => '/usr/local/bin/codex',
resolveRollout,
isWindowsProcessStartTimeAvailable: () => true,
resolvePermissionPolicy: () => codexStructuredPermissionPolicyForSettings({ agentDefaultArgs })
resolvePermissionPolicy: () => codexStructuredPermissionPolicyForSettings(permissionSettings)
})
}

Expand Down Expand Up @@ -144,11 +145,11 @@ describe('codex structured launch resolution', () => {
expect(fresh).not.toHaveProperty('supersedeIfUnsaved')
})

// Agent Permissions is the only thing derived from the arguments field. app-server owns it on
// Agent Permissions is the only launch setting the structured path reads. app-server owns it on
// the thread RPC rather than through the interactive CLI's process flags.
it('resolves the bypass posture as app-server thread policy', async () => {
const launch = await resolverFor(record(), undefined, undefined, {
codex: '--dangerously-bypass-approvals-and-sandbox --model gpt-5.6-sol'
agentDefaultArgs: { codex: '--model gpt-5.6-sol' }
})({ identity: IDENTITY })

expect(launch.args).toEqual(['app-server'])
Expand Down
32 changes: 24 additions & 8 deletions src/main/codex/codex-structured-permission-policy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ describe('codexStructuredPermissionPolicyForSettings', () => {
).toEqual(BYPASS)
})

it('bypasses when Yolo wrote the flag, alone or beside other tokens', () => {
it('bypasses when the flag is typed into Arguments under Manual', () => {
for (const codex of [
'--dangerously-bypass-approvals-and-sandbox',
'--dangerously-bypass-approvals-and-sandbox --model gpt-5.6-sol',
'--model gpt-5.6-sol --dangerously-bypass-approvals-and-sandbox'
]) {
expect(
codexStructuredPermissionPolicyForSettings({ agentDefaultArgs: { codex } }),
codexStructuredPermissionPolicyForSettings({
agentPermissionMode: 'ask',
agentDefaultArgs: { codex }
}),
codex
).toEqual(BYPASS)
}
Expand All @@ -36,7 +39,10 @@ describe('codexStructuredPermissionPolicyForSettings', () => {
'-- --dangerously-bypass-approvals-and-sandbox'
]) {
expect(
codexStructuredPermissionPolicyForSettings({ agentDefaultArgs: { codex } }),
codexStructuredPermissionPolicyForSettings({
agentPermissionMode: 'ask',
agentDefaultArgs: { codex }
}),
codex
).toEqual(MANUAL)
}
Expand All @@ -46,16 +52,25 @@ describe('codexStructuredPermissionPolicyForSettings', () => {
// means the fields are ABSENT, and absent is not a reset. A session flipped Yolo → Manual
// resumed with the Yolo thread's `approvalPolicy: never` still in force and escalated with no
// prompt. Manual has to say what it wants.
it('states the approval posture when Manual cleared the flag', () => {
expect(codexStructuredPermissionPolicyForSettings({ agentDefaultArgs: { codex: '' } })).toEqual(
MANUAL
)
it('states the approval posture in Manual', () => {
expect(
codexStructuredPermissionPolicyForSettings({ agentPermissionModeOverrides: { codex: 'ask' } })
).toEqual(MANUAL)
})

it('follows the typed mode, not whether Arguments are custom', () => {
expect(
codexStructuredPermissionPolicyForSettings({ agentDefaultArgs: { codex: '-m gpt-5.6-sol' } })
).toEqual(BYPASS)
})

it('never answers with an absent policy for either posture', () => {
for (const codex of ['', '--dangerously-bypass-approvals-and-sandbox', '--model gpt-5.6-sol']) {
expect(
codexStructuredPermissionPolicyForSettings({ agentDefaultArgs: { codex } }),
codexStructuredPermissionPolicyForSettings({
agentPermissionMode: 'ask',
agentDefaultArgs: { codex }
}),
codex
).toBeDefined()
}
Expand All @@ -66,6 +81,7 @@ describe('codexStructuredPermissionPolicyForSettings', () => {
it('carries nothing but the permission posture out of the arguments field', () => {
expect(
codexStructuredPermissionPolicyForSettings({
agentPermissionMode: 'ask',
agentDefaultArgs: {
codex: '--profile review --add-dir /repo -c model_reasoning_effort=high'
}
Expand Down
19 changes: 12 additions & 7 deletions src/main/codex/codex-structured-permission-policy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { GlobalSettings } from '../../shared/global-settings-types'
import { resolvedTuiAgentArgsBypassPermissions } from '../../shared/tui-agent-launch-defaults'
import type { AgentLaunchProfileSettings } from '../../shared/tui-agent-launch-defaults'
import { resolveAgentPermissionPosture } from '../../shared/tui-agent-permission-args'
import { resolveLocalAgentLaunchTarget } from '../../shared/windows-terminal-shell'

export type CodexStructuredPermissionPolicy =
| { approvalPolicy: 'never'; sandbox: 'danger-full-access' }
Expand Down Expand Up @@ -29,21 +31,24 @@ const MANUAL_POLICY = { approvalPolicy: 'on-request', sandbox: 'workspace-write'
/**
* The Agent Permissions setting as app-server thread policy.
*
* Derived per acquisition from the resolved launch arguments, never from the free-text Arguments
* field: app-server takes a narrower option set than the interactive CLI and the two are versioned
* apart, so the only thing read out of that field is the posture the toggle stores in it. An
* untouched profile resolves to the default Orca ships, which is the bypass flag.
* Derived per acquisition from the agent's typed permission mode. App-server takes a narrower
* option set than the interactive CLI and the two are versioned apart, so the only thing read out
* of the free-text Arguments is the bypass flag, which a terminal launch also honours.
*
* Always a policy, never `undefined`: both postures have to be said out loud, because the one
* that goes unsaid is the one a resume silently inherits from the other.
*/
export function codexStructuredPermissionPolicyForSettings(
settings:
| Partial<Pick<GlobalSettings, 'agentDefaultArgs' | 'terminalWindowsShell'>>
| (AgentLaunchProfileSettings & Partial<Pick<GlobalSettings, 'terminalWindowsShell'>>)
| null
| undefined
): CodexStructuredPermissionPolicy {
return resolvedTuiAgentArgsBypassPermissions('codex', settings, process.platform)
return resolveAgentPermissionPosture(
'codex',
settings,
resolveLocalAgentLaunchTarget(process.platform, settings?.terminalWindowsShell)
).effectiveBypass
? BYPASS_POLICY
: MANUAL_POLICY
}
2 changes: 1 addition & 1 deletion src/main/codex/codex-structured-thread-open.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('openCodexThread', () => {
thread: { id: 'thread-existing' }
}))
const permissionPolicy = codexStructuredPermissionPolicyForSettings({
agentDefaultArgs: { codex: '' }
agentPermissionMode: 'ask'
})

await openCodexThread(
Expand Down
Loading
Loading