dsh-log-contract 0.3.46 → 0.3.48
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/CHANGELOG.md +13 -0
- package/README.md +12 -6
- package/README.zh.md +7 -5
- package/VERSIONS.md +4 -2
- package/docs/CONTRACTS.md +16 -2
- package/lib/checks.js +21 -0
- package/lib/contracts.js +16 -0
- package/lib/prewrite.js +10 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
## [0.3.48] — 2026-12-04
|
|
2
|
+
|
|
3
|
+
- 修复写前校验回归:拟写事件**缺 `time`** 被误判为 E12。官方写入路径自行构建信封(`time: Date.now()`),拟写对象并不携带 `time`——写前校验现按同一语义补齐数字 `time`;E12 继续只拦**存储形态**(文件里缺 `time`/ISO 串仍判红)
|
|
4
|
+
- 反例口径:marker 载体缺 `time` ⇒ 写前绿(撤回/编辑路径恢复);同一形态落盘(文件缺 `time`)⇒ offline check 仍红;显式 ISO 串 `time` ⇒ 仍红
|
|
5
|
+
- 规则与文件级判定不变
|
|
6
|
+
|
|
7
|
+
## [0.3.47] — 2026-12-04
|
|
8
|
+
|
|
9
|
+
- 修复"体检绿但会话打不开"的盲区:新增 **E12** 宿主加载边界信封(`time` 必须为安全整数——ISO 字符串/缺失/`-0` 判红;`data` 必须存在;`ignorable` 只能 `true`;`seq` 不得为 `-0`)与 **E13** `assistant/attempt` 结算字段(`turn`/`step` 非负安全整数、`stream` 数组)
|
|
10
|
+
- 规则镜像官方加载器 seed/restore 边界的实际校验(对照 `dsh-session` 的信封与结算字段校验),而非只查 JSON 语法;日志契约 57 → 59 条
|
|
11
|
+
- 正/反例:数字 `time` ⇒ check 绿且官方 `Session.create` 可加载;ISO 字符串 `time` ⇒ check 红(E12)且官方加载抛 `invalid event envelope`
|
|
12
|
+
- 规则与判定其余部分不变
|
|
13
|
+
|
|
1
14
|
## [0.3.46] — 2026-12-02
|
|
2
15
|
|
|
3
16
|
- 版本记录状态更正:`VERSIONS.md` 按 npm registry 事实逐版核对 `npm 状态`(0.3.44 等已发版本更正为「已发」;未发版本保持「未发」),并补 0.3.45 / 0.3.46 行
|
package/README.md
CHANGED
|
@@ -156,9 +156,9 @@ missing; `unknown` means the tail could not be read.
|
|
|
156
156
|
|
|
157
157
|
## Three-layer contract (the model)
|
|
158
158
|
|
|
159
|
-
> **
|
|
159
|
+
> **75 rules in four report families**: **59 log-contract rules** across the layers below
|
|
160
160
|
> (each with an official source reference), plus **6 error-expression** (E1–E6),
|
|
161
|
-
> **3 version-identity** (ID1/ID2/ID6) and **7 run-contract** rules. `contracts` lists the
|
|
161
|
+
> **3 version-identity** (ID1/ID2/ID6) and **7 run-contract** rules. `contracts` lists the 59
|
|
162
162
|
> log-contract rules; the other families live in their own documents.
|
|
163
163
|
|
|
164
164
|
| Layer | Rules | What it guards |
|
|
@@ -182,12 +182,12 @@ dispatched by `family` and must not be merged by bare id.
|
|
|
182
182
|
|
|
183
183
|
| family | rules | guards | full list |
|
|
184
184
|
|---|---|---|---|
|
|
185
|
-
| **log contract** | **
|
|
185
|
+
| **log contract** | **59** | persisted session logs: frames (Z), header (H), storage rows (R), envelope/`seq` (E), surface (S), client engine (T/M/I), wire order (W), markers (P), concurrency (C), migration (G), archive (A) | [docs/CONTRACTS.md](docs/CONTRACTS.md) |
|
|
186
186
|
| **error-expression** | **6** (E1–E6) | error handling as a contract: one code with many causes, constant messages, terminal-word misuse, swallowed `cause`, unconditional success, claimed-but-unenforced invariants | [docs/ERROR-CONTRACT.md](docs/ERROR-CONTRACT.md) |
|
|
187
187
|
| **version-identity** | **3** (ID1–ID2, ID6) | *is the artifact you run the one the version promises?* ID1 one version ↔ one digest; ID2 the runtime digest is computed from the artifact and bound to `package.json.version`; ID6 the **package content** digest (npm pack list) is bound too — same version with changed docs/pack content is red | [docs/interface-versioning.md](docs/interface-versioning.md) |
|
|
188
188
|
| **run-contract** | **7** | *will it silently change while running?* R-1 failure latched; R-2a failed write never marked complete; R-2b withdrawal needs a consumer-readable reason; R-2b-2 initializing ≠ "none"; R-3 missing input ⇒ incompatible; R-5 closed sets exhaustive / open sets tolerant; R-6 side effects idempotent per stable key | [docs/RUN-CONTRACT.md](docs/RUN-CONTRACT.md) |
|
|
189
189
|
|
|
190
|
-
Total: **
|
|
190
|
+
Total: **75** assertions (59 + 6 + 3 + 7). The run-contract ids are **not** a contiguous
|
|
191
191
|
1…7 sequence — the code ids are `R-1 / R-2a / R-2b / R-2b-2 / R-3 / R-5 / R-6` (that is all
|
|
192
192
|
seven). S9 (log family) additionally reports a diagnosis category
|
|
193
193
|
(`old-cursor-replay` / `concurrent-writer` / `format-mix`) with a confidence and the decision
|
|
@@ -195,7 +195,7 @@ basis; the S9 verdict itself is unchanged.
|
|
|
195
195
|
|
|
196
196
|
## Identity contract (ID1 / ID2) — "is what runs what you think it is?"
|
|
197
197
|
|
|
198
|
-
A **separate report family** (`version-identity`): not counted in the
|
|
198
|
+
A **separate report family** (`version-identity`): not counted in the 59 log-contract rules,
|
|
199
199
|
and **not part of `ok` / exit codes** — it answers whether the artifact you run is the one
|
|
200
200
|
the declared version promises.
|
|
201
201
|
|
|
@@ -342,7 +342,7 @@ pnpm exec dsh-log-contract prewrite marker-write.json --log ~/.dsh/sessions/<id>
|
|
|
342
342
|
### 4. Contract catalog
|
|
343
343
|
|
|
344
344
|
```bash
|
|
345
|
-
pnpm exec dsh-log-contract contracts #
|
|
345
|
+
pnpm exec dsh-log-contract contracts # 59 log-contract rules with sources
|
|
346
346
|
pnpm exec dsh-log-contract explain S9 --json # one rule: title, criteria, control pointers
|
|
347
347
|
```
|
|
348
348
|
|
|
@@ -470,6 +470,12 @@ or runtime-code change (source checkout only). In an npm install the registry is
|
|
|
470
470
|
confidence and a decision basis (`category` / `confidence` / `hint` / `basis`); the verdict
|
|
471
471
|
does not change.
|
|
472
472
|
|
|
473
|
+
**`check` is green but the session still won't open?** That class is covered explicitly: `E12`
|
|
474
|
+
checks the **host load boundary** (`time` must be a number/safe integer — an ISO string is red;
|
|
475
|
+
`data` must exist; `ignorable` may only be `true`; `seq` may not be `-0`) and `E13` checks
|
|
476
|
+
`assistant/attempt` settlement fields (`turn`/`step` + `stream` array). The rules mirror the
|
|
477
|
+
official loader's seed/restore validation, not just the JSON syntax.
|
|
478
|
+
|
|
473
479
|
**How are the rules verified?** Every rule ships positive/negative controls; the suite also
|
|
474
480
|
runs a rules self-test (registry completeness, id binding, per-rule coverage, and "every
|
|
475
481
|
emitted id is registered"). See [Tests](#tests).
|
package/README.zh.md
CHANGED
|
@@ -138,8 +138,8 @@ pnpm dlx dsh-log-contract contracts
|
|
|
138
138
|
|
|
139
139
|
## 三层契约(模型)
|
|
140
140
|
|
|
141
|
-
> **四个报告家族、共
|
|
142
|
-
> (E1–E6)+ **
|
|
141
|
+
> **四个报告家族、共 75 条**:下表 **59 条日志契约**(每条带官方出处)+ **6 条错误表达**
|
|
142
|
+
> (E1–E6)+ **3 条版本同一性**(ID1/ID2/ID6)+ **7 条运行时契约**。`contracts` 只列 59 条
|
|
143
143
|
> 日志契约;其余家族各有独立文档。
|
|
144
144
|
|
|
145
145
|
| 层 | 规则 | 守护什么 |
|
|
@@ -161,7 +161,7 @@ pnpm dlx dsh-log-contract contracts
|
|
|
161
161
|
|
|
162
162
|
| 家族(`family`) | 条数 | 守护什么 | 全量清单 |
|
|
163
163
|
|---|---|---|---|
|
|
164
|
-
| **日志契约 log contract** | **
|
|
164
|
+
| **日志契约 log contract** | **59** | 持久化日志:帧形状(Z)、header(H)、存储行(R)、事件信封/seq(E)、surface 不变量(S)、客户端引擎(T/M/I)、wire 顺序(W)、插件 marker(P)、并发(C)、迁移预检(G)、归档可还原(A) | [docs/CONTRACTS.md](docs/CONTRACTS.md) |
|
|
165
165
|
| **错误表达 error-expression** | **6**(E1–E6) | 把错误处理当契约:一码多成因、message 常量、终态词误用、cause 被吞、无条件成功、声称但无执行点 | [docs/ERROR-CONTRACT.md](docs/ERROR-CONTRACT.md) |
|
|
166
166
|
| **版本同一性 version-identity** | **3**(ID1–ID2、ID6) | *跑的是不是声明版本承诺的那一份?* ID1 一物一号(同版本只能对应一个摘要);ID2 号可验(运行摘要由产物计算并与版本绑定);ID6 **包内容摘要**(npm 打包清单)也与版本绑定——同号改文档/包内容 ⇒ 红 | [docs/interface-versioning.md](docs/interface-versioning.md) |
|
|
167
167
|
| **运行时契约 run-contract** | **7** | *跑起来会不会静默变样?* R-1 失败置位不清零;R-2a 写失败不得标完整;R-2b 撤回必须带消费方可读原因;R-2b-2 初始化中 ≠ "没有";R-3 输入缺失 ⇒ 不兼容;R-5 闭集穷尽 / 开集不穷尽;R-6 同键副作用幂等 | [docs/RUN-CONTRACT.md](docs/RUN-CONTRACT.md) |
|
|
@@ -173,7 +173,7 @@ S9 的判定本身不变。
|
|
|
173
173
|
|
|
174
174
|
## 身份契约(ID1 / ID2)——"跑的是不是你以为的那一份?"
|
|
175
175
|
|
|
176
|
-
**独立报告家族**(`version-identity`):不计入
|
|
176
|
+
**独立报告家族**(`version-identity`):不计入 59 条日志契约,也**不进 `ok` / 退出码**——
|
|
177
177
|
它回答"运行产物是不是声明版本承诺的那一份"。
|
|
178
178
|
|
|
179
179
|
| 规则 | 守护什么 |
|
|
@@ -306,7 +306,7 @@ pnpm exec dsh-log-contract prewrite marker-write.json --log ~/.dsh/sessions/<id>
|
|
|
306
306
|
### 4. 契约目录
|
|
307
307
|
|
|
308
308
|
```bash
|
|
309
|
-
pnpm exec dsh-log-contract contracts #
|
|
309
|
+
pnpm exec dsh-log-contract contracts # 59 条日志契约(含出处)
|
|
310
310
|
pnpm exec dsh-log-contract explain S9 --json # 单条规则:标题、判据、对照指针
|
|
311
311
|
```
|
|
312
312
|
|
|
@@ -424,6 +424,8 @@ if (!verdict.ok) {
|
|
|
424
424
|
`concurrent-writer`(并发写者)/ `format-mix`(格式代混写),并在 `--json` 里给出置信度与
|
|
425
425
|
判定式(`category` / `confidence` / `hint` / `basis`);判定本身不变。
|
|
426
426
|
|
|
427
|
+
**`check` 绿但会话仍打不开?** 这一类已显式覆盖:`E12` 查**宿主加载边界**(`time` 必须是数字/安全整数——ISO 串判红;`data` 必须存在;`ignorable` 只能是 `true`;`seq` 不得为 `-0`),`E13` 查 `assistant/attempt` 结算字段(`turn`/`step` + `stream` 数组)。规则镜像官方加载器的 seed/restore 校验,而不只是 JSON 语法。
|
|
428
|
+
|
|
427
429
|
**规则怎么验证?** 每条规则都有正/负对照用例;另有一套规则自检(注册表完整性、id 绑定、
|
|
428
430
|
逐规则覆盖、"报出的违规码都已注册")。见下方[测试](#测试)。
|
|
429
431
|
|
package/VERSIONS.md
CHANGED
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
> `npm view dsh-log-contract versions` + `dist-tags.latest` 核对),之后发布**不回写**本表——
|
|
10
10
|
> 以 registry 为准。`已发` = registry 可见;`未发` = 仓库有 tag/记录但 registry 未见。
|
|
11
11
|
> 0.3.6–0.3.20 逐版列出;0.3.21–0.3.26 为同一窗口的连续修复,合并为一行(不缺失)。
|
|
12
|
-
> 当前 `package.json` 版本为 0.3.
|
|
12
|
+
> 当前 `package.json` 版本为 0.3.48。
|
|
13
13
|
|
|
14
14
|
| 包版本 | 日期 | npm 状态 | `schemaVersion` | 一句话变化 |
|
|
15
15
|
|---|---|---|---|---|
|
|
16
|
+
| 0.3.48 | 2026-12-04 | 待发(本次) | `"7"` | 修复写前校验对"拟写事件缺 time"的误判(按宿主 append 语义补齐 time;文件级 E12 不变) |
|
|
17
|
+
| 0.3.47 | 2026-12-04 | 待发(本次) | `"7"` | 修复加载边界盲区:+`E12` 宿主信封(time 可解析/必填/ignorable)、+`E13` assistant/attempt 结算字段;日志契约 57→59 |
|
|
16
18
|
| 0.3.46 | 2026-12-02 | 待发(本次) | `"7"` | 版本记录状态更正(VERSIONS 按 registry 事实更新;无规则变化) |
|
|
17
19
|
| 0.3.45 | 2026-12-01 | 已发 | `"7"` | IDENTITY +ID-6 包内容摘要(runtimeDigest + packageDigest 双登记;同号改包内容 ⇒ 红) |
|
|
18
20
|
| 0.3.44 | 2026-11-25 | 已发 | `"6"` | 文档与可读性修订(README 重写 / 家族总览 / VERSIONS 入包);规则无变化 |
|
|
@@ -50,7 +52,7 @@
|
|
|
50
52
|
| 0.3.7 | 2026-08-31 | 已发 | `"1"` | `check --resume` 三档 + `fix` 原语 + `--trim-budget` + 健康巡检 |
|
|
51
53
|
| 0.3.6 | 2026-08-30 | 已发 | `"1"` | T2:assistant/message 的非 chunk 源引用按官方 `:644` 报 error |
|
|
52
54
|
|
|
53
|
-
覆盖 **0.3.6 → 0.3.
|
|
55
|
+
覆盖 **0.3.6 → 0.3.48 共 43 个版本号**(38 行;0.3.21–0.3.26 合并一行)。
|
|
54
56
|
|
|
55
57
|
## 兼容承诺
|
|
56
58
|
|
package/docs/CONTRACTS.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
> (`@deepseek-ai/dsh-session`,各条出处见下)。后续规则随官方版本演进追加:
|
|
14
14
|
> T3/T4 = 渲染层白屏事故复盘,T5 = malformed turn/end 事故复盘。
|
|
15
15
|
>
|
|
16
|
-
> **家族索引**:本文件只含**日志契约**(当前
|
|
16
|
+
> **家族索引**:本文件只含**日志契约**(当前 59 条)。另有独立家族(按 `family` 分派、互不影响):
|
|
17
17
|
> 错误表达 **error-expression**(E1–E6,见 `docs/ERROR-CONTRACT.md`)、
|
|
18
18
|
> 版本同一性 **version-identity**(ID1/ID2/ID6,见 `docs/interface-versioning.md`)、
|
|
19
19
|
> 运行时契约 **run-contract**(R-3 / R-1 / R-2a / R-2b / R-2b-2 / R-5 / R-6,见 `docs/RUN-CONTRACT.md`)。
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
>
|
|
28
28
|
> 严重度:**error** = 违反即会话不可加载/写入被拒(fail-loud);**warning** = 合法但可疑。
|
|
29
29
|
|
|
30
|
-
## 规则索引(共
|
|
30
|
+
## 规则索引(共 59 条)
|
|
31
31
|
|
|
32
32
|
| id | 严重度 | 层级 | 规则 |
|
|
33
33
|
|---|---|---|---|
|
|
@@ -66,6 +66,8 @@
|
|
|
66
66
|
| E9 | error | persistence | system/message 的 source 契约(v3 plugin / v4 system-prompt) |
|
|
67
67
|
| E10 | error | persistence | request/header 的 data.header 字段约束 |
|
|
68
68
|
| E11 | error | persistence | seq 由日志层分配:写侧不得自造(省略 seq,或必须等于 nextSeq) |
|
|
69
|
+
| E12 | error | persistence | 宿主加载边界信封:time 必须可解析、data 必须存在、ignorable 只能是 true |
|
|
70
|
+
| E13 | error | persistence | assistant/attempt 结算字段:turn/step 非负安全整数 + stream 数组 |
|
|
69
71
|
| Z3 | warning | framing | 空会话文件(有 header 无事件)显式报出 |
|
|
70
72
|
| P3 | warning | plugin | tool/call ↔ tool/result 配对完整性(考古 B1) |
|
|
71
73
|
| P4 | warning | plugin | tool/result 输出结构可解析(考古 B2) |
|
|
@@ -301,6 +303,18 @@
|
|
|
301
303
|
- **出处**: 官方 append 信封按日志层连续光标分配 seq(dsh-session lib/index.js:1453-1459 append 信封、:398 planSurfaceEvent "not contiguous");实测两类破坏:① 生产者自行生成 seq 写入 ⇒ E2/S8 类红;② 删除两行不重编号 ⇒ 缺口
|
|
302
304
|
- **契约**: seq 的唯一合法来源是**日志层的连续光标**(写入时分配)。写侧(prewrite)拟写事件**不携带 seq**(由校验器赋 nextSeq),携带时必须等于 nextSeq,否则 E11 拒绝——⛔ 生产者不得自造/自增 seq。文件侧的"写侧自造"痕迹由 E2(缺口/倒退)与 S9(文件物理序回退)判红:删行不重编号 = 缺口 ⇒ E2;自造/回放旧光标 = 与光标不连续或物理序回退 ⇒ E2/S9。离线单看一行无法知道 seq 是谁写的,故文件侧判据是"连续性/物理序"这条可判下界。
|
|
303
305
|
|
|
306
|
+
### E12 — 宿主加载边界信封:time 必须可解析、data 必须存在、ignorable 只能是 true
|
|
307
|
+
|
|
308
|
+
- **层级**: persistence | **严重度**: error
|
|
309
|
+
- **出处**: 官方加载/种子边界 assertSessionEventEnvelope(dsh-session@0.2.0-rc.2 lib/index.js:1110-1130):要求 type 为 string、seq 为非负安全整数且非 -0、time 为 number 且安全整数且非 -0、data !== undefined、ignorable 只能 undefined|true,多键白名单见 E8
|
|
310
|
+
- **契约**: 宿主在把事件装进会话(seed/restore/读取)时会校验**信封形状**,契约只查语法会漏掉一类"体检绿但会话打不开"的样本。判据:① `time` 必须是 number 且安全整数、不得为 `-0`(⚠️ ISO 字符串、缺失、`null`、`"2026-…"` 一律判红——这是真实盲区);② `data` 必须存在(`undefined` 判红);③ `ignorable` 若出现只能是 `true`;④ `seq` 不得为 `-0`(E1 的补强)。以上任一违反 ⇒ 宿主加载器抛 invalid event envelope。
|
|
311
|
+
|
|
312
|
+
### E13 — assistant/attempt 结算字段:turn/step 非负安全整数 + stream 数组
|
|
313
|
+
|
|
314
|
+
- **层级**: persistence | **严重度**: error
|
|
315
|
+
- **出处**: 官方 assertAssistantSettlementShape(dsh-session@0.2.0-rc.2 lib/index.js:1156-1160,经 assertCurrentLlmShape 在加载/种子边界调用):data.turn/data.step 必须为非负安全整数且非 -0,data.stream 必须为数组
|
|
316
|
+
- **契约**: `assistant/attempt` 的 `data.turn` / `data.step` 必须是非负安全整数(`-0` 也算非法),`data.stream` 必须是数组;缺失或类型不符 ⇒ 宿主加载器直接拒绝("invalid settlement fields")。这是"只查 type 存在"会漏的第二类加载边界形状。
|
|
317
|
+
|
|
304
318
|
### Z3 — 空会话文件(有 header 无事件)显式报出
|
|
305
319
|
|
|
306
320
|
- **层级**: framing | **严重度**: warning
|
package/lib/checks.js
CHANGED
|
@@ -147,6 +147,27 @@ export function envelopeViolations(event, loc, version) {
|
|
|
147
147
|
} else if (!currentVocabulary(version).has(event.type) && event.ignorable !== true) {
|
|
148
148
|
out.push(violation('E3', loc, `type "${event.type}" 不在已知词汇表内且未带 ignorable 标记(可能由更新版本的 harness 写入)`));
|
|
149
149
|
}
|
|
150
|
+
// E12 · 宿主加载边界信封(2026-12-04 实测盲区:time 为 ISO 串时 check 绿、宿主 seed 拒绝)
|
|
151
|
+
if (typeof event.time !== 'number' || !Number.isSafeInteger(event.time) || Object.is(event.time, -0)) {
|
|
152
|
+
out.push(violation('E12', loc, `time 必须是宿主可解析的安全整数(number),实际 ${typeof event.time === 'string' ? `字符串 "${String(event.time).slice(0, 40)}"` : String(event.time)}——ISO 串/缺失/-0 都会让宿主加载器抛 invalid event envelope`));
|
|
153
|
+
}
|
|
154
|
+
if (event.data === undefined) {
|
|
155
|
+
out.push(violation('E12', loc, '事件缺少 data(宿主加载边界要求 data !== undefined)'));
|
|
156
|
+
}
|
|
157
|
+
if (event.ignorable !== undefined && event.ignorable !== true) {
|
|
158
|
+
out.push(violation('E12', loc, `ignorable 若出现只能是 true,实际 ${String(event.ignorable)}——宿主加载边界拒`));
|
|
159
|
+
}
|
|
160
|
+
if (Object.is(event.seq, -0)) {
|
|
161
|
+
out.push(violation('E12', loc, 'seq 不得为 -0(宿主加载边界按 Object.is 拒绝;E1 的补强)'));
|
|
162
|
+
}
|
|
163
|
+
if (event.type === 'assistant/attempt') {
|
|
164
|
+
const turn = event.data?.turn;
|
|
165
|
+
const step = event.data?.step;
|
|
166
|
+
const safe = (v) => typeof v === 'number' && Number.isSafeInteger(v) && v >= 0 && !Object.is(v, -0);
|
|
167
|
+
if (!safe(turn) || !safe(step) || !Array.isArray(event.data?.stream)) {
|
|
168
|
+
out.push(violation('E13', loc, `assistant/attempt 结算字段非法:turn=${String(turn)} step=${String(step)} stream=${Array.isArray(event.data?.stream) ? 'array' : String(event.data?.stream)}——turn/step 须为非负安全整数、stream 须为数组(宿主 invalid settlement fields)`));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
150
171
|
if (!isJsonValue(event.data)) {
|
|
151
172
|
out.push(violation('E4', loc, 'data 不是 lossless-JSON(函数/循环引用/非有限数等),写入热路径会拒绝'));
|
|
152
173
|
}
|
package/lib/contracts.js
CHANGED
|
@@ -364,6 +364,22 @@ export const CONTRACT_RULES = [
|
|
|
364
364
|
source: '官方 append 信封按日志层连续光标分配 seq(dsh-session lib/index.js:1453-1459 append 信封、:398 planSurfaceEvent "not contiguous");实测两类破坏:① 生产者自行生成 seq 写入 ⇒ E2/S8 类红;② 删除两行不重编号 ⇒ 缺口',
|
|
365
365
|
description: 'seq 的唯一合法来源是**日志层的连续光标**(写入时分配)。写侧(prewrite)拟写事件**不携带 seq**(由校验器赋 nextSeq),携带时必须等于 nextSeq,否则 E11 拒绝——⛔ 生产者不得自造/自增 seq。文件侧的"写侧自造"痕迹由 E2(缺口/倒退)与 S9(文件物理序回退)判红:删行不重编号 = 缺口 ⇒ E2;自造/回放旧光标 = 与光标不连续或物理序回退 ⇒ E2/S9。离线单看一行无法知道 seq 是谁写的,故文件侧判据是"连续性/物理序"这条可判下界。',
|
|
366
366
|
},
|
|
367
|
+
{
|
|
368
|
+
id: 'E12',
|
|
369
|
+
title: '宿主加载边界信封:time 必须可解析、data 必须存在、ignorable 只能是 true',
|
|
370
|
+
layer: LAYER.PERSISTENCE,
|
|
371
|
+
severity: SEVERITY.ERROR,
|
|
372
|
+
source: '官方加载/种子边界 assertSessionEventEnvelope(dsh-session@0.2.0-rc.2 lib/index.js:1110-1130):要求 type 为 string、seq 为非负安全整数且非 -0、time 为 number 且安全整数且非 -0、data !== undefined、ignorable 只能 undefined|true,多键白名单见 E8',
|
|
373
|
+
description: '宿主在把事件装进会话(seed/restore/读取)时会校验**信封形状**,契约只查语法会漏掉一类"体检绿但会话打不开"的样本。判据:① `time` 必须是 number 且安全整数、不得为 `-0`(⚠️ ISO 字符串、缺失、`null`、`"2026-…"` 一律判红——这是真实盲区);② `data` 必须存在(`undefined` 判红);③ `ignorable` 若出现只能是 `true`;④ `seq` 不得为 `-0`(E1 的补强)。以上任一违反 ⇒ 宿主加载器抛 invalid event envelope。',
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
id: 'E13',
|
|
377
|
+
title: 'assistant/attempt 结算字段:turn/step 非负安全整数 + stream 数组',
|
|
378
|
+
layer: LAYER.PERSISTENCE,
|
|
379
|
+
severity: SEVERITY.ERROR,
|
|
380
|
+
source: '官方 assertAssistantSettlementShape(dsh-session@0.2.0-rc.2 lib/index.js:1156-1160,经 assertCurrentLlmShape 在加载/种子边界调用):data.turn/data.step 必须为非负安全整数且非 -0,data.stream 必须为数组',
|
|
381
|
+
description: '`assistant/attempt` 的 `data.turn` / `data.step` 必须是非负安全整数(`-0` 也算非法),`data.stream` 必须是数组;缺失或类型不符 ⇒ 宿主加载器直接拒绝("invalid settlement fields")。这是"只查 type 存在"会漏的第二类加载边界形状。',
|
|
382
|
+
},
|
|
367
383
|
{
|
|
368
384
|
id: 'Z3',
|
|
369
385
|
title: '空会话文件(有 header 无事件)显式报出',
|
package/lib/prewrite.js
CHANGED
|
@@ -55,9 +55,17 @@ export function legacyMarkerKindOf(event) {
|
|
|
55
55
|
return { prefix, id, targetSeq: editor.targetSeq, seq: event.seq };
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* 把一个"拟写事件"规整为带 seq/time 的事件。
|
|
60
|
+
*
|
|
61
|
+
* - `seq` 未携带时按追加位置赋值(E11:seq 由日志层分配);
|
|
62
|
+
* - `time` 未携带时**补 `Date.now()`**:官方 append 自己构建信封
|
|
63
|
+
* (`dsh-session` lib/index.js:1456 `time: Date.now()`)——拟写对象里的 time 并不被宿主消费,
|
|
64
|
+
* 因此"缺 time"不是写出错误(E12 只应拦"宿主加载器会拒的存储形态")。
|
|
65
|
+
*/
|
|
59
66
|
function normalizeCandidate(candidate, nextSeq) {
|
|
60
|
-
|
|
67
|
+
const withSeq = candidate.seq === undefined ? { ...candidate, seq: nextSeq } : candidate;
|
|
68
|
+
return withSeq.time === undefined ? { ...withSeq, time: Date.now() } : withSeq;
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
/**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-log-contract",
|
|
3
3
|
"description": "日志契约守护 — DSH session log contract guard: offline health check (CLI) + pre-write validation for DeepSeek Harness session logs",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.48",
|
|
5
5
|
"packageManager": "pnpm@11.7.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "lib/index.js",
|