@earendil-works/pi-agent-core 0.99.2 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (450) hide show
  1. package/README.md +0 -8
  2. package/dist/index.d.ts +0 -22
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +0 -20
  5. package/dist/index.js.map +1 -1
  6. package/package.json +3 -45
  7. package/dist/harness/agent-harness.d.ts +0 -716
  8. package/dist/harness/agent-harness.d.ts.map +0 -1
  9. package/dist/harness/agent-harness.js +0 -6
  10. package/dist/harness/agent-harness.js.map +0 -1
  11. package/dist/harness/compaction/branch-summarization.d.ts +0 -68
  12. package/dist/harness/compaction/branch-summarization.d.ts.map +0 -1
  13. package/dist/harness/compaction/branch-summarization.js +0 -176
  14. package/dist/harness/compaction/branch-summarization.js.map +0 -1
  15. package/dist/harness/compaction/compaction.d.ts +0 -126
  16. package/dist/harness/compaction/compaction.d.ts.map +0 -1
  17. package/dist/harness/compaction/compaction.js +0 -560
  18. package/dist/harness/compaction/compaction.js.map +0 -1
  19. package/dist/harness/compaction/utils.d.ts +0 -25
  20. package/dist/harness/compaction/utils.d.ts.map +0 -1
  21. package/dist/harness/compaction/utils.js +0 -120
  22. package/dist/harness/compaction/utils.js.map +0 -1
  23. package/dist/harness/config.d.ts +0 -9
  24. package/dist/harness/config.d.ts.map +0 -1
  25. package/dist/harness/config.js +0 -35
  26. package/dist/harness/config.js.map +0 -1
  27. package/dist/harness/context.d.ts +0 -9
  28. package/dist/harness/context.d.ts.map +0 -1
  29. package/dist/harness/context.js +0 -13
  30. package/dist/harness/context.js.map +0 -1
  31. package/dist/harness/env/nodejs.d.ts +0 -43
  32. package/dist/harness/env/nodejs.d.ts.map +0 -1
  33. package/dist/harness/env/nodejs.js +0 -865
  34. package/dist/harness/env/nodejs.js.map +0 -1
  35. package/dist/harness/events.d.ts +0 -25
  36. package/dist/harness/events.d.ts.map +0 -1
  37. package/dist/harness/events.js +0 -250
  38. package/dist/harness/events.js.map +0 -1
  39. package/dist/harness/execution/assistant.d.ts +0 -42
  40. package/dist/harness/execution/assistant.d.ts.map +0 -1
  41. package/dist/harness/execution/assistant.js +0 -82
  42. package/dist/harness/execution/assistant.js.map +0 -1
  43. package/dist/harness/execution/effect-gate.d.ts +0 -22
  44. package/dist/harness/execution/effect-gate.d.ts.map +0 -1
  45. package/dist/harness/execution/effect-gate.js +0 -49
  46. package/dist/harness/execution/effect-gate.js.map +0 -1
  47. package/dist/harness/execution/tools.d.ts +0 -67
  48. package/dist/harness/execution/tools.d.ts.map +0 -1
  49. package/dist/harness/execution/tools.js +0 -119
  50. package/dist/harness/execution/tools.js.map +0 -1
  51. package/dist/harness/hooks.d.ts +0 -38
  52. package/dist/harness/hooks.d.ts.map +0 -1
  53. package/dist/harness/hooks.js +0 -406
  54. package/dist/harness/hooks.js.map +0 -1
  55. package/dist/harness/messages.d.ts +0 -51
  56. package/dist/harness/messages.d.ts.map +0 -1
  57. package/dist/harness/messages.js +0 -103
  58. package/dist/harness/messages.js.map +0 -1
  59. package/dist/harness/pico3/bash.d.ts +0 -10
  60. package/dist/harness/pico3/bash.d.ts.map +0 -1
  61. package/dist/harness/pico3/bash.js +0 -25
  62. package/dist/harness/pico3/bash.js.map +0 -1
  63. package/dist/harness/pico3/bounded.d.ts +0 -21
  64. package/dist/harness/pico3/bounded.d.ts.map +0 -1
  65. package/dist/harness/pico3/bounded.js +0 -98
  66. package/dist/harness/pico3/bounded.js.map +0 -1
  67. package/dist/harness/pico3/chord.d.ts +0 -41
  68. package/dist/harness/pico3/chord.d.ts.map +0 -1
  69. package/dist/harness/pico3/chord.js +0 -147
  70. package/dist/harness/pico3/chord.js.map +0 -1
  71. package/dist/harness/pico3/context.d.ts +0 -16
  72. package/dist/harness/pico3/context.d.ts.map +0 -1
  73. package/dist/harness/pico3/context.js +0 -88
  74. package/dist/harness/pico3/context.js.map +0 -1
  75. package/dist/harness/pico3/harness.d.ts +0 -198
  76. package/dist/harness/pico3/harness.d.ts.map +0 -1
  77. package/dist/harness/pico3/harness.js +0 -654
  78. package/dist/harness/pico3/harness.js.map +0 -1
  79. package/dist/harness/pico3/hooks.d.ts +0 -10
  80. package/dist/harness/pico3/hooks.d.ts.map +0 -1
  81. package/dist/harness/pico3/hooks.js +0 -33
  82. package/dist/harness/pico3/hooks.js.map +0 -1
  83. package/dist/harness/pico3/index.d.ts +0 -19
  84. package/dist/harness/pico3/index.d.ts.map +0 -1
  85. package/dist/harness/pico3/index.js +0 -15
  86. package/dist/harness/pico3/index.js.map +0 -1
  87. package/dist/harness/pico3/jsonl.d.ts +0 -58
  88. package/dist/harness/pico3/jsonl.d.ts.map +0 -1
  89. package/dist/harness/pico3/jsonl.js +0 -325
  90. package/dist/harness/pico3/jsonl.js.map +0 -1
  91. package/dist/harness/pico3/kinds/collapse.d.ts +0 -49
  92. package/dist/harness/pico3/kinds/collapse.d.ts.map +0 -1
  93. package/dist/harness/pico3/kinds/collapse.js +0 -191
  94. package/dist/harness/pico3/kinds/collapse.js.map +0 -1
  95. package/dist/harness/pico3/kinds/entries.d.ts +0 -78
  96. package/dist/harness/pico3/kinds/entries.d.ts.map +0 -1
  97. package/dist/harness/pico3/kinds/entries.js +0 -13
  98. package/dist/harness/pico3/kinds/entries.js.map +0 -1
  99. package/dist/harness/pico3/kinds/frames.d.ts +0 -9
  100. package/dist/harness/pico3/kinds/frames.d.ts.map +0 -1
  101. package/dist/harness/pico3/kinds/frames.js +0 -75
  102. package/dist/harness/pico3/kinds/frames.js.map +0 -1
  103. package/dist/harness/pico3/kinds/generation.d.ts +0 -94
  104. package/dist/harness/pico3/kinds/generation.d.ts.map +0 -1
  105. package/dist/harness/pico3/kinds/generation.js +0 -504
  106. package/dist/harness/pico3/kinds/generation.js.map +0 -1
  107. package/dist/harness/pico3/kinds/job.d.ts +0 -44
  108. package/dist/harness/pico3/kinds/job.d.ts.map +0 -1
  109. package/dist/harness/pico3/kinds/job.js +0 -143
  110. package/dist/harness/pico3/kinds/job.js.map +0 -1
  111. package/dist/harness/pico3/kinds/plugin.d.ts +0 -15
  112. package/dist/harness/pico3/kinds/plugin.d.ts.map +0 -1
  113. package/dist/harness/pico3/kinds/plugin.js +0 -35
  114. package/dist/harness/pico3/kinds/plugin.js.map +0 -1
  115. package/dist/harness/pico3/kinds/post-tools.d.ts +0 -22
  116. package/dist/harness/pico3/kinds/post-tools.d.ts.map +0 -1
  117. package/dist/harness/pico3/kinds/post-tools.js +0 -145
  118. package/dist/harness/pico3/kinds/post-tools.js.map +0 -1
  119. package/dist/harness/pico3/kinds/task-api.d.ts +0 -3
  120. package/dist/harness/pico3/kinds/task-api.d.ts.map +0 -1
  121. package/dist/harness/pico3/kinds/task-api.js +0 -45
  122. package/dist/harness/pico3/kinds/task-api.js.map +0 -1
  123. package/dist/harness/pico3/kinds/tool.d.ts +0 -43
  124. package/dist/harness/pico3/kinds/tool.d.ts.map +0 -1
  125. package/dist/harness/pico3/kinds/tool.js +0 -373
  126. package/dist/harness/pico3/kinds/tool.js.map +0 -1
  127. package/dist/harness/pico3/legacy-tracker.d.ts +0 -11
  128. package/dist/harness/pico3/legacy-tracker.d.ts.map +0 -1
  129. package/dist/harness/pico3/legacy-tracker.js +0 -41
  130. package/dist/harness/pico3/legacy-tracker.js.map +0 -1
  131. package/dist/harness/pico3/membrane.d.ts +0 -23
  132. package/dist/harness/pico3/membrane.d.ts.map +0 -1
  133. package/dist/harness/pico3/membrane.js +0 -141
  134. package/dist/harness/pico3/membrane.js.map +0 -1
  135. package/dist/harness/pico3/memory.d.ts +0 -53
  136. package/dist/harness/pico3/memory.d.ts.map +0 -1
  137. package/dist/harness/pico3/memory.js +0 -264
  138. package/dist/harness/pico3/memory.js.map +0 -1
  139. package/dist/harness/pico3/scheduler.d.ts +0 -49
  140. package/dist/harness/pico3/scheduler.d.ts.map +0 -1
  141. package/dist/harness/pico3/scheduler.js +0 -438
  142. package/dist/harness/pico3/scheduler.js.map +0 -1
  143. package/dist/harness/pico3/session.d.ts +0 -264
  144. package/dist/harness/pico3/session.d.ts.map +0 -1
  145. package/dist/harness/pico3/session.js +0 -1348
  146. package/dist/harness/pico3/session.js.map +0 -1
  147. package/dist/harness/pico3/system.d.ts +0 -126
  148. package/dist/harness/pico3/system.d.ts.map +0 -1
  149. package/dist/harness/pico3/system.js +0 -244
  150. package/dist/harness/pico3/system.js.map +0 -1
  151. package/dist/harness/pico3/types.d.ts +0 -973
  152. package/dist/harness/pico3/types.d.ts.map +0 -1
  153. package/dist/harness/pico3/types.js +0 -96
  154. package/dist/harness/pico3/types.js.map +0 -1
  155. package/dist/harness/pico3/view.d.ts +0 -34
  156. package/dist/harness/pico3/view.d.ts.map +0 -1
  157. package/dist/harness/pico3/view.js +0 -411
  158. package/dist/harness/pico3/view.js.map +0 -1
  159. package/dist/harness/prompt-templates.d.ts +0 -49
  160. package/dist/harness/prompt-templates.d.ts.map +0 -1
  161. package/dist/harness/prompt-templates.js +0 -225
  162. package/dist/harness/prompt-templates.js.map +0 -1
  163. package/dist/harness/result.d.ts +0 -133
  164. package/dist/harness/result.d.ts.map +0 -1
  165. package/dist/harness/result.js +0 -81
  166. package/dist/harness/result.js.map +0 -1
  167. package/dist/harness/runtime/drive/boundary.d.ts +0 -28
  168. package/dist/harness/runtime/drive/boundary.d.ts.map +0 -1
  169. package/dist/harness/runtime/drive/boundary.js +0 -173
  170. package/dist/harness/runtime/drive/boundary.js.map +0 -1
  171. package/dist/harness/runtime/drive/checkpoint.d.ts +0 -8
  172. package/dist/harness/runtime/drive/checkpoint.d.ts.map +0 -1
  173. package/dist/harness/runtime/drive/checkpoint.js +0 -133
  174. package/dist/harness/runtime/drive/checkpoint.js.map +0 -1
  175. package/dist/harness/runtime/drive/deferred.d.ts +0 -15
  176. package/dist/harness/runtime/drive/deferred.d.ts.map +0 -1
  177. package/dist/harness/runtime/drive/deferred.js +0 -179
  178. package/dist/harness/runtime/drive/deferred.js.map +0 -1
  179. package/dist/harness/runtime/drive/generation.d.ts +0 -8
  180. package/dist/harness/runtime/drive/generation.d.ts.map +0 -1
  181. package/dist/harness/runtime/drive/generation.js +0 -205
  182. package/dist/harness/runtime/drive/generation.js.map +0 -1
  183. package/dist/harness/runtime/drive/reconcile.d.ts +0 -5
  184. package/dist/harness/runtime/drive/reconcile.d.ts.map +0 -1
  185. package/dist/harness/runtime/drive/reconcile.js +0 -140
  186. package/dist/harness/runtime/drive/reconcile.js.map +0 -1
  187. package/dist/harness/runtime/drive/recovery.d.ts +0 -8
  188. package/dist/harness/runtime/drive/recovery.d.ts.map +0 -1
  189. package/dist/harness/runtime/drive/recovery.js +0 -85
  190. package/dist/harness/runtime/drive/recovery.js.map +0 -1
  191. package/dist/harness/runtime/drive/response.d.ts +0 -23
  192. package/dist/harness/runtime/drive/response.d.ts.map +0 -1
  193. package/dist/harness/runtime/drive/response.js +0 -394
  194. package/dist/harness/runtime/drive/response.js.map +0 -1
  195. package/dist/harness/runtime/drive/retry.d.ts +0 -4
  196. package/dist/harness/runtime/drive/retry.d.ts.map +0 -1
  197. package/dist/harness/runtime/drive/retry.js +0 -34
  198. package/dist/harness/runtime/drive/retry.js.map +0 -1
  199. package/dist/harness/runtime/drive/structural.d.ts +0 -32
  200. package/dist/harness/runtime/drive/structural.d.ts.map +0 -1
  201. package/dist/harness/runtime/drive/structural.js +0 -929
  202. package/dist/harness/runtime/drive/structural.js.map +0 -1
  203. package/dist/harness/runtime/drive/terminal.d.ts +0 -7
  204. package/dist/harness/runtime/drive/terminal.d.ts.map +0 -1
  205. package/dist/harness/runtime/drive/terminal.js +0 -49
  206. package/dist/harness/runtime/drive/terminal.js.map +0 -1
  207. package/dist/harness/runtime/drive/tool-placement.d.ts +0 -14
  208. package/dist/harness/runtime/drive/tool-placement.d.ts.map +0 -1
  209. package/dist/harness/runtime/drive/tool-placement.js +0 -219
  210. package/dist/harness/runtime/drive/tool-placement.js.map +0 -1
  211. package/dist/harness/runtime/drive/tools.d.ts +0 -6
  212. package/dist/harness/runtime/drive/tools.d.ts.map +0 -1
  213. package/dist/harness/runtime/drive/tools.js +0 -449
  214. package/dist/harness/runtime/drive/tools.js.map +0 -1
  215. package/dist/harness/runtime/drive.d.ts +0 -6
  216. package/dist/harness/runtime/drive.d.ts.map +0 -1
  217. package/dist/harness/runtime/drive.js +0 -93
  218. package/dist/harness/runtime/drive.js.map +0 -1
  219. package/dist/harness/runtime/harness.d.ts +0 -59
  220. package/dist/harness/runtime/harness.d.ts.map +0 -1
  221. package/dist/harness/runtime/harness.js +0 -311
  222. package/dist/harness/runtime/harness.js.map +0 -1
  223. package/dist/harness/runtime/index.d.ts +0 -2
  224. package/dist/harness/runtime/index.d.ts.map +0 -1
  225. package/dist/harness/runtime/index.js +0 -2
  226. package/dist/harness/runtime/index.js.map +0 -1
  227. package/dist/harness/runtime/lane.d.ts +0 -118
  228. package/dist/harness/runtime/lane.d.ts.map +0 -1
  229. package/dist/harness/runtime/lane.js +0 -1575
  230. package/dist/harness/runtime/lane.js.map +0 -1
  231. package/dist/harness/runtime/progress.d.ts +0 -15
  232. package/dist/harness/runtime/progress.d.ts.map +0 -1
  233. package/dist/harness/runtime/progress.js +0 -66
  234. package/dist/harness/runtime/progress.js.map +0 -1
  235. package/dist/harness/runtime/reducer.d.ts +0 -5
  236. package/dist/harness/runtime/reducer.d.ts.map +0 -1
  237. package/dist/harness/runtime/reducer.js +0 -240
  238. package/dist/harness/runtime/reducer.js.map +0 -1
  239. package/dist/harness/runtime/restore.d.ts +0 -24
  240. package/dist/harness/runtime/restore.d.ts.map +0 -1
  241. package/dist/harness/runtime/restore.js +0 -117
  242. package/dist/harness/runtime/restore.js.map +0 -1
  243. package/dist/harness/runtime/transcript.d.ts +0 -21
  244. package/dist/harness/runtime/transcript.d.ts.map +0 -1
  245. package/dist/harness/runtime/transcript.js +0 -72
  246. package/dist/harness/runtime/transcript.js.map +0 -1
  247. package/dist/harness/runtime/types.d.ts +0 -105
  248. package/dist/harness/runtime/types.d.ts.map +0 -1
  249. package/dist/harness/runtime/types.js +0 -61
  250. package/dist/harness/runtime/types.js.map +0 -1
  251. package/dist/harness/session/commit.d.ts +0 -53
  252. package/dist/harness/session/commit.d.ts.map +0 -1
  253. package/dist/harness/session/commit.js +0 -57
  254. package/dist/harness/session/commit.js.map +0 -1
  255. package/dist/harness/session/context.d.ts +0 -10
  256. package/dist/harness/session/context.d.ts.map +0 -1
  257. package/dist/harness/session/context.js +0 -49
  258. package/dist/harness/session/context.js.map +0 -1
  259. package/dist/harness/session/fork-policy.d.ts +0 -21
  260. package/dist/harness/session/fork-policy.d.ts.map +0 -1
  261. package/dist/harness/session/fork-policy.js +0 -55
  262. package/dist/harness/session/fork-policy.js.map +0 -1
  263. package/dist/harness/session/fork.d.ts +0 -16
  264. package/dist/harness/session/fork.d.ts.map +0 -1
  265. package/dist/harness/session/fork.js +0 -79
  266. package/dist/harness/session/fork.js.map +0 -1
  267. package/dist/harness/session/in-memory-storage-state.d.ts +0 -39
  268. package/dist/harness/session/in-memory-storage-state.d.ts.map +0 -1
  269. package/dist/harness/session/in-memory-storage-state.js +0 -276
  270. package/dist/harness/session/in-memory-storage-state.js.map +0 -1
  271. package/dist/harness/session/index.d.ts +0 -11
  272. package/dist/harness/session/index.d.ts.map +0 -1
  273. package/dist/harness/session/index.js +0 -9
  274. package/dist/harness/session/index.js.map +0 -1
  275. package/dist/harness/session/jsonl/codec.d.ts +0 -21
  276. package/dist/harness/session/jsonl/codec.d.ts.map +0 -1
  277. package/dist/harness/session/jsonl/codec.js +0 -45
  278. package/dist/harness/session/jsonl/codec.js.map +0 -1
  279. package/dist/harness/session/jsonl/fork.d.ts +0 -38
  280. package/dist/harness/session/jsonl/fork.d.ts.map +0 -1
  281. package/dist/harness/session/jsonl/fork.js +0 -264
  282. package/dist/harness/session/jsonl/fork.js.map +0 -1
  283. package/dist/harness/session/jsonl/index.d.ts +0 -4
  284. package/dist/harness/session/jsonl/index.d.ts.map +0 -1
  285. package/dist/harness/session/jsonl/index.js +0 -4
  286. package/dist/harness/session/jsonl/index.js.map +0 -1
  287. package/dist/harness/session/jsonl/io.d.ts +0 -14
  288. package/dist/harness/session/jsonl/io.d.ts.map +0 -1
  289. package/dist/harness/session/jsonl/io.js +0 -86
  290. package/dist/harness/session/jsonl/io.js.map +0 -1
  291. package/dist/harness/session/jsonl/legacy-v3.d.ts +0 -44
  292. package/dist/harness/session/jsonl/legacy-v3.d.ts.map +0 -1
  293. package/dist/harness/session/jsonl/legacy-v3.js +0 -462
  294. package/dist/harness/session/jsonl/legacy-v3.js.map +0 -1
  295. package/dist/harness/session/jsonl/repo.d.ts +0 -35
  296. package/dist/harness/session/jsonl/repo.d.ts.map +0 -1
  297. package/dist/harness/session/jsonl/repo.js +0 -301
  298. package/dist/harness/session/jsonl/repo.js.map +0 -1
  299. package/dist/harness/session/jsonl/storage.d.ts +0 -41
  300. package/dist/harness/session/jsonl/storage.d.ts.map +0 -1
  301. package/dist/harness/session/jsonl/storage.js +0 -200
  302. package/dist/harness/session/jsonl/storage.js.map +0 -1
  303. package/dist/harness/session/jsonl/types.d.ts +0 -39
  304. package/dist/harness/session/jsonl/types.d.ts.map +0 -1
  305. package/dist/harness/session/jsonl/types.js +0 -3
  306. package/dist/harness/session/jsonl/types.js.map +0 -1
  307. package/dist/harness/session/memory.d.ts +0 -48
  308. package/dist/harness/session/memory.d.ts.map +0 -1
  309. package/dist/harness/session/memory.js +0 -369
  310. package/dist/harness/session/memory.js.map +0 -1
  311. package/dist/harness/session/mutation-line.d.ts +0 -8
  312. package/dist/harness/session/mutation-line.d.ts.map +0 -1
  313. package/dist/harness/session/mutation-line.js +0 -21
  314. package/dist/harness/session/mutation-line.js.map +0 -1
  315. package/dist/harness/session/session.d.ts +0 -82
  316. package/dist/harness/session/session.d.ts.map +0 -1
  317. package/dist/harness/session/session.js +0 -361
  318. package/dist/harness/session/session.js.map +0 -1
  319. package/dist/harness/session/testing/benchmark/datasets.d.ts +0 -12
  320. package/dist/harness/session/testing/benchmark/datasets.d.ts.map +0 -1
  321. package/dist/harness/session/testing/benchmark/datasets.js +0 -24
  322. package/dist/harness/session/testing/benchmark/datasets.js.map +0 -1
  323. package/dist/harness/session/testing/benchmark/session-repo.d.ts +0 -42
  324. package/dist/harness/session/testing/benchmark/session-repo.d.ts.map +0 -1
  325. package/dist/harness/session/testing/benchmark/session-repo.js +0 -127
  326. package/dist/harness/session/testing/benchmark/session-repo.js.map +0 -1
  327. package/dist/harness/session/testing/benchmark/storage.d.ts +0 -25
  328. package/dist/harness/session/testing/benchmark/storage.d.ts.map +0 -1
  329. package/dist/harness/session/testing/benchmark/storage.js +0 -114
  330. package/dist/harness/session/testing/benchmark/storage.js.map +0 -1
  331. package/dist/harness/session/testing/conformance/session-repo.d.ts +0 -23
  332. package/dist/harness/session/testing/conformance/session-repo.d.ts.map +0 -1
  333. package/dist/harness/session/testing/conformance/session-repo.js +0 -809
  334. package/dist/harness/session/testing/conformance/session-repo.js.map +0 -1
  335. package/dist/harness/session/testing/conformance/storage.d.ts +0 -4
  336. package/dist/harness/session/testing/conformance/storage.d.ts.map +0 -1
  337. package/dist/harness/session/testing/conformance/storage.js +0 -600
  338. package/dist/harness/session/testing/conformance/storage.js.map +0 -1
  339. package/dist/harness/session/testing/gating-storage.d.ts +0 -26
  340. package/dist/harness/session/testing/gating-storage.d.ts.map +0 -1
  341. package/dist/harness/session/testing/gating-storage.js +0 -100
  342. package/dist/harness/session/testing/gating-storage.js.map +0 -1
  343. package/dist/harness/session/testing/index.d.ts +0 -10
  344. package/dist/harness/session/testing/index.d.ts.map +0 -1
  345. package/dist/harness/session/testing/index.js +0 -9
  346. package/dist/harness/session/testing/index.js.map +0 -1
  347. package/dist/harness/session/testing/instrumented-storage.d.ts +0 -11
  348. package/dist/harness/session/testing/instrumented-storage.d.ts.map +0 -1
  349. package/dist/harness/session/testing/instrumented-storage.js +0 -16
  350. package/dist/harness/session/testing/instrumented-storage.js.map +0 -1
  351. package/dist/harness/session/testing/storage-decorator.d.ts +0 -20
  352. package/dist/harness/session/testing/storage-decorator.d.ts.map +0 -1
  353. package/dist/harness/session/testing/storage-decorator.js +0 -41
  354. package/dist/harness/session/testing/storage-decorator.js.map +0 -1
  355. package/dist/harness/session/testing/types.d.ts +0 -12
  356. package/dist/harness/session/testing/types.d.ts.map +0 -1
  357. package/dist/harness/session/testing/types.js +0 -2
  358. package/dist/harness/session/testing/types.js.map +0 -1
  359. package/dist/harness/session/types.d.ts +0 -512
  360. package/dist/harness/session/types.d.ts.map +0 -1
  361. package/dist/harness/session/types.js +0 -9
  362. package/dist/harness/session/types.js.map +0 -1
  363. package/dist/harness/session/values.d.ts +0 -95
  364. package/dist/harness/session/values.d.ts.map +0 -1
  365. package/dist/harness/session/values.js +0 -81
  366. package/dist/harness/session/values.js.map +0 -1
  367. package/dist/harness/skills.d.ts +0 -46
  368. package/dist/harness/skills.d.ts.map +0 -1
  369. package/dist/harness/skills.js +0 -326
  370. package/dist/harness/skills.js.map +0 -1
  371. package/dist/harness/system-prompt.d.ts +0 -3
  372. package/dist/harness/system-prompt.d.ts.map +0 -1
  373. package/dist/harness/system-prompt.js +0 -30
  374. package/dist/harness/system-prompt.js.map +0 -1
  375. package/dist/harness/telemetry.d.ts +0 -1242
  376. package/dist/harness/telemetry.d.ts.map +0 -1
  377. package/dist/harness/telemetry.js +0 -527
  378. package/dist/harness/telemetry.js.map +0 -1
  379. package/dist/harness/tools/bash.d.ts +0 -27
  380. package/dist/harness/tools/bash.d.ts.map +0 -1
  381. package/dist/harness/tools/bash.js +0 -105
  382. package/dist/harness/tools/bash.js.map +0 -1
  383. package/dist/harness/tools/edit-diff.d.ts +0 -89
  384. package/dist/harness/tools/edit-diff.d.ts.map +0 -1
  385. package/dist/harness/tools/edit-diff.js +0 -386
  386. package/dist/harness/tools/edit-diff.js.map +0 -1
  387. package/dist/harness/tools/edit.d.ts +0 -19
  388. package/dist/harness/tools/edit.d.ts.map +0 -1
  389. package/dist/harness/tools/edit.js +0 -108
  390. package/dist/harness/tools/edit.js.map +0 -1
  391. package/dist/harness/tools/file-mutation-queue.d.ts +0 -5
  392. package/dist/harness/tools/file-mutation-queue.d.ts.map +0 -1
  393. package/dist/harness/tools/file-mutation-queue.js +0 -46
  394. package/dist/harness/tools/file-mutation-queue.js.map +0 -1
  395. package/dist/harness/tools/image.d.ts +0 -3
  396. package/dist/harness/tools/image.d.ts.map +0 -1
  397. package/dist/harness/tools/image.js +0 -106
  398. package/dist/harness/tools/image.js.map +0 -1
  399. package/dist/harness/tools/index.d.ts +0 -6
  400. package/dist/harness/tools/index.d.ts.map +0 -1
  401. package/dist/harness/tools/index.js +0 -5
  402. package/dist/harness/tools/index.js.map +0 -1
  403. package/dist/harness/tools/path-utils.d.ts +0 -5
  404. package/dist/harness/tools/path-utils.d.ts.map +0 -1
  405. package/dist/harness/tools/path-utils.js +0 -26
  406. package/dist/harness/tools/path-utils.js.map +0 -1
  407. package/dist/harness/tools/read.d.ts +0 -35
  408. package/dist/harness/tools/read.d.ts.map +0 -1
  409. package/dist/harness/tools/read.js +0 -108
  410. package/dist/harness/tools/read.js.map +0 -1
  411. package/dist/harness/tools/tool-context.d.ts +0 -6
  412. package/dist/harness/tools/tool-context.d.ts.map +0 -1
  413. package/dist/harness/tools/tool-context.js +0 -2
  414. package/dist/harness/tools/tool-context.js.map +0 -1
  415. package/dist/harness/tools/write.d.ts +0 -11
  416. package/dist/harness/tools/write.d.ts.map +0 -1
  417. package/dist/harness/tools/write.js +0 -31
  418. package/dist/harness/tools/write.js.map +0 -1
  419. package/dist/harness/types.d.ts +0 -305
  420. package/dist/harness/types.d.ts.map +0 -1
  421. package/dist/harness/types.js +0 -75
  422. package/dist/harness/types.js.map +0 -1
  423. package/dist/harness/utils/adaptive-publisher.d.ts +0 -24
  424. package/dist/harness/utils/adaptive-publisher.d.ts.map +0 -1
  425. package/dist/harness/utils/adaptive-publisher.js +0 -79
  426. package/dist/harness/utils/adaptive-publisher.js.map +0 -1
  427. package/dist/harness/utils/output-capture.d.ts +0 -31
  428. package/dist/harness/utils/output-capture.d.ts.map +0 -1
  429. package/dist/harness/utils/output-capture.js +0 -217
  430. package/dist/harness/utils/output-capture.js.map +0 -1
  431. package/dist/harness/utils/shell-output.d.ts +0 -29
  432. package/dist/harness/utils/shell-output.d.ts.map +0 -1
  433. package/dist/harness/utils/shell-output.js +0 -71
  434. package/dist/harness/utils/shell-output.js.map +0 -1
  435. package/dist/harness/utils/truncate.d.ts +0 -71
  436. package/dist/harness/utils/truncate.d.ts.map +0 -1
  437. package/dist/harness/utils/truncate.js +0 -296
  438. package/dist/harness/utils/truncate.js.map +0 -1
  439. package/dist/harness/utils/usage.d.ts +0 -4
  440. package/dist/harness/utils/usage.d.ts.map +0 -1
  441. package/dist/harness/utils/usage.js +0 -33
  442. package/dist/harness/utils/usage.js.map +0 -1
  443. package/dist/node.d.ts +0 -3
  444. package/dist/node.d.ts.map +0 -1
  445. package/dist/node.js +0 -3
  446. package/dist/node.js.map +0 -1
  447. package/dist/search/index.d.ts +0 -29
  448. package/dist/search/index.d.ts.map +0 -1
  449. package/dist/search/index.js +0 -2
  450. package/dist/search/index.js.map +0 -1
