pi-prompt-restore 0.1.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.
- package/CHANGELOG.md +11 -0
- package/LICENSE +9 -0
- package/README.md +82 -0
- package/index.ts +53 -0
- package/package.json +47 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0.0 — 2026-06-27
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Initial release
|
|
7
|
+
- **Ctrl+C save** — saves the current editor text before the built-in clear action runs
|
|
8
|
+
- **Up arrow restore** — when the editor is empty and a saved prompt exists, restores it immediately; subsequent Up presses go through normal history
|
|
9
|
+
- Each Ctrl+C overwrites the previous save so you always recover the most recently cleared prompt
|
|
10
|
+
- Copy (Ctrl+C with a selection) still works normally
|
|
11
|
+
- TUI-mode guard — does not activate in print, JSON, or RPC modes
|
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cullen Botha
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# Pi Prompt Restore
|
|
4
|
+
|
|
5
|
+
_Accidentally hit Ctrl+C instead of Ctrl+V? Get your prompt back with Up arrow._
|
|
6
|
+
|
|
7
|
+
[How It Works](#how-it-works) • [Installation](#installation) • [Usage](#usage)
|
|
8
|
+
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
Saves your in-progress prompt whenever Ctrl+C clears the editor, so a mistyped
|
|
12
|
+
paste shortcut doesn't cost you five minutes of careful prompt-crafting. Press
|
|
13
|
+
**Up arrow** to recover it — press Up again for normal history.
|
|
14
|
+
|
|
15
|
+
## How It Works
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
User types a prompt in the editor
|
|
19
|
+
│
|
|
20
|
+
▼
|
|
21
|
+
Ctrl+C pressed ──────────────────────────┐
|
|
22
|
+
│ │
|
|
23
|
+
▼ ▼
|
|
24
|
+
index.ts handleInput Built-in clear
|
|
25
|
+
(intercepts "ctrl+c") fires and wipes
|
|
26
|
+
│ the editor
|
|
27
|
+
▼
|
|
28
|
+
savedPrompt = this.getText()
|
|
29
|
+
│
|
|
30
|
+
▼
|
|
31
|
+
User presses Up (editor empty) ────► savedPrompt restored
|
|
32
|
+
│ savedPrompt cleared
|
|
33
|
+
▼
|
|
34
|
+
User presses Up again ─────────────► normal history recall
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
| Key | Without extension | With Prompt Saver |
|
|
38
|
+
| ------------------------ | ------------------------------------------------ | ------------------------------------------------------------------- |
|
|
39
|
+
| **Ctrl+C** | Clears the editor. Text is gone forever. | Text is saved silently, then the editor clears as usual. |
|
|
40
|
+
| **Up** (editor empty) | Recalls the last submitted message from history. | Restores the saved prompt first. Press Up again for normal history. |
|
|
41
|
+
| **Up** (editor has text) | Moves cursor up. | Moves cursor up (unchanged). |
|
|
42
|
+
|
|
43
|
+
- Each Ctrl+C overwrites the previous save — you always recover the **most recently** cleared prompt.
|
|
44
|
+
- Copy (Ctrl+C with a selection) still copies to the clipboard; the full text is also saved as a harmless side effect.
|
|
45
|
+
- The saved prompt is **not persisted** across sessions — it lives only until the next Ctrl+C or pi restart.
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
### Via npm
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
pi install npm:pi-prompt-restore
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Manual
|
|
56
|
+
|
|
57
|
+
Clone or copy into your pi extensions directory:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
cp -r pi-prompt-restore ~/.pi/agent/extensions/pi-prompt-restore
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Then run `/reload` in pi, or restart pi. The extension loads automatically from `~/.pi/agent/extensions/`.
|
|
64
|
+
|
|
65
|
+
## Usage
|
|
66
|
+
|
|
67
|
+
No commands, no configuration — just type.
|
|
68
|
+
|
|
69
|
+
1. Type a prompt.
|
|
70
|
+
2. Accidentally press **Ctrl+C** (editor clears).
|
|
71
|
+
3. Press **Up arrow** — your prompt is restored.
|
|
72
|
+
4. Press **Up arrow** again to browse normal history.
|
|
73
|
+
|
|
74
|
+
## Compatibility
|
|
75
|
+
|
|
76
|
+
- Works in interactive (**TUI**) mode only.
|
|
77
|
+
- Compatible with other extensions that don't replace the editor. If another
|
|
78
|
+
extension also calls `setEditorComponent`, the last one loaded wins.
|
|
79
|
+
|
|
80
|
+
## License
|
|
81
|
+
|
|
82
|
+
MIT
|
package/index.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Saver Extension
|
|
3
|
+
*
|
|
4
|
+
* Saves the current editor text when Ctrl+C clears the input,
|
|
5
|
+
* so accidentally discarded prompts can be retrieved with the up arrow.
|
|
6
|
+
*
|
|
7
|
+
* - Ctrl+C: saves the current text before clearing the editor
|
|
8
|
+
* - Up arrow: if editor is empty and a saved prompt exists, restores it
|
|
9
|
+
* - Subsequent up arrow presses go through normal history as usual
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { CustomEditor, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
13
|
+
import { matchesKey, Key } from "@earendil-works/pi-tui";
|
|
14
|
+
|
|
15
|
+
// Module-level state: the most recently cleared prompt
|
|
16
|
+
let savedPrompt: string | null = null;
|
|
17
|
+
|
|
18
|
+
class PromptSaverEditor extends CustomEditor {
|
|
19
|
+
handleInput(data: string): void {
|
|
20
|
+
// Intercept Ctrl+C: save the current text before it gets cleared
|
|
21
|
+
if (matchesKey(data, Key.ctrl("c"))) {
|
|
22
|
+
const text = this.getText();
|
|
23
|
+
if (text) {
|
|
24
|
+
savedPrompt = text;
|
|
25
|
+
}
|
|
26
|
+
// Let the default handler clear the editor (or copy if there's a selection)
|
|
27
|
+
super.handleInput(data);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Intercept Up arrow: restore saved prompt if editor is empty
|
|
32
|
+
if (matchesKey(data, Key.up)) {
|
|
33
|
+
if (!this.getText() && savedPrompt) {
|
|
34
|
+
this.setText(savedPrompt);
|
|
35
|
+
savedPrompt = null;
|
|
36
|
+
return; // Don't pass to super — we handled it
|
|
37
|
+
}
|
|
38
|
+
// Editor has text or no saved prompt: normal up behavior (cursor up / history)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Pass everything else to the default editor behavior
|
|
42
|
+
super.handleInput(data);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default function (pi: ExtensionAPI) {
|
|
47
|
+
pi.on("session_start", (_event, ctx) => {
|
|
48
|
+
// Only install in TUI mode (not print/json/rpc)
|
|
49
|
+
if (ctx.mode !== "tui") return;
|
|
50
|
+
|
|
51
|
+
ctx.ui.setEditorComponent((tui, theme, kb) => new PromptSaverEditor(tui, theme, kb));
|
|
52
|
+
});
|
|
53
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pi-prompt-restore",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Pi extension that saves discarded prompts when Ctrl+C clears the editor - recover with the Up arrow",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"pi-package",
|
|
7
|
+
"pi-extension",
|
|
8
|
+
"prompt",
|
|
9
|
+
"input",
|
|
10
|
+
"editor",
|
|
11
|
+
"recovery",
|
|
12
|
+
"undo",
|
|
13
|
+
"history",
|
|
14
|
+
"pi",
|
|
15
|
+
"coding-agent",
|
|
16
|
+
"tui"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Cullen Botha <mail@cullen.dev>",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"files": [
|
|
22
|
+
"index.ts",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"CHANGELOG.md"
|
|
26
|
+
],
|
|
27
|
+
"pi": {
|
|
28
|
+
"extensions": [
|
|
29
|
+
"./index.ts"
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/cullendotdev/pi-prompt-restore.git"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/cullendotdev/pi-prompt-restore#readme",
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/cullendotdev/pi-prompt-restore/issues"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
42
|
+
"@earendil-works/pi-tui": "*"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=22"
|
|
46
|
+
}
|
|
47
|
+
}
|