@caupulican/pi-adaptative 0.81.39 → 0.81.40
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 +52 -0
- package/README.md +2 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts +2 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js +2 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.ts +3 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts +9 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +290 -107
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +357 -122
- package/dist/bundled-resources/skills/tool-call-repair/references/repair-catalogue.md +2 -2
- package/dist/cli/args.d.ts +2 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +9 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-directory-layout.d.ts +15 -0
- package/dist/core/agent-directory-layout.d.ts.map +1 -0
- package/dist/core/agent-directory-layout.js +72 -0
- package/dist/core/agent-directory-layout.js.map +1 -0
- package/dist/core/agent-paths.d.ts +19 -2
- package/dist/core/agent-paths.d.ts.map +1 -1
- package/dist/core/agent-paths.js +67 -4
- package/dist/core/agent-paths.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +52 -8
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +397 -79
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +1 -0
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +1 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +71 -136
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +477 -1318
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/approval-gate.d.ts +3 -2
- package/dist/core/autonomy/approval-gate.d.ts.map +1 -1
- package/dist/core/autonomy/approval-gate.js +6 -28
- package/dist/core/autonomy/approval-gate.js.map +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
- package/dist/core/autonomy/bounded-completion.js +1 -1
- package/dist/core/autonomy/bounded-completion.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts +20 -12
- package/dist/core/autonomy/contracts.d.ts.map +1 -1
- package/dist/core/autonomy/contracts.js.map +1 -1
- package/dist/core/autonomy/foreground-envelope.d.ts +8 -2
- package/dist/core/autonomy/foreground-envelope.d.ts.map +1 -1
- package/dist/core/autonomy/foreground-envelope.js +8 -25
- package/dist/core/autonomy/foreground-envelope.js.map +1 -1
- package/dist/core/autonomy/gates.d.ts.map +1 -1
- package/dist/core/autonomy/gates.js +8 -10
- package/dist/core/autonomy/gates.js.map +1 -1
- package/dist/core/autonomy/lane-private-paths.d.ts +2 -0
- package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -0
- package/dist/core/autonomy/lane-private-paths.js +16 -0
- package/dist/core/autonomy/lane-private-paths.js.map +1 -0
- package/dist/core/autonomy/lane-tool-surface.d.ts +10 -0
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +46 -8
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/autonomy/lane-tracker.d.ts +14 -0
- package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tracker.js +38 -0
- package/dist/core/autonomy/lane-tracker.js.map +1 -1
- package/dist/core/autonomy/risk-assessment.d.ts +1 -2
- package/dist/core/autonomy/risk-assessment.d.ts.map +1 -1
- package/dist/core/autonomy/risk-assessment.js +1 -123
- package/dist/core/autonomy/risk-assessment.js.map +1 -1
- package/dist/core/autonomy/session-lane-record.d.ts +4 -4
- package/dist/core/autonomy/session-lane-record.d.ts.map +1 -1
- package/dist/core/autonomy/session-lane-record.js +16 -29
- package/dist/core/autonomy/session-lane-record.js.map +1 -1
- package/dist/core/autonomy/telemetry-events.d.ts +1 -1
- package/dist/core/autonomy/telemetry-events.d.ts.map +1 -1
- package/dist/core/autonomy/telemetry-events.js +1 -1
- package/dist/core/autonomy/telemetry-events.js.map +1 -1
- package/dist/core/autonomy-telemetry.d.ts +7 -7
- package/dist/core/autonomy-telemetry.d.ts.map +1 -1
- package/dist/core/autonomy-telemetry.js +9 -9
- package/dist/core/autonomy-telemetry.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +54 -236
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +140 -1273
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/capability-contract.d.ts +4 -0
- package/dist/core/capability-contract.d.ts.map +1 -0
- package/dist/core/capability-contract.js +28 -0
- package/dist/core/capability-contract.js.map +1 -0
- package/dist/core/compaction-controller.d.ts +90 -0
- package/dist/core/compaction-controller.d.ts.map +1 -0
- package/dist/core/compaction-controller.js +452 -0
- package/dist/core/compaction-controller.js.map +1 -0
- package/dist/core/compaction-support.d.ts +12 -11
- package/dist/core/compaction-support.d.ts.map +1 -1
- package/dist/core/compaction-support.js.map +1 -1
- package/dist/core/context/context-artifacts.d.ts +6 -2
- package/dist/core/context/context-artifacts.d.ts.map +1 -1
- package/dist/core/context/context-artifacts.js +34 -2
- package/dist/core/context/context-artifacts.js.map +1 -1
- package/dist/core/context/context-store-retention.d.ts +8 -2
- package/dist/core/context/context-store-retention.d.ts.map +1 -1
- package/dist/core/context/context-store-retention.js +158 -35
- package/dist/core/context/context-store-retention.js.map +1 -1
- package/dist/core/context/okf-memory.d.ts.map +1 -1
- package/dist/core/context/okf-memory.js +9 -11
- package/dist/core/context/okf-memory.js.map +1 -1
- package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -1
- package/dist/core/context/sqlite-runtime-index.js +6 -8
- package/dist/core/context/sqlite-runtime-index.js.map +1 -1
- package/dist/core/context-gc.d.ts +3 -0
- package/dist/core/context-gc.d.ts.map +1 -1
- package/dist/core/context-gc.js +10 -5
- package/dist/core/context-gc.js.map +1 -1
- package/dist/core/context-pipeline.d.ts.map +1 -1
- package/dist/core/context-pipeline.js +9 -4
- package/dist/core/context-pipeline.js.map +1 -1
- package/dist/core/default-tool-surface.d.ts.map +1 -1
- package/dist/core/default-tool-surface.js +1 -0
- package/dist/core/default-tool-surface.js.map +1 -1
- package/dist/core/delegation/managed-lane-controller.d.ts +34 -0
- package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -0
- package/dist/core/delegation/managed-lane-controller.js +217 -0
- package/dist/core/delegation/managed-lane-controller.js.map +1 -0
- package/dist/core/delegation/session-worker-claim.d.ts +44 -0
- package/dist/core/delegation/session-worker-claim.d.ts.map +1 -0
- package/dist/core/delegation/session-worker-claim.js +98 -0
- package/dist/core/delegation/session-worker-claim.js.map +1 -0
- package/dist/core/delegation/worker-actions.d.ts +7 -5
- package/dist/core/delegation/worker-actions.d.ts.map +1 -1
- package/dist/core/delegation/worker-actions.js +20 -4
- package/dist/core/delegation/worker-actions.js.map +1 -1
- package/dist/core/delegation/{worker-result.d.ts → worker-claim.d.ts} +13 -13
- package/dist/core/delegation/worker-claim.d.ts.map +1 -0
- package/dist/core/delegation/{worker-result.js → worker-claim.js} +61 -51
- package/dist/core/delegation/worker-claim.js.map +1 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts +110 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -0
- package/dist/core/delegation/worker-delegation-controller.js +861 -0
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -0
- package/dist/core/delegation/worker-delegation-request.d.ts +11 -0
- package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -0
- package/dist/core/delegation/worker-delegation-request.js +2 -0
- package/dist/core/delegation/worker-delegation-request.js.map +1 -0
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts +40 -0
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -0
- package/dist/core/delegation/worker-dispatch-scheduler.js +93 -0
- package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -0
- package/dist/core/delegation/worker-execution-policy.d.ts +62 -0
- package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -0
- package/dist/core/delegation/worker-execution-policy.js +160 -0
- package/dist/core/delegation/worker-execution-policy.js.map +1 -0
- package/dist/core/delegation/worker-lane-projection.d.ts +14 -0
- package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -0
- package/dist/core/delegation/worker-lane-projection.js +100 -0
- package/dist/core/delegation/worker-lane-projection.js.map +1 -0
- package/dist/core/delegation/worker-lifecycle.d.ts +97 -0
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -0
- package/dist/core/delegation/worker-lifecycle.js +339 -0
- package/dist/core/delegation/worker-lifecycle.js.map +1 -0
- package/dist/core/delegation/worker-notification-coordinator.d.ts +36 -0
- package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-notification-coordinator.js +90 -0
- package/dist/core/delegation/worker-notification-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts +55 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -0
- package/dist/core/delegation/worker-profile-resolver.js +113 -0
- package/dist/core/delegation/worker-profile-resolver.js.map +1 -0
- package/dist/core/delegation/worker-runner.d.ts +25 -14
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +122 -53
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-task-label.d.ts +3 -0
- package/dist/core/delegation/worker-task-label.d.ts.map +1 -0
- package/dist/core/delegation/worker-task-label.js +11 -0
- package/dist/core/delegation/worker-task-label.js.map +1 -0
- package/dist/core/doctor.d.ts +8 -0
- package/dist/core/doctor.d.ts.map +1 -1
- package/dist/core/doctor.js +32 -1
- package/dist/core/doctor.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +5 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +50 -15
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +6 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/storage.d.ts +8 -0
- package/dist/core/extensions/storage.d.ts.map +1 -0
- package/dist/core/extensions/storage.js +28 -0
- package/dist/core/extensions/storage.js.map +1 -0
- package/dist/core/extensions/types.d.ts +70 -21
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/failure-corpus.d.ts +1 -15
- package/dist/core/failure-corpus.d.ts.map +1 -1
- package/dist/core/failure-corpus.js +9 -37
- package/dist/core/failure-corpus.js.map +1 -1
- package/dist/core/foreground-recovery-controller.d.ts +52 -0
- package/dist/core/foreground-recovery-controller.d.ts.map +1 -0
- package/dist/core/foreground-recovery-controller.js +111 -0
- package/dist/core/foreground-recovery-controller.js.map +1 -0
- package/dist/core/gateways/channel-provider.d.ts +3 -0
- package/dist/core/gateways/channel-provider.d.ts.map +1 -1
- package/dist/core/gateways/channel-provider.js +31 -6
- package/dist/core/gateways/channel-provider.js.map +1 -1
- package/dist/core/goals/goal-acceptance.d.ts +11 -0
- package/dist/core/goals/goal-acceptance.d.ts.map +1 -0
- package/dist/core/goals/goal-acceptance.js +25 -0
- package/dist/core/goals/goal-acceptance.js.map +1 -0
- package/dist/core/goals/goal-auto-continue-controller.d.ts +27 -0
- package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -0
- package/dist/core/goals/goal-auto-continue-controller.js +93 -0
- package/dist/core/goals/goal-auto-continue-controller.js.map +1 -0
- package/dist/core/goals/goal-continuation-controller.d.ts +1 -1
- package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-controller.js +10 -0
- package/dist/core/goals/goal-continuation-controller.js.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.d.ts +1 -1
- package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.js +6 -6
- package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
- package/dist/core/goals/goal-lifecycle.d.ts +20 -0
- package/dist/core/goals/goal-lifecycle.d.ts.map +1 -0
- package/dist/core/goals/goal-lifecycle.js +17 -0
- package/dist/core/goals/goal-lifecycle.js.map +1 -0
- package/dist/core/goals/goal-runtime-snapshot.d.ts +11 -9
- package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
- package/dist/core/goals/goal-runtime-snapshot.js +10 -8
- package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
- package/dist/core/goals/goal-state.d.ts +1 -0
- package/dist/core/goals/goal-state.d.ts.map +1 -1
- package/dist/core/goals/goal-state.js +7 -10
- package/dist/core/goals/goal-state.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts +8 -6
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js +11 -41
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/goals/session-goal-state.d.ts +2 -4
- package/dist/core/goals/session-goal-state.d.ts.map +1 -1
- package/dist/core/goals/session-goal-state.js +10 -33
- package/dist/core/goals/session-goal-state.js.map +1 -1
- package/dist/core/human-input.d.ts +100 -0
- package/dist/core/human-input.d.ts.map +1 -0
- package/dist/core/human-input.js +362 -0
- package/dist/core/human-input.js.map +1 -0
- package/dist/core/index.d.ts +9 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +9 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/{telemetry.d.ts → install-telemetry.d.ts} +1 -1
- package/dist/core/install-telemetry.d.ts.map +1 -0
- package/dist/core/{telemetry.js → install-telemetry.js} +1 -1
- package/dist/core/install-telemetry.js.map +1 -0
- package/dist/core/keybindings.d.ts +17 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +24 -6
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/learning/learning-audit.d.ts +2 -4
- package/dist/core/learning/learning-audit.d.ts.map +1 -1
- package/dist/core/learning/learning-audit.js +9 -29
- package/dist/core/learning/learning-audit.js.map +1 -1
- package/dist/core/learning/learning-gate.d.ts.map +1 -1
- package/dist/core/learning/learning-gate.js +1 -6
- package/dist/core/learning/learning-gate.js.map +1 -1
- package/dist/core/learning/session-learning-decision.d.ts +2 -4
- package/dist/core/learning/session-learning-decision.d.ts.map +1 -1
- package/dist/core/learning/session-learning-decision.js +9 -29
- package/dist/core/learning/session-learning-decision.js.map +1 -1
- package/dist/core/memory-controller.d.ts.map +1 -1
- package/dist/core/memory-controller.js +4 -4
- package/dist/core/memory-controller.js.map +1 -1
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js +1 -0
- package/dist/core/model-capability.js.map +1 -1
- package/dist/core/model-resolver.d.ts +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +6 -9
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-router/intent-classifier.d.ts +1 -4
- package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
- package/dist/core/model-router/intent-classifier.js +1 -156
- package/dist/core/model-router/intent-classifier.js.map +1 -1
- package/dist/core/model-router-controller.d.ts.map +1 -1
- package/dist/core/model-router-controller.js +2 -2
- package/dist/core/model-router-controller.js.map +1 -1
- package/dist/core/model-selection-controller.d.ts +4 -4
- package/dist/core/model-selection-controller.d.ts.map +1 -1
- package/dist/core/model-selection-controller.js.map +1 -1
- package/dist/core/model-tool-protocol.d.ts +23 -0
- package/dist/core/model-tool-protocol.d.ts.map +1 -0
- package/dist/core/model-tool-protocol.js +43 -0
- package/dist/core/model-tool-protocol.js.map +1 -0
- package/dist/core/models/adaptation-store.d.ts +4 -6
- package/dist/core/models/adaptation-store.d.ts.map +1 -1
- package/dist/core/models/adaptation-store.js +95 -83
- package/dist/core/models/adaptation-store.js.map +1 -1
- package/dist/core/models/fitness-store.d.ts +2 -12
- package/dist/core/models/fitness-store.d.ts.map +1 -1
- package/dist/core/models/fitness-store.js +84 -57
- package/dist/core/models/fitness-store.js.map +1 -1
- package/dist/core/models/host-state-store.d.ts +34 -0
- package/dist/core/models/host-state-store.d.ts.map +1 -0
- package/dist/core/models/host-state-store.js +86 -0
- package/dist/core/models/host-state-store.js.map +1 -0
- package/dist/core/orchestration/agent-resume.d.ts +24 -0
- package/dist/core/orchestration/agent-resume.d.ts.map +1 -0
- package/dist/core/orchestration/agent-resume.js +90 -0
- package/dist/core/orchestration/agent-resume.js.map +1 -0
- package/dist/core/orchestration/capability-gateway.d.ts +61 -0
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -0
- package/dist/core/orchestration/capability-gateway.js +152 -0
- package/dist/core/orchestration/capability-gateway.js.map +1 -0
- package/dist/core/orchestration/contracts.d.ts +343 -0
- package/dist/core/orchestration/contracts.d.ts.map +1 -0
- package/dist/core/orchestration/contracts.js +135 -0
- package/dist/core/orchestration/contracts.js.map +1 -0
- package/dist/core/orchestration/delegation-ledger.d.ts +56 -0
- package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -0
- package/dist/core/orchestration/delegation-ledger.js +197 -0
- package/dist/core/orchestration/delegation-ledger.js.map +1 -0
- package/dist/core/orchestration/event-store.d.ts +83 -0
- package/dist/core/orchestration/event-store.d.ts.map +1 -0
- package/dist/core/orchestration/event-store.js +560 -0
- package/dist/core/orchestration/event-store.js.map +1 -0
- package/dist/core/orchestration/lane-tool-manifests.d.ts +9 -0
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -0
- package/dist/core/orchestration/lane-tool-manifests.js +37 -0
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -0
- package/dist/core/orchestration/model-binding.d.ts +15 -0
- package/dist/core/orchestration/model-binding.d.ts.map +1 -0
- package/dist/core/orchestration/model-binding.js +29 -0
- package/dist/core/orchestration/model-binding.js.map +1 -0
- package/dist/core/orchestration/policy-compiler.d.ts +49 -0
- package/dist/core/orchestration/policy-compiler.d.ts.map +1 -0
- package/dist/core/orchestration/policy-compiler.js +191 -0
- package/dist/core/orchestration/policy-compiler.js.map +1 -0
- package/dist/core/orchestration/policy-gate.d.ts +18 -0
- package/dist/core/orchestration/policy-gate.d.ts.map +1 -0
- package/dist/core/orchestration/policy-gate.js +24 -0
- package/dist/core/orchestration/policy-gate.js.map +1 -0
- package/dist/core/orchestration/profile-registry.d.ts +51 -0
- package/dist/core/orchestration/profile-registry.d.ts.map +1 -0
- package/dist/core/orchestration/profile-registry.js +393 -0
- package/dist/core/orchestration/profile-registry.js.map +1 -0
- package/dist/core/orchestration/profile-store.d.ts +31 -0
- package/dist/core/orchestration/profile-store.d.ts.map +1 -0
- package/dist/core/orchestration/profile-store.js +136 -0
- package/dist/core/orchestration/profile-store.js.map +1 -0
- package/dist/core/orchestration/risk-budget.d.ts +9 -0
- package/dist/core/orchestration/risk-budget.d.ts.map +1 -0
- package/dist/core/orchestration/risk-budget.js +48 -0
- package/dist/core/orchestration/risk-budget.js.map +1 -0
- package/dist/core/orchestration/task-runtime.d.ts +168 -0
- package/dist/core/orchestration/task-runtime.d.ts.map +1 -0
- package/dist/core/orchestration/task-runtime.js +1600 -0
- package/dist/core/orchestration/task-runtime.js.map +1 -0
- package/dist/core/orchestration/work-state-projection.d.ts +32 -0
- package/dist/core/orchestration/work-state-projection.d.ts.map +1 -0
- package/dist/core/orchestration/work-state-projection.js +116 -0
- package/dist/core/orchestration/work-state-projection.js.map +1 -0
- package/dist/core/orchestration/worker-execution-contract.d.ts +21 -0
- package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -0
- package/dist/core/orchestration/worker-execution-contract.js +179 -0
- package/dist/core/orchestration/worker-execution-contract.js.map +1 -0
- package/dist/core/orchestration/worker-result-adapter.d.ts +21 -0
- package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -0
- package/dist/core/orchestration/worker-result-adapter.js +109 -0
- package/dist/core/orchestration/worker-result-adapter.js.map +1 -0
- package/dist/core/process-identity.d.ts +11 -0
- package/dist/core/process-identity.d.ts.map +1 -0
- package/dist/core/process-identity.js +26 -0
- package/dist/core/process-identity.js.map +1 -0
- package/dist/core/process-matrix/codes.d.ts +14 -3
- package/dist/core/process-matrix/codes.d.ts.map +1 -1
- package/dist/core/process-matrix/codes.js.map +1 -1
- package/dist/core/process-matrix/resume-launcher.d.ts +26 -0
- package/dist/core/process-matrix/resume-launcher.d.ts.map +1 -0
- package/dist/core/process-matrix/resume-launcher.js +62 -0
- package/dist/core/process-matrix/resume-launcher.js.map +1 -0
- package/dist/core/process-matrix/runtime.d.ts +37 -22
- package/dist/core/process-matrix/runtime.d.ts.map +1 -1
- package/dist/core/process-matrix/runtime.js +399 -76
- package/dist/core/process-matrix/runtime.js.map +1 -1
- package/dist/core/process-matrix/store.d.ts +5 -2
- package/dist/core/process-matrix/store.d.ts.map +1 -1
- package/dist/core/process-matrix/store.js +123 -14
- package/dist/core/process-matrix/store.js.map +1 -1
- package/dist/core/process-matrix/supervisor.d.ts +10 -7
- package/dist/core/process-matrix/supervisor.d.ts.map +1 -1
- package/dist/core/process-matrix/supervisor.js +45 -14
- package/dist/core/process-matrix/supervisor.js.map +1 -1
- package/dist/core/profile-registry.d.ts.map +1 -1
- package/dist/core/profile-registry.js +6 -8
- package/dist/core/profile-registry.js.map +1 -1
- package/dist/core/reflection-controller.d.ts +4 -4
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +2 -1
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/reload-blockers.d.ts.map +1 -1
- package/dist/core/reload-blockers.js +6 -8
- package/dist/core/reload-blockers.js.map +1 -1
- package/dist/core/research/evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/evidence-bundle.js +1 -6
- package/dist/core/research/evidence-bundle.js.map +1 -1
- package/dist/core/research/lane-model-resolver.d.ts +33 -0
- package/dist/core/research/lane-model-resolver.d.ts.map +1 -0
- package/dist/core/research/lane-model-resolver.js +65 -0
- package/dist/core/research/lane-model-resolver.js.map +1 -0
- package/dist/core/research/model-fitness-controller.d.ts +38 -0
- package/dist/core/research/model-fitness-controller.d.ts.map +1 -0
- package/dist/core/research/model-fitness-controller.js +106 -0
- package/dist/core/research/model-fitness-controller.js.map +1 -0
- package/dist/core/research/model-fitness.d.ts +1 -1
- package/dist/core/research/model-fitness.d.ts.map +1 -1
- package/dist/core/research/model-fitness.js +4 -4
- package/dist/core/research/model-fitness.js.map +1 -1
- package/dist/core/research/research-gate.d.ts.map +1 -1
- package/dist/core/research/research-gate.js +7 -7
- package/dist/core/research/research-gate.js.map +1 -1
- package/dist/core/research/research-lane-controller.d.ts +62 -0
- package/dist/core/research/research-lane-controller.d.ts.map +1 -0
- package/dist/core/research/research-lane-controller.js +292 -0
- package/dist/core/research/research-lane-controller.js.map +1 -0
- package/dist/core/research/session-evidence-bundle.d.ts +2 -4
- package/dist/core/research/session-evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/session-evidence-bundle.js +10 -46
- package/dist/core/research/session-evidence-bundle.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +7 -2
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/risk-classifier.d.ts +6 -0
- package/dist/core/risk-classifier.d.ts.map +1 -0
- package/dist/core/risk-classifier.js +225 -0
- package/dist/core/risk-classifier.js.map +1 -0
- package/dist/core/runtime-builder.d.ts +26 -20
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +237 -178
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/sdk.d.ts +6 -3
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +61 -24
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-analytics.d.ts.map +1 -1
- package/dist/core/session-analytics.js +28 -1
- package/dist/core/session-analytics.js.map +1 -1
- package/dist/core/session-image-store.d.ts +33 -0
- package/dist/core/session-image-store.d.ts.map +1 -0
- package/dist/core/session-image-store.js +283 -0
- package/dist/core/session-image-store.js.map +1 -0
- package/dist/core/session-role.d.ts +6 -4
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +10 -4
- package/dist/core/session-role.js.map +1 -1
- package/dist/core/session-snapshot.d.ts +34 -0
- package/dist/core/session-snapshot.d.ts.map +1 -0
- package/dist/core/session-snapshot.js +68 -0
- package/dist/core/session-snapshot.js.map +1 -0
- package/dist/core/session-supervision-runtime.d.ts +31 -0
- package/dist/core/session-supervision-runtime.d.ts.map +1 -0
- package/dist/core/session-supervision-runtime.js +97 -0
- package/dist/core/session-supervision-runtime.js.map +1 -0
- package/dist/core/settings-manager.d.ts +9 -4
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +80 -28
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tasks/session-task-state.d.ts +2 -4
- package/dist/core/tasks/session-task-state.d.ts.map +1 -1
- package/dist/core/tasks/session-task-state.js +10 -28
- package/dist/core/tasks/session-task-state.js.map +1 -1
- package/dist/core/tasks/task-projection.d.ts +20 -0
- package/dist/core/tasks/task-projection.d.ts.map +1 -0
- package/dist/core/tasks/task-projection.js +47 -0
- package/dist/core/tasks/task-projection.js.map +1 -0
- package/dist/core/tasks/task-state.d.ts +4 -0
- package/dist/core/tasks/task-state.d.ts.map +1 -1
- package/dist/core/tasks/task-state.js +28 -11
- package/dist/core/tasks/task-state.js.map +1 -1
- package/dist/core/tool-capability-policy.d.ts +13 -0
- package/dist/core/tool-capability-policy.d.ts.map +1 -0
- package/dist/core/tool-capability-policy.js +85 -0
- package/dist/core/tool-capability-policy.js.map +1 -0
- package/dist/core/tool-protocol-controller.d.ts +91 -0
- package/dist/core/tool-protocol-controller.d.ts.map +1 -0
- package/dist/core/tool-protocol-controller.js +512 -0
- package/dist/core/tool-protocol-controller.js.map +1 -0
- package/dist/core/tool-recovery-log-records.d.ts +2 -3
- package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
- package/dist/core/tool-recovery-log-records.js +9 -35
- package/dist/core/tool-recovery-log-records.js.map +1 -1
- package/dist/core/tool-selection/tool-performance-store.d.ts +3 -7
- package/dist/core/tool-selection/tool-performance-store.d.ts.map +1 -1
- package/dist/core/tool-selection/tool-performance-store.js +97 -138
- package/dist/core/tool-selection/tool-performance-store.js.map +1 -1
- package/dist/core/tools/ask-question.d.ts +124 -0
- package/dist/core/tools/ask-question.d.ts.map +1 -0
- package/dist/core/tools/ask-question.js +693 -0
- package/dist/core/tools/ask-question.js.map +1 -0
- package/dist/core/tools/delegate-status.d.ts +31 -3
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +149 -29
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +15 -13
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +108 -23
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/extensionify.d.ts.map +1 -1
- package/dist/core/tools/extensionify.js +1 -0
- package/dist/core/tools/extensionify.js.map +1 -1
- package/dist/core/tools/goal.d.ts +5 -5
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +10 -10
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/model-fitness.d.ts.map +1 -1
- package/dist/core/tools/model-fitness.js +2 -2
- package/dist/core/tools/model-fitness.js.map +1 -1
- package/dist/core/tools/orchestration-panel.d.ts +43 -0
- package/dist/core/tools/orchestration-panel.d.ts.map +1 -0
- package/dist/core/tools/orchestration-panel.js +168 -0
- package/dist/core/tools/orchestration-panel.js.map +1 -0
- package/dist/core/tools/run-process.d.ts +26 -0
- package/dist/core/tools/run-process.d.ts.map +1 -0
- package/dist/core/tools/run-process.js +138 -0
- package/dist/core/tools/run-process.js.map +1 -0
- package/dist/core/tools/task-steps.d.ts +2 -0
- package/dist/core/tools/task-steps.d.ts.map +1 -1
- package/dist/core/tools/task-steps.js +102 -0
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/tools/tmux-dispatch.d.ts +3 -5
- package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
- package/dist/core/tools/tmux-dispatch.js +4 -4
- package/dist/core/tools/tmux-dispatch.js.map +1 -1
- package/dist/core/tools/windows-shell-engine.d.ts.map +1 -1
- package/dist/core/tools/windows-shell-engine.js +4 -6
- package/dist/core/tools/windows-shell-engine.js.map +1 -1
- package/dist/core/util/bounded-jsonl.d.ts +10 -0
- package/dist/core/util/bounded-jsonl.d.ts.map +1 -0
- package/dist/core/util/bounded-jsonl.js +75 -0
- package/dist/core/util/bounded-jsonl.js.map +1 -0
- package/dist/core/util/value-guards.d.ts +5 -0
- package/dist/core/util/value-guards.d.ts.map +1 -0
- package/dist/core/util/value-guards.js +12 -0
- package/dist/core/util/value-guards.js.map +1 -0
- package/dist/core/worktree-sync/store.d.ts +3 -3
- package/dist/core/worktree-sync/store.d.ts.map +1 -1
- package/dist/core/worktree-sync/store.js +10 -5
- package/dist/core/worktree-sync/store.js.map +1 -1
- package/dist/index.d.ts +13 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +128 -44
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts +4 -6
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +186 -28
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/clipboard-input.d.ts +7 -1
- package/dist/modes/interactive/clipboard-input.d.ts.map +1 -1
- package/dist/modes/interactive/clipboard-input.js +44 -6
- package/dist/modes/interactive/clipboard-input.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +2 -2
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/config-backup.d.ts.map +1 -1
- package/dist/modes/interactive/config-backup.js +5 -4
- package/dist/modes/interactive/config-backup.js.map +1 -1
- package/dist/modes/interactive/extension-ui-host.d.ts +14 -0
- package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
- package/dist/modes/interactive/extension-ui-host.js +76 -15
- package/dist/modes/interactive/extension-ui-host.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +3 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +63 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
- package/dist/modes/interactive/key-handlers.js +1 -1
- package/dist/modes/interactive/key-handlers.js.map +1 -1
- package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -1
- package/dist/modes/interactive/profile-menu-controller.js +7 -7
- package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
- package/dist/modes/interactive/report-commands.d.ts.map +1 -1
- package/dist/modes/interactive/report-commands.js +21 -0
- package/dist/modes/interactive/report-commands.js.map +1 -1
- package/dist/modes/interactive/session-flow-commands.d.ts +17 -2
- package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +50 -17
- package/dist/modes/interactive/session-flow-commands.js.map +1 -1
- package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-io-commands.js +16 -6
- package/dist/modes/interactive/session-io-commands.js.map +1 -1
- package/dist/modes/interactive/session-replacement-errors.d.ts +7 -0
- package/dist/modes/interactive/session-replacement-errors.d.ts.map +1 -0
- package/dist/modes/interactive/session-replacement-errors.js +15 -0
- package/dist/modes/interactive/session-replacement-errors.js.map +1 -0
- package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
- package/dist/modes/interactive/startup-checks.js +1 -1
- package/dist/modes/interactive/startup-checks.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +82 -23
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +15 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js +138 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +2 -13
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard-native.d.ts +1 -0
- package/dist/utils/clipboard-native.d.ts.map +1 -1
- package/dist/utils/clipboard-native.js.map +1 -1
- package/dist/utils/clipboard.d.ts +1 -0
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +52 -1
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/platform.d.ts +3 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +8 -0
- package/dist/utils/platform.js.map +1 -0
- package/dist/utils/work-directory.d.ts +11 -0
- package/dist/utils/work-directory.d.ts.map +1 -1
- package/dist/utils/work-directory.js +30 -9
- package/dist/utils/work-directory.js.map +1 -1
- package/docs/UI_POLISH_ORCHESTRATION.md +44 -0
- package/docs/UI_QUALITY_ORCHESTRATION.md +30 -0
- package/docs/docs.json +4 -0
- package/docs/extensions.md +62 -2
- package/docs/harness-architecture.md +156 -0
- package/docs/keybindings.md +11 -1
- package/docs/process-matrix.md +59 -26
- package/docs/rpc.md +45 -2
- package/docs/sessions.md +15 -0
- package/docs/settings.md +125 -11
- package/docs/task-steps.md +8 -0
- package/docs/telemetry.md +19 -0
- package/docs/tmux-agent-manager.md +10 -3
- package/docs/ui-reference/README.md +9 -0
- package/docs/ui-reference/orchestration-after.txt +7 -0
- package/docs/ui-reference/orchestration-before.txt +7 -0
- package/docs/ui-reference/orchestration-reference.txt +6 -0
- package/docs/usage.md +14 -2
- package/docs/work-directory.md +19 -8
- 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/question.ts +34 -245
- package/examples/extensions/questionnaire.ts +41 -407
- 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/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
- package/dist/core/delegation/session-worker-result.d.ts +0 -46
- package/dist/core/delegation/session-worker-result.d.ts.map +0 -1
- package/dist/core/delegation/session-worker-result.js +0 -113
- package/dist/core/delegation/session-worker-result.js.map +0 -1
- package/dist/core/delegation/worker-result.d.ts.map +0 -1
- package/dist/core/delegation/worker-result.js.map +0 -1
- package/dist/core/telemetry.d.ts.map +0 -1
- package/dist/core/telemetry.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"risk-assessment.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/risk-assessment.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"risk-assessment.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/risk-assessment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["export { assessOperationRisk } from \"../risk-classifier.ts\";\n"]}
|
|
@@ -1,124 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
const SECURITY_AUTH_RE = /\b(auth|token|credential|credentials|secret|api[-_]key)\b/i;
|
|
3
|
-
const DESTRUCTIVE_RE = /\b(delete|reset|rm\s+-rf|clean)\b/i;
|
|
4
|
-
const SELF_MOD_MUTATE_RE = /\b(modify|change|write|update|edit|delete|add|remove|set)\s+.*\b(skills|prompts|settings|tools|behavior)\b|self[-_]modification/i;
|
|
5
|
-
const ARCHITECTURE_MUTATE_RE = /\b(rewrite|redesign|change|modify|rearchitect)\s+.*\b(architecture|architect)\b/i;
|
|
6
|
-
const READ_ONLY_QUESTION_RE = /^(?:(?:can you|could you|please|pls|go ahead and|let'?s|i need you to|we need to|you should)\s+)?(?:how|what|why|when|where|which|who|explain|summarize|compare|describe|list|show|search|find|view|read|locate)\b/i;
|
|
7
|
-
const EXPLICIT_MODIFY_REQUEST_RE = /^(?:can you|could you|please|pls|go ahead and|let'?s|i need you to|we need to|you should)\s+.*\b(add|apply|build|change|commit|create|delete|edit|fix|generate|implement|install|modify|patch|refactor|remove|rename|replace|run|test|update|write|publish|release|push|deploy|tag|reset|clean|rewrite)\b/i;
|
|
8
|
-
// Shell parsing helpers
|
|
9
|
-
const DESTRUCTIVE_CMD_RE = /\b(rm(\s+-r|\s+-f|\s+-rf|\s+-fr)?|mv|cp|chmod|chown|install)\b|>\s*\/dev\/(sda|hda|vda)|\b(dd\s+if=)/i;
|
|
10
|
-
const GIT_MUTATE_CMD_RE = /\bgit\s+(commit|push|reset|clean|stash|rebase)\b/i;
|
|
11
|
-
const PKG_MUTATE_CMD_RE = /\b(npm|pnpm|yarn|bun)\s+(install|i|update|up|publish|run|remove|rm|uninstall)\b/i;
|
|
12
|
-
const RELEASE_DEPLOY_CMD_RE = /\b(release|deploy)\b/i;
|
|
13
|
-
const PYTHON_HIGH_IMPACT_RE = /\b(?:shutil\.(?:rmtree|move|copy|copy2|copytree)|os\.(?:remove|unlink|rmdir|removedirs|system)|subprocess\.(?:run|call|check_call|check_output|Popen)|Path\([^)]*\)\.(?:unlink|rmdir))\b/i;
|
|
14
|
-
const REDIRECTION_RE = /[<>]/;
|
|
15
|
-
function stripSingleQuotes(cmd) {
|
|
16
|
-
return cmd.replace(/'[^']*'/g, "''");
|
|
17
|
-
}
|
|
18
|
-
export function assessOperationRisk(input) {
|
|
19
|
-
const operation = input.operation.trim();
|
|
20
|
-
const command = input.command?.trim() ?? "";
|
|
21
|
-
const cleanCommand = command ? stripSingleQuotes(command) : "";
|
|
22
|
-
const fullText = `${operation} ${command}`.trim();
|
|
23
|
-
const cleanFullText = `${operation} ${cleanCommand}`.trim();
|
|
24
|
-
if (fullText.length === 0) {
|
|
25
|
-
return {
|
|
26
|
-
risk: "read-only",
|
|
27
|
-
reasonCode: "empty_operation",
|
|
28
|
-
reasons: ["Empty operation"],
|
|
29
|
-
requiresApproval: false,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
// 1. Explicit read-only operations
|
|
33
|
-
if (READ_ONLY_QUESTION_RE.test(operation) && !EXPLICIT_MODIFY_REQUEST_RE.test(operation)) {
|
|
34
|
-
return {
|
|
35
|
-
risk: "read-only",
|
|
36
|
-
reasonCode: "read_only_operation",
|
|
37
|
-
reasons: ["Operation is explicitly read-only (list/show/read/search)"],
|
|
38
|
-
requiresApproval: false,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
// 2. High-risk actions
|
|
42
|
-
if (RELEASE_PUBLISH_RE.test(cleanFullText)) {
|
|
43
|
-
return {
|
|
44
|
-
risk: "approval-required",
|
|
45
|
-
reasonCode: "release_publish_operation",
|
|
46
|
-
reasons: ["Operation mentions releasing, publishing, or deploying"],
|
|
47
|
-
requiresApproval: true,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
if (SECURITY_AUTH_RE.test(cleanFullText)) {
|
|
51
|
-
return {
|
|
52
|
-
risk: "approval-required", // updated based on user instruction: "high-impact or approval-required"
|
|
53
|
-
reasonCode: "security_auth_operation",
|
|
54
|
-
reasons: ["Operation mentions authentication or credentials"],
|
|
55
|
-
requiresApproval: true,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
if (DESTRUCTIVE_RE.test(cleanFullText)) {
|
|
59
|
-
return {
|
|
60
|
-
risk: "approval-required",
|
|
61
|
-
reasonCode: "destructive_operation",
|
|
62
|
-
reasons: ["Operation involves deleting, resetting, or cleaning"],
|
|
63
|
-
requiresApproval: true,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
if (SELF_MOD_MUTATE_RE.test(cleanFullText)) {
|
|
67
|
-
return {
|
|
68
|
-
risk: "approval-required",
|
|
69
|
-
reasonCode: "self_modification_operation",
|
|
70
|
-
reasons: ["Operation modifies settings, tools, skills, or prompts"],
|
|
71
|
-
requiresApproval: true,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
if (ARCHITECTURE_MUTATE_RE.test(cleanFullText)) {
|
|
75
|
-
return {
|
|
76
|
-
risk: "high-impact",
|
|
77
|
-
reasonCode: "architecture_mutation_operation",
|
|
78
|
-
reasons: ["Operation mentions rewriting or rearchitecting core parts"],
|
|
79
|
-
requiresApproval: false,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
// 3. Command risks
|
|
83
|
-
if (command) {
|
|
84
|
-
const cleanCmd = stripSingleQuotes(command);
|
|
85
|
-
if (DESTRUCTIVE_CMD_RE.test(cleanCmd) ||
|
|
86
|
-
GIT_MUTATE_CMD_RE.test(cleanCmd) ||
|
|
87
|
-
PKG_MUTATE_CMD_RE.test(cleanCmd) ||
|
|
88
|
-
RELEASE_DEPLOY_CMD_RE.test(cleanCmd) ||
|
|
89
|
-
PYTHON_HIGH_IMPACT_RE.test(cleanCmd) ||
|
|
90
|
-
REDIRECTION_RE.test(cleanCmd)) {
|
|
91
|
-
return {
|
|
92
|
-
risk: "approval-required",
|
|
93
|
-
reasonCode: "mutating_command",
|
|
94
|
-
reasons: ["Command executes a destructive, mutating, or publish operation"],
|
|
95
|
-
requiresApproval: true,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
// Default to scoped-write for any generic mutating tool action if it has a toolName or isn't read-only
|
|
100
|
-
// or read-only if it's purely a non-mutating intent (but since it didn't match read-only above, we default to scoped-write)
|
|
101
|
-
if (input.toolName &&
|
|
102
|
-
!["read_file", "search_web", "list_dir", "grep_search", "view_file", "memory"].includes(input.toolName)) {
|
|
103
|
-
return {
|
|
104
|
-
risk: "scoped-write",
|
|
105
|
-
reasonCode: "generic_mutation",
|
|
106
|
-
reasons: ["Generic mutating operation or command"],
|
|
107
|
-
requiresApproval: false,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
if (command) {
|
|
111
|
-
// Even if not explicitly destructive, shell commands could be anything, but we assume read-only if it's just 'ls', 'git status' etc.
|
|
112
|
-
// For now, if no mutating patterns matched, we assume read-only if there's no toolName, but wait, normal file edits are scoped-write.
|
|
113
|
-
// If there is a command, and it doesn't match the mutating patterns, we fall through to read-only.
|
|
114
|
-
// Wait, user says "Risk shell read-only commands like git status, rg, ls, npm view do not require approval."
|
|
115
|
-
// And "ordinary file edits inside allowed scope are scoped-write." (Handled by tools)
|
|
116
|
-
}
|
|
117
|
-
return {
|
|
118
|
-
risk: "read-only",
|
|
119
|
-
reasonCode: "default_read_only",
|
|
120
|
-
reasons: ["No mutating or high-risk patterns detected"],
|
|
121
|
-
requiresApproval: false,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
1
|
+
export { assessOperationRisk } from "../risk-classifier.js";
|
|
124
2
|
//# sourceMappingURL=risk-assessment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"risk-assessment.js","sourceRoot":"","sources":["../../../src/core/autonomy/risk-assessment.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"risk-assessment.js","sourceRoot":"","sources":["../../../src/core/autonomy/risk-assessment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["export { assessOperationRisk } from \"../risk-classifier.ts\";\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { SessionEntry, SessionManager } from "@caupulican/pi-agent-core/node";
|
|
2
|
+
import { type SessionSnapshotPayload } from "../session-snapshot.ts";
|
|
2
3
|
import { type LaneRecord } from "./lane-tracker.ts";
|
|
3
4
|
export declare const LANE_RECORD_CUSTOM_TYPE = "lane_record";
|
|
4
|
-
export
|
|
5
|
-
version: 1;
|
|
6
|
-
record: LaneRecord;
|
|
7
|
-
}
|
|
5
|
+
export type LaneRecordSnapshotPayload = SessionSnapshotPayload<"record", LaneRecord>;
|
|
8
6
|
export declare function appendLaneRecordSnapshot(sessionManager: Pick<SessionManager, "appendCustomEntry">, record: LaneRecord): string;
|
|
9
7
|
export declare function getLaneRecordSnapshots(entries: readonly SessionEntry[]): LaneRecord[];
|
|
8
|
+
/** Latest durable projection per logical lane id, preserving first-seen lane order. */
|
|
9
|
+
export declare function getLatestLaneRecordSnapshots(entries: readonly SessionEntry[]): LaneRecord[];
|
|
10
10
|
//# sourceMappingURL=session-lane-record.d.ts.map
|
|
@@ -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,gCAAgC,CAAC;AACnF,OAAO,EAA2C,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE7F,eAAO,MAAM,uBAAuB,gBAAgB,CAAC;AAErD,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,EAIN,KAAK,sBAAsB,EAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAA2C,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE7F,eAAO,MAAM,uBAAuB,gBAAgB,CAAC;AAErD,MAAM,MAAM,yBAAyB,GAAG,sBAAsB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AASrF,wBAAgB,wBAAwB,CACvC,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,MAAM,EAAE,UAAU,GAChB,MAAM,CAER;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,UAAU,EAAE,CAErF;AAED,uFAAuF;AACvF,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,UAAU,EAAE,CAI3F","sourcesContent":["import type { SessionEntry, SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport {\n\tappendSessionSnapshot,\n\tgetSessionSnapshots,\n\ttype SessionSnapshotCodec,\n\ttype SessionSnapshotPayload,\n} from \"../session-snapshot.ts\";\nimport { cloneLaneRecordForStorage, isLaneRecord, type LaneRecord } from \"./lane-tracker.ts\";\n\nexport const LANE_RECORD_CUSTOM_TYPE = \"lane_record\";\n\nexport type LaneRecordSnapshotPayload = SessionSnapshotPayload<\"record\", LaneRecord>;\n\nconst LANE_RECORD_SNAPSHOT_CODEC: SessionSnapshotCodec<LaneRecord, \"record\"> = {\n\tcustomType: LANE_RECORD_CUSTOM_TYPE,\n\tvalueKey: \"record\",\n\tisValue: isLaneRecord,\n\tclone: cloneLaneRecordForStorage,\n};\n\nexport function appendLaneRecordSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\trecord: LaneRecord,\n): string {\n\treturn appendSessionSnapshot(sessionManager, LANE_RECORD_SNAPSHOT_CODEC, record);\n}\n\nexport function getLaneRecordSnapshots(entries: readonly SessionEntry[]): LaneRecord[] {\n\treturn getSessionSnapshots(entries, LANE_RECORD_SNAPSHOT_CODEC);\n}\n\n/** Latest durable projection per logical lane id, preserving first-seen lane order. */\nexport function getLatestLaneRecordSnapshots(entries: readonly SessionEntry[]): LaneRecord[] {\n\tconst latest = new Map<string, LaneRecord>();\n\tfor (const record of getLaneRecordSnapshots(entries)) latest.set(record.laneId, record);\n\treturn [...latest.values()].map(cloneLaneRecordForStorage);\n}\n"]}
|
|
@@ -1,36 +1,23 @@
|
|
|
1
|
+
import { appendSessionSnapshot, getSessionSnapshots, } from "../session-snapshot.js";
|
|
1
2
|
import { cloneLaneRecordForStorage, isLaneRecord } from "./lane-tracker.js";
|
|
2
3
|
export const LANE_RECORD_CUSTOM_TYPE = "lane_record";
|
|
4
|
+
const LANE_RECORD_SNAPSHOT_CODEC = {
|
|
5
|
+
customType: LANE_RECORD_CUSTOM_TYPE,
|
|
6
|
+
valueKey: "record",
|
|
7
|
+
isValue: isLaneRecord,
|
|
8
|
+
clone: cloneLaneRecordForStorage,
|
|
9
|
+
};
|
|
3
10
|
export function appendLaneRecordSnapshot(sessionManager, record) {
|
|
4
|
-
|
|
5
|
-
version: 1,
|
|
6
|
-
record: cloneLaneRecordForStorage(record),
|
|
7
|
-
};
|
|
8
|
-
return sessionManager.appendCustomEntry(LANE_RECORD_CUSTOM_TYPE, payload);
|
|
9
|
-
}
|
|
10
|
-
function isPlainRecord(value) {
|
|
11
|
-
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
12
|
-
return false;
|
|
13
|
-
const prototype = Object.getPrototypeOf(value);
|
|
14
|
-
return prototype === Object.prototype || prototype === null;
|
|
11
|
+
return appendSessionSnapshot(sessionManager, LANE_RECORD_SNAPSHOT_CODEC, record);
|
|
15
12
|
}
|
|
16
13
|
export function getLaneRecordSnapshots(entries) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (payload.version !== 1)
|
|
26
|
-
continue;
|
|
27
|
-
if (!("record" in payload))
|
|
28
|
-
continue;
|
|
29
|
-
const record = payload.record;
|
|
30
|
-
if (isLaneRecord(record)) {
|
|
31
|
-
records.push(cloneLaneRecordForStorage(record));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return records;
|
|
14
|
+
return getSessionSnapshots(entries, LANE_RECORD_SNAPSHOT_CODEC);
|
|
15
|
+
}
|
|
16
|
+
/** Latest durable projection per logical lane id, preserving first-seen lane order. */
|
|
17
|
+
export function getLatestLaneRecordSnapshots(entries) {
|
|
18
|
+
const latest = new Map();
|
|
19
|
+
for (const record of getLaneRecordSnapshots(entries))
|
|
20
|
+
latest.set(record.laneId, record);
|
|
21
|
+
return [...latest.values()].map(cloneLaneRecordForStorage);
|
|
35
22
|
}
|
|
36
23
|
//# sourceMappingURL=session-lane-record.js.map
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"session-lane-record.js","sourceRoot":"","sources":["../../../src/core/autonomy/session-lane-record.ts"],"names":[],"mappings":"AACA,OAAO,EACN,qBAAqB,EACrB,mBAAmB,GAGnB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,yBAAyB,EAAE,YAAY,EAAmB,MAAM,mBAAmB,CAAC;AAE7F,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAAC;AAIrD,MAAM,0BAA0B,GAA+C;IAC9E,UAAU,EAAE,uBAAuB;IACnC,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,YAAY;IACrB,KAAK,EAAE,yBAAyB;CAChC,CAAC;AAEF,MAAM,UAAU,wBAAwB,CACvC,cAAyD,EACzD,MAAkB,EACT;IACT,OAAO,qBAAqB,CAAC,cAAc,EAAE,0BAA0B,EAAE,MAAM,CAAC,CAAC;AAAA,CACjF;AAED,MAAM,UAAU,sBAAsB,CAAC,OAAgC,EAAgB;IACtF,OAAO,mBAAmB,CAAC,OAAO,EAAE,0BAA0B,CAAC,CAAC;AAAA,CAChE;AAED,uFAAuF;AACvF,MAAM,UAAU,4BAA4B,CAAC,OAAgC,EAAgB;IAC5F,MAAM,MAAM,GAAG,IAAI,GAAG,EAAsB,CAAC;IAC7C,KAAK,MAAM,MAAM,IAAI,sBAAsB,CAAC,OAAO,CAAC;QAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxF,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;AAAA,CAC3D","sourcesContent":["import type { SessionEntry, SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport {\n\tappendSessionSnapshot,\n\tgetSessionSnapshots,\n\ttype SessionSnapshotCodec,\n\ttype SessionSnapshotPayload,\n} from \"../session-snapshot.ts\";\nimport { cloneLaneRecordForStorage, isLaneRecord, type LaneRecord } from \"./lane-tracker.ts\";\n\nexport const LANE_RECORD_CUSTOM_TYPE = \"lane_record\";\n\nexport type LaneRecordSnapshotPayload = SessionSnapshotPayload<\"record\", LaneRecord>;\n\nconst LANE_RECORD_SNAPSHOT_CODEC: SessionSnapshotCodec<LaneRecord, \"record\"> = {\n\tcustomType: LANE_RECORD_CUSTOM_TYPE,\n\tvalueKey: \"record\",\n\tisValue: isLaneRecord,\n\tclone: cloneLaneRecordForStorage,\n};\n\nexport function appendLaneRecordSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\trecord: LaneRecord,\n): string {\n\treturn appendSessionSnapshot(sessionManager, LANE_RECORD_SNAPSHOT_CODEC, record);\n}\n\nexport function getLaneRecordSnapshots(entries: readonly SessionEntry[]): LaneRecord[] {\n\treturn getSessionSnapshots(entries, LANE_RECORD_SNAPSHOT_CODEC);\n}\n\n/** Latest durable projection per logical lane id, preserving first-seen lane order. */\nexport function getLatestLaneRecordSnapshots(entries: readonly SessionEntry[]): LaneRecord[] {\n\tconst latest = new Map<string, LaneRecord>();\n\tfor (const record of getLaneRecordSnapshots(entries)) latest.set(record.laneId, record);\n\treturn [...latest.values()].map(cloneLaneRecordForStorage);\n}\n"]}
|
|
@@ -5,7 +5,7 @@ export declare const AUTONOMY_TELEMETRY_EVENT_TYPES: {
|
|
|
5
5
|
readonly approvalRequest: "autonomy.approval_request";
|
|
6
6
|
readonly evidenceBundle: "autonomy.evidence_bundle";
|
|
7
7
|
readonly workerRequest: "autonomy.worker_request";
|
|
8
|
-
readonly
|
|
8
|
+
readonly workerTerminal: "autonomy.worker_terminal";
|
|
9
9
|
readonly learningDecision: "autonomy.learning_decision";
|
|
10
10
|
};
|
|
11
11
|
export type AutonomyTelemetryEventType = (typeof AUTONOMY_TELEMETRY_EVENT_TYPES)[keyof typeof AUTONOMY_TELEMETRY_EVENT_TYPES];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-events.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/telemetry-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,eAAO,MAAM,8BAA8B;;;;;;;;CAQjC,CAAC;AAEX,MAAM,MAAM,0BAA0B,GACrC,CAAC,OAAO,8BAA8B,CAAC,CAAC,MAAM,OAAO,8BAA8B,CAAC,CAAC;AAEtF,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,0BAA0B,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,SAAS,CAAC;CACnB;AAiBD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAI,GAAG,OAAO,CAyCvE","sourcesContent":["import type { JsonValue } from \"./contracts.ts\";\n\nexport const AUTONOMY_TELEMETRY_EVENT_TYPES = {\n\trouteDecision: \"autonomy.route_decision\",\n\tgateOutcome: \"autonomy.gate_outcome\",\n\tapprovalRequest: \"autonomy.approval_request\",\n\tevidenceBundle: \"autonomy.evidence_bundle\",\n\tworkerRequest: \"autonomy.worker_request\",\n\
|
|
1
|
+
{"version":3,"file":"telemetry-events.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/telemetry-events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,eAAO,MAAM,8BAA8B;;;;;;;;CAQjC,CAAC;AAEX,MAAM,MAAM,0BAA0B,GACrC,CAAC,OAAO,8BAA8B,CAAC,CAAC,MAAM,OAAO,8BAA8B,CAAC,CAAC;AAEtF,MAAM,WAAW,sBAAsB;IACtC,IAAI,EAAE,0BAA0B,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,SAAS,CAAC;CACnB;AAiBD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAI,GAAG,OAAO,CAyCvE","sourcesContent":["import type { JsonValue } from \"./contracts.ts\";\n\nexport const AUTONOMY_TELEMETRY_EVENT_TYPES = {\n\trouteDecision: \"autonomy.route_decision\",\n\tgateOutcome: \"autonomy.gate_outcome\",\n\tapprovalRequest: \"autonomy.approval_request\",\n\tevidenceBundle: \"autonomy.evidence_bundle\",\n\tworkerRequest: \"autonomy.worker_request\",\n\tworkerTerminal: \"autonomy.worker_terminal\",\n\tlearningDecision: \"autonomy.learning_decision\",\n} as const;\n\nexport type AutonomyTelemetryEventType =\n\t(typeof AUTONOMY_TELEMETRY_EVENT_TYPES)[keyof typeof AUTONOMY_TELEMETRY_EVENT_TYPES];\n\nexport interface AutonomyTelemetryEvent {\n\ttype: AutonomyTelemetryEventType;\n\ttimestamp: string;\n\tpayload: JsonValue;\n}\n\nconst SECRET_KEYS = new Set([\n\t\"apikey\",\n\t\"api_key\",\n\t\"token\",\n\t\"accesstoken\",\n\t\"refreshtoken\",\n\t\"secret\",\n\t\"password\",\n\t\"authorization\",\n\t\"credential\",\n\t\"credentials\",\n]);\n\nconst BEARER_RE = /bearer\\s+\\S+/i;\n\nexport function redactTelemetryValue(value: unknown, depth = 0): unknown {\n\tif (depth > 20) {\n\t\treturn \"[Depth Limit Exceeded]\";\n\t}\n\n\tif (typeof value === \"string\") {\n\t\tif (BEARER_RE.test(value)) {\n\t\t\treturn \"[REDACTED BEARER TOKEN]\";\n\t\t}\n\t\tif (value.startsWith(\"sk-\")) {\n\t\t\treturn \"[REDACTED API KEY]\";\n\t\t}\n\t\treturn value;\n\t}\n\n\tif (value === null || typeof value !== \"object\") {\n\t\treturn value;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tconst result: unknown[] = [];\n\t\tfor (const item of value) {\n\t\t\tresult.push(redactTelemetryValue(item, depth + 1));\n\t\t}\n\t\treturn result;\n\t}\n\n\t// It is an object\n\tconst obj = value as Record<string, unknown>;\n\tconst result: Record<string, unknown> = {};\n\n\tfor (const key of Object.keys(obj)) {\n\t\tconst lowercaseKey = key.toLowerCase();\n\t\tif (SECRET_KEYS.has(lowercaseKey)) {\n\t\t\tresult[key] = \"[REDACTED]\";\n\t\t} else {\n\t\t\tresult[key] = redactTelemetryValue(obj[key], depth + 1);\n\t\t}\n\t}\n\n\treturn result;\n}\n"]}
|
|
@@ -4,7 +4,7 @@ export const AUTONOMY_TELEMETRY_EVENT_TYPES = {
|
|
|
4
4
|
approvalRequest: "autonomy.approval_request",
|
|
5
5
|
evidenceBundle: "autonomy.evidence_bundle",
|
|
6
6
|
workerRequest: "autonomy.worker_request",
|
|
7
|
-
|
|
7
|
+
workerTerminal: "autonomy.worker_terminal",
|
|
8
8
|
learningDecision: "autonomy.learning_decision",
|
|
9
9
|
};
|
|
10
10
|
const SECRET_KEYS = new Set([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-events.js","sourceRoot":"","sources":["../../../src/core/autonomy/telemetry-events.ts"],"names":[],"mappings":"AAE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OAAO,KAAK,CAAC;IACd,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAc,EAAE,CAAC;QAC7B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YAC1B,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IAED,kBAAkB;IAClB,MAAM,GAAG,GAAG,KAAgC,CAAC;IAC7C,MAAM,MAAM,GAA4B,EAAE,CAAC;IAE3C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QACpC,MAAM,YAAY,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC;QACvC,IAAI,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;YACnC,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC;QAC5B,CAAC;aAAM,CAAC;YACP,MAAM,CAAC,GAAG,CAAC,GAAG,oBAAoB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QACzD,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAC;AAAA,CACd","sourcesContent":["import type { JsonValue } from \"./contracts.ts\";\n\nexport const AUTONOMY_TELEMETRY_EVENT_TYPES = {\n\trouteDecision: \"autonomy.route_decision\",\n\tgateOutcome: \"autonomy.gate_outcome\",\n\tapprovalRequest: \"autonomy.approval_request\",\n\tevidenceBundle: \"autonomy.evidence_bundle\",\n\tworkerRequest: \"autonomy.worker_request\",\n\tworkerTerminal: \"autonomy.worker_terminal\",\n\tlearningDecision: \"autonomy.learning_decision\",\n} as const;\n\nexport type AutonomyTelemetryEventType =\n\t(typeof AUTONOMY_TELEMETRY_EVENT_TYPES)[keyof typeof AUTONOMY_TELEMETRY_EVENT_TYPES];\n\nexport interface AutonomyTelemetryEvent {\n\ttype: AutonomyTelemetryEventType;\n\ttimestamp: string;\n\tpayload: JsonValue;\n}\n\nconst SECRET_KEYS = new Set([\n\t\"apikey\",\n\t\"api_key\",\n\t\"token\",\n\t\"accesstoken\",\n\t\"refreshtoken\",\n\t\"secret\",\n\t\"password\",\n\t\"authorization\",\n\t\"credential\",\n\t\"credentials\",\n]);\n\nconst BEARER_RE = /bearer\\s+\\S+/i;\n\nexport function redactTelemetryValue(value: unknown, depth = 0): unknown {\n\tif (depth > 20) {\n\t\treturn \"[Depth Limit Exceeded]\";\n\t}\n\n\tif (typeof value === \"string\") {\n\t\tif (BEARER_RE.test(value)) {\n\t\t\treturn \"[REDACTED BEARER TOKEN]\";\n\t\t}\n\t\tif (value.startsWith(\"sk-\")) {\n\t\t\treturn \"[REDACTED API KEY]\";\n\t\t}\n\t\treturn value;\n\t}\n\n\tif (value === null || typeof value !== \"object\") {\n\t\treturn value;\n\t}\n\n\tif (Array.isArray(value)) {\n\t\tconst result: unknown[] = [];\n\t\tfor (const item of value) {\n\t\t\tresult.push(redactTelemetryValue(item, depth + 1));\n\t\t}\n\t\treturn result;\n\t}\n\n\t// It is an object\n\tconst obj = value as Record<string, unknown>;\n\tconst result: Record<string, unknown> = {};\n\n\tfor (const key of Object.keys(obj)) {\n\t\tconst lowercaseKey = key.toLowerCase();\n\t\tif (SECRET_KEYS.has(lowercaseKey)) {\n\t\t\tresult[key] = \"[REDACTED]\";\n\t\t} else {\n\t\t\tresult[key] = redactTelemetryValue(obj[key], depth + 1);\n\t\t}\n\t}\n\n\treturn result;\n}\n"]}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* rather than the whole AgentSession — they never mutate anything but the owned gate-outcome fields.
|
|
9
9
|
*/
|
|
10
10
|
import type { SessionManager } from "@caupulican/pi-agent-core/node";
|
|
11
|
-
import type { EvidenceBundle, GateOutcome, LearningDecision,
|
|
11
|
+
import type { EvidenceBundle, GateOutcome, LearningDecision, WorkerClaim } from "./autonomy/contracts.ts";
|
|
12
12
|
import type { AutonomyDiagnosticSnapshot, AutonomyStatusSnapshot, GateOutcomeHistoryEntry } from "./autonomy/status.ts";
|
|
13
13
|
import { type AutonomyTelemetryEvent } from "./autonomy/telemetry-events.ts";
|
|
14
14
|
import { type SessionCostSummary } from "./cost/cost-summary.ts";
|
|
@@ -28,12 +28,12 @@ export interface AutonomyTelemetryDeps {
|
|
|
28
28
|
getGoalStateSnapshot(): GoalState | undefined;
|
|
29
29
|
/** Live count of active lanes from the lane tracker — never inferred from historical snapshots. */
|
|
30
30
|
getActiveLaneCount(): number;
|
|
31
|
-
/** Research evidence bundles
|
|
32
|
-
|
|
33
|
-
/** Worker-delegation
|
|
34
|
-
|
|
35
|
-
/** Learning
|
|
36
|
-
|
|
31
|
+
/** Research evidence bundles across the complete session tree, including sibling branches. */
|
|
32
|
+
getSessionEvidenceBundleHistory(): EvidenceBundle[];
|
|
33
|
+
/** Worker-delegation claims across the complete session tree, including sibling branches. */
|
|
34
|
+
getSessionWorkerClaimHistory(): WorkerClaim[];
|
|
35
|
+
/** Learning decisions across the complete session tree, including sibling branches. */
|
|
36
|
+
getSessionLearningDecisionHistory(): LearningDecision[];
|
|
37
37
|
/** Learning audit records recorded this session. */
|
|
38
38
|
getLearningAuditRecords(): LearningAuditRecord[];
|
|
39
39
|
}
|
|
@@ -1 +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,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,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AAO,EAAE,WAAW,GAAG,IAAI,CAsB5C;IAED,iFAAiF;IACjF,qBAAqB,IAAI,uBAAuB,EAAE,CAEjD;IAED,iBAAiB,IAAI,sBAAsB,CA2C1C;IAED;;;;;OAKG;IACH,qBAAqB,CAAC,OAAO,CAAC,EAAE;QAAE,mBAAmB,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,0BAA0B,CA0J5F;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 { 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 { hasCostSummarySignal, hasSubagentCostSignal, type SessionCostSummary } from \"./cost/cost-summary.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/** Single source of truth for CURRENT/TODAY/SUBAGENTS display costs. */\n\tgetCostSummary(): SessionCostSummary;\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 costSummary = this.deps.getCostSummary();\n\t\tif (hasCostSummarySignal(costSummary)) {\n\t\t\tsnapshot.costSummary = costSummary;\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 costSummary = this.deps.getCostSummary();\n\t\tif (costSummary.currentCost > 0 || hasSubagentCostSignal(costSummary)) {\n\t\t\tcosts.push({ title: \"CURRENT\", summary: `$${costSummary.currentCost.toFixed(4)}` });\n\t\t}\n\t\tif (costSummary.todayCost > 0) {\n\t\t\tcosts.push({ title: \"TODAY\", summary: `$${costSummary.todayCost.toFixed(4)}` });\n\t\t}\n\t\tif (hasSubagentCostSignal(costSummary)) {\n\t\t\tcosts.push({\n\t\t\t\ttitle: \"SUBAGENTS\",\n\t\t\t\tsummary: `$${costSummary.subagentCost.toFixed(4)} included in CURRENT`,\n\t\t\t});\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"]}
|
|
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,cAAc,EAAE,WAAW,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE1G,OAAO,KAAK,EACX,0BAA0B,EAC1B,sBAAsB,EAEtB,uBAAuB,EACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEN,KAAK,sBAAsB,EAE3B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAA+C,KAAK,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC9G,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,wEAAwE;IACxE,cAAc,IAAI,kBAAkB,CAAC;IACrC,+CAA+C;IAC/C,oBAAoB,IAAI,SAAS,GAAG,SAAS,CAAC;IAC9C,qGAAmG;IACnG,kBAAkB,IAAI,MAAM,CAAC;IAC7B,8FAA8F;IAC9F,+BAA+B,IAAI,cAAc,EAAE,CAAC;IACpD,6FAA6F;IAC7F,4BAA4B,IAAI,WAAW,EAAE,CAAC;IAC9C,uFAAuF;IACvF,iCAAiC,IAAI,gBAAgB,EAAE,CAAC;IACxD,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,CA2C1C;IAED;;;;;OAKG;IACH,qBAAqB,CAAC,OAAO,CAAC,EAAE;QAAE,mBAAmB,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,0BAA0B,CA0J5F;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 { EvidenceBundle, GateOutcome, LearningDecision, WorkerClaim } 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 { hasCostSummarySignal, hasSubagentCostSignal, type SessionCostSummary } from \"./cost/cost-summary.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/** Single source of truth for CURRENT/TODAY/SUBAGENTS display costs. */\n\tgetCostSummary(): SessionCostSummary;\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 across the complete session tree, including sibling branches. */\n\tgetSessionEvidenceBundleHistory(): EvidenceBundle[];\n\t/** Worker-delegation claims across the complete session tree, including sibling branches. */\n\tgetSessionWorkerClaimHistory(): WorkerClaim[];\n\t/** Learning decisions across the complete session tree, including sibling branches. */\n\tgetSessionLearningDecisionHistory(): 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 costSummary = this.deps.getCostSummary();\n\t\tif (hasCostSummarySignal(costSummary)) {\n\t\t\tsnapshot.costSummary = costSummary;\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 costSummary = this.deps.getCostSummary();\n\t\tif (costSummary.currentCost > 0 || hasSubagentCostSignal(costSummary)) {\n\t\t\tcosts.push({ title: \"CURRENT\", summary: `$${costSummary.currentCost.toFixed(4)}` });\n\t\t}\n\t\tif (costSummary.todayCost > 0) {\n\t\t\tcosts.push({ title: \"TODAY\", summary: `$${costSummary.todayCost.toFixed(4)}` });\n\t\t}\n\t\tif (hasSubagentCostSignal(costSummary)) {\n\t\t\tcosts.push({\n\t\t\t\ttitle: \"SUBAGENTS\",\n\t\t\t\tsummary: `$${costSummary.subagentCost.toFixed(4)} included in CURRENT`,\n\t\t\t});\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.getSessionEvidenceBundleHistory().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 workerClaims = this.deps.getSessionWorkerClaimHistory();\n\t\tfor (const claim of workerClaims.slice(-maxEntriesPerFamily)) {\n\t\t\tdelegationEntries.push({\n\t\t\t\ttitle: `Worker ${claim.requestId} (${claim.status})`,\n\t\t\t\tsummary: claim.summary,\n\t\t\t\tmetadata: {\n\t\t\t\t\tchangedFileCount: claim.changedFiles.length,\n\t\t\t\t\tblockerCount: claim.blockers?.length ?? 0,\n\t\t\t\t\tusageReportId: claim.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.getSessionLearningDecisionHistory();\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"]}
|
|
@@ -173,7 +173,7 @@ export class AutonomyTelemetry {
|
|
|
173
173
|
},
|
|
174
174
|
});
|
|
175
175
|
}
|
|
176
|
-
for (const bundle of this.deps.
|
|
176
|
+
for (const bundle of this.deps.getSessionEvidenceBundleHistory().slice(-maxEntriesPerFamily)) {
|
|
177
177
|
researchEntries.push({
|
|
178
178
|
title: `Research: ${bundle.query}`,
|
|
179
179
|
metadata: { sourceCount: bundle.sources.length, findingCount: bundle.findings.length },
|
|
@@ -194,15 +194,15 @@ export class AutonomyTelemetry {
|
|
|
194
194
|
metadata: { costUsd: record.costUsd, startedAt: record.startedAt, completedAt: record.completedAt },
|
|
195
195
|
});
|
|
196
196
|
}
|
|
197
|
-
const
|
|
198
|
-
for (const
|
|
197
|
+
const workerClaims = this.deps.getSessionWorkerClaimHistory();
|
|
198
|
+
for (const claim of workerClaims.slice(-maxEntriesPerFamily)) {
|
|
199
199
|
delegationEntries.push({
|
|
200
|
-
title: `Worker ${
|
|
201
|
-
summary:
|
|
200
|
+
title: `Worker ${claim.requestId} (${claim.status})`,
|
|
201
|
+
summary: claim.summary,
|
|
202
202
|
metadata: {
|
|
203
|
-
changedFileCount:
|
|
204
|
-
blockerCount:
|
|
205
|
-
usageReportId:
|
|
203
|
+
changedFileCount: claim.changedFiles.length,
|
|
204
|
+
blockerCount: claim.blockers?.length ?? 0,
|
|
205
|
+
usageReportId: claim.usageReportId,
|
|
206
206
|
},
|
|
207
207
|
});
|
|
208
208
|
}
|
|
@@ -210,7 +210,7 @@ export class AutonomyTelemetry {
|
|
|
210
210
|
snapshot.delegation = delegationEntries;
|
|
211
211
|
}
|
|
212
212
|
const learningEntries = [];
|
|
213
|
-
const learningDecisions = this.deps.
|
|
213
|
+
const learningDecisions = this.deps.getSessionLearningDecisionHistory();
|
|
214
214
|
for (const decision of learningDecisions.slice(-maxEntriesPerFamily)) {
|
|
215
215
|
learningEntries.push({
|
|
216
216
|
title: `Learning (${decision.kind})`,
|
|
@@ -1 +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;AAEhE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAO3E,OAAO,EACN,8BAA8B,EAE9B,oBAAoB,GACpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAA2B,MAAM,wBAAwB,CAAC;AAG9G,OAAO,EAAE,6BAA6B,EAAkC,MAAM,0BAA0B,CAAC;AAEzG;iFACiF;AACjF,MAAM,8BAA8B,GAAG,oBAAoB,CAAC;AAE5D,qGAAqG;AACrG,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAyBtC,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,iBAAiB,CAAC,8BAA8B,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,QAAQ,EAAE,CAAC,CAAC;QAC9G,CAAC;QAAC,MAAM,CAAC;YACR,sFAAsF;QACvF,CAAC;IAAA,CACD;IAED;;;;;;OAMG;IACH,iBAAiB,CAAC,OAAoB,EAAQ;QAC7C,IAAI,CAAC,wBAAwB,GAAG,OAAO,CAAC;QACxC,MAAM,EAAE,GAAG,IAAI,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;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 { 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 { hasCostSummarySignal, hasSubagentCostSignal, type SessionCostSummary } from \"./cost/cost-summary.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/** Single source of truth for CURRENT/TODAY/SUBAGENTS display costs. */\n\tgetCostSummary(): SessionCostSummary;\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 costSummary = this.deps.getCostSummary();\n\t\tif (hasCostSummarySignal(costSummary)) {\n\t\t\tsnapshot.costSummary = costSummary;\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 costSummary = this.deps.getCostSummary();\n\t\tif (costSummary.currentCost > 0 || hasSubagentCostSignal(costSummary)) {\n\t\t\tcosts.push({ title: \"CURRENT\", summary: `$${costSummary.currentCost.toFixed(4)}` });\n\t\t}\n\t\tif (costSummary.todayCost > 0) {\n\t\t\tcosts.push({ title: \"TODAY\", summary: `$${costSummary.todayCost.toFixed(4)}` });\n\t\t}\n\t\tif (hasSubagentCostSignal(costSummary)) {\n\t\t\tcosts.push({\n\t\t\t\ttitle: \"SUBAGENTS\",\n\t\t\t\tsummary: `$${costSummary.subagentCost.toFixed(4)} included in CURRENT`,\n\t\t\t});\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"]}
|
|
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;AAEhE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAO3E,OAAO,EACN,8BAA8B,EAE9B,oBAAoB,GACpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAA2B,MAAM,wBAAwB,CAAC;AAG9G,OAAO,EAAE,6BAA6B,EAAkC,MAAM,0BAA0B,CAAC;AAEzG;iFACiF;AACjF,MAAM,8BAA8B,GAAG,oBAAoB,CAAC;AAE5D,qGAAqG;AACrG,MAAM,0BAA0B,GAAG,EAAE,CAAC;AAyBtC,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,iBAAiB,CAAC,8BAA8B,EAAE,EAAE,OAAO,EAAE,CAA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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 { EvidenceBundle, GateOutcome, LearningDecision, WorkerClaim } 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 { hasCostSummarySignal, hasSubagentCostSignal, type SessionCostSummary } from \"./cost/cost-summary.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/** Single source of truth for CURRENT/TODAY/SUBAGENTS display costs. */\n\tgetCostSummary(): SessionCostSummary;\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 across the complete session tree, including sibling branches. */\n\tgetSessionEvidenceBundleHistory(): EvidenceBundle[];\n\t/** Worker-delegation claims across the complete session tree, including sibling branches. */\n\tgetSessionWorkerClaimHistory(): WorkerClaim[];\n\t/** Learning decisions across the complete session tree, including sibling branches. */\n\tgetSessionLearningDecisionHistory(): 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 costSummary = this.deps.getCostSummary();\n\t\tif (hasCostSummarySignal(costSummary)) {\n\t\t\tsnapshot.costSummary = costSummary;\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 costSummary = this.deps.getCostSummary();\n\t\tif (costSummary.currentCost > 0 || hasSubagentCostSignal(costSummary)) {\n\t\t\tcosts.push({ title: \"CURRENT\", summary: `$${costSummary.currentCost.toFixed(4)}` });\n\t\t}\n\t\tif (costSummary.todayCost > 0) {\n\t\t\tcosts.push({ title: \"TODAY\", summary: `$${costSummary.todayCost.toFixed(4)}` });\n\t\t}\n\t\tif (hasSubagentCostSignal(costSummary)) {\n\t\t\tcosts.push({\n\t\t\t\ttitle: \"SUBAGENTS\",\n\t\t\t\tsummary: `$${costSummary.subagentCost.toFixed(4)} included in CURRENT`,\n\t\t\t});\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.getSessionEvidenceBundleHistory().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 workerClaims = this.deps.getSessionWorkerClaimHistory();\n\t\tfor (const claim of workerClaims.slice(-maxEntriesPerFamily)) {\n\t\t\tdelegationEntries.push({\n\t\t\t\ttitle: `Worker ${claim.requestId} (${claim.status})`,\n\t\t\t\tsummary: claim.summary,\n\t\t\t\tmetadata: {\n\t\t\t\t\tchangedFileCount: claim.changedFiles.length,\n\t\t\t\t\tblockerCount: claim.blockers?.length ?? 0,\n\t\t\t\t\tusageReportId: claim.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.getSessionLearningDecisionHistory();\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"]}
|