From b93409cfa42f35239e87061c6ad7ea76b188af37 Mon Sep 17 00:00:00 2001 From: Mikael Hugo Date: Sat, 9 May 2026 19:05:32 +0200 Subject: [PATCH] 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> --- src/headless.ts | 8 +++++++- src/resources/extensions/sf/auto/session.js | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/headless.ts b/src/headless.ts index 0e35a6f4e..cb946a92e 100644 --- a/src/headless.ts +++ b/src/headless.ts @@ -200,6 +200,7 @@ export interface HeadlessOptions { eventFilter?: Set; // filter JSONL output to specific event types resumeSession?: string; // session ID to resume (--resume ) 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) || {}), SF_HEADLESS: "1", + ...(options.yolo ? { SF_YOLO: "1" } : {}), }; // Propagate --bare to the child process if (options.bare) { diff --git a/src/resources/extensions/sf/auto/session.js b/src/resources/extensions/sf/auto/session.js index f8074289d..eb7fc346e 100644 --- a/src/resources/extensions/sf/auto/session.js +++ b/src/resources/extensions/sf/auto/session.js @@ -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 ────────────────────────────────────────────────────────────