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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix: detect unsupported Codex approval flag
0xdiego251328cd96ab2a
diff --git a/cli/src/cli.ts b/cli/src/cli.tsindex a20ad2197..0fa267952 100644--- a/cli/src/cli.ts+++ b/cli/src/cli.ts@@ -70,7 +70,7 @@ import { gridAvailable } from './lib/gridExec.js'import { ENGINE_CLI_COMMANDS, ENGINES, PROCESS_ENGINES, engineBin, enginePathOverride } from './lib/engineBin.js'import { isTerminalEngine, type AgentEngine } from './engines/types.js'import { engineInstallRecipe } from './lib/engineInstall.js'-import { buildEngineCommandArgv, buildEngineLaunchArgv, commandAvailableInInteractiveShell, namedAgentArgs } from './lib/engineLaunch.js'+import { buildEngineCommandArgv, buildEngineLaunchArgv, commandAvailableInInteractiveShell, commandSupportsFlagInInteractiveShell, namedAgentArgs, permissionModeFlags } from './lib/engineLaunch.js'import { buildGridEngineLaunch, describeGridLaunch, gridConflictingEnvToClear, gridEnvVarNames, type GridLaunchMachine, type GridWebSearchStatus } from './lib/gridLaunch.js'import { HERMES_SYSTEM_MANAGED_DIR } from './lib/gridWebMcp.js'import { writeGridConfigDir } from './lib/gridConfigDir.js'@@ -4236,6 +4236,27 @@ async function runForeground(session: AuthSession): Promise<void> {} catch {return { ok: false, error: 'CWD_NOT_FOUND' }}+ // `--approve-for-me` was added after older Codex CLI releases. Refuse the+ // incompatible Auto mode before opening a pane, rather than letting Codex+ // reject the flag and leaving the person in an unexpected fallback shell.+ // Ask mode has no flag and remains a useful workaround until Codex updates.+ const codexAutoApprove =+ engine === 'codex' &&+ (permissionMode !== null+ ? permissionModeFlags(engine, permissionMode)?.includes('--approve-for-me') === true+ : bypassPermission)+ if (codexAutoApprove) {+ const support = await commandSupportsFlagInInteractiveShell(+ engineBin('codex'),+ '--approve-for-me',+ )+ if (support === 'unsupported') {+ const detail =+ 'Your installed Codex CLI does not support --approve-for-me, which Harness uses for Auto approvals. Update Codex and try again, or choose Ask permissions for this harness.'+ console.warn(`[agent] create codex refused · ${detail}`)+ return { ok: false, error: 'CODEX_CLI_TOO_OLD', detail }+ }+ }// A domain-specific harness: put its files into the workspace first (template, AGENTS.md, skill// links) and take its env/argv for the launch. Refused, never approximated, when it is not here.let dshEnv: Record<string, string> | undefineddiff --git a/cli/src/lib/engineLaunch.spec.ts b/cli/src/lib/engineLaunch.spec.tsindex 13741f699..068a852f9 100644--- a/cli/src/lib/engineLaunch.spec.ts+++ b/cli/src/lib/engineLaunch.spec.ts@@ -17,6 +17,7 @@ import {buildEngineCommandArgv,buildEngineLaunchArgv,commandAvailableInInteractiveShell,+ commandSupportsFlagInInteractiveShell,engineFallbackPrelude,firstPromptArgs,gridPanePrelude,@@ -574,6 +575,45 @@ describe('commandAvailableInInteractiveShell', () => {})})+describe('commandSupportsFlagInInteractiveShell', () => {+ it('distinguishes an older CLI help surface from a supported flag', async () => {+ const binDir = mkdtempSync(join(tmpdir(), 'harness-engine-capability-'))+ dirs.push(binDir)+ const codex = join(binDir, 'codex')+ writeFileSync(+ codex,+ '#!/bin/sh\nif [ "$1" = "--help" ]; then printf "%s\\n" "--sandbox"; exit 0; fi\nexit 2\n',+ )+ chmodSync(codex, 0o700)+ process.env.HARNESS_ENGINE_TEST_PATH = binDir++ await expect(+ commandSupportsFlagInInteractiveShell('codex', '--approve-for-me', bashProbeShell()),+ ).resolves.toBe('unsupported')++ writeFileSync(+ codex,+ '#!/bin/sh\nif [ "$1" = "--help" ]; then printf "%s\\n" "--approve-for-me"; exit 0; fi\nexit 2\n',+ )+ await expect(+ commandSupportsFlagInInteractiveShell('codex', '--approve-for-me', bashProbeShell()),+ ).resolves.toBe('supported')+ })++ it('does not reject a CLI when its help command cannot be inspected', async () => {+ const binDir = mkdtempSync(join(tmpdir(), 'harness-engine-capability-'))+ dirs.push(binDir)+ const codex = join(binDir, 'codex')+ writeFileSync(codex, '#!/bin/sh\nexit 2\n')+ chmodSync(codex, 0o700)+ process.env.HARNESS_ENGINE_TEST_PATH = binDir++ await expect(+ commandSupportsFlagInInteractiveShell('codex', '--approve-for-me', bashProbeShell()),+ ).resolves.toBe('unknown')+ })+})+describe('buildEngineLaunchArgv — the grid the pane finds', () => {/** A runnable `grid` at `dir/grid`. Which one the pane's shell resolves is the assertion. */function gridAt(dir: string): string {diff --git a/cli/src/lib/engineLaunch.ts b/cli/src/lib/engineLaunch.tsindex aa3e2a015..18f4c0835 100644--- a/cli/src/lib/engineLaunch.ts+++ b/cli/src/lib/engineLaunch.ts@@ -795,3 +795,39 @@ export async function commandAvailableInInteractiveShell()})}++export type CommandFlagSupport = 'supported' | 'unsupported' | 'unknown'++/**+ * Checks a CLI's own help from the same interactive shell that would launch+ * it. `unknown` is deliberately non-blocking: a broken or unusually slow help+ * command must not turn an otherwise usable engine into a false refusal.+ */+export async function commandSupportsFlagInInteractiveShell(+ command: string,+ flag: string,+ shell: string | undefined = undefined,+): Promise<CommandFlagSupport> {+ const interactive = interactiveEngineShell(shell)+ if (!interactive) return 'unknown'+ const script = [+ 'help="$("$1" --help 2>&1)"',+ 'status=$?',+ '[ "$status" -eq 0 ] || exit 2',+ 'case "$help" in *"$2"*) exit 0 ;; *) exit 1 ;; esac',+ ].join('\n')+ return await new Promise((resolve) => {+ execFile(+ interactive.path,+ [...interactive.args, script, 'harness-engine-capability', command, flag],+ { timeout: 5_000 },+ (error) => {+ if (!error) resolve('supported')+ else {+ const code = (error as { code?: number | string }).code+ resolve(code === 1 || code === '1' ? 'unsupported' : 'unknown')+ }+ },+ )+ })+}diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dartindex 0c175b126..c1b5fa2d2 100644--- a/desktop/lib/state/app_state.dart+++ b/desktop/lib/state/app_state.dart@@ -6046,6 +6046,10 @@ class AppNotifier extends ChangeNotifier {'TMUX_UNAVAILABLE' =>'Harness needs tmux to start harnesses on $machine. ''Install tmux there, then try again.',+ 'CODEX_CLI_TOO_OLD' =>+ detail ??+ 'The installed Codex CLI on $machine is too old for Auto approvals. '+ 'Update Codex, or choose Ask permissions.','UNSUPPORTED_ON_REMOTE' || 'UNSUPPORTED' =>'Update the harness CLI on this machine to start a harness','INVALID_DSH' =>@@ -6230,6 +6234,7 @@ class AppNotifier extends ChangeNotifier {'INVALID_PROMPT','AGENT_UNSUPPORTED','TMUX_UNAVAILABLE',+ 'CODEX_CLI_TOO_OLD','TMUX_TOO_OLD_FOR_GRID','GRID_CONFIG_FAILED','UNSUPPORTED_ON_REMOTE',diff --git a/desktop/test/swarm_async_test.dart b/desktop/test/swarm_async_test.dartindex c158f91fe..e8f26fa4b 100644--- a/desktop/test/swarm_async_test.dart+++ b/desktop/test/swarm_async_test.dart@@ -97,6 +97,11 @@ void main() {null,'Harness needs tmux to start harnesses on Test host. Install tmux there, then try again.',),+ (+ 'CODEX_CLI_TOO_OLD',+ 'Your installed Codex CLI does not support --approve-for-me. Update Codex and try again.',+ 'Your installed Codex CLI does not support --approve-for-me. Update Codex and try again.',+ ),('UNSUPPORTED',null,