dsh-plugin-dev-kb 1.0.9 → 1.3.0

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.
Files changed (169) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.en.md +14 -8
  3. package/README.md +14 -8
  4. package/docs/banner.svg +25 -0
  5. package/kb/INDEX.md +8 -2
  6. package/kb/README.md +4 -4
  7. package/kb/extra/AGENTS.md +3 -3
  8. package/kb/extra/cookbook/adding-a-remote-api.md +197 -0
  9. package/kb/extra/cookbook/adding-a-remote-api.zh.md +197 -0
  10. package/kb/extra/cookbook/adding-a-session-format-version.md +109 -0
  11. package/kb/extra/cookbook/adding-a-session-format-version.zh.md +109 -0
  12. package/kb/extra/cookbook/adding-a-vendored-package.md +1 -1
  13. package/kb/extra/cookbook/adding-a-vendored-package.zh.md +1 -1
  14. package/kb/extra/cookbook/responding-to-pr-review-on-a-stack.md +1 -1
  15. package/kb/extra/cookbook/responding-to-pr-review-on-a-stack.zh.md +1 -1
  16. package/kb/extra/deepseek-llm-api-wire-extensions.md +19 -15
  17. package/kb/extra/deepseek-llm-api-wire-extensions.zh.md +19 -15
  18. package/kb/extra/development.md +13 -3
  19. package/kb/extra/development.zh.md +13 -3
  20. package/kb/extra/event-producer-consumer.md +49 -46
  21. package/kb/extra/event-producer-consumer.zh.md +52 -49
  22. package/kb/extra/i18n/README.md +2 -1
  23. package/kb/extra/i18n/README.zh.md +3 -2
  24. package/kb/extra/i18n/style-samples.md +2 -2
  25. package/kb/extra/i18n/translation-prompt.md +1 -1
  26. package/kb/extra/module-graph.md +493 -1002
  27. package/kb/extra/module-graph.zh.md +495 -1004
  28. package/kb/extra/rescope.md +1 -1
  29. package/kb/extra/rescope.zh.md +1 -1
  30. package/kb/extra/session-format-status.md +47 -0
  31. package/kb/extra/session-format-status.zh.md +47 -0
  32. package/kb/extra/subsystems/agent-team.md +3 -2
  33. package/kb/extra/subsystems/agent-team.zh.md +3 -2
  34. package/kb/extra/subsystems/attachment.md +157 -4
  35. package/kb/extra/subsystems/attachment.zh.md +157 -4
  36. package/kb/extra/subsystems/feedback.md +164 -30
  37. package/kb/extra/subsystems/feedback.zh.md +164 -30
  38. package/kb/extra/testing.md +9 -4
  39. package/kb/extra/testing.zh.md +9 -4
  40. package/kb/extra/web-styling.md +5 -0
  41. package/kb/extra/web-styling.zh.md +5 -0
  42. package/kb/meta/search-index.json +223 -151
  43. package/kb/meta/site-pages.txt +187 -181
  44. package/kb/meta/source.json +5 -5
  45. package/kb/meta/topics.md +5 -5
  46. package/kb/site/develop/basic/publish.md +1 -1
  47. package/kb/site/develop/cordis-tutorial/07-into-the-harness.md +3 -2
  48. package/kb/site/develop/practice/llm-adapter.md +4 -3
  49. package/kb/site/en/develop/basic/publish.md +1 -1
  50. package/kb/site/en/develop/cordis-tutorial/07-into-the-harness.md +3 -2
  51. package/kb/site/en/develop/practice/llm-adapter.md +4 -3
  52. package/kb/site/en/guide/network-proxy.md +87 -0
  53. package/kb/site/en/guide/providers.md +70 -17
  54. package/kb/site/en/guide/python-sdk.md +19 -3
  55. package/kb/site/en/guide/schedule.md +2 -0
  56. package/kb/site/en/reference/agent-lifecycle.md +17 -8
  57. package/kb/site/en/reference/api-gateway.md +2 -2
  58. package/kb/site/en/reference/capability-seams.md +24 -10
  59. package/kb/site/en/reference/config-catalog.md +322 -264
  60. package/kb/site/en/reference/cookbook/adding-a-package.md +1 -2
  61. package/kb/site/en/reference/cookbook/adding-a-settings-card.md +10 -8
  62. package/kb/site/en/reference/cookbook/adding-a-tool.md +1 -1
  63. package/kb/site/en/reference/cookbook/extension-cookbook.md +16 -13
  64. package/kb/site/en/reference/index.md +26 -9
  65. package/kb/site/en/reference/persistence-catalog.md +189 -95
  66. package/kb/site/en/reference/subsystems/approval.md +1 -1
  67. package/kb/site/en/reference/subsystems/client-modules.md +9 -0
  68. package/kb/site/en/reference/subsystems/client-resources.md +94 -0
  69. package/kb/site/en/reference/subsystems/code-runtime.md +7 -3
  70. package/kb/site/en/reference/subsystems/commands.md +25 -16
  71. package/kb/site/en/reference/subsystems/compaction.md +10 -10
  72. package/kb/site/en/reference/subsystems/conversation.md +11 -4
  73. package/kb/site/en/reference/subsystems/core.md +173 -29
  74. package/kb/site/en/reference/subsystems/credentials.md +5 -4
  75. package/kb/site/en/reference/subsystems/filesystem.md +15 -0
  76. package/kb/site/en/reference/subsystems/goal.md +38 -2
  77. package/kb/site/en/reference/subsystems/index.md +3 -1
  78. package/kb/site/en/reference/subsystems/invariants.md +1 -1
  79. package/kb/site/en/reference/subsystems/llm-streaming.md +43 -12
  80. package/kb/site/en/reference/subsystems/lsp.md +1 -1
  81. package/kb/site/en/reference/subsystems/permission-presets.md +5 -5
  82. package/kb/site/en/reference/subsystems/persistence.md +211 -199
  83. package/kb/site/en/reference/subsystems/plan.md +3 -3
  84. package/kb/site/en/reference/subsystems/sandbox.md +2 -0
  85. package/kb/site/en/reference/subsystems/schedule.md +9 -3
  86. package/kb/site/en/reference/subsystems/scope.md +1 -1
  87. package/kb/site/en/reference/subsystems/session-projection.md +50 -24
  88. package/kb/site/en/reference/subsystems/session-query.md +19 -13
  89. package/kb/site/en/reference/subsystems/session-reference.md +29 -1
  90. package/kb/site/en/reference/subsystems/session-telemetry.md +27 -10
  91. package/kb/site/en/reference/subsystems/session-title.md +6 -6
  92. package/kb/site/en/reference/subsystems/session.md +208 -103
  93. package/kb/site/en/reference/subsystems/settings.md +30 -12
  94. package/kb/site/en/reference/subsystems/shell.md +9 -6
  95. package/kb/site/en/reference/subsystems/sidebar-right.md +151 -0
  96. package/kb/site/en/reference/subsystems/skills.md +1 -1
  97. package/kb/site/en/reference/subsystems/slots.md +41 -32
  98. package/kb/site/en/reference/subsystems/spill.md +13 -6
  99. package/kb/site/en/reference/subsystems/storage.md +28 -5
  100. package/kb/site/en/reference/subsystems/subagent.md +58 -105
  101. package/kb/site/en/reference/subsystems/subprocess.md +25 -26
  102. package/kb/site/en/reference/subsystems/system-prompt.md +18 -3
  103. package/kb/site/en/reference/subsystems/token-meter.md +4 -3
  104. package/kb/site/en/reference/subsystems/tools.md +5 -5
  105. package/kb/site/en/reference/subsystems/typert.md +18 -18
  106. package/kb/site/en/reference/subsystems/web-client.md +1 -1
  107. package/kb/site/en/reference/subsystems/workspace.md +88 -9
  108. package/kb/site/en/reference/tool-catalog.md +56 -66
  109. package/kb/site/en/reference/tool-execution-pipeline.md +2 -2
  110. package/kb/site/guide/network-proxy.md +87 -0
  111. package/kb/site/guide/providers.md +70 -17
  112. package/kb/site/guide/python-sdk.md +19 -3
  113. package/kb/site/guide/schedule.md +2 -0
  114. package/kb/site/reference/agent-lifecycle.md +17 -8
  115. package/kb/site/reference/api-gateway.md +2 -2
  116. package/kb/site/reference/capability-seams.md +24 -10
  117. package/kb/site/reference/config-catalog.md +321 -263
  118. package/kb/site/reference/cookbook/adding-a-package.md +1 -2
  119. package/kb/site/reference/cookbook/adding-a-settings-card.md +10 -8
  120. package/kb/site/reference/cookbook/adding-a-tool.md +1 -1
  121. package/kb/site/reference/cookbook/extension-cookbook.md +16 -13
  122. package/kb/site/reference/index.md +26 -9
  123. package/kb/site/reference/persistence-catalog.md +190 -96
  124. package/kb/site/reference/subsystems/approval.md +1 -1
  125. package/kb/site/reference/subsystems/client-modules.md +9 -0
  126. package/kb/site/reference/subsystems/client-resources.md +94 -0
  127. package/kb/site/reference/subsystems/code-runtime.md +7 -3
  128. package/kb/site/reference/subsystems/commands.md +25 -16
  129. package/kb/site/reference/subsystems/compaction.md +10 -10
  130. package/kb/site/reference/subsystems/conversation.md +11 -4
  131. package/kb/site/reference/subsystems/core.md +173 -29
  132. package/kb/site/reference/subsystems/credentials.md +5 -4
  133. package/kb/site/reference/subsystems/filesystem.md +15 -0
  134. package/kb/site/reference/subsystems/goal.md +38 -2
  135. package/kb/site/reference/subsystems/index.md +14 -12
  136. package/kb/site/reference/subsystems/invariants.md +1 -1
  137. package/kb/site/reference/subsystems/llm-streaming.md +43 -12
  138. package/kb/site/reference/subsystems/lsp.md +1 -1
  139. package/kb/site/reference/subsystems/permission-presets.md +5 -5
  140. package/kb/site/reference/subsystems/persistence.md +210 -198
  141. package/kb/site/reference/subsystems/plan.md +3 -3
  142. package/kb/site/reference/subsystems/schedule.md +9 -3
  143. package/kb/site/reference/subsystems/scope.md +1 -1
  144. package/kb/site/reference/subsystems/session-projection.md +50 -24
  145. package/kb/site/reference/subsystems/session-query.md +19 -13
  146. package/kb/site/reference/subsystems/session-reference.md +29 -1
  147. package/kb/site/reference/subsystems/session-telemetry.md +27 -10
  148. package/kb/site/reference/subsystems/session-title.md +6 -6
  149. package/kb/site/reference/subsystems/session.md +208 -103
  150. package/kb/site/reference/subsystems/settings.md +30 -12
  151. package/kb/site/reference/subsystems/shell.md +9 -6
  152. package/kb/site/reference/subsystems/sidebar-right.md +151 -0
  153. package/kb/site/reference/subsystems/skills.md +1 -1
  154. package/kb/site/reference/subsystems/slots.md +41 -32
  155. package/kb/site/reference/subsystems/spill.md +13 -6
  156. package/kb/site/reference/subsystems/storage.md +28 -5
  157. package/kb/site/reference/subsystems/subagent.md +58 -105
  158. package/kb/site/reference/subsystems/subprocess.md +25 -26
  159. package/kb/site/reference/subsystems/system-prompt.md +18 -3
  160. package/kb/site/reference/subsystems/token-meter.md +4 -3
  161. package/kb/site/reference/subsystems/tools.md +5 -5
  162. package/kb/site/reference/subsystems/typert.md +18 -18
  163. package/kb/site/reference/subsystems/web-client.md +1 -1
  164. package/kb/site/reference/subsystems/workspace.md +88 -9
  165. package/kb/site/reference/tool-catalog.md +55 -65
  166. package/kb/site/reference/tool-execution-pipeline.md +2 -2
  167. package/lib/index.js +25 -44
  168. package/package.json +3 -2
  169. package/skills/dsh-plugin-dev-kb.md +4 -4
