open-multi-agent-kit 0.99.0 → 1.2.0
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 +30 -1
- package/README.md +3 -3
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js +1 -0
- package/dist/bun/cli.js.map +1 -1
- package/dist/bun/register-bundled-coding-agent.d.ts +10 -0
- package/dist/bun/register-bundled-coding-agent.d.ts.map +1 -0
- package/dist/bun/register-bundled-coding-agent.js +12 -0
- package/dist/bun/register-bundled-coding-agent.js.map +1 -0
- package/dist/cli/args.d.ts +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +1 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +2 -1
- package/dist/cli/help.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +14 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/neo-cli.d.ts +9 -0
- package/dist/commands/neo-cli.d.ts.map +1 -0
- package/dist/commands/neo-cli.js +61 -0
- package/dist/commands/neo-cli.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 +195 -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 +106 -0
- package/dist/coordination/operation.d.ts.map +1 -0
- package/dist/coordination/operation.js +179 -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 +89 -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/agent-session.d.ts +29 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +135 -37
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bundled-skills.d.ts +4 -0
- package/dist/core/bundled-skills.d.ts.map +1 -0
- package/dist/core/bundled-skills.js +32 -0
- package/dist/core/bundled-skills.js.map +1 -0
- package/dist/core/cli-diagnostics.d.ts +6 -0
- package/dist/core/cli-diagnostics.d.ts.map +1 -0
- package/dist/core/cli-diagnostics.js +20 -0
- package/dist/core/cli-diagnostics.js.map +1 -0
- 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 +60 -0
- package/dist/core/compaction/fallback.d.ts.map +1 -0
- package/dist/core/compaction/fallback.js +117 -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/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 +22 -0
- package/dist/core/context-budget-headroom.d.ts.map +1 -1
- package/dist/core/context-budget-headroom.js +46 -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-input-validation.d.ts +4 -0
- package/dist/core/context-budget-v2-input-validation.d.ts.map +1 -0
- package/dist/core/context-budget-v2-input-validation.js +79 -0
- package/dist/core/context-budget-v2-input-validation.js.map +1 -0
- package/dist/core/context-budget-v2-observability.d.ts +15 -0
- package/dist/core/context-budget-v2-observability.d.ts.map +1 -0
- package/dist/core/context-budget-v2-observability.js +35 -0
- package/dist/core/context-budget-v2-observability.js.map +1 -0
- package/dist/core/context-budget-v2-planned-items.d.ts +17 -0
- package/dist/core/context-budget-v2-planned-items.d.ts.map +1 -0
- package/dist/core/context-budget-v2-planned-items.js +59 -0
- package/dist/core/context-budget-v2-planned-items.js.map +1 -0
- package/dist/core/context-budget-v2-planner.d.ts.map +1 -1
- package/dist/core/context-budget-v2-planner.js +69 -51
- 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 +22 -3
- package/dist/core/context-budget-v2-selection.d.ts.map +1 -1
- package/dist/core/context-budget-v2-selection.js +41 -59
- package/dist/core/context-budget-v2-selection.js.map +1 -1
- package/dist/core/context-budget-v2-tiers.d.ts.map +1 -1
- package/dist/core/context-budget-v2-tiers.js +9 -42
- package/dist/core/context-budget-v2-tiers.js.map +1 -1
- package/dist/core/context-budget-v2-types.d.ts +14 -2
- 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/extensions/bundled-virtual-modules.d.ts +15 -0
- package/dist/core/extensions/bundled-virtual-modules.d.ts.map +1 -0
- package/dist/core/extensions/bundled-virtual-modules.js +63 -0
- package/dist/core/extensions/bundled-virtual-modules.js.map +1 -0
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +2 -42
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +1 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +6 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +10 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/loadout-runtime.d.ts +2 -8
- package/dist/core/loadout-runtime.d.ts.map +1 -1
- package/dist/core/loadout-runtime.js.map +1 -1
- package/dist/core/mcp/client.d.ts +27 -6
- package/dist/core/mcp/client.d.ts.map +1 -1
- package/dist/core/mcp/client.js +80 -20
- package/dist/core/mcp/client.js.map +1 -1
- package/dist/core/mcp/manager.d.ts +10 -1
- package/dist/core/mcp/manager.d.ts.map +1 -1
- package/dist/core/mcp/manager.js +68 -9
- package/dist/core/mcp/manager.js.map +1 -1
- package/dist/core/mcp/protocol.d.ts +9 -3
- package/dist/core/mcp/protocol.d.ts.map +1 -1
- package/dist/core/mcp/protocol.js +61 -15
- package/dist/core/mcp/protocol.js.map +1 -1
- package/dist/core/mcp/stdio-transport.d.ts +12 -1
- package/dist/core/mcp/stdio-transport.d.ts.map +1 -1
- package/dist/core/mcp/stdio-transport.js +30 -2
- package/dist/core/mcp/stdio-transport.js.map +1 -1
- package/dist/core/mcp-descriptor-injection.d.ts +26 -0
- package/dist/core/mcp-descriptor-injection.d.ts.map +1 -0
- package/dist/core/mcp-descriptor-injection.js +25 -0
- package/dist/core/mcp-descriptor-injection.js.map +1 -0
- package/dist/core/mcp-public-presets.d.ts +1 -3
- package/dist/core/mcp-public-presets.d.ts.map +1 -1
- package/dist/core/mcp-public-presets.js +3 -15
- package/dist/core/mcp-public-presets.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +24 -3
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/neo/catalog.d.ts +20 -0
- package/dist/core/neo/catalog.d.ts.map +1 -0
- package/dist/core/neo/catalog.js +50 -0
- package/dist/core/neo/catalog.js.map +1 -0
- package/dist/core/neo/setup.d.ts +3 -0
- package/dist/core/neo/setup.d.ts.map +1 -0
- package/dist/core/neo/setup.js +47 -0
- package/dist/core/neo/setup.js.map +1 -0
- package/dist/core/provider-default-models.d.ts +2 -0
- package/dist/core/provider-default-models.d.ts.map +1 -1
- package/dist/core/provider-default-models.js +2 -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 +2 -0
- package/dist/core/provider-display-names.js.map +1 -1
- package/dist/core/provider-error-classification.d.ts +57 -0
- package/dist/core/provider-error-classification.d.ts.map +1 -0
- package/dist/core/provider-error-classification.js +103 -0
- package/dist/core/provider-error-classification.js.map +1 -0
- package/dist/core/provider-resilience.d.ts +10 -0
- package/dist/core/provider-resilience.d.ts.map +1 -1
- package/dist/core/provider-resilience.js +36 -3
- package/dist/core/provider-resilience.js.map +1 -1
- package/dist/core/provider-usage-commandcode.d.ts +9 -0
- package/dist/core/provider-usage-commandcode.d.ts.map +1 -0
- package/dist/core/provider-usage-commandcode.js +198 -0
- package/dist/core/provider-usage-commandcode.js.map +1 -0
- package/dist/core/provider-usage-devin.d.ts +5 -3
- package/dist/core/provider-usage-devin.d.ts.map +1 -1
- package/dist/core/provider-usage-devin.js +15 -5
- package/dist/core/provider-usage-devin.js.map +1 -1
- package/dist/core/provider-usage-types.d.ts +1 -1
- package/dist/core/provider-usage-types.d.ts.map +1 -1
- package/dist/core/provider-usage-types.js.map +1 -1
- package/dist/core/provider-usage.d.ts.map +1 -1
- package/dist/core/provider-usage.js +6 -0
- package/dist/core/provider-usage.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 +8 -5
- 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-admission.d.ts +36 -0
- package/dist/core/resource-admission.d.ts.map +1 -1
- package/dist/core/resource-admission.js +59 -0
- package/dist/core/resource-admission.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +2 -2
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/run-usage-ledger.d.ts +47 -0
- package/dist/core/run-usage-ledger.d.ts.map +1 -0
- package/dist/core/run-usage-ledger.js +162 -0
- package/dist/core/run-usage-ledger.js.map +1 -0
- package/dist/core/run-usage-operation.d.ts +8 -0
- package/dist/core/run-usage-operation.d.ts.map +1 -0
- package/dist/core/run-usage-operation.js +12 -0
- package/dist/core/run-usage-operation.js.map +1 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +5 -6
- package/dist/core/sdk.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-failure-cause.d.ts.map +1 -1
- package/dist/core/session-failure-cause.js +14 -5
- package/dist/core/session-failure-cause.js.map +1 -1
- package/dist/core/session-prompt-lifecycle.d.ts +6 -0
- package/dist/core/session-prompt-lifecycle.d.ts.map +1 -1
- package/dist/core/session-prompt-lifecycle.js +47 -2
- package/dist/core/session-prompt-lifecycle.js.map +1 -1
- package/dist/core/session-termination.d.ts.map +1 -1
- package/dist/core/session-termination.js +4 -2
- package/dist/core/session-termination.js.map +1 -1
- package/dist/core/subagent-lane-authority.d.ts +28 -0
- package/dist/core/subagent-lane-authority.d.ts.map +1 -0
- package/dist/core/subagent-lane-authority.js +119 -0
- package/dist/core/subagent-lane-authority.js.map +1 -0
- package/dist/core/subagent-lane-contract.d.ts +114 -0
- package/dist/core/subagent-lane-contract.d.ts.map +1 -0
- package/dist/core/subagent-lane-contract.js +18 -0
- package/dist/core/subagent-lane-contract.js.map +1 -0
- package/dist/core/subagent-lane-launcher.d.ts +3 -6
- package/dist/core/subagent-lane-launcher.d.ts.map +1 -1
- package/dist/core/subagent-lane-launcher.js +53 -12
- package/dist/core/subagent-lane-launcher.js.map +1 -1
- package/dist/core/subagent-orchestration.d.ts +4 -17
- package/dist/core/subagent-orchestration.d.ts.map +1 -1
- package/dist/core/subagent-orchestration.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/verified-run/broker.d.ts.map +1 -1
- package/dist/core/verified-run/broker.js +4 -1
- package/dist/core/verified-run/broker.js.map +1 -1
- package/dist/core/workload-permit-pool.d.ts +1 -1
- package/dist/core/workload-permit-pool.d.ts.map +1 -1
- package/dist/core/workload-permit-pool.js +3 -0
- package/dist/core/workload-permit-pool.js.map +1 -1
- package/dist/guardrails/strict-evidence-approval-adapter.d.ts +34 -0
- package/dist/guardrails/strict-evidence-approval-adapter.d.ts.map +1 -0
- package/dist/guardrails/strict-evidence-approval-adapter.js +70 -0
- package/dist/guardrails/strict-evidence-approval-adapter.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +11 -18
- package/dist/main.js.map +1 -1
- 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 +161 -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 +31 -0
- package/dist/metacognition/index.d.ts.map +1 -0
- package/dist/metacognition/index.js +31 -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 +165 -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 +54 -0
- package/dist/metacognition/runtime-bridge.d.ts.map +1 -0
- package/dist/metacognition/runtime-bridge.js +140 -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/acp/acp-agent.d.ts +24 -0
- package/dist/modes/acp/acp-agent.d.ts.map +1 -0
- package/dist/modes/acp/acp-agent.js +133 -0
- package/dist/modes/acp/acp-agent.js.map +1 -0
- package/dist/modes/acp/acp-mode.d.ts +4 -0
- package/dist/modes/acp/acp-mode.d.ts.map +1 -0
- package/dist/modes/acp/acp-mode.js +34 -0
- package/dist/modes/acp/acp-mode.js.map +1 -0
- package/dist/modes/acp/acp-session.d.ts +4 -0
- package/dist/modes/acp/acp-session.d.ts.map +1 -0
- package/dist/modes/acp/acp-session.js +76 -0
- package/dist/modes/acp/acp-session.js.map +1 -0
- package/dist/modes/acp/acp-transport.d.ts +5 -0
- package/dist/modes/acp/acp-transport.d.ts.map +1 -0
- package/dist/modes/acp/acp-transport.js +90 -0
- package/dist/modes/acp/acp-transport.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- 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/docs/audit-revalidation-2026-09-17.md +77 -0
- package/docs/devin-harness.md +33 -4
- package/docs/ecraf-normalization.md +83 -0
- package/docs/metacognition.md +51 -0
- package/docs/model-catalog-refresh.md +110 -1
- package/docs/models.md +1 -1
- package/docs/neo.md +134 -0
- package/docs/providers.md +125 -6
- package/docs/run-usage-ledger.md +56 -0
- package/docs/runtime-algorithms.md +151 -3
- package/docs/skills.md +1 -1
- package/docs/usage.md +2 -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/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/subagent/adaptive-agent-runtime.ts +14 -1
- package/examples/extensions/subagent/graph-result.ts +48 -0
- package/examples/extensions/subagent/index.ts +246 -111
- package/examples/extensions/subagent/managed-process-tree.ts +42 -0
- package/examples/extensions/subagent/managed-process.test.ts +24 -0
- package/examples/extensions/subagent/managed-process.ts +93 -112
- package/examples/extensions/subagent/subagent-runtime-types.ts +17 -1
- package/examples/extensions/subagent/subagent-stream.ts +161 -0
- package/examples/extensions/terminal-browser/README.md +54 -0
- package/examples/extensions/terminal-browser/bridge-protocol.ts +29 -0
- package/examples/extensions/terminal-browser/bridge.ts +219 -0
- package/examples/extensions/terminal-browser/browser-surface.ts +288 -0
- package/examples/extensions/terminal-browser/index.ts +215 -0
- package/examples/extensions/terminal-browser/placeholders.ts +49 -0
- 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 +8 -7
- package/resources/neo/skills/omk-browser/SKILL.md +32 -0
- package/resources/neo/skills/omk-code-review/SKILL.md +24 -0
- package/resources/neo/skills/omk-computeruse/SKILL.md +34 -0
- package/resources/neo/skills/omk-mcp-setup/SKILL.md +48 -0
- package/resources/neo/skills/omk-research/SKILL.md +24 -0
- package/resources/neo/skills/omk-site/SKILL.md +28 -0
|
@@ -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":"","sources":["../../src/metacognition/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAiCxE,MAAM,SAAS,GAA8B;IAC5C,eAAe;IACf,oBAAoB;IACpB,0BAA0B;IAC1B,qBAAqB;IACrB,iBAAiB;IACjB,uBAAuB;IACvB,iBAAiB;IACjB,2BAA2B;IAC3B,sBAAsB;IACtB,2BAA2B;IAC3B,mBAAmB;IACnB,eAAe;IACf,kBAAkB;CAClB,CAAC;AAEF,yEAAkE;AAClE,MAAM,UAAU,eAAe,CAA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C,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
|
+
{"version":3,"file":"predictions.d.ts","sourceRoot":"","sources":["../../src/metacognition/predictions.ts"],"names":[],"mappings":"AAaA,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,OAAO,GAAG,aAAa,GAAG,UAAU,GAAG,oBAAoB,CAAC;AAC3G,MAAM,MAAM,aAAa,GAAG,6BAA6B,GAAG,qBAAqB,GAAG,MAAM,CAAC;AAC3F,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG,UAAU,GAAG,YAAY,GAAG,YAAY,CAAC;AACvF,MAAM,MAAM,YAAY,GACrB,iBAAiB,GACjB,iBAAiB,GACjB,wBAAwB,GACxB,qBAAqB,GACrB,gBAAgB,GAChB,MAAM,CAAC;AAEV,MA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AC,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"]}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Algorithm B — pre-execution prediction ledger and mismatch scoring.
|
|
3
|
+
* Spec: OMK_metacognitive_control_algorithms_2026-09-19.md §5.
|
|
4
|
+
*
|
|
5
|
+
* Predictions are registered by the host BEFORE outcomes exist and bound to
|
|
6
|
+
* candidate/environment/check/policy fingerprints. Later edits append a new
|
|
7
|
+
* prediction — existing records are never overwritten. Unobserved, cancelled,
|
|
8
|
+
* or environment-failed outcomes stay unobserved; they are never silently
|
|
9
|
+
* scored as code success or failure.
|
|
10
|
+
*/
|
|
11
|
+
import { brier, surprise } from "./decision.js";
|
|
12
|
+
import { canonical, ensure, integer, lexical, member, text, unique } from "./validation.js";
|
|
13
|
+
const LEDGER_BOUND = 4096;
|
|
14
|
+
function validatePrediction(p) {
|
|
15
|
+
text(p.predictionId, "predictionId", 128);
|
|
16
|
+
text(p.operationId, "operationId", 128);
|
|
17
|
+
text(p.taskId, "taskId", 128);
|
|
18
|
+
text(p.stageId, "stageId", 128);
|
|
19
|
+
member(p.kind, ["check-outcome", "scope", "side-effect", "resource", "hypothesis-outcome"], "kind");
|
|
20
|
+
text(p.candidateHash, "candidateHash", 128);
|
|
21
|
+
text(p.environmentHash, "environmentHash", 128);
|
|
22
|
+
text(p.checkDefinitionHash, "checkDefinitionHash", 128);
|
|
23
|
+
text(p.policyVersion, "policyVersion", 64);
|
|
24
|
+
text(p.modelRevision, "modelRevision", 128);
|
|
25
|
+
unique(p.skillHashes, "skillHashes", 64);
|
|
26
|
+
text(p.expectedOutcome, "expectedOutcome", 2048);
|
|
27
|
+
text(p.counterevidenceCondition, "counterevidenceCondition", 2048);
|
|
28
|
+
member(p.estimator, ["uncalibrated-model-estimate", "validated-estimator", "none"], "estimator");
|
|
29
|
+
integer(p.hostSequence, "hostSequence");
|
|
30
|
+
integer(p.registeredAtMs, "registeredAtMs");
|
|
31
|
+
if (p.probability !== undefined) {
|
|
32
|
+
ensure(p.probability >= 0 && p.probability <= 1, "probability out of range");
|
|
33
|
+
ensure(p.estimator !== "none", "probability requires a declared estimator");
|
|
34
|
+
}
|
|
35
|
+
if (p.expectedBinary !== undefined)
|
|
36
|
+
ensure(typeof p.expectedBinary === "boolean", "expectedBinary");
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Register a prediction. The host calls this BEFORE the operation runs.
|
|
40
|
+
* hostSequence is a host-owned monotone counter; predictions are immutable
|
|
41
|
+
* once registered — corrections append a new record.
|
|
42
|
+
*/
|
|
43
|
+
export function registerPrediction(ledger, prediction) {
|
|
44
|
+
ensure(ledger.length < LEDGER_BOUND, "prediction ledger bound exceeded");
|
|
45
|
+
validatePrediction({ ...prediction, status: "registered" });
|
|
46
|
+
ensure(!ledger.some((p) => p.predictionId === prediction.predictionId), "duplicate predictionId");
|
|
47
|
+
return [...ledger, { ...prediction, status: "registered" }];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Resolve a registered prediction against a host observation bound to the
|
|
51
|
+
* same candidate/check/environment fingerprints. Mismatched bindings reject —
|
|
52
|
+
* a prediction for one candidate cannot be scored against another.
|
|
53
|
+
*/
|
|
54
|
+
export function resolvePrediction(ledger, predictionId, observation) {
|
|
55
|
+
text(predictionId, "predictionId", 128);
|
|
56
|
+
const index = ledger.findIndex((p) => p.predictionId === predictionId);
|
|
57
|
+
ensure(index >= 0, "unknown predictionId");
|
|
58
|
+
const p = ledger[index];
|
|
59
|
+
ensure(p.status === "registered", `prediction ${predictionId} is ${p.status}`);
|
|
60
|
+
ensure(observation.candidateHash === p.candidateHash, "candidate binding mismatch");
|
|
61
|
+
ensure(observation.environmentHash === p.environmentHash, "environment binding mismatch");
|
|
62
|
+
ensure(observation.checkDefinitionHash === p.checkDefinitionHash, "check binding mismatch");
|
|
63
|
+
integer(observation.observedAtMs, "observedAtMs");
|
|
64
|
+
ensure(observation.observedAtMs >= p.registeredAtMs, "observation predates registration");
|
|
65
|
+
let mismatch = "none";
|
|
66
|
+
let score;
|
|
67
|
+
let surpriseScore;
|
|
68
|
+
if (observation.binaryOutcome !== undefined && p.expectedBinary !== undefined) {
|
|
69
|
+
const outcome = observation.binaryOutcome ? 1 : 0;
|
|
70
|
+
const expected = p.expectedBinary ? 1 : 0;
|
|
71
|
+
if (outcome !== expected)
|
|
72
|
+
mismatch = p.kind === "check-outcome" ? "unexpected-fail" : "unexpected-side-effect";
|
|
73
|
+
if (p.probability !== undefined) {
|
|
74
|
+
score = brier(p.probability, outcome);
|
|
75
|
+
surpriseScore = surprise(p.probability, outcome);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else if (observation.outcome !== p.expectedOutcome) {
|
|
79
|
+
mismatch = p.kind === "scope" ? "scope-mismatch" : "unexpected-fail";
|
|
80
|
+
}
|
|
81
|
+
if (observation.sideEffect === true && p.kind !== "side-effect" && mismatch === "none") {
|
|
82
|
+
mismatch = "unexpected-side-effect";
|
|
83
|
+
}
|
|
84
|
+
const resolved = {
|
|
85
|
+
...p,
|
|
86
|
+
status: "resolved",
|
|
87
|
+
resolvedAtMs: observation.observedAtMs,
|
|
88
|
+
observedOutcome: observation.outcome,
|
|
89
|
+
observedBinary: observation.binaryOutcome,
|
|
90
|
+
mismatch,
|
|
91
|
+
};
|
|
92
|
+
const next = ledger.slice();
|
|
93
|
+
next[index] = resolved;
|
|
94
|
+
return { ledger: next, scored: { predictionId, mismatch, brier: score, surprise: surpriseScore } };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Mark a prediction superseded (policy/budget/target changed before outcome)
|
|
98
|
+
* or unobserved (cancelled, environment failure, late result). Neither is
|
|
99
|
+
* ever scored as a code result.
|
|
100
|
+
*/
|
|
101
|
+
export function retirePrediction(ledger, predictionId, outcome) {
|
|
102
|
+
const index = ledger.findIndex((p) => p.predictionId === predictionId);
|
|
103
|
+
ensure(index >= 0, "unknown predictionId");
|
|
104
|
+
const p = ledger[index];
|
|
105
|
+
ensure(p.status === "registered", `prediction ${predictionId} is ${p.status}`);
|
|
106
|
+
const next = ledger.slice();
|
|
107
|
+
next[index] = { ...p, status: outcome };
|
|
108
|
+
return next;
|
|
109
|
+
}
|
|
110
|
+
/** Categorical mismatch summary plus scored aggregates. */
|
|
111
|
+
export function mismatchSummary(ledger) {
|
|
112
|
+
const byKind = {
|
|
113
|
+
"unexpected-pass": 0,
|
|
114
|
+
"unexpected-fail": 0,
|
|
115
|
+
"unexpected-side-effect": 0,
|
|
116
|
+
"missing-observation": 0,
|
|
117
|
+
"scope-mismatch": 0,
|
|
118
|
+
none: 0,
|
|
119
|
+
};
|
|
120
|
+
const surprising = [];
|
|
121
|
+
let brierSum = 0, surpriseSum = 0, scored = 0;
|
|
122
|
+
for (const p of ledger) {
|
|
123
|
+
if (p.status !== "resolved")
|
|
124
|
+
continue;
|
|
125
|
+
const kind = p.mismatch ?? "none";
|
|
126
|
+
byKind[kind] += 1;
|
|
127
|
+
if (p.observedBinary !== undefined && p.probability !== undefined) {
|
|
128
|
+
const outcome = p.observedBinary ? 1 : 0;
|
|
129
|
+
brierSum += brier(p.probability, outcome);
|
|
130
|
+
surpriseSum += surprise(p.probability, outcome);
|
|
131
|
+
scored += 1;
|
|
132
|
+
if (kind !== "none") {
|
|
133
|
+
surprising.push({
|
|
134
|
+
predictionId: p.predictionId,
|
|
135
|
+
mismatch: kind,
|
|
136
|
+
brier: brier(p.probability, outcome),
|
|
137
|
+
surprise: surprise(p.probability, outcome),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
surprising.sort((a, b) => (b.surprise ?? 0) - (a.surprise ?? 0) || lexical(a.predictionId, b.predictionId));
|
|
143
|
+
return {
|
|
144
|
+
total: ledger.length,
|
|
145
|
+
resolved: scored,
|
|
146
|
+
byKind,
|
|
147
|
+
meanBrier: scored > 0 ? brierSum / scored : undefined,
|
|
148
|
+
meanSurprise: scored > 0 ? surpriseSum / scored : undefined,
|
|
149
|
+
surprising,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/** §5.5: map a mismatch kind to the short control branch it triggers. */
|
|
153
|
+
export function mismatchBranch(kind) {
|
|
154
|
+
switch (kind) {
|
|
155
|
+
case "scope-mismatch":
|
|
156
|
+
return "impact-analysis-and-obligation-refresh";
|
|
157
|
+
case "unexpected-fail":
|
|
158
|
+
return "cause-hypothesis-discrimination";
|
|
159
|
+
case "unexpected-pass":
|
|
160
|
+
return "verifier-evaluation";
|
|
161
|
+
case "unexpected-side-effect":
|
|
162
|
+
return "boundary-and-permission-review";
|
|
163
|
+
case "missing-observation":
|
|
164
|
+
return "coverage-gap-registration";
|
|
165
|
+
case "none":
|
|
166
|
+
return "continue";
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
export function predictionFingerprint(p) {
|
|
170
|
+
return canonical([
|
|
171
|
+
p.operationId,
|
|
172
|
+
p.taskId,
|
|
173
|
+
p.stageId,
|
|
174
|
+
p.candidateHash,
|
|
175
|
+
p.environmentHash,
|
|
176
|
+
p.checkDefinitionHash,
|
|
177
|
+
p.policyVersion,
|
|
178
|
+
p.modelRevision,
|
|
179
|
+
]);
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=predictions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"predictions.js","sourceRoot":"","sources":["../../src/metacognition/predictions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,iBAAiB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AO,gCAAgC,CAAC;QACzC,KAAK,qBAAqB;YACzB,OAAO,2BAA2B,CAAC;QACpC,KAAK,MAAM;YACV,OAAO,UAAU,CAAC;IACpB,CAAC;AAAA,CACD;AAED,MAAM,UAAU,qBAAqB,CAAC,CAAa,EAAU;IAC5D,OAAO,SAAS,CAAC;QAChB,CAAC,CAAC,WAAW;QACb,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,aAAa;QACf,CAAC,CAAC,eAAe;QACjB,CAAC,CAAC,mBAAmB;QACrB,CAAC,CAAC,aAAa;QACf,CAAC,CAAC,aAAa;KACf,CAAC,CAAC;AAAA,CACH","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"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export interface CorpusDocument {
|
|
2
|
+
readonly id: string;
|
|
3
|
+
readonly uri: string;
|
|
4
|
+
readonly body: string;
|
|
5
|
+
}
|
|
6
|
+
export interface SearchHit extends CorpusDocument {
|
|
7
|
+
readonly score: number;
|
|
8
|
+
readonly trust: "candidate-only";
|
|
9
|
+
}
|
|
10
|
+
/** Retrieval tokens, not a semantic-knowledge detector. Short language names survive. */
|
|
11
|
+
export declare function retrievalTokens(value: string): string[];
|
|
12
|
+
/** BM25 with positive IDF; bounded local corpus, no I/O or model call. */
|
|
13
|
+
export declare function searchCorpus(query: string, corpus: readonly CorpusDocument[], limit?: number): SearchHit[];
|
|
14
|
+
export type AcquisitionResult<T> = {
|
|
15
|
+
readonly status: "ok";
|
|
16
|
+
readonly value: T;
|
|
17
|
+
} | {
|
|
18
|
+
readonly status: "budget-exhausted" | "busy" | "timeout" | "aborted" | "stale" | "error";
|
|
19
|
+
};
|
|
20
|
+
export interface AcquisitionOptions {
|
|
21
|
+
readonly maxRequests: number;
|
|
22
|
+
readonly maxInFlight: number;
|
|
23
|
+
readonly durationMs: number;
|
|
24
|
+
readonly perRequestMs: number;
|
|
25
|
+
readonly monotonicNow?: () => number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Owns every started promise until actual settlement, including noncooperative requests.
|
|
29
|
+
* The scope is per host-approved run. It is not a billing or process-isolation boundary.
|
|
30
|
+
*/
|
|
31
|
+
export declare class AcquisitionPool {
|
|
32
|
+
private readonly now;
|
|
33
|
+
private readonly deadline;
|
|
34
|
+
private readonly maxRequests;
|
|
35
|
+
private readonly maxInFlight;
|
|
36
|
+
private readonly perRequestMs;
|
|
37
|
+
private nextId;
|
|
38
|
+
private epoch;
|
|
39
|
+
private requests;
|
|
40
|
+
private readonly active;
|
|
41
|
+
constructor(options: AcquisitionOptions);
|
|
42
|
+
snapshot(): {
|
|
43
|
+
requests: number;
|
|
44
|
+
active: number;
|
|
45
|
+
quarantined: number;
|
|
46
|
+
remainingMs: number;
|
|
47
|
+
epoch: number;
|
|
48
|
+
};
|
|
49
|
+
/** Invalidation requests cancellation but never resets outstanding ownership or budget. */
|
|
50
|
+
invalidate(): void;
|
|
51
|
+
run<T>(operation: (signal: AbortSignal) => Promise<T>, parent?: AbortSignal): Promise<AcquisitionResult<T>>;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=retrieval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retrieval.d.ts","sourceRoot":"","sources":["../../src/metacognition/retrieval.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AACD,MAAM,WAAW,SAAU,SAAQ,cAAc;IAChD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;CACjC;AACD,yFAAyF;AACzF,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAQvD;AACD,0EAA0E;AAC1E,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,cAAc,EAAE,EAAE,KAAK,SAAI,GAAG,SAAS,EAAE,CAyCrG;AAED,MAAM,MAAM,iBAAiB,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O,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAgEhH;CACD","sourcesContent":["/**\n * Bounded local BM25 retrieval and the acquisition pool that owns every\n * started promise until actual settlement.\n *\n * Ported from docs/OMK_skill_knowledge_control_2026-09-19.zip\n * (src/retrieval.ts). Search hits are `candidate-only`, never auto-promoted\n * to observations.\n */\nimport { ensure, integer, lexical, text, unique } from \"./validation.ts\";\n\nexport interface CorpusDocument {\n\treadonly id: string;\n\treadonly uri: string;\n\treadonly body: string;\n}\nexport interface SearchHit extends CorpusDocument {\n\treadonly score: number;\n\treadonly trust: \"candidate-only\";\n}\n/** Retrieval tokens, not a semantic-knowledge detector. Short language names survive. */\nexport function retrievalTokens(value: string): string[] {\n\treturn (\n\t\tvalue\n\t\t\t.normalize(\"NFKC\")\n\t\t\t.replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n\t\t\t.toLowerCase()\n\t\t\t.match(/[\\p{L}\\p{N}]+(?:\\+\\+|#)?/gu) ?? []\n\t);\n}\n/** BM25 with positive IDF; bounded local corpus, no I/O or model call. */\nexport function searchCorpus(query: string, corpus: readonly CorpusDocument[], limit = 8): SearchHit[] {\n\ttext(query, \"query\", 4096);\n\tinteger(limit, \"limit\", 64);\n\tensure(corpus.length <= 5000, \"corpus too large\");\n\tunique(\n\t\tcorpus.map((d) => d.id),\n\t\t\"document ids\",\n\t\t5000,\n\t);\n\tlet totalChars = 0;\n\tconst documents = corpus.map((d) => {\n\t\ttext(d.uri, \"uri\");\n\t\tensure(typeof d.body === \"string\" && d.body.length <= 100_000, \"document too large\");\n\t\ttotalChars += d.body.length;\n\t\tensure(totalChars <= 10_000_000, \"corpus byte/character policy exceeded\");\n\t\tconst tokens = retrievalTokens(d.body);\n\t\tconst frequencies = new Map<string, number>();\n\t\tfor (const token of tokens) frequencies.set(token, (frequencies.get(token) ?? 0) + 1);\n\t\treturn { d, length: tokens.length, frequencies };\n\t});\n\tconst terms = [...new Set(retrievalTokens(query))];\n\tif (!terms.length || !documents.length || limit === 0) return [];\n\tconst avgLength = Math.max(1, documents.reduce((s, d) => s + d.length, 0) / documents.length);\n\tconst idf = new Map(\n\t\tterms.map((term) => {\n\t\t\tconst frequency = documents.filter((d) => d.frequencies.has(term)).length;\n\t\t\treturn [term, Math.log(1 + (documents.length - frequency + 0.5) / (frequency + 0.5))] as const;\n\t\t}),\n\t);\n\treturn documents\n\t\t.map(({ d, length, frequencies }): SearchHit => {\n\t\t\tlet score = 0;\n\t\t\tfor (const term of terms) {\n\t\t\t\tconst tf = frequencies.get(term) ?? 0;\n\t\t\t\tscore += (idf.get(term)! * tf * 2.2) / (tf + 1.2 * (0.25 + (0.75 * length) / avgLength));\n\t\t\t}\n\t\t\treturn { ...d, score, trust: \"candidate-only\" };\n\t\t})\n\t\t.filter((d) => d.score > 0)\n\t\t.sort((a, b) => b.score - a.score || lexical(a.id, b.id))\n\t\t.slice(0, limit);\n}\n\nexport type AcquisitionResult<T> =\n\t| { readonly status: \"ok\"; readonly value: T }\n\t| { readonly status: \"budget-exhausted\" | \"busy\" | \"timeout\" | \"aborted\" | \"stale\" | \"error\" };\nexport interface AcquisitionOptions {\n\treadonly maxRequests: number;\n\treadonly maxInFlight: number;\n\treadonly durationMs: number;\n\treadonly perRequestMs: number;\n\treadonly monotonicNow?: () => number;\n}\n/**\n * Owns every started promise until actual settlement, including noncooperative requests.\n * The scope is per host-approved run. It is not a billing or process-isolation boundary.\n */\nexport class AcquisitionPool {\n\tprivate readonly now: () => number;\n\tprivate readonly deadline: number;\n\tprivate readonly maxRequests: number;\n\tprivate readonly maxInFlight: number;\n\tprivate readonly perRequestMs: number;\n\tprivate nextId = 0;\n\tprivate epoch = 0;\n\tprivate requests = 0;\n\tprivate readonly active = new Map<number, { controller: AbortController; quarantined: boolean }>();\n\tconstructor(options: AcquisitionOptions) {\n\t\tinteger(options.maxRequests, \"maxRequests\", 100_000);\n\t\tinteger(options.maxInFlight, \"maxInFlight\", 64);\n\t\tinteger(options.durationMs, \"durationMs\", 86_400_000);\n\t\tinteger(options.perRequestMs, \"perRequestMs\", 86_400_000);\n\t\tthis.now = options.monotonicNow ?? (() => performance.now());\n\t\tconst start = this.now();\n\t\tensure(Number.isFinite(start) && start >= 0, \"invalid monotonic clock\");\n\t\tthis.deadline = start + options.durationMs;\n\t\tthis.maxRequests = options.maxRequests;\n\t\tthis.maxInFlight = options.maxInFlight;\n\t\tthis.perRequestMs = options.perRequestMs;\n\t}\n\tsnapshot(): { requests: number; active: number; quarantined: number; remainingMs: number; epoch: number } {\n\t\treturn {\n\t\t\trequests: this.requests,\n\t\t\tactive: this.active.size,\n\t\t\tquarantined: [...this.active.values()].filter((e) => e.quarantined).length,\n\t\t\tremainingMs: Math.max(0, Math.floor(this.deadline - this.now())),\n\t\t\tepoch: this.epoch,\n\t\t};\n\t}\n\t/** Invalidation requests cancellation but never resets outstanding ownership or budget. */\n\tinvalidate(): void {\n\t\tthis.epoch++;\n\t\tfor (const entry of this.active.values()) {\n\t\t\tentry.quarantined = true;\n\t\t\tentry.controller.abort();\n\t\t}\n\t}\n\tasync run<T>(operation: (signal: AbortSignal) => Promise<T>, parent?: AbortSignal): Promise<AcquisitionResult<T>> {\n\t\tif (parent?.aborted) return { status: \"aborted\" };\n\t\tconst remaining = this.deadline - this.now();\n\t\tif (this.requests >= this.maxRequests || remaining <= 0 || this.perRequestMs === 0) {\n\t\t\treturn { status: \"budget-exhausted\" };\n\t\t}\n\t\tif (this.active.size >= this.maxInFlight) return { status: \"busy\" };\n\t\tconst id = ++this.nextId,\n\t\t\tepoch = this.epoch,\n\t\t\tcontroller = new AbortController();\n\t\tconst entry = { controller, quarantined: false };\n\t\tthis.active.set(id, entry);\n\t\tthis.requests++;\n\t\tconst expires = this.now() + Math.min(remaining, this.perRequestMs);\n\t\tlet resolveStop!: (result: AcquisitionResult<T>) => void;\n\t\tconst stopped = new Promise<AcquisitionResult<T>>((resolve) => {\n\t\t\tresolveStop = resolve;\n\t\t});\n\t\tconst stop = (status: \"aborted\" | \"timeout\" | \"stale\"): void => {\n\t\t\tif (this.active.has(id)) entry.quarantined = true;\n\t\t\tresolveStop({ status });\n\t\t\tcontroller.abort();\n\t\t};\n\t\tconst onParent = (): void => stop(\"aborted\");\n\t\tconst onInternal = (): void => {\n\t\t\tif (epoch !== this.epoch) resolveStop({ status: \"stale\" });\n\t\t};\n\t\tparent?.addEventListener(\"abort\", onParent, { once: true });\n\t\tcontroller.signal.addEventListener(\"abort\", onInternal, { once: true });\n\t\tconst timer = setTimeout(() => stop(\"timeout\"), Math.max(1, Math.ceil(expires - this.now())));\n\t\t// Both fulfillment and rejection are owned. Late results are never promoted.\n\t\tconst task = Promise.resolve()\n\t\t\t.then(() => {\n\t\t\t\tif (controller.signal.aborted || parent?.aborted) throw new Error(\"cancelled-before-dispatch\");\n\t\t\t\treturn operation(controller.signal);\n\t\t\t})\n\t\t\t.then(\n\t\t\t\t(value): AcquisitionResult<T> => {\n\t\t\t\t\tif (epoch !== this.epoch) return { status: \"stale\" };\n\t\t\t\t\tif (parent?.aborted) return { status: \"aborted\" };\n\t\t\t\t\tif (controller.signal.aborted || this.now() >= expires) return { status: \"timeout\" };\n\t\t\t\t\treturn { status: \"ok\", value };\n\t\t\t\t},\n\t\t\t\t(): AcquisitionResult<T> => ({\n\t\t\t\t\tstatus:\n\t\t\t\t\t\tepoch !== this.epoch\n\t\t\t\t\t\t\t? \"stale\"\n\t\t\t\t\t\t\t: parent?.aborted\n\t\t\t\t\t\t\t\t? \"aborted\"\n\t\t\t\t\t\t\t\t: controller.signal.aborted\n\t\t\t\t\t\t\t\t\t? \"timeout\"\n\t\t\t\t\t\t\t\t\t: \"error\",\n\t\t\t\t}),\n\t\t\t)\n\t\t\t.finally(() => {\n\t\t\t\tthis.active.delete(id);\n\t\t\t});\n\t\ttry {\n\t\t\treturn await Promise.race([task, stopped]);\n\t\t} finally {\n\t\t\tclearTimeout(timer);\n\t\t\tparent?.removeEventListener(\"abort\", onParent);\n\t\t\tcontroller.signal.removeEventListener(\"abort\", onInternal);\n\t\t}\n\t}\n}\n"]}
|