/** * Reload Hotkey * * Convenience for rapid extension dev: a key that gets you to pi's built-in * /reload with minimal typing. * * WHY IT ONLY PREFILLS (can't fully auto-run): * There is no extension API that can invoke a reload directly. Confirmed in * pi's source: * 1. registerShortcut handlers receive a plain ExtensionContext, which has NO * ctx.reload() — reload lives on ExtensionCommandContext (command handlers * only, to avoid re-entrancy deadlocks). * 2. pi.sendUserMessage() delegates to prompt(text, {expandPromptTemplates: * false}), and prompt() only runs slash-command handling when * expandPromptTemplates is true. So a shortcut-sent "/reload" is delivered * to the MODEL as literal text, never executed. (The reload_runtime tool * snippet in the docs is broken for this reason.) * 3. The built-in /reload is handled inside the editor's onSubmit callback, * which is not exposed to extensions, so we can't submit on your behalf. * * So the best we can do is drop "/reload" into the editor; you press Enter. * If a future pi exposes a command/reload API for shortcuts, wire it here. * * Change RELOAD_KEY below to taste (see keybindings.md for the key format). */ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; const RELOAD_KEY = "f5"; const RELOAD_TEXT = "/reload"; export default function (pi: ExtensionAPI) { pi.registerShortcut(RELOAD_KEY, { description: "Prefill /reload (press Enter to reload the pi runtime)", handler: (ctx) => { if (!ctx.hasUI) return; const current = ctx.ui.getEditorText?.() ?? ""; if (current.trim() && current.trim() !== RELOAD_TEXT) { ctx.ui.notify(`Editor not empty — type ${RELOAD_TEXT} to reload`, "warning"); return; } ctx.ui.setEditorText(RELOAD_TEXT); ctx.ui.notify("Press Enter to reload the pi runtime", "info"); }, }); }