dsh-log-contract 0.3.22 → 0.3.24
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 +84 -97
- package/README.zh.md +69 -74
- package/bin/dsh-log-contract.mjs +4 -4
- package/docs/CONTRACTS.md +34 -34
- package/lib/archive.js +304 -14
- package/lib/checks.js +1332 -64
- package/lib/compat.js +278 -7
- package/lib/contracts.js +522 -8
- package/lib/host-probes.js +178 -4
- package/lib/legacy-fold.js +174 -4
- package/lib/log-reader.js +295 -3
- package/lib/prewrite.js +4 -4
- package/lib/repair.js +11 -11
- package/lib/validate.js +320 -49
- package/lib/version-support.js +146 -4
- package/lib/vocab.js +227 -4
- package/package.json +5 -15
- package/adapters/dsh/archive.js +0 -135
- package/adapters/dsh/event-shapes.js +0 -639
- package/adapters/dsh/format-versions.js +0 -743
- package/adapters/dsh/frames.js +0 -331
- package/adapters/dsh/host-probes.js +0 -212
- package/adapters/dsh/index.js +0 -35
- package/adapters/dsh/rules.js +0 -560
- package/adapters/dsh/surface.js +0 -792
- package/adapters/dsh/vocab.js +0 -66
- package/contract/index.js +0 -17
- package/contract/invariants.js +0 -478
- package/contract/registry.js +0 -77
- package/contract/rules.js +0 -70
- package/contract/verdict.js +0 -52
- package/docs/ARCHITECTURE.md +0 -46
package/README.md
CHANGED
|
@@ -35,7 +35,6 @@ plugin marker semantics).
|
|
|
35
35
|
---
|
|
36
36
|
|
|
37
37
|
## Where it sits in the business layer
|
|
38
|
-
|
|
39
38
|
> **dsh-log-contract is the core capability component of [dsh-retrace](https://github.com/yamingmou/dsh-retrace)** (the business layer's "doctor" module): it **checks and repairs** session logs so every recall/edit/rollback lands on a legal log — pre-write validation (`prewrite`) rejects error-level violations **before** anything is written.
|
|
40
39
|
>
|
|
41
40
|
> **About `/compact` (stated honestly)**: what this tool guarantees is that **new writes** stop creating token-meter pairing debt — since two-segment atomic pairs (marker + paired segment) landed, new markers pass T1 by construction. **Legacy** (single-segment) markers are still **known design debt**: pre-write validation downgrades their T1 violation to a warning (`legacyMarkerKindOf` in `lib/prewrite.js`, which applies to **historical markers only**), so such sessions need **one check + cleanup before compaction** (`check` to locate → `fix --remove-markers`; the plugin side calls this "the doctor"). Otherwise the T1 self-check blocks `/compact`.
|
|
@@ -54,7 +53,6 @@ DSH (see the [dsh-retrace repository](https://github.com/yamingmou/dsh-retrace))
|
|
|
54
53
|
---
|
|
55
54
|
|
|
56
55
|
## Why it exists
|
|
57
|
-
|
|
58
56
|
**"one log, two consumers, two verdicts"**: one log is consumed by both
|
|
59
57
|
humans and automated programs. Humans tolerate format drift; programs depend on
|
|
60
58
|
strict contracts. Once the format drifts, humans see nothing wrong while programs
|
|
@@ -69,7 +67,6 @@ line-by-line verification against the official Host source (each rule carries it
|
|
|
69
67
|
---
|
|
70
68
|
|
|
71
69
|
## Three-layer contract (the model)
|
|
72
|
-
|
|
73
70
|
> 30+ rules across the layers below (`contracts` lists them all, each with its
|
|
74
71
|
> official source reference).
|
|
75
72
|
|
|
@@ -86,29 +83,7 @@ line-by-line verification against the official Host source (each rule carries it
|
|
|
86
83
|
|
|
87
84
|
---
|
|
88
85
|
|
|
89
|
-
## ⚡ Case log — why "production-grade" is not a slogan
|
|
90
|
-
|
|
91
|
-
Each entry below is a **real log-corruption shape** from production sessions — the cases that
|
|
92
|
-
shaped this tool. Dates and shapes are real; session ids and file names are
|
|
93
|
-
omitted.
|
|
94
|
-
|
|
95
|
-
| # | Date | What happened | The rule / fix it produced |
|
|
96
|
-
|---|---|---|---|
|
|
97
|
-
| 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 |
|
|
98
|
-
| 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` |
|
|
99
|
-
| 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` |
|
|
100
|
-
| 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 |
|
|
101
|
-
| 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) |
|
|
102
|
-
| 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` |
|
|
103
|
-
|
|
104
|
-
> **Takeaway**: these rules are not synthetic theory — each one is pinned by a
|
|
105
|
-
> regression test that reproduces the corrupt shape it guards against. That is what
|
|
106
|
-
> "production-grade" means here.
|
|
107
|
-
|
|
108
|
-
---
|
|
109
|
-
|
|
110
86
|
## Version support (host / session format)
|
|
111
|
-
|
|
112
87
|
**Tested baseline (the versions this rule set was verified against)**:
|
|
113
88
|
|
|
114
89
|
| Item | Baseline | Note |
|
|
@@ -135,8 +110,61 @@ Both the human-readable `check` output and the `--json` `support` field carry th
|
|
|
135
110
|
version support: host @deepseek-ai/dsh-session@0.1.5-rc.1 (baseline 0.1.5-rc.1) | file format v3 (header, baseline)
|
|
136
111
|
```
|
|
137
112
|
|
|
138
|
-
##
|
|
113
|
+
## 🆕 0.3.18 – 0.3.21 · DSH 0.2.x (session format v4) support
|
|
114
|
+
**Session format v4** (`@deepseek-ai/dsh-session` 0.2.x) is now validated by format-version dispatch
|
|
115
|
+
rather than by relaxing the format gate:
|
|
139
116
|
|
|
117
|
+
- `tool/result` is validated with the v4 shape (`role: 'tool'`, no `tool-result` wrapper block)
|
|
118
|
+
- `system/message` accepts v4's `source.kind: 'system-prompt'`
|
|
119
|
+
- validation for v3 and earlier is **unchanged** (identical verdicts on 408 real v3 sessions before/after)
|
|
120
|
+
- the format gate still rejects **unknown** future versions (`readOnly`); v5+ remains unassessable by design
|
|
121
|
+
|
|
122
|
+
**New rules (51 total):**
|
|
123
|
+
|
|
124
|
+
| Rule | Checks |
|
|
125
|
+
|---|---|
|
|
126
|
+
| `G4` | unknown historical events may be declaratively skipped (`ignorable: true`; allow-list injectable) |
|
|
127
|
+
| `S10` | `sourceEventSeqs` elements: non-negative integers after decoding (official interval pairs allowed in storage) |
|
|
128
|
+
| `I2` | `seedLength` means *number of inherited events* (not bytes); `parentSession` + missing/0 is legal |
|
|
129
|
+
| `P5` | two-segment carrier pairing: 2nd segment's first seq == 1st segment seq (read side accepts the legacy order) |
|
|
130
|
+
| `A1` | "in-place restorable" is judged from structured fields only (`archiveRef` / `archive` / `externalized.*`) — never from free text |
|
|
131
|
+
|
|
132
|
+
**Large sessions:** reading is line-wise (no whole-file stringification ⇒ no `ERR_STRING_TOO_LONG` above ~536 MB),
|
|
133
|
+
and repair rebuilds `.jsonl.zstd` with streaming frames (header frame + chunked body frames, per-frame checksum + round-trip).
|
|
134
|
+
|
|
135
|
+
**Windows:** the `header.cwd` absolute-path check in `H2` is platform-aware (`win32` and `posix` both accepted).
|
|
136
|
+
|
|
137
|
+
**Compatibility:** Node ≥ 22; `@deepseek-ai/dsh-session` `^0.1.0-rc.7 || ^0.1.5-rc.1 || ^0.2.0-rc.1`; session formats v0–v4.
|
|
138
|
+
|
|
139
|
+
## Case log — why "production-grade" is not a slogan
|
|
140
|
+
Each entry below is a **real log-corruption shape** from production sessions — the cases that
|
|
141
|
+
shaped this tool. Dates and shapes are real; session ids and file names are
|
|
142
|
+
omitted.
|
|
143
|
+
|
|
144
|
+
| # | Date | What happened | The rule / fix it produced |
|
|
145
|
+
|---|---|---|---|
|
|
146
|
+
| 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 |
|
|
147
|
+
| 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` |
|
|
148
|
+
| 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` |
|
|
149
|
+
| 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 |
|
|
150
|
+
| 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) |
|
|
151
|
+
| 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` |
|
|
152
|
+
| 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) |
|
|
153
|
+
| 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 |
|
|
154
|
+
| 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 |
|
|
155
|
+
| 10 | 2026-09-17 | On **Windows**, `header.cwd` was judged with POSIX-only rules → **every** session flagged by **H2** ⇒ platform-aware absolute-path check |
|
|
156
|
+
| 11 | 2026-10-20 | A **> 500 MB session** crashed the reader (`ERR_STRING_TOO_LONG`) and repair built the whole text in memory ⇒ line-wise decode + streaming frame rebuild |
|
|
157
|
+
| 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 |
|
|
158
|
+
| 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 |
|
|
159
|
+
| 14 | 2026-10-20 | An **unknown but explicitly ignorable** event type blocked an entire migration ⇒ **G4** declarative skip + allow-list |
|
|
160
|
+
|
|
161
|
+
> **Takeaway**: these rules are not synthetic theory — each one is pinned by a
|
|
162
|
+
> regression test that reproduces the corrupt shape it guards against. That is what
|
|
163
|
+
> "production-grade" means here.
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Installation
|
|
140
168
|
```bash
|
|
141
169
|
pnpm add -D dsh-log-contract # or npm install
|
|
142
170
|
pnpm dlx dsh-log-contract --help
|
|
@@ -157,7 +185,6 @@ with the Harness read path).
|
|
|
157
185
|
---
|
|
158
186
|
|
|
159
187
|
## CLI
|
|
160
|
-
|
|
161
188
|
### 1. Offline health check
|
|
162
189
|
|
|
163
190
|
```bash
|
|
@@ -262,7 +289,6 @@ are flagged in `check`.
|
|
|
262
289
|
---
|
|
263
290
|
|
|
264
291
|
## Node API (embed pre-write validation in your script)
|
|
265
|
-
|
|
266
292
|
```js
|
|
267
293
|
import { loadSessionLog, validateSessionLog, createPreWriter } from 'dsh-log-contract';
|
|
268
294
|
|
|
@@ -289,7 +315,6 @@ if (!verdict.ok) {
|
|
|
289
315
|
---
|
|
290
316
|
|
|
291
317
|
## Tests
|
|
292
|
-
|
|
293
318
|
```bash
|
|
294
319
|
pnpm check && pnpm test # syntax check + contract-doc drift gate + all unit tests
|
|
295
320
|
```
|
|
@@ -303,7 +328,6 @@ pnpm check && pnpm test # syntax check + contract-doc drift gate + all unit t
|
|
|
303
328
|
> work from a clean clone.
|
|
304
329
|
|
|
305
330
|
## Local git hooks (opt-in)
|
|
306
|
-
|
|
307
331
|
The repository ships `.githooks/pre-push` (runs `pnpm check` before pushing), but it is
|
|
308
332
|
**not active automatically on clone** — point Git at it explicitly:
|
|
309
333
|
|
|
@@ -335,75 +359,16 @@ boundary note in [docs/CONTRACTS.md](docs/CONTRACTS.md).
|
|
|
335
359
|
|
|
336
360
|
---
|
|
337
361
|
|
|
338
|
-
##
|
|
362
|
+
## ⚠️ Upgrading — behaviour notes (0.3.12 → 0.3.24)
|
|
339
363
|
|
|
340
|
-
|
|
341
|
-
- [x] **Phase 1.5 (0.2.0)**: `fix` subcommand (strict seq scan + W1/W2 wire checks +
|
|
342
|
-
marker removal with renumbering + official frame rebuild); CI integration
|
|
343
|
-
(`dsh-log-contract check` as a scheduled guard over the Harness session dir)
|
|
344
|
-
- [x] **0.3.x (2026-08-30 case hardening)**: T1 token-meter pairing → 0.3.1 W1/W2
|
|
345
|
-
fold-position fix → 0.3.2 `tailSeq` → 0.3.3 `fix --neutralize` (in-place
|
|
346
|
-
turn-null neutralization) → 0.3.4 `fix --clip-crossstep` (cross-step clipping) →
|
|
347
|
-
0.3.5 **T2/S9/I1 rules** (cross-step source refs / physical order / inbox replay)
|
|
348
|
-
- [x] **0.3.6 → 0.3.15**: per-version rule routing for v0–v3 (T3/T4/T5, L3–L5, E8/E9/E10),
|
|
349
|
-
exit codes `3`/`4` for the host-capability and migration gates, and a version-support
|
|
350
|
-
report that says what was *not* verified (see [CHANGELOG.md](CHANGELOG.md))
|
|
351
|
-
- [ ] Phase 2: runtime guard (subscribe to the session append stream, validate live,
|
|
352
|
-
mark violations as `dsh/contract-violation`, policy configurable alert/block) —
|
|
353
|
-
DSH plugin form
|
|
354
|
-
- [ ] Phase 3: link with dsh-turn-guard / dsh-retrace timeline
|
|
355
|
-
|
|
356
|
-
## License
|
|
357
|
-
|
|
358
|
-
MIT © OfferKuai Team
|
|
359
|
-
|
|
360
|
-
---
|
|
361
|
-
|
|
362
|
-
## 🧱 Architecture — contract layer + platform adapter
|
|
363
|
-
|
|
364
|
-
Validation is split into a **platform-agnostic contract layer** (`contract/`) and a **platform adapter**
|
|
365
|
-
(`adapters/dsh/`): invariants, verdict model and the rule registry are shared; event shapes, format
|
|
366
|
-
versions (v0–v4), zstd framing and surface semantics live in the adapter. Adding another host platform is intended to
|
|
367
|
-
mean writing one adapter; the split is extracted and enforced today, while the adapter-facing API
|
|
368
|
-
(orchestration entry, id-neutral violations) is still being finalized.
|
|
369
|
-
|
|
370
|
-
The boundary is machine-enforced: `contract/` may contain no platform vocabulary and no adapter/implementation
|
|
371
|
-
imports (`pnpm check:strict`, also in CI and the optional pre-push hook). The public API, rule set (51 rules)
|
|
372
|
-
and verdicts are unchanged.
|
|
373
|
-
|
|
374
|
-
**Current status: partial.** The split is extracted and machine-enforced, but a second adapter is **not yet
|
|
375
|
-
drop-in**: the contract layer still emits platform rule ids for some invariants, and there is no
|
|
376
|
-
platform-neutral orchestration entry yet — a second adapter today would also need a thin runner.
|
|
377
|
-
See "Known gaps" in the changelog for the tracked follow-up list. See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
|
|
378
|
-
|
|
379
|
-
## 🆕 0.3.18 – 0.3.21 · DSH 0.2.x (session format v4) support
|
|
380
|
-
|
|
381
|
-
**Session format v4** (`@deepseek-ai/dsh-session` 0.2.x) is now validated by format-version dispatch
|
|
382
|
-
rather than by relaxing the format gate:
|
|
383
|
-
|
|
384
|
-
- `tool/result` is validated with the v4 shape (`role: 'tool'`, no `tool-result` wrapper block)
|
|
385
|
-
- `system/message` accepts v4's `source.kind: 'system-prompt'`
|
|
386
|
-
- validation for v3 and earlier is **unchanged** (identical verdicts on 408 real v3 sessions before/after)
|
|
387
|
-
- the format gate still rejects **unknown** future versions (`readOnly`); v5+ remains unassessable by design
|
|
388
|
-
|
|
389
|
-
**New rules (51 total):**
|
|
364
|
+
### 0.3.18 → 0.3.24 in one paragraph
|
|
390
365
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
| `A1` | "in-place restorable" is judged from structured fields only (`archiveRef` / `archive` / `externalized.*`) — never from free text |
|
|
398
|
-
|
|
399
|
-
**Large sessions:** reading is line-wise (no whole-file stringification ⇒ no `ERR_STRING_TOO_LONG` above ~536 MB),
|
|
400
|
-
and repair rebuilds `.jsonl.zstd` with streaming frames (header frame + chunked body frames, per-frame checksum + round-trip).
|
|
401
|
-
|
|
402
|
-
**Windows:** the `header.cwd` absolute-path check in `H2` is platform-aware (`win32` and `posix` both accepted).
|
|
403
|
-
|
|
404
|
-
**Compatibility:** Node ≥ 22; `@deepseek-ai/dsh-session` `^0.1.0-rc.7 || ^0.1.5-rc.1 || ^0.2.0-rc.1`; session formats v0–v4.
|
|
405
|
-
|
|
406
|
-
## ⚠️ Upgrading to 0.3.17 — behaviour changes you must know (0.3.12 → 0.3.17)
|
|
366
|
+
Session format **v4** (host `dsh-session` 0.2.x) is supported by version dispatch (`tool/result` role,
|
|
367
|
+
`system/message` source); five rules were added (`G4` unknown-but-ignorable events, `S10` reference element
|
|
368
|
+
types, `I2` `seedLength` semantics, `P5` carrier pairing, `A1` structured-only in-place restorability);
|
|
369
|
+
large sessions (> 500 MB) are read line-wise and repaired with streaming frames; the Windows absolute-path
|
|
370
|
+
check for `H2` is platform-aware. 0.3.22 adds a `contract/` + `adapters/dsh/` layering (behaviour unchanged;
|
|
371
|
+
still **partial** — see the changelog's known-gap list). Verdicts, exit codes and `--json` fields are unchanged.
|
|
407
372
|
|
|
408
373
|
> **0.3.17 changes no behaviour.** It only adjusts the wording of comments, test titles, a few
|
|
409
374
|
> diagnostic strings and the README. Every verdict, exit code and `--json`
|
|
@@ -438,3 +403,25 @@ the migration dimension is only partially covered.
|
|
|
438
403
|
The rule set is **not** the official upgrade chain's acceptance condition. `assessmentScope=partial` means
|
|
439
404
|
"the part this tool looked at is clean" — it does **not** mean the official upgrade will accept the file.
|
|
440
405
|
Read `coverage.uncovered` for the known gaps.
|
|
406
|
+
|
|
407
|
+
## Roadmap
|
|
408
|
+
- [x] **Phase 1 (0.1.0)**: CLI offline check + pre-write validation + contract catalog
|
|
409
|
+
- [x] **Phase 1.5 (0.2.0)**: `fix` subcommand (strict seq scan + W1/W2 wire checks +
|
|
410
|
+
marker removal with renumbering + official frame rebuild); CI integration
|
|
411
|
+
(`dsh-log-contract check` as a scheduled guard over the Harness session dir)
|
|
412
|
+
- [x] **0.3.x (2026-08-30 case hardening)**: T1 token-meter pairing → 0.3.1 W1/W2
|
|
413
|
+
fold-position fix → 0.3.2 `tailSeq` → 0.3.3 `fix --neutralize` (in-place
|
|
414
|
+
turn-null neutralization) → 0.3.4 `fix --clip-crossstep` (cross-step clipping) →
|
|
415
|
+
0.3.5 **T2/S9/I1 rules** (cross-step source refs / physical order / inbox replay)
|
|
416
|
+
- [x] **0.3.6 → 0.3.15**: per-version rule routing for v0–v3 (T3/T4/T5, L3–L5, E8/E9/E10),
|
|
417
|
+
exit codes `3`/`4` for the host-capability and migration gates, and a version-support
|
|
418
|
+
report that says what was *not* verified (see [CHANGELOG.md](CHANGELOG.md))
|
|
419
|
+
- [ ] Phase 2: runtime guard (subscribe to the session append stream, validate live,
|
|
420
|
+
mark violations as `dsh/contract-violation`, policy configurable alert/block) —
|
|
421
|
+
DSH plugin form
|
|
422
|
+
- [ ] Phase 3: link with dsh-turn-guard / dsh-retrace timeline
|
|
423
|
+
|
|
424
|
+
## License
|
|
425
|
+
MIT © OfferKuai Team
|
|
426
|
+
|
|
427
|
+
---
|
package/README.zh.md
CHANGED
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
---
|
|
30
30
|
|
|
31
31
|
## 它在业务层里的位置
|
|
32
|
-
|
|
33
32
|
> **dsh-log-contract 是 [dsh-retrace](https://github.com/yamingmou/dsh-retrace) 的核心能力组件**(业务层的「医生」模块):负责会话日志的**体检与修复**——让每一次撤回/编辑/回退都落在合法日志上,写前校验(`prewrite`)会把 error 级违约**拦在落盘之前**。
|
|
34
33
|
>
|
|
35
34
|
> **关于 `/compact`(如实表述)**:本工具保证的是**新写入**不再制造 token-meter 配对债——自两段原子成对(marker + 配对段)起,新 marker 天然通过 T1。**历史**(单段)marker 仍属**已知设计债**:写前校验对它的 T1 违规降级为 warning(`lib/prewrite.js` 的 `legacyMarkerKindOf` 白名单,**只适用于历史 marker**),因此这类会话**压缩(`/compact`)前需要先跑一次体检 + 清理**(`check` 定位 → `fix --remove-markers`;插件侧即「医生」),否则 T1 自检会拦住压缩。
|
|
@@ -47,7 +46,6 @@ dsh-retrace 的「日志体检与修复」能力——与 dsh-retrace 一起构
|
|
|
47
46
|
---
|
|
48
47
|
|
|
49
48
|
## 为什么需要它
|
|
50
|
-
|
|
51
49
|
**「one log, two consumers, two verdicts」**:一条日志同时被人类与自动化程序消费,人眼容忍格式微调,程序解析依赖严格契约;格式一旦漂移,人看不出问题,程序直接崩溃或误报。
|
|
52
50
|
|
|
53
51
|
**这里大多数规则都来自会话日志中实际出现过的损坏形态**——见下方 [⚡ 案例记录](#-案例记录)。由这些案例派生的用例都有回归测试钉住:损坏的日志形态本工具必须报出,修复后的形态必须通过。其余规则来自对官方宿主源码的逐行核对(每条规则都带 `source`)。
|
|
@@ -55,7 +53,6 @@ dsh-retrace 的「日志体检与修复」能力——与 dsh-retrace 一起构
|
|
|
55
53
|
---
|
|
56
54
|
|
|
57
55
|
## 三层契约(判定模型)
|
|
58
|
-
|
|
59
56
|
> 30+ 条规则,覆盖以下三层(`contracts` 列出全部,每条附官方源码出处)。
|
|
60
57
|
|
|
61
58
|
| 层 | 规则 | 守护什么 |
|
|
@@ -69,25 +66,7 @@ dsh-retrace 的「日志体检与修复」能力——与 dsh-retrace 一起构
|
|
|
69
66
|
|
|
70
67
|
---
|
|
71
68
|
|
|
72
|
-
## ⚡ 案例记录 ——「生产级保证」不是口号
|
|
73
|
-
|
|
74
|
-
下面每一条都来自**生产会话中实际出现的日志损坏形态**——正是这些案例促成了本工具。日期与形态真实,会话 id 与文件名省略。
|
|
75
|
-
|
|
76
|
-
| # | 日期 | 发生了什么 | 产出的规则/修复 |
|
|
77
|
-
|---|---|---|---|
|
|
78
|
-
| 1 | 2026-08-25 | 一次「恢复被隐藏内容」的修复写了**清空 `sourceEventSeqs`** 的 replace marker → 会话加载被拒(`SessionPersistenceCorruptionError`);第二次尝试把 marker 改成 **append** → 客户端引擎崩溃。两次都是**违约写入没被拦**。 | **S5**(sourceEventSeqs 必须覆盖被替换节点)、**M1**(turn-null 的 assistant/message 只能 replace)、写前校验 |
|
|
79
|
-
| 2 | 2026-08-27~28 | 中断/暂停的轮次恢复时按**过期内存光标**重放,把旧 seq 追加到文件尾(尾部回归、重复批次);两个写入者交织 → **文件物理序非单调**(`734056 → 733539 → 735470`)。会话 `seq gap` 加载失败。 | **S9**(物理序单调)、fix `--tail-renumber` |
|
|
80
|
-
| 3 | 2026-08-27~28 | **fork 边界孤儿 spliced**:fork 的「移除父待处理提示词」splice 假设父会话 inbox;子会话 seed 相对重放里 inbox 为空 → `resume failed: invalid persisted inbox splice`。 | **I1**(inbox seed 相对重放)、fix `--neutralize-orphan` |
|
|
81
|
-
| 4 | 2026-08-28 | 超限会话(**1,052,557 tokens** vs 1M 窗口)既无法继续也无法 `/compact`;裁剪预算估算对中文低估 ~3.7×。 | T1(token-meter 配对,保障可压缩)、`fix --trim-budget` 预算指引 |
|
|
82
|
-
| 5 | 2026-08-29 | **W1/W2 wire 违规**:marker 遮蔽了带 tool_calls 的 assistant 但漏盖 tool 结果 → 悬空 tool,严格端点 `INVALID_REQUEST` 拒绝请求流。 | **W1 / W2**(wire 消息流) |
|
|
83
|
-
| 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` |
|
|
84
|
-
|
|
85
|
-
> **结论**:这些规则不是合成理论——每一条都有回归测试复现它守护的那种损坏形态。这就是这里「生产级」的含义。
|
|
86
|
-
|
|
87
|
-
---
|
|
88
|
-
|
|
89
69
|
## 版本支持(宿主 / 会话格式)
|
|
90
|
-
|
|
91
70
|
**测试基线(本规则集验证过的版本)**:
|
|
92
71
|
|
|
93
72
|
| 项 | 基线 | 说明 |
|
|
@@ -115,8 +94,57 @@ dsh-retrace 的「日志体检与修复」能力——与 dsh-retrace 一起构
|
|
|
115
94
|
测试基线:@deepseek-ai/dsh-session@0.1.5-rc.1 | 会话格式 v3(已知 0/1/2/3;peer ^0.1.0-rc.7 || ^0.1.5-rc.1)
|
|
116
95
|
```
|
|
117
96
|
|
|
118
|
-
##
|
|
97
|
+
## 🆕 0.3.18 – 0.3.21 · 支持 DSH 0.2.x(会话格式 v4)
|
|
98
|
+
**会话格式 v4**(`@deepseek-ai/dsh-session` 0.2.x)改为**按格式版本分派规则**,而不是放宽格式闸门:
|
|
99
|
+
|
|
100
|
+
- `tool/result` 按 v4 形状校验(`role: 'tool'`、无 `tool-result` 包裹块)
|
|
101
|
+
- `system/message` 接受 v4 的 `source.kind: 'system-prompt'`
|
|
102
|
+
- **v3 及更早的判据零改动**(408 份真实 v3 会话前后判定完全一致)
|
|
103
|
+
- 格式闸门仍**拒绝未知的未来版本**(`readOnly`);v5+ 按设计保持"不可评估"
|
|
104
|
+
|
|
105
|
+
**新增规则(共 51 条):**
|
|
106
|
+
|
|
107
|
+
| 规则 | 判据 |
|
|
108
|
+
|---|---|
|
|
109
|
+
| `G4` | 未知历史事件可**声明式跳过**(`ignorable: true`;白名单可注入) |
|
|
110
|
+
| `S10` | `sourceEventSeqs` 元素:**解码后**必须为非负整数(存储层允许官方区间对) |
|
|
111
|
+
| `I2` | `seedLength` = **继承事件条数**(非字节);`parentSession` 存在且缺失/0 属合法 |
|
|
112
|
+
| `P5` | 两段 carrier 配对:第 2 段首元素 = 第 1 段 seq(读侧兼容早期写法) |
|
|
113
|
+
| `A1` | 「在位可还原」**只认结构化字段**(`archiveRef`/`archive`/`externalized.*`),不从自由文本推断 |
|
|
114
|
+
|
|
115
|
+
**大会话**:读取改为**按行解码**(不再整文件字符串化 ⇒ 约 536MB 以上不再抛 `ERR_STRING_TOO_LONG`);
|
|
116
|
+
修复采用**流式帧重建** `.jsonl.zstd`(header 帧 + 正文分块多帧,逐帧 checksum + roundtrip 校验)。
|
|
117
|
+
|
|
118
|
+
**Windows**:`H2` 的 `header.cwd` 绝对路径判断改为**平台感知**(`win32` 与 `posix` 都认)。
|
|
119
|
+
|
|
120
|
+
**兼容性**:Node ≥ 22;`@deepseek-ai/dsh-session` `^0.1.0-rc.7 || ^0.1.5-rc.1 || ^0.2.0-rc.1`;会话格式 v0–v4。
|
|
121
|
+
|
|
122
|
+
## 案例记录 ——「生产级保证」不是口号
|
|
123
|
+
下面每一条都来自**生产会话中实际出现的日志损坏形态**——正是这些案例促成了本工具。日期与形态真实,会话 id 与文件名省略。
|
|
124
|
+
|
|
125
|
+
| # | 日期 | 发生了什么 | 产出的规则/修复 |
|
|
126
|
+
|---|---|---|---|
|
|
127
|
+
| 1 | 2026-08-25 | 一次「恢复被隐藏内容」的修复写了**清空 `sourceEventSeqs`** 的 replace marker → 会话加载被拒(`SessionPersistenceCorruptionError`);第二次尝试把 marker 改成 **append** → 客户端引擎崩溃。两次都是**违约写入没被拦**。 | **S5**(sourceEventSeqs 必须覆盖被替换节点)、**M1**(turn-null 的 assistant/message 只能 replace)、写前校验 |
|
|
128
|
+
| 2 | 2026-08-27~28 | 中断/暂停的轮次恢复时按**过期内存光标**重放,把旧 seq 追加到文件尾(尾部回归、重复批次);两个写入者交织 → **文件物理序非单调**(`734056 → 733539 → 735470`)。会话 `seq gap` 加载失败。 | **S9**(物理序单调)、fix `--tail-renumber` |
|
|
129
|
+
| 3 | 2026-08-27~28 | **fork 边界孤儿 spliced**:fork 的「移除父待处理提示词」splice 假设父会话 inbox;子会话 seed 相对重放里 inbox 为空 → `resume failed: invalid persisted inbox splice`。 | **I1**(inbox seed 相对重放)、fix `--neutralize-orphan` |
|
|
130
|
+
| 4 | 2026-08-28 | 超限会话(**1,052,557 tokens** vs 1M 窗口)既无法继续也无法 `/compact`;裁剪预算估算对中文低估 ~3.7×。 | T1(token-meter 配对,保障可压缩)、`fix --trim-budget` 预算指引 |
|
|
131
|
+
| 5 | 2026-08-29 | **W1/W2 wire 违规**:marker 遮蔽了带 tool_calls 的 assistant 但漏盖 tool 结果 → 悬空 tool,严格端点 `INVALID_REQUEST` 拒绝请求流。 | **W1 / W2**(wire 消息流) |
|
|
132
|
+
| 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` |
|
|
133
|
+
| 7 | 2026-08-31 | 日志被压成**单个 zstd 帧**(或 header 未单独成帧)→ 不同读取器对记录边界理解不一致 ⇒ **Z4/Z5** 帧形状规则(首帧必须恰好一行 header;正文分帧) |
|
|
134
|
+
| 8 | 2026-08-31 | **尾帧在写入中被撕裂**的日志完全无法加载、且没有诊断 ⇒ **Z1** + 明确报「尾帧撕裂 / 写入中」 |
|
|
135
|
+
| 9 | 2026-09-09 | **会话格式 v4** 下 `tool/result` 改用 `role:'tool'`、`system/message` 带 `system-prompt` 来源 → v3 语义的检查在**健康 v4 日志**上产出**数千条误报** ⇒ 版本分派 + **E6/E9** v4 语义 |
|
|
136
|
+
| 10 | 2026-09-17 | **Windows** 上 `header.cwd` 用 POSIX 规则判定 → **所有**会话被 **H2** 误报 ⇒ 平台感知的绝对路径判定 |
|
|
137
|
+
| 11 | 2026-10-20 | **超过 500MB 的会话**让读取器崩溃(`ERR_STRING_TOO_LONG`),修复时又把全文拼进内存 ⇒ 按行解码 + 流式帧重建 |
|
|
138
|
+
| 12 | 2026-10-20 | 两段式载体引用有的把「审计段」写在前面、早期约定从区间起点开始 → 读取侧报出**数百个假孤儿载体** ⇒ **P5** 写侧成对 + 读侧容错 |
|
|
139
|
+
| 13 | 2026-10-20 | `seedLength` 被部分消费方当作**字节数**(其语义是「继承事件条数」),且 `parentSession` 配缺失/0 被当成损坏 ⇒ **I2** 语义钉死 |
|
|
140
|
+
| 14 | 2026-10-20 | 一种**未知但显式可忽略**的事件类型让整条迁移卡死 ⇒ **G4** 声明式跳过 + 白名单 |
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
> **结论**:这些规则不是合成理论——每一条都有回归测试复现它守护的那种损坏形态。这就是这里「生产级」的含义。
|
|
144
|
+
|
|
145
|
+
---
|
|
119
146
|
|
|
147
|
+
## 安装
|
|
120
148
|
```bash
|
|
121
149
|
pnpm add -D dsh-log-contract # 或 npm install
|
|
122
150
|
pnpm dlx dsh-log-contract --help
|
|
@@ -134,7 +162,6 @@ pnpm dlx dsh-log-contract --help
|
|
|
134
162
|
---
|
|
135
163
|
|
|
136
164
|
## CLI 用法
|
|
137
|
-
|
|
138
165
|
### 1. 离线体检
|
|
139
166
|
|
|
140
167
|
```bash
|
|
@@ -228,7 +255,6 @@ dsh-log-contract audit-report <session-log>
|
|
|
228
255
|
---
|
|
229
256
|
|
|
230
257
|
## Node API(写前校验嵌入你的脚本)
|
|
231
|
-
|
|
232
258
|
```js
|
|
233
259
|
import { loadSessionLog, validateSessionLog, createPreWriter } from 'dsh-log-contract';
|
|
234
260
|
|
|
@@ -255,7 +281,6 @@ if (!verdict.ok) {
|
|
|
255
281
|
---
|
|
256
282
|
|
|
257
283
|
## 测试
|
|
258
|
-
|
|
259
284
|
```bash
|
|
260
285
|
pnpm check && pnpm test # 语法检查 + 契约文档漂移闸 + 全部单测(含案例回归用例)
|
|
261
286
|
```
|
|
@@ -266,7 +291,6 @@ pnpm check && pnpm test # 语法检查 + 契约文档漂移闸 + 全部单测
|
|
|
266
291
|
> 因此 `pnpm check` / `pnpm test` 在干净的克隆里即可通过。
|
|
267
292
|
|
|
268
293
|
## 本地 Git 钩子(可选,需手动安装)
|
|
269
|
-
|
|
270
294
|
仓库提供 `.githooks/pre-push`(推送前跑 `pnpm check`),但它**不会因为 clone 自动生效**——必须显式指向:
|
|
271
295
|
|
|
272
296
|
```bash
|
|
@@ -294,56 +318,14 @@ git config --get core.hooksPath # 验证:应输出 .githooks
|
|
|
294
318
|
|
|
295
319
|
---
|
|
296
320
|
|
|
297
|
-
##
|
|
298
|
-
|
|
299
|
-
- [x] **Phase 1(0.1.0)**:CLI 离线体检 + 写前校验 + 契约目录
|
|
300
|
-
- [x] **Phase 1.5(0.2.0)**:`fix` 子命令(严格 seq 扫描 + W1/W2 wire 检查 + 移除 marker 重编号 + 官方帧格式重建);CI 集成(`dsh-log-contract check` 作为 Harness 会话目录的定时守护)
|
|
301
|
-
- [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 重放)
|
|
302
|
-
- [x] **0.3.6 → 0.3.15**:按被检文件版本择路的 v0–v3 规则(T3/T4/T5、L3–L5、E8/E9/E10)、宿主能力与迁移预检的退出码 `3`/`4`,以及如实报告"哪些版本**未**验证"的版本支持说明(详见 [CHANGELOG.md](CHANGELOG.md))
|
|
303
|
-
- [ ] Phase 2:运行时守护(订阅 session append 事件流实时校验,断裂即标记 `dsh/contract-violation` 事件,策略可配 告警/拦截)——DSH 插件形态
|
|
304
|
-
- [ ] Phase 3:与 dsh-turn-guard / dsh-retrace 时间线联动
|
|
305
|
-
|
|
306
|
-
## 许可
|
|
307
|
-
|
|
308
|
-
MIT © OfferKuai Team
|
|
309
|
-
|
|
310
|
-
---
|
|
311
|
-
|
|
312
|
-
## 🧱 架构 —— 契约层 + 平台适配器
|
|
313
|
-
|
|
314
|
-
校验被拆成**平台无关的契约层**(`contract/`)与**平台适配器**(`adapters/dsh/`):不变量、判定模型与规则注册表共享;
|
|
315
|
-
事件形状、格式版本(v0–v4)、zstd 帧与 surface 语义放在适配器里。**接入另一个宿主平台的意图是只写一个适配器、契约层不动**——分层已抽取并由机器强制;但适配器对接面(编排入口、与平台无关的违规 id)仍在收尾,在此之前接第二个平台还需一层薄 runner。
|
|
316
|
-
|
|
317
|
-
边界由机器强制:`contract/` 不得出现平台词汇、不得依赖适配器或实现层(`pnpm check:strict`,CI 与可选 pre-push 钩子同跑)。
|
|
318
|
-
公开 API、51 条规则与判定结果均不变。详见 [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md)。
|
|
319
|
-
|
|
320
|
-
## 🆕 0.3.18 – 0.3.21 · 支持 DSH 0.2.x(会话格式 v4)
|
|
321
|
-
|
|
322
|
-
**会话格式 v4**(`@deepseek-ai/dsh-session` 0.2.x)改为**按格式版本分派规则**,而不是放宽格式闸门:
|
|
323
|
-
|
|
324
|
-
- `tool/result` 按 v4 形状校验(`role: 'tool'`、无 `tool-result` 包裹块)
|
|
325
|
-
- `system/message` 接受 v4 的 `source.kind: 'system-prompt'`
|
|
326
|
-
- **v3 及更早的判据零改动**(408 份真实 v3 会话前后判定完全一致)
|
|
327
|
-
- 格式闸门仍**拒绝未知的未来版本**(`readOnly`);v5+ 按设计保持"不可评估"
|
|
328
|
-
|
|
329
|
-
**新增规则(共 51 条):**
|
|
330
|
-
|
|
331
|
-
| 规则 | 判据 |
|
|
332
|
-
|---|---|
|
|
333
|
-
| `G4` | 未知历史事件可**声明式跳过**(`ignorable: true`;白名单可注入) |
|
|
334
|
-
| `S10` | `sourceEventSeqs` 元素:**解码后**必须为非负整数(存储层允许官方区间对) |
|
|
335
|
-
| `I2` | `seedLength` = **继承事件条数**(非字节);`parentSession` 存在且缺失/0 属合法 |
|
|
336
|
-
| `P5` | 两段 carrier 配对:第 2 段首元素 = 第 1 段 seq(读侧兼容早期写法) |
|
|
337
|
-
| `A1` | 「在位可还原」**只认结构化字段**(`archiveRef`/`archive`/`externalized.*`),不从自由文本推断 |
|
|
338
|
-
|
|
339
|
-
**大会话**:读取改为**按行解码**(不再整文件字符串化 ⇒ 约 536MB 以上不再抛 `ERR_STRING_TOO_LONG`);
|
|
340
|
-
修复采用**流式帧重建** `.jsonl.zstd`(header 帧 + 正文分块多帧,逐帧 checksum + roundtrip 校验)。
|
|
341
|
-
|
|
342
|
-
**Windows**:`H2` 的 `header.cwd` 绝对路径判断改为**平台感知**(`win32` 与 `posix` 都认)。
|
|
321
|
+
## ⚠️ 升级说明(0.3.12 → 0.3.24)
|
|
343
322
|
|
|
344
|
-
|
|
323
|
+
### 0.3.18 → 0.3.24 一段话说清
|
|
345
324
|
|
|
346
|
-
|
|
325
|
+
**会话格式 v4**(宿主 `dsh-session` 0.2.x)改为按版本分派判定(`tool/result` 的 role、`system/message` 的来源);
|
|
326
|
+
新增五条规则(`G4` 未知但可忽略事件、`S10` 引用元素类型、`I2` `seedLength` 语义、`P5` 载体配对、`A1` 只认结构化字段的在位可还原);
|
|
327
|
+
大会话(>500MB)按行读取 + 流式帧重建;Windows 的 `header.cwd` 判定改为平台感知。0.3.22 增加
|
|
328
|
+
`contract/` + `adapters/dsh/` 分层(行为不变,且**仍是部分成立** —— 见 CHANGELOG 的已知缺口清单)。判定结果、退出码与 `--json` 字段均不变。
|
|
347
329
|
|
|
348
330
|
> **0.3.17 不含行为变更。** 它只调整了注释、测试标题、少量诊断文案与 README 的措辞。
|
|
349
331
|
> 所有判定结果、退出码与 `--json` 字段与 0.3.15 完全一致,
|
|
@@ -374,3 +356,16 @@ MIT © OfferKuai Team
|
|
|
374
356
|
**3.「体检通过」到哪一步为止。**
|
|
375
357
|
本工具的规则集**不等于**官方升级链的接受条件。`assessmentScope=partial` 只表示"本工具看过的那部分没问题",
|
|
376
358
|
**不构成**"官方升级会接受"。已知未覆盖的 6 类见 `coverage.uncovered`。
|
|
359
|
+
|
|
360
|
+
## Roadmap
|
|
361
|
+
- [x] **Phase 1(0.1.0)**:CLI 离线体检 + 写前校验 + 契约目录
|
|
362
|
+
- [x] **Phase 1.5(0.2.0)**:`fix` 子命令(严格 seq 扫描 + W1/W2 wire 检查 + 移除 marker 重编号 + 官方帧格式重建);CI 集成(`dsh-log-contract check` 作为 Harness 会话目录的定时守护)
|
|
363
|
+
- [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 重放)
|
|
364
|
+
- [x] **0.3.6 → 0.3.15**:按被检文件版本择路的 v0–v3 规则(T3/T4/T5、L3–L5、E8/E9/E10)、宿主能力与迁移预检的退出码 `3`/`4`,以及如实报告"哪些版本**未**验证"的版本支持说明(详见 [CHANGELOG.md](CHANGELOG.md))
|
|
365
|
+
- [ ] Phase 2:运行时守护(订阅 session append 事件流实时校验,断裂即标记 `dsh/contract-violation` 事件,策略可配 告警/拦截)——DSH 插件形态
|
|
366
|
+
- [ ] Phase 3:与 dsh-turn-guard / dsh-retrace 时间线联动
|
|
367
|
+
|
|
368
|
+
## 许可
|
|
369
|
+
MIT © OfferKuai Team
|
|
370
|
+
|
|
371
|
+
---
|
package/bin/dsh-log-contract.mjs
CHANGED
|
@@ -42,7 +42,7 @@ const USAGE = `dsh-log-contract —— 日志契约守护(DSH session log cont
|
|
|
42
42
|
用法:
|
|
43
43
|
dsh-log-contract check <session-log> [--json] [--max-details N] [--resume] [--fail-on-migration] [--no-fail-on-migration] [--archive-root DIR] [--ignorable-whitelist a,b]
|
|
44
44
|
离线体检 + **迁移预检** + **在位可还原(A1,独立维度)**。session-log 支持 .jsonl 与 .jsonl.zstd。
|
|
45
|
-
⚠️
|
|
45
|
+
⚠️ 口径边界:本工具只判定它实现的规则集。「ok」/「可加载」/「可继续」/「可压缩」
|
|
46
46
|
**不代表**会话"可用",**不代表**可安全编辑,也**不代表**官方升级路径会接受
|
|
47
47
|
(迁移是独立维度,覆盖边界见 contracts 输出与 lib/contracts.js 的 G 段)。
|
|
48
48
|
--json 输出机器可读 JSON 报告(含 host / assessable / assessmentScope / migration 字段)
|
|
@@ -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
|
-
诊断 +
|
|
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
|
|
83
|
+
—— token-meter 不再刷屏,会话驻留也安全(2026-08-30 事故)
|
|
84
84
|
--neutralize-legacy-markers
|
|
85
85
|
**一次性根治历史载体债**:只中和
|
|
86
86
|
assistant/message + data.editor 形态的历史 retrace marker
|
|
@@ -447,7 +447,7 @@ function cmdPrewrite(args) {
|
|
|
447
447
|
}
|
|
448
448
|
|
|
449
449
|
function cmdContracts() {
|
|
450
|
-
out('dsh-log-contract 契约规则目录(spec
|
|
450
|
+
out('dsh-log-contract 契约规则目录(spec:官方源码逐行核对 + 实测事故固化)\n\n');
|
|
451
451
|
for (const r of CONTRACT_RULES) {
|
|
452
452
|
const flags = [
|
|
453
453
|
r.candidate ? '候选规则' : null,
|