dsh-log-contract 0.3.25 → 0.3.28
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 +127 -45
- package/README.zh.md +106 -45
- package/bin/dsh-log-contract.mjs +13 -13
- package/docs/CONTRACTS.md +83 -55
- package/lib/archaeology.js +38 -22
- package/lib/archive.js +21 -21
- package/lib/checks.js +64 -64
- package/lib/compat.js +7 -7
- package/lib/contracts.js +88 -56
- package/lib/host-probes.js +4 -4
- package/lib/legacy-fold.js +5 -5
- package/lib/log-reader.js +82 -17
- package/lib/prewrite.js +23 -7
- package/lib/repair.js +34 -34
- package/lib/validate.js +39 -11
- package/lib/version-support.js +2 -2
- package/lib/vocab.js +8 -8
- package/package.json +6 -2
package/lib/archive.js
CHANGED
|
@@ -8,16 +8,16 @@
|
|
|
8
8
|
* 只有在调用方提供归档根目录时才能回答"在位可还原",否则只能回答"不可判定"——
|
|
9
9
|
* **不许**把"没查"冒充成"通过"。
|
|
10
10
|
*
|
|
11
|
-
* 口径(外部评审一手实测,
|
|
11
|
+
* 口径(外部评审一手实测,[n]-10-20):
|
|
12
12
|
* - 只认**结构化字段**:`data.archiveRef` / `data.archive` /
|
|
13
13
|
* `data.externalized.archiveRef` / `data.externalized.archive`;
|
|
14
|
-
* 校验元数据取同级 `archiveLine` / `
|
|
14
|
+
* 校验元数据取同级 `archiveLine` / `sha[n]`。
|
|
15
15
|
* - ⛔ **不得**从自由文本 grep 路径。实测两版文本口径全错:原版给 78.26%
|
|
16
16
|
* (正文模板/示例被算成引用)、改成"只认绝对路径"后 2.04%(正文里提到的真实路径示例
|
|
17
|
-
* 又虚低)。本机
|
|
18
|
-
* 出现在
|
|
17
|
+
* 又虚低)。本机 [n] 份真实会话:结构化指针 [n] 个,自由文本 `archive 第 N 行`
|
|
18
|
+
* 出现在 [n] 个事件里——两种口径差近 20 倍,文本 grep 不可用。
|
|
19
19
|
*
|
|
20
|
-
* 判据:目标文件存在 + `archiveLine` 行存在 + `
|
|
20
|
+
* 判据:目标文件存在 + `archiveLine` 行存在 + `sha[n]`(若有)匹配 = 在位可还原;
|
|
21
21
|
* 目标缺失/行缺失/sha 不符 = A1 error;绝对路径失效但同名归档在归档根可解析 = relocated
|
|
22
22
|
* warning(re-home 未回写:内容可找回,但**不在位**)。
|
|
23
23
|
*/
|
|
@@ -27,7 +27,7 @@ import crypto from 'node:crypto';
|
|
|
27
27
|
import { violation } from './checks.js';
|
|
28
28
|
import { decompressZstd } from './log-reader.js';
|
|
29
29
|
|
|
30
|
-
const ZSTD_MAGIC =
|
|
30
|
+
const ZSTD_MAGIC = 0xfd2fb[n];
|
|
31
31
|
|
|
32
32
|
/** 结构化指针字段(只认这些;`content`/`pointer`/散文一律不碰)。 */
|
|
33
33
|
export const ARCHIVE_POINTER_FIELDS = Object.freeze(['archiveRef', 'archive']);
|
|
@@ -48,7 +48,7 @@ function pushPointer(out, event, lineNo, field, ref, line, sha) {
|
|
|
48
48
|
field,
|
|
49
49
|
ref,
|
|
50
50
|
archiveLine: Number.isSafeInteger(line) ? line : null,
|
|
51
|
-
|
|
51
|
+
sha[n]: typeof sha === 'string' && sha !== '' ? sha : null,
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -59,7 +59,7 @@ function pushPointer(out, event, lineNo, field, ref, line, sha) {
|
|
|
59
59
|
* (手搓用例/第三方直接传事件数组)。
|
|
60
60
|
*
|
|
61
61
|
* @param {Array<{event:object,lineNo?:number}|object>} events
|
|
62
|
-
* @returns {Array<{seq:number|null,lineNo:number|null,type:string|null,field:string,ref:string,archiveLine:number|null,
|
|
62
|
+
* @returns {Array<{seq:number|null,lineNo:number|null,type:string|null,field:string,ref:string,archiveLine:number|null,sha[n]:string|null}>}
|
|
63
63
|
*/
|
|
64
64
|
export function collectArchivePointers(events) {
|
|
65
65
|
const out = [];
|
|
@@ -71,13 +71,13 @@ export function collectArchivePointers(events) {
|
|
|
71
71
|
if (!isPlainRecord(data)) continue;
|
|
72
72
|
for (const field of ARCHIVE_POINTER_FIELDS) {
|
|
73
73
|
if (data[field] === undefined) continue;
|
|
74
|
-
pushPointer(out, event, lineNo, `data.${field}`, data[field], data.archiveLine, data.
|
|
74
|
+
pushPointer(out, event, lineNo, `data.${field}`, data[field], data.archiveLine, data.sha[n] ?? data.archiveSha[n]);
|
|
75
75
|
}
|
|
76
76
|
const ext = data.externalized;
|
|
77
77
|
if (isPlainRecord(ext)) {
|
|
78
78
|
for (const field of EXTERNALIZED_POINTER_FIELDS) {
|
|
79
79
|
if (ext[field] === undefined) continue;
|
|
80
|
-
pushPointer(out, event, lineNo, `data.externalized.${field}`, ext[field], ext.archiveLine, ext.
|
|
80
|
+
pushPointer(out, event, lineNo, `data.externalized.${field}`, ext[field], ext.archiveLine, ext.sha[n] ?? ext.archiveSha[n]);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -136,7 +136,7 @@ function searchByBasename(dir, base, depth, index) {
|
|
|
136
136
|
|
|
137
137
|
/**
|
|
138
138
|
* 读归档文件的**行索引**(只保留请求的行;巨型归档不能整体 `toString`:
|
|
139
|
-
* >
|
|
139
|
+
* >[n]MiB 明文会触发 V8 字符串上限——那是器具限制,不是内容缺失,必须避免把它误报成 A1)。
|
|
140
140
|
*
|
|
141
141
|
* @param {string} file 归档路径(.jsonl.zst 走多帧解压;.jsonl 直接 utf8)
|
|
142
142
|
* @param {Set<number>} [wantedLines] 需要的 1-based 行号
|
|
@@ -172,14 +172,14 @@ export function readArchiveLines(file) {
|
|
|
172
172
|
return lines;
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
/**
|
|
176
|
-
function
|
|
177
|
-
return crypto.createHash('
|
|
175
|
+
/** sha[n](十六进制);匹配时允许 16 位前缀(深 H2 以 line16 为准,sha[n] 作对照)。 */
|
|
176
|
+
function sha[n]Hex(text) {
|
|
177
|
+
return crypto.createHash('sha[n]').update(text).digest('hex');
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
function shaMatches(line, want) {
|
|
181
181
|
if (typeof want !== 'string' || want.length < 16) return true; // 无/过短指纹 ⇒ 不做深校验(不猜)
|
|
182
|
-
const got =
|
|
182
|
+
const got = sha[n]Hex(line);
|
|
183
183
|
const w = want.toLowerCase();
|
|
184
184
|
if (w.length >= 64) return got === w.slice(0, 64);
|
|
185
185
|
return got.startsWith(w) || w.startsWith(got.slice(0, w.length));
|
|
@@ -235,14 +235,14 @@ export function verifyArchivePointers(pointers, { archiveRoots = [], readLines }
|
|
|
235
235
|
if (result.details.unresolved.length < 20) result.details.unresolved.push({ seq: pointer.seq, field: pointer.field, ref: pointer.ref });
|
|
236
236
|
continue;
|
|
237
237
|
}
|
|
238
|
-
const dedupeKey = `${target}\
|
|
238
|
+
const dedupeKey = `${target}\u[n]${pointer.archiveLine ?? ''}`;
|
|
239
239
|
if (seen.has(dedupeKey)) { result.duplicated++; continue; }
|
|
240
240
|
seen.add(dedupeKey);
|
|
241
241
|
unique.push({ pointer, target, relocated });
|
|
242
242
|
}
|
|
243
243
|
result.effectivePointers = unique.length;
|
|
244
244
|
// ② 按目标分组,一次扫描取回需要的行(巨型归档不能整体 toString:
|
|
245
|
-
// >
|
|
245
|
+
// >[n]MiB 明文会触发 V8 字符串上限,那是器具限制、不是内容缺失)。
|
|
246
246
|
const byTarget = new Map();
|
|
247
247
|
for (const item of unique) {
|
|
248
248
|
if (!byTarget.has(item.target)) byTarget.set(item.target, []);
|
|
@@ -255,7 +255,7 @@ export function verifyArchivePointers(pointers, { archiveRoots = [], readLines }
|
|
|
255
255
|
archiveIndex = (readLines ?? readArchiveIndex)(target, wanted);
|
|
256
256
|
if (Array.isArray(archiveIndex)) archiveIndex = { count: archiveIndex.length, lineAt: (n) => archiveIndex[n - 1] ?? '' };
|
|
257
257
|
} catch (err) {
|
|
258
|
-
const message = String(err?.message ?? err).slice(0,
|
|
258
|
+
const message = String(err?.message ?? err).slice(0, [n]);
|
|
259
259
|
for (const { pointer } of items) {
|
|
260
260
|
result.missing++;
|
|
261
261
|
if (result.details.missing.length < 20) result.details.missing.push({ seq: pointer.seq, field: pointer.field, ref: pointer.ref, target, reason: message });
|
|
@@ -273,10 +273,10 @@ export function verifyArchivePointers(pointers, { archiveRoots = [], readLines }
|
|
|
273
273
|
continue;
|
|
274
274
|
}
|
|
275
275
|
const line = archiveIndex.lineAt(lineNo);
|
|
276
|
-
if (!shaMatches(line, pointer.
|
|
276
|
+
if (!shaMatches(line, pointer.sha[n])) {
|
|
277
277
|
result.shaMismatch++;
|
|
278
|
-
if (result.details.shaMismatch.length < 20) result.details.shaMismatch.push({ seq: pointer.seq, field: pointer.field, ref: pointer.ref, target, archiveLine: lineNo, want: pointer.
|
|
279
|
-
result.violations.push(violation('A1', loc, `归档内容指纹不符:${pointer.field} → ${pointer.ref} 第 ${lineNo} 行
|
|
278
|
+
if (result.details.shaMismatch.length < 20) result.details.shaMismatch.push({ seq: pointer.seq, field: pointer.field, ref: pointer.ref, target, archiveLine: lineNo, want: pointer.sha[n]?.slice(0, 16), got: sha[n]Hex(line).slice(0, 16) });
|
|
279
|
+
result.violations.push(violation('A1', loc, `归档内容指纹不符:${pointer.field} → ${pointer.ref} 第 ${lineNo} 行 sha[n] 期望 ${pointer.sha[n]?.slice(0, 16)}…,实际 ${sha[n]Hex(line).slice(0, 16)}…——归档已漂移,不可在位还原`));
|
|
280
280
|
continue;
|
|
281
281
|
}
|
|
282
282
|
if (relocated) {
|
package/lib/checks.js
CHANGED
|
@@ -13,7 +13,7 @@ import { currentVocabulary, currentFold, V0_EVENT_TYPES } from './vocab.js';
|
|
|
13
13
|
import { ruleById } 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:[n]-[n]`)。 */
|
|
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']);
|
|
@@ -73,29 +73,29 @@ export function envelopeViolations(event, loc, version) {
|
|
|
73
73
|
if (event.type === 'request/header' && event.data?.reason === 'fallback') {
|
|
74
74
|
out.push(violation('E5', loc, 'request/header 使用已删除的遗留 reason "fallback"'));
|
|
75
75
|
}
|
|
76
|
-
// ──
|
|
76
|
+
// ── [n]-09-14 实测:3 例确证漏检补成候选规则 ───────────────────────
|
|
77
77
|
// E8 信封键白名单:宿主 `assertSessionEventEnvelope`(@deepseek-ai/dsh-session@0.1.5-rc.1
|
|
78
|
-
// lib/index.js:
|
|
78
|
+
// lib/index.js:[n]-[n])逐键 switch,只认 7 个键,其余一律 `invalid event envelope`。
|
|
79
79
|
// 实测反例:宿主拒、旧契约 0 违规。
|
|
80
80
|
if (typeof event === 'object' && event !== null) {
|
|
81
81
|
const extra = Object.keys(event).filter((k) => !ENVELOPE_ALLOWED_KEYS.has(k));
|
|
82
82
|
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:
|
|
83
|
+
out.push(violation('E8', loc, `事件信封含多余键 ${extra.join(', ')}——宿主只认 {${[...ENVELOPE_ALLOWED_KEYS].join(',')}}(dsh-session@0.1.5-rc.1 lib/index.js:[n]-[n])`));
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
// E10 request/header 的 data 字段约束:宿主 `validateSessionEventData`
|
|
87
|
-
// (dsh-session@0.1.5-rc.1 lib/index.js:
|
|
87
|
+
// (dsh-session@0.1.5-rc.1 lib/index.js:[n]-[n])——`header.system` 必须省略、
|
|
88
88
|
// 空 tools / 空 adapterDefaults 必须省略。实测反例:宿主拒、旧契约 0 违规。
|
|
89
89
|
if (event.type === 'request/header') {
|
|
90
90
|
const header = event.data?.header;
|
|
91
91
|
if (typeof header !== 'object' || header === null || Array.isArray(header)) {
|
|
92
92
|
out.push(violation('E10', loc, 'request/header 的 data.header 必须是对象'));
|
|
93
93
|
} 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:
|
|
94
|
+
if (Object.hasOwn(header, 'system')) out.push(violation('E10', loc, 'request/header 必须省略 header.system(系统提示改走 system/message)——宿主 lib/index.js:[n]'));
|
|
95
|
+
if (Array.isArray(header.tools) && header.tools.length === 0) out.push(violation('E10', loc, 'request/header 必须省略空 tools——宿主 lib/index.js:[n]'));
|
|
96
96
|
const defaults = header.adapterDefaults;
|
|
97
97
|
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:
|
|
98
|
+
out.push(violation('E10', loc, 'request/header 必须省略空 adapterDefaults——宿主 lib/index.js:[n]-[n]'));
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
}
|
|
@@ -103,10 +103,10 @@ export function envelopeViolations(event, loc, version) {
|
|
|
103
103
|
return out;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
/** 宿主信封键白名单(assertSessionEventEnvelope,dsh-session@0.1.5-rc.1 lib/index.js:
|
|
106
|
+
/** 宿主信封键白名单(assertSessionEventEnvelope,dsh-session@0.1.5-rc.1 lib/index.js:[n]-[n])。 */
|
|
107
107
|
export const ENVELOPE_ALLOWED_KEYS = new Set(['type', 'seq', 'time', 'data', 'surfaceOp', 'sourceEventSeqs', 'ignorable']);
|
|
108
108
|
|
|
109
|
-
/** v4 消息类事件 → 期望 role(dsh-session@0.2.0-rc.2 `MESSAGE_ROLE_BY_TYPE`,`src/index.ts:
|
|
109
|
+
/** v4 消息类事件 → 期望 role(dsh-session@0.2.0-rc.2 `MESSAGE_ROLE_BY_TYPE`,`src/index.ts:[n]-[n]`)。 */
|
|
110
110
|
const V4_MESSAGE_ROLE_BY_TYPE = {
|
|
111
111
|
'system/message': 'system',
|
|
112
112
|
'developer/message': 'developer',
|
|
@@ -116,14 +116,14 @@ const V4_MESSAGE_ROLE_BY_TYPE = {
|
|
|
116
116
|
};
|
|
117
117
|
|
|
118
118
|
/**
|
|
119
|
-
* 镜像官方 assertMessageEventShape(lib/index.js:
|
|
119
|
+
* 镜像官方 assertMessageEventShape(lib/index.js:[n]-[n])。**按被检文件版本**择路:
|
|
120
120
|
* v0–v3 → 旧形状(下方原逻辑);v4 → `v4MessageShapeViolations`。
|
|
121
121
|
*/
|
|
122
122
|
export function messageShapeViolations(event, loc, version) {
|
|
123
123
|
if (version >= 4) return v4MessageShapeViolations(event, loc);
|
|
124
124
|
const type = event.type;
|
|
125
125
|
// 把 v3 新增的 `system/message` 纳入形状检查(MESSAGE_ROLE_BY_TYPE:system/message → system,
|
|
126
|
-
// dsh-session@0.1.5-rc.1 lib/index.js:
|
|
126
|
+
// dsh-session@0.1.5-rc.1 lib/index.js:[n]-[n];source 要求 :[n]-[n])。旧实现只查 user/assistant/tool
|
|
127
127
|
// ⇒ 实测反例(system/message 的 source.kind='user')宿主拒、旧契约 0 违规。
|
|
128
128
|
if (type !== 'user/message' && type !== 'assistant/message' && type !== 'tool/result' && type !== 'system/message') return [];
|
|
129
129
|
const out = [];
|
|
@@ -156,9 +156,9 @@ export function messageShapeViolations(event, loc, version) {
|
|
|
156
156
|
}
|
|
157
157
|
if (type === 'system/message') {
|
|
158
158
|
// E9(候选规则):system/message 必须 plugin source(kind==='plugin' + plugin 非空)。
|
|
159
|
-
// 宿主依据:dsh-session@0.1.5-rc.1 lib/index.js:
|
|
159
|
+
// 宿主依据:dsh-session@0.1.5-rc.1 lib/index.js:[n]-[n]("must have plugin source")。
|
|
160
160
|
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:
|
|
161
|
+
out.push(violation('E9', loc, `${shape()}:system/message 必须带 plugin source(kind==='plugin' 且 plugin 非空)——宿主 lib/index.js:[n]-[n]`));
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
if (type === 'tool/result') {
|
|
@@ -178,9 +178,9 @@ export function messageShapeViolations(event, loc, version) {
|
|
|
178
178
|
|
|
179
179
|
/**
|
|
180
180
|
* v4 消息形状。两层一手依据:
|
|
181
|
-
* - 运行时 load 路径:dsh-session@0.2.0-rc.2 `assertMessageEventShape`(`src/index.ts:
|
|
181
|
+
* - 运行时 load 路径:dsh-session@0.2.0-rc.2 `assertMessageEventShape`(`src/index.ts:[n]-[n]`)——
|
|
182
182
|
* role 表、system-prompt source、model source、tool source + `toolCallId` 匹配;
|
|
183
|
-
* - 文件读取路径:`dsh-session-format-v3-to-v4` 原生 v4 准入(`src/tool-role.ts:89-
|
|
183
|
+
* - 文件读取路径:`dsh-session-format-v3-to-v4` 原生 v4 准入(`src/tool-role.ts:89-[n]`、
|
|
184
184
|
* `src/message-sources.ts:9`)——残留 `tool-result` 包装块、非布尔 `isError`、`data.error` 而
|
|
185
185
|
* `isError !== true`、`source.kind === 'plugin'` 一律 SessionFormatError ⇒ 会话从盘上读不回来。
|
|
186
186
|
* `adoptSessionEvent` 不查这几条,所以只看运行时会漏掉"写得进、读不回"的形状。
|
|
@@ -226,7 +226,7 @@ function v4MessageShapeViolations(event, loc) {
|
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
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:
|
|
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:[n]-[n]`));
|
|
230
230
|
}
|
|
231
231
|
if (type === 'tool/result') {
|
|
232
232
|
if (source?.kind !== 'tool' || typeof source.callId !== 'string' || source.callId === '') {
|
|
@@ -247,7 +247,7 @@ function v4MessageShapeViolations(event, loc) {
|
|
|
247
247
|
return out;
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
/** replace 操作数精确形状(镜像旧格式 isReplaceOp,lib/index.js:
|
|
250
|
+
/** replace 操作数精确形状(镜像旧格式 isReplaceOp,lib/index.js:[n]-[n])。 */
|
|
251
251
|
export function isReplaceOp(op) {
|
|
252
252
|
return (
|
|
253
253
|
typeof op === 'object' && op !== null &&
|
|
@@ -261,7 +261,7 @@ export function isReplaceOp(op) {
|
|
|
261
261
|
* 按**被检文件版本**归一化 replace 操作数到内部 `{start,end}`。
|
|
262
262
|
*
|
|
263
263
|
* 一手依据:官方 replace 字段在 v3 改名——旧格式(v0/v1/v2)`{op,start,end}`,
|
|
264
|
-
* v3 `{op,startSeq,endSeq}`(`dsh-session-format-v2-to-v3/lib/index.js:
|
|
264
|
+
* v3 `{op,startSeq,endSeq}`(`dsh-session-format-v2-to-v3/lib/index.js:[n]-[n]`)。
|
|
265
265
|
* 用错形状会得 null,由调用方归因为 S4(真实违规)。
|
|
266
266
|
*
|
|
267
267
|
* @param {unknown} op 待归一化的 surfaceOp
|
|
@@ -281,12 +281,12 @@ export function normalizeReplaceOp(op, version) {
|
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
/**
|
|
284
|
-
* S9 —— 文件物理序 seq 单调(
|
|
284
|
+
* S9 —— 文件物理序 seq 单调([n]-08-30 事故固化;交接书 L2)。
|
|
285
285
|
*
|
|
286
286
|
* 按**文件物理行序**(非 seq 排序)要求展开后的事件 seq 严格单调递增。
|
|
287
287
|
* 单进程 append 不可能写出非单调物理序(appendCore 断言 seq==cursor+i 且按
|
|
288
288
|
* id 串行化)——非单调 = 多写入者/旧光标回放交织的现场特征(某真实会话:物理序
|
|
289
|
-
*
|
|
289
|
+
* [n]→[n]→[n])。E2 只查「排序后连续」,排序会掩盖物理序倒退;
|
|
290
290
|
* S9 补「物理序单调」盲区。
|
|
291
291
|
*
|
|
292
292
|
* @param rows - loadSessionLog 的 rows(物理行序,每行含 decoded 数组)。
|
|
@@ -328,10 +328,10 @@ export function replaySurface(events, version) {
|
|
|
328
328
|
|
|
329
329
|
if (!eligible) {
|
|
330
330
|
if (op !== undefined || src !== undefined) {
|
|
331
|
-
// ──
|
|
331
|
+
// ── [n]-09-14 实测:这里的 S2 是误报 ───────────────────────────────
|
|
332
332
|
// 宿主 `@deepseek-ai/dsh-session@0.1.5-rc.1` 是**刻意容忍**的:
|
|
333
|
-
// lib/index.js:
|
|
334
|
-
// 同一函数的契约注释 lib/index.js:
|
|
333
|
+
// lib/index.js:[n] `if (!KNOWN_SESSION_EVENT_TYPES.has(event.type) && event.ignorable === true) return;`
|
|
334
|
+
// 同一函数的契约注释 lib/index.js:[n] —— "Unknown ignorable records retain opaque
|
|
335
335
|
// metadata and never change the surface."
|
|
336
336
|
// ⇒ **未知**类型且 `ignorable===true` 的事件带 surfaceOp/sourceEventSeqs 是合法的不透明
|
|
337
337
|
// 元数据(宿主收;实测反例:宿主收、旧契约 S2/error)。这里不再报 S2。
|
|
@@ -379,7 +379,7 @@ export function replaySurface(events, version) {
|
|
|
379
379
|
return { violations, nodes, replaceGeneration };
|
|
380
380
|
}
|
|
381
381
|
|
|
382
|
-
/** 镜像官方 assertProvenance(lib/index.js:
|
|
382
|
+
/** 镜像官方 assertProvenance(lib/index.js:[n]-[n])。 */
|
|
383
383
|
export function provenanceViolations(event, loc, shadowedSeqs) {
|
|
384
384
|
const out = [];
|
|
385
385
|
const raw = event.sourceEventSeqs;
|
|
@@ -415,7 +415,7 @@ export function provenanceViolations(event, loc, shadowedSeqs) {
|
|
|
415
415
|
return out;
|
|
416
416
|
}
|
|
417
417
|
|
|
418
|
-
/** 镜像官方 assertToolResultRewrite(lib/index.js:
|
|
418
|
+
/** 镜像官方 assertToolResultRewrite(lib/index.js:[n]-[n])的判定核心。 */
|
|
419
419
|
export function toolResultRewriteViolations(event, loc, shadowedSeqs) {
|
|
420
420
|
if (event.type !== 'tool/result') return [];
|
|
421
421
|
const out = [];
|
|
@@ -434,7 +434,7 @@ export function engineViolations(event, loc) {
|
|
|
434
434
|
const turn = event.data?.turn;
|
|
435
435
|
const step = event.data?.step;
|
|
436
436
|
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:
|
|
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:[n])`));
|
|
438
438
|
}
|
|
439
439
|
}
|
|
440
440
|
return out;
|
|
@@ -457,7 +457,7 @@ export function pluginViolations(event, loc) {
|
|
|
457
457
|
return out;
|
|
458
458
|
}
|
|
459
459
|
|
|
460
|
-
/** 折叠终验:**按文件版本**择路(
|
|
460
|
+
/** 折叠终验:**按文件版本**择路([n]-09-14 补强)。
|
|
461
461
|
*
|
|
462
462
|
* - v3 文件 → 运行时导出的官方 `foldSurface`(与运行时同语义);
|
|
463
463
|
* - v0/v1/v2 文件 → 本地 `legacyFoldSurface`(rc.7 `foldSurface` 逐条移植)。
|
|
@@ -465,7 +465,7 @@ export function pluginViolations(event, loc) {
|
|
|
465
465
|
* 为什么旧格式不能借用官方实现的 `violations` 字段:官方 `foldSurface` **只抛不报**,
|
|
466
466
|
* 旧口径下这里曾回退到 `replaySurface` 的 violations,但**没有任何调用方读它**
|
|
467
467
|
* (validate.js / prewrite.js 只看 `folded.error`)⇒ S8 在旧格式上永不触发——这正是
|
|
468
|
-
*
|
|
468
|
+
* [n]-09-14 六条失败里四条的真因。现在两条路径都是"抛错 = 拒绝"的同一种契约。 */
|
|
469
469
|
export function finalFold(events, version) {
|
|
470
470
|
const fold = currentFold(version);
|
|
471
471
|
try {
|
|
@@ -476,12 +476,12 @@ export function finalFold(events, version) {
|
|
|
476
476
|
}
|
|
477
477
|
|
|
478
478
|
/**
|
|
479
|
-
* T3 —— step 节点 key 冲突(
|
|
479
|
+
* T3 —— step 节点 key 冲突([n]-09-02 · 渲染层白屏事故真正根因固化)。
|
|
480
480
|
*
|
|
481
481
|
* 客户端渲染消息列表 = 从事件流构建节点,节点 key = `data.turn:data.step`
|
|
482
482
|
* (React 列表 key)。同 turn 内两个 step/start 的 step 号相同 → key 冲突 →
|
|
483
483
|
* React 渲染死循环 → 白屏/不展示(实测:同一 turn 内正常轮的 step 95/1 与
|
|
484
|
-
* 编辑块的 step 95/1 冲突;
|
|
484
|
+
* 编辑块的 step 95/1 冲突;[n]-09-02 全量扫描又发现多个同型冲突的会话,
|
|
485
485
|
* 均整块重编号修复)。
|
|
486
486
|
*
|
|
487
487
|
* 判定:扫 step/start,`data.turn:data.step` 组合重复 = error。
|
|
@@ -513,7 +513,7 @@ export function stepKeyViolations(events) {
|
|
|
513
513
|
}
|
|
514
514
|
|
|
515
515
|
/**
|
|
516
|
-
* T4 —— step/消息本体 turn 缺失(null/undefined)(
|
|
516
|
+
* T4 —— step/消息本体 turn 缺失(null/undefined)([n]-09-01 · D8 事故固化)。
|
|
517
517
|
*
|
|
518
518
|
* 客户端渲染状态机对 turn=null 的 step/消息**无法归属任何 turn** → 渲染死循环 →
|
|
519
519
|
* 白屏「载入历史」(实测:retrace 0.4.17 写的编辑块
|
|
@@ -541,9 +541,9 @@ export function nullTurnStepViolations(events) {
|
|
|
541
541
|
}
|
|
542
542
|
|
|
543
543
|
/**
|
|
544
|
-
* T5 —— turn/end 缺 reason.kind(
|
|
544
|
+
* T5 —— turn/end 缺 reason.kind([n]-09-02 · malformed turn/end 固化)。
|
|
545
545
|
*
|
|
546
|
-
* 官方 agent-loop 写 turn/end 恒带 `reason: { kind }`(dsh-agent-loop/lib/index.js:
|
|
546
|
+
* 官方 agent-loop 写 turn/end 恒带 `reason: { kind }`(dsh-agent-loop/lib/index.js:[n];
|
|
547
547
|
* kind ∈ completed|max-tokens|blocked|aborted|error|interrupted,中断恢复补
|
|
548
548
|
* interrupted,见 dsh-session interruptedTurnClosers)。官方 validation 强制
|
|
549
549
|
* reason.kind 存在——缺失 = malformed → 会话加载失败
|
|
@@ -560,14 +560,14 @@ export function turnEndReasonViolations(events) {
|
|
|
560
560
|
if (event.type !== 'turn/end') continue
|
|
561
561
|
const reason = event.data?.reason
|
|
562
562
|
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:
|
|
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:[n])`))
|
|
564
564
|
}
|
|
565
565
|
}
|
|
566
566
|
return out
|
|
567
567
|
}
|
|
568
568
|
|
|
569
569
|
/**
|
|
570
|
-
* E7 —— ignorable 未知 type 合法性(
|
|
570
|
+
* E7 —— ignorable 未知 type 合法性([n]-09-09 T2 增量)。
|
|
571
571
|
*
|
|
572
572
|
* 盲区:E3 对"未知 type + ignorable:true"直接放行(容忍更新版本 harness 写入),
|
|
573
573
|
* 但 ignorable 标记无合法性校验 = 后门——被读路径接纳却无人消费的未知事件 =
|
|
@@ -604,7 +604,7 @@ export function ignorableTypeViolations(events, version) {
|
|
|
604
604
|
export function toolPairingViolations(events) {
|
|
605
605
|
const out = [];
|
|
606
606
|
const calls = new Map(); // callId → { command, loc }
|
|
607
|
-
const results = new Map(); // callId → loc(双向:孤儿 result 也要指认,
|
|
607
|
+
const results = new Map(); // callId → loc(双向:孤儿 result 也要指认,[n]-09-09 T1)
|
|
608
608
|
for (const { event, lineNo } of events) {
|
|
609
609
|
if (event.type === 'tool/call') {
|
|
610
610
|
const callId = event.data?.callId;
|
|
@@ -612,7 +612,7 @@ export function toolPairingViolations(events) {
|
|
|
612
612
|
let command = '';
|
|
613
613
|
try {
|
|
614
614
|
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,
|
|
615
|
+
command = typeof args?.command === 'string' ? args.command.slice(0, [n]) : '';
|
|
616
616
|
} catch { /* 参数解析失败不阻断配对检查 */ }
|
|
617
617
|
calls.set(callId, { command, loc: { seq: event.seq, lineNo, eventType: event.type } });
|
|
618
618
|
}
|
|
@@ -688,7 +688,7 @@ export function toolResultStructureViolations(events) {
|
|
|
688
688
|
|
|
689
689
|
/**
|
|
690
690
|
* T1 —— token-meter 配对(复刻 @deepseek-ai/dsh-token-meter 的 _foldEvent 状态机,
|
|
691
|
-
*
|
|
691
|
+
* [n]-08-28 事故根因 3 固化):
|
|
692
692
|
* - `step/start` 打开一个 step(记录 turn/step);
|
|
693
693
|
* - `step/end` 必须匹配当前打开的 step/start,否则抛错;
|
|
694
694
|
* - `assistant/message` 必须匹配当前打开的 step/start(turn/step 完全一致),否则抛错;
|
|
@@ -734,14 +734,14 @@ export function tokenMeterViolations(events) {
|
|
|
734
734
|
}
|
|
735
735
|
|
|
736
736
|
/**
|
|
737
|
-
* T2 —— token-meter 的 sourceEventSeqs 引用必须同 turn/step(
|
|
737
|
+
* T2 —— token-meter 的 sourceEventSeqs 引用必须同 turn/step([n]-08-30 第二类
|
|
738
738
|
* 刷屏事故固化)。
|
|
739
739
|
*
|
|
740
|
-
* 镜像官方 `_estimateProviderAssistant`(dsh-token-meter lib/index.js:
|
|
740
|
+
* 镜像官方 `_estimateProviderAssistant`(dsh-token-meter lib/index.js:[n]-[n]):
|
|
741
741
|
* `assistant/message` 的每个 `sourceEventSeqs` 若指向 `assistant/chunk`,其
|
|
742
742
|
* turn/step 必须与消息自身一致;跨 step 引用 → 官方抛
|
|
743
743
|
* `token meter: assistant/message at seq N source seq M belongs to another step`
|
|
744
|
-
* (lib/index.js:
|
|
744
|
+
* (lib/index.js:[n])。
|
|
745
745
|
*
|
|
746
746
|
* 事故现场:DSH resend/regenerate 在 agent 仍开着 step 时被触发,会把旧 step 的
|
|
747
747
|
* chunk 全部引用进新 assistant/message(某真实会话的 chunk 源引用跨 step 7/8/9)→
|
|
@@ -759,7 +759,7 @@ export function tokenMeterSourceViolations(events) {
|
|
|
759
759
|
const turn = event.data?.turn;
|
|
760
760
|
const step = event.data?.step;
|
|
761
761
|
if (turn == null || step == null) continue; // turn-null marker 由 T1 覆盖
|
|
762
|
-
if (event.data?.usage === void 0) continue; // 无 usage 不触发 _estimateProviderAssistant(官方 :
|
|
762
|
+
if (event.data?.usage === void 0) continue; // 无 usage 不触发 _estimateProviderAssistant(官方 :[n] 前提)——replace marker(S5 遮蔽语义,sourceEventSeqs 含非 chunk 节点)合法
|
|
763
763
|
const seen = new Set();
|
|
764
764
|
for (const s of event.sourceEventSeqs) {
|
|
765
765
|
if (s >= event.seq) {
|
|
@@ -773,7 +773,7 @@ export function tokenMeterSourceViolations(events) {
|
|
|
773
773
|
seen.add(s);
|
|
774
774
|
const src = bySeq.get(s);
|
|
775
775
|
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 :
|
|
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 :[n] 对非 chunk 引用直接 throw),/compact 与压力测量永久失败`));
|
|
777
777
|
break; // 官方抛一次即停(consumedEvents 不前进),只报首条
|
|
778
778
|
}
|
|
779
779
|
if (src.event.data?.turn !== turn || src.event.data?.step !== step) {
|
|
@@ -928,16 +928,16 @@ export function wireViolations(events, version) {
|
|
|
928
928
|
* 覆盖(每条都有一手出处,官方 `@0.1.5-rc.2`):
|
|
929
929
|
* - **G1** `subagent/descriptor.data.version !== 3`
|
|
930
930
|
* - **G2** 事件类型不在官方 v0 dispositions 内(含 `ignorable:true`)
|
|
931
|
-
* - **G3** `session/title` / `session/title-llm-request` 的 `messageSeqs`(`v0-to-v1/lib/index.js:
|
|
931
|
+
* - **G3** `session/title` / `session/title-llm-request` 的 `messageSeqs`(`v0-to-v1/lib/index.js:[n]-[n]`)
|
|
932
932
|
*
|
|
933
933
|
* 仍未覆盖(由 `migrationVerdict().coverage.uncovered` 显式列出,**不许**当通过):
|
|
934
934
|
* `turn/start`(闭合/预期轮)、继承切点、`assistant/attempt` 配对、`stored log corrupt`、
|
|
935
935
|
* v0→v1 对其余事件的形状拒绝。
|
|
936
936
|
*
|
|
937
|
-
* **为什么 `turn/start` 不做(实测结论)**:官方那个状态机(`v0-to-v1:
|
|
937
|
+
* **为什么 `turn/start` 不做(实测结论)**:官方那个状态机(`v0-to-v1:[n]` 的
|
|
938
938
|
* `assertReleasedArtifactRelationships`)**不是**在原始 v0 事件上跑的——它由 **v1→v2**
|
|
939
939
|
* 以 `RELEASED_V2_RELATIONSHIP_EXTENSIONS` 调用在**变换后的 v1/v2 artifact** 上
|
|
940
|
-
* (`v1-to-v2/lib/index.js:
|
|
940
|
+
* (`v1-to-v2/lib/index.js:[n]`),并带 `cut`(继承切点)处理。实测:在原始 v0 上照抄该
|
|
941
941
|
* 状态机会在**已 seed 的会话**上狂报(样本(某真实会话):v0→v1 官方并不以该规则拒绝,
|
|
942
942
|
* 而原始 v0 上会报 19 条),属"规则文本对、应用对象错"。要忠实复现必须先把 v0→v1→v2 的
|
|
943
943
|
* 变换做出来 ⇒ 记未覆盖。
|
|
@@ -973,16 +973,16 @@ export function migrationPrecheckViolations(events, version, opts = {}) {
|
|
|
973
973
|
{ ignorable, ignorableRegistered }));
|
|
974
974
|
}
|
|
975
975
|
}
|
|
976
|
-
// ── G3 · session/title 系列 messageSeqs(官方 v0→v1 `assertTitleSources`,:
|
|
976
|
+
// ── G3 · session/title 系列 messageSeqs(官方 v0→v1 `assertTitleSources`,:[n]-[n])──
|
|
977
977
|
// 判据:每个被引 seq 必须解析到更早的 `user/message`,且 `data.source.kind === 'user'`;
|
|
978
978
|
// 另 `session/title` 的 `source.kind === 'user'` ⟺ `messageSeqs` 空。
|
|
979
979
|
//
|
|
980
|
-
// ⚠️ 应用面说明(实测
|
|
980
|
+
// ⚠️ 应用面说明(实测 [n]-09-15):官方 `assertTitleSources` 与 `turn/start` 状态机
|
|
981
981
|
// 同在 `assertReleasedArtifactRelationships` 里,而该函数被 **v1→v2** 以
|
|
982
982
|
// `RELEASED_V2_RELATIONSHIP_EXTENSIONS` 调用在**变换后的 v1/v2 artifact** 上
|
|
983
|
-
// (`dsh-session-format-v1-to-v2/lib/index.js:
|
|
983
|
+
// (`dsh-session-format-v1-to-v2/lib/index.js:[n]`),不是原始 v0 事件。
|
|
984
984
|
// 对 `messageSeqs` 这类"按 seq 索引 + 事件类型/source 判定"的引用,变换保序保类型
|
|
985
|
-
// ⇒ 在原始 v0 上判是**必要条件的近似**;实测
|
|
985
|
+
// ⇒ 在原始 v0 上判是**必要条件的近似**;实测 [n] 个真实 v0 上 **0 误报**。
|
|
986
986
|
const bySeq = new Map();
|
|
987
987
|
for (const { event } of events) if (event && typeof event === 'object') bySeq.set(event.seq, event);
|
|
988
988
|
for (const { event, lineNo } of events) {
|
|
@@ -1013,7 +1013,7 @@ export function migrationPrecheckViolations(events, version, opts = {}) {
|
|
|
1013
1013
|
}
|
|
1014
1014
|
|
|
1015
1015
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
1016
|
-
// 0.3.19 · v4 契约补充最小集(外部评审一手实测,
|
|
1016
|
+
// 0.3.19 · v4 契约补充最小集(外部评审一手实测,[n]-10-20)
|
|
1017
1017
|
// 5 条硬规则:S10 / I2 / P5 / G4 / A1。判据只新增/收严,不改既有规则的判定。
|
|
1018
1018
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
1019
1019
|
|
|
@@ -1022,7 +1022,7 @@ export function migrationPrecheckViolations(events, version, opts = {}) {
|
|
|
1022
1022
|
*
|
|
1023
1023
|
* 实测(外部评审一手):化石里存在嵌套 `[a,b]`,`v4test`/投影层/`restore` **全部静默
|
|
1024
1024
|
* 放过** ⇒ 契约层必须判红。但 `[a,b]` 本身是 v3+ 的**官方存储形态**(`encodeSeqRanges`
|
|
1025
|
-
* 把连续 ≥3 的 run 压成闭区间对;本机
|
|
1025
|
+
* 把连续 ≥3 的 run 压成闭区间对;本机 [n] 份真实 v3/v4 里 [n] 处,全部可被官方
|
|
1026
1026
|
* `decodeSeqRanges` 展开)⇒ 不能把合法的区间对当违规。判红点收严为两层:
|
|
1027
1027
|
* ① **存储形态**(`rawSourceEventSeqViolations`,看 `log.rows[].value`):元素只能是
|
|
1028
1028
|
* 非负安全整数或 `[start,end]`(start ≤ end),且必须能被官方 `decodeSeqRanges`
|
|
@@ -1108,17 +1108,17 @@ export function rawSourceEventSeqViolations(rows) {
|
|
|
1108
1108
|
* I2 —— `seedLength` 语义钉死 + `parentSession ∧ seedLength∈{缺失,0}` 合法(评审最小集 ③)。
|
|
1109
1109
|
*
|
|
1110
1110
|
* 一手依据(`@deepseek-ai/dsh-session-format-v0-to-v1@0.2.0-rc.2`):
|
|
1111
|
-
* - `package/lib/index.js:
|
|
1112
|
-
* - `:
|
|
1113
|
-
* - `:
|
|
1111
|
+
* - `package/lib/index.js:[n]` `seedLength` → `inheritedEventCount`(缺省 0);
|
|
1112
|
+
* - `:[n]` `isSeeded = record["seedLength"] !== undefined`(是否 seeded **只由字段是否存在决定**);
|
|
1113
|
+
* - `:[n]-[n]` `inheritedEventCount > events.length` → "Session inheritedEventCount exceeds its event count";`!isSeeded && inheritedEventCount !== 0` → "unseeded Session inheritedEventCount must be 0"。
|
|
1114
1114
|
*
|
|
1115
1115
|
* 结论(不再猜):
|
|
1116
|
-
* - **`parentSession` 有值 ≠ seeded**:血缘关系与继承计数是两件事。本机
|
|
1116
|
+
* - **`parentSession` 有值 ≠ seeded**:血缘关系与继承计数是两件事。本机 [n]/[n] 份真实
|
|
1117
1117
|
* v3/v4 头带 `parentSession` 且**无** `seedLength`(`isSeeded:false`)仍正常加载 ⇒
|
|
1118
1118
|
* `parentSession ∧ seedLength∈{缺失,0}` 判 **合法**(不告警、不拒)。
|
|
1119
|
-
* - `seedLength` 超过**展开后**事件数 ⇒ error(本机 16 份 v0 化石命中:
|
|
1120
|
-
* vs
|
|
1121
|
-
* - v4 运行时头**禁** `seedLength`(dsh-session@0.2.0-rc.2 lib/index.js:
|
|
1119
|
+
* - `seedLength` 超过**展开后**事件数 ⇒ error(本机 16 份 v0 化石命中:[n]/[n]/[n]
|
|
1120
|
+
* vs [n]/[n]/[n] —— 这些值明显是字节数/其它口径,官方迁移必拒)。
|
|
1121
|
+
* - v4 运行时头**禁** `seedLength`(dsh-session@0.2.0-rc.2 lib/index.js:[n])⇒ v4 文件带该字段 error。
|
|
1122
1122
|
*
|
|
1123
1123
|
* @param {object|null} header
|
|
1124
1124
|
* @param {Array<object>} events 展开后事件(chunk 行已展开),用于比较继承条数
|
|
@@ -1131,7 +1131,7 @@ export function seedLengthViolations(header, events, version) {
|
|
|
1131
1131
|
const has = Object.hasOwn(header, 'seedLength');
|
|
1132
1132
|
if (version >= 4) {
|
|
1133
1133
|
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:
|
|
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:[n]);v4 用 isSeeded + 构造器 inheritedEventCount,不落盘该字段`));
|
|
1135
1135
|
}
|
|
1136
1136
|
return out;
|
|
1137
1137
|
}
|
|
@@ -1143,7 +1143,7 @@ export function seedLengthViolations(header, events, version) {
|
|
|
1143
1143
|
}
|
|
1144
1144
|
const count = Array.isArray(events) ? events.length : 0;
|
|
1145
1145
|
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 :
|
|
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 :[n]-[n])`));
|
|
1147
1147
|
}
|
|
1148
1148
|
return out;
|
|
1149
1149
|
}
|
|
@@ -1178,7 +1178,7 @@ export function carrierRangesMatch(audit, carrier, version) {
|
|
|
1178
1178
|
/**
|
|
1179
1179
|
* P5 —— carrier 两段配对(评审最小集 ④;读侧)。
|
|
1180
1180
|
*
|
|
1181
|
-
* 现役写法(实测
|
|
1181
|
+
* 现役写法(实测 [n]/[n] 真实载体):`sourceEventSeqs = [审计段 seq, ...被遮蔽节点]`;
|
|
1182
1182
|
* 第 2 段 = 紧随审计段的 surface replace。规则:
|
|
1183
1183
|
* - 审计段 seq 在 **首元素** ⇒ 通过(现役);
|
|
1184
1184
|
* - 在 **末元素** ⇒ 通过(旧顺序,读侧容错),给 warning(不静默);
|
|
@@ -1212,7 +1212,7 @@ export function carrierPairingViolations(events, { version = 0 } = {}) {
|
|
|
1212
1212
|
// 读侧**两种写法都认**(外部评审要求;两种都在真实语料里出现过):
|
|
1213
1213
|
// ① 现役:`[审计段 seq, ...被遮蔽节点]`(审计段 seq 在首位);
|
|
1214
1214
|
// ② 早期:`[区间起点, ...被遮蔽节点]`(**不引用**审计段 seq;"区间起点"= replace 范围
|
|
1215
|
-
// 起点:实测真实语料
|
|
1215
|
+
// 起点:实测真实语料 [n] 个载体即此写法)。
|
|
1216
1216
|
// 两种都不报;其余(审计段 seq 在中间位、或首元素既非审计段也非区间起点)= 配对失败。
|
|
1217
1217
|
const range = surfaceReplaceRange(event.surfaceOp, version);
|
|
1218
1218
|
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 · 装即坏修复;[n]-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
|
+
* 移植源(一手,[n]-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:[n]-[n]`(该版本是最后一个把
|
|
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,sha[n] 前 16 位 `[n]c4f[n]ed07e7`)
|
|
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-[n]`
|
|
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, [[n]], [n] …]` ⇒ 内存形态 `[[n]…]`。
|
|
212
212
|
// v3 持久化层对连续段用区间对压缩(App 2.0.9 真实 v3 会话实测:1 个 `user/message` replace
|
|
213
|
-
// 的 `sourceEventSeqs`
|
|
213
|
+
// 的 `sourceEventSeqs` [n] 个存储项展开为 [n] 个 seq)。**不解码 = 拿物理未展开的序列
|
|
214
214
|
// 喂 S5/S6 与官方 foldSurface ⇒ 真实健康会话被误判 S5/S6/S8 + `--resume` broken。**
|
|
215
215
|
|
|
216
216
|
/** 非负安全整数(rc.7/0.1.5 `assertSeq`)。 */
|