dsh-plugin-om 0.0.62 → 0.0.64
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 +38 -24
- package/cordis.patch.yml +2 -0
- package/dist/client/OmCompactionCard.d.ts +1 -4
- package/dist/client/OmCompactionCard.d.ts.map +1 -1
- package/dist/client/definition.d.ts +1 -1
- package/dist/client/eval-model-panel.d.ts +17 -2
- package/dist/client/eval-model-panel.d.ts.map +1 -1
- package/dist/client/eval-model-register.d.ts +5 -2
- package/dist/client/eval-model-register.d.ts.map +1 -1
- package/dist/client/index.d.ts +2 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/locales.d.ts +6 -18
- package/dist/client/locales.d.ts.map +1 -1
- package/dist/client/om-config-controller.d.ts +3 -7
- package/dist/client/om-config-controller.d.ts.map +1 -1
- package/dist/client.js +115 -550
- package/dist/client.js.map +1 -1
- package/dist/compaction-eval/index.d.ts +8 -0
- package/dist/compaction-eval/index.d.ts.map +1 -0
- package/dist/compaction-eval/index.mjs +206 -0
- package/dist/compaction-eval-command.d.ts +6 -3
- package/dist/compaction-eval-command.d.ts.map +1 -1
- package/dist/compress.d.ts +1 -1
- package/dist/compress.d.ts.map +1 -1
- package/dist/config.d.ts +3 -11
- package/dist/config.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +38 -549
- package/dist/skill/compaction-eval/SKILL.md +2 -1
- package/dist/skill/compaction-eval/scripts/compress.mjs +21 -21
- package/dist/skill/compaction-eval/scripts/view.mjs +77 -79
- package/dist/system-reminder.d.ts +2 -2
- package/dist/system-reminder.d.ts.map +1 -1
- package/dist/utils-D-cEbiTF.mjs +89 -0
- package/locale/compaction-eval/en.json +6 -0
- package/locale/compaction-eval/zh.json +6 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +12 -1
- package/dist/client/OmRecompressMenu.d.ts +0 -11
- package/dist/client/OmRecompressMenu.d.ts.map +0 -1
- package/dist/client/recompress-inject.d.ts +0 -9
- package/dist/client/recompress-inject.d.ts.map +0 -1
- package/dist/client/recompress-run.d.ts +0 -94
- package/dist/client/recompress-run.d.ts.map +0 -1
- package/dist/recompress-gate.d.ts +0 -11
- package/dist/recompress-gate.d.ts.map +0 -1
- package/dist/recompress.d.ts +0 -82
- package/dist/recompress.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
|
-
import { brandString } from "@deepseek-ai/dsh-brand";
|
|
1
|
+
import { a as renderMessageText, c as toolArgsJson, i as isRecord$1, l as uuid, n as blocksToText, o as routedTarget, r as isMainSession, s as seqsCharCount, t as appendCdataText } from "./utils-D-cEbiTF.mjs";
|
|
4
2
|
import { CompactionId } from "@deepseek-ai/dsh-compaction";
|
|
5
3
|
import { BlockAssembler, createAssistantMessage, createSystemMessage, createToolResultMessage, createUserMessage, freezeMessage, isAgentLoopRequest, markAgentLoopRequest } from "@deepseek-ai/dsh-llm";
|
|
6
4
|
import { scopeOf } from "@deepseek-ai/dsh-scope";
|
|
@@ -9,288 +7,15 @@ import { renderPrompt } from "@deepseek-ai/dsh-system-prompt";
|
|
|
9
7
|
import { z } from "zod";
|
|
10
8
|
import { SUBAGENT_DESCRIPTOR_VERSION } from "@deepseek-ai/dsh-subagent";
|
|
11
9
|
import Schema from "@deepseek-ai/schemastery";
|
|
10
|
+
import { copyFileSync, existsSync, mkdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
12
11
|
import { homedir } from "node:os";
|
|
13
12
|
import path from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
14
|
import { toJSONSchema } from "zod/v4/core";
|
|
15
15
|
import { AttachmentId } from "@deepseek-ai/dsh-attachment";
|
|
16
16
|
//#region \0rolldown/runtime.js
|
|
17
17
|
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
18
18
|
//#endregion
|
|
19
|
-
//#region src/eval-session-text.ts
|
|
20
|
-
/**
|
|
21
|
-
* /om-compaction-eval 的文本契约:命令名与描述、新会话首条消息、成功文本及其反解。
|
|
22
|
-
* 宿主命令与客户端跳转共用本模块,因此不得引入 Node 专有依赖(客户端 bundle 会内联它)。
|
|
23
|
-
* 导出 EVAL_COMMAND_NAME / EVAL_COMMAND_DESCRIPTION / EvalPromptInput / buildEvalPrompt /
|
|
24
|
-
* evalStartedText / parseEvalSessionId。
|
|
25
|
-
*/
|
|
26
|
-
/** 命令名(无参数,裸调用即执行)。 */
|
|
27
|
-
const EVAL_COMMAND_NAME = "om-compaction-eval";
|
|
28
|
-
/** 命令描述(斜杠菜单与命令目录展示)。 */
|
|
29
|
-
const EVAL_COMMAND_DESCRIPTION = "ai分析OM结果";
|
|
30
|
-
/** 新会话首条消息:只给文档路径与会话标识,评估步骤全部由文档决定。 */
|
|
31
|
-
function buildEvalPrompt(input) {
|
|
32
|
-
const workspaceId = input.workspaceId === void 0 ? "" : ` workspace_id ${input.workspaceId}`;
|
|
33
|
-
return `按照 ${input.docPath} 分析会话。workspace ${input.cwd}${workspaceId} session_id ${input.sessionId}`;
|
|
34
|
-
}
|
|
35
|
-
/** 成功文本前缀;客户端按同一格式反解新会话 id 用于跳转。 */
|
|
36
|
-
const STARTED_PREFIX = "已启动 OM 结果分析会话 ";
|
|
37
|
-
/** 命令成功文本。 */
|
|
38
|
-
function evalStartedText(sessionId) {
|
|
39
|
-
return `${STARTED_PREFIX}${sessionId}`;
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region src/utils.ts
|
|
43
|
-
/** 判断值是否为普通对象(非 null、非数组)。 */
|
|
44
|
-
function isRecord$1(value) {
|
|
45
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
46
|
-
}
|
|
47
|
-
/** 生成 uuid:优先 crypto.randomUUID,回退为时间戳+随机串拼接。 */
|
|
48
|
-
function uuid() {
|
|
49
|
-
const cryptoObj = globalThis.crypto;
|
|
50
|
-
if (cryptoObj && typeof cryptoObj.randomUUID === "function") return cryptoObj.randomUUID();
|
|
51
|
-
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;
|
|
52
|
-
}
|
|
53
|
-
/** 提取 content 数组中的纯文本块(type === 'text' 的 block.text 拼接)。 */
|
|
54
|
-
function blocksToText(blocks) {
|
|
55
|
-
if (!Array.isArray(blocks)) return "";
|
|
56
|
-
const out = [];
|
|
57
|
-
for (const block of blocks) if (isRecord$1(block) && block.type === "text" && typeof block.text === "string") out.push(block.text);
|
|
58
|
-
return out.join("");
|
|
59
|
-
}
|
|
60
|
-
/** 消息内容的字符数:递归计入 text 块与 tool-result 内嵌文本。 */
|
|
61
|
-
function textCharCount(message) {
|
|
62
|
-
if (!message || !Array.isArray(message.content)) return 0;
|
|
63
|
-
let total = 0;
|
|
64
|
-
for (const block of message.content) if (block.type === "text") total += block.text.length;
|
|
65
|
-
else if (block.type === "tool-result") total += blocksToText(block.content).length;
|
|
66
|
-
return total;
|
|
67
|
-
}
|
|
68
|
-
/** 一组表层事件 seq 派生消息的字符数之和(OM 卡片「原始字符」口径)。 */
|
|
69
|
-
function seqsCharCount(session, seqs) {
|
|
70
|
-
const events = session.snapshotEvents();
|
|
71
|
-
return seqs.reduce((total, seq) => {
|
|
72
|
-
const event = events[seq];
|
|
73
|
-
return total + textCharCount(event ? session.deriveEventMessage(event) : null);
|
|
74
|
-
}, 0);
|
|
75
|
-
}
|
|
76
|
-
/** 面向 recall 的完整消息呈现:text 原样;tool-call 展开(参数=代码);tool-result 取文本。 */
|
|
77
|
-
function renderMessageText(message) {
|
|
78
|
-
if (!message || !Array.isArray(message.content)) return "";
|
|
79
|
-
const parts = [];
|
|
80
|
-
for (const block of message.content) if (block.type === "text") parts.push(block.text);
|
|
81
|
-
else if (block.type === "tool-call") parts.push(`[tool-call ${block.name} id=${String(block.id)}]
|
|
82
|
-
${toolArgsJson(block.arguments)}`);
|
|
83
|
-
else if (block.type === "tool-result") parts.push(blocksToText(block.content));
|
|
84
|
-
return parts.join("\n");
|
|
85
|
-
}
|
|
86
|
-
/** 安全 JSON 序列化:序列化失败时退回 String 呈现。 */
|
|
87
|
-
function safeJson(value) {
|
|
88
|
-
try {
|
|
89
|
-
return JSON.stringify(value, null, 2);
|
|
90
|
-
} catch {
|
|
91
|
-
return String(value);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* 工具调用参数的 JSON 文本(CDATA 内保持只有一层 JSON 转义):
|
|
96
|
-
* 字符串参数是模型产出的原始 JSON 串,原样返回(本身即合法 JSON,不再二次序列化);
|
|
97
|
-
* 其余结构 JSON.stringify 序列化一次。
|
|
98
|
-
*/
|
|
99
|
-
function toolArgsJson(args) {
|
|
100
|
-
if (typeof args === "string") return args;
|
|
101
|
-
return safeJson(args);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* 向元素追加 CDATA 正文:正文统一以 CDATA 包裹(逐字原样,不做实体转义)。
|
|
105
|
-
* 正文含 ]]> 时拆为相邻多个 CDATA 段,拼接后逐字还原原文,对读取方透明。
|
|
106
|
-
*/
|
|
107
|
-
function appendCdataText(doc, el, text) {
|
|
108
|
-
const parts = text.split("]]>");
|
|
109
|
-
for (let i = 0; i < parts.length; i += 1) if (i === 0) el.appendChild(doc.createCDATASection(parts[0] ?? ""));
|
|
110
|
-
else {
|
|
111
|
-
el.appendChild(doc.createCDATASection("]]"));
|
|
112
|
-
el.appendChild(doc.createCDATASection(`>${parts[i] ?? ""}`));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
/** 主会话判定:subagent 会话 header.origin === 'subagent'。 */
|
|
116
|
-
function isMainSession(session) {
|
|
117
|
-
return session.header?.origin !== "subagent";
|
|
118
|
-
}
|
|
119
|
-
/** 解析会话路由目标(provider/model),未路由时返回 undefined。 */
|
|
120
|
-
function routedTarget(session) {
|
|
121
|
-
try {
|
|
122
|
-
const config = session.requestHeader()?.config;
|
|
123
|
-
if (config?.provider && config.model) return {
|
|
124
|
-
provider: config.provider,
|
|
125
|
-
model: config.model
|
|
126
|
-
};
|
|
127
|
-
} catch {}
|
|
128
|
-
}
|
|
129
|
-
//#endregion
|
|
130
|
-
//#region src/compaction-eval-command.ts
|
|
131
|
-
/**
|
|
132
|
-
* /om-compaction-eval 命令:在被分析会话所属工作区新建一个会话,由它按随包发布的
|
|
133
|
-
* compaction-eval 文档分析当前会话的 OM 压缩结果,本会话上下文不受影响。
|
|
134
|
-
* 文档路径由本模块自身位置推出:发布产物优先,仓库源码兜底。
|
|
135
|
-
* 新会话的模型与思考等级默认沿用当前会话,可由命令参数 `provider/model [思考等级]` 指定。
|
|
136
|
-
* 导出 skillDocCandidates / skillDocPath / EvalModel / parseEvalModelInput /
|
|
137
|
-
* StartEvalResult / startEvalSession / buildCompactionEvalCommand。
|
|
138
|
-
*/
|
|
139
|
-
const MODEL_USAGE = "用法:/om-compaction-eval [provider/model [思考等级]]";
|
|
140
|
-
/**
|
|
141
|
-
* 解析命令参数 `provider/model [思考等级]`:以第一个 `/` 切分 provider 与 model,空白分隔等级。
|
|
142
|
-
* @returns 无参数时 model 为 undefined(沿用当前会话);格式错误返回用法说明。
|
|
143
|
-
*/
|
|
144
|
-
function parseEvalModelInput(rawInput) {
|
|
145
|
-
const parts = rawInput.split(/\s+/).filter((part) => part !== "");
|
|
146
|
-
if (parts.length === 0) return {
|
|
147
|
-
ok: true,
|
|
148
|
-
model: void 0
|
|
149
|
-
};
|
|
150
|
-
const [route, reasoningEffort] = parts;
|
|
151
|
-
const slash = route?.indexOf("/") ?? -1;
|
|
152
|
-
if (route === void 0 || slash <= 0 || slash === route.length - 1 || parts.length > 2) return {
|
|
153
|
-
ok: false,
|
|
154
|
-
error: MODEL_USAGE
|
|
155
|
-
};
|
|
156
|
-
return {
|
|
157
|
-
ok: true,
|
|
158
|
-
model: {
|
|
159
|
-
provider: route.slice(0, slash),
|
|
160
|
-
model: route.slice(slash + 1),
|
|
161
|
-
...reasoningEffort === void 0 ? {} : { reasoningEffort }
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
/** 当前会话最近一次请求使用的模型与思考等级;尚未请求过时 undefined。 */
|
|
166
|
-
function currentModel(session) {
|
|
167
|
-
try {
|
|
168
|
-
const config = session.requestHeader()?.config;
|
|
169
|
-
if (!config?.provider || !config.model) return void 0;
|
|
170
|
-
return {
|
|
171
|
-
provider: config.provider,
|
|
172
|
-
model: config.model,
|
|
173
|
-
...config.reasoningEffort === void 0 ? {} : { reasoningEffort: config.reasoningEffort }
|
|
174
|
-
};
|
|
175
|
-
} catch {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* skill 文档候选绝对路径,按优先级排列:
|
|
181
|
-
* 1. 发布产物 dist/skill/compaction-eval/SKILL.md(脚本为自包含 .mjs);
|
|
182
|
-
* 2. 仓库源码 .agents/skills/compaction-eval/SKILL.md(开发时 dist 未构建)。
|
|
183
|
-
* @param fromUrl - 入口模块 URL,缺省为本模块(打包后即 dist/index.mjs)。
|
|
184
|
-
*/
|
|
185
|
-
function skillDocCandidates(fromUrl = import.meta.url) {
|
|
186
|
-
return [fileURLToPath(new URL("./skill/compaction-eval/SKILL.md", fromUrl)), fileURLToPath(new URL("../.agents/skills/compaction-eval/SKILL.md", fromUrl))];
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* 第一个存在的 skill 文档路径。
|
|
190
|
-
* @param fromUrl - 入口模块 URL,缺省为本模块。
|
|
191
|
-
* @returns 文档绝对路径;都不存在时 undefined。
|
|
192
|
-
*/
|
|
193
|
-
function skillDocPath(fromUrl = import.meta.url) {
|
|
194
|
-
return skillDocCandidates(fromUrl).find((candidate) => existsSync(candidate));
|
|
195
|
-
}
|
|
196
|
-
/** 当前会话所属工作区 id;宿主无 workspaceRegistry 或会话未归属时 undefined。 */
|
|
197
|
-
function workspaceOf(ctx, sessionId) {
|
|
198
|
-
const registry = ctx.get("workspaceRegistry");
|
|
199
|
-
if (registry === void 0) return void 0;
|
|
200
|
-
return registry.list().find((workspace) => workspace.sessionIds.includes(sessionId))?.id;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* 新建同工作区会话并投递首条消息。
|
|
204
|
-
* 非主会话、会话无 cwd、文档缺失或宿主缺 sessionController 时返回失败且不建会话;
|
|
205
|
-
* 建会话与投递的异常归一为失败原因。
|
|
206
|
-
* @param ctx - 宿主上下文(经 ctx.get 容错读取 sessionController 与 workspaceRegistry)。
|
|
207
|
-
* @param agent - 命令所针对的会话,其 id 与 cwd 决定分析目标与新会话位置。
|
|
208
|
-
* @param signal - 命令取消信号,透传给投递。
|
|
209
|
-
* @param model - 新会话模型;缺省沿用当前会话,当前会话尚未请求过时用宿主默认。
|
|
210
|
-
*/
|
|
211
|
-
async function startEvalSession(ctx, agent, signal, model) {
|
|
212
|
-
const session = agent.session;
|
|
213
|
-
if (!isMainSession(session)) return {
|
|
214
|
-
ok: false,
|
|
215
|
-
error: "OM 结果分析仅支持主会话"
|
|
216
|
-
};
|
|
217
|
-
const cwd = session.header?.cwd;
|
|
218
|
-
if (cwd === void 0 || cwd === "") return {
|
|
219
|
-
ok: false,
|
|
220
|
-
error: "当前会话没有工作区信息"
|
|
221
|
-
};
|
|
222
|
-
const docPath = skillDocPath();
|
|
223
|
-
if (docPath === void 0) return {
|
|
224
|
-
ok: false,
|
|
225
|
-
error: "找不到 compaction-eval 文档"
|
|
226
|
-
};
|
|
227
|
-
const controller = ctx.get("sessionController");
|
|
228
|
-
if (controller === void 0) return {
|
|
229
|
-
ok: false,
|
|
230
|
-
error: "宿主未提供 sessionController 服务"
|
|
231
|
-
};
|
|
232
|
-
const workspaceId = workspaceOf(ctx, session.id);
|
|
233
|
-
const preset = session.header?.agentPreset;
|
|
234
|
-
try {
|
|
235
|
-
const created = await controller.create({
|
|
236
|
-
...workspaceId === void 0 ? { cwd } : { workspaceId },
|
|
237
|
-
...preset === void 0 ? {} : { agentPreset: preset }
|
|
238
|
-
});
|
|
239
|
-
const selected = model ?? currentModel(session);
|
|
240
|
-
if (selected !== void 0) await controller.selectModel({
|
|
241
|
-
sessionId: created.sessionId,
|
|
242
|
-
...selected
|
|
243
|
-
});
|
|
244
|
-
await controller.prompt({
|
|
245
|
-
requestId: brandString(uuid()),
|
|
246
|
-
sessionId: created.sessionId,
|
|
247
|
-
mode: "queue",
|
|
248
|
-
content: [{
|
|
249
|
-
type: "text",
|
|
250
|
-
text: buildEvalPrompt({
|
|
251
|
-
docPath,
|
|
252
|
-
cwd,
|
|
253
|
-
...workspaceId === void 0 ? {} : { workspaceId },
|
|
254
|
-
sessionId: session.id
|
|
255
|
-
})
|
|
256
|
-
}]
|
|
257
|
-
}, signal);
|
|
258
|
-
return {
|
|
259
|
-
ok: true,
|
|
260
|
-
sessionId: created.sessionId,
|
|
261
|
-
text: evalStartedText(created.sessionId)
|
|
262
|
-
};
|
|
263
|
-
} catch (error) {
|
|
264
|
-
return {
|
|
265
|
-
ok: false,
|
|
266
|
-
error: error instanceof Error ? error.message : String(error)
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
/** 构造 /om-compaction-eval 命令定义:可选参数指定新会话的模型与思考等级。 */
|
|
271
|
-
function buildCompactionEvalCommand(ctx) {
|
|
272
|
-
return {
|
|
273
|
-
name: EVAL_COMMAND_NAME,
|
|
274
|
-
description: EVAL_COMMAND_DESCRIPTION,
|
|
275
|
-
input: { hint: "[provider/model [思考等级]]" },
|
|
276
|
-
handler: async ({ agent, rawInput, signal }) => {
|
|
277
|
-
const parsed = parseEvalModelInput(rawInput);
|
|
278
|
-
if (!parsed.ok) return {
|
|
279
|
-
kind: "error",
|
|
280
|
-
text: parsed.error
|
|
281
|
-
};
|
|
282
|
-
const result = await startEvalSession(ctx, agent, signal, parsed.model);
|
|
283
|
-
return result.ok ? {
|
|
284
|
-
kind: "success",
|
|
285
|
-
text: result.text
|
|
286
|
-
} : {
|
|
287
|
-
kind: "error",
|
|
288
|
-
text: result.error
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
//#endregion
|
|
294
19
|
//#region node_modules/.pnpm/@xmldom+xmldom@0.9.11/node_modules/@xmldom/xmldom/lib/conventions.js
|
|
295
20
|
var require_conventions = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
296
21
|
/**
|
|
@@ -8528,10 +8253,6 @@ function formatCompactCount(value) {
|
|
|
8528
8253
|
if (value >= 1e3) return `${trim(value / 1e3)}k`;
|
|
8529
8254
|
return String(value);
|
|
8530
8255
|
}
|
|
8531
|
-
/** 毫秒耗时格式化为一位小数的秒数,如 63.1s。 */
|
|
8532
|
-
function formatSeconds(durationMs) {
|
|
8533
|
-
return `${(durationMs / 1e3).toFixed(1)}s`;
|
|
8534
|
-
}
|
|
8535
8256
|
//#endregion
|
|
8536
8257
|
//#region src/compaction-log.ts
|
|
8537
8258
|
/** 诊断子会话的 descriptor provider(宿主子代理列表识别用)。 */
|
|
@@ -10203,7 +9924,7 @@ function disposeAllReflections() {
|
|
|
10203
9924
|
* om/observe-pending / om/observe-invalidate / om/observe-summary,见 om-event.ts)
|
|
10204
9925
|
* 持久化在会话日志中(重启后从日志恢复);压缩失败保留待定,下个 pre-step 重启任务重试
|
|
10205
9926
|
* - pre-step 先做反思检查(只启动或跳过,不阻塞),再执行观察(压缩主体在后台运行,
|
|
10206
|
-
* pre-step
|
|
9927
|
+
* pre-step 仅在到期结果未就绪时阻塞等待);仅主会话生效;关闭包根行即停用
|
|
10207
9928
|
* - 压缩目标默认跟随会话路由;compressProvider + compressModel 成对配置时覆盖路由
|
|
10208
9929
|
* (成对配置下未路由会话也执行压缩);compressReasoningEffort 配置时压缩前经
|
|
10209
9930
|
* ctx.llm.resolveModelInfo 校验目标模型 reasoning.efforts(按 provider+model 缓存),
|
|
@@ -11097,10 +10818,6 @@ async function observePass(ctx, agent, config, waitCount, target, signal, reason
|
|
|
11097
10818
|
async function maybeCompress(ctx, agent, config, signal) {
|
|
11098
10819
|
const session = agent.session;
|
|
11099
10820
|
const logger = makeLogger(ctx, config.debug);
|
|
11100
|
-
if (!config.omEnabled) {
|
|
11101
|
-
logger.step("omEnabled=false,跳过压缩");
|
|
11102
|
-
return { failed: false };
|
|
11103
|
-
}
|
|
11104
10821
|
const target = compressionTarget(config, session);
|
|
11105
10822
|
if (target === void 0) {
|
|
11106
10823
|
logger.step("会话未路由(无 provider/model)且未配置压缩目标覆盖,跳过压缩");
|
|
@@ -11326,8 +11043,8 @@ function cosineSimilarity(a, b) {
|
|
|
11326
11043
|
//#region src/config.ts
|
|
11327
11044
|
/**
|
|
11328
11045
|
* 插件配置:宿主 Config 严格校验、volatile 引用读取与兼容 YAML 的宽松合并。
|
|
11329
|
-
* 导出 Config / PluginConfig / DEFAULT_CONFIG / currentConfig / resolveConfig
|
|
11330
|
-
*
|
|
11046
|
+
* 导出 Config / PluginConfig / DEFAULT_CONFIG / currentConfig / resolveConfig。
|
|
11047
|
+
* 宽松解析时未知键忽略、非法值回退默认值。
|
|
11331
11048
|
*/
|
|
11332
11049
|
/** 默认配置(冻结对象,resolveConfig 合并的基底;debug 缺省值在解析时按 NODE_ENV 判定)。 */
|
|
11333
11050
|
const DEFAULT_CONFIG = Object.freeze({
|
|
@@ -11335,10 +11052,8 @@ const DEFAULT_CONFIG = Object.freeze({
|
|
|
11335
11052
|
reflectThresholdTokens: 8e4,
|
|
11336
11053
|
compressMaxTokens: void 0,
|
|
11337
11054
|
rateLimitWaitMs: 6e4,
|
|
11338
|
-
recompressConcurrency: 2,
|
|
11339
11055
|
tailMessageCount: 20,
|
|
11340
11056
|
compressSkipReasoning: true,
|
|
11341
|
-
omEnabled: true,
|
|
11342
11057
|
progressReminderEnabled: true,
|
|
11343
11058
|
progressReminderIdleEnabled: false,
|
|
11344
11059
|
progressReminderIdleSteps: 4,
|
|
@@ -11350,36 +11065,42 @@ const DEFAULT_CONFIG = Object.freeze({
|
|
|
11350
11065
|
compressModel: void 0,
|
|
11351
11066
|
compressReasoningEffort: void 0
|
|
11352
11067
|
});
|
|
11068
|
+
/** debug 开关 schema:缺省按 NODE_ENV !== 'production' 判定。 */
|
|
11069
|
+
function debugSchema() {
|
|
11070
|
+
return Schema.boolean().default(process.env.NODE_ENV !== "production").volatile();
|
|
11071
|
+
}
|
|
11353
11072
|
/** 宿主保存时严格校验,所有字段均为稳定 volatile 引用,运行时由 Loader 原地提交。 */
|
|
11354
11073
|
const Config = Schema.object({
|
|
11355
11074
|
observeThresholdTokens: Schema.number().step(1).default(DEFAULT_CONFIG.observeThresholdTokens).volatile(),
|
|
11356
11075
|
reflectThresholdTokens: Schema.number().step(1).default(DEFAULT_CONFIG.reflectThresholdTokens).volatile(),
|
|
11357
11076
|
compressMaxTokens: Schema.number().step(1).volatile(),
|
|
11358
11077
|
rateLimitWaitMs: Schema.number().step(1).default(DEFAULT_CONFIG.rateLimitWaitMs).volatile(),
|
|
11359
|
-
recompressConcurrency: Schema.number().step(1).min(1).default(DEFAULT_CONFIG.recompressConcurrency).volatile(),
|
|
11360
11078
|
tailMessageCount: Schema.number().step(1).default(DEFAULT_CONFIG.tailMessageCount).volatile(),
|
|
11361
11079
|
compressSkipReasoning: Schema.boolean().default(DEFAULT_CONFIG.compressSkipReasoning).volatile(),
|
|
11362
|
-
omEnabled: Schema.boolean().default(DEFAULT_CONFIG.omEnabled).volatile(),
|
|
11363
11080
|
progressReminderEnabled: Schema.boolean().default(DEFAULT_CONFIG.progressReminderEnabled).volatile(),
|
|
11364
11081
|
progressReminderIdleEnabled: Schema.boolean().default(DEFAULT_CONFIG.progressReminderIdleEnabled).volatile(),
|
|
11365
11082
|
progressReminderIdleSteps: Schema.number().step(1).min(1).default(DEFAULT_CONFIG.progressReminderIdleSteps).volatile(),
|
|
11366
11083
|
progressReminderIdleToolCalls: Schema.number().step(1).min(0).default(DEFAULT_CONFIG.progressReminderIdleToolCalls).volatile(),
|
|
11367
|
-
debug:
|
|
11084
|
+
debug: debugSchema(),
|
|
11368
11085
|
semanticRecallEnabled: Schema.boolean().default(DEFAULT_CONFIG.semanticRecallEnabled).volatile(),
|
|
11369
11086
|
modelDir: Schema.string().default(DEFAULT_CONFIG.modelDir).volatile(),
|
|
11370
11087
|
compressProvider: Schema.string().volatile(),
|
|
11371
11088
|
compressModel: Schema.string().volatile(),
|
|
11372
11089
|
compressReasoningEffort: Schema.string().volatile()
|
|
11373
11090
|
}).default({});
|
|
11374
|
-
/**
|
|
11375
|
-
function
|
|
11376
|
-
if (!isRecord$1(config)) return
|
|
11091
|
+
/** 取出 keys 对应的当前值:volatile 引用解开 get(),原始值原样保留;非对象返回 undefined。 */
|
|
11092
|
+
function readVolatile(config, keys) {
|
|
11093
|
+
if (!isRecord$1(config)) return void 0;
|
|
11377
11094
|
const values = {};
|
|
11378
|
-
for (const key of
|
|
11095
|
+
for (const key of keys) {
|
|
11379
11096
|
const value = config[key];
|
|
11380
11097
|
values[key] = isRecord$1(value) && typeof value.get === "function" ? value.get() : value;
|
|
11381
11098
|
}
|
|
11382
|
-
return
|
|
11099
|
+
return values;
|
|
11100
|
+
}
|
|
11101
|
+
/** 解析宿主 volatile 引用中的当前值,也兼容直接传入的原始配置对象。 */
|
|
11102
|
+
function currentConfig(config) {
|
|
11103
|
+
return resolveConfig(readVolatile(config, Object.keys(DEFAULT_CONFIG)) ?? config);
|
|
11383
11104
|
}
|
|
11384
11105
|
/** 数值键校验参数表:键名 + [是否必须为整数, 下限(含)]。 */
|
|
11385
11106
|
const NUMBER_KEYS = [
|
|
@@ -11387,11 +11108,6 @@ const NUMBER_KEYS = [
|
|
|
11387
11108
|
["reflectThresholdTokens", true],
|
|
11388
11109
|
["compressMaxTokens", true],
|
|
11389
11110
|
["rateLimitWaitMs", true],
|
|
11390
|
-
[
|
|
11391
|
-
"recompressConcurrency",
|
|
11392
|
-
true,
|
|
11393
|
-
1
|
|
11394
|
-
],
|
|
11395
11111
|
["tailMessageCount", true],
|
|
11396
11112
|
[
|
|
11397
11113
|
"progressReminderIdleSteps",
|
|
@@ -11404,6 +11120,13 @@ const NUMBER_KEYS = [
|
|
|
11404
11120
|
0
|
|
11405
11121
|
]
|
|
11406
11122
|
];
|
|
11123
|
+
/** 校验数值:有限数,integer 时须为整数,且不小于 min;不合法返回 undefined。 */
|
|
11124
|
+
function resolveNumber(raw, integer, min) {
|
|
11125
|
+
if (typeof raw !== "number" || !Number.isFinite(raw)) return void 0;
|
|
11126
|
+
if (integer && !Number.isInteger(raw)) return void 0;
|
|
11127
|
+
if (min !== void 0 && raw < min) return void 0;
|
|
11128
|
+
return raw;
|
|
11129
|
+
}
|
|
11407
11130
|
/** 归一化原始配置输入:缺省 / null / 空串 / 非对象视为空对象。 */
|
|
11408
11131
|
function normalizeConfigInput(raw) {
|
|
11409
11132
|
if (raw === void 0 || raw === null) return {};
|
|
@@ -11418,6 +11141,10 @@ function resolveBoolean(raw, defaultValue) {
|
|
|
11418
11141
|
if (typeof raw === "boolean") return raw;
|
|
11419
11142
|
return defaultValue;
|
|
11420
11143
|
}
|
|
11144
|
+
/** 解析 debug 开关:非 boolean 回退 NODE_ENV !== 'production'。 */
|
|
11145
|
+
function resolveDebug(raw) {
|
|
11146
|
+
return resolveBoolean(raw, process.env.NODE_ENV !== "production");
|
|
11147
|
+
}
|
|
11421
11148
|
/** 解析字符串配置值:非空字符串才生效,缺省 / null / 空白串 / 非字符串回退 undefined。 */
|
|
11422
11149
|
function resolveOptionalString(raw) {
|
|
11423
11150
|
if (typeof raw === "string" && raw.trim() !== "") return raw;
|
|
@@ -11427,19 +11154,13 @@ function resolveConfig(raw) {
|
|
|
11427
11154
|
const input = normalizeConfigInput(raw);
|
|
11428
11155
|
const config = { ...DEFAULT_CONFIG };
|
|
11429
11156
|
for (const [key, integer, min] of NUMBER_KEYS) {
|
|
11430
|
-
const value = input[key];
|
|
11431
|
-
if (value
|
|
11432
|
-
if (typeof value === "string" && value.trim() === "") continue;
|
|
11433
|
-
if (typeof value !== "number" || !Number.isFinite(value)) continue;
|
|
11434
|
-
if (integer && !Number.isInteger(value)) continue;
|
|
11435
|
-
if (min !== void 0 && value < min) continue;
|
|
11436
|
-
config[key] = value;
|
|
11157
|
+
const value = resolveNumber(input[key], integer, min);
|
|
11158
|
+
if (value !== void 0) config[key] = value;
|
|
11437
11159
|
}
|
|
11438
11160
|
config.compressSkipReasoning = resolveBoolean(input.compressSkipReasoning, true);
|
|
11439
|
-
config.omEnabled = resolveBoolean(input.omEnabled, true);
|
|
11440
11161
|
config.progressReminderEnabled = resolveBoolean(input.progressReminderEnabled, true);
|
|
11441
11162
|
config.progressReminderIdleEnabled = resolveBoolean(input.progressReminderIdleEnabled, DEFAULT_CONFIG.progressReminderIdleEnabled);
|
|
11442
|
-
config.debug =
|
|
11163
|
+
config.debug = resolveDebug(input.debug);
|
|
11443
11164
|
config.semanticRecallEnabled = resolveBoolean(input.semanticRecallEnabled, true);
|
|
11444
11165
|
const modelDir = input.modelDir;
|
|
11445
11166
|
if (typeof modelDir === "string" && modelDir.trim() !== "") config.modelDir = modelDir;
|
|
@@ -11967,233 +11688,6 @@ function buildRecallTool(options) {
|
|
|
11967
11688
|
};
|
|
11968
11689
|
}
|
|
11969
11690
|
//#endregion
|
|
11970
|
-
//#region src/recompress-gate.ts
|
|
11971
|
-
/** 当前持有许可的数量。 */
|
|
11972
|
-
let active = 0;
|
|
11973
|
-
/** 排队中的请求(先进先出)。 */
|
|
11974
|
-
const queue = [];
|
|
11975
|
-
/** 按各自上限唤醒队首请求,直到许可用尽。 */
|
|
11976
|
-
function drain() {
|
|
11977
|
-
while (queue.length > 0) {
|
|
11978
|
-
const head = queue[0];
|
|
11979
|
-
if (head === void 0 || active >= Math.max(1, head.limit())) return;
|
|
11980
|
-
queue.shift();
|
|
11981
|
-
head.grant();
|
|
11982
|
-
}
|
|
11983
|
-
}
|
|
11984
|
-
/** 获取一个重压缩许可,返回幂等的 release;signal 中止时拒绝。 */
|
|
11985
|
-
function acquireRecompressSlot(limit, signal) {
|
|
11986
|
-
return new Promise((resolve, reject) => {
|
|
11987
|
-
if (signal?.aborted === true) {
|
|
11988
|
-
reject(signal.reason instanceof Error ? signal.reason : /* @__PURE__ */ new Error("aborted"));
|
|
11989
|
-
return;
|
|
11990
|
-
}
|
|
11991
|
-
const grant = () => {
|
|
11992
|
-
signal?.removeEventListener("abort", onAbort);
|
|
11993
|
-
active++;
|
|
11994
|
-
let released = false;
|
|
11995
|
-
resolve(() => {
|
|
11996
|
-
if (released) return;
|
|
11997
|
-
released = true;
|
|
11998
|
-
active--;
|
|
11999
|
-
drain();
|
|
12000
|
-
});
|
|
12001
|
-
};
|
|
12002
|
-
const waiter = {
|
|
12003
|
-
limit,
|
|
12004
|
-
grant
|
|
12005
|
-
};
|
|
12006
|
-
const onAbort = () => {
|
|
12007
|
-
const index = queue.indexOf(waiter);
|
|
12008
|
-
if (index >= 0) queue.splice(index, 1);
|
|
12009
|
-
reject(signal?.reason instanceof Error ? signal.reason : /* @__PURE__ */ new Error("aborted"));
|
|
12010
|
-
};
|
|
12011
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
12012
|
-
queue.push(waiter);
|
|
12013
|
-
drain();
|
|
12014
|
-
});
|
|
12015
|
-
}
|
|
12016
|
-
//#endregion
|
|
12017
|
-
//#region src/recompress.ts
|
|
12018
|
-
/** 命令行用法提示。 */
|
|
12019
|
-
const USAGE = "用法:/om-recompress <compactionId> <provider> <model> [思考等级]";
|
|
12020
|
-
/** 解析命令行:compactionId provider model [reasoningEffort],空白分隔。 */
|
|
12021
|
-
function parseRecompressInput(rawInput) {
|
|
12022
|
-
const parts = rawInput.trim().split(/\s+/).filter((part) => part !== "");
|
|
12023
|
-
const [compactionId, provider, model, reasoningEffort] = parts;
|
|
12024
|
-
if (compactionId === void 0 || provider === void 0 || model === void 0 || parts.length > 4) return {
|
|
12025
|
-
ok: false,
|
|
12026
|
-
error: USAGE
|
|
12027
|
-
};
|
|
12028
|
-
return {
|
|
12029
|
-
ok: true,
|
|
12030
|
-
request: {
|
|
12031
|
-
compactionId,
|
|
12032
|
-
provider,
|
|
12033
|
-
model,
|
|
12034
|
-
...reasoningEffort === void 0 ? {} : { reasoningEffort }
|
|
12035
|
-
}
|
|
12036
|
-
};
|
|
12037
|
-
}
|
|
12038
|
-
/** 按 compactionId 收集 start/summary/end 载荷。 */
|
|
12039
|
-
function findLifecycle(session, compactionId) {
|
|
12040
|
-
const lifecycle = {
|
|
12041
|
-
phase: void 0,
|
|
12042
|
-
summary: void 0,
|
|
12043
|
-
end: void 0
|
|
12044
|
-
};
|
|
12045
|
-
for (const event of session.snapshotEvents()) if (event.type === "compaction/start") {
|
|
12046
|
-
const data = event.data;
|
|
12047
|
-
if (String(data.compactionId) === compactionId) lifecycle.phase = data.phase;
|
|
12048
|
-
} else if (event.type === "compaction/summary") {
|
|
12049
|
-
const data = event.data;
|
|
12050
|
-
if (String(data.compactionId) === compactionId) lifecycle.summary = data;
|
|
12051
|
-
} else if (event.type === "compaction/end") {
|
|
12052
|
-
const data = event.data;
|
|
12053
|
-
if (String(data.compactionId) === compactionId) lifecycle.end = data;
|
|
12054
|
-
}
|
|
12055
|
-
return lifecycle;
|
|
12056
|
-
}
|
|
12057
|
-
/** 重建被压缩内容的视图:反思用被归档块的归档视图,观察用原消息;不可重建时返回错误。 */
|
|
12058
|
-
function rebuildView(session, phase, shadowedSeqs, skipReasoning) {
|
|
12059
|
-
if (phase === "reflect") return buildArchiveView(shadowedSeqs.flatMap((seq) => {
|
|
12060
|
-
const text = historyTextOf(session.snapshotEvents()[seq]);
|
|
12061
|
-
return text === void 0 ? [] : [{
|
|
12062
|
-
text,
|
|
12063
|
-
seq
|
|
12064
|
-
}];
|
|
12065
|
-
})).view;
|
|
12066
|
-
return buildObserveView(session, shadowedSeqs, { skipReasoning });
|
|
12067
|
-
}
|
|
12068
|
-
/** 按 compactionId 重建一次已成功压缩的输入视图;不可重放时返回错误文本。 */
|
|
12069
|
-
function compactionView(session, compactionId, skipReasoning) {
|
|
12070
|
-
const lifecycle = findLifecycle(session, compactionId);
|
|
12071
|
-
if (lifecycle.phase === void 0 && lifecycle.summary === void 0) return { error: `未找到压缩 ${compactionId}` };
|
|
12072
|
-
const summary = lifecycle.summary;
|
|
12073
|
-
if (summary === void 0 || lifecycle.end === void 0 || lifecycle.end.error !== void 0) return { error: `压缩 ${compactionId} 未成功完成,无法重压缩` };
|
|
12074
|
-
const shadowedSeqs = (summary.shadowedSeqs ?? []).map(Number);
|
|
12075
|
-
if (shadowedSeqs.length === 0) return { error: `压缩 ${compactionId} 缺少 shadowedSeqs,无法重放` };
|
|
12076
|
-
const firstEvent = session.snapshotEvents()[shadowedSeqs[0] ?? -1];
|
|
12077
|
-
const phase = lifecycle.phase ?? (historyTextOf(firstEvent) === void 0 ? "observe" : "reflect");
|
|
12078
|
-
const view = rebuildView(session, phase, shadowedSeqs, skipReasoning);
|
|
12079
|
-
if (typeof view === "string") return { error: view };
|
|
12080
|
-
const { minIndex, maxIndex } = view;
|
|
12081
|
-
if (minIndex === void 0 || maxIndex === void 0) return { error: `压缩 ${compactionId} 的原内容无可定位条目` };
|
|
12082
|
-
const originalChars = summary.shadowedCharCount ?? (phase === "observe" ? seqsCharCount(session, shadowedSeqs) : viewCharCount(view));
|
|
12083
|
-
return {
|
|
12084
|
-
phase,
|
|
12085
|
-
view: {
|
|
12086
|
-
...view,
|
|
12087
|
-
minIndex,
|
|
12088
|
-
maxIndex
|
|
12089
|
-
},
|
|
12090
|
-
originalChars
|
|
12091
|
-
};
|
|
12092
|
-
}
|
|
12093
|
-
/**
|
|
12094
|
-
* 对已成功的 compaction 用目标模型重压缩一次。校验失败、压缩循环失败均以
|
|
12095
|
-
* { ok: false } 返回,不抛错;会话本身不被修改(见文件头说明)。
|
|
12096
|
-
*/
|
|
12097
|
-
async function recompress(ctx, agent, config, request, signal) {
|
|
12098
|
-
const session = agent.session;
|
|
12099
|
-
if (!isMainSession(session)) return {
|
|
12100
|
-
ok: false,
|
|
12101
|
-
error: "重压缩仅支持主会话"
|
|
12102
|
-
};
|
|
12103
|
-
const replay = compactionView(session, request.compactionId, config.compressSkipReasoning);
|
|
12104
|
-
if ("error" in replay) return {
|
|
12105
|
-
ok: false,
|
|
12106
|
-
error: replay.error
|
|
12107
|
-
};
|
|
12108
|
-
const { phase, view, originalChars } = replay;
|
|
12109
|
-
if (signal?.aborted === true) return {
|
|
12110
|
-
ok: false,
|
|
12111
|
-
error: COMPACTION_ABORTED_ERROR
|
|
12112
|
-
};
|
|
12113
|
-
const target = {
|
|
12114
|
-
provider: request.provider,
|
|
12115
|
-
model: request.model
|
|
12116
|
-
};
|
|
12117
|
-
makeLogger(ctx, config.debug).step(`重压缩:${request.compactionId}(${phase})→ ${target.provider}/${target.model}${request.reasoningEffort === void 0 ? "" : ` · ${request.reasoningEffort}`}`);
|
|
12118
|
-
const outcome = await runCompressionLoop(ctx, session, {
|
|
12119
|
-
view,
|
|
12120
|
-
originalChars,
|
|
12121
|
-
phase,
|
|
12122
|
-
taskText: buildCompressionTaskText(phase, view.minIndex, view.maxIndex, view.segments),
|
|
12123
|
-
target,
|
|
12124
|
-
maxTokens: config.compressMaxTokens,
|
|
12125
|
-
rateLimitWaitMs: config.rateLimitWaitMs,
|
|
12126
|
-
skipReasoning: config.compressSkipReasoning,
|
|
12127
|
-
debug: config.debug,
|
|
12128
|
-
retry: true,
|
|
12129
|
-
...request.reasoningEffort === void 0 ? {} : { reasoningEffort: request.reasoningEffort },
|
|
12130
|
-
...signal === void 0 ? {} : { signal }
|
|
12131
|
-
});
|
|
12132
|
-
if (!outcome.ok) return {
|
|
12133
|
-
ok: false,
|
|
12134
|
-
error: outcome.error,
|
|
12135
|
-
...outcome.recordSessionId === void 0 ? {} : { recordSessionId: outcome.recordSessionId }
|
|
12136
|
-
};
|
|
12137
|
-
return {
|
|
12138
|
-
ok: true,
|
|
12139
|
-
text: outcome.text,
|
|
12140
|
-
phase,
|
|
12141
|
-
rounds: outcome.rounds,
|
|
12142
|
-
originalChars,
|
|
12143
|
-
newChars: outcome.text.length,
|
|
12144
|
-
durationMs: outcome.stats.durationMs,
|
|
12145
|
-
...outcome.recordSessionId === void 0 ? {} : { recordSessionId: outcome.recordSessionId }
|
|
12146
|
-
};
|
|
12147
|
-
}
|
|
12148
|
-
/** 重压缩命令名(压缩卡片按钮经宿主命令通道调用)。 */
|
|
12149
|
-
const RECOMPRESS_COMMAND_NAME = "om-recompress";
|
|
12150
|
-
/** 渲染命令结果文本:成功为「字符 原始消息 → 产物,耗时,模型(等级)」,失败给出原因。 */
|
|
12151
|
-
function describeResult(request, result) {
|
|
12152
|
-
const label = `${request.provider}/${request.model}(${request.reasoningEffort ?? "默认"})`;
|
|
12153
|
-
if (!result.ok) return `重压缩失败 ${label}:${result.error}`;
|
|
12154
|
-
return `重压缩完成 字符 ${formatCompactCount(result.originalChars)} → ${formatCompactCount(result.newChars)},${formatSeconds(result.durationMs)},${label}`;
|
|
12155
|
-
}
|
|
12156
|
-
/** 构造 /om-recompress 命令定义;配置按调用时刻读取。 */
|
|
12157
|
-
function buildRecompressCommand(ctx, getConfig) {
|
|
12158
|
-
return {
|
|
12159
|
-
name: RECOMPRESS_COMMAND_NAME,
|
|
12160
|
-
description: "由压缩卡片调用:用另一模型重新压缩一次已完成的压缩",
|
|
12161
|
-
input: { hint: "<compactionId> <provider> <model> [思考等级]" },
|
|
12162
|
-
handler: async ({ agent, rawInput, signal }) => {
|
|
12163
|
-
const parsed = parseRecompressInput(rawInput);
|
|
12164
|
-
if (!parsed.ok) return {
|
|
12165
|
-
kind: "error",
|
|
12166
|
-
text: parsed.error
|
|
12167
|
-
};
|
|
12168
|
-
let release;
|
|
12169
|
-
try {
|
|
12170
|
-
release = await acquireRecompressSlot(() => getConfig().recompressConcurrency, signal);
|
|
12171
|
-
} catch {
|
|
12172
|
-
return {
|
|
12173
|
-
kind: "error",
|
|
12174
|
-
text: describeResult(parsed.request, {
|
|
12175
|
-
ok: false,
|
|
12176
|
-
error: COMPACTION_ABORTED_ERROR
|
|
12177
|
-
})
|
|
12178
|
-
};
|
|
12179
|
-
}
|
|
12180
|
-
try {
|
|
12181
|
-
const result = await recompress(ctx, agent, getConfig(), parsed.request, signal);
|
|
12182
|
-
const text = describeResult(parsed.request, result);
|
|
12183
|
-
return result.ok ? {
|
|
12184
|
-
kind: "success",
|
|
12185
|
-
text
|
|
12186
|
-
} : {
|
|
12187
|
-
kind: "error",
|
|
12188
|
-
text
|
|
12189
|
-
};
|
|
12190
|
-
} finally {
|
|
12191
|
-
release();
|
|
12192
|
-
}
|
|
12193
|
-
}
|
|
12194
|
-
};
|
|
12195
|
-
}
|
|
12196
|
-
//#endregion
|
|
12197
11691
|
//#region src/system-reminder.ts
|
|
12198
11692
|
/**
|
|
12199
11693
|
* system-reminder:以 <system-reminder> 用户消息向主会话注入进度提醒,不进系统提示词。
|
|
@@ -12238,9 +11732,9 @@ function systemReminderMessage(reminder) {
|
|
|
12238
11732
|
}
|
|
12239
11733
|
});
|
|
12240
11734
|
}
|
|
12241
|
-
/** 按配置返回应注入的提醒:
|
|
11735
|
+
/** 按配置返回应注入的提醒:progressReminderEnabled 开启时为进度提醒。 */
|
|
12242
11736
|
function activeSystemReminders(config) {
|
|
12243
|
-
return config.
|
|
11737
|
+
return config.progressReminderEnabled ? [PROGRESS_REMINDER] : [];
|
|
12244
11738
|
}
|
|
12245
11739
|
/** 默认活动重发判定,与配置默认值一致。 */
|
|
12246
11740
|
const DEFAULT_PROGRESS_IDLE = Object.freeze({
|
|
@@ -12433,18 +11927,17 @@ function registerThinkingBinding(ctx, logger) {
|
|
|
12433
11927
|
const name = "dsh-plugin-om";
|
|
12434
11928
|
/**
|
|
12435
11929
|
* 插件必需的服务依赖:压缩请求(llm)与上下文压力计量(tokenMeter)。
|
|
12436
|
-
* tools /
|
|
11930
|
+
* tools / sessions 等为可选能力,缺失时对应功能自动停用。
|
|
12437
11931
|
*/
|
|
12438
11932
|
const inject = ["llm", "tokenMeter"];
|
|
12439
11933
|
/** 插件激活入口:解析配置、注册工具、接线 pre-step 自动压缩与提醒补发。 */
|
|
12440
11934
|
function apply(ctx, config) {
|
|
12441
11935
|
const resolved = currentConfig(config);
|
|
12442
11936
|
const logger = makeLogger(ctx, () => currentConfig(config).debug);
|
|
12443
|
-
logger.step(`apply 启动:observeThresholdTokens=${String(resolved.observeThresholdTokens)} reflectThresholdTokens=${String(resolved.reflectThresholdTokens)} compressMaxTokens=${resolved.compressMaxTokens === void 0 ? "未设置" : String(resolved.compressMaxTokens)} tailMessageCount=${String(resolved.tailMessageCount)}
|
|
11937
|
+
logger.step(`apply 启动:observeThresholdTokens=${String(resolved.observeThresholdTokens)} reflectThresholdTokens=${String(resolved.reflectThresholdTokens)} compressMaxTokens=${resolved.compressMaxTokens === void 0 ? "未设置" : String(resolved.compressMaxTokens)} tailMessageCount=${String(resolved.tailMessageCount)} debug=${String(resolved.debug)} compressProvider=${resolved.compressProvider ?? "跟随会话路由"} compressModel=${resolved.compressModel ?? "跟随会话路由"} compressReasoningEffort=${resolved.compressReasoningEffort ?? "模型默认"}`);
|
|
12444
11938
|
const warnModel = (message) => ctx.logger.warn(`dsh-plugin-om: ${message}`);
|
|
12445
11939
|
const logModel = (message) => logger.info(message);
|
|
12446
11940
|
if (ctx.get("tools") === void 0) logger.warn("tools 服务未挂载,recall 暂不可用");
|
|
12447
|
-
if (ctx.get("commands") === void 0) logger.warn("commands 服务未挂载,重压缩与 OM 结果评估命令暂不可用");
|
|
12448
11941
|
ctx.inject(["tools"], (inner) => {
|
|
12449
11942
|
let disposeRecall;
|
|
12450
11943
|
/** 当前已注册 recall 对应的语义增强开关与模型目录。 */
|
|
@@ -12481,10 +11974,6 @@ function apply(ctx, config) {
|
|
|
12481
11974
|
disposeRecall = void 0;
|
|
12482
11975
|
}, "dsh-plugin-om: recall tool");
|
|
12483
11976
|
});
|
|
12484
|
-
ctx.inject(["commands"], (inner) => {
|
|
12485
|
-
inner.effect(() => inner.commands.register(buildRecompressCommand(ctx, () => currentConfig(config))), "dsh-plugin-om: recompress command");
|
|
12486
|
-
inner.effect(() => inner.commands.register(buildCompactionEvalCommand(ctx)), "dsh-plugin-om: compaction eval command");
|
|
12487
|
-
});
|
|
12488
11977
|
ctx.inject(["sessions"], (inner) => registerThinkingBinding(inner, logger));
|
|
12489
11978
|
ctx.on("session/disposed", (session) => disposePrecompression(session.id));
|
|
12490
11979
|
ctx.effect(() => () => disposeAllPrecompressions(), "dsh-plugin-om: precompression registry");
|