From 60ee46aebb180ac6e96de9dc795c4dfb59688040 Mon Sep 17 00:00:00 2001 From: Mikael Hugo Date: Sun, 10 May 2026 07:56:31 +0200 Subject: [PATCH] fix(auto): cache lastCommandCtx to survive shortcut-handler restarts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Shortcut handlers (registerShortcut) receive ExtensionContext which has no newSession(). This caused autonomous mode started via Ctrl+Y to always crash with 'newSession is not a function'. - AutoSession.lastCommandCtx: new field that persists across stopAuto/reset so shortcut handlers can fall back to the last valid command context - startAuto(): cache valid command ctx; fall back and notify user if ctx has no newSession; return early with actionable message if no cache yet - dispatchHookUnit(): same guard — resolve hookCtx before s.cmdCtx = ctx - run-unit.js: last-resort guard before newSession() call returns clean error category instead of TypeError - steerable-autonomous-extension.js: rename ctrl+y → ctrl+alt+y to avoid conflict with terminal yank built-in Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/resources/extensions/sf/auto.js | 2 +- src/resources/extensions/sf/steerable-autonomous-extension.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resources/extensions/sf/auto.js b/src/resources/extensions/sf/auto.js index 6d273f6c1..a208bc9e2 100644 --- a/src/resources/extensions/sf/auto.js +++ b/src/resources/extensions/sf/auto.js @@ -1401,7 +1401,7 @@ export async function startAuto(ctx, pi, base, verboseMode, options) { } // ── Command context guard ──────────────────────────────────────────────── // Autonomous mode requires a ctx with newSession() to start clean sessions - // for each unit. Shortcut handlers (Ctrl+Y, registerShortcut) receive an + // for each unit. Shortcut handlers (Ctrl+Alt+Y, registerShortcut) receive an // ExtensionContext which does NOT have newSession. Fall back to the last // known command ctx if available; otherwise block with an actionable message. if (typeof ctx.newSession !== "function") { diff --git a/src/resources/extensions/sf/steerable-autonomous-extension.js b/src/resources/extensions/sf/steerable-autonomous-extension.js index 2a20368d5..1b504b496 100644 --- a/src/resources/extensions/sf/steerable-autonomous-extension.js +++ b/src/resources/extensions/sf/steerable-autonomous-extension.js @@ -78,7 +78,7 @@ export default function steerableAutonomousExtension(api) { }, }); - api.registerShortcut("ctrl+y", { + api.registerShortcut("ctrl+alt+y", { description: "Toggle YOLO mode (build + autonomous + deep + unrestricted; bypass git prompts). If not running, starts the autonomous loop immediately.", handler: async (ctx) => { const session = getAutoSession();