Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

fix(workers): auto-mode appends the provider's own flag, not claude's

Gastón Péchieu5d38c8656438
diff --git a/src/main/config.ts b/src/main/config.ts
index e2a3b597..3fab8ce4 100644
--- a/src/main/config.ts
+++ b/src/main/config.ts
@@ -665,20 +665,6 @@ export function modelForRole(
return MODEL_WORKER;
}
-/** Auto-suggested command string given current autoMode preference. */
-export function commandForAutoMode(
- config: HarnessConfig,
- provider?: AgentProvider
-): string {
- const p = provider ?? inferAgentProvider(config.defaultCommand);
- const base = p === 'claude' || p === 'custom'
- ? config.defaultCommand
- : defaultCommandForProvider(p, config.defaultCommand);
- if (!config.autoMode) return base;
- const flag = autoModeFlagForProvider(p);
- return flag ? `${base} ${flag}` : base;
-}
-
/** Ensure harnessHome exists on disk. */
export function ensureHarnessHome(path: string): { ok: boolean; error?: string } {
try {
diff --git a/src/main/workerLaunch.ts b/src/main/workerLaunch.ts
index e6e0ff7b..a76d9373 100644
--- a/src/main/workerLaunch.ts
+++ b/src/main/workerLaunch.ts
@@ -3,7 +3,7 @@
* pure function: this exact translation silently killed real workers for days
* while reporting success, which is what earned it a unit test.
*/
-import { inferAgentProvider } from '../shared/agentProvider';
+import { autoModeFlagForProvider, inferAgentProvider } from '../shared/agentProvider';
import { tokenizeCommand } from '../shared/commandLine';
export interface WorkerLaunch {
@@ -32,14 +32,16 @@ export function buildWorkerLaunch(opts: {
// Inherit the app's auto (skip-permissions) mode when the request takes no
// stance of its own: a headless worker has no human to click through tool
// prompts, so without the flag it stalls at the first ask until the idle
- // reaper kills it. An explicit --permission-mode in the request always wins,
- // and non-claude commands are left untouched.
- if (
- opts.autoMode &&
- inferAgentProvider(command, opts.requestProvider) === 'claude' &&
- !command.includes('--permission-mode')
- ) {
- command += ' --permission-mode bypassPermissions';
+ // reaper kills it. The flag is the PROVIDER'S — a codex worker needs
+ // --dangerously-bypass-approvals-and-sandbox, and claude's --permission-mode
+ // would mean nothing to it (an earlier hardcoded-claude version left every
+ // non-claude worker stalling; review caught it). An explicit stance in the
+ // request still wins: the flag's leading token already present as a TOKEN
+ // (not substring — copilot's flag starts with `-s`) means the request chose.
+ const provider = inferAgentProvider(command, opts.requestProvider);
+ const autoFlag = opts.autoMode ? autoModeFlagForProvider(provider) : '';
+ if (autoFlag && !tokenizeCommand(command).includes(tokenizeCommand(autoFlag)[0])) {
+ command += ` ${autoFlag}`;
}
// god authors `command` as a full command LINE ("claude --model … --permission-mode …"),
// but the PTY layer takes ONE executable name (resolveCommand) plus argv — the
diff --git a/test/worker-launch.test.cjs b/test/worker-launch.test.cjs
index 9b0e09e3..f579c362 100644
--- a/test/worker-launch.test.cjs
+++ b/test/worker-launch.test.cjs
@@ -53,11 +53,45 @@ test('an explicit --permission-mode in the request always wins over auto-mode',
assert.deepEqual(l.args, ['--permission-mode', 'plan']);
});
-test('auto-mode leaves non-claude commands untouched, and OFF appends nothing', () => {
+test('auto-mode OFF appends nothing', () => {
+ assert.deepEqual(launch({ requestCommand: 'claude', autoMode: false }).args, []);
+ assert.deepEqual(launch({ requestCommand: 'codex', autoMode: false }).args, []);
+});
+
+test("auto-mode appends the PROVIDER'S flag, not claude's", () => {
+ // A codex worker given --permission-mode would still stall at its first ask;
+ // each provider's preset knows its own flag, same as the renderer's spawn path.
const codex = launch({ requestCommand: 'codex', autoMode: true });
- assert.deepEqual(codex.args, []);
- const off = launch({ requestCommand: 'claude', autoMode: false });
- assert.deepEqual(off.args, []);
+ assert.deepEqual(codex.args, ['--dangerously-bypass-approvals-and-sandbox']);
+ const agy = launch({ requestCommand: 'agy', autoMode: true });
+ assert.deepEqual(agy.args, ['--dangerously-skip-permissions']);
+ const kimi = launch({ requestCommand: 'kimi', autoMode: true });
+ assert.deepEqual(kimi.args, ['--auto']);
+});
+
+test('an explicit stance wins for non-claude providers too (no doubled flag)', () => {
+ const l = launch({
+ requestCommand: 'codex --dangerously-bypass-approvals-and-sandbox',
+ autoMode: true
+ });
+ assert.deepEqual(l.args, ['--dangerously-bypass-approvals-and-sandbox']);
+});
+
+test('a provider whose preset declares no auto flag gets nothing appended', () => {
+ assert.deepEqual(launch({ requestCommand: 'opencode', autoMode: true }).args, []);
+ assert.deepEqual(launch({ requestCommand: 'my-own-tool', autoMode: true }).args, []);
+});
+
+test('a multi-token auto flag appends whole, and the stance check is by token', () => {
+ // copilot's flag starts with `-s`; a substring check would read the `-s` inside
+ // --summarize as an explicit stance and skip the append.
+ const l = launch({ requestCommand: 'copilot --summarize', autoMode: true });
+ assert.deepEqual(l.args, ['--summarize', '-s', '--allow-all-tools', '--no-ask-user']);
+});
+
+test("an explicit request provider picks that provider's flag for a custom binary", () => {
+ const l = launch({ requestCommand: 'my-codex-wrapper', requestProvider: 'codex', autoMode: true });
+ assert.deepEqual(l.args, ['--dangerously-bypass-approvals-and-sandbox']);
});
test('a missing command falls back to the default, then to claude', () => {