@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,594 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context pipeline: the session's per-turn context-shaping subsystem — the observe-only context
|
|
3
|
+
* audit, the shadow prompt-policy plan and its correlation with legacy context-gc, the enforcement
|
|
4
|
+
* pilot, the relevance-curation queue + the fitness-gated curation model resolver / brain-curation
|
|
5
|
+
* drain + compaction pre-digest, the legacy context-gc pass and its packed-artifact reference
|
|
6
|
+
* release, the tool-output artifact store, and the current-context token estimate.
|
|
7
|
+
*
|
|
8
|
+
* Extracted verbatim from agent-session.ts (god-file decomposition). Owns the latest
|
|
9
|
+
* audit/policy/correlation/enforcement/gc reports, the {@link BrainCurator} sidecar and its last
|
|
10
|
+
* skip reasons, and the lazily-built tool-artifact store. Everything else it needs — the turn
|
|
11
|
+
* index, the session/settings managers, the model registry, agent/workspace dirs, the active tool
|
|
12
|
+
* names, the disposed flag, the isolated-completion primitive, spawned-usage accounting, and the
|
|
13
|
+
* live {@link MemoryManager} — is reached through narrow deps accessors rather than the whole
|
|
14
|
+
* AgentSession.
|
|
15
|
+
*
|
|
16
|
+
* Context-transform boundary (deliberate): the per-turn stages ({@link estimateCurrentContextTokens},
|
|
17
|
+
* {@link runContextAudit}, {@link runPromptPolicyPlanning}, {@link applyContextGc},
|
|
18
|
+
* {@link correlatePromptPolicyWithContextGc}, {@link runPromptEnforcement},
|
|
19
|
+
* {@link enqueueRelevanceCuration}, {@link maybeDrainBrainCuration}) are invoked from the session's
|
|
20
|
+
* context transform as one-line delegations, so the transform stays the single owner of the pass
|
|
21
|
+
* ordering. This controller reaches {@link MemoryController} functionality only through
|
|
22
|
+
* {@link ContextPipelineDeps.getMemoryManager} (never imports it), and MemoryController never imports
|
|
23
|
+
* the pipeline — keeping the transform the one place the two subsystems meet.
|
|
24
|
+
*/
|
|
25
|
+
import { join } from "node:path";
|
|
26
|
+
import { estimateContextTokens, getLatestCompactionEntry } from "@caupulican/pi-agent-core/node";
|
|
27
|
+
import { BrainCurator, preDigestConversationText } from "./context/brain-curator.js";
|
|
28
|
+
import { createFileArtifactStore } from "./context/context-artifacts.js";
|
|
29
|
+
import { runContextAudit } from "./context/context-audit.js";
|
|
30
|
+
import { enforcePromptPolicy } from "./context/context-prompt-enforcement.js";
|
|
31
|
+
import { correlateWithContextGc, planPromptPolicy, } from "./context/context-prompt-policy.js";
|
|
32
|
+
import { applyContextGc } from "./context-gc.js";
|
|
33
|
+
import { resolveCliModel } from "./model-resolver.js";
|
|
34
|
+
import { FitnessStore } from "./models/fitness-store.js";
|
|
35
|
+
/** Latest user prompt text in the provider-visible array (curation goal line; bounded by caller). */
|
|
36
|
+
export function latestUserPromptText(messages) {
|
|
37
|
+
for (let index = messages.length - 1; index >= 0; index--) {
|
|
38
|
+
const message = messages[index];
|
|
39
|
+
if (!message || message.role !== "user")
|
|
40
|
+
continue;
|
|
41
|
+
if (typeof message.content === "string")
|
|
42
|
+
return message.content;
|
|
43
|
+
const text = message.content
|
|
44
|
+
.filter((part) => part.type === "text")
|
|
45
|
+
.map((part) => part.text)
|
|
46
|
+
.join("\n");
|
|
47
|
+
if (text.length > 0)
|
|
48
|
+
return text;
|
|
49
|
+
}
|
|
50
|
+
return "";
|
|
51
|
+
}
|
|
52
|
+
/** Read a packed grep/find tool result's `details.artifactId`, if present, without `any`. */
|
|
53
|
+
function extractArtifactId(message) {
|
|
54
|
+
if (!message || message.role !== "toolResult")
|
|
55
|
+
return undefined;
|
|
56
|
+
const details = message.details;
|
|
57
|
+
if (typeof details !== "object" || details === null)
|
|
58
|
+
return undefined;
|
|
59
|
+
const artifactId = details.artifactId;
|
|
60
|
+
return typeof artifactId === "string" ? artifactId : undefined;
|
|
61
|
+
}
|
|
62
|
+
export class ContextPipeline {
|
|
63
|
+
_latestContextGcReport = undefined;
|
|
64
|
+
/** Brain-curation sidecar (design: brain-context-curation-design.md). Inert unless the
|
|
65
|
+
* contextPolicy.curation setting is enabled AND the model passes the digest fitness gate. */
|
|
66
|
+
_brainCurator = new BrainCurator();
|
|
67
|
+
_lastCurationSkipReason = undefined;
|
|
68
|
+
_lastPreDigestSkipReason = undefined;
|
|
69
|
+
_toolArtifactStore = undefined;
|
|
70
|
+
_latestContextAuditReport = undefined;
|
|
71
|
+
_latestPromptPolicyReport = undefined;
|
|
72
|
+
_latestPromptPolicyGcCorrelation = undefined;
|
|
73
|
+
_latestPromptEnforcementReport = undefined;
|
|
74
|
+
deps;
|
|
75
|
+
constructor(deps) {
|
|
76
|
+
this.deps = deps;
|
|
77
|
+
}
|
|
78
|
+
_contextGcStorageDir() {
|
|
79
|
+
return join(this.deps.getAgentDir(), "context-gc", this.deps.getSessionManager().getSessionId());
|
|
80
|
+
}
|
|
81
|
+
_toolArtifactsDir() {
|
|
82
|
+
return join(this.deps.getAgentDir(), "context-artifacts", this.deps.getSessionManager().getSessionId());
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Session-scoped, filesystem-backed artifact store for first-capture-then-bound tool
|
|
86
|
+
* output (grep/find only, for now -- see tool-output-artifacts.md). Lazily created and
|
|
87
|
+
* cached so every tool construction in this session shares one store instance.
|
|
88
|
+
*
|
|
89
|
+
* `packToolOutput()` registers a reference (the packing tool call's id) at pack time
|
|
90
|
+
* and fails closed, so packed artifacts are never prematurely collected.
|
|
91
|
+
* `_releaseGcPackedArtifactReferences()` (called from `applyContextGc()`) releases
|
|
92
|
+
* that reference once context-gc packs the result out of live context, and
|
|
93
|
+
* opportunistically reclaims now-unreferenced artifacts via `cleanup()`.
|
|
94
|
+
* Remaining carry-forward gap: cleanup() now also runs at dispose(), but only reclaims
|
|
95
|
+
* already-released (zero-reference) artifacts. A session that ends before context-gc
|
|
96
|
+
* ever evicts a result never releases that reference, so its artifact stays on disk by
|
|
97
|
+
* design (resolvable on resume). Reclaiming those requires an explicit cross-session
|
|
98
|
+
* expiry/liveness policy, not just a sweep.
|
|
99
|
+
*/
|
|
100
|
+
getToolArtifactStore() {
|
|
101
|
+
this._toolArtifactStore ??= createFileArtifactStore({ baseDir: this._toolArtifactsDir() });
|
|
102
|
+
return this._toolArtifactStore;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Best-effort final sweep of any already-released (zero-reference) tool-output artifact at
|
|
106
|
+
* session dispose. Reads the field (not the getter) so a session that never packed anything
|
|
107
|
+
* doesn't force-create a store/dir just to sweep it.
|
|
108
|
+
*/
|
|
109
|
+
cleanupToolArtifactStoreOnDispose() {
|
|
110
|
+
this._toolArtifactStore?.cleanup();
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* One pass over the current branch, mapping each toolResult's toolCallId to its
|
|
114
|
+
* persisted session-entry id. Rebuilt every audit pass (O(branch) per turn), so this is
|
|
115
|
+
* O(n^2) over a long session. Fine at current scale; after the artifact-read fix this is
|
|
116
|
+
* the next per-turn audit cost to optimize if it ever matters (e.g. cache/incrementally
|
|
117
|
+
* update instead of a full rebuild).
|
|
118
|
+
*/
|
|
119
|
+
_buildSessionEntryIdLookup() {
|
|
120
|
+
const map = new Map();
|
|
121
|
+
for (const entry of this.deps.getSessionManager().getBranch()) {
|
|
122
|
+
if (entry.type === "message" && entry.message.role === "toolResult") {
|
|
123
|
+
map.set(entry.message.toolCallId, entry.id);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return (toolCallId) => map.get(toolCallId);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Phase 1 observe-only audit pass (see context/context-audit.ts): converts live
|
|
130
|
+
* toolResult messages into ContextItems and runs the existing retention/hard-constraint
|
|
131
|
+
* evaluators over them, storing the latest deterministic report for tests/debugging.
|
|
132
|
+
* Read-only with respect to messages, the transcript, and artifact references -- uses
|
|
133
|
+
* `_toolArtifactStore` (the field), not `getToolArtifactStore()` (the getter), so a
|
|
134
|
+
* session that never packed anything doesn't force-create a store/dir just to audit.
|
|
135
|
+
* Never throws into a live turn: any failure degrades to an empty report.
|
|
136
|
+
*/
|
|
137
|
+
runContextAudit(messages) {
|
|
138
|
+
try {
|
|
139
|
+
const report = runContextAudit(messages, {
|
|
140
|
+
turnIndex: this.deps.getTurnIndex(),
|
|
141
|
+
artifactStore: this._toolArtifactStore,
|
|
142
|
+
sessionEntryIdForToolCallId: this._buildSessionEntryIdLookup(),
|
|
143
|
+
});
|
|
144
|
+
this._latestContextAuditReport = report;
|
|
145
|
+
return report;
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
const report = { turnIndex: this.deps.getTurnIndex(), items: [] };
|
|
149
|
+
this._latestContextAuditReport = report;
|
|
150
|
+
return report;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Read-only inspection of the context audit. With `messages`, recomputes fresh against
|
|
155
|
+
* the given array (still no mutation of messages/transcript/artifact refs); without,
|
|
156
|
+
* returns the last report computed during a real transform pass.
|
|
157
|
+
*/
|
|
158
|
+
getContextAuditReport(messages) {
|
|
159
|
+
if (messages)
|
|
160
|
+
return this.runContextAudit(messages);
|
|
161
|
+
return this._latestContextAuditReport ?? { turnIndex: this.deps.getTurnIndex(), items: [] };
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Observe-first shadow/planning pass (see context/context-prompt-policy.ts): re-shapes
|
|
165
|
+
* the audit report into a per-item policy plan whose `appliedAction` is always
|
|
166
|
+
* "keep_raw" -- this never enforces anything, it only records what the policy engine
|
|
167
|
+
* would say. Never throws into a live turn: any failure degrades to an empty report.
|
|
168
|
+
*/
|
|
169
|
+
runPromptPolicyPlanning(auditReport) {
|
|
170
|
+
try {
|
|
171
|
+
const report = planPromptPolicy(auditReport);
|
|
172
|
+
this._latestPromptPolicyReport = report;
|
|
173
|
+
return report;
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
const report = { turnIndex: this.deps.getTurnIndex(), items: [] };
|
|
177
|
+
this._latestPromptPolicyReport = report;
|
|
178
|
+
return report;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Read-only inspection of the shadow policy plan. With `messages`, recomputes fresh
|
|
183
|
+
* (audit + plan) against the given array; without, returns the last plan computed
|
|
184
|
+
* during a real transform pass. Never mutates messages/transcript/artifact refs.
|
|
185
|
+
*/
|
|
186
|
+
getPromptPolicyReport(messages) {
|
|
187
|
+
if (messages)
|
|
188
|
+
return this.runPromptPolicyPlanning(this.runContextAudit(messages));
|
|
189
|
+
return this._latestPromptPolicyReport ?? { turnIndex: this.deps.getTurnIndex(), items: [] };
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Report-only correlation between the shadow plan just computed this turn and what the
|
|
193
|
+
* legacy context-gc pass actually packed. Runs after `applyContextGc()` has already
|
|
194
|
+
* produced its report; never influences context-gc itself. Never throws into a live
|
|
195
|
+
* turn: any failure degrades to an empty correlation.
|
|
196
|
+
*/
|
|
197
|
+
correlatePromptPolicyWithContextGc(gcReport) {
|
|
198
|
+
const shadowReport = this._latestPromptPolicyReport ?? { turnIndex: this.deps.getTurnIndex(), items: [] };
|
|
199
|
+
try {
|
|
200
|
+
this._latestPromptPolicyGcCorrelation = correlateWithContextGc(shadowReport, gcReport);
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
this._latestPromptPolicyGcCorrelation = { turnIndex: this.deps.getTurnIndex(), entries: [] };
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/** Read-only inspection of the latest shadow-plan/legacy-gc correlation, for tests/debugging. */
|
|
207
|
+
getPromptPolicyGcCorrelation() {
|
|
208
|
+
return this._latestPromptPolicyGcCorrelation ?? { turnIndex: this.deps.getTurnIndex(), entries: [] };
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* First enforcement pilot (see context/context-prompt-enforcement.ts): opt-in,
|
|
212
|
+
* default-disabled stub-in-place of stale artifact-backed tool_output results in the
|
|
213
|
+
* provider-visible message array only. Runs on `messages` AFTER context-gc has already
|
|
214
|
+
* produced its own result, so legacy context-gc's own packing/reporting is completely
|
|
215
|
+
* unaffected by this pass -- it only ever acts on messages gc left untouched this turn.
|
|
216
|
+
* Never throws into a live turn: any failure degrades to returning `messages` unchanged.
|
|
217
|
+
*/
|
|
218
|
+
runPromptEnforcement(messages, shadowReport) {
|
|
219
|
+
try {
|
|
220
|
+
const persistedSettings = this.deps.getSettingsManager().getContextPromptEnforcementSettings();
|
|
221
|
+
const curationEnabled = this.deps.getSettingsManager().getContextCurationSettings().enabled;
|
|
222
|
+
const settings = {
|
|
223
|
+
...persistedSettings,
|
|
224
|
+
// Runtime fact, never assumed: artifact_retrieve is a companion affordance
|
|
225
|
+
// (auto-activated alongside grep/find), not a default/global tool, so active
|
|
226
|
+
// tools can differ turn to turn -- see context-prompt-enforcement.ts's doc
|
|
227
|
+
// comment on why this is checked separately from hasAvailableRetrievalPath.
|
|
228
|
+
retrievalToolAvailable: this.deps.getActiveToolNames().includes("artifact_retrieve"),
|
|
229
|
+
brainRelevance: curationEnabled ? (itemId) => this._brainCurator.getRelevance(itemId) : undefined,
|
|
230
|
+
};
|
|
231
|
+
const result = enforcePromptPolicy(messages, shadowReport, settings);
|
|
232
|
+
this._latestPromptEnforcementReport = result.report;
|
|
233
|
+
return result;
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
const report = { turnIndex: this.deps.getTurnIndex(), items: [] };
|
|
237
|
+
this._latestPromptEnforcementReport = report;
|
|
238
|
+
return { messages, report };
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Enqueue relevance-scoring jobs for stale, artifact-backed tool outputs the enforcement
|
|
243
|
+
* pilot could act on. Pure queueing — the verdicts only ever take effect through the
|
|
244
|
+
* asymmetric advisory lever inside enforcePromptPolicy. Never throws into a turn.
|
|
245
|
+
*/
|
|
246
|
+
enqueueRelevanceCuration(messages, shadowReport) {
|
|
247
|
+
try {
|
|
248
|
+
const settings = this.deps.getSettingsManager().getContextCurationSettings();
|
|
249
|
+
if (!settings.enabled)
|
|
250
|
+
return;
|
|
251
|
+
const goal = latestUserPromptText(messages).slice(0, 400);
|
|
252
|
+
for (const item of shadowReport.items) {
|
|
253
|
+
if (!item.hasAvailableRetrievalPath)
|
|
254
|
+
continue;
|
|
255
|
+
const message = messages[item.messageIndex];
|
|
256
|
+
if (!message || message.role !== "toolResult" || message.toolCallId !== item.toolCallId)
|
|
257
|
+
continue;
|
|
258
|
+
if (message.isError)
|
|
259
|
+
continue;
|
|
260
|
+
const details = message.details;
|
|
261
|
+
if (details?.contextGc?.packed === true || details?.promptPolicy?.enforced === true)
|
|
262
|
+
continue;
|
|
263
|
+
const text = message.content
|
|
264
|
+
.filter((part) => part.type === "text")
|
|
265
|
+
.map((part) => part.text)
|
|
266
|
+
.join("\n");
|
|
267
|
+
if (text.length === 0)
|
|
268
|
+
continue;
|
|
269
|
+
this._brainCurator.enqueue({ kind: "relevance", key: item.itemId, content: text.slice(0, 4000), goal });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
// curation is a sidecar; it must never disrupt a turn
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Drain gate: settings on, model configured+authed, and the model has PASSED the digest
|
|
278
|
+
* fitness probe on THIS host (design: unfit or unprobed models are refused with a visible
|
|
279
|
+
* reason, never silently degraded). Fire-and-forget; never throws into a turn.
|
|
280
|
+
*/
|
|
281
|
+
/**
|
|
282
|
+
* Resolve the curation model IFF every gate passes: setting enabled, model configured,
|
|
283
|
+
* resolvable+authed, and digest-fitness-proven on THIS host (canonical "provider/id" ref —
|
|
284
|
+
* runModelFitness stores reports under it, while settings.model may be a bare id or pattern).
|
|
285
|
+
* Sets _lastCurationSkipReason on refusal; never throws.
|
|
286
|
+
*/
|
|
287
|
+
resolveCurationModelIfFit() {
|
|
288
|
+
const settings = this.deps.getSettingsManager().getContextCurationSettings();
|
|
289
|
+
if (!settings.enabled) {
|
|
290
|
+
// Never surface a stale refusal reason for a feature the user has since disabled.
|
|
291
|
+
this._lastCurationSkipReason = undefined;
|
|
292
|
+
return undefined;
|
|
293
|
+
}
|
|
294
|
+
if (!settings.model) {
|
|
295
|
+
this._lastCurationSkipReason = "curation_model_unset";
|
|
296
|
+
return undefined;
|
|
297
|
+
}
|
|
298
|
+
const resolved = resolveCliModel({ cliModel: settings.model, modelRegistry: this.deps.getModelRegistry() });
|
|
299
|
+
if (!resolved.model || !this.deps.getModelRegistry().hasConfiguredAuth(resolved.model)) {
|
|
300
|
+
this._lastCurationSkipReason = "curation_model_unresolved";
|
|
301
|
+
return undefined;
|
|
302
|
+
}
|
|
303
|
+
const canonicalRef = `${resolved.model.provider}/${resolved.model.id}`;
|
|
304
|
+
const fitness = FitnessStore.forAgentDir(this.deps.getAgentDir())
|
|
305
|
+
.getForHost()
|
|
306
|
+
.find((entry) => entry.model === canonicalRef);
|
|
307
|
+
const digestScore = fitness?.report.digest;
|
|
308
|
+
if (!digestScore) {
|
|
309
|
+
this._lastCurationSkipReason = "curation_model_unprobed";
|
|
310
|
+
return undefined;
|
|
311
|
+
}
|
|
312
|
+
if (digestScore.succeeded < Math.ceil(digestScore.total * (2 / 3))) {
|
|
313
|
+
this._lastCurationSkipReason = "curation_model_digest_unfit";
|
|
314
|
+
return undefined;
|
|
315
|
+
}
|
|
316
|
+
this._lastCurationSkipReason = undefined;
|
|
317
|
+
return resolved.model;
|
|
318
|
+
}
|
|
319
|
+
maybeDrainBrainCuration() {
|
|
320
|
+
try {
|
|
321
|
+
if (!this._brainCurator.hasWork() || this._brainCurator.isDraining)
|
|
322
|
+
return;
|
|
323
|
+
const model = this.resolveCurationModelIfFit();
|
|
324
|
+
if (!model)
|
|
325
|
+
return;
|
|
326
|
+
const settings = this.deps.getSettingsManager().getContextCurationSettings();
|
|
327
|
+
void this._drainBrainCuration(model, settings.maxJobsPerTurn);
|
|
328
|
+
}
|
|
329
|
+
catch {
|
|
330
|
+
// curation is a sidecar; it must never disrupt a turn
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Compaction pre-digest gate (design surface 3): everything the drain gate requires PLUS a
|
|
335
|
+
* RUNTIME reliability proof — the curator must have run >=5 jobs on this session with a parse
|
|
336
|
+
* failure rate <=5% before it is trusted to pre-digest compaction input. Returns undefined
|
|
337
|
+
* (verbatim compaction, byte-for-byte today's behavior) whenever any gate refuses.
|
|
338
|
+
*/
|
|
339
|
+
buildCompactionPreDigest() {
|
|
340
|
+
try {
|
|
341
|
+
const model = this.resolveCurationModelIfFit();
|
|
342
|
+
if (!model)
|
|
343
|
+
return undefined;
|
|
344
|
+
const telemetry = this._brainCurator.telemetry();
|
|
345
|
+
if (telemetry.jobsRun < 5 || telemetry.parseFailures / telemetry.jobsRun > 0.05) {
|
|
346
|
+
this._lastPreDigestSkipReason = "curation_predigest_reliability_unproven";
|
|
347
|
+
return undefined;
|
|
348
|
+
}
|
|
349
|
+
this._lastPreDigestSkipReason = undefined;
|
|
350
|
+
return async (text, signal) => {
|
|
351
|
+
const result = await preDigestConversationText({
|
|
352
|
+
text,
|
|
353
|
+
signal,
|
|
354
|
+
complete: async ({ systemPrompt, userPrompt, signal: chunkSignal }) => {
|
|
355
|
+
const completion = await this.deps.runIsolatedCompletion({
|
|
356
|
+
systemPrompt,
|
|
357
|
+
messages: [{ role: "user", content: [{ type: "text", text: userPrompt }], timestamp: Date.now() }],
|
|
358
|
+
model,
|
|
359
|
+
thinkingLevel: "off",
|
|
360
|
+
maxTokens: 512,
|
|
361
|
+
signal: chunkSignal,
|
|
362
|
+
cacheRetention: "short",
|
|
363
|
+
});
|
|
364
|
+
return {
|
|
365
|
+
text: completion.text,
|
|
366
|
+
costUsd: completion.usage.cost.total,
|
|
367
|
+
stopReason: String(completion.stopReason),
|
|
368
|
+
};
|
|
369
|
+
},
|
|
370
|
+
});
|
|
371
|
+
if (!this.deps.isDisposed() && result.totalChunks > 0) {
|
|
372
|
+
this.deps.getSessionManager().appendCustomEntry("brain-curation-predigest", {
|
|
373
|
+
version: 1,
|
|
374
|
+
totalChunks: result.totalChunks,
|
|
375
|
+
digested: result.digested,
|
|
376
|
+
failed: result.failed,
|
|
377
|
+
charsBefore: text.length,
|
|
378
|
+
charsAfter: result.text.length,
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
return result.text;
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
catch {
|
|
385
|
+
return undefined;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
async _drainBrainCuration(model, maxJobs) {
|
|
389
|
+
try {
|
|
390
|
+
// ACCUMULATE across all drained jobs (the drain runs the completer once PER job) —
|
|
391
|
+
// keeping only the last job's usage would under-report every multi-job drain.
|
|
392
|
+
let spentUsage;
|
|
393
|
+
const results = await this._brainCurator.drain({
|
|
394
|
+
maxJobs,
|
|
395
|
+
complete: async ({ systemPrompt, userPrompt, signal }) => {
|
|
396
|
+
const completion = await this.deps.runIsolatedCompletion({
|
|
397
|
+
systemPrompt,
|
|
398
|
+
messages: [{ role: "user", content: [{ type: "text", text: userPrompt }], timestamp: Date.now() }],
|
|
399
|
+
model,
|
|
400
|
+
thinkingLevel: "off",
|
|
401
|
+
maxTokens: 256,
|
|
402
|
+
signal,
|
|
403
|
+
// Both curation system prompts are static — the provider can cache the prefix.
|
|
404
|
+
cacheRetention: "short",
|
|
405
|
+
});
|
|
406
|
+
const usage = completion.usage;
|
|
407
|
+
if (!spentUsage) {
|
|
408
|
+
spentUsage = structuredClone(usage);
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
spentUsage.input += usage.input;
|
|
412
|
+
spentUsage.output += usage.output;
|
|
413
|
+
spentUsage.cacheRead += usage.cacheRead;
|
|
414
|
+
spentUsage.cacheWrite += usage.cacheWrite;
|
|
415
|
+
spentUsage.totalTokens += usage.totalTokens;
|
|
416
|
+
spentUsage.cost.input += usage.cost.input;
|
|
417
|
+
spentUsage.cost.output += usage.cost.output;
|
|
418
|
+
spentUsage.cost.cacheRead += usage.cost.cacheRead;
|
|
419
|
+
spentUsage.cost.cacheWrite += usage.cost.cacheWrite;
|
|
420
|
+
spentUsage.cost.total += usage.cost.total;
|
|
421
|
+
}
|
|
422
|
+
return {
|
|
423
|
+
text: completion.text,
|
|
424
|
+
costUsd: completion.usage.cost.total,
|
|
425
|
+
stopReason: String(completion.stopReason),
|
|
426
|
+
};
|
|
427
|
+
},
|
|
428
|
+
});
|
|
429
|
+
// Honest accounting even for free local models: token visibility is the contract.
|
|
430
|
+
if (spentUsage && (spentUsage.cost.total > 0 || spentUsage.totalTokens > 0)) {
|
|
431
|
+
this.deps.addSpawnedUsage(spentUsage, { label: "context-curator" });
|
|
432
|
+
}
|
|
433
|
+
if (this.deps.isDisposed() || results.length === 0)
|
|
434
|
+
return;
|
|
435
|
+
this.deps.getSessionManager().appendCustomEntry("brain-curation", {
|
|
436
|
+
version: 1,
|
|
437
|
+
results: results.map((result) => ({
|
|
438
|
+
key: result.key,
|
|
439
|
+
kind: result.kind,
|
|
440
|
+
ok: result.ok,
|
|
441
|
+
ms: result.ms,
|
|
442
|
+
...(result.digest !== undefined ? { digest: result.digest } : {}),
|
|
443
|
+
...(result.relevant !== undefined ? { relevant: result.relevant, confidence: result.confidence } : {}),
|
|
444
|
+
})),
|
|
445
|
+
telemetry: this._brainCurator.telemetry(),
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
catch {
|
|
449
|
+
// curation is a sidecar; it must never disrupt a turn
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
/** Curation status for diagnostics/dashboard: settings, live telemetry, last refusal reason. */
|
|
453
|
+
getContextCurationStatus() {
|
|
454
|
+
const settings = this.deps.getSettingsManager().getContextCurationSettings();
|
|
455
|
+
return {
|
|
456
|
+
enabled: settings.enabled,
|
|
457
|
+
model: settings.model,
|
|
458
|
+
telemetry: this._brainCurator.telemetry(),
|
|
459
|
+
lastSkipReason: this._lastCurationSkipReason,
|
|
460
|
+
lastPreDigestSkipReason: this._lastPreDigestSkipReason,
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
/** Read-only inspection of the latest prompt-enforcement report, for tests/debugging. */
|
|
464
|
+
getPromptEnforcementReport() {
|
|
465
|
+
return this._latestPromptEnforcementReport ?? { turnIndex: this.deps.getTurnIndex(), items: [] };
|
|
466
|
+
}
|
|
467
|
+
applyContextGc(messages, writePayloads) {
|
|
468
|
+
try {
|
|
469
|
+
const settings = this.deps.getSettingsManager().getContextGcSettings();
|
|
470
|
+
// Merge the ACTIVE memory providers' own page markers (e.g. transcript-recall's
|
|
471
|
+
// "<memory_context") into the semantic-memory marker list. The settings default is
|
|
472
|
+
// provider-agnostic and non-empty, so without this merge the recall pages the bundled
|
|
473
|
+
// default provider actually emits are never recognized as semantic-memory pages and
|
|
474
|
+
// accumulate raw for the life of the session — the exact growth Bug #7 GC exists to stop.
|
|
475
|
+
const providerMarkers = this.deps.getMemoryManager().getContextMarkers();
|
|
476
|
+
const curationSettings = this.deps.getSettingsManager().getContextCurationSettings();
|
|
477
|
+
const result = applyContextGc(messages, {
|
|
478
|
+
...settings,
|
|
479
|
+
semanticMemory: {
|
|
480
|
+
...settings.semanticMemory,
|
|
481
|
+
markers: [...new Set([...settings.semanticMemory.markers, ...providerMarkers])],
|
|
482
|
+
},
|
|
483
|
+
cwd: this.deps.getCwd(),
|
|
484
|
+
storageDir: this._contextGcStorageDir(),
|
|
485
|
+
writePayloads,
|
|
486
|
+
curation: curationSettings.enabled
|
|
487
|
+
? {
|
|
488
|
+
resolveDigest: (digestKey) => {
|
|
489
|
+
const digest = this._brainCurator.getDigest(digestKey);
|
|
490
|
+
// Count serves on the REAL per-turn pass only, never the report path.
|
|
491
|
+
if (digest !== undefined && writePayloads)
|
|
492
|
+
this._brainCurator.noteDigestServed();
|
|
493
|
+
return digest;
|
|
494
|
+
},
|
|
495
|
+
// Only the real per-turn pass enqueues work; the read-only report path
|
|
496
|
+
// (writePayloads=false) stays side-effect free.
|
|
497
|
+
onPacked: writePayloads
|
|
498
|
+
? (record, originalText) => {
|
|
499
|
+
this._brainCurator.enqueue({
|
|
500
|
+
kind: "stub_digest",
|
|
501
|
+
key: record.key ?? record.toolCallId,
|
|
502
|
+
content: originalText,
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
: undefined,
|
|
506
|
+
}
|
|
507
|
+
: undefined,
|
|
508
|
+
});
|
|
509
|
+
this._latestContextGcReport = result.report;
|
|
510
|
+
// Only release/reclaim on the real per-turn pass (writePayloads=true), never on
|
|
511
|
+
// the read-only status-report path (getContextGcReport with writePayloads=false),
|
|
512
|
+
// so merely inspecting the report can't have side effects.
|
|
513
|
+
if (writePayloads && result.report.packedCount > 0) {
|
|
514
|
+
this._releaseGcPackedArtifactReferences(messages, result.report);
|
|
515
|
+
}
|
|
516
|
+
return result;
|
|
517
|
+
}
|
|
518
|
+
catch {
|
|
519
|
+
const report = {
|
|
520
|
+
enabled: false,
|
|
521
|
+
packedCount: 0,
|
|
522
|
+
originalTokens: 0,
|
|
523
|
+
packedTokens: 0,
|
|
524
|
+
savedTokens: 0,
|
|
525
|
+
records: [],
|
|
526
|
+
};
|
|
527
|
+
this._latestContextGcReport = report;
|
|
528
|
+
return { messages, report };
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Reference-release + cleanup lifecycle: once context-gc has packed a grep/find tool
|
|
533
|
+
* result out of the live prompt (the message is no longer current/active working
|
|
534
|
+
* context -- see contracts-and-retention.md's "ephemeral"/"expired" retention
|
|
535
|
+
* classes), release the pack-time reference `packToolOutput()` registered for it, and
|
|
536
|
+
* opportunistically reclaim now-unreferenced artifacts. This is the other half of the
|
|
537
|
+
* D2b-1 gate: artifacts were being registered but never released, so they accumulated
|
|
538
|
+
* for the life of the session.
|
|
539
|
+
*
|
|
540
|
+
* `record.toolCallId` (from context-gc's packed record) is exactly the holder id
|
|
541
|
+
* `packToolOutput()` used when it called `addReference()` -- both trace back to the
|
|
542
|
+
* same tool call's id -- so no separate bookkeeping is needed to find it.
|
|
543
|
+
*/
|
|
544
|
+
_releaseGcPackedArtifactReferences(messages, report) {
|
|
545
|
+
const store = this._toolArtifactStore;
|
|
546
|
+
if (!store)
|
|
547
|
+
return; // no store was ever constructed, so nothing could have been packed to one
|
|
548
|
+
let releasedAny = false;
|
|
549
|
+
for (const record of report.records) {
|
|
550
|
+
if (record.toolName !== "grep" && record.toolName !== "find")
|
|
551
|
+
continue;
|
|
552
|
+
const artifactId = extractArtifactId(messages[record.messageIndex]);
|
|
553
|
+
if (!artifactId)
|
|
554
|
+
continue;
|
|
555
|
+
if (store.removeReference(artifactId, record.toolCallId))
|
|
556
|
+
releasedAny = true;
|
|
557
|
+
}
|
|
558
|
+
// Cleanup only runs immediately after a release actually happened in this pass, so
|
|
559
|
+
// a long session doesn't re-scan the artifact directory on every turn once nothing
|
|
560
|
+
// new became eligible for release.
|
|
561
|
+
if (releasedAny)
|
|
562
|
+
store.cleanup();
|
|
563
|
+
}
|
|
564
|
+
getContextGcReport(messages) {
|
|
565
|
+
if (messages)
|
|
566
|
+
return this.applyContextGc(messages, false).report;
|
|
567
|
+
return (this._latestContextGcReport ?? {
|
|
568
|
+
enabled: this.deps.getSettingsManager().getContextGcSettings().enabled,
|
|
569
|
+
packedCount: 0,
|
|
570
|
+
originalTokens: 0,
|
|
571
|
+
packedTokens: 0,
|
|
572
|
+
savedTokens: 0,
|
|
573
|
+
records: [],
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
estimateCurrentContextTokens(messages) {
|
|
577
|
+
const estimate = estimateContextTokens(messages);
|
|
578
|
+
const compactionEntry = getLatestCompactionEntry(this.deps.getSessionManager().getBranch());
|
|
579
|
+
if (estimate.lastUsageIndex === null || !compactionEntry) {
|
|
580
|
+
return estimate.tokens;
|
|
581
|
+
}
|
|
582
|
+
const usageMessage = messages[estimate.lastUsageIndex];
|
|
583
|
+
if (usageMessage?.role !== "assistant") {
|
|
584
|
+
return estimate.tokens;
|
|
585
|
+
}
|
|
586
|
+
const usageTimestamp = usageMessage.timestamp;
|
|
587
|
+
const compactionTimestamp = new Date(compactionEntry.timestamp).getTime();
|
|
588
|
+
if (usageTimestamp <= compactionTimestamp) {
|
|
589
|
+
return estimate.trailingTokens;
|
|
590
|
+
}
|
|
591
|
+
return estimate.tokens;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
//# sourceMappingURL=context-pipeline.js.map
|