@nicknisi/pi-stash 0.1.1 → 0.1.2

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.
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Message Stash Extension
3
+ *
4
+ * Replicates Claude Code's ctrl+s message stash: press ctrl+s to stash
5
+ * whatever you've typed in the input box, do something else, then press
6
+ * ctrl+s again (with an empty input) to restore it.
7
+ *
8
+ * - ctrl+s with text in the editor → pushes it onto a stack and clears
9
+ * - ctrl+s with an empty editor → pops the most recent stash back
10
+ * - sending another message → auto-restores the most recent stash
11
+ *
12
+ * A widget above the editor shows how many messages are stashed with a
13
+ * one-line preview of the most recent one.
14
+ */
15
+ import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
16
+ export default function stash(pi: ExtensionAPI): void;
package/dist/index.js ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Message Stash Extension
3
+ *
4
+ * Replicates Claude Code's ctrl+s message stash: press ctrl+s to stash
5
+ * whatever you've typed in the input box, do something else, then press
6
+ * ctrl+s again (with an empty input) to restore it.
7
+ *
8
+ * - ctrl+s with text in the editor → pushes it onto a stack and clears
9
+ * - ctrl+s with an empty editor → pops the most recent stash back
10
+ * - sending another message → auto-restores the most recent stash
11
+ *
12
+ * A widget above the editor shows how many messages are stashed with a
13
+ * one-line preview of the most recent one.
14
+ */
15
+ const WIDGET_KEY = 'message-stash';
16
+ export default function stash(pi) {
17
+ const stack = [];
18
+ const updateWidget = (ctx) => {
19
+ if (!ctx.hasUI)
20
+ return;
21
+ if (stack.length === 0) {
22
+ ctx.ui.setWidget(WIDGET_KEY, undefined);
23
+ return;
24
+ }
25
+ const theme = ctx.ui.theme;
26
+ const latest = stack[stack.length - 1];
27
+ const firstLine = latest.split('\n')[0] ?? '';
28
+ const preview = firstLine.length > 60 ? `${firstLine.slice(0, 60)}…` : firstLine;
29
+ const count = stack.length > 1 ? theme.fg('dim', ` (+${stack.length - 1} more)`) : '';
30
+ ctx.ui.setWidget(WIDGET_KEY, [
31
+ `${theme.fg('accent', '⧉ stashed:')} ${theme.fg('muted', preview)}${count} ${theme.fg('dim', '· ctrl+s to restore')}`,
32
+ ]);
33
+ };
34
+ pi.registerShortcut('ctrl+s', {
35
+ description: 'Stash / restore the typed message',
36
+ handler: async (ctx) => {
37
+ if (!ctx.hasUI)
38
+ return;
39
+ const text = ctx.ui.getEditorText();
40
+ if (text.trim().length > 0) {
41
+ stack.push(text);
42
+ ctx.ui.setEditorText('');
43
+ }
44
+ else if (stack.length > 0) {
45
+ ctx.ui.setEditorText(stack.pop());
46
+ }
47
+ updateWidget(ctx);
48
+ },
49
+ });
50
+ // After a message is submitted, auto-restore the most recent stash into
51
+ // the now-empty editor (mirrors Claude Code's behavior).
52
+ pi.on('before_agent_start', async (_event, ctx) => {
53
+ if (!ctx.hasUI || stack.length === 0)
54
+ return;
55
+ if (ctx.ui.getEditorText().trim().length > 0)
56
+ return;
57
+ ctx.ui.setEditorText(stack.pop());
58
+ updateWidget(ctx);
59
+ });
60
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nicknisi/pi-stash",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Stash and restore the current prompt draft",
5
5
  "keywords": [
6
6
  "pi",
@@ -15,11 +15,15 @@
15
15
  "directory": "packages/stash"
16
16
  },
17
17
  "files": [
18
+ "dist",
18
19
  "index.ts"
19
20
  ],
20
21
  "type": "module",
21
22
  "exports": {
22
- ".": "./index.ts"
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
26
+ }
23
27
  },
24
28
  "peerDependencies": {
25
29
  "@earendil-works/pi-coding-agent": "*"