@elie-laloum/outpost 5.0.0 → 7.0.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 (647) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +11 -11
  3. package/SECURITY.md +10 -0
  4. package/dist/adapters/agents/antigravity-adapter.d.ts +3 -0
  5. package/dist/adapters/agents/antigravity-adapter.js +41 -0
  6. package/dist/adapters/agents/antigravity-adapter.js.map +1 -0
  7. package/dist/adapters/agents/antigravity-authentication.d.ts +2 -0
  8. package/dist/adapters/agents/antigravity-authentication.js +27 -0
  9. package/dist/adapters/agents/antigravity-authentication.js.map +1 -0
  10. package/dist/adapters/agents/antigravity-diagnostics.d.ts +1 -0
  11. package/dist/adapters/agents/antigravity-diagnostics.js +6 -0
  12. package/dist/adapters/agents/antigravity-diagnostics.js.map +1 -0
  13. package/dist/adapters/agents/antigravity-events.d.ts +2 -0
  14. package/dist/adapters/agents/antigravity-events.js +75 -0
  15. package/dist/adapters/agents/antigravity-events.js.map +1 -0
  16. package/dist/adapters/agents/antigravity-request.d.ts +5 -0
  17. package/dist/adapters/agents/antigravity-request.js +37 -0
  18. package/dist/adapters/agents/antigravity-request.js.map +1 -0
  19. package/dist/adapters/agents/antigravity.constants.d.ts +3 -0
  20. package/dist/adapters/agents/antigravity.constants.js +4 -0
  21. package/dist/adapters/agents/antigravity.constants.js.map +1 -0
  22. package/dist/adapters/agents/{gemini.types.d.ts → antigravity.types.d.ts} +2 -2
  23. package/dist/adapters/agents/antigravity.types.js +2 -0
  24. package/dist/adapters/agents/antigravity.types.js.map +1 -0
  25. package/dist/adapters/agents/authentication.constants.d.ts +19 -9
  26. package/dist/adapters/agents/authentication.constants.js +12 -9
  27. package/dist/adapters/agents/authentication.constants.js.map +1 -1
  28. package/dist/adapters/agents/authentication.d.ts +11 -2
  29. package/dist/adapters/agents/authentication.js +70 -47
  30. package/dist/adapters/agents/authentication.js.map +1 -1
  31. package/dist/adapters/agents/authentication.types.d.ts +20 -0
  32. package/dist/adapters/agents/authentication.types.js +2 -0
  33. package/dist/adapters/agents/authentication.types.js.map +1 -0
  34. package/dist/adapters/agents/claude-adapter.js +4 -2
  35. package/dist/adapters/agents/claude-adapter.js.map +1 -1
  36. package/dist/adapters/agents/claude-authentication.d.ts +2 -0
  37. package/dist/adapters/agents/claude-authentication.js +34 -0
  38. package/dist/adapters/agents/claude-authentication.js.map +1 -0
  39. package/dist/adapters/agents/claude-events.js +52 -9
  40. package/dist/adapters/agents/claude-events.js.map +1 -1
  41. package/dist/adapters/agents/claude-request.js +2 -0
  42. package/dist/adapters/agents/claude-request.js.map +1 -1
  43. package/dist/adapters/agents/cli-diagnostics.constants.d.ts +6 -6
  44. package/dist/adapters/agents/cli-diagnostics.constants.js +6 -6
  45. package/dist/adapters/agents/cli-diagnostics.constants.js.map +1 -1
  46. package/dist/adapters/agents/cli-diagnostics.d.ts +1 -0
  47. package/dist/adapters/agents/cli-diagnostics.js +18 -0
  48. package/dist/adapters/agents/cli-diagnostics.js.map +1 -1
  49. package/dist/adapters/agents/codex-adapter.js +4 -2
  50. package/dist/adapters/agents/codex-adapter.js.map +1 -1
  51. package/dist/adapters/agents/codex-authentication.d.ts +3 -0
  52. package/dist/adapters/agents/codex-authentication.js +47 -0
  53. package/dist/adapters/agents/codex-authentication.js.map +1 -0
  54. package/dist/adapters/agents/codex-events.js +28 -2
  55. package/dist/adapters/agents/codex-events.js.map +1 -1
  56. package/dist/adapters/agents/copilot-adapter.d.ts +3 -0
  57. package/dist/adapters/agents/copilot-adapter.js +45 -0
  58. package/dist/adapters/agents/copilot-adapter.js.map +1 -0
  59. package/dist/adapters/agents/copilot-authentication.d.ts +2 -0
  60. package/dist/adapters/agents/copilot-authentication.js +46 -0
  61. package/dist/adapters/agents/copilot-authentication.js.map +1 -0
  62. package/dist/adapters/agents/copilot-diagnostics.d.ts +1 -0
  63. package/dist/adapters/agents/copilot-diagnostics.js +6 -0
  64. package/dist/adapters/agents/copilot-diagnostics.js.map +1 -0
  65. package/dist/adapters/agents/copilot-events.d.ts +2 -0
  66. package/dist/adapters/agents/copilot-events.js +66 -0
  67. package/dist/adapters/agents/copilot-events.js.map +1 -0
  68. package/dist/adapters/agents/copilot-request.d.ts +5 -0
  69. package/dist/adapters/agents/copilot-request.js +24 -0
  70. package/dist/adapters/agents/copilot-request.js.map +1 -0
  71. package/dist/adapters/agents/copilot-usage.d.ts +3 -0
  72. package/dist/adapters/agents/copilot-usage.js +19 -0
  73. package/dist/adapters/agents/copilot-usage.js.map +1 -0
  74. package/dist/adapters/agents/copilot.types.d.ts +6 -0
  75. package/dist/adapters/agents/copilot.types.js +2 -0
  76. package/dist/adapters/agents/copilot.types.js.map +1 -0
  77. package/dist/adapters/agents/event-decoder.d.ts +2 -2
  78. package/dist/adapters/agents/event-decoder.js +6 -5
  79. package/dist/adapters/agents/event-decoder.js.map +1 -1
  80. package/dist/adapters/agents/kimi-adapter.d.ts +3 -0
  81. package/dist/adapters/agents/kimi-adapter.js +51 -0
  82. package/dist/adapters/agents/kimi-adapter.js.map +1 -0
  83. package/dist/adapters/agents/kimi-authentication.d.ts +3 -0
  84. package/dist/adapters/agents/kimi-authentication.js +63 -0
  85. package/dist/adapters/agents/kimi-authentication.js.map +1 -0
  86. package/dist/adapters/agents/kimi-diagnostics.d.ts +2 -0
  87. package/dist/adapters/agents/kimi-diagnostics.js +14 -0
  88. package/dist/adapters/agents/kimi-diagnostics.js.map +1 -0
  89. package/dist/adapters/agents/kimi-events.d.ts +2 -0
  90. package/dist/adapters/agents/kimi-events.js +55 -0
  91. package/dist/adapters/agents/kimi-events.js.map +1 -0
  92. package/dist/adapters/agents/kimi-fork.d.ts +2 -0
  93. package/dist/adapters/agents/kimi-fork.js +11 -0
  94. package/dist/adapters/agents/kimi-fork.js.map +1 -0
  95. package/dist/adapters/agents/{gemini-request.d.ts → kimi-request.d.ts} +2 -2
  96. package/dist/adapters/agents/kimi-request.js +33 -0
  97. package/dist/adapters/agents/kimi-request.js.map +1 -0
  98. package/dist/adapters/agents/kimi-usage.d.ts +2 -0
  99. package/dist/adapters/agents/kimi-usage.js +7 -0
  100. package/dist/adapters/agents/kimi-usage.js.map +1 -0
  101. package/dist/adapters/agents/kimi.constants.d.ts +13 -0
  102. package/dist/adapters/agents/kimi.constants.js +14 -0
  103. package/dist/adapters/agents/kimi.constants.js.map +1 -0
  104. package/dist/adapters/agents/kimi.types.d.ts +7 -0
  105. package/dist/adapters/agents/kimi.types.js +2 -0
  106. package/dist/adapters/agents/kimi.types.js.map +1 -0
  107. package/dist/adapters/agents/model-support.constants.d.ts +3 -1
  108. package/dist/adapters/agents/model-support.constants.js +12 -2
  109. package/dist/adapters/agents/model-support.constants.js.map +1 -1
  110. package/dist/adapters/agents/protocol-fixtures.constants.d.ts +2 -2
  111. package/dist/adapters/agents/protocol-fixtures.constants.js +131 -9
  112. package/dist/adapters/agents/protocol-fixtures.constants.js.map +1 -1
  113. package/dist/adapters/agents/protocol-fixtures.types.d.ts +1 -0
  114. package/dist/adapters/agents/protocol-fixtures.types.js.map +1 -1
  115. package/dist/adapters/agents/protocol.d.ts +1 -0
  116. package/dist/adapters/agents/protocol.js +9 -0
  117. package/dist/adapters/agents/protocol.js.map +1 -1
  118. package/dist/adapters/agents/session-usage.constants.d.ts +10 -0
  119. package/dist/adapters/agents/session-usage.constants.js +110 -0
  120. package/dist/adapters/agents/session-usage.constants.js.map +1 -0
  121. package/dist/adapters/agents/session-usage.d.ts +5 -0
  122. package/dist/adapters/agents/session-usage.js +45 -0
  123. package/dist/adapters/agents/session-usage.js.map +1 -0
  124. package/dist/adapters/agents/settings.types.d.ts +1 -0
  125. package/dist/adapters/agents/settings.types.js.map +1 -1
  126. package/dist/adapters/agents/tool-result.d.ts +2 -0
  127. package/dist/adapters/agents/tool-result.js +17 -0
  128. package/dist/adapters/agents/tool-result.js.map +1 -0
  129. package/dist/adapters/models/anthropic-response.js +3 -0
  130. package/dist/adapters/models/anthropic-response.js.map +1 -1
  131. package/dist/adapters/models/http-provider.js +6 -1
  132. package/dist/adapters/models/http-provider.js.map +1 -1
  133. package/dist/adapters/models/openai-responses.js +10 -0
  134. package/dist/adapters/models/openai-responses.js.map +1 -1
  135. package/dist/adapters/models/retry-after.d.ts +1 -0
  136. package/dist/adapters/models/retry-after.js +16 -0
  137. package/dist/adapters/models/retry-after.js.map +1 -0
  138. package/dist/application/activity-watchdog.js +1 -2
  139. package/dist/application/activity-watchdog.js.map +1 -1
  140. package/dist/application/agent-authentication.d.ts +4 -0
  141. package/dist/application/agent-authentication.js +32 -0
  142. package/dist/application/agent-authentication.js.map +1 -0
  143. package/dist/application/agent-bootstrap.constants.d.ts +2 -5
  144. package/dist/application/agent-bootstrap.constants.js +27 -4
  145. package/dist/application/agent-bootstrap.constants.js.map +1 -1
  146. package/dist/application/agent-bootstrap.js +39 -12
  147. package/dist/application/agent-bootstrap.js.map +1 -1
  148. package/dist/application/agent-bootstrap.types.d.ts +19 -0
  149. package/dist/application/agent-bootstrap.types.js +2 -0
  150. package/dist/application/agent-bootstrap.types.js.map +1 -0
  151. package/dist/application/agent-output.js +74 -8
  152. package/dist/application/agent-output.js.map +1 -1
  153. package/dist/application/agent-request.d.ts +3 -0
  154. package/dist/application/agent-request.js +11 -0
  155. package/dist/application/agent-request.js.map +1 -0
  156. package/dist/application/agent-turn.js +74 -6
  157. package/dist/application/agent-turn.js.map +1 -1
  158. package/dist/application/agent-usage.d.ts +6 -0
  159. package/dist/application/agent-usage.js +57 -0
  160. package/dist/application/agent-usage.js.map +1 -0
  161. package/dist/application/attach.js +2 -0
  162. package/dist/application/attach.js.map +1 -1
  163. package/dist/application/credential-installer.constants.d.ts +1 -0
  164. package/dist/application/credential-installer.constants.js +22 -0
  165. package/dist/application/credential-installer.constants.js.map +1 -0
  166. package/dist/application/custom-turn.js +44 -49
  167. package/dist/application/custom-turn.js.map +1 -1
  168. package/dist/application/dispatch-observation.d.ts +1 -1
  169. package/dist/application/dispatch-observation.js +141 -21
  170. package/dist/application/dispatch-observation.js.map +1 -1
  171. package/dist/application/dispatch-observation.types.d.ts +2 -0
  172. package/dist/application/dispatch-observation.types.js.map +1 -1
  173. package/dist/application/dispatch-validation.js +2 -0
  174. package/dist/application/dispatch-validation.js.map +1 -1
  175. package/dist/application/dispatch.js +1 -1
  176. package/dist/application/dispatch.js.map +1 -1
  177. package/dist/application/doctor-agent.constants.d.ts +2 -8
  178. package/dist/application/doctor-agent.constants.js +43 -6
  179. package/dist/application/doctor-agent.constants.js.map +1 -1
  180. package/dist/application/doctor-agent.d.ts +2 -1
  181. package/dist/application/doctor-agent.js +15 -3
  182. package/dist/application/doctor-agent.js.map +1 -1
  183. package/dist/application/doctor-image.js +4 -6
  184. package/dist/application/doctor-image.js.map +1 -1
  185. package/dist/application/doctor-protocol.js +6 -11
  186. package/dist/application/doctor-protocol.js.map +1 -1
  187. package/dist/application/doctor-protocol.types.d.ts +1 -1
  188. package/dist/application/doctor-protocol.types.js.map +1 -1
  189. package/dist/application/doctor-sandbox.js +2 -5
  190. package/dist/application/doctor-sandbox.js.map +1 -1
  191. package/dist/application/doctor.js +28 -10
  192. package/dist/application/doctor.js.map +1 -1
  193. package/dist/application/doctor.types.d.ts +10 -1
  194. package/dist/application/doctor.types.js.map +1 -1
  195. package/dist/application/execution.constants.d.ts +2 -0
  196. package/dist/application/execution.constants.js +2 -0
  197. package/dist/application/execution.constants.js.map +1 -1
  198. package/dist/application/execution.types.d.ts +8 -0
  199. package/dist/application/execution.types.js.map +1 -1
  200. package/dist/application/harness-budget.d.ts +3 -0
  201. package/dist/application/harness-budget.js +42 -0
  202. package/dist/application/harness-budget.js.map +1 -0
  203. package/dist/application/harness-budget.types.d.ts +5 -0
  204. package/dist/application/harness-budget.types.js +2 -0
  205. package/dist/application/harness-budget.types.js.map +1 -0
  206. package/dist/application/harness-hooks.js +34 -3
  207. package/dist/application/harness-hooks.js.map +1 -1
  208. package/dist/application/harness-loop.js +52 -24
  209. package/dist/application/harness-loop.js.map +1 -1
  210. package/dist/application/harness-model-provider.d.ts +3 -0
  211. package/dist/application/harness-model-provider.js +49 -0
  212. package/dist/application/harness-model-provider.js.map +1 -0
  213. package/dist/application/harness-model-provider.types.d.ts +10 -0
  214. package/dist/application/harness-model-provider.types.js +2 -0
  215. package/dist/application/harness-model-provider.types.js.map +1 -0
  216. package/dist/application/harness-subagent.d.ts +4 -0
  217. package/dist/application/harness-subagent.js +110 -0
  218. package/dist/application/harness-subagent.js.map +1 -0
  219. package/dist/application/harness.types.d.ts +11 -0
  220. package/dist/application/harness.types.js.map +1 -1
  221. package/dist/application/lifecycle-hooks.d.ts +1 -1
  222. package/dist/application/lifecycle-hooks.js +5 -4
  223. package/dist/application/lifecycle-hooks.js.map +1 -1
  224. package/dist/application/observed-lease.d.ts +3 -0
  225. package/dist/application/observed-lease.js +26 -0
  226. package/dist/application/observed-lease.js.map +1 -0
  227. package/dist/application/outpost.types.d.ts +3 -1
  228. package/dist/application/outpost.types.js.map +1 -1
  229. package/dist/application/output-lines.d.ts +4 -0
  230. package/dist/application/output-lines.js +28 -0
  231. package/dist/application/output-lines.js.map +1 -0
  232. package/dist/application/queue-worker.js +1 -1
  233. package/dist/application/queue-worker.js.map +1 -1
  234. package/dist/application/queue-worker.types.d.ts +1 -0
  235. package/dist/application/queue-worker.types.js.map +1 -1
  236. package/dist/application/queued-task.js +24 -5
  237. package/dist/application/queued-task.js.map +1 -1
  238. package/dist/application/recovery-archive.d.ts +3 -2
  239. package/dist/application/recovery-archive.js +9 -2
  240. package/dist/application/recovery-archive.js.map +1 -1
  241. package/dist/application/recovery-restore.d.ts +3 -2
  242. package/dist/application/recovery-restore.js +9 -2
  243. package/dist/application/recovery-restore.js.map +1 -1
  244. package/dist/application/recovery-retention.d.ts +3 -2
  245. package/dist/application/recovery-retention.js +74 -26
  246. package/dist/application/recovery-retention.js.map +1 -1
  247. package/dist/application/remote-workspace.js +5 -4
  248. package/dist/application/remote-workspace.js.map +1 -1
  249. package/dist/application/remote-workspace.types.d.ts +1 -0
  250. package/dist/application/remote-workspace.types.js.map +1 -1
  251. package/dist/application/sandbox-agents.js +19 -19
  252. package/dist/application/sandbox-agents.js.map +1 -1
  253. package/dist/application/sandbox-attach.js +12 -3
  254. package/dist/application/sandbox-attach.js.map +1 -1
  255. package/dist/application/sandbox-dispatch.js +13 -27
  256. package/dist/application/sandbox-dispatch.js.map +1 -1
  257. package/dist/application/sandbox-provision.js +15 -9
  258. package/dist/application/sandbox-provision.js.map +1 -1
  259. package/dist/application/sandbox-session.types.d.ts +7 -2
  260. package/dist/application/sandbox-session.types.js.map +1 -1
  261. package/dist/application/sandbox.js +13 -6
  262. package/dist/application/sandbox.js.map +1 -1
  263. package/dist/application/speculation-checkpoint.d.ts +6 -0
  264. package/dist/application/speculation-checkpoint.js +206 -0
  265. package/dist/application/speculation-checkpoint.js.map +1 -0
  266. package/dist/application/speculation-checkpoint.types.d.ts +24 -0
  267. package/dist/application/speculation-checkpoint.types.js +2 -0
  268. package/dist/application/speculation-checkpoint.types.js.map +1 -0
  269. package/dist/application/speculation-integration.constants.d.ts +4 -0
  270. package/dist/application/speculation-integration.constants.js +5 -0
  271. package/dist/application/speculation-integration.constants.js.map +1 -0
  272. package/dist/application/speculation-integration.d.ts +2 -0
  273. package/dist/application/speculation-integration.js +67 -0
  274. package/dist/application/speculation-integration.js.map +1 -0
  275. package/dist/application/speculation-resume.d.ts +4 -0
  276. package/dist/application/speculation-resume.js +71 -0
  277. package/dist/application/speculation-resume.js.map +1 -0
  278. package/dist/application/speculation-run.d.ts +4 -0
  279. package/dist/application/speculation-run.js +320 -0
  280. package/dist/application/speculation-run.js.map +1 -0
  281. package/dist/application/speculation-timeout.d.ts +1 -0
  282. package/dist/application/speculation-timeout.js +15 -0
  283. package/dist/application/speculation-timeout.js.map +1 -0
  284. package/dist/application/speculation.constants.d.ts +1 -0
  285. package/dist/application/speculation.constants.js +5 -1
  286. package/dist/application/speculation.constants.js.map +1 -1
  287. package/dist/application/speculation.js +41 -149
  288. package/dist/application/speculation.js.map +1 -1
  289. package/dist/application/speculation.types.d.ts +23 -0
  290. package/dist/application/speculation.types.js.map +1 -1
  291. package/dist/application/startup-recovery.js +14 -1
  292. package/dist/application/startup-recovery.js.map +1 -1
  293. package/dist/application/startup-recovery.types.d.ts +1 -0
  294. package/dist/application/startup-recovery.types.js.map +1 -1
  295. package/dist/application/stop-reason.d.ts +2 -0
  296. package/dist/application/stop-reason.js +21 -0
  297. package/dist/application/stop-reason.js.map +1 -0
  298. package/dist/application/stop-reason.types.d.ts +4 -0
  299. package/dist/application/stop-reason.types.js +2 -0
  300. package/dist/application/stop-reason.types.js.map +1 -0
  301. package/dist/application/storage-reservation.js +9 -2
  302. package/dist/application/storage-reservation.js.map +1 -1
  303. package/dist/application/task-observation.d.ts +3 -0
  304. package/dist/application/task-observation.js +22 -0
  305. package/dist/application/task-observation.js.map +1 -0
  306. package/dist/application/task-usage.js +5 -12
  307. package/dist/application/task-usage.js.map +1 -1
  308. package/dist/application/tasks.js +41 -16
  309. package/dist/application/tasks.js.map +1 -1
  310. package/dist/application/tool-execution.js +42 -19
  311. package/dist/application/tool-execution.js.map +1 -1
  312. package/dist/application/workspace.js +6 -4
  313. package/dist/application/workspace.js.map +1 -1
  314. package/dist/cli/doctor-command.js +6 -2
  315. package/dist/cli/doctor-command.js.map +1 -1
  316. package/dist/cli/init-authentication.d.ts +4 -1
  317. package/dist/cli/init-authentication.js +28 -33
  318. package/dist/cli/init-authentication.js.map +1 -1
  319. package/dist/cli/init-command.js +3 -3
  320. package/dist/cli/init-command.js.map +1 -1
  321. package/dist/cli/main.constants.d.ts +50 -13
  322. package/dist/cli/main.constants.js +70 -8
  323. package/dist/cli/main.constants.js.map +1 -1
  324. package/dist/cli/main.js +2 -1
  325. package/dist/cli/main.js.map +1 -1
  326. package/dist/cli/scaffold-files.js +1 -1
  327. package/dist/cli/scaffold-files.js.map +1 -1
  328. package/dist/cli/scaffold-validation.js +29 -22
  329. package/dist/cli/scaffold-validation.js.map +1 -1
  330. package/dist/cli/scaffold.constants.d.ts +0 -1
  331. package/dist/cli/scaffold.constants.js +6 -2
  332. package/dist/cli/scaffold.constants.js.map +1 -1
  333. package/dist/cli/scaffold.types.d.ts +8 -2
  334. package/dist/cli/scaffold.types.js.map +1 -1
  335. package/dist/cli/starters.js +1 -3
  336. package/dist/cli/starters.js.map +1 -1
  337. package/dist/domain/agent-observation.d.ts +4 -0
  338. package/dist/domain/agent-observation.js +27 -0
  339. package/dist/domain/agent-observation.js.map +1 -0
  340. package/dist/domain/agent.types.d.ts +122 -14
  341. package/dist/domain/agent.types.js.map +1 -1
  342. package/dist/domain/authentication.constants.d.ts +3 -0
  343. package/dist/domain/authentication.constants.js +11 -0
  344. package/dist/domain/authentication.constants.js.map +1 -0
  345. package/dist/domain/authentication.d.ts +3 -0
  346. package/dist/domain/authentication.js +22 -0
  347. package/dist/domain/authentication.js.map +1 -0
  348. package/dist/domain/authentication.types.d.ts +5 -0
  349. package/dist/domain/authentication.types.js +2 -0
  350. package/dist/domain/authentication.types.js.map +1 -0
  351. package/dist/domain/harness.d.ts +2 -2
  352. package/dist/domain/harness.js +6 -0
  353. package/dist/domain/harness.js.map +1 -1
  354. package/dist/domain/harness.types.d.ts +4 -3
  355. package/dist/domain/harness.types.js.map +1 -1
  356. package/dist/domain/model.types.d.ts +8 -0
  357. package/dist/domain/model.types.js.map +1 -1
  358. package/dist/domain/observation.constants.d.ts +8 -0
  359. package/dist/domain/observation.constants.js +9 -0
  360. package/dist/domain/observation.constants.js.map +1 -0
  361. package/dist/domain/observation.d.ts +2 -0
  362. package/dist/domain/observation.js +190 -0
  363. package/dist/domain/observation.js.map +1 -0
  364. package/dist/domain/observation.types.d.ts +84 -0
  365. package/dist/domain/observation.types.js +2 -0
  366. package/dist/domain/observation.types.js.map +1 -0
  367. package/dist/domain/observed-operation.d.ts +2 -0
  368. package/dist/domain/observed-operation.js +30 -0
  369. package/dist/domain/observed-operation.js.map +1 -0
  370. package/dist/domain/sandbox.types.d.ts +2 -0
  371. package/dist/domain/sandbox.types.js.map +1 -1
  372. package/dist/domain/subagent.constants.d.ts +13 -0
  373. package/dist/domain/subagent.constants.js +9 -0
  374. package/dist/domain/subagent.constants.js.map +1 -0
  375. package/dist/domain/subagent.d.ts +4 -0
  376. package/dist/domain/subagent.js +28 -0
  377. package/dist/domain/subagent.js.map +1 -0
  378. package/dist/domain/subagent.types.d.ts +13 -0
  379. package/dist/domain/subagent.types.js +2 -0
  380. package/dist/domain/subagent.types.js.map +1 -0
  381. package/dist/domain/transcript.types.d.ts +2 -0
  382. package/dist/domain/transcript.types.js.map +1 -1
  383. package/dist/domain/usage.d.ts +1 -0
  384. package/dist/domain/usage.js +16 -0
  385. package/dist/domain/usage.js.map +1 -1
  386. package/dist/domain/workflow/budget.d.ts +7 -3
  387. package/dist/domain/workflow/budget.js +26 -0
  388. package/dist/domain/workflow/budget.js.map +1 -1
  389. package/dist/domain/workflow/budget.types.d.ts +1 -1
  390. package/dist/domain/workflow/budget.types.js.map +1 -1
  391. package/dist/domain/workflow/checkpoint-validation.js +7 -1
  392. package/dist/domain/workflow/checkpoint-validation.js.map +1 -1
  393. package/dist/domain/workflow/checkpoint.js +3 -0
  394. package/dist/domain/workflow/checkpoint.js.map +1 -1
  395. package/dist/domain/workflow/gate-validation.js +14 -1
  396. package/dist/domain/workflow/gate-validation.js.map +1 -1
  397. package/dist/domain/workflow/gates.d.ts +1 -1
  398. package/dist/domain/workflow/gates.js +52 -4
  399. package/dist/domain/workflow/gates.js.map +1 -1
  400. package/dist/domain/workflow/gates.types.d.ts +15 -1
  401. package/dist/domain/workflow/gates.types.js.map +1 -1
  402. package/dist/domain/workflow/idempotency.d.ts +1 -0
  403. package/dist/domain/workflow/idempotency.js +7 -0
  404. package/dist/domain/workflow/idempotency.js.map +1 -0
  405. package/dist/domain/workflow/retry.constants.d.ts +2 -0
  406. package/dist/domain/workflow/retry.constants.js +3 -0
  407. package/dist/domain/workflow/retry.constants.js.map +1 -0
  408. package/dist/domain/workflow/retry.d.ts +4 -0
  409. package/dist/domain/workflow/retry.js +49 -0
  410. package/dist/domain/workflow/retry.js.map +1 -0
  411. package/dist/domain/workflow/task-runner.js +9 -5
  412. package/dist/domain/workflow/task-runner.js.map +1 -1
  413. package/dist/domain/workflow/task.js +6 -6
  414. package/dist/domain/workflow/task.js.map +1 -1
  415. package/dist/domain/workflow/workflow-scheduler.js +110 -72
  416. package/dist/domain/workflow/workflow-scheduler.js.map +1 -1
  417. package/dist/domain/workflow/workflow-state.js +28 -12
  418. package/dist/domain/workflow/workflow-state.js.map +1 -1
  419. package/dist/domain/workflow.d.ts +1 -1
  420. package/dist/domain/workflow.js +1 -1
  421. package/dist/domain/workflow.js.map +1 -1
  422. package/dist/domain/workflow.types.d.ts +13 -2
  423. package/dist/domain/workflow.types.js.map +1 -1
  424. package/dist/index.d.ts +16 -11
  425. package/dist/index.js +7 -4
  426. package/dist/index.js.map +1 -1
  427. package/dist/infrastructure/conversations/capture.js +10 -0
  428. package/dist/infrastructure/conversations/capture.js.map +1 -1
  429. package/dist/infrastructure/conversations/harness-transcript.js +6 -0
  430. package/dist/infrastructure/conversations/harness-transcript.js.map +1 -1
  431. package/dist/infrastructure/conversations/harness-transcript.types.d.ts +2 -0
  432. package/dist/infrastructure/conversations/harness-transcript.types.js.map +1 -1
  433. package/dist/infrastructure/conversations/layout.js +2 -0
  434. package/dist/infrastructure/conversations/layout.js.map +1 -1
  435. package/dist/infrastructure/conversations/locate.js +7 -1
  436. package/dist/infrastructure/conversations/locate.js.map +1 -1
  437. package/dist/infrastructure/conversations/native-store.js +8 -1
  438. package/dist/infrastructure/conversations/native-store.js.map +1 -1
  439. package/dist/infrastructure/conversations/paths.js +3 -0
  440. package/dist/infrastructure/conversations/paths.js.map +1 -1
  441. package/dist/infrastructure/conversations/restore.js +7 -0
  442. package/dist/infrastructure/conversations/restore.js.map +1 -1
  443. package/dist/infrastructure/conversations/session-bundle.constants.d.ts +5 -0
  444. package/dist/infrastructure/conversations/session-bundle.constants.js +173 -0
  445. package/dist/infrastructure/conversations/session-bundle.constants.js.map +1 -0
  446. package/dist/infrastructure/conversations/session-bundle.d.ts +6 -0
  447. package/dist/infrastructure/conversations/session-bundle.js +98 -0
  448. package/dist/infrastructure/conversations/session-bundle.js.map +1 -0
  449. package/dist/infrastructure/conversations/session-bundle.types.d.ts +1 -0
  450. package/dist/infrastructure/conversations/session-bundle.types.js +2 -0
  451. package/dist/infrastructure/conversations/session-bundle.types.js.map +1 -0
  452. package/dist/infrastructure/conversations.js +4 -2
  453. package/dist/infrastructure/conversations.js.map +1 -1
  454. package/dist/infrastructure/conversations.types.d.ts +1 -1
  455. package/dist/infrastructure/conversations.types.js.map +1 -1
  456. package/dist/infrastructure/custom-reporter.js +32 -24
  457. package/dist/infrastructure/custom-reporter.js.map +1 -1
  458. package/dist/infrastructure/custom-reporter.types.d.ts +2 -0
  459. package/dist/infrastructure/custom-reporter.types.js.map +1 -1
  460. package/dist/infrastructure/git/git.constants.d.ts +1 -1
  461. package/dist/infrastructure/git/git.constants.js +1 -0
  462. package/dist/infrastructure/git/git.constants.js.map +1 -1
  463. package/dist/infrastructure/git/workspace-lease.js +4 -3
  464. package/dist/infrastructure/git/workspace-lease.js.map +1 -1
  465. package/dist/infrastructure/git/workspace.js +7 -6
  466. package/dist/infrastructure/git/workspace.js.map +1 -1
  467. package/dist/infrastructure/git/workspace.types.d.ts +1 -0
  468. package/dist/infrastructure/git/workspace.types.js.map +1 -1
  469. package/dist/infrastructure/host-credentials.constants.d.ts +1 -0
  470. package/dist/infrastructure/host-credentials.constants.js +2 -0
  471. package/dist/infrastructure/host-credentials.constants.js.map +1 -0
  472. package/dist/infrastructure/host-credentials.d.ts +4 -0
  473. package/dist/infrastructure/host-credentials.js +89 -0
  474. package/dist/infrastructure/host-credentials.js.map +1 -0
  475. package/dist/infrastructure/inspection-path.js +4 -3
  476. package/dist/infrastructure/inspection-path.js.map +1 -1
  477. package/dist/infrastructure/journal.constants.js +10 -1
  478. package/dist/infrastructure/journal.constants.js.map +1 -1
  479. package/dist/infrastructure/journal.d.ts +1 -1
  480. package/dist/infrastructure/journal.js +8 -75
  481. package/dist/infrastructure/journal.js.map +1 -1
  482. package/dist/infrastructure/journal.types.d.ts +2 -4
  483. package/dist/infrastructure/journal.types.js.map +1 -1
  484. package/dist/infrastructure/local-transport.js +9 -4
  485. package/dist/infrastructure/local-transport.js.map +1 -1
  486. package/dist/infrastructure/opentelemetry-dispatch.d.ts +3 -3
  487. package/dist/infrastructure/opentelemetry-dispatch.js +5 -4
  488. package/dist/infrastructure/opentelemetry-dispatch.js.map +1 -1
  489. package/dist/infrastructure/opentelemetry-observation.d.ts +5 -0
  490. package/dist/infrastructure/opentelemetry-observation.js +59 -0
  491. package/dist/infrastructure/opentelemetry-observation.js.map +1 -0
  492. package/dist/infrastructure/opentelemetry.js +15 -1
  493. package/dist/infrastructure/opentelemetry.js.map +1 -1
  494. package/dist/infrastructure/opentelemetry.types.d.ts +9 -1
  495. package/dist/infrastructure/opentelemetry.types.js.map +1 -1
  496. package/dist/infrastructure/reporter.d.ts +2 -2
  497. package/dist/infrastructure/reporter.js +5 -1
  498. package/dist/infrastructure/reporter.js.map +1 -1
  499. package/dist/infrastructure/repository-transport.constants.d.ts +1 -0
  500. package/dist/infrastructure/repository-transport.constants.js +2 -0
  501. package/dist/infrastructure/repository-transport.constants.js.map +1 -0
  502. package/dist/infrastructure/repository-transport.d.ts +2 -0
  503. package/dist/infrastructure/repository-transport.js +9 -0
  504. package/dist/infrastructure/repository-transport.js.map +1 -0
  505. package/dist/infrastructure/resource-activity-inspection.js +19 -24
  506. package/dist/infrastructure/resource-activity-inspection.js.map +1 -1
  507. package/dist/infrastructure/resource-activity.constants.d.ts +0 -1
  508. package/dist/infrastructure/resource-activity.constants.js +0 -1
  509. package/dist/infrastructure/resource-activity.constants.js.map +1 -1
  510. package/dist/infrastructure/resource-activity.js +20 -83
  511. package/dist/infrastructure/resource-activity.js.map +1 -1
  512. package/dist/infrastructure/s3-transport.constants.d.ts +2 -0
  513. package/dist/infrastructure/s3-transport.constants.js +3 -0
  514. package/dist/infrastructure/s3-transport.constants.js.map +1 -0
  515. package/dist/infrastructure/s3-transport.js +57 -3
  516. package/dist/infrastructure/s3-transport.js.map +1 -1
  517. package/dist/infrastructure/s3-transport.types.d.ts +1 -0
  518. package/dist/infrastructure/s3-transport.types.js.map +1 -1
  519. package/dist/infrastructure/speculation-store.constants.d.ts +3 -0
  520. package/dist/infrastructure/speculation-store.constants.js +2 -0
  521. package/dist/infrastructure/speculation-store.constants.js.map +1 -0
  522. package/dist/infrastructure/speculation-store.d.ts +4 -0
  523. package/dist/infrastructure/speculation-store.js +73 -0
  524. package/dist/infrastructure/speculation-store.js.map +1 -0
  525. package/dist/infrastructure/speculation-store.types.d.ts +12 -0
  526. package/dist/infrastructure/speculation-store.types.js +2 -0
  527. package/dist/infrastructure/speculation-store.types.js.map +1 -0
  528. package/dist/infrastructure/storage-inventory.constants.js +1 -0
  529. package/dist/infrastructure/storage-inventory.constants.js.map +1 -1
  530. package/dist/infrastructure/storage-inventory.types.d.ts +1 -1
  531. package/dist/infrastructure/storage-inventory.types.js.map +1 -1
  532. package/dist/infrastructure/storage-reservations.types.d.ts +0 -8
  533. package/dist/infrastructure/storage-reservations.types.js.map +1 -1
  534. package/dist/infrastructure/task-queue-bullmq-resources.js +3 -0
  535. package/dist/infrastructure/task-queue-bullmq-resources.js.map +1 -1
  536. package/dist/infrastructure/task-queue-http.js +29 -4
  537. package/dist/infrastructure/task-queue-http.js.map +1 -1
  538. package/dist/infrastructure/task-queue-http.types.d.ts +2 -2
  539. package/dist/infrastructure/task-queue-http.types.js.map +1 -1
  540. package/dist/infrastructure/transport-conversations.js +2 -0
  541. package/dist/infrastructure/transport-conversations.js.map +1 -1
  542. package/dist/infrastructure/transport-journal.d.ts +1 -1
  543. package/dist/infrastructure/transport-journal.js +8 -2
  544. package/dist/infrastructure/transport-journal.js.map +1 -1
  545. package/dist/infrastructure/transport-reservations.d.ts +1 -1
  546. package/dist/infrastructure/transport-reservations.js +14 -8
  547. package/dist/infrastructure/transport-reservations.js.map +1 -1
  548. package/dist/infrastructure/workflow-decision-signature.constants.d.ts +4 -0
  549. package/dist/infrastructure/workflow-decision-signature.constants.js +5 -0
  550. package/dist/infrastructure/workflow-decision-signature.constants.js.map +1 -0
  551. package/dist/infrastructure/workflow-decision-signature.d.ts +4 -0
  552. package/dist/infrastructure/workflow-decision-signature.js +83 -0
  553. package/dist/infrastructure/workflow-decision-signature.js.map +1 -0
  554. package/dist/infrastructure/workflow-decision-signature.types.d.ts +16 -0
  555. package/dist/infrastructure/workflow-decision-signature.types.js +2 -0
  556. package/dist/infrastructure/workflow-decision-signature.types.js.map +1 -0
  557. package/dist/providers/agents.d.ts +7 -2
  558. package/dist/providers/agents.js +4 -1
  559. package/dist/providers/agents.js.map +1 -1
  560. package/dist/providers/antigravity-install.constants.d.ts +2 -0
  561. package/dist/providers/antigravity-install.constants.js +28 -0
  562. package/dist/providers/antigravity-install.constants.js.map +1 -0
  563. package/dist/providers/antigravity-install.d.ts +2 -0
  564. package/dist/providers/antigravity-install.js +29 -0
  565. package/dist/providers/antigravity-install.js.map +1 -0
  566. package/dist/providers/antigravity-install.types.d.ts +4 -0
  567. package/dist/providers/antigravity-install.types.js +2 -0
  568. package/dist/providers/antigravity-install.types.js.map +1 -0
  569. package/dist/providers/container-recovery.d.ts +4 -0
  570. package/dist/providers/container-recovery.js +28 -0
  571. package/dist/providers/container-recovery.js.map +1 -0
  572. package/dist/providers/container.js +8 -0
  573. package/dist/providers/container.js.map +1 -1
  574. package/dist/providers/daytona-network.constants.d.ts +5 -0
  575. package/dist/providers/daytona-network.constants.js +8 -0
  576. package/dist/providers/daytona-network.constants.js.map +1 -0
  577. package/dist/providers/daytona-network.d.ts +4 -0
  578. package/dist/providers/daytona-network.js +33 -0
  579. package/dist/providers/daytona-network.js.map +1 -0
  580. package/dist/providers/daytona.d.ts +1 -0
  581. package/dist/providers/daytona.js +9 -3
  582. package/dist/providers/daytona.js.map +1 -1
  583. package/dist/providers/daytona.types.d.ts +2 -0
  584. package/dist/providers/daytona.types.js.map +1 -1
  585. package/dist/providers/firecracker-command.js +1 -1
  586. package/dist/providers/firecracker-command.js.map +1 -1
  587. package/dist/providers/firecracker-jailer.constants.d.ts +9 -0
  588. package/dist/providers/firecracker-jailer.constants.js +10 -0
  589. package/dist/providers/firecracker-jailer.constants.js.map +1 -0
  590. package/dist/providers/firecracker-jailer.d.ts +4 -0
  591. package/dist/providers/firecracker-jailer.js +171 -0
  592. package/dist/providers/firecracker-jailer.js.map +1 -0
  593. package/dist/providers/firecracker-machine.js +30 -8
  594. package/dist/providers/firecracker-machine.js.map +1 -1
  595. package/dist/providers/firecracker.types.d.ts +16 -0
  596. package/dist/providers/firecracker.types.js.map +1 -1
  597. package/dist/providers/vercel-network.js +1 -1
  598. package/dist/providers/vercel-network.js.map +1 -1
  599. package/dist/providers/vercel.js +6 -3
  600. package/dist/providers/vercel.js.map +1 -1
  601. package/dist/providers/versions.constants.d.ts +3 -1
  602. package/dist/providers/versions.constants.js +3 -1
  603. package/dist/providers/versions.constants.js.map +1 -1
  604. package/package.json +3 -3
  605. package/dist/adapters/agents/gemini-adapter.d.ts +0 -3
  606. package/dist/adapters/agents/gemini-adapter.js +0 -34
  607. package/dist/adapters/agents/gemini-adapter.js.map +0 -1
  608. package/dist/adapters/agents/gemini-diagnostics.d.ts +0 -2
  609. package/dist/adapters/agents/gemini-diagnostics.js +0 -15
  610. package/dist/adapters/agents/gemini-diagnostics.js.map +0 -1
  611. package/dist/adapters/agents/gemini-events.d.ts +0 -2
  612. package/dist/adapters/agents/gemini-events.js +0 -50
  613. package/dist/adapters/agents/gemini-events.js.map +0 -1
  614. package/dist/adapters/agents/gemini-request.js +0 -23
  615. package/dist/adapters/agents/gemini-request.js.map +0 -1
  616. package/dist/adapters/agents/gemini.types.js +0 -2
  617. package/dist/adapters/agents/gemini.types.js.map +0 -1
  618. package/dist/infrastructure/artifact-store.d.ts +0 -3
  619. package/dist/infrastructure/artifact-store.js +0 -110
  620. package/dist/infrastructure/artifact-store.js.map +0 -1
  621. package/dist/infrastructure/artifact-store.types.d.ts +0 -6
  622. package/dist/infrastructure/artifact-store.types.js +0 -2
  623. package/dist/infrastructure/artifact-store.types.js.map +0 -1
  624. package/dist/infrastructure/journal-retention.constants.d.ts +0 -4
  625. package/dist/infrastructure/journal-retention.constants.js +0 -5
  626. package/dist/infrastructure/journal-retention.constants.js.map +0 -1
  627. package/dist/infrastructure/journal-retention.d.ts +0 -2
  628. package/dist/infrastructure/journal-retention.js +0 -51
  629. package/dist/infrastructure/journal-retention.js.map +0 -1
  630. package/dist/infrastructure/storage-mutation-lock.constants.d.ts +0 -5
  631. package/dist/infrastructure/storage-mutation-lock.constants.js +0 -6
  632. package/dist/infrastructure/storage-mutation-lock.constants.js.map +0 -1
  633. package/dist/infrastructure/storage-mutation-lock.d.ts +0 -1
  634. package/dist/infrastructure/storage-mutation-lock.js +0 -21
  635. package/dist/infrastructure/storage-mutation-lock.js.map +0 -1
  636. package/dist/infrastructure/storage-reservations.constants.d.ts +0 -4
  637. package/dist/infrastructure/storage-reservations.constants.js +0 -5
  638. package/dist/infrastructure/storage-reservations.constants.js.map +0 -1
  639. package/dist/infrastructure/storage-reservations.d.ts +0 -2
  640. package/dist/infrastructure/storage-reservations.js +0 -150
  641. package/dist/infrastructure/storage-reservations.js.map +0 -1
  642. package/dist/infrastructure/workflow-checkpoint.d.ts +0 -3
  643. package/dist/infrastructure/workflow-checkpoint.js +0 -84
  644. package/dist/infrastructure/workflow-checkpoint.js.map +0 -1
  645. package/dist/infrastructure/workflow-checkpoint.types.d.ts +0 -6
  646. package/dist/infrastructure/workflow-checkpoint.types.js +0 -2
  647. package/dist/infrastructure/workflow-checkpoint.types.js.map +0 -1
