open-multi-agent-kit 1.2.0 → 1.2.3
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/CHANGELOG.md +54 -0
- package/README.md +2 -2
- package/dist/approval-api.d.ts +5 -0
- package/dist/approval-api.d.ts.map +1 -0
- package/dist/approval-api.js +5 -0
- package/dist/approval-api.js.map +1 -0
- package/dist/cli/session-picker.d.ts +2 -2
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/commands/verified-run-cli.d.ts.map +1 -1
- package/dist/commands/verified-run-cli.js +69 -22
- package/dist/commands/verified-run-cli.js.map +1 -1
- package/dist/commands/verified-run-signal.d.ts +3 -0
- package/dist/commands/verified-run-signal.d.ts.map +1 -0
- package/dist/commands/verified-run-signal.js +15 -0
- package/dist/commands/verified-run-signal.js.map +1 -0
- package/dist/coordination/broker.d.ts.map +1 -1
- package/dist/coordination/broker.js +13 -6
- package/dist/coordination/broker.js.map +1 -1
- package/dist/coordination/operation.d.ts +1 -0
- package/dist/coordination/operation.d.ts.map +1 -1
- package/dist/coordination/operation.js +55 -3
- package/dist/coordination/operation.js.map +1 -1
- package/dist/coordination/resource.d.ts +1 -1
- package/dist/coordination/resource.d.ts.map +1 -1
- package/dist/coordination/resource.js +10 -4
- package/dist/coordination/resource.js.map +1 -1
- package/dist/coordination/types.d.ts.map +1 -1
- package/dist/coordination/types.js +1 -1
- package/dist/coordination/types.js.map +1 -1
- package/dist/core/adaptorch-bridge.d.ts +1 -1
- package/dist/core/adaptorch-bridge.d.ts.map +1 -1
- package/dist/core/adaptorch-bridge.js +1 -1
- package/dist/core/adaptorch-bridge.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +16 -16
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +32 -33
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/canonical-json.d.ts +3 -0
- package/dist/core/canonical-json.d.ts.map +1 -0
- package/dist/core/canonical-json.js +20 -0
- package/dist/core/canonical-json.js.map +1 -0
- package/dist/core/compaction/compaction.d.ts +7 -3
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +14 -29
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/fallback.d.ts +16 -5
- package/dist/core/compaction/fallback.d.ts.map +1 -1
- package/dist/core/compaction/fallback.js +4 -3
- package/dist/core/compaction/fallback.js.map +1 -1
- package/dist/core/compaction/model-failover.d.ts +21 -0
- package/dist/core/compaction/model-failover.d.ts.map +1 -0
- package/dist/core/compaction/model-failover.js +46 -0
- package/dist/core/compaction/model-failover.js.map +1 -0
- package/dist/core/compaction/session-summary.d.ts +21 -0
- package/dist/core/compaction/session-summary.d.ts.map +1 -0
- package/dist/core/compaction/session-summary.js +27 -0
- package/dist/core/compaction/session-summary.js.map +1 -0
- package/dist/core/export-html/template.js +14 -0
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/session-lifecycle-types.d.ts +14 -0
- package/dist/core/extensions/session-lifecycle-types.d.ts.map +1 -0
- package/dist/core/extensions/session-lifecycle-types.js +2 -0
- package/dist/core/extensions/session-lifecycle-types.js.map +1 -0
- package/dist/core/extensions/types.d.ts +4 -9
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +10 -1
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +3 -6
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/legacy-resource-policy.d.ts +7 -0
- package/dist/core/legacy-resource-policy.d.ts.map +1 -0
- package/dist/core/legacy-resource-policy.js +9 -0
- package/dist/core/legacy-resource-policy.js.map +1 -0
- package/dist/core/mcp/config.d.ts.map +1 -1
- package/dist/core/mcp/config.js +17 -3
- package/dist/core/mcp/config.js.map +1 -1
- package/dist/core/mcp/connection-queue.d.ts +12 -0
- package/dist/core/mcp/connection-queue.d.ts.map +1 -0
- package/dist/core/mcp/connection-queue.js +46 -0
- package/dist/core/mcp/connection-queue.js.map +1 -0
- package/dist/core/mcp/manager-runtime.d.ts +55 -0
- package/dist/core/mcp/manager-runtime.d.ts.map +1 -0
- package/dist/core/mcp/manager-runtime.js +66 -0
- package/dist/core/mcp/manager-runtime.js.map +1 -0
- package/dist/core/mcp/manager.d.ts +12 -68
- package/dist/core/mcp/manager.d.ts.map +1 -1
- package/dist/core/mcp/manager.js +33 -113
- package/dist/core/mcp/manager.js.map +1 -1
- package/dist/core/mcp/protocol.d.ts.map +1 -1
- package/dist/core/mcp/protocol.js +70 -40
- package/dist/core/mcp/protocol.js.map +1 -1
- package/dist/core/package-manager.d.ts +4 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +59 -129
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/package-resource-patterns.d.ts +7 -0
- package/dist/core/package-resource-patterns.d.ts.map +1 -0
- package/dist/core/package-resource-patterns.js +99 -0
- package/dist/core/package-resource-patterns.js.map +1 -0
- package/dist/core/provider-resilience.d.ts +9 -0
- package/dist/core/provider-resilience.d.ts.map +1 -1
- package/dist/core/provider-resilience.js +15 -0
- package/dist/core/provider-resilience.js.map +1 -1
- package/dist/core/reasoning-router-v4.d.ts +5 -2
- package/dist/core/reasoning-router-v4.d.ts.map +1 -1
- package/dist/core/reasoning-router-v4.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +4 -8
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/run-execution-api.d.ts +8 -1
- package/dist/core/run-execution-api.d.ts.map +1 -1
- package/dist/core/run-execution-api.js +4 -0
- package/dist/core/run-execution-api.js.map +1 -1
- package/dist/core/run-journal.d.ts +1 -2
- package/dist/core/run-journal.d.ts.map +1 -1
- package/dist/core/run-journal.js +2 -19
- package/dist/core/run-journal.js.map +1 -1
- package/dist/core/session-listing.d.ts +51 -0
- package/dist/core/session-listing.d.ts.map +1 -0
- package/dist/core/session-listing.js +111 -0
- package/dist/core/session-listing.js.map +1 -0
- package/dist/core/session-manager.d.ts +12 -37
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +12 -118
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/session-message-text.d.ts +5 -0
- package/dist/core/session-message-text.d.ts.map +1 -0
- package/dist/core/session-message-text.js +9 -0
- package/dist/core/session-message-text.js.map +1 -0
- package/dist/core/skills-catalog-cache.d.ts +2 -0
- package/dist/core/skills-catalog-cache.d.ts.map +1 -1
- package/dist/core/skills-catalog-cache.js +71 -17
- package/dist/core/skills-catalog-cache.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/verified-run/authority-clock.d.ts +3 -0
- package/dist/core/verified-run/authority-clock.d.ts.map +1 -0
- package/dist/core/verified-run/authority-clock.js +25 -0
- package/dist/core/verified-run/authority-clock.js.map +1 -0
- package/dist/core/verified-run/authority-errors.d.ts +10 -0
- package/dist/core/verified-run/authority-errors.d.ts.map +1 -0
- package/dist/core/verified-run/authority-errors.js +17 -0
- package/dist/core/verified-run/authority-errors.js.map +1 -0
- package/dist/core/verified-run/authority-events.d.ts +126 -0
- package/dist/core/verified-run/authority-events.d.ts.map +1 -0
- package/dist/core/verified-run/authority-events.js +482 -0
- package/dist/core/verified-run/authority-events.js.map +1 -0
- package/dist/core/verified-run/authority-journal.d.ts +27 -0
- package/dist/core/verified-run/authority-journal.d.ts.map +1 -0
- package/dist/core/verified-run/authority-journal.js +83 -0
- package/dist/core/verified-run/authority-journal.js.map +1 -0
- package/dist/core/verified-run/authority-meaning.d.ts +13 -0
- package/dist/core/verified-run/authority-meaning.d.ts.map +1 -0
- package/dist/core/verified-run/authority-meaning.js +40 -0
- package/dist/core/verified-run/authority-meaning.js.map +1 -0
- package/dist/core/verified-run/authority-runtime.d.ts +82 -0
- package/dist/core/verified-run/authority-runtime.d.ts.map +1 -0
- package/dist/core/verified-run/authority-runtime.js +169 -0
- package/dist/core/verified-run/authority-runtime.js.map +1 -0
- package/dist/core/verified-run/authority-store.d.ts +204 -0
- package/dist/core/verified-run/authority-store.d.ts.map +1 -0
- package/dist/core/verified-run/authority-store.js +852 -0
- package/dist/core/verified-run/authority-store.js.map +1 -0
- package/dist/core/verified-run/broker.d.ts +8 -1
- package/dist/core/verified-run/broker.d.ts.map +1 -1
- package/dist/core/verified-run/broker.js +94 -90
- package/dist/core/verified-run/broker.js.map +1 -1
- package/dist/core/verified-run/candidate-policy.d.ts +10 -0
- package/dist/core/verified-run/candidate-policy.d.ts.map +1 -0
- package/dist/core/verified-run/candidate-policy.js +33 -0
- package/dist/core/verified-run/candidate-policy.js.map +1 -0
- package/dist/core/verified-run/candidate.d.ts.map +1 -1
- package/dist/core/verified-run/candidate.js +5 -10
- package/dist/core/verified-run/candidate.js.map +1 -1
- package/dist/core/verified-run/coordinator.d.ts +35 -17
- package/dist/core/verified-run/coordinator.d.ts.map +1 -1
- package/dist/core/verified-run/coordinator.js +111 -57
- package/dist/core/verified-run/coordinator.js.map +1 -1
- package/dist/core/verified-run/dag-phase.d.ts.map +1 -1
- package/dist/core/verified-run/dag-phase.js +1 -1
- package/dist/core/verified-run/dag-phase.js.map +1 -1
- package/dist/core/verified-run/dag-recovery.d.ts +5 -1
- package/dist/core/verified-run/dag-recovery.d.ts.map +1 -1
- package/dist/core/verified-run/dag-recovery.js +10 -4
- package/dist/core/verified-run/dag-recovery.js.map +1 -1
- package/dist/core/verified-run/event-parser.d.ts.map +1 -1
- package/dist/core/verified-run/event-parser.js +33 -0
- package/dist/core/verified-run/event-parser.js.map +1 -1
- package/dist/core/verified-run/evidence-read-projection.d.ts +4 -0
- package/dist/core/verified-run/evidence-read-projection.d.ts.map +1 -0
- package/dist/core/verified-run/evidence-read-projection.js +27 -0
- package/dist/core/verified-run/evidence-read-projection.js.map +1 -0
- package/dist/core/verified-run/evidence.d.ts +12 -1
- package/dist/core/verified-run/evidence.d.ts.map +1 -1
- package/dist/core/verified-run/evidence.js +51 -2
- package/dist/core/verified-run/evidence.js.map +1 -1
- package/dist/core/verified-run/git-candidate-preflight.d.ts +4 -0
- package/dist/core/verified-run/git-candidate-preflight.d.ts.map +1 -0
- package/dist/core/verified-run/git-candidate-preflight.js +34 -0
- package/dist/core/verified-run/git-candidate-preflight.js.map +1 -0
- package/dist/core/verified-run/git-effect-supervisor.d.ts +24 -0
- package/dist/core/verified-run/git-effect-supervisor.d.ts.map +1 -0
- package/dist/core/verified-run/git-effect-supervisor.js +174 -0
- package/dist/core/verified-run/git-effect-supervisor.js.map +1 -0
- package/dist/core/verified-run/git-execution.d.ts +27 -0
- package/dist/core/verified-run/git-execution.d.ts.map +1 -0
- package/dist/core/verified-run/git-execution.js +118 -0
- package/dist/core/verified-run/git-execution.js.map +1 -0
- package/dist/core/verified-run/git-plumbing.d.ts +37 -0
- package/dist/core/verified-run/git-plumbing.d.ts.map +1 -0
- package/dist/core/verified-run/git-plumbing.js +171 -0
- package/dist/core/verified-run/git-plumbing.js.map +1 -0
- package/dist/core/verified-run/git-publication-worker.d.ts +2 -0
- package/dist/core/verified-run/git-publication-worker.d.ts.map +1 -0
- package/dist/core/verified-run/git-publication-worker.js +54 -0
- package/dist/core/verified-run/git-publication-worker.js.map +1 -0
- package/dist/core/verified-run/git-sandbox-layout.d.ts +4 -0
- package/dist/core/verified-run/git-sandbox-layout.d.ts.map +1 -0
- package/dist/core/verified-run/git-sandbox-layout.js +29 -0
- package/dist/core/verified-run/git-sandbox-layout.js.map +1 -0
- package/dist/core/verified-run/git-worker-protocol.d.ts +19 -0
- package/dist/core/verified-run/git-worker-protocol.d.ts.map +1 -0
- package/dist/core/verified-run/git-worker-protocol.js +109 -0
- package/dist/core/verified-run/git-worker-protocol.js.map +1 -0
- package/dist/core/verified-run/git-worker-runtime.d.ts +19 -0
- package/dist/core/verified-run/git-worker-runtime.d.ts.map +1 -0
- package/dist/core/verified-run/git-worker-runtime.js +74 -0
- package/dist/core/verified-run/git-worker-runtime.js.map +1 -0
- package/dist/core/verified-run/journal.d.ts +2 -3
- package/dist/core/verified-run/journal.d.ts.map +1 -1
- package/dist/core/verified-run/journal.js.map +1 -1
- package/dist/core/verified-run/namespace-identity.d.ts.map +1 -1
- package/dist/core/verified-run/namespace-identity.js +1 -1
- package/dist/core/verified-run/namespace-identity.js.map +1 -1
- package/dist/core/verified-run/owned-execution.d.ts +10 -1
- package/dist/core/verified-run/owned-execution.d.ts.map +1 -1
- package/dist/core/verified-run/owned-execution.js +124 -31
- package/dist/core/verified-run/owned-execution.js.map +1 -1
- package/dist/core/verified-run/phase-context.d.ts +2 -0
- package/dist/core/verified-run/phase-context.d.ts.map +1 -1
- package/dist/core/verified-run/phase-context.js.map +1 -1
- package/dist/core/verified-run/projection.d.ts.map +1 -1
- package/dist/core/verified-run/projection.js +51 -1
- package/dist/core/verified-run/projection.js.map +1 -1
- package/dist/core/verified-run/publish-preflight.d.ts +12 -0
- package/dist/core/verified-run/publish-preflight.d.ts.map +1 -0
- package/dist/core/verified-run/publish-preflight.js +38 -0
- package/dist/core/verified-run/publish-preflight.js.map +1 -0
- package/dist/core/verified-run/publish-start.d.ts +5 -0
- package/dist/core/verified-run/publish-start.d.ts.map +1 -0
- package/dist/core/verified-run/publish-start.js +7 -0
- package/dist/core/verified-run/publish-start.js.map +1 -0
- package/dist/core/verified-run/recovery-projection.d.ts.map +1 -1
- package/dist/core/verified-run/recovery-projection.js +5 -0
- package/dist/core/verified-run/recovery-projection.js.map +1 -1
- package/dist/core/verified-run/recovery.d.ts +5 -1
- package/dist/core/verified-run/recovery.d.ts.map +1 -1
- package/dist/core/verified-run/recovery.js +10 -4
- package/dist/core/verified-run/recovery.js.map +1 -1
- package/dist/core/verified-run/run-plan.d.ts +17 -0
- package/dist/core/verified-run/run-plan.d.ts.map +1 -0
- package/dist/core/verified-run/run-plan.js +18 -0
- package/dist/core/verified-run/run-plan.js.map +1 -0
- package/dist/core/verified-run/run-publish-owned.d.ts +6 -0
- package/dist/core/verified-run/run-publish-owned.d.ts.map +1 -0
- package/dist/core/verified-run/run-publish-owned.js +199 -0
- package/dist/core/verified-run/run-publish-owned.js.map +1 -0
- package/dist/core/verified-run/run-publish.d.ts +19 -0
- package/dist/core/verified-run/run-publish.d.ts.map +1 -0
- package/dist/core/verified-run/run-publish.js +210 -0
- package/dist/core/verified-run/run-publish.js.map +1 -0
- package/dist/core/verified-run/run-status-owned.d.ts +4 -0
- package/dist/core/verified-run/run-status-owned.d.ts.map +1 -0
- package/dist/core/verified-run/run-status-owned.js +14 -0
- package/dist/core/verified-run/run-status-owned.js.map +1 -0
- package/dist/core/verified-run/run-status.d.ts +133 -0
- package/dist/core/verified-run/run-status.d.ts.map +1 -0
- package/dist/core/verified-run/run-status.js +193 -0
- package/dist/core/verified-run/run-status.js.map +1 -0
- package/dist/core/verified-run/run-types.d.ts +31 -0
- package/dist/core/verified-run/run-types.d.ts.map +1 -1
- package/dist/core/verified-run/run-types.js.map +1 -1
- package/dist/core/verified-run/storage.d.ts.map +1 -1
- package/dist/core/verified-run/storage.js +1 -1
- package/dist/core/verified-run/storage.js.map +1 -1
- package/dist/core/verified-run/supervisor-adapter.d.ts +81 -0
- package/dist/core/verified-run/supervisor-adapter.d.ts.map +1 -0
- package/dist/core/verified-run/supervisor-adapter.js +168 -0
- package/dist/core/verified-run/supervisor-adapter.js.map +1 -0
- package/dist/core/verified-run/verification-phase.d.ts.map +1 -1
- package/dist/core/verified-run/verification-phase.js +1 -1
- package/dist/core/verified-run/verification-phase.js.map +1 -1
- package/dist/core/verified-run/writer-phase.d.ts.map +1 -1
- package/dist/core/verified-run/writer-phase.js +1 -0
- package/dist/core/verified-run/writer-phase.js.map +1 -1
- package/dist/core/verified-run/writer-recovery.d.ts +2 -0
- package/dist/core/verified-run/writer-recovery.d.ts.map +1 -1
- package/dist/core/verified-run/writer-recovery.js +1 -0
- package/dist/core/verified-run/writer-recovery.js.map +1 -1
- package/dist/core/workload-shard-execution-types.d.ts +4 -1
- package/dist/core/workload-shard-execution-types.d.ts.map +1 -1
- package/dist/core/workload-shard-execution-types.js.map +1 -1
- package/dist/core/workload-shard-executor.d.ts +2 -2
- package/dist/core/workload-shard-executor.d.ts.map +1 -1
- package/dist/core/workload-shard-executor.js +16 -37
- package/dist/core/workload-shard-executor.js.map +1 -1
- package/dist/core/workload-shard-frontier.d.ts +5 -0
- package/dist/core/workload-shard-frontier.d.ts.map +1 -0
- package/dist/core/workload-shard-frontier.js +47 -0
- package/dist/core/workload-shard-frontier.js.map +1 -0
- package/dist/core/workload-shard-runner.d.ts.map +1 -1
- package/dist/core/workload-shard-runner.js +28 -17
- package/dist/core/workload-shard-runner.js.map +1 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +2 -1
- package/dist/main.js.map +1 -1
- package/dist/metacognition/bridge-result.d.ts +148 -0
- package/dist/metacognition/bridge-result.d.ts.map +1 -0
- package/dist/metacognition/bridge-result.js +46 -0
- package/dist/metacognition/bridge-result.js.map +1 -0
- package/dist/metacognition/calibration-selective.d.ts.map +1 -1
- package/dist/metacognition/calibration-selective.js +8 -2
- package/dist/metacognition/calibration-selective.js.map +1 -1
- package/dist/metacognition/index.d.ts +1 -0
- package/dist/metacognition/index.d.ts.map +1 -1
- package/dist/metacognition/index.js +1 -0
- package/dist/metacognition/index.js.map +1 -1
- package/dist/metacognition/risk.d.ts.map +1 -1
- package/dist/metacognition/risk.js +28 -14
- package/dist/metacognition/risk.js.map +1 -1
- package/dist/metacognition/runtime-bridge.d.ts +41 -14
- package/dist/metacognition/runtime-bridge.d.ts.map +1 -1
- package/dist/metacognition/runtime-bridge.js +357 -39
- package/dist/metacognition/runtime-bridge.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +2 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +42 -26
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/chat-container.d.ts +7 -0
- package/dist/modes/interactive/components/chat-container.d.ts.map +1 -0
- package/dist/modes/interactive/components/chat-container.js +14 -0
- package/dist/modes/interactive/components/chat-container.js.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.js +4 -2
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +0 -1
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-async-search.d.ts +33 -0
- package/dist/modes/interactive/components/session-selector-async-search.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-async-search.js +109 -0
- package/dist/modes/interactive/components/session-selector-async-search.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-loaders.d.ts +6 -0
- package/dist/modes/interactive/components/session-selector-loaders.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-loaders.js +9 -0
- package/dist/modes/interactive/components/session-selector-loaders.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts +1 -1
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-tree.d.ts +16 -0
- package/dist/modes/interactive/components/session-selector-tree.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-tree.js +46 -0
- package/dist/modes/interactive/components/session-selector-tree.js.map +1 -0
- package/dist/modes/interactive/components/session-selector.d.ts +6 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +36 -76
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution-images.d.ts +32 -0
- package/dist/modes/interactive/components/tool-execution-images.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-execution-images.js +144 -0
- package/dist/modes/interactive/components/tool-execution-images.js.map +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +3 -4
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +22 -71
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +7 -9
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/tui-diagnostics.d.ts +8 -4
- package/dist/modes/interactive/tui-diagnostics.d.ts.map +1 -1
- package/dist/modes/interactive/tui-diagnostics.js +35 -1
- package/dist/modes/interactive/tui-diagnostics.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +14 -17
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-response.d.ts +5 -0
- package/dist/modes/rpc/rpc-response.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-response.js +17 -0
- package/dist/modes/rpc/rpc-response.js.map +1 -0
- package/dist/utils/exif-orientation.d.ts.map +1 -1
- package/dist/utils/exif-orientation.js +2 -3
- package/dist/utils/exif-orientation.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +3 -5
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/adaptorch-preview-spec.md +7 -7
- package/docs/atomic-commit-planning.md +69 -0
- package/docs/compaction.md +26 -1
- package/docs/extensions.md +14 -0
- package/docs/mcp.md +22 -0
- package/docs/metacognition.md +79 -0
- package/docs/model-catalog-refresh.md +159 -1
- package/docs/models.md +1 -1
- package/docs/runtime-algorithms.md +49 -4
- package/docs/session-format.md +8 -0
- package/docs/sessions.md +19 -0
- package/docs/skills.md +19 -0
- package/docs/terminal-setup.md +15 -0
- package/docs/tui.md +41 -0
- package/docs/verified-run-safety.md +75 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/doom-overlay/wad-finder.ts +7 -3
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +18 -18
- package/package.json +6 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recovery-projection.js","sourceRoot":"","sources":["../../../src/core/verified-run/recovery-projection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAI9D,8FAA8F;AAC9F,MAAM,UAAU,mBAAmB,CAClC,OAAwB,EACxB,KAAoB,EACpB,QAIC,EACM;IACP,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC5B,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IAC9B,IAAI,CAAC,KAAK,CAAC,MAAM;QAAE,MAAM,IAAI,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;IACpE,IAAI,KAAK,CAA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I;QACb,WAAW,EAAE,KAAK,CAAC,UAAU;KAC7B,CAAC;AAAA,CACF","sourcesContent":["import { MAX_VERIFIED_RUN_GENERATIONS } from \"omk-protocol\";\nimport { retryTaskProjection } from \"./dag-retry-projection.ts\";\nimport type { RunEvent, WriterReduction } from \"./run-types.ts\";\nimport { digestObject, VerifiedRunError } from \"./storage.ts\";\n\ntype RecoveryEvent = Extract<RunEvent, { kind: \"resumed\" | \"writer_restarted\" | \"tasks_retried\" }>;\n\n/** Shared generation/command fence; only the writer variant resets attempt-local progress. */\nexport function reduceRecoveryEvent(\n\tcontext: WriterReduction,\n\tevent: RecoveryEvent,\n\tprogress: {\n\t\treadonly commands: Set<string>;\n\t\treadonly checked: Set<string>;\n\t\treadonly activeRole: \"writer\" | \"verifier\";\n\t},\n): void {\n\tconst state = context.state;\n\tconst command = event.command;\n\tif (!state.budget) throw new VerifiedRunError(\"resume_unavailable\");\n\tif (state.generation >= MAX_VERIFIED_RUN_GENERATIONS) throw new VerifiedRunError(\"recovery_limit\");\n\tif (command.expectedRevision !== state.revision || command.expectedGeneration !== state.generation)\n\t\tthrow new VerifiedRunError(\"stale_revision\");\n\tif (\n\t\tcommand.runId !== state.runId ||\n\t\tcommand.contractDigest !== digestObject(context.contract) ||\n\t\tprogress.commands.has(command.commandId)\n\t)\n\t\tthrow new VerifiedRunError(\"command_conflict\");\n\tif (\n\t\tevent.reconciledExecutionIds.length !== state.activeExecutionIds.length ||\n\t\tevent.reconciledExecutionIds.some((id, index) => id !== state.activeExecutionIds[index])\n\t)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tlet deadline: number;\n\tlet tasks = state.tasks;\n\tswitch (event.kind) {\n\t\tcase \"resumed\":\n\t\t\tif (\n\t\t\t\t!state.candidateDigest ||\n\t\t\t\tstate.writerOpen ||\n\t\t\t\tstate.verificationDeadlineMs === null ||\n\t\t\t\tevent.command.candidateDigest !== state.candidateDigest\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"resume_unavailable\");\n\t\t\tif (state.activeExecutionIds.length && progress.activeRole !== \"verifier\")\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tdeadline = state.verificationDeadlineMs;\n\t\t\tbreak;\n\t\tcase \"tasks_retried\":\n\t\t\tif (state.activeExecutionIds.length && progress.activeRole !== \"writer\")\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\ttasks = retryTaskProjection(context, event);\n\t\t\tdeadline = state.budget.workDeadlineMs;\n\t\t\tcontext.writerStarted = false;\n\t\t\tcontext.writerFinished = tasks.every((task) => task.status === \"succeeded\");\n\t\t\tcontext.producerStarted = false;\n\t\t\tcontext.writerCommands = 0;\n\t\t\tcontext.requestBaseline = state.modelRequests;\n\t\t\tbreak;\n\t\tcase \"writer_restarted\":\n\t\t\tif (context.contract.profile === \"linux-command-dag-v1\") throw new VerifiedRunError(\"task_recovery_required\");\n\t\t\tif (\n\t\t\t\t!state.inputDigest ||\n\t\t\t\tstate.candidateDigest ||\n\t\t\t\tevent.command.baseDigest !== state.inputDigest ||\n\t\t\t\tstate.inputDigest !== context.contract.workspace.baseDigest\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"input_checkpoint_missing\");\n\t\t\tif (state.activeExecutionIds.length && progress.activeRole !== \"writer\")\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tif (\n\t\t\t\tcontext.contract.profile === \"linux-scripted-agent-v1\" &&\n\t\t\t\tcontext.contract.writer.maxRequests - state.modelRequests < context.contract.writer.steps.length + 1\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"model_request_limit\");\n\t\t\tdeadline = state.budget.workDeadlineMs;\n\t\t\tcontext.writerStarted = false;\n\t\t\tcontext.writerFinished = false;\n\t\t\tcontext.producerStarted = false;\n\t\t\tcontext.writerCommands = 0;\n\t\t\tcontext.requestBaseline = state.modelRequests;\n\t\t\tbreak;\n\t\tdefault: {\n\t\t\tconst exhaustive: never = event;\n\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t}\n\t}\n\tif (event.observedMs < (state.lastClockMs ?? state.budget.startedMs) || event.observedMs >= deadline)\n\t\tthrow new VerifiedRunError(\"deadline\");\n\tprogress.commands.add(command.commandId);\n\tprogress.checked.clear();\n\tcontext.state = {\n\t\t...state,\n\t\tgeneration: state.generation + 1,\n\t\ttasks,\n\t\texecution: \"running\",\n\t\tsettlement: \"settled\",\n\t\tverification: \"not_requested\",\n\t\twriterOpen: false,\n\t\tactiveExecutionIds: [],\n\t\tprocesses: [],\n\t\tfailure: null,\n\t\tlastClockMs: event.observedMs,\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"recovery-projection.js","sourceRoot":"","sources":["../../../src/core/verified-run/recovery-projection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAI9D,8FAA8F;AAC9F,MAAM,UAAU,mBAAmB,CAClC,OAAwB,EACxB,KAAoB,EACpB,QAIC,EACM;IACP,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC5B,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;IAC9B,IAAI,CAAC,KAAK,CAAC,MAAM;QAAE,MAAM,IAAI,gBAAgB,CAAC,oBAAoB,CAAC,CAAC;IACpE,IAAI,KAAK,CAAC,UAAU,IAAI,4BAA4B;QAAE,MAAM,IAAI,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IACnG,IAAI,OAAO,CAAC,gBAAgB,KAAK,KAAK,CAAC,QAAQ,IAAI,OAAO,CAAC,kBAAkB,KAAK,KAAK,CAAC,UAAU;QACjG,MAAM,IAAI,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IAC9C,IACC,OAAO,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK;Q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\";\nimport type { RunEvent, WriterReduction } from \"./run-types.ts\";\nimport { digestObject, VerifiedRunError } from \"./storage.ts\";\n\ntype RecoveryEvent = Extract<RunEvent, { kind: \"resumed\" | \"writer_restarted\" | \"tasks_retried\" }>;\n\n/** Shared generation/command fence; only the writer variant resets attempt-local progress. */\nexport function reduceRecoveryEvent(\n\tcontext: WriterReduction,\n\tevent: RecoveryEvent,\n\tprogress: {\n\t\treadonly commands: Set<string>;\n\t\treadonly checked: Set<string>;\n\t\treadonly activeRole: \"writer\" | \"verifier\";\n\t},\n): void {\n\tconst state = context.state;\n\tconst command = event.command;\n\tif (!state.budget) throw new VerifiedRunError(\"resume_unavailable\");\n\tif (state.generation >= MAX_VERIFIED_RUN_GENERATIONS) throw new VerifiedRunError(\"recovery_limit\");\n\tif (command.expectedRevision !== state.revision || command.expectedGeneration !== state.generation)\n\t\tthrow new VerifiedRunError(\"stale_revision\");\n\tif (\n\t\tcommand.runId !== state.runId ||\n\t\tcommand.contractDigest !== digestObject(context.contract) ||\n\t\tprogress.commands.has(command.commandId)\n\t)\n\t\tthrow new VerifiedRunError(\"command_conflict\");\n\tif (\n\t\tevent.reconciledExecutionIds.length !== state.activeExecutionIds.length ||\n\t\tevent.reconciledExecutionIds.some((id, index) => id !== state.activeExecutionIds[index])\n\t)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tlet deadline: number;\n\tlet tasks = state.tasks;\n\tswitch (event.kind) {\n\t\tcase \"resumed\":\n\t\t\tif (\n\t\t\t\t!state.candidateDigest ||\n\t\t\t\tstate.writerOpen ||\n\t\t\t\tstate.verificationDeadlineMs === null ||\n\t\t\t\tevent.command.candidateDigest !== state.candidateDigest\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"resume_unavailable\");\n\t\t\tif (state.activeExecutionIds.length && progress.activeRole !== \"verifier\")\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tdeadline = state.verificationDeadlineMs;\n\t\t\tbreak;\n\t\tcase \"tasks_retried\":\n\t\t\tif (state.activeExecutionIds.length && progress.activeRole !== \"writer\")\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\ttasks = retryTaskProjection(context, event);\n\t\t\tdeadline = state.budget.workDeadlineMs;\n\t\t\tcontext.writerStarted = false;\n\t\t\tcontext.writerFinished = tasks.every((task) => task.status === \"succeeded\");\n\t\t\tcontext.producerStarted = false;\n\t\t\tcontext.writerCommands = 0;\n\t\t\tcontext.requestBaseline = state.modelRequests;\n\t\t\tbreak;\n\t\tcase \"writer_restarted\":\n\t\t\tif (context.contract.profile === \"linux-command-dag-v1\") throw new VerifiedRunError(\"task_recovery_required\");\n\t\t\tif (\n\t\t\t\t!state.inputDigest ||\n\t\t\t\tstate.candidateDigest ||\n\t\t\t\tevent.command.baseDigest !== state.inputDigest ||\n\t\t\t\tstate.inputDigest !== context.contract.workspace.baseDigest\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"input_checkpoint_missing\");\n\t\t\tif (state.activeExecutionIds.length && progress.activeRole !== \"writer\")\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tif (\n\t\t\t\tcontext.contract.profile === \"linux-scripted-agent-v1\" &&\n\t\t\t\tcontext.contract.writer.maxRequests - state.modelRequests < context.contract.writer.steps.length + 1\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"model_request_limit\");\n\t\t\tdeadline = state.budget.workDeadlineMs;\n\t\t\tcontext.writerStarted = false;\n\t\t\tcontext.writerFinished = false;\n\t\t\tcontext.producerStarted = false;\n\t\t\tcontext.writerCommands = 0;\n\t\t\tcontext.requestBaseline = state.modelRequests;\n\t\t\tbreak;\n\t\tdefault: {\n\t\t\tconst exhaustive: never = event;\n\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t}\n\t}\n\tif (event.observedMs < (state.lastClockMs ?? state.budget.startedMs) || event.observedMs >= deadline)\n\t\tthrow new VerifiedRunError(\"deadline\");\n\tprogress.commands.add(command.commandId);\n\tprogress.checked.clear();\n\tcontext.state = {\n\t\t...state,\n\t\tgeneration: state.generation + 1,\n\t\ttasks,\n\t\texecution: \"running\",\n\t\tsettlement: \"settled\",\n\t\tverification: \"not_requested\",\n\t\twriterOpen: false,\n\t\tactiveExecutionIds: [],\n\t\tprocesses: [],\n\t\tfailure: null,\n\t\tlastRecovery: {\n\t\t\tkind: event.kind,\n\t\t\tcommandId: command.commandId,\n\t\t\tgeneration: state.generation + 1,\n\t\t},\n\t\tlastClockMs: event.observedMs,\n\t};\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type RunResumeCommand } from "omk-protocol";
|
|
2
|
+
import type { RunAuthority } from "./authority-runtime.ts";
|
|
2
3
|
import type { RunProjection } from "./run-types.ts";
|
|
3
4
|
export interface RecoveryInspection {
|
|
4
5
|
readonly state: RunProjection;
|
|
@@ -8,5 +9,8 @@ export interface RecoveryInspection {
|
|
|
8
9
|
readonly ownership: "lease_required";
|
|
9
10
|
}
|
|
10
11
|
export declare function inspectRunRecovery(runPath: string): RecoveryInspection;
|
|
11
|
-
export declare function resumeFrozenCandidate(runPath: string, command: RunResumeCommand,
|
|
12
|
+
export declare function resumeFrozenCandidate(runPath: string, command: RunResumeCommand, options: {
|
|
13
|
+
readonly signal?: AbortSignal;
|
|
14
|
+
readonly authority: RunAuthority;
|
|
15
|
+
}): Promise<RunProjection>;
|
|
12
16
|
//# sourceMappingURL=recovery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/recovery.ts"],"names":[],"mappings":"AACA,OAAO,EAAgC,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/recovery.ts"],"names":[],"mappings":"AACA,OAAO,EAAgC,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAQ3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAIpD,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,SAAS,EACf,OAAO,GACP,UAAU,GACV,QAAQ,GACR,mBAAmB,GACnB,WAAW,GACX,SAAS,GACT,eAAe,GACf,gBAAgB,GAChB,mBAAmB,GACnB,gBAAgB,GAChB,WAAW,CAAC;IACf,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,sFAAsF;IACtF,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC;CACrC;AAsCD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,CA0CtE;AAED,wBAAsB,qBAAqB,CAC1C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAA;CAAE,GAC1E,OAAO,CAAC,aAAa,CAAC,CAwBxB","sourcesContent":["import { join } from \"node:path\";\nimport { MAX_VERIFIED_RUN_GENERATIONS, type RunResumeCommand } from \"omk-protocol\";\nimport type { RunAuthority } from \"./authority-runtime.ts\";\nimport { commandEnvironmentDigest, probeVerifiedSandbox } from \"./broker.ts\";\nimport { loadCandidate } from \"./candidate.ts\";\nimport { preflightCheckReceipts } from \"./check-receipt.ts\";\nimport type { JournalSnapshot } from \"./journal.ts\";\nimport { probeNamespace } from \"./namespace-identity.ts\";\nimport { readRunClock, remainingVerification } from \"./recovery-clock.ts\";\nimport { requireRunJournal, withRecoveryLease } from \"./recovery-command.ts\";\nimport type { RunProjection } from \"./run-types.ts\";\nimport { readRegularFile, VerifiedRunError } from \"./storage.ts\";\nimport { verifyCandidate } from \"./verification-phase.ts\";\n\nexport interface RecoveryInspection {\n\treadonly state: RunProjection;\n\treadonly readiness:\n\t\t| \"ready\"\n\t\t| \"terminal\"\n\t\t| \"legacy\"\n\t\t| \"candidate_missing\"\n\t\t| \"unsettled\"\n\t\t| \"expired\"\n\t\t| \"clock_changed\"\n\t\t| \"clock_rollback\"\n\t\t| \"clock_unavailable\"\n\t\t| \"recovery_limit\"\n\t\t| \"integrity\";\n\treadonly remainingVerifyMs: number | null;\n\t/** A ready inspection is advisory; exclusive ownership is acquired only by resume. */\n\treadonly ownership: \"lease_required\";\n}\n\nfunction assertCandidateRecoverable(runPath: string, journal: JournalSnapshot): number {\n\tconst state = journal.state;\n\tif (state.receiptDigest || state.execution === \"failed\") throw new VerifiedRunError(\"resume_terminal\");\n\tif (!state.budget || !state.environmentDigest) throw new VerifiedRunError(\"recovery_legacy\");\n\tif (!state.candidateDigest || state.writerOpen || state.verificationDeadlineMs === null)\n\t\tthrow new VerifiedRunError(\"candidate_missing\");\n\tif (state.generation >= MAX_VERIFIED_RUN_GENERATIONS) throw new VerifiedRunError(\"recovery_limit\");\n\tconst clock = readRunClock();\n\tconst remaining = remainingVerification(state.budget, state.verificationDeadlineMs, clock);\n\tif (clock.nowMs < (state.lastClockMs ?? state.budget.startedMs)) throw new VerifiedRunError(\"clock_rollback\");\n\tif (remaining <= 0) throw new VerifiedRunError(\"deadline\");\n\tfor (const id of state.activeExecutionIds) {\n\t\tconst dispatch = journal.records.find(\n\t\t\t(record) =>\n\t\t\t\trecord.generation === state.generation &&\n\t\t\t\trecord.event.kind === \"dispatch\" &&\n\t\t\t\trecord.event.executionId === id,\n\t\t)?.event;\n\t\tconst identity = state.processes.find((process) => process.executionId === id)?.identity;\n\t\tif (\n\t\t\tdispatch?.kind !== \"dispatch\" ||\n\t\t\tdispatch.role !== \"verifier\" ||\n\t\t\t!identity ||\n\t\t\tprobeNamespace(identity) !== \"gone\"\n\t\t)\n\t\t\tthrow new VerifiedRunError(\"unsettled\");\n\t}\n\tconst first = journal.records[0]?.event;\n\tif (first?.kind !== \"created\") throw new VerifiedRunError(\"integrity\");\n\tif (readRegularFile(join(runPath, \"issuer.key\"), 32).length !== 32) throw new VerifiedRunError(\"integrity\");\n\tloadCandidate(runPath, state.candidateDigest, first.contract.budget);\n\tif (commandEnvironmentDigest(first.contract, \"gated-v1\") !== state.environmentDigest)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\treturn remaining;\n}\n\nexport function inspectRunRecovery(runPath: string): RecoveryInspection {\n\tconst journal = requireRunJournal(runPath);\n\tlet readiness: RecoveryInspection[\"readiness\"] = \"ready\";\n\tlet remainingVerifyMs: number | null = null;\n\ttry {\n\t\tremainingVerifyMs = assertCandidateRecoverable(runPath, journal);\n\t} catch (error) {\n\t\tif (!(error instanceof Error)) throw error;\n\t\tswitch (error instanceof VerifiedRunError ? error.code : \"integrity\") {\n\t\t\tcase \"resume_terminal\":\n\t\t\t\treadiness = \"terminal\";\n\t\t\t\tbreak;\n\t\t\tcase \"recovery_legacy\":\n\t\t\t\treadiness = \"legacy\";\n\t\t\t\tbreak;\n\t\t\tcase \"deadline\":\n\t\t\t\treadiness = \"expired\";\n\t\t\t\tremainingVerifyMs = 0;\n\t\t\t\tbreak;\n\t\t\tcase \"candidate_missing\":\n\t\t\t\treadiness = \"candidate_missing\";\n\t\t\t\tbreak;\n\t\t\tcase \"unsettled\":\n\t\t\t\treadiness = \"unsettled\";\n\t\t\t\tbreak;\n\t\t\tcase \"clock_changed\":\n\t\t\t\treadiness = \"clock_changed\";\n\t\t\t\tbreak;\n\t\t\tcase \"clock_rollback\":\n\t\t\t\treadiness = \"clock_rollback\";\n\t\t\t\tbreak;\n\t\t\tcase \"clock_unavailable\":\n\t\t\t\treadiness = \"clock_unavailable\";\n\t\t\t\tbreak;\n\t\t\tcase \"recovery_limit\":\n\t\t\t\treadiness = \"recovery_limit\";\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\treadiness = \"integrity\";\n\t\t}\n\t}\n\treturn Object.freeze({ state: journal.state, readiness, remainingVerifyMs, ownership: \"lease_required\" });\n}\n\nexport async function resumeFrozenCandidate(\n\trunPath: string,\n\tcommand: RunResumeCommand,\n\toptions: { readonly signal?: AbortSignal; readonly authority: RunAuthority },\n): Promise<RunProjection> {\n\tif (options.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\treturn withRecoveryLease(runPath, command, async ({ snapshot, journal }) => {\n\t\tassertCandidateRecoverable(runPath, snapshot);\n\t\tconst first = snapshot.records[0]?.event;\n\t\tif (first?.kind !== \"created\") throw new VerifiedRunError(\"integrity\");\n\t\tpreflightCheckReceipts(first.contract);\n\t\tprobeVerifiedSandbox();\n\t\tassertCandidateRecoverable(runPath, snapshot);\n\t\tif (options.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\t\tjournal.append({\n\t\t\tkind: \"resumed\",\n\t\t\tcommand,\n\t\t\tobservedMs: readRunClock().nowMs,\n\t\t\treconciledExecutionIds: snapshot.state.activeExecutionIds,\n\t\t});\n\t\treturn verifyCandidate({\n\t\t\trunPath,\n\t\t\tjournal,\n\t\t\tcontract: first.contract,\n\t\t\tauthority: options.authority,\n\t\t\t...(options.signal ? { signal: options.signal } : {}),\n\t\t});\n\t});\n}\n"]}
|
|
@@ -90,8 +90,8 @@ export function inspectRunRecovery(runPath) {
|
|
|
90
90
|
}
|
|
91
91
|
return Object.freeze({ state: journal.state, readiness, remainingVerifyMs, ownership: "lease_required" });
|
|
92
92
|
}
|
|
93
|
-
export async function resumeFrozenCandidate(runPath, command,
|
|
94
|
-
if (signal?.aborted)
|
|
93
|
+
export async function resumeFrozenCandidate(runPath, command, options) {
|
|
94
|
+
if (options.signal?.aborted)
|
|
95
95
|
throw new VerifiedRunError("cancelled");
|
|
96
96
|
return withRecoveryLease(runPath, command, async ({ snapshot, journal }) => {
|
|
97
97
|
assertCandidateRecoverable(runPath, snapshot);
|
|
@@ -101,7 +101,7 @@ export async function resumeFrozenCandidate(runPath, command, signal) {
|
|
|
101
101
|
preflightCheckReceipts(first.contract);
|
|
102
102
|
probeVerifiedSandbox();
|
|
103
103
|
assertCandidateRecoverable(runPath, snapshot);
|
|
104
|
-
if (signal?.aborted)
|
|
104
|
+
if (options.signal?.aborted)
|
|
105
105
|
throw new VerifiedRunError("cancelled");
|
|
106
106
|
journal.append({
|
|
107
107
|
kind: "resumed",
|
|
@@ -109,7 +109,13 @@ export async function resumeFrozenCandidate(runPath, command, signal) {
|
|
|
109
109
|
observedMs: readRunClock().nowMs,
|
|
110
110
|
reconciledExecutionIds: snapshot.state.activeExecutionIds,
|
|
111
111
|
});
|
|
112
|
-
return verifyCandidate({
|
|
112
|
+
return verifyCandidate({
|
|
113
|
+
runPath,
|
|
114
|
+
journal,
|
|
115
|
+
contract: first.contract,
|
|
116
|
+
authority: options.authority,
|
|
117
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
118
|
+
});
|
|
113
119
|
});
|
|
114
120
|
}
|
|
115
121
|
//# sourceMappingURL=recovery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recovery.js","sourceRoot":"","sources":["../../../src/core/verified-run/recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,4BAA4B,EAAyB,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC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K;IACzB,IAAI,MAAM,EAAE,OAAO;QAAE,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;IAC7D,OAAO,iBAAiB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;QAC3E,0BAA0B,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC9C,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC;QACzC,IAAI,KAAK,EAAE,IAAI,KAAK,SAAS;YAAE,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;QACvE,sBAAsB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACvC,oBAAoB,EAAE,CAAC;QACvB,0BAA0B,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QAC9C,IAAI,MAAM,EAAE,OAAO;YAAE,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;QAC7D,OAAO,CAAC,MAAM,CAAC;YACd,IAAI,EAAE,SAAS;YACf,OAAO;YACP,UAAU,EAAE,YAAY,EAAE,CAAC,KAAK;YAChC,sBAAsB,EAAE,QAAQ,CAAC,KAAK,CAAC,kBAAkB;SACzD,CAAC,CAAC;QACH,OAAO,eAAe,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAAA,CACtG,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { join } from \"node:path\";\nimport { MAX_VERIFIED_RUN_GENERATIONS, type RunResumeCommand } from \"omk-protocol\";\nimport { commandEnvironmentDigest, probeVerifiedSandbox } from \"./broker.ts\";\nimport { loadCandidate } from \"./candidate.ts\";\nimport { preflightCheckReceipts } from \"./check-receipt.ts\";\nimport type { JournalSnapshot } from \"./journal.ts\";\nimport { probeNamespace } from \"./namespace-identity.ts\";\nimport { readRunClock, remainingVerification } from \"./recovery-clock.ts\";\nimport { requireRunJournal, withRecoveryLease } from \"./recovery-command.ts\";\nimport type { RunProjection } from \"./run-types.ts\";\nimport { readRegularFile, VerifiedRunError } from \"./storage.ts\";\nimport { verifyCandidate } from \"./verification-phase.ts\";\n\nexport interface RecoveryInspection {\n\treadonly state: RunProjection;\n\treadonly readiness:\n\t\t| \"ready\"\n\t\t| \"terminal\"\n\t\t| \"legacy\"\n\t\t| \"candidate_missing\"\n\t\t| \"unsettled\"\n\t\t| \"expired\"\n\t\t| \"clock_changed\"\n\t\t| \"clock_rollback\"\n\t\t| \"clock_unavailable\"\n\t\t| \"recovery_limit\"\n\t\t| \"integrity\";\n\treadonly remainingVerifyMs: number | null;\n\t/** A ready inspection is advisory; exclusive ownership is acquired only by resume. */\n\treadonly ownership: \"lease_required\";\n}\n\nfunction assertCandidateRecoverable(runPath: string, journal: JournalSnapshot): number {\n\tconst state = journal.state;\n\tif (state.receiptDigest || state.execution === \"failed\") throw new VerifiedRunError(\"resume_terminal\");\n\tif (!state.budget || !state.environmentDigest) throw new VerifiedRunError(\"recovery_legacy\");\n\tif (!state.candidateDigest || state.writerOpen || state.verificationDeadlineMs === null)\n\t\tthrow new VerifiedRunError(\"candidate_missing\");\n\tif (state.generation >= MAX_VERIFIED_RUN_GENERATIONS) throw new VerifiedRunError(\"recovery_limit\");\n\tconst clock = readRunClock();\n\tconst remaining = remainingVerification(state.budget, state.verificationDeadlineMs, clock);\n\tif (clock.nowMs < (state.lastClockMs ?? state.budget.startedMs)) throw new VerifiedRunError(\"clock_rollback\");\n\tif (remaining <= 0) throw new VerifiedRunError(\"deadline\");\n\tfor (const id of state.activeExecutionIds) {\n\t\tconst dispatch = journal.records.find(\n\t\t\t(record) =>\n\t\t\t\trecord.generation === state.generation &&\n\t\t\t\trecord.event.kind === \"dispatch\" &&\n\t\t\t\trecord.event.executionId === id,\n\t\t)?.event;\n\t\tconst identity = state.processes.find((process) => process.executionId === id)?.identity;\n\t\tif (\n\t\t\tdispatch?.kind !== \"dispatch\" ||\n\t\t\tdispatch.role !== \"verifier\" ||\n\t\t\t!identity ||\n\t\t\tprobeNamespace(identity) !== \"gone\"\n\t\t)\n\t\t\tthrow new VerifiedRunError(\"unsettled\");\n\t}\n\tconst first = journal.records[0]?.event;\n\tif (first?.kind !== \"created\") throw new VerifiedRunError(\"integrity\");\n\tif (readRegularFile(join(runPath, \"issuer.key\"), 32).length !== 32) throw new VerifiedRunError(\"integrity\");\n\tloadCandidate(runPath, state.candidateDigest, first.contract.budget);\n\tif (commandEnvironmentDigest(first.contract, \"gated-v1\") !== state.environmentDigest)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\treturn remaining;\n}\n\nexport function inspectRunRecovery(runPath: string): RecoveryInspection {\n\tconst journal = requireRunJournal(runPath);\n\tlet readiness: RecoveryInspection[\"readiness\"] = \"ready\";\n\tlet remainingVerifyMs: number | null = null;\n\ttry {\n\t\tremainingVerifyMs = assertCandidateRecoverable(runPath, journal);\n\t} catch (error) {\n\t\tif (!(error instanceof Error)) throw error;\n\t\tswitch (error instanceof VerifiedRunError ? error.code : \"integrity\") {\n\t\t\tcase \"resume_terminal\":\n\t\t\t\treadiness = \"terminal\";\n\t\t\t\tbreak;\n\t\t\tcase \"recovery_legacy\":\n\t\t\t\treadiness = \"legacy\";\n\t\t\t\tbreak;\n\t\t\tcase \"deadline\":\n\t\t\t\treadiness = \"expired\";\n\t\t\t\tremainingVerifyMs = 0;\n\t\t\t\tbreak;\n\t\t\tcase \"candidate_missing\":\n\t\t\t\treadiness = \"candidate_missing\";\n\t\t\t\tbreak;\n\t\t\tcase \"unsettled\":\n\t\t\t\treadiness = \"unsettled\";\n\t\t\t\tbreak;\n\t\t\tcase \"clock_changed\":\n\t\t\t\treadiness = \"clock_changed\";\n\t\t\t\tbreak;\n\t\t\tcase \"clock_rollback\":\n\t\t\t\treadiness = \"clock_rollback\";\n\t\t\t\tbreak;\n\t\t\tcase \"clock_unavailable\":\n\t\t\t\treadiness = \"clock_unavailable\";\n\t\t\t\tbreak;\n\t\t\tcase \"recovery_limit\":\n\t\t\t\treadiness = \"recovery_limit\";\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\treadiness = \"integrity\";\n\t\t}\n\t}\n\treturn Object.freeze({ state: journal.state, readiness, remainingVerifyMs, ownership: \"lease_required\" });\n}\n\nexport async function resumeFrozenCandidate(\n\trunPath: string,\n\tcommand: RunResumeCommand,\n\tsignal?: AbortSignal,\n): Promise<RunProjection> {\n\tif (signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\treturn withRecoveryLease(runPath, command, async ({ snapshot, journal }) => {\n\t\tassertCandidateRecoverable(runPath, snapshot);\n\t\tconst first = snapshot.records[0]?.event;\n\t\tif (first?.kind !== \"created\") throw new VerifiedRunError(\"integrity\");\n\t\tpreflightCheckReceipts(first.contract);\n\t\tprobeVerifiedSandbox();\n\t\tassertCandidateRecoverable(runPath, snapshot);\n\t\tif (signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\t\tjournal.append({\n\t\t\tkind: \"resumed\",\n\t\t\tcommand,\n\t\t\tobservedMs: readRunClock().nowMs,\n\t\t\treconciledExecutionIds: snapshot.state.activeExecutionIds,\n\t\t});\n\t\treturn verifyCandidate({ runPath, journal, contract: first.contract, ...(signal ? { signal } : {}) });\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"recovery.js","sourceRoot":"","sources":["../../../src/core/verified-run/recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,4BAA4B,EAAyB,MAAM,cAAc,CAAC;AAEnF,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,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AAC,SAAS;YAC5B,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACrD,CAAC,CAAC;IAAA,CACH,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { join } from \"node:path\";\nimport { MAX_VERIFIED_RUN_GENERATIONS, type RunResumeCommand } from \"omk-protocol\";\nimport type { RunAuthority } from \"./authority-runtime.ts\";\nimport { commandEnvironmentDigest, probeVerifiedSandbox } from \"./broker.ts\";\nimport { loadCandidate } from \"./candidate.ts\";\nimport { preflightCheckReceipts } from \"./check-receipt.ts\";\nimport type { JournalSnapshot } from \"./journal.ts\";\nimport { probeNamespace } from \"./namespace-identity.ts\";\nimport { readRunClock, remainingVerification } from \"./recovery-clock.ts\";\nimport { requireRunJournal, withRecoveryLease } from \"./recovery-command.ts\";\nimport type { RunProjection } from \"./run-types.ts\";\nimport { readRegularFile, VerifiedRunError } from \"./storage.ts\";\nimport { verifyCandidate } from \"./verification-phase.ts\";\n\nexport interface RecoveryInspection {\n\treadonly state: RunProjection;\n\treadonly readiness:\n\t\t| \"ready\"\n\t\t| \"terminal\"\n\t\t| \"legacy\"\n\t\t| \"candidate_missing\"\n\t\t| \"unsettled\"\n\t\t| \"expired\"\n\t\t| \"clock_changed\"\n\t\t| \"clock_rollback\"\n\t\t| \"clock_unavailable\"\n\t\t| \"recovery_limit\"\n\t\t| \"integrity\";\n\treadonly remainingVerifyMs: number | null;\n\t/** A ready inspection is advisory; exclusive ownership is acquired only by resume. */\n\treadonly ownership: \"lease_required\";\n}\n\nfunction assertCandidateRecoverable(runPath: string, journal: JournalSnapshot): number {\n\tconst state = journal.state;\n\tif (state.receiptDigest || state.execution === \"failed\") throw new VerifiedRunError(\"resume_terminal\");\n\tif (!state.budget || !state.environmentDigest) throw new VerifiedRunError(\"recovery_legacy\");\n\tif (!state.candidateDigest || state.writerOpen || state.verificationDeadlineMs === null)\n\t\tthrow new VerifiedRunError(\"candidate_missing\");\n\tif (state.generation >= MAX_VERIFIED_RUN_GENERATIONS) throw new VerifiedRunError(\"recovery_limit\");\n\tconst clock = readRunClock();\n\tconst remaining = remainingVerification(state.budget, state.verificationDeadlineMs, clock);\n\tif (clock.nowMs < (state.lastClockMs ?? state.budget.startedMs)) throw new VerifiedRunError(\"clock_rollback\");\n\tif (remaining <= 0) throw new VerifiedRunError(\"deadline\");\n\tfor (const id of state.activeExecutionIds) {\n\t\tconst dispatch = journal.records.find(\n\t\t\t(record) =>\n\t\t\t\trecord.generation === state.generation &&\n\t\t\t\trecord.event.kind === \"dispatch\" &&\n\t\t\t\trecord.event.executionId === id,\n\t\t)?.event;\n\t\tconst identity = state.processes.find((process) => process.executionId === id)?.identity;\n\t\tif (\n\t\t\tdispatch?.kind !== \"dispatch\" ||\n\t\t\tdispatch.role !== \"verifier\" ||\n\t\t\t!identity ||\n\t\t\tprobeNamespace(identity) !== \"gone\"\n\t\t)\n\t\t\tthrow new VerifiedRunError(\"unsettled\");\n\t}\n\tconst first = journal.records[0]?.event;\n\tif (first?.kind !== \"created\") throw new VerifiedRunError(\"integrity\");\n\tif (readRegularFile(join(runPath, \"issuer.key\"), 32).length !== 32) throw new VerifiedRunError(\"integrity\");\n\tloadCandidate(runPath, state.candidateDigest, first.contract.budget);\n\tif (commandEnvironmentDigest(first.contract, \"gated-v1\") !== state.environmentDigest)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\treturn remaining;\n}\n\nexport function inspectRunRecovery(runPath: string): RecoveryInspection {\n\tconst journal = requireRunJournal(runPath);\n\tlet readiness: RecoveryInspection[\"readiness\"] = \"ready\";\n\tlet remainingVerifyMs: number | null = null;\n\ttry {\n\t\tremainingVerifyMs = assertCandidateRecoverable(runPath, journal);\n\t} catch (error) {\n\t\tif (!(error instanceof Error)) throw error;\n\t\tswitch (error instanceof VerifiedRunError ? error.code : \"integrity\") {\n\t\t\tcase \"resume_terminal\":\n\t\t\t\treadiness = \"terminal\";\n\t\t\t\tbreak;\n\t\t\tcase \"recovery_legacy\":\n\t\t\t\treadiness = \"legacy\";\n\t\t\t\tbreak;\n\t\t\tcase \"deadline\":\n\t\t\t\treadiness = \"expired\";\n\t\t\t\tremainingVerifyMs = 0;\n\t\t\t\tbreak;\n\t\t\tcase \"candidate_missing\":\n\t\t\t\treadiness = \"candidate_missing\";\n\t\t\t\tbreak;\n\t\t\tcase \"unsettled\":\n\t\t\t\treadiness = \"unsettled\";\n\t\t\t\tbreak;\n\t\t\tcase \"clock_changed\":\n\t\t\t\treadiness = \"clock_changed\";\n\t\t\t\tbreak;\n\t\t\tcase \"clock_rollback\":\n\t\t\t\treadiness = \"clock_rollback\";\n\t\t\t\tbreak;\n\t\t\tcase \"clock_unavailable\":\n\t\t\t\treadiness = \"clock_unavailable\";\n\t\t\t\tbreak;\n\t\t\tcase \"recovery_limit\":\n\t\t\t\treadiness = \"recovery_limit\";\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\treadiness = \"integrity\";\n\t\t}\n\t}\n\treturn Object.freeze({ state: journal.state, readiness, remainingVerifyMs, ownership: \"lease_required\" });\n}\n\nexport async function resumeFrozenCandidate(\n\trunPath: string,\n\tcommand: RunResumeCommand,\n\toptions: { readonly signal?: AbortSignal; readonly authority: RunAuthority },\n): Promise<RunProjection> {\n\tif (options.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\treturn withRecoveryLease(runPath, command, async ({ snapshot, journal }) => {\n\t\tassertCandidateRecoverable(runPath, snapshot);\n\t\tconst first = snapshot.records[0]?.event;\n\t\tif (first?.kind !== \"created\") throw new VerifiedRunError(\"integrity\");\n\t\tpreflightCheckReceipts(first.contract);\n\t\tprobeVerifiedSandbox();\n\t\tassertCandidateRecoverable(runPath, snapshot);\n\t\tif (options.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\t\tjournal.append({\n\t\t\tkind: \"resumed\",\n\t\t\tcommand,\n\t\t\tobservedMs: readRunClock().nowMs,\n\t\t\treconciledExecutionIds: snapshot.state.activeExecutionIds,\n\t\t});\n\t\treturn verifyCandidate({\n\t\t\trunPath,\n\t\t\tjournal,\n\t\t\tcontract: first.contract,\n\t\t\tauthority: options.authority,\n\t\t\t...(options.signal ? { signal: options.signal } : {}),\n\t\t});\n\t});\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type RunContract } from "omk-protocol";
|
|
2
|
+
export interface VerifiedRunApproval {
|
|
3
|
+
/** Trusted host grant, not a JSON field in the model-authored contract or command. */
|
|
4
|
+
readonly approvedContractDigest: string;
|
|
5
|
+
readonly signal?: AbortSignal;
|
|
6
|
+
}
|
|
7
|
+
export interface VerifiedRunPlan {
|
|
8
|
+
readonly profile: RunContract["profile"];
|
|
9
|
+
readonly contractDigest: string;
|
|
10
|
+
readonly baseDigest: string;
|
|
11
|
+
readonly baseMatches: boolean;
|
|
12
|
+
readonly environmentDigest: string;
|
|
13
|
+
readonly checks: readonly string[];
|
|
14
|
+
readonly executionRequested: false;
|
|
15
|
+
}
|
|
16
|
+
export declare function planVerifiedRun(input: unknown): VerifiedRunPlan;
|
|
17
|
+
//# sourceMappingURL=run-plan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-plan.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/run-plan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAKlE,MAAM,WAAW,mBAAmB;IACnC,sFAAsF;IACtF,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAC;IACxC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;CAC9B;AACD,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IACzC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,kBAAkB,EAAE,KAAK,CAAC;CACnC;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,CAY/D","sourcesContent":["import { parseRunContract, type RunContract } from \"omk-protocol\";\nimport { commandEnvironmentDigest } from \"./broker.ts\";\nimport { captureCandidate } from \"./candidate.ts\";\nimport { digestObject } from \"./storage.ts\";\n\nexport interface VerifiedRunApproval {\n\t/** Trusted host grant, not a JSON field in the model-authored contract or command. */\n\treadonly approvedContractDigest: string;\n\treadonly signal?: AbortSignal;\n}\nexport interface VerifiedRunPlan {\n\treadonly profile: RunContract[\"profile\"];\n\treadonly contractDigest: string;\n\treadonly baseDigest: string;\n\treadonly baseMatches: boolean;\n\treadonly environmentDigest: string;\n\treadonly checks: readonly string[];\n\treadonly executionRequested: false;\n}\n\nexport function planVerifiedRun(input: unknown): VerifiedRunPlan {\n\tconst contract = parseRunContract(input);\n\tconst snapshot = captureCandidate(contract.workspace.root, contract.budget);\n\treturn Object.freeze({\n\t\tprofile: contract.profile,\n\t\tcontractDigest: digestObject(contract),\n\t\tbaseDigest: snapshot.digest,\n\t\tbaseMatches: snapshot.digest === contract.workspace.baseDigest,\n\t\tenvironmentDigest: commandEnvironmentDigest(contract, \"gated-v1\"),\n\t\tchecks: Object.freeze(contract.checks.map((check) => check.claimId)),\n\t\texecutionRequested: false,\n\t});\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { parseRunContract } from "omk-protocol";
|
|
2
|
+
import { commandEnvironmentDigest } from "./broker.js";
|
|
3
|
+
import { captureCandidate } from "./candidate.js";
|
|
4
|
+
import { digestObject } from "./storage.js";
|
|
5
|
+
export function planVerifiedRun(input) {
|
|
6
|
+
const contract = parseRunContract(input);
|
|
7
|
+
const snapshot = captureCandidate(contract.workspace.root, contract.budget);
|
|
8
|
+
return Object.freeze({
|
|
9
|
+
profile: contract.profile,
|
|
10
|
+
contractDigest: digestObject(contract),
|
|
11
|
+
baseDigest: snapshot.digest,
|
|
12
|
+
baseMatches: snapshot.digest === contract.workspace.baseDigest,
|
|
13
|
+
environmentDigest: commandEnvironmentDigest(contract, "gated-v1"),
|
|
14
|
+
checks: Object.freeze(contract.checks.map((check) => check.claimId)),
|
|
15
|
+
executionRequested: false,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=run-plan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-plan.js","sourceRoot":"","sources":["../../../src/core/verified-run/run-plan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAoB,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAiB5C,MAAM,UAAU,eAAe,CAAC,KAAc,EAAmB;IAChE,MAAM,QAAQ,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACzC,MAAM,QAAQ,GAAG,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC5E,OAAO,MAAM,CAAC,MAAM,CAAC;QACpB,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,cAAc,EAAE,YAAY,CAAC,QAAQ,CAAC;QACtC,UAAU,EAAE,QAAQ,CAAC,MAAM;QAC3B,WAAW,EAAE,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,SAAS,CAAC,UAAU;QAC9D,iBAAiB,EAAE,wBAAwB,CAAC,QAAQ,EAAE,UAAU,CAAC;QACjE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACpE,kBAAkB,EAAE,KAAK;KACzB,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { parseRunContract, type RunContract } from \"omk-protocol\";\nimport { commandEnvironmentDigest } from \"./broker.ts\";\nimport { captureCandidate } from \"./candidate.ts\";\nimport { digestObject } from \"./storage.ts\";\n\nexport interface VerifiedRunApproval {\n\t/** Trusted host grant, not a JSON field in the model-authored contract or command. */\n\treadonly approvedContractDigest: string;\n\treadonly signal?: AbortSignal;\n}\nexport interface VerifiedRunPlan {\n\treadonly profile: RunContract[\"profile\"];\n\treadonly contractDigest: string;\n\treadonly baseDigest: string;\n\treadonly baseMatches: boolean;\n\treadonly environmentDigest: string;\n\treadonly checks: readonly string[];\n\treadonly executionRequested: false;\n}\n\nexport function planVerifiedRun(input: unknown): VerifiedRunPlan {\n\tconst contract = parseRunContract(input);\n\tconst snapshot = captureCandidate(contract.workspace.root, contract.budget);\n\treturn Object.freeze({\n\t\tprofile: contract.profile,\n\t\tcontractDigest: digestObject(contract),\n\t\tbaseDigest: snapshot.digest,\n\t\tbaseMatches: snapshot.digest === contract.workspace.baseDigest,\n\t\tenvironmentDigest: commandEnvironmentDigest(contract, \"gated-v1\"),\n\t\tchecks: Object.freeze(contract.checks.map((check) => check.claimId)),\n\t\texecutionRequested: false,\n\t});\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RunPublishCommand } from "omk-protocol";
|
|
2
|
+
import { type PublishOptions } from "./run-publish.ts";
|
|
3
|
+
import type { RunProjection } from "./run-types.ts";
|
|
4
|
+
/** SDK/CLI publisher. Unsupported supervision never falls back to the legacy synchronous writer. */
|
|
5
|
+
export declare function publishVerifiedRunOwned(runPath: string, command: RunPublishCommand, options?: PublishOptions): Promise<RunProjection>;
|
|
6
|
+
//# sourceMappingURL=run-publish-owned.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-publish-owned.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/run-publish-owned.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAqBtD,OAAO,EAAE,KAAK,cAAc,EAAuC,MAAM,kBAAkB,CAAC;AAC5F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAIpD,oGAAoG;AACpG,wBAAsB,uBAAuB,CAC5C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,iBAAiB,EAC1B,OAAO,GAAE,cAAmB,GAC1B,OAAO,CAAC,aAAa,CAAC,CAyCxB","sourcesContent":["import { realpathSync } from \"node:fs\";\nimport type { RunPublishCommand } from \"omk-protocol\";\nimport { acquireSessionOwnerLeaseSync } from \"../session-owner-lease.ts\";\nimport { openRunAuthority, type RunAuthority } from \"./authority-runtime.ts\";\nimport { probeVerifiedSandbox } from \"./broker.ts\";\nimport { loadCandidate } from \"./candidate.ts\";\nimport { preflightGitCandidate } from \"./git-candidate-preflight.ts\";\nimport { executeOwnedGitPublication } from \"./git-effect-supervisor.ts\";\nimport { GitOperationBudget } from \"./git-execution.ts\";\nimport {\n\tassertGitWorkspaceRoot,\n\tOMK_ACCEPTED_REF,\n\tobjectExists,\n\trepoObjectFormat,\n\tresolveRef,\n\tzeroOid,\n} from \"./git-plumbing.ts\";\nimport { ownedGitDirectory } from \"./git-sandbox-layout.ts\";\nimport { loadGitWorkerRuntime } from \"./git-worker-runtime.ts\";\nimport { type JournalSnapshot, journalPath, VerifiedRunJournal } from \"./journal.ts\";\nimport { assertPublishable } from \"./publish-preflight.ts\";\nimport { requireRunJournal } from \"./recovery-command.ts\";\nimport { type PublishOptions, publishDisposition, recordPublished } from \"./run-publish.ts\";\nimport type { RunProjection } from \"./run-types.ts\";\nimport { digestObject, VerifiedRunError } from \"./storage.ts\";\nimport { loadSupervisorBackend } from \"./supervisor-adapter.ts\";\n\n/** SDK/CLI publisher. Unsupported supervision never falls back to the legacy synchronous writer. */\nexport async function publishVerifiedRunOwned(\n\trunPath: string,\n\tcommand: RunPublishCommand,\n\toptions: PublishOptions = {},\n): Promise<RunProjection> {\n\tconst initial = requireRunJournal(runPath);\n\tif (publishDisposition(initial, command) === \"completed\") return initial.state;\n\tif (options.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\tconst owner = acquireSessionOwnerLeaseSync(journalPath(runPath));\n\tlet opened: RunAuthority | null = null;\n\tlet result: RunProjection | undefined;\n\tconst failures: unknown[] = [];\n\ttry {\n\t\tconst snapshot = requireRunJournal(runPath);\n\t\tif (publishDisposition(snapshot, command) === \"completed\") result = snapshot.state;\n\t\telse {\n\t\t\tif (!options.authority) opened = openRunAuthority(runPath);\n\t\t\tconst authority = options.authority ?? opened;\n\t\t\tif (!authority) throw new VerifiedRunError(\"authority\");\n\t\t\tresult = await executePublish(\n\t\t\t\trunPath,\n\t\t\t\tsnapshot,\n\t\t\t\tnew VerifiedRunJournal(runPath, owner),\n\t\t\t\tcommand,\n\t\t\t\toptions,\n\t\t\t\tauthority,\n\t\t\t);\n\t\t}\n\t} catch (error) {\n\t\tfailures.push(error);\n\t}\n\ttry {\n\t\topened?.store.release();\n\t} catch (error) {\n\t\tfailures.push(error);\n\t}\n\ttry {\n\t\towner.release();\n\t} catch (error) {\n\t\tfailures.push(error);\n\t}\n\tif (failures.length === 1) throw failures[0];\n\tif (failures.length > 1) throw new AggregateError(failures, \"Publication owner cleanup failed\");\n\tif (!result) throw new VerifiedRunError(\"integrity\");\n\treturn result;\n}\n\nasync function executePublish(\n\trunPath: string,\n\tsnapshot: JournalSnapshot,\n\tjournal: VerifiedRunJournal,\n\tcommand: RunPublishCommand,\n\toptions: PublishOptions,\n\tauthority: RunAuthority,\n): Promise<RunProjection> {\n\tconst timeoutMs = options.timeoutMs ?? 60_000;\n\tif (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > 60_000) throw new VerifiedRunError(\"deadline\");\n\tconst deadlineNs = (process.hrtime.bigint() + BigInt(timeoutMs) * 1_000_000n).toString();\n\tconst budget = new GitOperationBudget({ signal: options.signal, timeoutMs });\n\tbudget.remaining();\n\tconst { contract, state } = assertPublishable(snapshot, command, runPath);\n\tconst repo = realpathSync(contract.workspace.root);\n\tassertGitWorkspaceRoot(repo, budget);\n\tconst zero = zeroOid(repoObjectFormat(repo, budget));\n\tif (command.parentOid.length !== zero.length) throw new VerifiedRunError(\"invalid_binding\");\n\tconst resumed = state.publication === \"intent\" && state.publicationCommandId === command.commandId;\n\tif (resumed) {\n\t\tconst oid = state.publicationCandidateOid;\n\t\tif (!oid) throw new VerifiedRunError(\"invalid_binding\");\n\t\tconst observed = resolveRef(repo, OMK_ACCEPTED_REF, budget);\n\t\tif (observed === oid && objectExists(repo, oid, budget)) return recordPublished(journal, command, oid);\n\t\tif ((observed ?? zero) !== command.parentOid)\n\t\t\treturn journal.append({\n\t\t\t\tkind: \"publish_failed\",\n\t\t\t\tcommandId: command.commandId,\n\t\t\t\tcode: \"reconciliation-required\",\n\t\t\t});\n\t}\n\tloadSupervisorBackend();\n\tprobeVerifiedSandbox();\n\townedGitDirectory(repo);\n\tconst runtime = loadGitWorkerRuntime();\n\tconst candidate = loadCandidate(runPath, state.candidateDigest, contract.budget);\n\tpreflightGitCandidate(candidate.manifest, candidate.contents);\n\tbudget.remaining();\n\tconst claims = [\n\t\t{\n\t\t\tnamespace: \"git-ref\",\n\t\t\tinstanceId: \"verified-run\",\n\t\t\tcanonicalKey: `omk-accepted-ref/${digestObject(repo).slice(0, 16)}`,\n\t\t\taccess: \"write\",\n\t\t\tgeneration: String(state.generation),\n\t\t},\n\t];\n\tconst admission = authority.store.acquire({\n\t\tsessionId: authority.sessionId,\n\t\tincarnation: authority.incarnation,\n\t\tcommandId: command.commandId,\n\t\tintentDigest: digestObject({\n\t\t\tadapter: \"owned-git-v1\",\n\t\t\truntimeDigest: runtime.digest,\n\t\t\tcandidateDigest: command.candidateDigest,\n\t\t\tparentOid: command.parentOid,\n\t\t\treceiptDigest: command.receiptDigest,\n\t\t\tpolicyDigest: command.policyDigest,\n\t\t\ttargetRef: OMK_ACCEPTED_REF,\n\t\t}),\n\t\tclaims,\n\t\tnow: Date.now(),\n\t\tttl: timeoutMs + contract.budget.cleanupMs,\n\t});\n\tif (admission.status !== \"granted\") throw new VerifiedRunError(\"authority_blocked\");\n\ttry {\n\t\tconst result = await executeOwnedGitPublication({\n\t\t\tworkspace: repo,\n\t\t\truntime,\n\t\t\tauthority,\n\t\t\ttoken: admission.token,\n\t\t\tclaims,\n\t\t\tbudget,\n\t\t\tdeadlineNs,\n\t\t\tcleanupMs: contract.budget.cleanupMs,\n\t\t\tsignal: options.signal,\n\t\t\tafterCas: options.afterCas,\n\t\t\tinput: {\n\t\t\t\tmanifest: candidate.manifest,\n\t\t\t\tcontents: candidate.contents,\n\t\t\t\tparentOid: command.parentOid,\n\t\t\t\tzeroOid: zero,\n\t\t\t\trunId: contract.runId,\n\t\t\t\tcandidateDigest: state.candidateDigest,\n\t\t\t\treceiptDigest: state.receiptDigest,\n\t\t\t},\n\t\t\tonPrepared: (candidateOid) => {\n\t\t\t\tif (resumed) {\n\t\t\t\t\tif (state.publicationCandidateOid !== candidateOid) throw new VerifiedRunError(\"invalid_binding\");\n\t\t\t\t} else\n\t\t\t\t\tjournal.append({\n\t\t\t\t\t\tkind: \"publish_intent\",\n\t\t\t\t\t\tcommandId: command.commandId,\n\t\t\t\t\t\tcandidateDigest: state.candidateDigest,\n\t\t\t\t\t\tcandidateOid,\n\t\t\t\t\t\tparentOid: command.parentOid,\n\t\t\t\t\t\ttargetRef: OMK_ACCEPTED_REF,\n\t\t\t\t\t\treceiptDigest: state.receiptDigest,\n\t\t\t\t\t\tpolicyDigest: command.policyDigest,\n\t\t\t\t\t\tgeneration: state.generation,\n\t\t\t\t\t});\n\t\t\t},\n\t\t});\n\t\tconst observed = resolveRef(repo, OMK_ACCEPTED_REF);\n\t\tif (observed === result.candidateOid && objectExists(repo, result.candidateOid))\n\t\t\treturn recordPublished(journal, command, result.candidateOid);\n\t\treturn journal.append({\n\t\t\tkind: \"publish_failed\",\n\t\t\tcommandId: command.commandId,\n\t\t\tcode:\n\t\t\t\t(observed ?? zero) === command.parentOid\n\t\t\t\t\t? \"ref-rejected\"\n\t\t\t\t\t: resumed\n\t\t\t\t\t\t? \"reconciliation-required\"\n\t\t\t\t\t\t: \"stale-parent\",\n\t\t});\n\t} catch (error) {\n\t\tconst grant = authority.store.state.grants.get(admission.token.grantSequence);\n\t\ttry {\n\t\t\tif (grant?.state === \"reserved\") authority.store.cancel(admission.token);\n\t\t\tif (\n\t\t\t\tgrant?.state === \"terminated\" &&\n\t\t\t\tjournal.state.publication === \"intent\" &&\n\t\t\t\terror instanceof VerifiedRunError &&\n\t\t\t\t[\"cancelled\", \"deadline\"].includes(error.code) &&\n\t\t\t\tresolveRef(repo, OMK_ACCEPTED_REF) !== journal.state.publicationCandidateOid\n\t\t\t)\n\t\t\t\tjournal.append({ kind: \"publish_failed\", commandId: command.commandId, code: \"reconciliation-required\" });\n\t\t} catch (cleanupError) {\n\t\t\tthrow new AggregateError([error, cleanupError], \"Publication failure could not be recorded\");\n\t\t}\n\t\tthrow error;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import { acquireSessionOwnerLeaseSync } from "../session-owner-lease.js";
|
|
3
|
+
import { openRunAuthority } from "./authority-runtime.js";
|
|
4
|
+
import { probeVerifiedSandbox } from "./broker.js";
|
|
5
|
+
import { loadCandidate } from "./candidate.js";
|
|
6
|
+
import { preflightGitCandidate } from "./git-candidate-preflight.js";
|
|
7
|
+
import { executeOwnedGitPublication } from "./git-effect-supervisor.js";
|
|
8
|
+
import { GitOperationBudget } from "./git-execution.js";
|
|
9
|
+
import { assertGitWorkspaceRoot, OMK_ACCEPTED_REF, objectExists, repoObjectFormat, resolveRef, zeroOid, } from "./git-plumbing.js";
|
|
10
|
+
import { ownedGitDirectory } from "./git-sandbox-layout.js";
|
|
11
|
+
import { loadGitWorkerRuntime } from "./git-worker-runtime.js";
|
|
12
|
+
import { journalPath, VerifiedRunJournal } from "./journal.js";
|
|
13
|
+
import { assertPublishable } from "./publish-preflight.js";
|
|
14
|
+
import { requireRunJournal } from "./recovery-command.js";
|
|
15
|
+
import { publishDisposition, recordPublished } from "./run-publish.js";
|
|
16
|
+
import { digestObject, VerifiedRunError } from "./storage.js";
|
|
17
|
+
import { loadSupervisorBackend } from "./supervisor-adapter.js";
|
|
18
|
+
/** SDK/CLI publisher. Unsupported supervision never falls back to the legacy synchronous writer. */
|
|
19
|
+
export async function publishVerifiedRunOwned(runPath, command, options = {}) {
|
|
20
|
+
const initial = requireRunJournal(runPath);
|
|
21
|
+
if (publishDisposition(initial, command) === "completed")
|
|
22
|
+
return initial.state;
|
|
23
|
+
if (options.signal?.aborted)
|
|
24
|
+
throw new VerifiedRunError("cancelled");
|
|
25
|
+
const owner = acquireSessionOwnerLeaseSync(journalPath(runPath));
|
|
26
|
+
let opened = null;
|
|
27
|
+
let result;
|
|
28
|
+
const failures = [];
|
|
29
|
+
try {
|
|
30
|
+
const snapshot = requireRunJournal(runPath);
|
|
31
|
+
if (publishDisposition(snapshot, command) === "completed")
|
|
32
|
+
result = snapshot.state;
|
|
33
|
+
else {
|
|
34
|
+
if (!options.authority)
|
|
35
|
+
opened = openRunAuthority(runPath);
|
|
36
|
+
const authority = options.authority ?? opened;
|
|
37
|
+
if (!authority)
|
|
38
|
+
throw new VerifiedRunError("authority");
|
|
39
|
+
result = await executePublish(runPath, snapshot, new VerifiedRunJournal(runPath, owner), command, options, authority);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
failures.push(error);
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
opened?.store.release();
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
failures.push(error);
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
owner.release();
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
failures.push(error);
|
|
56
|
+
}
|
|
57
|
+
if (failures.length === 1)
|
|
58
|
+
throw failures[0];
|
|
59
|
+
if (failures.length > 1)
|
|
60
|
+
throw new AggregateError(failures, "Publication owner cleanup failed");
|
|
61
|
+
if (!result)
|
|
62
|
+
throw new VerifiedRunError("integrity");
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
async function executePublish(runPath, snapshot, journal, command, options, authority) {
|
|
66
|
+
const timeoutMs = options.timeoutMs ?? 60_000;
|
|
67
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > 60_000)
|
|
68
|
+
throw new VerifiedRunError("deadline");
|
|
69
|
+
const deadlineNs = (process.hrtime.bigint() + BigInt(timeoutMs) * 1000000n).toString();
|
|
70
|
+
const budget = new GitOperationBudget({ signal: options.signal, timeoutMs });
|
|
71
|
+
budget.remaining();
|
|
72
|
+
const { contract, state } = assertPublishable(snapshot, command, runPath);
|
|
73
|
+
const repo = realpathSync(contract.workspace.root);
|
|
74
|
+
assertGitWorkspaceRoot(repo, budget);
|
|
75
|
+
const zero = zeroOid(repoObjectFormat(repo, budget));
|
|
76
|
+
if (command.parentOid.length !== zero.length)
|
|
77
|
+
throw new VerifiedRunError("invalid_binding");
|
|
78
|
+
const resumed = state.publication === "intent" && state.publicationCommandId === command.commandId;
|
|
79
|
+
if (resumed) {
|
|
80
|
+
const oid = state.publicationCandidateOid;
|
|
81
|
+
if (!oid)
|
|
82
|
+
throw new VerifiedRunError("invalid_binding");
|
|
83
|
+
const observed = resolveRef(repo, OMK_ACCEPTED_REF, budget);
|
|
84
|
+
if (observed === oid && objectExists(repo, oid, budget))
|
|
85
|
+
return recordPublished(journal, command, oid);
|
|
86
|
+
if ((observed ?? zero) !== command.parentOid)
|
|
87
|
+
return journal.append({
|
|
88
|
+
kind: "publish_failed",
|
|
89
|
+
commandId: command.commandId,
|
|
90
|
+
code: "reconciliation-required",
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
loadSupervisorBackend();
|
|
94
|
+
probeVerifiedSandbox();
|
|
95
|
+
ownedGitDirectory(repo);
|
|
96
|
+
const runtime = loadGitWorkerRuntime();
|
|
97
|
+
const candidate = loadCandidate(runPath, state.candidateDigest, contract.budget);
|
|
98
|
+
preflightGitCandidate(candidate.manifest, candidate.contents);
|
|
99
|
+
budget.remaining();
|
|
100
|
+
const claims = [
|
|
101
|
+
{
|
|
102
|
+
namespace: "git-ref",
|
|
103
|
+
instanceId: "verified-run",
|
|
104
|
+
canonicalKey: `omk-accepted-ref/${digestObject(repo).slice(0, 16)}`,
|
|
105
|
+
access: "write",
|
|
106
|
+
generation: String(state.generation),
|
|
107
|
+
},
|
|
108
|
+
];
|
|
109
|
+
const admission = authority.store.acquire({
|
|
110
|
+
sessionId: authority.sessionId,
|
|
111
|
+
incarnation: authority.incarnation,
|
|
112
|
+
commandId: command.commandId,
|
|
113
|
+
intentDigest: digestObject({
|
|
114
|
+
adapter: "owned-git-v1",
|
|
115
|
+
runtimeDigest: runtime.digest,
|
|
116
|
+
candidateDigest: command.candidateDigest,
|
|
117
|
+
parentOid: command.parentOid,
|
|
118
|
+
receiptDigest: command.receiptDigest,
|
|
119
|
+
policyDigest: command.policyDigest,
|
|
120
|
+
targetRef: OMK_ACCEPTED_REF,
|
|
121
|
+
}),
|
|
122
|
+
claims,
|
|
123
|
+
now: Date.now(),
|
|
124
|
+
ttl: timeoutMs + contract.budget.cleanupMs,
|
|
125
|
+
});
|
|
126
|
+
if (admission.status !== "granted")
|
|
127
|
+
throw new VerifiedRunError("authority_blocked");
|
|
128
|
+
try {
|
|
129
|
+
const result = await executeOwnedGitPublication({
|
|
130
|
+
workspace: repo,
|
|
131
|
+
runtime,
|
|
132
|
+
authority,
|
|
133
|
+
token: admission.token,
|
|
134
|
+
claims,
|
|
135
|
+
budget,
|
|
136
|
+
deadlineNs,
|
|
137
|
+
cleanupMs: contract.budget.cleanupMs,
|
|
138
|
+
signal: options.signal,
|
|
139
|
+
afterCas: options.afterCas,
|
|
140
|
+
input: {
|
|
141
|
+
manifest: candidate.manifest,
|
|
142
|
+
contents: candidate.contents,
|
|
143
|
+
parentOid: command.parentOid,
|
|
144
|
+
zeroOid: zero,
|
|
145
|
+
runId: contract.runId,
|
|
146
|
+
candidateDigest: state.candidateDigest,
|
|
147
|
+
receiptDigest: state.receiptDigest,
|
|
148
|
+
},
|
|
149
|
+
onPrepared: (candidateOid) => {
|
|
150
|
+
if (resumed) {
|
|
151
|
+
if (state.publicationCandidateOid !== candidateOid)
|
|
152
|
+
throw new VerifiedRunError("invalid_binding");
|
|
153
|
+
}
|
|
154
|
+
else
|
|
155
|
+
journal.append({
|
|
156
|
+
kind: "publish_intent",
|
|
157
|
+
commandId: command.commandId,
|
|
158
|
+
candidateDigest: state.candidateDigest,
|
|
159
|
+
candidateOid,
|
|
160
|
+
parentOid: command.parentOid,
|
|
161
|
+
targetRef: OMK_ACCEPTED_REF,
|
|
162
|
+
receiptDigest: state.receiptDigest,
|
|
163
|
+
policyDigest: command.policyDigest,
|
|
164
|
+
generation: state.generation,
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
const observed = resolveRef(repo, OMK_ACCEPTED_REF);
|
|
169
|
+
if (observed === result.candidateOid && objectExists(repo, result.candidateOid))
|
|
170
|
+
return recordPublished(journal, command, result.candidateOid);
|
|
171
|
+
return journal.append({
|
|
172
|
+
kind: "publish_failed",
|
|
173
|
+
commandId: command.commandId,
|
|
174
|
+
code: (observed ?? zero) === command.parentOid
|
|
175
|
+
? "ref-rejected"
|
|
176
|
+
: resumed
|
|
177
|
+
? "reconciliation-required"
|
|
178
|
+
: "stale-parent",
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
const grant = authority.store.state.grants.get(admission.token.grantSequence);
|
|
183
|
+
try {
|
|
184
|
+
if (grant?.state === "reserved")
|
|
185
|
+
authority.store.cancel(admission.token);
|
|
186
|
+
if (grant?.state === "terminated" &&
|
|
187
|
+
journal.state.publication === "intent" &&
|
|
188
|
+
error instanceof VerifiedRunError &&
|
|
189
|
+
["cancelled", "deadline"].includes(error.code) &&
|
|
190
|
+
resolveRef(repo, OMK_ACCEPTED_REF) !== journal.state.publicationCandidateOid)
|
|
191
|
+
journal.append({ kind: "publish_failed", commandId: command.commandId, code: "reconciliation-required" });
|
|
192
|
+
}
|
|
193
|
+
catch (cleanupError) {
|
|
194
|
+
throw new AggregateError([error, cleanupError], "Publication failure could not be recorded");
|
|
195
|
+
}
|
|
196
|
+
throw error;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=run-publish-owned.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-publish-owned.js","sourceRoot":"","sources":["../../../src/core/verified-run/run-publish-owned.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAqB,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EACN,sBAAsB,EACtB,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,OAAO,GACP,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,iB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AAK,KAAK,YAAY;gBAC7B,OAAO,CAAC,KAAK,CAAC,WAAW,KAAK,QAAQ;gBACtC,KAAK,YAAY,gBAAgB;gBACjC,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;gBAC9C,UAAU,CAAC,IAAI,EAAE,gBAAgB,CAAC,KAAK,OAAO,CAAC,KAAK,CAAC,uBAAuB;gBAE5E,OAAO,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,yBAAyB,EAAE,CAAC,CAAC;QAC5G,CAAC;QAAC,OAAO,YAAY,EAAE,CAAC;YACvB,MAAM,IAAI,cAAc,CAAC,CAAC,KAAK,EAAE,YAAY,CAAC,EAAE,2CAA2C,CAAC,CAAC;QAC9F,CAAC;QACD,MAAM,KAAK,CAAC;IACb,CAAC;AAAA,CACD","sourcesContent":["import { realpathSync } from \"node:fs\";\nimport type { RunPublishCommand } from \"omk-protocol\";\nimport { acquireSessionOwnerLeaseSync } from \"../session-owner-lease.ts\";\nimport { openRunAuthority, type RunAuthority } from \"./authority-runtime.ts\";\nimport { probeVerifiedSandbox } from \"./broker.ts\";\nimport { loadCandidate } from \"./candidate.ts\";\nimport { preflightGitCandidate } from \"./git-candidate-preflight.ts\";\nimport { executeOwnedGitPublication } from \"./git-effect-supervisor.ts\";\nimport { GitOperationBudget } from \"./git-execution.ts\";\nimport {\n\tassertGitWorkspaceRoot,\n\tOMK_ACCEPTED_REF,\n\tobjectExists,\n\trepoObjectFormat,\n\tresolveRef,\n\tzeroOid,\n} from \"./git-plumbing.ts\";\nimport { ownedGitDirectory } from \"./git-sandbox-layout.ts\";\nimport { loadGitWorkerRuntime } from \"./git-worker-runtime.ts\";\nimport { type JournalSnapshot, journalPath, VerifiedRunJournal } from \"./journal.ts\";\nimport { assertPublishable } from \"./publish-preflight.ts\";\nimport { requireRunJournal } from \"./recovery-command.ts\";\nimport { type PublishOptions, publishDisposition, recordPublished } from \"./run-publish.ts\";\nimport type { RunProjection } from \"./run-types.ts\";\nimport { digestObject, VerifiedRunError } from \"./storage.ts\";\nimport { loadSupervisorBackend } from \"./supervisor-adapter.ts\";\n\n/** SDK/CLI publisher. Unsupported supervision never falls back to the legacy synchronous writer. */\nexport async function publishVerifiedRunOwned(\n\trunPath: string,\n\tcommand: RunPublishCommand,\n\toptions: PublishOptions = {},\n): Promise<RunProjection> {\n\tconst initial = requireRunJournal(runPath);\n\tif (publishDisposition(initial, command) === \"completed\") return initial.state;\n\tif (options.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\tconst owner = acquireSessionOwnerLeaseSync(journalPath(runPath));\n\tlet opened: RunAuthority | null = null;\n\tlet result: RunProjection | undefined;\n\tconst failures: unknown[] = [];\n\ttry {\n\t\tconst snapshot = requireRunJournal(runPath);\n\t\tif (publishDisposition(snapshot, command) === \"completed\") result = snapshot.state;\n\t\telse {\n\t\t\tif (!options.authority) opened = openRunAuthority(runPath);\n\t\t\tconst authority = options.authority ?? opened;\n\t\t\tif (!authority) throw new VerifiedRunError(\"authority\");\n\t\t\tresult = await executePublish(\n\t\t\t\trunPath,\n\t\t\t\tsnapshot,\n\t\t\t\tnew VerifiedRunJournal(runPath, owner),\n\t\t\t\tcommand,\n\t\t\t\toptions,\n\t\t\t\tauthority,\n\t\t\t);\n\t\t}\n\t} catch (error) {\n\t\tfailures.push(error);\n\t}\n\ttry {\n\t\topened?.store.release();\n\t} catch (error) {\n\t\tfailures.push(error);\n\t}\n\ttry {\n\t\towner.release();\n\t} catch (error) {\n\t\tfailures.push(error);\n\t}\n\tif (failures.length === 1) throw failures[0];\n\tif (failures.length > 1) throw new AggregateError(failures, \"Publication owner cleanup failed\");\n\tif (!result) throw new VerifiedRunError(\"integrity\");\n\treturn result;\n}\n\nasync function executePublish(\n\trunPath: string,\n\tsnapshot: JournalSnapshot,\n\tjournal: VerifiedRunJournal,\n\tcommand: RunPublishCommand,\n\toptions: PublishOptions,\n\tauthority: RunAuthority,\n): Promise<RunProjection> {\n\tconst timeoutMs = options.timeoutMs ?? 60_000;\n\tif (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > 60_000) throw new VerifiedRunError(\"deadline\");\n\tconst deadlineNs = (process.hrtime.bigint() + BigInt(timeoutMs) * 1_000_000n).toString();\n\tconst budget = new GitOperationBudget({ signal: options.signal, timeoutMs });\n\tbudget.remaining();\n\tconst { contract, state } = assertPublishable(snapshot, command, runPath);\n\tconst repo = realpathSync(contract.workspace.root);\n\tassertGitWorkspaceRoot(repo, budget);\n\tconst zero = zeroOid(repoObjectFormat(repo, budget));\n\tif (command.parentOid.length !== zero.length) throw new VerifiedRunError(\"invalid_binding\");\n\tconst resumed = state.publication === \"intent\" && state.publicationCommandId === command.commandId;\n\tif (resumed) {\n\t\tconst oid = state.publicationCandidateOid;\n\t\tif (!oid) throw new VerifiedRunError(\"invalid_binding\");\n\t\tconst observed = resolveRef(repo, OMK_ACCEPTED_REF, budget);\n\t\tif (observed === oid && objectExists(repo, oid, budget)) return recordPublished(journal, command, oid);\n\t\tif ((observed ?? zero) !== command.parentOid)\n\t\t\treturn journal.append({\n\t\t\t\tkind: \"publish_failed\",\n\t\t\t\tcommandId: command.commandId,\n\t\t\t\tcode: \"reconciliation-required\",\n\t\t\t});\n\t}\n\tloadSupervisorBackend();\n\tprobeVerifiedSandbox();\n\townedGitDirectory(repo);\n\tconst runtime = loadGitWorkerRuntime();\n\tconst candidate = loadCandidate(runPath, state.candidateDigest, contract.budget);\n\tpreflightGitCandidate(candidate.manifest, candidate.contents);\n\tbudget.remaining();\n\tconst claims = [\n\t\t{\n\t\t\tnamespace: \"git-ref\",\n\t\t\tinstanceId: \"verified-run\",\n\t\t\tcanonicalKey: `omk-accepted-ref/${digestObject(repo).slice(0, 16)}`,\n\t\t\taccess: \"write\",\n\t\t\tgeneration: String(state.generation),\n\t\t},\n\t];\n\tconst admission = authority.store.acquire({\n\t\tsessionId: authority.sessionId,\n\t\tincarnation: authority.incarnation,\n\t\tcommandId: command.commandId,\n\t\tintentDigest: digestObject({\n\t\t\tadapter: \"owned-git-v1\",\n\t\t\truntimeDigest: runtime.digest,\n\t\t\tcandidateDigest: command.candidateDigest,\n\t\t\tparentOid: command.parentOid,\n\t\t\treceiptDigest: command.receiptDigest,\n\t\t\tpolicyDigest: command.policyDigest,\n\t\t\ttargetRef: OMK_ACCEPTED_REF,\n\t\t}),\n\t\tclaims,\n\t\tnow: Date.now(),\n\t\tttl: timeoutMs + contract.budget.cleanupMs,\n\t});\n\tif (admission.status !== \"granted\") throw new VerifiedRunError(\"authority_blocked\");\n\ttry {\n\t\tconst result = await executeOwnedGitPublication({\n\t\t\tworkspace: repo,\n\t\t\truntime,\n\t\t\tauthority,\n\t\t\ttoken: admission.token,\n\t\t\tclaims,\n\t\t\tbudget,\n\t\t\tdeadlineNs,\n\t\t\tcleanupMs: contract.budget.cleanupMs,\n\t\t\tsignal: options.signal,\n\t\t\tafterCas: options.afterCas,\n\t\t\tinput: {\n\t\t\t\tmanifest: candidate.manifest,\n\t\t\t\tcontents: candidate.contents,\n\t\t\t\tparentOid: command.parentOid,\n\t\t\t\tzeroOid: zero,\n\t\t\t\trunId: contract.runId,\n\t\t\t\tcandidateDigest: state.candidateDigest,\n\t\t\t\treceiptDigest: state.receiptDigest,\n\t\t\t},\n\t\t\tonPrepared: (candidateOid) => {\n\t\t\t\tif (resumed) {\n\t\t\t\t\tif (state.publicationCandidateOid !== candidateOid) throw new VerifiedRunError(\"invalid_binding\");\n\t\t\t\t} else\n\t\t\t\t\tjournal.append({\n\t\t\t\t\t\tkind: \"publish_intent\",\n\t\t\t\t\t\tcommandId: command.commandId,\n\t\t\t\t\t\tcandidateDigest: state.candidateDigest,\n\t\t\t\t\t\tcandidateOid,\n\t\t\t\t\t\tparentOid: command.parentOid,\n\t\t\t\t\t\ttargetRef: OMK_ACCEPTED_REF,\n\t\t\t\t\t\treceiptDigest: state.receiptDigest,\n\t\t\t\t\t\tpolicyDigest: command.policyDigest,\n\t\t\t\t\t\tgeneration: state.generation,\n\t\t\t\t\t});\n\t\t\t},\n\t\t});\n\t\tconst observed = resolveRef(repo, OMK_ACCEPTED_REF);\n\t\tif (observed === result.candidateOid && objectExists(repo, result.candidateOid))\n\t\t\treturn recordPublished(journal, command, result.candidateOid);\n\t\treturn journal.append({\n\t\t\tkind: \"publish_failed\",\n\t\t\tcommandId: command.commandId,\n\t\t\tcode:\n\t\t\t\t(observed ?? zero) === command.parentOid\n\t\t\t\t\t? \"ref-rejected\"\n\t\t\t\t\t: resumed\n\t\t\t\t\t\t? \"reconciliation-required\"\n\t\t\t\t\t\t: \"stale-parent\",\n\t\t});\n\t} catch (error) {\n\t\tconst grant = authority.store.state.grants.get(admission.token.grantSequence);\n\t\ttry {\n\t\t\tif (grant?.state === \"reserved\") authority.store.cancel(admission.token);\n\t\t\tif (\n\t\t\t\tgrant?.state === \"terminated\" &&\n\t\t\t\tjournal.state.publication === \"intent\" &&\n\t\t\t\terror instanceof VerifiedRunError &&\n\t\t\t\t[\"cancelled\", \"deadline\"].includes(error.code) &&\n\t\t\t\tresolveRef(repo, OMK_ACCEPTED_REF) !== journal.state.publicationCandidateOid\n\t\t\t)\n\t\t\t\tjournal.append({ kind: \"publish_failed\", commandId: command.commandId, code: \"reconciliation-required\" });\n\t\t} catch (cleanupError) {\n\t\t\tthrow new AggregateError([error, cleanupError], \"Publication failure could not be recorded\");\n\t\t}\n\t\tthrow error;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RunPublishCommand } from "omk-protocol";
|
|
2
|
+
import { type RunAuthority } from "./authority-runtime.ts";
|
|
3
|
+
import { OMK_ACCEPTED_REF } from "./git-plumbing.ts";
|
|
4
|
+
import { type JournalSnapshot, VerifiedRunJournal } from "./journal.ts";
|
|
5
|
+
import type { RunProjection } from "./run-types.ts";
|
|
6
|
+
export { OMK_ACCEPTED_REF };
|
|
7
|
+
export { publishPolicyDigest } from "./publish-preflight.ts";
|
|
8
|
+
export declare function publishDisposition(journal: JournalSnapshot, command: RunPublishCommand): "completed" | "resume" | "new";
|
|
9
|
+
export interface PublishOptions {
|
|
10
|
+
/** Fault injection after a successful CAS, before the result record. */
|
|
11
|
+
readonly afterCas?: () => void;
|
|
12
|
+
readonly signal?: AbortSignal;
|
|
13
|
+
/** One monotonic deadline shared by all Git writes, never replenished per file. */
|
|
14
|
+
readonly timeoutMs?: number;
|
|
15
|
+
readonly authority?: RunAuthority;
|
|
16
|
+
}
|
|
17
|
+
export declare function publishVerifiedRun(runPath: string, command: RunPublishCommand, options?: PublishOptions): RunProjection;
|
|
18
|
+
export declare function recordPublished(journal: VerifiedRunJournal, command: RunPublishCommand, candidateOid: string): RunProjection;
|
|
19
|
+
//# sourceMappingURL=run-publish.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-publish.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/run-publish.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAG7E,OAAO,EAIN,gBAAgB,EAMhB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,KAAK,eAAe,EAAe,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAIrF,OAAO,KAAK,EAAY,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAW7D,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,iBAAiB,GACxB,WAAW,GAAG,QAAQ,GAAG,KAAK,CAyBhC;AAED,MAAM,WAAW,cAAc;IAC9B,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,mFAAmF;IACnF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,YAAY,CAAC;CAClC;AAED,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,iBAAiB,EAC1B,OAAO,GAAE,cAAmB,GAC1B,aAAa,CAqBf;AAED,wBAAgB,eAAe,CAC9B,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE,iBAAiB,EAC1B,YAAY,EAAE,MAAM,GAClB,aAAa,CAOf","sourcesContent":["import { realpathSync } from \"node:fs\";\nimport type { RunPublishCommand } from \"omk-protocol\";\nimport { acquireSessionOwnerLeaseSync } from \"../session-owner-lease.ts\";\nimport { openRunAuthority, type RunAuthority } from \"./authority-runtime.ts\";\nimport { loadCandidate } from \"./candidate.ts\";\nimport { GitOperationBudget } from \"./git-execution.ts\";\nimport {\n\tassertGitWorkspaceRoot,\n\tcasRef,\n\tGitRefCasError,\n\tOMK_ACCEPTED_REF,\n\tobjectExists,\n\trepoObjectFormat,\n\tresolveRef,\n\tsealCandidateCommit,\n\tzeroOid,\n} from \"./git-plumbing.ts\";\nimport { type JournalSnapshot, journalPath, VerifiedRunJournal } from \"./journal.ts\";\nimport { assertPublishable } from \"./publish-preflight.ts\";\nimport { assertPublishEffectStart } from \"./publish-start.ts\";\nimport { requireRunJournal } from \"./recovery-command.ts\";\nimport type { RunEvent, RunProjection } from \"./run-types.ts\";\nimport { digestObject, VerifiedRunError } from \"./storage.ts\";\nexport { OMK_ACCEPTED_REF };\nexport { publishPolicyDigest } from \"./publish-preflight.ts\";\n\ntype PublishIntent = Extract<RunEvent, { kind: \"publish_intent\" }>;\nfunction openPublishIntents(journal: JournalSnapshot): readonly PublishIntent[] {\n\treturn journal.records.flatMap(({ event }) => (event.kind === \"publish_intent\" ? [event] : []));\n}\nfunction terminalFor(journal: JournalSnapshot, commandId: string): boolean {\n\treturn journal.records.some(\n\t\t({ event }) => (event.kind === \"published\" || event.kind === \"publish_failed\") && event.commandId === commandId,\n\t);\n}\nexport function publishDisposition(\n\tjournal: JournalSnapshot,\n\tcommand: RunPublishCommand,\n): \"completed\" | \"resume\" | \"new\" {\n\tconst first = journal.records[0]?.event;\n\tif (\n\t\tfirst?.kind !== \"created\" ||\n\t\tfirst.contract.runId !== command.runId ||\n\t\tdigestObject(first.contract) !== command.contractDigest\n\t)\n\t\tthrow new VerifiedRunError(\"command_conflict\");\n\tif (first.command.commandId === command.commandId) throw new VerifiedRunError(\"command_conflict\");\n\tconst own = openPublishIntents(journal).find((event) => event.commandId === command.commandId);\n\tif (own) {\n\t\tif (\n\t\t\town.candidateDigest !== command.candidateDigest ||\n\t\t\town.parentOid !== command.parentOid ||\n\t\t\town.receiptDigest !== command.receiptDigest ||\n\t\t\town.policyDigest !== command.policyDigest\n\t\t)\n\t\t\tthrow new VerifiedRunError(\"command_conflict\");\n\t\treturn terminalFor(journal, command.commandId) ? \"completed\" : \"resume\";\n\t}\n\tif (command.expectedRevision !== journal.state.revision || command.expectedGeneration !== journal.state.generation)\n\t\tthrow new VerifiedRunError(\"stale_revision\");\n\tif (journal.state.publication === \"intent\") throw new VerifiedRunError(\"reconciliation_required\");\n\tif (journal.state.publication === \"accepted\") throw new VerifiedRunError(\"already_published\");\n\treturn \"new\";\n}\n\nexport interface PublishOptions {\n\t/** Fault injection after a successful CAS, before the result record. */\n\treadonly afterCas?: () => void;\n\treadonly signal?: AbortSignal;\n\t/** One monotonic deadline shared by all Git writes, never replenished per file. */\n\treadonly timeoutMs?: number;\n\treadonly authority?: RunAuthority;\n}\n\nexport function publishVerifiedRun(\n\trunPath: string,\n\tcommand: RunPublishCommand,\n\toptions: PublishOptions = {},\n): RunProjection {\n\tconst initial = requireRunJournal(runPath);\n\tif (publishDisposition(initial, command) === \"completed\") return initial.state;\n\tif (options.signal?.aborted) throw new VerifiedRunError(\"cancelled\");\n\tconst owner = acquireSessionOwnerLeaseSync(journalPath(runPath));\n\tlet opened: RunAuthority | null = null;\n\ttry {\n\t\tconst snapshot = requireRunJournal(runPath);\n\t\tif (publishDisposition(snapshot, command) === \"completed\") return snapshot.state;\n\t\tif (!options.authority) opened = openRunAuthority(runPath);\n\t\tconst authority = options.authority ?? opened;\n\t\tif (!authority) throw new VerifiedRunError(\"authority\");\n\t\tconst journal = new VerifiedRunJournal(runPath, owner);\n\t\treturn executePublish(runPath, snapshot, journal, command, options, authority);\n\t} finally {\n\t\ttry {\n\t\t\topened?.store.release();\n\t\t} finally {\n\t\t\towner.release();\n\t\t}\n\t}\n}\n\nexport function recordPublished(\n\tjournal: VerifiedRunJournal,\n\tcommand: RunPublishCommand,\n\tcandidateOid: string,\n): RunProjection {\n\treturn journal.append({\n\t\tkind: \"published\",\n\t\tcommandId: command.commandId,\n\t\tcandidateOid,\n\t\tpreviousOid: command.parentOid,\n\t});\n}\n\nfunction executePublish(\n\trunPath: string,\n\tsnapshot: JournalSnapshot,\n\tjournal: VerifiedRunJournal,\n\tcommand: RunPublishCommand,\n\toptions: PublishOptions,\n\tauthority: RunAuthority,\n): RunProjection {\n\tconst budget = new GitOperationBudget({ signal: options.signal, timeoutMs: options.timeoutMs ?? 60_000 });\n\tbudget.remaining();\n\tconst { contract, state } = assertPublishable(snapshot, command, runPath);\n\tconst repoRoot = realpathSync(contract.workspace.root);\n\tassertGitWorkspaceRoot(repoRoot, budget);\n\tconst zero = zeroOid(repoObjectFormat(repoRoot, budget));\n\tif (command.parentOid.length !== zero.length) throw new VerifiedRunError(\"invalid_binding\");\n\tconst resumed = state.publication === \"intent\" && state.publicationCommandId === command.commandId;\n\t// Recovery observes the existing ref; it does not restart a terminal/unknown effect.\n\tif (resumed) {\n\t\tconst sealed = state.publicationCandidateOid;\n\t\tif (!sealed) throw new VerifiedRunError(\"invalid_binding\");\n\t\tconst observed = resolveRef(repoRoot, OMK_ACCEPTED_REF, budget);\n\t\tif (observed === sealed && objectExists(repoRoot, sealed, budget))\n\t\t\treturn recordPublished(journal, command, sealed);\n\t\tif ((observed ?? zero) !== command.parentOid)\n\t\t\treturn journal.append({\n\t\t\t\tkind: \"publish_failed\",\n\t\t\t\tcommandId: command.commandId,\n\t\t\t\tcode: \"reconciliation-required\",\n\t\t\t});\n\t}\n\tbudget.remaining();\n\tconst refClaims = [\n\t\t{\n\t\t\tnamespace: \"git-ref\",\n\t\t\tinstanceId: \"verified-run\",\n\t\t\tcanonicalKey: `omk-accepted-ref/${digestObject(repoRoot).slice(0, 16)}`,\n\t\t\taccess: \"write\",\n\t\t\tgeneration: String(state.generation),\n\t\t},\n\t];\n\tconst admission = authority.store.acquire({\n\t\tsessionId: authority.sessionId,\n\t\tincarnation: authority.incarnation,\n\t\tcommandId: command.commandId,\n\t\tintentDigest: digestObject({\n\t\t\tcandidateDigest: command.candidateDigest,\n\t\t\tparentOid: command.parentOid,\n\t\t\treceiptDigest: command.receiptDigest,\n\t\t\tpolicyDigest: command.policyDigest,\n\t\t\ttargetRef: OMK_ACCEPTED_REF,\n\t\t}),\n\t\tclaims: refClaims,\n\t\tnow: Date.now(),\n\t\tttl: 60_000,\n\t});\n\tif (admission.status !== \"granted\") throw new VerifiedRunError(\"authority_blocked\");\n\tconst token = admission.token;\n\t// Failure here must not settle somebody else's running/quarantined grant.\n\tassertPublishEffectStart(authority.store, token, refClaims, admission.duplicate);\n\tlet uncertain = false;\n\ttry {\n\t\tbudget.remaining();\n\t\tconst candidate = loadCandidate(runPath, state.candidateDigest, contract.budget);\n\t\tconst candidateOid = sealCandidateCommit(\n\t\t\trepoRoot,\n\t\t\t{\n\t\t\t\tmanifest: candidate.manifest,\n\t\t\t\tcontents: candidate.contents,\n\t\t\t\tparentOid: command.parentOid,\n\t\t\t\tzeroOid: zero,\n\t\t\t\trunId: contract.runId,\n\t\t\t\tcandidateDigest: state.candidateDigest,\n\t\t\t\treceiptDigest: state.receiptDigest,\n\t\t\t},\n\t\t\tbudget,\n\t\t);\n\t\tif (resumed) {\n\t\t\tif (state.publicationCandidateOid !== candidateOid) throw new VerifiedRunError(\"invalid_binding\");\n\t\t} else {\n\t\t\tjournal.append({\n\t\t\t\tkind: \"publish_intent\",\n\t\t\t\tcommandId: command.commandId,\n\t\t\t\tcandidateDigest: state.candidateDigest,\n\t\t\t\tcandidateOid,\n\t\t\t\tparentOid: command.parentOid,\n\t\t\t\ttargetRef: OMK_ACCEPTED_REF,\n\t\t\t\treceiptDigest: state.receiptDigest,\n\t\t\t\tpolicyDigest: command.policyDigest,\n\t\t\t\tgeneration: state.generation,\n\t\t\t});\n\t\t}\n\t\tconst observed = resolveRef(repoRoot, OMK_ACCEPTED_REF, budget);\n\t\tif (observed === candidateOid && objectExists(repoRoot, candidateOid, budget))\n\t\t\treturn recordPublished(journal, command, candidateOid);\n\t\tif ((observed ?? zero) !== command.parentOid)\n\t\t\treturn journal.append({\n\t\t\t\tkind: \"publish_failed\",\n\t\t\t\tcommandId: command.commandId,\n\t\t\t\tcode: resumed ? \"reconciliation-required\" : \"stale-parent\",\n\t\t\t});\n\t\tbudget.remaining();\n\t\tif (!authority.store.effectAuthorized(token, refClaims)) throw new VerifiedRunError(\"authority\");\n\t\ttry {\n\t\t\tcasRef(repoRoot, OMK_ACCEPTED_REF, candidateOid, command.parentOid, budget);\n\t\t} catch (error) {\n\t\t\tif (!(error instanceof GitRefCasError)) throw error;\n\t\t\tconst recoveryBudget = new GitOperationBudget({ timeoutMs: 5_000 });\n\t\t\tconst after = resolveRef(repoRoot, OMK_ACCEPTED_REF, recoveryBudget);\n\t\t\tif (after === candidateOid && objectExists(repoRoot, candidateOid, recoveryBudget))\n\t\t\t\treturn recordPublished(journal, command, candidateOid);\n\t\t\treturn journal.append({\n\t\t\t\tkind: \"publish_failed\",\n\t\t\t\tcommandId: command.commandId,\n\t\t\t\tcode: after === observed ? \"ref-rejected\" : resumed ? \"reconciliation-required\" : \"stale-parent\",\n\t\t\t});\n\t\t}\n\t\t// Once CAS succeeded, cancellation must not undo the committed publication.\n\t\toptions.afterCas?.();\n\t\treturn recordPublished(journal, command, candidateOid);\n\t} catch (error) {\n\t\tuncertain = error instanceof VerifiedRunError && error.code === \"git_outcome_unknown\";\n\t\tthrow error;\n\t} finally {\n\t\tif (uncertain) authority.store.cancel(token);\n\t\telse authority.store.confirmTerminated(token);\n\t}\n}\n"]}
|