@d3ara1n/pi-command-palette 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +28 -2
  2. package/package.json +1 -1
  3. package/src/index.ts +66 -4
package/README.md CHANGED
@@ -34,13 +34,39 @@ Or add to `~/.pi/agent/settings.json`:
34
34
 
35
35
  The palette lists:
36
36
 
37
- - **Built-in actions** — Model selector, New session, Compact, Reload, Fork, Tree, Resume
37
+ - **Built-in actions** — curated shortcuts for common operations (detailed below)
38
38
  - **Extension commands** — All registered `/command` entries
39
39
  - **Skills & Templates** — Skill commands and prompt templates
40
40
 
41
+ ### Built-in actions
42
+
43
+ Built-in actions are grouped by how they run:
44
+
45
+ **Run immediately** — they call pi's API directly, no editor round-trip:
46
+
47
+ | Action | What it does |
48
+ |--------|--------------|
49
+ | Model: Switch Model | Open a model selector overlay; switch instantly |
50
+ | Session: Compact | Compact the conversation right away |
51
+ | Editor: Copy Content | Copy current editor text to the clipboard |
52
+ | Editor: Clear Content | Clear the editor, saving the current text to the restore buffer |
53
+ | Restore: Previous Editor Text | Bring back text saved before the last command _(appears only when available)_ |
54
+
55
+ **Fill the editor** — they insert the matching `/command` for you to submit, just like any extension command:
56
+
57
+ | Action | Inserts |
58
+ |--------|---------|
59
+ | Session: New | `/new` |
60
+ | Session: Reload | `/reload` |
61
+ | Session: Fork | `/fork` |
62
+ | Session: Tree | `/tree` |
63
+ | Session: Resume | `/resume` |
64
+
65
+ > Pi ships with more built-in slash commands (e.g. `/export`, `/share`, `/name`, `/settings`). This palette only surfaces a curated subset above — for the rest, type them directly into the editor.
66
+
41
67
  ### Editor text preservation
42
68
 
43
- When a command replaces your current editor text, the original content is saved and a **Restore: Previous Editor Text** entry appears at the top of the palette. Select it to get your text back.
69
+ When a command replaces your editor text, or you run **Editor: Clear Content**, the original content is saved and a **Restore: Previous Editor Text** entry appears at the top of the palette. Select it to get your text back.
44
70
 
45
71
  ### Model selector
46
72
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d3ara1n/pi-command-palette",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "description": "Global command palette for pi — press Ctrl+Shift+P to search and run commands from anywhere",
6
6
  "main": "src/index.ts",
package/src/index.ts CHANGED
@@ -10,10 +10,12 @@
10
10
  * - Fuzzy search via SelectList
11
11
  * - Floating overlay on top of existing content
12
12
  * - Saves editor text before overwriting; offers "Restore" in palette
13
+ * - Clear editor into the restore buffer
13
14
  */
14
15
 
15
16
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
16
17
  import {
18
+ copyToClipboard,
17
19
  DynamicBorder,
18
20
  getAgentDir,
19
21
  resolveModelScopeWithDiagnostics,
@@ -37,7 +39,9 @@ type CommandAction =
37
39
  | { type: "model-select" }
38
40
  | { type: "compact" }
39
41
  | { type: "reload" }
40
- | { type: "restore" };
42
+ | { type: "restore" }
43
+ | { type: "copy-editor" }
44
+ | { type: "clear-editor" };
41
45
 
42
46
  interface PaletteItem {
43
47
  value: string;
@@ -52,6 +56,18 @@ interface PaletteItem {
52
56
  /** Editor text saved before the palette overwrites it. */
53
57
  let savedEditorText: string | null = null;
54
58
 
59
+ /**
60
+ * Explicit display order for built-in palette entries (lower = higher up).
61
+ * Unlisted built-ins fall back to alphabetical, after the listed ones;
62
+ * non-built-in entries always sort after built-ins.
63
+ */
64
+ const BUILTIN_ORDER: Record<string, number> = {
65
+ __model_select: 0,
66
+ __restore: 1,
67
+ __copy_editor: 2,
68
+ __clear_editor: 3,
69
+ };
70
+
55
71
  // ── Helpers ────────────────────────────────────────────────────────
56
72
 
57
73
  function buildPaletteItems(pi: ExtensionAPI, ctx: ExtensionContext): PaletteItem[] {
@@ -127,6 +143,22 @@ function buildPaletteItems(pi: ExtensionAPI, ctx: ExtensionContext): PaletteItem
127
143
  action: { type: "editor", text: "/resume" },
128
144
  });
129
145
 
146
+ items.push({
147
+ value: "__copy_editor",
148
+ label: "Editor: Copy Content",
149
+ description: "Copy current editor text to clipboard",
150
+ category: "Built-in",
151
+ action: { type: "copy-editor" },
152
+ });
153
+
154
+ items.push({
155
+ value: "__clear_editor",
156
+ label: "Editor: Clear Content",
157
+ description: "Clear editor (recover via Restore)",
158
+ category: "Built-in",
159
+ action: { type: "clear-editor" },
160
+ });
161
+
130
162
  // ── Extension commands, skills, templates ────────────────────
131
163
  const commands = pi.getCommands();
132
164
  for (const cmd of commands) {
@@ -143,10 +175,17 @@ function buildPaletteItems(pi: ExtensionAPI, ctx: ExtensionContext): PaletteItem
143
175
  });
144
176
  }
145
177
 
146
- // Sort: built-in first, then alphabetically within category
178
+ // Sort: built-in actions first, ordered by BUILTIN_ORDER (then alphabetical
179
+ // for unlisted built-ins); extension commands follow alphabetically.
147
180
  items.sort((a, b) => {
148
- if (a.category === "Built-in" && b.category !== "Built-in") return -1;
149
- if (a.category !== "Built-in" && b.category === "Built-in") return 1;
181
+ const aBuilt = a.category === "Built-in";
182
+ const bBuilt = b.category === "Built-in";
183
+ if (aBuilt !== bBuilt) return aBuilt ? -1 : 1;
184
+ if (aBuilt) {
185
+ const ai = BUILTIN_ORDER[a.value] ?? Number.MAX_SAFE_INTEGER;
186
+ const bi = BUILTIN_ORDER[b.value] ?? Number.MAX_SAFE_INTEGER;
187
+ if (ai !== bi) return ai - bi;
188
+ }
150
189
  return a.label.localeCompare(b.label);
151
190
  });
152
191
 
@@ -454,6 +493,29 @@ async function showCommandPalette(pi: ExtensionAPI, ctx: ExtensionContext): Prom
454
493
  ctx.ui.setEditorText("/reload");
455
494
  break;
456
495
  }
496
+ case "copy-editor": {
497
+ const text = ctx.ui.getEditorText();
498
+ if (text && text.trim()) {
499
+ await copyToClipboard(text);
500
+ ctx.ui.notify("Copied editor text to clipboard", "info");
501
+ } else {
502
+ ctx.ui.notify("Editor is empty", "warning");
503
+ }
504
+ break;
505
+ }
506
+ case "clear-editor": {
507
+ // Save current editor text to the restore buffer before clearing, so
508
+ // the built-in Restore action can bring it back.
509
+ const currentText = ctx.ui.getEditorText();
510
+ if (currentText && currentText.trim()) {
511
+ savedEditorText = currentText;
512
+ ctx.ui.setEditorText("");
513
+ ctx.ui.notify("Cleared editor — use Restore to recover", "info");
514
+ } else {
515
+ ctx.ui.notify("Editor is empty", "warning");
516
+ }
517
+ break;
518
+ }
457
519
  }
458
520
  }
459
521