@code-yeongyu/senpi-agent-core 2026.9.12 → 2026.9.13

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 (344) hide show
  1. package/README.md +4 -0
  2. package/dist/harness/agent-harness.d.ts +639 -384
  3. package/dist/harness/agent-harness.d.ts.map +1 -1
  4. package/dist/harness/agent-harness.js +5 -250
  5. package/dist/harness/agent-harness.js.map +1 -1
  6. package/dist/harness/compaction/branch-summarization.d.ts +12 -6
  7. package/dist/harness/compaction/branch-summarization.d.ts.map +1 -1
  8. package/dist/harness/compaction/branch-summarization.js +33 -27
  9. package/dist/harness/compaction/branch-summarization.js.map +1 -1
  10. package/dist/harness/compaction/compaction.d.ts +30 -8
  11. package/dist/harness/compaction/compaction.d.ts.map +1 -1
  12. package/dist/harness/compaction/compaction.js +53 -64
  13. package/dist/harness/compaction/compaction.js.map +1 -1
  14. package/dist/harness/config.d.ts +9 -0
  15. package/dist/harness/config.d.ts.map +1 -0
  16. package/dist/harness/config.js +35 -0
  17. package/dist/harness/config.js.map +1 -0
  18. package/dist/harness/context.d.ts +9 -0
  19. package/dist/harness/context.d.ts.map +1 -0
  20. package/dist/harness/context.js +13 -0
  21. package/dist/harness/context.js.map +1 -0
  22. package/dist/harness/env/nodejs.d.ts +25 -28
  23. package/dist/harness/env/nodejs.d.ts.map +1 -1
  24. package/dist/harness/env/nodejs.js +368 -125
  25. package/dist/harness/env/nodejs.js.map +1 -1
  26. package/dist/harness/events.d.ts +20 -38
  27. package/dist/harness/events.d.ts.map +1 -1
  28. package/dist/harness/events.js +233 -55
  29. package/dist/harness/events.js.map +1 -1
  30. package/dist/harness/execution/assistant.d.ts +42 -0
  31. package/dist/harness/execution/assistant.d.ts.map +1 -0
  32. package/dist/harness/execution/assistant.js +82 -0
  33. package/dist/harness/execution/assistant.js.map +1 -0
  34. package/dist/harness/execution/effect-gate.d.ts +22 -0
  35. package/dist/harness/execution/effect-gate.d.ts.map +1 -0
  36. package/dist/harness/execution/effect-gate.js +48 -0
  37. package/dist/harness/execution/effect-gate.js.map +1 -0
  38. package/dist/harness/execution/tools.d.ts +67 -0
  39. package/dist/harness/execution/tools.d.ts.map +1 -0
  40. package/dist/harness/execution/tools.js +121 -0
  41. package/dist/harness/execution/tools.js.map +1 -0
  42. package/dist/harness/hooks.d.ts +38 -0
  43. package/dist/harness/hooks.d.ts.map +1 -0
  44. package/dist/harness/hooks.js +404 -0
  45. package/dist/harness/hooks.js.map +1 -0
  46. package/dist/harness/messages.d.ts +2 -2
  47. package/dist/harness/messages.d.ts.map +1 -1
  48. package/dist/harness/messages.js.map +1 -1
  49. package/dist/harness/prompt-templates.d.ts +3 -2
  50. package/dist/harness/prompt-templates.d.ts.map +1 -1
  51. package/dist/harness/prompt-templates.js +17 -17
  52. package/dist/harness/prompt-templates.js.map +1 -1
  53. package/dist/harness/result.d.ts +93 -0
  54. package/dist/harness/result.d.ts.map +1 -1
  55. package/dist/harness/result.js +39 -0
  56. package/dist/harness/result.js.map +1 -1
  57. package/dist/harness/runtime/drive/boundary.d.ts +28 -0
  58. package/dist/harness/runtime/drive/boundary.d.ts.map +1 -0
  59. package/dist/harness/runtime/drive/boundary.js +173 -0
  60. package/dist/harness/runtime/drive/boundary.js.map +1 -0
  61. package/dist/harness/runtime/drive/checkpoint.d.ts +8 -0
  62. package/dist/harness/runtime/drive/checkpoint.d.ts.map +1 -0
  63. package/dist/harness/runtime/drive/checkpoint.js +133 -0
  64. package/dist/harness/runtime/drive/checkpoint.js.map +1 -0
  65. package/dist/harness/runtime/drive/deferred.d.ts +15 -0
  66. package/dist/harness/runtime/drive/deferred.d.ts.map +1 -0
  67. package/dist/harness/runtime/drive/deferred.js +179 -0
  68. package/dist/harness/runtime/drive/deferred.js.map +1 -0
  69. package/dist/harness/runtime/drive/generation.d.ts +8 -0
  70. package/dist/harness/runtime/drive/generation.d.ts.map +1 -0
  71. package/dist/harness/runtime/drive/generation.js +205 -0
  72. package/dist/harness/runtime/drive/generation.js.map +1 -0
  73. package/dist/harness/runtime/drive/reconcile.d.ts +5 -0
  74. package/dist/harness/runtime/drive/reconcile.d.ts.map +1 -0
  75. package/dist/harness/runtime/drive/reconcile.js +140 -0
  76. package/dist/harness/runtime/drive/reconcile.js.map +1 -0
  77. package/dist/harness/runtime/drive/recovery.d.ts +8 -0
  78. package/dist/harness/runtime/drive/recovery.d.ts.map +1 -0
  79. package/dist/harness/runtime/drive/recovery.js +85 -0
  80. package/dist/harness/runtime/drive/recovery.js.map +1 -0
  81. package/dist/harness/runtime/drive/response.d.ts +23 -0
  82. package/dist/harness/runtime/drive/response.d.ts.map +1 -0
  83. package/dist/harness/runtime/drive/response.js +394 -0
  84. package/dist/harness/runtime/drive/response.js.map +1 -0
  85. package/dist/harness/runtime/drive/retry.d.ts +4 -0
  86. package/dist/harness/runtime/drive/retry.d.ts.map +1 -0
  87. package/dist/harness/runtime/drive/retry.js +34 -0
  88. package/dist/harness/runtime/drive/retry.js.map +1 -0
  89. package/dist/harness/runtime/drive/structural.d.ts +32 -0
  90. package/dist/harness/runtime/drive/structural.d.ts.map +1 -0
  91. package/dist/harness/runtime/drive/structural.js +929 -0
  92. package/dist/harness/runtime/drive/structural.js.map +1 -0
  93. package/dist/harness/runtime/drive/terminal.d.ts +7 -0
  94. package/dist/harness/runtime/drive/terminal.d.ts.map +1 -0
  95. package/dist/harness/runtime/drive/terminal.js +49 -0
  96. package/dist/harness/runtime/drive/terminal.js.map +1 -0
  97. package/dist/harness/runtime/drive/tool-placement.d.ts +14 -0
  98. package/dist/harness/runtime/drive/tool-placement.d.ts.map +1 -0
  99. package/dist/harness/runtime/drive/tool-placement.js +244 -0
  100. package/dist/harness/runtime/drive/tool-placement.js.map +1 -0
  101. package/dist/harness/runtime/drive/tools.d.ts +6 -0
  102. package/dist/harness/runtime/drive/tools.d.ts.map +1 -0
  103. package/dist/harness/runtime/drive/tools.js +449 -0
  104. package/dist/harness/runtime/drive/tools.js.map +1 -0
  105. package/dist/harness/runtime/drive.d.ts +6 -0
  106. package/dist/harness/runtime/drive.d.ts.map +1 -0
  107. package/dist/harness/runtime/drive.js +93 -0
  108. package/dist/harness/runtime/drive.js.map +1 -0
  109. package/dist/harness/runtime/harness.d.ts +59 -0
  110. package/dist/harness/runtime/harness.d.ts.map +1 -0
  111. package/dist/harness/runtime/harness.js +302 -0
  112. package/dist/harness/runtime/harness.js.map +1 -0
  113. package/dist/harness/runtime/index.d.ts +2 -0
  114. package/dist/harness/runtime/index.d.ts.map +1 -0
  115. package/dist/harness/runtime/index.js +2 -0
  116. package/dist/harness/runtime/index.js.map +1 -0
  117. package/dist/harness/runtime/lane.d.ts +118 -0
  118. package/dist/harness/runtime/lane.d.ts.map +1 -0
  119. package/dist/harness/runtime/lane.js +1559 -0
  120. package/dist/harness/runtime/lane.js.map +1 -0
  121. package/dist/harness/runtime/progress.d.ts +15 -0
  122. package/dist/harness/runtime/progress.d.ts.map +1 -0
  123. package/dist/harness/runtime/progress.js +66 -0
  124. package/dist/harness/runtime/progress.js.map +1 -0
  125. package/dist/harness/runtime/reducer.d.ts +5 -0
  126. package/dist/harness/runtime/reducer.d.ts.map +1 -0
  127. package/dist/harness/runtime/reducer.js +240 -0
  128. package/dist/harness/runtime/reducer.js.map +1 -0
  129. package/dist/harness/runtime/restore.d.ts +24 -0
  130. package/dist/harness/runtime/restore.d.ts.map +1 -0
  131. package/dist/harness/runtime/restore.js +117 -0
  132. package/dist/harness/runtime/restore.js.map +1 -0
  133. package/dist/harness/runtime/transcript.d.ts +21 -0
  134. package/dist/harness/runtime/transcript.d.ts.map +1 -0
  135. package/dist/harness/runtime/transcript.js +72 -0
  136. package/dist/harness/runtime/transcript.js.map +1 -0
  137. package/dist/harness/runtime/types.d.ts +105 -0
  138. package/dist/harness/runtime/types.d.ts.map +1 -0
  139. package/dist/harness/runtime/types.js +50 -0
  140. package/dist/harness/runtime/types.js.map +1 -0
  141. package/dist/harness/session/commit.d.ts +53 -0
  142. package/dist/harness/session/commit.d.ts.map +1 -0
  143. package/dist/harness/session/commit.js +57 -0
  144. package/dist/harness/session/commit.js.map +1 -0
  145. package/dist/harness/session/context.d.ts +6 -19
  146. package/dist/harness/session/context.d.ts.map +1 -1
  147. package/dist/harness/session/context.js +31 -53
  148. package/dist/harness/session/context.js.map +1 -1
  149. package/dist/harness/session/fork-policy.d.ts +21 -0
  150. package/dist/harness/session/fork-policy.d.ts.map +1 -0
  151. package/dist/harness/session/fork-policy.js +55 -0
  152. package/dist/harness/session/fork-policy.js.map +1 -0
  153. package/dist/harness/session/fork.d.ts +16 -0
  154. package/dist/harness/session/fork.d.ts.map +1 -0
  155. package/dist/harness/session/fork.js +79 -0
  156. package/dist/harness/session/fork.js.map +1 -0
  157. package/dist/harness/session/in-memory-storage-state.d.ts +39 -0
  158. package/dist/harness/session/in-memory-storage-state.d.ts.map +1 -0
  159. package/dist/harness/session/in-memory-storage-state.js +269 -0
  160. package/dist/harness/session/in-memory-storage-state.js.map +1 -0
  161. package/dist/harness/session/index.d.ts +9 -5
  162. package/dist/harness/session/index.d.ts.map +1 -1
  163. package/dist/harness/session/index.js +7 -4
  164. package/dist/harness/session/index.js.map +1 -1
  165. package/dist/harness/session/jsonl/codec.d.ts +19 -8
  166. package/dist/harness/session/jsonl/codec.d.ts.map +1 -1
  167. package/dist/harness/session/jsonl/codec.js +34 -219
  168. package/dist/harness/session/jsonl/codec.js.map +1 -1
  169. package/dist/harness/session/jsonl/fork.d.ts +38 -0
  170. package/dist/harness/session/jsonl/fork.d.ts.map +1 -0
  171. package/dist/harness/session/jsonl/fork.js +266 -0
  172. package/dist/harness/session/jsonl/fork.js.map +1 -0
  173. package/dist/harness/session/jsonl/index.d.ts +4 -0
  174. package/dist/harness/session/jsonl/index.d.ts.map +1 -0
  175. package/dist/harness/session/jsonl/index.js +4 -0
  176. package/dist/harness/session/jsonl/index.js.map +1 -0
  177. package/dist/harness/session/jsonl/io.d.ts +14 -0
  178. package/dist/harness/session/jsonl/io.d.ts.map +1 -0
  179. package/dist/harness/session/jsonl/io.js +86 -0
  180. package/dist/harness/session/jsonl/io.js.map +1 -0
  181. package/dist/harness/session/jsonl/legacy-v3.d.ts +44 -0
  182. package/dist/harness/session/jsonl/legacy-v3.d.ts.map +1 -0
  183. package/dist/harness/session/jsonl/legacy-v3.js +454 -0
  184. package/dist/harness/session/jsonl/legacy-v3.js.map +1 -0
  185. package/dist/harness/session/jsonl/repo.d.ts +27 -24
  186. package/dist/harness/session/jsonl/repo.d.ts.map +1 -1
  187. package/dist/harness/session/jsonl/repo.js +276 -151
  188. package/dist/harness/session/jsonl/repo.js.map +1 -1
  189. package/dist/harness/session/jsonl/storage.d.ts +39 -41
  190. package/dist/harness/session/jsonl/storage.d.ts.map +1 -1
  191. package/dist/harness/session/jsonl/storage.js +175 -196
  192. package/dist/harness/session/jsonl/storage.js.map +1 -1
  193. package/dist/harness/session/jsonl/types.d.ts +23 -22
  194. package/dist/harness/session/jsonl/types.d.ts.map +1 -1
  195. package/dist/harness/session/jsonl/types.js +2 -1
  196. package/dist/harness/session/jsonl/types.js.map +1 -1
  197. package/dist/harness/session/memory.d.ts +44 -40
  198. package/dist/harness/session/memory.d.ts.map +1 -1
  199. package/dist/harness/session/memory.js +333 -115
  200. package/dist/harness/session/memory.js.map +1 -1
  201. package/dist/harness/session/mutation-line.d.ts +8 -0
  202. package/dist/harness/session/mutation-line.d.ts.map +1 -0
  203. package/dist/harness/session/mutation-line.js +22 -0
  204. package/dist/harness/session/mutation-line.js.map +1 -0
  205. package/dist/harness/session/session.d.ts +78 -51
  206. package/dist/harness/session/session.d.ts.map +1 -1
  207. package/dist/harness/session/session.js +327 -207
  208. package/dist/harness/session/session.js.map +1 -1
  209. package/dist/harness/session/testing/benchmark/datasets.d.ts +12 -0
  210. package/dist/harness/session/testing/benchmark/datasets.d.ts.map +1 -0
  211. package/dist/harness/session/testing/benchmark/datasets.js +24 -0
  212. package/dist/harness/session/testing/benchmark/datasets.js.map +1 -0
  213. package/dist/harness/session/testing/benchmark/session-repo.d.ts +42 -0
  214. package/dist/harness/session/testing/benchmark/session-repo.d.ts.map +1 -0
  215. package/dist/harness/session/testing/benchmark/session-repo.js +127 -0
  216. package/dist/harness/session/testing/benchmark/session-repo.js.map +1 -0
  217. package/dist/harness/session/testing/benchmark/storage.d.ts +25 -0
  218. package/dist/harness/session/testing/benchmark/storage.d.ts.map +1 -0
  219. package/dist/harness/session/testing/benchmark/storage.js +114 -0
  220. package/dist/harness/session/testing/benchmark/storage.js.map +1 -0
  221. package/dist/harness/session/testing/conformance/session-repo.d.ts +23 -0
  222. package/dist/harness/session/testing/conformance/session-repo.d.ts.map +1 -0
  223. package/dist/harness/session/testing/conformance/session-repo.js +809 -0
  224. package/dist/harness/session/testing/conformance/session-repo.js.map +1 -0
  225. package/dist/harness/session/testing/conformance/storage.d.ts +4 -0
  226. package/dist/harness/session/testing/conformance/storage.d.ts.map +1 -0
  227. package/dist/harness/session/testing/conformance/storage.js +600 -0
  228. package/dist/harness/session/testing/conformance/storage.js.map +1 -0
  229. package/dist/harness/session/testing/gating-storage.d.ts +26 -0
  230. package/dist/harness/session/testing/gating-storage.d.ts.map +1 -0
  231. package/dist/harness/session/testing/gating-storage.js +103 -0
  232. package/dist/harness/session/testing/gating-storage.js.map +1 -0
  233. package/dist/harness/session/testing/index.d.ts +9 -2
  234. package/dist/harness/session/testing/index.d.ts.map +1 -1
  235. package/dist/harness/session/testing/index.js +8 -1
  236. package/dist/harness/session/testing/index.js.map +1 -1
  237. package/dist/harness/session/testing/instrumented-storage.d.ts +11 -0
  238. package/dist/harness/session/testing/instrumented-storage.d.ts.map +1 -0
  239. package/dist/harness/session/testing/instrumented-storage.js +19 -0
  240. package/dist/harness/session/testing/instrumented-storage.js.map +1 -0
  241. package/dist/harness/session/testing/storage-decorator.d.ts +20 -0
  242. package/dist/harness/session/testing/storage-decorator.d.ts.map +1 -0
  243. package/dist/harness/session/testing/storage-decorator.js +40 -0
  244. package/dist/harness/session/testing/storage-decorator.js.map +1 -0
  245. package/dist/harness/session/testing/types.d.ts +5 -7
  246. package/dist/harness/session/testing/types.d.ts.map +1 -1
  247. package/dist/harness/session/testing/types.js.map +1 -1
  248. package/dist/harness/session/types.d.ts +425 -265
  249. package/dist/harness/session/types.d.ts.map +1 -1
  250. package/dist/harness/session/types.js +7 -7
  251. package/dist/harness/session/types.js.map +1 -1
  252. package/dist/harness/session/values.d.ts +95 -0
  253. package/dist/harness/session/values.d.ts.map +1 -0
  254. package/dist/harness/session/values.js +81 -0
  255. package/dist/harness/session/values.js.map +1 -0
  256. package/dist/harness/skills.d.ts +3 -2
  257. package/dist/harness/skills.d.ts.map +1 -1
  258. package/dist/harness/skills.js +29 -26
  259. package/dist/harness/skills.js.map +1 -1
  260. package/dist/harness/telemetry.d.ts +64 -43
  261. package/dist/harness/telemetry.d.ts.map +1 -1
  262. package/dist/harness/telemetry.js +45 -26
  263. package/dist/harness/telemetry.js.map +1 -1
  264. package/dist/harness/tools/bash.d.ts +4 -4
  265. package/dist/harness/tools/bash.d.ts.map +1 -1
  266. package/dist/harness/tools/bash.js +66 -93
  267. package/dist/harness/tools/bash.js.map +1 -1
  268. package/dist/harness/tools/edit.d.ts.map +1 -1
  269. package/dist/harness/tools/edit.js +17 -13
  270. package/dist/harness/tools/edit.js.map +1 -1
  271. package/dist/harness/tools/file-mutation-queue.d.ts +2 -1
  272. package/dist/harness/tools/file-mutation-queue.d.ts.map +1 -1
  273. package/dist/harness/tools/file-mutation-queue.js +5 -5
  274. package/dist/harness/tools/file-mutation-queue.js.map +1 -1
  275. package/dist/harness/tools/path-utils.d.ts +3 -2
  276. package/dist/harness/tools/path-utils.d.ts.map +1 -1
  277. package/dist/harness/tools/path-utils.js +5 -5
  278. package/dist/harness/tools/path-utils.js.map +1 -1
  279. package/dist/harness/tools/read.d.ts +2 -1
  280. package/dist/harness/tools/read.d.ts.map +1 -1
  281. package/dist/harness/tools/read.js +4 -6
  282. package/dist/harness/tools/read.js.map +1 -1
  283. package/dist/harness/tools/write.d.ts.map +1 -1
  284. package/dist/harness/tools/write.js +12 -8
  285. package/dist/harness/tools/write.js.map +1 -1
  286. package/dist/harness/types.d.ts +128 -45
  287. package/dist/harness/types.d.ts.map +1 -1
  288. package/dist/harness/types.js.map +1 -1
  289. package/dist/harness/utils/adaptive-publisher.d.ts +24 -0
  290. package/dist/harness/utils/adaptive-publisher.d.ts.map +1 -0
  291. package/dist/harness/utils/adaptive-publisher.js +79 -0
  292. package/dist/harness/utils/adaptive-publisher.js.map +1 -0
  293. package/dist/harness/utils/output-capture.d.ts +31 -0
  294. package/dist/harness/utils/output-capture.d.ts.map +1 -0
  295. package/dist/harness/utils/output-capture.js +217 -0
  296. package/dist/harness/utils/output-capture.js.map +1 -0
  297. package/dist/harness/utils/shell-output.d.ts +19 -5
  298. package/dist/harness/utils/shell-output.d.ts.map +1 -1
  299. package/dist/harness/utils/shell-output.js +65 -192
  300. package/dist/harness/utils/shell-output.js.map +1 -1
  301. package/dist/harness/utils/truncate.d.ts +1 -0
  302. package/dist/harness/utils/truncate.d.ts.map +1 -1
  303. package/dist/harness/utils/truncate.js +1 -1
  304. package/dist/harness/utils/truncate.js.map +1 -1
  305. package/dist/harness/utils/usage.d.ts +4 -0
  306. package/dist/harness/utils/usage.d.ts.map +1 -0
  307. package/dist/harness/utils/usage.js +33 -0
  308. package/dist/harness/utils/usage.js.map +1 -0
  309. package/dist/index.d.ts +4 -1
  310. package/dist/index.d.ts.map +1 -1
  311. package/dist/index.js +3 -6
  312. package/dist/index.js.map +1 -1
  313. package/dist/search/index.d.ts +24 -16
  314. package/dist/search/index.d.ts.map +1 -1
  315. package/dist/search/index.js +1 -1
  316. package/dist/search/index.js.map +1 -1
  317. package/dist/types.d.ts +2 -0
  318. package/dist/types.d.ts.map +1 -1
  319. package/dist/types.js.map +1 -1
  320. package/package.json +27 -6
  321. package/dist/harness/reducer.d.ts +0 -100
  322. package/dist/harness/reducer.d.ts.map +0 -1
  323. package/dist/harness/reducer.js +0 -420
  324. package/dist/harness/reducer.js.map +0 -1
  325. package/dist/harness/session/jsonl/errors.d.ts +0 -9
  326. package/dist/harness/session/jsonl/errors.d.ts.map +0 -1
  327. package/dist/harness/session/jsonl/errors.js +0 -18
  328. package/dist/harness/session/jsonl/errors.js.map +0 -1
  329. package/dist/harness/session/jsonl.d.ts +0 -3
  330. package/dist/harness/session/jsonl.d.ts.map +0 -1
  331. package/dist/harness/session/jsonl.js +0 -2
  332. package/dist/harness/session/jsonl.js.map +0 -1
  333. package/dist/harness/session/state.d.ts +0 -65
  334. package/dist/harness/session/state.d.ts.map +0 -1
  335. package/dist/harness/session/state.js +0 -320
  336. package/dist/harness/session/state.js.map +0 -1
  337. package/dist/harness/session/testing/conformance.d.ts +0 -4
  338. package/dist/harness/session/testing/conformance.d.ts.map +0 -1
  339. package/dist/harness/session/testing/conformance.js +0 -762
  340. package/dist/harness/session/testing/conformance.js.map +0 -1
  341. package/dist/search/scanning.d.ts +0 -29
  342. package/dist/search/scanning.d.ts.map +0 -1
  343. package/dist/search/scanning.js +0 -103
  344. package/dist/search/scanning.js.map +0 -1
