diff --git a/src/services/worker/ProcessRegistry.ts b/src/services/worker/ProcessRegistry.ts index cd7dab89..e4888d26 100644 --- a/src/services/worker/ProcessRegistry.ts +++ b/src/services/worker/ProcessRegistry.ts @@ -416,7 +416,23 @@ export function createPidCapturingSpawn(sessionDbId: number) { // causing subsequent flags to be consumed as values for the preceding flag. // The Agent SDK may produce empty-string args (e.g., settingSources defaults to [] // which joins to ""). Node preserves these, but Bun drops them, breaking CLI parsing. - const args = spawnOptions.args.filter(arg => arg !== ''); + // + // FIX: Simply filtering empty strings has the same effect as Bun dropping them — + // it leaves the preceding flag (e.g. --setting-sources) without a value, causing + // the next flag (e.g. --permission-mode) to be consumed as that value. + // Instead, we must remove the entire flag+empty-value pair. + const args: string[] = []; + for (let i = 0; i < spawnOptions.args.length; i++) { + const arg = spawnOptions.args[i]; + if (arg === '') continue; // skip standalone empty strings + // If this is a --flag followed by an empty string, skip both (remove the pair entirely) + if (arg.startsWith('--') && i + 1 < spawnOptions.args.length && spawnOptions.args[i + 1] === '') { + i++; // skip the empty value too + continue; + } + args.push(arg); + } + const child = useCmdWrapper ? spawn('cmd.exe', ['/d', '/c', spawnOptions.command, ...args], {