diff options
| author | user <user@clank> | 2026-07-22 20:07:05 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-08-12 19:34:35 +0200 |
| commit | 8f75a284f53b1ceb045de157c9381b9de7bfe209 (patch) | |
| tree | 397d7747954de25caf6f1b4845d3828c44c0df0b /pi-ext | |
| parent | user-prompt-frame: minimal glyphic corner (❯ ▁ prompt+cursor) (diff) | |
| download | sl0ppi-8f75a284f53b1ceb045de157c9381b9de7bfe209.tar.gz sl0ppi-8f75a284f53b1ceb045de157c9381b9de7bfe209.tar.xz sl0ppi-8f75a284f53b1ceb045de157c9381b9de7bfe209.zip | |
Add reload-hotkey.ts: bind a key (F5) to /reload
registerShortcut handlers only get a plain ExtensionContext (no ctx.reload,
which is command-context only), and keybindings.json has no reload action.
So register a /reload-runtime command that owns ctx.reload() and have the
shortcut queue it as a follow-up message — pi's documented reload pattern.
Key configurable via RELOAD_KEY.
Diffstat (limited to 'pi-ext')
| -rw-r--r-- | pi-ext/reload-hotkey.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/pi-ext/reload-hotkey.ts b/pi-ext/reload-hotkey.ts new file mode 100644 index 0000000..2457a70 --- /dev/null +++ b/pi-ext/reload-hotkey.ts @@ -0,0 +1,40 @@ +/** + * Reload Hotkey + * + * Binds a key to pi's /reload (reload extensions, skills, prompts, themes, + * context files) so you don't have to type it during rapid extension dev. + * + * Why a command + shortcut instead of a direct handler: + * ctx.reload() lives on ExtensionCommandContext (command handlers only) — it + * can deadlock if called from event/shortcut/tool contexts, and the shortcut + * handler only gets a plain ExtensionContext. So we register a real command + * (/reload-runtime) that owns the reload, and the shortcut just QUEUES that + * command as a follow-up user message. When idle it runs immediately; mid-run + * it reloads once the agent settles. This is pi's blessed reload pattern. + * + * Change RELOAD_KEY below to taste. Valid keys/modifiers: see keybindings.md + * (letters, digits, f1-f12, and ctrl/shift/alt combos, e.g. "ctrl+alt+r"). + */ + +import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; + +const RELOAD_KEY = "f5"; + +export default function (pi: ExtensionAPI) { + pi.registerCommand("reload-runtime", { + description: "Reload extensions, skills, prompts, themes, and context files", + handler: async (_args, ctx) => { + await ctx.reload(); + return; + }, + }); + + pi.registerShortcut(RELOAD_KEY, { + description: "Reload pi runtime (extensions/skills/prompts/themes)", + handler: (ctx) => { + // Queue the command; the command handler owns the actual ctx.reload(). + pi.sendUserMessage("/reload-runtime", { deliverAs: "followUp" }); + if (ctx.hasUI) ctx.ui.notify("Reloading pi runtime…", "info"); + }, + }); +} |
