dsh-log-contract 0.3.18 → 0.3.19
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/bin/dsh-log-contract.mjs +72 -7
- package/docs/CONTRACTS.md +36 -1
- package/lib/archive.js +309 -0
- package/lib/checks.js +331 -3
- package/lib/contracts.js +41 -0
- package/lib/index.js +2 -1
- package/lib/prewrite.js +21 -5
- package/lib/validate.js +78 -9
- package/package.json +1 -1
package/lib/validate.js
CHANGED
|
@@ -18,6 +18,8 @@ import { runHostProbes } from './host-probes.js';
|
|
|
18
18
|
import { SOURCE_DRIFT } from './contracts.js';
|
|
19
19
|
import {
|
|
20
20
|
CHUNK_ROW_TYPES,
|
|
21
|
+
carrierPairingViolations,
|
|
22
|
+
declarativeIgnorableViolations,
|
|
21
23
|
envelopeViolations,
|
|
22
24
|
ignorableTypeViolations,
|
|
23
25
|
engineViolations,
|
|
@@ -28,7 +30,10 @@ import {
|
|
|
28
30
|
nullTurnStepViolations,
|
|
29
31
|
physicalOrderViolations,
|
|
30
32
|
pluginViolations,
|
|
33
|
+
rawSourceEventSeqViolations,
|
|
31
34
|
replaySurface,
|
|
35
|
+
seedLengthViolations,
|
|
36
|
+
sourceEventSeqElementViolations,
|
|
32
37
|
stepKeyViolations,
|
|
33
38
|
turnEndReasonViolations,
|
|
34
39
|
violation,
|
|
@@ -38,6 +43,7 @@ import {
|
|
|
38
43
|
toolResultStructureViolations,
|
|
39
44
|
wireViolations,
|
|
40
45
|
} from './checks.js';
|
|
46
|
+
import { archiveVerdict } from './archive.js';
|
|
41
47
|
|
|
42
48
|
/**
|
|
43
49
|
* `header.cwd` 的"绝对路径"判据 —— **平台感知**(Issue #1)。
|
|
@@ -57,13 +63,16 @@ export function isAbsoluteLogPath(value) {
|
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
/** 宿主能力闸触发时**跳过**的规则(v3/被检版本语义相关)——报告里显式列出,避免"静默通过"。 */
|
|
60
|
-
const VERSION_DEPENDENT_RULES = ['E3', 'E7', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'W1', 'W2', 'T1', 'T2', 'T3', 'T4', 'T5', 'G1', 'G2'];
|
|
66
|
+
const VERSION_DEPENDENT_RULES = ['E3', 'E7', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'W1', 'W2', 'T1', 'T2', 'T3', 'T4', 'T5', 'G1', 'G2', 'G4', 'P5'];
|
|
61
67
|
|
|
62
68
|
/**
|
|
63
69
|
* 对会话日志执行全量离线体检。
|
|
64
70
|
*
|
|
65
71
|
* @param {object} log `loadSessionLog()` 的返回值
|
|
66
|
-
* @param {{ baseSeq?: number }} [opts]
|
|
72
|
+
* @param {{ baseSeq?: number, ignorableWhitelist?: string[], archiveRoots?: string[] }} [opts]
|
|
73
|
+
* - `ignorableWhitelist`:G4 可忽略消费者白名单(精确 type 或以 `/` 结尾的前缀;默认见
|
|
74
|
+
* `checks.js` 的 `DEFAULT_IGNORABLE_WHITELIST`);
|
|
75
|
+
* - `archiveRoots`:A1「在位可还原」的归档根目录;**不传 = 该维度不可判定**(不冒充通过)。
|
|
67
76
|
* @returns {{
|
|
68
77
|
* ok: boolean,
|
|
69
78
|
* violations: Array,
|
|
@@ -72,7 +81,7 @@ const VERSION_DEPENDENT_RULES = ['E3', 'E7', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6',
|
|
|
72
81
|
* }}
|
|
73
82
|
*/
|
|
74
83
|
export function validateSessionLog(log, opts = {}) {
|
|
75
|
-
const { baseSeq = 0 } = opts;
|
|
84
|
+
const { baseSeq = 0, ignorableWhitelist, archiveRoots } = opts;
|
|
76
85
|
const violations = [];
|
|
77
86
|
const { header, headerLine, rows, frameInfo } = log;
|
|
78
87
|
// C1 防御(多入口一致):即使调用方手搓 log 对象、未经 `loadSessionLog`,也在体检入口
|
|
@@ -89,7 +98,7 @@ export function validateSessionLog(log, opts = {}) {
|
|
|
89
98
|
// `S8×1 + E3×40 / verdict=broken / loadable:false`),危险是用户以为日志坏了去跑
|
|
90
99
|
// `fix --apply`。改为:只跑与版本无关的结构检查 + 显式"不可在本宿主评估"档。
|
|
91
100
|
if (!isAssessableFileVersion(formatVersion)) {
|
|
92
|
-
return unassessableResult({ header, headerLine, rows, events, frameInfo, baseSeq, formatVersion });
|
|
101
|
+
return unassessableResult({ header, headerLine, rows, events, frameInfo, baseSeq, formatVersion, ignorableWhitelist, archiveRoots });
|
|
93
102
|
}
|
|
94
103
|
|
|
95
104
|
// ── Z · 帧结构 ─────────────────────────────────────────────────────────
|
|
@@ -150,6 +159,17 @@ export function validateSessionLog(log, opts = {}) {
|
|
|
150
159
|
}
|
|
151
160
|
}
|
|
152
161
|
|
|
162
|
+
// ── S10 · sourceEventSeqs 元素类型硬断言(0.3.19 · 最小集 ②)───────────
|
|
163
|
+
// 两层:① 存储形态(rows[].value,官方区间对是合法存储形态);② 解码后形态(必须全是
|
|
164
|
+
// 非负整数)。覆盖面 = **所有事件**(含非 surface 与 ignorable 未知插件事件)。
|
|
165
|
+
violations.push(...rawSourceEventSeqViolations(rows));
|
|
166
|
+
violations.push(...sourceEventSeqElementViolations(events));
|
|
167
|
+
|
|
168
|
+
// ── I2 · seedLength = 继承事件条数(0.3.19 · 最小集 ③)─────────────────
|
|
169
|
+
// parentSession ∧ seedLength∈{缺失,0} 判**合法**(血缘 ≠ seeded);只有 seedLength 超过
|
|
170
|
+
// 展开后事件数、非法值、或 v4 头带该字段才判红。
|
|
171
|
+
violations.push(...seedLengthViolations(header, events.map((e) => e.event), formatVersion));
|
|
172
|
+
|
|
153
173
|
// ── E · 事件信封 + seq 连续性 ──────────────────────────────────────────
|
|
154
174
|
let expectedSeq = baseSeq;
|
|
155
175
|
let seqBroken = false;
|
|
@@ -210,6 +230,10 @@ export function validateSessionLog(log, opts = {}) {
|
|
|
210
230
|
violations.push(...pluginViolations(event, loc));
|
|
211
231
|
}
|
|
212
232
|
|
|
233
|
+
// ── P5 · carrier 两段配对(0.3.19 · 最小集 ④;**读侧容错**)──────────────
|
|
234
|
+
// 读侧两种真实写法都认:① 现役 [审计段 seq, ...];② 早期 [区间起点, ...](不引用审计段)。
|
|
235
|
+
violations.push(...carrierPairingViolations(events, { version: formatVersion }));
|
|
236
|
+
|
|
213
237
|
// ── C · 并发(仅当出现 seq 破坏时给出解释性告警)─────────────────────
|
|
214
238
|
if (seqBroken) {
|
|
215
239
|
violations.push(violation('C1', { lineNo: null }, 'seq 缺口/倒退是多写入者(≥2 个 Host 进程共享同一 session 目录)并发写的典型后果;离线体检无法观测竞态本身,但此痕迹需人工核查(N6)'));
|
|
@@ -218,7 +242,16 @@ export function validateSessionLog(log, opts = {}) {
|
|
|
218
242
|
// ── G · 迁移预检(**独立维度**:官方升级路径会不会拒;不进 ok/verdict)──────
|
|
219
243
|
// 官方把 v0/v1/v2 升到当前格式时的规则集比本工具的"读取/折叠"规则集更严:本工具判
|
|
220
244
|
// ok/compactable **不代表**官方迁移会接受。这里只加 migration 层 warning(见 contracts G1/G2)。
|
|
221
|
-
violations.push(...migrationPrecheckViolations(events, formatVersion));
|
|
245
|
+
violations.push(...migrationPrecheckViolations(events, formatVersion, { ignorableWhitelist }));
|
|
246
|
+
// G4(0.3.19 · 最小集 ①):未知历史事件 + ignorable:true = **声明式可忽略**。
|
|
247
|
+
// 已登记(白名单)⇒ 不报违规、进 acceptedDrops(迁移不硬拒);未登记 ⇒ warning(⛔ 不静默)。
|
|
248
|
+
const ignorableDrops = declarativeIgnorableViolations(events, formatVersion, { ignorableWhitelist });
|
|
249
|
+
violations.push(...ignorableDrops.violations);
|
|
250
|
+
|
|
251
|
+
// ── A1 · 在位可还原(0.3.19 · 最小集 ⑤;**独立维度**)────────────────────
|
|
252
|
+
// 只认结构化归档指针;未提供归档根目录 ⇒ verdict='unverifiable'(不冒充通过、不产生违规)。
|
|
253
|
+
const archive = archiveVerdict(events, { archiveRoots });
|
|
254
|
+
violations.push(...archive.violations);
|
|
222
255
|
|
|
223
256
|
// ── 汇总 ───────────────────────────────────────────────────────────────
|
|
224
257
|
violations.sort((a, b) => (a.seq ?? -1) - (b.seq ?? -1) || (a.lineNo ?? -1) - (b.lineNo ?? -1));
|
|
@@ -241,6 +274,10 @@ export function validateSessionLog(log, opts = {}) {
|
|
|
241
274
|
fileVersion: formatVersion,
|
|
242
275
|
hostMaxFileVersion: HOST_MAX_FILE_VERSION,
|
|
243
276
|
assessable: true,
|
|
277
|
+
// 0.3.19:结构化读数(不进 ok,只供报告/机器判读)
|
|
278
|
+
seedLength: Object.hasOwn(header ?? {}, 'seedLength') ? header.seedLength : null,
|
|
279
|
+
ignorableDrops: { registered: ignorableDrops.registered.length, unregistered: ignorableDrops.unregistered.length },
|
|
280
|
+
archiveVerdict: archive.verdict,
|
|
244
281
|
};
|
|
245
282
|
|
|
246
283
|
const result = {
|
|
@@ -249,6 +286,10 @@ export function validateSessionLog(log, opts = {}) {
|
|
|
249
286
|
violations,
|
|
250
287
|
summary,
|
|
251
288
|
surface: folded.surface ?? { nodes: replay.nodes, replacements: [] },
|
|
289
|
+
// A1 独立维度读数:没有归档根时 `verdict='unverifiable'`(不冒充通过)。
|
|
290
|
+
archive,
|
|
291
|
+
// G4 声明式可忽略:已登记(acceptedDrop,不阻断迁移)与未登记(warning + 仍阻断)。
|
|
292
|
+
ignorableDrops: { registered: ignorableDrops.registered, unregistered: ignorableDrops.unregistered },
|
|
252
293
|
};
|
|
253
294
|
// 版本支持面(2026-09-14 用户要求第 1 条):宿主版本 vs 测试基线 + 被检文件格式版本,
|
|
254
295
|
// 给出 warnings/readOnly。只读档由入口(prewrite/fix)强制执行。
|
|
@@ -269,7 +310,7 @@ export function validateSessionLog(log, opts = {}) {
|
|
|
269
310
|
* 里列出。**ok 固定 false**(不认证),但 `structuralOk` 单独给出结构层结论——
|
|
270
311
|
* 语义是"本宿主评估不了",不是"日志坏了"。
|
|
271
312
|
*/
|
|
272
|
-
function unassessableResult({ header, headerLine, rows, events, frameInfo, baseSeq, formatVersion }) {
|
|
313
|
+
function unassessableResult({ header, headerLine, rows, events, frameInfo, baseSeq, formatVersion, archiveRoots }) {
|
|
273
314
|
const violations = [];
|
|
274
315
|
const cap = hostCapability();
|
|
275
316
|
const notAssessable = {
|
|
@@ -323,6 +364,12 @@ function unassessableResult({ header, headerLine, rows, events, frameInfo, baseS
|
|
|
323
364
|
violations.push(...inboxReplayViolations(events, header));
|
|
324
365
|
violations.push(...toolPairingViolations(events));
|
|
325
366
|
violations.push(...toolResultStructureViolations(events));
|
|
367
|
+
// S10 / I2:版本无关的结构断言(0.3.19 最小集 ②③)。
|
|
368
|
+
violations.push(...rawSourceEventSeqViolations(rows));
|
|
369
|
+
violations.push(...sourceEventSeqElementViolations(events));
|
|
370
|
+
violations.push(...seedLengthViolations(header, events.map((e) => e.event), formatVersion));
|
|
371
|
+
const archive = archiveVerdict(events, { archiveRoots });
|
|
372
|
+
violations.push(...archive.violations);
|
|
326
373
|
for (const { event, lineNo } of events) {
|
|
327
374
|
const loc = { seq: event.seq, lineNo, eventType: event.type };
|
|
328
375
|
violations.push(...engineViolations(event, loc));
|
|
@@ -356,8 +403,13 @@ function unassessableResult({ header, headerLine, rows, events, frameInfo, baseS
|
|
|
356
403
|
fileVersion: formatVersion,
|
|
357
404
|
hostMaxFileVersion: HOST_MAX_FILE_VERSION,
|
|
358
405
|
assessable: false,
|
|
406
|
+
seedLength: Object.hasOwn(header ?? {}, 'seedLength') ? header.seedLength : null,
|
|
407
|
+
ignorableDrops: { registered: 0, unregistered: 0 },
|
|
408
|
+
archiveVerdict: archive.verdict,
|
|
359
409
|
},
|
|
360
410
|
surface: null,
|
|
411
|
+
archive,
|
|
412
|
+
ignorableDrops: { registered: [], unregistered: [] },
|
|
361
413
|
};
|
|
362
414
|
result.support = detectSupport({ header, events });
|
|
363
415
|
result.probes = hostProbes();
|
|
@@ -423,6 +475,7 @@ export function migrationVerdict(result) {
|
|
|
423
475
|
'G1 v0 源:subagent/descriptor.data.version !== 3',
|
|
424
476
|
'G2 v0 源:事件类型不在官方 v0 dispositions 内(含 ignorable:true)',
|
|
425
477
|
'G3 v0 源:session/title 系列 messageSeqs 必须引用更早的人类 user/message(含"空 ⟺ 用户标题")',
|
|
478
|
+
'G4 v0 源:未知历史事件 + ignorable:true = 声明式可忽略(已登记白名单 ⇒ acceptedDrop,不硬拒;未登记 ⇒ warning 且仍阻断)',
|
|
426
479
|
],
|
|
427
480
|
uncovered: [
|
|
428
481
|
// 2026-09-15:`turn/start` 试做后在**真实语料**上被判定为"应用对象错"——
|
|
@@ -441,11 +494,26 @@ export function migrationVerdict(result) {
|
|
|
441
494
|
note: '未覆盖 ≠ 通过:本维度只对 implemented 三条负责。官方判据版本:@deepseek-ai/dsh-session-format-v0-to-v1@0.1.5-rc.2 + v1-to-v2@0.1.5-rc.2',
|
|
442
495
|
};
|
|
443
496
|
if (result?.assessable === false) {
|
|
444
|
-
return { assessable: false, applies: null, ready: null, fileVersion, blocked: [], coverage, assessmentScope: 'none', reason: result?.notAssessable?.reason ?? null };
|
|
497
|
+
return { assessable: false, applies: null, ready: null, fileVersion, blocked: [], acceptedDrops: { registered: [], unregistered: [] }, coverage, assessmentScope: 'none', reason: result?.notAssessable?.reason ?? null };
|
|
498
|
+
}
|
|
499
|
+
// G4(0.3.19):已登记的"声明式可忽略"未知历史事件 = acceptedDrop,**不阻断**迁移;
|
|
500
|
+
// G2 事实预检本身保留(仍在 violations 里,供人看"官方 v0→v1 会拒"),只是不再计入 blocked。
|
|
501
|
+
// 未登记 ⇒ 仍在 blocked(⛔ 不静默:新增插件事件必须显式登记一次)。
|
|
502
|
+
const registered = [];
|
|
503
|
+
const unregistered = [];
|
|
504
|
+
for (const v of violations) {
|
|
505
|
+
if (v.layer !== 'migration') continue;
|
|
506
|
+
if (v.id === 'G2' && v.ignorable === true) {
|
|
507
|
+
const drop = { id: v.id, seq: v.seq ?? null, eventType: v.eventType ?? null, message: v.message };
|
|
508
|
+
if (v.ignorableRegistered === true) registered.push(drop);
|
|
509
|
+
else unregistered.push(drop);
|
|
510
|
+
}
|
|
445
511
|
}
|
|
446
|
-
const
|
|
512
|
+
const acceptedDrops = { registered, unregistered };
|
|
513
|
+
const blocked = violations.filter((v) => v.layer === 'migration'
|
|
514
|
+
&& !(v.id === 'G2' && v.ignorable === true && v.ignorableRegistered === true));
|
|
447
515
|
if (fileVersion !== null && fileVersion === MIGRATION_TARGET_VERSION) {
|
|
448
|
-
return { assessable: true, applies: false, ready: null, fileVersion, targetFileVersion: MIGRATION_TARGET_VERSION, blocked, coverage, assessmentScope: 'full', reason: `被检文件已是当前官方格式(version=${fileVersion}),无需迁移` };
|
|
516
|
+
return { assessable: true, applies: false, ready: null, fileVersion, targetFileVersion: MIGRATION_TARGET_VERSION, blocked, acceptedDrops, coverage, assessmentScope: 'full', reason: `被检文件已是当前官方格式(version=${fileVersion}),无需迁移` };
|
|
449
517
|
}
|
|
450
518
|
const applies = fileVersion !== null && fileVersion < MIGRATION_TARGET_VERSION;
|
|
451
519
|
return {
|
|
@@ -456,6 +524,7 @@ export function migrationVerdict(result) {
|
|
|
456
524
|
targetFileVersion: MIGRATION_TARGET_VERSION,
|
|
457
525
|
hostMaxFileVersion: HOST_MAX_FILE_VERSION,
|
|
458
526
|
blocked,
|
|
527
|
+
acceptedDrops,
|
|
459
528
|
coverage,
|
|
460
529
|
// 2026-09-14:待迁移文件(applies=true)**只**被 2 条 G 规则覆盖,
|
|
461
530
|
// 另有 6 类官方迁移规则未覆盖 ⇒ 评估范围只能是 "partial"。工具无法逐文件知道
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-log-contract",
|
|
3
3
|
"description": "日志契约守护 — DSH session log contract guard: offline health check (CLI) + pre-write validation for DeepSeek Harness session logs",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.19",
|
|
5
5
|
"packageManager": "pnpm@11.7.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "lib/index.js",
|