@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SessionEntry, SessionManager } from "
|
|
1
|
+
import type { SessionEntry, SessionManager } from "@caupulican/pi-agent-core/node";
|
|
2
2
|
import { type LaneRecord } from "./lane-tracker.ts";
|
|
3
3
|
export declare const LANE_RECORD_CUSTOM_TYPE = "lane_record";
|
|
4
4
|
export interface LaneRecordSnapshotPayload {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-lane-record.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/session-lane-record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"session-lane-record.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/session-lane-record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AACnF,OAAO,EAA2C,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE7F,eAAO,MAAM,uBAAuB,gBAAgB,CAAC;AAErD,MAAM,WAAW,yBAAyB;IACzC,OAAO,EAAE,CAAC,CAAC;IACX,MAAM,EAAE,UAAU,CAAC;CACnB;AAED,wBAAgB,wBAAwB,CACvC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,MAAM,EAAE,UAAU,GAChB,MAAM,CAMR;AAQD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,UAAU,EAAE,CAmBrF","sourcesContent":["import type { SessionEntry, SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport { cloneLaneRecordForStorage, isLaneRecord, type LaneRecord } from \"./lane-tracker.ts\";\n\nexport const LANE_RECORD_CUSTOM_TYPE = \"lane_record\";\n\nexport interface LaneRecordSnapshotPayload {\n\tversion: 1;\n\trecord: LaneRecord;\n}\n\nexport function appendLaneRecordSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\trecord: LaneRecord,\n): string {\n\tconst payload: LaneRecordSnapshotPayload = {\n\t\tversion: 1,\n\t\trecord: cloneLaneRecordForStorage(record),\n\t};\n\treturn sessionManager.appendCustomEntry(LANE_RECORD_CUSTOM_TYPE, payload);\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nexport function getLaneRecordSnapshots(entries: readonly SessionEntry[]): LaneRecord[] {\n\tconst records: LaneRecord[] = [];\n\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"custom\" || entry.customType !== LANE_RECORD_CUSTOM_TYPE) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst payload = entry.data;\n\t\tif (!isPlainRecord(payload)) continue;\n\t\tif (payload.version !== 1) continue;\n\t\tif (!(\"record\" in payload)) continue;\n\t\tconst record = payload.record;\n\t\tif (isLaneRecord(record)) {\n\t\t\trecords.push(cloneLaneRecordForStorage(record));\n\t\t}\n\t}\n\n\treturn records;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-lane-record.js","sourceRoot":"","sources":["../../../src/core/autonomy/session-lane-record.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,YAAY,EAAmB,MAAM,mBAAmB,CAAC;AAE7F,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAAC;AAOrD,MAAM,UAAU,wBAAwB,CACvC,cAAyD,EACzD,MAAkB,EACT;IACT,MAAM,OAAO,GAA8B;QAC1C,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,yBAAyB,CAAC,MAAM,CAAC;KACzC,CAAC;IACF,OAAO,cAAc,CAAC,iBAAiB,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;AAAA,CAC1E;AAED,SAAS,aAAa,CAAC,KAAc,EAAoC;IACxE,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9E,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/C,OAAO,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI,CAAC;AAAA,CAC5D;AAED,MAAM,UAAU,sBAAsB,CAAC,OAAgC,EAAgB;IACtF,MAAM,OAAO,GAAiB,EAAE,CAAC;IAEjC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,KAAK,uBAAuB,EAAE,CAAC;YAC7E,SAAS;QACV,CAAC;QAED,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC;QAC3B,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;YAAE,SAAS;QACtC,IAAI,OAAO,CAAC,OAAO,KAAK,CAAC;YAAE,SAAS;QACpC,IAAI,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC;YAAE,SAAS;QACrC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9B,IAAI,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC;QACjD,CAAC;IACF,CAAC;IAED,OAAO,OAAO,CAAC;AAAA,CACf","sourcesContent":["import type { SessionEntry, SessionManager } from \"
|
|
1
|
+
{"version":3,"file":"session-lane-record.js","sourceRoot":"","sources":["../../../src/core/autonomy/session-lane-record.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,YAAY,EAAmB,MAAM,mBAAmB,CAAC;AAE7F,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAAC;AAOrD,MAAM,UAAU,wBAAwB,CACvC,cAAyD,EACzD,MAAkB,EACT;IACT,MAAM,OAAO,GAA8B;QAC1C,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,yBAAyB,CAAC,MAAM,CAAC;KACzC,CAAC;IACF,OAAO,cAAc,CAAC,iBAAiB,CAAC,uBAAuB,EAAE,OAAO,CAAC,CAAC;AAAA,CAC1E;AAED,SAAS,aAAa,CAAC,KAAc,EAAoC;IACxE,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9E,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/C,OAAO,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI,CAAC;AAAA,CAC5D;AAED,MAAM,UAAU,sBAAsB,CAAC,OAAgC,EAAgB;IACtF,MAAM,OAAO,GAAiB,EAAE,CAAC;IAEjC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,KAAK,uBAAuB,EAAE,CAAC;YAC7E,SAAS;QACV,CAAC;QAED,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC;QAC3B,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;YAAE,SAAS;QACtC,IAAI,OAAO,CAAC,OAAO,KAAK,CAAC;YAAE,SAAS;QACpC,IAAI,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC;YAAE,SAAS;QACrC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9B,IAAI,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAAC;QACjD,CAAC;IACF,CAAC;IAED,OAAO,OAAO,CAAC;AAAA,CACf","sourcesContent":["import type { SessionEntry, SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport { cloneLaneRecordForStorage, isLaneRecord, type LaneRecord } from \"./lane-tracker.ts\";\n\nexport const LANE_RECORD_CUSTOM_TYPE = \"lane_record\";\n\nexport interface LaneRecordSnapshotPayload {\n\tversion: 1;\n\trecord: LaneRecord;\n}\n\nexport function appendLaneRecordSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\trecord: LaneRecord,\n): string {\n\tconst payload: LaneRecordSnapshotPayload = {\n\t\tversion: 1,\n\t\trecord: cloneLaneRecordForStorage(record),\n\t};\n\treturn sessionManager.appendCustomEntry(LANE_RECORD_CUSTOM_TYPE, payload);\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nexport function getLaneRecordSnapshots(entries: readonly SessionEntry[]): LaneRecord[] {\n\tconst records: LaneRecord[] = [];\n\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"custom\" || entry.customType !== LANE_RECORD_CUSTOM_TYPE) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst payload = entry.data;\n\t\tif (!isPlainRecord(payload)) continue;\n\t\tif (payload.version !== 1) continue;\n\t\tif (!(\"record\" in payload)) continue;\n\t\tconst record = payload.record;\n\t\tif (isLaneRecord(record)) {\n\t\t\trecords.push(cloneLaneRecordForStorage(record));\n\t\t}\n\t}\n\n\treturn records;\n}\n"]}
|
|
@@ -45,6 +45,7 @@ export interface AutonomyDiagnosticSnapshot {
|
|
|
45
45
|
delegation?: readonly DiagnosticEntry[];
|
|
46
46
|
learning?: readonly DiagnosticEntry[];
|
|
47
47
|
goals?: readonly DiagnosticEntry[];
|
|
48
|
+
processMemory?: readonly DiagnosticEntry[];
|
|
48
49
|
}
|
|
49
50
|
export declare function formatAutonomyStatus(args: AutonomyStatusSnapshot): string;
|
|
50
51
|
export declare function formatAutonomyDiagnostics(args: AutonomyDiagnosticSnapshot): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEtD,MAAM,WAAW,sBAAsB;IACtC,WAAW,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAClE,UAAU,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IACnE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CA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BAAgB,oBAAoB,CAAC,IAAI,EAAE,sBAAsB,GAAG,MAAM,CAuCzE;AAsBD,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,0BAA0B,GAAG,MAAM,CAclF","sourcesContent":["import type { GateOutcomeKind } from \"./contracts.ts\";\n\nexport interface AutonomyStatusSnapshot {\n\tlatestRoute?: { tier: string; reasonCode: string; risk?: string };\n\tlatestGate?: { outcome: string; gate: string; reasonCode: string };\n\tcurrentCostUsd?: number;\n\tdailyCostUsd?: number;\n\tspawnedCostUsd?: number;\n\tactiveGoal?: { goalId: string; status: string; openRequirements?: number; stallTurns?: number };\n\tactiveLaneCount?: number;\n}\n\n/**\n * One bounded entry in AgentSession's gate-outcome history (G8). Codes/ids only — never the gate's\n * human-facing `message`. The most recent entry is the tail; `at` is an ISO timestamp.\n */\nexport interface GateOutcomeHistoryEntry {\n\toutcome: GateOutcomeKind;\n\tgate: string;\n\treasonCode: string;\n\tat: string;\n}\n\nexport interface DiagnosticEntry {\n\ttitle: string;\n\tsummary?: string;\n\treasonCode?: string;\n\tmetadata?: Record<string, unknown>;\n}\n\nexport interface AutonomyDiagnosticSnapshot {\n\troutes?: readonly DiagnosticEntry[];\n\tgates?: readonly DiagnosticEntry[];\n\tcosts?: readonly DiagnosticEntry[];\n\tresearch?: readonly DiagnosticEntry[];\n\tdelegation?: readonly DiagnosticEntry[];\n\tlearning?: readonly DiagnosticEntry[];\n\tgoals?: readonly DiagnosticEntry[];\n\tprocessMemory?: readonly DiagnosticEntry[];\n}\n\nconst REDACTED = \"[REDACTED]\";\nconst CIRCULAR = \"[Circular]\";\nconst MAX_STRING_LENGTH = 200;\nconst SENSITIVE_KEYS = [\"token\", \"secret\", \"key\", \"credential\", \"password\", \"authorization\"];\nconst SENSITIVE_VALUE_REGEX = /bearer\\s+[\\w\\-._]+|api[-_]?key[-_]?[\\w\\-._]+|sk-[\\w\\-._]+/i;\n\nfunction formatCost(value: number): string {\n\treturn Number.isFinite(value) ? `$${value.toFixed(4)}` : \"$0.0000\";\n}\n\nfunction redactAndTruncateString(value: string): string {\n\tif (SENSITIVE_VALUE_REGEX.test(value)) return REDACTED;\n\tif (value.length <= MAX_STRING_LENGTH) return value;\n\treturn `${value.slice(0, MAX_STRING_LENGTH - 1)}…`;\n}\n\nfunction isSensitiveKey(key: string): boolean {\n\tconst lowerKey = key.toLowerCase();\n\treturn SENSITIVE_KEYS.some((sensitiveKey) => lowerKey.includes(sensitiveKey));\n}\n\nfunction sanitizeMetadataValue(value: unknown, seen: WeakSet<object>): unknown {\n\tif (typeof value === \"string\") return redactAndTruncateString(value);\n\tif (typeof value !== \"object\" || value === null) return value;\n\tif (seen.has(value)) return CIRCULAR;\n\tif (Array.isArray(value)) {\n\t\tseen.add(value);\n\t\treturn value.map((item) => sanitizeMetadataValue(item, seen));\n\t}\n\treturn sanitizeMetadata(value as Record<string, unknown>, seen);\n}\n\nfunction sanitizeMetadata(\n\tobj: Record<string, unknown>,\n\tseen: WeakSet<object> = new WeakSet(),\n): Record<string, unknown> {\n\tif (seen.has(obj)) return { value: CIRCULAR };\n\tseen.add(obj);\n\tconst result: Record<string, unknown> = {};\n\tfor (const [key, value] of Object.entries(obj)) {\n\t\tresult[key] = isSensitiveKey(key) ? REDACTED : sanitizeMetadataValue(value, seen);\n\t}\n\treturn result;\n}\n\nexport function formatAutonomyStatus(args: AutonomyStatusSnapshot): string {\n\tconst parts: string[] = [];\n\n\tif (args.latestRoute) {\n\t\tconst risk = args.latestRoute.risk ? ` (${redactAndTruncateString(args.latestRoute.risk)})` : \"\";\n\t\tparts.push(\n\t\t\t`Route: ${redactAndTruncateString(args.latestRoute.tier)}${risk} - ${redactAndTruncateString(args.latestRoute.reasonCode)}`,\n\t\t);\n\t}\n\n\tif (args.latestGate) {\n\t\tparts.push(\n\t\t\t`Gate: ${redactAndTruncateString(args.latestGate.gate)} = ${redactAndTruncateString(args.latestGate.outcome)} (${redactAndTruncateString(args.latestGate.reasonCode)})`,\n\t\t);\n\t}\n\n\tconst costs: string[] = [];\n\tif (args.currentCostUsd !== undefined) costs.push(`current: ${formatCost(args.currentCostUsd)}`);\n\tif (args.dailyCostUsd !== undefined) costs.push(`daily: ${formatCost(args.dailyCostUsd)}`);\n\tif (args.spawnedCostUsd !== undefined) costs.push(`spawned: ${formatCost(args.spawnedCostUsd)}`);\n\tif (costs.length > 0) {\n\t\tparts.push(`Costs: ${costs.join(\", \")}`);\n\t}\n\n\tif (args.activeGoal) {\n\t\tconst goal = args.activeGoal;\n\t\tconst requirements = goal.openRequirements !== undefined ? `, open reqs: ${goal.openRequirements}` : \"\";\n\t\tconst stalls = goal.stallTurns !== undefined ? `, stalls: ${goal.stallTurns}` : \"\";\n\t\tparts.push(\n\t\t\t`Goal [${redactAndTruncateString(goal.goalId)}]: ${redactAndTruncateString(goal.status)}${requirements}${stalls}`,\n\t\t);\n\t}\n\n\tif (args.activeLaneCount !== undefined) {\n\t\tparts.push(`Lanes: ${args.activeLaneCount}`);\n\t}\n\n\tif (parts.length === 0) return \"Autonomy: idle\";\n\treturn parts.join(\" | \");\n}\n\nfunction formatDiagnosticSection(name: string, entries?: readonly DiagnosticEntry[]): string | undefined {\n\tif (!entries || entries.length === 0) return undefined;\n\n\tconst lines: string[] = [`--- ${name} ---`];\n\tfor (const entry of entries) {\n\t\tlet header = `- ${redactAndTruncateString(entry.title)}`;\n\t\tif (entry.reasonCode) header += ` [${redactAndTruncateString(entry.reasonCode)}]`;\n\t\tlines.push(header);\n\n\t\tif (entry.summary) {\n\t\t\tlines.push(` Summary: ${redactAndTruncateString(entry.summary)}`);\n\t\t}\n\n\t\tif (entry.metadata) {\n\t\t\tlines.push(` Metadata: ${JSON.stringify(sanitizeMetadata(entry.metadata))}`);\n\t\t}\n\t}\n\treturn lines.join(\"\\n\");\n}\n\nexport function formatAutonomyDiagnostics(args: AutonomyDiagnosticSnapshot): string {\n\tconst sections = [\n\t\tformatDiagnosticSection(\"Routes\", args.routes),\n\t\tformatDiagnosticSection(\"Gates\", args.gates),\n\t\tformatDiagnosticSection(\"Costs\", args.costs),\n\t\tformatDiagnosticSection(\"Research\", args.research),\n\t\tformatDiagnosticSection(\"Delegation\", args.delegation),\n\t\tformatDiagnosticSection(\"Learning\", args.learning),\n\t\tformatDiagnosticSection(\"Goals\", args.goals),\n\t\tformatDiagnosticSection(\"Process Memory\", args.processMemory),\n\t].filter((section): section is string => Boolean(section));\n\n\tif (sections.length === 0) return \"No diagnostics available.\";\n\treturn sections.join(\"\\n\\n\");\n}\n"]}
|
|
@@ -99,6 +99,7 @@ export function formatAutonomyDiagnostics(args) {
|
|
|
99
99
|
formatDiagnosticSection("Delegation", args.delegation),
|
|
100
100
|
formatDiagnosticSection("Learning", args.learning),
|
|
101
101
|
formatDiagnosticSection("Goals", args.goals),
|
|
102
|
+
formatDiagnosticSection("Process Memory", args.processMemory),
|
|
102
103
|
].filter((section) => Boolean(section));
|
|
103
104
|
if (sections.length === 0)
|
|
104
105
|
return "No diagnostics available.";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../../src/core/autonomy/status.ts"],"names":[],"mappings":"AAwCA,MAAM,QAAQ,GAAG,YAAY,CAAC;AAC9B,MAAM,QAAQ,GAAG,YAAY,CAAC;AAC9B,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC;AAC7F,MAAM,qBAAqB,GAAG,4DAA4D,CAAC;AAE3F,SAAS,UAAU,CAAC,KAAa,EAAU;IAC1C,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAAA,CACnE;AAED,SAAS,uBAAuB,CAAC,KAAa,EAAU;IACvD,IAAI,qBAAqB,CAAC,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QAClD,uBAAuB,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC;QACtD,uBAAuB,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC;QAClD,uBAAuB,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC;KAC5C,CAAC,MAAM,CAAC,CAAC,OAAO,EAAqB,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAE3D,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,2BAA2B,CAAC;IAC9D,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAAA,CAC7B","sourcesContent":["import type { GateOutcomeKind } from \"./contracts.ts\";\n\nexport interface AutonomyStatusSnapshot {\n\tlatestRoute?: { tier: string; reasonCode: string; risk?: string };\n\tlatestGate?: { outcome: string; gate: string; reasonCode: string };\n\tcurrentCostUsd?: number;\n\tdailyCostUsd?: number;\n\tspawnedCostUsd?: number;\n\tactiveGoal?: { goalId: string; status: string; openRequirements?: number; stallTurns?: number };\n\tactiveLaneCount?: number;\n}\n\n/**\n * One bounded entry in AgentSession's gate-outcome history (G8). Codes/ids only — never the gate's\n * human-facing `message`. The most recent entry is the tail; `at` is an ISO timestamp.\n */\nexport interface GateOutcomeHistoryEntry {\n\toutcome: GateOutcomeKind;\n\tgate: string;\n\treasonCode: string;\n\tat: string;\n}\n\nexport interface DiagnosticEntry {\n\ttitle: string;\n\tsummary?: string;\n\treasonCode?: string;\n\tmetadata?: Record<string, unknown>;\n}\n\nexport interface AutonomyDiagnosticSnapshot {\n\troutes?: readonly DiagnosticEntry[];\n\tgates?: readonly DiagnosticEntry[];\n\tcosts?: readonly DiagnosticEntry[];\n\tresearch?: readonly DiagnosticEntry[];\n\tdelegation?: readonly DiagnosticEntry[];\n\tlearning?: readonly DiagnosticEntry[];\n\tgoals?: readonly DiagnosticEntry[];\n}\n\nconst REDACTED = \"[REDACTED]\";\nconst CIRCULAR = \"[Circular]\";\nconst MAX_STRING_LENGTH = 200;\nconst SENSITIVE_KEYS = [\"token\", \"secret\", \"key\", \"credential\", \"password\", \"authorization\"];\nconst SENSITIVE_VALUE_REGEX = /bearer\\s+[\\w\\-._]+|api[-_]?key[-_]?[\\w\\-._]+|sk-[\\w\\-._]+/i;\n\nfunction formatCost(value: number): string {\n\treturn Number.isFinite(value) ? `$${value.toFixed(4)}` : \"$0.0000\";\n}\n\nfunction redactAndTruncateString(value: string): string {\n\tif (SENSITIVE_VALUE_REGEX.test(value)) return REDACTED;\n\tif (value.length <= MAX_STRING_LENGTH) return value;\n\treturn `${value.slice(0, MAX_STRING_LENGTH - 1)}…`;\n}\n\nfunction isSensitiveKey(key: string): boolean {\n\tconst lowerKey = key.toLowerCase();\n\treturn SENSITIVE_KEYS.some((sensitiveKey) => lowerKey.includes(sensitiveKey));\n}\n\nfunction sanitizeMetadataValue(value: unknown, seen: WeakSet<object>): unknown {\n\tif (typeof value === \"string\") return redactAndTruncateString(value);\n\tif (typeof value !== \"object\" || value === null) return value;\n\tif (seen.has(value)) return CIRCULAR;\n\tif (Array.isArray(value)) {\n\t\tseen.add(value);\n\t\treturn value.map((item) => sanitizeMetadataValue(item, seen));\n\t}\n\treturn sanitizeMetadata(value as Record<string, unknown>, seen);\n}\n\nfunction sanitizeMetadata(\n\tobj: Record<string, unknown>,\n\tseen: WeakSet<object> = new WeakSet(),\n): Record<string, unknown> {\n\tif (seen.has(obj)) return { value: CIRCULAR };\n\tseen.add(obj);\n\tconst result: Record<string, unknown> = {};\n\tfor (const [key, value] of Object.entries(obj)) {\n\t\tresult[key] = isSensitiveKey(key) ? REDACTED : sanitizeMetadataValue(value, seen);\n\t}\n\treturn result;\n}\n\nexport function formatAutonomyStatus(args: AutonomyStatusSnapshot): string {\n\tconst parts: string[] = [];\n\n\tif (args.latestRoute) {\n\t\tconst risk = args.latestRoute.risk ? ` (${redactAndTruncateString(args.latestRoute.risk)})` : \"\";\n\t\tparts.push(\n\t\t\t`Route: ${redactAndTruncateString(args.latestRoute.tier)}${risk} - ${redactAndTruncateString(args.latestRoute.reasonCode)}`,\n\t\t);\n\t}\n\n\tif (args.latestGate) {\n\t\tparts.push(\n\t\t\t`Gate: ${redactAndTruncateString(args.latestGate.gate)} = ${redactAndTruncateString(args.latestGate.outcome)} (${redactAndTruncateString(args.latestGate.reasonCode)})`,\n\t\t);\n\t}\n\n\tconst costs: string[] = [];\n\tif (args.currentCostUsd !== undefined) costs.push(`current: ${formatCost(args.currentCostUsd)}`);\n\tif (args.dailyCostUsd !== undefined) costs.push(`daily: ${formatCost(args.dailyCostUsd)}`);\n\tif (args.spawnedCostUsd !== undefined) costs.push(`spawned: ${formatCost(args.spawnedCostUsd)}`);\n\tif (costs.length > 0) {\n\t\tparts.push(`Costs: ${costs.join(\", \")}`);\n\t}\n\n\tif (args.activeGoal) {\n\t\tconst goal = args.activeGoal;\n\t\tconst requirements = goal.openRequirements !== undefined ? `, open reqs: ${goal.openRequirements}` : \"\";\n\t\tconst stalls = goal.stallTurns !== undefined ? `, stalls: ${goal.stallTurns}` : \"\";\n\t\tparts.push(\n\t\t\t`Goal [${redactAndTruncateString(goal.goalId)}]: ${redactAndTruncateString(goal.status)}${requirements}${stalls}`,\n\t\t);\n\t}\n\n\tif (args.activeLaneCount !== undefined) {\n\t\tparts.push(`Lanes: ${args.activeLaneCount}`);\n\t}\n\n\tif (parts.length === 0) return \"Autonomy: idle\";\n\treturn parts.join(\" | \");\n}\n\nfunction formatDiagnosticSection(name: string, entries?: readonly DiagnosticEntry[]): string | undefined {\n\tif (!entries || entries.length === 0) return undefined;\n\n\tconst lines: string[] = [`--- ${name} ---`];\n\tfor (const entry of entries) {\n\t\tlet header = `- ${redactAndTruncateString(entry.title)}`;\n\t\tif (entry.reasonCode) header += ` [${redactAndTruncateString(entry.reasonCode)}]`;\n\t\tlines.push(header);\n\n\t\tif (entry.summary) {\n\t\t\tlines.push(` Summary: ${redactAndTruncateString(entry.summary)}`);\n\t\t}\n\n\t\tif (entry.metadata) {\n\t\t\tlines.push(` Metadata: ${JSON.stringify(sanitizeMetadata(entry.metadata))}`);\n\t\t}\n\t}\n\treturn lines.join(\"\\n\");\n}\n\nexport function formatAutonomyDiagnostics(args: AutonomyDiagnosticSnapshot): string {\n\tconst sections = [\n\t\tformatDiagnosticSection(\"Routes\", args.routes),\n\t\tformatDiagnosticSection(\"Gates\", args.gates),\n\t\tformatDiagnosticSection(\"Costs\", args.costs),\n\t\tformatDiagnosticSection(\"Research\", args.research),\n\t\tformatDiagnosticSection(\"Delegation\", args.delegation),\n\t\tformatDiagnosticSection(\"Learning\", args.learning),\n\t\tformatDiagnosticSection(\"Goals\", args.goals),\n\t].filter((section): section is string => Boolean(section));\n\n\tif (sections.length === 0) return \"No diagnostics available.\";\n\treturn sections.join(\"\\n\\n\");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../../src/core/autonomy/status.ts"],"names":[],"mappings":"AAyCA,MAAM,QAAQ,GAAG,YAAY,CAAC;AAC9B,MAAM,QAAQ,GAAG,YAAY,CAAC;AAC9B,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC;AAC7F,MAAM,qBAAqB,GAAG,4DAA4D,CAAC;AAE3F,SAAS,UAAU,CAAC,KAAa,EAAU;IAC1C,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAAA,CACnE;AAED,SAAS,uBAAuB,CAAC,KAAa,EAAU;IACvD,IAAI,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC;IACvD,IAAI,KAAK,CAAC,MAAM,IAAI,iBAAiB;QAAE,OAAO,KA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CAAC;QAClD,uBAAuB,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC;QAC5C,uBAAuB,CAAC,gBAAgB,EAAE,IAAI,CAAC,aAAa,CAAC;KAC7D,CAAC,MAAM,CAAC,CAAC,OAAO,EAAqB,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAE3D,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,2BAA2B,CAAC;IAC9D,OAAO,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAAA,CAC7B","sourcesContent":["import type { GateOutcomeKind } from \"./contracts.ts\";\n\nexport interface AutonomyStatusSnapshot {\n\tlatestRoute?: { tier: string; reasonCode: string; risk?: string };\n\tlatestGate?: { outcome: string; gate: string; reasonCode: string };\n\tcurrentCostUsd?: number;\n\tdailyCostUsd?: number;\n\tspawnedCostUsd?: number;\n\tactiveGoal?: { goalId: string; status: string; openRequirements?: number; stallTurns?: number };\n\tactiveLaneCount?: number;\n}\n\n/**\n * One bounded entry in AgentSession's gate-outcome history (G8). Codes/ids only — never the gate's\n * human-facing `message`. The most recent entry is the tail; `at` is an ISO timestamp.\n */\nexport interface GateOutcomeHistoryEntry {\n\toutcome: GateOutcomeKind;\n\tgate: string;\n\treasonCode: string;\n\tat: string;\n}\n\nexport interface DiagnosticEntry {\n\ttitle: string;\n\tsummary?: string;\n\treasonCode?: string;\n\tmetadata?: Record<string, unknown>;\n}\n\nexport interface AutonomyDiagnosticSnapshot {\n\troutes?: readonly DiagnosticEntry[];\n\tgates?: readonly DiagnosticEntry[];\n\tcosts?: readonly DiagnosticEntry[];\n\tresearch?: readonly DiagnosticEntry[];\n\tdelegation?: readonly DiagnosticEntry[];\n\tlearning?: readonly DiagnosticEntry[];\n\tgoals?: readonly DiagnosticEntry[];\n\tprocessMemory?: readonly DiagnosticEntry[];\n}\n\nconst REDACTED = \"[REDACTED]\";\nconst CIRCULAR = \"[Circular]\";\nconst MAX_STRING_LENGTH = 200;\nconst SENSITIVE_KEYS = [\"token\", \"secret\", \"key\", \"credential\", \"password\", \"authorization\"];\nconst SENSITIVE_VALUE_REGEX = /bearer\\s+[\\w\\-._]+|api[-_]?key[-_]?[\\w\\-._]+|sk-[\\w\\-._]+/i;\n\nfunction formatCost(value: number): string {\n\treturn Number.isFinite(value) ? `$${value.toFixed(4)}` : \"$0.0000\";\n}\n\nfunction redactAndTruncateString(value: string): string {\n\tif (SENSITIVE_VALUE_REGEX.test(value)) return REDACTED;\n\tif (value.length <= MAX_STRING_LENGTH) return value;\n\treturn `${value.slice(0, MAX_STRING_LENGTH - 1)}…`;\n}\n\nfunction isSensitiveKey(key: string): boolean {\n\tconst lowerKey = key.toLowerCase();\n\treturn SENSITIVE_KEYS.some((sensitiveKey) => lowerKey.includes(sensitiveKey));\n}\n\nfunction sanitizeMetadataValue(value: unknown, seen: WeakSet<object>): unknown {\n\tif (typeof value === \"string\") return redactAndTruncateString(value);\n\tif (typeof value !== \"object\" || value === null) return value;\n\tif (seen.has(value)) return CIRCULAR;\n\tif (Array.isArray(value)) {\n\t\tseen.add(value);\n\t\treturn value.map((item) => sanitizeMetadataValue(item, seen));\n\t}\n\treturn sanitizeMetadata(value as Record<string, unknown>, seen);\n}\n\nfunction sanitizeMetadata(\n\tobj: Record<string, unknown>,\n\tseen: WeakSet<object> = new WeakSet(),\n): Record<string, unknown> {\n\tif (seen.has(obj)) return { value: CIRCULAR };\n\tseen.add(obj);\n\tconst result: Record<string, unknown> = {};\n\tfor (const [key, value] of Object.entries(obj)) {\n\t\tresult[key] = isSensitiveKey(key) ? REDACTED : sanitizeMetadataValue(value, seen);\n\t}\n\treturn result;\n}\n\nexport function formatAutonomyStatus(args: AutonomyStatusSnapshot): string {\n\tconst parts: string[] = [];\n\n\tif (args.latestRoute) {\n\t\tconst risk = args.latestRoute.risk ? ` (${redactAndTruncateString(args.latestRoute.risk)})` : \"\";\n\t\tparts.push(\n\t\t\t`Route: ${redactAndTruncateString(args.latestRoute.tier)}${risk} - ${redactAndTruncateString(args.latestRoute.reasonCode)}`,\n\t\t);\n\t}\n\n\tif (args.latestGate) {\n\t\tparts.push(\n\t\t\t`Gate: ${redactAndTruncateString(args.latestGate.gate)} = ${redactAndTruncateString(args.latestGate.outcome)} (${redactAndTruncateString(args.latestGate.reasonCode)})`,\n\t\t);\n\t}\n\n\tconst costs: string[] = [];\n\tif (args.currentCostUsd !== undefined) costs.push(`current: ${formatCost(args.currentCostUsd)}`);\n\tif (args.dailyCostUsd !== undefined) costs.push(`daily: ${formatCost(args.dailyCostUsd)}`);\n\tif (args.spawnedCostUsd !== undefined) costs.push(`spawned: ${formatCost(args.spawnedCostUsd)}`);\n\tif (costs.length > 0) {\n\t\tparts.push(`Costs: ${costs.join(\", \")}`);\n\t}\n\n\tif (args.activeGoal) {\n\t\tconst goal = args.activeGoal;\n\t\tconst requirements = goal.openRequirements !== undefined ? `, open reqs: ${goal.openRequirements}` : \"\";\n\t\tconst stalls = goal.stallTurns !== undefined ? `, stalls: ${goal.stallTurns}` : \"\";\n\t\tparts.push(\n\t\t\t`Goal [${redactAndTruncateString(goal.goalId)}]: ${redactAndTruncateString(goal.status)}${requirements}${stalls}`,\n\t\t);\n\t}\n\n\tif (args.activeLaneCount !== undefined) {\n\t\tparts.push(`Lanes: ${args.activeLaneCount}`);\n\t}\n\n\tif (parts.length === 0) return \"Autonomy: idle\";\n\treturn parts.join(\" | \");\n}\n\nfunction formatDiagnosticSection(name: string, entries?: readonly DiagnosticEntry[]): string | undefined {\n\tif (!entries || entries.length === 0) return undefined;\n\n\tconst lines: string[] = [`--- ${name} ---`];\n\tfor (const entry of entries) {\n\t\tlet header = `- ${redactAndTruncateString(entry.title)}`;\n\t\tif (entry.reasonCode) header += ` [${redactAndTruncateString(entry.reasonCode)}]`;\n\t\tlines.push(header);\n\n\t\tif (entry.summary) {\n\t\t\tlines.push(` Summary: ${redactAndTruncateString(entry.summary)}`);\n\t\t}\n\n\t\tif (entry.metadata) {\n\t\t\tlines.push(` Metadata: ${JSON.stringify(sanitizeMetadata(entry.metadata))}`);\n\t\t}\n\t}\n\treturn lines.join(\"\\n\");\n}\n\nexport function formatAutonomyDiagnostics(args: AutonomyDiagnosticSnapshot): string {\n\tconst sections = [\n\t\tformatDiagnosticSection(\"Routes\", args.routes),\n\t\tformatDiagnosticSection(\"Gates\", args.gates),\n\t\tformatDiagnosticSection(\"Costs\", args.costs),\n\t\tformatDiagnosticSection(\"Research\", args.research),\n\t\tformatDiagnosticSection(\"Delegation\", args.delegation),\n\t\tformatDiagnosticSection(\"Learning\", args.learning),\n\t\tformatDiagnosticSection(\"Goals\", args.goals),\n\t\tformatDiagnosticSection(\"Process Memory\", args.processMemory),\n\t].filter((section): section is string => Boolean(section));\n\n\tif (sections.length === 0) return \"No diagnostics available.\";\n\treturn sections.join(\"\\n\\n\");\n}\n"]}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Autonomy telemetry sink + status/diagnostic snapshots.
|
|
3
|
+
*
|
|
4
|
+
* Extracted verbatim from agent-session.ts (god-file decomposition). Owns the latest gate outcome
|
|
5
|
+
* and the bounded gate-outcome history, and is the single sink for G3 autonomy-telemetry custom
|
|
6
|
+
* entries. The two snapshot builders READ broadly across live session state (router decision, cost,
|
|
7
|
+
* goal, lanes, and the research/delegation/learning/goal getters) through narrow deps accessors
|
|
8
|
+
* rather than the whole AgentSession — they never mutate anything but the owned gate-outcome fields.
|
|
9
|
+
*/
|
|
10
|
+
import type { SessionManager } from "@caupulican/pi-agent-core/node";
|
|
11
|
+
import type { SessionStats, SpawnedUsageTotals } from "./agent-session.ts";
|
|
12
|
+
import type { EvidenceBundle, GateOutcome, LearningDecision, WorkerResult } from "./autonomy/contracts.ts";
|
|
13
|
+
import type { AutonomyDiagnosticSnapshot, AutonomyStatusSnapshot, GateOutcomeHistoryEntry } from "./autonomy/status.ts";
|
|
14
|
+
import { type AutonomyTelemetryEvent } from "./autonomy/telemetry-events.ts";
|
|
15
|
+
import type { DailyUsageTotals } from "./cost/daily-usage.ts";
|
|
16
|
+
import type { GoalState } from "./goals/goal-state.ts";
|
|
17
|
+
import type { LearningAuditRecord } from "./learning/learning-audit.ts";
|
|
18
|
+
import { type ModelRouterDecisionStatus } from "./model-router/status.ts";
|
|
19
|
+
export interface AutonomyTelemetryDeps {
|
|
20
|
+
/** Session log: `appendCustomEntry` is the telemetry sink; `getEntries` feeds diagnostic aggregation. */
|
|
21
|
+
getSessionManager(): Pick<SessionManager, "appendCustomEntry" | "getEntries">;
|
|
22
|
+
/** Latest model-router decision, for the snapshot's `latestRoute` — owned by the router, not this sink. */
|
|
23
|
+
getLastModelRouterDecision(): ModelRouterDecisionStatus | undefined;
|
|
24
|
+
/** Reason the last research lane was skipped, if any — surfaced in the diagnostic's research family. */
|
|
25
|
+
getLastResearchLaneSkipReason(): string | undefined;
|
|
26
|
+
/** This session's own usage totals (cost only is read). */
|
|
27
|
+
getSessionStats(): SessionStats;
|
|
28
|
+
/** Spawned-child usage totals (cost only is read). */
|
|
29
|
+
getSpawnedUsage(): SpawnedUsageTotals;
|
|
30
|
+
/** Cross-session daily usage totals, if trackable — preserves the source's optional-call semantics. */
|
|
31
|
+
getDailyUsageTotals(): DailyUsageTotals | undefined;
|
|
32
|
+
/** Current goal state, if a goal is active. */
|
|
33
|
+
getGoalStateSnapshot(): GoalState | undefined;
|
|
34
|
+
/** Live count of active lanes from the lane tracker — never inferred from historical snapshots. */
|
|
35
|
+
getActiveLaneCount(): number;
|
|
36
|
+
/** Research evidence bundles recorded this session. */
|
|
37
|
+
getEvidenceBundleSnapshots(): EvidenceBundle[];
|
|
38
|
+
/** Worker-delegation result snapshots recorded this session. */
|
|
39
|
+
getWorkerResultSnapshots(): WorkerResult[];
|
|
40
|
+
/** Learning decision snapshots recorded this session. */
|
|
41
|
+
getLearningDecisionSnapshots(): LearningDecision[];
|
|
42
|
+
/** Learning audit records recorded this session. */
|
|
43
|
+
getLearningAuditRecords(): LearningAuditRecord[];
|
|
44
|
+
}
|
|
45
|
+
export declare class AutonomyTelemetry {
|
|
46
|
+
private _lastAutonomyGateOutcome?;
|
|
47
|
+
/** G8: bounded (cap {@link GATE_OUTCOME_HISTORY_LIMIT}) history of gate outcomes; tail is latest. */
|
|
48
|
+
private readonly _gateOutcomeHistory;
|
|
49
|
+
private readonly deps;
|
|
50
|
+
constructor(deps: AutonomyTelemetryDeps);
|
|
51
|
+
/**
|
|
52
|
+
* G3: bounded autonomy-telemetry sink. Passes the whole event through {@link redactTelemetryValue}
|
|
53
|
+
* (the taxonomy's redaction contract) before storing it, so a secret that leaked into a payload
|
|
54
|
+
* field never lands in the session log. Observe-only: a failure here can never surface into the
|
|
55
|
+
* turn it is measuring, so the whole body is swallowed. Payloads MUST stay small (ids, codes,
|
|
56
|
+
* numbers) — never prompt/summary text; callers own that discipline.
|
|
57
|
+
*/
|
|
58
|
+
emitTelemetry(event: AutonomyTelemetryEvent): void;
|
|
59
|
+
/**
|
|
60
|
+
* G8: single sink for a gate outcome. Keeps the latest-outcome getter behavior identical (the
|
|
61
|
+
* full {@link GateOutcome} still lands in `_lastAutonomyGateOutcome`), and additionally appends a
|
|
62
|
+
* bounded codes-only entry to {@link _gateOutcomeHistory} (oldest evicted at
|
|
63
|
+
* {@link GATE_OUTCOME_HISTORY_LIMIT}) and emits the `gate_outcome` telemetry event. The history
|
|
64
|
+
* tail therefore always mirrors the latest outcome. Only called with an active envelope.
|
|
65
|
+
*/
|
|
66
|
+
recordGateOutcome(outcome: GateOutcome): void;
|
|
67
|
+
/** G8: copies of the bounded gate-outcome history, oldest first, latest last. */
|
|
68
|
+
getGateOutcomeHistory(): GateOutcomeHistoryEntry[];
|
|
69
|
+
getStatusSnapshot(): AutonomyStatusSnapshot;
|
|
70
|
+
/**
|
|
71
|
+
* Aggregate an effectiveness/autonomy dashboard: what Pi has actually been doing (recent
|
|
72
|
+
* route choices, latest gate outcome, cost, and any research/delegation/learning/goal
|
|
73
|
+
* activity). Read-only — combines existing session-log getters, never mutates state or
|
|
74
|
+
* recomputes a route/gate decision.
|
|
75
|
+
*/
|
|
76
|
+
getDiagnosticSnapshot(options?: {
|
|
77
|
+
maxEntriesPerFamily?: number;
|
|
78
|
+
}): AutonomyDiagnosticSnapshot;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=autonomy-telemetry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autonomy-telemetry.d.ts","sourceRoot":"","sources":["../../src/core/autonomy-telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAErE,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE3G,OAAO,KAAK,EACX,0BAA0B,EAC1B,sBAAsB,EAEtB,uBAAuB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEN,KAAK,sBAAsB,EAE3B,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EAAiC,KAAK,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AASzG,MAAM,WAAW,qBAAqB;IACrC,yGAAyG;IACzG,iBAAiB,IAAI,IAAI,CAAC,cAAc,EAAE,mBAAmB,GAAG,YAAY,CAAC,CAAC;IAC9E,6GAA2G;IAC3G,0BAA0B,IAAI,yBAAyB,GAAG,SAAS,CAAC;IACpE,0GAAwG;IACxG,6BAA6B,IAAI,MAAM,GAAG,SAAS,CAAC;IACpD,2DAA2D;IAC3D,eAAe,IAAI,YAAY,CAAC;IAChC,sDAAsD;IACtD,eAAe,IAAI,kBAAkB,CAAC;IACtC,yGAAuG;IACvG,mBAAmB,IAAI,gBAAgB,GAAG,SAAS,CAAC;IACpD,+CAA+C;IAC/C,oBAAoB,IAAI,SAAS,GAAG,SAAS,CAAC;IAC9C,qGAAmG;IACnG,kBAAkB,IAAI,MAAM,CAAC;IAC7B,uDAAuD;IACvD,0BAA0B,IAAI,cAAc,EAAE,CAAC;IAC/C,gEAAgE;IAChE,wBAAwB,IAAI,YAAY,EAAE,CAAC;IAC3C,yDAAyD;IACzD,4BAA4B,IAAI,gBAAgB,EAAE,CAAC;IACnD,oDAAoD;IACpD,uBAAuB,IAAI,mBAAmB,EAAE,CAAC;CACjD;AAED,qBAAa,iBAAiB;IAC7B,OAAO,CAAC,wBAAwB,CAAC,CAAc;IAC/C,qGAAqG;IACrG,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAiC;IAErE,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAwB;IAE7C,YAAY,IAAI,EAAE,qBAAqB,EAEtC;IAED;;;;;;OAMG;IACH,aAAa,CAAC,KAAK,EAAE,sBAAsB,GAAG,IAAI,CAOjD;IAED;;;;;;OAMG;IACH,iBAAiB,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAsB5C;IAED,iFAAiF;IACjF,qBAAqB,IAAI,uBAAuB,EAAE,CAEjD;IAED,iBAAiB,IAAI,sBAAsB,CAqD1C;IAED;;;;;OAKG;IACH,qBAAqB,CAAC,OAAO,CAAC,EAAE;QAAE,mBAAmB,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,0BAA0B,CAuJ5F;CACD","sourcesContent":["/**\n * Autonomy telemetry sink + status/diagnostic snapshots.\n *\n * Extracted verbatim from agent-session.ts (god-file decomposition). Owns the latest gate outcome\n * and the bounded gate-outcome history, and is the single sink for G3 autonomy-telemetry custom\n * entries. The two snapshot builders READ broadly across live session state (router decision, cost,\n * goal, lanes, and the research/delegation/learning/goal getters) through narrow deps accessors\n * rather than the whole AgentSession — they never mutate anything but the owned gate-outcome fields.\n */\n\nimport type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport { getProcessMemoryMb } from \"../utils/process-memory.ts\";\nimport type { SessionStats, SpawnedUsageTotals } from \"./agent-session.ts\";\nimport type { EvidenceBundle, GateOutcome, LearningDecision, WorkerResult } from \"./autonomy/contracts.ts\";\nimport { getLaneRecordSnapshots } from \"./autonomy/session-lane-record.ts\";\nimport type {\n\tAutonomyDiagnosticSnapshot,\n\tAutonomyStatusSnapshot,\n\tDiagnosticEntry,\n\tGateOutcomeHistoryEntry,\n} from \"./autonomy/status.ts\";\nimport {\n\tAUTONOMY_TELEMETRY_EVENT_TYPES,\n\ttype AutonomyTelemetryEvent,\n\tredactTelemetryValue,\n} from \"./autonomy/telemetry-events.ts\";\nimport type { DailyUsageTotals } from \"./cost/daily-usage.ts\";\nimport type { GoalState } from \"./goals/goal-state.ts\";\nimport type { LearningAuditRecord } from \"./learning/learning-audit.ts\";\nimport { getRecentModelRouterDecisions, type ModelRouterDecisionStatus } from \"./model-router/status.ts\";\n\n/** Custom-entry type for G3 autonomy telemetry. Distinct from the router/lane record types so a\n * telemetry consumer can filter on it without decoding operational snapshots. */\nconst AUTONOMY_TELEMETRY_CUSTOM_TYPE = \"autonomy-telemetry\";\n\n/** G8: bound on the in-memory gate-outcome history. Oldest entries evict once the cap is reached. */\nconst GATE_OUTCOME_HISTORY_LIMIT = 50;\n\nexport interface AutonomyTelemetryDeps {\n\t/** Session log: `appendCustomEntry` is the telemetry sink; `getEntries` feeds diagnostic aggregation. */\n\tgetSessionManager(): Pick<SessionManager, \"appendCustomEntry\" | \"getEntries\">;\n\t/** Latest model-router decision, for the snapshot's `latestRoute` — owned by the router, not this sink. */\n\tgetLastModelRouterDecision(): ModelRouterDecisionStatus | undefined;\n\t/** Reason the last research lane was skipped, if any — surfaced in the diagnostic's research family. */\n\tgetLastResearchLaneSkipReason(): string | undefined;\n\t/** This session's own usage totals (cost only is read). */\n\tgetSessionStats(): SessionStats;\n\t/** Spawned-child usage totals (cost only is read). */\n\tgetSpawnedUsage(): SpawnedUsageTotals;\n\t/** Cross-session daily usage totals, if trackable — preserves the source's optional-call semantics. */\n\tgetDailyUsageTotals(): DailyUsageTotals | undefined;\n\t/** Current goal state, if a goal is active. */\n\tgetGoalStateSnapshot(): GoalState | undefined;\n\t/** Live count of active lanes from the lane tracker — never inferred from historical snapshots. */\n\tgetActiveLaneCount(): number;\n\t/** Research evidence bundles recorded this session. */\n\tgetEvidenceBundleSnapshots(): EvidenceBundle[];\n\t/** Worker-delegation result snapshots recorded this session. */\n\tgetWorkerResultSnapshots(): WorkerResult[];\n\t/** Learning decision snapshots recorded this session. */\n\tgetLearningDecisionSnapshots(): LearningDecision[];\n\t/** Learning audit records recorded this session. */\n\tgetLearningAuditRecords(): LearningAuditRecord[];\n}\n\nexport class AutonomyTelemetry {\n\tprivate _lastAutonomyGateOutcome?: GateOutcome;\n\t/** G8: bounded (cap {@link GATE_OUTCOME_HISTORY_LIMIT}) history of gate outcomes; tail is latest. */\n\tprivate readonly _gateOutcomeHistory: GateOutcomeHistoryEntry[] = [];\n\n\tprivate readonly deps: AutonomyTelemetryDeps;\n\n\tconstructor(deps: AutonomyTelemetryDeps) {\n\t\tthis.deps = deps;\n\t}\n\n\t/**\n\t * G3: bounded autonomy-telemetry sink. Passes the whole event through {@link redactTelemetryValue}\n\t * (the taxonomy's redaction contract) before storing it, so a secret that leaked into a payload\n\t * field never lands in the session log. Observe-only: a failure here can never surface into the\n\t * turn it is measuring, so the whole body is swallowed. Payloads MUST stay small (ids, codes,\n\t * numbers) — never prompt/summary text; callers own that discipline.\n\t */\n\temitTelemetry(event: AutonomyTelemetryEvent): void {\n\t\ttry {\n\t\t\tconst redacted = redactTelemetryValue(event) as Record<string, unknown>;\n\t\t\tthis.deps.getSessionManager().appendCustomEntry(AUTONOMY_TELEMETRY_CUSTOM_TYPE, { version: 1, ...redacted });\n\t\t} catch {\n\t\t\t// Telemetry is best-effort: swallow so a sink failure cannot break the observed turn.\n\t\t}\n\t}\n\n\t/**\n\t * G8: single sink for a gate outcome. Keeps the latest-outcome getter behavior identical (the\n\t * full {@link GateOutcome} still lands in `_lastAutonomyGateOutcome`), and additionally appends a\n\t * bounded codes-only entry to {@link _gateOutcomeHistory} (oldest evicted at\n\t * {@link GATE_OUTCOME_HISTORY_LIMIT}) and emits the `gate_outcome` telemetry event. The history\n\t * tail therefore always mirrors the latest outcome. Only called with an active envelope.\n\t */\n\trecordGateOutcome(outcome: GateOutcome): void {\n\t\tthis._lastAutonomyGateOutcome = outcome;\n\t\tconst at = new Date().toISOString();\n\t\tthis._gateOutcomeHistory.push({\n\t\t\toutcome: outcome.outcome,\n\t\t\tgate: outcome.gate,\n\t\t\treasonCode: outcome.reasonCode,\n\t\t\tat,\n\t\t});\n\t\twhile (this._gateOutcomeHistory.length > GATE_OUTCOME_HISTORY_LIMIT) {\n\t\t\tthis._gateOutcomeHistory.shift();\n\t\t}\n\t\t// G8: gate outcome event. Codes/ids only — never the gate's human-facing message.\n\t\tthis.emitTelemetry({\n\t\t\ttype: AUTONOMY_TELEMETRY_EVENT_TYPES.gateOutcome,\n\t\t\ttimestamp: at,\n\t\t\tpayload: {\n\t\t\t\toutcome: outcome.outcome,\n\t\t\t\tgate: outcome.gate,\n\t\t\t\treasonCode: outcome.reasonCode,\n\t\t\t},\n\t\t});\n\t}\n\n\t/** G8: copies of the bounded gate-outcome history, oldest first, latest last. */\n\tgetGateOutcomeHistory(): GateOutcomeHistoryEntry[] {\n\t\treturn this._gateOutcomeHistory.map((entry) => ({ ...entry }));\n\t}\n\n\tgetStatusSnapshot(): AutonomyStatusSnapshot {\n\t\tconst snapshot: AutonomyStatusSnapshot = {};\n\n\t\tconst lastRouterDecision = this.deps.getLastModelRouterDecision();\n\t\tif (lastRouterDecision?.route) {\n\t\t\tsnapshot.latestRoute = {\n\t\t\t\ttier: lastRouterDecision.route.tier,\n\t\t\t\treasonCode: lastRouterDecision.route.reasonCode,\n\t\t\t\trisk: lastRouterDecision.route.risk,\n\t\t\t};\n\t\t}\n\n\t\tif (this._lastAutonomyGateOutcome) {\n\t\t\tsnapshot.latestGate = {\n\t\t\t\toutcome: this._lastAutonomyGateOutcome.outcome,\n\t\t\t\tgate: this._lastAutonomyGateOutcome.gate,\n\t\t\t\treasonCode: this._lastAutonomyGateOutcome.reasonCode,\n\t\t\t};\n\t\t}\n\n\t\tconst currentCost = this.deps.getSessionStats().cost;\n\t\tif (currentCost > 0) {\n\t\t\tsnapshot.currentCostUsd = currentCost;\n\t\t}\n\n\t\tconst spawnedCost = this.deps.getSpawnedUsage().cost;\n\t\tif (spawnedCost > 0) {\n\t\t\tsnapshot.spawnedCostUsd = spawnedCost;\n\t\t}\n\n\t\tconst dailyCost = this.deps.getDailyUsageTotals()?.totalCost;\n\t\tif (dailyCost !== undefined && dailyCost > 0) {\n\t\t\tsnapshot.dailyCostUsd = dailyCost;\n\t\t}\n\n\t\tconst goal = this.deps.getGoalStateSnapshot();\n\t\tif (goal) {\n\t\t\tsnapshot.activeGoal = {\n\t\t\t\tgoalId: goal.goalId,\n\t\t\t\tstatus: goal.status,\n\t\t\t\topenRequirements: goal.requirements.filter((requirement) => requirement.status === \"open\").length,\n\t\t\t\tstallTurns: goal.stallTurns,\n\t\t\t};\n\t\t}\n\n\t\t// Real live count from the lane tracker — never inferred from historical snapshots. Absent\n\t\t// while zero, matching the presence-means-signal convention of the sibling fields.\n\t\tconst activeLaneCount = this.deps.getActiveLaneCount();\n\t\tif (activeLaneCount > 0) {\n\t\t\tsnapshot.activeLaneCount = activeLaneCount;\n\t\t}\n\n\t\treturn snapshot;\n\t}\n\n\t/**\n\t * Aggregate an effectiveness/autonomy dashboard: what Pi has actually been doing (recent\n\t * route choices, latest gate outcome, cost, and any research/delegation/learning/goal\n\t * activity). Read-only — combines existing session-log getters, never mutates state or\n\t * recomputes a route/gate decision.\n\t */\n\tgetDiagnosticSnapshot(options?: { maxEntriesPerFamily?: number }): AutonomyDiagnosticSnapshot {\n\t\tconst maxEntriesPerFamily = options?.maxEntriesPerFamily ?? 10;\n\t\tconst snapshot: AutonomyDiagnosticSnapshot = {};\n\t\tconst goal = this.deps.getGoalStateSnapshot();\n\n\t\tconst recentDecisions = getRecentModelRouterDecisions(\n\t\t\tthis.deps.getSessionManager().getEntries(),\n\t\t\tmaxEntriesPerFamily,\n\t\t);\n\t\tif (recentDecisions.length > 0) {\n\t\t\tsnapshot.routes = recentDecisions.map(\n\t\t\t\t(decision): DiagnosticEntry => ({\n\t\t\t\t\ttitle: decision.route.tier,\n\t\t\t\t\tsummary: decision.routedModel,\n\t\t\t\t\treasonCode: decision.route.reasonCode,\n\t\t\t\t\tmetadata: { risk: decision.route.risk, outcome: decision.outcome, intent: decision.intent },\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tif (this._lastAutonomyGateOutcome) {\n\t\t\tconst gate = this._lastAutonomyGateOutcome;\n\t\t\tsnapshot.gates = [\n\t\t\t\t{\n\t\t\t\t\ttitle: gate.gate,\n\t\t\t\t\tsummary: gate.message,\n\t\t\t\t\treasonCode: gate.reasonCode,\n\t\t\t\t\tmetadata: { outcome: gate.outcome, reversible: gate.reversible },\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tconst costs: DiagnosticEntry[] = [];\n\t\tconst currentCostForDiagnostics = this.deps.getSessionStats().cost;\n\t\tif (currentCostForDiagnostics > 0) {\n\t\t\tcosts.push({ title: \"current\", summary: `$${currentCostForDiagnostics.toFixed(4)}` });\n\t\t}\n\t\tconst spawnedCost = this.deps.getSpawnedUsage().cost;\n\t\tif (spawnedCost > 0) costs.push({ title: \"spawned\", summary: `$${spawnedCost.toFixed(4)}` });\n\t\tconst dailyCostForDiagnostics = this.deps.getDailyUsageTotals()?.totalCost;\n\t\tif (dailyCostForDiagnostics !== undefined && dailyCostForDiagnostics > 0) {\n\t\t\tcosts.push({ title: \"daily\", summary: `$${dailyCostForDiagnostics.toFixed(4)}` });\n\t\t}\n\t\tif (costs.length > 0) snapshot.costs = costs;\n\n\t\tconst researchEntries: DiagnosticEntry[] = [];\n\t\tconst researchLaneRecords = getLaneRecordSnapshots(this.deps.getSessionManager().getEntries()).filter(\n\t\t\t(record) => record.type === \"research\",\n\t\t);\n\t\tfor (const record of researchLaneRecords.slice(-maxEntriesPerFamily)) {\n\t\t\tresearchEntries.push({\n\t\t\t\ttitle: `Lane ${record.laneId} (${record.status})`,\n\t\t\t\treasonCode: record.reasonCode,\n\t\t\t\tmetadata: {\n\t\t\t\t\tcostUsd: record.costUsd,\n\t\t\t\t\tstartedAt: record.startedAt,\n\t\t\t\t\tcompletedAt: record.completedAt,\n\t\t\t\t\tgoalId: record.goalId,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tfor (const bundle of this.deps.getEvidenceBundleSnapshots().slice(-maxEntriesPerFamily)) {\n\t\t\tresearchEntries.push({\n\t\t\t\ttitle: `Research: ${bundle.query}`,\n\t\t\t\tmetadata: { sourceCount: bundle.sources.length, findingCount: bundle.findings.length },\n\t\t\t});\n\t\t}\n\t\tif (this.deps.getLastResearchLaneSkipReason()) {\n\t\t\tresearchEntries.push({ title: \"Last skip\", reasonCode: this.deps.getLastResearchLaneSkipReason() });\n\t\t}\n\t\tif (researchEntries.length > 0) {\n\t\t\tsnapshot.research = researchEntries;\n\t\t}\n\n\t\tconst delegationEntries: DiagnosticEntry[] = [];\n\t\tconst workerLaneRecords = getLaneRecordSnapshots(this.deps.getSessionManager().getEntries()).filter(\n\t\t\t(record) => record.type === \"worker\",\n\t\t);\n\t\tfor (const record of workerLaneRecords.slice(-maxEntriesPerFamily)) {\n\t\t\tdelegationEntries.push({\n\t\t\t\ttitle: `Lane ${record.laneId} (${record.status})`,\n\t\t\t\treasonCode: record.reasonCode,\n\t\t\t\tmetadata: { costUsd: record.costUsd, startedAt: record.startedAt, completedAt: record.completedAt },\n\t\t\t});\n\t\t}\n\t\tconst workerResults = this.deps.getWorkerResultSnapshots();\n\t\tfor (const result of workerResults.slice(-maxEntriesPerFamily)) {\n\t\t\tdelegationEntries.push({\n\t\t\t\ttitle: `Worker ${result.requestId} (${result.status})`,\n\t\t\t\tsummary: result.summary,\n\t\t\t\tmetadata: {\n\t\t\t\t\tchangedFileCount: result.changedFiles.length,\n\t\t\t\t\tblockerCount: result.blockers?.length ?? 0,\n\t\t\t\t\tusageReportId: result.usageReportId,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tif (delegationEntries.length > 0) {\n\t\t\tsnapshot.delegation = delegationEntries;\n\t\t}\n\n\t\tconst learningEntries: DiagnosticEntry[] = [];\n\t\tconst learningDecisions = this.deps.getLearningDecisionSnapshots();\n\t\tfor (const decision of learningDecisions.slice(-maxEntriesPerFamily)) {\n\t\t\tlearningEntries.push({\n\t\t\t\ttitle: `Learning (${decision.kind})`,\n\t\t\t\tsummary: decision.summary,\n\t\t\t\treasonCode: decision.reasonCode,\n\t\t\t\tmetadata: { confidence: decision.confidence, requiresApproval: decision.requiresApproval },\n\t\t\t});\n\t\t}\n\t\tfor (const audit of this.deps.getLearningAuditRecords().slice(-maxEntriesPerFamily)) {\n\t\t\tlearningEntries.push({\n\t\t\t\ttitle: `Audit ${audit.id} (${audit.action})`,\n\t\t\t\tsummary: audit.summary,\n\t\t\t\treasonCode: audit.reasonCode,\n\t\t\t\tmetadata: { layer: audit.layer, proposalId: audit.proposalId, rollbackOf: audit.rollbackOf },\n\t\t\t});\n\t\t}\n\t\tif (learningEntries.length > 0) {\n\t\t\tsnapshot.learning = learningEntries;\n\t\t}\n\n\t\tif (goal) {\n\t\t\tsnapshot.goals = [\n\t\t\t\t{\n\t\t\t\t\ttitle: `Goal ${goal.goalId}`,\n\t\t\t\t\tsummary: goal.userGoal,\n\t\t\t\t\treasonCode: goal.status,\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\topenRequirementCount: goal.requirements.filter((requirement) => requirement.status === \"open\").length,\n\t\t\t\t\t\tstallTurns: goal.stallTurns,\n\t\t\t\t\t\tblockedReason: goal.blockedReason,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tconst processMemory = getProcessMemoryMb();\n\t\tsnapshot.processMemory = [\n\t\t\t{\n\t\t\t\ttitle: \"process\",\n\t\t\t\tmetadata: {\n\t\t\t\t\trssMb: processMemory.rssMb,\n\t\t\t\t\theapUsedMb: processMemory.heapUsedMb,\n\t\t\t\t\texternalMb: processMemory.externalMb,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\n\t\treturn snapshot;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Autonomy telemetry sink + status/diagnostic snapshots.
|
|
3
|
+
*
|
|
4
|
+
* Extracted verbatim from agent-session.ts (god-file decomposition). Owns the latest gate outcome
|
|
5
|
+
* and the bounded gate-outcome history, and is the single sink for G3 autonomy-telemetry custom
|
|
6
|
+
* entries. The two snapshot builders READ broadly across live session state (router decision, cost,
|
|
7
|
+
* goal, lanes, and the research/delegation/learning/goal getters) through narrow deps accessors
|
|
8
|
+
* rather than the whole AgentSession — they never mutate anything but the owned gate-outcome fields.
|
|
9
|
+
*/
|
|
10
|
+
import { getProcessMemoryMb } from "../utils/process-memory.js";
|
|
11
|
+
import { getLaneRecordSnapshots } from "./autonomy/session-lane-record.js";
|
|
12
|
+
import { AUTONOMY_TELEMETRY_EVENT_TYPES, redactTelemetryValue, } from "./autonomy/telemetry-events.js";
|
|
13
|
+
import { getRecentModelRouterDecisions } from "./model-router/status.js";
|
|
14
|
+
/** Custom-entry type for G3 autonomy telemetry. Distinct from the router/lane record types so a
|
|
15
|
+
* telemetry consumer can filter on it without decoding operational snapshots. */
|
|
16
|
+
const AUTONOMY_TELEMETRY_CUSTOM_TYPE = "autonomy-telemetry";
|
|
17
|
+
/** G8: bound on the in-memory gate-outcome history. Oldest entries evict once the cap is reached. */
|
|
18
|
+
const GATE_OUTCOME_HISTORY_LIMIT = 50;
|
|
19
|
+
export class AutonomyTelemetry {
|
|
20
|
+
_lastAutonomyGateOutcome;
|
|
21
|
+
/** G8: bounded (cap {@link GATE_OUTCOME_HISTORY_LIMIT}) history of gate outcomes; tail is latest. */
|
|
22
|
+
_gateOutcomeHistory = [];
|
|
23
|
+
deps;
|
|
24
|
+
constructor(deps) {
|
|
25
|
+
this.deps = deps;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* G3: bounded autonomy-telemetry sink. Passes the whole event through {@link redactTelemetryValue}
|
|
29
|
+
* (the taxonomy's redaction contract) before storing it, so a secret that leaked into a payload
|
|
30
|
+
* field never lands in the session log. Observe-only: a failure here can never surface into the
|
|
31
|
+
* turn it is measuring, so the whole body is swallowed. Payloads MUST stay small (ids, codes,
|
|
32
|
+
* numbers) — never prompt/summary text; callers own that discipline.
|
|
33
|
+
*/
|
|
34
|
+
emitTelemetry(event) {
|
|
35
|
+
try {
|
|
36
|
+
const redacted = redactTelemetryValue(event);
|
|
37
|
+
this.deps.getSessionManager().appendCustomEntry(AUTONOMY_TELEMETRY_CUSTOM_TYPE, { version: 1, ...redacted });
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Telemetry is best-effort: swallow so a sink failure cannot break the observed turn.
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* G8: single sink for a gate outcome. Keeps the latest-outcome getter behavior identical (the
|
|
45
|
+
* full {@link GateOutcome} still lands in `_lastAutonomyGateOutcome`), and additionally appends a
|
|
46
|
+
* bounded codes-only entry to {@link _gateOutcomeHistory} (oldest evicted at
|
|
47
|
+
* {@link GATE_OUTCOME_HISTORY_LIMIT}) and emits the `gate_outcome` telemetry event. The history
|
|
48
|
+
* tail therefore always mirrors the latest outcome. Only called with an active envelope.
|
|
49
|
+
*/
|
|
50
|
+
recordGateOutcome(outcome) {
|
|
51
|
+
this._lastAutonomyGateOutcome = outcome;
|
|
52
|
+
const at = new Date().toISOString();
|
|
53
|
+
this._gateOutcomeHistory.push({
|
|
54
|
+
outcome: outcome.outcome,
|
|
55
|
+
gate: outcome.gate,
|
|
56
|
+
reasonCode: outcome.reasonCode,
|
|
57
|
+
at,
|
|
58
|
+
});
|
|
59
|
+
while (this._gateOutcomeHistory.length > GATE_OUTCOME_HISTORY_LIMIT) {
|
|
60
|
+
this._gateOutcomeHistory.shift();
|
|
61
|
+
}
|
|
62
|
+
// G8: gate outcome event. Codes/ids only — never the gate's human-facing message.
|
|
63
|
+
this.emitTelemetry({
|
|
64
|
+
type: AUTONOMY_TELEMETRY_EVENT_TYPES.gateOutcome,
|
|
65
|
+
timestamp: at,
|
|
66
|
+
payload: {
|
|
67
|
+
outcome: outcome.outcome,
|
|
68
|
+
gate: outcome.gate,
|
|
69
|
+
reasonCode: outcome.reasonCode,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/** G8: copies of the bounded gate-outcome history, oldest first, latest last. */
|
|
74
|
+
getGateOutcomeHistory() {
|
|
75
|
+
return this._gateOutcomeHistory.map((entry) => ({ ...entry }));
|
|
76
|
+
}
|
|
77
|
+
getStatusSnapshot() {
|
|
78
|
+
const snapshot = {};
|
|
79
|
+
const lastRouterDecision = this.deps.getLastModelRouterDecision();
|
|
80
|
+
if (lastRouterDecision?.route) {
|
|
81
|
+
snapshot.latestRoute = {
|
|
82
|
+
tier: lastRouterDecision.route.tier,
|
|
83
|
+
reasonCode: lastRouterDecision.route.reasonCode,
|
|
84
|
+
risk: lastRouterDecision.route.risk,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (this._lastAutonomyGateOutcome) {
|
|
88
|
+
snapshot.latestGate = {
|
|
89
|
+
outcome: this._lastAutonomyGateOutcome.outcome,
|
|
90
|
+
gate: this._lastAutonomyGateOutcome.gate,
|
|
91
|
+
reasonCode: this._lastAutonomyGateOutcome.reasonCode,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const currentCost = this.deps.getSessionStats().cost;
|
|
95
|
+
if (currentCost > 0) {
|
|
96
|
+
snapshot.currentCostUsd = currentCost;
|
|
97
|
+
}
|
|
98
|
+
const spawnedCost = this.deps.getSpawnedUsage().cost;
|
|
99
|
+
if (spawnedCost > 0) {
|
|
100
|
+
snapshot.spawnedCostUsd = spawnedCost;
|
|
101
|
+
}
|
|
102
|
+
const dailyCost = this.deps.getDailyUsageTotals()?.totalCost;
|
|
103
|
+
if (dailyCost !== undefined && dailyCost > 0) {
|
|
104
|
+
snapshot.dailyCostUsd = dailyCost;
|
|
105
|
+
}
|
|
106
|
+
const goal = this.deps.getGoalStateSnapshot();
|
|
107
|
+
if (goal) {
|
|
108
|
+
snapshot.activeGoal = {
|
|
109
|
+
goalId: goal.goalId,
|
|
110
|
+
status: goal.status,
|
|
111
|
+
openRequirements: goal.requirements.filter((requirement) => requirement.status === "open").length,
|
|
112
|
+
stallTurns: goal.stallTurns,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
// Real live count from the lane tracker — never inferred from historical snapshots. Absent
|
|
116
|
+
// while zero, matching the presence-means-signal convention of the sibling fields.
|
|
117
|
+
const activeLaneCount = this.deps.getActiveLaneCount();
|
|
118
|
+
if (activeLaneCount > 0) {
|
|
119
|
+
snapshot.activeLaneCount = activeLaneCount;
|
|
120
|
+
}
|
|
121
|
+
return snapshot;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Aggregate an effectiveness/autonomy dashboard: what Pi has actually been doing (recent
|
|
125
|
+
* route choices, latest gate outcome, cost, and any research/delegation/learning/goal
|
|
126
|
+
* activity). Read-only — combines existing session-log getters, never mutates state or
|
|
127
|
+
* recomputes a route/gate decision.
|
|
128
|
+
*/
|
|
129
|
+
getDiagnosticSnapshot(options) {
|
|
130
|
+
const maxEntriesPerFamily = options?.maxEntriesPerFamily ?? 10;
|
|
131
|
+
const snapshot = {};
|
|
132
|
+
const goal = this.deps.getGoalStateSnapshot();
|
|
133
|
+
const recentDecisions = getRecentModelRouterDecisions(this.deps.getSessionManager().getEntries(), maxEntriesPerFamily);
|
|
134
|
+
if (recentDecisions.length > 0) {
|
|
135
|
+
snapshot.routes = recentDecisions.map((decision) => ({
|
|
136
|
+
title: decision.route.tier,
|
|
137
|
+
summary: decision.routedModel,
|
|
138
|
+
reasonCode: decision.route.reasonCode,
|
|
139
|
+
metadata: { risk: decision.route.risk, outcome: decision.outcome, intent: decision.intent },
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
if (this._lastAutonomyGateOutcome) {
|
|
143
|
+
const gate = this._lastAutonomyGateOutcome;
|
|
144
|
+
snapshot.gates = [
|
|
145
|
+
{
|
|
146
|
+
title: gate.gate,
|
|
147
|
+
summary: gate.message,
|
|
148
|
+
reasonCode: gate.reasonCode,
|
|
149
|
+
metadata: { outcome: gate.outcome, reversible: gate.reversible },
|
|
150
|
+
},
|
|
151
|
+
];
|
|
152
|
+
}
|
|
153
|
+
const costs = [];
|
|
154
|
+
const currentCostForDiagnostics = this.deps.getSessionStats().cost;
|
|
155
|
+
if (currentCostForDiagnostics > 0) {
|
|
156
|
+
costs.push({ title: "current", summary: `$${currentCostForDiagnostics.toFixed(4)}` });
|
|
157
|
+
}
|
|
158
|
+
const spawnedCost = this.deps.getSpawnedUsage().cost;
|
|
159
|
+
if (spawnedCost > 0)
|
|
160
|
+
costs.push({ title: "spawned", summary: `$${spawnedCost.toFixed(4)}` });
|
|
161
|
+
const dailyCostForDiagnostics = this.deps.getDailyUsageTotals()?.totalCost;
|
|
162
|
+
if (dailyCostForDiagnostics !== undefined && dailyCostForDiagnostics > 0) {
|
|
163
|
+
costs.push({ title: "daily", summary: `$${dailyCostForDiagnostics.toFixed(4)}` });
|
|
164
|
+
}
|
|
165
|
+
if (costs.length > 0)
|
|
166
|
+
snapshot.costs = costs;
|
|
167
|
+
const researchEntries = [];
|
|
168
|
+
const researchLaneRecords = getLaneRecordSnapshots(this.deps.getSessionManager().getEntries()).filter((record) => record.type === "research");
|
|
169
|
+
for (const record of researchLaneRecords.slice(-maxEntriesPerFamily)) {
|
|
170
|
+
researchEntries.push({
|
|
171
|
+
title: `Lane ${record.laneId} (${record.status})`,
|
|
172
|
+
reasonCode: record.reasonCode,
|
|
173
|
+
metadata: {
|
|
174
|
+
costUsd: record.costUsd,
|
|
175
|
+
startedAt: record.startedAt,
|
|
176
|
+
completedAt: record.completedAt,
|
|
177
|
+
goalId: record.goalId,
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
for (const bundle of this.deps.getEvidenceBundleSnapshots().slice(-maxEntriesPerFamily)) {
|
|
182
|
+
researchEntries.push({
|
|
183
|
+
title: `Research: ${bundle.query}`,
|
|
184
|
+
metadata: { sourceCount: bundle.sources.length, findingCount: bundle.findings.length },
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
if (this.deps.getLastResearchLaneSkipReason()) {
|
|
188
|
+
researchEntries.push({ title: "Last skip", reasonCode: this.deps.getLastResearchLaneSkipReason() });
|
|
189
|
+
}
|
|
190
|
+
if (researchEntries.length > 0) {
|
|
191
|
+
snapshot.research = researchEntries;
|
|
192
|
+
}
|
|
193
|
+
const delegationEntries = [];
|
|
194
|
+
const workerLaneRecords = getLaneRecordSnapshots(this.deps.getSessionManager().getEntries()).filter((record) => record.type === "worker");
|
|
195
|
+
for (const record of workerLaneRecords.slice(-maxEntriesPerFamily)) {
|
|
196
|
+
delegationEntries.push({
|
|
197
|
+
title: `Lane ${record.laneId} (${record.status})`,
|
|
198
|
+
reasonCode: record.reasonCode,
|
|
199
|
+
metadata: { costUsd: record.costUsd, startedAt: record.startedAt, completedAt: record.completedAt },
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
const workerResults = this.deps.getWorkerResultSnapshots();
|
|
203
|
+
for (const result of workerResults.slice(-maxEntriesPerFamily)) {
|
|
204
|
+
delegationEntries.push({
|
|
205
|
+
title: `Worker ${result.requestId} (${result.status})`,
|
|
206
|
+
summary: result.summary,
|
|
207
|
+
metadata: {
|
|
208
|
+
changedFileCount: result.changedFiles.length,
|
|
209
|
+
blockerCount: result.blockers?.length ?? 0,
|
|
210
|
+
usageReportId: result.usageReportId,
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (delegationEntries.length > 0) {
|
|
215
|
+
snapshot.delegation = delegationEntries;
|
|
216
|
+
}
|
|
217
|
+
const learningEntries = [];
|
|
218
|
+
const learningDecisions = this.deps.getLearningDecisionSnapshots();
|
|
219
|
+
for (const decision of learningDecisions.slice(-maxEntriesPerFamily)) {
|
|
220
|
+
learningEntries.push({
|
|
221
|
+
title: `Learning (${decision.kind})`,
|
|
222
|
+
summary: decision.summary,
|
|
223
|
+
reasonCode: decision.reasonCode,
|
|
224
|
+
metadata: { confidence: decision.confidence, requiresApproval: decision.requiresApproval },
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
for (const audit of this.deps.getLearningAuditRecords().slice(-maxEntriesPerFamily)) {
|
|
228
|
+
learningEntries.push({
|
|
229
|
+
title: `Audit ${audit.id} (${audit.action})`,
|
|
230
|
+
summary: audit.summary,
|
|
231
|
+
reasonCode: audit.reasonCode,
|
|
232
|
+
metadata: { layer: audit.layer, proposalId: audit.proposalId, rollbackOf: audit.rollbackOf },
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
if (learningEntries.length > 0) {
|
|
236
|
+
snapshot.learning = learningEntries;
|
|
237
|
+
}
|
|
238
|
+
if (goal) {
|
|
239
|
+
snapshot.goals = [
|
|
240
|
+
{
|
|
241
|
+
title: `Goal ${goal.goalId}`,
|
|
242
|
+
summary: goal.userGoal,
|
|
243
|
+
reasonCode: goal.status,
|
|
244
|
+
metadata: {
|
|
245
|
+
openRequirementCount: goal.requirements.filter((requirement) => requirement.status === "open").length,
|
|
246
|
+
stallTurns: goal.stallTurns,
|
|
247
|
+
blockedReason: goal.blockedReason,
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
];
|
|
251
|
+
}
|
|
252
|
+
const processMemory = getProcessMemoryMb();
|
|
253
|
+
snapshot.processMemory = [
|
|
254
|
+
{
|
|
255
|
+
title: "process",
|
|
256
|
+
metadata: {
|
|
257
|
+
rssMb: processMemory.rssMb,
|
|
258
|
+
heapUsedMb: processMemory.heapUsedMb,
|
|
259
|
+
externalMb: processMemory.externalMb,
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
];
|
|
263
|
+
return snapshot;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
//# sourceMappingURL=autonomy-telemetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autonomy-telemetry.js","sourceRoot":"","sources":["../../src/core/autonomy-telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAGhE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAO3E,OAAO,EACN,8BAA8B,EAE9B,oBAAoB,GACpB,MAAM,gCAAgC,CAAC;AAIxC,OAAO,EAAE,6BAA6B,EAAkC,MAAM,0BAA0B,CAAC;AAEzG;iFACiF;AACjF,MAAM,8BAA8B,GAAG,oBAAoB,CAAC;AAE5D,qGAAqG;AACrG,MAAM,0BAA0B,GAAG,EAAE,CAAC;AA6BtC,MAAM,OAAO,iBAAiB;IACrB,wBAAwB,CAAe;IAC/C,qGAAqG;IACpF,mBAAmB,GAA8B,EAAE,CAAC;IAEpD,IAAI,CAAwB;IAE7C,YAAY,IAA2B,EAAE;QACxC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IAAA,CACjB;IAED;;;;;;OAMG;IACH,aAAa,CAAC,KAA6B,EAAQ;QAClD,IAAI,CAAC;YACJ,MAAM,QAAQ,GAAG,oBAAoB,CAAC,KAAK,CAA4B,CAAC;YACxE,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,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AAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,QAAQ,CAAC,QAAQ,GAAG,eAAe,CAAC;QACrC,CAAC;QAED,IAAI,IAAI,EAAE,CAAC;YACV,QAAQ,CAAC,KAAK,GAAG;gBAChB;oBACC,KAAK,EAAE,QAAQ,IAAI,CAAC,MAAM,EAAE;oBAC5B,OAAO,EAAE,IAAI,CAAC,QAAQ;oBACtB,UAAU,EAAE,IAAI,CAAC,MAAM;oBACvB,QAAQ,EAAE;wBACT,oBAAoB,EAAE,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,MAAM;wBACrG,UAAU,EAAE,IAAI,CAAC,UAAU;wBAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;qBACjC;iBACD;aACD,CAAC;QACH,CAAC;QAED,MAAM,aAAa,GAAG,kBAAkB,EAAE,CAAC;QAC3C,QAAQ,CAAC,aAAa,GAAG;YACxB;gBACC,KAAK,EAAE,SAAS;gBAChB,QAAQ,EAAE;oBACT,KAAK,EAAE,aAAa,CAAC,KAAK;oBAC1B,UAAU,EAAE,aAAa,CAAC,UAAU;oBACpC,UAAU,EAAE,aAAa,CAAC,UAAU;iBACpC;aACD;SACD,CAAC;QAEF,OAAO,QAAQ,CAAC;IAAA,CAChB;CACD","sourcesContent":["/**\n * Autonomy telemetry sink + status/diagnostic snapshots.\n *\n * Extracted verbatim from agent-session.ts (god-file decomposition). Owns the latest gate outcome\n * and the bounded gate-outcome history, and is the single sink for G3 autonomy-telemetry custom\n * entries. The two snapshot builders READ broadly across live session state (router decision, cost,\n * goal, lanes, and the research/delegation/learning/goal getters) through narrow deps accessors\n * rather than the whole AgentSession — they never mutate anything but the owned gate-outcome fields.\n */\n\nimport type { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport { getProcessMemoryMb } from \"../utils/process-memory.ts\";\nimport type { SessionStats, SpawnedUsageTotals } from \"./agent-session.ts\";\nimport type { EvidenceBundle, GateOutcome, LearningDecision, WorkerResult } from \"./autonomy/contracts.ts\";\nimport { getLaneRecordSnapshots } from \"./autonomy/session-lane-record.ts\";\nimport type {\n\tAutonomyDiagnosticSnapshot,\n\tAutonomyStatusSnapshot,\n\tDiagnosticEntry,\n\tGateOutcomeHistoryEntry,\n} from \"./autonomy/status.ts\";\nimport {\n\tAUTONOMY_TELEMETRY_EVENT_TYPES,\n\ttype AutonomyTelemetryEvent,\n\tredactTelemetryValue,\n} from \"./autonomy/telemetry-events.ts\";\nimport type { DailyUsageTotals } from \"./cost/daily-usage.ts\";\nimport type { GoalState } from \"./goals/goal-state.ts\";\nimport type { LearningAuditRecord } from \"./learning/learning-audit.ts\";\nimport { getRecentModelRouterDecisions, type ModelRouterDecisionStatus } from \"./model-router/status.ts\";\n\n/** Custom-entry type for G3 autonomy telemetry. Distinct from the router/lane record types so a\n * telemetry consumer can filter on it without decoding operational snapshots. */\nconst AUTONOMY_TELEMETRY_CUSTOM_TYPE = \"autonomy-telemetry\";\n\n/** G8: bound on the in-memory gate-outcome history. Oldest entries evict once the cap is reached. */\nconst GATE_OUTCOME_HISTORY_LIMIT = 50;\n\nexport interface AutonomyTelemetryDeps {\n\t/** Session log: `appendCustomEntry` is the telemetry sink; `getEntries` feeds diagnostic aggregation. */\n\tgetSessionManager(): Pick<SessionManager, \"appendCustomEntry\" | \"getEntries\">;\n\t/** Latest model-router decision, for the snapshot's `latestRoute` — owned by the router, not this sink. */\n\tgetLastModelRouterDecision(): ModelRouterDecisionStatus | undefined;\n\t/** Reason the last research lane was skipped, if any — surfaced in the diagnostic's research family. */\n\tgetLastResearchLaneSkipReason(): string | undefined;\n\t/** This session's own usage totals (cost only is read). */\n\tgetSessionStats(): SessionStats;\n\t/** Spawned-child usage totals (cost only is read). */\n\tgetSpawnedUsage(): SpawnedUsageTotals;\n\t/** Cross-session daily usage totals, if trackable — preserves the source's optional-call semantics. */\n\tgetDailyUsageTotals(): DailyUsageTotals | undefined;\n\t/** Current goal state, if a goal is active. */\n\tgetGoalStateSnapshot(): GoalState | undefined;\n\t/** Live count of active lanes from the lane tracker — never inferred from historical snapshots. */\n\tgetActiveLaneCount(): number;\n\t/** Research evidence bundles recorded this session. */\n\tgetEvidenceBundleSnapshots(): EvidenceBundle[];\n\t/** Worker-delegation result snapshots recorded this session. */\n\tgetWorkerResultSnapshots(): WorkerResult[];\n\t/** Learning decision snapshots recorded this session. */\n\tgetLearningDecisionSnapshots(): LearningDecision[];\n\t/** Learning audit records recorded this session. */\n\tgetLearningAuditRecords(): LearningAuditRecord[];\n}\n\nexport class AutonomyTelemetry {\n\tprivate _lastAutonomyGateOutcome?: GateOutcome;\n\t/** G8: bounded (cap {@link GATE_OUTCOME_HISTORY_LIMIT}) history of gate outcomes; tail is latest. */\n\tprivate readonly _gateOutcomeHistory: GateOutcomeHistoryEntry[] = [];\n\n\tprivate readonly deps: AutonomyTelemetryDeps;\n\n\tconstructor(deps: AutonomyTelemetryDeps) {\n\t\tthis.deps = deps;\n\t}\n\n\t/**\n\t * G3: bounded autonomy-telemetry sink. Passes the whole event through {@link redactTelemetryValue}\n\t * (the taxonomy's redaction contract) before storing it, so a secret that leaked into a payload\n\t * field never lands in the session log. Observe-only: a failure here can never surface into the\n\t * turn it is measuring, so the whole body is swallowed. Payloads MUST stay small (ids, codes,\n\t * numbers) — never prompt/summary text; callers own that discipline.\n\t */\n\temitTelemetry(event: AutonomyTelemetryEvent): void {\n\t\ttry {\n\t\t\tconst redacted = redactTelemetryValue(event) as Record<string, unknown>;\n\t\t\tthis.deps.getSessionManager().appendCustomEntry(AUTONOMY_TELEMETRY_CUSTOM_TYPE, { version: 1, ...redacted });\n\t\t} catch {\n\t\t\t// Telemetry is best-effort: swallow so a sink failure cannot break the observed turn.\n\t\t}\n\t}\n\n\t/**\n\t * G8: single sink for a gate outcome. Keeps the latest-outcome getter behavior identical (the\n\t * full {@link GateOutcome} still lands in `_lastAutonomyGateOutcome`), and additionally appends a\n\t * bounded codes-only entry to {@link _gateOutcomeHistory} (oldest evicted at\n\t * {@link GATE_OUTCOME_HISTORY_LIMIT}) and emits the `gate_outcome` telemetry event. The history\n\t * tail therefore always mirrors the latest outcome. Only called with an active envelope.\n\t */\n\trecordGateOutcome(outcome: GateOutcome): void {\n\t\tthis._lastAutonomyGateOutcome = outcome;\n\t\tconst at = new Date().toISOString();\n\t\tthis._gateOutcomeHistory.push({\n\t\t\toutcome: outcome.outcome,\n\t\t\tgate: outcome.gate,\n\t\t\treasonCode: outcome.reasonCode,\n\t\t\tat,\n\t\t});\n\t\twhile (this._gateOutcomeHistory.length > GATE_OUTCOME_HISTORY_LIMIT) {\n\t\t\tthis._gateOutcomeHistory.shift();\n\t\t}\n\t\t// G8: gate outcome event. Codes/ids only — never the gate's human-facing message.\n\t\tthis.emitTelemetry({\n\t\t\ttype: AUTONOMY_TELEMETRY_EVENT_TYPES.gateOutcome,\n\t\t\ttimestamp: at,\n\t\t\tpayload: {\n\t\t\t\toutcome: outcome.outcome,\n\t\t\t\tgate: outcome.gate,\n\t\t\t\treasonCode: outcome.reasonCode,\n\t\t\t},\n\t\t});\n\t}\n\n\t/** G8: copies of the bounded gate-outcome history, oldest first, latest last. */\n\tgetGateOutcomeHistory(): GateOutcomeHistoryEntry[] {\n\t\treturn this._gateOutcomeHistory.map((entry) => ({ ...entry }));\n\t}\n\n\tgetStatusSnapshot(): AutonomyStatusSnapshot {\n\t\tconst snapshot: AutonomyStatusSnapshot = {};\n\n\t\tconst lastRouterDecision = this.deps.getLastModelRouterDecision();\n\t\tif (lastRouterDecision?.route) {\n\t\t\tsnapshot.latestRoute = {\n\t\t\t\ttier: lastRouterDecision.route.tier,\n\t\t\t\treasonCode: lastRouterDecision.route.reasonCode,\n\t\t\t\trisk: lastRouterDecision.route.risk,\n\t\t\t};\n\t\t}\n\n\t\tif (this._lastAutonomyGateOutcome) {\n\t\t\tsnapshot.latestGate = {\n\t\t\t\toutcome: this._lastAutonomyGateOutcome.outcome,\n\t\t\t\tgate: this._lastAutonomyGateOutcome.gate,\n\t\t\t\treasonCode: this._lastAutonomyGateOutcome.reasonCode,\n\t\t\t};\n\t\t}\n\n\t\tconst currentCost = this.deps.getSessionStats().cost;\n\t\tif (currentCost > 0) {\n\t\t\tsnapshot.currentCostUsd = currentCost;\n\t\t}\n\n\t\tconst spawnedCost = this.deps.getSpawnedUsage().cost;\n\t\tif (spawnedCost > 0) {\n\t\t\tsnapshot.spawnedCostUsd = spawnedCost;\n\t\t}\n\n\t\tconst dailyCost = this.deps.getDailyUsageTotals()?.totalCost;\n\t\tif (dailyCost !== undefined && dailyCost > 0) {\n\t\t\tsnapshot.dailyCostUsd = dailyCost;\n\t\t}\n\n\t\tconst goal = this.deps.getGoalStateSnapshot();\n\t\tif (goal) {\n\t\t\tsnapshot.activeGoal = {\n\t\t\t\tgoalId: goal.goalId,\n\t\t\t\tstatus: goal.status,\n\t\t\t\topenRequirements: goal.requirements.filter((requirement) => requirement.status === \"open\").length,\n\t\t\t\tstallTurns: goal.stallTurns,\n\t\t\t};\n\t\t}\n\n\t\t// Real live count from the lane tracker — never inferred from historical snapshots. Absent\n\t\t// while zero, matching the presence-means-signal convention of the sibling fields.\n\t\tconst activeLaneCount = this.deps.getActiveLaneCount();\n\t\tif (activeLaneCount > 0) {\n\t\t\tsnapshot.activeLaneCount = activeLaneCount;\n\t\t}\n\n\t\treturn snapshot;\n\t}\n\n\t/**\n\t * Aggregate an effectiveness/autonomy dashboard: what Pi has actually been doing (recent\n\t * route choices, latest gate outcome, cost, and any research/delegation/learning/goal\n\t * activity). Read-only — combines existing session-log getters, never mutates state or\n\t * recomputes a route/gate decision.\n\t */\n\tgetDiagnosticSnapshot(options?: { maxEntriesPerFamily?: number }): AutonomyDiagnosticSnapshot {\n\t\tconst maxEntriesPerFamily = options?.maxEntriesPerFamily ?? 10;\n\t\tconst snapshot: AutonomyDiagnosticSnapshot = {};\n\t\tconst goal = this.deps.getGoalStateSnapshot();\n\n\t\tconst recentDecisions = getRecentModelRouterDecisions(\n\t\t\tthis.deps.getSessionManager().getEntries(),\n\t\t\tmaxEntriesPerFamily,\n\t\t);\n\t\tif (recentDecisions.length > 0) {\n\t\t\tsnapshot.routes = recentDecisions.map(\n\t\t\t\t(decision): DiagnosticEntry => ({\n\t\t\t\t\ttitle: decision.route.tier,\n\t\t\t\t\tsummary: decision.routedModel,\n\t\t\t\t\treasonCode: decision.route.reasonCode,\n\t\t\t\t\tmetadata: { risk: decision.route.risk, outcome: decision.outcome, intent: decision.intent },\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tif (this._lastAutonomyGateOutcome) {\n\t\t\tconst gate = this._lastAutonomyGateOutcome;\n\t\t\tsnapshot.gates = [\n\t\t\t\t{\n\t\t\t\t\ttitle: gate.gate,\n\t\t\t\t\tsummary: gate.message,\n\t\t\t\t\treasonCode: gate.reasonCode,\n\t\t\t\t\tmetadata: { outcome: gate.outcome, reversible: gate.reversible },\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tconst costs: DiagnosticEntry[] = [];\n\t\tconst currentCostForDiagnostics = this.deps.getSessionStats().cost;\n\t\tif (currentCostForDiagnostics > 0) {\n\t\t\tcosts.push({ title: \"current\", summary: `$${currentCostForDiagnostics.toFixed(4)}` });\n\t\t}\n\t\tconst spawnedCost = this.deps.getSpawnedUsage().cost;\n\t\tif (spawnedCost > 0) costs.push({ title: \"spawned\", summary: `$${spawnedCost.toFixed(4)}` });\n\t\tconst dailyCostForDiagnostics = this.deps.getDailyUsageTotals()?.totalCost;\n\t\tif (dailyCostForDiagnostics !== undefined && dailyCostForDiagnostics > 0) {\n\t\t\tcosts.push({ title: \"daily\", summary: `$${dailyCostForDiagnostics.toFixed(4)}` });\n\t\t}\n\t\tif (costs.length > 0) snapshot.costs = costs;\n\n\t\tconst researchEntries: DiagnosticEntry[] = [];\n\t\tconst researchLaneRecords = getLaneRecordSnapshots(this.deps.getSessionManager().getEntries()).filter(\n\t\t\t(record) => record.type === \"research\",\n\t\t);\n\t\tfor (const record of researchLaneRecords.slice(-maxEntriesPerFamily)) {\n\t\t\tresearchEntries.push({\n\t\t\t\ttitle: `Lane ${record.laneId} (${record.status})`,\n\t\t\t\treasonCode: record.reasonCode,\n\t\t\t\tmetadata: {\n\t\t\t\t\tcostUsd: record.costUsd,\n\t\t\t\t\tstartedAt: record.startedAt,\n\t\t\t\t\tcompletedAt: record.completedAt,\n\t\t\t\t\tgoalId: record.goalId,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tfor (const bundle of this.deps.getEvidenceBundleSnapshots().slice(-maxEntriesPerFamily)) {\n\t\t\tresearchEntries.push({\n\t\t\t\ttitle: `Research: ${bundle.query}`,\n\t\t\t\tmetadata: { sourceCount: bundle.sources.length, findingCount: bundle.findings.length },\n\t\t\t});\n\t\t}\n\t\tif (this.deps.getLastResearchLaneSkipReason()) {\n\t\t\tresearchEntries.push({ title: \"Last skip\", reasonCode: this.deps.getLastResearchLaneSkipReason() });\n\t\t}\n\t\tif (researchEntries.length > 0) {\n\t\t\tsnapshot.research = researchEntries;\n\t\t}\n\n\t\tconst delegationEntries: DiagnosticEntry[] = [];\n\t\tconst workerLaneRecords = getLaneRecordSnapshots(this.deps.getSessionManager().getEntries()).filter(\n\t\t\t(record) => record.type === \"worker\",\n\t\t);\n\t\tfor (const record of workerLaneRecords.slice(-maxEntriesPerFamily)) {\n\t\t\tdelegationEntries.push({\n\t\t\t\ttitle: `Lane ${record.laneId} (${record.status})`,\n\t\t\t\treasonCode: record.reasonCode,\n\t\t\t\tmetadata: { costUsd: record.costUsd, startedAt: record.startedAt, completedAt: record.completedAt },\n\t\t\t});\n\t\t}\n\t\tconst workerResults = this.deps.getWorkerResultSnapshots();\n\t\tfor (const result of workerResults.slice(-maxEntriesPerFamily)) {\n\t\t\tdelegationEntries.push({\n\t\t\t\ttitle: `Worker ${result.requestId} (${result.status})`,\n\t\t\t\tsummary: result.summary,\n\t\t\t\tmetadata: {\n\t\t\t\t\tchangedFileCount: result.changedFiles.length,\n\t\t\t\t\tblockerCount: result.blockers?.length ?? 0,\n\t\t\t\t\tusageReportId: result.usageReportId,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t\tif (delegationEntries.length > 0) {\n\t\t\tsnapshot.delegation = delegationEntries;\n\t\t}\n\n\t\tconst learningEntries: DiagnosticEntry[] = [];\n\t\tconst learningDecisions = this.deps.getLearningDecisionSnapshots();\n\t\tfor (const decision of learningDecisions.slice(-maxEntriesPerFamily)) {\n\t\t\tlearningEntries.push({\n\t\t\t\ttitle: `Learning (${decision.kind})`,\n\t\t\t\tsummary: decision.summary,\n\t\t\t\treasonCode: decision.reasonCode,\n\t\t\t\tmetadata: { confidence: decision.confidence, requiresApproval: decision.requiresApproval },\n\t\t\t});\n\t\t}\n\t\tfor (const audit of this.deps.getLearningAuditRecords().slice(-maxEntriesPerFamily)) {\n\t\t\tlearningEntries.push({\n\t\t\t\ttitle: `Audit ${audit.id} (${audit.action})`,\n\t\t\t\tsummary: audit.summary,\n\t\t\t\treasonCode: audit.reasonCode,\n\t\t\t\tmetadata: { layer: audit.layer, proposalId: audit.proposalId, rollbackOf: audit.rollbackOf },\n\t\t\t});\n\t\t}\n\t\tif (learningEntries.length > 0) {\n\t\t\tsnapshot.learning = learningEntries;\n\t\t}\n\n\t\tif (goal) {\n\t\t\tsnapshot.goals = [\n\t\t\t\t{\n\t\t\t\t\ttitle: `Goal ${goal.goalId}`,\n\t\t\t\t\tsummary: goal.userGoal,\n\t\t\t\t\treasonCode: goal.status,\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\topenRequirementCount: goal.requirements.filter((requirement) => requirement.status === \"open\").length,\n\t\t\t\t\t\tstallTurns: goal.stallTurns,\n\t\t\t\t\t\tblockedReason: goal.blockedReason,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t];\n\t\t}\n\n\t\tconst processMemory = getProcessMemoryMb();\n\t\tsnapshot.processMemory = [\n\t\t\t{\n\t\t\t\ttitle: \"process\",\n\t\t\t\tmetadata: {\n\t\t\t\t\trssMb: processMemory.rssMb,\n\t\t\t\t\theapUsedMb: processMemory.heapUsedMb,\n\t\t\t\t\texternalMb: processMemory.externalMb,\n\t\t\t\t},\n\t\t\t},\n\t\t];\n\n\t\treturn snapshot;\n\t}\n}\n"]}
|