editprompt 1.4.0 → 1.5.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/dist/index.js +52 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import { promisify } from "node:util";
|
|
|
7
7
|
import Conf from "conf";
|
|
8
8
|
import clipboardy from "clipboardy";
|
|
9
9
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
10
|
+
import { randomBytes } from "node:crypto";
|
|
10
11
|
import { tmpdir } from "node:os";
|
|
11
12
|
import { join } from "node:path";
|
|
12
13
|
|
|
@@ -71,7 +72,44 @@ function setupLogger(options = {}) {
|
|
|
71
72
|
|
|
72
73
|
//#endregion
|
|
73
74
|
//#region package.json
|
|
74
|
-
var version = "1.
|
|
75
|
+
var version = "1.5.0";
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/config/constants.ts
|
|
79
|
+
const TEMP_FILE_PREFIX = ".editprompt-";
|
|
80
|
+
const TEMP_FILE_EXTENSION = ".md";
|
|
81
|
+
const DEFAULT_EDITOR = "vim";
|
|
82
|
+
const TMUX_IMSG_LIMIT_BYTES = 16 * 1024;
|
|
83
|
+
const TMUX_SEND_CHUNK_BYTES = TMUX_IMSG_LIMIT_BYTES / 2;
|
|
84
|
+
const WEZTERM_SEND_CHUNK_BYTES = TMUX_SEND_CHUNK_BYTES;
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/utils/contentChunker.ts
|
|
88
|
+
/**
|
|
89
|
+
* Split content into chunks not exceeding maxBytes (UTF-8 byte count),
|
|
90
|
+
* never breaking a Unicode code point across chunks.
|
|
91
|
+
*
|
|
92
|
+
* Content shorter than maxBytes is returned as a single chunk, so short
|
|
93
|
+
* input keeps the previous behavior of being sent in one shot.
|
|
94
|
+
*/
|
|
95
|
+
function splitByByteSize(content, maxBytes) {
|
|
96
|
+
if (content === "") return [];
|
|
97
|
+
const chunks = [];
|
|
98
|
+
let current = "";
|
|
99
|
+
let currentBytes = 0;
|
|
100
|
+
for (const char of content) {
|
|
101
|
+
const charBytes = Buffer.byteLength(char, "utf8");
|
|
102
|
+
if (current !== "" && currentBytes + charBytes > maxBytes) {
|
|
103
|
+
chunks.push(current);
|
|
104
|
+
current = "";
|
|
105
|
+
currentBytes = 0;
|
|
106
|
+
}
|
|
107
|
+
current += char;
|
|
108
|
+
currentBytes += charBytes;
|
|
109
|
+
}
|
|
110
|
+
if (current !== "") chunks.push(current);
|
|
111
|
+
return chunks;
|
|
112
|
+
}
|
|
75
113
|
|
|
76
114
|
//#endregion
|
|
77
115
|
//#region src/modules/tmux.ts
|
|
@@ -156,8 +194,12 @@ async function sendKeyToTmuxPane(paneId, key, delay = 1e3) {
|
|
|
156
194
|
}
|
|
157
195
|
async function inputToTmuxPane(paneId, content) {
|
|
158
196
|
await execAsync$1(`tmux if-shell -t '${paneId}' '[ "#{pane_in_mode}" = "1" ]' "copy-mode -q -t '${paneId}'"`);
|
|
159
|
-
|
|
160
|
-
|
|
197
|
+
const chunks = splitByByteSize(content, TMUX_SEND_CHUNK_BYTES);
|
|
198
|
+
for (const chunk of chunks) await execAsync$1(`tmux send-keys -t '${paneId}' -- '${chunk.replace(/'/g, "'\\''")}'`);
|
|
199
|
+
logger$11.debug("Content sent to tmux pane: {paneId} ({chunks} chunk(s))", {
|
|
200
|
+
paneId,
|
|
201
|
+
chunks: chunks.length
|
|
202
|
+
});
|
|
161
203
|
}
|
|
162
204
|
|
|
163
205
|
//#endregion
|
|
@@ -289,8 +331,12 @@ async function sendKeyToWeztermPane(paneId, key, delay = 1e3) {
|
|
|
289
331
|
await execAsync(`wezterm cli send-text --no-paste --pane-id '${paneId}' $'${key}'`);
|
|
290
332
|
}
|
|
291
333
|
async function inputToWeztermPane(paneId, content) {
|
|
292
|
-
|
|
293
|
-
|
|
334
|
+
const chunks = splitByByteSize(content, WEZTERM_SEND_CHUNK_BYTES);
|
|
335
|
+
for (const chunk of chunks) await execAsync(`wezterm cli send-text --no-paste --pane-id '${paneId}' -- '${chunk.replace(/'/g, "'\\''")}'`);
|
|
336
|
+
logger$10.debug("Content sent to wezterm pane: {paneId} ({chunks} chunk(s))", {
|
|
337
|
+
paneId,
|
|
338
|
+
chunks: chunks.length
|
|
339
|
+
});
|
|
294
340
|
}
|
|
295
341
|
|
|
296
342
|
//#endregion
|
|
@@ -855,12 +901,6 @@ const inputCommand = define({
|
|
|
855
901
|
}
|
|
856
902
|
});
|
|
857
903
|
|
|
858
|
-
//#endregion
|
|
859
|
-
//#region src/config/constants.ts
|
|
860
|
-
const TEMP_FILE_PREFIX = ".editprompt-";
|
|
861
|
-
const TEMP_FILE_EXTENSION = ".md";
|
|
862
|
-
const DEFAULT_EDITOR = "vim";
|
|
863
|
-
|
|
864
904
|
//#endregion
|
|
865
905
|
//#region src/utils/envParser.ts
|
|
866
906
|
/**
|
|
@@ -888,7 +928,7 @@ function getFormattedDateTime() {
|
|
|
888
928
|
async function createTempFile() {
|
|
889
929
|
const tempDir = join(tmpdir(), "editprompt-prompts");
|
|
890
930
|
await mkdir(tempDir, { recursive: true });
|
|
891
|
-
const filePath = join(tempDir, `${TEMP_FILE_PREFIX}${getFormattedDateTime()}${TEMP_FILE_EXTENSION}`);
|
|
931
|
+
const filePath = join(tempDir, `${TEMP_FILE_PREFIX}${getFormattedDateTime()}-${randomBytes(4).toString("hex")}${TEMP_FILE_EXTENSION}`);
|
|
892
932
|
await writeFile(filePath, "", "utf-8");
|
|
893
933
|
return filePath;
|
|
894
934
|
}
|