@caupulican/pi-adaptative 0.81.39 → 0.81.41
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 +77 -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 +3 -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 +4 -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 +4 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +31 -1
- 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 +25 -2
- package/dist/core/agent-paths.d.ts.map +1 -1
- package/dist/core/agent-paths.js +79 -4
- package/dist/core/agent-paths.js.map +1 -1
- package/dist/core/agent-session-contracts.d.ts +293 -0
- package/dist/core/agent-session-contracts.d.ts.map +1 -0
- package/dist/core/agent-session-contracts.js +26 -0
- package/dist/core/agent-session-contracts.js.map +1 -0
- 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 +400 -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 +74 -518
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +370 -1432
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +3 -1
- package/dist/core/auth-storage.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 +48 -9
- 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 +56 -236
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +141 -1273
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/bedrock-sso-login.d.ts +16 -0
- package/dist/core/bedrock-sso-login.d.ts.map +1 -0
- package/dist/core/bedrock-sso-login.js +98 -0
- package/dist/core/bedrock-sso-login.js.map +1 -0
- 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 +13 -17
- package/dist/core/compaction-support.d.ts.map +1 -1
- package/dist/core/compaction-support.js +3 -3
- 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 +1 -1
- package/dist/core/context-pipeline.d.ts.map +1 -1
- package/dist/core/context-pipeline.js +16 -37
- package/dist/core/context-pipeline.js.map +1 -1
- package/dist/core/cost/cost-summary.d.ts.map +1 -1
- package/dist/core/cost/cost-summary.js +5 -3
- package/dist/core/cost/cost-summary.js.map +1 -1
- package/dist/core/cost/daily-usage.d.ts.map +1 -1
- package/dist/core/cost/daily-usage.js +4 -5
- package/dist/core/cost/daily-usage.js.map +1 -1
- package/dist/core/default-tool-surface.d.ts.map +1 -1
- package/dist/core/default-tool-surface.js +2 -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/extension-import-authority.d.ts +6 -0
- package/dist/core/extension-import-authority.d.ts.map +1 -0
- package/dist/core/extension-import-authority.js +10 -0
- package/dist/core/extension-import-authority.js.map +1 -0
- 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 +52 -18
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +3 -0
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +20 -5
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/stale-context.d.ts +2 -0
- package/dist/core/extensions/stale-context.d.ts.map +1 -0
- package/dist/core/extensions/stale-context.js +2 -0
- package/dist/core/extensions/stale-context.js.map +1 -0
- 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 +78 -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 +53 -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/goal-loop-controller.d.ts +14 -9
- package/dist/core/goal-loop-controller.d.ts.map +1 -1
- package/dist/core/goal-loop-controller.js +47 -75
- package/dist/core/goal-loop-controller.js.map +1 -1
- package/dist/core/goals/compact-goal-context.d.ts +11 -0
- package/dist/core/goals/compact-goal-context.d.ts.map +1 -0
- package/dist/core/goals/compact-goal-context.js +59 -0
- package/dist/core/goals/compact-goal-context.js.map +1 -0
- 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 +27 -0
- package/dist/core/goals/goal-acceptance.js.map +1 -0
- package/dist/core/goals/goal-auto-continue-controller.d.ts +28 -0
- package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -0
- package/dist/core/goals/goal-auto-continue-controller.js +90 -0
- package/dist/core/goals/goal-auto-continue-controller.js.map +1 -0
- package/dist/core/goals/goal-continuation-controller.d.ts +2 -2
- package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-controller.js +52 -11
- package/dist/core/goals/goal-continuation-controller.js.map +1 -1
- package/dist/core/goals/goal-continuation-defaults.d.ts +4 -29
- package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-defaults.js +4 -32
- package/dist/core/goals/goal-continuation-defaults.js.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.d.ts +8 -18
- package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.js +9 -179
- package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
- package/dist/core/goals/goal-lifecycle.d.ts +43 -0
- package/dist/core/goals/goal-lifecycle.d.ts.map +1 -0
- package/dist/core/goals/goal-lifecycle.js +102 -0
- package/dist/core/goals/goal-lifecycle.js.map +1 -0
- package/dist/core/goals/goal-record.d.ts +17 -0
- package/dist/core/goals/goal-record.d.ts.map +1 -0
- package/dist/core/goals/goal-record.js +31 -0
- package/dist/core/goals/goal-record.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-session-controller.d.ts +42 -0
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -0
- package/dist/core/goals/goal-session-controller.js +128 -0
- package/dist/core/goals/goal-session-controller.js.map +1 -0
- package/dist/core/goals/goal-state.d.ts +46 -25
- package/dist/core/goals/goal-state.d.ts.map +1 -1
- package/dist/core/goals/goal-state.js +91 -24
- package/dist/core/goals/goal-state.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts +9 -10
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js +60 -75
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/goals/session-goal-state.d.ts +20 -12
- package/dist/core/goals/session-goal-state.d.ts.map +1 -1
- package/dist/core/goals/session-goal-state.js +133 -33
- package/dist/core/goals/session-goal-state.js.map +1 -1
- package/dist/core/human-input-controller.d.ts +47 -0
- package/dist/core/human-input-controller.d.ts.map +1 -0
- package/dist/core/human-input-controller.js +181 -0
- package/dist/core/human-input-controller.js.map +1 -0
- 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/local-runtime-controller.d.ts +1 -1
- package/dist/core/local-runtime-controller.d.ts.map +1 -1
- package/dist/core/local-runtime-controller.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 +0 -19
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js +1 -19
- package/dist/core/model-capability.js.map +1 -1
- package/dist/core/model-registry.d.ts +6 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +13 -5
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +17 -2
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +38 -25
- 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 +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 +5 -5
- 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 +200 -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/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +20 -3
- package/dist/core/package-manager.js.map +1 -1
- 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-filter-controller.d.ts +8 -1
- package/dist/core/profile-filter-controller.d.ts.map +1 -1
- package/dist/core/profile-filter-controller.js +23 -5
- package/dist/core/profile-filter-controller.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/prompt-templates.d.ts +1 -0
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +18 -29
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/reflection-controller.d.ts +5 -5
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +5 -2
- 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/request-auth.d.ts +7 -0
- package/dist/core/request-auth.d.ts.map +1 -0
- package/dist/core/request-auth.js +8 -0
- package/dist/core/request-auth.js.map +1 -0
- 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 +23 -8
- 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 +233 -0
- package/dist/core/risk-classifier.js.map +1 -0
- package/dist/core/runtime-builder.d.ts +41 -23
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +365 -253
- 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 +68 -25
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/secrets/credential-exposure-guard.d.ts +9 -0
- package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -0
- package/dist/core/secrets/credential-exposure-guard.js +241 -0
- package/dist/core/secrets/credential-exposure-guard.js.map +1 -0
- package/dist/core/secrets/secret-dotenv.d.ts +27 -0
- package/dist/core/secrets/secret-dotenv.d.ts.map +1 -0
- package/dist/core/secrets/secret-dotenv.js +183 -0
- package/dist/core/secrets/secret-dotenv.js.map +1 -0
- package/dist/core/secrets/secret-vault-format.d.ts +112 -0
- package/dist/core/secrets/secret-vault-format.d.ts.map +1 -0
- package/dist/core/secrets/secret-vault-format.js +397 -0
- package/dist/core/secrets/secret-vault-format.js.map +1 -0
- package/dist/core/secrets/secret-vault.d.ts +72 -0
- package/dist/core/secrets/secret-vault.d.ts.map +1 -0
- package/dist/core/secrets/secret-vault.js +671 -0
- package/dist/core/secrets/secret-vault.js.map +1 -0
- package/dist/core/session-analytics.d.ts +4 -23
- package/dist/core/session-analytics.d.ts.map +1 -1
- package/dist/core/session-analytics.js +67 -70
- 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 +11 -4
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +24 -5
- 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/session-tree-navigator.d.ts +4 -6
- package/dist/core/session-tree-navigator.d.ts.map +1 -1
- package/dist/core/session-tree-navigator.js +4 -1
- package/dist/core/session-tree-navigator.js.map +1 -1
- package/dist/core/settings-manager.d.ts +10 -5
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +81 -29
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +2 -2
- package/dist/core/slash-commands.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 +86 -0
- package/dist/core/tool-capability-policy.js.map +1 -0
- package/dist/core/tool-gate-controller.d.ts.map +1 -1
- package/dist/core/tool-gate-controller.js +8 -2
- package/dist/core/tool-gate-controller.js.map +1 -1
- package/dist/core/tool-protocol-controller.d.ts +89 -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-recovery-stats.d.ts +21 -1
- package/dist/core/tool-recovery-stats.d.ts.map +1 -1
- package/dist/core/tool-recovery-stats.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/bash.d.ts +5 -0
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +59 -5
- package/dist/core/tools/bash.js.map +1 -1
- 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 +148 -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 +106 -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/git-filter.d.ts +1 -8
- package/dist/core/tools/git-filter.d.ts.map +1 -1
- package/dist/core/tools/git-filter.js +2 -63
- package/dist/core/tools/git-filter.js.map +1 -1
- package/dist/core/tools/goal.d.ts +10 -8
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +106 -28
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/index.d.ts +1 -0
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +1 -0
- package/dist/core/tools/index.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 +40 -0
- package/dist/core/tools/orchestration-panel.d.ts.map +1 -0
- package/dist/core/tools/orchestration-panel.js +124 -0
- package/dist/core/tools/orchestration-panel.js.map +1 -0
- package/dist/core/tools/output-accumulator.d.ts +11 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +36 -3
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/python.d.ts +2 -0
- package/dist/core/tools/python.d.ts.map +1 -1
- package/dist/core/tools/python.js +3 -1
- package/dist/core/tools/python.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +1 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/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/search-command-guard.d.ts +14 -0
- package/dist/core/tools/search-command-guard.d.ts.map +1 -0
- package/dist/core/tools/search-command-guard.js +333 -0
- package/dist/core/tools/search-command-guard.js.map +1 -0
- package/dist/core/tools/secret-store.d.ts +38 -0
- package/dist/core/tools/secret-store.d.ts.map +1 -0
- package/dist/core/tools/secret-store.js +412 -0
- package/dist/core/tools/secret-store.js.map +1 -0
- package/dist/core/tools/shell-command-parser.d.ts +16 -0
- package/dist/core/tools/shell-command-parser.d.ts.map +1 -0
- package/dist/core/tools/shell-command-parser.js +113 -0
- package/dist/core/tools/shell-command-parser.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 +99 -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/atomic-file.d.ts +6 -2
- package/dist/core/util/atomic-file.d.ts.map +1 -1
- package/dist/core/util/atomic-file.js +4 -4
- package/dist/core/util/atomic-file.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 +15 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +149 -51
- 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/auth-dialogs-controller.d.ts +4 -0
- package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
- package/dist/modes/interactive/auth-dialogs-controller.js +60 -1
- package/dist/modes/interactive/auth-dialogs-controller.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/activity-lane.d.ts +55 -0
- package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -0
- package/dist/modes/interactive/components/activity-lane.js +304 -0
- package/dist/modes/interactive/components/activity-lane.js.map +1 -0
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +19 -10
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/expandable-text.d.ts +12 -0
- package/dist/modes/interactive/components/expandable-text.d.ts.map +1 -0
- package/dist/modes/interactive/components/expandable-text.js +17 -0
- package/dist/modes/interactive/components/expandable-text.js.map +1 -0
- package/dist/modes/interactive/components/extension-editor.d.ts +15 -1
- package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-editor.js +30 -21
- package/dist/modes/interactive/components/extension-editor.js.map +1 -1
- package/dist/modes/interactive/components/extension-input.d.ts +1 -0
- package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/extension-input.js +6 -1
- package/dist/modes/interactive/components/extension-input.js.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.d.ts +2 -2
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +23 -14
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +6 -6
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +19 -11
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +53 -20
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-group.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-group.js +3 -0
- package/dist/modes/interactive/components/tool-group.js.map +1 -1
- package/dist/modes/interactive/components/usage-action-selector.d.ts +16 -0
- package/dist/modes/interactive/components/usage-action-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/usage-action-selector.js +46 -0
- package/dist/modes/interactive/components/usage-action-selector.js.map +1 -0
- 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 +77 -15
- package/dist/modes/interactive/extension-ui-host.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts +15 -0
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +27 -19
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/history-reload-math.d.ts +6 -2
- package/dist/modes/interactive/history-reload-math.d.ts.map +1 -1
- package/dist/modes/interactive/history-reload-math.js +10 -5
- package/dist/modes/interactive/history-reload-math.js.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.d.ts +74 -0
- package/dist/modes/interactive/interactive-event-controller.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-event-controller.js +328 -0
- package/dist/modes/interactive/interactive-event-controller.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +22 -24
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +245 -595
- 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/loaded-resources-view.d.ts +20 -0
- package/dist/modes/interactive/loaded-resources-view.d.ts.map +1 -0
- package/dist/modes/interactive/loaded-resources-view.js +147 -0
- package/dist/modes/interactive/loaded-resources-view.js.map +1 -0
- 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/resource-display.d.ts.map +1 -1
- package/dist/modes/interactive/resource-display.js +8 -2
- package/dist/modes/interactive/resource-display.js.map +1 -1
- package/dist/modes/interactive/resource-shell-commands.d.ts +1 -5
- package/dist/modes/interactive/resource-shell-commands.d.ts.map +1 -1
- package/dist/modes/interactive/resource-shell-commands.js +0 -5
- package/dist/modes/interactive/resource-shell-commands.js.map +1 -1
- package/dist/modes/interactive/session-flow-commands.d.ts +27 -8
- package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +150 -64
- 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/interactive/usage-commands.d.ts +34 -0
- package/dist/modes/interactive/usage-commands.d.ts.map +1 -0
- package/dist/modes/interactive/usage-commands.js +225 -0
- package/dist/modes/interactive/usage-commands.js.map +1 -0
- 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/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +5 -3
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +3 -1
- package/dist/utils/version-check.js.map +1 -1
- 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 +38 -0
- package/docs/UI_QUALITY_ORCHESTRATION.md +28 -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/providers.md +9 -1
- 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 +14 -0
- package/docs/ui-reference/orchestration-before.txt +13 -0
- package/docs/ui-reference/orchestration-reference.txt +16 -0
- package/docs/usage.md +22 -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 +13 -13
- 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
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Agent, AgentMessage, ThinkingLevel } from "@caupulican/pi-agent-core";
|
|
2
|
+
import { type CompactionResult, type CompactionSettings, type SessionManager } from "@caupulican/pi-agent-core/node";
|
|
3
|
+
import type { Api, AssistantMessage, Model } from "@caupulican/pi-ai";
|
|
4
|
+
import type { ExtensionRunner } from "./extensions/index.ts";
|
|
5
|
+
import type { FailureCorpusRecorder } from "./failure-corpus.ts";
|
|
6
|
+
import type { SettingsManager } from "./settings-manager.ts";
|
|
7
|
+
export type AutoCompactionReason = "overflow" | "threshold";
|
|
8
|
+
type CompactionControllerEvent = {
|
|
9
|
+
type: "compaction_start";
|
|
10
|
+
reason: "manual" | AutoCompactionReason;
|
|
11
|
+
} | {
|
|
12
|
+
type: "compaction_end";
|
|
13
|
+
reason: "manual" | AutoCompactionReason;
|
|
14
|
+
result: CompactionResult | undefined;
|
|
15
|
+
aborted: boolean;
|
|
16
|
+
willRetry: boolean;
|
|
17
|
+
errorMessage?: string;
|
|
18
|
+
skipReason?: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: "warning";
|
|
21
|
+
message: string;
|
|
22
|
+
};
|
|
23
|
+
export interface CompactionControllerDeps {
|
|
24
|
+
agent: Agent;
|
|
25
|
+
sessionManager: SessionManager;
|
|
26
|
+
settingsManager: SettingsManager;
|
|
27
|
+
getModel(): Model<Api> | undefined;
|
|
28
|
+
getAdaptedSettings(): CompactionSettings;
|
|
29
|
+
getRequestAuth(model: Model<Api>): Promise<{
|
|
30
|
+
apiKey?: string;
|
|
31
|
+
headers?: Record<string, string>;
|
|
32
|
+
}>;
|
|
33
|
+
resolveModelAndAuth(compactionModel: Model<Api>, sessionModel: Model<Api>): Promise<{
|
|
34
|
+
model: Model<Api>;
|
|
35
|
+
apiKey?: string;
|
|
36
|
+
headers?: Record<string, string>;
|
|
37
|
+
failure?: string;
|
|
38
|
+
}>;
|
|
39
|
+
resolveModel(sessionModel: Model<Api>): Model<Api>;
|
|
40
|
+
getSelectionReason(): string | undefined;
|
|
41
|
+
resolveThinkingLevel(compactionModel: Model<Api>, sessionModel: Model<Api>): ThinkingLevel | undefined;
|
|
42
|
+
describeSummarizer(): string;
|
|
43
|
+
getExtensionRunner(): ExtensionRunner;
|
|
44
|
+
isRawStream(): boolean;
|
|
45
|
+
disconnectAgent(): void;
|
|
46
|
+
reconnectAgent(): void;
|
|
47
|
+
abortForeground(): Promise<void>;
|
|
48
|
+
emit(event: CompactionControllerEvent): void;
|
|
49
|
+
estimateCurrentContextTokens(messages: AgentMessage[]): number;
|
|
50
|
+
buildPreDigest(): ((text: string, signal?: AbortSignal) => Promise<string>) | undefined;
|
|
51
|
+
refreshAfterCompaction(): void;
|
|
52
|
+
getFailureCorpus(): FailureCorpusRecorder;
|
|
53
|
+
measureLiveContextTokens(): number;
|
|
54
|
+
runAutoCompaction(reason: AutoCompactionReason, willRetry: boolean): Promise<boolean>;
|
|
55
|
+
compactWithRetry(run: () => Promise<CompactionResult>, signal: AbortSignal, provider?: string): Promise<CompactionResult>;
|
|
56
|
+
}
|
|
57
|
+
export declare function runCompactionWithRetry<T>(options: {
|
|
58
|
+
run(): Promise<T>;
|
|
59
|
+
signal: AbortSignal;
|
|
60
|
+
provider?: string;
|
|
61
|
+
getRetrySettings(): {
|
|
62
|
+
enabled: boolean;
|
|
63
|
+
maxRetries: number;
|
|
64
|
+
baseDelayMs: number;
|
|
65
|
+
};
|
|
66
|
+
recordFailure(record: Parameters<FailureCorpusRecorder["record"]>[0]): void;
|
|
67
|
+
}): Promise<T>;
|
|
68
|
+
/** Owns compaction detection, execution, retry, persistence, notification, and cancellation. */
|
|
69
|
+
export declare class CompactionController {
|
|
70
|
+
private manualAbortController;
|
|
71
|
+
private autoAbortController;
|
|
72
|
+
private overflowRecoveryAttempted;
|
|
73
|
+
private readonly deps;
|
|
74
|
+
constructor(deps: CompactionControllerDeps);
|
|
75
|
+
isRunning(): boolean;
|
|
76
|
+
resetOverflowRecovery(): void;
|
|
77
|
+
abort(): void;
|
|
78
|
+
checkContextWindowUsageWarning(): void;
|
|
79
|
+
maybeCompactBeforeContextTransform(messages: AgentMessage[], projectContextGc: (messages: AgentMessage[]) => AgentMessage[]): Promise<boolean>;
|
|
80
|
+
compact(customInstructions?: string): Promise<CompactionResult>;
|
|
81
|
+
check(assistantMessage: AssistantMessage, skipAbortedCheck?: boolean): Promise<boolean>;
|
|
82
|
+
measureLiveContextTokens(): number;
|
|
83
|
+
runAuto(reason: AutoCompactionReason, willRetry: boolean): Promise<boolean>;
|
|
84
|
+
compactWithRetry(run: () => Promise<CompactionResult>, signal: AbortSignal, provider?: string): Promise<CompactionResult>;
|
|
85
|
+
private findLastAssistantMessage;
|
|
86
|
+
private getExtensionCompaction;
|
|
87
|
+
private applyResult;
|
|
88
|
+
}
|
|
89
|
+
export {};
|
|
90
|
+
//# sourceMappingURL=compaction-controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compaction-controller.d.ts","sourceRoot":"","sources":["../../src/core/compaction-controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAe,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAEjG,OAAO,EAGN,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EAQvB,KAAK,cAAc,EAEnB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,GAAG,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAGtE,OAAO,KAAK,EAAE,eAAe,EAA8B,MAAM,uBAAuB,CAAC;AACzF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D,MAAM,MAAM,oBAAoB,GAAG,UAAU,GAAG,WAAW,CAAC;AAE5D,KAAK,yBAAyB,GAC3B;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,MAAM,EAAE,QAAQ,GAAG,oBAAoB,CAAA;CAAE,GACrE;IACA,IAAI,EAAE,gBAAgB,CAAC;IACvB,MAAM,EAAE,QAAQ,GAAG,oBAAoB,CAAC;IACxC,MAAM,EAAE,gBAAgB,GAAG,SAAS,CAAC;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACnB,GACD;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAExC,MAAM,WAAW,wBAAwB;IACxC,KAAK,EAAE,KAAK,CAAC;IACb,cAAc,EAAE,cAAc,CAAC;IAC/B,eAAe,EAAE,eAAe,CAAC;IACjC,QAAQ,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IACnC,kBAAkB,IAAI,kBAAkB,CAAC;IACzC,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAAE,CAAC,CAAC;IAClG,mBAAmB,CAClB,eAAe,EAAE,KAAK,CAAC,GAAG,CAAC,EAC3B,YAAY,EAAE,KAAK,CAAC,GAAG,CAAC,GACtB,OAAO,CAAC;QAAE,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACvG,YAAY,CAAC,YAAY,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IACnD,kBAAkB,IAAI,MAAM,GAAG,SAAS,CAAC;IACzC,oBAAoB,CAAC,eAAe,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,aAAa,GAAG,SAAS,CAAC;IACvG,kBAAkB,IAAI,MAAM,CAAC;IAC7B,kBAAkB,IAAI,eAAe,CAAC;IACtC,WAAW,IAAI,OAAO,CAAC;IACvB,eAAe,IAAI,IAAI,CAAC;IACxB,cAAc,IAAI,IAAI,CAAC;IACvB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,CAAC,KAAK,EAAE,yBAAyB,GAAG,IAAI,CAAC;IAC7C,4BAA4B,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;IAC/D,cAAc,IAAI,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC;IACxF,sBAAsB,IAAI,IAAI,CAAC;IAC/B,gBAAgB,IAAI,qBAAqB,CAAC;IAC1C,wBAAwB,IAAI,MAAM,CAAC;IACnC,iBAAiB,CAAC,MAAM,EAAE,oBAAoB,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACtF,gBAAgB,CACf,GAAG,EAAE,MAAM,OAAO,CAAC,gBAAgB,CAAC,EACpC,MAAM,EAAE,WAAW,EACnB,QAAQ,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC7B;AAED,wBAAsB,sBAAsB,CAAC,CAAC,EAAE,OAAO,EAAE;IACxD,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;IAClB,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,IAAI;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IAClF,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CAC5E,GAAG,OAAO,CAAC,CAAC,CAAC,CAwBb;AAED,gGAAgG;AAChG,qBAAa,oBAAoB;IAChC,OAAO,CAAC,qBAAqB,CAA8B;IAC3D,OAAO,CAAC,mBAAmB,CAA8B;IACzD,OAAO,CAAC,yBAAyB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA2B;IAEhD,YAAY,IAAI,EAAE,wBAAwB,EAEzC;IAED,SAAS,IAAI,OAAO,CAEnB;IAED,qBAAqB,IAAI,IAAI,CAE5B;IAED,KAAK,IAAI,IAAI,CAGZ;IAED,8BAA8B,IAAI,IAAI,CA0BrC;IAEK,kCAAkC,CACvC,QAAQ,EAAE,YAAY,EAAE,EACxB,gBAAgB,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,YAAY,EAAE,GAC5D,OAAO,CAAC,OAAO,CAAC,CAiBlB;IAEK,OAAO,CAAC,kBAAkB,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAkIpE;IAEK,KAAK,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,gBAAgB,UAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAiEzF;IAED,wBAAwB,IAAI,MAAM,CAWjC;IAEK,OAAO,CAAC,MAAM,EAAE,oBAAoB,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAgJhF;IAEK,gBAAgB,CACrB,GAAG,EAAE,MAAM,OAAO,CAAC,gBAAgB,CAAC,EACpC,MAAM,EAAE,WAAW,EACnB,QAAQ,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,gBAAgB,CAAC,CAQ3B;IAED,OAAO,CAAC,wBAAwB;YAQlB,sBAAsB;YAkBtB,WAAW;CAuBzB","sourcesContent":["import type { Agent, AgentMessage, RetryPolicy, ThinkingLevel } from \"@caupulican/pi-agent-core\";\nimport { classifyFailure, computeRetryDelayMs, DEFAULT_RETRY_POLICY, sleepAbortable } from \"@caupulican/pi-agent-core\";\nimport {\n\ttype CompactionEntry,\n\ttype CompactionPreparation,\n\ttype CompactionResult,\n\ttype CompactionSettings,\n\tcalculateContextTokens,\n\tcompact,\n\tcreateDeterministicCompaction,\n\testimateContextTokens,\n\tgetLatestCompactionEntry,\n\tprepareCompaction,\n\trunCompactionLoop,\n\ttype SessionManager,\n\tshouldCompact,\n} from \"@caupulican/pi-agent-core/node\";\nimport type { Api, AssistantMessage, Model } from \"@caupulican/pi-ai\";\nimport { isContextOverflow } from \"@caupulican/pi-ai\";\nimport { formatNoModelSelectedMessage } from \"./auth-guidance.ts\";\nimport type { ExtensionRunner, SessionBeforeCompactResult } from \"./extensions/index.ts\";\nimport type { FailureCorpusRecorder } from \"./failure-corpus.ts\";\nimport type { SettingsManager } from \"./settings-manager.ts\";\n\nexport type AutoCompactionReason = \"overflow\" | \"threshold\";\n\ntype CompactionControllerEvent =\n\t| { type: \"compaction_start\"; reason: \"manual\" | AutoCompactionReason }\n\t| {\n\t\t\ttype: \"compaction_end\";\n\t\t\treason: \"manual\" | AutoCompactionReason;\n\t\t\tresult: CompactionResult | undefined;\n\t\t\taborted: boolean;\n\t\t\twillRetry: boolean;\n\t\t\terrorMessage?: string;\n\t\t\tskipReason?: string;\n\t }\n\t| { type: \"warning\"; message: string };\n\nexport interface CompactionControllerDeps {\n\tagent: Agent;\n\tsessionManager: SessionManager;\n\tsettingsManager: SettingsManager;\n\tgetModel(): Model<Api> | undefined;\n\tgetAdaptedSettings(): CompactionSettings;\n\tgetRequestAuth(model: Model<Api>): Promise<{ apiKey?: string; headers?: Record<string, string> }>;\n\tresolveModelAndAuth(\n\t\tcompactionModel: Model<Api>,\n\t\tsessionModel: Model<Api>,\n\t): Promise<{ model: Model<Api>; apiKey?: string; headers?: Record<string, string>; failure?: string }>;\n\tresolveModel(sessionModel: Model<Api>): Model<Api>;\n\tgetSelectionReason(): string | undefined;\n\tresolveThinkingLevel(compactionModel: Model<Api>, sessionModel: Model<Api>): ThinkingLevel | undefined;\n\tdescribeSummarizer(): string;\n\tgetExtensionRunner(): ExtensionRunner;\n\tisRawStream(): boolean;\n\tdisconnectAgent(): void;\n\treconnectAgent(): void;\n\tabortForeground(): Promise<void>;\n\temit(event: CompactionControllerEvent): void;\n\testimateCurrentContextTokens(messages: AgentMessage[]): number;\n\tbuildPreDigest(): ((text: string, signal?: AbortSignal) => Promise<string>) | undefined;\n\trefreshAfterCompaction(): void;\n\tgetFailureCorpus(): FailureCorpusRecorder;\n\tmeasureLiveContextTokens(): number;\n\trunAutoCompaction(reason: AutoCompactionReason, willRetry: boolean): Promise<boolean>;\n\tcompactWithRetry(\n\t\trun: () => Promise<CompactionResult>,\n\t\tsignal: AbortSignal,\n\t\tprovider?: string,\n\t): Promise<CompactionResult>;\n}\n\nexport async function runCompactionWithRetry<T>(options: {\n\trun(): Promise<T>;\n\tsignal: AbortSignal;\n\tprovider?: string;\n\tgetRetrySettings(): { enabled: boolean; maxRetries: number; baseDelayMs: number };\n\trecordFailure(record: Parameters<FailureCorpusRecorder[\"record\"]>[0]): void;\n}): Promise<T> {\n\tconst retrySettings = options.getRetrySettings();\n\tconst maxAttempts = retrySettings.enabled ? Math.max(1, retrySettings.maxRetries + 1) : 1;\n\tconst policy: RetryPolicy = {\n\t\tmaxAttempts,\n\t\tbaseDelayMs: retrySettings.baseDelayMs,\n\t\tmaxDelayMs: DEFAULT_RETRY_POLICY.maxDelayMs,\n\t\tjitterRatio: 0,\n\t};\n\tfor (let attempt = 1; ; attempt++) {\n\t\ttry {\n\t\t\treturn await options.run();\n\t\t} catch (error) {\n\t\t\tif (options.signal.aborted || attempt >= maxAttempts) throw error;\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tconst classified = classifyFailure({ message, provider: options.provider });\n\t\t\toptions.recordFailure({ provider: options.provider, message, classified });\n\t\t\tif (!classified.retryable) throw error;\n\t\t\tawait sleepAbortable(\n\t\t\t\tcomputeRetryDelayMs(policy, attempt, { retryAfterMs: classified.retryAfterMs }),\n\t\t\t\toptions.signal,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/** Owns compaction detection, execution, retry, persistence, notification, and cancellation. */\nexport class CompactionController {\n\tprivate manualAbortController: AbortController | undefined;\n\tprivate autoAbortController: AbortController | undefined;\n\tprivate overflowRecoveryAttempted = false;\n\tprivate readonly deps: CompactionControllerDeps;\n\n\tconstructor(deps: CompactionControllerDeps) {\n\t\tthis.deps = deps;\n\t}\n\n\tisRunning(): boolean {\n\t\treturn this.manualAbortController !== undefined || this.autoAbortController !== undefined;\n\t}\n\n\tresetOverflowRecovery(): void {\n\t\tthis.overflowRecoveryAttempted = false;\n\t}\n\n\tabort(): void {\n\t\tthis.manualAbortController?.abort();\n\t\tthis.autoAbortController?.abort();\n\t}\n\n\tcheckContextWindowUsageWarning(): void {\n\t\tconst model = this.deps.getModel();\n\t\tif (!model) return;\n\t\tconst contextWindow = model.contextWindow ?? 0;\n\t\tif (contextWindow <= 0) return;\n\n\t\tconst systemPromptTokens = Math.ceil((this.deps.agent.state.systemPrompt ?? \"\").length / 4);\n\t\tlet toolsChars = 0;\n\t\tfor (const tool of this.deps.agent.state.tools || []) {\n\t\t\ttoolsChars += tool.name.length;\n\t\t\ttoolsChars += tool.description?.length ?? 0;\n\t\t\tif (tool.parameters) toolsChars += JSON.stringify(tool.parameters).length;\n\t\t}\n\t\tconst baseTokens = systemPromptTokens + Math.ceil(toolsChars / 4);\n\n\t\tif (baseTokens >= contextWindow) {\n\t\t\tthis.deps.emit({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tmessage: `Base configuration (system prompt and active tools) consumes ${baseTokens} tokens, which exceeds the model's context window of ${contextWindow} tokens. The model cannot process any prompts in this state.`,\n\t\t\t});\n\t\t} else if (baseTokens >= contextWindow * 0.7) {\n\t\t\tthis.deps.emit({\n\t\t\t\ttype: \"warning\",\n\t\t\t\tmessage: `Base configuration (system prompt and active tools) consumes ${baseTokens} tokens (${Math.round((baseTokens / contextWindow) * 100)}% of the ${contextWindow} context window). This leaves very little room for conversation history and may cause immediate compaction or context overflow.`,\n\t\t\t});\n\t\t}\n\t}\n\n\tasync maybeCompactBeforeContextTransform(\n\t\tmessages: AgentMessage[],\n\t\tprojectContextGc: (messages: AgentMessage[]) => AgentMessage[],\n\t): Promise<boolean> {\n\t\tconst settings = this.deps.getAdaptedSettings();\n\t\tconst model = this.deps.getModel();\n\t\tconst contextWindow = model?.contextWindow ?? 0;\n\t\tif (!settings.enabled || !model || contextWindow <= 0 || this.isRunning()) return false;\n\n\t\tconst triggerTokens = model.autoCompactionTriggerTokens;\n\t\tconst contextTokens = this.deps.estimateCurrentContextTokens(messages);\n\t\tif (!shouldCompact(contextTokens, contextWindow, settings, triggerTokens)) return false;\n\t\tconst projectedMessages = projectContextGc(messages);\n\t\tconst projectedTokens = this.deps.estimateCurrentContextTokens(projectedMessages);\n\t\tif (!shouldCompact(projectedTokens, contextWindow, settings, triggerTokens)) return false;\n\n\t\tconst latestBefore = getLatestCompactionEntry(this.deps.sessionManager.getBranch())?.id;\n\t\tawait this.deps.runAutoCompaction(\"threshold\", false);\n\t\tconst latestAfter = getLatestCompactionEntry(this.deps.sessionManager.getBranch())?.id;\n\t\treturn Boolean(latestAfter && latestAfter !== latestBefore);\n\t}\n\n\tasync compact(customInstructions?: string): Promise<CompactionResult> {\n\t\tthis.deps.disconnectAgent();\n\t\tawait this.deps.abortForeground();\n\t\tthis.manualAbortController = new AbortController();\n\t\tthis.deps.emit({ type: \"compaction_start\", reason: \"manual\" });\n\n\t\ttry {\n\t\t\tconst sessionModel = this.deps.getModel();\n\t\t\tif (!sessionModel) throw new Error(formatNoModelSelectedMessage());\n\n\t\t\tconst selectedCompactionModel = this.deps.resolveModel(sessionModel);\n\t\t\tif (this.deps.isRawStream()) await this.deps.getRequestAuth(selectedCompactionModel);\n\t\t\tconst selectionReason = this.deps.getSelectionReason() ?? \"unknown\";\n\t\t\tconst settings = this.deps.getAdaptedSettings();\n\t\t\tconst initialBranch = this.deps.sessionManager.getBranch();\n\t\t\tconst initialPreparation = prepareCompaction(initialBranch, settings);\n\t\t\tif (!initialPreparation) {\n\t\t\t\tconst lastEntry = initialBranch[initialBranch.length - 1];\n\t\t\t\tif (lastEntry?.type === \"compaction\") throw new Error(\"Already compacted\");\n\t\t\t\tthrow new Error(\"Nothing to compact (session too small)\");\n\t\t\t}\n\n\t\t\tconst signal = this.manualAbortController.signal;\n\t\t\tconst extension = await this.getExtensionCompaction(\n\t\t\t\tinitialPreparation,\n\t\t\t\tinitialBranch,\n\t\t\t\tcustomInstructions,\n\t\t\t\tsignal,\n\t\t\t);\n\t\t\tif (extension.cancelled) throw new Error(\"Compaction cancelled\");\n\t\t\tif (extension.result) {\n\t\t\t\tawait this.applyResult(extension.result, true);\n\t\t\t\tthis.deps.emit({\n\t\t\t\t\ttype: \"compaction_end\",\n\t\t\t\t\treason: \"manual\",\n\t\t\t\t\tresult: extension.result,\n\t\t\t\t\taborted: false,\n\t\t\t\t\twillRetry: false,\n\t\t\t\t});\n\t\t\t\treturn extension.result;\n\t\t\t}\n\n\t\t\tlet appliedResult: CompactionResult | undefined;\n\t\t\tconst outcome = await runCompactionLoop({\n\t\t\t\tmeasureLiveTokens: () =>\n\t\t\t\t\tMath.max(this.deps.estimateCurrentContextTokens(this.deps.agent.state.messages), 1),\n\t\t\t\tshouldCompact: () => true,\n\t\t\t\tgetPostApplyMargin: () => 0,\n\t\t\t\tgetBranch: () => this.deps.sessionManager.getBranch(),\n\t\t\t\tgetBaseKeepRecentTokens: () => settings.keepRecentTokens,\n\t\t\t\tresolveModelAndAuth: async (modelTier) => {\n\t\t\t\t\tconst model = modelTier === \"cheap\" ? selectedCompactionModel : sessionModel;\n\t\t\t\t\treturn this.deps.resolveModelAndAuth(model, sessionModel);\n\t\t\t\t},\n\t\t\t\tsummarizeAndVerify: async (params, model, apiKey, headers, branch) => {\n\t\t\t\t\tconst preparation = prepareCompaction(\n\t\t\t\t\t\tbranch,\n\t\t\t\t\t\t{ ...settings, keepRecentTokens: params.keepRecentTokens },\n\t\t\t\t\t\t{ allowTrailingCompactionAsPrevious: true },\n\t\t\t\t\t);\n\t\t\t\t\tif (!preparation) throw new Error(\"Nothing to compact (session too small)\");\n\t\t\t\t\tconst compactionThinkingLevel = this.deps.resolveThinkingLevel(model, sessionModel);\n\t\t\t\t\tconst result = await this.deps.compactWithRetry(\n\t\t\t\t\t\t() =>\n\t\t\t\t\t\t\tcompact(\n\t\t\t\t\t\t\t\tpreparation,\n\t\t\t\t\t\t\t\tmodel,\n\t\t\t\t\t\t\t\tapiKey,\n\t\t\t\t\t\t\t\theaders,\n\t\t\t\t\t\t\t\tcustomInstructions,\n\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\tcompactionThinkingLevel,\n\t\t\t\t\t\t\t\tthis.deps.agent.streamFn,\n\t\t\t\t\t\t\t\tthis.deps.buildPreDigest(),\n\t\t\t\t\t\t\t\t{ chunked: params.chunked },\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\tmodel.provider,\n\t\t\t\t\t);\n\t\t\t\t\treturn { result };\n\t\t\t\t},\n\t\t\t\tbuildDeterministicCheckpoint: () => ({ result: createDeterministicCompaction(initialPreparation) }),\n\t\t\t\tapply: async (result) => {\n\t\t\t\t\tif (signal.aborted) throw new Error(\"Compaction cancelled\");\n\t\t\t\t\tawait this.applyResult(result, false);\n\t\t\t\t\tappliedResult = result;\n\t\t\t\t},\n\t\t\t\tverifyPostApplyEffect: () => false,\n\t\t\t\tonTransition: ({ cycle, cause, detail }) => {\n\t\t\t\t\tthis.deps.emit({\n\t\t\t\t\t\ttype: \"warning\",\n\t\t\t\t\t\tmessage: `manual compaction cycle ${cycle}: ${cause}${detail ? ` (${detail})` : \"\"} — retrying from step 0 (${this.deps.describeSummarizer()})`,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tsignal,\n\t\t\t});\n\n\t\t\tif (outcome.kind === \"failed\") {\n\t\t\t\tif (outcome.reason === \"aborted\") throw new Error(\"Compaction cancelled\");\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`manual compaction failed after retry ladder using ${selectedCompactionModel.provider}/${selectedCompactionModel.id} (${selectionReason}); first failure: ${outcome.reason}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (outcome.kind === \"skip\" || !appliedResult) {\n\t\t\t\tthrow new Error(outcome.kind === \"skip\" ? outcome.reason : \"Compaction failed\");\n\t\t\t}\n\t\t\tthis.deps.emit({\n\t\t\t\ttype: \"compaction_end\",\n\t\t\t\treason: \"manual\",\n\t\t\t\tresult: appliedResult,\n\t\t\t\taborted: false,\n\t\t\t\twillRetry: false,\n\t\t\t});\n\t\t\treturn appliedResult;\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tconst aborted = message === \"Compaction cancelled\" || (error instanceof Error && error.name === \"AbortError\");\n\t\t\tthis.deps.emit({\n\t\t\t\ttype: \"compaction_end\",\n\t\t\t\treason: \"manual\",\n\t\t\t\tresult: undefined,\n\t\t\t\taborted,\n\t\t\t\twillRetry: false,\n\t\t\t\terrorMessage: aborted ? undefined : `Compaction failed: ${message}`,\n\t\t\t});\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tthis.manualAbortController = undefined;\n\t\t\tthis.deps.reconnectAgent();\n\t\t}\n\t}\n\n\tasync check(assistantMessage: AssistantMessage, skipAbortedCheck = true): Promise<boolean> {\n\t\tconst settings = this.deps.getAdaptedSettings();\n\t\tif (!settings.enabled) return false;\n\t\tif (skipAbortedCheck && assistantMessage.stopReason === \"aborted\") return false;\n\n\t\tconst model = this.deps.getModel();\n\t\tconst contextWindow = model?.contextWindow ?? 0;\n\t\tconst sameModel = model && assistantMessage.provider === model.provider && assistantMessage.model === model.id;\n\t\tconst compactionEntry = getLatestCompactionEntry(this.deps.sessionManager.getBranch());\n\t\tconst assistantIsFromBeforeCompaction =\n\t\t\tcompactionEntry !== null && assistantMessage.timestamp <= new Date(compactionEntry.timestamp).getTime();\n\t\tif (assistantIsFromBeforeCompaction) return false;\n\n\t\tif (sameModel && isContextOverflow(assistantMessage, contextWindow)) {\n\t\t\tif (this.overflowRecoveryAttempted) {\n\t\t\t\tthis.deps.emit({\n\t\t\t\t\ttype: \"compaction_end\",\n\t\t\t\t\treason: \"overflow\",\n\t\t\t\t\tresult: undefined,\n\t\t\t\t\taborted: false,\n\t\t\t\t\twillRetry: false,\n\t\t\t\t\terrorMessage:\n\t\t\t\t\t\t\"Context overflow recovery failed after one compact-and-retry attempt. Try reducing context or switching to a larger-context model.\",\n\t\t\t\t});\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tthis.overflowRecoveryAttempted = true;\n\t\t\tconst messages = this.deps.agent.state.messages;\n\t\t\tif (messages.length > 0 && messages[messages.length - 1].role === \"assistant\") {\n\t\t\t\tthis.deps.agent.state.messages = messages.slice(0, -1);\n\t\t\t}\n\t\t\treturn this.deps.runAutoCompaction(\"overflow\", true);\n\t\t}\n\n\t\tlet contextTokens: number;\n\t\tif (assistantMessage.stopReason === \"error\") {\n\t\t\tconst messages = this.deps.agent.state.messages;\n\t\t\tconst estimate = estimateContextTokens(messages);\n\t\t\tif (estimate.lastUsageIndex === null) return false;\n\t\t\tconst usageMessage = messages[estimate.lastUsageIndex];\n\t\t\tif (\n\t\t\t\tcompactionEntry &&\n\t\t\t\tusageMessage.role === \"assistant\" &&\n\t\t\t\tusageMessage.timestamp <= new Date(compactionEntry.timestamp).getTime()\n\t\t\t) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tcontextTokens = estimate.tokens;\n\t\t} else {\n\t\t\tcontextTokens = calculateContextTokens(assistantMessage.usage);\n\t\t\tconst estimate = estimateContextTokens(this.deps.agent.state.messages);\n\t\t\tif (estimate.lastUsageIndex !== null) {\n\t\t\t\tconst usageMessage = this.deps.agent.state.messages[estimate.lastUsageIndex];\n\t\t\t\tconst usageIsPostCompaction = !(\n\t\t\t\t\tcompactionEntry &&\n\t\t\t\t\tusageMessage.role === \"assistant\" &&\n\t\t\t\t\tusageMessage.timestamp <= new Date(compactionEntry.timestamp).getTime()\n\t\t\t\t);\n\t\t\t\tif (usageIsPostCompaction) contextTokens = Math.max(contextTokens, estimate.tokens);\n\t\t\t}\n\t\t}\n\t\tif (shouldCompact(contextTokens, contextWindow, settings, model?.autoCompactionTriggerTokens)) {\n\t\t\treturn this.deps.runAutoCompaction(\"threshold\", false);\n\t\t}\n\t\treturn false;\n\t}\n\n\tmeasureLiveContextTokens(): number {\n\t\tconst estimatedTokens = this.deps.estimateCurrentContextTokens(this.deps.agent.state.messages);\n\t\tconst assistantMessage = this.findLastAssistantMessage();\n\t\tif (!assistantMessage || assistantMessage.stopReason === \"error\" || assistantMessage.stopReason === \"aborted\") {\n\t\t\treturn estimatedTokens;\n\t\t}\n\t\tconst compactionEntry = getLatestCompactionEntry(this.deps.sessionManager.getBranch());\n\t\tif (compactionEntry && assistantMessage.timestamp <= new Date(compactionEntry.timestamp).getTime()) {\n\t\t\treturn estimatedTokens;\n\t\t}\n\t\treturn Math.max(calculateContextTokens(assistantMessage.usage), estimatedTokens);\n\t}\n\n\tasync runAuto(reason: AutoCompactionReason, willRetry: boolean): Promise<boolean> {\n\t\tconst settings = this.deps.getAdaptedSettings();\n\t\tconst model = this.deps.getModel();\n\t\tthis.deps.emit({ type: \"compaction_start\", reason });\n\t\tconst hadQueuedMessages = this.deps.agent.hasQueuedMessages();\n\t\tthis.autoAbortController = new AbortController();\n\t\tconst signal = this.autoAbortController.signal;\n\t\tlet fromExtension = false;\n\t\tlet lastCompaction: CompactionResult | undefined;\n\t\tlet extensionCancelled = false;\n\t\ttry {\n\t\t\tif (!model) {\n\t\t\t\tthis.deps.emit({\n\t\t\t\t\ttype: \"compaction_end\",\n\t\t\t\t\treason,\n\t\t\t\t\tresult: undefined,\n\t\t\t\t\taborted: false,\n\t\t\t\t\twillRetry: false,\n\t\t\t\t\tskipReason: \"no model selected\",\n\t\t\t\t});\n\t\t\t\treturn hadQueuedMessages || this.deps.agent.hasQueuedMessages();\n\t\t\t}\n\n\t\t\tconst contextWindow = model.contextWindow;\n\t\t\tconst margin = Math.max(0, Math.floor(0.01 * contextWindow));\n\t\t\tconst outcome = await runCompactionLoop({\n\t\t\t\tgetBranch: () => this.deps.sessionManager.getBranch(),\n\t\t\t\tmeasureLiveTokens: () => this.deps.measureLiveContextTokens(),\n\t\t\t\tshouldCompact:\n\t\t\t\t\treason === \"overflow\"\n\t\t\t\t\t\t? () => true\n\t\t\t\t\t\t: (tokens) => shouldCompact(tokens, contextWindow, settings, model.autoCompactionTriggerTokens),\n\t\t\t\tgetPostApplyMargin: () => margin,\n\t\t\t\tgetBaseKeepRecentTokens: () => settings.keepRecentTokens,\n\t\t\t\tresolveModelAndAuth: async (modelTier) =>\n\t\t\t\t\tthis.deps.resolveModelAndAuth(modelTier === \"session\" ? model : this.deps.resolveModel(model), model),\n\t\t\t\tsummarizeAndVerify: async (params, compactModel, apiKey, headers, branchEntries) => {\n\t\t\t\t\tfromExtension = false;\n\t\t\t\t\tconst preparation = prepareCompaction(branchEntries, {\n\t\t\t\t\t\t...settings,\n\t\t\t\t\t\tkeepRecentTokens: params.keepRecentTokens,\n\t\t\t\t\t});\n\t\t\t\t\tif (!preparation) throw new Error(\"already compacted\");\n\t\t\t\t\tconst compactionThinkingLevel = this.deps.resolveThinkingLevel(compactModel, model);\n\t\t\t\t\tconst extension = await this.getExtensionCompaction(preparation, branchEntries, undefined, signal);\n\t\t\t\t\tif (extension.cancelled) {\n\t\t\t\t\t\textensionCancelled = true;\n\t\t\t\t\t\tthrow new Error(\"auto-compaction-cancelled\");\n\t\t\t\t\t}\n\t\t\t\t\tif (extension.result) {\n\t\t\t\t\t\tfromExtension = true;\n\t\t\t\t\t\treturn { result: extension.result };\n\t\t\t\t\t}\n\t\t\t\t\tconst result = await this.deps.compactWithRetry(\n\t\t\t\t\t\t() =>\n\t\t\t\t\t\t\tcompact(\n\t\t\t\t\t\t\t\tpreparation,\n\t\t\t\t\t\t\t\tcompactModel,\n\t\t\t\t\t\t\t\tapiKey,\n\t\t\t\t\t\t\t\theaders,\n\t\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\tcompactionThinkingLevel,\n\t\t\t\t\t\t\t\tthis.deps.agent.streamFn,\n\t\t\t\t\t\t\t\tthis.deps.buildPreDigest(),\n\t\t\t\t\t\t\t\t{ chunked: params.chunked },\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\tsignal,\n\t\t\t\t\t\tcompactModel.provider,\n\t\t\t\t\t);\n\t\t\t\t\treturn { result };\n\t\t\t\t},\n\t\t\t\tbuildDeterministicCheckpoint: () => {\n\t\t\t\t\tconst preparation = prepareCompaction(this.deps.sessionManager.getBranch(), settings);\n\t\t\t\t\tif (!preparation) throw new Error(\"already compacted\");\n\t\t\t\t\tfromExtension = false;\n\t\t\t\t\treturn { result: createDeterministicCompaction(preparation) };\n\t\t\t\t},\n\t\t\t\tapply: async (result) => {\n\t\t\t\t\tlastCompaction = result;\n\t\t\t\t\tawait this.applyResult(result, fromExtension);\n\t\t\t\t},\n\t\t\t\tverifyPostApplyEffect: reason === \"overflow\" ? () => false : undefined,\n\t\t\t\tonTransition: ({ cycle, cause, detail }) => {\n\t\t\t\t\tthis.deps.emit({\n\t\t\t\t\t\ttype: \"warning\",\n\t\t\t\t\t\tmessage: `auto-compaction cycle ${cycle}: ${cause}${detail ? ` (${detail})` : \"\"} — retrying from step 0 (${this.deps.describeSummarizer()})`,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\tsignal,\n\t\t\t});\n\n\t\t\tif (outcome.kind === \"skip\") {\n\t\t\t\tthis.deps.emit({\n\t\t\t\t\ttype: \"compaction_end\",\n\t\t\t\t\treason,\n\t\t\t\t\tresult: undefined,\n\t\t\t\t\taborted: false,\n\t\t\t\t\twillRetry: false,\n\t\t\t\t\tskipReason: outcome.reason,\n\t\t\t\t});\n\t\t\t\treturn hadQueuedMessages || this.deps.agent.hasQueuedMessages();\n\t\t\t}\n\t\t\tif (outcome.kind === \"failed\") {\n\t\t\t\tif (outcome.reason === \"aborted\") {\n\t\t\t\t\tthis.deps.emit({ type: \"compaction_end\", reason, result: undefined, aborted: true, willRetry: false });\n\t\t\t\t\treturn hadQueuedMessages || this.deps.agent.hasQueuedMessages();\n\t\t\t\t}\n\t\t\t\tthrow new Error(outcome.reason);\n\t\t\t}\n\t\t\tif (extensionCancelled || signal.aborted) {\n\t\t\t\tthis.deps.emit({ type: \"compaction_end\", reason, result: undefined, aborted: true, willRetry: false });\n\t\t\t\treturn hadQueuedMessages || this.deps.agent.hasQueuedMessages();\n\t\t\t}\n\n\t\t\tconst result = outcome.kind === \"success\" ? outcome.result : lastCompaction;\n\t\t\tif (!result) throw new Error(\"Auto-compaction succeeded without a result\");\n\t\t\tthis.deps.emit({ type: \"compaction_end\", reason, result, aborted: false, willRetry });\n\t\t\tif (willRetry) {\n\t\t\t\tconst messages = this.deps.agent.state.messages;\n\t\t\t\tconst lastMessage = messages[messages.length - 1];\n\t\t\t\tif (lastMessage?.role === \"assistant\" && lastMessage.stopReason === \"error\") {\n\t\t\t\t\tthis.deps.agent.state.messages = messages.slice(0, -1);\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn hadQueuedMessages || this.deps.agent.hasQueuedMessages();\n\t\t} catch (error) {\n\t\t\tconst errorMessage = error instanceof Error ? error.message : \"compaction failed\";\n\t\t\tthis.deps.emit({\n\t\t\t\ttype: \"compaction_end\",\n\t\t\t\treason,\n\t\t\t\tresult: undefined,\n\t\t\t\taborted: false,\n\t\t\t\twillRetry: false,\n\t\t\t\terrorMessage:\n\t\t\t\t\treason === \"overflow\"\n\t\t\t\t\t\t? `Context overflow recovery failed: ${errorMessage}`\n\t\t\t\t\t\t: `Auto-compaction failed: ${errorMessage}`,\n\t\t\t});\n\t\t\treturn hadQueuedMessages || this.deps.agent.hasQueuedMessages();\n\t\t} finally {\n\t\t\tthis.autoAbortController = undefined;\n\t\t}\n\t}\n\n\tasync compactWithRetry(\n\t\trun: () => Promise<CompactionResult>,\n\t\tsignal: AbortSignal,\n\t\tprovider?: string,\n\t): Promise<CompactionResult> {\n\t\treturn runCompactionWithRetry({\n\t\t\trun,\n\t\t\tsignal,\n\t\t\tprovider,\n\t\t\tgetRetrySettings: () => this.deps.settingsManager.getRetrySettings(),\n\t\t\trecordFailure: (record) => this.deps.getFailureCorpus().record(record),\n\t\t});\n\t}\n\n\tprivate findLastAssistantMessage(): AssistantMessage | undefined {\n\t\tfor (let index = this.deps.agent.state.messages.length - 1; index >= 0; index--) {\n\t\t\tconst message = this.deps.agent.state.messages[index];\n\t\t\tif (message.role === \"assistant\") return message;\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tprivate async getExtensionCompaction(\n\t\tpreparation: CompactionPreparation,\n\t\tbranchEntries: ReturnType<SessionManager[\"getBranch\"]>,\n\t\tcustomInstructions: string | undefined,\n\t\tsignal: AbortSignal,\n\t): Promise<{ cancelled: boolean; result?: CompactionResult }> {\n\t\tconst extensionRunner = this.deps.getExtensionRunner();\n\t\tif (!extensionRunner.hasHandlers(\"session_before_compact\")) return { cancelled: false };\n\t\tconst extensionResult = (await extensionRunner.emit({\n\t\t\ttype: \"session_before_compact\",\n\t\t\tpreparation,\n\t\t\tbranchEntries,\n\t\t\tcustomInstructions,\n\t\t\tsignal,\n\t\t})) as SessionBeforeCompactResult | undefined;\n\t\treturn { cancelled: extensionResult?.cancel === true, result: extensionResult?.compaction };\n\t}\n\n\tprivate async applyResult(result: CompactionResult, fromExtension: boolean): Promise<void> {\n\t\tthis.deps.sessionManager.appendCompaction(\n\t\t\tresult.summary,\n\t\t\tresult.firstKeptEntryId,\n\t\t\tresult.tokensBefore,\n\t\t\tresult.details,\n\t\t\tfromExtension,\n\t\t\tresult.usage,\n\t\t);\n\t\tthis.deps.refreshAfterCompaction();\n\t\tconst savedEntry = this.deps.sessionManager\n\t\t\t.getEntries()\n\t\t\t.find((entry) => entry.type === \"compaction\" && entry.summary === result.summary) as\n\t\t\t| CompactionEntry\n\t\t\t| undefined;\n\t\tif (savedEntry) {\n\t\t\tawait this.deps.getExtensionRunner().emit({\n\t\t\t\ttype: \"session_compact\",\n\t\t\t\tcompactionEntry: savedEntry,\n\t\t\t\tfromExtension,\n\t\t\t});\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import { classifyFailure, computeRetryDelayMs, DEFAULT_RETRY_POLICY, sleepAbortable } from "@caupulican/pi-agent-core";
|
|
2
|
+
import { calculateContextTokens, compact, createDeterministicCompaction, estimateContextTokens, getLatestCompactionEntry, prepareCompaction, runCompactionLoop, shouldCompact, } from "@caupulican/pi-agent-core/node";
|
|
3
|
+
import { isContextOverflow } from "@caupulican/pi-ai";
|
|
4
|
+
import { formatNoModelSelectedMessage } from "./auth-guidance.js";
|
|
5
|
+
export async function runCompactionWithRetry(options) {
|
|
6
|
+
const retrySettings = options.getRetrySettings();
|
|
7
|
+
const maxAttempts = retrySettings.enabled ? Math.max(1, retrySettings.maxRetries + 1) : 1;
|
|
8
|
+
const policy = {
|
|
9
|
+
maxAttempts,
|
|
10
|
+
baseDelayMs: retrySettings.baseDelayMs,
|
|
11
|
+
maxDelayMs: DEFAULT_RETRY_POLICY.maxDelayMs,
|
|
12
|
+
jitterRatio: 0,
|
|
13
|
+
};
|
|
14
|
+
for (let attempt = 1;; attempt++) {
|
|
15
|
+
try {
|
|
16
|
+
return await options.run();
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (options.signal.aborted || attempt >= maxAttempts)
|
|
20
|
+
throw error;
|
|
21
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
22
|
+
const classified = classifyFailure({ message, provider: options.provider });
|
|
23
|
+
options.recordFailure({ provider: options.provider, message, classified });
|
|
24
|
+
if (!classified.retryable)
|
|
25
|
+
throw error;
|
|
26
|
+
await sleepAbortable(computeRetryDelayMs(policy, attempt, { retryAfterMs: classified.retryAfterMs }), options.signal);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** Owns compaction detection, execution, retry, persistence, notification, and cancellation. */
|
|
31
|
+
export class CompactionController {
|
|
32
|
+
manualAbortController;
|
|
33
|
+
autoAbortController;
|
|
34
|
+
overflowRecoveryAttempted = false;
|
|
35
|
+
deps;
|
|
36
|
+
constructor(deps) {
|
|
37
|
+
this.deps = deps;
|
|
38
|
+
}
|
|
39
|
+
isRunning() {
|
|
40
|
+
return this.manualAbortController !== undefined || this.autoAbortController !== undefined;
|
|
41
|
+
}
|
|
42
|
+
resetOverflowRecovery() {
|
|
43
|
+
this.overflowRecoveryAttempted = false;
|
|
44
|
+
}
|
|
45
|
+
abort() {
|
|
46
|
+
this.manualAbortController?.abort();
|
|
47
|
+
this.autoAbortController?.abort();
|
|
48
|
+
}
|
|
49
|
+
checkContextWindowUsageWarning() {
|
|
50
|
+
const model = this.deps.getModel();
|
|
51
|
+
if (!model)
|
|
52
|
+
return;
|
|
53
|
+
const contextWindow = model.contextWindow ?? 0;
|
|
54
|
+
if (contextWindow <= 0)
|
|
55
|
+
return;
|
|
56
|
+
const systemPromptTokens = Math.ceil((this.deps.agent.state.systemPrompt ?? "").length / 4);
|
|
57
|
+
let toolsChars = 0;
|
|
58
|
+
for (const tool of this.deps.agent.state.tools || []) {
|
|
59
|
+
toolsChars += tool.name.length;
|
|
60
|
+
toolsChars += tool.description?.length ?? 0;
|
|
61
|
+
if (tool.parameters)
|
|
62
|
+
toolsChars += JSON.stringify(tool.parameters).length;
|
|
63
|
+
}
|
|
64
|
+
const baseTokens = systemPromptTokens + Math.ceil(toolsChars / 4);
|
|
65
|
+
if (baseTokens >= contextWindow) {
|
|
66
|
+
this.deps.emit({
|
|
67
|
+
type: "warning",
|
|
68
|
+
message: `Base configuration (system prompt and active tools) consumes ${baseTokens} tokens, which exceeds the model's context window of ${contextWindow} tokens. The model cannot process any prompts in this state.`,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
else if (baseTokens >= contextWindow * 0.7) {
|
|
72
|
+
this.deps.emit({
|
|
73
|
+
type: "warning",
|
|
74
|
+
message: `Base configuration (system prompt and active tools) consumes ${baseTokens} tokens (${Math.round((baseTokens / contextWindow) * 100)}% of the ${contextWindow} context window). This leaves very little room for conversation history and may cause immediate compaction or context overflow.`,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async maybeCompactBeforeContextTransform(messages, projectContextGc) {
|
|
79
|
+
const settings = this.deps.getAdaptedSettings();
|
|
80
|
+
const model = this.deps.getModel();
|
|
81
|
+
const contextWindow = model?.contextWindow ?? 0;
|
|
82
|
+
if (!settings.enabled || !model || contextWindow <= 0 || this.isRunning())
|
|
83
|
+
return false;
|
|
84
|
+
const triggerTokens = model.autoCompactionTriggerTokens;
|
|
85
|
+
const contextTokens = this.deps.estimateCurrentContextTokens(messages);
|
|
86
|
+
if (!shouldCompact(contextTokens, contextWindow, settings, triggerTokens))
|
|
87
|
+
return false;
|
|
88
|
+
const projectedMessages = projectContextGc(messages);
|
|
89
|
+
const projectedTokens = this.deps.estimateCurrentContextTokens(projectedMessages);
|
|
90
|
+
if (!shouldCompact(projectedTokens, contextWindow, settings, triggerTokens))
|
|
91
|
+
return false;
|
|
92
|
+
const latestBefore = getLatestCompactionEntry(this.deps.sessionManager.getBranch())?.id;
|
|
93
|
+
await this.deps.runAutoCompaction("threshold", false);
|
|
94
|
+
const latestAfter = getLatestCompactionEntry(this.deps.sessionManager.getBranch())?.id;
|
|
95
|
+
return Boolean(latestAfter && latestAfter !== latestBefore);
|
|
96
|
+
}
|
|
97
|
+
async compact(customInstructions) {
|
|
98
|
+
this.deps.disconnectAgent();
|
|
99
|
+
await this.deps.abortForeground();
|
|
100
|
+
this.manualAbortController = new AbortController();
|
|
101
|
+
this.deps.emit({ type: "compaction_start", reason: "manual" });
|
|
102
|
+
try {
|
|
103
|
+
const sessionModel = this.deps.getModel();
|
|
104
|
+
if (!sessionModel)
|
|
105
|
+
throw new Error(formatNoModelSelectedMessage());
|
|
106
|
+
const selectedCompactionModel = this.deps.resolveModel(sessionModel);
|
|
107
|
+
if (this.deps.isRawStream())
|
|
108
|
+
await this.deps.getRequestAuth(selectedCompactionModel);
|
|
109
|
+
const selectionReason = this.deps.getSelectionReason() ?? "unknown";
|
|
110
|
+
const settings = this.deps.getAdaptedSettings();
|
|
111
|
+
const initialBranch = this.deps.sessionManager.getBranch();
|
|
112
|
+
const initialPreparation = prepareCompaction(initialBranch, settings);
|
|
113
|
+
if (!initialPreparation) {
|
|
114
|
+
const lastEntry = initialBranch[initialBranch.length - 1];
|
|
115
|
+
if (lastEntry?.type === "compaction")
|
|
116
|
+
throw new Error("Already compacted");
|
|
117
|
+
throw new Error("Nothing to compact (session too small)");
|
|
118
|
+
}
|
|
119
|
+
const signal = this.manualAbortController.signal;
|
|
120
|
+
const extension = await this.getExtensionCompaction(initialPreparation, initialBranch, customInstructions, signal);
|
|
121
|
+
if (extension.cancelled)
|
|
122
|
+
throw new Error("Compaction cancelled");
|
|
123
|
+
if (extension.result) {
|
|
124
|
+
await this.applyResult(extension.result, true);
|
|
125
|
+
this.deps.emit({
|
|
126
|
+
type: "compaction_end",
|
|
127
|
+
reason: "manual",
|
|
128
|
+
result: extension.result,
|
|
129
|
+
aborted: false,
|
|
130
|
+
willRetry: false,
|
|
131
|
+
});
|
|
132
|
+
return extension.result;
|
|
133
|
+
}
|
|
134
|
+
let appliedResult;
|
|
135
|
+
const outcome = await runCompactionLoop({
|
|
136
|
+
measureLiveTokens: () => Math.max(this.deps.estimateCurrentContextTokens(this.deps.agent.state.messages), 1),
|
|
137
|
+
shouldCompact: () => true,
|
|
138
|
+
getPostApplyMargin: () => 0,
|
|
139
|
+
getBranch: () => this.deps.sessionManager.getBranch(),
|
|
140
|
+
getBaseKeepRecentTokens: () => settings.keepRecentTokens,
|
|
141
|
+
resolveModelAndAuth: async (modelTier) => {
|
|
142
|
+
const model = modelTier === "cheap" ? selectedCompactionModel : sessionModel;
|
|
143
|
+
return this.deps.resolveModelAndAuth(model, sessionModel);
|
|
144
|
+
},
|
|
145
|
+
summarizeAndVerify: async (params, model, apiKey, headers, branch) => {
|
|
146
|
+
const preparation = prepareCompaction(branch, { ...settings, keepRecentTokens: params.keepRecentTokens }, { allowTrailingCompactionAsPrevious: true });
|
|
147
|
+
if (!preparation)
|
|
148
|
+
throw new Error("Nothing to compact (session too small)");
|
|
149
|
+
const compactionThinkingLevel = this.deps.resolveThinkingLevel(model, sessionModel);
|
|
150
|
+
const result = await this.deps.compactWithRetry(() => compact(preparation, model, apiKey, headers, customInstructions, signal, compactionThinkingLevel, this.deps.agent.streamFn, this.deps.buildPreDigest(), { chunked: params.chunked }), signal, model.provider);
|
|
151
|
+
return { result };
|
|
152
|
+
},
|
|
153
|
+
buildDeterministicCheckpoint: () => ({ result: createDeterministicCompaction(initialPreparation) }),
|
|
154
|
+
apply: async (result) => {
|
|
155
|
+
if (signal.aborted)
|
|
156
|
+
throw new Error("Compaction cancelled");
|
|
157
|
+
await this.applyResult(result, false);
|
|
158
|
+
appliedResult = result;
|
|
159
|
+
},
|
|
160
|
+
verifyPostApplyEffect: () => false,
|
|
161
|
+
onTransition: ({ cycle, cause, detail }) => {
|
|
162
|
+
this.deps.emit({
|
|
163
|
+
type: "warning",
|
|
164
|
+
message: `manual compaction cycle ${cycle}: ${cause}${detail ? ` (${detail})` : ""} — retrying from step 0 (${this.deps.describeSummarizer()})`,
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
signal,
|
|
168
|
+
});
|
|
169
|
+
if (outcome.kind === "failed") {
|
|
170
|
+
if (outcome.reason === "aborted")
|
|
171
|
+
throw new Error("Compaction cancelled");
|
|
172
|
+
throw new Error(`manual compaction failed after retry ladder using ${selectedCompactionModel.provider}/${selectedCompactionModel.id} (${selectionReason}); first failure: ${outcome.reason}`);
|
|
173
|
+
}
|
|
174
|
+
if (outcome.kind === "skip" || !appliedResult) {
|
|
175
|
+
throw new Error(outcome.kind === "skip" ? outcome.reason : "Compaction failed");
|
|
176
|
+
}
|
|
177
|
+
this.deps.emit({
|
|
178
|
+
type: "compaction_end",
|
|
179
|
+
reason: "manual",
|
|
180
|
+
result: appliedResult,
|
|
181
|
+
aborted: false,
|
|
182
|
+
willRetry: false,
|
|
183
|
+
});
|
|
184
|
+
return appliedResult;
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
188
|
+
const aborted = message === "Compaction cancelled" || (error instanceof Error && error.name === "AbortError");
|
|
189
|
+
this.deps.emit({
|
|
190
|
+
type: "compaction_end",
|
|
191
|
+
reason: "manual",
|
|
192
|
+
result: undefined,
|
|
193
|
+
aborted,
|
|
194
|
+
willRetry: false,
|
|
195
|
+
errorMessage: aborted ? undefined : `Compaction failed: ${message}`,
|
|
196
|
+
});
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
199
|
+
finally {
|
|
200
|
+
this.manualAbortController = undefined;
|
|
201
|
+
this.deps.reconnectAgent();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
async check(assistantMessage, skipAbortedCheck = true) {
|
|
205
|
+
const settings = this.deps.getAdaptedSettings();
|
|
206
|
+
if (!settings.enabled)
|
|
207
|
+
return false;
|
|
208
|
+
if (skipAbortedCheck && assistantMessage.stopReason === "aborted")
|
|
209
|
+
return false;
|
|
210
|
+
const model = this.deps.getModel();
|
|
211
|
+
const contextWindow = model?.contextWindow ?? 0;
|
|
212
|
+
const sameModel = model && assistantMessage.provider === model.provider && assistantMessage.model === model.id;
|
|
213
|
+
const compactionEntry = getLatestCompactionEntry(this.deps.sessionManager.getBranch());
|
|
214
|
+
const assistantIsFromBeforeCompaction = compactionEntry !== null && assistantMessage.timestamp <= new Date(compactionEntry.timestamp).getTime();
|
|
215
|
+
if (assistantIsFromBeforeCompaction)
|
|
216
|
+
return false;
|
|
217
|
+
if (sameModel && isContextOverflow(assistantMessage, contextWindow)) {
|
|
218
|
+
if (this.overflowRecoveryAttempted) {
|
|
219
|
+
this.deps.emit({
|
|
220
|
+
type: "compaction_end",
|
|
221
|
+
reason: "overflow",
|
|
222
|
+
result: undefined,
|
|
223
|
+
aborted: false,
|
|
224
|
+
willRetry: false,
|
|
225
|
+
errorMessage: "Context overflow recovery failed after one compact-and-retry attempt. Try reducing context or switching to a larger-context model.",
|
|
226
|
+
});
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
this.overflowRecoveryAttempted = true;
|
|
230
|
+
const messages = this.deps.agent.state.messages;
|
|
231
|
+
if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
|
|
232
|
+
this.deps.agent.state.messages = messages.slice(0, -1);
|
|
233
|
+
}
|
|
234
|
+
return this.deps.runAutoCompaction("overflow", true);
|
|
235
|
+
}
|
|
236
|
+
let contextTokens;
|
|
237
|
+
if (assistantMessage.stopReason === "error") {
|
|
238
|
+
const messages = this.deps.agent.state.messages;
|
|
239
|
+
const estimate = estimateContextTokens(messages);
|
|
240
|
+
if (estimate.lastUsageIndex === null)
|
|
241
|
+
return false;
|
|
242
|
+
const usageMessage = messages[estimate.lastUsageIndex];
|
|
243
|
+
if (compactionEntry &&
|
|
244
|
+
usageMessage.role === "assistant" &&
|
|
245
|
+
usageMessage.timestamp <= new Date(compactionEntry.timestamp).getTime()) {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
contextTokens = estimate.tokens;
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
contextTokens = calculateContextTokens(assistantMessage.usage);
|
|
252
|
+
const estimate = estimateContextTokens(this.deps.agent.state.messages);
|
|
253
|
+
if (estimate.lastUsageIndex !== null) {
|
|
254
|
+
const usageMessage = this.deps.agent.state.messages[estimate.lastUsageIndex];
|
|
255
|
+
const usageIsPostCompaction = !(compactionEntry &&
|
|
256
|
+
usageMessage.role === "assistant" &&
|
|
257
|
+
usageMessage.timestamp <= new Date(compactionEntry.timestamp).getTime());
|
|
258
|
+
if (usageIsPostCompaction)
|
|
259
|
+
contextTokens = Math.max(contextTokens, estimate.tokens);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (shouldCompact(contextTokens, contextWindow, settings, model?.autoCompactionTriggerTokens)) {
|
|
263
|
+
return this.deps.runAutoCompaction("threshold", false);
|
|
264
|
+
}
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
measureLiveContextTokens() {
|
|
268
|
+
const estimatedTokens = this.deps.estimateCurrentContextTokens(this.deps.agent.state.messages);
|
|
269
|
+
const assistantMessage = this.findLastAssistantMessage();
|
|
270
|
+
if (!assistantMessage || assistantMessage.stopReason === "error" || assistantMessage.stopReason === "aborted") {
|
|
271
|
+
return estimatedTokens;
|
|
272
|
+
}
|
|
273
|
+
const compactionEntry = getLatestCompactionEntry(this.deps.sessionManager.getBranch());
|
|
274
|
+
if (compactionEntry && assistantMessage.timestamp <= new Date(compactionEntry.timestamp).getTime()) {
|
|
275
|
+
return estimatedTokens;
|
|
276
|
+
}
|
|
277
|
+
return Math.max(calculateContextTokens(assistantMessage.usage), estimatedTokens);
|
|
278
|
+
}
|
|
279
|
+
async runAuto(reason, willRetry) {
|
|
280
|
+
const settings = this.deps.getAdaptedSettings();
|
|
281
|
+
const model = this.deps.getModel();
|
|
282
|
+
this.deps.emit({ type: "compaction_start", reason });
|
|
283
|
+
const hadQueuedMessages = this.deps.agent.hasQueuedMessages();
|
|
284
|
+
this.autoAbortController = new AbortController();
|
|
285
|
+
const signal = this.autoAbortController.signal;
|
|
286
|
+
let fromExtension = false;
|
|
287
|
+
let lastCompaction;
|
|
288
|
+
let extensionCancelled = false;
|
|
289
|
+
try {
|
|
290
|
+
if (!model) {
|
|
291
|
+
this.deps.emit({
|
|
292
|
+
type: "compaction_end",
|
|
293
|
+
reason,
|
|
294
|
+
result: undefined,
|
|
295
|
+
aborted: false,
|
|
296
|
+
willRetry: false,
|
|
297
|
+
skipReason: "no model selected",
|
|
298
|
+
});
|
|
299
|
+
return hadQueuedMessages || this.deps.agent.hasQueuedMessages();
|
|
300
|
+
}
|
|
301
|
+
const contextWindow = model.contextWindow;
|
|
302
|
+
const margin = Math.max(0, Math.floor(0.01 * contextWindow));
|
|
303
|
+
const outcome = await runCompactionLoop({
|
|
304
|
+
getBranch: () => this.deps.sessionManager.getBranch(),
|
|
305
|
+
measureLiveTokens: () => this.deps.measureLiveContextTokens(),
|
|
306
|
+
shouldCompact: reason === "overflow"
|
|
307
|
+
? () => true
|
|
308
|
+
: (tokens) => shouldCompact(tokens, contextWindow, settings, model.autoCompactionTriggerTokens),
|
|
309
|
+
getPostApplyMargin: () => margin,
|
|
310
|
+
getBaseKeepRecentTokens: () => settings.keepRecentTokens,
|
|
311
|
+
resolveModelAndAuth: async (modelTier) => this.deps.resolveModelAndAuth(modelTier === "session" ? model : this.deps.resolveModel(model), model),
|
|
312
|
+
summarizeAndVerify: async (params, compactModel, apiKey, headers, branchEntries) => {
|
|
313
|
+
fromExtension = false;
|
|
314
|
+
const preparation = prepareCompaction(branchEntries, {
|
|
315
|
+
...settings,
|
|
316
|
+
keepRecentTokens: params.keepRecentTokens,
|
|
317
|
+
});
|
|
318
|
+
if (!preparation)
|
|
319
|
+
throw new Error("already compacted");
|
|
320
|
+
const compactionThinkingLevel = this.deps.resolveThinkingLevel(compactModel, model);
|
|
321
|
+
const extension = await this.getExtensionCompaction(preparation, branchEntries, undefined, signal);
|
|
322
|
+
if (extension.cancelled) {
|
|
323
|
+
extensionCancelled = true;
|
|
324
|
+
throw new Error("auto-compaction-cancelled");
|
|
325
|
+
}
|
|
326
|
+
if (extension.result) {
|
|
327
|
+
fromExtension = true;
|
|
328
|
+
return { result: extension.result };
|
|
329
|
+
}
|
|
330
|
+
const result = await this.deps.compactWithRetry(() => compact(preparation, compactModel, apiKey, headers, undefined, signal, compactionThinkingLevel, this.deps.agent.streamFn, this.deps.buildPreDigest(), { chunked: params.chunked }), signal, compactModel.provider);
|
|
331
|
+
return { result };
|
|
332
|
+
},
|
|
333
|
+
buildDeterministicCheckpoint: () => {
|
|
334
|
+
const preparation = prepareCompaction(this.deps.sessionManager.getBranch(), settings);
|
|
335
|
+
if (!preparation)
|
|
336
|
+
throw new Error("already compacted");
|
|
337
|
+
fromExtension = false;
|
|
338
|
+
return { result: createDeterministicCompaction(preparation) };
|
|
339
|
+
},
|
|
340
|
+
apply: async (result) => {
|
|
341
|
+
lastCompaction = result;
|
|
342
|
+
await this.applyResult(result, fromExtension);
|
|
343
|
+
},
|
|
344
|
+
verifyPostApplyEffect: reason === "overflow" ? () => false : undefined,
|
|
345
|
+
onTransition: ({ cycle, cause, detail }) => {
|
|
346
|
+
this.deps.emit({
|
|
347
|
+
type: "warning",
|
|
348
|
+
message: `auto-compaction cycle ${cycle}: ${cause}${detail ? ` (${detail})` : ""} — retrying from step 0 (${this.deps.describeSummarizer()})`,
|
|
349
|
+
});
|
|
350
|
+
},
|
|
351
|
+
signal,
|
|
352
|
+
});
|
|
353
|
+
if (outcome.kind === "skip") {
|
|
354
|
+
this.deps.emit({
|
|
355
|
+
type: "compaction_end",
|
|
356
|
+
reason,
|
|
357
|
+
result: undefined,
|
|
358
|
+
aborted: false,
|
|
359
|
+
willRetry: false,
|
|
360
|
+
skipReason: outcome.reason,
|
|
361
|
+
});
|
|
362
|
+
return hadQueuedMessages || this.deps.agent.hasQueuedMessages();
|
|
363
|
+
}
|
|
364
|
+
if (outcome.kind === "failed") {
|
|
365
|
+
if (outcome.reason === "aborted") {
|
|
366
|
+
this.deps.emit({ type: "compaction_end", reason, result: undefined, aborted: true, willRetry: false });
|
|
367
|
+
return hadQueuedMessages || this.deps.agent.hasQueuedMessages();
|
|
368
|
+
}
|
|
369
|
+
throw new Error(outcome.reason);
|
|
370
|
+
}
|
|
371
|
+
if (extensionCancelled || signal.aborted) {
|
|
372
|
+
this.deps.emit({ type: "compaction_end", reason, result: undefined, aborted: true, willRetry: false });
|
|
373
|
+
return hadQueuedMessages || this.deps.agent.hasQueuedMessages();
|
|
374
|
+
}
|
|
375
|
+
const result = outcome.kind === "success" ? outcome.result : lastCompaction;
|
|
376
|
+
if (!result)
|
|
377
|
+
throw new Error("Auto-compaction succeeded without a result");
|
|
378
|
+
this.deps.emit({ type: "compaction_end", reason, result, aborted: false, willRetry });
|
|
379
|
+
if (willRetry) {
|
|
380
|
+
const messages = this.deps.agent.state.messages;
|
|
381
|
+
const lastMessage = messages[messages.length - 1];
|
|
382
|
+
if (lastMessage?.role === "assistant" && lastMessage.stopReason === "error") {
|
|
383
|
+
this.deps.agent.state.messages = messages.slice(0, -1);
|
|
384
|
+
}
|
|
385
|
+
return true;
|
|
386
|
+
}
|
|
387
|
+
return hadQueuedMessages || this.deps.agent.hasQueuedMessages();
|
|
388
|
+
}
|
|
389
|
+
catch (error) {
|
|
390
|
+
const errorMessage = error instanceof Error ? error.message : "compaction failed";
|
|
391
|
+
this.deps.emit({
|
|
392
|
+
type: "compaction_end",
|
|
393
|
+
reason,
|
|
394
|
+
result: undefined,
|
|
395
|
+
aborted: false,
|
|
396
|
+
willRetry: false,
|
|
397
|
+
errorMessage: reason === "overflow"
|
|
398
|
+
? `Context overflow recovery failed: ${errorMessage}`
|
|
399
|
+
: `Auto-compaction failed: ${errorMessage}`,
|
|
400
|
+
});
|
|
401
|
+
return hadQueuedMessages || this.deps.agent.hasQueuedMessages();
|
|
402
|
+
}
|
|
403
|
+
finally {
|
|
404
|
+
this.autoAbortController = undefined;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
async compactWithRetry(run, signal, provider) {
|
|
408
|
+
return runCompactionWithRetry({
|
|
409
|
+
run,
|
|
410
|
+
signal,
|
|
411
|
+
provider,
|
|
412
|
+
getRetrySettings: () => this.deps.settingsManager.getRetrySettings(),
|
|
413
|
+
recordFailure: (record) => this.deps.getFailureCorpus().record(record),
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
findLastAssistantMessage() {
|
|
417
|
+
for (let index = this.deps.agent.state.messages.length - 1; index >= 0; index--) {
|
|
418
|
+
const message = this.deps.agent.state.messages[index];
|
|
419
|
+
if (message.role === "assistant")
|
|
420
|
+
return message;
|
|
421
|
+
}
|
|
422
|
+
return undefined;
|
|
423
|
+
}
|
|
424
|
+
async getExtensionCompaction(preparation, branchEntries, customInstructions, signal) {
|
|
425
|
+
const extensionRunner = this.deps.getExtensionRunner();
|
|
426
|
+
if (!extensionRunner.hasHandlers("session_before_compact"))
|
|
427
|
+
return { cancelled: false };
|
|
428
|
+
const extensionResult = (await extensionRunner.emit({
|
|
429
|
+
type: "session_before_compact",
|
|
430
|
+
preparation,
|
|
431
|
+
branchEntries,
|
|
432
|
+
customInstructions,
|
|
433
|
+
signal,
|
|
434
|
+
}));
|
|
435
|
+
return { cancelled: extensionResult?.cancel === true, result: extensionResult?.compaction };
|
|
436
|
+
}
|
|
437
|
+
async applyResult(result, fromExtension) {
|
|
438
|
+
this.deps.sessionManager.appendCompaction(result.summary, result.firstKeptEntryId, result.tokensBefore, result.details, fromExtension, result.usage);
|
|
439
|
+
this.deps.refreshAfterCompaction();
|
|
440
|
+
const savedEntry = this.deps.sessionManager
|
|
441
|
+
.getEntries()
|
|
442
|
+
.find((entry) => entry.type === "compaction" && entry.summary === result.summary);
|
|
443
|
+
if (savedEntry) {
|
|
444
|
+
await this.deps.getExtensionRunner().emit({
|
|
445
|
+
type: "session_compact",
|
|
446
|
+
compactionEntry: savedEntry,
|
|
447
|
+
fromExtension,
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
//# sourceMappingURL=compaction-controller.js.map
|