@caupulican/pi-adaptative 0.85.4 → 0.86.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -0
- package/dist/bun/cli.d.ts +1 -1
- package/dist/bun/cli.d.ts.map +1 -1
- package/dist/bun/cli.js +1 -0
- package/dist/bun/cli.js.map +1 -1
- package/dist/core/agent-paths.d.ts +3 -3
- package/dist/core/agent-paths.d.ts.map +1 -1
- package/dist/core/agent-paths.js +3 -3
- package/dist/core/agent-paths.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +1 -1
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session.d.ts +11 -5
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +14 -3
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +2 -2
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +2 -2
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
- package/dist/core/autonomy/bounded-completion.js +19 -8
- package/dist/core/autonomy/bounded-completion.js.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.d.ts +11 -5
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +34 -8
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/autonomy/subagent-prompt.d.ts +3 -3
- package/dist/core/autonomy/subagent-prompt.js +9 -9
- package/dist/core/autonomy/subagent-prompt.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +10 -8
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +23 -13
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/bash-execution-controller.d.ts +4 -0
- package/dist/core/bash-execution-controller.d.ts.map +1 -1
- package/dist/core/bash-execution-controller.js +11 -4
- package/dist/core/bash-execution-controller.js.map +1 -1
- package/dist/core/bash-executor.d.ts +2 -0
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +4 -3
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/billing-failover-controller.d.ts +2 -2
- package/dist/core/billing-failover-controller.d.ts.map +1 -1
- package/dist/core/billing-failover-controller.js +1 -1
- package/dist/core/billing-failover-controller.js.map +1 -1
- package/dist/core/capability-contract.d.ts +1 -1
- package/dist/core/capability-contract.d.ts.map +1 -1
- package/dist/core/capability-contract.js +0 -1
- package/dist/core/capability-contract.js.map +1 -1
- package/dist/core/compaction-controller.d.ts +8 -2
- package/dist/core/compaction-controller.d.ts.map +1 -1
- package/dist/core/compaction-controller.js +73 -3
- package/dist/core/compaction-controller.js.map +1 -1
- package/dist/core/compaction-support.d.ts +2 -2
- package/dist/core/compaction-support.d.ts.map +1 -1
- package/dist/core/compaction-support.js +9 -1
- package/dist/core/compaction-support.js.map +1 -1
- package/dist/core/context/artifact-retrieval.d.ts +1 -1
- package/dist/core/context/artifact-retrieval.d.ts.map +1 -1
- package/dist/core/context/artifact-retrieval.js +1 -1
- package/dist/core/context/artifact-retrieval.js.map +1 -1
- package/dist/core/context/context-artifacts.d.ts +6 -6
- package/dist/core/context/context-artifacts.d.ts.map +1 -1
- package/dist/core/context/context-artifacts.js +151 -63
- package/dist/core/context/context-artifacts.js.map +1 -1
- package/dist/core/context/context-composition.js +1 -1
- package/dist/core/context/context-composition.js.map +1 -1
- package/dist/core/context/context-store-retention.d.ts.map +1 -1
- package/dist/core/context/context-store-retention.js +5 -2
- package/dist/core/context/context-store-retention.js.map +1 -1
- package/dist/core/context/file-store-memory-provider.js +1 -1
- package/dist/core/context/file-store-memory-provider.js.map +1 -1
- package/dist/core/context/tool-output-packer.d.ts +1 -1
- package/dist/core/context/tool-output-packer.d.ts.map +1 -1
- package/dist/core/context/tool-output-packer.js +1 -1
- package/dist/core/context/tool-output-packer.js.map +1 -1
- package/dist/core/context-gc.d.ts.map +1 -1
- package/dist/core/context-gc.js +7 -5
- package/dist/core/context-gc.js.map +1 -1
- package/dist/core/context-pipeline.d.ts +2 -2
- package/dist/core/context-pipeline.d.ts.map +1 -1
- package/dist/core/context-pipeline.js +8 -4
- package/dist/core/context-pipeline.js.map +1 -1
- package/dist/core/cost/cost-summary.d.ts +1 -1
- package/dist/core/cost/cost-summary.d.ts.map +1 -1
- package/dist/core/cost/cost-summary.js +1 -1
- package/dist/core/cost/cost-summary.js.map +1 -1
- package/dist/core/cost/daily-usage.d.ts +1 -1
- package/dist/core/cost/daily-usage.d.ts.map +1 -1
- package/dist/core/cost/daily-usage.js +2 -2
- package/dist/core/cost/daily-usage.js.map +1 -1
- package/dist/core/cost/session-usage.d.ts +1 -1
- package/dist/core/cost/session-usage.d.ts.map +1 -1
- package/dist/core/cost/session-usage.js +1 -1
- package/dist/core/cost/session-usage.js.map +1 -1
- package/dist/core/default-tool-surface.d.ts +1 -0
- package/dist/core/default-tool-surface.d.ts.map +1 -1
- package/dist/core/default-tool-surface.js +3 -2
- package/dist/core/default-tool-surface.js.map +1 -1
- package/dist/core/delegation/worker-actions.js +1 -1
- package/dist/core/delegation/worker-actions.js.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts +27 -8
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js +191 -33
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-agent-control.d.ts +45 -6
- package/dist/core/delegation/worker-agent-control.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control.js +110 -13
- package/dist/core/delegation/worker-agent-control.js.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.d.ts +1 -1
- package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.js +180 -160
- package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
- package/dist/core/delegation/worker-authority-resolver.d.ts +23 -0
- package/dist/core/delegation/worker-authority-resolver.d.ts.map +1 -0
- package/dist/core/delegation/worker-authority-resolver.js +128 -0
- package/dist/core/delegation/worker-authority-resolver.js.map +1 -0
- package/dist/core/delegation/worker-conversation-store.d.ts +2 -1
- package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -1
- package/dist/core/delegation/worker-conversation-store.js +4 -3
- package/dist/core/delegation/worker-conversation-store.js.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts +7 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +260 -87
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-delegation-request.d.ts +25 -4
- package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-request.js +90 -1
- package/dist/core/delegation/worker-delegation-request.js.map +1 -1
- package/dist/core/delegation/worker-execution-policy.d.ts +2 -0
- package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
- package/dist/core/delegation/worker-execution-policy.js +22 -12
- package/dist/core/delegation/worker-execution-policy.js.map +1 -1
- package/dist/core/delegation/worker-lifecycle.d.ts +1 -0
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
- package/dist/core/delegation/worker-lifecycle.js +4 -2
- package/dist/core/delegation/worker-lifecycle.js.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.d.ts +0 -2
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.js +8 -35
- package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
- package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-recovery-coordinator.js +1 -0
- package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-runner.d.ts +6 -1
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +20 -6
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-tree-budget-coordinator.d.ts +47 -0
- package/dist/core/delegation/worker-tree-budget-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-tree-budget-coordinator.js +210 -0
- package/dist/core/delegation/worker-tree-budget-coordinator.js.map +1 -0
- package/dist/core/extensions/builtin.d.ts +2 -2
- package/dist/core/extensions/builtin.d.ts.map +1 -1
- package/dist/core/extensions/builtin.js +2 -2
- package/dist/core/extensions/builtin.js.map +1 -1
- package/dist/core/extensions/bundled-virtual-modules.d.ts +2 -0
- package/dist/core/extensions/bundled-virtual-modules.d.ts.map +1 -0
- package/dist/core/extensions/bundled-virtual-modules.js +129 -0
- package/dist/core/extensions/bundled-virtual-modules.js.map +1 -0
- package/dist/core/extensions/factory-runtime.d.ts +22 -0
- package/dist/core/extensions/factory-runtime.d.ts.map +1 -0
- package/dist/core/extensions/factory-runtime.js +334 -0
- package/dist/core/extensions/factory-runtime.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 +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/lifecycle.d.ts +13 -0
- package/dist/core/extensions/lifecycle.d.ts.map +1 -0
- package/dist/core/extensions/lifecycle.js +52 -0
- package/dist/core/extensions/lifecycle.js.map +1 -0
- package/dist/core/extensions/loader.d.ts +3 -24
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +21 -531
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/virtual-modules.d.ts +51 -0
- package/dist/core/extensions/virtual-modules.d.ts.map +1 -0
- package/dist/core/extensions/virtual-modules.js +59 -0
- package/dist/core/extensions/virtual-modules.js.map +1 -0
- package/dist/core/foreground-recovery-controller.d.ts +2 -1
- package/dist/core/foreground-recovery-controller.d.ts.map +1 -1
- package/dist/core/foreground-recovery-controller.js +3 -3
- package/dist/core/foreground-recovery-controller.js.map +1 -1
- package/dist/core/goal-loop-controller.js +1 -1
- package/dist/core/goal-loop-controller.js.map +1 -1
- package/dist/core/goals/compact-goal-context.d.ts +1 -1
- package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
- package/dist/core/goals/compact-goal-context.js +1 -1
- package/dist/core/goals/compact-goal-context.js.map +1 -1
- package/dist/core/goals/goal-auto-continue-controller.js +1 -1
- package/dist/core/goals/goal-auto-continue-controller.js.map +1 -1
- package/dist/core/goals/goal-session-controller.d.ts +1 -1
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-session-controller.js +1 -1
- package/dist/core/goals/goal-session-controller.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +1 -1
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/index.d.ts +3 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/memory/providers/file-store.d.ts.map +1 -1
- package/dist/core/memory/providers/file-store.js +1 -1
- package/dist/core/memory/providers/file-store.js.map +1 -1
- package/dist/core/memory/providers/user-memory-archive.js +1 -1
- package/dist/core/memory/providers/user-memory-archive.js.map +1 -1
- package/dist/core/model-registry.d.ts +2 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +4 -1
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +1 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-router-controller.js +1 -1
- package/dist/core/model-router-controller.js.map +1 -1
- package/dist/core/model-selection-controller.js +1 -1
- package/dist/core/model-selection-controller.js.map +1 -1
- package/dist/core/model-tool-protocol.d.ts +1 -1
- package/dist/core/model-tool-protocol.d.ts.map +1 -1
- package/dist/core/model-tool-protocol.js +1 -1
- package/dist/core/model-tool-protocol.js.map +1 -1
- package/dist/core/models/llamacpp-runtime.d.ts +7 -0
- package/dist/core/models/llamacpp-runtime.d.ts.map +1 -1
- package/dist/core/models/llamacpp-runtime.js +8 -3
- package/dist/core/models/llamacpp-runtime.js.map +1 -1
- package/dist/core/models/local-runtime.js +1 -1
- package/dist/core/models/local-runtime.js.map +1 -1
- package/dist/core/models/runtime-process.d.ts.map +1 -1
- package/dist/core/models/runtime-process.js +5 -18
- package/dist/core/models/runtime-process.js.map +1 -1
- package/dist/core/orchestration/bounded-string-array.d.ts +11 -0
- package/dist/core/orchestration/bounded-string-array.d.ts.map +1 -0
- package/dist/core/orchestration/bounded-string-array.js +17 -0
- package/dist/core/orchestration/bounded-string-array.js.map +1 -0
- package/dist/core/orchestration/capability-gateway.d.ts +16 -0
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
- package/dist/core/orchestration/capability-gateway.js +38 -0
- package/dist/core/orchestration/capability-gateway.js.map +1 -1
- package/dist/core/orchestration/contracts.d.ts +11 -3
- package/dist/core/orchestration/contracts.d.ts.map +1 -1
- package/dist/core/orchestration/contracts.js +0 -1
- package/dist/core/orchestration/contracts.js.map +1 -1
- package/dist/core/orchestration/delegation-ledger.d.ts +1 -0
- package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
- package/dist/core/orchestration/delegation-ledger.js +3 -0
- package/dist/core/orchestration/delegation-ledger.js.map +1 -1
- package/dist/core/orchestration/event-store.d.ts +12 -10
- package/dist/core/orchestration/event-store.d.ts.map +1 -1
- package/dist/core/orchestration/event-store.js +94 -104
- package/dist/core/orchestration/event-store.js.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts +2 -2
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.js +4 -1
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
- package/dist/core/orchestration/model-binding.d.ts +1 -1
- package/dist/core/orchestration/model-binding.d.ts.map +1 -1
- package/dist/core/orchestration/model-binding.js +1 -1
- package/dist/core/orchestration/model-binding.js.map +1 -1
- package/dist/core/orchestration/policy-compiler.d.ts.map +1 -1
- package/dist/core/orchestration/policy-compiler.js +8 -9
- package/dist/core/orchestration/policy-compiler.js.map +1 -1
- package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
- package/dist/core/orchestration/profile-registry.js +4 -10
- package/dist/core/orchestration/profile-registry.js.map +1 -1
- package/dist/core/orchestration/task-profile-writer.js +1 -1
- package/dist/core/orchestration/task-profile-writer.js.map +1 -1
- package/dist/core/orchestration/task-runtime.d.ts +1 -0
- package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
- package/dist/core/orchestration/task-runtime.js +58 -3
- package/dist/core/orchestration/task-runtime.js.map +1 -1
- package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
- package/dist/core/orchestration/worker-execution-contract.js +10 -17
- package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
- package/dist/core/process-matrix/runtime.d.ts +15 -1
- package/dist/core/process-matrix/runtime.d.ts.map +1 -1
- package/dist/core/process-matrix/runtime.js +55 -34
- package/dist/core/process-matrix/runtime.js.map +1 -1
- package/dist/core/reflection-controller.d.ts +4 -3
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +2 -2
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/research/model-fitness-controller.js +1 -1
- package/dist/core/research/model-fitness-controller.js.map +1 -1
- package/dist/core/research/research-lane-controller.d.ts +2 -2
- package/dist/core/research/research-lane-controller.d.ts.map +1 -1
- package/dist/core/research/research-lane-controller.js +1 -1
- package/dist/core/research/research-lane-controller.js.map +1 -1
- package/dist/core/resource-loader.d.ts +10 -19
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +8 -70
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/risk-classifier.js +3 -3
- package/dist/core/risk-classifier.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +4 -1
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +47 -18
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/scout-controller.d.ts +1 -1
- package/dist/core/scout-controller.d.ts.map +1 -1
- package/dist/core/scout-controller.js +1 -1
- package/dist/core/scout-controller.js.map +1 -1
- package/dist/core/sdk.d.ts +2 -2
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +3 -3
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/secrets/bitwarden-credential-storage.d.ts +51 -0
- package/dist/core/secrets/bitwarden-credential-storage.d.ts.map +1 -0
- package/dist/core/secrets/bitwarden-credential-storage.js +345 -0
- package/dist/core/secrets/bitwarden-credential-storage.js.map +1 -0
- package/dist/core/secrets/credential-exposure-guard.d.ts +8 -4
- package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -1
- package/dist/core/secrets/credential-exposure-guard.js +31 -29
- package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
- package/dist/core/secrets/credential-manager.d.ts +109 -0
- package/dist/core/secrets/credential-manager.d.ts.map +1 -0
- package/dist/core/secrets/credential-manager.js +384 -0
- package/dist/core/secrets/credential-manager.js.map +1 -0
- package/dist/core/secrets/credential-project.d.ts +4 -0
- package/dist/core/secrets/credential-project.d.ts.map +1 -0
- package/dist/core/secrets/credential-project.js +145 -0
- package/dist/core/secrets/credential-project.js.map +1 -0
- package/dist/core/secrets/secret-dotenv.d.ts +1 -1
- package/dist/core/secrets/secret-dotenv.js +1 -1
- package/dist/core/secrets/secret-dotenv.js.map +1 -1
- package/dist/core/security/context-threat-scanner.d.ts +14 -0
- package/dist/core/security/context-threat-scanner.d.ts.map +1 -0
- package/dist/core/security/context-threat-scanner.js +71 -0
- package/dist/core/security/context-threat-scanner.js.map +1 -0
- package/dist/core/session-supervision-runtime.d.ts +4 -1
- package/dist/core/session-supervision-runtime.d.ts.map +1 -1
- package/dist/core/session-supervision-runtime.js +49 -11
- package/dist/core/session-supervision-runtime.js.map +1 -1
- package/dist/core/settings-manager.d.ts +4 -2
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +10 -6
- 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 +1 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/system-prompt.js +1 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tool-capability-policy.js +2 -2
- package/dist/core/tool-capability-policy.js.map +1 -1
- package/dist/core/tool-recovery-logger.js +1 -1
- package/dist/core/tool-recovery-logger.js.map +1 -1
- package/dist/core/tools/artifact-retrieve.js +1 -1
- package/dist/core/tools/artifact-retrieve.js.map +1 -1
- package/dist/core/tools/bash.d.ts +2 -2
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +16 -4
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +29 -1
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +179 -28
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/extensionify-runtime.d.ts +44 -0
- package/dist/core/tools/extensionify-runtime.d.ts.map +1 -0
- package/dist/core/tools/extensionify-runtime.js +115 -0
- package/dist/core/tools/extensionify-runtime.js.map +1 -0
- package/dist/core/tools/extensionify.d.ts +9 -30
- package/dist/core/tools/extensionify.d.ts.map +1 -1
- package/dist/core/tools/extensionify.js +10 -140
- package/dist/core/tools/extensionify.js.map +1 -1
- package/dist/core/tools/find.d.ts +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +1 -1
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/git-filter.d.ts +1 -0
- package/dist/core/tools/git-filter.d.ts.map +1 -1
- package/dist/core/tools/git-filter.js +1 -1
- package/dist/core/tools/git-filter.js.map +1 -1
- package/dist/core/tools/index.d.ts +2 -4
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +7 -43
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +1 -1
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +1 -1
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +1 -1
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/profile-writer.js +3 -3
- package/dist/core/tools/profile-writer.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 +17 -12
- package/dist/core/tools/python.js.map +1 -1
- package/dist/core/tools/render-utils.js +1 -1
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/run-process.d.ts +2 -0
- package/dist/core/tools/run-process.d.ts.map +1 -1
- package/dist/core/tools/run-process.js +7 -3
- package/dist/core/tools/run-process.js.map +1 -1
- package/dist/core/tools/search-command-guard.d.ts +8 -0
- package/dist/core/tools/search-command-guard.d.ts.map +1 -1
- package/dist/core/tools/search-command-guard.js +54 -0
- package/dist/core/tools/search-command-guard.js.map +1 -1
- package/dist/core/tools/secret-store.d.ts +8 -18
- package/dist/core/tools/secret-store.d.ts.map +1 -1
- package/dist/core/tools/secret-store.js +83 -348
- package/dist/core/tools/secret-store.js.map +1 -1
- package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
- package/dist/core/tools/shell-contract-router.js +9 -4
- package/dist/core/tools/shell-contract-router.js.map +1 -1
- package/dist/core/tools/shell-session.d.ts.map +1 -1
- package/dist/core/tools/shell-session.js +6 -4
- package/dist/core/tools/shell-session.js.map +1 -1
- package/dist/core/tools/tool-definition-factory.d.ts +32 -0
- package/dist/core/tools/tool-definition-factory.d.ts.map +1 -0
- package/dist/core/tools/tool-definition-factory.js +55 -0
- package/dist/core/tools/tool-definition-factory.js.map +1 -0
- package/dist/core/util/atomic-file.d.ts.map +1 -1
- package/dist/core/util/atomic-file.js +79 -32
- package/dist/core/util/atomic-file.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +24 -18
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/auto-learn-controller.js +1 -1
- package/dist/modes/interactive/auto-learn-controller.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +35 -14
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +1 -1
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.js +1 -1
- package/dist/modes/interactive/interactive-event-controller.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +27 -4
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/secret-menu-controller.d.ts +21 -0
- package/dist/modes/interactive/secret-menu-controller.d.ts.map +1 -0
- package/dist/modes/interactive/secret-menu-controller.js +276 -0
- package/dist/modes/interactive/secret-menu-controller.js.map +1 -0
- package/dist/utils/child-process.js +1 -1
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/tools-manager.d.ts +2 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +43 -48
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/zip-extractor.d.ts +8 -0
- package/dist/utils/zip-extractor.d.ts.map +1 -0
- package/dist/utils/zip-extractor.js +275 -0
- package/dist/utils/zip-extractor.js.map +1 -0
- package/docs/harness-architecture.md +34 -22
- package/docs/index.md +1 -1
- package/docs/resources.md +1 -1
- package/docs/settings.md +39 -103
- package/docs/usage.md +7 -5
- package/docs/worker-profiles.md +9 -7
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +7 -5
- package/dist/core/secrets/secret-vault-format.d.ts +0 -112
- package/dist/core/secrets/secret-vault-format.d.ts.map +0 -1
- package/dist/core/secrets/secret-vault-format.js +0 -396
- package/dist/core/secrets/secret-vault-format.js.map +0 -1
- package/dist/core/secrets/secret-vault.d.ts +0 -72
- package/dist/core/secrets/secret-vault.d.ts.map +0 -1
- package/dist/core/secrets/secret-vault.js +0 -663
- package/dist/core/secrets/secret-vault.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,68 @@
|
|
|
1
|
+
## [0.86.1] - 2026-08-05
|
|
2
|
+
|
|
3
|
+
### Fixed
|
|
4
|
+
|
|
5
|
+
- Matched active project credentials across canonical, symlinked, and Windows short-path working directories, and aligned orchestration regression gates with explicit non-delegating leaf profiles and effective profile-free capability telemetry.
|
|
6
|
+
|
|
7
|
+
## [0.86.0] - 2026-08-05
|
|
8
|
+
|
|
9
|
+
### Breaking Changes
|
|
10
|
+
|
|
11
|
+
- Replaced the local `SecretVault`/dotenv-materialization API and model-driven credential mutation actions with a provider-neutral credential manager backed by Bitwarden; the model-facing `secret_store` now exposes only status, metadata listing, and project-authorized activation.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- Added automatic pinned `bw` provisioning, the private `/secrets` owner workflow, portable Git-project bindings, cross-machine Bitwarden sync, and in-memory credential injection for Bash, Python, and allowlisted direct processes without exposing `BW_SESSION` to model-controlled execution.
|
|
16
|
+
|
|
17
|
+
## [0.85.9] - 2026-08-05
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
- Added durable recursive worker-agent trees with inherited delegation, exact paginated peer transcripts, threaded messages, event-driven agent controls, platform-shell execution, and model-authored model/reasoning/tool/capability/path/budget selection.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- Changed orchestration profiles into optional presets: profile-free agents receive the maximum host-permitted core surface, direct project writes are enabled by default, roles are labels unless the host supplies a ceiling, root budgets are cumulative, and the global scheduler replaces framework depth, fan-out, and per-profile concurrency caps.
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
|
|
29
|
+
- Made recursive worker orchestration parent-aware: queued children now have stable identities, waiting parents yield scheduler capacity, terminal children deliver one durable idempotent parent handoff, peer controls stay tree-scoped, reply replay is atomic, explicit leaf grants remain non-delegating, and concurrent descendants share cumulative provider budgets.
|
|
30
|
+
- Counted durable agent attempts that ended before their first usage checkpoint when reconstructing a root tree's cumulative attempt budget after restart.
|
|
31
|
+
- Resolved omitted adaptive-agent reasoning from the selected model's supported default instead of assuming `medium` and rejecting non-reasoning models.
|
|
32
|
+
- Chunked wall-clock timers above the host timer limit and saturated durable lease timestamps at the maximum representable date so unrestricted safe-integer budgets cannot overflow into immediate timeouts or failed starts.
|
|
33
|
+
- Removed per-event idempotency marker files from the bounded orchestration event store and made its corruption cursor a non-atomic derived overwrite, reducing Windows filesystem and security-scanner churn while retaining exact cross-process deduplication and cursor recovery.
|
|
34
|
+
|
|
35
|
+
## [0.85.8] - 2026-08-05
|
|
36
|
+
|
|
37
|
+
### Changed
|
|
38
|
+
|
|
39
|
+
- Upgraded the pinned test toolchain to Vite 8.2 and Vitest 4.1, enabled the native Node module runner, and made Linux and Windows workflows verify and use the same source-resolution contract.
|
|
40
|
+
- Split extension loading, factory execution, virtual-module catalogs, threat scanning, extensionification, and tool-definition construction into explicit lifecycle owners, and replaced broad cross-package barrels with narrow owner imports.
|
|
41
|
+
|
|
42
|
+
### Fixed
|
|
43
|
+
|
|
44
|
+
- Serialized supervision start/stop transitions, cleaned partially started peers, awaited runtime-owned memory, GC, shell, and supervision shutdown before process-matrix and early CLI exits, and made Windows memory cleanup wait for worker termination before removing its state tree.
|
|
45
|
+
- Made suite and manual-session cleanup await idempotent session disposal before unregistering providers and deleting state, preventing background workers, extension runtimes, and Windows file handles from leaking across tests.
|
|
46
|
+
- Serialized same-target async atomic writes and advisory-lock admission with self-removing per-path queues, preventing Windows rename retry storms without bottlenecking unrelated files or tenants.
|
|
47
|
+
- Isolated draft extension validation from the live generation, bounded extension factory and disposal lifecycles, and fenced process-matrix storage and llama process ownership behind injected adapters.
|
|
48
|
+
- Removed the Vite transform graph from targeted source tests and narrowed heavyweight test fixtures, reducing cold focused-test startup from roughly 7–12 seconds to roughly 2–3 seconds.
|
|
49
|
+
|
|
50
|
+
## [0.85.7] - 2026-08-04
|
|
51
|
+
|
|
52
|
+
### Fixed
|
|
53
|
+
|
|
54
|
+
- Isolated external-resource discovery and reload-rollback regressions from unrelated bundled-extension imports so native Windows release validation retains deterministic time bounds.
|
|
55
|
+
|
|
56
|
+
## [0.85.6] - 2026-08-04
|
|
57
|
+
|
|
58
|
+
## [0.85.5] - 2026-08-04
|
|
59
|
+
|
|
60
|
+
### Fixed
|
|
61
|
+
|
|
62
|
+
- Treated final ripgrep and grep exit code 1 as successful zero-match results across Linux and Windows, preserved PowerShell grep IO/regex failures as exit code 2, kept routed external commands in the persistent Windows shell, and kept goal-continuation budgets independent from the core identical-tool-call runaway guard.
|
|
63
|
+
- Prevented later turns from re-entering an auto-compaction frontier that failed to restore headroom until materially new compactable history exists, while preserving overflow recovery.
|
|
64
|
+
- Serialized context-GC payload and artifact ownership updates across processes, replaced quadratic shared reference-array rewrites with bounded holder markers, and kept read-only GC projections from replacing the latest committed report.
|
|
65
|
+
|
|
1
66
|
## [0.85.4] - 2026-08-04
|
|
2
67
|
|
|
3
68
|
### Breaking Changes
|
package/dist/bun/cli.d.ts
CHANGED
package/dist/bun/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/bun/cli.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/bun/cli.ts"],"names":[],"mappings":";AACA,OAAO,+CAA+C,CAAC"}
|
package/dist/bun/cli.js
CHANGED
package/dist/bun/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/bun/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC;AACzB,OAAO,CAAC,WAAW,GAAG,CAAC,GAAG,EAAE,GAAE,CAAC,CAA+B,CAAC;AAE/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,iBAAiB,EAAE,CAAC;AAEpB,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAC;AACtC,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\nimport { APP_NAME } from \"../config.ts\";\n\nprocess.title = APP_NAME;\nprocess.emitWarning = (() => {}) as typeof process.emitWarning;\n\nimport { restoreSandboxEnv } from \"./restore-sandbox-env.ts\";\n\nrestoreSandboxEnv();\n\nawait import(\"./register-bedrock.ts\");\nawait import(\"../cli.ts\");\n"]}
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/bun/cli.ts"],"names":[],"mappings":";AACA,OAAO,+CAA+C,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,CAAC,KAAK,GAAG,QAAQ,CAAC;AACzB,OAAO,CAAC,WAAW,GAAG,CAAC,GAAG,EAAE,GAAE,CAAC,CAA+B,CAAC;AAE/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,iBAAiB,EAAE,CAAC;AAEpB,MAAM,MAAM,CAAC,uBAAuB,CAAC,CAAC;AACtC,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\nimport \"../core/extensions/bundled-virtual-modules.ts\";\nimport { APP_NAME } from \"../config.ts\";\n\nprocess.title = APP_NAME;\nprocess.emitWarning = (() => {}) as typeof process.emitWarning;\n\nimport { restoreSandboxEnv } from \"./restore-sandbox-env.ts\";\n\nrestoreSandboxEnv();\n\nawait import(\"./register-bedrock.ts\");\nawait import(\"../cli.ts\");\n"]}
|
|
@@ -15,11 +15,11 @@ export declare function stateDir(agentDir: string): string;
|
|
|
15
15
|
export declare function stateFile(agentDir: string, ...segments: string[]): string;
|
|
16
16
|
/** `<agentDir>/state/attachments` -- bounded, session-keyed clipboard image attachments. */
|
|
17
17
|
export declare function attachmentsDir(agentDir: string): string;
|
|
18
|
-
/**
|
|
18
|
+
/** Retired local-secret state root. Current credential storage is provider-backed and never writes here. */
|
|
19
19
|
export declare function secretsDir(agentDir: string): string;
|
|
20
|
-
/**
|
|
20
|
+
/** Retired local vault path retained only so model-facing file access stays denied. */
|
|
21
21
|
export declare function secretVaultFile(agentDir: string): string;
|
|
22
|
-
/**
|
|
22
|
+
/** Retired plaintext materialization root retained only so model-facing file access stays denied. */
|
|
23
23
|
export declare function managedSecretEnvDir(agentDir: string): string;
|
|
24
24
|
/** `<agentDir>/state/extensions/<namespace>` -- durable state owned by one extension. */
|
|
25
25
|
export declare function extensionStateDir(agentDir: string, namespace: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-paths.d.ts","sourceRoot":"","sources":["../../src/core/agent-paths.ts"],"names":[],"mappings":"AAwCA,OAAO,EACN,cAAc,EACd,yBAAyB,EACzB,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,EACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAGhE,wEAAwE;AACxE,eAAO,MAAM,qBAAqB,YACjC,WAAW,EACX,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,WAAW,EACX,SAAS,EACT,WAAW,EACX,kBAAkB,CACT,CAAC;AAEX,oFAAoF;AACpF,eAAO,MAAM,0BAA0B,YACtC,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,UAAU,EACV,OAAO,EACP,OAAO,EACP,KAAK,EACL,MAAM,EACN,UAAU,EACV,QAAQ,EACR,UAAU,EACV,KAAK,EACL,KAAK,EACL,WAAW,CACF,CAAC;AAIX,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE/D;AAED,4GAA4G;AAC5G,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAErD;AAED,2GAA2G;AAC3G,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,qCAAqC;AACrC,wBAAgB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAEzE;AAED,4FAA4F;AAC5F,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,
|
|
1
|
+
{"version":3,"file":"agent-paths.d.ts","sourceRoot":"","sources":["../../src/core/agent-paths.ts"],"names":[],"mappings":"AA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
CHANGED
|
@@ -95,15 +95,15 @@ export function stateFile(agentDir, ...segments) {
|
|
|
95
95
|
export function attachmentsDir(agentDir) {
|
|
96
96
|
return stateFile(agentDir, "attachments");
|
|
97
97
|
}
|
|
98
|
-
/**
|
|
98
|
+
/** Retired local-secret state root. Current credential storage is provider-backed and never writes here. */
|
|
99
99
|
export function secretsDir(agentDir) {
|
|
100
100
|
return stateFile(agentDir, "secrets");
|
|
101
101
|
}
|
|
102
|
-
/**
|
|
102
|
+
/** Retired local vault path retained only so model-facing file access stays denied. */
|
|
103
103
|
export function secretVaultFile(agentDir) {
|
|
104
104
|
return join(secretsDir(agentDir), "vault.json");
|
|
105
105
|
}
|
|
106
|
-
/**
|
|
106
|
+
/** Retired plaintext materialization root retained only so model-facing file access stays denied. */
|
|
107
107
|
export function managedSecretEnvDir(agentDir) {
|
|
108
108
|
return join(secretsDir(agentDir), "materialized");
|
|
109
109
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-paths.js","sourceRoot":"","sources":["../../src/core/agent-paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACN,cAAc,EACd,yBAAyB,EACzB,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,GACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAEpE,wEAAwE;AACxE,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACpC,WAAW;IACX,eAAe;IACf,aAAa;IACb,kBAAkB;IAClB,WAAW;IACX,SAAS;IACT,WAAW;I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;AACH,MAAM,UAAU,YAAY,CAAC,QAAgB;IAC5C,OAAO,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;AACpC,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,MAAM,CAAC,QAAgB;IACtC,OAAO,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AAC9B,CAAC;AAID,oGAAoG;AACpG,MAAM,UAAU,WAAW,CAAC,IAAuB,EAAE,QAAgB;IACpE,OAAO,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,oBAAoB,CAAC,QAAgB;IACpD,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,aAAa,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;GAKG;AACH,OAAO,EACN,WAAW,EACX,yBAAyB,EACzB,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,eAAe,GACf,CAAC;AAGF;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,wBAAwB,CAAC","sourcesContent":["/**\n * Typed path SSOT for everything machine-managed under `<agentDir>` (`~/.pi/agent/` by default,\n * `getAgentDir()` in `../config.ts`). Every writer that persists machine data (stores, caches, managed\n * runtimes/models, cross-process coordination) MUST resolve its path through one of the accessors\n * below instead of hand-rolling `join(agentDir, …)` — that ad-hoc pattern is exactly how root-level\n * stragglers like `trust.json` accumulated, and nothing stopped the next writer from doing it again.\n *\n * Canonical layout:\n * ```\n * <agentDir>/\n * auth.json settings.json models.json keybindings.json MEMORY.md USER.md SYSTEM.md … user CONFIG/MEMORY (root, kept)\n * okf-memory/ authored memory (root, kept)\n * skills/ extensions/ prompts/ themes/ profiles/ user RESOURCES (root, kept)\n * profiles/directories/<workspace-hash>/settings.json directory overlays\n * state/ durable machine state (model adaptation/fitness, tool performance,\n * learning observations, trust decisions, config backups, …) -- stateDir/stateFile\n * cache/ rebuildable, safe to delete (tool-path probes, jiti transform cache, uv) -- cacheDir/cacheFile\n * work/ transient/scratch, delegated to work-directory.ts (tenant/run/lease),\n * including context/sessions/<session-id>/{gc,artifacts} -- re-exported below\n * runtimes/<kind> models/<kind> -- runtimesDir/modelsDir\n * npm/ git/ sessions/ -- npmDir/gitDir/sessionsDir\n * state/orchestration/sessions/<session-key>/ -- one foreground-session-owned\n * control-plane bundle\n * worktrees/<repo-slug>/<laneKey> durable lane checkouts (core/worktree-sync) -- worktreesDir\n * ```\n *\n * Every accessor takes `agentDir` as an explicit, required first argument -- deliberately mirroring\n * `work-directory.ts`'s existing `getWorkRoot(agentDir)` convention rather than defaulting to\n * `getAgentDir()` internally. Several real callers (stores' `forAgentDir`, test harnesses with a temp\n * agentDir) build paths for a NON-default agentDir; a hidden default would silently resolve the wrong\n * root for those callers instead of failing loudly. Callers operating on the process-wide default pass\n * `getAgentDir()` explicitly at the call site.\n *\n * These accessors are pure path builders -- no directory creation, no I/O. Every existing writer\n * already creates its parent directory at write time (see `util/atomic-file.ts`'s\n * `mkdirSync(dirname(filePath), { recursive: true })`), so duplicating that here would be redundant\n * and would blur the \"pure function\" contract readers rely on.\n */\nimport { createHash } from \"node:crypto\";\nimport { join } from \"node:path\";\nimport {\n\tacquireWorkRun,\n\tassertPortablePathSegment,\n\tboundedWorkRetention,\n\tcreateWorkRunId,\n\tgetProcessWorkRun,\n\tgetWorkRoot,\n\tgetWorkRunDir,\n\tgetWorkTenantDir,\n\thasActiveWorkRunLease,\n\tpruneWorkTenant,\n} from \"../utils/work-directory.ts\";\nimport { getReloadCoordinationDir } from \"./reload-blockers.ts\";\nimport { requireBoundedTrimmedText } from \"./util/bounded-value.ts\";\n\n/** Root entries reserved for user-authored configuration and memory. */\nexport const AGENT_ROOT_FILE_NAMES = [\n\t\"auth.json\",\n\t\"settings.json\",\n\t\"models.json\",\n\t\"keybindings.json\",\n\t\"MEMORY.md\",\n\t\"USER.md\",\n\t\"SYSTEM.md\",\n\t\"APPEND_SYSTEM.md\",\n] as const;\n\n/** Root entries reserved for user resources and machine-managed storage classes. */\nexport const AGENT_ROOT_DIRECTORY_NAMES = [\n\t\"okf-memory\",\n\t\"skills\",\n\t\"extensions\",\n\t\"prompts\",\n\t\"themes\",\n\t\"profiles\",\n\t\"state\",\n\t\"cache\",\n\t\"bin\",\n\t\"work\",\n\t\"runtimes\",\n\t\"models\",\n\t\"sessions\",\n\t\"npm\",\n\t\"git\",\n\t\"worktrees\",\n] as const;\n\nconst AGENT_ROOT_ENTRY_NAMES = new Set<string>([...AGENT_ROOT_FILE_NAMES, ...AGENT_ROOT_DIRECTORY_NAMES]);\n\nexport function isCanonicalAgentRootEntry(name: string): boolean {\n\treturn AGENT_ROOT_ENTRY_NAMES.has(name);\n}\n\n/** `<agentDir>/<name>` -- a root-level user config/memory file (auth.json, settings.json, MEMORY.md, …). */\nexport function configFile(agentDir: string, name: string): string {\n\treturn join(agentDir, name);\n}\n\n/** `<agentDir>/okf-memory` -- user-authored durable OKF memory documents. */\nexport function okfMemoryDir(agentDir: string): string {\n\treturn join(agentDir, \"okf-memory\");\n}\n\n/** `<agentDir>/state` -- durable machine-managed state. Deleting it loses real history, not just cache. */\nexport function stateDir(agentDir: string): string {\n\treturn join(agentDir, \"state\");\n}\n\n/** `<agentDir>/state/<segments…>` */\nexport function stateFile(agentDir: string, ...segments: string[]): string {\n\treturn join(stateDir(agentDir), ...segments);\n}\n\n/** `<agentDir>/state/attachments` -- bounded, session-keyed clipboard image attachments. */\nexport function attachmentsDir(agentDir: string): string {\n\treturn stateFile(agentDir, \"attachments\");\n}\n\n/** `<agentDir>/state/secrets` -- encrypted credential vault and owner-approved materializations. */\nexport function secretsDir(agentDir: string): string {\n\treturn stateFile(agentDir, \"secrets\");\n}\n\n/** `<agentDir>/state/secrets/vault.json` -- encrypted, versioned generic credential vault. */\nexport function secretVaultFile(agentDir: string): string {\n\treturn join(secretsDir(agentDir), \"vault.json\");\n}\n\n/** `<agentDir>/state/secrets/materialized` -- private generated dotenv files, grouped by profile. */\nexport function managedSecretEnvDir(agentDir: string): string {\n\treturn join(secretsDir(agentDir), \"materialized\");\n}\n\n/** `<agentDir>/state/extensions/<namespace>` -- durable state owned by one extension. */\nexport function extensionStateDir(agentDir: string, namespace: string): string {\n\tassertPortablePathSegment(\"Extension namespace\", namespace);\n\treturn stateFile(agentDir, \"extensions\", namespace);\n}\n\n/** `<agentDir>/state/backups/config` -- explicit user-requested configuration snapshots. */\nexport function configBackupsDir(agentDir: string): string {\n\treturn stateFile(agentDir, \"backups\", \"config\");\n}\n\n/** `<agentDir>/cache` -- rebuildable; safe to delete (the next run just re-probes/recomputes). */\nexport function cacheDir(agentDir: string): string {\n\treturn join(agentDir, \"cache\");\n}\n\n/** `<agentDir>/cache/<segments…>` */\nexport function cacheFile(agentDir: string, ...segments: string[]): string {\n\treturn join(cacheDir(agentDir), ...segments);\n}\n\n/** `<agentDir>/cache/extensions/<namespace>` -- rebuildable cache owned by one extension. */\nexport function extensionCacheDir(agentDir: string, namespace: string): string {\n\tassertPortablePathSegment(\"Extension namespace\", namespace);\n\treturn cacheFile(agentDir, \"extensions\", namespace);\n}\n\n/** `<agentDir>/bin` -- managed executable helpers (fd, rg, jq, uv). */\nexport function binDir(agentDir: string): string {\n\treturn join(agentDir, \"bin\");\n}\n\n/** `<agentDir>/runtimes/<kind>` -- a managed runtime install (ollama, python, prism-llamacpp, needle, …). */\nexport function runtimesDir(kind: string, agentDir: string): string {\n\treturn join(agentDir, \"runtimes\", kind);\n}\n\n/** `<agentDir>/models/<kind>` -- downloaded model weights, grouped by provider/runtime. */\nexport function modelsDir(kind: string, agentDir: string): string {\n\treturn join(agentDir, \"models\", kind);\n}\n\n/** `<agentDir>/sessions` -- session transcript storage (large, established; not a \"loose file\"). */\nexport function sessionsDir(agentDir: string): string {\n\treturn join(agentDir, \"sessions\");\n}\n\nfunction orchestrationSessionKey(parentSessionId: string): string {\n\tconst normalized = requireBoundedTrimmedText(parentSessionId, 512, \"Parent session id\");\n\tconst readable =\n\t\tencodeURIComponent(normalized)\n\t\t\t.replaceAll(\"%\", \"_\")\n\t\t\t// encodeURIComponent deliberately leaves `*` unescaped, but Windows forbids it in paths.\n\t\t\t// Restrict the readable prefix to a portable ASCII subset; the digest retains exact identity.\n\t\t\t.replaceAll(/[^a-zA-Z0-9._~-]/g, \"_\")\n\t\t\t.slice(0, 80) || \"session\";\n\tconst digest = createHash(\"sha256\").update(normalized).digest(\"hex\").slice(0, 16);\n\treturn `${readable}-${digest}`;\n}\n\n/**\n * `<agentDir>/state/orchestration/sessions/<session-key>` -- the one durable control-plane\n * bundle owned by a foreground session. Event state, worker mailboxes, mutation journals, and\n * worker transcripts must stay beneath this boundary so explicit session deletion can remove\n * exactly its companion artifacts without scanning global state.\n */\nexport function orchestrationSessionsDir(agentDir: string): string {\n\treturn stateFile(agentDir, \"orchestration\", \"sessions\");\n}\n\n/**\n * `<agentDir>/state/orchestration/sessions/<session-key>` -- the one durable control-plane\n * bundle owned by a foreground session.\n */\nexport function orchestrationSessionDir(agentDir: string, parentSessionId: string): string {\n\treturn join(orchestrationSessionsDir(agentDir), orchestrationSessionKey(parentSessionId));\n}\n\n/** `<orchestrationSessionDir>/events` -- append-only event tail, snapshot, cursor, and idempotency state. */\nexport function orchestrationEventStoreDir(agentDir: string, parentSessionId: string): string {\n\treturn join(orchestrationSessionDir(agentDir, parentSessionId), \"events\");\n}\n\n/**\n * `<orchestrationSessionDir>/worker-conversations` -- durable Pi worker transcripts owned by one\n * foreground session. Worker conversations remain in SessionManager's established JSONL format,\n * but are intentionally outside the foreground session picker namespace.\n */\nexport function workerConversationSessionsDir(agentDir: string, parentSessionId: string): string {\n\treturn join(orchestrationSessionDir(agentDir, parentSessionId), \"worker-conversations\");\n}\n\n/**\n * `<orchestrationSessionDir>/worker-mailboxes/<scope-digest>.json` -- durable bounded control\n * messages for one logical worker. Identity stays hashed so neither agent ids nor project paths\n * become path segments.\n */\nexport function workerAgentMailboxFile(agentDir: string, parentSessionId: string, scopeDigest: string): string {\n\tif (!/^[a-f0-9]{32,64}$/i.test(scopeDigest)) {\n\t\tthrow new TypeError(\"Worker agent mailbox scope digest must be a hexadecimal SHA-256 prefix.\");\n\t}\n\treturn join(\n\t\torchestrationSessionDir(agentDir, parentSessionId),\n\t\t\"worker-mailboxes\",\n\t\t`${scopeDigest.toLowerCase()}.json`,\n\t);\n}\n\n/**\n * `<orchestrationSessionDir>/worker-actions/<scope-digest>.json` -- durable, bounded mutation\n * intents and receipts for one fenced worker attempt. The opaque digest intentionally keeps task\n * identifiers out of filesystem path segments and works on Windows and WSL.\n */\nexport function workerActionJournalFile(agentDir: string, parentSessionId: string, scopeDigest: string): string {\n\tif (!/^[a-f0-9]{32,64}$/i.test(scopeDigest)) {\n\t\tthrow new TypeError(\"Worker action journal scope digest must be a hexadecimal SHA-256 prefix.\");\n\t}\n\treturn join(\n\t\torchestrationSessionDir(agentDir, parentSessionId),\n\t\t\"worker-actions\",\n\t\t`${scopeDigest.toLowerCase()}.json`,\n\t);\n}\n\n/** `<agentDir>/npm` -- managed npm package installs. */\nexport function npmDir(agentDir: string): string {\n\treturn join(agentDir, \"npm\");\n}\n\n/**\n * `<agentDir>/worktrees` -- lane worktree checkouts for the worktree-sync subsystem\n * (`core/worktree-sync/`), grouped as `worktrees/<repo-slug>/<laneKey>`. These hold REAL\n * uncommitted agent work, so they are durable like `state/` -- never under transient `work/`,\n * whose retention would silently eat in-progress code.\n */\nexport function worktreesDir(agentDir: string): string {\n\treturn join(agentDir, \"worktrees\");\n}\n\n/** `<agentDir>/git` -- managed git-sourced package installs. */\nexport function gitDir(agentDir: string): string {\n\treturn join(agentDir, \"git\");\n}\n\nexport type AgentResourceKind = \"skills\" | \"prompts\" | \"themes\" | \"extensions\" | \"profiles\";\n\n/** `<agentDir>/<kind>` -- a user-managed resource directory. Root, kept: moving it breaks users. */\nexport function resourceDir(kind: AgentResourceKind, agentDir: string): string {\n\treturn join(agentDir, kind);\n}\n\n/** `<agentDir>/profiles/directories` -- durable per-directory resource-profile overlays. */\nexport function directoryProfilesDir(agentDir: string): string {\n\treturn join(resourceDir(\"profiles\", agentDir), \"directories\");\n}\n\n/**\n * `work/` is a mature transient/scratch root with its own tenant/run/lease/retention machinery\n * (`utils/work-directory.ts`). The SSOT delegates to it wholesale instead of reimplementing -- these\n * are straight re-exports so every category (state/cache/work/runtimes/models/…) is reachable from one\n * module without duplicating `work-directory.ts`'s logic.\n */\nexport {\n\tgetWorkRoot,\n\tassertPortablePathSegment,\n\tboundedWorkRetention,\n\tgetWorkTenantDir,\n\tgetWorkRunDir,\n\tgetProcessWorkRun,\n\thasActiveWorkRunLease,\n\tacquireWorkRun,\n\tcreateWorkRunId,\n\tpruneWorkTenant,\n};\nexport type { AcquireWorkRunOptions, WorkRetentionOptions, WorkRunLease } from \"../utils/work-directory.ts\";\n\n/**\n * `work/reload-coordination` -- cross-process reload/live-op coordination state. Already correctly\n * work-scoped (defined in `reload-blockers.ts`, its natural home given the surrounding reload-gate\n * logic there); re-exported here under the taxonomy's canonical name for SSOT discoverability.\n */\nexport const reloadCoordinationDir = getReloadCoordinationDir;\n"]}
|
|
1
|
+
{"version":3,"file":"agent-paths.js","sourceRoot":"","sources":["../../src/core/agent-paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACN,cAAc,EACd,yBAAyB,EACzB,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,qBAAqB,EACrB,eAAe,GACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,yBAAy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E,OAAO,CACnC,CAAC;AACH,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,MAAM,CAAC,QAAgB;IACtC,OAAO,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,QAAgB;IAC5C,OAAO,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;AACpC,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,MAAM,CAAC,QAAgB;IACtC,OAAO,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AAC9B,CAAC;AAID,oGAAoG;AACpG,MAAM,UAAU,WAAW,CAAC,IAAuB,EAAE,QAAgB;IACpE,OAAO,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,oBAAoB,CAAC,QAAgB;IACpD,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,aAAa,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;GAKG;AACH,OAAO,EACN,WAAW,EACX,yBAAyB,EACzB,oBAAoB,EACpB,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,eAAe,GACf,CAAC;AAGF;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,wBAAwB,CAAC","sourcesContent":["/**\n * Typed path SSOT for everything machine-managed under `<agentDir>` (`~/.pi/agent/` by default,\n * `getAgentDir()` in `../config.ts`). Every writer that persists machine data (stores, caches, managed\n * runtimes/models, cross-process coordination) MUST resolve its path through one of the accessors\n * below instead of hand-rolling `join(agentDir, …)` — that ad-hoc pattern is exactly how root-level\n * stragglers like `trust.json` accumulated, and nothing stopped the next writer from doing it again.\n *\n * Canonical layout:\n * ```\n * <agentDir>/\n * auth.json settings.json models.json keybindings.json MEMORY.md USER.md SYSTEM.md … user CONFIG/MEMORY (root, kept)\n * okf-memory/ authored memory (root, kept)\n * skills/ extensions/ prompts/ themes/ profiles/ user RESOURCES (root, kept)\n * profiles/directories/<workspace-hash>/settings.json directory overlays\n * state/ durable machine state (model adaptation/fitness, tool performance,\n * learning observations, trust decisions, config backups, …) -- stateDir/stateFile\n * cache/ rebuildable, safe to delete (tool-path probes, jiti transform cache, uv) -- cacheDir/cacheFile\n * work/ transient/scratch, delegated to work-directory.ts (tenant/run/lease),\n * including context/sessions/<session-id>/{gc,artifacts} -- re-exported below\n * runtimes/<kind> models/<kind> -- runtimesDir/modelsDir\n * npm/ git/ sessions/ -- npmDir/gitDir/sessionsDir\n * state/orchestration/sessions/<session-key>/ -- one foreground-session-owned\n * control-plane bundle\n * worktrees/<repo-slug>/<laneKey> durable lane checkouts (core/worktree-sync) -- worktreesDir\n * ```\n *\n * Every accessor takes `agentDir` as an explicit, required first argument -- deliberately mirroring\n * `work-directory.ts`'s existing `getWorkRoot(agentDir)` convention rather than defaulting to\n * `getAgentDir()` internally. Several real callers (stores' `forAgentDir`, test harnesses with a temp\n * agentDir) build paths for a NON-default agentDir; a hidden default would silently resolve the wrong\n * root for those callers instead of failing loudly. Callers operating on the process-wide default pass\n * `getAgentDir()` explicitly at the call site.\n *\n * These accessors are pure path builders -- no directory creation, no I/O. Every existing writer\n * already creates its parent directory at write time (see `util/atomic-file.ts`'s\n * `mkdirSync(dirname(filePath), { recursive: true })`), so duplicating that here would be redundant\n * and would blur the \"pure function\" contract readers rely on.\n */\nimport { createHash } from \"node:crypto\";\nimport { join } from \"node:path\";\nimport {\n\tacquireWorkRun,\n\tassertPortablePathSegment,\n\tboundedWorkRetention,\n\tcreateWorkRunId,\n\tgetProcessWorkRun,\n\tgetWorkRoot,\n\tgetWorkRunDir,\n\tgetWorkTenantDir,\n\thasActiveWorkRunLease,\n\tpruneWorkTenant,\n} from \"../utils/work-directory.ts\";\nimport { getReloadCoordinationDir } from \"./reload-blockers.ts\";\nimport { requireBoundedTrimmedText } from \"./util/bounded-value.ts\";\n\n/** Root entries reserved for user-authored configuration and memory. */\nexport const AGENT_ROOT_FILE_NAMES = [\n\t\"auth.json\",\n\t\"settings.json\",\n\t\"models.json\",\n\t\"keybindings.json\",\n\t\"MEMORY.md\",\n\t\"USER.md\",\n\t\"SYSTEM.md\",\n\t\"APPEND_SYSTEM.md\",\n] as const;\n\n/** Root entries reserved for user resources and machine-managed storage classes. */\nexport const AGENT_ROOT_DIRECTORY_NAMES = [\n\t\"okf-memory\",\n\t\"skills\",\n\t\"extensions\",\n\t\"prompts\",\n\t\"themes\",\n\t\"profiles\",\n\t\"state\",\n\t\"cache\",\n\t\"bin\",\n\t\"work\",\n\t\"runtimes\",\n\t\"models\",\n\t\"sessions\",\n\t\"npm\",\n\t\"git\",\n\t\"worktrees\",\n] as const;\n\nconst AGENT_ROOT_ENTRY_NAMES = new Set<string>([...AGENT_ROOT_FILE_NAMES, ...AGENT_ROOT_DIRECTORY_NAMES]);\n\nexport function isCanonicalAgentRootEntry(name: string): boolean {\n\treturn AGENT_ROOT_ENTRY_NAMES.has(name);\n}\n\n/** `<agentDir>/<name>` -- a root-level user config/memory file (auth.json, settings.json, MEMORY.md, …). */\nexport function configFile(agentDir: string, name: string): string {\n\treturn join(agentDir, name);\n}\n\n/** `<agentDir>/okf-memory` -- user-authored durable OKF memory documents. */\nexport function okfMemoryDir(agentDir: string): string {\n\treturn join(agentDir, \"okf-memory\");\n}\n\n/** `<agentDir>/state` -- durable machine-managed state. Deleting it loses real history, not just cache. */\nexport function stateDir(agentDir: string): string {\n\treturn join(agentDir, \"state\");\n}\n\n/** `<agentDir>/state/<segments…>` */\nexport function stateFile(agentDir: string, ...segments: string[]): string {\n\treturn join(stateDir(agentDir), ...segments);\n}\n\n/** `<agentDir>/state/attachments` -- bounded, session-keyed clipboard image attachments. */\nexport function attachmentsDir(agentDir: string): string {\n\treturn stateFile(agentDir, \"attachments\");\n}\n\n/** Retired local-secret state root. Current credential storage is provider-backed and never writes here. */\nexport function secretsDir(agentDir: string): string {\n\treturn stateFile(agentDir, \"secrets\");\n}\n\n/** Retired local vault path retained only so model-facing file access stays denied. */\nexport function secretVaultFile(agentDir: string): string {\n\treturn join(secretsDir(agentDir), \"vault.json\");\n}\n\n/** Retired plaintext materialization root retained only so model-facing file access stays denied. */\nexport function managedSecretEnvDir(agentDir: string): string {\n\treturn join(secretsDir(agentDir), \"materialized\");\n}\n\n/** `<agentDir>/state/extensions/<namespace>` -- durable state owned by one extension. */\nexport function extensionStateDir(agentDir: string, namespace: string): string {\n\tassertPortablePathSegment(\"Extension namespace\", namespace);\n\treturn stateFile(agentDir, \"extensions\", namespace);\n}\n\n/** `<agentDir>/state/backups/config` -- explicit user-requested configuration snapshots. */\nexport function configBackupsDir(agentDir: string): string {\n\treturn stateFile(agentDir, \"backups\", \"config\");\n}\n\n/** `<agentDir>/cache` -- rebuildable; safe to delete (the next run just re-probes/recomputes). */\nexport function cacheDir(agentDir: string): string {\n\treturn join(agentDir, \"cache\");\n}\n\n/** `<agentDir>/cache/<segments…>` */\nexport function cacheFile(agentDir: string, ...segments: string[]): string {\n\treturn join(cacheDir(agentDir), ...segments);\n}\n\n/** `<agentDir>/cache/extensions/<namespace>` -- rebuildable cache owned by one extension. */\nexport function extensionCacheDir(agentDir: string, namespace: string): string {\n\tassertPortablePathSegment(\"Extension namespace\", namespace);\n\treturn cacheFile(agentDir, \"extensions\", namespace);\n}\n\n/** `<agentDir>/bin` -- managed executable helpers (fd, rg, jq, uv). */\nexport function binDir(agentDir: string): string {\n\treturn join(agentDir, \"bin\");\n}\n\n/** `<agentDir>/runtimes/<kind>` -- a managed runtime install (ollama, python, prism-llamacpp, needle, …). */\nexport function runtimesDir(kind: string, agentDir: string): string {\n\treturn join(agentDir, \"runtimes\", kind);\n}\n\n/** `<agentDir>/models/<kind>` -- downloaded model weights, grouped by provider/runtime. */\nexport function modelsDir(kind: string, agentDir: string): string {\n\treturn join(agentDir, \"models\", kind);\n}\n\n/** `<agentDir>/sessions` -- session transcript storage (large, established; not a \"loose file\"). */\nexport function sessionsDir(agentDir: string): string {\n\treturn join(agentDir, \"sessions\");\n}\n\nfunction orchestrationSessionKey(parentSessionId: string): string {\n\tconst normalized = requireBoundedTrimmedText(parentSessionId, 512, \"Parent session id\");\n\tconst readable =\n\t\tencodeURIComponent(normalized)\n\t\t\t.replaceAll(\"%\", \"_\")\n\t\t\t// encodeURIComponent deliberately leaves `*` unescaped, but Windows forbids it in paths.\n\t\t\t// Restrict the readable prefix to a portable ASCII subset; the digest retains exact identity.\n\t\t\t.replaceAll(/[^a-zA-Z0-9._~-]/g, \"_\")\n\t\t\t.slice(0, 80) || \"session\";\n\tconst digest = createHash(\"sha256\").update(normalized).digest(\"hex\").slice(0, 16);\n\treturn `${readable}-${digest}`;\n}\n\n/**\n * `<agentDir>/state/orchestration/sessions/<session-key>` -- the one durable control-plane\n * bundle owned by a foreground session. Event state, worker mailboxes, mutation journals, and\n * worker transcripts must stay beneath this boundary so explicit session deletion can remove\n * exactly its companion artifacts without scanning global state.\n */\nexport function orchestrationSessionsDir(agentDir: string): string {\n\treturn stateFile(agentDir, \"orchestration\", \"sessions\");\n}\n\n/**\n * `<agentDir>/state/orchestration/sessions/<session-key>` -- the one durable control-plane\n * bundle owned by a foreground session.\n */\nexport function orchestrationSessionDir(agentDir: string, parentSessionId: string): string {\n\treturn join(orchestrationSessionsDir(agentDir), orchestrationSessionKey(parentSessionId));\n}\n\n/** `<orchestrationSessionDir>/events` -- append-only event tail, snapshot, cursor, and idempotency state. */\nexport function orchestrationEventStoreDir(agentDir: string, parentSessionId: string): string {\n\treturn join(orchestrationSessionDir(agentDir, parentSessionId), \"events\");\n}\n\n/**\n * `<orchestrationSessionDir>/worker-conversations` -- durable Pi worker transcripts owned by one\n * foreground session. Worker conversations remain in SessionManager's established JSONL format,\n * but are intentionally outside the foreground session picker namespace.\n */\nexport function workerConversationSessionsDir(agentDir: string, parentSessionId: string): string {\n\treturn join(orchestrationSessionDir(agentDir, parentSessionId), \"worker-conversations\");\n}\n\n/**\n * `<orchestrationSessionDir>/worker-mailboxes/<scope-digest>.json` -- durable bounded control\n * messages for one logical worker. Identity stays hashed so neither agent ids nor project paths\n * become path segments.\n */\nexport function workerAgentMailboxFile(agentDir: string, parentSessionId: string, scopeDigest: string): string {\n\tif (!/^[a-f0-9]{32,64}$/i.test(scopeDigest)) {\n\t\tthrow new TypeError(\"Worker agent mailbox scope digest must be a hexadecimal SHA-256 prefix.\");\n\t}\n\treturn join(\n\t\torchestrationSessionDir(agentDir, parentSessionId),\n\t\t\"worker-mailboxes\",\n\t\t`${scopeDigest.toLowerCase()}.json`,\n\t);\n}\n\n/**\n * `<orchestrationSessionDir>/worker-actions/<scope-digest>.json` -- durable, bounded mutation\n * intents and receipts for one fenced worker attempt. The opaque digest intentionally keeps task\n * identifiers out of filesystem path segments and works on Windows and WSL.\n */\nexport function workerActionJournalFile(agentDir: string, parentSessionId: string, scopeDigest: string): string {\n\tif (!/^[a-f0-9]{32,64}$/i.test(scopeDigest)) {\n\t\tthrow new TypeError(\"Worker action journal scope digest must be a hexadecimal SHA-256 prefix.\");\n\t}\n\treturn join(\n\t\torchestrationSessionDir(agentDir, parentSessionId),\n\t\t\"worker-actions\",\n\t\t`${scopeDigest.toLowerCase()}.json`,\n\t);\n}\n\n/** `<agentDir>/npm` -- managed npm package installs. */\nexport function npmDir(agentDir: string): string {\n\treturn join(agentDir, \"npm\");\n}\n\n/**\n * `<agentDir>/worktrees` -- lane worktree checkouts for the worktree-sync subsystem\n * (`core/worktree-sync/`), grouped as `worktrees/<repo-slug>/<laneKey>`. These hold REAL\n * uncommitted agent work, so they are durable like `state/` -- never under transient `work/`,\n * whose retention would silently eat in-progress code.\n */\nexport function worktreesDir(agentDir: string): string {\n\treturn join(agentDir, \"worktrees\");\n}\n\n/** `<agentDir>/git` -- managed git-sourced package installs. */\nexport function gitDir(agentDir: string): string {\n\treturn join(agentDir, \"git\");\n}\n\nexport type AgentResourceKind = \"skills\" | \"prompts\" | \"themes\" | \"extensions\" | \"profiles\";\n\n/** `<agentDir>/<kind>` -- a user-managed resource directory. Root, kept: moving it breaks users. */\nexport function resourceDir(kind: AgentResourceKind, agentDir: string): string {\n\treturn join(agentDir, kind);\n}\n\n/** `<agentDir>/profiles/directories` -- durable per-directory resource-profile overlays. */\nexport function directoryProfilesDir(agentDir: string): string {\n\treturn join(resourceDir(\"profiles\", agentDir), \"directories\");\n}\n\n/**\n * `work/` is a mature transient/scratch root with its own tenant/run/lease/retention machinery\n * (`utils/work-directory.ts`). The SSOT delegates to it wholesale instead of reimplementing -- these\n * are straight re-exports so every category (state/cache/work/runtimes/models/…) is reachable from one\n * module without duplicating `work-directory.ts`'s logic.\n */\nexport {\n\tgetWorkRoot,\n\tassertPortablePathSegment,\n\tboundedWorkRetention,\n\tgetWorkTenantDir,\n\tgetWorkRunDir,\n\tgetProcessWorkRun,\n\thasActiveWorkRunLease,\n\tacquireWorkRun,\n\tcreateWorkRunId,\n\tpruneWorkTenant,\n};\nexport type { AcquireWorkRunOptions, WorkRetentionOptions, WorkRunLease } from \"../utils/work-directory.ts\";\n\n/**\n * `work/reload-coordination` -- cross-process reload/live-op coordination state. Already correctly\n * work-scoped (defined in `reload-blockers.ts`, its natural home given the surrounding reload-gate\n * logic there); re-exported here under the taxonomy's canonical name for SSOT discoverability.\n */\nexport const reloadCoordinationDir = getReloadCoordinationDir;\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SessionManager } from "@caupulican/pi-agent-core/
|
|
1
|
+
import { SessionManager } from "@caupulican/pi-agent-core/session";
|
|
2
2
|
import type { AgentSession } from "./agent-session.ts";
|
|
3
3
|
import type { AgentSessionRuntimeDiagnostic, AgentSessionServices } from "./agent-session-services.ts";
|
|
4
4
|
import type { ReplacedSessionContext, SessionStartEvent } from "./extensions/index.ts";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-runtime.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"agent-session-runtime.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-runtime.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAEnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,6BAA6B,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACvG,OAAO,KAAK,EAAE,sBAAsB,EAAwB,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE7G,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAGzD;;;;;GAKG;AACH,MAAM,WAAW,+BAAgC,SAAQ,wBAAwB;IAChF,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,WAAW,EAAE,6BAA6B,EAAE,CAAC;CAC7C;AAgBD,oFAAoF;AACpF,MAAM,WAAW,2BAA2B;IAC3C,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC7B;AAED,6EAA6E;AAC7E,MAAM,WAAW,yBAAyB;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+FAA+F;IAC/F,2BAA2B,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC9E,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,sBAAsB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7D;AAUD;;;;;;GAMG;AACH,MAAM,MAAM,gCAAgC,GAAG,CAAC,OAAO,EAAE;IACxD,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,cAA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1,6 +1,6 @@
|
|
|
1
1
|
import { copyFileSync, existsSync, constants as fsConstants, mkdirSync, unlinkSync } from "node:fs";
|
|
2
2
|
import { basename, join, resolve } from "node:path";
|
|
3
|
-
import { SessionManager } from "@caupulican/pi-agent-core/
|
|
3
|
+
import { SessionManager } from "@caupulican/pi-agent-core/session";
|
|
4
4
|
import { resolvePath } from "../utils/paths.js";
|
|
5
5
|
import { emitSessionShutdownEvent } from "./extensions/runner.js";
|
|
6
6
|
import { assertSessionCwdExists } from "./session-cwd.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-runtime.js","sourceRoot":"","sources":["../../src/core/agent-session-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,IAAI,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AA+D1D;;GAEG;AACH,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IAGxD,YAAY,QAAgB;QAC3B,KAAK,CAAC,mBAAmB,QAAQ,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;QAC7C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;CACD;AAED,gGAAgG;AAChG,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IAMxD,YACC,KAAgC,EAChC,eAAwB,EACxB,SAAkB,EAClB,aAAuB;QAEvB,MAAM,iBAAiB,GAAG,eAAe,YAAY,KAAK,CAAC,CAAC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AAC,CAAC,CAAC;YACzC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;gBAAE,MAAM,IAAI,cAAc,CAAC,MAAM,EAAE,kCAAkC,CAAC,CAAC;YAC5F,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACvB,CAAC,CAAC,EAAE,CAAC;QACL,IAAI,CAAC,gBAAgB,GAAG,QAAQ,CAAC;QACjC,IAAI,CAAC;YACJ,MAAM,QAAQ,CAAC;QAChB,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;QACnC,CAAC;IACF,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC9C,aAA+C,EAC/C,OAKC;IAED,sBAAsB,CAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC;IAC5C,OAAO,IAAI,mBAAmB,CAC7B,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,QAAQ,EACf,aAAa,EACb,MAAM,CAAC,WAAW,EAClB,MAAM,CAAC,oBAAoB,CAC3B,CAAC;AACH,CAAC;AAED,OAAO,EAKN,8BAA8B,EAC9B,0BAA0B,GAC1B,MAAM,6BAA6B,CAAC","sourcesContent":["import { copyFileSync, existsSync, constants as fsConstants, mkdirSync, unlinkSync } from \"node:fs\";\nimport { basename, join, resolve } from \"node:path\";\nimport { SessionManager } from \"@caupulican/pi-agent-core/node\";\nimport { resolvePath } from \"../utils/paths.ts\";\nimport type { AgentSession } from \"./agent-session.ts\";\nimport type { AgentSessionRuntimeDiagnostic, AgentSessionServices } from \"./agent-session-services.ts\";\nimport type { ReplacedSessionContext, SessionShutdownEvent, SessionStartEvent } from \"./extensions/index.ts\";\nimport { emitSessionShutdownEvent } from \"./extensions/runner.ts\";\nimport type { CreateAgentSessionResult } from \"./sdk.ts\";\nimport { assertSessionCwdExists } from \"./session-cwd.ts\";\n\n/**\n * Result returned by runtime creation.\n *\n * The caller gets the created session, its cwd-bound services, and all\n * diagnostics collected during setup.\n */\nexport interface CreateAgentSessionRuntimeResult extends CreateAgentSessionResult {\n\tservices: AgentSessionServices;\n\tdiagnostics: AgentSessionRuntimeDiagnostic[];\n}\n\ninterface AgentSessionRuntimeState {\n\tsession: AgentSession;\n\tservices: AgentSessionServices;\n\tdiagnostics: AgentSessionRuntimeDiagnostic[];\n\tmodelFallbackMessage?: string;\n}\n\ninterface RuntimeShutdownProgress {\n\tshutdownEventEmitted: boolean;\n\tstoppedResources: Set<AgentSessionRuntimeResource>;\n\thostInvalidated: boolean;\n\tsessionDisposed: boolean;\n}\n\n/** Session-owned background runtime that must not survive a session replacement. */\nexport interface AgentSessionRuntimeResource {\n\tstart(session: AgentSession): Promise<void>;\n\tstop(): Promise<void> | void;\n}\n\n/** Internal activation hooks used by the interactive session-resume flow. */\nexport interface AgentSessionSwitchOptions {\n\tcwdOverride?: string;\n\t/** Runs against the installed replacement after host rebind and before supervisors restart. */\n\tbeforeSessionResourcesStart?: (session: AgentSession) => Promise<void> | void;\n\twithSession?: (ctx: ReplacedSessionContext) => Promise<void>;\n}\n\ninterface SessionReplacementCommitOptions {\n\treason: SessionShutdownEvent[\"reason\"];\n\ttargetSessionFile: string | undefined;\n\tbeforeSessionResourcesStart?: (session: AgentSession) => Promise<void> | void;\n\twithSession?: (ctx: ReplacedSessionContext) => Promise<void>;\n\tonDiscard?: () => void;\n}\n\n/**\n * Creates a full runtime for a target cwd and session manager.\n *\n * The factory closes over process-global fixed inputs, recreates cwd-bound\n * services for the effective cwd, resolves session options against those\n * services, and finally creates the AgentSession.\n */\nexport type CreateAgentSessionRuntimeFactory = (options: {\n\tcwd: string;\n\tagentDir: string;\n\tsessionManager: SessionManager;\n\tsessionStartEvent?: SessionStartEvent;\n}) => Promise<CreateAgentSessionRuntimeResult>;\n\n/**\n * Thrown when /import references a JSONL file path that does not exist.\n */\nexport class SessionImportFileNotFoundError extends Error {\n\treadonly filePath: string;\n\n\tconstructor(filePath: string) {\n\t\tsuper(`File not found: ${filePath}`);\n\t\tthis.name = \"SessionImportFileNotFoundError\";\n\t\tthis.filePath = filePath;\n\t}\n}\n\n/** A teardown or activation failure at the replacement boundary, including rollback outcome. */\nexport class SessionReplacementRuntimeError extends Error {\n\treadonly phase: \"teardown\" | \"activation\";\n\treadonly recovered: boolean;\n\treadonly transitionError: unknown;\n\treadonly recoveryError: unknown | undefined;\n\n\tconstructor(\n\t\tphase: \"teardown\" | \"activation\",\n\t\ttransitionError: unknown,\n\t\trecovered: boolean,\n\t\trecoveryError?: unknown,\n\t) {\n\t\tconst transitionMessage = transitionError instanceof Error ? transitionError.message : String(transitionError);\n\t\tsuper(\n\t\t\trecovered\n\t\t\t\t? `Session replacement ${phase} failed; the previous session was restored: ${transitionMessage}`\n\t\t\t\t: `Session replacement ${phase} failed and the previous session could not be restored safely: ${transitionMessage}`,\n\t\t);\n\t\tthis.name = \"SessionReplacementRuntimeError\";\n\t\tthis.phase = phase;\n\t\tthis.recovered = recovered;\n\t\tthis.transitionError = transitionError;\n\t\tthis.recoveryError = recoveryError;\n\t}\n}\n\n/** A post-commit extension callback failed; the replacement itself remains the active session. */\nexport class SessionReplacementCallbackError extends Error {\n\treadonly replacementCommitted = true;\n\treadonly callbackError: unknown;\n\n\tconstructor(callbackError: unknown) {\n\t\tconst callbackMessage = callbackError instanceof Error ? callbackError.message : String(callbackError);\n\t\tsuper(`Session replacement completed, but its withSession callback failed: ${callbackMessage}`);\n\t\tthis.name = \"SessionReplacementCallbackError\";\n\t\tthis.callbackError = callbackError;\n\t}\n}\n\nfunction extractUserMessageText(content: string | Array<{ type: string; text?: string }>): string {\n\tif (typeof content === \"string\") {\n\t\treturn content;\n\t}\n\n\treturn content\n\t\t.filter((part): part is { type: \"text\"; text: string } => part.type === \"text\" && typeof part.text === \"string\")\n\t\t.map((part) => part.text)\n\t\t.join(\"\");\n}\n\n/**\n * Owns the current AgentSession plus its cwd-bound services.\n *\n * Session replacement methods construct the candidate runtime before retiring\n * the current one. If preparation fails, the working session remains active.\n */\nexport class AgentSessionRuntime {\n\tprivate rebindSession?: (session: AgentSession) => Promise<void>;\n\tprivate beforeSessionInvalidate?: () => void;\n\tprivate _session: AgentSession;\n\tprivate _services: AgentSessionServices;\n\tprivate readonly createRuntime: CreateAgentSessionRuntimeFactory;\n\tprivate _diagnostics: AgentSessionRuntimeDiagnostic[];\n\tprivate _modelFallbackMessage?: string;\n\tprivate _replacementInFlight: Promise<unknown> | undefined;\n\tprivate _disposeInFlight: Promise<void> | undefined;\n\tprivate _disposeStarted = false;\n\tprivate _disposed = false;\n\tprivate readonly disposeProgress: RuntimeShutdownProgress = {\n\t\tshutdownEventEmitted: false,\n\t\tstoppedResources: new Set(),\n\t\thostInvalidated: false,\n\t\tsessionDisposed: false,\n\t};\n\tprivate readonly sessionResources: AgentSessionRuntimeResource[] = [];\n\n\tconstructor(\n\t\t_session: AgentSession,\n\t\t_services: AgentSessionServices,\n\t\tcreateRuntime: CreateAgentSessionRuntimeFactory,\n\t\t_diagnostics: AgentSessionRuntimeDiagnostic[] = [],\n\t\t_modelFallbackMessage?: string,\n\t) {\n\t\tthis._session = _session;\n\t\tthis._services = _services;\n\t\tthis.createRuntime = createRuntime;\n\t\tthis._diagnostics = _diagnostics;\n\t\tthis._modelFallbackMessage = _modelFallbackMessage;\n\t}\n\n\tget services(): AgentSessionServices {\n\t\treturn this._services;\n\t}\n\n\tget session(): AgentSession {\n\t\treturn this._session;\n\t}\n\n\tget cwd(): string {\n\t\treturn this._services.cwd;\n\t}\n\n\tget diagnostics(): readonly AgentSessionRuntimeDiagnostic[] {\n\t\treturn this._diagnostics;\n\t}\n\n\tget modelFallbackMessage(): string | undefined {\n\t\treturn this._modelFallbackMessage;\n\t}\n\n\t/** True from replacement admission until rebind and replacement callbacks have settled. */\n\tget isReplacing(): boolean {\n\t\treturn this._replacementInFlight !== undefined;\n\t}\n\n\tsetRebindSession(rebindSession?: (session: AgentSession) => Promise<void>): void {\n\t\tthis.rebindSession = rebindSession;\n\t}\n\n\t/**\n\t * Set a synchronous callback that runs after `session_shutdown` handlers finish\n\t * but before the current session is invalidated.\n\t *\n\t * This is for host-owned UI teardown that must not yield to the event loop,\n\t * such as detaching extension-provided TUI components before the old extension\n\t * context becomes stale.\n\t */\n\tsetBeforeSessionInvalidate(beforeSessionInvalidate?: () => void): void {\n\t\tthis.beforeSessionInvalidate = beforeSessionInvalidate;\n\t}\n\n\t/** Register a resource whose lifecycle follows the active session (supervisors, watchers). */\n\tregisterSessionResource(resource: AgentSessionRuntimeResource): void {\n\t\tif (this.sessionResources.includes(resource)) return;\n\t\tthis.sessionResources.push(resource);\n\t}\n\n\tprivate async emitBeforeSwitch(\n\t\treason: \"new\" | \"resume\",\n\t\ttargetSessionFile?: string,\n\t): Promise<{ cancelled: boolean }> {\n\t\tconst runner = this.session.extensionRunner;\n\t\tif (!runner.hasHandlers(\"session_before_switch\")) {\n\t\t\treturn { cancelled: false };\n\t\t}\n\n\t\tconst result = await runner.emit({\n\t\t\ttype: \"session_before_switch\",\n\t\t\treason,\n\t\t\ttargetSessionFile,\n\t\t});\n\t\treturn { cancelled: result?.cancel === true };\n\t}\n\n\tprivate async emitBeforeFork(\n\t\tentryId: string,\n\t\toptions: { position: \"before\" | \"at\" },\n\t): Promise<{ cancelled: boolean }> {\n\t\tconst runner = this.session.extensionRunner;\n\t\tif (!runner.hasHandlers(\"session_before_fork\")) {\n\t\t\treturn { cancelled: false };\n\t\t}\n\n\t\tconst result = await runner.emit({\n\t\t\ttype: \"session_before_fork\",\n\t\t\tentryId,\n\t\t\t...options,\n\t\t});\n\t\treturn { cancelled: result?.cancel === true };\n\t}\n\n\tprivate async teardownCurrent(reason: SessionShutdownEvent[\"reason\"], targetSessionFile?: string): Promise<void> {\n\t\tconst errors = await this.shutdownRuntime(this.session, reason, targetSessionFile, {\n\t\t\tstopResources: true,\n\t\t\tinvalidateHost: true,\n\t\t});\n\t\tif (errors.length === 1) throw errors[0];\n\t\tif (errors.length > 1) throw new AggregateError(errors, \"Session runtime teardown failed.\");\n\t}\n\n\tprivate async discardPrepared(result: CreateAgentSessionRuntimeResult): Promise<void> {\n\t\tawait result.session.disposeAndWait();\n\t}\n\n\tprivate removeCreatedSessionFile(sessionFile: string | undefined): void {\n\t\tif (!sessionFile || sessionFile === this.session.sessionFile || !existsSync(sessionFile)) return;\n\t\ttry {\n\t\t\tunlinkSync(sessionFile);\n\t\t} catch {\n\t\t\t// Best-effort rollback of an artifact created solely for the rejected replacement.\n\t\t}\n\t}\n\n\tprivate async prepareReplacement(\n\t\tsessionManager: SessionManager,\n\t\tsessionStartEvent: SessionStartEvent,\n\t): Promise<CreateAgentSessionRuntimeResult> {\n\t\treturn this.createRuntime({\n\t\t\tcwd: sessionManager.getCwd(),\n\t\t\tagentDir: this.services.agentDir,\n\t\t\tsessionManager,\n\t\t\tsessionStartEvent,\n\t\t});\n\t}\n\n\tprivate async commitReplacement(\n\t\tresult: CreateAgentSessionRuntimeResult,\n\t\toptions: SessionReplacementCommitOptions,\n\t): Promise<void> {\n\t\tconst previous = this.snapshot();\n\t\ttry {\n\t\t\tawait this.teardownCurrent(options.reason, options.targetSessionFile);\n\t\t} catch (transitionError: unknown) {\n\t\t\tconst recoveryError = await this.restorePreviousAfterRuntimeFailure(previous, result, options, false);\n\t\t\tthrow new SessionReplacementRuntimeError(\n\t\t\t\t\"teardown\",\n\t\t\t\ttransitionError,\n\t\t\t\trecoveryError === undefined,\n\t\t\t\trecoveryError,\n\t\t\t);\n\t\t}\n\t\tthis.apply(result);\n\t\ttry {\n\t\t\tawait this.activateReplacement(options);\n\t\t} catch (activationError: unknown) {\n\t\t\tconst recoveryError = await this.restorePreviousAfterRuntimeFailure(previous, result, options, true);\n\t\t\tthrow new SessionReplacementRuntimeError(\n\t\t\t\t\"activation\",\n\t\t\t\tactivationError,\n\t\t\t\trecoveryError === undefined,\n\t\t\t\trecoveryError,\n\t\t\t);\n\t\t}\n\t\tif (options.withSession) {\n\t\t\ttry {\n\t\t\t\tawait options.withSession(this.session.createReplacedSessionContext());\n\t\t\t} catch (callbackError: unknown) {\n\t\t\t\tthrow new SessionReplacementCallbackError(callbackError);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate snapshot(): AgentSessionRuntimeState {\n\t\treturn {\n\t\t\tsession: this._session,\n\t\t\tservices: this._services,\n\t\t\tdiagnostics: [...this._diagnostics],\n\t\t\t...(this._modelFallbackMessage !== undefined ? { modelFallbackMessage: this._modelFallbackMessage } : {}),\n\t\t};\n\t}\n\n\tprivate apply(result: AgentSessionRuntimeState): void {\n\t\tthis._session = result.session;\n\t\tthis._services = result.services;\n\t\tthis._diagnostics = result.diagnostics;\n\t\tthis._modelFallbackMessage = result.modelFallbackMessage;\n\t}\n\n\tprivate async activateReplacement(options: SessionReplacementCommitOptions): Promise<void> {\n\t\tif (this.rebindSession) {\n\t\t\tawait this.rebindSession(this.session);\n\t\t}\n\t\tawait options.beforeSessionResourcesStart?.(this.session);\n\t\tfor (const resource of this.sessionResources) await resource.start(this.session);\n\t}\n\n\tprivate async restorePreviousAfterRuntimeFailure(\n\t\tprevious: AgentSessionRuntimeState,\n\t\tfailed: CreateAgentSessionRuntimeResult,\n\t\toptions: SessionReplacementCommitOptions,\n\t\tcandidateActivated: boolean,\n\t): Promise<unknown | undefined> {\n\t\tconst cleanupErrors = await this.shutdownRuntime(failed.session, options.reason, previous.session.sessionFile, {\n\t\t\tstopResources: candidateActivated,\n\t\t\tinvalidateHost: candidateActivated,\n\t\t});\n\t\t// The old AgentSession was disposed at the commit boundary, but its SessionManager remains the\n\t\t// durable reconstruction source. Restore the old snapshot temporarily so rollback-only artifact\n\t\t// cleanup cannot mistake the failed candidate for the active session.\n\t\tthis.apply(previous);\n\t\ttry {\n\t\t\toptions.onDiscard?.();\n\t\t} catch (error: unknown) {\n\t\t\tcleanupErrors.push(error);\n\t\t}\n\n\t\tlet restored: CreateAgentSessionRuntimeResult | undefined;\n\t\ttry {\n\t\t\trestored = await this.createRuntime({\n\t\t\t\tcwd: previous.services.cwd,\n\t\t\t\tagentDir: previous.services.agentDir,\n\t\t\t\tsessionManager: previous.session.sessionManager,\n\t\t\t\tsessionStartEvent: {\n\t\t\t\t\ttype: \"session_start\",\n\t\t\t\t\treason: \"resume\",\n\t\t\t\t\tpreviousSessionFile: failed.session.sessionFile,\n\t\t\t\t},\n\t\t\t});\n\t\t\tthis.apply(restored);\n\t\t\tif (this.rebindSession) await this.rebindSession(this.session);\n\t\t\tfor (const resource of this.sessionResources) await resource.start(this.session);\n\t\t} catch (recoveryError: unknown) {\n\t\t\tif (restored) {\n\t\t\t\tcleanupErrors.push(\n\t\t\t\t\t...(await this.shutdownRuntime(restored.session, \"resume\", failed.session.sessionFile, {\n\t\t\t\t\t\tstopResources: true,\n\t\t\t\t\t\tinvalidateHost: true,\n\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.apply(previous);\n\t\t\treturn cleanupErrors.length > 0\n\t\t\t\t? new AggregateError([...cleanupErrors, recoveryError], \"Session rollback and cleanup failed.\")\n\t\t\t\t: recoveryError;\n\t\t}\n\n\t\treturn cleanupErrors.length > 0\n\t\t\t? new AggregateError(\n\t\t\t\t\tcleanupErrors,\n\t\t\t\t\t\"The previous session was restored, but failed replacement cleanup was incomplete.\",\n\t\t\t\t)\n\t\t\t: undefined;\n\t}\n\n\tprivate async shutdownRuntime(\n\t\tsession: AgentSession,\n\t\treason: SessionShutdownEvent[\"reason\"],\n\t\ttargetSessionFile: string | undefined,\n\t\toptions: { stopResources: boolean; invalidateHost: boolean; progress?: RuntimeShutdownProgress },\n\t): Promise<unknown[]> {\n\t\tconst errors: unknown[] = [];\n\t\tconst progress =\n\t\t\toptions.progress ??\n\t\t\t({\n\t\t\t\tshutdownEventEmitted: false,\n\t\t\t\tstoppedResources: new Set(),\n\t\t\t\thostInvalidated: false,\n\t\t\t\tsessionDisposed: false,\n\t\t\t} satisfies RuntimeShutdownProgress);\n\t\tif (!progress.shutdownEventEmitted) {\n\t\t\ttry {\n\t\t\t\tawait emitSessionShutdownEvent(session.extensionRunner, {\n\t\t\t\t\ttype: \"session_shutdown\",\n\t\t\t\t\treason,\n\t\t\t\t\ttargetSessionFile,\n\t\t\t\t});\n\t\t\t\tprogress.shutdownEventEmitted = true;\n\t\t\t} catch (error: unknown) {\n\t\t\t\terrors.push(error);\n\t\t\t}\n\t\t}\n\t\tif (options.stopResources) {\n\t\t\tfor (const resource of this.sessionResources) {\n\t\t\t\tif (progress.stoppedResources.has(resource)) continue;\n\t\t\t\ttry {\n\t\t\t\t\tawait resource.stop();\n\t\t\t\t\tprogress.stoppedResources.add(resource);\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\terrors.push(error);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (options.invalidateHost && !progress.hostInvalidated) {\n\t\t\ttry {\n\t\t\t\tthis.beforeSessionInvalidate?.();\n\t\t\t\tprogress.hostInvalidated = true;\n\t\t\t} catch (error: unknown) {\n\t\t\t\terrors.push(error);\n\t\t\t}\n\t\t}\n\t\tif (!progress.sessionDisposed) {\n\t\t\ttry {\n\t\t\t\tawait session.disposeAndWait();\n\t\t\t\tprogress.sessionDisposed = true;\n\t\t\t} catch (error: unknown) {\n\t\t\t\terrors.push(error);\n\t\t\t}\n\t\t}\n\t\treturn errors;\n\t}\n\n\tprivate runSessionReplacement<T>(operation: () => Promise<T>): Promise<T> {\n\t\tif (this._disposeStarted) {\n\t\t\treturn Promise.reject(new Error(\"The session runtime has already been disposed.\"));\n\t\t}\n\t\tif (this._replacementInFlight) {\n\t\t\treturn Promise.reject(new Error(\"A session replacement is already in progress.\"));\n\t\t}\n\t\tconst replacement = Promise.resolve().then(operation);\n\t\tthis._replacementInFlight = replacement;\n\t\treturn replacement.finally(() => {\n\t\t\tif (this._replacementInFlight === replacement) this._replacementInFlight = undefined;\n\t\t});\n\t}\n\n\tasync switchSession(sessionPath: string, options?: AgentSessionSwitchOptions): Promise<{ cancelled: boolean }> {\n\t\treturn this.runSessionReplacement(() => this.switchSessionUnserialized(sessionPath, options));\n\t}\n\n\tprivate async switchSessionUnserialized(\n\t\tsessionPath: string,\n\t\toptions?: AgentSessionSwitchOptions,\n\t): Promise<{ cancelled: boolean }> {\n\t\tconst beforeResult = await this.emitBeforeSwitch(\"resume\", sessionPath);\n\t\tif (beforeResult.cancelled) {\n\t\t\treturn beforeResult;\n\t\t}\n\n\t\tconst previousSessionFile = this.session.sessionFile;\n\t\tconst sessionManager = SessionManager.open(sessionPath, this.services.agentDir, undefined, options?.cwdOverride);\n\t\tassertSessionCwdExists(sessionManager, this.cwd);\n\t\tconst prepared = await this.prepareReplacement(sessionManager, {\n\t\t\ttype: \"session_start\",\n\t\t\treason: \"resume\",\n\t\t\tpreviousSessionFile,\n\t\t});\n\t\tawait this.commitReplacement(prepared, {\n\t\t\treason: \"resume\",\n\t\t\ttargetSessionFile: sessionManager.getSessionFile(),\n\t\t\tbeforeSessionResourcesStart: options?.beforeSessionResourcesStart,\n\t\t\twithSession: options?.withSession,\n\t\t});\n\t\treturn { cancelled: false };\n\t}\n\n\tasync newSession(options?: {\n\t\tparentSession?: string;\n\t\tsetup?: (sessionManager: SessionManager) => Promise<void>;\n\t\twithSession?: (ctx: ReplacedSessionContext) => Promise<void>;\n\t}): Promise<{ cancelled: boolean }> {\n\t\treturn this.runSessionReplacement(() => this.newSessionUnserialized(options));\n\t}\n\n\tprivate async newSessionUnserialized(options?: {\n\t\tparentSession?: string;\n\t\tsetup?: (sessionManager: SessionManager) => Promise<void>;\n\t\twithSession?: (ctx: ReplacedSessionContext) => Promise<void>;\n\t}): Promise<{ cancelled: boolean }> {\n\t\tconst beforeResult = await this.emitBeforeSwitch(\"new\");\n\t\tif (beforeResult.cancelled) {\n\t\t\treturn beforeResult;\n\t\t}\n\n\t\tconst previousSessionFile = this.session.sessionFile;\n\t\tconst sessionDir = this.session.sessionManager.getSessionDir();\n\t\tconst sessionManager = SessionManager.create(this.cwd, this.services.agentDir, sessionDir);\n\t\tif (options?.parentSession) {\n\t\t\tsessionManager.newSession({ parentSession: options.parentSession });\n\t\t}\n\n\t\tlet prepared: CreateAgentSessionRuntimeResult;\n\t\ttry {\n\t\t\tprepared = await this.prepareReplacement(sessionManager, {\n\t\t\t\ttype: \"session_start\",\n\t\t\t\treason: \"new\",\n\t\t\t\tpreviousSessionFile,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthis.removeCreatedSessionFile(sessionManager.getSessionFile());\n\t\t\tthrow error;\n\t\t}\n\t\tif (options?.setup) {\n\t\t\ttry {\n\t\t\t\tawait options.setup(prepared.session.sessionManager);\n\t\t\t\tprepared.session.agent.state.messages = prepared.session.sessionManager.buildSessionContext().messages;\n\t\t\t} catch (error) {\n\t\t\t\tawait this.discardPrepared(prepared);\n\t\t\t\tthis.removeCreatedSessionFile(sessionManager.getSessionFile());\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tawait this.commitReplacement(prepared, {\n\t\t\treason: \"new\",\n\t\t\ttargetSessionFile: sessionManager.getSessionFile(),\n\t\t\twithSession: options?.withSession,\n\t\t\tonDiscard: () => this.removeCreatedSessionFile(sessionManager.getSessionFile()),\n\t\t});\n\t\treturn { cancelled: false };\n\t}\n\n\tasync fork(\n\t\tentryId: string,\n\t\toptions?: { position?: \"before\" | \"at\"; withSession?: (ctx: ReplacedSessionContext) => Promise<void> },\n\t): Promise<{ cancelled: boolean; selectedText?: string }> {\n\t\treturn this.runSessionReplacement(() => this.forkUnserialized(entryId, options));\n\t}\n\n\tprivate async forkUnserialized(\n\t\tentryId: string,\n\t\toptions?: { position?: \"before\" | \"at\"; withSession?: (ctx: ReplacedSessionContext) => Promise<void> },\n\t): Promise<{ cancelled: boolean; selectedText?: string }> {\n\t\tconst position = options?.position ?? \"before\";\n\t\tconst beforeResult = await this.emitBeforeFork(entryId, { position });\n\t\tif (beforeResult.cancelled) {\n\t\t\treturn { cancelled: true };\n\t\t}\n\t\tlet targetLeafId: string | null;\n\t\tlet selectedText: string | undefined;\n\n\t\tconst selectedEntry = this.session.sessionManager.getEntry(entryId);\n\t\tif (!selectedEntry) {\n\t\t\tthrow new Error(\"Invalid entry ID for forking\");\n\t\t}\n\n\t\tif (position === \"at\") {\n\t\t\ttargetLeafId = selectedEntry.id;\n\t\t} else {\n\t\t\tif (selectedEntry.type !== \"message\" || selectedEntry.message.role !== \"user\") {\n\t\t\t\tthrow new Error(\"Invalid entry ID for forking\");\n\t\t\t}\n\t\t\ttargetLeafId = selectedEntry.parentId;\n\t\t\tselectedText = extractUserMessageText(selectedEntry.message.content);\n\t\t}\n\n\t\tconst previousSessionFile = this.session.sessionFile;\n\t\tif (this.session.sessionManager.isPersisted()) {\n\t\t\tconst currentSessionFile = this.session.sessionFile;\n\t\t\tif (!currentSessionFile) {\n\t\t\t\tthrow new Error(\"Persisted session is missing a session file\");\n\t\t\t}\n\t\t\tconst sessionDir = this.session.sessionManager.getSessionDir();\n\t\t\tif (!targetLeafId) {\n\t\t\t\tconst sessionManager = SessionManager.create(this.cwd, this.services.agentDir, sessionDir);\n\t\t\t\tsessionManager.newSession({ parentSession: currentSessionFile });\n\t\t\t\tlet prepared: CreateAgentSessionRuntimeResult;\n\t\t\t\ttry {\n\t\t\t\t\tprepared = await this.prepareReplacement(sessionManager, {\n\t\t\t\t\t\ttype: \"session_start\",\n\t\t\t\t\t\treason: \"fork\",\n\t\t\t\t\t\tpreviousSessionFile,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.removeCreatedSessionFile(sessionManager.getSessionFile());\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tawait this.commitReplacement(prepared, {\n\t\t\t\t\treason: \"fork\",\n\t\t\t\t\ttargetSessionFile: sessionManager.getSessionFile(),\n\t\t\t\t\twithSession: options?.withSession,\n\t\t\t\t\tonDiscard: () => this.removeCreatedSessionFile(sessionManager.getSessionFile()),\n\t\t\t\t});\n\t\t\t\treturn { cancelled: false, selectedText };\n\t\t\t}\n\t\t\tif (!existsSync(currentSessionFile)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"This session has not been saved yet. Wait for the first assistant response before cloning or forking it.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst sourceSessionManager = SessionManager.open(currentSessionFile, this.services.agentDir, sessionDir);\n\t\t\tconst sessionManager = sourceSessionManager.createBranchedSessionManager(targetLeafId);\n\t\t\tconst forkedSessionPath = sessionManager.getSessionFile();\n\t\t\tif (!forkedSessionPath) {\n\t\t\t\tthrow new Error(\"Failed to create forked session\");\n\t\t\t}\n\t\t\tlet prepared: CreateAgentSessionRuntimeResult;\n\t\t\ttry {\n\t\t\t\tprepared = await this.prepareReplacement(sessionManager, {\n\t\t\t\t\ttype: \"session_start\",\n\t\t\t\t\treason: \"fork\",\n\t\t\t\t\tpreviousSessionFile,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tthis.removeCreatedSessionFile(forkedSessionPath);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tawait this.commitReplacement(prepared, {\n\t\t\t\treason: \"fork\",\n\t\t\t\ttargetSessionFile: forkedSessionPath,\n\t\t\t\twithSession: options?.withSession,\n\t\t\t\tonDiscard: () => this.removeCreatedSessionFile(forkedSessionPath),\n\t\t\t});\n\t\t\treturn { cancelled: false, selectedText };\n\t\t}\n\n\t\tlet sessionManager: SessionManager;\n\t\tif (!targetLeafId) {\n\t\t\tsessionManager = SessionManager.inMemory(this.cwd);\n\t\t\tsessionManager.newSession({ parentSession: this.session.sessionFile });\n\t\t} else {\n\t\t\tsessionManager = this.session.sessionManager.createBranchedSessionManager(targetLeafId);\n\t\t}\n\t\tconst prepared = await this.prepareReplacement(sessionManager, {\n\t\t\ttype: \"session_start\",\n\t\t\treason: \"fork\",\n\t\t\tpreviousSessionFile,\n\t\t});\n\t\tawait this.commitReplacement(prepared, {\n\t\t\treason: \"fork\",\n\t\t\ttargetSessionFile: sessionManager.getSessionFile(),\n\t\t\twithSession: options?.withSession,\n\t\t});\n\t\treturn { cancelled: false, selectedText };\n\t}\n\n\t/**\n\t * Import a session JSONL file and switch runtime state to the imported session.\n\t *\n\t * @returns `{ cancelled: true }` when cancelled by `session_before_switch`, otherwise `{ cancelled: false }`.\n\t * @throws {SessionImportFileNotFoundError} When the input path does not exist.\n\t * @throws {MissingSessionCwdError} When the imported session cwd cannot be resolved and no override is provided.\n\t */\n\tasync importFromJsonl(inputPath: string, cwdOverride?: string): Promise<{ cancelled: boolean }> {\n\t\treturn this.runSessionReplacement(() => this.importFromJsonlUnserialized(inputPath, cwdOverride));\n\t}\n\n\tprivate async importFromJsonlUnserialized(inputPath: string, cwdOverride?: string): Promise<{ cancelled: boolean }> {\n\t\tconst resolvedPath = resolvePath(inputPath);\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tthrow new SessionImportFileNotFoundError(resolvedPath);\n\t\t}\n\n\t\tconst sessionDir = this.session.sessionManager.getSessionDir();\n\t\tconst destinationPath = join(sessionDir, basename(resolvedPath));\n\t\tconst beforeResult = await this.emitBeforeSwitch(\"resume\", destinationPath);\n\t\tif (beforeResult.cancelled) {\n\t\t\treturn beforeResult;\n\t\t}\n\n\t\tconst previousSessionFile = this.session.sessionFile;\n\t\tlet copied = false;\n\t\tif (resolve(destinationPath) !== resolvedPath) {\n\t\t\tif (!existsSync(sessionDir)) mkdirSync(sessionDir, { recursive: true });\n\t\t\tcopyFileSync(resolvedPath, destinationPath, fsConstants.COPYFILE_EXCL);\n\t\t\tcopied = true;\n\t\t}\n\n\t\tlet sessionManager: SessionManager;\n\t\tlet prepared: CreateAgentSessionRuntimeResult;\n\t\ttry {\n\t\t\tsessionManager = SessionManager.open(destinationPath, this.services.agentDir, sessionDir, cwdOverride);\n\t\t\tassertSessionCwdExists(sessionManager, this.cwd);\n\t\t\tprepared = await this.prepareReplacement(sessionManager, {\n\t\t\t\ttype: \"session_start\",\n\t\t\t\treason: \"resume\",\n\t\t\t\tpreviousSessionFile,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tif (copied) this.removeCreatedSessionFile(destinationPath);\n\t\t\tthrow error;\n\t\t}\n\t\tawait this.commitReplacement(prepared, {\n\t\t\treason: \"resume\",\n\t\t\ttargetSessionFile: sessionManager.getSessionFile(),\n\t\t\tonDiscard: copied ? () => this.removeCreatedSessionFile(destinationPath) : undefined,\n\t\t});\n\t\treturn { cancelled: false };\n\t}\n\n\tasync dispose(): Promise<void> {\n\t\tif (this._disposeInFlight) return this._disposeInFlight;\n\t\tif (this._disposed) return;\n\t\tthis._disposeStarted = true;\n\t\tconst replacement = this._replacementInFlight;\n\t\tconst disposal = (async () => {\n\t\t\tif (replacement) {\n\t\t\t\ttry {\n\t\t\t\t\tawait replacement;\n\t\t\t\t} catch {\n\t\t\t\t\t// Replacement already reports its own error; dispose whichever runtime it left active.\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst errors = await this.shutdownRuntime(this.session, \"quit\", undefined, {\n\t\t\t\tstopResources: true,\n\t\t\t\tinvalidateHost: true,\n\t\t\t\tprogress: this.disposeProgress,\n\t\t\t});\n\t\t\tif (errors.length === 1) throw errors[0];\n\t\t\tif (errors.length > 1) throw new AggregateError(errors, \"Session runtime disposal failed.\");\n\t\t\tthis._disposed = true;\n\t\t})();\n\t\tthis._disposeInFlight = disposal;\n\t\ttry {\n\t\t\tawait disposal;\n\t\t} finally {\n\t\t\tthis._disposeInFlight = undefined;\n\t\t}\n\t}\n}\n\n/**\n * Create the initial runtime from a runtime factory and initial session target.\n *\n * The same factory is stored on the returned AgentSessionRuntime and reused for\n * later /new, /resume, /fork, and import flows.\n */\nexport async function createAgentSessionRuntime(\n\tcreateRuntime: CreateAgentSessionRuntimeFactory,\n\toptions: {\n\t\tcwd: string;\n\t\tagentDir: string;\n\t\tsessionManager: SessionManager;\n\t\tsessionStartEvent?: SessionStartEvent;\n\t},\n): Promise<AgentSessionRuntime> {\n\tassertSessionCwdExists(options.sessionManager, options.cwd);\n\tconst result = await createRuntime(options);\n\treturn new AgentSessionRuntime(\n\t\tresult.session,\n\t\tresult.services,\n\t\tcreateRuntime,\n\t\tresult.diagnostics,\n\t\tresult.modelFallbackMessage,\n\t);\n}\n\nexport {\n\ttype AgentSessionRuntimeDiagnostic,\n\ttype AgentSessionServices,\n\ttype CreateAgentSessionFromServicesOptions,\n\ttype CreateAgentSessionServicesOptions,\n\tcreateAgentSessionFromServices,\n\tcreateAgentSessionServices,\n} from \"./agent-session-services.ts\";\n"]}
|
|
1
|
+
{"version":3,"file":"agent-session-runtime.js","sourceRoot":"","sources":["../../src/core/agent-session-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,IAAI,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAElE,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AA+D1D;;GAEG;AACH,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IAGxD,YAAY,QAAgB;QAC3B,KAAK,CAAC,mBAAmB,QAAQ,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;QAC7C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;CACD;AAED,gGAAgG;AAChG,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IAMxD,YACC,KAAgC,EAChC,eAAwB,EACxB,SAAkB,EAClB,aAAuB;QAEvB,MAAM,iBAAiB,GAAG,eAAe,YAAY,KAAK,CAAC,CAAC,CAAC,eAA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CAAC;YACzC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;gBAAE,MAAM,IAAI,cAAc,CAAC,MAAM,EAAE,kCAAkC,CAAC,CAAC;YAC5F,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACvB,CAAC,CAAC,EAAE,CAAC;QACL,IAAI,CAAC,gBAAgB,GAAG,QAAQ,CAAC;QACjC,IAAI,CAAC;YACJ,MAAM,QAAQ,CAAC;QAChB,CAAC;gBAAS,CAAC;YACV,IAAI,CAAC,gBAAgB,GAAG,SAAS,CAAC;QACnC,CAAC;IACF,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC9C,aAA+C,EAC/C,OAKC;IAED,sBAAsB,CAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5D,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,OAAO,CAAC,CAAC;IAC5C,OAAO,IAAI,mBAAmB,CAC7B,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,QAAQ,EACf,aAAa,EACb,MAAM,CAAC,WAAW,EAClB,MAAM,CAAC,oBAAoB,CAC3B,CAAC;AACH,CAAC;AAED,OAAO,EAKN,8BAA8B,EAC9B,0BAA0B,GAC1B,MAAM,6BAA6B,CAAC","sourcesContent":["import { copyFileSync, existsSync, constants as fsConstants, mkdirSync, unlinkSync } from \"node:fs\";\nimport { basename, join, resolve } from \"node:path\";\nimport { SessionManager } from \"@caupulican/pi-agent-core/session\";\nimport { resolvePath } from \"../utils/paths.ts\";\nimport type { AgentSession } from \"./agent-session.ts\";\nimport type { AgentSessionRuntimeDiagnostic, AgentSessionServices } from \"./agent-session-services.ts\";\nimport type { ReplacedSessionContext, SessionShutdownEvent, SessionStartEvent } from \"./extensions/index.ts\";\nimport { emitSessionShutdownEvent } from \"./extensions/runner.ts\";\nimport type { CreateAgentSessionResult } from \"./sdk.ts\";\nimport { assertSessionCwdExists } from \"./session-cwd.ts\";\n\n/**\n * Result returned by runtime creation.\n *\n * The caller gets the created session, its cwd-bound services, and all\n * diagnostics collected during setup.\n */\nexport interface CreateAgentSessionRuntimeResult extends CreateAgentSessionResult {\n\tservices: AgentSessionServices;\n\tdiagnostics: AgentSessionRuntimeDiagnostic[];\n}\n\ninterface AgentSessionRuntimeState {\n\tsession: AgentSession;\n\tservices: AgentSessionServices;\n\tdiagnostics: AgentSessionRuntimeDiagnostic[];\n\tmodelFallbackMessage?: string;\n}\n\ninterface RuntimeShutdownProgress {\n\tshutdownEventEmitted: boolean;\n\tstoppedResources: Set<AgentSessionRuntimeResource>;\n\thostInvalidated: boolean;\n\tsessionDisposed: boolean;\n}\n\n/** Session-owned background runtime that must not survive a session replacement. */\nexport interface AgentSessionRuntimeResource {\n\tstart(session: AgentSession): Promise<void>;\n\tstop(): Promise<void> | void;\n}\n\n/** Internal activation hooks used by the interactive session-resume flow. */\nexport interface AgentSessionSwitchOptions {\n\tcwdOverride?: string;\n\t/** Runs against the installed replacement after host rebind and before supervisors restart. */\n\tbeforeSessionResourcesStart?: (session: AgentSession) => Promise<void> | void;\n\twithSession?: (ctx: ReplacedSessionContext) => Promise<void>;\n}\n\ninterface SessionReplacementCommitOptions {\n\treason: SessionShutdownEvent[\"reason\"];\n\ttargetSessionFile: string | undefined;\n\tbeforeSessionResourcesStart?: (session: AgentSession) => Promise<void> | void;\n\twithSession?: (ctx: ReplacedSessionContext) => Promise<void>;\n\tonDiscard?: () => void;\n}\n\n/**\n * Creates a full runtime for a target cwd and session manager.\n *\n * The factory closes over process-global fixed inputs, recreates cwd-bound\n * services for the effective cwd, resolves session options against those\n * services, and finally creates the AgentSession.\n */\nexport type CreateAgentSessionRuntimeFactory = (options: {\n\tcwd: string;\n\tagentDir: string;\n\tsessionManager: SessionManager;\n\tsessionStartEvent?: SessionStartEvent;\n}) => Promise<CreateAgentSessionRuntimeResult>;\n\n/**\n * Thrown when /import references a JSONL file path that does not exist.\n */\nexport class SessionImportFileNotFoundError extends Error {\n\treadonly filePath: string;\n\n\tconstructor(filePath: string) {\n\t\tsuper(`File not found: ${filePath}`);\n\t\tthis.name = \"SessionImportFileNotFoundError\";\n\t\tthis.filePath = filePath;\n\t}\n}\n\n/** A teardown or activation failure at the replacement boundary, including rollback outcome. */\nexport class SessionReplacementRuntimeError extends Error {\n\treadonly phase: \"teardown\" | \"activation\";\n\treadonly recovered: boolean;\n\treadonly transitionError: unknown;\n\treadonly recoveryError: unknown | undefined;\n\n\tconstructor(\n\t\tphase: \"teardown\" | \"activation\",\n\t\ttransitionError: unknown,\n\t\trecovered: boolean,\n\t\trecoveryError?: unknown,\n\t) {\n\t\tconst transitionMessage = transitionError instanceof Error ? transitionError.message : String(transitionError);\n\t\tsuper(\n\t\t\trecovered\n\t\t\t\t? `Session replacement ${phase} failed; the previous session was restored: ${transitionMessage}`\n\t\t\t\t: `Session replacement ${phase} failed and the previous session could not be restored safely: ${transitionMessage}`,\n\t\t);\n\t\tthis.name = \"SessionReplacementRuntimeError\";\n\t\tthis.phase = phase;\n\t\tthis.recovered = recovered;\n\t\tthis.transitionError = transitionError;\n\t\tthis.recoveryError = recoveryError;\n\t}\n}\n\n/** A post-commit extension callback failed; the replacement itself remains the active session. */\nexport class SessionReplacementCallbackError extends Error {\n\treadonly replacementCommitted = true;\n\treadonly callbackError: unknown;\n\n\tconstructor(callbackError: unknown) {\n\t\tconst callbackMessage = callbackError instanceof Error ? callbackError.message : String(callbackError);\n\t\tsuper(`Session replacement completed, but its withSession callback failed: ${callbackMessage}`);\n\t\tthis.name = \"SessionReplacementCallbackError\";\n\t\tthis.callbackError = callbackError;\n\t}\n}\n\nfunction extractUserMessageText(content: string | Array<{ type: string; text?: string }>): string {\n\tif (typeof content === \"string\") {\n\t\treturn content;\n\t}\n\n\treturn content\n\t\t.filter((part): part is { type: \"text\"; text: string } => part.type === \"text\" && typeof part.text === \"string\")\n\t\t.map((part) => part.text)\n\t\t.join(\"\");\n}\n\n/**\n * Owns the current AgentSession plus its cwd-bound services.\n *\n * Session replacement methods construct the candidate runtime before retiring\n * the current one. If preparation fails, the working session remains active.\n */\nexport class AgentSessionRuntime {\n\tprivate rebindSession?: (session: AgentSession) => Promise<void>;\n\tprivate beforeSessionInvalidate?: () => void;\n\tprivate _session: AgentSession;\n\tprivate _services: AgentSessionServices;\n\tprivate readonly createRuntime: CreateAgentSessionRuntimeFactory;\n\tprivate _diagnostics: AgentSessionRuntimeDiagnostic[];\n\tprivate _modelFallbackMessage?: string;\n\tprivate _replacementInFlight: Promise<unknown> | undefined;\n\tprivate _disposeInFlight: Promise<void> | undefined;\n\tprivate _disposeStarted = false;\n\tprivate _disposed = false;\n\tprivate readonly disposeProgress: RuntimeShutdownProgress = {\n\t\tshutdownEventEmitted: false,\n\t\tstoppedResources: new Set(),\n\t\thostInvalidated: false,\n\t\tsessionDisposed: false,\n\t};\n\tprivate readonly sessionResources: AgentSessionRuntimeResource[] = [];\n\n\tconstructor(\n\t\t_session: AgentSession,\n\t\t_services: AgentSessionServices,\n\t\tcreateRuntime: CreateAgentSessionRuntimeFactory,\n\t\t_diagnostics: AgentSessionRuntimeDiagnostic[] = [],\n\t\t_modelFallbackMessage?: string,\n\t) {\n\t\tthis._session = _session;\n\t\tthis._services = _services;\n\t\tthis.createRuntime = createRuntime;\n\t\tthis._diagnostics = _diagnostics;\n\t\tthis._modelFallbackMessage = _modelFallbackMessage;\n\t}\n\n\tget services(): AgentSessionServices {\n\t\treturn this._services;\n\t}\n\n\tget session(): AgentSession {\n\t\treturn this._session;\n\t}\n\n\tget cwd(): string {\n\t\treturn this._services.cwd;\n\t}\n\n\tget diagnostics(): readonly AgentSessionRuntimeDiagnostic[] {\n\t\treturn this._diagnostics;\n\t}\n\n\tget modelFallbackMessage(): string | undefined {\n\t\treturn this._modelFallbackMessage;\n\t}\n\n\t/** True from replacement admission until rebind and replacement callbacks have settled. */\n\tget isReplacing(): boolean {\n\t\treturn this._replacementInFlight !== undefined;\n\t}\n\n\tsetRebindSession(rebindSession?: (session: AgentSession) => Promise<void>): void {\n\t\tthis.rebindSession = rebindSession;\n\t}\n\n\t/**\n\t * Set a synchronous callback that runs after `session_shutdown` handlers finish\n\t * but before the current session is invalidated.\n\t *\n\t * This is for host-owned UI teardown that must not yield to the event loop,\n\t * such as detaching extension-provided TUI components before the old extension\n\t * context becomes stale.\n\t */\n\tsetBeforeSessionInvalidate(beforeSessionInvalidate?: () => void): void {\n\t\tthis.beforeSessionInvalidate = beforeSessionInvalidate;\n\t}\n\n\t/** Register a resource whose lifecycle follows the active session (supervisors, watchers). */\n\tregisterSessionResource(resource: AgentSessionRuntimeResource): void {\n\t\tif (this.sessionResources.includes(resource)) return;\n\t\tthis.sessionResources.push(resource);\n\t}\n\n\tprivate async emitBeforeSwitch(\n\t\treason: \"new\" | \"resume\",\n\t\ttargetSessionFile?: string,\n\t): Promise<{ cancelled: boolean }> {\n\t\tconst runner = this.session.extensionRunner;\n\t\tif (!runner.hasHandlers(\"session_before_switch\")) {\n\t\t\treturn { cancelled: false };\n\t\t}\n\n\t\tconst result = await runner.emit({\n\t\t\ttype: \"session_before_switch\",\n\t\t\treason,\n\t\t\ttargetSessionFile,\n\t\t});\n\t\treturn { cancelled: result?.cancel === true };\n\t}\n\n\tprivate async emitBeforeFork(\n\t\tentryId: string,\n\t\toptions: { position: \"before\" | \"at\" },\n\t): Promise<{ cancelled: boolean }> {\n\t\tconst runner = this.session.extensionRunner;\n\t\tif (!runner.hasHandlers(\"session_before_fork\")) {\n\t\t\treturn { cancelled: false };\n\t\t}\n\n\t\tconst result = await runner.emit({\n\t\t\ttype: \"session_before_fork\",\n\t\t\tentryId,\n\t\t\t...options,\n\t\t});\n\t\treturn { cancelled: result?.cancel === true };\n\t}\n\n\tprivate async teardownCurrent(reason: SessionShutdownEvent[\"reason\"], targetSessionFile?: string): Promise<void> {\n\t\tconst errors = await this.shutdownRuntime(this.session, reason, targetSessionFile, {\n\t\t\tstopResources: true,\n\t\t\tinvalidateHost: true,\n\t\t});\n\t\tif (errors.length === 1) throw errors[0];\n\t\tif (errors.length > 1) throw new AggregateError(errors, \"Session runtime teardown failed.\");\n\t}\n\n\tprivate async discardPrepared(result: CreateAgentSessionRuntimeResult): Promise<void> {\n\t\tawait result.session.disposeAndWait();\n\t}\n\n\tprivate removeCreatedSessionFile(sessionFile: string | undefined): void {\n\t\tif (!sessionFile || sessionFile === this.session.sessionFile || !existsSync(sessionFile)) return;\n\t\ttry {\n\t\t\tunlinkSync(sessionFile);\n\t\t} catch {\n\t\t\t// Best-effort rollback of an artifact created solely for the rejected replacement.\n\t\t}\n\t}\n\n\tprivate async prepareReplacement(\n\t\tsessionManager: SessionManager,\n\t\tsessionStartEvent: SessionStartEvent,\n\t): Promise<CreateAgentSessionRuntimeResult> {\n\t\treturn this.createRuntime({\n\t\t\tcwd: sessionManager.getCwd(),\n\t\t\tagentDir: this.services.agentDir,\n\t\t\tsessionManager,\n\t\t\tsessionStartEvent,\n\t\t});\n\t}\n\n\tprivate async commitReplacement(\n\t\tresult: CreateAgentSessionRuntimeResult,\n\t\toptions: SessionReplacementCommitOptions,\n\t): Promise<void> {\n\t\tconst previous = this.snapshot();\n\t\ttry {\n\t\t\tawait this.teardownCurrent(options.reason, options.targetSessionFile);\n\t\t} catch (transitionError: unknown) {\n\t\t\tconst recoveryError = await this.restorePreviousAfterRuntimeFailure(previous, result, options, false);\n\t\t\tthrow new SessionReplacementRuntimeError(\n\t\t\t\t\"teardown\",\n\t\t\t\ttransitionError,\n\t\t\t\trecoveryError === undefined,\n\t\t\t\trecoveryError,\n\t\t\t);\n\t\t}\n\t\tthis.apply(result);\n\t\ttry {\n\t\t\tawait this.activateReplacement(options);\n\t\t} catch (activationError: unknown) {\n\t\t\tconst recoveryError = await this.restorePreviousAfterRuntimeFailure(previous, result, options, true);\n\t\t\tthrow new SessionReplacementRuntimeError(\n\t\t\t\t\"activation\",\n\t\t\t\tactivationError,\n\t\t\t\trecoveryError === undefined,\n\t\t\t\trecoveryError,\n\t\t\t);\n\t\t}\n\t\tif (options.withSession) {\n\t\t\ttry {\n\t\t\t\tawait options.withSession(this.session.createReplacedSessionContext());\n\t\t\t} catch (callbackError: unknown) {\n\t\t\t\tthrow new SessionReplacementCallbackError(callbackError);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate snapshot(): AgentSessionRuntimeState {\n\t\treturn {\n\t\t\tsession: this._session,\n\t\t\tservices: this._services,\n\t\t\tdiagnostics: [...this._diagnostics],\n\t\t\t...(this._modelFallbackMessage !== undefined ? { modelFallbackMessage: this._modelFallbackMessage } : {}),\n\t\t};\n\t}\n\n\tprivate apply(result: AgentSessionRuntimeState): void {\n\t\tthis._session = result.session;\n\t\tthis._services = result.services;\n\t\tthis._diagnostics = result.diagnostics;\n\t\tthis._modelFallbackMessage = result.modelFallbackMessage;\n\t}\n\n\tprivate async activateReplacement(options: SessionReplacementCommitOptions): Promise<void> {\n\t\tif (this.rebindSession) {\n\t\t\tawait this.rebindSession(this.session);\n\t\t}\n\t\tawait options.beforeSessionResourcesStart?.(this.session);\n\t\tfor (const resource of this.sessionResources) await resource.start(this.session);\n\t}\n\n\tprivate async restorePreviousAfterRuntimeFailure(\n\t\tprevious: AgentSessionRuntimeState,\n\t\tfailed: CreateAgentSessionRuntimeResult,\n\t\toptions: SessionReplacementCommitOptions,\n\t\tcandidateActivated: boolean,\n\t): Promise<unknown | undefined> {\n\t\tconst cleanupErrors = await this.shutdownRuntime(failed.session, options.reason, previous.session.sessionFile, {\n\t\t\tstopResources: candidateActivated,\n\t\t\tinvalidateHost: candidateActivated,\n\t\t});\n\t\t// The old AgentSession was disposed at the commit boundary, but its SessionManager remains the\n\t\t// durable reconstruction source. Restore the old snapshot temporarily so rollback-only artifact\n\t\t// cleanup cannot mistake the failed candidate for the active session.\n\t\tthis.apply(previous);\n\t\ttry {\n\t\t\toptions.onDiscard?.();\n\t\t} catch (error: unknown) {\n\t\t\tcleanupErrors.push(error);\n\t\t}\n\n\t\tlet restored: CreateAgentSessionRuntimeResult | undefined;\n\t\ttry {\n\t\t\trestored = await this.createRuntime({\n\t\t\t\tcwd: previous.services.cwd,\n\t\t\t\tagentDir: previous.services.agentDir,\n\t\t\t\tsessionManager: previous.session.sessionManager,\n\t\t\t\tsessionStartEvent: {\n\t\t\t\t\ttype: \"session_start\",\n\t\t\t\t\treason: \"resume\",\n\t\t\t\t\tpreviousSessionFile: failed.session.sessionFile,\n\t\t\t\t},\n\t\t\t});\n\t\t\tthis.apply(restored);\n\t\t\tif (this.rebindSession) await this.rebindSession(this.session);\n\t\t\tfor (const resource of this.sessionResources) await resource.start(this.session);\n\t\t} catch (recoveryError: unknown) {\n\t\t\tif (restored) {\n\t\t\t\tcleanupErrors.push(\n\t\t\t\t\t...(await this.shutdownRuntime(restored.session, \"resume\", failed.session.sessionFile, {\n\t\t\t\t\t\tstopResources: true,\n\t\t\t\t\t\tinvalidateHost: true,\n\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.apply(previous);\n\t\t\treturn cleanupErrors.length > 0\n\t\t\t\t? new AggregateError([...cleanupErrors, recoveryError], \"Session rollback and cleanup failed.\")\n\t\t\t\t: recoveryError;\n\t\t}\n\n\t\treturn cleanupErrors.length > 0\n\t\t\t? new AggregateError(\n\t\t\t\t\tcleanupErrors,\n\t\t\t\t\t\"The previous session was restored, but failed replacement cleanup was incomplete.\",\n\t\t\t\t)\n\t\t\t: undefined;\n\t}\n\n\tprivate async shutdownRuntime(\n\t\tsession: AgentSession,\n\t\treason: SessionShutdownEvent[\"reason\"],\n\t\ttargetSessionFile: string | undefined,\n\t\toptions: { stopResources: boolean; invalidateHost: boolean; progress?: RuntimeShutdownProgress },\n\t): Promise<unknown[]> {\n\t\tconst errors: unknown[] = [];\n\t\tconst progress =\n\t\t\toptions.progress ??\n\t\t\t({\n\t\t\t\tshutdownEventEmitted: false,\n\t\t\t\tstoppedResources: new Set(),\n\t\t\t\thostInvalidated: false,\n\t\t\t\tsessionDisposed: false,\n\t\t\t} satisfies RuntimeShutdownProgress);\n\t\tif (!progress.shutdownEventEmitted) {\n\t\t\ttry {\n\t\t\t\tawait emitSessionShutdownEvent(session.extensionRunner, {\n\t\t\t\t\ttype: \"session_shutdown\",\n\t\t\t\t\treason,\n\t\t\t\t\ttargetSessionFile,\n\t\t\t\t});\n\t\t\t\tprogress.shutdownEventEmitted = true;\n\t\t\t} catch (error: unknown) {\n\t\t\t\terrors.push(error);\n\t\t\t}\n\t\t}\n\t\tif (options.stopResources) {\n\t\t\tfor (const resource of this.sessionResources) {\n\t\t\t\tif (progress.stoppedResources.has(resource)) continue;\n\t\t\t\ttry {\n\t\t\t\t\tawait resource.stop();\n\t\t\t\t\tprogress.stoppedResources.add(resource);\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\terrors.push(error);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (options.invalidateHost && !progress.hostInvalidated) {\n\t\t\ttry {\n\t\t\t\tthis.beforeSessionInvalidate?.();\n\t\t\t\tprogress.hostInvalidated = true;\n\t\t\t} catch (error: unknown) {\n\t\t\t\terrors.push(error);\n\t\t\t}\n\t\t}\n\t\tif (!progress.sessionDisposed) {\n\t\t\ttry {\n\t\t\t\tawait session.disposeAndWait();\n\t\t\t\tprogress.sessionDisposed = true;\n\t\t\t} catch (error: unknown) {\n\t\t\t\terrors.push(error);\n\t\t\t}\n\t\t}\n\t\treturn errors;\n\t}\n\n\tprivate runSessionReplacement<T>(operation: () => Promise<T>): Promise<T> {\n\t\tif (this._disposeStarted) {\n\t\t\treturn Promise.reject(new Error(\"The session runtime has already been disposed.\"));\n\t\t}\n\t\tif (this._replacementInFlight) {\n\t\t\treturn Promise.reject(new Error(\"A session replacement is already in progress.\"));\n\t\t}\n\t\tconst replacement = Promise.resolve().then(operation);\n\t\tthis._replacementInFlight = replacement;\n\t\treturn replacement.finally(() => {\n\t\t\tif (this._replacementInFlight === replacement) this._replacementInFlight = undefined;\n\t\t});\n\t}\n\n\tasync switchSession(sessionPath: string, options?: AgentSessionSwitchOptions): Promise<{ cancelled: boolean }> {\n\t\treturn this.runSessionReplacement(() => this.switchSessionUnserialized(sessionPath, options));\n\t}\n\n\tprivate async switchSessionUnserialized(\n\t\tsessionPath: string,\n\t\toptions?: AgentSessionSwitchOptions,\n\t): Promise<{ cancelled: boolean }> {\n\t\tconst beforeResult = await this.emitBeforeSwitch(\"resume\", sessionPath);\n\t\tif (beforeResult.cancelled) {\n\t\t\treturn beforeResult;\n\t\t}\n\n\t\tconst previousSessionFile = this.session.sessionFile;\n\t\tconst sessionManager = SessionManager.open(sessionPath, this.services.agentDir, undefined, options?.cwdOverride);\n\t\tassertSessionCwdExists(sessionManager, this.cwd);\n\t\tconst prepared = await this.prepareReplacement(sessionManager, {\n\t\t\ttype: \"session_start\",\n\t\t\treason: \"resume\",\n\t\t\tpreviousSessionFile,\n\t\t});\n\t\tawait this.commitReplacement(prepared, {\n\t\t\treason: \"resume\",\n\t\t\ttargetSessionFile: sessionManager.getSessionFile(),\n\t\t\tbeforeSessionResourcesStart: options?.beforeSessionResourcesStart,\n\t\t\twithSession: options?.withSession,\n\t\t});\n\t\treturn { cancelled: false };\n\t}\n\n\tasync newSession(options?: {\n\t\tparentSession?: string;\n\t\tsetup?: (sessionManager: SessionManager) => Promise<void>;\n\t\twithSession?: (ctx: ReplacedSessionContext) => Promise<void>;\n\t}): Promise<{ cancelled: boolean }> {\n\t\treturn this.runSessionReplacement(() => this.newSessionUnserialized(options));\n\t}\n\n\tprivate async newSessionUnserialized(options?: {\n\t\tparentSession?: string;\n\t\tsetup?: (sessionManager: SessionManager) => Promise<void>;\n\t\twithSession?: (ctx: ReplacedSessionContext) => Promise<void>;\n\t}): Promise<{ cancelled: boolean }> {\n\t\tconst beforeResult = await this.emitBeforeSwitch(\"new\");\n\t\tif (beforeResult.cancelled) {\n\t\t\treturn beforeResult;\n\t\t}\n\n\t\tconst previousSessionFile = this.session.sessionFile;\n\t\tconst sessionDir = this.session.sessionManager.getSessionDir();\n\t\tconst sessionManager = SessionManager.create(this.cwd, this.services.agentDir, sessionDir);\n\t\tif (options?.parentSession) {\n\t\t\tsessionManager.newSession({ parentSession: options.parentSession });\n\t\t}\n\n\t\tlet prepared: CreateAgentSessionRuntimeResult;\n\t\ttry {\n\t\t\tprepared = await this.prepareReplacement(sessionManager, {\n\t\t\t\ttype: \"session_start\",\n\t\t\t\treason: \"new\",\n\t\t\t\tpreviousSessionFile,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthis.removeCreatedSessionFile(sessionManager.getSessionFile());\n\t\t\tthrow error;\n\t\t}\n\t\tif (options?.setup) {\n\t\t\ttry {\n\t\t\t\tawait options.setup(prepared.session.sessionManager);\n\t\t\t\tprepared.session.agent.state.messages = prepared.session.sessionManager.buildSessionContext().messages;\n\t\t\t} catch (error) {\n\t\t\t\tawait this.discardPrepared(prepared);\n\t\t\t\tthis.removeCreatedSessionFile(sessionManager.getSessionFile());\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tawait this.commitReplacement(prepared, {\n\t\t\treason: \"new\",\n\t\t\ttargetSessionFile: sessionManager.getSessionFile(),\n\t\t\twithSession: options?.withSession,\n\t\t\tonDiscard: () => this.removeCreatedSessionFile(sessionManager.getSessionFile()),\n\t\t});\n\t\treturn { cancelled: false };\n\t}\n\n\tasync fork(\n\t\tentryId: string,\n\t\toptions?: { position?: \"before\" | \"at\"; withSession?: (ctx: ReplacedSessionContext) => Promise<void> },\n\t): Promise<{ cancelled: boolean; selectedText?: string }> {\n\t\treturn this.runSessionReplacement(() => this.forkUnserialized(entryId, options));\n\t}\n\n\tprivate async forkUnserialized(\n\t\tentryId: string,\n\t\toptions?: { position?: \"before\" | \"at\"; withSession?: (ctx: ReplacedSessionContext) => Promise<void> },\n\t): Promise<{ cancelled: boolean; selectedText?: string }> {\n\t\tconst position = options?.position ?? \"before\";\n\t\tconst beforeResult = await this.emitBeforeFork(entryId, { position });\n\t\tif (beforeResult.cancelled) {\n\t\t\treturn { cancelled: true };\n\t\t}\n\t\tlet targetLeafId: string | null;\n\t\tlet selectedText: string | undefined;\n\n\t\tconst selectedEntry = this.session.sessionManager.getEntry(entryId);\n\t\tif (!selectedEntry) {\n\t\t\tthrow new Error(\"Invalid entry ID for forking\");\n\t\t}\n\n\t\tif (position === \"at\") {\n\t\t\ttargetLeafId = selectedEntry.id;\n\t\t} else {\n\t\t\tif (selectedEntry.type !== \"message\" || selectedEntry.message.role !== \"user\") {\n\t\t\t\tthrow new Error(\"Invalid entry ID for forking\");\n\t\t\t}\n\t\t\ttargetLeafId = selectedEntry.parentId;\n\t\t\tselectedText = extractUserMessageText(selectedEntry.message.content);\n\t\t}\n\n\t\tconst previousSessionFile = this.session.sessionFile;\n\t\tif (this.session.sessionManager.isPersisted()) {\n\t\t\tconst currentSessionFile = this.session.sessionFile;\n\t\t\tif (!currentSessionFile) {\n\t\t\t\tthrow new Error(\"Persisted session is missing a session file\");\n\t\t\t}\n\t\t\tconst sessionDir = this.session.sessionManager.getSessionDir();\n\t\t\tif (!targetLeafId) {\n\t\t\t\tconst sessionManager = SessionManager.create(this.cwd, this.services.agentDir, sessionDir);\n\t\t\t\tsessionManager.newSession({ parentSession: currentSessionFile });\n\t\t\t\tlet prepared: CreateAgentSessionRuntimeResult;\n\t\t\t\ttry {\n\t\t\t\t\tprepared = await this.prepareReplacement(sessionManager, {\n\t\t\t\t\t\ttype: \"session_start\",\n\t\t\t\t\t\treason: \"fork\",\n\t\t\t\t\t\tpreviousSessionFile,\n\t\t\t\t\t});\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.removeCreatedSessionFile(sessionManager.getSessionFile());\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t\tawait this.commitReplacement(prepared, {\n\t\t\t\t\treason: \"fork\",\n\t\t\t\t\ttargetSessionFile: sessionManager.getSessionFile(),\n\t\t\t\t\twithSession: options?.withSession,\n\t\t\t\t\tonDiscard: () => this.removeCreatedSessionFile(sessionManager.getSessionFile()),\n\t\t\t\t});\n\t\t\t\treturn { cancelled: false, selectedText };\n\t\t\t}\n\t\t\tif (!existsSync(currentSessionFile)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"This session has not been saved yet. Wait for the first assistant response before cloning or forking it.\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst sourceSessionManager = SessionManager.open(currentSessionFile, this.services.agentDir, sessionDir);\n\t\t\tconst sessionManager = sourceSessionManager.createBranchedSessionManager(targetLeafId);\n\t\t\tconst forkedSessionPath = sessionManager.getSessionFile();\n\t\t\tif (!forkedSessionPath) {\n\t\t\t\tthrow new Error(\"Failed to create forked session\");\n\t\t\t}\n\t\t\tlet prepared: CreateAgentSessionRuntimeResult;\n\t\t\ttry {\n\t\t\t\tprepared = await this.prepareReplacement(sessionManager, {\n\t\t\t\t\ttype: \"session_start\",\n\t\t\t\t\treason: \"fork\",\n\t\t\t\t\tpreviousSessionFile,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tthis.removeCreatedSessionFile(forkedSessionPath);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tawait this.commitReplacement(prepared, {\n\t\t\t\treason: \"fork\",\n\t\t\t\ttargetSessionFile: forkedSessionPath,\n\t\t\t\twithSession: options?.withSession,\n\t\t\t\tonDiscard: () => this.removeCreatedSessionFile(forkedSessionPath),\n\t\t\t});\n\t\t\treturn { cancelled: false, selectedText };\n\t\t}\n\n\t\tlet sessionManager: SessionManager;\n\t\tif (!targetLeafId) {\n\t\t\tsessionManager = SessionManager.inMemory(this.cwd);\n\t\t\tsessionManager.newSession({ parentSession: this.session.sessionFile });\n\t\t} else {\n\t\t\tsessionManager = this.session.sessionManager.createBranchedSessionManager(targetLeafId);\n\t\t}\n\t\tconst prepared = await this.prepareReplacement(sessionManager, {\n\t\t\ttype: \"session_start\",\n\t\t\treason: \"fork\",\n\t\t\tpreviousSessionFile,\n\t\t});\n\t\tawait this.commitReplacement(prepared, {\n\t\t\treason: \"fork\",\n\t\t\ttargetSessionFile: sessionManager.getSessionFile(),\n\t\t\twithSession: options?.withSession,\n\t\t});\n\t\treturn { cancelled: false, selectedText };\n\t}\n\n\t/**\n\t * Import a session JSONL file and switch runtime state to the imported session.\n\t *\n\t * @returns `{ cancelled: true }` when cancelled by `session_before_switch`, otherwise `{ cancelled: false }`.\n\t * @throws {SessionImportFileNotFoundError} When the input path does not exist.\n\t * @throws {MissingSessionCwdError} When the imported session cwd cannot be resolved and no override is provided.\n\t */\n\tasync importFromJsonl(inputPath: string, cwdOverride?: string): Promise<{ cancelled: boolean }> {\n\t\treturn this.runSessionReplacement(() => this.importFromJsonlUnserialized(inputPath, cwdOverride));\n\t}\n\n\tprivate async importFromJsonlUnserialized(inputPath: string, cwdOverride?: string): Promise<{ cancelled: boolean }> {\n\t\tconst resolvedPath = resolvePath(inputPath);\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tthrow new SessionImportFileNotFoundError(resolvedPath);\n\t\t}\n\n\t\tconst sessionDir = this.session.sessionManager.getSessionDir();\n\t\tconst destinationPath = join(sessionDir, basename(resolvedPath));\n\t\tconst beforeResult = await this.emitBeforeSwitch(\"resume\", destinationPath);\n\t\tif (beforeResult.cancelled) {\n\t\t\treturn beforeResult;\n\t\t}\n\n\t\tconst previousSessionFile = this.session.sessionFile;\n\t\tlet copied = false;\n\t\tif (resolve(destinationPath) !== resolvedPath) {\n\t\t\tif (!existsSync(sessionDir)) mkdirSync(sessionDir, { recursive: true });\n\t\t\tcopyFileSync(resolvedPath, destinationPath, fsConstants.COPYFILE_EXCL);\n\t\t\tcopied = true;\n\t\t}\n\n\t\tlet sessionManager: SessionManager;\n\t\tlet prepared: CreateAgentSessionRuntimeResult;\n\t\ttry {\n\t\t\tsessionManager = SessionManager.open(destinationPath, this.services.agentDir, sessionDir, cwdOverride);\n\t\t\tassertSessionCwdExists(sessionManager, this.cwd);\n\t\t\tprepared = await this.prepareReplacement(sessionManager, {\n\t\t\t\ttype: \"session_start\",\n\t\t\t\treason: \"resume\",\n\t\t\t\tpreviousSessionFile,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tif (copied) this.removeCreatedSessionFile(destinationPath);\n\t\t\tthrow error;\n\t\t}\n\t\tawait this.commitReplacement(prepared, {\n\t\t\treason: \"resume\",\n\t\t\ttargetSessionFile: sessionManager.getSessionFile(),\n\t\t\tonDiscard: copied ? () => this.removeCreatedSessionFile(destinationPath) : undefined,\n\t\t});\n\t\treturn { cancelled: false };\n\t}\n\n\tasync dispose(): Promise<void> {\n\t\tif (this._disposeInFlight) return this._disposeInFlight;\n\t\tif (this._disposed) return;\n\t\tthis._disposeStarted = true;\n\t\tconst replacement = this._replacementInFlight;\n\t\tconst disposal = (async () => {\n\t\t\tif (replacement) {\n\t\t\t\ttry {\n\t\t\t\t\tawait replacement;\n\t\t\t\t} catch {\n\t\t\t\t\t// Replacement already reports its own error; dispose whichever runtime it left active.\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst errors = await this.shutdownRuntime(this.session, \"quit\", undefined, {\n\t\t\t\tstopResources: true,\n\t\t\t\tinvalidateHost: true,\n\t\t\t\tprogress: this.disposeProgress,\n\t\t\t});\n\t\t\tif (errors.length === 1) throw errors[0];\n\t\t\tif (errors.length > 1) throw new AggregateError(errors, \"Session runtime disposal failed.\");\n\t\t\tthis._disposed = true;\n\t\t})();\n\t\tthis._disposeInFlight = disposal;\n\t\ttry {\n\t\t\tawait disposal;\n\t\t} finally {\n\t\t\tthis._disposeInFlight = undefined;\n\t\t}\n\t}\n}\n\n/**\n * Create the initial runtime from a runtime factory and initial session target.\n *\n * The same factory is stored on the returned AgentSessionRuntime and reused for\n * later /new, /resume, /fork, and import flows.\n */\nexport async function createAgentSessionRuntime(\n\tcreateRuntime: CreateAgentSessionRuntimeFactory,\n\toptions: {\n\t\tcwd: string;\n\t\tagentDir: string;\n\t\tsessionManager: SessionManager;\n\t\tsessionStartEvent?: SessionStartEvent;\n\t},\n): Promise<AgentSessionRuntime> {\n\tassertSessionCwdExists(options.sessionManager, options.cwd);\n\tconst result = await createRuntime(options);\n\treturn new AgentSessionRuntime(\n\t\tresult.session,\n\t\tresult.services,\n\t\tcreateRuntime,\n\t\tresult.diagnostics,\n\t\tresult.modelFallbackMessage,\n\t);\n}\n\nexport {\n\ttype AgentSessionRuntimeDiagnostic,\n\ttype AgentSessionServices,\n\ttype CreateAgentSessionFromServicesOptions,\n\ttype CreateAgentSessionServicesOptions,\n\tcreateAgentSessionFromServices,\n\tcreateAgentSessionServices,\n} from \"./agent-session-services.ts\";\n"]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { type Agent } from "@caupulican/pi-agent-core/agent";
|
|
2
|
+
import type { CompactionResult } from "@caupulican/pi-agent-core/compaction/compaction";
|
|
3
|
+
import { type CustomMessage } from "@caupulican/pi-agent-core/messages";
|
|
4
|
+
import { type StreamIdleOptions } from "@caupulican/pi-agent-core/reliability";
|
|
5
|
+
import type { BranchSummaryEntry, SessionManager } from "@caupulican/pi-agent-core/session";
|
|
6
|
+
import type { AgentMessage, AgentState, ThinkingLevel } from "@caupulican/pi-agent-core/types";
|
|
4
7
|
import type { Api, ImageContent, Model, TextContent, Usage } from "@caupulican/pi-ai";
|
|
5
8
|
import type { CapabilityEnvelope, EvidenceBundle, LearningDecision, WorkerClaim, WorkerRequest } from "./autonomy/contracts.ts";
|
|
6
9
|
import type { LaneRecord } from "./autonomy/lane-tracker.ts";
|
|
@@ -36,6 +39,7 @@ import type { OllamaRuntime, TransformersRuntime } from "./models/local-runtime.
|
|
|
36
39
|
import { type PromptTemplate } from "./prompt-templates.ts";
|
|
37
40
|
import type { ModelFitnessReport } from "./research/model-fitness.ts";
|
|
38
41
|
import type { ResourceLoader } from "./resource-loader.ts";
|
|
42
|
+
import type { CredentialManager } from "./secrets/credential-manager.ts";
|
|
39
43
|
import type { SettingsManager } from "./settings-manager.ts";
|
|
40
44
|
import { type TaskStepsState } from "./tasks/task-state.ts";
|
|
41
45
|
import { type ToolProbeReport } from "./tool-protocol-controller.ts";
|
|
@@ -96,7 +100,7 @@ export declare class AgentSession {
|
|
|
96
100
|
/** Autonomy telemetry sink + status/diagnostic snapshots (see autonomy-telemetry.ts); owns
|
|
97
101
|
* the latest gate outcome and the bounded gate-outcome history. */
|
|
98
102
|
private readonly _autonomyTelemetry;
|
|
99
|
-
/** Goal auto-continue + research lane +
|
|
103
|
+
/** Goal auto-continue + research lane + recursive worker-agent orchestration + model-fitness probe (see
|
|
100
104
|
* background-lane-controller.ts); owns the lane timers/guards, the last research-lane skip
|
|
101
105
|
* reason, the live LaneTracker, and the in-flight research/worker abort controllers. */
|
|
102
106
|
private readonly _backgroundLanes;
|
|
@@ -931,7 +935,7 @@ export declare class AgentSession {
|
|
|
931
935
|
goalId?: string;
|
|
932
936
|
}): Promise<ResearchLaneRunOutcome>;
|
|
933
937
|
/**
|
|
934
|
-
* Run one
|
|
938
|
+
* Run one durable worker-agent turn. Delegates to {@link BackgroundLaneController};
|
|
935
939
|
* consumed by the `delegate` tool.
|
|
936
940
|
*/
|
|
937
941
|
runWorkerDelegationOnce(request: WorkerDelegationRequest): Promise<WorkerDelegationRunOutcome>;
|
|
@@ -1008,5 +1012,7 @@ export declare class AgentSession {
|
|
|
1008
1012
|
* Get the extension runner (for setting UI context and error handlers).
|
|
1009
1013
|
*/
|
|
1010
1014
|
get extensionRunner(): ExtensionRunner;
|
|
1015
|
+
/** Owner control-plane access for the native /secrets TUI. Never exposed as an agent tool. */
|
|
1016
|
+
get credentialManager(): CredentialManager;
|
|
1011
1017
|
}
|
|
1012
1018
|
//# sourceMappingURL=agent-session.d.ts.map
|