dsh-log-contract 0.3.48 → 0.3.49
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 +6 -0
- package/README.md +2 -0
- package/README.zh.md +1 -0
- package/VERSIONS.md +3 -2
- package/bin/dsh-log-contract.mjs +9 -1
- package/lib/index.js +1 -1
- package/lib/prewrite.js +44 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
## [0.3.49] — 2026-12-04
|
|
2
|
+
|
|
3
|
+
- 修复"既有行违规阻断所有写入":写前校验把历史遗留行的加载形状问题(E12/E13,如老事件缺 `time`)归因为 `origin: existing` 并降级为 warning,**不再阻断**用户撤回/编辑;本次候选引入的违规仍是 error 硬拒
|
|
4
|
+
- CLI 基线门同步:仅"非既有行形状"的 error 阻断写入;存在历史行形状问题时打印迁移提示并继续(`LEGACY_ROW_SHAPE_IDS` / `blockingBaselineViolations` 已导出,供写前守卫复用)
|
|
5
|
+
- 用例:既有行缺 `time` + 合法候选 ⇒ 允许写(API 与 CLI 双路径);候选 ISO `time` ⇒ 仍红;候选缺 `time` ⇒ 按宿主语义补齐
|
|
6
|
+
|
|
1
7
|
## [0.3.48] — 2026-12-04
|
|
2
8
|
|
|
3
9
|
- 修复写前校验回归:拟写事件**缺 `time`** 被误判为 E12。官方写入路径自行构建信封(`time: Date.now()`),拟写对象并不携带 `time`——写前校验现按同一语义补齐数字 `time`;E12 继续只拦**存储形态**(文件里缺 `time`/ISO 串仍判红)
|
package/README.md
CHANGED
|
@@ -333,6 +333,8 @@ pnpm exec dsh-log-contract prewrite marker-write.json --log ~/.dsh/sessions/<id>
|
|
|
333
333
|
|
|
334
334
|
- A baseline with error-level violations is rejected outright (the pre-surgery baseline must
|
|
335
335
|
be green).
|
|
336
|
+
- **Existing rows vs the candidate**: load-shape problems on **existing** rows (E12/E13, e.g. legacy events without `time`) are reported as warnings and **do not block** the write; anything the **candidate** introduces is still rejected.
|
|
337
|
+
- **Existing rows vs the candidate**: load-shape problems on **existing** rows (E12/E13, e.g. legacy events without `time`) are reported as warnings and **do not block** the write; anything the **candidate** introduces is still rejected.
|
|
336
338
|
- `seq` must be **omitted** (auto-assigned as `nextSeq`) or exactly `nextSeq` — a
|
|
337
339
|
self-invented `seq` is rejected (`E11`); on the file side, delete-without-renumber and
|
|
338
340
|
invented `seq` show up as gaps and are caught by `E2` / `S9`.
|
package/README.zh.md
CHANGED
|
@@ -299,6 +299,7 @@ pnpm exec dsh-log-contract prewrite marker-write.json --log ~/.dsh/sessions/<id>
|
|
|
299
299
|
```
|
|
300
300
|
|
|
301
301
|
- 基线已有 error 级违规 ⇒ 直接拒绝(手术前基线必须绿)。
|
|
302
|
+
- **既有行 vs 候选**:既有行的加载形状问题(E12/E13,如老事件缺 `time`)按 warning 报出、**不阻断**本次写入;候选自身引入的违规仍硬拒。
|
|
302
303
|
- `seq` 必须**省略**(自动赋 `nextSeq`)或恰等于 `nextSeq`——自造 `seq` 被拒(`E11`);
|
|
303
304
|
文件侧的"删行不重编号"和"自造 seq"表现为缺口,由 `E2` / `S9` 抓。
|
|
304
305
|
- 只有通过才允许落盘——**先校验、后提交**(与官方 `SurfaceManager.validateNext` 同一思路)。
|
package/VERSIONS.md
CHANGED
|
@@ -9,10 +9,11 @@
|
|
|
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.49。
|
|
13
13
|
|
|
14
14
|
| 包版本 | 日期 | npm 状态 | `schemaVersion` | 一句话变化 |
|
|
15
15
|
|---|---|---|---|---|
|
|
16
|
+
| 0.3.49 | 2026-12-04 | 待发(本次) | `"7"` | 修复既有行 E12/E13 阻断写入:既有行降级为 warning(origin=existing),仅候选新违规硬拒;CLI 基线门同步 |
|
|
16
17
|
| 0.3.48 | 2026-12-04 | 待发(本次) | `"7"` | 修复写前校验对"拟写事件缺 time"的误判(按宿主 append 语义补齐 time;文件级 E12 不变) |
|
|
17
18
|
| 0.3.47 | 2026-12-04 | 待发(本次) | `"7"` | 修复加载边界盲区:+`E12` 宿主信封(time 可解析/必填/ignorable)、+`E13` assistant/attempt 结算字段;日志契约 57→59 |
|
|
18
19
|
| 0.3.46 | 2026-12-02 | 待发(本次) | `"7"` | 版本记录状态更正(VERSIONS 按 registry 事实更新;无规则变化) |
|
|
@@ -52,7 +53,7 @@
|
|
|
52
53
|
| 0.3.7 | 2026-08-31 | 已发 | `"1"` | `check --resume` 三档 + `fix` 原语 + `--trim-budget` + 健康巡检 |
|
|
53
54
|
| 0.3.6 | 2026-08-30 | 已发 | `"1"` | T2:assistant/message 的非 chunk 源引用按官方 `:644` 报 error |
|
|
54
55
|
|
|
55
|
-
覆盖 **0.3.6 → 0.3.
|
|
56
|
+
覆盖 **0.3.6 → 0.3.49 共 44 个版本号**(39 行;0.3.21–0.3.26 合并一行)。
|
|
56
57
|
|
|
57
58
|
## 兼容承诺
|
|
58
59
|
|
package/bin/dsh-log-contract.mjs
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import fs from 'node:fs';
|
|
16
16
|
import { delimiter as pathDelimiter, join as pathJoin } from 'node:path';
|
|
17
|
+
import { LEGACY_ROW_SHAPE_IDS, blockingBaselineViolations } from '../lib/prewrite.js';
|
|
17
18
|
import { loadSessionLog, validateSessionLog, resumeVerdict, migrationVerdict, assessmentScope, createPreWriter, repairSession, readSessionHeader, CONTRACT_RULES, ruleById, explainRule, extractToolOutputs, auditToolCalls, hostCapability, HOST_MAX_FILE_VERSION, detectSupport, ERROR_CONTRACT_RULES, checkErrorContract, normalizePath, checkIdentity, IDENTITY_RULES, packageRoot, RUN_CONTRACT_RULES } from '../lib/index.js';
|
|
18
19
|
|
|
19
20
|
/**
|
|
@@ -444,10 +445,17 @@ function cmdPrewrite(args) {
|
|
|
444
445
|
if (baseline.assessable === false) {
|
|
445
446
|
fail(`不可在本宿主评估该会话(${baseline.notAssessable?.reason ?? '宿主能力不足'})——写前校验无法给出可信结论;请用 0.1.5+ 宿主`, 3);
|
|
446
447
|
}
|
|
447
|
-
|
|
448
|
+
// 基线门:只阻断"非既有行形状"的 error。历史行的加载形状问题(E12/E13,如老事件缺 time)
|
|
449
|
+
// 属既有行遗留,按 warning 提示并允许本次写入(否则用户撤回/编辑会被永久拦死)。
|
|
450
|
+
const legacyShapeErrors = baseline.violations.filter((v) => v.severity === 'error' && LEGACY_ROW_SHAPE_IDS.has(v.id));
|
|
451
|
+
if (blockingBaselineViolations(baseline.violations).length > 0) {
|
|
448
452
|
// 基线已坏:写前校验无法在坏基线上给出可信结论
|
|
449
453
|
fail(`基线会话已有 ${baseline.summary.bySeverity.error} 个 error 级违规,请先修复基线再校验写入(安全修复协议第 2 步:改前基线必须绿)`);
|
|
450
454
|
}
|
|
455
|
+
if (legacyShapeErrors.length > 0) {
|
|
456
|
+
errOut(`⚠️ 基线含 ${legacyShapeErrors.length} 条既有行的加载形状问题(${[...new Set(legacyShapeErrors.map((v) => v.id))].join('/')})——按"既有行"降级:不阻断本次写入;建议一次性迁移这些行(如补齐数字 time)
|
|
457
|
+
`);
|
|
458
|
+
}
|
|
451
459
|
|
|
452
460
|
// C2:把被检文件的 header 显式交给 prewriter(版本不再靠模块级全局;缺省也能自行推断)
|
|
453
461
|
const prewriter = createPreWriter({ events: log.events.map((e) => e.event), header: log.header, ignorableWhitelist: prewriteWhitelist });
|
package/lib/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { loadSessionLog, tailSeq, readSessionHeader } from './log-reader.js';
|
|
8
8
|
export { validateSessionLog, resumeVerdict, migrationVerdict, assessmentScope } from './validate.js';
|
|
9
|
-
export { createPreWriter, preWriterFromLog } from './prewrite.js';
|
|
9
|
+
export { createPreWriter, preWriterFromLog, LEGACY_ROW_SHAPE_IDS, blockingBaselineViolations } from './prewrite.js';
|
|
10
10
|
export { repairSession, strictScanText, removeMarkersText, neutralizeMarkersText, clipCrossStepSourcesText, dropFailedTurnsText, trimLastMessagesText, trimLastMessagesByBudget, estimateTokensText, compactLastMessagesText, rebuildZstdText, tailRenumberText, neutralizeOrphanText, extractTurnText, keepRangesText } from './repair.js';
|
|
11
11
|
export { CONTRACT_RULES, LAYER, SEVERITY, ruleById } from './contracts.js';
|
|
12
12
|
export { explainRule, examplePointers, relatedCommandsOf, EXPLAIN_KEYS, EXPLAIN_DOC } from './explain.js';
|
package/lib/prewrite.js
CHANGED
|
@@ -63,6 +63,18 @@ export function legacyMarkerKindOf(event) {
|
|
|
63
63
|
* (`dsh-session` lib/index.js:1456 `time: Date.now()`)——拟写对象里的 time 并不被宿主消费,
|
|
64
64
|
* 因此"缺 time"不是写出错误(E12 只应拦"宿主加载器会拒的存储形态")。
|
|
65
65
|
*/
|
|
66
|
+
/**
|
|
67
|
+
* 「既有行形状」规则:这些规则的违规若落在**既有且未被本次修改**的事件上,
|
|
68
|
+
* 属历史遗留行的加载形状问题(如老事件缺 `time`),不得阻断用户写入。
|
|
69
|
+
* 供写前守卫/CLI 的"基线门"复用(与 validateAppend 的 origin 归因同一口径)。
|
|
70
|
+
*/
|
|
71
|
+
export const LEGACY_ROW_SHAPE_IDS = Object.freeze(new Set(['E12', 'E13']));
|
|
72
|
+
|
|
73
|
+
/** 基线门:只保留会阻断写入的 error(既有行的形状问题降级,不阻断)。 */
|
|
74
|
+
export function blockingBaselineViolations(violations = []) {
|
|
75
|
+
return (violations ?? []).filter((v) => v.severity === 'error' && !LEGACY_ROW_SHAPE_IDS.has(v.id));
|
|
76
|
+
}
|
|
77
|
+
|
|
66
78
|
function normalizeCandidate(candidate, nextSeq) {
|
|
67
79
|
const withSeq = candidate.seq === undefined ? { ...candidate, seq: nextSeq } : candidate;
|
|
68
80
|
return withSeq.time === undefined ? { ...withSeq, time: Date.now() } : withSeq;
|
|
@@ -201,6 +213,38 @@ export function createPreWriter(input = {}) {
|
|
|
201
213
|
: candidateEvents.map((event) => ({ event }));
|
|
202
214
|
violations.push(...declarativeIgnorableViolations(subject, 0, { ignorableWhitelist }).violations);
|
|
203
215
|
}
|
|
216
|
+
// ── 归因:既有行 vs 本次候选 ────────────────────────────────────────────
|
|
217
|
+
// 写前守卫会把**整份日志副本**送进来校验;若旧行本身有历史上遗留的信封问题
|
|
218
|
+
// (如老事件缺 `time`),那不是"本次写入引入的新违规",不得把所有写入永久拒掉。
|
|
219
|
+
// 规则:seq 属于**既有且未被本次修改**的事件 ⇒ origin='existing',降级为 warning
|
|
220
|
+
// (可见、可一次性迁移),不阻断;本次候选/新增行仍按 error 硬拒;seq=null 的
|
|
221
|
+
// 全局性结论(fold 失败等)保持 error(无法归因到单行)。
|
|
222
|
+
const baseBySeq = new Map();
|
|
223
|
+
for (const e of events) baseBySeq.set(e.seq, e);
|
|
224
|
+
const currentBySeq = new Map();
|
|
225
|
+
for (const e of candidateEvents) if (!currentBySeq.has(e.seq)) currentBySeq.set(e.seq, e);
|
|
226
|
+
const sameEvent = (a, b) => {
|
|
227
|
+
if (a === b) return true;
|
|
228
|
+
try { return JSON.stringify(a) === JSON.stringify(b); } catch { return false; }
|
|
229
|
+
};
|
|
230
|
+
const isExistingRow = (v) => {
|
|
231
|
+
if (v.seq === null || !baseBySeq.has(v.seq)) return false;
|
|
232
|
+
return sameEvent(baseBySeq.get(v.seq), currentBySeq.get(v.seq));
|
|
233
|
+
};
|
|
234
|
+
const attributed = violations.map((v) => {
|
|
235
|
+
if (isExistingRow(v)) {
|
|
236
|
+
return {
|
|
237
|
+
...v,
|
|
238
|
+
origin: 'existing',
|
|
239
|
+
originalSeverity: v.severity,
|
|
240
|
+
severity: 'warning',
|
|
241
|
+
message: `${v.message}(既有行:不阻断本次写入;建议一次性迁移该行)`,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
return { ...v, origin: v.seq === null ? 'global' : 'candidate' };
|
|
245
|
+
});
|
|
246
|
+
violations.length = 0;
|
|
247
|
+
violations.push(...attributed);
|
|
204
248
|
const bySeverity = { error: 0, warning: 0, info: 0 };
|
|
205
249
|
for (const v of violations) bySeverity[v.severity] = (bySeverity[v.severity] ?? 0) + 1;
|
|
206
250
|
// 「让降级可见」:把"本次写入沿用了历史 marker 形态(债)"作为**结构化字段**带出,
|
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.49",
|
|
5
5
|
"packageManager": "pnpm@11.7.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "lib/index.js",
|