mocode-ai 1.8.10 → 1.9.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/README.md +2 -2
- package/README.zh-CN.md +2 -2
- package/dist/agent/index.js +18 -1
- package/dist/agent/model-turn.js +19 -5
- package/dist/agent/run-coordinator.js +32 -5
- package/dist/attachments/clipboard.js +22 -0
- package/dist/attachments/image.js +63 -0
- package/dist/config/index.js +1 -1
- package/dist/headless.js +7 -0
- package/dist/i18n/index.js +20 -2
- package/dist/memory/anchor-backfill.js +227 -0
- package/dist/memory/anchor.js +91 -9
- package/dist/memory/graph.js +54 -6
- package/dist/memory/guard.js +174 -0
- package/dist/memory/health.js +13 -0
- package/dist/memory/index.js +5 -2
- package/dist/memory/reflect.js +130 -7
- package/dist/memory/seed.js +227 -0
- package/dist/memory/store.js +16 -2
- package/dist/memory/tail.js +20 -0
- package/dist/memory/turn-recall.js +149 -0
- package/dist/repl/commands/image.js +30 -17
- package/dist/repl/commands/memory.js +217 -4
- package/dist/repl/commands.js +1 -0
- package/dist/repl/message-format.js +18 -0
- package/dist/repl/runtime.js +103 -9
- package/dist/tools/builtins/memory-graph.js +20 -6
- package/dist/tools/builtins/memory-list.js +3 -1
- package/dist/tools/builtins/memory-save.js +30 -3
- package/dist/tools/builtins/memory-search.js +5 -0
- package/dist/tools/builtins/memory-update.js +13 -3
- 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 +50 -1
- package/package.json +1 -1
package/dist/repl/runtime.js
CHANGED
|
@@ -21,10 +21,12 @@ 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';
|
|
27
|
-
import { buildMemoryIndexSection, buildAboutYouSection, buildProjectGraphHint, buildEpisodeSection, initPersona, gcMemories, kickoffReflection, kickoffConsolidation,
|
|
29
|
+
import { buildMemoryIndexSection, buildAboutYouSection, buildProjectGraphHint, buildEpisodeSection, initPersona, gcMemories, kickoffReflection, kickoffConsolidation, reflectOnExit, getLastReflectResult, clearLastReflectResult, snapshotTranscript, formatReflectResult, flushRecallStats, flushProactiveStats, flushTurnRecallStats, writeMemoryHealth, resetProactiveTurn, captureMemoryBaseline, buildMemoryTailSection, loadAll, } from '../memory/index.js';
|
|
28
30
|
import { finalizeCurrentEpisode } from './episode-finalize.js';
|
|
29
31
|
import { collectQueryHistory } from '../session/query-history.js';
|
|
30
32
|
import { ToolPolicyController } from '../tools/policy.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 兜底)。
|
|
@@ -350,6 +408,19 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
|
|
|
350
408
|
if (!history.some((m) => m.role === 'user')) {
|
|
351
409
|
layout.writeWelcomeBlock(welcomeLines());
|
|
352
410
|
}
|
|
411
|
+
// R9.4 空库提示:记忆开着但一条 active 都没有 → 说清「怎么让它有」,而不是让用户
|
|
412
|
+
// 对着空库空转。只在启动时提示一次(不是每轮),且不给 UI 常驻噪音:
|
|
413
|
+
// 「零感知」路线要求的是**行为**里有记忆,不是界面上反复提醒记忆的存在。
|
|
414
|
+
if (isMemoryEnabled()) {
|
|
415
|
+
try {
|
|
416
|
+
const hasActive = loadAll().some((e) => e.status === 'active');
|
|
417
|
+
if (!hasActive)
|
|
418
|
+
layout.contentWrite(`${ui.dim} ${t('memory.emptyHint')}${ui.reset}\n`);
|
|
419
|
+
}
|
|
420
|
+
catch {
|
|
421
|
+
// 读库失败不阻塞启动(与 gcMemories 同口径)
|
|
422
|
+
}
|
|
423
|
+
}
|
|
353
424
|
// 启动时限频自动 GC(24h 闸门,归档+purge 全做):fire-and-forget,
|
|
354
425
|
// 不阻塞进入主循环;runRetention 内部归档本地秒完、reflection 后台跑。可用 MOCODE_AUTO_GC=false 关闭。
|
|
355
426
|
void runtime.session.autoGc().catch(() => undefined);
|
|
@@ -560,6 +631,7 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
|
|
|
560
631
|
// 回填后用户再发随消息一起带走;side channel 也不会在未 push user msg 时错写 index。
|
|
561
632
|
const imgs = pendingAttachments;
|
|
562
633
|
pendingAttachments = [];
|
|
634
|
+
syncPendingAttachChips(); // 已随消息提交:清脚栏 pending chip(归属显示在 echoInput 的气泡下)
|
|
563
635
|
const userInput = imgs.length === 0
|
|
564
636
|
? input
|
|
565
637
|
: [
|
|
@@ -615,6 +687,8 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
|
|
|
615
687
|
// 与召回计数一起在轮末落一次。健康快照仍只由 /memory health 与退出路径写,
|
|
616
688
|
// 因为它要读全库 + 算 stale,不该每轮付这个成本。
|
|
617
689
|
flushProactiveStats();
|
|
690
|
+
// R18:每轮静默召回的计数同样在内存累计,轮末落一次。
|
|
691
|
+
flushTurnRecallStats();
|
|
618
692
|
turnCount++;
|
|
619
693
|
if (turnCount % config.reflectEveryN === 0) {
|
|
620
694
|
kickoffReflection(snapshotTranscript(history, 20));
|
|
@@ -774,6 +848,12 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
|
|
|
774
848
|
prompt: PROMPT,
|
|
775
849
|
commands: buildSlashCommands(),
|
|
776
850
|
onCycleMode: cycleMode,
|
|
851
|
+
onPasteImage: pasteImageFromClipboard,
|
|
852
|
+
hasPendingAttachments: () => pendingAttachments.length > 0,
|
|
853
|
+
clearPendingAttachments: () => {
|
|
854
|
+
pendingAttachments = [];
|
|
855
|
+
syncPendingAttachChips();
|
|
856
|
+
},
|
|
777
857
|
// Ctrl+R / Ctrl+P 历史搜索候选源:惰性工厂——当前会话内存 queryHistory + 最近落盘会话,
|
|
778
858
|
// 聚合要读盘,只有面板真正打开(Ctrl+R/P)才求值,平常轮次零开销
|
|
779
859
|
history: () => collectQueryHistory(queryHistory).map((e) => e.text),
|
|
@@ -871,9 +951,11 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
|
|
|
871
951
|
list: () => pendingAttachments,
|
|
872
952
|
clear: () => {
|
|
873
953
|
pendingAttachments = [];
|
|
954
|
+
syncPendingAttachChips();
|
|
874
955
|
},
|
|
875
956
|
push: (att) => {
|
|
876
957
|
pendingAttachments.push(att);
|
|
958
|
+
syncPendingAttachChips();
|
|
877
959
|
},
|
|
878
960
|
},
|
|
879
961
|
buildSystemMessage,
|
|
@@ -918,7 +1000,10 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
|
|
|
918
1000
|
layout.contentWrite(`${ui.dim}${t('repl.unknownCommandHint')}${ui.reset}\n`);
|
|
919
1001
|
continue; // 与其他命令一致:回 INPUT 态由循环顶部的 normalizeInputBoundary + enterInputMode 负责
|
|
920
1002
|
}
|
|
921
|
-
|
|
1003
|
+
// N 行 message + 2 行尾随空(含 \n\n 留下的 open current 行) + 每附件 1 行 chip
|
|
1004
|
+
// + 每降采样附件 1 行完整说明 + 有附件时 chip 区与 agent 正文间的 1 行分隔空行。
|
|
1005
|
+
const downscaledCount = pendingAttachments.filter((a) => a.downscaledFrom).length;
|
|
1006
|
+
const bubbleRows = input.length + 2 + pendingAttachments.length + downscaledCount + (pendingAttachments.length > 0 ? 1 : 0);
|
|
922
1007
|
// 排队消息入队时即已确认 → 跳过 500ms 撤回窗口,直接发送。
|
|
923
1008
|
const shouldCommit = autoSend || (await awaitPendingRecall(input));
|
|
924
1009
|
if (!shouldCommit) {
|
|
@@ -927,6 +1012,7 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
|
|
|
927
1012
|
// (runTurn 入口的 pendingAttachments.flush 仍按现有逻辑把附件塞进 userInput)。
|
|
928
1013
|
layout.rewindContent(bubbleRows);
|
|
929
1014
|
pendingPrefill = input;
|
|
1015
|
+
syncPendingAttachChips(); // 撤回:echoInput 清掉的脚栏 chip 按保留的 pendingAttachments 恢复
|
|
930
1016
|
layout.enterInputMode(t('repl.idle'));
|
|
931
1017
|
continue;
|
|
932
1018
|
}
|
|
@@ -943,6 +1029,7 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
|
|
|
943
1029
|
queryHistory.pop();
|
|
944
1030
|
layout.rewindContent(bubbleRows);
|
|
945
1031
|
pendingPrefill = input;
|
|
1032
|
+
syncPendingAttachChips(); // 撤回:脚栏 chip 按保留的 pendingAttachments 恢复
|
|
946
1033
|
layout.enterInputMode(t('repl.idle'));
|
|
947
1034
|
continue;
|
|
948
1035
|
}
|
|
@@ -968,16 +1055,23 @@ export async function startRepl(initialHistory, sessionId, sandboxRootOverride,
|
|
|
968
1055
|
}
|
|
969
1056
|
}
|
|
970
1057
|
}
|
|
971
|
-
// R6.1:退出前落情节(纯本地、零 LLM
|
|
1058
|
+
// R6.1:退出前落情节(纯本地、零 LLM,毫秒级;放在反思之前——反思能从本轮情节里
|
|
1059
|
+
// 读到「这个会话干了什么」,顺序反了就少一段素材)。
|
|
972
1060
|
finalizeCurrentEpisode(currentSessionId, history, queryHistory);
|
|
973
1061
|
// R4.1:退出时写一份健康快照。放这里而不是每轮:它要读全库 + 算 stale,
|
|
974
|
-
//
|
|
1062
|
+
// 每轮付这个成本不值当。
|
|
1063
|
+
// 注意:healthPath() 是**固定路径**(.mocode/memory-health.json),每次都是覆盖写,
|
|
1064
|
+
// 所以磁盘上只有「最后一次生成」的那份,不构成历史趋势线。想留存历史需自行按时间戳
|
|
1065
|
+
// 复制出去。快照只在退出与 /memory health 时生成,而 /memory health 是现场重算的,
|
|
1066
|
+
// 因此读这个文件判断现状前先看它的 generatedAt。
|
|
1067
|
+
// 退出兜底反思:短会话(1–2 轮)永远到不了 cadence,退出是唯一能确保发生的边界。
|
|
1068
|
+
// reflectOnExit 内部已含 drain(等在飞收尾),所以不必再单独调 drainMemoryBackground。
|
|
1069
|
+
// 放在写健康快照**之前**:这样快照能看到本轮新增的条目与计数,不会留下"刚反思完、
|
|
1070
|
+
// 快照却还是旧数字"的错位。
|
|
1071
|
+
await reflectOnExit(snapshotTranscript(history, 20));
|
|
975
1072
|
flushProactiveStats();
|
|
1073
|
+
flushTurnRecallStats();
|
|
976
1074
|
writeMemoryHealth(isMemoryEnabled());
|
|
977
|
-
// 退出前等在飞反思收尾。注意:Ctrl+C 在 TUI(raw 模式)下是按键不是 SIGINT,空输入框时
|
|
978
|
-
// 由主循环 catch { break } 接住,因此**会**走到这里等反思跑完;只有非 raw 模式下的
|
|
979
|
-
// 进程级 SIGINT → process.exit(130) 才跳过(fire-and-forget 不承诺中断时完成)。
|
|
980
|
-
await drainMemoryBackground();
|
|
981
1075
|
await runtime.close();
|
|
982
1076
|
await closeAllMcp();
|
|
983
1077
|
layout.exitAltScreen();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addTriple, graphStats, neighborsOf, pathBetween } from '../../memory/graph.js';
|
|
1
|
+
import { addTriple, graphStats, neighborsOf, parseAsOf, pathBetween } from '../../memory/graph.js';
|
|
2
2
|
import { formatRecallStats } from '../../memory/recall-stats.js';
|
|
3
3
|
// ---------- memory_graph ----------
|
|
4
4
|
// 知识图谱维护工具:邻居遍历(1-3 跳,可 relation 过滤)、两点最短路径、手工加三元组、看图统计。
|
|
@@ -33,6 +33,10 @@ export const memoryGraphTool = {
|
|
|
33
33
|
},
|
|
34
34
|
query: { type: 'string', description: 'neighbors: entity name or id; path: start entity' },
|
|
35
35
|
depth: { type: 'integer', description: 'neighbors: hops, 1-3, default 1' },
|
|
36
|
+
asOf: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
description: 'neighbors/path: answer "what did I believe at THAT moment" instead of now. ISO timestamp or YYYY-MM-DD (local midnight). Edges are time-sliced by validAt/invalidAt: an edge counts iff validAt <= asOf < invalidAt. Use it when the current answer contradicts an older decision and you need to know which belief was held then. Omit for the current view.',
|
|
39
|
+
},
|
|
36
40
|
src: { type: 'string', description: 'add: source entity name' },
|
|
37
41
|
relation: {
|
|
38
42
|
type: 'string',
|
|
@@ -81,14 +85,20 @@ export const memoryGraphTool = {
|
|
|
81
85
|
return '错误:neighbors 需要 query(实体名或 id)。';
|
|
82
86
|
const depth = typeof args.depth === 'number' ? args.depth : 1;
|
|
83
87
|
const rel = typeof args.relation === 'string' ? args.relation.trim() : '';
|
|
84
|
-
const
|
|
88
|
+
const asOf = parseAsOf(args.asOf);
|
|
89
|
+
if (!asOf.ok)
|
|
90
|
+
return `错误:${asOf.reason}`;
|
|
91
|
+
const r = neighborsOf(query, depth, rel || undefined, asOf.ms);
|
|
85
92
|
if (!r.center)
|
|
86
93
|
return `(图中没有实体 "${query}")`;
|
|
87
94
|
const relNote = rel ? `,仅 ${rel} 边` : '';
|
|
95
|
+
const atNote = asOf.ms != null ? `,asOf ${new Date(asOf.ms).toISOString()}` : '';
|
|
88
96
|
const lines = [
|
|
89
97
|
`## ${r.center.name} (${r.center.id})${r.center.summary ? ` — ${r.center.summary}` : ''}`,
|
|
90
98
|
r.entities.length > 0 ? `\n## 邻居实体\n${fmtEntities(r.entities)}` : '',
|
|
91
|
-
`\n## 边(${r.edges.length}${relNote}${r.truncated ? ',已截断' : ''})\n${fmtEdges(r.edges)}`,
|
|
99
|
+
`\n## 边(${r.edges.length}${relNote}${atNote}${r.truncated ? ',已截断' : ''})\n${fmtEdges(r.edges)}`,
|
|
100
|
+
// 「那一刻没有边」与「实体不存在」是两种完全不同的答案,不说清楚会被误读成后者。
|
|
101
|
+
asOf.ms != null && r.edges.length === 0 ? '\n(该时刻没有成立的边——实体在,但那时还没有这条关系)' : '',
|
|
92
102
|
].filter(Boolean);
|
|
93
103
|
return lines.join('\n');
|
|
94
104
|
}
|
|
@@ -97,12 +107,16 @@ export const memoryGraphTool = {
|
|
|
97
107
|
const to = String(args.dst ?? '').trim();
|
|
98
108
|
if (!from || !to)
|
|
99
109
|
return '错误:path 需要 query(起点实体)和 dst(终点实体)。';
|
|
100
|
-
const
|
|
110
|
+
const asOf = parseAsOf(args.asOf);
|
|
111
|
+
if (!asOf.ok)
|
|
112
|
+
return `错误:${asOf.reason}`;
|
|
113
|
+
const r = pathBetween(from, to, asOf.ms);
|
|
114
|
+
const scope = asOf.ms != null ? `该时刻(${new Date(asOf.ms).toISOString()})` : '现在';
|
|
101
115
|
if (!r)
|
|
102
|
-
return `(无
|
|
116
|
+
return `(无 ${scope} 成立的路径:${from} ⇸ ${to},或端点实体不存在)`;
|
|
103
117
|
const chain = r.path.map((e) => e.name).join(' → ');
|
|
104
118
|
const lines = [
|
|
105
|
-
`## ${r.from.name} ⇢ ${r.to.name}(${r.edges.length}
|
|
119
|
+
`## ${r.from.name} ⇢ ${r.to.name}(${r.edges.length} 跳${asOf.ms != null ? `,asOf ${new Date(asOf.ms).toISOString()}` : ''})`,
|
|
106
120
|
`路径:${chain}`,
|
|
107
121
|
`\n## 边\n${fmtEdges(r.edges)}`,
|
|
108
122
|
];
|
|
@@ -29,7 +29,9 @@ export const memoryListTool = {
|
|
|
29
29
|
return '(无记忆条目)';
|
|
30
30
|
const lines = items.map((i) => {
|
|
31
31
|
const gap = !i.hasTrigger && wantsTrigger(i.type) ? ' [NO-TRIGGER]' : '';
|
|
32
|
-
|
|
32
|
+
// R16.1:来源不可信的条目在这里也要露出来,否则一眼扫列表看不出哪条是"从网页上抄的"。
|
|
33
|
+
const origin = i.origin === 'tool_output' ? ' [UNVERIFIED-ORIGIN]' : '';
|
|
34
|
+
return `- ${i.id}: ${i.name} — ${i.summary} (${i.type}, ${i.status})${gap}${origin}`;
|
|
33
35
|
});
|
|
34
36
|
const gaps = items.filter((i) => !i.hasTrigger && wantsTrigger(i.type)).length;
|
|
35
37
|
if (gaps > 0) {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { saveEntry, memoryWriteBlockedMessage } from '../../memory/store.js';
|
|
2
2
|
import { addTriple } from '../../memory/graph.js';
|
|
3
3
|
import { buildAnchors } from '../../memory/anchor.js';
|
|
4
|
+
import { detectHijack } from '../../memory/guard.js';
|
|
5
|
+
import { appendAudit } from '../../memory/audit.js';
|
|
4
6
|
/**
|
|
5
7
|
* 把工具参数里的 anchors 归一成 AnchorInput[]。
|
|
6
8
|
*
|
|
@@ -18,8 +20,11 @@ function parseAnchorInputs(raw) {
|
|
|
18
20
|
const p = typeof a.path === 'string' ? a.path.trim() : '';
|
|
19
21
|
if (!p)
|
|
20
22
|
continue;
|
|
23
|
+
// R7.1:非法 kind 一律按 file 处理。静默纠正比报错好——报错会让模型整条记忆都放弃写,
|
|
24
|
+
// 而它本来只是想锚一个文件,顺带把 kind 拼错了。
|
|
25
|
+
const k = a.kind === 'dir' || a.kind === 'url' ? a.kind : undefined;
|
|
21
26
|
const s = typeof a.symbol === 'string' ? a.symbol.trim() : '';
|
|
22
|
-
out.push({ path: p, ...(s ? { symbol: s } : {}) });
|
|
27
|
+
out.push({ ...(k ? { kind: k } : {}), path: p, ...(s ? { symbol: s } : {}) });
|
|
23
28
|
}
|
|
24
29
|
return out;
|
|
25
30
|
}
|
|
@@ -97,13 +102,18 @@ export const memorySaveTool = {
|
|
|
97
102
|
},
|
|
98
103
|
anchors: {
|
|
99
104
|
type: 'array',
|
|
100
|
-
description: '
|
|
105
|
+
description: 'Anchors: the thing this memory talks about, so a later change marks the memory stale instead of silently serving an outdated fact. kind=file (default) for a file or one of its symbols; kind=dir for a directory (detects added/removed/renamed entries, not edits inside files); kind=url for a web page (recorded as provenance only — it is never fetched, so it can never be verified). Pass paths/symbols only — hashes are computed for you at write time. Anchors that cannot be resolved are dropped.',
|
|
101
106
|
items: {
|
|
102
107
|
type: 'object',
|
|
103
108
|
properties: {
|
|
109
|
+
kind: {
|
|
110
|
+
type: 'string',
|
|
111
|
+
enum: ['file', 'dir', 'url'],
|
|
112
|
+
description: 'Default "file". Use "dir" for a directory, "url" for a web page.',
|
|
113
|
+
},
|
|
104
114
|
path: {
|
|
105
115
|
type: 'string',
|
|
106
|
-
description: 'Workspace-relative file path, e.g. "src/memory/store.ts" (
|
|
116
|
+
description: 'Workspace-relative file/directory path (forward slashes), e.g. "src/memory/store.ts" — or an http(s) URL when kind=url',
|
|
107
117
|
},
|
|
108
118
|
symbol: {
|
|
109
119
|
type: 'string',
|
|
@@ -131,6 +141,23 @@ export const memorySaveTool = {
|
|
|
131
141
|
const trigger = typeof args.trigger === 'string' ? args.trigger.trim() : '';
|
|
132
142
|
const action = typeof args.action === 'string' ? args.action.trim() : '';
|
|
133
143
|
const anchors = parseAnchorInputs(args.anchors);
|
|
144
|
+
// R16.2:指令性内容拒写。模型可能刚读完一个网页,把里面的"忽略之前的指令"当成
|
|
145
|
+
// 一条"要记住的约定"存进来——那样它此后每次启动都会进 system prompt。
|
|
146
|
+
// 确定性规则,**不靠模型自省**:模型正是被攻击对象,让它判断"这算不算注入"不可靠。
|
|
147
|
+
// 拒绝必须说清原因并留证,否则模型会换个 name 反复重试。
|
|
148
|
+
const hijack = detectHijack(`${name} ${summary} ${body}`);
|
|
149
|
+
if (hijack) {
|
|
150
|
+
appendAudit({
|
|
151
|
+
at: new Date().toISOString(),
|
|
152
|
+
action: 'refuse',
|
|
153
|
+
detail: `拒绝写入记忆「${name.slice(0, 60)}」:命中投毒规则 ${hijack.rule}`,
|
|
154
|
+
reason: `hijack:${hijack.rule}`,
|
|
155
|
+
snippet: hijack.sample,
|
|
156
|
+
});
|
|
157
|
+
return (`拒绝写入:内容命中投毒/注入规则 ${hijack.rule}(「${hijack.sample}」)。\n` +
|
|
158
|
+
`记忆会在**每次启动**时注入系统提示,所以这类"改写 agent 指令/身份/报告义务"的文本一律不落库。\n` +
|
|
159
|
+
`如果这是需要记住的知识(例如"看到这类网页要当心"),请改成**描述性结论**并避免逐字照抄原文。`);
|
|
160
|
+
}
|
|
134
161
|
const r = saveEntry({
|
|
135
162
|
name,
|
|
136
163
|
summary,
|
|
@@ -36,6 +36,11 @@ function statusMark(e, st, anchor) {
|
|
|
36
36
|
const why = describeAnchorState(anchor);
|
|
37
37
|
parts.push(`STALE-CODE${why ? ` (${why})` : ''}`);
|
|
38
38
|
}
|
|
39
|
+
// R16.1:来源标记。只在**二手转述**时出现——内容逐字来自工具输出(网页/文件/命令),
|
|
40
|
+
// 模型没经用户确认就记了下来。给的是"引用前先核实"的提示,不是"这条是假的"。
|
|
41
|
+
// 默认路径(模型自己总结的事实)不加标记,保持零噪音。
|
|
42
|
+
if (e.origin === 'tool_output')
|
|
43
|
+
parts.push('UNVERIFIED-ORIGIN');
|
|
39
44
|
return parts.length > 0 ? ` [${parts.join(' | ')}]` : '';
|
|
40
45
|
}
|
|
41
46
|
export const memorySearchTool = {
|
|
@@ -14,8 +14,10 @@ function parseAnchorInputs(raw) {
|
|
|
14
14
|
const p = typeof a.path === 'string' ? a.path.trim() : '';
|
|
15
15
|
if (!p)
|
|
16
16
|
continue;
|
|
17
|
+
// R7.1:非法 kind 按 file 处理(与 memory_save 同口径),不因此丢整条锚点。
|
|
18
|
+
const k = a.kind === 'dir' || a.kind === 'url' ? a.kind : undefined;
|
|
17
19
|
const s = typeof a.symbol === 'string' ? a.symbol.trim() : '';
|
|
18
|
-
out.push({ path: p, ...(s ? { symbol: s } : {}) });
|
|
20
|
+
out.push({ ...(k ? { kind: k } : {}), path: p, ...(s ? { symbol: s } : {}) });
|
|
19
21
|
}
|
|
20
22
|
return out;
|
|
21
23
|
}
|
|
@@ -44,11 +46,19 @@ export const memoryUpdateTool = {
|
|
|
44
46
|
},
|
|
45
47
|
anchors: {
|
|
46
48
|
type: 'array',
|
|
47
|
-
description: '
|
|
49
|
+
description: 'Anchors — REPLACES the whole set (pass [] to clear). kind=file (default) for a file or symbol; dir for a directory (detects added/removed/renamed entries, not edits inside files); url for a web page (provenance only, never fetched so never verified). Pass paths/symbols only; hashes are recomputed at write time. Use this so a later change surfaces the memory as stale instead of silently serving an outdated fact.',
|
|
48
50
|
items: {
|
|
49
51
|
type: 'object',
|
|
50
52
|
properties: {
|
|
51
|
-
|
|
53
|
+
kind: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
enum: ['file', 'dir', 'url'],
|
|
56
|
+
description: 'Default "file". Use "dir" for a directory, "url" for a web page.',
|
|
57
|
+
},
|
|
58
|
+
path: {
|
|
59
|
+
type: 'string',
|
|
60
|
+
description: 'Workspace-relative file/directory path, or an http(s) URL when kind=url',
|
|
61
|
+
},
|
|
52
62
|
symbol: {
|
|
53
63
|
type: 'string',
|
|
54
64
|
description: 'Optional function/class/const name; prefers a fragment over the whole file',
|
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 刷新;
|