@atolis-hq/wake 0.2.97 → 0.3.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 (442) hide show
  1. package/dist/src/activities/agent/agent-activity-definition.js +26 -0
  2. package/dist/src/activities/agent/agent-activity.js +171 -0
  3. package/dist/src/activities/agent/agent-result.js +149 -0
  4. package/dist/src/activities/contracts/activity.js +10 -0
  5. package/dist/src/activities/contracts/config.js +2 -0
  6. package/dist/src/activities/contracts/event-schema.js +302 -0
  7. package/dist/src/activities/contracts/events.js +42 -0
  8. package/dist/src/activities/contracts/identifiers.js +29 -0
  9. package/dist/src/activities/contracts/registry.js +71 -0
  10. package/dist/src/activities/contracts/streams.js +17 -0
  11. package/dist/src/activities/contracts/vocabulary.js +58 -0
  12. package/dist/src/activities/index.js +21 -0
  13. package/dist/src/activities/pr/activity-support.js +111 -0
  14. package/dist/src/activities/pr/application.js +158 -0
  15. package/dist/src/activities/pr/approve.js +85 -0
  16. package/dist/src/activities/pr/capability.js +11 -0
  17. package/dist/src/activities/pr/decision-claim.js +76 -0
  18. package/dist/src/activities/pr/event-drafts.js +66 -0
  19. package/dist/src/activities/pr/intent.js +37 -0
  20. package/dist/src/activities/pr/merge-authority-gate.js +14 -0
  21. package/dist/src/activities/pr/merge.js +110 -0
  22. package/dist/src/activities/pr/policy.js +135 -0
  23. package/dist/src/activities/pr/projection.js +130 -0
  24. package/dist/src/activities/pr/vocabulary.js +30 -0
  25. package/dist/src/activities/review/authorization.js +22 -0
  26. package/dist/src/activities/review/contracts.js +22 -0
  27. package/dist/src/activities/review/signals.js +3 -0
  28. package/dist/src/bootstrap/analytics-projection.js +26 -0
  29. package/dist/src/bootstrap/board-projection.js +337 -0
  30. package/dist/src/bootstrap/composition-root.js +382 -0
  31. package/dist/src/bootstrap/config/load-config.js +51 -0
  32. package/dist/src/bootstrap/config/root-schema.js +134 -0
  33. package/dist/src/bootstrap/external-ref.js +12 -0
  34. package/dist/src/bootstrap/fake-provider-files.js +44 -0
  35. package/dist/src/bootstrap/fake-scenarios.js +22 -0
  36. package/dist/src/bootstrap/index.js +48 -0
  37. package/dist/src/bootstrap/initialise.js +434 -0
  38. package/dist/src/bootstrap/paths.js +15 -0
  39. package/dist/src/bootstrap/projection-runtime.js +27 -0
  40. package/dist/src/bootstrap/runner-quota-reporter.js +21 -0
  41. package/dist/src/bootstrap/runner-registry.js +30 -0
  42. package/dist/src/bootstrap/schedule-checkpoint-store.js +49 -0
  43. package/dist/src/bootstrap/self-update-application.js +195 -0
  44. package/dist/src/bootstrap/self-update-failure-log.js +33 -0
  45. package/dist/src/bootstrap/source-update-port.js +47 -0
  46. package/dist/src/bootstrap/status-publish-activity.js +42 -0
  47. package/dist/src/bootstrap/surface-api-applications.js +325 -0
  48. package/dist/src/bootstrap/surface-api-execution-applications.js +95 -0
  49. package/dist/src/bootstrap/surface-api-metadata.js +12 -0
  50. package/dist/src/bootstrap/surface-api-projection-pages.js +22 -0
  51. package/dist/src/bootstrap/surface-api-run-context.js +5 -0
  52. package/dist/src/bootstrap/surface-api-transcripts.js +57 -0
  53. package/dist/src/bootstrap/surface-api-work-applications.js +199 -0
  54. package/dist/src/bootstrap/surface-applications.js +7 -0
  55. package/dist/src/bootstrap/surface-cli-applications.js +701 -0
  56. package/dist/src/bootstrap/update-ledger.js +61 -0
  57. package/dist/src/bootstrap/update-maintenance-lease.js +176 -0
  58. package/dist/src/{version.js → bootstrap/version.js} +35 -51
  59. package/dist/src/control-plane/application/advance-once.js +184 -0
  60. package/dist/src/control-plane/application/control-plane-projection.js +42 -0
  61. package/dist/src/control-plane/application/control-plane-service.js +42 -0
  62. package/dist/src/control-plane/application/intake-pipeline.js +29 -0
  63. package/dist/src/control-plane/application/runner-control-service.js +66 -0
  64. package/dist/src/control-plane/application/runner-pipeline.js +57 -0
  65. package/dist/src/control-plane/application/schedule-service.js +47 -0
  66. package/dist/src/control-plane/application/work-cancellation-policy.js +31 -0
  67. package/dist/src/control-plane/contracts/commands.js +10 -0
  68. package/dist/src/control-plane/contracts/config.js +22 -0
  69. package/dist/src/control-plane/contracts/events.js +81 -0
  70. package/dist/src/control-plane/contracts/streams.js +5 -0
  71. package/dist/src/control-plane/domain/dispatch-policy.js +15 -0
  72. package/dist/src/control-plane/domain/quota-policy.js +26 -0
  73. package/dist/src/control-plane/domain/runner-quota.js +35 -0
  74. package/dist/src/control-plane/domain/schedule-policy.js +46 -0
  75. package/dist/src/control-plane/index.js +20 -0
  76. package/dist/src/control-plane/infrastructure/intake-host.js +24 -0
  77. package/dist/src/control-plane/infrastructure/resident-host.js +45 -0
  78. package/dist/src/control-plane/infrastructure/tick-host.js +35 -0
  79. package/dist/src/execution/application/activation-claim.js +50 -0
  80. package/dist/src/execution/application/active-run-cancellation.js +14 -0
  81. package/dist/src/execution/application/execution-activity.js +97 -0
  82. package/dist/src/execution/application/execution-projection.js +17 -0
  83. package/dist/src/execution/application/execution-service.js +372 -0
  84. package/dist/src/execution/application/execution-validation.js +26 -0
  85. package/dist/src/execution/application/recovery-service.js +212 -0
  86. package/dist/src/execution/application/run-lifecycle.js +115 -0
  87. package/dist/src/execution/application/run-liveness-service.js +80 -0
  88. package/dist/src/execution/application/run-repository.js +27 -0
  89. package/dist/src/execution/contracts/commands.js +1 -0
  90. package/dist/src/execution/contracts/config.js +35 -0
  91. package/dist/src/execution/contracts/control-plane.js +1 -0
  92. package/dist/src/execution/contracts/event-factory.js +53 -0
  93. package/dist/src/execution/contracts/events.js +274 -0
  94. package/dist/src/execution/contracts/identifiers.js +5 -0
  95. package/dist/src/execution/contracts/liveness.js +1 -0
  96. package/dist/src/execution/contracts/results.js +1 -0
  97. package/dist/src/execution/contracts/runner.js +15 -0
  98. package/dist/src/execution/contracts/streams.js +10 -0
  99. package/dist/src/execution/contracts/views.js +1 -0
  100. package/dist/src/execution/contracts/vocabulary.js +43 -0
  101. package/dist/src/execution/contracts/workspace.js +1 -0
  102. package/dist/src/execution/domain/run-result.js +34 -0
  103. package/dist/src/execution/domain/run.js +142 -0
  104. package/dist/src/execution/index.js +31 -0
  105. package/dist/src/execution/infrastructure/agent-runner-adapter.js +114 -0
  106. package/dist/src/execution/infrastructure/process-execution.js +29 -0
  107. package/dist/src/execution/infrastructure/prompt-templates.js +42 -0
  108. package/dist/src/execution/infrastructure/runners/claude.js +120 -0
  109. package/dist/src/execution/infrastructure/runners/codex.js +143 -0
  110. package/dist/src/execution/infrastructure/runners/command.js +4 -0
  111. package/dist/src/execution/infrastructure/runners/cursor.js +69 -0
  112. package/dist/src/execution/infrastructure/runners/fake-scenarios.js +99 -0
  113. package/dist/src/execution/infrastructure/runners/fake.js +65 -0
  114. package/dist/src/execution/infrastructure/runners/registry.js +26 -0
  115. package/dist/src/execution/infrastructure/transcript-store.js +223 -0
  116. package/dist/src/execution/infrastructure/transcripts.js +11 -0
  117. package/dist/src/execution/infrastructure/workspace/fake-workspace.js +19 -0
  118. package/dist/src/execution/infrastructure/workspace/git-workspace.js +241 -0
  119. package/dist/src/integrations/application/agent-run-publication-reactor.js +111 -0
  120. package/dist/src/integrations/application/artifact-registration-reactor.js +159 -0
  121. package/dist/src/integrations/application/poll-service.js +25 -0
  122. package/dist/src/integrations/application/terminal-agent-run-report.js +40 -0
  123. package/dist/src/integrations/application/work-admission.js +31 -0
  124. package/dist/src/integrations/application/work-conclusion.js +19 -0
  125. package/dist/src/integrations/contracts/artifact-events.js +60 -0
  126. package/dist/src/integrations/contracts/artifact-vocabulary.js +9 -0
  127. package/dist/src/integrations/contracts/config.js +14 -0
  128. package/dist/src/integrations/contracts/identifiers.js +5 -0
  129. package/dist/src/integrations/contracts/intake-rules.js +14 -0
  130. package/dist/src/integrations/contracts/intake.js +1 -0
  131. package/dist/src/integrations/contracts/outcome-vocabulary.js +7 -0
  132. package/dist/src/integrations/contracts/provider.js +37 -0
  133. package/dist/src/integrations/contracts/streams.js +10 -0
  134. package/dist/src/integrations/delivery/application/delivery-outcome-reactor.js +75 -0
  135. package/dist/src/integrations/delivery/application/delivery-projector.js +165 -0
  136. package/dist/src/integrations/delivery/application/delivery-service.js +173 -0
  137. package/dist/src/integrations/delivery/contracts/commands.js +1 -0
  138. package/dist/src/integrations/delivery/contracts/config.js +1 -0
  139. package/dist/src/integrations/delivery/contracts/event-factory.js +18 -0
  140. package/dist/src/integrations/delivery/contracts/events.js +86 -0
  141. package/dist/src/integrations/delivery/contracts/intents.js +89 -0
  142. package/dist/src/integrations/delivery/contracts/views.js +1 -0
  143. package/dist/src/integrations/delivery/contracts/vocabulary.js +22 -0
  144. package/dist/src/integrations/fake/durable-delivery-provider.js +48 -0
  145. package/dist/src/integrations/fake/external-sink.js +9 -0
  146. package/dist/src/integrations/fake/external-source.js +44 -0
  147. package/dist/src/integrations/fake/inbound-translator.js +130 -0
  148. package/dist/src/integrations/fake/provider.js +95 -0
  149. package/dist/src/integrations/github/application/agent-context-reader.js +54 -0
  150. package/dist/src/integrations/github/application/agent-run-comment.js +94 -0
  151. package/dist/src/integrations/github/application/comment-history-reader.js +43 -0
  152. package/dist/src/integrations/github/application/inbound-context.js +10 -0
  153. package/dist/src/integrations/github/application/inbound-review-signals.js +159 -0
  154. package/dist/src/integrations/github/application/inbound-translator.js +231 -0
  155. package/dist/src/integrations/github/application/inbound-watch-gate-signals.js +84 -0
  156. package/dist/src/integrations/github/application/intake-policy.js +23 -0
  157. package/dist/src/integrations/github/application/outbound-translator.js +47 -0
  158. package/dist/src/integrations/github/application/poll-service.js +29 -0
  159. package/dist/src/integrations/github/application/pull-request-translation.js +10 -0
  160. package/dist/src/integrations/github/application/resource-links.js +8 -0
  161. package/dist/src/integrations/github/application/review-command-translator.js +16 -0
  162. package/dist/src/integrations/github/application/wake-labels.js +95 -0
  163. package/dist/src/integrations/github/contracts/config.js +47 -0
  164. package/dist/src/integrations/github/contracts/events.js +127 -0
  165. package/dist/src/integrations/github/contracts/external-key.js +19 -0
  166. package/dist/src/integrations/github/contracts/payloads.js +9 -0
  167. package/dist/src/integrations/github/contracts/vocabulary.js +55 -0
  168. package/dist/src/integrations/github/index.js +31 -0
  169. package/dist/src/integrations/github/infrastructure/client-reads.js +214 -0
  170. package/dist/src/integrations/github/infrastructure/client.js +132 -0
  171. package/dist/src/integrations/github/infrastructure/content-fingerprint.js +10 -0
  172. package/dist/src/integrations/github/infrastructure/delivery.js +31 -0
  173. package/dist/src/integrations/github/infrastructure/etag-cache.js +56 -0
  174. package/dist/src/integrations/github/infrastructure/gh-auth.js +19 -0
  175. package/dist/src/integrations/github/infrastructure/issue-source.js +109 -0
  176. package/dist/src/integrations/github/infrastructure/pr-source.js +186 -0
  177. package/dist/src/integrations/github/infrastructure/review-source.js +70 -0
  178. package/dist/src/integrations/github/infrastructure/source.js +108 -0
  179. package/dist/src/integrations/github/provider.js +96 -0
  180. package/dist/src/integrations/index.js +30 -0
  181. package/dist/src/kernel/contracts/checkpoint-store.js +1 -0
  182. package/dist/src/kernel/contracts/clock.js +1 -0
  183. package/dist/src/kernel/contracts/commands.js +1 -0
  184. package/dist/src/kernel/contracts/event-journal.js +2 -0
  185. package/dist/src/kernel/contracts/event-schema.js +54 -0
  186. package/dist/src/kernel/contracts/events.js +11 -0
  187. package/dist/src/kernel/contracts/id-generator.js +1 -0
  188. package/dist/src/kernel/contracts/identifiers.js +8 -0
  189. package/dist/src/kernel/contracts/projection-store.js +1 -0
  190. package/dist/src/kernel/contracts/relations.js +1 -0
  191. package/dist/src/kernel/contracts/schema.js +17 -0
  192. package/dist/src/kernel/contracts/vocabulary.js +6 -0
  193. package/dist/src/kernel/domain/event-envelope.js +29 -0
  194. package/dist/src/kernel/domain/match-mode.js +11 -0
  195. package/dist/src/kernel/domain/relation.js +10 -0
  196. package/dist/src/kernel/index.js +17 -0
  197. package/dist/src/{lib/clock.js → kernel/infrastructure/system-clock.js} +3 -3
  198. package/dist/src/kernel/infrastructure/ulid-id-generator.js +9 -0
  199. package/dist/src/main.js +137 -1030
  200. package/dist/src/orchestration/application/accept-activity-outcome.js +25 -0
  201. package/dist/src/orchestration/application/accept-signal.js +35 -0
  202. package/dist/src/orchestration/application/advance-workflow.js +160 -0
  203. package/dist/src/orchestration/application/coordination-claims.js +107 -0
  204. package/dist/src/orchestration/application/group-budget-recorder.js +43 -0
  205. package/dist/src/orchestration/application/orchestration-projection.js +20 -0
  206. package/dist/src/orchestration/application/orchestration-repository.js +36 -0
  207. package/dist/src/orchestration/application/orchestration-service.js +82 -0
  208. package/dist/src/orchestration/application/request-child.js +118 -0
  209. package/dist/src/orchestration/application/signal-reactor.js +17 -0
  210. package/dist/src/orchestration/application/start-workflow.js +51 -0
  211. package/dist/src/orchestration/application/watch-reactor.js +82 -0
  212. package/dist/src/orchestration/contracts/activity-outcome.js +18 -0
  213. package/dist/src/orchestration/contracts/commands.js +1 -0
  214. package/dist/src/orchestration/contracts/config.js +128 -0
  215. package/dist/src/orchestration/contracts/event-decoder.js +263 -0
  216. package/dist/src/orchestration/contracts/events.js +41 -0
  217. package/dist/src/orchestration/contracts/identifiers.js +35 -0
  218. package/dist/src/orchestration/contracts/streams.js +38 -0
  219. package/dist/src/orchestration/contracts/views.js +1 -0
  220. package/dist/src/orchestration/contracts/vocabulary.js +30 -0
  221. package/dist/src/orchestration/domain/activation-policy.js +55 -0
  222. package/dist/src/orchestration/domain/approval-defaults.js +17 -0
  223. package/dist/src/orchestration/domain/child-policy.js +63 -0
  224. package/dist/src/orchestration/domain/compiler.js +162 -0
  225. package/dist/src/orchestration/domain/coordination-events.js +25 -0
  226. package/dist/src/orchestration/domain/decision-events.js +47 -0
  227. package/dist/src/orchestration/domain/interpreter.js +49 -0
  228. package/dist/src/orchestration/domain/operator-retry-policy.js +34 -0
  229. package/dist/src/orchestration/domain/retry-policy.js +26 -0
  230. package/dist/src/orchestration/domain/signal-policy.js +120 -0
  231. package/dist/src/orchestration/domain/supplemental-policy.js +61 -0
  232. package/dist/src/orchestration/domain/transition.js +55 -0
  233. package/dist/src/orchestration/domain/workflow-graph.js +41 -0
  234. package/dist/src/orchestration/domain/workflow-instance-events.js +236 -0
  235. package/dist/src/orchestration/domain/workflow-instance.js +41 -0
  236. package/dist/src/orchestration/domain/workflow-selector.js +21 -0
  237. package/dist/src/orchestration/index.js +19 -0
  238. package/dist/src/persistence/application/projection-runner.js +79 -0
  239. package/dist/src/persistence/filesystem/file-checkpoint-store.js +35 -0
  240. package/dist/src/persistence/filesystem/file-event-journal.js +143 -0
  241. package/dist/src/persistence/filesystem/file-lock.js +91 -0
  242. package/dist/src/persistence/filesystem/file-projection-store.js +64 -0
  243. package/dist/src/persistence/index.js +8 -0
  244. package/dist/src/persistence/memory/in-memory-checkpoint-store.js +14 -0
  245. package/dist/src/persistence/memory/in-memory-event-journal.js +88 -0
  246. package/dist/src/persistence/memory/in-memory-projection-store.js +17 -0
  247. package/dist/src/resources/application/lookup-projections.js +48 -0
  248. package/dist/src/resources/application/resource-lookup.js +16 -0
  249. package/dist/src/resources/application/resource-projections.js +81 -0
  250. package/dist/src/resources/application/resource-repository.js +18 -0
  251. package/dist/src/resources/application/resource-service.js +83 -0
  252. package/dist/src/resources/contracts/commands.js +1 -0
  253. package/dist/src/resources/contracts/config.js +2 -0
  254. package/dist/src/resources/contracts/events.js +83 -0
  255. package/dist/src/resources/contracts/identifiers.js +15 -0
  256. package/dist/src/resources/contracts/streams.js +6 -0
  257. package/dist/src/resources/contracts/views.js +1 -0
  258. package/dist/src/resources/contracts/vocabulary.js +67 -0
  259. package/dist/src/resources/domain/correlation.js +8 -0
  260. package/dist/src/resources/domain/resource.js +58 -0
  261. package/dist/src/resources/index.js +14 -0
  262. package/dist/src/surfaces/api/contracts/activities.js +1 -0
  263. package/dist/src/surfaces/api/contracts/board.js +2 -0
  264. package/dist/src/surfaces/api/contracts/common.js +46 -0
  265. package/dist/src/surfaces/api/contracts/control-plane.js +5 -0
  266. package/dist/src/surfaces/api/contracts/events.js +1 -0
  267. package/dist/src/surfaces/api/contracts/execution.js +1 -0
  268. package/dist/src/surfaces/api/contracts/index.js +13 -0
  269. package/dist/src/surfaces/api/contracts/observability.js +1 -0
  270. package/dist/src/surfaces/api/contracts/orchestration.js +1 -0
  271. package/dist/src/surfaces/api/contracts/resources.js +1 -0
  272. package/dist/src/surfaces/api/contracts/status.js +1 -0
  273. package/dist/src/surfaces/api/contracts/system.js +1 -0
  274. package/dist/src/surfaces/api/contracts/transport-values.js +39 -0
  275. package/dist/src/surfaces/api/contracts/work.js +17 -0
  276. package/dist/src/surfaces/api/http-server.js +121 -0
  277. package/dist/src/surfaces/api/presenters/activities.js +1 -0
  278. package/dist/src/surfaces/api/presenters/board.js +3 -0
  279. package/dist/src/surfaces/api/presenters/control-plane.js +1 -0
  280. package/dist/src/surfaces/api/presenters/events.js +1 -0
  281. package/dist/src/surfaces/api/presenters/execution.js +59 -0
  282. package/dist/src/surfaces/api/presenters/observability.js +1 -0
  283. package/dist/src/surfaces/api/presenters/orchestration.js +19 -0
  284. package/dist/src/surfaces/api/presenters/resources.js +15 -0
  285. package/dist/src/surfaces/api/presenters/status.js +3 -0
  286. package/dist/src/surfaces/api/presenters/system.js +14 -0
  287. package/dist/src/surfaces/api/presenters/work.js +16 -0
  288. package/dist/src/surfaces/api/problem-details.js +9 -0
  289. package/dist/src/surfaces/api/router.js +13 -0
  290. package/dist/src/surfaces/api/routes/activities.js +1 -0
  291. package/dist/src/surfaces/api/routes/applications.js +1 -0
  292. package/dist/src/surfaces/api/routes/commands.js +82 -0
  293. package/dist/src/surfaces/api/routes/control-plane.js +6 -0
  294. package/dist/src/surfaces/api/routes/events.js +1 -0
  295. package/dist/src/surfaces/api/routes/execution.js +8 -0
  296. package/dist/src/surfaces/api/routes/index.js +18 -0
  297. package/dist/src/surfaces/api/routes/observability.js +1 -0
  298. package/dist/src/surfaces/api/routes/orchestration.js +1 -0
  299. package/dist/src/surfaces/api/routes/pagination.js +78 -0
  300. package/dist/src/surfaces/api/routes/read.js +135 -0
  301. package/dist/src/surfaces/api/routes/resources.js +1 -0
  302. package/dist/src/surfaces/api/routes/responses.js +67 -0
  303. package/dist/src/surfaces/api/routes/system.js +1 -0
  304. package/dist/src/surfaces/api/routes/work.js +9 -0
  305. package/dist/src/surfaces/cli/commands/api.js +1 -0
  306. package/dist/src/surfaces/cli/commands/audit.js +10 -0
  307. package/dist/src/surfaces/cli/commands/correlate.js +2 -0
  308. package/dist/src/surfaces/cli/commands/doctor.js +6 -0
  309. package/dist/src/surfaces/cli/commands/init.js +39 -0
  310. package/dist/src/surfaces/cli/commands/sandbox-entrypoint.js +33 -0
  311. package/dist/src/surfaces/cli/commands/sandbox-setup.js +29 -0
  312. package/dist/src/surfaces/cli/commands/sandbox.js +105 -0
  313. package/dist/src/surfaces/cli/commands/self-update.js +38 -0
  314. package/dist/src/surfaces/cli/commands/smoke.js +16 -0
  315. package/dist/src/surfaces/cli/commands/start.js +1 -0
  316. package/dist/src/surfaces/cli/commands/stop.js +13 -0
  317. package/dist/src/surfaces/cli/commands/tick.js +1 -0
  318. package/dist/src/surfaces/cli/commands/ui.js +2 -0
  319. package/dist/src/surfaces/cli/commands/validate-state.js +5 -0
  320. package/dist/src/surfaces/cli/infrastructure/docker-cli.js +221 -0
  321. package/dist/src/surfaces/cli/infrastructure/process-log.js +86 -0
  322. package/dist/src/surfaces/cli/main.js +140 -0
  323. package/dist/src/surfaces/cli/usage.js +33 -0
  324. package/dist/src/surfaces/contracts/config.js +34 -0
  325. package/dist/src/surfaces/index.js +47 -0
  326. package/dist/src/surfaces/web-assets/assets/index-Bfn4FwZG.css +1 -0
  327. package/dist/src/surfaces/web-assets/assets/index-ipB6JPGU.js +1090 -0
  328. package/dist/src/surfaces/web-assets/index.html +13 -0
  329. package/dist/src/surfaces/web-host/asset-source.js +1 -0
  330. package/dist/src/surfaces/web-host/packaged-assets.js +44 -0
  331. package/dist/src/work/application/work-projection.js +59 -0
  332. package/dist/src/work/application/work-repository.js +18 -0
  333. package/dist/src/work/application/work-service.js +117 -0
  334. package/dist/src/work/contracts/commands.js +1 -0
  335. package/dist/src/work/contracts/config.js +2 -0
  336. package/dist/src/work/contracts/events.js +103 -0
  337. package/dist/src/work/contracts/identifiers.js +5 -0
  338. package/dist/src/work/contracts/streams.js +6 -0
  339. package/dist/src/work/contracts/views.js +1 -0
  340. package/dist/src/work/contracts/vocabulary.js +6 -0
  341. package/dist/src/work/domain/work-item.js +89 -0
  342. package/dist/src/work/index.js +11 -0
  343. package/docker/Dockerfile +10 -6
  344. package/docker/Dockerfile.packaged +3 -3
  345. package/package.json +29 -4
  346. package/prompts/implement.md +2 -2
  347. package/templates/SETUP.md +7 -7
  348. package/dist/src/adapters/claude/claude-runner.js +0 -529
  349. package/dist/src/adapters/codex/codex-runner.js +0 -503
  350. package/dist/src/adapters/cursor/cursor-runner.js +0 -418
  351. package/dist/src/adapters/docker/docker-cli.js +0 -150
  352. package/dist/src/adapters/fake/fake-artifact-verifier.js +0 -14
  353. package/dist/src/adapters/fake/fake-github-pull-request-activity-source.js +0 -77
  354. package/dist/src/adapters/fake/fake-resource-index.js +0 -21
  355. package/dist/src/adapters/fake/fake-runner.js +0 -77
  356. package/dist/src/adapters/fake/fake-ticketing-system.js +0 -185
  357. package/dist/src/adapters/fake/fake-workspace-manager.js +0 -81
  358. package/dist/src/adapters/fs/resource-index.js +0 -126
  359. package/dist/src/adapters/fs/self-update-ledger.js +0 -17
  360. package/dist/src/adapters/fs/state-store.js +0 -775
  361. package/dist/src/adapters/git/git-workspace-manager.js +0 -289
  362. package/dist/src/adapters/github/github-artifact-verifier.js +0 -38
  363. package/dist/src/adapters/github/github-auth.js +0 -16
  364. package/dist/src/adapters/github/github-client.js +0 -249
  365. package/dist/src/adapters/github/github-etag-cache.js +0 -57
  366. package/dist/src/adapters/github/github-issues-work-source.js +0 -692
  367. package/dist/src/adapters/github/github-pull-request-activity-source.js +0 -584
  368. package/dist/src/adapters/github/github-pull-request-merge-actor.js +0 -45
  369. package/dist/src/adapters/http/ui-assets.js +0 -1188
  370. package/dist/src/adapters/http/ui-data.js +0 -1107
  371. package/dist/src/adapters/http/ui-server.js +0 -458
  372. package/dist/src/adapters/runner/cli-command.js +0 -73
  373. package/dist/src/adapters/runner/prompt-templates.js +0 -76
  374. package/dist/src/adapters/runner/runner-cli-adapter.js +0 -112
  375. package/dist/src/adapters/runner/runner-registry.js +0 -139
  376. package/dist/src/adapters/runner/runtime-events.js +0 -32
  377. package/dist/src/adapters/runner/stage-prompt.js +0 -268
  378. package/dist/src/adapters/runner/transcripts.js +0 -25
  379. package/dist/src/cli/audit-command.js +0 -36
  380. package/dist/src/cli/correlate-command.js +0 -62
  381. package/dist/src/cli/doctor-command.js +0 -48
  382. package/dist/src/cli/init-command.js +0 -18
  383. package/dist/src/cli/sandbox-command.js +0 -258
  384. package/dist/src/cli/sandbox-entrypoint-command.js +0 -88
  385. package/dist/src/cli/sandbox-exec-logging.js +0 -7
  386. package/dist/src/cli/sandbox-resume.js +0 -79
  387. package/dist/src/cli/sandbox-setup-command.js +0 -31
  388. package/dist/src/cli/scaffold-assets.js +0 -100
  389. package/dist/src/cli/self-update-command.js +0 -198
  390. package/dist/src/cli/startup-preflight.js +0 -134
  391. package/dist/src/cli/stop-command.js +0 -46
  392. package/dist/src/cli/ui-command.js +0 -27
  393. package/dist/src/config/defaults.js +0 -10
  394. package/dist/src/config/discover-config-files.js +0 -11
  395. package/dist/src/config/load-config.js +0 -69
  396. package/dist/src/config/split-config.js +0 -14
  397. package/dist/src/core/active-run-recovery.js +0 -44
  398. package/dist/src/core/approval-intents.js +0 -16
  399. package/dist/src/core/audit-events.js +0 -82
  400. package/dist/src/core/control-plane.js +0 -192
  401. package/dist/src/core/event-builders.js +0 -153
  402. package/dist/src/core/event-resolver.js +0 -249
  403. package/dist/src/core/lifecycle-service.js +0 -8
  404. package/dist/src/core/live-execution.js +0 -81
  405. package/dist/src/core/outbox.js +0 -198
  406. package/dist/src/core/policy-engine.js +0 -389
  407. package/dist/src/core/projection-updater.js +0 -693
  408. package/dist/src/core/quota-backoff.js +0 -69
  409. package/dist/src/core/run-lease.js +0 -38
  410. package/dist/src/core/scheduled-workflow-source.js +0 -199
  411. package/dist/src/core/sink-router.js +0 -107
  412. package/dist/src/core/stale-run-reconciler.js +0 -352
  413. package/dist/src/core/tick-runner.js +0 -2442
  414. package/dist/src/core/workspace-cleanup.js +0 -117
  415. package/dist/src/domain/branch-naming.js +0 -14
  416. package/dist/src/domain/custom-commands.js +0 -58
  417. package/dist/src/domain/event-types.js +0 -158
  418. package/dist/src/domain/manual-labels.js +0 -1
  419. package/dist/src/domain/resource-uri.js +0 -38
  420. package/dist/src/domain/runner-routing.js +0 -127
  421. package/dist/src/domain/runtime-events.js +0 -36
  422. package/dist/src/domain/schema.js +0 -1233
  423. package/dist/src/domain/sources.js +0 -16
  424. package/dist/src/domain/stages.js +0 -36
  425. package/dist/src/domain/work-item-labels.js +0 -48
  426. package/dist/src/domain/work-item-lifecycle.js +0 -10
  427. package/dist/src/domain/work-item-status.js +0 -33
  428. package/dist/src/domain/workflows.js +0 -159
  429. package/dist/src/lib/deep-merge.js +0 -14
  430. package/dist/src/lib/detached-process-logging.js +0 -46
  431. package/dist/src/lib/event-log.js +0 -21
  432. package/dist/src/lib/format.js +0 -41
  433. package/dist/src/lib/json-file.js +0 -23
  434. package/dist/src/lib/lock.js +0 -181
  435. package/dist/src/lib/log-rotation.js +0 -42
  436. package/dist/src/lib/paths.js +0 -52
  437. package/dist/src/lib/process-identity.js +0 -54
  438. package/dist/src/lib/state-health.js +0 -30
  439. package/dist/src/lib/work-id.js +0 -19
  440. package/dist/src/lib/yaml-file.js +0 -20
  441. /package/dist/src/{core → activities/pr}/contracts.js +0 -0
  442. /package/dist/src/{domain/types.js → control-plane/contracts/views.js} +0 -0
