mocode-ai 1.8.2 → 1.8.3
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/repl/running-input.js +40 -3
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ import { stdin } from 'node:process';
|
|
|
3
3
|
import * as layout from '../ui/layout.js';
|
|
4
4
|
import * as mouse from '../ui/mouse.js';
|
|
5
5
|
import { promptComposer } from '../ui/composer.js';
|
|
6
|
+
import { ensurePasteDetector, pasteState } from '../ui/prompt-internal/paste.js';
|
|
6
7
|
import { appendCurrentSessionRuntimeEvent } from '../session/index.js';
|
|
7
8
|
import { getAgentMode } from '../agent/mode.js';
|
|
8
9
|
const emitter = stdin;
|
|
@@ -16,6 +17,8 @@ let listening = false; // onRunningKey 是否处于挂载期(start → stop 之
|
|
|
16
17
|
let queuedTurns = [];
|
|
17
18
|
/** 运行态打开的输入面板(Ctrl+G);非 null = 面板仍开着。主循环进 INPUT 态前须等它关闭,否则两个 keypress 监听抢键。 */
|
|
18
19
|
let composerPending = null;
|
|
20
|
+
/** 粘贴多行时 \r\n 合一:刚吃了 \r,尾随的 \n 需吞掉(与 INPUT 态编辑器一致)。 */
|
|
21
|
+
let pasteJustSawCR = false;
|
|
19
22
|
/** 获取运行中输入缓冲(agent 结束后预填下一轮 INPUT 态)。 */
|
|
20
23
|
export function getRunningInput() {
|
|
21
24
|
return runningInput;
|
|
@@ -64,6 +67,12 @@ export function waitForRunningComposer() {
|
|
|
64
67
|
function paint() {
|
|
65
68
|
layout.paintRunningInput(runningInput.replace(/[\r\n]/g, ' '), runningCursor, runningPlaceholder);
|
|
66
69
|
}
|
|
70
|
+
/** 在光标处插入文本(打字/粘贴),推进光标并重绘;换行保留在缓冲里(回显折空格),作为同一条内容。 */
|
|
71
|
+
function insertRunningText(text) {
|
|
72
|
+
runningInput = runningInput.slice(0, runningCursor) + text + runningInput.slice(runningCursor);
|
|
73
|
+
runningCursor += text.length;
|
|
74
|
+
paint();
|
|
75
|
+
}
|
|
67
76
|
/**
|
|
68
77
|
* Ctrl+G(运行态):打开输入面板编辑 typeahead 缓冲。
|
|
69
78
|
* 期间摘掉 onRunningKey(面板自己挂 keypress),并标记 overlay——流式输出 / 状态行心跳 / spinner 帧只喂缓冲
|
|
@@ -145,6 +154,27 @@ function onRunningKey(_str, key) {
|
|
|
145
154
|
}
|
|
146
155
|
return;
|
|
147
156
|
}
|
|
157
|
+
// 粘贴中(块级/时间窗检测,与 INPUT 态编辑器共用 pasteState):整段累积进 typeahead 缓冲,
|
|
158
|
+
// 换行作为多行文本插入而非触发 Enter 入队——否则粘贴一段含上百行的日志会被拆成上百条排队消息。
|
|
159
|
+
// \r\n 合一成单个 \n(尾随 \n 吞掉);可打印字符在光标处插入。粘贴结束(50ms 静默)后用户按 Enter 才整条入队。
|
|
160
|
+
if (pasteState.pasting) {
|
|
161
|
+
const s = key.sequence ?? '';
|
|
162
|
+
const isReturn = key.name === 'return' || key.name === 'enter';
|
|
163
|
+
if (s === '\n' && pasteJustSawCR) {
|
|
164
|
+
pasteJustSawCR = false;
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (isReturn || s === '\r' || s === '\n') {
|
|
168
|
+
pasteJustSawCR = s === '\r';
|
|
169
|
+
insertRunningText('\n');
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
pasteJustSawCR = false;
|
|
173
|
+
if (s && s >= ' ' && s !== '\uFEFF' && !key.ctrl && !key.meta)
|
|
174
|
+
insertRunningText(s);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
pasteJustSawCR = false;
|
|
148
178
|
// Ctrl+G:打开输入面板(与 INPUT 态一致;确认只填回 typeahead 缓冲,agent 结束后预填,不发送)
|
|
149
179
|
if (key.ctrl && key.name === 'g') {
|
|
150
180
|
if (!composerPending) {
|
|
@@ -222,9 +252,7 @@ function onRunningKey(_str, key) {
|
|
|
222
252
|
}
|
|
223
253
|
// 可打印字符(>= 空格,非 ctrl/meta)→ 光标处插入 + 非 dim 回显(与空闲态一致)
|
|
224
254
|
if (s && s >= ' ' && !key.ctrl && !key.meta) {
|
|
225
|
-
|
|
226
|
-
runningCursor += s.length;
|
|
227
|
-
paint();
|
|
255
|
+
insertRunningText(s);
|
|
228
256
|
}
|
|
229
257
|
}
|
|
230
258
|
/** 鼠标右键单击输入框(未拖动)时 layout 读剪贴板后回调:在光标处插入 typeahead 缓冲(单行,换行折为空格)。 */
|
|
@@ -239,6 +267,15 @@ export function startRunningListener(placeholder) {
|
|
|
239
267
|
runningPlaceholder = placeholder;
|
|
240
268
|
runningInput = '';
|
|
241
269
|
runningCursor = 0;
|
|
270
|
+
pasteJustSawCR = false;
|
|
271
|
+
// 粘贴检测(块级/时间窗)是 INPUT 态编辑器同款、全局幂等:运行态也装上,使多行/大段粘贴
|
|
272
|
+
// 在 onRunningKey 的 pasting 分支整段进 typeahead,而不是被换行拆成多条排队消息。
|
|
273
|
+
ensurePasteDetector();
|
|
274
|
+
if (pasteState.pasteTimer)
|
|
275
|
+
clearTimeout(pasteState.pasteTimer);
|
|
276
|
+
pasteState.pasting = false;
|
|
277
|
+
pasteState.pasteParts = [];
|
|
278
|
+
pasteState.onPasteEnd = null; // 运行态直接实时累积进 runningInput,不用编辑器的落 chip 回调
|
|
242
279
|
emitKeypressEvents(stdin); // 幂等:首轮 prompt 已永久挂解析器,这里防御性再调
|
|
243
280
|
try {
|
|
244
281
|
stdin.setRawMode(true);
|