From e06f0a669652e7ed1474ebf0f5276aaf00b01b4c Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Sun, 5 Apr 2026 00:09:44 -0700 Subject: [PATCH] feat: pair-agent auto-launches headed mode before pairing When pair-agent detects headless mode, it auto-switches to headed (visible Chromium window) so the user can watch what the remote agent does. Use --headless to skip this. Fixed compiled binary path resolution (process.execPath, not process.argv[1] which is virtual /$bunfs/ in Bun compiled binaries). Co-Authored-By: Claude Opus 4.6 (1M context) --- browse/src/cli.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/browse/src/cli.ts b/browse/src/cli.ts index 09593344..87312636 100644 --- a/browse/src/cli.ts +++ b/browse/src/cli.ts @@ -922,10 +922,31 @@ Refs: After 'snapshot', use @e1, @e2... as selectors: commandArgs.push(stdin.trim()); } - const state = await ensureServer(); + let state = await ensureServer(); // ─── Pair-Agent (post-server, pre-dispatch) ────────────── if (command === 'pair-agent') { + // Ensure headed mode — the user should see the browser window + // when sharing it with another agent. Feels safer, more impressive. + if (state.mode !== 'headed' && !hasFlag(commandArgs, '--headless')) { + console.log('[browse] Opening GStack Browser so you can see what the remote agent does...'); + // In compiled binaries, process.argv[1] is /$bunfs/... (virtual). + // Use process.execPath which is the real binary on disk. + const browseBin = process.execPath; + const connectProc = Bun.spawn([browseBin, 'connect'], { + cwd: process.cwd(), + stdio: ['ignore', 'inherit', 'inherit'], + env: process.env, + }); + await connectProc.exited; + // Re-read state after headed mode switch + const newState = readState(); + if (newState && await isServerHealthy(newState.port)) { + state = newState as ServerState; + } else { + console.warn('[browse] Could not switch to headed mode. Continuing headless.'); + } + } await handlePairAgent(state, commandArgs); process.exit(0); }