cloving 0.3.20 → 1.0.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/{LICENSE.md → LICENSE} +1 -1
- package/README.md +475 -182
- package/dist/src/authority/budgets.d.ts +12 -0
- package/dist/src/authority/budgets.js +42 -0
- package/dist/src/authority/commands.d.ts +7 -0
- package/dist/src/authority/commands.js +263 -0
- package/dist/src/authority/details.d.ts +28 -0
- package/dist/src/authority/details.js +33 -0
- package/dist/src/authority/dispatch-decision.d.ts +40 -0
- package/dist/src/authority/dispatch-decision.js +47 -0
- package/dist/src/authority/effect-requests.d.ts +2 -0
- package/dist/src/authority/effect-requests.js +139 -0
- package/dist/src/authority/effect-results.d.ts +4 -0
- package/dist/src/authority/effect-results.js +236 -0
- package/dist/src/authority/events.d.ts +2 -0
- package/dist/src/authority/events.js +45 -0
- package/dist/src/authority/gate-reduction.d.ts +8 -0
- package/dist/src/authority/gate-reduction.js +109 -0
- package/dist/src/authority/gates.d.ts +48 -0
- package/dist/src/authority/gates.js +77 -0
- package/dist/src/authority/history-state.d.ts +15 -0
- package/dist/src/authority/history-state.js +61 -0
- package/dist/src/authority/history.d.ts +13 -0
- package/dist/src/authority/history.js +37 -0
- package/dist/src/authority/instants.d.ts +3 -0
- package/dist/src/authority/instants.js +38 -0
- package/dist/src/authority/leases.d.ts +15 -0
- package/dist/src/authority/leases.js +113 -0
- package/dist/src/authority/operations.d.ts +101 -0
- package/dist/src/authority/operations.js +75 -0
- package/dist/src/authority/reconciliation.d.ts +27 -0
- package/dist/src/authority/reconciliation.js +147 -0
- package/dist/src/authority/reducer.d.ts +41 -0
- package/dist/src/authority/reducer.js +139 -0
- package/dist/src/authority/reduction-state.d.ts +36 -0
- package/dist/src/authority/reduction-state.js +68 -0
- package/dist/src/authority/reduction.d.ts +6 -0
- package/dist/src/authority/reduction.js +160 -0
- package/dist/src/authority/status-closure.d.ts +4 -0
- package/dist/src/authority/status-closure.js +57 -0
- package/dist/src/authority/status-effects.d.ts +17 -0
- package/dist/src/authority/status-effects.js +43 -0
- package/dist/src/authority/status-input.d.ts +45 -0
- package/dist/src/authority/status-input.js +9 -0
- package/dist/src/authority/status.d.ts +32 -0
- package/dist/src/authority/status.js +256 -0
- package/dist/src/authority/stop-sequence.d.ts +37 -0
- package/dist/src/authority/stop-sequence.js +91 -0
- package/dist/src/authority/transitions.d.ts +63 -0
- package/dist/src/authority/transitions.js +122 -0
- package/dist/src/broker/actor/adapter-calls.d.ts +13 -0
- package/dist/src/broker/actor/adapter-calls.js +34 -0
- package/dist/src/broker/actor/adapter-outcomes.d.ts +28 -0
- package/dist/src/broker/actor/adapter-outcomes.js +80 -0
- package/dist/src/broker/actor/authority-actor.d.ts +25 -0
- package/dist/src/broker/actor/authority-actor.js +169 -0
- package/dist/src/broker/actor/authority-changes.d.ts +31 -0
- package/dist/src/broker/actor/authority-changes.js +46 -0
- package/dist/src/broker/actor/authority-connection.d.ts +15 -0
- package/dist/src/broker/actor/authority-connection.js +44 -0
- package/dist/src/broker/actor/authority-conversion.d.ts +10 -0
- package/dist/src/broker/actor/authority-conversion.js +72 -0
- package/dist/src/broker/actor/authority-delivery.d.ts +13 -0
- package/dist/src/broker/actor/authority-delivery.js +162 -0
- package/dist/src/broker/actor/authority-logger.d.ts +2 -0
- package/dist/src/broker/actor/authority-logger.js +19 -0
- package/dist/src/broker/actor/authority-policy.d.ts +9 -0
- package/dist/src/broker/actor/authority-policy.js +11 -0
- package/dist/src/broker/actor/authority-queries.d.ts +45 -0
- package/dist/src/broker/actor/authority-queries.js +85 -0
- package/dist/src/broker/actor/authority-receipts.d.ts +28 -0
- package/dist/src/broker/actor/authority-receipts.js +84 -0
- package/dist/src/broker/actor/authority-release.d.ts +13 -0
- package/dist/src/broker/actor/authority-release.js +69 -0
- package/dist/src/broker/actor/authority-runtime.d.ts +60 -0
- package/dist/src/broker/actor/authority-runtime.js +204 -0
- package/dist/src/broker/actor/authority-session.d.ts +65 -0
- package/dist/src/broker/actor/authority-session.js +252 -0
- package/dist/src/broker/actor/authority-settings.d.ts +33 -0
- package/dist/src/broker/actor/authority-settings.js +63 -0
- package/dist/src/broker/actor/authority-upgrades.d.ts +16 -0
- package/dist/src/broker/actor/authority-upgrades.js +12 -0
- package/dist/src/broker/actor/authority-watchdog.d.ts +14 -0
- package/dist/src/broker/actor/authority-watchdog.js +41 -0
- package/dist/src/broker/actor/authority.d.ts +14 -0
- package/dist/src/broker/actor/authority.js +115 -0
- package/dist/src/broker/actor/delivery-intents.d.ts +68 -0
- package/dist/src/broker/actor/delivery-intents.js +77 -0
- package/dist/src/broker/actor/delivery-plan.d.ts +2 -0
- package/dist/src/broker/actor/delivery-plan.js +109 -0
- package/dist/src/broker/actor/delivery-results.d.ts +11 -0
- package/dist/src/broker/actor/delivery-results.js +63 -0
- package/dist/src/broker/actor/effect-delivery.d.ts +19 -0
- package/dist/src/broker/actor/effect-delivery.js +118 -0
- package/dist/src/broker/actor/effect-plan.d.ts +41 -0
- package/dist/src/broker/actor/effect-plan.js +173 -0
- package/dist/src/broker/actor/effect-queries.d.ts +27 -0
- package/dist/src/broker/actor/effect-queries.js +80 -0
- package/dist/src/broker/actor/effect-turn.d.ts +25 -0
- package/dist/src/broker/actor/effect-turn.js +84 -0
- package/dist/src/broker/actor/pin-check.d.ts +6 -0
- package/dist/src/broker/actor/pin-check.js +12 -0
- package/dist/src/broker/actor/runtime-parts.d.ts +23 -0
- package/dist/src/broker/actor/runtime-parts.js +34 -0
- package/dist/src/broker/actor/stop-plan.d.ts +20 -0
- package/dist/src/broker/actor/stop-plan.js +46 -0
- package/dist/src/broker/actor/stop-turn.d.ts +17 -0
- package/dist/src/broker/actor/stop-turn.js +42 -0
- package/dist/src/broker/actor/turn-draft.d.ts +31 -0
- package/dist/src/broker/actor/turn-draft.js +138 -0
- package/dist/src/broker/actor/turn-plan.d.ts +17 -0
- package/dist/src/broker/actor/turn-plan.js +136 -0
- package/dist/src/broker/actor/turn-refusals.d.ts +8 -0
- package/dist/src/broker/actor/turn-refusals.js +35 -0
- package/dist/src/broker/actor/turn-staging.d.ts +78 -0
- package/dist/src/broker/actor/turn-staging.js +34 -0
- package/dist/src/broker/actor/turn-state.d.ts +34 -0
- package/dist/src/broker/actor/turn-state.js +208 -0
- package/dist/src/broker/authority-admission.d.ts +21 -0
- package/dist/src/broker/authority-admission.js +70 -0
- package/dist/src/broker/authority-restore.d.ts +30 -0
- package/dist/src/broker/authority-restore.js +165 -0
- package/dist/src/broker/decision-restore.d.ts +16 -0
- package/dist/src/broker/decision-restore.js +158 -0
- package/dist/src/broker/decision-upgrade.d.ts +3 -0
- package/dist/src/broker/decision-upgrade.js +12 -0
- package/dist/src/broker/effect-restore.d.ts +20 -0
- package/dist/src/broker/effect-restore.js +111 -0
- package/dist/src/broker/effect-upgrade.d.ts +3 -0
- package/dist/src/broker/effect-upgrade.js +9 -0
- package/dist/src/broker/operation-digest.d.ts +1 -0
- package/dist/src/broker/operation-digest.js +4 -0
- package/dist/src/broker/socket-address.d.ts +9 -0
- package/dist/src/broker/socket-address.js +14 -0
- package/dist/src/broker/workflow-pin.d.ts +2 -0
- package/dist/src/broker/workflow-pin.js +5 -0
- package/dist/src/chats/destination.d.ts +4 -0
- package/dist/src/chats/destination.js +94 -0
- package/dist/src/chats/import.d.ts +13 -0
- package/dist/src/chats/import.js +71 -0
- package/dist/src/chats/normalize.d.ts +20 -0
- package/dist/src/chats/normalize.js +139 -0
- package/dist/src/chats/reader.d.ts +15 -0
- package/dist/src/chats/reader.js +87 -0
- package/dist/src/cli/arguments.d.ts +23 -0
- package/dist/src/cli/arguments.js +154 -0
- package/dist/src/cli/client.d.ts +15 -0
- package/dist/src/cli/client.js +122 -0
- package/dist/src/cli/commands.d.ts +14 -0
- package/dist/src/cli/commands.js +253 -0
- package/dist/src/cli/main.d.ts +1 -0
- package/dist/src/cli/main.js +80 -0
- package/dist/src/cli/render.d.ts +8 -0
- package/dist/src/cli/render.js +186 -0
- package/dist/src/cli/runtime-arguments.d.ts +73 -0
- package/dist/src/cli/runtime-arguments.js +248 -0
- package/dist/src/cli/runtime-directory.d.ts +4 -0
- package/dist/src/cli/runtime-directory.js +25 -0
- package/dist/src/cli/toolchain.d.ts +3 -0
- package/dist/src/cli/toolchain.js +74 -0
- package/dist/src/cli/usage.d.ts +4 -0
- package/dist/src/cli/usage.js +124 -0
- package/dist/src/cli/validate.d.ts +38 -0
- package/dist/src/cli/validate.js +116 -0
- package/dist/src/cli/watch-board-view.d.ts +22 -0
- package/dist/src/cli/watch-board-view.js +128 -0
- package/dist/src/cli/watch-board.d.ts +15 -0
- package/dist/src/cli/watch-board.js +174 -0
- package/dist/src/cli/watch-element.d.ts +11 -0
- package/dist/src/cli/watch-element.js +6 -0
- package/dist/src/cli/watch-model.d.ts +29 -0
- package/dist/src/cli/watch-model.js +261 -0
- package/dist/src/cli/watch-navigation.d.ts +9 -0
- package/dist/src/cli/watch-navigation.js +40 -0
- package/dist/src/cli/watch-page.d.ts +1 -0
- package/dist/src/cli/watch-page.js +272 -0
- package/dist/src/cli/watch-paths.d.ts +2 -0
- package/dist/src/cli/watch-paths.js +52 -0
- package/dist/src/cli/watch-phases.d.ts +7 -0
- package/dist/src/cli/watch-phases.js +148 -0
- package/dist/src/cli/watch-reads.d.ts +28 -0
- package/dist/src/cli/watch-reads.js +244 -0
- package/dist/src/cli/watch-render.d.ts +139 -0
- package/dist/src/cli/watch-render.js +95 -0
- package/dist/src/cli/watch-server.d.ts +10 -0
- package/dist/src/cli/watch-server.js +176 -0
- package/dist/src/cli/watch-stream.d.ts +11 -0
- package/dist/src/cli/watch-stream.js +128 -0
- package/dist/src/cli/watch-turn.d.ts +29 -0
- package/dist/src/cli/watch-turn.js +130 -0
- package/dist/src/cli/watch-view.d.ts +39 -0
- package/dist/src/cli/watch-view.js +223 -0
- package/dist/src/cli.d.ts +2 -0
- package/dist/src/cli.js +62 -0
- package/dist/src/daemon/claude-turn.d.ts +28 -0
- package/dist/src/daemon/claude-turn.js +135 -0
- package/dist/src/daemon/claude-worker.d.ts +26 -0
- package/dist/src/daemon/claude-worker.js +224 -0
- package/dist/src/daemon/codex-stream.d.ts +4 -0
- package/dist/src/daemon/codex-stream.js +113 -0
- package/dist/src/daemon/daemon.d.ts +46 -0
- package/dist/src/daemon/daemon.js +186 -0
- package/dist/src/daemon/delivery-router.d.ts +10 -0
- package/dist/src/daemon/delivery-router.js +34 -0
- package/dist/src/daemon/github-calls.d.ts +29 -0
- package/dist/src/daemon/github-calls.js +127 -0
- package/dist/src/daemon/github-issue-methods.d.ts +3 -0
- package/dist/src/daemon/github-issue-methods.js +99 -0
- package/dist/src/daemon/github-issue-privacy.d.ts +6 -0
- package/dist/src/daemon/github-issue-privacy.js +131 -0
- package/dist/src/daemon/github-merge.d.ts +18 -0
- package/dist/src/daemon/github-merge.js +259 -0
- package/dist/src/daemon/github-methods.d.ts +5 -0
- package/dist/src/daemon/github-methods.js +198 -0
- package/dist/src/daemon/github-operation.d.ts +38 -0
- package/dist/src/daemon/github-operation.js +57 -0
- package/dist/src/daemon/github-worker.d.ts +17 -0
- package/dist/src/daemon/github-worker.js +281 -0
- package/dist/src/daemon/host-environment.d.ts +8 -0
- package/dist/src/daemon/host-environment.js +14 -0
- package/dist/src/daemon/issue-queue.d.ts +9 -0
- package/dist/src/daemon/issue-queue.js +163 -0
- package/dist/src/daemon/notify-message.d.ts +14 -0
- package/dist/src/daemon/notify-message.js +48 -0
- package/dist/src/daemon/notify.d.ts +12 -0
- package/dist/src/daemon/notify.js +161 -0
- package/dist/src/daemon/operation-journal.d.ts +42 -0
- package/dist/src/daemon/operation-journal.js +53 -0
- package/dist/src/daemon/ticket-registration.d.ts +33 -0
- package/dist/src/daemon/ticket-registration.js +177 -0
- package/dist/src/daemon/ticket-source.d.ts +17 -0
- package/dist/src/daemon/ticket-source.js +36 -0
- package/dist/src/daemon/work-tree.d.ts +26 -0
- package/dist/src/daemon/work-tree.js +206 -0
- package/dist/src/effect-authorization.d.ts +21 -0
- package/dist/src/effect-authorization.js +14 -0
- package/dist/src/execution-pin.d.ts +4 -0
- package/dist/src/execution-pin.js +68 -0
- package/dist/src/host/start-delivery.d.ts +41 -0
- package/dist/src/host/start-delivery.js +68 -0
- package/dist/src/host/step-bridge-host.d.ts +79 -0
- package/dist/src/host/step-bridge-host.js +205 -0
- package/dist/src/host/step-claims.d.ts +31 -0
- package/dist/src/host/step-claims.js +85 -0
- package/dist/src/host/world-host.d.ts +21 -0
- package/dist/src/host/world-host.js +51 -0
- package/dist/src/host/world-reconciliation.d.ts +37 -0
- package/dist/src/host/world-reconciliation.js +75 -0
- package/dist/src/host/world-runs.d.ts +14 -0
- package/dist/src/host/world-runs.js +61 -0
- package/dist/src/operation-identity.d.ts +7 -0
- package/dist/src/operation-identity.js +59 -0
- package/dist/src/protocol.d.ts +35 -0
- package/dist/src/protocol.js +64 -0
- package/dist/src/resource-files.d.ts +1 -0
- package/dist/src/resource-files.js +29 -0
- package/dist/src/service/changes.d.ts +11 -0
- package/dist/src/service/changes.js +32 -0
- package/dist/src/service/decision-handler.d.ts +9 -0
- package/dist/src/service/decision-handler.js +233 -0
- package/dist/src/service/event-handler.d.ts +10 -0
- package/dist/src/service/event-handler.js +70 -0
- package/dist/src/service/expiry.d.ts +13 -0
- package/dist/src/service/expiry.js +53 -0
- package/dist/src/service/gateway.d.ts +21 -0
- package/dist/src/service/gateway.js +120 -0
- package/dist/src/service/registry.d.ts +40 -0
- package/dist/src/service/registry.js +13 -0
- package/dist/src/service/replies.d.ts +26 -0
- package/dist/src/service/replies.js +56 -0
- package/dist/src/service/run-handlers.d.ts +4 -0
- package/dist/src/service/run-handlers.js +271 -0
- package/dist/src/service/service.d.ts +58 -0
- package/dist/src/service/service.js +212 -0
- package/dist/src/service/submission-handler.d.ts +4 -0
- package/dist/src/service/submission-handler.js +206 -0
- package/dist/src/service/transport.d.ts +16 -0
- package/dist/src/service/transport.js +141 -0
- package/dist/src/service/worker-port.d.ts +85 -0
- package/dist/src/service/worker-port.js +126 -0
- package/dist/src/step-bridge.d.ts +57 -0
- package/dist/src/step-bridge.js +4 -0
- package/dist/src/steps/decision-gate.d.ts +2 -0
- package/dist/src/steps/decision-gate.js +8 -0
- package/dist/src/steps/load-cycle.d.ts +10 -0
- package/dist/src/steps/load-cycle.js +11 -0
- package/dist/src/steps/protected-effect.d.ts +2 -0
- package/dist/src/steps/protected-effect.js +8 -0
- package/dist/src/storage/decision-rows.d.ts +54 -0
- package/dist/src/storage/decision-rows.js +72 -0
- package/dist/src/storage/decision-snapshots.d.ts +17 -0
- package/dist/src/storage/decision-snapshots.js +25 -0
- package/dist/src/storage/domain-changes.d.ts +48 -0
- package/dist/src/storage/domain-changes.js +213 -0
- package/dist/src/storage/domain-rows.d.ts +85 -0
- package/dist/src/storage/domain-rows.js +129 -0
- package/dist/src/storage/domain-schema.d.ts +32 -0
- package/dist/src/storage/domain-schema.js +193 -0
- package/dist/src/storage/effect-changes.d.ts +5 -0
- package/dist/src/storage/effect-changes.js +105 -0
- package/dist/src/storage/effect-rows.d.ts +67 -0
- package/dist/src/storage/effect-rows.js +74 -0
- package/dist/src/storage/effect-schema.d.ts +1 -0
- package/dist/src/storage/effect-schema.js +59 -0
- package/dist/src/storage/statements.d.ts +9 -0
- package/dist/src/storage/statements.js +8 -0
- package/dist/src/submission.d.ts +42 -0
- package/dist/src/submission.js +71 -0
- package/dist/src/turn-profile.d.ts +13 -0
- package/dist/src/turn-profile.js +100 -0
- package/dist/src/workflow-admission.d.ts +45 -0
- package/dist/src/workflow-admission.js +151 -0
- package/dist/src/workflow-contracts.d.ts +27 -0
- package/dist/src/workflow-contracts.js +88 -0
- package/dist/src/workflow-declaration.d.ts +11 -0
- package/dist/src/workflow-declaration.js +57 -0
- package/dist/src/workflow-resources.d.ts +8 -0
- package/dist/src/workflow-resources.js +14 -0
- package/dist/src/workflows.d.ts +5 -0
- package/dist/src/workflows.js +3 -0
- package/dist/tools/compile-workflows.d.ts +1 -0
- package/dist/tools/compile-workflows.js +33 -0
- package/dist/tools/self-host-processes.d.ts +10 -0
- package/dist/tools/self-host-processes.js +151 -0
- package/dist/tools/self-host-workflows.d.ts +15 -0
- package/dist/tools/self-host-workflows.js +78 -0
- package/dist/tools/self-host.d.ts +1 -0
- package/dist/tools/self-host.js +261 -0
- package/dist/tools/self-update-host.d.ts +6 -0
- package/dist/tools/self-update-host.js +41 -0
- package/dist/tools/self-update.d.ts +10 -0
- package/dist/tools/self-update.js +105 -0
- package/dist/tools/workflow-manifest.d.ts +3 -0
- package/dist/tools/workflow-manifest.js +34 -0
- package/dist/workflows/develop-prd.d.ts +7 -0
- package/dist/workflows/develop-prd.js +97 -0
- package/dist/workflows/develop-ticket.d.ts +15 -0
- package/dist/workflows/develop-ticket.js +301 -0
- package/dist/workflows/issue-labels.d.ts +14 -0
- package/dist/workflows/issue-labels.js +36 -0
- package/package.json +82 -75
- package/dist/abstract_gpt/index.js +0 -55
- package/dist/cloving_gpt/adapters/Adapter.js +0 -2
- package/dist/cloving_gpt/adapters/azureopenai.js +0 -69
- package/dist/cloving_gpt/adapters/claude.js +0 -128
- package/dist/cloving_gpt/adapters/gemini.js +0 -135
- package/dist/cloving_gpt/adapters/gpt4all.js +0 -29
- package/dist/cloving_gpt/adapters/index.js +0 -2
- package/dist/cloving_gpt/adapters/mistral.js +0 -128
- package/dist/cloving_gpt/adapters/ollama.js +0 -128
- package/dist/cloving_gpt/adapters/openai.js +0 -100
- package/dist/cloving_gpt/index.js +0 -192
- package/dist/commands/analyze.js +0 -47
- package/dist/commands/chat.js +0 -14
- package/dist/commands/check.js +0 -7
- package/dist/commands/commit.js +0 -44
- package/dist/commands/config.js +0 -167
- package/dist/commands/describe.js +0 -235
- package/dist/commands/generate/code.js +0 -21
- package/dist/commands/generate/commit.js +0 -11
- package/dist/commands/generate/context.js +0 -82
- package/dist/commands/generate/docs.js +0 -11
- package/dist/commands/generate/documentation.js +0 -11
- package/dist/commands/generate/fizzbuzz.js +0 -35
- package/dist/commands/generate/init.js +0 -15
- package/dist/commands/generate/review.js +0 -11
- package/dist/commands/generate/sh.js +0 -95
- package/dist/commands/generate/shell.js +0 -11
- package/dist/commands/generate/unit_tests.js +0 -11
- package/dist/commands/init.js +0 -13
- package/dist/commands/models.js +0 -22
- package/dist/commands/project/build.js +0 -88
- package/dist/commands/project/complete.js +0 -12
- package/dist/commands/project/init.js +0 -82
- package/dist/commands/project/plan.js +0 -108
- package/dist/commands/proxy.js +0 -11
- package/dist/commands/review.js +0 -50
- package/dist/commands/tokens.js +0 -75
- package/dist/commands/unit_tests.js +0 -150
- package/dist/commands/update.js +0 -7
- package/dist/file2.js +0 -4
- package/dist/index.js +0 -136
- package/dist/managers/BlockManager.js +0 -120
- package/dist/managers/ChatManager.js +0 -653
- package/dist/managers/ChunkManager.js +0 -32
- package/dist/managers/CodeManager.js +0 -185
- package/dist/managers/CommitManager.js +0 -78
- package/dist/managers/DocsManager.js +0 -88
- package/dist/managers/DocumentationManager.js +0 -114
- package/dist/managers/InitManager.js +0 -230
- package/dist/managers/ProxyManager.js +0 -210
- package/dist/managers/ReviewManager.js +0 -131
- package/dist/managers/ShellManager.js +0 -163
- package/dist/managers/StreamManager.js +0 -308
- package/dist/managers/UnitTestManager.js +0 -243
- package/dist/managers/src/managers/ProxyManager.js +0 -1
- package/dist/newfile.js +0 -2
- package/dist/package.json +0 -86
- package/dist/utils/command_utils.js +0 -384
- package/dist/utils/config_utils.js +0 -249
- package/dist/utils/gitUtils.js +0 -42
- package/dist/utils/git_utils.js +0 -217
- package/dist/utils/modelUtils.js +0 -7
- package/dist/utils/model_utils.js +0 -7
- package/dist/utils/prompt_utils.js +0 -333
- package/dist/utils/prompts/CODEGEN_COULDNT_APPLY.md +0 -5
- package/dist/utils/prompts/CODEGEN_EXAMPLES.md +0 -82
- package/dist/utils/prompts/CODEGEN_INSTRUCTIONS.md +0 -43
- package/dist/utils/prompts/DOCS_INSTRUCTIONS.md +0 -9
- package/dist/utils/prompts/INIT_INSTRUCTIONS.md +0 -132
- package/dist/utils/prompts/REVIEW_INSTRUCTIONS.md +0 -49
- package/dist/utils/prompts/SHELL_INSTRUCTIONS.md +0 -15
- package/dist/utils/prompts/SPECIAL_FILES.md +0 -66
- package/dist/utils/prompts/index.js +0 -27
- package/dist/utils/string_utils.js +0 -505
- package/dist/utils/types.js +0 -2
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type EffectEvent, type EffectState, type RunBudget } from "./operations.ts";
|
|
2
|
+
type Payload = Readonly<Record<string, string>>;
|
|
3
|
+
export declare function admittedBudgets(budgets: EffectState["budgets"], admission: {
|
|
4
|
+
readonly runId: string;
|
|
5
|
+
readonly payload: Payload;
|
|
6
|
+
}): EffectState["budgets"];
|
|
7
|
+
export interface Authorization {
|
|
8
|
+
readonly reason: string | null;
|
|
9
|
+
readonly budget: RunBudget | undefined;
|
|
10
|
+
}
|
|
11
|
+
export declare function authorization(budget: RunBudget | undefined, event: EffectEvent): Authorization;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { authorizeEffect } from "../effect-authorization.js";
|
|
2
|
+
import { count, field, } from "./operations.js";
|
|
3
|
+
function capabilityList(text) {
|
|
4
|
+
const value = JSON.parse(text);
|
|
5
|
+
return Array.isArray(value) ? value.map(String) : [];
|
|
6
|
+
}
|
|
7
|
+
export function admittedBudgets(budgets, admission) {
|
|
8
|
+
const { runId, payload } = admission;
|
|
9
|
+
const limit = payload["effectLimit"];
|
|
10
|
+
if (limit === undefined)
|
|
11
|
+
return budgets;
|
|
12
|
+
return {
|
|
13
|
+
...budgets,
|
|
14
|
+
[runId]: {
|
|
15
|
+
runId,
|
|
16
|
+
limit: Number(limit),
|
|
17
|
+
spent: 0,
|
|
18
|
+
capabilities: capabilityList(payload["capabilities"] ?? "[]"),
|
|
19
|
+
exhaustedSequence: null,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const exhausted = "budget-exhausted";
|
|
24
|
+
export function authorization(budget, event) {
|
|
25
|
+
if (budget === undefined || budget.exhaustedSequence !== null)
|
|
26
|
+
return { reason: exhausted, budget };
|
|
27
|
+
const result = authorizeEffect({ capabilities: budget.capabilities }, {
|
|
28
|
+
budget: { limit: budget.limit, spent: budget.spent },
|
|
29
|
+
request: {
|
|
30
|
+
capability: field(event, "capability"),
|
|
31
|
+
units: count(event, "units"),
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
if (result.kind === "authorized")
|
|
35
|
+
return { reason: null, budget: { ...budget, spent: result.spent } };
|
|
36
|
+
return {
|
|
37
|
+
reason: result.reason,
|
|
38
|
+
budget: result.reason === exhausted
|
|
39
|
+
? { ...budget, exhaustedSequence: event.sequence }
|
|
40
|
+
: budget,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type AuthorityCommand, type EventType } from "./transitions.ts";
|
|
2
|
+
export declare const commandEvents: Readonly<Record<string, EventType>>;
|
|
3
|
+
export declare function parseCommand(value: unknown): AuthorityCommand | null;
|
|
4
|
+
export declare const recoveryBound = 10;
|
|
5
|
+
export declare function isCapabilityList(value: unknown): value is string;
|
|
6
|
+
export declare function isIdentifier(value: unknown): value is string;
|
|
7
|
+
export declare function isRecordKey(value: unknown): value is string;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { isInstant } from "./instants.js";
|
|
2
|
+
import { isBlockedReason } from "../workflow-contracts.js";
|
|
3
|
+
import { numberFields, textFields, } from "./transitions.js";
|
|
4
|
+
const identifier = /^[A-Za-z0-9._:/-]{1,128}$/;
|
|
5
|
+
const digest = /^sha256:[0-9a-f]{64}$/;
|
|
6
|
+
const operation = /^[\x20-\x7e]{1,512}$/;
|
|
7
|
+
export const commandEvents = {
|
|
8
|
+
"admit-run": "run.created",
|
|
9
|
+
"mark-started": "run.started",
|
|
10
|
+
"open-gate": "gate.opened",
|
|
11
|
+
"register-wait": "gate.wait-registered",
|
|
12
|
+
"decide-gate": "gate.decided",
|
|
13
|
+
"expire-gate": "gate.expired",
|
|
14
|
+
"pause-run": "run.paused",
|
|
15
|
+
"resume-run": "run.resumed",
|
|
16
|
+
"complete-run": "run.completed",
|
|
17
|
+
"fail-run": "run.failed",
|
|
18
|
+
"cancel-run": "run.cancelled",
|
|
19
|
+
"report-observation": "run.observed",
|
|
20
|
+
"record-dispatch": "step.dispatched",
|
|
21
|
+
"request-effect": "effect.requested",
|
|
22
|
+
"grant-lease": "lease.granted",
|
|
23
|
+
"expire-lease": "lease.expired",
|
|
24
|
+
"report-effect": "effect.reported",
|
|
25
|
+
"record-outcome": "operation.reconciled",
|
|
26
|
+
};
|
|
27
|
+
const revised = { required: ["expectedRevision"] };
|
|
28
|
+
const shapes = {
|
|
29
|
+
"admit-run": {
|
|
30
|
+
required: ["workflow"],
|
|
31
|
+
optional: [
|
|
32
|
+
"submission",
|
|
33
|
+
"input",
|
|
34
|
+
"resolver",
|
|
35
|
+
"effectLimit",
|
|
36
|
+
"capabilities",
|
|
37
|
+
],
|
|
38
|
+
groups: [
|
|
39
|
+
["submission", "input", "resolver"],
|
|
40
|
+
["effectLimit", "capabilities"],
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
"mark-started": revised,
|
|
44
|
+
"open-gate": {
|
|
45
|
+
required: ["gateId", "expectedRevision"],
|
|
46
|
+
optional: ["gateKind", "subject", "prompt", "expiresAt"],
|
|
47
|
+
groups: [["gateKind", "subject", "prompt"]],
|
|
48
|
+
consistent: (fields) => fields["expiresAt"] === undefined || fields["gateKind"] !== undefined,
|
|
49
|
+
},
|
|
50
|
+
"register-wait": { required: ["gateId"] },
|
|
51
|
+
"decide-gate": {
|
|
52
|
+
required: ["gateId", "decision", "expectedRevision"],
|
|
53
|
+
optional: ["generation", "subject", "answer"],
|
|
54
|
+
groups: [["generation", "subject"]],
|
|
55
|
+
consistent: (fields) => {
|
|
56
|
+
const typed = fields["generation"] !== undefined;
|
|
57
|
+
if (typed && fields["decision"] === "denied")
|
|
58
|
+
return true;
|
|
59
|
+
return ((fields["answer"] !== undefined) ===
|
|
60
|
+
(typed && fields["decision"] === "answered"));
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
"expire-gate": { required: ["gateId"] },
|
|
64
|
+
"pause-run": revised,
|
|
65
|
+
"resume-run": revised,
|
|
66
|
+
"complete-run": {
|
|
67
|
+
required: ["expectedRevision"],
|
|
68
|
+
optional: ["outcome", "outcomeReason"],
|
|
69
|
+
validators: {
|
|
70
|
+
outcome: (value) => value === "handoff_requested" || value === "blocked",
|
|
71
|
+
outcomeReason: isBlockedReason,
|
|
72
|
+
},
|
|
73
|
+
consistent: (fields) => fields["outcomeReason"] === undefined || fields["outcome"] === "blocked",
|
|
74
|
+
},
|
|
75
|
+
"fail-run": revised,
|
|
76
|
+
"cancel-run": revised,
|
|
77
|
+
"report-observation": {
|
|
78
|
+
required: ["condition", "reason"],
|
|
79
|
+
optional: ["evidence", "retryAt", "attempt", "limit", "operationId"],
|
|
80
|
+
groups: [["attempt", "limit"]],
|
|
81
|
+
},
|
|
82
|
+
"record-dispatch": { required: ["operationId", "receipt"] },
|
|
83
|
+
"request-effect": {
|
|
84
|
+
required: [
|
|
85
|
+
"operationId",
|
|
86
|
+
"capability",
|
|
87
|
+
"method",
|
|
88
|
+
"target",
|
|
89
|
+
"payload",
|
|
90
|
+
"inputDigest",
|
|
91
|
+
"units",
|
|
92
|
+
"recoveryLimit",
|
|
93
|
+
],
|
|
94
|
+
optional: ["resource", "transport", "source", "sourceGeneration"],
|
|
95
|
+
groups: [["source", "sourceGeneration"]],
|
|
96
|
+
},
|
|
97
|
+
"grant-lease": {
|
|
98
|
+
required: ["operationId", "leaseGeneration", "expiresAt", "capacity"],
|
|
99
|
+
},
|
|
100
|
+
"expire-lease": { required: ["operationId", "leaseGeneration"] },
|
|
101
|
+
"report-effect": {
|
|
102
|
+
required: [
|
|
103
|
+
"operationId",
|
|
104
|
+
"inputDigest",
|
|
105
|
+
"leaseGeneration",
|
|
106
|
+
"worker",
|
|
107
|
+
"outcome",
|
|
108
|
+
],
|
|
109
|
+
optional: ["result", "reason", "evidence"],
|
|
110
|
+
consistent: (fields) => reportedOutcomes.includes(String(fields["outcome"])) &&
|
|
111
|
+
(fields["outcome"] === "failed" ||
|
|
112
|
+
(fields["result"] !== undefined) ===
|
|
113
|
+
(fields["outcome"] === "completed")) &&
|
|
114
|
+
(fields["reason"] !== undefined) === (fields["outcome"] === "failed"),
|
|
115
|
+
},
|
|
116
|
+
"record-outcome": {
|
|
117
|
+
required: ["operationId", "outcome"],
|
|
118
|
+
optional: [
|
|
119
|
+
"leaseGeneration",
|
|
120
|
+
"receipt",
|
|
121
|
+
"worker",
|
|
122
|
+
"result",
|
|
123
|
+
"reason",
|
|
124
|
+
"evidence",
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
const reportedOutcomes = ["completed", "failed", "stopped"];
|
|
129
|
+
const outcomes = [...reportedOutcomes, "accepted", "not-started", "unknown"];
|
|
130
|
+
const conditions = [
|
|
131
|
+
"working",
|
|
132
|
+
"quota-wait",
|
|
133
|
+
"infrastructure-failure",
|
|
134
|
+
"code-failure",
|
|
135
|
+
"stopped",
|
|
136
|
+
];
|
|
137
|
+
export function parseCommand(value) {
|
|
138
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
139
|
+
return null;
|
|
140
|
+
const fields = Object.fromEntries(Object.entries(value).filter(([, item]) => item !== undefined));
|
|
141
|
+
const { kind, commandId, runId } = fields;
|
|
142
|
+
if (!knownKind(kind) || !isRecordKey(commandId) || !isRecordKey(runId))
|
|
143
|
+
return null;
|
|
144
|
+
if (!completeFields(kind, fields))
|
|
145
|
+
return null;
|
|
146
|
+
return {
|
|
147
|
+
kind,
|
|
148
|
+
commandId,
|
|
149
|
+
runId,
|
|
150
|
+
...numbers(fields),
|
|
151
|
+
...texts(fields),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function knownKind(kind) {
|
|
155
|
+
return typeof kind === "string" && Object.hasOwn(commandEvents, kind);
|
|
156
|
+
}
|
|
157
|
+
function completeFields(kind, fields) {
|
|
158
|
+
const shape = shapes[kind] ?? revised;
|
|
159
|
+
const optional = shape.optional ?? [];
|
|
160
|
+
const allowed = [
|
|
161
|
+
"kind",
|
|
162
|
+
"commandId",
|
|
163
|
+
"runId",
|
|
164
|
+
...shape.required,
|
|
165
|
+
...optional,
|
|
166
|
+
];
|
|
167
|
+
const present = optional.filter((key) => fields[key] !== undefined);
|
|
168
|
+
return (Object.keys(fields).every((key) => allowed.includes(key)) &&
|
|
169
|
+
[...shape.required, ...present].every((key) => (shape.validators?.[key] ?? validators[key] ?? isIdentifier)(fields[key])) &&
|
|
170
|
+
(shape.groups ?? []).every((group) => complete(group, fields)) &&
|
|
171
|
+
(shape.consistent?.(fields) ?? true));
|
|
172
|
+
}
|
|
173
|
+
function complete(group, fields) {
|
|
174
|
+
const present = group.filter((key) => fields[key] !== undefined).length;
|
|
175
|
+
return present === 0 || present === group.length;
|
|
176
|
+
}
|
|
177
|
+
function numbers(fields) {
|
|
178
|
+
const result = {};
|
|
179
|
+
for (const name of numberFields) {
|
|
180
|
+
const value = fields[name];
|
|
181
|
+
if (typeof value === "number")
|
|
182
|
+
result[name] = value;
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
function texts(fields) {
|
|
187
|
+
const result = {};
|
|
188
|
+
for (const name of textFields) {
|
|
189
|
+
const value = fields[name];
|
|
190
|
+
if (typeof value === "string")
|
|
191
|
+
result[name] = value;
|
|
192
|
+
}
|
|
193
|
+
return result;
|
|
194
|
+
}
|
|
195
|
+
function whole(value) {
|
|
196
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
197
|
+
}
|
|
198
|
+
export const recoveryBound = 10;
|
|
199
|
+
function positive(value) {
|
|
200
|
+
return whole(value) && value > 0;
|
|
201
|
+
}
|
|
202
|
+
function atMost(value, limit) {
|
|
203
|
+
return whole(value) && value <= limit;
|
|
204
|
+
}
|
|
205
|
+
function printable(value) {
|
|
206
|
+
return typeof value === "string" && operation.test(value);
|
|
207
|
+
}
|
|
208
|
+
function isDigest(value) {
|
|
209
|
+
return typeof value === "string" && digest.test(value);
|
|
210
|
+
}
|
|
211
|
+
function parsedList(text) {
|
|
212
|
+
try {
|
|
213
|
+
const value = JSON.parse(text);
|
|
214
|
+
return Array.isArray(value) ? value : null;
|
|
215
|
+
}
|
|
216
|
+
catch {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
export function isCapabilityList(value) {
|
|
221
|
+
if (typeof value !== "string")
|
|
222
|
+
return false;
|
|
223
|
+
const list = parsedList(value);
|
|
224
|
+
return (list !== null &&
|
|
225
|
+
list.length <= 64 &&
|
|
226
|
+
list.every(isIdentifier) &&
|
|
227
|
+
list.every((item, index) => index === 0 || String(list[index - 1]) < item) &&
|
|
228
|
+
JSON.stringify(list) === value);
|
|
229
|
+
}
|
|
230
|
+
const validators = {
|
|
231
|
+
expectedRevision: positive,
|
|
232
|
+
generation: positive,
|
|
233
|
+
attempt: positive,
|
|
234
|
+
limit: positive,
|
|
235
|
+
operationId: printable,
|
|
236
|
+
gateKind: (value) => value === "question" || value === "approval",
|
|
237
|
+
subject: isDigest,
|
|
238
|
+
effectLimit: whole,
|
|
239
|
+
units: whole,
|
|
240
|
+
recoveryLimit: (value) => positive(value) && atMost(value, recoveryBound),
|
|
241
|
+
leaseGeneration: positive,
|
|
242
|
+
sourceGeneration: positive,
|
|
243
|
+
capacity: positive,
|
|
244
|
+
capabilities: isCapabilityList,
|
|
245
|
+
target: printable,
|
|
246
|
+
transport: printable,
|
|
247
|
+
source: printable,
|
|
248
|
+
payload: isDigest,
|
|
249
|
+
inputDigest: isDigest,
|
|
250
|
+
result: isDigest,
|
|
251
|
+
resource: isRecordKey,
|
|
252
|
+
outcome: (value) => typeof value === "string" && outcomes.includes(value),
|
|
253
|
+
condition: (value) => typeof value === "string" && conditions.includes(value),
|
|
254
|
+
expiresAt: isInstant,
|
|
255
|
+
retryAt: isInstant,
|
|
256
|
+
};
|
|
257
|
+
export function isIdentifier(value) {
|
|
258
|
+
return typeof value === "string" && identifier.test(value);
|
|
259
|
+
}
|
|
260
|
+
const plainRecord = {};
|
|
261
|
+
export function isRecordKey(value) {
|
|
262
|
+
return isIdentifier(value) && !(value in plainRecord);
|
|
263
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface Observation {
|
|
2
|
+
readonly condition: string;
|
|
3
|
+
readonly reason: string;
|
|
4
|
+
readonly evidence: string | null;
|
|
5
|
+
readonly retryAt: string | null;
|
|
6
|
+
readonly operationId: string | null;
|
|
7
|
+
readonly attempt: number | null;
|
|
8
|
+
readonly limit: number | null;
|
|
9
|
+
readonly sequence: number;
|
|
10
|
+
readonly recordedAt: string;
|
|
11
|
+
}
|
|
12
|
+
export interface RunDetails {
|
|
13
|
+
readonly runId: string;
|
|
14
|
+
readonly generation: number;
|
|
15
|
+
readonly submission: string | null;
|
|
16
|
+
readonly input: string | null;
|
|
17
|
+
readonly resolver: string | null;
|
|
18
|
+
readonly observation: Observation | null;
|
|
19
|
+
}
|
|
20
|
+
type Payload = Readonly<Record<string, string>>;
|
|
21
|
+
export declare function admittedDetails(runId: string, payload: Payload): RunDetails;
|
|
22
|
+
export declare function observed(details: RunDetails, event: {
|
|
23
|
+
readonly payload: Payload;
|
|
24
|
+
readonly sequence: number;
|
|
25
|
+
readonly recordedAt: string;
|
|
26
|
+
}): RunDetails;
|
|
27
|
+
export declare function continued(details: RunDetails): RunDetails;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function admittedDetails(runId, payload) {
|
|
2
|
+
return {
|
|
3
|
+
runId,
|
|
4
|
+
generation: 1,
|
|
5
|
+
submission: payload["submission"] ?? null,
|
|
6
|
+
input: payload["input"] ?? null,
|
|
7
|
+
resolver: payload["resolver"] ?? null,
|
|
8
|
+
observation: null,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function count(value) {
|
|
12
|
+
return value === undefined ? null : Number(value);
|
|
13
|
+
}
|
|
14
|
+
export function observed(details, event) {
|
|
15
|
+
const { payload } = event;
|
|
16
|
+
return {
|
|
17
|
+
...details,
|
|
18
|
+
observation: {
|
|
19
|
+
condition: payload["condition"] ?? "",
|
|
20
|
+
reason: payload["reason"] ?? "",
|
|
21
|
+
evidence: payload["evidence"] ?? null,
|
|
22
|
+
retryAt: payload["retryAt"] ?? null,
|
|
23
|
+
operationId: payload["operationId"] ?? null,
|
|
24
|
+
attempt: count(payload["attempt"]),
|
|
25
|
+
limit: count(payload["limit"]),
|
|
26
|
+
sequence: event.sequence,
|
|
27
|
+
recordedAt: event.recordedAt,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function continued(details) {
|
|
32
|
+
return { ...details, generation: details.generation + 1 };
|
|
33
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface DispatchRead {
|
|
2
|
+
readonly attempt: {
|
|
3
|
+
readonly outcome: string | null;
|
|
4
|
+
readonly inputDigest: string;
|
|
5
|
+
readonly leaseGeneration: number | null;
|
|
6
|
+
} | undefined;
|
|
7
|
+
readonly released: boolean;
|
|
8
|
+
readonly runStatus: string;
|
|
9
|
+
readonly workflow: string;
|
|
10
|
+
readonly pinned: boolean;
|
|
11
|
+
readonly operation: {
|
|
12
|
+
readonly status: string;
|
|
13
|
+
readonly capability: string;
|
|
14
|
+
readonly units: number;
|
|
15
|
+
} | undefined;
|
|
16
|
+
readonly budget: {
|
|
17
|
+
readonly limit: number;
|
|
18
|
+
readonly spent: number;
|
|
19
|
+
readonly capabilities: readonly string[];
|
|
20
|
+
readonly exhaustedSequence: number | null;
|
|
21
|
+
} | undefined;
|
|
22
|
+
readonly lease: {
|
|
23
|
+
readonly operationId: string;
|
|
24
|
+
readonly generation: number;
|
|
25
|
+
readonly expiresAt: string;
|
|
26
|
+
readonly state: string;
|
|
27
|
+
} | undefined;
|
|
28
|
+
}
|
|
29
|
+
export interface DispatchCheck {
|
|
30
|
+
readonly intent: {
|
|
31
|
+
readonly operationId: string;
|
|
32
|
+
readonly inputDigest: string;
|
|
33
|
+
readonly computedDigest: string;
|
|
34
|
+
readonly workflow: string;
|
|
35
|
+
readonly leaseGeneration?: number;
|
|
36
|
+
};
|
|
37
|
+
readonly now: string;
|
|
38
|
+
}
|
|
39
|
+
export type DispatchDecision = "stale" | "withheld" | "refused" | "blocked" | "send";
|
|
40
|
+
export declare function dispatchDecision(read: DispatchRead, check: DispatchCheck): DispatchDecision;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { authorizeEffect } from "../effect-authorization.js";
|
|
2
|
+
import { isAfter } from "./instants.js";
|
|
3
|
+
function bound(read, intent) {
|
|
4
|
+
const { attempt, lease, operation } = read;
|
|
5
|
+
if (attempt === undefined || lease === undefined || operation === undefined)
|
|
6
|
+
return false;
|
|
7
|
+
return [
|
|
8
|
+
attempt.outcome === null,
|
|
9
|
+
attempt.inputDigest === intent.inputDigest,
|
|
10
|
+
intent.computedDigest === intent.inputDigest,
|
|
11
|
+
read.workflow === intent.workflow,
|
|
12
|
+
attempt.leaseGeneration === lease.generation,
|
|
13
|
+
intent.leaseGeneration === lease.generation,
|
|
14
|
+
lease.operationId === intent.operationId,
|
|
15
|
+
lease.state !== "released",
|
|
16
|
+
].every(Boolean);
|
|
17
|
+
}
|
|
18
|
+
function sendable(read, now) {
|
|
19
|
+
return [
|
|
20
|
+
!read.released,
|
|
21
|
+
read.runStatus === "running",
|
|
22
|
+
read.operation?.status === "dispatch-pending",
|
|
23
|
+
read.lease?.state === "held",
|
|
24
|
+
isAfter(read.lease?.expiresAt ?? "", now),
|
|
25
|
+
].every(Boolean);
|
|
26
|
+
}
|
|
27
|
+
function authorized(read) {
|
|
28
|
+
const { budget, operation } = read;
|
|
29
|
+
if (budget === undefined || operation === undefined)
|
|
30
|
+
return false;
|
|
31
|
+
if (budget.exhaustedSequence !== null)
|
|
32
|
+
return false;
|
|
33
|
+
const result = authorizeEffect({ capabilities: budget.capabilities }, {
|
|
34
|
+
budget: { limit: budget.limit, spent: budget.spent - operation.units },
|
|
35
|
+
request: { capability: operation.capability, units: operation.units },
|
|
36
|
+
});
|
|
37
|
+
return result.kind === "authorized";
|
|
38
|
+
}
|
|
39
|
+
export function dispatchDecision(read, check) {
|
|
40
|
+
if (!bound(read, check.intent))
|
|
41
|
+
return "stale";
|
|
42
|
+
if (!sendable(read, check.now))
|
|
43
|
+
return "withheld";
|
|
44
|
+
if (!authorized(read))
|
|
45
|
+
return "refused";
|
|
46
|
+
return read.pinned ? "send" : "blocked";
|
|
47
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { operationScope } from "../operation-identity.js";
|
|
2
|
+
import { authorization } from "./budgets.js";
|
|
3
|
+
import { current, ownedLease } from "./leases.js";
|
|
4
|
+
import { cancelledOperation, count, field, rejected, runOperations, withOperation, } from "./operations.js";
|
|
5
|
+
const admittingStatuses = ["running", "paused", "waiting_gate"];
|
|
6
|
+
const terminalStatuses = ["completed", "failed", "cancelled"];
|
|
7
|
+
const compared = [
|
|
8
|
+
"capability",
|
|
9
|
+
"method",
|
|
10
|
+
"target",
|
|
11
|
+
"payload",
|
|
12
|
+
"inputDigest",
|
|
13
|
+
];
|
|
14
|
+
function refusal(context) {
|
|
15
|
+
const { event, runStatus } = context;
|
|
16
|
+
if (terminalStatuses.includes(runStatus))
|
|
17
|
+
return "terminal-run";
|
|
18
|
+
if (!admittingStatuses.includes(runStatus))
|
|
19
|
+
return "run-not-running";
|
|
20
|
+
const scope = operationScope(field(event, "operationId"));
|
|
21
|
+
if (scope?.run !== event.runId)
|
|
22
|
+
return "operation-scope-mismatch";
|
|
23
|
+
if (runOperations.includes(scope.operation))
|
|
24
|
+
return "operation-scope-mismatch";
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
function leaseKeyOf(event) {
|
|
28
|
+
return event.payload["resource"] ?? field(event, "operationId");
|
|
29
|
+
}
|
|
30
|
+
function equalInput(operation, event) {
|
|
31
|
+
return (compared.every((name) => operation[name] === field(event, name)) &&
|
|
32
|
+
operation.units === count(event, "units") &&
|
|
33
|
+
operation.leaseKey === leaseKeyOf(event));
|
|
34
|
+
}
|
|
35
|
+
function waitReason(effects, wait) {
|
|
36
|
+
const lease = effects.leases[wait.leaseKey];
|
|
37
|
+
if (lease !== undefined && lease.state !== "released")
|
|
38
|
+
return "resource";
|
|
39
|
+
return wait.runStatus === "running" ? "ready" : "run-not-running";
|
|
40
|
+
}
|
|
41
|
+
function requestedOperation(event, outcome) {
|
|
42
|
+
return {
|
|
43
|
+
runId: event.runId,
|
|
44
|
+
operationId: field(event, "operationId"),
|
|
45
|
+
capability: field(event, "capability"),
|
|
46
|
+
method: field(event, "method"),
|
|
47
|
+
target: field(event, "target"),
|
|
48
|
+
payload: field(event, "payload"),
|
|
49
|
+
inputDigest: field(event, "inputDigest"),
|
|
50
|
+
units: count(event, "units"),
|
|
51
|
+
leaseKey: leaseKeyOf(event),
|
|
52
|
+
recoveryLimit: count(event, "recoveryLimit"),
|
|
53
|
+
...outcome,
|
|
54
|
+
attempts: 0,
|
|
55
|
+
receipt: null,
|
|
56
|
+
worker: null,
|
|
57
|
+
result: null,
|
|
58
|
+
requestedSequence: event.sequence,
|
|
59
|
+
settledSequence: null,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function withoutWaits(operations, event) {
|
|
63
|
+
return Object.fromEntries(Object.entries(operations).map(([operationId, operation]) => [
|
|
64
|
+
operationId,
|
|
65
|
+
operation.runId === event.runId && operation.status === "waiting"
|
|
66
|
+
? cancelledOperation(operation, {
|
|
67
|
+
reason: "budget-exhausted",
|
|
68
|
+
sequence: event.sequence,
|
|
69
|
+
})
|
|
70
|
+
: operation,
|
|
71
|
+
]));
|
|
72
|
+
}
|
|
73
|
+
function admitted(effects, context) {
|
|
74
|
+
const { event, runStatus } = context;
|
|
75
|
+
const operationId = field(event, "operationId");
|
|
76
|
+
const { reason, budget } = authorization(effects.budgets[event.runId], event);
|
|
77
|
+
const budgets = budget === undefined
|
|
78
|
+
? effects.budgets
|
|
79
|
+
: { ...effects.budgets, [event.runId]: budget };
|
|
80
|
+
const remaining = reason === "budget-exhausted"
|
|
81
|
+
? withoutWaits(effects.operations, event)
|
|
82
|
+
: effects.operations;
|
|
83
|
+
const operation = reason === null
|
|
84
|
+
? requestedOperation(event, {
|
|
85
|
+
status: "waiting",
|
|
86
|
+
reason: waitReason(effects, {
|
|
87
|
+
leaseKey: leaseKeyOf(event),
|
|
88
|
+
runStatus,
|
|
89
|
+
}),
|
|
90
|
+
waitSequence: event.sequence,
|
|
91
|
+
})
|
|
92
|
+
: requestedOperation(event, {
|
|
93
|
+
status: "refused",
|
|
94
|
+
reason,
|
|
95
|
+
waitSequence: null,
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
kind: "changed",
|
|
99
|
+
effects: withOperation({ ...effects, budgets, operations: remaining }, operation),
|
|
100
|
+
disposition: {
|
|
101
|
+
operationId,
|
|
102
|
+
disposition: reason === null ? "admitted" : "refused",
|
|
103
|
+
reason,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
export function requested(effects, context) {
|
|
108
|
+
const refused = refusal(context);
|
|
109
|
+
if (refused !== undefined)
|
|
110
|
+
return rejected(refused);
|
|
111
|
+
const { event } = context;
|
|
112
|
+
const operationId = field(event, "operationId");
|
|
113
|
+
const existing = effects.operations[operationId];
|
|
114
|
+
if (existing !== undefined)
|
|
115
|
+
return equalInput(existing, event)
|
|
116
|
+
? {
|
|
117
|
+
kind: "changed",
|
|
118
|
+
effects,
|
|
119
|
+
disposition: { operationId, disposition: "existing", reason: null },
|
|
120
|
+
}
|
|
121
|
+
: rejected("changed-operation-input");
|
|
122
|
+
const denied = denial(effects, event);
|
|
123
|
+
if (denied === undefined)
|
|
124
|
+
return admitted(effects, context);
|
|
125
|
+
return {
|
|
126
|
+
kind: "changed",
|
|
127
|
+
effects,
|
|
128
|
+
disposition: { operationId, disposition: "denied", reason: denied },
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function denial(effects, event) {
|
|
132
|
+
const source = effects.operations[event.payload["source"] ?? ""];
|
|
133
|
+
if (event.payload["source"] === undefined)
|
|
134
|
+
return undefined;
|
|
135
|
+
const lease = source?.runId === event.runId ? ownedLease(effects, source) : undefined;
|
|
136
|
+
if (lease?.generation !== count(event, "sourceGeneration"))
|
|
137
|
+
return "retired-lease-generation";
|
|
138
|
+
return current(lease, event) ? undefined : "lease-expired";
|
|
139
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type EffectContext, type EffectEvent, type EffectResult, type EffectState } from "./operations.ts";
|
|
2
|
+
export declare function reported(effects: EffectState, context: EffectContext): EffectResult;
|
|
3
|
+
export declare function stopReported(effects: EffectState, event: EffectEvent): EffectState;
|
|
4
|
+
export declare function reconciled(effects: EffectState, context: EffectContext): EffectResult;
|