@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.
Files changed (3) hide show
  1. package/README.md +15 -5
  2. package/index.ts +51 -49
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,15 +1,25 @@
1
1
  # @ryan_nookpi/pi-extension-clipboard
2
2
 
3
- Clipboard copy tool for pi using OSC52 escape sequences.
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
- ## What it provides
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
- - `copy_to_clipboard` tool
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 { ExtensionAPI } from "@mariozechner/pi-coding-agent";
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
- export default function clipboardExtension(pi: ExtensionAPI): void {
40
- pi.registerTool({
41
- name: "copy_to_clipboard",
42
- label: "Copy to Clipboard",
43
- description:
44
- "Copy text to the user's system clipboard. Use this when the user asks you to " +
45
- "put something in their clipboard, write a draft reply to clipboard, or copy any " +
46
- "generated text for easy pasting. The text will be available for pasting immediately.",
47
- parameters: Type.Object({
48
- text: Type.String({
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
- async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
53
- const { text } = params as { text: string };
50
+ }),
51
+ async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
52
+ const { text } = params;
54
53
 
55
- if (!text || text.trim().length === 0) {
56
- return {
57
- content: [{ type: "text", text: "Error: No text provided to copy." }],
58
- details: { success: false, error: "empty_text" },
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
- try {
63
- copyToClipboard(text);
61
+ try {
62
+ copyToClipboard(text);
64
63
 
65
- const preview = text.length > 100 ? `${text.slice(0, 100)}...` : text;
66
- const charCount = text.length;
64
+ const preview = text.length > 100 ? `${text.slice(0, 100)}...` : text;
65
+ const charCount = text.length;
67
66
 
68
- if (ctx.hasUI) {
69
- ctx.ui.notify(`Copied ${charCount} characters to clipboard`, "info");
70
- }
67
+ if (ctx.hasUI) {
68
+ ctx.ui.notify(`Copied ${charCount} characters to clipboard`, "info");
69
+ }
71
70
 
72
- return {
73
- content: [
74
- {
75
- type: "text",
76
- text: `Successfully copied ${charCount} characters to clipboard.\n\nPreview:\n${preview}`,
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
- } catch (error) {
86
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
87
- return {
88
- content: [{ type: "text", text: `Failed to copy to clipboard: ${errorMessage}` }],
89
- details: { success: false, error: errorMessage },
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryan_nookpi/pi-extension-clipboard",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Clipboard copy tool extension for pi using OSC52 escape sequences.",
5
5
  "type": "module",
6
6
  "keywords": [