mocode-ai 1.8.10 → 1.9.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/attachments/clipboard.js +22 -0
- package/dist/attachments/image.js +63 -0
- package/dist/i18n/index.js +16 -2
- package/dist/repl/commands/image.js +30 -17
- package/dist/repl/commands.js +1 -0
- package/dist/repl/message-format.js +18 -0
- package/dist/repl/runtime.js +69 -2
- package/dist/ui/clipboard.js +97 -0
- package/dist/ui/layout-internal/core.js +1 -1
- package/dist/ui/layout-internal/input-paint.js +7 -5
- package/dist/ui/layout-internal/state.js +8 -0
- package/dist/ui/layout-internal/statusbar.js +22 -1
- package/dist/ui/prompt-internal/editor.js +39 -0
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 剪贴板截图 → 待发附件的共享通道(Ctrl+Y 快捷键与 /image clip 命令共用)。
|
|
3
|
+
*
|
|
4
|
+
* 这里只负责"系统剪贴板字节 → ImageAttachment(含 4MiB 上限 / PNG 降采样)";
|
|
5
|
+
* 入队去重、视觉能力警告、上屏反馈由调用方各自处理。
|
|
6
|
+
*/
|
|
7
|
+
import { config } from '../config/index.js';
|
|
8
|
+
import { readClipboardImage } from '../ui/clipboard.js';
|
|
9
|
+
import { buildImageAttachmentFromBuffer, MAX_INLINE_BYTES_DEFAULT } from './image.js';
|
|
10
|
+
export async function readClipboardAsAttachment() {
|
|
11
|
+
const buf = await readClipboardImage();
|
|
12
|
+
if (!buf)
|
|
13
|
+
return { ok: false, empty: true };
|
|
14
|
+
const ts = new Date().toISOString().replace(/[:.]/g, '-');
|
|
15
|
+
const name = `clipboard-${ts}.png`;
|
|
16
|
+
const r = buildImageAttachmentFromBuffer(buf, `clipboard:${ts}`, name, {
|
|
17
|
+
maxBytes: config.maxImageBytes ?? MAX_INLINE_BYTES_DEFAULT,
|
|
18
|
+
});
|
|
19
|
+
if (!r.ok)
|
|
20
|
+
return { ok: false, reason: r.reason };
|
|
21
|
+
return { ok: true, att: r.att, downscaledFrom: r.downscaledFrom };
|
|
22
|
+
}
|
|
@@ -134,6 +134,7 @@ async function downscalePngFile(abs, maxBytes, failPrefix, budgetBytes) {
|
|
|
134
134
|
bytes: buf.length,
|
|
135
135
|
mime: 'image/png',
|
|
136
136
|
dataUrl: `data:image/png;base64,${buf.toString('base64')}`,
|
|
137
|
+
downscaledFrom: { width: png.width, height: png.height },
|
|
137
138
|
},
|
|
138
139
|
};
|
|
139
140
|
}
|
|
@@ -174,6 +175,68 @@ export async function loadImageAttachmentWithDownscale(input, opts) {
|
|
|
174
175
|
}
|
|
175
176
|
return downscalePngFile(abs, opts.maxBytes, loaded.reason, opts.budgetBytes ?? INLINE_PNG_BUDGET_BYTES);
|
|
176
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* 从内存字节构造附件(剪贴板截图通道:PNG 由系统 API 直接给出,无落盘路径)。
|
|
180
|
+
*
|
|
181
|
+
* 与 loadImageAttachmentWithDownscale 同口径:魔数嗅探类型、4 MiB 硬上限、超软预算/超限
|
|
182
|
+
* 的 PNG 走同一套手写解码降采样(零原生依赖),JPEG/WebP/GIF 超限拒绝。`name` 仅用于
|
|
183
|
+
* chip 展示与去重,`source` 写进 path(发送时只读 dataUrl,path 不被打开)。
|
|
184
|
+
*/
|
|
185
|
+
export function buildImageAttachmentFromBuffer(buf, source, name, opts) {
|
|
186
|
+
const mime = sniffImageMime(buf);
|
|
187
|
+
if (!mime)
|
|
188
|
+
return { ok: false, reason: 'unsupported: 剪贴板内容不是可识别的图片(png/jpg/gif/webp)' };
|
|
189
|
+
const budget = opts.budgetBytes ?? INLINE_PNG_BUDGET_BYTES;
|
|
190
|
+
let out = buf;
|
|
191
|
+
let downscaledFrom;
|
|
192
|
+
if (mime === 'image/png' && (out.length > opts.maxBytes || out.length > budget)) {
|
|
193
|
+
try {
|
|
194
|
+
const png = decodePng(buf);
|
|
195
|
+
let img = downscale(png, DOWNSCALE_MAX_EDGE).img;
|
|
196
|
+
let encoded = encodePng(img);
|
|
197
|
+
for (const edge of DOWNSCALE_FALLBACK_EDGES) {
|
|
198
|
+
if (encoded.length <= budget || edge >= Math.max(img.width, img.height))
|
|
199
|
+
continue;
|
|
200
|
+
img = downscale(png, edge).img;
|
|
201
|
+
encoded = encodePng(img);
|
|
202
|
+
}
|
|
203
|
+
if (encoded.length <= opts.maxBytes && encoded.length < out.length) {
|
|
204
|
+
downscaledFrom = { width: png.width, height: png.height };
|
|
205
|
+
out = encoded;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
210
|
+
// 8-bit RGB/RGBA 之外的 PNG(如 16-bit/调色板)手写解码不支持:降采样失败时
|
|
211
|
+
// 不致命——未超硬上限就原样发,超了走下面的 too large 拒绝。
|
|
212
|
+
if (buf.length > opts.maxBytes) {
|
|
213
|
+
return {
|
|
214
|
+
ok: false,
|
|
215
|
+
reason: `too large: ${formatBytes(buf.length)} (max ${formatBytes(opts.maxBytes)});降采样失败: ${message}`,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if (out.length > opts.maxBytes) {
|
|
221
|
+
return { ok: false, reason: `too large: ${formatBytes(out.length)} (max ${formatBytes(opts.maxBytes)})` };
|
|
222
|
+
}
|
|
223
|
+
// id 只哈希内容(不含 source/name):同一张剪贴板截图连抓两次时间戳不同但字节相同,
|
|
224
|
+
// 去重仍能命中(pendingAttachments 按 id 判重)。
|
|
225
|
+
const id = createHash('sha1').update(out).digest('hex');
|
|
226
|
+
return {
|
|
227
|
+
ok: true,
|
|
228
|
+
att: {
|
|
229
|
+
id,
|
|
230
|
+
path: source,
|
|
231
|
+
name,
|
|
232
|
+
bytes: out.length,
|
|
233
|
+
mime,
|
|
234
|
+
dataUrl: `data:${mime};base64,${out.toString('base64')}`,
|
|
235
|
+
...(downscaledFrom ? { downscaledFrom } : {}),
|
|
236
|
+
},
|
|
237
|
+
...(downscaledFrom ? { downscaledFrom } : {}),
|
|
238
|
+
};
|
|
239
|
+
}
|
|
177
240
|
export async function loadImageAttachment(input, opts) {
|
|
178
241
|
const trimmed = input.trim();
|
|
179
242
|
if (!trimmed)
|
package/dist/i18n/index.js
CHANGED
|
@@ -142,7 +142,14 @@ const zhCN = {
|
|
|
142
142
|
'prompt.revertFiles': '撤销文件改动{detail}',
|
|
143
143
|
'prompt.revertDetail': '({count} 个文件恢复到回滚前)',
|
|
144
144
|
'prompt.messagesOnly': '只撤销消息,保留文件改动',
|
|
145
|
-
'prompt.emptyPlaceholder': '输入需求,按 Enter
|
|
145
|
+
'prompt.emptyPlaceholder': '输入需求,按 Enter 开始干活;Ctrl+G 打开输入面板,Ctrl+Y 粘贴剪贴板截图',
|
|
146
|
+
'prompt.imageEmpty': '剪贴板里没有图片(先截图或复制图片,再按 Ctrl+Y)',
|
|
147
|
+
'prompt.imageFailed': '[image] 剪贴板抓图失败: {reason}',
|
|
148
|
+
'prompt.imageDownscaled': '⚠ 原图 {width}×{height} 超过内联上限,已降采样后附加(剪贴板原图未保存)',
|
|
149
|
+
'prompt.imageDownscaledFile': '⚠ 原图 {width}×{height} 超过内联上限,已降采样后附加(磁盘原图不变)',
|
|
150
|
+
'prompt.imageDownscaledBadge': '↓{width}×{height}',
|
|
151
|
+
'prompt.imageVisionWarningShort': '⚠ {model} 不支持视觉',
|
|
152
|
+
'commands.imageClip': '从剪贴板抓截图附加',
|
|
146
153
|
'prompt.confirmSendHint': '再按一次 Enter 发送 · 其它键继续编辑',
|
|
147
154
|
'composer.title': '输入面板',
|
|
148
155
|
'composer.pos': '{row}/{total} 行 · {col} 列 · {chars} 字',
|
|
@@ -596,7 +603,14 @@ const en = {
|
|
|
596
603
|
'prompt.revertFiles': 'Revert file changes{detail}',
|
|
597
604
|
'prompt.revertDetail': ' ({count} files restored to before the rollback)',
|
|
598
605
|
'prompt.messagesOnly': 'Roll back messages only; keep file changes',
|
|
599
|
-
'prompt.emptyPlaceholder': 'Type what you need, press Enter to get started;
|
|
606
|
+
'prompt.emptyPlaceholder': 'Type what you need, press Enter to get started; Ctrl+G opens the composer, Ctrl+Y pastes a screenshot from the clipboard',
|
|
607
|
+
'prompt.imageEmpty': 'No image in clipboard (screenshot or copy an image first, then press Ctrl+Y)',
|
|
608
|
+
'prompt.imageFailed': '[image] clipboard capture failed: {reason}',
|
|
609
|
+
'prompt.imageDownscaled': '⚠ Source {width}×{height} exceeds the inline limit; downscaled copy attached (clipboard image not saved)',
|
|
610
|
+
'prompt.imageDownscaledFile': '⚠ Source {width}×{height} exceeds the inline limit; downscaled copy attached (original file unchanged)',
|
|
611
|
+
'prompt.imageDownscaledBadge': '↓{width}×{height}',
|
|
612
|
+
'prompt.imageVisionWarningShort': '⚠ {model} has no vision',
|
|
613
|
+
'commands.imageClip': 'Attach a screenshot from the clipboard',
|
|
600
614
|
'prompt.confirmSendHint': 'Press Enter again to send · any other key keeps editing',
|
|
601
615
|
'composer.title': 'Composer',
|
|
602
616
|
'composer.pos': '{row}/{total} lines · col {col} · {chars} chars',
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 图片附件命令组:/image · /image list · /image clear · /image <path>
|
|
2
|
+
* 图片附件命令组:/image · /image list · /image clear · /image clip · /image <path>
|
|
3
3
|
*
|
|
4
4
|
* 单 handler 内部按完整 line 分流,顺序与原 if 链一致:
|
|
5
|
-
* 先 list/clear(完整匹配),再落到 <path> 分支。
|
|
5
|
+
* 先 list/clear/clip(完整匹配),再落到 <path> 分支。
|
|
6
6
|
*
|
|
7
7
|
* dispatch 阶段**不调 runTurn**:仅 mutate ctx.attachments 状态,
|
|
8
8
|
* 提交时(runTurn 入口)才 flush 进 history。
|
|
@@ -10,13 +10,18 @@
|
|
|
10
10
|
import * as layout from '../../ui/layout.js';
|
|
11
11
|
import { ui } from '../../ui/theme.js';
|
|
12
12
|
import { config } from '../../config/index.js';
|
|
13
|
+
import { t } from '../../i18n/index.js';
|
|
13
14
|
import { loadImageAttachmentWithDownscale, renderChip, MAX_INLINE_BYTES_DEFAULT } from '../../attachments/image.js';
|
|
14
|
-
import {
|
|
15
|
+
import { readClipboardAsAttachment } from '../../attachments/clipboard.js';
|
|
15
16
|
import { unhandled, next } from './types.js';
|
|
16
17
|
export const imageCommands = [
|
|
17
18
|
async (ctx) => {
|
|
18
19
|
const { line } = ctx;
|
|
19
|
-
const isImage = line === '/image' ||
|
|
20
|
+
const isImage = line === '/image' ||
|
|
21
|
+
line === '/image list' ||
|
|
22
|
+
line === '/image clear' ||
|
|
23
|
+
line === '/image clip' ||
|
|
24
|
+
line.startsWith('/image ');
|
|
20
25
|
if (!isImage)
|
|
21
26
|
return unhandled();
|
|
22
27
|
const pending = ctx.attachments.list();
|
|
@@ -43,12 +48,30 @@ export const imageCommands = [
|
|
|
43
48
|
}
|
|
44
49
|
return next();
|
|
45
50
|
}
|
|
51
|
+
// /image clip:从系统剪贴板抓截图(Ctrl+Y 快捷键的命令形态,供终端吞键时兜底)。
|
|
52
|
+
// 成功只更新脚栏(push 钩子已同步 chip/降采样 badge/视觉预警),不写内容缓冲——
|
|
53
|
+
// 否则确认行会游离在 banner 与气泡之间,提交后又在气泡下重复一次。
|
|
54
|
+
if (line === '/image clip') {
|
|
55
|
+
const r = await readClipboardAsAttachment();
|
|
56
|
+
if (!r.ok) {
|
|
57
|
+
if ('empty' in r) {
|
|
58
|
+
layout.contentWrite(` ${ui.yellow}${t('prompt.imageEmpty')}${ui.reset}\n`);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
layout.contentWrite(`${ui.red}[image] ${r.reason}${ui.reset}\n`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (!ctx.attachments.list().some((a) => a.id === r.att.id)) {
|
|
65
|
+
ctx.attachments.push(r.att);
|
|
66
|
+
}
|
|
67
|
+
return next();
|
|
68
|
+
}
|
|
46
69
|
const arg = line
|
|
47
70
|
.slice('/image'.length)
|
|
48
71
|
.trim()
|
|
49
72
|
.replace(/^["']|["']$/g, '');
|
|
50
73
|
if (!arg) {
|
|
51
|
-
layout.contentWrite(`${ui.dim}用法: /image <path
|
|
74
|
+
layout.contentWrite(`${ui.dim}用法: /image <path>(或 /image clip 抓剪贴板截图)${ui.reset}\n`);
|
|
52
75
|
return next();
|
|
53
76
|
}
|
|
54
77
|
const maxBytes = config.maxImageBytes ?? MAX_INLINE_BYTES_DEFAULT;
|
|
@@ -57,20 +80,10 @@ export const imageCommands = [
|
|
|
57
80
|
layout.contentWrite(`${ui.red}[image] ${r.reason}${ui.reset}\n`);
|
|
58
81
|
return next();
|
|
59
82
|
}
|
|
60
|
-
|
|
83
|
+
// 成功只更新脚栏(push 钩子同步 chip/降采样 badge/视觉预警),不写内容缓冲。
|
|
84
|
+
if (!ctx.attachments.list().some((a) => a.id === r.att.id)) {
|
|
61
85
|
ctx.attachments.push(r.att);
|
|
62
86
|
}
|
|
63
|
-
// 用户粘/挂的高 DPI 截图超限时会被降采样:必须说出来,否则用户以为发的是原图,
|
|
64
|
-
// 之后模型「看不清小字」时无从归因。
|
|
65
|
-
if (r.downscaledFrom) {
|
|
66
|
-
layout.contentWrite(` ${ui.yellow}⚠ 原图 ${r.downscaledFrom.width}×${r.downscaledFrom.height} 超过内联上限,已降采样后附加(磁盘原图不变)。${ui.reset}\n`);
|
|
67
|
-
}
|
|
68
|
-
layout.contentWrite(` ${ui.dim}${renderChip(r.att)} — will attach to next message${ui.reset}\n`);
|
|
69
|
-
// 提前警告(不阻断附加):当前模型已知不支持视觉(如 MiniMax M2.x / gpt-3.5 等)时,
|
|
70
|
-
// 附加时就提示,而不是等发送后才在 catch 块里翻译 API 报错——减少一轮无意义请求。
|
|
71
|
-
if (!modelSupportsVision(config.model)) {
|
|
72
|
-
layout.contentWrite(` ${ui.yellow}⚠ 当前模型 ${config.model} 已知不支持视觉输入,发送图片可能会失败。可用 /model 切换。${ui.reset}\n`);
|
|
73
|
-
}
|
|
74
87
|
return next();
|
|
75
88
|
},
|
|
76
89
|
];
|
package/dist/repl/commands.js
CHANGED
|
@@ -154,6 +154,7 @@ export function buildSlashCommands() {
|
|
|
154
154
|
desc: d('commands.image'),
|
|
155
155
|
children: [
|
|
156
156
|
{ name: 'attach <path>', value: '/image ', submit: false, desc: d('commands.imageAttach') },
|
|
157
|
+
{ name: 'clip', value: '/image clip', desc: d('commands.imageClip') },
|
|
157
158
|
{ name: 'list', value: '/image list', desc: d('commands.imageList') },
|
|
158
159
|
{ name: 'clear', value: '/image clear', desc: d('commands.imageClear') },
|
|
159
160
|
],
|
|
@@ -187,18 +187,36 @@ export function renderHistory(history) {
|
|
|
187
187
|
if (atts && atts.length > 0) {
|
|
188
188
|
for (const a of atts) {
|
|
189
189
|
layout.contentWrite(` ${ui.dim}${renderChip(a)}${ui.reset}\n`);
|
|
190
|
+
if (a.downscaledFrom) {
|
|
191
|
+
const msg = a.path.startsWith('clipboard:')
|
|
192
|
+
? t('prompt.imageDownscaled', {
|
|
193
|
+
width: a.downscaledFrom.width,
|
|
194
|
+
height: a.downscaledFrom.height,
|
|
195
|
+
})
|
|
196
|
+
: t('prompt.imageDownscaledFile', {
|
|
197
|
+
width: a.downscaledFrom.width,
|
|
198
|
+
height: a.downscaledFrom.height,
|
|
199
|
+
});
|
|
200
|
+
layout.contentWrite(` ${ui.yellow}${msg}${ui.reset}\n`);
|
|
201
|
+
}
|
|
190
202
|
}
|
|
203
|
+
// 与实时 echoInput 同口径:附件区后补一个空行再进 agent 正文。
|
|
204
|
+
layout.contentWrite('\n');
|
|
191
205
|
}
|
|
192
206
|
else if (Array.isArray(m.content)) {
|
|
193
207
|
// 旧 session 没侧 channel:从 data URL 头抽 mime,显一个通用 chip
|
|
194
208
|
const c = m.content;
|
|
209
|
+
let fallbackChips = 0;
|
|
195
210
|
for (const p of c) {
|
|
196
211
|
if (p && typeof p === 'object' && p.type === 'image_url') {
|
|
197
212
|
const url = p.image_url?.url ?? '';
|
|
198
213
|
const mime = url.startsWith('data:') ? url.slice(5, url.indexOf(';')) : 'image';
|
|
199
214
|
layout.contentWrite(` ${ui.dim}📷 ${mime}${ui.reset}\n`);
|
|
215
|
+
fallbackChips++;
|
|
200
216
|
}
|
|
201
217
|
}
|
|
218
|
+
if (fallbackChips > 0)
|
|
219
|
+
layout.contentWrite('\n');
|
|
202
220
|
}
|
|
203
221
|
continue;
|
|
204
222
|
}
|
package/dist/repl/runtime.js
CHANGED
|
@@ -21,6 +21,8 @@ import '../tools/builtins/index.js';
|
|
|
21
21
|
import { initializeAllMcp, getMcpTools, closeAllMcp } from '../mcp/index.js';
|
|
22
22
|
import { refreshChatTools, classifyChatError } from '../llm/index.js';
|
|
23
23
|
import { renderChip } from '../attachments/image.js';
|
|
24
|
+
import { readClipboardAsAttachment } from '../attachments/clipboard.js';
|
|
25
|
+
import { modelSupportsVision } from '../llm/capabilities.js';
|
|
24
26
|
import { contextState, appendCurrentSessionRuntimeEvent } from '../session/index.js';
|
|
25
27
|
import { effectiveSystemPrompt, skillsChangedSinceLastObserve } from '../skills/index.js';
|
|
26
28
|
import { clearSkillActivation } from '../skills/activation.js';
|
|
@@ -72,6 +74,30 @@ let pendingTimer = null;
|
|
|
72
74
|
* (供 renderHistory 复显文件名——base64 不可逆地塞进 history 后,只能从侧 channel 拿原文件名)。
|
|
73
75
|
* messageAttachments 已移到 ./message-format.ts (共享 Map,renderHistory 与 runTurn 都用)。 */
|
|
74
76
|
let pendingAttachments = [];
|
|
77
|
+
/**
|
|
78
|
+
* 把待发附件同步到脚栏「虚拟空行」(spinner 行上方,不进内容缓冲):
|
|
79
|
+
* chip 后挂降采样 badge(↓WxH,黄色);当前模型不支持视觉时行尾再拼短预警。
|
|
80
|
+
* 提交/撤回/清空/附加后都调一次;真正的归属与完整降采样说明在 echoInput 气泡下显示。
|
|
81
|
+
*/
|
|
82
|
+
function syncPendingAttachChips() {
|
|
83
|
+
if (pendingAttachments.length === 0) {
|
|
84
|
+
layout.setPendingAttachChips([], '');
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const chips = pendingAttachments.map((a) => {
|
|
88
|
+
const badge = a.downscaledFrom
|
|
89
|
+
? `${ui.yellow} ${t('prompt.imageDownscaledBadge', {
|
|
90
|
+
width: a.downscaledFrom.width,
|
|
91
|
+
height: a.downscaledFrom.height,
|
|
92
|
+
})}${ui.dim}`
|
|
93
|
+
: '';
|
|
94
|
+
return `${renderChip(a)}${badge}`;
|
|
95
|
+
});
|
|
96
|
+
const warning = modelSupportsVision(config.model)
|
|
97
|
+
? ''
|
|
98
|
+
: `${ui.yellow}${t('prompt.imageVisionWarningShort', { model: config.model })}${ui.reset}`;
|
|
99
|
+
layout.setPendingAttachChips(chips, warning);
|
|
100
|
+
}
|
|
75
101
|
// ── onRunningKey / onRunningMousePaste / startRunningListener / stopRunningListener 已移到 ./running-input.ts ──
|
|
76
102
|
// formatUserMessage 已移到 ./message-format.ts
|
|
77
103
|
/** 把多行提交输入回显进内容区(❯ 首行,续行按 prompt 宽度缩进)。仅 TUI 态回显(非 TTY 由 readline 自带回显)。 */
|
|
@@ -79,14 +105,46 @@ function echoInput(lines, trailingBlank = true) {
|
|
|
79
105
|
if (!layout.isActive())
|
|
80
106
|
return;
|
|
81
107
|
layout.contentWrite(formatUserMessage(lines, trailingBlank));
|
|
82
|
-
// 多模态附件:每张一行 chip 跟在 user bubble 后(原 /rollback /resume 复显一致)
|
|
108
|
+
// 多模态附件:每张一行 chip 跟在 user bubble 后(原 /rollback /resume 复显一致);
|
|
109
|
+
// 被降采样的图下一行给完整说明(脚栏只有 ↓WxH badge,正式归属处要说清原图尺寸)。
|
|
83
110
|
for (const a of pendingAttachments) {
|
|
84
111
|
layout.contentWrite(` ${ui.dim}${renderChip(a)}${ui.reset}\n`);
|
|
112
|
+
if (a.downscaledFrom) {
|
|
113
|
+
// 文件附件(/image <path>)磁盘原图还在;剪贴板附件原图不落盘——措辞分开,避免误导。
|
|
114
|
+
const msg = a.path.startsWith('clipboard:')
|
|
115
|
+
? t('prompt.imageDownscaled', { width: a.downscaledFrom.width, height: a.downscaledFrom.height })
|
|
116
|
+
: t('prompt.imageDownscaledFile', { width: a.downscaledFrom.width, height: a.downscaledFrom.height });
|
|
117
|
+
layout.contentWrite(` ${ui.yellow}${msg}${ui.reset}\n`);
|
|
118
|
+
}
|
|
85
119
|
}
|
|
120
|
+
// 有附件时 formatUserMessage 的尾空行落在 chip 之前(气泡→空行→chip),chip 与 agent
|
|
121
|
+
// 正文之间还需补一个空行,否则回复紧贴截图 chip(无附件时尾空行本就是分隔,不用补)。
|
|
122
|
+
if (pendingAttachments.length > 0)
|
|
123
|
+
layout.contentWrite('\n');
|
|
86
124
|
// 用户气泡会填满终端整列宽;Windows Terminal 在末列进入 pending-wrap 后,紧随的 LF
|
|
87
125
|
// 偶尔只更新内部滚屏状态,导致上一轮耗时行与新气泡暂时黏连。缓冲中的物理行始终正确,
|
|
88
126
|
// 提交后立即按缓冲重绘,避免必须等滚动或 Agent 结束时的 repaint 才显示正确边界。
|
|
89
127
|
layout.repaintViewport();
|
|
128
|
+
// chip 已在气泡下正式回显 → 清脚栏 pending 提示(不清 pendingAttachments:路由未完成,
|
|
129
|
+
// flush 在 runTurn 里;若 500ms 撤回窗口内被 recall,rewindContent 后会重新 sync 回来)。
|
|
130
|
+
if (pendingAttachments.length > 0)
|
|
131
|
+
layout.setPendingAttachChips([], '');
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Ctrl+Y:从系统剪贴板抓截图 → 构造附件 → push 待发队列 → 同步脚栏。
|
|
135
|
+
*
|
|
136
|
+
* 成功(含重复图去重)返回 null——chip / ↓WxH 降采样 badge / 非视觉模型短预警都在脚栏
|
|
137
|
+
* 虚拟空行,不写内容缓冲;剪贴板无图返 {kind:'empty'}(黄提示),图太大/格式不支持返
|
|
138
|
+
* {kind:'error'}(红提示,透传 reason)。
|
|
139
|
+
*/
|
|
140
|
+
async function pasteImageFromClipboard() {
|
|
141
|
+
const r = await readClipboardAsAttachment();
|
|
142
|
+
if (!r.ok)
|
|
143
|
+
return 'empty' in r ? { kind: 'empty' } : { kind: 'error', reason: r.reason };
|
|
144
|
+
if (!pendingAttachments.some((a) => a.id === r.att.id))
|
|
145
|
+
pendingAttachments.push(r.att);
|
|
146
|
+
syncPendingAttachChips();
|
|
147
|
+
return null;
|
|
90
148
|
}
|
|
91
149
|
/**
|
|
92
150
|
* 等待 pending 撤回窗口(用户 Enter 后、agent 真发请求前的 500ms 兜底)。
|
|
@@ -560,6 +618,7 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
|
|
|
560
618
|
// 回填后用户再发随消息一起带走;side channel 也不会在未 push user msg 时错写 index。
|
|
561
619
|
const imgs = pendingAttachments;
|
|
562
620
|
pendingAttachments = [];
|
|
621
|
+
syncPendingAttachChips(); // 已随消息提交:清脚栏 pending chip(归属显示在 echoInput 的气泡下)
|
|
563
622
|
const userInput = imgs.length === 0
|
|
564
623
|
? input
|
|
565
624
|
: [
|
|
@@ -774,6 +833,7 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
|
|
|
774
833
|
prompt: PROMPT,
|
|
775
834
|
commands: buildSlashCommands(),
|
|
776
835
|
onCycleMode: cycleMode,
|
|
836
|
+
onPasteImage: pasteImageFromClipboard,
|
|
777
837
|
// Ctrl+R / Ctrl+P 历史搜索候选源:惰性工厂——当前会话内存 queryHistory + 最近落盘会话,
|
|
778
838
|
// 聚合要读盘,只有面板真正打开(Ctrl+R/P)才求值,平常轮次零开销
|
|
779
839
|
history: () => collectQueryHistory(queryHistory).map((e) => e.text),
|
|
@@ -871,9 +931,11 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
|
|
|
871
931
|
list: () => pendingAttachments,
|
|
872
932
|
clear: () => {
|
|
873
933
|
pendingAttachments = [];
|
|
934
|
+
syncPendingAttachChips();
|
|
874
935
|
},
|
|
875
936
|
push: (att) => {
|
|
876
937
|
pendingAttachments.push(att);
|
|
938
|
+
syncPendingAttachChips();
|
|
877
939
|
},
|
|
878
940
|
},
|
|
879
941
|
buildSystemMessage,
|
|
@@ -918,7 +980,10 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
|
|
|
918
980
|
layout.contentWrite(`${ui.dim}${t('repl.unknownCommandHint')}${ui.reset}\n`);
|
|
919
981
|
continue; // 与其他命令一致:回 INPUT 态由循环顶部的 normalizeInputBoundary + enterInputMode 负责
|
|
920
982
|
}
|
|
921
|
-
|
|
983
|
+
// N 行 message + 2 行尾随空(含 \n\n 留下的 open current 行) + 每附件 1 行 chip
|
|
984
|
+
// + 每降采样附件 1 行完整说明 + 有附件时 chip 区与 agent 正文间的 1 行分隔空行。
|
|
985
|
+
const downscaledCount = pendingAttachments.filter((a) => a.downscaledFrom).length;
|
|
986
|
+
const bubbleRows = input.length + 2 + pendingAttachments.length + downscaledCount + (pendingAttachments.length > 0 ? 1 : 0);
|
|
922
987
|
// 排队消息入队时即已确认 → 跳过 500ms 撤回窗口,直接发送。
|
|
923
988
|
const shouldCommit = autoSend || (await awaitPendingRecall(input));
|
|
924
989
|
if (!shouldCommit) {
|
|
@@ -927,6 +992,7 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
|
|
|
927
992
|
// (runTurn 入口的 pendingAttachments.flush 仍按现有逻辑把附件塞进 userInput)。
|
|
928
993
|
layout.rewindContent(bubbleRows);
|
|
929
994
|
pendingPrefill = input;
|
|
995
|
+
syncPendingAttachChips(); // 撤回:echoInput 清掉的脚栏 chip 按保留的 pendingAttachments 恢复
|
|
930
996
|
layout.enterInputMode(t('repl.idle'));
|
|
931
997
|
continue;
|
|
932
998
|
}
|
|
@@ -943,6 +1009,7 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
|
|
|
943
1009
|
queryHistory.pop();
|
|
944
1010
|
layout.rewindContent(bubbleRows);
|
|
945
1011
|
pendingPrefill = input;
|
|
1012
|
+
syncPendingAttachChips(); // 撤回:脚栏 chip 按保留的 pendingAttachments 恢复
|
|
946
1013
|
layout.enterInputMode(t('repl.idle'));
|
|
947
1014
|
continue;
|
|
948
1015
|
}
|
package/dist/ui/clipboard.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { stdout, platform } from 'node:process';
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
3
5
|
/**
|
|
4
6
|
* 系统剪贴板读写(叶子模块,无 UI 依赖)。
|
|
5
7
|
*
|
|
@@ -146,3 +148,98 @@ export async function readClipboard() {
|
|
|
146
148
|
const xs = await captureOutput('xsel', ['--clipboard', '--output'], 'utf8');
|
|
147
149
|
return xs ?? '';
|
|
148
150
|
}
|
|
151
|
+
/** spawn 不吃 stdin 的命令,把 stdout 按二进制收集;空输出/失败返回 null(不抛)。 */
|
|
152
|
+
function captureBinary(cmd, args) {
|
|
153
|
+
return new Promise((resolve) => {
|
|
154
|
+
try {
|
|
155
|
+
const p = spawn(cmd, args, { stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true });
|
|
156
|
+
const chunks = [];
|
|
157
|
+
let settled = false;
|
|
158
|
+
const finish = (v) => {
|
|
159
|
+
if (settled)
|
|
160
|
+
return;
|
|
161
|
+
settled = true;
|
|
162
|
+
resolve(v);
|
|
163
|
+
};
|
|
164
|
+
p.stdout.on('data', (c) => chunks.push(c));
|
|
165
|
+
p.stdout.on('error', () => finish(null));
|
|
166
|
+
p.on('error', () => finish(null));
|
|
167
|
+
p.on('close', (code) => {
|
|
168
|
+
if (code !== 0)
|
|
169
|
+
return finish(null);
|
|
170
|
+
const buf = Buffer.concat(chunks);
|
|
171
|
+
finish(buf.length > 0 ? buf : null);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
resolve(null);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* 读取系统剪贴板里的图片(截图后 Win+Shift+S / Ctrl+C 图片文件的常见落点)。
|
|
181
|
+
*
|
|
182
|
+
* 各端统一导出 PNG 字节:
|
|
183
|
+
* - win32:STA 线程跑 WinForms `Clipboard::GetImage()` 存临时 PNG(剪贴板 API 要求 STA;
|
|
184
|
+
* Bitmap.Save 写文件而非 stdout,避免 PowerShell 管道把 PNG 当文本编码破坏字节);
|
|
185
|
+
* - darwin:osascript 让 Preview 风格的 `PNGf` TIFF 剪贴板项落到临时文件;
|
|
186
|
+
* - linux:Wayland `wl-paste -t image/png`;X11 `xclip -t image/png -o`。
|
|
187
|
+
*
|
|
188
|
+
* 剪贴板无图 / 工具缺失均返回 null(不抛),调用方按"剪贴板里没有图片"提示。
|
|
189
|
+
*/
|
|
190
|
+
export async function readClipboardImage() {
|
|
191
|
+
if (platform === 'win32') {
|
|
192
|
+
const tmp = join(tmpdir(), `mocode-clip-${process.pid}-${Date.now()}.png`);
|
|
193
|
+
const out = await captureOutput('powershell', [
|
|
194
|
+
'-NoProfile',
|
|
195
|
+
'-NonInteractive',
|
|
196
|
+
'-STA',
|
|
197
|
+
'-Command',
|
|
198
|
+
`Add-Type -AssemblyName System.Windows.Forms; Add-Type -AssemblyName System.Drawing; ` +
|
|
199
|
+
`$img = $null; for ($i=0; $i -lt 5 -and $null -eq $img; $i++) { try { ` +
|
|
200
|
+
`$img = [System.Windows.Forms.Clipboard]::GetImage() } catch { Start-Sleep -Milliseconds 50 } }; ` +
|
|
201
|
+
`if ($null -ne $img) { $img.Save('${tmp.replace(/'/g, "''")}', [System.Drawing.Imaging.ImageFormat]::Png); $img.Dispose(); Write-Output OK }`,
|
|
202
|
+
], 'utf8');
|
|
203
|
+
if (!out || !out.includes('OK'))
|
|
204
|
+
return null;
|
|
205
|
+
try {
|
|
206
|
+
const { readFile, rm } = await import('node:fs/promises');
|
|
207
|
+
const buf = await readFile(tmp);
|
|
208
|
+
await rm(tmp, { force: true });
|
|
209
|
+
return buf.length > 0 ? buf : null;
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (platform === 'darwin') {
|
|
216
|
+
// osascript 写文件用 HFS 冒号路径(Macintosh HD:Users:...),不能直接给 POSIX 斜线路径——
|
|
217
|
+
// `open for access POSIX file (...)` 在多数 macOS 版本上会解析失败。让 osascript 自己取
|
|
218
|
+
// 进程临时目录(POSIX file of (...)),再写 PNGf(raw data,ignore binary responses 必须关)。
|
|
219
|
+
const stamp = `mocode-clip-${process.pid}-${Date.now()}.png`;
|
|
220
|
+
const script = `set outPath to (POSIX file ((POSIX path of (path to temp items from user domain)) & "${stamp}"))` +
|
|
221
|
+
`\nset png_data to (the clipboard as «class PNGf»)` +
|
|
222
|
+
`\nset fp to open for access outPath with write permission` +
|
|
223
|
+
`\nwrite png_data to fp\nclose access fp` +
|
|
224
|
+
`\nreturn (POSIX path of outPath)`;
|
|
225
|
+
const out = await captureOutput('osascript', ['-e', script], 'utf8');
|
|
226
|
+
const tmp = out?.trim();
|
|
227
|
+
if (!tmp)
|
|
228
|
+
return null;
|
|
229
|
+
try {
|
|
230
|
+
const { readFile, rm } = await import('node:fs/promises');
|
|
231
|
+
const buf = await readFile(tmp);
|
|
232
|
+
await rm(tmp, { force: true });
|
|
233
|
+
return buf.length > 0 ? buf : null;
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
// linux:Wayland 优先,X11 兜底
|
|
240
|
+
const wl = await captureBinary('wl-paste', ['-t', 'image/png']);
|
|
241
|
+
if (wl)
|
|
242
|
+
return wl;
|
|
243
|
+
const xc = await captureBinary('xclip', ['-selection', 'clipboard', '-t', 'image/png', '-o']);
|
|
244
|
+
return xc;
|
|
245
|
+
}
|
|
@@ -30,7 +30,7 @@ import { paintInput, repaint } from './input-paint.js';
|
|
|
30
30
|
import { WHEEL_LINES, screenRowToAbsLine, repaintViewport, scrollBy, scrollWheel, resetScroll, lockScrollToBottom, } from './scroll.js';
|
|
31
31
|
import { contentWrite, contentInsertAfter, contentDeleteFrom, contentReplaceLine, reflowContentForResize, flushMdSegment, } from './content-write.js';
|
|
32
32
|
export { isTuiActive, getGeo, getEffectiveContentBottom, setRegion, contentMode, isStreamingPaused } from './screen.js';
|
|
33
|
-
export { drawStatusBar, setStatus, stopTurnTimer, startTurnTimerIfRunning, paintLiveAtCursor, clearLiveAtCursor, setLiveUsage, setQueuedTurn, setStatusBase, } from './statusbar.js';
|
|
33
|
+
export { drawStatusBar, setStatus, stopTurnTimer, startTurnTimerIfRunning, paintLiveAtCursor, clearLiveAtCursor, setLiveUsage, setQueuedTurn, setStatusBase, setPendingAttachChips, } from './statusbar.js';
|
|
34
34
|
export { paintInput, paintRunningInput, repaint } from './input-paint.js';
|
|
35
35
|
export { isScrolled, repaintViewport, repaintContentLine, scrollBy, scrollWheel, resetScroll, setMenuReserve, lockScrollToBottom, unlockScroll, isScrollLocked, } from './scroll.js';
|
|
36
36
|
export { contentWrite, writeBanner, rewriteBanner, bannerHeight, contentWriteMd, contentWriteMdOnce, clearContent, rewindContent, writeWelcomeBlock, dismissWelcomeBlock, contentInsertAfter, contentDeleteFrom, totalRows, isLastContentRowBlank, normalizeMutationBoundary, normalizeInputBoundary, contentReplaceLine, notifyContentReset, } from './content-write.js';
|
|
@@ -7,7 +7,7 @@ import * as content from '../content.js';
|
|
|
7
7
|
import { state } from './state.js';
|
|
8
8
|
import { esc, cup, getGeo, getEffectiveContentBottom, setRegion, runningCaretPos } from './screen.js';
|
|
9
9
|
import { SEL_OPEN, SEL_OFF, normalizeInputSelection, inputViewSig } from './selection.js';
|
|
10
|
-
import { composeSpinnerLine, composeModelLine, composePlanLines, drawStatusBar } from './statusbar.js';
|
|
10
|
+
import { composeSpinnerLine, composeModelLine, composePlanLines, composePendingAttachLine, drawStatusBar, } from './statusbar.js';
|
|
11
11
|
// ── 输入区(底栏输入框 + 向上菜单)──
|
|
12
12
|
/**
|
|
13
13
|
* 把逻辑行软折成可视行并开窗(超 maxInputRows 时滑窗保光标可见)。返回可见可视行文本(已折行)+
|
|
@@ -157,8 +157,9 @@ export function paintInput(view) {
|
|
|
157
157
|
buf += cup(effBottom, 1) + esc.clearLine + line;
|
|
158
158
|
}
|
|
159
159
|
// 2c. 虚拟空行(内容区与状态栏之间的视觉间隔,属底栏非内容):
|
|
160
|
-
// - 无活跃 plan:清空保留作分隔(原设计)
|
|
161
160
|
// - 有活跃 plan:渲染 plan chip(整帧重画时也要更新,避免 listener 漏触发后残留)
|
|
161
|
+
// - 否则有待发图片附件:渲染附件 chip(不进内容缓冲,提交后由 echoInput 正式回显)
|
|
162
|
+
// - 都没有:清空保留作分隔
|
|
162
163
|
// - plan 过长:占 2 行(planRows=2),spinner/上线/输入行随之整体下移 1 行
|
|
163
164
|
// paintInput 与 drawStatusBar 共享同一 planRows 模块态,setRegion 已据此把脚栏撑高。
|
|
164
165
|
{
|
|
@@ -171,10 +172,11 @@ export function paintInput(view) {
|
|
|
171
172
|
buf += cup(g.contentBottom + 2, 1) + esc.clearLine;
|
|
172
173
|
state.planRows = 1;
|
|
173
174
|
}
|
|
174
|
-
// plan
|
|
175
|
-
//
|
|
175
|
+
// 无 plan 时:画待发附件脚栏(chip + 降采样 badge + 非视觉预警,不进内容缓冲);
|
|
176
|
+
// slash 菜单向上展开时最后一行也落在这一行,会互相覆盖——菜单打开期间隐藏(关菜单恢复)。
|
|
176
177
|
if (planBuf.length === 0) {
|
|
177
|
-
|
|
178
|
+
const attLine = view.menu && view.menu.lines.length > 0 ? '' : composePendingAttachLine(g.cols);
|
|
179
|
+
buf += cup(g.contentBottom + 1, 1) + esc.clearLine + attLine;
|
|
178
180
|
}
|
|
179
181
|
}
|
|
180
182
|
// 3. 状态行:spinner 行 + model 行(两行式底栏)
|
|
@@ -57,6 +57,14 @@ export const state = {
|
|
|
57
57
|
flushTimer: null, // 用户停手后 flush 缓冲内容(repaintViewport)
|
|
58
58
|
// ── 状态栏(底栏文案 / spinner / 走时 / plan chip / live 帧位) ──
|
|
59
59
|
base: null,
|
|
60
|
+
/**
|
|
61
|
+
* 待发图片附件的 chip 行(已带色、不带换行),画在 spinner 行上方的「虚拟空行」
|
|
62
|
+
* (与 plan chip 同一位置;plan 非空时让位于 plan)。**不进内容缓冲**——提交后由
|
|
63
|
+
* echoInput 在用户气泡下正式回显一次,避免 Ctrl+Y/命令的反馈行成为无归属游离行。
|
|
64
|
+
*/
|
|
65
|
+
pendingAttachChips: [],
|
|
66
|
+
/** 待发附件的附加警告(已带色,如非视觉模型预警/降采样提示),拼在 chip 行末尾。 */
|
|
67
|
+
pendingAttachWarning: '',
|
|
60
68
|
/** 运行态实时 token 用量(agent core 流式推送,轮末 repl 清 undefined)。
|
|
61
69
|
* composeModelLine 在 RUNNING 态把它画成 chip 放 context 进度条左侧;
|
|
62
70
|
* 不主动触发重画——RUNNING 态 turnTimer 80ms 心跳重画自然取最新值。 */
|
|
@@ -227,7 +227,8 @@ export function drawStatusBar(status) {
|
|
|
227
227
|
// plan 从非空变成空(已结算为 ## Done:/ notes 里无活跃 ## Plan: 段)时,清掉残留的 plan 行 1。
|
|
228
228
|
// 否则上轮渲染的「plan: 标题 (N/M) ▸ 当前步」会卡在底栏「虚拟空行」位置直到下一次重启 REPL。
|
|
229
229
|
if (planLines.length === 0) {
|
|
230
|
-
|
|
230
|
+
// 无 plan 但有待发附件:同一行位置画附件脚栏(不进内容缓冲,见 setPendingAttachChips)。
|
|
231
|
+
planBuf += cup(planRow1, 1) + esc.clearLine + composePendingAttachLine(g.cols);
|
|
231
232
|
}
|
|
232
233
|
let out = planBuf +
|
|
233
234
|
cup(spinnerRow, 1) +
|
|
@@ -257,6 +258,26 @@ export function setStatus(status, frame) {
|
|
|
257
258
|
state.spinnerFrame = frame;
|
|
258
259
|
drawStatusBar();
|
|
259
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* 更新待发附件脚栏行(repl 的 pendingAttachments 真相源 → 脚栏虚拟空行)。
|
|
263
|
+
* 只写 state,不主动重画——调用方随后的 paintInput/drawStatusBar 自然带上。
|
|
264
|
+
* @param chips 已带色 chip(可含降采样 badge),多个两空格分隔
|
|
265
|
+
* @param warning 已带色的行级警告(如非视觉模型预警),拼在 chip 末尾
|
|
266
|
+
*/
|
|
267
|
+
export function setPendingAttachChips(chips, warning = '') {
|
|
268
|
+
state.pendingAttachChips = chips;
|
|
269
|
+
state.pendingAttachWarning = warning;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* 拼待发附件脚栏行(chips + 行级警告),整体截到列宽;无附件返回空串。
|
|
273
|
+
* paintInput 与 drawStatusBar 共用,保证两条重画路径输出一致。
|
|
274
|
+
*/
|
|
275
|
+
export function composePendingAttachLine(cols) {
|
|
276
|
+
if (state.pendingAttachChips.length === 0)
|
|
277
|
+
return '';
|
|
278
|
+
const warning = state.pendingAttachWarning ? ` ${state.pendingAttachWarning}` : '';
|
|
279
|
+
return truncateDisplay(`${ui.dim}${state.pendingAttachChips.join(' ')}${ui.reset}${warning}`, Math.max(1, cols));
|
|
280
|
+
}
|
|
260
281
|
/**
|
|
261
282
|
* 启走时刷新计时器:RUNNING 态每 80ms 重画状态行,使 composeStatus 重算 elapsed。
|
|
262
283
|
* 必要性:spinner 在首 token 到达即 stop,思考/正文流式期间状态行不再经 spinner 刷新;
|
|
@@ -54,6 +54,8 @@ export async function promptWithSlashMenu(opts) {
|
|
|
54
54
|
let undoSnapshot = null;
|
|
55
55
|
/** 二次确认武装截止时刻(绝对 ms);0=未武装。见 submit() 与 MOCODE_CONFIRM_SEND。 */
|
|
56
56
|
let confirmArmedUntil = 0;
|
|
57
|
+
/** Ctrl+Y 剪贴板抓图进行中:禁止重入(连按不重复入队同一张图)。 */
|
|
58
|
+
let pastingImage = false;
|
|
57
59
|
let resolved = false;
|
|
58
60
|
let resolve;
|
|
59
61
|
let reject;
|
|
@@ -648,6 +650,12 @@ export async function promptWithSlashMenu(opts) {
|
|
|
648
650
|
void openHistorySearch();
|
|
649
651
|
return;
|
|
650
652
|
}
|
|
653
|
+
// Ctrl+Y:从系统剪贴板抓截图并入待发附件(Win+Shift+S 截图后无需再存文件)。
|
|
654
|
+
// 多数终端会拦截 Ctrl+V 自己做文本粘贴,故用不被拦截的 Ctrl+Y(yank 语义)。
|
|
655
|
+
if (key.ctrl && key.name === 'y') {
|
|
656
|
+
void pasteClipboardImage();
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
651
659
|
const isReturn = key.name === 'return' || key.name === 'enter';
|
|
652
660
|
// 换行:Ctrl+J / Ctrl+Enter / Alt+Enter(meta)/ Shift+Enter(终端区分时)/ lone LF
|
|
653
661
|
// (粘贴的 CR/LF 已在上方 pasting 分支累积进 pasteParts,不会到此)
|
|
@@ -895,6 +903,37 @@ export async function promptWithSlashMenu(opts) {
|
|
|
895
903
|
}
|
|
896
904
|
redraw();
|
|
897
905
|
}
|
|
906
|
+
/**
|
|
907
|
+
* Ctrl+Y:让 repl 从系统剪贴板抓图(repl 持有 pendingAttachments 与 config,editor 不直接依赖)。
|
|
908
|
+
* 成功(含去重)完全静默——chip / 降采样 badge / 非视觉预警都在脚栏虚拟空行,提交后才在
|
|
909
|
+
* 气泡下正式回显;只有「剪贴板无图 / 抓图失败」给一条内容区瞬时提示。
|
|
910
|
+
* busy 期间连按只取第一次。
|
|
911
|
+
*/
|
|
912
|
+
async function pasteClipboardImage() {
|
|
913
|
+
if (resolved || !opts.onPasteImage || pastingImage)
|
|
914
|
+
return;
|
|
915
|
+
pastingImage = true;
|
|
916
|
+
try {
|
|
917
|
+
const notice = await opts.onPasteImage();
|
|
918
|
+
if (resolved || !notice)
|
|
919
|
+
return;
|
|
920
|
+
if (notice.kind === 'empty') {
|
|
921
|
+
layout.contentWrite(`${ui.yellow}${t('prompt.imageEmpty')}${ui.reset}\n`);
|
|
922
|
+
}
|
|
923
|
+
else {
|
|
924
|
+
layout.contentWrite(`${ui.red}${t('prompt.imageFailed', { reason: notice.reason })}${ui.reset}\n`);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
catch {
|
|
928
|
+
// 剪贴板工具异常不应打断输入循环;与 readClipboard 同口径静默降级为提示。
|
|
929
|
+
if (!resolved)
|
|
930
|
+
layout.contentWrite(`${ui.yellow}${t('prompt.imageEmpty')}${ui.reset}\n`);
|
|
931
|
+
}
|
|
932
|
+
finally {
|
|
933
|
+
pastingImage = false;
|
|
934
|
+
redraw();
|
|
935
|
+
}
|
|
936
|
+
}
|
|
898
937
|
return new Promise((res, rej) => {
|
|
899
938
|
resolve = res;
|
|
900
939
|
reject = rej;
|