feat(headless): add -y / --yolo CLI flag to sf headless

- HeadlessOptions.yolo added
- parseHeadlessArgs handles --yolo and -y (short form)
- SF_YOLO=1 is injected into the RPC child env when flag is set
- AutoSession._loadPersistedModeState() checks SF_YOLO=1 and
  auto-activates YOLO mode (build+autonomous+deep+unrestricted)
  on session startup

Usage:
  sf headless -y autonomous       # YOLO + autonomous mode
  sf headless --yolo next         # YOLO + run next unit

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Mikael Hugo 2026-05-09 19:05:32 +02:00
parent 995a57335b
commit b93409cfa4
2 changed files with 11 additions and 1 deletions

View file

@ -200,6 +200,7 @@ export interface HeadlessOptions {
eventFilter?: Set<string>; // filter JSONL output to specific event types
resumeSession?: string; // session ID to resume (--resume <id>)
bare?: boolean; // --bare: suppress CLAUDE.md/AGENTS.md, user skills, project preferences
yolo?: boolean; // --yolo / -y: activate YOLO mode (build+autonomous+deep+unrestricted)
}
/**
@ -381,7 +382,9 @@ export function parseHeadlessArgs(argv: string[]): HeadlessOptions {
const arg = args[i];
if (arg === "headless") continue;
if (arg.startsWith("--")) {
if (arg === "-y") {
options.yolo = true;
} else if (arg.startsWith("--")) {
if (arg === "--timeout" && i + 1 < args.length) {
options.timeout = parseInt(args[++i], 10);
if (Number.isNaN(options.timeout) || options.timeout < 0) {
@ -460,6 +463,8 @@ export function parseHeadlessArgs(argv: string[]): HeadlessOptions {
options.resumeSession = args[++i];
} else if (arg === "--bare") {
options.bare = true;
} else if (arg === "--yolo") {
options.yolo = true;
} else if (commandSeen) {
options.commandArgs.push(arg);
}
@ -864,6 +869,7 @@ async function runHeadlessOnce(
clientOptions.env = {
...((clientOptions.env as Record<string, string>) || {}),
SF_HEADLESS: "1",
...(options.yolo ? { SF_YOLO: "1" } : {}),
};
// Propagate --bare to the child process
if (options.bare) {

View file

@ -118,6 +118,10 @@ export class AutoSession {
// Always stamp surface from env: persisted value reflects previous launch's
// surface and should not override the current surface detection.
this.surface = detectSurface();
// Auto-activate YOLO when SF_YOLO=1 (set by --yolo / -y CLI flag)
if (process.env.SF_YOLO === "1" && !this.yolo) {
this.toggleYolo();
}
}
// ── Lifecycle ────────────────────────────────────────────────────────────