fix(auto): cache lastCommandCtx from any SF command so Ctrl+Y works immediately

Previously required /autonomous first. Now any slash command (/next, /chat,
/clear etc.) caches the ExtensionCommandContext, so Ctrl+Y YOLO shortcut
works on first press after any command interaction.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Mikael Hugo 2026-05-10 08:10:27 +02:00
parent d56e68c789
commit d8c687702b

View file

@ -33,6 +33,17 @@ export function registerSFCommands(pi) {
getArgumentCompletions: (prefix) =>
getSfTopLevelCommandCompletions(command.cmd, prefix),
handler: async (args, ctx) => {
// Cache this command ctx so shortcut handlers (Ctrl+Y) can fall back
// to a valid ExtensionCommandContext that has newSession().
// Import lazily to avoid a circular dep at module load time.
importExtensionModule(import.meta.url, "../auto/session.js").then(
({ getAutoSession }) => {
const s = getAutoSession();
if (typeof ctx.newSession === "function") {
s.lastCommandCtx = ctx;
}
},
).catch(() => {});
await dispatchDirectSFCommand(command.cmd, args, ctx, pi);
},
});