@atolis-hq/wake 0.2.97 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- 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 +436 -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/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/templates/SETUP.md +0 -115
- /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,14 @@
|
|
|
1
|
+
import { runId } from '../contracts/identifiers.js';
|
|
2
|
+
import { RunStatus } from '../contracts/vocabulary.js';
|
|
3
|
+
import { confirmCancellation, requestCancellation } from './run-liveness-service.js';
|
|
4
|
+
export async function cancelActiveRuns(repository, clock, workflowInstanceIds, reason, active) {
|
|
5
|
+
const workflowIds = new Set(workflowInstanceIds);
|
|
6
|
+
const cancelled = [];
|
|
7
|
+
for (const run of await repository.list()) {
|
|
8
|
+
if (run.status !== RunStatus.Started || !workflowIds.has(run.workflowInstanceId))
|
|
9
|
+
continue;
|
|
10
|
+
await requestCancellation(repository, clock, runId(run.runId), reason, active);
|
|
11
|
+
cancelled.push(await confirmCancellation(repository, clock, runId(run.runId)));
|
|
12
|
+
}
|
|
13
|
+
return cancelled;
|
|
14
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ExecutionEventType } from '../contracts/events.js';
|
|
2
|
+
import { parseAgentRunnerResponse } from '../infrastructure/agent-runner-adapter.js';
|
|
3
|
+
import { createRunEvent } from './run-lifecycle.js';
|
|
4
|
+
export async function executeActivity(runtime, currentRunId, request) {
|
|
5
|
+
const { activation, context, occurredAt, runner } = request;
|
|
6
|
+
const controller = new AbortController();
|
|
7
|
+
runtime.active.set(currentRunId, controller);
|
|
8
|
+
const executionContext = {
|
|
9
|
+
signal: controller.signal,
|
|
10
|
+
occurredAt,
|
|
11
|
+
runId: currentRunId,
|
|
12
|
+
...(request.resumeSessionId === undefined ? {} : { resumeSessionId: request.resumeSessionId }),
|
|
13
|
+
...(request.usageBaseline === undefined ? {} : { usageBaseline: request.usageBaseline }),
|
|
14
|
+
...(request.reportRunnerStarted === undefined
|
|
15
|
+
? {}
|
|
16
|
+
: { reportRunnerStarted: request.reportRunnerStarted }),
|
|
17
|
+
...workspaceContext(request.workspace),
|
|
18
|
+
...(runner === undefined ? {} : { runner }),
|
|
19
|
+
...(runtime.dependencies.transcriptRecorder === undefined
|
|
20
|
+
? {}
|
|
21
|
+
: { transcriptRecorder: runtime.dependencies.transcriptRecorder }),
|
|
22
|
+
...(runtime.dependencies.logOperationalError === undefined
|
|
23
|
+
? {}
|
|
24
|
+
: { logOperationalError: runtime.dependencies.logOperationalError }),
|
|
25
|
+
...(request.runnerName === undefined
|
|
26
|
+
? {}
|
|
27
|
+
: {
|
|
28
|
+
runnerContext: {
|
|
29
|
+
runnerName: request.runnerName,
|
|
30
|
+
...(request.runnerCli === undefined ? {} : { runnerCli: request.runnerCli }),
|
|
31
|
+
activationOrdinal: activation.ordinal,
|
|
32
|
+
...(request.runnerModel === undefined ? {} : { model: request.runnerModel }),
|
|
33
|
+
...(request.runnerEffort === undefined ? {} : { effort: request.runnerEffort }),
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
reportExternalExecution: externalExecutionReporter(runtime, currentRunId, context, activation),
|
|
37
|
+
reportRunnerResult: runnerResultReporter(runtime, currentRunId, context, activation, request),
|
|
38
|
+
};
|
|
39
|
+
return runtime.activities.execute({
|
|
40
|
+
activationId: activation.activationId,
|
|
41
|
+
activity: activation.activity,
|
|
42
|
+
workItemId: context.workItemId,
|
|
43
|
+
workflowInstanceId: context.workflowInstanceId,
|
|
44
|
+
orchestrationGroupId: context.orchestrationGroupId,
|
|
45
|
+
causationId: activation.activationId,
|
|
46
|
+
input: activation.input,
|
|
47
|
+
resources: context.resources,
|
|
48
|
+
}, executionContext);
|
|
49
|
+
}
|
|
50
|
+
function externalExecutionReporter(runtime, currentRunId, context, activation) {
|
|
51
|
+
return async (reference) => {
|
|
52
|
+
const loaded = await runtime.repository.load(currentRunId);
|
|
53
|
+
await runtime.repository.append(currentRunId, loaded.sequence, [
|
|
54
|
+
createRunEvent({
|
|
55
|
+
runId: currentRunId,
|
|
56
|
+
eventId: `${currentRunId}:external:${reference.id}`,
|
|
57
|
+
eventType: ExecutionEventType.RunExternalExecutionReported,
|
|
58
|
+
occurredAt: runtime.dependencies.clock.now().toISOString(),
|
|
59
|
+
correlationId: context.orchestrationGroupId,
|
|
60
|
+
causationId: activation.activationId,
|
|
61
|
+
payload: reference,
|
|
62
|
+
}),
|
|
63
|
+
]);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function runnerResultReporter(runtime, currentRunId, context, activation, request) {
|
|
67
|
+
return async (result) => {
|
|
68
|
+
const loaded = await runtime.repository.load(currentRunId);
|
|
69
|
+
const event = createRunEvent({
|
|
70
|
+
runId: currentRunId,
|
|
71
|
+
eventId: `${currentRunId}:runner-result`,
|
|
72
|
+
eventType: ExecutionEventType.RunRunnerResultReported,
|
|
73
|
+
occurredAt: runtime.dependencies.clock.now().toISOString(),
|
|
74
|
+
correlationId: context.orchestrationGroupId,
|
|
75
|
+
causationId: activation.activationId,
|
|
76
|
+
payload: { transport: result.transport, agent: parseAgentRunnerResponse(result) },
|
|
77
|
+
});
|
|
78
|
+
await appendIdempotently(runtime.repository, currentRunId, loaded.sequence, event);
|
|
79
|
+
if (result.failure?.kind === 'provider-quota-exceeded' && request.runnerName !== undefined)
|
|
80
|
+
await runtime.dependencies.reportRunnerQuota?.({
|
|
81
|
+
runnerName: request.runnerName,
|
|
82
|
+
message: result.failure.message,
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function workspaceContext(workspace) {
|
|
87
|
+
return workspace === undefined ? {} : { workspace };
|
|
88
|
+
}
|
|
89
|
+
async function appendIdempotently(repository, currentRunId, sequence, event) {
|
|
90
|
+
try {
|
|
91
|
+
await repository.append(currentRunId, sequence, [event]);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
const current = await repository.load(currentRunId);
|
|
95
|
+
await repository.append(currentRunId, current.sequence, [event]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { selectRunExecutionEvent } from '../contracts/events.js';
|
|
2
|
+
import { foldRun } from '../domain/run.js';
|
|
3
|
+
export const executionProjection = {
|
|
4
|
+
name: 'execution',
|
|
5
|
+
select(event) {
|
|
6
|
+
const owned = selectRunExecutionEvent(event);
|
|
7
|
+
return owned === null ? null : { key: owned.stream.id };
|
|
8
|
+
},
|
|
9
|
+
initial: () => ({ events: [], view: null }),
|
|
10
|
+
project(previous, event) {
|
|
11
|
+
const owned = selectRunExecutionEvent(event);
|
|
12
|
+
if (owned === null)
|
|
13
|
+
return previous;
|
|
14
|
+
const events = [...previous.events, owned];
|
|
15
|
+
return { events, view: foldRun(events) };
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
/* eslint-disable max-lines */
|
|
2
|
+
import { ActivityExecutionKind, } from '../../activities/index.js';
|
|
3
|
+
import { runId } from '../contracts/identifiers.js';
|
|
4
|
+
import { ExecutionStreamKind } from '../contracts/streams.js';
|
|
5
|
+
import { RunStatus, WorkspaceMode } from '../contracts/vocabulary.js';
|
|
6
|
+
import { claimActivation, releaseActivation } from './activation-claim.js';
|
|
7
|
+
import { cancelActiveRuns } from './active-run-cancellation.js';
|
|
8
|
+
import { executeActivity, } from './execution-activity.js';
|
|
9
|
+
import { acquireWorkspace, validateResourceRequirements } from './execution-validation.js';
|
|
10
|
+
import { recordRunFailure, recordRunSuccess, recordWorkspaceCleanupFailure, startRun, } from './run-lifecycle.js';
|
|
11
|
+
import { claimRun, confirmCancellation, renewLease, requestCancellation, } from './run-liveness-service.js';
|
|
12
|
+
import { RunRepository } from './run-repository.js';
|
|
13
|
+
export function createExecutionService(journal, activities, config, dependencies) {
|
|
14
|
+
const repository = new RunRepository(journal);
|
|
15
|
+
const active = new Map();
|
|
16
|
+
return {
|
|
17
|
+
attempt: (activation, context) => attemptExecution({ activities, config, dependencies, repository, active, journal }, activation, context),
|
|
18
|
+
list: (activationId) => repository.list(activationId),
|
|
19
|
+
isLocallyActive: (id) => active.has(runId(id)),
|
|
20
|
+
claim: (id, owner) => claimRun(repository, dependencies.clock, config, runId(id), owner),
|
|
21
|
+
renewLease: (id, owner) => renewLease(repository, dependencies.clock, config, runId(id), owner),
|
|
22
|
+
requestCancellation: (id, reason) => requestCancellation(repository, dependencies.clock, runId(id), reason, active),
|
|
23
|
+
confirmCancellation: (id) => confirmCancellation(repository, dependencies.clock, runId(id)),
|
|
24
|
+
cancelActive: (workflowInstanceIds, reason) => cancelActiveRuns(repository, dependencies.clock, workflowInstanceIds, reason, active),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
// Starts the durable Run and hands agent invocation ownership to the detached worker.
|
|
28
|
+
// eslint-disable-next-line max-lines-per-function
|
|
29
|
+
async function attemptExecution(runtime, activation, context) {
|
|
30
|
+
const definition = runtime.activities.describe(activation.activity);
|
|
31
|
+
runtime.activities.validateInput(activation.activity, activation.input);
|
|
32
|
+
validateResources(definition.resources, context.resources);
|
|
33
|
+
const runner = resolveRunner(runtime, definition.executionKind, activation, context);
|
|
34
|
+
const owner = context.owner ?? 'execution';
|
|
35
|
+
const prior = await runtime.repository.list(activation.activationId);
|
|
36
|
+
const resumeCandidates = context.sessionPolicy === 'resume-stage' ? await runtime.repository.list() : prior;
|
|
37
|
+
const resumeScope = {
|
|
38
|
+
workflowInstanceId: context.workflowInstanceId,
|
|
39
|
+
stage: activation.stage,
|
|
40
|
+
...(context.sessionPolicy === undefined ? {} : { policy: context.sessionPolicy }),
|
|
41
|
+
};
|
|
42
|
+
const resumeSessionId = resumeSessionIdFor(resumeCandidates, runner.cli, resumeScope);
|
|
43
|
+
const usageBaseline = usageBaselineFor(resumeCandidates, runner.cli, resumeSessionId, resumeScope);
|
|
44
|
+
const existing = existingRun(prior, runtime.dependencies.clock, owner);
|
|
45
|
+
if (existing !== undefined)
|
|
46
|
+
return existing;
|
|
47
|
+
const currentRunId = runId(runtime.dependencies.ids.next(ExecutionStreamKind.Run));
|
|
48
|
+
const startedAt = runtime.dependencies.clock.now().toISOString();
|
|
49
|
+
let reportRunnerStarted = () => { };
|
|
50
|
+
const runnerStarted = new Promise((resolve) => {
|
|
51
|
+
reportRunnerStarted = resolve;
|
|
52
|
+
});
|
|
53
|
+
let lease;
|
|
54
|
+
let claimed = false;
|
|
55
|
+
try {
|
|
56
|
+
await claimActivationForAttempt(runtime, activation, currentRunId, owner, startedAt);
|
|
57
|
+
claimed = true;
|
|
58
|
+
lease = await acquireAttemptWorkspace(runtime, activation, context, currentRunId);
|
|
59
|
+
await startRun({
|
|
60
|
+
dependencies: runLifecycleDependencies(runtime),
|
|
61
|
+
runId: currentRunId,
|
|
62
|
+
activation,
|
|
63
|
+
context,
|
|
64
|
+
attempt: prior.length + 1,
|
|
65
|
+
startedAt,
|
|
66
|
+
runner,
|
|
67
|
+
lease,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
const persisted = await runtime.repository.load(currentRunId);
|
|
72
|
+
if (persisted.view?.status === RunStatus.Started) {
|
|
73
|
+
try {
|
|
74
|
+
await recordRunFailure({
|
|
75
|
+
dependencies: runLifecycleDependencies(runtime),
|
|
76
|
+
runId: currentRunId,
|
|
77
|
+
activation,
|
|
78
|
+
context,
|
|
79
|
+
error,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
await cleanupRun(runtime, currentRunId, activation, context, lease);
|
|
84
|
+
}
|
|
85
|
+
return (await runtime.repository.load(currentRunId)).view;
|
|
86
|
+
}
|
|
87
|
+
await releasePreStartResources(runtime, activation, currentRunId, lease, claimed);
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
90
|
+
const completion = completeRun(runtime, currentRunId, activation, context, startedAt, runner, resumeSessionId, usageBaseline, lease, reportRunnerStarted);
|
|
91
|
+
void completion.catch(() => {
|
|
92
|
+
reportRunnerStarted();
|
|
93
|
+
// A detached worker must never create an unhandled rejection for its caller.
|
|
94
|
+
});
|
|
95
|
+
await yieldToRunStart(definition.executionKind === ActivityExecutionKind.Deterministic &&
|
|
96
|
+
context.awaitImmediateCompletion
|
|
97
|
+
? undefined
|
|
98
|
+
: definition.executionKind === ActivityExecutionKind.Deterministic
|
|
99
|
+
? Promise.resolve()
|
|
100
|
+
: runnerStarted);
|
|
101
|
+
return (await runtime.repository.load(currentRunId)).view;
|
|
102
|
+
}
|
|
103
|
+
async function yieldToRunStart(runnerStarted) {
|
|
104
|
+
if (runnerStarted !== undefined)
|
|
105
|
+
return runnerStarted;
|
|
106
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
107
|
+
}
|
|
108
|
+
// A Run completion atomically carries the full execution lease context.
|
|
109
|
+
// eslint-disable-next-line max-params
|
|
110
|
+
async function completeRun(runtime, currentRunId, activation, context, startedAt, runner, resumeSessionId, usageBaseline, lease, reportRunnerStarted) {
|
|
111
|
+
const renewal = renewWhileRunning(runtime, currentRunId, context.owner ?? 'execution');
|
|
112
|
+
try {
|
|
113
|
+
const outcome = await executeActivity(runtime, currentRunId, {
|
|
114
|
+
activation,
|
|
115
|
+
context,
|
|
116
|
+
occurredAt: startedAt,
|
|
117
|
+
runner: runner.runner,
|
|
118
|
+
...(runner.name === undefined ? {} : { runnerName: runner.name }),
|
|
119
|
+
...(runner.cli === undefined ? {} : { runnerCli: runner.cli }),
|
|
120
|
+
...(runner.model === undefined ? {} : { runnerModel: runner.model }),
|
|
121
|
+
...(runner.effort === undefined ? {} : { runnerEffort: runner.effort }),
|
|
122
|
+
...(resumeSessionId === undefined ? {} : { resumeSessionId }),
|
|
123
|
+
...(usageBaseline === undefined ? {} : { usageBaseline }),
|
|
124
|
+
...(lease === undefined ? {} : { workspace: { path: lease.path, mode: lease.mode } }),
|
|
125
|
+
reportRunnerStarted,
|
|
126
|
+
});
|
|
127
|
+
await renewal.stop();
|
|
128
|
+
await recordRunSuccess({
|
|
129
|
+
dependencies: runLifecycleDependencies(runtime),
|
|
130
|
+
runId: currentRunId,
|
|
131
|
+
activation,
|
|
132
|
+
context,
|
|
133
|
+
outcome,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
try {
|
|
138
|
+
await renewal.stop();
|
|
139
|
+
await recordRunFailure({
|
|
140
|
+
dependencies: runLifecycleDependencies(runtime),
|
|
141
|
+
runId: currentRunId,
|
|
142
|
+
activation,
|
|
143
|
+
context,
|
|
144
|
+
error,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
// The caller already has a durable started Run; cleanup must still run.
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
reportRunnerStarted();
|
|
153
|
+
await renewal.stop();
|
|
154
|
+
await cleanupRun(runtime, currentRunId, activation, context, lease);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function renewWhileRunning(runtime, currentRunId, owner) {
|
|
158
|
+
const leaseDurationMs = runtime.config.leaseDurationMs ?? 60_000;
|
|
159
|
+
const intervalMs = runtime.config.leaseRenewalIntervalMs ?? Math.max(1, Math.floor(leaseDurationMs / 2));
|
|
160
|
+
let inFlight;
|
|
161
|
+
let stopped = false;
|
|
162
|
+
const timer = setInterval(() => {
|
|
163
|
+
if (stopped || inFlight !== undefined)
|
|
164
|
+
return;
|
|
165
|
+
const renewal = renewLease(runtime.repository, runtime.dependencies.clock, runtime.config, currentRunId, owner).then(() => undefined, () => {
|
|
166
|
+
// Recovery will reconcile a worker only after this process no longer tracks it.
|
|
167
|
+
});
|
|
168
|
+
inFlight = renewal;
|
|
169
|
+
void renewal.finally(() => {
|
|
170
|
+
if (inFlight === renewal)
|
|
171
|
+
inFlight = undefined;
|
|
172
|
+
});
|
|
173
|
+
}, intervalMs);
|
|
174
|
+
return {
|
|
175
|
+
async stop() {
|
|
176
|
+
stopped = true;
|
|
177
|
+
clearInterval(timer);
|
|
178
|
+
await inFlight;
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
async function cleanupRun(runtime, currentRunId, activation, context, lease) {
|
|
183
|
+
try {
|
|
184
|
+
await releaseActivation({
|
|
185
|
+
journal: runtime.journal,
|
|
186
|
+
clock: runtime.dependencies.clock,
|
|
187
|
+
activationId: activation.activationId,
|
|
188
|
+
runId: currentRunId,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
finally {
|
|
192
|
+
runtime.active.delete(currentRunId);
|
|
193
|
+
try {
|
|
194
|
+
await lease?.release();
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
try {
|
|
198
|
+
await recordWorkspaceCleanupFailure({
|
|
199
|
+
dependencies: runLifecycleDependencies(runtime),
|
|
200
|
+
runId: currentRunId,
|
|
201
|
+
activation,
|
|
202
|
+
context,
|
|
203
|
+
error,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
// A cleanup diagnostic must not make an already-finished run fatal.
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async function releasePreStartResources(runtime, activation, currentRunId, lease, claimed) {
|
|
213
|
+
if (claimed) {
|
|
214
|
+
try {
|
|
215
|
+
await releaseActivation({
|
|
216
|
+
journal: runtime.journal,
|
|
217
|
+
clock: runtime.dependencies.clock,
|
|
218
|
+
activationId: activation.activationId,
|
|
219
|
+
runId: currentRunId,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
// Preserve the original pre-start failure.
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
await lease?.release();
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
// There is no durable Run on which to record a cleanup diagnostic.
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
export function resumeSessionIdFor(prior, cli, scope) {
|
|
234
|
+
if (cli === undefined || scope?.policy === 'fresh')
|
|
235
|
+
return undefined;
|
|
236
|
+
const eligible = resumeEligibleRuns(prior, scope);
|
|
237
|
+
return [...eligible]
|
|
238
|
+
.filter((run) => isResumeTerminal(run.status))
|
|
239
|
+
.sort(compareNewestTerminalRun)
|
|
240
|
+
.find((run) => run.runner?.cli === cli &&
|
|
241
|
+
typeof run.agent?.metadata.sessionId === 'string' &&
|
|
242
|
+
run.agent.metadata.sessionId.trim().length > 0)?.agent?.metadata.sessionId;
|
|
243
|
+
}
|
|
244
|
+
export function usageBaselineFor(prior, cli, sessionId, scope) {
|
|
245
|
+
if (cli === undefined || sessionId === undefined)
|
|
246
|
+
return undefined;
|
|
247
|
+
const matching = resumeEligibleRuns(prior, scope).filter((run) => isResumeTerminal(run.status) &&
|
|
248
|
+
run.runner?.cli === cli &&
|
|
249
|
+
run.agent?.metadata.sessionId === sessionId);
|
|
250
|
+
if (matching.length === 0)
|
|
251
|
+
return undefined;
|
|
252
|
+
const requiredInput = sumCompleteCounters(matching, 'inputTokens');
|
|
253
|
+
const requiredOutput = sumCompleteCounters(matching, 'outputTokens');
|
|
254
|
+
if (requiredInput === undefined || requiredOutput === undefined)
|
|
255
|
+
return undefined;
|
|
256
|
+
const cacheRead = optionalCacheBaseline(matching, 'cacheReadTokens');
|
|
257
|
+
const cacheWrite = optionalCacheBaseline(matching, 'cacheWriteTokens');
|
|
258
|
+
if (cacheRead === 'invalid' || cacheWrite === 'invalid')
|
|
259
|
+
return undefined;
|
|
260
|
+
return {
|
|
261
|
+
input: requiredInput,
|
|
262
|
+
output: requiredOutput,
|
|
263
|
+
...(cacheRead === undefined ? {} : { cacheRead }),
|
|
264
|
+
...(cacheWrite === undefined ? {} : { cacheWrite }),
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function sumCompleteCounters(runs, key) {
|
|
268
|
+
let total = 0;
|
|
269
|
+
for (const run of runs) {
|
|
270
|
+
const value = run.agent?.metadata[key];
|
|
271
|
+
if (!isValidHistoricalCounter(value))
|
|
272
|
+
return undefined;
|
|
273
|
+
total += value;
|
|
274
|
+
}
|
|
275
|
+
return total;
|
|
276
|
+
}
|
|
277
|
+
function optionalCacheBaseline(runs, key) {
|
|
278
|
+
const values = runs.map((run) => run.agent?.metadata[key]);
|
|
279
|
+
let incomplete = false;
|
|
280
|
+
let total = 0;
|
|
281
|
+
for (const value of values) {
|
|
282
|
+
if (value === undefined) {
|
|
283
|
+
incomplete = true;
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
if (!isValidHistoricalCounter(value))
|
|
287
|
+
return 'invalid';
|
|
288
|
+
total += value;
|
|
289
|
+
}
|
|
290
|
+
return incomplete ? undefined : total;
|
|
291
|
+
}
|
|
292
|
+
function isValidHistoricalCounter(value) {
|
|
293
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0;
|
|
294
|
+
}
|
|
295
|
+
function resumeEligibleRuns(prior, scope) {
|
|
296
|
+
return scope?.policy !== 'resume-stage' || scope.stage === undefined
|
|
297
|
+
? prior
|
|
298
|
+
: prior.filter((run) => run.workflowInstanceId === scope.workflowInstanceId && run.stage === scope.stage);
|
|
299
|
+
}
|
|
300
|
+
function isResumeTerminal(status) {
|
|
301
|
+
return (status === RunStatus.Succeeded || status === RunStatus.Failed || status === RunStatus.Cancelled);
|
|
302
|
+
}
|
|
303
|
+
function compareNewestTerminalRun(left, right) {
|
|
304
|
+
const byFinishedAt = (right.finishedAt ?? '').localeCompare(left.finishedAt ?? '');
|
|
305
|
+
if (byFinishedAt !== 0)
|
|
306
|
+
return byFinishedAt;
|
|
307
|
+
const byAttempt = right.attempt - left.attempt;
|
|
308
|
+
if (byAttempt !== 0)
|
|
309
|
+
return byAttempt;
|
|
310
|
+
return right.runId.localeCompare(left.runId);
|
|
311
|
+
}
|
|
312
|
+
function resolveRunner(runtime, executionKind, activation, context) {
|
|
313
|
+
const runnerPool = activation.execution?.runnerPool ?? runtime.config.defaultRunnerPool;
|
|
314
|
+
if (runtime.config.runnerPools[runnerPool] === undefined)
|
|
315
|
+
throw new Error(`Unknown execution runner pool: ${runnerPool}`);
|
|
316
|
+
if (executionKind !== ActivityExecutionKind.Agent)
|
|
317
|
+
return { runner: undefined };
|
|
318
|
+
const resolved = runtime.dependencies.runners?.resolve(runnerPool, context.ineligibleRunners ?? new Set());
|
|
319
|
+
return describeResolvedRunner(runtime, runnerPool, resolved);
|
|
320
|
+
}
|
|
321
|
+
function describeResolvedRunner(runtime, pool, resolved) {
|
|
322
|
+
if (resolved === undefined)
|
|
323
|
+
return { runner: undefined };
|
|
324
|
+
return {
|
|
325
|
+
runner: resolved.runner,
|
|
326
|
+
name: resolved.name,
|
|
327
|
+
model: runtime.config.agentRunners?.[resolved.name]?.model,
|
|
328
|
+
effort: runtime.config.agentRunners?.[resolved.name]?.effort,
|
|
329
|
+
pool,
|
|
330
|
+
cli: runtime.config.agentRunners?.[resolved.name]?.kind,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function runLifecycleDependencies(runtime) {
|
|
334
|
+
return {
|
|
335
|
+
clock: runtime.dependencies.clock,
|
|
336
|
+
config: runtime.config,
|
|
337
|
+
repository: runtime.repository,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
async function claimActivationForAttempt(runtime, activation, currentRunId, owner, occurredAt) {
|
|
341
|
+
await claimActivation({
|
|
342
|
+
journal: runtime.journal,
|
|
343
|
+
clock: runtime.dependencies.clock,
|
|
344
|
+
config: runtime.config,
|
|
345
|
+
activationId: activation.activationId,
|
|
346
|
+
runId: currentRunId,
|
|
347
|
+
owner,
|
|
348
|
+
occurredAt,
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
function acquireAttemptWorkspace(runtime, activation, context, currentRunId) {
|
|
352
|
+
return acquireWorkspace(currentRunId, activation.execution?.workspace ?? WorkspaceMode.None, context.workItemId, context.resources, runtime.dependencies.workspaces);
|
|
353
|
+
}
|
|
354
|
+
function existingRun(runs, clock, owner) {
|
|
355
|
+
const completed = runs.find((run) => run.status === RunStatus.Succeeded);
|
|
356
|
+
if (completed !== undefined)
|
|
357
|
+
return completed;
|
|
358
|
+
const ambiguous = runs.find((run) => run.status === RunStatus.Ambiguous);
|
|
359
|
+
if (ambiguous !== undefined)
|
|
360
|
+
return ambiguous;
|
|
361
|
+
const active = runs.find((run) => run.status === RunStatus.Started);
|
|
362
|
+
if (active === undefined)
|
|
363
|
+
return undefined;
|
|
364
|
+
if (active.lease !== undefined &&
|
|
365
|
+
new Date(active.lease.expiresAt) > clock.now() &&
|
|
366
|
+
active.lease.owner !== owner)
|
|
367
|
+
throw new Error(`Run ${active.runId} has an unexpired lease`);
|
|
368
|
+
return active;
|
|
369
|
+
}
|
|
370
|
+
function validateResources(requirements, resources) {
|
|
371
|
+
validateResourceRequirements(requirements, resources);
|
|
372
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ActivityResourceCardinality } from '../../activities/index.js';
|
|
2
|
+
import { BuiltInResourceKind } from '../../resources/index.js';
|
|
3
|
+
import { WorkspaceMode } from '../contracts/vocabulary.js';
|
|
4
|
+
export async function acquireWorkspace(runId, mode, workItemId, resources, provider) {
|
|
5
|
+
if (mode === WorkspaceMode.None)
|
|
6
|
+
return undefined;
|
|
7
|
+
if (provider === undefined)
|
|
8
|
+
throw new Error('Workspace provider is required');
|
|
9
|
+
const repositoryResource = resources.find((resource) => resource.kind === BuiltInResourceKind.Repository) ??
|
|
10
|
+
resources.find((resource) => resource.kind === BuiltInResourceKind.Issue ||
|
|
11
|
+
resource.kind === BuiltInResourceKind.PullRequest);
|
|
12
|
+
if (repositoryResource === undefined)
|
|
13
|
+
throw new Error('Repository Resource is required');
|
|
14
|
+
return provider.acquire({ runId, mode, workItemId, repositoryResource });
|
|
15
|
+
}
|
|
16
|
+
export function validateResourceRequirements(requirements, resources) {
|
|
17
|
+
for (const requirement of requirements) {
|
|
18
|
+
const count = resources.filter((resource) => resource.capabilities.includes(requirement.capability)).length;
|
|
19
|
+
if (requirement.cardinality === ActivityResourceCardinality.ExactlyOne && count !== 1)
|
|
20
|
+
throw new Error(`Activity requires exactly one ${requirement.capability} Resource`);
|
|
21
|
+
if (requirement.cardinality === ActivityResourceCardinality.OneOrMore && count < 1)
|
|
22
|
+
throw new Error(`Activity requires ${requirement.capability} Resources`);
|
|
23
|
+
if (requirement.cardinality === ActivityResourceCardinality.ZeroOrOne && count > 1)
|
|
24
|
+
throw new Error(`Activity allows at most one ${requirement.capability} Resource`);
|
|
25
|
+
}
|
|
26
|
+
}
|