pi-abort-recall 1.0.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/LICENSE +21 -0
- package/README.md +36 -0
- package/index.ts +27 -0
- package/package.json +22 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ouzhenkun
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# pi-abort-recall
|
|
2
|
+
|
|
3
|
+
**Recall your last prompt back to the editor after aborting — so you can edit and retry without retyping.**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/pi-abort-recall)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## Why
|
|
9
|
+
|
|
10
|
+
When you press Escape to abort an AI response, your original message disappears from the editor. If you wanted to tweak the wording and retry, you have to retype it from scratch.
|
|
11
|
+
|
|
12
|
+
This extension puts it back automatically.
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pi install npm:pi-abort-recall
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Requires Pi v0.37.0+.
|
|
21
|
+
|
|
22
|
+
## How It Works
|
|
23
|
+
|
|
24
|
+
1. Captures the text content of each user message as it's sent
|
|
25
|
+
2. When an assistant response ends with `stopReason: "aborted"`, restores the last user message back to the editor via `ctx.ui.setEditorText`
|
|
26
|
+
|
|
27
|
+
That's it. No config, no dependencies.
|
|
28
|
+
|
|
29
|
+
## Limitations
|
|
30
|
+
|
|
31
|
+
- Only restores the most recent user message — earlier messages in a multi-turn conversation are not recoverable.
|
|
32
|
+
- Image or file attachments in the original message are not restored, only text content.
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
MIT
|
package/index.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi-abort-recall
|
|
3
|
+
*
|
|
4
|
+
* When a request is aborted (Esc), restores the last sent user message back to the editor.
|
|
5
|
+
*/
|
|
6
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
|
|
8
|
+
export default function (pi: ExtensionAPI) {
|
|
9
|
+
let lastUserMessage = "";
|
|
10
|
+
|
|
11
|
+
pi.on("message_end", async (event, ctx) => {
|
|
12
|
+
if (event.message.role === "user") {
|
|
13
|
+
const text = event.message.content
|
|
14
|
+
.filter((b: any) => b.type === "text")
|
|
15
|
+
.map((b: any) => b.text)
|
|
16
|
+
.join("");
|
|
17
|
+
if (text.trim()) lastUserMessage = text;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (event.message.role === "assistant" && (event.message as any).stopReason === "aborted") {
|
|
22
|
+
if (lastUserMessage) {
|
|
23
|
+
ctx.ui.setEditorText(lastUserMessage);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pi-abort-recall",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Recall your last prompt back to the editor after aborting (Esc)",
|
|
5
|
+
"keywords": ["pi-package"],
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "ouzhenkun",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/ouzhenkun/pi-abort-recall.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/ouzhenkun/pi-abort-recall",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/ouzhenkun/pi-abort-recall/issues"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
18
|
+
},
|
|
19
|
+
"pi": {
|
|
20
|
+
"extensions": ["./index.ts"]
|
|
21
|
+
}
|
|
22
|
+
}
|