dsh-log-contract 0.3.28 → 0.3.29

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 CHANGED
@@ -157,7 +157,7 @@ rather than by relaxing the format gate:
157
157
 
158
158
  - `tool/result` is validated with the v4 shape (`role: 'tool'`, no `tool-result` wrapper block)
159
159
  - `system/message` accepts v4's `source.kind: 'system-prompt'`
160
- - validation for v3 and earlier is **unchanged** (identical verdicts on [n] real v3 sessions before/after)
160
+ - validation for v3 and earlier is **unchanged** (identical verdicts on 408 real v3 sessions before/after)
161
161
  - the format gate still rejects **unknown** future versions (`readOnly`); v5+ remains unassessable by design
162
162
 
163
163
  **Rules (55 total as of 0.3.28):** the five rules below were added in the
@@ -185,23 +185,23 @@ omitted.
185
185
 
186
186
  | # | Date | What happened | The rule / fix it produced |
187
187
  | --- | --- | --- | --- |
188
- | 1 | [n]-08-25 | A "restore hidden content" repair wrote a replace marker with **emptied `sourceEventSeqs`** → the session refused to load (`SessionPersistenceCorruptionError`); a second attempt changed the marker to **append** → the client engine crashed. Both were **violating writes that nothing caught**. | **S5** (sourceEventSeqs must cover shadowed nodes), **M1** (turn-null assistant/message can only be replace), pre-write validation |
189
- | 2 | [n]-08-27~28 | Interrupted/restarted turns replayed with a **stale in-memory cursor**, re-appending old seqs to the file tail (tail regression, duplicate batches); two writers interleaved → **file-physical order non-monotonic** (`[n] → [n] → [n]`). Sessions failed to load with `seq gap`. | **S9** (physical-order monotonic), fix `--tail-renumber` |
190
- | 3 | [n]-08-27~28 | **Fork-boundary orphan splice**: the fork's "remove parent's pending prompt" splice assumed the parent's inbox; the child's seed-relative replay has an empty inbox → `resume failed: invalid persisted inbox splice`. | **I1** (inbox seed-relative replay), fix `--neutralize-orphan` |
191
- | 4 | [n]-08-28 | An oversized session (**[n] tokens** vs the 1M window) could neither continue nor `/compact`; the trim budget estimator underpriced CJK by ~3.7×. | T1 (token-meter pairing) for compactability, `fix --trim-budget` guidance |
192
- | 5 | [n]-08-29 | **W1/W2 wire violations**: markers shadowed an assistant with tool_calls but left the tool results dangling → strict endpoints (`INVALID_REQUEST`) reject the session's request stream. | **W1 / W2** (wire message flow) |
193
- | 6 | [n]-08-30 | A single **turn-null marker** made the token-meter listener throw on **every** appended event (`consumedEvents` never advanced → full-prefix re-fold per event) → **30s / [n] log lines**, host event loop crushed, all sessions locked. Same session also had a **cross-step sourceEventSeqs** (steps 7/8/9 mixed in one assistant message) — offline checks were green, the live meter crashed. | **T1** (turn/step pairing), **T2** (cross-step source refs), `fix --neutralize`, `fix --clip-crossstep` |
194
- | 7 | [n]-08-31 | A log was compressed as a **single zstd frame** (or the header did not form its own frame) → different readers disagreed on record boundaries ⇒ **Z4/Z5** frame-shape rules (first frame = exactly one header line; body framed) | |
195
- | 8 | [n]-08-31 | A log whose **last zstd frame was torn** mid-write could not be loaded at all, with no diagnosis ⇒ **Z1** + explicit "torn tail / in-flight write" reporting | |
196
- | 9 | [n]-09-09 | On **session format v4**, `tool/result` uses `role: 'tool'` and `system/message` carries a `system-prompt` source → v3-shaped checks produced **thousands of false errors on healthy v4 logs** ⇒ version dispatch + **E6/E9** v4 semantics | |
197
- | 10 | [n]-09-17 | On **Windows**, `header.cwd` was judged with POSIX-only rules → **every** session flagged by **H2** ⇒ platform-aware absolute-path check | |
198
- | 11 | [n]-10-20 | A **> [size] session** crashed the reader (`ERR_STRING_TOO_LONG`) and repair built the whole text in memory ⇒ line-wise decode + streaming frame rebuild | |
199
- | 12 | [n]-10-20 | Two-segment carrier references were written with the audit segment first while an earlier convention started at the range start → readers reported hundreds of **false orphan carriers** ⇒ **P5** write-side pairing + tolerant read-side | |
200
- | 13 | [n]-10-20 | `seedLength` was read as a **byte size** by some consumers (it is the number of inherited events), and `parentSession` with missing/0 was treated as corruption ⇒ **I2** semantics pinned | |
201
- | 14 | [n]-10-20 | An **unknown but explicitly ignorable** event type blocked an entire migration ⇒ **G4** declarative skip + allow-list | |
202
- | 15 | [n]-10-26 | A **truncated zstd frame** made the session-header reader throw `ERR_OUT_OF_RANGE`, and because there was no per-item isolation the whole enumeration/summary run failed (hundreds of failures over 33 days) — **one damaged file sank the whole batch** | **R4** (read/parse tolerance: degrade to a structured, countable result), **R5** (per-item isolation + failure counting in aggregation APIs) |
203
- | 16 | [n]-10-26 | A file whose **last frame was cut mid-write** still reported `ok=true` — the check certifies only the events it actually read | **Z6** (`tailStatus: complete/interrupted/truncated/unknown`) + the documented tail-completeness boundary |
204
- | 17 | [n]-10-26 | Producers **inventing `seq` on the write side**, and **deleting rows without renumbering** | **E11** (`seq` assigned by the log layer only; pre-write rejects self-invented `seq`), gap traces pinned to `E2`/`S9` |
188
+ | 1 | 2026-08-25 | A "restore hidden content" repair wrote a replace marker with **emptied `sourceEventSeqs`** → the session refused to load (`SessionPersistenceCorruptionError`); a second attempt changed the marker to **append** → the client engine crashed. Both were **violating writes that nothing caught**. | **S5** (sourceEventSeqs must cover shadowed nodes), **M1** (turn-null assistant/message can only be replace), pre-write validation |
189
+ | 2 | 2026-08-27~28 | Interrupted/restarted turns replayed with a **stale in-memory cursor**, re-appending old seqs to the file tail (tail regression, duplicate batches); two writers interleaved → **file-physical order non-monotonic** (`734056 → 733539 → 735470`). Sessions failed to load with `seq gap`. | **S9** (physical-order monotonic), fix `--tail-renumber` |
190
+ | 3 | 2026-08-27~28 | **Fork-boundary orphan splice**: the fork's "remove parent's pending prompt" splice assumed the parent's inbox; the child's seed-relative replay has an empty inbox → `resume failed: invalid persisted inbox splice`. | **I1** (inbox seed-relative replay), fix `--neutralize-orphan` |
191
+ | 4 | 2026-08-28 | An oversized session (**1,052,557 tokens** vs the 1M window) could neither continue nor `/compact`; the trim budget estimator underpriced CJK by ~3.7×. | T1 (token-meter pairing) for compactability, `fix --trim-budget` guidance |
192
+ | 5 | 2026-08-29 | **W1/W2 wire violations**: markers shadowed an assistant with tool_calls but left the tool results dangling → strict endpoints (`INVALID_REQUEST`) reject the session's request stream. | **W1 / W2** (wire message flow) |
193
+ | 6 | 2026-08-30 | A single **turn-null marker** made the token-meter listener throw on **every** appended event (`consumedEvents` never advanced → full-prefix re-fold per event) → **30s / 10,008 log lines**, host event loop crushed, all sessions locked. Same session also had a **cross-step sourceEventSeqs** (steps 7/8/9 mixed in one assistant message) — offline checks were green, the live meter crashed. | **T1** (turn/step pairing), **T2** (cross-step source refs), `fix --neutralize`, `fix --clip-crossstep` |
194
+ | 7 | 2026-08-31 | A log was compressed as a **single zstd frame** (or the header did not form its own frame) → different readers disagreed on record boundaries ⇒ **Z4/Z5** frame-shape rules (first frame = exactly one header line; body framed) | |
195
+ | 8 | 2026-08-31 | A log whose **last zstd frame was torn** mid-write could not be loaded at all, with no diagnosis ⇒ **Z1** + explicit "torn tail / in-flight write" reporting | |
196
+ | 9 | 2026-09-09 | On **session format v4**, `tool/result` uses `role: 'tool'` and `system/message` carries a `system-prompt` source → v3-shaped checks produced **thousands of false errors on healthy v4 logs** ⇒ version dispatch + **E6/E9** v4 semantics | |
197
+ | 10 | 2026-09-17 | On **Windows**, `header.cwd` was judged with POSIX-only rules → **every** session flagged by **H2** ⇒ platform-aware absolute-path check | |
198
+ | 11 | 2026-10-20 | A **> [size] session** crashed the reader (`ERR_STRING_TOO_LONG`) and repair built the whole text in memory ⇒ line-wise decode + streaming frame rebuild | |
199
+ | 12 | 2026-10-20 | Two-segment carrier references were written with the audit segment first while an earlier convention started at the range start → readers reported hundreds of **false orphan carriers** ⇒ **P5** write-side pairing + tolerant read-side | |
200
+ | 13 | 2026-10-20 | `seedLength` was read as a **byte size** by some consumers (it is the number of inherited events), and `parentSession` with missing/0 was treated as corruption ⇒ **I2** semantics pinned | |
201
+ | 14 | 2026-10-20 | An **unknown but explicitly ignorable** event type blocked an entire migration ⇒ **G4** declarative skip + allow-list | |
202
+ | 15 | 2026-10-26 | A **truncated zstd frame** made the session-header reader throw `ERR_OUT_OF_RANGE`, and because there was no per-item isolation the whole enumeration/summary run failed (hundreds of failures over 33 days) — **one damaged file sank the whole batch** | **R4** (read/parse tolerance: degrade to a structured, countable result), **R5** (per-item isolation + failure counting in aggregation APIs) |
203
+ | 16 | 2026-10-26 | A file whose **last frame was cut mid-write** still reported `ok=true` — the check certifies only the events it actually read | **Z6** (`tailStatus: complete/interrupted/truncated/unknown`) + the documented tail-completeness boundary |
204
+ | 17 | 2026-10-26 | Producers **inventing `seq` on the write side**, and **deleting rows without renumbering** | **E11** (`seq` assigned by the log layer only; pre-write rejects self-invented `seq`), gap traces pinned to `E2`/`S9` |
205
205
 
