mocode-ai 1.10.0 → 1.10.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/dist/agent/index.js +13 -3
- package/dist/agent/mentioned-files.js +71 -0
- package/dist/agent/model-turn.js +55 -11
- package/dist/agent/progress-guard.js +67 -0
- package/dist/agent/run-coordinator.js +140 -12
- package/dist/agent/short-path-completion.js +109 -0
- package/dist/agent/spawn.js +39 -0
- package/dist/agent/stages/history-manager.js +1 -0
- package/dist/agent/tool-helpers.js +2 -2
- package/dist/agent/tool-turn.js +49 -4
- package/dist/agent/work-discipline.js +9 -9
- package/dist/config/index.js +13 -10
- package/dist/context/relevance.js +2 -1
- package/dist/host/stdio.js +88 -27
- package/dist/i18n/index.js +26 -10
- package/dist/llm/index.js +27 -3
- package/dist/llm/message-shape.js +18 -0
- package/dist/llm/reasoning.js +17 -0
- package/dist/models/reasoning-cap.js +19 -2
- package/dist/orchestrator/lane-executor.js +7 -1
- package/dist/orchestrator/repl.js +30 -49
- package/dist/repl/commands/appearance.js +1 -2
- package/dist/repl/commands/compact.js +4 -0
- package/dist/repl/commands/model-actions.js +4 -3
- package/dist/repl/commands/model.js +2 -3
- package/dist/repl/message-format.js +7 -6
- package/dist/repl/running-input.js +27 -65
- package/dist/repl/runtime.js +118 -76
- package/dist/rollback/store.js +36 -23
- package/dist/runtime/runtime.js +1 -1
- package/dist/session/compact.js +41 -4
- package/dist/session/retention.js +4 -0
- package/dist/session/short-path-metrics.js +185 -0
- package/dist/session/store.js +78 -3
- package/dist/session/terminal-transcript.js +101 -0
- package/dist/tools/builtins/ask-human.js +2 -2
- package/dist/tools/builtins/edit-file.js +28 -5
- package/dist/tools/builtins/grep.js +85 -35
- package/dist/tools/builtins/plan-update.js +4 -2
- package/dist/tools/builtins/read-file.js +95 -44
- package/dist/tools/builtins/run-command.js +57 -9
- package/dist/tools/ripgrep-client.js +31 -11
- package/dist/tools/tool-runtime.js +29 -8
- package/dist/ui/layout-internal/content-write.js +7 -3
- package/dist/ui/layout-internal/core.js +1 -1
- package/dist/ui/layout-internal/state.js +0 -6
- package/dist/ui/layout-internal/statusbar.js +0 -30
- package/dist/ui/output-sink.js +24 -0
- package/dist/ui/spinner.js +3 -1
- package/package.json +4 -2
package/dist/i18n/index.js
CHANGED
|
@@ -175,10 +175,10 @@ const zhCN = {
|
|
|
175
175
|
'intervention.emptyInput': '自动返回空输入',
|
|
176
176
|
'intervention.nonInteractive': '[介入] {title}(非交互环境,{kind})',
|
|
177
177
|
'repl.idle': '空闲',
|
|
178
|
-
'repl.queuedCommandHeld': '排队的是斜杠命令,已填入输入框,请确认后手动发送',
|
|
179
178
|
'repl.loadFailed': '(加载失败)',
|
|
180
179
|
'repl.resumeAnchor': '已恢复会话 {id} · {count} 条消息 · 当前模型 {model}(/model switch 可切换)',
|
|
181
|
-
'repl.compactedNotice': '──
|
|
180
|
+
'repl.compactedNotice': '── 较早的模型上下文已压缩 · 以下是保存的摘要 ──',
|
|
181
|
+
'repl.modelCompacted': '── 模型上下文已压缩 · 聊天记录仍可查看 ──',
|
|
182
182
|
'repl.compactedTruncated': '…(摘要共 {total} 字符,仅显示前 {shown} 字符)',
|
|
183
183
|
'repl.noSessions': '(没有已保存的会话)',
|
|
184
184
|
'repl.noValue': '(无)',
|
|
@@ -320,9 +320,6 @@ const zhCN = {
|
|
|
320
320
|
'banner.disabled': '关闭',
|
|
321
321
|
'status.modeSwitch': 'Shift+Tab 切换',
|
|
322
322
|
'status.history': '历史 ↑{count}(PgDn 回底)',
|
|
323
|
-
'status.queued': '排队 ·',
|
|
324
|
-
'status.queuedCount': '排队 ×{count} ·',
|
|
325
|
-
'status.queuePlanTag': '(Plan)',
|
|
326
323
|
'status.planMoreSteps': '还有 {count} 步',
|
|
327
324
|
'status.measured': '实测',
|
|
328
325
|
'status.estimated': '估算',
|
|
@@ -330,6 +327,16 @@ const zhCN = {
|
|
|
330
327
|
'status.providerMeasured': 'provider 上一步实测 {tokens}:{pct}%',
|
|
331
328
|
'agent.sending': '发送中… (任意键 / Esc / Ctrl+C 撤回)',
|
|
332
329
|
'agent.thinking': '思考中',
|
|
330
|
+
'agent.openingTargetFile': '目标文件',
|
|
331
|
+
'agent.openingRead': '我先查看 {file},了解现有内容。',
|
|
332
|
+
'agent.openingEdit': '我先修改 {file}。',
|
|
333
|
+
'agent.openingSearch': '我先在工作区定位相关文件或代码。',
|
|
334
|
+
'agent.openingCommand': '我先运行命令,查看执行结果。',
|
|
335
|
+
'agent.openingWeb': '我先查找相关网页资料。',
|
|
336
|
+
'agent.openingClarify': '我先确认一项影响后续工作的细节。',
|
|
337
|
+
'agent.openingTools': '我先准备这一步需要的工具。',
|
|
338
|
+
'agent.openingGeneric': '我先执行这项任务的第一步操作。',
|
|
339
|
+
'agent.openingSteered': '按你的补充,{action}',
|
|
333
340
|
'agent.generating': '生成 {tool}',
|
|
334
341
|
'agent.executing': '执行 {tool}',
|
|
335
342
|
'agent.retrying': '连接异常,{seconds}s 后重试(第 {attempt} 次)',
|
|
@@ -362,6 +369,7 @@ const zhCN = {
|
|
|
362
369
|
'toolError.invalidJson': '错误:工具 {name} 的 arguments 不是合法 JSON: {arguments}',
|
|
363
370
|
'toolError.execution': '错误:工具 {name} 执行失败: {message}',
|
|
364
371
|
'command.outputTruncated': '...(输出已截断 {count} 字符,保留开头与结尾)...',
|
|
372
|
+
'command.encodingHint': '[输出包含较多 NUL 或替换字符。如需读取这些字节,请检查输出分隔符或字符编码。]',
|
|
365
373
|
'command.interrupted': '[已中断]',
|
|
366
374
|
'command.executionFailed': '执行失败: {message}',
|
|
367
375
|
'command.exitCode': '[退出码 {code}]',
|
|
@@ -680,10 +688,10 @@ const en = {
|
|
|
680
688
|
'intervention.emptyInput': 'automatically returned empty input',
|
|
681
689
|
'intervention.nonInteractive': '[intervention] {title} (non-interactive; {kind})',
|
|
682
690
|
'repl.idle': 'Idle',
|
|
683
|
-
'repl.queuedCommandHeld': 'Queued text is a slash command; filled into the input for you to send manually',
|
|
684
691
|
'repl.loadFailed': '(load failed)',
|
|
685
692
|
'repl.resumeAnchor': 'Resumed session {id} · {count} messages · model {model} (/model switch to change)',
|
|
686
|
-
'repl.compactedNotice': '── Earlier
|
|
693
|
+
'repl.compactedNotice': '── Earlier model context was compacted · Saved summary below ──',
|
|
694
|
+
'repl.modelCompacted': '── Model context compacted · Chat history is still available ──',
|
|
687
695
|
'repl.compactedTruncated': '… (summary is {total} chars, showing the first {shown})',
|
|
688
696
|
'repl.noSessions': '(no saved sessions)',
|
|
689
697
|
'repl.noValue': '(none)',
|
|
@@ -824,9 +832,6 @@ const en = {
|
|
|
824
832
|
'banner.disabled': 'Disabled',
|
|
825
833
|
'status.modeSwitch': 'Shift+Tab Switch',
|
|
826
834
|
'status.history': 'History ↑{count} (PgDn to bottom)',
|
|
827
|
-
'status.queued': 'queued ·',
|
|
828
|
-
'status.queuedCount': 'queued ×{count} ·',
|
|
829
|
-
'status.queuePlanTag': ' (Plan)',
|
|
830
835
|
'status.planMoreSteps': '{count} more step(s)',
|
|
831
836
|
'status.measured': 'measured',
|
|
832
837
|
'status.estimated': 'estimated',
|
|
@@ -834,6 +839,16 @@ const en = {
|
|
|
834
839
|
'status.providerMeasured': 'provider measured {tokens} last step:{pct}%',
|
|
835
840
|
'agent.sending': 'Sending… (any key / Esc / Ctrl+C to recall)',
|
|
836
841
|
'agent.thinking': 'Thinking',
|
|
842
|
+
'agent.openingTargetFile': 'the target file',
|
|
843
|
+
'agent.openingRead': 'I’ll inspect {file} to see what’s there.',
|
|
844
|
+
'agent.openingEdit': 'I’ll start by editing {file}.',
|
|
845
|
+
'agent.openingSearch': 'I’ll locate the relevant files or code in the workspace.',
|
|
846
|
+
'agent.openingCommand': 'I’ll run the command and check its result.',
|
|
847
|
+
'agent.openingWeb': 'I’ll look up the relevant web sources.',
|
|
848
|
+
'agent.openingClarify': 'I’ll clarify a detail that affects the next step.',
|
|
849
|
+
'agent.openingTools': 'I’ll prepare the tools needed for the next step.',
|
|
850
|
+
'agent.openingGeneric': 'I’ll start with the first operation for this task.',
|
|
851
|
+
'agent.openingSteered': 'With your update in mind, {action}',
|
|
837
852
|
'agent.generating': 'Generating {tool}',
|
|
838
853
|
'agent.executing': 'Running {tool}',
|
|
839
854
|
'agent.retrying': 'Connection lost, retrying in {seconds}s (attempt {attempt})',
|
|
@@ -868,6 +883,7 @@ const en = {
|
|
|
868
883
|
'command.executionFailed': 'Execution failed: {message}',
|
|
869
884
|
'command.exitCode': '[exit code {code}]',
|
|
870
885
|
'command.timedOut': '[timed out and terminated]',
|
|
886
|
+
'command.encodingHint': '[Output contains frequent NUL or replacement characters. Check the delimiter or encoding if you need to interpret those bytes.]',
|
|
871
887
|
'repl.errorLabel': '[Error]',
|
|
872
888
|
'repl.visionUnsupported': 'The current model, {model}, does not support vision input.',
|
|
873
889
|
'repl.originalError': 'Original: {message}',
|
package/dist/llm/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { getPlanDisabledTools, getProfileDisabledTools } from '../tools/constant
|
|
|
4
4
|
import { imageSizeFromDataUrl } from '../attachments/image.js';
|
|
5
5
|
import { ThinkTagFilter } from './think-filter.js';
|
|
6
6
|
import { sanitizeToolSchemas } from './tool-schema.js';
|
|
7
|
-
import { sanitizeAssistantContent, sanitizeContentParts } from './message-shape.js';
|
|
7
|
+
import { prepareReasoningContent, sanitizeAssistantContent, sanitizeContentParts } from './message-shape.js';
|
|
8
8
|
import { isMarkedStreamInterrupted } from './stream-interrupt.js';
|
|
9
9
|
import { defaultAnthropicFetch, anthropicChatOnce } from './providers/anthropic.js';
|
|
10
10
|
import { vertexChatOnce } from './providers/vertex.js';
|
|
@@ -440,6 +440,15 @@ function logRetry(attempt, err, waitMs) {
|
|
|
440
440
|
export function __setChatCreateImpl(impl) {
|
|
441
441
|
defaultClientState.openAICreateImpl = impl;
|
|
442
442
|
}
|
|
443
|
+
/** 仅 DeepSeek 官方端点要求 tools 请求回传 reasoning_content;代理与 DashScope 不套用。 */
|
|
444
|
+
function isOfficialDeepSeekEndpoint(baseURL) {
|
|
445
|
+
try {
|
|
446
|
+
return /(?:^|\.)deepseek\.com$/i.test(new URL(baseURL).hostname);
|
|
447
|
+
}
|
|
448
|
+
catch {
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
443
452
|
/**
|
|
444
453
|
* 工具 schema 保持稳定数组引用,再在 MCP 发现或扩展变动后原地刷新;
|
|
445
454
|
* 这样 chat()/预算模块的默认参数不会继续指向陈旧的顶层快照。
|
|
@@ -714,6 +723,7 @@ async function chatOnce(messages, handlers, signal, toolsOverride, runtime = def
|
|
|
714
723
|
provider: runtimeConfig.provider,
|
|
715
724
|
model: runtime.getModel(),
|
|
716
725
|
maxTokens: runtimeConfig.maxTokens,
|
|
726
|
+
baseURL: runtimeConfig.baseURL,
|
|
717
727
|
// 仅当激活预设来自目录且对应当前模型时携带,否则走正则兜底。
|
|
718
728
|
...(activePreset && activePreset.catalogProvider && activePreset.model === runtime.getModel()
|
|
719
729
|
? {
|
|
@@ -727,7 +737,10 @@ async function chatOnce(messages, handlers, signal, toolsOverride, runtime = def
|
|
|
727
737
|
});
|
|
728
738
|
const stream = await create({
|
|
729
739
|
model: runtime.getModel(),
|
|
730
|
-
messages: sanitizeContentParts(sanitizeAssistantContent(normalizeImageDetail(messages))),
|
|
740
|
+
messages: prepareReasoningContent(sanitizeContentParts(sanitizeAssistantContent(normalizeImageDetail(messages))),
|
|
741
|
+
// DeepSeek 官方 thinking 默认开启;带工具时必须回传完整历史思考,auto 也要保留。
|
|
742
|
+
// DashScope 与其它 OpenAI 兼容端点不认这个扩展字段,统一剥离。
|
|
743
|
+
activeTools.length > 0 && effort !== 'off' && isOfficialDeepSeekEndpoint(runtimeConfig.baseURL)),
|
|
731
744
|
stream: true,
|
|
732
745
|
// 空工具表(如摘要请求)不发 tools 字段——部分网关拒绝空数组。
|
|
733
746
|
...(activeTools.length > 0
|
|
@@ -745,6 +758,7 @@ async function chatOnce(messages, handlers, signal, toolsOverride, runtime = def
|
|
|
745
758
|
// content 内嵌 think 标签由独立增量状态机过滤。它只暂存“可能组成标签”的后缀,
|
|
746
759
|
// 因而既能覆盖标签任意位置跨 chunk,也不会让普通正文固定延迟数个字符。
|
|
747
760
|
let visibleContent = '';
|
|
761
|
+
let reasoningContent = '';
|
|
748
762
|
let consumedAny = false;
|
|
749
763
|
const thinkFilter = new ThinkTagFilter();
|
|
750
764
|
let usage;
|
|
@@ -803,6 +817,12 @@ async function chatOnce(messages, handlers, signal, toolsOverride, runtime = def
|
|
|
803
817
|
}
|
|
804
818
|
if (!delta)
|
|
805
819
|
continue; // 末尾 usage-only chunk 等无 delta
|
|
820
|
+
if (delta.reasoning_content) {
|
|
821
|
+
reasoningContent += delta.reasoning_content;
|
|
822
|
+
// reasoning_content 同样计费,但不作为可见正文或触发 onText。
|
|
823
|
+
if (handlers.onProgress)
|
|
824
|
+
countLive(delta.reasoning_content);
|
|
825
|
+
}
|
|
806
826
|
if (delta.content) {
|
|
807
827
|
if (handlers.onProgress)
|
|
808
828
|
countLive(delta.content);
|
|
@@ -850,6 +870,7 @@ async function chatOnce(messages, handlers, signal, toolsOverride, runtime = def
|
|
|
850
870
|
return {
|
|
851
871
|
content: consumedAny ? visibleContent : null,
|
|
852
872
|
toolCalls,
|
|
873
|
+
...(reasoningContent ? { reasoningContent } : {}),
|
|
853
874
|
usage,
|
|
854
875
|
finishReason,
|
|
855
876
|
};
|
|
@@ -963,7 +984,8 @@ const messageTokensCache = new WeakMap();
|
|
|
963
984
|
function messageSignature(m) {
|
|
964
985
|
const c = m.content;
|
|
965
986
|
const tcs = m.tool_calls;
|
|
966
|
-
|
|
987
|
+
const reasoning = m.role === 'assistant' ? m.reasoning_content : undefined;
|
|
988
|
+
return `${m.role ?? ''}|${typeof c === 'string' ? c.length : -1}|${tcs ? 1 : 0}|${reasoning?.length ?? 0}`;
|
|
967
989
|
}
|
|
968
990
|
/** 估算单条消息的 token 数:结构开销 + content + tool_calls 参数。内容签名命中则复用上次结果。 */
|
|
969
991
|
export function messageTokens(m) {
|
|
@@ -979,6 +1001,8 @@ export function messageTokens(m) {
|
|
|
979
1001
|
else if (role === 'tool')
|
|
980
1002
|
structural = 6;
|
|
981
1003
|
let body = contentTokens(m.content);
|
|
1004
|
+
if (m.role === 'assistant' && m.reasoning_content)
|
|
1005
|
+
body += estimateTokens(m.reasoning_content);
|
|
982
1006
|
const tcs = m.tool_calls;
|
|
983
1007
|
if (tcs) {
|
|
984
1008
|
for (const tc of tcs)
|
|
@@ -67,3 +67,21 @@ export function sanitizeAssistantContent(messages) {
|
|
|
67
67
|
});
|
|
68
68
|
return changed ? next : messages;
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* DeepSeek 官方 thinking + tools 要求所有历史 assistant 轮原样回传 reasoning_content。
|
|
72
|
+
* 字段仍完整保存在会话中;其它 provider / 无工具请求只在 transport 的副本上剥离。
|
|
73
|
+
* 无需改写时复用原数组和消息引用,保持长会话的前缀缓存稳定。
|
|
74
|
+
*/
|
|
75
|
+
export function prepareReasoningContent(messages, preserve) {
|
|
76
|
+
if (preserve)
|
|
77
|
+
return messages;
|
|
78
|
+
let changed = false;
|
|
79
|
+
const next = messages.map((message) => {
|
|
80
|
+
if (message.role !== 'assistant' || message.reasoning_content === undefined)
|
|
81
|
+
return message;
|
|
82
|
+
const { reasoning_content: _reasoning, ...clean } = message;
|
|
83
|
+
changed = true;
|
|
84
|
+
return clean;
|
|
85
|
+
});
|
|
86
|
+
return changed ? next : messages;
|
|
87
|
+
}
|
package/dist/llm/reasoning.js
CHANGED
|
@@ -68,6 +68,7 @@ export function recognizesReasoning(target) {
|
|
|
68
68
|
/gpt-?5/.test(m) ||
|
|
69
69
|
/qwen[-_]?3/.test(m) ||
|
|
70
70
|
/deepseek[-_]?r1/.test(m) ||
|
|
71
|
+
/deepseek[-_]?(?:v4|flash)/.test(m) ||
|
|
71
72
|
/glm[-_]?4[.-]?[56]/.test(m) ||
|
|
72
73
|
/glm[-_]?5/.test(m) ||
|
|
73
74
|
/doubao[-_]?seed/.test(m));
|
|
@@ -81,6 +82,9 @@ export function resolveReasoningParams(effort, target) {
|
|
|
81
82
|
// Gemini/Vertex provider 在 buildGeminiRequest 内直接生成 thinkingConfig;这里不应再注入 OpenAI 方言。
|
|
82
83
|
if (target.provider === 'google')
|
|
83
84
|
return {};
|
|
85
|
+
// 目录显式声明不支持思考是硬边界,不能因型号名命中正则又悄悄开启。
|
|
86
|
+
if (target.catalogReasoning === false)
|
|
87
|
+
return {};
|
|
84
88
|
// 目录优先:带 catalogProviderId 时按目录能力+厂商方言产出。
|
|
85
89
|
// 注意 anthropic 路径的思考在 anthropic provider 内仍走它自己的 target.provider,
|
|
86
90
|
// 目录只对 OpenAI 兼容路径有意义;Anthropic 官方协议继续走下方既有分支。
|
|
@@ -133,6 +137,19 @@ export function resolveReasoningParams(effort, target) {
|
|
|
133
137
|
return { thinking: { type: 'disabled' } };
|
|
134
138
|
return { thinking: { type: 'enabled' } };
|
|
135
139
|
}
|
|
140
|
+
// DeepSeek V4 / Flash 是混合思考模型。官方端点用 thinking + reasoning_effort;
|
|
141
|
+
// DashScope 兼容端点用 enable_thinking + thinking_budget(两种写法均已实测,按端点选厂商原生方言)。
|
|
142
|
+
if (/deepseek[-_]?(?:v4|flash)/.test(m)) {
|
|
143
|
+
if (/dashscope(?:-[a-z]+)?\.aliyuncs\.com/i.test(target.baseURL ?? '')) {
|
|
144
|
+
if (effort === 'off')
|
|
145
|
+
return { enable_thinking: false };
|
|
146
|
+
return { enable_thinking: true, thinking_budget: THINK_BUDGET[effort] };
|
|
147
|
+
}
|
|
148
|
+
if (effort === 'off')
|
|
149
|
+
return { thinking: { type: 'disabled' } };
|
|
150
|
+
// DeepSeek 官方只有 low/high/max 三档,归一化 medium 映射到 high。
|
|
151
|
+
return { thinking: { type: 'enabled' }, reasoning_effort: effort === 'low' ? 'low' : 'high' };
|
|
152
|
+
}
|
|
136
153
|
// DeepSeek-R1:无开关参数,任何档位都不下发。
|
|
137
154
|
if (/deepseek[-_]?r1/.test(m))
|
|
138
155
|
return {};
|
|
@@ -10,7 +10,7 @@ const PROVIDER_DIALECT = {
|
|
|
10
10
|
alibaba: 'qwen',
|
|
11
11
|
zhipuai: 'thinking-toggle',
|
|
12
12
|
volcengine: 'thinking-toggle',
|
|
13
|
-
deepseek: '
|
|
13
|
+
deepseek: 'deepseek',
|
|
14
14
|
moonshotai: 'thinking-toggle',
|
|
15
15
|
};
|
|
16
16
|
export function dialectForProvider(catalogProviderId) {
|
|
@@ -20,7 +20,7 @@ export function dialectForProvider(catalogProviderId) {
|
|
|
20
20
|
function pickEffortValue(effort, values, off) {
|
|
21
21
|
const v = values.map((s) => s.toLowerCase());
|
|
22
22
|
const priorities = off
|
|
23
|
-
? { any: ['off', 'disabled', 'minimal', 'low'] }
|
|
23
|
+
? { any: ['off', 'disabled', 'none', 'minimal', 'low'] }
|
|
24
24
|
: effort === 'low'
|
|
25
25
|
? { any: ['low', 'minimal'] }
|
|
26
26
|
: effort === 'medium'
|
|
@@ -72,6 +72,23 @@ export function paramsFromCatalog(input) {
|
|
|
72
72
|
// 无 effort/toggle 元数据但已知是 OpenAI 方言:直接下发归一化档位(off→low)。
|
|
73
73
|
return { reasoning_effort: isOff ? 'low' : input.effort };
|
|
74
74
|
}
|
|
75
|
+
// ── DeepSeek:thinking 开关 + 官方 effort 档位 ──
|
|
76
|
+
if (dialect === 'deepseek') {
|
|
77
|
+
if (isOff)
|
|
78
|
+
return { thinking: { type: 'disabled' } };
|
|
79
|
+
const base = { thinking: { type: 'enabled' } };
|
|
80
|
+
if (effortOpt?.values?.length) {
|
|
81
|
+
// DeepSeek 官方只有 low/high/max 时没有 medium,统一映射到 high。
|
|
82
|
+
base.reasoning_effort =
|
|
83
|
+
input.effort === 'medium' && !effortOpt.values.some((value) => /^(medium|mid)$/i.test(value))
|
|
84
|
+
? 'high'
|
|
85
|
+
: pickEffortValue(input.effort, effortOpt.values, false);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
base.reasoning_effort = input.effort === 'low' ? 'low' : 'high';
|
|
89
|
+
}
|
|
90
|
+
return base;
|
|
91
|
+
}
|
|
75
92
|
// ── thinking-toggle 方言 ──
|
|
76
93
|
if (dialect === 'thinking-toggle') {
|
|
77
94
|
if (effortOpt?.values && effortOpt.values.length > 0 && !isOff) {
|
|
@@ -243,7 +243,13 @@ export class LaneReplExecutor {
|
|
|
243
243
|
if (this.cancelled.has(process_.key) || process_.dead)
|
|
244
244
|
this.settle(process_, null);
|
|
245
245
|
}, this.pollMs);
|
|
246
|
-
|
|
246
|
+
// ⚠ 这里**不能** unref:`result` 只能由这个 interval 结算,而等待一轮是"有活在跑",
|
|
247
|
+
// 进程就该活着。unref 之后一旦事件循环没有别的 ref 句柄,Node 会直接排空 ——
|
|
248
|
+
// 这个 Promise 永不 resolve,`node --test` 报
|
|
249
|
+
// "Promise resolution is still pending but the event loop has already resolved"
|
|
250
|
+
// 并把它记成 cancelledByParent(CI 从 1.9.5 起就是被这条连锁拖垮的:本地 Windows
|
|
251
|
+
// 因为 Go 测试等残留 ref 句柄恰好托住了循环,所以一直没复现)。
|
|
252
|
+
// 对照:同文件的 waitReady 用 `await sleep()`(ref 句柄),语义一致。
|
|
247
253
|
try {
|
|
248
254
|
return await result;
|
|
249
255
|
}
|
|
@@ -21,7 +21,7 @@ import { ui } from '../ui/theme.js';
|
|
|
21
21
|
import * as layout from '../ui/layout.js';
|
|
22
22
|
import { padEndDisplay, summarizeToolCall, truncateDisplay } from '../ui/render.js';
|
|
23
23
|
import { promptWithSlashMenu } from '../ui/prompt.js';
|
|
24
|
-
import { clearRunningInput,
|
|
24
|
+
import { clearRunningInput, getRunningInput, startRunningListener, stopRunningListener, waitForRunningComposer, } from '../repl/running-input.js';
|
|
25
25
|
import { collectQueryHistory } from '../session/query-history.js';
|
|
26
26
|
import { SupervisorRuntime } from './supervisor.js';
|
|
27
27
|
import { terminalAutoOpenEnabled } from './terminal.js';
|
|
@@ -277,57 +277,38 @@ export async function runSupervisorChat(options) {
|
|
|
277
277
|
// 运行态打开的 Ctrl+G 面板可能在本轮结束时仍开着:等它关闭再进 INPUT 态,
|
|
278
278
|
// 否则两个 keypress 监听抢键(面板内容随后经 getRunningInput 预填)。
|
|
279
279
|
await waitForRunningComposer();
|
|
280
|
-
// 运行中按 Enter 排队的句子:agent 一结束就自动发送,跳过输入框(入队那一刻即已确认)。
|
|
281
|
-
// 斜杠命令不静默执行(否则排队 /exit 会在用户没看着时触发),改为填回输入框等确认。
|
|
282
|
-
const queued = consumeQueuedTurn();
|
|
283
280
|
let input = null;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
//
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
281
|
+
if (hasSubmitted)
|
|
282
|
+
layout.normalizeInputBoundary();
|
|
283
|
+
layout.enterInputMode('supervisor 待命');
|
|
284
|
+
try {
|
|
285
|
+
input = await promptWithSlashMenu({
|
|
286
|
+
prompt: PROMPT,
|
|
287
|
+
commands: supervisorCommands(),
|
|
288
|
+
history: () => collectQueryHistory(queryHistory).map((entry) => entry.text),
|
|
289
|
+
// 第二输入源(静默唤醒):只在**空输入框**里取,人正在打字时绝不抢。
|
|
290
|
+
// 排队的多条合并成一条——五个 Run 同时跑完,合成一次查收比五次清楚。
|
|
291
|
+
takeExternalTurn: () => {
|
|
292
|
+
if (wakeQueue.length === 0)
|
|
293
|
+
return null;
|
|
294
|
+
const batch = wakeQueue.splice(0, wakeQueue.length);
|
|
295
|
+
wakeText = batch.join('\n---\n');
|
|
296
|
+
return wakeText;
|
|
297
|
+
},
|
|
298
|
+
// 预填:命令预填优先,否则使用运行中的草稿。
|
|
299
|
+
...(pendingPrefill
|
|
300
|
+
? { initialLines: pendingPrefill }
|
|
301
|
+
: getRunningInput()
|
|
302
|
+
? { initialLines: [getRunningInput()] }
|
|
303
|
+
: {}),
|
|
304
|
+
});
|
|
297
305
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
layout.normalizeInputBoundary();
|
|
301
|
-
layout.enterInputMode('supervisor 待命');
|
|
302
|
-
try {
|
|
303
|
-
input = await promptWithSlashMenu({
|
|
304
|
-
prompt: PROMPT,
|
|
305
|
-
commands: supervisorCommands(),
|
|
306
|
-
history: () => collectQueryHistory(queryHistory).map((entry) => entry.text),
|
|
307
|
-
// 第二输入源(静默唤醒):只在**空输入框**里取,人正在打字时绝不抢。
|
|
308
|
-
// 排队的多条合并成一条——五个 Run 同时跑完,合成一次查收比五次清楚。
|
|
309
|
-
takeExternalTurn: () => {
|
|
310
|
-
if (wakeQueue.length === 0)
|
|
311
|
-
return null;
|
|
312
|
-
const batch = wakeQueue.splice(0, wakeQueue.length);
|
|
313
|
-
wakeText = batch.join('\n---\n');
|
|
314
|
-
return wakeText;
|
|
315
|
-
},
|
|
316
|
-
// 预填:待确认的排队斜杠命令优先,否则运行中打的字。
|
|
317
|
-
...(pendingPrefill
|
|
318
|
-
? { initialLines: pendingPrefill }
|
|
319
|
-
: getRunningInput()
|
|
320
|
-
? { initialLines: [getRunningInput()] }
|
|
321
|
-
: {}),
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
catch {
|
|
325
|
-
break; // Ctrl+C / Ctrl+D
|
|
326
|
-
}
|
|
327
|
-
pendingPrefill = null;
|
|
328
|
-
// 预填已消费:不清会一直重填同一段(主 REPL 同款约定)。
|
|
329
|
-
clearRunningInput();
|
|
306
|
+
catch {
|
|
307
|
+
break; // Ctrl+C / Ctrl+D
|
|
330
308
|
}
|
|
309
|
+
pendingPrefill = null;
|
|
310
|
+
// 预填已消费:不清会一直重填同一段(主 REPL 同款约定)。
|
|
311
|
+
clearRunningInput();
|
|
331
312
|
if (input === null)
|
|
332
313
|
break;
|
|
333
314
|
const line = input.join('\n').trim();
|
|
@@ -15,7 +15,6 @@ import { config } from '../../config/index.js';
|
|
|
15
15
|
import { updateConfigKey } from '../../config/file.js';
|
|
16
16
|
import { promptThemePicker } from '../../ui/prompt.js';
|
|
17
17
|
import { themeDescription } from '../commands.js';
|
|
18
|
-
import { renderHistory } from '../message-format.js';
|
|
19
18
|
import { unhandled, next } from './types.js';
|
|
20
19
|
export const appearanceCommands = [
|
|
21
20
|
async (ctx) => {
|
|
@@ -57,7 +56,7 @@ export const appearanceCommands = [
|
|
|
57
56
|
ctx.refreshStatusBase(ctx.history);
|
|
58
57
|
layout.clearContent();
|
|
59
58
|
if (ctx.history.some((m) => m.role === 'user')) {
|
|
60
|
-
|
|
59
|
+
ctx.renderTranscript();
|
|
61
60
|
}
|
|
62
61
|
else {
|
|
63
62
|
layout.writeBanner(bannerLines(ctx.banner()));
|
|
@@ -15,6 +15,7 @@ import { t } from '../../i18n/index.js';
|
|
|
15
15
|
import { appendCurrentSessionRuntimeEvent, hashTraceValue } from '../../session/index.js';
|
|
16
16
|
import { startRunningListener, stopRunningListener } from '../running-input.js';
|
|
17
17
|
import { unhandled, next } from './types.js';
|
|
18
|
+
import { createTerminalTranscript } from '../../session/terminal-transcript.js';
|
|
18
19
|
export const compactCommands = [
|
|
19
20
|
async (ctx) => {
|
|
20
21
|
const { line } = ctx;
|
|
@@ -35,6 +36,7 @@ export const compactCommands = [
|
|
|
35
36
|
// 走调度器路径:与自动每步压缩完全一致——先跑零成本清理(cold tools 优先),最后才 LLM 摘要。
|
|
36
37
|
// focus 透传到 compact_history action 的 LLM 摘要 prompt。
|
|
37
38
|
// 返回 SchedulerRunLog 给 UI 显示决策;退化路径(开关关时)在 manualCompact 内部走 compactHistory。
|
|
39
|
+
const beforeReplay = createTerminalTranscript(ctx.history).base;
|
|
38
40
|
const log = await (async () => {
|
|
39
41
|
const signal = startRunningListener(t('running.compacting'));
|
|
40
42
|
try {
|
|
@@ -53,6 +55,8 @@ export const compactCommands = [
|
|
|
53
55
|
});
|
|
54
56
|
if (!log)
|
|
55
57
|
return next();
|
|
58
|
+
if (log.historyMutation !== 'none')
|
|
59
|
+
ctx.recordCompaction(beforeReplay);
|
|
56
60
|
const d = log.compactDetail;
|
|
57
61
|
appendCurrentSessionRuntimeEvent('compact', {
|
|
58
62
|
source: 'manual',
|
|
@@ -12,7 +12,6 @@ import { writeConfigKeys } from '../../config/file.js';
|
|
|
12
12
|
import { savePreset, setActivePresetName } from '../../config/presets.js';
|
|
13
13
|
import { reconfigureClient } from '../../llm/index.js';
|
|
14
14
|
import { promptIntervention } from '../../ui/intervention.js';
|
|
15
|
-
import { renderHistory } from '../message-format.js';
|
|
16
15
|
import { refreshCatalog } from '../../models/catalog.js';
|
|
17
16
|
import { buildPreset, defaultPresetName, preferredKeyEnvName, resolveApiKey } from '../../models/map-preset.js';
|
|
18
17
|
/** 应用预设到 config + 落 config 文件 + 重建 client + 重显。 */
|
|
@@ -26,7 +25,8 @@ export function applyPresetConfig(ctx, p) {
|
|
|
26
25
|
// 预设带值用值;不带显式清除(否则旧 MAX_TOKENS 残留会盖过新预设)。
|
|
27
26
|
maxTokens: p.maxTokens ?? null,
|
|
28
27
|
anthropicPromptCache: p.anthropicPromptCache,
|
|
29
|
-
|
|
28
|
+
// 预设缺省必须显式回 auto,不能残留上一个模型或全局设置的高档思考。
|
|
29
|
+
reasoningEffort: p.reasoningEffort ?? 'auto',
|
|
30
30
|
});
|
|
31
31
|
writeConfigKeys({
|
|
32
32
|
LLM_PROVIDER: p.provider,
|
|
@@ -35,6 +35,7 @@ export function applyPresetConfig(ctx, p) {
|
|
|
35
35
|
LLM_MODEL: p.model,
|
|
36
36
|
CONTEXT_WINDOW_TOKENS: String(p.contextWindow),
|
|
37
37
|
MAX_TOKENS: p.maxTokens ? String(p.maxTokens) : null,
|
|
38
|
+
REASONING_EFFORT: p.reasoningEffort ?? 'auto',
|
|
38
39
|
ANTHROPIC_PROMPT_CACHE: p.anthropicPromptCache ? 'true' : 'false',
|
|
39
40
|
});
|
|
40
41
|
// 关键不变量:应用预设即激活——必须同步 .active 指针。否则重启时旧激活预设的优先级
|
|
@@ -49,7 +50,7 @@ export function applyPresetConfig(ctx, p) {
|
|
|
49
50
|
ctx.refreshStatusBase(ctx.history);
|
|
50
51
|
layout.clearContent();
|
|
51
52
|
if (ctx.history.some((m) => m.role === 'user'))
|
|
52
|
-
|
|
53
|
+
ctx.renderTranscript();
|
|
53
54
|
else
|
|
54
55
|
layout.writeBanner(bannerLines(ctx.banner()));
|
|
55
56
|
}
|
|
@@ -21,7 +21,6 @@ import { deletePreset, getPreset, isValidPresetName, listPresets, savePreset, se
|
|
|
21
21
|
import { reconfigureClient } from '../../llm/index.js';
|
|
22
22
|
import { recognizesReasoning } from '../../llm/reasoning.js';
|
|
23
23
|
import { promptIntervention } from '../../ui/intervention.js';
|
|
24
|
-
import { renderHistory } from '../message-format.js';
|
|
25
24
|
import { MODEL_PRESETS, maskKey } from '../commands.js';
|
|
26
25
|
import { unhandled, next } from './types.js';
|
|
27
26
|
/** 决定自动存的预设名:协议、缓存配置和连接四元组都一致时不重复存。 */
|
|
@@ -101,7 +100,7 @@ export const modelCommands = [
|
|
|
101
100
|
ctx.refreshStatusBase(history);
|
|
102
101
|
layout.clearContent();
|
|
103
102
|
if (history.some((m) => m.role === 'user')) {
|
|
104
|
-
|
|
103
|
+
ctx.renderTranscript();
|
|
105
104
|
}
|
|
106
105
|
else {
|
|
107
106
|
layout.writeBanner(bannerLines(ctx.banner()));
|
|
@@ -454,7 +453,7 @@ export const modelCommands = [
|
|
|
454
453
|
ctx.refreshStatusBase(history);
|
|
455
454
|
layout.clearContent();
|
|
456
455
|
if (history.some((m) => m.role === 'user')) {
|
|
457
|
-
|
|
456
|
+
ctx.renderTranscript();
|
|
458
457
|
}
|
|
459
458
|
else {
|
|
460
459
|
layout.writeBanner(bannerLines(ctx.banner()));
|
|
@@ -138,7 +138,7 @@ export function queryHistoryFromMessages(messages) {
|
|
|
138
138
|
* 用 batch.writeSummaryOnly 出单行摘要(与实时 runAgent 同一渲染器,UI 一致)。
|
|
139
139
|
* 回放默认全折叠;用户可鼠标点击摘要行展开(由 BatchRenderer 接管,见 ui/batch.ts)。
|
|
140
140
|
*/
|
|
141
|
-
export function renderHistory(history) {
|
|
141
|
+
export function renderHistory(history, useLiveAttachments = true) {
|
|
142
142
|
const idToEntry = new Map();
|
|
143
143
|
const idToArgs = new Map(); // tool_call id → 原始参数 JSON,供重建 mutation diff
|
|
144
144
|
// 普通工具可跨 assistant 步聚合;mutation 各自占一个 group,并切断前后普通工具。
|
|
@@ -158,18 +158,18 @@ export function renderHistory(history) {
|
|
|
158
158
|
for (let idx = 0; idx < history.length; idx++) {
|
|
159
159
|
const m = history[idx];
|
|
160
160
|
if (m.role === 'system') {
|
|
161
|
-
//
|
|
161
|
+
// 旧会话有摘要时显示摘要正文;展示记录中的无正文标记只提示模型做过压缩。
|
|
162
162
|
const body = textOf(m.content);
|
|
163
163
|
if (idx > 0 && body.startsWith(SUMMARY_MARKER)) {
|
|
164
164
|
flushBatch();
|
|
165
165
|
layout.normalizeMutationBoundary();
|
|
166
|
-
layout.contentWrite(`${ui.dim}${t('repl.compactedNotice')}${ui.reset}\n\n`);
|
|
167
166
|
const text = body.slice(SUMMARY_MARKER.length).trim();
|
|
167
|
+
layout.contentWrite(`${ui.dim}${t(text ? 'repl.compactedNotice' : 'repl.modelCompacted')}${ui.reset}\n\n`);
|
|
168
168
|
if (text.length > SUMMARY_REPLAY_MAX_CHARS) {
|
|
169
169
|
layout.contentWriteMdOnce(text.slice(0, SUMMARY_REPLAY_MAX_CHARS));
|
|
170
170
|
layout.contentWrite(`${ui.dim}${t('repl.compactedTruncated', { total: text.length, shown: SUMMARY_REPLAY_MAX_CHARS })}${ui.reset}\n`);
|
|
171
171
|
}
|
|
172
|
-
else {
|
|
172
|
+
else if (text) {
|
|
173
173
|
layout.contentWriteMdOnce(text);
|
|
174
174
|
}
|
|
175
175
|
layout.normalizeMutationBoundary();
|
|
@@ -183,7 +183,7 @@ export function renderHistory(history) {
|
|
|
183
183
|
layout.normalizeInputBoundary();
|
|
184
184
|
const lines = textOf(m.content).split('\n');
|
|
185
185
|
layout.contentWrite(formatUserMessage(lines));
|
|
186
|
-
const atts = messageAttachments.get(idx);
|
|
186
|
+
const atts = useLiveAttachments ? messageAttachments.get(idx) : undefined;
|
|
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`);
|
|
@@ -211,7 +211,8 @@ export function renderHistory(history) {
|
|
|
211
211
|
if (p && typeof p === 'object' && p.type === 'image_url') {
|
|
212
212
|
const url = p.image_url?.url ?? '';
|
|
213
213
|
const mime = url.startsWith('data:') ? url.slice(5, url.indexOf(';')) : 'image';
|
|
214
|
-
|
|
214
|
+
const name = p.name;
|
|
215
|
+
layout.contentWrite(` ${ui.dim}📷 ${typeof name === 'string' && name ? name : mime}${ui.reset}\n`);
|
|
215
216
|
fallbackChips++;
|
|
216
217
|
}
|
|
217
218
|
}
|