@caupulican/pi-adaptative 0.80.103 → 0.81.1
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 +128 -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 +154 -512
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +675 -4589
- 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/http-dispatcher.d.ts +4 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +6 -1
- package/dist/core/http-dispatcher.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/settings-manager.d.ts +16 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +22 -0
- package/dist/core/settings-manager.js.map +1 -1
- 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,640 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime build & reload: the session's tool-registry assembly and the self-modification-safe
|
|
3
|
+
* extension reload path. Owns building the base tool definitions, wrapping them into the live tool
|
|
4
|
+
* registry (`_refreshToolRegistry`), constructing the {@link ExtensionRunner} for a rebuilt runtime
|
|
5
|
+
* (`_buildRuntime`), and the repo's self-modification safety crown jewel: the preflight-guarded
|
|
6
|
+
* `reload()` with its snapshot / doctor / commit-or-rollback sequence, plus the single-extension
|
|
7
|
+
* live load/unload/reconcile operations that rebuild the runtime in place.
|
|
8
|
+
*
|
|
9
|
+
* Extracted verbatim from agent-session.ts (god-file decomposition). Owns ONLY the tool-registry
|
|
10
|
+
* state — the base tool definitions, the wrapped tool registry, the definition registry, and the
|
|
11
|
+
* per-tool prompt snippet/guideline maps. Everything else the build & reload touch — the live
|
|
12
|
+
* {@link ExtensionRunner}, the agent's tool/system-prompt state, the base system prompt, the
|
|
13
|
+
* resource loader, the session/settings managers, the model registry, the profile tool filter and
|
|
14
|
+
* its warning sinks, the requested-active-tool-names request, the memory subsystem, and the many
|
|
15
|
+
* host callbacks the rebuilt tools/runtime are wired to — is reached through narrow deps accessors
|
|
16
|
+
* that read and write the SAME storage the host owns today.
|
|
17
|
+
*
|
|
18
|
+
* Snapshot-ownership boundary (deliberate, load-bearing for reload safety): the reload snapshot
|
|
19
|
+
* spans state owned by OTHER collaborators — the extension runner and its ref, `agent.state.tools`
|
|
20
|
+
* / `agent.state.systemPrompt`, and `_baseSystemPrompt`. Those are captured and restored through
|
|
21
|
+
* {@link RuntimeBuilderDeps} get/set accessors so save/restore mutate exactly the host/agent fields
|
|
22
|
+
* they mutated before extraction; only the five tool-registry maps are captured by direct field
|
|
23
|
+
* reference here (this builder owns them). The `_extensionRunnerRef.current` update folds into
|
|
24
|
+
* {@link RuntimeBuilderDeps.setExtensionRunner} (the same field-then-ref pattern the host used at
|
|
25
|
+
* every assignment site), so no observer runs between the two writes.
|
|
26
|
+
*
|
|
27
|
+
* Host-binding boundary (deliberate): `_bindExtensionCore` — which exposes the SESSION's own public
|
|
28
|
+
* surface (sendMessage, setModel, compact, abort, reload, …) to the extension runner — stays
|
|
29
|
+
* host-side and is invoked from {@link buildRuntime} via {@link RuntimeBuilderDeps.bindExtensionCore};
|
|
30
|
+
* it is host identity, not build logic, and moving it would only re-export ~30 host methods through
|
|
31
|
+
* deps to hand them straight back. The host keeps one-line delegations for the public reload /
|
|
32
|
+
* load / unload / reconcile API and for `getAllTools` / `getToolDefinition`, and a private
|
|
33
|
+
* `_refreshToolRegistry` delegation for its internal callers.
|
|
34
|
+
*/
|
|
35
|
+
import { resetApiProviders } from "@caupulican/pi-ai";
|
|
36
|
+
import { createCoreDiagnosticsToolDefinitions } from "./extensions/builtin.js";
|
|
37
|
+
import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
|
|
38
|
+
import { disposeExtensionEventSubscriptions } from "./extensions/loader.js";
|
|
39
|
+
import { emitSessionShutdownEvent } from "./extensions/runner.js";
|
|
40
|
+
import { matchesResourceProfilePattern, } from "./settings-manager.js";
|
|
41
|
+
import { createSyntheticSourceInfo } from "./source-info.js";
|
|
42
|
+
import { buildReflexUserPrompt, parseReflexPlan, REFLEX_INTERPRETER_SYSTEM_PROMPT, } from "./toolkit/reflex-interpreter.js";
|
|
43
|
+
import { executeToolkitScript } from "./toolkit/script-runner.js";
|
|
44
|
+
import { createDelegateToolDefinition } from "./tools/delegate.js";
|
|
45
|
+
import { createGoalToolDefinition } from "./tools/goal.js";
|
|
46
|
+
import { createAllToolDefinitions } from "./tools/index.js";
|
|
47
|
+
import { createModelFitnessToolDefinition } from "./tools/model-fitness.js";
|
|
48
|
+
import { createRunToolkitScriptToolDefinition } from "./tools/run-toolkit-script.js";
|
|
49
|
+
import { createToolDefinitionFromAgentTool } from "./tools/tool-definition-wrapper.js";
|
|
50
|
+
/**
|
|
51
|
+
* Owns the tool-registry build and the self-modification-safe extension reload extracted from
|
|
52
|
+
* {@link AgentSession}. See the module header for the snapshot-ownership and host-binding boundaries.
|
|
53
|
+
*/
|
|
54
|
+
export class RuntimeBuilder {
|
|
55
|
+
// Tool registry for extension getTools/setTools
|
|
56
|
+
_toolRegistry = new Map();
|
|
57
|
+
_toolDefinitions = new Map();
|
|
58
|
+
_toolPromptSnippets = new Map();
|
|
59
|
+
_toolPromptGuidelines = new Map();
|
|
60
|
+
_baseToolDefinitions = new Map();
|
|
61
|
+
deps;
|
|
62
|
+
constructor(deps) {
|
|
63
|
+
this.deps = deps;
|
|
64
|
+
}
|
|
65
|
+
/** Whether a tool name is present in the live wrapped registry. */
|
|
66
|
+
hasTool(name) {
|
|
67
|
+
return this._toolRegistry.has(name);
|
|
68
|
+
}
|
|
69
|
+
/** The live wrapped tool for a name, if registered (activation lookup). */
|
|
70
|
+
getRegisteredTool(name) {
|
|
71
|
+
return this._toolRegistry.get(name);
|
|
72
|
+
}
|
|
73
|
+
/** A registered tool's normalized prompt snippet, if any. */
|
|
74
|
+
getToolPromptSnippet(name) {
|
|
75
|
+
return this._toolPromptSnippets.get(name);
|
|
76
|
+
}
|
|
77
|
+
/** A registered tool's normalized prompt guidelines, if any. */
|
|
78
|
+
getToolPromptGuidelines(name) {
|
|
79
|
+
return this._toolPromptGuidelines.get(name);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get all configured tools with name, description, parameter schema, prompt guidelines, and source metadata.
|
|
83
|
+
*/
|
|
84
|
+
getAllTools() {
|
|
85
|
+
return Array.from(this._toolDefinitions.values()).map(({ definition, sourceInfo }) => ({
|
|
86
|
+
name: definition.name,
|
|
87
|
+
description: definition.description,
|
|
88
|
+
parameters: definition.parameters,
|
|
89
|
+
promptGuidelines: definition.promptGuidelines,
|
|
90
|
+
sourceInfo,
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
getToolDefinition(name) {
|
|
94
|
+
return this._toolDefinitions.get(name)?.definition;
|
|
95
|
+
}
|
|
96
|
+
refreshToolRegistry(options) {
|
|
97
|
+
const previousRegistryNames = new Set(this._toolRegistry.keys());
|
|
98
|
+
// Re-derive from the pre-filter REQUEST, never from agent.state.tools: the active set is
|
|
99
|
+
// capability/profile-filtered, so feeding it back through setActiveToolsByName would
|
|
100
|
+
// permanently shrink what a later switch to a larger model (or permissive profile) restores.
|
|
101
|
+
const previousActiveToolNames = this.deps.getRequestedActiveToolNames() ?? this.deps.getActiveToolNames();
|
|
102
|
+
const allowedToolNames = this.deps.getAllowedToolNames();
|
|
103
|
+
const excludedToolNames = this.deps.getExcludedToolNames();
|
|
104
|
+
const toolProfileFilter = this.deps.getToolProfileFilter();
|
|
105
|
+
const isAllowedTool = (name) => {
|
|
106
|
+
if (allowedToolNames && !allowedToolNames.has(name))
|
|
107
|
+
return false;
|
|
108
|
+
if (excludedToolNames?.has(name))
|
|
109
|
+
return false;
|
|
110
|
+
if (!toolProfileFilter)
|
|
111
|
+
return true;
|
|
112
|
+
if (toolProfileFilter.allow.length > 0 && !matchesResourceProfilePattern(name, toolProfileFilter.allow)) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
if (matchesResourceProfilePattern(name, toolProfileFilter.block))
|
|
116
|
+
return false;
|
|
117
|
+
return true;
|
|
118
|
+
};
|
|
119
|
+
const registeredTools = this.deps.getExtensionRunner().getAllRegisteredTools();
|
|
120
|
+
const allCustomTools = [
|
|
121
|
+
...registeredTools,
|
|
122
|
+
...this.deps.getCustomTools().map((definition) => ({
|
|
123
|
+
definition,
|
|
124
|
+
sourceInfo: createSyntheticSourceInfo(`<sdk:${definition.name}>`, { source: "sdk" }),
|
|
125
|
+
})),
|
|
126
|
+
// Memory subsystem provider tools (e.g. file-store's `memory` tool).
|
|
127
|
+
...this.deps
|
|
128
|
+
.getMemoryManager()
|
|
129
|
+
.getToolDefinitions()
|
|
130
|
+
.map((definition) => ({
|
|
131
|
+
definition,
|
|
132
|
+
sourceInfo: createSyntheticSourceInfo(`<memory:${definition.name}>`, { source: "sdk" }),
|
|
133
|
+
})),
|
|
134
|
+
].filter((tool) => isAllowedTool(tool.definition.name));
|
|
135
|
+
const definitionRegistry = new Map(Array.from(this._baseToolDefinitions.entries())
|
|
136
|
+
.filter(([name]) => isAllowedTool(name))
|
|
137
|
+
.map(([name, definition]) => [
|
|
138
|
+
name,
|
|
139
|
+
{
|
|
140
|
+
definition,
|
|
141
|
+
sourceInfo: createSyntheticSourceInfo(`<builtin:${name}>`, { source: "builtin" }),
|
|
142
|
+
},
|
|
143
|
+
]));
|
|
144
|
+
for (const tool of allCustomTools) {
|
|
145
|
+
definitionRegistry.set(tool.definition.name, {
|
|
146
|
+
definition: tool.definition,
|
|
147
|
+
sourceInfo: tool.sourceInfo,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
this._toolDefinitions = definitionRegistry;
|
|
151
|
+
this._toolPromptSnippets = new Map(Array.from(definitionRegistry.values())
|
|
152
|
+
.map(({ definition }) => {
|
|
153
|
+
const snippet = this.deps.normalizePromptSnippet(definition.promptSnippet);
|
|
154
|
+
return snippet ? [definition.name, snippet] : undefined;
|
|
155
|
+
})
|
|
156
|
+
.filter((entry) => entry !== undefined));
|
|
157
|
+
this._toolPromptGuidelines = new Map(Array.from(definitionRegistry.values())
|
|
158
|
+
.map(({ definition }) => {
|
|
159
|
+
const guidelines = this.deps.normalizePromptGuidelines(definition.promptGuidelines);
|
|
160
|
+
return guidelines.length > 0 ? [definition.name, guidelines] : undefined;
|
|
161
|
+
})
|
|
162
|
+
.filter((entry) => entry !== undefined));
|
|
163
|
+
const runner = this.deps.getExtensionRunner();
|
|
164
|
+
const wrappedExtensionTools = wrapRegisteredTools(allCustomTools, runner);
|
|
165
|
+
const wrappedBuiltInTools = wrapRegisteredTools(Array.from(this._baseToolDefinitions.values())
|
|
166
|
+
.filter((definition) => isAllowedTool(definition.name))
|
|
167
|
+
.map((definition) => ({
|
|
168
|
+
definition,
|
|
169
|
+
sourceInfo: createSyntheticSourceInfo(`<builtin:${definition.name}>`, { source: "builtin" }),
|
|
170
|
+
})), runner);
|
|
171
|
+
const toolRegistry = new Map(wrappedBuiltInTools.map((tool) => [tool.name, tool]));
|
|
172
|
+
for (const tool of wrappedExtensionTools) {
|
|
173
|
+
toolRegistry.set(tool.name, tool);
|
|
174
|
+
}
|
|
175
|
+
this._toolRegistry = toolRegistry;
|
|
176
|
+
const requestedBase = options?.activeToolNames ? [...options.activeToolNames] : [...previousActiveToolNames];
|
|
177
|
+
const nextActiveToolNames = requestedBase.filter((name) => isAllowedTool(name));
|
|
178
|
+
const autoActivated = [];
|
|
179
|
+
if (allowedToolNames) {
|
|
180
|
+
for (const toolName of this._toolRegistry.keys()) {
|
|
181
|
+
if (allowedToolNames.has(toolName)) {
|
|
182
|
+
nextActiveToolNames.push(toolName);
|
|
183
|
+
autoActivated.push(toolName);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
else if (options?.includeAllExtensionTools) {
|
|
188
|
+
for (const tool of wrappedExtensionTools) {
|
|
189
|
+
nextActiveToolNames.push(tool.name);
|
|
190
|
+
autoActivated.push(tool.name);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else if (!options?.activeToolNames) {
|
|
194
|
+
for (const toolName of this._toolRegistry.keys()) {
|
|
195
|
+
if (!previousRegistryNames.has(toolName)) {
|
|
196
|
+
nextActiveToolNames.push(toolName);
|
|
197
|
+
autoActivated.push(toolName);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// Strict UAC: the active profile is the COMPLETE grant, so a tool the profile names
|
|
202
|
+
// explicitly is itself a request for that tool — it must ACTIVATE from the registry even
|
|
203
|
+
// if the session never requested it. Without this, activation is only ever the requested
|
|
204
|
+
// defaults ∩ allow-list, and a profile granting non-default tools (a search-only profile's
|
|
205
|
+
// grep/find) yields an empty or truncated tool set on load and /reload. A blanket "*"
|
|
206
|
+
// stays grant-only: activation then still derives from the request/defaults above.
|
|
207
|
+
const explicitAllowPatterns = toolProfileFilter?.allow.filter((pattern) => pattern !== "*") ?? [];
|
|
208
|
+
if (explicitAllowPatterns.length > 0) {
|
|
209
|
+
const boundPatterns = new Set();
|
|
210
|
+
for (const toolName of this._toolRegistry.keys()) {
|
|
211
|
+
if (!isAllowedTool(toolName))
|
|
212
|
+
continue;
|
|
213
|
+
for (const pattern of explicitAllowPatterns) {
|
|
214
|
+
if (matchesResourceProfilePattern(toolName, [pattern]))
|
|
215
|
+
boundPatterns.add(pattern);
|
|
216
|
+
}
|
|
217
|
+
if (matchesResourceProfilePattern(toolName, explicitAllowPatterns)) {
|
|
218
|
+
nextActiveToolNames.push(toolName);
|
|
219
|
+
autoActivated.push(toolName);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// G13: an explicit grant that binds to NO registered tool is a silent no-op — typo'd
|
|
223
|
+
// name, or the owning extension is not granted/loaded. Surface it.
|
|
224
|
+
this.deps.setUnboundToolGrantWarnings(explicitAllowPatterns
|
|
225
|
+
.filter((pattern) => !boundPatterns.has(pattern))
|
|
226
|
+
.map((pattern) => `profile tool grant "${pattern}" binds to no registered tool (typo, or the owning extension is not granted/loaded)`));
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
this.deps.setUnboundToolGrantWarnings([]);
|
|
230
|
+
}
|
|
231
|
+
// artifact_retrieve companion auto-activation is enforced inside
|
|
232
|
+
// setActiveToolsByName() itself (not duplicated here), so every activation path --
|
|
233
|
+
// including the public, extension-exposed setActiveTools() -- gets the same
|
|
234
|
+
// guarantee, not just this settings/profile refresh flow.
|
|
235
|
+
this.deps.setActiveToolsByName([...new Set(nextActiveToolNames)]);
|
|
236
|
+
// setActiveToolsByName just stored the profile-filtered ACTIVE set as the request; restore
|
|
237
|
+
// the true pre-filter request (plus this refresh's auto-activations) so an internal refresh
|
|
238
|
+
// can never permanently narrow it.
|
|
239
|
+
this.deps.setRequestedActiveToolNames([...new Set([...requestedBase, ...autoActivated])]);
|
|
240
|
+
}
|
|
241
|
+
_createReloadRuntimeSnapshot() {
|
|
242
|
+
const agent = this.deps.getAgent();
|
|
243
|
+
return {
|
|
244
|
+
extensionRunner: this.deps.getExtensionRunner(),
|
|
245
|
+
baseToolDefinitions: this._baseToolDefinitions,
|
|
246
|
+
toolRegistry: this._toolRegistry,
|
|
247
|
+
toolDefinitions: this._toolDefinitions,
|
|
248
|
+
toolPromptSnippets: this._toolPromptSnippets,
|
|
249
|
+
toolPromptGuidelines: this._toolPromptGuidelines,
|
|
250
|
+
agentTools: agent.state.tools,
|
|
251
|
+
agentSystemPrompt: agent.state.systemPrompt,
|
|
252
|
+
baseSystemPrompt: this.deps.getBaseSystemPrompt(),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
_restoreReloadRuntimeSnapshot(snapshot) {
|
|
256
|
+
// setExtensionRunner restores both _extensionRunner and _extensionRunnerRef.current together
|
|
257
|
+
// (the same field-then-ref pair the host wrote at every assignment site); nothing reads the
|
|
258
|
+
// ref between the two writes, so folding them is unobservable.
|
|
259
|
+
this.deps.setExtensionRunner(snapshot.extensionRunner);
|
|
260
|
+
this._baseToolDefinitions = snapshot.baseToolDefinitions;
|
|
261
|
+
this._toolRegistry = snapshot.toolRegistry;
|
|
262
|
+
this._toolDefinitions = snapshot.toolDefinitions;
|
|
263
|
+
this._toolPromptSnippets = snapshot.toolPromptSnippets;
|
|
264
|
+
this._toolPromptGuidelines = snapshot.toolPromptGuidelines;
|
|
265
|
+
const agent = this.deps.getAgent();
|
|
266
|
+
agent.state.tools = snapshot.agentTools;
|
|
267
|
+
agent.state.systemPrompt = snapshot.agentSystemPrompt;
|
|
268
|
+
this.deps.setBaseSystemPrompt(snapshot.baseSystemPrompt);
|
|
269
|
+
this.deps.applyExtensionBindings(snapshot.extensionRunner);
|
|
270
|
+
}
|
|
271
|
+
_doctorReloadRuntime() {
|
|
272
|
+
const extensionErrors = this.deps.getResourceLoader().getExtensions().errors;
|
|
273
|
+
if (extensionErrors.length > 0) {
|
|
274
|
+
const summary = extensionErrors
|
|
275
|
+
.slice(0, 6)
|
|
276
|
+
.map((error) => `${error.path}: ${error.error}`)
|
|
277
|
+
.join("; ");
|
|
278
|
+
throw new Error(`Extension reload failed doctor: ${summary}`);
|
|
279
|
+
}
|
|
280
|
+
const missingActiveTools = this.deps.getActiveToolNames().filter((name) => !this._toolRegistry.has(name));
|
|
281
|
+
if (missingActiveTools.length > 0) {
|
|
282
|
+
throw new Error(`Extension reload failed doctor: active tool(s) missing after reload: ${missingActiveTools.join(", ")}`);
|
|
283
|
+
}
|
|
284
|
+
for (const tool of this.deps.getAgent().state.tools) {
|
|
285
|
+
if (!this._toolDefinitions.has(tool.name)) {
|
|
286
|
+
throw new Error(`Extension reload failed doctor: tool ${tool.name} missing from definition registry`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
this.deps.createAgentContextSnapshot();
|
|
290
|
+
this.deps.getContextUsage();
|
|
291
|
+
}
|
|
292
|
+
buildRuntime(options) {
|
|
293
|
+
const settingsManager = this.deps.getSettingsManager();
|
|
294
|
+
const autoResizeImages = settingsManager.getImageAutoResize();
|
|
295
|
+
const shellCommandPrefix = settingsManager.getShellCommandPrefix();
|
|
296
|
+
const shellPath = settingsManager.getShellPath();
|
|
297
|
+
const baseToolsOverride = this.deps.getBaseToolsOverride();
|
|
298
|
+
// grep/find must not emit a "Full output: artifact tool-output:<id>" handle that
|
|
299
|
+
// nothing can resolve. If artifact_retrieve is explicitly excluded/blocked/outside
|
|
300
|
+
// an active allowlist, don't hand grep/find an artifact store at all: they fall
|
|
301
|
+
// back to their pre-existing bounded preview/truncation behavior, with no
|
|
302
|
+
// payload/meta files ever written and no retrieval promise made.
|
|
303
|
+
const toolArtifactStore = this.deps.isToolOrCommandAllowedByProfile("artifact_retrieve")
|
|
304
|
+
? this.deps.getToolArtifactStore()
|
|
305
|
+
: undefined;
|
|
306
|
+
const baseToolDefinitions = baseToolsOverride
|
|
307
|
+
? Object.fromEntries(Object.entries(baseToolsOverride).map(([name, tool]) => [name, createToolDefinitionFromAgentTool(tool)]))
|
|
308
|
+
: createAllToolDefinitions(this.deps.getCwd(), {
|
|
309
|
+
read: { autoResizeImages },
|
|
310
|
+
bash: { commandPrefix: shellCommandPrefix, shellPath },
|
|
311
|
+
grep: { artifactStore: toolArtifactStore },
|
|
312
|
+
find: { artifactStore: toolArtifactStore },
|
|
313
|
+
artifact_retrieve: { artifactStore: toolArtifactStore },
|
|
314
|
+
});
|
|
315
|
+
this._baseToolDefinitions = new Map(Object.entries(baseToolDefinitions).map(([name, tool]) => [name, tool]));
|
|
316
|
+
if (!baseToolsOverride) {
|
|
317
|
+
for (const definition of createCoreDiagnosticsToolDefinitions(() => this.deps.getActiveToolNames(), () => this.getAllTools(), (messages) => this.deps.getContextGcReport(messages), () => this.deps.getMemoryAuditDiagnostics())) {
|
|
318
|
+
this._baseToolDefinitions.set(definition.name, definition);
|
|
319
|
+
}
|
|
320
|
+
const goalToolDefinition = createGoalToolDefinition({
|
|
321
|
+
getGoalState: () => this.deps.getGoalStateSnapshot(),
|
|
322
|
+
saveGoalState: (state) => {
|
|
323
|
+
this.deps.saveGoalStateSnapshot(state);
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
this._baseToolDefinitions.set(goalToolDefinition.name, goalToolDefinition);
|
|
327
|
+
const delegateToolDefinition = createDelegateToolDefinition({
|
|
328
|
+
runWorkerDelegation: (args) => this.deps.runWorkerDelegationOnce(args),
|
|
329
|
+
});
|
|
330
|
+
this._baseToolDefinitions.set(delegateToolDefinition.name, delegateToolDefinition);
|
|
331
|
+
// Registered but not default-active: probes spend tokens on the probed model, so
|
|
332
|
+
// activation is an explicit choice (settings/profile/setActiveTools or /autonomy fitness).
|
|
333
|
+
const modelFitnessToolDefinition = createModelFitnessToolDefinition({
|
|
334
|
+
runProbe: (args) => this.deps.runModelFitness(args),
|
|
335
|
+
});
|
|
336
|
+
this._baseToolDefinitions.set(modelFitnessToolDefinition.name, modelFitnessToolDefinition);
|
|
337
|
+
const runToolkitScriptToolDefinition = createRunToolkitScriptToolDefinition({
|
|
338
|
+
getScripts: () => this.deps.getSettingsManager().getToolkitScripts(),
|
|
339
|
+
execute: (script, scriptArgs) => executeToolkitScript({ script, scriptArgs, cwd: this.deps.getCwd() }),
|
|
340
|
+
// Reflex brain (fitness-gated local model): resolves ambiguous requests into a
|
|
341
|
+
// registry pick. Best-effort — absent/unfit brain keeps the shortlist behavior.
|
|
342
|
+
interpret: async (request, scripts) => {
|
|
343
|
+
const model = this.deps.resolveCurationModelIfFit();
|
|
344
|
+
if (!model)
|
|
345
|
+
return undefined;
|
|
346
|
+
const completion = await this.deps.runIsolatedCompletion({
|
|
347
|
+
systemPrompt: REFLEX_INTERPRETER_SYSTEM_PROMPT,
|
|
348
|
+
messages: [
|
|
349
|
+
{
|
|
350
|
+
role: "user",
|
|
351
|
+
content: [{ type: "text", text: buildReflexUserPrompt(request, scripts) }],
|
|
352
|
+
timestamp: Date.now(),
|
|
353
|
+
},
|
|
354
|
+
],
|
|
355
|
+
model,
|
|
356
|
+
thinkingLevel: "off",
|
|
357
|
+
maxTokens: 256,
|
|
358
|
+
cacheRetention: "short",
|
|
359
|
+
});
|
|
360
|
+
if (completion.usage.cost.total > 0 || completion.usage.totalTokens > 0) {
|
|
361
|
+
this.deps.addSpawnedUsage(completion.usage, { label: "toolkit-brain" });
|
|
362
|
+
}
|
|
363
|
+
return parseReflexPlan(completion.text);
|
|
364
|
+
},
|
|
365
|
+
});
|
|
366
|
+
this._baseToolDefinitions.set(runToolkitScriptToolDefinition.name, runToolkitScriptToolDefinition);
|
|
367
|
+
}
|
|
368
|
+
const extensionsResult = this.deps.getResourceLoader().getExtensions();
|
|
369
|
+
if (options.flagValues) {
|
|
370
|
+
for (const [name, value] of options.flagValues) {
|
|
371
|
+
extensionsResult.runtime.flagValues.set(name, value);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const extensions = this.deps.filterExtensionsForRuntime(extensionsResult.extensions);
|
|
375
|
+
const runtimeExtensionPaths = new Set(extensions.map((extension) => extension.path));
|
|
376
|
+
extensionsResult.runtime.pendingProviderRegistrations =
|
|
377
|
+
extensionsResult.runtime.pendingProviderRegistrations.filter((registration) => runtimeExtensionPaths.has(registration.extensionPath));
|
|
378
|
+
const runner = new ExtensionRunner(extensions, extensionsResult.runtime, this.deps.getCwd(), this.deps.getSessionManager(), this.deps.getModelRegistry());
|
|
379
|
+
this.deps.setExtensionRunner(runner);
|
|
380
|
+
this.deps.bindExtensionCore(runner);
|
|
381
|
+
this.deps.applyExtensionBindings(runner);
|
|
382
|
+
const defaultActiveToolNames = baseToolsOverride
|
|
383
|
+
? Object.keys(baseToolsOverride)
|
|
384
|
+
: ["read", "bash", "edit", "write", "context_audit", "goal", "delegate", "run_toolkit_script"];
|
|
385
|
+
const baseActiveToolNames = options.activeToolNames ?? defaultActiveToolNames;
|
|
386
|
+
this.refreshToolRegistry({
|
|
387
|
+
activeToolNames: baseActiveToolNames,
|
|
388
|
+
includeAllExtensionTools: options.includeAllExtensionTools,
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
async reload() {
|
|
392
|
+
if (this.deps.isStreaming()) {
|
|
393
|
+
throw new Error("Cannot reload while the agent is streaming or a tool call is active");
|
|
394
|
+
}
|
|
395
|
+
if (this.deps.isCompacting()) {
|
|
396
|
+
throw new Error("Cannot reload while context compaction or branch summarization is active");
|
|
397
|
+
}
|
|
398
|
+
const previousRunner = this.deps.getExtensionRunner();
|
|
399
|
+
const snapshot = this._createReloadRuntimeSnapshot();
|
|
400
|
+
// Preserve the pre-filter tool REQUEST across the rebuild, not the capability/profile-filtered
|
|
401
|
+
// active set — otherwise a reload under a small model permanently shrinks the restorable set.
|
|
402
|
+
const activeToolNames = this.deps.getRequestedActiveToolNames() ?? this.deps.getActiveToolNames();
|
|
403
|
+
const previousFlagValues = previousRunner.getFlagValues();
|
|
404
|
+
const reloadErrors = [];
|
|
405
|
+
let newRunner;
|
|
406
|
+
try {
|
|
407
|
+
await this.deps.getSettingsManager().reload();
|
|
408
|
+
// Re-derive the resource-profile tool filter from the freshly reloaded settings.
|
|
409
|
+
// Unlike skills/prompts/themes (which re-filter through the resource loader on every
|
|
410
|
+
// reload), the tool filter is held on the session, so without this a live edit to the
|
|
411
|
+
// active profile's tools allow/block — or switching the active profile — would not
|
|
412
|
+
// apply on /reload and allowed tools would stay missing.
|
|
413
|
+
this.deps.setToolProfileFilter(this.deps.deriveToolProfileFilter());
|
|
414
|
+
// Re-apply the active profile's model/thinking from the freshly reloaded settings, so a live
|
|
415
|
+
// profile edit (or switch) takes effect on /reload. Skipped when the launch used an explicit
|
|
416
|
+
// --model/--thinking flag, which must win over the profile across reloads.
|
|
417
|
+
await this.deps.reapplyActiveProfileModelSettings();
|
|
418
|
+
await this.deps.getResourceLoader().reload({ failOnExtensionErrors: true, deferExtensionDispose: true });
|
|
419
|
+
resetApiProviders();
|
|
420
|
+
this.buildRuntime({
|
|
421
|
+
activeToolNames,
|
|
422
|
+
flagValues: previousFlagValues,
|
|
423
|
+
includeAllExtensionTools: true,
|
|
424
|
+
});
|
|
425
|
+
newRunner = this.deps.getExtensionRunner();
|
|
426
|
+
const offDoctorErrors = newRunner.onError((error) => {
|
|
427
|
+
reloadErrors.push(`${error.extensionPath} ${error.event}: ${error.error}`);
|
|
428
|
+
});
|
|
429
|
+
try {
|
|
430
|
+
this._doctorReloadRuntime();
|
|
431
|
+
// Reload starts memory providers fresh; loaded extensions re-register below.
|
|
432
|
+
this.deps.clearPendingMemoryProviders();
|
|
433
|
+
const hasBindings = this.deps.getExtensionUIContext() ||
|
|
434
|
+
this.deps.getExtensionCommandContextActions() ||
|
|
435
|
+
this.deps.getExtensionShutdownHandler() ||
|
|
436
|
+
this.deps.getExtensionErrorListener();
|
|
437
|
+
if (hasBindings) {
|
|
438
|
+
await newRunner.emit({ type: "session_start", reason: "reload" });
|
|
439
|
+
await this.deps.extendResourcesFromExtensions("reload");
|
|
440
|
+
this._doctorReloadRuntime();
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
finally {
|
|
444
|
+
offDoctorErrors();
|
|
445
|
+
}
|
|
446
|
+
if (reloadErrors.length > 0) {
|
|
447
|
+
throw new Error(`Extension reload failed doctor: ${reloadErrors.slice(0, 6).join("; ")}`);
|
|
448
|
+
}
|
|
449
|
+
await emitSessionShutdownEvent(previousRunner, { type: "session_shutdown", reason: "reload" });
|
|
450
|
+
previousRunner.invalidate();
|
|
451
|
+
this.deps.getResourceLoader().commitReload?.();
|
|
452
|
+
// Re-derive the memory subsystem from the reloaded settings/providers.
|
|
453
|
+
await this.deps.initializeMemory();
|
|
454
|
+
}
|
|
455
|
+
catch (error) {
|
|
456
|
+
if (newRunner && newRunner !== previousRunner) {
|
|
457
|
+
newRunner.invalidate("This extension ctx was discarded because reload failed and Pi restored the previous valid runtime.");
|
|
458
|
+
}
|
|
459
|
+
this.deps.getResourceLoader().rollbackReload?.();
|
|
460
|
+
this._restoreReloadRuntimeSnapshot(snapshot);
|
|
461
|
+
throw error;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* Unload a single extension without full reload.
|
|
466
|
+
* Runs the extension's session_shutdown lifecycle, unregisters its providers,
|
|
467
|
+
* disposes its event subscriptions, and rebuilds the runtime.
|
|
468
|
+
* Falls back to full reload on error.
|
|
469
|
+
*/
|
|
470
|
+
async unloadExtensionLive(extensionPath) {
|
|
471
|
+
if (this.deps.isStreaming()) {
|
|
472
|
+
throw new Error("Cannot unload extension while the agent is streaming or a tool call is active");
|
|
473
|
+
}
|
|
474
|
+
if (this.deps.isCompacting()) {
|
|
475
|
+
throw new Error("Cannot unload extension while context compaction or branch summarization is active");
|
|
476
|
+
}
|
|
477
|
+
const ext = this.deps.getResourceLoader().getLoadedExtension(extensionPath);
|
|
478
|
+
if (!ext) {
|
|
479
|
+
return; // Nothing to unload
|
|
480
|
+
}
|
|
481
|
+
const previousRunner = this.deps.getExtensionRunner();
|
|
482
|
+
try {
|
|
483
|
+
// Run session_shutdown lifecycle for this extension only
|
|
484
|
+
await this.deps.getExtensionRunner().emitToExtension(ext, { type: "session_shutdown", reason: "unload" });
|
|
485
|
+
// Unregister its providers (keyed by the extension's own path, as registered)
|
|
486
|
+
const runtime = this.deps.getResourceLoader().getExtensions().runtime;
|
|
487
|
+
for (const name of runtime.getProvidersForExtension(ext.path)) {
|
|
488
|
+
runtime.unregisterProvider(name, ext.path);
|
|
489
|
+
}
|
|
490
|
+
// Dispose its event subscriptions and run disposers
|
|
491
|
+
await disposeExtensionEventSubscriptions([ext]);
|
|
492
|
+
// Remove from loaded extensions
|
|
493
|
+
this.deps.getResourceLoader().removeLoadedExtension(extensionPath);
|
|
494
|
+
// Rebuild runtime with new extension set
|
|
495
|
+
const activeToolNames = this.deps.getRequestedActiveToolNames() ?? this.deps.getActiveToolNames();
|
|
496
|
+
const previousFlagValues = previousRunner.getFlagValues();
|
|
497
|
+
this.buildRuntime({
|
|
498
|
+
activeToolNames,
|
|
499
|
+
flagValues: previousFlagValues,
|
|
500
|
+
includeAllExtensionTools: true,
|
|
501
|
+
});
|
|
502
|
+
previousRunner.invalidate();
|
|
503
|
+
// Notify extensions-changed listeners
|
|
504
|
+
this.deps.notifyExtensionsChanged();
|
|
505
|
+
}
|
|
506
|
+
catch (error) {
|
|
507
|
+
// Fall back to full reload on error
|
|
508
|
+
try {
|
|
509
|
+
await this.reload();
|
|
510
|
+
}
|
|
511
|
+
catch {
|
|
512
|
+
// Suppress nested error; original error will be thrown below
|
|
513
|
+
}
|
|
514
|
+
throw error;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Load a single extension without full reload.
|
|
519
|
+
* Loads the extension with fresh import, rebuilds the runtime,
|
|
520
|
+
* and runs the extension's session_start lifecycle.
|
|
521
|
+
* Falls back to full reload on error.
|
|
522
|
+
*/
|
|
523
|
+
async loadExtensionLive(extensionPath) {
|
|
524
|
+
if (this.deps.isStreaming()) {
|
|
525
|
+
throw new Error("Cannot load extension while the agent is streaming or a tool call is active");
|
|
526
|
+
}
|
|
527
|
+
if (this.deps.isCompacting()) {
|
|
528
|
+
throw new Error("Cannot load extension while context compaction or branch summarization is active");
|
|
529
|
+
}
|
|
530
|
+
const previousRunner = this.deps.getExtensionRunner();
|
|
531
|
+
try {
|
|
532
|
+
// Load the extension with fresh import
|
|
533
|
+
const { extension, error } = await this.deps.getResourceLoader().loadSingleExtension(extensionPath);
|
|
534
|
+
if (error || !extension) {
|
|
535
|
+
throw new Error(error || `Failed to load extension: ${extensionPath}`);
|
|
536
|
+
}
|
|
537
|
+
// Rebuild runtime to aggregate tools/commands/handlers/providers
|
|
538
|
+
const activeToolNames = this.deps.getRequestedActiveToolNames() ?? this.deps.getActiveToolNames();
|
|
539
|
+
const previousFlagValues = previousRunner.getFlagValues();
|
|
540
|
+
this.buildRuntime({
|
|
541
|
+
activeToolNames,
|
|
542
|
+
flagValues: previousFlagValues,
|
|
543
|
+
includeAllExtensionTools: true,
|
|
544
|
+
});
|
|
545
|
+
// Run session_start lifecycle for the new extension only
|
|
546
|
+
await this.deps.getExtensionRunner().emitToExtension(extension, { type: "session_start", reason: "load" });
|
|
547
|
+
// Notify extensions-changed listeners
|
|
548
|
+
this.deps.notifyExtensionsChanged();
|
|
549
|
+
}
|
|
550
|
+
catch (error) {
|
|
551
|
+
// Fall back to full reload on error
|
|
552
|
+
try {
|
|
553
|
+
await this.reload();
|
|
554
|
+
}
|
|
555
|
+
catch {
|
|
556
|
+
// Suppress nested error; original error will be thrown below
|
|
557
|
+
}
|
|
558
|
+
throw error;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Reconcile loaded extensions with the active profile.
|
|
563
|
+
* Loads extensions that should be enabled but aren't, and unloads extensions that shouldn't be.
|
|
564
|
+
* Falls back to full reload if any individual load/unload fails.
|
|
565
|
+
*/
|
|
566
|
+
async reconcileLoadedExtensions() {
|
|
567
|
+
if (this.deps.isStreaming()) {
|
|
568
|
+
throw new Error("Cannot reconcile extensions while the agent is streaming or a tool call is active");
|
|
569
|
+
}
|
|
570
|
+
if (this.deps.isCompacting()) {
|
|
571
|
+
throw new Error("Cannot reconcile extensions while context compaction or branch summarization is active");
|
|
572
|
+
}
|
|
573
|
+
try {
|
|
574
|
+
// Get all discoverable extension paths
|
|
575
|
+
const allDiscoverablePaths = await this.deps.getResourceLoader().getDiscoverableExtensionPaths();
|
|
576
|
+
// Get the target enabled set based on profile filters
|
|
577
|
+
const targetEnabledSet = new Set();
|
|
578
|
+
for (const path of allDiscoverablePaths) {
|
|
579
|
+
if (this.deps.getSettingsManager().isResourceAllowedByProfile("extensions", path)) {
|
|
580
|
+
targetEnabledSet.add(path);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
// Get currently loaded set
|
|
584
|
+
const loadedExtensions = this.deps.getResourceLoader().getExtensions().extensions;
|
|
585
|
+
const loadedSet = new Set();
|
|
586
|
+
for (const ext of loadedExtensions) {
|
|
587
|
+
loadedSet.add(ext.path);
|
|
588
|
+
}
|
|
589
|
+
// Collect unloads and loads
|
|
590
|
+
const toUnload = [];
|
|
591
|
+
const toLoad = [];
|
|
592
|
+
for (const path of loadedSet) {
|
|
593
|
+
if (!targetEnabledSet.has(path)) {
|
|
594
|
+
toUnload.push(path);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
for (const path of targetEnabledSet) {
|
|
598
|
+
if (!loadedSet.has(path)) {
|
|
599
|
+
toLoad.push(path);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
// Apply unloads first, then loads, to minimize churn
|
|
603
|
+
// Collect errors but continue through all operations
|
|
604
|
+
const errors = [];
|
|
605
|
+
for (const path of toUnload) {
|
|
606
|
+
try {
|
|
607
|
+
await this.unloadExtensionLive(path);
|
|
608
|
+
}
|
|
609
|
+
catch (error) {
|
|
610
|
+
errors.push(error instanceof Error ? error : new Error(String(error)));
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
for (const path of toLoad) {
|
|
614
|
+
try {
|
|
615
|
+
await this.loadExtensionLive(path);
|
|
616
|
+
}
|
|
617
|
+
catch (error) {
|
|
618
|
+
errors.push(error instanceof Error ? error : new Error(String(error)));
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
// If any errors occurred, throw the first one (already fell back to full reload in load/unload)
|
|
622
|
+
if (errors.length > 0) {
|
|
623
|
+
throw errors[0];
|
|
624
|
+
}
|
|
625
|
+
// Single notification at the end
|
|
626
|
+
this.deps.notifyExtensionsChanged();
|
|
627
|
+
}
|
|
628
|
+
catch (error) {
|
|
629
|
+
// Fall back to full reload on error
|
|
630
|
+
try {
|
|
631
|
+
await this.reload();
|
|
632
|
+
}
|
|
633
|
+
catch {
|
|
634
|
+
// Suppress nested error; original error will be thrown below
|
|
635
|
+
}
|
|
636
|
+
throw error;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
//# sourceMappingURL=runtime-builder.js.map
|