@atolis-hq/wake 0.2.97 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (443) hide show
  1. package/README.md +5 -5
  2. package/dist/src/activities/agent/agent-activity-definition.js +26 -0
  3. package/dist/src/activities/agent/agent-activity.js +171 -0
  4. package/dist/src/activities/agent/agent-result.js +149 -0
  5. package/dist/src/activities/contracts/activity.js +10 -0
  6. package/dist/src/activities/contracts/config.js +2 -0
  7. package/dist/src/activities/contracts/event-schema.js +302 -0
  8. package/dist/src/activities/contracts/events.js +42 -0
  9. package/dist/src/activities/contracts/identifiers.js +29 -0
  10. package/dist/src/activities/contracts/registry.js +71 -0
  11. package/dist/src/activities/contracts/streams.js +17 -0
  12. package/dist/src/activities/contracts/vocabulary.js +58 -0
  13. package/dist/src/activities/index.js +21 -0
  14. package/dist/src/activities/pr/activity-support.js +111 -0
  15. package/dist/src/activities/pr/application.js +158 -0
  16. package/dist/src/activities/pr/approve.js +85 -0
  17. package/dist/src/activities/pr/capability.js +11 -0
  18. package/dist/src/activities/pr/decision-claim.js +76 -0
  19. package/dist/src/activities/pr/event-drafts.js +66 -0
  20. package/dist/src/activities/pr/intent.js +37 -0
  21. package/dist/src/activities/pr/merge-authority-gate.js +14 -0
  22. package/dist/src/activities/pr/merge.js +110 -0
  23. package/dist/src/activities/pr/policy.js +135 -0
  24. package/dist/src/activities/pr/projection.js +130 -0
  25. package/dist/src/activities/pr/vocabulary.js +30 -0
  26. package/dist/src/activities/review/authorization.js +22 -0
  27. package/dist/src/activities/review/contracts.js +22 -0
  28. package/dist/src/activities/review/signals.js +3 -0
  29. package/dist/src/bootstrap/analytics-projection.js +26 -0
  30. package/dist/src/bootstrap/board-projection.js +337 -0
  31. package/dist/src/bootstrap/composition-root.js +382 -0
  32. package/dist/src/bootstrap/config/load-config.js +51 -0
  33. package/dist/src/bootstrap/config/root-schema.js +134 -0
  34. package/dist/src/bootstrap/external-ref.js +12 -0
  35. package/dist/src/bootstrap/fake-provider-files.js +44 -0
  36. package/dist/src/bootstrap/fake-scenarios.js +22 -0
  37. package/dist/src/bootstrap/index.js +48 -0
  38. package/dist/src/bootstrap/initialise.js +436 -0
  39. package/dist/src/bootstrap/paths.js +15 -0
  40. package/dist/src/bootstrap/projection-runtime.js +27 -0
  41. package/dist/src/bootstrap/runner-quota-reporter.js +21 -0
  42. package/dist/src/bootstrap/runner-registry.js +30 -0
  43. package/dist/src/bootstrap/schedule-checkpoint-store.js +49 -0
  44. package/dist/src/bootstrap/self-update-application.js +195 -0
  45. package/dist/src/bootstrap/self-update-failure-log.js +33 -0
  46. package/dist/src/bootstrap/source-update-port.js +47 -0
  47. package/dist/src/bootstrap/status-publish-activity.js +42 -0
  48. package/dist/src/bootstrap/surface-api-applications.js +325 -0
  49. package/dist/src/bootstrap/surface-api-execution-applications.js +95 -0
  50. package/dist/src/bootstrap/surface-api-metadata.js +12 -0
  51. package/dist/src/bootstrap/surface-api-projection-pages.js +22 -0
  52. package/dist/src/bootstrap/surface-api-run-context.js +5 -0
  53. package/dist/src/bootstrap/surface-api-transcripts.js +57 -0
  54. package/dist/src/bootstrap/surface-api-work-applications.js +199 -0
  55. package/dist/src/bootstrap/surface-applications.js +7 -0
  56. package/dist/src/bootstrap/surface-cli-applications.js +701 -0
  57. package/dist/src/bootstrap/update-ledger.js +61 -0
  58. package/dist/src/bootstrap/update-maintenance-lease.js +176 -0
  59. package/dist/src/{version.js → bootstrap/version.js} +35 -51
  60. package/dist/src/control-plane/application/advance-once.js +184 -0
  61. package/dist/src/control-plane/application/control-plane-projection.js +42 -0
  62. package/dist/src/control-plane/application/control-plane-service.js +42 -0
  63. package/dist/src/control-plane/application/intake-pipeline.js +29 -0
  64. package/dist/src/control-plane/application/runner-control-service.js +66 -0
  65. package/dist/src/control-plane/application/runner-pipeline.js +57 -0
  66. package/dist/src/control-plane/application/schedule-service.js +47 -0
  67. package/dist/src/control-plane/application/work-cancellation-policy.js +31 -0
  68. package/dist/src/control-plane/contracts/commands.js +10 -0
  69. package/dist/src/control-plane/contracts/config.js +22 -0
  70. package/dist/src/control-plane/contracts/events.js +81 -0
  71. package/dist/src/control-plane/contracts/streams.js +5 -0
  72. package/dist/src/control-plane/domain/dispatch-policy.js +15 -0
  73. package/dist/src/control-plane/domain/quota-policy.js +26 -0
  74. package/dist/src/control-plane/domain/runner-quota.js +35 -0
  75. package/dist/src/control-plane/domain/schedule-policy.js +46 -0
  76. package/dist/src/control-plane/index.js +20 -0
  77. package/dist/src/control-plane/infrastructure/intake-host.js +24 -0
  78. package/dist/src/control-plane/infrastructure/resident-host.js +45 -0
  79. package/dist/src/control-plane/infrastructure/tick-host.js +35 -0
  80. package/dist/src/execution/application/activation-claim.js +50 -0
  81. package/dist/src/execution/application/active-run-cancellation.js +14 -0
  82. package/dist/src/execution/application/execution-activity.js +97 -0
  83. package/dist/src/execution/application/execution-projection.js +17 -0
  84. package/dist/src/execution/application/execution-service.js +372 -0
  85. package/dist/src/execution/application/execution-validation.js +26 -0
  86. package/dist/src/execution/application/recovery-service.js +212 -0
  87. package/dist/src/execution/application/run-lifecycle.js +115 -0
  88. package/dist/src/execution/application/run-liveness-service.js +80 -0
  89. package/dist/src/execution/application/run-repository.js +27 -0
  90. package/dist/src/execution/contracts/commands.js +1 -0
  91. package/dist/src/execution/contracts/config.js +35 -0
  92. package/dist/src/execution/contracts/control-plane.js +1 -0
  93. package/dist/src/execution/contracts/event-factory.js +53 -0
  94. package/dist/src/execution/contracts/events.js +274 -0
  95. package/dist/src/execution/contracts/identifiers.js +5 -0
  96. package/dist/src/execution/contracts/liveness.js +1 -0
  97. package/dist/src/execution/contracts/results.js +1 -0
  98. package/dist/src/execution/contracts/runner.js +15 -0
  99. package/dist/src/execution/contracts/streams.js +10 -0
  100. package/dist/src/execution/contracts/views.js +1 -0
  101. package/dist/src/execution/contracts/vocabulary.js +43 -0
  102. package/dist/src/execution/contracts/workspace.js +1 -0
  103. package/dist/src/execution/domain/run-result.js +34 -0
  104. package/dist/src/execution/domain/run.js +142 -0
  105. package/dist/src/execution/index.js +31 -0
  106. package/dist/src/execution/infrastructure/agent-runner-adapter.js +114 -0
  107. package/dist/src/execution/infrastructure/process-execution.js +29 -0
  108. package/dist/src/execution/infrastructure/prompt-templates.js +42 -0
  109. package/dist/src/execution/infrastructure/runners/claude.js +120 -0
  110. package/dist/src/execution/infrastructure/runners/codex.js +143 -0
  111. package/dist/src/execution/infrastructure/runners/command.js +4 -0
  112. package/dist/src/execution/infrastructure/runners/cursor.js +69 -0
  113. package/dist/src/execution/infrastructure/runners/fake-scenarios.js +99 -0
  114. package/dist/src/execution/infrastructure/runners/fake.js +65 -0
  115. package/dist/src/execution/infrastructure/runners/registry.js +26 -0
  116. package/dist/src/execution/infrastructure/transcript-store.js +223 -0
  117. package/dist/src/execution/infrastructure/transcripts.js +11 -0
  118. package/dist/src/execution/infrastructure/workspace/fake-workspace.js +19 -0
  119. package/dist/src/execution/infrastructure/workspace/git-workspace.js +241 -0
  120. package/dist/src/integrations/application/agent-run-publication-reactor.js +111 -0
  121. package/dist/src/integrations/application/artifact-registration-reactor.js +159 -0
  122. package/dist/src/integrations/application/poll-service.js +25 -0
  123. package/dist/src/integrations/application/terminal-agent-run-report.js +40 -0
  124. package/dist/src/integrations/application/work-admission.js +31 -0
  125. package/dist/src/integrations/application/work-conclusion.js +19 -0
  126. package/dist/src/integrations/contracts/artifact-events.js +60 -0
  127. package/dist/src/integrations/contracts/artifact-vocabulary.js +9 -0
  128. package/dist/src/integrations/contracts/config.js +14 -0
  129. package/dist/src/integrations/contracts/identifiers.js +5 -0
  130. package/dist/src/integrations/contracts/intake-rules.js +14 -0
  131. package/dist/src/integrations/contracts/intake.js +1 -0
  132. package/dist/src/integrations/contracts/outcome-vocabulary.js +7 -0
  133. package/dist/src/integrations/contracts/provider.js +37 -0
  134. package/dist/src/integrations/contracts/streams.js +10 -0
  135. package/dist/src/integrations/delivery/application/delivery-outcome-reactor.js +75 -0
  136. package/dist/src/integrations/delivery/application/delivery-projector.js +165 -0
  137. package/dist/src/integrations/delivery/application/delivery-service.js +173 -0
  138. package/dist/src/integrations/delivery/contracts/commands.js +1 -0
  139. package/dist/src/integrations/delivery/contracts/config.js +1 -0
  140. package/dist/src/integrations/delivery/contracts/event-factory.js +18 -0
  141. package/dist/src/integrations/delivery/contracts/events.js +86 -0
  142. package/dist/src/integrations/delivery/contracts/intents.js +89 -0
  143. package/dist/src/integrations/delivery/contracts/views.js +1 -0
  144. package/dist/src/integrations/delivery/contracts/vocabulary.js +22 -0
  145. package/dist/src/integrations/fake/durable-delivery-provider.js +48 -0
  146. package/dist/src/integrations/fake/external-sink.js +9 -0
  147. package/dist/src/integrations/fake/external-source.js +44 -0
  148. package/dist/src/integrations/fake/inbound-translator.js +130 -0
  149. package/dist/src/integrations/fake/provider.js +95 -0
  150. package/dist/src/integrations/github/application/agent-context-reader.js +54 -0
  151. package/dist/src/integrations/github/application/agent-run-comment.js +94 -0
  152. package/dist/src/integrations/github/application/comment-history-reader.js +43 -0
  153. package/dist/src/integrations/github/application/inbound-context.js +10 -0
  154. package/dist/src/integrations/github/application/inbound-review-signals.js +159 -0
  155. package/dist/src/integrations/github/application/inbound-translator.js +231 -0
  156. package/dist/src/integrations/github/application/inbound-watch-gate-signals.js +84 -0
  157. package/dist/src/integrations/github/application/intake-policy.js +23 -0
  158. package/dist/src/integrations/github/application/outbound-translator.js +47 -0
  159. package/dist/src/integrations/github/application/poll-service.js +29 -0
  160. package/dist/src/integrations/github/application/pull-request-translation.js +10 -0
  161. package/dist/src/integrations/github/application/resource-links.js +8 -0
  162. package/dist/src/integrations/github/application/review-command-translator.js +16 -0
  163. package/dist/src/integrations/github/application/wake-labels.js +95 -0
  164. package/dist/src/integrations/github/contracts/config.js +47 -0
  165. package/dist/src/integrations/github/contracts/events.js +127 -0
  166. package/dist/src/integrations/github/contracts/external-key.js +19 -0
  167. package/dist/src/integrations/github/contracts/payloads.js +9 -0
  168. package/dist/src/integrations/github/contracts/vocabulary.js +55 -0
  169. package/dist/src/integrations/github/index.js +31 -0
  170. package/dist/src/integrations/github/infrastructure/client-reads.js +214 -0
  171. package/dist/src/integrations/github/infrastructure/client.js +132 -0
  172. package/dist/src/integrations/github/infrastructure/content-fingerprint.js +10 -0
  173. package/dist/src/integrations/github/infrastructure/delivery.js +31 -0
  174. package/dist/src/integrations/github/infrastructure/etag-cache.js +56 -0
  175. package/dist/src/integrations/github/infrastructure/gh-auth.js +19 -0
  176. package/dist/src/integrations/github/infrastructure/issue-source.js +109 -0
  177. package/dist/src/integrations/github/infrastructure/pr-source.js +186 -0
  178. package/dist/src/integrations/github/infrastructure/review-source.js +70 -0
  179. package/dist/src/integrations/github/infrastructure/source.js +108 -0
  180. package/dist/src/integrations/github/provider.js +96 -0
  181. package/dist/src/integrations/index.js +30 -0
  182. package/dist/src/kernel/contracts/checkpoint-store.js +1 -0
  183. package/dist/src/kernel/contracts/clock.js +1 -0
  184. package/dist/src/kernel/contracts/commands.js +1 -0
  185. package/dist/src/kernel/contracts/event-journal.js +2 -0
  186. package/dist/src/kernel/contracts/event-schema.js +54 -0
  187. package/dist/src/kernel/contracts/events.js +11 -0
  188. package/dist/src/kernel/contracts/id-generator.js +1 -0
  189. package/dist/src/kernel/contracts/identifiers.js +8 -0
  190. package/dist/src/kernel/contracts/projection-store.js +1 -0
  191. package/dist/src/kernel/contracts/relations.js +1 -0
  192. package/dist/src/kernel/contracts/schema.js +17 -0
  193. package/dist/src/kernel/contracts/vocabulary.js +6 -0
  194. package/dist/src/kernel/domain/event-envelope.js +29 -0
  195. package/dist/src/kernel/domain/match-mode.js +11 -0
  196. package/dist/src/kernel/domain/relation.js +10 -0
  197. package/dist/src/kernel/index.js +17 -0
  198. package/dist/src/{lib/clock.js → kernel/infrastructure/system-clock.js} +3 -3
  199. package/dist/src/kernel/infrastructure/ulid-id-generator.js +9 -0
  200. package/dist/src/main.js +137 -1030
  201. package/dist/src/orchestration/application/accept-activity-outcome.js +25 -0
  202. package/dist/src/orchestration/application/accept-signal.js +35 -0
  203. package/dist/src/orchestration/application/advance-workflow.js +160 -0
  204. package/dist/src/orchestration/application/coordination-claims.js +107 -0
  205. package/dist/src/orchestration/application/group-budget-recorder.js +43 -0
  206. package/dist/src/orchestration/application/orchestration-projection.js +20 -0
  207. package/dist/src/orchestration/application/orchestration-repository.js +36 -0
  208. package/dist/src/orchestration/application/orchestration-service.js +82 -0
  209. package/dist/src/orchestration/application/request-child.js +118 -0
  210. package/dist/src/orchestration/application/signal-reactor.js +17 -0
  211. package/dist/src/orchestration/application/start-workflow.js +51 -0
  212. package/dist/src/orchestration/application/watch-reactor.js +82 -0
  213. package/dist/src/orchestration/contracts/activity-outcome.js +18 -0
  214. package/dist/src/orchestration/contracts/commands.js +1 -0
  215. package/dist/src/orchestration/contracts/config.js +128 -0
  216. package/dist/src/orchestration/contracts/event-decoder.js +263 -0
  217. package/dist/src/orchestration/contracts/events.js +41 -0
  218. package/dist/src/orchestration/contracts/identifiers.js +35 -0
  219. package/dist/src/orchestration/contracts/streams.js +38 -0
  220. package/dist/src/orchestration/contracts/views.js +1 -0
  221. package/dist/src/orchestration/contracts/vocabulary.js +30 -0
  222. package/dist/src/orchestration/domain/activation-policy.js +55 -0
  223. package/dist/src/orchestration/domain/approval-defaults.js +17 -0
  224. package/dist/src/orchestration/domain/child-policy.js +63 -0
  225. package/dist/src/orchestration/domain/compiler.js +162 -0
  226. package/dist/src/orchestration/domain/coordination-events.js +25 -0
  227. package/dist/src/orchestration/domain/decision-events.js +47 -0
  228. package/dist/src/orchestration/domain/interpreter.js +49 -0
  229. package/dist/src/orchestration/domain/operator-retry-policy.js +34 -0
  230. package/dist/src/orchestration/domain/retry-policy.js +26 -0
  231. package/dist/src/orchestration/domain/signal-policy.js +120 -0
  232. package/dist/src/orchestration/domain/supplemental-policy.js +61 -0
  233. package/dist/src/orchestration/domain/transition.js +55 -0
  234. package/dist/src/orchestration/domain/workflow-graph.js +41 -0
  235. package/dist/src/orchestration/domain/workflow-instance-events.js +236 -0
  236. package/dist/src/orchestration/domain/workflow-instance.js +41 -0
  237. package/dist/src/orchestration/domain/workflow-selector.js +21 -0
  238. package/dist/src/orchestration/index.js +19 -0
  239. package/dist/src/persistence/application/projection-runner.js +79 -0
  240. package/dist/src/persistence/filesystem/file-checkpoint-store.js +35 -0
  241. package/dist/src/persistence/filesystem/file-event-journal.js +143 -0
  242. package/dist/src/persistence/filesystem/file-lock.js +91 -0
  243. package/dist/src/persistence/filesystem/file-projection-store.js +64 -0
  244. package/dist/src/persistence/index.js +8 -0
  245. package/dist/src/persistence/memory/in-memory-checkpoint-store.js +14 -0
  246. package/dist/src/persistence/memory/in-memory-event-journal.js +88 -0
  247. package/dist/src/persistence/memory/in-memory-projection-store.js +17 -0
  248. package/dist/src/resources/application/lookup-projections.js +48 -0
  249. package/dist/src/resources/application/resource-lookup.js +16 -0
  250. package/dist/src/resources/application/resource-projections.js +81 -0
  251. package/dist/src/resources/application/resource-repository.js +18 -0
  252. package/dist/src/resources/application/resource-service.js +83 -0
  253. package/dist/src/resources/contracts/commands.js +1 -0
  254. package/dist/src/resources/contracts/config.js +2 -0
  255. package/dist/src/resources/contracts/events.js +83 -0
  256. package/dist/src/resources/contracts/identifiers.js +15 -0
  257. package/dist/src/resources/contracts/streams.js +6 -0
  258. package/dist/src/resources/contracts/views.js +1 -0
  259. package/dist/src/resources/contracts/vocabulary.js +67 -0
  260. package/dist/src/resources/domain/correlation.js +8 -0
  261. package/dist/src/resources/domain/resource.js +58 -0
  262. package/dist/src/resources/index.js +14 -0
  263. package/dist/src/surfaces/api/contracts/activities.js +1 -0
  264. package/dist/src/surfaces/api/contracts/board.js +2 -0
  265. package/dist/src/surfaces/api/contracts/common.js +46 -0
  266. package/dist/src/surfaces/api/contracts/control-plane.js +5 -0
  267. package/dist/src/surfaces/api/contracts/events.js +1 -0
  268. package/dist/src/surfaces/api/contracts/execution.js +1 -0
  269. package/dist/src/surfaces/api/contracts/index.js +13 -0
  270. package/dist/src/surfaces/api/contracts/observability.js +1 -0
  271. package/dist/src/surfaces/api/contracts/orchestration.js +1 -0
  272. package/dist/src/surfaces/api/contracts/resources.js +1 -0
  273. package/dist/src/surfaces/api/contracts/status.js +1 -0
  274. package/dist/src/surfaces/api/contracts/system.js +1 -0
  275. package/dist/src/surfaces/api/contracts/transport-values.js +39 -0
  276. package/dist/src/surfaces/api/contracts/work.js +17 -0
  277. package/dist/src/surfaces/api/http-server.js +121 -0
  278. package/dist/src/surfaces/api/presenters/activities.js +1 -0
  279. package/dist/src/surfaces/api/presenters/board.js +3 -0
  280. package/dist/src/surfaces/api/presenters/control-plane.js +1 -0
  281. package/dist/src/surfaces/api/presenters/events.js +1 -0
  282. package/dist/src/surfaces/api/presenters/execution.js +59 -0
  283. package/dist/src/surfaces/api/presenters/observability.js +1 -0
  284. package/dist/src/surfaces/api/presenters/orchestration.js +19 -0
  285. package/dist/src/surfaces/api/presenters/resources.js +15 -0
  286. package/dist/src/surfaces/api/presenters/status.js +3 -0
  287. package/dist/src/surfaces/api/presenters/system.js +14 -0
  288. package/dist/src/surfaces/api/presenters/work.js +16 -0
  289. package/dist/src/surfaces/api/problem-details.js +9 -0
  290. package/dist/src/surfaces/api/router.js +13 -0
  291. package/dist/src/surfaces/api/routes/activities.js +1 -0
  292. package/dist/src/surfaces/api/routes/applications.js +1 -0
  293. package/dist/src/surfaces/api/routes/commands.js +82 -0
  294. package/dist/src/surfaces/api/routes/control-plane.js +6 -0
  295. package/dist/src/surfaces/api/routes/events.js +1 -0
  296. package/dist/src/surfaces/api/routes/execution.js +8 -0
  297. package/dist/src/surfaces/api/routes/index.js +18 -0
  298. package/dist/src/surfaces/api/routes/observability.js +1 -0
  299. package/dist/src/surfaces/api/routes/orchestration.js +1 -0
  300. package/dist/src/surfaces/api/routes/pagination.js +78 -0
  301. package/dist/src/surfaces/api/routes/read.js +135 -0
  302. package/dist/src/surfaces/api/routes/resources.js +1 -0
  303. package/dist/src/surfaces/api/routes/responses.js +67 -0
  304. package/dist/src/surfaces/api/routes/system.js +1 -0
  305. package/dist/src/surfaces/api/routes/work.js +9 -0
  306. package/dist/src/surfaces/cli/commands/api.js +1 -0
  307. package/dist/src/surfaces/cli/commands/audit.js +10 -0
  308. package/dist/src/surfaces/cli/commands/correlate.js +2 -0
  309. package/dist/src/surfaces/cli/commands/doctor.js +6 -0
  310. package/dist/src/surfaces/cli/commands/init.js +39 -0
  311. package/dist/src/surfaces/cli/commands/sandbox-entrypoint.js +33 -0
  312. package/dist/src/surfaces/cli/commands/sandbox-setup.js +29 -0
  313. package/dist/src/surfaces/cli/commands/sandbox.js +105 -0
  314. package/dist/src/surfaces/cli/commands/self-update.js +38 -0
  315. package/dist/src/surfaces/cli/commands/smoke.js +16 -0
  316. package/dist/src/surfaces/cli/commands/start.js +1 -0
  317. package/dist/src/surfaces/cli/commands/stop.js +13 -0
  318. package/dist/src/surfaces/cli/commands/tick.js +1 -0
  319. package/dist/src/surfaces/cli/commands/ui.js +2 -0
  320. package/dist/src/surfaces/cli/commands/validate-state.js +5 -0
  321. package/dist/src/surfaces/cli/infrastructure/docker-cli.js +221 -0
  322. package/dist/src/surfaces/cli/infrastructure/process-log.js +86 -0
  323. package/dist/src/surfaces/cli/main.js +140 -0
  324. package/dist/src/surfaces/cli/usage.js +33 -0
  325. package/dist/src/surfaces/contracts/config.js +34 -0
  326. package/dist/src/surfaces/index.js +47 -0
  327. package/dist/src/surfaces/web-assets/assets/index-Bfn4FwZG.css +1 -0
  328. package/dist/src/surfaces/web-assets/assets/index-ipB6JPGU.js +1090 -0
  329. package/dist/src/surfaces/web-assets/index.html +13 -0
  330. package/dist/src/surfaces/web-host/asset-source.js +1 -0
  331. package/dist/src/surfaces/web-host/packaged-assets.js +44 -0
  332. package/dist/src/work/application/work-projection.js +59 -0
  333. package/dist/src/work/application/work-repository.js +18 -0
  334. package/dist/src/work/application/work-service.js +117 -0
  335. package/dist/src/work/contracts/commands.js +1 -0
  336. package/dist/src/work/contracts/config.js +2 -0
  337. package/dist/src/work/contracts/events.js +103 -0
  338. package/dist/src/work/contracts/identifiers.js +5 -0
  339. package/dist/src/work/contracts/streams.js +6 -0
  340. package/dist/src/work/contracts/views.js +1 -0
  341. package/dist/src/work/contracts/vocabulary.js +6 -0
  342. package/dist/src/work/domain/work-item.js +89 -0
  343. package/dist/src/work/index.js +11 -0
  344. package/docker/Dockerfile +10 -6
  345. package/docker/Dockerfile.packaged +3 -3
  346. package/package.json +29 -4
  347. package/prompts/implement.md +2 -2
  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/templates/SETUP.md +0 -115
  442. /package/dist/src/{core → activities/pr}/contracts.js +0 -0
  443. /package/dist/src/{domain/types.js → control-plane/contracts/views.js} +0 -0
