dsh-log-contract 0.3.28 → 0.3.33
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 +48 -38
- package/README.zh.md +38 -38
- package/bin/dsh-log-contract.mjs +67 -15
- package/docs/CONTRACTS.md +74 -60
- package/docs/interface-versioning.md +46 -0
- package/lib/archive.js +21 -21
- package/lib/checks.js +155 -66
- package/lib/compat.js +7 -7
- package/lib/contracts.js +77 -60
- package/lib/explain.js +129 -0
- package/lib/host-probes.js +4 -4
- package/lib/index.js +1 -0
- package/lib/legacy-fold.js +5 -5
- package/lib/log-reader.js +57 -23
- package/lib/prewrite.js +6 -6
- package/lib/repair.js +34 -34
- package/lib/validate.js +27 -9
- package/lib/version-support.js +4 -4
- package/lib/vocab.js +8 -8
- package/package.json +2 -2
package/lib/checks.js
CHANGED
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
import { isSurfaceEligibleType } from '@deepseek-ai/dsh-session';
|
|
11
11
|
import { isJsonValue, decodeSeqRanges } from './compat.js';
|
|
12
12
|
import { currentVocabulary, currentFold, V0_EVENT_TYPES } from './vocab.js';
|
|
13
|
-
import { ruleById } from './contracts.js';
|
|
13
|
+
import { ruleById, SEVERITY } from './contracts.js';
|
|
14
14
|
|
|
15
15
|
export const SURFACE_TYPES = new Set(['user/message', 'assistant/message', 'tool/result']);
|
|
16
|
-
/** v3 新增 `system/message`(官方 `SURFACE_EVENT_TYPES`,0.1.5 `lib/index.js:
|
|
16
|
+
/** v3 新增 `system/message`(官方 `SURFACE_EVENT_TYPES`,0.1.5 `lib/index.js:149-154`)。 */
|
|
17
17
|
export const MODERN_SURFACE_TYPES = new Set([...SURFACE_TYPES, 'system/message']);
|
|
18
18
|
/** v4 新增 `developer/message`(官方 `SURFACE_EVENT_TYPES`,dsh-session@0.2.0-rc.2 `src/surface.ts:50-56`)。 */
|
|
19
19
|
export const V4_SURFACE_TYPES = new Set([...MODERN_SURFACE_TYPES, 'developer/message']);
|
|
@@ -47,6 +47,95 @@ export function isSafeInt(v) {
|
|
|
47
47
|
return typeof v === 'number' && Number.isSafeInteger(v) && v >= 0;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
// ── Z7/Z8 · zstd 逐帧元数据(0.3.32 · framing)──────────────────────────────
|
|
51
|
+
/**
|
|
52
|
+
* 规则 id 的单点定义(判定里不再散落字符串字面量)。
|
|
53
|
+
* - `Z7` = 单帧尺寸上限;`Z8` = 帧校验和必存。
|
|
54
|
+
* ⚠️ `Z3` 已被"空会话文件(有 header 无事件)"占用,**不改名**,故 checksum 用 Z8。
|
|
55
|
+
*/
|
|
56
|
+
export const FRAME_SIZE_RULE = 'Z7';
|
|
57
|
+
export const FRAME_CHECKSUM_RULE = 'Z8';
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* **Z7 单帧尺寸阈值(集中常量块)** —— 升级判据只改这里,判定逻辑不动。
|
|
61
|
+
*
|
|
62
|
+
* 判据 = 帧的**压缩后字节数**(`scanZstdFrames()` 的 `size`,含帧头与 checksum 尾)。
|
|
63
|
+
* 初版两档都是 warning(`FRAME_SIZE_SEVERITY` 的 `error` 档也指向 warning):
|
|
64
|
+
* 2026-11-05 真实语料实测(口径:`$DSH_HOME/sessions` 全量,1,551 会话 / 约 25.8 万帧;
|
|
65
|
+
* 实测时刻 11:45 CST,活跃会话仍在写 ⇒ 帧数会缓慢增长):
|
|
66
|
+
* >8MB 共 15 帧、集中在 8 个在写 v4 大会话,最大 26.4MB,无 >32MB ⇒ WARN 属预期噪声,
|
|
67
|
+
* 不阻断(大帧不影响加载)。后续把 `FRAME_SIZE_SEVERITY.error` 改 `SEVERITY.ERROR`
|
|
68
|
+
* 即升 ERROR,判据与测试无需改。
|
|
69
|
+
*/
|
|
70
|
+
export const FRAME_SIZE_LIMITS = Object.freeze({
|
|
71
|
+
/** 超过即 warning(8 MiB)。 */
|
|
72
|
+
warnBytes: 8 * 1024 * 1024,
|
|
73
|
+
/** 超过即"升档"违规(32 MiB);初版仍是 warning,见上方注释。 */
|
|
74
|
+
errorBytes: 32 * 1024 * 1024,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/** 两档对应的 severity(初版均 warning;升 ERROR 只改 `error` 这一行)。 */
|
|
78
|
+
export const FRAME_SIZE_SEVERITY = Object.freeze({
|
|
79
|
+
warn: SEVERITY.WARNING,
|
|
80
|
+
big32: SEVERITY.WARNING, // 文档别名 BIG32;初版仍是 warning
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Z8 · 帧校验和必存 + Z7 · 单帧尺寸上限(**逐帧**判,与事件无关)。
|
|
85
|
+
*
|
|
86
|
+
* Z8(0.3.32 · 2026-11 实测反例):zstd 帧头 descriptor 的 `Content_Checksum` 位
|
|
87
|
+
* (bit 2)必须置位 —— 缺位时帧内容无法自证完整(bitrot/截断只有解码失败才暴露;
|
|
88
|
+
* 宿主读路径不校验 checksum,缺位不会被发现)。**按文件格式版本分档**(闸门零误报):
|
|
89
|
+
* v4+ 缺位 ⇒ error;v0–v3 缺位 ⇒ warning —— 2026-11-05 真实语料实测:17 帧 / 10 个
|
|
90
|
+
* 2026-09-27 老 v3 会话缺该位(历史写入器产物,宿主仍能正常加载),判 ERROR 会把
|
|
91
|
+
* "能加载的老会话"误报成 broken。
|
|
92
|
+
*
|
|
93
|
+
* Z7:单帧 `size` 超阈值即报(>8MB / >32MB,初版均 warning,见 `FRAME_SIZE_LIMITS`)。
|
|
94
|
+
*
|
|
95
|
+
* @param {Array<{start:number,end:number,size:number,checksum:boolean}>} frames
|
|
96
|
+
* `scanZstdFrames()` 的 `frames`(即 `loadSessionLog().frameInfo.frameMeta`)。
|
|
97
|
+
* @param {{fileVersion?: number}} [opts] `fileVersion` = header.version(Z8 分档依据)。
|
|
98
|
+
* @returns {Array<object>} violations(空数组 = 绿)
|
|
99
|
+
*/
|
|
100
|
+
export function frameMetadataViolations(frames, { fileVersion = 0 } = {}) {
|
|
101
|
+
const out = [];
|
|
102
|
+
if (!Array.isArray(frames)) return out;
|
|
103
|
+
for (let index = 0; index < frames.length; index++) {
|
|
104
|
+
const frame = frames[index] ?? {};
|
|
105
|
+
const start = Number.isSafeInteger(frame.start) ? frame.start : 0;
|
|
106
|
+
const end = Number.isSafeInteger(frame.end) ? frame.end : start;
|
|
107
|
+
const size = Number.isSafeInteger(frame.size) ? frame.size : end - start;
|
|
108
|
+
if (frame.checksum === false) {
|
|
109
|
+
const legacy = !(fileVersion >= 4);
|
|
110
|
+
const extra = {
|
|
111
|
+
frameIndex: index,
|
|
112
|
+
frameStart: start,
|
|
113
|
+
frameSize: size,
|
|
114
|
+
severity: legacy ? SEVERITY.WARNING : SEVERITY.ERROR,
|
|
115
|
+
};
|
|
116
|
+
if (legacy) extra.checksumDowngraded = `历史格式 v${fileVersion} 缺 checksum 降为 warning(宿主可加载,不判 broken)`;
|
|
117
|
+
out.push(violation(
|
|
118
|
+
FRAME_CHECKSUM_RULE,
|
|
119
|
+
{ lineNo: null },
|
|
120
|
+
`第 ${index + 1} 帧(字节 [${start},${end}),${size} B)帧头未置 Content_Checksum 位`
|
|
121
|
+
+ ' —— zstd 帧校验和必存;缺位时帧内容无法自证完整(bitrot/截断只有解码失败才暴露,宿主读路径不校验 checksum)',
|
|
122
|
+
extra,
|
|
123
|
+
));
|
|
124
|
+
}
|
|
125
|
+
if (size > FRAME_SIZE_LIMITS.warnBytes) {
|
|
126
|
+
const tier = size > FRAME_SIZE_LIMITS.errorBytes ? 'big32' : 'warn';
|
|
127
|
+
out.push(violation(
|
|
128
|
+
FRAME_SIZE_RULE,
|
|
129
|
+
{ lineNo: null },
|
|
130
|
+
`第 ${index + 1} 帧(字节 [${start},${end}))压缩后 ${size} B,超过 ${FRAME_SIZE_LIMITS[tier === 'big32' ? 'errorBytes' : 'warnBytes']} B 阈值`
|
|
131
|
+
+ `(${tier === 'big32' ? '32MB' : '8MB'} 档)—— 单帧越大 ⇒ Z2"单帧全损"一次丢得越多、读取内存峰值越高;缩短写入批次即可`,
|
|
132
|
+
{ frameIndex: index, frameStart: start, frameSize: size, sizeTier: tier, severity: FRAME_SIZE_SEVERITY[tier] },
|
|
133
|
+
));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return out;
|
|
137
|
+
}
|
|
138
|
+
|
|
50
139
|
/** 事件信封 shape:seq/type/time/data(E1/E3/E4/E5/E6)。version = 被检文件版本。 */
|
|
51
140
|
export function envelopeViolations(event, loc, version) {
|
|
52
141
|
const out = [];
|
|
@@ -73,29 +162,29 @@ export function envelopeViolations(event, loc, version) {
|
|
|
73
162
|
if (event.type === 'request/header' && event.data?.reason === 'fallback') {
|
|
74
163
|
out.push(violation('E5', loc, 'request/header 使用已删除的遗留 reason "fallback"'));
|
|
75
164
|
}
|
|
76
|
-
// ──
|
|
165
|
+
// ── 2026-09-14 实测:3 例确证漏检补成候选规则 ───────────────────────
|
|
77
166
|
// E8 信封键白名单:宿主 `assertSessionEventEnvelope`(@deepseek-ai/dsh-session@0.1.5-rc.1
|
|
78
|
-
// lib/index.js:
|
|
167
|
+
// lib/index.js:852-861)逐键 switch,只认 7 个键,其余一律 `invalid event envelope`。
|
|
79
168
|
// 实测反例:宿主拒、旧契约 0 违规。
|
|
80
169
|
if (typeof event === 'object' && event !== null) {
|
|
81
170
|
const extra = Object.keys(event).filter((k) => !ENVELOPE_ALLOWED_KEYS.has(k));
|
|
82
171
|
if (extra.length > 0) {
|
|
83
|
-
out.push(violation('E8', loc, `事件信封含多余键 ${extra.join(', ')}——宿主只认 {${[...ENVELOPE_ALLOWED_KEYS].join(',')}}(dsh-session@0.1.5-rc.1 lib/index.js:
|
|
172
|
+
out.push(violation('E8', loc, `事件信封含多余键 ${extra.join(', ')}——宿主只认 {${[...ENVELOPE_ALLOWED_KEYS].join(',')}}(dsh-session@0.1.5-rc.1 lib/index.js:852-861)`));
|
|
84
173
|
}
|
|
85
174
|
}
|
|
86
175
|
// E10 request/header 的 data 字段约束:宿主 `validateSessionEventData`
|
|
87
|
-
// (dsh-session@0.1.5-rc.1 lib/index.js:
|
|
176
|
+
// (dsh-session@0.1.5-rc.1 lib/index.js:231-248)——`header.system` 必须省略、
|
|
88
177
|
// 空 tools / 空 adapterDefaults 必须省略。实测反例:宿主拒、旧契约 0 违规。
|
|
89
178
|
if (event.type === 'request/header') {
|
|
90
179
|
const header = event.data?.header;
|
|
91
180
|
if (typeof header !== 'object' || header === null || Array.isArray(header)) {
|
|
92
181
|
out.push(violation('E10', loc, 'request/header 的 data.header 必须是对象'));
|
|
93
182
|
} else {
|
|
94
|
-
if (Object.hasOwn(header, 'system')) out.push(violation('E10', loc, 'request/header 必须省略 header.system(系统提示改走 system/message)——宿主 lib/index.js:
|
|
95
|
-
if (Array.isArray(header.tools) && header.tools.length === 0) out.push(violation('E10', loc, 'request/header 必须省略空 tools——宿主 lib/index.js:
|
|
183
|
+
if (Object.hasOwn(header, 'system')) out.push(violation('E10', loc, 'request/header 必须省略 header.system(系统提示改走 system/message)——宿主 lib/index.js:237'));
|
|
184
|
+
if (Array.isArray(header.tools) && header.tools.length === 0) out.push(violation('E10', loc, 'request/header 必须省略空 tools——宿主 lib/index.js:238'));
|
|
96
185
|
const defaults = header.adapterDefaults;
|
|
97
186
|
if (typeof defaults === 'object' && defaults !== null && !Array.isArray(defaults) && Object.keys(defaults).length === 0) {
|
|
98
|
-
out.push(violation('E10', loc, 'request/header 必须省略空 adapterDefaults——宿主 lib/index.js:
|
|
187
|
+
out.push(violation('E10', loc, 'request/header 必须省略空 adapterDefaults——宿主 lib/index.js:239-240'));
|
|
99
188
|
}
|
|
100
189
|
}
|
|
101
190
|
}
|
|
@@ -103,10 +192,10 @@ export function envelopeViolations(event, loc, version) {
|
|
|
103
192
|
return out;
|
|
104
193
|
}
|
|
105
194
|
|
|
106
|
-
/** 宿主信封键白名单(assertSessionEventEnvelope,dsh-session@0.1.5-rc.1 lib/index.js:
|
|
195
|
+
/** 宿主信封键白名单(assertSessionEventEnvelope,dsh-session@0.1.5-rc.1 lib/index.js:852-861)。 */
|
|
107
196
|
export const ENVELOPE_ALLOWED_KEYS = new Set(['type', 'seq', 'time', 'data', 'surfaceOp', 'sourceEventSeqs', 'ignorable']);
|
|
108
197
|
|
|
109
|
-
/** v4 消息类事件 → 期望 role(dsh-session@0.2.0-rc.2 `MESSAGE_ROLE_BY_TYPE`,`src/index.ts:
|
|
198
|
+
/** v4 消息类事件 → 期望 role(dsh-session@0.2.0-rc.2 `MESSAGE_ROLE_BY_TYPE`,`src/index.ts:323-329`)。 */
|
|
110
199
|
const V4_MESSAGE_ROLE_BY_TYPE = {
|
|
111
200
|
'system/message': 'system',
|
|
112
201
|
'developer/message': 'developer',
|
|
@@ -116,14 +205,14 @@ const V4_MESSAGE_ROLE_BY_TYPE = {
|
|
|
116
205
|
};
|
|
117
206
|
|
|
118
207
|
/**
|
|
119
|
-
* 镜像官方 assertMessageEventShape(lib/index.js:
|
|
208
|
+
* 镜像官方 assertMessageEventShape(lib/index.js:1242-1266)。**按被检文件版本**择路:
|
|
120
209
|
* v0–v3 → 旧形状(下方原逻辑);v4 → `v4MessageShapeViolations`。
|
|
121
210
|
*/
|
|
122
211
|
export function messageShapeViolations(event, loc, version) {
|
|
123
212
|
if (version >= 4) return v4MessageShapeViolations(event, loc);
|
|
124
213
|
const type = event.type;
|
|
125
214
|
// 把 v3 新增的 `system/message` 纳入形状检查(MESSAGE_ROLE_BY_TYPE:system/message → system,
|
|
126
|
-
// dsh-session@0.1.5-rc.1 lib/index.js:
|
|
215
|
+
// dsh-session@0.1.5-rc.1 lib/index.js:917-926;source 要求 :942-944)。旧实现只查 user/assistant/tool
|
|
127
216
|
// ⇒ 实测反例(system/message 的 source.kind='user')宿主拒、旧契约 0 违规。
|
|
128
217
|
if (type !== 'user/message' && type !== 'assistant/message' && type !== 'tool/result' && type !== 'system/message') return [];
|
|
129
218
|
const out = [];
|
|
@@ -156,9 +245,9 @@ export function messageShapeViolations(event, loc, version) {
|
|
|
156
245
|
}
|
|
157
246
|
if (type === 'system/message') {
|
|
158
247
|
// E9(候选规则):system/message 必须 plugin source(kind==='plugin' + plugin 非空)。
|
|
159
|
-
// 宿主依据:dsh-session@0.1.5-rc.1 lib/index.js:
|
|
248
|
+
// 宿主依据:dsh-session@0.1.5-rc.1 lib/index.js:942-944("must have plugin source")。
|
|
160
249
|
if (source?.kind !== 'plugin' || typeof source.plugin !== 'string' || source.plugin === '') {
|
|
161
|
-
out.push(violation('E9', loc, `${shape()}:system/message 必须带 plugin source(kind==='plugin' 且 plugin 非空)——宿主 lib/index.js:
|
|
250
|
+
out.push(violation('E9', loc, `${shape()}:system/message 必须带 plugin source(kind==='plugin' 且 plugin 非空)——宿主 lib/index.js:942-944`));
|
|
162
251
|
}
|
|
163
252
|
}
|
|
164
253
|
if (type === 'tool/result') {
|
|
@@ -178,9 +267,9 @@ export function messageShapeViolations(event, loc, version) {
|
|
|
178
267
|
|
|
179
268
|
/**
|
|
180
269
|
* v4 消息形状。两层一手依据:
|
|
181
|
-
* - 运行时 load 路径:dsh-session@0.2.0-rc.2 `assertMessageEventShape`(`src/index.ts:
|
|
270
|
+
* - 运行时 load 路径:dsh-session@0.2.0-rc.2 `assertMessageEventShape`(`src/index.ts:331-381`)——
|
|
182
271
|
* role 表、system-prompt source、model source、tool source + `toolCallId` 匹配;
|
|
183
|
-
* - 文件读取路径:`dsh-session-format-v3-to-v4` 原生 v4 准入(`src/tool-role.ts:89-
|
|
272
|
+
* - 文件读取路径:`dsh-session-format-v3-to-v4` 原生 v4 准入(`src/tool-role.ts:89-109`、
|
|
184
273
|
* `src/message-sources.ts:9`)——残留 `tool-result` 包装块、非布尔 `isError`、`data.error` 而
|
|
185
274
|
* `isError !== true`、`source.kind === 'plugin'` 一律 SessionFormatError ⇒ 会话从盘上读不回来。
|
|
186
275
|
* `adoptSessionEvent` 不查这几条,所以只看运行时会漏掉"写得进、读不回"的形状。
|
|
@@ -226,7 +315,7 @@ function v4MessageShapeViolations(event, loc) {
|
|
|
226
315
|
}
|
|
227
316
|
}
|
|
228
317
|
if (type === 'system/message' && source?.kind !== 'system-prompt') {
|
|
229
|
-
out.push(violation('E9', loc, `${shape()}:system/message 必须带 system-prompt source(kind==='system-prompt')——dsh-session@0.2.0-rc.2 src/index.ts:
|
|
318
|
+
out.push(violation('E9', loc, `${shape()}:system/message 必须带 system-prompt source(kind==='system-prompt')——dsh-session@0.2.0-rc.2 src/index.ts:360-364`));
|
|
230
319
|
}
|
|
231
320
|
if (type === 'tool/result') {
|
|
232
321
|
if (source?.kind !== 'tool' || typeof source.callId !== 'string' || source.callId === '') {
|
|
@@ -247,7 +336,7 @@ function v4MessageShapeViolations(event, loc) {
|
|
|
247
336
|
return out;
|
|
248
337
|
}
|
|
249
338
|
|
|
250
|
-
/** replace 操作数精确形状(镜像旧格式 isReplaceOp,lib/index.js:
|
|
339
|
+
/** replace 操作数精确形状(镜像旧格式 isReplaceOp,lib/index.js:300-303)。 */
|
|
251
340
|
export function isReplaceOp(op) {
|
|
252
341
|
return (
|
|
253
342
|
typeof op === 'object' && op !== null &&
|
|
@@ -261,7 +350,7 @@ export function isReplaceOp(op) {
|
|
|
261
350
|
* 按**被检文件版本**归一化 replace 操作数到内部 `{start,end}`。
|
|
262
351
|
*
|
|
263
352
|
* 一手依据:官方 replace 字段在 v3 改名——旧格式(v0/v1/v2)`{op,start,end}`,
|
|
264
|
-
* v3 `{op,startSeq,endSeq}`(`dsh-session-format-v2-to-v3/lib/index.js:
|
|
353
|
+
* v3 `{op,startSeq,endSeq}`(`dsh-session-format-v2-to-v3/lib/index.js:361-371`)。
|
|
265
354
|
* 用错形状会得 null,由调用方归因为 S4(真实违规)。
|
|
266
355
|
*
|
|
267
356
|
* @param {unknown} op 待归一化的 surfaceOp
|
|
@@ -281,12 +370,12 @@ export function normalizeReplaceOp(op, version) {
|
|
|
281
370
|
}
|
|
282
371
|
|
|
283
372
|
/**
|
|
284
|
-
* S9 —— 文件物理序 seq 单调(
|
|
373
|
+
* S9 —— 文件物理序 seq 单调(2026-08-30 事故固化;交接书 L2)。
|
|
285
374
|
*
|
|
286
375
|
* 按**文件物理行序**(非 seq 排序)要求展开后的事件 seq 严格单调递增。
|
|
287
376
|
* 单进程 append 不可能写出非单调物理序(appendCore 断言 seq==cursor+i 且按
|
|
288
377
|
* id 串行化)——非单调 = 多写入者/旧光标回放交织的现场特征(某真实会话:物理序
|
|
289
|
-
*
|
|
378
|
+
* 734056→733539→735470)。E2 只查「排序后连续」,排序会掩盖物理序倒退;
|
|
290
379
|
* S9 补「物理序单调」盲区。
|
|
291
380
|
*
|
|
292
381
|
* @param rows - loadSessionLog 的 rows(物理行序,每行含 decoded 数组)。
|
|
@@ -328,10 +417,10 @@ export function replaySurface(events, version) {
|
|
|
328
417
|
|
|
329
418
|
if (!eligible) {
|
|
330
419
|
if (op !== undefined || src !== undefined) {
|
|
331
|
-
// ──
|
|
420
|
+
// ── 2026-09-14 实测:这里的 S2 是误报 ───────────────────────────────
|
|
332
421
|
// 宿主 `@deepseek-ai/dsh-session@0.1.5-rc.1` 是**刻意容忍**的:
|
|
333
|
-
// lib/index.js:
|
|
334
|
-
// 同一函数的契约注释 lib/index.js:
|
|
422
|
+
// lib/index.js:270 `if (!KNOWN_SESSION_EVENT_TYPES.has(event.type) && event.ignorable === true) return;`
|
|
423
|
+
// 同一函数的契约注释 lib/index.js:305 —— "Unknown ignorable records retain opaque
|
|
335
424
|
// metadata and never change the surface."
|
|
336
425
|
// ⇒ **未知**类型且 `ignorable===true` 的事件带 surfaceOp/sourceEventSeqs 是合法的不透明
|
|
337
426
|
// 元数据(宿主收;实测反例:宿主收、旧契约 S2/error)。这里不再报 S2。
|
|
@@ -379,7 +468,7 @@ export function replaySurface(events, version) {
|
|
|
379
468
|
return { violations, nodes, replaceGeneration };
|
|
380
469
|
}
|
|
381
470
|
|
|
382
|
-
/** 镜像官方 assertProvenance(lib/index.js:
|
|
471
|
+
/** 镜像官方 assertProvenance(lib/index.js:320-337)。 */
|
|
383
472
|
export function provenanceViolations(event, loc, shadowedSeqs) {
|
|
384
473
|
const out = [];
|
|
385
474
|
const raw = event.sourceEventSeqs;
|
|
@@ -415,7 +504,7 @@ export function provenanceViolations(event, loc, shadowedSeqs) {
|
|
|
415
504
|
return out;
|
|
416
505
|
}
|
|
417
506
|
|
|
418
|
-
/** 镜像官方 assertToolResultRewrite(lib/index.js:
|
|
507
|
+
/** 镜像官方 assertToolResultRewrite(lib/index.js:369-395)的判定核心。 */
|
|
419
508
|
export function toolResultRewriteViolations(event, loc, shadowedSeqs) {
|
|
420
509
|
if (event.type !== 'tool/result') return [];
|
|
421
510
|
const out = [];
|
|
@@ -434,7 +523,7 @@ export function engineViolations(event, loc) {
|
|
|
434
523
|
const turn = event.data?.turn;
|
|
435
524
|
const step = event.data?.step;
|
|
436
525
|
if (turn == null || step == null) {
|
|
437
|
-
out.push(violation('M1', loc, `assistant/message 以 append 进入 surface 但 data.turn/data.step 缺失(turn=${String(turn)}, step=${String(step)})——只能以 replace 承载(插件 marker 定义),append 会触发客户端引擎崩溃(rt.js:
|
|
526
|
+
out.push(violation('M1', loc, `assistant/message 以 append 进入 surface 但 data.turn/data.step 缺失(turn=${String(turn)}, step=${String(step)})——只能以 replace 承载(插件 marker 定义),append 会触发客户端引擎崩溃(rt.js:6816)`));
|
|
438
527
|
}
|
|
439
528
|
}
|
|
440
529
|
return out;
|
|
@@ -457,7 +546,7 @@ export function pluginViolations(event, loc) {
|
|
|
457
546
|
return out;
|
|
458
547
|
}
|
|
459
548
|
|
|
460
|
-
/** 折叠终验:**按文件版本**择路(
|
|
549
|
+
/** 折叠终验:**按文件版本**择路(2026-09-14 补强)。
|
|
461
550
|
*
|
|
462
551
|
* - v3 文件 → 运行时导出的官方 `foldSurface`(与运行时同语义);
|
|
463
552
|
* - v0/v1/v2 文件 → 本地 `legacyFoldSurface`(rc.7 `foldSurface` 逐条移植)。
|
|
@@ -465,7 +554,7 @@ export function pluginViolations(event, loc) {
|
|
|
465
554
|
* 为什么旧格式不能借用官方实现的 `violations` 字段:官方 `foldSurface` **只抛不报**,
|
|
466
555
|
* 旧口径下这里曾回退到 `replaySurface` 的 violations,但**没有任何调用方读它**
|
|
467
556
|
* (validate.js / prewrite.js 只看 `folded.error`)⇒ S8 在旧格式上永不触发——这正是
|
|
468
|
-
*
|
|
557
|
+
* 2026-09-14 六条失败里四条的真因。现在两条路径都是"抛错 = 拒绝"的同一种契约。 */
|
|
469
558
|
export function finalFold(events, version) {
|
|
470
559
|
const fold = currentFold(version);
|
|
471
560
|
try {
|
|
@@ -476,12 +565,12 @@ export function finalFold(events, version) {
|
|
|
476
565
|
}
|
|
477
566
|
|
|
478
567
|
/**
|
|
479
|
-
* T3 —— step 节点 key 冲突(
|
|
568
|
+
* T3 —— step 节点 key 冲突(2026-09-02 · 渲染层白屏事故真正根因固化)。
|
|
480
569
|
*
|
|
481
570
|
* 客户端渲染消息列表 = 从事件流构建节点,节点 key = `data.turn:data.step`
|
|
482
571
|
* (React 列表 key)。同 turn 内两个 step/start 的 step 号相同 → key 冲突 →
|
|
483
572
|
* React 渲染死循环 → 白屏/不展示(实测:同一 turn 内正常轮的 step 95/1 与
|
|
484
|
-
* 编辑块的 step 95/1 冲突;
|
|
573
|
+
* 编辑块的 step 95/1 冲突;2026-09-02 全量扫描又发现多个同型冲突的会话,
|
|
485
574
|
* 均整块重编号修复)。
|
|
486
575
|
*
|
|
487
576
|
* 判定:扫 step/start,`data.turn:data.step` 组合重复 = error。
|
|
@@ -513,7 +602,7 @@ export function stepKeyViolations(events) {
|
|
|
513
602
|
}
|
|
514
603
|
|
|
515
604
|
/**
|
|
516
|
-
* T4 —— step/消息本体 turn 缺失(null/undefined)(
|
|
605
|
+
* T4 —— step/消息本体 turn 缺失(null/undefined)(2026-09-01 · D8 事故固化)。
|
|
517
606
|
*
|
|
518
607
|
* 客户端渲染状态机对 turn=null 的 step/消息**无法归属任何 turn** → 渲染死循环 →
|
|
519
608
|
* 白屏「载入历史」(实测:retrace 0.4.17 写的编辑块
|
|
@@ -541,9 +630,9 @@ export function nullTurnStepViolations(events) {
|
|
|
541
630
|
}
|
|
542
631
|
|
|
543
632
|
/**
|
|
544
|
-
* T5 —— turn/end 缺 reason.kind(
|
|
633
|
+
* T5 —— turn/end 缺 reason.kind(2026-09-02 · malformed turn/end 固化)。
|
|
545
634
|
*
|
|
546
|
-
* 官方 agent-loop 写 turn/end 恒带 `reason: { kind }`(dsh-agent-loop/lib/index.js:
|
|
635
|
+
* 官方 agent-loop 写 turn/end 恒带 `reason: { kind }`(dsh-agent-loop/lib/index.js:620;
|
|
547
636
|
* kind ∈ completed|max-tokens|blocked|aborted|error|interrupted,中断恢复补
|
|
548
637
|
* interrupted,见 dsh-session interruptedTurnClosers)。官方 validation 强制
|
|
549
638
|
* reason.kind 存在——缺失 = malformed → 会话加载失败
|
|
@@ -560,14 +649,14 @@ export function turnEndReasonViolations(events) {
|
|
|
560
649
|
if (event.type !== 'turn/end') continue
|
|
561
650
|
const reason = event.data?.reason
|
|
562
651
|
if (!reason || typeof reason.kind !== 'string') {
|
|
563
|
-
out.push(violation('T5', { seq: event.seq, lineNo, eventType: event.type }, `turn/end 缺 data.reason.kind(reason=${JSON.stringify(reason)})——官方 validation 拒绝 → 会话加载失败(malformed turn/end;turn/end 必须带 reason.kind,镜像 dsh-agent-loop:
|
|
652
|
+
out.push(violation('T5', { seq: event.seq, lineNo, eventType: event.type }, `turn/end 缺 data.reason.kind(reason=${JSON.stringify(reason)})——官方 validation 拒绝 → 会话加载失败(malformed turn/end;turn/end 必须带 reason.kind,镜像 dsh-agent-loop:620)`))
|
|
564
653
|
}
|
|
565
654
|
}
|
|
566
655
|
return out
|
|
567
656
|
}
|
|
568
657
|
|
|
569
658
|
/**
|
|
570
|
-
* E7 —— ignorable 未知 type 合法性(
|
|
659
|
+
* E7 —— ignorable 未知 type 合法性(2026-09-09 T2 增量)。
|
|
571
660
|
*
|
|
572
661
|
* 盲区:E3 对"未知 type + ignorable:true"直接放行(容忍更新版本 harness 写入),
|
|
573
662
|
* 但 ignorable 标记无合法性校验 = 后门——被读路径接纳却无人消费的未知事件 =
|
|
@@ -604,7 +693,7 @@ export function ignorableTypeViolations(events, version) {
|
|
|
604
693
|
export function toolPairingViolations(events) {
|
|
605
694
|
const out = [];
|
|
606
695
|
const calls = new Map(); // callId → { command, loc }
|
|
607
|
-
const results = new Map(); // callId → loc(双向:孤儿 result 也要指认,
|
|
696
|
+
const results = new Map(); // callId → loc(双向:孤儿 result 也要指认,2026-09-09 T1)
|
|
608
697
|
for (const { event, lineNo } of events) {
|
|
609
698
|
if (event.type === 'tool/call') {
|
|
610
699
|
const callId = event.data?.callId;
|
|
@@ -612,7 +701,7 @@ export function toolPairingViolations(events) {
|
|
|
612
701
|
let command = '';
|
|
613
702
|
try {
|
|
614
703
|
const args = typeof event.data?.arguments === 'string' ? JSON.parse(event.data.arguments) : event.data?.arguments;
|
|
615
|
-
command = typeof args?.command === 'string' ? args.command.slice(0,
|
|
704
|
+
command = typeof args?.command === 'string' ? args.command.slice(0, 120) : '';
|
|
616
705
|
} catch { /* 参数解析失败不阻断配对检查 */ }
|
|
617
706
|
calls.set(callId, { command, loc: { seq: event.seq, lineNo, eventType: event.type } });
|
|
618
707
|
}
|
|
@@ -688,7 +777,7 @@ export function toolResultStructureViolations(events) {
|
|
|
688
777
|
|
|
689
778
|
/**
|
|
690
779
|
* T1 —— token-meter 配对(复刻 @deepseek-ai/dsh-token-meter 的 _foldEvent 状态机,
|
|
691
|
-
*
|
|
780
|
+
* 2026-08-28 事故根因 3 固化):
|
|
692
781
|
* - `step/start` 打开一个 step(记录 turn/step);
|
|
693
782
|
* - `step/end` 必须匹配当前打开的 step/start,否则抛错;
|
|
694
783
|
* - `assistant/message` 必须匹配当前打开的 step/start(turn/step 完全一致),否则抛错;
|
|
@@ -734,14 +823,14 @@ export function tokenMeterViolations(events) {
|
|
|
734
823
|
}
|
|
735
824
|
|
|
736
825
|
/**
|
|
737
|
-
* T2 —— token-meter 的 sourceEventSeqs 引用必须同 turn/step(
|
|
826
|
+
* T2 —— token-meter 的 sourceEventSeqs 引用必须同 turn/step(2026-08-30 第二类
|
|
738
827
|
* 刷屏事故固化)。
|
|
739
828
|
*
|
|
740
|
-
* 镜像官方 `_estimateProviderAssistant`(dsh-token-meter lib/index.js:
|
|
829
|
+
* 镜像官方 `_estimateProviderAssistant`(dsh-token-meter lib/index.js:634-650):
|
|
741
830
|
* `assistant/message` 的每个 `sourceEventSeqs` 若指向 `assistant/chunk`,其
|
|
742
831
|
* turn/step 必须与消息自身一致;跨 step 引用 → 官方抛
|
|
743
832
|
* `token meter: assistant/message at seq N source seq M belongs to another step`
|
|
744
|
-
* (lib/index.js:
|
|
833
|
+
* (lib/index.js:645)。
|
|
745
834
|
*
|
|
746
835
|
* 事故现场:DSH resend/regenerate 在 agent 仍开着 step 时被触发,会把旧 step 的
|
|
747
836
|
* chunk 全部引用进新 assistant/message(某真实会话的 chunk 源引用跨 step 7/8/9)→
|
|
@@ -759,7 +848,7 @@ export function tokenMeterSourceViolations(events) {
|
|
|
759
848
|
const turn = event.data?.turn;
|
|
760
849
|
const step = event.data?.step;
|
|
761
850
|
if (turn == null || step == null) continue; // turn-null marker 由 T1 覆盖
|
|
762
|
-
if (event.data?.usage === void 0) continue; // 无 usage 不触发 _estimateProviderAssistant(官方 :
|
|
851
|
+
if (event.data?.usage === void 0) continue; // 无 usage 不触发 _estimateProviderAssistant(官方 :592 前提)——replace marker(S5 遮蔽语义,sourceEventSeqs 含非 chunk 节点)合法
|
|
763
852
|
const seen = new Set();
|
|
764
853
|
for (const s of event.sourceEventSeqs) {
|
|
765
854
|
if (s >= event.seq) {
|
|
@@ -773,7 +862,7 @@ export function tokenMeterSourceViolations(events) {
|
|
|
773
862
|
seen.add(s);
|
|
774
863
|
const src = bySeq.get(s);
|
|
775
864
|
if (!src || src.event.type !== 'assistant/chunk') {
|
|
776
|
-
out.push(violation('T2', { seq: event.seq, lineNo, eventType: event.type }, `assistant/message at seq ${event.seq} source seq ${s} is not assistant/chunk(实际 ${src ? src.event.type : 'MISSING'})——token meter 折叠会抛错(_estimateProviderAssistant :
|
|
865
|
+
out.push(violation('T2', { seq: event.seq, lineNo, eventType: event.type }, `assistant/message at seq ${event.seq} source seq ${s} is not assistant/chunk(实际 ${src ? src.event.type : 'MISSING'})——token meter 折叠会抛错(_estimateProviderAssistant :644 对非 chunk 引用直接 throw),/compact 与压力测量永久失败`));
|
|
777
866
|
break; // 官方抛一次即停(consumedEvents 不前进),只报首条
|
|
778
867
|
}
|
|
779
868
|
if (src.event.data?.turn !== turn || src.event.data?.step !== step) {
|
|
@@ -928,16 +1017,16 @@ export function wireViolations(events, version) {
|
|
|
928
1017
|
* 覆盖(每条都有一手出处,官方 `@0.1.5-rc.2`):
|
|
929
1018
|
* - **G1** `subagent/descriptor.data.version !== 3`
|
|
930
1019
|
* - **G2** 事件类型不在官方 v0 dispositions 内(含 `ignorable:true`)
|
|
931
|
-
* - **G3** `session/title` / `session/title-llm-request` 的 `messageSeqs`(`v0-to-v1/lib/index.js:
|
|
1020
|
+
* - **G3** `session/title` / `session/title-llm-request` 的 `messageSeqs`(`v0-to-v1/lib/index.js:2543-2556`)
|
|
932
1021
|
*
|
|
933
1022
|
* 仍未覆盖(由 `migrationVerdict().coverage.uncovered` 显式列出,**不许**当通过):
|
|
934
1023
|
* `turn/start`(闭合/预期轮)、继承切点、`assistant/attempt` 配对、`stored log corrupt`、
|
|
935
1024
|
* v0→v1 对其余事件的形状拒绝。
|
|
936
1025
|
*
|
|
937
|
-
* **为什么 `turn/start` 不做(实测结论)**:官方那个状态机(`v0-to-v1:
|
|
1026
|
+
* **为什么 `turn/start` 不做(实测结论)**:官方那个状态机(`v0-to-v1:2270` 的
|
|
938
1027
|
* `assertReleasedArtifactRelationships`)**不是**在原始 v0 事件上跑的——它由 **v1→v2**
|
|
939
1028
|
* 以 `RELEASED_V2_RELATIONSHIP_EXTENSIONS` 调用在**变换后的 v1/v2 artifact** 上
|
|
940
|
-
* (`v1-to-v2/lib/index.js:
|
|
1029
|
+
* (`v1-to-v2/lib/index.js:104`),并带 `cut`(继承切点)处理。实测:在原始 v0 上照抄该
|
|
941
1030
|
* 状态机会在**已 seed 的会话**上狂报(样本(某真实会话):v0→v1 官方并不以该规则拒绝,
|
|
942
1031
|
* 而原始 v0 上会报 19 条),属"规则文本对、应用对象错"。要忠实复现必须先把 v0→v1→v2 的
|
|
943
1032
|
* 变换做出来 ⇒ 记未覆盖。
|
|
@@ -973,16 +1062,16 @@ export function migrationPrecheckViolations(events, version, opts = {}) {
|
|
|
973
1062
|
{ ignorable, ignorableRegistered }));
|
|
974
1063
|
}
|
|
975
1064
|
}
|
|
976
|
-
// ── G3 · session/title 系列 messageSeqs(官方 v0→v1 `assertTitleSources`,:
|
|
1065
|
+
// ── G3 · session/title 系列 messageSeqs(官方 v0→v1 `assertTitleSources`,:2543-2556)──
|
|
977
1066
|
// 判据:每个被引 seq 必须解析到更早的 `user/message`,且 `data.source.kind === 'user'`;
|
|
978
1067
|
// 另 `session/title` 的 `source.kind === 'user'` ⟺ `messageSeqs` 空。
|
|
979
1068
|
//
|
|
980
|
-
// ⚠️ 应用面说明(实测
|
|
1069
|
+
// ⚠️ 应用面说明(实测 2026-09-15):官方 `assertTitleSources` 与 `turn/start` 状态机
|
|
981
1070
|
// 同在 `assertReleasedArtifactRelationships` 里,而该函数被 **v1→v2** 以
|
|
982
1071
|
// `RELEASED_V2_RELATIONSHIP_EXTENSIONS` 调用在**变换后的 v1/v2 artifact** 上
|
|
983
|
-
// (`dsh-session-format-v1-to-v2/lib/index.js:
|
|
1072
|
+
// (`dsh-session-format-v1-to-v2/lib/index.js:104`),不是原始 v0 事件。
|
|
984
1073
|
// 对 `messageSeqs` 这类"按 seq 索引 + 事件类型/source 判定"的引用,变换保序保类型
|
|
985
|
-
// ⇒ 在原始 v0
|
|
1074
|
+
// ⇒ 在原始 v0 上判是**必要条件的近似**;实测多处真实 v0 上 **0 误报**。
|
|
986
1075
|
const bySeq = new Map();
|
|
987
1076
|
for (const { event } of events) if (event && typeof event === 'object') bySeq.set(event.seq, event);
|
|
988
1077
|
for (const { event, lineNo } of events) {
|
|
@@ -1013,7 +1102,7 @@ export function migrationPrecheckViolations(events, version, opts = {}) {
|
|
|
1013
1102
|
}
|
|
1014
1103
|
|
|
1015
1104
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
1016
|
-
// 0.3.19 · v4 契约补充最小集(外部评审一手实测,
|
|
1105
|
+
// 0.3.19 · v4 契约补充最小集(外部评审一手实测,2026-10-20)
|
|
1017
1106
|
// 5 条硬规则:S10 / I2 / P5 / G4 / A1。判据只新增/收严,不改既有规则的判定。
|
|
1018
1107
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
1019
1108
|
|
|
@@ -1022,7 +1111,7 @@ export function migrationPrecheckViolations(events, version, opts = {}) {
|
|
|
1022
1111
|
*
|
|
1023
1112
|
* 实测(外部评审一手):化石里存在嵌套 `[a,b]`,`v4test`/投影层/`restore` **全部静默
|
|
1024
1113
|
* 放过** ⇒ 契约层必须判红。但 `[a,b]` 本身是 v3+ 的**官方存储形态**(`encodeSeqRanges`
|
|
1025
|
-
* 把连续 ≥3 的 run
|
|
1114
|
+
* 把连续 ≥3 的 run 压成闭区间对;大规模真实语料真实 v3/v4 里 265 处,全部可被官方
|
|
1026
1115
|
* `decodeSeqRanges` 展开)⇒ 不能把合法的区间对当违规。判红点收严为两层:
|
|
1027
1116
|
* ① **存储形态**(`rawSourceEventSeqViolations`,看 `log.rows[].value`):元素只能是
|
|
1028
1117
|
* 非负安全整数或 `[start,end]`(start ≤ end),且必须能被官方 `decodeSeqRanges`
|
|
@@ -1108,17 +1197,17 @@ export function rawSourceEventSeqViolations(rows) {
|
|
|
1108
1197
|
* I2 —— `seedLength` 语义钉死 + `parentSession ∧ seedLength∈{缺失,0}` 合法(评审最小集 ③)。
|
|
1109
1198
|
*
|
|
1110
1199
|
* 一手依据(`@deepseek-ai/dsh-session-format-v0-to-v1@0.2.0-rc.2`):
|
|
1111
|
-
* - `package/lib/index.js:
|
|
1112
|
-
* - `:
|
|
1113
|
-
* - `:
|
|
1200
|
+
* - `package/lib/index.js:1707` `seedLength` → `inheritedEventCount`(缺省 0);
|
|
1201
|
+
* - `:1720` `isSeeded = record["seedLength"] !== undefined`(是否 seeded **只由字段是否存在决定**);
|
|
1202
|
+
* - `:1517-1520` `inheritedEventCount > events.length` → "Session inheritedEventCount exceeds its event count";`!isSeeded && inheritedEventCount !== 0` → "unseeded Session inheritedEventCount must be 0"。
|
|
1114
1203
|
*
|
|
1115
1204
|
* 结论(不再猜):
|
|
1116
|
-
* - **`parentSession` 有值 ≠ seeded
|
|
1205
|
+
* - **`parentSession` 有值 ≠ seeded**:血缘关系与继承计数是两件事。大规模真实语料
|
|
1117
1206
|
* v3/v4 头带 `parentSession` 且**无** `seedLength`(`isSeeded:false`)仍正常加载 ⇒
|
|
1118
1207
|
* `parentSession ∧ seedLength∈{缺失,0}` 判 **合法**(不告警、不拒)。
|
|
1119
|
-
* - `seedLength` 超过**展开后**事件数 ⇒ error
|
|
1120
|
-
* vs
|
|
1121
|
-
* - v4 运行时头**禁** `seedLength`(dsh-session@0.2.0-rc.2 lib/index.js:
|
|
1208
|
+
* - `seedLength` 超过**展开后**事件数 ⇒ error(多份真实语料 v0 化石命中:153113/531084/683896
|
|
1209
|
+
* vs 34841/12973/20268 —— 这些值明显是字节数/其它口径,官方迁移必拒)。
|
|
1210
|
+
* - v4 运行时头**禁** `seedLength`(dsh-session@0.2.0-rc.2 lib/index.js:1040)⇒ v4 文件带该字段 error。
|
|
1122
1211
|
*
|
|
1123
1212
|
* @param {object|null} header
|
|
1124
1213
|
* @param {Array<object>} events 展开后事件(chunk 行已展开),用于比较继承条数
|
|
@@ -1131,7 +1220,7 @@ export function seedLengthViolations(header, events, version) {
|
|
|
1131
1220
|
const has = Object.hasOwn(header, 'seedLength');
|
|
1132
1221
|
if (version >= 4) {
|
|
1133
1222
|
if (has) {
|
|
1134
|
-
out.push(violation('I2', {}, `v4 会话头不得带 seedLength(实际 ${String(header.seedLength)})——宿主 header 校验直接拒:"session header has invalid field \\"seedLength\\""(dsh-session@0.2.0-rc.2 lib/index.js:
|
|
1223
|
+
out.push(violation('I2', {}, `v4 会话头不得带 seedLength(实际 ${String(header.seedLength)})——宿主 header 校验直接拒:"session header has invalid field \\"seedLength\\""(dsh-session@0.2.0-rc.2 lib/index.js:1040);v4 用 isSeeded + 构造器 inheritedEventCount,不落盘该字段`));
|
|
1135
1224
|
}
|
|
1136
1225
|
return out;
|
|
1137
1226
|
}
|
|
@@ -1143,7 +1232,7 @@ export function seedLengthViolations(header, events, version) {
|
|
|
1143
1232
|
}
|
|
1144
1233
|
const count = Array.isArray(events) ? events.length : 0;
|
|
1145
1234
|
if (seedLength > count) {
|
|
1146
|
-
out.push(violation('I2', {}, `header.seedLength=${seedLength} 大于展开后事件数 ${count}——seedLength 语义是**继承事件条数**(官方 inheritedEventCount),不是字节数/行数;官方解码/迁移会抛 "Session inheritedEventCount exceeds its event count"(dsh-session-format-v0-to-v1@0.2.0-rc.2 :
|
|
1235
|
+
out.push(violation('I2', {}, `header.seedLength=${seedLength} 大于展开后事件数 ${count}——seedLength 语义是**继承事件条数**(官方 inheritedEventCount),不是字节数/行数;官方解码/迁移会抛 "Session inheritedEventCount exceeds its event count"(dsh-session-format-v0-to-v1@0.2.0-rc.2 :1517-1520)`));
|
|
1147
1236
|
}
|
|
1148
1237
|
return out;
|
|
1149
1238
|
}
|
|
@@ -1178,13 +1267,13 @@ export function carrierRangesMatch(audit, carrier, version) {
|
|
|
1178
1267
|
/**
|
|
1179
1268
|
* P5 —— carrier 两段配对(评审最小集 ④;读侧)。
|
|
1180
1269
|
*
|
|
1181
|
-
* 现役写法(实测
|
|
1270
|
+
* 现役写法(实测 888/888 真实载体):`sourceEventSeqs = [审计段 seq, ...被遮蔽节点]`;
|
|
1182
1271
|
* 第 2 段 = 紧随审计段的 surface replace。规则:
|
|
1183
1272
|
* - 审计段 seq 在 **首元素** ⇒ 通过(现役);
|
|
1184
1273
|
* - 在 **末元素** ⇒ 通过(旧顺序,读侧容错),给 warning(不静默);
|
|
1185
1274
|
* - 在中间位 / 载体紧邻审计段却**完全没引用**它 ⇒ error(配对失败 / 孤儿审计段)。
|
|
1186
1275
|
* 官方 compaction 的 `compaction/summary` 引用是另一形状(`[compaction/start, summary, …]`),
|
|
1187
|
-
* 审计段类型限定 `compaction/prune`
|
|
1276
|
+
* 审计段类型限定 `compaction/prune` 天然不误报(实测样例)。
|
|
1188
1277
|
*
|
|
1189
1278
|
* @param {Array<{event:object,lineNo?:number}>} events 行序事件
|
|
1190
1279
|
* @param {{version?:number}} [opts] 被检文件版本(决定 replace 字段名)
|
|
@@ -1212,7 +1301,7 @@ export function carrierPairingViolations(events, { version = 0 } = {}) {
|
|
|
1212
1301
|
// 读侧**两种写法都认**(外部评审要求;两种都在真实语料里出现过):
|
|
1213
1302
|
// ① 现役:`[审计段 seq, ...被遮蔽节点]`(审计段 seq 在首位);
|
|
1214
1303
|
// ② 早期:`[区间起点, ...被遮蔽节点]`(**不引用**审计段 seq;"区间起点"= replace 范围
|
|
1215
|
-
// 起点:实测真实语料
|
|
1304
|
+
// 起点:实测真实语料 1,519 个载体即此写法)。
|
|
1216
1305
|
// 两种都不报;其余(审计段 seq 在中间位、或首元素既非审计段也非区间起点)= 配对失败。
|
|
1217
1306
|
const range = surfaceReplaceRange(event.surfaceOp, version);
|
|
1218
1307
|
const legacyStartFirst = range !== null && src[0] === range.start;
|
package/lib/compat.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dsh-log-contract · lib/compat.js —— 兼容层(任务 1.3 · 装即坏修复;
|
|
2
|
+
* dsh-log-contract · lib/compat.js —— 兼容层(任务 1.3 · 装即坏修复;2026-09-14 语义对齐重写)
|
|
3
3
|
*
|
|
4
4
|
* 背景:本包原先从 `@deepseek-ai/dsh-session` 直接导入 `decodeStorageRecord` 与 `isJsonValue`。
|
|
5
5
|
* 官方 0.1.5 树已**不再从包根导出**这两个符号(0.1.5-rc.1 `lib/index.js` 的 26 个导出里没有它们),
|
|
@@ -9,14 +9,14 @@
|
|
|
9
9
|
* `decodeStorageRecord` 对损坏 chunk 行返回 `[value]` 而非抛错,导致 R2 永不触发;
|
|
10
10
|
* `isJsonValue` 不拒 `-0`、不拒稀疏数组、不查原型——与官方 lossless-JSON 边界不一致)。
|
|
11
11
|
*
|
|
12
|
-
* 移植源(一手,
|
|
12
|
+
* 移植源(一手,2026-09-14 实测):
|
|
13
13
|
* - `decodeStorageRecord` / `validateRow` / `expandRow`:
|
|
14
|
-
* `@deepseek-ai/dsh-session@0.1.0-rc.7` `lib/index.js:
|
|
14
|
+
* `@deepseek-ai/dsh-session@0.1.0-rc.7` `lib/index.js:922-1035`(该版本是最后一个把
|
|
15
15
|
* `decodeStorageRecord` 从包根导出的版本;与 App 2.0.9 内置的
|
|
16
|
-
* `dsh-session/lib/types/chunk-rows.js`(= 0.1.2-rc.1,
|
|
16
|
+
* `dsh-session/lib/types/chunk-rows.js`(= 0.1.2-rc.1,sha256 前 16 位 `5724c4f798ed07e7`)
|
|
17
17
|
* 校验规则一致)。**fail-loud**:损坏的 chunk 行必须抛错——它是损坏存储,静默当普通事件
|
|
18
18
|
* 处理会丢掉整段 run。
|
|
19
|
-
* - `isJsonValue`:`@deepseek-ai/dsh-session@0.1.0-rc.7` `lib/index.js:74-
|
|
19
|
+
* - `isJsonValue`:`@deepseek-ai/dsh-session@0.1.0-rc.7` `lib/index.js:74-205`
|
|
20
20
|
* `walkJsonValue(value, false)`(lossless-JSON 边界:拒绝稀疏数组、非有限数、`-0`、
|
|
21
21
|
* 循环引用、非普通原型、symbol/不可枚举键)。
|
|
22
22
|
*
|
|
@@ -208,9 +208,9 @@ export function decodeStorageRecord(value) {
|
|
|
208
208
|
// (见 vocab.js 的双宿主声明)。本包 peer 允许两个版本 ⇒ 必须在两种宿主上都能解码。
|
|
209
209
|
//
|
|
210
210
|
// 语义(官方 `seq-ranges.js:34-73`):`sourceEventSeqs` 的 JSON 存储形态是"数字 + 闭区间对"
|
|
211
|
-
// 混合数组,例 `[3, [
|
|
211
|
+
// 混合数组,例 `[3, [174,176], 180, …]` ⇒ 内存形态 `[3,174,175,176,180,…]`。
|
|
212
212
|
// v3 持久化层对连续段用区间对压缩(App 2.0.9 真实 v3 会话实测:1 个 `user/message` replace
|
|
213
|
-
// 的 `sourceEventSeqs`
|
|
213
|
+
// 的 `sourceEventSeqs` 2251 个存储项展开为 2259 个 seq)。**不解码 = 拿物理未展开的序列
|
|
214
214
|
// 喂 S5/S6 与官方 foldSurface ⇒ 真实健康会话被误判 S5/S6/S8 + `--resume` broken。**
|
|
215
215
|
|
|
216
216
|
/** 非负安全整数(rc.7/0.1.5 `assertSeq`)。 */
|