editprompt 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 eetann
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,152 @@
1
+ # editprompt
2
+
3
+ A CLI tool that lets you write prompts for CLI tools using your favorite text editor. Originally designed for [Claude Code](https://docs.anthropic.com/en/docs/claude-code/overview), but works with any CLI process.
4
+
5
+ ## Features
6
+
7
+ - 🖊️ **Editor Integration**: Use your preferred text editor to write prompts
8
+ - 🔍 **Process Detection**: Automatically detects running CLI processes (configurable)
9
+ - 🖥️ **Tmux Support**: Send prompts directly to tmux sessions
10
+ - 📋 **Clipboard Fallback**: Automatically copies to clipboard if sending fails
11
+ - ⚡ **Smart Fallbacks**: Multiple fallback strategies ensure your prompt gets delivered
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ # Install globally via npm
17
+ npm install -g editprompt
18
+
19
+ # Or use with npx
20
+ npx editprompt
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ### Basic Usage
26
+
27
+ ```bash
28
+ # Use with your default editor (from $EDITOR)
29
+ editprompt
30
+
31
+ # Specify a different editor
32
+ editprompt --editor nvim
33
+ editprompt -e nvim
34
+
35
+ # Target a different process (default: claude)
36
+ editprompt --process foobar
37
+ editprompt -p foobar
38
+
39
+ # Show help
40
+ editprompt --help
41
+
42
+ # Show version
43
+ editprompt --version
44
+ ```
45
+
46
+ It is useful to configure tmux as follows.
47
+
48
+ ```tmux
49
+ bind -n M-q split-window -v -l 10 \
50
+ -c '#{pane_current_path}' \
51
+ 'editprompt --editor nvim'
52
+ ```
53
+
54
+ If you prefer popup, you can configure it as follows.
55
+ ```tmux
56
+ bind -n M-q display-popup -E \
57
+ -d '#{pane_current_path}' \
58
+ 'editprompt --editor nvim'
59
+ ```
60
+
61
+ ### How it Works
62
+
63
+ 1. **Opens your editor** with a temporary markdown file
64
+ 2. **Write your prompt** and save/exit the editor
65
+ 3. **Detects target processes** running on your system (default: claude)
66
+ 4. **Sends the prompt** using the best available method:
67
+ - 🎯 **Tmux sessions**: Direct input via `tmux send-keys`
68
+ - 📋 **Clipboard**: Copies content as final fallback
69
+
70
+ ### Process Selection
71
+
72
+ When multiple processes are detected, you'll see an interactive selection menu:
73
+
74
+ ```
75
+ ? Select a process:
76
+ 1. PID: 12345 | Tmux: main:0.1 | Directory: /home/user/project1
77
+ 2. PID: 67890 | Directory: /home/user/project2
78
+ ```
79
+
80
+ The display shows:
81
+ - **PID**: Process ID
82
+ - **Tmux**: Session, window, and pane (if running in tmux)
83
+ - **Directory**: Working directory of the process
84
+
85
+ ## Configuration
86
+
87
+ ### Editor Selection
88
+
89
+ editprompt respects the following editor priority:
90
+
91
+ 1. `--editor/-e` command line option
92
+ 2. `$EDITOR` environment variable
93
+ 3. Default: `vi`
94
+
95
+ ### Environment Variables
96
+
97
+ - `EDITOR`: Your preferred text editor
98
+
99
+ ## Requirements
100
+
101
+ - Node.js 18+ or Bun
102
+ - Target CLI process (default: `claude` command)
103
+ - Optional: tmux (for direct session integration)
104
+
105
+ ## Development
106
+
107
+ ```bash
108
+ # Clone the repository
109
+ git clone https://github.com/eetann/editprompt.git
110
+ cd editprompt
111
+
112
+ # Install dependencies
113
+ bun install
114
+
115
+ # Build
116
+ bun run build
117
+
118
+ # Run tests
119
+ bun test
120
+
121
+ # Development mode
122
+ bun run dev
123
+ ```
124
+
125
+ ### Project Structure
126
+
127
+ ```
128
+ src/
129
+ ├── config/
130
+ │ └── constants.ts # Configuration constants
131
+ ├── modules/
132
+ │ ├── editor.ts # Editor launching and file handling
133
+ │ ├── process.ts # Process detection and communication
134
+ │ └── selector.ts # Interactive process selection
135
+ ├── utils/
136
+ │ └── tempFile.ts # Temporary file management
137
+ └── index.ts # CLI entry point
138
+ ```
139
+
140
+ ## Technical Details
141
+
142
+ ### Tmux Integration
143
+
144
+ When the target process is running in a tmux session, editprompt uses `tmux send-keys` to send input directly to the appropriate pane. This provides seamless integration without disrupting your existing session.
145
+
146
+ ### Fallback Strategy
147
+
148
+ editprompt implements fallback strategy:
149
+
150
+ 1. **Tmux Integration**: Direct input to tmux panes (when available)
151
+ <!-- 2. **New Process**: Launch new Claude instance with piped input -->
152
+ 2. **Clipboard**: Copy content to clipboard with error notification
@@ -0,0 +1 @@
1
+ export { };
package/dist/index.js ADDED
@@ -0,0 +1,253 @@
1
+ #!/usr/bin/env node
2
+ import { cli } from "gunshi";
3
+ import { exec, spawn } from "node:child_process";
4
+ import { mkdtemp, readFile, readlink, writeFile } from "node:fs/promises";
5
+ import { tmpdir } from "node:os";
6
+ import { join } from "node:path";
7
+ import { promisify } from "node:util";
8
+ import clipboardy from "clipboardy";
9
+ import find from "find-process";
10
+ import inquirer from "inquirer";
11
+
12
+ //#region src/config/constants.ts
13
+ const TEMP_FILE_PREFIX = ".editprompt-";
14
+ const TEMP_FILE_EXTENSION = ".md";
15
+ const DEFAULT_EDITOR = "vim";
16
+ const DEFAULT_PROCESS_NAME = "claude";
17
+
18
+ //#endregion
19
+ //#region src/utils/tempFile.ts
20
+ function getFormattedDateTime() {
21
+ const now = /* @__PURE__ */ new Date();
22
+ const year = now.getFullYear();
23
+ const month = String(now.getMonth() + 1).padStart(2, "0");
24
+ const day = String(now.getDate()).padStart(2, "0");
25
+ const hours = String(now.getHours()).padStart(2, "0");
26
+ const minutes = String(now.getMinutes()).padStart(2, "0");
27
+ const seconds = String(now.getSeconds()).padStart(2, "0");
28
+ return `${year}${month}${day}${hours}${minutes}${seconds}`;
29
+ }
30
+ async function createTempFile() {
31
+ const tempDir = await mkdtemp(join(tmpdir(), "editprompt-"));
32
+ const fileName = `${TEMP_FILE_PREFIX}${getFormattedDateTime()}${TEMP_FILE_EXTENSION}`;
33
+ const filePath = join(tempDir, fileName);
34
+ await writeFile(filePath, "", "utf-8");
35
+ return filePath;
36
+ }
37
+
38
+ //#endregion
39
+ //#region src/modules/editor.ts
40
+ function getEditor(editorOption) {
41
+ return editorOption || process.env.EDITOR || DEFAULT_EDITOR;
42
+ }
43
+ async function launchEditor(editor, filePath) {
44
+ return new Promise((resolve, reject) => {
45
+ const editorProcess = spawn(editor, [filePath], {
46
+ stdio: "inherit",
47
+ shell: true
48
+ });
49
+ editorProcess.on("error", (error) => {
50
+ reject(new Error(`Failed to launch editor: ${error.message}`));
51
+ });
52
+ editorProcess.on("exit", (code) => {
53
+ if (code === 0) resolve();
54
+ else reject(new Error(`Editor exited with code: ${code}`));
55
+ });
56
+ });
57
+ }
58
+ async function readFileContent(filePath) {
59
+ try {
60
+ const content = await readFile(filePath, "utf-8");
61
+ return content.trim();
62
+ } catch (error) {
63
+ throw new Error(`Failed to read file: ${error instanceof Error ? error.message : "Unknown error"}`);
64
+ }
65
+ }
66
+ async function openEditorAndGetContent(editorOption) {
67
+ const tempFilePath = await createTempFile();
68
+ const editor = getEditor(editorOption);
69
+ try {
70
+ await launchEditor(editor, tempFilePath);
71
+ const content = await readFileContent(tempFilePath);
72
+ if (!content) throw new Error("No content was entered in the editor");
73
+ return content;
74
+ } catch (error) {
75
+ if (error instanceof Error) throw error;
76
+ throw new Error("An unknown error occurred");
77
+ }
78
+ }
79
+
80
+ //#endregion
81
+ //#region src/modules/process.ts
82
+ const execAsync = promisify(exec);
83
+ async function getProcessCwd(pid) {
84
+ try {
85
+ const cwdPath = join("/proc", pid.toString(), "cwd");
86
+ const cwd = await readlink(cwdPath);
87
+ return cwd;
88
+ } catch (error) {
89
+ return void 0;
90
+ }
91
+ }
92
+ async function findTargetProcesses(processName = DEFAULT_PROCESS_NAME) {
93
+ const tmuxAvailable = await checkTmuxAvailable();
94
+ if (tmuxAvailable) {
95
+ const tmuxProcesses = await findTargetInTmux(processName);
96
+ if (tmuxProcesses.length > 0) return Promise.all(tmuxProcesses.map(async (proc) => {
97
+ const cwd = await getProcessCwd(proc.pid);
98
+ return {
99
+ ...proc,
100
+ cwd
101
+ };
102
+ }));
103
+ }
104
+ const processes = await find("name", processName);
105
+ const targetProcesses = await Promise.all(processes.map(async (proc) => {
106
+ const cwd = await getProcessCwd(proc.pid);
107
+ return {
108
+ pid: proc.pid,
109
+ name: proc.name,
110
+ cmd: proc.cmd,
111
+ cwd
112
+ };
113
+ }));
114
+ return targetProcesses.filter((p) => p.name === processName);
115
+ }
116
+ async function checkTmuxAvailable() {
117
+ try {
118
+ await execAsync("tmux list-sessions");
119
+ return true;
120
+ } catch {
121
+ return false;
122
+ }
123
+ }
124
+ async function getTmuxPanes() {
125
+ try {
126
+ const { stdout } = await execAsync("tmux list-panes -a -F '#{session_name}:#{window_index}.#{pane_index}:#{pane_pid}:#{pane_current_command}'");
127
+ return stdout.trim().split("\n").map((line) => {
128
+ const [session, windowPane, pid, command] = line.split(":");
129
+ const [window, pane] = windowPane.split(".");
130
+ return {
131
+ session,
132
+ window,
133
+ pane,
134
+ pid: Number.parseInt(pid, 10),
135
+ command
136
+ };
137
+ });
138
+ } catch {
139
+ return [];
140
+ }
141
+ }
142
+ async function findTargetInTmux(processName = DEFAULT_PROCESS_NAME) {
143
+ const processes = await find("name", processName);
144
+ const targetProcesses = processes.filter((p) => p.name === processName);
145
+ if (targetProcesses.length === 0) return [];
146
+ const tmuxPanes = await getTmuxPanes();
147
+ if (tmuxPanes.length === 0) return [];
148
+ const matchedProcesses = [];
149
+ for (const process$1 of targetProcesses) {
150
+ const matchingPane = tmuxPanes.find((pane) => pane.pid === process$1.ppid);
151
+ if (matchingPane) matchedProcesses.push({
152
+ pid: process$1.pid,
153
+ name: process$1.name,
154
+ cmd: process$1.cmd,
155
+ tmuxSession: matchingPane.session,
156
+ tmuxWindow: matchingPane.window,
157
+ tmuxPane: matchingPane.pane
158
+ });
159
+ }
160
+ return matchedProcesses;
161
+ }
162
+ async function sendToTmuxPane(session, window, pane, content) {
163
+ const target = `${session}:${window}.${pane}`;
164
+ await execAsync(`tmux send-keys -t '${target}' '${content.replace(/'/g, "'\\''")}'`);
165
+ }
166
+ async function copyToClipboard(content) {
167
+ await clipboardy.write(content);
168
+ }
169
+ async function sendContentToProcess(process$1, content) {
170
+ try {
171
+ if (process$1.tmuxSession && process$1.tmuxWindow && process$1.tmuxPane) {
172
+ await sendToTmuxPane(process$1.tmuxSession, process$1.tmuxWindow, process$1.tmuxPane, content);
173
+ return;
174
+ }
175
+ } catch (error) {
176
+ console.log(`Failed to send to process. Content copied to clipboard. Error: ${error instanceof Error ? error.message : "Unknown error"}`);
177
+ }
178
+ await copyToClipboard(content);
179
+ console.log("Copy!");
180
+ }
181
+
182
+ //#endregion
183
+ //#region src/modules/selector.ts
184
+ function formatProcessChoice(proc, index) {
185
+ const parts = [`PID: ${proc.pid}`];
186
+ if (proc.tmuxSession) parts.push(`Tmux: ${proc.tmuxSession}:${proc.tmuxWindow}.${proc.tmuxPane}`);
187
+ if (proc.cwd) parts.push(`Directory: ${proc.cwd}`);
188
+ return {
189
+ name: `${index + 1}. ${parts.join(" | ")}`,
190
+ value: proc
191
+ };
192
+ }
193
+ async function selectProcess(processes) {
194
+ if (processes.length === 0) throw new Error("No processes to select from");
195
+ if (processes.length === 1) return processes[0];
196
+ const choices = processes.map((proc, index) => formatProcessChoice(proc, index));
197
+ const { selectedProcess } = await inquirer.prompt([{
198
+ type: "list",
199
+ name: "selectedProcess",
200
+ message: "Select a process:",
201
+ choices
202
+ }]);
203
+ return selectedProcess;
204
+ }
205
+
206
+ //#endregion
207
+ //#region src/index.ts
208
+ const argv = process.argv.slice(2);
209
+ await cli(argv, {
210
+ name: "editprompt",
211
+ description: "A CLI tool that lets you write prompts for Claude Code using your favorite text editor",
212
+ args: {
213
+ editor: {
214
+ short: "e",
215
+ description: "Editor to use (overrides $EDITOR)",
216
+ type: "string"
217
+ },
218
+ process: {
219
+ short: "p",
220
+ description: "Process name to target (default: claude)",
221
+ type: "string"
222
+ }
223
+ },
224
+ async run(ctx) {
225
+ try {
226
+ console.log("Opening editor...");
227
+ const content = await openEditorAndGetContent(ctx.values.editor);
228
+ if (!content) {
229
+ console.log("No content entered. Exiting.");
230
+ return;
231
+ }
232
+ const processName = ctx.values.process || DEFAULT_PROCESS_NAME;
233
+ console.log(`Searching for ${processName} processes...`);
234
+ const processes = await findTargetProcesses(processName);
235
+ if (processes.length === 0) console.log(`No ${processName} process found.`);
236
+ else {
237
+ const selectedProcess = await selectProcess(processes);
238
+ const processInfo = [`PID ${selectedProcess.pid}`];
239
+ if (selectedProcess.tmuxSession) processInfo.push(`Tmux: ${selectedProcess.tmuxSession}:${selectedProcess.tmuxWindow}.${selectedProcess.tmuxPane}`);
240
+ if (selectedProcess.cwd) processInfo.push(`Directory: ${selectedProcess.cwd}`);
241
+ console.log(`Selected process: ${processInfo.join(" | ")}`);
242
+ console.log(`Sending content to ${processName} process...`);
243
+ await sendContentToProcess(selectedProcess, content);
244
+ console.log("Content sent successfully!");
245
+ }
246
+ } catch (error) {
247
+ console.error(`Error: ${error instanceof Error ? error.message : "Unknown error"}`);
248
+ process.exit(1);
249
+ }
250
+ }
251
+ }, { version: "0.0.1" });
252
+
253
+ //#endregion
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "editprompt",
3
+ "version": "0.0.1",
4
+ "author": "eetann",
5
+ "description": "A CLI tool that lets you write prompts for CLI tools using your favorite text editor",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/eetann/editprompt.git"
10
+ },
11
+ "homepage": "https://github.com/eetann/editprompt",
12
+ "bugs": {
13
+ "url": "https://github.com/eetann/editprompt/issues"
14
+ },
15
+ "keywords": [
16
+ "cli",
17
+ "editor",
18
+ "prompt",
19
+ "tmux",
20
+ "clipboard",
21
+ "command-line",
22
+ "text-editor"
23
+ ],
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "type": "module",
28
+ "files": ["dist"],
29
+ "main": "./dist/index.js",
30
+ "module": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "exports": {
33
+ ".": "./dist/index.js",
34
+ "./package.json": "./package.json"
35
+ },
36
+ "bin": {
37
+ "editprompt": "./dist/index.js"
38
+ },
39
+ "scripts": {
40
+ "build": "tsdown",
41
+ "dev": "tsdown --watch",
42
+ "test": "bun test",
43
+ "test:watch": "bun test --watch"
44
+ },
45
+ "devDependencies": {
46
+ "@biomejs/biome": "1.9.4",
47
+ "@types/bun": "^1.2.16",
48
+ "@types/find-process": "^1.2.2",
49
+ "@types/inquirer": "^9.0.8",
50
+ "@types/node": "^24.0.1",
51
+ "tsdown": "latest"
52
+ },
53
+ "packageManager": "pnpm@10.8.1+sha512.c50088ba998c67b8ca8c99df8a5e02fd2ae2e2b29aaf238feaa9e124248d3f48f9fb6db2424949ff901cffbb5e0f0cc1ad6aedb602cd29450751d11c35023677",
54
+ "dependencies": {
55
+ "clipboardy": "^4.0.0",
56
+ "find-process": "^1.4.10",
57
+ "gunshi": "^0.26.3",
58
+ "inquirer": "^12.6.3"
59
+ }
60
+ }