dsh-plugin-om 0.0.62 → 0.0.63

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.
@@ -8108,8 +8108,8 @@ function sharedModelDir() {
8108
8108
  //#region src/config.ts
8109
8109
  /**
8110
8110
  * 插件配置:宿主 Config 严格校验、volatile 引用读取与兼容 YAML 的宽松合并。
8111
- * 导出 Config / PluginConfig / DEFAULT_CONFIG / currentConfig / resolveConfig;
8112
- * 旧输入在 resolveConfig 中未知键忽略、非法值回退默认值。
8111
+ * 导出 Config / PluginConfig / DEFAULT_CONFIG / currentConfig / resolveConfig。
8112
+ * 宽松解析时未知键忽略、非法值回退默认值。
8113
8113
  */
8114
8114
  /** 默认配置(冻结对象,resolveConfig 合并的基底;debug 缺省值在解析时按 NODE_ENV 判定)。 */
8115
8115
  const DEFAULT_CONFIG = Object.freeze({
@@ -8120,7 +8120,6 @@ const DEFAULT_CONFIG = Object.freeze({
8120
8120
  recompressConcurrency: 2,
8121
8121
  tailMessageCount: 20,
8122
8122
  compressSkipReasoning: true,
8123
- omEnabled: true,
8124
8123
  progressReminderEnabled: true,
8125
8124
  progressReminderIdleEnabled: false,
8126
8125
  progressReminderIdleSteps: 4,
@@ -8132,6 +8131,10 @@ const DEFAULT_CONFIG = Object.freeze({
8132
8131
  compressModel: void 0,
8133
8132
  compressReasoningEffort: void 0
8134
8133
  });
8134
+ /** debug 开关 schema:缺省按 NODE_ENV !== 'production' 判定。 */
8135
+ function debugSchema() {
8136
+ return Schema.boolean().default(process.env.NODE_ENV !== "production").volatile();
8137
+ }
8135
8138
  Schema.object({
8136
8139
  observeThresholdTokens: Schema.number().step(1).default(DEFAULT_CONFIG.observeThresholdTokens).volatile(),
8137
8140
  reflectThresholdTokens: Schema.number().step(1).default(DEFAULT_CONFIG.reflectThresholdTokens).volatile(),
@@ -8140,12 +8143,11 @@ Schema.object({
8140
8143
  recompressConcurrency: Schema.number().step(1).min(1).default(DEFAULT_CONFIG.recompressConcurrency).volatile(),
8141
8144
  tailMessageCount: Schema.number().step(1).default(DEFAULT_CONFIG.tailMessageCount).volatile(),
8142
8145
  compressSkipReasoning: Schema.boolean().default(DEFAULT_CONFIG.compressSkipReasoning).volatile(),
8143
- omEnabled: Schema.boolean().default(DEFAULT_CONFIG.omEnabled).volatile(),
8144
8146
  progressReminderEnabled: Schema.boolean().default(DEFAULT_CONFIG.progressReminderEnabled).volatile(),
8145
8147
  progressReminderIdleEnabled: Schema.boolean().default(DEFAULT_CONFIG.progressReminderIdleEnabled).volatile(),
8146
8148
  progressReminderIdleSteps: Schema.number().step(1).min(1).default(DEFAULT_CONFIG.progressReminderIdleSteps).volatile(),
8147
8149
  progressReminderIdleToolCalls: Schema.number().step(1).min(0).default(DEFAULT_CONFIG.progressReminderIdleToolCalls).volatile(),
8148
- debug: Schema.boolean().default(process.env.NODE_ENV !== "production").volatile(),
8150
+ debug: debugSchema(),
8149
8151
  semanticRecallEnabled: Schema.boolean().default(DEFAULT_CONFIG.semanticRecallEnabled).volatile(),
8150
8152
  modelDir: Schema.string().default(DEFAULT_CONFIG.modelDir).volatile(),
8151
8153
  compressProvider: Schema.string().volatile(),
@@ -8175,6 +8177,13 @@ const NUMBER_KEYS = [
8175
8177
  0
8176
8178
  ]
8177
8179
  ];
8180
+ /** 校验数值:有限数,integer 时须为整数,且不小于 min;不合法返回 undefined。 */
8181
+ function resolveNumber(raw, integer, min) {
8182
+ if (typeof raw !== "number" || !Number.isFinite(raw)) return void 0;
8183
+ if (integer && !Number.isInteger(raw)) return void 0;
8184
+ if (min !== void 0 && raw < min) return void 0;
8185
+ return raw;
8186
+ }
8178
8187
  /** 归一化原始配置输入:缺省 / null / 空串 / 非对象视为空对象。 */
8179
8188
  function normalizeConfigInput(raw) {
8180
8189
  if (raw === void 0 || raw === null) return {};
@@ -8189,6 +8198,10 @@ function resolveBoolean(raw, defaultValue) {
8189
8198
  if (typeof raw === "boolean") return raw;
8190
8199
  return defaultValue;
8191
8200
  }
8201
+ /** 解析 debug 开关:非 boolean 回退 NODE_ENV !== 'production'。 */
8202
+ function resolveDebug(raw) {
8203
+ return resolveBoolean(raw, process.env.NODE_ENV !== "production");
8204
+ }
8192
8205
  /** 解析字符串配置值:非空字符串才生效,缺省 / null / 空白串 / 非字符串回退 undefined。 */
8193
8206
  function resolveOptionalString(raw) {
8194
8207
  if (typeof raw === "string" && raw.trim() !== "") return raw;
@@ -8198,19 +8211,13 @@ function resolveConfig(raw) {
8198
8211
  const input = normalizeConfigInput(raw);
8199
8212
  const config = { ...DEFAULT_CONFIG };
8200
8213
  for (const [key, integer, min] of NUMBER_KEYS) {
8201
- const value = input[key];
8202
- if (value === void 0 || value === null) continue;
8203
- if (typeof value === "string" && value.trim() === "") continue;
8204
- if (typeof value !== "number" || !Number.isFinite(value)) continue;
8205
- if (integer && !Number.isInteger(value)) continue;
8206
- if (min !== void 0 && value < min) continue;
8207
- config[key] = value;
8214
+ const value = resolveNumber(input[key], integer, min);
8215
+ if (value !== void 0) config[key] = value;
8208
8216
  }
8209
8217
  config.compressSkipReasoning = resolveBoolean(input.compressSkipReasoning, true);
8210
- config.omEnabled = resolveBoolean(input.omEnabled, true);
8211
8218
  config.progressReminderEnabled = resolveBoolean(input.progressReminderEnabled, true);
8212
8219
  config.progressReminderIdleEnabled = resolveBoolean(input.progressReminderIdleEnabled, DEFAULT_CONFIG.progressReminderIdleEnabled);
8213
- config.debug = resolveBoolean(input.debug, process.env.NODE_ENV !== "production");
8220
+ config.debug = resolveDebug(input.debug);
8214
8221
  config.semanticRecallEnabled = resolveBoolean(input.semanticRecallEnabled, true);
8215
8222
  const modelDir = input.modelDir;
8216
8223
  if (typeof modelDir === "string" && modelDir.trim() !== "") config.modelDir = modelDir;
@@ -16,8 +16,8 @@ export type SystemReminder = {
16
16
  export declare const PROGRESS_REMINDER: SystemReminder;
17
17
  /** 构造一条新的提醒消息。 */
18
18
  export declare function systemReminderMessage(reminder: SystemReminder): UserMessage;
19
- /** 按配置返回应注入的提醒:omEnabled 与 progressReminderEnabled 同时开启时为进度提醒。 */
20
- export declare function activeSystemReminders(config: Pick<PluginConfig, 'omEnabled' | 'progressReminderEnabled'>): SystemReminder[];
19
+ /** 按配置返回应注入的提醒:progressReminderEnabled 开启时为进度提醒。 */
20
+ export declare function activeSystemReminders(config: Pick<PluginConfig, 'progressReminderEnabled'>): SystemReminder[];
21
21
  /** 活动重发判定:开关、静默窗口内已结束 step 数下限、工具调用数须超过的值。 */
22
22
  export type ProgressIdleOptions = {
23
23
  readonly enabled: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"system-reminder.d.ts","sourceRoot":"","sources":["../src/system-reminder.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,KAAK,EAAE,OAAO,EAAgB,WAAW,EAAE,MAAM,YAAY,CAAC;AAErE,yEAAyE;AACzE,eAAO,MAAM,6BAA6B,kCAAkC,CAAC;AAE7E,sBAAsB;AACtB,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,CAAC,IAAI,EAAE,OAAO,6BAA6B,CAAC;IACpD,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;CAC/B,CAAC;AAEF,kDAAkD;AAClD,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,IAAI,EAAE,OAAO,6BAA6B,CAAC;IACpD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAOF,YAAY;AACZ,eAAO,MAAM,iBAAiB,EAAE,cAS/B,CAAC;AAEF,kBAAkB;AAClB,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,cAAc,GAAG,WAAW,CAK3E;AAED,kEAAkE;AAClE,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,WAAW,GAAG,yBAAyB,CAAC,GAClE,cAAc,EAAE,CAElB;AAED,8CAA8C;AAC9C,MAAM,MAAM,mBAAmB,GAAG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,CAK3E;AAED,oDAAoD;AACpD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,yBAAyB,CAAC,GACpD,cAAc,EAAE,CAElB;AAED,8CAA8C;AAC9C,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,yBAAyB;AACzB,eAAO,MAAM,qBAAqB,EAAE,mBAIlC,CAAC;AAEH,mBAAmB;AACnB,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,IAAI,CACV,YAAY,EACZ,6BAA6B,GAAG,2BAA2B,GAAG,+BAA+B,CAC9F,GACA,mBAAmB,CAMrB;AAuDD;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,SAAS,WAAW,EAAE,EAChC,SAAS,EAAE,SAAS,cAAc,EAAE,EACpC,IAAI,GAAE,mBAA2C,GAChD,WAAW,EAAE,CAwBf"}
@@ -0,0 +1,89 @@
1
+ //#region src/utils.ts
2
+ /** 判断值是否为普通对象(非 null、非数组)。 */
3
+ function isRecord(value) {
4
+ return typeof value === "object" && value !== null && !Array.isArray(value);
5
+ }
6
+ /** 生成 uuid:优先 crypto.randomUUID,回退为时间戳+随机串拼接。 */
7
+ function uuid() {
8
+ const cryptoObj = globalThis.crypto;
9
+ if (cryptoObj && typeof cryptoObj.randomUUID === "function") return cryptoObj.randomUUID();
10
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 12)}`;
11
+ }
12
+ /** 提取 content 数组中的纯文本块(type === 'text' 的 block.text 拼接)。 */
13
+ function blocksToText(blocks) {
14
+ if (!Array.isArray(blocks)) return "";
15
+ const out = [];
16
+ for (const block of blocks) if (isRecord(block) && block.type === "text" && typeof block.text === "string") out.push(block.text);
17
+ return out.join("");
18
+ }
19
+ /** 消息内容的字符数:递归计入 text 块与 tool-result 内嵌文本。 */
20
+ function textCharCount(message) {
21
+ if (!message || !Array.isArray(message.content)) return 0;
22
+ let total = 0;
23
+ for (const block of message.content) if (block.type === "text") total += block.text.length;
24
+ else if (block.type === "tool-result") total += blocksToText(block.content).length;
25
+ return total;
26
+ }
27
+ /** 一组表层事件 seq 派生消息的字符数之和(OM 卡片「原始字符」口径)。 */
28
+ function seqsCharCount(session, seqs) {
29
+ const events = session.snapshotEvents();
30
+ return seqs.reduce((total, seq) => {
31
+ const event = events[seq];
32
+ return total + textCharCount(event ? session.deriveEventMessage(event) : null);
33
+ }, 0);
34
+ }
35
+ /** 面向 recall 的完整消息呈现:text 原样;tool-call 展开(参数=代码);tool-result 取文本。 */
36
+ function renderMessageText(message) {
37
+ if (!message || !Array.isArray(message.content)) return "";
38
+ const parts = [];
39
+ for (const block of message.content) if (block.type === "text") parts.push(block.text);
40
+ else if (block.type === "tool-call") parts.push(`[tool-call ${block.name} id=${String(block.id)}]
41
+ ${toolArgsJson(block.arguments)}`);
42
+ else if (block.type === "tool-result") parts.push(blocksToText(block.content));
43
+ return parts.join("\n");
44
+ }
45
+ /** 安全 JSON 序列化:序列化失败时退回 String 呈现。 */
46
+ function safeJson(value) {
47
+ try {
48
+ return JSON.stringify(value, null, 2);
49
+ } catch {
50
+ return String(value);
51
+ }
52
+ }
53
+ /**
54
+ * 工具调用参数的 JSON 文本(CDATA 内保持只有一层 JSON 转义):
55
+ * 字符串参数是模型产出的原始 JSON 串,原样返回(本身即合法 JSON,不再二次序列化);
56
+ * 其余结构 JSON.stringify 序列化一次。
57
+ */
58
+ function toolArgsJson(args) {
59
+ if (typeof args === "string") return args;
60
+ return safeJson(args);
61
+ }
62
+ /**
63
+ * 向元素追加 CDATA 正文:正文统一以 CDATA 包裹(逐字原样,不做实体转义)。
64
+ * 正文含 ]]> 时拆为相邻多个 CDATA 段,拼接后逐字还原原文,对读取方透明。
65
+ */
66
+ function appendCdataText(doc, el, text) {
67
+ const parts = text.split("]]>");
68
+ for (let i = 0; i < parts.length; i += 1) if (i === 0) el.appendChild(doc.createCDATASection(parts[0] ?? ""));
69
+ else {
70
+ el.appendChild(doc.createCDATASection("]]"));
71
+ el.appendChild(doc.createCDATASection(`>${parts[i] ?? ""}`));
72
+ }
73
+ }
74
+ /** 主会话判定:subagent 会话 header.origin === 'subagent'。 */
75
+ function isMainSession(session) {
76
+ return session.header?.origin !== "subagent";
77
+ }
78
+ /** 解析会话路由目标(provider/model),未路由时返回 undefined。 */
79
+ function routedTarget(session) {
80
+ try {
81
+ const config = session.requestHeader()?.config;
82
+ if (config?.provider && config.model) return {
83
+ provider: config.provider,
84
+ model: config.model
85
+ };
86
+ } catch {}
87
+ }
88
+ //#endregion
89
+ export { renderMessageText as a, toolArgsJson as c, isRecord as i, uuid as l, blocksToText as n, routedTarget as o, isMainSession as r, seqsCharCount as s, appendCdataText as t };
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "OM compaction eval",
4
+ "description": "Provides /om-compaction-eval. Run it in a session compacted by OM to analyze compaction quality."
5
+ }
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "OM 结果评估",
4
+ "description": "提供 /om-compaction-eval 命令。在进行过 OM 压缩的会话中调用此命令,可以分析压缩质量。"
5
+ }
6
+ }
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "OM-style context management",
4
+ "description": "Observational Memory style context compaction and verbatim recall."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "OM风格的上下文管理",
4
+ "description": "提供 Observational Memory 风格的上下文压缩和原文召回能力。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "dsh-plugin-om",
3
- "version": "0.0.62",
3
+ "version": "0.0.63",
4
4
  "type": "module",
5
+ "description": "Observational Memory style context compaction and verbatim recall for DSH",
5
6
  "main": "./dist/index.mjs",
6
7
  "module": "./dist/index.mjs",
7
8
  "types": "./dist/index.d.ts",
@@ -19,14 +20,21 @@
19
20
  "types": "./dist/index.d.ts",
20
21
  "import": "./dist/index.mjs"
21
22
  },
23
+ "./compaction-eval": {
24
+ "types": "./dist/compaction-eval/index.d.ts",
25
+ "import": "./dist/compaction-eval/index.mjs"
26
+ },
22
27
  "./client": {
23
28
  "types": "./dist/client/index.d.ts",
24
29
  "default": "./dist/client.js"
25
30
  },
31
+ "./locale/*.json": "./locale/*.json",
32
+ "./compaction-eval/locale/*.json": "./locale/compaction-eval/*.json",
26
33
  "./package.json": "./package.json"
27
34
  },
28
35
  "files": [
29
36
  "dist",
37
+ "locale",
30
38
  "models",
31
39
  "!models/*/onnx/*.onnx",
32
40
  "cordis.patch.yml",