@atolis-hq/wake 0.2.97 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/activities/agent/agent-activity-definition.js +26 -0
- package/dist/src/activities/agent/agent-activity.js +171 -0
- package/dist/src/activities/agent/agent-result.js +149 -0
- package/dist/src/activities/contracts/activity.js +10 -0
- package/dist/src/activities/contracts/config.js +2 -0
- package/dist/src/activities/contracts/event-schema.js +302 -0
- package/dist/src/activities/contracts/events.js +42 -0
- package/dist/src/activities/contracts/identifiers.js +29 -0
- package/dist/src/activities/contracts/registry.js +71 -0
- package/dist/src/activities/contracts/streams.js +17 -0
- package/dist/src/activities/contracts/vocabulary.js +58 -0
- package/dist/src/activities/index.js +21 -0
- package/dist/src/activities/pr/activity-support.js +111 -0
- package/dist/src/activities/pr/application.js +158 -0
- package/dist/src/activities/pr/approve.js +85 -0
- package/dist/src/activities/pr/capability.js +11 -0
- package/dist/src/activities/pr/decision-claim.js +76 -0
- package/dist/src/activities/pr/event-drafts.js +66 -0
- package/dist/src/activities/pr/intent.js +37 -0
- package/dist/src/activities/pr/merge-authority-gate.js +14 -0
- package/dist/src/activities/pr/merge.js +110 -0
- package/dist/src/activities/pr/policy.js +135 -0
- package/dist/src/activities/pr/projection.js +130 -0
- package/dist/src/activities/pr/vocabulary.js +30 -0
- package/dist/src/activities/review/authorization.js +22 -0
- package/dist/src/activities/review/contracts.js +22 -0
- package/dist/src/activities/review/signals.js +3 -0
- package/dist/src/bootstrap/analytics-projection.js +26 -0
- package/dist/src/bootstrap/board-projection.js +337 -0
- package/dist/src/bootstrap/composition-root.js +382 -0
- package/dist/src/bootstrap/config/load-config.js +51 -0
- package/dist/src/bootstrap/config/root-schema.js +134 -0
- package/dist/src/bootstrap/external-ref.js +12 -0
- package/dist/src/bootstrap/fake-provider-files.js +44 -0
- package/dist/src/bootstrap/fake-scenarios.js +22 -0
- package/dist/src/bootstrap/index.js +48 -0
- package/dist/src/bootstrap/initialise.js +434 -0
- package/dist/src/bootstrap/paths.js +15 -0
- package/dist/src/bootstrap/projection-runtime.js +27 -0
- package/dist/src/bootstrap/runner-quota-reporter.js +21 -0
- package/dist/src/bootstrap/runner-registry.js +30 -0
- package/dist/src/bootstrap/schedule-checkpoint-store.js +49 -0
- package/dist/src/bootstrap/self-update-application.js +195 -0
- package/dist/src/bootstrap/self-update-failure-log.js +33 -0
- package/dist/src/bootstrap/source-update-port.js +47 -0
- package/dist/src/bootstrap/status-publish-activity.js +42 -0
- package/dist/src/bootstrap/surface-api-applications.js +325 -0
- package/dist/src/bootstrap/surface-api-execution-applications.js +95 -0
- package/dist/src/bootstrap/surface-api-metadata.js +12 -0
- package/dist/src/bootstrap/surface-api-projection-pages.js +22 -0
- package/dist/src/bootstrap/surface-api-run-context.js +5 -0
- package/dist/src/bootstrap/surface-api-transcripts.js +57 -0
- package/dist/src/bootstrap/surface-api-work-applications.js +199 -0
- package/dist/src/bootstrap/surface-applications.js +7 -0
- package/dist/src/bootstrap/surface-cli-applications.js +701 -0
- package/dist/src/bootstrap/update-ledger.js +61 -0
- package/dist/src/bootstrap/update-maintenance-lease.js +176 -0
- package/dist/src/{version.js → bootstrap/version.js} +35 -51
- package/dist/src/control-plane/application/advance-once.js +184 -0
- package/dist/src/control-plane/application/control-plane-projection.js +42 -0
- package/dist/src/control-plane/application/control-plane-service.js +42 -0
- package/dist/src/control-plane/application/intake-pipeline.js +29 -0
- package/dist/src/control-plane/application/runner-control-service.js +66 -0
- package/dist/src/control-plane/application/runner-pipeline.js +57 -0
- package/dist/src/control-plane/application/schedule-service.js +47 -0
- package/dist/src/control-plane/application/work-cancellation-policy.js +31 -0
- package/dist/src/control-plane/contracts/commands.js +10 -0
- package/dist/src/control-plane/contracts/config.js +22 -0
- package/dist/src/control-plane/contracts/events.js +81 -0
- package/dist/src/control-plane/contracts/streams.js +5 -0
- package/dist/src/control-plane/domain/dispatch-policy.js +15 -0
- package/dist/src/control-plane/domain/quota-policy.js +26 -0
- package/dist/src/control-plane/domain/runner-quota.js +35 -0
- package/dist/src/control-plane/domain/schedule-policy.js +46 -0
- package/dist/src/control-plane/index.js +20 -0
- package/dist/src/control-plane/infrastructure/intake-host.js +24 -0
- package/dist/src/control-plane/infrastructure/resident-host.js +45 -0
- package/dist/src/control-plane/infrastructure/tick-host.js +35 -0
- package/dist/src/execution/application/activation-claim.js +50 -0
- package/dist/src/execution/application/active-run-cancellation.js +14 -0
- package/dist/src/execution/application/execution-activity.js +97 -0
- package/dist/src/execution/application/execution-projection.js +17 -0
- package/dist/src/execution/application/execution-service.js +372 -0
- package/dist/src/execution/application/execution-validation.js +26 -0
- package/dist/src/execution/application/recovery-service.js +212 -0
- package/dist/src/execution/application/run-lifecycle.js +115 -0
- package/dist/src/execution/application/run-liveness-service.js +80 -0
- package/dist/src/execution/application/run-repository.js +27 -0
- package/dist/src/execution/contracts/commands.js +1 -0
- package/dist/src/execution/contracts/config.js +35 -0
- package/dist/src/execution/contracts/control-plane.js +1 -0
- package/dist/src/execution/contracts/event-factory.js +53 -0
- package/dist/src/execution/contracts/events.js +274 -0
- package/dist/src/execution/contracts/identifiers.js +5 -0
- package/dist/src/execution/contracts/liveness.js +1 -0
- package/dist/src/execution/contracts/results.js +1 -0
- package/dist/src/execution/contracts/runner.js +15 -0
- package/dist/src/execution/contracts/streams.js +10 -0
- package/dist/src/execution/contracts/views.js +1 -0
- package/dist/src/execution/contracts/vocabulary.js +43 -0
- package/dist/src/execution/contracts/workspace.js +1 -0
- package/dist/src/execution/domain/run-result.js +34 -0
- package/dist/src/execution/domain/run.js +142 -0
- package/dist/src/execution/index.js +31 -0
- package/dist/src/execution/infrastructure/agent-runner-adapter.js +114 -0
- package/dist/src/execution/infrastructure/process-execution.js +29 -0
- package/dist/src/execution/infrastructure/prompt-templates.js +42 -0
- package/dist/src/execution/infrastructure/runners/claude.js +120 -0
- package/dist/src/execution/infrastructure/runners/codex.js +143 -0
- package/dist/src/execution/infrastructure/runners/command.js +4 -0
- package/dist/src/execution/infrastructure/runners/cursor.js +69 -0
- package/dist/src/execution/infrastructure/runners/fake-scenarios.js +99 -0
- package/dist/src/execution/infrastructure/runners/fake.js +65 -0
- package/dist/src/execution/infrastructure/runners/registry.js +26 -0
- package/dist/src/execution/infrastructure/transcript-store.js +223 -0
- package/dist/src/execution/infrastructure/transcripts.js +11 -0
- package/dist/src/execution/infrastructure/workspace/fake-workspace.js +19 -0
- package/dist/src/execution/infrastructure/workspace/git-workspace.js +241 -0
- package/dist/src/integrations/application/agent-run-publication-reactor.js +111 -0
- package/dist/src/integrations/application/artifact-registration-reactor.js +159 -0
- package/dist/src/integrations/application/poll-service.js +25 -0
- package/dist/src/integrations/application/terminal-agent-run-report.js +40 -0
- package/dist/src/integrations/application/work-admission.js +31 -0
- package/dist/src/integrations/application/work-conclusion.js +19 -0
- package/dist/src/integrations/contracts/artifact-events.js +60 -0
- package/dist/src/integrations/contracts/artifact-vocabulary.js +9 -0
- package/dist/src/integrations/contracts/config.js +14 -0
- package/dist/src/integrations/contracts/identifiers.js +5 -0
- package/dist/src/integrations/contracts/intake-rules.js +14 -0
- package/dist/src/integrations/contracts/intake.js +1 -0
- package/dist/src/integrations/contracts/outcome-vocabulary.js +7 -0
- package/dist/src/integrations/contracts/provider.js +37 -0
- package/dist/src/integrations/contracts/streams.js +10 -0
- package/dist/src/integrations/delivery/application/delivery-outcome-reactor.js +75 -0
- package/dist/src/integrations/delivery/application/delivery-projector.js +165 -0
- package/dist/src/integrations/delivery/application/delivery-service.js +173 -0
- package/dist/src/integrations/delivery/contracts/commands.js +1 -0
- package/dist/src/integrations/delivery/contracts/config.js +1 -0
- package/dist/src/integrations/delivery/contracts/event-factory.js +18 -0
- package/dist/src/integrations/delivery/contracts/events.js +86 -0
- package/dist/src/integrations/delivery/contracts/intents.js +89 -0
- package/dist/src/integrations/delivery/contracts/views.js +1 -0
- package/dist/src/integrations/delivery/contracts/vocabulary.js +22 -0
- package/dist/src/integrations/fake/durable-delivery-provider.js +48 -0
- package/dist/src/integrations/fake/external-sink.js +9 -0
- package/dist/src/integrations/fake/external-source.js +44 -0
- package/dist/src/integrations/fake/inbound-translator.js +130 -0
- package/dist/src/integrations/fake/provider.js +95 -0
- package/dist/src/integrations/github/application/agent-context-reader.js +54 -0
- package/dist/src/integrations/github/application/agent-run-comment.js +94 -0
- package/dist/src/integrations/github/application/comment-history-reader.js +43 -0
- package/dist/src/integrations/github/application/inbound-context.js +10 -0
- package/dist/src/integrations/github/application/inbound-review-signals.js +159 -0
- package/dist/src/integrations/github/application/inbound-translator.js +231 -0
- package/dist/src/integrations/github/application/inbound-watch-gate-signals.js +84 -0
- package/dist/src/integrations/github/application/intake-policy.js +23 -0
- package/dist/src/integrations/github/application/outbound-translator.js +47 -0
- package/dist/src/integrations/github/application/poll-service.js +29 -0
- package/dist/src/integrations/github/application/pull-request-translation.js +10 -0
- package/dist/src/integrations/github/application/resource-links.js +8 -0
- package/dist/src/integrations/github/application/review-command-translator.js +16 -0
- package/dist/src/integrations/github/application/wake-labels.js +95 -0
- package/dist/src/integrations/github/contracts/config.js +47 -0
- package/dist/src/integrations/github/contracts/events.js +127 -0
- package/dist/src/integrations/github/contracts/external-key.js +19 -0
- package/dist/src/integrations/github/contracts/payloads.js +9 -0
- package/dist/src/integrations/github/contracts/vocabulary.js +55 -0
- package/dist/src/integrations/github/index.js +31 -0
- package/dist/src/integrations/github/infrastructure/client-reads.js +214 -0
- package/dist/src/integrations/github/infrastructure/client.js +132 -0
- package/dist/src/integrations/github/infrastructure/content-fingerprint.js +10 -0
- package/dist/src/integrations/github/infrastructure/delivery.js +31 -0
- package/dist/src/integrations/github/infrastructure/etag-cache.js +56 -0
- package/dist/src/integrations/github/infrastructure/gh-auth.js +19 -0
- package/dist/src/integrations/github/infrastructure/issue-source.js +109 -0
- package/dist/src/integrations/github/infrastructure/pr-source.js +186 -0
- package/dist/src/integrations/github/infrastructure/review-source.js +70 -0
- package/dist/src/integrations/github/infrastructure/source.js +108 -0
- package/dist/src/integrations/github/provider.js +96 -0
- package/dist/src/integrations/index.js +30 -0
- package/dist/src/kernel/contracts/checkpoint-store.js +1 -0
- package/dist/src/kernel/contracts/clock.js +1 -0
- package/dist/src/kernel/contracts/commands.js +1 -0
- package/dist/src/kernel/contracts/event-journal.js +2 -0
- package/dist/src/kernel/contracts/event-schema.js +54 -0
- package/dist/src/kernel/contracts/events.js +11 -0
- package/dist/src/kernel/contracts/id-generator.js +1 -0
- package/dist/src/kernel/contracts/identifiers.js +8 -0
- package/dist/src/kernel/contracts/projection-store.js +1 -0
- package/dist/src/kernel/contracts/relations.js +1 -0
- package/dist/src/kernel/contracts/schema.js +17 -0
- package/dist/src/kernel/contracts/vocabulary.js +6 -0
- package/dist/src/kernel/domain/event-envelope.js +29 -0
- package/dist/src/kernel/domain/match-mode.js +11 -0
- package/dist/src/kernel/domain/relation.js +10 -0
- package/dist/src/kernel/index.js +17 -0
- package/dist/src/{lib/clock.js → kernel/infrastructure/system-clock.js} +3 -3
- package/dist/src/kernel/infrastructure/ulid-id-generator.js +9 -0
- package/dist/src/main.js +137 -1030
- package/dist/src/orchestration/application/accept-activity-outcome.js +25 -0
- package/dist/src/orchestration/application/accept-signal.js +35 -0
- package/dist/src/orchestration/application/advance-workflow.js +160 -0
- package/dist/src/orchestration/application/coordination-claims.js +107 -0
- package/dist/src/orchestration/application/group-budget-recorder.js +43 -0
- package/dist/src/orchestration/application/orchestration-projection.js +20 -0
- package/dist/src/orchestration/application/orchestration-repository.js +36 -0
- package/dist/src/orchestration/application/orchestration-service.js +82 -0
- package/dist/src/orchestration/application/request-child.js +118 -0
- package/dist/src/orchestration/application/signal-reactor.js +17 -0
- package/dist/src/orchestration/application/start-workflow.js +51 -0
- package/dist/src/orchestration/application/watch-reactor.js +82 -0
- package/dist/src/orchestration/contracts/activity-outcome.js +18 -0
- package/dist/src/orchestration/contracts/commands.js +1 -0
- package/dist/src/orchestration/contracts/config.js +128 -0
- package/dist/src/orchestration/contracts/event-decoder.js +263 -0
- package/dist/src/orchestration/contracts/events.js +41 -0
- package/dist/src/orchestration/contracts/identifiers.js +35 -0
- package/dist/src/orchestration/contracts/streams.js +38 -0
- package/dist/src/orchestration/contracts/views.js +1 -0
- package/dist/src/orchestration/contracts/vocabulary.js +30 -0
- package/dist/src/orchestration/domain/activation-policy.js +55 -0
- package/dist/src/orchestration/domain/approval-defaults.js +17 -0
- package/dist/src/orchestration/domain/child-policy.js +63 -0
- package/dist/src/orchestration/domain/compiler.js +162 -0
- package/dist/src/orchestration/domain/coordination-events.js +25 -0
- package/dist/src/orchestration/domain/decision-events.js +47 -0
- package/dist/src/orchestration/domain/interpreter.js +49 -0
- package/dist/src/orchestration/domain/operator-retry-policy.js +34 -0
- package/dist/src/orchestration/domain/retry-policy.js +26 -0
- package/dist/src/orchestration/domain/signal-policy.js +120 -0
- package/dist/src/orchestration/domain/supplemental-policy.js +61 -0
- package/dist/src/orchestration/domain/transition.js +55 -0
- package/dist/src/orchestration/domain/workflow-graph.js +41 -0
- package/dist/src/orchestration/domain/workflow-instance-events.js +236 -0
- package/dist/src/orchestration/domain/workflow-instance.js +41 -0
- package/dist/src/orchestration/domain/workflow-selector.js +21 -0
- package/dist/src/orchestration/index.js +19 -0
- package/dist/src/persistence/application/projection-runner.js +79 -0
- package/dist/src/persistence/filesystem/file-checkpoint-store.js +35 -0
- package/dist/src/persistence/filesystem/file-event-journal.js +143 -0
- package/dist/src/persistence/filesystem/file-lock.js +91 -0
- package/dist/src/persistence/filesystem/file-projection-store.js +64 -0
- package/dist/src/persistence/index.js +8 -0
- package/dist/src/persistence/memory/in-memory-checkpoint-store.js +14 -0
- package/dist/src/persistence/memory/in-memory-event-journal.js +88 -0
- package/dist/src/persistence/memory/in-memory-projection-store.js +17 -0
- package/dist/src/resources/application/lookup-projections.js +48 -0
- package/dist/src/resources/application/resource-lookup.js +16 -0
- package/dist/src/resources/application/resource-projections.js +81 -0
- package/dist/src/resources/application/resource-repository.js +18 -0
- package/dist/src/resources/application/resource-service.js +83 -0
- package/dist/src/resources/contracts/commands.js +1 -0
- package/dist/src/resources/contracts/config.js +2 -0
- package/dist/src/resources/contracts/events.js +83 -0
- package/dist/src/resources/contracts/identifiers.js +15 -0
- package/dist/src/resources/contracts/streams.js +6 -0
- package/dist/src/resources/contracts/views.js +1 -0
- package/dist/src/resources/contracts/vocabulary.js +67 -0
- package/dist/src/resources/domain/correlation.js +8 -0
- package/dist/src/resources/domain/resource.js +58 -0
- package/dist/src/resources/index.js +14 -0
- package/dist/src/surfaces/api/contracts/activities.js +1 -0
- package/dist/src/surfaces/api/contracts/board.js +2 -0
- package/dist/src/surfaces/api/contracts/common.js +46 -0
- package/dist/src/surfaces/api/contracts/control-plane.js +5 -0
- package/dist/src/surfaces/api/contracts/events.js +1 -0
- package/dist/src/surfaces/api/contracts/execution.js +1 -0
- package/dist/src/surfaces/api/contracts/index.js +13 -0
- package/dist/src/surfaces/api/contracts/observability.js +1 -0
- package/dist/src/surfaces/api/contracts/orchestration.js +1 -0
- package/dist/src/surfaces/api/contracts/resources.js +1 -0
- package/dist/src/surfaces/api/contracts/status.js +1 -0
- package/dist/src/surfaces/api/contracts/system.js +1 -0
- package/dist/src/surfaces/api/contracts/transport-values.js +39 -0
- package/dist/src/surfaces/api/contracts/work.js +17 -0
- package/dist/src/surfaces/api/http-server.js +121 -0
- package/dist/src/surfaces/api/presenters/activities.js +1 -0
- package/dist/src/surfaces/api/presenters/board.js +3 -0
- package/dist/src/surfaces/api/presenters/control-plane.js +1 -0
- package/dist/src/surfaces/api/presenters/events.js +1 -0
- package/dist/src/surfaces/api/presenters/execution.js +59 -0
- package/dist/src/surfaces/api/presenters/observability.js +1 -0
- package/dist/src/surfaces/api/presenters/orchestration.js +19 -0
- package/dist/src/surfaces/api/presenters/resources.js +15 -0
- package/dist/src/surfaces/api/presenters/status.js +3 -0
- package/dist/src/surfaces/api/presenters/system.js +14 -0
- package/dist/src/surfaces/api/presenters/work.js +16 -0
- package/dist/src/surfaces/api/problem-details.js +9 -0
- package/dist/src/surfaces/api/router.js +13 -0
- package/dist/src/surfaces/api/routes/activities.js +1 -0
- package/dist/src/surfaces/api/routes/applications.js +1 -0
- package/dist/src/surfaces/api/routes/commands.js +82 -0
- package/dist/src/surfaces/api/routes/control-plane.js +6 -0
- package/dist/src/surfaces/api/routes/events.js +1 -0
- package/dist/src/surfaces/api/routes/execution.js +8 -0
- package/dist/src/surfaces/api/routes/index.js +18 -0
- package/dist/src/surfaces/api/routes/observability.js +1 -0
- package/dist/src/surfaces/api/routes/orchestration.js +1 -0
- package/dist/src/surfaces/api/routes/pagination.js +78 -0
- package/dist/src/surfaces/api/routes/read.js +135 -0
- package/dist/src/surfaces/api/routes/resources.js +1 -0
- package/dist/src/surfaces/api/routes/responses.js +67 -0
- package/dist/src/surfaces/api/routes/system.js +1 -0
- package/dist/src/surfaces/api/routes/work.js +9 -0
- package/dist/src/surfaces/cli/commands/api.js +1 -0
- package/dist/src/surfaces/cli/commands/audit.js +10 -0
- package/dist/src/surfaces/cli/commands/correlate.js +2 -0
- package/dist/src/surfaces/cli/commands/doctor.js +6 -0
- package/dist/src/surfaces/cli/commands/init.js +39 -0
- package/dist/src/surfaces/cli/commands/sandbox-entrypoint.js +33 -0
- package/dist/src/surfaces/cli/commands/sandbox-setup.js +29 -0
- package/dist/src/surfaces/cli/commands/sandbox.js +105 -0
- package/dist/src/surfaces/cli/commands/self-update.js +38 -0
- package/dist/src/surfaces/cli/commands/smoke.js +16 -0
- package/dist/src/surfaces/cli/commands/start.js +1 -0
- package/dist/src/surfaces/cli/commands/stop.js +13 -0
- package/dist/src/surfaces/cli/commands/tick.js +1 -0
- package/dist/src/surfaces/cli/commands/ui.js +2 -0
- package/dist/src/surfaces/cli/commands/validate-state.js +5 -0
- package/dist/src/surfaces/cli/infrastructure/docker-cli.js +221 -0
- package/dist/src/surfaces/cli/infrastructure/process-log.js +86 -0
- package/dist/src/surfaces/cli/main.js +140 -0
- package/dist/src/surfaces/cli/usage.js +33 -0
- package/dist/src/surfaces/contracts/config.js +34 -0
- package/dist/src/surfaces/index.js +47 -0
- package/dist/src/surfaces/web-assets/assets/index-Bfn4FwZG.css +1 -0
- package/dist/src/surfaces/web-assets/assets/index-ipB6JPGU.js +1090 -0
- package/dist/src/surfaces/web-assets/index.html +13 -0
- package/dist/src/surfaces/web-host/asset-source.js +1 -0
- package/dist/src/surfaces/web-host/packaged-assets.js +44 -0
- package/dist/src/work/application/work-projection.js +59 -0
- package/dist/src/work/application/work-repository.js +18 -0
- package/dist/src/work/application/work-service.js +117 -0
- package/dist/src/work/contracts/commands.js +1 -0
- package/dist/src/work/contracts/config.js +2 -0
- package/dist/src/work/contracts/events.js +103 -0
- package/dist/src/work/contracts/identifiers.js +5 -0
- package/dist/src/work/contracts/streams.js +6 -0
- package/dist/src/work/contracts/views.js +1 -0
- package/dist/src/work/contracts/vocabulary.js +6 -0
- package/dist/src/work/domain/work-item.js +89 -0
- package/dist/src/work/index.js +11 -0
- package/docker/Dockerfile +10 -6
- package/docker/Dockerfile.packaged +3 -3
- package/package.json +29 -4
- package/prompts/implement.md +2 -2
- package/templates/SETUP.md +7 -7
- package/dist/src/adapters/claude/claude-runner.js +0 -529
- package/dist/src/adapters/codex/codex-runner.js +0 -503
- package/dist/src/adapters/cursor/cursor-runner.js +0 -418
- package/dist/src/adapters/docker/docker-cli.js +0 -150
- package/dist/src/adapters/fake/fake-artifact-verifier.js +0 -14
- package/dist/src/adapters/fake/fake-github-pull-request-activity-source.js +0 -77
- package/dist/src/adapters/fake/fake-resource-index.js +0 -21
- package/dist/src/adapters/fake/fake-runner.js +0 -77
- package/dist/src/adapters/fake/fake-ticketing-system.js +0 -185
- package/dist/src/adapters/fake/fake-workspace-manager.js +0 -81
- package/dist/src/adapters/fs/resource-index.js +0 -126
- package/dist/src/adapters/fs/self-update-ledger.js +0 -17
- package/dist/src/adapters/fs/state-store.js +0 -775
- package/dist/src/adapters/git/git-workspace-manager.js +0 -289
- package/dist/src/adapters/github/github-artifact-verifier.js +0 -38
- package/dist/src/adapters/github/github-auth.js +0 -16
- package/dist/src/adapters/github/github-client.js +0 -249
- package/dist/src/adapters/github/github-etag-cache.js +0 -57
- package/dist/src/adapters/github/github-issues-work-source.js +0 -692
- package/dist/src/adapters/github/github-pull-request-activity-source.js +0 -584
- package/dist/src/adapters/github/github-pull-request-merge-actor.js +0 -45
- package/dist/src/adapters/http/ui-assets.js +0 -1188
- package/dist/src/adapters/http/ui-data.js +0 -1107
- package/dist/src/adapters/http/ui-server.js +0 -458
- package/dist/src/adapters/runner/cli-command.js +0 -73
- package/dist/src/adapters/runner/prompt-templates.js +0 -76
- package/dist/src/adapters/runner/runner-cli-adapter.js +0 -112
- package/dist/src/adapters/runner/runner-registry.js +0 -139
- package/dist/src/adapters/runner/runtime-events.js +0 -32
- package/dist/src/adapters/runner/stage-prompt.js +0 -268
- package/dist/src/adapters/runner/transcripts.js +0 -25
- package/dist/src/cli/audit-command.js +0 -36
- package/dist/src/cli/correlate-command.js +0 -62
- package/dist/src/cli/doctor-command.js +0 -48
- package/dist/src/cli/init-command.js +0 -18
- package/dist/src/cli/sandbox-command.js +0 -258
- package/dist/src/cli/sandbox-entrypoint-command.js +0 -88
- package/dist/src/cli/sandbox-exec-logging.js +0 -7
- package/dist/src/cli/sandbox-resume.js +0 -79
- package/dist/src/cli/sandbox-setup-command.js +0 -31
- package/dist/src/cli/scaffold-assets.js +0 -100
- package/dist/src/cli/self-update-command.js +0 -198
- package/dist/src/cli/startup-preflight.js +0 -134
- package/dist/src/cli/stop-command.js +0 -46
- package/dist/src/cli/ui-command.js +0 -27
- package/dist/src/config/defaults.js +0 -10
- package/dist/src/config/discover-config-files.js +0 -11
- package/dist/src/config/load-config.js +0 -69
- package/dist/src/config/split-config.js +0 -14
- package/dist/src/core/active-run-recovery.js +0 -44
- package/dist/src/core/approval-intents.js +0 -16
- package/dist/src/core/audit-events.js +0 -82
- package/dist/src/core/control-plane.js +0 -192
- package/dist/src/core/event-builders.js +0 -153
- package/dist/src/core/event-resolver.js +0 -249
- package/dist/src/core/lifecycle-service.js +0 -8
- package/dist/src/core/live-execution.js +0 -81
- package/dist/src/core/outbox.js +0 -198
- package/dist/src/core/policy-engine.js +0 -389
- package/dist/src/core/projection-updater.js +0 -693
- package/dist/src/core/quota-backoff.js +0 -69
- package/dist/src/core/run-lease.js +0 -38
- package/dist/src/core/scheduled-workflow-source.js +0 -199
- package/dist/src/core/sink-router.js +0 -107
- package/dist/src/core/stale-run-reconciler.js +0 -352
- package/dist/src/core/tick-runner.js +0 -2442
- package/dist/src/core/workspace-cleanup.js +0 -117
- package/dist/src/domain/branch-naming.js +0 -14
- package/dist/src/domain/custom-commands.js +0 -58
- package/dist/src/domain/event-types.js +0 -158
- package/dist/src/domain/manual-labels.js +0 -1
- package/dist/src/domain/resource-uri.js +0 -38
- package/dist/src/domain/runner-routing.js +0 -127
- package/dist/src/domain/runtime-events.js +0 -36
- package/dist/src/domain/schema.js +0 -1233
- package/dist/src/domain/sources.js +0 -16
- package/dist/src/domain/stages.js +0 -36
- package/dist/src/domain/work-item-labels.js +0 -48
- package/dist/src/domain/work-item-lifecycle.js +0 -10
- package/dist/src/domain/work-item-status.js +0 -33
- package/dist/src/domain/workflows.js +0 -159
- package/dist/src/lib/deep-merge.js +0 -14
- package/dist/src/lib/detached-process-logging.js +0 -46
- package/dist/src/lib/event-log.js +0 -21
- package/dist/src/lib/format.js +0 -41
- package/dist/src/lib/json-file.js +0 -23
- package/dist/src/lib/lock.js +0 -181
- package/dist/src/lib/log-rotation.js +0 -42
- package/dist/src/lib/paths.js +0 -52
- package/dist/src/lib/process-identity.js +0 -54
- package/dist/src/lib/state-health.js +0 -30
- package/dist/src/lib/work-id.js +0 -19
- package/dist/src/lib/yaml-file.js +0 -20
- /package/dist/src/{core → activities/pr}/contracts.js +0 -0
- /package/dist/src/{domain/types.js → control-plane/contracts/views.js} +0 -0
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
function applyTimeOfDay(input) {
|
|
2
|
-
let hours = input.hours;
|
|
3
|
-
if (hours === 12) {
|
|
4
|
-
hours = 0;
|
|
5
|
-
}
|
|
6
|
-
if (input.meridiem === 'pm') {
|
|
7
|
-
hours += 12;
|
|
8
|
-
}
|
|
9
|
-
const reset = new Date(input.now);
|
|
10
|
-
if (input.useUtc) {
|
|
11
|
-
reset.setUTCHours(hours, input.minutes, 0, 0);
|
|
12
|
-
if (reset.getTime() <= input.now.getTime()) {
|
|
13
|
-
reset.setUTCDate(reset.getUTCDate() + 1);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
reset.setHours(hours, input.minutes, 0, 0);
|
|
18
|
-
if (reset.getTime() <= input.now.getTime()) {
|
|
19
|
-
reset.setDate(reset.getDate() + 1);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return reset.toISOString();
|
|
23
|
-
}
|
|
24
|
-
// CLIs report quota resets in prose, e.g. Claude's "resets 1:10am (UTC)" or
|
|
25
|
-
// Codex's "try again at 2:29 PM" (no zone marker at all). Only trust a time as
|
|
26
|
-
// UTC when the message says so explicitly; an unlabeled time is the CLI
|
|
27
|
-
// provider's local clock, not ours, but treating it as this machine's local
|
|
28
|
-
// time is the closest honest guess without a zone — better than silently
|
|
29
|
-
// assuming UTC and pausing for the wrong duration.
|
|
30
|
-
const utcResetPattern = /(?:resets?|try again at)\s+(\d{1,2})(?::(\d{2}))?\s*(am|pm)\s*(?:\(utc\)|utc)/i;
|
|
31
|
-
const localResetPattern = /(?:resets?|try again at)\s+(\d{1,2})(?::(\d{2}))?\s*(am|pm)\b/i;
|
|
32
|
-
// A cap on the exponential-backoff guess used when no reset time is reported
|
|
33
|
-
// (see below). Kept well under a working day so a stuck-forever pause is
|
|
34
|
-
// never possible even if the guess is wrong - worst case, Wake retries hourly.
|
|
35
|
-
const maxEstimatedPauseMs = 60 * 60_000;
|
|
36
|
-
export function resolveQuotaPauseUntil(input) {
|
|
37
|
-
const utcMatch = utcResetPattern.exec(input.result);
|
|
38
|
-
if (utcMatch !== null) {
|
|
39
|
-
return {
|
|
40
|
-
pausedUntil: applyTimeOfDay({
|
|
41
|
-
hours: Number(utcMatch[1]),
|
|
42
|
-
minutes: Number(utcMatch[2] ?? 0),
|
|
43
|
-
meridiem: utcMatch[3]?.toLowerCase(),
|
|
44
|
-
now: input.now,
|
|
45
|
-
useUtc: true,
|
|
46
|
-
}),
|
|
47
|
-
source: 'reported',
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
const localMatch = localResetPattern.exec(input.result);
|
|
51
|
-
if (localMatch !== null) {
|
|
52
|
-
return {
|
|
53
|
-
pausedUntil: applyTimeOfDay({
|
|
54
|
-
hours: Number(localMatch[1]),
|
|
55
|
-
minutes: Number(localMatch[2] ?? 0),
|
|
56
|
-
meridiem: localMatch[3]?.toLowerCase(),
|
|
57
|
-
now: input.now,
|
|
58
|
-
useUtc: false,
|
|
59
|
-
}),
|
|
60
|
-
source: 'reported',
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
const boundedFailureCount = Math.max(1, Math.min(input.failureCount, 6));
|
|
64
|
-
const delayMs = Math.min(15 * 60_000 * 2 ** (boundedFailureCount - 1), maxEstimatedPauseMs);
|
|
65
|
-
return {
|
|
66
|
-
pausedUntil: new Date(input.now.getTime() + delayMs).toISOString(),
|
|
67
|
-
source: 'estimated',
|
|
68
|
-
};
|
|
69
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
export const runLeaseDurationMs = 60_000;
|
|
3
|
-
export const runLeaseRenewalIntervalMs = 20_000;
|
|
4
|
-
export function createRunLease(input) {
|
|
5
|
-
const acquiredAt = input.clock.now();
|
|
6
|
-
const expiresAt = new Date(acquiredAt.getTime() + runLeaseDurationMs);
|
|
7
|
-
return {
|
|
8
|
-
leaseId: `lease-${randomUUID()}`,
|
|
9
|
-
ownerInstanceId: input.ownerInstanceId,
|
|
10
|
-
acquiredAt: acquiredAt.toISOString(),
|
|
11
|
-
lastRenewedAt: acquiredAt.toISOString(),
|
|
12
|
-
expiresAt: expiresAt.toISOString(),
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export function isRunLeaseExpired(record, now) {
|
|
16
|
-
if (record.lease === undefined) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
return Date.parse(record.lease.expiresAt) <= now.getTime();
|
|
20
|
-
}
|
|
21
|
-
export async function renewRunLease(input) {
|
|
22
|
-
const now = input.clock.now();
|
|
23
|
-
const renewed = await input.stateStore.updateRunRecordIf(input.runId, {
|
|
24
|
-
expect: (record) => record.status === 'running' &&
|
|
25
|
-
record.lifecycle !== 'TERMINAL' &&
|
|
26
|
-
record.lease?.leaseId === input.leaseId &&
|
|
27
|
-
record.lease.ownerInstanceId === input.ownerInstanceId,
|
|
28
|
-
update: (record) => ({
|
|
29
|
-
...record,
|
|
30
|
-
lease: {
|
|
31
|
-
...record.lease,
|
|
32
|
-
lastRenewedAt: now.toISOString(),
|
|
33
|
-
expiresAt: new Date(now.getTime() + runLeaseDurationMs).toISOString(),
|
|
34
|
-
},
|
|
35
|
-
}),
|
|
36
|
-
});
|
|
37
|
-
return renewed !== null;
|
|
38
|
-
}
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { createUnkeyedEventEnvelope } from '../lib/event-log.js';
|
|
2
|
-
import { buildResourceUri } from '../domain/resource-uri.js';
|
|
3
|
-
import { readJsonFile, writeJsonFile } from '../lib/json-file.js';
|
|
4
|
-
import { createWakePaths } from '../lib/paths.js';
|
|
5
|
-
import { isMissingPathError } from '../lib/state-health.js';
|
|
6
|
-
const syntheticRepo = 'wake/internal';
|
|
7
|
-
const syntheticIssueNumber = 1;
|
|
8
|
-
function parseCronField(raw, min, max) {
|
|
9
|
-
const allowed = new Set();
|
|
10
|
-
for (const part of raw.split(',')) {
|
|
11
|
-
const trimmed = part.trim();
|
|
12
|
-
if (trimmed.length === 0) {
|
|
13
|
-
throw new Error(`invalid cron field "${raw}"`);
|
|
14
|
-
}
|
|
15
|
-
const stepMatch = /^(.*)\/(\d+)$/.exec(trimmed);
|
|
16
|
-
const base = stepMatch?.[1] ?? trimmed;
|
|
17
|
-
const step = stepMatch === null ? 1 : Number(stepMatch[2]);
|
|
18
|
-
if (!Number.isInteger(step) || step <= 0) {
|
|
19
|
-
throw new Error(`invalid cron step "${trimmed}"`);
|
|
20
|
-
}
|
|
21
|
-
const range = base === '*'
|
|
22
|
-
? [min, max]
|
|
23
|
-
: (() => {
|
|
24
|
-
const match = /^(\d+)(?:-(\d+))?$/.exec(base);
|
|
25
|
-
if (match === null) {
|
|
26
|
-
throw new Error(`invalid cron segment "${trimmed}"`);
|
|
27
|
-
}
|
|
28
|
-
const start = Number(match[1]);
|
|
29
|
-
const end = match[2] === undefined ? start : Number(match[2]);
|
|
30
|
-
if (start < min || end > max || start > end) {
|
|
31
|
-
throw new Error(`cron segment "${trimmed}" is outside ${min}-${max}`);
|
|
32
|
-
}
|
|
33
|
-
return [start, end];
|
|
34
|
-
})();
|
|
35
|
-
for (let value = range[0]; value <= range[1]; value += step) {
|
|
36
|
-
allowed.add(value);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return { matches: (value) => allowed.has(value) };
|
|
40
|
-
}
|
|
41
|
-
function parseCron(cron) {
|
|
42
|
-
const fields = cron.trim().split(/\s+/);
|
|
43
|
-
if (fields.length !== 5) {
|
|
44
|
-
throw new Error(`cron schedule must have five fields: ${cron}`);
|
|
45
|
-
}
|
|
46
|
-
return [
|
|
47
|
-
parseCronField(fields[0], 0, 59),
|
|
48
|
-
parseCronField(fields[1], 0, 23),
|
|
49
|
-
parseCronField(fields[2], 1, 31),
|
|
50
|
-
parseCronField(fields[3], 1, 12),
|
|
51
|
-
parseCronField(fields[4], 0, 6),
|
|
52
|
-
];
|
|
53
|
-
}
|
|
54
|
-
function matchesCron(date, cron) {
|
|
55
|
-
return (cron[0].matches(date.getUTCMinutes()) &&
|
|
56
|
-
cron[1].matches(date.getUTCHours()) &&
|
|
57
|
-
cron[2].matches(date.getUTCDate()) &&
|
|
58
|
-
cron[3].matches(date.getUTCMonth() + 1) &&
|
|
59
|
-
cron[4].matches(date.getUTCDay()));
|
|
60
|
-
}
|
|
61
|
-
function floorToMinute(date) {
|
|
62
|
-
const copy = new Date(date);
|
|
63
|
-
copy.setUTCSeconds(0, 0);
|
|
64
|
-
return copy;
|
|
65
|
-
}
|
|
66
|
-
export function previousMatchingSlot(input) {
|
|
67
|
-
const parsed = parseCron(input.cron);
|
|
68
|
-
const slot = floorToMinute(input.now);
|
|
69
|
-
const afterMs = input.after === undefined ? undefined : Date.parse(input.after);
|
|
70
|
-
const lookbackMinutes = 366 * 24 * 60;
|
|
71
|
-
for (let checked = 0; checked < lookbackMinutes; checked += 1) {
|
|
72
|
-
const slotIso = slot.toISOString();
|
|
73
|
-
if (afterMs !== undefined && slot.getTime() <= afterMs) {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
if (matchesCron(slot, parsed)) {
|
|
77
|
-
return slotIso;
|
|
78
|
-
}
|
|
79
|
-
slot.setUTCMinutes(slot.getUTCMinutes() - 1);
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
function triggerStateFile(wakeRoot, workflow) {
|
|
84
|
-
return `${createWakePaths(wakeRoot).dataRoot}/triggers/${workflow}.json`;
|
|
85
|
-
}
|
|
86
|
-
async function readTriggerState(wakeRoot, workflow) {
|
|
87
|
-
try {
|
|
88
|
-
const raw = await readJsonFile(triggerStateFile(wakeRoot, workflow));
|
|
89
|
-
if (raw === null || typeof raw !== 'object') {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
const record = raw;
|
|
93
|
-
return record.schemaVersion === 1 &&
|
|
94
|
-
record.workflow === workflow &&
|
|
95
|
-
typeof record.lastFiredSlot === 'string' &&
|
|
96
|
-
typeof record.updatedAt === 'string'
|
|
97
|
-
? {
|
|
98
|
-
schemaVersion: 1,
|
|
99
|
-
workflow,
|
|
100
|
-
lastFiredSlot: record.lastFiredSlot,
|
|
101
|
-
updatedAt: record.updatedAt,
|
|
102
|
-
}
|
|
103
|
-
: null;
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
if (isMissingPathError(error)) {
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
throw error;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
function scheduledEventId(workflow, slot) {
|
|
113
|
-
return `scheduled-workflow-${workflow}-${slot.replace(/[^a-z0-9]+/gi, '-')}`;
|
|
114
|
-
}
|
|
115
|
-
function scheduledResourceUri(workflow, slot) {
|
|
116
|
-
return buildResourceUri('wake', 'schedule', `${workflow}@${slot}`);
|
|
117
|
-
}
|
|
118
|
-
function syntheticTicket(input) {
|
|
119
|
-
const eventId = scheduledEventId(input.workflow, input.slot);
|
|
120
|
-
const resourceUri = scheduledResourceUri(input.workflow, input.slot);
|
|
121
|
-
const url = `https://wake.local/schedules/${encodeURIComponent(input.workflow)}/${encodeURIComponent(input.slot)}`;
|
|
122
|
-
return createUnkeyedEventEnvelope({
|
|
123
|
-
eventId,
|
|
124
|
-
streamScope: 'global-intake',
|
|
125
|
-
direction: 'inbound',
|
|
126
|
-
sourceSystem: 'wake',
|
|
127
|
-
sourceEventType: 'ticket.upsert',
|
|
128
|
-
sourceRefs: {
|
|
129
|
-
repo: syntheticRepo,
|
|
130
|
-
issueNumber: syntheticIssueNumber,
|
|
131
|
-
sourceUrl: url,
|
|
132
|
-
resourceUri,
|
|
133
|
-
},
|
|
134
|
-
occurredAt: input.slot,
|
|
135
|
-
ingestedAt: input.now,
|
|
136
|
-
trigger: 'immediate',
|
|
137
|
-
payload: {
|
|
138
|
-
ticket: {
|
|
139
|
-
repo: syntheticRepo,
|
|
140
|
-
number: syntheticIssueNumber,
|
|
141
|
-
title: `Scheduled workflow: ${input.workflow}`,
|
|
142
|
-
body: `Wake fired scheduled workflow "${input.workflow}" for cron slot ${input.slot}.`,
|
|
143
|
-
labels: ['wake:scheduled-workflow', `wake:workflow.${input.workflow}`],
|
|
144
|
-
assignees: [],
|
|
145
|
-
isPullRequest: false,
|
|
146
|
-
state: 'open',
|
|
147
|
-
url,
|
|
148
|
-
createdAt: input.slot,
|
|
149
|
-
updatedAt: input.slot,
|
|
150
|
-
},
|
|
151
|
-
workflow: input.workflow,
|
|
152
|
-
trigger: {
|
|
153
|
-
kind: 'schedule',
|
|
154
|
-
slot: input.slot,
|
|
155
|
-
idempotencyKey: eventId,
|
|
156
|
-
},
|
|
157
|
-
providerEventType: 'wake.schedule.fired',
|
|
158
|
-
},
|
|
159
|
-
derivedHints: {
|
|
160
|
-
workflow: input.workflow,
|
|
161
|
-
},
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
export function createScheduledWorkflowSource(deps) {
|
|
165
|
-
return {
|
|
166
|
-
async pollEvents() {
|
|
167
|
-
const events = [];
|
|
168
|
-
const now = deps.now();
|
|
169
|
-
const nowIso = now.toISOString();
|
|
170
|
-
for (const [workflow, definition] of Object.entries(deps.config.workflows)) {
|
|
171
|
-
const cron = definition.trigger?.schedule?.cron;
|
|
172
|
-
if (cron === undefined) {
|
|
173
|
-
continue;
|
|
174
|
-
}
|
|
175
|
-
const state = await readTriggerState(deps.config.paths.wakeRoot, workflow);
|
|
176
|
-
const slot = previousMatchingSlot({
|
|
177
|
-
cron,
|
|
178
|
-
now,
|
|
179
|
-
...(state?.lastFiredSlot === undefined ? {} : { after: state.lastFiredSlot }),
|
|
180
|
-
});
|
|
181
|
-
if (slot === null) {
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
const eventId = scheduledEventId(workflow, slot);
|
|
185
|
-
if ((await deps.stateStore.readEventEnvelope(eventId)) !== null) {
|
|
186
|
-
await writeJsonFile(triggerStateFile(deps.config.paths.wakeRoot, workflow), {
|
|
187
|
-
schemaVersion: 1,
|
|
188
|
-
workflow,
|
|
189
|
-
lastFiredSlot: slot,
|
|
190
|
-
updatedAt: nowIso,
|
|
191
|
-
});
|
|
192
|
-
continue;
|
|
193
|
-
}
|
|
194
|
-
events.push(syntheticTicket({ workflow, slot, now: nowIso }));
|
|
195
|
-
}
|
|
196
|
-
return events;
|
|
197
|
-
},
|
|
198
|
-
};
|
|
199
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { LABELS_REQUESTED_EVENT, PUBLISH_INTENT_REQUESTED_EVENT } from '../domain/event-types.js';
|
|
2
|
-
export function createWorkSourceFanIn(sources) {
|
|
3
|
-
return {
|
|
4
|
-
async pollEvents(input) {
|
|
5
|
-
const batches = await Promise.all(sources.map((source) => source.pollEvents(input)));
|
|
6
|
-
return batches.flat();
|
|
7
|
-
},
|
|
8
|
-
async refreshForDispatch(input) {
|
|
9
|
-
for (const source of sources) {
|
|
10
|
-
if (source.refreshForDispatch === undefined) {
|
|
11
|
-
continue;
|
|
12
|
-
}
|
|
13
|
-
const result = await source.refreshForDispatch(input);
|
|
14
|
-
if (result !== null) {
|
|
15
|
-
return result;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return null;
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function intentKind(event) {
|
|
23
|
-
if (event.sourceEventType !== PUBLISH_INTENT_REQUESTED_EVENT) {
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
return typeof event.payload.kind === 'string' ? event.payload.kind : null;
|
|
27
|
-
}
|
|
28
|
-
function isTerminalStageIntent(event) {
|
|
29
|
-
const stage = event.derivedHints?.stage;
|
|
30
|
-
return stage === 'done' || event.payload.sentinel === 'BLOCKED';
|
|
31
|
-
}
|
|
32
|
-
function subscriptionMatches(event, subscription) {
|
|
33
|
-
if (subscription === intentKind(event)) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
return subscription === 'stage.terminal' && isTerminalStageIntent(event);
|
|
37
|
-
}
|
|
38
|
-
function sinkNameForResourceUri(resourceUri, fallback) {
|
|
39
|
-
const [provider, kind] = resourceUri.split(':');
|
|
40
|
-
if (provider === undefined || kind === undefined) {
|
|
41
|
-
return fallback;
|
|
42
|
-
}
|
|
43
|
-
return kind === 'pr' || kind === 'pr-review-thread' ? `${provider}-pr` : fallback;
|
|
44
|
-
}
|
|
45
|
-
function withSinkRef(event, sink) {
|
|
46
|
-
return {
|
|
47
|
-
...event,
|
|
48
|
-
sourceRefs: {
|
|
49
|
-
...event.sourceRefs,
|
|
50
|
-
sink: event.sourceRefs.sink ?? sink,
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
function targetSinksForEvent(input) {
|
|
55
|
-
const targetSinks = new Set();
|
|
56
|
-
const origin = typeof input.event.payload.origin === 'string' ? input.event.payload.origin : undefined;
|
|
57
|
-
const sourceOrigin = input.event.sourceRefs.sink ?? origin;
|
|
58
|
-
if (input.event.sourceEventType === LABELS_REQUESTED_EVENT) {
|
|
59
|
-
const projectionOrigin = typeof input.event.payload.origin === 'string' ? input.event.payload.origin : undefined;
|
|
60
|
-
if (projectionOrigin !== undefined) {
|
|
61
|
-
targetSinks.add(projectionOrigin);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
const resourceUri = input.event.sourceRefs.resourceUri;
|
|
65
|
-
if (input.event.sourceEventType === PUBLISH_INTENT_REQUESTED_EVENT &&
|
|
66
|
-
sourceOrigin !== undefined) {
|
|
67
|
-
const resourceSink = resourceUri === undefined ? sourceOrigin : sinkNameForResourceUri(resourceUri, sourceOrigin);
|
|
68
|
-
targetSinks.add(input.sinksByName.has(resourceSink) ? resourceSink : sourceOrigin);
|
|
69
|
-
}
|
|
70
|
-
for (const [sinkName, sinkConfig] of Object.entries(input.config.sinks ?? {})) {
|
|
71
|
-
if (sinkConfig.subscribe.some((subscription) => subscriptionMatches(input.event, subscription))) {
|
|
72
|
-
targetSinks.add(sinkName);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return targetSinks;
|
|
76
|
-
}
|
|
77
|
-
export function createOutboundSinkRouter(input) {
|
|
78
|
-
const sinksByName = new Map(input.sinks.map((sink) => [sink.sink, sink]));
|
|
79
|
-
return {
|
|
80
|
-
async deliverIntent({ event }) {
|
|
81
|
-
const targetSinks = targetSinksForEvent({ event, sinksByName, config: input.config });
|
|
82
|
-
const deliveryEvents = [];
|
|
83
|
-
for (const sinkName of targetSinks) {
|
|
84
|
-
const sink = sinksByName.get(sinkName);
|
|
85
|
-
if (sink === undefined) {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
const sinkDeliveryEvents = await sink.deliverIntent({ event });
|
|
89
|
-
deliveryEvents.push(...sinkDeliveryEvents.map((deliveryEvent) => withSinkRef(deliveryEvent, sinkName)));
|
|
90
|
-
}
|
|
91
|
-
return deliveryEvents;
|
|
92
|
-
},
|
|
93
|
-
async reconcileIntent({ event }) {
|
|
94
|
-
const targetSinks = targetSinksForEvent({ event, sinksByName, config: input.config });
|
|
95
|
-
const deliveryEvents = [];
|
|
96
|
-
for (const sinkName of targetSinks) {
|
|
97
|
-
const sink = sinksByName.get(sinkName);
|
|
98
|
-
if (sink?.reconcileIntent === undefined) {
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
const sinkDeliveryEvents = await sink.reconcileIntent({ event });
|
|
102
|
-
deliveryEvents.push(...sinkDeliveryEvents.map((deliveryEvent) => withSinkRef(deliveryEvent, sinkName)));
|
|
103
|
-
}
|
|
104
|
-
return deliveryEvents;
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
}
|