open-multi-agent-kit 1.0.0 → 1.2.2
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 +52 -1
- 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/help.d.ts.map +1 -1
- package/dist/cli/help.js +1 -0
- package/dist/cli/help.js.map +1 -1
- 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/awareness.d.ts +32 -0
- package/dist/coordination/awareness.d.ts.map +1 -0
- package/dist/coordination/awareness.js +55 -0
- package/dist/coordination/awareness.js.map +1 -0
- package/dist/coordination/broker.d.ts +79 -0
- package/dist/coordination/broker.d.ts.map +1 -0
- package/dist/coordination/broker.js +202 -0
- package/dist/coordination/broker.js.map +1 -0
- package/dist/coordination/index.d.ts +16 -0
- package/dist/coordination/index.d.ts.map +1 -0
- package/dist/coordination/index.js +16 -0
- package/dist/coordination/index.js.map +1 -0
- package/dist/coordination/integration.d.ts +59 -0
- package/dist/coordination/integration.d.ts.map +1 -0
- package/dist/coordination/integration.js +126 -0
- package/dist/coordination/integration.js.map +1 -0
- package/dist/coordination/operation.d.ts +107 -0
- package/dist/coordination/operation.d.ts.map +1 -0
- package/dist/coordination/operation.js +231 -0
- package/dist/coordination/operation.js.map +1 -0
- package/dist/coordination/resource.d.ts +33 -0
- package/dist/coordination/resource.d.ts.map +1 -0
- package/dist/coordination/resource.js +95 -0
- package/dist/coordination/resource.js.map +1 -0
- package/dist/coordination/session.d.ts +74 -0
- package/dist/coordination/session.d.ts.map +1 -0
- package/dist/coordination/session.js +143 -0
- package/dist/coordination/session.js.map +1 -0
- package/dist/coordination/types.d.ts +68 -0
- package/dist/coordination/types.d.ts.map +1 -0
- package/dist/coordination/types.js +26 -0
- package/dist/coordination/types.js.map +1 -0
- 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 +35 -15
- 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/control-state.d.ts +41 -0
- package/dist/core/compaction/control-state.d.ts.map +1 -0
- package/dist/core/compaction/control-state.js +85 -0
- package/dist/core/compaction/control-state.js.map +1 -0
- package/dist/core/compaction/fallback.d.ts +71 -0
- package/dist/core/compaction/fallback.d.ts.map +1 -0
- package/dist/core/compaction/fallback.js +118 -0
- package/dist/core/compaction/fallback.js.map +1 -0
- package/dist/core/compaction/index.d.ts +2 -0
- package/dist/core/compaction/index.d.ts.map +1 -1
- package/dist/core/compaction/index.js +2 -0
- package/dist/core/compaction/index.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/context-budget-headroom-candidates.d.ts +16 -1
- package/dist/core/context-budget-headroom-candidates.d.ts.map +1 -1
- package/dist/core/context-budget-headroom-candidates.js +31 -13
- package/dist/core/context-budget-headroom-candidates.js.map +1 -1
- package/dist/core/context-budget-headroom-types.d.ts +7 -1
- package/dist/core/context-budget-headroom-types.d.ts.map +1 -1
- package/dist/core/context-budget-headroom-types.js +0 -1
- package/dist/core/context-budget-headroom-types.js.map +1 -1
- package/dist/core/context-budget-headroom.d.ts +10 -0
- package/dist/core/context-budget-headroom.d.ts.map +1 -1
- package/dist/core/context-budget-headroom.js +11 -2
- package/dist/core/context-budget-headroom.js.map +1 -1
- package/dist/core/context-budget-v2-global-pass.d.ts +21 -0
- package/dist/core/context-budget-v2-global-pass.d.ts.map +1 -0
- package/dist/core/context-budget-v2-global-pass.js +203 -0
- package/dist/core/context-budget-v2-global-pass.js.map +1 -0
- package/dist/core/context-budget-v2-planned-items.d.ts +12 -0
- package/dist/core/context-budget-v2-planned-items.d.ts.map +1 -1
- package/dist/core/context-budget-v2-planned-items.js +21 -2
- package/dist/core/context-budget-v2-planned-items.js.map +1 -1
- package/dist/core/context-budget-v2-planner.d.ts.map +1 -1
- package/dist/core/context-budget-v2-planner.js +18 -19
- package/dist/core/context-budget-v2-planner.js.map +1 -1
- package/dist/core/context-budget-v2-scoring.d.ts +7 -1
- package/dist/core/context-budget-v2-scoring.d.ts.map +1 -1
- package/dist/core/context-budget-v2-scoring.js.map +1 -1
- package/dist/core/context-budget-v2-selection.d.ts +3 -0
- package/dist/core/context-budget-v2-selection.d.ts.map +1 -1
- package/dist/core/context-budget-v2-selection.js +6 -2
- package/dist/core/context-budget-v2-selection.js.map +1 -1
- package/dist/core/context-budget-v2-types.d.ts +6 -1
- package/dist/core/context-budget-v2-types.d.ts.map +1 -1
- package/dist/core/context-budget-v2-types.js +6 -1
- package/dist/core/context-budget-v2-types.js.map +1 -1
- 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-default-models.d.ts +1 -0
- package/dist/core/provider-default-models.d.ts.map +1 -1
- package/dist/core/provider-default-models.js +1 -0
- package/dist/core/provider-default-models.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 +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-resolver.d.ts +7 -0
- package/dist/core/reasoning-router-resolver.d.ts.map +1 -1
- package/dist/core/reasoning-router-resolver.js +21 -3
- package/dist/core/reasoning-router-resolver.js.map +1 -1
- package/dist/core/reasoning-router-v4.d.ts +13 -7
- package/dist/core/reasoning-router-v4.d.ts.map +1 -1
- package/dist/core/reasoning-router-v4.js +8 -5
- 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-compaction-service.d.ts +15 -0
- package/dist/core/session-compaction-service.d.ts.map +1 -1
- package/dist/core/session-compaction-service.js +17 -4
- package/dist/core/session-compaction-service.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/todo-runtime-state.d.ts +12 -0
- package/dist/core/todo-runtime-state.d.ts.map +1 -1
- package/dist/core/todo-runtime-state.js +23 -0
- package/dist/core/todo-runtime-state.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 +77 -0
- package/dist/core/verified-run/supervisor-adapter.d.ts.map +1 -0
- package/dist/core/verified-run/supervisor-adapter.js +164 -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 +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -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 +78 -0
- package/dist/metacognition/calibration-selective.d.ts.map +1 -0
- package/dist/metacognition/calibration-selective.js +167 -0
- package/dist/metacognition/calibration-selective.js.map +1 -0
- package/dist/metacognition/calibration.d.ts +62 -0
- package/dist/metacognition/calibration.d.ts.map +1 -0
- package/dist/metacognition/calibration.js +122 -0
- package/dist/metacognition/calibration.js.map +1 -0
- package/dist/metacognition/checkpoint.d.ts +60 -0
- package/dist/metacognition/checkpoint.d.ts.map +1 -0
- package/dist/metacognition/checkpoint.js +57 -0
- package/dist/metacognition/checkpoint.js.map +1 -0
- package/dist/metacognition/context7.d.ts +48 -0
- package/dist/metacognition/context7.d.ts.map +1 -0
- package/dist/metacognition/context7.js +154 -0
- package/dist/metacognition/context7.js.map +1 -0
- package/dist/metacognition/decision.d.ts +44 -0
- package/dist/metacognition/decision.d.ts.map +1 -0
- package/dist/metacognition/decision.js +111 -0
- package/dist/metacognition/decision.js.map +1 -0
- package/dist/metacognition/evaluation.d.ts +73 -0
- package/dist/metacognition/evaluation.d.ts.map +1 -0
- package/dist/metacognition/evaluation.js +97 -0
- package/dist/metacognition/evaluation.js.map +1 -0
- package/dist/metacognition/index.d.ts +32 -0
- package/dist/metacognition/index.d.ts.map +1 -0
- package/dist/metacognition/index.js +32 -0
- package/dist/metacognition/index.js.map +1 -0
- package/dist/metacognition/knowledge-action.d.ts +43 -0
- package/dist/metacognition/knowledge-action.d.ts.map +1 -0
- package/dist/metacognition/knowledge-action.js +60 -0
- package/dist/metacognition/knowledge-action.js.map +1 -0
- package/dist/metacognition/knowledge.d.ts +84 -0
- package/dist/metacognition/knowledge.d.ts.map +1 -0
- package/dist/metacognition/knowledge.js +165 -0
- package/dist/metacognition/knowledge.js.map +1 -0
- package/dist/metacognition/obligations.d.ts +82 -0
- package/dist/metacognition/obligations.d.ts.map +1 -0
- package/dist/metacognition/obligations.js +139 -0
- package/dist/metacognition/obligations.js.map +1 -0
- package/dist/metacognition/observation-validity.d.ts +83 -0
- package/dist/metacognition/observation-validity.d.ts.map +1 -0
- package/dist/metacognition/observation-validity.js +118 -0
- package/dist/metacognition/observation-validity.js.map +1 -0
- package/dist/metacognition/observe.d.ts +45 -0
- package/dist/metacognition/observe.d.ts.map +1 -0
- package/dist/metacognition/observe.js +59 -0
- package/dist/metacognition/observe.js.map +1 -0
- package/dist/metacognition/policy.d.ts +53 -0
- package/dist/metacognition/policy.d.ts.map +1 -0
- package/dist/metacognition/policy.js +155 -0
- package/dist/metacognition/policy.js.map +1 -0
- package/dist/metacognition/predictions.d.ts +78 -0
- package/dist/metacognition/predictions.d.ts.map +1 -0
- package/dist/metacognition/predictions.js +181 -0
- package/dist/metacognition/predictions.js.map +1 -0
- package/dist/metacognition/retrieval.d.ts +53 -0
- package/dist/metacognition/retrieval.d.ts.map +1 -0
- package/dist/metacognition/retrieval.js +170 -0
- package/dist/metacognition/retrieval.js.map +1 -0
- package/dist/metacognition/risk.d.ts +48 -0
- package/dist/metacognition/risk.d.ts.map +1 -0
- package/dist/metacognition/risk.js +179 -0
- package/dist/metacognition/risk.js.map +1 -0
- package/dist/metacognition/route-economics.d.ts +95 -0
- package/dist/metacognition/route-economics.d.ts.map +1 -0
- package/dist/metacognition/route-economics.js +110 -0
- package/dist/metacognition/route-economics.js.map +1 -0
- package/dist/metacognition/runtime-bridge.d.ts +81 -0
- package/dist/metacognition/runtime-bridge.d.ts.map +1 -0
- package/dist/metacognition/runtime-bridge.js +458 -0
- package/dist/metacognition/runtime-bridge.js.map +1 -0
- package/dist/metacognition/skills.d.ts +42 -0
- package/dist/metacognition/skills.d.ts.map +1 -0
- package/dist/metacognition/skills.js +220 -0
- package/dist/metacognition/skills.js.map +1 -0
- package/dist/metacognition/state.d.ts +110 -0
- package/dist/metacognition/state.d.ts.map +1 -0
- package/dist/metacognition/state.js +52 -0
- package/dist/metacognition/state.js.map +1 -0
- package/dist/metacognition/validation.d.ts +19 -0
- package/dist/metacognition/validation.d.ts.map +1 -0
- package/dist/metacognition/validation.js +58 -0
- package/dist/metacognition/validation.js.map +1 -0
- package/dist/metacognition/verification.d.ts +93 -0
- package/dist/metacognition/verification.d.ts.map +1 -0
- package/dist/metacognition/verification.js +132 -0
- package/dist/metacognition/verification.js.map +1 -0
- package/dist/metacognition/verifier.d.ts +49 -0
- package/dist/metacognition/verifier.d.ts.map +1 -0
- package/dist/metacognition/verifier.js +88 -0
- package/dist/metacognition/verifier.js.map +1 -0
- 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/observation/identity.d.ts +14 -0
- package/dist/observation/identity.d.ts.map +1 -0
- package/dist/observation/identity.js +29 -0
- package/dist/observation/identity.js.map +1 -0
- package/dist/observation/index.d.ts +13 -0
- package/dist/observation/index.d.ts.map +1 -0
- package/dist/observation/index.js +13 -0
- package/dist/observation/index.js.map +1 -0
- package/dist/observation/observe-mode.d.ts +46 -0
- package/dist/observation/observe-mode.d.ts.map +1 -0
- package/dist/observation/observe-mode.js +83 -0
- package/dist/observation/observe-mode.js.map +1 -0
- package/dist/observation/store.d.ts +53 -0
- package/dist/observation/store.d.ts.map +1 -0
- package/dist/observation/store.js +126 -0
- package/dist/observation/store.js.map +1 -0
- package/dist/observation/types.d.ts +72 -0
- package/dist/observation/types.d.ts.map +1 -0
- package/dist/observation/types.js +9 -0
- package/dist/observation/types.js.map +1 -0
- package/dist/observation/view.d.ts +39 -0
- package/dist/observation/view.d.ts.map +1 -0
- package/dist/observation/view.js +173 -0
- package/dist/observation/view.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 +130 -0
- package/docs/model-catalog-refresh.md +218 -1
- package/docs/models.md +1 -1
- package/docs/providers.md +53 -0
- package/docs/runtime-algorithms.md +156 -7
- 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
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observation mode — §13 "기존 완료 판정 호출부: 메타상태를 진단으로 첨부,
|
|
3
|
+
* 최종 승인·검증 영수증은 기존 권위에 둠."
|
|
4
|
+
*
|
|
5
|
+
* Produces a serializable diagnostic snapshot for the host to attach at a
|
|
6
|
+
* completion/verification boundary. It never mutates the run, never issues a
|
|
7
|
+
* receipt, and never changes `verified` — it only reports what the
|
|
8
|
+
* metacognition state saw at that checkpoint.
|
|
9
|
+
*/
|
|
10
|
+
import { type CheckpointResult } from "./checkpoint.ts";
|
|
11
|
+
import type { ActionConstraints, MetaAction } from "./policy.ts";
|
|
12
|
+
import type { MetaState } from "./state.ts";
|
|
13
|
+
export interface MetaDiagnostic {
|
|
14
|
+
readonly schema: "omk.metacognition.diagnostic.v1";
|
|
15
|
+
readonly taskId: string;
|
|
16
|
+
readonly stageId: string;
|
|
17
|
+
readonly stateFingerprint: string;
|
|
18
|
+
readonly finishKind: "continue" | "verified-completion" | "inconclusive";
|
|
19
|
+
readonly finishReason?: string;
|
|
20
|
+
readonly proposedAction: MetaActionKindLabel;
|
|
21
|
+
readonly openRequiredObligations: number;
|
|
22
|
+
readonly violatedObligations: number;
|
|
23
|
+
readonly blockedHighRiskCandidates: number;
|
|
24
|
+
readonly unresolvedMismatches: number;
|
|
25
|
+
readonly verifierBlindSpots: number;
|
|
26
|
+
readonly runnerHealth: MetaState["verifier"]["runnerHealth"];
|
|
27
|
+
readonly calibrationDemoted: number;
|
|
28
|
+
readonly checkpointCount: number;
|
|
29
|
+
}
|
|
30
|
+
type MetaActionKindLabel = MetaAction["kind"];
|
|
31
|
+
/** Observation-mode diagnostic. Read-only over MetaState — no side effects. */
|
|
32
|
+
export declare function attachMetaDiagnostics(state: MetaState, constraints: ActionConstraints, nowMs: number): MetaDiagnostic;
|
|
33
|
+
/** Project a checkpoint result into the diagnostic record. */
|
|
34
|
+
export declare function toDiagnostic(state: MetaState, result: CheckpointResult): MetaDiagnostic;
|
|
35
|
+
/**
|
|
36
|
+
* Run one observation-mode checkpoint through the bridge: returns the kernel
|
|
37
|
+
* report plus the diagnostic to attach. The host keeps its own completion
|
|
38
|
+
* verdict; this only advises.
|
|
39
|
+
*/
|
|
40
|
+
export declare function observeCheckpoint(state: MetaState, constraints: ActionConstraints, nowMs: number): {
|
|
41
|
+
readonly result: CheckpointResult;
|
|
42
|
+
readonly diagnostic: MetaDiagnostic;
|
|
43
|
+
};
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=observe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe.d.ts","sourceRoot":"","sources":["../../src/metacognition/observe.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,KAAK,gBAAgB,EAAc,MAAM,iBAAiB,CAAC;AACpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAI5C,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,MAAM,EAAE,iCAAiC,CAAC;IACnD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,UAAU,EAAE,UAAU,GAAG,qBAAqB,GAAG,cAAc,CAAC;IACzE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,cAAc,EAAE,mBAAmB,CAAC;IAC7C,QAAQ,CAAC,uBAAuB,EAAE,MAAM,CAAC;IACzC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,yBAAyB,EAAE,MAAM,CAAC;IAC3C,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,YAAY,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC,cAAc,CAAC,CAAC;IAC7D,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;CACjC;AACD,KAAK,mBAAmB,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;AAE9C,iFAA+E;AAC/E,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG,cAAc,CAIrH;AAED,8DAA8D;AAC9D,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,GAAG,cAAc,CAiCvF;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAChC,KAAK,EAAE,SAAS,EAChB,WAAW,EAAE,iBAAiB,EAC9B,KAAK,EAAE,MAAM,GACX;IAAE,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAA;CAAE,CAG5E","sourcesContent":["/**\n * Observation mode — §13 \"기존 완료 판정 호출부: 메타상태를 진단으로 첨부,\n * 최종 승인·검증 영수증은 기존 권위에 둠.\"\n *\n * Produces a serializable diagnostic snapshot for the host to attach at a\n * completion/verification boundary. It never mutates the run, never issues a\n * receipt, and never changes `verified` — it only reports what the\n * metacognition state saw at that checkpoint.\n */\nimport { type CheckpointResult, checkpoint } from \"./checkpoint.ts\";\nimport type { ActionConstraints, MetaAction } from \"./policy.ts\";\nimport { mismatchSummary } from \"./predictions.ts\";\nimport type { MetaState } from \"./state.ts\";\nimport { stateFingerprint } from \"./state.ts\";\nimport { integer } from \"./validation.ts\";\n\nexport interface MetaDiagnostic {\n\treadonly schema: \"omk.metacognition.diagnostic.v1\";\n\treadonly taskId: string;\n\treadonly stageId: string;\n\treadonly stateFingerprint: string;\n\treadonly finishKind: \"continue\" | \"verified-completion\" | \"inconclusive\";\n\treadonly finishReason?: string;\n\treadonly proposedAction: MetaActionKindLabel;\n\treadonly openRequiredObligations: number;\n\treadonly violatedObligations: number;\n\treadonly blockedHighRiskCandidates: number;\n\treadonly unresolvedMismatches: number;\n\treadonly verifierBlindSpots: number;\n\treadonly runnerHealth: MetaState[\"verifier\"][\"runnerHealth\"];\n\treadonly calibrationDemoted: number;\n\treadonly checkpointCount: number;\n}\ntype MetaActionKindLabel = MetaAction[\"kind\"];\n\n/** Observation-mode diagnostic. Read-only over MetaState — no side effects. */\nexport function attachMetaDiagnostics(state: MetaState, constraints: ActionConstraints, nowMs: number): MetaDiagnostic {\n\tinteger(nowMs, \"nowMs\");\n\tconst result = checkpoint({ state, nowMs, constraints });\n\treturn toDiagnostic(state, result);\n}\n\n/** Project a checkpoint result into the diagnostic record. */\nexport function toDiagnostic(state: MetaState, result: CheckpointResult): MetaDiagnostic {\n\tconst mismatches = mismatchSummary(state.predictions);\n\tconst blindSpots = state.verifier.evaluations.reduce(\n\t\t(n, e) => n + e.blindSpots.length + (e.detectionRate === \"unknown\" ? 1 : 0),\n\t\t0,\n\t);\n\tconst demoted = Object.values(state.calibration.buckets).filter((b) => b.state === \"demoted\").length;\n\treturn {\n\t\tschema: \"omk.metacognition.diagnostic.v1\",\n\t\ttaskId: state.goal.taskId,\n\t\tstageId: state.goal.stageId,\n\t\tstateFingerprint: stateFingerprint(state),\n\t\tfinishKind: result.finish.kind,\n\t\tfinishReason:\n\t\t\tresult.finish.kind === \"inconclusive\"\n\t\t\t\t? result.finish.reason\n\t\t\t\t: result.finish.kind === \"verified-completion\"\n\t\t\t\t\t? result.finish.receiptId\n\t\t\t\t\t: undefined,\n\t\tproposedAction: result.action.kind,\n\t\topenRequiredObligations: state.obligations.filter((o) => o.status === \"required\").length,\n\t\tviolatedObligations: state.obligations.filter((o) => o.status === \"violated\").length,\n\t\tblockedHighRiskCandidates: state.obligations.filter((o) => o.status === \"blocked-high-risk\").length,\n\t\tunresolvedMismatches:\n\t\t\tmismatches.byKind[\"unexpected-fail\"] +\n\t\t\tmismatches.byKind[\"unexpected-side-effect\"] +\n\t\t\tmismatches.byKind[\"scope-mismatch\"] +\n\t\t\tmismatches.byKind[\"missing-observation\"],\n\t\tverifierBlindSpots: blindSpots,\n\t\trunnerHealth: state.verifier.runnerHealth,\n\t\tcalibrationDemoted: demoted,\n\t\tcheckpointCount: result.state.checkpointCount,\n\t};\n}\n\n/**\n * Run one observation-mode checkpoint through the bridge: returns the kernel\n * report plus the diagnostic to attach. The host keeps its own completion\n * verdict; this only advises.\n */\nexport function observeCheckpoint(\n\tstate: MetaState,\n\tconstraints: ActionConstraints,\n\tnowMs: number,\n): { readonly result: CheckpointResult; readonly diagnostic: MetaDiagnostic } {\n\tconst result = checkpoint({ state, nowMs, constraints });\n\treturn { result, diagnostic: toDiagnostic(state, result) };\n}\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observation mode — §13 "기존 완료 판정 호출부: 메타상태를 진단으로 첨부,
|
|
3
|
+
* 최종 승인·검증 영수증은 기존 권위에 둠."
|
|
4
|
+
*
|
|
5
|
+
* Produces a serializable diagnostic snapshot for the host to attach at a
|
|
6
|
+
* completion/verification boundary. It never mutates the run, never issues a
|
|
7
|
+
* receipt, and never changes `verified` — it only reports what the
|
|
8
|
+
* metacognition state saw at that checkpoint.
|
|
9
|
+
*/
|
|
10
|
+
import { checkpoint } from "./checkpoint.js";
|
|
11
|
+
import { mismatchSummary } from "./predictions.js";
|
|
12
|
+
import { stateFingerprint } from "./state.js";
|
|
13
|
+
import { integer } from "./validation.js";
|
|
14
|
+
/** Observation-mode diagnostic. Read-only over MetaState — no side effects. */
|
|
15
|
+
export function attachMetaDiagnostics(state, constraints, nowMs) {
|
|
16
|
+
integer(nowMs, "nowMs");
|
|
17
|
+
const result = checkpoint({ state, nowMs, constraints });
|
|
18
|
+
return toDiagnostic(state, result);
|
|
19
|
+
}
|
|
20
|
+
/** Project a checkpoint result into the diagnostic record. */
|
|
21
|
+
export function toDiagnostic(state, result) {
|
|
22
|
+
const mismatches = mismatchSummary(state.predictions);
|
|
23
|
+
const blindSpots = state.verifier.evaluations.reduce((n, e) => n + e.blindSpots.length + (e.detectionRate === "unknown" ? 1 : 0), 0);
|
|
24
|
+
const demoted = Object.values(state.calibration.buckets).filter((b) => b.state === "demoted").length;
|
|
25
|
+
return {
|
|
26
|
+
schema: "omk.metacognition.diagnostic.v1",
|
|
27
|
+
taskId: state.goal.taskId,
|
|
28
|
+
stageId: state.goal.stageId,
|
|
29
|
+
stateFingerprint: stateFingerprint(state),
|
|
30
|
+
finishKind: result.finish.kind,
|
|
31
|
+
finishReason: result.finish.kind === "inconclusive"
|
|
32
|
+
? result.finish.reason
|
|
33
|
+
: result.finish.kind === "verified-completion"
|
|
34
|
+
? result.finish.receiptId
|
|
35
|
+
: undefined,
|
|
36
|
+
proposedAction: result.action.kind,
|
|
37
|
+
openRequiredObligations: state.obligations.filter((o) => o.status === "required").length,
|
|
38
|
+
violatedObligations: state.obligations.filter((o) => o.status === "violated").length,
|
|
39
|
+
blockedHighRiskCandidates: state.obligations.filter((o) => o.status === "blocked-high-risk").length,
|
|
40
|
+
unresolvedMismatches: mismatches.byKind["unexpected-fail"] +
|
|
41
|
+
mismatches.byKind["unexpected-side-effect"] +
|
|
42
|
+
mismatches.byKind["scope-mismatch"] +
|
|
43
|
+
mismatches.byKind["missing-observation"],
|
|
44
|
+
verifierBlindSpots: blindSpots,
|
|
45
|
+
runnerHealth: state.verifier.runnerHealth,
|
|
46
|
+
calibrationDemoted: demoted,
|
|
47
|
+
checkpointCount: result.state.checkpointCount,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Run one observation-mode checkpoint through the bridge: returns the kernel
|
|
52
|
+
* report plus the diagnostic to attach. The host keeps its own completion
|
|
53
|
+
* verdict; this only advises.
|
|
54
|
+
*/
|
|
55
|
+
export function observeCheckpoint(state, constraints, nowMs) {
|
|
56
|
+
const result = checkpoint({ state, nowMs, constraints });
|
|
57
|
+
return { result, diagnostic: toDiagnostic(state, result) };
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=observe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observe.js","sourceRoot":"","sources":["../../src/metacognition/observe.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAyB,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAqB1C,iFAA+E;AAC/E,MAAM,UAAU,qBAAqB,CAAC,KAAgB,EAAE,WAA8B,EAAE,KAAa,EAAkB;IACtH,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACxB,MAAM,MAAM,GAAG,UAAU,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;IACzD,OAAO,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAAA,CACnC;AAED,8DAA8D;AAC9D,MAAM,UAAU,YAAY,CAAC,KAAgB,EAAE,MAAwB,EAAkB;IACxF,MAAM,UAAU,GAAG,eAAe,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACtD,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,CACnD,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAC3E,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AC;YAC3C,UAAU,CAAC,MAAM,CAAC,gBAAgB,CAAC;YACnC,UAAU,CAAC,MAAM,CAAC,qBAAqB,CAAC;QACzC,kBAAkB,EAAE,UAAU;QAC9B,YAAY,EAAE,KAAK,CAAC,QAAQ,CAAC,YAAY;QACzC,kBAAkB,EAAE,OAAO;QAC3B,eAAe,EAAE,MAAM,CAAC,KAAK,CAAC,eAAe;KAC7C,CAAC;AAAA,CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAChC,KAAgB,EAChB,WAA8B,EAC9B,KAAa,EACgE;IAC7E,MAAM,MAAM,GAAG,UAAU,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;IACzD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,CAAC;AAAA,CAC3D","sourcesContent":["/**\n * Observation mode — §13 \"기존 완료 판정 호출부: 메타상태를 진단으로 첨부,\n * 최종 승인·검증 영수증은 기존 권위에 둠.\"\n *\n * Produces a serializable diagnostic snapshot for the host to attach at a\n * completion/verification boundary. It never mutates the run, never issues a\n * receipt, and never changes `verified` — it only reports what the\n * metacognition state saw at that checkpoint.\n */\nimport { type CheckpointResult, checkpoint } from \"./checkpoint.ts\";\nimport type { ActionConstraints, MetaAction } from \"./policy.ts\";\nimport { mismatchSummary } from \"./predictions.ts\";\nimport type { MetaState } from \"./state.ts\";\nimport { stateFingerprint } from \"./state.ts\";\nimport { integer } from \"./validation.ts\";\n\nexport interface MetaDiagnostic {\n\treadonly schema: \"omk.metacognition.diagnostic.v1\";\n\treadonly taskId: string;\n\treadonly stageId: string;\n\treadonly stateFingerprint: string;\n\treadonly finishKind: \"continue\" | \"verified-completion\" | \"inconclusive\";\n\treadonly finishReason?: string;\n\treadonly proposedAction: MetaActionKindLabel;\n\treadonly openRequiredObligations: number;\n\treadonly violatedObligations: number;\n\treadonly blockedHighRiskCandidates: number;\n\treadonly unresolvedMismatches: number;\n\treadonly verifierBlindSpots: number;\n\treadonly runnerHealth: MetaState[\"verifier\"][\"runnerHealth\"];\n\treadonly calibrationDemoted: number;\n\treadonly checkpointCount: number;\n}\ntype MetaActionKindLabel = MetaAction[\"kind\"];\n\n/** Observation-mode diagnostic. Read-only over MetaState — no side effects. */\nexport function attachMetaDiagnostics(state: MetaState, constraints: ActionConstraints, nowMs: number): MetaDiagnostic {\n\tinteger(nowMs, \"nowMs\");\n\tconst result = checkpoint({ state, nowMs, constraints });\n\treturn toDiagnostic(state, result);\n}\n\n/** Project a checkpoint result into the diagnostic record. */\nexport function toDiagnostic(state: MetaState, result: CheckpointResult): MetaDiagnostic {\n\tconst mismatches = mismatchSummary(state.predictions);\n\tconst blindSpots = state.verifier.evaluations.reduce(\n\t\t(n, e) => n + e.blindSpots.length + (e.detectionRate === \"unknown\" ? 1 : 0),\n\t\t0,\n\t);\n\tconst demoted = Object.values(state.calibration.buckets).filter((b) => b.state === \"demoted\").length;\n\treturn {\n\t\tschema: \"omk.metacognition.diagnostic.v1\",\n\t\ttaskId: state.goal.taskId,\n\t\tstageId: state.goal.stageId,\n\t\tstateFingerprint: stateFingerprint(state),\n\t\tfinishKind: result.finish.kind,\n\t\tfinishReason:\n\t\t\tresult.finish.kind === \"inconclusive\"\n\t\t\t\t? result.finish.reason\n\t\t\t\t: result.finish.kind === \"verified-completion\"\n\t\t\t\t\t? result.finish.receiptId\n\t\t\t\t\t: undefined,\n\t\tproposedAction: result.action.kind,\n\t\topenRequiredObligations: state.obligations.filter((o) => o.status === \"required\").length,\n\t\tviolatedObligations: state.obligations.filter((o) => o.status === \"violated\").length,\n\t\tblockedHighRiskCandidates: state.obligations.filter((o) => o.status === \"blocked-high-risk\").length,\n\t\tunresolvedMismatches:\n\t\t\tmismatches.byKind[\"unexpected-fail\"] +\n\t\t\tmismatches.byKind[\"unexpected-side-effect\"] +\n\t\t\tmismatches.byKind[\"scope-mismatch\"] +\n\t\t\tmismatches.byKind[\"missing-observation\"],\n\t\tverifierBlindSpots: blindSpots,\n\t\trunnerHealth: state.verifier.runnerHealth,\n\t\tcalibrationDemoted: demoted,\n\t\tcheckpointCount: result.state.checkpointCount,\n\t};\n}\n\n/**\n * Run one observation-mode checkpoint through the bridge: returns the kernel\n * report plus the diagnostic to attach. The host keeps its own completion\n * verdict; this only advises.\n */\nexport function observeCheckpoint(\n\tstate: MetaState,\n\tconstraints: ActionConstraints,\n\tnowMs: number,\n): { readonly result: CheckpointResult; readonly diagnostic: MetaDiagnostic } {\n\tconst result = checkpoint({ state, nowMs, constraints });\n\treturn { result, diagnostic: toDiagnostic(state, result) };\n}\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { MetaState } from "./state.ts";
|
|
2
|
+
export type MetaActionKind = "inspect_local" | "retrieve_reference" | "run_discriminating_probe" | "strengthen_verifier" | "reselect_skills" | "revise_implementation" | "switch_strategy" | "request_required_decision" | "continue_object_work" | "finish_with_bound_receipt" | "stop_inconclusive" | "settle_safety" | "form_obligations";
|
|
3
|
+
export interface MetaAction {
|
|
4
|
+
readonly kind: MetaActionKind;
|
|
5
|
+
readonly obligationId?: string;
|
|
6
|
+
readonly hypothesisId?: string;
|
|
7
|
+
readonly reason: string;
|
|
8
|
+
readonly priority: number;
|
|
9
|
+
}
|
|
10
|
+
export interface ActionConstraints {
|
|
11
|
+
readonly authorizedActions: readonly MetaActionKind[];
|
|
12
|
+
readonly prerequisites: Partial<Readonly<Record<MetaActionKind, readonly string[]>>>;
|
|
13
|
+
readonly actionCostsMs: Partial<Readonly<Record<MetaActionKind, number>>>;
|
|
14
|
+
readonly actionCostsRequests: Partial<Readonly<Record<MetaActionKind, number>>>;
|
|
15
|
+
readonly inScopeKinds: readonly MetaActionKind[];
|
|
16
|
+
}
|
|
17
|
+
/** §9.2: Authorized ∧ Prerequisites ∧ BudgetFits ∧ ScopeBound. */
|
|
18
|
+
export declare function feasibleActions(state: MetaState, constraints: ActionConstraints): MetaActionKind[];
|
|
19
|
+
/**
|
|
20
|
+
* §14 priority table — the baseline deterministic policy. Safety first, then
|
|
21
|
+
* required decisions, host-observed obligations, verifier health, prediction
|
|
22
|
+
* mismatches, verifier blind spots, stagnation, optional positive-VOI work,
|
|
23
|
+
* object work, then finish.
|
|
24
|
+
*/
|
|
25
|
+
export declare function selectAction(state: MetaState, constraints: ActionConstraints, options?: {
|
|
26
|
+
readonly receipt?: {
|
|
27
|
+
receiptId: string;
|
|
28
|
+
candidateHash: string;
|
|
29
|
+
scope: string;
|
|
30
|
+
} | null;
|
|
31
|
+
readonly maxRepetitions?: number;
|
|
32
|
+
readonly switchCost?: number;
|
|
33
|
+
readonly estimatedSwitchGain?: number;
|
|
34
|
+
readonly voiCandidates?: readonly {
|
|
35
|
+
kind: MetaActionKind;
|
|
36
|
+
voi: number;
|
|
37
|
+
}[];
|
|
38
|
+
readonly progress?: {
|
|
39
|
+
goalScope: string;
|
|
40
|
+
candidateFamily: string;
|
|
41
|
+
errorClass: string;
|
|
42
|
+
approach: string;
|
|
43
|
+
checkMethod: string;
|
|
44
|
+
sourceFamily: string;
|
|
45
|
+
};
|
|
46
|
+
}): MetaAction;
|
|
47
|
+
/**
|
|
48
|
+
* §6.2/§6.5 VOI evaluation for one observation action. Returns the finite
|
|
49
|
+
* computation result; the caller supplies real priors and likelihoods and may
|
|
50
|
+
* include approved 2-step bundles whose joint value is computed the same way.
|
|
51
|
+
*/
|
|
52
|
+
export declare function valueOfObservation(prior: readonly number[], losses: readonly (readonly number[])[], likelihoodByHypothesis: readonly (readonly number[])[], cost: number): number;
|
|
53
|
+
//# sourceMappingURL=policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/metacognition/policy.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5C,MAAM,MAAM,cAAc,GACvB,eAAe,GACf,oBAAoB,GACpB,0BA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;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACtF,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS;QAAE,IAAI,EAAE,cAAc,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC1E,QAAQ,CAAC,QAAQ,CAAC,EAAE;QACnB,SAAS,EAAE,MAAM,CAAC;QAClB,eAAe,EAAE,MAAM,CAAC;QACxB,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;KACrB,CAAC;CACF,GACC,UAAU,CAsGZ;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,MAAM,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,EACtC,sBAAsB,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,EACtD,IAAI,EAAE,MAAM,GACV,MAAM,CAER","sourcesContent":["/**\n * Algorithm F — bounded metacontrol policy. Spec §9, §14.\n *\n * Feasibility precedes optimization: an action that is unauthorized, missing\n * prerequisites, over budget, or out of scope is absent from the feasible set\n * no matter how much information it promises. The baseline policy is the\n * explicit priority table of §14, not a score-sum that folds safety\n * constraints into a utility number.\n */\nimport { experimentValue } from \"./decision.ts\";\nimport type { MetaState } from \"./state.ts\";\nimport { isStagnant, netSwitchValue, progressKey } from \"./verifier.ts\";\n\nexport type MetaActionKind =\n\t| \"inspect_local\"\n\t| \"retrieve_reference\"\n\t| \"run_discriminating_probe\"\n\t| \"strengthen_verifier\"\n\t| \"reselect_skills\"\n\t| \"revise_implementation\"\n\t| \"switch_strategy\"\n\t| \"request_required_decision\"\n\t| \"continue_object_work\"\n\t| \"finish_with_bound_receipt\"\n\t| \"stop_inconclusive\"\n\t| \"settle_safety\"\n\t| \"form_obligations\";\n\nexport interface MetaAction {\n\treadonly kind: MetaActionKind;\n\treadonly obligationId?: string;\n\treadonly hypothesisId?: string;\n\treadonly reason: string;\n\treadonly priority: number;\n}\n\nexport interface ActionConstraints {\n\treadonly authorizedActions: readonly MetaActionKind[];\n\treadonly prerequisites: Partial<Readonly<Record<MetaActionKind, readonly string[]>>>;\n\treadonly actionCostsMs: Partial<Readonly<Record<MetaActionKind, number>>>;\n\treadonly actionCostsRequests: Partial<Readonly<Record<MetaActionKind, number>>>;\n\treadonly inScopeKinds: readonly MetaActionKind[];\n}\n\nconst ALL_KINDS: readonly MetaActionKind[] = [\n\t\"inspect_local\",\n\t\"retrieve_reference\",\n\t\"run_discriminating_probe\",\n\t\"strengthen_verifier\",\n\t\"reselect_skills\",\n\t\"revise_implementation\",\n\t\"switch_strategy\",\n\t\"request_required_decision\",\n\t\"continue_object_work\",\n\t\"finish_with_bound_receipt\",\n\t\"stop_inconclusive\",\n\t\"settle_safety\",\n\t\"form_obligations\",\n];\n\n/** §9.2: Authorized ∧ Prerequisites ∧ BudgetFits ∧ ScopeBound. */\nexport function feasibleActions(state: MetaState, constraints: ActionConstraints): MetaActionKind[] {\n\treturn ALL_KINDS.filter((kind) => {\n\t\tif (!constraints.authorizedActions.includes(kind)) return false;\n\t\tif (!constraints.inScopeKinds.includes(kind)) return false;\n\t\tfor (const prereq of constraints.prerequisites[kind] ?? []) {\n\t\t\tconst met =\n\t\t\t\tstate.obligations.some((o) => o.id === prereq && o.status === \"satisfied\") ||\n\t\t\t\tstate.predictions.some((p) => p.predictionId === prereq && p.status === \"resolved\");\n\t\t\tif (!met) return false;\n\t\t}\n\t\tconst ms = constraints.actionCostsMs[kind] ?? 0;\n\t\tconst req = constraints.actionCostsRequests[kind] ?? 0;\n\t\treturn ms <= state.budget.remainingMs && req <= state.budget.remainingRequests;\n\t});\n}\n\n/**\n * §14 priority table — the baseline deterministic policy. Safety first, then\n * required decisions, host-observed obligations, verifier health, prediction\n * mismatches, verifier blind spots, stagnation, optional positive-VOI work,\n * object work, then finish.\n */\nexport function selectAction(\n\tstate: MetaState,\n\tconstraints: ActionConstraints,\n\toptions?: {\n\t\treadonly receipt?: { receiptId: string; candidateHash: string; scope: string } | null;\n\t\treadonly maxRepetitions?: number;\n\t\treadonly switchCost?: number;\n\t\treadonly estimatedSwitchGain?: number;\n\t\treadonly voiCandidates?: readonly { kind: MetaActionKind; voi: number }[];\n\t\treadonly progress?: {\n\t\t\tgoalScope: string;\n\t\t\tcandidateFamily: string;\n\t\t\terrorClass: string;\n\t\t\tapproach: string;\n\t\t\tcheckMethod: string;\n\t\t\tsourceFamily: string;\n\t\t};\n\t},\n): MetaAction {\n\tconst feasible = new Set(feasibleActions(state, constraints));\n\tconst pick = (\n\t\tkind: MetaActionKind,\n\t\treason: string,\n\t\tpriority: number,\n\t\textra?: Partial<MetaAction>,\n\t): MetaAction | null => (feasible.has(kind) ? { kind, reason, priority, ...extra } : null);\n\n\t// 0: cancellation, authorization violation, safety constraint, binding mismatch.\n\tif (\n\t\tstate.policy.interruptionReason !== null ||\n\t\tstate.facts.candidateHash === \"\" ||\n\t\t!constraints.authorizedActions.every((a) => state.policy.authorizedActions.includes(a))\n\t) {\n\t\treturn (\n\t\t\tpick(\"settle_safety\", \"safety-or-binding\", 0) ?? {\n\t\t\t\tkind: \"stop_inconclusive\",\n\t\t\t\treason: \"unsafe-feasible-set\",\n\t\t\t\tpriority: 0,\n\t\t\t}\n\t\t);\n\t}\n\t// 1: required user decision or unknown prerequisite.\n\tconst needsDecision = state.obligations.find(\n\t\t(o) => o.status === \"blocked-high-risk\" || (o.status === \"required\" && o.checkMethodId === null && o.required),\n\t);\n\tif (needsDecision) {\n\t\tconst action = pick(\"request_required_decision\", `required-decision:${needsDecision.id}`, 1, {\n\t\t\tobligationId: needsDecision.id,\n\t\t});\n\t\tif (action) return action;\n\t}\n\t// 2: host-observed new required obligation → refresh obligations, gate the step.\n\tconst newRequired = state.obligations.find((o) => o.status === \"required\" && o.coverageFraction === 0);\n\tif (newRequired) {\n\t\tconst action = pick(\"form_obligations\", `new-required:${newRequired.id}`, 2, { obligationId: newRequired.id });\n\t\tif (action) return action;\n\t}\n\t// 3: check execution itself invalid → diagnose environment, not code.\n\tif (state.verifier.runnerHealth !== \"healthy\") {\n\t\tconst action = pick(\"inspect_local\", \"verifier-health-unverified\", 3);\n\t\tif (action) return action;\n\t}\n\t// 4: prediction mismatch or adoptable evidence conflict → discriminate causes.\n\tconst mismatch = state.predictions.find(\n\t\t(p) => p.status === \"resolved\" && p.mismatch !== undefined && p.mismatch !== \"none\",\n\t);\n\tif (mismatch && state.hypotheses.open.length > 1) {\n\t\tconst action = pick(\"run_discriminating_probe\", `mismatch:${mismatch.predictionId}`, 4, {\n\t\t\thypothesisId: state.hypotheses.open[0],\n\t\t});\n\t\tif (action) return action;\n\t}\n\t// 5: verifier blind spot on an important obligation → negative control / new check.\n\tconst blind = state.verifier.evaluations.find((e) => e.detectionRate === \"unknown\" || e.blindSpots.length > 0);\n\tif (blind) {\n\t\tconst action = pick(\"strengthen_verifier\", `blind-spot:${blind.obligationId}`, 5, {\n\t\t\tobligationId: blind.obligationId,\n\t\t});\n\t\tif (action) return action;\n\t}\n\t// 6: same strategy, no valid progress → switch with hysteresis, or stop.\n\tconst maxRep = options?.maxRepetitions ?? 3;\n\tif (options?.progress && isStagnant(options.progress, state.progressHistory, maxRep)) {\n\t\tconst switchGain = netSwitchValue(options.estimatedSwitchGain ?? 0, 0, options.switchCost ?? 0);\n\t\tif (switchGain > 0) {\n\t\t\tconst action = pick(\"switch_strategy\", `stagnant:${progressKey(options.progress)}`, 6);\n\t\t\tif (action) return action;\n\t\t}\n\t\tconst stop = pick(\"stop_inconclusive\", \"stagnant-no-progress\", 6);\n\t\tif (stop) return stop;\n\t}\n\t// 7: optional information acquisition with positive VOI.\n\tconst voi = (options?.voiCandidates ?? [])\n\t\t.filter((c) => c.voi > 0 && feasible.has(c.kind))\n\t\t.sort((a, b) => b.voi - a.voi);\n\tif (voi.length > 0) {\n\t\treturn (\n\t\t\tpick(voi[0]!.kind, `positive-voi:${voi[0]!.voi}`, 7) ?? {\n\t\t\t\tkind: \"stop_inconclusive\",\n\t\t\t\treason: \"no-feasible-voi-action\",\n\t\t\t\tpriority: 7,\n\t\t\t}\n\t\t);\n\t}\n\t// 8: premises sufficient, object work remains.\n\tconst openRequired = state.obligations.filter((o) => o.status === \"required\" || o.status === \"violated\");\n\tif (openRequired.length === 0) {\n\t\tconst action = pick(\"continue_object_work\", \"premises-satisfied\", 8);\n\t\tif (action) return action;\n\t}\n\t// 9: object work done → verified bounded completion or inconclusive stop.\n\tif (options?.receipt && openRequired.length === 0) {\n\t\tconst action = pick(\"finish_with_bound_receipt\", `receipt:${options.receipt.receiptId}`, 9);\n\t\tif (action) return action;\n\t}\n\tconst blocked =\n\t\tpick(\"revise_implementation\", `open-obligations:${openRequired.length}`, 8) ??\n\t\tpick(\"inspect_local\", \"open-obligations-inspect\", 8);\n\tif (blocked) return blocked;\n\treturn { kind: \"stop_inconclusive\", reason: \"no-feasible-action\", priority: 9 };\n}\n\n/**\n * §6.2/§6.5 VOI evaluation for one observation action. Returns the finite\n * computation result; the caller supplies real priors and likelihoods and may\n * include approved 2-step bundles whose joint value is computed the same way.\n */\nexport function valueOfObservation(\n\tprior: readonly number[],\n\tlosses: readonly (readonly number[])[],\n\tlikelihoodByHypothesis: readonly (readonly number[])[],\n\tcost: number,\n): number {\n\treturn experimentValue(prior, losses, likelihoodByHypothesis, cost).netValue;\n}\n"]}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Algorithm F — bounded metacontrol policy. Spec §9, §14.
|
|
3
|
+
*
|
|
4
|
+
* Feasibility precedes optimization: an action that is unauthorized, missing
|
|
5
|
+
* prerequisites, over budget, or out of scope is absent from the feasible set
|
|
6
|
+
* no matter how much information it promises. The baseline policy is the
|
|
7
|
+
* explicit priority table of §14, not a score-sum that folds safety
|
|
8
|
+
* constraints into a utility number.
|
|
9
|
+
*/
|
|
10
|
+
import { experimentValue } from "./decision.js";
|
|
11
|
+
import { isStagnant, netSwitchValue, progressKey } from "./verifier.js";
|
|
12
|
+
const ALL_KINDS = [
|
|
13
|
+
"inspect_local",
|
|
14
|
+
"retrieve_reference",
|
|
15
|
+
"run_discriminating_probe",
|
|
16
|
+
"strengthen_verifier",
|
|
17
|
+
"reselect_skills",
|
|
18
|
+
"revise_implementation",
|
|
19
|
+
"switch_strategy",
|
|
20
|
+
"request_required_decision",
|
|
21
|
+
"continue_object_work",
|
|
22
|
+
"finish_with_bound_receipt",
|
|
23
|
+
"stop_inconclusive",
|
|
24
|
+
"settle_safety",
|
|
25
|
+
"form_obligations",
|
|
26
|
+
];
|
|
27
|
+
/** §9.2: Authorized ∧ Prerequisites ∧ BudgetFits ∧ ScopeBound. */
|
|
28
|
+
export function feasibleActions(state, constraints) {
|
|
29
|
+
return ALL_KINDS.filter((kind) => {
|
|
30
|
+
if (!constraints.authorizedActions.includes(kind))
|
|
31
|
+
return false;
|
|
32
|
+
if (!constraints.inScopeKinds.includes(kind))
|
|
33
|
+
return false;
|
|
34
|
+
for (const prereq of constraints.prerequisites[kind] ?? []) {
|
|
35
|
+
const met = state.obligations.some((o) => o.id === prereq && o.status === "satisfied") ||
|
|
36
|
+
state.predictions.some((p) => p.predictionId === prereq && p.status === "resolved");
|
|
37
|
+
if (!met)
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const ms = constraints.actionCostsMs[kind] ?? 0;
|
|
41
|
+
const req = constraints.actionCostsRequests[kind] ?? 0;
|
|
42
|
+
return ms <= state.budget.remainingMs && req <= state.budget.remainingRequests;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* §14 priority table — the baseline deterministic policy. Safety first, then
|
|
47
|
+
* required decisions, host-observed obligations, verifier health, prediction
|
|
48
|
+
* mismatches, verifier blind spots, stagnation, optional positive-VOI work,
|
|
49
|
+
* object work, then finish.
|
|
50
|
+
*/
|
|
51
|
+
export function selectAction(state, constraints, options) {
|
|
52
|
+
const feasible = new Set(feasibleActions(state, constraints));
|
|
53
|
+
const pick = (kind, reason, priority, extra) => (feasible.has(kind) ? { kind, reason, priority, ...extra } : null);
|
|
54
|
+
// 0: cancellation, authorization violation, safety constraint, binding mismatch.
|
|
55
|
+
if (state.policy.interruptionReason !== null ||
|
|
56
|
+
state.facts.candidateHash === "" ||
|
|
57
|
+
!constraints.authorizedActions.every((a) => state.policy.authorizedActions.includes(a))) {
|
|
58
|
+
return (pick("settle_safety", "safety-or-binding", 0) ?? {
|
|
59
|
+
kind: "stop_inconclusive",
|
|
60
|
+
reason: "unsafe-feasible-set",
|
|
61
|
+
priority: 0,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// 1: required user decision or unknown prerequisite.
|
|
65
|
+
const needsDecision = state.obligations.find((o) => o.status === "blocked-high-risk" || (o.status === "required" && o.checkMethodId === null && o.required));
|
|
66
|
+
if (needsDecision) {
|
|
67
|
+
const action = pick("request_required_decision", `required-decision:${needsDecision.id}`, 1, {
|
|
68
|
+
obligationId: needsDecision.id,
|
|
69
|
+
});
|
|
70
|
+
if (action)
|
|
71
|
+
return action;
|
|
72
|
+
}
|
|
73
|
+
// 2: host-observed new required obligation → refresh obligations, gate the step.
|
|
74
|
+
const newRequired = state.obligations.find((o) => o.status === "required" && o.coverageFraction === 0);
|
|
75
|
+
if (newRequired) {
|
|
76
|
+
const action = pick("form_obligations", `new-required:${newRequired.id}`, 2, { obligationId: newRequired.id });
|
|
77
|
+
if (action)
|
|
78
|
+
return action;
|
|
79
|
+
}
|
|
80
|
+
// 3: check execution itself invalid → diagnose environment, not code.
|
|
81
|
+
if (state.verifier.runnerHealth !== "healthy") {
|
|
82
|
+
const action = pick("inspect_local", "verifier-health-unverified", 3);
|
|
83
|
+
if (action)
|
|
84
|
+
return action;
|
|
85
|
+
}
|
|
86
|
+
// 4: prediction mismatch or adoptable evidence conflict → discriminate causes.
|
|
87
|
+
const mismatch = state.predictions.find((p) => p.status === "resolved" && p.mismatch !== undefined && p.mismatch !== "none");
|
|
88
|
+
if (mismatch && state.hypotheses.open.length > 1) {
|
|
89
|
+
const action = pick("run_discriminating_probe", `mismatch:${mismatch.predictionId}`, 4, {
|
|
90
|
+
hypothesisId: state.hypotheses.open[0],
|
|
91
|
+
});
|
|
92
|
+
if (action)
|
|
93
|
+
return action;
|
|
94
|
+
}
|
|
95
|
+
// 5: verifier blind spot on an important obligation → negative control / new check.
|
|
96
|
+
const blind = state.verifier.evaluations.find((e) => e.detectionRate === "unknown" || e.blindSpots.length > 0);
|
|
97
|
+
if (blind) {
|
|
98
|
+
const action = pick("strengthen_verifier", `blind-spot:${blind.obligationId}`, 5, {
|
|
99
|
+
obligationId: blind.obligationId,
|
|
100
|
+
});
|
|
101
|
+
if (action)
|
|
102
|
+
return action;
|
|
103
|
+
}
|
|
104
|
+
// 6: same strategy, no valid progress → switch with hysteresis, or stop.
|
|
105
|
+
const maxRep = options?.maxRepetitions ?? 3;
|
|
106
|
+
if (options?.progress && isStagnant(options.progress, state.progressHistory, maxRep)) {
|
|
107
|
+
const switchGain = netSwitchValue(options.estimatedSwitchGain ?? 0, 0, options.switchCost ?? 0);
|
|
108
|
+
if (switchGain > 0) {
|
|
109
|
+
const action = pick("switch_strategy", `stagnant:${progressKey(options.progress)}`, 6);
|
|
110
|
+
if (action)
|
|
111
|
+
return action;
|
|
112
|
+
}
|
|
113
|
+
const stop = pick("stop_inconclusive", "stagnant-no-progress", 6);
|
|
114
|
+
if (stop)
|
|
115
|
+
return stop;
|
|
116
|
+
}
|
|
117
|
+
// 7: optional information acquisition with positive VOI.
|
|
118
|
+
const voi = (options?.voiCandidates ?? [])
|
|
119
|
+
.filter((c) => c.voi > 0 && feasible.has(c.kind))
|
|
120
|
+
.sort((a, b) => b.voi - a.voi);
|
|
121
|
+
if (voi.length > 0) {
|
|
122
|
+
return (pick(voi[0].kind, `positive-voi:${voi[0].voi}`, 7) ?? {
|
|
123
|
+
kind: "stop_inconclusive",
|
|
124
|
+
reason: "no-feasible-voi-action",
|
|
125
|
+
priority: 7,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
// 8: premises sufficient, object work remains.
|
|
129
|
+
const openRequired = state.obligations.filter((o) => o.status === "required" || o.status === "violated");
|
|
130
|
+
if (openRequired.length === 0) {
|
|
131
|
+
const action = pick("continue_object_work", "premises-satisfied", 8);
|
|
132
|
+
if (action)
|
|
133
|
+
return action;
|
|
134
|
+
}
|
|
135
|
+
// 9: object work done → verified bounded completion or inconclusive stop.
|
|
136
|
+
if (options?.receipt && openRequired.length === 0) {
|
|
137
|
+
const action = pick("finish_with_bound_receipt", `receipt:${options.receipt.receiptId}`, 9);
|
|
138
|
+
if (action)
|
|
139
|
+
return action;
|
|
140
|
+
}
|
|
141
|
+
const blocked = pick("revise_implementation", `open-obligations:${openRequired.length}`, 8) ??
|
|
142
|
+
pick("inspect_local", "open-obligations-inspect", 8);
|
|
143
|
+
if (blocked)
|
|
144
|
+
return blocked;
|
|
145
|
+
return { kind: "stop_inconclusive", reason: "no-feasible-action", priority: 9 };
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* §6.2/§6.5 VOI evaluation for one observation action. Returns the finite
|
|
149
|
+
* computation result; the caller supplies real priors and likelihoods and may
|
|
150
|
+
* include approved 2-step bundles whose joint value is computed the same way.
|
|
151
|
+
*/
|
|
152
|
+
export function valueOfObservation(prior, losses, likelihoodByHypothesis, cost) {
|
|
153
|
+
return experimentValue(prior, losses, likelihoodByHypothesis, cost).netValue;
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":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AC,CAAC;QACrE,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;IAC3B,CAAC;IACD,4EAA0E;IAC1E,IAAI,OAAO,EAAE,OAAO,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnD,MAAM,MAAM,GAAG,IAAI,CAAC,2BAA2B,EAAE,WAAW,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;QAC5F,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;IAC3B,CAAC;IACD,MAAM,OAAO,GACZ,IAAI,CAAC,uBAAuB,EAAE,oBAAoB,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAC3E,IAAI,CAAC,eAAe,EAAE,0BAA0B,EAAE,CAAC,CAAC,CAAC;IACtD,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IAC5B,OAAO,EAAE,IAAI,EAAE,mBAAmB,EAAE,MAAM,EAAE,oBAAoB,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;AAAA,CAChF;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CACjC,KAAwB,EACxB,MAAsC,EACtC,sBAAsD,EACtD,IAAY,EACH;IACT,OAAO,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,sBAAsB,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC;AAAA,CAC7E","sourcesContent":["/**\n * Algorithm F — bounded metacontrol policy. Spec §9, §14.\n *\n * Feasibility precedes optimization: an action that is unauthorized, missing\n * prerequisites, over budget, or out of scope is absent from the feasible set\n * no matter how much information it promises. The baseline policy is the\n * explicit priority table of §14, not a score-sum that folds safety\n * constraints into a utility number.\n */\nimport { experimentValue } from \"./decision.ts\";\nimport type { MetaState } from \"./state.ts\";\nimport { isStagnant, netSwitchValue, progressKey } from \"./verifier.ts\";\n\nexport type MetaActionKind =\n\t| \"inspect_local\"\n\t| \"retrieve_reference\"\n\t| \"run_discriminating_probe\"\n\t| \"strengthen_verifier\"\n\t| \"reselect_skills\"\n\t| \"revise_implementation\"\n\t| \"switch_strategy\"\n\t| \"request_required_decision\"\n\t| \"continue_object_work\"\n\t| \"finish_with_bound_receipt\"\n\t| \"stop_inconclusive\"\n\t| \"settle_safety\"\n\t| \"form_obligations\";\n\nexport interface MetaAction {\n\treadonly kind: MetaActionKind;\n\treadonly obligationId?: string;\n\treadonly hypothesisId?: string;\n\treadonly reason: string;\n\treadonly priority: number;\n}\n\nexport interface ActionConstraints {\n\treadonly authorizedActions: readonly MetaActionKind[];\n\treadonly prerequisites: Partial<Readonly<Record<MetaActionKind, readonly string[]>>>;\n\treadonly actionCostsMs: Partial<Readonly<Record<MetaActionKind, number>>>;\n\treadonly actionCostsRequests: Partial<Readonly<Record<MetaActionKind, number>>>;\n\treadonly inScopeKinds: readonly MetaActionKind[];\n}\n\nconst ALL_KINDS: readonly MetaActionKind[] = [\n\t\"inspect_local\",\n\t\"retrieve_reference\",\n\t\"run_discriminating_probe\",\n\t\"strengthen_verifier\",\n\t\"reselect_skills\",\n\t\"revise_implementation\",\n\t\"switch_strategy\",\n\t\"request_required_decision\",\n\t\"continue_object_work\",\n\t\"finish_with_bound_receipt\",\n\t\"stop_inconclusive\",\n\t\"settle_safety\",\n\t\"form_obligations\",\n];\n\n/** §9.2: Authorized ∧ Prerequisites ∧ BudgetFits ∧ ScopeBound. */\nexport function feasibleActions(state: MetaState, constraints: ActionConstraints): MetaActionKind[] {\n\treturn ALL_KINDS.filter((kind) => {\n\t\tif (!constraints.authorizedActions.includes(kind)) return false;\n\t\tif (!constraints.inScopeKinds.includes(kind)) return false;\n\t\tfor (const prereq of constraints.prerequisites[kind] ?? []) {\n\t\t\tconst met =\n\t\t\t\tstate.obligations.some((o) => o.id === prereq && o.status === \"satisfied\") ||\n\t\t\t\tstate.predictions.some((p) => p.predictionId === prereq && p.status === \"resolved\");\n\t\t\tif (!met) return false;\n\t\t}\n\t\tconst ms = constraints.actionCostsMs[kind] ?? 0;\n\t\tconst req = constraints.actionCostsRequests[kind] ?? 0;\n\t\treturn ms <= state.budget.remainingMs && req <= state.budget.remainingRequests;\n\t});\n}\n\n/**\n * §14 priority table — the baseline deterministic policy. Safety first, then\n * required decisions, host-observed obligations, verifier health, prediction\n * mismatches, verifier blind spots, stagnation, optional positive-VOI work,\n * object work, then finish.\n */\nexport function selectAction(\n\tstate: MetaState,\n\tconstraints: ActionConstraints,\n\toptions?: {\n\t\treadonly receipt?: { receiptId: string; candidateHash: string; scope: string } | null;\n\t\treadonly maxRepetitions?: number;\n\t\treadonly switchCost?: number;\n\t\treadonly estimatedSwitchGain?: number;\n\t\treadonly voiCandidates?: readonly { kind: MetaActionKind; voi: number }[];\n\t\treadonly progress?: {\n\t\t\tgoalScope: string;\n\t\t\tcandidateFamily: string;\n\t\t\terrorClass: string;\n\t\t\tapproach: string;\n\t\t\tcheckMethod: string;\n\t\t\tsourceFamily: string;\n\t\t};\n\t},\n): MetaAction {\n\tconst feasible = new Set(feasibleActions(state, constraints));\n\tconst pick = (\n\t\tkind: MetaActionKind,\n\t\treason: string,\n\t\tpriority: number,\n\t\textra?: Partial<MetaAction>,\n\t): MetaAction | null => (feasible.has(kind) ? { kind, reason, priority, ...extra } : null);\n\n\t// 0: cancellation, authorization violation, safety constraint, binding mismatch.\n\tif (\n\t\tstate.policy.interruptionReason !== null ||\n\t\tstate.facts.candidateHash === \"\" ||\n\t\t!constraints.authorizedActions.every((a) => state.policy.authorizedActions.includes(a))\n\t) {\n\t\treturn (\n\t\t\tpick(\"settle_safety\", \"safety-or-binding\", 0) ?? {\n\t\t\t\tkind: \"stop_inconclusive\",\n\t\t\t\treason: \"unsafe-feasible-set\",\n\t\t\t\tpriority: 0,\n\t\t\t}\n\t\t);\n\t}\n\t// 1: required user decision or unknown prerequisite.\n\tconst needsDecision = state.obligations.find(\n\t\t(o) => o.status === \"blocked-high-risk\" || (o.status === \"required\" && o.checkMethodId === null && o.required),\n\t);\n\tif (needsDecision) {\n\t\tconst action = pick(\"request_required_decision\", `required-decision:${needsDecision.id}`, 1, {\n\t\t\tobligationId: needsDecision.id,\n\t\t});\n\t\tif (action) return action;\n\t}\n\t// 2: host-observed new required obligation → refresh obligations, gate the step.\n\tconst newRequired = state.obligations.find((o) => o.status === \"required\" && o.coverageFraction === 0);\n\tif (newRequired) {\n\t\tconst action = pick(\"form_obligations\", `new-required:${newRequired.id}`, 2, { obligationId: newRequired.id });\n\t\tif (action) return action;\n\t}\n\t// 3: check execution itself invalid → diagnose environment, not code.\n\tif (state.verifier.runnerHealth !== \"healthy\") {\n\t\tconst action = pick(\"inspect_local\", \"verifier-health-unverified\", 3);\n\t\tif (action) return action;\n\t}\n\t// 4: prediction mismatch or adoptable evidence conflict → discriminate causes.\n\tconst mismatch = state.predictions.find(\n\t\t(p) => p.status === \"resolved\" && p.mismatch !== undefined && p.mismatch !== \"none\",\n\t);\n\tif (mismatch && state.hypotheses.open.length > 1) {\n\t\tconst action = pick(\"run_discriminating_probe\", `mismatch:${mismatch.predictionId}`, 4, {\n\t\t\thypothesisId: state.hypotheses.open[0],\n\t\t});\n\t\tif (action) return action;\n\t}\n\t// 5: verifier blind spot on an important obligation → negative control / new check.\n\tconst blind = state.verifier.evaluations.find((e) => e.detectionRate === \"unknown\" || e.blindSpots.length > 0);\n\tif (blind) {\n\t\tconst action = pick(\"strengthen_verifier\", `blind-spot:${blind.obligationId}`, 5, {\n\t\t\tobligationId: blind.obligationId,\n\t\t});\n\t\tif (action) return action;\n\t}\n\t// 6: same strategy, no valid progress → switch with hysteresis, or stop.\n\tconst maxRep = options?.maxRepetitions ?? 3;\n\tif (options?.progress && isStagnant(options.progress, state.progressHistory, maxRep)) {\n\t\tconst switchGain = netSwitchValue(options.estimatedSwitchGain ?? 0, 0, options.switchCost ?? 0);\n\t\tif (switchGain > 0) {\n\t\t\tconst action = pick(\"switch_strategy\", `stagnant:${progressKey(options.progress)}`, 6);\n\t\t\tif (action) return action;\n\t\t}\n\t\tconst stop = pick(\"stop_inconclusive\", \"stagnant-no-progress\", 6);\n\t\tif (stop) return stop;\n\t}\n\t// 7: optional information acquisition with positive VOI.\n\tconst voi = (options?.voiCandidates ?? [])\n\t\t.filter((c) => c.voi > 0 && feasible.has(c.kind))\n\t\t.sort((a, b) => b.voi - a.voi);\n\tif (voi.length > 0) {\n\t\treturn (\n\t\t\tpick(voi[0]!.kind, `positive-voi:${voi[0]!.voi}`, 7) ?? {\n\t\t\t\tkind: \"stop_inconclusive\",\n\t\t\t\treason: \"no-feasible-voi-action\",\n\t\t\t\tpriority: 7,\n\t\t\t}\n\t\t);\n\t}\n\t// 8: premises sufficient, object work remains.\n\tconst openRequired = state.obligations.filter((o) => o.status === \"required\" || o.status === \"violated\");\n\tif (openRequired.length === 0) {\n\t\tconst action = pick(\"continue_object_work\", \"premises-satisfied\", 8);\n\t\tif (action) return action;\n\t}\n\t// 9: object work done → verified bounded completion or inconclusive stop.\n\tif (options?.receipt && openRequired.length === 0) {\n\t\tconst action = pick(\"finish_with_bound_receipt\", `receipt:${options.receipt.receiptId}`, 9);\n\t\tif (action) return action;\n\t}\n\tconst blocked =\n\t\tpick(\"revise_implementation\", `open-obligations:${openRequired.length}`, 8) ??\n\t\tpick(\"inspect_local\", \"open-obligations-inspect\", 8);\n\tif (blocked) return blocked;\n\treturn { kind: \"stop_inconclusive\", reason: \"no-feasible-action\", priority: 9 };\n}\n\n/**\n * §6.2/§6.5 VOI evaluation for one observation action. Returns the finite\n * computation result; the caller supplies real priors and likelihoods and may\n * include approved 2-step bundles whose joint value is computed the same way.\n */\nexport function valueOfObservation(\n\tprior: readonly number[],\n\tlosses: readonly (readonly number[])[],\n\tlikelihoodByHypothesis: readonly (readonly number[])[],\n\tcost: number,\n): number {\n\treturn experimentValue(prior, losses, likelihoodByHypothesis, cost).netValue;\n}\n"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export type PredictionKind = "check-outcome" | "scope" | "side-effect" | "resource" | "hypothesis-outcome";
|
|
2
|
+
export type EstimatorKind = "uncalibrated-model-estimate" | "validated-estimator" | "none";
|
|
3
|
+
export type PredictionStatus = "registered" | "resolved" | "superseded" | "unobserved";
|
|
4
|
+
export type MismatchKind = "unexpected-pass" | "unexpected-fail" | "unexpected-side-effect" | "missing-observation" | "scope-mismatch" | "none";
|
|
5
|
+
export interface Prediction {
|
|
6
|
+
readonly predictionId: string;
|
|
7
|
+
readonly operationId: string;
|
|
8
|
+
readonly taskId: string;
|
|
9
|
+
readonly stageId: string;
|
|
10
|
+
readonly kind: PredictionKind;
|
|
11
|
+
readonly candidateHash: string;
|
|
12
|
+
readonly environmentHash: string;
|
|
13
|
+
readonly checkDefinitionHash: string;
|
|
14
|
+
readonly policyVersion: string;
|
|
15
|
+
readonly modelRevision: string;
|
|
16
|
+
readonly skillHashes: readonly string[];
|
|
17
|
+
readonly expectedOutcome: string;
|
|
18
|
+
/** Binary expectation for scored predictions; undefined for categorical. */
|
|
19
|
+
readonly expectedBinary?: boolean;
|
|
20
|
+
readonly probability?: number;
|
|
21
|
+
readonly estimator: EstimatorKind;
|
|
22
|
+
readonly counterevidenceCondition: string;
|
|
23
|
+
readonly hostSequence: number;
|
|
24
|
+
readonly registeredAtMs: number;
|
|
25
|
+
status: PredictionStatus;
|
|
26
|
+
readonly resolvedAtMs?: number;
|
|
27
|
+
readonly observedOutcome?: string;
|
|
28
|
+
readonly observedBinary?: boolean;
|
|
29
|
+
readonly mismatch?: MismatchKind;
|
|
30
|
+
}
|
|
31
|
+
export interface ScoredPrediction {
|
|
32
|
+
readonly predictionId: string;
|
|
33
|
+
readonly mismatch: MismatchKind;
|
|
34
|
+
readonly brier?: number;
|
|
35
|
+
readonly surprise?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Register a prediction. The host calls this BEFORE the operation runs.
|
|
39
|
+
* hostSequence is a host-owned monotone counter; predictions are immutable
|
|
40
|
+
* once registered — corrections append a new record.
|
|
41
|
+
*/
|
|
42
|
+
export declare function registerPrediction(ledger: readonly Prediction[], prediction: Omit<Prediction, "status">): readonly Prediction[];
|
|
43
|
+
/**
|
|
44
|
+
* Resolve a registered prediction against a host observation bound to the
|
|
45
|
+
* same candidate/check/environment fingerprints. Mismatched bindings reject —
|
|
46
|
+
* a prediction for one candidate cannot be scored against another.
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolvePrediction(ledger: readonly Prediction[], predictionId: string, observation: {
|
|
49
|
+
readonly candidateHash: string;
|
|
50
|
+
readonly environmentHash: string;
|
|
51
|
+
readonly checkDefinitionHash: string;
|
|
52
|
+
readonly outcome: string;
|
|
53
|
+
readonly binaryOutcome?: boolean;
|
|
54
|
+
readonly sideEffect?: boolean;
|
|
55
|
+
readonly observedAtMs: number;
|
|
56
|
+
}): {
|
|
57
|
+
ledger: readonly Prediction[];
|
|
58
|
+
scored: ScoredPrediction;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Mark a prediction superseded (policy/budget/target changed before outcome)
|
|
62
|
+
* or unobserved (cancelled, environment failure, late result). Neither is
|
|
63
|
+
* ever scored as a code result.
|
|
64
|
+
*/
|
|
65
|
+
export declare function retirePrediction(ledger: readonly Prediction[], predictionId: string, outcome: "superseded" | "unobserved"): readonly Prediction[];
|
|
66
|
+
/** Categorical mismatch summary plus scored aggregates. */
|
|
67
|
+
export declare function mismatchSummary(ledger: readonly Prediction[]): {
|
|
68
|
+
readonly total: number;
|
|
69
|
+
readonly resolved: number;
|
|
70
|
+
readonly byKind: Readonly<Record<MismatchKind, number>>;
|
|
71
|
+
readonly meanBrier?: number;
|
|
72
|
+
readonly meanSurprise?: number;
|
|
73
|
+
readonly surprising: readonly ScoredPrediction[];
|
|
74
|
+
};
|
|
75
|
+
/** §5.5: map a mismatch kind to the short control branch it triggers. */
|
|
76
|
+
export declare function mismatchBranch(kind: MismatchKind): string;
|
|
77
|
+
export declare function predictionFingerprint(p: Prediction): string;
|
|
78
|
+
//# sourceMappingURL=predictions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1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;;GAIG;AACH,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,SAAS,UAAU,EAAE,EAC7B,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,YAAY,GAAG,YAAY,GAClC,SAAS,UAAU,EAAE,CAQvB;AAED,2DAA2D;AAC3D,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,UAAU,EAAE,GAAG;IAC/D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;IACxD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,UAAU,EAAE,SAAS,gBAAgB,EAAE,CAAC;CACjD,CAyCA;AAED,0EAAyE;AACzE,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAezD;AAED,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,UAAU,GAAG,MAAM,CAW3D","sourcesContent":["/**\n * Algorithm B — pre-execution prediction ledger and mismatch scoring.\n * Spec: OMK_metacognitive_control_algorithms_2026-09-19.md §5.\n *\n * Predictions are registered by the host BEFORE outcomes exist and bound to\n * candidate/environment/check/policy fingerprints. Later edits append a new\n * prediction — existing records are never overwritten. Unobserved, cancelled,\n * or environment-failed outcomes stay unobserved; they are never silently\n * scored as code success or failure.\n */\nimport { brier, surprise } from \"./decision.ts\";\nimport { canonical, ensure, integer, lexical, member, text, unique } from \"./validation.ts\";\n\nexport type PredictionKind = \"check-outcome\" | \"scope\" | \"side-effect\" | \"resource\" | \"hypothesis-outcome\";\nexport type EstimatorKind = \"uncalibrated-model-estimate\" | \"validated-estimator\" | \"none\";\nexport type PredictionStatus = \"registered\" | \"resolved\" | \"superseded\" | \"unobserved\";\nexport type MismatchKind =\n\t| \"unexpected-pass\"\n\t| \"unexpected-fail\"\n\t| \"unexpected-side-effect\"\n\t| \"missing-observation\"\n\t| \"scope-mismatch\"\n\t| \"none\";\n\nexport interface Prediction {\n\treadonly predictionId: string;\n\treadonly operationId: string;\n\treadonly taskId: string;\n\treadonly stageId: string;\n\treadonly kind: PredictionKind;\n\treadonly candidateHash: string;\n\treadonly environmentHash: string;\n\treadonly checkDefinitionHash: string;\n\treadonly policyVersion: string;\n\treadonly modelRevision: string;\n\treadonly skillHashes: readonly string[];\n\treadonly expectedOutcome: string;\n\t/** Binary expectation for scored predictions; undefined for categorical. */\n\treadonly expectedBinary?: boolean;\n\treadonly probability?: number;\n\treadonly estimator: EstimatorKind;\n\treadonly counterevidenceCondition: string;\n\treadonly hostSequence: number;\n\treadonly registeredAtMs: number;\n\tstatus: PredictionStatus;\n\treadonly resolvedAtMs?: number;\n\treadonly observedOutcome?: string;\n\treadonly observedBinary?: boolean;\n\treadonly mismatch?: MismatchKind;\n}\nexport interface ScoredPrediction {\n\treadonly predictionId: string;\n\treadonly mismatch: MismatchKind;\n\treadonly brier?: number;\n\treadonly surprise?: number;\n}\n\nconst LEDGER_BOUND = 4096;\n\nfunction validatePrediction(p: Prediction): void {\n\ttext(p.predictionId, \"predictionId\", 128);\n\ttext(p.operationId, \"operationId\", 128);\n\ttext(p.taskId, \"taskId\", 128);\n\ttext(p.stageId, \"stageId\", 128);\n\tmember(p.kind, [\"check-outcome\", \"scope\", \"side-effect\", \"resource\", \"hypothesis-outcome\"], \"kind\");\n\ttext(p.candidateHash, \"candidateHash\", 128);\n\ttext(p.environmentHash, \"environmentHash\", 128);\n\ttext(p.checkDefinitionHash, \"checkDefinitionHash\", 128);\n\ttext(p.policyVersion, \"policyVersion\", 64);\n\ttext(p.modelRevision, \"modelRevision\", 128);\n\tunique(p.skillHashes, \"skillHashes\", 64);\n\ttext(p.expectedOutcome, \"expectedOutcome\", 2048);\n\ttext(p.counterevidenceCondition, \"counterevidenceCondition\", 2048);\n\tmember(p.estimator, [\"uncalibrated-model-estimate\", \"validated-estimator\", \"none\"], \"estimator\");\n\tinteger(p.hostSequence, \"hostSequence\");\n\tinteger(p.registeredAtMs, \"registeredAtMs\");\n\tif (p.probability !== undefined) {\n\t\tensure(p.probability >= 0 && p.probability <= 1, \"probability out of range\");\n\t\tensure(p.estimator !== \"none\", \"probability requires a declared estimator\");\n\t}\n\tif (p.expectedBinary !== undefined) ensure(typeof p.expectedBinary === \"boolean\", \"expectedBinary\");\n}\n\n/**\n * Register a prediction. The host calls this BEFORE the operation runs.\n * hostSequence is a host-owned monotone counter; predictions are immutable\n * once registered — corrections append a new record.\n */\nexport function registerPrediction(\n\tledger: readonly Prediction[],\n\tprediction: Omit<Prediction, \"status\">,\n): readonly Prediction[] {\n\tensure(ledger.length < LEDGER_BOUND, \"prediction ledger bound exceeded\");\n\tvalidatePrediction({ ...prediction, status: \"registered\" });\n\tensure(!ledger.some((p) => p.predictionId === prediction.predictionId), \"duplicate predictionId\");\n\treturn [...ledger, { ...prediction, status: \"registered\" }];\n}\n\n/**\n * Resolve a registered prediction against a host observation bound to the\n * same candidate/check/environment fingerprints. Mismatched bindings reject —\n * a prediction for one candidate cannot be scored against another.\n */\nexport function resolvePrediction(\n\tledger: readonly Prediction[],\n\tpredictionId: string,\n\tobservation: {\n\t\treadonly candidateHash: string;\n\t\treadonly environmentHash: string;\n\t\treadonly checkDefinitionHash: string;\n\t\treadonly outcome: string;\n\t\treadonly binaryOutcome?: boolean;\n\t\treadonly sideEffect?: boolean;\n\t\treadonly observedAtMs: number;\n\t},\n): { ledger: readonly Prediction[]; scored: ScoredPrediction } {\n\ttext(predictionId, \"predictionId\", 128);\n\tconst index = ledger.findIndex((p) => p.predictionId === predictionId);\n\tensure(index >= 0, \"unknown predictionId\");\n\tconst p = ledger[index]!;\n\tensure(p.status === \"registered\", `prediction ${predictionId} is ${p.status}`);\n\tensure(observation.candidateHash === p.candidateHash, \"candidate binding mismatch\");\n\tensure(observation.environmentHash === p.environmentHash, \"environment binding mismatch\");\n\tensure(observation.checkDefinitionHash === p.checkDefinitionHash, \"check binding mismatch\");\n\tinteger(observation.observedAtMs, \"observedAtMs\");\n\tensure(observation.observedAtMs >= p.registeredAtMs, \"observation predates registration\");\n\tlet mismatch: MismatchKind = \"none\";\n\tlet score: number | undefined;\n\tlet surpriseScore: number | undefined;\n\tif (observation.binaryOutcome !== undefined && p.expectedBinary !== undefined) {\n\t\tconst outcome: 0 | 1 = observation.binaryOutcome ? 1 : 0;\n\t\tconst expected: 0 | 1 = p.expectedBinary ? 1 : 0;\n\t\tif (outcome !== expected) mismatch = p.kind === \"check-outcome\" ? \"unexpected-fail\" : \"unexpected-side-effect\";\n\t\tif (p.probability !== undefined) {\n\t\t\tscore = brier(p.probability, outcome);\n\t\t\tsurpriseScore = surprise(p.probability, outcome);\n\t\t}\n\t} else if (observation.outcome !== p.expectedOutcome) {\n\t\tmismatch = p.kind === \"scope\" ? \"scope-mismatch\" : \"unexpected-fail\";\n\t}\n\tif (observation.sideEffect === true && p.kind !== \"side-effect\" && mismatch === \"none\") {\n\t\tmismatch = \"unexpected-side-effect\";\n\t}\n\tconst resolved: Prediction = {\n\t\t...p,\n\t\tstatus: \"resolved\",\n\t\tresolvedAtMs: observation.observedAtMs,\n\t\tobservedOutcome: observation.outcome,\n\t\tobservedBinary: observation.binaryOutcome,\n\t\tmismatch,\n\t};\n\tconst next = ledger.slice();\n\tnext[index] = resolved;\n\treturn { ledger: next, scored: { predictionId, mismatch, brier: score, surprise: surpriseScore } };\n}\n\n/**\n * Mark a prediction superseded (policy/budget/target changed before outcome)\n * or unobserved (cancelled, environment failure, late result). Neither is\n * ever scored as a code result.\n */\nexport function retirePrediction(\n\tledger: readonly Prediction[],\n\tpredictionId: string,\n\toutcome: \"superseded\" | \"unobserved\",\n): readonly Prediction[] {\n\tconst index = ledger.findIndex((p) => p.predictionId === predictionId);\n\tensure(index >= 0, \"unknown predictionId\");\n\tconst p = ledger[index]!;\n\tensure(p.status === \"registered\", `prediction ${predictionId} is ${p.status}`);\n\tconst next = ledger.slice();\n\tnext[index] = { ...p, status: outcome };\n\treturn next;\n}\n\n/** Categorical mismatch summary plus scored aggregates. */\nexport function mismatchSummary(ledger: readonly Prediction[]): {\n\treadonly total: number;\n\treadonly resolved: number;\n\treadonly byKind: Readonly<Record<MismatchKind, number>>;\n\treadonly meanBrier?: number;\n\treadonly meanSurprise?: number;\n\treadonly surprising: readonly ScoredPrediction[];\n} {\n\tconst byKind: Record<MismatchKind, number> = {\n\t\t\"unexpected-pass\": 0,\n\t\t\"unexpected-fail\": 0,\n\t\t\"unexpected-side-effect\": 0,\n\t\t\"missing-observation\": 0,\n\t\t\"scope-mismatch\": 0,\n\t\tnone: 0,\n\t};\n\tconst surprising: ScoredPrediction[] = [];\n\tlet brierSum = 0,\n\t\tsurpriseSum = 0,\n\t\tscored = 0;\n\tfor (const p of ledger) {\n\t\tif (p.status !== \"resolved\") continue;\n\t\tconst kind = p.mismatch ?? \"none\";\n\t\tbyKind[kind] += 1;\n\t\tif (p.observedBinary !== undefined && p.probability !== undefined) {\n\t\t\tconst outcome: 0 | 1 = p.observedBinary ? 1 : 0;\n\t\t\tbrierSum += brier(p.probability, outcome);\n\t\t\tsurpriseSum += surprise(p.probability, outcome);\n\t\t\tscored += 1;\n\t\t\tif (kind !== \"none\") {\n\t\t\t\tsurprising.push({\n\t\t\t\t\tpredictionId: p.predictionId,\n\t\t\t\t\tmismatch: kind,\n\t\t\t\t\tbrier: brier(p.probability, outcome),\n\t\t\t\t\tsurprise: surprise(p.probability, outcome),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\tsurprising.sort((a, b) => (b.surprise ?? 0) - (a.surprise ?? 0) || lexical(a.predictionId, b.predictionId));\n\treturn {\n\t\ttotal: ledger.length,\n\t\tresolved: scored,\n\t\tbyKind,\n\t\tmeanBrier: scored > 0 ? brierSum / scored : undefined,\n\t\tmeanSurprise: scored > 0 ? surpriseSum / scored : undefined,\n\t\tsurprising,\n\t};\n}\n\n/** §5.5: map a mismatch kind to the short control branch it triggers. */\nexport function mismatchBranch(kind: MismatchKind): string {\n\tswitch (kind) {\n\t\tcase \"scope-mismatch\":\n\t\t\treturn \"impact-analysis-and-obligation-refresh\";\n\t\tcase \"unexpected-fail\":\n\t\t\treturn \"cause-hypothesis-discrimination\";\n\t\tcase \"unexpected-pass\":\n\t\t\treturn \"verifier-evaluation\";\n\t\tcase \"unexpected-side-effect\":\n\t\t\treturn \"boundary-and-permission-review\";\n\t\tcase \"missing-observation\":\n\t\t\treturn \"coverage-gap-registration\";\n\t\tcase \"none\":\n\t\t\treturn \"continue\";\n\t}\n}\n\nexport function predictionFingerprint(p: Prediction): string {\n\treturn canonical([\n\t\tp.operationId,\n\t\tp.taskId,\n\t\tp.stageId,\n\t\tp.candidateHash,\n\t\tp.environmentHash,\n\t\tp.checkDefinitionHash,\n\t\tp.policyVersion,\n\t\tp.modelRevision,\n\t]);\n}\n"]}
|