open-multi-agent-kit 1.0.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -1
- package/README.md +2 -2
- package/dist/approval-api.d.ts +5 -0
- package/dist/approval-api.d.ts.map +1 -0
- package/dist/approval-api.js +5 -0
- package/dist/approval-api.js.map +1 -0
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +1 -0
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/session-picker.d.ts +2 -2
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/commands/verified-run-cli.d.ts.map +1 -1
- package/dist/commands/verified-run-cli.js +69 -22
- package/dist/commands/verified-run-cli.js.map +1 -1
- package/dist/commands/verified-run-signal.d.ts +3 -0
- package/dist/commands/verified-run-signal.d.ts.map +1 -0
- package/dist/commands/verified-run-signal.js +15 -0
- package/dist/commands/verified-run-signal.js.map +1 -0
- package/dist/coordination/awareness.d.ts +32 -0
- package/dist/coordination/awareness.d.ts.map +1 -0
- package/dist/coordination/awareness.js +55 -0
- package/dist/coordination/awareness.js.map +1 -0
- package/dist/coordination/broker.d.ts +79 -0
- package/dist/coordination/broker.d.ts.map +1 -0
- package/dist/coordination/broker.js +202 -0
- package/dist/coordination/broker.js.map +1 -0
- package/dist/coordination/index.d.ts +16 -0
- package/dist/coordination/index.d.ts.map +1 -0
- package/dist/coordination/index.js +16 -0
- package/dist/coordination/index.js.map +1 -0
- package/dist/coordination/integration.d.ts +59 -0
- package/dist/coordination/integration.d.ts.map +1 -0
- package/dist/coordination/integration.js +126 -0
- package/dist/coordination/integration.js.map +1 -0
- package/dist/coordination/operation.d.ts +107 -0
- package/dist/coordination/operation.d.ts.map +1 -0
- package/dist/coordination/operation.js +231 -0
- package/dist/coordination/operation.js.map +1 -0
- package/dist/coordination/resource.d.ts +33 -0
- package/dist/coordination/resource.d.ts.map +1 -0
- package/dist/coordination/resource.js +95 -0
- package/dist/coordination/resource.js.map +1 -0
- package/dist/coordination/session.d.ts +74 -0
- package/dist/coordination/session.d.ts.map +1 -0
- package/dist/coordination/session.js +143 -0
- package/dist/coordination/session.js.map +1 -0
- package/dist/coordination/types.d.ts +68 -0
- package/dist/coordination/types.d.ts.map +1 -0
- package/dist/coordination/types.js +26 -0
- package/dist/coordination/types.js.map +1 -0
- package/dist/core/adaptorch-bridge.d.ts +1 -1
- package/dist/core/adaptorch-bridge.d.ts.map +1 -1
- package/dist/core/adaptorch-bridge.js +1 -1
- package/dist/core/adaptorch-bridge.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +16 -16
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +35 -15
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/canonical-json.d.ts +3 -0
- package/dist/core/canonical-json.d.ts.map +1 -0
- package/dist/core/canonical-json.js +20 -0
- package/dist/core/canonical-json.js.map +1 -0
- package/dist/core/compaction/compaction.d.ts +7 -3
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +14 -29
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/control-state.d.ts +41 -0
- package/dist/core/compaction/control-state.d.ts.map +1 -0
- package/dist/core/compaction/control-state.js +85 -0
- package/dist/core/compaction/control-state.js.map +1 -0
- package/dist/core/compaction/fallback.d.ts +71 -0
- package/dist/core/compaction/fallback.d.ts.map +1 -0
- package/dist/core/compaction/fallback.js +118 -0
- package/dist/core/compaction/fallback.js.map +1 -0
- package/dist/core/compaction/index.d.ts +2 -0
- package/dist/core/compaction/index.d.ts.map +1 -1
- package/dist/core/compaction/index.js +2 -0
- package/dist/core/compaction/index.js.map +1 -1
- package/dist/core/compaction/model-failover.d.ts +21 -0
- package/dist/core/compaction/model-failover.d.ts.map +1 -0
- package/dist/core/compaction/model-failover.js +46 -0
- package/dist/core/compaction/model-failover.js.map +1 -0
- package/dist/core/compaction/session-summary.d.ts +21 -0
- package/dist/core/compaction/session-summary.d.ts.map +1 -0
- package/dist/core/compaction/session-summary.js +27 -0
- package/dist/core/compaction/session-summary.js.map +1 -0
- package/dist/core/context-budget-headroom-candidates.d.ts +16 -1
- package/dist/core/context-budget-headroom-candidates.d.ts.map +1 -1
- package/dist/core/context-budget-headroom-candidates.js +31 -13
- package/dist/core/context-budget-headroom-candidates.js.map +1 -1
- package/dist/core/context-budget-headroom-types.d.ts +7 -1
- package/dist/core/context-budget-headroom-types.d.ts.map +1 -1
- package/dist/core/context-budget-headroom-types.js +0 -1
- package/dist/core/context-budget-headroom-types.js.map +1 -1
- package/dist/core/context-budget-headroom.d.ts +10 -0
- package/dist/core/context-budget-headroom.d.ts.map +1 -1
- package/dist/core/context-budget-headroom.js +11 -2
- package/dist/core/context-budget-headroom.js.map +1 -1
- package/dist/core/context-budget-v2-global-pass.d.ts +21 -0
- package/dist/core/context-budget-v2-global-pass.d.ts.map +1 -0
- package/dist/core/context-budget-v2-global-pass.js +203 -0
- package/dist/core/context-budget-v2-global-pass.js.map +1 -0
- package/dist/core/context-budget-v2-planned-items.d.ts +12 -0
- package/dist/core/context-budget-v2-planned-items.d.ts.map +1 -1
- package/dist/core/context-budget-v2-planned-items.js +21 -2
- package/dist/core/context-budget-v2-planned-items.js.map +1 -1
- package/dist/core/context-budget-v2-planner.d.ts.map +1 -1
- package/dist/core/context-budget-v2-planner.js +18 -19
- package/dist/core/context-budget-v2-planner.js.map +1 -1
- package/dist/core/context-budget-v2-scoring.d.ts +7 -1
- package/dist/core/context-budget-v2-scoring.d.ts.map +1 -1
- package/dist/core/context-budget-v2-scoring.js.map +1 -1
- package/dist/core/context-budget-v2-selection.d.ts +3 -0
- package/dist/core/context-budget-v2-selection.d.ts.map +1 -1
- package/dist/core/context-budget-v2-selection.js +6 -2
- package/dist/core/context-budget-v2-selection.js.map +1 -1
- package/dist/core/context-budget-v2-types.d.ts +6 -1
- package/dist/core/context-budget-v2-types.d.ts.map +1 -1
- package/dist/core/context-budget-v2-types.js +6 -1
- package/dist/core/context-budget-v2-types.js.map +1 -1
- package/dist/core/export-html/template.js +14 -0
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/session-lifecycle-types.d.ts +14 -0
- package/dist/core/extensions/session-lifecycle-types.d.ts.map +1 -0
- package/dist/core/extensions/session-lifecycle-types.js +2 -0
- package/dist/core/extensions/session-lifecycle-types.js.map +1 -0
- package/dist/core/extensions/types.d.ts +4 -9
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +10 -1
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +3 -6
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/legacy-resource-policy.d.ts +7 -0
- package/dist/core/legacy-resource-policy.d.ts.map +1 -0
- package/dist/core/legacy-resource-policy.js +9 -0
- package/dist/core/legacy-resource-policy.js.map +1 -0
- package/dist/core/mcp/config.d.ts.map +1 -1
- package/dist/core/mcp/config.js +17 -3
- package/dist/core/mcp/config.js.map +1 -1
- package/dist/core/mcp/connection-queue.d.ts +12 -0
- package/dist/core/mcp/connection-queue.d.ts.map +1 -0
- package/dist/core/mcp/connection-queue.js +46 -0
- package/dist/core/mcp/connection-queue.js.map +1 -0
- package/dist/core/mcp/manager-runtime.d.ts +55 -0
- package/dist/core/mcp/manager-runtime.d.ts.map +1 -0
- package/dist/core/mcp/manager-runtime.js +66 -0
- package/dist/core/mcp/manager-runtime.js.map +1 -0
- package/dist/core/mcp/manager.d.ts +12 -68
- package/dist/core/mcp/manager.d.ts.map +1 -1
- package/dist/core/mcp/manager.js +33 -113
- package/dist/core/mcp/manager.js.map +1 -1
- package/dist/core/mcp/protocol.d.ts.map +1 -1
- package/dist/core/mcp/protocol.js +70 -40
- package/dist/core/mcp/protocol.js.map +1 -1
- package/dist/core/package-manager.d.ts +4 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +59 -129
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/package-resource-patterns.d.ts +7 -0
- package/dist/core/package-resource-patterns.d.ts.map +1 -0
- package/dist/core/package-resource-patterns.js +99 -0
- package/dist/core/package-resource-patterns.js.map +1 -0
- package/dist/core/provider-default-models.d.ts +1 -0
- package/dist/core/provider-default-models.d.ts.map +1 -1
- package/dist/core/provider-default-models.js +1 -0
- package/dist/core/provider-default-models.js.map +1 -1
- package/dist/core/provider-display-names.d.ts.map +1 -1
- package/dist/core/provider-display-names.js +1 -0
- package/dist/core/provider-display-names.js.map +1 -1
- package/dist/core/provider-resilience.d.ts +9 -0
- package/dist/core/provider-resilience.d.ts.map +1 -1
- package/dist/core/provider-resilience.js +15 -0
- package/dist/core/provider-resilience.js.map +1 -1
- package/dist/core/reasoning-router-resolver.d.ts +7 -0
- package/dist/core/reasoning-router-resolver.d.ts.map +1 -1
- package/dist/core/reasoning-router-resolver.js +21 -3
- package/dist/core/reasoning-router-resolver.js.map +1 -1
- package/dist/core/reasoning-router-v4.d.ts +13 -7
- package/dist/core/reasoning-router-v4.d.ts.map +1 -1
- package/dist/core/reasoning-router-v4.js +8 -5
- package/dist/core/reasoning-router-v4.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +4 -8
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/run-execution-api.d.ts +8 -1
- package/dist/core/run-execution-api.d.ts.map +1 -1
- package/dist/core/run-execution-api.js +4 -0
- package/dist/core/run-execution-api.js.map +1 -1
- package/dist/core/run-journal.d.ts +1 -2
- package/dist/core/run-journal.d.ts.map +1 -1
- package/dist/core/run-journal.js +2 -19
- package/dist/core/run-journal.js.map +1 -1
- package/dist/core/session-compaction-service.d.ts +15 -0
- package/dist/core/session-compaction-service.d.ts.map +1 -1
- package/dist/core/session-compaction-service.js +17 -4
- package/dist/core/session-compaction-service.js.map +1 -1
- package/dist/core/session-listing.d.ts +51 -0
- package/dist/core/session-listing.d.ts.map +1 -0
- package/dist/core/session-listing.js +111 -0
- package/dist/core/session-listing.js.map +1 -0
- package/dist/core/session-manager.d.ts +12 -37
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +12 -118
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/session-message-text.d.ts +5 -0
- package/dist/core/session-message-text.d.ts.map +1 -0
- package/dist/core/session-message-text.js +9 -0
- package/dist/core/session-message-text.js.map +1 -0
- package/dist/core/skills-catalog-cache.d.ts +2 -0
- package/dist/core/skills-catalog-cache.d.ts.map +1 -1
- package/dist/core/skills-catalog-cache.js +71 -17
- package/dist/core/skills-catalog-cache.js.map +1 -1
- package/dist/core/todo-runtime-state.d.ts +12 -0
- package/dist/core/todo-runtime-state.d.ts.map +1 -1
- package/dist/core/todo-runtime-state.js +23 -0
- package/dist/core/todo-runtime-state.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/verified-run/authority-clock.d.ts +3 -0
- package/dist/core/verified-run/authority-clock.d.ts.map +1 -0
- package/dist/core/verified-run/authority-clock.js +25 -0
- package/dist/core/verified-run/authority-clock.js.map +1 -0
- package/dist/core/verified-run/authority-errors.d.ts +10 -0
- package/dist/core/verified-run/authority-errors.d.ts.map +1 -0
- package/dist/core/verified-run/authority-errors.js +17 -0
- package/dist/core/verified-run/authority-errors.js.map +1 -0
- package/dist/core/verified-run/authority-events.d.ts +126 -0
- package/dist/core/verified-run/authority-events.d.ts.map +1 -0
- package/dist/core/verified-run/authority-events.js +482 -0
- package/dist/core/verified-run/authority-events.js.map +1 -0
- package/dist/core/verified-run/authority-journal.d.ts +27 -0
- package/dist/core/verified-run/authority-journal.d.ts.map +1 -0
- package/dist/core/verified-run/authority-journal.js +83 -0
- package/dist/core/verified-run/authority-journal.js.map +1 -0
- package/dist/core/verified-run/authority-meaning.d.ts +13 -0
- package/dist/core/verified-run/authority-meaning.d.ts.map +1 -0
- package/dist/core/verified-run/authority-meaning.js +40 -0
- package/dist/core/verified-run/authority-meaning.js.map +1 -0
- package/dist/core/verified-run/authority-runtime.d.ts +82 -0
- package/dist/core/verified-run/authority-runtime.d.ts.map +1 -0
- package/dist/core/verified-run/authority-runtime.js +169 -0
- package/dist/core/verified-run/authority-runtime.js.map +1 -0
- package/dist/core/verified-run/authority-store.d.ts +204 -0
- package/dist/core/verified-run/authority-store.d.ts.map +1 -0
- package/dist/core/verified-run/authority-store.js +852 -0
- package/dist/core/verified-run/authority-store.js.map +1 -0
- package/dist/core/verified-run/broker.d.ts +8 -1
- package/dist/core/verified-run/broker.d.ts.map +1 -1
- package/dist/core/verified-run/broker.js +94 -90
- package/dist/core/verified-run/broker.js.map +1 -1
- package/dist/core/verified-run/candidate-policy.d.ts +10 -0
- package/dist/core/verified-run/candidate-policy.d.ts.map +1 -0
- package/dist/core/verified-run/candidate-policy.js +33 -0
- package/dist/core/verified-run/candidate-policy.js.map +1 -0
- package/dist/core/verified-run/candidate.d.ts.map +1 -1
- package/dist/core/verified-run/candidate.js +5 -10
- package/dist/core/verified-run/candidate.js.map +1 -1
- package/dist/core/verified-run/coordinator.d.ts +35 -17
- package/dist/core/verified-run/coordinator.d.ts.map +1 -1
- package/dist/core/verified-run/coordinator.js +111 -57
- package/dist/core/verified-run/coordinator.js.map +1 -1
- package/dist/core/verified-run/dag-phase.d.ts.map +1 -1
- package/dist/core/verified-run/dag-phase.js +1 -1
- package/dist/core/verified-run/dag-phase.js.map +1 -1
- package/dist/core/verified-run/dag-recovery.d.ts +5 -1
- package/dist/core/verified-run/dag-recovery.d.ts.map +1 -1
- package/dist/core/verified-run/dag-recovery.js +10 -4
- package/dist/core/verified-run/dag-recovery.js.map +1 -1
- package/dist/core/verified-run/event-parser.d.ts.map +1 -1
- package/dist/core/verified-run/event-parser.js +33 -0
- package/dist/core/verified-run/event-parser.js.map +1 -1
- package/dist/core/verified-run/evidence-read-projection.d.ts +4 -0
- package/dist/core/verified-run/evidence-read-projection.d.ts.map +1 -0
- package/dist/core/verified-run/evidence-read-projection.js +27 -0
- package/dist/core/verified-run/evidence-read-projection.js.map +1 -0
- package/dist/core/verified-run/evidence.d.ts +12 -1
- package/dist/core/verified-run/evidence.d.ts.map +1 -1
- package/dist/core/verified-run/evidence.js +51 -2
- package/dist/core/verified-run/evidence.js.map +1 -1
- package/dist/core/verified-run/git-candidate-preflight.d.ts +4 -0
- package/dist/core/verified-run/git-candidate-preflight.d.ts.map +1 -0
- package/dist/core/verified-run/git-candidate-preflight.js +34 -0
- package/dist/core/verified-run/git-candidate-preflight.js.map +1 -0
- package/dist/core/verified-run/git-effect-supervisor.d.ts +24 -0
- package/dist/core/verified-run/git-effect-supervisor.d.ts.map +1 -0
- package/dist/core/verified-run/git-effect-supervisor.js +174 -0
- package/dist/core/verified-run/git-effect-supervisor.js.map +1 -0
- package/dist/core/verified-run/git-execution.d.ts +27 -0
- package/dist/core/verified-run/git-execution.d.ts.map +1 -0
- package/dist/core/verified-run/git-execution.js +118 -0
- package/dist/core/verified-run/git-execution.js.map +1 -0
- package/dist/core/verified-run/git-plumbing.d.ts +37 -0
- package/dist/core/verified-run/git-plumbing.d.ts.map +1 -0
- package/dist/core/verified-run/git-plumbing.js +171 -0
- package/dist/core/verified-run/git-plumbing.js.map +1 -0
- package/dist/core/verified-run/git-publication-worker.d.ts +2 -0
- package/dist/core/verified-run/git-publication-worker.d.ts.map +1 -0
- package/dist/core/verified-run/git-publication-worker.js +54 -0
- package/dist/core/verified-run/git-publication-worker.js.map +1 -0
- package/dist/core/verified-run/git-sandbox-layout.d.ts +4 -0
- package/dist/core/verified-run/git-sandbox-layout.d.ts.map +1 -0
- package/dist/core/verified-run/git-sandbox-layout.js +29 -0
- package/dist/core/verified-run/git-sandbox-layout.js.map +1 -0
- package/dist/core/verified-run/git-worker-protocol.d.ts +19 -0
- package/dist/core/verified-run/git-worker-protocol.d.ts.map +1 -0
- package/dist/core/verified-run/git-worker-protocol.js +109 -0
- package/dist/core/verified-run/git-worker-protocol.js.map +1 -0
- package/dist/core/verified-run/git-worker-runtime.d.ts +19 -0
- package/dist/core/verified-run/git-worker-runtime.d.ts.map +1 -0
- package/dist/core/verified-run/git-worker-runtime.js +74 -0
- package/dist/core/verified-run/git-worker-runtime.js.map +1 -0
- package/dist/core/verified-run/journal.d.ts +2 -3
- package/dist/core/verified-run/journal.d.ts.map +1 -1
- package/dist/core/verified-run/journal.js.map +1 -1
- package/dist/core/verified-run/namespace-identity.d.ts.map +1 -1
- package/dist/core/verified-run/namespace-identity.js +1 -1
- package/dist/core/verified-run/namespace-identity.js.map +1 -1
- package/dist/core/verified-run/owned-execution.d.ts +10 -1
- package/dist/core/verified-run/owned-execution.d.ts.map +1 -1
- package/dist/core/verified-run/owned-execution.js +124 -31
- package/dist/core/verified-run/owned-execution.js.map +1 -1
- package/dist/core/verified-run/phase-context.d.ts +2 -0
- package/dist/core/verified-run/phase-context.d.ts.map +1 -1
- package/dist/core/verified-run/phase-context.js.map +1 -1
- package/dist/core/verified-run/projection.d.ts.map +1 -1
- package/dist/core/verified-run/projection.js +51 -1
- package/dist/core/verified-run/projection.js.map +1 -1
- package/dist/core/verified-run/publish-preflight.d.ts +12 -0
- package/dist/core/verified-run/publish-preflight.d.ts.map +1 -0
- package/dist/core/verified-run/publish-preflight.js +38 -0
- package/dist/core/verified-run/publish-preflight.js.map +1 -0
- package/dist/core/verified-run/publish-start.d.ts +5 -0
- package/dist/core/verified-run/publish-start.d.ts.map +1 -0
- package/dist/core/verified-run/publish-start.js +7 -0
- package/dist/core/verified-run/publish-start.js.map +1 -0
- package/dist/core/verified-run/recovery-projection.d.ts.map +1 -1
- package/dist/core/verified-run/recovery-projection.js +5 -0
- package/dist/core/verified-run/recovery-projection.js.map +1 -1
- package/dist/core/verified-run/recovery.d.ts +5 -1
- package/dist/core/verified-run/recovery.d.ts.map +1 -1
- package/dist/core/verified-run/recovery.js +10 -4
- package/dist/core/verified-run/recovery.js.map +1 -1
- package/dist/core/verified-run/run-plan.d.ts +17 -0
- package/dist/core/verified-run/run-plan.d.ts.map +1 -0
- package/dist/core/verified-run/run-plan.js +18 -0
- package/dist/core/verified-run/run-plan.js.map +1 -0
- package/dist/core/verified-run/run-publish-owned.d.ts +6 -0
- package/dist/core/verified-run/run-publish-owned.d.ts.map +1 -0
- package/dist/core/verified-run/run-publish-owned.js +199 -0
- package/dist/core/verified-run/run-publish-owned.js.map +1 -0
- package/dist/core/verified-run/run-publish.d.ts +19 -0
- package/dist/core/verified-run/run-publish.d.ts.map +1 -0
- package/dist/core/verified-run/run-publish.js +210 -0
- package/dist/core/verified-run/run-publish.js.map +1 -0
- package/dist/core/verified-run/run-status-owned.d.ts +4 -0
- package/dist/core/verified-run/run-status-owned.d.ts.map +1 -0
- package/dist/core/verified-run/run-status-owned.js +14 -0
- package/dist/core/verified-run/run-status-owned.js.map +1 -0
- package/dist/core/verified-run/run-status.d.ts +133 -0
- package/dist/core/verified-run/run-status.d.ts.map +1 -0
- package/dist/core/verified-run/run-status.js +193 -0
- package/dist/core/verified-run/run-status.js.map +1 -0
- package/dist/core/verified-run/run-types.d.ts +31 -0
- package/dist/core/verified-run/run-types.d.ts.map +1 -1
- package/dist/core/verified-run/run-types.js.map +1 -1
- package/dist/core/verified-run/storage.d.ts.map +1 -1
- package/dist/core/verified-run/storage.js +1 -1
- package/dist/core/verified-run/storage.js.map +1 -1
- package/dist/core/verified-run/supervisor-adapter.d.ts +77 -0
- package/dist/core/verified-run/supervisor-adapter.d.ts.map +1 -0
- package/dist/core/verified-run/supervisor-adapter.js +164 -0
- package/dist/core/verified-run/supervisor-adapter.js.map +1 -0
- package/dist/core/verified-run/verification-phase.d.ts.map +1 -1
- package/dist/core/verified-run/verification-phase.js +1 -1
- package/dist/core/verified-run/verification-phase.js.map +1 -1
- package/dist/core/verified-run/writer-phase.d.ts.map +1 -1
- package/dist/core/verified-run/writer-phase.js +1 -0
- package/dist/core/verified-run/writer-phase.js.map +1 -1
- package/dist/core/verified-run/writer-recovery.d.ts +2 -0
- package/dist/core/verified-run/writer-recovery.d.ts.map +1 -1
- package/dist/core/verified-run/writer-recovery.js +1 -0
- package/dist/core/verified-run/writer-recovery.js.map +1 -1
- package/dist/core/workload-shard-execution-types.d.ts +4 -1
- package/dist/core/workload-shard-execution-types.d.ts.map +1 -1
- package/dist/core/workload-shard-execution-types.js.map +1 -1
- package/dist/core/workload-shard-executor.d.ts +2 -2
- package/dist/core/workload-shard-executor.d.ts.map +1 -1
- package/dist/core/workload-shard-executor.js +16 -37
- package/dist/core/workload-shard-executor.js.map +1 -1
- package/dist/core/workload-shard-frontier.d.ts +5 -0
- package/dist/core/workload-shard-frontier.d.ts.map +1 -0
- package/dist/core/workload-shard-frontier.js +47 -0
- package/dist/core/workload-shard-frontier.js.map +1 -0
- package/dist/core/workload-shard-runner.d.ts.map +1 -1
- package/dist/core/workload-shard-runner.js +28 -17
- package/dist/core/workload-shard-runner.js.map +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +2 -1
- package/dist/main.js.map +1 -1
- package/dist/metacognition/bridge-result.d.ts +148 -0
- package/dist/metacognition/bridge-result.d.ts.map +1 -0
- package/dist/metacognition/bridge-result.js +46 -0
- package/dist/metacognition/bridge-result.js.map +1 -0
- package/dist/metacognition/calibration-selective.d.ts +78 -0
- package/dist/metacognition/calibration-selective.d.ts.map +1 -0
- package/dist/metacognition/calibration-selective.js +167 -0
- package/dist/metacognition/calibration-selective.js.map +1 -0
- package/dist/metacognition/calibration.d.ts +62 -0
- package/dist/metacognition/calibration.d.ts.map +1 -0
- package/dist/metacognition/calibration.js +122 -0
- package/dist/metacognition/calibration.js.map +1 -0
- package/dist/metacognition/checkpoint.d.ts +60 -0
- package/dist/metacognition/checkpoint.d.ts.map +1 -0
- package/dist/metacognition/checkpoint.js +57 -0
- package/dist/metacognition/checkpoint.js.map +1 -0
- package/dist/metacognition/context7.d.ts +48 -0
- package/dist/metacognition/context7.d.ts.map +1 -0
- package/dist/metacognition/context7.js +154 -0
- package/dist/metacognition/context7.js.map +1 -0
- package/dist/metacognition/decision.d.ts +44 -0
- package/dist/metacognition/decision.d.ts.map +1 -0
- package/dist/metacognition/decision.js +111 -0
- package/dist/metacognition/decision.js.map +1 -0
- package/dist/metacognition/evaluation.d.ts +73 -0
- package/dist/metacognition/evaluation.d.ts.map +1 -0
- package/dist/metacognition/evaluation.js +97 -0
- package/dist/metacognition/evaluation.js.map +1 -0
- package/dist/metacognition/index.d.ts +32 -0
- package/dist/metacognition/index.d.ts.map +1 -0
- package/dist/metacognition/index.js +32 -0
- package/dist/metacognition/index.js.map +1 -0
- package/dist/metacognition/knowledge-action.d.ts +43 -0
- package/dist/metacognition/knowledge-action.d.ts.map +1 -0
- package/dist/metacognition/knowledge-action.js +60 -0
- package/dist/metacognition/knowledge-action.js.map +1 -0
- package/dist/metacognition/knowledge.d.ts +84 -0
- package/dist/metacognition/knowledge.d.ts.map +1 -0
- package/dist/metacognition/knowledge.js +165 -0
- package/dist/metacognition/knowledge.js.map +1 -0
- package/dist/metacognition/obligations.d.ts +82 -0
- package/dist/metacognition/obligations.d.ts.map +1 -0
- package/dist/metacognition/obligations.js +139 -0
- package/dist/metacognition/obligations.js.map +1 -0
- package/dist/metacognition/observation-validity.d.ts +83 -0
- package/dist/metacognition/observation-validity.d.ts.map +1 -0
- package/dist/metacognition/observation-validity.js +118 -0
- package/dist/metacognition/observation-validity.js.map +1 -0
- package/dist/metacognition/observe.d.ts +45 -0
- package/dist/metacognition/observe.d.ts.map +1 -0
- package/dist/metacognition/observe.js +59 -0
- package/dist/metacognition/observe.js.map +1 -0
- package/dist/metacognition/policy.d.ts +53 -0
- package/dist/metacognition/policy.d.ts.map +1 -0
- package/dist/metacognition/policy.js +155 -0
- package/dist/metacognition/policy.js.map +1 -0
- package/dist/metacognition/predictions.d.ts +78 -0
- package/dist/metacognition/predictions.d.ts.map +1 -0
- package/dist/metacognition/predictions.js +181 -0
- package/dist/metacognition/predictions.js.map +1 -0
- package/dist/metacognition/retrieval.d.ts +53 -0
- package/dist/metacognition/retrieval.d.ts.map +1 -0
- package/dist/metacognition/retrieval.js +170 -0
- package/dist/metacognition/retrieval.js.map +1 -0
- package/dist/metacognition/risk.d.ts +48 -0
- package/dist/metacognition/risk.d.ts.map +1 -0
- package/dist/metacognition/risk.js +179 -0
- package/dist/metacognition/risk.js.map +1 -0
- package/dist/metacognition/route-economics.d.ts +95 -0
- package/dist/metacognition/route-economics.d.ts.map +1 -0
- package/dist/metacognition/route-economics.js +110 -0
- package/dist/metacognition/route-economics.js.map +1 -0
- package/dist/metacognition/runtime-bridge.d.ts +81 -0
- package/dist/metacognition/runtime-bridge.d.ts.map +1 -0
- package/dist/metacognition/runtime-bridge.js +458 -0
- package/dist/metacognition/runtime-bridge.js.map +1 -0
- package/dist/metacognition/skills.d.ts +42 -0
- package/dist/metacognition/skills.d.ts.map +1 -0
- package/dist/metacognition/skills.js +220 -0
- package/dist/metacognition/skills.js.map +1 -0
- package/dist/metacognition/state.d.ts +110 -0
- package/dist/metacognition/state.d.ts.map +1 -0
- package/dist/metacognition/state.js +52 -0
- package/dist/metacognition/state.js.map +1 -0
- package/dist/metacognition/validation.d.ts +19 -0
- package/dist/metacognition/validation.d.ts.map +1 -0
- package/dist/metacognition/validation.js +58 -0
- package/dist/metacognition/validation.js.map +1 -0
- package/dist/metacognition/verification.d.ts +93 -0
- package/dist/metacognition/verification.d.ts.map +1 -0
- package/dist/metacognition/verification.js +132 -0
- package/dist/metacognition/verification.js.map +1 -0
- package/dist/metacognition/verifier.d.ts +49 -0
- package/dist/metacognition/verifier.d.ts.map +1 -0
- package/dist/metacognition/verifier.js +88 -0
- package/dist/metacognition/verifier.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts +2 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +42 -26
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/chat-container.d.ts +7 -0
- package/dist/modes/interactive/components/chat-container.d.ts.map +1 -0
- package/dist/modes/interactive/components/chat-container.js +14 -0
- package/dist/modes/interactive/components/chat-container.js.map +1 -0
- package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
- package/dist/modes/interactive/components/dynamic-border.js +4 -2
- package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +0 -1
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-async-search.d.ts +33 -0
- package/dist/modes/interactive/components/session-selector-async-search.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-async-search.js +109 -0
- package/dist/modes/interactive/components/session-selector-async-search.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-loaders.d.ts +6 -0
- package/dist/modes/interactive/components/session-selector-loaders.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-loaders.js +9 -0
- package/dist/modes/interactive/components/session-selector-loaders.js.map +1 -0
- package/dist/modes/interactive/components/session-selector-search.d.ts +1 -1
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-tree.d.ts +16 -0
- package/dist/modes/interactive/components/session-selector-tree.d.ts.map +1 -0
- package/dist/modes/interactive/components/session-selector-tree.js +46 -0
- package/dist/modes/interactive/components/session-selector-tree.js.map +1 -0
- package/dist/modes/interactive/components/session-selector.d.ts +6 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +36 -76
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution-images.d.ts +32 -0
- package/dist/modes/interactive/components/tool-execution-images.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-execution-images.js +144 -0
- package/dist/modes/interactive/components/tool-execution-images.js.map +1 -0
- package/dist/modes/interactive/components/tool-execution.d.ts +3 -4
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +22 -71
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +7 -9
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/tui-diagnostics.d.ts +8 -4
- package/dist/modes/interactive/tui-diagnostics.d.ts.map +1 -1
- package/dist/modes/interactive/tui-diagnostics.js +35 -1
- package/dist/modes/interactive/tui-diagnostics.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +14 -17
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-response.d.ts +5 -0
- package/dist/modes/rpc/rpc-response.d.ts.map +1 -0
- package/dist/modes/rpc/rpc-response.js +17 -0
- package/dist/modes/rpc/rpc-response.js.map +1 -0
- package/dist/observation/identity.d.ts +14 -0
- package/dist/observation/identity.d.ts.map +1 -0
- package/dist/observation/identity.js +29 -0
- package/dist/observation/identity.js.map +1 -0
- package/dist/observation/index.d.ts +13 -0
- package/dist/observation/index.d.ts.map +1 -0
- package/dist/observation/index.js +13 -0
- package/dist/observation/index.js.map +1 -0
- package/dist/observation/observe-mode.d.ts +46 -0
- package/dist/observation/observe-mode.d.ts.map +1 -0
- package/dist/observation/observe-mode.js +83 -0
- package/dist/observation/observe-mode.js.map +1 -0
- package/dist/observation/store.d.ts +53 -0
- package/dist/observation/store.d.ts.map +1 -0
- package/dist/observation/store.js +126 -0
- package/dist/observation/store.js.map +1 -0
- package/dist/observation/types.d.ts +72 -0
- package/dist/observation/types.d.ts.map +1 -0
- package/dist/observation/types.js +9 -0
- package/dist/observation/types.js.map +1 -0
- package/dist/observation/view.d.ts +39 -0
- package/dist/observation/view.d.ts.map +1 -0
- package/dist/observation/view.js +173 -0
- package/dist/observation/view.js.map +1 -0
- package/dist/utils/exif-orientation.d.ts.map +1 -1
- package/dist/utils/exif-orientation.js +2 -3
- package/dist/utils/exif-orientation.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +3 -5
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/adaptorch-preview-spec.md +7 -7
- package/docs/atomic-commit-planning.md +69 -0
- package/docs/compaction.md +26 -1
- package/docs/extensions.md +14 -0
- package/docs/mcp.md +22 -0
- package/docs/metacognition.md +130 -0
- package/docs/model-catalog-refresh.md +218 -1
- package/docs/models.md +1 -1
- package/docs/providers.md +53 -0
- package/docs/runtime-algorithms.md +156 -7
- package/docs/session-format.md +8 -0
- package/docs/sessions.md +19 -0
- package/docs/skills.md +19 -0
- package/docs/terminal-setup.md +15 -0
- package/docs/tui.md +41 -0
- package/docs/verified-run-safety.md +75 -0
- package/examples/extensions/custom-provider-anthropic/index.ts +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/doom-overlay/wad-finder.ts +7 -3
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +18 -18
- package/package.json +6 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-budget-v2-scoring.js","sourceRoot":"","sources":["../../src/core/context-budget-v2-scoring.ts"],"names":[],"mappings":"AAkBA,MAAM,kBAAkB,GAA4C;IACnE,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,GAAG;IACT,MAAM,EAAE,EAAE;IACV,GAAG,EAAE,EAAE;CACP,CAAC;AAEF,gFAAgF;AAChF,MAAM,6BAA6B,GAAkD;IACpF,MAAM,EAAE,GAAG;IACX,aAAa,EAAE,EAAE;IACjB,eAAe,EAAE,CAAC;IAClB,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,GAAG,EAAE,CAAC;IACN,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,CAAC;CACV,CAAC;AAEF,MAAM,UAAU,wBAAwB,CAAC,IAAyB,EAAE,eAAuB,EAAU;IACpG,IAAI,IAAI,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,iBAAiB,CAAC;IACjC,CAAC;IACD,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnD,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC;IAC/C,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;IACzC,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC;IAClD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,GAAG,IAAI,CAAC;IAC5D,OAAO,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,IAAI,CAAC;AAAA,CACxD;AAED,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,CAC9C;AAED,SAAS,iBAAiB,CAAC,MAAc,EAAU;IAClD,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;AAAA,CAC1D;AAED;;;;;GAKG;AACH,SAAS,OAAO,CAAC,OAAsB,EAAU;IAChD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,OAAO,CAAC,cAAc,IAAI,CAAC,EAAE,CAAC;QAC7E,OAAO,OAAO,CAAC,cAAc,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IAChE,CAAC;IACD,MAAM,KAAK,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC;IAC7E,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAAA,CACvC","sourcesContent":["import type { ContextBudgetItemV2, ContextBudgetPriorityV2, ContextBudgetTierV2 } from \"./context-budget-headroom.ts\";\n\nexport interface PlannedItemV2 {\n\treadonly item: ContextBudgetItemV2;\n\treadonly fullTokens: number;\n\t/**\n\t * Cheapest non-omit representation cost, i.e. the true marginal cost of\n\t * admitting this item at all. Equals `fullTokens` when the item has no\n\t * cheaper pointer/summary/headroom representation.\n\t */\n\treadonly admissibleTokens: number;\n\treadonly contentHash: string;\n\treadonly baseScore: number;\n\tredundancyPenalty: number;\n\teffectiveScore: number;\n\treadonly isHard: boolean;\n}\n\nconst PRIORITY_WEIGHT_V2: Record<ContextBudgetPriorityV2, number> = {\n\thard: 1_000_000,\n\thigh: 120,\n\tmedium: 60,\n\tlow: 15,\n};\n\n/** E-folding time in turns: at this age the factor is exp(-1), not one half. */\nconst RECENCY_TIME_CONSTANT_BY_TIER: Readonly<Record<ContextBudgetTierV2, number>> = {\n\tsystem: 999,\n\t\"active-goal\": 12,\n\t\"current-files\": 8,\n\ttools: 4,\n\tskills: 6,\n\tmcp: 6,\n\thistory: 3,\n\tevidence: 8,\n\tscratch: 2,\n};\n\nexport function scoreContextBudgetItemV2(item: ContextBudgetItemV2, estimatedTokens: number): number {\n\tif (item.priority === \"hard\") {\n\t\treturn Number.POSITIVE_INFINITY;\n\t}\n\tconst priority = PRIORITY_WEIGHT_V2[item.priority];\n\tconst relevance = clamp01(item.relevance) * 25;\n\tconst recency = deriveRecency(item) * 15;\n\tconst evidence = clamp01(item.evidenceValue) * 25;\n\tconst cost = Math.sqrt(Math.max(0, estimatedTokens)) * 0.55;\n\treturn priority + relevance + recency + evidence - cost;\n}\n\nexport function applyRedundancyPenalties(items: readonly PlannedItemV2[]): Map<string, number> {\n\tconst penalties = new Map<string, number>();\n\tconst groups = new Map<string, PlannedItemV2[]>();\n\tfor (const planned of items) {\n\t\tif (!planned.item.redundancyKey) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst group = groups.get(planned.item.redundancyKey);\n\t\tif (group) {\n\t\t\tgroup.push(planned);\n\t\t} else {\n\t\t\tgroups.set(planned.item.redundancyKey, [planned]);\n\t\t}\n\t}\n\tfor (const group of groups.values()) {\n\t\tif (group.length <= 1) {\n\t\t\tcontinue;\n\t\t}\n\t\tgroup.sort((a, b) => {\n\t\t\tif (b.baseScore !== a.baseScore) {\n\t\t\t\treturn b.baseScore - a.baseScore;\n\t\t\t}\n\t\t\treturn a.item.id.localeCompare(b.item.id);\n\t\t});\n\t\tfor (let index = 1; index < group.length; index++) {\n\t\t\tconst duplicate = group[index];\n\t\t\tpenalties.set(duplicate.item.id, redundancyPenalty(duplicate.fullTokens) * index);\n\t\t}\n\t}\n\treturn penalties;\n}\n\n/**\n * Order optional items for the budgeted 0/1 knapsack the planner greedily fills.\n *\n * Value density (effective score per token) is the primary key. Ordering by\n * priority class first would let a single expensive `high` item evict an\n * arbitrary number of far denser `medium` items, which makes the greedy\n * unbounded-bad against the optimal packing. Priority still shapes the outcome\n * through `PRIORITY_WEIGHT_V2` in the score numerator, and non-negotiable\n * context uses `hard`/`required`, which the planner pins before this ordering\n * is consulted. Remaining keys break ties into a deterministic total order.\n */\nexport function compareOptionalForSelection(a: PlannedItemV2, b: PlannedItemV2): number {\n\tconst aDensity = density(a);\n\tconst bDensity = density(b);\n\tif (bDensity !== aDensity) {\n\t\treturn bDensity - aDensity;\n\t}\n\tconst aScore = Number.isNaN(a.effectiveScore) ? Number.NEGATIVE_INFINITY : a.effectiveScore;\n\tconst bScore = Number.isNaN(b.effectiveScore) ? Number.NEGATIVE_INFINITY : b.effectiveScore;\n\tif (bScore !== aScore) return bScore - aScore;\n\tconst priorityDelta = priorityRank(b.item.priority) - priorityRank(a.item.priority);\n\tif (priorityDelta !== 0) {\n\t\treturn priorityDelta;\n\t}\n\tconst aTokens = Number.isNaN(a.fullTokens) ? Number.POSITIVE_INFINITY : a.fullTokens;\n\tconst bTokens = Number.isNaN(b.fullTokens) ? Number.POSITIVE_INFINITY : b.fullTokens;\n\tif (aTokens !== bTokens) return aTokens - bTokens;\n\treturn a.item.id.localeCompare(b.item.id);\n}\n\nfunction priorityRank(priority: ContextBudgetPriorityV2): number {\n\tswitch (priority) {\n\t\tcase \"hard\":\n\t\t\treturn 4;\n\t\tcase \"high\":\n\t\t\treturn 3;\n\t\tcase \"medium\":\n\t\t\treturn 2;\n\t\tcase \"low\":\n\t\t\treturn 1;\n\t}\n}\n\nfunction clamp01(value: number | undefined): number {\n\tif (value === undefined || !Number.isFinite(value)) {\n\t\treturn 0;\n\t}\n\treturn Math.max(0, Math.min(1, value));\n}\n\nfunction deriveRecency(item: ContextBudgetItemV2): number {\n\tif (item.recency !== undefined) {\n\t\treturn clamp01(item.recency);\n\t}\n\tconst age = item.ageTurns ?? 0;\n\tconst timeConstant = RECENCY_TIME_CONSTANT_BY_TIER[item.tier] ?? 6;\n\treturn clamp01(Math.exp(-age / timeConstant));\n}\n\nfunction redundancyPenalty(tokens: number): number {\n\treturn Math.max(10, Math.sqrt(Math.max(0, tokens)) * 0.8);\n}\n\n/**\n * Value per token of the CHEAPEST admissible representation. Dividing by\n * `fullTokens` would systematically penalize retrievable or summarizable items,\n * which are exactly the items the planner admits cheaply when the budget is\n * tight — the regime where this ordering decides anything at all.\n */\nfunction density(planned: PlannedItemV2): number {\n\tif (!Number.isFinite(planned.effectiveScore) || planned.effectiveScore <= 0) {\n\t\treturn planned.effectiveScore > 0 ? planned.effectiveScore : 0;\n\t}\n\tconst value = planned.effectiveScore / Math.max(planned.admissibleTokens, 1);\n\treturn Number.isNaN(value) ? 0 : value;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"context-budget-v2-scoring.js","sourceRoot":"","sources":["../../src/core/context-budget-v2-scoring.ts"],"names":[],"mappings":"AA6BA,MAAM,kBAAkB,GAA4C;IACnE,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,GAAG;IACT,MAAM,EAAE,EAAE;IACV,GAAG,EAAE,EAAE;CACP,CAAC;AAEF,gFAAgF;AAChF,MAAM,6BAA6B,GAAkD;IACpF,MAAM,EAAE,GAAG;IACX,aAAa,EAAE,EAAE;IACjB,eAAe,EAAE,CAAC;IAClB,KAAK,EAAE,CAAC;IACR,MAAM,EAAE,CAAC;IACT,GAAG,EAAE,CAAC;IACN,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,CAAC;CACV,CAAC;AAEF,MAAM,UAAU,wBAAwB,CAAC,IAAyB,EAAE,eAAuB,EAAU;IACpG,IAAI,IAAI,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,iBAAiB,CAAC;IACjC,CAAC;IACD,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnD,MAAM,SAAS,GAAG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V2,\n} from \"./context-budget-headroom.ts\";\n\nexport interface PlannedItemV2 {\n\treadonly item: ContextBudgetItemV2;\n\treadonly fullTokens: number;\n\t/**\n\t * Cheapest non-omit representation cost, i.e. the true marginal cost of\n\t * admitting this item at all. Equals `fullTokens` when the item has no\n\t * cheaper pointer/summary/headroom representation.\n\t */\n\treadonly admissibleTokens: number;\n\t/**\n\t * Representations priced with the planner's token counter. Selection must\n\t * choose from these rather than re-deriving with a different estimator, or\n\t * the cost an item was ranked on and the cost it pays can diverge.\n\t */\n\treadonly candidates?: readonly ContextRepresentationCandidateV2[];\n\treadonly contentHash: string;\n\treadonly baseScore: number;\n\tredundancyPenalty: number;\n\teffectiveScore: number;\n\treadonly isHard: boolean;\n}\n\nconst PRIORITY_WEIGHT_V2: Record<ContextBudgetPriorityV2, number> = {\n\thard: 1_000_000,\n\thigh: 120,\n\tmedium: 60,\n\tlow: 15,\n};\n\n/** E-folding time in turns: at this age the factor is exp(-1), not one half. */\nconst RECENCY_TIME_CONSTANT_BY_TIER: Readonly<Record<ContextBudgetTierV2, number>> = {\n\tsystem: 999,\n\t\"active-goal\": 12,\n\t\"current-files\": 8,\n\ttools: 4,\n\tskills: 6,\n\tmcp: 6,\n\thistory: 3,\n\tevidence: 8,\n\tscratch: 2,\n};\n\nexport function scoreContextBudgetItemV2(item: ContextBudgetItemV2, estimatedTokens: number): number {\n\tif (item.priority === \"hard\") {\n\t\treturn Number.POSITIVE_INFINITY;\n\t}\n\tconst priority = PRIORITY_WEIGHT_V2[item.priority];\n\tconst relevance = clamp01(item.relevance) * 25;\n\tconst recency = deriveRecency(item) * 15;\n\tconst evidence = clamp01(item.evidenceValue) * 25;\n\tconst cost = Math.sqrt(Math.max(0, estimatedTokens)) * 0.55;\n\treturn priority + relevance + recency + evidence - cost;\n}\n\nexport function applyRedundancyPenalties(items: readonly PlannedItemV2[]): Map<string, number> {\n\tconst penalties = new Map<string, number>();\n\tconst groups = new Map<string, PlannedItemV2[]>();\n\tfor (const planned of items) {\n\t\tif (!planned.item.redundancyKey) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst group = groups.get(planned.item.redundancyKey);\n\t\tif (group) {\n\t\t\tgroup.push(planned);\n\t\t} else {\n\t\t\tgroups.set(planned.item.redundancyKey, [planned]);\n\t\t}\n\t}\n\tfor (const group of groups.values()) {\n\t\tif (group.length <= 1) {\n\t\t\tcontinue;\n\t\t}\n\t\tgroup.sort((a, b) => {\n\t\t\tif (b.baseScore !== a.baseScore) {\n\t\t\t\treturn b.baseScore - a.baseScore;\n\t\t\t}\n\t\t\treturn a.item.id.localeCompare(b.item.id);\n\t\t});\n\t\tfor (let index = 1; index < group.length; index++) {\n\t\t\tconst duplicate = group[index];\n\t\t\tpenalties.set(duplicate.item.id, redundancyPenalty(duplicate.fullTokens) * index);\n\t\t}\n\t}\n\treturn penalties;\n}\n\n/**\n * Order optional items for the budgeted 0/1 knapsack the planner greedily fills.\n *\n * Value density (effective score per token) is the primary key. Ordering by\n * priority class first would let a single expensive `high` item evict an\n * arbitrary number of far denser `medium` items, which makes the greedy\n * unbounded-bad against the optimal packing. Priority still shapes the outcome\n * through `PRIORITY_WEIGHT_V2` in the score numerator, and non-negotiable\n * context uses `hard`/`required`, which the planner pins before this ordering\n * is consulted. Remaining keys break ties into a deterministic total order.\n */\nexport function compareOptionalForSelection(a: PlannedItemV2, b: PlannedItemV2): number {\n\tconst aDensity = density(a);\n\tconst bDensity = density(b);\n\tif (bDensity !== aDensity) {\n\t\treturn bDensity - aDensity;\n\t}\n\tconst aScore = Number.isNaN(a.effectiveScore) ? Number.NEGATIVE_INFINITY : a.effectiveScore;\n\tconst bScore = Number.isNaN(b.effectiveScore) ? Number.NEGATIVE_INFINITY : b.effectiveScore;\n\tif (bScore !== aScore) return bScore - aScore;\n\tconst priorityDelta = priorityRank(b.item.priority) - priorityRank(a.item.priority);\n\tif (priorityDelta !== 0) {\n\t\treturn priorityDelta;\n\t}\n\tconst aTokens = Number.isNaN(a.fullTokens) ? Number.POSITIVE_INFINITY : a.fullTokens;\n\tconst bTokens = Number.isNaN(b.fullTokens) ? Number.POSITIVE_INFINITY : b.fullTokens;\n\tif (aTokens !== bTokens) return aTokens - bTokens;\n\treturn a.item.id.localeCompare(b.item.id);\n}\n\nfunction priorityRank(priority: ContextBudgetPriorityV2): number {\n\tswitch (priority) {\n\t\tcase \"hard\":\n\t\t\treturn 4;\n\t\tcase \"high\":\n\t\t\treturn 3;\n\t\tcase \"medium\":\n\t\t\treturn 2;\n\t\tcase \"low\":\n\t\t\treturn 1;\n\t}\n}\n\nfunction clamp01(value: number | undefined): number {\n\tif (value === undefined || !Number.isFinite(value)) {\n\t\treturn 0;\n\t}\n\treturn Math.max(0, Math.min(1, value));\n}\n\nfunction deriveRecency(item: ContextBudgetItemV2): number {\n\tif (item.recency !== undefined) {\n\t\treturn clamp01(item.recency);\n\t}\n\tconst age = item.ageTurns ?? 0;\n\tconst timeConstant = RECENCY_TIME_CONSTANT_BY_TIER[item.tier] ?? 6;\n\treturn clamp01(Math.exp(-age / timeConstant));\n}\n\nfunction redundancyPenalty(tokens: number): number {\n\treturn Math.max(10, Math.sqrt(Math.max(0, tokens)) * 0.8);\n}\n\n/**\n * Value per token of the CHEAPEST admissible representation. Dividing by\n * `fullTokens` would systematically penalize retrievable or summarizable items,\n * which are exactly the items the planner admits cheaply when the budget is\n * tight — the regime where this ordering decides anything at all.\n */\nfunction density(planned: PlannedItemV2): number {\n\tif (!Number.isFinite(planned.effectiveScore) || planned.effectiveScore <= 0) {\n\t\treturn planned.effectiveScore > 0 ? planned.effectiveScore : 0;\n\t}\n\tconst value = planned.effectiveScore / Math.max(planned.admissibleTokens, 1);\n\treturn Number.isNaN(value) ? 0 : value;\n}\n"]}
|
|
@@ -3,8 +3,10 @@ import { type ContextBudgetSelectionCacheV2 } from "./context-budget-v2-cache.ts
|
|
|
3
3
|
import { type PlannedItemV2 } from "./context-budget-v2-scoring.ts";
|
|
4
4
|
import { type QualityDiagnosticV2, type SelectedRepresentationV2, type TierBudgetAllocationV2 } from "./context-budget-v2-types.ts";
|
|
5
5
|
export interface OptionalSelectionState {
|
|
6
|
+
/** Per-tier caps; `floor` is the tier's reservation, which the exchange pass must not raid. */
|
|
6
7
|
readonly allocation: ReadonlyMap<ContextBudgetTierV2, {
|
|
7
8
|
readonly ceiling: number;
|
|
9
|
+
readonly floor?: number;
|
|
8
10
|
}>;
|
|
9
11
|
readonly available: number;
|
|
10
12
|
readonly cache?: ContextBudgetSelectionCacheV2;
|
|
@@ -47,4 +49,5 @@ export declare function buildTierAllocations(allocation: ReadonlyMap<ContextBudg
|
|
|
47
49
|
readonly hard: number;
|
|
48
50
|
}>, tierUsed: Record<ContextBudgetTierV2, number>): TierBudgetAllocationV2[];
|
|
49
51
|
export declare function createTierUsage(): Record<ContextBudgetTierV2, number>;
|
|
52
|
+
export declare function toSelected(itemId: string, candidate: ContextRepresentationCandidateV2): SelectedRepresentationV2;
|
|
50
53
|
//# sourceMappingURL=context-budget-v2-selection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-budget-v2-selection.d.ts","sourceRoot":"","sources":["../../src/core/context-budget-v2-selection.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,gCAAgC,EACrC,KAAK,kBAAkB,EACvB,4BAA4B,EAE5B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAEN,KAAK,6BAA6B,EAElC,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAA4B,KAAK,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC9F,OAAO,EAEN,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC3B,MAAM,8BAA8B,CAAC;AAEtC,MAAM,WAAW,sBAAsB;IACtC,QAAQ,CAAC,UAAU,EAAE,WAAW,CAAC,mBAAmB,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;K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EAAE,EACvC,WAAW,EAAE,mBAAmB,EAAE,EAClC,kBAAkB,EAAE,kBAAkB,EAAE,GACtC,IAAI,CAkBN;AAED,wBAAgB,uBAAuB,CACtC,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,wBAAwB,CAAC,EACxD,WAAW,EAAE,mBAAmB,EAAE,GAChC,IAAI,CAUN;AAED,wBAAgB,oBAAoB,CACnC,UAAU,EAAE,WAAW,CACtB,mBAAmB,EACnB;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAChF,EACD,MAAM,EAAE,WAAW,CAAC,mBAAmB,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,EACnE,QAAQ,EAAE,MAAM,CAAC,mBAAmB,EAAE,MAAM,CAAC,GAC3C,sBAAsB,EAAE,CAY1B;AAED,wBAAgB,eAAe,IAAI,MAAM,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAErE","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\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\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\tconst candidates = planned.item.representations ?? deriveRepresentationCandidates(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\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.d.ts","sourceRoot":"","sources":["../../src/core/context-budget-v2-selection.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,gCAA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AM,EAAE,MAAM,EAAE,SAAS,EAAE,gCAAgC,GAAG,wBAAwB,CAYhH","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"]}
|
|
@@ -46,7 +46,11 @@ export function selectOptionalItem(planned, state) {
|
|
|
46
46
|
? floorPass.floorTokens
|
|
47
47
|
: (state.allocation.get(planned.item.tier)?.ceiling ?? state.available);
|
|
48
48
|
const remaining = Math.max(0, state.available - state.usedTokens);
|
|
49
|
-
|
|
49
|
+
// Prefer the planner-priced candidates: re-deriving here with the default
|
|
50
|
+
// heuristic would price the chosen text differently from the ranking cost.
|
|
51
|
+
const candidates = planned.candidates ??
|
|
52
|
+
planned.item.representations ??
|
|
53
|
+
deriveRepresentationCandidates(planned.item, state.qualityPolicy);
|
|
50
54
|
const materializedEnabled = planned.item.representations === undefined;
|
|
51
55
|
let cachedCandidates = state.resolvedCandidates?.get(planned.item.id);
|
|
52
56
|
if (cachedCandidates === undefined) {
|
|
@@ -149,7 +153,7 @@ export function buildTierAllocations(allocation, demand, tierUsed) {
|
|
|
149
153
|
export function createTierUsage() {
|
|
150
154
|
return Object.fromEntries(ALL_TIERS_V2.map((tier) => [tier, 0]));
|
|
151
155
|
}
|
|
152
|
-
function toSelected(itemId, candidate) {
|
|
156
|
+
export function toSelected(itemId, candidate) {
|
|
153
157
|
return {
|
|
154
158
|
itemId,
|
|
155
159
|
kind: candidate.kind,
|
|
@@ -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,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;AA8BtC,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,EAAE,MAAM;QACZ,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI;QACvB,eAA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;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\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\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\tconst candidates = planned.item.representations ?? deriveRepresentationCandidates(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\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,0BA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AC,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"]}
|
|
@@ -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";
|
|
@@ -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;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,o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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 */\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\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"]}
|
|
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,4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,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;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 */\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\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"]}
|
|
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"]}
|
|
@@ -1826,6 +1826,20 @@
|
|
|
1826
1826
|
return element.isContentEditable || Boolean(element.closest?.('[contenteditable="true"]'));
|
|
1827
1827
|
};
|
|
1828
1828
|
|
|
1829
|
+
const attachHeaderHandlers = () => {
|
|
1830
|
+
document.querySelector('[data-action="toggle-thinking"]')?.addEventListener('click', toggleThinking);
|
|
1831
|
+
document.querySelector('[data-action="toggle-tools"]')?.addEventListener('click', toggleToolOutputs);
|
|
1832
|
+
};
|
|
1833
|
+
|
|
1834
|
+
const isEditableTarget = (element) => {
|
|
1835
|
+
if (!element) return false;
|
|
1836
|
+
const tagName = element.tagName;
|
|
1837
|
+
if (tagName === 'INPUT' || tagName === 'TEXTAREA' || tagName === 'SELECT' || tagName === 'BUTTON') {
|
|
1838
|
+
return true;
|
|
1839
|
+
}
|
|
1840
|
+
return element.isContentEditable || Boolean(element.closest?.('[contenteditable="true"]'));
|
|
1841
|
+
};
|
|
1842
|
+
|
|
1829
1843
|
// Keyboard shortcuts
|
|
1830
1844
|
document.addEventListener('keydown', (e) => {
|
|
1831
1845
|
if (e.key === 'Escape') {
|
|
@@ -6,7 +6,7 @@ export type { SourceInfo } from "../source-info.ts";
|
|
|
6
6
|
export { createExtensionRuntime, discoverAndLoadExtensions, loadExtensionFromFactory, loadExtensions, } from "./loader.ts";
|
|
7
7
|
export type { ExtensionErrorListener, ForkHandler, NavigateTreeHandler, NewSessionHandler, ShutdownHandler, SwitchSessionHandler, } from "./runner.ts";
|
|
8
8
|
export { ExtensionRunner } from "./runner.ts";
|
|
9
|
-
export type { AfterProviderResponseEvent, AgentEndEvent, AgentStartEvent, AgentToolResult, AgentToolUpdateCallback, AppendEntryHandler, AppKeybinding, AutocompleteProviderFactory, BashToolCallEvent, BashToolResultEvent, BeforeAgentStartEvent, BeforeAgentStartEventResult, BeforeProviderRequestEvent, BeforeProviderRequestEventResult, BuildSystemPromptOptions, CompactOptions, ContextEvent, ContextEventResult, ContextUsage, CustomToolCallEvent, CustomToolResultEvent, EditorFactory, EditToolCallEvent, EditToolResultEvent, ExecOptions, ExecResult, Extension, ExtensionActions, ExtensionAPI, ExtensionCommandContext, ExtensionCommandContextActions, ExtensionContext, ExtensionContextActions, ExtensionError, ExtensionEvent, ExtensionFactory, ExtensionFlag, ExtensionHandler, ExtensionMode, ExtensionRuntime, ExtensionShortcut, ExtensionUIContext, ExtensionUIDialogOptions, ExtensionWidgetOptions, FindToolCallEvent, FindToolResultEvent, GetActiveToolsHandler, GetAllToolsHandler, GetCommandsHandler, GetThinkingLevelHandler, GrepToolCallEvent, GrepToolResultEvent, InputEvent, InputEventResult, InputSource, KeybindingsManager, LoadExtensionsResult, LsToolCallEvent, LsToolResultEvent, MessageEndEvent, MessageRenderer, MessageRenderOptions, MessageStartEvent, MessageUpdateEvent, ModelSelectEvent, ModelSelectSource, ProviderConfig, ProviderModelConfig, ReadToolCallEvent, ReadToolResultEvent, RegisteredCommand, RegisteredTool, ReplacedSessionContext, ResolvedCommand, ResourcesDiscoverEvent, ResourcesDiscoverResult, SendMessageHandler, SendUserMessageHandler, SessionBeforeCompactEvent, SessionBeforeCompactResult, SessionBeforeForkEvent, SessionBeforeForkResult, SessionBeforeSwitchEvent, SessionBeforeSwitchResult, SessionBeforeTreeEvent, SessionBeforeTreeResult, SessionCompactEvent, SessionEvent, SessionShutdownEvent, SessionStartEvent, SessionTreeEvent, SetActiveToolsHandler, SetLabelHandler, SetModelHandler, SetThinkingLevelHandler, TerminalInputHandler, ToolCallEvent, ToolCallEventResult, ToolDefinition, ToolExecutionEndEvent, ToolExecutionMode, ToolExecutionStartEvent, ToolExecutionUpdateEvent, ToolInfo, ToolRenderResultOptions, ToolResultEvent, ToolResultEventResult, TreePreparation, TurnEndEvent, TurnStartEvent, UserBashEvent, UserBashEventResult, WidgetPlacement, WorkingIndicatorOptions, WriteToolCallEvent, WriteToolResultEvent, } from "./types.ts";
|
|
9
|
+
export type { AfterProviderResponseEvent, AgentEndEvent, AgentStartEvent, AgentToolResult, AgentToolUpdateCallback, AppendEntryHandler, AppKeybinding, AutocompleteProviderFactory, BashToolCallEvent, BashToolResultEvent, BeforeAgentStartEvent, BeforeAgentStartEventResult, BeforeProviderRequestEvent, BeforeProviderRequestEventResult, BuildSystemPromptOptions, CompactOptions, ContextEvent, ContextEventResult, ContextUsage, CustomToolCallEvent, CustomToolResultEvent, EditorFactory, EditToolCallEvent, EditToolResultEvent, ExecOptions, ExecResult, Extension, ExtensionActions, ExtensionAPI, ExtensionCommandContext, ExtensionCommandContextActions, ExtensionContext, ExtensionContextActions, ExtensionError, ExtensionEvent, ExtensionFactory, ExtensionFlag, ExtensionHandler, ExtensionMode, ExtensionRuntime, ExtensionShortcut, ExtensionUIContext, ExtensionUIDialogOptions, ExtensionWidgetOptions, FindToolCallEvent, FindToolResultEvent, GetActiveToolsHandler, GetAllToolsHandler, GetCommandsHandler, GetThinkingLevelHandler, GrepToolCallEvent, GrepToolResultEvent, InputEvent, InputEventResult, InputSource, KeybindingsManager, LoadExtensionsResult, LsToolCallEvent, LsToolResultEvent, MessageEndEvent, MessageRenderer, MessageRenderOptions, MessageStartEvent, MessageUpdateEvent, ModelSelectEvent, ModelSelectSource, ProviderConfig, ProviderModelConfig, ReadToolCallEvent, ReadToolResultEvent, RegisteredCommand, RegisteredTool, ReplacedSessionContext, ResolvedCommand, ResourcesDiscoverEvent, ResourcesDiscoverResult, SendMessageHandler, SendUserMessageHandler, SessionBeforeCompactEvent, SessionBeforeCompactResult, SessionBeforeForkEvent, SessionBeforeForkResult, SessionBeforeSwitchEvent, SessionBeforeSwitchResult, SessionBeforeTreeEvent, SessionBeforeTreeResult, SessionCompactEvent, SessionEvent, SessionInfoChangedEvent, SessionShutdownEvent, SessionStartEvent, SessionTreeEvent, SetActiveToolsHandler, SetLabelHandler, SetModelHandler, SetThinkingLevelHandler, TerminalInputHandler, ToolCallEvent, ToolCallEventResult, ToolDefinition, ToolExecutionEndEvent, ToolExecutionMode, ToolExecutionStartEvent, ToolExecutionUpdateEvent, ToolInfo, ToolRenderResultOptions, ToolResultEvent, ToolResultEventResult, TreePreparation, TurnEndEvent, TurnStartEvent, UserBashEvent, UserBashEventResult, WidgetPlacement, WorkingIndicatorOptions, WriteToolCallEvent, WriteToolResultEvent, } from "./types.ts";
|
|
10
10
|
export { defineTool, isBashToolResult, isEditToolResult, isFindToolResult, isGrepToolResult, isLsToolResult, isReadToolResult, isToolCallEventType, isWriteToolResult, } from "./types.ts";
|
|
11
11
|
export { wrapRegisteredTool, wrapRegisteredTools } from "./wrapper.ts";
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACjF,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACN,sBAAsB,EACtB,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,GACd,MAAM,aAAa,CAAC;AACrB,YAAY,EACX,sBAAsB,EACtB,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EACX,0BAA0B,EAC1B,aAAa,EACb,eAAe,EAEf,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAElB,aAAa,EACb,2BAA2B,EAE3B,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,2BAA2B,EAC3B,0BAA0B,EAC1B,gCAAgC,EAChC,wBAAwB,EAExB,cAAc,EAEd,YAAY,EAEZ,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,qBAAqB,EACrB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,UAAU,EACV,SAAS,EACT,gBAAgB,EAEhB,YAAY,EACZ,uBAAuB,EACvB,8BAA8B,EAC9B,gBAAgB,EAChB,uBAAuB,EAEvB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,aAAa,E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iBAAiB,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC","sourcesContent":["/**\n * Extension system for lifecycle events and custom tools.\n */\n\nexport type { SlashCommandInfo, SlashCommandSource } from \"../slash-commands.ts\";\nexport type { SourceInfo } from \"../source-info.ts\";\nexport {\n\tcreateExtensionRuntime,\n\tdiscoverAndLoadExtensions,\n\tloadExtensionFromFactory,\n\tloadExtensions,\n} from \"./loader.ts\";\nexport type {\n\tExtensionErrorListener,\n\tForkHandler,\n\tNavigateTreeHandler,\n\tNewSessionHandler,\n\tShutdownHandler,\n\tSwitchSessionHandler,\n} from \"./runner.ts\";\nexport { ExtensionRunner } from \"./runner.ts\";\nexport type {\n\tAfterProviderResponseEvent,\n\tAgentEndEvent,\n\tAgentStartEvent,\n\t// Re-exports\n\tAgentToolResult,\n\tAgentToolUpdateCallback,\n\tAppendEntryHandler,\n\t// App keybindings (for custom editors)\n\tAppKeybinding,\n\tAutocompleteProviderFactory,\n\t// Events - Tool (ToolCallEvent types)\n\tBashToolCallEvent,\n\tBashToolResultEvent,\n\tBeforeAgentStartEvent,\n\tBeforeAgentStartEventResult,\n\tBeforeProviderRequestEvent,\n\tBeforeProviderRequestEventResult,\n\tBuildSystemPromptOptions,\n\t// Context\n\tCompactOptions,\n\t// Events - Agent\n\tContextEvent,\n\t// Event Results\n\tContextEventResult,\n\tContextUsage,\n\tCustomToolCallEvent,\n\tCustomToolResultEvent,\n\tEditorFactory,\n\tEditToolCallEvent,\n\tEditToolResultEvent,\n\tExecOptions,\n\tExecResult,\n\tExtension,\n\tExtensionActions,\n\t// API\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionCommandContextActions,\n\tExtensionContext,\n\tExtensionContextActions,\n\t// Errors\n\tExtensionError,\n\tExtensionEvent,\n\tExtensionFactory,\n\tExtensionFlag,\n\tExtensionHandler,\n\tExtensionMode,\n\t// Runtime\n\tExtensionRuntime,\n\tExtensionShortcut,\n\tExtensionUIContext,\n\tExtensionUIDialogOptions,\n\tExtensionWidgetOptions,\n\tFindToolCallEvent,\n\tFindToolResultEvent,\n\tGetActiveToolsHandler,\n\tGetAllToolsHandler,\n\tGetCommandsHandler,\n\tGetThinkingLevelHandler,\n\tGrepToolCallEvent,\n\tGrepToolResultEvent,\n\t// Events - Input\n\tInputEvent,\n\tInputEventResult,\n\tInputSource,\n\tKeybindingsManager,\n\tLoadExtensionsResult,\n\tLsToolCallEvent,\n\tLsToolResultEvent,\n\t// Events - Message\n\tMessageEndEvent,\n\t// Message Rendering\n\tMessageRenderer,\n\tMessageRenderOptions,\n\tMessageStartEvent,\n\tMessageUpdateEvent,\n\tModelSelectEvent,\n\tModelSelectSource,\n\t// Provider Registration\n\tProviderConfig,\n\tProviderModelConfig,\n\tReadToolCallEvent,\n\tReadToolResultEvent,\n\t// Commands\n\tRegisteredCommand,\n\tRegisteredTool,\n\tReplacedSessionContext,\n\tResolvedCommand,\n\t// Events - Resources\n\tResourcesDiscoverEvent,\n\tResourcesDiscoverResult,\n\tSendMessageHandler,\n\tSendUserMessageHandler,\n\tSessionBeforeCompactEvent,\n\tSessionBeforeCompactResult,\n\tSessionBeforeForkEvent,\n\tSessionBeforeForkResult,\n\tSessionBeforeSwitchEvent,\n\tSessionBeforeSwitchResult,\n\tSessionBeforeTreeEvent,\n\tSessionBeforeTreeResult,\n\tSessionCompactEvent,\n\tSessionEvent,\n\tSessionShutdownEvent,\n\t// Events - Session\n\tSessionStartEvent,\n\tSessionTreeEvent,\n\tSetActiveToolsHandler,\n\tSetLabelHandler,\n\tSetModelHandler,\n\tSetThinkingLevelHandler,\n\tTerminalInputHandler,\n\t// Events - Tool\n\tToolCallEvent,\n\tToolCallEventResult,\n\t// Tools\n\tToolDefinition,\n\t// Events - Tool Execution\n\tToolExecutionEndEvent,\n\t// Tool execution mode\n\tToolExecutionMode,\n\tToolExecutionStartEvent,\n\tToolExecutionUpdateEvent,\n\tToolInfo,\n\tToolRenderResultOptions,\n\tToolResultEvent,\n\tToolResultEventResult,\n\tTreePreparation,\n\tTurnEndEvent,\n\tTurnStartEvent,\n\t// Events - User Bash\n\tUserBashEvent,\n\tUserBashEventResult,\n\tWidgetPlacement,\n\tWorkingIndicatorOptions,\n\tWriteToolCallEvent,\n\tWriteToolResultEvent,\n} from \"./types.ts\";\n// Type guards\nexport {\n\tdefineTool,\n\tisBashToolResult,\n\tisEditToolResult,\n\tisFindToolResult,\n\tisGrepToolResult,\n\tisLsToolResult,\n\tisReadToolResult,\n\tisToolCallEventType,\n\tisWriteToolResult,\n} from \"./types.ts\";\nexport { wrapRegisteredTool, wrapRegisteredTools } from \"./wrapper.ts\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,YAAY,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACjF,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACN,sBAAsB,EACtB,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,GACd,MAAM,aAAa,CAAC;AACrB,YAAY,EACX,sBAAsB,EACtB,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,GACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EACX,0BAA0B,EAC1B,aAAa,EACb,eAAe,EAEf,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAElB,aAAa,EACb,2BAA2B,EAE3B,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,2BAA2B,EAC3B,0BAA0B,EAC1B,gCAAgC,EAChC,wBAAwB,EAExB,cAAc,EAEd,YAAY,EAEZ,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,qBAAqB,EACrB,aAAa,EACb,iBAAiB,EACjB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,EACf,uBAAuB,EACvB,kBAAkB,EAClB,oBAAoB,GACpB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACN,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC","sourcesContent":["/**\n * Extension system for lifecycle events and custom tools.\n */\n\nexport type { SlashCommandInfo, SlashCommandSource } from \"../slash-commands.ts\";\nexport type { SourceInfo } from \"../source-info.ts\";\nexport {\n\tcreateExtensionRuntime,\n\tdiscoverAndLoadExtensions,\n\tloadExtensionFromFactory,\n\tloadExtensions,\n} from \"./loader.ts\";\nexport type {\n\tExtensionErrorListener,\n\tForkHandler,\n\tNavigateTreeHandler,\n\tNewSessionHandler,\n\tShutdownHandler,\n\tSwitchSessionHandler,\n} from \"./runner.ts\";\nexport { ExtensionRunner } from \"./runner.ts\";\nexport type {\n\tAfterProviderResponseEvent,\n\tAgentEndEvent,\n\tAgentStartEvent,\n\t// Re-exports\n\tAgentToolResult,\n\tAgentToolUpdateCallback,\n\tAppendEntryHandler,\n\t// App keybindings (for custom editors)\n\tAppKeybinding,\n\tAutocompleteProviderFactory,\n\t// Events - Tool (ToolCallEvent types)\n\tBashToolCallEvent,\n\tBashToolResultEvent,\n\tBeforeAgentStartEvent,\n\tBeforeAgentStartEventResult,\n\tBeforeProviderRequestEvent,\n\tBeforeProviderRequestEventResult,\n\tBuildSystemPromptOptions,\n\t// Context\n\tCompactOptions,\n\t// Events - Agent\n\tContextEvent,\n\t// Event Results\n\tContextEventResult,\n\tContextUsage,\n\tCustomToolCallEvent,\n\tCustomToolResultEvent,\n\tEditorFactory,\n\tEditToolCallEvent,\n\tEditToolResultEvent,\n\tExecOptions,\n\tExecResult,\n\tExtension,\n\tExtensionActions,\n\t// API\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionCommandContextActions,\n\tExtensionContext,\n\tExtensionContextActions,\n\t// Errors\n\tExtensionError,\n\tExtensionEvent,\n\tExtensionFactory,\n\tExtensionFlag,\n\tExtensionHandler,\n\tExtensionMode,\n\t// Runtime\n\tExtensionRuntime,\n\tExtensionShortcut,\n\tExtensionUIContext,\n\tExtensionUIDialogOptions,\n\tExtensionWidgetOptions,\n\tFindToolCallEvent,\n\tFindToolResultEvent,\n\tGetActiveToolsHandler,\n\tGetAllToolsHandler,\n\tGetCommandsHandler,\n\tGetThinkingLevelHandler,\n\tGrepToolCallEvent,\n\tGrepToolResultEvent,\n\t// Events - Input\n\tInputEvent,\n\tInputEventResult,\n\tInputSource,\n\tKeybindingsManager,\n\tLoadExtensionsResult,\n\tLsToolCallEvent,\n\tLsToolResultEvent,\n\t// Events - Message\n\tMessageEndEvent,\n\t// Message Rendering\n\tMessageRenderer,\n\tMessageRenderOptions,\n\tMessageStartEvent,\n\tMessageUpdateEvent,\n\tModelSelectEvent,\n\tModelSelectSource,\n\t// Provider Registration\n\tProviderConfig,\n\tProviderModelConfig,\n\tReadToolCallEvent,\n\tReadToolResultEvent,\n\t// Commands\n\tRegisteredCommand,\n\tRegisteredTool,\n\tReplacedSessionContext,\n\tResolvedCommand,\n\t// Events - Resources\n\tResourcesDiscoverEvent,\n\tResourcesDiscoverResult,\n\tSendMessageHandler,\n\tSendUserMessageHandler,\n\tSessionBeforeCompactEvent,\n\tSessionBeforeCompactResult,\n\tSessionBeforeForkEvent,\n\tSessionBeforeForkResult,\n\tSessionBeforeSwitchEvent,\n\tSessionBeforeSwitchResult,\n\tSessionBeforeTreeEvent,\n\tSessionBeforeTreeResult,\n\tSessionCompactEvent,\n\tSessionEvent,\n\tSessionInfoChangedEvent,\n\tSessionShutdownEvent,\n\t// Events - Session\n\tSessionStartEvent,\n\tSessionTreeEvent,\n\tSetActiveToolsHandler,\n\tSetLabelHandler,\n\tSetModelHandler,\n\tSetThinkingLevelHandler,\n\tTerminalInputHandler,\n\t// Events - Tool\n\tToolCallEvent,\n\tToolCallEventResult,\n\t// Tools\n\tToolDefinition,\n\t// Events - Tool Execution\n\tToolExecutionEndEvent,\n\t// Tool execution mode\n\tToolExecutionMode,\n\tToolExecutionStartEvent,\n\tToolExecutionUpdateEvent,\n\tToolInfo,\n\tToolRenderResultOptions,\n\tToolResultEvent,\n\tToolResultEventResult,\n\tTreePreparation,\n\tTurnEndEvent,\n\tTurnStartEvent,\n\t// Events - User Bash\n\tUserBashEvent,\n\tUserBashEventResult,\n\tWidgetPlacement,\n\tWorkingIndicatorOptions,\n\tWriteToolCallEvent,\n\tWriteToolResultEvent,\n} from \"./types.ts\";\n// Type guards\nexport {\n\tdefineTool,\n\tisBashToolResult,\n\tisEditToolResult,\n\tisFindToolResult,\n\tisGrepToolResult,\n\tisLsToolResult,\n\tisReadToolResult,\n\tisToolCallEventType,\n\tisWriteToolResult,\n} from \"./types.ts\";\nexport { wrapRegisteredTool, wrapRegisteredTools } from \"./wrapper.ts\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/extensions/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EACN,sBAAsB,EACtB,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,GACd,MAAM,aAAa,CAAC;AASrB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/extensions/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EACN,sBAAsB,EACtB,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,GACd,MAAM,aAAa,CAAC;AASrB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AA6I9C,cAAc;AACd,OAAO,EACN,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC","sourcesContent":["/**\n * Extension system for lifecycle events and custom tools.\n */\n\nexport type { SlashCommandInfo, SlashCommandSource } from \"../slash-commands.ts\";\nexport type { SourceInfo } from \"../source-info.ts\";\nexport {\n\tcreateExtensionRuntime,\n\tdiscoverAndLoadExtensions,\n\tloadExtensionFromFactory,\n\tloadExtensions,\n} from \"./loader.ts\";\nexport type {\n\tExtensionErrorListener,\n\tForkHandler,\n\tNavigateTreeHandler,\n\tNewSessionHandler,\n\tShutdownHandler,\n\tSwitchSessionHandler,\n} from \"./runner.ts\";\nexport { ExtensionRunner } from \"./runner.ts\";\nexport type {\n\tAfterProviderResponseEvent,\n\tAgentEndEvent,\n\tAgentStartEvent,\n\t// Re-exports\n\tAgentToolResult,\n\tAgentToolUpdateCallback,\n\tAppendEntryHandler,\n\t// App keybindings (for custom editors)\n\tAppKeybinding,\n\tAutocompleteProviderFactory,\n\t// Events - Tool (ToolCallEvent types)\n\tBashToolCallEvent,\n\tBashToolResultEvent,\n\tBeforeAgentStartEvent,\n\tBeforeAgentStartEventResult,\n\tBeforeProviderRequestEvent,\n\tBeforeProviderRequestEventResult,\n\tBuildSystemPromptOptions,\n\t// Context\n\tCompactOptions,\n\t// Events - Agent\n\tContextEvent,\n\t// Event Results\n\tContextEventResult,\n\tContextUsage,\n\tCustomToolCallEvent,\n\tCustomToolResultEvent,\n\tEditorFactory,\n\tEditToolCallEvent,\n\tEditToolResultEvent,\n\tExecOptions,\n\tExecResult,\n\tExtension,\n\tExtensionActions,\n\t// API\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionCommandContextActions,\n\tExtensionContext,\n\tExtensionContextActions,\n\t// Errors\n\tExtensionError,\n\tExtensionEvent,\n\tExtensionFactory,\n\tExtensionFlag,\n\tExtensionHandler,\n\tExtensionMode,\n\t// Runtime\n\tExtensionRuntime,\n\tExtensionShortcut,\n\tExtensionUIContext,\n\tExtensionUIDialogOptions,\n\tExtensionWidgetOptions,\n\tFindToolCallEvent,\n\tFindToolResultEvent,\n\tGetActiveToolsHandler,\n\tGetAllToolsHandler,\n\tGetCommandsHandler,\n\tGetThinkingLevelHandler,\n\tGrepToolCallEvent,\n\tGrepToolResultEvent,\n\t// Events - Input\n\tInputEvent,\n\tInputEventResult,\n\tInputSource,\n\tKeybindingsManager,\n\tLoadExtensionsResult,\n\tLsToolCallEvent,\n\tLsToolResultEvent,\n\t// Events - Message\n\tMessageEndEvent,\n\t// Message Rendering\n\tMessageRenderer,\n\tMessageRenderOptions,\n\tMessageStartEvent,\n\tMessageUpdateEvent,\n\tModelSelectEvent,\n\tModelSelectSource,\n\t// Provider Registration\n\tProviderConfig,\n\tProviderModelConfig,\n\tReadToolCallEvent,\n\tReadToolResultEvent,\n\t// Commands\n\tRegisteredCommand,\n\tRegisteredTool,\n\tReplacedSessionContext,\n\tResolvedCommand,\n\t// Events - Resources\n\tResourcesDiscoverEvent,\n\tResourcesDiscoverResult,\n\tSendMessageHandler,\n\tSendUserMessageHandler,\n\tSessionBeforeCompactEvent,\n\tSessionBeforeCompactResult,\n\tSessionBeforeForkEvent,\n\tSessionBeforeForkResult,\n\tSessionBeforeSwitchEvent,\n\tSessionBeforeSwitchResult,\n\tSessionBeforeTreeEvent,\n\tSessionBeforeTreeResult,\n\tSessionCompactEvent,\n\tSessionEvent,\n\tSessionInfoChangedEvent,\n\tSessionShutdownEvent,\n\t// Events - Session\n\tSessionStartEvent,\n\tSessionTreeEvent,\n\tSetActiveToolsHandler,\n\tSetLabelHandler,\n\tSetModelHandler,\n\tSetThinkingLevelHandler,\n\tTerminalInputHandler,\n\t// Events - Tool\n\tToolCallEvent,\n\tToolCallEventResult,\n\t// Tools\n\tToolDefinition,\n\t// Events - Tool Execution\n\tToolExecutionEndEvent,\n\t// Tool execution mode\n\tToolExecutionMode,\n\tToolExecutionStartEvent,\n\tToolExecutionUpdateEvent,\n\tToolInfo,\n\tToolRenderResultOptions,\n\tToolResultEvent,\n\tToolResultEventResult,\n\tTreePreparation,\n\tTurnEndEvent,\n\tTurnStartEvent,\n\t// Events - User Bash\n\tUserBashEvent,\n\tUserBashEventResult,\n\tWidgetPlacement,\n\tWorkingIndicatorOptions,\n\tWriteToolCallEvent,\n\tWriteToolResultEvent,\n} from \"./types.ts\";\n// Type guards\nexport {\n\tdefineTool,\n\tisBashToolResult,\n\tisEditToolResult,\n\tisFindToolResult,\n\tisGrepToolResult,\n\tisLsToolResult,\n\tisReadToolResult,\n\tisToolCallEventType,\n\tisWriteToolResult,\n} from \"./types.ts\";\nexport { wrapRegisteredTool, wrapRegisteredTools } from \"./wrapper.ts\";\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Fired when a session is started, loaded, or reloaded. */
|
|
2
|
+
export interface SessionStartEvent {
|
|
3
|
+
type: "session_start";
|
|
4
|
+
reason: "startup" | "reload" | "new" | "resume" | "fork";
|
|
5
|
+
/** Previously active file for new, resume and fork. */
|
|
6
|
+
previousSessionFile?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Fired when the current session metadata changes. */
|
|
9
|
+
export interface SessionInfoChangedEvent {
|
|
10
|
+
type: "session_info_changed";
|
|
11
|
+
/** Undefined when the normalized name is cleared. */
|
|
12
|
+
name: string | undefined;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=session-lifecycle-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-lifecycle-types.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/session-lifecycle-types.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,MAAM,WAAW,iBAAiB;IACjC,IAAI,EAAE,eAAe,CAAC;IACtB,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IACzD,uDAAuD;IACvD,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,uDAAuD;AACvD,MAAM,WAAW,uBAAuB;IACvC,IAAI,EAAE,sBAAsB,CAAC;IAC7B,qDAAqD;IACrD,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;CACzB","sourcesContent":["/** Fired when a session is started, loaded, or reloaded. */\nexport interface SessionStartEvent {\n\ttype: \"session_start\";\n\treason: \"startup\" | \"reload\" | \"new\" | \"resume\" | \"fork\";\n\t/** Previously active file for new, resume and fork. */\n\tpreviousSessionFile?: string;\n}\n\n/** Fired when the current session metadata changes. */\nexport interface SessionInfoChangedEvent {\n\ttype: \"session_info_changed\";\n\t/** Undefined when the normalized name is cleared. */\n\tname: string | undefined;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-lifecycle-types.js","sourceRoot":"","sources":["../../../src/core/extensions/session-lifecycle-types.ts"],"names":[],"mappings":"","sourcesContent":["/** Fired when a session is started, loaded, or reloaded. */\nexport interface SessionStartEvent {\n\ttype: \"session_start\";\n\treason: \"startup\" | \"reload\" | \"new\" | \"resume\" | \"fork\";\n\t/** Previously active file for new, resume and fork. */\n\tpreviousSessionFile?: string;\n}\n\n/** Fired when the current session metadata changes. */\nexport interface SessionInfoChangedEvent {\n\ttype: \"session_info_changed\";\n\t/** Undefined when the normalized name is cleared. */\n\tname: string | undefined;\n}\n"]}
|