@deepseek-ai/dsh-session-format-v0-to-v1 0.1.3-alpha.2

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: 308e61fdd7fc97d4ab90bc965bdc7d9ac7e39b57
6
+ README.zh.md: 6002e753ef5ac2924cfef4a28554487983145a9e
package/README.md ADDED
@@ -0,0 +1,113 @@
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
+ # @deepseek-ai/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 released-v0 JSONL record language one physical row at a time 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 fields 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 the package has no independently observable runtime registrations whose state can diverge; decoder and migration-stage state belongs to one restore.
31
+
32
+ ### Entry point
33
+
34
+ ```text
35
+ const decoder = releasedV0SessionFormatCodec.createDecoder(physicalHeader, 'recoverable')
36
+ for (const row of physicalRows) decoder.decodeRow(row, migrationContext)
37
+ const inheritedEventCount = decoder.finish(migrationContext)
38
+ const stage = sessionFormatV0ToV1.createStage(stageInput)
39
+ stage.transformEvent(event, migrationContext)
40
+ const targetInheritedEventCount = stage.finish(migrationContext)
41
+ ```
42
+
43
+ `releasedV0SessionFormatCodec` reads the exact v0 header and physical rows, including packed Assistant deltas and range-encoded provenance. Its decoder emits either a scalar event or a codec-owned compact run through `emitEvent()` and `emitRun()`. `sessionFormatV0ToV1` creates one stateful stage per restore; the static catalog connects that decoder and stage so migration does not retain a physical-row array. `releasedV1SessionFormatCodec` exposes the same row-at-a-time decoder for the v1 physical layout without freezing the ordinary event vocabulary.
44
+
45
+ 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.
46
+
47
+ The bounded historical normalizers convert `steering/message` to `user/message`, rename `compact/*` events to `compaction/*`, remove `turn/start.trigger`, convert retired `turn/end` reasons, add current message wrappers and deterministic ids for legacy messages, retry chains, and compaction groups, 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.
48
+
49
+ -----
50
+
51
+ <a id="understand-the-implementation"></a>
52
+ ## Understand the implementation
53
+
54
+ <details>
55
+ <summary>Implementation internals — click to expand</summary>
56
+
57
+ The physical codec validates each packed row atomically, emits it as a compact run, and never mutates parsed input. Recoverable decoding drops a complete faulty row and keeps the preceding prefix unless a later decoded `turn/end` proves that the faulty region was committed. The incremental normalizer retains only message, retry, and open-compaction identities; the catalog performs complete relationship validation on the final current artifact.
58
+
59
+ | File | Role |
60
+ |---|---|
61
+ | [`src/codec.ts`](src/codec.ts) | Frozen v0/v1 physical headers, packed rows, and provenance ranges |
62
+ | [`src/dispositions.ts`](src/dispositions.ts) | Released-v0 event and payload-member inventory |
63
+ | [`src/payload-validation.ts`](src/payload-validation.ts) | Frozen nested payload semantics for every released-v0/v1 event type |
64
+ | [`src/relationships.ts`](src/relationships.ts) | Frozen cross-event pairings: turns, steps, tool starts and results, retries, compaction, titles |
65
+ | [`src/migration.ts`](src/migration.ts) | Identity edge and legacy normalization |
66
+ | [`src/validation.ts`](src/validation.ts) | Exact source and target validation |
67
+
68
+ </details>
69
+
70
+ -----
71
+
72
+ <a id="further-exploration"></a>
73
+ ## Further Exploration
74
+
75
+ - [Migration machinery](../session-format/README.md) — pure chain and codec contracts.
76
+ - [Static catalog](../session-format-catalog/README.md) — build-owned assembly.
77
+ - [Session subsystem](../../../docs/subsystems/session.md) — current logical Session semantics.
78
+
79
+ -----
80
+
81
+ <a id="model-experience"></a>
82
+ ## Model Experience
83
+
84
+ ### Historical restoration
85
+
86
+ #### What the model sees
87
+
88
+ 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.
89
+
90
+ #### Token effect
91
+
92
+ Zero direct tokens.
93
+
94
+ #### KV Cache effect
95
+
96
+ No direct effect for canonical v0 history. Bounded normalizers preserve model-visible content while producing current wrappers and deterministic identities.
97
+
98
+ ## Known Limitations and Deferred Work
99
+
100
+ <a id="known-limitations-and-deferred-work"></a>
101
+
102
+ - **Closed first-party inventory** — unknown external-plugin events refuse migration in this alpha policy.
103
+ - **One adjacent edge** — this package does not perform publication or select later migrations.
104
+
105
+ <a id="dev-note"></a>
106
+ ### Dev Note
107
+
108
+ <details>
109
+ <summary>Working context for maintainers — click to expand</summary>
110
+
111
+ None.
112
+
113
+ </details>
package/README.zh.md ADDED
@@ -0,0 +1,113 @@
1
+ ---
2
+ description: "冻结的已发布 v0 Session 标头、事件与打包行解码器,以及到 v1 的恒等转换。"
3
+ kind: "package-library"
4
+ ---
5
+
6
+ # @deepseek-ai/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` 外,该迁移边会保留经过校验的 header 与事件事实;它也会应用 v0 持久化曾接受的有限旧格式规范化。该包冻结 v0 reader、严格的 v1 迁移目标校验器,以及词汇中立的 v1 物理 codec,使后续迁移边无需导入最新 Session 表示即可复用它。它的大部分源码是冻结的已发布 v0/v1 事件词表而不是恒等转换本身:`payload-validation.ts` 与 `relationships.ts` 钉住每种第一方事件类型的 payload 成员与生命周期配对,使畸形历史日志在已安装的 current restorer 运行之前就以「不支持的迁移」被拒绝并保留源文件,也使后续重构已发布事件的迁移边无需导入当前 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` 获取该迁移边;功能组合不会挂载它。只有在装配或测试静态已发布格式目录时,才直接导入本包。它不发布运行时不变式伴生入口,因为本包没有状态可能彼此分歧的、可独立观测的运行时注册项;decoder 与 migration stage 的状态只属于一次还原。
31
+
32
+ ### 入口
33
+
34
+ ```text
35
+ const decoder = releasedV0SessionFormatCodec.createDecoder(physicalHeader, 'recoverable')
36
+ for (const row of physicalRows) decoder.decodeRow(row, migrationContext)
37
+ const inheritedEventCount = decoder.finish(migrationContext)
38
+ const stage = sessionFormatV0ToV1.createStage(stageInput)
39
+ stage.transformEvent(event, migrationContext)
40
+ const targetInheritedEventCount = stage.finish(migrationContext)
41
+ ```
42
+
43
+ `releasedV0SessionFormatCodec` 读取精确的 v0 header 与物理行,包括打包的 Assistant 增量和范围编码的来源序号。它的 decoder 通过 `emitEvent()` 与 `emitRun()` 发出单个事件或 codec 自有的紧凑 run。`sessionFormatV0ToV1` 为每次还原创建一个有状态 Stage;静态 catalog 连接该 decoder 与 Stage,使迁移无需保留物理行数组。`releasedV1SessionFormatCodec` 为 v1 物理布局暴露相同的逐行 decoder,同时不冻结普通事件词表。
44
+
45
+ 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,已知分支则接受结构校验。
46
+
47
+ 有限的历史规范化会把 `steering/message` 转换为 `user/message`、把 `compact/*` 事件重命名为 `compaction/*`、移除 `turn/start.trigger`、转换已停用的 `turn/end` reason、添加当前消息包装层,并为旧 message、retry chain 与 compaction group 补充确定性 id,同时移除已停用且重复的 `request/header.header.messagePrefix`。已停用的 `request/header-delta`、`mode/set` 和 `request/header` fallback reason 会使迁移失败。除此之外,任何事件、引用、来源或 payload 事实都不得改变。
48
+
49
+ -----
50
+
51
+ <a id="understand-the-implementation"></a>
52
+ ## 理解实现
53
+
54
+ <details>
55
+ <summary>实现细节——点击展开</summary>
56
+
57
+ 物理 codec 会以行为原子单位校验每个打包行,以紧凑 run 发出它,且绝不修改已解析输入。可恢复解码会丢弃完整的故障行并保留此前前缀,除非后续成功解码的 `turn/end` 证明故障区域已经提交。增量 normalizer 只保留 message、retry 与未结束 compaction 的 identity;catalog 会在最终当前 artifact 上执行完整关系校验。
58
+
59
+ | 文件 | 职责 |
60
+ |---|---|
61
+ | [`src/codec.ts`](src/codec.ts) | 冻结的 v0/v1 物理标头、打包行与来源序号范围 |
62
+ | [`src/dispositions.ts`](src/dispositions.ts) | 已发布 v0 事件与 payload 成员清单 |
63
+ | [`src/payload-validation.ts`](src/payload-validation.ts) | 每种已发布 v0/v1 事件类型的冻结嵌套 payload 语义 |
64
+ | [`src/relationships.ts`](src/relationships.ts) | 冻结的跨事件配对:轮次、步骤、工具开始与结果、重试、压缩、标题 |
65
+ | [`src/migration.ts`](src/migration.ts) | 恒等迁移边与旧格式规范化 |
66
+ | [`src/validation.ts`](src/validation.ts) | 精确的源与目标校验 |
67
+
68
+ </details>
69
+
70
+ -----
71
+
72
+ <a id="further-exploration"></a>
73
+ ## 进一步探索
74
+
75
+ - [迁移机制](../session-format/README.zh.md)——纯迁移链与编解码约定。
76
+ - [静态目录](../session-format-catalog/README.zh.md)——构建拥有的装配。
77
+ - [Session 子系统](../../../docs/subsystems/session.zh.md)——当前逻辑 Session 语义。
78
+
79
+ -----
80
+
81
+ <a id="model-experience"></a>
82
+ ## 模型体验
83
+
84
+ ### 历史还原
85
+
86
+ #### 模型看到什么
87
+
88
+ 没有直接内容。还原后,`deriveMessages()` 会看到在 v1 下保持不变的规范已发布 v0 事件;有限历史结构会通过规定的当前包装层产生相同的模型可见内容。
89
+
90
+ #### Token 影响
91
+
92
+ 不直接产生 token。
93
+
94
+ #### KV Cache 影响
95
+
96
+ 对规范 v0 历史没有直接影响。有限 normalizer 会在生成当前包装层与确定性标识时保留模型可见内容。
97
+
98
+ ## 已知限制与延期工作
99
+
100
+ <a id="known-limitations-and-deferred-work"></a>
101
+
102
+ - **封闭的第一方清单**——按照当前 Alpha 策略,未知的外部插件事件会使迁移失败。
103
+ - **单个相邻迁移边**——本包不执行发布,也不选择后续迁移。
104
+
105
+ <a id="dev-note"></a>
106
+ ### 开发备注
107
+
108
+ <details>
109
+ <summary>维护者的工作上下文——点击展开</summary>
110
+
111
+ 无。
112
+
113
+ </details>