@earendil-works/pi-agent-core 0.87.1 → 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":"prompt-templates.js","sourceRoot":"","sources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I,GAAa,EAAE,EAAU;IACrG,OAAO,cAAc,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAAA,CAC9C","sourcesContent":["import { parse } from \"yaml\";\nimport type { Context } from \"./context.ts\";\nimport { type ExecutionEnv, type FileInfo, type PromptTemplate, type Result, toError } from \"./types.ts\";\n\nexport type PromptTemplateDiagnosticCode = \"file_info_failed\" | \"list_failed\" | \"read_failed\" | \"parse_failed\";\n\n/** Warning produced while loading prompt templates. */\nexport interface PromptTemplateDiagnostic {\n\t/** Diagnostic severity. Currently only warnings are emitted. */\n\ttype: \"warning\";\n\t/** Stable diagnostic code. */\n\tcode: PromptTemplateDiagnosticCode;\n\t/** Human-readable diagnostic message. */\n\tmessage: string;\n\t/** Path associated with the diagnostic. */\n\tpath: string;\n}\n\ninterface PromptTemplateFrontmatter {\n\tdescription?: string;\n\t\"argument-hint\"?: string;\n\t[key: string]: unknown;\n}\n\n/**\n * Load prompt templates from one or more paths.\n *\n * Directory inputs load direct `.md` children non-recursively. File inputs load explicit `.md` files. Missing paths and\n * non-markdown files are skipped. Read and parse failures are returned as diagnostics.\n */\nexport async function loadPromptTemplates(\n\tenv: ExecutionEnv,\n\tpaths: string | string[],\n\tcontext: Context,\n): Promise<{ promptTemplates: PromptTemplate[]; diagnostics: PromptTemplateDiagnostic[] }> {\n\tconst promptTemplates: PromptTemplate[] = [];\n\tconst diagnostics: PromptTemplateDiagnostic[] = [];\n\tfor (const path of Array.isArray(paths) ? paths : [paths]) {\n\t\tconst infoResult = await env.fileInfo(path, context);\n\t\tif (!infoResult.ok) {\n\t\t\tif (infoResult.error.code !== \"not_found\") {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\ttype: \"warning\",\n\t\t\t\t\tcode: \"file_info_failed\",\n\t\t\t\t\tmessage: infoResult.error.message,\n\t\t\t\t\tpath,\n\t\t\t\t});\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst info = infoResult.value;\n\t\tconst kind = await resolveKind(env, info, diagnostics, context);\n\t\tif (kind === \"directory\") {\n\t\t\tconst result = await loadTemplatesFromDir(env, info.path, context);\n\t\t\tpromptTemplates.push(...result.promptTemplates);\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t} else if (kind === \"file\" && info.name.endsWith(\".md\")) {\n\t\t\tconst result = await loadTemplateFromFile(env, info.path, info.name, context);\n\t\t\tif (result.promptTemplate) promptTemplates.push(result.promptTemplate);\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t}\n\t}\n\treturn { promptTemplates, diagnostics };\n}\n\n/**\n * Load prompt templates from source-tagged paths.\n *\n * Source values are preserved exactly and attached to every loaded prompt template and diagnostic. The agent package does\n * not interpret source values; applications define their own provenance shape.\n */\nexport async function loadSourcedPromptTemplates<TSource, TPromptTemplate extends PromptTemplate = PromptTemplate>(\n\tenv: ExecutionEnv,\n\tinputs: Array<{ path: string; source: TSource }>,\n\tmapPromptTemplate:\n\t\t| ((promptTemplate: PromptTemplate, source: TSource, context: Context) => TPromptTemplate)\n\t\t| undefined,\n\tcontext: Context,\n): Promise<{\n\tpromptTemplates: Array<{ promptTemplate: TPromptTemplate; source: TSource }>;\n\tdiagnostics: Array<PromptTemplateDiagnostic & { source: TSource }>;\n}> {\n\tconst promptTemplates: Array<{ promptTemplate: TPromptTemplate; source: TSource }> = [];\n\tconst diagnostics: Array<PromptTemplateDiagnostic & { source: TSource }> = [];\n\tfor (const input of inputs) {\n\t\tconst result = await loadPromptTemplates(env, input.path, context);\n\t\tfor (const promptTemplate of result.promptTemplates) {\n\t\t\tpromptTemplates.push({\n\t\t\t\tpromptTemplate: mapPromptTemplate\n\t\t\t\t\t? mapPromptTemplate(promptTemplate, input.source, context)\n\t\t\t\t\t: (promptTemplate as TPromptTemplate),\n\t\t\t\tsource: input.source,\n\t\t\t});\n\t\t}\n\t\tfor (const diagnostic of result.diagnostics) diagnostics.push({ ...diagnostic, source: input.source });\n\t}\n\treturn { promptTemplates, diagnostics };\n}\n\nasync function loadTemplatesFromDir(\n\tenv: ExecutionEnv,\n\tdir: string,\n\tcontext: Context,\n): Promise<{ promptTemplates: PromptTemplate[]; diagnostics: PromptTemplateDiagnostic[] }> {\n\tconst promptTemplates: PromptTemplate[] = [];\n\tconst diagnostics: PromptTemplateDiagnostic[] = [];\n\tconst entriesResult = await env.listDir(dir, context);\n\tif (!entriesResult.ok) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"warning\",\n\t\t\tcode: \"list_failed\",\n\t\t\tmessage: entriesResult.error.message,\n\t\t\tpath: dir,\n\t\t});\n\t\treturn { promptTemplates, diagnostics };\n\t}\n\tconst entries = entriesResult.value;\n\n\tfor (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {\n\t\tconst kind = await resolveKind(env, entry, diagnostics, context);\n\t\tif (kind !== \"file\" || !entry.name.endsWith(\".md\")) continue;\n\t\tconst result = await loadTemplateFromFile(env, entry.path, entry.name, context);\n\t\tif (result.promptTemplate) promptTemplates.push(result.promptTemplate);\n\t\tdiagnostics.push(...result.diagnostics);\n\t}\n\treturn { promptTemplates, diagnostics };\n}\n\nasync function loadTemplateFromFile(\n\tenv: ExecutionEnv,\n\tfilePath: string,\n\tfileName: string,\n\tcontext: Context,\n): Promise<{ promptTemplate: PromptTemplate | null; diagnostics: PromptTemplateDiagnostic[] }> {\n\tconst diagnostics: PromptTemplateDiagnostic[] = [];\n\tconst rawContent = await env.readTextFile(filePath, context);\n\tif (!rawContent.ok) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"warning\",\n\t\t\tcode: \"read_failed\",\n\t\t\tmessage: rawContent.error.message,\n\t\t\tpath: filePath,\n\t\t});\n\t\treturn { promptTemplate: null, diagnostics };\n\t}\n\n\tconst parsed = parseFrontmatter<PromptTemplateFrontmatter>(rawContent.value);\n\tif (!parsed.ok) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"warning\",\n\t\t\tcode: \"parse_failed\",\n\t\t\tmessage: parsed.error.message,\n\t\t\tpath: filePath,\n\t\t});\n\t\treturn { promptTemplate: null, diagnostics };\n\t}\n\n\tconst { frontmatter, body } = parsed.value;\n\tconst firstLine = body.split(\"\\n\").find((line) => line.trim());\n\tlet description = typeof frontmatter.description === \"string\" ? frontmatter.description : \"\";\n\tif (!description && firstLine) {\n\t\tdescription = firstLine.slice(0, 60);\n\t\tif (firstLine.length > 60) description += \"...\";\n\t}\n\treturn {\n\t\tpromptTemplate: {\n\t\t\tname: fileName.replace(/\\.md$/i, \"\"),\n\t\t\tdescription,\n\t\t\tcontent: body,\n\t\t},\n\t\tdiagnostics,\n\t};\n}\n\nasync function resolveKind(\n\tenv: ExecutionEnv,\n\tinfo: FileInfo,\n\tdiagnostics: PromptTemplateDiagnostic[],\n\tcontext: Context,\n): Promise<\"file\" | \"directory\" | undefined> {\n\tif (info.kind === \"file\" || info.kind === \"directory\") return info.kind;\n\tconst canonicalPath = await env.canonicalPath(info.path, context);\n\tif (!canonicalPath.ok) {\n\t\tif (canonicalPath.error.code !== \"not_found\") {\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tcode: \"file_info_failed\",\n\t\t\t\tmessage: canonicalPath.error.message,\n\t\t\t\tpath: info.path,\n\t\t\t});\n\t\t}\n\t\treturn undefined;\n\t}\n\tconst target = await env.fileInfo(canonicalPath.value, context);\n\tif (!target.ok) {\n\t\tif (target.error.code !== \"not_found\") {\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tcode: \"file_info_failed\",\n\t\t\t\tmessage: target.error.message,\n\t\t\t\tpath: info.path,\n\t\t\t});\n\t\t}\n\t\treturn undefined;\n\t}\n\treturn target.value.kind === \"file\" || target.value.kind === \"directory\" ? target.value.kind : undefined;\n}\n\nfunction parseFrontmatter<T extends Record<string, unknown>>(\n\tcontent: string,\n): Result<{ frontmatter: T; body: string }, Error> {\n\ttry {\n\t\tconst normalized = content.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n\t\tif (!normalized.startsWith(\"---\")) return { ok: true, value: { frontmatter: {} as T, body: normalized } };\n\t\tconst endIndex = normalized.indexOf(\"\\n---\", 3);\n\t\tif (endIndex === -1) return { ok: true, value: { frontmatter: {} as T, body: normalized } };\n\t\tconst yamlString = normalized.slice(4, endIndex);\n\t\tconst body = normalized.slice(endIndex + 4).trim();\n\t\treturn { ok: true, value: { frontmatter: (parse(yamlString) ?? {}) as T, body } };\n\t} catch (error) {\n\t\treturn { ok: false, error: toError(error) };\n\t}\n}\n\n/** Parse an argument string using simple shell-style single and double quotes. */\nexport function parseCommandArgs(argsString: string): string[] {\n\tconst args: string[] = [];\n\tlet current = \"\";\n\tlet inQuote: string | null = null;\n\n\tfor (let i = 0; i < argsString.length; i++) {\n\t\tconst char = argsString[i]!;\n\t\tif (inQuote) {\n\t\t\tif (char === inQuote) inQuote = null;\n\t\t\telse current += char;\n\t\t} else if (char === '\"' || char === \"'\") {\n\t\t\tinQuote = char;\n\t\t} else if (char === \" \" || char === \"\\t\") {\n\t\t\tif (current) {\n\t\t\t\targs.push(current);\n\t\t\t\tcurrent = \"\";\n\t\t\t}\n\t\t} else {\n\t\t\tcurrent += char;\n\t\t}\n\t}\n\tif (current) args.push(current);\n\treturn args;\n}\n\n/** Substitute prompt template placeholders (`$1`, `$@`, `$ARGUMENTS`, `${@:N}`, `${@:N:L}`) with command arguments. */\nexport function substituteArgs(content: string, args: string[]): string {\n\tlet result = content;\n\tresult = result.replace(/\\$(\\d+)/g, (_, num: string) => args[parseInt(num, 10) - 1] ?? \"\");\n\tresult = result.replace(/\\$\\{@:(\\d+)(?::(\\d+))?\\}/g, (_, startStr: string, lengthStr?: string) => {\n\t\tlet start = parseInt(startStr, 10) - 1;\n\t\tif (start < 0) start = 0;\n\t\tif (lengthStr) return args.slice(start, start + parseInt(lengthStr, 10)).join(\" \");\n\t\treturn args.slice(start).join(\" \");\n\t});\n\tconst allArgs = args.join(\" \");\n\tresult = result.replace(/\\$ARGUMENTS/g, allArgs);\n\tresult = result.replace(/\\$@/g, allArgs);\n\treturn result;\n}\n\n/** Format a prompt template invocation with positional arguments. */\nexport function formatPromptTemplateInvocation(template: PromptTemplate, args: string[] = []): string {\n\treturn substituteArgs(template.content, args);\n}\n"]}
1
+ {"version":3,"file":"prompt-templates.js","sourceRoot":"","sources":["../../src/harness/prompt-templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAsE,OAAO,EAAE,MAAM,YAAY,CAAC;AAsBzG;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACxC,GAAiB,EACjB,KAAwB,EACxB,OAAgB;IAEhB,MAAM,eAAe,GAAqB,EAAE,CAAC;IAC7C,MAAM,WAAW,GAA+B,EAAE,CAAC;IACnD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3D,MAAM,UAAU,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACrD,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC;YACpB,IAAI,UAAU,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;gBAC3C,WAAW,CAAC,IAAI,CAAC;oBAChB,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,kBAAkB;oBACxB,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,OAAO;oBACjC,IAAI;iBACJ,CAAC,CAAC;YACJ,CAAC;YACD,SAAS;QACV,CAAC;QACD,MAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC;QAC9B,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,GAAG,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;QAChE,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;YAC1B,MA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AAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC;AACf,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,8BAA8B,CAAC,QAAwB,EAAE,IAAI,GAAa,EAAE;IAC3F,OAAO,cAAc,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import { parse } from \"yaml\";\nimport type { Context } from \"./context.ts\";\nimport { type ExecutionEnv, type FileInfo, type PromptTemplate, type Result, toError } from \"./types.ts\";\n\nexport type PromptTemplateDiagnosticCode = \"file_info_failed\" | \"list_failed\" | \"read_failed\" | \"parse_failed\";\n\n/** Warning produced while loading prompt templates. */\nexport interface PromptTemplateDiagnostic {\n\t/** Diagnostic severity. Currently only warnings are emitted. */\n\ttype: \"warning\";\n\t/** Stable diagnostic code. */\n\tcode: PromptTemplateDiagnosticCode;\n\t/** Human-readable diagnostic message. */\n\tmessage: string;\n\t/** Path associated with the diagnostic. */\n\tpath: string;\n}\n\ninterface PromptTemplateFrontmatter {\n\tdescription?: string;\n\t\"argument-hint\"?: string;\n\t[key: string]: unknown;\n}\n\n/**\n * Load prompt templates from one or more paths.\n *\n * Directory inputs load direct `.md` children non-recursively. File inputs load explicit `.md` files. Missing paths and\n * non-markdown files are skipped. Read and parse failures are returned as diagnostics.\n */\nexport async function loadPromptTemplates(\n\tenv: ExecutionEnv,\n\tpaths: string | string[],\n\tcontext: Context,\n): Promise<{ promptTemplates: PromptTemplate[]; diagnostics: PromptTemplateDiagnostic[] }> {\n\tconst promptTemplates: PromptTemplate[] = [];\n\tconst diagnostics: PromptTemplateDiagnostic[] = [];\n\tfor (const path of Array.isArray(paths) ? paths : [paths]) {\n\t\tconst infoResult = await env.fileInfo(path, context);\n\t\tif (!infoResult.ok) {\n\t\t\tif (infoResult.error.code !== \"not_found\") {\n\t\t\t\tdiagnostics.push({\n\t\t\t\t\ttype: \"warning\",\n\t\t\t\t\tcode: \"file_info_failed\",\n\t\t\t\t\tmessage: infoResult.error.message,\n\t\t\t\t\tpath,\n\t\t\t\t});\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst info = infoResult.value;\n\t\tconst kind = await resolveKind(env, info, diagnostics, context);\n\t\tif (kind === \"directory\") {\n\t\t\tconst result = await loadTemplatesFromDir(env, info.path, context);\n\t\t\tpromptTemplates.push(...result.promptTemplates);\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t} else if (kind === \"file\" && info.name.endsWith(\".md\")) {\n\t\t\tconst result = await loadTemplateFromFile(env, info.path, info.name, context);\n\t\t\tif (result.promptTemplate) promptTemplates.push(result.promptTemplate);\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t}\n\t}\n\treturn { promptTemplates, diagnostics };\n}\n\n/**\n * Load prompt templates from source-tagged paths.\n *\n * Source values are preserved exactly and attached to every loaded prompt template and diagnostic. The agent package does\n * not interpret source values; applications define their own provenance shape.\n */\nexport async function loadSourcedPromptTemplates<TSource, TPromptTemplate extends PromptTemplate = PromptTemplate>(\n\tenv: ExecutionEnv,\n\tinputs: Array<{ path: string; source: TSource }>,\n\tmapPromptTemplate:\n\t\t| ((promptTemplate: PromptTemplate, source: TSource, context: Context) => TPromptTemplate)\n\t\t| undefined,\n\tcontext: Context,\n): Promise<{\n\tpromptTemplates: Array<{ promptTemplate: TPromptTemplate; source: TSource }>;\n\tdiagnostics: Array<PromptTemplateDiagnostic & { source: TSource }>;\n}> {\n\tconst promptTemplates: Array<{ promptTemplate: TPromptTemplate; source: TSource }> = [];\n\tconst diagnostics: Array<PromptTemplateDiagnostic & { source: TSource }> = [];\n\tfor (const input of inputs) {\n\t\tconst result = await loadPromptTemplates(env, input.path, context);\n\t\tfor (const promptTemplate of result.promptTemplates) {\n\t\t\tpromptTemplates.push({\n\t\t\t\tpromptTemplate: mapPromptTemplate\n\t\t\t\t\t? mapPromptTemplate(promptTemplate, input.source, context)\n\t\t\t\t\t: (promptTemplate as TPromptTemplate),\n\t\t\t\tsource: input.source,\n\t\t\t});\n\t\t}\n\t\tfor (const diagnostic of result.diagnostics) diagnostics.push({ ...diagnostic, source: input.source });\n\t}\n\treturn { promptTemplates, diagnostics };\n}\n\nasync function loadTemplatesFromDir(\n\tenv: ExecutionEnv,\n\tdir: string,\n\tcontext: Context,\n): Promise<{ promptTemplates: PromptTemplate[]; diagnostics: PromptTemplateDiagnostic[] }> {\n\tconst promptTemplates: PromptTemplate[] = [];\n\tconst diagnostics: PromptTemplateDiagnostic[] = [];\n\tconst entriesResult = await env.listDir(dir, context);\n\tif (!entriesResult.ok) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"warning\",\n\t\t\tcode: \"list_failed\",\n\t\t\tmessage: entriesResult.error.message,\n\t\t\tpath: dir,\n\t\t});\n\t\treturn { promptTemplates, diagnostics };\n\t}\n\tconst entries = entriesResult.value;\n\n\tfor (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {\n\t\tconst kind = await resolveKind(env, entry, diagnostics, context);\n\t\tif (kind !== \"file\" || !entry.name.endsWith(\".md\")) continue;\n\t\tconst result = await loadTemplateFromFile(env, entry.path, entry.name, context);\n\t\tif (result.promptTemplate) promptTemplates.push(result.promptTemplate);\n\t\tdiagnostics.push(...result.diagnostics);\n\t}\n\treturn { promptTemplates, diagnostics };\n}\n\nasync function loadTemplateFromFile(\n\tenv: ExecutionEnv,\n\tfilePath: string,\n\tfileName: string,\n\tcontext: Context,\n): Promise<{ promptTemplate: PromptTemplate | null; diagnostics: PromptTemplateDiagnostic[] }> {\n\tconst diagnostics: PromptTemplateDiagnostic[] = [];\n\tconst rawContent = await env.readTextFile(filePath, context);\n\tif (!rawContent.ok) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"warning\",\n\t\t\tcode: \"read_failed\",\n\t\t\tmessage: rawContent.error.message,\n\t\t\tpath: filePath,\n\t\t});\n\t\treturn { promptTemplate: null, diagnostics };\n\t}\n\n\tconst parsed = parseFrontmatter<PromptTemplateFrontmatter>(rawContent.value);\n\tif (!parsed.ok) {\n\t\tdiagnostics.push({\n\t\t\ttype: \"warning\",\n\t\t\tcode: \"parse_failed\",\n\t\t\tmessage: parsed.error.message,\n\t\t\tpath: filePath,\n\t\t});\n\t\treturn { promptTemplate: null, diagnostics };\n\t}\n\n\tconst { frontmatter, body } = parsed.value;\n\tconst firstLine = body.split(\"\\n\").find((line) => line.trim());\n\tlet description = typeof frontmatter.description === \"string\" ? frontmatter.description : \"\";\n\tif (!description && firstLine) {\n\t\tdescription = firstLine.slice(0, 60);\n\t\tif (firstLine.length > 60) description += \"...\";\n\t}\n\treturn {\n\t\tpromptTemplate: {\n\t\t\tname: fileName.replace(/\\.md$/i, \"\"),\n\t\t\tdescription,\n\t\t\tcontent: body,\n\t\t},\n\t\tdiagnostics,\n\t};\n}\n\nasync function resolveKind(\n\tenv: ExecutionEnv,\n\tinfo: FileInfo,\n\tdiagnostics: PromptTemplateDiagnostic[],\n\tcontext: Context,\n): Promise<\"file\" | \"directory\" | undefined> {\n\tif (info.kind === \"file\" || info.kind === \"directory\") return info.kind;\n\tconst canonicalPath = await env.canonicalPath(info.path, context);\n\tif (!canonicalPath.ok) {\n\t\tif (canonicalPath.error.code !== \"not_found\") {\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tcode: \"file_info_failed\",\n\t\t\t\tmessage: canonicalPath.error.message,\n\t\t\t\tpath: info.path,\n\t\t\t});\n\t\t}\n\t\treturn undefined;\n\t}\n\tconst target = await env.fileInfo(canonicalPath.value, context);\n\tif (!target.ok) {\n\t\tif (target.error.code !== \"not_found\") {\n\t\t\tdiagnostics.push({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tcode: \"file_info_failed\",\n\t\t\t\tmessage: target.error.message,\n\t\t\t\tpath: info.path,\n\t\t\t});\n\t\t}\n\t\treturn undefined;\n\t}\n\treturn target.value.kind === \"file\" || target.value.kind === \"directory\" ? target.value.kind : undefined;\n}\n\nfunction parseFrontmatter<T extends Record<string, unknown>>(\n\tcontent: string,\n): Result<{ frontmatter: T; body: string }, Error> {\n\ttry {\n\t\tconst normalized = content.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n\t\tif (!normalized.startsWith(\"---\")) return { ok: true, value: { frontmatter: {} as T, body: normalized } };\n\t\tconst endIndex = normalized.indexOf(\"\\n---\", 3);\n\t\tif (endIndex === -1) return { ok: true, value: { frontmatter: {} as T, body: normalized } };\n\t\tconst yamlString = normalized.slice(4, endIndex);\n\t\tconst body = normalized.slice(endIndex + 4).trim();\n\t\treturn { ok: true, value: { frontmatter: (parse(yamlString) ?? {}) as T, body } };\n\t} catch (error) {\n\t\treturn { ok: false, error: toError(error) };\n\t}\n}\n\n/** Parse an argument string using simple shell-style single and double quotes. */\nexport function parseCommandArgs(argsString: string): string[] {\n\tconst args: string[] = [];\n\tlet current = \"\";\n\tlet inQuote: string | null = null;\n\n\tfor (let i = 0; i < argsString.length; i++) {\n\t\tconst char = argsString[i]!;\n\t\tif (inQuote) {\n\t\t\tif (char === inQuote) inQuote = null;\n\t\t\telse current += char;\n\t\t} else if (char === '\"' || char === \"'\") {\n\t\t\tinQuote = char;\n\t\t} else if (char === \" \" || char === \"\\t\") {\n\t\t\tif (current) {\n\t\t\t\targs.push(current);\n\t\t\t\tcurrent = \"\";\n\t\t\t}\n\t\t} else {\n\t\t\tcurrent += char;\n\t\t}\n\t}\n\tif (current) args.push(current);\n\treturn args;\n}\n\n/** Substitute prompt template placeholders (`$1`, `$@`, `$ARGUMENTS`, `${@:N}`, `${@:N:L}`) with command arguments. */\nexport function substituteArgs(content: string, args: string[]): string {\n\tlet result = content;\n\tresult = result.replace(/\\$(\\d+)/g, (_, num: string) => args[parseInt(num, 10) - 1] ?? \"\");\n\tresult = result.replace(/\\$\\{@:(\\d+)(?::(\\d+))?\\}/g, (_, startStr: string, lengthStr?: string) => {\n\t\tlet start = parseInt(startStr, 10) - 1;\n\t\tif (start < 0) start = 0;\n\t\tif (lengthStr) return args.slice(start, start + parseInt(lengthStr, 10)).join(\" \");\n\t\treturn args.slice(start).join(\" \");\n\t});\n\tconst allArgs = args.join(\" \");\n\tresult = result.replace(/\\$ARGUMENTS/g, allArgs);\n\tresult = result.replace(/\\$@/g, allArgs);\n\treturn result;\n}\n\n/** Format a prompt template invocation with positional arguments. */\nexport function formatPromptTemplateInvocation(template: PromptTemplate, args: string[] = []): string {\n\treturn substituteArgs(template.content, args);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/harness/result.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhG,eAAO,MAAM,MAAM;OACf,MAAM;QAGL,MAAM;SAGL,MAAM,EAAE,MAAM;;;;UAGb,MAAM,EAAE,MAAM;;;;CAGpB,CAAC;AAEF,MAAM,WAAW,gBAAgB,CAAC,GAAG,SAAS,MAAM,CAAE,SAAQ,KAAK;IAClE,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC;IACnB,MAAM,IAAI;QAAE,IAAI,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnE;AAED,MAAM,WAAW,kBAAkB,CAAC,GAAG,SAAS,MAAM;IACrD,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,KAAK,EAAE,KAAK,GAAG,gBAAgB,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/F,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAAC,GAAG,CAAC,CAAC;CACnD;AAED,wBAAg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TError> = { ok: true; value: TValue } | { ok: false; error: TError };\n\nexport const Result = {\n\tok<TValue>(value: TValue): Result<TValue, never> {\n\t\treturn { ok: true, value };\n\t},\n\terr<TError>(error: TError): Result<never, TError> {\n\t\treturn { ok: false, error };\n\t},\n\tisOk<TValue, TError>(result: Result<TValue, TError>): result is { ok: true; value: TValue } {\n\t\treturn result.ok;\n\t},\n\tisErr<TValue, TError>(result: Result<TValue, TError>): result is { ok: false; error: TError } {\n\t\treturn !result.ok;\n\t},\n};\n\nexport interface TaggedErrorValue<Tag extends string> extends Error {\n\treadonly _tag: Tag;\n\ttoJSON(): { _tag: Tag; message: string } & Record<string, unknown>;\n}\n\nexport interface TaggedErrorFactory<Tag extends string> {\n\tnew <Props extends { message: string }>(props: Props): TaggedErrorValue<Tag> & Readonly<Props>;\n\tis(value: unknown): value is TaggedErrorValue<Tag>;\n}\n\nexport function TaggedError<Tag extends string>(tag: Tag): TaggedErrorFactory<Tag> {\n\tclass TaggedErrorClass extends Error {\n\t\treadonly _tag = tag;\n\n\t\tconstructor(props: { message: string } & Record<string, unknown>) {\n\t\t\tsuper(props.message);\n\t\t\tthis.name = tag;\n\t\t\tObject.assign(this, props);\n\t\t}\n\n\t\ttoJSON(): { _tag: Tag; message: string } & Record<string, unknown> {\n\t\t\tconst payload: Record<string, unknown> = {};\n\t\t\tfor (const key of Object.keys(this)) {\n\t\t\t\tif (key !== \"_tag\") payload[key] = (this as unknown as Record<string, unknown>)[key];\n\t\t\t}\n\t\t\treturn { _tag: tag, message: this.message, ...payload };\n\t\t}\n\n\t\tstatic is(value: unknown): value is TaggedErrorValue<Tag> {\n\t\t\treturn value instanceof TaggedErrorClass;\n\t\t}\n\t}\n\treturn TaggedErrorClass as unknown as TaggedErrorFactory<Tag>;\n}\n\nexport class LaneBusy extends TaggedError(\"LaneBusy\")<{\n\tlane: string;\n\toperationId: string;\n\toperationKind: \"run\" | \"compaction\" | \"navigation\";\n\tmessage: string;\n}> {}\nexport class OperationMismatch extends TaggedError(\"OperationMismatch\")<{\n\tlane: string;\n\texpectedOperationId: string;\n\tcurrentOperationId?: string;\n\tlastOperationId?: string;\n\tmessage: string;\n}> {}\nexport class NoActiveRun extends TaggedError(\"NoActiveRun\")<{ lane: string; message: string }> {}\nexport class NoActiveOperation extends TaggedError(\"NoActiveOperation\")<{ lane: string; message: string }> {}\nexport class NothingToResume extends TaggedError(\"NothingToResume\")<{ lane: string; message: string }> {}\nexport class NothingToCompact extends TaggedError(\"NothingToCompact\")<{ lane: string; message: string }> {}\nexport class InvalidMessage extends TaggedError(\"InvalidMessage\")<{\n\tlane: string;\n\treason: string;\n\tmessage: string;\n}> {}\nexport class InvalidNavigation extends TaggedError(\"InvalidNavigation\")<{\n\tlane: string;\n\treason: string;\n\tmessage: string;\n}> {}\nexport class UnknownSkill extends TaggedError(\"UnknownSkill\")<{ name: string; message: string }> {}\nexport class UnknownTemplate extends TaggedError(\"UnknownTemplate\")<{ name: string; message: string }> {}\nexport class UnknownTarget extends TaggedError(\"UnknownTarget\")<{ targetId: string; message: string }> {}\nexport class InvalidLane extends TaggedError(\"InvalidLane\")<{\n\tlane: string;\n\treason: string;\n\tmessage: string;\n}> {}\nexport class Closed extends TaggedError(\"Closed\")<{ message: string }> {}\n\nexport class HarnessFault extends Error {\n\treadonly cause: unknown;\n\n\tconstructor(message: string, cause: unknown) {\n\t\tsuper(message);\n\t\tthis.name = \"HarnessFault\";\n\t\tthis.cause = cause;\n\t}\n}\n\nexport class HarnessClosed extends Error {\n\tconstructor() {\n\t\tsuper(\"AgentHarness was closed while the operation was active\");\n\t\tthis.name = \"HarnessClosed\";\n\t}\n}\n\nexport type ErrorMatchers<TError extends TaggedErrorValue<string>, TValue> = {\n\t[Tag in TError[\"_tag\"]]: (error: Extract<TError, { _tag: Tag }>) => TValue;\n};\n\nexport function matchError<TError extends TaggedErrorValue<string>, TValue>(\n\terror: TError,\n\tmatchers: ErrorMatchers<TError, TValue>,\n): TValue {\n\tconst matcher = (matchers as unknown as Record<string, (value: TError) => TValue>)[error._tag];\n\treturn matcher(error);\n}\n"]}
1
+ {"version":3,"file":"result.d.ts","sourceRoot":"","sources":["../../src/harness/result.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhG,eAAO,MAAM,MAAM;IAClB,EAAE,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;IAGhD,GAAG,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC;IAGjD,IAAI,CAAC,MAAM,EAAE,MAAM,UAAU,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,IAAI;QAAE,EAAE,EAAE,IAAI,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;IAG3F,KAAK,CAAC,MAAM,EAAE,MAAM,UAAU,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,IAAI;QAAE,EAAE,EAAE,KAAK,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;CAG7F,CAAC;AAEF,MAAM,WAAW,gBAAgB,CAAC,GAAG,SAAS,MAAM,CAAE,SAAQ,KAAK;IAClE,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC;IACnB,MAAM,IAAI;QAAE,IAAI,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnE;AAED,MAAM,WAAW,kBAAkB,CAAC,GAAG,SAAS,MAAM;IACrD,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,KAAK,EAAE,KAAK,GAA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QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IAAA,CACnB;CACD;AAED,MAAM,OAAO,aAAc,SAAQ,KAAK;IACvC,cAAc;QACb,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAChE,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAAA,CAC5B;CACD;AAMD,MAAM,UAAU,UAAU,CACzB,KAAa,EACb,QAAuC,EAC9B;IACT,MAAM,OAAO,GAAI,QAAiE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/F,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;AAAA,CACtB","sourcesContent":["export type Result<TValue, TError> = { ok: true; value: TValue } | { ok: false; error: TError };\n\nexport const Result = {\n\tok<TValue>(value: TValue): Result<TValue, never> {\n\t\treturn { ok: true, value };\n\t},\n\terr<TError>(error: TError): Result<never, TError> {\n\t\treturn { ok: false, error };\n\t},\n\tisOk<TValue, TError>(result: Result<TValue, TError>): result is { ok: true; value: TValue } {\n\t\treturn result.ok;\n\t},\n\tisErr<TValue, TError>(result: Result<TValue, TError>): result is { ok: false; error: TError } {\n\t\treturn !result.ok;\n\t},\n};\n\nexport interface TaggedErrorValue<Tag extends string> extends Error {\n\treadonly _tag: Tag;\n\ttoJSON(): { _tag: Tag; message: string } & Record<string, unknown>;\n}\n\nexport interface TaggedErrorFactory<Tag extends string> {\n\tnew <Props extends { message: string }>(props: Props): TaggedErrorValue<Tag> & Readonly<Props>;\n\tis(value: unknown): value is TaggedErrorValue<Tag>;\n}\n\nexport function TaggedError<Tag extends string>(tag: Tag): TaggedErrorFactory<Tag> {\n\tclass TaggedErrorClass extends Error {\n\t\treadonly _tag = tag;\n\n\t\tconstructor(props: { message: string } & Record<string, unknown>) {\n\t\t\tsuper(props.message);\n\t\t\tthis.name = tag;\n\t\t\tObject.assign(this, props);\n\t\t}\n\n\t\ttoJSON(): { _tag: Tag; message: string } & Record<string, unknown> {\n\t\t\tconst payload: Record<string, unknown> = {};\n\t\t\tfor (const key of Object.keys(this)) {\n\t\t\t\tif (key !== \"_tag\") payload[key] = (this as unknown as Record<string, unknown>)[key];\n\t\t\t}\n\t\t\treturn { _tag: tag, message: this.message, ...payload };\n\t\t}\n\n\t\tstatic is(value: unknown): value is TaggedErrorValue<Tag> {\n\t\t\treturn value instanceof TaggedErrorClass;\n\t\t}\n\t}\n\treturn TaggedErrorClass as unknown as TaggedErrorFactory<Tag>;\n}\n\nexport class LaneBusy extends TaggedError(\"LaneBusy\")<{\n\tlane: string;\n\toperationId: string;\n\toperationKind: \"run\" | \"compaction\" | \"navigation\";\n\tmessage: string;\n}> {}\nexport class OperationMismatch extends TaggedError(\"OperationMismatch\")<{\n\tlane: string;\n\texpectedOperationId: string;\n\tcurrentOperationId?: string;\n\tlastOperationId?: string;\n\tmessage: string;\n}> {}\nexport class NoActiveRun extends TaggedError(\"NoActiveRun\")<{ lane: string; message: string }> {}\nexport class NoActiveOperation extends TaggedError(\"NoActiveOperation\")<{ lane: string; message: string }> {}\nexport class NothingToResume extends TaggedError(\"NothingToResume\")<{ lane: string; message: string }> {}\nexport class NothingToCompact extends TaggedError(\"NothingToCompact\")<{ lane: string; message: string }> {}\nexport class InvalidMessage extends TaggedError(\"InvalidMessage\")<{\n\tlane: string;\n\treason: string;\n\tmessage: string;\n}> {}\nexport class InvalidNavigation extends TaggedError(\"InvalidNavigation\")<{\n\tlane: string;\n\treason: string;\n\tmessage: string;\n}> {}\nexport class UnknownSkill extends TaggedError(\"UnknownSkill\")<{ name: string; message: string }> {}\nexport class UnknownTemplate extends TaggedError(\"UnknownTemplate\")<{ name: string; message: string }> {}\nexport class UnknownTarget extends TaggedError(\"UnknownTarget\")<{ targetId: string; message: string }> {}\nexport class InvalidLane extends TaggedError(\"InvalidLane\")<{\n\tlane: string;\n\treason: string;\n\tmessage: string;\n}> {}\nexport class Closed extends TaggedError(\"Closed\")<{ message: string }> {}\n\nexport class HarnessFault extends Error {\n\treadonly cause: unknown;\n\n\tconstructor(message: string, cause: unknown) {\n\t\tsuper(message);\n\t\tthis.name = \"HarnessFault\";\n\t\tthis.cause = cause;\n\t}\n}\n\nexport class HarnessClosed extends Error {\n\tconstructor() {\n\t\tsuper(\"AgentHarness was closed while the operation was active\");\n\t\tthis.name = \"HarnessClosed\";\n\t}\n}\n\nexport type ErrorMatchers<TError extends TaggedErrorValue<string>, TValue> = {\n\t[Tag in TError[\"_tag\"]]: (error: Extract<TError, { _tag: Tag }>) => TValue;\n};\n\nexport function matchError<TError extends TaggedErrorValue<string>, TValue>(\n\terror: TError,\n\tmatchers: ErrorMatchers<TError, TValue>,\n): TValue {\n\tconst matcher = (matchers as unknown as Record<string, (value: TError) => TValue>)[error._tag];\n\treturn matcher(error);\n}\n"]}
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/harness/result.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,MAAM,GAAG;IACrB,EAAE,CAAS,KAAa;QACvB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IACD,GAAG,CAAS,KAAa;QACxB,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAC7B,CAAC;IACD,IAAI,CAAiB,MAA8B;QAClD,OAAO,MAAM,CAAC,EAAE,CAAC;IAClB,CAAC;IACD,KAAK,CAAiB,MAA8B;QACnD,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;IACnB,CAAC;CACD,CAAC;AAYF,MAAM,UAAU,WAAW,CAAqB,GAAQ;IACvD,MAAM,gBAAiB,SAAQ,KAAK;QAC1B,IAAI,GAAG,GAAG,CAAC;QAEpB,YAAY,KAAoD;YAC/D,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACrB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;YAChB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC5B,CAAC;QAED,MAAM;YACL,MAAM,OAAO,G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,MAAM,OAAO,MAAO,SAAQ,WAAW,CAAC,QAAQ,CAAsB;CAAG;AAEzE,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC7B,KAAK,CAAU;IAExB,YAAY,OAAe,EAAE,KAAc;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;CACD;AAED,MAAM,OAAO,aAAc,SAAQ,KAAK;IACvC;QACC,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAChE,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC7B,CAAC;CACD;AAMD,MAAM,UAAU,UAAU,CACzB,KAAa,EACb,QAAuC;IAEvC,MAAM,OAAO,GAAI,QAAiE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC/F,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC","sourcesContent":["export type Result<TValue, TError> = { ok: true; value: TValue } | { ok: false; error: TError };\n\nexport const Result = {\n\tok<TValue>(value: TValue): Result<TValue, never> {\n\t\treturn { ok: true, value };\n\t},\n\terr<TError>(error: TError): Result<never, TError> {\n\t\treturn { ok: false, error };\n\t},\n\tisOk<TValue, TError>(result: Result<TValue, TError>): result is { ok: true; value: TValue } {\n\t\treturn result.ok;\n\t},\n\tisErr<TValue, TError>(result: Result<TValue, TError>): result is { ok: false; error: TError } {\n\t\treturn !result.ok;\n\t},\n};\n\nexport interface TaggedErrorValue<Tag extends string> extends Error {\n\treadonly _tag: Tag;\n\ttoJSON(): { _tag: Tag; message: string } & Record<string, unknown>;\n}\n\nexport interface TaggedErrorFactory<Tag extends string> {\n\tnew <Props extends { message: string }>(props: Props): TaggedErrorValue<Tag> & Readonly<Props>;\n\tis(value: unknown): value is TaggedErrorValue<Tag>;\n}\n\nexport function TaggedError<Tag extends string>(tag: Tag): TaggedErrorFactory<Tag> {\n\tclass TaggedErrorClass extends Error {\n\t\treadonly _tag = tag;\n\n\t\tconstructor(props: { message: string } & Record<string, unknown>) {\n\t\t\tsuper(props.message);\n\t\t\tthis.name = tag;\n\t\t\tObject.assign(this, props);\n\t\t}\n\n\t\ttoJSON(): { _tag: Tag; message: string } & Record<string, unknown> {\n\t\t\tconst payload: Record<string, unknown> = {};\n\t\t\tfor (const key of Object.keys(this)) {\n\t\t\t\tif (key !== \"_tag\") payload[key] = (this as unknown as Record<string, unknown>)[key];\n\t\t\t}\n\t\t\treturn { _tag: tag, message: this.message, ...payload };\n\t\t}\n\n\t\tstatic is(value: unknown): value is TaggedErrorValue<Tag> {\n\t\t\treturn value instanceof TaggedErrorClass;\n\t\t}\n\t}\n\treturn TaggedErrorClass as unknown as TaggedErrorFactory<Tag>;\n}\n\nexport class LaneBusy extends TaggedError(\"LaneBusy\")<{\n\tlane: string;\n\toperationId: string;\n\toperationKind: \"run\" | \"compaction\" | \"navigation\";\n\tmessage: string;\n}> {}\nexport class OperationMismatch extends TaggedError(\"OperationMismatch\")<{\n\tlane: string;\n\texpectedOperationId: string;\n\tcurrentOperationId?: string;\n\tlastOperationId?: string;\n\tmessage: string;\n}> {}\nexport class NoActiveRun extends TaggedError(\"NoActiveRun\")<{ lane: string; message: string }> {}\nexport class NoActiveOperation extends TaggedError(\"NoActiveOperation\")<{ lane: string; message: string }> {}\nexport class NothingToResume extends TaggedError(\"NothingToResume\")<{ lane: string; message: string }> {}\nexport class NothingToCompact extends TaggedError(\"NothingToCompact\")<{ lane: string; message: string }> {}\nexport class InvalidMessage extends TaggedError(\"InvalidMessage\")<{\n\tlane: string;\n\treason: string;\n\tmessage: string;\n}> {}\nexport class InvalidNavigation extends TaggedError(\"InvalidNavigation\")<{\n\tlane: string;\n\treason: string;\n\tmessage: string;\n}> {}\nexport class UnknownSkill extends TaggedError(\"UnknownSkill\")<{ name: string; message: string }> {}\nexport class UnknownTemplate extends TaggedError(\"UnknownTemplate\")<{ name: string; message: string }> {}\nexport class UnknownTarget extends TaggedError(\"UnknownTarget\")<{ targetId: string; message: string }> {}\nexport class InvalidLane extends TaggedError(\"InvalidLane\")<{\n\tlane: string;\n\treason: string;\n\tmessage: string;\n}> {}\nexport class Closed extends TaggedError(\"Closed\")<{ message: string }> {}\n\nexport class HarnessFault extends Error {\n\treadonly cause: unknown;\n\n\tconstructor(message: string, cause: unknown) {\n\t\tsuper(message);\n\t\tthis.name = \"HarnessFault\";\n\t\tthis.cause = cause;\n\t}\n}\n\nexport class HarnessClosed extends Error {\n\tconstructor() {\n\t\tsuper(\"AgentHarness was closed while the operation was active\");\n\t\tthis.name = \"HarnessClosed\";\n\t}\n}\n\nexport type ErrorMatchers<TError extends TaggedErrorValue<string>, TValue> = {\n\t[Tag in TError[\"_tag\"]]: (error: Extract<TError, { _tag: Tag }>) => TValue;\n};\n\nexport function matchError<TError extends TaggedErrorValue<string>, TValue>(\n\terror: TError,\n\tmatchers: ErrorMatchers<TError, TValue>,\n): TValue {\n\tconst matcher = (matchers as unknown as Record<string, (value: TError) => TValue>)[error._tag];\n\treturn matcher(error);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../../../../src/harness/runtime/drive/boundary.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG3E,OAAO,KAAK,EACX,uBAAuB,EACvB,mBAAmB,EACnB,YAAY,EACZ,QAAQ,EACR,qBAAqB,EACrB,cAAc,EACd,aAAa,EACb,wBAAwB,EACxB,6BAA6B,EAC7B,qBAAqB,EACrB,KAAK,EACL,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGrE,MAAM,WAAW,qBAAqB;IACrC,IAAI,EAAE,gBAAgB,CAAC;IACvB,QAAQ,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6FAA6F;AAC7F,wBAAsB,iBAAiB,CAAC,QAAQ,SAAS,MAAM,GAAG,SAAS,EAAE,MAAM,SAAS,uBAAuB,EAClH,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EACpB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,OAAO,CAAC,mBAAmB,CAAC,cAAc,CAAC,EAAE;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,CAAC,EAClF,eAAe,EAAE,SAAS,MAAM,EAAE,EAClC,aAAa,GAAE,YAAY,EAAO,GAChC,OAAO,CAAC,eAAe,CAAC,CA2F1B","sourcesContent":["import { DEFAULT_MAX_AGENT_RETRY_DELAY_MS } from \"@earendil-works/pi-ai\";\nimport type { HarnessEvent, LaneQueuedItem } from \"../../agent-harness.ts\";\nimport { insertEntry } from \"../../session/commit.ts\";\nimport { SessionInvariantError } from \"../../session/session.ts\";\nimport type {\n\tAssistantReadyOperation,\n\tCheckpointOperation,\n\tCommitResult,\n\tNewEntry,\n\tNormalizedRetryPolicy,\n\tOperationScope,\n\tSessionReader,\n\tSummaryDecidingOperation,\n\tSummaryEffectPendingOperation,\n\tSummaryReadyOperation,\n\tWrite,\n} from \"../../session/types.ts\";\nimport { branchTip, deleteValue, pendingEntry, setValue } from \"../../session/values.ts\";\nimport type { Lane } from \"../lane.ts\";\nimport { committedEntryEvents, entryLifecycleEvents, readBoundedContext, readLaneQueues } from \"../transcript.ts\";\nimport type { Drive, LaneState, ProcedureResult } from \"../types.ts\";\nimport { operationCleanupWrites, operationResultRecord } from \"./terminal.ts\";\n\nexport interface BoundaryFinishPending {\n\tkind: \"finish_pending\";\n\tentryIds: string[];\n}\n\nexport interface BoundaryPlacement {\n\tentries: NewEntry[];\n\twrites: Write[];\n\ttipId: string | null;\n\tinbox: LaneState[\"inbox\"];\n\ttriggerEntryId?: string;\n\tqueues?: LaneQueuedItem[];\n}\n\ntype FinishBoundaryOperation =\n\t| CheckpointOperation\n\t| SummaryDecidingOperation\n\t| SummaryReadyOperation\n\t| SummaryEffectPendingOperation;\n\nexport function normalizedRetryPolicy<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n): NormalizedRetryPolicy {\n\tconst retry = lane.readConfig().retryPolicy;\n\treturn {\n\t\tmaxAttempts: retry.enabled ? retry.maxRetries + 1 : 1,\n\t\tbaseDelayMs: retry.baseDelayMs,\n\t\tmaxAgentDelayMs: retry.maxAgentDelayMs ?? DEFAULT_MAX_AGENT_RETRY_DELAY_MS,\n\t};\n}\n\nexport function assistantReadyAtBoundary<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tstate: LaneState,\n\tscope: OperationScope,\n\ttriggerEntryId: string,\n\toverflowRecoveryUsed: boolean,\n): AssistantReadyOperation {\n\tconst config = lane.readConfig();\n\treturn {\n\t\t...scope,\n\t\tat: \"assistant.ready\",\n\t\tgenerationContext: {\n\t\t\tstepId: lane.session.idGenerator.next(),\n\t\t\ttriggerEntryId,\n\t\t\tconfiguration: state.configuration,\n\t\t\tstreamOptions: config.streamOptions,\n\t\t\tretryPolicy: normalizedRetryPolicy(lane),\n\t\t\toverflowRecoveryUsed,\n\t\t},\n\t\tnextAttempt: 1,\n\t};\n}\n\n/** Select and materialize one boundary's lane-owned input without committing it. */\nexport async function planBoundaryInbox<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tstate: LaneState,\n\tscope: OperationScope,\n\treader: SessionReader,\n\ttipId: string | null,\n\tfollowUpWhenNoTrigger: boolean,\n): Promise<BoundaryPlacement> {\n\tconst steer = state.inbox.filter((item) => item.kind === \"steer\");\n\tconst selectedSteer = scope.settings.steeringMode === \"all\" ? steer : steer.slice(0, 1);\n\tlet selected = state.inbox.filter(\n\t\t(item) => item.kind === \"write\" || selectedSteer.some((candidate) => candidate.entryId === item.entryId),\n\t);\n\tconst load = (items: typeof selected) =>\n\t\tPromise.all(\n\t\t\titems.map(async (item) => {\n\t\t\t\tconst stored = await reader.getValue(pendingEntry(item.entryId), drive.context);\n\t\t\t\tif (stored === undefined) {\n\t\t\t\t\tthrow new SessionInvariantError(`Pending ${item.kind} entry ${item.entryId} is missing its payload`);\n\t\t\t\t}\n\t\t\t\tif (item.kind !== \"write\" && stored.value.type !== \"message\") {\n\t\t\t\t\tthrow new SessionInvariantError(`Queued ${item.kind} entry ${item.entryId} is not a message`);\n\t\t\t\t}\n\t\t\t\treturn { item, pending: stored.value };\n\t\t\t}),\n\t\t);\n\tlet pending = await load(selected);\n\tconst projects = (value: (typeof pending)[number][\"pending\"]): boolean =>\n\t\tvalue.type === \"message\" || lane.readConfig().entryProjectors[value.customType] !== undefined;\n\tif (followUpWhenNoTrigger && !pending.some(({ pending: value }) => projects(value))) {\n\t\tconst followUp = state.inbox.filter((item) => item.kind === \"followUp\");\n\t\tconst selectedFollowUp = scope.settings.followUpMode === \"all\" ? followUp : followUp.slice(0, 1);\n\t\tselected = [...selected, ...selectedFollowUp].sort((a, b) => state.inbox.indexOf(a) - state.inbox.indexOf(b));\n\t\tpending = await load(selected);\n\t}\n\n\tlet parentId = tipId;\n\tlet triggerEntryId: string | undefined;\n\tconst entries: NewEntry[] = pending.map(({ item, pending: value }) => {\n\t\tconst entry: NewEntry =\n\t\t\tvalue.type === \"message\"\n\t\t\t\t? { id: item.entryId, parentId, type: \"message\", message: value.payload }\n\t\t\t\t: {\n\t\t\t\t\t\tid: item.entryId,\n\t\t\t\t\t\tparentId,\n\t\t\t\t\t\ttype: \"custom\",\n\t\t\t\t\t\tcustomType: value.customType,\n\t\t\t\t\t\t...(value.payload === undefined ? {} : { data: value.payload }),\n\t\t\t\t\t};\n\t\tparentId = item.entryId;\n\t\tif (projects(value)) triggerEntryId = item.entryId;\n\t\treturn entry;\n\t});\n\tconst selectedIds = new Set(selected.map((item) => item.entryId));\n\tconst inbox = state.inbox.filter((item) => !selectedIds.has(item.entryId));\n\tconst queues = selected.length === 0 ? undefined : await readLaneQueues(reader, inbox, drive.context);\n\treturn {\n\t\tentries,\n\t\twrites: [\n\t\t\t...entries.map((entry) => insertEntry(entry)),\n\t\t\t...selected.map((item) => deleteValue(pendingEntry(item.entryId))),\n\t\t\t...(entries.length === 0 ? [] : [setValue(branchTip(lane.name), parentId)]),\n\t\t],\n\t\ttipId: parentId,\n\t\tinbox,\n\t\t...(triggerEntryId === undefined ? {} : { triggerEntryId }),\n\t\t...(queues === undefined ? {} : { queues }),\n\t};\n}\n\nexport function boundaryPlacementEvents(\n\tplacement: BoundaryPlacement,\n\tcommit: CommitResult,\n\tfirstWriteIndex: number,\n\tlane: string,\n\trunId: string,\n): HarnessEvent[] {\n\treturn [\n\t\t...committedEntryEvents(placement.entries, commit, lane, runId, firstWriteIndex),\n\t\t...(placement.queues === undefined ? [] : [{ type: \"queue_update\" as const, lane, queues: placement.queues }]),\n\t];\n}\n\n/** Replan after before_run_end and commit either renewed work or the terminal run result. */\nexport async function finishRunBoundary<TContext extends object | undefined, TState extends FinishBoundaryOperation>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tcapability: TState,\n\tcontinuation: Extract<CheckpointOperation[\"continuation\"], { kind: \"may_finish\" }>,\n\tplannedEntryIds: readonly string[],\n\tpendingEvents: HarnessEvent[] = [],\n): Promise<ProcedureResult> {\n\tconst context = await readBoundedContext(lane, drive, capability);\n\tif (context.kind === \"cancel_requested\") return { kind: \"continue\" };\n\tconst hook = await lane.hooks.runWithGate(\n\t\t\"before_run_end\",\n\t\t{ lane: lane.name, runId: drive.operationId, messages: context.value },\n\t\tdrive.gate,\n\t\tdrive.context,\n\t);\n\tconst followUp =\n\t\thook?.followUp === undefined\n\t\t\t? undefined\n\t\t\t: {\n\t\t\t\t\tid: lane.session.idGenerator.next(),\n\t\t\t\t\tmessage: { role: \"user\" as const, content: hook.followUp, timestamp: Date.now() },\n\t\t\t\t};\n\tconst result = await lane.continueOperation<TState, ProcedureResult>(\n\t\tcapability,\n\t\tasync (state, current, meta, reader) => {\n\t\t\tconst placement = await planBoundaryInbox(lane, drive, state, current, reader, state.tipId, true);\n\t\t\tif (placement.triggerEntryId !== undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\twrites: placement.writes,\n\t\t\t\t\toperationState: assistantReadyAtBoundary(lane, state, current, placement.triggerEntryId, false),\n\t\t\t\t\tlane: { tipId: placement.tipId, inbox: placement.inbox },\n\t\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\t\tevents: (commit) => [\n\t\t\t\t\t\t...pendingEvents,\n\t\t\t\t\t\t...boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst hookPlanIsCurrent =\n\t\t\t\tplacement.entries.length === plannedEntryIds.length &&\n\t\t\t\tplacement.entries.every((entry, index) => entry.id === plannedEntryIds[index]);\n\t\t\tif (hookPlanIsCurrent && followUp !== undefined) {\n\t\t\t\tconst entry: NewEntry = {\n\t\t\t\t\tid: followUp.id,\n\t\t\t\t\tparentId: placement.tipId,\n\t\t\t\t\ttype: \"message\",\n\t\t\t\t\tmessage: followUp.message,\n\t\t\t\t};\n\t\t\t\tconst entryWriteIndex = placement.writes.length;\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\twrites: [...placement.writes, insertEntry(entry), setValue(branchTip(lane.name), followUp.id)],\n\t\t\t\t\toperationState: assistantReadyAtBoundary(lane, state, current, followUp.id, false),\n\t\t\t\t\tlane: { tipId: followUp.id, inbox: placement.inbox },\n\t\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\t\tevents: (commit) => [\n\t\t\t\t\t\t...pendingEvents,\n\t\t\t\t\t\t...boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t\t\t...entryLifecycleEvents(\n\t\t\t\t\t\t\t{ ...entry, seq: commit.seqs[entryWriteIndex]!, timestamp: commit.timestamp },\n\t\t\t\t\t\t\tlane.name,\n\t\t\t\t\t\t\tdrive.operationId,\n\t\t\t\t\t\t),\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (placement.tipId === null) throw new SessionInvariantError(\"Completed run has no tip\");\n\t\t\tif (continuation.includeFinalAssistant && current.latestAssistantEntryId === null) {\n\t\t\t\tthrow new SessionInvariantError(\"Completed run is missing its final assistant\");\n\t\t\t}\n\t\t\tconst record = operationResultRecord(meta, \"completed\", placement.tipId);\n\t\t\tconst cleanup = await operationCleanupWrites(reader, drive.operationId, current, drive.context);\n\t\t\treturn {\n\t\t\t\tkind: \"finish\",\n\t\t\t\twrites: [...placement.writes, ...cleanup],\n\t\t\t\trecord,\n\t\t\t\tlane: { tipId: placement.tipId, inbox: placement.inbox },\n\t\t\t\tmaterialize: () => ({ kind: \"settled\", outcome: record }) as const,\n\t\t\t\tevents: (commit) => [\n\t\t\t\t\t...pendingEvents,\n\t\t\t\t\t...boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"run_end\",\n\t\t\t\t\t\tlane: lane.name,\n\t\t\t\t\t\trunId: drive.operationId,\n\t\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\t\tfromTipId: meta.sourceTipId,\n\t\t\t\t\t\ttipId: placement.tipId,\n\t\t\t\t\t\tendedAt: record.endedAt,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t},\n\t\tdrive.context,\n\t);\n\treturn result.kind === \"cancel_requested\" ? { kind: \"continue\" } : result.value;\n}\n"]}
1
+ {"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../../../../src/harness/runtime/drive/boundary.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG3E,OAAO,KAAK,EACX,uBAAuB,EACvB,mBAAmB,EACnB,YAAY,EACZ,QAAQ,EACR,qBAAqB,EACrB,cAAc,EACd,aAAa,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AK,EAAE,KAAK,CAAC,WAAW;oBACxB,MAAM,EAAE,WAAW;oBACnB,SAAS,EAAE,IAAI,CAAC,WAAW;oBAC3B,KAAK,EAAE,SAAS,CAAC,KAAK;oBACtB,OAAO,EAAE,MAAM,CAAC,OAAO;iBACvB;aACD;SACD,CAAC;IAAA,CACF,EACD,KAAK,CAAC,OAAO,CACb,CAAC;IACF,OAAO,MAAM,CAAC,IAAI,KAAK,kBAAkB,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;AAAA,CAChF","sourcesContent":["import { DEFAULT_MAX_AGENT_RETRY_DELAY_MS } from \"@earendil-works/pi-ai\";\nimport type { HarnessEvent, LaneQueuedItem } from \"../../agent-harness.ts\";\nimport { insertEntry } from \"../../session/commit.ts\";\nimport { SessionInvariantError } from \"../../session/session.ts\";\nimport type {\n\tAssistantReadyOperation,\n\tCheckpointOperation,\n\tCommitResult,\n\tNewEntry,\n\tNormalizedRetryPolicy,\n\tOperationScope,\n\tSessionReader,\n\tSummaryDecidingOperation,\n\tSummaryEffectPendingOperation,\n\tSummaryReadyOperation,\n\tWrite,\n} from \"../../session/types.ts\";\nimport { branchTip, deleteValue, pendingEntry, setValue } from \"../../session/values.ts\";\nimport type { Lane } from \"../lane.ts\";\nimport { committedEntryEvents, entryLifecycleEvents, readBoundedContext, readLaneQueues } from \"../transcript.ts\";\nimport type { Drive, LaneState, ProcedureResult } from \"../types.ts\";\nimport { operationCleanupWrites, operationResultRecord } from \"./terminal.ts\";\n\nexport interface BoundaryFinishPending {\n\tkind: \"finish_pending\";\n\tentryIds: string[];\n}\n\nexport interface BoundaryPlacement {\n\tentries: NewEntry[];\n\twrites: Write[];\n\ttipId: string | null;\n\tinbox: LaneState[\"inbox\"];\n\ttriggerEntryId?: string;\n\tqueues?: LaneQueuedItem[];\n}\n\ntype FinishBoundaryOperation =\n\t| CheckpointOperation\n\t| SummaryDecidingOperation\n\t| SummaryReadyOperation\n\t| SummaryEffectPendingOperation;\n\nexport function normalizedRetryPolicy<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n): NormalizedRetryPolicy {\n\tconst retry = lane.readConfig().retryPolicy;\n\treturn {\n\t\tmaxAttempts: retry.enabled ? retry.maxRetries + 1 : 1,\n\t\tbaseDelayMs: retry.baseDelayMs,\n\t\tmaxAgentDelayMs: retry.maxAgentDelayMs ?? DEFAULT_MAX_AGENT_RETRY_DELAY_MS,\n\t};\n}\n\nexport function assistantReadyAtBoundary<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tstate: LaneState,\n\tscope: OperationScope,\n\ttriggerEntryId: string,\n\toverflowRecoveryUsed: boolean,\n): AssistantReadyOperation {\n\tconst config = lane.readConfig();\n\treturn {\n\t\t...scope,\n\t\tat: \"assistant.ready\",\n\t\tgenerationContext: {\n\t\t\tstepId: lane.session.idGenerator.next(),\n\t\t\ttriggerEntryId,\n\t\t\tconfiguration: state.configuration,\n\t\t\tstreamOptions: config.streamOptions,\n\t\t\tretryPolicy: normalizedRetryPolicy(lane),\n\t\t\toverflowRecoveryUsed,\n\t\t},\n\t\tnextAttempt: 1,\n\t};\n}\n\n/** Select and materialize one boundary's lane-owned input without committing it. */\nexport async function planBoundaryInbox<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tstate: LaneState,\n\tscope: OperationScope,\n\treader: SessionReader,\n\ttipId: string | null,\n\tfollowUpWhenNoTrigger: boolean,\n): Promise<BoundaryPlacement> {\n\tconst steer = state.inbox.filter((item) => item.kind === \"steer\");\n\tconst selectedSteer = scope.settings.steeringMode === \"all\" ? steer : steer.slice(0, 1);\n\tlet selected = state.inbox.filter(\n\t\t(item) => item.kind === \"write\" || selectedSteer.some((candidate) => candidate.entryId === item.entryId),\n\t);\n\tconst load = (items: typeof selected) =>\n\t\tPromise.all(\n\t\t\titems.map(async (item) => {\n\t\t\t\tconst stored = await reader.getValue(pendingEntry(item.entryId), drive.context);\n\t\t\t\tif (stored === undefined) {\n\t\t\t\t\tthrow new SessionInvariantError(`Pending ${item.kind} entry ${item.entryId} is missing its payload`);\n\t\t\t\t}\n\t\t\t\tif (item.kind !== \"write\" && stored.value.type !== \"message\") {\n\t\t\t\t\tthrow new SessionInvariantError(`Queued ${item.kind} entry ${item.entryId} is not a message`);\n\t\t\t\t}\n\t\t\t\treturn { item, pending: stored.value };\n\t\t\t}),\n\t\t);\n\tlet pending = await load(selected);\n\tconst projects = (value: (typeof pending)[number][\"pending\"]): boolean =>\n\t\tvalue.type === \"message\" || lane.readConfig().entryProjectors[value.customType] !== undefined;\n\tif (followUpWhenNoTrigger && !pending.some(({ pending: value }) => projects(value))) {\n\t\tconst followUp = state.inbox.filter((item) => item.kind === \"followUp\");\n\t\tconst selectedFollowUp = scope.settings.followUpMode === \"all\" ? followUp : followUp.slice(0, 1);\n\t\tselected = [...selected, ...selectedFollowUp].sort((a, b) => state.inbox.indexOf(a) - state.inbox.indexOf(b));\n\t\tpending = await load(selected);\n\t}\n\n\tlet parentId = tipId;\n\tlet triggerEntryId: string | undefined;\n\tconst entries: NewEntry[] = pending.map(({ item, pending: value }) => {\n\t\tconst entry: NewEntry =\n\t\t\tvalue.type === \"message\"\n\t\t\t\t? { id: item.entryId, parentId, type: \"message\", message: value.payload }\n\t\t\t\t: {\n\t\t\t\t\t\tid: item.entryId,\n\t\t\t\t\t\tparentId,\n\t\t\t\t\t\ttype: \"custom\",\n\t\t\t\t\t\tcustomType: value.customType,\n\t\t\t\t\t\t...(value.payload === undefined ? {} : { data: value.payload }),\n\t\t\t\t\t};\n\t\tparentId = item.entryId;\n\t\tif (projects(value)) triggerEntryId = item.entryId;\n\t\treturn entry;\n\t});\n\tconst selectedIds = new Set(selected.map((item) => item.entryId));\n\tconst inbox = state.inbox.filter((item) => !selectedIds.has(item.entryId));\n\tconst queues = selected.length === 0 ? undefined : await readLaneQueues(reader, inbox, drive.context);\n\treturn {\n\t\tentries,\n\t\twrites: [\n\t\t\t...entries.map((entry) => insertEntry(entry)),\n\t\t\t...selected.map((item) => deleteValue(pendingEntry(item.entryId))),\n\t\t\t...(entries.length === 0 ? [] : [setValue(branchTip(lane.name), parentId)]),\n\t\t],\n\t\ttipId: parentId,\n\t\tinbox,\n\t\t...(triggerEntryId === undefined ? {} : { triggerEntryId }),\n\t\t...(queues === undefined ? {} : { queues }),\n\t};\n}\n\nexport function boundaryPlacementEvents(\n\tplacement: BoundaryPlacement,\n\tcommit: CommitResult,\n\tfirstWriteIndex: number,\n\tlane: string,\n\trunId: string,\n): HarnessEvent[] {\n\treturn [\n\t\t...committedEntryEvents(placement.entries, commit, lane, runId, firstWriteIndex),\n\t\t...(placement.queues === undefined ? [] : [{ type: \"queue_update\" as const, lane, queues: placement.queues }]),\n\t];\n}\n\n/** Replan after before_run_end and commit either renewed work or the terminal run result. */\nexport async function finishRunBoundary<TContext extends object | undefined, TState extends FinishBoundaryOperation>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tcapability: TState,\n\tcontinuation: Extract<CheckpointOperation[\"continuation\"], { kind: \"may_finish\" }>,\n\tplannedEntryIds: readonly string[],\n\tpendingEvents: HarnessEvent[] = [],\n): Promise<ProcedureResult> {\n\tconst context = await readBoundedContext(lane, drive, capability);\n\tif (context.kind === \"cancel_requested\") return { kind: \"continue\" };\n\tconst hook = await lane.hooks.runWithGate(\n\t\t\"before_run_end\",\n\t\t{ lane: lane.name, runId: drive.operationId, messages: context.value },\n\t\tdrive.gate,\n\t\tdrive.context,\n\t);\n\tconst followUp =\n\t\thook?.followUp === undefined\n\t\t\t? undefined\n\t\t\t: {\n\t\t\t\t\tid: lane.session.idGenerator.next(),\n\t\t\t\t\tmessage: { role: \"user\" as const, content: hook.followUp, timestamp: Date.now() },\n\t\t\t\t};\n\tconst result = await lane.continueOperation<TState, ProcedureResult>(\n\t\tcapability,\n\t\tasync (state, current, meta, reader) => {\n\t\t\tconst placement = await planBoundaryInbox(lane, drive, state, current, reader, state.tipId, true);\n\t\t\tif (placement.triggerEntryId !== undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\twrites: placement.writes,\n\t\t\t\t\toperationState: assistantReadyAtBoundary(lane, state, current, placement.triggerEntryId, false),\n\t\t\t\t\tlane: { tipId: placement.tipId, inbox: placement.inbox },\n\t\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\t\tevents: (commit) => [\n\t\t\t\t\t\t...pendingEvents,\n\t\t\t\t\t\t...boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst hookPlanIsCurrent =\n\t\t\t\tplacement.entries.length === plannedEntryIds.length &&\n\t\t\t\tplacement.entries.every((entry, index) => entry.id === plannedEntryIds[index]);\n\t\t\tif (hookPlanIsCurrent && followUp !== undefined) {\n\t\t\t\tconst entry: NewEntry = {\n\t\t\t\t\tid: followUp.id,\n\t\t\t\t\tparentId: placement.tipId,\n\t\t\t\t\ttype: \"message\",\n\t\t\t\t\tmessage: followUp.message,\n\t\t\t\t};\n\t\t\t\tconst entryWriteIndex = placement.writes.length;\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\twrites: [...placement.writes, insertEntry(entry), setValue(branchTip(lane.name), followUp.id)],\n\t\t\t\t\toperationState: assistantReadyAtBoundary(lane, state, current, followUp.id, false),\n\t\t\t\t\tlane: { tipId: followUp.id, inbox: placement.inbox },\n\t\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\t\tevents: (commit) => [\n\t\t\t\t\t\t...pendingEvents,\n\t\t\t\t\t\t...boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t\t\t...entryLifecycleEvents(\n\t\t\t\t\t\t\t{ ...entry, seq: commit.seqs[entryWriteIndex]!, timestamp: commit.timestamp },\n\t\t\t\t\t\t\tlane.name,\n\t\t\t\t\t\t\tdrive.operationId,\n\t\t\t\t\t\t),\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (placement.tipId === null) throw new SessionInvariantError(\"Completed run has no tip\");\n\t\t\tif (continuation.includeFinalAssistant && current.latestAssistantEntryId === null) {\n\t\t\t\tthrow new SessionInvariantError(\"Completed run is missing its final assistant\");\n\t\t\t}\n\t\t\tconst record = operationResultRecord(meta, \"completed\", placement.tipId);\n\t\t\tconst cleanup = await operationCleanupWrites(reader, drive.operationId, current, drive.context);\n\t\t\treturn {\n\t\t\t\tkind: \"finish\",\n\t\t\t\twrites: [...placement.writes, ...cleanup],\n\t\t\t\trecord,\n\t\t\t\tlane: { tipId: placement.tipId, inbox: placement.inbox },\n\t\t\t\tmaterialize: () => ({ kind: \"settled\", outcome: record }) as const,\n\t\t\t\tevents: (commit) => [\n\t\t\t\t\t...pendingEvents,\n\t\t\t\t\t...boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"run_end\",\n\t\t\t\t\t\tlane: lane.name,\n\t\t\t\t\t\trunId: drive.operationId,\n\t\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\t\tfromTipId: meta.sourceTipId,\n\t\t\t\t\t\ttipId: placement.tipId,\n\t\t\t\t\t\tendedAt: record.endedAt,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t},\n\t\tdrive.context,\n\t);\n\treturn result.kind === \"cancel_requested\" ? { kind: \"continue\" } : result.value;\n}\n"]}
1
+ {"version":3,"file":"boundary.js","sourceRoot":"","sources":["../../../../src/harness/runtime/drive/boundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gCAAgC,EAAE,MAAM,uBAAuB,CAAC;AAEzE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAcjE,OAAO,EAAE,SAAS,EAAE,WAAW,EA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;gBACnB,GAAG,aAAa;gBAChB,GAAG,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,WAAW,CAAC;gBAC9E;oBACC,IAAI,EAAE,SAAS;oBACf,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,KAAK,EAAE,KAAK,CAAC,WAAW;oBACxB,MAAM,EAAE,WAAW;oBACnB,SAAS,EAAE,IAAI,CAAC,WAAW;oBAC3B,KAAK,EAAE,SAAS,CAAC,KAAK;oBACtB,OAAO,EAAE,MAAM,CAAC,OAAO;iBACvB;aACD;SACD,CAAC;IACH,CAAC,EACD,KAAK,CAAC,OAAO,CACb,CAAC;IACF,OAAO,MAAM,CAAC,IAAI,KAAK,kBAAkB,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;AACjF,CAAC","sourcesContent":["import { DEFAULT_MAX_AGENT_RETRY_DELAY_MS } from \"@earendil-works/pi-ai\";\nimport type { HarnessEvent, LaneQueuedItem } from \"../../agent-harness.ts\";\nimport { insertEntry } from \"../../session/commit.ts\";\nimport { SessionInvariantError } from \"../../session/session.ts\";\nimport type {\n\tAssistantReadyOperation,\n\tCheckpointOperation,\n\tCommitResult,\n\tNewEntry,\n\tNormalizedRetryPolicy,\n\tOperationScope,\n\tSessionReader,\n\tSummaryDecidingOperation,\n\tSummaryEffectPendingOperation,\n\tSummaryReadyOperation,\n\tWrite,\n} from \"../../session/types.ts\";\nimport { branchTip, deleteValue, pendingEntry, setValue } from \"../../session/values.ts\";\nimport type { Lane } from \"../lane.ts\";\nimport { committedEntryEvents, entryLifecycleEvents, readBoundedContext, readLaneQueues } from \"../transcript.ts\";\nimport type { Drive, LaneState, ProcedureResult } from \"../types.ts\";\nimport { operationCleanupWrites, operationResultRecord } from \"./terminal.ts\";\n\nexport interface BoundaryFinishPending {\n\tkind: \"finish_pending\";\n\tentryIds: string[];\n}\n\nexport interface BoundaryPlacement {\n\tentries: NewEntry[];\n\twrites: Write[];\n\ttipId: string | null;\n\tinbox: LaneState[\"inbox\"];\n\ttriggerEntryId?: string;\n\tqueues?: LaneQueuedItem[];\n}\n\ntype FinishBoundaryOperation =\n\t| CheckpointOperation\n\t| SummaryDecidingOperation\n\t| SummaryReadyOperation\n\t| SummaryEffectPendingOperation;\n\nexport function normalizedRetryPolicy<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n): NormalizedRetryPolicy {\n\tconst retry = lane.readConfig().retryPolicy;\n\treturn {\n\t\tmaxAttempts: retry.enabled ? retry.maxRetries + 1 : 1,\n\t\tbaseDelayMs: retry.baseDelayMs,\n\t\tmaxAgentDelayMs: retry.maxAgentDelayMs ?? DEFAULT_MAX_AGENT_RETRY_DELAY_MS,\n\t};\n}\n\nexport function assistantReadyAtBoundary<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tstate: LaneState,\n\tscope: OperationScope,\n\ttriggerEntryId: string,\n\toverflowRecoveryUsed: boolean,\n): AssistantReadyOperation {\n\tconst config = lane.readConfig();\n\treturn {\n\t\t...scope,\n\t\tat: \"assistant.ready\",\n\t\tgenerationContext: {\n\t\t\tstepId: lane.session.idGenerator.next(),\n\t\t\ttriggerEntryId,\n\t\t\tconfiguration: state.configuration,\n\t\t\tstreamOptions: config.streamOptions,\n\t\t\tretryPolicy: normalizedRetryPolicy(lane),\n\t\t\toverflowRecoveryUsed,\n\t\t},\n\t\tnextAttempt: 1,\n\t};\n}\n\n/** Select and materialize one boundary's lane-owned input without committing it. */\nexport async function planBoundaryInbox<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tstate: LaneState,\n\tscope: OperationScope,\n\treader: SessionReader,\n\ttipId: string | null,\n\tfollowUpWhenNoTrigger: boolean,\n): Promise<BoundaryPlacement> {\n\tconst steer = state.inbox.filter((item) => item.kind === \"steer\");\n\tconst selectedSteer = scope.settings.steeringMode === \"all\" ? steer : steer.slice(0, 1);\n\tlet selected = state.inbox.filter(\n\t\t(item) => item.kind === \"write\" || selectedSteer.some((candidate) => candidate.entryId === item.entryId),\n\t);\n\tconst load = (items: typeof selected) =>\n\t\tPromise.all(\n\t\t\titems.map(async (item) => {\n\t\t\t\tconst stored = await reader.getValue(pendingEntry(item.entryId), drive.context);\n\t\t\t\tif (stored === undefined) {\n\t\t\t\t\tthrow new SessionInvariantError(`Pending ${item.kind} entry ${item.entryId} is missing its payload`);\n\t\t\t\t}\n\t\t\t\tif (item.kind !== \"write\" && stored.value.type !== \"message\") {\n\t\t\t\t\tthrow new SessionInvariantError(`Queued ${item.kind} entry ${item.entryId} is not a message`);\n\t\t\t\t}\n\t\t\t\treturn { item, pending: stored.value };\n\t\t\t}),\n\t\t);\n\tlet pending = await load(selected);\n\tconst projects = (value: (typeof pending)[number][\"pending\"]): boolean =>\n\t\tvalue.type === \"message\" || lane.readConfig().entryProjectors[value.customType] !== undefined;\n\tif (followUpWhenNoTrigger && !pending.some(({ pending: value }) => projects(value))) {\n\t\tconst followUp = state.inbox.filter((item) => item.kind === \"followUp\");\n\t\tconst selectedFollowUp = scope.settings.followUpMode === \"all\" ? followUp : followUp.slice(0, 1);\n\t\tselected = [...selected, ...selectedFollowUp].sort((a, b) => state.inbox.indexOf(a) - state.inbox.indexOf(b));\n\t\tpending = await load(selected);\n\t}\n\n\tlet parentId = tipId;\n\tlet triggerEntryId: string | undefined;\n\tconst entries: NewEntry[] = pending.map(({ item, pending: value }) => {\n\t\tconst entry: NewEntry =\n\t\t\tvalue.type === \"message\"\n\t\t\t\t? { id: item.entryId, parentId, type: \"message\", message: value.payload }\n\t\t\t\t: {\n\t\t\t\t\t\tid: item.entryId,\n\t\t\t\t\t\tparentId,\n\t\t\t\t\t\ttype: \"custom\",\n\t\t\t\t\t\tcustomType: value.customType,\n\t\t\t\t\t\t...(value.payload === undefined ? {} : { data: value.payload }),\n\t\t\t\t\t};\n\t\tparentId = item.entryId;\n\t\tif (projects(value)) triggerEntryId = item.entryId;\n\t\treturn entry;\n\t});\n\tconst selectedIds = new Set(selected.map((item) => item.entryId));\n\tconst inbox = state.inbox.filter((item) => !selectedIds.has(item.entryId));\n\tconst queues = selected.length === 0 ? undefined : await readLaneQueues(reader, inbox, drive.context);\n\treturn {\n\t\tentries,\n\t\twrites: [\n\t\t\t...entries.map((entry) => insertEntry(entry)),\n\t\t\t...selected.map((item) => deleteValue(pendingEntry(item.entryId))),\n\t\t\t...(entries.length === 0 ? [] : [setValue(branchTip(lane.name), parentId)]),\n\t\t],\n\t\ttipId: parentId,\n\t\tinbox,\n\t\t...(triggerEntryId === undefined ? {} : { triggerEntryId }),\n\t\t...(queues === undefined ? {} : { queues }),\n\t};\n}\n\nexport function boundaryPlacementEvents(\n\tplacement: BoundaryPlacement,\n\tcommit: CommitResult,\n\tfirstWriteIndex: number,\n\tlane: string,\n\trunId: string,\n): HarnessEvent[] {\n\treturn [\n\t\t...committedEntryEvents(placement.entries, commit, lane, runId, firstWriteIndex),\n\t\t...(placement.queues === undefined ? [] : [{ type: \"queue_update\" as const, lane, queues: placement.queues }]),\n\t];\n}\n\n/** Replan after before_run_end and commit either renewed work or the terminal run result. */\nexport async function finishRunBoundary<TContext extends object | undefined, TState extends FinishBoundaryOperation>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tcapability: TState,\n\tcontinuation: Extract<CheckpointOperation[\"continuation\"], { kind: \"may_finish\" }>,\n\tplannedEntryIds: readonly string[],\n\tpendingEvents: HarnessEvent[] = [],\n): Promise<ProcedureResult> {\n\tconst context = await readBoundedContext(lane, drive, capability);\n\tif (context.kind === \"cancel_requested\") return { kind: \"continue\" };\n\tconst hook = await lane.hooks.runWithGate(\n\t\t\"before_run_end\",\n\t\t{ lane: lane.name, runId: drive.operationId, messages: context.value },\n\t\tdrive.gate,\n\t\tdrive.context,\n\t);\n\tconst followUp =\n\t\thook?.followUp === undefined\n\t\t\t? undefined\n\t\t\t: {\n\t\t\t\t\tid: lane.session.idGenerator.next(),\n\t\t\t\t\tmessage: { role: \"user\" as const, content: hook.followUp, timestamp: Date.now() },\n\t\t\t\t};\n\tconst result = await lane.continueOperation<TState, ProcedureResult>(\n\t\tcapability,\n\t\tasync (state, current, meta, reader) => {\n\t\t\tconst placement = await planBoundaryInbox(lane, drive, state, current, reader, state.tipId, true);\n\t\t\tif (placement.triggerEntryId !== undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\twrites: placement.writes,\n\t\t\t\t\toperationState: assistantReadyAtBoundary(lane, state, current, placement.triggerEntryId, false),\n\t\t\t\t\tlane: { tipId: placement.tipId, inbox: placement.inbox },\n\t\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\t\tevents: (commit) => [\n\t\t\t\t\t\t...pendingEvents,\n\t\t\t\t\t\t...boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst hookPlanIsCurrent =\n\t\t\t\tplacement.entries.length === plannedEntryIds.length &&\n\t\t\t\tplacement.entries.every((entry, index) => entry.id === plannedEntryIds[index]);\n\t\t\tif (hookPlanIsCurrent && followUp !== undefined) {\n\t\t\t\tconst entry: NewEntry = {\n\t\t\t\t\tid: followUp.id,\n\t\t\t\t\tparentId: placement.tipId,\n\t\t\t\t\ttype: \"message\",\n\t\t\t\t\tmessage: followUp.message,\n\t\t\t\t};\n\t\t\t\tconst entryWriteIndex = placement.writes.length;\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\twrites: [...placement.writes, insertEntry(entry), setValue(branchTip(lane.name), followUp.id)],\n\t\t\t\t\toperationState: assistantReadyAtBoundary(lane, state, current, followUp.id, false),\n\t\t\t\t\tlane: { tipId: followUp.id, inbox: placement.inbox },\n\t\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\t\tevents: (commit) => [\n\t\t\t\t\t\t...pendingEvents,\n\t\t\t\t\t\t...boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t\t\t...entryLifecycleEvents(\n\t\t\t\t\t\t\t{ ...entry, seq: commit.seqs[entryWriteIndex]!, timestamp: commit.timestamp },\n\t\t\t\t\t\t\tlane.name,\n\t\t\t\t\t\t\tdrive.operationId,\n\t\t\t\t\t\t),\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (placement.tipId === null) throw new SessionInvariantError(\"Completed run has no tip\");\n\t\t\tif (continuation.includeFinalAssistant && current.latestAssistantEntryId === null) {\n\t\t\t\tthrow new SessionInvariantError(\"Completed run is missing its final assistant\");\n\t\t\t}\n\t\t\tconst record = operationResultRecord(meta, \"completed\", placement.tipId);\n\t\t\tconst cleanup = await operationCleanupWrites(reader, drive.operationId, current, drive.context);\n\t\t\treturn {\n\t\t\t\tkind: \"finish\",\n\t\t\t\twrites: [...placement.writes, ...cleanup],\n\t\t\t\trecord,\n\t\t\t\tlane: { tipId: placement.tipId, inbox: placement.inbox },\n\t\t\t\tmaterialize: () => ({ kind: \"settled\", outcome: record }) as const,\n\t\t\t\tevents: (commit) => [\n\t\t\t\t\t...pendingEvents,\n\t\t\t\t\t...boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"run_end\",\n\t\t\t\t\t\tlane: lane.name,\n\t\t\t\t\t\trunId: drive.operationId,\n\t\t\t\t\t\tstatus: \"completed\",\n\t\t\t\t\t\tfromTipId: meta.sourceTipId,\n\t\t\t\t\t\ttipId: placement.tipId,\n\t\t\t\t\t\tendedAt: record.endedAt,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t},\n\t\tdrive.context,\n\t);\n\treturn result.kind === \"cancel_requested\" ? { kind: \"continue\" } : result.value;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"checkpoint.d.ts","sourceRoot":"","sources":["../../../../src/harness/runtime/drive/checkpoint.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,KAAK,mBAAmB,EAIxB,KAAK,iBAAiB,EAEtB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAU1D,4DAA4D;AAC5D,wBAAsB,QAAQ,CAAC,QAAQ,SAAS,MAAM,GAAG,SAAS,EACjE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EACpB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,iBAAiB,GACpB,OAAO,CAAC,eAAe,CAAC,CA+D1B;AAED,gEAAgE;AAChE,wBAAsB,aAAa,CAAC,QAAQ,SAAS,MAAM,GAAG,SAAS,EACtE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EACpB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,mBAAmB,GACtB,OAAO,CAAC,eAAe,CAAC,CA2F1B","sourcesContent":["import { insertEntry } from \"../../session/commit.ts\";\nimport { SessionInvariantError } from \"../../session/session.ts\";\nimport {\n\ttype CheckpointOperation,\n\ttype MessageEntry,\n\ttype NewEntry,\n\toperationScopeOf,\n\ttype StartingOperation,\n\ttype SummaryDecidingOperation,\n} from \"../../session/types.ts\";\nimport { branchTip, operationPreparation, setValue } from \"../../session/values.ts\";\nimport type { Lane } from \"../lane.ts\";\nimport { chainEntries, committedEntryEvents } from \"../transcript.ts\";\nimport type { Drive, ProcedureResult } from \"../types.ts\";\nimport {\n\tassistantReadyAtBoundary,\n\ttype BoundaryFinishPending,\n\tboundaryPlacementEvents,\n\tfinishRunBoundary,\n\tplanBoundaryInbox,\n} from \"./boundary.ts\";\nimport { prepareCompactionThreshold } from \"./structural.ts\";\n\n/** Consume before_run and commit the initial checkpoint. */\nexport async function startRun<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\trun: StartingOperation,\n): Promise<ProcedureResult> {\n\tconst prompt = await lane.continueOperation(\n\t\trun,\n\t\tasync (_state, _current, meta, reader) => {\n\t\t\tif (meta.intent.kind !== \"run\") throw new SessionInvariantError(\"Run operation has non-run intent\");\n\t\t\tconst entries = await reader.getEntries(meta.intent.promptEntryIds, drive.context);\n\t\t\tconst messages = meta.intent.promptEntryIds.map((id) => {\n\t\t\t\tconst entry = entries.get(id);\n\t\t\t\tif (entry?.type !== \"message\") {\n\t\t\t\t\tthrow new SessionInvariantError(`Run prompt entry ${id} is missing its message`);\n\t\t\t\t}\n\t\t\t\treturn entry.message;\n\t\t\t});\n\t\t\treturn { kind: \"return\", result: messages };\n\t\t},\n\t\tdrive.context,\n\t);\n\tif (prompt.kind === \"cancel_requested\") return { kind: \"continue\" };\n\n\tconst hook = await lane.hooks.runWithGate(\n\t\t\"before_run\",\n\t\t{ lane: lane.name, runId: drive.operationId, prompt: prompt.value, resources: lane.readConfig().resources },\n\t\tdrive.gate,\n\t\tdrive.context,\n\t);\n\tconst injected = hook?.messages ?? [];\n\tfor (const message of injected) {\n\t\tif (message.role === \"assistant\" && message.stopReason === \"pending\") {\n\t\t\tthrow new SessionInvariantError(\"before_run returned a pending assistant message\");\n\t\t}\n\t}\n\tconst reserved = injected.map((message) => ({ id: lane.session.idGenerator.next(), message }));\n\n\tconst result = await lane.continueOperation(\n\t\trun,\n\t\t(state, current) => {\n\t\t\tconst entries: NewEntry<MessageEntry>[] = chainEntries(\n\t\t\t\tstate.tipId,\n\t\t\t\treserved.map(({ id, message }) => ({ id, type: \"message\" as const, message })),\n\t\t\t);\n\t\t\tconst triggerEntryId = entries.at(-1)?.id ?? state.tipId;\n\t\t\tif (triggerEntryId === null) throw new SessionInvariantError(\"Run start has no trigger entry\");\n\t\t\tconst nextState: CheckpointOperation = {\n\t\t\t\t...operationScopeOf(current),\n\t\t\t\tat: \"checkpoint\",\n\t\t\t\tcontinuation: { kind: \"need_assistant\", overflowRecoveryUsed: false },\n\t\t\t\ttriggerEntryId,\n\t\t\t};\n\t\t\treturn {\n\t\t\t\tkind: \"commit\",\n\t\t\t\twrites: [\n\t\t\t\t\t...entries.map((entry) => insertEntry(entry)),\n\t\t\t\t\t...(entries.length === 0 ? [] : [setValue(branchTip(lane.name), triggerEntryId)]),\n\t\t\t\t],\n\t\t\t\toperationState: nextState,\n\t\t\t\tlane: { tipId: triggerEntryId },\n\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\tevents: (commit) => committedEntryEvents(entries, commit, lane.name, drive.operationId),\n\t\t\t};\n\t\t},\n\t\tdrive.context,\n\t);\n\treturn result.kind === \"cancel_requested\" ? { kind: \"continue\" } : result.value;\n}\n\n/** Advance one durable run boundary with at most one commit. */\nexport async function runCheckpoint<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\trun: CheckpointOperation,\n): Promise<ProcedureResult> {\n\tconst threshold = await prepareCompactionThreshold(lane, drive, run);\n\tif (threshold.kind === \"cancel_requested\") return { kind: \"continue\" };\n\tconst planned = await lane.continueOperation<CheckpointOperation, ProcedureResult | BoundaryFinishPending>(\n\t\trun,\n\t\tasync (state, current, _meta, reader) => {\n\t\t\tconst placement = await planBoundaryInbox(\n\t\t\t\tlane,\n\t\t\t\tdrive,\n\t\t\t\tstate,\n\t\t\t\tcurrent,\n\t\t\t\treader,\n\t\t\t\tstate.tipId,\n\t\t\t\tthreshold.value === undefined && current.continuation.kind === \"may_finish\",\n\t\t\t);\n\t\t\tif (placement.triggerEntryId !== undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\twrites: placement.writes,\n\t\t\t\t\toperationState: assistantReadyAtBoundary(lane, state, current, placement.triggerEntryId, false),\n\t\t\t\t\tlane: { tipId: placement.tipId, inbox: placement.inbox },\n\t\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\t\tevents: (commit) => boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (threshold.value !== undefined) {\n\t\t\t\tconst structural: SummaryDecidingOperation = {\n\t\t\t\t\t...operationScopeOf(current),\n\t\t\t\t\tat: \"summary.deciding\",\n\t\t\t\t\ttask: {\n\t\t\t\t\t\ttaskId: threshold.value.taskId,\n\t\t\t\t\t\treason: \"threshold\",\n\t\t\t\t\t\tboundary: {\n\t\t\t\t\t\t\tkind: \"resume_checkpoint\",\n\t\t\t\t\t\t\tresumeAfter: { continuation: current.continuation, triggerEntryId: current.triggerEntryId },\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\twrites: [\n\t\t\t\t\t\t...placement.writes,\n\t\t\t\t\t\tsetValue(\n\t\t\t\t\t\t\toperationPreparation(drive.operationId, threshold.value.taskId),\n\t\t\t\t\t\t\tthreshold.value.preparation,\n\t\t\t\t\t\t),\n\t\t\t\t\t],\n\t\t\t\t\toperationState: structural,\n\t\t\t\t\tlane: { tipId: placement.tipId, inbox: placement.inbox },\n\t\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\t\tevents: (commit) => [\n\t\t\t\t\t\t...boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"compaction_start\",\n\t\t\t\t\t\t\tlane: lane.name,\n\t\t\t\t\t\t\trunId: drive.operationId,\n\t\t\t\t\t\t\treason: \"threshold\",\n\t\t\t\t\t\t\tstartedAt: commit.timestamp,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (current.continuation.kind === \"need_assistant\") {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\twrites: placement.writes,\n\t\t\t\t\toperationState: assistantReadyAtBoundary(\n\t\t\t\t\t\tlane,\n\t\t\t\t\t\tstate,\n\t\t\t\t\t\tcurrent,\n\t\t\t\t\t\tcurrent.triggerEntryId,\n\t\t\t\t\t\tcurrent.continuation.overflowRecoveryUsed,\n\t\t\t\t\t),\n\t\t\t\t\tlane: { tipId: placement.tipId, inbox: placement.inbox },\n\t\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\t\tevents: (commit) => boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: \"return\",\n\t\t\t\tresult: { kind: \"finish_pending\", entryIds: placement.entries.map((entry) => entry.id) } as const,\n\t\t\t};\n\t\t},\n\t\tdrive.context,\n\t);\n\tif (planned.kind === \"cancel_requested\") return { kind: \"continue\" };\n\tif (planned.value.kind !== \"finish_pending\") return planned.value;\n\tif (run.continuation.kind !== \"may_finish\") {\n\t\tthrow new SessionInvariantError(\"Checkpoint finish mediation requires a finish continuation\");\n\t}\n\treturn finishRunBoundary(lane, drive, run, run.continuation, planned.value.entryIds);\n}\n"]}
1
+ {"version":3,"file":"checkpoint.d.ts","sourceRoot":"","sources":["../../../../src/harness/runtime/drive/checkpoint.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,KAAK,mBAAmB,EAIxB,KAAK,iBAAiB,EAEtB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAU1D,4DAA4D;AAC5D,wBAAsB,QAAQ,CAAC,QAAQ,SAAS,MAAM,GAAG,SAAS,EACjE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EACpB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,iBAAiB,GACpB,OAAO,CAAC,eAAe,CAAC,CA+D1B;AAED,gEAAgE;AAChE,wBAAsB,aAAa,CAAC,QAAQ,SAAS,MAAM,GAAG,SAAS,EACtE,IAAI,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AAU,EAAE,CAAC;IACrE,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,gBAAgB;QAAE,OAAO,OAAO,CAAC,KAAK,CAAC;IAClE,IAAI,GAAG,CAAC,YAAY,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAC5C,MAAM,IAAI,qBAAqB,CAAC,4DAA4D,CAAC,CAAC;IAC/F,CAAC;IACD,OAAO,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAAA,CACrF","sourcesContent":["import { insertEntry } from \"../../session/commit.ts\";\nimport { SessionInvariantError } from \"../../session/session.ts\";\nimport {\n\ttype CheckpointOperation,\n\ttype MessageEntry,\n\ttype NewEntry,\n\toperationScopeOf,\n\ttype StartingOperation,\n\ttype SummaryDecidingOperation,\n} from \"../../session/types.ts\";\nimport { branchTip, operationPreparation, setValue } from \"../../session/values.ts\";\nimport type { Lane } from \"../lane.ts\";\nimport { chainEntries, committedEntryEvents } from \"../transcript.ts\";\nimport type { Drive, ProcedureResult } from \"../types.ts\";\nimport {\n\tassistantReadyAtBoundary,\n\ttype BoundaryFinishPending,\n\tboundaryPlacementEvents,\n\tfinishRunBoundary,\n\tplanBoundaryInbox,\n} from \"./boundary.ts\";\nimport { prepareCompactionThreshold } from \"./structural.ts\";\n\n/** Consume before_run and commit the initial checkpoint. */\nexport async function startRun<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\trun: StartingOperation,\n): Promise<ProcedureResult> {\n\tconst prompt = await lane.continueOperation(\n\t\trun,\n\t\tasync (_state, _current, meta, reader) => {\n\t\t\tif (meta.intent.kind !== \"run\") throw new SessionInvariantError(\"Run operation has non-run intent\");\n\t\t\tconst entries = await reader.getEntries(meta.intent.promptEntryIds, drive.context);\n\t\t\tconst messages = meta.intent.promptEntryIds.map((id) => {\n\t\t\t\tconst entry = entries.get(id);\n\t\t\t\tif (entry?.type !== \"message\") {\n\t\t\t\t\tthrow new SessionInvariantError(`Run prompt entry ${id} is missing its message`);\n\t\t\t\t}\n\t\t\t\treturn entry.message;\n\t\t\t});\n\t\t\treturn { kind: \"return\", result: messages };\n\t\t},\n\t\tdrive.context,\n\t);\n\tif (prompt.kind === \"cancel_requested\") return { kind: \"continue\" };\n\n\tconst hook = await lane.hooks.runWithGate(\n\t\t\"before_run\",\n\t\t{ lane: lane.name, runId: drive.operationId, prompt: prompt.value, resources: lane.readConfig().resources },\n\t\tdrive.gate,\n\t\tdrive.context,\n\t);\n\tconst injected = hook?.messages ?? [];\n\tfor (const message of injected) {\n\t\tif (message.role === \"assistant\" && message.stopReason === \"pending\") {\n\t\t\tthrow new SessionInvariantError(\"before_run returned a pending assistant message\");\n\t\t}\n\t}\n\tconst reserved = injected.map((message) => ({ id: lane.session.idGenerator.next(), message }));\n\n\tconst result = await lane.continueOperation(\n\t\trun,\n\t\t(state, current) => {\n\t\t\tconst entries: NewEntry<MessageEntry>[] = chainEntries(\n\t\t\t\tstate.tipId,\n\t\t\t\treserved.map(({ id, message }) => ({ id, type: \"message\" as const, message })),\n\t\t\t);\n\t\t\tconst triggerEntryId = entries.at(-1)?.id ?? state.tipId;\n\t\t\tif (triggerEntryId === null) throw new SessionInvariantError(\"Run start has no trigger entry\");\n\t\t\tconst nextState: CheckpointOperation = {\n\t\t\t\t...operationScopeOf(current),\n\t\t\t\tat: \"checkpoint\",\n\t\t\t\tcontinuation: { kind: \"need_assistant\", overflowRecoveryUsed: false },\n\t\t\t\ttriggerEntryId,\n\t\t\t};\n\t\t\treturn {\n\t\t\t\tkind: \"commit\",\n\t\t\t\twrites: [\n\t\t\t\t\t...entries.map((entry) => insertEntry(entry)),\n\t\t\t\t\t...(entries.length === 0 ? [] : [setValue(branchTip(lane.name), triggerEntryId)]),\n\t\t\t\t],\n\t\t\t\toperationState: nextState,\n\t\t\t\tlane: { tipId: triggerEntryId },\n\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\tevents: (commit) => committedEntryEvents(entries, commit, lane.name, drive.operationId),\n\t\t\t};\n\t\t},\n\t\tdrive.context,\n\t);\n\treturn result.kind === \"cancel_requested\" ? { kind: \"continue\" } : result.value;\n}\n\n/** Advance one durable run boundary with at most one commit. */\nexport async function runCheckpoint<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\trun: CheckpointOperation,\n): Promise<ProcedureResult> {\n\tconst threshold = await prepareCompactionThreshold(lane, drive, run);\n\tif (threshold.kind === \"cancel_requested\") return { kind: \"continue\" };\n\tconst planned = await lane.continueOperation<CheckpointOperation, ProcedureResult | BoundaryFinishPending>(\n\t\trun,\n\t\tasync (state, current, _meta, reader) => {\n\t\t\tconst placement = await planBoundaryInbox(\n\t\t\t\tlane,\n\t\t\t\tdrive,\n\t\t\t\tstate,\n\t\t\t\tcurrent,\n\t\t\t\treader,\n\t\t\t\tstate.tipId,\n\t\t\t\tthreshold.value === undefined && current.continuation.kind === \"may_finish\",\n\t\t\t);\n\t\t\tif (placement.triggerEntryId !== undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\twrites: placement.writes,\n\t\t\t\t\toperationState: assistantReadyAtBoundary(lane, state, current, placement.triggerEntryId, false),\n\t\t\t\t\tlane: { tipId: placement.tipId, inbox: placement.inbox },\n\t\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\t\tevents: (commit) => boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (threshold.value !== undefined) {\n\t\t\t\tconst structural: SummaryDecidingOperation = {\n\t\t\t\t\t...operationScopeOf(current),\n\t\t\t\t\tat: \"summary.deciding\",\n\t\t\t\t\ttask: {\n\t\t\t\t\t\ttaskId: threshold.value.taskId,\n\t\t\t\t\t\treason: \"threshold\",\n\t\t\t\t\t\tboundary: {\n\t\t\t\t\t\t\tkind: \"resume_checkpoint\",\n\t\t\t\t\t\t\tresumeAfter: { continuation: current.continuation, triggerEntryId: current.triggerEntryId },\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\twrites: [\n\t\t\t\t\t\t...placement.writes,\n\t\t\t\t\t\tsetValue(\n\t\t\t\t\t\t\toperationPreparation(drive.operationId, threshold.value.taskId),\n\t\t\t\t\t\t\tthreshold.value.preparation,\n\t\t\t\t\t\t),\n\t\t\t\t\t],\n\t\t\t\t\toperationState: structural,\n\t\t\t\t\tlane: { tipId: placement.tipId, inbox: placement.inbox },\n\t\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\t\tevents: (commit) => [\n\t\t\t\t\t\t...boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"compaction_start\",\n\t\t\t\t\t\t\tlane: lane.name,\n\t\t\t\t\t\t\trunId: drive.operationId,\n\t\t\t\t\t\t\treason: \"threshold\",\n\t\t\t\t\t\t\tstartedAt: commit.timestamp,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (current.continuation.kind === \"need_assistant\") {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\twrites: placement.writes,\n\t\t\t\t\toperationState: assistantReadyAtBoundary(\n\t\t\t\t\t\tlane,\n\t\t\t\t\t\tstate,\n\t\t\t\t\t\tcurrent,\n\t\t\t\t\t\tcurrent.triggerEntryId,\n\t\t\t\t\t\tcurrent.continuation.overflowRecoveryUsed,\n\t\t\t\t\t),\n\t\t\t\t\tlane: { tipId: placement.tipId, inbox: placement.inbox },\n\t\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\t\tevents: (commit) => boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: \"return\",\n\t\t\t\tresult: { kind: \"finish_pending\", entryIds: placement.entries.map((entry) => entry.id) } as const,\n\t\t\t};\n\t\t},\n\t\tdrive.context,\n\t);\n\tif (planned.kind === \"cancel_requested\") return { kind: \"continue\" };\n\tif (planned.value.kind !== \"finish_pending\") return planned.value;\n\tif (run.continuation.kind !== \"may_finish\") {\n\t\tthrow new SessionInvariantError(\"Checkpoint finish mediation requires a finish continuation\");\n\t}\n\treturn finishRunBoundary(lane, drive, run, run.continuation, planned.value.entryIds);\n}\n"]}
1
+ {"version":3,"file":"checkpoint.js","sourceRoot":"","sources":["../../../../src/harness/runtime/drive/checkpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAIN,gBAAgB,GAGhB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAEpF,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAEtE,OAAO,EACN,wBAAwB,EAExB,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,GACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAE7D,4DAA4D;AAC5D,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC7B,IAAoB,EACpB,KAAY,EACZ,GAAsB;IAEtB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAC1C,GAAG,EACH,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;QACxC,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,KAAK;YAAE,MAAM,IAAI,qBAAqB,CA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O,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,EAAW;SACjG,CAAC;IACH,CAAC,EACD,KAAK,CAAC,OAAO,CACb,CAAC;IACF,IAAI,OAAO,CAAC,IAAI,KAAK,kBAAkB;QAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;IACrE,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,gBAAgB;QAAE,OAAO,OAAO,CAAC,KAAK,CAAC;IAClE,IAAI,GAAG,CAAC,YAAY,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAC5C,MAAM,IAAI,qBAAqB,CAAC,4DAA4D,CAAC,CAAC;IAC/F,CAAC;IACD,OAAO,iBAAiB,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AACtF,CAAC","sourcesContent":["import { insertEntry } from \"../../session/commit.ts\";\nimport { SessionInvariantError } from \"../../session/session.ts\";\nimport {\n\ttype CheckpointOperation,\n\ttype MessageEntry,\n\ttype NewEntry,\n\toperationScopeOf,\n\ttype StartingOperation,\n\ttype SummaryDecidingOperation,\n} from \"../../session/types.ts\";\nimport { branchTip, operationPreparation, setValue } from \"../../session/values.ts\";\nimport type { Lane } from \"../lane.ts\";\nimport { chainEntries, committedEntryEvents } from \"../transcript.ts\";\nimport type { Drive, ProcedureResult } from \"../types.ts\";\nimport {\n\tassistantReadyAtBoundary,\n\ttype BoundaryFinishPending,\n\tboundaryPlacementEvents,\n\tfinishRunBoundary,\n\tplanBoundaryInbox,\n} from \"./boundary.ts\";\nimport { prepareCompactionThreshold } from \"./structural.ts\";\n\n/** Consume before_run and commit the initial checkpoint. */\nexport async function startRun<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\trun: StartingOperation,\n): Promise<ProcedureResult> {\n\tconst prompt = await lane.continueOperation(\n\t\trun,\n\t\tasync (_state, _current, meta, reader) => {\n\t\t\tif (meta.intent.kind !== \"run\") throw new SessionInvariantError(\"Run operation has non-run intent\");\n\t\t\tconst entries = await reader.getEntries(meta.intent.promptEntryIds, drive.context);\n\t\t\tconst messages = meta.intent.promptEntryIds.map((id) => {\n\t\t\t\tconst entry = entries.get(id);\n\t\t\t\tif (entry?.type !== \"message\") {\n\t\t\t\t\tthrow new SessionInvariantError(`Run prompt entry ${id} is missing its message`);\n\t\t\t\t}\n\t\t\t\treturn entry.message;\n\t\t\t});\n\t\t\treturn { kind: \"return\", result: messages };\n\t\t},\n\t\tdrive.context,\n\t);\n\tif (prompt.kind === \"cancel_requested\") return { kind: \"continue\" };\n\n\tconst hook = await lane.hooks.runWithGate(\n\t\t\"before_run\",\n\t\t{ lane: lane.name, runId: drive.operationId, prompt: prompt.value, resources: lane.readConfig().resources },\n\t\tdrive.gate,\n\t\tdrive.context,\n\t);\n\tconst injected = hook?.messages ?? [];\n\tfor (const message of injected) {\n\t\tif (message.role === \"assistant\" && message.stopReason === \"pending\") {\n\t\t\tthrow new SessionInvariantError(\"before_run returned a pending assistant message\");\n\t\t}\n\t}\n\tconst reserved = injected.map((message) => ({ id: lane.session.idGenerator.next(), message }));\n\n\tconst result = await lane.continueOperation(\n\t\trun,\n\t\t(state, current) => {\n\t\t\tconst entries: NewEntry<MessageEntry>[] = chainEntries(\n\t\t\t\tstate.tipId,\n\t\t\t\treserved.map(({ id, message }) => ({ id, type: \"message\" as const, message })),\n\t\t\t);\n\t\t\tconst triggerEntryId = entries.at(-1)?.id ?? state.tipId;\n\t\t\tif (triggerEntryId === null) throw new SessionInvariantError(\"Run start has no trigger entry\");\n\t\t\tconst nextState: CheckpointOperation = {\n\t\t\t\t...operationScopeOf(current),\n\t\t\t\tat: \"checkpoint\",\n\t\t\t\tcontinuation: { kind: \"need_assistant\", overflowRecoveryUsed: false },\n\t\t\t\ttriggerEntryId,\n\t\t\t};\n\t\t\treturn {\n\t\t\t\tkind: \"commit\",\n\t\t\t\twrites: [\n\t\t\t\t\t...entries.map((entry) => insertEntry(entry)),\n\t\t\t\t\t...(entries.length === 0 ? [] : [setValue(branchTip(lane.name), triggerEntryId)]),\n\t\t\t\t],\n\t\t\t\toperationState: nextState,\n\t\t\t\tlane: { tipId: triggerEntryId },\n\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\tevents: (commit) => committedEntryEvents(entries, commit, lane.name, drive.operationId),\n\t\t\t};\n\t\t},\n\t\tdrive.context,\n\t);\n\treturn result.kind === \"cancel_requested\" ? { kind: \"continue\" } : result.value;\n}\n\n/** Advance one durable run boundary with at most one commit. */\nexport async function runCheckpoint<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\trun: CheckpointOperation,\n): Promise<ProcedureResult> {\n\tconst threshold = await prepareCompactionThreshold(lane, drive, run);\n\tif (threshold.kind === \"cancel_requested\") return { kind: \"continue\" };\n\tconst planned = await lane.continueOperation<CheckpointOperation, ProcedureResult | BoundaryFinishPending>(\n\t\trun,\n\t\tasync (state, current, _meta, reader) => {\n\t\t\tconst placement = await planBoundaryInbox(\n\t\t\t\tlane,\n\t\t\t\tdrive,\n\t\t\t\tstate,\n\t\t\t\tcurrent,\n\t\t\t\treader,\n\t\t\t\tstate.tipId,\n\t\t\t\tthreshold.value === undefined && current.continuation.kind === \"may_finish\",\n\t\t\t);\n\t\t\tif (placement.triggerEntryId !== undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\twrites: placement.writes,\n\t\t\t\t\toperationState: assistantReadyAtBoundary(lane, state, current, placement.triggerEntryId, false),\n\t\t\t\t\tlane: { tipId: placement.tipId, inbox: placement.inbox },\n\t\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\t\tevents: (commit) => boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (threshold.value !== undefined) {\n\t\t\t\tconst structural: SummaryDecidingOperation = {\n\t\t\t\t\t...operationScopeOf(current),\n\t\t\t\t\tat: \"summary.deciding\",\n\t\t\t\t\ttask: {\n\t\t\t\t\t\ttaskId: threshold.value.taskId,\n\t\t\t\t\t\treason: \"threshold\",\n\t\t\t\t\t\tboundary: {\n\t\t\t\t\t\t\tkind: \"resume_checkpoint\",\n\t\t\t\t\t\t\tresumeAfter: { continuation: current.continuation, triggerEntryId: current.triggerEntryId },\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\twrites: [\n\t\t\t\t\t\t...placement.writes,\n\t\t\t\t\t\tsetValue(\n\t\t\t\t\t\t\toperationPreparation(drive.operationId, threshold.value.taskId),\n\t\t\t\t\t\t\tthreshold.value.preparation,\n\t\t\t\t\t\t),\n\t\t\t\t\t],\n\t\t\t\t\toperationState: structural,\n\t\t\t\t\tlane: { tipId: placement.tipId, inbox: placement.inbox },\n\t\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\t\tevents: (commit) => [\n\t\t\t\t\t\t...boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"compaction_start\",\n\t\t\t\t\t\t\tlane: lane.name,\n\t\t\t\t\t\t\trunId: drive.operationId,\n\t\t\t\t\t\t\treason: \"threshold\",\n\t\t\t\t\t\t\tstartedAt: commit.timestamp,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t};\n\t\t\t}\n\t\t\tif (current.continuation.kind === \"need_assistant\") {\n\t\t\t\treturn {\n\t\t\t\t\tkind: \"commit\",\n\t\t\t\t\twrites: placement.writes,\n\t\t\t\t\toperationState: assistantReadyAtBoundary(\n\t\t\t\t\t\tlane,\n\t\t\t\t\t\tstate,\n\t\t\t\t\t\tcurrent,\n\t\t\t\t\t\tcurrent.triggerEntryId,\n\t\t\t\t\t\tcurrent.continuation.overflowRecoveryUsed,\n\t\t\t\t\t),\n\t\t\t\t\tlane: { tipId: placement.tipId, inbox: placement.inbox },\n\t\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\t\tevents: (commit) => boundaryPlacementEvents(placement, commit, 0, lane.name, drive.operationId),\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tkind: \"return\",\n\t\t\t\tresult: { kind: \"finish_pending\", entryIds: placement.entries.map((entry) => entry.id) } as const,\n\t\t\t};\n\t\t},\n\t\tdrive.context,\n\t);\n\tif (planned.kind === \"cancel_requested\") return { kind: \"continue\" };\n\tif (planned.value.kind !== \"finish_pending\") return planned.value;\n\tif (run.continuation.kind !== \"may_finish\") {\n\t\tthrow new SessionInvariantError(\"Checkpoint finish mediation requires a finish continuation\");\n\t}\n\treturn finishRunBoundary(lane, drive, run, run.continuation, planned.value.entryIds);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"deferred.d.ts","sourceRoot":"","sources":["../../../../src/harness/runtime/drive/deferred.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAO,cAAc,EAAS,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAAE,KAAK,OAAO,EAAwC,MAAM,kBAAkB,CAAC;AAItF,OAAO,EACN,KAAK,8BAA8B,EACnC,KAAK,0BAA0B,EAK/B,KAAK,aAAa,EAElB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAA2B,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGnF,KAAK,YAAY,GAAG,0BAA0B,GAAG,8BAA8B,CAAC;AA0BhF,wBAAsB,wBAAwB,CAC7C,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,OAAO,GACd,OAAO,CAAC,cAAc,CAAC,CAqBzB;AA2LD,oFAAoF;AACpF,wBAAgB,oBAAoB,CAAC,QAAQ,SAAS,MAAM,GAAG,SAAS,EACvE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EACpB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,0BAA0B,GAClC,OAAO,CAAC,eAAe,CAAC,CAE1B;AAED,iGAAiG;AACjG,wBAAgB,mBAAmB,CAAC,QAAQ,SAAS,MAAM,GAAG,SAAS,EACtE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EACpB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,8BAA8B,GACtC,OAAO,CAAC,eAAe,CAAC,CAE1B;AAED,6DAA6D;AAC7D,wBAAgB,WAAW,CAAC,QAAQ,SAAS,MAAM,GAAG,SAAS,EAC9D,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EACpB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,0BAA0B,GAAG,8BAA8B,GACnE,OAAO,CAAC,eAAe,CAAC,CAI1B","sourcesContent":["import type { Api, DeferredHandle, Model } from \"@earendil-works/pi-ai\";\nimport { type Context, getTelemetryContext, withAbortSignal } from \"../../context.ts\";\nimport { consumeAssistantStream } from \"../../execution/assistant.ts\";\nimport { applyStreamOptionsPatch } from \"../../hooks.ts\";\nimport { SessionInvariantError } from \"../../session/session.ts\";\nimport {\n\ttype DeferredEffectPendingOperation,\n\ttype DeferredSuspendedOperation,\n\ttype LaneConfiguration,\n\ttype OperationError,\n\ttype OperationScope,\n\toperationScopeOf,\n\ttype SessionReader,\n\ttype SettledAssistantMessage,\n} from \"../../session/types.ts\";\nimport { deleteList, pendingAssistantFrames } from \"../../session/values.ts\";\nimport type { AgentHarnessStreamOptions } from \"../../types.ts\";\nimport type { Lane } from \"../lane.ts\";\nimport type { ContinueOperationResult, Drive, ProcedureResult } from \"../types.ts\";\nimport { openAssistantResponse, publishConfigurationFailure, publishResponse } from \"./response.ts\";\n\ntype DeferredLeaf = DeferredSuspendedOperation | DeferredEffectPendingOperation;\n/** Deferred effect payload without the run-wide scope fields. */\ntype EffectPendingFields = Omit<DeferredEffectPendingOperation, keyof OperationScope>;\n\ntype PreparedDeferredPoll = {\n\tkind: \"ready\";\n\tsource: DeferredHandle;\n\tmodel: Model<Api>;\n\tpoll: number;\n\tstreamOptions: AgentHarnessStreamOptions;\n};\n\ntype DeferredPreparation =\n\t| PreparedDeferredPoll\n\t| { kind: \"cancel_requested\" }\n\t| { kind: \"waiting\"; source: DeferredHandle }\n\t| { kind: \"configuration_failure\" };\n\nfunction configurationError(identity: LaneConfiguration[\"model\"]): OperationError {\n\treturn {\n\t\tcode: \"model_unavailable\",\n\t\tmessage: \"The configured model is unavailable in this process\",\n\t\tdetails: identity,\n\t};\n}\n\nexport async function readDeferredSourceHandle(\n\treader: SessionReader,\n\tdeferred: DeferredLeaf,\n\tcontext: Context,\n): Promise<DeferredHandle> {\n\tconst source = (await reader.getEntries([deferred.sourceEntryId], context)).get(deferred.sourceEntryId);\n\tif (\n\t\tsource?.type !== \"message\" ||\n\t\tsource.message.role !== \"assistant\" ||\n\t\tsource.message.stopReason !== \"deferred\" ||\n\t\tsource.message.deferred === undefined\n\t) {\n\t\tthrow new SessionInvariantError(`Deferred source ${deferred.sourceEntryId} is missing its assistant handle`);\n\t}\n\tconst handle = source.message.deferred;\n\tconst identity = deferred.configuration.model;\n\tif (\n\t\thandle.id.length === 0 ||\n\t\thandle.provider !== identity.provider ||\n\t\thandle.modelId !== identity.modelId ||\n\t\thandle.api !== source.message.api\n\t) {\n\t\tthrow new SessionInvariantError(`Deferred source ${deferred.sourceEntryId} has an invalid handle`);\n\t}\n\treturn handle;\n}\n\nasync function readSourceHandle<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tdeferred: DeferredLeaf,\n): Promise<ContinueOperationResult<DeferredHandle>> {\n\treturn lane.continueOperation(\n\t\tdeferred,\n\t\tasync (_state, _current, _meta, reader) => ({\n\t\t\tkind: \"return\",\n\t\t\tresult: await readDeferredSourceHandle(reader, deferred, drive.context),\n\t\t}),\n\t\tdrive.context,\n\t);\n}\n\nasync function prepareDeferredPoll<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\texpected: DeferredLeaf,\n): Promise<DeferredPreparation> {\n\tconst source = await readSourceHandle(lane, drive, expected);\n\tif (source.kind === \"cancel_requested\") return source;\n\tif (drive.deferredPermits === 0) return { kind: \"waiting\", source: source.value };\n\n\tconst identity = expected.configuration.model;\n\tconst model = lane.models.getModel(identity.provider, identity.modelId);\n\tif (model === undefined) return { kind: \"configuration_failure\" };\n\tconst baseOptions: AgentHarnessStreamOptions = { ...expected.streamOptions, deferred: false };\n\tconst poll = expected.at === \"deferred.suspended\" ? expected.poll + 1 : expected.poll;\n\tconst beforeRequest = await lane.hooks.runWithGate(\n\t\t\"before_request\",\n\t\t{\n\t\t\tlane: lane.name,\n\t\t\trunId: drive.operationId,\n\t\t\tmodel,\n\t\t\tstep: \"deferred\",\n\t\t\tattempt: poll,\n\t\t\tstreamOptions: baseOptions,\n\t\t},\n\t\tdrive.gate,\n\t\tdrive.context,\n\t);\n\treturn {\n\t\tkind: \"ready\",\n\t\tsource: source.value,\n\t\tmodel,\n\t\tpoll,\n\t\tstreamOptions: {\n\t\t\t...(beforeRequest?.streamOptions === undefined\n\t\t\t\t? baseOptions\n\t\t\t\t: applyStreamOptionsPatch(baseOptions, beforeRequest.streamOptions)),\n\t\t\tdeferred: false,\n\t\t},\n\t};\n}\n\nasync function publishPollIntent<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tdeferred: DeferredLeaf,\n\tprepared: PreparedDeferredPoll,\n\trecovery: boolean,\n): Promise<ContinueOperationResult<DeferredEffectPendingOperation>> {\n\tconst at = Date.now();\n\tconst next: EffectPendingFields = {\n\t\tat: \"deferred.effect_pending\",\n\t\tstepId: deferred.stepId,\n\t\tsourceEntryId: deferred.sourceEntryId,\n\t\tpoll: prepared.poll,\n\t\tresponseEntryId: lane.session.idGenerator.next(at),\n\t\tusageId: lane.session.idGenerator.next(at),\n\t\tconfiguration: deferred.configuration,\n\t\tstreamOptions: deferred.streamOptions,\n\t};\n\treturn lane.continueOperation(\n\t\tdeferred,\n\t\t(_state, current) => {\n\t\t\tconst nextState: DeferredEffectPendingOperation = { ...operationScopeOf(current), ...next };\n\t\t\treturn {\n\t\t\t\tkind: \"commit\",\n\t\t\t\twrites:\n\t\t\t\t\tdeferred.at === \"deferred.effect_pending\"\n\t\t\t\t\t\t? [deleteList(pendingAssistantFrames(drive.operationId, deferred.responseEntryId))]\n\t\t\t\t\t\t: [],\n\t\t\t\toperationState: nextState,\n\t\t\t\tmaterialize: () => {\n\t\t\t\t\tdrive.deferredPermits--;\n\t\t\t\t\treturn nextState;\n\t\t\t\t},\n\t\t\t\tevents: () => [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"run_resume\",\n\t\t\t\t\t\tlane: lane.name,\n\t\t\t\t\t\trunId: drive.operationId,\n\t\t\t\t\t\t...(recovery ? { recovery: true as const } : {}),\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"turn_start\",\n\t\t\t\t\t\tlane: lane.name,\n\t\t\t\t\t\trunId: drive.operationId,\n\t\t\t\t\t\tturnId: `${next.stepId}:poll:${next.poll}`,\n\t\t\t\t\t\t...(recovery ? { recovery: true as const } : {}),\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t},\n\t\tdrive.context,\n\t);\n}\n\nasync function performDeferredPoll<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tprepared: PreparedDeferredPoll,\n\tintent: DeferredEffectPendingOperation,\n\trecovery: boolean,\n): Promise<SettledAssistantMessage> {\n\tconst response = openAssistantResponse(lane, drive, intent.responseEntryId, recovery);\n\tlet metadata: { status?: number; headers?: Record<string, string> } = {};\n\tconst admitted = withAbortSignal(drive.gate.signal, drive.context);\n\tconst stream = drive.gate.admit(() =>\n\t\tlane.models.streamDeferred(prepared.model, prepared.source, {\n\t\t\twait: 0,\n\t\t\tsignal: admitted.abortSignal,\n\t\t\ttelemetryContext: getTelemetryContext(admitted),\n\t\t\ttimeoutMs: prepared.streamOptions.timeoutMs,\n\t\t\tmaxRetries: prepared.streamOptions.maxRetries,\n\t\t\tmaxRetryDelayMs: prepared.streamOptions.maxRetryDelayMs,\n\t\t\theaders: prepared.streamOptions.headers,\n\t\t\tonPayload: async (payload, requestModel) => {\n\t\t\t\tconst result = await lane.hooks.runWithGate(\n\t\t\t\t\t\"before_payload\",\n\t\t\t\t\t{ lane: lane.name, runId: drive.operationId, model: requestModel, payload },\n\t\t\t\t\tdrive.gate,\n\t\t\t\t\tdrive.context,\n\t\t\t\t);\n\t\t\t\treturn result?.payload;\n\t\t\t},\n\t\t\tonResponse: (response) => {\n\t\t\t\tmetadata = { status: response.status, headers: response.headers };\n\t\t\t},\n\t\t}),\n\t);\n\n\ttry {\n\t\treturn await consumeAssistantStream(\n\t\t\tstream,\n\t\t\tresponse.observer,\n\t\t\t(message, context) => response.afterResponse(message, metadata, context),\n\t\t\tdrive.context,\n\t\t);\n\t} finally {\n\t\tawait response.close();\n\t}\n}\n\nasync function pollDeferred<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\texpected: DeferredLeaf,\n\trecovery: boolean,\n): Promise<ProcedureResult> {\n\tconst prepared = await prepareDeferredPoll(lane, drive, expected);\n\tif (prepared.kind === \"cancel_requested\") return { kind: \"continue\" };\n\tif (prepared.kind === \"waiting\") {\n\t\treturn {\n\t\t\tkind: \"waiting\",\n\t\t\toutcome: {\n\t\t\t\tkind: \"waiting\",\n\t\t\t\toperationId: drive.operationId,\n\t\t\t\treason: \"deferred\",\n\t\t\t\tdeferred: prepared.source,\n\t\t\t},\n\t\t};\n\t}\n\tif (prepared.kind === \"configuration_failure\") {\n\t\treturn publishConfigurationFailure(lane, drive, expected, configurationError(expected.configuration.model));\n\t}\n\n\tconst intent = await publishPollIntent(lane, drive, expected, prepared, recovery);\n\tif (intent.kind === \"cancel_requested\") return { kind: \"continue\" };\n\tconst response = await performDeferredPoll(lane, drive, prepared, intent.value, recovery);\n\treturn publishResponse(lane, drive, intent.value, response, recovery ? { recovery: true } : {});\n}\n\n/** Poll one durably suspended deferred response when this pass carries a permit. */\nexport function runDeferredSuspended<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tdeferred: DeferredSuspendedOperation,\n): Promise<ProcedureResult> {\n\treturn pollDeferred(lane, drive, deferred, false);\n}\n\n/** Replace one orphaned unknown-outcome poll under fresh ids when this pass carries a permit. */\nexport function recoverDeferredPoll<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tdeferred: DeferredEffectPendingOperation,\n): Promise<ProcedureResult> {\n\treturn pollDeferred(lane, drive, deferred, true);\n}\n\n/** Advance or report the wait for one deferred run phase. */\nexport function runDeferred<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tdeferred: DeferredSuspendedOperation | DeferredEffectPendingOperation,\n): Promise<ProcedureResult> {\n\treturn deferred.at === \"deferred.suspended\"\n\t\t? runDeferredSuspended(lane, drive, deferred)\n\t\t: recoverDeferredPoll(lane, drive, deferred);\n}\n"]}
1
+ {"version":3,"file":"deferred.d.ts","sourceRoot":"","sources":["../../../../src/harness/runtime/drive/deferred.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAO,cAAc,EAAS,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAAE,KAAK,OAAO,EAAwC,MAAM,kBAAkB,CAAC;AAItF,OAAO,EACN,KAAK,8BAA8B,EACnC,KAAK,0BAA0B,EAK/B,KAAK,aAAa,EAElB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,EAA2B,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGn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CAAC,IAAI,KAAK,kBAAkB;QAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;IACpE,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC1F,OAAO,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAAA,CAChG;AAED,oFAAoF;AACpF,MAAM,UAAU,oBAAoB,CACnC,IAAoB,EACpB,KAAY,EACZ,QAAoC,EACT;IAC3B,OAAO,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;AAAA,CAClD;AAED,iGAAiG;AACjG,MAAM,UAAU,mBAAmB,CAClC,IAAoB,EACpB,KAAY,EACZ,QAAwC,EACb;IAC3B,OAAO,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;AAAA,CACjD;AAED,6DAA6D;AAC7D,MAAM,UAAU,WAAW,CAC1B,IAAoB,EACpB,KAAY,EACZ,QAAqE,EAC1C;IAC3B,OAAO,QAAQ,CAAC,EAAE,KAAK,oBAAoB;QAC1C,CAAC,CAAC,oBAAoB,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC;QAC7C,CAAC,CAAC,mBAAmB,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AAAA,CAC9C","sourcesContent":["import type { Api, DeferredHandle, Model } from \"@earendil-works/pi-ai\";\nimport { type Context, getTelemetryContext, withAbortSignal } from \"../../context.ts\";\nimport { consumeAssistantStream } from \"../../execution/assistant.ts\";\nimport { applyStreamOptionsPatch } from \"../../hooks.ts\";\nimport { SessionInvariantError } from \"../../session/session.ts\";\nimport {\n\ttype DeferredEffectPendingOperation,\n\ttype DeferredSuspendedOperation,\n\ttype LaneConfiguration,\n\ttype OperationError,\n\ttype OperationScope,\n\toperationScopeOf,\n\ttype SessionReader,\n\ttype SettledAssistantMessage,\n} from \"../../session/types.ts\";\nimport { deleteList, pendingAssistantFrames } from \"../../session/values.ts\";\nimport type { AgentHarnessStreamOptions } from \"../../types.ts\";\nimport type { Lane } from \"../lane.ts\";\nimport type { ContinueOperationResult, Drive, ProcedureResult } from \"../types.ts\";\nimport { openAssistantResponse, publishConfigurationFailure, publishResponse } from \"./response.ts\";\n\ntype DeferredLeaf = DeferredSuspendedOperation | DeferredEffectPendingOperation;\n/** Deferred effect payload without the run-wide scope fields. */\ntype EffectPendingFields = Omit<DeferredEffectPendingOperation, keyof OperationScope>;\n\ntype PreparedDeferredPoll = {\n\tkind: \"ready\";\n\tsource: DeferredHandle;\n\tmodel: Model<Api>;\n\tpoll: number;\n\tstreamOptions: AgentHarnessStreamOptions;\n};\n\ntype DeferredPreparation =\n\t| PreparedDeferredPoll\n\t| { kind: \"cancel_requested\" }\n\t| { kind: \"waiting\"; source: DeferredHandle }\n\t| { kind: \"configuration_failure\" };\n\nfunction configurationError(identity: LaneConfiguration[\"model\"]): OperationError {\n\treturn {\n\t\tcode: \"model_unavailable\",\n\t\tmessage: \"The configured model is unavailable in this process\",\n\t\tdetails: identity,\n\t};\n}\n\nexport async function readDeferredSourceHandle(\n\treader: SessionReader,\n\tdeferred: DeferredLeaf,\n\tcontext: Context,\n): Promise<DeferredHandle> {\n\tconst source = (await reader.getEntries([deferred.sourceEntryId], context)).get(deferred.sourceEntryId);\n\tif (\n\t\tsource?.type !== \"message\" ||\n\t\tsource.message.role !== \"assistant\" ||\n\t\tsource.message.stopReason !== \"deferred\" ||\n\t\tsource.message.deferred === undefined\n\t) {\n\t\tthrow new SessionInvariantError(`Deferred source ${deferred.sourceEntryId} is missing its assistant handle`);\n\t}\n\tconst handle = source.message.deferred;\n\tconst identity = deferred.configuration.model;\n\tif (\n\t\thandle.id.length === 0 ||\n\t\thandle.provider !== identity.provider ||\n\t\thandle.modelId !== identity.modelId ||\n\t\thandle.api !== source.message.api\n\t) {\n\t\tthrow new SessionInvariantError(`Deferred source ${deferred.sourceEntryId} has an invalid handle`);\n\t}\n\treturn handle;\n}\n\nasync function readSourceHandle<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tdeferred: DeferredLeaf,\n): Promise<ContinueOperationResult<DeferredHandle>> {\n\treturn lane.continueOperation(\n\t\tdeferred,\n\t\tasync (_state, _current, _meta, reader) => ({\n\t\t\tkind: \"return\",\n\t\t\tresult: await readDeferredSourceHandle(reader, deferred, drive.context),\n\t\t}),\n\t\tdrive.context,\n\t);\n}\n\nasync function prepareDeferredPoll<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\texpected: DeferredLeaf,\n): Promise<DeferredPreparation> {\n\tconst source = await readSourceHandle(lane, drive, expected);\n\tif (source.kind === \"cancel_requested\") return source;\n\tif (drive.deferredPermits === 0) return { kind: \"waiting\", source: source.value };\n\n\tconst identity = expected.configuration.model;\n\tconst model = lane.models.getModel(identity.provider, identity.modelId);\n\tif (model === undefined) return { kind: \"configuration_failure\" };\n\tconst baseOptions: AgentHarnessStreamOptions = { ...expected.streamOptions, deferred: false };\n\tconst poll = expected.at === \"deferred.suspended\" ? expected.poll + 1 : expected.poll;\n\tconst beforeRequest = await lane.hooks.runWithGate(\n\t\t\"before_request\",\n\t\t{\n\t\t\tlane: lane.name,\n\t\t\trunId: drive.operationId,\n\t\t\tmodel,\n\t\t\tstep: \"deferred\",\n\t\t\tattempt: poll,\n\t\t\tstreamOptions: baseOptions,\n\t\t},\n\t\tdrive.gate,\n\t\tdrive.context,\n\t);\n\treturn {\n\t\tkind: \"ready\",\n\t\tsource: source.value,\n\t\tmodel,\n\t\tpoll,\n\t\tstreamOptions: {\n\t\t\t...(beforeRequest?.streamOptions === undefined\n\t\t\t\t? baseOptions\n\t\t\t\t: applyStreamOptionsPatch(baseOptions, beforeRequest.streamOptions)),\n\t\t\tdeferred: false,\n\t\t},\n\t};\n}\n\nasync function publishPollIntent<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tdeferred: DeferredLeaf,\n\tprepared: PreparedDeferredPoll,\n\trecovery: boolean,\n): Promise<ContinueOperationResult<DeferredEffectPendingOperation>> {\n\tconst at = Date.now();\n\tconst next: EffectPendingFields = {\n\t\tat: \"deferred.effect_pending\",\n\t\tstepId: deferred.stepId,\n\t\tsourceEntryId: deferred.sourceEntryId,\n\t\tpoll: prepared.poll,\n\t\tresponseEntryId: lane.session.idGenerator.next(at),\n\t\tusageId: lane.session.idGenerator.next(at),\n\t\tconfiguration: deferred.configuration,\n\t\tstreamOptions: deferred.streamOptions,\n\t};\n\treturn lane.continueOperation(\n\t\tdeferred,\n\t\t(_state, current) => {\n\t\t\tconst nextState: DeferredEffectPendingOperation = { ...operationScopeOf(current), ...next };\n\t\t\treturn {\n\t\t\t\tkind: \"commit\",\n\t\t\t\twrites:\n\t\t\t\t\tdeferred.at === \"deferred.effect_pending\"\n\t\t\t\t\t\t? [deleteList(pendingAssistantFrames(drive.operationId, deferred.responseEntryId))]\n\t\t\t\t\t\t: [],\n\t\t\t\toperationState: nextState,\n\t\t\t\tmaterialize: () => {\n\t\t\t\t\tdrive.deferredPermits--;\n\t\t\t\t\treturn nextState;\n\t\t\t\t},\n\t\t\t\tevents: () => [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"run_resume\",\n\t\t\t\t\t\tlane: lane.name,\n\t\t\t\t\t\trunId: drive.operationId,\n\t\t\t\t\t\t...(recovery ? { recovery: true as const } : {}),\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"turn_start\",\n\t\t\t\t\t\tlane: lane.name,\n\t\t\t\t\t\trunId: drive.operationId,\n\t\t\t\t\t\tturnId: `${next.stepId}:poll:${next.poll}`,\n\t\t\t\t\t\t...(recovery ? { recovery: true as const } : {}),\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t},\n\t\tdrive.context,\n\t);\n}\n\nasync function performDeferredPoll<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tprepared: PreparedDeferredPoll,\n\tintent: DeferredEffectPendingOperation,\n\trecovery: boolean,\n): Promise<SettledAssistantMessage> {\n\tconst response = openAssistantResponse(lane, drive, intent.responseEntryId, recovery);\n\tlet metadata: { status?: number; headers?: Record<string, string> } = {};\n\tconst admitted = withAbortSignal(drive.gate.signal, drive.context);\n\tconst stream = drive.gate.admit(() =>\n\t\tlane.models.streamDeferred(prepared.model, prepared.source, {\n\t\t\twait: 0,\n\t\t\tsignal: admitted.abortSignal,\n\t\t\ttelemetryContext: getTelemetryContext(admitted),\n\t\t\ttimeoutMs: prepared.streamOptions.timeoutMs,\n\t\t\tmaxRetries: prepared.streamOptions.maxRetries,\n\t\t\tmaxRetryDelayMs: prepared.streamOptions.maxRetryDelayMs,\n\t\t\theaders: prepared.streamOptions.headers,\n\t\t\tonPayload: async (payload, requestModel) => {\n\t\t\t\tconst result = await lane.hooks.runWithGate(\n\t\t\t\t\t\"before_payload\",\n\t\t\t\t\t{ lane: lane.name, runId: drive.operationId, model: requestModel, payload },\n\t\t\t\t\tdrive.gate,\n\t\t\t\t\tdrive.context,\n\t\t\t\t);\n\t\t\t\treturn result?.payload;\n\t\t\t},\n\t\t\tonResponse: (response) => {\n\t\t\t\tmetadata = { status: response.status, headers: response.headers };\n\t\t\t},\n\t\t}),\n\t);\n\n\ttry {\n\t\treturn await consumeAssistantStream(\n\t\t\tstream,\n\t\t\tresponse.observer,\n\t\t\t(message, context) => response.afterResponse(message, metadata, context),\n\t\t\tdrive.context,\n\t\t);\n\t} finally {\n\t\tawait response.close();\n\t}\n}\n\nasync function pollDeferred<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\texpected: DeferredLeaf,\n\trecovery: boolean,\n): Promise<ProcedureResult> {\n\tconst prepared = await prepareDeferredPoll(lane, drive, expected);\n\tif (prepared.kind === \"cancel_requested\") return { kind: \"continue\" };\n\tif (prepared.kind === \"waiting\") {\n\t\treturn {\n\t\t\tkind: \"waiting\",\n\t\t\toutcome: {\n\t\t\t\tkind: \"waiting\",\n\t\t\t\toperationId: drive.operationId,\n\t\t\t\treason: \"deferred\",\n\t\t\t\tdeferred: prepared.source,\n\t\t\t},\n\t\t};\n\t}\n\tif (prepared.kind === \"configuration_failure\") {\n\t\treturn publishConfigurationFailure(lane, drive, expected, configurationError(expected.configuration.model));\n\t}\n\n\tconst intent = await publishPollIntent(lane, drive, expected, prepared, recovery);\n\tif (intent.kind === \"cancel_requested\") return { kind: \"continue\" };\n\tconst response = await performDeferredPoll(lane, drive, prepared, intent.value, recovery);\n\treturn publishResponse(lane, drive, intent.value, response, recovery ? { recovery: true } : {});\n}\n\n/** Poll one durably suspended deferred response when this pass carries a permit. */\nexport function runDeferredSuspended<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tdeferred: DeferredSuspendedOperation,\n): Promise<ProcedureResult> {\n\treturn pollDeferred(lane, drive, deferred, false);\n}\n\n/** Replace one orphaned unknown-outcome poll under fresh ids when this pass carries a permit. */\nexport function recoverDeferredPoll<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tdeferred: DeferredEffectPendingOperation,\n): Promise<ProcedureResult> {\n\treturn pollDeferred(lane, drive, deferred, true);\n}\n\n/** Advance or report the wait for one deferred run phase. */\nexport function runDeferred<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tdeferred: DeferredSuspendedOperation | DeferredEffectPendingOperation,\n): Promise<ProcedureResult> {\n\treturn deferred.at === \"deferred.suspended\"\n\t\t? runDeferredSuspended(lane, drive, deferred)\n\t\t: recoverDeferredPoll(lane, drive, deferred);\n}\n"]}
1
+ {"version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AK,EAAE,QAAQ,CAAC;QAC7C,CAAC,CAAC,mBAAmB,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["import type { Api, DeferredHandle, Model } from \"@earendil-works/pi-ai\";\nimport { type Context, getTelemetryContext, withAbortSignal } from \"../../context.ts\";\nimport { consumeAssistantStream } from \"../../execution/assistant.ts\";\nimport { applyStreamOptionsPatch } from \"../../hooks.ts\";\nimport { SessionInvariantError } from \"../../session/session.ts\";\nimport {\n\ttype DeferredEffectPendingOperation,\n\ttype DeferredSuspendedOperation,\n\ttype LaneConfiguration,\n\ttype OperationError,\n\ttype OperationScope,\n\toperationScopeOf,\n\ttype SessionReader,\n\ttype SettledAssistantMessage,\n} from \"../../session/types.ts\";\nimport { deleteList, pendingAssistantFrames } from \"../../session/values.ts\";\nimport type { AgentHarnessStreamOptions } from \"../../types.ts\";\nimport type { Lane } from \"../lane.ts\";\nimport type { ContinueOperationResult, Drive, ProcedureResult } from \"../types.ts\";\nimport { openAssistantResponse, publishConfigurationFailure, publishResponse } from \"./response.ts\";\n\ntype DeferredLeaf = DeferredSuspendedOperation | DeferredEffectPendingOperation;\n/** Deferred effect payload without the run-wide scope fields. */\ntype EffectPendingFields = Omit<DeferredEffectPendingOperation, keyof OperationScope>;\n\ntype PreparedDeferredPoll = {\n\tkind: \"ready\";\n\tsource: DeferredHandle;\n\tmodel: Model<Api>;\n\tpoll: number;\n\tstreamOptions: AgentHarnessStreamOptions;\n};\n\ntype DeferredPreparation =\n\t| PreparedDeferredPoll\n\t| { kind: \"cancel_requested\" }\n\t| { kind: \"waiting\"; source: DeferredHandle }\n\t| { kind: \"configuration_failure\" };\n\nfunction configurationError(identity: LaneConfiguration[\"model\"]): OperationError {\n\treturn {\n\t\tcode: \"model_unavailable\",\n\t\tmessage: \"The configured model is unavailable in this process\",\n\t\tdetails: identity,\n\t};\n}\n\nexport async function readDeferredSourceHandle(\n\treader: SessionReader,\n\tdeferred: DeferredLeaf,\n\tcontext: Context,\n): Promise<DeferredHandle> {\n\tconst source = (await reader.getEntries([deferred.sourceEntryId], context)).get(deferred.sourceEntryId);\n\tif (\n\t\tsource?.type !== \"message\" ||\n\t\tsource.message.role !== \"assistant\" ||\n\t\tsource.message.stopReason !== \"deferred\" ||\n\t\tsource.message.deferred === undefined\n\t) {\n\t\tthrow new SessionInvariantError(`Deferred source ${deferred.sourceEntryId} is missing its assistant handle`);\n\t}\n\tconst handle = source.message.deferred;\n\tconst identity = deferred.configuration.model;\n\tif (\n\t\thandle.id.length === 0 ||\n\t\thandle.provider !== identity.provider ||\n\t\thandle.modelId !== identity.modelId ||\n\t\thandle.api !== source.message.api\n\t) {\n\t\tthrow new SessionInvariantError(`Deferred source ${deferred.sourceEntryId} has an invalid handle`);\n\t}\n\treturn handle;\n}\n\nasync function readSourceHandle<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tdeferred: DeferredLeaf,\n): Promise<ContinueOperationResult<DeferredHandle>> {\n\treturn lane.continueOperation(\n\t\tdeferred,\n\t\tasync (_state, _current, _meta, reader) => ({\n\t\t\tkind: \"return\",\n\t\t\tresult: await readDeferredSourceHandle(reader, deferred, drive.context),\n\t\t}),\n\t\tdrive.context,\n\t);\n}\n\nasync function prepareDeferredPoll<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\texpected: DeferredLeaf,\n): Promise<DeferredPreparation> {\n\tconst source = await readSourceHandle(lane, drive, expected);\n\tif (source.kind === \"cancel_requested\") return source;\n\tif (drive.deferredPermits === 0) return { kind: \"waiting\", source: source.value };\n\n\tconst identity = expected.configuration.model;\n\tconst model = lane.models.getModel(identity.provider, identity.modelId);\n\tif (model === undefined) return { kind: \"configuration_failure\" };\n\tconst baseOptions: AgentHarnessStreamOptions = { ...expected.streamOptions, deferred: false };\n\tconst poll = expected.at === \"deferred.suspended\" ? expected.poll + 1 : expected.poll;\n\tconst beforeRequest = await lane.hooks.runWithGate(\n\t\t\"before_request\",\n\t\t{\n\t\t\tlane: lane.name,\n\t\t\trunId: drive.operationId,\n\t\t\tmodel,\n\t\t\tstep: \"deferred\",\n\t\t\tattempt: poll,\n\t\t\tstreamOptions: baseOptions,\n\t\t},\n\t\tdrive.gate,\n\t\tdrive.context,\n\t);\n\treturn {\n\t\tkind: \"ready\",\n\t\tsource: source.value,\n\t\tmodel,\n\t\tpoll,\n\t\tstreamOptions: {\n\t\t\t...(beforeRequest?.streamOptions === undefined\n\t\t\t\t? baseOptions\n\t\t\t\t: applyStreamOptionsPatch(baseOptions, beforeRequest.streamOptions)),\n\t\t\tdeferred: false,\n\t\t},\n\t};\n}\n\nasync function publishPollIntent<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tdeferred: DeferredLeaf,\n\tprepared: PreparedDeferredPoll,\n\trecovery: boolean,\n): Promise<ContinueOperationResult<DeferredEffectPendingOperation>> {\n\tconst at = Date.now();\n\tconst next: EffectPendingFields = {\n\t\tat: \"deferred.effect_pending\",\n\t\tstepId: deferred.stepId,\n\t\tsourceEntryId: deferred.sourceEntryId,\n\t\tpoll: prepared.poll,\n\t\tresponseEntryId: lane.session.idGenerator.next(at),\n\t\tusageId: lane.session.idGenerator.next(at),\n\t\tconfiguration: deferred.configuration,\n\t\tstreamOptions: deferred.streamOptions,\n\t};\n\treturn lane.continueOperation(\n\t\tdeferred,\n\t\t(_state, current) => {\n\t\t\tconst nextState: DeferredEffectPendingOperation = { ...operationScopeOf(current), ...next };\n\t\t\treturn {\n\t\t\t\tkind: \"commit\",\n\t\t\t\twrites:\n\t\t\t\t\tdeferred.at === \"deferred.effect_pending\"\n\t\t\t\t\t\t? [deleteList(pendingAssistantFrames(drive.operationId, deferred.responseEntryId))]\n\t\t\t\t\t\t: [],\n\t\t\t\toperationState: nextState,\n\t\t\t\tmaterialize: () => {\n\t\t\t\t\tdrive.deferredPermits--;\n\t\t\t\t\treturn nextState;\n\t\t\t\t},\n\t\t\t\tevents: () => [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"run_resume\",\n\t\t\t\t\t\tlane: lane.name,\n\t\t\t\t\t\trunId: drive.operationId,\n\t\t\t\t\t\t...(recovery ? { recovery: true as const } : {}),\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"turn_start\",\n\t\t\t\t\t\tlane: lane.name,\n\t\t\t\t\t\trunId: drive.operationId,\n\t\t\t\t\t\tturnId: `${next.stepId}:poll:${next.poll}`,\n\t\t\t\t\t\t...(recovery ? { recovery: true as const } : {}),\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t},\n\t\tdrive.context,\n\t);\n}\n\nasync function performDeferredPoll<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tprepared: PreparedDeferredPoll,\n\tintent: DeferredEffectPendingOperation,\n\trecovery: boolean,\n): Promise<SettledAssistantMessage> {\n\tconst response = openAssistantResponse(lane, drive, intent.responseEntryId, recovery);\n\tlet metadata: { status?: number; headers?: Record<string, string> } = {};\n\tconst admitted = withAbortSignal(drive.gate.signal, drive.context);\n\tconst stream = drive.gate.admit(() =>\n\t\tlane.models.streamDeferred(prepared.model, prepared.source, {\n\t\t\twait: 0,\n\t\t\tsignal: admitted.abortSignal,\n\t\t\ttelemetryContext: getTelemetryContext(admitted),\n\t\t\ttimeoutMs: prepared.streamOptions.timeoutMs,\n\t\t\tmaxRetries: prepared.streamOptions.maxRetries,\n\t\t\tmaxRetryDelayMs: prepared.streamOptions.maxRetryDelayMs,\n\t\t\theaders: prepared.streamOptions.headers,\n\t\t\tonPayload: async (payload, requestModel) => {\n\t\t\t\tconst result = await lane.hooks.runWithGate(\n\t\t\t\t\t\"before_payload\",\n\t\t\t\t\t{ lane: lane.name, runId: drive.operationId, model: requestModel, payload },\n\t\t\t\t\tdrive.gate,\n\t\t\t\t\tdrive.context,\n\t\t\t\t);\n\t\t\t\treturn result?.payload;\n\t\t\t},\n\t\t\tonResponse: (response) => {\n\t\t\t\tmetadata = { status: response.status, headers: response.headers };\n\t\t\t},\n\t\t}),\n\t);\n\n\ttry {\n\t\treturn await consumeAssistantStream(\n\t\t\tstream,\n\t\t\tresponse.observer,\n\t\t\t(message, context) => response.afterResponse(message, metadata, context),\n\t\t\tdrive.context,\n\t\t);\n\t} finally {\n\t\tawait response.close();\n\t}\n}\n\nasync function pollDeferred<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\texpected: DeferredLeaf,\n\trecovery: boolean,\n): Promise<ProcedureResult> {\n\tconst prepared = await prepareDeferredPoll(lane, drive, expected);\n\tif (prepared.kind === \"cancel_requested\") return { kind: \"continue\" };\n\tif (prepared.kind === \"waiting\") {\n\t\treturn {\n\t\t\tkind: \"waiting\",\n\t\t\toutcome: {\n\t\t\t\tkind: \"waiting\",\n\t\t\t\toperationId: drive.operationId,\n\t\t\t\treason: \"deferred\",\n\t\t\t\tdeferred: prepared.source,\n\t\t\t},\n\t\t};\n\t}\n\tif (prepared.kind === \"configuration_failure\") {\n\t\treturn publishConfigurationFailure(lane, drive, expected, configurationError(expected.configuration.model));\n\t}\n\n\tconst intent = await publishPollIntent(lane, drive, expected, prepared, recovery);\n\tif (intent.kind === \"cancel_requested\") return { kind: \"continue\" };\n\tconst response = await performDeferredPoll(lane, drive, prepared, intent.value, recovery);\n\treturn publishResponse(lane, drive, intent.value, response, recovery ? { recovery: true } : {});\n}\n\n/** Poll one durably suspended deferred response when this pass carries a permit. */\nexport function runDeferredSuspended<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tdeferred: DeferredSuspendedOperation,\n): Promise<ProcedureResult> {\n\treturn pollDeferred(lane, drive, deferred, false);\n}\n\n/** Replace one orphaned unknown-outcome poll under fresh ids when this pass carries a permit. */\nexport function recoverDeferredPoll<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tdeferred: DeferredEffectPendingOperation,\n): Promise<ProcedureResult> {\n\treturn pollDeferred(lane, drive, deferred, true);\n}\n\n/** Advance or report the wait for one deferred run phase. */\nexport function runDeferred<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tdeferred: DeferredSuspendedOperation | DeferredEffectPendingOperation,\n): Promise<ProcedureResult> {\n\treturn deferred.at === \"deferred.suspended\"\n\t\t? runDeferredSuspended(lane, drive, deferred)\n\t\t: recoverDeferredPoll(lane, drive, deferred);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"generation.d.ts","sourceRoot":"","sources":["../../../../src/harness/runtime/drive/generation.ts"],"names":[],"mappings":"AAMA,OAAO,EAEN,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,EAMhC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,KAAK,EAA2B,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAqNnF,2FAA2F;AAC3F,wBAAsB,YAAY,CAAC,QAAQ,SAAS,MAAM,GAAG,SAAS,EACrE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EACpB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,2BAA2B,GACrC,OAAO,CAAC,eAAe,CAAC,CA4C1B;AAED,gFAAgF;AAChF,wBAAsB,aAAa,CAAC,QAAQ,SAAS,MAAM,GAAG,SAAS,EACtE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EACpB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,uBAAuB,GAAG,2BAA2B,GAC/D,OAAO,CAAC,eAAe,CAAC,CAa1B","sourcesContent":["import type { Api, Model, Tool } from \"@earendil-works/pi-ai\";\nimport type { AgentMessage } from \"../../../types.ts\";\nimport { type Context, getTelemetryContext, withAbortSignal } from \"../../context.ts\";\nimport { type HarnessAssistantStreamConfig, streamHarnessAssistant } from \"../../execution/assistant.ts\";\nimport { applyStreamOptionsPatch } from \"../../hooks.ts\";\nimport { SessionInvariantError } from \"../../session/session.ts\";\nimport {\n\ttype AssistantEffectPendingOperation,\n\ttype AssistantReadyOperation,\n\ttype AssistantRetryWaitOperation,\n\ttype JsonValue,\n\ttype OperationError,\n\ttype OperationScope,\n\toperationScopeOf,\n\ttype SettledAssistantMessage,\n} from \"../../session/types.ts\";\nimport type { AgentHarnessStreamOptions } from \"../../types.ts\";\nimport type { Lane } from \"../lane.ts\";\nimport { readBoundedContext } from \"../transcript.ts\";\nimport type { ContinueOperationResult, Drive, ProcedureResult } from \"../types.ts\";\nimport { openAssistantResponse, publishConfigurationFailure, publishResponse } from \"./response.ts\";\nimport { waitUntil } from \"./retry.ts\";\n\n/** Assistant effect-pending payload without the run-wide scope fields. */\ntype AssistantEffectPending = Omit<AssistantEffectPendingOperation, keyof OperationScope>;\n\ntype PreparedGeneration = {\n\tkind: \"ready\";\n\tmodel: Model<Api>;\n\ttools: Tool[];\n\tmessages: AgentMessage[];\n\tsystemPrompt: string;\n\tstreamOptions: AgentHarnessStreamOptions;\n\ttoProviderMessages: HarnessAssistantStreamConfig[\"toProviderMessages\"];\n};\n\ntype GenerationPreparation =\n\t| PreparedGeneration\n\t| { kind: \"configuration_failure\"; error: OperationError }\n\t| { kind: \"cancel_requested\" };\n\nfunction configurationError(\n\tcode: \"model_unavailable\" | \"configured_tools_unavailable\",\n\tdetails: JsonValue,\n): OperationError {\n\treturn {\n\t\tcode,\n\t\tmessage:\n\t\t\tcode === \"model_unavailable\"\n\t\t\t\t? \"The configured model is unavailable in this process\"\n\t\t\t\t: \"One or more configured tools are unavailable in this process\",\n\t\tdetails,\n\t};\n}\n\nasync function resolveSystemPrompt<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tcontext: Context,\n): Promise<string> {\n\tconst config = lane.readConfig();\n\tif (config.systemPrompt === undefined) return \"\";\n\tif (typeof config.systemPrompt === \"string\") return config.systemPrompt;\n\tconst source = config.toolContext;\n\tconst toolContext = typeof source === \"function\" ? await source(context) : source;\n\treturn config.systemPrompt(toolContext as TContext, context);\n}\n\nasync function prepareGeneration<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tgeneration: AssistantReadyOperation,\n): Promise<GenerationPreparation> {\n\tconst identity = generation.generationContext.configuration.model;\n\tconst model = lane.models.getModel(identity.provider, identity.modelId);\n\tif (model === undefined) {\n\t\treturn { kind: \"configuration_failure\", error: configurationError(\"model_unavailable\", identity) };\n\t}\n\n\tconst config = lane.readConfig();\n\tconst toolsByName = new Map(config.tools.map((tool) => [tool.name, tool]));\n\tconst missingTools = generation.generationContext.configuration.activeToolNames.filter(\n\t\t(name) => !toolsByName.has(name),\n\t);\n\tif (missingTools.length !== 0) {\n\t\treturn {\n\t\t\tkind: \"configuration_failure\",\n\t\t\terror: configurationError(\"configured_tools_unavailable\", { tools: missingTools }),\n\t\t};\n\t}\n\tconst tools: Tool[] = generation.generationContext.configuration.activeToolNames.map((name) => {\n\t\tconst tool = toolsByName.get(name);\n\t\tif (tool === undefined) throw new SessionInvariantError(`Configured tool ${name} disappeared during resolution`);\n\t\treturn {\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: tool.parameters,\n\t\t\t...(tool.constrainedSampling === undefined ? {} : { constrainedSampling: tool.constrainedSampling }),\n\t\t};\n\t});\n\n\tconst messages = await readBoundedContext(lane, drive, generation);\n\tif (messages.kind === \"cancel_requested\") return messages;\n\tconst systemPrompt = await resolveSystemPrompt(lane, drive.context);\n\tconst beforeRequest = await lane.hooks.runWithGate(\n\t\t\"before_request\",\n\t\t{\n\t\t\tlane: lane.name,\n\t\t\trunId: drive.operationId,\n\t\t\tmodel,\n\t\t\tstep: \"assistant\",\n\t\t\tattempt: generation.nextAttempt,\n\t\t\tstreamOptions: generation.generationContext.streamOptions,\n\t\t},\n\t\tdrive.gate,\n\t\tdrive.context,\n\t);\n\tconst streamOptions =\n\t\tbeforeRequest?.streamOptions === undefined\n\t\t\t? generation.generationContext.streamOptions\n\t\t\t: applyStreamOptionsPatch(generation.generationContext.streamOptions, beforeRequest.streamOptions);\n\treturn {\n\t\tkind: \"ready\",\n\t\tmodel,\n\t\ttools,\n\t\tmessages: messages.value,\n\t\tsystemPrompt,\n\t\tstreamOptions,\n\t\ttoProviderMessages: config.toProviderMessages,\n\t};\n}\n\nasync function publishGenerationIntent<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tready: AssistantReadyOperation,\n\tprepared: PreparedGeneration,\n): Promise<ContinueOperationResult<AssistantEffectPendingOperation>> {\n\tconst at = Date.now();\n\tconst pending: AssistantEffectPending = {\n\t\tat: \"assistant.effect_pending\",\n\t\tgenerationContext: ready.generationContext,\n\t\tattempt: ready.nextAttempt,\n\t\tresponseEntryId: lane.session.idGenerator.next(at),\n\t\tusageId: lane.session.idGenerator.next(at),\n\t\tintendedOutputLimit: prepared.model.maxTokens,\n\t\tcontextWindow: prepared.model.contextWindow,\n\t};\n\treturn lane.continueOperation(\n\t\tready,\n\t\t(_state, current) => {\n\t\t\tconst nextState: AssistantEffectPendingOperation = { ...operationScopeOf(current), ...pending };\n\t\t\treturn {\n\t\t\t\tkind: \"commit\",\n\t\t\t\twrites: [],\n\t\t\t\toperationState: nextState,\n\t\t\t\tmaterialize: () => nextState,\n\t\t\t\tevents: () =>\n\t\t\t\t\tready.nextAttempt === 1\n\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"turn_start\",\n\t\t\t\t\t\t\t\t\tlane: lane.name,\n\t\t\t\t\t\t\t\t\trunId: drive.operationId,\n\t\t\t\t\t\t\t\t\tturnId: ready.generationContext.stepId,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t]\n\t\t\t\t\t\t: [],\n\t\t\t};\n\t\t},\n\t\tdrive.context,\n\t);\n}\n\nasync function performGeneration<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tintent: AssistantEffectPendingOperation,\n\tprepared: PreparedGeneration,\n): Promise<SettledAssistantMessage> {\n\tconst response = openAssistantResponse(lane, drive, intent.responseEntryId);\n\ttry {\n\t\treturn await streamHarnessAssistant(\n\t\t\tprepared.messages,\n\t\t\t{\n\t\t\t\tmodel: prepared.model,\n\t\t\t\tsystemPrompt: prepared.systemPrompt,\n\t\t\t\ttools: prepared.tools,\n\t\t\t\tthinkingLevel: intent.generationContext.configuration.thinkingLevel,\n\t\t\t\tstreamOptions: prepared.streamOptions,\n\t\t\t\ttransformContext: async (requestContext, context) => {\n\t\t\t\t\tconst result = await lane.hooks.runWithGate(\n\t\t\t\t\t\t\"transform_context\",\n\t\t\t\t\t\t{ lane: lane.name, runId: drive.operationId, ...requestContext },\n\t\t\t\t\t\tdrive.gate,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tmessages: result?.messages ?? requestContext.messages,\n\t\t\t\t\t\tsystemPrompt: result?.systemPrompt ?? requestContext.systemPrompt,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t\ttoProviderMessages: prepared.toProviderMessages,\n\t\t\t\tbeforePayload: async (payload, requestModel, context) => {\n\t\t\t\t\tconst result = await lane.hooks.runWithGate(\n\t\t\t\t\t\t\"before_payload\",\n\t\t\t\t\t\t{ lane: lane.name, runId: drive.operationId, model: requestModel, payload },\n\t\t\t\t\t\tdrive.gate,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t);\n\t\t\t\t\treturn result?.payload;\n\t\t\t\t},\n\t\t\t\tafterResponse: response.afterResponse,\n\t\t\t\trequest: (aiContext, options, context) => {\n\t\t\t\t\tconst admitted = withAbortSignal(drive.gate.signal, context);\n\t\t\t\t\treturn drive.gate.admit(() =>\n\t\t\t\t\t\tlane.models.streamSimple(prepared.model, aiContext, {\n\t\t\t\t\t\t\t...options,\n\t\t\t\t\t\t\tsessionId: `${lane.session.metadata.id}:${lane.name}`,\n\t\t\t\t\t\t\tsignal: admitted.abortSignal,\n\t\t\t\t\t\t\ttelemetryContext: getTelemetryContext(admitted),\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tobserver: response.observer,\n\t\t\t},\n\t\t\tdrive.context,\n\t\t);\n\t} finally {\n\t\tawait response.close();\n\t}\n}\n\n/** Advance one durable assistant retry wait according to this pass's local wait policy. */\nexport async function runRetryWait<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tgeneration: AssistantRetryWaitOperation,\n): Promise<ProcedureResult> {\n\tif (Date.now() < generation.notBefore) {\n\t\tif (!drive.waitForRetry) {\n\t\t\treturn {\n\t\t\t\tkind: \"waiting\",\n\t\t\t\toutcome: {\n\t\t\t\t\tkind: \"waiting\",\n\t\t\t\t\toperationId: drive.operationId,\n\t\t\t\t\treason: \"retry\",\n\t\t\t\t\tnotBefore: generation.notBefore,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tawait drive.gate.admit(() => waitUntil(generation.notBefore, drive.gate.signal));\n\t}\n\n\tconst result = await lane.continueOperation(\n\t\tgeneration,\n\t\t(_state, current) => {\n\t\t\tconst nextState: AssistantReadyOperation = {\n\t\t\t\t...operationScopeOf(current),\n\t\t\t\tat: \"assistant.ready\",\n\t\t\t\tgenerationContext: generation.generationContext,\n\t\t\t\tnextAttempt: generation.nextAttempt,\n\t\t\t};\n\t\t\treturn {\n\t\t\t\tkind: \"commit\",\n\t\t\t\twrites: [],\n\t\t\t\toperationState: nextState,\n\t\t\t\tmaterialize: () => ({ kind: \"continue\" }) as const,\n\t\t\t\tevents: () => [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"retry_start\",\n\t\t\t\t\t\tlane: lane.name,\n\t\t\t\t\t\trunId: drive.operationId,\n\t\t\t\t\t\tstep: generation.generationContext.stepId,\n\t\t\t\t\t\tattempt: generation.nextAttempt,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t},\n\t\tdrive.context,\n\t);\n\treturn result.kind === \"cancel_requested\" ? { kind: \"continue\" } : result.value;\n}\n\n/** Execute one ready assistant generation or advance its durable retry wait. */\nexport async function runGeneration<TContext extends object | undefined>(\n\tlane: Lane<TContext>,\n\tdrive: Drive,\n\tgeneration: AssistantReadyOperation | AssistantRetryWaitOperation,\n): Promise<ProcedureResult> {\n\tif (generation.at === \"assistant.retry_wait\") return runRetryWait(lane, drive, generation);\n\n\tconst prepared = await prepareGeneration(lane, drive, generation);\n\tif (prepared.kind === \"configuration_failure\") {\n\t\treturn publishConfigurationFailure(lane, drive, generation, prepared.error);\n\t}\n\tif (prepared.kind === \"cancel_requested\") return { kind: \"continue\" };\n\n\tconst intent = await publishGenerationIntent(lane, drive, generation, prepared);\n\tif (intent.kind === \"cancel_requested\") return { kind: \"continue\" };\n\tconst response = await performGeneration(lane, drive, intent.value, prepared);\n\treturn publishResponse(lane, drive, intent.value, response);\n}\n"]}
1
+ {"version":3,"file":"generation.d.ts","sourceRoot":"","sources":["../../../../src/harness/runtime/drive/generation.ts"],"names":[],"mappings":"AAMA,OAAO,EAEN,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,EAMhC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,KAAK,EAA2B,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAqNnF,2FAA2F;AAC3F,wBAAsB,YAAY,CAAC,QAAQ,SAAS,MAAM,GAAG,SAAS,EACrE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EACpB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,2BAA2B,GACrC,OAAO,CAAC,eAAe,CAAC,CA4C1B;AAED,gFAAgF;AAChF,wBAAsB,aAAa,CAAC,QAAQ,SAAS,MAAM,GAAG,SAAS,EACtE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,EACpB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,uBAAuB,GAAG,2BAA2B,GAC/D,OAAO,CAAC,eAAe,CAAC,CAa1B"}