206
206
  > **Takeaway**: these rules are not synthetic theory — each one is pinned by a
207
207
  > regression test that reproduces the corrupt shape it guards against. That is what
@@ -241,11 +241,11 @@ Sample output (the CLI reports in Chinese — it is the tool's UI language):
241
241
 
242
242
  ```
243
243
  📋 dsh-log-contract check —— backup-session-xxxx.jsonl.zstd
244
- 事件 [n] | surface 节点 16 | replace 代数 5 | 帧 [n]([n].5KiB → [n].3KiB)
244
+ 事件 204754 | surface 节点 16 | replace 代数 5 | 帧 8620(3439.5KiB → 8191.3KiB)
245
245
  违规 1(error 1 / warning 0)
246
246
 
247
247
  [error] S5 @ seq <seq> / line <line> (assistant/message)
248
- surface replace: sourceEventSeqs 必须覆盖每个被替换节点;缺失 [n] [n](共 2 个)
248
+ surface replace: sourceEventSeqs 必须覆盖每个被替换节点;缺失 121774, 121779(共 2 个)
249
249
 
250
250
  ❌ 未通过:见上方违规明细(error 级 = 会话不可读/不可写)
251
251
  ```
@@ -272,7 +272,7 @@ read* are self-consistent — see the `tailStatus` note in the 0.3.28 section ab
272
272
  stream in surface order and catch "dangling tool messages" (a tool result with no
273
273
  preceding assistant tool_calls) and "user text between tool_calls and their
274
274
  results" — tolerated by some endpoints, `INVALID_REQUEST` on strict ones
275
- (MiMo, verified [n]-08-27).
275
+ (MiMo, verified 2026-08-27).
276
276
 
277
277
  ### 2. Repair (`fix`)
278
278
 
@@ -305,7 +305,7 @@ dsh-log-contract fix [path]<id>.jsonl.zstd --remove-markers --apply
305
305
 
306
306
  ```jsonc
307
307
  // Append one event to the log tail (seq omitted = auto-assigned as nextSeq)
308
- { "append": { "type": "assistant/message", "surfaceOp": { "op": "replace", "start": [n] "end": [n] }, "sourceEventSeqs": [[n] [n] "…"], "data": { "turn": null, "step": null, "message": { "…": "…" }, "editor": { "targetSeq": [n] "text": "…" } } } }
308
+ { "append": { "type": "assistant/message", "surfaceOp": { "op": "replace", "start": 121774, "end": 156421 }, "sourceEventSeqs": [121774, 121779, "…"], "data": { "turn": null, "step": null, "message": { "…": "…" }, "editor": { "targetSeq": 156430, "text": "…" } } } }
309
309
 
310
310
  // Frame-level surgery: the complete event list after the edit (both baseline and
311
311
  // result must be green before it may land)
@@ -364,8 +364,8 @@ if (!baseline.ok) throw new Error('baseline is broken; repair it first');
364
364
  const prewriter = createPreWriter({ events: log.events.map((e) => e.event) });
365
365
  const verdict = prewriter.validateAppend({
366
366
  type: 'assistant/message',
367
- surfaceOp: { op: 'replace', start: [n] end: [n] },
368
- sourceEventSeqs: [[n] [n] /* …must fully cover shadowed nodes… */],
367
+ surfaceOp: { op: 'replace', start: 121774, end: 156421 },
368
+ sourceEventSeqs: [121774, 121779 /* …must fully cover shadowed nodes… */],
369
369
  data: { turn: null, step: null, message: { /* … */ } },
370
370
  });
371
371
  if (!verdict.ok) {
@@ -453,7 +453,7 @@ check for `H2` is platform-aware. still **partial** — see the changelog's know
453
453
 
454
454
  > **0.3.17 changes no behaviour.** It only adjusts the wording of comments, test titles, a few
455
455
  > diagnostic strings and the README. Every verdict, exit code and `--json`
456
- > field is unchanged from 0.3.[n] so everything below applies unchanged when going from 0.3.12 to 0.3.17.
456
+ > field is unchanged from 0.3.15, so everything below applies unchanged when going from 0.3.12 to 0.3.17.
457
457
  >
458
458
  > 0.3.15 was a documentation-only release as well.
459
459
 
@@ -490,7 +490,7 @@ Read `coverage.uncovered` for the known gaps.
490
490
  - [x] **Phase 1.5 (0.2.0)**: `fix` subcommand (strict seq scan + W1/W2 wire checks +
491
491
  marker removal with renumbering + official frame rebuild); CI integration
492
492
  (`dsh-log-contract check` as a scheduled guard over the Harness session dir)
493
- - [x] **0.3.x ([n]-08-30 case hardening)**: T1 token-meter pairing → 0.3.1 W1/W2
493
+ - [x] **0.3.x (2026-08-30 case hardening)**: T1 token-meter pairing → 0.3.1 W1/W2
494
494
  fold-position fix → 0.3.2 `tailSeq` → 0.3.3 `fix --neutralize` (in-place
495
495
  turn-null neutralization) → 0.3.4 `fix --clip-crossstep` (cross-step clipping) →
496
496
  0.3.5 **T2/S9/I1 rules** (cross-step source refs / physical order / inbox replay)
package/README.zh.md CHANGED
@@ -129,7 +129,7 @@ dsh-retrace 的「日志体检与修复」能力——与 dsh-retrace 一起构
129
129
 
130
130
  - `tool/result` 按 v4 形状校验(`role: 'tool'`、无 `tool-result` 包裹块)
131
131
  - `system/message` 接受 v4 的 `source.kind: 'system-prompt'`
132
- - **v3 及更早的判据零改动**([n] 份真实 v3 会话前后判定完全一致)
132
+ - **v3 及更早的判据零改动**(408 份真实 v3 会话前后判定完全一致)
133
133
  - 格式闸门仍**拒绝未知的未来版本**(`readOnly`);v5+ 按设计保持"不可评估"
134
134
 
135
135
  **规则(0.3.28 起共 55 条)**:下表五条是 0.3.18 – 0.3.24 窗口新增
@@ -143,7 +143,7 @@ dsh-retrace 的「日志体检与修复」能力——与 dsh-retrace 一起构
143
143
  | `P5` | 两段 carrier 配对:第 2 段首元素 = 第 1 段 seq(读侧兼容早期写法) |
144
144
  | `A1` | 「在位可还原」**只认结构化字段**(`archiveRef`/`archive`/`externalized.*`),不从自由文本推断 |
145
145
 
146
- **[internal]**:读取改为**按行解码**(不再整文件字符串化 ⇒ 约 [size] 以上不再抛 `ERR_STRING_TOO_LONG`);
146
+ **internal**:读取改为**按行解码**(不再整文件字符串化 ⇒ 约 [size] 以上不再抛 `ERR_STRING_TOO_LONG`);
147
147
  修复采用**流式帧重建** `.jsonl.zstd`(header 帧 + 正文分块多帧,逐帧 checksum + roundtrip 校验)。
148
148
 
149
149
  **Windows**:`H2` 的 `header.cwd` 绝对路径判断改为**平台感知**(`win32` 与 `posix` 都认)。
@@ -155,23 +155,23 @@ dsh-retrace 的「日志体检与修复」能力——与 dsh-retrace 一起构
155
155
 
156
156
  | # | 日期 | 发生了什么 | 产出的规则/修复 |
157
157
  | --- | --- | --- | --- |
158
- | 1 | [n]-08-25 | 一次「恢复被隐藏内容」的修复写了**清空 `sourceEventSeqs`** 的 replace marker → 会话加载被拒(`SessionPersistenceCorruptionError`);第二次尝试把 marker 改成 **append** → 客户端引擎崩溃。两次都是**违约写入没被拦**。 | **S5**(sourceEventSeqs 必须覆盖被替换节点)、**M1**(turn-null 的 assistant/message 只能 replace)、写前校验 |
159
- | 2 | [n]-08-27~28 | 中断/暂停的轮次恢复时按**过期内存光标**重放,把旧 seq 追加到文件尾(尾部回归、重复批次);两个写入者交织 → **文件物理序非单调**(`[n] → [n] → [n]`)。会话 `seq gap` 加载失败。 | **S9**(物理序单调)、fix `--tail-renumber` |
160
- | 3 | [n]-08-27~28 | **fork 边界孤儿 spliced**:fork 的「移除父待处理提示词」splice 假设父会话 inbox;子会话 seed 相对重放里 inbox 为空 → `resume failed: invalid persisted inbox splice`。 | **I1**(inbox seed 相对重放)、fix `--neutralize-orphan` |
161
- | 4 | [n]-08-28 | 超限会话(**[n] tokens** vs 1M 窗口)既无法继续也无法 `/compact`;裁剪预算估算对中文低估 ~3.7×。 | T1(token-meter 配对,保障可压缩)、`fix --trim-budget` 预算指引 |
162
- | 5 | [n]-08-29 | **W1/W2 wire 违规**:marker 遮蔽了带 tool_calls 的 assistant 但漏盖 tool 结果 → 悬空 tool,严格端点 `INVALID_REQUEST` 拒绝请求流。 | **W1 / W2**(wire 消息流) |
163
- | 6 | [n]-08-30 | 单个 **turn-null marker** 让 token-meter 监听器在**每条**追加事件上抛错(`consumedEvents` 不前进 → 每事件全前缀重折)→ **30 秒 / [n] 行日志**、host 事件循环被压垮、全部会话锁定。同会话还有**跨 step sourceEventSeqs**(step 7/8/9 混进一条 assistant 消息)——离线 check 全绿、实机 meter 崩溃。 | **T1**(turn/step 配对)、**T2**(跨 step 源引用)、`fix --neutralize`、`fix --clip-crossstep` |
164
- | 7 | [n]-08-31 | 日志被压成**单个 zstd 帧**(或 header 未单独成帧)→ 不同读取器对记录边界理解不一致 ⇒ **Z4/Z5** 帧形状规则(首帧必须恰好一行 header;正文分帧) | |
165
- | 8 | [n]-08-31 | **尾帧在写入中被撕裂**的日志完全无法加载、且没有诊断 ⇒ **Z1** + 明确报「尾帧撕裂 / 写入中」 | |
166
- | 9 | [n]-09-09 | **会话格式 v4** 下 `tool/result` 改用 `role:'tool'`、`system/message` 带 `system-prompt` 来源 → v3 语义的检查在**健康 v4 日志**上产出**数千条误报** ⇒ 版本分派 + **E6/E9** v4 语义 | |
167
- | 10 | [n]-09-17 | **Windows** 上 `header.cwd` 用 POSIX 规则判定 → **所有**会话被 **H2** 误报 ⇒ 平台感知的绝对路径判定 | |
168
- | 11 | [n]-10-20 | **超过 [size] 的会话**让读取器崩溃(`ERR_STRING_TOO_LONG`),修复时又把全文拼进内存 ⇒ 按行解码 + 流式帧重建 | |
169
- | 12 | [n]-10-20 | 两段式载体引用有的把「审计段」写在前面、早期约定从区间起点开始 → 读取侧报出**数百个假孤儿载体** ⇒ **P5** 写侧成对 + 读侧容错 | |
170
- | 13 | [n]-10-20 | `seedLength` 被部分消费方当作**字节数**(其语义是「继承事件条数」),且 `parentSession` 配缺失/0 被当成损坏 ⇒ **I2** 语义钉死 | |
171
- | 14 | [n]-10-20 | 一种**未知但显式可忽略**的事件类型让整条迁移卡死 ⇒ **G4** 声明式跳过 + 白名单 | |
172
- | 15 | [n]-10-26 | 一个**截断 zstd 帧**让会话读头抛 `ERR_OUT_OF_RANGE`,而聚合循环没有逐项隔离 ⇒ 整个枚举/汇总能力失败(33 天内数百次)——**单文件损坏 ⇒ 整表失败** | **R4**(读取容错:降级为结构化、可计数结果)、**R5**(聚合 API 逐项隔离 + 失败计数) |
173
- | 16 | [n]-10-26 | **最后一帧写入中被切**的文件仍报 `ok=true`——体检只认证已读到的事件 | **Z6**(`tailStatus: complete/interrupted/truncated/unknown`)+ 明示口径边界 |
174
- | 17 | [n]-10-26 | 生产者**写侧自造 seq**、以及**删行不重编号** | **E11**(seq 由日志层分配;写前拒绝自造 seq)、缺口痕迹钉到 `E2`/`S9` |
158
+ | 1 | 2026-08-25 | 一次「恢复被隐藏内容」的修复写了**清空 `sourceEventSeqs`** 的 replace marker → 会话加载被拒(`SessionPersistenceCorruptionError`);第二次尝试把 marker 改成 **append** → 客户端引擎崩溃。两次都是**违约写入没被拦**。 | **S5**(sourceEventSeqs 必须覆盖被替换节点)、**M1**(turn-null 的 assistant/message 只能 replace)、写前校验 |
159
+ | 2 | 2026-08-27~28 | 中断/暂停的轮次恢复时按**过期内存光标**重放,把旧 seq 追加到文件尾(尾部回归、重复批次);两个写入者交织 → **文件物理序非单调**(`734056 → 733539 → 735470`)。会话 `seq gap` 加载失败。 | **S9**(物理序单调)、fix `--tail-renumber` |
160
+ | 3 | 2026-08-27~28 | **fork 边界孤儿 spliced**:fork 的「移除父待处理提示词」splice 假设父会话 inbox;子会话 seed 相对重放里 inbox 为空 → `resume failed: invalid persisted inbox splice`。 | **I1**(inbox seed 相对重放)、fix `--neutralize-orphan` |
161
+ | 4 | 2026-08-28 | 超限会话(**1,052,557 tokens** vs 1M 窗口)既无法继续也无法 `/compact`;裁剪预算估算对中文低估 ~3.7×。 | T1(token-meter 配对,保障可压缩)、`fix --trim-budget` 预算指引 |
162
+ | 5 | 2026-08-29 | **W1/W2 wire 违规**:marker 遮蔽了带 tool_calls 的 assistant 但漏盖 tool 结果 → 悬空 tool,严格端点 `INVALID_REQUEST` 拒绝请求流。 | **W1 / W2**(wire 消息流) |
163
+ | 6 | 2026-08-30 | 单个 **turn-null marker** 让 token-meter 监听器在**每条**追加事件上抛错(`consumedEvents` 不前进 → 每事件全前缀重折)→ **30 秒 / 10,008 行日志**、host 事件循环被压垮、全部会话锁定。同会话还有**跨 step sourceEventSeqs**(step 7/8/9 混进一条 assistant 消息)——离线 check 全绿、实机 meter 崩溃。 | **T1**(turn/step 配对)、**T2**(跨 step 源引用)、`fix --neutralize`、`fix --clip-crossstep` |
164
+ | 7 | 2026-08-31 | 日志被压成**单个 zstd 帧**(或 header 未单独成帧)→ 不同读取器对记录边界理解不一致 ⇒ **Z4/Z5** 帧形状规则(首帧必须恰好一行 header;正文分帧) | |
165
+ | 8 | 2026-08-31 | **尾帧在写入中被撕裂**的日志完全无法加载、且没有诊断 ⇒ **Z1** + 明确报「尾帧撕裂 / 写入中」 | |
166
+ | 9 | 2026-09-09 | **会话格式 v4** 下 `tool/result` 改用 `role:'tool'`、`system/message` 带 `system-prompt` 来源 → v3 语义的检查在**健康 v4 日志**上产出**数千条误报** ⇒ 版本分派 + **E6/E9** v4 语义 | |
167
+ | 10 | 2026-09-17 | **Windows** 上 `header.cwd` 用 POSIX 规则判定 → **所有**会话被 **H2** 误报 ⇒ 平台感知的绝对路径判定 | |
168
+ | 11 | 2026-10-20 | **超过 [size] 的会话**让读取器崩溃(`ERR_STRING_TOO_LONG`),修复时又把全文拼进内存 ⇒ 按行解码 + 流式帧重建 | |
169
+ | 12 | 2026-10-20 | 两段式载体引用有的把「审计段」写在前面、早期约定从区间起点开始 → 读取侧报出**数百个假孤儿载体** ⇒ **P5** 写侧成对 + 读侧容错 | |
170
+ | 13 | 2026-10-20 | `seedLength` 被部分消费方当作**字节数**(其语义是「继承事件条数」),且 `parentSession` 配缺失/0 被当成损坏 ⇒ **I2** 语义钉死 | |
171
+ | 14 | 2026-10-20 | 一种**未知但显式可忽略**的事件类型让整条迁移卡死 ⇒ **G4** 声明式跳过 + 白名单 | |
172
+ | 15 | 2026-10-26 | 一个**截断 zstd 帧**让会话读头抛 `ERR_OUT_OF_RANGE`,而聚合循环没有逐项隔离 ⇒ 整个枚举/汇总能力失败(33 天内数百次)——**单文件损坏 ⇒ 整表失败** | **R4**(读取容错:降级为结构化、可计数结果)、**R5**(聚合 API 逐项隔离 + 失败计数) |
173
+ | 16 | 2026-10-26 | **最后一帧写入中被切**的文件仍报 `ok=true`——体检只认证已读到的事件 | **Z6**(`tailStatus: complete/interrupted/truncated/unknown`)+ 明示口径边界 |
174
+ | 17 | 2026-10-26 | 生产者**写侧自造 seq**、以及**删行不重编号** | **E11**(seq 由日志层分配;写前拒绝自造 seq)、缺口痕迹钉到 `E2`/`S9` |
175
175
 
176
176
 
177
177
  > **结论**:这些规则不是合成理论——每一条都有回归测试复现它守护的那种损坏形态。这就是这里「生产级」的含义。
@@ -207,11 +207,11 @@ dsh-log-contract check [path]<id>.jsonl.zstd --json # 机器可读
207
207
 
208
208
  ```
209
209
  📋 dsh-log-contract check —— backup-session-xxxx.jsonl.zstd
210
- 事件 [n] | surface 节点 16 | replace 代数 5 | 帧 [n]([n].5KiB → [n].3KiB)
210
+ 事件 204754 | surface 节点 16 | replace 代数 5 | 帧 8620(3439.5KiB → 8191.3KiB)
211
211
  违规 1(error 1 / warning 0)
212
212
 
213
213
  [error] S5 @ seq <seq> / line <line> (assistant/message)
214
- surface replace: sourceEventSeqs 必须覆盖每个被替换节点;缺失 [n] [n](共 2 个)
214
+ surface replace: sourceEventSeqs 必须覆盖每个被替换节点;缺失 121774, 121779(共 2 个)
215
215
 
216
216
  ❌ 未通过:见上方违规明细(error 级 = 会话不可读/不可写)
217
217
  ```
@@ -234,7 +234,7 @@ dsh-log-contract check [path]<id>.jsonl.zstd --json # 机器可读
234
234
  `check` 自 0.2.0 起新增 **W1/W2 wire 级检查**:按 surface 顺序展开模型请求消息流,
235
235
  捕获"悬空 tool 消息"(tool 结果没有前置 assistant tool_calls)与"user 文本插在
236
236
  tool_calls 与其结果之间"——这类问题 DeepSeek 曾容忍,但 MiMo 等严格端点会直接
237
- `INVALID_REQUEST`([n]-08-27 实锤)。
237
+ `INVALID_REQUEST`(2026-08-27 实锤)。
238
238
 
239
239
  ### 2. 修复(`fix`)
240
240
 
@@ -262,7 +262,7 @@ dsh-log-contract fix [path]<id>.jsonl.zstd --remove-markers --apply
262
262
 
263
263
  ```jsonc
264
264
  // 拟追加一个事件到日志尾部(seq 缺省 = 自动按 nextSeq 赋值)
265
- { "append": { "type": "assistant/message", "surfaceOp": { "op": "replace", "start": [n] "end": [n] }, "sourceEventSeqs": [[n] [n] "…"], "data": { "turn": null, "step": null, "message": { "…": "…" }, "editor": { "targetSeq": [n] "text": "…" } } } }
265
+ { "append": { "type": "assistant/message", "surfaceOp": { "op": "replace", "start": 121774, "end": 156421 }, "sourceEventSeqs": [121774, 121779, "…"], "data": { "turn": null, "step": null, "message": { "…": "…" }, "editor": { "targetSeq": 156430, "text": "…" } } } }
266
266
 
267
267
  // 帧级手术后的完整事件列表(改后确认,与改前基线双绿才允许落盘)
268
268
  { "edit": [ "…完整事件列表…" ] }
@@ -316,8 +316,8 @@ if (!baseline.ok) throw new Error('基线已坏,先修基线');
316
316
  const prewriter = createPreWriter({ events: log.events.map((e) => e.event) });
317
317
  const verdict = prewriter.validateAppend({
318
318
  type: 'assistant/message',
319
- surfaceOp: { op: 'replace', start: [n] end: [n] },
320
- sourceEventSeqs: [[n] [n] /* …必须完整覆盖被替换节点… */],
319
+ surfaceOp: { op: 'replace', start: 121774, end: 156421 },
320
+ sourceEventSeqs: [121774, 121779 /* …必须完整覆盖被替换节点… */],
321
321
  data: { turn: null, step: null, message: { /* … */ } },
322
322
  });
323
323
  if (!verdict.ok) {
@@ -385,7 +385,7 @@ git config --get core.hooksPath # 验证:应输出 .githooks
385
385
 
386
386
  **会话格式 v4**(宿主 `dsh-session` 0.2.x)改为按版本分派判定(`tool/result` 的 role、`system/message` 的来源);
387
387
  新增五条规则(`G4` 未知但可忽略事件、`S10` 引用元素类型、`I2` `seedLength` 语义、`P5` 载体配对、`A1` 只认结构化字段的在位可还原);
388
- [internal](>[size])按行读取 + 流式帧重建;Windows 的 `header.cwd` 判定改为平台感知。
388
+ internal(>[size])按行读取 + 流式帧重建;Windows 的 `header.cwd` 判定改为平台感知。
389
389
  > **0.3.17 不含行为变更。** 它只调整了注释、测试标题、少量诊断文案与 README 的措辞。
390
390
  > 所有判定结果、退出码与 `--json` 字段与 0.3.15 完全一致,
391
391
  > 因此从 0.3.12 升到 0.3.17 时,下面各条与原来完全一致。
@@ -419,7 +419,7 @@ git config --get core.hooksPath # 验证:应输出 .githooks
419
419
  ## Roadmap
420
420
  - [x] **Phase 1(0.1.0)**:CLI 离线体检 + 写前校验 + 契约目录
421
421
  - [x] **Phase 1.5(0.2.0)**:`fix` 子命令(严格 seq 扫描 + W1/W2 wire 检查 + 移除 marker 重编号 + 官方帧格式重建);CI 集成(`dsh-log-contract check` 作为 Harness 会话目录的定时守护)
422
- - [x] **0.3.x([n]-08-30 案例固化)**:T1 token-meter 配对 → 0.3.1 W1/W2 折叠位置修复 → 0.3.2 `tailSeq` → 0.3.3 `fix --neutralize`(turn-null marker 原地中和)→ 0.3.4 `fix --clip-crossstep`(跨 step 引用裁剪)→ 0.3.5 **T2/S9/I1 规则**(跨 step 源引用 / 物理序单调 / inbox 重放)
422
+ - [x] **0.3.x(2026-08-30 案例固化)**:T1 token-meter 配对 → 0.3.1 W1/W2 折叠位置修复 → 0.3.2 `tailSeq` → 0.3.3 `fix --neutralize`(turn-null marker 原地中和)→ 0.3.4 `fix --clip-crossstep`(跨 step 引用裁剪)→ 0.3.5 **T2/S9/I1 规则**(跨 step 源引用 / 物理序单调 / inbox 重放)
423
423
  - [x] **0.3.6 → 0.3.15**:按被检文件版本择路的 v0–v3 规则(T3/T4/T5、L3–L5、E8/E9/E10)、宿主能力与迁移预检的退出码 `3`/`4`,以及如实报告"哪些版本**未**验证"的版本支持说明(详见 [CHANGELOG.md](CHANGELOG.md))
424
424
  - [ ] Phase 2:运行时守护(订阅 session append 事件流实时校验,断裂即标记 `dsh/contract-violation` 事件,策略可配 告警/拦截)——DSH 插件形态
425
425
  - [ ] Phase 3:与 dsh-turn-guard / dsh-retrace 时间线联动
@@ -19,7 +19,7 @@ import { loadSessionLog, validateSessionLog, resumeVerdict, migrationVerdict, as
19
19
  /**
20
20
  * 同步写 fd——`process.stdout.write` 在**管道**下是异步的,紧跟着的
21
21
  * `process.exit()` 不会等待 flush:>~64KiB 的输出会丢尾,`--json` 因此变成非法 JSON
22
- * (实测在 [n] 事件夹具与真实 [size] v3 会话上复现,stdout [n]B 处 "Unterminated string")。
22
+ * (实测在 3000 事件夹具与真实 [size] v3 会话上复现,stdout 56648B 处 "Unterminated string")。
23
23
  * 这里直接同步写 fd 1/2(非阻塞管道 EAGAIN 时自旋重试),做到"先写完再 exit"。
24
24
  */
25
25
  function writeAllSync(fd, text) {
@@ -73,14 +73,14 @@ const USAGE = `dsh-log-contract —— 日志契约守护(DSH session log cont
73
73
  --no-fail-on-migration 退出该档)。
74
74
 
75
75
  dsh-log-contract fix <session-log> [--remove-markers] [--neutralize] [--neutralize-legacy-markers] [--clip-crossstep] [--drop-failed-turns] [--trim-last N] [--compact-last N] [--tail-renumber D] [--neutralize-orphan] [--extract-turn N] [--keep-ranges a-b,c-d] [--apply] [--backup-dir DIR] [--json]
76
- 诊断 + 修复([n]-08 事故固化方案)。先做严格 seq 连续扫描 + 契约体检
76
+ 诊断 + 修复(2026-08 事故固化方案)。先做严格 seq 连续扫描 + 契约体检
77
77
  (含 W1/W2 wire 级悬空 tool 检查),再按需修复:
78
78
  --remove-markers 移除 retrace/message-editor marker 并全量重编号
79
79
  (用于大范围遮蔽历史 / marker 漏盖 tool/result)
80
80
  --clip-crossstep 裁剪 assistant/message 的跨 step sourceEventSeqs(token-meter 不再抛 belongs to another step)
81
81
  --neutralize 原地中和 turn-null marker(type→retrace/marker +
82
82
  ignorable:true,删 surfaceOp/sourceEventSeqs,seq/行数不变)
83
- —— token-meter 不再刷屏,会话驻留也安全([n]-08-30 事故)
83
+ —— token-meter 不再刷屏,会话驻留也安全(2026-08-30 事故)
84
84
  --neutralize-legacy-markers
85
85
  **一次性根治历史载体债**:只中和
86
86
  assistant/message + data.editor 形态的历史 retrace marker
@@ -146,7 +146,7 @@ function printViolations(violations, maxDetails = 8) {
146
146
  }
147
147
  }
148
148
 
149
- /** 漂移抬头([n]-09-14):漂移清单 + 未复核清单 + "勿据此跑 fix --apply"。 */
149
+ /** 漂移抬头(2026-09-14):漂移清单 + 未internal清单 + "勿据此跑 fix --apply"。 */
150
150
  function driftLines(drift, probes) {
151
151
  if (!drift) return '';
152
152
  const host = probes ? `${probes.hostPackage}(SESSION_FORMAT_VERSION=${probes.sessionFormatVersion},词表 ${probes.knownTypes} 类)` : '未知';
@@ -158,15 +158,15 @@ function driftLines(drift, probes) {
158
158
  if (drift.unverifiedRules.length > 0) {
159
159
  out += ` ⛔ **UNVERIFIED**(探针与规则假设不一致,结论不可采信):${drift.unverifiedRules.join('、')}\n`;
160
160
  }
161
- out += ` 出处未复核(已知债,仅告警):${drift.driftedSources.join('、')}\n`;
161
+ out += ` 出处未internal(已知债,仅告警):${drift.driftedSources.join('、')}\n`;
162
162
  out += ` 判定前提存疑(仅告警):${drift.premiseStale.join('、')}${drift.undecidable.length ? `;无法判定:${drift.undecidable.join('、')}` : ''}\n`;
163
163
  if (drift.fixApplyBlocked) {
164
- out += ' ⛔ **禁止据此跑 `fix --apply`**(存在未验证规则:写入类动作不可逆)——先按 report 复核这些规则或显式确认。\n';
164
+ out += ' ⛔ **禁止据此跑 `fix --apply`**(存在未验证规则:写入类动作不可逆)——先按 report internal这些规则或显式确认。\n';
165
165
  }
166
166
  return out;
167
167
  }
168
168
 
169
- /** 版本支持面([n]-09-14 用户要求第 1 条):一行摘要 + 逐条告警。
169
+ /** 版本支持面(2026-09-14 用户要求第 1 条):一行摘要 + 逐条告警。
170
170
  * `readOnly` = 未验证格式 ⇒ 只读(check 照跑结构层;prewrite/fix 直接拒绝)。 */
171
171
  function supportLines(support) {
172
172
  if (!support) return '';
@@ -194,7 +194,7 @@ function notAssessableBanner(result) {
194
194
  /** 迁移预检(独立维度)文本。
195
195
  * @param {object} mig `migrationVerdict()` 结果
196
196
  * @param {boolean} partial 待迁移文件(`migration.applies===true`)⇒ 迁移维度只部分覆盖,
197
- * 不得给无条件绿([n]-09-14 规格 (i)+(iii))。
197
+ * 不得给无条件绿(2026-09-14 规格 (i)+(iii))。
198
198
  */
199
199
  function migrationLine(mig, partial = false) {
200
200
  if (!mig) return '';
@@ -207,7 +207,7 @@ function migrationLine(mig, partial = false) {
207
207
  : ` 迁移预检(独立维度,≠"可用/可升级"):✅ 通过(仅限本工具覆盖范围)\n`)
208
208
  : ` 迁移预检(独立维度,≠"可用/可升级"):❌ blocked(${n} 项:官方升级路径会拒)\n`;
209
209
  for (const v of (mig.blocked ?? []).slice(0, 5)) {
210
- s += ` [${v.id}] seq ${v.seq ?? '-'}${v.eventType ? ` (${v.eventType})` : ''} — ${String(v.message).slice(0, [n])}\n`;
210
+ s += ` [${v.id}] seq ${v.seq ?? '-'}${v.eventType ? ` (${v.eventType})` : ''} — ${String(v.message).slice(0, 130)}\n`;
211
211
  }
212
212
  if (n > 5) s += ` …另有 ${n - 5} 项\n`;
213
213
  const drops = mig.acceptedDrops ?? { registered: [], unregistered: [] };
@@ -237,7 +237,7 @@ function archiveLines(archive) {
237
237
  if (archive.verdict === 'unverifiable') {
238
238
  return ' 在位可还原(A1,独立维度):— 未提供归档根目录(不可判定;加 `--archive-root DIR` 或 env DSH_LOG_CONTRACT_ARCHIVE_ROOTS 才评估)\n';
239
239
  }
240
- const rate = (archive.restorableRate * [n]).toFixed(2);
240
+ const rate = (archive.restorableRate * 100).toFixed(2);
241
241
  let s = ` 在位可还原(A1,独立维度,只认结构指针):${archive.verdict === 'restorable' ? '✅' : '❌'} ${rate}%`
242
242
  + `(指针 ${archive.pointers},去重后 ${archive.effectivePointers ?? archive.pointers}:可还原 ${archive.restorable}`
243
243
  + ` / relocated ${archive.relocated} / 缺失 ${archive.missing} / 行缺失 ${archive.lineMissing} / sha 不符 ${archive.shaMismatch} / 无法解析 ${archive.unresolved})\n`;
@@ -324,7 +324,7 @@ function cmdCheck(args) {
324
324
  const passMark = partial ? '✔' : '✅';
325
325
  const icons = { loadable: `${passMark} 可加载`, resumable: `${passMark} 可继续`, compactable: `${passMark} 可压缩`, broken: '❌ 不可用' };
326
326
  out(`\n📋 dsh-log-contract check --resume —— ${file}\n`);
327
- out(` 事件 ${summary.events} | surface 节点 ${summary.surfaceNodes} | replace 代数 ${summary.replaceGeneration} | 帧 ${summary.frames}(${(summary.compressedBytes / [n]).toFixed(1)}KiB → ${(summary.plaintextBytes / [n]).toFixed(1)}KiB)\n`);
327
+ out(` 事件 ${summary.events} | surface 节点 ${summary.surfaceNodes} | replace 代数 ${summary.replaceGeneration} | 帧 ${summary.frames}(${(summary.compressedBytes / 1024).toFixed(1)}KiB → ${(summary.plaintextBytes / 1024).toFixed(1)}KiB)\n`);
328
328
  out(` 违规 ${summary.total}(error ${summary.bySeverity.error} / warning ${summary.bySeverity.warning})\n\n`);
329
329
  out(` 分层结论(**本工具规则集内**,不代表"可用",也不代表官方升级会接受):\n`);
330
330
  const tiers = [
@@ -351,7 +351,7 @@ function cmdCheck(args) {
351
351
  }
352
352
 
353
353
  out(`\n📋 dsh-log-contract check —— ${file}\n`);
354
- out(` 事件 ${summary.events} | surface 节点 ${summary.surfaceNodes} | replace 代数 ${summary.replaceGeneration} | 帧 ${summary.frames}(${(summary.compressedBytes / [n]).toFixed(1)}KiB → ${(summary.plaintextBytes / [n]).toFixed(1)}KiB)\n`);
354
+ out(` 事件 ${summary.events} | surface 节点 ${summary.surfaceNodes} | replace 代数 ${summary.replaceGeneration} | 帧 ${summary.frames}(${(summary.compressedBytes / 1024).toFixed(1)}KiB → ${(summary.plaintextBytes / 1024).toFixed(1)}KiB)\n`);
355
355
  out(` 违规 ${summary.total}(error ${summary.bySeverity.error} / warning ${summary.bySeverity.warning})\n`);
356
356
  out(supportLines(result.support));
357
357
  out(driftLines(result.drift, result.probes));
@@ -393,7 +393,7 @@ function cmdPrewrite(args) {
393
393
  ? process.env.DSH_LOG_CONTRACT_IGNORABLE_WHITELIST.split(',').map((x) => x.trim()).filter(Boolean)
394
394
  : undefined;
395
395
  const baseline = validateSessionLog(log, { ignorableWhitelist: prewriteWhitelist });
396
- // 版本支持面([n]-09-14 用户要求第 1 条):**未验证格式 ⇒ 只读**,不得给出写入结论。
396
+ // 版本支持面(2026-09-14 用户要求第 1 条):**未验证格式 ⇒ 只读**,不得给出写入结论。
397
397
  if (baseline.support?.readOnly) {
398
398
  fail(`未验证的会话格式(来源 ${baseline.support.file.source},版本 v${baseline.support.file.version})——按只读处理,写前校验无法给出可信结论。`
399
399
  + ` ${baseline.support.warnings?.[0] ?? ''}`, 3);
@@ -451,7 +451,7 @@ function cmdContracts() {
451
451
  for (const r of CONTRACT_RULES) {
452
452
  const flags = [
453
453
  r.candidate ? '候选规则' : null,
454
- r.sourceVerified === false ? '出处未复核' : null,
454
+ r.sourceVerified === false ? '出处未internal' : null,
455
455
  r.premiseStale ? '判定前提存疑' : null,
456
456
  ].filter(Boolean).join(' / ');
457
457
  out(` ${r.id} [${r.severity}/${r.layer}] ${r.title}${flags ? ` ⟪${flags}⟫` : ''}\n ${r.description}\n 出处: ${r.source}\n\n`);
@@ -472,7 +472,7 @@ function cmdFix(args) {
472
472
  const trimBudget = budgetIdx >= 0 && args[budgetIdx + 1] ? Number(args[budgetIdx + 1]) : undefined;
473
473
  const compactIdx = args.indexOf('--compact-last');
474
474
  const compactLast = compactIdx >= 0 && args[compactIdx + 1] ? Number(args[compactIdx + 1]) : undefined;
475
- // L4 新原语([n]-08-30 收编外部验证工具)
475
+ // L4 新原语(2026-08-30 收编外部验证工具)
476
476
  const tailIdx = args.indexOf('--tail-renumber');
477
477
  const tailRenumberDelta = tailIdx >= 0 && args[tailIdx + 1] ? Number(args[tailIdx + 1]) : undefined;
478
478
  const neutralizeOrphan = args.includes('--neutralize-orphan');
@@ -575,7 +575,7 @@ function cmdAuditReport(args) {
575
575
  process.exit(0);
576
576
  }
577
577
  out(`\n📊 dsh-log-contract audit-report —— ${file}\n`);
578
- out(` 工具调用 ${report.calls} | 结果 ${report.results} | 孤儿 ${report.orphans} | 配对率 ${(report.pairingRate * [n]).toFixed(1)}%\n`);
578
+ out(` 工具调用 ${report.calls} | 结果 ${report.results} | 孤儿 ${report.orphans} | 配对率 ${(report.pairingRate * 100).toFixed(1)}%\n`);
579
579
  out(` 输出总字节 ${report.outputBytes}`);
580
580
  if (report.largest) out(` | 最大 ${report.largest.size}B(${(report.largest.command || '?').slice(0, 40)})`);
581
581
  out(`\n 命令分布(前 ${report.commands.top.length} 个去重):\n`);