@@ -0,0 +1,206 @@
1
+ import { createHash } from "node:crypto";
2
+ import { realpath } from "node:fs/promises";
3
+ import { checkpointValue } from "../domain/workflow/checkpoint-value.js";
4
+ export async function speculationIdentity(options) {
5
+ return createHash("sha256")
6
+ .update(JSON.stringify({
7
+ repository: await realpath(options.repository),
8
+ version: options.durability?.version,
9
+ provider: options.sandboxProvider.name,
10
+ placement: options.sandboxProvider.placement,
11
+ candidates: options.candidates.map(({ key, request }) => ({
12
+ key,
13
+ brief: request.brief,
14
+ response: request.response?.tag,
15
+ })),
16
+ budget: options.budget,
17
+ }))
18
+ .digest("hex");
19
+ }
20
+ function diagnostic(value) {
21
+ try {
22
+ return String(value);
23
+ }
24
+ catch {
25
+ return "Unprintable speculation error";
26
+ }
27
+ }
28
+ export function encodeSpeculation(state) {
29
+ for (const attempt of state.attempts)
30
+ if (attempt.record?.result)
31
+ checkpointValue(attempt.record.result.value);
32
+ const encoded = JSON.parse(JSON.stringify({
33
+ ...state,
34
+ attempts: state.attempts.map((attempt) => ({
35
+ ...attempt,
36
+ ...(attempt.record
37
+ ? {
38
+ record: {
39
+ ...attempt.record,
40
+ ...(attempt.record.error !== undefined
41
+ ? { error: diagnostic(attempt.record.error) }
42
+ : {}),
43
+ ...(attempt.record.result
44
+ ? {
45
+ result: {
46
+ ...attempt.record.result,
47
+ ...(attempt.record.result.observerErrors
48
+ ? {
49
+ observerErrors: attempt.record.result.observerErrors.map(diagnostic),
50
+ }
51
+ : {}),
52
+ },
53
+ }
54
+ : {}),
55
+ },
56
+ }
57
+ : {}),
58
+ })),
59
+ }));
60
+ const value = checkpointValue(encoded);
61
+ if (value.kind !== "json")
62
+ throw new Error("Missing speculation state");
63
+ return value.value;
64
+ }
65
+ function object(value) {
66
+ return !!value && typeof value === "object" && !Array.isArray(value);
67
+ }
68
+ function integer(value) {
69
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
70
+ }
71
+ function usage(value) {
72
+ return (object(value) &&
73
+ ["input", "cached", "output"].every((key) => integer(value[key])) &&
74
+ Object.entries(value).every(([key, count]) => key === "complete" ? typeof count === "boolean" : integer(count)));
75
+ }
76
+ function output(value) {
77
+ if (!object(value) ||
78
+ typeof value.text !== "string" ||
79
+ typeof value.completed !== "boolean" ||
80
+ !usage(value.usage) ||
81
+ typeof value.branch !== "string" ||
82
+ typeof value.directory !== "string" ||
83
+ !Array.isArray(value.turns) ||
84
+ !Array.isArray(value.commits))
85
+ return false;
86
+ if (!value.turns.every((turn) => object(turn) &&
87
+ typeof turn.text === "string" &&
88
+ integer(turn.status) &&
89
+ typeof turn.durationMs === "number" &&
90
+ usage(turn.usage)))
91
+ return false;
92
+ if (!value.commits.every((commit) => object(commit) &&
93
+ typeof commit.oid === "string" &&
94
+ typeof commit.subject === "string"))
95
+ return false;
96
+ for (const key of [
97
+ "conversation",
98
+ "completion",
99
+ "transcript",
100
+ "retainedDirectory",
101
+ ])
102
+ if (value[key] !== undefined && typeof value[key] !== "string")
103
+ return false;
104
+ for (const key of ["logReference", "transcriptReference"]) {
105
+ const reference = value[key];
106
+ if (reference !== undefined &&
107
+ (!object(reference) ||
108
+ typeof reference.key !== "string" ||
109
+ typeof reference.revision !== "string"))
110
+ return false;
111
+ }
112
+ return true;
113
+ }
114
+ export function validateSpeculation(value, identity, keys) {
115
+ const invalid = () => new Error("Invalid or incompatible speculation checkpoint");
116
+ if (!object(value) ||
117
+ value.format !== 1 ||
118
+ value.identity !== identity ||
119
+ typeof value.id !== "string" ||
120
+ !/^[a-f0-9-]{36}$/.test(value.id) ||
121
+ typeof value.finished !== "boolean" ||
122
+ !object(value.before) ||
123
+ typeof value.before.head !== "string" ||
124
+ !/^[a-f0-9]{40,64}$/.test(value.before.head) ||
125
+ typeof value.before.branch !== "string" ||
126
+ typeof value.before.fingerprint !== "string" ||
127
+ typeof value.before.dirty !== "boolean" ||
128
+ !Array.isArray(value.attempts) ||
129
+ !object(value.usage) ||
130
+ !integer(value.usage.attempts) ||
131
+ !usage(value.usage.tokens))
132
+ throw invalid();
133
+ if (value.status !== undefined &&
134
+ !["winner", "no-winner", "aborted", "budget-exhausted"].includes(String(value.status)))
135
+ throw invalid();
136
+ if (value.error !== undefined && typeof value.error !== "string")
137
+ throw invalid();
138
+ const attempts = new Map();
139
+ let admitted = 0, winners = 0;
140
+ for (const item of value.attempts) {
141
+ if (!object(item) ||
142
+ typeof item.key !== "string" ||
143
+ !keys.includes(item.key) ||
144
+ !integer(item.attempt) ||
145
+ item.attempt !== (attempts.get(item.key) ?? 0) + 1 ||
146
+ item.branch !==
147
+ `outpost/speculation/${value.id}/${item.key}/${item.attempt}` ||
148
+ !["waiting", "running", "validated", "settled"].includes(String(item.phase)) ||
149
+ !["pending", "done"].includes(String(item.cleanup)))
150
+ throw invalid();
151
+ attempts.set(item.key, item.attempt);
152
+ if (item.phase !== "waiting")
153
+ admitted++;
154
+ for (const key of ["resourceId", "directory"])
155
+ if (item[key] !== undefined && typeof item[key] !== "string")
156
+ throw invalid();
157
+ if (item.accepted !== undefined && typeof item.accepted !== "boolean")
158
+ throw invalid();
159
+ if (item.phase === "validated" && typeof item.accepted !== "boolean")
160
+ throw invalid();
161
+ const record = item.record;
162
+ if (record !== undefined) {
163
+ if (!object(record) ||
164
+ record.key !== item.key ||
165
+ record.branch !== item.branch ||
166
+ !["winner", "rejected", "failed", "cancelled", "skipped"].includes(String(record.status)))
167
+ throw invalid();
168
+ if (record.status === "winner") {
169
+ if (item.phase !== "settled" ||
170
+ item.accepted !== true ||
171
+ !record.result ||
172
+ typeof record.commit !== "string" ||
173
+ !/^[a-f0-9]{40,64}$/.test(record.commit))
174
+ throw invalid();
175
+ winners++;
176
+ }
177
+ if (record.attempt !== undefined && record.attempt !== item.attempt)
178
+ throw invalid();
179
+ if (record.cleanup !== undefined && record.cleanup !== item.cleanup)
180
+ throw invalid();
181
+ if (record.result !== undefined && !output(record.result))
182
+ throw invalid();
183
+ for (const key of [
184
+ "directory",
185
+ "retainedDirectory",
186
+ "error",
187
+ "resourceId",
188
+ "commit",
189
+ ])
190
+ if (record[key] !== undefined && typeof record[key] !== "string")
191
+ throw invalid();
192
+ if (record.result &&
193
+ object(record.result) &&
194
+ !Object.hasOwn(record.result, "value"))
195
+ record.result.value = undefined;
196
+ }
197
+ if (item.phase === "settled" && !record)
198
+ throw invalid();
199
+ }
200
+ if (attempts.size !== keys.length ||
201
+ admitted !== value.usage.attempts ||
202
+ winners > 1 ||
203
+ (value.finished && (value.status === "winner") !== (winners === 1)))
204
+ throw invalid();
205
+ }
206
+ //# sourceMappingURL=speculation-checkpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speculation-checkpoint.js","sourceRoot":"","sources":["../../src/application/speculation-checkpoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAKzE,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,OAA8B;IAE9B,OAAO,UAAU,CAAC,QAAQ,CAAC;SACxB,MAAM,CACL,IAAI,CAAC,SAAS,CAAC;QACb,UAAU,EAAE,MAAM,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC;QAC9C,OAAO,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO;QACpC,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,IAAI;QACtC,SAAS,EAAE,OAAO,CAAC,eAAe,CAAC,SAAS;QAC5C,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;YACxD,GAAG;YACH,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,GAAG;SAChC,CAAC,CAAC;QACH,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CACH;SACA,MAAM,CAAC,KAAK,CAAC,CAAC;AACnB,CAAC;AACD,SAAS,UAAU,CAAC,KAA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CAAC,OAAO;gBACjE,MAAM,OAAO,EAAE,CAAC;YAClB,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,IAAI,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO;gBACjE,MAAM,OAAO,EAAE,CAAC;YAClB,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;gBACvD,MAAM,OAAO,EAAE,CAAC;YAClB,KAAK,MAAM,GAAG,IAAI;gBAChB,WAAW;gBACX,mBAAmB;gBACnB,OAAO;gBACP,YAAY;gBACZ,QAAQ;aACT;gBACC,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,QAAQ;oBAC9D,MAAM,OAAO,EAAE,CAAC;YACpB,IACE,MAAM,CAAC,MAAM;gBACb,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;gBACrB,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAEtC,MAAM,CAAC,MAAM,CAAC,KAAK,GAAG,SAAS,CAAC;QACpC,CAAC;QACD,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,IAAI,CAAC,MAAM;YAAE,MAAM,OAAO,EAAE,CAAC;IAC3D,CAAC;IACD,IACE,QAAQ,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM;QAC7B,QAAQ,KAAK,KAAK,CAAC,KAAK,CAAC,QAAQ;QACjC,OAAO,GAAG,CAAC;QACX,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC;QAEnE,MAAM,OAAO,EAAE,CAAC;AACpB,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { realpath } from \"node:fs/promises\";\nimport { checkpointValue } from \"../domain/workflow/checkpoint-value.ts\";\nimport type { WorkflowJson } from \"../domain/workflow/checkpoint.types.ts\";\nimport type { SpeculationOptions } from \"./speculation.types.ts\";\nimport type { SpeculationCheckpoint } from \"./speculation-checkpoint.types.ts\";\n\nexport async function speculationIdentity<T>(\n options: SpeculationOptions<T>,\n): Promise<string> {\n return createHash(\"sha256\")\n .update(\n JSON.stringify({\n repository: await realpath(options.repository),\n version: options.durability?.version,\n provider: options.sandboxProvider.name,\n placement: options.sandboxProvider.placement,\n candidates: options.candidates.map(({ key, request }) => ({\n key,\n brief: request.brief,\n response: request.response?.tag,\n })),\n budget: options.budget,\n }),\n )\n .digest(\"hex\");\n}\nfunction diagnostic(value: unknown): string {\n try {\n return String(value);\n } catch {\n return \"Unprintable speculation error\";\n }\n}\n\nexport function encodeSpeculation<T>(\n state: SpeculationCheckpoint<T>,\n): WorkflowJson {\n for (const attempt of state.attempts)\n if (attempt.record?.result) checkpointValue(attempt.record.result.value);\n const encoded: unknown = JSON.parse(\n JSON.stringify({\n ...state,\n attempts: state.attempts.map((attempt) => ({\n ...attempt,\n ...(attempt.record\n ? {\n record: {\n ...attempt.record,\n ...(attempt.record.error !== undefined\n ? { error: diagnostic(attempt.record.error) }\n : {}),\n ...(attempt.record.result\n ? {\n result: {\n ...attempt.record.result,\n ...(attempt.record.result.observerErrors\n ? {\n observerErrors:\n attempt.record.result.observerErrors.map(\n diagnostic,\n ),\n }\n : {}),\n },\n }\n : {}),\n },\n }\n : {}),\n })),\n }),\n );\n const value = checkpointValue(encoded);\n if (value.kind !== \"json\") throw new Error(\"Missing speculation state\");\n return value.value;\n}\nfunction object(value: unknown): value is Record<string, unknown> {\n return !!value && typeof value === \"object\" && !Array.isArray(value);\n}\nfunction integer(value: unknown): value is number {\n return typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0;\n}\nfunction usage(value: unknown): boolean {\n return (\n object(value) &&\n [\"input\", \"cached\", \"output\"].every((key) => integer(value[key])) &&\n Object.entries(value).every(([key, count]) =>\n key === \"complete\" ? typeof count === \"boolean\" : integer(count),\n )\n );\n}\nfunction output(value: unknown): boolean {\n if (\n !object(value) ||\n typeof value.text !== \"string\" ||\n typeof value.completed !== \"boolean\" ||\n !usage(value.usage) ||\n typeof value.branch !== \"string\" ||\n typeof value.directory !== \"string\" ||\n !Array.isArray(value.turns) ||\n !Array.isArray(value.commits)\n )\n return false;\n if (\n !value.turns.every(\n (turn) =>\n object(turn) &&\n typeof turn.text === \"string\" &&\n integer(turn.status) &&\n typeof turn.durationMs === \"number\" &&\n usage(turn.usage),\n )\n )\n return false;\n if (\n !value.commits.every(\n (commit) =>\n object(commit) &&\n typeof commit.oid === \"string\" &&\n typeof commit.subject === \"string\",\n )\n )\n return false;\n for (const key of [\n \"conversation\",\n \"completion\",\n \"transcript\",\n \"retainedDirectory\",\n ])\n if (value[key] !== undefined && typeof value[key] !== \"string\")\n return false;\n for (const key of [\"logReference\", \"transcriptReference\"]) {\n const reference = value[key];\n if (\n reference !== undefined &&\n (!object(reference) ||\n typeof reference.key !== \"string\" ||\n typeof reference.revision !== \"string\")\n )\n return false;\n }\n return true;\n}\nexport function validateSpeculation<T>(\n value: unknown,\n identity: string,\n keys: readonly string[],\n): asserts value is SpeculationCheckpoint<T> {\n const invalid = () =>\n new Error(\"Invalid or incompatible speculation checkpoint\");\n if (\n !object(value) ||\n value.format !== 1 ||\n value.identity !== identity ||\n typeof value.id !== \"string\" ||\n !/^[a-f0-9-]{36}$/.test(value.id) ||\n typeof value.finished !== \"boolean\" ||\n !object(value.before) ||\n typeof value.before.head !== \"string\" ||\n !/^[a-f0-9]{40,64}$/.test(value.before.head) ||\n typeof value.before.branch !== \"string\" ||\n typeof value.before.fingerprint !== \"string\" ||\n typeof value.before.dirty !== \"boolean\" ||\n !Array.isArray(value.attempts) ||\n !object(value.usage) ||\n !integer(value.usage.attempts) ||\n !usage(value.usage.tokens)\n )\n throw invalid();\n if (\n value.status !== undefined &&\n ![\"winner\", \"no-winner\", \"aborted\", \"budget-exhausted\"].includes(\n String(value.status),\n )\n )\n throw invalid();\n if (value.error !== undefined && typeof value.error !== \"string\")\n throw invalid();\n const attempts = new Map<string, number>();\n let admitted = 0,\n winners = 0;\n for (const item of value.attempts) {\n if (\n !object(item) ||\n typeof item.key !== \"string\" ||\n !keys.includes(item.key) ||\n !integer(item.attempt) ||\n item.attempt !== (attempts.get(item.key) ?? 0) + 1 ||\n item.branch !==\n `outpost/speculation/${value.id}/${item.key}/${item.attempt}` ||\n ![\"waiting\", \"running\", \"validated\", \"settled\"].includes(\n String(item.phase),\n ) ||\n ![\"pending\", \"done\"].includes(String(item.cleanup))\n )\n throw invalid();\n attempts.set(item.key, item.attempt);\n if (item.phase !== \"waiting\") admitted++;\n for (const key of [\"resourceId\", \"directory\"])\n if (item[key] !== undefined && typeof item[key] !== \"string\")\n throw invalid();\n if (item.accepted !== undefined && typeof item.accepted !== \"boolean\")\n throw invalid();\n if (item.phase === \"validated\" && typeof item.accepted !== \"boolean\")\n throw invalid();\n const record = item.record;\n if (record !== undefined) {\n if (\n !object(record) ||\n record.key !== item.key ||\n record.branch !== item.branch ||\n ![\"winner\", \"rejected\", \"failed\", \"cancelled\", \"skipped\"].includes(\n String(record.status),\n )\n )\n throw invalid();\n if (record.status === \"winner\") {\n if (\n item.phase !== \"settled\" ||\n item.accepted !== true ||\n !record.result ||\n typeof record.commit !== \"string\" ||\n !/^[a-f0-9]{40,64}$/.test(record.commit)\n )\n throw invalid();\n winners++;\n }\n if (record.attempt !== undefined && record.attempt !== item.attempt)\n throw invalid();\n if (record.cleanup !== undefined && record.cleanup !== item.cleanup)\n throw invalid();\n if (record.result !== undefined && !output(record.result))\n throw invalid();\n for (const key of [\n \"directory\",\n \"retainedDirectory\",\n \"error\",\n \"resourceId\",\n \"commit\",\n ])\n if (record[key] !== undefined && typeof record[key] !== \"string\")\n throw invalid();\n if (\n record.result &&\n object(record.result) &&\n !Object.hasOwn(record.result, \"value\")\n )\n record.result.value = undefined;\n }\n if (item.phase === \"settled\" && !record) throw invalid();\n }\n if (\n attempts.size !== keys.length ||\n admitted !== value.usage.attempts ||\n winners > 1 ||\n (value.finished && (value.status === \"winner\") !== (winners === 1))\n )\n throw invalid();\n}\n"]}
@@ -0,0 +1,24 @@
1
+ import type { WorkflowUsage } from "../domain/workflow/budget.types.ts";
2
+ import type { SpeculativeCandidateResult, SpeculativeHostSnapshot } from "./speculation.types.ts";
3
+ export interface SpeculationAttempt<T> {
4
+ key: string;
5
+ attempt: number;
6
+ branch: string;
7
+ phase: "waiting" | "running" | "validated" | "settled";
8
+ resourceId?: string;
9
+ directory?: string;
10
+ cleanup: "pending" | "done";
11
+ accepted?: boolean;
12
+ record?: SpeculativeCandidateResult<T>;
13
+ }
14
+ export interface SpeculationCheckpoint<T> {
15
+ format: 1;
16
+ identity: string;
17
+ id: string;
18
+ before: SpeculativeHostSnapshot;
19
+ attempts: SpeculationAttempt<T>[];
20
+ usage: WorkflowUsage;
21
+ finished: boolean;
22
+ status?: "winner" | "no-winner" | "aborted" | "budget-exhausted";
23
+ error?: string;
24
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=speculation-checkpoint.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speculation-checkpoint.types.js","sourceRoot":"","sources":["../../src/application/speculation-checkpoint.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { WorkflowUsage } from \"../domain/workflow/budget.types.ts\";\nimport type {\n SpeculativeCandidateResult,\n SpeculativeHostSnapshot,\n} from \"./speculation.types.ts\";\n\nexport interface SpeculationAttempt<T> {\n key: string;\n attempt: number;\n branch: string;\n phase: \"waiting\" | \"running\" | \"validated\" | \"settled\";\n resourceId?: string;\n directory?: string;\n cleanup: \"pending\" | \"done\";\n accepted?: boolean;\n record?: SpeculativeCandidateResult<T>;\n}\nexport interface SpeculationCheckpoint<T> {\n format: 1;\n identity: string;\n id: string;\n before: SpeculativeHostSnapshot;\n attempts: SpeculationAttempt<T>[];\n usage: WorkflowUsage;\n finished: boolean;\n status?: \"winner\" | \"no-winner\" | \"aborted\" | \"budget-exhausted\";\n error?: string;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export declare const speculationIntegrationLimits: {
2
+ readonly deadlineMs: 30000;
3
+ readonly retainBytes: number;
4
+ };
@@ -0,0 +1,5 @@
1
+ export const speculationIntegrationLimits = {
2
+ deadlineMs: 30_000,
3
+ retainBytes: 1024 * 1024,
4
+ };
5
+ //# sourceMappingURL=speculation-integration.constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speculation-integration.constants.js","sourceRoot":"","sources":["../../src/application/speculation-integration.constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,UAAU,EAAE,MAAM;IAClB,WAAW,EAAE,IAAI,GAAG,IAAI;CAChB,CAAC","sourcesContent":["export const speculationIntegrationLimits = {\n deadlineMs: 30_000,\n retainBytes: 1024 * 1024,\n} as const;\n"]}
@@ -0,0 +1,2 @@
1
+ import type { SpeculationIntegration } from "./speculation.types.ts";
2
+ export declare function checkSpeculationIntegration(repository: string, branch: string, expectedCommit?: string): Promise<SpeculationIntegration>;
@@ -0,0 +1,67 @@
1
+ import { speculationIntegrationLimits } from "./speculation-integration.constants.js";
2
+ import { executeProcess } from "../infrastructure/process.js";
3
+ import { git } from "../infrastructure/git/command.js";
4
+ import { speculativeHostSnapshot } from "./speculation-host.js";
5
+ export async function checkSpeculationIntegration(repository, branch, expectedCommit) {
6
+ const host = await speculativeHostSnapshot(repository);
7
+ const blocked = (reason) => ({
8
+ status: "blocked",
9
+ host,
10
+ conflicts: [],
11
+ reason,
12
+ });
13
+ if (host.dirty)
14
+ return blocked("Host has uncommitted changes");
15
+ if (host.branch === "HEAD")
16
+ return blocked("Host HEAD is detached");
17
+ try {
18
+ const candidateCommit = (await git(repository, ["rev-parse", "--verify", `${branch}^{commit}`])).trim();
19
+ if (expectedCommit && candidateCommit !== expectedCommit)
20
+ return blocked("Candidate branch changed since validation");
21
+ const result = await executeProcess({
22
+ executable: "git",
23
+ arguments: [
24
+ "-c",
25
+ `core.hooksPath=${process.platform === "win32" ? "NUL" : "/dev/null"}`,
26
+ "merge-tree",
27
+ "--write-tree",
28
+ "--name-only",
29
+ "-z",
30
+ host.head,
31
+ candidateCommit,
32
+ ],
33
+ directory: repository,
34
+ deadlineMs: speculationIntegrationLimits.deadlineMs,
35
+ retain: speculationIntegrationLimits.retainBytes,
36
+ variables: { LC_ALL: "C", GIT_TERMINAL_PROMPT: "0" },
37
+ });
38
+ if (result.status !== 0 && result.status !== 1)
39
+ return blocked("Git merge-tree preflight failed: " + result.stderr);
40
+ if (result.stdout.length >= speculationIntegrationLimits.retainBytes)
41
+ return blocked("Git merge-tree output exceeded its limit");
42
+ const conflicts = result.status === 1
43
+ ? result.stdout
44
+ .split("\0")
45
+ .slice(1)
46
+ .filter((_, index, entries) => index < entries.indexOf(""))
47
+ : [];
48
+ const after = await speculativeHostSnapshot(repository);
49
+ const currentCandidate = (await git(repository, ["rev-parse", "--verify", `${branch}^{commit}`])).trim();
50
+ if (after.head !== host.head ||
51
+ after.dirty !== host.dirty ||
52
+ after.fingerprint !== host.fingerprint ||
53
+ after.branch !== host.branch ||
54
+ currentCandidate !== candidateCommit)
55
+ return blocked("Repository changed during integration preflight");
56
+ return {
57
+ status: result.status === 0 ? "clean" : "conflict",
58
+ host,
59
+ candidateCommit,
60
+ conflicts,
61
+ };
62
+ }
63
+ catch (error) {
64
+ return blocked(String(error));
65
+ }
66
+ }
67
+ //# sourceMappingURL=speculation-integration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speculation-integration.js","sourceRoot":"","sources":["../../src/application/speculation-integration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,GAAG,EAAE,MAAM,kCAAkC,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MA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AO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAChC,CAAC;AACH,CAAC","sourcesContent":["import { speculationIntegrationLimits } from \"./speculation-integration.constants.ts\";\nimport { executeProcess } from \"../infrastructure/process.ts\";\nimport { git } from \"../infrastructure/git/command.ts\";\nimport { speculativeHostSnapshot } from \"./speculation-host.ts\";\nimport type { SpeculationIntegration } from \"./speculation.types.ts\";\n\nexport async function checkSpeculationIntegration(\n repository: string,\n branch: string,\n expectedCommit?: string,\n): Promise<SpeculationIntegration> {\n const host = await speculativeHostSnapshot(repository);\n const blocked = (reason: string): SpeculationIntegration => ({\n status: \"blocked\",\n host,\n conflicts: [],\n reason,\n });\n if (host.dirty) return blocked(\"Host has uncommitted changes\");\n if (host.branch === \"HEAD\") return blocked(\"Host HEAD is detached\");\n try {\n const candidateCommit = (\n await git(repository, [\"rev-parse\", \"--verify\", `${branch}^{commit}`])\n ).trim();\n if (expectedCommit && candidateCommit !== expectedCommit)\n return blocked(\"Candidate branch changed since validation\");\n const result = await executeProcess({\n executable: \"git\",\n arguments: [\n \"-c\",\n `core.hooksPath=${process.platform === \"win32\" ? \"NUL\" : \"/dev/null\"}`,\n \"merge-tree\",\n \"--write-tree\",\n \"--name-only\",\n \"-z\",\n host.head,\n candidateCommit,\n ],\n directory: repository,\n deadlineMs: speculationIntegrationLimits.deadlineMs,\n retain: speculationIntegrationLimits.retainBytes,\n variables: { LC_ALL: \"C\", GIT_TERMINAL_PROMPT: \"0\" },\n });\n if (result.status !== 0 && result.status !== 1)\n return blocked(\"Git merge-tree preflight failed: \" + result.stderr);\n if (result.stdout.length >= speculationIntegrationLimits.retainBytes)\n return blocked(\"Git merge-tree output exceeded its limit\");\n const conflicts =\n result.status === 1\n ? result.stdout\n .split(\"\\0\")\n .slice(1)\n .filter((_, index, entries) => index < entries.indexOf(\"\"))\n : [];\n const after = await speculativeHostSnapshot(repository);\n const currentCandidate = (\n await git(repository, [\"rev-parse\", \"--verify\", `${branch}^{commit}`])\n ).trim();\n if (\n after.head !== host.head ||\n after.dirty !== host.dirty ||\n after.fingerprint !== host.fingerprint ||\n after.branch !== host.branch ||\n currentCandidate !== candidateCommit\n )\n return blocked(\"Repository changed during integration preflight\");\n return {\n status: result.status === 0 ? \"clean\" : \"conflict\",\n host,\n candidateCommit,\n conflicts,\n };\n } catch (error) {\n return blocked(String(error));\n }\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { WorkflowAccounting } from "../domain/workflow/budget.types.ts";
2
+ import type { SpeculationCheckpoint, SpeculationAttempt } from "./speculation-checkpoint.types.ts";
3
+ import type { SpeculationOptions } from "./speculation.types.ts";
4
+ export declare function resumeSpeculation<T>(options: SpeculationOptions<T>, state: SpeculationCheckpoint<T>, accounting: WorkflowAccounting, save: () => Promise<void>, cleanupMs: number): Promise<Map<string, SpeculationAttempt<T>>>;
@@ -0,0 +1,71 @@
1
+ import { invariant } from "../domain/errors.js";
2
+ import { speculationTimeout } from "./speculation-timeout.js";
3
+ export async function resumeSpeculation(options, state, accounting, save, cleanupMs) {
4
+ const latest = new Map(state.attempts.map((attempt) => [attempt.key, attempt]));
5
+ if (state.attempts.some((attempt) => attempt.phase !== "waiting" && attempt.phase !== "settled") &&
6
+ options.durability?.resume !== "retry-incomplete")
7
+ throw new Error("Interrupted speculation requires resume retry-incomplete to authorize replay");
8
+ await save();
9
+ for (const attempt of state.attempts) {
10
+ if (attempt.cleanup === "done")
11
+ continue;
12
+ if (attempt.resourceId) {
13
+ invariant(options.sandboxProvider.recover, "Sandbox provider cannot recover this resource");
14
+ await save();
15
+ await speculationTimeout(options.sandboxProvider.recover(attempt.resourceId, {
16
+ signal: AbortSignal.timeout(cleanupMs),
17
+ deadlineMs: cleanupMs,
18
+ }), cleanupMs);
19
+ }
20
+ attempt.cleanup = "done";
21
+ if (attempt.record)
22
+ attempt.record = { ...attempt.record, cleanup: "done" };
23
+ await save();
24
+ }
25
+ let recoveredWinner = state.attempts.some((attempt) => attempt.record?.status === "winner");
26
+ for (const previous of latest.values()) {
27
+ if (previous.phase === "waiting" || previous.phase === "settled")
28
+ continue;
29
+ if (previous.phase === "validated" && previous.record) {
30
+ previous.phase = "settled";
31
+ const accepted = previous.accepted && !recoveredWinner;
32
+ previous.record = {
33
+ ...previous.record,
34
+ status: accepted ? "winner" : "rejected",
35
+ cleanup: "done",
36
+ ...(previous.directory
37
+ ? { retainedDirectory: previous.directory }
38
+ : {}),
39
+ };
40
+ recoveredWinner ||= !!accepted;
41
+ continue;
42
+ }
43
+ accounting.report({ input: 0, cached: 0, output: 0, complete: false });
44
+ previous.phase = "settled";
45
+ previous.record = {
46
+ key: previous.key,
47
+ branch: previous.branch,
48
+ attempt: previous.attempt,
49
+ status: "cancelled",
50
+ cleanup: "done",
51
+ ...(previous.directory
52
+ ? {
53
+ directory: previous.directory,
54
+ retainedDirectory: previous.directory,
55
+ }
56
+ : {}),
57
+ error: "Interrupted by coordinator failure",
58
+ };
59
+ const attempt = {
60
+ key: previous.key,
61
+ attempt: previous.attempt + 1,
62
+ branch: `outpost/speculation/${state.id}/${previous.key}/${previous.attempt + 1}`,
63
+ phase: "waiting",
64
+ cleanup: "done",
65
+ };
66
+ state.attempts.push(attempt);
67
+ latest.set(attempt.key, attempt);
68
+ }
69
+ return latest;
70
+ }
71
+ //# sourceMappingURL=speculation-resume.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speculation-resume.js","sourceRoot":"","sources":["../../src/application/speculation-resume.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAOhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAA8B,EAC9B,KAA+B,EAC/B,UAA8B,EAC9B,IAAyB,EACzB,SAAiB;IAEjB,MAAM,MAAM,GAAG,IAAI,GAAG,CACpB,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAA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;YACP,KAAK,EAAE,oCAAoC;SAC5C,CAAC;QACF,MAAM,OAAO,GAA0B;YACrC,GAAG,EAAE,QAAQ,CAAC,GAAG;YACjB,OAAO,EAAE,QAAQ,CAAC,OAAO,GAAG,CAAC;YAC7B,MAAM,EAAE,uBAAuB,KAAK,CAAC,EAAE,IAAI,QAAQ,CAAC,GAAG,IAAI,QAAQ,CAAC,OAAO,GAAG,CAAC,EAAE;YACjF,KAAK,EAAE,SAAS;YAChB,OAAO,EAAE,MAAM;SAChB,CAAC;QACF,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC7B,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { invariant } from \"../domain/errors.ts\";\nimport type { WorkflowAccounting } from \"../domain/workflow/budget.types.ts\";\nimport type {\n SpeculationCheckpoint,\n SpeculationAttempt,\n} from \"./speculation-checkpoint.types.ts\";\nimport type { SpeculationOptions } from \"./speculation.types.ts\";\nimport { speculationTimeout } from \"./speculation-timeout.ts\";\n\nexport async function resumeSpeculation<T>(\n options: SpeculationOptions<T>,\n state: SpeculationCheckpoint<T>,\n accounting: WorkflowAccounting,\n save: () => Promise<void>,\n cleanupMs: number,\n): Promise<Map<string, SpeculationAttempt<T>>> {\n const latest = new Map(\n state.attempts.map((attempt) => [attempt.key, attempt]),\n );\n if (\n state.attempts.some(\n (attempt) => attempt.phase !== \"waiting\" && attempt.phase !== \"settled\",\n ) &&\n options.durability?.resume !== \"retry-incomplete\"\n )\n throw new Error(\n \"Interrupted speculation requires resume retry-incomplete to authorize replay\",\n );\n await save();\n for (const attempt of state.attempts) {\n if (attempt.cleanup === \"done\") continue;\n if (attempt.resourceId) {\n invariant(\n options.sandboxProvider.recover,\n \"Sandbox provider cannot recover this resource\",\n );\n await save();\n await speculationTimeout(\n options.sandboxProvider.recover(attempt.resourceId, {\n signal: AbortSignal.timeout(cleanupMs),\n deadlineMs: cleanupMs,\n }),\n cleanupMs,\n );\n }\n attempt.cleanup = \"done\";\n if (attempt.record) attempt.record = { ...attempt.record, cleanup: \"done\" };\n await save();\n }\n let recoveredWinner = state.attempts.some(\n (attempt) => attempt.record?.status === \"winner\",\n );\n for (const previous of latest.values()) {\n if (previous.phase === \"waiting\" || previous.phase === \"settled\") continue;\n if (previous.phase === \"validated\" && previous.record) {\n previous.phase = \"settled\";\n const accepted = previous.accepted && !recoveredWinner;\n previous.record = {\n ...previous.record,\n status: accepted ? \"winner\" : \"rejected\",\n cleanup: \"done\",\n ...(previous.directory\n ? { retainedDirectory: previous.directory }\n : {}),\n };\n recoveredWinner ||= !!accepted;\n continue;\n }\n accounting.report({ input: 0, cached: 0, output: 0, complete: false });\n previous.phase = \"settled\";\n previous.record = {\n key: previous.key,\n branch: previous.branch,\n attempt: previous.attempt,\n status: \"cancelled\",\n cleanup: \"done\",\n ...(previous.directory\n ? {\n directory: previous.directory,\n retainedDirectory: previous.directory,\n }\n : {}),\n error: \"Interrupted by coordinator failure\",\n };\n const attempt: SpeculationAttempt<T> = {\n key: previous.key,\n attempt: previous.attempt + 1,\n branch: `outpost/speculation/${state.id}/${previous.key}/${previous.attempt + 1}`,\n phase: \"waiting\",\n cleanup: \"done\",\n };\n state.attempts.push(attempt);\n latest.set(attempt.key, attempt);\n }\n return latest;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { SpeculationCheckpoint } from "./speculation-checkpoint.types.ts";
2
+ import type { SpeculationStoreSession } from "../infrastructure/speculation-store.types.ts";
3
+ import type { SpeculationOptions, SpeculationResult } from "./speculation.types.ts";
4
+ export declare function runSpeculation<T>(options: SpeculationOptions<T>, state: SpeculationCheckpoint<T>, session: SpeculationStoreSession | undefined, concurrency: number, cleanupMs: number): Promise<SpeculationResult<T>>;