@earendil-works/pi-agent-core 0.87.0 → 0.99.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (242) hide show
  1. package/README.md +4 -0
  2. package/dist/agent-loop.d.ts +27 -2
  3. package/dist/agent-loop.d.ts.map +1 -1
  4. package/dist/agent-loop.js +44 -15
  5. package/dist/agent-loop.js.map +1 -1
  6. package/dist/agent.d.ts +9 -0
  7. package/dist/agent.d.ts.map +1 -1
  8. package/dist/agent.js +3 -0
  9. package/dist/agent.js.map +1 -1
  10. package/dist/harness/agent-harness.d.ts.map +1 -1
  11. package/dist/harness/compaction/branch-summarization.d.ts.map +1 -1
  12. package/dist/harness/compaction/branch-summarization.js.map +1 -1
  13. package/dist/harness/compaction/compaction.d.ts.map +1 -1
  14. package/dist/harness/compaction/compaction.js.map +1 -1
  15. package/dist/harness/compaction/utils.d.ts.map +1 -1
  16. package/dist/harness/compaction/utils.js.map +1 -1
  17. package/dist/harness/config.d.ts.map +1 -1
  18. package/dist/harness/config.js.map +1 -1
  19. package/dist/harness/context.d.ts.map +1 -1
  20. package/dist/harness/context.js.map +1 -1
  21. package/dist/harness/env/nodejs.d.ts.map +1 -1
  22. package/dist/harness/env/nodejs.js.map +1 -1
  23. package/dist/harness/events.d.ts.map +1 -1
  24. package/dist/harness/events.js.map +1 -1
  25. package/dist/harness/execution/assistant.d.ts.map +1 -1
  26. package/dist/harness/execution/assistant.js.map +1 -1
  27. package/dist/harness/execution/effect-gate.d.ts.map +1 -1
  28. package/dist/harness/execution/effect-gate.js.map +1 -1
  29. package/dist/harness/execution/tools.d.ts.map +1 -1
  30. package/dist/harness/execution/tools.js.map +1 -1
  31. package/dist/harness/hooks.d.ts.map +1 -1
  32. package/dist/harness/hooks.js.map +1 -1
  33. package/dist/harness/messages.d.ts.map +1 -1
  34. package/dist/harness/messages.js.map +1 -1
  35. package/dist/harness/pico3/bash.d.ts.map +1 -1
  36. package/dist/harness/pico3/bash.js.map +1 -1
  37. package/dist/harness/pico3/bounded.d.ts.map +1 -1
  38. package/dist/harness/pico3/bounded.js.map +1 -1
  39. package/dist/harness/pico3/chord.d.ts.map +1 -1
  40. package/dist/harness/pico3/chord.js.map +1 -1
  41. package/dist/harness/pico3/context.d.ts.map +1 -1
  42. package/dist/harness/pico3/context.js.map +1 -1
  43. package/dist/harness/pico3/harness.d.ts +4 -3
  44. package/dist/harness/pico3/harness.d.ts.map +1 -1
  45. package/dist/harness/pico3/harness.js.map +1 -1
  46. package/dist/harness/pico3/hooks.d.ts +2 -2
  47. package/dist/harness/pico3/hooks.d.ts.map +1 -1
  48. package/dist/harness/pico3/hooks.js.map +1 -1
  49. package/dist/harness/pico3/index.d.ts.map +1 -1
  50. package/dist/harness/pico3/jsonl.d.ts.map +1 -1
  51. package/dist/harness/pico3/jsonl.js.map +1 -1
  52. package/dist/harness/pico3/kinds/collapse.d.ts.map +1 -1
  53. package/dist/harness/pico3/kinds/collapse.js.map +1 -1
  54. package/dist/harness/pico3/kinds/entries.d.ts.map +1 -1
  55. package/dist/harness/pico3/kinds/frames.d.ts.map +1 -1
  56. package/dist/harness/pico3/kinds/frames.js.map +1 -1
  57. package/dist/harness/pico3/kinds/generation.d.ts.map +1 -1
  58. package/dist/harness/pico3/kinds/generation.js.map +1 -1
  59. package/dist/harness/pico3/kinds/job.d.ts.map +1 -1
  60. package/dist/harness/pico3/kinds/job.js.map +1 -1
  61. package/dist/harness/pico3/kinds/plugin.d.ts.map +1 -1
  62. package/dist/harness/pico3/kinds/plugin.js.map +1 -1
  63. package/dist/harness/pico3/kinds/post-tools.d.ts.map +1 -1
  64. package/dist/harness/pico3/kinds/post-tools.js.map +1 -1
  65. package/dist/harness/pico3/kinds/task-api.d.ts.map +1 -1
  66. package/dist/harness/pico3/kinds/task-api.js.map +1 -1
  67. package/dist/harness/pico3/kinds/tool.d.ts.map +1 -1
  68. package/dist/harness/pico3/kinds/tool.js.map +1 -1
  69. package/dist/harness/pico3/legacy-tracker.d.ts +11 -0
  70. package/dist/harness/pico3/legacy-tracker.d.ts.map +1 -0
  71. package/dist/harness/pico3/legacy-tracker.js +41 -0
  72. package/dist/harness/pico3/legacy-tracker.js.map +1 -0
  73. package/dist/harness/pico3/membrane.d.ts.map +1 -1
  74. package/dist/harness/pico3/membrane.js.map +1 -1
  75. package/dist/harness/pico3/memory.d.ts +1 -1
  76. package/dist/harness/pico3/memory.d.ts.map +1 -1
  77. package/dist/harness/pico3/memory.js.map +1 -1
  78. package/dist/harness/pico3/scheduler.d.ts +3 -0
  79. package/dist/harness/pico3/scheduler.d.ts.map +1 -1
  80. package/dist/harness/pico3/scheduler.js.map +1 -1
  81. package/dist/harness/pico3/session.d.ts +3 -2
  82. package/dist/harness/pico3/session.d.ts.map +1 -1
  83. package/dist/harness/pico3/session.js +5 -4
  84. package/dist/harness/pico3/session.js.map +1 -1
  85. package/dist/harness/pico3/system.d.ts +1 -1
  86. package/dist/harness/pico3/system.d.ts.map +1 -1
  87. package/dist/harness/pico3/system.js.map +1 -1
  88. package/dist/harness/pico3/types.d.ts +1 -1
  89. package/dist/harness/pico3/types.d.ts.map +1 -1
  90. package/dist/harness/pico3/types.js.map +1 -1
  91. package/dist/harness/pico3/view.d.ts.map +1 -1
  92. package/dist/harness/pico3/view.js +6 -12
  93. package/dist/harness/pico3/view.js.map +1 -1
  94. package/dist/harness/prompt-templates.d.ts.map +1 -1
  95. package/dist/harness/prompt-templates.js.map +1 -1
  96. package/dist/harness/result.d.ts.map +1 -1
  97. package/dist/harness/result.js.map +1 -1
  98. package/dist/harness/runtime/drive/boundary.d.ts.map +1 -1
  99. package/dist/harness/runtime/drive/boundary.js.map +1 -1
  100. package/dist/harness/runtime/drive/checkpoint.d.ts.map +1 -1
  101. package/dist/harness/runtime/drive/checkpoint.js.map +1 -1
  102. package/dist/harness/runtime/drive/deferred.d.ts.map +1 -1
  103. package/dist/harness/runtime/drive/deferred.js.map +1 -1
  104. package/dist/harness/runtime/drive/generation.d.ts.map +1 -1
  105. package/dist/harness/runtime/drive/generation.js.map +1 -1
  106. package/dist/harness/runtime/drive/reconcile.d.ts.map +1 -1
  107. package/dist/harness/runtime/drive/reconcile.js.map +1 -1
  108. package/dist/harness/runtime/drive/recovery.d.ts.map +1 -1
  109. package/dist/harness/runtime/drive/recovery.js.map +1 -1
  110. package/dist/harness/runtime/drive/response.d.ts.map +1 -1
  111. package/dist/harness/runtime/drive/response.js.map +1 -1
  112. package/dist/harness/runtime/drive/retry.d.ts.map +1 -1
  113. package/dist/harness/runtime/drive/retry.js.map +1 -1
  114. package/dist/harness/runtime/drive/structural.d.ts.map +1 -1
  115. package/dist/harness/runtime/drive/structural.js.map +1 -1
  116. package/dist/harness/runtime/drive/terminal.d.ts.map +1 -1
  117. package/dist/harness/runtime/drive/terminal.js.map +1 -1
  118. package/dist/harness/runtime/drive/tool-placement.d.ts.map +1 -1
  119. package/dist/harness/runtime/drive/tool-placement.js.map +1 -1
  120. package/dist/harness/runtime/drive/tools.d.ts.map +1 -1
  121. package/dist/harness/runtime/drive/tools.js.map +1 -1
  122. package/dist/harness/runtime/drive.d.ts.map +1 -1
  123. package/dist/harness/runtime/drive.js.map +1 -1
  124. package/dist/harness/runtime/harness.d.ts.map +1 -1
  125. package/dist/harness/runtime/harness.js.map +1 -1
  126. package/dist/harness/runtime/index.d.ts.map +1 -1
  127. package/dist/harness/runtime/lane.d.ts +17 -0
  128. package/dist/harness/runtime/lane.d.ts.map +1 -1
  129. package/dist/harness/runtime/lane.js.map +1 -1
  130. package/dist/harness/runtime/progress.d.ts.map +1 -1
  131. package/dist/harness/runtime/progress.js.map +1 -1
  132. package/dist/harness/runtime/reducer.d.ts.map +1 -1
  133. package/dist/harness/runtime/reducer.js.map +1 -1
  134. package/dist/harness/runtime/restore.d.ts.map +1 -1
  135. package/dist/harness/runtime/restore.js.map +1 -1
  136. package/dist/harness/runtime/transcript.d.ts.map +1 -1
  137. package/dist/harness/runtime/transcript.js.map +1 -1
  138. package/dist/harness/runtime/types.d.ts.map +1 -1
  139. package/dist/harness/runtime/types.js.map +1 -1
  140. package/dist/harness/session/commit.d.ts.map +1 -1
  141. package/dist/harness/session/commit.js.map +1 -1
  142. package/dist/harness/session/context.d.ts.map +1 -1
  143. package/dist/harness/session/context.js.map +1 -1
  144. package/dist/harness/session/fork-policy.d.ts.map +1 -1
  145. package/dist/harness/session/fork-policy.js.map +1 -1
  146. package/dist/harness/session/fork.d.ts.map +1 -1
  147. package/dist/harness/session/fork.js.map +1 -1
  148. package/dist/harness/session/in-memory-storage-state.d.ts.map +1 -1
  149. package/dist/harness/session/in-memory-storage-state.js.map +1 -1
  150. package/dist/harness/session/index.d.ts.map +1 -1
  151. package/dist/harness/session/jsonl/codec.d.ts.map +1 -1
  152. package/dist/harness/session/jsonl/codec.js.map +1 -1
  153. package/dist/harness/session/jsonl/fork.d.ts.map +1 -1
  154. package/dist/harness/session/jsonl/fork.js.map +1 -1
  155. package/dist/harness/session/jsonl/index.d.ts.map +1 -1
  156. package/dist/harness/session/jsonl/io.d.ts.map +1 -1
  157. package/dist/harness/session/jsonl/io.js.map +1 -1
  158. package/dist/harness/session/jsonl/legacy-v3.d.ts +1 -0
  159. package/dist/harness/session/jsonl/legacy-v3.d.ts.map +1 -1
  160. package/dist/harness/session/jsonl/legacy-v3.js.map +1 -1
  161. package/dist/harness/session/jsonl/repo.d.ts.map +1 -1
  162. package/dist/harness/session/jsonl/repo.js.map +1 -1
  163. package/dist/harness/session/jsonl/storage.d.ts +1 -0
  164. package/dist/harness/session/jsonl/storage.d.ts.map +1 -1
  165. package/dist/harness/session/jsonl/storage.js.map +1 -1
  166. package/dist/harness/session/jsonl/types.d.ts.map +1 -1
  167. package/dist/harness/session/memory.d.ts.map +1 -1
  168. package/dist/harness/session/memory.js.map +1 -1
  169. package/dist/harness/session/mutation-line.d.ts.map +1 -1
  170. package/dist/harness/session/mutation-line.js.map +1 -1
  171. package/dist/harness/session/session.d.ts.map +1 -1
  172. package/dist/harness/session/session.js.map +1 -1
  173. package/dist/harness/session/testing/benchmark/datasets.d.ts.map +1 -1
  174. package/dist/harness/session/testing/benchmark/datasets.js.map +1 -1
  175. package/dist/harness/session/testing/benchmark/session-repo.d.ts.map +1 -1
  176. package/dist/harness/session/testing/benchmark/session-repo.js.map +1 -1
  177. package/dist/harness/session/testing/benchmark/storage.d.ts.map +1 -1
  178. package/dist/harness/session/testing/benchmark/storage.js.map +1 -1
  179. package/dist/harness/session/testing/conformance/session-repo.d.ts.map +1 -1
  180. package/dist/harness/session/testing/conformance/session-repo.js.map +1 -1
  181. package/dist/harness/session/testing/conformance/storage.d.ts.map +1 -1
  182. package/dist/harness/session/testing/conformance/storage.js.map +1 -1
  183. package/dist/harness/session/testing/gating-storage.d.ts.map +1 -1
  184. package/dist/harness/session/testing/gating-storage.js.map +1 -1
  185. package/dist/harness/session/testing/index.d.ts.map +1 -1
  186. package/dist/harness/session/testing/instrumented-storage.d.ts.map +1 -1
  187. package/dist/harness/session/testing/instrumented-storage.js.map +1 -1
  188. package/dist/harness/session/testing/storage-decorator.d.ts.map +1 -1
  189. package/dist/harness/session/testing/storage-decorator.js.map +1 -1
  190. package/dist/harness/session/testing/types.d.ts.map +1 -1
  191. package/dist/harness/session/types.d.ts.map +1 -1
  192. package/dist/harness/session/types.js.map +1 -1
  193. package/dist/harness/session/values.d.ts +2 -2
  194. package/dist/harness/session/values.d.ts.map +1 -1
  195. package/dist/harness/session/values.js.map +1 -1
  196. package/dist/harness/skills.d.ts.map +1 -1
  197. package/dist/harness/skills.js.map +1 -1
  198. package/dist/harness/system-prompt.d.ts.map +1 -1
  199. package/dist/harness/system-prompt.js.map +1 -1
  200. package/dist/harness/telemetry.d.ts.map +1 -1
  201. package/dist/harness/telemetry.js.map +1 -1
  202. package/dist/harness/tools/bash.d.ts.map +1 -1
  203. package/dist/harness/tools/bash.js.map +1 -1
  204. package/dist/harness/tools/edit-diff.d.ts.map +1 -1
  205. package/dist/harness/tools/edit-diff.js.map +1 -1
  206. package/dist/harness/tools/edit.d.ts.map +1 -1
  207. package/dist/harness/tools/edit.js.map +1 -1
  208. package/dist/harness/tools/file-mutation-queue.d.ts.map +1 -1
  209. package/dist/harness/tools/file-mutation-queue.js.map +1 -1
  210. package/dist/harness/tools/image.d.ts.map +1 -1
  211. package/dist/harness/tools/image.js.map +1 -1
  212. package/dist/harness/tools/index.d.ts.map +1 -1
  213. package/dist/harness/tools/path-utils.d.ts.map +1 -1
  214. package/dist/harness/tools/path-utils.js.map +1 -1
  215. package/dist/harness/tools/read.d.ts.map +1 -1
  216. package/dist/harness/tools/read.js.map +1 -1
  217. package/dist/harness/tools/tool-context.d.ts.map +1 -1
  218. package/dist/harness/tools/write.d.ts.map +1 -1
  219. package/dist/harness/tools/write.js.map +1 -1
  220. package/dist/harness/types.d.ts.map +1 -1
  221. package/dist/harness/types.js.map +1 -1
  222. package/dist/harness/utils/adaptive-publisher.d.ts.map +1 -1
  223. package/dist/harness/utils/adaptive-publisher.js.map +1 -1
  224. package/dist/harness/utils/output-capture.d.ts.map +1 -1
  225. package/dist/harness/utils/output-capture.js.map +1 -1
  226. package/dist/harness/utils/shell-output.d.ts.map +1 -1
  227. package/dist/harness/utils/shell-output.js.map +1 -1
  228. package/dist/harness/utils/truncate.d.ts.map +1 -1
  229. package/dist/harness/utils/truncate.js.map +1 -1
  230. package/dist/harness/utils/usage.d.ts.map +1 -1
  231. package/dist/harness/utils/usage.js.map +1 -1
  232. package/dist/index.d.ts.map +1 -1
  233. package/dist/node.d.ts.map +1 -1
  234. package/dist/proxy.d.ts.map +1 -1
  235. package/dist/proxy.js.map +1 -1
  236. package/dist/search/index.d.ts.map +1 -1
  237. package/dist/stream-fn.d.ts.map +1 -1
  238. package/dist/stream-fn.js.map +1 -1
  239. package/dist/types.d.ts +30 -2
  240. package/dist/types.d.ts.map +1 -1
  241. package/dist/types.js.map +1 -1
  242. package/package.json +9 -10
