@kevinweber/pi-copy-prompt 0.0.0-stage → 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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -2
  3. package/package.json +29 -4
  4. package/src/index.ts +148 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kevin Weber
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 CHANGED
@@ -1,3 +1,34 @@
1
- # Temporary Holding Version
1
+ # @kevinweber/pi-copy-prompt
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Copy your current Pi draft to the clipboard with **⌘Y** on macOS (`super+y`). Collapsed pasted text is copied in full, and the editor briefly shows `prompt copied`.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pi install npm:@kevinweber/pi-copy-prompt@1.0.0
9
+ ```
10
+
11
+ ## Behavior
12
+
13
+ - Copies draft text without submitting it, preserving whitespace and expanding collapsed pastes.
14
+ - Does not copy system instructions, conversation history or attachments.
15
+ - Leaves the clipboard unchanged when the draft is empty or whitespace-only.
16
+ - Reports clipboard errors.
17
+
18
+ ## Compatibility and privacy
19
+
20
+ Requires Node.js >=22.19.0 and Pi with custom-editor and expanded-paste support.
21
+
22
+ Your terminal must support the Super/Command modifier, typically through the Kitty keyboard protocol, and pass the shortcut through to Pi. `ctrl+y` keeps its usual yank behavior.
23
+
24
+ Do not combine this package with another custom-editor extension or a local copy of this extension. Pi supports only one custom editor at a time.
25
+
26
+ Remote clipboard copying requires terminal support for OSC 52; the confirmation cannot guarantee that the terminal accepted it. Copied text may be saved in clipboard history or synced to other devices.
27
+
28
+ ## Contributing
29
+
30
+ See [CONTRIBUTING.md](https://github.com/kevinweber/pi-copy-prompt/blob/main/CONTRIBUTING.md) for development checks.
31
+
32
+ ## License
33
+
34
+ MIT © Kevin Weber
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
1
  {
2
2
  "name": "@kevinweber/pi-copy-prompt",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Copy the full expanded Pi editor draft to the clipboard with super+y",
5
+ "keywords": ["pi-package", "pi", "pi-extension", "pi-coding-agent", "clipboard", "copy-prompt", "editor"],
6
+ "author": "Kevin Weber",
7
+ "license": "MIT",
8
+ "type": "module",
9
+ "engines": { "node": ">=22.19.0" },
10
+ "files": ["src/index.ts", "README.md", "LICENSE"],
11
+ "repository": { "type": "git", "url": "git+https://github.com/kevinweber/pi-copy-prompt.git" },
12
+ "homepage": "https://github.com/kevinweber/pi-copy-prompt#readme",
13
+ "bugs": { "url": "https://github.com/kevinweber/pi-copy-prompt/issues" },
14
+ "pi": { "extensions": ["./src/index.ts"] },
15
+ "peerDependencies": {
16
+ "@earendil-works/pi-coding-agent": "*",
17
+ "@earendil-works/pi-tui": "*"
18
+ },
19
+ "devDependencies": {
20
+ "@earendil-works/pi-coding-agent": "1.4.0",
21
+ "@earendil-works/pi-tui": "1.4.0",
22
+ "typescript": "^5.8.3"
23
+ },
24
+ "scripts": {
25
+ "check": "node --check src/index.ts",
26
+ "typecheck": "tsc --noEmit",
27
+ "test": "node --experimental-strip-types --test src/index.test.mjs",
28
+ "prepublishOnly": "npm run ci",
29
+ "ci": "npm run check && npm run typecheck && npm run test"
30
+ }
31
+ }
package/src/index.ts ADDED
@@ -0,0 +1,148 @@
1
+ /** Copy the expanded editor draft with super+y and show brief border feedback. */
2
+ import {
3
+ CustomEditor,
4
+ copyToClipboard,
5
+ type ExtensionAPI,
6
+ type KeybindingsManager,
7
+ type Theme,
8
+ } from "@earendil-works/pi-coding-agent";
9
+ import {
10
+ Key,
11
+ truncateToWidth,
12
+ visibleWidth,
13
+ type EditorTheme,
14
+ type TUI,
15
+ } from "@earendil-works/pi-tui";
16
+
17
+ export function fitBorder(
18
+ left: string,
19
+ right: string,
20
+ width: number,
21
+ border: (text: string) => string,
22
+ fill: (text: string) => string = border,
23
+ ): string {
24
+ if (width <= 0) return "";
25
+ if (width === 1) return border("─");
26
+
27
+ let leftText = left;
28
+ let rightText = right;
29
+ const fixedWidth = 2;
30
+ const minimumGap = 3;
31
+
32
+ while (
33
+ fixedWidth + visibleWidth(leftText) + visibleWidth(rightText) + minimumGap > width &&
34
+ visibleWidth(rightText) > 0
35
+ ) {
36
+ rightText = truncateToWidth(rightText, Math.max(0, visibleWidth(rightText) - 1), "");
37
+ }
38
+ while (
39
+ fixedWidth + visibleWidth(leftText) + visibleWidth(rightText) + minimumGap > width &&
40
+ visibleWidth(leftText) > 0
41
+ ) {
42
+ leftText = truncateToWidth(leftText, Math.max(0, visibleWidth(leftText) - 1), "");
43
+ }
44
+
45
+ const gapWidth = Math.max(0, width - fixedWidth - visibleWidth(leftText) - visibleWidth(rightText));
46
+ return `${border("─")}${leftText}${fill("─".repeat(gapWidth))}${rightText}${border("─")}`;
47
+ }
48
+
49
+ class CopyPromptEditor extends CustomEditor {
50
+ private readonly _tui: TUI;
51
+ private readonly _getTheme: () => Theme;
52
+ private _copied = false;
53
+ private _resetTimer: ReturnType<typeof setTimeout> | undefined;
54
+ disposed = false;
55
+
56
+ constructor(tui: TUI, theme: EditorTheme, keybindings: KeybindingsManager, getTheme: () => Theme) {
57
+ super(tui, theme, keybindings);
58
+ this._tui = tui;
59
+ this._getTheme = getTheme;
60
+ }
61
+
62
+ showCopied(): void {
63
+ if (this.disposed) return;
64
+ this._copied = true;
65
+ if (this._resetTimer !== undefined) clearTimeout(this._resetTimer);
66
+ this._resetTimer = setTimeout(() => {
67
+ this._resetTimer = undefined;
68
+ this._copied = false;
69
+ this._tui.requestRender();
70
+ }, 2000);
71
+ this._tui.requestRender();
72
+ }
73
+
74
+ clearCopied(): void {
75
+ if (this._resetTimer !== undefined) {
76
+ clearTimeout(this._resetTimer);
77
+ this._resetTimer = undefined;
78
+ }
79
+ if (!this._copied) return;
80
+ this._copied = false;
81
+ if (!this.disposed) this._tui.requestRender();
82
+ }
83
+
84
+ dispose(): void {
85
+ if (this.disposed) return;
86
+ this.disposed = true;
87
+ this.clearCopied();
88
+ }
89
+
90
+ protected renderBottomBorder(width: number): string {
91
+ const theme = this._getTheme();
92
+ const label = this._copied
93
+ ? theme.fg("accent", " prompt copied ")
94
+ : theme.fg("muted", " ⌘Y (copy prompt) ");
95
+ return fitBorder("", label, width, (text) => this.borderColor(text));
96
+ }
97
+
98
+ handleInput(data: string): void { super.handleInput(data); this.clearCopied(); }
99
+ setText(text: string): void { super.setText(text); this.clearCopied(); }
100
+ insertTextAtCursor(text: string): void { super.insertTextAtCursor(text); this.clearCopied(); }
101
+ }
102
+
103
+ export default function (pi: ExtensionAPI) {
104
+ let editorRef: CopyPromptEditor | undefined;
105
+
106
+ pi.on("session_start", (_event, ctx) => {
107
+ editorRef?.dispose();
108
+ editorRef = undefined;
109
+ if (ctx.mode !== "tui") return;
110
+
111
+ ctx.ui.setEditorComponent((tui, theme, keybindings) => {
112
+ editorRef?.dispose();
113
+ const editor = new CopyPromptEditor(tui, theme, keybindings, () => ctx.ui.theme);
114
+ editorRef = editor;
115
+ return editor;
116
+ });
117
+ });
118
+
119
+ pi.on("session_shutdown", () => {
120
+ editorRef?.dispose();
121
+ editorRef = undefined;
122
+ });
123
+
124
+ pi.registerShortcut(Key.super("y"), {
125
+ description: "Copy current prompt to clipboard",
126
+ handler: async (ctx) => {
127
+ if (ctx.mode !== "tui") return;
128
+ const editor = editorRef;
129
+ if (!editor || editor.disposed) return;
130
+ const text = editor.getExpandedText();
131
+ editor.clearCopied();
132
+ if (!text.trim()) {
133
+ ctx.ui.notify("Nothing to copy — editor is empty", "info");
134
+ return;
135
+ }
136
+ try {
137
+ await copyToClipboard(text);
138
+ } catch {
139
+ if (editorRef === editor && !editor.disposed) {
140
+ ctx.ui.notify("Could not copy prompt to clipboard", "error");
141
+ }
142
+ return;
143
+ }
144
+ // A clipboard operation can finish after shutdown or editor/session replacement.
145
+ if (editorRef === editor && !editor.disposed) editor.showCopied();
146
+ },
147
+ });
148
+ }