open-multi-agent-kit 0.98.3 → 0.98.5
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 +44 -0
- package/README.md +12 -2
- package/dist/cli/args.d.ts +1 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +14 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +3 -0
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/mcp-attach.d.ts +3 -3
- package/dist/cli/mcp-attach.d.ts.map +1 -1
- package/dist/cli/mcp-attach.js +5 -4
- package/dist/cli/mcp-attach.js.map +1 -1
- package/dist/cli/model-contract.d.ts +5 -0
- package/dist/cli/model-contract.d.ts.map +1 -0
- package/dist/cli/model-contract.js +45 -0
- package/dist/cli/model-contract.js.map +1 -0
- package/dist/commands/adaptorch-doctor-cli.d.ts.map +1 -1
- package/dist/commands/adaptorch-doctor-cli.js +32 -10
- package/dist/commands/adaptorch-doctor-cli.js.map +1 -1
- package/dist/commands/init-cli.d.ts +12 -0
- package/dist/commands/init-cli.d.ts.map +1 -0
- package/dist/commands/init-cli.js +76 -0
- package/dist/commands/init-cli.js.map +1 -0
- package/dist/commands/provider-sync-cli.d.ts +27 -0
- package/dist/commands/provider-sync-cli.d.ts.map +1 -0
- package/dist/commands/provider-sync-cli.js +177 -0
- package/dist/commands/provider-sync-cli.js.map +1 -0
- package/dist/commands/run-command.d.ts +9 -0
- package/dist/commands/run-command.d.ts.map +1 -0
- package/dist/commands/run-command.js +34 -0
- package/dist/commands/run-command.js.map +1 -0
- package/dist/commands/verified-run-cli.d.ts +6 -0
- package/dist/commands/verified-run-cli.d.ts.map +1 -0
- package/dist/commands/verified-run-cli.js +190 -0
- package/dist/commands/verified-run-cli.js.map +1 -0
- package/dist/core/active-skill-state.d.ts +7 -0
- package/dist/core/active-skill-state.d.ts.map +1 -0
- package/dist/core/active-skill-state.js +25 -0
- package/dist/core/active-skill-state.js.map +1 -0
- package/dist/core/agent-session-services.d.ts +10 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +43 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +7 -9
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +91 -126
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/codex-chatgpt-web-bridge.d.ts +99 -0
- package/dist/core/codex-chatgpt-web-bridge.d.ts.map +1 -0
- package/dist/core/codex-chatgpt-web-bridge.js +192 -0
- package/dist/core/codex-chatgpt-web-bridge.js.map +1 -0
- package/dist/core/codex-chatgpt-web-sync.d.ts +50 -0
- package/dist/core/codex-chatgpt-web-sync.d.ts.map +1 -0
- package/dist/core/codex-chatgpt-web-sync.js +119 -0
- package/dist/core/codex-chatgpt-web-sync.js.map +1 -0
- package/dist/core/compaction/compaction-headroom.d.ts +30 -0
- package/dist/core/compaction/compaction-headroom.d.ts.map +1 -0
- package/dist/core/compaction/compaction-headroom.js +48 -0
- package/dist/core/compaction/compaction-headroom.js.map +1 -0
- package/dist/core/compaction/compaction.d.ts +2 -29
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +19 -47
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/overflow-retry-guard.d.ts +20 -0
- package/dist/core/compaction/overflow-retry-guard.d.ts.map +1 -0
- package/dist/core/compaction/overflow-retry-guard.js +38 -0
- package/dist/core/compaction/overflow-retry-guard.js.map +1 -0
- package/dist/core/context-budget-headroom-types.d.ts.map +1 -1
- package/dist/core/context-budget-headroom-types.js +1 -1
- package/dist/core/context-budget-headroom-types.js.map +1 -1
- package/dist/core/context-budget-token-counter-types.d.ts +27 -0
- package/dist/core/context-budget-token-counter-types.d.ts.map +1 -0
- package/dist/core/context-budget-token-counter-types.js +2 -0
- package/dist/core/context-budget-token-counter-types.js.map +1 -0
- package/dist/core/context-budget-token-counter.d.ts +2 -26
- package/dist/core/context-budget-token-counter.d.ts.map +1 -1
- package/dist/core/context-budget-token-counter.js +2 -0
- package/dist/core/context-budget-token-counter.js.map +1 -1
- package/dist/core/context-budget-v2-scoring.d.ts.map +1 -1
- package/dist/core/context-budget-v2-scoring.js +14 -10
- package/dist/core/context-budget-v2-scoring.js.map +1 -1
- package/dist/core/domain-router.d.ts.map +1 -1
- package/dist/core/domain-router.js +1 -1
- package/dist/core/domain-router.js.map +1 -1
- package/dist/core/grok-harness-dispatch.d.ts +4 -0
- package/dist/core/grok-harness-dispatch.d.ts.map +1 -1
- package/dist/core/grok-harness-dispatch.js +20 -3
- package/dist/core/grok-harness-dispatch.js.map +1 -1
- package/dist/core/grok-harness.d.ts +15 -9
- package/dist/core/grok-harness.d.ts.map +1 -1
- package/dist/core/grok-harness.js +34 -8
- package/dist/core/grok-harness.js.map +1 -1
- package/dist/core/mcp/tools.d.ts +2 -2
- package/dist/core/mcp/tools.d.ts.map +1 -1
- package/dist/core/mcp/tools.js +29 -3
- package/dist/core/mcp/tools.js.map +1 -1
- package/dist/core/model-registry-schema.d.ts +1081 -0
- package/dist/core/model-registry-schema.d.ts.map +1 -0
- package/dist/core/model-registry-schema.js +148 -0
- package/dist/core/model-registry-schema.js.map +1 -0
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +1 -146
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +2 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +2 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/prompt-preset.d.ts +1 -1
- package/dist/core/prompt-preset.d.ts.map +1 -1
- package/dist/core/prompt-preset.js +16 -1
- package/dist/core/prompt-preset.js.map +1 -1
- package/dist/core/prompt-settlement.d.ts +4 -3
- package/dist/core/prompt-settlement.d.ts.map +1 -1
- package/dist/core/prompt-settlement.js.map +1 -1
- package/dist/core/provider-display-names.d.ts.map +1 -1
- package/dist/core/provider-display-names.js +1 -0
- package/dist/core/provider-display-names.js.map +1 -1
- package/dist/core/provider-resilience.d.ts +8 -0
- package/dist/core/provider-resilience.d.ts.map +1 -1
- package/dist/core/provider-resilience.js +20 -3
- package/dist/core/provider-resilience.js.map +1 -1
- package/dist/core/provider-usage-types.d.ts +42 -0
- package/dist/core/provider-usage-types.d.ts.map +1 -0
- package/dist/core/provider-usage-types.js +2 -0
- package/dist/core/provider-usage-types.js.map +1 -0
- package/dist/core/provider-usage.d.ts +2 -31
- package/dist/core/provider-usage.d.ts.map +1 -1
- package/dist/core/provider-usage.js +4 -0
- package/dist/core/provider-usage.js.map +1 -1
- package/dist/core/redaction.d.ts.map +1 -1
- package/dist/core/redaction.js +18 -2
- package/dist/core/redaction.js.map +1 -1
- package/dist/core/run-budget-policy.d.ts +18 -0
- package/dist/core/run-budget-policy.d.ts.map +1 -0
- package/dist/core/run-budget-policy.js +52 -0
- package/dist/core/run-budget-policy.js.map +1 -0
- package/dist/core/run-budget.d.ts +33 -0
- package/dist/core/run-budget.d.ts.map +1 -0
- package/dist/core/run-budget.js +89 -0
- package/dist/core/run-budget.js.map +1 -0
- package/dist/core/run-execution-api.d.ts +15 -0
- package/dist/core/run-execution-api.d.ts.map +1 -0
- package/dist/core/run-execution-api.js +7 -0
- package/dist/core/run-execution-api.js.map +1 -0
- package/dist/core/run-journal.d.ts.map +1 -1
- package/dist/core/run-journal.js +30 -208
- package/dist/core/run-journal.js.map +1 -1
- package/dist/core/sandbox/policy-merge.d.ts +6 -0
- package/dist/core/sandbox/policy-merge.d.ts.map +1 -0
- package/dist/core/sandbox/policy-merge.js +74 -0
- package/dist/core/sandbox/policy-merge.js.map +1 -0
- package/dist/core/sandbox/policy-paths.d.ts +4 -0
- package/dist/core/sandbox/policy-paths.d.ts.map +1 -0
- package/dist/core/sandbox/policy-paths.js +21 -0
- package/dist/core/sandbox/policy-paths.js.map +1 -0
- package/dist/core/sandbox/policy-types.d.ts +75 -0
- package/dist/core/sandbox/policy-types.d.ts.map +1 -0
- package/dist/core/sandbox/policy-types.js +2 -0
- package/dist/core/sandbox/policy-types.js.map +1 -0
- package/dist/core/sandbox/policy.d.ts +3 -77
- package/dist/core/sandbox/policy.d.ts.map +1 -1
- package/dist/core/sandbox/policy.js +3 -98
- package/dist/core/sandbox/policy.js.map +1 -1
- package/dist/core/sdk-provider-stream.d.ts +14 -0
- package/dist/core/sdk-provider-stream.d.ts.map +1 -0
- package/dist/core/sdk-provider-stream.js +38 -0
- package/dist/core/sdk-provider-stream.js.map +1 -0
- package/dist/core/sdk.d.ts +5 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +17 -33
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-bash-service.d.ts +2 -2
- package/dist/core/session-bash-service.d.ts.map +1 -1
- package/dist/core/session-bash-service.js +21 -9
- package/dist/core/session-bash-service.js.map +1 -1
- package/dist/core/session-failure-cause.d.ts.map +1 -1
- package/dist/core/session-failure-cause.js +15 -3
- package/dist/core/session-failure-cause.js.map +1 -1
- package/dist/core/session-prompt-lifecycle.d.ts +25 -0
- package/dist/core/session-prompt-lifecycle.d.ts.map +1 -0
- package/dist/core/session-prompt-lifecycle.js +87 -0
- package/dist/core/session-prompt-lifecycle.js.map +1 -0
- package/dist/core/session-run-budget.d.ts +28 -0
- package/dist/core/session-run-budget.d.ts.map +1 -0
- package/dist/core/session-run-budget.js +127 -0
- package/dist/core/session-run-budget.js.map +1 -0
- package/dist/core/session-run-termination.d.ts +18 -0
- package/dist/core/session-run-termination.d.ts.map +1 -0
- package/dist/core/session-run-termination.js +72 -0
- package/dist/core/session-run-termination.js.map +1 -0
- package/dist/core/session-termination-types.d.ts +97 -0
- package/dist/core/session-termination-types.d.ts.map +1 -0
- package/dist/core/session-termination-types.js +26 -0
- package/dist/core/session-termination-types.js.map +1 -0
- package/dist/core/session-termination.d.ts +3 -97
- package/dist/core/session-termination.d.ts.map +1 -1
- package/dist/core/session-termination.js +25 -29
- package/dist/core/session-termination.js.map +1 -1
- package/dist/core/skill-selector.d.ts +40 -0
- package/dist/core/skill-selector.d.ts.map +1 -0
- package/dist/core/skill-selector.js +102 -0
- package/dist/core/skill-selector.js.map +1 -0
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/subagent-lane-launcher.d.ts +3 -2
- package/dist/core/subagent-lane-launcher.d.ts.map +1 -1
- package/dist/core/subagent-lane-launcher.js +24 -13
- package/dist/core/subagent-lane-launcher.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +2 -4
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/turn-metrics-record.d.ts +55 -0
- package/dist/core/turn-metrics-record.d.ts.map +1 -0
- package/dist/core/turn-metrics-record.js +149 -0
- package/dist/core/turn-metrics-record.js.map +1 -0
- package/dist/core/turn-metrics.d.ts +4 -56
- package/dist/core/turn-metrics.d.ts.map +1 -1
- package/dist/core/turn-metrics.js +12 -60
- package/dist/core/turn-metrics.js.map +1 -1
- package/dist/core/verified-run/broker.d.ts +26 -0
- package/dist/core/verified-run/broker.d.ts.map +1 -0
- package/dist/core/verified-run/broker.js +210 -0
- package/dist/core/verified-run/broker.js.map +1 -0
- package/dist/core/verified-run/candidate.d.ts +24 -0
- package/dist/core/verified-run/candidate.d.ts.map +1 -0
- package/dist/core/verified-run/candidate.js +167 -0
- package/dist/core/verified-run/candidate.js.map +1 -0
- package/dist/core/verified-run/check-receipt.d.ts +18 -0
- package/dist/core/verified-run/check-receipt.d.ts.map +1 -0
- package/dist/core/verified-run/check-receipt.js +92 -0
- package/dist/core/verified-run/check-receipt.js.map +1 -0
- package/dist/core/verified-run/coordinator.d.ts +39 -0
- package/dist/core/verified-run/coordinator.d.ts.map +1 -0
- package/dist/core/verified-run/coordinator.js +190 -0
- package/dist/core/verified-run/coordinator.js.map +1 -0
- package/dist/core/verified-run/dag-candidates.d.ts +8 -0
- package/dist/core/verified-run/dag-candidates.d.ts.map +1 -0
- package/dist/core/verified-run/dag-candidates.js +65 -0
- package/dist/core/verified-run/dag-candidates.js.map +1 -0
- package/dist/core/verified-run/dag-phase.d.ts +7 -0
- package/dist/core/verified-run/dag-phase.d.ts.map +1 -0
- package/dist/core/verified-run/dag-phase.js +92 -0
- package/dist/core/verified-run/dag-phase.js.map +1 -0
- package/dist/core/verified-run/dag-projection.d.ts +7 -0
- package/dist/core/verified-run/dag-projection.d.ts.map +1 -0
- package/dist/core/verified-run/dag-projection.js +90 -0
- package/dist/core/verified-run/dag-projection.js.map +1 -0
- package/dist/core/verified-run/dag-recovery.d.ts +13 -0
- package/dist/core/verified-run/dag-recovery.d.ts.map +1 -0
- package/dist/core/verified-run/dag-recovery.js +98 -0
- package/dist/core/verified-run/dag-recovery.js.map +1 -0
- package/dist/core/verified-run/dag-retry-projection.d.ts +9 -0
- package/dist/core/verified-run/dag-retry-projection.d.ts.map +1 -0
- package/dist/core/verified-run/dag-retry-projection.js +43 -0
- package/dist/core/verified-run/dag-retry-projection.js.map +1 -0
- package/dist/core/verified-run/dag-types.d.ts +47 -0
- package/dist/core/verified-run/dag-types.d.ts.map +1 -0
- package/dist/core/verified-run/dag-types.js +2 -0
- package/dist/core/verified-run/dag-types.js.map +1 -0
- package/dist/core/verified-run/event-parser.d.ts +3 -0
- package/dist/core/verified-run/event-parser.d.ts.map +1 -0
- package/dist/core/verified-run/event-parser.js +153 -0
- package/dist/core/verified-run/event-parser.js.map +1 -0
- package/dist/core/verified-run/events.d.ts +4 -0
- package/dist/core/verified-run/events.d.ts.map +1 -0
- package/dist/core/verified-run/events.js +3 -0
- package/dist/core/verified-run/events.js.map +1 -0
- package/dist/core/verified-run/evidence-binding.d.ts +18 -0
- package/dist/core/verified-run/evidence-binding.d.ts.map +1 -0
- package/dist/core/verified-run/evidence-binding.js +81 -0
- package/dist/core/verified-run/evidence-binding.js.map +1 -0
- package/dist/core/verified-run/evidence.d.ts +27 -0
- package/dist/core/verified-run/evidence.d.ts.map +1 -0
- package/dist/core/verified-run/evidence.js +100 -0
- package/dist/core/verified-run/evidence.js.map +1 -0
- package/dist/core/verified-run/journal.d.ts +32 -0
- package/dist/core/verified-run/journal.d.ts.map +1 -0
- package/dist/core/verified-run/journal.js +103 -0
- package/dist/core/verified-run/journal.js.map +1 -0
- package/dist/core/verified-run/namespace-identity.d.ts +11 -0
- package/dist/core/verified-run/namespace-identity.d.ts.map +1 -0
- package/dist/core/verified-run/namespace-identity.js +77 -0
- package/dist/core/verified-run/namespace-identity.js.map +1 -0
- package/dist/core/verified-run/owned-execution.d.ts +21 -0
- package/dist/core/verified-run/owned-execution.d.ts.map +1 -0
- package/dist/core/verified-run/owned-execution.js +43 -0
- package/dist/core/verified-run/owned-execution.js.map +1 -0
- package/dist/core/verified-run/phase-context.d.ts +9 -0
- package/dist/core/verified-run/phase-context.d.ts.map +1 -0
- package/dist/core/verified-run/phase-context.js +2 -0
- package/dist/core/verified-run/phase-context.js.map +1 -0
- package/dist/core/verified-run/process-gate.d.ts +5 -0
- package/dist/core/verified-run/process-gate.d.ts.map +1 -0
- package/dist/core/verified-run/process-gate.js +31 -0
- package/dist/core/verified-run/process-gate.js.map +1 -0
- package/dist/core/verified-run/projection.d.ts +4 -0
- package/dist/core/verified-run/projection.d.ts.map +1 -0
- package/dist/core/verified-run/projection.js +219 -0
- package/dist/core/verified-run/projection.js.map +1 -0
- package/dist/core/verified-run/recovery-clock.d.ts +19 -0
- package/dist/core/verified-run/recovery-clock.d.ts.map +1 -0
- package/dist/core/verified-run/recovery-clock.js +69 -0
- package/dist/core/verified-run/recovery-clock.js.map +1 -0
- package/dist/core/verified-run/recovery-command.d.ts +11 -0
- package/dist/core/verified-run/recovery-command.d.ts.map +1 -0
- package/dist/core/verified-run/recovery-command.js +73 -0
- package/dist/core/verified-run/recovery-command.js.map +1 -0
- package/dist/core/verified-run/recovery-projection.d.ts +12 -0
- package/dist/core/verified-run/recovery-projection.d.ts.map +1 -0
- package/dist/core/verified-run/recovery-projection.js +88 -0
- package/dist/core/verified-run/recovery-projection.js.map +1 -0
- package/dist/core/verified-run/recovery.d.ts +12 -0
- package/dist/core/verified-run/recovery.d.ts.map +1 -0
- package/dist/core/verified-run/recovery.js +115 -0
- package/dist/core/verified-run/recovery.js.map +1 -0
- package/dist/core/verified-run/run-types.d.ts +103 -0
- package/dist/core/verified-run/run-types.d.ts.map +1 -0
- package/dist/core/verified-run/run-types.js +2 -0
- package/dist/core/verified-run/run-types.js.map +1 -0
- package/dist/core/verified-run/scripted-writer.d.ts +15 -0
- package/dist/core/verified-run/scripted-writer.d.ts.map +1 -0
- package/dist/core/verified-run/scripted-writer.js +94 -0
- package/dist/core/verified-run/scripted-writer.js.map +1 -0
- package/dist/core/verified-run/session-port.d.ts +27 -0
- package/dist/core/verified-run/session-port.d.ts.map +1 -0
- package/dist/core/verified-run/session-port.js +2 -0
- package/dist/core/verified-run/session-port.js.map +1 -0
- package/dist/core/verified-run/storage.d.ts +15 -0
- package/dist/core/verified-run/storage.d.ts.map +1 -0
- package/dist/core/verified-run/storage.js +96 -0
- package/dist/core/verified-run/storage.js.map +1 -0
- package/dist/core/verified-run/verification-phase.d.ts +5 -0
- package/dist/core/verified-run/verification-phase.d.ts.map +1 -0
- package/dist/core/verified-run/verification-phase.js +56 -0
- package/dist/core/verified-run/verification-phase.js.map +1 -0
- package/dist/core/verified-run/work-recovery.d.ts +8 -0
- package/dist/core/verified-run/work-recovery.d.ts.map +1 -0
- package/dist/core/verified-run/work-recovery.js +44 -0
- package/dist/core/verified-run/work-recovery.js.map +1 -0
- package/dist/core/verified-run/writer-completion.d.ts +4 -0
- package/dist/core/verified-run/writer-completion.d.ts.map +1 -0
- package/dist/core/verified-run/writer-completion.js +27 -0
- package/dist/core/verified-run/writer-completion.js.map +1 -0
- package/dist/core/verified-run/writer-phase.d.ts +8 -0
- package/dist/core/verified-run/writer-phase.d.ts.map +1 -0
- package/dist/core/verified-run/writer-phase.js +76 -0
- package/dist/core/verified-run/writer-phase.js.map +1 -0
- package/dist/core/verified-run/writer-projection.d.ts +11 -0
- package/dist/core/verified-run/writer-projection.d.ts.map +1 -0
- package/dist/core/verified-run/writer-projection.js +70 -0
- package/dist/core/verified-run/writer-projection.js.map +1 -0
- package/dist/core/verified-run/writer-recovery.d.ts +16 -0
- package/dist/core/verified-run/writer-recovery.d.ts.map +1 -0
- package/dist/core/verified-run/writer-recovery.js +107 -0
- package/dist/core/verified-run/writer-recovery.js.map +1 -0
- package/dist/core/workload-permit-pool.d.ts +1 -3
- package/dist/core/workload-permit-pool.d.ts.map +1 -1
- package/dist/core/workload-permit-pool.js +11 -11
- package/dist/core/workload-permit-pool.js.map +1 -1
- package/dist/guardrails/evidence-system.d.ts +1 -1
- package/dist/guardrails/evidence-system.d.ts.map +1 -1
- package/dist/guardrails/evidence-system.js +18 -29
- package/dist/guardrails/evidence-system.js.map +1 -1
- package/dist/guardrails/merge-gate-result.d.ts +4 -0
- package/dist/guardrails/merge-gate-result.d.ts.map +1 -0
- package/dist/guardrails/merge-gate-result.js +32 -0
- package/dist/guardrails/merge-gate-result.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +17 -23
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/session-failure.d.ts +13 -0
- package/dist/modes/interactive/components/session-failure.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-failure.js +81 -0
- package/dist/modes/interactive/components/session-failure.js.map +1 -0
- package/dist/modes/interactive/interactive-login-options.d.ts +27 -0
- package/dist/modes/interactive/interactive-login-options.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-login-options.js +54 -0
- package/dist/modes/interactive/interactive-login-options.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +8 -4
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +183 -171
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/interactive-resume-command.d.ts +3 -0
- package/dist/modes/interactive/interactive-resume-command.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-resume-command.js +24 -0
- package/dist/modes/interactive/interactive-resume-command.js.map +1 -0
- package/dist/modes/interactive/interactive-tool-result.d.ts +32 -0
- package/dist/modes/interactive/interactive-tool-result.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-tool-result.js +59 -0
- package/dist/modes/interactive/interactive-tool-result.js.map +1 -0
- package/dist/modes/interactive/tui-diagnostics.d.ts +36 -0
- package/dist/modes/interactive/tui-diagnostics.d.ts.map +1 -0
- package/dist/modes/interactive/tui-diagnostics.js +105 -0
- package/dist/modes/interactive/tui-diagnostics.js.map +1 -0
- package/dist/modes/interactive/tui-runtime-info.d.ts +20 -0
- package/dist/modes/interactive/tui-runtime-info.d.ts.map +1 -0
- package/dist/modes/interactive/tui-runtime-info.js +76 -0
- package/dist/modes/interactive/tui-runtime-info.js.map +1 -0
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +22 -0
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +10 -60
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/terminal-links.d.ts +13 -0
- package/dist/utils/terminal-links.d.ts.map +1 -0
- package/dist/utils/terminal-links.js +68 -0
- package/dist/utils/terminal-links.js.map +1 -0
- package/dist/utils/windows-clipboard-image.d.ts +16 -0
- package/dist/utils/windows-clipboard-image.d.ts.map +1 -0
- package/dist/utils/windows-clipboard-image.js +87 -0
- package/dist/utils/windows-clipboard-image.js.map +1 -0
- package/docs/adaptorch-onboarding.md +80 -0
- package/docs/containerization.md +12 -0
- package/docs/context-files.md +97 -0
- package/docs/correctness-wall.md +8 -0
- package/docs/custom-provider.md +35 -0
- package/docs/development.md +28 -3
- package/docs/environment-variables.md +2 -0
- package/docs/grok-harness.md +4 -0
- package/docs/harness-boundaries.md +154 -0
- package/docs/harness-improvements.md +90 -0
- package/docs/json.md +19 -0
- package/docs/keybindings.md +2 -2
- package/docs/mcp.md +22 -2
- package/docs/metrics.md +66 -16
- package/docs/model-catalog-refresh.md +190 -0
- package/docs/model-contract.md +168 -0
- package/docs/models.md +21 -4
- package/docs/provider-resilience.md +5 -3
- package/docs/providers.md +68 -1
- package/docs/quickstart.md +4 -0
- package/docs/release-audit-0.98.4.md +112 -0
- package/docs/release-audit-0.98.5.md +84 -0
- package/docs/review-bundle-followup.md +195 -0
- package/docs/run-protocol.md +33 -1
- package/docs/runtime-algorithms.md +45 -0
- package/docs/sdk.md +204 -2
- package/docs/sessions.md +1 -1
- package/docs/settings.md +17 -1
- package/docs/skills.md +2 -0
- package/docs/tb21-audit.md +131 -0
- package/docs/terminal-setup.md +20 -0
- package/docs/usage.md +77 -1
- package/docs/verified-run-testing.md +417 -0
- package/docs/verified-run.md +388 -0
- package/docs/windows.md +48 -0
- package/examples/README.md +4 -0
- package/examples/context/AGENTS.md +64 -0
- package/examples/context/CLAUDE.md +17 -0
- package/examples/context/INTERNET.md +42 -0
- 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/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 -6
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { reduceDagEvent } from "./dag-projection.js";
|
|
2
|
+
import { reduceRecoveryEvent } from "./recovery-projection.js";
|
|
3
|
+
import { VerifiedRunError } from "./storage.js";
|
|
4
|
+
import { acceptWriterDispatch, reduceWriterEvent } from "./writer-projection.js";
|
|
5
|
+
/** Deterministic replay only. Recovery observations are supplied by the trusted host adapter. */
|
|
6
|
+
export function projectRun(events) {
|
|
7
|
+
const first = events[0];
|
|
8
|
+
if (first?.kind !== "created" || first.contract.runId !== first.command.runId)
|
|
9
|
+
throw new VerifiedRunError("integrity");
|
|
10
|
+
const context = {
|
|
11
|
+
contract: first.contract,
|
|
12
|
+
writerFinished: false,
|
|
13
|
+
writerStarted: false,
|
|
14
|
+
producerStarted: false,
|
|
15
|
+
writerCommands: 0,
|
|
16
|
+
requestBaseline: 0,
|
|
17
|
+
requests: new Set(),
|
|
18
|
+
state: {
|
|
19
|
+
runId: first.contract.runId,
|
|
20
|
+
revision: 1,
|
|
21
|
+
generation: 1,
|
|
22
|
+
execution: "ready",
|
|
23
|
+
settlement: "open",
|
|
24
|
+
verification: "not_requested",
|
|
25
|
+
application: "not_requested",
|
|
26
|
+
candidateDigest: null,
|
|
27
|
+
inputDigest: null,
|
|
28
|
+
receiptDigest: null,
|
|
29
|
+
failure: null,
|
|
30
|
+
activeExecutionIds: [],
|
|
31
|
+
writerOpen: false,
|
|
32
|
+
modelRequests: 0,
|
|
33
|
+
tasks: first.contract.profile === "linux-command-dag-v1"
|
|
34
|
+
? first.contract.writer.tasks.map((task) => ({
|
|
35
|
+
taskId: task.id,
|
|
36
|
+
attempt: 0,
|
|
37
|
+
generation: 1,
|
|
38
|
+
status: "pending",
|
|
39
|
+
inputDigest: null,
|
|
40
|
+
outputDigest: null,
|
|
41
|
+
failure: null,
|
|
42
|
+
}))
|
|
43
|
+
: [],
|
|
44
|
+
budget: null,
|
|
45
|
+
environmentDigest: null,
|
|
46
|
+
verificationDeadlineMs: null,
|
|
47
|
+
lastClockMs: null,
|
|
48
|
+
processes: [],
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
const dispatched = new Set();
|
|
52
|
+
const checked = new Set();
|
|
53
|
+
const commands = new Set([first.command.commandId]);
|
|
54
|
+
let activeRole = "writer";
|
|
55
|
+
for (const event of events.slice(1)) {
|
|
56
|
+
const state = context.state;
|
|
57
|
+
if (state.execution === "failed" || state.receiptDigest)
|
|
58
|
+
throw new VerifiedRunError("integrity");
|
|
59
|
+
switch (event.kind) {
|
|
60
|
+
case "created":
|
|
61
|
+
throw new VerifiedRunError("integrity");
|
|
62
|
+
case "budget_anchored": {
|
|
63
|
+
const budget = event.budget;
|
|
64
|
+
const limits = first.contract.budget;
|
|
65
|
+
if (state.revision !== 1 ||
|
|
66
|
+
state.budget ||
|
|
67
|
+
budget.workDeadlineMs - budget.startedMs !== limits.workMs ||
|
|
68
|
+
budget.verifyCapMs - budget.workDeadlineMs !== limits.verifyMs ||
|
|
69
|
+
budget.cleanupDeadlineMs - budget.verifyCapMs !== limits.cleanupMs)
|
|
70
|
+
throw new VerifiedRunError("integrity");
|
|
71
|
+
context.state = {
|
|
72
|
+
...state,
|
|
73
|
+
budget,
|
|
74
|
+
environmentDigest: event.environmentDigest,
|
|
75
|
+
lastClockMs: budget.startedMs,
|
|
76
|
+
};
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case "input_checkpoint":
|
|
80
|
+
if (state.revision !== 2 ||
|
|
81
|
+
!state.budget ||
|
|
82
|
+
state.inputDigest ||
|
|
83
|
+
event.digest !== first.contract.workspace.baseDigest)
|
|
84
|
+
throw new VerifiedRunError("integrity");
|
|
85
|
+
context.state = { ...state, inputDigest: event.digest };
|
|
86
|
+
break;
|
|
87
|
+
case "task_started":
|
|
88
|
+
case "task_finished":
|
|
89
|
+
case "tasks_paused":
|
|
90
|
+
reduceDagEvent(context, event);
|
|
91
|
+
break;
|
|
92
|
+
case "writer_opened":
|
|
93
|
+
case "model_request":
|
|
94
|
+
case "writer_closed":
|
|
95
|
+
reduceWriterEvent(context, event);
|
|
96
|
+
break;
|
|
97
|
+
case "dispatch": {
|
|
98
|
+
if (state.failure || state.activeExecutionIds.length || dispatched.has(event.executionId))
|
|
99
|
+
throw new VerifiedRunError("integrity");
|
|
100
|
+
if (event.role === "writer") {
|
|
101
|
+
acceptWriterDispatch(context, event);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
if (!context.writerFinished ||
|
|
105
|
+
state.writerOpen ||
|
|
106
|
+
!state.candidateDigest ||
|
|
107
|
+
event.claimId === null ||
|
|
108
|
+
!first.contract.checks.some((check) => check.claimId === event.claimId) ||
|
|
109
|
+
checked.has(event.claimId))
|
|
110
|
+
throw new VerifiedRunError("integrity");
|
|
111
|
+
checked.add(event.claimId);
|
|
112
|
+
}
|
|
113
|
+
dispatched.add(event.executionId);
|
|
114
|
+
activeRole = event.role;
|
|
115
|
+
context.state = {
|
|
116
|
+
...state,
|
|
117
|
+
execution: "running",
|
|
118
|
+
settlement: "draining",
|
|
119
|
+
activeExecutionIds: [event.executionId],
|
|
120
|
+
};
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
case "process_ready":
|
|
124
|
+
if (!state.budget ||
|
|
125
|
+
state.activeExecutionIds[0] !== event.executionId ||
|
|
126
|
+
event.identity.bootId !== state.budget.bootId ||
|
|
127
|
+
state.processes.some((item) => item.executionId === event.executionId))
|
|
128
|
+
throw new VerifiedRunError("integrity");
|
|
129
|
+
context.state = {
|
|
130
|
+
...state,
|
|
131
|
+
processes: [...state.processes, { executionId: event.executionId, identity: event.identity }],
|
|
132
|
+
};
|
|
133
|
+
break;
|
|
134
|
+
case "exited":
|
|
135
|
+
if (state.activeExecutionIds[0] !== event.executionId ||
|
|
136
|
+
(state.budget &&
|
|
137
|
+
event.failure === null &&
|
|
138
|
+
!state.processes.some((item) => item.executionId === event.executionId)))
|
|
139
|
+
throw new VerifiedRunError("integrity");
|
|
140
|
+
if (activeRole === "writer")
|
|
141
|
+
context.writerFinished = event.failure === null;
|
|
142
|
+
context.state = {
|
|
143
|
+
...state,
|
|
144
|
+
settlement: state.writerOpen ? "open" : "settled",
|
|
145
|
+
activeExecutionIds: [],
|
|
146
|
+
failure: event.failure,
|
|
147
|
+
};
|
|
148
|
+
break;
|
|
149
|
+
case "candidate": {
|
|
150
|
+
if (!context.writerFinished ||
|
|
151
|
+
state.writerOpen ||
|
|
152
|
+
state.failure ||
|
|
153
|
+
state.activeExecutionIds.length ||
|
|
154
|
+
state.candidateDigest ||
|
|
155
|
+
state.tasks.some((task) => task.status !== "succeeded" || task.generation !== state.generation))
|
|
156
|
+
throw new VerifiedRunError("integrity");
|
|
157
|
+
if (state.budget) {
|
|
158
|
+
if (event.observedMs === undefined ||
|
|
159
|
+
event.verificationDeadlineMs === undefined ||
|
|
160
|
+
event.observedMs < state.budget.startedMs ||
|
|
161
|
+
event.observedMs > state.budget.workDeadlineMs ||
|
|
162
|
+
event.verificationDeadlineMs !==
|
|
163
|
+
Math.min(event.observedMs + first.contract.budget.verifyMs, state.budget.verifyCapMs))
|
|
164
|
+
throw new VerifiedRunError("integrity");
|
|
165
|
+
}
|
|
166
|
+
else if (event.observedMs !== undefined || event.verificationDeadlineMs !== undefined)
|
|
167
|
+
throw new VerifiedRunError("integrity");
|
|
168
|
+
context.state = {
|
|
169
|
+
...state,
|
|
170
|
+
candidateDigest: event.digest,
|
|
171
|
+
verificationDeadlineMs: event.verificationDeadlineMs ?? null,
|
|
172
|
+
lastClockMs: event.observedMs ?? null,
|
|
173
|
+
};
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
case "resumed":
|
|
177
|
+
case "tasks_retried":
|
|
178
|
+
case "writer_restarted":
|
|
179
|
+
reduceRecoveryEvent(context, event, { commands, checked, activeRole });
|
|
180
|
+
break;
|
|
181
|
+
case "evaluated":
|
|
182
|
+
if (!state.candidateDigest ||
|
|
183
|
+
state.writerOpen ||
|
|
184
|
+
state.activeExecutionIds.length ||
|
|
185
|
+
checked.size !== first.contract.checks.length ||
|
|
186
|
+
(event.verified && state.failure))
|
|
187
|
+
throw new VerifiedRunError("integrity");
|
|
188
|
+
context.state = {
|
|
189
|
+
...state,
|
|
190
|
+
receiptDigest: event.receiptDigest,
|
|
191
|
+
execution: "succeeded",
|
|
192
|
+
verification: event.verified ? "verified" : "violated",
|
|
193
|
+
application: event.verified ? "candidate_ready" : "not_requested",
|
|
194
|
+
};
|
|
195
|
+
break;
|
|
196
|
+
case "failed":
|
|
197
|
+
context.state = {
|
|
198
|
+
...state,
|
|
199
|
+
execution: "failed",
|
|
200
|
+
failure: event.code,
|
|
201
|
+
verification: "inconclusive",
|
|
202
|
+
settlement: state.activeExecutionIds.length || state.writerOpen ? "quarantined" : "settled",
|
|
203
|
+
};
|
|
204
|
+
break;
|
|
205
|
+
default: {
|
|
206
|
+
const exhaustive = event;
|
|
207
|
+
throw new VerifiedRunError(String(exhaustive));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
context.state = { ...context.state, revision: state.revision + 1 };
|
|
211
|
+
}
|
|
212
|
+
return Object.freeze({
|
|
213
|
+
...context.state,
|
|
214
|
+
activeExecutionIds: Object.freeze([...context.state.activeExecutionIds]),
|
|
215
|
+
processes: Object.freeze(context.state.processes.map((item) => Object.freeze(item))),
|
|
216
|
+
tasks: Object.freeze(context.state.tasks.map((task) => Object.freeze(task))),
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=projection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projection.js","sourceRoot":"","sources":["../../../src/core/verified-run/projection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEjF,iGAAiG;AACjG,MAAM,UAAU,UAAU,CAAC,MAA2B,EAAiB;IACtE,MAAM,K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AAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;KAC5E,CAAC,CAAC;AAAA,CACH","sourcesContent":["import { reduceDagEvent } from \"./dag-projection.ts\";\nimport type { RunTaskProjection } from \"./dag-types.ts\";\nimport { reduceRecoveryEvent } from \"./recovery-projection.ts\";\nimport type { RunEvent, RunProjection, WriterReduction } from \"./run-types.ts\";\nimport { VerifiedRunError } from \"./storage.ts\";\nimport { acceptWriterDispatch, reduceWriterEvent } from \"./writer-projection.ts\";\n\n/** Deterministic replay only. Recovery observations are supplied by the trusted host adapter. */\nexport function projectRun(events: readonly RunEvent[]): RunProjection {\n\tconst first = events[0];\n\tif (first?.kind !== \"created\" || first.contract.runId !== first.command.runId)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tconst context: WriterReduction = {\n\t\tcontract: first.contract,\n\t\twriterFinished: false,\n\t\twriterStarted: false,\n\t\tproducerStarted: false,\n\t\twriterCommands: 0,\n\t\trequestBaseline: 0,\n\t\trequests: new Set(),\n\t\tstate: {\n\t\t\trunId: first.contract.runId,\n\t\t\trevision: 1,\n\t\t\tgeneration: 1,\n\t\t\texecution: \"ready\",\n\t\t\tsettlement: \"open\",\n\t\t\tverification: \"not_requested\",\n\t\t\tapplication: \"not_requested\",\n\t\t\tcandidateDigest: null,\n\t\t\tinputDigest: null,\n\t\t\treceiptDigest: null,\n\t\t\tfailure: null,\n\t\t\tactiveExecutionIds: [],\n\t\t\twriterOpen: false,\n\t\t\tmodelRequests: 0,\n\t\t\ttasks:\n\t\t\t\tfirst.contract.profile === \"linux-command-dag-v1\"\n\t\t\t\t\t? first.contract.writer.tasks.map(\n\t\t\t\t\t\t\t(task): RunTaskProjection => ({\n\t\t\t\t\t\t\t\ttaskId: task.id,\n\t\t\t\t\t\t\t\tattempt: 0,\n\t\t\t\t\t\t\t\tgeneration: 1,\n\t\t\t\t\t\t\t\tstatus: \"pending\",\n\t\t\t\t\t\t\t\tinputDigest: null,\n\t\t\t\t\t\t\t\toutputDigest: null,\n\t\t\t\t\t\t\t\tfailure: null,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t)\n\t\t\t\t\t: [],\n\t\t\tbudget: null,\n\t\t\tenvironmentDigest: null,\n\t\t\tverificationDeadlineMs: null,\n\t\t\tlastClockMs: null,\n\t\t\tprocesses: [],\n\t\t},\n\t};\n\tconst dispatched = new Set<string>();\n\tconst checked = new Set<string>();\n\tconst commands = new Set([first.command.commandId]);\n\tlet activeRole: \"writer\" | \"verifier\" = \"writer\";\n\tfor (const event of events.slice(1)) {\n\t\tconst state = context.state;\n\t\tif (state.execution === \"failed\" || state.receiptDigest) throw new VerifiedRunError(\"integrity\");\n\t\tswitch (event.kind) {\n\t\t\tcase \"created\":\n\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\tcase \"budget_anchored\": {\n\t\t\t\tconst budget = event.budget;\n\t\t\t\tconst limits = first.contract.budget;\n\t\t\t\tif (\n\t\t\t\t\tstate.revision !== 1 ||\n\t\t\t\t\tstate.budget ||\n\t\t\t\t\tbudget.workDeadlineMs - budget.startedMs !== limits.workMs ||\n\t\t\t\t\tbudget.verifyCapMs - budget.workDeadlineMs !== limits.verifyMs ||\n\t\t\t\t\tbudget.cleanupDeadlineMs - budget.verifyCapMs !== limits.cleanupMs\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tbudget,\n\t\t\t\t\tenvironmentDigest: event.environmentDigest,\n\t\t\t\t\tlastClockMs: budget.startedMs,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"input_checkpoint\":\n\t\t\t\tif (\n\t\t\t\t\tstate.revision !== 2 ||\n\t\t\t\t\t!state.budget ||\n\t\t\t\t\tstate.inputDigest ||\n\t\t\t\t\tevent.digest !== first.contract.workspace.baseDigest\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = { ...state, inputDigest: event.digest };\n\t\t\t\tbreak;\n\t\t\tcase \"task_started\":\n\t\t\tcase \"task_finished\":\n\t\t\tcase \"tasks_paused\":\n\t\t\t\treduceDagEvent(context, event);\n\t\t\t\tbreak;\n\t\t\tcase \"writer_opened\":\n\t\t\tcase \"model_request\":\n\t\t\tcase \"writer_closed\":\n\t\t\t\treduceWriterEvent(context, event);\n\t\t\t\tbreak;\n\t\t\tcase \"dispatch\": {\n\t\t\t\tif (state.failure || state.activeExecutionIds.length || dispatched.has(event.executionId))\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tif (event.role === \"writer\") {\n\t\t\t\t\tacceptWriterDispatch(context, event);\n\t\t\t\t} else {\n\t\t\t\t\tif (\n\t\t\t\t\t\t!context.writerFinished ||\n\t\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\t\t!state.candidateDigest ||\n\t\t\t\t\t\tevent.claimId === null ||\n\t\t\t\t\t\t!first.contract.checks.some((check) => check.claimId === event.claimId) ||\n\t\t\t\t\t\tchecked.has(event.claimId)\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\t\tchecked.add(event.claimId);\n\t\t\t\t}\n\t\t\t\tdispatched.add(event.executionId);\n\t\t\t\tactiveRole = event.role;\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\texecution: \"running\",\n\t\t\t\t\tsettlement: \"draining\",\n\t\t\t\t\tactiveExecutionIds: [event.executionId],\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"process_ready\":\n\t\t\t\tif (\n\t\t\t\t\t!state.budget ||\n\t\t\t\t\tstate.activeExecutionIds[0] !== event.executionId ||\n\t\t\t\t\tevent.identity.bootId !== state.budget.bootId ||\n\t\t\t\t\tstate.processes.some((item) => item.executionId === event.executionId)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tprocesses: [...state.processes, { executionId: event.executionId, identity: event.identity }],\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"exited\":\n\t\t\t\tif (\n\t\t\t\t\tstate.activeExecutionIds[0] !== event.executionId ||\n\t\t\t\t\t(state.budget &&\n\t\t\t\t\t\tevent.failure === null &&\n\t\t\t\t\t\t!state.processes.some((item) => item.executionId === event.executionId))\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tif (activeRole === \"writer\") context.writerFinished = event.failure === null;\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tsettlement: state.writerOpen ? \"open\" : \"settled\",\n\t\t\t\t\tactiveExecutionIds: [],\n\t\t\t\t\tfailure: event.failure,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"candidate\": {\n\t\t\t\tif (\n\t\t\t\t\t!context.writerFinished ||\n\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\tstate.failure ||\n\t\t\t\t\tstate.activeExecutionIds.length ||\n\t\t\t\t\tstate.candidateDigest ||\n\t\t\t\t\tstate.tasks.some((task) => task.status !== \"succeeded\" || task.generation !== state.generation)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tif (state.budget) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tevent.observedMs === undefined ||\n\t\t\t\t\t\tevent.verificationDeadlineMs === undefined ||\n\t\t\t\t\t\tevent.observedMs < state.budget.startedMs ||\n\t\t\t\t\t\tevent.observedMs > state.budget.workDeadlineMs ||\n\t\t\t\t\t\tevent.verificationDeadlineMs !==\n\t\t\t\t\t\t\tMath.min(event.observedMs + first.contract.budget.verifyMs, state.budget.verifyCapMs)\n\t\t\t\t\t)\n\t\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\t} else if (event.observedMs !== undefined || event.verificationDeadlineMs !== undefined)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\tcandidateDigest: event.digest,\n\t\t\t\t\tverificationDeadlineMs: event.verificationDeadlineMs ?? null,\n\t\t\t\t\tlastClockMs: event.observedMs ?? null,\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"resumed\":\n\t\t\tcase \"tasks_retried\":\n\t\t\tcase \"writer_restarted\":\n\t\t\t\treduceRecoveryEvent(context, event, { commands, checked, activeRole });\n\t\t\t\tbreak;\n\t\t\tcase \"evaluated\":\n\t\t\t\tif (\n\t\t\t\t\t!state.candidateDigest ||\n\t\t\t\t\tstate.writerOpen ||\n\t\t\t\t\tstate.activeExecutionIds.length ||\n\t\t\t\t\tchecked.size !== first.contract.checks.length ||\n\t\t\t\t\t(event.verified && state.failure)\n\t\t\t\t)\n\t\t\t\t\tthrow new VerifiedRunError(\"integrity\");\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\treceiptDigest: event.receiptDigest,\n\t\t\t\t\texecution: \"succeeded\",\n\t\t\t\t\tverification: event.verified ? \"verified\" : \"violated\",\n\t\t\t\t\tapplication: event.verified ? \"candidate_ready\" : \"not_requested\",\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"failed\":\n\t\t\t\tcontext.state = {\n\t\t\t\t\t...state,\n\t\t\t\t\texecution: \"failed\",\n\t\t\t\t\tfailure: event.code,\n\t\t\t\t\tverification: \"inconclusive\",\n\t\t\t\t\tsettlement: state.activeExecutionIds.length || state.writerOpen ? \"quarantined\" : \"settled\",\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tdefault: {\n\t\t\t\tconst exhaustive: never = event;\n\t\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t\t}\n\t\t}\n\t\tcontext.state = { ...context.state, revision: state.revision + 1 };\n\t}\n\treturn Object.freeze({\n\t\t...context.state,\n\t\tactiveExecutionIds: Object.freeze([...context.state.activeExecutionIds]),\n\t\tprocesses: Object.freeze(context.state.processes.map((item) => Object.freeze(item))),\n\t\ttasks: Object.freeze(context.state.tasks.map((task) => Object.freeze(task))),\n\t});\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RunPhaseBudget } from "omk-protocol";
|
|
2
|
+
export interface RunClock {
|
|
3
|
+
readonly bootId: string;
|
|
4
|
+
readonly nowMs: number;
|
|
5
|
+
}
|
|
6
|
+
export interface RecoveryBudget {
|
|
7
|
+
readonly bootId: string;
|
|
8
|
+
readonly startedMs: number;
|
|
9
|
+
readonly workDeadlineMs: number;
|
|
10
|
+
readonly verifyCapMs: number;
|
|
11
|
+
readonly cleanupDeadlineMs: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function readRunClock(): RunClock;
|
|
14
|
+
export declare function anchorRunBudget(limits: RunPhaseBudget, clock: RunClock): RecoveryBudget;
|
|
15
|
+
export declare function parseRecoveryBudget(raw: unknown): RecoveryBudget;
|
|
16
|
+
export declare function remainingRunTime(budget: RecoveryBudget, deadlineMs: number, clock?: RunClock): number;
|
|
17
|
+
export declare const remainingVerification: typeof remainingRunTime;
|
|
18
|
+
export declare function localVerificationDeadline(budget: RecoveryBudget, deadlineMs: number): number;
|
|
19
|
+
//# sourceMappingURL=recovery-clock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recovery-clock.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/recovery-clock.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAGnD,MAAM,WAAW,QAAQ;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AACD,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;CACnC;AAGD,wBAAgB,YAAY,IAAI,QAAQ,CAOvC;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,QAAQ,GAAG,cAAc,CAQvF;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,cAAc,CAgChE;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,WAAiB,GAAG,MAAM,CAM3G;AAED,eAAO,MAAM,qBAAqB,yBAAmB,CAAC;AAEtD,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAI5F","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { uptime } from \"node:os\";\nimport { performance } from \"node:perf_hooks\";\nimport type { RunPhaseBudget } from \"omk-protocol\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\nexport interface RunClock {\n\treadonly bootId: string;\n\treadonly nowMs: number;\n}\nexport interface RecoveryBudget {\n\treadonly bootId: string;\n\treadonly startedMs: number;\n\treadonly workDeadlineMs: number;\n\treadonly verifyCapMs: number;\n\treadonly cleanupDeadlineMs: number;\n}\nconst BOOT_ID = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/;\n\nexport function readRunClock(): RunClock {\n\tif (process.platform !== \"linux\") throw new VerifiedRunError(\"clock_unavailable\");\n\tconst bootId = readFileSync(\"/proc/sys/kernel/random/boot_id\", \"utf8\").trim();\n\tconst nowMs = Math.floor(uptime() * 1000);\n\tif (!BOOT_ID.test(bootId) || !Number.isSafeInteger(nowMs) || nowMs < 0)\n\t\tthrow new VerifiedRunError(\"clock_unavailable\");\n\treturn Object.freeze({ bootId, nowMs });\n}\n\nexport function anchorRunBudget(limits: RunPhaseBudget, clock: RunClock): RecoveryBudget {\n\treturn parseRecoveryBudget({\n\t\tbootId: clock.bootId,\n\t\tstartedMs: clock.nowMs,\n\t\tworkDeadlineMs: clock.nowMs + limits.workMs,\n\t\tverifyCapMs: clock.nowMs + limits.workMs + limits.verifyMs,\n\t\tcleanupDeadlineMs: clock.nowMs + limits.workMs + limits.verifyMs + limits.cleanupMs,\n\t});\n}\n\nexport function parseRecoveryBudget(raw: unknown): RecoveryBudget {\n\tif (\n\t\ttypeof raw !== \"object\" ||\n\t\traw === null ||\n\t\t!(\"bootId\" in raw) ||\n\t\ttypeof raw.bootId !== \"string\" ||\n\t\t!BOOT_ID.test(raw.bootId) ||\n\t\t!(\"startedMs\" in raw) ||\n\t\ttypeof raw.startedMs !== \"number\" ||\n\t\t!(\"workDeadlineMs\" in raw) ||\n\t\ttypeof raw.workDeadlineMs !== \"number\" ||\n\t\t!(\"verifyCapMs\" in raw) ||\n\t\ttypeof raw.verifyCapMs !== \"number\" ||\n\t\t!(\"cleanupDeadlineMs\" in raw) ||\n\t\ttypeof raw.cleanupDeadlineMs !== \"number\"\n\t)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tconst values = [raw.startedMs, raw.workDeadlineMs, raw.verifyCapMs, raw.cleanupDeadlineMs];\n\tif (\n\t\tvalues.some((value) => !Number.isSafeInteger(value) || value < 0) ||\n\t\traw.workDeadlineMs <= raw.startedMs ||\n\t\traw.verifyCapMs <= raw.workDeadlineMs ||\n\t\traw.cleanupDeadlineMs <= raw.verifyCapMs\n\t)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\treturn Object.freeze({\n\t\tbootId: raw.bootId,\n\t\tstartedMs: raw.startedMs,\n\t\tworkDeadlineMs: raw.workDeadlineMs,\n\t\tverifyCapMs: raw.verifyCapMs,\n\t\tcleanupDeadlineMs: raw.cleanupDeadlineMs,\n\t});\n}\n\nexport function remainingRunTime(budget: RecoveryBudget, deadlineMs: number, clock = readRunClock()): number {\n\tif (clock.bootId !== budget.bootId) throw new VerifiedRunError(\"clock_changed\");\n\tif (clock.nowMs < budget.startedMs) throw new VerifiedRunError(\"clock_rollback\");\n\tif (!Number.isSafeInteger(deadlineMs) || deadlineMs <= budget.startedMs || deadlineMs > budget.verifyCapMs)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\treturn Math.max(0, deadlineMs - clock.nowMs);\n}\n\nexport const remainingVerification = remainingRunTime;\n\nexport function localVerificationDeadline(budget: RecoveryBudget, deadlineMs: number): number {\n\tconst remaining = remainingVerification(budget, deadlineMs);\n\tif (remaining <= 0) throw new VerifiedRunError(\"deadline\");\n\treturn performance.now() + remaining;\n}\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { uptime } from "node:os";
|
|
3
|
+
import { performance } from "node:perf_hooks";
|
|
4
|
+
import { VerifiedRunError } from "./storage.js";
|
|
5
|
+
const BOOT_ID = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/;
|
|
6
|
+
export function readRunClock() {
|
|
7
|
+
if (process.platform !== "linux")
|
|
8
|
+
throw new VerifiedRunError("clock_unavailable");
|
|
9
|
+
const bootId = readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim();
|
|
10
|
+
const nowMs = Math.floor(uptime() * 1000);
|
|
11
|
+
if (!BOOT_ID.test(bootId) || !Number.isSafeInteger(nowMs) || nowMs < 0)
|
|
12
|
+
throw new VerifiedRunError("clock_unavailable");
|
|
13
|
+
return Object.freeze({ bootId, nowMs });
|
|
14
|
+
}
|
|
15
|
+
export function anchorRunBudget(limits, clock) {
|
|
16
|
+
return parseRecoveryBudget({
|
|
17
|
+
bootId: clock.bootId,
|
|
18
|
+
startedMs: clock.nowMs,
|
|
19
|
+
workDeadlineMs: clock.nowMs + limits.workMs,
|
|
20
|
+
verifyCapMs: clock.nowMs + limits.workMs + limits.verifyMs,
|
|
21
|
+
cleanupDeadlineMs: clock.nowMs + limits.workMs + limits.verifyMs + limits.cleanupMs,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export function parseRecoveryBudget(raw) {
|
|
25
|
+
if (typeof raw !== "object" ||
|
|
26
|
+
raw === null ||
|
|
27
|
+
!("bootId" in raw) ||
|
|
28
|
+
typeof raw.bootId !== "string" ||
|
|
29
|
+
!BOOT_ID.test(raw.bootId) ||
|
|
30
|
+
!("startedMs" in raw) ||
|
|
31
|
+
typeof raw.startedMs !== "number" ||
|
|
32
|
+
!("workDeadlineMs" in raw) ||
|
|
33
|
+
typeof raw.workDeadlineMs !== "number" ||
|
|
34
|
+
!("verifyCapMs" in raw) ||
|
|
35
|
+
typeof raw.verifyCapMs !== "number" ||
|
|
36
|
+
!("cleanupDeadlineMs" in raw) ||
|
|
37
|
+
typeof raw.cleanupDeadlineMs !== "number")
|
|
38
|
+
throw new VerifiedRunError("integrity");
|
|
39
|
+
const values = [raw.startedMs, raw.workDeadlineMs, raw.verifyCapMs, raw.cleanupDeadlineMs];
|
|
40
|
+
if (values.some((value) => !Number.isSafeInteger(value) || value < 0) ||
|
|
41
|
+
raw.workDeadlineMs <= raw.startedMs ||
|
|
42
|
+
raw.verifyCapMs <= raw.workDeadlineMs ||
|
|
43
|
+
raw.cleanupDeadlineMs <= raw.verifyCapMs)
|
|
44
|
+
throw new VerifiedRunError("integrity");
|
|
45
|
+
return Object.freeze({
|
|
46
|
+
bootId: raw.bootId,
|
|
47
|
+
startedMs: raw.startedMs,
|
|
48
|
+
workDeadlineMs: raw.workDeadlineMs,
|
|
49
|
+
verifyCapMs: raw.verifyCapMs,
|
|
50
|
+
cleanupDeadlineMs: raw.cleanupDeadlineMs,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export function remainingRunTime(budget, deadlineMs, clock = readRunClock()) {
|
|
54
|
+
if (clock.bootId !== budget.bootId)
|
|
55
|
+
throw new VerifiedRunError("clock_changed");
|
|
56
|
+
if (clock.nowMs < budget.startedMs)
|
|
57
|
+
throw new VerifiedRunError("clock_rollback");
|
|
58
|
+
if (!Number.isSafeInteger(deadlineMs) || deadlineMs <= budget.startedMs || deadlineMs > budget.verifyCapMs)
|
|
59
|
+
throw new VerifiedRunError("integrity");
|
|
60
|
+
return Math.max(0, deadlineMs - clock.nowMs);
|
|
61
|
+
}
|
|
62
|
+
export const remainingVerification = remainingRunTime;
|
|
63
|
+
export function localVerificationDeadline(budget, deadlineMs) {
|
|
64
|
+
const remaining = remainingVerification(budget, deadlineMs);
|
|
65
|
+
if (remaining <= 0)
|
|
66
|
+
throw new VerifiedRunError("deadline");
|
|
67
|
+
return performance.now() + remaining;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=recovery-clock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recovery-clock.js","sourceRoot":"","sources":["../../../src/core/verified-run/recovery-clock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAahD,MAAM,OAAO,GAAG,+CAA+C,CAAC;AAEhE,MAAM,UAAU,YAAY,GAAa;IACxC,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QAAE,MAAM,IAAI,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;IAClF,MAAM,MAAM,GAAG,YAAY,CAAC,iCAAiC,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IAC9E,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IAC1C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM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,WAAW;QACzG,MAAM,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACzC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;AAAA,CAC7C;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,gBAAgB,CAAC;AAEtD,MAAM,UAAU,yBAAyB,CAAC,MAAsB,EAAE,UAAkB,EAAU;IAC7F,MAAM,SAAS,GAAG,qBAAqB,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC5D,IAAI,SAAS,IAAI,CAAC;QAAE,MAAM,IAAI,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC3D,OAAO,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;AAAA,CACrC","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { uptime } from \"node:os\";\nimport { performance } from \"node:perf_hooks\";\nimport type { RunPhaseBudget } from \"omk-protocol\";\nimport { VerifiedRunError } from \"./storage.ts\";\n\nexport interface RunClock {\n\treadonly bootId: string;\n\treadonly nowMs: number;\n}\nexport interface RecoveryBudget {\n\treadonly bootId: string;\n\treadonly startedMs: number;\n\treadonly workDeadlineMs: number;\n\treadonly verifyCapMs: number;\n\treadonly cleanupDeadlineMs: number;\n}\nconst BOOT_ID = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/;\n\nexport function readRunClock(): RunClock {\n\tif (process.platform !== \"linux\") throw new VerifiedRunError(\"clock_unavailable\");\n\tconst bootId = readFileSync(\"/proc/sys/kernel/random/boot_id\", \"utf8\").trim();\n\tconst nowMs = Math.floor(uptime() * 1000);\n\tif (!BOOT_ID.test(bootId) || !Number.isSafeInteger(nowMs) || nowMs < 0)\n\t\tthrow new VerifiedRunError(\"clock_unavailable\");\n\treturn Object.freeze({ bootId, nowMs });\n}\n\nexport function anchorRunBudget(limits: RunPhaseBudget, clock: RunClock): RecoveryBudget {\n\treturn parseRecoveryBudget({\n\t\tbootId: clock.bootId,\n\t\tstartedMs: clock.nowMs,\n\t\tworkDeadlineMs: clock.nowMs + limits.workMs,\n\t\tverifyCapMs: clock.nowMs + limits.workMs + limits.verifyMs,\n\t\tcleanupDeadlineMs: clock.nowMs + limits.workMs + limits.verifyMs + limits.cleanupMs,\n\t});\n}\n\nexport function parseRecoveryBudget(raw: unknown): RecoveryBudget {\n\tif (\n\t\ttypeof raw !== \"object\" ||\n\t\traw === null ||\n\t\t!(\"bootId\" in raw) ||\n\t\ttypeof raw.bootId !== \"string\" ||\n\t\t!BOOT_ID.test(raw.bootId) ||\n\t\t!(\"startedMs\" in raw) ||\n\t\ttypeof raw.startedMs !== \"number\" ||\n\t\t!(\"workDeadlineMs\" in raw) ||\n\t\ttypeof raw.workDeadlineMs !== \"number\" ||\n\t\t!(\"verifyCapMs\" in raw) ||\n\t\ttypeof raw.verifyCapMs !== \"number\" ||\n\t\t!(\"cleanupDeadlineMs\" in raw) ||\n\t\ttypeof raw.cleanupDeadlineMs !== \"number\"\n\t)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\tconst values = [raw.startedMs, raw.workDeadlineMs, raw.verifyCapMs, raw.cleanupDeadlineMs];\n\tif (\n\t\tvalues.some((value) => !Number.isSafeInteger(value) || value < 0) ||\n\t\traw.workDeadlineMs <= raw.startedMs ||\n\t\traw.verifyCapMs <= raw.workDeadlineMs ||\n\t\traw.cleanupDeadlineMs <= raw.verifyCapMs\n\t)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\treturn Object.freeze({\n\t\tbootId: raw.bootId,\n\t\tstartedMs: raw.startedMs,\n\t\tworkDeadlineMs: raw.workDeadlineMs,\n\t\tverifyCapMs: raw.verifyCapMs,\n\t\tcleanupDeadlineMs: raw.cleanupDeadlineMs,\n\t});\n}\n\nexport function remainingRunTime(budget: RecoveryBudget, deadlineMs: number, clock = readRunClock()): number {\n\tif (clock.bootId !== budget.bootId) throw new VerifiedRunError(\"clock_changed\");\n\tif (clock.nowMs < budget.startedMs) throw new VerifiedRunError(\"clock_rollback\");\n\tif (!Number.isSafeInteger(deadlineMs) || deadlineMs <= budget.startedMs || deadlineMs > budget.verifyCapMs)\n\t\tthrow new VerifiedRunError(\"integrity\");\n\treturn Math.max(0, deadlineMs - clock.nowMs);\n}\n\nexport const remainingVerification = remainingRunTime;\n\nexport function localVerificationDeadline(budget: RecoveryBudget, deadlineMs: number): number {\n\tconst remaining = remainingVerification(budget, deadlineMs);\n\tif (remaining <= 0) throw new VerifiedRunError(\"deadline\");\n\treturn performance.now() + remaining;\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RunResumeCommand, RunTaskRetryCommand, RunWriterRestartCommand } from "omk-protocol";
|
|
2
|
+
import { type JournalSnapshot, VerifiedRunJournal } from "./journal.ts";
|
|
3
|
+
import type { RunProjection } from "./run-types.ts";
|
|
4
|
+
export type RecoveryCommand = RunResumeCommand | RunWriterRestartCommand | RunTaskRetryCommand;
|
|
5
|
+
export declare function requireRunJournal(runPath: string): JournalSnapshot;
|
|
6
|
+
/** One lease/CAS/idempotency boundary for all explicit recovery actions. */
|
|
7
|
+
export declare function withRecoveryLease(runPath: string, command: RecoveryCommand, execute: (input: {
|
|
8
|
+
readonly snapshot: JournalSnapshot;
|
|
9
|
+
readonly journal: VerifiedRunJournal;
|
|
10
|
+
}) => Promise<RunProjection>): Promise<RunProjection>;
|
|
11
|
+
//# sourceMappingURL=recovery-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recovery-command.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/recovery-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEnG,OAAO,EAAE,KAAK,eAAe,EAA+B,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACrG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGpD,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG,uBAAuB,GAAG,mBAAmB,CAAC;AAC/F,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,CAIlE;AA4CD,4EAA4E;AAC5E,wBAAsB,iBAAiB,CACtC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,CAAC,KAAK,EAAE;IAChB,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC;IACnC,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;CACrC,KAAK,OAAO,CAAC,aAAa,CAAC,GAC1B,OAAO,CAAC,aAAa,CAAC,CAsBxB","sourcesContent":["import type { RunResumeCommand, RunTaskRetryCommand, RunWriterRestartCommand } from \"omk-protocol\";\nimport { acquireSessionOwnerLeaseSync } from \"../session-owner-lease.ts\";\nimport { type JournalSnapshot, journalPath, readRunJournal, VerifiedRunJournal } from \"./journal.ts\";\nimport type { RunProjection } from \"./run-types.ts\";\nimport { digestObject, VerifiedRunError } from \"./storage.ts\";\n\nexport type RecoveryCommand = RunResumeCommand | RunWriterRestartCommand | RunTaskRetryCommand;\nexport function requireRunJournal(runPath: string): JournalSnapshot {\n\tconst journal = readRunJournal(runPath);\n\tif (!journal) throw new VerifiedRunError(\"missing_run\");\n\treturn journal;\n}\n\nfunction commandDisposition(journal: JournalSnapshot, command: RecoveryCommand): \"new\" | \"duplicate\" {\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 previous = journal.records.find(\n\t\t({ event }) =>\n\t\t\t(event.kind === \"resumed\" || event.kind === \"writer_restarted\" || event.kind === \"tasks_retried\") &&\n\t\t\tevent.command.commandId === command.commandId,\n\t)?.event;\n\tif (previous?.kind === \"resumed\" || previous?.kind === \"writer_restarted\" || previous?.kind === \"tasks_retried\") {\n\t\tif (digestObject(previous.command) !== digestObject(command)) throw new VerifiedRunError(\"command_conflict\");\n\t\treturn \"duplicate\";\n\t}\n\tif (command.expectedRevision !== journal.state.revision || command.expectedGeneration !== journal.state.generation)\n\t\tthrow new VerifiedRunError(\"stale_revision\");\n\tswitch (command.kind) {\n\t\tcase \"resume\":\n\t\t\tif (command.candidateDigest !== journal.state.candidateDigest)\n\t\t\t\tthrow new VerifiedRunError(\"candidate_mismatch\");\n\t\t\tbreak;\n\t\tcase \"retry_tasks\":\n\t\tcase \"restart_writer\":\n\t\t\tif (!journal.state.inputDigest) throw new VerifiedRunError(\"input_checkpoint_missing\");\n\t\t\tif (\n\t\t\t\tcommand.baseDigest !== journal.state.inputDigest ||\n\t\t\t\tcommand.baseDigest !== first.contract.workspace.baseDigest\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"input_mismatch\");\n\t\t\tbreak;\n\t\tdefault: {\n\t\t\tconst exhaustive: never = command;\n\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t}\n\t}\n\treturn \"new\";\n}\n\n/** One lease/CAS/idempotency boundary for all explicit recovery actions. */\nexport async function withRecoveryLease(\n\trunPath: string,\n\tcommand: RecoveryCommand,\n\texecute: (input: {\n\t\treadonly snapshot: JournalSnapshot;\n\t\treadonly journal: VerifiedRunJournal;\n\t}) => Promise<RunProjection>,\n): Promise<RunProjection> {\n\tconst initial = requireRunJournal(runPath);\n\tif (commandDisposition(initial, command) === \"duplicate\") return initial.state;\n\tconst owner = acquireSessionOwnerLeaseSync(journalPath(runPath));\n\ttry {\n\t\tconst snapshot = requireRunJournal(runPath);\n\t\tif (commandDisposition(snapshot, command) === \"duplicate\") return snapshot.state;\n\t\tconst journal = new VerifiedRunJournal(runPath, owner);\n\t\ttry {\n\t\t\treturn await execute({ snapshot, journal });\n\t\t} catch (error) {\n\t\t\tif (\n\t\t\t\terror instanceof VerifiedRunError &&\n\t\t\t\tjournal.state.generation > snapshot.state.generation &&\n\t\t\t\t!journal.state.receiptDigest\n\t\t\t)\n\t\t\t\treturn journal.append({ kind: \"failed\", code: error.code });\n\t\t\tthrow error;\n\t\t}\n\t} finally {\n\t\towner.release();\n\t}\n}\n"]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { acquireSessionOwnerLeaseSync } from "../session-owner-lease.js";
|
|
2
|
+
import { journalPath, readRunJournal, VerifiedRunJournal } from "./journal.js";
|
|
3
|
+
import { digestObject, VerifiedRunError } from "./storage.js";
|
|
4
|
+
export function requireRunJournal(runPath) {
|
|
5
|
+
const journal = readRunJournal(runPath);
|
|
6
|
+
if (!journal)
|
|
7
|
+
throw new VerifiedRunError("missing_run");
|
|
8
|
+
return journal;
|
|
9
|
+
}
|
|
10
|
+
function commandDisposition(journal, command) {
|
|
11
|
+
const first = journal.records[0]?.event;
|
|
12
|
+
if (first?.kind !== "created" ||
|
|
13
|
+
first.contract.runId !== command.runId ||
|
|
14
|
+
digestObject(first.contract) !== command.contractDigest)
|
|
15
|
+
throw new VerifiedRunError("command_conflict");
|
|
16
|
+
if (first.command.commandId === command.commandId)
|
|
17
|
+
throw new VerifiedRunError("command_conflict");
|
|
18
|
+
const previous = journal.records.find(({ event }) => (event.kind === "resumed" || event.kind === "writer_restarted" || event.kind === "tasks_retried") &&
|
|
19
|
+
event.command.commandId === command.commandId)?.event;
|
|
20
|
+
if (previous?.kind === "resumed" || previous?.kind === "writer_restarted" || previous?.kind === "tasks_retried") {
|
|
21
|
+
if (digestObject(previous.command) !== digestObject(command))
|
|
22
|
+
throw new VerifiedRunError("command_conflict");
|
|
23
|
+
return "duplicate";
|
|
24
|
+
}
|
|
25
|
+
if (command.expectedRevision !== journal.state.revision || command.expectedGeneration !== journal.state.generation)
|
|
26
|
+
throw new VerifiedRunError("stale_revision");
|
|
27
|
+
switch (command.kind) {
|
|
28
|
+
case "resume":
|
|
29
|
+
if (command.candidateDigest !== journal.state.candidateDigest)
|
|
30
|
+
throw new VerifiedRunError("candidate_mismatch");
|
|
31
|
+
break;
|
|
32
|
+
case "retry_tasks":
|
|
33
|
+
case "restart_writer":
|
|
34
|
+
if (!journal.state.inputDigest)
|
|
35
|
+
throw new VerifiedRunError("input_checkpoint_missing");
|
|
36
|
+
if (command.baseDigest !== journal.state.inputDigest ||
|
|
37
|
+
command.baseDigest !== first.contract.workspace.baseDigest)
|
|
38
|
+
throw new VerifiedRunError("input_mismatch");
|
|
39
|
+
break;
|
|
40
|
+
default: {
|
|
41
|
+
const exhaustive = command;
|
|
42
|
+
throw new VerifiedRunError(String(exhaustive));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return "new";
|
|
46
|
+
}
|
|
47
|
+
/** One lease/CAS/idempotency boundary for all explicit recovery actions. */
|
|
48
|
+
export async function withRecoveryLease(runPath, command, execute) {
|
|
49
|
+
const initial = requireRunJournal(runPath);
|
|
50
|
+
if (commandDisposition(initial, command) === "duplicate")
|
|
51
|
+
return initial.state;
|
|
52
|
+
const owner = acquireSessionOwnerLeaseSync(journalPath(runPath));
|
|
53
|
+
try {
|
|
54
|
+
const snapshot = requireRunJournal(runPath);
|
|
55
|
+
if (commandDisposition(snapshot, command) === "duplicate")
|
|
56
|
+
return snapshot.state;
|
|
57
|
+
const journal = new VerifiedRunJournal(runPath, owner);
|
|
58
|
+
try {
|
|
59
|
+
return await execute({ snapshot, journal });
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
if (error instanceof VerifiedRunError &&
|
|
63
|
+
journal.state.generation > snapshot.state.generation &&
|
|
64
|
+
!journal.state.receiptDigest)
|
|
65
|
+
return journal.append({ kind: "failed", code: error.code });
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
owner.release();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=recovery-command.js.map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} from \"../session-owner-lease.ts\";\nimport { type JournalSnapshot, journalPath, readRunJournal, VerifiedRunJournal } from \"./journal.ts\";\nimport type { RunProjection } from \"./run-types.ts\";\nimport { digestObject, VerifiedRunError } from \"./storage.ts\";\n\nexport type RecoveryCommand = RunResumeCommand | RunWriterRestartCommand | RunTaskRetryCommand;\nexport function requireRunJournal(runPath: string): JournalSnapshot {\n\tconst journal = readRunJournal(runPath);\n\tif (!journal) throw new VerifiedRunError(\"missing_run\");\n\treturn journal;\n}\n\nfunction commandDisposition(journal: JournalSnapshot, command: RecoveryCommand): \"new\" | \"duplicate\" {\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 previous = journal.records.find(\n\t\t({ event }) =>\n\t\t\t(event.kind === \"resumed\" || event.kind === \"writer_restarted\" || event.kind === \"tasks_retried\") &&\n\t\t\tevent.command.commandId === command.commandId,\n\t)?.event;\n\tif (previous?.kind === \"resumed\" || previous?.kind === \"writer_restarted\" || previous?.kind === \"tasks_retried\") {\n\t\tif (digestObject(previous.command) !== digestObject(command)) throw new VerifiedRunError(\"command_conflict\");\n\t\treturn \"duplicate\";\n\t}\n\tif (command.expectedRevision !== journal.state.revision || command.expectedGeneration !== journal.state.generation)\n\t\tthrow new VerifiedRunError(\"stale_revision\");\n\tswitch (command.kind) {\n\t\tcase \"resume\":\n\t\t\tif (command.candidateDigest !== journal.state.candidateDigest)\n\t\t\t\tthrow new VerifiedRunError(\"candidate_mismatch\");\n\t\t\tbreak;\n\t\tcase \"retry_tasks\":\n\t\tcase \"restart_writer\":\n\t\t\tif (!journal.state.inputDigest) throw new VerifiedRunError(\"input_checkpoint_missing\");\n\t\t\tif (\n\t\t\t\tcommand.baseDigest !== journal.state.inputDigest ||\n\t\t\t\tcommand.baseDigest !== first.contract.workspace.baseDigest\n\t\t\t)\n\t\t\t\tthrow new VerifiedRunError(\"input_mismatch\");\n\t\t\tbreak;\n\t\tdefault: {\n\t\t\tconst exhaustive: never = command;\n\t\t\tthrow new VerifiedRunError(String(exhaustive));\n\t\t}\n\t}\n\treturn \"new\";\n}\n\n/** One lease/CAS/idempotency boundary for all explicit recovery actions. */\nexport async function withRecoveryLease(\n\trunPath: string,\n\tcommand: RecoveryCommand,\n\texecute: (input: {\n\t\treadonly snapshot: JournalSnapshot;\n\t\treadonly journal: VerifiedRunJournal;\n\t}) => Promise<RunProjection>,\n): Promise<RunProjection> {\n\tconst initial = requireRunJournal(runPath);\n\tif (commandDisposition(initial, command) === \"duplicate\") return initial.state;\n\tconst owner = acquireSessionOwnerLeaseSync(journalPath(runPath));\n\ttry {\n\t\tconst snapshot = requireRunJournal(runPath);\n\t\tif (commandDisposition(snapshot, command) === \"duplicate\") return snapshot.state;\n\t\tconst journal = new VerifiedRunJournal(runPath, owner);\n\t\ttry {\n\t\t\treturn await execute({ snapshot, journal });\n\t\t} catch (error) {\n\t\t\tif (\n\t\t\t\terror instanceof VerifiedRunError &&\n\t\t\t\tjournal.state.generation > snapshot.state.generation &&\n\t\t\t\t!journal.state.receiptDigest\n\t\t\t)\n\t\t\t\treturn journal.append({ kind: \"failed\", code: error.code });\n\t\t\tthrow error;\n\t\t}\n\t} finally {\n\t\towner.release();\n\t}\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RunEvent, WriterReduction } from "./run-types.ts";
|
|
2
|
+
type RecoveryEvent = Extract<RunEvent, {
|
|
3
|
+
kind: "resumed" | "writer_restarted" | "tasks_retried";
|
|
4
|
+
}>;
|
|
5
|
+
/** Shared generation/command fence; only the writer variant resets attempt-local progress. */
|
|
6
|
+
export declare function reduceRecoveryEvent(context: WriterReduction, event: RecoveryEvent, progress: {
|
|
7
|
+
readonly commands: Set<string>;
|
|
8
|
+
readonly checked: Set<string>;
|
|
9
|
+
readonly activeRole: "writer" | "verifier";
|
|
10
|
+
}): void;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=recovery-projection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recovery-projection.d.ts","sourceRoot":"","sources":["../../../src/core/verified-run/recovery-projection.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGhE,KAAK,aAAa,GAAG,OAAO,CAAC,QAAQ,EAAE;IAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,GAAG,eAAe,CAAA;CAAE,CAAC,CAAC;AAEnG,8FAA8F;AAC9F,wBAAgB,mBAAmB,CAClC,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE;IACT,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,QAAQ,GAAG,UAAU,CAAC;CAC3C,GACC,IAAI,CAyFN","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"]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { MAX_VERIFIED_RUN_GENERATIONS } from "omk-protocol";
|
|
2
|
+
import { retryTaskProjection } from "./dag-retry-projection.js";
|
|
3
|
+
import { digestObject, VerifiedRunError } from "./storage.js";
|
|
4
|
+
/** Shared generation/command fence; only the writer variant resets attempt-local progress. */
|
|
5
|
+
export function reduceRecoveryEvent(context, event, progress) {
|
|
6
|
+
const state = context.state;
|
|
7
|
+
const command = event.command;
|
|
8
|
+
if (!state.budget)
|
|
9
|
+
throw new VerifiedRunError("resume_unavailable");
|
|
10
|
+
if (state.generation >= MAX_VERIFIED_RUN_GENERATIONS)
|
|
11
|
+
throw new VerifiedRunError("recovery_limit");
|
|
12
|
+
if (command.expectedRevision !== state.revision || command.expectedGeneration !== state.generation)
|
|
13
|
+
throw new VerifiedRunError("stale_revision");
|
|
14
|
+
if (command.runId !== state.runId ||
|
|
15
|
+
command.contractDigest !== digestObject(context.contract) ||
|
|
16
|
+
progress.commands.has(command.commandId))
|
|
17
|
+
throw new VerifiedRunError("command_conflict");
|
|
18
|
+
if (event.reconciledExecutionIds.length !== state.activeExecutionIds.length ||
|
|
19
|
+
event.reconciledExecutionIds.some((id, index) => id !== state.activeExecutionIds[index]))
|
|
20
|
+
throw new VerifiedRunError("integrity");
|
|
21
|
+
let deadline;
|
|
22
|
+
let tasks = state.tasks;
|
|
23
|
+
switch (event.kind) {
|
|
24
|
+
case "resumed":
|
|
25
|
+
if (!state.candidateDigest ||
|
|
26
|
+
state.writerOpen ||
|
|
27
|
+
state.verificationDeadlineMs === null ||
|
|
28
|
+
event.command.candidateDigest !== state.candidateDigest)
|
|
29
|
+
throw new VerifiedRunError("resume_unavailable");
|
|
30
|
+
if (state.activeExecutionIds.length && progress.activeRole !== "verifier")
|
|
31
|
+
throw new VerifiedRunError("integrity");
|
|
32
|
+
deadline = state.verificationDeadlineMs;
|
|
33
|
+
break;
|
|
34
|
+
case "tasks_retried":
|
|
35
|
+
if (state.activeExecutionIds.length && progress.activeRole !== "writer")
|
|
36
|
+
throw new VerifiedRunError("integrity");
|
|
37
|
+
tasks = retryTaskProjection(context, event);
|
|
38
|
+
deadline = state.budget.workDeadlineMs;
|
|
39
|
+
context.writerStarted = false;
|
|
40
|
+
context.writerFinished = tasks.every((task) => task.status === "succeeded");
|
|
41
|
+
context.producerStarted = false;
|
|
42
|
+
context.writerCommands = 0;
|
|
43
|
+
context.requestBaseline = state.modelRequests;
|
|
44
|
+
break;
|
|
45
|
+
case "writer_restarted":
|
|
46
|
+
if (context.contract.profile === "linux-command-dag-v1")
|
|
47
|
+
throw new VerifiedRunError("task_recovery_required");
|
|
48
|
+
if (!state.inputDigest ||
|
|
49
|
+
state.candidateDigest ||
|
|
50
|
+
event.command.baseDigest !== state.inputDigest ||
|
|
51
|
+
state.inputDigest !== context.contract.workspace.baseDigest)
|
|
52
|
+
throw new VerifiedRunError("input_checkpoint_missing");
|
|
53
|
+
if (state.activeExecutionIds.length && progress.activeRole !== "writer")
|
|
54
|
+
throw new VerifiedRunError("integrity");
|
|
55
|
+
if (context.contract.profile === "linux-scripted-agent-v1" &&
|
|
56
|
+
context.contract.writer.maxRequests - state.modelRequests < context.contract.writer.steps.length + 1)
|
|
57
|
+
throw new VerifiedRunError("model_request_limit");
|
|
58
|
+
deadline = state.budget.workDeadlineMs;
|
|
59
|
+
context.writerStarted = false;
|
|
60
|
+
context.writerFinished = false;
|
|
61
|
+
context.producerStarted = false;
|
|
62
|
+
context.writerCommands = 0;
|
|
63
|
+
context.requestBaseline = state.modelRequests;
|
|
64
|
+
break;
|
|
65
|
+
default: {
|
|
66
|
+
const exhaustive = event;
|
|
67
|
+
throw new VerifiedRunError(String(exhaustive));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (event.observedMs < (state.lastClockMs ?? state.budget.startedMs) || event.observedMs >= deadline)
|
|
71
|
+
throw new VerifiedRunError("deadline");
|
|
72
|
+
progress.commands.add(command.commandId);
|
|
73
|
+
progress.checked.clear();
|
|
74
|
+
context.state = {
|
|
75
|
+
...state,
|
|
76
|
+
generation: state.generation + 1,
|
|
77
|
+
tasks,
|
|
78
|
+
execution: "running",
|
|
79
|
+
settlement: "settled",
|
|
80
|
+
verification: "not_requested",
|
|
81
|
+
writerOpen: false,
|
|
82
|
+
activeExecutionIds: [],
|
|
83
|
+
processes: [],
|
|
84
|
+
failure: null,
|
|
85
|
+
lastClockMs: event.observedMs,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=recovery-projection.js.map
|
|
@@ -0,0 +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,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;QAC7B,OAAO,CAAC,cAAc,KAAK,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC;QACzD,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC;QAExC,MAAM,IAAI,gBAAgB,CAAC,kB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G,KAAK,CAAC,aAAa,CAAC;YAC9C,MAAM;QACP,SAAS,CAAC;YACT,MAAM,UAAU,GAAU,KAAK,CAAC;YAChC,MAAM,IAAI,gBAAgB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;QAChD,CAAC;IACF,CAAC;IACD,IAAI,KAAK,CAAC,UAAU,GAAG,CAAC,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,UAAU,IAAI,QAAQ;QACnG,MAAM,IAAI,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACxC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACzC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACzB,OAAO,CAAC,KAAK,GAAG;QACf,GAAG,KAAK;QACR,UAAU,EAAE,KAAK,CAAC,UAAU,GAAG,CAAC;QAChC,KAAK;QACL,SAAS,EAAE,SAAS;QACpB,UAAU,EAAE,SAAS;QACrB,YAAY,EAAE,eAAe;QAC7B,UAAU,EAAE,KAAK;QACjB,kBAAkB,EAAE,EAAE;QACtB,SAAS,EAAE,EAAE;QACb,OAAO,EAAE,IAAI;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"]}
|