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,62 @@
|
|
|
1
|
+
export interface ConditionKey {
|
|
2
|
+
readonly modelRevision: string;
|
|
3
|
+
readonly skillHashes: readonly string[];
|
|
4
|
+
readonly toolchain: string;
|
|
5
|
+
readonly taskBand: string;
|
|
6
|
+
readonly checkKind: string;
|
|
7
|
+
readonly checkHealth: "healthy" | "degraded" | "unverified";
|
|
8
|
+
readonly budgetBand: string;
|
|
9
|
+
readonly policyVersion: string;
|
|
10
|
+
}
|
|
11
|
+
export type BucketState = "insufficient-data" | "active" | "demoted";
|
|
12
|
+
export interface CalibrationBucket {
|
|
13
|
+
readonly key: ConditionKey;
|
|
14
|
+
readonly keyHash: string;
|
|
15
|
+
readonly priorAlpha: number;
|
|
16
|
+
readonly priorBeta: number;
|
|
17
|
+
successes: number;
|
|
18
|
+
failures: number;
|
|
19
|
+
drift: number;
|
|
20
|
+
state: BucketState;
|
|
21
|
+
readonly demotedReason?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface CalibrationStore {
|
|
24
|
+
readonly buckets: Readonly<Record<string, CalibrationBucket>>;
|
|
25
|
+
readonly minSamples: number;
|
|
26
|
+
readonly referenceMean: number;
|
|
27
|
+
readonly slack: number;
|
|
28
|
+
readonly threshold: number;
|
|
29
|
+
}
|
|
30
|
+
export declare function conditionKeyHash(key: ConditionKey): string;
|
|
31
|
+
export declare function createCalibrationStore(options: {
|
|
32
|
+
readonly minSamples: number;
|
|
33
|
+
readonly priorAlpha: number;
|
|
34
|
+
readonly priorBeta: number;
|
|
35
|
+
readonly referenceMean: number;
|
|
36
|
+
readonly slack: number;
|
|
37
|
+
readonly threshold: number;
|
|
38
|
+
}): CalibrationStore;
|
|
39
|
+
/**
|
|
40
|
+
* Record one independent task outcome. Never count 100 runs of one task as
|
|
41
|
+
* 100 independent tasks; the caller supplies one pre-registered binary outcome
|
|
42
|
+
* per task. Environment failures belong in delivery metrics, not here.
|
|
43
|
+
*/
|
|
44
|
+
export declare function recordOutcome(store: CalibrationStore, key: ConditionKey, outcome: "success" | "failure", loss: number): CalibrationStore;
|
|
45
|
+
/**
|
|
46
|
+
* Demote every bucket whose condition changed underneath it: new model
|
|
47
|
+
* revision, new check definition, or new major toolchain version. Explicit
|
|
48
|
+
* condition changes never wait for statistical drift detection.
|
|
49
|
+
*/
|
|
50
|
+
export declare function demoteOnConditionChange(store: CalibrationStore, change: {
|
|
51
|
+
modelRevision?: string;
|
|
52
|
+
checkKind?: string;
|
|
53
|
+
toolchain?: string;
|
|
54
|
+
policyVersion?: string;
|
|
55
|
+
}): CalibrationStore;
|
|
56
|
+
/** Posterior mean success rate for one bucket, or `insufficient-data`. */
|
|
57
|
+
export declare function conditionalSuccessRate(store: CalibrationStore, key: ConditionKey): {
|
|
58
|
+
state: BucketState;
|
|
59
|
+
rate?: number;
|
|
60
|
+
samples: number;
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=calibration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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AAM,CAAC;CAC3B;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAkB1D;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC/C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC3B,GAAG,gBAAgB,CAenB;AAkBD;;;;GAIG;AACH,wBAAgB,aAAa,CAC5B,KAAK,EAAE,gBAAgB,EACvB,GAAG,EAAE,YAAY,EACjB,OAAO,EAAE,SAAS,GAAG,SAAS,EAC9B,IAAI,EAAE,MAAM,GACV,gBAAgB,CAoBlB;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,gBAAgB,EACvB,MAAM,EAAE;IAAE,aAAa,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAChG,gBAAgB,CAclB;AAED,0EAA0E;AAC1E,wBAAgB,sBAAsB,CACrC,KAAK,EAAE,gBAAgB,EACvB,GAAG,EAAE,YAAY,GACf;IAAE,KAAK,EAAE,WAAW,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAUxD","sourcesContent":["/**\n * Algorithms E and G — conditional capability/calibration records and\n * drift-triggered demotion. Spec §8, §10.3.\n *\n * Records are per condition bucket: model revision + loaded skill content\n * fingerprints + toolchain version + task/effect/difficulty band + check\n * type/health + budget band + selection policy version. A bucket with too few\n * samples stays `insufficient-data`; a new provider revision, check\n * definition, or major library version demotes the bucket immediately,\n * without waiting for statistical detection.\n */\nimport { betaPosteriorMean, driftStatistic } from \"./decision.ts\";\nimport { canonical, ensure, finite, integer, lexical, member, text } from \"./validation.ts\";\n\nexport interface ConditionKey {\n\treadonly modelRevision: string;\n\treadonly skillHashes: readonly string[];\n\treadonly toolchain: string;\n\treadonly taskBand: string;\n\treadonly checkKind: string;\n\treadonly checkHealth: \"healthy\" | \"degraded\" | \"unverified\";\n\treadonly budgetBand: string;\n\treadonly policyVersion: string;\n}\nexport type BucketState = \"insufficient-data\" | \"active\" | \"demoted\";\nexport interface CalibrationBucket {\n\treadonly key: ConditionKey;\n\treadonly keyHash: string;\n\treadonly priorAlpha: number;\n\treadonly priorBeta: number;\n\tsuccesses: number;\n\tfailures: number;\n\tdrift: number;\n\tstate: BucketState;\n\treadonly demotedReason?: string;\n}\nexport interface CalibrationStore {\n\treadonly buckets: Readonly<Record<string, CalibrationBucket>>;\n\treadonly minSamples: number;\n\treadonly referenceMean: number;\n\treadonly slack: number;\n\treadonly threshold: number;\n}\n\nexport function conditionKeyHash(key: ConditionKey): string {\n\ttext(key.modelRevision, \"modelRevision\", 128);\n\ttext(key.toolchain, \"toolchain\", 128);\n\ttext(key.taskBand, \"taskBand\", 128);\n\ttext(key.checkKind, \"checkKind\", 128);\n\tmember(key.checkHealth, [\"healthy\", \"degraded\", \"unverified\"], \"checkHealth\");\n\ttext(key.budgetBand, \"budgetBand\", 128);\n\ttext(key.policyVersion, \"policyVersion\", 64);\n\treturn canonical([\n\t\tkey.modelRevision,\n\t\t[...key.skillHashes].sort(lexical),\n\t\tkey.toolchain,\n\t\tkey.taskBand,\n\t\tkey.checkKind,\n\t\tkey.checkHealth,\n\t\tkey.budgetBand,\n\t\tkey.policyVersion,\n\t]);\n}\n\nexport function createCalibrationStore(options: {\n\treadonly minSamples: number;\n\treadonly priorAlpha: number;\n\treadonly priorBeta: number;\n\treadonly referenceMean: number;\n\treadonly slack: number;\n\treadonly threshold: number;\n}): CalibrationStore {\n\tinteger(options.minSamples, \"minSamples\", 100_000);\n\tfinite(options.priorAlpha, \"priorAlpha\", 1e9);\n\tfinite(options.priorBeta, \"priorBeta\", 1e9);\n\tensure(options.priorAlpha > 0 && options.priorBeta > 0, \"beta prior must be positive\");\n\tfinite(options.referenceMean, \"referenceMean\");\n\tfinite(options.slack, \"slack\");\n\tfinite(options.threshold, \"threshold\");\n\treturn {\n\t\tbuckets: {},\n\t\tminSamples: options.minSamples,\n\t\treferenceMean: options.referenceMean,\n\t\tslack: options.slack,\n\t\tthreshold: options.threshold,\n\t};\n}\n\nfunction bucketFor(store: CalibrationStore, key: ConditionKey): CalibrationBucket {\n\tconst keyHash = conditionKeyHash(key);\n\treturn (\n\t\tstore.buckets[keyHash] ?? {\n\t\t\tkey,\n\t\t\tkeyHash,\n\t\t\tpriorAlpha: 1,\n\t\t\tpriorBeta: 1,\n\t\t\tsuccesses: 0,\n\t\t\tfailures: 0,\n\t\t\tdrift: 0,\n\t\t\tstate: \"insufficient-data\",\n\t\t}\n\t);\n}\n\n/**\n * Record one independent task outcome. Never count 100 runs of one task as\n * 100 independent tasks; the caller supplies one pre-registered binary outcome\n * per task. Environment failures belong in delivery metrics, not here.\n */\nexport function recordOutcome(\n\tstore: CalibrationStore,\n\tkey: ConditionKey,\n\toutcome: \"success\" | \"failure\",\n\tloss: number,\n): CalibrationStore {\n\tmember(outcome, [\"success\", \"failure\"], \"outcome\");\n\tfinite(loss, \"loss\");\n\tconst bucket = bucketFor(store, key);\n\tif (bucket.state === \"demoted\") return store;\n\tconst next: CalibrationBucket = {\n\t\t...bucket,\n\t\tsuccesses: bucket.successes + (outcome === \"success\" ? 1 : 0),\n\t\tfailures: bucket.failures + (outcome === \"failure\" ? 1 : 0),\n\t\tdrift: driftStatistic(bucket.drift, loss, store.referenceMean, store.slack),\n\t\tstate: bucket.successes + bucket.failures + 1 >= store.minSamples ? \"active\" : \"insufficient-data\",\n\t};\n\tconst demoted = next.drift > store.threshold;\n\treturn {\n\t\t...store,\n\t\tbuckets: {\n\t\t\t...store.buckets,\n\t\t\t[next.keyHash]: demoted ? { ...next, state: \"demoted\", demotedReason: \"drift-threshold\" } : next,\n\t\t},\n\t};\n}\n\n/**\n * Demote every bucket whose condition changed underneath it: new model\n * revision, new check definition, or new major toolchain version. Explicit\n * condition changes never wait for statistical drift detection.\n */\nexport function demoteOnConditionChange(\n\tstore: CalibrationStore,\n\tchange: { modelRevision?: string; checkKind?: string; toolchain?: string; policyVersion?: string },\n): CalibrationStore {\n\tconst buckets: Record<string, CalibrationBucket> = {};\n\tfor (const [hash, bucket] of Object.entries(store.buckets)) {\n\t\tconst changed =\n\t\t\t(change.modelRevision !== undefined && bucket.key.modelRevision !== change.modelRevision) ||\n\t\t\t(change.checkKind !== undefined && bucket.key.checkKind !== change.checkKind) ||\n\t\t\t(change.toolchain !== undefined && bucket.key.toolchain !== change.toolchain) ||\n\t\t\t(change.policyVersion !== undefined && bucket.key.policyVersion !== change.policyVersion);\n\t\tbuckets[hash] =\n\t\t\tchanged && bucket.state !== \"demoted\"\n\t\t\t\t? { ...bucket, state: \"demoted\", demotedReason: \"condition-change\" }\n\t\t\t\t: bucket;\n\t}\n\treturn { ...store, buckets };\n}\n\n/** Posterior mean success rate for one bucket, or `insufficient-data`. */\nexport function conditionalSuccessRate(\n\tstore: CalibrationStore,\n\tkey: ConditionKey,\n): { state: BucketState; rate?: number; samples: number } {\n\tconst bucket = store.buckets[conditionKeyHash(key)];\n\tif (!bucket) return { state: \"insufficient-data\", samples: 0 };\n\tconst samples = bucket.successes + bucket.failures;\n\tif (bucket.state !== \"active\") return { state: bucket.state, samples };\n\treturn {\n\t\tstate: \"active\",\n\t\tsamples,\n\t\trate: betaPosteriorMean(bucket.priorAlpha, bucket.priorBeta, bucket.successes, bucket.failures),\n\t};\n}\n"]}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Algorithms E and G — conditional capability/calibration records and
|
|
3
|
+
* drift-triggered demotion. Spec §8, §10.3.
|
|
4
|
+
*
|
|
5
|
+
* Records are per condition bucket: model revision + loaded skill content
|
|
6
|
+
* fingerprints + toolchain version + task/effect/difficulty band + check
|
|
7
|
+
* type/health + budget band + selection policy version. A bucket with too few
|
|
8
|
+
* samples stays `insufficient-data`; a new provider revision, check
|
|
9
|
+
* definition, or major library version demotes the bucket immediately,
|
|
10
|
+
* without waiting for statistical detection.
|
|
11
|
+
*/
|
|
12
|
+
import { betaPosteriorMean, driftStatistic } from "./decision.js";
|
|
13
|
+
import { canonical, ensure, finite, integer, lexical, member, text } from "./validation.js";
|
|
14
|
+
export function conditionKeyHash(key) {
|
|
15
|
+
text(key.modelRevision, "modelRevision", 128);
|
|
16
|
+
text(key.toolchain, "toolchain", 128);
|
|
17
|
+
text(key.taskBand, "taskBand", 128);
|
|
18
|
+
text(key.checkKind, "checkKind", 128);
|
|
19
|
+
member(key.checkHealth, ["healthy", "degraded", "unverified"], "checkHealth");
|
|
20
|
+
text(key.budgetBand, "budgetBand", 128);
|
|
21
|
+
text(key.policyVersion, "policyVersion", 64);
|
|
22
|
+
return canonical([
|
|
23
|
+
key.modelRevision,
|
|
24
|
+
[...key.skillHashes].sort(lexical),
|
|
25
|
+
key.toolchain,
|
|
26
|
+
key.taskBand,
|
|
27
|
+
key.checkKind,
|
|
28
|
+
key.checkHealth,
|
|
29
|
+
key.budgetBand,
|
|
30
|
+
key.policyVersion,
|
|
31
|
+
]);
|
|
32
|
+
}
|
|
33
|
+
export function createCalibrationStore(options) {
|
|
34
|
+
integer(options.minSamples, "minSamples", 100_000);
|
|
35
|
+
finite(options.priorAlpha, "priorAlpha", 1e9);
|
|
36
|
+
finite(options.priorBeta, "priorBeta", 1e9);
|
|
37
|
+
ensure(options.priorAlpha > 0 && options.priorBeta > 0, "beta prior must be positive");
|
|
38
|
+
finite(options.referenceMean, "referenceMean");
|
|
39
|
+
finite(options.slack, "slack");
|
|
40
|
+
finite(options.threshold, "threshold");
|
|
41
|
+
return {
|
|
42
|
+
buckets: {},
|
|
43
|
+
minSamples: options.minSamples,
|
|
44
|
+
referenceMean: options.referenceMean,
|
|
45
|
+
slack: options.slack,
|
|
46
|
+
threshold: options.threshold,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function bucketFor(store, key) {
|
|
50
|
+
const keyHash = conditionKeyHash(key);
|
|
51
|
+
return (store.buckets[keyHash] ?? {
|
|
52
|
+
key,
|
|
53
|
+
keyHash,
|
|
54
|
+
priorAlpha: 1,
|
|
55
|
+
priorBeta: 1,
|
|
56
|
+
successes: 0,
|
|
57
|
+
failures: 0,
|
|
58
|
+
drift: 0,
|
|
59
|
+
state: "insufficient-data",
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Record one independent task outcome. Never count 100 runs of one task as
|
|
64
|
+
* 100 independent tasks; the caller supplies one pre-registered binary outcome
|
|
65
|
+
* per task. Environment failures belong in delivery metrics, not here.
|
|
66
|
+
*/
|
|
67
|
+
export function recordOutcome(store, key, outcome, loss) {
|
|
68
|
+
member(outcome, ["success", "failure"], "outcome");
|
|
69
|
+
finite(loss, "loss");
|
|
70
|
+
const bucket = bucketFor(store, key);
|
|
71
|
+
if (bucket.state === "demoted")
|
|
72
|
+
return store;
|
|
73
|
+
const next = {
|
|
74
|
+
...bucket,
|
|
75
|
+
successes: bucket.successes + (outcome === "success" ? 1 : 0),
|
|
76
|
+
failures: bucket.failures + (outcome === "failure" ? 1 : 0),
|
|
77
|
+
drift: driftStatistic(bucket.drift, loss, store.referenceMean, store.slack),
|
|
78
|
+
state: bucket.successes + bucket.failures + 1 >= store.minSamples ? "active" : "insufficient-data",
|
|
79
|
+
};
|
|
80
|
+
const demoted = next.drift > store.threshold;
|
|
81
|
+
return {
|
|
82
|
+
...store,
|
|
83
|
+
buckets: {
|
|
84
|
+
...store.buckets,
|
|
85
|
+
[next.keyHash]: demoted ? { ...next, state: "demoted", demotedReason: "drift-threshold" } : next,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Demote every bucket whose condition changed underneath it: new model
|
|
91
|
+
* revision, new check definition, or new major toolchain version. Explicit
|
|
92
|
+
* condition changes never wait for statistical drift detection.
|
|
93
|
+
*/
|
|
94
|
+
export function demoteOnConditionChange(store, change) {
|
|
95
|
+
const buckets = {};
|
|
96
|
+
for (const [hash, bucket] of Object.entries(store.buckets)) {
|
|
97
|
+
const changed = (change.modelRevision !== undefined && bucket.key.modelRevision !== change.modelRevision) ||
|
|
98
|
+
(change.checkKind !== undefined && bucket.key.checkKind !== change.checkKind) ||
|
|
99
|
+
(change.toolchain !== undefined && bucket.key.toolchain !== change.toolchain) ||
|
|
100
|
+
(change.policyVersion !== undefined && bucket.key.policyVersion !== change.policyVersion);
|
|
101
|
+
buckets[hash] =
|
|
102
|
+
changed && bucket.state !== "demoted"
|
|
103
|
+
? { ...bucket, state: "demoted", demotedReason: "condition-change" }
|
|
104
|
+
: bucket;
|
|
105
|
+
}
|
|
106
|
+
return { ...store, buckets };
|
|
107
|
+
}
|
|
108
|
+
/** Posterior mean success rate for one bucket, or `insufficient-data`. */
|
|
109
|
+
export function conditionalSuccessRate(store, key) {
|
|
110
|
+
const bucket = store.buckets[conditionKeyHash(key)];
|
|
111
|
+
if (!bucket)
|
|
112
|
+
return { state: "insufficient-data", samples: 0 };
|
|
113
|
+
const samples = bucket.successes + bucket.failures;
|
|
114
|
+
if (bucket.state !== "active")
|
|
115
|
+
return { state: bucket.state, samples };
|
|
116
|
+
return {
|
|
117
|
+
state: "active",
|
|
118
|
+
samples,
|
|
119
|
+
rate: betaPosteriorMean(bucket.priorAlpha, bucket.priorBeta, bucket.successes, bucket.failures),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=calibration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calibration.js","sourceRoot":"","sources":["../../src/metacognition/calibration.ts"],"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KAAK,EAAE,QAAQ;QACf,OAAO;QACP,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,QAAQ,CAAC;KAC/F,CAAC;AAAA,CACF","sourcesContent":["/**\n * Algorithms E and G — conditional capability/calibration records and\n * drift-triggered demotion. Spec §8, §10.3.\n *\n * Records are per condition bucket: model revision + loaded skill content\n * fingerprints + toolchain version + task/effect/difficulty band + check\n * type/health + budget band + selection policy version. A bucket with too few\n * samples stays `insufficient-data`; a new provider revision, check\n * definition, or major library version demotes the bucket immediately,\n * without waiting for statistical detection.\n */\nimport { betaPosteriorMean, driftStatistic } from \"./decision.ts\";\nimport { canonical, ensure, finite, integer, lexical, member, text } from \"./validation.ts\";\n\nexport interface ConditionKey {\n\treadonly modelRevision: string;\n\treadonly skillHashes: readonly string[];\n\treadonly toolchain: string;\n\treadonly taskBand: string;\n\treadonly checkKind: string;\n\treadonly checkHealth: \"healthy\" | \"degraded\" | \"unverified\";\n\treadonly budgetBand: string;\n\treadonly policyVersion: string;\n}\nexport type BucketState = \"insufficient-data\" | \"active\" | \"demoted\";\nexport interface CalibrationBucket {\n\treadonly key: ConditionKey;\n\treadonly keyHash: string;\n\treadonly priorAlpha: number;\n\treadonly priorBeta: number;\n\tsuccesses: number;\n\tfailures: number;\n\tdrift: number;\n\tstate: BucketState;\n\treadonly demotedReason?: string;\n}\nexport interface CalibrationStore {\n\treadonly buckets: Readonly<Record<string, CalibrationBucket>>;\n\treadonly minSamples: number;\n\treadonly referenceMean: number;\n\treadonly slack: number;\n\treadonly threshold: number;\n}\n\nexport function conditionKeyHash(key: ConditionKey): string {\n\ttext(key.modelRevision, \"modelRevision\", 128);\n\ttext(key.toolchain, \"toolchain\", 128);\n\ttext(key.taskBand, \"taskBand\", 128);\n\ttext(key.checkKind, \"checkKind\", 128);\n\tmember(key.checkHealth, [\"healthy\", \"degraded\", \"unverified\"], \"checkHealth\");\n\ttext(key.budgetBand, \"budgetBand\", 128);\n\ttext(key.policyVersion, \"policyVersion\", 64);\n\treturn canonical([\n\t\tkey.modelRevision,\n\t\t[...key.skillHashes].sort(lexical),\n\t\tkey.toolchain,\n\t\tkey.taskBand,\n\t\tkey.checkKind,\n\t\tkey.checkHealth,\n\t\tkey.budgetBand,\n\t\tkey.policyVersion,\n\t]);\n}\n\nexport function createCalibrationStore(options: {\n\treadonly minSamples: number;\n\treadonly priorAlpha: number;\n\treadonly priorBeta: number;\n\treadonly referenceMean: number;\n\treadonly slack: number;\n\treadonly threshold: number;\n}): CalibrationStore {\n\tinteger(options.minSamples, \"minSamples\", 100_000);\n\tfinite(options.priorAlpha, \"priorAlpha\", 1e9);\n\tfinite(options.priorBeta, \"priorBeta\", 1e9);\n\tensure(options.priorAlpha > 0 && options.priorBeta > 0, \"beta prior must be positive\");\n\tfinite(options.referenceMean, \"referenceMean\");\n\tfinite(options.slack, \"slack\");\n\tfinite(options.threshold, \"threshold\");\n\treturn {\n\t\tbuckets: {},\n\t\tminSamples: options.minSamples,\n\t\treferenceMean: options.referenceMean,\n\t\tslack: options.slack,\n\t\tthreshold: options.threshold,\n\t};\n}\n\nfunction bucketFor(store: CalibrationStore, key: ConditionKey): CalibrationBucket {\n\tconst keyHash = conditionKeyHash(key);\n\treturn (\n\t\tstore.buckets[keyHash] ?? {\n\t\t\tkey,\n\t\t\tkeyHash,\n\t\t\tpriorAlpha: 1,\n\t\t\tpriorBeta: 1,\n\t\t\tsuccesses: 0,\n\t\t\tfailures: 0,\n\t\t\tdrift: 0,\n\t\t\tstate: \"insufficient-data\",\n\t\t}\n\t);\n}\n\n/**\n * Record one independent task outcome. Never count 100 runs of one task as\n * 100 independent tasks; the caller supplies one pre-registered binary outcome\n * per task. Environment failures belong in delivery metrics, not here.\n */\nexport function recordOutcome(\n\tstore: CalibrationStore,\n\tkey: ConditionKey,\n\toutcome: \"success\" | \"failure\",\n\tloss: number,\n): CalibrationStore {\n\tmember(outcome, [\"success\", \"failure\"], \"outcome\");\n\tfinite(loss, \"loss\");\n\tconst bucket = bucketFor(store, key);\n\tif (bucket.state === \"demoted\") return store;\n\tconst next: CalibrationBucket = {\n\t\t...bucket,\n\t\tsuccesses: bucket.successes + (outcome === \"success\" ? 1 : 0),\n\t\tfailures: bucket.failures + (outcome === \"failure\" ? 1 : 0),\n\t\tdrift: driftStatistic(bucket.drift, loss, store.referenceMean, store.slack),\n\t\tstate: bucket.successes + bucket.failures + 1 >= store.minSamples ? \"active\" : \"insufficient-data\",\n\t};\n\tconst demoted = next.drift > store.threshold;\n\treturn {\n\t\t...store,\n\t\tbuckets: {\n\t\t\t...store.buckets,\n\t\t\t[next.keyHash]: demoted ? { ...next, state: \"demoted\", demotedReason: \"drift-threshold\" } : next,\n\t\t},\n\t};\n}\n\n/**\n * Demote every bucket whose condition changed underneath it: new model\n * revision, new check definition, or new major toolchain version. Explicit\n * condition changes never wait for statistical drift detection.\n */\nexport function demoteOnConditionChange(\n\tstore: CalibrationStore,\n\tchange: { modelRevision?: string; checkKind?: string; toolchain?: string; policyVersion?: string },\n): CalibrationStore {\n\tconst buckets: Record<string, CalibrationBucket> = {};\n\tfor (const [hash, bucket] of Object.entries(store.buckets)) {\n\t\tconst changed =\n\t\t\t(change.modelRevision !== undefined && bucket.key.modelRevision !== change.modelRevision) ||\n\t\t\t(change.checkKind !== undefined && bucket.key.checkKind !== change.checkKind) ||\n\t\t\t(change.toolchain !== undefined && bucket.key.toolchain !== change.toolchain) ||\n\t\t\t(change.policyVersion !== undefined && bucket.key.policyVersion !== change.policyVersion);\n\t\tbuckets[hash] =\n\t\t\tchanged && bucket.state !== \"demoted\"\n\t\t\t\t? { ...bucket, state: \"demoted\", demotedReason: \"condition-change\" }\n\t\t\t\t: bucket;\n\t}\n\treturn { ...store, buckets };\n}\n\n/** Posterior mean success rate for one bucket, or `insufficient-data`. */\nexport function conditionalSuccessRate(\n\tstore: CalibrationStore,\n\tkey: ConditionKey,\n): { state: BucketState; rate?: number; samples: number } {\n\tconst bucket = store.buckets[conditionKeyHash(key)];\n\tif (!bucket) return { state: \"insufficient-data\", samples: 0 };\n\tconst samples = bucket.successes + bucket.failures;\n\tif (bucket.state !== \"active\") return { state: bucket.state, samples };\n\treturn {\n\t\tstate: \"active\",\n\t\tsamples,\n\t\trate: betaPosteriorMean(bucket.priorAlpha, bucket.priorBeta, bucket.successes, bucket.failures),\n\t};\n}\n"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* §9.4 checkpoint ordering: refresh obligations from host observations,
|
|
3
|
+
* evaluate knowledge gaps, classify prediction mismatches, evaluate verifier
|
|
4
|
+
* blind spots and runner health, then select one bounded action.
|
|
5
|
+
*
|
|
6
|
+
* The host calls this at a safe decision boundary — never mid-stream, and
|
|
7
|
+
* never as a path for model reasoning to remove a `required` obligation.
|
|
8
|
+
*/
|
|
9
|
+
import type { ChangeAtom, ObligationRule } from "./obligations.ts";
|
|
10
|
+
import { type ActionConstraints, type MetaAction, type MetaActionKind } from "./policy.ts";
|
|
11
|
+
import type { MetaState } from "./state.ts";
|
|
12
|
+
import { type FinishState } from "./state.ts";
|
|
13
|
+
import { type MutantRecord, type VerifierEvaluation } from "./verifier.ts";
|
|
14
|
+
export interface CheckpointInput {
|
|
15
|
+
readonly state: MetaState;
|
|
16
|
+
readonly atoms?: readonly ChangeAtom[];
|
|
17
|
+
readonly rules?: readonly ObligationRule[];
|
|
18
|
+
readonly nowMs: number;
|
|
19
|
+
readonly constraints: ActionConstraints;
|
|
20
|
+
readonly mutants?: readonly MutantRecord[];
|
|
21
|
+
readonly receipt?: {
|
|
22
|
+
receiptId: string;
|
|
23
|
+
candidateHash: string;
|
|
24
|
+
scope: string;
|
|
25
|
+
} | null;
|
|
26
|
+
readonly options?: {
|
|
27
|
+
readonly maxRepetitions?: number;
|
|
28
|
+
readonly switchCost?: number;
|
|
29
|
+
readonly estimatedSwitchGain?: number;
|
|
30
|
+
readonly voiCandidates?: readonly {
|
|
31
|
+
kind: MetaActionKind;
|
|
32
|
+
voi: number;
|
|
33
|
+
}[];
|
|
34
|
+
readonly progress?: {
|
|
35
|
+
readonly goalScope: string;
|
|
36
|
+
readonly candidateFamily: string;
|
|
37
|
+
readonly errorClass: string;
|
|
38
|
+
readonly approach: string;
|
|
39
|
+
readonly checkMethod: string;
|
|
40
|
+
readonly sourceFamily: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface CheckpointResult {
|
|
45
|
+
readonly state: MetaState;
|
|
46
|
+
readonly action: MetaAction;
|
|
47
|
+
readonly finish: FinishState;
|
|
48
|
+
readonly newObligations: number;
|
|
49
|
+
readonly newPredictions: number;
|
|
50
|
+
readonly mismatches: number;
|
|
51
|
+
readonly verifierEvaluations: readonly VerifierEvaluation[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* One checkpoint evaluation. Refreshes obligations from observed atoms when
|
|
55
|
+
* provided, resolves registered predictions against fresh observations when
|
|
56
|
+
* provided, evaluates verifier mutants when provided, then selects the next
|
|
57
|
+
* action under the §14 priority table.
|
|
58
|
+
*/
|
|
59
|
+
export declare function checkpoint(input: CheckpointInput): CheckpointResult;
|
|
60
|
+
//# sourceMappingURL=checkpoint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint.d.ts","sourceRoot":"","sources":["../../src/metacognition/checkpoint.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEnE,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,UAAU,EAAE,KAAK,cAAc,EAAgB,MAAM,aAAa,CAAC;AACzG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,KAAK,WAAW,EAAkC,MAAM,YAAY,CAAC;AAE9E,OAAO,EAAoB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QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,mBAAmB,EAAE,SAAS,kBAAkB,EAAE,CAAC;CAC5D;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB,CA4CnE","sourcesContent":["/**\n * §9.4 checkpoint ordering: refresh obligations from host observations,\n * evaluate knowledge gaps, classify prediction mismatches, evaluate verifier\n * blind spots and runner health, then select one bounded action.\n *\n * The host calls this at a safe decision boundary — never mid-stream, and\n * never as a path for model reasoning to remove a `required` obligation.\n */\nimport type { ChangeAtom, ObligationRule } from \"./obligations.ts\";\nimport { instantiateObligations } from \"./obligations.ts\";\nimport { type ActionConstraints, type MetaAction, type MetaActionKind, selectAction } from \"./policy.ts\";\nimport type { MetaState } from \"./state.ts\";\nimport { type FinishState, finishState, validateMetaState } from \"./state.ts\";\nimport { integer } from \"./validation.ts\";\nimport { evaluateVerifier, type MutantRecord, type VerifierEvaluation } from \"./verifier.ts\";\n\nexport interface CheckpointInput {\n\treadonly state: MetaState;\n\treadonly atoms?: readonly ChangeAtom[];\n\treadonly rules?: readonly ObligationRule[];\n\treadonly nowMs: number;\n\treadonly constraints: ActionConstraints;\n\treadonly mutants?: readonly MutantRecord[];\n\treadonly receipt?: { receiptId: string; candidateHash: string; scope: string } | null;\n\treadonly options?: {\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\treadonly goalScope: string;\n\t\t\treadonly candidateFamily: string;\n\t\t\treadonly errorClass: string;\n\t\t\treadonly approach: string;\n\t\t\treadonly checkMethod: string;\n\t\t\treadonly sourceFamily: string;\n\t\t};\n\t};\n}\nexport interface CheckpointResult {\n\treadonly state: MetaState;\n\treadonly action: MetaAction;\n\treadonly finish: FinishState;\n\treadonly newObligations: number;\n\treadonly newPredictions: number;\n\treadonly mismatches: number;\n\treadonly verifierEvaluations: readonly VerifierEvaluation[];\n}\n\n/**\n * One checkpoint evaluation. Refreshes obligations from observed atoms when\n * provided, resolves registered predictions against fresh observations when\n * provided, evaluates verifier mutants when provided, then selects the next\n * action under the §14 priority table.\n */\nexport function checkpoint(input: CheckpointInput): CheckpointResult {\n\tinteger(input.nowMs, \"nowMs\");\n\tvalidateMetaState(input.state);\n\tlet state = input.state;\n\tlet newObligations = 0;\n\tif (input.atoms && input.rules) {\n\t\tconst report = instantiateObligations(input.atoms, input.rules, input.nowMs);\n\t\tconst merged = [...state.obligations, ...report.required, ...report.candidates];\n\t\tnewObligations = report.required.length + report.candidates.length;\n\t\tstate = { ...state, obligations: merged };\n\t}\n\tlet mismatches = 0;\n\tfor (const p of state.predictions) {\n\t\tif (p.status === \"resolved\" && p.mismatch !== undefined && p.mismatch !== \"none\") mismatches += 1;\n\t}\n\tconst verifierEvaluations: VerifierEvaluation[] = [...state.verifier.evaluations];\n\tif (input.mutants) {\n\t\tfor (const obligation of state.obligations) {\n\t\t\tconst scoped = input.mutants.filter((m) => m.obligationId === obligation.id);\n\t\t\tif (scoped.length === 0) continue;\n\t\t\tverifierEvaluations.push(\n\t\t\t\tevaluateVerifier(obligation.id, input.mutants, state.verifier.runnerHealth === \"healthy\"),\n\t\t\t);\n\t\t}\n\t\tstate = { ...state, verifier: { ...state.verifier, evaluations: verifierEvaluations } };\n\t}\n\tconst action = selectAction(state, input.constraints, {\n\t\treceipt: input.receipt ?? null,\n\t\tmaxRepetitions: input.options?.maxRepetitions,\n\t\tswitchCost: input.options?.switchCost,\n\t\testimatedSwitchGain: input.options?.estimatedSwitchGain,\n\t\tvoiCandidates: input.options?.voiCandidates,\n\t\tprogress: input.options?.progress,\n\t});\n\tconst finish = finishState(state, input.receipt ?? null);\n\treturn {\n\t\tstate: { ...state, checkpointCount: state.checkpointCount + 1 },\n\t\taction,\n\t\tfinish,\n\t\tnewObligations,\n\t\tnewPredictions: 0,\n\t\tmismatches,\n\t\tverifierEvaluations,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { instantiateObligations } from "./obligations.js";
|
|
2
|
+
import { selectAction } from "./policy.js";
|
|
3
|
+
import { finishState, validateMetaState } from "./state.js";
|
|
4
|
+
import { integer } from "./validation.js";
|
|
5
|
+
import { evaluateVerifier } from "./verifier.js";
|
|
6
|
+
/**
|
|
7
|
+
* One checkpoint evaluation. Refreshes obligations from observed atoms when
|
|
8
|
+
* provided, resolves registered predictions against fresh observations when
|
|
9
|
+
* provided, evaluates verifier mutants when provided, then selects the next
|
|
10
|
+
* action under the §14 priority table.
|
|
11
|
+
*/
|
|
12
|
+
export function checkpoint(input) {
|
|
13
|
+
integer(input.nowMs, "nowMs");
|
|
14
|
+
validateMetaState(input.state);
|
|
15
|
+
let state = input.state;
|
|
16
|
+
let newObligations = 0;
|
|
17
|
+
if (input.atoms && input.rules) {
|
|
18
|
+
const report = instantiateObligations(input.atoms, input.rules, input.nowMs);
|
|
19
|
+
const merged = [...state.obligations, ...report.required, ...report.candidates];
|
|
20
|
+
newObligations = report.required.length + report.candidates.length;
|
|
21
|
+
state = { ...state, obligations: merged };
|
|
22
|
+
}
|
|
23
|
+
let mismatches = 0;
|
|
24
|
+
for (const p of state.predictions) {
|
|
25
|
+
if (p.status === "resolved" && p.mismatch !== undefined && p.mismatch !== "none")
|
|
26
|
+
mismatches += 1;
|
|
27
|
+
}
|
|
28
|
+
const verifierEvaluations = [...state.verifier.evaluations];
|
|
29
|
+
if (input.mutants) {
|
|
30
|
+
for (const obligation of state.obligations) {
|
|
31
|
+
const scoped = input.mutants.filter((m) => m.obligationId === obligation.id);
|
|
32
|
+
if (scoped.length === 0)
|
|
33
|
+
continue;
|
|
34
|
+
verifierEvaluations.push(evaluateVerifier(obligation.id, input.mutants, state.verifier.runnerHealth === "healthy"));
|
|
35
|
+
}
|
|
36
|
+
state = { ...state, verifier: { ...state.verifier, evaluations: verifierEvaluations } };
|
|
37
|
+
}
|
|
38
|
+
const action = selectAction(state, input.constraints, {
|
|
39
|
+
receipt: input.receipt ?? null,
|
|
40
|
+
maxRepetitions: input.options?.maxRepetitions,
|
|
41
|
+
switchCost: input.options?.switchCost,
|
|
42
|
+
estimatedSwitchGain: input.options?.estimatedSwitchGain,
|
|
43
|
+
voiCandidates: input.options?.voiCandidates,
|
|
44
|
+
progress: input.options?.progress,
|
|
45
|
+
});
|
|
46
|
+
const finish = finishState(state, input.receipt ?? null);
|
|
47
|
+
return {
|
|
48
|
+
state: { ...state, checkpointCount: state.checkpointCount + 1 },
|
|
49
|
+
action,
|
|
50
|
+
finish,
|
|
51
|
+
newObligations,
|
|
52
|
+
newPredictions: 0,
|
|
53
|
+
mismatches,
|
|
54
|
+
verifierEvaluations,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=checkpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpoint.js","sourceRoot":"","sources":["../../src/metacognition/checkpoint.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAgE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEzG,OAAO,EAAoB,WAAW,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAA8C,MAAM,eAAe,CAAC;AAmC7F;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,KAAsB,EAAoB;IACpE,O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UAAU,CAAC,EAAE,CAAC,CAAC;YAC7E,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;gBAAE,SAAS;YAClC,mBAAmB,CAAC,IAAI,CACvB,gBAAgB,CAAC,UAAU,CAAC,EAAE,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,YAAY,KAAK,SAAS,CAAC,CACzF,CAAC;QACH,CAAC;QACD,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAE,WAAW,EAAE,mBAAmB,EAAE,EAAE,CAAC;IACzF,CAAC;IACD,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE;QACrD,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,IAAI;QAC9B,cAAc,EAAE,KAAK,CAAC,OAAO,EAAE,cAAc;QAC7C,UAAU,EAAE,KAAK,CAAC,OAAO,EAAE,UAAU;QACrC,mBAAmB,EAAE,KAAK,CAAC,OAAO,EAAE,mBAAmB;QACvD,aAAa,EAAE,KAAK,CAAC,OAAO,EAAE,aAAa;QAC3C,QAAQ,EAAE,KAAK,CAAC,OAAO,EAAE,QAAQ;KACjC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC;IACzD,OAAO;QACN,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,eAAe,EAAE,KAAK,CAAC,eAAe,GAAG,CAAC,EAAE;QAC/D,MAAM;QACN,MAAM;QACN,cAAc;QACd,cAAc,EAAE,CAAC;QACjB,UAAU;QACV,mBAAmB;KACnB,CAAC;AAAA,CACF","sourcesContent":["/**\n * §9.4 checkpoint ordering: refresh obligations from host observations,\n * evaluate knowledge gaps, classify prediction mismatches, evaluate verifier\n * blind spots and runner health, then select one bounded action.\n *\n * The host calls this at a safe decision boundary — never mid-stream, and\n * never as a path for model reasoning to remove a `required` obligation.\n */\nimport type { ChangeAtom, ObligationRule } from \"./obligations.ts\";\nimport { instantiateObligations } from \"./obligations.ts\";\nimport { type ActionConstraints, type MetaAction, type MetaActionKind, selectAction } from \"./policy.ts\";\nimport type { MetaState } from \"./state.ts\";\nimport { type FinishState, finishState, validateMetaState } from \"./state.ts\";\nimport { integer } from \"./validation.ts\";\nimport { evaluateVerifier, type MutantRecord, type VerifierEvaluation } from \"./verifier.ts\";\n\nexport interface CheckpointInput {\n\treadonly state: MetaState;\n\treadonly atoms?: readonly ChangeAtom[];\n\treadonly rules?: readonly ObligationRule[];\n\treadonly nowMs: number;\n\treadonly constraints: ActionConstraints;\n\treadonly mutants?: readonly MutantRecord[];\n\treadonly receipt?: { receiptId: string; candidateHash: string; scope: string } | null;\n\treadonly options?: {\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\treadonly goalScope: string;\n\t\t\treadonly candidateFamily: string;\n\t\t\treadonly errorClass: string;\n\t\t\treadonly approach: string;\n\t\t\treadonly checkMethod: string;\n\t\t\treadonly sourceFamily: string;\n\t\t};\n\t};\n}\nexport interface CheckpointResult {\n\treadonly state: MetaState;\n\treadonly action: MetaAction;\n\treadonly finish: FinishState;\n\treadonly newObligations: number;\n\treadonly newPredictions: number;\n\treadonly mismatches: number;\n\treadonly verifierEvaluations: readonly VerifierEvaluation[];\n}\n\n/**\n * One checkpoint evaluation. Refreshes obligations from observed atoms when\n * provided, resolves registered predictions against fresh observations when\n * provided, evaluates verifier mutants when provided, then selects the next\n * action under the §14 priority table.\n */\nexport function checkpoint(input: CheckpointInput): CheckpointResult {\n\tinteger(input.nowMs, \"nowMs\");\n\tvalidateMetaState(input.state);\n\tlet state = input.state;\n\tlet newObligations = 0;\n\tif (input.atoms && input.rules) {\n\t\tconst report = instantiateObligations(input.atoms, input.rules, input.nowMs);\n\t\tconst merged = [...state.obligations, ...report.required, ...report.candidates];\n\t\tnewObligations = report.required.length + report.candidates.length;\n\t\tstate = { ...state, obligations: merged };\n\t}\n\tlet mismatches = 0;\n\tfor (const p of state.predictions) {\n\t\tif (p.status === \"resolved\" && p.mismatch !== undefined && p.mismatch !== \"none\") mismatches += 1;\n\t}\n\tconst verifierEvaluations: VerifierEvaluation[] = [...state.verifier.evaluations];\n\tif (input.mutants) {\n\t\tfor (const obligation of state.obligations) {\n\t\t\tconst scoped = input.mutants.filter((m) => m.obligationId === obligation.id);\n\t\t\tif (scoped.length === 0) continue;\n\t\t\tverifierEvaluations.push(\n\t\t\t\tevaluateVerifier(obligation.id, input.mutants, state.verifier.runnerHealth === \"healthy\"),\n\t\t\t);\n\t\t}\n\t\tstate = { ...state, verifier: { ...state.verifier, evaluations: verifierEvaluations } };\n\t}\n\tconst action = selectAction(state, input.constraints, {\n\t\treceipt: input.receipt ?? null,\n\t\tmaxRepetitions: input.options?.maxRepetitions,\n\t\tswitchCost: input.options?.switchCost,\n\t\testimatedSwitchGain: input.options?.estimatedSwitchGain,\n\t\tvoiCandidates: input.options?.voiCandidates,\n\t\tprogress: input.options?.progress,\n\t});\n\tconst finish = finishState(state, input.receipt ?? null);\n\treturn {\n\t\tstate: { ...state, checkpointCount: state.checkpointCount + 1 },\n\t\taction,\n\t\tfinish,\n\t\tnewObligations,\n\t\tnewPredictions: 0,\n\t\tmismatches,\n\t\tverifierEvaluations,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fixed-origin Context7 GET adapter with explicit egress approval.
|
|
3
|
+
*
|
|
4
|
+
* Ported from docs/OMK_skill_knowledge_control_2026-09-19.zip
|
|
5
|
+
* (src/context7.ts). Every attempted HTTP request consumes a shared
|
|
6
|
+
* AcquisitionPool permit; there is no retry, redirect-following, or
|
|
7
|
+
* auto-selection of the first result. Returned `rules` fields are data, never
|
|
8
|
+
* promoted to instructions.
|
|
9
|
+
*/
|
|
10
|
+
import type { AcquisitionPool, AcquisitionResult } from "./retrieval.ts";
|
|
11
|
+
export interface Context7Options {
|
|
12
|
+
readonly apiKey: string;
|
|
13
|
+
readonly enabled: boolean;
|
|
14
|
+
readonly approvedLibraryNames: readonly string[];
|
|
15
|
+
readonly approvedLibraryIds: readonly string[];
|
|
16
|
+
readonly approvedQueries: readonly string[];
|
|
17
|
+
readonly pool: AcquisitionPool;
|
|
18
|
+
readonly maxResponseBytes?: number;
|
|
19
|
+
readonly fetchImpl?: typeof fetch;
|
|
20
|
+
}
|
|
21
|
+
export interface LibraryCandidate {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly title: string;
|
|
24
|
+
readonly versions: readonly string[];
|
|
25
|
+
}
|
|
26
|
+
export interface DocumentationCandidate {
|
|
27
|
+
readonly uri: string;
|
|
28
|
+
readonly body: string;
|
|
29
|
+
readonly requestedLibraryId: string;
|
|
30
|
+
readonly trust: "candidate-only";
|
|
31
|
+
}
|
|
32
|
+
/** Fixed-origin GET adapter. In OMK prefer routing equivalent requests through admitted MCP tools. */
|
|
33
|
+
export declare class Context7Client {
|
|
34
|
+
private readonly key;
|
|
35
|
+
private readonly enabled;
|
|
36
|
+
private readonly names;
|
|
37
|
+
private readonly ids;
|
|
38
|
+
private readonly queries;
|
|
39
|
+
private readonly pool;
|
|
40
|
+
private readonly fetcher;
|
|
41
|
+
private readonly limit;
|
|
42
|
+
constructor(options: Context7Options);
|
|
43
|
+
resolveLibraries(name: string, query: string, signal?: AbortSignal): Promise<AcquisitionResult<readonly LibraryCandidate[]>>;
|
|
44
|
+
getDocumentation(id: string, query: string, signal?: AbortSignal): Promise<AcquisitionResult<readonly DocumentationCandidate[]>>;
|
|
45
|
+
private authorize;
|
|
46
|
+
private get;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=context7.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context7.d.ts","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OAAO,CAAC,QAAQ,CAAC,IAAI,CAAkB;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IACvC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,YAAY,OAAO,EAAE,eAAe,EAanC;IACD,gBAAgB,CACf,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,iBAAiB,CAAC,SAAS,gBAAgB,EAAE,CAAC,CAAC,CAkBzD;IACD,gBAAgB,CACf,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,iBAAiB,CAAC,SAAS,sBAAsB,EAAE,CAAC,CAAC,CAqC/D;IACD,OAAO,CAAC,SAAS;YAKH,GAAG;CAiDjB","sourcesContent":["/**\n * Fixed-origin Context7 GET adapter with explicit egress approval.\n *\n * Ported from docs/OMK_skill_knowledge_control_2026-09-19.zip\n * (src/context7.ts). Every attempted HTTP request consumes a shared\n * AcquisitionPool permit; there is no retry, redirect-following, or\n * auto-selection of the first result. Returned `rules` fields are data, never\n * promoted to instructions.\n */\nimport type { AcquisitionPool, AcquisitionResult } from \"./retrieval.ts\";\nimport { ensure, integer, text } from \"./validation.ts\";\n\nexport interface Context7Options {\n\treadonly apiKey: string;\n\treadonly enabled: boolean;\n\treadonly approvedLibraryNames: readonly string[];\n\treadonly approvedLibraryIds: readonly string[];\n\treadonly approvedQueries: readonly string[];\n\treadonly pool: AcquisitionPool;\n\treadonly maxResponseBytes?: number;\n\treadonly fetchImpl?: typeof fetch;\n}\nexport interface LibraryCandidate {\n\treadonly id: string;\n\treadonly title: string;\n\treadonly versions: readonly string[];\n}\nexport interface DocumentationCandidate {\n\treadonly uri: string;\n\treadonly body: string;\n\treadonly requestedLibraryId: string;\n\treadonly trust: \"candidate-only\";\n}\n/** Fixed-origin GET adapter. In OMK prefer routing equivalent requests through admitted MCP tools. */\nexport class Context7Client {\n\tprivate readonly key: string;\n\tprivate readonly enabled: boolean;\n\tprivate readonly names: ReadonlySet<string>;\n\tprivate readonly ids: ReadonlySet<string>;\n\tprivate readonly queries: ReadonlySet<string>;\n\tprivate readonly pool: AcquisitionPool;\n\tprivate readonly fetcher: typeof fetch;\n\tprivate readonly limit: number;\n\tconstructor(options: Context7Options) {\n\t\ttext(options.apiKey, \"apiKey\", 4096);\n\t\tensure(typeof options.enabled === \"boolean\", \"enabled must be boolean\");\n\t\tthis.limit = options.maxResponseBytes ?? 200_000;\n\t\tinteger(this.limit, \"maxResponseBytes\", 2_000_000);\n\t\tensure(this.limit > 0, \"response limit must be positive\");\n\t\tthis.key = options.apiKey;\n\t\tthis.enabled = options.enabled;\n\t\tthis.names = new Set(options.approvedLibraryNames);\n\t\tthis.ids = new Set(options.approvedLibraryIds);\n\t\tthis.queries = new Set(options.approvedQueries);\n\t\tthis.pool = options.pool;\n\t\tthis.fetcher = options.fetchImpl ?? fetch;\n\t}\n\tresolveLibraries(\n\t\tname: string,\n\t\tquery: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<AcquisitionResult<readonly LibraryCandidate[]>> {\n\t\tthis.authorize(query);\n\t\ttext(name, \"libraryName\", 500);\n\t\tensure(this.names.has(name), \"unapproved library name\");\n\t\treturn this.pool.run(async (abort) => {\n\t\t\tconst payload = await this.get(\"/api/v2/libs/search\", { libraryName: name, query }, abort);\n\t\t\tconst object = record(payload);\n\t\t\tensure(Array.isArray(object.results), \"invalid search response\");\n\t\t\tensure(object.results.length <= 256, \"too many library candidates\");\n\t\t\treturn object.results.map((raw): LibraryCandidate => {\n\t\t\t\tconst candidate = record(raw);\n\t\t\t\tconst id = string(candidate.id),\n\t\t\t\t\ttitle = string(candidate.title);\n\t\t\t\tconst versions = candidate.versions ?? [];\n\t\t\t\tensure(Array.isArray(versions) && versions.every((v) => typeof v === \"string\"), \"invalid versions\");\n\t\t\t\treturn { id, title, versions: versions as string[] };\n\t\t\t});\n\t\t}, signal);\n\t}\n\tgetDocumentation(\n\t\tid: string,\n\t\tquery: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<AcquisitionResult<readonly DocumentationCandidate[]>> {\n\t\tthis.authorize(query);\n\t\ttext(id, \"libraryId\", 500);\n\t\tensure(this.ids.has(id), \"unapproved library id: validate identity/version before retrieval\");\n\t\treturn this.pool.run(async (abort) => {\n\t\t\tconst object = record(await this.get(\"/api/v2/context\", { libraryId: id, query, type: \"json\" }, abort));\n\t\t\tconst info = object.infoSnippets,\n\t\t\t\tcode = object.codeSnippets;\n\t\t\tensure(Array.isArray(info) && Array.isArray(code), \"invalid documentation response\");\n\t\t\tensure(info.length + code.length <= 256, \"too many snippets\");\n\t\t\tconst result: DocumentationCandidate[] = [];\n\t\t\tconst add = (uri: unknown, body: string): void => {\n\t\t\t\tif (typeof uri !== \"string\") return;\n\t\t\t\tlet parsed: URL;\n\t\t\t\ttry {\n\t\t\t\t\tparsed = new URL(uri);\n\t\t\t\t} catch {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Metadata only, never followed. Reject executable/non-web references.\n\t\t\t\tif (parsed.protocol !== \"https:\" || parsed.username || parsed.password) return;\n\t\t\t\tresult.push({ uri: parsed.href, body, requestedLibraryId: id, trust: \"candidate-only\" });\n\t\t\t};\n\t\t\tfor (const raw of info) {\n\t\t\t\tconst v = record(raw);\n\t\t\t\tadd(v.pageId, string(v.content));\n\t\t\t}\n\t\t\tfor (const raw of code) {\n\t\t\t\tconst v = record(raw);\n\t\t\t\tconst list = v.codeList;\n\t\t\t\tensure(Array.isArray(list), \"invalid codeList\");\n\t\t\t\tconst body = list.map((item) => string(record(item).code)).join(\"\\n\\n\");\n\t\t\t\tadd(v.codeId, body);\n\t\t\t}\n\t\t\t// The response's optional `rules` field is deliberately not promoted to instructions.\n\t\t\treturn result;\n\t\t}, signal);\n\t}\n\tprivate authorize(query: string): void {\n\t\tensure(this.enabled, \"remote acquisition disabled\");\n\t\ttext(query, \"public query\", 500);\n\t\tensure(this.queries.has(query), \"query has not been approved for egress\");\n\t}\n\tprivate async get(path: string, parameters: Record<string, string>, signal: AbortSignal): Promise<unknown> {\n\t\tconst url = new URL(path, \"https://context7.com\");\n\t\tfor (const [key, value] of Object.entries(parameters)) url.searchParams.set(key, value);\n\t\tconst response = await this.fetcher(url, {\n\t\t\tmethod: \"GET\",\n\t\t\tredirect: \"error\",\n\t\t\tsignal,\n\t\t\theaders: { Authorization: `Bearer ${this.key}`, Accept: \"application/json\" },\n\t\t});\n\t\t// No retry here: every attempted HTTP request must acquire a fresh shared budget slot.\n\t\tif (response.status !== 200) {\n\t\t\tif (response.body) await response.body.cancel();\n\t\t\tthrow new Error(`context7-http-${response.status}`);\n\t\t}\n\t\tconst contentType = response.headers.get(\"content-type\") ?? \"\";\n\t\tif (!contentType.includes(\"application/json\")) {\n\t\t\tif (response.body) await response.body.cancel();\n\t\t\tthrow new Error(\"unexpected response content type\");\n\t\t}\n\t\tensure(response.body !== null, \"missing response body\");\n\t\tconst reader = response.body.getReader();\n\t\tlet bytes = 0;\n\t\tconst chunks: Uint8Array[] = [];\n\t\ttry {\n\t\t\twhile (true) {\n\t\t\t\tconst next = await reader.read();\n\t\t\t\tif (next.done) break;\n\t\t\t\tbytes += next.value.byteLength;\n\t\t\t\tensure(bytes <= this.limit, \"response byte budget exceeded\");\n\t\t\t\tchunks.push(next.value);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tawait reader.cancel();\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\treader.releaseLock();\n\t\t}\n\t\tconst joined = new Uint8Array(bytes);\n\t\tlet at = 0;\n\t\tfor (const chunk of chunks) {\n\t\t\tjoined.set(chunk, at);\n\t\t\tat += chunk.byteLength;\n\t\t}\n\t\ttry {\n\t\t\treturn JSON.parse(new TextDecoder(\"utf-8\", { fatal: true }).decode(joined)) as unknown;\n\t\t} catch {\n\t\t\tthrow new Error(\"malformed context7 response body\");\n\t\t}\n\t}\n}\nfunction record(value: unknown): Record<string, unknown> {\n\tensure(value !== null && typeof value === \"object\" && !Array.isArray(value), \"expected response object\");\n\treturn value as Record<string, unknown>;\n}\nfunction string(value: unknown): string {\n\tensure(typeof value === \"string\", \"expected response string\");\n\treturn value;\n}\n"]}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { ensure, integer, text } from "./validation.js";
|
|
2
|
+
/** Fixed-origin GET adapter. In OMK prefer routing equivalent requests through admitted MCP tools. */
|
|
3
|
+
export class Context7Client {
|
|
4
|
+
key;
|
|
5
|
+
enabled;
|
|
6
|
+
names;
|
|
7
|
+
ids;
|
|
8
|
+
queries;
|
|
9
|
+
pool;
|
|
10
|
+
fetcher;
|
|
11
|
+
limit;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
text(options.apiKey, "apiKey", 4096);
|
|
14
|
+
ensure(typeof options.enabled === "boolean", "enabled must be boolean");
|
|
15
|
+
this.limit = options.maxResponseBytes ?? 200_000;
|
|
16
|
+
integer(this.limit, "maxResponseBytes", 2_000_000);
|
|
17
|
+
ensure(this.limit > 0, "response limit must be positive");
|
|
18
|
+
this.key = options.apiKey;
|
|
19
|
+
this.enabled = options.enabled;
|
|
20
|
+
this.names = new Set(options.approvedLibraryNames);
|
|
21
|
+
this.ids = new Set(options.approvedLibraryIds);
|
|
22
|
+
this.queries = new Set(options.approvedQueries);
|
|
23
|
+
this.pool = options.pool;
|
|
24
|
+
this.fetcher = options.fetchImpl ?? fetch;
|
|
25
|
+
}
|
|
26
|
+
resolveLibraries(name, query, signal) {
|
|
27
|
+
this.authorize(query);
|
|
28
|
+
text(name, "libraryName", 500);
|
|
29
|
+
ensure(this.names.has(name), "unapproved library name");
|
|
30
|
+
return this.pool.run(async (abort) => {
|
|
31
|
+
const payload = await this.get("/api/v2/libs/search", { libraryName: name, query }, abort);
|
|
32
|
+
const object = record(payload);
|
|
33
|
+
ensure(Array.isArray(object.results), "invalid search response");
|
|
34
|
+
ensure(object.results.length <= 256, "too many library candidates");
|
|
35
|
+
return object.results.map((raw) => {
|
|
36
|
+
const candidate = record(raw);
|
|
37
|
+
const id = string(candidate.id), title = string(candidate.title);
|
|
38
|
+
const versions = candidate.versions ?? [];
|
|
39
|
+
ensure(Array.isArray(versions) && versions.every((v) => typeof v === "string"), "invalid versions");
|
|
40
|
+
return { id, title, versions: versions };
|
|
41
|
+
});
|
|
42
|
+
}, signal);
|
|
43
|
+
}
|
|
44
|
+
getDocumentation(id, query, signal) {
|
|
45
|
+
this.authorize(query);
|
|
46
|
+
text(id, "libraryId", 500);
|
|
47
|
+
ensure(this.ids.has(id), "unapproved library id: validate identity/version before retrieval");
|
|
48
|
+
return this.pool.run(async (abort) => {
|
|
49
|
+
const object = record(await this.get("/api/v2/context", { libraryId: id, query, type: "json" }, abort));
|
|
50
|
+
const info = object.infoSnippets, code = object.codeSnippets;
|
|
51
|
+
ensure(Array.isArray(info) && Array.isArray(code), "invalid documentation response");
|
|
52
|
+
ensure(info.length + code.length <= 256, "too many snippets");
|
|
53
|
+
const result = [];
|
|
54
|
+
const add = (uri, body) => {
|
|
55
|
+
if (typeof uri !== "string")
|
|
56
|
+
return;
|
|
57
|
+
let parsed;
|
|
58
|
+
try {
|
|
59
|
+
parsed = new URL(uri);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// Metadata only, never followed. Reject executable/non-web references.
|
|
65
|
+
if (parsed.protocol !== "https:" || parsed.username || parsed.password)
|
|
66
|
+
return;
|
|
67
|
+
result.push({ uri: parsed.href, body, requestedLibraryId: id, trust: "candidate-only" });
|
|
68
|
+
};
|
|
69
|
+
for (const raw of info) {
|
|
70
|
+
const v = record(raw);
|
|
71
|
+
add(v.pageId, string(v.content));
|
|
72
|
+
}
|
|
73
|
+
for (const raw of code) {
|
|
74
|
+
const v = record(raw);
|
|
75
|
+
const list = v.codeList;
|
|
76
|
+
ensure(Array.isArray(list), "invalid codeList");
|
|
77
|
+
const body = list.map((item) => string(record(item).code)).join("\n\n");
|
|
78
|
+
add(v.codeId, body);
|
|
79
|
+
}
|
|
80
|
+
// The response's optional `rules` field is deliberately not promoted to instructions.
|
|
81
|
+
return result;
|
|
82
|
+
}, signal);
|
|
83
|
+
}
|
|
84
|
+
authorize(query) {
|
|
85
|
+
ensure(this.enabled, "remote acquisition disabled");
|
|
86
|
+
text(query, "public query", 500);
|
|
87
|
+
ensure(this.queries.has(query), "query has not been approved for egress");
|
|
88
|
+
}
|
|
89
|
+
async get(path, parameters, signal) {
|
|
90
|
+
const url = new URL(path, "https://context7.com");
|
|
91
|
+
for (const [key, value] of Object.entries(parameters))
|
|
92
|
+
url.searchParams.set(key, value);
|
|
93
|
+
const response = await this.fetcher(url, {
|
|
94
|
+
method: "GET",
|
|
95
|
+
redirect: "error",
|
|
96
|
+
signal,
|
|
97
|
+
headers: { Authorization: `Bearer ${this.key}`, Accept: "application/json" },
|
|
98
|
+
});
|
|
99
|
+
// No retry here: every attempted HTTP request must acquire a fresh shared budget slot.
|
|
100
|
+
if (response.status !== 200) {
|
|
101
|
+
if (response.body)
|
|
102
|
+
await response.body.cancel();
|
|
103
|
+
throw new Error(`context7-http-${response.status}`);
|
|
104
|
+
}
|
|
105
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
106
|
+
if (!contentType.includes("application/json")) {
|
|
107
|
+
if (response.body)
|
|
108
|
+
await response.body.cancel();
|
|
109
|
+
throw new Error("unexpected response content type");
|
|
110
|
+
}
|
|
111
|
+
ensure(response.body !== null, "missing response body");
|
|
112
|
+
const reader = response.body.getReader();
|
|
113
|
+
let bytes = 0;
|
|
114
|
+
const chunks = [];
|
|
115
|
+
try {
|
|
116
|
+
while (true) {
|
|
117
|
+
const next = await reader.read();
|
|
118
|
+
if (next.done)
|
|
119
|
+
break;
|
|
120
|
+
bytes += next.value.byteLength;
|
|
121
|
+
ensure(bytes <= this.limit, "response byte budget exceeded");
|
|
122
|
+
chunks.push(next.value);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
await reader.cancel();
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
reader.releaseLock();
|
|
131
|
+
}
|
|
132
|
+
const joined = new Uint8Array(bytes);
|
|
133
|
+
let at = 0;
|
|
134
|
+
for (const chunk of chunks) {
|
|
135
|
+
joined.set(chunk, at);
|
|
136
|
+
at += chunk.byteLength;
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(joined));
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
throw new Error("malformed context7 response body");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function record(value) {
|
|
147
|
+
ensure(value !== null && typeof value === "object" && !Array.isArray(value), "expected response object");
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
function string(value) {
|
|
151
|
+
ensure(typeof value === "string", "expected response string");
|
|
152
|
+
return value;
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=context7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context7.js","sourceRoot":"","sources":["../../src/metacognition/context7.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAuBxD,sGAAsG;AACtG,MAAM,OAAO,cAAc;IACT,GAAG,CAAS;IACZ,OAAO,CAAU;IACjB,KAAK,CAAsB;IAC3B,GAAG,CAAsB;IACzB,OAAO,CAAsB;IAC7B,IAAI,CAAkB;IACtB,OAAO,CAAe;IACtB,KAAK,CAAS;IAC/B,YAAY,OAAwB,EAAE;QACrC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;QACrC,MAAM,CAAC,OAAO,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,yBAAyB,CAAC,CAAC;QAC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CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACzB,CAAC;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;YACtB,MAAM,KAAK,CAAC;QACb,CAAC;gBAAS,CAAC;YACV,MAAM,CAAC,WAAW,EAAE,CAAC;QACtB,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,EAAE,GAAG,CAAC,CAAC;QACX,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC5B,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YACtB,EAAE,IAAI,KAAK,CAAC,UAAU,CAAC;QACxB,CAAC;QACD,IAAI,CAAC;YACJ,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAY,CAAC;QACxF,CAAC;QAAC,MAAM,CAAC;YACR,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACrD,CAAC;IAAA,CACD;CACD;AACD,SAAS,MAAM,CAAC,KAAc,EAA2B;IACxD,MAAM,CAAC,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,0BAA0B,CAAC,CAAC;IACzG,OAAO,KAAgC,CAAC;AAAA,CACxC;AACD,SAAS,MAAM,CAAC,KAAc,EAAU;IACvC,MAAM,CAAC,OAAO,KAAK,KAAK,QAAQ,EAAE,0BAA0B,CAAC,CAAC;IAC9D,OAAO,KAAK,CAAC;AAAA,CACb","sourcesContent":["/**\n * Fixed-origin Context7 GET adapter with explicit egress approval.\n *\n * Ported from docs/OMK_skill_knowledge_control_2026-09-19.zip\n * (src/context7.ts). Every attempted HTTP request consumes a shared\n * AcquisitionPool permit; there is no retry, redirect-following, or\n * auto-selection of the first result. Returned `rules` fields are data, never\n * promoted to instructions.\n */\nimport type { AcquisitionPool, AcquisitionResult } from \"./retrieval.ts\";\nimport { ensure, integer, text } from \"./validation.ts\";\n\nexport interface Context7Options {\n\treadonly apiKey: string;\n\treadonly enabled: boolean;\n\treadonly approvedLibraryNames: readonly string[];\n\treadonly approvedLibraryIds: readonly string[];\n\treadonly approvedQueries: readonly string[];\n\treadonly pool: AcquisitionPool;\n\treadonly maxResponseBytes?: number;\n\treadonly fetchImpl?: typeof fetch;\n}\nexport interface LibraryCandidate {\n\treadonly id: string;\n\treadonly title: string;\n\treadonly versions: readonly string[];\n}\nexport interface DocumentationCandidate {\n\treadonly uri: string;\n\treadonly body: string;\n\treadonly requestedLibraryId: string;\n\treadonly trust: \"candidate-only\";\n}\n/** Fixed-origin GET adapter. In OMK prefer routing equivalent requests through admitted MCP tools. */\nexport class Context7Client {\n\tprivate readonly key: string;\n\tprivate readonly enabled: boolean;\n\tprivate readonly names: ReadonlySet<string>;\n\tprivate readonly ids: ReadonlySet<string>;\n\tprivate readonly queries: ReadonlySet<string>;\n\tprivate readonly pool: AcquisitionPool;\n\tprivate readonly fetcher: typeof fetch;\n\tprivate readonly limit: number;\n\tconstructor(options: Context7Options) {\n\t\ttext(options.apiKey, \"apiKey\", 4096);\n\t\tensure(typeof options.enabled === \"boolean\", \"enabled must be boolean\");\n\t\tthis.limit = options.maxResponseBytes ?? 200_000;\n\t\tinteger(this.limit, \"maxResponseBytes\", 2_000_000);\n\t\tensure(this.limit > 0, \"response limit must be positive\");\n\t\tthis.key = options.apiKey;\n\t\tthis.enabled = options.enabled;\n\t\tthis.names = new Set(options.approvedLibraryNames);\n\t\tthis.ids = new Set(options.approvedLibraryIds);\n\t\tthis.queries = new Set(options.approvedQueries);\n\t\tthis.pool = options.pool;\n\t\tthis.fetcher = options.fetchImpl ?? fetch;\n\t}\n\tresolveLibraries(\n\t\tname: string,\n\t\tquery: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<AcquisitionResult<readonly LibraryCandidate[]>> {\n\t\tthis.authorize(query);\n\t\ttext(name, \"libraryName\", 500);\n\t\tensure(this.names.has(name), \"unapproved library name\");\n\t\treturn this.pool.run(async (abort) => {\n\t\t\tconst payload = await this.get(\"/api/v2/libs/search\", { libraryName: name, query }, abort);\n\t\t\tconst object = record(payload);\n\t\t\tensure(Array.isArray(object.results), \"invalid search response\");\n\t\t\tensure(object.results.length <= 256, \"too many library candidates\");\n\t\t\treturn object.results.map((raw): LibraryCandidate => {\n\t\t\t\tconst candidate = record(raw);\n\t\t\t\tconst id = string(candidate.id),\n\t\t\t\t\ttitle = string(candidate.title);\n\t\t\t\tconst versions = candidate.versions ?? [];\n\t\t\t\tensure(Array.isArray(versions) && versions.every((v) => typeof v === \"string\"), \"invalid versions\");\n\t\t\t\treturn { id, title, versions: versions as string[] };\n\t\t\t});\n\t\t}, signal);\n\t}\n\tgetDocumentation(\n\t\tid: string,\n\t\tquery: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<AcquisitionResult<readonly DocumentationCandidate[]>> {\n\t\tthis.authorize(query);\n\t\ttext(id, \"libraryId\", 500);\n\t\tensure(this.ids.has(id), \"unapproved library id: validate identity/version before retrieval\");\n\t\treturn this.pool.run(async (abort) => {\n\t\t\tconst object = record(await this.get(\"/api/v2/context\", { libraryId: id, query, type: \"json\" }, abort));\n\t\t\tconst info = object.infoSnippets,\n\t\t\t\tcode = object.codeSnippets;\n\t\t\tensure(Array.isArray(info) && Array.isArray(code), \"invalid documentation response\");\n\t\t\tensure(info.length + code.length <= 256, \"too many snippets\");\n\t\t\tconst result: DocumentationCandidate[] = [];\n\t\t\tconst add = (uri: unknown, body: string): void => {\n\t\t\t\tif (typeof uri !== \"string\") return;\n\t\t\t\tlet parsed: URL;\n\t\t\t\ttry {\n\t\t\t\t\tparsed = new URL(uri);\n\t\t\t\t} catch {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Metadata only, never followed. Reject executable/non-web references.\n\t\t\t\tif (parsed.protocol !== \"https:\" || parsed.username || parsed.password) return;\n\t\t\t\tresult.push({ uri: parsed.href, body, requestedLibraryId: id, trust: \"candidate-only\" });\n\t\t\t};\n\t\t\tfor (const raw of info) {\n\t\t\t\tconst v = record(raw);\n\t\t\t\tadd(v.pageId, string(v.content));\n\t\t\t}\n\t\t\tfor (const raw of code) {\n\t\t\t\tconst v = record(raw);\n\t\t\t\tconst list = v.codeList;\n\t\t\t\tensure(Array.isArray(list), \"invalid codeList\");\n\t\t\t\tconst body = list.map((item) => string(record(item).code)).join(\"\\n\\n\");\n\t\t\t\tadd(v.codeId, body);\n\t\t\t}\n\t\t\t// The response's optional `rules` field is deliberately not promoted to instructions.\n\t\t\treturn result;\n\t\t}, signal);\n\t}\n\tprivate authorize(query: string): void {\n\t\tensure(this.enabled, \"remote acquisition disabled\");\n\t\ttext(query, \"public query\", 500);\n\t\tensure(this.queries.has(query), \"query has not been approved for egress\");\n\t}\n\tprivate async get(path: string, parameters: Record<string, string>, signal: AbortSignal): Promise<unknown> {\n\t\tconst url = new URL(path, \"https://context7.com\");\n\t\tfor (const [key, value] of Object.entries(parameters)) url.searchParams.set(key, value);\n\t\tconst response = await this.fetcher(url, {\n\t\t\tmethod: \"GET\",\n\t\t\tredirect: \"error\",\n\t\t\tsignal,\n\t\t\theaders: { Authorization: `Bearer ${this.key}`, Accept: \"application/json\" },\n\t\t});\n\t\t// No retry here: every attempted HTTP request must acquire a fresh shared budget slot.\n\t\tif (response.status !== 200) {\n\t\t\tif (response.body) await response.body.cancel();\n\t\t\tthrow new Error(`context7-http-${response.status}`);\n\t\t}\n\t\tconst contentType = response.headers.get(\"content-type\") ?? \"\";\n\t\tif (!contentType.includes(\"application/json\")) {\n\t\t\tif (response.body) await response.body.cancel();\n\t\t\tthrow new Error(\"unexpected response content type\");\n\t\t}\n\t\tensure(response.body !== null, \"missing response body\");\n\t\tconst reader = response.body.getReader();\n\t\tlet bytes = 0;\n\t\tconst chunks: Uint8Array[] = [];\n\t\ttry {\n\t\t\twhile (true) {\n\t\t\t\tconst next = await reader.read();\n\t\t\t\tif (next.done) break;\n\t\t\t\tbytes += next.value.byteLength;\n\t\t\t\tensure(bytes <= this.limit, \"response byte budget exceeded\");\n\t\t\t\tchunks.push(next.value);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tawait reader.cancel();\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\treader.releaseLock();\n\t\t}\n\t\tconst joined = new Uint8Array(bytes);\n\t\tlet at = 0;\n\t\tfor (const chunk of chunks) {\n\t\t\tjoined.set(chunk, at);\n\t\t\tat += chunk.byteLength;\n\t\t}\n\t\ttry {\n\t\t\treturn JSON.parse(new TextDecoder(\"utf-8\", { fatal: true }).decode(joined)) as unknown;\n\t\t} catch {\n\t\t\tthrow new Error(\"malformed context7 response body\");\n\t\t}\n\t}\n}\nfunction record(value: unknown): Record<string, unknown> {\n\tensure(value !== null && typeof value === \"object\" && !Array.isArray(value), \"expected response object\");\n\treturn value as Record<string, unknown>;\n}\nfunction string(value: unknown): string {\n\tensure(typeof value === \"string\", \"expected response string\");\n\treturn value;\n}\n"]}
|