fix(auto): cache lastCommandCtx to survive shortcut-handler restarts

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>
This commit is contained in:
Mikael Hugo 2026-05-10 07:56:31 +02:00
parent 529138db9a
commit 60ee46aebb
2 changed files with 2 additions and 2 deletions

View file

@ -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") {

View file

@ -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();