Restore agent hook opt-out controls (#2778)

This commit is contained in:
Neil
2026-05-25 10:37:22 -07:00
committed by GitHub
parent aaa6ade586
commit d4703bd1ab
50 changed files with 1627 additions and 275 deletions
+19
View File
@@ -0,0 +1,19 @@
export const ORCA_CLAUDE_AGENT_STATUS_SETTINGS_ENV = 'ORCA_CLAUDE_AGENT_STATUS_SETTINGS'
export const ORCA_CLAUDE_AGENT_STATUS_SETTINGS_FILE = 'claude-agent-status-settings.json'
type ClaudeSettingsShell = 'posix' | 'powershell' | 'cmd'
export function appendOrcaClaudeAgentStatusSettings(
command: string,
shell: ClaudeSettingsShell
): string {
// Why: Claude's --settings is a per-process overlay. CLAUDE_CONFIG_DIR
// would fork auth/session state and normal external Claude launches.
if (shell === 'powershell') {
return `${command} --settings $Env:${ORCA_CLAUDE_AGENT_STATUS_SETTINGS_ENV}`
}
if (shell === 'cmd') {
return `${command} --settings "%${ORCA_CLAUDE_AGENT_STATUS_SETTINGS_ENV}%"`
}
return `${command} --settings "$HOME/.orca/agent-hooks/${ORCA_CLAUDE_AGENT_STATUS_SETTINGS_FILE}"`
}
+5
View File
@@ -0,0 +1,5 @@
export const ORCA_CODEX_AGENT_STATUS_PROFILE = 'orca-agent-status'
export function appendOrcaCodexAgentStatusProfile(command: string): string {
return `${command} --profile-v2 ${ORCA_CODEX_AGENT_STATUS_PROFILE}`
}
+1
View File
@@ -250,6 +250,7 @@ export function getDefaultSettings(homedir: string): GlobalSettings {
opencodeWorkspaceId: '',
geminiCliOAuthEnabled: false,
agentCmdOverrides: {},
agentStatusHooksEnabled: true,
keepComputerAwakeWhileAgentsRun: false,
// Why: 'auto' runs a layout-aware probe at boot (see
// src/renderer/src/lib/keyboard-layout/*) that picks 'true' for US and
+73
View File
@@ -36,6 +36,79 @@ describe('tui agent startup plans', () => {
expect(plan?.launchCommand).toBe('claude "fix ^"quoted^" ^& ^%PATH^%"')
})
it('launches Codex with the Orca profile when agent status hooks are enabled', () => {
const plan = buildAgentStartupPlan({
agent: 'codex',
prompt: 'fix it',
cmdOverrides: {},
platform: 'linux',
useOrcaCodexAgentStatusProfile: true
})
expect(plan?.launchCommand).toBe("codex --profile-v2 orca-agent-status 'fix it'")
})
it('launches Claude with the Orca settings file when agent status hooks are enabled', () => {
const plan = buildAgentStartupPlan({
agent: 'claude',
prompt: 'fix it',
cmdOverrides: {},
platform: 'linux',
useOrcaClaudeAgentStatusSettings: true
})
expect(plan?.launchCommand).toBe(
'claude --settings "$HOME/.orca/agent-hooks/claude-agent-status-settings.json" \'fix it\''
)
})
it('uses the target shell syntax for Claude settings injection', () => {
expect(
buildAgentStartupPlan({
agent: 'claude',
prompt: 'fix it',
cmdOverrides: {},
platform: 'win32',
useOrcaClaudeAgentStatusSettings: true
})?.launchCommand
).toBe("claude --settings $Env:ORCA_CLAUDE_AGENT_STATUS_SETTINGS 'fix it'")
expect(
buildAgentStartupPlan({
agent: 'claude',
prompt: 'fix it',
cmdOverrides: {},
platform: 'win32',
shell: 'cmd',
useOrcaClaudeAgentStatusSettings: true
})?.launchCommand
).toBe('claude --settings "%ORCA_CLAUDE_AGENT_STATUS_SETTINGS%" "fix it"')
})
it('leaves Claude command overrides untouched', () => {
const plan = buildAgentStartupPlan({
agent: 'claude',
prompt: 'fix it',
cmdOverrides: { claude: 'claude --dangerously-skip-permissions' },
platform: 'linux',
useOrcaClaudeAgentStatusSettings: true
})
expect(plan?.launchCommand).toBe("claude --dangerously-skip-permissions 'fix it'")
})
it('leaves Codex command overrides untouched', () => {
const plan = buildAgentStartupPlan({
agent: 'codex',
prompt: 'fix it',
cmdOverrides: { codex: 'codex --profile work' },
platform: 'linux',
useOrcaCodexAgentStatusProfile: true
})
expect(plan?.launchCommand).toBe("codex --profile work 'fix it'")
})
it('clears draft environment variables with the target shell syntax', () => {
expect(
buildAgentDraftLaunchPlan({
+40 -2
View File
@@ -1,4 +1,6 @@
import { isShellProcess } from './agent-detection'
import { appendOrcaClaudeAgentStatusSettings } from './claude-settings'
import { appendOrcaCodexAgentStatusProfile } from './codex-profile'
import { TUI_AGENT_CONFIG } from './tui-agent-config'
import type { TuiAgent } from './types'
@@ -44,6 +46,26 @@ function commandSeparator(shell: AgentStartupShell): string {
return shell === 'cmd' ? ' & ' : '; '
}
function resolveBaseCommand(args: {
agent: TuiAgent
cmdOverrides: Partial<Record<TuiAgent, string>>
shell: AgentStartupShell
useOrcaClaudeAgentStatusSettings?: boolean
useOrcaCodexAgentStatusProfile?: boolean
}): string {
const override = args.cmdOverrides[args.agent]
if (override) {
return override
}
const command = TUI_AGENT_CONFIG[args.agent].launchCmd
if (args.agent === 'claude' && args.useOrcaClaudeAgentStatusSettings) {
return appendOrcaClaudeAgentStatusSettings(command, args.shell)
}
return args.agent === 'codex' && args.useOrcaCodexAgentStatusProfile
? appendOrcaCodexAgentStatusProfile(command)
: command
}
export function buildAgentStartupPlan(args: {
agent: TuiAgent
prompt: string
@@ -51,12 +73,20 @@ export function buildAgentStartupPlan(args: {
platform: NodeJS.Platform
shell?: AgentStartupShell
allowEmptyPromptLaunch?: boolean
useOrcaClaudeAgentStatusSettings?: boolean
useOrcaCodexAgentStatusProfile?: boolean
}): AgentStartupPlan | null {
const { agent, prompt, cmdOverrides, platform, allowEmptyPromptLaunch = false } = args
const shell = resolveStartupShell(platform, args.shell)
const trimmedPrompt = prompt.trim()
const config = TUI_AGENT_CONFIG[agent]
const baseCommand = cmdOverrides[agent] ?? config.launchCmd
const baseCommand = resolveBaseCommand({
agent,
cmdOverrides,
shell,
useOrcaClaudeAgentStatusSettings: args.useOrcaClaudeAgentStatusSettings,
useOrcaCodexAgentStatusProfile: args.useOrcaCodexAgentStatusProfile
})
if (!trimmedPrompt) {
if (!allowEmptyPromptLaunch) {
@@ -129,6 +159,8 @@ export function buildAgentDraftLaunchPlan(args: {
cmdOverrides: Partial<Record<TuiAgent, string>>
platform: NodeJS.Platform
shell?: AgentStartupShell
useOrcaClaudeAgentStatusSettings?: boolean
useOrcaCodexAgentStatusProfile?: boolean
}): AgentDraftLaunchPlan | null {
const { agent, draft, cmdOverrides, platform } = args
const shell = resolveStartupShell(platform, args.shell)
@@ -137,7 +169,13 @@ export function buildAgentDraftLaunchPlan(args: {
if (!trimmed) {
return null
}
const baseCommand = cmdOverrides[agent] ?? config.launchCmd
const baseCommand = resolveBaseCommand({
agent,
cmdOverrides,
shell,
useOrcaClaudeAgentStatusSettings: args.useOrcaClaudeAgentStatusSettings,
useOrcaCodexAgentStatusProfile: args.useOrcaCodexAgentStatusProfile
})
if (config.draftPromptFlag) {
const quoted = quoteStartupArg(trimmed, shell)
return {
+3
View File
@@ -1770,6 +1770,9 @@ export type GlobalSettings = {
geminiCliOAuthEnabled: boolean
/** Per-agent CLI command overrides. A missing key means use the catalog default binary name. */
agentCmdOverrides: Partial<Record<TuiAgent, string>>
/** Why: disabling must persist so startup does not reinstall global agent
* hook entries right after the user removes them from Settings or CLI. */
agentStatusHooksEnabled: boolean
/** When true, Orca requests local awake assertions while hook-reported agents are working. */
keepComputerAwakeWhileAgentsRun: boolean
/** Why: macOS terminals must choose between letting Option compose layout