@@ -0,0 +1,29 @@
1
+ import { spawn } from 'node:child_process';
2
+ export function runProcess(command, args, cwd, signal, timeoutMs) {
3
+ const child = spawn(command, args, { cwd, shell: false, stdio: ['ignore', 'pipe', 'pipe'] });
4
+ const result = new Promise((resolve, reject) => {
5
+ let stdout = '';
6
+ let stderr = '';
7
+ let timedOut = false;
8
+ const timeout = timeoutMs === undefined
9
+ ? undefined
10
+ : setTimeout(() => {
11
+ timedOut = true;
12
+ child.kill();
13
+ }, timeoutMs);
14
+ child.stdout.on('data', (chunk) => (stdout += chunk.toString()));
15
+ child.stderr.on('data', (chunk) => (stderr += chunk.toString()));
16
+ child.once('error', (error) => {
17
+ if (timeout !== undefined)
18
+ clearTimeout(timeout);
19
+ reject(error);
20
+ });
21
+ child.once('close', (exitCode) => {
22
+ if (timeout !== undefined)
23
+ clearTimeout(timeout);
24
+ resolve({ stdout, stderr, exitCode, timedOut });
25
+ });
26
+ });
27
+ signal.addEventListener('abort', () => child.kill(), { once: true });
28
+ return { result, cancel: async () => void child.kill() };
29
+ }
@@ -0,0 +1,42 @@
1
+ import Handlebars from 'handlebars';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+ import YAML from 'yaml';
5
+ import { z } from 'zod';
6
+ const frontmatterSchema = z
7
+ .object({
8
+ model: z.string().trim().min(1).nullable().optional(),
9
+ maxTurns: z.number().int().positive().optional(),
10
+ allowedTools: z.array(z.string().trim().min(1)).nullable().optional(),
11
+ extraArgs: z.array(z.string()).nullable().optional(),
12
+ })
13
+ .strict();
14
+ export function renderPromptTemplate(template, context) {
15
+ return Handlebars.compile(template.body, { noEscape: true, strict: true })(context);
16
+ }
17
+ export async function loadPromptTemplate(wakeRoot, name) {
18
+ if (!/^[a-z0-9][a-z0-9-]*$/i.test(name))
19
+ throw new Error(`Invalid prompt template name: ${name}`);
20
+ const path = join(wakeRoot, 'prompts', `${name}.md`);
21
+ const source = await readFile(path, 'utf8');
22
+ const match = /^---\r?\n([\s\S]*?)---\r?\n?([\s\S]*)$/u.exec(source);
23
+ if (match === null)
24
+ throw new Error(`Prompt template ${path} must start with YAML frontmatter`);
25
+ const [, frontmatterSource, body] = match;
26
+ let parsed;
27
+ try {
28
+ parsed = YAML.parse(frontmatterSource);
29
+ }
30
+ catch (error) {
31
+ const message = error instanceof Error ? error.message : 'Unknown YAML parsing failure';
32
+ throw new Error(`Prompt template ${path} frontmatter is invalid: ${message}`, { cause: error });
33
+ }
34
+ const validated = frontmatterSchema.safeParse(parsed ?? {});
35
+ if (!validated.success) {
36
+ const details = validated.error.issues
37
+ .map((issue) => `${issue.path.join('.')}: ${issue.message}`)
38
+ .join('; ');
39
+ throw new Error(`Prompt template ${path} frontmatter is invalid: ${details}`);
40
+ }
41
+ return { name, body: body.trim(), frontmatter: validated.data };
42
+ }
@@ -0,0 +1,120 @@
1
+ import { ExternalExecutionKind } from '../../../activities/index.js';
2
+ import { ExecutionCancellationReason, RunStatus } from '../../contracts/vocabulary.js';
3
+ import { runProcess } from '../process-execution.js';
4
+ export function createClaudeRunner(options = {}) {
5
+ return cliRunner('claude', options.command ?? 'claude', (request) => claudeCommandArgs(request, options.args, options), {
6
+ ...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
7
+ ...(options.model === undefined ? {} : { defaultModel: options.model }),
8
+ parseSuccessfulOutput: parseClaudeOutput,
9
+ });
10
+ }
11
+ export function parseClaudeOutput(stdout, _request) {
12
+ const value = parseRecord(stdout);
13
+ if (value === undefined || typeof value.result !== 'string')
14
+ return {};
15
+ return {
16
+ output: value.result,
17
+ ...(typeof value.session_id === 'string' ? { sessionId: value.session_id } : {}),
18
+ ...claudeUsage(value),
19
+ };
20
+ }
21
+ function claudeUsage(value) {
22
+ const usage = record(value.usage);
23
+ const input = usage === undefined ? undefined : numeric(usage.input_tokens);
24
+ const output = usage === undefined ? undefined : numeric(usage.output_tokens);
25
+ if (usage === undefined || input === undefined || output === undefined)
26
+ return {};
27
+ const cacheRead = numeric(usage.cache_read_input_tokens);
28
+ const cacheWrite = numeric(usage.cache_creation_input_tokens);
29
+ const costUsd = numeric(value.total_cost_usd);
30
+ return {
31
+ tokenUsage: {
32
+ input,
33
+ output,
34
+ ...(cacheRead === undefined ? {} : { cacheRead }),
35
+ ...(cacheWrite === undefined ? {} : { cacheWrite }),
36
+ ...(costUsd === undefined ? {} : { costUsd }),
37
+ },
38
+ };
39
+ }
40
+ function parseRecord(stdout) {
41
+ try {
42
+ return record(JSON.parse(stdout));
43
+ }
44
+ catch {
45
+ return undefined;
46
+ }
47
+ }
48
+ function record(value) {
49
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
50
+ ? value
51
+ : undefined;
52
+ }
53
+ function numeric(value) {
54
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
55
+ }
56
+ export function claudeCommandArgs(request, passthroughArgs = [], defaults = {}) {
57
+ const model = request.model ?? defaults.model;
58
+ const effort = request.effort ?? defaults.effort;
59
+ return [
60
+ '-p',
61
+ '--output-format',
62
+ 'json',
63
+ ...(request.resumeSessionId === undefined ? [] : ['--resume', request.resumeSessionId]),
64
+ ...(model === undefined ? [] : ['--model', model]),
65
+ ...(effort === undefined ? [] : ['--effort', effort]),
66
+ ...(request.maxTurns === undefined ? [] : ['--max-turns', String(request.maxTurns)]),
67
+ ...(request.allowedTools.length === 0
68
+ ? []
69
+ : ['--allowedTools', request.allowedTools.join(' ')]),
70
+ ...passthroughArgs,
71
+ '--',
72
+ request.prompt,
73
+ ];
74
+ }
75
+ export function cliRunner(name, command, args, options = {}) {
76
+ return {
77
+ async start(request, signal) {
78
+ const process = runProcess(command, args(request), request.workspacePath, signal, options.timeoutMs);
79
+ return {
80
+ identity: {
81
+ kind: ExternalExecutionKind.Process,
82
+ id: request.runId,
83
+ startedAt: new Date().toISOString(),
84
+ },
85
+ result: process.result.then((value) => value.exitCode === 0 && !value.timedOut
86
+ ? {
87
+ transport: RunStatus.Succeeded,
88
+ output: value.stdout,
89
+ runner: name,
90
+ ...((request.model ?? options.defaultModel) === undefined
91
+ ? {}
92
+ : { model: request.model ?? options.defaultModel }),
93
+ ...parseSuccessfulOutput(value.stdout, request, options.parseSuccessfulOutput),
94
+ }
95
+ : {
96
+ transport: RunStatus.Failed,
97
+ output: value.stdout,
98
+ runner: name,
99
+ failure: {
100
+ kind: value.timedOut ? ExecutionCancellationReason.Timeout : 'process-exit',
101
+ message: value.timedOut
102
+ ? `Runner timed out after ${options.timeoutMs}ms`
103
+ : value.stderr || `exit ${value.exitCode}`,
104
+ },
105
+ }),
106
+ cancel: process.cancel,
107
+ };
108
+ },
109
+ };
110
+ }
111
+ function parseSuccessfulOutput(stdout, request, parser) {
112
+ if (parser === undefined)
113
+ return {};
114
+ try {
115
+ return parser(stdout, request);
116
+ }
117
+ catch {
118
+ return {};
119
+ }
120
+ }
@@ -0,0 +1,143 @@
1
+ import { WorkspaceMode } from '../../contracts/vocabulary.js';
2
+ import { cliRunner } from './claude.js';
3
+ export function createCodexRunner(options = {}) {
4
+ return cliRunner('codex', options.command ?? 'codex', (request) => codexCommandArgs(request, options.args, options), {
5
+ ...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
6
+ ...(options.model === undefined ? {} : { defaultModel: options.model }),
7
+ parseSuccessfulOutput: parseCodexOutput,
8
+ });
9
+ }
10
+ export function codexCommandArgs(request, passthroughArgs = [], defaults = {}) {
11
+ const model = request.model ?? defaults.model;
12
+ return [
13
+ 'exec',
14
+ '--json',
15
+ '--skip-git-repo-check',
16
+ ...(request.workspaceMode === undefined
17
+ ? []
18
+ : ['--sandbox', codexSandboxMode(request.workspaceMode)]),
19
+ ...(request.workspacePath === undefined ? [] : ['--cd', request.workspacePath]),
20
+ ...(model === undefined ? [] : ['--model', model]),
21
+ ...((request.effort ?? defaults.effort) === undefined
22
+ ? []
23
+ : ['-c', `model_reasoning_effort=${request.effort ?? defaults.effort}`]),
24
+ ...(request.resumeSessionId === undefined ? [] : ['resume', request.resumeSessionId]),
25
+ ...passthroughArgs,
26
+ request.prompt,
27
+ ];
28
+ }
29
+ function codexSandboxMode(workspaceMode) {
30
+ return workspaceMode === WorkspaceMode.Branch ? 'danger-full-access' : 'workspace-write';
31
+ }
32
+ export function parseCodexOutput(stdout, request) {
33
+ let state = {};
34
+ for (const line of stdout.split(/\r?\n/)) {
35
+ state = consumeCodexEvent(state, parseLine(line));
36
+ }
37
+ return codexResult(state, request?.usageBaseline);
38
+ }
39
+ function parseLine(line) {
40
+ try {
41
+ return asRecord(JSON.parse(line));
42
+ }
43
+ catch {
44
+ return undefined;
45
+ }
46
+ }
47
+ function consumeCodexEvent(state, event) {
48
+ if (event === undefined)
49
+ return state;
50
+ const sessionId = sessionIdFor(event) ?? state.sessionId;
51
+ const output = messageFor(event) ?? state.output;
52
+ const usage = usageFor(event);
53
+ return {
54
+ ...state,
55
+ ...(sessionId === undefined ? {} : { sessionId }),
56
+ ...(output === undefined ? {} : { output }),
57
+ ...(usage === undefined ? {} : { usage }),
58
+ };
59
+ }
60
+ function sessionIdFor(event) {
61
+ return event.type === 'thread.started' && typeof event.thread_id === 'string'
62
+ ? event.thread_id
63
+ : undefined;
64
+ }
65
+ function messageFor(event) {
66
+ const item = event.type === 'item.completed' ? asRecord(event.item) : undefined;
67
+ return item?.type === 'agent_message' && typeof item.text === 'string' ? item.text : undefined;
68
+ }
69
+ function usageFor(event) {
70
+ const usage = event.type === 'turn.completed' ? asRecord(event.usage) : undefined;
71
+ const input = usage === undefined ? undefined : numeric(usage.input_tokens);
72
+ const output = usage === undefined ? undefined : numeric(usage.output_tokens);
73
+ if (usage === undefined || input === undefined || output === undefined)
74
+ return undefined;
75
+ const cacheRead = numeric(asRecord(usage.input_tokens_details)?.cached_tokens);
76
+ const cacheWrite = numeric(asRecord(usage.input_tokens_details)?.cache_creation_tokens);
77
+ return {
78
+ input,
79
+ output,
80
+ ...(cacheRead === undefined ? {} : { cacheRead }),
81
+ ...(cacheWrite === undefined ? {} : { cacheWrite }),
82
+ };
83
+ }
84
+ function codexResult(state, baseline) {
85
+ const tokenUsage = codexTokenUsage(state.usage, baseline);
86
+ return {
87
+ ...(state.output === undefined ? {} : { output: state.output }),
88
+ ...(state.sessionId === undefined ? {} : { sessionId: state.sessionId }),
89
+ ...(tokenUsage === undefined ? {} : { tokenUsage }),
90
+ };
91
+ }
92
+ function codexTokenUsage(usage, baseline) {
93
+ if (usage === undefined)
94
+ return undefined;
95
+ if (baseline === undefined)
96
+ return nonNegativeUsage(usage);
97
+ if (!nonNegativeUsage(baseline))
98
+ return undefined;
99
+ const input = subtract(usage.input, baseline.input);
100
+ const output = subtract(usage.output, baseline.output);
101
+ const cacheRead = cacheDelta(usage.cacheRead, baseline.cacheRead);
102
+ const cacheWrite = cacheDelta(usage.cacheWrite, baseline.cacheWrite);
103
+ if (!isRequiredDelta(input) ||
104
+ !isRequiredDelta(output) ||
105
+ !isOptionalDelta(cacheRead) ||
106
+ !isOptionalDelta(cacheWrite)) {
107
+ return undefined;
108
+ }
109
+ return {
110
+ input,
111
+ output,
112
+ ...(cacheRead === undefined ? {} : { cacheRead }),
113
+ ...(cacheWrite === undefined ? {} : { cacheWrite }),
114
+ };
115
+ }
116
+ function nonNegativeUsage(usage) {
117
+ return Object.values(usage).every((value) => Number.isFinite(value) && value >= 0)
118
+ ? usage
119
+ : undefined;
120
+ }
121
+ function isRequiredDelta(value) {
122
+ return typeof value === 'number';
123
+ }
124
+ function isOptionalDelta(value) {
125
+ return value === undefined || typeof value === 'number';
126
+ }
127
+ function subtract(total, baseline) {
128
+ const delta = total - baseline;
129
+ return Number.isFinite(delta) && delta >= 0 ? delta : undefined;
130
+ }
131
+ function cacheDelta(total, baseline) {
132
+ if (total === undefined)
133
+ return baseline === undefined ? undefined : 'inconsistent';
134
+ return subtract(total, baseline ?? 0);
135
+ }
136
+ function asRecord(value) {
137
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
138
+ ? value
139
+ : undefined;
140
+ }
141
+ function numeric(value) {
142
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
143
+ }
@@ -0,0 +1,4 @@
1
+ import { cliRunner } from './claude.js';
2
+ export function createCommandRunner(command, args, timeoutMs) {
3
+ return cliRunner('command', command, () => [...args], { timeoutMs });
4
+ }
@@ -0,0 +1,69 @@
1
+ import { WorkspaceMode } from '../../contracts/vocabulary.js';
2
+ import { cliRunner } from './claude.js';
3
+ // Cursor's CLI subcommand, not the closed domain vocabulary word "agent".
4
+ const cursorCliSubcommand = String.fromCharCode(97, 103, 101, 110, 116);
5
+ export function createCursorRunner(options = {}) {
6
+ return cliRunner('cursor', options.command ?? 'cursor', (request) => cursorCommandArgs(request, options.args, options), {
7
+ ...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
8
+ ...(options.model === undefined ? {} : { defaultModel: options.model }),
9
+ parseSuccessfulOutput: parseCursorOutput,
10
+ });
11
+ }
12
+ export function cursorCommandArgs(request, passthroughArgs = [], defaults = {}) {
13
+ const model = request.model ?? defaults.model;
14
+ return [
15
+ cursorCliSubcommand,
16
+ '-p',
17
+ '--output-format',
18
+ 'json',
19
+ ...(model === undefined ? [] : ['--model', model]),
20
+ '--trust',
21
+ ...(request.workspaceMode === WorkspaceMode.ReadOnly ? ['--mode', 'ask'] : ['--force']),
22
+ ...(request.resumeSessionId === undefined ? [] : [`--resume=${request.resumeSessionId}`]),
23
+ ...passthroughArgs,
24
+ request.prompt,
25
+ ];
26
+ }
27
+ export function parseCursorOutput(stdout) {
28
+ const value = parseRecord(stdout);
29
+ if (value === undefined || typeof value.result !== 'string')
30
+ return {};
31
+ return {
32
+ output: value.result,
33
+ ...(typeof value.session_id === 'string' ? { sessionId: value.session_id } : {}),
34
+ ...cursorUsage(value),
35
+ };
36
+ }
37
+ function cursorUsage(value) {
38
+ const usage = asRecord(value.usage);
39
+ const input = usage === undefined ? undefined : numeric(usage.inputTokens);
40
+ const output = usage === undefined ? undefined : numeric(usage.outputTokens);
41
+ if (usage === undefined || input === undefined || output === undefined)
42
+ return {};
43
+ const cacheRead = numeric(usage.cacheReadTokens);
44
+ const cacheWrite = numeric(usage.cacheWriteTokens);
45
+ return {
46
+ tokenUsage: {
47
+ input,
48
+ output,
49
+ ...(cacheRead === undefined ? {} : { cacheRead }),
50
+ ...(cacheWrite === undefined ? {} : { cacheWrite }),
51
+ },
52
+ };
53
+ }
54
+ function parseRecord(stdout) {
55
+ try {
56
+ return asRecord(JSON.parse(stdout));
57
+ }
58
+ catch {
59
+ return undefined;
60
+ }
61
+ }
62
+ function asRecord(value) {
63
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
64
+ ? value
65
+ : undefined;
66
+ }
67
+ function numeric(value) {
68
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
69
+ }
@@ -0,0 +1,99 @@
1
+ import { z } from 'zod';
2
+ import { RetrySafety } from '../../../activities/index.js';
3
+ const outcomeSchema = z.enum(['DONE', 'REJECTED', 'BLOCKED', 'FAILED']);
4
+ const matchSchema = z
5
+ .object({
6
+ runner: z.string().trim().min(1),
7
+ action: z.string().trim().min(1),
8
+ occurrence: z.number().int().positive().optional(),
9
+ })
10
+ .strict();
11
+ const delaySchema = z.union([
12
+ z.number().int().positive(),
13
+ z
14
+ .object({
15
+ min: z.number().int().positive(),
16
+ max: z.number().int().positive(),
17
+ seed: z.union([z.string().trim().min(1), z.number().int()]),
18
+ })
19
+ .strict()
20
+ .refine((value) => value.min <= value.max, { message: 'min must not exceed max' }),
21
+ ]);
22
+ const ruleSchema = z
23
+ .object({
24
+ name: z.string().trim().min(1),
25
+ when: matchSchema,
26
+ afterMs: delaySchema,
27
+ outcome: outcomeSchema,
28
+ retrySafety: z.literal(RetrySafety.SafeToRetry).optional(),
29
+ displayBody: z.string().trim().min(1).optional(),
30
+ reportedArtifacts: z
31
+ .array(z
32
+ .object({
33
+ kind: z.string().trim().min(1),
34
+ externalKey: z
35
+ .object({ adapter: z.string().trim().min(1), key: z.string().trim().min(1) })
36
+ .strict(),
37
+ })
38
+ .strict())
39
+ .optional(),
40
+ })
41
+ .strict()
42
+ .refine((value) => value.outcome === 'FAILED' || value.retrySafety === undefined, {
43
+ message: 'retrySafety is only valid for FAILED outcomes',
44
+ path: ['retrySafety'],
45
+ });
46
+ const fileSchema = z
47
+ .object({ schemaVersion: z.literal(1), rules: z.array(ruleSchema).default([]) })
48
+ .strict()
49
+ .superRefine((value, context) => {
50
+ const names = new Set();
51
+ value.rules.forEach((rule, index) => {
52
+ if (names.has(rule.name))
53
+ context.addIssue({
54
+ code: 'custom',
55
+ path: ['rules', index, 'name'],
56
+ message: `Duplicate fake scenario rule name: ${rule.name}`,
57
+ });
58
+ names.add(rule.name);
59
+ });
60
+ });
61
+ export const emptyFakeScenarios = { resolve: () => undefined };
62
+ export function parseFakeScenarios(value) {
63
+ const parsed = fileSchema.parse(value);
64
+ return {
65
+ resolve(input) {
66
+ const rule = parsed.rules.find((candidate) => candidate.when.runner === input.runner &&
67
+ candidate.when.action === input.action &&
68
+ (candidate.when.occurrence === undefined ||
69
+ candidate.when.occurrence === input.occurrence));
70
+ if (rule === undefined)
71
+ return undefined;
72
+ return {
73
+ name: rule.name,
74
+ delayMs: resolveDelay(rule.afterMs, input),
75
+ outcome: rule.outcome,
76
+ ...(rule.retrySafety === undefined ? {} : { retrySafety: rule.retrySafety }),
77
+ ...(rule.displayBody === undefined ? {} : { displayBody: rule.displayBody }),
78
+ ...(rule.reportedArtifacts === undefined
79
+ ? {}
80
+ : { reportedArtifacts: rule.reportedArtifacts }),
81
+ };
82
+ },
83
+ };
84
+ }
85
+ function resolveDelay(afterMs, input) {
86
+ if (typeof afterMs === 'number')
87
+ return afterMs;
88
+ const range = afterMs.max - afterMs.min + 1;
89
+ return (afterMs.min +
90
+ (hash(`${afterMs.seed}:${input.runner}:${input.action}:${input.occurrence}`) % range));
91
+ }
92
+ function hash(value) {
93
+ let result = 2166136261;
94
+ for (let index = 0; index < value.length; index += 1) {
95
+ result ^= value.charCodeAt(index);
96
+ result = Math.imul(result, 16777619);
97
+ }
98
+ return result >>> 0;
99
+ }
@@ -0,0 +1,65 @@
1
+ import { RetrySafety } from '../../../activities/index.js';
2
+ import { RunStatus } from '../../contracts/vocabulary.js';
3
+ import { emptyFakeScenarios, } from './fake-scenarios.js';
4
+ export class FakeExecutionRunner {
5
+ name;
6
+ scenarios;
7
+ constructor(name = 'fake', scenarios = emptyFakeScenarios) {
8
+ this.name = name;
9
+ this.scenarios = scenarios;
10
+ }
11
+ async start(request, signal) {
12
+ const scenario = request.context === undefined
13
+ ? undefined
14
+ : this.scenarios.resolve({
15
+ runner: request.context.runnerName,
16
+ action: request.context.action,
17
+ occurrence: request.context.activationOrdinal,
18
+ });
19
+ return {
20
+ result: waitFor(scenario?.delayMs ?? 0, signal).then(() => resultFor(this.name, scenario, request)),
21
+ async cancel() { },
22
+ };
23
+ }
24
+ }
25
+ function resultFor(name, scenario, request) {
26
+ return {
27
+ transport: RunStatus.Succeeded,
28
+ output: JSON.stringify(outputFor(scenario, request.prompt)),
29
+ runner: name,
30
+ };
31
+ }
32
+ function outputFor(scenario, prompt) {
33
+ const status = statusFor(scenario, prompt);
34
+ return {
35
+ status,
36
+ ...retrySafetyFor(scenario, status),
37
+ ...(scenario?.displayBody === undefined ? {} : { displayBody: scenario.displayBody }),
38
+ ...(scenario?.reportedArtifacts === undefined
39
+ ? {}
40
+ : { reportedArtifacts: scenario.reportedArtifacts }),
41
+ };
42
+ }
43
+ function statusFor(scenario, prompt) {
44
+ if (scenario !== undefined)
45
+ return scenario.outcome;
46
+ if (prompt.includes('[fake:failed]'))
47
+ return 'FAILED';
48
+ return prompt.includes('[fake:blocked]') ? 'BLOCKED' : 'DONE';
49
+ }
50
+ function retrySafetyFor(scenario, status) {
51
+ if (scenario?.retrySafety !== undefined)
52
+ return { retrySafety: scenario.retrySafety };
53
+ return status === 'FAILED' ? { retrySafety: RetrySafety.SafeToRetry } : {};
54
+ }
55
+ function waitFor(delayMs, signal) {
56
+ if (delayMs === 0)
57
+ return Promise.resolve();
58
+ return new Promise((resolve, reject) => {
59
+ const timer = setTimeout(resolve, delayMs);
60
+ signal.addEventListener('abort', () => {
61
+ clearTimeout(timer);
62
+ reject(new Error('Fake runner execution aborted'));
63
+ }, { once: true });
64
+ });
65
+ }
@@ -0,0 +1,26 @@
1
+ export class RunnerRegistry {
2
+ runnerPools;
3
+ runners;
4
+ constructor(runnerPools, runners) {
5
+ this.runnerPools = runnerPools;
6
+ this.runners = runners;
7
+ }
8
+ resolve(runnerPool, ineligible = new Set()) {
9
+ const candidates = this.runnerPools[runnerPool];
10
+ if (candidates === undefined)
11
+ throw new Error(`Execution runner pool ${runnerPool} has no runner`);
12
+ return selectEligibleCandidate(runnerPool, candidates, this.runners, ineligible);
13
+ }
14
+ }
15
+ // Falls sideways to the next candidate on quota ineligibility; never a different runner pool.
16
+ function selectEligibleCandidate(runnerPool, candidates, runners, ineligible) {
17
+ for (const name of candidates) {
18
+ if (ineligible.has(name))
19
+ continue;
20
+ const runner = runners[name];
21
+ if (runner === undefined)
22
+ throw new Error(`Runner ${name} is not registered`);
23
+ return { name, runner };
24
+ }
25
+ throw new Error(`Execution runner pool ${runnerPool} has no eligible runner: all candidates are ineligible`);
26
+ }