@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.
- 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 -2365
- 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
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { correlationId, EventActorKind, EventSourceKind } from '../../kernel/index.js';
|
|
2
|
+
import { createRunExecutionEventDraft } from '../contracts/event-factory.js';
|
|
3
|
+
import { ExecutionEventType } from '../contracts/events.js';
|
|
4
|
+
import { runId } from '../contracts/identifiers.js';
|
|
5
|
+
import { runStream } from '../contracts/streams.js';
|
|
6
|
+
import { ExecutionFailureCode, ExternalExecutionState, RunStatus, } from '../contracts/vocabulary.js';
|
|
7
|
+
import { RunRepository } from './run-repository.js';
|
|
8
|
+
export class RecoveryService {
|
|
9
|
+
clock;
|
|
10
|
+
inspector;
|
|
11
|
+
activities;
|
|
12
|
+
config;
|
|
13
|
+
blocker;
|
|
14
|
+
repository;
|
|
15
|
+
constructor(journal, clock, inspector, activities, config = {}, blocker) {
|
|
16
|
+
this.clock = clock;
|
|
17
|
+
this.inspector = inspector;
|
|
18
|
+
this.activities = activities;
|
|
19
|
+
this.config = config;
|
|
20
|
+
this.blocker = blocker;
|
|
21
|
+
this.repository = new RunRepository(journal);
|
|
22
|
+
}
|
|
23
|
+
async recover(id, owner) {
|
|
24
|
+
const currentRunId = runId(id);
|
|
25
|
+
const loaded = await this.repository.load(currentRunId);
|
|
26
|
+
const run = loaded.view;
|
|
27
|
+
if (run === null || run.status !== RunStatus.Started)
|
|
28
|
+
return requireRun(run);
|
|
29
|
+
if (run.lease !== undefined && new Date(run.lease.expiresAt) > this.clock.now())
|
|
30
|
+
throw new Error(`Run ${id} does not have an expired lease`);
|
|
31
|
+
if (run.externalExecution === undefined)
|
|
32
|
+
return this.appendFailure(currentRunId, run, 'External execution was never reported');
|
|
33
|
+
const inspection = await this.inspector.inspect(run.externalExecution);
|
|
34
|
+
if (inspection.kind === ExternalExecutionState.Running)
|
|
35
|
+
return this.appendLease(currentRunId, run, owner);
|
|
36
|
+
if (inspection.kind === ExternalExecutionState.Completed)
|
|
37
|
+
return this.appendRecovered(currentRunId, run, inspection.result);
|
|
38
|
+
if (inspection.kind === ExternalExecutionState.Absent)
|
|
39
|
+
return this.appendFailure(currentRunId, run, 'External execution is absent');
|
|
40
|
+
return this.appendAmbiguity(currentRunId, run, inspection.reason);
|
|
41
|
+
}
|
|
42
|
+
async resolve(id, resolution, context) {
|
|
43
|
+
if (context.actor.kind !== EventActorKind.Operator)
|
|
44
|
+
throw new Error('Ambiguous Run resolution requires an operator actor');
|
|
45
|
+
const currentRunId = runId(id);
|
|
46
|
+
const loaded = await this.repository.load(currentRunId);
|
|
47
|
+
if (loaded.view === null)
|
|
48
|
+
throw new Error(`Run ${id} does not exist`);
|
|
49
|
+
if (!loaded.view.escalated || loaded.view.status !== RunStatus.Ambiguous)
|
|
50
|
+
throw new Error(`Run ${id} is not escalated`);
|
|
51
|
+
const draft = resolution.kind === RunStatus.Succeeded
|
|
52
|
+
? createRunExecutionEventDraft({
|
|
53
|
+
...resolutionMetadata(currentRunId, loaded.view, context),
|
|
54
|
+
eventType: ExecutionEventType.RunSucceeded,
|
|
55
|
+
payload: { outcome: resolution.outcome, finishedAt: context.occurredAt },
|
|
56
|
+
})
|
|
57
|
+
: createRunExecutionEventDraft({
|
|
58
|
+
...resolutionMetadata(currentRunId, loaded.view, context),
|
|
59
|
+
eventType: ExecutionEventType.RunFailed,
|
|
60
|
+
payload: { failure: resolution.failure, finishedAt: context.occurredAt },
|
|
61
|
+
});
|
|
62
|
+
try {
|
|
63
|
+
await this.repository.append(currentRunId, loaded.sequence, [draft]);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// A concurrent resolution wins deterministically; return the resulting view.
|
|
67
|
+
}
|
|
68
|
+
return (await this.repository.load(currentRunId)).view;
|
|
69
|
+
}
|
|
70
|
+
async recoverActive(owner, isLocallyActive = () => false) {
|
|
71
|
+
const recovered = [];
|
|
72
|
+
for (const run of await this.repository.list()) {
|
|
73
|
+
if (run.status !== RunStatus.Started)
|
|
74
|
+
continue;
|
|
75
|
+
if (isLocallyActive(run.runId))
|
|
76
|
+
continue;
|
|
77
|
+
if (run.lease !== undefined && new Date(run.lease.expiresAt) > this.clock.now())
|
|
78
|
+
continue;
|
|
79
|
+
recovered.push(await this.recover(run.runId, owner));
|
|
80
|
+
}
|
|
81
|
+
return recovered;
|
|
82
|
+
}
|
|
83
|
+
async appendLease(id, run, owner) {
|
|
84
|
+
const now = this.clock.now().toISOString();
|
|
85
|
+
return this.append(id, leaseRenewedDraft(id, run, {
|
|
86
|
+
owner,
|
|
87
|
+
acquiredAt: now,
|
|
88
|
+
expiresAt: new Date(this.clock.now().getTime() + (this.config.leaseDurationMs ?? 60_000)).toISOString(),
|
|
89
|
+
}, now));
|
|
90
|
+
}
|
|
91
|
+
async appendRecovered(id, run, result) {
|
|
92
|
+
const finishedAt = this.clock.now().toISOString();
|
|
93
|
+
const outcome = recoveredOutcome(run, result, this.activities);
|
|
94
|
+
return this.append(id, recoveredDraft(id, run, { result, outcome, finishedAt }, finishedAt));
|
|
95
|
+
}
|
|
96
|
+
async appendFailure(id, run, message) {
|
|
97
|
+
const finishedAt = this.clock.now().toISOString();
|
|
98
|
+
return this.append(id, failedDraft(id, run, { failure: { kind: ExecutionFailureCode.Unexpected, message }, finishedAt }, finishedAt));
|
|
99
|
+
}
|
|
100
|
+
async appendAmbiguity(id, run, reason) {
|
|
101
|
+
const loaded = await this.repository.load(id);
|
|
102
|
+
if (loaded.view === null)
|
|
103
|
+
throw new Error(`Run ${id} does not exist`);
|
|
104
|
+
if (loaded.view.status !== RunStatus.Started)
|
|
105
|
+
return loaded.view;
|
|
106
|
+
const occurredAt = this.clock.now().toISOString();
|
|
107
|
+
const attempt = loaded.view.ambiguityAttempts + 1;
|
|
108
|
+
const drafts = [
|
|
109
|
+
ambiguityObservedDraft(id, loaded.view, { reason, attempt }, occurredAt),
|
|
110
|
+
];
|
|
111
|
+
if (attempt >= (this.config.maxAmbiguityReconciliationAttempts ?? 3))
|
|
112
|
+
drafts.push(ambiguousDraft(id, loaded.view, { reason, finishedAt: occurredAt }, occurredAt));
|
|
113
|
+
await this.repository.append(id, loaded.sequence, drafts);
|
|
114
|
+
const updated = (await this.repository.load(id)).view;
|
|
115
|
+
if (updated.escalated)
|
|
116
|
+
await this.blocker?.block(updated.workflowInstanceId, `run-ambiguous-after-${attempt}-attempts`, {
|
|
117
|
+
commandId: `${id}:recovery-escalation:${attempt}`,
|
|
118
|
+
correlationId: correlationId(updated.orchestrationGroupId),
|
|
119
|
+
occurredAt,
|
|
120
|
+
actor: { kind: EventActorKind.System, id: 'execution-recovery' },
|
|
121
|
+
});
|
|
122
|
+
return updated;
|
|
123
|
+
}
|
|
124
|
+
async append(id, draft) {
|
|
125
|
+
const loaded = await this.repository.load(id);
|
|
126
|
+
if (loaded.view === null)
|
|
127
|
+
throw new Error(`Run ${id} does not exist`);
|
|
128
|
+
if (loaded.view.status !== RunStatus.Started)
|
|
129
|
+
return loaded.view;
|
|
130
|
+
await this.repository.append(id, loaded.sequence, [draft]);
|
|
131
|
+
return (await this.repository.load(id)).view;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export function createRecoveryCoordinator(service) {
|
|
135
|
+
return { recoverActive: (owner) => service.recoverActive(owner) };
|
|
136
|
+
}
|
|
137
|
+
function leaseRenewedDraft(id, run, payload, occurredAt) {
|
|
138
|
+
return createRunExecutionEventDraft({
|
|
139
|
+
...eventMetadata(id, run, occurredAt),
|
|
140
|
+
eventType: ExecutionEventType.RunLeaseRenewed,
|
|
141
|
+
payload,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function recoveredDraft(id, run, payload, occurredAt) {
|
|
145
|
+
return createRunExecutionEventDraft({
|
|
146
|
+
...eventMetadata(id, run, occurredAt),
|
|
147
|
+
eventType: ExecutionEventType.RunRecovered,
|
|
148
|
+
payload,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function failedDraft(id, run, payload, occurredAt) {
|
|
152
|
+
return createRunExecutionEventDraft({
|
|
153
|
+
...eventMetadata(id, run, occurredAt),
|
|
154
|
+
eventType: ExecutionEventType.RunFailed,
|
|
155
|
+
payload,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function ambiguityObservedDraft(id, run, payload, occurredAt) {
|
|
159
|
+
return createRunExecutionEventDraft({
|
|
160
|
+
...eventMetadata(id, run, occurredAt),
|
|
161
|
+
eventId: `${id}:recovery-ambiguity:${payload.attempt}:${occurredAt}`,
|
|
162
|
+
eventType: ExecutionEventType.RunAmbiguityObserved,
|
|
163
|
+
payload,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
function ambiguousDraft(id, run, payload, occurredAt) {
|
|
167
|
+
return createRunExecutionEventDraft({
|
|
168
|
+
...eventMetadata(id, run, occurredAt),
|
|
169
|
+
eventType: ExecutionEventType.RunAmbiguous,
|
|
170
|
+
payload,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
function resolutionMetadata(id, run, context) {
|
|
174
|
+
return {
|
|
175
|
+
eventId: `${context.commandId}:run-resolution`,
|
|
176
|
+
occurredAt: context.occurredAt,
|
|
177
|
+
correlationId: context.correlationId,
|
|
178
|
+
causationId: context.commandId,
|
|
179
|
+
actor: context.actor,
|
|
180
|
+
source: { kind: EventSourceKind.Internal, id: 'execution-recovery' },
|
|
181
|
+
stream: runStream(id),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function eventMetadata(id, run, occurredAt) {
|
|
185
|
+
return {
|
|
186
|
+
eventId: `${id}:recovery:${occurredAt}`,
|
|
187
|
+
occurredAt,
|
|
188
|
+
correlationId: run.orchestrationGroupId,
|
|
189
|
+
causationId: run.activationId,
|
|
190
|
+
actor: { kind: EventActorKind.System, id: 'execution-recovery' },
|
|
191
|
+
source: { kind: EventSourceKind.Internal, id: 'execution-recovery' },
|
|
192
|
+
stream: runStream(id),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function recoveredOutcome(run, result, activities) {
|
|
196
|
+
if (result.transport !== RunStatus.Succeeded)
|
|
197
|
+
throw new Error(`Recovered result is not successful: ${result.transport}`);
|
|
198
|
+
return activities.validateOutcome(run.activity, parseRecoveredOutput(result.output));
|
|
199
|
+
}
|
|
200
|
+
function parseRecoveredOutput(output) {
|
|
201
|
+
try {
|
|
202
|
+
return JSON.parse(output);
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
return { kind: output.trim() };
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function requireRun(run) {
|
|
209
|
+
if (run === null)
|
|
210
|
+
throw new Error('Run does not exist');
|
|
211
|
+
return run;
|
|
212
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { EventActorKind, EventSourceKind, createEventDraft, } from '../../kernel/index.js';
|
|
2
|
+
import { ExecutionEventType } from '../contracts/events.js';
|
|
3
|
+
import { runStream } from '../contracts/streams.js';
|
|
4
|
+
import { RunStatus } from '../contracts/vocabulary.js';
|
|
5
|
+
import { failureFrom } from '../domain/run-result.js';
|
|
6
|
+
import { claimRun } from './run-liveness-service.js';
|
|
7
|
+
export async function startRun(input) {
|
|
8
|
+
const { dependencies, runId: currentRunId, activation, context, attempt, startedAt, runner, lease, } = input;
|
|
9
|
+
await dependencies.repository.append(currentRunId, 0, [
|
|
10
|
+
createRunEvent({
|
|
11
|
+
runId: currentRunId,
|
|
12
|
+
eventId: `${currentRunId}:started`,
|
|
13
|
+
eventType: ExecutionEventType.RunStarted,
|
|
14
|
+
occurredAt: startedAt,
|
|
15
|
+
correlationId: context.orchestrationGroupId,
|
|
16
|
+
causationId: activation.activationId,
|
|
17
|
+
payload: {
|
|
18
|
+
activationId: activation.activationId,
|
|
19
|
+
activity: activation.activity,
|
|
20
|
+
...(activation.stage === undefined ? {} : { stage: activation.stage }),
|
|
21
|
+
workflowInstanceId: context.workflowInstanceId,
|
|
22
|
+
orchestrationGroupId: context.orchestrationGroupId,
|
|
23
|
+
attempt,
|
|
24
|
+
startedAt,
|
|
25
|
+
...(runner.name === undefined
|
|
26
|
+
? {}
|
|
27
|
+
: {
|
|
28
|
+
runner: {
|
|
29
|
+
name: runner.name,
|
|
30
|
+
...(runner.model === undefined ? {} : { model: runner.model }),
|
|
31
|
+
...(runner.effort === undefined ? {} : { effort: runner.effort }),
|
|
32
|
+
...(runner.pool === undefined ? {} : { pool: runner.pool }),
|
|
33
|
+
...(runner.cli === undefined ? {} : { cli: runner.cli }),
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
...(lease === undefined
|
|
37
|
+
? {}
|
|
38
|
+
: {
|
|
39
|
+
workspace: {
|
|
40
|
+
mode: lease.mode,
|
|
41
|
+
path: lease.path,
|
|
42
|
+
...(lease.branch === undefined ? {} : { branch: lease.branch }),
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
]);
|
|
48
|
+
await claimRun(dependencies.repository, dependencies.clock, dependencies.config, currentRunId, context.owner ?? 'execution');
|
|
49
|
+
}
|
|
50
|
+
export async function recordWorkspaceCleanupFailure(input) {
|
|
51
|
+
const { dependencies, runId: currentRunId, activation, context, error } = input;
|
|
52
|
+
const loaded = await dependencies.repository.load(currentRunId);
|
|
53
|
+
await dependencies.repository.append(currentRunId, loaded.sequence, [
|
|
54
|
+
createRunEvent({
|
|
55
|
+
runId: currentRunId,
|
|
56
|
+
eventId: `${currentRunId}:workspace-cleanup-failed`,
|
|
57
|
+
eventType: ExecutionEventType.RunWorkspaceCleanupFailed,
|
|
58
|
+
occurredAt: dependencies.clock.now().toISOString(),
|
|
59
|
+
correlationId: context.orchestrationGroupId,
|
|
60
|
+
causationId: activation.activationId,
|
|
61
|
+
payload: { message: error instanceof Error ? error.message : `${error}` },
|
|
62
|
+
}),
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
65
|
+
export async function recordRunSuccess(input) {
|
|
66
|
+
const { dependencies, runId: currentRunId, activation, context, outcome } = input;
|
|
67
|
+
const finishedAt = dependencies.clock.now().toISOString();
|
|
68
|
+
const loaded = await dependencies.repository.load(currentRunId);
|
|
69
|
+
if (loaded.view?.status !== RunStatus.Started)
|
|
70
|
+
return;
|
|
71
|
+
await dependencies.repository.append(currentRunId, loaded.sequence, [
|
|
72
|
+
createRunEvent({
|
|
73
|
+
runId: currentRunId,
|
|
74
|
+
eventId: `${currentRunId}:succeeded`,
|
|
75
|
+
eventType: ExecutionEventType.RunSucceeded,
|
|
76
|
+
occurredAt: finishedAt,
|
|
77
|
+
correlationId: context.orchestrationGroupId,
|
|
78
|
+
causationId: activation.activationId,
|
|
79
|
+
payload: { outcome, finishedAt },
|
|
80
|
+
}),
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
export async function recordRunFailure(input) {
|
|
84
|
+
const { dependencies, runId: currentRunId, activation, context, error } = input;
|
|
85
|
+
const loaded = await dependencies.repository.load(currentRunId);
|
|
86
|
+
if (loaded.sequence === 0)
|
|
87
|
+
throw error;
|
|
88
|
+
if (loaded.view?.status !== RunStatus.Started)
|
|
89
|
+
return;
|
|
90
|
+
const finishedAt = dependencies.clock.now().toISOString();
|
|
91
|
+
await dependencies.repository.append(currentRunId, loaded.sequence, [
|
|
92
|
+
createRunEvent({
|
|
93
|
+
runId: currentRunId,
|
|
94
|
+
eventId: `${currentRunId}:failed`,
|
|
95
|
+
eventType: ExecutionEventType.RunFailed,
|
|
96
|
+
occurredAt: finishedAt,
|
|
97
|
+
correlationId: context.orchestrationGroupId,
|
|
98
|
+
causationId: activation.activationId,
|
|
99
|
+
payload: { failure: failureFrom(error), finishedAt },
|
|
100
|
+
}),
|
|
101
|
+
]);
|
|
102
|
+
}
|
|
103
|
+
export function createRunEvent(input) {
|
|
104
|
+
return createEventDraft({
|
|
105
|
+
eventId: input.eventId,
|
|
106
|
+
eventType: input.eventType,
|
|
107
|
+
occurredAt: input.occurredAt,
|
|
108
|
+
correlationId: input.correlationId,
|
|
109
|
+
causationId: input.causationId,
|
|
110
|
+
actor: { kind: EventActorKind.System, id: 'execution' },
|
|
111
|
+
source: { kind: EventSourceKind.Internal, id: 'execution' },
|
|
112
|
+
stream: runStream(input.runId),
|
|
113
|
+
payload: input.payload,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { createEventDraft, EventActorKind, EventSourceKind, } from '../../kernel/index.js';
|
|
2
|
+
import { ExecutionEventType } from '../contracts/events.js';
|
|
3
|
+
import { runStream } from '../contracts/streams.js';
|
|
4
|
+
import { RunStatus } from '../contracts/vocabulary.js';
|
|
5
|
+
const defaultLeaseDurationMs = 60_000;
|
|
6
|
+
export async function claimRun(repository, clock, config, currentRunId, owner) {
|
|
7
|
+
const loaded = await repository.load(currentRunId);
|
|
8
|
+
const run = requireActiveRun(loaded.view);
|
|
9
|
+
const now = clock.now();
|
|
10
|
+
if (run.lease !== undefined && new Date(run.lease.expiresAt) > now && run.lease.owner !== owner)
|
|
11
|
+
throw new Error(`Run ${currentRunId} has an unexpired lease`);
|
|
12
|
+
const lease = {
|
|
13
|
+
owner,
|
|
14
|
+
acquiredAt: now.toISOString(),
|
|
15
|
+
expiresAt: new Date(now.getTime() + (config.leaseDurationMs ?? defaultLeaseDurationMs)).toISOString(),
|
|
16
|
+
};
|
|
17
|
+
await repository.append(currentRunId, loaded.sequence, [
|
|
18
|
+
livenessEvent(currentRunId, run, ExecutionEventType.RunLeaseClaimed, lease, now.toISOString()),
|
|
19
|
+
]);
|
|
20
|
+
return (await repository.load(currentRunId)).view;
|
|
21
|
+
}
|
|
22
|
+
export async function renewLease(repository, clock, config, currentRunId, owner) {
|
|
23
|
+
const loaded = await repository.load(currentRunId);
|
|
24
|
+
const run = requireActiveRun(loaded.view);
|
|
25
|
+
if (run.lease?.owner !== owner)
|
|
26
|
+
throw new Error(`Run ${currentRunId} lease is not owned by ${owner}`);
|
|
27
|
+
const now = clock.now();
|
|
28
|
+
const renewalIntervalMs = config.leaseRenewalIntervalMs ?? 0;
|
|
29
|
+
if (now.getTime() < new Date(run.lease.acquiredAt).getTime() + renewalIntervalMs)
|
|
30
|
+
throw new Error(`Run ${currentRunId} lease renewal is not due`);
|
|
31
|
+
const lease = {
|
|
32
|
+
owner,
|
|
33
|
+
acquiredAt: now.toISOString(),
|
|
34
|
+
expiresAt: new Date(now.getTime() + (config.leaseDurationMs ?? defaultLeaseDurationMs)).toISOString(),
|
|
35
|
+
};
|
|
36
|
+
await repository.append(currentRunId, loaded.sequence, [
|
|
37
|
+
livenessEvent(currentRunId, run, ExecutionEventType.RunLeaseRenewed, lease, now.toISOString()),
|
|
38
|
+
]);
|
|
39
|
+
return (await repository.load(currentRunId)).view;
|
|
40
|
+
}
|
|
41
|
+
export async function requestCancellation(repository, clock, currentRunId, reason, active) {
|
|
42
|
+
const loaded = await repository.load(currentRunId);
|
|
43
|
+
const run = requireActiveRun(loaded.view);
|
|
44
|
+
const requestedAt = clock.now().toISOString();
|
|
45
|
+
await repository.append(currentRunId, loaded.sequence, [
|
|
46
|
+
livenessEvent(currentRunId, run, ExecutionEventType.RunCancellationRequested, { requestedAt, reason }, requestedAt),
|
|
47
|
+
]);
|
|
48
|
+
active.get(currentRunId)?.abort(reason);
|
|
49
|
+
return (await repository.load(currentRunId)).view;
|
|
50
|
+
}
|
|
51
|
+
export async function confirmCancellation(repository, clock, currentRunId) {
|
|
52
|
+
const loaded = await repository.load(currentRunId);
|
|
53
|
+
const run = requireActiveRun(loaded.view);
|
|
54
|
+
if (run.cancellation === undefined)
|
|
55
|
+
throw new Error(`Run ${currentRunId} has no cancellation request`);
|
|
56
|
+
const confirmedAt = clock.now().toISOString();
|
|
57
|
+
await repository.append(currentRunId, loaded.sequence, [
|
|
58
|
+
livenessEvent(currentRunId, run, ExecutionEventType.RunCancellationConfirmed, { confirmedAt }, confirmedAt),
|
|
59
|
+
livenessEvent(currentRunId, run, ExecutionEventType.RunCancelled, { finishedAt: confirmedAt }, confirmedAt),
|
|
60
|
+
]);
|
|
61
|
+
return (await repository.load(currentRunId)).view;
|
|
62
|
+
}
|
|
63
|
+
function requireActiveRun(run) {
|
|
64
|
+
if (run === null || run.status !== RunStatus.Started)
|
|
65
|
+
throw new Error('Run is not active');
|
|
66
|
+
return run;
|
|
67
|
+
}
|
|
68
|
+
function livenessEvent(currentRunId, run, eventType, payload, occurredAt) {
|
|
69
|
+
return createEventDraft({
|
|
70
|
+
eventId: `${currentRunId}:${eventType}:${occurredAt}`,
|
|
71
|
+
eventType,
|
|
72
|
+
occurredAt,
|
|
73
|
+
correlationId: run.orchestrationGroupId,
|
|
74
|
+
causationId: run.activationId,
|
|
75
|
+
actor: { kind: EventActorKind.System, id: 'execution' },
|
|
76
|
+
source: { kind: EventSourceKind.Internal, id: 'execution' },
|
|
77
|
+
stream: runStream(currentRunId),
|
|
78
|
+
payload,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { decodeRunExecutionEvent, } from '../contracts/events.js';
|
|
2
|
+
import { runId } from '../contracts/identifiers.js';
|
|
3
|
+
import { isRunStream, runStream } from '../contracts/streams.js';
|
|
4
|
+
import { foldRun } from '../domain/run.js';
|
|
5
|
+
export class RunRepository {
|
|
6
|
+
journal;
|
|
7
|
+
constructor(journal) {
|
|
8
|
+
this.journal = journal;
|
|
9
|
+
}
|
|
10
|
+
async load(runId) {
|
|
11
|
+
const events = await this.journal.readStream(runStream(runId));
|
|
12
|
+
return { sequence: events.length, view: foldRun(events.map(decodeRunExecutionEvent)) };
|
|
13
|
+
}
|
|
14
|
+
async append(runId, sequence, drafts) {
|
|
15
|
+
const events = await this.journal.append(runStream(runId), sequence, drafts);
|
|
16
|
+
return events.map(decodeRunExecutionEvent);
|
|
17
|
+
}
|
|
18
|
+
async list(activationId) {
|
|
19
|
+
const ids = new Set((await this.journal.readAll(0))
|
|
20
|
+
.filter((event) => isRunStream(event.stream))
|
|
21
|
+
.map((event) => runId(event.stream.id)));
|
|
22
|
+
const runs = (await Promise.all([...ids].map(async (id) => (await this.load(id)).view))).filter((run) => run !== null);
|
|
23
|
+
return activationId === undefined
|
|
24
|
+
? runs
|
|
25
|
+
: runs.filter((run) => run.activationId === activationId);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const isReservedFlag = (arg) => arg === '--output-format' || arg === '--resume';
|
|
3
|
+
const agentRunnerBase = {
|
|
4
|
+
model: z.string().trim().min(1).optional(),
|
|
5
|
+
effort: z.string().trim().min(1).optional(),
|
|
6
|
+
timeoutMs: z.number().int().positive().default(1_800_000),
|
|
7
|
+
args: z.array(z.string()).default([]),
|
|
8
|
+
};
|
|
9
|
+
const commandRunner = (kind) => z
|
|
10
|
+
.object({ kind: z.literal(kind), command: z.string().trim().min(1), ...agentRunnerBase })
|
|
11
|
+
.strict();
|
|
12
|
+
export const executionConfigSchema = z
|
|
13
|
+
.object({
|
|
14
|
+
agentRunners: z
|
|
15
|
+
.record(z.string().trim().min(1), z
|
|
16
|
+
.discriminatedUnion('kind', [
|
|
17
|
+
commandRunner('claude-cli'),
|
|
18
|
+
commandRunner('codex-cli'),
|
|
19
|
+
commandRunner('cursor-cli'),
|
|
20
|
+
commandRunner('command'),
|
|
21
|
+
z.object({ kind: z.literal('fake'), ...agentRunnerBase }).strict(),
|
|
22
|
+
])
|
|
23
|
+
.refine((value) => !value.args.some(isReservedFlag), {
|
|
24
|
+
message: 'args must not contain --output-format or --resume',
|
|
25
|
+
}))
|
|
26
|
+
.default({}),
|
|
27
|
+
runnerPools: z
|
|
28
|
+
.record(z.string().trim().min(1), z.array(z.string().trim().min(1)).min(1))
|
|
29
|
+
.default({}),
|
|
30
|
+
defaultRunnerPool: z.string().trim().min(1),
|
|
31
|
+
leaseDurationMs: z.number().int().positive().optional(),
|
|
32
|
+
leaseRenewalIntervalMs: z.number().int().positive().optional(),
|
|
33
|
+
maxAmbiguityReconciliationAttempts: z.number().int().positive().optional(),
|
|
34
|
+
})
|
|
35
|
+
.strict();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createEventDraft } from '../../kernel/index.js';
|
|
2
|
+
import { ExecutionEventType, } from './events.js';
|
|
3
|
+
// Exhaustive dispatch preserves the closed event-to-payload mapping.
|
|
4
|
+
// eslint-disable-next-line complexity
|
|
5
|
+
export function createRunExecutionEventDraft(input) {
|
|
6
|
+
switch (input.eventType) {
|
|
7
|
+
case ExecutionEventType.RunStarted:
|
|
8
|
+
return createEventDraft(input);
|
|
9
|
+
case ExecutionEventType.RunSucceeded:
|
|
10
|
+
return createEventDraft(input);
|
|
11
|
+
case ExecutionEventType.RunFailed:
|
|
12
|
+
return createEventDraft(input);
|
|
13
|
+
case ExecutionEventType.RunLeaseClaimed:
|
|
14
|
+
return createEventDraft(input);
|
|
15
|
+
case ExecutionEventType.RunLeaseRenewed:
|
|
16
|
+
return createEventDraft(input);
|
|
17
|
+
case ExecutionEventType.RunExternalExecutionReported:
|
|
18
|
+
return createEventDraft(input);
|
|
19
|
+
case ExecutionEventType.RunRunnerResultReported:
|
|
20
|
+
return createEventDraft(input);
|
|
21
|
+
case ExecutionEventType.RunWorkspaceCleanupFailed:
|
|
22
|
+
return createEventDraft(input);
|
|
23
|
+
case ExecutionEventType.RunCancellationRequested:
|
|
24
|
+
return createEventDraft(input);
|
|
25
|
+
case ExecutionEventType.RunCancellationConfirmed:
|
|
26
|
+
return createEventDraft(input);
|
|
27
|
+
case ExecutionEventType.RunCancelled:
|
|
28
|
+
return createEventDraft(input);
|
|
29
|
+
case ExecutionEventType.RunRecovered:
|
|
30
|
+
return createEventDraft(input);
|
|
31
|
+
case ExecutionEventType.RunAmbiguityObserved:
|
|
32
|
+
return createEventDraft(input);
|
|
33
|
+
case ExecutionEventType.RunAmbiguous:
|
|
34
|
+
return createEventDraft(input);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function createActivationExecutionEventDraft(input) {
|
|
38
|
+
switch (input.eventType) {
|
|
39
|
+
case ExecutionEventType.ActivationClaimed:
|
|
40
|
+
return createEventDraft(input);
|
|
41
|
+
case ExecutionEventType.ActivationReleased:
|
|
42
|
+
return createEventDraft(input);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function createExecutionEventDraft(input) {
|
|
46
|
+
switch (input.eventType) {
|
|
47
|
+
case ExecutionEventType.ActivationClaimed:
|
|
48
|
+
case ExecutionEventType.ActivationReleased:
|
|
49
|
+
return createActivationExecutionEventDraft(input);
|
|
50
|
+
default:
|
|
51
|
+
return createRunExecutionEventDraft(input);
|
|
52
|
+
}
|
|
53
|
+
}
|