@@ -5,31 +5,127 @@ outline: [2,3]
5
5
 
6
6
  # 会话持久化
7
7
 
8
- 事件日志的**持久性 seam**。[session.md](./session.md) 描述了内存中的 `Session`:仅追加的 `SessionEvent` 日志即为真源。本页描述如何使该日志持久化:抽象的 `SessionPersistence` 服务、它的后端、flush 检查点、崩溃恢复,以及随日志一同存储的元数据头。日志承载的事件词汇在生成的[持久化日志事件目录](../persistence-catalog.md)中逐项列举。
8
+ 事件日志的**持久性 seam**。[session.md](./session.md) 描述了内存中的 `Session`:仅追加的 `SessionEvent` 日志即为真源。本页描述如何使该日志持久化:抽象的 `SessionPersistence` 服务、它的提供方模型与随产品交付的 JSONL 后端、flush 检查点、崩溃恢复,以及随日志一同存储的元数据头。日志承载的事件词汇在生成的[持久化日志事件目录](../persistence-catalog.md)中逐项列举。
9
9
 
10
- 该 seam 是一个[能力 seam](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/architecture/2026-06-13-capability-seams.zh.md):一个抽象服务([dsh-session-persistence](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/session/session-persistence),`ctx.sessionPersistence`)在现有 `SessionEvent` 上定义 locate/create/append、可复用的 Session 准备流程、逻辑 load/inspect、物理后缀读取,以及轻量的 list/snapshot 观察——**没有平行的持久化事件类型**——以及三个实现同一约定的可互换提供方。见 [session-persistence Agent Note](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/architecture/2026-06-14-session-persistence.zh.md)。
10
+ 该 seam 是一个[能力 seam](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/architecture/2026-06-13-capability-seams.zh.md):一个抽象服务([dsh-session-persistence](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/session/session-persistence),`ctx.sessionPersistence`)在现有 `SessionEvent` 上暴露 `create`/`open`/`stat`/`list`——**没有平行的持久化事件类型**——其中 `create` `open` 返回逐会话的 `SessionHandle`(`read`/`append`/`flush`/`close`),它承载全部日志访问与单写者所有权。仓库随产品交付 [dsh-session-persistence-jsonl](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/session/session-persistence-jsonl) 作为其 provider;仓库外 provider 可以实现同一服务约定。见[基于句柄的持久化 Agent Note](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/architecture/2026-08-27-handle-based-session-persistence.zh.md)与 [session-persistence Agent Note](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/architecture/2026-06-14-session-persistence.zh.md)。
11
+
12
+ ## `SessionHandle`——通向已存储会话的一条打开通道
13
+
14
+ 每一次日志读写都经由句柄流动,绝不经由按 id 寻址的服务方法:句柄是跨进程写租约把守的唯一入口。读取会返回调用方独占的外层 slice,以及由生产者建立的 event value 别名状态。一种句柄类型同时服务两种访问——在 `read` 句柄上执行修改是运行时的 `SessionReadOnlyError`,而非类型层面的拆分——而进程内单写者所有权使得在已有活跃持有者时第二次 `open(id, 'write')` 以 `SessionAlreadyOwnedError` 拒绝。
15
+
16
+ ```ts type-equiv
17
+ /** One persistence event slice returned by {@link SessionHandle.read}. */
18
+ interface SessionHandleReadResult {
19
+ /**
20
+ * Whether event values are exclusively owned or shared only after deep
21
+ * freezing. Slicing preserves the producer's state even when no events remain.
22
+ */
23
+ readonly eventState: SessionSeedEventState
24
+ /** Event values in a caller-owned outer array. */
25
+ readonly events: readonly SessionEvent[]
26
+ }
27
+ ```
28
+
29
+ ```ts type-equiv
30
+ /**
31
+ * One open channel onto a stored session. A handle is single-owner state, not
32
+ * a shared service: `read` never backtracks below what this handle already
33
+ * observed, a `write` handle reads its own successful appends, and `close()`
34
+ * is the one teardown (idempotent, uncancellable; `Symbol.asyncDispose`
35
+ * delegates to it). Every operation on a closed handle rejects with
36
+ * `SessionHandleClosedError`.
37
+ *
38
+ * Freshness across handles: once an `append` or `flush` resolves on a write
39
+ * handle, every read STARTED afterwards on the same backend instance — on any
40
+ * handle, or through `stat`/`list` — observes at least that prefix.
41
+ * Reads concurrent with a mutation carry no ordering promise beyond the valid
42
+ * contiguous prefix.
43
+ */
44
+ interface SessionHandle extends AsyncDisposable {
45
+ /** The stored session this handle addresses. */
46
+ readonly id: SessionId
47
+ /** The immutable stored header, fixed at `create`/`open`. */
48
+ readonly header: SessionHeader
49
+ /**
50
+ * Exact fork-inherited prefix length stored with the log; `0` when
51
+ * `header.isSeeded` is false. Storage metadata paired with the header for
52
+ * every body read, never part of the replayable event log.
53
+ */
54
+ readonly inheritedEventCount: SessionLogOffset
55
+ /** Whether this handle may mutate the log. */
56
+ readonly access: SessionAccess
57
+
58
+ /**
59
+ * Read a slice of the valid contiguous logical log. The slice is a legal log
60
+ * prefix segment: a torn physical tail is never returned, and repeated reads
61
+ * on this handle never observe an older state than a prior read.
62
+ * @param offset - first logical event seq to include; defaults to `0`.
63
+ * @param length - maximum number of events to return; defaults to the rest
64
+ * of the log. An offset at or past the end returns an empty list.
65
+ * @param options - optional cancellation.
66
+ * @returns the caller-owned outer slice plus the ownership state of its event values.
67
+ */
68
+ read(offset?: number, length?: number, options?: SessionHandleReadOptions): Promise<SessionHandleReadResult>
69
+
70
+ /**
71
+ * Append a contiguous batch continuing the current logical end. The first
72
+ * event's `seq` MUST equal the stored next-seq; committed events are never
73
+ * rewritten. Persistence is best-effort: on resolution the batch is
74
+ * accepted, ordered, and visible to reads on this backend instance, but
75
+ * only a resolved {@link flush} promises it survives a crash — a backend
76
+ * may buffer or batch physical writes behind append. Rejects with
77
+ * `SessionReadOnlyError` on a read handle and `SessionOwnershipLostError`
78
+ * when write ownership is gone.
79
+ * @param events - the contiguous batch, in seq order.
80
+ * @param options - optional cancellation observed before the write starts.
81
+ */
82
+ append(events: readonly SessionEvent[], options?: SessionHandleAppendOptions): Promise<void>
83
+
84
+ /**
85
+ * The durability barrier — the one operation that promises storage: on
86
+ * resolution every acknowledged append is durable and the session is
87
+ * materialized for other processes; an empty created session becomes
88
+ * durably listable here. Callers that must survive a crash flush; a backend
89
+ * whose `append` already persists on resolution treats this as
90
+ * materialize-if-needed. Rejects with `SessionReadOnlyError` on a read
91
+ * handle.
92
+ * @param options - optional cancellation observed before the barrier starts.
93
+ */
94
+ flush(options?: SessionHandleFlushOptions): Promise<void>
95
+
96
+ /**
97
+ * Release the handle: a read handle frees local resources; a write handle
98
+ * completes pending durability and releases write ownership. Idempotent,
99
+ * asynchronous, and deliberately not cancellable.
100
+ */
101
+ close(): Promise<void>
102
+ }
103
+ ```
104
+
105
+ 已创建的会话自 `create` 完成之刻起即可在本进程内被观察到,而后端可以把物理实体化(纯粹的优化)推迟到第一次 `append` 或 `flush`;其他进程只能看到已实体化的会话,一个在崩溃前从未实体化的会话等于从未存在。
11
106
 
