@caupulican/pi-adaptative 0.80.103 → 0.81.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 +120 -0
- package/dist/cli/session-picker.d.ts +1 -1
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +7 -1
- package/dist/cli.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +6 -6
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +1 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +152 -512
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +635 -4590
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/session-lane-record.d.ts +1 -1
- package/dist/core/autonomy/session-lane-record.d.ts.map +1 -1
- package/dist/core/autonomy/session-lane-record.js.map +1 -1
- package/dist/core/autonomy/status.d.ts +1 -0
- package/dist/core/autonomy/status.d.ts.map +1 -1
- package/dist/core/autonomy/status.js +1 -0
- package/dist/core/autonomy/status.js.map +1 -1
- package/dist/core/autonomy-telemetry.d.ts +80 -0
- package/dist/core/autonomy-telemetry.d.ts.map +1 -0
- package/dist/core/autonomy-telemetry.js +266 -0
- package/dist/core/autonomy-telemetry.js.map +1 -0
- package/dist/core/background-lane-controller.d.ts +186 -0
- package/dist/core/background-lane-controller.d.ts.map +1 -0
- package/dist/core/background-lane-controller.js +691 -0
- package/dist/core/background-lane-controller.js.map +1 -0
- package/dist/core/bash-execution-controller.d.ts +51 -0
- package/dist/core/bash-execution-controller.d.ts.map +1 -0
- package/dist/core/bash-execution-controller.js +96 -0
- package/dist/core/bash-execution-controller.js.map +1 -0
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +9 -2
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/compaction-support.d.ts +56 -0
- package/dist/core/compaction-support.d.ts.map +1 -0
- package/dist/core/compaction-support.js +99 -0
- package/dist/core/compaction-support.js.map +1 -0
- package/dist/core/context/artifact-retrieval.d.ts +1 -1
- package/dist/core/context/artifact-retrieval.d.ts.map +1 -1
- package/dist/core/context/artifact-retrieval.js +1 -1
- package/dist/core/context/artifact-retrieval.js.map +1 -1
- package/dist/core/context/context-composition.d.ts.map +1 -1
- package/dist/core/context/context-composition.js +1 -1
- package/dist/core/context/context-composition.js.map +1 -1
- package/dist/core/context/tool-output-packer.d.ts +1 -1
- package/dist/core/context/tool-output-packer.d.ts.map +1 -1
- package/dist/core/context/tool-output-packer.js +1 -1
- package/dist/core/context/tool-output-packer.js.map +1 -1
- package/dist/core/context-gc.d.ts.map +1 -1
- package/dist/core/context-gc.js +1 -1
- package/dist/core/context-gc.js.map +1 -1
- package/dist/core/context-pipeline.d.ts +223 -0
- package/dist/core/context-pipeline.d.ts.map +1 -0
- package/dist/core/context-pipeline.js +594 -0
- package/dist/core/context-pipeline.js.map +1 -0
- package/dist/core/cost/daily-usage.d.ts +1 -1
- package/dist/core/cost/daily-usage.d.ts.map +1 -1
- package/dist/core/cost/daily-usage.js +1 -1
- package/dist/core/cost/daily-usage.js.map +1 -1
- package/dist/core/cost/session-usage.d.ts +1 -1
- package/dist/core/cost/session-usage.d.ts.map +1 -1
- package/dist/core/cost/session-usage.js +1 -1
- package/dist/core/cost/session-usage.js.map +1 -1
- package/dist/core/delegation/session-worker-result.d.ts +1 -1
- package/dist/core/delegation/session-worker-result.d.ts.map +1 -1
- package/dist/core/delegation/session-worker-result.js.map +1 -1
- package/dist/core/exec.d.ts +2 -0
- package/dist/core/exec.d.ts.map +1 -1
- package/dist/core/exec.js +15 -9
- package/dist/core/exec.js.map +1 -1
- package/dist/core/export-html/index.d.ts +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +2 -2
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/extensions/builtin.d.ts.map +1 -1
- package/dist/core/extensions/builtin.js +2 -2
- package/dist/core/extensions/builtin.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +2 -4
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/goal-loop-controller.d.ts +24 -0
- package/dist/core/goal-loop-controller.d.ts.map +1 -0
- package/dist/core/goal-loop-controller.js +83 -0
- package/dist/core/goal-loop-controller.js.map +1 -0
- package/dist/core/goals/goal-runtime-snapshot.d.ts +1 -1
- package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
- package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
- package/dist/core/goals/session-goal-state.d.ts +1 -1
- package/dist/core/goals/session-goal-state.d.ts.map +1 -1
- package/dist/core/goals/session-goal-state.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/learning/learning-audit.d.ts +1 -1
- package/dist/core/learning/learning-audit.d.ts.map +1 -1
- package/dist/core/learning/learning-audit.js.map +1 -1
- package/dist/core/learning/session-learning-decision.d.ts +1 -1
- package/dist/core/learning/session-learning-decision.d.ts.map +1 -1
- package/dist/core/learning/session-learning-decision.js.map +1 -1
- package/dist/core/local-runtime-controller.d.ts +99 -0
- package/dist/core/local-runtime-controller.d.ts.map +1 -0
- package/dist/core/local-runtime-controller.js +214 -0
- package/dist/core/local-runtime-controller.js.map +1 -0
- package/dist/core/memory/providers/transcript-recall.d.ts.map +1 -1
- package/dist/core/memory/providers/transcript-recall.js +1 -1
- package/dist/core/memory/providers/transcript-recall.js.map +1 -1
- package/dist/core/memory-controller.d.ts +139 -0
- package/dist/core/memory-controller.d.ts.map +1 -0
- package/dist/core/memory-controller.js +323 -0
- package/dist/core/memory-controller.js.map +1 -0
- package/dist/core/model-router/status.d.ts +1 -1
- package/dist/core/model-router/status.d.ts.map +1 -1
- package/dist/core/model-router/status.js.map +1 -1
- package/dist/core/model-router-controller.d.ts +140 -0
- package/dist/core/model-router-controller.d.ts.map +1 -0
- package/dist/core/model-router-controller.js +623 -0
- package/dist/core/model-router-controller.js.map +1 -0
- package/dist/core/model-selection-controller.d.ts +95 -0
- package/dist/core/model-selection-controller.d.ts.map +1 -0
- package/dist/core/model-selection-controller.js +252 -0
- package/dist/core/model-selection-controller.js.map +1 -0
- package/dist/core/models/model-ref.d.ts +13 -0
- package/dist/core/models/model-ref.d.ts.map +1 -1
- package/dist/core/models/model-ref.js +22 -0
- package/dist/core/models/model-ref.js.map +1 -1
- package/dist/core/profile-filter-controller.d.ts +77 -0
- package/dist/core/profile-filter-controller.d.ts.map +1 -0
- package/dist/core/profile-filter-controller.js +159 -0
- package/dist/core/profile-filter-controller.js.map +1 -0
- package/dist/core/reflection-controller.d.ts +111 -0
- package/dist/core/reflection-controller.d.ts.map +1 -0
- package/dist/core/reflection-controller.js +412 -0
- package/dist/core/reflection-controller.js.map +1 -0
- package/dist/core/research/model-fitness.d.ts +12 -0
- package/dist/core/research/model-fitness.d.ts.map +1 -1
- package/dist/core/research/model-fitness.js +21 -0
- package/dist/core/research/model-fitness.js.map +1 -1
- package/dist/core/research/session-evidence-bundle.d.ts +1 -1
- package/dist/core/research/session-evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/session-evidence-bundle.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +222 -0
- package/dist/core/runtime-builder.d.ts.map +1 -0
- package/dist/core/runtime-builder.js +640 -0
- package/dist/core/runtime-builder.js.map +1 -0
- package/dist/core/sdk.d.ts +2 -2
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +3 -4
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-analytics.d.ts +96 -0
- package/dist/core/session-analytics.d.ts.map +1 -0
- package/dist/core/session-analytics.js +331 -0
- package/dist/core/session-analytics.js.map +1 -0
- package/dist/core/session-manager-factory.d.ts +18 -0
- package/dist/core/session-manager-factory.d.ts.map +1 -0
- package/dist/core/session-manager-factory.js +32 -0
- package/dist/core/session-manager-factory.js.map +1 -0
- package/dist/core/session-tree-navigator.d.ts +68 -0
- package/dist/core/session-tree-navigator.d.ts.map +1 -0
- package/dist/core/session-tree-navigator.js +217 -0
- package/dist/core/session-tree-navigator.js.map +1 -0
- package/dist/core/system-prompt-builder.d.ts +63 -0
- package/dist/core/system-prompt-builder.d.ts.map +1 -0
- package/dist/core/system-prompt-builder.js +181 -0
- package/dist/core/system-prompt-builder.js.map +1 -0
- package/dist/core/tool-gate-controller.d.ts +36 -0
- package/dist/core/tool-gate-controller.d.ts.map +1 -0
- package/dist/core/tool-gate-controller.js +94 -0
- package/dist/core/tool-gate-controller.js.map +1 -0
- package/dist/core/tools/artifact-retrieve.d.ts.map +1 -1
- package/dist/core/tools/artifact-retrieve.js +1 -1
- package/dist/core/tools/artifact-retrieve.js.map +1 -1
- package/dist/core/tools/bash.d.ts +4 -2
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +49 -7
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts +6 -0
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js +61 -1
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/find.d.ts +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +1 -1
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +1 -1
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +1 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +1 -1
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +1 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +1 -1
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +1 -1
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/read.d.ts +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +1 -1
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +13 -12
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/auth-dialogs-controller.d.ts +59 -0
- package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -0
- package/dist/modes/interactive/auth-dialogs-controller.js +398 -0
- package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -0
- package/dist/modes/interactive/auto-learn-controller.d.ts +168 -0
- package/dist/modes/interactive/auto-learn-controller.d.ts.map +1 -0
- package/dist/modes/interactive/auto-learn-controller.js +1239 -0
- package/dist/modes/interactive/auto-learn-controller.js.map +1 -0
- package/dist/modes/interactive/autocomplete-provider.d.ts +26 -0
- package/dist/modes/interactive/autocomplete-provider.d.ts.map +1 -0
- package/dist/modes/interactive/autocomplete-provider.js +103 -0
- package/dist/modes/interactive/autocomplete-provider.js.map +1 -0
- package/dist/modes/interactive/autonomy-commands.d.ts +38 -0
- package/dist/modes/interactive/autonomy-commands.d.ts.map +1 -0
- package/dist/modes/interactive/autonomy-commands.js +142 -0
- package/dist/modes/interactive/autonomy-commands.js.map +1 -0
- package/dist/modes/interactive/clipboard-input.d.ts +37 -0
- package/dist/modes/interactive/clipboard-input.d.ts.map +1 -0
- package/dist/modes/interactive/clipboard-input.js +59 -0
- package/dist/modes/interactive/clipboard-input.js.map +1 -0
- package/dist/modes/interactive/compaction-queue.d.ts +30 -0
- package/dist/modes/interactive/compaction-queue.d.ts.map +1 -0
- package/dist/modes/interactive/compaction-queue.js +91 -0
- package/dist/modes/interactive/compaction-queue.js.map +1 -0
- package/dist/modes/interactive/components/bash-execution.d.ts +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +1 -1
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts +1 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts +1 -1
- package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.d.ts +1 -1
- package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +2 -2
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/config-backup.d.ts +27 -0
- package/dist/modes/interactive/config-backup.d.ts.map +1 -0
- package/dist/modes/interactive/config-backup.js +146 -0
- package/dist/modes/interactive/config-backup.js.map +1 -0
- package/dist/modes/interactive/editor-overlay-host.d.ts +48 -0
- package/dist/modes/interactive/editor-overlay-host.d.ts.map +1 -0
- package/dist/modes/interactive/editor-overlay-host.js +43 -0
- package/dist/modes/interactive/editor-overlay-host.js.map +1 -0
- package/dist/modes/interactive/extension-ui-host.d.ts +165 -0
- package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -0
- package/dist/modes/interactive/extension-ui-host.js +610 -0
- package/dist/modes/interactive/extension-ui-host.js.map +1 -0
- package/dist/modes/interactive/external-editor.d.ts +18 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -0
- package/dist/modes/interactive/external-editor.js +107 -0
- package/dist/modes/interactive/external-editor.js.map +1 -0
- package/dist/modes/interactive/history-reload-math.d.ts +24 -0
- package/dist/modes/interactive/history-reload-math.d.ts.map +1 -0
- package/dist/modes/interactive/history-reload-math.js +129 -0
- package/dist/modes/interactive/history-reload-math.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +22 -238
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +714 -5910
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/key-handlers.d.ts +46 -0
- package/dist/modes/interactive/key-handlers.d.ts.map +1 -0
- package/dist/modes/interactive/key-handlers.js +80 -0
- package/dist/modes/interactive/key-handlers.js.map +1 -0
- package/dist/modes/interactive/local-model-commands.d.ts +68 -0
- package/dist/modes/interactive/local-model-commands.d.ts.map +1 -0
- package/dist/modes/interactive/local-model-commands.js +288 -0
- package/dist/modes/interactive/local-model-commands.js.map +1 -0
- package/dist/modes/interactive/profile-menu-controller.d.ts +77 -0
- package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -0
- package/dist/modes/interactive/profile-menu-controller.js +917 -0
- package/dist/modes/interactive/profile-menu-controller.js.map +1 -0
- package/dist/modes/interactive/report-commands.d.ts +46 -0
- package/dist/modes/interactive/report-commands.d.ts.map +1 -0
- package/dist/modes/interactive/report-commands.js +255 -0
- package/dist/modes/interactive/report-commands.js.map +1 -0
- package/dist/modes/interactive/resource-display.d.ts +73 -0
- package/dist/modes/interactive/resource-display.d.ts.map +1 -0
- package/dist/modes/interactive/resource-display.js +278 -0
- package/dist/modes/interactive/resource-display.js.map +1 -0
- package/dist/modes/interactive/resource-shell-commands.d.ts +64 -0
- package/dist/modes/interactive/resource-shell-commands.d.ts.map +1 -0
- package/dist/modes/interactive/resource-shell-commands.js +202 -0
- package/dist/modes/interactive/resource-shell-commands.js.map +1 -0
- package/dist/modes/interactive/session-flow-commands.d.ts +139 -0
- package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -0
- package/dist/modes/interactive/session-flow-commands.js +458 -0
- package/dist/modes/interactive/session-flow-commands.js.map +1 -0
- package/dist/modes/interactive/session-io-commands.d.ts +73 -0
- package/dist/modes/interactive/session-io-commands.d.ts.map +1 -0
- package/dist/modes/interactive/session-io-commands.js +202 -0
- package/dist/modes/interactive/session-io-commands.js.map +1 -0
- package/dist/modes/interactive/settings-selector-flow.d.ts +42 -0
- package/dist/modes/interactive/settings-selector-flow.d.ts.map +1 -0
- package/dist/modes/interactive/settings-selector-flow.js +287 -0
- package/dist/modes/interactive/settings-selector-flow.js.map +1 -0
- package/dist/modes/interactive/signal-lifecycle.d.ts +55 -0
- package/dist/modes/interactive/signal-lifecycle.d.ts.map +1 -0
- package/dist/modes/interactive/signal-lifecycle.js +177 -0
- package/dist/modes/interactive/signal-lifecycle.js.map +1 -0
- package/dist/modes/interactive/startup-checks.d.ts +38 -0
- package/dist/modes/interactive/startup-checks.d.ts.map +1 -0
- package/dist/modes/interactive/startup-checks.js +189 -0
- package/dist/modes/interactive/startup-checks.js.map +1 -0
- package/dist/modes/rpc/rpc-client.d.ts +1 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +1 -1
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/utils/paths.d.ts +2 -14
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +5 -30
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/process-memory.d.ts +8 -0
- package/dist/utils/process-memory.d.ts.map +1 -0
- package/dist/utils/process-memory.js +11 -0
- package/dist/utils/process-memory.js.map +1 -0
- package/dist/utils/shell.d.ts +0 -9
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +0 -37
- package/dist/utils/shell.js.map +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/11-sessions.ts +8 -8
- package/examples/sdk/13-session-runtime.ts +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
- package/dist/core/compaction/branch-summarization.d.ts +0 -88
- package/dist/core/compaction/branch-summarization.d.ts.map +0 -1
- package/dist/core/compaction/branch-summarization.js +0 -243
- package/dist/core/compaction/branch-summarization.js.map +0 -1
- package/dist/core/compaction/compaction.d.ts +0 -143
- package/dist/core/compaction/compaction.d.ts.map +0 -1
- package/dist/core/compaction/compaction.js +0 -659
- package/dist/core/compaction/compaction.js.map +0 -1
- package/dist/core/compaction/index.d.ts +0 -7
- package/dist/core/compaction/index.d.ts.map +0 -1
- package/dist/core/compaction/index.js +0 -7
- package/dist/core/compaction/index.js.map +0 -1
- package/dist/core/compaction/utils.d.ts +0 -38
- package/dist/core/compaction/utils.d.ts.map +0 -1
- package/dist/core/compaction/utils.js +0 -153
- package/dist/core/compaction/utils.js.map +0 -1
- package/dist/core/message-retention.d.ts +0 -26
- package/dist/core/message-retention.d.ts.map +0 -1
- package/dist/core/message-retention.js +0 -95
- package/dist/core/message-retention.js.map +0 -1
- package/dist/core/messages.d.ts +0 -77
- package/dist/core/messages.d.ts.map +0 -1
- package/dist/core/messages.js +0 -123
- package/dist/core/messages.js.map +0 -1
- package/dist/core/session-manager.d.ts +0 -337
- package/dist/core/session-manager.d.ts.map +0 -1
- package/dist/core/session-manager.js +0 -1328
- package/dist/core/session-manager.js.map +0 -1
- package/dist/core/tools/truncate.d.ts +0 -70
- package/dist/core/tools/truncate.d.ts.map +0 -1
- package/dist/core/tools/truncate.js +0 -215
- package/dist/core/tools/truncate.js.map +0 -1
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Background-lane controller: goal auto-continue, the research lane, scout-worker delegation, and
|
|
3
|
+
* the model-fitness probe.
|
|
4
|
+
*
|
|
5
|
+
* Extracted verbatim from agent-session.ts (god-file decomposition). Owns the lane timers, the
|
|
6
|
+
* single-flight guards, the last research-lane skip reason, the live {@link LaneTracker}, and the
|
|
7
|
+
* session-lifetime abort controllers for in-flight research/worker passes. Everything else it needs
|
|
8
|
+
* — the session manager, settings, model registry, live model, capability envelope, the goal
|
|
9
|
+
* continuation LOOP, the isolated-completion primitive, spawned-usage accounting, and the telemetry
|
|
10
|
+
* sink — is reached through narrow deps accessors rather than the whole AgentSession.
|
|
11
|
+
*
|
|
12
|
+
* Drive-loop boundary (deliberate): the idle triggers ({@link scheduleGoalAutoContinueFromIdle},
|
|
13
|
+
* {@link scheduleResearchLaneFromIdle}) are invoked from the session's prompt tail as one-line
|
|
14
|
+
* delegations; goal auto-continue itself only ever asks the session to `continueGoalLoop`, so this
|
|
15
|
+
* controller never touches `prompt()`, the last-assistant-message, retry, or streaming state.
|
|
16
|
+
*/
|
|
17
|
+
import { LaneTracker } from "./autonomy/lane-tracker.js";
|
|
18
|
+
import { appendLaneRecordSnapshot, getLaneRecordSnapshots } from "./autonomy/session-lane-record.js";
|
|
19
|
+
import { composeSubagentSystemPrompt } from "./autonomy/subagent-prompt.js";
|
|
20
|
+
import { AUTONOMY_TELEMETRY_EVENT_TYPES } from "./autonomy/telemetry-events.js";
|
|
21
|
+
import { applyWorkerActions } from "./delegation/worker-actions.js";
|
|
22
|
+
import { runWorker } from "./delegation/worker-runner.js";
|
|
23
|
+
import { deriveModelCapabilityProfile, scaleContinuationBudgetsForCapability, } from "./model-capability.js";
|
|
24
|
+
import { resolveCliModel } from "./model-resolver.js";
|
|
25
|
+
import { FitnessStore } from "./models/fitness-store.js";
|
|
26
|
+
import { runModelFitnessProbe } from "./research/model-fitness.js";
|
|
27
|
+
import { runResearch } from "./research/research-runner.js";
|
|
28
|
+
export class BackgroundLaneController {
|
|
29
|
+
/** Pending idle timer that starts bounded goal continuation after the session becomes idle. */
|
|
30
|
+
_goalAutoContinueTimer;
|
|
31
|
+
/** Guards bounded idle autosteer so continuation prompts do not recursively trigger themselves. */
|
|
32
|
+
_isGoalAutoContinuing = false;
|
|
33
|
+
/** Pending idle timer that starts an autonomous research pass after the session becomes idle. */
|
|
34
|
+
_researchLaneTimer;
|
|
35
|
+
/** Single-flight guard: at most one research pass runs at a time per session. */
|
|
36
|
+
_isResearchLaneRunning = false;
|
|
37
|
+
/** Why the last idle research-lane evaluation skipped, for /autonomy diagnostics. */
|
|
38
|
+
_lastResearchLaneSkipReason;
|
|
39
|
+
/** Live lane registry — the real source for AutonomyStatusSnapshot.activeLaneCount. */
|
|
40
|
+
_laneTracker = new LaneTracker();
|
|
41
|
+
/** Session-lifetime abort for in-flight research passes (same pattern as _reflectionAbort). */
|
|
42
|
+
_researchLaneAbort = new AbortController();
|
|
43
|
+
/** Session-lifetime abort for in-flight delegated workers. */
|
|
44
|
+
_workerDelegationAbort = new AbortController();
|
|
45
|
+
deps;
|
|
46
|
+
constructor(deps) {
|
|
47
|
+
this.deps = deps;
|
|
48
|
+
}
|
|
49
|
+
/** Live lane records tracked by this process (running and terminal). */
|
|
50
|
+
getLaneRecords() {
|
|
51
|
+
return this._laneTracker.getRecords();
|
|
52
|
+
}
|
|
53
|
+
/** Live count of active lanes — the real source for AutonomyStatusSnapshot.activeLaneCount. */
|
|
54
|
+
getActiveLaneCount() {
|
|
55
|
+
return this._laneTracker.getActiveCount();
|
|
56
|
+
}
|
|
57
|
+
/** Why the last idle research-lane evaluation skipped, for /autonomy diagnostics. */
|
|
58
|
+
getLastResearchLaneSkipReason() {
|
|
59
|
+
return this._lastResearchLaneSkipReason;
|
|
60
|
+
}
|
|
61
|
+
/** Abort any in-flight research pass or delegated worker (called on session dispose). */
|
|
62
|
+
abortInFlightLanes() {
|
|
63
|
+
this._researchLaneAbort.abort();
|
|
64
|
+
this._workerDelegationAbort.abort();
|
|
65
|
+
}
|
|
66
|
+
clearGoalAutoContinueTimer() {
|
|
67
|
+
if (this._goalAutoContinueTimer !== undefined) {
|
|
68
|
+
clearTimeout(this._goalAutoContinueTimer);
|
|
69
|
+
this._goalAutoContinueTimer = undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
scheduleGoalAutoContinueFromIdle(options) {
|
|
73
|
+
if (options?.autoContinueGoal === false || this._isGoalAutoContinuing || this.deps.isDisposed())
|
|
74
|
+
return;
|
|
75
|
+
// Small-window models cannot afford multi-thousand-token continuation prompts per idle turn.
|
|
76
|
+
if (!this.deps.getModelCapabilityProfile().backgroundLanesEnabled)
|
|
77
|
+
return;
|
|
78
|
+
const { maxStallTurns, goalAutoContinue, goalAutoContinueDelayMs } = this.deps
|
|
79
|
+
.getSettingsManager()
|
|
80
|
+
.getAutonomySettings();
|
|
81
|
+
if (!goalAutoContinue)
|
|
82
|
+
return;
|
|
83
|
+
const snapshot = this.deps.getGoalRuntimeSnapshot({ maxStallTurns });
|
|
84
|
+
if (snapshot.continuation.action !== "continue")
|
|
85
|
+
return;
|
|
86
|
+
this.clearGoalAutoContinueTimer();
|
|
87
|
+
this._goalAutoContinueTimer = setTimeout(() => {
|
|
88
|
+
this._goalAutoContinueTimer = undefined;
|
|
89
|
+
void this._runScheduledGoalAutoContinue();
|
|
90
|
+
}, goalAutoContinueDelayMs);
|
|
91
|
+
const timer = this._goalAutoContinueTimer;
|
|
92
|
+
if (typeof timer === "object" && timer && "unref" in timer) {
|
|
93
|
+
const { unref } = timer;
|
|
94
|
+
unref?.call(timer);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async _runScheduledGoalAutoContinue() {
|
|
98
|
+
if (this._isGoalAutoContinuing || this.deps.isDisposed())
|
|
99
|
+
return;
|
|
100
|
+
const { maxStallTurns, goalContinueTurns, goalContinueMaxWallClockMinutes, goalAutoContinue } = this.deps
|
|
101
|
+
.getSettingsManager()
|
|
102
|
+
.getAutonomySettings();
|
|
103
|
+
if (!goalAutoContinue)
|
|
104
|
+
return;
|
|
105
|
+
const snapshot = this.deps.getGoalRuntimeSnapshot({ maxStallTurns });
|
|
106
|
+
if (snapshot.continuation.action !== "continue")
|
|
107
|
+
return;
|
|
108
|
+
// Lean-window models (16-32k) keep autosteer but at a reduced budget; full passes through.
|
|
109
|
+
const scaled = scaleContinuationBudgetsForCapability(this.deps.getModelCapabilityProfile(), {
|
|
110
|
+
maxTurns: goalContinueTurns,
|
|
111
|
+
maxWallClockMinutes: goalContinueMaxWallClockMinutes,
|
|
112
|
+
});
|
|
113
|
+
this._isGoalAutoContinuing = true;
|
|
114
|
+
try {
|
|
115
|
+
await this.deps.continueGoalLoop({
|
|
116
|
+
maxTurns: scaled.maxTurns,
|
|
117
|
+
maxStallTurns,
|
|
118
|
+
maxWallClockMinutes: scaled.maxWallClockMinutes,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
123
|
+
this.deps.emit({ type: "warning", message: `Goal auto-continuation failed: ${message}` });
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
this._isGoalAutoContinuing = false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
clearResearchLaneTimer() {
|
|
130
|
+
if (this._researchLaneTimer !== undefined) {
|
|
131
|
+
clearTimeout(this._researchLaneTimer);
|
|
132
|
+
this._researchLaneTimer = undefined;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Derive the research demand from durable goal state: an active goal with open requirements,
|
|
137
|
+
* deduplicated against the latest persisted bundle so the same requirement set is never
|
|
138
|
+
* researched twice (the query is deterministic, so dedupe survives session reload).
|
|
139
|
+
*/
|
|
140
|
+
_buildResearchLaneDemand() {
|
|
141
|
+
const goal = this.deps.getGoalStateSnapshot();
|
|
142
|
+
if (!goal || goal.status !== "active") {
|
|
143
|
+
this._lastResearchLaneSkipReason = "no_active_goal";
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
const open = goal.requirements.filter((requirement) => requirement.status === "open");
|
|
147
|
+
if (open.length === 0) {
|
|
148
|
+
this._lastResearchLaneSkipReason = "no_open_requirements";
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
const query = `goal:${goal.goalId} requirements:${open
|
|
152
|
+
.map((requirement) => requirement.id)
|
|
153
|
+
.sort()
|
|
154
|
+
.join(",")}`;
|
|
155
|
+
if (this.deps.getEvidenceBundleSnapshot()?.query === query) {
|
|
156
|
+
this._lastResearchLaneSkipReason = "recent_evidence_sufficient";
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
const context = [
|
|
160
|
+
`Goal: ${goal.userGoal}`,
|
|
161
|
+
"Open requirements:",
|
|
162
|
+
...open.slice(0, 20).map((requirement) => `- ${requirement.text}`),
|
|
163
|
+
].join("\n");
|
|
164
|
+
return { query, context, goalId: goal.goalId };
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Idle trigger for the autonomous research lane (mirrors {@link scheduleGoalAutoContinueFromIdle}).
|
|
168
|
+
* All skips are recorded in `_lastResearchLaneSkipReason` and surfaced via diagnostics — the lane
|
|
169
|
+
* informs, it never prompts or blocks the foreground.
|
|
170
|
+
*/
|
|
171
|
+
scheduleResearchLaneFromIdle() {
|
|
172
|
+
if (this._isResearchLaneRunning || this.deps.isDisposed() || this.deps.isChildSession())
|
|
173
|
+
return;
|
|
174
|
+
if (!this.deps.getModelCapabilityProfile().backgroundLanesEnabled) {
|
|
175
|
+
this._lastResearchLaneSkipReason = "model_context_too_small";
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const research = this.deps.getSettingsManager().getResearchLaneSettings();
|
|
179
|
+
if (!research.enabled) {
|
|
180
|
+
this._lastResearchLaneSkipReason = "research_lane_disabled";
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const { mode } = this.deps.getSettingsManager().getAutonomySettings();
|
|
184
|
+
if (mode === "off") {
|
|
185
|
+
this._lastResearchLaneSkipReason = "autonomy_mode_off";
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const priorRuns = getLaneRecordSnapshots(this.deps.getSessionManager().getEntries()).filter((record) => record.type === "research").length;
|
|
189
|
+
if (priorRuns >= research.maxRunsPerSession) {
|
|
190
|
+
this._lastResearchLaneSkipReason = "max_runs_reached";
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (!this._buildResearchLaneDemand())
|
|
194
|
+
return;
|
|
195
|
+
this.clearResearchLaneTimer();
|
|
196
|
+
this._researchLaneTimer = setTimeout(() => {
|
|
197
|
+
this._researchLaneTimer = undefined;
|
|
198
|
+
void this._runScheduledResearchLane();
|
|
199
|
+
}, research.idleDelayMs);
|
|
200
|
+
const timer = this._researchLaneTimer;
|
|
201
|
+
if (typeof timer === "object" && timer && "unref" in timer) {
|
|
202
|
+
const { unref } = timer;
|
|
203
|
+
unref?.call(timer);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
async _runScheduledResearchLane() {
|
|
207
|
+
if (this._isResearchLaneRunning || this.deps.isDisposed())
|
|
208
|
+
return;
|
|
209
|
+
const research = this.deps.getSettingsManager().getResearchLaneSettings();
|
|
210
|
+
const { mode } = this.deps.getSettingsManager().getAutonomySettings();
|
|
211
|
+
if (!research.enabled || mode === "off")
|
|
212
|
+
return;
|
|
213
|
+
try {
|
|
214
|
+
await this.runResearchLaneOnce();
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
218
|
+
this.deps.emit({ type: "warning", message: `Research lane failed: ${message}` });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/** Capability profile for a specific lane model (lane budgets scale to the lane model's window). */
|
|
222
|
+
_laneCapabilityProfile(model) {
|
|
223
|
+
return deriveModelCapabilityProfile({
|
|
224
|
+
contextWindow: model.contextWindow,
|
|
225
|
+
mode: this.deps.getSettingsManager().getModelCapabilitySettings().mode,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Resolve the model for a background lane. Lanes are shipped BY this session, so they inherit
|
|
230
|
+
* the session's own model unless a lane-specific model is explicitly configured — a single-model
|
|
231
|
+
* setup (e.g. one local open model) runs its lanes on that same model. An explicitly configured
|
|
232
|
+
* pattern that cannot resolve/authenticate is a visible skip, not a silent fallback.
|
|
233
|
+
*/
|
|
234
|
+
resolveLaneModel(configuredPattern) {
|
|
235
|
+
if (configuredPattern) {
|
|
236
|
+
const resolved = resolveCliModel({ cliModel: configuredPattern, modelRegistry: this.deps.getModelRegistry() });
|
|
237
|
+
if (resolved.model && this.deps.getModelRegistry().hasConfiguredAuth(resolved.model)) {
|
|
238
|
+
return resolved.model;
|
|
239
|
+
}
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
return this.deps.getModel() ?? undefined;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Resolve what a lane ships with. Precedence: explicit lane model setting, then the lane
|
|
246
|
+
* profile's model (a shipped profile with a model MUST be obeyed — unresolvable is a visible
|
|
247
|
+
* skip, never a fallback), then generic inheritance of the session model.
|
|
248
|
+
*/
|
|
249
|
+
_resolveLaneShipment(laneSettings, missingModelReason) {
|
|
250
|
+
let laneProfile;
|
|
251
|
+
if (laneSettings.profile) {
|
|
252
|
+
laneProfile = this.deps.getSettingsManager().getProfileRegistry().getProfile(laneSettings.profile);
|
|
253
|
+
if (!laneProfile) {
|
|
254
|
+
return { ok: false, skipReason: "lane_profile_not_found" };
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
let model;
|
|
258
|
+
if (laneSettings.model) {
|
|
259
|
+
model = this.resolveLaneModel(laneSettings.model);
|
|
260
|
+
if (!model)
|
|
261
|
+
return { ok: false, skipReason: missingModelReason };
|
|
262
|
+
}
|
|
263
|
+
else if (laneProfile?.model) {
|
|
264
|
+
model = this.resolveLaneModel(laneProfile.model);
|
|
265
|
+
if (!model)
|
|
266
|
+
return { ok: false, skipReason: "no_lane_profile_model" };
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
model = this.deps.getModel() ?? undefined;
|
|
270
|
+
if (!model)
|
|
271
|
+
return { ok: false, skipReason: missingModelReason };
|
|
272
|
+
}
|
|
273
|
+
return { ok: true, model, laneProfile };
|
|
274
|
+
}
|
|
275
|
+
/** UAC tool grants from a shipped lane profile, recorded on the lane envelope. */
|
|
276
|
+
_laneProfileToolGrants(laneProfile) {
|
|
277
|
+
const toolsFilter = laneProfile?.resources.tools;
|
|
278
|
+
return {
|
|
279
|
+
...(toolsFilter?.allow && toolsFilter.allow.length > 0 ? { allowedTools: [...toolsFilter.allow] } : {}),
|
|
280
|
+
...(toolsFilter?.block && toolsFilter.block.length > 0 ? { deniedTools: [...toolsFilter.block] } : {}),
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
/** Stripped research envelope — never the foreground/architect envelope. */
|
|
284
|
+
_buildResearchLaneEnvelope(maxUsd, laneProfile) {
|
|
285
|
+
return {
|
|
286
|
+
id: `research-${this.deps.getSessionId()}-${Date.now()}`,
|
|
287
|
+
profileId: laneProfile?.name,
|
|
288
|
+
capabilities: ["research", "read_files", "memory_read"],
|
|
289
|
+
...this._laneProfileToolGrants(laneProfile),
|
|
290
|
+
maxEstimatedUsd: Math.min(maxUsd, this.deps.getCapabilityEnvelope()?.maxEstimatedUsd ?? Number.POSITIVE_INFINITY),
|
|
291
|
+
createdAt: new Date().toISOString(),
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Run one bounded, read-only research pass and persist its results: evidence bundle snapshot,
|
|
296
|
+
* terminal lane record, and spawned-usage cost report (single-hop invariant, idempotent on the
|
|
297
|
+
* lane's reportId). Explicit calls (e.g. `/autonomy research`) express user intent and bypass the
|
|
298
|
+
* enabled/mode/dedupe gates the idle scheduler enforces; budget and capability gates always apply.
|
|
299
|
+
*/
|
|
300
|
+
async runResearchLaneOnce(request) {
|
|
301
|
+
if (this._isResearchLaneRunning) {
|
|
302
|
+
return { started: false, skipReason: "research_lane_already_running" };
|
|
303
|
+
}
|
|
304
|
+
if (this.deps.isDisposed()) {
|
|
305
|
+
return { started: false, skipReason: "session_disposed" };
|
|
306
|
+
}
|
|
307
|
+
const settings = this.deps.getSettingsManager().getResearchLaneSettings();
|
|
308
|
+
const demand = request?.query
|
|
309
|
+
? { query: request.query, context: request.context ?? "", goalId: request.goalId }
|
|
310
|
+
: this._buildResearchLaneDemand();
|
|
311
|
+
if (!demand) {
|
|
312
|
+
return { started: false, skipReason: this._lastResearchLaneSkipReason ?? "no_research_demand" };
|
|
313
|
+
}
|
|
314
|
+
const shipment = this._resolveLaneShipment(settings, "no_research_model");
|
|
315
|
+
if (!shipment.ok) {
|
|
316
|
+
this._lastResearchLaneSkipReason = shipment.skipReason;
|
|
317
|
+
return { started: false, skipReason: shipment.skipReason };
|
|
318
|
+
}
|
|
319
|
+
const { model, laneProfile } = shipment;
|
|
320
|
+
this._isResearchLaneRunning = true;
|
|
321
|
+
this._laneTracker.ensureCounterAtLeast(getLaneRecordSnapshots(this.deps.getSessionManager().getEntries()).length + 1);
|
|
322
|
+
const startedRecord = this._laneTracker.start({ type: "research", goalId: demand.goalId });
|
|
323
|
+
try {
|
|
324
|
+
let spentUsage;
|
|
325
|
+
// Best-effort, pointer-first workspace evidence. Derives search terms from the goal/requirement
|
|
326
|
+
// text (not the identity-key query) and is bounded + silent-on-failure: [] == today's behavior.
|
|
327
|
+
const workspaceSources = await this.deps.collectWorkspaceSources({
|
|
328
|
+
query: `${demand.context}\n${demand.query}`,
|
|
329
|
+
cwd: this.deps.getCwd(),
|
|
330
|
+
maxSources: settings.maxSources,
|
|
331
|
+
});
|
|
332
|
+
const result = await runResearch({
|
|
333
|
+
query: demand.query,
|
|
334
|
+
context: demand.context,
|
|
335
|
+
sources: workspaceSources,
|
|
336
|
+
envelope: this._buildResearchLaneEnvelope(settings.maxUsd, laneProfile),
|
|
337
|
+
maxUsd: settings.maxUsd,
|
|
338
|
+
maxSources: settings.maxSources,
|
|
339
|
+
maxFindings: settings.maxFindings,
|
|
340
|
+
maxWallClockMs: settings.maxWallClockMs,
|
|
341
|
+
signal: this._researchLaneAbort.signal,
|
|
342
|
+
complete: async ({ systemPrompt, userPrompt, signal }) => {
|
|
343
|
+
const completion = await this.deps.runIsolatedCompletion({
|
|
344
|
+
// Level-0 core always survives; profile soul and role prompt are the replaceable
|
|
345
|
+
// layers; a settings-provided prompt replaces everything above the core.
|
|
346
|
+
systemPrompt: composeSubagentSystemPrompt({
|
|
347
|
+
soul: laneProfile?.soul,
|
|
348
|
+
rolePrompt: systemPrompt,
|
|
349
|
+
override: settings.systemPrompt,
|
|
350
|
+
}),
|
|
351
|
+
messages: [{ role: "user", content: [{ type: "text", text: userPrompt }], timestamp: Date.now() }],
|
|
352
|
+
model,
|
|
353
|
+
thinkingLevel: laneProfile?.thinking ?? "off",
|
|
354
|
+
maxTokens: this._laneCapabilityProfile(model).laneMaxOutputTokens,
|
|
355
|
+
signal,
|
|
356
|
+
// Core/soul/role are all static per configuration — the provider can cache the prefix.
|
|
357
|
+
cacheRetention: "short",
|
|
358
|
+
});
|
|
359
|
+
spentUsage = completion.usage;
|
|
360
|
+
return {
|
|
361
|
+
text: completion.text,
|
|
362
|
+
costUsd: completion.usage.cost.total,
|
|
363
|
+
stopReason: String(completion.stopReason),
|
|
364
|
+
};
|
|
365
|
+
},
|
|
366
|
+
});
|
|
367
|
+
// Bug #21 pattern: if the session was disposed while the completion was in flight, do NOT
|
|
368
|
+
// persist evidence/records/usage against the dead session.
|
|
369
|
+
if (this.deps.isDisposed()) {
|
|
370
|
+
const record = this._laneTracker.complete(startedRecord.laneId, {
|
|
371
|
+
status: "canceled",
|
|
372
|
+
reasonCode: "session_disposed",
|
|
373
|
+
});
|
|
374
|
+
return { started: true, record, result };
|
|
375
|
+
}
|
|
376
|
+
let evidenceEntryId;
|
|
377
|
+
if (result.bundle) {
|
|
378
|
+
evidenceEntryId = this.deps.saveEvidenceBundleSnapshot(result.bundle);
|
|
379
|
+
}
|
|
380
|
+
if (spentUsage && (spentUsage.cost.total > 0 || spentUsage.totalTokens > 0)) {
|
|
381
|
+
this.deps.addSpawnedUsage(spentUsage, {
|
|
382
|
+
label: "research-lane",
|
|
383
|
+
reportId: `research:${this.deps.getSessionId()}:${startedRecord.laneId}`,
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
const record = this._laneTracker.complete(startedRecord.laneId, {
|
|
387
|
+
status: result.status,
|
|
388
|
+
reasonCode: result.reasonCode,
|
|
389
|
+
costUsd: result.costUsd,
|
|
390
|
+
evidenceEntryId,
|
|
391
|
+
});
|
|
392
|
+
if (record) {
|
|
393
|
+
appendLaneRecordSnapshot(this.deps.getSessionManager(), record);
|
|
394
|
+
// G3: a research lane's product is an evidence bundle, so its terminal record maps to
|
|
395
|
+
// the evidence_bundle event. Lane outcome only (status/reasonCode/cost) — no findings text.
|
|
396
|
+
this.deps.emitAutonomyTelemetry({
|
|
397
|
+
type: AUTONOMY_TELEMETRY_EVENT_TYPES.evidenceBundle,
|
|
398
|
+
timestamp: new Date().toISOString(),
|
|
399
|
+
payload: {
|
|
400
|
+
laneId: record.laneId,
|
|
401
|
+
laneType: record.type,
|
|
402
|
+
status: record.status,
|
|
403
|
+
reasonCode: record.reasonCode ?? null,
|
|
404
|
+
costUsd: record.costUsd ?? null,
|
|
405
|
+
hasEvidence: record.evidenceEntryId !== undefined,
|
|
406
|
+
},
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
return { started: true, record, result };
|
|
410
|
+
}
|
|
411
|
+
catch (error) {
|
|
412
|
+
const record = this._laneTracker.complete(startedRecord.laneId, {
|
|
413
|
+
status: "failed",
|
|
414
|
+
reasonCode: "research_lane_error",
|
|
415
|
+
});
|
|
416
|
+
if (record && !this.deps.isDisposed()) {
|
|
417
|
+
appendLaneRecordSnapshot(this.deps.getSessionManager(), record);
|
|
418
|
+
this.deps.emitAutonomyTelemetry({
|
|
419
|
+
type: AUTONOMY_TELEMETRY_EVENT_TYPES.evidenceBundle,
|
|
420
|
+
timestamp: new Date().toISOString(),
|
|
421
|
+
payload: {
|
|
422
|
+
laneId: record.laneId,
|
|
423
|
+
laneType: record.type,
|
|
424
|
+
status: record.status,
|
|
425
|
+
reasonCode: record.reasonCode ?? null,
|
|
426
|
+
costUsd: record.costUsd ?? null,
|
|
427
|
+
hasEvidence: record.evidenceEntryId !== undefined,
|
|
428
|
+
},
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
432
|
+
this.deps.emit({ type: "warning", message: `Research lane failed: ${message}` });
|
|
433
|
+
return { started: true, record };
|
|
434
|
+
}
|
|
435
|
+
finally {
|
|
436
|
+
this._isResearchLaneRunning = false;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Run one bounded scout-worker delegation: build a WorkerRequest with a stripped read-only
|
|
441
|
+
* envelope, execute it as an isolated completion on a cheap lane, validate the result via
|
|
442
|
+
* {@link validateWorkerResult} before acceptance, and persist result + lane record + spawned
|
|
443
|
+
* usage (idempotent per-lane reportId). Consumed by the `delegate` tool.
|
|
444
|
+
*/
|
|
445
|
+
async runWorkerDelegationOnce(request) {
|
|
446
|
+
const delegationSettings = this.deps.getSettingsManager().getWorkerDelegationSettings();
|
|
447
|
+
if (this._laneTracker.getActiveCount("worker") >= delegationSettings.maxConcurrent) {
|
|
448
|
+
return { started: false, skipReason: "worker_delegation_already_running" };
|
|
449
|
+
}
|
|
450
|
+
if (this.deps.isDisposed()) {
|
|
451
|
+
return { started: false, skipReason: "session_disposed" };
|
|
452
|
+
}
|
|
453
|
+
const instructions = request.instructions.trim();
|
|
454
|
+
if (instructions.length === 0) {
|
|
455
|
+
return { started: false, skipReason: "missing_instructions" };
|
|
456
|
+
}
|
|
457
|
+
const settings = delegationSettings;
|
|
458
|
+
if (!settings.enabled) {
|
|
459
|
+
return { started: false, skipReason: "worker_delegation_disabled" };
|
|
460
|
+
}
|
|
461
|
+
const shipment = this._resolveLaneShipment(settings, "no_worker_model");
|
|
462
|
+
if (!shipment.ok) {
|
|
463
|
+
return { started: false, skipReason: shipment.skipReason };
|
|
464
|
+
}
|
|
465
|
+
const { model, laneProfile } = shipment;
|
|
466
|
+
this._laneTracker.ensureCounterAtLeast(getLaneRecordSnapshots(this.deps.getSessionManager().getEntries()).length + 1);
|
|
467
|
+
const startedRecord = this._laneTracker.start({ type: "worker" });
|
|
468
|
+
const maxUsd = Math.min(settings.maxUsd, this.deps.getCapabilityEnvelope()?.maxEstimatedUsd ?? Number.POSITIVE_INFINITY);
|
|
469
|
+
const workerRequest = {
|
|
470
|
+
id: startedRecord.laneId,
|
|
471
|
+
instructions,
|
|
472
|
+
route: {
|
|
473
|
+
tier: "cheap",
|
|
474
|
+
risk: "read-only",
|
|
475
|
+
confidence: 1,
|
|
476
|
+
reasonCode: "scout_worker",
|
|
477
|
+
reasons: ["Read-only scout delegation"],
|
|
478
|
+
},
|
|
479
|
+
envelope: {
|
|
480
|
+
id: `worker-${this.deps.getSessionId()}-${startedRecord.laneId}`,
|
|
481
|
+
profileId: laneProfile?.name,
|
|
482
|
+
// write_files requires BOTH the opt-in AND an explicit non-empty path scope —
|
|
483
|
+
// an unscoped write grant is refused here, not discovered at validation time.
|
|
484
|
+
capabilities: settings.writeEnabled && settings.writePaths.length > 0 ? ["read_files", "write_files"] : ["read_files"],
|
|
485
|
+
...(settings.writeEnabled && settings.writePaths.length > 0
|
|
486
|
+
? { allowedPaths: [...settings.writePaths] }
|
|
487
|
+
: {}),
|
|
488
|
+
...this._laneProfileToolGrants(laneProfile),
|
|
489
|
+
maxEstimatedUsd: maxUsd,
|
|
490
|
+
createdAt: new Date().toISOString(),
|
|
491
|
+
},
|
|
492
|
+
maxEstimatedUsd: maxUsd,
|
|
493
|
+
createdAt: new Date().toISOString(),
|
|
494
|
+
};
|
|
495
|
+
// G8: worker delegation START. Routing/scope codes + budget only — never the instructions text.
|
|
496
|
+
this.deps.emitAutonomyTelemetry({
|
|
497
|
+
type: AUTONOMY_TELEMETRY_EVENT_TYPES.workerRequest,
|
|
498
|
+
timestamp: new Date().toISOString(),
|
|
499
|
+
payload: {
|
|
500
|
+
id: workerRequest.id,
|
|
501
|
+
tier: workerRequest.route.tier,
|
|
502
|
+
capabilities: [...workerRequest.envelope.capabilities],
|
|
503
|
+
maxEstimatedUsd: workerRequest.maxEstimatedUsd ?? null,
|
|
504
|
+
},
|
|
505
|
+
});
|
|
506
|
+
const usageReportId = `worker:${this.deps.getSessionId()}:${startedRecord.laneId}`;
|
|
507
|
+
try {
|
|
508
|
+
let spentUsage;
|
|
509
|
+
const outcome = await runWorker({
|
|
510
|
+
request: workerRequest,
|
|
511
|
+
maxUsd,
|
|
512
|
+
maxWallClockMs: settings.maxWallClockMs,
|
|
513
|
+
usageReportId,
|
|
514
|
+
signal: this._workerDelegationAbort.signal,
|
|
515
|
+
// Parent validation must use the same relative-path baseline the runner reports in.
|
|
516
|
+
cwd: this.deps.getCwd(),
|
|
517
|
+
// Write lane (G2): runner-side action application through the envelope path scope.
|
|
518
|
+
applyActions: workerRequest.envelope.capabilities.includes("write_files")
|
|
519
|
+
? (actions) => applyWorkerActions({ actions, envelope: workerRequest.envelope, cwd: this.deps.getCwd() })
|
|
520
|
+
: undefined,
|
|
521
|
+
complete: async ({ systemPrompt, userPrompt, signal }) => {
|
|
522
|
+
const completion = await this.deps.runIsolatedCompletion({
|
|
523
|
+
// Level-0 core always survives. A model-provided prompt (delegate tool) is the most
|
|
524
|
+
// specific override, then the settings-level prompt, then profile soul + role prompt.
|
|
525
|
+
systemPrompt: composeSubagentSystemPrompt({
|
|
526
|
+
soul: laneProfile?.soul,
|
|
527
|
+
rolePrompt: systemPrompt,
|
|
528
|
+
override: request.systemPrompt ?? settings.systemPrompt,
|
|
529
|
+
}),
|
|
530
|
+
messages: [{ role: "user", content: [{ type: "text", text: userPrompt }], timestamp: Date.now() }],
|
|
531
|
+
model,
|
|
532
|
+
thinkingLevel: laneProfile?.thinking ?? "off",
|
|
533
|
+
maxTokens: this._laneCapabilityProfile(model).laneMaxOutputTokens,
|
|
534
|
+
signal,
|
|
535
|
+
// Core/soul/role are all static per configuration — the provider can cache the prefix.
|
|
536
|
+
cacheRetention: "short",
|
|
537
|
+
});
|
|
538
|
+
spentUsage = completion.usage;
|
|
539
|
+
return {
|
|
540
|
+
text: completion.text,
|
|
541
|
+
costUsd: completion.usage.cost.total,
|
|
542
|
+
stopReason: String(completion.stopReason),
|
|
543
|
+
};
|
|
544
|
+
},
|
|
545
|
+
});
|
|
546
|
+
// Bug #21 pattern: never persist against a disposed session.
|
|
547
|
+
if (this.deps.isDisposed()) {
|
|
548
|
+
const record = this._laneTracker.complete(startedRecord.laneId, {
|
|
549
|
+
status: "canceled",
|
|
550
|
+
reasonCode: "session_disposed",
|
|
551
|
+
});
|
|
552
|
+
return { started: true, record, outcome };
|
|
553
|
+
}
|
|
554
|
+
this.deps.saveWorkerResultSnapshot(outcome.result, workerRequest);
|
|
555
|
+
if (spentUsage && (spentUsage.cost.total > 0 || spentUsage.totalTokens > 0)) {
|
|
556
|
+
this.deps.addSpawnedUsage(spentUsage, { label: "worker-delegation", reportId: usageReportId });
|
|
557
|
+
}
|
|
558
|
+
const record = this._laneTracker.complete(startedRecord.laneId, {
|
|
559
|
+
status: outcome.laneStatus,
|
|
560
|
+
reasonCode: outcome.reasonCode,
|
|
561
|
+
costUsd: outcome.costUsd,
|
|
562
|
+
});
|
|
563
|
+
if (record) {
|
|
564
|
+
appendLaneRecordSnapshot(this.deps.getSessionManager(), record);
|
|
565
|
+
// G3: worker lane terminal record -> worker_result event. Lane outcome only
|
|
566
|
+
// (status/reasonCode/cost) — never the worker's summary/changed-file text.
|
|
567
|
+
this.deps.emitAutonomyTelemetry({
|
|
568
|
+
type: AUTONOMY_TELEMETRY_EVENT_TYPES.workerResult,
|
|
569
|
+
timestamp: new Date().toISOString(),
|
|
570
|
+
payload: {
|
|
571
|
+
laneId: record.laneId,
|
|
572
|
+
laneType: record.type,
|
|
573
|
+
status: record.status,
|
|
574
|
+
reasonCode: record.reasonCode ?? null,
|
|
575
|
+
costUsd: record.costUsd ?? null,
|
|
576
|
+
},
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
return { started: true, record, outcome };
|
|
580
|
+
}
|
|
581
|
+
catch (error) {
|
|
582
|
+
const record = this._laneTracker.complete(startedRecord.laneId, {
|
|
583
|
+
status: "failed",
|
|
584
|
+
reasonCode: "worker_delegation_error",
|
|
585
|
+
});
|
|
586
|
+
if (record && !this.deps.isDisposed()) {
|
|
587
|
+
appendLaneRecordSnapshot(this.deps.getSessionManager(), record);
|
|
588
|
+
this.deps.emitAutonomyTelemetry({
|
|
589
|
+
type: AUTONOMY_TELEMETRY_EVENT_TYPES.workerResult,
|
|
590
|
+
timestamp: new Date().toISOString(),
|
|
591
|
+
payload: {
|
|
592
|
+
laneId: record.laneId,
|
|
593
|
+
laneType: record.type,
|
|
594
|
+
status: record.status,
|
|
595
|
+
reasonCode: record.reasonCode ?? null,
|
|
596
|
+
costUsd: record.costUsd ?? null,
|
|
597
|
+
},
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
601
|
+
this.deps.emit({ type: "warning", message: `Worker delegation failed: ${message}` });
|
|
602
|
+
return { started: true, record };
|
|
603
|
+
}
|
|
604
|
+
finally {
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Probe a candidate model against the subagent contracts (research/worker/judge/search/
|
|
609
|
+
* tool-call surfaces) via {@link runModelFitnessProbe}. The model must resolve and
|
|
610
|
+
* authenticate; every probe call runs as an isolated completion on that model, and probe
|
|
611
|
+
* spend is reported through spawned-usage accounting.
|
|
612
|
+
*/
|
|
613
|
+
async runModelFitness(args) {
|
|
614
|
+
if (this.deps.isDisposed())
|
|
615
|
+
return { started: false, skipReason: "session_disposed" };
|
|
616
|
+
const resolved = this.resolveLaneModel(args.model.trim() || undefined);
|
|
617
|
+
if (!resolved)
|
|
618
|
+
return { started: false, skipReason: "model_unresolved_or_unauthenticated" };
|
|
619
|
+
const capability = this._laneCapabilityProfile(resolved);
|
|
620
|
+
const spent = {
|
|
621
|
+
input: 0,
|
|
622
|
+
output: 0,
|
|
623
|
+
cacheRead: 0,
|
|
624
|
+
cacheWrite: 0,
|
|
625
|
+
totalTokens: 0,
|
|
626
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
|
|
627
|
+
};
|
|
628
|
+
const report = await runModelFitnessProbe({
|
|
629
|
+
trials: args.trials,
|
|
630
|
+
signal: this._researchLaneAbort.signal,
|
|
631
|
+
complete: async ({ systemPrompt, userPrompt, signal }) => {
|
|
632
|
+
const callStarted = Date.now();
|
|
633
|
+
const completion = await this.deps.runIsolatedCompletion({
|
|
634
|
+
systemPrompt,
|
|
635
|
+
messages: [{ role: "user", content: [{ type: "text", text: userPrompt }], timestamp: Date.now() }],
|
|
636
|
+
model: resolved,
|
|
637
|
+
thinkingLevel: "off",
|
|
638
|
+
maxTokens: capability.laneMaxOutputTokens,
|
|
639
|
+
signal,
|
|
640
|
+
cacheRetention: "short",
|
|
641
|
+
});
|
|
642
|
+
const callMs = Date.now() - callStarted;
|
|
643
|
+
spent.input += completion.usage.input;
|
|
644
|
+
spent.output += completion.usage.output;
|
|
645
|
+
spent.cacheRead += completion.usage.cacheRead;
|
|
646
|
+
spent.cacheWrite += completion.usage.cacheWrite;
|
|
647
|
+
spent.totalTokens += completion.usage.totalTokens;
|
|
648
|
+
spent.cost.input += completion.usage.cost.input;
|
|
649
|
+
spent.cost.output += completion.usage.cost.output;
|
|
650
|
+
spent.cost.cacheRead += completion.usage.cost.cacheRead;
|
|
651
|
+
spent.cost.cacheWrite += completion.usage.cost.cacheWrite;
|
|
652
|
+
spent.cost.total += completion.usage.cost.total;
|
|
653
|
+
return {
|
|
654
|
+
text: completion.text,
|
|
655
|
+
costUsd: completion.usage.cost.total,
|
|
656
|
+
stopReason: String(completion.stopReason),
|
|
657
|
+
// Wall-clock fallback for tok/s: providers don't expose pure eval time, so the
|
|
658
|
+
// measured call time stands in — slightly conservative (includes network/queue).
|
|
659
|
+
outputTokens: completion.usage.output,
|
|
660
|
+
evalMs: callMs,
|
|
661
|
+
};
|
|
662
|
+
},
|
|
663
|
+
});
|
|
664
|
+
if (!this.deps.isDisposed() && (spent.cost.total > 0 || spent.totalTokens > 0)) {
|
|
665
|
+
this.deps.addSpawnedUsage(spent, { label: "model-fitness" });
|
|
666
|
+
}
|
|
667
|
+
const modelRef = `${resolved.provider}/${resolved.id}`;
|
|
668
|
+
// Fitness is a property of a model ON a host — persist the report host-keyed so role
|
|
669
|
+
// assignments stay per-machine (a model can await better hardware without being forgotten).
|
|
670
|
+
// Best-effort: a disk problem must not fail the probe itself.
|
|
671
|
+
try {
|
|
672
|
+
if (!this.deps.isDisposed()) {
|
|
673
|
+
FitnessStore.forAgentDir(this.deps.getAgentDir()).save(modelRef, report);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
catch {
|
|
677
|
+
// best-effort persistence
|
|
678
|
+
}
|
|
679
|
+
return { started: true, model: modelRef, report };
|
|
680
|
+
}
|
|
681
|
+
/** Fitness reports persisted for THIS host (measured evidence for architect/profile decisions). */
|
|
682
|
+
getStoredFitnessReports() {
|
|
683
|
+
try {
|
|
684
|
+
return FitnessStore.forAgentDir(this.deps.getAgentDir()).getForHost();
|
|
685
|
+
}
|
|
686
|
+
catch {
|
|
687
|
+
return [];
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
//# sourceMappingURL=background-lane-controller.js.map
|