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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-budget-v2-selection.js","sourceRoot":"","sources":["../../src/core/context-budget-v2-selection.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,4BAA4B,EAC5B,8BAA8B,EAC9B,cAAc,GACd,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,0BAA0B,EAA4B,MAAM,mCAAmC,CAAC;AACzG,OAAO,EACN,0BAA0B,EAE1B,0BAA0B,GAC1B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,2CAA2C,EAAE,MAAM,wCAAwC,CAAC;AACrG,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAsB,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AACxH,OAAO,EACN,YAAY,GAIZ,MAAM,8BAA8B,CAAC;AAetC;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SAAS,CAAC,IAAI;QACpB,eAAe,EAAE,SAAS,CAAC,eAAe;QAC1C,QAAQ,EAAE,SAAS,CAAC,QAAQ;QAC5B,SAAS,EAAE,SAAS,CAAC,SAAS;QAC9B,WAAW,EAAE,SAAS,CAAC,WAAW;QAClC,YAAY,EAAE,SAAS,CAAC,YAAY;QACpC,KAAK,EAAE,SAAS,CAAC,KAAK;KACtB,CAAC;AAAA,CACF;AAED,SAAS,QAAQ,CAChB,OAAsB,EACtB,KAAqF,EAC9E;IACP,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,CAAC;QACzC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC;YACtB,MAAM,EAAE,qBAAqB;YAC7B,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE;YACvB,MAAM,EAAE,eAAe,OAAO,CAAC,IAAI,CAAC,IAAI,UAAU,OAAO,CAAC,IAAI,CAAC,EAAE,+CAA+C;SAChH,CAAC,CAAC;QACH,KAAK,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;AAAA,CACD","sourcesContent":["import {\n\ttype ContextBudgetItemV2,\n\ttype ContextBudgetTierV2,\n\ttype ContextRepresentationCandidateV2,\n\ttype ContextSourceRefV2,\n\tchooseHeadroomRepresentation,\n\tderiveRepresentationCandidates,\n\tfullTextTokens,\n} from \"./context-budget-headroom.ts\";\nimport { createFallbackTokenCounter, type TokenCounterAdapter } from \"./context-budget-token-counter.ts\";\nimport {\n\tapplyRepresentationCacheV2,\n\ttype ContextBudgetSelectionCacheV2,\n\twriteRepresentationCacheV2,\n} from \"./context-budget-v2-cache.ts\";\nimport { recordContextBudgetRepresentationCacheHitV2 } from \"./context-budget-v2-cache-telemetry.ts\";\nimport { computeCoverageGap } from \"./context-budget-v2-coverage.ts\";\nimport { contentHashOf } from \"./context-budget-v2-plan-hash.ts\";\nimport { applyRedundancyPenalties, type PlannedItemV2, scoreContextBudgetItemV2 } from \"./context-budget-v2-scoring.ts\";\nimport {\n\tALL_TIERS_V2,\n\ttype QualityDiagnosticV2,\n\ttype SelectedRepresentationV2,\n\ttype TierBudgetAllocationV2,\n} from \"./context-budget-v2-types.ts\";\n\nexport interface OptionalSelectionState {\n\treadonly allocation: ReadonlyMap<ContextBudgetTierV2, { readonly ceiling: number }>;\n\treadonly available: number;\n\treadonly cache?: ContextBudgetSelectionCacheV2;\n\treadonly diagnostics: QualityDiagnosticV2[];\n\treadonly omitted: ContextBudgetItemV2[];\n\treadonly qualityPolicy: Parameters<typeof chooseHeadroomRepresentation>[2];\n\treadonly retrievalFallbacks: ContextSourceRefV2[];\n\treadonly selection: Map<string, SelectedRepresentationV2>;\n\treadonly tierUsed: Record<ContextBudgetTierV2, number>;\n\treadonly usedTokens: number;\n}\n\n/**\n * Cheapest non-omit representation cost for an item, i.e. what admitting it\n * actually costs when the budget is tight. Falls back to full text when no\n * cheaper representation exists.\n */\nfunction minAdmissibleTokens(candidates: readonly ContextRepresentationCandidateV2[], fullTokens: number): number {\n\tlet min = Number.POSITIVE_INFINITY;\n\tfor (const candidate of candidates) {\n\t\tif (candidate.kind === \"omit\") continue;\n\t\tif (candidate.estimatedTokens < min) min = candidate.estimatedTokens;\n\t}\n\treturn Math.max(1, Number.isFinite(min) ? min : fullTokens);\n}\n\nexport function createPlannedItems(\n\titems: readonly ContextBudgetItemV2[],\n\ttokenCounter: TokenCounterAdapter | undefined,\n\tmodelId: string,\n\tqualityPolicy?: Parameters<typeof deriveRepresentationCandidates>[1],\n): PlannedItemV2[] {\n\tconst counter = tokenCounter ?? createFallbackTokenCounter();\n\treturn items.map((item) => {\n\t\tconst overrideTokenEstimate = item.tokenEstimate ?? counter.countText(item.text, modelId).tokens;\n\t\tconst itemWithTokens =\n\t\t\titem.tokenEstimate === undefined ? { ...item, tokenEstimate: overrideTokenEstimate } : item;\n\t\tconst fullTokens = fullTextTokens(itemWithTokens);\n\t\tconst isHard = item.priority === \"hard\" || item.required === true;\n\t\tconst baseScore = isHard ? Number.POSITIVE_INFINITY : scoreContextBudgetItemV2(itemWithTokens, fullTokens);\n\t\tconst candidates =\n\t\t\titemWithTokens.representations ?? deriveRepresentationCandidates(itemWithTokens, qualityPolicy);\n\t\treturn {\n\t\t\titem: itemWithTokens,\n\t\t\tfullTokens,\n\t\t\tadmissibleTokens: minAdmissibleTokens(candidates, fullTokens),\n\t\t\tcontentHash: contentHashOf(item.text),\n\t\t\tbaseScore,\n\t\t\tredundancyPenalty: 0,\n\t\t\teffectiveScore: baseScore,\n\t\t\tisHard,\n\t\t};\n\t});\n}\n\nexport function applyPlannerRedundancyPenalties(plannedItems: PlannedItemV2[]): void {\n\tconst penalties = applyRedundancyPenalties(plannedItems.filter((planned) => !planned.isHard));\n\tfor (const planned of plannedItems) {\n\t\tconst penalty = penalties.get(planned.item.id);\n\t\tif (penalty === undefined) continue;\n\t\tplanned.redundancyPenalty = penalty;\n\t\tplanned.effectiveScore = planned.baseScore - penalty;\n\t}\n}\n\nexport function selectHardItem(\n\tplanned: PlannedItemV2,\n\tselection: Map<string, SelectedRepresentationV2>,\n\ttierUsed: Record<ContextBudgetTierV2, number>,\n): number {\n\tconst candidate: ContextRepresentationCandidateV2 = {\n\t\tkind: \"full\",\n\t\ttext: planned.item.text,\n\t\testimatedTokens: planned.fullTokens,\n\t\tfidelity: planned.item.tokenEstimate !== undefined ? \"exact\" : \"bounded\",\n\t\tsourceRef: planned.item.sourceRef,\n\t};\n\tselection.set(planned.item.id, toSelected(planned.item.id, candidate));\n\ttierUsed[planned.item.tier] += planned.fullTokens;\n\treturn planned.fullTokens;\n}\n\nexport function selectOptionalItem(planned: PlannedItemV2, state: OptionalSelectionState): number {\n\tif (state.usedTokens >= state.available) {\n\t\tomitItem(planned, state);\n\t\treturn state.usedTokens;\n\t}\n\tconst tierCeiling = state.allocation.get(planned.item.tier)?.ceiling ?? state.available;\n\tconst remaining = Math.max(0, state.available - state.usedTokens);\n\tconst candidates = planned.item.representations ?? deriveRepresentationCandidates(planned.item, state.qualityPolicy);\n\tconst materializedEnabled = planned.item.representations === undefined;\n\tconst cachedCandidates = state.cache\n\t\t? applyRepresentationCacheV2({ planned, candidates, cache: state.cache, materializedEnabled })\n\t\t: candidates;\n\tconst chosen = chooseHeadroomRepresentation(\n\t\t{ ...planned.item, representations: cachedCandidates },\n\t\t{\n\t\t\ttierUsedTokens: state.tierUsed[planned.item.tier],\n\t\t\ttierCeilingTokens: tierCeiling,\n\t\t\tremainingGlobalTokens: remaining,\n\t\t},\n\t\tstate.qualityPolicy,\n\t);\n\tif (chosen.kind === \"omit\") {\n\t\tconst tierRemaining = Math.max(0, tierCeiling - state.tierUsed[planned.item.tier]);\n\t\tconst globalFit = cachedCandidates.filter(\n\t\t\t(candidate) => candidate.kind !== \"omit\" && candidate.estimatedTokens <= remaining,\n\t\t);\n\t\tif (globalFit.length > 0 && globalFit.every((candidate) => candidate.estimatedTokens > tierRemaining)) {\n\t\t\tstate.diagnostics.push({\n\t\t\t\treason: \"tier_ceiling_exceeded\",\n\t\t\t\titemId: planned.item.id,\n\t\t\t\tdetail: `${planned.item.tier} item \"${planned.item.id}\" needs ${Math.min(\n\t\t\t\t\t...globalFit.map((candidate) => candidate.estimatedTokens),\n\t\t\t\t)} tokens with ${tierRemaining} tier tokens remaining`,\n\t\t\t});\n\t\t}\n\t\tomitItem(planned, state);\n\t\treturn state.usedTokens;\n\t}\n\tif (state.tierUsed[planned.item.tier] + chosen.estimatedTokens > tierCeiling) {\n\t\tstate.diagnostics.push({\n\t\t\treason: \"tier_ceiling_exceeded\",\n\t\t\titemId: planned.item.id,\n\t\t\tdetail: `${planned.item.tier} item \"${planned.item.id}\" needs ${chosen.estimatedTokens} tokens with ${Math.max(0, tierCeiling - state.tierUsed[planned.item.tier])} tier tokens remaining`,\n\t\t});\n\t\tomitItem(planned, state);\n\t\treturn state.usedTokens;\n\t}\n\tif (state.usedTokens + chosen.estimatedTokens > state.available) {\n\t\tomitItem(planned, state);\n\t\treturn state.usedTokens;\n\t}\n\tif (state.cache) {\n\t\tif (chosen.cache?.hit === true) {\n\t\t\trecordContextBudgetRepresentationCacheHitV2(\n\t\t\t\tstate.cache.telemetry,\n\t\t\t\tchosen.kind,\n\t\t\t\tchosen.cache.keyKind,\n\t\t\t\tplanned.fullTokens,\n\t\t\t);\n\t\t}\n\t\twriteRepresentationCacheV2({ planned, selected: chosen, cache: state.cache, materializedEnabled });\n\t}\n\tstate.selection.set(planned.item.id, toSelected(planned.item.id, chosen));\n\tstate.tierUsed[planned.item.tier] += chosen.estimatedTokens;\n\treturn state.usedTokens + chosen.estimatedTokens;\n}\n\nexport function emitOmissionDiagnostics(\n\tomitted: readonly ContextBudgetItemV2[],\n\tdiagnostics: QualityDiagnosticV2[],\n\tretrievalFallbacks: ContextSourceRefV2[],\n): void {\n\tfor (const item of omitted) {\n\t\tif (item.priority === \"high\" || item.required === true) {\n\t\t\tdiagnostics.push({\n\t\t\t\treason: \"omitted_high_priority\",\n\t\t\t\titemId: item.id,\n\t\t\t\tdetail: `${item.tier} item \"${item.id}\" could not fit within the prompt budget`,\n\t\t\t});\n\t\t}\n\t\tif (item.sourceRef?.retrievable) {\n\t\t\tdiagnostics.push({\n\t\t\t\treason: \"restore_on_demand_hint\",\n\t\t\t\titemId: item.id,\n\t\t\t\tdetail: `retrievable \"${item.id}\" kept as fallback via ${item.sourceRef.uri}`,\n\t\t\t});\n\t\t\tretrievalFallbacks.push(item.sourceRef);\n\t\t}\n\t}\n}\n\nexport function emitCoverageDiagnostics(\n\tquery: string | undefined,\n\tselection: ReadonlyMap<string, SelectedRepresentationV2>,\n\tdiagnostics: QualityDiagnosticV2[],\n): void {\n\tconst coverage = computeCoverageGap(\n\t\tquery,\n\t\t[...selection.values()].map((representation) => representation.text),\n\t);\n\tif (!coverage.gap) return;\n\tdiagnostics.push({\n\t\treason: \"coverage_gap\",\n\t\tdetail: `query terms not covered by selected context: ${coverage.missing.join(\", \")}`,\n\t});\n}\n\nexport function buildTierAllocations(\n\tallocation: ReadonlyMap<\n\t\tContextBudgetTierV2,\n\t\t{ readonly floor: number; readonly ceiling: number; readonly allocated: number }\n\t>,\n\tdemand: ReadonlyMap<ContextBudgetTierV2, { readonly hard: number }>,\n\ttierUsed: Record<ContextBudgetTierV2, number>,\n): TierBudgetAllocationV2[] {\n\treturn ALL_TIERS_V2.map((tier) => {\n\t\tconst raw = allocation.get(tier) ?? { floor: 0, ceiling: 0, allocated: 0 };\n\t\treturn {\n\t\t\ttier,\n\t\t\tfloorTokens: raw.floor,\n\t\t\tceilingTokens: raw.ceiling,\n\t\t\tallocatedTokens: raw.allocated,\n\t\t\tusedTokens: tierUsed[tier],\n\t\t\thardTokens: demand.get(tier)?.hard ?? 0,\n\t\t};\n\t});\n}\n\nexport function createTierUsage(): Record<ContextBudgetTierV2, number> {\n\treturn {\n\t\tsystem: 0,\n\t\t\"active-goal\": 0,\n\t\t\"current-files\": 0,\n\t\ttools: 0,\n\t\tskills: 0,\n\t\tmcp: 0,\n\t\thistory: 0,\n\t\tevidence: 0,\n\t\tscratch: 0,\n\t};\n}\n\nfunction toSelected(itemId: string, candidate: ContextRepresentationCandidateV2): SelectedRepresentationV2 {\n\treturn {\n\t\titemId,\n\t\tkind: candidate.kind,\n\t\ttext: candidate.text,\n\t\testimatedTokens: candidate.estimatedTokens,\n\t\tfidelity: candidate.fidelity,\n\t\tsourceRef: candidate.sourceRef,\n\t\tsummaryHash: candidate.summaryHash,\n\t\tcompressorId: candidate.compressorId,\n\t\tcache: candidate.cache,\n\t};\n}\n\nfunction omitItem(\n\tplanned: PlannedItemV2,\n\tstate: Pick<OptionalSelectionState, \"diagnostics\" | \"omitted\" | \"retrievalFallbacks\">,\n): void {\n\tstate.omitted.push(planned.item);\n\tif (planned.item.sourceRef?.retrievable) {\n\t\tstate.diagnostics.push({\n\t\t\treason: \"retrieval_miss_risk\",\n\t\t\titemId: planned.item.id,\n\t\t\tdetail: `retrievable ${planned.item.tier} item \"${planned.item.id}\" omitted; keep pointer for restore-on-demand`,\n\t\t});\n\t\tstate.retrievalFallbacks.push(planned.item.sourceRef);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"context-budget-v2-selection.js","sourceRoot":"","sources":["../../src/core/context-budget-v2-selection.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,4BAA4B,EAC5B,8BAA8B,GAC9B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,0BAA0B,EAE1B,0BAA0B,GAC1B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,2CAA2C,EAAE,MAAM,wCAAwC,CAAC;AACrG,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAsB,MAAM,gCAAgC,CAAC;AAC9F,OAAO,EACN,YAAY,GAIZ,MAAM,8BAA8B,CAAC;AA+BtC,MAAM,UAAU,+BAA+B,CAAC,YAA6B,EAAQ;IACpF,MAAM,SAAS,GAAG,wBAAwB,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9F,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/C,IAAI,OAAO,KAAK,SAAS;YAAE,SAAS;QACpC,OAAO,CAAC,iBAAiB,GAAG,OAAO,CAAC;QACpC,OAAO,CAAC,cAAc,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC;IACtD,CAAC;AAAA,CACD;AAED,MAAM,UAAU,cAAc,CAC7B,OAAsB,EACtB,SAAgD,EAChD,QAA6C,EACpC;IACT,MAAM,SAAS,GAAqC;QACnD,IAAI,E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SAAS,CAAC,IAAI;QACpB,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,eAAe,EAAE,SAAS,CAAC,eAAe;QAC1C,QAAQ,EAAE,SAAS,CAAC,QAAQ;QAC5B,SAAS,EAAE,SAAS,CAAC,SAAS;QAC9B,WAAW,EAAE,SAAS,CAAC,WAAW;QAClC,YAAY,EAAE,SAAS,CAAC,YAAY;QACpC,KAAK,EAAE,SAAS,CAAC,KAAK;KACtB,CAAC;AAAA,CACF;AAED,SAAS,QAAQ,CAChB,OAAsB,EACtB,KAAqF,EAC9E;IACP,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,CAAC;QACzC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC;YACtB,MAAM,EAAE,qBAAqB;YAC7B,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,EAAE;YACvB,MAAM,EAAE,eAAe,OAAO,CAAC,IAAI,CAAC,IAAI,UAAU,OAAO,CAAC,IAAI,CAAC,EAAE,+CAA+C;SAChH,CAAC,CAAC;QACH,KAAK,CAAC,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;AAAA,CACD","sourcesContent":["import {\n\ttype ContextBudgetItemV2,\n\ttype ContextBudgetTierV2,\n\ttype ContextRepresentationCandidateV2,\n\ttype ContextSourceRefV2,\n\tchooseHeadroomRepresentation,\n\tderiveRepresentationCandidates,\n} from \"./context-budget-headroom.ts\";\nimport {\n\tapplyRepresentationCacheV2,\n\ttype ContextBudgetSelectionCacheV2,\n\twriteRepresentationCacheV2,\n} from \"./context-budget-v2-cache.ts\";\nimport { recordContextBudgetRepresentationCacheHitV2 } from \"./context-budget-v2-cache-telemetry.ts\";\nimport { computeCoverageGap } from \"./context-budget-v2-coverage.ts\";\nimport { applyRedundancyPenalties, type PlannedItemV2 } from \"./context-budget-v2-scoring.ts\";\nimport {\n\tALL_TIERS_V2,\n\ttype QualityDiagnosticV2,\n\ttype SelectedRepresentationV2,\n\ttype TierBudgetAllocationV2,\n} from \"./context-budget-v2-types.ts\";\n\nexport interface OptionalSelectionState {\n\t/** Per-tier caps; `floor` is the tier's reservation, which the exchange pass must not raid. */\n\treadonly allocation: ReadonlyMap<ContextBudgetTierV2, { readonly ceiling: number; readonly floor?: number }>;\n\treadonly available: number;\n\treadonly cache?: ContextBudgetSelectionCacheV2;\n\treadonly diagnostics: QualityDiagnosticV2[];\n\treadonly omitted: ContextBudgetItemV2[];\n\treadonly qualityPolicy: Parameters<typeof chooseHeadroomRepresentation>[2];\n\treadonly retrievalFallbacks: ContextSourceRefV2[];\n\treadonly selection: Map<string, SelectedRepresentationV2>;\n\treadonly tierUsed: Record<ContextBudgetTierV2, number>;\n\treadonly usedTokens: number;\n\t/**\n\t * Floor-reservation pass state. When set and the item belongs to this\n\t * tier, the call admits it only while the tier's floor has headroom; an\n\t * item that cannot fit inside the remaining floor is left unselected\n\t * (never omitted) for the later global pass to reconsider under the\n\t * tier's ceiling.\n\t */\n\treadonly floorReservation?: { readonly tier: ContextBudgetTierV2; readonly floorTokens: number };\n\t/**\n\t * Cache-resolved candidates per item, shared across the floor and global\n\t * passes so one item does not double-count provider reads (negative hits,\n\t * stale rejects, misses) or repeat materialization work when it is\n\t * reconsidered.\n\t */\n\treadonly resolvedCandidates?: Map<string, readonly ContextRepresentationCandidateV2[]>;\n}\n\nexport function applyPlannerRedundancyPenalties(plannedItems: PlannedItemV2[]): void {\n\tconst penalties = applyRedundancyPenalties(plannedItems.filter((planned) => !planned.isHard));\n\tfor (const planned of plannedItems) {\n\t\tconst penalty = penalties.get(planned.item.id);\n\t\tif (penalty === undefined) continue;\n\t\tplanned.redundancyPenalty = penalty;\n\t\tplanned.effectiveScore = planned.baseScore - penalty;\n\t}\n}\n\nexport function selectHardItem(\n\tplanned: PlannedItemV2,\n\tselection: Map<string, SelectedRepresentationV2>,\n\ttierUsed: Record<ContextBudgetTierV2, number>,\n): number {\n\tconst candidate: ContextRepresentationCandidateV2 = {\n\t\tkind: \"full\",\n\t\ttext: planned.item.text,\n\t\testimatedTokens: planned.fullTokens,\n\t\tfidelity: planned.item.tokenEstimate !== undefined ? \"exact\" : \"bounded\",\n\t\tsourceRef: planned.item.sourceRef,\n\t};\n\tselection.set(planned.item.id, toSelected(planned.item.id, candidate));\n\ttierUsed[planned.item.tier] += planned.fullTokens;\n\treturn planned.fullTokens;\n}\n\nexport function selectOptionalItem(planned: PlannedItemV2, state: OptionalSelectionState): number {\n\tconst floorPass =\n\t\tstate.floorReservation !== undefined && planned.item.tier === state.floorReservation.tier\n\t\t\t? state.floorReservation\n\t\t\t: undefined;\n\tif (floorPass !== undefined && state.tierUsed[planned.item.tier] >= floorPass.floorTokens) {\n\t\t// This tier's guaranteed claim is already spent; leave the item for the\n\t\t// global pass rather than consuming another tier's budget.\n\t\treturn state.usedTokens;\n\t}\n\tif (state.usedTokens >= state.available) {\n\t\tif (floorPass === undefined) omitItem(planned, state);\n\t\treturn state.usedTokens;\n\t}\n\t// During the floor pass the binding cap is the tier's remaining floor;\n\t// afterwards the tier's ceiling (or the global remainder) applies.\n\tconst tierCeiling =\n\t\tfloorPass !== undefined\n\t\t\t? floorPass.floorTokens\n\t\t\t: (state.allocation.get(planned.item.tier)?.ceiling ?? state.available);\n\tconst remaining = Math.max(0, state.available - state.usedTokens);\n\t// Prefer the planner-priced candidates: re-deriving here with the default\n\t// heuristic would price the chosen text differently from the ranking cost.\n\tconst candidates =\n\t\tplanned.candidates ??\n\t\tplanned.item.representations ??\n\t\tderiveRepresentationCandidates(planned.item, state.qualityPolicy);\n\tconst materializedEnabled = planned.item.representations === undefined;\n\tlet cachedCandidates = state.resolvedCandidates?.get(planned.item.id);\n\tif (cachedCandidates === undefined) {\n\t\tcachedCandidates = state.cache\n\t\t\t? applyRepresentationCacheV2({ planned, candidates, cache: state.cache, materializedEnabled })\n\t\t\t: candidates;\n\t\tstate.resolvedCandidates?.set(planned.item.id, cachedCandidates);\n\t}\n\tconst chosen = chooseHeadroomRepresentation(\n\t\t{ ...planned.item, representations: cachedCandidates },\n\t\t{\n\t\t\ttierUsedTokens: state.tierUsed[planned.item.tier],\n\t\t\ttierCeilingTokens: tierCeiling,\n\t\t\tremainingGlobalTokens: remaining,\n\t\t},\n\t\tstate.qualityPolicy,\n\t);\n\tif (chosen.kind === \"omit\") {\n\t\tif (floorPass !== undefined) {\n\t\t\t// No admissible representation fits inside the remaining floor; the\n\t\t\t// global pass may still admit it against the tier's ceiling.\n\t\t\treturn state.usedTokens;\n\t\t}\n\t\tconst tierRemaining = Math.max(0, tierCeiling - state.tierUsed[planned.item.tier]);\n\t\tconst globalFit = cachedCandidates.filter(\n\t\t\t(candidate) => candidate.kind !== \"omit\" && candidate.estimatedTokens <= remaining,\n\t\t);\n\t\tif (globalFit.length > 0 && globalFit.every((candidate) => candidate.estimatedTokens > tierRemaining)) {\n\t\t\tstate.diagnostics.push({\n\t\t\t\treason: \"tier_ceiling_exceeded\",\n\t\t\t\titemId: planned.item.id,\n\t\t\t\tdetail: `${planned.item.tier} item \"${planned.item.id}\" needs ${Math.min(\n\t\t\t\t\t...globalFit.map((candidate) => candidate.estimatedTokens),\n\t\t\t\t)} tokens with ${tierRemaining} tier tokens remaining`,\n\t\t\t});\n\t\t}\n\t\tomitItem(planned, state);\n\t\treturn state.usedTokens;\n\t}\n\tif (state.tierUsed[planned.item.tier] + chosen.estimatedTokens > tierCeiling) {\n\t\tif (floorPass !== undefined) {\n\t\t\treturn state.usedTokens;\n\t\t}\n\t\tstate.diagnostics.push({\n\t\t\treason: \"tier_ceiling_exceeded\",\n\t\t\titemId: planned.item.id,\n\t\t\tdetail: `${planned.item.tier} item \"${planned.item.id}\" needs ${chosen.estimatedTokens} tokens with ${Math.max(0, tierCeiling - state.tierUsed[planned.item.tier])} tier tokens remaining`,\n\t\t});\n\t\tomitItem(planned, state);\n\t\treturn state.usedTokens;\n\t}\n\tif (state.usedTokens + chosen.estimatedTokens > state.available) {\n\t\tif (floorPass === undefined) omitItem(planned, state);\n\t\treturn state.usedTokens;\n\t}\n\tif (state.cache) {\n\t\tif (chosen.cache?.hit === true) {\n\t\t\trecordContextBudgetRepresentationCacheHitV2(\n\t\t\t\tstate.cache.telemetry,\n\t\t\t\tchosen.kind,\n\t\t\t\tchosen.cache.keyKind,\n\t\t\t\tplanned.fullTokens,\n\t\t\t);\n\t\t}\n\t\twriteRepresentationCacheV2({ planned, selected: chosen, cache: state.cache, materializedEnabled });\n\t}\n\tstate.selection.set(planned.item.id, toSelected(planned.item.id, chosen));\n\tstate.tierUsed[planned.item.tier] += chosen.estimatedTokens;\n\treturn state.usedTokens + chosen.estimatedTokens;\n}\n\nexport function emitOmissionDiagnostics(\n\tomitted: readonly ContextBudgetItemV2[],\n\tdiagnostics: QualityDiagnosticV2[],\n\tretrievalFallbacks: ContextSourceRefV2[],\n): void {\n\tfor (const item of omitted) {\n\t\tif (item.priority === \"high\" || item.required === true) {\n\t\t\tdiagnostics.push({\n\t\t\t\treason: \"omitted_high_priority\",\n\t\t\t\titemId: item.id,\n\t\t\t\tdetail: `${item.tier} item \"${item.id}\" could not fit within the prompt budget`,\n\t\t\t});\n\t\t}\n\t\tif (item.sourceRef?.retrievable) {\n\t\t\tdiagnostics.push({\n\t\t\t\treason: \"restore_on_demand_hint\",\n\t\t\t\titemId: item.id,\n\t\t\t\tdetail: `retrievable \"${item.id}\" kept as fallback via ${item.sourceRef.uri}`,\n\t\t\t});\n\t\t\tretrievalFallbacks.push(item.sourceRef);\n\t\t}\n\t}\n}\n\nexport function emitCoverageDiagnostics(\n\tquery: string | undefined,\n\tselection: ReadonlyMap<string, SelectedRepresentationV2>,\n\tdiagnostics: QualityDiagnosticV2[],\n): void {\n\tconst coverage = computeCoverageGap(\n\t\tquery,\n\t\t[...selection.values()].map((representation) => representation.text),\n\t);\n\tif (!coverage.gap) return;\n\tdiagnostics.push({\n\t\treason: \"coverage_gap\",\n\t\tdetail: `query terms not covered by selected context: ${coverage.missing.join(\", \")}`,\n\t});\n}\n\nexport function buildTierAllocations(\n\tallocation: ReadonlyMap<\n\t\tContextBudgetTierV2,\n\t\t{ readonly floor: number; readonly ceiling: number; readonly allocated: number }\n\t>,\n\tdemand: ReadonlyMap<ContextBudgetTierV2, { readonly hard: number }>,\n\ttierUsed: Record<ContextBudgetTierV2, number>,\n): TierBudgetAllocationV2[] {\n\treturn ALL_TIERS_V2.map((tier) => {\n\t\tconst raw = allocation.get(tier) ?? { floor: 0, ceiling: 0, allocated: 0 };\n\t\treturn {\n\t\t\ttier,\n\t\t\tfloorTokens: raw.floor,\n\t\t\tceilingTokens: raw.ceiling,\n\t\t\tallocatedTokens: raw.allocated,\n\t\t\tusedTokens: tierUsed[tier],\n\t\t\thardTokens: demand.get(tier)?.hard ?? 0,\n\t\t};\n\t});\n}\n\nexport function createTierUsage(): Record<ContextBudgetTierV2, number> {\n\treturn Object.fromEntries(ALL_TIERS_V2.map((tier) => [tier, 0])) as Record<ContextBudgetTierV2, number>;\n}\n\nexport function toSelected(itemId: string, candidate: ContextRepresentationCandidateV2): SelectedRepresentationV2 {\n\treturn {\n\t\titemId,\n\t\tkind: candidate.kind,\n\t\ttext: candidate.text,\n\t\testimatedTokens: candidate.estimatedTokens,\n\t\tfidelity: candidate.fidelity,\n\t\tsourceRef: candidate.sourceRef,\n\t\tsummaryHash: candidate.summaryHash,\n\t\tcompressorId: candidate.compressorId,\n\t\tcache: candidate.cache,\n\t};\n}\n\nfunction omitItem(\n\tplanned: PlannedItemV2,\n\tstate: Pick<OptionalSelectionState, \"diagnostics\" | \"omitted\" | \"retrievalFallbacks\">,\n): void {\n\tstate.omitted.push(planned.item);\n\tif (planned.item.sourceRef?.retrievable) {\n\t\tstate.diagnostics.push({\n\t\t\treason: \"retrieval_miss_risk\",\n\t\t\titemId: planned.item.id,\n\t\t\tdetail: `retrievable ${planned.item.tier} item \"${planned.item.id}\" omitted; keep pointer for restore-on-demand`,\n\t\t});\n\t\tstate.retrievalFallbacks.push(planned.item.sourceRef);\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-budget-v2-tiers.d.ts","sourceRoot":"","sources":["../../src/core/context-budget-v2-tiers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAgB,KAAK,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAErF,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC3B;AAED,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,SAAS,aAAa,EAAE,GAAG,GAAG,CAAC,mBAAmB,EAAE,aAAa,CAAC,CAajH;AAED,wBAAgB,aAAa,CAC5B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,CAAC,EACjE,MAAM,EAAE,GAAG,CAAC,mBAAmB,EAAE,aAAa,CAAC,GAC7C,GAAG,CAAC,mBAAmB,EAAE,iBAAiB,CAAC,
|
|
1
|
+
{"version":3,"file":"context-budget-v2-tiers.d.ts","sourceRoot":"","sources":["../../src/core/context-budget-v2-tiers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAgB,KAAK,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAErF,MAAM,WAAW,aAAa;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC3B;AAED,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,SAAS,aAAa,EAAE,GAAG,GAAG,CAAC,mBAAmB,EAAE,aAAa,CAAC,CAajH;AAED,wBAAgB,aAAa,CAC5B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,CAAC,EACjE,MAAM,EAAE,GAAG,CAAC,mBAAmB,EAAE,aAAa,CAAC,GAC7C,GAAG,CAAC,mBAAmB,EAAE,iBAAiB,CAAC,CAmB7C","sourcesContent":["import type { ContextBudgetTierV2 } from \"./context-budget-headroom.ts\";\nimport type { PlannedItemV2 } from \"./context-budget-v2-scoring.ts\";\nimport { ALL_TIERS_V2, type TierBudgetPolicyV2 } from \"./context-budget-v2-types.ts\";\n\nexport interface RawTierDemand {\n\treadonly demand: number;\n\treadonly hard: number;\n}\n\nexport interface RawTierAllocation {\n\treadonly floor: number;\n\treadonly ceiling: number;\n\treadonly allocated: number;\n}\n\nexport function computeTierDemand(plannedItems: readonly PlannedItemV2[]): Map<ContextBudgetTierV2, RawTierDemand> {\n\tconst demand = new Map<ContextBudgetTierV2, RawTierDemand>();\n\tfor (const tier of ALL_TIERS_V2) {\n\t\tdemand.set(tier, { demand: 0, hard: 0 });\n\t}\n\tfor (const planned of plannedItems) {\n\t\tconst entry = demand.get(planned.item.tier) ?? { demand: 0, hard: 0 };\n\t\tdemand.set(planned.item.tier, {\n\t\t\tdemand: entry.demand + planned.fullTokens,\n\t\t\thard: entry.hard + (planned.isHard ? planned.fullTokens : 0),\n\t\t});\n\t}\n\treturn demand;\n}\n\nexport function allocateTiers(\n\tavailable: number,\n\tpolicy: Readonly<Record<ContextBudgetTierV2, TierBudgetPolicyV2>>,\n\tdemand: Map<ContextBudgetTierV2, RawTierDemand>,\n): Map<ContextBudgetTierV2, RawTierAllocation> {\n\tconst out = new Map<ContextBudgetTierV2, RawTierAllocation>();\n\n\tfor (const tier of ALL_TIERS_V2) {\n\t\tconst floor = Math.max(0, Math.floor(policy[tier].floorPct * available));\n\t\tconst ceiling = Math.max(floor, Math.floor(policy[tier].ceilingPct * available));\n\t\tconst entry = demand.get(tier) ?? { demand: 0, hard: 0 };\n\t\tconst want = Math.max(entry.demand, entry.hard);\n\t\t// `allocated` is the tier's guaranteed claim — what the floor pass is\n\t\t// entitled to spend on this tier's own items before global competition:\n\t\t// its hard demand (always admitted) or, beyond that, its demand capped\n\t\t// at the floor. The previous residual-redistribution loop could never\n\t\t// move this number on normal input (min(want, max(ceiling, hard)) makes\n\t\t// want-allocated or ceiling-allocated zero), so it is removed rather\n\t\t// than kept as dead code. Leftover budget competes globally in the\n\t\t// ceiling-bounded selection pass instead.\n\t\tout.set(tier, { floor, ceiling, allocated: Math.min(want, Math.max(floor, entry.hard)) });\n\t}\n\treturn out;\n}\n"]}
|
|
@@ -15,54 +15,21 @@ export function computeTierDemand(plannedItems) {
|
|
|
15
15
|
}
|
|
16
16
|
export function allocateTiers(available, policy, demand) {
|
|
17
17
|
const out = new Map();
|
|
18
|
-
const floors = {};
|
|
19
|
-
const ceilings = {};
|
|
20
|
-
const wants = {};
|
|
21
18
|
for (const tier of ALL_TIERS_V2) {
|
|
22
19
|
const floor = Math.max(0, Math.floor(policy[tier].floorPct * available));
|
|
23
20
|
const ceiling = Math.max(floor, Math.floor(policy[tier].ceilingPct * available));
|
|
24
21
|
const entry = demand.get(tier) ?? { demand: 0, hard: 0 };
|
|
25
22
|
const want = Math.max(entry.demand, entry.hard);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
let residual = available - totalAllocated;
|
|
36
|
-
if (residual <= 0) {
|
|
37
|
-
return out;
|
|
38
|
-
}
|
|
39
|
-
const shortfalls = collectShortfalls(out, wants);
|
|
40
|
-
const totalGap = shortfalls.reduce((sum, shortfall) => sum + shortfall.gap, 0);
|
|
41
|
-
if (totalGap <= 0) {
|
|
42
|
-
return out;
|
|
43
|
-
}
|
|
44
|
-
for (const { tier, gap } of shortfalls) {
|
|
45
|
-
const share = Math.min(gap, Math.floor((residual * gap) / totalGap));
|
|
46
|
-
if (share <= 0)
|
|
47
|
-
continue;
|
|
48
|
-
const entry = out.get(tier);
|
|
49
|
-
if (!entry)
|
|
50
|
-
continue;
|
|
51
|
-
out.set(tier, { ...entry, allocated: entry.allocated + share });
|
|
52
|
-
residual -= share;
|
|
23
|
+
// `allocated` is the tier's guaranteed claim — what the floor pass is
|
|
24
|
+
// entitled to spend on this tier's own items before global competition:
|
|
25
|
+
// its hard demand (always admitted) or, beyond that, its demand capped
|
|
26
|
+
// at the floor. The previous residual-redistribution loop could never
|
|
27
|
+
// move this number on normal input (min(want, max(ceiling, hard)) makes
|
|
28
|
+
// want-allocated or ceiling-allocated zero), so it is removed rather
|
|
29
|
+
// than kept as dead code. Leftover budget competes globally in the
|
|
30
|
+
// ceiling-bounded selection pass instead.
|
|
31
|
+
out.set(tier, { floor, ceiling, allocated: Math.min(want, Math.max(floor, entry.hard)) });
|
|
53
32
|
}
|
|
54
33
|
return out;
|
|
55
34
|
}
|
|
56
|
-
function collectShortfalls(allocations, wants) {
|
|
57
|
-
const shortfalls = [];
|
|
58
|
-
for (const tier of ALL_TIERS_V2) {
|
|
59
|
-
const entry = allocations.get(tier);
|
|
60
|
-
if (!entry)
|
|
61
|
-
continue;
|
|
62
|
-
const gap = Math.min(Math.max(0, wants[tier] - entry.allocated), Math.max(0, entry.ceiling - entry.allocated));
|
|
63
|
-
if (gap > 0)
|
|
64
|
-
shortfalls.push({ tier, gap });
|
|
65
|
-
}
|
|
66
|
-
return shortfalls;
|
|
67
|
-
}
|
|
68
35
|
//# sourceMappingURL=context-budget-v2-tiers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-budget-v2-tiers.js","sourceRoot":"","sources":["../../src/core/context-budget-v2-tiers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAA2B,MAAM,8BAA8B,CAAC;AAarF,MAAM,UAAU,iBAAiB,CAAC,YAAsC,EAA2C;IAClH,MAAM,MAAM,GAAG,IAAI,GAAG,EAAsC,CAAC;IAC7D,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QACjC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;IAC1C,CAAC;IACD,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;QACpC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QACtE,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE;YAC7B,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,UAAU;YACzC,IAAI,EAAE,KAAK,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;SAC5D,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAAA,CACd;AAED,MAAM,UAAU,aAAa,CAC5B,SAAiB,EACjB,MAAi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EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC;QACzE,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC;QACjF,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QAChD,wEAAsE;QACtE,wEAAwE;QACxE,uEAAuE;QACvE,sEAAsE;QACtE,wEAAwE;QACxE,qEAAqE;QACrE,mEAAmE;QACnE,0CAA0C;QAC1C,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;IAC3F,CAAC;IACD,OAAO,GAAG,CAAC;AAAA,CACX","sourcesContent":["import type { ContextBudgetTierV2 } from \"./context-budget-headroom.ts\";\nimport type { PlannedItemV2 } from \"./context-budget-v2-scoring.ts\";\nimport { ALL_TIERS_V2, type TierBudgetPolicyV2 } from \"./context-budget-v2-types.ts\";\n\nexport interface RawTierDemand {\n\treadonly demand: number;\n\treadonly hard: number;\n}\n\nexport interface RawTierAllocation {\n\treadonly floor: number;\n\treadonly ceiling: number;\n\treadonly allocated: number;\n}\n\nexport function computeTierDemand(plannedItems: readonly PlannedItemV2[]): Map<ContextBudgetTierV2, RawTierDemand> {\n\tconst demand = new Map<ContextBudgetTierV2, RawTierDemand>();\n\tfor (const tier of ALL_TIERS_V2) {\n\t\tdemand.set(tier, { demand: 0, hard: 0 });\n\t}\n\tfor (const planned of plannedItems) {\n\t\tconst entry = demand.get(planned.item.tier) ?? { demand: 0, hard: 0 };\n\t\tdemand.set(planned.item.tier, {\n\t\t\tdemand: entry.demand + planned.fullTokens,\n\t\t\thard: entry.hard + (planned.isHard ? planned.fullTokens : 0),\n\t\t});\n\t}\n\treturn demand;\n}\n\nexport function allocateTiers(\n\tavailable: number,\n\tpolicy: Readonly<Record<ContextBudgetTierV2, TierBudgetPolicyV2>>,\n\tdemand: Map<ContextBudgetTierV2, RawTierDemand>,\n): Map<ContextBudgetTierV2, RawTierAllocation> {\n\tconst out = new Map<ContextBudgetTierV2, RawTierAllocation>();\n\n\tfor (const tier of ALL_TIERS_V2) {\n\t\tconst floor = Math.max(0, Math.floor(policy[tier].floorPct * available));\n\t\tconst ceiling = Math.max(floor, Math.floor(policy[tier].ceilingPct * available));\n\t\tconst entry = demand.get(tier) ?? { demand: 0, hard: 0 };\n\t\tconst want = Math.max(entry.demand, entry.hard);\n\t\t// `allocated` is the tier's guaranteed claim — what the floor pass is\n\t\t// entitled to spend on this tier's own items before global competition:\n\t\t// its hard demand (always admitted) or, beyond that, its demand capped\n\t\t// at the floor. The previous residual-redistribution loop could never\n\t\t// move this number on normal input (min(want, max(ceiling, hard)) makes\n\t\t// want-allocated or ceiling-allocated zero), so it is removed rather\n\t\t// than kept as dead code. Leftover budget competes globally in the\n\t\t// ceiling-bounded selection pass instead.\n\t\tout.set(tier, { floor, ceiling, allocated: Math.min(want, Math.max(floor, entry.hard)) });\n\t}\n\treturn out;\n}\n"]}
|
|
@@ -15,8 +15,13 @@ export declare const CONTEXT_BUDGET_POLICY_VERSION_V2 = "context-budget-v2";
|
|
|
15
15
|
*
|
|
16
16
|
* `sel-2`: density-ordered selection over the cheapest admissible representation
|
|
17
17
|
* (previously priority-class-ordered over full-text tokens).
|
|
18
|
+
* `sel-3`: derived representations are priced by counting their materialized
|
|
19
|
+
* text with the planner's counter; the summary ratio is no longer a cost, so
|
|
20
|
+
* plans cached under `sel-2` carry under-priced summaries and must not be served.
|
|
21
|
+
* The same token covers the exchange and promotion passes added alongside it,
|
|
22
|
+
* which change the selected set for identical inputs.
|
|
18
23
|
*/
|
|
19
|
-
export declare const CONTEXT_BUDGET_SELECTION_POLICY_V2 = "sel-
|
|
24
|
+
export declare const CONTEXT_BUDGET_SELECTION_POLICY_V2 = "sel-3";
|
|
20
25
|
/** Fixed compatibility telemetry for the removed legacy token optimizer. */
|
|
21
26
|
export interface TokenOptimizerRuntimeStatus {
|
|
22
27
|
readonly optimizerId: "legacy-token-optimizer";
|
|
@@ -26,7 +31,14 @@ export interface TokenOptimizerRuntimeStatus {
|
|
|
26
31
|
readonly compatibilityOnly: true;
|
|
27
32
|
}
|
|
28
33
|
export interface TierBudgetPolicyV2 {
|
|
34
|
+
/**
|
|
35
|
+
* Guaranteed share of the available budget the floor-reservation pass
|
|
36
|
+
* spends on this tier's own items before leftovers compete globally.
|
|
37
|
+
* A real reservation — not merely a lower bound on the ceiling — so a
|
|
38
|
+
* higher-scored item in another tier cannot starve this tier's minimum.
|
|
39
|
+
*/
|
|
29
40
|
readonly floorPct: number;
|
|
41
|
+
/** Hard cap on this tier's share; selection above it is omitted. */
|
|
30
42
|
readonly ceilingPct: number;
|
|
31
43
|
}
|
|
32
44
|
export declare const DEFAULT_TIER_POLICY_V2: Readonly<Record<ContextBudgetTierV2, TierBudgetPolicyV2>>;
|
|
@@ -75,7 +87,7 @@ export interface TierBudgetAllocationV2 {
|
|
|
75
87
|
readonly usedTokens: number;
|
|
76
88
|
readonly hardTokens: number;
|
|
77
89
|
}
|
|
78
|
-
export type QualityDiagnosticReasonV2 = "omitted_high_priority" | "retrieval_miss_risk" | "restore_on_demand_hint" | "hard_pin_over_capacity" | "coverage_gap" | "tier_ceiling_exceeded" | "invalid_budget";
|
|
90
|
+
export type QualityDiagnosticReasonV2 = "omitted_high_priority" | "retrieval_miss_risk" | "restore_on_demand_hint" | "hard_pin_over_capacity" | "coverage_gap" | "tier_ceiling_exceeded" | "tier_floor_over_budget" | "invalid_input" | "invalid_budget";
|
|
79
91
|
export interface QualityDiagnosticV2 {
|
|
80
92
|
readonly reason: QualityDiagnosticReasonV2;
|
|
81
93
|
readonly itemId?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-budget-v2-types.d.ts","sourceRoot":"","sources":["../../src/core/context-budget-v2-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,mBAAmB,EACnB,mBAAmB,EACnB,oCAAoC,EACpC,gCAAgC,EAChC,2BAA2B,EAC3B,kBAAkB,EAClB,uBAAuB,EACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,2CAA2C,CAAC;AAElG;;;GAGG;AACH,eAAO,MAAM,gCAAgC,sBAAsB,CAAC;AAEpE;;;;;;;;;GASG;AACH,eAAO,MAAM,kCAAkC,UAAU,CAAC;AAE1D,4EAA4E;AAC5E,MAAM,WAAW,2BAA2B;IAC3C,QAAQ,CAAC,WAAW,EAAE,wBAAwB,CAAC;IAC/C,QAAQ,CAAC,MAAM,EAAE,2BAA2B,CAAC;IAC7C,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,4BAA4B,EAAE,mBAAmB,CAAC;IAC3D,QAAQ,CAAC,iBAAiB,EAAE,IAAI,CAAC;CACjC;AAED,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,CAU5F,CAAC;AAEF,eAAO,MAAM,YAAY,EAA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SourceRefV2,\n\tHeadroomQualityPolicyV2,\n} from \"./context-budget-headroom.ts\";\nimport type { TokenCounterAdapter } from \"./context-budget-token-counter.ts\";\nimport type { ContextCacheInvalidationSnapshot } from \"./context-budget-v2-cache-invalidation.ts\";\n\n/**\n * Public optimizer identifier. It is reported in the system prompt and used as a\n * cache namespace, so it must stay stable across internal policy changes.\n */\nexport const CONTEXT_BUDGET_POLICY_VERSION_V2 = \"context-budget-v2\";\n\n/**\n * Internal token for the optional-item selection policy, kept separate from the\n * public identifier so a scoring or ordering change can invalidate cached plans\n * without renaming the optimizer. Bump it whenever the selected set can differ\n * for identical inputs; otherwise plans built under the previous policy keep\n * being served for the whole cache TTL, including from disk.\n *\n * `sel-2`: density-ordered selection over the cheapest admissible representation\n * (previously priority-class-ordered over full-text tokens).\n */\nexport const CONTEXT_BUDGET_SELECTION_POLICY_V2 = \"sel-2\";\n\n/** Fixed compatibility telemetry for the removed legacy token optimizer. */\nexport interface TokenOptimizerRuntimeStatus {\n\treadonly optimizerId: \"legacy-token-optimizer\";\n\treadonly status: \"quarantined_compatibility\";\n\treadonly active: false;\n\treadonly activeContextBudgetOptimizer: \"context-budget-v2\";\n\treadonly compatibilityOnly: true;\n}\n\nexport interface TierBudgetPolicyV2 {\n\treadonly floorPct: number;\n\treadonly ceilingPct: number;\n}\n\nexport const DEFAULT_TIER_POLICY_V2: Readonly<Record<ContextBudgetTierV2, TierBudgetPolicyV2>> = {\n\tsystem: { floorPct: 0.25, ceilingPct: 0.45 },\n\t\"active-goal\": { floorPct: 0.1, ceilingPct: 0.25 },\n\t\"current-files\": { floorPct: 0.08, ceilingPct: 0.2 },\n\ttools: { floorPct: 0.04, ceilingPct: 0.12 },\n\tskills: { floorPct: 0.03, ceilingPct: 0.12 },\n\tmcp: { floorPct: 0.02, ceilingPct: 0.08 },\n\thistory: { floorPct: 0.1, ceilingPct: 0.3 },\n\tevidence: { floorPct: 0.08, ceilingPct: 0.25 },\n\tscratch: { floorPct: 0, ceilingPct: 0.05 },\n};\n\nexport const ALL_TIERS_V2: readonly ContextBudgetTierV2[] = [\n\t\"system\",\n\t\"active-goal\",\n\t\"current-files\",\n\t\"tools\",\n\t\"skills\",\n\t\"mcp\",\n\t\"history\",\n\t\"evidence\",\n\t\"scratch\",\n];\n\nexport interface PromptContextBudgetInputV2 {\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens?: number;\n\treadonly safetyMarginTokens?: number;\n\treadonly modelId?: string;\n\treadonly tokenizerId?: string;\n\treadonly policyVersion?: string;\n\t/** Overrides {@link CONTEXT_BUDGET_SELECTION_POLICY_V2}. */\n\treadonly selectionPolicyVersion?: string;\n\treadonly promptHash?: string;\n\treadonly query?: string;\n\treadonly items: readonly ContextBudgetItemV2[];\n\treadonly tokenCounter?: TokenCounterAdapter;\n\treadonly tierPolicy?: Partial<Record<ContextBudgetTierV2, TierBudgetPolicyV2>>;\n\treadonly qualityPolicy?: HeadroomQualityPolicyV2;\n\treadonly cacheProvider?: ContextBudgetCacheProviderV2;\n\treadonly cacheNamespace?: string;\n\treadonly queryIntentHash?: string;\n\treadonly cacheBudgetBucket?: string;\n\treadonly redactionPolicyHash?: string;\n\treadonly safetyProfileHash?: string;\n\treadonly cacheNowEpochMs?: number;\n\treadonly cacheTtlMs?: number;\n\treadonly cacheInvalidationSnapshot?: ContextCacheInvalidationSnapshot;\n}\n\nexport interface SelectedRepresentationV2 {\n\treadonly itemId: string;\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly cache?: ContextRepresentationCacheMetadataV2;\n}\n\nexport interface TierBudgetAllocationV2 {\n\treadonly tier: ContextBudgetTierV2;\n\treadonly floorTokens: number;\n\treadonly ceilingTokens: number;\n\treadonly allocatedTokens: number;\n\treadonly usedTokens: number;\n\treadonly hardTokens: number;\n}\n\nexport type QualityDiagnosticReasonV2 =\n\t| \"omitted_high_priority\"\n\t| \"retrieval_miss_risk\"\n\t| \"restore_on_demand_hint\"\n\t| \"hard_pin_over_capacity\"\n\t| \"coverage_gap\"\n\t| \"tier_ceiling_exceeded\"\n\t| \"invalid_budget\";\n\nexport interface QualityDiagnosticV2 {\n\treadonly reason: QualityDiagnosticReasonV2;\n\treadonly itemId?: string;\n\treadonly detail: string;\n}\n\nexport interface ContextBudgetObservabilityCountsV2 {\n\treadonly selected: number;\n\treadonly omitted: number;\n\treadonly pointer: number;\n\treadonly compressed: number;\n\treadonly full: number;\n\treadonly retrievalFallback: number;\n}\n\nexport interface ContextBudgetObservabilityTokensV2 {\n\treadonly available: number;\n\treadonly used: number;\n\treadonly raw: number;\n\treadonly omitted: number;\n\treadonly tokenSavings: number;\n}\n\nexport type ContextBudgetCacheLayerV2 = \"turn\" | \"session\" | \"workspace\" | \"shared\";\n\nexport type ContextBudgetRepresentationCacheRejectReasonV2 =\n\t| \"fingerprint_mismatch\"\n\t| \"kind_mismatch\"\n\t| \"model_mismatch\"\n\t| \"negative\"\n\t| \"policy_mismatch\"\n\t| \"poisoned\"\n\t| \"source_hash_mismatch\"\n\t| \"stale\"\n\t| \"token_invalid\"\n\t| \"tokenizer_mismatch\";\n\nexport type ContextBudgetRepresentationCacheKeyKindV2 = \"exact\" | \"materialized\";\n\nexport interface ContextBudgetMaterializedVerificationV2 {\n\treadonly queryCoverage?: number;\n\treadonly sourceCoverage?: number;\n\treadonly secretLeakScore?: number;\n\treadonly poisonScore?: number;\n\treadonly validatorVersion?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheEntryV2 {\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceHash: string;\n\treadonly representationFingerprint: string;\n\treadonly keyKind?: ContextBudgetRepresentationCacheKeyKindV2;\n\treadonly modelId: string;\n\treadonly tokenizerId: string;\n\treadonly policyVersion: string;\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly compressorPolicyHash?: string;\n\treadonly qualityPolicyHash?: string;\n\treadonly queryIntentCluster?: string;\n\treadonly outputTextHash?: string;\n\treadonly targetTokenBucket?: number;\n\treadonly verification?: ContextBudgetMaterializedVerificationV2;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetRepresentationCacheReadV2 {\n\treadonly entry: ContextBudgetRepresentationCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetNegativeCacheEntryV2 {\n\treadonly reason: string;\n\treadonly createdAtEpochMs?: number;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetPlanCacheEntryV2 {\n\treadonly plan: PromptContextBudgetPlanV2;\n\treadonly sourceHashes: Readonly<Record<string, string>>;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetPlanCacheReadV2 {\n\treadonly entry: ContextBudgetPlanCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetCacheProviderV2 {\n\tgetInvalidationSnapshot?(): ContextCacheInvalidationSnapshot | undefined;\n\tsetInvalidationSnapshot?(snapshot: ContextCacheInvalidationSnapshot): void;\n\treadRepresentation(key: string): ContextBudgetRepresentationCacheReadV2 | undefined;\n\twriteRepresentation(input: { readonly key: string; readonly entry: ContextBudgetRepresentationCacheEntryV2 }): void;\n\tdeleteRepresentation?(key: string): void;\n\treadNegativeRepresentation(key: string): ContextBudgetNegativeCacheEntryV2 | undefined;\n\twriteNegativeRepresentation(input: { readonly key: string; readonly reason: string }): void;\n\tdeleteNegativeRepresentation?(key: string): void;\n\treadPlan(key: string): ContextBudgetPlanCacheReadV2 | undefined;\n\twritePlan(input: { readonly key: string; readonly entry: ContextBudgetPlanCacheEntryV2 }): void;\n\tdeletePlan?(key: string): void;\n}\n\nexport interface ContextBudgetPlanCacheTelemetryV2 {\n\treadonly hit: boolean;\n\treadonly key: string;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n\treadonly rejectedReason?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheTelemetryV2 {\n\treadonly exactHits: number;\n\treadonly semanticHits: number;\n\treadonly pointerHits: number;\n\treadonly misses: number;\n\treadonly staleRejects: number;\n\treadonly poisonRejects: number;\n\treadonly negativeHits: number;\n\treadonly writes: number;\n}\n\nexport interface ContextBudgetCacheTokenTelemetryV2 {\n\treadonly raw: number;\n\treadonly rendered: number;\n\treadonly savedByCache: number;\n\treadonly savedByCompression: number;\n\treadonly savedByOmission: number;\n}\n\nexport interface TokenCacheTelemetryV2 {\n\treadonly planCache: ContextBudgetPlanCacheTelemetryV2;\n\treadonly representationCache: ContextBudgetRepresentationCacheTelemetryV2;\n\treadonly tokens: ContextBudgetCacheTokenTelemetryV2;\n}\n\nexport interface PromptContextBudgetObservabilityV2 {\n\treadonly counts: ContextBudgetObservabilityCountsV2;\n\treadonly diagnosticReasons: readonly QualityDiagnosticReasonV2[];\n\treadonly tokens: ContextBudgetObservabilityTokensV2;\n\treadonly planHash: string;\n\treadonly cache: TokenCacheTelemetryV2;\n\treadonly tokenOptimizer: TokenOptimizerRuntimeStatus;\n}\n\nexport interface PromptContextBudgetPlanV2 {\n\treadonly policyVersion: string;\n\treadonly promptHash?: string;\n\treadonly planHash: string;\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens: number;\n\treadonly safetyMarginTokens: number;\n\treadonly availableTokens: number;\n\treadonly usedTokens: number;\n\treadonly omittedTokens: number;\n\treadonly rawTokens: number;\n\treadonly tokenSavingsRatio: number;\n\treadonly emergency: boolean;\n\treadonly omittedHighPriority: boolean;\n\treadonly tierAllocations: readonly TierBudgetAllocationV2[];\n\treadonly selectedRepresentations: readonly SelectedRepresentationV2[];\n\treadonly includedItemIds: readonly string[];\n\treadonly omittedItemIds: readonly string[];\n\treadonly diagnostics: readonly QualityDiagnosticV2[];\n\treadonly retrievalFallbacks: readonly ContextSourceRefV2[];\n\treadonly observability: PromptContextBudgetObservabilityV2;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"context-budget-v2-types.d.ts","sourceRoot":"","sources":["../../src/core/context-budget-v2-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,mBAAmB,EACnB,mBAAmB,EACnB,oCAAoC,EACpC,gCAAgC,EAChC,2BAA2B,EAC3B,kBAAkB,EAClB,uBAAuB,EACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,2CAA2C,CAAC;AAElG;;;GAGG;AACH,eAAO,MAAM,gCAAgC,sBAAsB,CAAC;AAEpE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,kCAAkC,UAAU,CAAC;AAE1D,4EAA4E;AAC5E,MAAM,WAAW,2BAA2B;IAC3C,QAAQ,CAAC,WAAW,EAAE,wBAAwB,CAAC;IAC/C,QAAQ,CAAC,MAAM,EAAE,2BAA2B,CAAC;IAC7C,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,4BAA4B,EAAE,mBAAmB,CAAC;IAC3D,QAAQ,CAAC,iBAAiB,EAAE,IAAI,CAAC;CACjC;AAED,MAAM,WAAW,kBAAkB;IAClC;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,oEAAoE;IACpE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,mBAAmB,EAAE,kBAAkB,CAAC,CAU5F,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,SAAS,mBAAmB,EAUtD,CAAC;AAEF,MAAM,WAAW,0BAA0B;IAC1C,Q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ACtC,QAAQ,CAAC,cAAc,EAAE,2BAA2B,CAAC;CACrD;AAED,MAAM,WAAW,yBAAyB;IACzC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,mBAAmB,EAAE,OAAO,CAAC;IACtC,QAAQ,CAAC,eAAe,EAAE,SAAS,sBAAsB,EAAE,CAAC;IAC5D,QAAQ,CAAC,uBAAuB,EAAE,SAAS,wBAAwB,EAAE,CAAC;IACtE,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,QAAQ,CAAC,WAAW,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACrD,QAAQ,CAAC,kBAAkB,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAC3D,QAAQ,CAAC,aAAa,EAAE,kCAAkC,CAAC;CAC3D","sourcesContent":["import type {\n\tContextBudgetItemV2,\n\tContextBudgetTierV2,\n\tContextRepresentationCacheMetadataV2,\n\tContextRepresentationCandidateV2,\n\tContextRepresentationKindV2,\n\tContextSourceRefV2,\n\tHeadroomQualityPolicyV2,\n} from \"./context-budget-headroom.ts\";\nimport type { TokenCounterAdapter } from \"./context-budget-token-counter.ts\";\nimport type { ContextCacheInvalidationSnapshot } from \"./context-budget-v2-cache-invalidation.ts\";\n\n/**\n * Public optimizer identifier. It is reported in the system prompt and used as a\n * cache namespace, so it must stay stable across internal policy changes.\n */\nexport const CONTEXT_BUDGET_POLICY_VERSION_V2 = \"context-budget-v2\";\n\n/**\n * Internal token for the optional-item selection policy, kept separate from the\n * public identifier so a scoring or ordering change can invalidate cached plans\n * without renaming the optimizer. Bump it whenever the selected set can differ\n * for identical inputs; otherwise plans built under the previous policy keep\n * being served for the whole cache TTL, including from disk.\n *\n * `sel-2`: density-ordered selection over the cheapest admissible representation\n * (previously priority-class-ordered over full-text tokens).\n * `sel-3`: derived representations are priced by counting their materialized\n * text with the planner's counter; the summary ratio is no longer a cost, so\n * plans cached under `sel-2` carry under-priced summaries and must not be served.\n * The same token covers the exchange and promotion passes added alongside it,\n * which change the selected set for identical inputs.\n */\nexport const CONTEXT_BUDGET_SELECTION_POLICY_V2 = \"sel-3\";\n\n/** Fixed compatibility telemetry for the removed legacy token optimizer. */\nexport interface TokenOptimizerRuntimeStatus {\n\treadonly optimizerId: \"legacy-token-optimizer\";\n\treadonly status: \"quarantined_compatibility\";\n\treadonly active: false;\n\treadonly activeContextBudgetOptimizer: \"context-budget-v2\";\n\treadonly compatibilityOnly: true;\n}\n\nexport interface TierBudgetPolicyV2 {\n\t/**\n\t * Guaranteed share of the available budget the floor-reservation pass\n\t * spends on this tier's own items before leftovers compete globally.\n\t * A real reservation — not merely a lower bound on the ceiling — so a\n\t * higher-scored item in another tier cannot starve this tier's minimum.\n\t */\n\treadonly floorPct: number;\n\t/** Hard cap on this tier's share; selection above it is omitted. */\n\treadonly ceilingPct: number;\n}\n\nexport const DEFAULT_TIER_POLICY_V2: Readonly<Record<ContextBudgetTierV2, TierBudgetPolicyV2>> = {\n\tsystem: { floorPct: 0.25, ceilingPct: 0.45 },\n\t\"active-goal\": { floorPct: 0.1, ceilingPct: 0.25 },\n\t\"current-files\": { floorPct: 0.08, ceilingPct: 0.2 },\n\ttools: { floorPct: 0.04, ceilingPct: 0.12 },\n\tskills: { floorPct: 0.03, ceilingPct: 0.12 },\n\tmcp: { floorPct: 0.02, ceilingPct: 0.08 },\n\thistory: { floorPct: 0.1, ceilingPct: 0.3 },\n\tevidence: { floorPct: 0.08, ceilingPct: 0.25 },\n\tscratch: { floorPct: 0, ceilingPct: 0.05 },\n};\n\nexport const ALL_TIERS_V2: readonly ContextBudgetTierV2[] = [\n\t\"system\",\n\t\"active-goal\",\n\t\"current-files\",\n\t\"tools\",\n\t\"skills\",\n\t\"mcp\",\n\t\"history\",\n\t\"evidence\",\n\t\"scratch\",\n];\n\nexport interface PromptContextBudgetInputV2 {\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens?: number;\n\treadonly safetyMarginTokens?: number;\n\treadonly modelId?: string;\n\treadonly tokenizerId?: string;\n\treadonly policyVersion?: string;\n\t/** Overrides {@link CONTEXT_BUDGET_SELECTION_POLICY_V2}. */\n\treadonly selectionPolicyVersion?: string;\n\treadonly promptHash?: string;\n\treadonly query?: string;\n\treadonly items: readonly ContextBudgetItemV2[];\n\treadonly tokenCounter?: TokenCounterAdapter;\n\treadonly tierPolicy?: Partial<Record<ContextBudgetTierV2, TierBudgetPolicyV2>>;\n\treadonly qualityPolicy?: HeadroomQualityPolicyV2;\n\treadonly cacheProvider?: ContextBudgetCacheProviderV2;\n\treadonly cacheNamespace?: string;\n\treadonly queryIntentHash?: string;\n\treadonly cacheBudgetBucket?: string;\n\treadonly redactionPolicyHash?: string;\n\treadonly safetyProfileHash?: string;\n\treadonly cacheNowEpochMs?: number;\n\treadonly cacheTtlMs?: number;\n\treadonly cacheInvalidationSnapshot?: ContextCacheInvalidationSnapshot;\n}\n\nexport interface SelectedRepresentationV2 {\n\treadonly itemId: string;\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly cache?: ContextRepresentationCacheMetadataV2;\n}\n\nexport interface TierBudgetAllocationV2 {\n\treadonly tier: ContextBudgetTierV2;\n\treadonly floorTokens: number;\n\treadonly ceilingTokens: number;\n\treadonly allocatedTokens: number;\n\treadonly usedTokens: number;\n\treadonly hardTokens: number;\n}\n\nexport type QualityDiagnosticReasonV2 =\n\t| \"omitted_high_priority\"\n\t| \"retrieval_miss_risk\"\n\t| \"restore_on_demand_hint\"\n\t| \"hard_pin_over_capacity\"\n\t| \"coverage_gap\"\n\t| \"tier_ceiling_exceeded\"\n\t| \"tier_floor_over_budget\"\n\t| \"invalid_input\"\n\t| \"invalid_budget\";\n\nexport interface QualityDiagnosticV2 {\n\treadonly reason: QualityDiagnosticReasonV2;\n\treadonly itemId?: string;\n\treadonly detail: string;\n}\n\nexport interface ContextBudgetObservabilityCountsV2 {\n\treadonly selected: number;\n\treadonly omitted: number;\n\treadonly pointer: number;\n\treadonly compressed: number;\n\treadonly full: number;\n\treadonly retrievalFallback: number;\n}\n\nexport interface ContextBudgetObservabilityTokensV2 {\n\treadonly available: number;\n\treadonly used: number;\n\treadonly raw: number;\n\treadonly omitted: number;\n\treadonly tokenSavings: number;\n}\n\nexport type ContextBudgetCacheLayerV2 = \"turn\" | \"session\" | \"workspace\" | \"shared\";\n\nexport type ContextBudgetRepresentationCacheRejectReasonV2 =\n\t| \"fingerprint_mismatch\"\n\t| \"kind_mismatch\"\n\t| \"model_mismatch\"\n\t| \"negative\"\n\t| \"policy_mismatch\"\n\t| \"poisoned\"\n\t| \"source_hash_mismatch\"\n\t| \"stale\"\n\t| \"token_invalid\"\n\t| \"tokenizer_mismatch\";\n\nexport type ContextBudgetRepresentationCacheKeyKindV2 = \"exact\" | \"materialized\";\n\nexport interface ContextBudgetMaterializedVerificationV2 {\n\treadonly queryCoverage?: number;\n\treadonly sourceCoverage?: number;\n\treadonly secretLeakScore?: number;\n\treadonly poisonScore?: number;\n\treadonly validatorVersion?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheEntryV2 {\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceHash: string;\n\treadonly representationFingerprint: string;\n\treadonly keyKind?: ContextBudgetRepresentationCacheKeyKindV2;\n\treadonly modelId: string;\n\treadonly tokenizerId: string;\n\treadonly policyVersion: string;\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly compressorPolicyHash?: string;\n\treadonly qualityPolicyHash?: string;\n\treadonly queryIntentCluster?: string;\n\treadonly outputTextHash?: string;\n\treadonly targetTokenBucket?: number;\n\treadonly verification?: ContextBudgetMaterializedVerificationV2;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetRepresentationCacheReadV2 {\n\treadonly entry: ContextBudgetRepresentationCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetNegativeCacheEntryV2 {\n\treadonly reason: string;\n\treadonly createdAtEpochMs?: number;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetPlanCacheEntryV2 {\n\treadonly plan: PromptContextBudgetPlanV2;\n\treadonly sourceHashes: Readonly<Record<string, string>>;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetPlanCacheReadV2 {\n\treadonly entry: ContextBudgetPlanCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetCacheProviderV2 {\n\tgetInvalidationSnapshot?(): ContextCacheInvalidationSnapshot | undefined;\n\tsetInvalidationSnapshot?(snapshot: ContextCacheInvalidationSnapshot): void;\n\treadRepresentation(key: string): ContextBudgetRepresentationCacheReadV2 | undefined;\n\twriteRepresentation(input: { readonly key: string; readonly entry: ContextBudgetRepresentationCacheEntryV2 }): void;\n\tdeleteRepresentation?(key: string): void;\n\treadNegativeRepresentation(key: string): ContextBudgetNegativeCacheEntryV2 | undefined;\n\twriteNegativeRepresentation(input: { readonly key: string; readonly reason: string }): void;\n\tdeleteNegativeRepresentation?(key: string): void;\n\treadPlan(key: string): ContextBudgetPlanCacheReadV2 | undefined;\n\twritePlan(input: { readonly key: string; readonly entry: ContextBudgetPlanCacheEntryV2 }): void;\n\tdeletePlan?(key: string): void;\n}\n\nexport interface ContextBudgetPlanCacheTelemetryV2 {\n\treadonly hit: boolean;\n\treadonly key: string;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n\treadonly rejectedReason?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheTelemetryV2 {\n\treadonly exactHits: number;\n\treadonly semanticHits: number;\n\treadonly pointerHits: number;\n\treadonly misses: number;\n\treadonly staleRejects: number;\n\treadonly poisonRejects: number;\n\treadonly negativeHits: number;\n\treadonly writes: number;\n}\n\nexport interface ContextBudgetCacheTokenTelemetryV2 {\n\treadonly raw: number;\n\treadonly rendered: number;\n\treadonly savedByCache: number;\n\treadonly savedByCompression: number;\n\treadonly savedByOmission: number;\n}\n\nexport interface TokenCacheTelemetryV2 {\n\treadonly planCache: ContextBudgetPlanCacheTelemetryV2;\n\treadonly representationCache: ContextBudgetRepresentationCacheTelemetryV2;\n\treadonly tokens: ContextBudgetCacheTokenTelemetryV2;\n}\n\nexport interface PromptContextBudgetObservabilityV2 {\n\treadonly counts: ContextBudgetObservabilityCountsV2;\n\treadonly diagnosticReasons: readonly QualityDiagnosticReasonV2[];\n\treadonly tokens: ContextBudgetObservabilityTokensV2;\n\treadonly planHash: string;\n\treadonly cache: TokenCacheTelemetryV2;\n\treadonly tokenOptimizer: TokenOptimizerRuntimeStatus;\n}\n\nexport interface PromptContextBudgetPlanV2 {\n\treadonly policyVersion: string;\n\treadonly promptHash?: string;\n\treadonly planHash: string;\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens: number;\n\treadonly safetyMarginTokens: number;\n\treadonly availableTokens: number;\n\treadonly usedTokens: number;\n\treadonly omittedTokens: number;\n\treadonly rawTokens: number;\n\treadonly tokenSavingsRatio: number;\n\treadonly emergency: boolean;\n\treadonly omittedHighPriority: boolean;\n\treadonly tierAllocations: readonly TierBudgetAllocationV2[];\n\treadonly selectedRepresentations: readonly SelectedRepresentationV2[];\n\treadonly includedItemIds: readonly string[];\n\treadonly omittedItemIds: readonly string[];\n\treadonly diagnostics: readonly QualityDiagnosticV2[];\n\treadonly retrievalFallbacks: readonly ContextSourceRefV2[];\n\treadonly observability: PromptContextBudgetObservabilityV2;\n}\n"]}
|
|
@@ -12,8 +12,13 @@ export const CONTEXT_BUDGET_POLICY_VERSION_V2 = "context-budget-v2";
|
|
|
12
12
|
*
|
|
13
13
|
* `sel-2`: density-ordered selection over the cheapest admissible representation
|
|
14
14
|
* (previously priority-class-ordered over full-text tokens).
|
|
15
|
+
* `sel-3`: derived representations are priced by counting their materialized
|
|
16
|
+
* text with the planner's counter; the summary ratio is no longer a cost, so
|
|
17
|
+
* plans cached under `sel-2` carry under-priced summaries and must not be served.
|
|
18
|
+
* The same token covers the exchange and promotion passes added alongside it,
|
|
19
|
+
* which change the selected set for identical inputs.
|
|
15
20
|
*/
|
|
16
|
-
export const CONTEXT_BUDGET_SELECTION_POLICY_V2 = "sel-
|
|
21
|
+
export const CONTEXT_BUDGET_SELECTION_POLICY_V2 = "sel-3";
|
|
17
22
|
export const DEFAULT_TIER_POLICY_V2 = {
|
|
18
23
|
system: { floorPct: 0.25, ceilingPct: 0.45 },
|
|
19
24
|
"active-goal": { floorPct: 0.1, ceilingPct: 0.25 },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-budget-v2-types.js","sourceRoot":"","sources":["../../src/core/context-budget-v2-types.ts"],"names":[],"mappings":"AAYA;;;GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAAmB,CAAC;AAEpE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,OAAO,CAAC;AAgB1D,MAAM,CAAC,MAAM,sBAAsB,GAA8D;IAChG,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC5C,aAAa,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE;IAClD,eAAe,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE;IACpD,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC3C,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC5C,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IACzC,OAAO,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE;IAC3C,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC9C,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE;CAC1C,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAmC;IAC3D,QAAQ;IACR,aAAa;IACb,eAAe;IACf,OAAO;IACP,QAAQ;IACR,KAAK;IACL,SAAS;IACT,UAAU;IACV,SAAS;CACT,CAAC","sourcesContent":["import type {\n\tContextBudgetItemV2,\n\tContextBudgetTierV2,\n\tContextRepresentationCacheMetadataV2,\n\tContextRepresentationCandidateV2,\n\tContextRepresentationKindV2,\n\tContextSourceRefV2,\n\tHeadroomQualityPolicyV2,\n} from \"./context-budget-headroom.ts\";\nimport type { TokenCounterAdapter } from \"./context-budget-token-counter.ts\";\nimport type { ContextCacheInvalidationSnapshot } from \"./context-budget-v2-cache-invalidation.ts\";\n\n/**\n * Public optimizer identifier. It is reported in the system prompt and used as a\n * cache namespace, so it must stay stable across internal policy changes.\n */\nexport const CONTEXT_BUDGET_POLICY_VERSION_V2 = \"context-budget-v2\";\n\n/**\n * Internal token for the optional-item selection policy, kept separate from the\n * public identifier so a scoring or ordering change can invalidate cached plans\n * without renaming the optimizer. Bump it whenever the selected set can differ\n * for identical inputs; otherwise plans built under the previous policy keep\n * being served for the whole cache TTL, including from disk.\n *\n * `sel-2`: density-ordered selection over the cheapest admissible representation\n * (previously priority-class-ordered over full-text tokens).\n */\nexport const CONTEXT_BUDGET_SELECTION_POLICY_V2 = \"sel-2\";\n\n/** Fixed compatibility telemetry for the removed legacy token optimizer. */\nexport interface TokenOptimizerRuntimeStatus {\n\treadonly optimizerId: \"legacy-token-optimizer\";\n\treadonly status: \"quarantined_compatibility\";\n\treadonly active: false;\n\treadonly activeContextBudgetOptimizer: \"context-budget-v2\";\n\treadonly compatibilityOnly: true;\n}\n\nexport interface TierBudgetPolicyV2 {\n\treadonly floorPct: number;\n\treadonly ceilingPct: number;\n}\n\nexport const DEFAULT_TIER_POLICY_V2: Readonly<Record<ContextBudgetTierV2, TierBudgetPolicyV2>> = {\n\tsystem: { floorPct: 0.25, ceilingPct: 0.45 },\n\t\"active-goal\": { floorPct: 0.1, ceilingPct: 0.25 },\n\t\"current-files\": { floorPct: 0.08, ceilingPct: 0.2 },\n\ttools: { floorPct: 0.04, ceilingPct: 0.12 },\n\tskills: { floorPct: 0.03, ceilingPct: 0.12 },\n\tmcp: { floorPct: 0.02, ceilingPct: 0.08 },\n\thistory: { floorPct: 0.1, ceilingPct: 0.3 },\n\tevidence: { floorPct: 0.08, ceilingPct: 0.25 },\n\tscratch: { floorPct: 0, ceilingPct: 0.05 },\n};\n\nexport const ALL_TIERS_V2: readonly ContextBudgetTierV2[] = [\n\t\"system\",\n\t\"active-goal\",\n\t\"current-files\",\n\t\"tools\",\n\t\"skills\",\n\t\"mcp\",\n\t\"history\",\n\t\"evidence\",\n\t\"scratch\",\n];\n\nexport interface PromptContextBudgetInputV2 {\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens?: number;\n\treadonly safetyMarginTokens?: number;\n\treadonly modelId?: string;\n\treadonly tokenizerId?: string;\n\treadonly policyVersion?: string;\n\t/** Overrides {@link CONTEXT_BUDGET_SELECTION_POLICY_V2}. */\n\treadonly selectionPolicyVersion?: string;\n\treadonly promptHash?: string;\n\treadonly query?: string;\n\treadonly items: readonly ContextBudgetItemV2[];\n\treadonly tokenCounter?: TokenCounterAdapter;\n\treadonly tierPolicy?: Partial<Record<ContextBudgetTierV2, TierBudgetPolicyV2>>;\n\treadonly qualityPolicy?: HeadroomQualityPolicyV2;\n\treadonly cacheProvider?: ContextBudgetCacheProviderV2;\n\treadonly cacheNamespace?: string;\n\treadonly queryIntentHash?: string;\n\treadonly cacheBudgetBucket?: string;\n\treadonly redactionPolicyHash?: string;\n\treadonly safetyProfileHash?: string;\n\treadonly cacheNowEpochMs?: number;\n\treadonly cacheTtlMs?: number;\n\treadonly cacheInvalidationSnapshot?: ContextCacheInvalidationSnapshot;\n}\n\nexport interface SelectedRepresentationV2 {\n\treadonly itemId: string;\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly cache?: ContextRepresentationCacheMetadataV2;\n}\n\nexport interface TierBudgetAllocationV2 {\n\treadonly tier: ContextBudgetTierV2;\n\treadonly floorTokens: number;\n\treadonly ceilingTokens: number;\n\treadonly allocatedTokens: number;\n\treadonly usedTokens: number;\n\treadonly hardTokens: number;\n}\n\nexport type QualityDiagnosticReasonV2 =\n\t| \"omitted_high_priority\"\n\t| \"retrieval_miss_risk\"\n\t| \"restore_on_demand_hint\"\n\t| \"hard_pin_over_capacity\"\n\t| \"coverage_gap\"\n\t| \"tier_ceiling_exceeded\"\n\t| \"invalid_budget\";\n\nexport interface QualityDiagnosticV2 {\n\treadonly reason: QualityDiagnosticReasonV2;\n\treadonly itemId?: string;\n\treadonly detail: string;\n}\n\nexport interface ContextBudgetObservabilityCountsV2 {\n\treadonly selected: number;\n\treadonly omitted: number;\n\treadonly pointer: number;\n\treadonly compressed: number;\n\treadonly full: number;\n\treadonly retrievalFallback: number;\n}\n\nexport interface ContextBudgetObservabilityTokensV2 {\n\treadonly available: number;\n\treadonly used: number;\n\treadonly raw: number;\n\treadonly omitted: number;\n\treadonly tokenSavings: number;\n}\n\nexport type ContextBudgetCacheLayerV2 = \"turn\" | \"session\" | \"workspace\" | \"shared\";\n\nexport type ContextBudgetRepresentationCacheRejectReasonV2 =\n\t| \"fingerprint_mismatch\"\n\t| \"kind_mismatch\"\n\t| \"model_mismatch\"\n\t| \"negative\"\n\t| \"policy_mismatch\"\n\t| \"poisoned\"\n\t| \"source_hash_mismatch\"\n\t| \"stale\"\n\t| \"token_invalid\"\n\t| \"tokenizer_mismatch\";\n\nexport type ContextBudgetRepresentationCacheKeyKindV2 = \"exact\" | \"materialized\";\n\nexport interface ContextBudgetMaterializedVerificationV2 {\n\treadonly queryCoverage?: number;\n\treadonly sourceCoverage?: number;\n\treadonly secretLeakScore?: number;\n\treadonly poisonScore?: number;\n\treadonly validatorVersion?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheEntryV2 {\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceHash: string;\n\treadonly representationFingerprint: string;\n\treadonly keyKind?: ContextBudgetRepresentationCacheKeyKindV2;\n\treadonly modelId: string;\n\treadonly tokenizerId: string;\n\treadonly policyVersion: string;\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly compressorPolicyHash?: string;\n\treadonly qualityPolicyHash?: string;\n\treadonly queryIntentCluster?: string;\n\treadonly outputTextHash?: string;\n\treadonly targetTokenBucket?: number;\n\treadonly verification?: ContextBudgetMaterializedVerificationV2;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetRepresentationCacheReadV2 {\n\treadonly entry: ContextBudgetRepresentationCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetNegativeCacheEntryV2 {\n\treadonly reason: string;\n\treadonly createdAtEpochMs?: number;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetPlanCacheEntryV2 {\n\treadonly plan: PromptContextBudgetPlanV2;\n\treadonly sourceHashes: Readonly<Record<string, string>>;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetPlanCacheReadV2 {\n\treadonly entry: ContextBudgetPlanCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetCacheProviderV2 {\n\tgetInvalidationSnapshot?(): ContextCacheInvalidationSnapshot | undefined;\n\tsetInvalidationSnapshot?(snapshot: ContextCacheInvalidationSnapshot): void;\n\treadRepresentation(key: string): ContextBudgetRepresentationCacheReadV2 | undefined;\n\twriteRepresentation(input: { readonly key: string; readonly entry: ContextBudgetRepresentationCacheEntryV2 }): void;\n\tdeleteRepresentation?(key: string): void;\n\treadNegativeRepresentation(key: string): ContextBudgetNegativeCacheEntryV2 | undefined;\n\twriteNegativeRepresentation(input: { readonly key: string; readonly reason: string }): void;\n\tdeleteNegativeRepresentation?(key: string): void;\n\treadPlan(key: string): ContextBudgetPlanCacheReadV2 | undefined;\n\twritePlan(input: { readonly key: string; readonly entry: ContextBudgetPlanCacheEntryV2 }): void;\n\tdeletePlan?(key: string): void;\n}\n\nexport interface ContextBudgetPlanCacheTelemetryV2 {\n\treadonly hit: boolean;\n\treadonly key: string;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n\treadonly rejectedReason?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheTelemetryV2 {\n\treadonly exactHits: number;\n\treadonly semanticHits: number;\n\treadonly pointerHits: number;\n\treadonly misses: number;\n\treadonly staleRejects: number;\n\treadonly poisonRejects: number;\n\treadonly negativeHits: number;\n\treadonly writes: number;\n}\n\nexport interface ContextBudgetCacheTokenTelemetryV2 {\n\treadonly raw: number;\n\treadonly rendered: number;\n\treadonly savedByCache: number;\n\treadonly savedByCompression: number;\n\treadonly savedByOmission: number;\n}\n\nexport interface TokenCacheTelemetryV2 {\n\treadonly planCache: ContextBudgetPlanCacheTelemetryV2;\n\treadonly representationCache: ContextBudgetRepresentationCacheTelemetryV2;\n\treadonly tokens: ContextBudgetCacheTokenTelemetryV2;\n}\n\nexport interface PromptContextBudgetObservabilityV2 {\n\treadonly counts: ContextBudgetObservabilityCountsV2;\n\treadonly diagnosticReasons: readonly QualityDiagnosticReasonV2[];\n\treadonly tokens: ContextBudgetObservabilityTokensV2;\n\treadonly planHash: string;\n\treadonly cache: TokenCacheTelemetryV2;\n\treadonly tokenOptimizer: TokenOptimizerRuntimeStatus;\n}\n\nexport interface PromptContextBudgetPlanV2 {\n\treadonly policyVersion: string;\n\treadonly promptHash?: string;\n\treadonly planHash: string;\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens: number;\n\treadonly safetyMarginTokens: number;\n\treadonly availableTokens: number;\n\treadonly usedTokens: number;\n\treadonly omittedTokens: number;\n\treadonly rawTokens: number;\n\treadonly tokenSavingsRatio: number;\n\treadonly emergency: boolean;\n\treadonly omittedHighPriority: boolean;\n\treadonly tierAllocations: readonly TierBudgetAllocationV2[];\n\treadonly selectedRepresentations: readonly SelectedRepresentationV2[];\n\treadonly includedItemIds: readonly string[];\n\treadonly omittedItemIds: readonly string[];\n\treadonly diagnostics: readonly QualityDiagnosticV2[];\n\treadonly retrievalFallbacks: readonly ContextSourceRefV2[];\n\treadonly observability: PromptContextBudgetObservabilityV2;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"context-budget-v2-types.js","sourceRoot":"","sources":["../../src/core/context-budget-v2-types.ts"],"names":[],"mappings":"AAYA;;;GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAAmB,CAAC;AAEpE;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,OAAO,CAAC;AAuB1D,MAAM,CAAC,MAAM,sBAAsB,GAA8D;IAChG,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC5C,aAAa,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE;IAClD,eAAe,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE;IACpD,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC3C,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC5C,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IACzC,OAAO,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE;IAC3C,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC9C,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE;CAC1C,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAmC;IAC3D,QAAQ;IACR,aAAa;IACb,eAAe;IACf,OAAO;IACP,QAAQ;IACR,KAAK;IACL,SAAS;IACT,UAAU;IACV,SAAS;CACT,CAAC","sourcesContent":["import type {\n\tContextBudgetItemV2,\n\tContextBudgetTierV2,\n\tContextRepresentationCacheMetadataV2,\n\tContextRepresentationCandidateV2,\n\tContextRepresentationKindV2,\n\tContextSourceRefV2,\n\tHeadroomQualityPolicyV2,\n} from \"./context-budget-headroom.ts\";\nimport type { TokenCounterAdapter } from \"./context-budget-token-counter.ts\";\nimport type { ContextCacheInvalidationSnapshot } from \"./context-budget-v2-cache-invalidation.ts\";\n\n/**\n * Public optimizer identifier. It is reported in the system prompt and used as a\n * cache namespace, so it must stay stable across internal policy changes.\n */\nexport const CONTEXT_BUDGET_POLICY_VERSION_V2 = \"context-budget-v2\";\n\n/**\n * Internal token for the optional-item selection policy, kept separate from the\n * public identifier so a scoring or ordering change can invalidate cached plans\n * without renaming the optimizer. Bump it whenever the selected set can differ\n * for identical inputs; otherwise plans built under the previous policy keep\n * being served for the whole cache TTL, including from disk.\n *\n * `sel-2`: density-ordered selection over the cheapest admissible representation\n * (previously priority-class-ordered over full-text tokens).\n * `sel-3`: derived representations are priced by counting their materialized\n * text with the planner's counter; the summary ratio is no longer a cost, so\n * plans cached under `sel-2` carry under-priced summaries and must not be served.\n * The same token covers the exchange and promotion passes added alongside it,\n * which change the selected set for identical inputs.\n */\nexport const CONTEXT_BUDGET_SELECTION_POLICY_V2 = \"sel-3\";\n\n/** Fixed compatibility telemetry for the removed legacy token optimizer. */\nexport interface TokenOptimizerRuntimeStatus {\n\treadonly optimizerId: \"legacy-token-optimizer\";\n\treadonly status: \"quarantined_compatibility\";\n\treadonly active: false;\n\treadonly activeContextBudgetOptimizer: \"context-budget-v2\";\n\treadonly compatibilityOnly: true;\n}\n\nexport interface TierBudgetPolicyV2 {\n\t/**\n\t * Guaranteed share of the available budget the floor-reservation pass\n\t * spends on this tier's own items before leftovers compete globally.\n\t * A real reservation — not merely a lower bound on the ceiling — so a\n\t * higher-scored item in another tier cannot starve this tier's minimum.\n\t */\n\treadonly floorPct: number;\n\t/** Hard cap on this tier's share; selection above it is omitted. */\n\treadonly ceilingPct: number;\n}\n\nexport const DEFAULT_TIER_POLICY_V2: Readonly<Record<ContextBudgetTierV2, TierBudgetPolicyV2>> = {\n\tsystem: { floorPct: 0.25, ceilingPct: 0.45 },\n\t\"active-goal\": { floorPct: 0.1, ceilingPct: 0.25 },\n\t\"current-files\": { floorPct: 0.08, ceilingPct: 0.2 },\n\ttools: { floorPct: 0.04, ceilingPct: 0.12 },\n\tskills: { floorPct: 0.03, ceilingPct: 0.12 },\n\tmcp: { floorPct: 0.02, ceilingPct: 0.08 },\n\thistory: { floorPct: 0.1, ceilingPct: 0.3 },\n\tevidence: { floorPct: 0.08, ceilingPct: 0.25 },\n\tscratch: { floorPct: 0, ceilingPct: 0.05 },\n};\n\nexport const ALL_TIERS_V2: readonly ContextBudgetTierV2[] = [\n\t\"system\",\n\t\"active-goal\",\n\t\"current-files\",\n\t\"tools\",\n\t\"skills\",\n\t\"mcp\",\n\t\"history\",\n\t\"evidence\",\n\t\"scratch\",\n];\n\nexport interface PromptContextBudgetInputV2 {\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens?: number;\n\treadonly safetyMarginTokens?: number;\n\treadonly modelId?: string;\n\treadonly tokenizerId?: string;\n\treadonly policyVersion?: string;\n\t/** Overrides {@link CONTEXT_BUDGET_SELECTION_POLICY_V2}. */\n\treadonly selectionPolicyVersion?: string;\n\treadonly promptHash?: string;\n\treadonly query?: string;\n\treadonly items: readonly ContextBudgetItemV2[];\n\treadonly tokenCounter?: TokenCounterAdapter;\n\treadonly tierPolicy?: Partial<Record<ContextBudgetTierV2, TierBudgetPolicyV2>>;\n\treadonly qualityPolicy?: HeadroomQualityPolicyV2;\n\treadonly cacheProvider?: ContextBudgetCacheProviderV2;\n\treadonly cacheNamespace?: string;\n\treadonly queryIntentHash?: string;\n\treadonly cacheBudgetBucket?: string;\n\treadonly redactionPolicyHash?: string;\n\treadonly safetyProfileHash?: string;\n\treadonly cacheNowEpochMs?: number;\n\treadonly cacheTtlMs?: number;\n\treadonly cacheInvalidationSnapshot?: ContextCacheInvalidationSnapshot;\n}\n\nexport interface SelectedRepresentationV2 {\n\treadonly itemId: string;\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly cache?: ContextRepresentationCacheMetadataV2;\n}\n\nexport interface TierBudgetAllocationV2 {\n\treadonly tier: ContextBudgetTierV2;\n\treadonly floorTokens: number;\n\treadonly ceilingTokens: number;\n\treadonly allocatedTokens: number;\n\treadonly usedTokens: number;\n\treadonly hardTokens: number;\n}\n\nexport type QualityDiagnosticReasonV2 =\n\t| \"omitted_high_priority\"\n\t| \"retrieval_miss_risk\"\n\t| \"restore_on_demand_hint\"\n\t| \"hard_pin_over_capacity\"\n\t| \"coverage_gap\"\n\t| \"tier_ceiling_exceeded\"\n\t| \"tier_floor_over_budget\"\n\t| \"invalid_input\"\n\t| \"invalid_budget\";\n\nexport interface QualityDiagnosticV2 {\n\treadonly reason: QualityDiagnosticReasonV2;\n\treadonly itemId?: string;\n\treadonly detail: string;\n}\n\nexport interface ContextBudgetObservabilityCountsV2 {\n\treadonly selected: number;\n\treadonly omitted: number;\n\treadonly pointer: number;\n\treadonly compressed: number;\n\treadonly full: number;\n\treadonly retrievalFallback: number;\n}\n\nexport interface ContextBudgetObservabilityTokensV2 {\n\treadonly available: number;\n\treadonly used: number;\n\treadonly raw: number;\n\treadonly omitted: number;\n\treadonly tokenSavings: number;\n}\n\nexport type ContextBudgetCacheLayerV2 = \"turn\" | \"session\" | \"workspace\" | \"shared\";\n\nexport type ContextBudgetRepresentationCacheRejectReasonV2 =\n\t| \"fingerprint_mismatch\"\n\t| \"kind_mismatch\"\n\t| \"model_mismatch\"\n\t| \"negative\"\n\t| \"policy_mismatch\"\n\t| \"poisoned\"\n\t| \"source_hash_mismatch\"\n\t| \"stale\"\n\t| \"token_invalid\"\n\t| \"tokenizer_mismatch\";\n\nexport type ContextBudgetRepresentationCacheKeyKindV2 = \"exact\" | \"materialized\";\n\nexport interface ContextBudgetMaterializedVerificationV2 {\n\treadonly queryCoverage?: number;\n\treadonly sourceCoverage?: number;\n\treadonly secretLeakScore?: number;\n\treadonly poisonScore?: number;\n\treadonly validatorVersion?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheEntryV2 {\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceHash: string;\n\treadonly representationFingerprint: string;\n\treadonly keyKind?: ContextBudgetRepresentationCacheKeyKindV2;\n\treadonly modelId: string;\n\treadonly tokenizerId: string;\n\treadonly policyVersion: string;\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly compressorPolicyHash?: string;\n\treadonly qualityPolicyHash?: string;\n\treadonly queryIntentCluster?: string;\n\treadonly outputTextHash?: string;\n\treadonly targetTokenBucket?: number;\n\treadonly verification?: ContextBudgetMaterializedVerificationV2;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetRepresentationCacheReadV2 {\n\treadonly entry: ContextBudgetRepresentationCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetNegativeCacheEntryV2 {\n\treadonly reason: string;\n\treadonly createdAtEpochMs?: number;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetPlanCacheEntryV2 {\n\treadonly plan: PromptContextBudgetPlanV2;\n\treadonly sourceHashes: Readonly<Record<string, string>>;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetPlanCacheReadV2 {\n\treadonly entry: ContextBudgetPlanCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetCacheProviderV2 {\n\tgetInvalidationSnapshot?(): ContextCacheInvalidationSnapshot | undefined;\n\tsetInvalidationSnapshot?(snapshot: ContextCacheInvalidationSnapshot): void;\n\treadRepresentation(key: string): ContextBudgetRepresentationCacheReadV2 | undefined;\n\twriteRepresentation(input: { readonly key: string; readonly entry: ContextBudgetRepresentationCacheEntryV2 }): void;\n\tdeleteRepresentation?(key: string): void;\n\treadNegativeRepresentation(key: string): ContextBudgetNegativeCacheEntryV2 | undefined;\n\twriteNegativeRepresentation(input: { readonly key: string; readonly reason: string }): void;\n\tdeleteNegativeRepresentation?(key: string): void;\n\treadPlan(key: string): ContextBudgetPlanCacheReadV2 | undefined;\n\twritePlan(input: { readonly key: string; readonly entry: ContextBudgetPlanCacheEntryV2 }): void;\n\tdeletePlan?(key: string): void;\n}\n\nexport interface ContextBudgetPlanCacheTelemetryV2 {\n\treadonly hit: boolean;\n\treadonly key: string;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n\treadonly rejectedReason?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheTelemetryV2 {\n\treadonly exactHits: number;\n\treadonly semanticHits: number;\n\treadonly pointerHits: number;\n\treadonly misses: number;\n\treadonly staleRejects: number;\n\treadonly poisonRejects: number;\n\treadonly negativeHits: number;\n\treadonly writes: number;\n}\n\nexport interface ContextBudgetCacheTokenTelemetryV2 {\n\treadonly raw: number;\n\treadonly rendered: number;\n\treadonly savedByCache: number;\n\treadonly savedByCompression: number;\n\treadonly savedByOmission: number;\n}\n\nexport interface TokenCacheTelemetryV2 {\n\treadonly planCache: ContextBudgetPlanCacheTelemetryV2;\n\treadonly representationCache: ContextBudgetRepresentationCacheTelemetryV2;\n\treadonly tokens: ContextBudgetCacheTokenTelemetryV2;\n}\n\nexport interface PromptContextBudgetObservabilityV2 {\n\treadonly counts: ContextBudgetObservabilityCountsV2;\n\treadonly diagnosticReasons: readonly QualityDiagnosticReasonV2[];\n\treadonly tokens: ContextBudgetObservabilityTokensV2;\n\treadonly planHash: string;\n\treadonly cache: TokenCacheTelemetryV2;\n\treadonly tokenOptimizer: TokenOptimizerRuntimeStatus;\n}\n\nexport interface PromptContextBudgetPlanV2 {\n\treadonly policyVersion: string;\n\treadonly promptHash?: string;\n\treadonly planHash: string;\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens: number;\n\treadonly safetyMarginTokens: number;\n\treadonly availableTokens: number;\n\treadonly usedTokens: number;\n\treadonly omittedTokens: number;\n\treadonly rawTokens: number;\n\treadonly tokenSavingsRatio: number;\n\treadonly emergency: boolean;\n\treadonly omittedHighPriority: boolean;\n\treadonly tierAllocations: readonly TierBudgetAllocationV2[];\n\treadonly selectedRepresentations: readonly SelectedRepresentationV2[];\n\treadonly includedItemIds: readonly string[];\n\treadonly omittedItemIds: readonly string[];\n\treadonly diagnostics: readonly QualityDiagnosticV2[];\n\treadonly retrievalFallbacks: readonly ContextSourceRefV2[];\n\treadonly observability: PromptContextBudgetObservabilityV2;\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Virtual modules for compiled Bun binaries — the extension-facing view of the
|
|
3
|
+
* bundled package namespaces.
|
|
4
|
+
*
|
|
5
|
+
* Extracted from loader.ts: the table resolves the bundled
|
|
6
|
+
* `open-multi-agent-kit` namespace that the binary entry registers at startup
|
|
7
|
+
* (src/bun/register-bundled-coding-agent.ts). loader.ts itself must not import
|
|
8
|
+
* `../../index.ts` — that edge put it inside the index↔core import cycle
|
|
9
|
+
* (scripts/check-import-cycles.mjs).
|
|
10
|
+
*/
|
|
11
|
+
/** Registration point for the compiled binary's bundled `open-multi-agent-kit` namespace. */
|
|
12
|
+
export declare function registerBundledCodingAgentNamespace(namespace: unknown): void;
|
|
13
|
+
/** Modules available to extensions via virtualModules (compiled Bun binary only). */
|
|
14
|
+
export declare function buildVirtualModules(): Record<string, unknown>;
|
|
15
|
+
//# sourceMappingURL=bundled-virtual-modules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundled-virtual-modules.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/bundled-virtual-modules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAsBH,6FAA6F;AAC7F,wBAAgB,mCAAmC,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAE5E;AAUD,qFAAqF;AACrF,wBAAgB,mBAAmB,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAuB7D","sourcesContent":["/**\n * Virtual modules for compiled Bun binaries — the extension-facing view of the\n * bundled package namespaces.\n *\n * Extracted from loader.ts: the table resolves the bundled\n * `open-multi-agent-kit` namespace that the binary entry registers at startup\n * (src/bun/register-bundled-coding-agent.ts). loader.ts itself must not import\n * `../../index.ts` — that edge put it inside the index↔core import cycle\n * (scripts/check-import-cycles.mjs).\n */\n\n// Static imports of packages that extensions may use.\n// These MUST be static so Bun bundles them into the compiled binary.\n// The virtualModules option then makes them available to extensions.\nimport * as _bundledOmkAgentCore from \"omk-agent-core\";\nimport * as _bundledOmkAgentCoreNode from \"omk-agent-core/node\";\nimport * as _bundledOmkAi from \"omk-ai\";\nimport * as _bundledOmkAiOauth from \"omk-ai/oauth\";\nimport * as _bundledOmkTui from \"omk-tui\";\nimport * as _bundledTypebox from \"typebox\";\nimport * as _bundledTypeboxCompile from \"typebox/compile\";\nimport * as _bundledTypeboxValue from \"typebox/value\";\nimport { LEGACY_PI_RUNTIME_ALIASES, type PiCompatibilityTarget } from \"../pi-compat.ts\";\n\n/**\n * The compiled-binary entry registers the bundled package namespace here before\n * any extension resolves. loader.ts cannot import `../../index.ts` directly\n * (cycle), so this module is the injection point instead.\n */\nlet _bundledCodingAgentNamespace: unknown;\n\n/** Registration point for the compiled binary's bundled `open-multi-agent-kit` namespace. */\nexport function registerBundledCodingAgentNamespace(namespace: unknown): void {\n\t_bundledCodingAgentNamespace = namespace;\n}\n\nconst LEGACY_PI_VIRTUAL_TARGETS: Record<Exclude<PiCompatibilityTarget, \"coding-agent\">, unknown> = {\n\t\"agent-core\": _bundledOmkAgentCore,\n\t\"agent-core-node\": _bundledOmkAgentCoreNode,\n\tai: _bundledOmkAi,\n\t\"ai-oauth\": _bundledOmkAiOauth,\n\ttui: _bundledOmkTui,\n};\n\n/** Modules available to extensions via virtualModules (compiled Bun binary only). */\nexport function buildVirtualModules(): Record<string, unknown> {\n\tconst bundledCodingAgent = _bundledCodingAgentNamespace;\n\tconst legacyTargets: Record<PiCompatibilityTarget, unknown> = {\n\t\t...LEGACY_PI_VIRTUAL_TARGETS,\n\t\t\"coding-agent\": bundledCodingAgent,\n\t};\n\treturn {\n\t\t...Object.fromEntries(\n\t\t\tObject.entries(LEGACY_PI_RUNTIME_ALIASES).map(([specifier, target]) => [specifier, legacyTargets[target]]),\n\t\t),\n\t\ttypebox: _bundledTypebox,\n\t\t\"typebox/compile\": _bundledTypeboxCompile,\n\t\t\"typebox/value\": _bundledTypeboxValue,\n\t\t\"@sinclair/typebox\": _bundledTypebox,\n\t\t\"@sinclair/typebox/compile\": _bundledTypeboxCompile,\n\t\t\"@sinclair/typebox/value\": _bundledTypeboxValue,\n\t\t\"omk-agent-core\": _bundledOmkAgentCore,\n\t\t\"omk-agent-core/node\": _bundledOmkAgentCoreNode,\n\t\t\"omk-tui\": _bundledOmkTui,\n\t\t\"omk-ai\": _bundledOmkAi,\n\t\t\"omk-ai/oauth\": _bundledOmkAiOauth,\n\t\t\"open-multi-agent-kit\": bundledCodingAgent,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Virtual modules for compiled Bun binaries — the extension-facing view of the
|
|
3
|
+
* bundled package namespaces.
|
|
4
|
+
*
|
|
5
|
+
* Extracted from loader.ts: the table resolves the bundled
|
|
6
|
+
* `open-multi-agent-kit` namespace that the binary entry registers at startup
|
|
7
|
+
* (src/bun/register-bundled-coding-agent.ts). loader.ts itself must not import
|
|
8
|
+
* `../../index.ts` — that edge put it inside the index↔core import cycle
|
|
9
|
+
* (scripts/check-import-cycles.mjs).
|
|
10
|
+
*/
|
|
11
|
+
// Static imports of packages that extensions may use.
|
|
12
|
+
// These MUST be static so Bun bundles them into the compiled binary.
|
|
13
|
+
// The virtualModules option then makes them available to extensions.
|
|
14
|
+
import * as _bundledOmkAgentCore from "omk-agent-core";
|
|
15
|
+
import * as _bundledOmkAgentCoreNode from "omk-agent-core/node";
|
|
16
|
+
import * as _bundledOmkAi from "omk-ai";
|
|
17
|
+
import * as _bundledOmkAiOauth from "omk-ai/oauth";
|
|
18
|
+
import * as _bundledOmkTui from "omk-tui";
|
|
19
|
+
import * as _bundledTypebox from "typebox";
|
|
20
|
+
import * as _bundledTypeboxCompile from "typebox/compile";
|
|
21
|
+
import * as _bundledTypeboxValue from "typebox/value";
|
|
22
|
+
import { LEGACY_PI_RUNTIME_ALIASES } from "../pi-compat.js";
|
|
23
|
+
/**
|
|
24
|
+
* The compiled-binary entry registers the bundled package namespace here before
|
|
25
|
+
* any extension resolves. loader.ts cannot import `../../index.ts` directly
|
|
26
|
+
* (cycle), so this module is the injection point instead.
|
|
27
|
+
*/
|
|
28
|
+
let _bundledCodingAgentNamespace;
|
|
29
|
+
/** Registration point for the compiled binary's bundled `open-multi-agent-kit` namespace. */
|
|
30
|
+
export function registerBundledCodingAgentNamespace(namespace) {
|
|
31
|
+
_bundledCodingAgentNamespace = namespace;
|
|
32
|
+
}
|
|
33
|
+
const LEGACY_PI_VIRTUAL_TARGETS = {
|
|
34
|
+
"agent-core": _bundledOmkAgentCore,
|
|
35
|
+
"agent-core-node": _bundledOmkAgentCoreNode,
|
|
36
|
+
ai: _bundledOmkAi,
|
|
37
|
+
"ai-oauth": _bundledOmkAiOauth,
|
|
38
|
+
tui: _bundledOmkTui,
|
|
39
|
+
};
|
|
40
|
+
/** Modules available to extensions via virtualModules (compiled Bun binary only). */
|
|
41
|
+
export function buildVirtualModules() {
|
|
42
|
+
const bundledCodingAgent = _bundledCodingAgentNamespace;
|
|
43
|
+
const legacyTargets = {
|
|
44
|
+
...LEGACY_PI_VIRTUAL_TARGETS,
|
|
45
|
+
"coding-agent": bundledCodingAgent,
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
...Object.fromEntries(Object.entries(LEGACY_PI_RUNTIME_ALIASES).map(([specifier, target]) => [specifier, legacyTargets[target]])),
|
|
49
|
+
typebox: _bundledTypebox,
|
|
50
|
+
"typebox/compile": _bundledTypeboxCompile,
|
|
51
|
+
"typebox/value": _bundledTypeboxValue,
|
|
52
|
+
"@sinclair/typebox": _bundledTypebox,
|
|
53
|
+
"@sinclair/typebox/compile": _bundledTypeboxCompile,
|
|
54
|
+
"@sinclair/typebox/value": _bundledTypeboxValue,
|
|
55
|
+
"omk-agent-core": _bundledOmkAgentCore,
|
|
56
|
+
"omk-agent-core/node": _bundledOmkAgentCoreNode,
|
|
57
|
+
"omk-tui": _bundledOmkTui,
|
|
58
|
+
"omk-ai": _bundledOmkAi,
|
|
59
|
+
"omk-ai/oauth": _bundledOmkAiOauth,
|
|
60
|
+
"open-multi-agent-kit": bundledCodingAgent,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=bundled-virtual-modules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundled-virtual-modules.js","sourceRoot":"","sources":["../../../src/core/extensions/bundled-virtual-modules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,sDAAsD;AACtD,qEAAqE;AACrE,qEAAqE;AACrE,OAAO,KAAK,oBAAoB,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,wBAAwB,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,aAAa,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,kBAAkB,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,cAAc,MAAM,SAAS,CAAC;AAC1C,OAAO,KAAK,eAAe,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,sBAAsB,MAAM,iBAAiB,CAAC;AAC1D,OAAO,KAAK,oBAAoB,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,yBAAyB,EAA8B,MAAM,iBAAiB,CAAC;AAExF;;;;GAIG;AACH,IAAI,4BAAqC,CAAC;AAE1C,6FAA6F;AAC7F,MAAM,UAAU,mCAAmC,CAAC,SAAkB,EAAQ;IAC7E,4BAA4B,GAAG,SAAS,CAAC;AAAA,CACzC;AAED,MAAM,yBAAyB,GAAoE;IAClG,YAAY,EAAE,oBAAoB;IAClC,iBAAiB,EAAE,wBAAwB;IAC3C,EAAE,EAAE,aAAa;IACjB,UAAU,EAAE,kBAAkB;IAC9B,GAAG,EAAE,cAAc;CACnB,CAAC;AAEF,qFAAqF;AACrF,MAAM,UAAU,mBAAmB,GAA4B;IAC9D,MAAM,kBAAkB,GAAG,4BAA4B,CAAC;IACxD,MAAM,aAAa,GAA2C;QAC7D,GAAG,yBAAyB;QAC5B,cAAc,EAAE,kBAAkB;KAClC,CAAC;IACF,OAAO;QACN,GAAG,MAAM,CAAC,WAAW,CACpB,MAAM,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAC1G;QACD,OAAO,EAAE,eAAe;QACxB,iBAAiB,EAAE,sBAAsB;QACzC,eAAe,EAAE,oBAAoB;QACrC,mBAAmB,EAAE,eAAe;QACpC,2BAA2B,EAAE,sBAAsB;QACnD,yBAAyB,EAAE,oBAAoB;QAC/C,gBAAgB,EAAE,oBAAoB;QACtC,qBAAqB,EAAE,wBAAwB;QAC/C,SAAS,EAAE,cAAc;QACzB,QAAQ,EAAE,aAAa;QACvB,cAAc,EAAE,kBAAkB;QAClC,sBAAsB,EAAE,kBAAkB;KAC1C,CAAC;AAAA,CACF","sourcesContent":["/**\n * Virtual modules for compiled Bun binaries — the extension-facing view of the\n * bundled package namespaces.\n *\n * Extracted from loader.ts: the table resolves the bundled\n * `open-multi-agent-kit` namespace that the binary entry registers at startup\n * (src/bun/register-bundled-coding-agent.ts). loader.ts itself must not import\n * `../../index.ts` — that edge put it inside the index↔core import cycle\n * (scripts/check-import-cycles.mjs).\n */\n\n// Static imports of packages that extensions may use.\n// These MUST be static so Bun bundles them into the compiled binary.\n// The virtualModules option then makes them available to extensions.\nimport * as _bundledOmkAgentCore from \"omk-agent-core\";\nimport * as _bundledOmkAgentCoreNode from \"omk-agent-core/node\";\nimport * as _bundledOmkAi from \"omk-ai\";\nimport * as _bundledOmkAiOauth from \"omk-ai/oauth\";\nimport * as _bundledOmkTui from \"omk-tui\";\nimport * as _bundledTypebox from \"typebox\";\nimport * as _bundledTypeboxCompile from \"typebox/compile\";\nimport * as _bundledTypeboxValue from \"typebox/value\";\nimport { LEGACY_PI_RUNTIME_ALIASES, type PiCompatibilityTarget } from \"../pi-compat.ts\";\n\n/**\n * The compiled-binary entry registers the bundled package namespace here before\n * any extension resolves. loader.ts cannot import `../../index.ts` directly\n * (cycle), so this module is the injection point instead.\n */\nlet _bundledCodingAgentNamespace: unknown;\n\n/** Registration point for the compiled binary's bundled `open-multi-agent-kit` namespace. */\nexport function registerBundledCodingAgentNamespace(namespace: unknown): void {\n\t_bundledCodingAgentNamespace = namespace;\n}\n\nconst LEGACY_PI_VIRTUAL_TARGETS: Record<Exclude<PiCompatibilityTarget, \"coding-agent\">, unknown> = {\n\t\"agent-core\": _bundledOmkAgentCore,\n\t\"agent-core-node\": _bundledOmkAgentCoreNode,\n\tai: _bundledOmkAi,\n\t\"ai-oauth\": _bundledOmkAiOauth,\n\ttui: _bundledOmkTui,\n};\n\n/** Modules available to extensions via virtualModules (compiled Bun binary only). */\nexport function buildVirtualModules(): Record<string, unknown> {\n\tconst bundledCodingAgent = _bundledCodingAgentNamespace;\n\tconst legacyTargets: Record<PiCompatibilityTarget, unknown> = {\n\t\t...LEGACY_PI_VIRTUAL_TARGETS,\n\t\t\"coding-agent\": bundledCodingAgent,\n\t};\n\treturn {\n\t\t...Object.fromEntries(\n\t\t\tObject.entries(LEGACY_PI_RUNTIME_ALIASES).map(([specifier, target]) => [specifier, legacyTargets[target]]),\n\t\t),\n\t\ttypebox: _bundledTypebox,\n\t\t\"typebox/compile\": _bundledTypeboxCompile,\n\t\t\"typebox/value\": _bundledTypeboxValue,\n\t\t\"@sinclair/typebox\": _bundledTypebox,\n\t\t\"@sinclair/typebox/compile\": _bundledTypeboxCompile,\n\t\t\"@sinclair/typebox/value\": _bundledTypeboxValue,\n\t\t\"omk-agent-core\": _bundledOmkAgentCore,\n\t\t\"omk-agent-core/node\": _bundledOmkAgentCoreNode,\n\t\t\"omk-tui\": _bundledOmkTui,\n\t\t\"omk-ai\": _bundledOmkAi,\n\t\t\"omk-ai/oauth\": _bundledOmkAiOauth,\n\t\t\"open-multi-agent-kit\": bundledCodingAgent,\n\t};\n}\n"]}
|