@@ -1 +1 @@
1
- {"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../../src/harness/runtime/progress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAS,MAAM,qBAAqB,CAAC;AAEhE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,KAAK,EAAa,MAAM,YAAY,CAAC;AAEnD,MAAM,WAAW,eAAe,CAAC,CAAC;IACjC,KAAK,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACrB,IAAI,IAAI,IAAI,CAAC;IACb,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AAED,wBAAsB,mBAAmB,CACxC,MAAM,EAAE,aAAa,EACrB,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAalC;AAoCD,wBAAgB,iBAAiB,CAAC,QAAQ,SAAS,MAAM,GAAG,SAAS,EACpE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EACpB,KAAK,EAAE,KAAK,EACZ,eAAe,EAAE,MAAM,GACrB,eAAe,CAAC,qBAAqB,CAAC,CAexC;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,SAAS,MAAM,GAAG,SAAS,EACnE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EACpB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,GAClB,eAAe,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAqB3C","sourcesContent":["import type { AssistantMessageFrame } from \"@earendil-works/pi-ai\";\nimport type { AgentToolResult } from \"../../types.ts\";\nimport type { Context } from \"../context.ts\";\nimport type { SessionReader, Write } from \"../session/types.ts\";\nimport { appendList, pendingAssistantFrames, pendingToolOutput, setValue } from \"../session/values.ts\";\nimport type { Lane } from \"./lane.ts\";\nimport type { Drive, LaneState } from \"./types.ts\";\n\nexport interface ProgressChannel<T> {\n\twrite(item: T): void;\n\tseal(): void;\n\tdrain(): Promise<void>;\n}\n\nexport async function readAssistantFrames(\n\treader: SessionReader,\n\toperationId: string,\n\tresponseEntryId: string,\n\tcontext: Context,\n): Promise<AssistantMessageFrame[]> {\n\tconst frames: AssistantMessageFrame[] = [];\n\tlet cursor: { seq: number } | undefined;\n\tfor (;;) {\n\t\tconst page = await reader.readList(\n\t\t\tpendingAssistantFrames(operationId, responseEntryId),\n\t\t\t{ order: \"asc\", limit: 1_000, ...(cursor === undefined ? {} : { cursor }) },\n\t\t\tcontext,\n\t\t);\n\t\tframes.push(...page.map(({ value }) => value));\n\t\tif (page.length < 1_000) return frames;\n\t\tcursor = { seq: page[page.length - 1]!.seq };\n\t}\n}\n\nfunction openProgress<TContext extends object | undefined, T>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tcommitWrite: (item: T) => Write,\n\tstillOwns: (state: LaneState) => boolean,\n): ProgressChannel<T> {\n\tlet sealed = false;\n\tlet latest: Promise<void> = Promise.resolve();\n\treturn {\n\t\twrite(item) {\n\t\t\tif (sealed) return;\n\t\t\tconst write = lane\n\t\t\t\t.command((projection) => {\n\t\t\t\t\tif (!stillOwns(projection)) return { kind: \"return\", result: undefined };\n\t\t\t\t\treturn {\n\t\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\t\twrites: [commitWrite(item)],\n\t\t\t\t\t\tnext: projection,\n\t\t\t\t\t\tmaterialize: () => undefined,\n\t\t\t\t\t};\n\t\t\t\t}, drive.context)\n\t\t\t\t.then(() => undefined);\n\t\t\tlatest = write;\n\t\t\tvoid write.catch(() => {});\n\t\t},\n\t\tseal() {\n\t\t\tsealed = true;\n\t\t},\n\t\tasync drain() {\n\t\t\tawait latest;\n\t\t},\n\t};\n}\n\nexport function openFrameProgress<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tresponseEntryId: string,\n): ProgressChannel<AssistantMessageFrame> {\n\tconst address = pendingAssistantFrames(drive.operationId, responseEntryId);\n\treturn openProgress(\n\t\tlane,\n\t\tdrive,\n\t\t(frame) => appendList(address, frame),\n\t\t(state) => {\n\t\t\tconst run = state.operation?.state;\n\t\t\tif (run === undefined) return false;\n\t\t\treturn (\n\t\t\t\t(run.at === \"assistant.effect_pending\" || run.at === \"deferred.effect_pending\") &&\n\t\t\t\trun.responseEntryId === responseEntryId\n\t\t\t);\n\t\t},\n\t);\n}\n\nexport function openToolProgress<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tturnId: string,\n\tsourceIndex: number,\n\tinvocationId: string,\n): ProgressChannel<AgentToolResult<unknown>> {\n\tconst address = pendingToolOutput(drive.operationId, invocationId);\n\treturn openProgress(\n\t\tlane,\n\t\tdrive,\n\t\t(snapshot) => setValue(address, snapshot),\n\t\t(state) => {\n\t\t\tconst operation = state.operation;\n\t\t\tif (operation?.state.at !== \"tools\") return false;\n\t\t\tconst batch = operation.state.batch;\n\t\t\treturn (\n\t\t\t\tbatch.turnId === turnId &&\n\t\t\t\tbatch.calls.some(\n\t\t\t\t\t(call) =>\n\t\t\t\t\t\tcall.sourceIndex === sourceIndex &&\n\t\t\t\t\t\tcall.resultEntryId === invocationId &&\n\t\t\t\t\t\tcall.status === \"effect_pending\",\n\t\t\t\t)\n\t\t\t);\n\t\t},\n\t);\n}\n"]}
1
+ {"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../../src/harness/runtime/progress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EA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E,OAAO,YAAY,CAClB,IAAI,EACJ,KAAK,EACL,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,EACzC,CAAC,KAAK,EAAE,EAAE,CAAC;QACV,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,CAAC;QAClC,IAAI,SAAS,EAAE,KAAK,CAAC,EAAE,KAAK,OAAO;YAAE,OAAO,KAAK,CAAC;QAClD,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC;QACpC,OAAO,CACN,KAAK,CAAC,MAAM,KAAK,MAAM;YACvB,KAAK,CAAC,KAAK,CAAC,IAAI,CACf,CAAC,IAAI,EAAE,EAAE,CACR,IAAI,CAAC,WAAW,KAAK,WAAW;gBAChC,IAAI,CAAC,aAAa,KAAK,YAAY;gBACnC,IAAI,CAAC,MAAM,KAAK,gBAAgB,CACjC,CACD,CAAC;IAAA,CACF,CACD,CAAC;AAAA,CACF","sourcesContent":["import type { AssistantMessageFrame } from \"@earendil-works/pi-ai\";\nimport type { AgentToolResult } from \"../../types.ts\";\nimport type { Context } from \"../context.ts\";\nimport type { SessionReader, Write } from \"../session/types.ts\";\nimport { appendList, pendingAssistantFrames, pendingToolOutput, setValue } from \"../session/values.ts\";\nimport type { Lane } from \"./lane.ts\";\nimport type { Drive, LaneState } from \"./types.ts\";\n\nexport interface ProgressChannel<T> {\n\twrite(item: T): void;\n\tseal(): void;\n\tdrain(): Promise<void>;\n}\n\nexport async function readAssistantFrames(\n\treader: SessionReader,\n\toperationId: string,\n\tresponseEntryId: string,\n\tcontext: Context,\n): Promise<AssistantMessageFrame[]> {\n\tconst frames: AssistantMessageFrame[] = [];\n\tlet cursor: { seq: number } | undefined;\n\tfor (;;) {\n\t\tconst page = await reader.readList(\n\t\t\tpendingAssistantFrames(operationId, responseEntryId),\n\t\t\t{ order: \"asc\", limit: 1_000, ...(cursor === undefined ? {} : { cursor }) },\n\t\t\tcontext,\n\t\t);\n\t\tframes.push(...page.map(({ value }) => value));\n\t\tif (page.length < 1_000) return frames;\n\t\tcursor = { seq: page[page.length - 1]!.seq };\n\t}\n}\n\nfunction openProgress<TContext extends object | undefined, T>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tcommitWrite: (item: T) => Write,\n\tstillOwns: (state: LaneState) => boolean,\n): ProgressChannel<T> {\n\tlet sealed = false;\n\tlet latest: Promise<void> = Promise.resolve();\n\treturn {\n\t\twrite(item) {\n\t\t\tif (sealed) return;\n\t\t\tconst write = lane\n\t\t\t\t.command((projection) => {\n\t\t\t\t\tif (!stillOwns(projection)) return { kind: \"return\", result: undefined };\n\t\t\t\t\treturn {\n\t\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\t\twrites: [commitWrite(item)],\n\t\t\t\t\t\tnext: projection,\n\t\t\t\t\t\tmaterialize: () => undefined,\n\t\t\t\t\t};\n\t\t\t\t}, drive.context)\n\t\t\t\t.then(() => undefined);\n\t\t\tlatest = write;\n\t\t\tvoid write.catch(() => {});\n\t\t},\n\t\tseal() {\n\t\t\tsealed = true;\n\t\t},\n\t\tasync drain() {\n\t\t\tawait latest;\n\t\t},\n\t};\n}\n\nexport function openFrameProgress<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tresponseEntryId: string,\n): ProgressChannel<AssistantMessageFrame> {\n\tconst address = pendingAssistantFrames(drive.operationId, responseEntryId);\n\treturn openProgress(\n\t\tlane,\n\t\tdrive,\n\t\t(frame) => appendList(address, frame),\n\t\t(state) => {\n\t\t\tconst run = state.operation?.state;\n\t\t\tif (run === undefined) return false;\n\t\t\treturn (\n\t\t\t\t(run.at === \"assistant.effect_pending\" || run.at === \"deferred.effect_pending\") &&\n\t\t\t\trun.responseEntryId === responseEntryId\n\t\t\t);\n\t\t},\n\t);\n}\n\nexport function openToolProgress<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tturnId: string,\n\tsourceIndex: number,\n\tinvocationId: string,\n): ProgressChannel<AgentToolResult<unknown>> {\n\tconst address = pendingToolOutput(drive.operationId, invocationId);\n\treturn openProgress(\n\t\tlane,\n\t\tdrive,\n\t\t(snapshot) => setValue(address, snapshot),\n\t\t(state) => {\n\t\t\tconst operation = state.operation;\n\t\t\tif (operation?.state.at !== \"tools\") return false;\n\t\t\tconst batch = operation.state.batch;\n\t\t\treturn (\n\t\t\t\tbatch.turnId === turnId &&\n\t\t\t\tbatch.calls.some(\n\t\t\t\t\t(call) =>\n\t\t\t\t\t\tcall.sourceIndex === sourceIndex &&\n\t\t\t\t\t\tcall.resultEntryId === invocationId &&\n\t\t\t\t\t\tcall.status === \"effect_pending\",\n\t\t\t\t)\n\t\t\t);\n\t\t},\n\t);\n}\n"]}
1
+ {"version":3,"file":"progress.js","sourceRoot":"","sources":["../../../src/harness/runtime/progress.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAUvG,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACxC,MAAqB,EACrB,WAAmB,EACnB,eAAuB,EACvB,OAAgB;IAEhB,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,IAAI,MAAmC,CAAC;IACxC,SAAS,CAAC;QACT,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,QAAQ,CACjC,sBAAsB,CAAC,WAAW,EAAE,eAAe,CAAC,EACpD,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAC3E,OAAO,CACP,CAAC;QACF,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/C,IAAI,I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CAAC;AACH,CAAC","sourcesContent":["import type { AssistantMessageFrame } from \"@earendil-works/pi-ai\";\nimport type { AgentToolResult } from \"../../types.ts\";\nimport type { Context } from \"../context.ts\";\nimport type { SessionReader, Write } from \"../session/types.ts\";\nimport { appendList, pendingAssistantFrames, pendingToolOutput, setValue } from \"../session/values.ts\";\nimport type { Lane } from \"./lane.ts\";\nimport type { Drive, LaneState } from \"./types.ts\";\n\nexport interface ProgressChannel<T> {\n\twrite(item: T): void;\n\tseal(): void;\n\tdrain(): Promise<void>;\n}\n\nexport async function readAssistantFrames(\n\treader: SessionReader,\n\toperationId: string,\n\tresponseEntryId: string,\n\tcontext: Context,\n): Promise<AssistantMessageFrame[]> {\n\tconst frames: AssistantMessageFrame[] = [];\n\tlet cursor: { seq: number } | undefined;\n\tfor (;;) {\n\t\tconst page = await reader.readList(\n\t\t\tpendingAssistantFrames(operationId, responseEntryId),\n\t\t\t{ order: \"asc\", limit: 1_000, ...(cursor === undefined ? {} : { cursor }) },\n\t\t\tcontext,\n\t\t);\n\t\tframes.push(...page.map(({ value }) => value));\n\t\tif (page.length < 1_000) return frames;\n\t\tcursor = { seq: page[page.length - 1]!.seq };\n\t}\n}\n\nfunction openProgress<TContext extends object | undefined, T>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tcommitWrite: (item: T) => Write,\n\tstillOwns: (state: LaneState) => boolean,\n): ProgressChannel<T> {\n\tlet sealed = false;\n\tlet latest: Promise<void> = Promise.resolve();\n\treturn {\n\t\twrite(item) {\n\t\t\tif (sealed) return;\n\t\t\tconst write = lane\n\t\t\t\t.command((projection) => {\n\t\t\t\t\tif (!stillOwns(projection)) return { kind: \"return\", result: undefined };\n\t\t\t\t\treturn {\n\t\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\t\twrites: [commitWrite(item)],\n\t\t\t\t\t\tnext: projection,\n\t\t\t\t\t\tmaterialize: () => undefined,\n\t\t\t\t\t};\n\t\t\t\t}, drive.context)\n\t\t\t\t.then(() => undefined);\n\t\t\tlatest = write;\n\t\t\tvoid write.catch(() => {});\n\t\t},\n\t\tseal() {\n\t\t\tsealed = true;\n\t\t},\n\t\tasync drain() {\n\t\t\tawait latest;\n\t\t},\n\t};\n}\n\nexport function openFrameProgress<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tresponseEntryId: string,\n): ProgressChannel<AssistantMessageFrame> {\n\tconst address = pendingAssistantFrames(drive.operationId, responseEntryId);\n\treturn openProgress(\n\t\tlane,\n\t\tdrive,\n\t\t(frame) => appendList(address, frame),\n\t\t(state) => {\n\t\t\tconst run = state.operation?.state;\n\t\t\tif (run === undefined) return false;\n\t\t\treturn (\n\t\t\t\t(run.at === \"assistant.effect_pending\" || run.at === \"deferred.effect_pending\") &&\n\t\t\t\trun.responseEntryId === responseEntryId\n\t\t\t);\n\t\t},\n\t);\n}\n\nexport function openToolProgress<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tturnId: string,\n\tsourceIndex: number,\n\tinvocationId: string,\n): ProgressChannel<AgentToolResult<unknown>> {\n\tconst address = pendingToolOutput(drive.operationId, invocationId);\n\treturn openProgress(\n\t\tlane,\n\t\tdrive,\n\t\t(snapshot) => setValue(address, snapshot),\n\t\t(state) => {\n\t\t\tconst operation = state.operation;\n\t\t\tif (operation?.state.at !== \"tools\") return false;\n\t\t\tconst batch = operation.state.batch;\n\t\t\treturn (\n\t\t\t\tbatch.turnId === turnId &&\n\t\t\t\tbatch.calls.some(\n\t\t\t\t\t(call) =>\n\t\t\t\t\t\tcall.sourceIndex === sourceIndex &&\n\t\t\t\t\t\tcall.resultEntryId === invocationId &&\n\t\t\t\t\t\tcall.status === \"effect_pending\",\n\t\t\t\t)\n\t\t\t);\n\t\t},\n\t);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../../src/harness/runtime/reducer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGtF,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,SAAS,CAAC;AAiBzD,2GAA2G;AAC3G,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,YAAY,GAAG,cAAc,GAClC,qBAAqB,CA+MvB","sourcesContent":["import type { HarnessEvent, LaneSnapshot, LaneWatchEvent } from \"../agent-harness.ts\";\nimport type { OperationResultRecord } from \"../session/types.ts\";\n\nexport type LaneSnapshotReduction = \"rebase\" | undefined;\n\ntype LaneOperationSnapshot = NonNullable<LaneSnapshot[\"operation\"]>;\n\nfunction upsertTool(operation: LaneOperationSnapshot, tool: LaneOperationSnapshot[\"runningTools\"][number]): void {\n\tconst index = operation.runningTools.findIndex((candidate) => candidate.toolCallId === tool.toolCallId);\n\tif (index === -1) operation.runningTools.push(tool);\n\telse operation.runningTools[index] = tool;\n}\n\nfunction matchingOperation(\n\tsnapshot: LaneSnapshot,\n\toperationId: string,\n): NonNullable<LaneSnapshot[\"operation\"]> | undefined {\n\treturn snapshot.operation?.id === operationId ? snapshot.operation : undefined;\n}\n\n/** Apply one harness event to a mutable lane snapshot. Navigation completion requires a fresh snapshot. */\nexport function reduceLaneSnapshot(\n\tsnapshot: LaneSnapshot,\n\tevent: HarnessEvent | LaneWatchEvent,\n): LaneSnapshotReduction {\n\tif (\"lane\" in event && event.lane !== undefined && event.lane !== snapshot.lane && event.type !== \"usage\") return;\n\tswitch (event.type) {\n\t\tcase \"run_start\":\n\t\t\tsnapshot.operation = {\n\t\t\t\tid: event.runId,\n\t\t\t\tkind: \"run\",\n\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\tfromTipId: snapshot.tipId,\n\t\t\t\tstatus: \"open\",\n\t\t\t\trunningTools: [],\n\t\t\t};\n\t\t\treturn;\n\t\tcase \"compaction_start\":\n\t\t\tif (snapshot.operation !== null) return;\n\t\t\tsnapshot.operation = {\n\t\t\t\tid: event.runId,\n\t\t\t\tkind: \"compaction\",\n\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\tfromTipId: snapshot.tipId,\n\t\t\t\tstatus: \"open\",\n\t\t\t\trunningTools: [],\n\t\t\t};\n\t\t\treturn;\n\t\tcase \"navigation_start\":\n\t\t\tsnapshot.operation = {\n\t\t\t\tid: event.runId,\n\t\t\t\tkind: \"navigation\",\n\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\tfromTipId: snapshot.tipId,\n\t\t\t\tstatus: \"open\",\n\t\t\t\trunningTools: [],\n\t\t\t};\n\t\t\treturn;\n\t\tcase \"operation_abort\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.operationId);\n\t\t\tif (operation !== undefined) operation.status = \"aborting\";\n\t\t\treturn;\n\t\t}\n\t\tcase \"run_resume\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) delete operation.deferred;\n\t\t\treturn;\n\t\t}\n\t\tcase \"run_suspend\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation === undefined) return;\n\t\t\tdelete operation.streamingMessage;\n\t\t\toperation.deferred = { handle: event.deferred, poll: event.poll };\n\t\t\treturn;\n\t\t}\n\t\tcase \"retry_scheduled\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) {\n\t\t\t\toperation.retry = {\n\t\t\t\t\tattempt: event.attempt,\n\t\t\t\t\tmaxAttempts: event.maxAttempts,\n\t\t\t\t\tnextAttemptAt: event.notBefore,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tcase \"retry_start\":\n\t\tcase \"retry_end\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) delete operation.retry;\n\t\t\treturn;\n\t\t}\n\t\tcase \"message_start\": {\n\t\t\tif (\n\t\t\t\tevent.runId === undefined ||\n\t\t\t\tevent.message.role !== \"assistant\" ||\n\t\t\t\tevent.message.stopReason !== \"pending\"\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) operation.streamingMessage = event.message;\n\t\t\treturn;\n\t\t}\n\t\tcase \"message_update\": {\n\t\t\tif (event.message.role !== \"assistant\") return;\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) operation.streamingMessage = event.message;\n\t\t\treturn;\n\t\t}\n\t\tcase \"message_end\": {\n\t\t\tif (event.runId === undefined) return;\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) delete operation.streamingMessage;\n\t\t\treturn;\n\t\t}\n\t\tcase \"tool_start\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation === undefined) return;\n\t\t\tupsertTool(operation, {\n\t\t\t\tstatus: \"running\",\n\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\ttoolName: event.toolName,\n\t\t\t\targs: event.args,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tcase \"tool_update\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tconst tool = operation?.runningTools.find((candidate) => candidate.toolCallId === event.toolCallId);\n\t\t\tif (tool?.status === \"running\") tool.result = event.partialResult;\n\t\t\treturn;\n\t\t}\n\t\tcase \"tool_end\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation === undefined) return;\n\t\t\tconst index = operation.runningTools.findIndex((candidate) => candidate.toolCallId === event.toolCallId);\n\t\t\tconst current = operation.runningTools[index];\n\t\t\tif (current === undefined) return;\n\t\t\toperation.runningTools[index] = {\n\t\t\t\tstatus: \"settled\",\n\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\ttoolName: event.toolName,\n\t\t\t\targs: current.args,\n\t\t\t\tresult: event.result,\n\t\t\t\tisError: event.isError,\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\tcase \"entry_added\": {\n\t\t\tif (event.entry.type === \"message\" && event.entry.message.role === \"toolResult\") {\n\t\t\t\tconst operation = snapshot.operation;\n\t\t\t\tif (operation !== null) {\n\t\t\t\t\tconst toolCallId = event.entry.message.toolCallId;\n\t\t\t\t\tconst index = operation.runningTools.findIndex((candidate) => candidate.toolCallId === toolCallId);\n\t\t\t\t\tif (index !== -1) operation.runningTools.splice(index, 1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (event.entry.type === \"compaction\") snapshot.transcript.splice(0, snapshot.transcript.length, event.entry);\n\t\t\telse snapshot.transcript.push(event.entry);\n\t\t\tsnapshot.tipId = event.entry.id;\n\t\t\tif (event.entry.type === \"message\") snapshot.stats.messageCount += 1;\n\t\t\treturn;\n\t\t}\n\t\tcase \"queue_update\":\n\t\t\tsnapshot.queues = event.queues;\n\t\t\treturn;\n\t\tcase \"usage\":\n\t\t\tsnapshot.stats.usage = event.totals;\n\t\t\treturn;\n\t\tcase \"config_update\":\n\t\t\tif (!(\"lane\" in event) || event.lane !== snapshot.lane) return;\n\t\t\tswitch (event.property) {\n\t\t\t\tcase \"model\":\n\t\t\t\t\tsnapshot.configuration.model = event.value;\n\t\t\t\t\treturn;\n\t\t\t\tcase \"thinkingLevel\":\n\t\t\t\t\tsnapshot.configuration.thinkingLevel = event.value;\n\t\t\t\t\treturn;\n\t\t\t\tcase \"activeTools\":\n\t\t\t\t\tsnapshot.configuration.activeToolNames = event.value;\n\t\t\t\t\treturn;\n\t\t\t}\n\t\t\treturn;\n\t\tcase \"run_end\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation?.kind !== \"run\") return;\n\t\t\tconst record: OperationResultRecord = {\n\t\t\t\toperationId: event.runId,\n\t\t\t\tkind: \"run\",\n\t\t\t\tstatus: event.status,\n\t\t\t\t...(event.status === \"failed\" ? { error: event.error } : {}),\n\t\t\t\tfromTipId: event.fromTipId,\n\t\t\t\ttipId: event.tipId,\n\t\t\t\tstartedAt: operation.startedAt,\n\t\t\t\tendedAt: event.endedAt,\n\t\t\t};\n\t\t\tsnapshot.lastResult = record;\n\t\t\tsnapshot.operation = null;\n\t\t\tsnapshot.tipId = event.tipId;\n\t\t\treturn;\n\t\t}\n\t\tcase \"compaction_end\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation?.kind !== \"compaction\") return;\n\t\t\tconst record: OperationResultRecord = {\n\t\t\t\toperationId: event.runId,\n\t\t\t\tkind: \"compaction\",\n\t\t\t\tstatus: event.status,\n\t\t\t\t...(event.status === \"failed\" ? { error: event.error } : {}),\n\t\t\t\tfromTipId: operation.fromTipId,\n\t\t\t\ttipId: snapshot.tipId,\n\t\t\t\tstartedAt: operation.startedAt,\n\t\t\t\tendedAt: event.endedAt,\n\t\t\t};\n\t\t\tsnapshot.lastResult = record;\n\t\t\tsnapshot.operation = null;\n\t\t\treturn;\n\t\t}\n\t\tcase \"navigation_end\":\n\t\t\treturn \"rebase\";\n\t\tcase \"fault\":\n\t\t\tsnapshot.faulted = true;\n\t\t\treturn;\n\t\tcase \"handler_error\":\n\t\tcase \"turn_start\":\n\t\tcase \"turn_end\":\n\t\tcase \"value_update\":\n\t\tcase \"lane_created\":\n\t\t\treturn;\n\t}\n}\n"]}
1
+ {"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../../src/harness/runtime/reducer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGtF,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,SAAS,CAAC;AAiBzD,2GAA2G;AAC3G,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,YAAY,GAAG,cAAc,GAClC,qBAAqB,CA+MvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"reducer.js","sourceRoot":"","sources":["../../../src/harness/runtime/reducer.ts"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AAgB;YACpB,OAAO,QAAQ,CAAC;QACjB,KAAK,OAAO;YACX,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC;YACxB,OAAO;QACR,KAAK,eAAe,CAAC;QACrB,KAAK,YAAY,CAAC;QAClB,KAAK,UAAU,CAAC;QAChB,KAAK,cAAc,CAAC;QACpB,KAAK,cAAc;YAClB,OAAO;IACT,CAAC;AAAA,CACD","sourcesContent":["import type { HarnessEvent, LaneSnapshot, LaneWatchEvent } from \"../agent-harness.ts\";\nimport type { OperationResultRecord } from \"../session/types.ts\";\n\nexport type LaneSnapshotReduction = \"rebase\" | undefined;\n\ntype LaneOperationSnapshot = NonNullable<LaneSnapshot[\"operation\"]>;\n\nfunction upsertTool(operation: LaneOperationSnapshot, tool: LaneOperationSnapshot[\"runningTools\"][number]): void {\n\tconst index = operation.runningTools.findIndex((candidate) => candidate.toolCallId === tool.toolCallId);\n\tif (index === -1) operation.runningTools.push(tool);\n\telse operation.runningTools[index] = tool;\n}\n\nfunction matchingOperation(\n\tsnapshot: LaneSnapshot,\n\toperationId: string,\n): NonNullable<LaneSnapshot[\"operation\"]> | undefined {\n\treturn snapshot.operation?.id === operationId ? snapshot.operation : undefined;\n}\n\n/** Apply one harness event to a mutable lane snapshot. Navigation completion requires a fresh snapshot. */\nexport function reduceLaneSnapshot(\n\tsnapshot: LaneSnapshot,\n\tevent: HarnessEvent | LaneWatchEvent,\n): LaneSnapshotReduction {\n\tif (\"lane\" in event && event.lane !== undefined && event.lane !== snapshot.lane && event.type !== \"usage\") return;\n\tswitch (event.type) {\n\t\tcase \"run_start\":\n\t\t\tsnapshot.operation = {\n\t\t\t\tid: event.runId,\n\t\t\t\tkind: \"run\",\n\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\tfromTipId: snapshot.tipId,\n\t\t\t\tstatus: \"open\",\n\t\t\t\trunningTools: [],\n\t\t\t};\n\t\t\treturn;\n\t\tcase \"compaction_start\":\n\t\t\tif (snapshot.operation !== null) return;\n\t\t\tsnapshot.operation = {\n\t\t\t\tid: event.runId,\n\t\t\t\tkind: \"compaction\",\n\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\tfromTipId: snapshot.tipId,\n\t\t\t\tstatus: \"open\",\n\t\t\t\trunningTools: [],\n\t\t\t};\n\t\t\treturn;\n\t\tcase \"navigation_start\":\n\t\t\tsnapshot.operation = {\n\t\t\t\tid: event.runId,\n\t\t\t\tkind: \"navigation\",\n\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\tfromTipId: snapshot.tipId,\n\t\t\t\tstatus: \"open\",\n\t\t\t\trunningTools: [],\n\t\t\t};\n\t\t\treturn;\n\t\tcase \"operation_abort\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.operationId);\n\t\t\tif (operation !== undefined) operation.status = \"aborting\";\n\t\t\treturn;\n\t\t}\n\t\tcase \"run_resume\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) delete operation.deferred;\n\t\t\treturn;\n\t\t}\n\t\tcase \"run_suspend\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation === undefined) return;\n\t\t\tdelete operation.streamingMessage;\n\t\t\toperation.deferred = { handle: event.deferred, poll: event.poll };\n\t\t\treturn;\n\t\t}\n\t\tcase \"retry_scheduled\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) {\n\t\t\t\toperation.retry = {\n\t\t\t\t\tattempt: event.attempt,\n\t\t\t\t\tmaxAttempts: event.maxAttempts,\n\t\t\t\t\tnextAttemptAt: event.notBefore,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tcase \"retry_start\":\n\t\tcase \"retry_end\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) delete operation.retry;\n\t\t\treturn;\n\t\t}\n\t\tcase \"message_start\": {\n\t\t\tif (\n\t\t\t\tevent.runId === undefined ||\n\t\t\t\tevent.message.role !== \"assistant\" ||\n\t\t\t\tevent.message.stopReason !== \"pending\"\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) operation.streamingMessage = event.message;\n\t\t\treturn;\n\t\t}\n\t\tcase \"message_update\": {\n\t\t\tif (event.message.role !== \"assistant\") return;\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) operation.streamingMessage = event.message;\n\t\t\treturn;\n\t\t}\n\t\tcase \"message_end\": {\n\t\t\tif (event.runId === undefined) return;\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) delete operation.streamingMessage;\n\t\t\treturn;\n\t\t}\n\t\tcase \"tool_start\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation === undefined) return;\n\t\t\tupsertTool(operation, {\n\t\t\t\tstatus: \"running\",\n\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\ttoolName: event.toolName,\n\t\t\t\targs: event.args,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tcase \"tool_update\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tconst tool = operation?.runningTools.find((candidate) => candidate.toolCallId === event.toolCallId);\n\t\t\tif (tool?.status === \"running\") tool.result = event.partialResult;\n\t\t\treturn;\n\t\t}\n\t\tcase \"tool_end\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation === undefined) return;\n\t\t\tconst index = operation.runningTools.findIndex((candidate) => candidate.toolCallId === event.toolCallId);\n\t\t\tconst current = operation.runningTools[index];\n\t\t\tif (current === undefined) return;\n\t\t\toperation.runningTools[index] = {\n\t\t\t\tstatus: \"settled\",\n\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\ttoolName: event.toolName,\n\t\t\t\targs: current.args,\n\t\t\t\tresult: event.result,\n\t\t\t\tisError: event.isError,\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\tcase \"entry_added\": {\n\t\t\tif (event.entry.type === \"message\" && event.entry.message.role === \"toolResult\") {\n\t\t\t\tconst operation = snapshot.operation;\n\t\t\t\tif (operation !== null) {\n\t\t\t\t\tconst toolCallId = event.entry.message.toolCallId;\n\t\t\t\t\tconst index = operation.runningTools.findIndex((candidate) => candidate.toolCallId === toolCallId);\n\t\t\t\t\tif (index !== -1) operation.runningTools.splice(index, 1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (event.entry.type === \"compaction\") snapshot.transcript.splice(0, snapshot.transcript.length, event.entry);\n\t\t\telse snapshot.transcript.push(event.entry);\n\t\t\tsnapshot.tipId = event.entry.id;\n\t\t\tif (event.entry.type === \"message\") snapshot.stats.messageCount += 1;\n\t\t\treturn;\n\t\t}\n\t\tcase \"queue_update\":\n\t\t\tsnapshot.queues = event.queues;\n\t\t\treturn;\n\t\tcase \"usage\":\n\t\t\tsnapshot.stats.usage = event.totals;\n\t\t\treturn;\n\t\tcase \"config_update\":\n\t\t\tif (!(\"lane\" in event) || event.lane !== snapshot.lane) return;\n\t\t\tswitch (event.property) {\n\t\t\t\tcase \"model\":\n\t\t\t\t\tsnapshot.configuration.model = event.value;\n\t\t\t\t\treturn;\n\t\t\t\tcase \"thinkingLevel\":\n\t\t\t\t\tsnapshot.configuration.thinkingLevel = event.value;\n\t\t\t\t\treturn;\n\t\t\t\tcase \"activeTools\":\n\t\t\t\t\tsnapshot.configuration.activeToolNames = event.value;\n\t\t\t\t\treturn;\n\t\t\t}\n\t\t\treturn;\n\t\tcase \"run_end\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation?.kind !== \"run\") return;\n\t\t\tconst record: OperationResultRecord = {\n\t\t\t\toperationId: event.runId,\n\t\t\t\tkind: \"run\",\n\t\t\t\tstatus: event.status,\n\t\t\t\t...(event.status === \"failed\" ? { error: event.error } : {}),\n\t\t\t\tfromTipId: event.fromTipId,\n\t\t\t\ttipId: event.tipId,\n\t\t\t\tstartedAt: operation.startedAt,\n\t\t\t\tendedAt: event.endedAt,\n\t\t\t};\n\t\t\tsnapshot.lastResult = record;\n\t\t\tsnapshot.operation = null;\n\t\t\tsnapshot.tipId = event.tipId;\n\t\t\treturn;\n\t\t}\n\t\tcase \"compaction_end\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation?.kind !== \"compaction\") return;\n\t\t\tconst record: OperationResultRecord = {\n\t\t\t\toperationId: event.runId,\n\t\t\t\tkind: \"compaction\",\n\t\t\t\tstatus: event.status,\n\t\t\t\t...(event.status === \"failed\" ? { error: event.error } : {}),\n\t\t\t\tfromTipId: operation.fromTipId,\n\t\t\t\ttipId: snapshot.tipId,\n\t\t\t\tstartedAt: operation.startedAt,\n\t\t\t\tendedAt: event.endedAt,\n\t\t\t};\n\t\t\tsnapshot.lastResult = record;\n\t\t\tsnapshot.operation = null;\n\t\t\treturn;\n\t\t}\n\t\tcase \"navigation_end\":\n\t\t\treturn \"rebase\";\n\t\tcase \"fault\":\n\t\t\tsnapshot.faulted = true;\n\t\t\treturn;\n\t\tcase \"handler_error\":\n\t\tcase \"turn_start\":\n\t\tcase \"turn_end\":\n\t\tcase \"value_update\":\n\t\tcase \"lane_created\":\n\t\t\treturn;\n\t}\n}\n"]}
1
+ {"version":3,"file":"reducer.js","sourceRoot":"","sources":["../../../src/harness/runtime/reducer.ts"],"names":[],"mappings":"AAOA,SAAS,UAAU,CAAC,SAAgC,EAAE,IAAmD;IACxG,MAAM,KAAK,GAAG,SAAS,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,UAAU,KAAK,IAAI,CAAC,UAAU,CAAC,CAAC;IACxG,IAAI,KAAK,KAAK,CAAC,CAAC;QAAE,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;QAC/C,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG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,MAAM,CAAC;YAC7B,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC;YAC1B,QAAQ,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;YAC7B,OAAO;QACR,CAAC;QACD,KAAK,gBAAgB,EAAE,CAAC;YACvB,MAAM,SAAS,GAAG,iBAAiB,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;YAC3D,IAAI,SAAS,EAAE,IAAI,KAAK,YAAY;gBAAE,OAAO;YAC7C,MAAM,MAAM,GAA0B;gBACrC,WAAW,EAAE,KAAK,CAAC,KAAK;gBACxB,IAAI,EAAE,YAAY;gBAClB,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC5D,SAAS,EAAE,SAAS,CAAC,SAAS;gBAC9B,KAAK,EAAE,QAAQ,CAAC,KAAK;gBACrB,SAAS,EAAE,SAAS,CAAC,SAAS;gBAC9B,OAAO,EAAE,KAAK,CAAC,OAAO;aACtB,CAAC;YACF,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC;YAC7B,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC;YAC1B,OAAO;QACR,CAAC;QACD,KAAK,gBAAgB;YACpB,OAAO,QAAQ,CAAC;QACjB,KAAK,OAAO;YACX,QAAQ,CAAC,OAAO,GAAG,IAAI,CAAC;YACxB,OAAO;QACR,KAAK,eAAe,CAAC;QACrB,KAAK,YAAY,CAAC;QAClB,KAAK,UAAU,CAAC;QAChB,KAAK,cAAc,CAAC;QACpB,KAAK,cAAc;YAClB,OAAO;IACT,CAAC;AACF,CAAC","sourcesContent":["import type { HarnessEvent, LaneSnapshot, LaneWatchEvent } from \"../agent-harness.ts\";\nimport type { OperationResultRecord } from \"../session/types.ts\";\n\nexport type LaneSnapshotReduction = \"rebase\" | undefined;\n\ntype LaneOperationSnapshot = NonNullable<LaneSnapshot[\"operation\"]>;\n\nfunction upsertTool(operation: LaneOperationSnapshot, tool: LaneOperationSnapshot[\"runningTools\"][number]): void {\n\tconst index = operation.runningTools.findIndex((candidate) => candidate.toolCallId === tool.toolCallId);\n\tif (index === -1) operation.runningTools.push(tool);\n\telse operation.runningTools[index] = tool;\n}\n\nfunction matchingOperation(\n\tsnapshot: LaneSnapshot,\n\toperationId: string,\n): NonNullable<LaneSnapshot[\"operation\"]> | undefined {\n\treturn snapshot.operation?.id === operationId ? snapshot.operation : undefined;\n}\n\n/** Apply one harness event to a mutable lane snapshot. Navigation completion requires a fresh snapshot. */\nexport function reduceLaneSnapshot(\n\tsnapshot: LaneSnapshot,\n\tevent: HarnessEvent | LaneWatchEvent,\n): LaneSnapshotReduction {\n\tif (\"lane\" in event && event.lane !== undefined && event.lane !== snapshot.lane && event.type !== \"usage\") return;\n\tswitch (event.type) {\n\t\tcase \"run_start\":\n\t\t\tsnapshot.operation = {\n\t\t\t\tid: event.runId,\n\t\t\t\tkind: \"run\",\n\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\tfromTipId: snapshot.tipId,\n\t\t\t\tstatus: \"open\",\n\t\t\t\trunningTools: [],\n\t\t\t};\n\t\t\treturn;\n\t\tcase \"compaction_start\":\n\t\t\tif (snapshot.operation !== null) return;\n\t\t\tsnapshot.operation = {\n\t\t\t\tid: event.runId,\n\t\t\t\tkind: \"compaction\",\n\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\tfromTipId: snapshot.tipId,\n\t\t\t\tstatus: \"open\",\n\t\t\t\trunningTools: [],\n\t\t\t};\n\t\t\treturn;\n\t\tcase \"navigation_start\":\n\t\t\tsnapshot.operation = {\n\t\t\t\tid: event.runId,\n\t\t\t\tkind: \"navigation\",\n\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\tfromTipId: snapshot.tipId,\n\t\t\t\tstatus: \"open\",\n\t\t\t\trunningTools: [],\n\t\t\t};\n\t\t\treturn;\n\t\tcase \"operation_abort\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.operationId);\n\t\t\tif (operation !== undefined) operation.status = \"aborting\";\n\t\t\treturn;\n\t\t}\n\t\tcase \"run_resume\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) delete operation.deferred;\n\t\t\treturn;\n\t\t}\n\t\tcase \"run_suspend\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation === undefined) return;\n\t\t\tdelete operation.streamingMessage;\n\t\t\toperation.deferred = { handle: event.deferred, poll: event.poll };\n\t\t\treturn;\n\t\t}\n\t\tcase \"retry_scheduled\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) {\n\t\t\t\toperation.retry = {\n\t\t\t\t\tattempt: event.attempt,\n\t\t\t\t\tmaxAttempts: event.maxAttempts,\n\t\t\t\t\tnextAttemptAt: event.notBefore,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tcase \"retry_start\":\n\t\tcase \"retry_end\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) delete operation.retry;\n\t\t\treturn;\n\t\t}\n\t\tcase \"message_start\": {\n\t\t\tif (\n\t\t\t\tevent.runId === undefined ||\n\t\t\t\tevent.message.role !== \"assistant\" ||\n\t\t\t\tevent.message.stopReason !== \"pending\"\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) operation.streamingMessage = event.message;\n\t\t\treturn;\n\t\t}\n\t\tcase \"message_update\": {\n\t\t\tif (event.message.role !== \"assistant\") return;\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) operation.streamingMessage = event.message;\n\t\t\treturn;\n\t\t}\n\t\tcase \"message_end\": {\n\t\t\tif (event.runId === undefined) return;\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation !== undefined) delete operation.streamingMessage;\n\t\t\treturn;\n\t\t}\n\t\tcase \"tool_start\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation === undefined) return;\n\t\t\tupsertTool(operation, {\n\t\t\t\tstatus: \"running\",\n\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\ttoolName: event.toolName,\n\t\t\t\targs: event.args,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tcase \"tool_update\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tconst tool = operation?.runningTools.find((candidate) => candidate.toolCallId === event.toolCallId);\n\t\t\tif (tool?.status === \"running\") tool.result = event.partialResult;\n\t\t\treturn;\n\t\t}\n\t\tcase \"tool_end\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation === undefined) return;\n\t\t\tconst index = operation.runningTools.findIndex((candidate) => candidate.toolCallId === event.toolCallId);\n\t\t\tconst current = operation.runningTools[index];\n\t\t\tif (current === undefined) return;\n\t\t\toperation.runningTools[index] = {\n\t\t\t\tstatus: \"settled\",\n\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\ttoolName: event.toolName,\n\t\t\t\targs: current.args,\n\t\t\t\tresult: event.result,\n\t\t\t\tisError: event.isError,\n\t\t\t};\n\t\t\treturn;\n\t\t}\n\t\tcase \"entry_added\": {\n\t\t\tif (event.entry.type === \"message\" && event.entry.message.role === \"toolResult\") {\n\t\t\t\tconst operation = snapshot.operation;\n\t\t\t\tif (operation !== null) {\n\t\t\t\t\tconst toolCallId = event.entry.message.toolCallId;\n\t\t\t\t\tconst index = operation.runningTools.findIndex((candidate) => candidate.toolCallId === toolCallId);\n\t\t\t\t\tif (index !== -1) operation.runningTools.splice(index, 1);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (event.entry.type === \"compaction\") snapshot.transcript.splice(0, snapshot.transcript.length, event.entry);\n\t\t\telse snapshot.transcript.push(event.entry);\n\t\t\tsnapshot.tipId = event.entry.id;\n\t\t\tif (event.entry.type === \"message\") snapshot.stats.messageCount += 1;\n\t\t\treturn;\n\t\t}\n\t\tcase \"queue_update\":\n\t\t\tsnapshot.queues = event.queues;\n\t\t\treturn;\n\t\tcase \"usage\":\n\t\t\tsnapshot.stats.usage = event.totals;\n\t\t\treturn;\n\t\tcase \"config_update\":\n\t\t\tif (!(\"lane\" in event) || event.lane !== snapshot.lane) return;\n\t\t\tswitch (event.property) {\n\t\t\t\tcase \"model\":\n\t\t\t\t\tsnapshot.configuration.model = event.value;\n\t\t\t\t\treturn;\n\t\t\t\tcase \"thinkingLevel\":\n\t\t\t\t\tsnapshot.configuration.thinkingLevel = event.value;\n\t\t\t\t\treturn;\n\t\t\t\tcase \"activeTools\":\n\t\t\t\t\tsnapshot.configuration.activeToolNames = event.value;\n\t\t\t\t\treturn;\n\t\t\t}\n\t\t\treturn;\n\t\tcase \"run_end\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation?.kind !== \"run\") return;\n\t\t\tconst record: OperationResultRecord = {\n\t\t\t\toperationId: event.runId,\n\t\t\t\tkind: \"run\",\n\t\t\t\tstatus: event.status,\n\t\t\t\t...(event.status === \"failed\" ? { error: event.error } : {}),\n\t\t\t\tfromTipId: event.fromTipId,\n\t\t\t\ttipId: event.tipId,\n\t\t\t\tstartedAt: operation.startedAt,\n\t\t\t\tendedAt: event.endedAt,\n\t\t\t};\n\t\t\tsnapshot.lastResult = record;\n\t\t\tsnapshot.operation = null;\n\t\t\tsnapshot.tipId = event.tipId;\n\t\t\treturn;\n\t\t}\n\t\tcase \"compaction_end\": {\n\t\t\tconst operation = matchingOperation(snapshot, event.runId);\n\t\t\tif (operation?.kind !== \"compaction\") return;\n\t\t\tconst record: OperationResultRecord = {\n\t\t\t\toperationId: event.runId,\n\t\t\t\tkind: \"compaction\",\n\t\t\t\tstatus: event.status,\n\t\t\t\t...(event.status === \"failed\" ? { error: event.error } : {}),\n\t\t\t\tfromTipId: operation.fromTipId,\n\t\t\t\ttipId: snapshot.tipId,\n\t\t\t\tstartedAt: operation.startedAt,\n\t\t\t\tendedAt: event.endedAt,\n\t\t\t};\n\t\t\tsnapshot.lastResult = record;\n\t\t\tsnapshot.operation = null;\n\t\t\treturn;\n\t\t}\n\t\tcase \"navigation_end\":\n\t\t\treturn \"rebase\";\n\t\tcase \"fault\":\n\t\t\tsnapshot.faulted = true;\n\t\t\treturn;\n\t\tcase \"handler_error\":\n\t\tcase \"turn_start\":\n\t\tcase \"turn_end\":\n\t\tcase \"value_update\":\n\t\tcase \"lane_created\":\n\t\t\treturn;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"restore.d.ts","sourceRoot":"","sources":["../../../src/harness/runtime/restore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,EACX,SAAS,IAAI,gBAAgB,EAC7B,iBAAiB,EAGjB,OAAO,EACP,aAAa,EACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAON,KAAK,WAAW,EAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAiC5C,MAAM,MAAM,qBAAqB,GAC9B;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,GAAG,EAAE,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;CAAE,GACnD;IACA,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAChC,aAAa,EAAE,WAAW,CAAC,iBAAiB,CAAC,CAAC;IAC9C,SAAS,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAC;CACxC,CAAC;AAiBL,wBAAsB,eAAe,CACpC,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,qBAAqB,CAAC,CAOhC;AAED,gFAAgF;AAChF,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAuBlG;AAED,mFAAmF;AACnF,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAWhG;AAED,wBAAsB,gBAAgB,CACrC,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,OAAO,CAAC,qBAAqB,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,EACxD,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,SAAS,CAAC,CAmCpB","sourcesContent":["import type { Context } from \"../context.ts\";\nimport { SessionInvariantError } from \"../session/session.ts\";\nimport type {\n\tLaneState as DurableLaneState,\n\tLaneConfiguration,\n\tOperationMeta,\n\tOperationState,\n\tSession,\n\tSessionReader,\n} from \"../session/types.ts\";\nimport {\n\tbranchTip,\n\tbranchTipInventoryPrefix,\n\tlaneConfig,\n\tlaneState as laneStateValue,\n\toperationMeta,\n\toperationState,\n\ttype StoredValue,\n} from \"../session/values.ts\";\nimport type { LaneState } from \"./types.ts\";\n\nfunction isSummaryState(state: OperationState): state is Extract<OperationState, { at: `summary.${string}` }> {\n\treturn state.at.startsWith(\"summary.\");\n}\n\nfunction stateMatchesIntent(intent: OperationMeta[\"intent\"], state: OperationState): boolean {\n\tif (intent.kind === \"compaction\") return isSummaryState(state) && state.task.boundary.kind === \"finish\";\n\tif (intent.kind === \"navigation\") {\n\t\tif (state.at === \"navigation.ready_to_commit\") {\n\t\t\treturn !intent.summarize && state.targetId === intent.targetId && state.label === intent.label;\n\t\t}\n\t\treturn (\n\t\t\tintent.summarize &&\n\t\t\tisSummaryState(state) &&\n\t\t\tstate.task.boundary.kind === \"commit_navigation\" &&\n\t\t\tstate.task.boundary.targetId === intent.targetId &&\n\t\t\tstate.task.boundary.label === intent.label &&\n\t\t\tstate.task.customInstructions === intent.customInstructions\n\t\t);\n\t}\n\treturn (\n\t\tstate.at !== \"navigation.ready_to_commit\" &&\n\t\t(!isSummaryState(state) || state.task.boundary.kind === \"resume_checkpoint\")\n\t);\n}\n\ntype LaneValues = {\n\ttip: StoredValue<string | null> | undefined;\n\tconfiguration: StoredValue<LaneConfiguration> | undefined;\n\tlaneState: StoredValue<DurableLaneState> | undefined;\n};\n\nexport type ClassifiedLaneStorage =\n\t| { kind: \"absent\" }\n\t| { kind: \"branch\"; tip: StoredValue<string | null> }\n\t| {\n\t\t\tkind: \"lane\";\n\t\t\ttip: StoredValue<string | null>;\n\t\t\tconfiguration: StoredValue<LaneConfiguration>;\n\t\t\tlaneState: StoredValue<DurableLaneState>;\n\t };\n\nfunction classifyLaneStorage(lane: string, values: LaneValues): ClassifiedLaneStorage {\n\tconst { tip, configuration, laneState } = values;\n\tif (tip === undefined && configuration === undefined && laneState === undefined) {\n\t\treturn { kind: \"absent\" };\n\t}\n\tif (tip !== undefined && configuration === undefined && laneState === undefined) {\n\t\treturn { kind: \"branch\", tip };\n\t}\n\tif (tip === undefined) throw new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing branch.tip`);\n\tif (configuration === undefined)\n\t\tthrow new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.config`);\n\tif (laneState === undefined) throw new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.state`);\n\treturn { kind: \"lane\", tip, configuration, laneState };\n}\n\nexport async function readLaneStorage(\n\treader: SessionReader,\n\tlane: string,\n\tcontext: Context,\n): Promise<ClassifiedLaneStorage> {\n\tconst [tip, configuration, laneState] = await Promise.all([\n\t\treader.getValue(branchTip(lane), context),\n\t\treader.getValue(laneConfig(lane), context),\n\t\treader.getValue(laneStateValue(lane), context),\n\t]);\n\treturn classifyLaneStorage(lane, { tip, configuration, laneState });\n}\n\n/** Restore every complete configured AgentLane in one coherent Session read. */\nexport function restoreSession(session: Session, context: Context): Promise<Map<string, LaneState>> {\n\treturn session.mutate(async (reader) => {\n\t\tconst [tips, configurations, states] = await Promise.all([\n\t\t\treader.scanValues(branchTipInventoryPrefix(), context),\n\t\t\treader.scanValues(laneConfig(\"\"), context),\n\t\t\treader.scanValues(laneStateValue(\"\"), context),\n\t\t]);\n\t\tconst tipByLane = new Map(tips.map((value) => [value.address.key, value]));\n\t\tconst configurationByLane = new Map(configurations.map((value) => [value.address.key, value]));\n\t\tconst stateByLane = new Map(states.map((value) => [value.address.key, value]));\n\t\tconst names = new Set([...tipByLane.keys(), ...configurationByLane.keys(), ...stateByLane.keys()]);\n\t\tconst restored = new Map<string, LaneState>();\n\t\tfor (const lane of names) {\n\t\t\tconst stored = classifyLaneStorage(lane, {\n\t\t\t\ttip: tipByLane.get(lane),\n\t\t\t\tconfiguration: configurationByLane.get(lane),\n\t\t\t\tlaneState: stateByLane.get(lane),\n\t\t\t});\n\t\t\tif (stored.kind !== \"lane\") continue;\n\t\t\trestored.set(lane, await restoreLaneState(reader, lane, stored, context));\n\t\t}\n\t\treturn restored;\n\t}, context);\n}\n\n/** Restore one configured lane without starting work or interpreting its state. */\nexport function restoreLane(session: Session, lane: string, context: Context): Promise<LaneState> {\n\treturn session.mutate(async (reader) => {\n\t\tconst stored = await readLaneStorage(reader, lane, context);\n\t\tif (stored.kind === \"absent\") {\n\t\t\tthrow new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing branch.tip`);\n\t\t}\n\t\tif (stored.kind === \"branch\") {\n\t\t\tthrow new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.config`);\n\t\t}\n\t\treturn restoreLaneState(reader, lane, stored, context);\n\t}, context);\n}\n\nexport async function restoreLaneState(\n\treader: SessionReader,\n\tlane: string,\n\tstored: Extract<ClassifiedLaneStorage, { kind: \"lane\" }>,\n\tcontext: Context,\n): Promise<LaneState> {\n\tconst operationId = stored.laneState.value.currentOperationId;\n\tlet operation: LaneState[\"operation\"] = null;\n\tif (operationId !== null) {\n\t\tconst [meta, state] = await Promise.all([\n\t\t\treader.getValue(operationMeta(operationId), context),\n\t\t\treader.getValue(operationState(operationId), context),\n\t\t]);\n\t\tif (meta === undefined) throw new SessionInvariantError(`Operation ${operationId} is missing op.meta`);\n\t\tif (state === undefined) throw new SessionInvariantError(`Operation ${operationId} is missing op.state`);\n\t\tif (meta.value.operationId !== operationId) {\n\t\t\tthrow new SessionInvariantError(\n\t\t\t\t`Operation ${operationId} metadata names operation ${JSON.stringify(meta.value.operationId)}`,\n\t\t\t);\n\t\t}\n\t\tif (meta.value.lane !== lane) {\n\t\t\tthrow new SessionInvariantError(\n\t\t\t\t`Operation ${operationId} belongs to lane ${JSON.stringify(meta.value.lane)}, not ${JSON.stringify(lane)}`,\n\t\t\t);\n\t\t}\n\t\tif (!stateMatchesIntent(meta.value.intent, state.value)) {\n\t\t\tthrow new SessionInvariantError(\n\t\t\t\t`Operation ${operationId} intent ${meta.value.intent.kind} does not match state ${state.value.at}`,\n\t\t\t);\n\t\t}\n\t\toperation = { meta: meta.value, state: state.value };\n\t}\n\n\treturn {\n\t\ttipId: stored.tip.value,\n\t\tconfiguration: stored.configuration.value,\n\t\tinbox: stored.laneState.value.inbox,\n\t\tlastOperationId: stored.laneState.value.lastOperationId,\n\t\toperation,\n\t};\n}\n"]}
1
+ {"version":3,"file":"restore.d.ts","sourceRoot":"","sources":["../../../src/harness/runtime/restore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,EACX,SAAS,IAAI,gBAAgB,EAC7B,iBAAiB,EAGjB,OAAO,EACP,aAAa,EACb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAON,KA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,WAAW,oBAAoB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAC1G,CAAC;QACH,CAAC;QACD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACzD,MAAM,IAAI,qBAAqB,CAC9B,aAAa,WAAW,WAAW,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,yBAAyB,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,CAClG,CAAC;QACH,CAAC;QACD,SAAS,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;IACtD,CAAC;IAED,OAAO;QACN,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK;QACvB,aAAa,EAAE,MAAM,CAAC,aAAa,CAAC,KAAK;QACzC,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK;QACnC,eAAe,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,eAAe;QACvD,SAAS;KACT,CAAC;AAAA,CACF","sourcesContent":["import type { Context } from \"../context.ts\";\nimport { SessionInvariantError } from \"../session/session.ts\";\nimport type {\n\tLaneState as DurableLaneState,\n\tLaneConfiguration,\n\tOperationMeta,\n\tOperationState,\n\tSession,\n\tSessionReader,\n} from \"../session/types.ts\";\nimport {\n\tbranchTip,\n\tbranchTipInventoryPrefix,\n\tlaneConfig,\n\tlaneState as laneStateValue,\n\toperationMeta,\n\toperationState,\n\ttype StoredValue,\n} from \"../session/values.ts\";\nimport type { LaneState } from \"./types.ts\";\n\nfunction isSummaryState(state: OperationState): state is Extract<OperationState, { at: `summary.${string}` }> {\n\treturn state.at.startsWith(\"summary.\");\n}\n\nfunction stateMatchesIntent(intent: OperationMeta[\"intent\"], state: OperationState): boolean {\n\tif (intent.kind === \"compaction\") return isSummaryState(state) && state.task.boundary.kind === \"finish\";\n\tif (intent.kind === \"navigation\") {\n\t\tif (state.at === \"navigation.ready_to_commit\") {\n\t\t\treturn !intent.summarize && state.targetId === intent.targetId && state.label === intent.label;\n\t\t}\n\t\treturn (\n\t\t\tintent.summarize &&\n\t\t\tisSummaryState(state) &&\n\t\t\tstate.task.boundary.kind === \"commit_navigation\" &&\n\t\t\tstate.task.boundary.targetId === intent.targetId &&\n\t\t\tstate.task.boundary.label === intent.label &&\n\t\t\tstate.task.customInstructions === intent.customInstructions\n\t\t);\n\t}\n\treturn (\n\t\tstate.at !== \"navigation.ready_to_commit\" &&\n\t\t(!isSummaryState(state) || state.task.boundary.kind === \"resume_checkpoint\")\n\t);\n}\n\ntype LaneValues = {\n\ttip: StoredValue<string | null> | undefined;\n\tconfiguration: StoredValue<LaneConfiguration> | undefined;\n\tlaneState: StoredValue<DurableLaneState> | undefined;\n};\n\nexport type ClassifiedLaneStorage =\n\t| { kind: \"absent\" }\n\t| { kind: \"branch\"; tip: StoredValue<string | null> }\n\t| {\n\t\t\tkind: \"lane\";\n\t\t\ttip: StoredValue<string | null>;\n\t\t\tconfiguration: StoredValue<LaneConfiguration>;\n\t\t\tlaneState: StoredValue<DurableLaneState>;\n\t };\n\nfunction classifyLaneStorage(lane: string, values: LaneValues): ClassifiedLaneStorage {\n\tconst { tip, configuration, laneState } = values;\n\tif (tip === undefined && configuration === undefined && laneState === undefined) {\n\t\treturn { kind: \"absent\" };\n\t}\n\tif (tip !== undefined && configuration === undefined && laneState === undefined) {\n\t\treturn { kind: \"branch\", tip };\n\t}\n\tif (tip === undefined) throw new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing branch.tip`);\n\tif (configuration === undefined)\n\t\tthrow new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.config`);\n\tif (laneState === undefined) throw new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.state`);\n\treturn { kind: \"lane\", tip, configuration, laneState };\n}\n\nexport async function readLaneStorage(\n\treader: SessionReader,\n\tlane: string,\n\tcontext: Context,\n): Promise<ClassifiedLaneStorage> {\n\tconst [tip, configuration, laneState] = await Promise.all([\n\t\treader.getValue(branchTip(lane), context),\n\t\treader.getValue(laneConfig(lane), context),\n\t\treader.getValue(laneStateValue(lane), context),\n\t]);\n\treturn classifyLaneStorage(lane, { tip, configuration, laneState });\n}\n\n/** Restore every complete configured AgentLane in one coherent Session read. */\nexport function restoreSession(session: Session, context: Context): Promise<Map<string, LaneState>> {\n\treturn session.mutate(async (reader) => {\n\t\tconst [tips, configurations, states] = await Promise.all([\n\t\t\treader.scanValues(branchTipInventoryPrefix(), context),\n\t\t\treader.scanValues(laneConfig(\"\"), context),\n\t\t\treader.scanValues(laneStateValue(\"\"), context),\n\t\t]);\n\t\tconst tipByLane = new Map(tips.map((value) => [value.address.key, value]));\n\t\tconst configurationByLane = new Map(configurations.map((value) => [value.address.key, value]));\n\t\tconst stateByLane = new Map(states.map((value) => [value.address.key, value]));\n\t\tconst names = new Set([...tipByLane.keys(), ...configurationByLane.keys(), ...stateByLane.keys()]);\n\t\tconst restored = new Map<string, LaneState>();\n\t\tfor (const lane of names) {\n\t\t\tconst stored = classifyLaneStorage(lane, {\n\t\t\t\ttip: tipByLane.get(lane),\n\t\t\t\tconfiguration: configurationByLane.get(lane),\n\t\t\t\tlaneState: stateByLane.get(lane),\n\t\t\t});\n\t\t\tif (stored.kind !== \"lane\") continue;\n\t\t\trestored.set(lane, await restoreLaneState(reader, lane, stored, context));\n\t\t}\n\t\treturn restored;\n\t}, context);\n}\n\n/** Restore one configured lane without starting work or interpreting its state. */\nexport function restoreLane(session: Session, lane: string, context: Context): Promise<LaneState> {\n\treturn session.mutate(async (reader) => {\n\t\tconst stored = await readLaneStorage(reader, lane, context);\n\t\tif (stored.kind === \"absent\") {\n\t\t\tthrow new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing branch.tip`);\n\t\t}\n\t\tif (stored.kind === \"branch\") {\n\t\t\tthrow new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.config`);\n\t\t}\n\t\treturn restoreLaneState(reader, lane, stored, context);\n\t}, context);\n}\n\nexport async function restoreLaneState(\n\treader: SessionReader,\n\tlane: string,\n\tstored: Extract<ClassifiedLaneStorage, { kind: \"lane\" }>,\n\tcontext: Context,\n): Promise<LaneState> {\n\tconst operationId = stored.laneState.value.currentOperationId;\n\tlet operation: LaneState[\"operation\"] = null;\n\tif (operationId !== null) {\n\t\tconst [meta, state] = await Promise.all([\n\t\t\treader.getValue(operationMeta(operationId), context),\n\t\t\treader.getValue(operationState(operationId), context),\n\t\t]);\n\t\tif (meta === undefined) throw new SessionInvariantError(`Operation ${operationId} is missing op.meta`);\n\t\tif (state === undefined) throw new SessionInvariantError(`Operation ${operationId} is missing op.state`);\n\t\tif (meta.value.operationId !== operationId) {\n\t\t\tthrow new SessionInvariantError(\n\t\t\t\t`Operation ${operationId} metadata names operation ${JSON.stringify(meta.value.operationId)}`,\n\t\t\t);\n\t\t}\n\t\tif (meta.value.lane !== lane) {\n\t\t\tthrow new SessionInvariantError(\n\t\t\t\t`Operation ${operationId} belongs to lane ${JSON.stringify(meta.value.lane)}, not ${JSON.stringify(lane)}`,\n\t\t\t);\n\t\t}\n\t\tif (!stateMatchesIntent(meta.value.intent, state.value)) {\n\t\t\tthrow new SessionInvariantError(\n\t\t\t\t`Operation ${operationId} intent ${meta.value.intent.kind} does not match state ${state.value.at}`,\n\t\t\t);\n\t\t}\n\t\toperation = { meta: meta.value, state: state.value };\n\t}\n\n\treturn {\n\t\ttipId: stored.tip.value,\n\t\tconfiguration: stored.configuration.value,\n\t\tinbox: stored.laneState.value.inbox,\n\t\tlastOperationId: stored.laneState.value.lastOperationId,\n\t\toperation,\n\t};\n}\n"]}
1
+ {"version":3,"file":"restore.js","sourceRoot":"","sources":["../../../src/harness/runtime/restore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qB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AK,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAC1G,CAAC;QACH,CAAC;QACD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACzD,MAAM,IAAI,qBAAqB,CAC9B,aAAa,WAAW,WAAW,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,yBAAyB,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,CAClG,CAAC;QACH,CAAC;QACD,SAAS,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;IACtD,CAAC;IAED,OAAO;QACN,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,KAAK;QACvB,aAAa,EAAE,MAAM,CAAC,aAAa,CAAC,KAAK;QACzC,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK;QACnC,eAAe,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,eAAe;QACvD,SAAS;KACT,CAAC;AACH,CAAC","sourcesContent":["import type { Context } from \"../context.ts\";\nimport { SessionInvariantError } from \"../session/session.ts\";\nimport type {\n\tLaneState as DurableLaneState,\n\tLaneConfiguration,\n\tOperationMeta,\n\tOperationState,\n\tSession,\n\tSessionReader,\n} from \"../session/types.ts\";\nimport {\n\tbranchTip,\n\tbranchTipInventoryPrefix,\n\tlaneConfig,\n\tlaneState as laneStateValue,\n\toperationMeta,\n\toperationState,\n\ttype StoredValue,\n} from \"../session/values.ts\";\nimport type { LaneState } from \"./types.ts\";\n\nfunction isSummaryState(state: OperationState): state is Extract<OperationState, { at: `summary.${string}` }> {\n\treturn state.at.startsWith(\"summary.\");\n}\n\nfunction stateMatchesIntent(intent: OperationMeta[\"intent\"], state: OperationState): boolean {\n\tif (intent.kind === \"compaction\") return isSummaryState(state) && state.task.boundary.kind === \"finish\";\n\tif (intent.kind === \"navigation\") {\n\t\tif (state.at === \"navigation.ready_to_commit\") {\n\t\t\treturn !intent.summarize && state.targetId === intent.targetId && state.label === intent.label;\n\t\t}\n\t\treturn (\n\t\t\tintent.summarize &&\n\t\t\tisSummaryState(state) &&\n\t\t\tstate.task.boundary.kind === \"commit_navigation\" &&\n\t\t\tstate.task.boundary.targetId === intent.targetId &&\n\t\t\tstate.task.boundary.label === intent.label &&\n\t\t\tstate.task.customInstructions === intent.customInstructions\n\t\t);\n\t}\n\treturn (\n\t\tstate.at !== \"navigation.ready_to_commit\" &&\n\t\t(!isSummaryState(state) || state.task.boundary.kind === \"resume_checkpoint\")\n\t);\n}\n\ntype LaneValues = {\n\ttip: StoredValue<string | null> | undefined;\n\tconfiguration: StoredValue<LaneConfiguration> | undefined;\n\tlaneState: StoredValue<DurableLaneState> | undefined;\n};\n\nexport type ClassifiedLaneStorage =\n\t| { kind: \"absent\" }\n\t| { kind: \"branch\"; tip: StoredValue<string | null> }\n\t| {\n\t\t\tkind: \"lane\";\n\t\t\ttip: StoredValue<string | null>;\n\t\t\tconfiguration: StoredValue<LaneConfiguration>;\n\t\t\tlaneState: StoredValue<DurableLaneState>;\n\t };\n\nfunction classifyLaneStorage(lane: string, values: LaneValues): ClassifiedLaneStorage {\n\tconst { tip, configuration, laneState } = values;\n\tif (tip === undefined && configuration === undefined && laneState === undefined) {\n\t\treturn { kind: \"absent\" };\n\t}\n\tif (tip !== undefined && configuration === undefined && laneState === undefined) {\n\t\treturn { kind: \"branch\", tip };\n\t}\n\tif (tip === undefined) throw new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing branch.tip`);\n\tif (configuration === undefined)\n\t\tthrow new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.config`);\n\tif (laneState === undefined) throw new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.state`);\n\treturn { kind: \"lane\", tip, configuration, laneState };\n}\n\nexport async function readLaneStorage(\n\treader: SessionReader,\n\tlane: string,\n\tcontext: Context,\n): Promise<ClassifiedLaneStorage> {\n\tconst [tip, configuration, laneState] = await Promise.all([\n\t\treader.getValue(branchTip(lane), context),\n\t\treader.getValue(laneConfig(lane), context),\n\t\treader.getValue(laneStateValue(lane), context),\n\t]);\n\treturn classifyLaneStorage(lane, { tip, configuration, laneState });\n}\n\n/** Restore every complete configured AgentLane in one coherent Session read. */\nexport function restoreSession(session: Session, context: Context): Promise<Map<string, LaneState>> {\n\treturn session.mutate(async (reader) => {\n\t\tconst [tips, configurations, states] = await Promise.all([\n\t\t\treader.scanValues(branchTipInventoryPrefix(), context),\n\t\t\treader.scanValues(laneConfig(\"\"), context),\n\t\t\treader.scanValues(laneStateValue(\"\"), context),\n\t\t]);\n\t\tconst tipByLane = new Map(tips.map((value) => [value.address.key, value]));\n\t\tconst configurationByLane = new Map(configurations.map((value) => [value.address.key, value]));\n\t\tconst stateByLane = new Map(states.map((value) => [value.address.key, value]));\n\t\tconst names = new Set([...tipByLane.keys(), ...configurationByLane.keys(), ...stateByLane.keys()]);\n\t\tconst restored = new Map<string, LaneState>();\n\t\tfor (const lane of names) {\n\t\t\tconst stored = classifyLaneStorage(lane, {\n\t\t\t\ttip: tipByLane.get(lane),\n\t\t\t\tconfiguration: configurationByLane.get(lane),\n\t\t\t\tlaneState: stateByLane.get(lane),\n\t\t\t});\n\t\t\tif (stored.kind !== \"lane\") continue;\n\t\t\trestored.set(lane, await restoreLaneState(reader, lane, stored, context));\n\t\t}\n\t\treturn restored;\n\t}, context);\n}\n\n/** Restore one configured lane without starting work or interpreting its state. */\nexport function restoreLane(session: Session, lane: string, context: Context): Promise<LaneState> {\n\treturn session.mutate(async (reader) => {\n\t\tconst stored = await readLaneStorage(reader, lane, context);\n\t\tif (stored.kind === \"absent\") {\n\t\t\tthrow new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing branch.tip`);\n\t\t}\n\t\tif (stored.kind === \"branch\") {\n\t\t\tthrow new SessionInvariantError(`Lane ${JSON.stringify(lane)} is missing lane.config`);\n\t\t}\n\t\treturn restoreLaneState(reader, lane, stored, context);\n\t}, context);\n}\n\nexport async function restoreLaneState(\n\treader: SessionReader,\n\tlane: string,\n\tstored: Extract<ClassifiedLaneStorage, { kind: \"lane\" }>,\n\tcontext: Context,\n): Promise<LaneState> {\n\tconst operationId = stored.laneState.value.currentOperationId;\n\tlet operation: LaneState[\"operation\"] = null;\n\tif (operationId !== null) {\n\t\tconst [meta, state] = await Promise.all([\n\t\t\treader.getValue(operationMeta(operationId), context),\n\t\t\treader.getValue(operationState(operationId), context),\n\t\t]);\n\t\tif (meta === undefined) throw new SessionInvariantError(`Operation ${operationId} is missing op.meta`);\n\t\tif (state === undefined) throw new SessionInvariantError(`Operation ${operationId} is missing op.state`);\n\t\tif (meta.value.operationId !== operationId) {\n\t\t\tthrow new SessionInvariantError(\n\t\t\t\t`Operation ${operationId} metadata names operation ${JSON.stringify(meta.value.operationId)}`,\n\t\t\t);\n\t\t}\n\t\tif (meta.value.lane !== lane) {\n\t\t\tthrow new SessionInvariantError(\n\t\t\t\t`Operation ${operationId} belongs to lane ${JSON.stringify(meta.value.lane)}, not ${JSON.stringify(lane)}`,\n\t\t\t);\n\t\t}\n\t\tif (!stateMatchesIntent(meta.value.intent, state.value)) {\n\t\t\tthrow new SessionInvariantError(\n\t\t\t\t`Operation ${operationId} intent ${meta.value.intent.kind} does not match state ${state.value.at}`,\n\t\t\t);\n\t\t}\n\t\toperation = { meta: meta.value, state: state.value };\n\t}\n\n\treturn {\n\t\ttipId: stored.tip.value,\n\t\tconfiguration: stored.configuration.value,\n\t\tinbox: stored.laneState.value.inbox,\n\t\tlastOperationId: stored.laneState.value.lastOperationId,\n\t\toperation,\n\t};\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"transcript.d.ts","sourceRoot":"","sources":["../../../src/harness/runtime/transcript.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAA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AAc,EAC1G,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EACpB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,MAAM,GAChB,OAAO,CAAC,uBAAuB,CAAC,YAAY,EAAE,CAAC,CAAC,CAWlD;AAED,wBAAgB,cAAc,CAC7B,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,SAAS,SAAS,EAAE,EAC3B,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,cAAc,EAAE,CAAC,CAsB3B;AAED,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,aAAa,EACrB,GAAG,EAAE,SAAS,MAAM,EAAE,EACtB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,KAAK,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,CAAC,CAAC,CAU5D","sourcesContent":["import type { AgentMessage } from \"../../types.ts\";\nimport type { HarnessEvent, LaneQueuedItem } from \"../agent-harness.ts\";\nimport type { Context } from \"../context.ts\";\nimport { materializeCommittedEntry } from \"../session/commit.ts\";\nimport { buildSessionContext } from \"../session/context.ts\";\nimport { SessionInvariantError } from \"../session/session.ts\";\nimport type { CommitResult, Entry, InboxItem, NewEntry, OperationState, SessionReader } from \"../session/types.ts\";\nimport { pendingEntry } from \"../session/values.ts\";\nimport type { Lane } from \"./lane.ts\";\nimport type { ContinueOperationResult, Drive } from \"./types.ts\";\n\nexport function chainEntries<T extends { id: string }>(\n\tparentId: string | null,\n\titems: readonly T[],\n): Array<T & { parentId: string | null }> {\n\treturn items.map((item) => {\n\t\tconst entry = { ...item, parentId };\n\t\tparentId = item.id;\n\t\treturn entry;\n\t});\n}\n\nexport function entryLifecycleEvents(entry: Entry, lane: string, runId?: string): HarnessEvent[] {\n\tconst operation = runId === undefined ? {} : { runId };\n\treturn entry.type === \"message\"\n\t\t? [\n\t\t\t\t{ type: \"message_start\", lane, ...operation, message: entry.message },\n\t\t\t\t{ type: \"message_end\", lane, ...operation, message: entry.message, entryId: entry.id },\n\t\t\t\t{ type: \"entry_added\", lane, entry },\n\t\t\t]\n\t\t: [{ type: \"entry_added\", lane, entry }];\n}\n\nexport function committedEntryEvents(\n\tentries: readonly NewEntry[],\n\tcommit: CommitResult,\n\tlane: string,\n\trunId?: string,\n\tfirstWriteIndex = 0,\n): HarnessEvent[] {\n\treturn entries.flatMap((entry, index) =>\n\t\tentryLifecycleEvents(\n\t\t\tmaterializeCommittedEntry(entry, commit.seqs[firstWriteIndex + index]!, commit.timestamp),\n\t\t\tlane,\n\t\t\trunId,\n\t\t),\n\t);\n}\n\nexport function readBoundedEntries<TContext extends object | undefined, TState extends OperationState>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tcapability: TState,\n): Promise<ContinueOperationResult<Entry[]>> {\n\treturn lane.continueOperation(\n\t\tcapability,\n\t\tasync (state, _current, _meta, reader) => {\n\t\t\tif (state.tipId === null) throw new SessionInvariantError(\"Run operation has no Branch tip\");\n\t\t\tconst entries = await reader.scanBranch(\n\t\t\t\t{ start: state.tipId, stopAtType: \"compaction\", order: \"newestFirst\" },\n\t\t\t\tdrive.context,\n\t\t\t);\n\t\t\treturn { kind: \"return\", result: entries.reverse() };\n\t\t},\n\t\tdrive.context,\n\t);\n}\n\nexport async function readBoundedContext<TContext extends object | undefined, TState extends OperationState>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tcapability: TState,\n): Promise<ContinueOperationResult<AgentMessage[]>> {\n\tconst entries = await readBoundedEntries(lane, drive, capability);\n\tif (entries.kind === \"cancel_requested\") return entries;\n\treturn {\n\t\tkind: \"result\",\n\t\tvalue: await buildSessionContext(\n\t\t\tentries.value,\n\t\t\t{ entryProjectors: lane.readConfig().entryProjectors },\n\t\t\tdrive.context,\n\t\t),\n\t};\n}\n\nexport function readLaneQueues(\n\treader: SessionReader,\n\tinbox: readonly InboxItem[],\n\tcontext: Context,\n): Promise<LaneQueuedItem[]> {\n\treturn Promise.all(\n\t\tinbox.map(async (item): Promise<LaneQueuedItem> => {\n\t\t\tconst stored = await reader.getValue(pendingEntry(item.entryId), context);\n\t\t\tif (stored === undefined) {\n\t\t\t\tthrow new SessionInvariantError(`Pending ${item.kind} entry ${item.entryId} is missing its payload`);\n\t\t\t}\n\t\t\tif (stored.value.type === \"message\") {\n\t\t\t\treturn { entryId: item.entryId, kind: item.kind, type: \"message\", message: stored.value.payload };\n\t\t\t}\n\t\t\tif (item.kind !== \"write\") {\n\t\t\t\tthrow new SessionInvariantError(`Pending ${item.kind} entry ${item.entryId} is not a message`);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tentryId: item.entryId,\n\t\t\t\tkind: \"write\",\n\t\t\t\ttype: \"custom\",\n\t\t\t\tcustomType: stored.value.customType,\n\t\t\t\t...(stored.value.payload === undefined ? {} : { data: stored.value.payload }),\n\t\t\t};\n\t\t}),\n\t);\n}\n\nexport function readPendingMessages(\n\treader: SessionReader,\n\tids: readonly string[],\n\tdescription: string,\n\tcontext: Context,\n): Promise<Array<{ entryId: string; message: AgentMessage }>> {\n\treturn Promise.all(\n\t\tids.map(async (entryId) => {\n\t\t\tconst value = await reader.getValue(pendingEntry(entryId), context);\n\t\t\tif (value?.value.type !== \"message\") {\n\t\t\t\tthrow new SessionInvariantError(`${description} ${entryId} is missing its message payload`);\n\t\t\t}\n\t\t\treturn { entryId, message: value.value.payload };\n\t\t}),\n\t);\n}\n"]}
1
+ {"version":3,"file":"transcript.d.ts","sourceRoot":"","sources":["../../../src/harness/runtime/transcript.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAI7C,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,cA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AAC;QACD,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC3B,MAAM,IAAI,qBAAqB,CAAC,WAAW,IAAI,CAAC,IAAI,UAAU,IAAI,CAAC,OAAO,mBAAmB,CAAC,CAAC;QAChG,CAAC;QACD,OAAO;YACN,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,UAAU;YACnC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;SAC7E,CAAC;IAAA,CACF,CAAC,CACF,CAAC;AAAA,CACF;AAED,MAAM,UAAU,mBAAmB,CAClC,MAAqB,EACrB,GAAsB,EACtB,WAAmB,EACnB,OAAgB,EAC6C;IAC7D,OAAO,OAAO,CAAC,GAAG,CACjB,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;QACpE,IAAI,KAAK,EAAE,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YACrC,MAAM,IAAI,qBAAqB,CAAC,GAAG,WAAW,IAAI,OAAO,iCAAiC,CAAC,CAAC;QAC7F,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IAAA,CACjD,CAAC,CACF,CAAC;AAAA,CACF","sourcesContent":["import type { AgentMessage } from \"../../types.ts\";\nimport type { HarnessEvent, LaneQueuedItem } from \"../agent-harness.ts\";\nimport type { Context } from \"../context.ts\";\nimport { materializeCommittedEntry } from \"../session/commit.ts\";\nimport { buildSessionContext } from \"../session/context.ts\";\nimport { SessionInvariantError } from \"../session/session.ts\";\nimport type { CommitResult, Entry, InboxItem, NewEntry, OperationState, SessionReader } from \"../session/types.ts\";\nimport { pendingEntry } from \"../session/values.ts\";\nimport type { Lane } from \"./lane.ts\";\nimport type { ContinueOperationResult, Drive } from \"./types.ts\";\n\nexport function chainEntries<T extends { id: string }>(\n\tparentId: string | null,\n\titems: readonly T[],\n): Array<T & { parentId: string | null }> {\n\treturn items.map((item) => {\n\t\tconst entry = { ...item, parentId };\n\t\tparentId = item.id;\n\t\treturn entry;\n\t});\n}\n\nexport function entryLifecycleEvents(entry: Entry, lane: string, runId?: string): HarnessEvent[] {\n\tconst operation = runId === undefined ? {} : { runId };\n\treturn entry.type === \"message\"\n\t\t? [\n\t\t\t\t{ type: \"message_start\", lane, ...operation, message: entry.message },\n\t\t\t\t{ type: \"message_end\", lane, ...operation, message: entry.message, entryId: entry.id },\n\t\t\t\t{ type: \"entry_added\", lane, entry },\n\t\t\t]\n\t\t: [{ type: \"entry_added\", lane, entry }];\n}\n\nexport function committedEntryEvents(\n\tentries: readonly NewEntry[],\n\tcommit: CommitResult,\n\tlane: string,\n\trunId?: string,\n\tfirstWriteIndex = 0,\n): HarnessEvent[] {\n\treturn entries.flatMap((entry, index) =>\n\t\tentryLifecycleEvents(\n\t\t\tmaterializeCommittedEntry(entry, commit.seqs[firstWriteIndex + index]!, commit.timestamp),\n\t\t\tlane,\n\t\t\trunId,\n\t\t),\n\t);\n}\n\nexport function readBoundedEntries<TContext extends object | undefined, TState extends OperationState>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tcapability: TState,\n): Promise<ContinueOperationResult<Entry[]>> {\n\treturn lane.continueOperation(\n\t\tcapability,\n\t\tasync (state, _current, _meta, reader) => {\n\t\t\tif (state.tipId === null) throw new SessionInvariantError(\"Run operation has no Branch tip\");\n\t\t\tconst entries = await reader.scanBranch(\n\t\t\t\t{ start: state.tipId, stopAtType: \"compaction\", order: \"newestFirst\" },\n\t\t\t\tdrive.context,\n\t\t\t);\n\t\t\treturn { kind: \"return\", result: entries.reverse() };\n\t\t},\n\t\tdrive.context,\n\t);\n}\n\nexport async function readBoundedContext<TContext extends object | undefined, TState extends OperationState>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tcapability: TState,\n): Promise<ContinueOperationResult<AgentMessage[]>> {\n\tconst entries = await readBoundedEntries(lane, drive, capability);\n\tif (entries.kind === \"cancel_requested\") return entries;\n\treturn {\n\t\tkind: \"result\",\n\t\tvalue: await buildSessionContext(\n\t\t\tentries.value,\n\t\t\t{ entryProjectors: lane.readConfig().entryProjectors },\n\t\t\tdrive.context,\n\t\t),\n\t};\n}\n\nexport function readLaneQueues(\n\treader: SessionReader,\n\tinbox: readonly InboxItem[],\n\tcontext: Context,\n): Promise<LaneQueuedItem[]> {\n\treturn Promise.all(\n\t\tinbox.map(async (item): Promise<LaneQueuedItem> => {\n\t\t\tconst stored = await reader.getValue(pendingEntry(item.entryId), context);\n\t\t\tif (stored === undefined) {\n\t\t\t\tthrow new SessionInvariantError(`Pending ${item.kind} entry ${item.entryId} is missing its payload`);\n\t\t\t}\n\t\t\tif (stored.value.type === \"message\") {\n\t\t\t\treturn { entryId: item.entryId, kind: item.kind, type: \"message\", message: stored.value.payload };\n\t\t\t}\n\t\t\tif (item.kind !== \"write\") {\n\t\t\t\tthrow new SessionInvariantError(`Pending ${item.kind} entry ${item.entryId} is not a message`);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tentryId: item.entryId,\n\t\t\t\tkind: \"write\",\n\t\t\t\ttype: \"custom\",\n\t\t\t\tcustomType: stored.value.customType,\n\t\t\t\t...(stored.value.payload === undefined ? {} : { data: stored.value.payload }),\n\t\t\t};\n\t\t}),\n\t);\n}\n\nexport function readPendingMessages(\n\treader: SessionReader,\n\tids: readonly string[],\n\tdescription: string,\n\tcontext: Context,\n): Promise<Array<{ entryId: string; message: AgentMessage }>> {\n\treturn Promise.all(\n\t\tids.map(async (entryId) => {\n\t\t\tconst value = await reader.getValue(pendingEntry(entryId), context);\n\t\t\tif (value?.value.type !== \"message\") {\n\t\t\t\tthrow new SessionInvariantError(`${description} ${entryId} is missing its message payload`);\n\t\t\t}\n\t\t\treturn { entryId, message: value.value.payload };\n\t\t}),\n\t);\n}\n"]}
1
+ {"version":3,"file":"transcript.js","sourceRoot":"","sources":["../../../src/harness/runtime/transcript.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIpD,MAAM,UAAU,YAAY,CAC3B,QAAuB,EACvB,KAAmB;IAEnB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACzB,MAAM,KAAK,GAAG,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,CAAC;QACpC,QAAQ,GAAG,IAAI,CAAC,EAAE,CAAC;QACnB,OAAO,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAY,EAAE,IAAY,EAAE,KAAc;IAC9E,MAAM,SAAS,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;IACvD,OAAO,KAAK,CAAC,IAAI,KAAK,SAAS;QAC9B,CAAC,CAAC;YACA,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,GAAG,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;YACrE,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAA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YACrB,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,UAAU;YACnC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;SAC7E,CAAC;IACH,CAAC,CAAC,CACF,CAAC;AACH,CAAC;AAED,MAAM,UAAU,mBAAmB,CAClC,MAAqB,EACrB,GAAsB,EACtB,WAAmB,EACnB,OAAgB;IAEhB,OAAO,OAAO,CAAC,GAAG,CACjB,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACzB,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC;QACpE,IAAI,KAAK,EAAE,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YACrC,MAAM,IAAI,qBAAqB,CAAC,GAAG,WAAW,IAAI,OAAO,iCAAiC,CAAC,CAAC;QAC7F,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IAClD,CAAC,CAAC,CACF,CAAC;AACH,CAAC","sourcesContent":["import type { AgentMessage } from \"../../types.ts\";\nimport type { HarnessEvent, LaneQueuedItem } from \"../agent-harness.ts\";\nimport type { Context } from \"../context.ts\";\nimport { materializeCommittedEntry } from \"../session/commit.ts\";\nimport { buildSessionContext } from \"../session/context.ts\";\nimport { SessionInvariantError } from \"../session/session.ts\";\nimport type { CommitResult, Entry, InboxItem, NewEntry, OperationState, SessionReader } from \"../session/types.ts\";\nimport { pendingEntry } from \"../session/values.ts\";\nimport type { Lane } from \"./lane.ts\";\nimport type { ContinueOperationResult, Drive } from \"./types.ts\";\n\nexport function chainEntries<T extends { id: string }>(\n\tparentId: string | null,\n\titems: readonly T[],\n): Array<T & { parentId: string | null }> {\n\treturn items.map((item) => {\n\t\tconst entry = { ...item, parentId };\n\t\tparentId = item.id;\n\t\treturn entry;\n\t});\n}\n\nexport function entryLifecycleEvents(entry: Entry, lane: string, runId?: string): HarnessEvent[] {\n\tconst operation = runId === undefined ? {} : { runId };\n\treturn entry.type === \"message\"\n\t\t? [\n\t\t\t\t{ type: \"message_start\", lane, ...operation, message: entry.message },\n\t\t\t\t{ type: \"message_end\", lane, ...operation, message: entry.message, entryId: entry.id },\n\t\t\t\t{ type: \"entry_added\", lane, entry },\n\t\t\t]\n\t\t: [{ type: \"entry_added\", lane, entry }];\n}\n\nexport function committedEntryEvents(\n\tentries: readonly NewEntry[],\n\tcommit: CommitResult,\n\tlane: string,\n\trunId?: string,\n\tfirstWriteIndex = 0,\n): HarnessEvent[] {\n\treturn entries.flatMap((entry, index) =>\n\t\tentryLifecycleEvents(\n\t\t\tmaterializeCommittedEntry(entry, commit.seqs[firstWriteIndex + index]!, commit.timestamp),\n\t\t\tlane,\n\t\t\trunId,\n\t\t),\n\t);\n}\n\nexport function readBoundedEntries<TContext extends object | undefined, TState extends OperationState>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tcapability: TState,\n): Promise<ContinueOperationResult<Entry[]>> {\n\treturn lane.continueOperation(\n\t\tcapability,\n\t\tasync (state, _current, _meta, reader) => {\n\t\t\tif (state.tipId === null) throw new SessionInvariantError(\"Run operation has no Branch tip\");\n\t\t\tconst entries = await reader.scanBranch(\n\t\t\t\t{ start: state.tipId, stopAtType: \"compaction\", order: \"newestFirst\" },\n\t\t\t\tdrive.context,\n\t\t\t);\n\t\t\treturn { kind: \"return\", result: entries.reverse() };\n\t\t},\n\t\tdrive.context,\n\t);\n}\n\nexport async function readBoundedContext<TContext extends object | undefined, TState extends OperationState>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tcapability: TState,\n): Promise<ContinueOperationResult<AgentMessage[]>> {\n\tconst entries = await readBoundedEntries(lane, drive, capability);\n\tif (entries.kind === \"cancel_requested\") return entries;\n\treturn {\n\t\tkind: \"result\",\n\t\tvalue: await buildSessionContext(\n\t\t\tentries.value,\n\t\t\t{ entryProjectors: lane.readConfig().entryProjectors },\n\t\t\tdrive.context,\n\t\t),\n\t};\n}\n\nexport function readLaneQueues(\n\treader: SessionReader,\n\tinbox: readonly InboxItem[],\n\tcontext: Context,\n): Promise<LaneQueuedItem[]> {\n\treturn Promise.all(\n\t\tinbox.map(async (item): Promise<LaneQueuedItem> => {\n\t\t\tconst stored = await reader.getValue(pendingEntry(item.entryId), context);\n\t\t\tif (stored === undefined) {\n\t\t\t\tthrow new SessionInvariantError(`Pending ${item.kind} entry ${item.entryId} is missing its payload`);\n\t\t\t}\n\t\t\tif (stored.value.type === \"message\") {\n\t\t\t\treturn { entryId: item.entryId, kind: item.kind, type: \"message\", message: stored.value.payload };\n\t\t\t}\n\t\t\tif (item.kind !== \"write\") {\n\t\t\t\tthrow new SessionInvariantError(`Pending ${item.kind} entry ${item.entryId} is not a message`);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tentryId: item.entryId,\n\t\t\t\tkind: \"write\",\n\t\t\t\ttype: \"custom\",\n\t\t\t\tcustomType: stored.value.customType,\n\t\t\t\t...(stored.value.payload === undefined ? {} : { data: stored.value.payload }),\n\t\t\t};\n\t\t}),\n\t);\n}\n\nexport function readPendingMessages(\n\treader: SessionReader,\n\tids: readonly string[],\n\tdescription: string,\n\tcontext: Context,\n): Promise<Array<{ entryId: string; message: AgentMessage }>> {\n\treturn Promise.all(\n\t\tids.map(async (entryId) => {\n\t\t\tconst value = await reader.getValue(pendingEntry(entryId), context);\n\t\t\tif (value?.value.type !== \"message\") {\n\t\t\t\tthrow new SessionInvariantError(`${description} ${entryId} is missing its message payload`);\n\t\t\t}\n\t\t\treturn { entryId, message: value.value.payload };\n\t\t}),\n\t);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"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AAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,eAAe,EAAE,MAAM,CAAC;IAExB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;IACtC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkB;IAClD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAkC;IACpE,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA2B;IAE5D,YAAY,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAmBlD;IAED,MAAM,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAElC;IAED,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAEzB;IAED,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAE5C;IAED,WAAW,IAAI,IAAI,CAElB;IAED,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAI5B;CACD;AAED,MAAM,MAAM,eAAe,GACxB;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,GACpB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,qBAAqB,CAAA;CAAE,CAAC","sourcesContent":["import type { RetryPolicy } from \"@earendil-works/pi-ai\";\nimport type { QueueMode } from \"../../types.ts\";\nimport type { AgentHarnessOptions, DriveOptions, DriveOutcome, HarnessEvent, Resources } from \"../agent-harness.ts\";\nimport type { CompactionSettings } from \"../compaction/compaction.ts\";\nimport { type Context, withoutAbortSignal } from \"../context.ts\";\nimport { createGate, type Gate, type GateControl } from \"../execution/effect-gate.ts\";\nimport type {\n\tCommitResult,\n\tInboxItem,\n\tLaneConfiguration,\n\tOperation,\n\tOperationResultRecord,\n\tOperationState,\n\tWrite,\n} from \"../session/types.ts\";\nimport type { AgentHarnessStreamOptions, AgentHarnessTool } from \"../types.ts\";\n\nexport class SliceNotImplemented extends Error {\n\tconstructor(operation: string) {\n\t\tsuper(`${operation} is not implemented until its later AgentHarness slice`);\n\t\tthis.name = \"SliceNotImplemented\";\n\t}\n}\n\n/** Current process-local harness configuration. */\nexport interface Config<TContext extends object | undefined> {\n\treadonly tools: AgentHarnessTool<TContext>[];\n\treadonly resources: Resources;\n\treadonly streamOptions: AgentHarnessStreamOptions;\n\treadonly retryPolicy: RetryPolicy;\n\treadonly compaction: CompactionSettings;\n\treadonly steeringMode: QueueMode;\n\treadonly followUpMode: QueueMode;\n\treadonly toolExecution: \"sequential\" | \"parallel\";\n\treadonly toolContext: AgentHarnessOptions<TContext>[\"toolContext\"];\n\treadonly systemPrompt: AgentHarnessOptions<TContext>[\"systemPrompt\"];\n\treadonly toProviderMessages: NonNullable<AgentHarnessOptions<TContext>[\"toProviderMessages\"]>;\n\treadonly entryProjectors: Readonly<NonNullable<AgentHarnessOptions<TContext>[\"entryProjectors\"]>>;\n}\n\n/** The current durable state owned by one lane. */\nexport interface LaneState {\n\treadonly tipId: string | null;\n\treadonly configuration: LaneConfiguration;\n\treadonly inbox: InboxItem[];\n\treadonly lastOperationId: string | null;\n\treadonly operation: Operation | null;\n}\n\ntype Synchronous<TResult> = TResult extends PromiseLike<unknown> ? never : TResult;\n\ninterface CommitDecision<TResult> {\n\tkind: \"commit\";\n\twrites: Write[];\n\tmaterialize(commit: CommitResult): Synchronous<TResult>;\n\tevents?(commit: CommitResult): HarnessEvent[];\n}\n\n/** One effect-free decision made on a lane's serialized mutation line. */\nexport type LaneCommand<TResult> =\n\t| (CommitDecision<TResult> & { next: LaneState })\n\t| { kind: \"return\"; result: TResult }\n\t| { kind: \"reject\"; error: Error };\n\nexport type ContinueOperationResult<TResult> = { kind: \"cancel_requested\" } | { kind: \"result\"; value: TResult };\n\n/** A durable operation transition. The Lane pairs the state write with projection publication. */\ntype LanePatch = Partial<Pick<LaneState, \"tipId\" | \"configuration\" | \"inbox\">>;\n\ninterface FinishDecision<TResult> {\n\tkind: \"finish\";\n\twrites: Write[];\n\trecord: OperationResultRecord;\n\tlane?: LanePatch;\n\tmaterialize(commit: CommitResult): Synchronous<TResult>;\n\tevents?(commit: CommitResult): HarnessEvent[];\n}\n\nexport type OperationCommand<TResult> =\n\t| (CommitDecision<TResult> & { operationState: OperationState; lane?: LanePatch })\n\t| FinishDecision<TResult>\n\t| { kind: \"return\"; result: TResult };\n\n/** One installed process-local drive pass. */\nexport class Drive {\n\treadonly operationId: string;\n\treadonly completion: Promise<DriveOutcome>;\n\treadonly gate: Gate;\n\treadonly context: Context;\n\treadonly waitForRetry: boolean;\n\treadonly closeSignal: AbortSignal;\n\tdeferredPermits: number;\n\n\tprivate readonly control: GateControl;\n\tprivate readonly closeController: AbortController;\n\tprivate readonly resolveCompletion: (outcome: DriveOutcome) => void;\n\tprivate readonly rejectCompletion: (error: unknown) => void;\n\n\tconstructor(options: DriveOptions, context: Context) {\n\t\tthis.operationId = options.operationId;\n\t\tthis.context = withoutAbortSignal(context);\n\t\tthis.waitForRetry = options.waitForRetry ?? false;\n\t\tthis.deferredPermits = options.pollDeferred === true ? 1 : 0;\n\t\tlet resolveCompletion!: (outcome: DriveOutcome) => void;\n\t\tlet rejectCompletion!: (error: unknown) => void;\n\t\tthis.completion = new Promise<DriveOutcome>((resolve, reject) => {\n\t\t\tresolveCompletion = resolve;\n\t\t\trejectCompletion = reject;\n\t\t});\n\t\tthis.resolveCompletion = resolveCompletion;\n\t\tthis.rejectCompletion = rejectCompletion;\n\t\tvoid this.completion.catch(() => {});\n\t\tconst { gate, control } = createGate();\n\t\tthis.gate = gate;\n\t\tthis.control = control;\n\t\tthis.closeController = new AbortController();\n\t\tthis.closeSignal = this.closeController.signal;\n\t}\n\n\tsettle(outcome: DriveOutcome): void {\n\t\tthis.resolveCompletion(outcome);\n\t}\n\n\tfail(error: unknown): void {\n\t\tthis.rejectCompletion(error);\n\t}\n\n\tbeginAbort(cancellation: Promise<void>): void {\n\t\tthis.control.beginAbort(cancellation);\n\t}\n\n\tsignalAbort(): void {\n\t\tthis.control.signalAbort();\n\t}\n\n\tcloseGate(error: Error): void {\n\t\tthis.control.close(error);\n\t\tif (!this.closeSignal.aborted) this.closeController.abort(error);\n\t\tthis.rejectCompletion(error);\n\t}\n}\n\nexport type ProcedureResult =\n\t| { kind: \"continue\" }\n\t| { kind: \"waiting\"; outcome: DriveOutcome }\n\t| { kind: \"settled\"; outcome: OperationResultRecord };\n"]}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/harness/runtime/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACpH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,KAAK,OAAO,EAAsB,MAAM,eAAe,CAAC;AACjE,OAAO,EAAc,KAAK,IAAI,EAAoB,MAAM,6BAA6B,CAAC;AACtF,OAAO,KAAK,EACX,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,qBAAqB,EACrB,cAAc,EACd,KAAK,EACL,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,yBAAyB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/E,qBAAa,mBAAoB,SAAQ,KAAK;IAC7C,YAAY,SAAS,EAAE,MAAM,EAG5B;CACD;AAED,mDAAmD;AACnD,MAAM,WAAW,MAAM,CAAC,QAAQ,SAAS,MAAM,GAAG,SAAS;IAC1D,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC7C,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,aAAa,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,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,EAAE,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;QAC7C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC;IAAA,CAC/C;IAED,MAAM,CAAC,OAAqB,EAAQ;QACnC,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAAA,CAChC;IAED,IAAI,CAAC,KAAc,EAAQ;QAC1B,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAAA,CAC7B;IAED,UAAU,CAAC,YAA2B,EAAQ;QAC7C,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IAAA,CACtC;IAED,WAAW,GAAS;QACnB,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;IAAA,CAC3B;IAED,SAAS,CAAC,KAAY,EAAQ;QAC7B,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO;YAAE,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACjE,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAAA,CAC7B;CACD","sourcesContent":["import type { RetryPolicy } from \"@earendil-works/pi-ai\";\nimport type { QueueMode } from \"../../types.ts\";\nimport type { AgentHarnessOptions, DriveOptions, DriveOutcome, HarnessEvent, Resources } from \"../agent-harness.ts\";\nimport type { CompactionSettings } from \"../compaction/compaction.ts\";\nimport { type Context, withoutAbortSignal } from \"../context.ts\";\nimport { createGate, type Gate, type GateControl } from \"../execution/effect-gate.ts\";\nimport type {\n\tCommitResult,\n\tInboxItem,\n\tLaneConfiguration,\n\tOperation,\n\tOperationResultRecord,\n\tOperationState,\n\tWrite,\n} from \"../session/types.ts\";\nimport type { AgentHarnessStreamOptions, AgentHarnessTool } from \"../types.ts\";\n\nexport class SliceNotImplemented extends Error {\n\tconstructor(operation: string) {\n\t\tsuper(`${operation} is not implemented until its later AgentHarness slice`);\n\t\tthis.name = \"SliceNotImplemented\";\n\t}\n}\n\n/** Current process-local harness configuration. */\nexport interface Config<TContext extends object | undefined> {\n\treadonly tools: AgentHarnessTool<TContext>[];\n\treadonly resources: Resources;\n\treadonly streamOptions: AgentHarnessStreamOptions;\n\treadonly retryPolicy: RetryPolicy;\n\treadonly compaction: CompactionSettings;\n\treadonly steeringMode: QueueMode;\n\treadonly followUpMode: QueueMode;\n\treadonly toolExecution: \"sequential\" | \"parallel\";\n\treadonly toolContext: AgentHarnessOptions<TContext>[\"toolContext\"];\n\treadonly systemPrompt: AgentHarnessOptions<TContext>[\"systemPrompt\"];\n\treadonly toProviderMessages: NonNullable<AgentHarnessOptions<TContext>[\"toProviderMessages\"]>;\n\treadonly entryProjectors: Readonly<NonNullable<AgentHarnessOptions<TContext>[\"entryProjectors\"]>>;\n}\n\n/** The current durable state owned by one lane. */\nexport interface LaneState {\n\treadonly tipId: string | null;\n\treadonly configuration: LaneConfiguration;\n\treadonly inbox: InboxItem[];\n\treadonly lastOperationId: string | null;\n\treadonly operation: Operation | null;\n}\n\ntype Synchronous<TResult> = TResult extends PromiseLike<unknown> ? never : TResult;\n\ninterface CommitDecision<TResult> {\n\tkind: \"commit\";\n\twrites: Write[];\n\tmaterialize(commit: CommitResult): Synchronous<TResult>;\n\tevents?(commit: CommitResult): HarnessEvent[];\n}\n\n/** One effect-free decision made on a lane's serialized mutation line. */\nexport type LaneCommand<TResult> =\n\t| (CommitDecision<TResult> & { next: LaneState })\n\t| { kind: \"return\"; result: TResult }\n\t| { kind: \"reject\"; error: Error };\n\nexport type ContinueOperationResult<TResult> = { kind: \"cancel_requested\" } | { kind: \"result\"; value: TResult };\n\n/** A durable operation transition. The Lane pairs the state write with projection publication. */\ntype LanePatch = Partial<Pick<LaneState, \"tipId\" | \"configuration\" | \"inbox\">>;\n\ninterface FinishDecision<TResult> {\n\tkind: \"finish\";\n\twrites: Write[];\n\trecord: OperationResultRecord;\n\tlane?: LanePatch;\n\tmaterialize(commit: CommitResult): Synchronous<TResult>;\n\tevents?(commit: CommitResult): HarnessEvent[];\n}\n\nexport type OperationCommand<TResult> =\n\t| (CommitDecision<TResult> & { operationState: OperationState; lane?: LanePatch })\n\t| FinishDecision<TResult>\n\t| { kind: \"return\"; result: TResult };\n\n/** One installed process-local drive pass. */\nexport class Drive {\n\treadonly operationId: string;\n\treadonly completion: Promise<DriveOutcome>;\n\treadonly gate: Gate;\n\treadonly context: Context;\n\treadonly waitForRetry: boolean;\n\treadonly closeSignal: AbortSignal;\n\tdeferredPermits: number;\n\n\tprivate readonly control: GateControl;\n\tprivate readonly closeController: AbortController;\n\tprivate readonly resolveCompletion: (outcome: DriveOutcome) => void;\n\tprivate readonly rejectCompletion: (error: unknown) => void;\n\n\tconstructor(options: DriveOptions, context: Context) {\n\t\tthis.operationId = options.operationId;\n\t\tthis.context = withoutAbortSignal(context);\n\t\tthis.waitForRetry = options.waitForRetry ?? false;\n\t\tthis.deferredPermits = options.pollDeferred === true ? 1 : 0;\n\t\tlet resolveCompletion!: (outcome: DriveOutcome) => void;\n\t\tlet rejectCompletion!: (error: unknown) => void;\n\t\tthis.completion = new Promise<DriveOutcome>((resolve, reject) => {\n\t\t\tresolveCompletion = resolve;\n\t\t\trejectCompletion = reject;\n\t\t});\n\t\tthis.resolveCompletion = resolveCompletion;\n\t\tthis.rejectCompletion = rejectCompletion;\n\t\tvoid this.completion.catch(() => {});\n\t\tconst { gate, control } = createGate();\n\t\tthis.gate = gate;\n\t\tthis.control = control;\n\t\tthis.closeController = new AbortController();\n\t\tthis.closeSignal = this.closeController.signal;\n\t}\n\n\tsettle(outcome: DriveOutcome): void {\n\t\tthis.resolveCompletion(outcome);\n\t}\n\n\tfail(error: unknown): void {\n\t\tthis.rejectCompletion(error);\n\t}\n\n\tbeginAbort(cancellation: Promise<void>): void {\n\t\tthis.control.beginAbort(cancellation);\n\t}\n\n\tsignalAbort(): void {\n\t\tthis.control.signalAbort();\n\t}\n\n\tcloseGate(error: Error): void {\n\t\tthis.control.close(error);\n\t\tif (!this.closeSignal.aborted) this.closeController.abort(error);\n\t\tthis.rejectCompletion(error);\n\t}\n}\n\nexport type ProcedureResult =\n\t| { kind: \"continue\" }\n\t| { kind: \"waiting\"; outcome: DriveOutcome }\n\t| { kind: \"settled\"; outcome: OperationResultRecord };\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/harness/runtime/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAgB,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,UAAU,EAA+B,MAAM,6BAA6B,CAAC;AAYtF,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC7C,YAAY,SAAiB;QAC5B,KAAK,CAAC,GAAG,SAAS,wDAAwD,CAAC,CAAC;QAC5E,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACnC,CAAC;CACD;AA6DD,8CAA8C;AAC9C,MAAM,OAAO,KAAK;IACR,WAAW,CAAS;IACpB,UAAU,CAAwB;IAClC,IAAI,CAAO;IACX,OAAO,CAAU;IACjB,YAAY,CAAU;IACtB,WAAW,CAAc;IAClC,eAAe,CAAS;IAEP,OAAO,CAAc;IACrB,eAAe,CAAkB;IACjC,iBAAiB,CAAkC;IACnD,gBAAgB,CAA2B;IAE5D,YAAY,OAAqB,EAAE,OAAgB;QAClD,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAC3C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,KAAK,CAAC;QAClD,IAAI,CAAC,eAAe,G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CAAC,WAAW,CAAC,OAAO;YAAE,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACjE,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;CACD","sourcesContent":["import type { RetryPolicy } from \"@earendil-works/pi-ai\";\nimport type { QueueMode } from \"../../types.ts\";\nimport type { AgentHarnessOptions, DriveOptions, DriveOutcome, HarnessEvent, Resources } from \"../agent-harness.ts\";\nimport type { CompactionSettings } from \"../compaction/compaction.ts\";\nimport { type Context, withoutAbortSignal } from \"../context.ts\";\nimport { createGate, type Gate, type GateControl } from \"../execution/effect-gate.ts\";\nimport type {\n\tCommitResult,\n\tInboxItem,\n\tLaneConfiguration,\n\tOperation,\n\tOperationResultRecord,\n\tOperationState,\n\tWrite,\n} from \"../session/types.ts\";\nimport type { AgentHarnessStreamOptions, AgentHarnessTool } from \"../types.ts\";\n\nexport class SliceNotImplemented extends Error {\n\tconstructor(operation: string) {\n\t\tsuper(`${operation} is not implemented until its later AgentHarness slice`);\n\t\tthis.name = \"SliceNotImplemented\";\n\t}\n}\n\n/** Current process-local harness configuration. */\nexport interface Config<TContext extends object | undefined> {\n\treadonly tools: AgentHarnessTool<TContext>[];\n\treadonly resources: Resources;\n\treadonly streamOptions: AgentHarnessStreamOptions;\n\treadonly retryPolicy: RetryPolicy;\n\treadonly compaction: CompactionSettings;\n\treadonly steeringMode: QueueMode;\n\treadonly followUpMode: QueueMode;\n\treadonly toolExecution: \"sequential\" | \"parallel\";\n\treadonly toolContext: AgentHarnessOptions<TContext>[\"toolContext\"];\n\treadonly systemPrompt: AgentHarnessOptions<TContext>[\"systemPrompt\"];\n\treadonly toProviderMessages: NonNullable<AgentHarnessOptions<TContext>[\"toProviderMessages\"]>;\n\treadonly entryProjectors: Readonly<NonNullable<AgentHarnessOptions<TContext>[\"entryProjectors\"]>>;\n}\n\n/** The current durable state owned by one lane. */\nexport interface LaneState {\n\treadonly tipId: string | null;\n\treadonly configuration: LaneConfiguration;\n\treadonly inbox: InboxItem[];\n\treadonly lastOperationId: string | null;\n\treadonly operation: Operation | null;\n}\n\ntype Synchronous<TResult> = TResult extends PromiseLike<unknown> ? never : TResult;\n\ninterface CommitDecision<TResult> {\n\tkind: \"commit\";\n\twrites: Write[];\n\tmaterialize(commit: CommitResult): Synchronous<TResult>;\n\tevents?(commit: CommitResult): HarnessEvent[];\n}\n\n/** One effect-free decision made on a lane's serialized mutation line. */\nexport type LaneCommand<TResult> =\n\t| (CommitDecision<TResult> & { next: LaneState })\n\t| { kind: \"return\"; result: TResult }\n\t| { kind: \"reject\"; error: Error };\n\nexport type ContinueOperationResult<TResult> = { kind: \"cancel_requested\" } | { kind: \"result\"; value: TResult };\n\n/** A durable operation transition. The Lane pairs the state write with projection publication. */\ntype LanePatch = Partial<Pick<LaneState, \"tipId\" | \"configuration\" | \"inbox\">>;\n\ninterface FinishDecision<TResult> {\n\tkind: \"finish\";\n\twrites: Write[];\n\trecord: OperationResultRecord;\n\tlane?: LanePatch;\n\tmaterialize(commit: CommitResult): Synchronous<TResult>;\n\tevents?(commit: CommitResult): HarnessEvent[];\n}\n\nexport type OperationCommand<TResult> =\n\t| (CommitDecision<TResult> & { operationState: OperationState; lane?: LanePatch })\n\t| FinishDecision<TResult>\n\t| { kind: \"return\"; result: TResult };\n\n/** One installed process-local drive pass. */\nexport class Drive {\n\treadonly operationId: string;\n\treadonly completion: Promise<DriveOutcome>;\n\treadonly gate: Gate;\n\treadonly context: Context;\n\treadonly waitForRetry: boolean;\n\treadonly closeSignal: AbortSignal;\n\tdeferredPermits: number;\n\n\tprivate readonly control: GateControl;\n\tprivate readonly closeController: AbortController;\n\tprivate readonly resolveCompletion: (outcome: DriveOutcome) => void;\n\tprivate readonly rejectCompletion: (error: unknown) => void;\n\n\tconstructor(options: DriveOptions, context: Context) {\n\t\tthis.operationId = options.operationId;\n\t\tthis.context = withoutAbortSignal(context);\n\t\tthis.waitForRetry = options.waitForRetry ?? false;\n\t\tthis.deferredPermits = options.pollDeferred === true ? 1 : 0;\n\t\tlet resolveCompletion!: (outcome: DriveOutcome) => void;\n\t\tlet rejectCompletion!: (error: unknown) => void;\n\t\tthis.completion = new Promise<DriveOutcome>((resolve, reject) => {\n\t\t\tresolveCompletion = resolve;\n\t\t\trejectCompletion = reject;\n\t\t});\n\t\tthis.resolveCompletion = resolveCompletion;\n\t\tthis.rejectCompletion = rejectCompletion;\n\t\tvoid this.completion.catch(() => {});\n\t\tconst { gate, control } = createGate();\n\t\tthis.gate = gate;\n\t\tthis.control = control;\n\t\tthis.closeController = new AbortController();\n\t\tthis.closeSignal = this.closeController.signal;\n\t}\n\n\tsettle(outcome: DriveOutcome): void {\n\t\tthis.resolveCompletion(outcome);\n\t}\n\n\tfail(error: unknown): void {\n\t\tthis.rejectCompletion(error);\n\t}\n\n\tbeginAbort(cancellation: Promise<void>): void {\n\t\tthis.control.beginAbort(cancellation);\n\t}\n\n\tsignalAbort(): void {\n\t\tthis.control.signalAbort();\n\t}\n\n\tcloseGate(error: Error): void {\n\t\tthis.control.close(error);\n\t\tif (!this.closeSignal.aborted) this.closeController.abort(error);\n\t\tthis.rejectCompletion(error);\n\t}\n}\n\nexport type ProcedureResult =\n\t| { kind: \"continue\" }\n\t| { kind: \"waiting\"; outcome: DriveOutcome }\n\t| { kind: \"settled\"; outcome: OperationResultRecord };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"commit.d.ts","sourceRoot":"","sources":["../../../src/harness/session/commit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEzG,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAC5D,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG;IAAE,IAAI,EAAE,OAAO,C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G,UAAU,CAEvD;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,UAAU,CAElE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,cAAc,CAexF;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,KAAK,CAEhG;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,cAAc,CAMzG;AAED,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,qBAAqB,GAC1B,IAAI,CAsBN","sourcesContent":["import type { CommitResult, Entry, EntryWrite, NewEntry, UsageRow, UsageWrite, Write } from \"./types.ts\";\n\nexport type CommittedEntryWrite = Entry & { kind: \"entry\" };\nexport type CommittedUsageWrite = UsageRow & { kind: \"usage\" };\nexport interface CommittedValueSetWrite {\n\tkind: \"value\";\n\top: \"set\";\n\tseq: number;\n\tnamespace: string;\n\tkey: string;\n\tvalue: unknown;\n}\nexport interface CommittedValueDeleteWrite {\n\tkind: \"value\";\n\top: \"delete\";\n\tseq: number;\n\tnamespace: string;\n\tkey: string;\n}\nexport interface CommittedListAppendWrite {\n\tkind: \"list\";\n\top: \"append\";\n\tseq: number;\n\tnamespace: string;\n\tkey: string;\n\tvalue: unknown;\n}\nexport interface CommittedListDeleteWrite {\n\tkind: \"list\";\n\top: \"delete\";\n\tseq: number;\n\tnamespace: string;\n\tkey: string;\n}\nexport type CommittedWrite =\n\t| CommittedEntryWrite\n\t| CommittedUsageWrite\n\t| CommittedValueSetWrite\n\t| CommittedValueDeleteWrite\n\t| CommittedListAppendWrite\n\t| CommittedListDeleteWrite;\n\nexport interface PreparedCommit {\n\twrites: CommittedWrite[];\n\tresult: Omit<CommitResult, \"stats\">;\n}\n\nexport interface CommitValidationState {\n\thasEntryOrUsageId(id: string): boolean;\n\thasEntryId(id: string): boolean;\n}\n\nexport function insertEntry(entry: NewEntry): EntryWrite {\n\treturn { kind: \"entry\", entry };\n}\n\nexport function insertUsage(row: Omit<UsageRow, \"seq\">): UsageWrite {\n\treturn { kind: \"usage\", row };\n}\n\nexport function commitWrite(write: Write, seq: number, timestamp: number): CommittedWrite {\n\tswitch (write.kind) {\n\t\tcase \"entry\":\n\t\t\treturn { kind: \"entry\", ...write.entry, seq, timestamp };\n\t\tcase \"usage\":\n\t\t\treturn { kind: \"usage\", ...write.row, seq };\n\t\tcase \"value\":\n\t\t\treturn write.op === \"set\"\n\t\t\t\t? { kind: \"value\", op: \"set\", seq, namespace: write.namespace, key: write.key, value: write.value }\n\t\t\t\t: { kind: \"value\", op: \"delete\", seq, namespace: write.namespace, key: write.key };\n\t\tcase \"list\":\n\t\t\treturn write.op === \"append\"\n\t\t\t\t? { kind: \"list\", op: \"append\", seq, namespace: write.namespace, key: write.key, value: write.value }\n\t\t\t\t: { kind: \"list\", op: \"delete\", seq, namespace: write.namespace, key: write.key };\n\t}\n}\n\nexport function materializeCommittedEntry(entry: NewEntry, seq: number, timestamp: number): Entry {\n\treturn { ...entry, seq, timestamp };\n}\n\nexport function prepareStorageCommit(writes: Write[], firstSeq: number, timestamp: number): PreparedCommit {\n\tconst committedWrites = writes.map((write, index) => commitWrite(write, firstSeq + index, timestamp));\n\treturn {\n\t\twrites: committedWrites,\n\t\tresult: { firstSeq, seqs: committedWrites.map((write) => write.seq), timestamp },\n\t};\n}\n\nexport function validateCommittedWrites(\n\twrites: readonly CommittedWrite[],\n\tfirstSeq: number,\n\tstate: CommitValidationState,\n): void {\n\tlet previousSeq = firstSeq - 1;\n\tconst transactionIds = new Set<string>();\n\tconst transactionEntryIds = new Set<string>();\n\tfor (const write of writes) {\n\t\tif (write.seq <= previousSeq) throw new Error(`Non-monotonic storage sequence: ${write.seq}`);\n\t\tpreviousSeq = write.seq;\n\t\tif (write.kind !== \"entry\" && write.kind !== \"usage\") continue;\n\t\tif (state.hasEntryOrUsageId(write.id) || transactionIds.has(write.id)) {\n\t\t\tthrow new Error(`Duplicate entry or usage id: ${write.id}`);\n\t\t}\n\t\tif (\n\t\t\twrite.kind === \"entry\" &&\n\t\t\twrite.parentId !== null &&\n\t\t\t!state.hasEntryId(write.parentId) &&\n\t\t\t!transactionEntryIds.has(write.parentId)\n\t\t) {\n\t\t\tthrow new Error(`Missing parent entry: ${write.parentId}`);\n\t\t}\n\t\ttransactionIds.add(write.id);\n\t\tif (write.kind === \"entry\") transactionEntryIds.add(write.id);\n\t}\n}\n"]}
1
+ {"version":3,"file":"commit.d.ts","sourceRoot":"","sources":["../../../src/harness/session/commit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEzG,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAC5D,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAC/D,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,OAAO,CAAC;IACd,EAAE,EAAE,KAAK,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,OAAO,CAAC;CACf;AACD,MAAM,WAAW,yBAAyB;IACzC,IAAI,EAAE,OAAO,CAAC;IACd,EAAE,EAAE,QAAQ,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;I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,GAAG,EAAU,CAAC;IACzC,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC5B,IAAI,KAAK,CAAC,GAAG,IAAI,WAAW;YAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC;QAC9F,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC;QACxB,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO;YAAE,SAAS;QAC/D,IAAI,KAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;YACvE,MAAM,IAAI,KAAK,CAAC,gCAAgC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7D,CAAC;QACD,IACC,KAAK,CAAC,IAAI,KAAK,OAAO;YACtB,KAAK,CAAC,QAAQ,KAAK,IAAI;YACvB,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC;YACjC,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EACvC,CAAC;YACF,MAAM,IAAI,KAAK,CAAC,yBAAyB,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC5D,CAAC;QACD,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO;YAAE,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC/D,CAAC;AAAA,CACD","sourcesContent":["import type { CommitResult, Entry, EntryWrite, NewEntry, UsageRow, UsageWrite, Write } from \"./types.ts\";\n\nexport type CommittedEntryWrite = Entry & { kind: \"entry\" };\nexport type CommittedUsageWrite = UsageRow & { kind: \"usage\" };\nexport interface CommittedValueSetWrite {\n\tkind: \"value\";\n\top: \"set\";\n\tseq: number;\n\tnamespace: string;\n\tkey: string;\n\tvalue: unknown;\n}\nexport interface CommittedValueDeleteWrite {\n\tkind: \"value\";\n\top: \"delete\";\n\tseq: number;\n\tnamespace: string;\n\tkey: string;\n}\nexport interface CommittedListAppendWrite {\n\tkind: \"list\";\n\top: \"append\";\n\tseq: number;\n\tnamespace: string;\n\tkey: string;\n\tvalue: unknown;\n}\nexport interface CommittedListDeleteWrite {\n\tkind: \"list\";\n\top: \"delete\";\n\tseq: number;\n\tnamespace: string;\n\tkey: string;\n}\nexport type CommittedWrite =\n\t| CommittedEntryWrite\n\t| CommittedUsageWrite\n\t| CommittedValueSetWrite\n\t| CommittedValueDeleteWrite\n\t| CommittedListAppendWrite\n\t| CommittedListDeleteWrite;\n\nexport interface PreparedCommit {\n\twrites: CommittedWrite[];\n\tresult: Omit<CommitResult, \"stats\">;\n}\n\nexport interface CommitValidationState {\n\thasEntryOrUsageId(id: string): boolean;\n\thasEntryId(id: string): boolean;\n}\n\nexport function insertEntry(entry: NewEntry): EntryWrite {\n\treturn { kind: \"entry\", entry };\n}\n\nexport function insertUsage(row: Omit<UsageRow, \"seq\">): UsageWrite {\n\treturn { kind: \"usage\", row };\n}\n\nexport function commitWrite(write: Write, seq: number, timestamp: number): CommittedWrite {\n\tswitch (write.kind) {\n\t\tcase \"entry\":\n\t\t\treturn { kind: \"entry\", ...write.entry, seq, timestamp };\n\t\tcase \"usage\":\n\t\t\treturn { kind: \"usage\", ...write.row, seq };\n\t\tcase \"value\":\n\t\t\treturn write.op === \"set\"\n\t\t\t\t? { kind: \"value\", op: \"set\", seq, namespace: write.namespace, key: write.key, value: write.value }\n\t\t\t\t: { kind: \"value\", op: \"delete\", seq, namespace: write.namespace, key: write.key };\n\t\tcase \"list\":\n\t\t\treturn write.op === \"append\"\n\t\t\t\t? { kind: \"list\", op: \"append\", seq, namespace: write.namespace, key: write.key, value: write.value }\n\t\t\t\t: { kind: \"list\", op: \"delete\", seq, namespace: write.namespace, key: write.key };\n\t}\n}\n\nexport function materializeCommittedEntry(entry: NewEntry, seq: number, timestamp: number): Entry {\n\treturn { ...entry, seq, timestamp };\n}\n\nexport function prepareStorageCommit(writes: Write[], firstSeq: number, timestamp: number): PreparedCommit {\n\tconst committedWrites = writes.map((write, index) => commitWrite(write, firstSeq + index, timestamp));\n\treturn {\n\t\twrites: committedWrites,\n\t\tresult: { firstSeq, seqs: committedWrites.map((write) => write.seq), timestamp },\n\t};\n}\n\nexport function validateCommittedWrites(\n\twrites: readonly CommittedWrite[],\n\tfirstSeq: number,\n\tstate: CommitValidationState,\n): void {\n\tlet previousSeq = firstSeq - 1;\n\tconst transactionIds = new Set<string>();\n\tconst transactionEntryIds = new Set<string>();\n\tfor (const write of writes) {\n\t\tif (write.seq <= previousSeq) throw new Error(`Non-monotonic storage sequence: ${write.seq}`);\n\t\tpreviousSeq = write.seq;\n\t\tif (write.kind !== \"entry\" && write.kind !== \"usage\") continue;\n\t\tif (state.hasEntryOrUsageId(write.id) || transactionIds.has(write.id)) {\n\t\t\tthrow new Error(`Duplicate entry or usage id: ${write.id}`);\n\t\t}\n\t\tif (\n\t\t\twrite.kind === \"entry\" &&\n\t\t\twrite.parentId !== null &&\n\t\t\t!state.hasEntryId(write.parentId) &&\n\t\t\t!transactionEntryIds.has(write.parentId)\n\t\t) {\n\t\t\tthrow new Error(`Missing parent entry: ${write.parentId}`);\n\t\t}\n\t\ttransactionIds.add(write.id);\n\t\tif (write.kind === \"entry\") transactionEntryIds.add(write.id);\n\t}\n}\n"]}
1
+ {"version":3,"file":"commit.js","sourceRoot":"","sources":["../../../src/harness/session/commit.ts"],"names":[],"mappings":"AAoDA,MAAM,UAAU,WAAW,CAAC,KAAe;IAC1C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAA0B;IACrD,OAAO,EAAE,IAA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ACvE,MAAM,IAAI,KAAK,CAAC,gCAAgC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7D,CAAC;QACD,IACC,KAAK,CAAC,IAAI,KAAK,OAAO;YACtB,KAAK,CAAC,QAAQ,KAAK,IAAI;YACvB,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC;YACjC,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EACvC,CAAC;YACF,MAAM,IAAI,KAAK,CAAC,yBAAyB,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC5D,CAAC;QACD,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO;YAAE,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC/D,CAAC;AACF,CAAC","sourcesContent":["import type { CommitResult, Entry, EntryWrite, NewEntry, UsageRow, UsageWrite, Write } from \"./types.ts\";\n\nexport type CommittedEntryWrite = Entry & { kind: \"entry\" };\nexport type CommittedUsageWrite = UsageRow & { kind: \"usage\" };\nexport interface CommittedValueSetWrite {\n\tkind: \"value\";\n\top: \"set\";\n\tseq: number;\n\tnamespace: string;\n\tkey: string;\n\tvalue: unknown;\n}\nexport interface CommittedValueDeleteWrite {\n\tkind: \"value\";\n\top: \"delete\";\n\tseq: number;\n\tnamespace: string;\n\tkey: string;\n}\nexport interface CommittedListAppendWrite {\n\tkind: \"list\";\n\top: \"append\";\n\tseq: number;\n\tnamespace: string;\n\tkey: string;\n\tvalue: unknown;\n}\nexport interface CommittedListDeleteWrite {\n\tkind: \"list\";\n\top: \"delete\";\n\tseq: number;\n\tnamespace: string;\n\tkey: string;\n}\nexport type CommittedWrite =\n\t| CommittedEntryWrite\n\t| CommittedUsageWrite\n\t| CommittedValueSetWrite\n\t| CommittedValueDeleteWrite\n\t| CommittedListAppendWrite\n\t| CommittedListDeleteWrite;\n\nexport interface PreparedCommit {\n\twrites: CommittedWrite[];\n\tresult: Omit<CommitResult, \"stats\">;\n}\n\nexport interface CommitValidationState {\n\thasEntryOrUsageId(id: string): boolean;\n\thasEntryId(id: string): boolean;\n}\n\nexport function insertEntry(entry: NewEntry): EntryWrite {\n\treturn { kind: \"entry\", entry };\n}\n\nexport function insertUsage(row: Omit<UsageRow, \"seq\">): UsageWrite {\n\treturn { kind: \"usage\", row };\n}\n\nexport function commitWrite(write: Write, seq: number, timestamp: number): CommittedWrite {\n\tswitch (write.kind) {\n\t\tcase \"entry\":\n\t\t\treturn { kind: \"entry\", ...write.entry, seq, timestamp };\n\t\tcase \"usage\":\n\t\t\treturn { kind: \"usage\", ...write.row, seq };\n\t\tcase \"value\":\n\t\t\treturn write.op === \"set\"\n\t\t\t\t? { kind: \"value\", op: \"set\", seq, namespace: write.namespace, key: write.key, value: write.value }\n\t\t\t\t: { kind: \"value\", op: \"delete\", seq, namespace: write.namespace, key: write.key };\n\t\tcase \"list\":\n\t\t\treturn write.op === \"append\"\n\t\t\t\t? { kind: \"list\", op: \"append\", seq, namespace: write.namespace, key: write.key, value: write.value }\n\t\t\t\t: { kind: \"list\", op: \"delete\", seq, namespace: write.namespace, key: write.key };\n\t}\n}\n\nexport function materializeCommittedEntry(entry: NewEntry, seq: number, timestamp: number): Entry {\n\treturn { ...entry, seq, timestamp };\n}\n\nexport function prepareStorageCommit(writes: Write[], firstSeq: number, timestamp: number): PreparedCommit {\n\tconst committedWrites = writes.map((write, index) => commitWrite(write, firstSeq + index, timestamp));\n\treturn {\n\t\twrites: committedWrites,\n\t\tresult: { firstSeq, seqs: committedWrites.map((write) => write.seq), timestamp },\n\t};\n}\n\nexport function validateCommittedWrites(\n\twrites: readonly CommittedWrite[],\n\tfirstSeq: number,\n\tstate: CommitValidationState,\n): void {\n\tlet previousSeq = firstSeq - 1;\n\tconst transactionIds = new Set<string>();\n\tconst transactionEntryIds = new Set<string>();\n\tfor (const write of writes) {\n\t\tif (write.seq <= previousSeq) throw new Error(`Non-monotonic storage sequence: ${write.seq}`);\n\t\tpreviousSeq = write.seq;\n\t\tif (write.kind !== \"entry\" && write.kind !== \"usage\") continue;\n\t\tif (state.hasEntryOrUsageId(write.id) || transactionIds.has(write.id)) {\n\t\t\tthrow new Error(`Duplicate entry or usage id: ${write.id}`);\n\t\t}\n\t\tif (\n\t\t\twrite.kind === \"entry\" &&\n\t\t\twrite.parentId !== null &&\n\t\t\t!state.hasEntryId(write.parentId) &&\n\t\t\t!transactionEntryIds.has(write.parentId)\n\t\t) {\n\t\t\tthrow new Error(`Missing parent entry: ${write.parentId}`);\n\t\t}\n\t\ttransactionIds.add(write.id);\n\t\tif (write.kind === \"entry\") transactionEntryIds.add(write.id);\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/harness/session/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,EAAmB,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEzE,MAAM,WAAW,0BAA0B;IAC1C,eAAe,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;CAC3D;AAED,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,SAAS,KAAK,EAAE,GAAG,KAAK,EAAE,CAY1E;AASD,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,KAAK,GAAG,YAAY,EAAE,CAc1E;AAED,wBAAsB,mBAAmB,CACxC,WAAW,EAAE,SAAS,KAAK,EAAE,EAC7B,OAAO,EAAE,0BAA0B,GAAG,SAAS,EAC/C,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,YAAY,EAAE,CAAC,CAazB","sourcesContent":["import type { AgentMessage } from \"../../types.ts\";\nimport type { Context } from \"../context.ts\";\nimport { createBranchSummaryMessage, createCompactionSummaryMessage } from \"../messages.ts\";\nimport type { CompactionEntry, Entry, EntryProjector } from \"./types.ts\";\n\nexport interface SessionContextBuildOptions {\n\tentryProjectors?: Readonly<Record<string, EntryProjector>>;\n}\n\nexport function buildContextEntries(pathEntries: readonly Entry[]): Entry[] {\n\tlet compaction: CompactionEntry | undefined;\n\tlet compactionIndex = -1;\n\tfor (let index = pathEntries.length - 1; index >= 0; index--) {\n\t\tconst entry = pathEntries[index];\n\t\tif (entry?.type === \"compaction\") {\n\t\t\tcompaction = entry;\n\t\t\tcompactionIndex = index;\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn compaction === undefined ? [...pathEntries] : [compaction, ...pathEntries.slice(compactionIndex + 1)];\n}\n\nfunction isContextMessage(message: AgentMessage): boolean {\n\treturn (\n\t\tmessage.role !== \"assistant\" ||\n\t\t(message.stopReason !== \"error\" && message.stopReason !== \"aborted\" && message.stopReason !== \"deferred\")\n\t);\n}\n\nexport function sessionEntryToContextMessages(entry: Entry): AgentMessage[] {\n\tswitch (entry.type) {\n\t\tcase \"message\":\n\t\t\treturn isContextMessage(entry.message) ? [entry.message] : [];\n\t\tcase \"compaction\":\n\t\t\treturn [\n\t\t\t\tcreateCompactionSummaryMessage(entry.summary, entry.tokensBefore, entry.timestamp),\n\t\t\t\t...entry.retainedTail.filter(isContextMessage),\n\t\t\t];\n\t\tcase \"branch_summary\":\n\t\t\treturn entry.summary ? [createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp)] : [];\n\t\tcase \"custom\":\n\t\t\treturn [];\n\t}\n}\n\nexport async function buildSessionContext(\n\tpathEntries: readonly Entry[],\n\toptions: SessionContextBuildOptions | undefined,\n\tcontext: Context,\n): Promise<AgentMessage[]> {\n\toptions ??= {};\n\tconst entries = buildContextEntries(pathEntries);\n\tconst messages: AgentMessage[] = [];\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"custom\") {\n\t\t\tmessages.push(...sessionEntryToContextMessages(entry));\n\t\t\tcontinue;\n\t\t}\n\t\tconst projector = options.entryProjectors?.[entry.customType];\n\t\tif (projector !== undefined) messages.push(...((await projector(entry, context)) ?? []));\n\t}\n\treturn messages;\n}\n"]}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/harness/session/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,EAAmB,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEzE,MAAM,WAAW,0BAA0B;IAC1C,eAAe,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;CAC3D;AAED,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,SAAS,KAAK,EAAE,GAAG,KAAK,EAAE,CAY1E;AASD,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,KAAK,GAAG,YAAY,EAAE,CAc1E;AAED,wBAAsB,mBAAmB,CACxC,WAAW,EAAE,SAAS,KAAK,EAAE,EAC7B,OAAO,EAAE,0BAA0B,GAAG,SAAS,EAC/C,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,YAAY,EAAE,CAAC,CAazB"}
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/harness/session/context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;AAO5F,MAAM,UAAU,mBAAmB,CAAC,WAA6B,EAAW;IAC3E,IAAI,UAAuC,CAAC;IAC5C,IAAI,eAAe,GAAG,CAAC,CAAC,CAAC;IACzB,KAAK,IAAI,KAAK,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QA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AAC,EAAE,CAAC;QACxG,KAAK,QAAQ;YACZ,OAAO,EAAE,CAAC;IACZ,CAAC;AAAA,CACD;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACxC,WAA6B,EAC7B,OAA+C,EAC/C,OAAgB,EACU;IAC1B,OAAO,KAAK,EAAE,CAAC;IACf,MAAM,OAAO,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;IACjD,MAAM,QAAQ,GAAmB,EAAE,CAAC;IACpC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,QAAQ,CAAC,IAAI,CAAC,GAAG,6BAA6B,CAAC,KAAK,CAAC,CAAC,CAAC;YACvD,SAAS;QACV,CAAC;QACD,MAAM,SAAS,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC9D,IAAI,SAAS,KAAK,SAAS;YAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC1F,CAAC;IACD,OAAO,QAAQ,CAAC;AAAA,CAChB","sourcesContent":["import type { AgentMessage } from \"../../types.ts\";\nimport type { Context } from \"../context.ts\";\nimport { createBranchSummaryMessage, createCompactionSummaryMessage } from \"../messages.ts\";\nimport type { CompactionEntry, Entry, EntryProjector } from \"./types.ts\";\n\nexport interface SessionContextBuildOptions {\n\tentryProjectors?: Readonly<Record<string, EntryProjector>>;\n}\n\nexport function buildContextEntries(pathEntries: readonly Entry[]): Entry[] {\n\tlet compaction: CompactionEntry | undefined;\n\tlet compactionIndex = -1;\n\tfor (let index = pathEntries.length - 1; index >= 0; index--) {\n\t\tconst entry = pathEntries[index];\n\t\tif (entry?.type === \"compaction\") {\n\t\t\tcompaction = entry;\n\t\t\tcompactionIndex = index;\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn compaction === undefined ? [...pathEntries] : [compaction, ...pathEntries.slice(compactionIndex + 1)];\n}\n\nfunction isContextMessage(message: AgentMessage): boolean {\n\treturn (\n\t\tmessage.role !== \"assistant\" ||\n\t\t(message.stopReason !== \"error\" && message.stopReason !== \"aborted\" && message.stopReason !== \"deferred\")\n\t);\n}\n\nexport function sessionEntryToContextMessages(entry: Entry): AgentMessage[] {\n\tswitch (entry.type) {\n\t\tcase \"message\":\n\t\t\treturn isContextMessage(entry.message) ? [entry.message] : [];\n\t\tcase \"compaction\":\n\t\t\treturn [\n\t\t\t\tcreateCompactionSummaryMessage(entry.summary, entry.tokensBefore, entry.timestamp),\n\t\t\t\t...entry.retainedTail.filter(isContextMessage),\n\t\t\t];\n\t\tcase \"branch_summary\":\n\t\t\treturn entry.summary ? [createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp)] : [];\n\t\tcase \"custom\":\n\t\t\treturn [];\n\t}\n}\n\nexport async function buildSessionContext(\n\tpathEntries: readonly Entry[],\n\toptions: SessionContextBuildOptions | undefined,\n\tcontext: Context,\n): Promise<AgentMessage[]> {\n\toptions ??= {};\n\tconst entries = buildContextEntries(pathEntries);\n\tconst messages: AgentMessage[] = [];\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"custom\") {\n\t\t\tmessages.push(...sessionEntryToContextMessages(entry));\n\t\t\tcontinue;\n\t\t}\n\t\tconst projector = options.entryProjectors?.[entry.customType];\n\t\tif (projector !== undefined) messages.push(...((await projector(entry, context)) ?? []));\n\t}\n\treturn messages;\n}\n"]}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/harness/session/context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,8BAA8B,EAAE,MAAM,gBAAgB,CAAC;AAO5F,MAAM,UAAU,mBAAmB,CAAC,WAA6B;IAChE,IAAI,UAAuC,CAAC;IAC5C,IAAI,eAAe,GAAG,CAAC,CAAC,CAAC;IACzB,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CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACxG,KAAK,QAAQ;YACZ,OAAO,EAAE,CAAC;IACZ,CAAC;AACF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACxC,WAA6B,EAC7B,OAA+C,EAC/C,OAAgB;IAEhB,OAAO,KAAK,EAAE,CAAC;IACf,MAAM,OAAO,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;IACjD,MAAM,QAAQ,GAAmB,EAAE,CAAC;IACpC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC7B,QAAQ,CAAC,IAAI,CAAC,GAAG,6BAA6B,CAAC,KAAK,CAAC,CAAC,CAAC;YACvD,SAAS;QACV,CAAC;QACD,MAAM,SAAS,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC9D,IAAI,SAAS,KAAK,SAAS;YAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC1F,CAAC;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC","sourcesContent":["import type { AgentMessage } from \"../../types.ts\";\nimport type { Context } from \"../context.ts\";\nimport { createBranchSummaryMessage, createCompactionSummaryMessage } from \"../messages.ts\";\nimport type { CompactionEntry, Entry, EntryProjector } from \"./types.ts\";\n\nexport interface SessionContextBuildOptions {\n\tentryProjectors?: Readonly<Record<string, EntryProjector>>;\n}\n\nexport function buildContextEntries(pathEntries: readonly Entry[]): Entry[] {\n\tlet compaction: CompactionEntry | undefined;\n\tlet compactionIndex = -1;\n\tfor (let index = pathEntries.length - 1; index >= 0; index--) {\n\t\tconst entry = pathEntries[index];\n\t\tif (entry?.type === \"compaction\") {\n\t\t\tcompaction = entry;\n\t\t\tcompactionIndex = index;\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn compaction === undefined ? [...pathEntries] : [compaction, ...pathEntries.slice(compactionIndex + 1)];\n}\n\nfunction isContextMessage(message: AgentMessage): boolean {\n\treturn (\n\t\tmessage.role !== \"assistant\" ||\n\t\t(message.stopReason !== \"error\" && message.stopReason !== \"aborted\" && message.stopReason !== \"deferred\")\n\t);\n}\n\nexport function sessionEntryToContextMessages(entry: Entry): AgentMessage[] {\n\tswitch (entry.type) {\n\t\tcase \"message\":\n\t\t\treturn isContextMessage(entry.message) ? [entry.message] : [];\n\t\tcase \"compaction\":\n\t\t\treturn [\n\t\t\t\tcreateCompactionSummaryMessage(entry.summary, entry.tokensBefore, entry.timestamp),\n\t\t\t\t...entry.retainedTail.filter(isContextMessage),\n\t\t\t];\n\t\tcase \"branch_summary\":\n\t\t\treturn entry.summary ? [createBranchSummaryMessage(entry.summary, entry.fromId, entry.timestamp)] : [];\n\t\tcase \"custom\":\n\t\t\treturn [];\n\t}\n}\n\nexport async function buildSessionContext(\n\tpathEntries: readonly Entry[],\n\toptions: SessionContextBuildOptions | undefined,\n\tcontext: Context,\n): Promise<AgentMessage[]> {\n\toptions ??= {};\n\tconst entries = buildContextEntries(pathEntries);\n\tconst messages: AgentMessage[] = [];\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"custom\") {\n\t\t\tmessages.push(...sessionEntryToContextMessages(entry));\n\t\t\tcontinue;\n\t\t}\n\t\tconst projector = options.entryProjectors?.[entry.customType];\n\t\tif (projector !== undefined) messages.push(...((await projector(entry, context)) ?? []));\n\t}\n\treturn messages;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"fork-policy.d.ts","sourceRoot":"","sources":["../../../src/harness/session/fork-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACpF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,MAAM,oBAAoB,GAC7B;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAClE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAErB,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,OAAO,CAAC,WAAW,EAAE;IAAE,KAAK,EAAE,QAAQ,CAAA;CAAE,CAAC,EAClD,MAAM,EAAE;IACP,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC/B,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC1D,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACvC,GACC,OAAO,CAAC,oBAAoB,EAAE;IAAE,KAAK,EAAE,QAAQ,CAAA;CAAE,CAAC,CAsBpD;AAED,uFAAuF;AACvF,wBAAgB,4BAA4B,CAC3C,KAAK,EAAE,sBAAsB,GAAG,wBAAwB,EACxD,IAAI,EAAE,oBAAoB,EAC1B,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,GACzC,sBAAsB,GAAG,wBAAwB,GAAG,SAAS,CAuB/D","sourcesContent":["import type { CommittedListAppendWrite, CommittedValueSetWrite } from \"./commit.ts\";\nimport type { ForkOptions } from \"./types.ts\";\n\nexport type ForkCurrentStatePlan =\n\t| { scope: \"branch\"; branch: string; destinationTip: string | null }\n\t| { scope: \"tree\" };\n\nexport function selectBranchFork(\n\toptions: Extract<ForkOptions, { scope: \"branch\" }>,\n\tsource: {\n\t\ttip: string | null | undefined;\n\t\tgetParent: (entryId: string) => string | null | undefined;\n\t\tselectEntry: (entryId: string) => void;\n\t},\n): Extract<ForkCurrentStatePlan, { scope: \"branch\" }> {\n\tif (source.tip === undefined) throw new Error(`Unknown source branch: ${options.branch}`);\n\tconst requested = options.entryId ?? source.tip;\n\tlet found = requested === null;\n\tlet destinationTip: string | null = null;\n\tlet entryId = source.tip;\n\twhile (entryId !== null) {\n\t\tconst parentId = source.getParent(entryId);\n\t\tif (parentId === undefined) throw new Error(`Corrupt source branch: missing parent ${entryId}`);\n\t\tif (entryId === requested) {\n\t\t\tfound = true;\n\t\t\tdestinationTip = options.position === \"before\" ? parentId : entryId;\n\t\t\tif (options.position !== \"before\") source.selectEntry(entryId);\n\t\t} else if (found) {\n\t\t\tsource.selectEntry(entryId);\n\t\t}\n\t\tentryId = parentId;\n\t}\n\tif (!found) {\n\t\tthrow new Error(`Fork entry ${requested} is not on source branch ${JSON.stringify(options.branch)}`);\n\t}\n\treturn { scope: \"branch\", branch: options.branch, destinationTip };\n}\n\n/** Project one current scalar row or surviving list element into destination state. */\nexport function projectForkCurrentStateWrite(\n\twrite: CommittedValueSetWrite | CommittedListAppendWrite,\n\tplan: ForkCurrentStatePlan,\n\tisEntryCopied: (entryId: string) => boolean,\n): CommittedValueSetWrite | CommittedListAppendWrite | undefined {\n\tswitch (write.namespace) {\n\t\tcase \"pi.session.name\":\n\t\t\treturn write;\n\t\tcase \"pi.entry.label\":\n\t\t\treturn isEntryCopied(write.key) ? write : undefined;\n\t\tcase \"pi.branch.tip\":\n\t\t\tif (plan.scope === \"tree\") return write;\n\t\t\treturn write.key === plan.branch ? { ...write, value: plan.destinationTip } : undefined;\n\t\tcase \"pi.lane.config\":\n\t\t\treturn plan.scope === \"tree\" || write.key === plan.branch ? write : undefined;\n\t\tcase \"pi.lane.state\":\n\t\t\treturn plan.scope === \"tree\" || write.key === plan.branch\n\t\t\t\t? { ...write, value: { currentOperationId: null, lastOperationId: null, inbox: [] } }\n\t\t\t\t: undefined;\n\t\tcase \"pi.result\":\n\t\t\treturn undefined;\n\t}\n\tif (write.namespace.startsWith(\"pi.op.\") || write.namespace.startsWith(\"pi.pending.\")) return undefined;\n\tif (write.namespace === \"pi\" || write.namespace.startsWith(\"pi.\")) {\n\t\tthrow new Error(`Unknown reserved fork namespace: ${write.namespace}`);\n\t}\n\treturn plan.scope === \"tree\" ? write : undefined;\n}\n"]}
1
+ {"version":3,"file":"fork-policy.d.ts","sourceRoot":"","sources":["../../../src/harness/session/fork-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACpF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,MAAM,oBAAoB,GAC7B;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAClE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAErB,wBAAgB,gBAAgB,CAC/B,OAAO,EAAE,OAAO,CAAC,WAAW,EAAE;IAAE,KAAK,EAAE,QAAQ,CAAA;CAAE,CAAC,EAClD,MAAM,EAAE;IACP,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC/B,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC1D,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACvC,GACC,OAAO,CAAC,oBAAoB,EAAE;IAAE,KAAK,EAAE,QAAQ,CAAA;CAAE,CAAC,CAsBpD;AAED,uFAAuF;AACvF,wBAAgB,4BAA4B,CAC3C,KAAK,EAAE,sBAAsB,GAAG,wBAAwB,EACxD,IAAI,EAAE,oBAAoB,EAC1B,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,GACzC,sBAAsB,GAAG,wBAAwB,GAAG,SAAS,CAuB/D"}
@@ -1 +1 @@
1
- {"version":3,"file":"fork-policy.js","sourceRoot":"","sources":["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Aa,CAAC;QAAE,OAAO,SAAS,CAAC;IACxG,IAAI,KAAK,CAAC,SAAS,KAAK,IAAI,IAAI,KAAK,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACnE,MAAM,IAAI,KAAK,CAAC,oCAAoC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAAA,CACjD","sourcesContent":["import type { CommittedListAppendWrite, CommittedValueSetWrite } from \"./commit.ts\";\nimport type { ForkOptions } from \"./types.ts\";\n\nexport type ForkCurrentStatePlan =\n\t| { scope: \"branch\"; branch: string; destinationTip: string | null }\n\t| { scope: \"tree\" };\n\nexport function selectBranchFork(\n\toptions: Extract<ForkOptions, { scope: \"branch\" }>,\n\tsource: {\n\t\ttip: string | null | undefined;\n\t\tgetParent: (entryId: string) => string | null | undefined;\n\t\tselectEntry: (entryId: string) => void;\n\t},\n): Extract<ForkCurrentStatePlan, { scope: \"branch\" }> {\n\tif (source.tip === undefined) throw new Error(`Unknown source branch: ${options.branch}`);\n\tconst requested = options.entryId ?? source.tip;\n\tlet found = requested === null;\n\tlet destinationTip: string | null = null;\n\tlet entryId = source.tip;\n\twhile (entryId !== null) {\n\t\tconst parentId = source.getParent(entryId);\n\t\tif (parentId === undefined) throw new Error(`Corrupt source branch: missing parent ${entryId}`);\n\t\tif (entryId === requested) {\n\t\t\tfound = true;\n\t\t\tdestinationTip = options.position === \"before\" ? parentId : entryId;\n\t\t\tif (options.position !== \"before\") source.selectEntry(entryId);\n\t\t} else if (found) {\n\t\t\tsource.selectEntry(entryId);\n\t\t}\n\t\tentryId = parentId;\n\t}\n\tif (!found) {\n\t\tthrow new Error(`Fork entry ${requested} is not on source branch ${JSON.stringify(options.branch)}`);\n\t}\n\treturn { scope: \"branch\", branch: options.branch, destinationTip };\n}\n\n/** Project one current scalar row or surviving list element into destination state. */\nexport function projectForkCurrentStateWrite(\n\twrite: CommittedValueSetWrite | CommittedListAppendWrite,\n\tplan: ForkCurrentStatePlan,\n\tisEntryCopied: (entryId: string) => boolean,\n): CommittedValueSetWrite | CommittedListAppendWrite | undefined {\n\tswitch (write.namespace) {\n\t\tcase \"pi.session.name\":\n\t\t\treturn write;\n\t\tcase \"pi.entry.label\":\n\t\t\treturn isEntryCopied(write.key) ? write : undefined;\n\t\tcase \"pi.branch.tip\":\n\t\t\tif (plan.scope === \"tree\") return write;\n\t\t\treturn write.key === plan.branch ? { ...write, value: plan.destinationTip } : undefined;\n\t\tcase \"pi.lane.config\":\n\t\t\treturn plan.scope === \"tree\" || write.key === plan.branch ? write : undefined;\n\t\tcase \"pi.lane.state\":\n\t\t\treturn plan.scope === \"tree\" || write.key === plan.branch\n\t\t\t\t? { ...write, value: { currentOperationId: null, lastOperationId: null, inbox: [] } }\n\t\t\t\t: undefined;\n\t\tcase \"pi.result\":\n\t\t\treturn undefined;\n\t}\n\tif (write.namespace.startsWith(\"pi.op.\") || write.namespace.startsWith(\"pi.pending.\")) return undefined;\n\tif (write.namespace === \"pi\" || write.namespace.startsWith(\"pi.\")) {\n\t\tthrow new Error(`Unknown reserved fork namespace: ${write.namespace}`);\n\t}\n\treturn plan.scope === \"tree\" ? write : undefined;\n}\n"]}
1
+ {"version":3,"file":"fork-policy.js","sourceRoot":"","sources":["../../../src/harness/session/fork-policy.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,gBAAgB,CAC/B,OAAkD,EAClD,MAIC;IAED,IAAI,MAAM,CAAC,GAAG,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,0BAA0B,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1F,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC;IAChD,IAAI,KAAK,GAAG,SAAS,KAAK,IAAI,CAAC;IAC/B,IAAI,cAAc,GAAkB,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ittedValueSetWrite } from \"./commit.ts\";\nimport type { ForkOptions } from \"./types.ts\";\n\nexport type ForkCurrentStatePlan =\n\t| { scope: \"branch\"; branch: string; destinationTip: string | null }\n\t| { scope: \"tree\" };\n\nexport function selectBranchFork(\n\toptions: Extract<ForkOptions, { scope: \"branch\" }>,\n\tsource: {\n\t\ttip: string | null | undefined;\n\t\tgetParent: (entryId: string) => string | null | undefined;\n\t\tselectEntry: (entryId: string) => void;\n\t},\n): Extract<ForkCurrentStatePlan, { scope: \"branch\" }> {\n\tif (source.tip === undefined) throw new Error(`Unknown source branch: ${options.branch}`);\n\tconst requested = options.entryId ?? source.tip;\n\tlet found = requested === null;\n\tlet destinationTip: string | null = null;\n\tlet entryId = source.tip;\n\twhile (entryId !== null) {\n\t\tconst parentId = source.getParent(entryId);\n\t\tif (parentId === undefined) throw new Error(`Corrupt source branch: missing parent ${entryId}`);\n\t\tif (entryId === requested) {\n\t\t\tfound = true;\n\t\t\tdestinationTip = options.position === \"before\" ? parentId : entryId;\n\t\t\tif (options.position !== \"before\") source.selectEntry(entryId);\n\t\t} else if (found) {\n\t\t\tsource.selectEntry(entryId);\n\t\t}\n\t\tentryId = parentId;\n\t}\n\tif (!found) {\n\t\tthrow new Error(`Fork entry ${requested} is not on source branch ${JSON.stringify(options.branch)}`);\n\t}\n\treturn { scope: \"branch\", branch: options.branch, destinationTip };\n}\n\n/** Project one current scalar row or surviving list element into destination state. */\nexport function projectForkCurrentStateWrite(\n\twrite: CommittedValueSetWrite | CommittedListAppendWrite,\n\tplan: ForkCurrentStatePlan,\n\tisEntryCopied: (entryId: string) => boolean,\n): CommittedValueSetWrite | CommittedListAppendWrite | undefined {\n\tswitch (write.namespace) {\n\t\tcase \"pi.session.name\":\n\t\t\treturn write;\n\t\tcase \"pi.entry.label\":\n\t\t\treturn isEntryCopied(write.key) ? write : undefined;\n\t\tcase \"pi.branch.tip\":\n\t\t\tif (plan.scope === \"tree\") return write;\n\t\t\treturn write.key === plan.branch ? { ...write, value: plan.destinationTip } : undefined;\n\t\tcase \"pi.lane.config\":\n\t\t\treturn plan.scope === \"tree\" || write.key === plan.branch ? write : undefined;\n\t\tcase \"pi.lane.state\":\n\t\t\treturn plan.scope === \"tree\" || write.key === plan.branch\n\t\t\t\t? { ...write, value: { currentOperationId: null, lastOperationId: null, inbox: [] } }\n\t\t\t\t: undefined;\n\t\tcase \"pi.result\":\n\t\t\treturn undefined;\n\t}\n\tif (write.namespace.startsWith(\"pi.op.\") || write.namespace.startsWith(\"pi.pending.\")) return undefined;\n\tif (write.namespace === \"pi\" || write.namespace.startsWith(\"pi.\")) {\n\t\tthrow new Error(`Unknown reserved fork namespace: ${write.namespace}`);\n\t}\n\treturn plan.scope === \"tree\" ? write : undefined;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"fork.d.ts","sourceRoot":"","sources":["../../../src/harness/session/fork.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAoC,KAAK,WAAW,EAAqB,MAAM,aAAa,CAAC;AAEpG,MAAM,WAAW,kBAAkB;IAClC,OAAO,EAAE,KAAK,EAAE,CAAC;IACjB,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;IACrC,yFAAyF;IACzF,eAAe,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,uBAAuB;IACvC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC5B,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;IACrC,OAAO,EAAE,MAAM,CAAC;CAChB;AAYD,yEAAyE;AACzE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,WAAW,GAAG,uBAAuB,CAkC5G","sourcesContent":["import { type ForkCurrentStatePlan, projectForkCurrentStateWrite, selectBranchFork } from \"./fork-policy.ts\";\nimport type { Entry, ForkOptions } from \"./types.ts\";\nimport { branchTip, laneConfig, laneState, type StoredValue, type Value, value } from \"./values.ts\";\n\nexport interface ForkSourceSnapshot {\n\tentries: Entry[];\n\tscalarValues: StoredValue<unknown>[];\n\t/** False when a backend supplied only the requested branch rather than the full tree. */\n\tentriesComplete?: boolean;\n}\n\nexport interface ForkDestinationSnapshot {\n\tentries: Map<string, Entry>;\n\tscalarValues: StoredValue<unknown>[];\n\tnextSeq: number;\n}\n\nfunction storedValuesInNamespace<T>(values: readonly StoredValue<unknown>[], address: Value<T>): StoredValue<T>[] {\n\treturn values.filter((stored) => stored.address.namespace === address.namespace) as StoredValue<T>[];\n}\n\nfunction findStoredValue<T>(values: readonly StoredValue<unknown>[], address: Value<T>): StoredValue<T> | undefined {\n\treturn values.find(\n\t\t(stored) => stored.address.namespace === address.namespace && stored.address.key === address.key,\n\t) as StoredValue<T> | undefined;\n}\n\n/** Build the complete logical state for a forked destination session. */\nexport function createForkSnapshot(source: ForkSourceSnapshot, options: ForkOptions): ForkDestinationSnapshot {\n\tconst sourceEntries = new Map(source.entries.map((entry) => [entry.id, entry]));\n\tconst sourceTips = storedValuesInNamespace(source.scalarValues, branchTip(\"\"));\n\tvalidateForkSourceSnapshot(source, sourceEntries, sourceTips, options);\n\n\tconst { entryIds, plan } = selectForkContents(sourceEntries, sourceTips, options);\n\tconst entries = new Map<string, Entry>();\n\tfor (const id of entryIds) entries.set(id, sourceEntries.get(id)!);\n\n\tconst scalarValues: StoredValue<unknown>[] = [];\n\tlet nextSeq = Math.max(0, ...[...entries.values()].map((entry) => entry.seq)) + 1;\n\tfor (const stored of source.scalarValues) {\n\t\tconst projected = projectForkCurrentStateWrite(\n\t\t\t{\n\t\t\t\tkind: \"value\",\n\t\t\t\top: \"set\",\n\t\t\t\tseq: stored.seq,\n\t\t\t\tnamespace: stored.address.namespace,\n\t\t\t\tkey: stored.address.key,\n\t\t\t\tvalue: stored.value,\n\t\t\t},\n\t\t\tplan,\n\t\t\t(entryId) => entryIds.has(entryId),\n\t\t);\n\t\tif (projected !== undefined) {\n\t\t\tscalarValues.push({\n\t\t\t\taddress: value<unknown>(projected.namespace, projected.key),\n\t\t\t\tvalue: projected.value,\n\t\t\t\tseq: nextSeq++,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn { entries, scalarValues, nextSeq };\n}\n\nfunction selectForkContents(\n\tsourceEntries: Map<string, Entry>,\n\tsourceTips: StoredValue<string | null>[],\n\toptions: ForkOptions,\n): { entryIds: Set<string>; plan: ForkCurrentStatePlan } {\n\tconst entryIds = new Set<string>();\n\tif (options.scope === \"tree\") {\n\t\tfor (const id of sourceEntries.keys()) entryIds.add(id);\n\t\treturn { entryIds, plan: { scope: \"tree\" } };\n\t}\n\n\tconst sourceTip = sourceTips.find((stored) => stored.address.key === options.branch);\n\tconst plan = selectBranchFork(options, {\n\t\ttip: sourceTip?.value,\n\t\tgetParent: (entryId) => sourceEntries.get(entryId)?.parentId,\n\t\tselectEntry: (entryId) => entryIds.add(entryId),\n\t});\n\treturn { entryIds, plan };\n}\n\nfunction validateForkSourceSnapshot(\n\tsource: ForkSourceSnapshot,\n\tsourceEntries: Map<string, Entry>,\n\tsourceTips: StoredValue<string | null>[],\n\toptions: ForkOptions,\n): void {\n\tconst sourceTipKeys = new Set(sourceTips.map((stored) => stored.address.key));\n\n\tfor (const stored of source.scalarValues) {\n\t\tif (\n\t\t\t(stored.address.namespace === laneConfig(\"\").namespace ||\n\t\t\t\tstored.address.namespace === laneState(\"\").namespace) &&\n\t\t\t!sourceTipKeys.has(stored.address.key)\n\t\t) {\n\t\t\tthrow new Error(`Source session branch ${JSON.stringify(stored.address.key)} is missing branch.tip`);\n\t\t}\n\t}\n\tfor (const tip of sourceTips) {\n\t\tconst configuration = findStoredValue(source.scalarValues, laneConfig(tip.address.key));\n\t\tconst state = findStoredValue(source.scalarValues, laneState(tip.address.key));\n\t\tif ((configuration === undefined) !== (state === undefined)) {\n\t\t\tthrow new Error(`Source session branch ${JSON.stringify(tip.address.key)} has incomplete lane state`);\n\t\t}\n\t\tif (options.scope === \"branch\" && tip.address.key === options.branch && configuration === undefined) {\n\t\t\tthrow new Error(`Source branch ${JSON.stringify(options.branch)} is not a configured AgentLane`);\n\t\t}\n\t\tif (\n\t\t\t(source.entriesComplete !== false || options.scope === \"tree\") &&\n\t\t\ttip.value !== null &&\n\t\t\t!sourceEntries.has(tip.value)\n\t\t) {\n\t\t\tthrow new Error(`Source session branch ${JSON.stringify(tip.address.key)} has an unknown tip`);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"fork.d.ts","sourceRoot":"","sources":["../../../src/harness/session/fork.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAoC,KAAK,WAAW,EAAqB,MAAM,aAAa,CAAC;AAEpG,MAAM,WAAW,kBAAkB;IAClC,OAAO,EAAE,KAAK,EAAE,CAAC;IACjB,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;IACrC,yFAAyF;IACzF,eAAe,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,uBAAuB;IACvC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC5B,YAAY,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;IACrC,OAAO,EAAE,MAAM,CAAC;CAChB;AAYD,yEAAyE;AACzE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,EAAE,OAAO,EAAE,WAAW,GAAG,uBAAuB,CAkC5G"}