@@ -0,0 +1,231 @@
1
+ /* eslint-disable max-lines */
2
+ import { createPullRequestService, } from '../../../activities/index.js';
3
+ import { UlidIdGenerator, } from '../../../kernel/index.js';
4
+ import { BuiltInResourceCapability, BuiltInResourceKind, ResourceCorrelationRole, resourceId, } from '../../../resources/index.js';
5
+ import { workItemId } from '../../../work/index.js';
6
+ import { admitObservedWork } from '../../application/work-admission.js';
7
+ import { concludeObservedWork } from '../../application/work-conclusion.js';
8
+ import { evaluateIntakeRules } from '../../contracts/intake-rules.js';
9
+ import { GitHubEventType, selectGitHubAdapterEvent } from '../contracts/events.js';
10
+ import { GitHubAdapter } from '../contracts/vocabulary.js';
11
+ import { commandContext } from './inbound-context.js';
12
+ import { applyReviewSignal } from './inbound-review-signals.js';
13
+ import { applyWatchGateVerdictSignal } from './inbound-watch-gate-signals.js';
14
+ import { gitHubIntakeFacts, gitHubIntakeRules } from './intake-policy.js';
15
+ import { observePullRequest } from './pull-request-translation.js';
16
+ export class InboundTranslator {
17
+ journal;
18
+ checkpoints;
19
+ work;
20
+ resources;
21
+ minted = new Map();
22
+ translate(payload) {
23
+ const { resourceId: resourceIdValue, workItemId: workItemIdValue } = this.newIdentity({
24
+ adapter: this.adapter,
25
+ key: payload.externalKey,
26
+ });
27
+ const commands = [
28
+ {
29
+ kind: 'discover-resource',
30
+ resourceId: resourceIdValue,
31
+ externalKey: { adapter: this.adapter, key: payload.externalKey },
32
+ revision: payload.revision,
33
+ },
34
+ { kind: 'create-work-item', workItemId: workItemIdValue, objective: payload.title },
35
+ { kind: 'correlate-resource', resourceId: resourceIdValue, workItemId: workItemIdValue },
36
+ ];
37
+ if (payload.kind === 'pull-request') {
38
+ commands.push({
39
+ kind: 'pr.observe',
40
+ input: observePullRequest(resourceIdValue, workItemIdValue, payload),
41
+ });
42
+ }
43
+ return commands;
44
+ }
45
+ constructor(journal, checkpoints, work, resources, dependencies = {}) {
46
+ this.journal = journal;
47
+ this.checkpoints = checkpoints;
48
+ this.work = work;
49
+ this.resources = resources;
50
+ this.pullRequests = dependencies.pullRequests;
51
+ this.ids = dependencies.ids ?? new UlidIdGenerator();
52
+ this.lookup = dependencies.lookup;
53
+ this.adapter = dependencies.adapter ?? GitHubAdapter;
54
+ this.orchestration = dependencies.orchestration;
55
+ this.runs = dependencies.runs;
56
+ this.routing = dependencies.routing;
57
+ this.intake = gitHubIntakeRules(dependencies.intake ?? []);
58
+ this.conclusion = dependencies.conclusion;
59
+ }
60
+ pullRequests;
61
+ ids;
62
+ lookup;
63
+ adapter;
64
+ orchestration;
65
+ runs;
66
+ routing;
67
+ intake;
68
+ conclusion;
69
+ // Adapter filtering, checkpointing, and typed event dispatch must stay together.
70
+ // eslint-disable-next-line complexity
71
+ async runOnce(limit = 100) {
72
+ if (this.journal === undefined ||
73
+ this.checkpoints === undefined ||
74
+ this.work === undefined ||
75
+ this.resources === undefined) {
76
+ throw new Error('InboundTranslator services are required to run evidence translation');
77
+ }
78
+ const checkpoint = `reactor:integration.${this.adapter}.inbound`;
79
+ const position = await this.checkpoints.load(checkpoint);
80
+ const events = await this.journal.readAll(position, limit);
81
+ for (const event of events) {
82
+ const owned = selectGitHubAdapterEvent(event);
83
+ if (owned?.stream.id === this.adapter && owned.eventType === GitHubEventType.WorkObserved)
84
+ await this.apply(owned);
85
+ if (owned?.stream.id === this.adapter &&
86
+ owned.eventType === GitHubEventType.CommentObserved) {
87
+ await applyReviewSignal({
88
+ event: owned,
89
+ journal: this.journal,
90
+ resources: this.resources,
91
+ work: this.work,
92
+ lookup: this.lookup,
93
+ pullRequests: this.pullRequests,
94
+ ids: this.ids,
95
+ adapter: this.adapter,
96
+ orchestration: this.orchestration,
97
+ });
98
+ await applyWatchGateVerdictSignal({
99
+ event: owned,
100
+ runs: this.runs,
101
+ orchestration: this.orchestration,
102
+ });
103
+ }
104
+ await this.checkpoints.save(checkpoint, event.globalPosition);
105
+ }
106
+ return events.length;
107
+ }
108
+ async apply(event) {
109
+ if (this.work === undefined || this.resources === undefined)
110
+ return;
111
+ const payload = event.payload;
112
+ const context = commandContext(event);
113
+ const pullRequests = this.pullRequests ?? createPullRequestService(this.journal, this.work, this.resources);
114
+ const intake = evaluateIntakeRules(this.intake, gitHubIntakeFacts(payload));
115
+ const identity = await this.resolveIdentity({ adapter: this.adapter, key: payload.externalKey }, intake.admitted);
116
+ if (identity === null)
117
+ return;
118
+ if (!identity.created) {
119
+ await this.applyReobservation({
120
+ payload,
121
+ context,
122
+ pullRequests,
123
+ resourceId: identity.resourceId,
124
+ workItemId: identity.workItemId,
125
+ });
126
+ return;
127
+ }
128
+ const { resourceId: resourceIdValue, workItemId: workItemIdValue } = identity;
129
+ const isPullRequest = payload.kind === 'pull-request';
130
+ await admitObservedWork(this.admissionServices(), {
131
+ adapter: this.adapter,
132
+ resourceId: resourceIdValue,
133
+ workItemId: workItemIdValue,
134
+ kind: isPullRequest ? BuiltInResourceKind.PullRequest : BuiltInResourceKind.Issue,
135
+ externalKey: { adapter: this.adapter, key: payload.externalKey },
136
+ capabilities: isPullRequest
137
+ ? [
138
+ BuiltInResourceCapability.Commentable,
139
+ BuiltInResourceCapability.Reviewable,
140
+ BuiltInResourceCapability.Revisioned,
141
+ ]
142
+ : [BuiltInResourceCapability.Commentable],
143
+ objective: payload.title,
144
+ tags: intake.tags,
145
+ revision: payload.revision,
146
+ title: payload.title,
147
+ }, context, isPullRequest
148
+ ? async () => {
149
+ await pullRequests.observe(observePullRequest(resourceIdValue, workItemIdValue, payload), context);
150
+ }
151
+ : undefined);
152
+ }
153
+ async applyReobservation(input) {
154
+ const { payload, context, pullRequests, resourceId: resourceIdValue, workItemId: workItemIdValue, } = input;
155
+ const current = await this.resources.get(resourceIdValue);
156
+ if (current === null)
157
+ throw new Error(`Resource ${resourceIdValue} could not be loaded`);
158
+ if (current.revision !== payload.revision) {
159
+ await this.resources.discover({
160
+ resourceId: current.resourceId,
161
+ kind: current.kind,
162
+ externalKey: current.externalKey,
163
+ capabilities: current.capabilities,
164
+ revision: payload.revision,
165
+ ...(current.title === undefined ? {} : { title: current.title }),
166
+ }, context);
167
+ if (payload.outcome !== undefined && this.conclusion !== undefined) {
168
+ await concludeObservedWork({ work: this.work, conclusion: this.conclusion }, {
169
+ workItemId: workItemIdValue,
170
+ outcome: payload.outcome,
171
+ reason: `${this.adapter} ${payload.externalKey} closed`,
172
+ });
173
+ }
174
+ }
175
+ if (payload.kind === 'pull-request')
176
+ await pullRequests.observe(observePullRequest(current.resourceId, workItemIdValue, payload), context);
177
+ }
178
+ mintIdentity(externalKey) {
179
+ const key = `${externalKey.adapter}:${externalKey.key}`;
180
+ const existing = this.minted.get(key);
181
+ if (existing !== undefined)
182
+ return existing;
183
+ const identity = this.newIdentity(externalKey);
184
+ this.minted.set(key, identity);
185
+ return identity;
186
+ }
187
+ newIdentity(_externalKey) {
188
+ return {
189
+ resourceId: resourceId(this.ids.next('resource')),
190
+ workItemId: workItemId(this.ids.next('work')),
191
+ };
192
+ }
193
+ admissionServices() {
194
+ if (this.work === undefined ||
195
+ this.resources === undefined ||
196
+ this.orchestration === undefined ||
197
+ this.routing === undefined)
198
+ throw new Error('InboundTranslator requires work, resources, orchestration, and routing');
199
+ return {
200
+ work: this.work,
201
+ resources: this.resources,
202
+ orchestration: this.orchestration,
203
+ routing: this.routing,
204
+ };
205
+ }
206
+ async resolveIdentity(externalKey, admitted) {
207
+ const key = `${externalKey.adapter}:${externalKey.key}`;
208
+ const inBatch = this.minted.get(key);
209
+ if (inBatch !== undefined)
210
+ return { ...inBatch, created: false };
211
+ if (this.lookup === undefined)
212
+ throw new Error('InboundTranslator lookup is required');
213
+ const resourceIdValue = await this.lookup.resourceIdForExternalKey(externalKey);
214
+ if (resourceIdValue !== null) {
215
+ if (this.resources === undefined)
216
+ throw new Error('InboundTranslator resources are required');
217
+ const correlation = (await this.resources.correlations(resourceIdValue)).find((value) => value.role === ResourceCorrelationRole.Primary);
218
+ // A deleted WorkItem retracts its primary correlation while retaining the external
219
+ // resource as a durable tombstone. Do not remint it or let it block later intake.
220
+ if (correlation === undefined)
221
+ return null;
222
+ const identity = { resourceId: resourceIdValue, workItemId: correlation.workItemId };
223
+ this.minted.set(key, identity);
224
+ return { ...identity, created: false };
225
+ }
226
+ // An ineligible object Wake has never seen produces no WorkItem, Run, or effect.
227
+ if (!admitted)
228
+ return null;
229
+ return { ...this.mintIdentity(externalKey), created: true };
230
+ }
231
+ }
@@ -0,0 +1,84 @@
1
+ import { z } from 'zod';
2
+ import { ActivityOutcomeKind } from '../../../activities/index.js';
3
+ import { runId, RunStatus } from '../../../execution/index.js';
4
+ import { ApprovalAuthorityKind, WatchGateVerdictSignal, watchId, } from '../../../orchestration/index.js';
5
+ import { commandContext } from './inbound-context.js';
6
+ const markerSchema = z
7
+ .object({
8
+ wake: z
9
+ .object({
10
+ watchGateVerdict: z
11
+ .object({
12
+ runId: z.string().min(1),
13
+ outcome: z.enum(['DONE', 'REJECTED', 'BLOCKED', 'FAILED']),
14
+ })
15
+ .strict(),
16
+ })
17
+ .strict(),
18
+ })
19
+ .strict();
20
+ function extractMarker(body) {
21
+ for (const match of body.matchAll(/```json\s*([\s\S]*?)```/g)) {
22
+ if (match[1] === undefined)
23
+ continue;
24
+ try {
25
+ const parsed = markerSchema.safeParse(JSON.parse(match[1]));
26
+ if (parsed.success)
27
+ return parsed.data.wake.watchGateVerdict;
28
+ }
29
+ catch {
30
+ // Other JSON fences are ordinary comment content, not necessarily Wake markers.
31
+ }
32
+ }
33
+ return null;
34
+ }
35
+ function translateOutcome(outcome) {
36
+ if (outcome === 'DONE')
37
+ return ActivityOutcomeKind.Done;
38
+ if (outcome === 'REJECTED')
39
+ return ActivityOutcomeKind.Rejected;
40
+ return null;
41
+ }
42
+ export async function applyWatchGateVerdictSignal(input) {
43
+ const { event, runs, orchestration } = input;
44
+ if (runs === undefined || orchestration === undefined)
45
+ return;
46
+ const marker = extractMarker(event.payload.body);
47
+ if (marker === null)
48
+ return;
49
+ const outcome = translateOutcome(marker.outcome);
50
+ if (outcome === null)
51
+ return;
52
+ const verdict = await verifyWatchGateVerdict({ marker, outcome, runs, orchestration });
53
+ if (verdict === null)
54
+ return;
55
+ await orchestration.acceptSignal(verdict.parentWorkflowInstanceId, {
56
+ kind: WatchGateVerdictSignal,
57
+ outcome: verdict.outcome,
58
+ authority: { kind: ApprovalAuthorityKind.Watch, watch: verdict.childWatchId },
59
+ actorId: event.payload.actor.id,
60
+ actorDecision: { authorized: true, evidenceId: event.eventId },
61
+ providerEventId: event.eventId,
62
+ }, commandContext(event));
63
+ }
64
+ async function verifyWatchGateVerdict(input) {
65
+ const { marker, outcome, runs, orchestration } = input;
66
+ const run = (await runs.load(runId(marker.runId))).view;
67
+ if (run === null)
68
+ return null;
69
+ if (run.status !== RunStatus.Succeeded || run.outcome?.kind !== outcome)
70
+ return null;
71
+ const workflows = await orchestration.listAll();
72
+ const child = workflows.find((workflow) => workflow.workflowInstanceId === run.workflowInstanceId);
73
+ if (child?.parentWorkflowInstanceId === undefined || child.watchId === undefined)
74
+ return null;
75
+ const childWatchId = watchId(child.watchId);
76
+ const parent = workflows.find((workflow) => workflow.workflowInstanceId === child.parentWorkflowInstanceId);
77
+ if (!isWaitingForChildWatch(parent, childWatchId))
78
+ return null;
79
+ return { parentWorkflowInstanceId: child.parentWorkflowInstanceId, outcome, childWatchId };
80
+ }
81
+ function isWaitingForChildWatch(parent, childWatchId) {
82
+ return (parent?.waitingFor?.signalKind === WatchGateVerdictSignal &&
83
+ parent.waitingFor.from?.some((authority) => authority.kind === ApprovalAuthorityKind.Watch && authority.watch === childWatchId) === true);
84
+ }
@@ -0,0 +1,23 @@
1
+ import { GitHubIntakeFacet } from '../contracts/vocabulary.js';
2
+ // GitHub's `where` vocabulary translated onto provider-neutral facets. Eligibility and
3
+ // tagging semantics live in integrations/contracts; only the vocabulary is GitHub's.
4
+ export function gitHubIntakeRules(configured) {
5
+ return configured.map((rule) => ({
6
+ where: {
7
+ ...(rule.where.kind === undefined ? {} : { [GitHubIntakeFacet.Kind]: [rule.where.kind] }),
8
+ [GitHubIntakeFacet.Label]: rule.where.labels,
9
+ [GitHubIntakeFacet.Assignee]: rule.where.requiredAssignees,
10
+ [GitHubIntakeFacet.Author]: rule.where.requiredAuthors,
11
+ },
12
+ matchMode: rule.matchMode,
13
+ tags: rule.tags,
14
+ }));
15
+ }
16
+ export function gitHubIntakeFacts(payload) {
17
+ return {
18
+ [GitHubIntakeFacet.Kind]: [payload.kind],
19
+ [GitHubIntakeFacet.Label]: payload.labels ?? [],
20
+ [GitHubIntakeFacet.Assignee]: payload.assignees ?? [],
21
+ [GitHubIntakeFacet.Author]: [payload.actor.id],
22
+ };
23
+ }
@@ -0,0 +1,47 @@
1
+ import { BuiltInResourceKind } from '../../../resources/index.js';
2
+ import { DeliveryIntentKind } from '../../delivery/contracts/vocabulary.js';
3
+ import { parseGitHubResourceKey } from '../contracts/external-key.js';
4
+ import { GitHubAdapter, GitHubOutboundAction, } from '../contracts/vocabulary.js';
5
+ import { formatAgentRunComment } from './agent-run-comment.js';
6
+ export function translateGitHubOutbound(resource, intent) {
7
+ if (resource.externalKey.adapter !== GitHubAdapter)
8
+ throw new Error('Resource is not a GitHub resource');
9
+ const { owner, repo, number } = parseGitHubResourceKey(resource.externalKey.key);
10
+ return {
11
+ owner,
12
+ repo,
13
+ ...(resource.kind === BuiltInResourceKind.PullRequest
14
+ ? { pull_number: number }
15
+ : { issue_number: number }),
16
+ action: outboundAction(intent),
17
+ idempotencyKey: intent.intentEventId,
18
+ ...('report' in intent.payload
19
+ ? {
20
+ body: formatAgentRunComment({
21
+ idempotencyKey: intent.intentEventId,
22
+ ...intent.payload.report,
23
+ }),
24
+ }
25
+ : 'body' in intent.payload
26
+ ? { body: intent.payload.body }
27
+ : {}),
28
+ ...('revision' in intent.payload ? { sha: intent.payload.revision } : {}),
29
+ ...('method' in intent.payload ? { merge_method: intent.payload.method } : {}),
30
+ };
31
+ }
32
+ function outboundAction(intent) {
33
+ switch (intent.kind) {
34
+ case DeliveryIntentKind.PrApprove:
35
+ return GitHubOutboundAction.Approve;
36
+ case DeliveryIntentKind.PrMerge:
37
+ return 'autoMerge' in intent.payload && intent.payload.autoMerge
38
+ ? GitHubOutboundAction.EnableAutoMerge
39
+ : GitHubOutboundAction.Merge;
40
+ case DeliveryIntentKind.StatusPublish:
41
+ return GitHubOutboundAction.Status;
42
+ case DeliveryIntentKind.ReplyPublish:
43
+ case DeliveryIntentKind.AgentRunPublish:
44
+ return GitHubOutboundAction.Reply;
45
+ }
46
+ throw new Error(`Unknown delivery intent kind: ${intent.kind}`);
47
+ }
@@ -0,0 +1,29 @@
1
+ import { EventSourceKind } from '../../../kernel/index.js';
2
+ import { integrationStream } from '../../contracts/streams.js';
3
+ import { GitHubEventType } from '../contracts/events.js';
4
+ import { GitHubAdapter } from '../contracts/vocabulary.js';
5
+ const gitHubEventTypes = new Set(Object.values(GitHubEventType));
6
+ export class PollService {
7
+ journal;
8
+ source;
9
+ constructor(journal, source) {
10
+ this.journal = journal;
11
+ this.source = source;
12
+ }
13
+ async pollOnce(signal) {
14
+ const drafts = await this.source.poll(signal);
15
+ for (const draft of drafts) {
16
+ if (draft.source.kind !== EventSourceKind.Adapter || draft.source.id !== 'github') {
17
+ throw new Error('PollService accepts GitHub adapter evidence only');
18
+ }
19
+ if (!gitHubEventTypes.has(draft.eventType)) {
20
+ throw new Error('PollService cannot append canonical domain events');
21
+ }
22
+ }
23
+ if (drafts.length === 0)
24
+ return;
25
+ const stream = integrationStream(GitHubAdapter);
26
+ const existing = await this.journal.readStream(stream);
27
+ await this.journal.append(stream, existing.length, drafts.map((draft) => ({ ...draft, stream })));
28
+ }
29
+ }
@@ -0,0 +1,10 @@
1
+ export function observePullRequest(resourceId, workItemId, payload) {
2
+ return {
3
+ resourceId,
4
+ workItemId,
5
+ state: payload.state,
6
+ headRevision: payload.headRevision ?? payload.revision,
7
+ baseRevision: payload.baseRevision ?? 'unknown',
8
+ checks: payload.checks ?? 'unknown',
9
+ };
10
+ }
@@ -0,0 +1,8 @@
1
+ const issueOrPullRequestLocator = /^(?<owner>[^/]+)\/(?<repo>[^#]+)#(?<number>[1-9]\d*)$/;
2
+ export const resolveGitHubResourceUrl = (externalKey) => {
3
+ const match = issueOrPullRequestLocator.exec(externalKey.key);
4
+ if (match?.groups === undefined)
5
+ return null;
6
+ const { owner, repo, number } = match.groups;
7
+ return `https://github.com/${owner}/${repo}/issues/${number}`;
8
+ };
@@ -0,0 +1,16 @@
1
+ import { ReviewDecisionKind, } from '../../../activities/index.js';
2
+ export function translateGitHubReviewCommand(input) {
3
+ const command = input.body.trim();
4
+ if (command !== '/accepted' && command !== '/changes')
5
+ return null;
6
+ return {
7
+ resourceId: input.resourceId,
8
+ revision: input.revision,
9
+ actorId: input.actorId,
10
+ actorKind: input.actorKind,
11
+ resourceAuthorId: input.resourceAuthorId,
12
+ authorization: input.authorization,
13
+ providerEventId: input.providerEventId,
14
+ kind: command === '/accepted' ? ReviewDecisionKind.Accepted : ReviewDecisionKind.ChangesRequested,
15
+ };
16
+ }
@@ -0,0 +1,95 @@
1
+ import { WorkflowStatus } from '../../../orchestration/index.js';
2
+ import { WorkStatus } from '../../../work/index.js';
3
+ import { GitHubWakeStatusLabel, isGitHubWakeMarker, } from '../contracts/vocabulary.js';
4
+ export function reconcileGitHubWakeLabels(current, desired) {
5
+ const userLabels = current.filter((label) => !isGitHubWakeMarker(label));
6
+ return [...userLabels, ...desired];
7
+ }
8
+ export function isGitHubWakeEcho(input) {
9
+ return (input.authorLogin.toLowerCase() === input.authenticatedLogin.toLowerCase() ||
10
+ input.body.includes('<!-- wake:agent -->') ||
11
+ input.labels.some(isGitHubWakeMarker));
12
+ }
13
+ export function createGitHubWakeLabelReconciler(input) {
14
+ const openWorkItemIds = async (workItemIds) => {
15
+ const open = new Set();
16
+ for (const workItemId of workItemIds) {
17
+ const item = await input.work.get(workItemId);
18
+ if (item?.state === WorkStatus.Open)
19
+ open.add(workItemId);
20
+ }
21
+ return open;
22
+ };
23
+ return {
24
+ async runOnce() {
25
+ const workflows = await input.orchestration.listAll();
26
+ // Closed/cancelled is terminal for a WorkItem — there is no reopen path
27
+ // (see work-item.spec.md) — so once synced, a concluded issue's labels
28
+ // never need checking again. Without this, listAll() keeps returning
29
+ // every WorkItem ever created and this loop keeps making a live
30
+ // getLabels call per item, every cycle, forever.
31
+ const open = await openWorkItemIds(new Set(workflows.map((workflow) => workflow.workItemId)));
32
+ // A watch's spawned child shares its parent's work item (and so its GitHub
33
+ // resource) but is not the canonical state for that issue — only the
34
+ // top-level (non-child) workflow instance drives its stage/status labels.
35
+ // An active child instead surfaces as the watching marker below, so the
36
+ // issue's own progress labels stay stable while a background review runs.
37
+ for (const workflow of workflows) {
38
+ if (workflow.parentWorkflowInstanceId !== undefined)
39
+ continue;
40
+ if (!open.has(workflow.workItemId))
41
+ continue;
42
+ const watching = workflows.some((candidate) => candidate.parentWorkflowInstanceId === workflow.workflowInstanceId &&
43
+ candidate.status !== WorkflowStatus.Completed);
44
+ const desired = desiredWakeLabels(workflow, watching);
45
+ for (const correlation of await input.resources.correlationsForWork(workflow.workItemId)) {
46
+ const resource = await input.resources.get(correlation.resourceId);
47
+ if (resource?.externalKey.adapter !== 'github')
48
+ continue;
49
+ const locator = parseGitHubIssueKey(resource.externalKey.key);
50
+ if (locator === null)
51
+ continue;
52
+ const current = await input.getLabels(locator.owner, locator.repo, locator.number);
53
+ const next = reconcileGitHubWakeLabels(current, desired);
54
+ if (!sameLabels(current, next))
55
+ await input.setLabels(locator.owner, locator.repo, locator.number, next);
56
+ }
57
+ }
58
+ },
59
+ };
60
+ }
61
+ function desiredWakeLabels(workflow, watching) {
62
+ return [
63
+ `wake:status.${statusLabel(workflow.status)}`,
64
+ `wake:stage.${workflow.currentStage}`,
65
+ `wake:workflow.${workflow.workflowName}`,
66
+ ...(watching ? ['wake:watching'] : []),
67
+ ];
68
+ }
69
+ function statusLabel(status) {
70
+ switch (status) {
71
+ case WorkflowStatus.Active:
72
+ return GitHubWakeStatusLabel.Working;
73
+ case WorkflowStatus.Waiting:
74
+ return GitHubWakeStatusLabel.AwaitingApproval;
75
+ case WorkflowStatus.Blocked:
76
+ return GitHubWakeStatusLabel.Blocked;
77
+ case WorkflowStatus.Completed:
78
+ return GitHubWakeStatusLabel.Completed;
79
+ case WorkflowStatus.Superseded:
80
+ return GitHubWakeStatusLabel.Failed;
81
+ }
82
+ }
83
+ function parseGitHubIssueKey(key) {
84
+ const match = /^(?<owner>[^/]+)\/(?<repo>[^#]+)#(?<number>[1-9]\d*)$/.exec(key);
85
+ if (match?.groups === undefined)
86
+ return null;
87
+ return {
88
+ owner: match.groups.owner,
89
+ repo: match.groups.repo,
90
+ number: Number(match.groups.number),
91
+ };
92
+ }
93
+ function sameLabels(left, right) {
94
+ return left.length === right.length && left.every((label, index) => label === right[index]);
95
+ }
@@ -0,0 +1,47 @@
1
+ import { z } from 'zod';
2
+ import { MatchMode } from '../../../kernel/index.js';
3
+ import { isGitHubWakeMarker } from './vocabulary.js';
4
+ const repositorySchema = z
5
+ .object({ owner: z.string().trim().min(1), repo: z.string().trim().min(1) })
6
+ .strict();
7
+ const intakeTag = z
8
+ .string()
9
+ .trim()
10
+ .min(1)
11
+ .refine((tag) => !isGitHubWakeMarker(tag), {
12
+ message: 'intake tags must not come from a Wake-owned marker family; Wake would observe its own marker and re-route',
13
+ });
14
+ const intakeRuleSchema = z
15
+ .object({
16
+ where: z
17
+ .object({
18
+ kind: z.enum(['issue', 'pull-request']).optional(),
19
+ requiredAssignees: z.array(z.string().trim().min(1)).default([]),
20
+ requiredAuthors: z.array(z.string().trim().min(1)).default([]),
21
+ labels: z.array(z.string().trim().min(1)).default([]),
22
+ })
23
+ .strict(),
24
+ matchMode: z.enum([MatchMode.Any, MatchMode.All]).default(MatchMode.Any),
25
+ tags: z.array(intakeTag).default([]),
26
+ })
27
+ .strict();
28
+ export const gitHubConfigSchema = z
29
+ .object({
30
+ enabled: z.boolean(),
31
+ token: z.string().trim().min(1).optional(),
32
+ repositories: z.array(repositorySchema).min(1),
33
+ polling: z
34
+ .object({
35
+ maxPerRepo: z.number().int().positive().default(25),
36
+ commentPageSize: z.number().int().positive().max(100).default(25),
37
+ lookbackMs: z.number().int().nonnegative().default(60_000),
38
+ })
39
+ .strict()
40
+ .default({ maxPerRepo: 25, commentPageSize: 25, lookbackMs: 60_000 }),
41
+ intake: z.array(intakeRuleSchema).default([]),
42
+ publication: z
43
+ .object({ postStatusComments: z.boolean().default(true) })
44
+ .strict()
45
+ .default({ postStatusComments: true }),
46
+ })
47
+ .strict();