fix(headless): skip Ask→Build mode gate in SF_HEADLESS mode

In headless mode the showConfirm dialog blocks forever since there is
no TUI to answer it. The user already consented by calling /next or
/autonomous explicitly — the gate adds no value and hangs the run.

Add process.env.SF_HEADLESS !== '1' to the gate condition so headless
runs bypass it and proceed directly to autonomous execution.

Verified: `sf headless --command next` now completes slice S03
(719 526 tokens, 10 tool calls, $0.027) without hanging.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Mikael Hugo 2026-05-12 17:28:09 +02:00
parent d22df007a7
commit 93d547c65e

View file

@ -1470,10 +1470,13 @@ export async function startAuto(ctx, pi, base, verboseMode, options) {
// Skip if workMode is already "build" — runControl is reset to "manual" on
// autonomous stop but workMode persists, so this avoids a spurious prompt
// for users who stay in Build mode between autonomous runs.
// Skip in headless mode — the user already consented by calling /next or
// /autonomous explicitly; showing a TUI confirm dialog would block forever.
if (
s.runControl === "manual" &&
s.workMode !== "build" &&
!options?.skipModeGate
!options?.skipModeGate &&
process.env.SF_HEADLESS !== "1"
) {
const confirmed = await showConfirm(ctx, {
title: "Switch to Build mode?",