@atolis-hq/wake 0.2.96 → 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 -2365
  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,127 @@
1
+ import { z } from 'zod';
2
+ import { ProviderPermission, PullRequestCheckState, PullRequestState, ReviewActorKind, ReviewerAuthorizationSource, } from '../../../activities/index.js';
3
+ import { eventEnvelopeSchema, } from '../../../kernel/index.js';
4
+ import { adapterId } from '../../contracts/identifiers.js';
5
+ import { ExternalWorkOutcome } from '../../contracts/outcome-vocabulary.js';
6
+ import { IntegrationStreamKind } from '../../contracts/streams.js';
7
+ export const GitHubEventType = {
8
+ WorkObserved: 'integration.github.work-observed',
9
+ CommentObserved: 'integration.github.comment-observed',
10
+ DeliveryObserved: 'integration.github.delivery-observed',
11
+ };
12
+ const streamSchema = z
13
+ .object({
14
+ kind: z.literal(IntegrationStreamKind.Integration),
15
+ id: z.string().transform(adapterId),
16
+ })
17
+ .strict();
18
+ const rawSchema = z.record(z.string(), z.unknown());
19
+ const actorSchema = z
20
+ .object({ id: z.string(), kind: z.enum([ReviewActorKind.Human, ReviewActorKind.Bot]) })
21
+ .strict();
22
+ const authorizationSchema = z.discriminatedUnion('source', [
23
+ z
24
+ .object({
25
+ source: z.literal(ReviewerAuthorizationSource.ConfiguredReviewer),
26
+ reviewerId: z.string(),
27
+ })
28
+ .strict(),
29
+ z
30
+ .object({
31
+ source: z.literal(ReviewerAuthorizationSource.ProviderPermission),
32
+ permission: z.enum([
33
+ ProviderPermission.None,
34
+ ProviderPermission.Read,
35
+ ProviderPermission.Triage,
36
+ ProviderPermission.Write,
37
+ ProviderPermission.Maintain,
38
+ ProviderPermission.Admin,
39
+ ]),
40
+ })
41
+ .strict(),
42
+ z.object({ source: z.literal(ReviewerAuthorizationSource.None) }).strict(),
43
+ ]);
44
+ const eventSchema = z.discriminatedUnion('eventType', [
45
+ eventEnvelopeSchema.extend({
46
+ eventType: z.literal(GitHubEventType.WorkObserved),
47
+ stream: streamSchema,
48
+ payload: z
49
+ .object({
50
+ externalKey: z.string(),
51
+ kind: z.enum(['issue', 'pull-request']),
52
+ title: z.string(),
53
+ body: z.string(),
54
+ state: z.enum([PullRequestState.Open, PullRequestState.Closed, PullRequestState.Merged]),
55
+ outcome: z.enum([ExternalWorkOutcome.Completed, ExternalWorkOutcome.Cancelled]).optional(),
56
+ revision: z.string(),
57
+ headRevision: z.string().optional(),
58
+ baseRevision: z.string().optional(),
59
+ checks: z
60
+ .enum([
61
+ PullRequestCheckState.Unknown,
62
+ PullRequestCheckState.Pending,
63
+ PullRequestCheckState.Passing,
64
+ PullRequestCheckState.Failing,
65
+ ])
66
+ .optional(),
67
+ actor: actorSchema,
68
+ labels: z.array(z.string()).readonly().optional(),
69
+ assignees: z.array(z.string()).readonly().optional(),
70
+ raw: rawSchema,
71
+ })
72
+ .strict(),
73
+ }),
74
+ eventEnvelopeSchema.extend({
75
+ eventType: z.literal(GitHubEventType.CommentObserved),
76
+ stream: streamSchema,
77
+ payload: z.discriminatedUnion('reviewKind', [
78
+ z
79
+ .object({
80
+ externalKey: z.string(),
81
+ reviewKind: z.literal('formal'),
82
+ body: z.string(),
83
+ revision: z.string(),
84
+ actor: actorSchema,
85
+ resourceAuthorId: z.string().optional(),
86
+ authorization: authorizationSchema.optional(),
87
+ raw: rawSchema,
88
+ })
89
+ .strict(),
90
+ z
91
+ .object({
92
+ externalKey: z.string(),
93
+ reviewKind: z.literal('issue'),
94
+ body: z.string(),
95
+ revision: z.string(),
96
+ location: z
97
+ .object({
98
+ path: z.string(),
99
+ line: z.number().int(),
100
+ side: z.enum(['LEFT', 'RIGHT']),
101
+ })
102
+ .strict()
103
+ .optional(),
104
+ actor: actorSchema,
105
+ raw: rawSchema,
106
+ })
107
+ .strict(),
108
+ ]),
109
+ }),
110
+ eventEnvelopeSchema.extend({
111
+ eventType: z.literal(GitHubEventType.DeliveryObserved),
112
+ stream: streamSchema,
113
+ payload: z.object({ deliveryId: z.string(), raw: rawSchema }).strict(),
114
+ }),
115
+ ]);
116
+ export function decodeGitHubAdapterEvent(event) {
117
+ const result = eventSchema.safeParse(event);
118
+ if (!result.success)
119
+ throw invalidGitHubEvent(event, result.error);
120
+ return result.data;
121
+ }
122
+ export function selectGitHubAdapterEvent(event) {
123
+ return event.eventType.startsWith('integration.github.') ? decodeGitHubAdapterEvent(event) : null;
124
+ }
125
+ function invalidGitHubEvent(event, cause) {
126
+ return new Error(`Invalid GitHub adapter event ${event.eventId} at global position ${event.globalPosition} (${event.eventType}): ${cause.message}`, { cause });
127
+ }
@@ -0,0 +1,19 @@
1
+ import { z } from 'zod';
2
+ const keyPattern = /^([^/\s#]+)\/([^/\s#]+)#(\d+)$/;
3
+ export function formatGitHubResourceKey(locator) {
4
+ return `${locator.owner}/${locator.repo}#${locator.number}`;
5
+ }
6
+ export function parseGitHubResourceKey(key) {
7
+ const matched = keyPattern.exec(key);
8
+ if (matched === null)
9
+ throw new Error(`Invalid GitHub resource key: ${key}`);
10
+ const parsed = z.coerce
11
+ .number()
12
+ .int()
13
+ .positive()
14
+ .max(Number.MAX_SAFE_INTEGER, 'Expected safe integer')
15
+ .safeParse(matched[3]);
16
+ if (!parsed.success)
17
+ throw new Error(`Invalid GitHub resource key: ${key}: ${parsed.error.issues.map((issue) => issue.message).join('; ')}`, { cause: parsed.error });
18
+ return { owner: matched[1], repo: matched[2], number: parsed.data };
19
+ }
@@ -0,0 +1,9 @@
1
+ export function gitHubLabelNames(payload) {
2
+ return (payload.labels ?? []).flatMap((label) => {
3
+ const name = typeof label === 'string' ? label : label.name;
4
+ return name === undefined ? [] : [name];
5
+ });
6
+ }
7
+ export function gitHubAssigneeLogins(payload) {
8
+ return (payload.assignees ?? []).flatMap((assignee) => assignee?.login === undefined ? [] : [assignee.login]);
9
+ }
@@ -0,0 +1,55 @@
1
+ import { MergeMethod } from '../../../activities/index.js';
2
+ import { defineClosedVocabulary } from '../../../kernel/index.js';
3
+ import { adapterId } from '../../contracts/identifiers.js';
4
+ export const GitHubAdapter = adapterId('github');
5
+ export const BuiltInAdapterId = { GitHub: GitHubAdapter };
6
+ export const GitHubCheckRunStatus = defineClosedVocabulary({
7
+ Queued: 'queued',
8
+ InProgress: 'in_progress',
9
+ Completed: 'completed',
10
+ });
11
+ // GitHub's own issue/PR listing filter. Distinct from Wake's MatchMode, which
12
+ // happens to share the token "all" but means something unrelated.
13
+ export const GitHubListState = defineClosedVocabulary({
14
+ All: 'all',
15
+ Open: 'open',
16
+ Closed: 'closed',
17
+ });
18
+ export const GitHubReviewState = defineClosedVocabulary({
19
+ Approved: 'APPROVED',
20
+ ChangesRequested: 'CHANGES_REQUESTED',
21
+ });
22
+ // Label families Wake owns and republishes. Nothing may tag intake from them: the
23
+ // adapter would observe Wake's own marker, re-route, and publish again.
24
+ export const GitHubWakeStatusLabel = defineClosedVocabulary({
25
+ Working: 'working',
26
+ AwaitingApproval: 'awaiting-approval',
27
+ Blocked: 'blocked',
28
+ Completed: 'completed',
29
+ Failed: 'failed',
30
+ });
31
+ export const GitHubWakeMarkerPrefix = defineClosedVocabulary({
32
+ Status: 'wake:status.',
33
+ Stage: 'wake:stage.',
34
+ Workflow: 'wake:workflow.',
35
+ });
36
+ const GitHubWakeMarkerNamespace = 'wake:';
37
+ export function isGitHubWakeMarker(label) {
38
+ return label.startsWith(GitHubWakeMarkerNamespace);
39
+ }
40
+ // Facets a GitHub intake rule may constrain, and the observation fields they read.
41
+ export const GitHubIntakeFacet = {
42
+ Kind: 'kind',
43
+ Label: 'label',
44
+ Assignee: 'assignee',
45
+ Author: 'author',
46
+ };
47
+ export const UnknownGitHubIdentity = 'unknown-github-identity';
48
+ export const UnknownGitHubRevision = 'unknown-github-revision';
49
+ export const GitHubOutboundAction = {
50
+ Approve: 'approve',
51
+ EnableAutoMerge: 'enable-auto-merge',
52
+ Merge: MergeMethod.Merge,
53
+ Status: 'status',
54
+ Reply: 'reply',
55
+ };
@@ -0,0 +1,31 @@
1
+ export * from '../../kernel/index.js';
2
+ export * from '../contracts/identifiers.js';
3
+ export * from '../contracts/streams.js';
4
+ export * from '../delivery/application/delivery-outcome-reactor.js';
5
+ export * from '../delivery/application/delivery-projector.js';
6
+ export * from '../delivery/application/delivery-service.js';
7
+ export * from '../delivery/contracts/commands.js';
8
+ export * from '../delivery/contracts/config.js';
9
+ export * from '../delivery/contracts/event-factory.js';
10
+ export * from '../delivery/contracts/events.js';
11
+ export * from '../delivery/contracts/intents.js';
12
+ export * from '../delivery/contracts/views.js';
13
+ export * from '../delivery/contracts/vocabulary.js';
14
+ export * from './application/inbound-translator.js';
15
+ export * from './application/agent-context-reader.js';
16
+ export * from './application/poll-service.js';
17
+ export * from './application/resource-links.js';
18
+ export * from './application/review-command-translator.js';
19
+ export * from './application/wake-labels.js';
20
+ export * from './contracts/config.js';
21
+ export * from './contracts/events.js';
22
+ export * from './contracts/payloads.js';
23
+ export * from './contracts/vocabulary.js';
24
+ export * from './infrastructure/client.js';
25
+ export * from './infrastructure/etag-cache.js';
26
+ export * from './infrastructure/gh-auth.js';
27
+ export * from './infrastructure/issue-source.js';
28
+ export * from './infrastructure/pr-source.js';
29
+ export * from './infrastructure/review-source.js';
30
+ export * from './infrastructure/source.js';
31
+ export * from './provider.js';
@@ -0,0 +1,214 @@
1
+ /* eslint-disable max-lines */
2
+ import { PullRequestState } from '../../../activities/index.js';
3
+ import { GitHubListState } from '../contracts/vocabulary.js';
4
+ import { fetchPaginatedWithEtag, fetchWithEtag } from './etag-cache.js';
5
+ export function listIssues(octokit, cache, owner, repo, maxResults) {
6
+ return fetchPaginatedWithEtag({
7
+ cache,
8
+ key: `issues:${owner}/${repo}`,
9
+ maxResults,
10
+ pages: (headers) => octokit.paginate.iterator(octokit.rest.issues.listForRepo, {
11
+ owner,
12
+ repo,
13
+ state: GitHubListState.All,
14
+ per_page: Math.min(maxResults, 100),
15
+ ...(headers === undefined ? {} : { headers }),
16
+ }),
17
+ }).then((items) => items.map(normalizeIssue));
18
+ }
19
+ function normalizeIssue(issue) {
20
+ return {
21
+ number: issue.number,
22
+ title: issue.title,
23
+ body: issue.body ?? null,
24
+ state: issue.state === PullRequestState.Closed ? PullRequestState.Closed : PullRequestState.Open,
25
+ ...(issue.state_reason === undefined ? {} : { state_reason: issue.state_reason }),
26
+ updated_at: issue.updated_at,
27
+ ...(issue.user === undefined ? {} : { user: issue.user }),
28
+ ...(issue.labels === undefined ? {} : { labels: issue.labels }),
29
+ ...(issue.assignees === undefined ? {} : { assignees: issue.assignees }),
30
+ ...(issue.pull_request === undefined ? {} : { pull_request: issue.pull_request }),
31
+ };
32
+ }
33
+ export async function listPullRequests(octokit, cache, owner, repo, maxResults) {
34
+ const pullRequests = await fetchPaginatedWithEtag({
35
+ cache,
36
+ key: `pulls:${owner}/${repo}`,
37
+ maxResults,
38
+ pages: (headers) => octokit.paginate.iterator(octokit.rest.pulls.list, {
39
+ owner,
40
+ repo,
41
+ state: GitHubListState.All,
42
+ per_page: Math.min(maxResults, 100),
43
+ ...(headers === undefined ? {} : { headers }),
44
+ }),
45
+ });
46
+ return pullRequests.map(normalizePullRequestState);
47
+ }
48
+ export async function listReviews(octokit, cache, owner, repo, pullNumber, pageSize) {
49
+ const reviews = await fetchPaginatedWithEtag({
50
+ cache,
51
+ key: `reviews:${owner}/${repo}#${pullNumber}`,
52
+ pages: (headers) => octokit.paginate.iterator(octokit.rest.pulls.listReviews, {
53
+ owner,
54
+ repo,
55
+ pull_number: pullNumber,
56
+ per_page: pageSize,
57
+ ...(headers === undefined ? {} : { headers }),
58
+ }),
59
+ });
60
+ return reviews.map((review) => ({
61
+ id: review.id,
62
+ state: review.state,
63
+ body: review.body,
64
+ commit_id: review.commit_id ?? '',
65
+ submitted_at: review.submitted_at ?? '',
66
+ ...(review.user === undefined ? {} : { user: review.user }),
67
+ }));
68
+ }
69
+ export async function listReviewComments(octokit, cache, owner, repo, pullNumber, pageSize) {
70
+ const comments = await fetchPaginatedWithEtag({
71
+ cache,
72
+ key: `review-comments:${owner}/${repo}#${pullNumber}`,
73
+ pages: (headers) => octokit.paginate.iterator(octokit.rest.pulls.listReviewComments, {
74
+ owner,
75
+ repo,
76
+ pull_number: pullNumber,
77
+ per_page: Math.min(pageSize, 100),
78
+ ...(headers === undefined ? {} : { headers }),
79
+ }),
80
+ });
81
+ return comments.map((comment) => ({
82
+ id: comment.id,
83
+ body: comment.body ?? null,
84
+ created_at: comment.created_at,
85
+ updated_at: comment.updated_at,
86
+ ...(comment.user === undefined ? {} : { user: comment.user }),
87
+ ...(comment.path === undefined ? {} : { path: comment.path }),
88
+ ...(comment.line === undefined || comment.line === null ? {} : { line: comment.line }),
89
+ ...(comment.side === undefined ? {} : { side: comment.side }),
90
+ }));
91
+ }
92
+ export function listCheckRunsForRef(octokit, cache, owner, repo, ref) {
93
+ return fetchPaginatedWithEtag({
94
+ cache,
95
+ key: `check-runs:${owner}/${repo}@${ref}`,
96
+ pages: (headers) => octokit.paginate.iterator(octokit.rest.checks.listForRef, {
97
+ owner,
98
+ repo,
99
+ ref,
100
+ per_page: 100,
101
+ ...(headers === undefined ? {} : { headers }),
102
+ }),
103
+ });
104
+ }
105
+ export function getCombinedStatusForRef(octokit, cache, owner, repo, ref) {
106
+ return fetchPaginatedWithEtag({
107
+ cache,
108
+ key: `combined-status:${owner}/${repo}@${ref}`,
109
+ pages: (headers) => ({
110
+ async *[Symbol.asyncIterator]() {
111
+ let page = 1;
112
+ let count = 0;
113
+ while (true) {
114
+ const response = await octokit.rest.repos.getCombinedStatusForRef({
115
+ owner,
116
+ repo,
117
+ ref,
118
+ per_page: 100,
119
+ page,
120
+ ...(headers === undefined ? {} : { headers }),
121
+ });
122
+ const statuses = response.data.statuses;
123
+ count += statuses.length;
124
+ yield { data: statuses, headers: response.headers };
125
+ if (statuses.length < 100 || count >= response.data.total_count)
126
+ return;
127
+ page += 1;
128
+ }
129
+ },
130
+ }),
131
+ });
132
+ }
133
+ export function branch(octokit, cache, owner, repo, name) {
134
+ return fetchWithEtag({
135
+ cache,
136
+ key: `branch:${owner}/${repo}/${name}`,
137
+ request: async (headers) => {
138
+ const response = await octokit.rest.repos.getBranch({
139
+ owner,
140
+ repo,
141
+ branch: name,
142
+ ...(headers === undefined ? {} : { headers }),
143
+ });
144
+ return {
145
+ data: response.data,
146
+ ...(response.headers.etag === undefined ? {} : { etag: response.headers.etag }),
147
+ };
148
+ },
149
+ });
150
+ }
151
+ export function getIssueLabels(octokit, cache, owner, repo, issueNumber) {
152
+ return fetchWithEtag({
153
+ cache,
154
+ key: `issue:${owner}/${repo}#${issueNumber}`,
155
+ request: async (headers) => {
156
+ const response = await octokit.rest.issues.get({
157
+ owner,
158
+ repo,
159
+ issue_number: issueNumber,
160
+ ...(headers === undefined ? {} : { headers }),
161
+ });
162
+ return {
163
+ data: response.data.labels.flatMap((label) => typeof label === 'string' ? [label] : label.name === undefined ? [] : [label.name]),
164
+ ...(response.headers.etag === undefined ? {} : { etag: response.headers.etag }),
165
+ };
166
+ },
167
+ });
168
+ }
169
+ export function getPullRequest(octokit, cache, owner, repo, pullNumber) {
170
+ return fetchWithEtag({
171
+ cache,
172
+ key: `pull:${owner}/${repo}#${pullNumber}`,
173
+ request: async (headers) => {
174
+ const response = await octokit.rest.pulls.get({
175
+ owner,
176
+ repo,
177
+ pull_number: pullNumber,
178
+ ...(headers === undefined ? {} : { headers }),
179
+ });
180
+ return {
181
+ data: response.data,
182
+ ...(response.headers.etag === undefined ? {} : { etag: response.headers.etag }),
183
+ };
184
+ },
185
+ });
186
+ }
187
+ function normalizePullRequestState(pullRequest) {
188
+ return {
189
+ ...pullRequest,
190
+ state: pullRequest.state === PullRequestState.Closed
191
+ ? PullRequestState.Closed
192
+ : PullRequestState.Open,
193
+ };
194
+ }
195
+ export async function listIssueComments(octokit, cache, owner, repo, issueNumber, pageSize) {
196
+ const comments = await fetchPaginatedWithEtag({
197
+ cache,
198
+ key: `issue-comments:${owner}/${repo}#${issueNumber}`,
199
+ pages: (headers) => octokit.paginate.iterator(octokit.rest.issues.listComments, {
200
+ owner,
201
+ repo,
202
+ issue_number: issueNumber,
203
+ per_page: Math.min(pageSize, 100),
204
+ ...(headers === undefined ? {} : { headers }),
205
+ }),
206
+ });
207
+ return comments.map((comment) => ({
208
+ id: comment.id,
209
+ body: comment.body ?? null,
210
+ created_at: comment.created_at,
211
+ updated_at: comment.updated_at,
212
+ ...(comment.user === undefined ? {} : { user: comment.user }),
213
+ }));
214
+ }
@@ -0,0 +1,132 @@
1
+ import { Octokit } from '@octokit/rest';
2
+ import { MergeMethod } from '../../../activities/index.js';
3
+ import { GitHubOutboundAction } from '../contracts/vocabulary.js';
4
+ import { branch, getCombinedStatusForRef, getIssueLabels, getPullRequest, listCheckRunsForRef, listIssueComments, listIssues, listPullRequests, listReviewComments, listReviews, } from './client-reads.js';
5
+ import { createEtagCache } from './etag-cache.js';
6
+ // Octokit's request-log plugin reports every non-2xx response through this
7
+ // callback, including the expected 304 responses produced by conditional ETag
8
+ // reads. Keep those cache hits quiet, but retain a small, safe operator signal
9
+ // for actual GitHub failures. Octokit may pass error context after the message;
10
+ // deliberately ignore it because it can contain request authentication data.
11
+ function requestLogStatus(message) {
12
+ const match = / - (\d{3}) with id /.exec(message);
13
+ return match === null ? undefined : Number(match[1]);
14
+ }
15
+ export function redactGitHubRequestMessage(message) {
16
+ if (typeof message !== 'string')
17
+ return 'GitHub request failed';
18
+ return message
19
+ .replace(/\b(?:gh[pousr]_[A-Za-z0-9_]+|github_pat_[A-Za-z0-9_]+)\b/g, '<redacted>')
20
+ .replace(/\b(?:bearer|token|basic)\s+\S+/gi, '<redacted>')
21
+ .replace(/([?&](?:access_token|token|authorization)=)[^&\s]+/gi, '$1<redacted>');
22
+ }
23
+ function logGitHubRequestFailure(message) {
24
+ const text = redactGitHubRequestMessage(message);
25
+ if (requestLogStatus(text) === 304)
26
+ return;
27
+ process.stderr.write(`GitHub request failed: ${text}\n`);
28
+ }
29
+ export function createGitHubClient(token) {
30
+ const octokit = new Octokit({
31
+ auth: token,
32
+ log: { debug() { }, info() { }, warn() { }, error: logGitHubRequestFailure },
33
+ });
34
+ const cache = createEtagCache();
35
+ return {
36
+ authenticatedLogin: async () => (await octokit.rest.users.getAuthenticated()).data.login,
37
+ listIssues: (owner, repo, maxResults) => listIssues(octokit, cache, owner, repo, maxResults),
38
+ listPullRequests: (owner, repo, maxResults) => listPullRequests(octokit, cache, owner, repo, maxResults),
39
+ listIssueComments: (owner, repo, issueNumber, pageSize) => listIssueComments(octokit, cache, owner, repo, issueNumber, pageSize),
40
+ listReviewComments: (owner, repo, pullNumber, pageSize) => listReviewComments(octokit, cache, owner, repo, pullNumber, pageSize),
41
+ getIssueLabels: (owner, repo, issueNumber) => getIssueLabels(octokit, cache, owner, repo, issueNumber),
42
+ setIssueLabels: async (owner, repo, issueNumber, labels) => {
43
+ await octokit.rest.issues.setLabels({
44
+ owner,
45
+ repo,
46
+ issue_number: issueNumber,
47
+ labels: [...labels],
48
+ });
49
+ },
50
+ getPullRequest: (owner, repo, pullNumber) => getPullRequest(octokit, cache, owner, repo, pullNumber),
51
+ listReviews: (owner, repo, pullNumber, pageSize) => listReviews(octokit, cache, owner, repo, pullNumber, pageSize),
52
+ listCheckRunsForRef: (owner, repo, ref) => listCheckRunsForRef(octokit, cache, owner, repo, ref),
53
+ getCombinedStatusForRef: (owner, repo, ref) => getCombinedStatusForRef(octokit, cache, owner, repo, ref),
54
+ branch: (owner, repo, name) => branch(octokit, cache, owner, repo, name),
55
+ deliver: (command) => deliver(octokit, command),
56
+ };
57
+ }
58
+ async function deliver(octokit, command) {
59
+ const marker = `<!-- wake:delivery:${command.idempotencyKey} -->`;
60
+ if (command.action === 'approve') {
61
+ if (command.pull_number === undefined)
62
+ throw new Error('GitHub approval requires a pull request');
63
+ const response = await octokit.rest.pulls.createReview({
64
+ owner: command.owner,
65
+ repo: command.repo,
66
+ pull_number: command.pull_number,
67
+ event: 'APPROVE',
68
+ body: marker,
69
+ });
70
+ return String(response.data.id);
71
+ }
72
+ if (command.action === MergeMethod.Merge) {
73
+ if (command.pull_number === undefined)
74
+ throw new Error('GitHub merge requires a pull request');
75
+ return directMerge(octokit, command);
76
+ }
77
+ if (command.action === GitHubOutboundAction.EnableAutoMerge) {
78
+ return enableAutoMerge(octokit, command);
79
+ }
80
+ const issueNumber = command.issue_number ?? command.pull_number;
81
+ if (issueNumber === undefined)
82
+ throw new Error('GitHub comment requires an issue or pull request');
83
+ const response = await octokit.rest.issues.createComment({
84
+ owner: command.owner,
85
+ repo: command.repo,
86
+ issue_number: issueNumber,
87
+ body: `${command.body ?? ''}\n${marker}`,
88
+ });
89
+ return String(response.data.id);
90
+ }
91
+ async function enableAutoMerge(octokit, command) {
92
+ if (command.pull_number === undefined)
93
+ throw new Error('GitHub auto-merge requires a pull request');
94
+ if (command.merge_method === undefined)
95
+ throw new Error('GitHub auto-merge requires an explicit merge method');
96
+ const pullRequest = await octokit.rest.pulls.get({
97
+ owner: command.owner,
98
+ repo: command.repo,
99
+ pull_number: command.pull_number,
100
+ });
101
+ try {
102
+ const result = await octokit.graphql(`mutation EnableWakeAutoMerge($pullRequestId: ID!, $mergeMethod: PullRequestMergeMethod!) {
103
+ enablePullRequestAutoMerge(input: { pullRequestId: $pullRequestId, mergeMethod: $mergeMethod }) {
104
+ pullRequest { id }
105
+ }
106
+ }`, {
107
+ pullRequestId: pullRequest.data.node_id,
108
+ mergeMethod: graphQlMergeMethod(command.merge_method),
109
+ });
110
+ return result.enablePullRequestAutoMerge.pullRequest.id;
111
+ }
112
+ catch (error) {
113
+ if (!isAlreadyCleanError(error))
114
+ throw error;
115
+ return directMerge(octokit, command);
116
+ }
117
+ }
118
+ async function directMerge(octokit, command) {
119
+ const response = await octokit.rest.pulls.merge({
120
+ owner: command.owner,
121
+ repo: command.repo,
122
+ pull_number: command.pull_number,
123
+ ...(command.merge_method === undefined ? {} : { merge_method: command.merge_method }),
124
+ });
125
+ return response.data.sha;
126
+ }
127
+ function graphQlMergeMethod(method) {
128
+ return method.toUpperCase();
129
+ }
130
+ function isAlreadyCleanError(error) {
131
+ return error instanceof Error && /is in clean status/i.test(error.message);
132
+ }
@@ -0,0 +1,10 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { isGitHubWakeMarker } from '../contracts/vocabulary.js';
3
+ // Wake's own status/stage/workflow labels are excluded so republishing them never
4
+ // looks like an external change — see reconcileGitHubWakeLabels.
5
+ export function gitHubContentFingerprint(input) {
6
+ return createHash('sha256').update(JSON.stringify(input)).digest('hex');
7
+ }
8
+ export function withoutWakeMarkers(labels) {
9
+ return [...labels].filter((label) => !isGitHubWakeMarker(label)).sort();
10
+ }
@@ -0,0 +1,31 @@
1
+ import { DeliveryResultKind } from '../../delivery/contracts/vocabulary.js';
2
+ const GitHubDeliveryFailureCode = 'github-error';
3
+ export function createGitHubDelivery(deliver) {
4
+ return {
5
+ async deliver(intent) {
6
+ try {
7
+ return {
8
+ kind: DeliveryResultKind.Confirmed,
9
+ externalId: await deliver(intent, intent.intentEventId),
10
+ };
11
+ }
12
+ catch (error) {
13
+ return {
14
+ kind: DeliveryResultKind.Failed,
15
+ code: GitHubDeliveryFailureCode,
16
+ message: githubErrorMessage(error),
17
+ };
18
+ }
19
+ },
20
+ async reconcile() {
21
+ return { kind: DeliveryResultKind.Unknown };
22
+ },
23
+ };
24
+ }
25
+ function githubErrorMessage(error) {
26
+ if (error instanceof Error)
27
+ return error.message;
28
+ if (typeof error === 'string')
29
+ return error;
30
+ return 'GitHub delivery failed with a non-Error rejection';
31
+ }