@@ -1,352 +1,512 @@
1
- import type { StopReason, Usage } from "@earendil-works/pi-ai";
2
- import "../messages.ts";
3
- import type { AgentMessage } from "../../types.ts";
4
- import type { Session } from "./session.ts";
5
- export type JsonValue = null | boolean | number | string | JsonValue[] | {
6
- [key: string]: JsonValue;
1
+ import type { JsonValue } from "@earendil-works/chord";
2
+ import type { AssistantMessage, StopReason, Usage } from "@earendil-works/pi-ai";
3
+ import type { AgentMessage, QueueMode, ThinkingLevel } from "../../types.ts";
4
+ import type { BranchPreparation } from "../compaction/branch-summarization.ts";
5
+ import type { CompactionPreparation, CompactionSettings } from "../compaction/compaction.ts";
6
+ import type { Context } from "../context.ts";
7
+ import type { AgentHarnessStreamOptions } from "../types.ts";
8
+ import type { ListElement, ListReadOptions, ListWrite, StoredValue, Value, ValueList, ValueWrite } from "./values.ts";
9
+ export type { JsonValue } from "@earendil-works/chord";
10
+ export type SettledAssistantMessage = AssistantMessage & {
11
+ stopReason: Exclude<StopReason, "pending">;
7
12
  };
8
- export type SessionStopReason = Exclude<StopReason, "pending"> | "deferred";
9
- export interface IdGenerator {
10
- next(): string;
11
- }
13
+ export type EntryType = "message" | "compaction" | "branch_summary" | "custom";
12
14
  export interface EntryBase {
13
- type: string;
14
15
  id: string;
15
- seq: number;
16
16
  parentId: string | null;
17
+ seq: number;
17
18
  timestamp: number;
19
+ type: EntryType;
20
+ customType?: string;
18
21
  }
19
22
  export interface MessageEntry extends EntryBase {
20
23
  type: "message";
21
24
  message: AgentMessage;
22
25
  terminate?: true;
23
26
  }
24
- export interface ModelChangeEntry extends EntryBase {
25
- type: "model_change";
26
- provider: string;
27
- modelId: string;
28
- }
29
- export interface ThinkingLevelEntry extends EntryBase {
30
- type: "thinking_level_change";
31
- thinkingLevel: string;
32
- }
33
- export interface ConfigurationUpdateEntry extends EntryBase {
34
- type: "configuration_update";
35
- reasoning: {
36
- effort: string;
37
- };
38
- }
39
- export interface ActiveToolsEntry extends EntryBase {
40
- type: "active_tools_change";
41
- activeToolNames: string[];
42
- }
43
27
  export interface CompactionEntry extends EntryBase {
44
28
  type: "compaction";
45
29
  summary: string;
46
30
  retainedTail: AgentMessage[];
47
31
  tokensBefore: number;
48
- details?: unknown;
32
+ details?: JsonValue;
49
33
  usage?: Usage;
34
+ fromHook: boolean;
50
35
  }
51
36
  export interface BranchSummaryEntry extends EntryBase {
52
37
  type: "branch_summary";
53
- fromId: string;
38
+ fromId: string | null;
54
39
  summary: string;
55
- details?: unknown;
40
+ details?: JsonValue;
56
41
  usage?: Usage;
42
+ fromHook: boolean;
57
43
  }
58
44
  export interface CustomEntry extends EntryBase {
59
45
  type: "custom";
60
46
  customType: string;
61
- data?: unknown;
47
+ data?: JsonValue;
62
48
  }
63
- export type Entry = MessageEntry | ModelChangeEntry | ThinkingLevelEntry | ConfigurationUpdateEntry | ActiveToolsEntry | CompactionEntry | BranchSummaryEntry | CustomEntry;
64
- export type ProvisionedEntry<TEntry extends Entry = Entry> = TEntry extends Entry ? Omit<TEntry, "parentId" | "seq" | "timestamp"> : never;
65
- export interface RecordBase {
66
- id: string;
67
- seq: number;
68
- lane: string;
69
- timestamp: number;
49
+ /** Convert an application-defined custom entry into model context. */
50
+ export type EntryProjector = (entry: CustomEntry, context: Context) => AgentMessage[] | undefined | Promise<AgentMessage[] | undefined>;
51
+ export type Entry = MessageEntry | CompactionEntry | BranchSummaryEntry | CustomEntry;
52
+ /** Entry supplied to a transaction before storage assigns sequence and timestamp. */
53
+ export type NewEntry<TEntry extends Entry = Entry> = TEntry extends Entry ? Omit<TEntry, "seq" | "timestamp"> : never;
54
+ export interface LaneConfiguration {
55
+ model: {
56
+ provider: string;
57
+ modelId: string;
58
+ };
59
+ thinkingLevel: ThinkingLevel;
60
+ activeToolNames: string[];
70
61
  }
71
- export interface OperationStartedRecord extends RecordBase {
72
- type: "operation_started";
73
- sourceLeafId: string | null;
62
+ export interface OperationMeta {
63
+ operationId: string;
64
+ lane: string;
65
+ sourceTipId: string | null;
66
+ startedAt: number;
74
67
  intent: {
75
68
  kind: "run";
76
- /** Normalized caller input before before_run; kept for suspended operations and before_resume. */
77
- originalPrompt: AgentMessage[];
78
- /** Captured nextRun items, then the prompt, then before_run injections. */
79
- initialMessages: ProvisionedEntry[];
80
- systemPromptOverride?: string;
81
- resumeData?: {
82
- [extensionId: string]: JsonValue;
83
- };
69
+ promptEntryIds: string[];
84
70
  } | {
85
71
  kind: "compaction";
86
72
  customInstructions?: string;
87
- resultEntryId: string;
88
73
  } | {
89
74
  kind: "navigation";
90
75
  targetId: string | null;
91
76
  summarize: boolean;
92
- customInstructions?: string;
93
77
  label?: string;
94
- summaryEntryId?: string;
78
+ customInstructions?: string;
95
79
  };
96
80
  }
97
- export interface AbortRequestedRecord extends RecordBase {
98
- type: "abort_requested";
99
- runId: string;
100
- }
101
- export interface OperationFinishedRecord extends RecordBase {
102
- type: "operation_finished";
103
- runId: string;
104
- outcome: "completed" | "aborted" | "failed" | "declined";
105
- error?: {
106
- code: string;
107
- message: string;
108
- };
81
+ export type Control = {
82
+ status: "running";
83
+ } | {
84
+ status: "cancel_requested";
85
+ requestedAt: number;
86
+ };
87
+ export interface OperationError {
88
+ code: string;
89
+ message: string;
90
+ details?: JsonValue;
109
91
  }
110
- export type CompactionReason = "manual" | "threshold" | "overflow";
111
- export type StepAttemptRecord = RecordBase & ({
112
- type: "step_attempt";
113
- runId: string;
114
- step: "assistant" | "branch_summary";
115
- attempt: number;
116
- resultEntryId: string;
117
- compactionReason?: never;
92
+ export type TerminalStatus = "completed" | "declined" | "aborted" | "failed";
93
+ /** Immutable lane-lived observation record written by one terminal transaction. */
94
+ export interface OperationResultRecord {
95
+ operationId: string;
96
+ kind: OperationMeta["intent"]["kind"];
97
+ status: TerminalStatus;
98
+ error?: OperationError;
99
+ fromTipId: string | null;
100
+ tipId: string | null;
101
+ startedAt: number;
102
+ endedAt: number;
103
+ }
104
+ export type Continuation = {
105
+ kind: "need_assistant";
106
+ overflowRecoveryUsed: boolean;
118
107
  } | {
119
- type: "step_attempt";
120
- runId: string;
121
- step: "compaction";
122
- attempt: number;
108
+ kind: "may_finish";
109
+ includeFinalAssistant: boolean;
110
+ };
111
+ /** Checkpoint payload; the flat leaf literal replaces the old nested phase tag. */
112
+ export interface CheckpointData {
113
+ continuation: Continuation;
114
+ triggerEntryId: string;
115
+ }
116
+ export type InboxItemKind = "steer" | "followUp" | "nextRun" | "write";
117
+ export interface InboxItem {
118
+ entryId: string;
119
+ kind: InboxItemKind;
120
+ }
121
+ export interface NormalizedRetryPolicy {
122
+ maxAttempts: number;
123
+ baseDelayMs: number;
124
+ maxAgentDelayMs: number;
125
+ }
126
+ export interface GenerationContext {
127
+ stepId: string;
128
+ triggerEntryId: string;
129
+ configuration: LaneConfiguration;
130
+ streamOptions: AgentHarnessStreamOptions;
131
+ retryPolicy: NormalizedRetryPolicy;
132
+ overflowRecoveryUsed: boolean;
133
+ }
134
+ interface ToolCallSource {
135
+ /** Zero-based index in the assistant message's complete content array, not a filtered tool-call ordinal. */
136
+ sourceIndex: number;
123
137
  resultEntryId: string;
124
- /** Persists why compaction summary generation started so recovery resumes the same work. */
125
- compactionReason: CompactionReason;
138
+ }
139
+ export type ToolCall = ToolCallSource & ({
140
+ status: "planned";
141
+ } | {
142
+ status: "effect_pending";
143
+ replay: "never" | "safe";
144
+ } | {
145
+ status: "outcome_ready";
146
+ terminate: boolean;
147
+ } | {
148
+ status: "completed";
149
+ terminate: boolean;
126
150
  });
127
- export interface ToolStartedRecord extends RecordBase {
128
- type: "tool_started";
129
- runId: string;
151
+ export interface ToolBatch {
130
152
  assistantEntryId: string;
131
- toolIndex: number;
132
- toolCallId: string;
133
- toolName: string;
134
- effectiveArgs: {
135
- [key: string]: unknown;
136
- };
153
+ configuration: LaneConfiguration;
154
+ turnId: string;
155
+ calls: ToolCall[];
156
+ }
157
+ export interface SummaryContext {
137
158
  resultEntryId: string;
138
- replay: "never" | "safe";
159
+ configuration: LaneConfiguration;
160
+ streamOptions: AgentHarnessStreamOptions;
161
+ retryPolicy: NormalizedRetryPolicy;
162
+ }
163
+ export interface Cancellable {
164
+ control: Control;
165
+ }
166
+ export interface RunSettings {
167
+ compaction: CompactionSettings;
168
+ steeringMode: QueueMode;
169
+ followUpMode: QueueMode;
170
+ toolExecution: "sequential" | "parallel";
171
+ }
172
+ /** Uniform scope carried by every operation leaf. */
173
+ export interface OperationScope extends Cancellable {
174
+ settings: RunSettings;
175
+ latestAssistantEntryId: string | null;
176
+ }
177
+ /** Shared backoff data for every retry-wait leaf. */
178
+ export interface RetryWait {
179
+ nextAttempt: number;
180
+ notBefore: number;
181
+ errorMessage: string;
182
+ }
183
+ export interface AssistantGenerationScope {
184
+ generationContext: GenerationContext;
139
185
  }
140
- export type QueueEnqueuedRecord = RecordBase & ({
141
- type: "queue_enqueued";
142
- queue: "steer" | "followUp";
143
- runId: string;
144
- target: ProvisionedEntry;
186
+ export type ResultBoundary = {
187
+ kind: "resume_checkpoint";
188
+ resumeAfter: CheckpointData;
145
189
  } | {
146
- type: "queue_enqueued";
147
- queue: "nextRun";
148
- runId?: never;
149
- target: ProvisionedEntry;
150
- });
151
- export interface QueueCancelledRecord extends RecordBase {
152
- type: "queue_cancelled";
153
- runId?: string;
154
- entryId: string;
190
+ kind: "finish";
191
+ } | {
192
+ kind: "commit_navigation";
193
+ targetId: string;
194
+ label?: string;
195
+ };
196
+ export interface SummaryTask {
197
+ taskId: string;
198
+ reason?: "manual" | "threshold" | "overflow";
199
+ customInstructions?: string;
200
+ boundary: ResultBoundary;
155
201
  }
156
- export interface WriteDeferredRecord extends RecordBase {
157
- type: "write_deferred";
158
- runId: string;
159
- target: ProvisionedEntry;
202
+ export interface SummaryGenerationScope {
203
+ task: SummaryTask;
204
+ summaryContext: SummaryContext;
160
205
  }
161
- export type UsageRecord = RecordBase & {
162
- type: "usage";
163
- usage: Usage;
164
- } & ({
165
- cause: "assistant" | "compaction" | "branch_summary" | "deferred_fetch";
166
- runId: string;
167
- entryId: string;
206
+ export interface SummaryGenerationReady extends SummaryGenerationScope {
207
+ nextAttempt: number;
208
+ }
209
+ export interface SummaryGenerationEffectPending extends SummaryGenerationScope {
168
210
  attempt: number;
169
- stopReason: SessionStopReason;
170
- } | {
171
- cause: "tool";
172
- runId: string;
173
- entryId: string;
174
- toolCallId: string;
211
+ request?: {
212
+ index: number;
213
+ usageId: string;
214
+ };
215
+ usageIds: string[];
216
+ }
217
+ export interface SummaryGenerationRetryWait extends SummaryGenerationScope, RetryWait {
218
+ }
219
+ export interface DeferredScope extends OperationScope {
220
+ stepId: string;
221
+ sourceEntryId: string;
222
+ poll: number;
223
+ configuration: LaneConfiguration;
224
+ streamOptions: AgentHarnessStreamOptions;
225
+ }
226
+ export interface StartingOperation extends OperationScope {
227
+ at: "starting";
228
+ }
229
+ export interface CheckpointOperation extends OperationScope, CheckpointData {
230
+ at: "checkpoint";
231
+ }
232
+ export interface AssistantReadyOperation extends OperationScope, AssistantGenerationScope {
233
+ at: "assistant.ready";
234
+ nextAttempt: number;
235
+ }
236
+ export interface AssistantEffectPendingOperation extends OperationScope, AssistantGenerationScope {
237
+ at: "assistant.effect_pending";
238
+ attempt: number;
239
+ responseEntryId: string;
240
+ usageId: string;
241
+ intendedOutputLimit: number;
242
+ contextWindow: number;
243
+ }
244
+ export interface AssistantRetryWaitOperation extends OperationScope, AssistantGenerationScope, RetryWait {
245
+ at: "assistant.retry_wait";
246
+ }
247
+ export interface ToolsOperation extends OperationScope {
248
+ at: "tools";
249
+ batch: ToolBatch;
250
+ }
251
+ export interface DeferredSuspendedOperation extends DeferredScope {
252
+ at: "deferred.suspended";
253
+ }
254
+ export interface DeferredEffectPendingOperation extends DeferredScope {
255
+ at: "deferred.effect_pending";
256
+ responseEntryId: string;
257
+ usageId: string;
258
+ }
259
+ export interface SummaryDecidingOperation extends OperationScope {
260
+ at: "summary.deciding";
261
+ task: SummaryTask;
262
+ }
263
+ export interface SummaryReadyOperation extends OperationScope, SummaryGenerationReady {
264
+ at: "summary.ready";
265
+ }
266
+ export interface SummaryEffectPendingOperation extends OperationScope, SummaryGenerationEffectPending {
267
+ at: "summary.effect_pending";
268
+ }
269
+ export interface SummaryRetryWaitOperation extends OperationScope, SummaryGenerationRetryWait {
270
+ at: "summary.retry_wait";
271
+ }
272
+ export interface NavigationReadyToCommitOperation extends OperationScope {
273
+ at: "navigation.ready_to_commit";
274
+ /** Unsummarized navigation may target the branch root (null). */
275
+ targetId: string | null;
276
+ label?: string;
277
+ }
278
+ /** Flat durable operation state: exactly 13 family-neutral dispatcher leaves. */
279
+ export type OperationState = StartingOperation | CheckpointOperation | AssistantReadyOperation | AssistantEffectPendingOperation | AssistantRetryWaitOperation | ToolsOperation | DeferredSuspendedOperation | DeferredEffectPendingOperation | SummaryDecidingOperation | SummaryReadyOperation | SummaryEffectPendingOperation | SummaryRetryWaitOperation | NavigationReadyToCommitOperation;
280
+ export type OperationAt = OperationState["at"];
281
+ /** Copy only the uniform operation scope when constructing a successor leaf. */
282
+ export declare function operationScopeOf(state: OperationState): OperationScope;
283
+ export type Operation = {
284
+ meta: OperationMeta;
285
+ state: OperationState;
286
+ };
287
+ export interface LaneState {
288
+ currentOperationId: string | null;
289
+ lastOperationId: string | null;
290
+ inbox: InboxItem[];
291
+ }
292
+ export type PendingEntry = {
293
+ type: "message";
294
+ payload: AgentMessage;
175
295
  } | {
176
- cause: "hook";
177
- runId: string;
178
- entryId: string;
296
+ type: "custom";
297
+ customType: string;
298
+ payload?: JsonValue;
299
+ };
300
+ export interface DurableFileOperations {
301
+ read: string[];
302
+ written: string[];
303
+ edited: string[];
304
+ }
305
+ export type DurableStructuralPreparation = {
306
+ kind: "compaction";
307
+ messagesToSummarize: CompactionPreparation["messagesToSummarize"];
308
+ turnPrefixMessages: CompactionPreparation["turnPrefixMessages"];
309
+ retainedTail: CompactionPreparation["retainedTail"];
310
+ isSplitTurn: boolean;
311
+ tokensBefore: number;
312
+ previousSummary?: string;
313
+ fileOps: DurableFileOperations;
314
+ settings: CompactionSettings;
179
315
  } | {
180
- cause: "adjustment";
181
- runId?: string;
316
+ kind: "branch_summary";
317
+ messages: BranchPreparation["messages"];
318
+ fileOps: DurableFileOperations;
319
+ totalTokens: number;
320
+ };
321
+ export interface UsageRow {
322
+ id: string;
323
+ seq: number;
324
+ usage: Usage;
182
325
  entryId?: string;
326
+ adjustment: boolean;
183
327
  details?: JsonValue;
184
- });
185
- export type LaneRecord = OperationStartedRecord | AbortRequestedRecord | OperationFinishedRecord | StepAttemptRecord | ToolStartedRecord | QueueEnqueuedRecord | QueueCancelledRecord | WriteDeferredRecord | UsageRecord;
186
- export type NewRecord<TRecord extends LaneRecord = LaneRecord> = TRecord extends LaneRecord ? Omit<TRecord, "seq" | "timestamp"> : never;
187
- export type EntryOrder = "newestFirst" | "oldestFirst";
328
+ }
329
+ export interface EntryWrite {
330
+ kind: "entry";
331
+ entry: NewEntry;
332
+ }
333
+ export interface UsageWrite {
334
+ kind: "usage";
335
+ row: Omit<UsageRow, "seq">;
336
+ }
337
+ export type Write = EntryWrite | UsageWrite | ValueWrite | ListWrite;
338
+ export interface CommitResult {
339
+ firstSeq: number;
340
+ seqs: number[];
341
+ timestamp: number;
342
+ /** Session totals immediately after this commit was applied. */
343
+ stats: SessionStats;
344
+ }
345
+ export interface EntryStructure {
346
+ id: string;
347
+ parentId: string | null;
348
+ seq: number;
349
+ timestamp: number;
350
+ type: EntryType;
351
+ customType?: string;
352
+ }
188
353
  export interface EntryCursor {
189
- afterSeq: number;
354
+ seq: number;
190
355
  }
191
- export interface EntryQuery {
192
- type?: Entry["type"];
356
+ export interface BranchScan {
357
+ start?: string;
358
+ stopAtType?: EntryType;
359
+ stopAtId?: string;
360
+ type?: EntryType;
193
361
  customType?: string;
194
- order?: EntryOrder;
362
+ order?: "newestFirst" | "oldestFirst";
195
363
  limit?: number;
196
364
  cursor?: EntryCursor;
197
365
  }
198
- /** Bounds of a branch scan. Default: the whole path, leaf to root. */
199
- export interface BranchBounds {
200
- start?: string;
201
- stopAtType?: Entry["type"];
202
- stopAtId?: string;
366
+ export type StorageBranchScan = BranchScan & {
367
+ start: string;
368
+ };
369
+ export interface EntryScan {
370
+ type?: EntryType;
371
+ customType?: string;
372
+ fromSeq?: number;
373
+ toSeq?: number;
374
+ order?: "asc" | "desc";
375
+ limit?: number;
203
376
  }
204
- export interface RecordQuery {
205
- /** Exact lane match. Omit to query every lane. */
206
- lane?: string;
207
- /** Exact record discriminant match. Omit to query every record type. */
208
- type?: LaneRecord["type"];
209
- /**
210
- * Operation identity. Matches OperationStartedRecord.id and the runId
211
- * property of operation-owned records. Records without an operation
212
- * identity do not match.
213
- */
214
- runId?: string;
215
- /** Exact operation intent kind. Valid only with type "operation_started". */
216
- operationKind?: OperationStartedRecord["intent"]["kind"];
217
- /** Exclusive chronological lower bound: seq > afterSeq, regardless of order. */
218
- afterSeq?: number;
219
- /** Sequence order. Default: "newestFirst". */
220
- order?: EntryOrder;
221
- /** Positive maximum number of matching records. */
377
+ export interface UsageScan {
378
+ fromSeq?: number;
379
+ toSeq?: number;
380
+ order?: "asc" | "desc";
222
381
  limit?: number;
223
382
  }
383
+ export interface SessionStats {
384
+ messageCount: number;
385
+ usage: Usage;
386
+ }
387
+ export interface Storage {
388
+ commit(writes: Write[], context: Context): Promise<CommitResult>;
389
+ getEntries(ids: string[], context: Context): Promise<Map<string, Entry>>;
390
+ getValue<T>(address: Value<T>, context: Context): Promise<StoredValue<T> | undefined>;
391
+ scanValues<T>(prefix: Value<T>, context: Context): Promise<StoredValue<T>[]>;
392
+ readList<T>(address: ValueList<T>, options: ListReadOptions | undefined, context: Context): Promise<ListElement<T>[]>;
393
+ scanBranch(query: StorageBranchScan, context: Context): Promise<Entry[]>;
394
+ scanBranchStructure(query: StorageBranchScan, context: Context): Promise<EntryStructure[]>;
395
+ scanEntries(query: EntryScan, context: Context): Promise<Entry[]>;
396
+ scanUsage(query: UsageScan, context: Context): Promise<UsageRow[]>;
397
+ getStats(context: Context): Promise<SessionStats>;
398
+ close(context: Context): Promise<void>;
399
+ }
224
400
  export interface SessionMetadata {
225
401
  id: string;
226
402
  createdAt: number;
403
+ storageVersion: number;
404
+ cwd?: string;
227
405
  parentSessionId?: string;
406
+ legacyParentSessionPath?: string;
228
407
  }
229
- export interface SessionStats {
230
- messageCount: number;
231
- cachedTokens: number;
232
- uncachedTokens: number;
233
- totalTokens: number;
234
- costTotal: number;
235
- }
236
- export interface LanePointer {
237
- lane: string;
238
- leafId: string | null;
408
+ export interface IdGenerator {
409
+ next(timestampMs?: number): string;
239
410
  }
240
- export type LogItem = {
241
- kind: "entry";
242
- seq: number;
243
- entry: Entry;
244
- } | {
245
- kind: "record";
246
- seq: number;
247
- record: LaneRecord;
248
- } | {
249
- kind: "lane";
250
- seq: number;
251
- lane: string;
252
- leafId: string | null;
253
- } | {
254
- kind: "fact";
255
- seq: number;
256
- fact: "name";
257
- name: string | undefined;
258
- } | {
259
- kind: "fact";
260
- seq: number;
261
- fact: "label";
262
- targetId: string;
263
- label: string | undefined;
264
- };
265
- export interface LogOptions {
266
- afterSeq?: number;
411
+ export interface EntryQuery {
412
+ type?: EntryType;
413
+ customType?: string;
414
+ order?: "asc" | "desc";
267
415
  limit?: number;
416
+ cursor?: EntryCursor;
417
+ }
418
+ export interface SessionReader {
419
+ getEntries(ids: string[], context: Context): Promise<Map<string, Entry>>;
420
+ getStats(context: Context): Promise<SessionStats>;
421
+ getValue<T>(address: Value<T>, context: Context): Promise<StoredValue<T> | undefined>;
422
+ scanValues<T>(prefix: Value<T>, context: Context): Promise<StoredValue<T>[]>;
423
+ readList<T>(address: ValueList<T>, options: ListReadOptions | undefined, context: Context): Promise<ListElement<T>[]>;
424
+ /** Scan a branch from an explicit entry while this reader capability remains valid. */
425
+ scanBranch(query: StorageBranchScan, context: Context): Promise<Entry[]>;
426
+ }
427
+ /** Exclusive keyless mutation barrier for one Session. */
428
+ export interface SessionMutation extends SessionReader {
429
+ /** Exactly zero or one commit attempt. A second attempt rejects. */
430
+ commit(writes: Write[], context: Context): Promise<CommitResult>;
431
+ /** Wait for any commit attempt, invalidate the capability, and release the barrier. */
432
+ end(context: Context): Promise<void>;
268
433
  }
269
- export interface SessionStorage<TMetadata extends SessionMetadata = SessionMetadata> {
270
- getMetadata(): Promise<TMetadata>;
271
- getLanes(): Promise<{
272
- lane: string;
273
- leafId: string | null;
274
- }[]>;
275
- createLane(lane: string, at: string | null): Promise<void>;
276
- moveLane(lane: string, to: string | null): Promise<void>;
277
- appendEntry<TEntry extends Entry>(entry: ProvisionedEntry<TEntry>, lane: string): Promise<TEntry>;
278
- appendRecord<TRecord extends LaneRecord>(record: NewRecord<TRecord>): Promise<TRecord>;
279
- getEntry(id: string): Promise<Entry | undefined>;
280
- findEntries(query?: EntryQuery): Promise<Entry[]>;
281
- /** start is mandatory here (as opposed to SessionTree's findEntriesOnBranch); defaulting to a lane's leaf is view sugar. */
282
- findEntriesOnBranch(query: EntryQuery & BranchBounds & {
283
- start: string;
284
- }): Promise<Entry[]>;
285
- findRecords<K extends LaneRecord["type"]>(query: RecordQuery & {
286
- type: K;
287
- }): Promise<Extract<LaneRecord, {
288
- type: K;
289
- }>[]>;
290
- findRecords(query?: RecordQuery): Promise<LaneRecord[]>;
434
+ /** Callback-scoped mutation capability without authority to release its Session barrier. */
435
+ export type SessionMutator = Omit<SessionMutation, "end">;
436
+ export type SessionMutationCallback<T> = (mutator: SessionMutator, context: Context) => T | Promise<T>;
437
+ export interface Branch {
438
+ readonly name: string;
439
+ getTipId(context: Context): Promise<string | null>;
440
+ findEntries(query: BranchScan | undefined, context: Context): Promise<Entry[]>;
441
+ findEntry(query: BranchScan | undefined, context: Context): Promise<Entry | undefined>;
442
+ appendMessage(message: AgentMessage, context: Context): Promise<string>;
443
+ appendCustomEntry(customType: string, data: JsonValue | undefined, context: Context): Promise<string>;
444
+ }
445
+ export interface Session<TMetadata extends SessionMetadata = SessionMetadata> extends SessionReader {
446
+ readonly metadata: TMetadata;
447
+ readonly idGenerator: IdGenerator;
448
+ getEntry(id: string, context: Context): Promise<Entry | undefined>;
449
+ getStats(context: Context): Promise<SessionStats>;
450
+ getName(context: Context): Promise<string | undefined>;
451
+ getLabel(targetId: string, context: Context): Promise<string | undefined>;
452
+ findEntries(query: EntryQuery | undefined, context: Context): Promise<Entry[]>;
453
+ findEntry(query: EntryQuery | undefined, context: Context): Promise<Entry | undefined>;
454
+ branch(name: string, context: Context): Promise<Branch | undefined>;
455
+ createBranch(name: string, at: string | null, context: Context): Promise<Branch>;
456
+ beginMutation(context: Context): Promise<SessionMutation>;
291
457
  /**
292
- * Returns unfinished operation starts newest first. Recovery uses `limit: 2`:
293
- * zero results mean the lane is idle, one means it is suspended, and two
294
- * mean at least two operations are open, which is corruption. Further
295
- * results provide no additional recovery state.
458
+ * Trusted exclusive callback over the Session mutation line. Calling a public Session writer from
459
+ * this callback queues it behind the callback; awaiting that nested writer therefore deadlocks.
460
+ * Use the supplied mutator for the callback's sole commit.
296
461
  */
297
- findOpenOperations(lane: string, options?: {
298
- limit?: number;
299
- }): Promise<OperationStartedRecord[]>;
300
- getLog(options?: {
301
- afterSeq?: number;
302
- limit?: number;
303
- }): Promise<LogItem[]>;
304
- getName(): Promise<string | undefined>;
305
- setName(name: string | undefined): Promise<void>;
306
- getLabel(id: string): Promise<string | undefined>;
307
- setLabel(id: string, label: string | undefined): Promise<void>;
308
- getStats(): Promise<SessionStats>;
309
- }
310
- export interface SessionTree {
311
- getLeafId(): Promise<string | null>;
312
- getEntry(id: string): Promise<Entry | undefined>;
313
- getStats(): Promise<SessionStats>;
314
- getName(): Promise<string | undefined>;
315
- setName(name: string | undefined): Promise<void>;
316
- getLabel(targetId: string): Promise<string | undefined>;
317
- setLabel(targetId: string, label: string | undefined): Promise<void>;
318
- /** Session-wide, all branches, sequence order. */
319
- findEntries(query?: EntryQuery): Promise<Entry[]>;
320
- findEntry(query?: EntryQuery): Promise<Entry | undefined>;
321
- /** Branch-scoped: the path from start toward root. */
322
- findEntriesOnBranch(query?: EntryQuery & BranchBounds): Promise<Entry[]>;
323
- findEntryOnBranch(query?: EntryQuery & BranchBounds): Promise<Entry | undefined>;
324
- appendMessage(message: AgentMessage): Promise<string>;
325
- appendCustomEntry(customType: string, data?: unknown): Promise<string>;
462
+ mutate<T>(mutation: SessionMutationCallback<T>, context: Context): Promise<T>;
463
+ setValue<T>(address: Value<T>, next: NoInfer<T>, context: Context): Promise<void>;
464
+ deleteValue<T>(address: Value<T>, context: Context): Promise<void>;
465
+ appendList<T>(address: ValueList<T>, element: NoInfer<T>, context: Context): Promise<void>;
466
+ deleteList<T>(address: ValueList<T>, context: Context): Promise<void>;
467
+ setName(name: string | undefined, context: Context): Promise<void>;
468
+ setLabel(targetId: string, label: string | undefined, context: Context): Promise<void>;
469
+ close(context: Context): Promise<void>;
326
470
  }
327
471
  export interface SessionCreateOptions {
328
472
  id?: string;
329
473
  parentSessionId?: string;
330
474
  }
331
475
  export type ForkOptions = {
332
- scope?: "branch";
476
+ /**
477
+ * Copy one path from a complete configured source AgentLane under the same
478
+ * Branch name, with copied configuration and fresh idle lane state.
479
+ */
480
+ scope: "branch";
481
+ /** Source Branch to copy. */
482
+ branch: string;
483
+ /** Entry on the source Branch's current tip ancestry. Defaults to the current tip. */
333
484
  entryId?: string;
485
+ /**
486
+ * Whether the fork includes the selected entry or stops at its parent.
487
+ * Defaults to including the selected entry.
488
+ */
334
489
  position?: "before" | "at";
490
+ /** Optional destination session id. */
491
+ id?: string;
335
492
  } | {
493
+ /**
494
+ * Copy the whole conversation tree and every Branch tip. Each configured
495
+ * AgentLane copies configuration plus fresh idle state; data-only Branches
496
+ * remain data-only. Operation/pending/result/usage state is excluded.
497
+ */
336
498
  scope: "tree";
499
+ /** Optional destination session id. */
500
+ id?: string;
337
501
  };
338
- export interface SessionRepo<TMetadata extends SessionMetadata = SessionMetadata, TCreateOptions extends SessionCreateOptions = SessionCreateOptions, TListOptions = void> {
339
- create(options: TCreateOptions): Promise<Session<TMetadata>>;
340
- /** Opens the session for writing and acquires any backend writer claim. */
341
- open(metadata: TMetadata): Promise<Session<TMetadata>>;
342
- /** Lists session metadata without opening sessions or acquiring writer claims. */
343
- list(options?: TListOptions): Promise<TMetadata[]>;
344
- delete(metadata: TMetadata): Promise<void>;
345
- fork(source: TMetadata, options: ForkOptions & TCreateOptions): Promise<Session<TMetadata>>;
346
- }
347
- export type SessionErrorCode = "not_found" | "already_exists" | "invalid_entry" | "invalid_payload" | "invalid_lane" | "invalid_query" | "invalid_fork_target" | "storage";
348
- export declare class SessionError extends Error {
349
- readonly code: SessionErrorCode;
350
- constructor(code: SessionErrorCode, message: string, cause?: Error);
502
+ export interface SessionRepo<TMetadata extends SessionMetadata = SessionMetadata, TCreateOptions extends {
503
+ id?: string;
504
+ parentSessionId?: string;
505
+ } = SessionCreateOptions, TListOptions = void> {
506
+ create(options: TCreateOptions, context: Context): Promise<Session<TMetadata>>;
507
+ open(metadata: TMetadata, context: Context): Promise<Session<TMetadata>>;
508
+ list(options: TListOptions | undefined, context: Context): Promise<TMetadata[]>;
509
+ delete(metadata: TMetadata, context: Context): Promise<void>;
510
+ fork(source: TMetadata, options: ForkOptions, context: Context): Promise<Session<TMetadata>>;
351
511
  }
352
512
  //# sourceMappingURL=types.d.ts.map