@ryan_nookpi/pi-extension-clipboard 0.1.0 → 0.1.1
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/README.md +15 -5
- package/index.ts +51 -49
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
# @ryan_nookpi/pi-extension-clipboard
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This extension lets pi copy generated text directly to your system clipboard.
|
|
4
|
+
|
|
5
|
+
It is especially handy for reply drafts, commit messages, PR descriptions, SQL queries, and other text you want to paste right away.
|
|
4
6
|
|
|
5
7
|
## Install
|
|
6
8
|
|
|
7
9
|
```bash
|
|
8
|
-
pi install /Users/creatrip/Documents/pi-extension/packages/clipboard
|
|
9
10
|
pi install npm:@ryan_nookpi/pi-extension-clipboard
|
|
10
11
|
```
|
|
11
12
|
|
|
12
|
-
##
|
|
13
|
+
## Great for
|
|
14
|
+
|
|
15
|
+
- "Write a reply draft and put it in my clipboard"
|
|
16
|
+
- copying long outputs without selecting them manually
|
|
17
|
+
- using clipboard copy from terminal or SSH-based workflows
|
|
18
|
+
|
|
19
|
+
## Example prompts
|
|
20
|
+
|
|
21
|
+
- "Draft a Slack reply and copy it to my clipboard."
|
|
22
|
+
- "Put this SQL query in my clipboard."
|
|
23
|
+
- "Write a PR description and copy it for me."
|
|
13
24
|
|
|
14
|
-
|
|
15
|
-
- `./index.ts` entry
|
|
25
|
+
After installation, pi can use the `copy_to_clipboard` tool to copy results instantly.
|
package/index.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* Ask the LLM: "write me a draft reply and put it into clipboard!"
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import type
|
|
12
|
+
import { defineTool, type ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
13
13
|
import { Type } from "@sinclair/typebox";
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -36,59 +36,61 @@ function copyToClipboard(text: string): void {
|
|
|
36
36
|
process.stdout.write(osc52);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
description: "The text to copy to the clipboard",
|
|
50
|
-
}),
|
|
39
|
+
const copyToClipboardTool = defineTool({
|
|
40
|
+
name: "copy_to_clipboard",
|
|
41
|
+
label: "Copy to Clipboard",
|
|
42
|
+
description:
|
|
43
|
+
"Copy text to the user's system clipboard. Use this when the user asks you to " +
|
|
44
|
+
"put something in their clipboard, write a draft reply to clipboard, or copy any " +
|
|
45
|
+
"generated text for easy pasting. The text will be available for pasting immediately.",
|
|
46
|
+
parameters: Type.Object({
|
|
47
|
+
text: Type.String({
|
|
48
|
+
description: "The text to copy to the clipboard",
|
|
51
49
|
}),
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
}),
|
|
51
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
52
|
+
const { text } = params;
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
if (!text || text.trim().length === 0) {
|
|
55
|
+
return {
|
|
56
|
+
content: [{ type: "text", text: "Error: No text provided to copy." }],
|
|
57
|
+
details: { success: false, error: "empty_text" },
|
|
58
|
+
};
|
|
59
|
+
}
|
|
61
60
|
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
try {
|
|
62
|
+
copyToClipboard(text);
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
const preview = text.length > 100 ? `${text.slice(0, 100)}...` : text;
|
|
65
|
+
const charCount = text.length;
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
if (ctx.hasUI) {
|
|
68
|
+
ctx.ui.notify(`Copied ${charCount} characters to clipboard`, "info");
|
|
69
|
+
}
|
|
71
70
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
details: {
|
|
80
|
-
success: true,
|
|
81
|
-
characterCount: charCount,
|
|
82
|
-
preview,
|
|
71
|
+
return {
|
|
72
|
+
content: [
|
|
73
|
+
{
|
|
74
|
+
type: "text",
|
|
75
|
+
text: `Successfully copied ${charCount} characters to clipboard.\n\nPreview:\n${preview}`,
|
|
83
76
|
},
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
77
|
+
],
|
|
78
|
+
details: {
|
|
79
|
+
success: true,
|
|
80
|
+
characterCount: charCount,
|
|
81
|
+
preview,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
} catch (error) {
|
|
85
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
86
|
+
return {
|
|
87
|
+
content: [{ type: "text", text: `Failed to copy to clipboard: ${errorMessage}` }],
|
|
88
|
+
details: { success: false, error: errorMessage },
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
export default function clipboardExtension(pi: ExtensionAPI): void {
|
|
95
|
+
pi.registerTool(copyToClipboardTool);
|
|
94
96
|
}
|