diff --git a/src/resources/extensions/sf/commands/index.js b/src/resources/extensions/sf/commands/index.js index 283f1ccf4..9b4a0fb39 100644 --- a/src/resources/extensions/sf/commands/index.js +++ b/src/resources/extensions/sf/commands/index.js @@ -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); }, });