12
107
  ## flush 检查点
13
108
 
14
- `session/event` 是一个*同步*通知;持久化插件会将事件复制到逐会话控制器,而不阻塞生产方。第一个待处理事件会开启固定批处理窗口,后续事件会加入但不会重置截止时间。窗口到期后会启动一个持久化批次;该次写入期间接纳的事件会获得自己的截止时间,并形成后续批次。`session/flush` 会取消等待并排空至完全停稳,因此循环仍将其用作在领取下一个普通轮次之前的顺序与错误观察检查点。后台写入被拒绝时会保留对应事件并暂停自动重试;新事件会开启新的固定窗口,而显式 flush 会立即重试,并通过 `agent/error` logger 报告失败,绝不会把失败记录成已关闭轮次之后的会话事件。dispose(资源释放)会执行同样的最终排空。配置的最大值只限制有意的批处理等待,不限制事件循环调度或后端完成持久化的延迟([决策](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/architecture/2026-08-08-bounded-session-persistence-write-batching.zh.md))。
109
+ `session/event` 是一个*同步*通知;挂载的后端按会话 id 把它路由进活跃写句柄的有界 write-behind 窗口,而不阻塞生产方(后端一次性安装这些监听器,因为持久化已保证每个 id 只有一个活跃写句柄)。第一个待处理事件会开启固定的内部批处理窗口,后续事件会加入但不会重置其截止时间。窗口到期后会通过该会话的写句柄启动一次持久化 `append`;该次写入期间接纳的事件会获得自己的截止时间,并形成后续批次。`session/flush` 会取消等待并排空至完全停稳,因此循环仍将其用作在领取下一个普通轮次之前的顺序与错误观察检查点。后台写入被拒绝时会按序保留对应事件、暂停自动路径,并通过 logger 报告;下一次显式 flush 会重试,并向其调用方响亮地拒绝。`session/disposed` 会执行同样的最终排空并关闭句柄,而 `close()` 本身会经由仍然打开的存储排空已路由的缓冲,因此后端 teardown 的关闭清扫不丢任何数据。该窗口只限制有意的批处理等待,不限制事件循环调度或后端完成持久化的延迟。
15
110
 
16
111
  ## 崩溃恢复保留被中断的轮次
17
112
 