@@ -1,325 +0,0 @@
1
- import { closeSync, existsSync, fsyncSync, ftruncateSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, statSync, unlinkSync, writeSync, } from "node:fs";
2
- import { join } from "node:path";
3
- import { BACKGROUND_CONTEXT } from "@earendil-works/chord/context";
4
- import { isBase } from "@earendil-works/chord/delta";
5
- import { MemoryStorage } from "./memory.js";
6
- /**
7
- * Files in a session directory:
8
- * main.jsonl conversations, entries, inputs, rewindable/session doc ops, each task's
9
- * CREATE and TERMINAL records, and one marker per commit. Append-only, never rewritten.
10
- * sticky-<conversation>.jsonl sticky doc ops; rewritten from its last base by `truncate` (on the Session line)
11
- * task-<id>.jsonl a live task's intermediate patches (running, checkpoints); unlinked after its
12
- * terminal record is published in main
13
- *
14
- * Publication (§10): one commit `Seq`; sidecar records are appended first, then exactly one main
15
- * record, last, listing the sidecar refs it expects — the publication point. Replay applies a sidecar
16
- * record only when main has the marker for that seq naming that file; unconfirmed sidecar tails are
17
- * ignored. Every record carries the committed-ID high-water. Bytes after the last newline of any file
18
- * are a torn write and are truncated before the file is opened for append. There is no compaction.
19
- *
20
- * With `fsync: false`, recovery covers process termination while the OS and filesystem remain alive.
21
- * It does not promise that an acknowledged commit survives power loss, kernel/host failure,
22
- * storage-cache loss, or a filesystem that loses/reorders completed writes. An acknowledged tail may
23
- * roll back, or a surviving main marker may reference a missing sidecar and make open fail rather
24
- * than expose partial state. A lost pre-effect checkpoint can cause an external effect to be attempted
25
- * again; external idempotency remains required.
26
- *
27
- * With `fsync: true`, each sidecar is flushed before the main publication marker is flushed. This
28
- * strengthens file-data durability and ordering across machine failure. It is not a complete database
29
- * guarantee: newly created files, renames, and unlinks are not followed by a parent-directory fsync,
30
- * and storage hardware/filesystems may provide weaker guarantees.
31
- *
32
- * One process owns a directory at a time; a second process is unsupported.
33
- */
34
- export class JsonlStorage extends MemoryStorage {
35
- mainFd;
36
- sidecars = new Map(); // sticky docs, by conversation
37
- taskSidecars = new Map();
38
- dir;
39
- fsync;
40
- closedOnce = false;
41
- constructor(dir, fsync) {
42
- super();
43
- this.dir = dir;
44
- this.fsync = fsync;
45
- this.mainFd = openSync(join(dir, "main.jsonl"), "a");
46
- }
47
- static async open(dir, opts = {}) {
48
- mkdirSync(dir, { recursive: true });
49
- for (const f of readdirSync(dir))
50
- if (f.endsWith(".jsonl"))
51
- truncateTornTail(join(dir, f));
52
- const storage = new JsonlStorage(dir, opts.fsync ?? true);
53
- try {
54
- await storage.replay();
55
- return storage;
56
- }
57
- catch (error) {
58
- await storage.close();
59
- throw error;
60
- }
61
- }
62
- /** For tests and tooling: sizes of every file in the directory. */
63
- sizes() {
64
- const out = {};
65
- for (const f of readdirSync(this.dir))
66
- out[f] = statSync(join(this.dir, f)).size;
67
- return out;
68
- }
69
- async replay() {
70
- const read = (file) => {
71
- if (!existsSync(file))
72
- return [];
73
- const bytes = readFileSync(file);
74
- const out = [];
75
- let start = 0;
76
- let last = 0;
77
- for (let end = bytes.indexOf(0x0a, start); end >= 0; end = bytes.indexOf(0x0a, start)) {
78
- const line = bytes.subarray(start, end).toString("utf8");
79
- start = end + 1;
80
- if (line === "")
81
- continue;
82
- let record;
83
- try {
84
- record = JSON.parse(line);
85
- }
86
- catch (error) {
87
- throw new Error(`${file}: malformed record: ${String(error)}`);
88
- }
89
- if (typeof record.seq !== "number" || typeof record.maxId !== "number" || !Array.isArray(record.writes))
90
- throw new Error(`${file}: record lacks seq/maxId/writes`);
91
- if (record.seq <= last)
92
- throw new Error(`${file}: sequence not increasing at ${record.seq}`);
93
- last = record.seq;
94
- out.push({ record, end: start });
95
- }
96
- return out;
97
- };
98
- let maxId = 0;
99
- // Main is the commit log. Confirmed = (seq → refs) for every marker.
100
- const main = read(join(this.dir, "main.jsonl")).map(({ record }) => record);
101
- const confirmed = new Map();
102
- for (const record of main)
103
- confirmed.set(record.seq, new Set(record.refs ?? []));
104
- // Merge every file's records by seq so batches apply in commit order.
105
- const sidecarFiles = readdirSync(this.dir).filter((file) => file.startsWith("sticky-") || file.startsWith("task-"));
106
- const bySeq = new Map();
107
- const found = new Map();
108
- const retainedStickyBase = new Map();
109
- const retiredTasks = new Map();
110
- for (const record of main) {
111
- for (const write of record.writes) {
112
- if (write.type === "task.patch" && write.patch.status === "terminal")
113
- retiredTasks.set(write.patch.id, record.seq);
114
- }
115
- bySeq.set(record.seq, [...record.writes]);
116
- maxId = Math.max(maxId, record.maxId);
117
- }
118
- for (const file of sidecarFiles) {
119
- const path = join(this.dir, file);
120
- const records = read(path);
121
- const first = records[0]?.record;
122
- if (file.startsWith("sticky-") &&
123
- first !== undefined &&
124
- isBase(first.writes.flatMap((write) => (write.type === "doc" ? write.ops : [])))) {
125
- retainedStickyBase.set(file, first.seq);
126
- }
127
- let confirmedEnd = 0;
128
- let sawUnconfirmed = false;
129
- for (const { record, end } of records) {
130
- if (!confirmed.get(record.seq)?.has(file)) {
131
- sawUnconfirmed = true;
132
- continue;
133
- }
134
- if (sawUnconfirmed)
135
- throw new Error(`${path}: confirmed record follows an unconfirmed tail at ${record.seq}`);
136
- confirmedEnd = end;
137
- const files = found.get(record.seq) ?? new Set();
138
- files.add(file);
139
- found.set(record.seq, files);
140
- bySeq.get(record.seq).push(...record.writes);
141
- maxId = Math.max(maxId, record.maxId);
142
- }
143
- if (sawUnconfirmed)
144
- truncateTo(path, confirmedEnd);
145
- }
146
- for (const record of main) {
147
- for (const file of record.refs ?? []) {
148
- if (found.get(record.seq)?.has(file))
149
- continue;
150
- const retainedFrom = retainedStickyBase.get(file);
151
- if (retainedFrom !== undefined && record.seq < retainedFrom)
152
- continue;
153
- if (file.startsWith("task-")) {
154
- const id = Number(file.slice(5, -6));
155
- const retiredAt = retiredTasks.get(id);
156
- if (retiredAt !== undefined && record.seq < retiredAt)
157
- continue;
158
- }
159
- throw new Error(`${join(this.dir, file)}: missing record for published sequence ${record.seq}`);
160
- }
161
- }
162
- for (const seq of [...bySeq.keys()].sort((a, b) => a - b)) {
163
- this.seq = seq - 1;
164
- await super.commit(bySeq.get(seq), BACKGROUND_CONTEXT);
165
- }
166
- this.setNextId(maxId + 1);
167
- // Task sidecars belong to live tasks only; a leftover for a terminal (or unknown) task cannot resurrect anything.
168
- for (const f of sidecarFiles) {
169
- if (!f.startsWith("task-"))
170
- continue;
171
- const id = Number(f.slice(5, -6));
172
- const t = await super.task(id);
173
- if (t === undefined || t.status === "terminal")
174
- unlinkSync(join(this.dir, f));
175
- }
176
- }
177
- async commit(writes, ctx) {
178
- if (this.closedOnce)
179
- throw new Error("storage closed");
180
- const seq = this.seq + 1;
181
- const apply = this.stage(writes, seq); // validates the whole batch first; throws before any file is touched
182
- const maxId = this.nextIdAfter(writes);
183
- const main = [];
184
- const sticky = new Map();
185
- const tasks = new Map();
186
- const retired = [];
187
- for (const w of writes) {
188
- if (w.type === "doc" && w.ref.doc === "sticky")
189
- (sticky.get(w.ref.conversationId) ?? sticky.set(w.ref.conversationId, []).get(w.ref.conversationId)).push(w);
190
- else if (w.type === "task.patch" && w.patch.status !== "terminal")
191
- (tasks.get(w.patch.id) ?? tasks.set(w.patch.id, []).get(w.patch.id)).push(w);
192
- else {
193
- main.push(w);
194
- if (w.type === "task.patch" && w.patch.status === "terminal")
195
- retired.push(w.patch.id);
196
- }
197
- }
198
- const refs = [];
199
- for (const [id, ws] of tasks) {
200
- this.append(this.taskSidecar(id), { seq, maxId, writes: ws });
201
- refs.push(`task-${id}.jsonl`);
202
- }
203
- for (const [c, ws] of sticky) {
204
- this.append(this.sidecar(c), { seq, maxId, writes: ws });
205
- refs.push(`sticky-${c}.jsonl`);
206
- }
207
- this.append(this.mainFd, { seq, maxId, writes: main, ...(refs.length ? { refs } : {}) }); // the publication point
208
- apply();
209
- this.seq = seq;
210
- for (const id of retired)
211
- this.retireTaskSidecar(id); // after the terminal record is durably published
212
- void ctx;
213
- return seq;
214
- }
215
- nextIdAfter(writes) {
216
- let max = this.nextIdValue - 1;
217
- for (const w of writes) {
218
- const id = w.type === "conversation"
219
- ? w.conversation.id
220
- : w.type === "entry"
221
- ? w.entry.id
222
- : w.type === "task"
223
- ? w.task.id
224
- : w.type === "input"
225
- ? w.input.id
226
- : 0;
227
- max = Math.max(max, id);
228
- }
229
- return max;
230
- }
231
- append(fd, record) {
232
- writeSync(fd, `${JSON.stringify(record)}\n`);
233
- if (this.fsync)
234
- fsyncSync(fd);
235
- }
236
- sidecar(conversationId) {
237
- let fd = this.sidecars.get(conversationId);
238
- if (fd === undefined) {
239
- fd = openSync(join(this.dir, `sticky-${conversationId}.jsonl`), "a");
240
- this.sidecars.set(conversationId, fd);
241
- }
242
- return fd;
243
- }
244
- taskSidecar(id) {
245
- let fd = this.taskSidecars.get(id);
246
- if (fd === undefined) {
247
- fd = openSync(join(this.dir, `task-${id}.jsonl`), "a");
248
- this.taskSidecars.set(id, fd);
249
- }
250
- return fd;
251
- }
252
- retireTaskSidecar(id) {
253
- const fd = this.taskSidecars.get(id);
254
- if (fd !== undefined)
255
- closeSync(fd);
256
- this.taskSidecars.delete(id);
257
- try {
258
- unlinkSync(join(this.dir, `task-${id}.jsonl`));
259
- }
260
- catch { }
261
- }
262
- /** Rewrite the sticky sidecar from its last base: temp file, optional fsync, rename. Called on the Session line. */
263
- async truncate(ref, _ctx) {
264
- await super.truncate(ref);
265
- if (ref.doc !== "sticky")
266
- return;
267
- const file = join(this.dir, `sticky-${ref.conversationId}.jsonl`);
268
- if (!existsSync(file))
269
- return;
270
- const lines = readFileSync(file, "utf8").split("\n").filter(Boolean);
271
- let start = 0;
272
- for (let i = lines.length - 1; i >= 0; i--)
273
- if (isBase(JSON.parse(lines[i]).writes.flatMap((w) => (w.type === "doc" ? w.ops : [])))) {
274
- start = i;
275
- break;
276
- }
277
- if (start === 0)
278
- return;
279
- const tmp = `${file}.tmp`;
280
- const fd = openSync(tmp, "w");
281
- writeSync(fd, lines
282
- .slice(start)
283
- .map((l) => `${l}\n`)
284
- .join(""));
285
- if (this.fsync)
286
- fsyncSync(fd);
287
- closeSync(fd);
288
- const old = this.sidecars.get(ref.conversationId);
289
- if (old !== undefined)
290
- closeSync(old);
291
- renameSync(tmp, file);
292
- this.sidecars.set(ref.conversationId, openSync(file, "a"));
293
- }
294
- async close(_ctx) {
295
- if (this.closedOnce)
296
- return;
297
- this.closedOnce = true;
298
- await super.close();
299
- closeSync(this.mainFd);
300
- for (const fd of this.sidecars.values())
301
- closeSync(fd);
302
- for (const fd of this.taskSidecars.values())
303
- closeSync(fd);
304
- }
305
- }
306
- function truncateTo(file, length) {
307
- const fd = openSync(file, "r+");
308
- try {
309
- ftruncateSync(fd, length);
310
- }
311
- finally {
312
- closeSync(fd);
313
- }
314
- }
315
- /** Bytes after the last newline are a torn write: cut them so a later append cannot extend a corrupt line. */
316
- function truncateTornTail(file) {
317
- const size = statSync(file).size;
318
- if (size === 0)
319
- return;
320
- const buf = readFileSync(file);
321
- const end = buf.lastIndexOf(0x0a);
322
- if (end + 1 !== buf.length)
323
- truncateTo(file, end + 1);
324
- }
325
- //# sourceMappingURL=jsonl.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jsonl.js","sourceRoot":"","sources":["../../../src/harness/pico3/jsonl.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EACT,UAAU,EACV,SAAS,EACT,aAAa,EACb,SAAS,EACT,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,UAAU,EACV,SAAS,GACT,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,MAAM,EAAW,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAW5C;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,OAAO,YAAa,SAAQ,aAAa;IACtC,MAAM,CAAS;IACN,QAAQ,GAAG,IAAI,GAAG,EAAc,CAAC,CAAC,+BAA+B;IACjE,YAAY,GAAG,IAAI,GAAG,EAAc,CAAC;IACrC,GAAG,CAAS;IACpB,KAAK,CAAU;IAChB,UAAU,GAAG,KAAK,CAAC;IAE3B,YAAoB,GAAW,EAAE,KAAc;QAC9C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC,EAAE,GAAG,CAAC,CAAC;IACtD,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAW,EAAE,IAAI,GAAwB,EAAE;QAC5D,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACpC,KAAK,MAAM,CAAC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EAAE;YAAE,SAAS,CAAC,EAAE,CAAC,CAAC;IAC5D,CAAC;CACD;AAED,SAAS,UAAU,CAAC,IAAY,EAAE,MAAc;IAC/C,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAChC,IAAI,CAAC;QACJ,aAAa,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IAC3B,CAAC;YAAS,CAAC;QACV,SAAS,CAAC,EAAE,CAAC,CAAC;IACf,CAAC;AACF,CAAC;AAED,8GAA8G;AAC9G,SAAS,gBAAgB,CAAC,IAAY;IACrC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;IACjC,IAAI,IAAI,KAAK,CAAC;QAAE,OAAO;IACvB,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAC/B,MAAM,GAAG,GAAG,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAClC,IAAI,GAAG,GAAG,CAAC,KAAK,GAAG,CAAC,MAAM;QAAE,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import {\n\tcloseSync,\n\texistsSync,\n\tfsyncSync,\n\tftruncateSync,\n\tmkdirSync,\n\topenSync,\n\treaddirSync,\n\treadFileSync,\n\trenameSync,\n\tstatSync,\n\tunlinkSync,\n\twriteSync,\n} from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { Context } from \"@earendil-works/chord\";\nimport { BACKGROUND_CONTEXT } from \"@earendil-works/chord/context\";\nimport { isBase, type Op } from \"@earendil-works/chord/delta\";\nimport { MemoryStorage } from \"./memory.ts\";\nimport type { DocRef, Id, Seq, Storage, Write } from \"./types.ts\";\n\n/** One line of any file. `refs` (main only) lists the sidecar files this commit also wrote. */\ninterface Record_ {\n\tseq: Seq;\n\tmaxId: Id;\n\twrites: Write[];\n\trefs?: string[];\n}\n\n/**\n * Files in a session directory:\n * main.jsonl conversations, entries, inputs, rewindable/session doc ops, each task's\n * CREATE and TERMINAL records, and one marker per commit. Append-only, never rewritten.\n * sticky-<conversation>.jsonl sticky doc ops; rewritten from its last base by `truncate` (on the Session line)\n * task-<id>.jsonl a live task's intermediate patches (running, checkpoints); unlinked after its\n * terminal record is published in main\n *\n * Publication (§10): one commit `Seq`; sidecar records are appended first, then exactly one main\n * record, last, listing the sidecar refs it expects — the publication point. Replay applies a sidecar\n * record only when main has the marker for that seq naming that file; unconfirmed sidecar tails are\n * ignored. Every record carries the committed-ID high-water. Bytes after the last newline of any file\n * are a torn write and are truncated before the file is opened for append. There is no compaction.\n *\n * With `fsync: false`, recovery covers process termination while the OS and filesystem remain alive.\n * It does not promise that an acknowledged commit survives power loss, kernel/host failure,\n * storage-cache loss, or a filesystem that loses/reorders completed writes. An acknowledged tail may\n * roll back, or a surviving main marker may reference a missing sidecar and make open fail rather\n * than expose partial state. A lost pre-effect checkpoint can cause an external effect to be attempted\n * again; external idempotency remains required.\n *\n * With `fsync: true`, each sidecar is flushed before the main publication marker is flushed. This\n * strengthens file-data durability and ordering across machine failure. It is not a complete database\n * guarantee: newly created files, renames, and unlinks are not followed by a parent-directory fsync,\n * and storage hardware/filesystems may provide weaker guarantees.\n *\n * One process owns a directory at a time; a second process is unsupported.\n */\nexport class JsonlStorage extends MemoryStorage implements Storage {\n\tprivate mainFd: number;\n\tprivate readonly sidecars = new Map<Id, number>(); // sticky docs, by conversation\n\tprivate readonly taskSidecars = new Map<Id, number>();\n\tprivate readonly dir: string;\n\treadonly fsync: boolean;\n\tprivate closedOnce = false;\n\n\tprivate constructor(dir: string, fsync: boolean) {\n\t\tsuper();\n\t\tthis.dir = dir;\n\t\tthis.fsync = fsync;\n\t\tthis.mainFd = openSync(join(dir, \"main.jsonl\"), \"a\");\n\t}\n\n\tstatic async open(dir: string, opts: { fsync?: boolean } = {}): Promise<JsonlStorage> {\n\t\tmkdirSync(dir, { recursive: true });\n\t\tfor (const f of readdirSync(dir)) if (f.endsWith(\".jsonl\")) truncateTornTail(join(dir, f));\n\t\tconst storage = new JsonlStorage(dir, opts.fsync ?? true);\n\t\ttry {\n\t\t\tawait storage.replay();\n\t\t\treturn storage;\n\t\t} catch (error) {\n\t\t\tawait storage.close();\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/** For tests and tooling: sizes of every file in the directory. */\n\tsizes(): { [file: string]: number } {\n\t\tconst out: { [file: string]: number } = {};\n\t\tfor (const f of readdirSync(this.dir)) out[f] = statSync(join(this.dir, f)).size;\n\t\treturn out;\n\t}\n\n\tprivate async replay() {\n\t\tconst read = (file: string): { record: Record_; end: number }[] => {\n\t\t\tif (!existsSync(file)) return [];\n\t\t\tconst bytes = readFileSync(file);\n\t\t\tconst out: { record: Record_; end: number }[] = [];\n\t\t\tlet start = 0;\n\t\t\tlet last = 0;\n\t\t\tfor (let end = bytes.indexOf(0x0a, start); end >= 0; end = bytes.indexOf(0x0a, start)) {\n\t\t\t\tconst line = bytes.subarray(start, end).toString(\"utf8\");\n\t\t\t\tstart = end + 1;\n\t\t\t\tif (line === \"\") continue;\n\t\t\t\tlet record: Record_;\n\t\t\t\ttry {\n\t\t\t\t\trecord = JSON.parse(line) as Record_;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthrow new Error(`${file}: malformed record: ${String(error)}`);\n\t\t\t\t}\n\t\t\t\tif (typeof record.seq !== \"number\" || typeof record.maxId !== \"number\" || !Array.isArray(record.writes))\n\t\t\t\t\tthrow new Error(`${file}: record lacks seq/maxId/writes`);\n\t\t\t\tif (record.seq <= last) throw new Error(`${file}: sequence not increasing at ${record.seq}`);\n\t\t\t\tlast = record.seq;\n\t\t\t\tout.push({ record, end: start });\n\t\t\t}\n\t\t\treturn out;\n\t\t};\n\t\tlet maxId = 0;\n\t\t// Main is the commit log. Confirmed = (seq → refs) for every marker.\n\t\tconst main = read(join(this.dir, \"main.jsonl\")).map(({ record }) => record);\n\t\tconst confirmed = new Map<Seq, Set<string>>();\n\t\tfor (const record of main) confirmed.set(record.seq, new Set(record.refs ?? []));\n\t\t// Merge every file's records by seq so batches apply in commit order.\n\t\tconst sidecarFiles = readdirSync(this.dir).filter(\n\t\t\t(file) => file.startsWith(\"sticky-\") || file.startsWith(\"task-\"),\n\t\t);\n\t\tconst bySeq = new Map<Seq, Write[]>();\n\t\tconst found = new Map<Seq, Set<string>>();\n\t\tconst retainedStickyBase = new Map<string, Seq>();\n\t\tconst retiredTasks = new Map<Id, Seq>();\n\t\tfor (const record of main) {\n\t\t\tfor (const write of record.writes) {\n\t\t\t\tif (write.type === \"task.patch\" && write.patch.status === \"terminal\")\n\t\t\t\t\tretiredTasks.set(write.patch.id, record.seq);\n\t\t\t}\n\t\t\tbySeq.set(record.seq, [...record.writes]);\n\t\t\tmaxId = Math.max(maxId, record.maxId);\n\t\t}\n\t\tfor (const file of sidecarFiles) {\n\t\t\tconst path = join(this.dir, file);\n\t\t\tconst records = read(path);\n\t\t\tconst first = records[0]?.record;\n\t\t\tif (\n\t\t\t\tfile.startsWith(\"sticky-\") &&\n\t\t\t\tfirst !== undefined &&\n\t\t\t\tisBase(first.writes.flatMap((write) => (write.type === \"doc\" ? write.ops : [])))\n\t\t\t) {\n\t\t\t\tretainedStickyBase.set(file, first.seq);\n\t\t\t}\n\t\t\tlet confirmedEnd = 0;\n\t\t\tlet sawUnconfirmed = false;\n\t\t\tfor (const { record, end } of records) {\n\t\t\t\tif (!confirmed.get(record.seq)?.has(file)) {\n\t\t\t\t\tsawUnconfirmed = true;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (sawUnconfirmed)\n\t\t\t\t\tthrow new Error(`${path}: confirmed record follows an unconfirmed tail at ${record.seq}`);\n\t\t\t\tconfirmedEnd = end;\n\t\t\t\tconst files = found.get(record.seq) ?? new Set<string>();\n\t\t\t\tfiles.add(file);\n\t\t\t\tfound.set(record.seq, files);\n\t\t\t\tbySeq.get(record.seq)!.push(...record.writes);\n\t\t\t\tmaxId = Math.max(maxId, record.maxId);\n\t\t\t}\n\t\t\tif (sawUnconfirmed) truncateTo(path, confirmedEnd);\n\t\t}\n\t\tfor (const record of main) {\n\t\t\tfor (const file of record.refs ?? []) {\n\t\t\t\tif (found.get(record.seq)?.has(file)) continue;\n\t\t\t\tconst retainedFrom = retainedStickyBase.get(file);\n\t\t\t\tif (retainedFrom !== undefined && record.seq < retainedFrom) continue;\n\t\t\t\tif (file.startsWith(\"task-\")) {\n\t\t\t\t\tconst id = Number(file.slice(5, -6));\n\t\t\t\t\tconst retiredAt = retiredTasks.get(id);\n\t\t\t\t\tif (retiredAt !== undefined && record.seq < retiredAt) continue;\n\t\t\t\t}\n\t\t\t\tthrow new Error(`${join(this.dir, file)}: missing record for published sequence ${record.seq}`);\n\t\t\t}\n\t\t}\n\t\tfor (const seq of [...bySeq.keys()].sort((a, b) => a - b)) {\n\t\t\tthis.seq = seq - 1;\n\t\t\tawait super.commit(bySeq.get(seq)!, BACKGROUND_CONTEXT);\n\t\t}\n\t\tthis.setNextId(maxId + 1);\n\t\t// Task sidecars belong to live tasks only; a leftover for a terminal (or unknown) task cannot resurrect anything.\n\t\tfor (const f of sidecarFiles) {\n\t\t\tif (!f.startsWith(\"task-\")) continue;\n\t\t\tconst id = Number(f.slice(5, -6));\n\t\t\tconst t = await super.task(id);\n\t\t\tif (t === undefined || t.status === \"terminal\") unlinkSync(join(this.dir, f));\n\t\t}\n\t}\n\n\toverride async commit(writes: readonly Write[], ctx: Context): Promise<Seq> {\n\t\tif (this.closedOnce) throw new Error(\"storage closed\");\n\t\tconst seq = this.seq + 1;\n\t\tconst apply = this.stage(writes, seq); // validates the whole batch first; throws before any file is touched\n\t\tconst maxId = this.nextIdAfter(writes);\n\t\tconst main: Write[] = [];\n\t\tconst sticky = new Map<Id, Write[]>();\n\t\tconst tasks = new Map<Id, Write[]>();\n\t\tconst retired: Id[] = [];\n\t\tfor (const w of writes) {\n\t\t\tif (w.type === \"doc\" && w.ref.doc === \"sticky\")\n\t\t\t\t(sticky.get(w.ref.conversationId) ?? sticky.set(w.ref.conversationId, []).get(w.ref.conversationId)!).push(\n\t\t\t\t\tw,\n\t\t\t\t);\n\t\t\telse if (w.type === \"task.patch\" && w.patch.status !== \"terminal\")\n\t\t\t\t(tasks.get(w.patch.id) ?? tasks.set(w.patch.id, []).get(w.patch.id)!).push(w);\n\t\t\telse {\n\t\t\t\tmain.push(w);\n\t\t\t\tif (w.type === \"task.patch\" && w.patch.status === \"terminal\") retired.push(w.patch.id);\n\t\t\t}\n\t\t}\n\t\tconst refs: string[] = [];\n\t\tfor (const [id, ws] of tasks) {\n\t\t\tthis.append(this.taskSidecar(id), { seq, maxId, writes: ws });\n\t\t\trefs.push(`task-${id}.jsonl`);\n\t\t}\n\t\tfor (const [c, ws] of sticky) {\n\t\t\tthis.append(this.sidecar(c), { seq, maxId, writes: ws });\n\t\t\trefs.push(`sticky-${c}.jsonl`);\n\t\t}\n\t\tthis.append(this.mainFd, { seq, maxId, writes: main, ...(refs.length ? { refs } : {}) }); // the publication point\n\t\tapply();\n\t\tthis.seq = seq;\n\t\tfor (const id of retired) this.retireTaskSidecar(id); // after the terminal record is durably published\n\t\tvoid ctx;\n\t\treturn seq;\n\t}\n\tprivate nextIdAfter(writes: readonly Write[]): Id {\n\t\tlet max = this.nextIdValue - 1;\n\t\tfor (const w of writes) {\n\t\t\tconst id =\n\t\t\t\tw.type === \"conversation\"\n\t\t\t\t\t? w.conversation.id\n\t\t\t\t\t: w.type === \"entry\"\n\t\t\t\t\t\t? w.entry.id\n\t\t\t\t\t\t: w.type === \"task\"\n\t\t\t\t\t\t\t? w.task.id\n\t\t\t\t\t\t\t: w.type === \"input\"\n\t\t\t\t\t\t\t\t? w.input.id\n\t\t\t\t\t\t\t\t: 0;\n\t\t\tmax = Math.max(max, id);\n\t\t}\n\t\treturn max;\n\t}\n\n\tprivate append(fd: number, record: Record_) {\n\t\twriteSync(fd, `${JSON.stringify(record)}\\n`);\n\t\tif (this.fsync) fsyncSync(fd);\n\t}\n\n\tprivate sidecar(conversationId: Id): number {\n\t\tlet fd = this.sidecars.get(conversationId);\n\t\tif (fd === undefined) {\n\t\t\tfd = openSync(join(this.dir, `sticky-${conversationId}.jsonl`), \"a\");\n\t\t\tthis.sidecars.set(conversationId, fd);\n\t\t}\n\t\treturn fd;\n\t}\n\tprivate taskSidecar(id: Id): number {\n\t\tlet fd = this.taskSidecars.get(id);\n\t\tif (fd === undefined) {\n\t\t\tfd = openSync(join(this.dir, `task-${id}.jsonl`), \"a\");\n\t\t\tthis.taskSidecars.set(id, fd);\n\t\t}\n\t\treturn fd;\n\t}\n\tprivate retireTaskSidecar(id: Id) {\n\t\tconst fd = this.taskSidecars.get(id);\n\t\tif (fd !== undefined) closeSync(fd);\n\t\tthis.taskSidecars.delete(id);\n\t\ttry {\n\t\t\tunlinkSync(join(this.dir, `task-${id}.jsonl`));\n\t\t} catch {}\n\t}\n\n\t/** Rewrite the sticky sidecar from its last base: temp file, optional fsync, rename. Called on the Session line. */\n\toverride async truncate(ref: DocRef, _ctx?: Context): Promise<void> {\n\t\tawait super.truncate(ref);\n\t\tif (ref.doc !== \"sticky\") return;\n\t\tconst file = join(this.dir, `sticky-${ref.conversationId}.jsonl`);\n\t\tif (!existsSync(file)) return;\n\t\tconst lines = readFileSync(file, \"utf8\").split(\"\\n\").filter(Boolean);\n\t\tlet start = 0;\n\t\tfor (let i = lines.length - 1; i >= 0; i--)\n\t\t\tif (\n\t\t\t\tisBase((JSON.parse(lines[i]!) as Record_).writes.flatMap((w) => (w.type === \"doc\" ? w.ops : [])) as Op[])\n\t\t\t) {\n\t\t\t\tstart = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\tif (start === 0) return;\n\t\tconst tmp = `${file}.tmp`;\n\t\tconst fd = openSync(tmp, \"w\");\n\t\twriteSync(\n\t\t\tfd,\n\t\t\tlines\n\t\t\t\t.slice(start)\n\t\t\t\t.map((l) => `${l}\\n`)\n\t\t\t\t.join(\"\"),\n\t\t);\n\t\tif (this.fsync) fsyncSync(fd);\n\t\tcloseSync(fd);\n\t\tconst old = this.sidecars.get(ref.conversationId);\n\t\tif (old !== undefined) closeSync(old);\n\t\trenameSync(tmp, file);\n\t\tthis.sidecars.set(ref.conversationId, openSync(file, \"a\"));\n\t}\n\n\toverride async close(_ctx?: Context) {\n\t\tif (this.closedOnce) return;\n\t\tthis.closedOnce = true;\n\t\tawait super.close();\n\t\tcloseSync(this.mainFd);\n\t\tfor (const fd of this.sidecars.values()) closeSync(fd);\n\t\tfor (const fd of this.taskSidecars.values()) closeSync(fd);\n\t}\n}\n\nfunction truncateTo(file: string, length: number): void {\n\tconst fd = openSync(file, \"r+\");\n\ttry {\n\t\tftruncateSync(fd, length);\n\t} finally {\n\t\tcloseSync(fd);\n\t}\n}\n\n/** Bytes after the last newline are a torn write: cut them so a later append cannot extend a corrupt line. */\nfunction truncateTornTail(file: string) {\n\tconst size = statSync(file).size;\n\tif (size === 0) return;\n\tconst buf = readFileSync(file);\n\tconst end = buf.lastIndexOf(0x0a);\n\tif (end + 1 !== buf.length) truncateTo(file, end + 1);\n}\n"]}
@@ -1,49 +0,0 @@
1
- import type { Context } from "@earendil-works/chord";
2
- import { type CoreKind, type Entry, type HookInfo, type HookResult, type Id, type ModelRef, type RetryPolicy, type ThinkingLevel } from "../types.ts";
3
- export type CollapseInput = {
4
- reason: "threshold" | "manual" | "overflow";
5
- through: Id;
6
- instructions?: string;
7
- };
8
- type Base = {
9
- expectedHead: Id | null;
10
- instructions?: string;
11
- model: ModelRef;
12
- thinkingLevel: ThinkingLevel;
13
- retry: RetryPolicy;
14
- attempt: number;
15
- };
16
- export type CollapseCheckpoint = ({
17
- phase: "summarizing";
18
- } & Base) | ({
19
- phase: "retrying";
20
- untilMs: number;
21
- lastError: string;
22
- } & Base) | ({
23
- phase: "prepared";
24
- summary: string;
25
- } & Base);
26
- export type CollapseFailure = {
27
- reason: "stale" | "declined" | "provider" | "retries_exhausted" | "no_model";
28
- detail: string;
29
- };
30
- export interface CollapseHooks {
31
- beforeCollapse(reason: "threshold" | "manual" | "overflow", through: Id, entries: Entry[], info: HookInfo, ctx: Context): HookResult<{
32
- decline: true;
33
- } | {
34
- instructions?: string;
35
- summary?: string;
36
- }>;
37
- }
38
- export declare const collapseConfig: {
39
- readonly rewindable: {
40
- readonly threshold: number;
41
- readonly keepRecent: number;
42
- };
43
- };
44
- export declare const collapse: CoreKind<CollapseInput, CollapseCheckpoint, {
45
- summary: Id;
46
- }, CollapseFailure, null, CollapseHooks, typeof collapseConfig>;
47
- export declare function chooseThrough(entries: Entry[], keepRecent: number): Id | undefined;
48
- export {};
49
- //# sourceMappingURL=collapse.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"collapse.d.ts","sourceRoot":"","sources":["../../../../src/harness/pico3/kinds/collapse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAIrD,OAAO,EAEN,KAAK,QAAQ,EAEb,KAAK,KAAK,EACV,KAAK,QAAQ,EACb,KAAK,UAAU,EACf,KAAK,EAAE,EACP,KAAK,QAAQ,EAEb,KAAK,WAAW,EAKhB,KAAK,aAAa,EAElB,MAAM,aAAa,CAAC;AAQrB,MAAM,MAAM,aAAa,GAAG;IAAE,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAChH,KAAK,IAAI,GAAG;IACX,YAAY,EAAE,EAAE,GAAG,IAAI,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,QAAQ,CAAC;IAChB,aAAa,EAAE,aAAa,CAAC;IAC7B,KAAK,EAAE,WAAW,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CAChB,CAAC;AACF,MAAM,MAAM,kBAAkB,GAC3B,CAAC;IAAE,KAAK,EAAE,aAAa,CAAA;CAAE,GAAG,IAAI,CAAC,GACjC,CAAC;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,GAClE,CAAC;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAAC;AACnD,MAAM,MAAM,eAAe,GAAG;IAC7B,MAAM,EAAE,OAAO,GAAG,UAAU,GAAG,UAAU,GAAG,mBAAmB,GAAG,UAAU,CAAC;IAC7E,MAAM,EAAE,MAAM,CAAC;CACf,CAAC;AACF,MAAM,WAAW,aAAa;IAC7B,cAAc,CACb,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,UAAU,EAC3C,OAAO,EAAE,EAAE,EACX,OAAO,EAAE,KAAK,EAAE,EAChB,IAAI,EAAE,QAAQ,EACd,GAAG,EAAE,OAAO,GACV,UAAU,CAAC;QAAE,OAAO,EAAE,IAAI,CAAA;KAAE,GAAG;QAAE,YAAY,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC/E;AACD,eAAO,MAAM,cAAc;aAAK,UAAU;iBAAI,SAAS,EAAO,MAAM;iBAAE,UAAU,EAAY,MAAM;;CAAa,CAAC;AAwBhH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAC9B,aAAa,EACb,kBAAkB,EAClB;IAAE,OAAO,EAAE,EAAE,CAAA;CAAE,EACf,eAAe,EACf,IAAI,EACJ,aAAa,EACb,OAAO,cAAc,CA4ErB,CAAC;AAwFF,wBAAgB,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,EAAE,GAAG,SAAS,CAuBlF"}
@@ -1,191 +0,0 @@
1
- import { estimateContextTokens } from "@earendil-works/pi-ai/utils/estimate";
2
- import { effectiveTools } from "../system.js";
3
- import { toStored, } from "../types.js";
4
- import { retryDecision } from "./generation.js";
5
- const estimate = (messages) => estimateContextTokens(messages.filter((message) => message.role !== "system")).tokens;
6
- export const collapseConfig = { rewindable: { threshold: 0, keepRecent: 20_000 } };
7
- const failed = (reason, detail) => ({
8
- status: "failed",
9
- failure: { reason, detail },
10
- });
11
- const baseOf = (checkpoint) => {
12
- const { phase: _phase, ...rest } = checkpoint;
13
- const { untilMs: _untilMs, lastError: _lastError, summary: _summary, ...base } = rest;
14
- return base;
15
- };
16
- export const collapse = {
17
- name: "pi.collapse",
18
- config: collapseConfig,
19
- inflight: ["summarizing"],
20
- async initial(task, runtime, ctx) {
21
- const state = await runtime.rewindable(task.conversationId, ctx);
22
- if (state.model === undefined)
23
- return { done: () => failed("no_model", "no model configured") };
24
- const sticky = await runtime.sticky(task.conversationId, ctx);
25
- const head = await runtime.newestEntry(task.conversationId, { withHead: true }, ctx);
26
- const { entries } = await runtime.context(task.conversationId, task.input.through, ctx);
27
- let decision = {};
28
- await runtime.hooks.each(ctx, (hook, api) => hook.beforeCollapse?.(task.input.reason, task.input.through, entries, api, ctx), (value) => {
29
- if (value === undefined)
30
- return;
31
- decision = value;
32
- return true;
33
- });
34
- if ("decline" in decision)
35
- return { done: () => failed("declined", "declined by beforeCollapse") };
36
- const choice = decision;
37
- const base = {
38
- expectedHead: head?.id ?? null,
39
- ...((choice.instructions ?? task.input.instructions)
40
- ? { instructions: choice.instructions ?? task.input.instructions }
41
- : {}),
42
- model: state.model,
43
- thinkingLevel: state.thinkingLevel,
44
- retry: sticky.retry,
45
- attempt: 1,
46
- };
47
- if (choice.summary !== undefined) {
48
- return {
49
- next: async (tx, current) => (await headMoved(tx, current.conversationId, base))
50
- ? failed("stale", "head moved during beforeCollapse")
51
- : { phase: "prepared", summary: choice.summary, ...base },
52
- };
53
- }
54
- return summarizeNow(task, base, runtime, ctx, "check head");
55
- },
56
- phases: {
57
- async summarizing(task, runtime) {
58
- return afterFailure(baseOf(task.checkpoint), null, "interrupted", runtime);
59
- },
60
- async retrying(task, runtime, ctx) {
61
- await runtime.sleep(task.checkpoint.untilMs, ctx);
62
- return summarizeNow(task, { ...baseOf(task.checkpoint), attempt: task.checkpoint.attempt + 1 }, runtime, ctx);
63
- },
64
- async prepared(task, runtime) {
65
- const { summary } = task.checkpoint;
66
- const base = baseOf(task.checkpoint);
67
- return {
68
- done: async (tx, current) => {
69
- const { head, entries } = await tx.context(current.conversationId);
70
- if ((head?.id ?? null) !== base.expectedHead)
71
- return failed("stale", "head moved during collapse");
72
- const retained = entries.find((entry) => entry.id > task.input.through);
73
- const id = tx.appendEntry(current.conversationId, {
74
- kind: "pi.summary",
75
- data: { through: task.input.through },
76
- model: [{ role: "user", content: summary, timestamp: runtime.now() }],
77
- head: retained?.id ?? "self",
78
- });
79
- return { status: "completed", result: { summary: id } };
80
- },
81
- };
82
- },
83
- },
84
- async abort() {
85
- return async () => null;
86
- },
87
- };
88
- const headMoved = async (tx, conversationId, base) => ((await tx.newestEntry(conversationId, { withHead: true }))?.id ?? null) !== base.expectedHead;
89
- async function summarizeNow(task, base, runtime, ctx, check) {
90
- const stale = await runtime.commit(async (tx, current) => {
91
- if (check && (await headMoved(tx, current.conversationId, base)))
92
- return true;
93
- tx.checkpoint({ phase: "summarizing", ...base });
94
- return false;
95
- }, ctx);
96
- if (stale)
97
- return { done: () => failed("stale", "head moved during beforeCollapse") };
98
- const model = runtime.models.resolve(base.model);
99
- if (model === undefined)
100
- return { done: () => failed("no_model", "model unavailable") };
101
- const { messages } = await runtime.context(task.conversationId, task.input.through, ctx);
102
- const tools = effectiveTools(messages);
103
- const request = [
104
- ...messages,
105
- ...(tools.length > 0
106
- ? [toStored({ role: "system", content: "", toolsRemoved: tools, timestamp: runtime.now() })]
107
- : []),
108
- {
109
- role: "user",
110
- content: `${base.instructions ?? "Summarize the conversation so far for continuation."}\n\nRespond with the summary only.`,
111
- timestamp: runtime.now(),
112
- },
113
- ];
114
- let message;
115
- try {
116
- for await (const event of runtime.models.stream(model, { messages: request, thinkingLevel: base.thinkingLevel }, ctx)) {
117
- if (event.type === "done") {
118
- message = event.message;
119
- break;
120
- }
121
- if (event.type === "error") {
122
- message = event.error;
123
- break;
124
- }
125
- }
126
- }
127
- catch (error) {
128
- if (ctx.abortSignal?.aborted)
129
- throw error;
130
- return afterFailure(base, null, String(error), runtime);
131
- }
132
- if (message === undefined)
133
- return afterFailure(base, null, "no message", runtime);
134
- if (message.content.some((content) => content.type === "toolCall")) {
135
- return afterFailure(base, { ...message, stopReason: "error" }, "summarizer returned tool calls", runtime);
136
- }
137
- if (message.stopReason === "error")
138
- return afterFailure(base, message, message.errorMessage ?? "provider error", runtime);
139
- const summary = message.content
140
- .filter((content) => content.type === "text")
141
- .map((content) => content.text)
142
- .join("");
143
- return { next: { phase: "prepared", summary, ...base } };
144
- }
145
- function afterFailure(base, message, detail, runtime) {
146
- const decision = retryDecision(base, message, runtime.now());
147
- if (decision.kind === "fail")
148
- return { done: () => failed(decision.reason, detail) };
149
- return {
150
- next: (tx, current) => {
151
- tx.emit({
152
- type: "compaction.retrying",
153
- taskId: current.id,
154
- attempt: base.attempt,
155
- retryAt: decision.untilMs,
156
- error: detail,
157
- });
158
- return { phase: "retrying", ...base, untilMs: decision.untilMs, lastError: detail };
159
- },
160
- };
161
- }
162
- export function chooseThrough(entries, keepRecent) {
163
- const exchanges = [];
164
- let open;
165
- for (const entry of entries) {
166
- const role = entry.model?.[0]?.role;
167
- const tokens = estimate((entry.model ?? []));
168
- if (role === "assistant") {
169
- open = { last: entry.id, tokens };
170
- exchanges.push(open);
171
- }
172
- else if (role === "toolResult" && open) {
173
- open.last = entry.id;
174
- open.tokens += tokens;
175
- }
176
- else {
177
- open = undefined;
178
- exchanges.push({ last: entry.id, tokens });
179
- }
180
- }
181
- let retained = 0;
182
- let index = exchanges.length - 1;
183
- while (index >= 0 && retained + exchanges[index].tokens <= keepRecent)
184
- retained += exchanges[index--].tokens;
185
- if (index < 0)
186
- return undefined;
187
- if (index === exchanges.length - 1)
188
- return exchanges[index - 1]?.last;
189
- return exchanges[index].last;
190
- }
191
- //# sourceMappingURL=collapse.js.map