dsh-plugin-om 0.0.55 → 0.0.57
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 +74 -18
- package/dist/client/OmCompactionCard.d.ts.map +1 -1
- package/dist/client/OmEvalModelPanel.d.ts +22 -0
- package/dist/client/OmEvalModelPanel.d.ts.map +1 -0
- package/dist/client/OmRecompressMenu.d.ts +3 -3
- package/dist/client/OmRecompressMenu.d.ts.map +1 -1
- package/dist/client/compaction-eval-jump.d.ts +20 -0
- package/dist/client/compaction-eval-jump.d.ts.map +1 -0
- package/dist/client/definition.d.ts +2 -2
- package/dist/client/definition.d.ts.map +1 -1
- package/dist/client/eval-model-panel.d.ts +57 -0
- package/dist/client/eval-model-panel.d.ts.map +1 -0
- package/dist/client/eval-model-register.d.ts +10 -0
- package/dist/client/eval-model-register.d.ts.map +1 -0
- package/dist/client/index.d.ts +2 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/locales.d.ts +13 -2
- package/dist/client/locales.d.ts.map +1 -1
- package/dist/client/om-config-controller.d.ts +4 -1
- package/dist/client/om-config-controller.d.ts.map +1 -1
- package/dist/client/recompress-run.d.ts +23 -2
- package/dist/client/recompress-run.d.ts.map +1 -1
- package/dist/client.js +675 -116
- package/dist/client.js.map +1 -1
- package/dist/compaction-eval-command.d.ts +54 -0
- package/dist/compaction-eval-command.d.ts.map +1 -0
- package/dist/compaction-log.d.ts +31 -9
- package/dist/compaction-log.d.ts.map +1 -1
- package/dist/compress-loop.d.ts +21 -10
- package/dist/compress-loop.d.ts.map +1 -1
- package/dist/compress-tools.d.ts +16 -8
- package/dist/compress-tools.d.ts.map +1 -1
- package/dist/compress-view.d.ts +1 -3
- package/dist/compress-view.d.ts.map +1 -1
- package/dist/compress.d.ts +117 -8
- package/dist/compress.d.ts.map +1 -1
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/constants.d.ts +3 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/eval-session-text.d.ts +28 -0
- package/dist/eval-session-text.d.ts.map +1 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1392 -480
- package/dist/log-index.d.ts +2 -2
- package/dist/log-index.d.ts.map +1 -1
- package/dist/om-event.d.ts +26 -2
- package/dist/om-event.d.ts.map +1 -1
- package/dist/precompress.d.ts +100 -0
- package/dist/precompress.d.ts.map +1 -0
- package/dist/recall-xml.d.ts +2 -1
- package/dist/recall-xml.d.ts.map +1 -1
- package/dist/recompress-gate.d.ts +11 -0
- package/dist/recompress-gate.d.ts.map +1 -0
- package/dist/recompress.d.ts +20 -4
- package/dist/recompress.d.ts.map +1 -1
- package/dist/skill/compaction-eval/SKILL.md +72 -0
- package/dist/skill/compaction-eval/references/facts-prompt.md +42 -0
- package/dist/skill/compaction-eval/references/judge-prompt.md +48 -0
- package/dist/skill/compaction-eval/references/rules.md +56 -0
- package/dist/skill/compaction-eval/scripts/aggregate.mjs +372 -0
- package/dist/skill/compaction-eval/scripts/compress.mjs +15675 -0
- package/dist/skill/compaction-eval/scripts/merge.mjs +287 -0
- package/dist/skill/compaction-eval/scripts/prepare.mjs +1620 -0
- package/dist/skill/compaction-eval/scripts/view.mjs +15983 -0
- package/dist/system-reminder.d.ts.map +1 -1
- package/dist/thinking-binding.d.ts +28 -0
- package/dist/thinking-binding.d.ts.map +1 -0
- package/dist/types.d.ts +9 -6
- package/dist/types.d.ts.map +1 -1
- package/package.json +10 -3
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { existsSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { basename, join, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
//#region .agents/skills/compaction-eval/scripts/judging.ts
|
|
6
|
+
/**
|
|
7
|
+
* facts 与评审文件的共享类型、判定词与校验逻辑,供 aggregate.ts 与 merge.ts 使用。
|
|
8
|
+
*/
|
|
9
|
+
/** 事实判定词到得分。 */
|
|
10
|
+
const VERDICT = {
|
|
11
|
+
保留: 1,
|
|
12
|
+
部分: .5,
|
|
13
|
+
丢失: 0,
|
|
14
|
+
歪曲: -1
|
|
15
|
+
};
|
|
16
|
+
/** 无关信息判定词到得分。 */
|
|
17
|
+
const D_VERDICT = {
|
|
18
|
+
已省略: 1,
|
|
19
|
+
已概括: .7,
|
|
20
|
+
详细保留: 0
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* 校验单个评审内容:事实与无关信息全覆盖、无重复、无未知 id、判定词合法。
|
|
24
|
+
* 返回全部问题(带评审文件名前缀),为空即通过。
|
|
25
|
+
*/
|
|
26
|
+
function judgeProblems(judge, fj, name) {
|
|
27
|
+
const problems = [];
|
|
28
|
+
for (const [items, words, label, all] of [[
|
|
29
|
+
judge.facts,
|
|
30
|
+
VERDICT,
|
|
31
|
+
"事实",
|
|
32
|
+
fj.facts
|
|
33
|
+
], [
|
|
34
|
+
judge.irrelevant,
|
|
35
|
+
D_VERDICT,
|
|
36
|
+
"无关信息",
|
|
37
|
+
fj.irrelevant
|
|
38
|
+
]]) {
|
|
39
|
+
const byId = /* @__PURE__ */ new Map();
|
|
40
|
+
for (const x of items ?? []) if (byId.has(x.id)) problems.push(`${name} ${label} ${x.id} 重复判定`);
|
|
41
|
+
else byId.set(x.id, x);
|
|
42
|
+
for (const f of all) {
|
|
43
|
+
const x = byId.get(f.id);
|
|
44
|
+
if (x === void 0) problems.push(`${name} 未覆盖${label} ${f.id}`);
|
|
45
|
+
else if (!(x.verdict in words)) problems.push(`${name} ${label} ${f.id} 判定词非法:${x.verdict}`);
|
|
46
|
+
}
|
|
47
|
+
for (const x of items ?? []) if (!all.some((f) => f.id === x.id)) problems.push(`${name} ${label} ${x.id} 不在清单中`);
|
|
48
|
+
}
|
|
49
|
+
return problems;
|
|
50
|
+
}
|
|
51
|
+
/** facts.json 的规范哈希:按稳定序列化计算,供评审文件记录与 aggregate 比对。 */
|
|
52
|
+
function factsHash(fj) {
|
|
53
|
+
const canon = JSON.stringify({
|
|
54
|
+
facts: fj.facts.map((f) => ({
|
|
55
|
+
id: f.id,
|
|
56
|
+
fact: f.fact,
|
|
57
|
+
category: f.category,
|
|
58
|
+
position: f.position,
|
|
59
|
+
source_indices: f.source_indices,
|
|
60
|
+
check_hint: f.check_hint,
|
|
61
|
+
evidence_after: f.evidence_after ?? ""
|
|
62
|
+
})),
|
|
63
|
+
irrelevant: fj.irrelevant.map((d) => ({
|
|
64
|
+
id: d.id,
|
|
65
|
+
fact: d.fact,
|
|
66
|
+
is_credential: d.is_credential ?? false
|
|
67
|
+
}))
|
|
68
|
+
});
|
|
69
|
+
return createHash("sha256").update(canon, "utf8").digest("hex");
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region .agents/skills/compaction-eval/scripts/paths.ts
|
|
73
|
+
/** 用法行中的脚本名:取实际入口文件名,源码版为 .ts,发布版为 .mjs。 */
|
|
74
|
+
function selfName(fallback) {
|
|
75
|
+
const entry = process.argv[1];
|
|
76
|
+
return entry === void 0 ? fallback : basename(entry);
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region .agents/skills/compaction-eval/scripts/merge.ts
|
|
80
|
+
/**
|
|
81
|
+
* 合并 subagent 分段产出的 facts 与评审文件,并做全覆盖校验。
|
|
82
|
+
*
|
|
83
|
+
* 用法:
|
|
84
|
+
* node merge.ts facts <评估目录>
|
|
85
|
+
* 合并 parts/facts/ 下的 head.json、head-2.json…、mid…、tail…、irrelevant…
|
|
86
|
+
* 为 facts.json,按分段顺序统一编号 F01…、D01…;position 由分段文件名决定。
|
|
87
|
+
* node merge.ts judge <评估目录> <V> <N>
|
|
88
|
+
* 合并 parts/judge-<V>-<N>/ 下的 head.json、mid.json、tail.json、rest.json
|
|
89
|
+
* 为 judge-<V>-<N>.json,记录所基于 facts.json 的 facts_sha。
|
|
90
|
+
*
|
|
91
|
+
* 校验失败时列出全部问题并以非零码退出,不写文件;修正分段文件后重跑。
|
|
92
|
+
*/
|
|
93
|
+
/** facts 建议条数范围,超出仅告警。 */
|
|
94
|
+
const FACT_RANGE = [20, 35];
|
|
95
|
+
/** 无关信息建议最少条数,低于仅告警。 */
|
|
96
|
+
const IRRELEVANT_MIN = 5;
|
|
97
|
+
/** 读取 JSON 文件。 */
|
|
98
|
+
function readJson(p) {
|
|
99
|
+
return JSON.parse(readFileSync(p, "utf8"));
|
|
100
|
+
}
|
|
101
|
+
/** 按 <base>.json、<base>-2.json… 顺序读取分段文件;一个都没有返回 null。 */
|
|
102
|
+
function readParts(dir, base) {
|
|
103
|
+
if (!existsSync(dir)) return null;
|
|
104
|
+
const partNo = (n) => {
|
|
105
|
+
const m = /-(\d+)\.json$/.exec(n);
|
|
106
|
+
if (m === null) return 1;
|
|
107
|
+
const v = Number(m[1]);
|
|
108
|
+
return v >= 2 ? v : null;
|
|
109
|
+
};
|
|
110
|
+
const names = readdirSync(dir).filter((n) => n === `${base}.json` || new RegExp(`^${base}-\\d+\\.json$`).test(n)).map((n) => ({
|
|
111
|
+
n,
|
|
112
|
+
no: partNo(n)
|
|
113
|
+
})).filter((x) => x.no !== null).sort((a, b) => a.no - b.no).map((x) => x.n);
|
|
114
|
+
if (!names.length) return null;
|
|
115
|
+
return names.map((n) => readJson(join(dir, n)));
|
|
116
|
+
}
|
|
117
|
+
/** 补零编号。 */
|
|
118
|
+
const pad = (prefix, i) => `${prefix}${String(i).padStart(2, "0")}`;
|
|
119
|
+
/** 合并 facts 分段为 facts.json。校验失败时列出全部问题、置非零退出码且不写文件。 */
|
|
120
|
+
function mergeFacts(dir) {
|
|
121
|
+
const metaPath = join(dir, "meta.json");
|
|
122
|
+
if (!existsSync(metaPath)) throw new Error(`评估目录缺少 meta.json(${dir} 不是 prepare 产出的评估目录)`);
|
|
123
|
+
const [lo, hi] = readJson(metaPath).range;
|
|
124
|
+
const partsDir = join(dir, "parts", "facts");
|
|
125
|
+
const problems = [];
|
|
126
|
+
const facts = [];
|
|
127
|
+
const warnings = [];
|
|
128
|
+
for (const p of [
|
|
129
|
+
"head",
|
|
130
|
+
"mid",
|
|
131
|
+
"tail"
|
|
132
|
+
]) {
|
|
133
|
+
const parts = readParts(partsDir, p);
|
|
134
|
+
if (parts === null) {
|
|
135
|
+
problems.push(`缺少分段文件 ${p}.json(该分段没有事实时也要写出空数组)`);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
parts.forEach((part, pi) => {
|
|
139
|
+
if (!Array.isArray(part)) {
|
|
140
|
+
problems.push(`${p}${pi ? `-${pi + 1}` : ""}.json 应为数组`);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
part.forEach((x, xi) => {
|
|
144
|
+
const where = `${p}${pi ? `-${pi + 1}` : ""}.json 第 ${xi + 1} 条`;
|
|
145
|
+
if (typeof x.fact !== "string" || !x.fact.trim()) problems.push(`${where} 缺少 fact`);
|
|
146
|
+
if (x.category !== "A" && x.category !== "B" && x.category !== "C") problems.push(`${where} category 应为 A/B/C,实际 ${String(x.category)}`);
|
|
147
|
+
const nums = (Array.isArray(x.source_indices) ? x.source_indices : []).filter((i) => typeof i === "number");
|
|
148
|
+
if (!nums.length) problems.push(`${where} 缺少 source_indices`);
|
|
149
|
+
const outOfRange = nums.filter((i) => i < lo || i > hi);
|
|
150
|
+
if (outOfRange.length) problems.push(`${where} source_indices 超出区间 [${lo}..${hi}]:${outOfRange.join(" ")}`);
|
|
151
|
+
if (typeof x.check_hint !== "string" || !x.check_hint.trim()) problems.push(`${where} 缺少 check_hint`);
|
|
152
|
+
facts.push({
|
|
153
|
+
id: "",
|
|
154
|
+
fact: typeof x.fact === "string" ? x.fact : "",
|
|
155
|
+
category: x.category ?? "C",
|
|
156
|
+
position: p,
|
|
157
|
+
source_indices: nums,
|
|
158
|
+
check_hint: typeof x.check_hint === "string" ? x.check_hint : "",
|
|
159
|
+
...typeof x.evidence_after === "string" ? { evidence_after: x.evidence_after } : {}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
const irrelevant = [];
|
|
165
|
+
const dParts = readParts(partsDir, "irrelevant");
|
|
166
|
+
if (dParts === null) problems.push("缺少分段文件 irrelevant.json(没有无关信息时也要写出空数组)");
|
|
167
|
+
else dParts.forEach((part, pi) => {
|
|
168
|
+
if (!Array.isArray(part)) {
|
|
169
|
+
problems.push(`irrelevant${pi ? `-${pi + 1}` : ""}.json 应为数组`);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
part.forEach((x, xi) => {
|
|
173
|
+
const where = `irrelevant${pi ? `-${pi + 1}` : ""}.json 第 ${xi + 1} 条`;
|
|
174
|
+
if (typeof x.fact !== "string" || !x.fact.trim()) problems.push(`${where} 缺少 fact`);
|
|
175
|
+
irrelevant.push({
|
|
176
|
+
id: "",
|
|
177
|
+
fact: typeof x.fact === "string" ? x.fact : "",
|
|
178
|
+
is_credential: x.is_credential === true
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
if (problems.length) {
|
|
183
|
+
for (const p of problems) console.error(p);
|
|
184
|
+
process.exitCode = 1;
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
facts.forEach((f, i) => {
|
|
188
|
+
f.id = pad("F", i + 1);
|
|
189
|
+
});
|
|
190
|
+
irrelevant.forEach((d, i) => {
|
|
191
|
+
d.id = pad("D", i + 1);
|
|
192
|
+
});
|
|
193
|
+
if (facts.length < FACT_RANGE[0] || facts.length > FACT_RANGE[1]) warnings.push(`关键事实 ${facts.length} 条,建议 ${FACT_RANGE[0]}–${FACT_RANGE[1]} 条`);
|
|
194
|
+
if (irrelevant.length < IRRELEVANT_MIN) warnings.push(`无关信息 ${irrelevant.length} 条,建议至少 ${IRRELEVANT_MIN} 条`);
|
|
195
|
+
const fj = {
|
|
196
|
+
facts,
|
|
197
|
+
irrelevant
|
|
198
|
+
};
|
|
199
|
+
writeFileSync(join(dir, "facts.json"), JSON.stringify(fj, null, 1), "utf8");
|
|
200
|
+
const byPos = (p) => facts.filter((f) => f.position === p).length;
|
|
201
|
+
console.log(`facts.json:关键事实 ${facts.length} 条(head ${byPos("head")} / mid ${byPos("mid")} / tail ${byPos("tail")}),无关信息 ${irrelevant.length} 条,facts_sha ${factsHash(fj).slice(0, 12)}`);
|
|
202
|
+
for (const w of warnings) console.warn(`告警:${w}`);
|
|
203
|
+
}
|
|
204
|
+
/** 合并评审分段为 judge-<V>-<N>.json,写入所依据 facts.json 的哈希。 */
|
|
205
|
+
function mergeJudge(dir, v, n) {
|
|
206
|
+
const fj = readJson(join(dir, "facts.json"));
|
|
207
|
+
const partsDir = join(dir, "parts", `judge-${v}-${n}`);
|
|
208
|
+
const problems = [];
|
|
209
|
+
const factItems = [];
|
|
210
|
+
for (const p of [
|
|
211
|
+
"head",
|
|
212
|
+
"mid",
|
|
213
|
+
"tail"
|
|
214
|
+
]) {
|
|
215
|
+
const expected = fj.facts.filter((f) => f.position === p);
|
|
216
|
+
const part = readParts(partsDir, p);
|
|
217
|
+
if (part === null) {
|
|
218
|
+
if (expected.length) problems.push(`缺少分段文件 ${p}.json(应含 ${expected.map((f) => f.id).join(" ")})`);
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
part.forEach((xs, pi) => {
|
|
222
|
+
if (!Array.isArray(xs)) {
|
|
223
|
+
problems.push(`${p}${pi ? `-${pi + 1}` : ""}.json 应为数组`);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
xs.forEach((x) => {
|
|
227
|
+
const f = fj.facts.find((y) => y.id === x.id);
|
|
228
|
+
if (f && f.position !== p) problems.push(`事实 ${x.id} 属于 ${f.position},被写在 ${p}.json`);
|
|
229
|
+
factItems.push(x);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
const rest = readParts(partsDir, "rest");
|
|
234
|
+
let restData = {
|
|
235
|
+
irrelevant: [],
|
|
236
|
+
unsupported_claims: [],
|
|
237
|
+
extra_irrelevant: [],
|
|
238
|
+
overall_comment: void 0
|
|
239
|
+
};
|
|
240
|
+
if (rest === null) problems.push("缺少分段文件 rest.json(应含无关信息判定与清单外内容)");
|
|
241
|
+
else if (rest.length > 1) problems.push("rest.json 只允许一个文件");
|
|
242
|
+
else {
|
|
243
|
+
const r = rest[0];
|
|
244
|
+
if (!r) problems.push("rest.json 内容为空");
|
|
245
|
+
else restData = {
|
|
246
|
+
irrelevant: Array.isArray(r.irrelevant) ? r.irrelevant : [],
|
|
247
|
+
unsupported_claims: Array.isArray(r.unsupported_claims) ? r.unsupported_claims : [],
|
|
248
|
+
extra_irrelevant: Array.isArray(r.extra_irrelevant) ? r.extra_irrelevant : [],
|
|
249
|
+
overall_comment: typeof r.overall_comment === "string" ? r.overall_comment : void 0
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
const judge = {
|
|
253
|
+
facts: factItems,
|
|
254
|
+
irrelevant: restData.irrelevant,
|
|
255
|
+
unsupported_claims: restData.unsupported_claims,
|
|
256
|
+
extra_irrelevant: restData.extra_irrelevant,
|
|
257
|
+
...restData.overall_comment !== void 0 ? { overall_comment: restData.overall_comment } : {},
|
|
258
|
+
facts_sha: factsHash(fj)
|
|
259
|
+
};
|
|
260
|
+
problems.push(...judgeProblems(judge, fj, `judge-${v}-${n}`));
|
|
261
|
+
if (problems.length) {
|
|
262
|
+
for (const p of problems) console.error(p);
|
|
263
|
+
process.exitCode = 1;
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const name = `judge-${v}-${n}.json`;
|
|
267
|
+
writeFileSync(join(dir, name), JSON.stringify(judge, null, 1), "utf8");
|
|
268
|
+
console.log(`${name}:事实判定 ${judge.facts.length} 条,无关信息判定 ${judge.irrelevant.length} 条,无依据断言 ${judge.unsupported_claims?.length ?? 0} 条,清单外无关内容 ${judge.extra_irrelevant?.length ?? 0} 条`);
|
|
269
|
+
}
|
|
270
|
+
/** 命令行入口。 */
|
|
271
|
+
function main() {
|
|
272
|
+
const [cmd, dir, v, n] = process.argv.slice(2);
|
|
273
|
+
if (cmd === "facts" && dir) {
|
|
274
|
+
mergeFacts(resolve(dir));
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (cmd === "judge" && dir && v && n) {
|
|
278
|
+
mergeJudge(resolve(dir), v, n);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const me = selfName("merge.ts");
|
|
282
|
+
console.error(`用法:node ${me} facts <评估目录> | ${me} judge <评估目录> <V> <N>`);
|
|
283
|
+
process.exitCode = 2;
|
|
284
|
+
}
|
|
285
|
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) main();
|
|
286
|
+
//#endregion
|
|
287
|
+
export { mergeFacts, mergeJudge };
|