18
- 后端重新加载一个在轮次中途崩溃的日志时,会发现一个已打开的 `turn/start` 却没有 `turn/end`。它**不会**截断日志:在长周期任务中,单个轮次可能非常庞大(许多步骤、大量工具输出),而这些事件在崩溃前已被持久追加。后端改为用一个合成的 `turn/end { reason: { kind: 'interrupted' } }` 关闭这个遗留轮次,在不改变其前后任何独立事件的情况下配平被中断的执行。`interrupted` 是唯一一个不由循环发出的 `TurnEndReason`(见 [session.md](./session.md#why-a-turn-ended-turnendreasonmap))。
113
+ 一个在轮次中途崩溃的日志以打开的 `turn/start` 而无 `turn/end` 结束。持久化**不会**截断或修复它:在长周期任务中,单个轮次可能非常庞大(许多步骤、大量工具输出),而这些事件在崩溃前已被持久追加。它返回物理上有效的连续日志;只有撕裂物理尾部——属于一次从未完成的 append——中不完整的碎片会被丢弃:从中恢复的完整记录(JSONL 后端会部分解码撕裂的 Zstandard 帧)由写路径在句柄的第一次新 append 之前持久重写。修复是读方的职责:resume(agent-loop)通过其写句柄读取已存储的日志,计算 `interruptedTurnClosers`——缺失的工具错误、任何未闭合的 `step/end`,以及一个合成的 `turn/end { reason: { kind: 'interrupted' } }`——并在发布 Session 之前把它们作为普通批次通过同一句柄追加。`interrupted` 是唯一一个不由循环发出的 `TurnEndReason`(见 [session.md](./session.md#why-a-turn-ended-turnendreasonmap))。
19
114
 
20
- 修复仅适用于冷会话。对于活跃 id,`SessionPersistence.load(id)` 会等待权威内存快照完成持久化,并且只在日志平衡时返回;若活跃轮次仍未闭合,则拒绝操作,而不是添加合成的中断边界。HMR(热模块替换)会接管活跃前缀,而不会关闭其中正在进行的轮次。
115
+ 因此修复只在写所有权之下写入:活跃会话的写句柄由其生命周期所有者持有,故并发的 `open(id, 'write')` 会以 `SessionAlreadyOwnedError` 拒绝,而不是让修复与活跃轮次竞速。只读观察方(session-query)仅在内存中用同样的闭合事件配平被中断的冷日志,不回写任何内容。
21
116
 
22
- `SessionPersistence.inspect(id)` 会构造一个不可变的逻辑 Session,但不发布它,也不写入恢复内容。冷检查会在内存中配平中断的轮次,同时保持撕裂的物理尾部不变;检查已处于活跃状态的 Session 则借用其当前不可变快照,因此可能包含未闭合的轮次。使用协调器的实现会在有界 LRU 中保留这个精确的冷未发布 Session,因此重复历史读取与后续 `prepare(id)` 可复用同一次读取、解压、验证、冻结及 Session 构造。`prepare(id)` 会预留该 Session、提交待处理修复并返回可 dispose 的发布句柄;`load(id)` 使用相同机制提交修复,但不会发布 Session。该生命周期由 [Session 准备阶段决策](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/architecture/2026-08-05-session-preparation.zh.md)定义。
117
+ 只读观察即 `open(id, 'read')`:句柄提供经过验证的连续前缀切片,绝不返回撕裂尾部,且同一句柄上的重复读取绝不会观察到比先前读取更旧的状态。持久化侧不存在已准备 Session 缓存:session-query 拥有自己的冷读缓存,按 `stat().revision` 变更令牌为每个 id 缓存一个已配平的冷 Session,仅在令牌变化时重新读取。该生命周期由[基于句柄的持久化 Agent Note](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/architecture/2026-08-27-handle-based-session-persistence.zh.md)定义;已归档的 [Session 准备阶段记录](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/archived/architecture/2026-08-05-session-preparation.md)记载了发布边界 `SessionPreparation` 最初的决策。
23
118
 
24
- ## `SessionLocation`——可选的逐会话产物目标
119
+ ## `SessionLocation`——拒绝诊断的产物目标
25
120
 
26
- `SessionPersistence.locate(meta)` 会同步解析一个归后端所有的独立产物,而不会读取、创建或 flush 它。JSONL 返回其项目/会话目录内 transcript(文本记录)的绝对路径;SQLite 因各会话共享一个数据库而返回 `undefined`。因此,返回的路径可能指向尚不存在的文件,或指向还不包含当前尚未 flush 轮次的文件;它是位置提示,不是授权或新鲜度保证。
121
+ `SessionLocation` 不是面向消费者的查询:日志访问走会话句柄的 `read`。它仅作为拒绝诊断存在,使 `SessionFormatUnsupportedError` 能指出本构建拒绝解读的原始日志。JSONL 提供其项目/会话目录内 transcript(文本记录)的绝对路径;没有逐会话工件的后端则不提供。
27
122
 
28
123
  ```ts type-equiv
29
124
  /**
30
- * A backend-resolved, per-session local artifact location. The path is an
31
- * absolute target path and can name an artifact that has not materialized yet.
32
- * Consumers must treat it as a location hint, never as an authorization token.
125
+ * A backend-resolved, per-session local artifact location. Carried only by
126
+ * refusal diagnostics ({@link SessionFormatUnsupportedError}) so a user can
127
+ * find the raw log a build refused to interpret; it is not a consumer-facing
128
+ * query — log access goes through a session handle's `read`.
33
129
  */
34
130
  interface SessionLocation {
35
131
  /** Backend-specific artifact kind, for example `jsonl`. */
@@ -43,7 +139,7 @@ interface SessionLocation {
43
139
 
44
140
  ## `SessionHeader`:日志旁的元数据
45
141
 
46
- 每个会话的元数据与事件日志**分开**存储:格式版本、cwd、血统与 seed 边界是存储层关注点而非对话事件,因此不进入 `SessionEventMap`,也不会到达 `deriveMessages()`。header 通过 `session.header` 附加到 `Session` 上。
142
+ 每个会话的元数据与事件日志**分开**存储:header 携带格式版本、cwd `isSeeded` 谱系 bit,含正文的存储值则在其旁边单独携带精确 inherited cut。二者都不进入 `SessionEventMap`,也不会到达 `deriveMessages()`。logical header 通过 `session.header` 附加,Session 则以 `inheritedEventCount` 暴露其 cut。
47
143
 
48
144
  源码:[`packages/core/session/src/types.ts`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/core/session/src/types.ts)
49
145
 
@@ -53,11 +149,10 @@ interface SessionLocation {
53
149
  */
54
150
  interface SessionHeader {
55
151
  /**
56
- * On-disk format version, stamped from {@link SESSION_FORMAT_VERSION} when the
57
- * session is created. A persistence backend rejects any other version on load
58
- * (no migration — see the constant).
152
+ * Current logical format version, stamped from {@link SESSION_FORMAT_VERSION}.
153
+ * Historical physical headers are translated before entering this interface.
59
154
  */
60
- readonly version: number
155
+ readonly version: typeof SESSION_FORMAT_VERSION
61
156
  /** The session's id (mirrors the {@link Session}'s id). */
62
157
  readonly id: SessionId
63
158
  /** Non-negative safe-integer Unix epoch milliseconds when the session was created. */
@@ -67,10 +162,10 @@ interface SessionHeader {
67
162
  /** The session this one was forked from (seed lineage), if any. */
68
163
  readonly parentSession?: SessionId
69
164
  /**
70
- * How many leading events were inherited through a seed. Persisting this
71
- * boundary lets resume and replay distinguish parent history from child work.
165
+ * Whether this Session contains a fork-inherited event prefix. The exact prefix
166
+ * length is Session state rather than ordinary header metadata.
72
167
  */
73
- readonly seedLength?: number
168
+ readonly isSeeded: boolean
74
169
  /**
75
170
  * Coarse product classification for a session created as a subagent child.
76
171
  * This is presentation metadata, not proof that the child is continuable.
@@ -94,11 +189,11 @@ interface SessionHeader {
94
189
 
95
190
  ## 格式拒绝:本构建无法可靠读取的日志
96
191
 
97
- 后端用 `SessionFormatUnsupportedError` 拒绝无法可靠解读的日志,它与 `SessionPersistenceCorruptionError` 区分,因为数据没有损坏。header `version` `SESSION_FORMAT_VERSION` 新时,消息说明方向("由更新的 harness 写入,请升级 harness 后打开");比它旧时说明本构建没有升级路径。经过 legacy 形状归一化后,本构建生成集合(`KNOWN_SESSION_EVENT_TYPES`,由 `gen-persistence-catalog` 生成)之外的事件类型也会拒绝重建,因为静默跳过该事件可能改变日志其余部分的解读方式。后端为每个会话保留独立文件时,消息附上原始日志路径,被拒绝的文本仍然可读。JSONL 后端直接从原始 header 行拒绝外来版本,先于校验本格式版本的 header 字段和解码任何事件行,因此结构完全不同的未来格式仍会报告升级方向,绝不会报"损坏";SQLite 则先由自己的 `SCHEMA_VERSION` pragma 把关整个文件的结构。设计理由与推迟建设的升级器链见[事件词汇表显式拒绝 Agent Note](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/simplification/2026-08-25-fail-closed-session-event-vocabulary.zh.md)
192
+ 后端用 `SessionFormatUnsupportedError` 拒绝无法可靠解读的日志,它与 `SessionPersistenceCorruptionError` 区分,因为数据没有损坏。`stat` `list` 会对最高规范 generation 分类,并在不读取或改变正文的前提下转换受支持的历史 header。历史 `open` 会共享每个 Session 唯一的一次 migration preparation,再返回当前逻辑值,并保持每个源路径、字节与 inode 不变。JSONL provider 直接从该内存结果返回读句柄而不发布;写 open 则在持有单写者 claim 与文件 lease 时复用 preparation、排他发布最终 current generation,随后才返回可写句柄。即使仍有较旧的可读 generation,最高的未来 generation 仍会导致拒绝。当前格式恢复会保留已安装扩展和带 `ignorable: true` 的未知事件;历史 v0/v1/v2 迁移则会拒绝未知类型,即使它带有 ignorable 标记。后端为每个会话保留独立文件时,消息附上选定的原始日志路径。仓库外后端必须在自己的物理格式入口提供等价的仅当前句柄值与方向感知拒绝。[已发布格式迁移决策](https://github.com/deepseek-ai/deepseek-harness/blob/master/.agents/notes/implemented/architecture/2026-08-31-released-session-format-migrations.zh.md)负责迁移链与不可变发布规则。
98
193
 
99
194
  ## `CreateSessionOptions`:seed 与元数据
100
195
 
101
- 通过 store 创建 `Session` 时会接收 `seed`(初始回放或 fork 历史)与 `meta`(store 整合进 `SessionHeader` 的存储层字段)。store 填充 `version`/`id` 并为 `createdAt` 提供默认值;调用方可以提供已校验的绝对 `cwd`、`parentSession` 谱系、`seedLength` 种子边界、可选的粗粒度 `origin`、`delegationDepth`、用于组装该 agent(智能体)的 `agentPreset` 以及已有的 `createdAt`。`origin: 'subagent'` 让产品导航能够隐藏重复的 child 行;它不证明描述符有效,也不证明 child 可以恢复。
196
+ 通过 store 创建 `Session` 时会接收 `seed`(初始回放或 fork 历史)、可选的精确 `inheritedEventCount` 与 `meta`(store 整合进 `SessionHeader` 的存储层字段)。store 填充 `version`/`id` 并为 `createdAt` 提供默认值;调用方可以提供已校验的绝对 `cwd`、`parentSession` 谱系、`isSeeded` 谱系标记、可选的粗粒度 `origin`、`delegationDepth`、用于组装该 agent(智能体)的 `agentPreset` 以及已有的 `createdAt`。seeded 创建必须显式提供与 inherited prefix 完全相等的 seed 和精确 cut;constructor 会先在该 cut 追加 child-owned tagged end-seed marker,setup 再添加 child-owned event。`origin: 'subagent'` 让产品导航能够隐藏重复的 child 行;它不证明描述符有效,也不证明 child 可以恢复。
102
197
 
103
198
  ```ts type-equiv
104
199
  /**
@@ -110,14 +205,20 @@ interface CreateSessionOptions {
110
205
  /** Initial replay or fork history supplied at construction. */
111
206
  readonly seed?: readonly SessionEvent[]
112
207
  /**
113
- * Storage metadata read once before publication. `seedLength` is explicit
114
- * because a resumed seed contains the full stored log, not only its inherited prefix.
208
+ * Exact fork-inherited prefix length when `meta.isSeeded` is true. The
209
+ * constructor seed is exactly this inherited prefix; the constructor
210
+ * appends the child-owned tagged marker at the cut.
211
+ */
212
+ readonly inheritedEventCount?: SessionLogOffset
213
+ /**
214
+ * Storage metadata read once before publication. `isSeeded` marks fork
215
+ * lineage; supplying replay history alone does not make it inherited.
115
216
  */
116
217
  readonly meta?: {
117
218
  readonly cwd?: string
118
219
  readonly parentSession?: SessionId
119
220
  readonly createdAt?: number
120
- readonly seedLength?: number
221
+ readonly isSeeded?: boolean
121
222
  readonly origin?: 'subagent'
122
223
  readonly delegationDepth?: number
123
224
  readonly agentPreset?: string
@@ -125,47 +226,41 @@ interface CreateSessionOptions {
125
226
  }
126
227
  ```
127
228
 
128
- 因此,回放/fork 的调用方式为 `ctx.sessions.create(id, { seed: seedEvents })`;将一个*持久化*会话恢复为活跃 agent 的调用方式为 `ctx.agents.resume({ resumeSessionId })`。
229
+ 因此,回放/fork 的调用方式为 `ctx.agents.create({ sessionId, seed, meta })`——fork 还会随 `meta.isSeeded: true` 提供 `inheritedEventCount`,且只有经 agent-loop 发布的会话才会持久化,且循环会在发布之前通过新会话的写句柄存储 seed;将一个*持久化*会话恢复为活跃 agent 的调用方式为 `ctx.agents.resume({ resumeSessionId })`。
129
230
 
130
- ## `SessionRawArtifact`——逐字存储工件文本
231
+ ## 准备与恢复所有权
131
232
 
132
- 后端为单个会话自持的工件文本,与其持久化写入的字节逐字一致(按物理编码解码)。`readRaw` 返回它而不从解析后事件重建,因此后端特定的序列化(chunk 打包、键序、换行)得以保留。Consumer 须先检查 `supportsRawArtifacts`:`false` 表示后端不提供此能力(如 SQLite),而 `readRaw(...) === undefined` 表示受支持的后端没有该会话的已实体化工件。
233
+ `SessionStore.prepare()` 接收普通创建选项,或通过 `RestoredSessionOptions` 接收可直接接管的 seed。它的 `eventState` 表明 event value 是独占对象,还是只有深度冻结后的共享对象;生产者负责建立该状态,slice 不会根据结果长度推断其他状态。恢复流程会校验并直接接管这些值,不再复制或冻结。`SessionPreparation` 随后持有该精确的未发布 Session,直至发布或回滚;dispose 是同步且幂等的。agent-loop 的 resume 通过该会话的写句柄读取这份结果,并在准备之前追加独占的 `interruptedTurnClosers`。
133
234
 
134
235
  ```ts type-equiv
135
- /** A backend's own raw artifact text for one session, verbatim. */
136
- interface SessionRawArtifact {
137
- /** The session header parsed from the artifact's own first line. */
138
- readonly meta: SessionHeader
139
- /** The artifact's base filename on disk, without any physical encoding suffix. */
140
- readonly filename: string
141
- /** The artifact's full text content, decoded from the backend's physical encoding. */
142
- readonly content: string
143
- }
236
+ /**
237
+ * Aliasing state of an adoptable Session seed. `shared-frozen` permits deeply
238
+ * frozen aliases plus independently owned unfrozen values in the same seed.
239
+ */
240
+ type SessionSeedEventState = 'detached' | 'shared-frozen'
144
241
  ```
145
242
 
146
- ## 准备与恢复所有权
147
-
148
- `SessionStore.prepare()` 接收普通创建选项,或通过 `RestoredSessionOptions` 转移所有权的全新的持久化对象图。恢复分支会就地验证并冻结转移来的 header 与事件,因此调用方不得保留可变别名。`SessionPreparation` 随后持有该精确的未发布 Session,直至发布或回滚;dispose 是同步且幂等的。持久化检查只暴露 `SessionInspection`,即从同一个已准备 Session 借用的不可变逻辑视图。
149
-
150
243
  ```ts type-equiv
151
244
  /**
152
- * Fresh storage values transferred to {@link SessionStore.prepare} without a
153
- * second serialization copy. Callers retain no mutable aliases.
245
+ * Adoptable storage values transferred to {@link SessionStore.prepare}
246
+ * without another copy or freeze pass.
154
247
  */
155
248
  interface RestoredSessionOptions {
156
- /** Fresh detached storage events to validate and freeze in place. */
249
+ /** Events that are independently owned or already deeply frozen. */
157
250
  readonly seed: SessionEvent[]
158
- /** Fresh detached storage metadata to validate and freeze in place. */
251
+ /** Independently owned storage metadata to validate and freeze in place. */
159
252
  readonly meta: SessionHeader
160
- /** Select the persistence ownership-transfer path. */
161
- readonly seedSource: 'persistence'
253
+ /** Exact number of fork-inherited leading events decoded from storage. */
254
+ readonly inheritedEventCount: SessionLogOffset
255
+ /** Aliasing state carried from the operation that produced the seed. */
256
+ readonly eventState: SessionSeedEventState
162
257
  }
163
258
  ```
164
259
 
165
260
  ```ts type-equiv
166
261
  /** Inputs accepted while constructing an unpublished Session. */
167
262
  type PrepareSessionOptions =
168
- | (CreateSessionOptions & { readonly seedSource?: undefined })
263
+ | (CreateSessionOptions & { readonly eventState?: undefined })
169
264
  | RestoredSessionOptions
170
265
  ```
171
266
 
@@ -199,19 +294,9 @@ declare class SessionPreparation implements Disposable {
199
294
  }
200
295
  ```
201
296
 
202
- ```ts type-equiv
203
- /** Immutable logical session prepared from persistence or a live owner. */
204
- interface SessionInspection {
205
- /** Validated immutable session metadata. */
206
- readonly meta: SessionHeader
207
- /** Validated contiguous logical event log. */
208
- readonly events: readonly SessionEvent[]
209
- }
210
- ```
211
-
212
297
  ## 轻量源修订号
213
298
 
214
- 派生状态的消费方会在加载完整事件日志之前比较一个低开销的不透明修订号。其表示由持久化后端拥有,并随 append 或会修改数据的 load 修复以事务方式改变;调用方仅比较修订号是否相等。
299
+ 派生读取模型的消费方会在加载完整事件日志之前比较一个低开销的不透明修订号。该修订号是来自 `stat`/`list` 的逐后端实例变更令牌:修订号相等可视为日志未变;不相等则不作任何承诺,且写所有权的变动绝不会改变修订号。session-query 以它为键管理冷读缓存;该令牌在 open、read 或 resume 中不起任何作用。
215
300
 
216
301
  ```ts type-equiv
217
302
  /**
@@ -222,21 +307,29 @@ type SessionPersistenceRevision = Branded<'SessionPersistenceRevision'>
222
307
  ```
223
308
 
224
309
  ```ts type-equiv
225
- /** Lightweight immutable source identity returned without loading a full log. */
310
+ /**
311
+ * Lightweight stored-session observation returned by {@link SessionPersistence.stat}
312
+ * and {@link SessionPersistence.list} without reading the full event log.
313
+ */
226
314
  interface SessionPersistenceSnapshot {
227
- /** Detached metadata for one materialized session. */
228
- header: SessionHeader
229
- /** Opaque source-qualified token that changes whenever this stored log changes. */
230
- revision: SessionPersistenceRevision
315
+ /** Detached metadata for one stored session. */
316
+ readonly header: SessionHeader
317
+ /** Opaque change token; see {@link SessionPersistence.stat}. */
318
+ readonly revision: SessionPersistenceRevision
319
+ /** Logical event count, when the backend can provide it cheaply from metadata; otherwise absent. */
320
+ readonly eventCount?: number
321
+ /** Physical artifact byte size, when the backend can provide it cheaply (JSONL); otherwise absent. */
322
+ readonly sizeBytes?: number
231
323
  }
232
324
  ```
233
325
 
326
+ 可选的 `eventCount`/`sizeBytes` 字段仍是供明确需要它们的 consumer 使用的低成本 backend observation。Session 列表不借助这两个字段打开冷日志,只读取 header 与经过 identity 校验的 projection cache hint,因此 cache 或 Session format 升级不会把启动变成 body scan。
327
+
234
328
  ## 后端
235
329
 
236
- 两者都实现同一个抽象 `SessionPersistence`(在 `SessionEvent` 上执行 locate/create/append/prepare/load/inspect/readFrom/list/listSnapshots,观察方法可选支持取消),并通过共享的 `runPersistenceContract` 套件:
330
+ 随产品交付的 provider 实现抽象 `SessionPersistence` 约定(`create`/`open`/`stat`/`list`,逐会话 `SessionHandle` 承载 `read`/`append`/`flush`/`close`,全程可选支持取消),并通过共享的持久化契约套件:
237
331
 
238
- - **[dsh-session-persistence-jsonl](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/session/session-persistence-jsonl)**——逐会话仅追加的逻辑 JSONL 日志,默认存储为带 checksum 的连续 Zstandard frame,也可配置为原始行;支持崩溃安全的原子写入、被中断轮次的恢复以及读取/回放路径。
239
- - **[dsh-session-persistence-sqlite](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/session/session-persistence-sqlite)**:一个可选启用的 `node:sqlite` 后端,使用 schema 19 把同一分片块中字段完全匹配的 delta 连续段存为有界物理 `text-chunks`、`reasoning-chunks` 与 `tool-call-chunks` 行。它在返回前重建完整逻辑事件流,只打包新增的持久批次,并拒绝旧 schema,而不是执行迁移。
332
+ - **[dsh-session-persistence-jsonl](https://github.com/deepseek-ai/deepseek-harness/tree/master/packages/session/session-persistence-jsonl)**——逐会话仅追加的逻辑 JSONL 日志,默认存储为带 checksum 的连续 Zstandard frame,也可配置为原始行;具备崩溃安全的原子实体化、逐批 `fsync` 的 append,以及在第一次新 append 之前截断撕裂尾部。`stat`/`list` 携带 `sizeBytes` 与尽力而为的、由 `fs.stat` 派生的修订号。
240
333
 
241
334
  <!-- BEGIN GENERATED cordis-surface (gen-cordis-catalog.ts) — do not edit between markers -->
242
335
 
@@ -250,158 +343,77 @@ Generated from source by `scripts/gen-cordis-catalog.ts` (verified fresh by `pnp
250
343
 
251
344
  ### `ctx.sessionPersistence` — `SessionPersistence` (abstract seam)
252
345
 
253
- Durable append-only session storage. Implementations preserve contiguous, losslessly JSON-serializable events; append resolves only after durability, and load balances a complete interrupted tail without rewriting committed events.
346
+ Durable append-only session storage addressed through per-session handles.
254
347
 
255
- ```ts cordis-catalog
256
- /**
257
- * Resolve this backend's independent local artifact for a session without
258
- * reading, creating, flushing, or otherwise materializing it. Backends such
259
- * as SQLite that do not own one artifact per session return `undefined`.
260
- * @param meta - the immutable session header whose artifact is requested.
261
- * @returns the backend-specific absolute location, when one exists.
262
- */
263
- abstract locate(meta: SessionHeader): SessionLocation | undefined
348
+ Storage semantics shared by every backend: events are contiguous from seq 0 and never rewritten; a torn physical tail is never returned to a reader and is truncated by the write path before its first append; reads validate current-format records only and refuse unknown vocabulary fail-closed. `append` persists best-effort; `flush` — per handle or service-wide — is the durability barrier.
264
349
 
265
- /**
266
- * Read a session's backend-owned artifact text verbatim — the exact durable
267
- * bytes the backend wrote (decoded from its physical encoding, e.g. a
268
- * decompressed JSONL). The returned `content` is the raw text, not a
269
- * reconstruction from parsed events, so it preserves backend-specific
270
- * serialization (chunk packing, key order, line breaks). Callers first test
271
- * {@link supportsRawArtifacts}; `undefined` then means only that the requested
272
- * session has no materialized artifact.
273
- * @param _id - the persisted session to read (unused by the default: no
274
- * per-session artifact).
275
- * @param signal - optional cancellation for backend read work.
276
- * @returns the raw artifact plus its parsed header, or `undefined` when the
277
- * session is absent.
278
- * @throws when this backend does not expose per-session raw artifacts.
279
- */
280
- readRaw(_id: SessionId, signal?: AbortSignal): Promise<SessionRawArtifact | undefined>
350
+ Visibility: a created session is observable through `stat`/`list`/`open` in this process from the moment `create` resolves, even while a backend defers physical materialization (a pure optimization); other processes see the session only once it materializes, and a session that never materialized before a crash never existed. `SessionHandle.flush` forces materialization.
281
351
 
282
- /**
283
- * Register a new session's metadata. A backend MAY defer the physical write
284
- * until the first {@link append} (lazy materialization), in which case a
285
- * created-but-never-appended session is absent from {@link list}
286
- * — abandoned sessions leave nothing behind.
287
- * @param meta - the immutable header (id, version, cwd, lineage) to record.
288
- */
289
- abstract create(meta: SessionHeader): Promise<void>
290
-
291
- /**
292
- * Ensure a live session has a durable header even when it has no events.
293
- * Ordinary sessions remain lazily materialized; lifecycle frontends call
294
- * this only when an empty session itself is a durable resumable resource.
295
- * @param _session - exact live session whose registered header is materialized.
296
- */
297
- ensureMaterialized(_session: Session): Promise<void>
298
-
299
- /**
300
- * Durably persist a batch of events. Honors the append-only and contiguous-
301
- * seq contracts: the first event's `seq` MUST equal the stored next-seq
302
- * (after `load` has durably closed any interrupted turn). Rejects non-JSON-
303
- * serializable `event.data` with an error naming the offending event type.
304
- * @param id - the session the batch belongs to.
305
- * @param events - the contiguous batch to persist, in seq order.
306
- */
307
- abstract append(id: SessionId, events: readonly SessionEvent[]): Promise<void>
308
-
309
- /**
310
- * Prepare the exact unpublished Session used by resume. Implementations may
311
- * reuse object graphs retained by an earlier {@link inspect} after confirming
312
- * their durable revision is still current; disposal releases an unpublished
313
- * reservation. Revision retries require the durable log to remain unchanged
314
- * for one read/check round trip; continuous external writers may delay completion.
315
- * @param id - persisted session to prepare.
316
- * @param signal - optional cancellation for preparation work.
317
- * @returns one owned unpublished Session preparation.
318
- */
319
- async prepare(id: SessionId, signal?: AbortSignal): Promise<SessionPreparation>
320
-
321
- /**
322
- * Load an immutable balanced logical view and commit any required cold
323
- * recovery. A complete interrupted final turn is preserved and durably
324
- * closed with missing tool errors plus any open step and turn boundaries;
325
- * only a torn final record is discarded. Unknown versions and corruption in
326
- * the committed prefix reject. Implementations MUST NOT crash-repair an
327
- * identity still bound to a live Session: a balanced live log may return as a
328
- * durable snapshot, while an open live turn rejects. Returned values may be
329
- * shared with immutable live or prepared state and must not be mutated.
330
- * Revision-based implementations may wait for one stable read/check round trip.
331
- * @param id - the persisted session to reload.
332
- * @returns the header and a log ending on a balanced `turn/end`.
333
- */
334
- abstract load(id: SessionId): Promise<SessionInspection>
352
+ Freshness: once an `append` or `flush` resolves, reads started afterwards on this backend instance observe at least that prefix.
335
353
 
354
+ ```ts cordis-catalog
336
355
  /**
337
- * Inspect an immutable logical session without committing recovery or
338
- * publishing it. A cold complete interrupted turn receives synthetic closers
339
- * in memory and a torn physical tail remains untouched. An already-live
340
- * Session instead yields its current immutable snapshot, which may contain an
341
- * open turn and its `session/end-seed` boundary. Coordinator-backed
342
- * implementations retain the exact cold unpublished Session for bounded
343
- * reuse by a later {@link prepare}. A stale ready source is reloaded; a source
344
- * already committing or reserved for resume remains exclusive, and inspection
345
- * may borrow its immutable view. Callers borrow only the immutable header and
346
- * log. Continuous external writers may delay revision convergence.
347
- * @param id - the persisted session to inspect.
348
- * @param signal - optional cancellation for queued and backend read work.
349
- * @returns the validated header and current logical event log.
356
+ * Create a new stored session and take its write ownership.
357
+ * @param header - the immutable header (id, version, cwd, lineage) to store.
358
+ * @param options - optional cancellation.
359
+ * @returns a `write` handle owned by the caller; close it to release ownership.
360
+ * @throws {SessionAlreadyExistsError} when the id already exists.
350
361
  */
351
- abstract inspect(id: SessionId, signal?: AbortSignal): Promise<SessionInspection>
362
+ abstract create(header: SessionHeader, options?: SessionPersistenceCreateOptions): Promise<SessionHandle>
352
363
 
353
364
  /**
354
- * Borrow one exact inspection while retaining any reusable prepared source.
355
- * A cold observation must pin the exact prepared Session that a later
356
- * {@link prepare} reserves. Implementations must not degrade this operation
357
- * to a detached {@link inspect} result.
358
- * @param id - persisted session to observe.
359
- * @param signal - optional cancellation for preparation work.
360
- * @returns a disposable immutable observation.
365
+ * Open an existing stored session.
366
+ *
367
+ * `read` never takes ownership and works while another handle (or process)
368
+ * holds write ownership. `write` atomically claims single-writer ownership;
369
+ * an existing active owner rejects.
370
+ * @param id - the stored session to open.
371
+ * @param access - `read` or `write`.
372
+ * @param options - optional cancellation.
373
+ * @returns the open handle.
374
+ * @throws {SessionPersistenceNotFoundError} when the session does not exist.
375
+ * @throws {SessionAlreadyOwnedError} for `write` when ownership is taken.
361
376
  */
362
- abstract borrowSession(id: SessionId, signal?: AbortSignal): Promise<BorrowedSessionSource>
377
+ abstract open(id: SessionId, access: SessionAccess, options?: SessionPersistenceOpenOptions): Promise<SessionHandle>
363
378
 
364
379
  /**
365
- * Read the stored events from `fromSeq` onward the read-from-seq
366
- * primitive for read models that resume from a watermark (e.g. a persisted
367
- * projection cache folding only the tail past its checkpoint). Unlike
368
- * {@link inspect}, it is a detached physical suffix read: no preparation
369
- * cache, torn-tail truncation, synthetic closers, or coordinator-state
370
- * publication. Only events from the valid contiguous stored prefix are
371
- * returned, so a torn fragment never reaches the caller. `fromSeq` at or
372
- * beyond the stored prefix returns an empty event list (never an error).
373
- * Backends whose medium can seek by seq
374
- * (SQLite) read only the suffix; sequential media (JSONL, both encodings)
375
- * still parse the whole artifact and skip forward — the primitive bounds
376
- * what is RETURNED and refolded, not every backend's physical read.
377
- * @param id - the persisted session to read.
378
- * @param fromSeq - first event seq to include; a non-negative safe integer.
379
- * @param signal - optional cancellation for queued and backend read work.
380
- * @returns the header and the stored events with `seq >= fromSeq`.
380
+ * Flush every active write handle owned by this service instance in one
381
+ * durability barrier: each handle's routed live events drain durably and
382
+ * its session materializes, exactly as that handle's own
383
+ * `SessionHandle.flush` would. Read handles buffer nothing and are
384
+ * untouched. A handle closed concurrently counts as flushed — close itself
385
+ * drains durably.
386
+ * @returns resolution once every write handle active at the call has flushed.
387
+ * @throws {AggregateError} naming each session whose flush failed; the
388
+ * remaining handles still flush.
381
389
  */
382
- abstract readFrom(id: SessionId, fromSeq: number, signal?: AbortSignal): Promise<{ meta: SessionHeader; events: SessionEvent[] }>
390
+ abstract flush(): Promise<void>
383
391
 
384
392
  /**
385
- * Lightweight listing from metadata, without a full-log parse.
386
- * @param signal - optional cancellation for backend listing work.
387
- * @returns one header per materialized session.
393
+ * Observe one stored session without reading its event log or taking
394
+ * ownership.
395
+ *
396
+ * The snapshot's `revision` is an opaque change token comparable only
397
+ * against revisions from the same service instance and session id: equal
398
+ * revisions may be treated as an unchanged log; unequal revisions promise
399
+ * nothing. Write-ownership churn does not change a revision. It exists for
400
+ * derived read-model caches keyed off `stat`/`list`; it plays no part in
401
+ * open, read, or resume.
402
+ * @param id - the stored session to observe.
403
+ * @param options - optional cancellation.
404
+ * @returns the snapshot, or `undefined` when the session does not exist.
388
405
  */
389
- abstract list(signal?: AbortSignal): Promise<SessionHeader[]>
406
+ abstract stat(id: SessionId, options?: SessionPersistenceStatOptions): Promise<SessionPersistenceSnapshot | undefined>
390
407
 
391
408
  /**
392
- * List materialized sessions with cheap per-log change tokens.
393
- *
394
- * Repeated observations of an unchanged log return the same revision. A
395
- * successful mutating {@link load} repair changes the next listed revision.
396
- * Revisions also distinguish independently backed stores so backend-local
397
- * counters cannot compare equal across different persistence sources.
398
- * @param signal - optional cancellation for backend snapshot-listing work.
399
- * @returns one header and opaque revision per materialized session without loading full logs.
409
+ * List every stored session visible to this process, in no promised order.
410
+ * @param options - optional cancellation.
411
+ * @returns one snapshot per stored session.
400
412
  */
401
- abstract listSnapshots(signal?: AbortSignal): Promise<SessionPersistenceSnapshot[]>
413
+ abstract list(options?: SessionPersistenceListOptions): Promise<readonly SessionPersistenceSnapshot[]>
402
414
  ```
403
415
 
404
- Types: [Session](./session.md) · [SessionEvent](./session.md) · [SessionId](./core.md)
416
+ Types: [SessionId](./core.md)
405
417
 
406
418
  Source: [`packages/session/session-persistence/src/index.ts`](https://github.com/deepseek-ai/deepseek-harness/blob/master/packages/session/session-persistence/src/index.ts)
407
419
  <!-- END GENERATED cordis-surface -->
@@ -11,7 +11,7 @@ outline: [2,3]
11
11
 
12
12
  ## 已记录状态与恢复
13
13
 
14
- `plan/mode`(`{ active: boolean }`)是仅记日志、整值替换的[会话事件](./session.md):持久且可回放,绝不进入模型 transcript(文本记录)。`foldPlanMode(events, end?)` 返回前缀中最后一条已记录值,没有时返回 `false`:生效状态始终是会话日志的纯折叠,因此恢复、fork 与压缩(compaction)无需实时镜像即可将其复原,UI 通过 `session/event` 观察已提交的切换。完整事件声明见[持久化日志事件目录](../persistence-catalog.md)。
14
+ `plan/mode`(`{ active: boolean }`)是仅记日志、整值替换的[会话事件](./session.md):持久且可回放,绝不进入模型 transcript(文本记录)。可选注册的 `plan` 单元折叠已提交模式、命令结算结果和最近一次请求头记录的模式。`ctx.planMode` 通过 `stateOf()` 读取该状态;注册表、`plan` key `turnBoundary` key 缺失时,第一次依赖它们的访问会失败。客户端只接收 `{ active, pending }`;恢复、fork 与压缩(compaction)都能从日志恢复两者。完整事件声明见[持久化日志事件目录](../persistence-catalog.md)。
15
15
 
16
16
  ## 待生效选择与 pre-step 追加
17
17
 
@@ -29,7 +29,7 @@ interface PlanModeConfig {
29
29
  }
30
30
  ```
31
31
 
32
- `section` 缺失、为空白或不是字符串,以及任何未知键,都会在插件加载时失败,而不是被忽略。计划模式激活期间,确切的 `section` 文本以 first-party 顺序 500 渲染为 `plan:policy` [系统提示词段落](./system-prompt.md);未激活的计划模式不贡献任何文本。
32
+ `section` 缺失、为空白或不是字符串,以及任何未知键,都会在插件加载时失败,而不是被忽略。计划模式激活期间,确切的 `section` 文本以 order 50 渲染为 `plan:policy` [系统提示词段落](./system-prompt.md);未激活的计划模式不贡献任何文本。
33
33
 
34
34
  ## 退出工具与 `/plan` 命令
35
35
 
@@ -53,7 +53,7 @@ Generated from source by `scripts/gen-cordis-catalog.ts` (verified fresh by `pnp
53
53
 
54
54
  ### `ctx.planMode` — `PlanModeController`
55
55
 
56
- `ctx.planMode`: owns logged plan state, applies and narrates selected state at step start, the `plan:policy` section, the `/plan` command, and the stable exit tool. UIs observe committed flips through `session/event`; there is no live mirror.
56
+ `ctx.planMode`: owns logged plan state, applies and narrates selected state at step start, the `plan:policy` section, the `/plan` command, and the stable exit tool. Client carriers expose the projection's cropped `{ active, pending }` view.
57
57
 
58
58
  ```ts cordis-catalog
59
59
  /**