open-multi-agent-kit 0.98.5 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/README.md +4 -3
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js +1 -0
- package/dist/bun/cli.js.map +1 -1
- package/dist/bun/register-bundled-coding-agent.d.ts +10 -0
- package/dist/bun/register-bundled-coding-agent.d.ts.map +1 -0
- package/dist/bun/register-bundled-coding-agent.js +12 -0
- package/dist/bun/register-bundled-coding-agent.js.map +1 -0
- package/dist/cli/args.d.ts +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +1 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +2 -1
- package/dist/cli/help.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +14 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/neo-cli.d.ts +9 -0
- package/dist/commands/neo-cli.d.ts.map +1 -0
- package/dist/commands/neo-cli.js +61 -0
- package/dist/commands/neo-cli.js.map +1 -0
- package/dist/commands/verified-run-cli.d.ts.map +1 -1
- package/dist/commands/verified-run-cli.js +2 -2
- package/dist/commands/verified-run-cli.js.map +1 -1
- package/dist/core/agent-session.d.ts +29 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +126 -32
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bundled-skills.d.ts +4 -0
- package/dist/core/bundled-skills.d.ts.map +1 -0
- package/dist/core/bundled-skills.js +32 -0
- package/dist/core/bundled-skills.js.map +1 -0
- package/dist/core/cli-diagnostics.d.ts +6 -0
- package/dist/core/cli-diagnostics.d.ts.map +1 -0
- package/dist/core/cli-diagnostics.js +20 -0
- package/dist/core/cli-diagnostics.js.map +1 -0
- package/dist/core/context-budget-headroom.d.ts +12 -0
- package/dist/core/context-budget-headroom.d.ts.map +1 -1
- package/dist/core/context-budget-headroom.js +35 -0
- package/dist/core/context-budget-headroom.js.map +1 -1
- package/dist/core/context-budget-v2-input-validation.d.ts +4 -0
- package/dist/core/context-budget-v2-input-validation.d.ts.map +1 -0
- package/dist/core/context-budget-v2-input-validation.js +79 -0
- package/dist/core/context-budget-v2-input-validation.js.map +1 -0
- package/dist/core/context-budget-v2-observability.d.ts +15 -0
- package/dist/core/context-budget-v2-observability.d.ts.map +1 -0
- package/dist/core/context-budget-v2-observability.js +35 -0
- package/dist/core/context-budget-v2-observability.js.map +1 -0
- package/dist/core/context-budget-v2-planned-items.d.ts +5 -0
- package/dist/core/context-budget-v2-planned-items.d.ts.map +1 -0
- package/dist/core/context-budget-v2-planned-items.js +40 -0
- package/dist/core/context-budget-v2-planned-items.js.map +1 -0
- package/dist/core/context-budget-v2-planner.d.ts.map +1 -1
- package/dist/core/context-budget-v2-planner.js +57 -38
- package/dist/core/context-budget-v2-planner.js.map +1 -1
- package/dist/core/context-budget-v2-selection.d.ts +19 -3
- package/dist/core/context-budget-v2-selection.d.ts.map +1 -1
- package/dist/core/context-budget-v2-selection.js +35 -57
- package/dist/core/context-budget-v2-selection.js.map +1 -1
- package/dist/core/context-budget-v2-tiers.d.ts.map +1 -1
- package/dist/core/context-budget-v2-tiers.js +9 -42
- package/dist/core/context-budget-v2-tiers.js.map +1 -1
- package/dist/core/context-budget-v2-types.d.ts +8 -1
- package/dist/core/context-budget-v2-types.d.ts.map +1 -1
- package/dist/core/context-budget-v2-types.js.map +1 -1
- package/dist/core/devin-harness-dispatch.d.ts +12 -0
- package/dist/core/devin-harness-dispatch.d.ts.map +1 -0
- package/dist/core/devin-harness-dispatch.js +12 -0
- package/dist/core/devin-harness-dispatch.js.map +1 -0
- package/dist/core/devin-harness.d.ts +53 -0
- package/dist/core/devin-harness.d.ts.map +1 -0
- package/dist/core/devin-harness.js +112 -0
- package/dist/core/devin-harness.js.map +1 -0
- package/dist/core/domain-dispatch.d.ts +4 -1
- package/dist/core/domain-dispatch.d.ts.map +1 -1
- package/dist/core/domain-dispatch.js +5 -0
- package/dist/core/domain-dispatch.js.map +1 -1
- package/dist/core/domain-loadouts-provider-harness.d.ts +12 -0
- package/dist/core/domain-loadouts-provider-harness.d.ts.map +1 -0
- package/dist/core/domain-loadouts-provider-harness.js +122 -0
- package/dist/core/domain-loadouts-provider-harness.js.map +1 -0
- package/dist/core/domain-loadouts.d.ts +2 -33
- package/dist/core/domain-loadouts.d.ts.map +1 -1
- package/dist/core/domain-loadouts.js +3 -56
- package/dist/core/domain-loadouts.js.map +1 -1
- package/dist/core/domain-profile.d.ts +40 -0
- package/dist/core/domain-profile.d.ts.map +1 -0
- package/dist/core/domain-profile.js +7 -0
- package/dist/core/domain-profile.js.map +1 -0
- package/dist/core/extensions/bundled-virtual-modules.d.ts +15 -0
- package/dist/core/extensions/bundled-virtual-modules.d.ts.map +1 -0
- package/dist/core/extensions/bundled-virtual-modules.js +63 -0
- package/dist/core/extensions/bundled-virtual-modules.js.map +1 -0
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +2 -42
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +1 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +6 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +10 -0
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/grok-harness-dispatch.d.ts +6 -20
- package/dist/core/grok-harness-dispatch.d.ts.map +1 -1
- package/dist/core/grok-harness-dispatch.js +6 -55
- package/dist/core/grok-harness-dispatch.js.map +1 -1
- package/dist/core/grok-harness.d.ts +7 -9
- package/dist/core/grok-harness.d.ts.map +1 -1
- package/dist/core/grok-harness.js +9 -23
- package/dist/core/grok-harness.js.map +1 -1
- package/dist/core/harness-skills.d.ts +20 -0
- package/dist/core/harness-skills.d.ts.map +1 -0
- package/dist/core/harness-skills.js +36 -0
- package/dist/core/harness-skills.js.map +1 -0
- package/dist/core/index.d.ts +2 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/loadout-runtime-state.d.ts +25 -0
- package/dist/core/loadout-runtime-state.d.ts.map +1 -0
- package/dist/core/loadout-runtime-state.js +39 -0
- package/dist/core/loadout-runtime-state.js.map +1 -0
- package/dist/core/loadout-runtime.d.ts +4 -20
- package/dist/core/loadout-runtime.d.ts.map +1 -1
- package/dist/core/loadout-runtime.js +6 -13
- package/dist/core/loadout-runtime.js.map +1 -1
- package/dist/core/mcp/client.d.ts +27 -6
- package/dist/core/mcp/client.d.ts.map +1 -1
- package/dist/core/mcp/client.js +80 -20
- package/dist/core/mcp/client.js.map +1 -1
- package/dist/core/mcp/manager.d.ts +10 -1
- package/dist/core/mcp/manager.d.ts.map +1 -1
- package/dist/core/mcp/manager.js +68 -9
- package/dist/core/mcp/manager.js.map +1 -1
- package/dist/core/mcp/protocol.d.ts +9 -3
- package/dist/core/mcp/protocol.d.ts.map +1 -1
- package/dist/core/mcp/protocol.js +61 -15
- package/dist/core/mcp/protocol.js.map +1 -1
- package/dist/core/mcp/stdio-transport.d.ts +12 -1
- package/dist/core/mcp/stdio-transport.d.ts.map +1 -1
- package/dist/core/mcp/stdio-transport.js +30 -2
- package/dist/core/mcp/stdio-transport.js.map +1 -1
- package/dist/core/mcp-descriptor-injection.d.ts +26 -0
- package/dist/core/mcp-descriptor-injection.d.ts.map +1 -0
- package/dist/core/mcp-descriptor-injection.js +25 -0
- package/dist/core/mcp-descriptor-injection.js.map +1 -0
- package/dist/core/mcp-public-presets.d.ts +1 -3
- package/dist/core/mcp-public-presets.d.ts.map +1 -1
- package/dist/core/mcp-public-presets.js +3 -15
- package/dist/core/mcp-public-presets.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +24 -3
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +1 -41
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +2 -49
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/neo/catalog.d.ts +20 -0
- package/dist/core/neo/catalog.d.ts.map +1 -0
- package/dist/core/neo/catalog.js +50 -0
- package/dist/core/neo/catalog.js.map +1 -0
- package/dist/core/neo/setup.d.ts +3 -0
- package/dist/core/neo/setup.d.ts.map +1 -0
- package/dist/core/neo/setup.js +47 -0
- package/dist/core/neo/setup.js.map +1 -0
- package/dist/core/provider-default-models.d.ts +43 -0
- package/dist/core/provider-default-models.d.ts.map +1 -0
- package/dist/core/provider-default-models.js +51 -0
- package/dist/core/provider-default-models.js.map +1 -0
- package/dist/core/provider-display-names.d.ts.map +1 -1
- package/dist/core/provider-display-names.js +2 -0
- package/dist/core/provider-display-names.js.map +1 -1
- package/dist/core/provider-error-classification.d.ts +57 -0
- package/dist/core/provider-error-classification.d.ts.map +1 -0
- package/dist/core/provider-error-classification.js +103 -0
- package/dist/core/provider-error-classification.js.map +1 -0
- package/dist/core/provider-harness-dispatch.d.ts +63 -0
- package/dist/core/provider-harness-dispatch.d.ts.map +1 -0
- package/dist/core/provider-harness-dispatch.js +60 -0
- package/dist/core/provider-harness-dispatch.js.map +1 -0
- package/dist/core/provider-resilience.d.ts +10 -0
- package/dist/core/provider-resilience.d.ts.map +1 -1
- package/dist/core/provider-resilience.js +36 -3
- package/dist/core/provider-resilience.js.map +1 -1
- package/dist/core/provider-usage-commandcode.d.ts +9 -0
- package/dist/core/provider-usage-commandcode.d.ts.map +1 -0
- package/dist/core/provider-usage-commandcode.js +198 -0
- package/dist/core/provider-usage-commandcode.js.map +1 -0
- package/dist/core/provider-usage-devin.d.ts +18 -0
- package/dist/core/provider-usage-devin.d.ts.map +1 -0
- package/dist/core/provider-usage-devin.js +71 -0
- package/dist/core/provider-usage-devin.js.map +1 -0
- package/dist/core/provider-usage-text.d.ts +5 -0
- package/dist/core/provider-usage-text.d.ts.map +1 -0
- package/dist/core/provider-usage-text.js +15 -0
- package/dist/core/provider-usage-text.js.map +1 -0
- package/dist/core/provider-usage-types.d.ts +2 -1
- package/dist/core/provider-usage-types.d.ts.map +1 -1
- package/dist/core/provider-usage-types.js.map +1 -1
- package/dist/core/provider-usage.d.ts +1 -2
- package/dist/core/provider-usage.d.ts.map +1 -1
- package/dist/core/provider-usage.js +18 -7
- package/dist/core/provider-usage.js.map +1 -1
- package/dist/core/resource-admission.d.ts +36 -0
- package/dist/core/resource-admission.d.ts.map +1 -1
- package/dist/core/resource-admission.js +59 -0
- package/dist/core/resource-admission.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +2 -2
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/run-execution-api.d.ts +1 -1
- package/dist/core/run-execution-api.d.ts.map +1 -1
- package/dist/core/run-execution-api.js.map +1 -1
- package/dist/core/run-usage-ledger.d.ts +47 -0
- package/dist/core/run-usage-ledger.d.ts.map +1 -0
- package/dist/core/run-usage-ledger.js +162 -0
- package/dist/core/run-usage-ledger.js.map +1 -0
- package/dist/core/run-usage-operation.d.ts +8 -0
- package/dist/core/run-usage-operation.d.ts.map +1 -0
- package/dist/core/run-usage-operation.js +12 -0
- package/dist/core/run-usage-operation.js.map +1 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +20 -16
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-failure-cause.d.ts.map +1 -1
- package/dist/core/session-failure-cause.js +14 -5
- package/dist/core/session-failure-cause.js.map +1 -1
- package/dist/core/session-prompt-lifecycle.d.ts +6 -0
- package/dist/core/session-prompt-lifecycle.d.ts.map +1 -1
- package/dist/core/session-prompt-lifecycle.js +47 -2
- package/dist/core/session-prompt-lifecycle.js.map +1 -1
- package/dist/core/session-termination.d.ts.map +1 -1
- package/dist/core/session-termination.js +4 -2
- package/dist/core/session-termination.js.map +1 -1
- package/dist/core/subagent-lane-authority.d.ts +28 -0
- package/dist/core/subagent-lane-authority.d.ts.map +1 -0
- package/dist/core/subagent-lane-authority.js +119 -0
- package/dist/core/subagent-lane-authority.js.map +1 -0
- package/dist/core/subagent-lane-contract.d.ts +114 -0
- package/dist/core/subagent-lane-contract.d.ts.map +1 -0
- package/dist/core/subagent-lane-contract.js +18 -0
- package/dist/core/subagent-lane-contract.js.map +1 -0
- package/dist/core/subagent-lane-launcher.d.ts +3 -6
- package/dist/core/subagent-lane-launcher.d.ts.map +1 -1
- package/dist/core/subagent-lane-launcher.js +53 -12
- package/dist/core/subagent-lane-launcher.js.map +1 -1
- package/dist/core/subagent-orchestration.d.ts +4 -17
- package/dist/core/subagent-orchestration.d.ts.map +1 -1
- package/dist/core/subagent-orchestration.js.map +1 -1
- package/dist/core/verified-run/broker.d.ts.map +1 -1
- package/dist/core/verified-run/broker.js +4 -1
- package/dist/core/verified-run/broker.js.map +1 -1
- package/dist/core/verified-run/dag-phase.d.ts +1 -1
- package/dist/core/verified-run/dag-phase.d.ts.map +1 -1
- package/dist/core/verified-run/dag-phase.js +46 -8
- package/dist/core/verified-run/dag-phase.js.map +1 -1
- package/dist/core/verified-run/dag-projection.d.ts.map +1 -1
- package/dist/core/verified-run/dag-projection.js +25 -12
- package/dist/core/verified-run/dag-projection.js.map +1 -1
- package/dist/core/verified-run/dag-types.d.ts +11 -0
- package/dist/core/verified-run/dag-types.d.ts.map +1 -1
- package/dist/core/verified-run/dag-types.js.map +1 -1
- package/dist/core/verified-run/event-parser.d.ts.map +1 -1
- package/dist/core/verified-run/event-parser.js +1 -0
- package/dist/core/verified-run/event-parser.js.map +1 -1
- package/dist/core/verified-run/owned-execution.d.ts +1 -0
- package/dist/core/verified-run/owned-execution.d.ts.map +1 -1
- package/dist/core/verified-run/owned-execution.js +7 -1
- package/dist/core/verified-run/owned-execution.js.map +1 -1
- package/dist/core/verified-run/process-projection.d.ts +13 -0
- package/dist/core/verified-run/process-projection.d.ts.map +1 -0
- package/dist/core/verified-run/process-projection.js +82 -0
- package/dist/core/verified-run/process-projection.js.map +1 -0
- package/dist/core/verified-run/projection.d.ts.map +1 -1
- package/dist/core/verified-run/projection.js +11 -55
- package/dist/core/verified-run/projection.js.map +1 -1
- package/dist/core/verified-run/run-types.d.ts +1 -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/task-execution.d.ts +9 -0
- package/dist/core/verified-run/task-execution.d.ts.map +1 -0
- package/dist/core/verified-run/task-execution.js +29 -0
- package/dist/core/verified-run/task-execution.js.map +1 -0
- package/dist/core/verified-run/writer-projection.d.ts.map +1 -1
- package/dist/core/verified-run/writer-projection.js +6 -5
- package/dist/core/verified-run/writer-projection.js.map +1 -1
- package/dist/core/workload-permit-pool.d.ts +1 -1
- package/dist/core/workload-permit-pool.d.ts.map +1 -1
- package/dist/core/workload-permit-pool.js +3 -0
- package/dist/core/workload-permit-pool.js.map +1 -1
- package/dist/guardrails/strict-evidence-approval-adapter.d.ts +34 -0
- package/dist/guardrails/strict-evidence-approval-adapter.d.ts.map +1 -0
- package/dist/guardrails/strict-evidence-approval-adapter.js +70 -0
- package/dist/guardrails/strict-evidence-approval-adapter.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +11 -18
- package/dist/main.js.map +1 -1
- package/dist/modes/acp/acp-agent.d.ts +24 -0
- package/dist/modes/acp/acp-agent.d.ts.map +1 -0
- package/dist/modes/acp/acp-agent.js +133 -0
- package/dist/modes/acp/acp-agent.js.map +1 -0
- package/dist/modes/acp/acp-mode.d.ts +4 -0
- package/dist/modes/acp/acp-mode.d.ts.map +1 -0
- package/dist/modes/acp/acp-mode.js +34 -0
- package/dist/modes/acp/acp-mode.js.map +1 -0
- package/dist/modes/acp/acp-session.d.ts +4 -0
- package/dist/modes/acp/acp-session.d.ts.map +1 -0
- package/dist/modes/acp/acp-session.js +76 -0
- package/dist/modes/acp/acp-session.js.map +1 -0
- package/dist/modes/acp/acp-transport.d.ts +5 -0
- package/dist/modes/acp/acp-transport.d.ts.map +1 -0
- package/dist/modes/acp/acp-transport.js +90 -0
- package/dist/modes/acp/acp-transport.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +3 -5
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/resource-description.d.ts +3 -0
- package/dist/modes/interactive/resource-description.d.ts.map +1 -0
- package/dist/modes/interactive/resource-description.js +15 -0
- package/dist/modes/interactive/resource-description.js.map +1 -0
- package/docs/audit-revalidation-2026-09-17.md +77 -0
- package/docs/devin-harness.md +150 -0
- package/docs/docs.json +4 -0
- package/docs/ecraf-normalization.md +83 -0
- package/docs/environment-variables.md +2 -1
- package/docs/index.md +1 -0
- package/docs/loadout-domains/README.md +2 -1
- package/docs/loadout-domains/devin-harness.md +72 -0
- package/docs/metrics.md +57 -16
- package/docs/model-catalog-refresh.md +51 -1
- package/docs/models.md +1 -1
- package/docs/neo.md +134 -0
- package/docs/providers.md +143 -1
- package/docs/release-audit-0.98.5.md +17 -0
- package/docs/release-audit-0.99.0.md +68 -0
- package/docs/run-protocol.md +4 -3
- package/docs/run-usage-ledger.md +56 -0
- package/docs/runtime-algorithms.md +48 -1
- package/docs/sdk.md +9 -5
- package/docs/settings.md +1 -1
- package/docs/skills.md +1 -1
- package/docs/startup-resource-labels-testing.md +47 -0
- package/docs/tb21-audit.md +18 -4
- package/docs/usage.md +7 -1
- package/docs/verified-run-remaining-design.md +881 -0
- package/docs/verified-run-testing.md +91 -0
- package/docs/verified-run.md +30 -9
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/subagent/adaptive-agent-runtime.ts +14 -1
- package/examples/extensions/subagent/graph-result.ts +48 -0
- package/examples/extensions/subagent/index.ts +246 -111
- package/examples/extensions/subagent/managed-process-tree.ts +42 -0
- package/examples/extensions/subagent/managed-process.test.ts +24 -0
- package/examples/extensions/subagent/managed-process.ts +93 -112
- package/examples/extensions/subagent/subagent-runtime-types.ts +17 -1
- package/examples/extensions/subagent/subagent-stream.ts +161 -0
- package/examples/extensions/terminal-browser/README.md +54 -0
- package/examples/extensions/terminal-browser/bridge-protocol.ts +29 -0
- package/examples/extensions/terminal-browser/bridge.ts +219 -0
- package/examples/extensions/terminal-browser/browser-surface.ts +288 -0
- package/examples/extensions/terminal-browser/index.ts +215 -0
- package/examples/extensions/terminal-browser/placeholders.ts +49 -0
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +18 -18
- package/package.json +8 -7
- package/resources/neo/skills/omk-browser/SKILL.md +32 -0
- package/resources/neo/skills/omk-code-review/SKILL.md +24 -0
- package/resources/neo/skills/omk-computeruse/SKILL.md +34 -0
- package/resources/neo/skills/omk-mcp-setup/SKILL.md +48 -0
- package/resources/neo/skills/omk-research/SKILL.md +24 -0
- package/resources/neo/skills/omk-site/SKILL.md +28 -0
|
@@ -15,54 +15,21 @@ export function computeTierDemand(plannedItems) {
|
|
|
15
15
|
}
|
|
16
16
|
export function allocateTiers(available, policy, demand) {
|
|
17
17
|
const out = new Map();
|
|
18
|
-
const floors = {};
|
|
19
|
-
const ceilings = {};
|
|
20
|
-
const wants = {};
|
|
21
18
|
for (const tier of ALL_TIERS_V2) {
|
|
22
19
|
const floor = Math.max(0, Math.floor(policy[tier].floorPct * available));
|
|
23
20
|
const ceiling = Math.max(floor, Math.floor(policy[tier].ceilingPct * available));
|
|
24
21
|
const entry = demand.get(tier) ?? { demand: 0, hard: 0 };
|
|
25
22
|
const want = Math.max(entry.demand, entry.hard);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
let residual = available - totalAllocated;
|
|
36
|
-
if (residual <= 0) {
|
|
37
|
-
return out;
|
|
38
|
-
}
|
|
39
|
-
const shortfalls = collectShortfalls(out, wants);
|
|
40
|
-
const totalGap = shortfalls.reduce((sum, shortfall) => sum + shortfall.gap, 0);
|
|
41
|
-
if (totalGap <= 0) {
|
|
42
|
-
return out;
|
|
43
|
-
}
|
|
44
|
-
for (const { tier, gap } of shortfalls) {
|
|
45
|
-
const share = Math.min(gap, Math.floor((residual * gap) / totalGap));
|
|
46
|
-
if (share <= 0)
|
|
47
|
-
continue;
|
|
48
|
-
const entry = out.get(tier);
|
|
49
|
-
if (!entry)
|
|
50
|
-
continue;
|
|
51
|
-
out.set(tier, { ...entry, allocated: entry.allocated + share });
|
|
52
|
-
residual -= share;
|
|
23
|
+
// `allocated` is the tier's guaranteed claim — what the floor pass is
|
|
24
|
+
// entitled to spend on this tier's own items before global competition:
|
|
25
|
+
// its hard demand (always admitted) or, beyond that, its demand capped
|
|
26
|
+
// at the floor. The previous residual-redistribution loop could never
|
|
27
|
+
// move this number on normal input (min(want, max(ceiling, hard)) makes
|
|
28
|
+
// want-allocated or ceiling-allocated zero), so it is removed rather
|
|
29
|
+
// than kept as dead code. Leftover budget competes globally in the
|
|
30
|
+
// ceiling-bounded selection pass instead.
|
|
31
|
+
out.set(tier, { floor, ceiling, allocated: Math.min(want, Math.max(floor, entry.hard)) });
|
|
53
32
|
}
|
|
54
33
|
return out;
|
|
55
34
|
}
|
|
56
|
-
function collectShortfalls(allocations, wants) {
|
|
57
|
-
const shortfalls = [];
|
|
58
|
-
for (const tier of ALL_TIERS_V2) {
|
|
59
|
-
const entry = allocations.get(tier);
|
|
60
|
-
if (!entry)
|
|
61
|
-
continue;
|
|
62
|
-
const gap = Math.min(Math.max(0, wants[tier] - entry.allocated), Math.max(0, entry.ceiling - entry.allocated));
|
|
63
|
-
if (gap > 0)
|
|
64
|
-
shortfalls.push({ tier, gap });
|
|
65
|
-
}
|
|
66
|
-
return shortfalls;
|
|
67
|
-
}
|
|
68
35
|
//# sourceMappingURL=context-budget-v2-tiers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-budget-v2-tiers.js","sourceRoot":"","sources":["../../src/core/context-budget-v2-tiers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAA2B,MAAM,8BAA8B,CAAC;AAarF,MAAM,UAAU,iBAAiB,CAAC,YAAsC,EAA2C;IAClH,MAAM,MAAM,GAAG,IAAI,GAAG,EAAsC,CAAC;IAC7D,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QACjC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;IAC1C,CAAC;IACD,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;QACpC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QACtE,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE;YAC7B,MAAM,EAAE,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,UAAU;YACzC,IAAI,EAAE,KAAK,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;SAC5D,CAAC,CAAC;IACJ,CAAC;IACD,O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AI,YAAY,EAAE,CAAC;QACjC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC;QACzE,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC;QACjF,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QAChD,wEAAsE;QACtE,wEAAwE;QACxE,uEAAuE;QACvE,sEAAsE;QACtE,wEAAwE;QACxE,qEAAqE;QACrE,mEAAmE;QACnE,0CAA0C;QAC1C,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;IAC3F,CAAC;IACD,OAAO,GAAG,CAAC;AAAA,CACX","sourcesContent":["import type { ContextBudgetTierV2 } from \"./context-budget-headroom.ts\";\nimport type { PlannedItemV2 } from \"./context-budget-v2-scoring.ts\";\nimport { ALL_TIERS_V2, type TierBudgetPolicyV2 } from \"./context-budget-v2-types.ts\";\n\nexport interface RawTierDemand {\n\treadonly demand: number;\n\treadonly hard: number;\n}\n\nexport interface RawTierAllocation {\n\treadonly floor: number;\n\treadonly ceiling: number;\n\treadonly allocated: number;\n}\n\nexport function computeTierDemand(plannedItems: readonly PlannedItemV2[]): Map<ContextBudgetTierV2, RawTierDemand> {\n\tconst demand = new Map<ContextBudgetTierV2, RawTierDemand>();\n\tfor (const tier of ALL_TIERS_V2) {\n\t\tdemand.set(tier, { demand: 0, hard: 0 });\n\t}\n\tfor (const planned of plannedItems) {\n\t\tconst entry = demand.get(planned.item.tier) ?? { demand: 0, hard: 0 };\n\t\tdemand.set(planned.item.tier, {\n\t\t\tdemand: entry.demand + planned.fullTokens,\n\t\t\thard: entry.hard + (planned.isHard ? planned.fullTokens : 0),\n\t\t});\n\t}\n\treturn demand;\n}\n\nexport function allocateTiers(\n\tavailable: number,\n\tpolicy: Readonly<Record<ContextBudgetTierV2, TierBudgetPolicyV2>>,\n\tdemand: Map<ContextBudgetTierV2, RawTierDemand>,\n): Map<ContextBudgetTierV2, RawTierAllocation> {\n\tconst out = new Map<ContextBudgetTierV2, RawTierAllocation>();\n\n\tfor (const tier of ALL_TIERS_V2) {\n\t\tconst floor = Math.max(0, Math.floor(policy[tier].floorPct * available));\n\t\tconst ceiling = Math.max(floor, Math.floor(policy[tier].ceilingPct * available));\n\t\tconst entry = demand.get(tier) ?? { demand: 0, hard: 0 };\n\t\tconst want = Math.max(entry.demand, entry.hard);\n\t\t// `allocated` is the tier's guaranteed claim — what the floor pass is\n\t\t// entitled to spend on this tier's own items before global competition:\n\t\t// its hard demand (always admitted) or, beyond that, its demand capped\n\t\t// at the floor. The previous residual-redistribution loop could never\n\t\t// move this number on normal input (min(want, max(ceiling, hard)) makes\n\t\t// want-allocated or ceiling-allocated zero), so it is removed rather\n\t\t// than kept as dead code. Leftover budget competes globally in the\n\t\t// ceiling-bounded selection pass instead.\n\t\tout.set(tier, { floor, ceiling, allocated: Math.min(want, Math.max(floor, entry.hard)) });\n\t}\n\treturn out;\n}\n"]}
|
|
@@ -26,7 +26,14 @@ export interface TokenOptimizerRuntimeStatus {
|
|
|
26
26
|
readonly compatibilityOnly: true;
|
|
27
27
|
}
|
|
28
28
|
export interface TierBudgetPolicyV2 {
|
|
29
|
+
/**
|
|
30
|
+
* Guaranteed share of the available budget the floor-reservation pass
|
|
31
|
+
* spends on this tier's own items before leftovers compete globally.
|
|
32
|
+
* A real reservation — not merely a lower bound on the ceiling — so a
|
|
33
|
+
* higher-scored item in another tier cannot starve this tier's minimum.
|
|
34
|
+
*/
|
|
29
35
|
readonly floorPct: number;
|
|
36
|
+
/** Hard cap on this tier's share; selection above it is omitted. */
|
|
30
37
|
readonly ceilingPct: number;
|
|
31
38
|
}
|
|
32
39
|
export declare const DEFAULT_TIER_POLICY_V2: Readonly<Record<ContextBudgetTierV2, TierBudgetPolicyV2>>;
|
|
@@ -75,7 +82,7 @@ export interface TierBudgetAllocationV2 {
|
|
|
75
82
|
readonly usedTokens: number;
|
|
76
83
|
readonly hardTokens: number;
|
|
77
84
|
}
|
|
78
|
-
export type QualityDiagnosticReasonV2 = "omitted_high_priority" | "retrieval_miss_risk" | "restore_on_demand_hint" | "hard_pin_over_capacity" | "coverage_gap" | "tier_ceiling_exceeded" | "invalid_budget";
|
|
85
|
+
export type QualityDiagnosticReasonV2 = "omitted_high_priority" | "retrieval_miss_risk" | "restore_on_demand_hint" | "hard_pin_over_capacity" | "coverage_gap" | "tier_ceiling_exceeded" | "tier_floor_over_budget" | "invalid_input" | "invalid_budget";
|
|
79
86
|
export interface QualityDiagnosticV2 {
|
|
80
87
|
readonly reason: QualityDiagnosticReasonV2;
|
|
81
88
|
readonly itemId?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-budget-v2-types.d.ts","sourceRoot":"","sources":["../../src/core/context-budget-v2-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,mBAAmB,EACnB,mBAAmB,EACnB,oCAAoC,EACpC,gCAAgC,EAChC,2BAA2B,EAC3B,kBAAkB,EAClB,uBAAuB,EACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,KAAK,E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,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,mBAAmB,EAAE,OAAO,CAAC;IACtC,QAAQ,CAAC,eAAe,EAAE,SAAS,sBAAsB,EAAE,CAAC;IAC5D,QAAQ,CAAC,uBAAuB,EAAE,SAAS,wBAAwB,EAAE,CAAC;IACtE,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,QAAQ,CAAC,WAAW,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACrD,QAAQ,CAAC,kBAAkB,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAC3D,QAAQ,CAAC,aAAa,EAAE,kCAAkC,CAAC;CAC3D","sourcesContent":["import type {\n\tContextBudgetItemV2,\n\tContextBudgetTierV2,\n\tContextRepresentationCacheMetadataV2,\n\tContextRepresentationCandidateV2,\n\tContextRepresentationKindV2,\n\tContextSourceRefV2,\n\tHeadroomQualityPolicyV2,\n} from \"./context-budget-headroom.ts\";\nimport type { TokenCounterAdapter } from \"./context-budget-token-counter.ts\";\nimport type { ContextCacheInvalidationSnapshot } from \"./context-budget-v2-cache-invalidation.ts\";\n\n/**\n * Public optimizer identifier. It is reported in the system prompt and used as a\n * cache namespace, so it must stay stable across internal policy changes.\n */\nexport const CONTEXT_BUDGET_POLICY_VERSION_V2 = \"context-budget-v2\";\n\n/**\n * Internal token for the optional-item selection policy, kept separate from the\n * public identifier so a scoring or ordering change can invalidate cached plans\n * without renaming the optimizer. Bump it whenever the selected set can differ\n * for identical inputs; otherwise plans built under the previous policy keep\n * being served for the whole cache TTL, including from disk.\n *\n * `sel-2`: density-ordered selection over the cheapest admissible representation\n * (previously priority-class-ordered over full-text tokens).\n */\nexport const CONTEXT_BUDGET_SELECTION_POLICY_V2 = \"sel-2\";\n\n/** Fixed compatibility telemetry for the removed legacy token optimizer. */\nexport interface TokenOptimizerRuntimeStatus {\n\treadonly optimizerId: \"legacy-token-optimizer\";\n\treadonly status: \"quarantined_compatibility\";\n\treadonly active: false;\n\treadonly activeContextBudgetOptimizer: \"context-budget-v2\";\n\treadonly compatibilityOnly: true;\n}\n\nexport interface TierBudgetPolicyV2 {\n\treadonly floorPct: number;\n\treadonly ceilingPct: number;\n}\n\nexport const DEFAULT_TIER_POLICY_V2: Readonly<Record<ContextBudgetTierV2, TierBudgetPolicyV2>> = {\n\tsystem: { floorPct: 0.25, ceilingPct: 0.45 },\n\t\"active-goal\": { floorPct: 0.1, ceilingPct: 0.25 },\n\t\"current-files\": { floorPct: 0.08, ceilingPct: 0.2 },\n\ttools: { floorPct: 0.04, ceilingPct: 0.12 },\n\tskills: { floorPct: 0.03, ceilingPct: 0.12 },\n\tmcp: { floorPct: 0.02, ceilingPct: 0.08 },\n\thistory: { floorPct: 0.1, ceilingPct: 0.3 },\n\tevidence: { floorPct: 0.08, ceilingPct: 0.25 },\n\tscratch: { floorPct: 0, ceilingPct: 0.05 },\n};\n\nexport const ALL_TIERS_V2: readonly ContextBudgetTierV2[] = [\n\t\"system\",\n\t\"active-goal\",\n\t\"current-files\",\n\t\"tools\",\n\t\"skills\",\n\t\"mcp\",\n\t\"history\",\n\t\"evidence\",\n\t\"scratch\",\n];\n\nexport interface PromptContextBudgetInputV2 {\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens?: number;\n\treadonly safetyMarginTokens?: number;\n\treadonly modelId?: string;\n\treadonly tokenizerId?: string;\n\treadonly policyVersion?: string;\n\t/** Overrides {@link CONTEXT_BUDGET_SELECTION_POLICY_V2}. */\n\treadonly selectionPolicyVersion?: string;\n\treadonly promptHash?: string;\n\treadonly query?: string;\n\treadonly items: readonly ContextBudgetItemV2[];\n\treadonly tokenCounter?: TokenCounterAdapter;\n\treadonly tierPolicy?: Partial<Record<ContextBudgetTierV2, TierBudgetPolicyV2>>;\n\treadonly qualityPolicy?: HeadroomQualityPolicyV2;\n\treadonly cacheProvider?: ContextBudgetCacheProviderV2;\n\treadonly cacheNamespace?: string;\n\treadonly queryIntentHash?: string;\n\treadonly cacheBudgetBucket?: string;\n\treadonly redactionPolicyHash?: string;\n\treadonly safetyProfileHash?: string;\n\treadonly cacheNowEpochMs?: number;\n\treadonly cacheTtlMs?: number;\n\treadonly cacheInvalidationSnapshot?: ContextCacheInvalidationSnapshot;\n}\n\nexport interface SelectedRepresentationV2 {\n\treadonly itemId: string;\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly cache?: ContextRepresentationCacheMetadataV2;\n}\n\nexport interface TierBudgetAllocationV2 {\n\treadonly tier: ContextBudgetTierV2;\n\treadonly floorTokens: number;\n\treadonly ceilingTokens: number;\n\treadonly allocatedTokens: number;\n\treadonly usedTokens: number;\n\treadonly hardTokens: number;\n}\n\nexport type QualityDiagnosticReasonV2 =\n\t| \"omitted_high_priority\"\n\t| \"retrieval_miss_risk\"\n\t| \"restore_on_demand_hint\"\n\t| \"hard_pin_over_capacity\"\n\t| \"coverage_gap\"\n\t| \"tier_ceiling_exceeded\"\n\t| \"invalid_budget\";\n\nexport interface QualityDiagnosticV2 {\n\treadonly reason: QualityDiagnosticReasonV2;\n\treadonly itemId?: string;\n\treadonly detail: string;\n}\n\nexport interface ContextBudgetObservabilityCountsV2 {\n\treadonly selected: number;\n\treadonly omitted: number;\n\treadonly pointer: number;\n\treadonly compressed: number;\n\treadonly full: number;\n\treadonly retrievalFallback: number;\n}\n\nexport interface ContextBudgetObservabilityTokensV2 {\n\treadonly available: number;\n\treadonly used: number;\n\treadonly raw: number;\n\treadonly omitted: number;\n\treadonly tokenSavings: number;\n}\n\nexport type ContextBudgetCacheLayerV2 = \"turn\" | \"session\" | \"workspace\" | \"shared\";\n\nexport type ContextBudgetRepresentationCacheRejectReasonV2 =\n\t| \"fingerprint_mismatch\"\n\t| \"kind_mismatch\"\n\t| \"model_mismatch\"\n\t| \"negative\"\n\t| \"policy_mismatch\"\n\t| \"poisoned\"\n\t| \"source_hash_mismatch\"\n\t| \"stale\"\n\t| \"token_invalid\"\n\t| \"tokenizer_mismatch\";\n\nexport type ContextBudgetRepresentationCacheKeyKindV2 = \"exact\" | \"materialized\";\n\nexport interface ContextBudgetMaterializedVerificationV2 {\n\treadonly queryCoverage?: number;\n\treadonly sourceCoverage?: number;\n\treadonly secretLeakScore?: number;\n\treadonly poisonScore?: number;\n\treadonly validatorVersion?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheEntryV2 {\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceHash: string;\n\treadonly representationFingerprint: string;\n\treadonly keyKind?: ContextBudgetRepresentationCacheKeyKindV2;\n\treadonly modelId: string;\n\treadonly tokenizerId: string;\n\treadonly policyVersion: string;\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly compressorPolicyHash?: string;\n\treadonly qualityPolicyHash?: string;\n\treadonly queryIntentCluster?: string;\n\treadonly outputTextHash?: string;\n\treadonly targetTokenBucket?: number;\n\treadonly verification?: ContextBudgetMaterializedVerificationV2;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetRepresentationCacheReadV2 {\n\treadonly entry: ContextBudgetRepresentationCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetNegativeCacheEntryV2 {\n\treadonly reason: string;\n\treadonly createdAtEpochMs?: number;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetPlanCacheEntryV2 {\n\treadonly plan: PromptContextBudgetPlanV2;\n\treadonly sourceHashes: Readonly<Record<string, string>>;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetPlanCacheReadV2 {\n\treadonly entry: ContextBudgetPlanCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetCacheProviderV2 {\n\tgetInvalidationSnapshot?(): ContextCacheInvalidationSnapshot | undefined;\n\tsetInvalidationSnapshot?(snapshot: ContextCacheInvalidationSnapshot): void;\n\treadRepresentation(key: string): ContextBudgetRepresentationCacheReadV2 | undefined;\n\twriteRepresentation(input: { readonly key: string; readonly entry: ContextBudgetRepresentationCacheEntryV2 }): void;\n\tdeleteRepresentation?(key: string): void;\n\treadNegativeRepresentation(key: string): ContextBudgetNegativeCacheEntryV2 | undefined;\n\twriteNegativeRepresentation(input: { readonly key: string; readonly reason: string }): void;\n\tdeleteNegativeRepresentation?(key: string): void;\n\treadPlan(key: string): ContextBudgetPlanCacheReadV2 | undefined;\n\twritePlan(input: { readonly key: string; readonly entry: ContextBudgetPlanCacheEntryV2 }): void;\n\tdeletePlan?(key: string): void;\n}\n\nexport interface ContextBudgetPlanCacheTelemetryV2 {\n\treadonly hit: boolean;\n\treadonly key: string;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n\treadonly rejectedReason?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheTelemetryV2 {\n\treadonly exactHits: number;\n\treadonly semanticHits: number;\n\treadonly pointerHits: number;\n\treadonly misses: number;\n\treadonly staleRejects: number;\n\treadonly poisonRejects: number;\n\treadonly negativeHits: number;\n\treadonly writes: number;\n}\n\nexport interface ContextBudgetCacheTokenTelemetryV2 {\n\treadonly raw: number;\n\treadonly rendered: number;\n\treadonly savedByCache: number;\n\treadonly savedByCompression: number;\n\treadonly savedByOmission: number;\n}\n\nexport interface TokenCacheTelemetryV2 {\n\treadonly planCache: ContextBudgetPlanCacheTelemetryV2;\n\treadonly representationCache: ContextBudgetRepresentationCacheTelemetryV2;\n\treadonly tokens: ContextBudgetCacheTokenTelemetryV2;\n}\n\nexport interface PromptContextBudgetObservabilityV2 {\n\treadonly counts: ContextBudgetObservabilityCountsV2;\n\treadonly diagnosticReasons: readonly QualityDiagnosticReasonV2[];\n\treadonly tokens: ContextBudgetObservabilityTokensV2;\n\treadonly planHash: string;\n\treadonly cache: TokenCacheTelemetryV2;\n\treadonly tokenOptimizer: TokenOptimizerRuntimeStatus;\n}\n\nexport interface PromptContextBudgetPlanV2 {\n\treadonly policyVersion: string;\n\treadonly promptHash?: string;\n\treadonly planHash: string;\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens: number;\n\treadonly safetyMarginTokens: number;\n\treadonly availableTokens: number;\n\treadonly usedTokens: number;\n\treadonly omittedTokens: number;\n\treadonly rawTokens: number;\n\treadonly tokenSavingsRatio: number;\n\treadonly emergency: boolean;\n\treadonly omittedHighPriority: boolean;\n\treadonly tierAllocations: readonly TierBudgetAllocationV2[];\n\treadonly selectedRepresentations: readonly SelectedRepresentationV2[];\n\treadonly includedItemIds: readonly string[];\n\treadonly omittedItemIds: readonly string[];\n\treadonly diagnostics: readonly QualityDiagnosticV2[];\n\treadonly retrievalFallbacks: readonly ContextSourceRefV2[];\n\treadonly observability: PromptContextBudgetObservabilityV2;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"context-budget-v2-types.d.ts","sourceRoot":"","sources":["../../src/core/context-budget-v2-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,mBAAmB,EACnB,mBAAmB,EACnB,oCAAoC,EACpC,gCAAgC,EAChC,2BAA2B,EAC3B,kBAAkB,EAClB,uBAAuB,EACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,2CAA2C,CAAC;AAElG;;;GAGG;AACH,eAAO,MAAM,gCAAgC,sBAAsB,CAAC;AAEpE;;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,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,mBAAmB,EAAE,OAAO,CAAC;IACtC,QAAQ,CAAC,eAAe,EAAE,SAAS,sBAAsB,EAAE,CAAC;IAC5D,QAAQ,CAAC,uBAAuB,EAAE,SAAS,wBAAwB,EAAE,CAAC;IACtE,QAAQ,CAAC,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5C,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,QAAQ,CAAC,WAAW,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACrD,QAAQ,CAAC,kBAAkB,EAAE,SAAS,kBAAkB,EAAE,CAAC;IAC3D,QAAQ,CAAC,aAAa,EAAE,kCAAkC,CAAC;CAC3D","sourcesContent":["import type {\n\tContextBudgetItemV2,\n\tContextBudgetTierV2,\n\tContextRepresentationCacheMetadataV2,\n\tContextRepresentationCandidateV2,\n\tContextRepresentationKindV2,\n\tContextSourceRefV2,\n\tHeadroomQualityPolicyV2,\n} from \"./context-budget-headroom.ts\";\nimport type { TokenCounterAdapter } from \"./context-budget-token-counter.ts\";\nimport type { ContextCacheInvalidationSnapshot } from \"./context-budget-v2-cache-invalidation.ts\";\n\n/**\n * Public optimizer identifier. It is reported in the system prompt and used as a\n * cache namespace, so it must stay stable across internal policy changes.\n */\nexport const CONTEXT_BUDGET_POLICY_VERSION_V2 = \"context-budget-v2\";\n\n/**\n * Internal token for the optional-item selection policy, kept separate from the\n * public identifier so a scoring or ordering change can invalidate cached plans\n * without renaming the optimizer. Bump it whenever the selected set can differ\n * for identical inputs; otherwise plans built under the previous policy keep\n * being served for the whole cache TTL, including from disk.\n *\n * `sel-2`: density-ordered selection over the cheapest admissible representation\n * (previously priority-class-ordered over full-text tokens).\n */\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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-budget-v2-types.js","sourceRoot":"","sources":["../../src/core/context-budget-v2-types.ts"],"names":[],"mappings":"AAYA;;;GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAAmB,CAAC;AAEpE;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,OAAO,CAAC;AAgB1D,MAAM,CAAC,MAAM,sBAAsB,GAA8D;IAChG,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC5C,aAAa,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE;IAClD,eAAe,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE;IACpD,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC3C,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC5C,GAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IACzC,OAAO,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,EAAE;IAC3C,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE;IAC9C,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE;CAC1C,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAmC;IAC3D,QAAQ;IACR,aAAa;IACb,eAAe;IACf,OAAO;IACP,QAAQ;IACR,KAAK;IACL,SAAS;IACT,UAAU;IACV,SAAS;CACT,CAAC","sourcesContent":["import type {\n\tContextBudgetItemV2,\n\tContextBudgetTierV2,\n\tContextRepresentationCacheMetadataV2,\n\tContextRepresentationCandidateV2,\n\tContextRepresentationKindV2,\n\tContextSourceRefV2,\n\tHeadroomQualityPolicyV2,\n} from \"./context-budget-headroom.ts\";\nimport type { TokenCounterAdapter } from \"./context-budget-token-counter.ts\";\nimport type { ContextCacheInvalidationSnapshot } from \"./context-budget-v2-cache-invalidation.ts\";\n\n/**\n * Public optimizer identifier. It is reported in the system prompt and used as a\n * cache namespace, so it must stay stable across internal policy changes.\n */\nexport const CONTEXT_BUDGET_POLICY_VERSION_V2 = \"context-budget-v2\";\n\n/**\n * Internal token for the optional-item selection policy, kept separate from the\n * public identifier so a scoring or ordering change can invalidate cached plans\n * without renaming the optimizer. Bump it whenever the selected set can differ\n * for identical inputs; otherwise plans built under the previous policy keep\n * being served for the whole cache TTL, including from disk.\n *\n * `sel-2`: density-ordered selection over the cheapest admissible representation\n * (previously priority-class-ordered over full-text tokens).\n */\nexport const CONTEXT_BUDGET_SELECTION_POLICY_V2 = \"sel-2\";\n\n/** Fixed compatibility telemetry for the removed legacy token optimizer. */\nexport interface TokenOptimizerRuntimeStatus {\n\treadonly optimizerId: \"legacy-token-optimizer\";\n\treadonly status: \"quarantined_compatibility\";\n\treadonly active: false;\n\treadonly activeContextBudgetOptimizer: \"context-budget-v2\";\n\treadonly compatibilityOnly: true;\n}\n\nexport interface TierBudgetPolicyV2 {\n\treadonly floorPct: number;\n\treadonly ceilingPct: number;\n}\n\nexport const DEFAULT_TIER_POLICY_V2: Readonly<Record<ContextBudgetTierV2, TierBudgetPolicyV2>> = {\n\tsystem: { floorPct: 0.25, ceilingPct: 0.45 },\n\t\"active-goal\": { floorPct: 0.1, ceilingPct: 0.25 },\n\t\"current-files\": { floorPct: 0.08, ceilingPct: 0.2 },\n\ttools: { floorPct: 0.04, ceilingPct: 0.12 },\n\tskills: { floorPct: 0.03, ceilingPct: 0.12 },\n\tmcp: { floorPct: 0.02, ceilingPct: 0.08 },\n\thistory: { floorPct: 0.1, ceilingPct: 0.3 },\n\tevidence: { floorPct: 0.08, ceilingPct: 0.25 },\n\tscratch: { floorPct: 0, ceilingPct: 0.05 },\n};\n\nexport const ALL_TIERS_V2: readonly ContextBudgetTierV2[] = [\n\t\"system\",\n\t\"active-goal\",\n\t\"current-files\",\n\t\"tools\",\n\t\"skills\",\n\t\"mcp\",\n\t\"history\",\n\t\"evidence\",\n\t\"scratch\",\n];\n\nexport interface PromptContextBudgetInputV2 {\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens?: number;\n\treadonly safetyMarginTokens?: number;\n\treadonly modelId?: string;\n\treadonly tokenizerId?: string;\n\treadonly policyVersion?: string;\n\t/** Overrides {@link CONTEXT_BUDGET_SELECTION_POLICY_V2}. */\n\treadonly selectionPolicyVersion?: string;\n\treadonly promptHash?: string;\n\treadonly query?: string;\n\treadonly items: readonly ContextBudgetItemV2[];\n\treadonly tokenCounter?: TokenCounterAdapter;\n\treadonly tierPolicy?: Partial<Record<ContextBudgetTierV2, TierBudgetPolicyV2>>;\n\treadonly qualityPolicy?: HeadroomQualityPolicyV2;\n\treadonly cacheProvider?: ContextBudgetCacheProviderV2;\n\treadonly cacheNamespace?: string;\n\treadonly queryIntentHash?: string;\n\treadonly cacheBudgetBucket?: string;\n\treadonly redactionPolicyHash?: string;\n\treadonly safetyProfileHash?: string;\n\treadonly cacheNowEpochMs?: number;\n\treadonly cacheTtlMs?: number;\n\treadonly cacheInvalidationSnapshot?: ContextCacheInvalidationSnapshot;\n}\n\nexport interface SelectedRepresentationV2 {\n\treadonly itemId: string;\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly cache?: ContextRepresentationCacheMetadataV2;\n}\n\nexport interface TierBudgetAllocationV2 {\n\treadonly tier: ContextBudgetTierV2;\n\treadonly floorTokens: number;\n\treadonly ceilingTokens: number;\n\treadonly allocatedTokens: number;\n\treadonly usedTokens: number;\n\treadonly hardTokens: number;\n}\n\nexport type QualityDiagnosticReasonV2 =\n\t| \"omitted_high_priority\"\n\t| \"retrieval_miss_risk\"\n\t| \"restore_on_demand_hint\"\n\t| \"hard_pin_over_capacity\"\n\t| \"coverage_gap\"\n\t| \"tier_ceiling_exceeded\"\n\t| \"invalid_budget\";\n\nexport interface QualityDiagnosticV2 {\n\treadonly reason: QualityDiagnosticReasonV2;\n\treadonly itemId?: string;\n\treadonly detail: string;\n}\n\nexport interface ContextBudgetObservabilityCountsV2 {\n\treadonly selected: number;\n\treadonly omitted: number;\n\treadonly pointer: number;\n\treadonly compressed: number;\n\treadonly full: number;\n\treadonly retrievalFallback: number;\n}\n\nexport interface ContextBudgetObservabilityTokensV2 {\n\treadonly available: number;\n\treadonly used: number;\n\treadonly raw: number;\n\treadonly omitted: number;\n\treadonly tokenSavings: number;\n}\n\nexport type ContextBudgetCacheLayerV2 = \"turn\" | \"session\" | \"workspace\" | \"shared\";\n\nexport type ContextBudgetRepresentationCacheRejectReasonV2 =\n\t| \"fingerprint_mismatch\"\n\t| \"kind_mismatch\"\n\t| \"model_mismatch\"\n\t| \"negative\"\n\t| \"policy_mismatch\"\n\t| \"poisoned\"\n\t| \"source_hash_mismatch\"\n\t| \"stale\"\n\t| \"token_invalid\"\n\t| \"tokenizer_mismatch\";\n\nexport type ContextBudgetRepresentationCacheKeyKindV2 = \"exact\" | \"materialized\";\n\nexport interface ContextBudgetMaterializedVerificationV2 {\n\treadonly queryCoverage?: number;\n\treadonly sourceCoverage?: number;\n\treadonly secretLeakScore?: number;\n\treadonly poisonScore?: number;\n\treadonly validatorVersion?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheEntryV2 {\n\treadonly kind: ContextRepresentationKindV2;\n\treadonly text: string;\n\treadonly estimatedTokens: number;\n\treadonly fidelity: ContextRepresentationCandidateV2[\"fidelity\"];\n\treadonly sourceHash: string;\n\treadonly representationFingerprint: string;\n\treadonly keyKind?: ContextBudgetRepresentationCacheKeyKindV2;\n\treadonly modelId: string;\n\treadonly tokenizerId: string;\n\treadonly policyVersion: string;\n\treadonly sourceRef?: ContextSourceRefV2;\n\treadonly summaryHash?: string;\n\treadonly compressorId?: string;\n\treadonly compressorPolicyHash?: string;\n\treadonly qualityPolicyHash?: string;\n\treadonly queryIntentCluster?: string;\n\treadonly outputTextHash?: string;\n\treadonly targetTokenBucket?: number;\n\treadonly verification?: ContextBudgetMaterializedVerificationV2;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetRepresentationCacheReadV2 {\n\treadonly entry: ContextBudgetRepresentationCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetNegativeCacheEntryV2 {\n\treadonly reason: string;\n\treadonly createdAtEpochMs?: number;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetPlanCacheEntryV2 {\n\treadonly plan: PromptContextBudgetPlanV2;\n\treadonly sourceHashes: Readonly<Record<string, string>>;\n\treadonly createdAtEpochMs?: number;\n}\n\nexport interface ContextBudgetPlanCacheReadV2 {\n\treadonly entry: ContextBudgetPlanCacheEntryV2;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n}\n\nexport interface ContextBudgetCacheProviderV2 {\n\tgetInvalidationSnapshot?(): ContextCacheInvalidationSnapshot | undefined;\n\tsetInvalidationSnapshot?(snapshot: ContextCacheInvalidationSnapshot): void;\n\treadRepresentation(key: string): ContextBudgetRepresentationCacheReadV2 | undefined;\n\twriteRepresentation(input: { readonly key: string; readonly entry: ContextBudgetRepresentationCacheEntryV2 }): void;\n\tdeleteRepresentation?(key: string): void;\n\treadNegativeRepresentation(key: string): ContextBudgetNegativeCacheEntryV2 | undefined;\n\twriteNegativeRepresentation(input: { readonly key: string; readonly reason: string }): void;\n\tdeleteNegativeRepresentation?(key: string): void;\n\treadPlan(key: string): ContextBudgetPlanCacheReadV2 | undefined;\n\twritePlan(input: { readonly key: string; readonly entry: ContextBudgetPlanCacheEntryV2 }): void;\n\tdeletePlan?(key: string): void;\n}\n\nexport interface ContextBudgetPlanCacheTelemetryV2 {\n\treadonly hit: boolean;\n\treadonly key: string;\n\treadonly layer?: ContextBudgetCacheLayerV2;\n\treadonly rejectedReason?: string;\n}\n\nexport interface ContextBudgetRepresentationCacheTelemetryV2 {\n\treadonly exactHits: number;\n\treadonly semanticHits: number;\n\treadonly pointerHits: number;\n\treadonly misses: number;\n\treadonly staleRejects: number;\n\treadonly poisonRejects: number;\n\treadonly negativeHits: number;\n\treadonly writes: number;\n}\n\nexport interface ContextBudgetCacheTokenTelemetryV2 {\n\treadonly raw: number;\n\treadonly rendered: number;\n\treadonly savedByCache: number;\n\treadonly savedByCompression: number;\n\treadonly savedByOmission: number;\n}\n\nexport interface TokenCacheTelemetryV2 {\n\treadonly planCache: ContextBudgetPlanCacheTelemetryV2;\n\treadonly representationCache: ContextBudgetRepresentationCacheTelemetryV2;\n\treadonly tokens: ContextBudgetCacheTokenTelemetryV2;\n}\n\nexport interface PromptContextBudgetObservabilityV2 {\n\treadonly counts: ContextBudgetObservabilityCountsV2;\n\treadonly diagnosticReasons: readonly QualityDiagnosticReasonV2[];\n\treadonly tokens: ContextBudgetObservabilityTokensV2;\n\treadonly planHash: string;\n\treadonly cache: TokenCacheTelemetryV2;\n\treadonly tokenOptimizer: TokenOptimizerRuntimeStatus;\n}\n\nexport interface PromptContextBudgetPlanV2 {\n\treadonly policyVersion: string;\n\treadonly promptHash?: string;\n\treadonly planHash: string;\n\treadonly maxTokens: number;\n\treadonly responseReserveTokens: number;\n\treadonly safetyMarginTokens: number;\n\treadonly availableTokens: number;\n\treadonly usedTokens: number;\n\treadonly omittedTokens: number;\n\treadonly rawTokens: number;\n\treadonly tokenSavingsRatio: number;\n\treadonly emergency: boolean;\n\treadonly omittedHighPriority: boolean;\n\treadonly tierAllocations: readonly TierBudgetAllocationV2[];\n\treadonly selectedRepresentations: readonly SelectedRepresentationV2[];\n\treadonly includedItemIds: readonly string[];\n\treadonly omittedItemIds: readonly string[];\n\treadonly diagnostics: readonly QualityDiagnosticV2[];\n\treadonly retrievalFallbacks: readonly ContextSourceRefV2[];\n\treadonly observability: PromptContextBudgetObservabilityV2;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"context-budget-v2-types.js","sourceRoot":"","sources":["../../src/core/context-budget-v2-types.ts"],"names":[],"mappings":"AAYA;;;GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAAmB,CAAC;AAEpE;;;;;;;;;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"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apply the `devin-harness` domain loadout when the active provider is Devin.
|
|
3
|
+
* Does not require `OMK_DOMAIN_ROUTING=1`. Convenience wrapper over
|
|
4
|
+
* `tryProviderHarnessDispatch()` bound to the real loadout runtime.
|
|
5
|
+
*/
|
|
6
|
+
import type { LoadoutRuntimeSession, LoadoutRuntimeState } from "./loadout-runtime.ts";
|
|
7
|
+
import { type ProviderHarnessDispatchInput, type ProviderHarnessDispatchResult } from "./provider-harness-dispatch.ts";
|
|
8
|
+
import type { ResourceLoader } from "./resource-loader.ts";
|
|
9
|
+
export type DevinHarnessDispatchInput = ProviderHarnessDispatchInput<LoadoutRuntimeSession, ResourceLoader>;
|
|
10
|
+
export type DevinHarnessDispatchResult = ProviderHarnessDispatchResult<LoadoutRuntimeState>;
|
|
11
|
+
export declare function tryDevinHarnessDispatch(input: DevinHarnessDispatchInput): DevinHarnessDispatchResult;
|
|
12
|
+
//# sourceMappingURL=devin-harness-dispatch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devin-harness-dispatch.d.ts","sourceRoot":"","sources":["../../src/core/devin-harness-dispatch.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACvF,OAAO,EACN,KAAK,4BAA4B,EACjC,KAAK,6BAA6B,EAElC,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,MAAM,MAAM,yBAAyB,GAAG,4BAA4B,CAAC,qBAAqB,EAAE,cAAc,CAAC,CAAC;AAC5G,MAAM,MAAM,0BAA0B,GAAG,6BAA6B,CAAC,mBAAmB,CAAC,CAAC;AAE5F,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,yBAAyB,GAAG,0BAA0B,CAEpG","sourcesContent":["/**\n * Apply the `devin-harness` domain loadout when the active provider is Devin.\n * Does not require `OMK_DOMAIN_ROUTING=1`. Convenience wrapper over\n * `tryProviderHarnessDispatch()` bound to the real loadout runtime.\n */\n\nimport { DEVIN_HARNESS_SPEC } from \"./devin-harness.ts\";\nimport { LOADOUT_HARNESS_RUNTIME } from \"./domain-dispatch.ts\";\nimport type { LoadoutRuntimeSession, LoadoutRuntimeState } from \"./loadout-runtime.ts\";\nimport {\n\ttype ProviderHarnessDispatchInput,\n\ttype ProviderHarnessDispatchResult,\n\ttryProviderHarnessDispatch,\n} from \"./provider-harness-dispatch.ts\";\nimport type { ResourceLoader } from \"./resource-loader.ts\";\n\nexport type DevinHarnessDispatchInput = ProviderHarnessDispatchInput<LoadoutRuntimeSession, ResourceLoader>;\nexport type DevinHarnessDispatchResult = ProviderHarnessDispatchResult<LoadoutRuntimeState>;\n\nexport function tryDevinHarnessDispatch(input: DevinHarnessDispatchInput): DevinHarnessDispatchResult {\n\treturn tryProviderHarnessDispatch(DEVIN_HARNESS_SPEC, LOADOUT_HARNESS_RUNTIME, input);\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Apply the `devin-harness` domain loadout when the active provider is Devin.
|
|
3
|
+
* Does not require `OMK_DOMAIN_ROUTING=1`. Convenience wrapper over
|
|
4
|
+
* `tryProviderHarnessDispatch()` bound to the real loadout runtime.
|
|
5
|
+
*/
|
|
6
|
+
import { DEVIN_HARNESS_SPEC } from "./devin-harness.js";
|
|
7
|
+
import { LOADOUT_HARNESS_RUNTIME } from "./domain-dispatch.js";
|
|
8
|
+
import { tryProviderHarnessDispatch, } from "./provider-harness-dispatch.js";
|
|
9
|
+
export function tryDevinHarnessDispatch(input) {
|
|
10
|
+
return tryProviderHarnessDispatch(DEVIN_HARNESS_SPEC, LOADOUT_HARNESS_RUNTIME, input);
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=devin-harness-dispatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devin-harness-dispatch.js","sourceRoot":"","sources":["../../src/core/devin-harness-dispatch.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,EAGN,0BAA0B,GAC1B,MAAM,gCAAgC,CAAC;AAMxC,MAAM,UAAU,uBAAuB,CAAC,KAAgC,EAA8B;IACrG,OAAO,0BAA0B,CAAC,kBAAkB,EAAE,uBAAuB,EAAE,KAAK,CAAC,CAAC;AAAA,CACtF","sourcesContent":["/**\n * Apply the `devin-harness` domain loadout when the active provider is Devin.\n * Does not require `OMK_DOMAIN_ROUTING=1`. Convenience wrapper over\n * `tryProviderHarnessDispatch()` bound to the real loadout runtime.\n */\n\nimport { DEVIN_HARNESS_SPEC } from \"./devin-harness.ts\";\nimport { LOADOUT_HARNESS_RUNTIME } from \"./domain-dispatch.ts\";\nimport type { LoadoutRuntimeSession, LoadoutRuntimeState } from \"./loadout-runtime.ts\";\nimport {\n\ttype ProviderHarnessDispatchInput,\n\ttype ProviderHarnessDispatchResult,\n\ttryProviderHarnessDispatch,\n} from \"./provider-harness-dispatch.ts\";\nimport type { ResourceLoader } from \"./resource-loader.ts\";\n\nexport type DevinHarnessDispatchInput = ProviderHarnessDispatchInput<LoadoutRuntimeSession, ResourceLoader>;\nexport type DevinHarnessDispatchResult = ProviderHarnessDispatchResult<LoadoutRuntimeState>;\n\nexport function tryDevinHarnessDispatch(input: DevinHarnessDispatchInput): DevinHarnessDispatchResult {\n\treturn tryProviderHarnessDispatch(DEVIN_HARNESS_SPEC, LOADOUT_HARNESS_RUNTIME, input);\n}\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Devin SWE-2 harness: provider identity, auto-apply flag, per-turn skill
|
|
3
|
+
* grants, and the optional `~/.omk/agent/devin.md` operator overlay.
|
|
4
|
+
*
|
|
5
|
+
* The canonical operator contract is `docs/devin-harness.md`; the domain
|
|
6
|
+
* loadout is `devin-harness` in `domain-loadouts.ts`.
|
|
7
|
+
*/
|
|
8
|
+
import { type HarnessSkillCandidate, type HarnessSkillSelectionOptions } from "./harness-skills.ts";
|
|
9
|
+
import type { ProviderHarnessSpec } from "./provider-harness-dispatch.ts";
|
|
10
|
+
/** Built-in provider id for the Devin CLI subscription adapter. */
|
|
11
|
+
export declare const DEVIN_PROVIDER = "devin";
|
|
12
|
+
/** The only logical model the Devin adapter serves. */
|
|
13
|
+
export declare const DEVIN_SWE2_MODEL_ID = "swe-2";
|
|
14
|
+
/** Local context budget bundled with `devin/swe-2`; mirrors `DEVIN_LONG_CONTEXT_TOKENS` in omk-ai. */
|
|
15
|
+
export declare const DEVIN_SWE2_CONTEXT_WINDOW = 1000000;
|
|
16
|
+
/** Domain loadout id applied automatically when the Devin provider is active. */
|
|
17
|
+
export declare const DEVIN_HARNESS_DOMAIN_ID = "devin-harness";
|
|
18
|
+
/** Optional host-specific operator overlay appended to the system prompt on Devin sessions. */
|
|
19
|
+
export declare const DEVIN_PLAYBOOK_FILENAME = "devin.md";
|
|
20
|
+
/** Cap live system-prompt append size to reduce threshold autocompaction churn. */
|
|
21
|
+
export declare const DEVIN_PLAYBOOK_MAX_APPEND_CHARS = 24000;
|
|
22
|
+
/** SWE-2 efforts the adapter accepts; every other thinking level is rejected before credentials are sent. */
|
|
23
|
+
export declare const DEVIN_SWE2_EFFORTS: readonly ["medium", "high", "max"];
|
|
24
|
+
export type DevinSwe2Effort = (typeof DEVIN_SWE2_EFFORTS)[number];
|
|
25
|
+
export type DevinHarnessIntent = "code" | "debug" | "test" | "repo";
|
|
26
|
+
export type DevinHarnessSkillCandidate = HarnessSkillCandidate;
|
|
27
|
+
export type DevinHarnessSkillSelectionOptions = HarnessSkillSelectionOptions;
|
|
28
|
+
export declare function isDevinProvider(provider: string | undefined): boolean;
|
|
29
|
+
export declare function isDevinSwe2Effort(level: string | undefined): level is DevinSwe2Effort;
|
|
30
|
+
/**
|
|
31
|
+
* Recommended effort for a task class. SWE-2 medium acts sooner on simple and
|
|
32
|
+
* intermediate work; high and max plan and verify more on complex work.
|
|
33
|
+
*/
|
|
34
|
+
export declare function recommendedDevinEffortForIntent(intent: DevinHarnessIntent): DevinSwe2Effort;
|
|
35
|
+
export declare function recommendedDevinSkillTierForIntent(intent: DevinHarnessIntent): readonly string[];
|
|
36
|
+
/**
|
|
37
|
+
* Smallest devin-harness skill grant from the live inventory. The domain
|
|
38
|
+
* profile owns the allowlist; explicit-only skills are excluded. `headroom`
|
|
39
|
+
* requires lexical or measured pressure, and the result never exceeds
|
|
40
|
+
* `MAX_SELECTED_SKILLS` names.
|
|
41
|
+
*/
|
|
42
|
+
export declare function selectDevinHarnessSkills(task: string, inventory: readonly DevinHarnessSkillCandidate[], options?: DevinHarnessSkillSelectionOptions): readonly string[];
|
|
43
|
+
/**
|
|
44
|
+
* When true (default), selecting the `devin` provider applies the `devin-harness`
|
|
45
|
+
* domain loadout (skills/MCP/hooks/tool gate). Set `OMK_DEVIN_HARNESS=0` to disable.
|
|
46
|
+
*/
|
|
47
|
+
export declare function devinHarnessAutoApplyEnabled(env?: NodeJS.ProcessEnv | Readonly<Record<string, string | undefined>>): boolean;
|
|
48
|
+
/** Provider-harness spec consumed by `tryProviderHarnessDispatch()`. */
|
|
49
|
+
export declare const DEVIN_HARNESS_SPEC: ProviderHarnessSpec;
|
|
50
|
+
/** Read ~/.omk/agent/devin.md for appending to the system prompt on Devin sessions. */
|
|
51
|
+
export declare function loadDevinPlaybookAppend(): string | undefined;
|
|
52
|
+
export declare function devinPlaybookAppendForProvider(provider: string | undefined): string | undefined;
|
|
53
|
+
//# sourceMappingURL=devin-harness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devin-harness.d.ts","sourceRoot":"","sources":["../../src/core/devin-harness.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,EAEjC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAE1E,mEAAmE;AACnE,eAAO,MAAM,cAAc,UAAU,CAAC;AAEtC,uDAAuD;AACvD,eAAO,MAAM,mBAAmB,UAAU,CAAC;AAE3C,sGAAsG;AACtG,eAAO,MAAM,yBAAyB,UAAY,CAAC;AAEnD,iFAAiF;AACjF,eAAO,MAAM,uBAAuB,kBAAkB,CAAC;AAIvD,+FAA+F;AAC/F,eAAO,MAAM,uBAAuB,aAAa,CAAC;AAElD,mFAAmF;AACnF,eAAO,MAAM,+BAA+B,QAAS,CAAC;AAEtD,6GAA6G;AAC7G,eAAO,MAAM,kBAAkB,oCAAqC,CAAC;AACrE,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAElE,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AASpE,MAAM,MAAM,0BAA0B,GAAG,qBAAqB,CAAC;AAC/D,MAAM,MAAM,iCAAiC,GAAG,4BAA4B,CAAC;AAM7E,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAErE;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,KAAK,IAAI,eAAe,CAErF;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,kBAAkB,GAAG,eAAe,CAU3F;AAED,wBAAgB,kCAAkC,CAAC,MAAM,EAAE,kBAAkB,GAAG,SAAS,MAAM,EAAE,CAEhG;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACvC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,SAAS,0BAA0B,EAAE,EAChD,OAAO,GAAE,iCAAsC,GAC7C,SAAS,MAAM,EAAE,CAEnB;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAC3C,GAAG,GAAE,MAAM,CAAC,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAe,GACjF,OAAO,CAMT;AAED,wEAAwE;AACxE,eAAO,MAAM,kBAAkB,EAAE,mBAIhC,CAAC;AAEF,uFAAuF;AACvF,wBAAgB,uBAAuB,IAAI,MAAM,GAAG,SAAS,CAiB5D;AAED,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAK/F","sourcesContent":["/**\n * Devin SWE-2 harness: provider identity, auto-apply flag, per-turn skill\n * grants, and the optional `~/.omk/agent/devin.md` operator overlay.\n *\n * The canonical operator contract is `docs/devin-harness.md`; the domain\n * loadout is `devin-harness` in `domain-loadouts.ts`.\n */\n\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { getAgentDir } from \"../config.ts\";\nimport { getDomainProfile } from \"./domain-loadouts.ts\";\nimport {\n\ttype HarnessSkillCandidate,\n\ttype HarnessSkillSelectionOptions,\n\tselectHarnessSkills,\n} from \"./harness-skills.ts\";\nimport { capabilityGateNames } from \"./loadout-safety.ts\";\nimport type { ProviderHarnessSpec } from \"./provider-harness-dispatch.ts\";\n\n/** Built-in provider id for the Devin CLI subscription adapter. */\nexport const DEVIN_PROVIDER = \"devin\";\n\n/** The only logical model the Devin adapter serves. */\nexport const DEVIN_SWE2_MODEL_ID = \"swe-2\";\n\n/** Local context budget bundled with `devin/swe-2`; mirrors `DEVIN_LONG_CONTEXT_TOKENS` in omk-ai. */\nexport const DEVIN_SWE2_CONTEXT_WINDOW = 1_000_000;\n\n/** Domain loadout id applied automatically when the Devin provider is active. */\nexport const DEVIN_HARNESS_DOMAIN_ID = \"devin-harness\";\n\nconst DEVIN_HARNESS_AUTO_APPLY_ENV = \"OMK_DEVIN_HARNESS\";\n\n/** Optional host-specific operator overlay appended to the system prompt on Devin sessions. */\nexport const DEVIN_PLAYBOOK_FILENAME = \"devin.md\";\n\n/** Cap live system-prompt append size to reduce threshold autocompaction churn. */\nexport const DEVIN_PLAYBOOK_MAX_APPEND_CHARS = 24_000;\n\n/** SWE-2 efforts the adapter accepts; every other thinking level is rejected before credentials are sent. */\nexport const DEVIN_SWE2_EFFORTS = [\"medium\", \"high\", \"max\"] as const;\nexport type DevinSwe2Effort = (typeof DEVIN_SWE2_EFFORTS)[number];\n\nexport type DevinHarnessIntent = \"code\" | \"debug\" | \"test\" | \"repo\";\n\nconst SKILLS_BY_INTENT = {\n\tcode: [\"packages\", \"programming\"],\n\tdebug: [\"packages\", \"debugging\", \"programming\"],\n\ttest: [\"tdd-workflow\", \"programming\"],\n\trepo: [\"understand-anything\", \"packages\"],\n} as const satisfies Record<DevinHarnessIntent, readonly string[]>;\n\nexport type DevinHarnessSkillCandidate = HarnessSkillCandidate;\nexport type DevinHarnessSkillSelectionOptions = HarnessSkillSelectionOptions;\n\nconst DEVIN_HARNESS_ALLOWED_SKILLS: ReadonlySet<string> = new Set(\n\tcapabilityGateNames(getDomainProfile(DEVIN_HARNESS_DOMAIN_ID).skills),\n);\n\nexport function isDevinProvider(provider: string | undefined): boolean {\n\treturn provider === DEVIN_PROVIDER;\n}\n\nexport function isDevinSwe2Effort(level: string | undefined): level is DevinSwe2Effort {\n\treturn (DEVIN_SWE2_EFFORTS as readonly string[]).includes(level ?? \"\");\n}\n\n/**\n * Recommended effort for a task class. SWE-2 medium acts sooner on simple and\n * intermediate work; high and max plan and verify more on complex work.\n */\nexport function recommendedDevinEffortForIntent(intent: DevinHarnessIntent): DevinSwe2Effort {\n\tswitch (intent) {\n\t\tcase \"code\":\n\t\t\treturn \"medium\";\n\t\tcase \"test\":\n\t\t\treturn \"high\";\n\t\tcase \"debug\":\n\t\tcase \"repo\":\n\t\t\treturn \"max\";\n\t}\n}\n\nexport function recommendedDevinSkillTierForIntent(intent: DevinHarnessIntent): readonly string[] {\n\treturn SKILLS_BY_INTENT[intent];\n}\n\n/**\n * Smallest devin-harness skill grant from the live inventory. The domain\n * profile owns the allowlist; explicit-only skills are excluded. `headroom`\n * requires lexical or measured pressure, and the result never exceeds\n * `MAX_SELECTED_SKILLS` names.\n */\nexport function selectDevinHarnessSkills(\n\ttask: string,\n\tinventory: readonly DevinHarnessSkillCandidate[],\n\toptions: DevinHarnessSkillSelectionOptions = {},\n): readonly string[] {\n\treturn selectHarnessSkills(DEVIN_HARNESS_ALLOWED_SKILLS, task, inventory, options);\n}\n\n/**\n * When true (default), selecting the `devin` provider applies the `devin-harness`\n * domain loadout (skills/MCP/hooks/tool gate). Set `OMK_DEVIN_HARNESS=0` to disable.\n */\nexport function devinHarnessAutoApplyEnabled(\n\tenv: NodeJS.ProcessEnv | Readonly<Record<string, string | undefined>> = process.env,\n): boolean {\n\tconst raw = env[DEVIN_HARNESS_AUTO_APPLY_ENV]?.trim().toLowerCase();\n\tif (raw === \"0\" || raw === \"false\" || raw === \"off\" || raw === \"no\") {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\n/** Provider-harness spec consumed by `tryProviderHarnessDispatch()`. */\nexport const DEVIN_HARNESS_SPEC: ProviderHarnessSpec = {\n\tdomainId: DEVIN_HARNESS_DOMAIN_ID,\n\tapplies: (provider, env) => devinHarnessAutoApplyEnabled(env) && isDevinProvider(provider),\n\tselectSkills: (task, inventory, options) => selectDevinHarnessSkills(task, inventory, { paths: options.paths }),\n};\n\n/** Read ~/.omk/agent/devin.md for appending to the system prompt on Devin sessions. */\nexport function loadDevinPlaybookAppend(): string | undefined {\n\tconst path = join(getAgentDir(), DEVIN_PLAYBOOK_FILENAME);\n\tif (!existsSync(path)) {\n\t\treturn undefined;\n\t}\n\ttry {\n\t\tlet text = readFileSync(path, \"utf-8\").trim();\n\t\tif (text.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (text.length > DEVIN_PLAYBOOK_MAX_APPEND_CHARS) {\n\t\t\ttext = `${text.slice(0, DEVIN_PLAYBOOK_MAX_APPEND_CHARS)}\\n\\n[... devin.md truncated for system prompt; full file: ${path}]`;\n\t\t}\n\t\treturn text;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport function devinPlaybookAppendForProvider(provider: string | undefined): string | undefined {\n\tif (!isDevinProvider(provider)) {\n\t\treturn undefined;\n\t}\n\treturn loadDevinPlaybookAppend();\n}\n"]}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Devin SWE-2 harness: provider identity, auto-apply flag, per-turn skill
|
|
3
|
+
* grants, and the optional `~/.omk/agent/devin.md` operator overlay.
|
|
4
|
+
*
|
|
5
|
+
* The canonical operator contract is `docs/devin-harness.md`; the domain
|
|
6
|
+
* loadout is `devin-harness` in `domain-loadouts.ts`.
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { getAgentDir } from "../config.js";
|
|
11
|
+
import { getDomainProfile } from "./domain-loadouts.js";
|
|
12
|
+
import { selectHarnessSkills, } from "./harness-skills.js";
|
|
13
|
+
import { capabilityGateNames } from "./loadout-safety.js";
|
|
14
|
+
/** Built-in provider id for the Devin CLI subscription adapter. */
|
|
15
|
+
export const DEVIN_PROVIDER = "devin";
|
|
16
|
+
/** The only logical model the Devin adapter serves. */
|
|
17
|
+
export const DEVIN_SWE2_MODEL_ID = "swe-2";
|
|
18
|
+
/** Local context budget bundled with `devin/swe-2`; mirrors `DEVIN_LONG_CONTEXT_TOKENS` in omk-ai. */
|
|
19
|
+
export const DEVIN_SWE2_CONTEXT_WINDOW = 1_000_000;
|
|
20
|
+
/** Domain loadout id applied automatically when the Devin provider is active. */
|
|
21
|
+
export const DEVIN_HARNESS_DOMAIN_ID = "devin-harness";
|
|
22
|
+
const DEVIN_HARNESS_AUTO_APPLY_ENV = "OMK_DEVIN_HARNESS";
|
|
23
|
+
/** Optional host-specific operator overlay appended to the system prompt on Devin sessions. */
|
|
24
|
+
export const DEVIN_PLAYBOOK_FILENAME = "devin.md";
|
|
25
|
+
/** Cap live system-prompt append size to reduce threshold autocompaction churn. */
|
|
26
|
+
export const DEVIN_PLAYBOOK_MAX_APPEND_CHARS = 24_000;
|
|
27
|
+
/** SWE-2 efforts the adapter accepts; every other thinking level is rejected before credentials are sent. */
|
|
28
|
+
export const DEVIN_SWE2_EFFORTS = ["medium", "high", "max"];
|
|
29
|
+
const SKILLS_BY_INTENT = {
|
|
30
|
+
code: ["packages", "programming"],
|
|
31
|
+
debug: ["packages", "debugging", "programming"],
|
|
32
|
+
test: ["tdd-workflow", "programming"],
|
|
33
|
+
repo: ["understand-anything", "packages"],
|
|
34
|
+
};
|
|
35
|
+
const DEVIN_HARNESS_ALLOWED_SKILLS = new Set(capabilityGateNames(getDomainProfile(DEVIN_HARNESS_DOMAIN_ID).skills));
|
|
36
|
+
export function isDevinProvider(provider) {
|
|
37
|
+
return provider === DEVIN_PROVIDER;
|
|
38
|
+
}
|
|
39
|
+
export function isDevinSwe2Effort(level) {
|
|
40
|
+
return DEVIN_SWE2_EFFORTS.includes(level ?? "");
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Recommended effort for a task class. SWE-2 medium acts sooner on simple and
|
|
44
|
+
* intermediate work; high and max plan and verify more on complex work.
|
|
45
|
+
*/
|
|
46
|
+
export function recommendedDevinEffortForIntent(intent) {
|
|
47
|
+
switch (intent) {
|
|
48
|
+
case "code":
|
|
49
|
+
return "medium";
|
|
50
|
+
case "test":
|
|
51
|
+
return "high";
|
|
52
|
+
case "debug":
|
|
53
|
+
case "repo":
|
|
54
|
+
return "max";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export function recommendedDevinSkillTierForIntent(intent) {
|
|
58
|
+
return SKILLS_BY_INTENT[intent];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Smallest devin-harness skill grant from the live inventory. The domain
|
|
62
|
+
* profile owns the allowlist; explicit-only skills are excluded. `headroom`
|
|
63
|
+
* requires lexical or measured pressure, and the result never exceeds
|
|
64
|
+
* `MAX_SELECTED_SKILLS` names.
|
|
65
|
+
*/
|
|
66
|
+
export function selectDevinHarnessSkills(task, inventory, options = {}) {
|
|
67
|
+
return selectHarnessSkills(DEVIN_HARNESS_ALLOWED_SKILLS, task, inventory, options);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* When true (default), selecting the `devin` provider applies the `devin-harness`
|
|
71
|
+
* domain loadout (skills/MCP/hooks/tool gate). Set `OMK_DEVIN_HARNESS=0` to disable.
|
|
72
|
+
*/
|
|
73
|
+
export function devinHarnessAutoApplyEnabled(env = process.env) {
|
|
74
|
+
const raw = env[DEVIN_HARNESS_AUTO_APPLY_ENV]?.trim().toLowerCase();
|
|
75
|
+
if (raw === "0" || raw === "false" || raw === "off" || raw === "no") {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
/** Provider-harness spec consumed by `tryProviderHarnessDispatch()`. */
|
|
81
|
+
export const DEVIN_HARNESS_SPEC = {
|
|
82
|
+
domainId: DEVIN_HARNESS_DOMAIN_ID,
|
|
83
|
+
applies: (provider, env) => devinHarnessAutoApplyEnabled(env) && isDevinProvider(provider),
|
|
84
|
+
selectSkills: (task, inventory, options) => selectDevinHarnessSkills(task, inventory, { paths: options.paths }),
|
|
85
|
+
};
|
|
86
|
+
/** Read ~/.omk/agent/devin.md for appending to the system prompt on Devin sessions. */
|
|
87
|
+
export function loadDevinPlaybookAppend() {
|
|
88
|
+
const path = join(getAgentDir(), DEVIN_PLAYBOOK_FILENAME);
|
|
89
|
+
if (!existsSync(path)) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
let text = readFileSync(path, "utf-8").trim();
|
|
94
|
+
if (text.length === 0) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
if (text.length > DEVIN_PLAYBOOK_MAX_APPEND_CHARS) {
|
|
98
|
+
text = `${text.slice(0, DEVIN_PLAYBOOK_MAX_APPEND_CHARS)}\n\n[... devin.md truncated for system prompt; full file: ${path}]`;
|
|
99
|
+
}
|
|
100
|
+
return text;
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export function devinPlaybookAppendForProvider(provider) {
|
|
107
|
+
if (!isDevinProvider(provider)) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
return loadDevinPlaybookAppend();
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=devin-harness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devin-harness.js","sourceRoot":"","sources":["../../src/core/devin-harness.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAGN,mBAAmB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D,mEAAmE;AACnE,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC;AAEtC,uDAAuD;AACvD,MAAM,CAAC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UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,IAAI,CAAC;QACJ,IAAI,IAAI,GAAG,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;QAC9C,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,SAAS,CAAC;QAClB,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,GAAG,+BAA+B,EAAE,CAAC;YACnD,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,+BAA+B,CAAC,6DAA6D,IAAI,GAAG,CAAC;QAC9H,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AAAA,CACD;AAED,MAAM,UAAU,8BAA8B,CAAC,QAA4B,EAAsB;IAChG,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChC,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,OAAO,uBAAuB,EAAE,CAAC;AAAA,CACjC","sourcesContent":["/**\n * Devin SWE-2 harness: provider identity, auto-apply flag, per-turn skill\n * grants, and the optional `~/.omk/agent/devin.md` operator overlay.\n *\n * The canonical operator contract is `docs/devin-harness.md`; the domain\n * loadout is `devin-harness` in `domain-loadouts.ts`.\n */\n\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { getAgentDir } from \"../config.ts\";\nimport { getDomainProfile } from \"./domain-loadouts.ts\";\nimport {\n\ttype HarnessSkillCandidate,\n\ttype HarnessSkillSelectionOptions,\n\tselectHarnessSkills,\n} from \"./harness-skills.ts\";\nimport { capabilityGateNames } from \"./loadout-safety.ts\";\nimport type { ProviderHarnessSpec } from \"./provider-harness-dispatch.ts\";\n\n/** Built-in provider id for the Devin CLI subscription adapter. */\nexport const DEVIN_PROVIDER = \"devin\";\n\n/** The only logical model the Devin adapter serves. */\nexport const DEVIN_SWE2_MODEL_ID = \"swe-2\";\n\n/** Local context budget bundled with `devin/swe-2`; mirrors `DEVIN_LONG_CONTEXT_TOKENS` in omk-ai. */\nexport const DEVIN_SWE2_CONTEXT_WINDOW = 1_000_000;\n\n/** Domain loadout id applied automatically when the Devin provider is active. */\nexport const DEVIN_HARNESS_DOMAIN_ID = \"devin-harness\";\n\nconst DEVIN_HARNESS_AUTO_APPLY_ENV = \"OMK_DEVIN_HARNESS\";\n\n/** Optional host-specific operator overlay appended to the system prompt on Devin sessions. */\nexport const DEVIN_PLAYBOOK_FILENAME = \"devin.md\";\n\n/** Cap live system-prompt append size to reduce threshold autocompaction churn. */\nexport const DEVIN_PLAYBOOK_MAX_APPEND_CHARS = 24_000;\n\n/** SWE-2 efforts the adapter accepts; every other thinking level is rejected before credentials are sent. */\nexport const DEVIN_SWE2_EFFORTS = [\"medium\", \"high\", \"max\"] as const;\nexport type DevinSwe2Effort = (typeof DEVIN_SWE2_EFFORTS)[number];\n\nexport type DevinHarnessIntent = \"code\" | \"debug\" | \"test\" | \"repo\";\n\nconst SKILLS_BY_INTENT = {\n\tcode: [\"packages\", \"programming\"],\n\tdebug: [\"packages\", \"debugging\", \"programming\"],\n\ttest: [\"tdd-workflow\", \"programming\"],\n\trepo: [\"understand-anything\", \"packages\"],\n} as const satisfies Record<DevinHarnessIntent, readonly string[]>;\n\nexport type DevinHarnessSkillCandidate = HarnessSkillCandidate;\nexport type DevinHarnessSkillSelectionOptions = HarnessSkillSelectionOptions;\n\nconst DEVIN_HARNESS_ALLOWED_SKILLS: ReadonlySet<string> = new Set(\n\tcapabilityGateNames(getDomainProfile(DEVIN_HARNESS_DOMAIN_ID).skills),\n);\n\nexport function isDevinProvider(provider: string | undefined): boolean {\n\treturn provider === DEVIN_PROVIDER;\n}\n\nexport function isDevinSwe2Effort(level: string | undefined): level is DevinSwe2Effort {\n\treturn (DEVIN_SWE2_EFFORTS as readonly string[]).includes(level ?? \"\");\n}\n\n/**\n * Recommended effort for a task class. SWE-2 medium acts sooner on simple and\n * intermediate work; high and max plan and verify more on complex work.\n */\nexport function recommendedDevinEffortForIntent(intent: DevinHarnessIntent): DevinSwe2Effort {\n\tswitch (intent) {\n\t\tcase \"code\":\n\t\t\treturn \"medium\";\n\t\tcase \"test\":\n\t\t\treturn \"high\";\n\t\tcase \"debug\":\n\t\tcase \"repo\":\n\t\t\treturn \"max\";\n\t}\n}\n\nexport function recommendedDevinSkillTierForIntent(intent: DevinHarnessIntent): readonly string[] {\n\treturn SKILLS_BY_INTENT[intent];\n}\n\n/**\n * Smallest devin-harness skill grant from the live inventory. The domain\n * profile owns the allowlist; explicit-only skills are excluded. `headroom`\n * requires lexical or measured pressure, and the result never exceeds\n * `MAX_SELECTED_SKILLS` names.\n */\nexport function selectDevinHarnessSkills(\n\ttask: string,\n\tinventory: readonly DevinHarnessSkillCandidate[],\n\toptions: DevinHarnessSkillSelectionOptions = {},\n): readonly string[] {\n\treturn selectHarnessSkills(DEVIN_HARNESS_ALLOWED_SKILLS, task, inventory, options);\n}\n\n/**\n * When true (default), selecting the `devin` provider applies the `devin-harness`\n * domain loadout (skills/MCP/hooks/tool gate). Set `OMK_DEVIN_HARNESS=0` to disable.\n */\nexport function devinHarnessAutoApplyEnabled(\n\tenv: NodeJS.ProcessEnv | Readonly<Record<string, string | undefined>> = process.env,\n): boolean {\n\tconst raw = env[DEVIN_HARNESS_AUTO_APPLY_ENV]?.trim().toLowerCase();\n\tif (raw === \"0\" || raw === \"false\" || raw === \"off\" || raw === \"no\") {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\n/** Provider-harness spec consumed by `tryProviderHarnessDispatch()`. */\nexport const DEVIN_HARNESS_SPEC: ProviderHarnessSpec = {\n\tdomainId: DEVIN_HARNESS_DOMAIN_ID,\n\tapplies: (provider, env) => devinHarnessAutoApplyEnabled(env) && isDevinProvider(provider),\n\tselectSkills: (task, inventory, options) => selectDevinHarnessSkills(task, inventory, { paths: options.paths }),\n};\n\n/** Read ~/.omk/agent/devin.md for appending to the system prompt on Devin sessions. */\nexport function loadDevinPlaybookAppend(): string | undefined {\n\tconst path = join(getAgentDir(), DEVIN_PLAYBOOK_FILENAME);\n\tif (!existsSync(path)) {\n\t\treturn undefined;\n\t}\n\ttry {\n\t\tlet text = readFileSync(path, \"utf-8\").trim();\n\t\tif (text.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tif (text.length > DEVIN_PLAYBOOK_MAX_APPEND_CHARS) {\n\t\t\ttext = `${text.slice(0, DEVIN_PLAYBOOK_MAX_APPEND_CHARS)}\\n\\n[... devin.md truncated for system prompt; full file: ${path}]`;\n\t\t}\n\t\treturn text;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nexport function devinPlaybookAppendForProvider(provider: string | undefined): string | undefined {\n\tif (!isDevinProvider(provider)) {\n\t\treturn undefined;\n\t}\n\treturn loadDevinPlaybookAppend();\n}\n"]}
|
|
@@ -8,9 +8,12 @@
|
|
|
8
8
|
import type { ToolDefinition } from "./extensions/types.ts";
|
|
9
9
|
import type { LoadoutAccessPolicy } from "./loadout-access-policy.ts";
|
|
10
10
|
import { type CompositionTrace, type ScopeHints } from "./loadout-compose.ts";
|
|
11
|
-
import { type LoadoutRuntimeSession } from "./loadout-runtime.ts";
|
|
11
|
+
import { type LoadoutRuntimeSession, type LoadoutRuntimeState } from "./loadout-runtime.ts";
|
|
12
12
|
import type { LoadoutAuthority, LoadoutProfile, LoadoutRole } from "./loadouts.ts";
|
|
13
|
+
import type { ProviderHarnessRuntime } from "./provider-harness-dispatch.ts";
|
|
13
14
|
import type { ResourceLoader } from "./resource-loader.ts";
|
|
15
|
+
/** Real loadout runtime entry points for provider-harness dispatch (`tryProviderHarnessDispatch`). */
|
|
16
|
+
export declare const LOADOUT_HARNESS_RUNTIME: ProviderHarnessRuntime<LoadoutRuntimeSession, ResourceLoader, LoadoutRuntimeState>;
|
|
14
17
|
export interface DomainDispatchInput {
|
|
15
18
|
readonly role: LoadoutRole;
|
|
16
19
|
readonly initialPrompt: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domain-dispatch.d.ts","sourceRoot":"","sources":["../../src/core/domain-dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAkB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAEN,KAAK,gBAAgB,EAErB,KAAK,UAAU,EACf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAyB,KAAK,qBAAqB,
|
|
1
|
+
{"version":3,"file":"domain-dispatch.d.ts","sourceRoot":"","sources":["../../src/core/domain-dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAkB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAEN,KAAK,gBAAgB,EAErB,KAAK,UAAU,EACf,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAyB,KAAK,qBAAqB,EAAE,KAAK,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AACnH,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACnF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,sGAAsG;AACtG,eAAO,MAAM,uBAAuB,EAAE,sBAAsB,CAC3D,qBAAqB,EACrB,cAAc,EACd,mBAAmB,CAInB,CAAC;AAEF,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,O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,sBAAsB,CACrC,GAAG,GAAE,MAAM,CAAC,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAe,GACjF,OAAO,CAET;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,mBAAmB,GAAG,oBAAoB,CAyClF","sourcesContent":["/**\n * Opt-in domain dispatch orchestration.\n *\n * Callers can invoke it to route an initial prompt, compose a role/domain\n * loadout, apply it to the current runtime inventory, and receive an access\n * policy suitable for existing AgentSession enforcement.\n */\n\nimport { routeDomain } from \"./domain-router.ts\";\nimport type { RegisteredTool, ToolDefinition } from \"./extensions/types.ts\";\nimport type { LoadoutAccessPolicy } from \"./loadout-access-policy.ts\";\nimport {\n\ttype ComposeLoadoutOptions,\n\ttype CompositionTrace,\n\tcomposeLoadout,\n\ttype ScopeHints,\n} from \"./loadout-compose.ts\";\nimport { createLoadoutPolicyFromRuntimeState, validatePolicyIntegrity } from \"./loadout-policy-bridge.ts\";\nimport { applyLoadoutToRuntime, type LoadoutRuntimeSession, type LoadoutRuntimeState } from \"./loadout-runtime.ts\";\nimport type { LoadoutAuthority, LoadoutProfile, LoadoutRole } from \"./loadouts.ts\";\nimport type { ProviderHarnessRuntime } from \"./provider-harness-dispatch.ts\";\nimport type { ResourceLoader } from \"./resource-loader.ts\";\n\n/** Real loadout runtime entry points for provider-harness dispatch (`tryProviderHarnessDispatch`). */\nexport const LOADOUT_HARNESS_RUNTIME: ProviderHarnessRuntime<\n\tLoadoutRuntimeSession,\n\tResourceLoader,\n\tLoadoutRuntimeState\n> = {\n\tapplyLoadoutToRuntime,\n\tcreateLoadoutPolicyFromRuntimeState,\n};\n\nexport interface DomainDispatchInput {\n\treadonly role: LoadoutRole;\n\treadonly initialPrompt: string;\n\treadonly session: LoadoutRuntimeSession;\n\treadonly resourceLoader: ResourceLoader;\n\treadonly cwd: string;\n\treadonly agentDir: string;\n\treadonly grantAuthority?: LoadoutAuthority;\n\treadonly scopeHints?: ScopeHints;\n\treadonly env?: NodeJS.ProcessEnv | Readonly<Record<string, string | undefined>>;\n\treadonly roleProfileOverride?: LoadoutProfile;\n\treadonly blockedPaths?: readonly string[];\n}\n\nexport interface DomainDispatchResult {\n\treadonly loadoutAccessPolicy: LoadoutAccessPolicy | undefined;\n\treadonly domainUsed: string | undefined;\n\treadonly fallback: boolean;\n\treadonly warnings: readonly string[];\n\treadonly trace: CompositionTrace | undefined;\n}\n\nexport interface DomainDispatchRuntimeSessionOptions {\n\treadonly baseToolNames: readonly string[];\n\treadonly resourceLoader: ResourceLoader;\n\treadonly customTools?: readonly ToolDefinition[];\n\treadonly allowedToolNames?: readonly string[];\n\treadonly excludedToolNames?: readonly string[];\n}\n\nexport function createDomainDispatchRuntimeSession(\n\toptions: DomainDispatchRuntimeSessionOptions,\n): LoadoutRuntimeSession {\n\tconst allowedToolNameSet = options.allowedToolNames ? new Set(options.allowedToolNames) : undefined;\n\tconst excludedToolNameSet = options.excludedToolNames ? new Set(options.excludedToolNames) : undefined;\n\tconst isAllowedTool = (name: string): boolean =>\n\t\t(!allowedToolNameSet || allowedToolNameSet.has(name)) && !excludedToolNameSet?.has(name);\n\n\tconst base = new Map<string, ToolDefinition>();\n\tfor (const name of uniqueSorted(options.baseToolNames).filter(isAllowedTool)) {\n\t\tbase.set(name, { name } as unknown as ToolDefinition);\n\t}\n\n\tconst extensionToolsByName = new Map<string, RegisteredTool>();\n\tfor (const extension of options.resourceLoader.getExtensions().extensions) {\n\t\tfor (const tool of extension.tools.values()) {\n\t\t\tconst name = tool.definition.name;\n\t\t\tif (isAllowedTool(name) && !extensionToolsByName.has(name)) {\n\t\t\t\textensionToolsByName.set(name, tool);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\t_baseToolDefinitions: base,\n\t\t_extensionRunner: { getAllRegisteredTools: () => [...extensionToolsByName.values()] },\n\t\t_customTools: [...(options.customTools ?? [])].filter((tool) => isAllowedTool(tool.name)),\n\t};\n}\n\nexport function isDomainRoutingEnabled(\n\tenv: NodeJS.ProcessEnv | Readonly<Record<string, string | undefined>> = process.env,\n): boolean {\n\treturn env.OMK_DOMAIN_ROUTING === \"1\";\n}\n\nexport function tryDomainDispatch(input: DomainDispatchInput): DomainDispatchResult {\n\tif (!isDomainRoutingEnabled(input.env)) {\n\t\treturn noPolicy(false, [], undefined, undefined);\n\t}\n\n\tlet domainUsed: string | undefined;\n\tlet trace: CompositionTrace | undefined;\n\ttry {\n\t\tconst route = routeDomain({ task: input.initialPrompt });\n\t\tdomainUsed = route.primary.id;\n\t\tconst composeOptions: ComposeLoadoutOptions = {\n\t\t\tgrantAuthority: input.grantAuthority,\n\t\t\tscopeHints: input.scopeHints,\n\t\t\troleProfileOverride: input.roleProfileOverride,\n\t\t};\n\t\tconst profile = composeLoadout(input.role, route.primary, composeOptions);\n\t\ttrace = profile.composition;\n\t\tconst state = applyLoadoutToRuntime(input.session, input.resourceLoader, input.cwd, input.agentDir, {\n\t\t\tprofile,\n\t\t\trole: input.role,\n\t\t\tgrantAuthority: input.grantAuthority,\n\t\t\tassignedReadPaths: input.scopeHints?.readScope,\n\t\t\tassignedWritePaths: input.scopeHints?.writeScope,\n\t\t});\n\t\tconst policy = createPolicyOrThrow(state, profile.commands, input.cwd, input.blockedPaths);\n\t\tconst integrity = validatePolicyIntegrity(policy, state);\n\t\treturn {\n\t\t\tloadoutAccessPolicy: policy,\n\t\t\tdomainUsed,\n\t\t\tfallback: route.confidence === \"fallback\",\n\t\t\twarnings: uniqueSorted([\n\t\t\t\t...routeWarnings(route),\n\t\t\t\t...profile.composition.warnings,\n\t\t\t\t...state.warnings,\n\t\t\t\t...integrity.warnings,\n\t\t\t]),\n\t\t\ttrace,\n\t\t};\n\t} catch (error) {\n\t\treturn noPolicy(true, [errorMessage(error)], domainUsed, trace);\n\t}\n}\n\nfunction createPolicyOrThrow(\n\tstate: LoadoutRuntimeState,\n\tcommands: LoadoutProfile[\"commands\"],\n\tcwd: string,\n\tblockedPaths: readonly string[] | undefined,\n): LoadoutAccessPolicy {\n\treturn createLoadoutPolicyFromRuntimeState(state, {\n\t\tcwd,\n\t\tblockedPaths,\n\t\tcommands,\n\t});\n}\n\nfunction noPolicy(\n\tfallback: boolean,\n\twarnings: readonly string[],\n\tdomainUsed: string | undefined,\n\ttrace: CompositionTrace | undefined,\n): DomainDispatchResult {\n\treturn {\n\t\tloadoutAccessPolicy: undefined,\n\t\tdomainUsed,\n\t\tfallback,\n\t\twarnings: uniqueSorted(warnings),\n\t\ttrace,\n\t};\n}\n\nfunction routeWarnings(route: ReturnType<typeof routeDomain>): string[] {\n\tconst warnings: string[] = [];\n\tif (route.ambiguous) warnings.push(route.reason);\n\tif (route.confidence === \"fallback\") warnings.push(route.reason);\n\treturn warnings;\n}\n\nfunction errorMessage(error: unknown): string {\n\tif (error instanceof Error) return error.message;\n\treturn String(error);\n}\n\nfunction uniqueSorted(values: readonly string[]): string[] {\n\treturn [...new Set(values.map((value) => value.trim()).filter((value) => value !== \"\"))].sort((a, b) => {\n\t\tif (a < b) return -1;\n\t\tif (a > b) return 1;\n\t\treturn 0;\n\t});\n}\n"]}
|
|
@@ -9,6 +9,11 @@ import { routeDomain } from "./domain-router.js";
|
|
|
9
9
|
import { composeLoadout, } from "./loadout-compose.js";
|
|
10
10
|
import { createLoadoutPolicyFromRuntimeState, validatePolicyIntegrity } from "./loadout-policy-bridge.js";
|
|
11
11
|
import { applyLoadoutToRuntime } from "./loadout-runtime.js";
|
|
12
|
+
/** Real loadout runtime entry points for provider-harness dispatch (`tryProviderHarnessDispatch`). */
|
|
13
|
+
export const LOADOUT_HARNESS_RUNTIME = {
|
|
14
|
+
applyLoadoutToRuntime,
|
|
15
|
+
createLoadoutPolicyFromRuntimeState,
|
|
16
|
+
};
|
|
12
17
|
export function createDomainDispatchRuntimeSession(options) {
|
|
13
18
|
const allowedToolNameSet = options.allowedToolNames ? new Set(options.allowedToolNames) : undefined;
|
|
14
19
|
const excludedToolNameSet = options.excludedToolNames ? new Set(options.excludedToolNames) : undefined;
|