@xneog/dsh-session-format-v0-to-v1 0.1.3-alpha.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DeepSeek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ # Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
2
+ # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
+ # after editing either side, bring the other along and re-record with:
4
+ # pnpm run verify-translation-pairing --write packages/session/session-format-v0-to-v1/README.md
5
+ README.md: 9adc2e30f93da2d47b6a21a14267e8036ee20901
6
+ README.zh.md: 6ffb678913ae7d935122f297e1748881e6c9b46d
package/README.md ADDED
@@ -0,0 +1,109 @@
1
+ ---
2
+ description: "Frozen released-v0 Session header, event, and packed-row decoder with the identity conversion to v1."
3
+ kind: "package-library"
4
+ ---
5
+
6
+ # @xneog/dsh-session-format-v0-to-v1
7
+
8
+ English | [中文](README.zh.md)
9
+
10
+ ## Summary
11
+
12
+ `dsh-session-format-v0-to-v1` decodes the complete released-v0 JSONL record language and converts it into the shared-layout v1 format. The edge preserves validated header and event facts except for `version: 0` becoming `version: 1`; it also applies the finite legacy normalizers that v0 persistence accepted. The package freezes the v0 reader, the strict v1 migration target validator, and a vocabulary-neutral v1 physical codec that a later edge can reuse without importing the latest Session representation. Most of its source is the frozen released v0/v1 event vocabulary rather than the identity conversion: `payload-validation.ts` and `relationships.ts` pin the payload members and lifecycle pairings of every first-party event type, so a malformed historical log is refused as an unsupported migration with its source retained before the installed current restorer runs, and a later edge that restructures released events can trust their shapes without importing the current Session package.
13
+
14
+ ## Table of Contents
15
+
16
+ - [Use this package](#use-this-package)
17
+ - [Understand the implementation](#understand-the-implementation)
18
+ - [Further Exploration](#further-exploration)
19
+ - [Model Experience](#model-experience)
20
+ - [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
21
+ - [Dev Note](#dev-note)
22
+
23
+ -----
24
+
25
+ <a id="use-this-package"></a>
26
+ ## Use this package
27
+
28
+ ### When to use it
29
+
30
+ Persistence obtains this edge through `dsh-session-format-catalog`; feature compositions do not mount it. Import it directly only when assembling or testing the static released-format catalog. No runtime invariant companion is published because every codec and migration call validates its complete source or target artifact and retains no runtime state.
31
+
32
+ ### Entry point
33
+
34
+ ```text
35
+ const decodedV0 = releasedV0SessionFormatCodec.decodeArtifact(header, rows)
36
+ const migratedV1 = sessionFormatV0ToV1.migrate(decodedV0)
37
+ ```
38
+
39
+ `releasedV0SessionFormatCodec` reads the exact v0 header and physical rows, including packed assistant deltas and range-encoded provenance. `sessionFormatV0ToV1` normalizes and strictly validates a complete detached artifact. `releasedV1SessionFormatCodec` preserves the v1 physical layout without freezing the ordinary event vocabulary; the catalog restores current events against the installed Session package.
40
+
41
+ The alpha edge refuses every event type outside its frozen inventory, including an unknown event marked `ignorable: true`. It also refuses unexpected payload members. `tool/result.meta` and nested PTC `arguments` remain explicit opaque JSON fields and are preserved without Session-sequence interpretation. Unknown content-block `type`, message-source `kind`, assistant finish-reason `kind`, and `turn/end` reason `kind` arms remain owner-opaque JSON while their known arms receive structural validation.
42
+
43
+ The bounded historical normalizers convert `steering/message` to `user/message`, remove `turn/start.trigger`, convert retired `turn/end` reasons, add the current message wrappers and deterministic legacy message ids, and remove the obsolete `request/header.header.messagePrefix` duplicate. Retired `request/header-delta`, `mode/set`, and the `request/header` fallback reason refuse migration. No other event, reference, source, or payload fact may change.
44
+
45
+ -----
46
+
47
+ <a id="understand-the-implementation"></a>
48
+ ## Understand the implementation
49
+
50
+ <details>
51
+ <summary>Implementation internals — click to expand</summary>
52
+
53
+ The physical codec expands each packed row atomically and never mutates parsed input. Recoverable decoding rolls back a complete faulty row and keeps the preceding prefix unless a later decoded `turn/end` proves that the faulty region was committed. The migration validates the frozen payload disposition before changing the header version and validates the exact v1 target again.
54
+
55
+ | File | Role |
56
+ |---|---|
57
+ | [`src/codec.ts`](src/codec.ts) | Frozen v0/v1 physical headers, packed rows, and provenance ranges |
58
+ | [`src/dispositions.ts`](src/dispositions.ts) | Released-v0 event and payload-member inventory |
59
+ | [`src/payload-validation.ts`](src/payload-validation.ts) | Frozen nested payload semantics for every released-v0/v1 event type |
60
+ | [`src/relationships.ts`](src/relationships.ts) | Frozen cross-event pairings: turns, steps, tool starts and results, retries, compaction, titles |
61
+ | [`src/migration.ts`](src/migration.ts) | Identity edge and legacy normalization |
62
+ | [`src/validation.ts`](src/validation.ts) | Exact source and target validation |
63
+
64
+ </details>
65
+
66
+ -----
67
+
68
+ <a id="further-exploration"></a>
69
+ ## Further Exploration
70
+
71
+ - [Migration machinery](../session-format/README.md) — pure chain and codec contracts.
72
+ - [Static catalog](../session-format-catalog/README.md) — build-owned assembly.
73
+ - [Session subsystem](../../../docs/subsystems/session.md) — current logical Session semantics.
74
+
75
+ -----
76
+
77
+ <a id="model-experience"></a>
78
+ ## Model Experience
79
+
80
+ ### Historical restoration
81
+
82
+ #### What the model sees
83
+
84
+ Nothing directly. After restoration, `deriveMessages()` sees canonical released-v0 events unchanged under v1; bounded historical forms produce the same model-visible content through their defined current wrappers.
85
+
86
+ #### Token effect
87
+
88
+ Zero direct tokens.
89
+
90
+ #### KV Cache effect
91
+
92
+ No direct effect for canonical v0 history. Bounded normalizers preserve model-visible content while producing current wrappers and deterministic identities.
93
+
94
+ ## Known Limitations and Deferred Work
95
+
96
+ <a id="known-limitations-and-deferred-work"></a>
97
+
98
+ - **Closed first-party inventory** — unknown external-plugin events refuse migration in this alpha policy.
99
+ - **One adjacent edge** — this package does not perform publication or select later migrations.
100
+
101
+ <a id="dev-note"></a>
102
+ ### Dev Note
103
+
104
+ <details>
105
+ <summary>Working context for maintainers — click to expand</summary>
106
+
107
+ None.
108
+
109
+ </details>
package/README.zh.md ADDED
@@ -0,0 +1,109 @@
1
+ ---
2
+ description: "冻结的已发布 v0 Session 标头、事件与打包行解码器,以及到 v1 的恒等转换。"
3
+ kind: "package-library"
4
+ ---
5
+
6
+ # @xneog/dsh-session-format-v0-to-v1
7
+
8
+ [English](README.md) | 中文
9
+
10
+ ## 概述
11
+
12
+ `dsh-session-format-v0-to-v1` 解码完整的已发布 v0 JSONL 记录语言,并把它转换为共享布局的 v1 格式。除把 `version: 0` 改为 `version: 1` 外,该迁移边会保留经过校验的标头与事件事实;它也会应用 v0 持久化曾接受的有限旧格式规范化。该包冻结 v0 读取器、严格的 v1 迁移目标校验器,以及不冻结事件词表的 v1 物理编解码器,使后续迁移边无需导入最新 Session 表示即可复用它。它的大部分源码是冻结的已发布 v0/v1 事件词表而不是恒等转换本身:`payload-validation.ts` 与 `relationships.ts` 钉住每种第一方事件类型的 payload 成员与生命周期配对,使畸形历史日志在已安装的 current 恢复器运行之前就以「不支持的迁移」被拒绝并保留源文件,也使后续重构已发布事件的迁移边无需导入当前 Session 包即可信任其形状。
13
+
14
+ ## 目录
15
+
16
+ - [使用本包](#use-this-package)
17
+ - [理解实现](#understand-the-implementation)
18
+ - [进一步探索](#further-exploration)
19
+ - [模型体验](#model-experience)
20
+ - [已知限制与延期工作](#known-limitations-and-deferred-work)
21
+ - [开发备注](#dev-note)
22
+
23
+ -----
24
+
25
+ <a id="use-this-package"></a>
26
+ ## 使用本包
27
+
28
+ ### 何时使用
29
+
30
+ 持久化通过 `dsh-session-format-catalog` 获取该迁移边;功能组合不会挂载它。只有在装配或测试静态已发布格式目录时,才直接导入本包。它不发布运行时不变式伴生入口,因为每次 codec 与迁移调用都会校验完整的源或目标 artifact,且不保留运行时状态。
31
+
32
+ ### 入口
33
+
34
+ ```text
35
+ const decodedV0 = releasedV0SessionFormatCodec.decodeArtifact(header, rows)
36
+ const migratedV1 = sessionFormatV0ToV1.migrate(decodedV0)
37
+ ```
38
+
39
+ `releasedV0SessionFormatCodec` 读取精确的 v0 标头与物理行,包括打包的 Assistant 增量和范围编码的来源序号。`sessionFormatV0ToV1` 规范化并严格校验一个完整且分离的产物。`releasedV1SessionFormatCodec` 在不冻结普通事件词表的前提下保留 v1 物理布局;目录会根据已安装的 Session 包还原当前事件。
40
+
41
+ Alpha 迁移边会拒绝冻结清单之外的所有事件类型,包括带有 `ignorable: true` 标记的未知事件。它也会拒绝意外的 payload 成员。`tool/result.meta` 与嵌套 PTC `arguments` 是显式的不透明 JSON 字段;迁移会原样保留它们,不把其中的数字解释为 Session 序号。未知 content-block `type`、message-source `kind`、assistant finish-reason `kind` 与 `turn/end` reason `kind` 分支保持 owner-opaque JSON,已知分支则接受结构校验。
42
+
43
+ 有限的历史规范化会把 `steering/message` 转换为 `user/message`、移除 `turn/start.trigger`、转换已停用的 `turn/end` reason、添加当前消息包装层与确定性的旧消息 id,并移除已停用且重复的 `request/header.header.messagePrefix`。已停用的 `request/header-delta`、`mode/set` 和 `request/header` fallback reason 会使迁移失败。除此之外,任何事件、引用、来源或 payload 事实都不得改变。
44
+
45
+ -----
46
+
47
+ <a id="understand-the-implementation"></a>
48
+ ## 理解实现
49
+
50
+ <details>
51
+ <summary>实现细节——点击展开</summary>
52
+
53
+ 物理编解码器会以行为原子单位展开每个打包行,且绝不修改已解析输入。可恢复解码会回滚完整的故障行并保留此前前缀,除非后续成功解码的 `turn/end` 证明故障区域已经提交。迁移会先校验冻结的 payload 处置,再更改标头版本,并再次校验精确的 v1 目标。
54
+
55
+ | 文件 | 职责 |
56
+ |---|---|
57
+ | [`src/codec.ts`](src/codec.ts) | 冻结的 v0/v1 物理标头、打包行与来源序号范围 |
58
+ | [`src/dispositions.ts`](src/dispositions.ts) | 已发布 v0 事件与 payload 成员清单 |
59
+ | [`src/payload-validation.ts`](src/payload-validation.ts) | 每种已发布 v0/v1 事件类型的冻结嵌套 payload 语义 |
60
+ | [`src/relationships.ts`](src/relationships.ts) | 冻结的跨事件配对:轮次、步骤、工具开始与结果、重试、压缩、标题 |
61
+ | [`src/migration.ts`](src/migration.ts) | 恒等迁移边与旧格式规范化 |
62
+ | [`src/validation.ts`](src/validation.ts) | 精确的源与目标校验 |
63
+
64
+ </details>
65
+
66
+ -----
67
+
68
+ <a id="further-exploration"></a>
69
+ ## 进一步探索
70
+
71
+ - [迁移机制](../session-format/README.zh.md)——纯迁移链与编解码约定。
72
+ - [静态目录](../session-format-catalog/README.zh.md)——构建拥有的装配。
73
+ - [Session 子系统](../../../docs/subsystems/session.zh.md)——当前逻辑 Session 语义。
74
+
75
+ -----
76
+
77
+ <a id="model-experience"></a>
78
+ ## 模型体验
79
+
80
+ ### 历史还原
81
+
82
+ #### 模型看到什么
83
+
84
+ 没有直接内容。还原后,`deriveMessages()` 会看到在 v1 下保持不变的规范已发布 v0 事件;有限历史结构会通过规定的当前包装层产生相同的模型可见内容。
85
+
86
+ #### Token 影响
87
+
88
+ 不直接产生 token。
89
+
90
+ #### KV Cache 影响
91
+
92
+ 对规范 v0 历史没有直接影响。有限 normalizer 会在生成当前包装层与确定性标识时保留模型可见内容。
93
+
94
+ ## 已知限制与延期工作
95
+
96
+ <a id="known-limitations-and-deferred-work"></a>
97
+
98
+ - **封闭的第一方清单**——按照当前 Alpha 策略,未知的外部插件事件会使迁移失败。
99
+ - **单个相邻迁移边**——本包不执行发布,也不选择后续迁移。
100
+
101
+ <a id="dev-note"></a>
102
+ ### 开发备注
103
+
104
+ <details>
105
+ <summary>维护者的工作上下文——点击展开</summary>
106
+
107
+ 无。
108
+
109
+ </details>