@caupulican/pi-adaptative 0.81.39 → 0.81.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/README.md +2 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts +2 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js +2 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.ts +3 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts +9 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +290 -107
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +357 -122
- package/dist/bundled-resources/skills/tool-call-repair/references/repair-catalogue.md +2 -2
- package/dist/cli/args.d.ts +2 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +9 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-directory-layout.d.ts +15 -0
- package/dist/core/agent-directory-layout.d.ts.map +1 -0
- package/dist/core/agent-directory-layout.js +72 -0
- package/dist/core/agent-directory-layout.js.map +1 -0
- package/dist/core/agent-paths.d.ts +19 -2
- package/dist/core/agent-paths.d.ts.map +1 -1
- package/dist/core/agent-paths.js +67 -4
- package/dist/core/agent-paths.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +52 -8
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +397 -79
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +1 -0
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +1 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +71 -136
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +477 -1318
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/approval-gate.d.ts +3 -2
- package/dist/core/autonomy/approval-gate.d.ts.map +1 -1
- package/dist/core/autonomy/approval-gate.js +6 -28
- package/dist/core/autonomy/approval-gate.js.map +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
- package/dist/core/autonomy/bounded-completion.js +1 -1
- package/dist/core/autonomy/bounded-completion.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts +20 -12
- package/dist/core/autonomy/contracts.d.ts.map +1 -1
- package/dist/core/autonomy/contracts.js.map +1 -1
- package/dist/core/autonomy/foreground-envelope.d.ts +8 -2
- package/dist/core/autonomy/foreground-envelope.d.ts.map +1 -1
- package/dist/core/autonomy/foreground-envelope.js +8 -25
- package/dist/core/autonomy/foreground-envelope.js.map +1 -1
- package/dist/core/autonomy/gates.d.ts.map +1 -1
- package/dist/core/autonomy/gates.js +8 -10
- package/dist/core/autonomy/gates.js.map +1 -1
- package/dist/core/autonomy/lane-private-paths.d.ts +2 -0
- package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -0
- package/dist/core/autonomy/lane-private-paths.js +16 -0
- package/dist/core/autonomy/lane-private-paths.js.map +1 -0
- package/dist/core/autonomy/lane-tool-surface.d.ts +10 -0
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +46 -8
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/autonomy/lane-tracker.d.ts +14 -0
- package/dist/core/autonomy/lane-tracker.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tracker.js +38 -0
- package/dist/core/autonomy/lane-tracker.js.map +1 -1
- package/dist/core/autonomy/risk-assessment.d.ts +1 -2
- package/dist/core/autonomy/risk-assessment.d.ts.map +1 -1
- package/dist/core/autonomy/risk-assessment.js +1 -123
- package/dist/core/autonomy/risk-assessment.js.map +1 -1
- package/dist/core/autonomy/session-lane-record.d.ts +4 -4
- package/dist/core/autonomy/session-lane-record.d.ts.map +1 -1
- package/dist/core/autonomy/session-lane-record.js +16 -29
- package/dist/core/autonomy/session-lane-record.js.map +1 -1
- package/dist/core/autonomy/telemetry-events.d.ts +1 -1
- package/dist/core/autonomy/telemetry-events.d.ts.map +1 -1
- package/dist/core/autonomy/telemetry-events.js +1 -1
- package/dist/core/autonomy/telemetry-events.js.map +1 -1
- package/dist/core/autonomy-telemetry.d.ts +7 -7
- package/dist/core/autonomy-telemetry.d.ts.map +1 -1
- package/dist/core/autonomy-telemetry.js +9 -9
- package/dist/core/autonomy-telemetry.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +54 -236
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +140 -1273
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/capability-contract.d.ts +4 -0
- package/dist/core/capability-contract.d.ts.map +1 -0
- package/dist/core/capability-contract.js +28 -0
- package/dist/core/capability-contract.js.map +1 -0
- package/dist/core/compaction-controller.d.ts +90 -0
- package/dist/core/compaction-controller.d.ts.map +1 -0
- package/dist/core/compaction-controller.js +452 -0
- package/dist/core/compaction-controller.js.map +1 -0
- package/dist/core/compaction-support.d.ts +12 -11
- package/dist/core/compaction-support.d.ts.map +1 -1
- package/dist/core/compaction-support.js.map +1 -1
- package/dist/core/context/context-artifacts.d.ts +6 -2
- package/dist/core/context/context-artifacts.d.ts.map +1 -1
- package/dist/core/context/context-artifacts.js +34 -2
- package/dist/core/context/context-artifacts.js.map +1 -1
- package/dist/core/context/context-store-retention.d.ts +8 -2
- package/dist/core/context/context-store-retention.d.ts.map +1 -1
- package/dist/core/context/context-store-retention.js +158 -35
- package/dist/core/context/context-store-retention.js.map +1 -1
- package/dist/core/context/okf-memory.d.ts.map +1 -1
- package/dist/core/context/okf-memory.js +9 -11
- package/dist/core/context/okf-memory.js.map +1 -1
- package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -1
- package/dist/core/context/sqlite-runtime-index.js +6 -8
- package/dist/core/context/sqlite-runtime-index.js.map +1 -1
- package/dist/core/context-gc.d.ts +3 -0
- package/dist/core/context-gc.d.ts.map +1 -1
- package/dist/core/context-gc.js +10 -5
- package/dist/core/context-gc.js.map +1 -1
- package/dist/core/context-pipeline.d.ts.map +1 -1
- package/dist/core/context-pipeline.js +9 -4
- package/dist/core/context-pipeline.js.map +1 -1
- package/dist/core/default-tool-surface.d.ts.map +1 -1
- package/dist/core/default-tool-surface.js +1 -0
- package/dist/core/default-tool-surface.js.map +1 -1
- package/dist/core/delegation/managed-lane-controller.d.ts +34 -0
- package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -0
- package/dist/core/delegation/managed-lane-controller.js +217 -0
- package/dist/core/delegation/managed-lane-controller.js.map +1 -0
- package/dist/core/delegation/session-worker-claim.d.ts +44 -0
- package/dist/core/delegation/session-worker-claim.d.ts.map +1 -0
- package/dist/core/delegation/session-worker-claim.js +98 -0
- package/dist/core/delegation/session-worker-claim.js.map +1 -0
- package/dist/core/delegation/worker-actions.d.ts +7 -5
- package/dist/core/delegation/worker-actions.d.ts.map +1 -1
- package/dist/core/delegation/worker-actions.js +20 -4
- package/dist/core/delegation/worker-actions.js.map +1 -1
- package/dist/core/delegation/{worker-result.d.ts → worker-claim.d.ts} +13 -13
- package/dist/core/delegation/worker-claim.d.ts.map +1 -0
- package/dist/core/delegation/{worker-result.js → worker-claim.js} +61 -51
- package/dist/core/delegation/worker-claim.js.map +1 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts +110 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -0
- package/dist/core/delegation/worker-delegation-controller.js +861 -0
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -0
- package/dist/core/delegation/worker-delegation-request.d.ts +11 -0
- package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -0
- package/dist/core/delegation/worker-delegation-request.js +2 -0
- package/dist/core/delegation/worker-delegation-request.js.map +1 -0
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts +40 -0
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -0
- package/dist/core/delegation/worker-dispatch-scheduler.js +93 -0
- package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -0
- package/dist/core/delegation/worker-execution-policy.d.ts +62 -0
- package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -0
- package/dist/core/delegation/worker-execution-policy.js +160 -0
- package/dist/core/delegation/worker-execution-policy.js.map +1 -0
- package/dist/core/delegation/worker-lane-projection.d.ts +14 -0
- package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -0
- package/dist/core/delegation/worker-lane-projection.js +100 -0
- package/dist/core/delegation/worker-lane-projection.js.map +1 -0
- package/dist/core/delegation/worker-lifecycle.d.ts +97 -0
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -0
- package/dist/core/delegation/worker-lifecycle.js +339 -0
- package/dist/core/delegation/worker-lifecycle.js.map +1 -0
- package/dist/core/delegation/worker-notification-coordinator.d.ts +36 -0
- package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-notification-coordinator.js +90 -0
- package/dist/core/delegation/worker-notification-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts +55 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -0
- package/dist/core/delegation/worker-profile-resolver.js +113 -0
- package/dist/core/delegation/worker-profile-resolver.js.map +1 -0
- package/dist/core/delegation/worker-runner.d.ts +25 -14
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +122 -53
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-task-label.d.ts +3 -0
- package/dist/core/delegation/worker-task-label.d.ts.map +1 -0
- package/dist/core/delegation/worker-task-label.js +11 -0
- package/dist/core/delegation/worker-task-label.js.map +1 -0
- package/dist/core/doctor.d.ts +8 -0
- package/dist/core/doctor.d.ts.map +1 -1
- package/dist/core/doctor.js +32 -1
- package/dist/core/doctor.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +5 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +50 -15
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +6 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/storage.d.ts +8 -0
- package/dist/core/extensions/storage.d.ts.map +1 -0
- package/dist/core/extensions/storage.js +28 -0
- package/dist/core/extensions/storage.js.map +1 -0
- package/dist/core/extensions/types.d.ts +70 -21
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/failure-corpus.d.ts +1 -15
- package/dist/core/failure-corpus.d.ts.map +1 -1
- package/dist/core/failure-corpus.js +9 -37
- package/dist/core/failure-corpus.js.map +1 -1
- package/dist/core/foreground-recovery-controller.d.ts +52 -0
- package/dist/core/foreground-recovery-controller.d.ts.map +1 -0
- package/dist/core/foreground-recovery-controller.js +111 -0
- package/dist/core/foreground-recovery-controller.js.map +1 -0
- package/dist/core/gateways/channel-provider.d.ts +3 -0
- package/dist/core/gateways/channel-provider.d.ts.map +1 -1
- package/dist/core/gateways/channel-provider.js +31 -6
- package/dist/core/gateways/channel-provider.js.map +1 -1
- package/dist/core/goals/goal-acceptance.d.ts +11 -0
- package/dist/core/goals/goal-acceptance.d.ts.map +1 -0
- package/dist/core/goals/goal-acceptance.js +25 -0
- package/dist/core/goals/goal-acceptance.js.map +1 -0
- package/dist/core/goals/goal-auto-continue-controller.d.ts +27 -0
- package/dist/core/goals/goal-auto-continue-controller.d.ts.map +1 -0
- package/dist/core/goals/goal-auto-continue-controller.js +93 -0
- package/dist/core/goals/goal-auto-continue-controller.js.map +1 -0
- package/dist/core/goals/goal-continuation-controller.d.ts +1 -1
- package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-controller.js +10 -0
- package/dist/core/goals/goal-continuation-controller.js.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.d.ts +1 -1
- package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.js +6 -6
- package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
- package/dist/core/goals/goal-lifecycle.d.ts +20 -0
- package/dist/core/goals/goal-lifecycle.d.ts.map +1 -0
- package/dist/core/goals/goal-lifecycle.js +17 -0
- package/dist/core/goals/goal-lifecycle.js.map +1 -0
- package/dist/core/goals/goal-runtime-snapshot.d.ts +11 -9
- package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -1
- package/dist/core/goals/goal-runtime-snapshot.js +10 -8
- package/dist/core/goals/goal-runtime-snapshot.js.map +1 -1
- package/dist/core/goals/goal-state.d.ts +1 -0
- package/dist/core/goals/goal-state.d.ts.map +1 -1
- package/dist/core/goals/goal-state.js +7 -10
- package/dist/core/goals/goal-state.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts +8 -6
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js +11 -41
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/goals/session-goal-state.d.ts +2 -4
- package/dist/core/goals/session-goal-state.d.ts.map +1 -1
- package/dist/core/goals/session-goal-state.js +10 -33
- package/dist/core/goals/session-goal-state.js.map +1 -1
- package/dist/core/human-input.d.ts +100 -0
- package/dist/core/human-input.d.ts.map +1 -0
- package/dist/core/human-input.js +362 -0
- package/dist/core/human-input.js.map +1 -0
- package/dist/core/index.d.ts +9 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +9 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/{telemetry.d.ts → install-telemetry.d.ts} +1 -1
- package/dist/core/install-telemetry.d.ts.map +1 -0
- package/dist/core/{telemetry.js → install-telemetry.js} +1 -1
- package/dist/core/install-telemetry.js.map +1 -0
- package/dist/core/keybindings.d.ts +17 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +24 -6
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/learning/learning-audit.d.ts +2 -4
- package/dist/core/learning/learning-audit.d.ts.map +1 -1
- package/dist/core/learning/learning-audit.js +9 -29
- package/dist/core/learning/learning-audit.js.map +1 -1
- package/dist/core/learning/learning-gate.d.ts.map +1 -1
- package/dist/core/learning/learning-gate.js +1 -6
- package/dist/core/learning/learning-gate.js.map +1 -1
- package/dist/core/learning/session-learning-decision.d.ts +2 -4
- package/dist/core/learning/session-learning-decision.d.ts.map +1 -1
- package/dist/core/learning/session-learning-decision.js +9 -29
- package/dist/core/learning/session-learning-decision.js.map +1 -1
- package/dist/core/memory-controller.d.ts.map +1 -1
- package/dist/core/memory-controller.js +4 -4
- package/dist/core/memory-controller.js.map +1 -1
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js +1 -0
- package/dist/core/model-capability.js.map +1 -1
- package/dist/core/model-resolver.d.ts +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +6 -9
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/model-router/intent-classifier.d.ts +1 -4
- package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
- package/dist/core/model-router/intent-classifier.js +1 -156
- package/dist/core/model-router/intent-classifier.js.map +1 -1
- package/dist/core/model-router-controller.d.ts.map +1 -1
- package/dist/core/model-router-controller.js +2 -2
- package/dist/core/model-router-controller.js.map +1 -1
- package/dist/core/model-selection-controller.d.ts +4 -4
- package/dist/core/model-selection-controller.d.ts.map +1 -1
- package/dist/core/model-selection-controller.js.map +1 -1
- package/dist/core/model-tool-protocol.d.ts +23 -0
- package/dist/core/model-tool-protocol.d.ts.map +1 -0
- package/dist/core/model-tool-protocol.js +43 -0
- package/dist/core/model-tool-protocol.js.map +1 -0
- package/dist/core/models/adaptation-store.d.ts +4 -6
- package/dist/core/models/adaptation-store.d.ts.map +1 -1
- package/dist/core/models/adaptation-store.js +95 -83
- package/dist/core/models/adaptation-store.js.map +1 -1
- package/dist/core/models/fitness-store.d.ts +2 -12
- package/dist/core/models/fitness-store.d.ts.map +1 -1
- package/dist/core/models/fitness-store.js +84 -57
- package/dist/core/models/fitness-store.js.map +1 -1
- package/dist/core/models/host-state-store.d.ts +34 -0
- package/dist/core/models/host-state-store.d.ts.map +1 -0
- package/dist/core/models/host-state-store.js +86 -0
- package/dist/core/models/host-state-store.js.map +1 -0
- package/dist/core/orchestration/agent-resume.d.ts +24 -0
- package/dist/core/orchestration/agent-resume.d.ts.map +1 -0
- package/dist/core/orchestration/agent-resume.js +90 -0
- package/dist/core/orchestration/agent-resume.js.map +1 -0
- package/dist/core/orchestration/capability-gateway.d.ts +61 -0
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -0
- package/dist/core/orchestration/capability-gateway.js +152 -0
- package/dist/core/orchestration/capability-gateway.js.map +1 -0
- package/dist/core/orchestration/contracts.d.ts +343 -0
- package/dist/core/orchestration/contracts.d.ts.map +1 -0
- package/dist/core/orchestration/contracts.js +135 -0
- package/dist/core/orchestration/contracts.js.map +1 -0
- package/dist/core/orchestration/delegation-ledger.d.ts +56 -0
- package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -0
- package/dist/core/orchestration/delegation-ledger.js +197 -0
- package/dist/core/orchestration/delegation-ledger.js.map +1 -0
- package/dist/core/orchestration/event-store.d.ts +83 -0
- package/dist/core/orchestration/event-store.d.ts.map +1 -0
- package/dist/core/orchestration/event-store.js +560 -0
- package/dist/core/orchestration/event-store.js.map +1 -0
- package/dist/core/orchestration/lane-tool-manifests.d.ts +9 -0
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -0
- package/dist/core/orchestration/lane-tool-manifests.js +37 -0
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -0
- package/dist/core/orchestration/model-binding.d.ts +15 -0
- package/dist/core/orchestration/model-binding.d.ts.map +1 -0
- package/dist/core/orchestration/model-binding.js +29 -0
- package/dist/core/orchestration/model-binding.js.map +1 -0
- package/dist/core/orchestration/policy-compiler.d.ts +49 -0
- package/dist/core/orchestration/policy-compiler.d.ts.map +1 -0
- package/dist/core/orchestration/policy-compiler.js +191 -0
- package/dist/core/orchestration/policy-compiler.js.map +1 -0
- package/dist/core/orchestration/policy-gate.d.ts +18 -0
- package/dist/core/orchestration/policy-gate.d.ts.map +1 -0
- package/dist/core/orchestration/policy-gate.js +24 -0
- package/dist/core/orchestration/policy-gate.js.map +1 -0
- package/dist/core/orchestration/profile-registry.d.ts +51 -0
- package/dist/core/orchestration/profile-registry.d.ts.map +1 -0
- package/dist/core/orchestration/profile-registry.js +393 -0
- package/dist/core/orchestration/profile-registry.js.map +1 -0
- package/dist/core/orchestration/profile-store.d.ts +31 -0
- package/dist/core/orchestration/profile-store.d.ts.map +1 -0
- package/dist/core/orchestration/profile-store.js +136 -0
- package/dist/core/orchestration/profile-store.js.map +1 -0
- package/dist/core/orchestration/risk-budget.d.ts +9 -0
- package/dist/core/orchestration/risk-budget.d.ts.map +1 -0
- package/dist/core/orchestration/risk-budget.js +48 -0
- package/dist/core/orchestration/risk-budget.js.map +1 -0
- package/dist/core/orchestration/task-runtime.d.ts +168 -0
- package/dist/core/orchestration/task-runtime.d.ts.map +1 -0
- package/dist/core/orchestration/task-runtime.js +1600 -0
- package/dist/core/orchestration/task-runtime.js.map +1 -0
- package/dist/core/orchestration/work-state-projection.d.ts +32 -0
- package/dist/core/orchestration/work-state-projection.d.ts.map +1 -0
- package/dist/core/orchestration/work-state-projection.js +116 -0
- package/dist/core/orchestration/work-state-projection.js.map +1 -0
- package/dist/core/orchestration/worker-execution-contract.d.ts +21 -0
- package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -0
- package/dist/core/orchestration/worker-execution-contract.js +179 -0
- package/dist/core/orchestration/worker-execution-contract.js.map +1 -0
- package/dist/core/orchestration/worker-result-adapter.d.ts +21 -0
- package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -0
- package/dist/core/orchestration/worker-result-adapter.js +109 -0
- package/dist/core/orchestration/worker-result-adapter.js.map +1 -0
- package/dist/core/process-identity.d.ts +11 -0
- package/dist/core/process-identity.d.ts.map +1 -0
- package/dist/core/process-identity.js +26 -0
- package/dist/core/process-identity.js.map +1 -0
- package/dist/core/process-matrix/codes.d.ts +14 -3
- package/dist/core/process-matrix/codes.d.ts.map +1 -1
- package/dist/core/process-matrix/codes.js.map +1 -1
- package/dist/core/process-matrix/resume-launcher.d.ts +26 -0
- package/dist/core/process-matrix/resume-launcher.d.ts.map +1 -0
- package/dist/core/process-matrix/resume-launcher.js +62 -0
- package/dist/core/process-matrix/resume-launcher.js.map +1 -0
- package/dist/core/process-matrix/runtime.d.ts +37 -22
- package/dist/core/process-matrix/runtime.d.ts.map +1 -1
- package/dist/core/process-matrix/runtime.js +399 -76
- package/dist/core/process-matrix/runtime.js.map +1 -1
- package/dist/core/process-matrix/store.d.ts +5 -2
- package/dist/core/process-matrix/store.d.ts.map +1 -1
- package/dist/core/process-matrix/store.js +123 -14
- package/dist/core/process-matrix/store.js.map +1 -1
- package/dist/core/process-matrix/supervisor.d.ts +10 -7
- package/dist/core/process-matrix/supervisor.d.ts.map +1 -1
- package/dist/core/process-matrix/supervisor.js +45 -14
- package/dist/core/process-matrix/supervisor.js.map +1 -1
- package/dist/core/profile-registry.d.ts.map +1 -1
- package/dist/core/profile-registry.js +6 -8
- package/dist/core/profile-registry.js.map +1 -1
- package/dist/core/reflection-controller.d.ts +4 -4
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +2 -1
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/reload-blockers.d.ts.map +1 -1
- package/dist/core/reload-blockers.js +6 -8
- package/dist/core/reload-blockers.js.map +1 -1
- package/dist/core/research/evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/evidence-bundle.js +1 -6
- package/dist/core/research/evidence-bundle.js.map +1 -1
- package/dist/core/research/lane-model-resolver.d.ts +33 -0
- package/dist/core/research/lane-model-resolver.d.ts.map +1 -0
- package/dist/core/research/lane-model-resolver.js +65 -0
- package/dist/core/research/lane-model-resolver.js.map +1 -0
- package/dist/core/research/model-fitness-controller.d.ts +38 -0
- package/dist/core/research/model-fitness-controller.d.ts.map +1 -0
- package/dist/core/research/model-fitness-controller.js +106 -0
- package/dist/core/research/model-fitness-controller.js.map +1 -0
- package/dist/core/research/model-fitness.d.ts +1 -1
- package/dist/core/research/model-fitness.d.ts.map +1 -1
- package/dist/core/research/model-fitness.js +4 -4
- package/dist/core/research/model-fitness.js.map +1 -1
- package/dist/core/research/research-gate.d.ts.map +1 -1
- package/dist/core/research/research-gate.js +7 -7
- package/dist/core/research/research-gate.js.map +1 -1
- package/dist/core/research/research-lane-controller.d.ts +62 -0
- package/dist/core/research/research-lane-controller.d.ts.map +1 -0
- package/dist/core/research/research-lane-controller.js +292 -0
- package/dist/core/research/research-lane-controller.js.map +1 -0
- package/dist/core/research/session-evidence-bundle.d.ts +2 -4
- package/dist/core/research/session-evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/session-evidence-bundle.js +10 -46
- package/dist/core/research/session-evidence-bundle.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +7 -2
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/risk-classifier.d.ts +6 -0
- package/dist/core/risk-classifier.d.ts.map +1 -0
- package/dist/core/risk-classifier.js +225 -0
- package/dist/core/risk-classifier.js.map +1 -0
- package/dist/core/runtime-builder.d.ts +26 -20
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +237 -178
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/sdk.d.ts +6 -3
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +61 -24
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-analytics.d.ts.map +1 -1
- package/dist/core/session-analytics.js +28 -1
- package/dist/core/session-analytics.js.map +1 -1
- package/dist/core/session-image-store.d.ts +33 -0
- package/dist/core/session-image-store.d.ts.map +1 -0
- package/dist/core/session-image-store.js +283 -0
- package/dist/core/session-image-store.js.map +1 -0
- package/dist/core/session-role.d.ts +6 -4
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +10 -4
- package/dist/core/session-role.js.map +1 -1
- package/dist/core/session-snapshot.d.ts +34 -0
- package/dist/core/session-snapshot.d.ts.map +1 -0
- package/dist/core/session-snapshot.js +68 -0
- package/dist/core/session-snapshot.js.map +1 -0
- package/dist/core/session-supervision-runtime.d.ts +31 -0
- package/dist/core/session-supervision-runtime.d.ts.map +1 -0
- package/dist/core/session-supervision-runtime.js +97 -0
- package/dist/core/session-supervision-runtime.js.map +1 -0
- package/dist/core/settings-manager.d.ts +9 -4
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +80 -28
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tasks/session-task-state.d.ts +2 -4
- package/dist/core/tasks/session-task-state.d.ts.map +1 -1
- package/dist/core/tasks/session-task-state.js +10 -28
- package/dist/core/tasks/session-task-state.js.map +1 -1
- package/dist/core/tasks/task-projection.d.ts +20 -0
- package/dist/core/tasks/task-projection.d.ts.map +1 -0
- package/dist/core/tasks/task-projection.js +47 -0
- package/dist/core/tasks/task-projection.js.map +1 -0
- package/dist/core/tasks/task-state.d.ts +4 -0
- package/dist/core/tasks/task-state.d.ts.map +1 -1
- package/dist/core/tasks/task-state.js +28 -11
- package/dist/core/tasks/task-state.js.map +1 -1
- package/dist/core/tool-capability-policy.d.ts +13 -0
- package/dist/core/tool-capability-policy.d.ts.map +1 -0
- package/dist/core/tool-capability-policy.js +85 -0
- package/dist/core/tool-capability-policy.js.map +1 -0
- package/dist/core/tool-protocol-controller.d.ts +91 -0
- package/dist/core/tool-protocol-controller.d.ts.map +1 -0
- package/dist/core/tool-protocol-controller.js +512 -0
- package/dist/core/tool-protocol-controller.js.map +1 -0
- package/dist/core/tool-recovery-log-records.d.ts +2 -3
- package/dist/core/tool-recovery-log-records.d.ts.map +1 -1
- package/dist/core/tool-recovery-log-records.js +9 -35
- package/dist/core/tool-recovery-log-records.js.map +1 -1
- package/dist/core/tool-selection/tool-performance-store.d.ts +3 -7
- package/dist/core/tool-selection/tool-performance-store.d.ts.map +1 -1
- package/dist/core/tool-selection/tool-performance-store.js +97 -138
- package/dist/core/tool-selection/tool-performance-store.js.map +1 -1
- package/dist/core/tools/ask-question.d.ts +124 -0
- package/dist/core/tools/ask-question.d.ts.map +1 -0
- package/dist/core/tools/ask-question.js +693 -0
- package/dist/core/tools/ask-question.js.map +1 -0
- package/dist/core/tools/delegate-status.d.ts +31 -3
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +149 -29
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +15 -13
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +108 -23
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/extensionify.d.ts.map +1 -1
- package/dist/core/tools/extensionify.js +1 -0
- package/dist/core/tools/extensionify.js.map +1 -1
- package/dist/core/tools/goal.d.ts +5 -5
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +10 -10
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/model-fitness.d.ts.map +1 -1
- package/dist/core/tools/model-fitness.js +2 -2
- package/dist/core/tools/model-fitness.js.map +1 -1
- package/dist/core/tools/orchestration-panel.d.ts +43 -0
- package/dist/core/tools/orchestration-panel.d.ts.map +1 -0
- package/dist/core/tools/orchestration-panel.js +168 -0
- package/dist/core/tools/orchestration-panel.js.map +1 -0
- package/dist/core/tools/run-process.d.ts +26 -0
- package/dist/core/tools/run-process.d.ts.map +1 -0
- package/dist/core/tools/run-process.js +138 -0
- package/dist/core/tools/run-process.js.map +1 -0
- package/dist/core/tools/task-steps.d.ts +2 -0
- package/dist/core/tools/task-steps.d.ts.map +1 -1
- package/dist/core/tools/task-steps.js +102 -0
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/tools/tmux-dispatch.d.ts +3 -5
- package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
- package/dist/core/tools/tmux-dispatch.js +4 -4
- package/dist/core/tools/tmux-dispatch.js.map +1 -1
- package/dist/core/tools/windows-shell-engine.d.ts.map +1 -1
- package/dist/core/tools/windows-shell-engine.js +4 -6
- package/dist/core/tools/windows-shell-engine.js.map +1 -1
- package/dist/core/util/bounded-jsonl.d.ts +10 -0
- package/dist/core/util/bounded-jsonl.d.ts.map +1 -0
- package/dist/core/util/bounded-jsonl.js +75 -0
- package/dist/core/util/bounded-jsonl.js.map +1 -0
- package/dist/core/util/value-guards.d.ts +5 -0
- package/dist/core/util/value-guards.d.ts.map +1 -0
- package/dist/core/util/value-guards.js +12 -0
- package/dist/core/util/value-guards.js.map +1 -0
- package/dist/core/worktree-sync/store.d.ts +3 -3
- package/dist/core/worktree-sync/store.d.ts.map +1 -1
- package/dist/core/worktree-sync/store.js +10 -5
- package/dist/core/worktree-sync/store.js.map +1 -1
- package/dist/index.d.ts +13 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +128 -44
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts +4 -6
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +186 -28
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/clipboard-input.d.ts +7 -1
- package/dist/modes/interactive/clipboard-input.d.ts.map +1 -1
- package/dist/modes/interactive/clipboard-input.js +44 -6
- package/dist/modes/interactive/clipboard-input.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +2 -2
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/config-backup.d.ts.map +1 -1
- package/dist/modes/interactive/config-backup.js +5 -4
- package/dist/modes/interactive/config-backup.js.map +1 -1
- package/dist/modes/interactive/extension-ui-host.d.ts +14 -0
- package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
- package/dist/modes/interactive/extension-ui-host.js +76 -15
- package/dist/modes/interactive/extension-ui-host.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +3 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +63 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
- package/dist/modes/interactive/key-handlers.js +1 -1
- package/dist/modes/interactive/key-handlers.js.map +1 -1
- package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -1
- package/dist/modes/interactive/profile-menu-controller.js +7 -7
- package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
- package/dist/modes/interactive/report-commands.d.ts.map +1 -1
- package/dist/modes/interactive/report-commands.js +21 -0
- package/dist/modes/interactive/report-commands.js.map +1 -1
- package/dist/modes/interactive/session-flow-commands.d.ts +17 -2
- package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +50 -17
- package/dist/modes/interactive/session-flow-commands.js.map +1 -1
- package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-io-commands.js +16 -6
- package/dist/modes/interactive/session-io-commands.js.map +1 -1
- package/dist/modes/interactive/session-replacement-errors.d.ts +7 -0
- package/dist/modes/interactive/session-replacement-errors.d.ts.map +1 -0
- package/dist/modes/interactive/session-replacement-errors.js +15 -0
- package/dist/modes/interactive/session-replacement-errors.js.map +1 -0
- package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
- package/dist/modes/interactive/startup-checks.js +1 -1
- package/dist/modes/interactive/startup-checks.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +82 -23
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +15 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js +138 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +2 -13
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard-native.d.ts +1 -0
- package/dist/utils/clipboard-native.d.ts.map +1 -1
- package/dist/utils/clipboard-native.js.map +1 -1
- package/dist/utils/clipboard.d.ts +1 -0
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +52 -1
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/platform.d.ts +3 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +8 -0
- package/dist/utils/platform.js.map +1 -0
- package/dist/utils/work-directory.d.ts +11 -0
- package/dist/utils/work-directory.d.ts.map +1 -1
- package/dist/utils/work-directory.js +30 -9
- package/dist/utils/work-directory.js.map +1 -1
- package/docs/UI_POLISH_ORCHESTRATION.md +44 -0
- package/docs/UI_QUALITY_ORCHESTRATION.md +30 -0
- package/docs/docs.json +4 -0
- package/docs/extensions.md +62 -2
- package/docs/harness-architecture.md +156 -0
- package/docs/keybindings.md +11 -1
- package/docs/process-matrix.md +59 -26
- package/docs/rpc.md +45 -2
- package/docs/sessions.md +15 -0
- package/docs/settings.md +125 -11
- package/docs/task-steps.md +8 -0
- package/docs/telemetry.md +19 -0
- package/docs/tmux-agent-manager.md +10 -3
- package/docs/ui-reference/README.md +9 -0
- package/docs/ui-reference/orchestration-after.txt +7 -0
- package/docs/ui-reference/orchestration-before.txt +7 -0
- package/docs/ui-reference/orchestration-reference.txt +6 -0
- package/docs/usage.md +14 -2
- package/docs/work-directory.md +19 -8
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/question.ts +34 -245
- package/examples/extensions/questionnaire.ts +41 -407
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
- package/dist/core/delegation/session-worker-result.d.ts +0 -46
- package/dist/core/delegation/session-worker-result.d.ts.map +0 -1
- package/dist/core/delegation/session-worker-result.js +0 -113
- package/dist/core/delegation/session-worker-result.js.map +0 -1
- package/dist/core/delegation/worker-result.d.ts.map +0 -1
- package/dist/core/delegation/worker-result.js.map +0 -1
- package/dist/core/telemetry.d.ts.map +0 -1
- package/dist/core/telemetry.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-handlers.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/key-handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE,MAAM,W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,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,mBAAmB,IAAI,IAAI,CAAC;IAC5B,yBAAyB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAoE5D","sourcesContent":["/**\n * Editor/global key-handler wiring extracted from interactive-mode.\n *\n * `setupKeyHandlers` installs the escape/action/ctrl-D/change/paste/recall\n * callbacks on the default editor (and the global debug handler on the TUI),\n * each delegating to a host method or toggling the bash-mode/last-escape state.\n * It runs once at init through a wide `KeyHandlersHost` seam; interactive-mode\n * keeps a thin wrapper.\n */\n\nimport type { EditorComponent, TUI } from \"@caupulican/pi-tui\";\nimport type { AgentSession } from \"../../core/agent-session.ts\";\nimport type { SettingsManager } from \"../../core/settings-manager.ts\";\nimport type { CustomEditor } from \"./components/custom-editor.ts\";\n\nexport interface KeyHandlersHost {\n\treadonly defaultEditor: CustomEditor;\n\treadonly editor: EditorComponent;\n\treadonly ui: TUI;\n\treadonly session: Pick<AgentSession, \"isStreaming\" | \"isBashRunning\" | \"abortBash\">;\n\treadonly settingsManager: Pick<SettingsManager, \"getDoubleEscapeAction\">;\n\tisBashMode: boolean;\n\tlastEscapeTime: number;\n\trestoreQueuedMessagesToEditor(options?: { abort?: boolean; currentText?: string }): number;\n\tupdateEditorBorderColor(): void;\n\tshowTreeSelector(initialSelectedId?: string): void;\n\tshowUserMessageSelector(newSessionName?: string): void;\n\thandleCtrlC(): void;\n\thandleCtrlD(): void;\n\thandleCtrlZ(): void;\n\tcycleThinkingLevel(): void;\n\tcycleModel(direction: \"forward\" | \"backward\"): Promise<void>;\n\thandleDebugCommand(): void;\n\tshowModelSelector(initialSearchInput?: string): Promise<void>;\n\tloadTuiHistoryOnDemand(): void;\n\ttoggleThinkingBlockVisibility(): Promise<void>;\n\topenExternalEditor(): Promise<void>;\n\thandleFollowUp(): Promise<void>;\n\thandleDequeue(): void;\n\thandleClearCommand(newSessionName?: string): Promise<void>;\n\tshowSessionSelector(): void;\n\thandleClipboardImagePaste(): Promise<void>;\n}\n\nexport function setupKeyHandlers(host: KeyHandlersHost): void {\n\t// Set up handlers on defaultEditor - they use host.editor for text access\n\t// so they work correctly regardless of which editor is active\n\thost.defaultEditor.onEscape = () => {\n\t\tif (host.session.isStreaming) {\n\t\t\thost.restoreQueuedMessagesToEditor({ abort: true });\n\t\t} else if (host.session.isBashRunning) {\n\t\t\thost.session.abortBash();\n\t\t} else if (host.isBashMode) {\n\t\t\thost.editor.setText(\"\");\n\t\t\thost.isBashMode = false;\n\t\t\thost.updateEditorBorderColor();\n\t\t} else if (!host.editor.getText().trim()) {\n\t\t\t// Double-escape with empty editor triggers /tree, /fork, or nothing based on setting\n\t\t\tconst action = host.settingsManager.getDoubleEscapeAction();\n\t\t\tif (action !== \"none\") {\n\t\t\t\tconst now = Date.now();\n\t\t\t\tif (now - host.lastEscapeTime < 500) {\n\t\t\t\t\tif (action === \"tree\") {\n\t\t\t\t\t\thost.showTreeSelector();\n\t\t\t\t\t} else {\n\t\t\t\t\t\thost.showUserMessageSelector();\n\t\t\t\t\t}\n\t\t\t\t\thost.lastEscapeTime = 0;\n\t\t\t\t} else {\n\t\t\t\t\thost.lastEscapeTime = now;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\t// Register app action handlers\n\thost.defaultEditor.onAction(\"app.clear\", () => host.handleCtrlC());\n\thost.defaultEditor.onCtrlD = () => host.handleCtrlD();\n\thost.defaultEditor.onAction(\"app.suspend\", () => host.handleCtrlZ());\n\thost.defaultEditor.onAction(\"app.thinking.cycle\", () => host.cycleThinkingLevel());\n\thost.defaultEditor.onAction(\"app.model.cycleForward\", () => host.cycleModel(\"forward\"));\n\thost.defaultEditor.onAction(\"app.model.cycleBackward\", () => host.cycleModel(\"backward\"));\n\n\t// Global debug handler on TUI (works regardless of focus)\n\thost.ui.onDebug = () => host.handleDebugCommand();\n\thost.defaultEditor.onAction(\"app.model.select\", () => void host.showModelSelector());\n\thost.defaultEditor.onAction(\"app.tools.expand\", () => host.loadTuiHistoryOnDemand());\n\thost.defaultEditor.onAction(\"app.thinking.toggle\", () => void host.toggleThinkingBlockVisibility());\n\thost.defaultEditor.onAction(\"app.editor.external\", () => host.openExternalEditor());\n\thost.defaultEditor.onAction(\"app.message.followUp\", () => host.handleFollowUp());\n\thost.defaultEditor.onAction(\"app.message.dequeue\", () => host.handleDequeue());\n\t// Plain Up arrow on an empty editor recalls queued messages for editing\n\t// before history navigation. Many terminals (e.g. Windows Terminal) swallow\n\t// the alt-chord bindings, so the queue must be reachable without them.\n\thost.defaultEditor.onRecallQueued = () => host.restoreQueuedMessagesToEditor() > 0;\n\thost.defaultEditor.onAction(\"app.session.new\", () => host.handleClearCommand());\n\thost.defaultEditor.onAction(\"app.session.tree\", () => host.showTreeSelector());\n\thost.defaultEditor.onAction(\"app.session.fork\", () => host.showUserMessageSelector());\n\thost.defaultEditor.onAction(\"app.session.resume\", () => host.showSessionSelector());\n\n\thost.defaultEditor.onChange = (text: string) => {\n\t\tconst wasBashMode = host.isBashMode;\n\t\thost.isBashMode = text.trimStart().startsWith(\"!\");\n\t\tif (wasBashMode !== host.isBashMode) {\n\t\t\thost.updateEditorBorderColor();\n\t\t}\n\t};\n\n\t// Handle
|
|
1
|
+
{"version":3,"file":"key-handlers.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/key-handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,aAAa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,CAAC,IAAI,CAAC,CAAC;IAC3D,mBAAmB,IAAI,IAAI,CAAC;IAC5B,yBAAyB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAoE5D","sourcesContent":["/**\n * Editor/global key-handler wiring extracted from interactive-mode.\n *\n * `setupKeyHandlers` installs the escape/action/ctrl-D/change/paste/recall\n * callbacks on the default editor (and the global debug handler on the TUI),\n * each delegating to a host method or toggling the bash-mode/last-escape state.\n * It runs once at init through a wide `KeyHandlersHost` seam; interactive-mode\n * keeps a thin wrapper.\n */\n\nimport type { EditorComponent, TUI } from \"@caupulican/pi-tui\";\nimport type { AgentSession } from \"../../core/agent-session.ts\";\nimport type { SettingsManager } from \"../../core/settings-manager.ts\";\nimport type { CustomEditor } from \"./components/custom-editor.ts\";\n\nexport interface KeyHandlersHost {\n\treadonly defaultEditor: CustomEditor;\n\treadonly editor: EditorComponent;\n\treadonly ui: TUI;\n\treadonly session: Pick<AgentSession, \"isStreaming\" | \"isBashRunning\" | \"abortBash\">;\n\treadonly settingsManager: Pick<SettingsManager, \"getDoubleEscapeAction\">;\n\tisBashMode: boolean;\n\tlastEscapeTime: number;\n\trestoreQueuedMessagesToEditor(options?: { abort?: boolean; currentText?: string }): number;\n\tupdateEditorBorderColor(): void;\n\tshowTreeSelector(initialSelectedId?: string): void;\n\tshowUserMessageSelector(newSessionName?: string): void;\n\thandleCtrlC(): void;\n\thandleCtrlD(): void;\n\thandleCtrlZ(): void;\n\tcycleThinkingLevel(): void;\n\tcycleModel(direction: \"forward\" | \"backward\"): Promise<void>;\n\thandleDebugCommand(): void;\n\tshowModelSelector(initialSearchInput?: string): Promise<void>;\n\tloadTuiHistoryOnDemand(): void;\n\ttoggleThinkingBlockVisibility(): Promise<void>;\n\topenExternalEditor(): Promise<void>;\n\thandleFollowUp(): Promise<void>;\n\thandleDequeue(): void;\n\thandleClearCommand(newSessionName?: string): Promise<void>;\n\tshowSessionSelector(): void;\n\thandleClipboardImagePaste(): Promise<void>;\n}\n\nexport function setupKeyHandlers(host: KeyHandlersHost): void {\n\t// Set up handlers on defaultEditor - they use host.editor for text access\n\t// so they work correctly regardless of which editor is active\n\thost.defaultEditor.onEscape = () => {\n\t\tif (host.session.isStreaming) {\n\t\t\thost.restoreQueuedMessagesToEditor({ abort: true });\n\t\t} else if (host.session.isBashRunning) {\n\t\t\thost.session.abortBash();\n\t\t} else if (host.isBashMode) {\n\t\t\thost.editor.setText(\"\");\n\t\t\thost.isBashMode = false;\n\t\t\thost.updateEditorBorderColor();\n\t\t} else if (!host.editor.getText().trim()) {\n\t\t\t// Double-escape with empty editor triggers /tree, /fork, or nothing based on setting\n\t\t\tconst action = host.settingsManager.getDoubleEscapeAction();\n\t\t\tif (action !== \"none\") {\n\t\t\t\tconst now = Date.now();\n\t\t\t\tif (now - host.lastEscapeTime < 500) {\n\t\t\t\t\tif (action === \"tree\") {\n\t\t\t\t\t\thost.showTreeSelector();\n\t\t\t\t\t} else {\n\t\t\t\t\t\thost.showUserMessageSelector();\n\t\t\t\t\t}\n\t\t\t\t\thost.lastEscapeTime = 0;\n\t\t\t\t} else {\n\t\t\t\t\thost.lastEscapeTime = now;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\t// Register app action handlers\n\thost.defaultEditor.onAction(\"app.clear\", () => host.handleCtrlC());\n\thost.defaultEditor.onCtrlD = () => host.handleCtrlD();\n\thost.defaultEditor.onAction(\"app.suspend\", () => host.handleCtrlZ());\n\thost.defaultEditor.onAction(\"app.thinking.cycle\", () => host.cycleThinkingLevel());\n\thost.defaultEditor.onAction(\"app.model.cycleForward\", () => host.cycleModel(\"forward\"));\n\thost.defaultEditor.onAction(\"app.model.cycleBackward\", () => host.cycleModel(\"backward\"));\n\n\t// Global debug handler on TUI (works regardless of focus)\n\thost.ui.onDebug = () => host.handleDebugCommand();\n\thost.defaultEditor.onAction(\"app.model.select\", () => void host.showModelSelector());\n\thost.defaultEditor.onAction(\"app.tools.expand\", () => host.loadTuiHistoryOnDemand());\n\thost.defaultEditor.onAction(\"app.thinking.toggle\", () => void host.toggleThinkingBlockVisibility());\n\thost.defaultEditor.onAction(\"app.editor.external\", () => host.openExternalEditor());\n\thost.defaultEditor.onAction(\"app.message.followUp\", () => host.handleFollowUp());\n\thost.defaultEditor.onAction(\"app.message.dequeue\", () => host.handleDequeue());\n\t// Plain Up arrow on an empty editor recalls queued messages for editing\n\t// before history navigation. Many terminals (e.g. Windows Terminal) swallow\n\t// the alt-chord bindings, so the queue must be reachable without them.\n\thost.defaultEditor.onRecallQueued = () => host.restoreQueuedMessagesToEditor() > 0;\n\thost.defaultEditor.onAction(\"app.session.new\", () => host.handleClearCommand());\n\thost.defaultEditor.onAction(\"app.session.tree\", () => host.showTreeSelector());\n\thost.defaultEditor.onAction(\"app.session.fork\", () => host.showUserMessageSelector());\n\thost.defaultEditor.onAction(\"app.session.resume\", () => host.showSessionSelector());\n\n\thost.defaultEditor.onChange = (text: string) => {\n\t\tconst wasBashMode = host.isBashMode;\n\t\thost.isBashMode = text.trimStart().startsWith(\"!\");\n\t\tif (wasBashMode !== host.isBashMode) {\n\t\t\thost.updateEditorBorderColor();\n\t\t}\n\t};\n\n\t// Handle the configurable platform paste chord (Ctrl+V on Unix, Alt+V on Windows).\n\thost.defaultEditor.onPasteImage = () => {\n\t\thost.handleClipboardImagePaste();\n\t};\n}\n"]}
|
|
@@ -72,7 +72,7 @@ export function setupKeyHandlers(host) {
|
|
|
72
72
|
host.updateEditorBorderColor();
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
|
-
// Handle
|
|
75
|
+
// Handle the configurable platform paste chord (Ctrl+V on Unix, Alt+V on Windows).
|
|
76
76
|
host.defaultEditor.onPasteImage = () => {
|
|
77
77
|
host.handleClipboardImagePaste();
|
|
78
78
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-handlers.js","sourceRoot":"","sources":["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AAE,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACnD,IAAI,WAAW,KAAK,IAAI,CAAC,UAAU,EAAE,CAAC;YACrC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAChC,CAAC;IAAA,CACD,CAAC;IAEF,mFAAmF;IACnF,IAAI,CAAC,aAAa,CAAC,YAAY,GAAG,GAAG,EAAE,CAAC;QACvC,IAAI,CAAC,yBAAyB,EAAE,CAAC;IAAA,CACjC,CAAC;AAAA,CACF","sourcesContent":["/**\n * Editor/global key-handler wiring extracted from interactive-mode.\n *\n * `setupKeyHandlers` installs the escape/action/ctrl-D/change/paste/recall\n * callbacks on the default editor (and the global debug handler on the TUI),\n * each delegating to a host method or toggling the bash-mode/last-escape state.\n * It runs once at init through a wide `KeyHandlersHost` seam; interactive-mode\n * keeps a thin wrapper.\n */\n\nimport type { EditorComponent, TUI } from \"@caupulican/pi-tui\";\nimport type { AgentSession } from \"../../core/agent-session.ts\";\nimport type { SettingsManager } from \"../../core/settings-manager.ts\";\nimport type { CustomEditor } from \"./components/custom-editor.ts\";\n\nexport interface KeyHandlersHost {\n\treadonly defaultEditor: CustomEditor;\n\treadonly editor: EditorComponent;\n\treadonly ui: TUI;\n\treadonly session: Pick<AgentSession, \"isStreaming\" | \"isBashRunning\" | \"abortBash\">;\n\treadonly settingsManager: Pick<SettingsManager, \"getDoubleEscapeAction\">;\n\tisBashMode: boolean;\n\tlastEscapeTime: number;\n\trestoreQueuedMessagesToEditor(options?: { abort?: boolean; currentText?: string }): number;\n\tupdateEditorBorderColor(): void;\n\tshowTreeSelector(initialSelectedId?: string): void;\n\tshowUserMessageSelector(newSessionName?: string): void;\n\thandleCtrlC(): void;\n\thandleCtrlD(): void;\n\thandleCtrlZ(): void;\n\tcycleThinkingLevel(): void;\n\tcycleModel(direction: \"forward\" | \"backward\"): Promise<void>;\n\thandleDebugCommand(): void;\n\tshowModelSelector(initialSearchInput?: string): Promise<void>;\n\tloadTuiHistoryOnDemand(): void;\n\ttoggleThinkingBlockVisibility(): Promise<void>;\n\topenExternalEditor(): Promise<void>;\n\thandleFollowUp(): Promise<void>;\n\thandleDequeue(): void;\n\thandleClearCommand(newSessionName?: string): Promise<void>;\n\tshowSessionSelector(): void;\n\thandleClipboardImagePaste(): Promise<void>;\n}\n\nexport function setupKeyHandlers(host: KeyHandlersHost): void {\n\t// Set up handlers on defaultEditor - they use host.editor for text access\n\t// so they work correctly regardless of which editor is active\n\thost.defaultEditor.onEscape = () => {\n\t\tif (host.session.isStreaming) {\n\t\t\thost.restoreQueuedMessagesToEditor({ abort: true });\n\t\t} else if (host.session.isBashRunning) {\n\t\t\thost.session.abortBash();\n\t\t} else if (host.isBashMode) {\n\t\t\thost.editor.setText(\"\");\n\t\t\thost.isBashMode = false;\n\t\t\thost.updateEditorBorderColor();\n\t\t} else if (!host.editor.getText().trim()) {\n\t\t\t// Double-escape with empty editor triggers /tree, /fork, or nothing based on setting\n\t\t\tconst action = host.settingsManager.getDoubleEscapeAction();\n\t\t\tif (action !== \"none\") {\n\t\t\t\tconst now = Date.now();\n\t\t\t\tif (now - host.lastEscapeTime < 500) {\n\t\t\t\t\tif (action === \"tree\") {\n\t\t\t\t\t\thost.showTreeSelector();\n\t\t\t\t\t} else {\n\t\t\t\t\t\thost.showUserMessageSelector();\n\t\t\t\t\t}\n\t\t\t\t\thost.lastEscapeTime = 0;\n\t\t\t\t} else {\n\t\t\t\t\thost.lastEscapeTime = now;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t};\n\n\t// Register app action handlers\n\thost.defaultEditor.onAction(\"app.clear\", () => host.handleCtrlC());\n\thost.defaultEditor.onCtrlD = () => host.handleCtrlD();\n\thost.defaultEditor.onAction(\"app.suspend\", () => host.handleCtrlZ());\n\thost.defaultEditor.onAction(\"app.thinking.cycle\", () => host.cycleThinkingLevel());\n\thost.defaultEditor.onAction(\"app.model.cycleForward\", () => host.cycleModel(\"forward\"));\n\thost.defaultEditor.onAction(\"app.model.cycleBackward\", () => host.cycleModel(\"backward\"));\n\n\t// Global debug handler on TUI (works regardless of focus)\n\thost.ui.onDebug = () => host.handleDebugCommand();\n\thost.defaultEditor.onAction(\"app.model.select\", () => void host.showModelSelector());\n\thost.defaultEditor.onAction(\"app.tools.expand\", () => host.loadTuiHistoryOnDemand());\n\thost.defaultEditor.onAction(\"app.thinking.toggle\", () => void host.toggleThinkingBlockVisibility());\n\thost.defaultEditor.onAction(\"app.editor.external\", () => host.openExternalEditor());\n\thost.defaultEditor.onAction(\"app.message.followUp\", () => host.handleFollowUp());\n\thost.defaultEditor.onAction(\"app.message.dequeue\", () => host.handleDequeue());\n\t// Plain Up arrow on an empty editor recalls queued messages for editing\n\t// before history navigation. Many terminals (e.g. Windows Terminal) swallow\n\t// the alt-chord bindings, so the queue must be reachable without them.\n\thost.defaultEditor.onRecallQueued = () => host.restoreQueuedMessagesToEditor() > 0;\n\thost.defaultEditor.onAction(\"app.session.new\", () => host.handleClearCommand());\n\thost.defaultEditor.onAction(\"app.session.tree\", () => host.showTreeSelector());\n\thost.defaultEditor.onAction(\"app.session.fork\", () => host.showUserMessageSelector());\n\thost.defaultEditor.onAction(\"app.session.resume\", () => host.showSessionSelector());\n\n\thost.defaultEditor.onChange = (text: string) => {\n\t\tconst wasBashMode = host.isBashMode;\n\t\thost.isBashMode = text.trimStart().startsWith(\"!\");\n\t\tif (wasBashMode !== host.isBashMode) {\n\t\t\thost.updateEditorBorderColor();\n\t\t}\n\t};\n\n\t// Handle the configurable platform paste chord (Ctrl+V on Unix, Alt+V on Windows).\n\thost.defaultEditor.onPasteImage = () => {\n\t\thost.handleClipboardImagePaste();\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profile-menu-controller.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/profile-menu-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAA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,CAAC;CACzC;AAED,MAAM,WAAW,yBAAyB;IACzC,UAAU,IAAI,YAAY,CAAC;IAC3B,EAAE,EAAE,uBAAuB,CAAC;CAC5B;AAMD,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAO9F;AAED,qBAAa,qBAAqB;IACjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA4B;IAEjD,YAAY,IAAI,EAAE,yBAAyB,EAE1C;IAED,OAAO,KAAK,OAAO,GAElB;IACD,OAAO,KAAK,cAAc,GAEzB;IACD,OAAO,KAAK,eAAe,GAE1B;IACD,OAAO,KAAK,EAAE,GAEb;IAEK,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAoB5D;YAEa,yBAAyB;YAmCzB,sBAAsB;IAsEpC,OAAO,CAAC,4BAA4B;YAoCtB,gBAAgB;YA+BhB,0BAA0B;YAgC1B,yBAAyB;YA6BzB,sBAAsB;YAiDtB,sBAAsB;YAkDtB,+BAA+B;YAuD/B,+BAA+B;YAsC/B,uBAAuB;YAkJvB,2BAA2B;YA4D3B,oBAAoB;YA2EpB,gCAAgC;YAsChC,2BAA2B;IAkCnC,qBAAqB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA8B/D;YAEa,YAAY;IA+G1B,mFAAmF;IACnF,OAAO,CAAC,qBAAqB;IAgBvB,2BAA2B,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQpE;YAEa,iBAAiB;YAuDjB,kBAAkB;YA4ClB,oBAAoB;IAwDlC,OAAO,CAAC,oBAAoB;YAkBd,uBAAuB;YA2EvB,2BAA2B;YAmF3B,8BAA8B;CAiB5C","sourcesContent":["/**\n * Resource-profile & external-source menu controller.\n *\n * Extracted verbatim from interactive-mode.ts (god-file decomposition). Owns the /profiles command\n * and the resource-hub menu tree: active-profile selection, profile create/delete/persist, the\n * library (per-profile resource grants) editor, and external-source root management. It holds NO\n * state of its own — every profile/source fact lives in settingsManager / the profile registry /\n * the session resourceLoader — so it takes narrow deps (a live session accessor plus a UI callback\n * surface, including the editor-overlay-backed showSelector) rather than the whole InteractiveMode\n * instance.\n */\n\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport type { Api, Model } from \"@caupulican/pi-ai\";\nimport type { Component, SelectItem, TUI } from \"@caupulican/pi-tui\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type { AgentSession } from \"../../core/agent-session.ts\";\nimport { resolveCliModel } from \"../../core/model-resolver.ts\";\nimport type { NormalizedProfile } from \"../../core/profile-registry.ts\";\nimport { resourceProfileSettingsChangedKinds } from \"../../core/resource-profile-equality.ts\";\nimport type { SettingsReloadSnapshot } from \"../../core/settings-manager.ts\";\nimport { validateSkillName } from \"../../core/skills.ts\";\nimport { allToolNames } from \"../../core/tools/index.ts\";\nimport { parseFrontmatter } from \"../../utils/frontmatter.ts\";\nimport { ExtensionInputComponent } from \"./components/extension-input.ts\";\nimport {\n\tProfileResourceEditorComponent,\n\ttype ProfileResourceEditorKind,\n\tresolveResourceEditPath,\n} from \"./components/profile-resource-editor.ts\";\nimport { ProfileSelectorComponent } from \"./components/profile-selector.ts\";\nimport { SelectSubmenu } from \"./components/settings-selector.ts\";\nimport { captureProfileFiles, restoreProfileFiles } from \"./config-backup.ts\";\nimport { getAvailableThemesWithPaths } from \"./theme/theme.ts\";\n\ntype WritableProfileScope = \"session\" | \"directory\" | \"project\" | \"global\" | \"reusable-file\";\n\nexport const NO_ACTIVE_PROFILE_DESCRIPTION =\n\t\"Baseline resources; inline SDK extensions load, discovered extensions stay withheld\";\n\nfunction deletionScopeForProfile(profile: NormalizedProfile): WritableProfileScope | undefined {\n\tswitch (profile.source) {\n\t\tcase \"inline\":\n\t\t\treturn \"session\";\n\t\tcase \"directory-overlay\":\n\t\t\treturn \"directory\";\n\t\tcase \"project-settings\":\n\t\t\treturn \"project\";\n\t\tcase \"global-settings\":\n\t\t\treturn \"global\";\n\t\tcase \"profile-file\": {\n\t\t\tconst localProfilePath = path.resolve(getAgentDir(), \"profiles\", `${profile.name}.json`);\n\t\t\treturn profile.sourcePath && path.resolve(profile.sourcePath) === localProfilePath\n\t\t\t\t? \"reusable-file\"\n\t\t\t\t: undefined;\n\t\t}\n\t\tcase \"embedded\":\n\t\tcase \"external-settings\":\n\t\t\treturn undefined;\n\t}\n}\n\ninterface ProfileDefinitionRollbackTarget {\n\tprofileName: string;\n\tscope: WritableProfileScope;\n\tprofileFilesSnapshot?: ReturnType<typeof captureProfileFiles>;\n}\n\nexport interface ProfileMenuControllerUi {\n\tshowSelector(\n\t\tcreate: (done: () => void) => {\n\t\t\tcomponent: Component;\n\t\t\tfocus: Component;\n\t\t\tonSuperseded?: () => void;\n\t\t},\n\t): void;\n\tshowStatus(message: string): void;\n\tshowError(message: string): void;\n\tshowWarning(message: string): void;\n\trequestRender(): void;\n\treadonly tui: TUI;\n\treadonly footerDataProvider: { setExtensionStatus(key: string, text: string | undefined): void };\n\tinvalidateFooter(): void;\n\tupdateEditorBorderColor(): void;\n\topenEditorForPath(filePath: string): Promise<boolean>;\n\thandleReloadCommand(): Promise<boolean>;\n\tmaybeWarnAboutAnthropicSubscriptionAuth(model?: Model<Api>): void;\n\tcheckDaxnutsEasterEgg(model: { provider: string; id: string }): void;\n\tshowSettingsSelector(): void;\n\tgetAutoLearnModelOptions(): SelectItem[];\n}\n\nexport interface ProfileMenuControllerDeps {\n\tgetSession(): AgentSession;\n\tui: ProfileMenuControllerUi;\n}\n\nfunction portableBasename(filePath: string): string {\n\treturn filePath.split(/[\\\\/]/).filter(Boolean).pop() ?? filePath;\n}\n\nexport function getProfileExtensionDisplayLabel(filePath: string, description?: string): string {\n\tconst normalizedDescription = description?.trim();\n\tif (normalizedDescription) return normalizedDescription;\n\tconst fileName = portableBasename(filePath);\n\tif (!/^index\\.(?:ts|js)$/i.test(fileName)) return fileName;\n\tconst parentPath = filePath.slice(0, Math.max(0, filePath.length - fileName.length)).replace(/[\\\\/]$/, \"\");\n\treturn portableBasename(parentPath) || fileName;\n}\n\nexport class ProfileMenuController {\n\tprivate readonly deps: ProfileMenuControllerDeps;\n\n\tconstructor(deps: ProfileMenuControllerDeps) {\n\t\tthis.deps = deps;\n\t}\n\n\tprivate get session(): AgentSession {\n\t\treturn this.deps.getSession();\n\t}\n\tprivate get sessionManager() {\n\t\treturn this.deps.getSession().sessionManager;\n\t}\n\tprivate get settingsManager() {\n\t\treturn this.deps.getSession().settingsManager;\n\t}\n\tprivate get ui(): ProfileMenuControllerUi {\n\t\treturn this.deps.ui;\n\t}\n\n\tasync handleResourcesHubAction(action: string): Promise<void> {\n\t\tswitch (action) {\n\t\t\tcase \"nudge-add-source\":\n\t\t\t\tvoid this.addExternalResourceRootFlow().then(() => {\n\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase \"active-profile\":\n\t\t\t\tvoid this.openActiveProfileSelector();\n\t\t\t\tbreak;\n\t\t\tcase \"manage-library\":\n\t\t\t\tvoid this.openLibraryManagerFlow();\n\t\t\t\tbreak;\n\t\t\tcase \"manage-profiles\":\n\t\t\t\tvoid this.openManageProfilesFlow();\n\t\t\t\tbreak;\n\t\t\tcase \"sources\":\n\t\t\t\tvoid this.openSourcesManagerFlow();\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tprivate async openActiveProfileSelector(): Promise<void> {\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst profiles = registry.listProfiles();\n\t\tconst activeNames = this.settingsManager.getActiveResourceProfileNames();\n\n\t\tconst options = [\n\t\t\t{ value: \"(none)\", label: \"(none)\", description: NO_ACTIVE_PROFILE_DESCRIPTION },\n\t\t\t...profiles.map((p) => ({\n\t\t\t\tvalue: p.name,\n\t\t\t\tlabel: p.name,\n\t\t\t\tdescription: p.description || p.source,\n\t\t\t})),\n\t\t];\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\"Profile / Situation\",\n\t\t\t\t\"Select the active runtime profile/situation for this session. This is session-only unless saved elsewhere.\",\n\t\t\t\toptions,\n\t\t\t\tactiveNames[0] || \"(none)\",\n\t\t\t\t(value) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.applyProfile(value === \"(none)\" ? \"\" : value).then(() => {\n\t\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tprivate async openManageProfilesFlow(): Promise<void> {\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst profiles = registry.listProfiles();\n\t\tconst editableProfiles = profiles.map((p) => ({\n\t\t\tvalue: p.name,\n\t\t\tlabel: p.name,\n\t\t\tdescription: p.description || p.source,\n\t\t}));\n\n\t\tconst options = [\n\t\t\t{\n\t\t\t\tvalue: \"create\",\n\t\t\t\tlabel: \"+ Create profile / situation...\",\n\t\t\t\tdescription: \"Create a new resource profile/situation definition.\",\n\t\t\t},\n\t\t];\n\n\t\tif (editableProfiles.length > 0) {\n\t\t\toptions.push({\n\t\t\t\tvalue: \"edit-model\",\n\t\t\t\tlabel: \"Edit profile model...\",\n\t\t\t\tdescription: \"Pin a model or inherit the session/default model.\",\n\t\t\t});\n\t\t}\n\n\t\tif (this.settingsManager.getActiveResourceProfileNames().length > 0) {\n\t\t\toptions.push({\n\t\t\t\tvalue: \"persist\",\n\t\t\t\tlabel: \"Persist active profile / situation to...\",\n\t\t\t\tdescription: \"Save the current active profile/situation selection so it survives restart.\",\n\t\t\t});\n\t\t}\n\n\t\tif (editableProfiles.length > 0) {\n\t\t\toptions.push({\n\t\t\t\tvalue: \"delete\",\n\t\t\t\tlabel: \"Delete profile / situation...\",\n\t\t\t\tdescription: \"Remove a profile/situation definition from where it is stored.\",\n\t\t\t});\n\t\t}\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\"Manage Profiles / Situations\",\n\t\t\t\t\"Create, edit, delete, or persist profile/situation definitions.\",\n\t\t\t\toptions,\n\t\t\t\t\"\",\n\t\t\t\t(value) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tif (value === \"create\") {\n\t\t\t\t\t\tvoid this.createProfileFlow().then(() => {\n\t\t\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t\t\t});\n\t\t\t\t\t} else if (value === \"edit-model\") {\n\t\t\t\t\t\tthis.openEditProfileModelSelector();\n\t\t\t\t\t} else if (value === \"persist\") {\n\t\t\t\t\t\tvoid this.openPersistProfileSelector();\n\t\t\t\t\t} else if (value === \"delete\") {\n\t\t\t\t\t\tvoid this.openDeleteProfileSelector();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tprivate openEditProfileModelSelector(): void {\n\t\tconst profiles = this.settingsManager\n\t\t\t.getProfileRegistry()\n\t\t\t.listProfiles()\n\t\t\t.filter((profile) => deletionScopeForProfile(profile) !== undefined);\n\t\tif (profiles.length === 0) {\n\t\t\tthis.ui.showStatus(\"No writable profiles available. External and embedded profiles are read-only.\");\n\t\t\treturn;\n\t\t}\n\t\tconst activeNames = this.settingsManager.getActiveResourceProfileNames();\n\t\tconst initialValue = profiles.find((profile) => activeNames.includes(profile.name))?.name ?? profiles[0].name;\n\t\tconst items = profiles.map((profile) => ({\n\t\t\tvalue: profile.name,\n\t\t\tlabel: profile.name,\n\t\t\tdescription: `${profile.model ? `Pinned: ${profile.model}` : \"Inherits session/default model\"} · ${profile.description || profile.source}`,\n\t\t}));\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\"Edit Profile Model\",\n\t\t\t\t\"Choose a writable profile, then pin or inherit its foreground model.\",\n\t\t\t\titems,\n\t\t\t\tinitialValue,\n\t\t\t\t(profileName) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.editProfileModel(profileName);\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.openManageProfilesFlow();\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tprivate async editProfileModel(profileName: string): Promise<void> {\n\t\tconst profile = this.settingsManager.getProfileRegistry().getProfile(profileName);\n\t\tif (!profile) {\n\t\t\tthis.ui.showError(`Profile \"${profileName}\" is no longer available.`);\n\t\t\treturn;\n\t\t}\n\t\tconst scope = deletionScopeForProfile(profile);\n\t\tif (!scope) {\n\t\t\tthis.ui.showError(`Profile \"${profileName}\" is read-only (${profile.source}).`);\n\t\t\treturn;\n\t\t}\n\t\tconst selectedModel = await this.selectProfileModel(profile.model);\n\t\tif (selectedModel === undefined) {\n\t\t\tvoid this.openManageProfilesFlow();\n\t\t\treturn;\n\t\t}\n\t\tconst model = selectedModel ?? undefined;\n\t\tif (model === profile.model) {\n\t\t\tthis.ui.showStatus(`Profile \"${profileName}\" model unchanged.`);\n\t\t\treturn;\n\t\t}\n\t\tawait this.saveProfileResources(\n\t\t\t{ ...profile, model },\n\t\t\tprofile.resources,\n\t\t\tprofile.resources,\n\t\t\tscope,\n\t\t\tthis.settingsManager.getActiveResourceProfileNames().includes(profile.name),\n\t\t\ttrue,\n\t\t);\n\t}\n\n\tprivate async openPersistProfileSelector(): Promise<void> {\n\t\tconst scopeOptions = [\n\t\t\t{ value: \"session\", label: \"session\", description: \"Runtime only (not written to disk)\" },\n\t\t\t{\n\t\t\t\tvalue: \"directory\",\n\t\t\t\tlabel: \"directory\",\n\t\t\t\tdescription: \"~/.pi/agent/resource-profiles/<hash>/settings.json\",\n\t\t\t},\n\t\t\t{ value: \"project\", label: \"project\", description: \".pi/settings.json\" },\n\t\t\t{ value: \"global\", label: \"global\", description: \"~/.pi/agent/settings.json\" },\n\t\t];\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\"Persist Active Profile / Situation\",\n\t\t\t\t\"Choose where to write the active profile/situation selection.\",\n\t\t\t\tscopeOptions,\n\t\t\t\t\"directory\",\n\t\t\t\t(value) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tthis.persistActiveProfile(value as \"session\" | \"directory\" | \"project\" | \"global\");\n\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.openManageProfilesFlow();\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tprivate async openDeleteProfileSelector(): Promise<void> {\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst editableProfiles = registry.listProfiles().map((p) => ({\n\t\t\tvalue: p.name,\n\t\t\tlabel: p.name,\n\t\t\tdescription: p.description || p.source,\n\t\t}));\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\"Delete Profile / Situation\",\n\t\t\t\t\"Pick a profile/situation to delete.\",\n\t\t\t\teditableProfiles,\n\t\t\t\t\"\",\n\t\t\t\t(value) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.deleteProfileFromSource(value).then(() => {\n\t\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.openManageProfilesFlow();\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tprivate async openSourcesManagerFlow(): Promise<void> {\n\t\tconst externalRoots = this.settingsManager.getExternalResourceRoots();\n\t\tconst trustedRoots = this.settingsManager.getTrustedResourceRoots();\n\n\t\tconst options = [\n\t\t\t{\n\t\t\t\tvalue: \"add\",\n\t\t\t\tlabel: \"+ Add external root...\",\n\t\t\t\tdescription: \"Register a new external directory root (requires trust)\",\n\t\t\t},\n\t\t];\n\n\t\tfor (const r of externalRoots) {\n\t\t\tconst isTrusted = trustedRoots.includes(r);\n\t\t\toptions.push({\n\t\t\t\tvalue: `remove:${r}`,\n\t\t\t\tlabel: `Remove: ${r}`,\n\t\t\t\tdescription: isTrusted ? \"Trusted external root\" : \"Untrusted external root\",\n\t\t\t});\n\t\t}\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\"Sources\",\n\t\t\t\t\"Manage external resource roots. Adding a root requires trust confirmation.\",\n\t\t\t\toptions,\n\t\t\t\t\"\",\n\t\t\t\t(value) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tif (value === \"add\") {\n\t\t\t\t\t\tvoid this.addExternalResourceRootFlow().then(() => {\n\t\t\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t\t\t});\n\t\t\t\t\t} else if (value.startsWith(\"remove:\")) {\n\t\t\t\t\t\tconst root = value.slice(\"remove:\".length);\n\t\t\t\t\t\tvoid this.removeExternalResourceRootFlow(root).then(() => {\n\t\t\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tprivate async openLibraryManagerFlow(): Promise<void> {\n\t\tconst activeNames = this.settingsManager.getActiveResourceProfileNames();\n\t\tconst activeName = activeNames[0];\n\n\t\tif (!activeName || activeName === \"(none)\") {\n\t\t\tthis.ui.showSelector((done) => {\n\t\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\t\"No Active Profile / Situation\",\n\t\t\t\t\t\"Select or create a profile/situation to manage the library.\",\n\t\t\t\t\t[\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tvalue: \"select\",\n\t\t\t\t\t\t\tlabel: \"Select existing profile / situation...\",\n\t\t\t\t\t\t\tdescription: \"Choose an existing profile/situation to activate.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tvalue: \"create\",\n\t\t\t\t\t\t\tlabel: \"Create new profile / situation...\",\n\t\t\t\t\t\t\tdescription: \"Create a new profile/situation definition.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\t\"select\",\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tif (value === \"create\") {\n\t\t\t\t\t\t\tvoid this.createProfileAndOpenLibraryFlow();\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tvoid this.selectProfileAndOpenLibraryFlow();\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst profile = registry.getProfile(activeName);\n\t\tif (!profile) {\n\t\t\tthis.ui.showError(`Active profile/situation \"${activeName}\" not found in registry.`);\n\t\t\treturn;\n\t\t}\n\t\tconst scope = this.scopeForProfileSource(profile.source);\n\t\tvoid this.openLibraryEditorForProfile(profile.name, scope);\n\t}\n\n\tprivate async createProfileAndOpenLibraryFlow(): Promise<void> {\n\t\tconst name = await new Promise<string | undefined>((resolve) => {\n\t\t\tthis.ui.showSelector((done) => {\n\t\t\t\tconst input = new ExtensionInputComponent(\n\t\t\t\t\t\"Create Profile / Situation\",\n\t\t\t\t\t\"Enter profile/situation name\",\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(value);\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t},\n\t\t\t\t\t{ tui: this.ui.tui },\n\t\t\t\t);\n\t\t\t\treturn { component: input, focus: input, onSuperseded: () => resolve(undefined) };\n\t\t\t});\n\t\t});\n\n\t\tif (name === undefined) {\n\t\t\tvoid this.openLibraryManagerFlow();\n\t\t\treturn;\n\t\t}\n\n\t\tconst trimmed = name.trim();\n\t\tif (!trimmed) {\n\t\t\tthis.ui.showWarning(\"Profile/situation name cannot be empty.\");\n\t\t\tvoid this.openLibraryManagerFlow();\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst profileModel = await this.selectProfileModel();\n\t\t\tif (profileModel === undefined) {\n\t\t\t\tvoid this.openLibraryManagerFlow();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.settingsManager.setProfileDefinition(\n\t\t\t\ttrimmed,\n\t\t\t\t{\n\t\t\t\t\tname: trimmed,\n\t\t\t\t\tmodel: profileModel ?? undefined,\n\t\t\t\t\tresources: {},\n\t\t\t\t},\n\t\t\t\t\"reusable-file\",\n\t\t\t);\n\t\t\tawait this.applyProfile(trimmed);\n\t\t\tvoid this.openLibraryEditorForProfile(trimmed, \"reusable-file\");\n\t\t} catch (error) {\n\t\t\tthis.ui.showError(error instanceof Error ? error.message : String(error));\n\t\t\tvoid this.openLibraryManagerFlow();\n\t\t}\n\t}\n\n\tprivate async selectProfileAndOpenLibraryFlow(): Promise<void> {\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst profiles = registry.listProfiles();\n\t\tconst editableProfiles = profiles.map((p) => ({\n\t\t\tvalue: p.name,\n\t\t\tlabel: p.name,\n\t\t\tdescription: p.description || p.source,\n\t\t}));\n\n\t\tif (editableProfiles.length === 0) {\n\t\t\tthis.ui.showWarning(\"No existing profiles/situations to select. Please create one.\");\n\t\t\tvoid this.createProfileAndOpenLibraryFlow();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\"Select Profile / Situation\",\n\t\t\t\t\"Pick a profile/situation to activate and edit.\",\n\t\t\t\teditableProfiles,\n\t\t\t\t\"\",\n\t\t\t\t(value) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.applyProfile(value).then(() => {\n\t\t\t\t\t\tconst profile = registry.getProfile(value)!;\n\t\t\t\t\t\tconst scope = this.scopeForProfileSource(profile.source);\n\t\t\t\t\t\tvoid this.openLibraryEditorForProfile(value, scope);\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.openLibraryManagerFlow();\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tprivate async getProfileResourceKinds(): Promise<ProfileResourceEditorKind[]> {\n\t\tconst loader = this.session.resourceLoader;\n\t\tconst base = portableBasename;\n\t\tconst allDiscoverableExtensions = await loader.getDiscoverableExtensionPaths();\n\t\t// Defined BEFORE the skills/prompts arrays below that call it (const = TDZ: defining it\n\t\t// later crashes the whole app with a ReferenceError when the library editor opens).\n\t\tconst getFrontmatterDescription = (filePath: string): string | undefined => {\n\t\t\ttry {\n\t\t\t\tconst content = fs.readFileSync(filePath, \"utf-8\");\n\t\t\t\tconst { frontmatter } = parseFrontmatter<Record<string, unknown>>(content);\n\t\t\t\tif (typeof frontmatter.description === \"string\") return frontmatter.description;\n\t\t\t} catch {}\n\t\t\treturn undefined;\n\t\t};\n\t\t// The editor's universe must be profile-INDEPENDENT (discovery, not loading): the loaded\n\t\t// getters are narrowed by the active profile, so building the lists from them makes\n\t\t// currently-blocked skills/prompts/context files ungrantable — including expanding the\n\t\t// very profile you are running under. Union the loaded (rich metadata) sets with the\n\t\t// full pre-filter discovery paths.\n\t\tconst loadedSkills = loader.getSkills().skills;\n\t\tconst loadedSkillPaths = new Set(loadedSkills.map((skill) => skill.filePath));\n\t\tconst skillIdFromPath = (skillPath: string): string => {\n\t\t\tconst parts = skillPath.split(/[\\\\/]/);\n\t\t\tconst last = parts.pop() ?? skillPath;\n\t\t\tif (/^skill\\.md$/i.test(last)) return parts.pop() ?? last;\n\t\t\treturn last.replace(/\\.md$/i, \"\");\n\t\t};\n\t\tconst skills = [\n\t\t\t...loadedSkills.map((skill) => ({ id: skill.name, path: skill.filePath, description: skill.description })),\n\t\t\t...loader\n\t\t\t\t.getDiscoverableSkillPaths()\n\t\t\t\t.filter((skillPath) => !loadedSkillPaths.has(skillPath))\n\t\t\t\t.map((skillPath) => ({\n\t\t\t\t\tid: skillIdFromPath(skillPath),\n\t\t\t\t\tpath: skillPath,\n\t\t\t\t\tdescription: getFrontmatterDescription(skillPath),\n\t\t\t\t})),\n\t\t];\n\t\tconst loadedPrompts = loader.getPrompts().prompts;\n\t\tconst loadedPromptPaths = new Set(loadedPrompts.map((prompt) => prompt.filePath));\n\t\tconst prompts = [\n\t\t\t...loadedPrompts.map((prompt) => ({\n\t\t\t\tid: prompt.name,\n\t\t\t\tpath: prompt.filePath,\n\t\t\t\tdescription: prompt.description,\n\t\t\t})),\n\t\t\t...loader\n\t\t\t\t.getDiscoverablePromptPaths()\n\t\t\t\t.filter((promptPath) => !loadedPromptPaths.has(promptPath))\n\t\t\t\t.map((promptPath) => ({\n\t\t\t\t\tid: (promptPath.split(/[\\\\/]/).pop() ?? promptPath).replace(/\\.md$/i, \"\"),\n\t\t\t\t\tpath: promptPath,\n\t\t\t\t\tdescription: getFrontmatterDescription(promptPath),\n\t\t\t\t})),\n\t\t];\n\t\tconst themes = getAvailableThemesWithPaths();\n\t\tconst loadedAgentPaths = new Set(loader.getAgentsFiles().agentsFiles.map((file) => file.path));\n\t\tconst agents = [\n\t\t\t...loader.getAgentsFiles().agentsFiles.map((file) => ({ path: file.path })),\n\t\t\t...loader\n\t\t\t\t.getDiscoverableAgentsFilePaths()\n\t\t\t\t.filter((agentPath) => !loadedAgentPaths.has(agentPath))\n\t\t\t\t.map((agentPath) => ({ path: agentPath })),\n\t\t];\n\n\t\tconst getAgentDescription = (filePath: string): string | undefined => {\n\t\t\ttry {\n\t\t\t\tconst content = fs.readFileSync(filePath, \"utf-8\");\n\t\t\t\tconst { frontmatter } = parseFrontmatter<Record<string, unknown>>(content);\n\t\t\t\tif (typeof frontmatter.description === \"string\") {\n\t\t\t\t\treturn frontmatter.description;\n\t\t\t\t}\n\t\t\t} catch {}\n\t\t\treturn undefined;\n\t\t};\n\n\t\tconst getExtensionDescription = (filePath: string): string | undefined => {\n\t\t\ttry {\n\t\t\t\tlet dir = filePath;\n\t\t\t\tif (fs.existsSync(filePath) && !fs.statSync(filePath).isDirectory()) {\n\t\t\t\t\tdir = path.dirname(filePath);\n\t\t\t\t}\n\t\t\t\tconst pkgPath = path.join(dir, \"package.json\");\n\t\t\t\tif (fs.existsSync(pkgPath)) {\n\t\t\t\t\tconst pkg = JSON.parse(fs.readFileSync(pkgPath, \"utf-8\"));\n\t\t\t\t\tif (typeof pkg.description === \"string\") {\n\t\t\t\t\t\treturn pkg.description;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch {}\n\t\t\treturn undefined;\n\t\t};\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: \"tools\",\n\t\t\t\tlabel: \"Tools\",\n\t\t\t\t// Built-ins plus every currently registered tool (extension tools included), so\n\t\t\t\t// an extension tool can be granted by name without hand-editing settings JSON.\n\t\t\t\titems: [...new Set([...allToolNames, ...this.session.getAllTools().map((tool) => tool.name)])].map(\n\t\t\t\t\t(name: string) => ({ id: name }),\n\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tkind: \"skills\",\n\t\t\t\tlabel: \"Skills\",\n\t\t\t\titems: skills,\n\t\t\t},\n\t\t\t{\n\t\t\t\tkind: \"extensions\",\n\t\t\t\tlabel: \"Extensions\",\n\t\t\t\titems: allDiscoverableExtensions.map((extensionPath) => {\n\t\t\t\t\tconst description = getExtensionDescription(extensionPath);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tid: path.resolve(extensionPath),\n\t\t\t\t\t\tlabel: getProfileExtensionDisplayLabel(extensionPath, description),\n\t\t\t\t\t\tpath: extensionPath,\n\t\t\t\t\t\tdescription,\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t},\n\t\t\t{\n\t\t\t\tkind: \"agents\",\n\t\t\t\tlabel: \"Agents\",\n\t\t\t\titems: agents.map((f) => ({\n\t\t\t\t\tid: base(f.path),\n\t\t\t\t\tpath: f.path,\n\t\t\t\t\tdescription: getAgentDescription(f.path),\n\t\t\t\t})),\n\t\t\t},\n\t\t\t{\n\t\t\t\tkind: \"prompts\",\n\t\t\t\tlabel: \"Prompts\",\n\t\t\t\titems: prompts,\n\t\t\t},\n\t\t\t{\n\t\t\t\tkind: \"themes\",\n\t\t\t\tlabel: \"Themes\",\n\t\t\t\titems: themes.map((t) => ({\n\t\t\t\t\tid: t.name,\n\t\t\t\t\tpath: t.path,\n\t\t\t\t})),\n\t\t\t},\n\t\t];\n\t}\n\n\tprivate async openLibraryEditorForProfile(\n\t\tprofileName: string,\n\t\tinitialScope: \"session\" | \"directory\" | \"project\" | \"global\" | \"reusable-file\",\n\t): Promise<void> {\n\t\tconst currentScope = initialScope;\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst profile = registry.getProfile(profileName);\n\t\tif (!profile) {\n\t\t\tthis.ui.showError(`Profile not found: ${profileName}`);\n\t\t\treturn;\n\t\t}\n\n\t\tconst kinds = await this.getProfileResourceKinds();\n\t\tconst originalResources = profile.resources;\n\t\tconst isActiveProfile = this.settingsManager.getActiveResourceProfileNames().includes(profile.name);\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst editor = new ProfileResourceEditorComponent({\n\t\t\t\tprofileName: profile!.name,\n\t\t\t\tprofileScope: currentScope,\n\t\t\t\tinitialResources: profile!.resources,\n\t\t\t\tkinds,\n\t\t\t\tcwd: this.sessionManager.getCwd(),\n\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\texternalResourceRoots: this.settingsManager.getExternalResourceRoots(),\n\t\t\t\tonSave: (resources) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.saveProfileResources(profile, originalResources, resources, currentScope, isActiveProfile);\n\t\t\t\t},\n\t\t\t\tonCancel: () => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.openLibraryManagerFlow();\n\t\t\t\t},\n\t\t\t\tonScopeChange: () => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.promptScopeChangeForProfile(profileName, currentScope);\n\t\t\t\t},\n\t\t\t\tonEdit: async (id, pathValue, kind) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tconst resolvedEditPath = resolveResourceEditPath(id, pathValue, kind);\n\t\t\t\t\tif (!resolvedEditPath) {\n\t\t\t\t\t\tthis.ui.showWarning(`Resource \"${id}\" of kind \"${kind}\" has no editable file path.`);\n\t\t\t\t\t\tvoid this.openLibraryEditorForProfile(profileName, currentScope);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (!fs.existsSync(resolvedEditPath)) {\n\t\t\t\t\t\tthis.ui.showError(`Resolved path for \"${id}\" does not exist: ${resolvedEditPath}`);\n\t\t\t\t\t\tvoid this.openLibraryEditorForProfile(profileName, currentScope);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tawait this.ui.openEditorForPath(resolvedEditPath);\n\t\t\t\t\tawait this.ui.handleReloadCommand();\n\t\t\t\t\tvoid this.openLibraryEditorForProfile(profileName, currentScope);\n\t\t\t\t},\n\t\t\t});\n\n\t\t\treturn { component: editor, focus: editor };\n\t\t});\n\t}\n\n\tprivate async saveProfileResources(\n\t\tprofile: NormalizedProfile,\n\t\toriginalResources: NormalizedProfile[\"resources\"],\n\t\tresources: NormalizedProfile[\"resources\"],\n\t\tscope: WritableProfileScope,\n\t\tisActiveProfile: boolean,\n\t\truntimeMetadataChanged = false,\n\t): Promise<void> {\n\t\tconst definition = {\n\t\t\tname: profile.name,\n\t\t\tdescription: profile.description,\n\t\t\tmodel: profile.model,\n\t\t\tthinking: profile.thinking,\n\t\t\tmodelRouter: profile.modelRouter,\n\t\t\tsoul: profile.soul,\n\t\t\tresources,\n\t\t};\n\t\tconst changedKinds = resourceProfileSettingsChangedKinds(originalResources, resources);\n\t\tif (!isActiveProfile || (changedKinds.size === 0 && !runtimeMetadataChanged)) {\n\t\t\ttry {\n\t\t\t\tthis.settingsManager.setProfileDefinition(profile.name, definition, scope);\n\t\t\t\tthis.ui.showStatus(`Saved profile \"${profile.name}\" to ${scope}.`);\n\t\t\t\tthis.ui.requestRender();\n\t\t\t} catch (error) {\n\t\t\t\tthis.ui.showError(error instanceof Error ? error.message : String(error));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst settingsSnapshot = this.settingsManager.createReloadSnapshot();\n\t\tconst profilesDir = path.join(getAgentDir(), \"profiles\");\n\t\tconst profileFilesSnapshot = scope === \"reusable-file\" ? captureProfileFiles(profilesDir) : undefined;\n\t\tlet stagedRuntimeApplied = false;\n\t\ttry {\n\t\t\t// Validate the edited authority surface as a session overlay first. Persistent scopes are\n\t\t\t// written only after the complete runtime generation passes its reload doctor.\n\t\t\tthis.settingsManager.setProfileDefinition(profile.name, definition, \"session\");\n\t\t\tif (!(await this.ui.handleReloadCommand())) {\n\t\t\t\tthis.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstagedRuntimeApplied = true;\n\n\t\t\tif (scope !== \"session\") {\n\t\t\t\tthis.settingsManager.setProfileDefinition(profile.name, definition, scope);\n\t\t\t\tawait this.settingsManager.flush();\n\t\t\t\t// Drop the validation-only inline winner, then refresh the registry from the now-validated\n\t\t\t\t// persistent definition. The live runtime already represents the same profile definition.\n\t\t\t\tthis.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\t\tawait this.settingsManager.reload();\n\t\t\t}\n\n\t\t\tconst active = this.settingsManager.getActiveResourceProfileNames()[0] ?? \"(none)\";\n\t\t\tthis.ui.footerDataProvider.setExtensionStatus(\"profile\", active);\n\t\t\tthis.ui.invalidateFooter();\n\t\t\tthis.ui.updateEditorBorderColor();\n\t\t\tthis.ui.showStatus(`Saved profile \"${profile.name}\" to ${scope}.`);\n\t\t} catch (error) {\n\t\t\tconst rollbackError = stagedRuntimeApplied\n\t\t\t\t? await this.rollbackValidatedProfileMutation(settingsSnapshot, {\n\t\t\t\t\t\tprofileName: profile.name,\n\t\t\t\t\t\tscope,\n\t\t\t\t\t\tprofileFilesSnapshot,\n\t\t\t\t\t})\n\t\t\t\t: undefined;\n\t\t\tif (!stagedRuntimeApplied) this.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthis.ui.showError(\n\t\t\t\trollbackError\n\t\t\t\t\t? `${message}; rollback failed: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`\n\t\t\t\t\t: message,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async rollbackValidatedProfileMutation(\n\t\tsettingsSnapshot: SettingsReloadSnapshot,\n\t\tdefinition?: ProfileDefinitionRollbackTarget,\n\t): Promise<unknown> {\n\t\tconst errors: string[] = [];\n\t\ttry {\n\t\t\tif (definition?.scope === \"reusable-file\") {\n\t\t\t\trestoreProfileFiles(path.join(getAgentDir(), \"profiles\"), definition.profileFilesSnapshot!);\n\t\t\t} else if (definition && definition.scope !== \"session\") {\n\t\t\t\tthis.settingsManager.restoreProfileDefinitionFromReloadSnapshot(\n\t\t\t\t\tdefinition.profileName,\n\t\t\t\t\tdefinition.scope,\n\t\t\t\t\tsettingsSnapshot,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst global = settingsSnapshot.globalSettings;\n\t\t\tthis.settingsManager.replaceGlobalResourceProfileConfiguration({\n\t\t\t\tresourceProfiles: global.resourceProfiles,\n\t\t\t\tactiveResourceProfile: global.activeResourceProfile,\n\t\t\t\tactiveResourceProfiles: global.activeResourceProfiles,\n\t\t\t\texternalResourceRoots: global.externalResourceRoots,\n\t\t\t\ttrustedResourceRoots: global.trustedResourceRoots,\n\t\t\t});\n\t\t\tawait this.settingsManager.flush();\n\t\t} catch (error) {\n\t\t\terrors.push(`persistence: ${error instanceof Error ? error.message : String(error)}`);\n\t\t}\n\t\tthis.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\ttry {\n\t\t\tif (!(await this.ui.handleReloadCommand())) {\n\t\t\t\terrors.push(\"runtime: the previous profile runtime could not be restored\");\n\t\t\t}\n\t\t} catch (error) {\n\t\t\terrors.push(`runtime: ${error instanceof Error ? error.message : String(error)}`);\n\t\t}\n\t\treturn errors.length > 0 ? new Error(errors.join(\"; \")) : undefined;\n\t}\n\n\tprivate async promptScopeChangeForProfile(\n\t\tprofileName: string,\n\t\tcurrentScope: \"session\" | \"directory\" | \"project\" | \"global\" | \"reusable-file\",\n\t): Promise<void> {\n\t\tconst scopeOptions = [\n\t\t\t{ value: \"session\", label: \"session\", description: \"Runtime only (not written to disk)\" },\n\t\t\t{\n\t\t\t\tvalue: \"directory\",\n\t\t\t\tlabel: \"directory\",\n\t\t\t\tdescription: \"~/.pi/agent/resource-profiles/<hash>/settings.json\",\n\t\t\t},\n\t\t\t{ value: \"project\", label: \"project\", description: \".pi/settings.json\" },\n\t\t\t{ value: \"global\", label: \"global\", description: \"~/.pi/agent/settings.json\" },\n\t\t];\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\"Change Profile / Situation Scope\",\n\t\t\t\t`Select new scope for profile/situation \"${profileName}\".`,\n\t\t\t\tscopeOptions,\n\t\t\t\tcurrentScope,\n\t\t\t\t(value) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.openLibraryEditorForProfile(profileName, value as any);\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.openLibraryEditorForProfile(profileName, currentScope);\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tasync handleProfilesCommand(profileName?: string): Promise<void> {\n\t\tif (profileName) {\n\t\t\tawait this.applyProfile(profileName);\n\t\t\treturn;\n\t\t}\n\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst profiles = registry.listProfiles();\n\t\tif (profiles.length === 0) {\n\t\t\tthis.ui.showWarning(\n\t\t\t\t\"No profiles found. Add resourceProfiles to settings or JSON files under ~/.pi/agent/profiles/.\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new ProfileSelectorComponent(\n\t\t\t\tprofiles,\n\t\t\t\tthis.settingsManager.getActiveResourceProfileNames(),\n\t\t\t\t(profile) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.applyProfile(profile);\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tthis.ui.requestRender();\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tprivate async applyProfile(profileName: string): Promise<void> {\n\t\tconst normalizedName = profileName.trim();\n\t\tconst normalizedLower = normalizedName.toLowerCase();\n\t\tif (normalizedName.length === 0 || normalizedLower === \"none\" || normalizedLower === \"(none)\") {\n\t\t\tconst settingsSnapshot = this.settingsManager.createReloadSnapshot();\n\t\t\tlet stagedRuntimeApplied = false;\n\t\t\ttry {\n\t\t\t\tthis.settingsManager.setRuntimeResourceProfiles([]);\n\t\t\t\tif (!(await this.ui.handleReloadCommand())) {\n\t\t\t\t\tthis.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tstagedRuntimeApplied = true;\n\t\t\t\t// Persist only after the new runtime generation passes its reload doctor.\n\t\t\t\tthis.settingsManager.setActiveProfile(undefined, \"global\");\n\t\t\t\tawait this.settingsManager.flush();\n\t\t\t\tthis.session.sessionManager.appendCustomEntry(\"pi.activeResourceProfiles\", {\n\t\t\t\t\tprofiles: [],\n\t\t\t\t});\n\t\t\t\tconst activeProfileName = this.settingsManager.getActiveResourceProfileNames()[0] ?? \"(none)\";\n\t\t\t\tthis.ui.footerDataProvider.setExtensionStatus(\"profile\", activeProfileName);\n\t\t\t\tthis.ui.invalidateFooter();\n\t\t\t\tthis.ui.updateEditorBorderColor();\n\t\t\t\tthis.ui.showStatus(`Profile: ${activeProfileName}`);\n\t\t\t} catch (error) {\n\t\t\t\tconst rollbackError = stagedRuntimeApplied\n\t\t\t\t\t? await this.rollbackValidatedProfileMutation(settingsSnapshot)\n\t\t\t\t\t: undefined;\n\t\t\t\tif (!stagedRuntimeApplied) this.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\tthis.ui.showError(\n\t\t\t\t\trollbackError\n\t\t\t\t\t\t? `${message}; rollback failed: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`\n\t\t\t\t\t\t: message,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst profile =\n\t\t\tnormalizedName.startsWith(\"./\") || normalizedName.startsWith(\"../\")\n\t\t\t\t? registry.resolveProfileRef(normalizedName, this.sessionManager.getCwd())\n\t\t\t\t: registry.getProfile(normalizedName);\n\t\tif (!profile) {\n\t\t\tthis.ui.showError(`Profile not found: ${profileName}`);\n\t\t\treturn;\n\t\t}\n\n\t\tconst settingsSnapshot = this.settingsManager.createReloadSnapshot();\n\t\tconst modelRegistrySnapshot = profile.model ? this.session.modelRegistry.createReloadSnapshot() : undefined;\n\t\tlet stagedRuntimeApplied = false;\n\t\ttry {\n\t\t\tconst activeProfileRef =\n\t\t\t\tnormalizedName.startsWith(\"./\") || normalizedName.startsWith(\"../\") ? normalizedName : profile.name;\n\t\t\tlet requestedModel: Model<Api> | undefined;\n\t\t\tif (profile.model) {\n\t\t\t\tthis.session.modelRegistry.refresh();\n\t\t\t\tconst resolved = resolveCliModel({ cliModel: profile.model, modelRegistry: this.session.modelRegistry });\n\t\t\t\t// The profile may grant an extension that contributes this model. The current generation\n\t\t\t\t// cannot validate that case; the atomic reload binds new providers before authoritative\n\t\t\t\t// profile resolution and rolls back if the model is still unresolved.\n\t\t\t\tif (!resolved.error && resolved.warning) {\n\t\t\t\t\tthis.ui.showWarning(resolved.warning);\n\t\t\t\t}\n\t\t\t\tif (!resolved.error) requestedModel = resolved.model;\n\t\t\t}\n\n\t\t\t// Stage the complete situation in memory. Runtime reload applies model/thinking, resource\n\t\t\t// grants, extensions, skills, prompts, and soul together; explicit launch overrides still win.\n\t\t\tthis.settingsManager.setRuntimeResourceProfiles([activeProfileRef]);\n\t\t\tif (!(await this.ui.handleReloadCommand())) {\n\t\t\t\tthis.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\t\tif (modelRegistrySnapshot) this.session.modelRegistry.restoreReloadSnapshot(modelRegistrySnapshot);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstagedRuntimeApplied = true;\n\n\t\t\t// Selection survives restarts only after the new runtime generation passes its reload doctor.\n\t\t\tthis.settingsManager.setActiveProfile(activeProfileRef, \"global\");\n\t\t\tawait this.settingsManager.flush();\n\t\t\tthis.session.sessionManager.appendCustomEntry(\"pi.activeResourceProfiles\", {\n\t\t\t\tprofiles: [activeProfileRef],\n\t\t\t});\n\t\t\tthis.ui.footerDataProvider.setExtensionStatus(\"profile\", profile.name);\n\t\t\tthis.ui.invalidateFooter();\n\t\t\tthis.ui.updateEditorBorderColor();\n\t\t\tthis.ui.showStatus(`Profile: ${profile.name}`);\n\t\t\tif (\n\t\t\t\trequestedModel &&\n\t\t\t\tthis.session.model?.provider === requestedModel.provider &&\n\t\t\t\tthis.session.model.id === requestedModel.id\n\t\t\t) {\n\t\t\t\tvoid this.ui.maybeWarnAboutAnthropicSubscriptionAuth(requestedModel);\n\t\t\t\tthis.ui.checkDaxnutsEasterEgg(requestedModel);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst rollbackError = stagedRuntimeApplied\n\t\t\t\t? await this.rollbackValidatedProfileMutation(settingsSnapshot)\n\t\t\t\t: undefined;\n\t\t\tif (!stagedRuntimeApplied) this.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\tif (modelRegistrySnapshot) this.session.modelRegistry.restoreReloadSnapshot(modelRegistrySnapshot);\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthis.ui.showError(\n\t\t\t\trollbackError\n\t\t\t\t\t? `${message}; rollback failed: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`\n\t\t\t\t\t: message,\n\t\t\t);\n\t\t}\n\t}\n\n\t/** Map where a profile currently lives to the scope we should write it back to. */\n\tprivate scopeForProfileSource(source: string): WritableProfileScope {\n\t\tswitch (source) {\n\t\t\tcase \"profile-file\":\n\t\t\t\treturn \"reusable-file\";\n\t\t\tcase \"directory-overlay\":\n\t\t\tcase \"embedded\":\n\t\t\t\treturn \"directory\";\n\t\t\tcase \"project-settings\":\n\t\t\t\treturn \"project\";\n\t\t\tcase \"inline\":\n\t\t\t\treturn \"session\";\n\t\t\tdefault:\n\t\t\t\treturn \"global\";\n\t\t}\n\t}\n\n\tasync refreshAfterProfileMutation(profileName: string): Promise<void> {\n\t\tif (this.settingsManager.getActiveResourceProfileNames().includes(profileName)) {\n\t\t\tif (!(await this.ui.handleReloadCommand())) return;\n\t\t\tconst active = this.settingsManager.getActiveResourceProfileNames()[0] ?? \"(none)\";\n\t\t\tthis.ui.footerDataProvider.setExtensionStatus(\"profile\", active);\n\t\t\tthis.ui.invalidateFooter();\n\t\t\tthis.ui.updateEditorBorderColor();\n\t\t}\n\t}\n\n\tprivate async createProfileFlow(): Promise<void> {\n\t\tconst name = await new Promise<string | undefined>((resolve) => {\n\t\t\tthis.ui.showSelector((done) => {\n\t\t\t\tconst input = new ExtensionInputComponent(\n\t\t\t\t\t\"Create Profile / Situation\",\n\t\t\t\t\t\"Enter profile/situation name\",\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(value);\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t},\n\t\t\t\t\t{ tui: this.ui.tui },\n\t\t\t\t);\n\t\t\t\treturn { component: input, focus: input, onSuperseded: () => resolve(undefined) };\n\t\t\t});\n\t\t});\n\n\t\tif (name === undefined) {\n\t\t\tthis.ui.requestRender();\n\t\t\treturn;\n\t\t}\n\n\t\tconst trimmed = name.trim();\n\t\tif (!trimmed) {\n\t\t\tthis.ui.showError(\"Profile/situation name cannot be empty\");\n\t\t\treturn this.createProfileFlow();\n\t\t}\n\n\t\t// Validate name rules using validateSkillName\n\t\tconst errors = validateSkillName(trimmed);\n\t\tif (errors.length > 0) {\n\t\t\tthis.ui.showError(`Invalid profile/situation name: ${errors.join(\", \")}`);\n\t\t\treturn this.createProfileFlow();\n\t\t}\n\n\t\t// Collision check\n\t\tconst existing = this.settingsManager.getProfileRegistry().getProfile(trimmed);\n\t\tif (existing) {\n\t\t\tthis.ui.showError(`Profile/situation \"${trimmed}\" already exists`);\n\t\t\treturn this.createProfileFlow();\n\t\t}\n\n\t\tconst profileModel = await this.selectProfileModel();\n\t\tif (profileModel === undefined) {\n\t\t\tthis.ui.requestRender();\n\t\t\treturn;\n\t\t}\n\n\t\t// Open the resource editor on the NEW profile\n\t\tvoid this.openNewProfileEditor(trimmed, profileModel ?? undefined);\n\t}\n\n\tprivate async selectProfileModel(profileModel?: string): Promise<string | null | undefined> {\n\t\tconst inheritValue = \"(inherit)\";\n\t\tconst availableModelOptions = [...this.ui.getAutoLearnModelOptions()];\n\t\tif (profileModel && !availableModelOptions.some((option) => option.value === profileModel)) {\n\t\t\tavailableModelOptions.unshift({\n\t\t\t\tvalue: profileModel,\n\t\t\t\tlabel: profileModel,\n\t\t\t\tdescription: \"Current profile model (not currently available)\",\n\t\t\t});\n\t\t}\n\t\tconst modelOptions = [\n\t\t\t{\n\t\t\t\tvalue: inheritValue,\n\t\t\t\tlabel: \"Inherit session/default model\",\n\t\t\t\tdescription: \"Remove the profile model pin and use the current session/default model\",\n\t\t\t},\n\t\t\t...availableModelOptions,\n\t\t];\n\n\t\treturn await new Promise<string | null | undefined>((resolve) => {\n\t\t\tthis.ui.showSelector((done) => {\n\t\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\t\"Profile Model\",\n\t\t\t\t\t\"Pin a foreground model for this profile or inherit the session/default model.\",\n\t\t\t\t\tmodelOptions,\n\t\t\t\t\tprofileModel ?? inheritValue,\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(value === inheritValue ? null : value);\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tcomponent: selector,\n\t\t\t\t\tfocus: selector.getSelectList(),\n\t\t\t\t\tonSuperseded: () => resolve(undefined),\n\t\t\t\t};\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate async openNewProfileEditor(profileName: string, profileModel?: string): Promise<void> {\n\t\tconst scope = \"reusable-file\";\n\t\tconst kinds = await this.getProfileResourceKinds();\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst editor = new ProfileResourceEditorComponent({\n\t\t\t\tprofileName,\n\t\t\t\tprofileScope: scope,\n\t\t\t\tinitialResources: {},\n\t\t\t\tkinds,\n\t\t\t\tcwd: this.sessionManager.getCwd(),\n\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\texternalResourceRoots: this.settingsManager.getExternalResourceRoots(),\n\t\t\t\tonSave: (resources) => {\n\t\t\t\t\tdone();\n\t\t\t\t\ttry {\n\t\t\t\t\t\tthis.settingsManager.setProfileDefinition(\n\t\t\t\t\t\t\tprofileName,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: profileName,\n\t\t\t\t\t\t\t\tmodel: profileModel,\n\t\t\t\t\t\t\t\tresources,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tscope,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.ui.showStatus(`Saved profile \"${profileName}\" to ${scope}.`);\n\t\t\t\t\t\tthis.ui.requestRender();\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tthis.ui.showError(error instanceof Error ? error.message : String(error));\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tonCancel: () => {\n\t\t\t\t\tdone();\n\t\t\t\t\tthis.ui.requestRender();\n\t\t\t\t},\n\t\t\t\tonEdit: async (id, pathValue, kind) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tconst resolvedEditPath = resolveResourceEditPath(id, pathValue, kind);\n\t\t\t\t\tif (!resolvedEditPath) {\n\t\t\t\t\t\tthis.ui.showWarning(`Resource \"${id}\" of kind \"${kind}\" has no editable file path.`);\n\t\t\t\t\t\tvoid this.openNewProfileEditor(profileName, profileModel);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (!fs.existsSync(resolvedEditPath)) {\n\t\t\t\t\t\tthis.ui.showError(`Resolved path for \"${id}\" does not exist: ${resolvedEditPath}`);\n\t\t\t\t\t\tvoid this.openNewProfileEditor(profileName, profileModel);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tawait this.ui.openEditorForPath(resolvedEditPath);\n\t\t\t\t\tawait this.ui.handleReloadCommand();\n\t\t\t\t\tvoid this.openNewProfileEditor(profileName, profileModel);\n\t\t\t\t},\n\t\t\t});\n\t\t\treturn { component: editor, focus: editor };\n\t\t});\n\t}\n\n\tprivate persistActiveProfile(scope: \"session\" | \"directory\" | \"project\" | \"global\"): void {\n\t\tconst active = this.settingsManager.getActiveResourceProfileNames()[0];\n\t\tif (!active) {\n\t\t\tthis.ui.showError(\"No active profile to persist. Select one with /profiles first.\");\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tif (scope === \"session\") {\n\t\t\t\tthis.settingsManager.setRuntimeResourceProfiles([active]);\n\t\t\t} else {\n\t\t\t\tthis.settingsManager.setActiveProfile(active, scope);\n\t\t\t}\n\t\t\tthis.ui.showStatus(`Active profile \"${active}\" persisted to ${scope}.`);\n\t\t} catch (error) {\n\t\t\tthis.ui.showError(error instanceof Error ? error.message : String(error));\n\t\t}\n\t}\n\n\tprivate async deleteProfileFromSource(profileName: string): Promise<void> {\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst profile = registry.getProfile(profileName);\n\t\tif (!profile) {\n\t\t\tthis.ui.showError(`Profile not found: ${profileName}`);\n\t\t\treturn;\n\t\t}\n\t\tconst scope = deletionScopeForProfile(profile);\n\t\tif (!scope) {\n\t\t\tconst location = profile.sourcePath ? ` at ${profile.sourcePath}` : \"\";\n\t\t\tthis.ui.showError(\n\t\t\t\t`Profile \"${profileName}\" comes from read-only source ${profile.source}${location}; edit or remove that source definition directly.`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst wasActive = this.settingsManager.getActiveResourceProfileNames().some((profileRef) => {\n\t\t\tif (profileRef === profileName || profileRef === profile.name) return true;\n\t\t\tconst activeProfile =\n\t\t\t\tprofileRef.startsWith(\"./\") || profileRef.startsWith(\"../\")\n\t\t\t\t\t? registry.resolveProfileRef(profileRef, this.sessionManager.getCwd())\n\t\t\t\t\t: registry.getProfile(profileRef);\n\t\t\treturn Boolean(\n\t\t\t\tactiveProfile && activeProfile.name === profile.name && activeProfile.sourcePath === profile.sourcePath,\n\t\t\t);\n\t\t});\n\t\tconst settingsSnapshot = this.settingsManager.createReloadSnapshot();\n\t\tconst profileFilesSnapshot =\n\t\t\tscope === \"reusable-file\" ? captureProfileFiles(path.join(getAgentDir(), \"profiles\")) : undefined;\n\t\tlet switchedToNone = false;\n\t\ttry {\n\t\t\tif (wasActive) {\n\t\t\t\t// Stage an explicit empty runtime selection while the definition is still intact. The\n\t\t\t\t// full reload can now remove the profile's extensions, tools, providers, model, and\n\t\t\t\t// memory generation atomically. Persisting the deletion is deliberately deferred until\n\t\t\t\t// that generation passes its doctor, so a failed reload has no on-disk deletion to undo.\n\t\t\t\tthis.settingsManager.setRuntimeResourceProfiles([]);\n\t\t\t\tif (!(await this.ui.handleReloadCommand())) {\n\t\t\t\t\tthis.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tswitchedToNone = true;\n\t\t\t}\n\n\t\t\tthis.settingsManager.deleteProfile(profileName, scope);\n\t\t\tconst remaining = this.settingsManager.getProfileRegistry().getProfile(profileName);\n\t\t\tif (remaining && remaining.source === profile.source && remaining.sourcePath === profile.sourcePath) {\n\t\t\t\tthrow new Error(`Profile \"${profileName}\" was not removed from ${profile.source}.`);\n\t\t\t}\n\t\t\tif (wasActive) {\n\t\t\t\tthis.settingsManager.setActiveProfile(undefined, \"global\");\n\t\t\t\tawait this.settingsManager.flush();\n\t\t\t\tthis.session.sessionManager.appendCustomEntry(\"pi.activeResourceProfiles\", { profiles: [] });\n\t\t\t\tthis.ui.footerDataProvider.setExtensionStatus(\"profile\", \"(none)\");\n\t\t\t\tthis.ui.invalidateFooter();\n\t\t\t\tthis.ui.updateEditorBorderColor();\n\t\t\t}\n\t\t\tthis.ui.showStatus(`Deleted profile \"${profileName}\" from ${scope}.`);\n\t\t} catch (error) {\n\t\t\tconst rollbackError = switchedToNone\n\t\t\t\t? await this.rollbackValidatedProfileMutation(settingsSnapshot, {\n\t\t\t\t\t\tprofileName,\n\t\t\t\t\t\tscope,\n\t\t\t\t\t\tprofileFilesSnapshot,\n\t\t\t\t\t})\n\t\t\t\t: undefined;\n\t\t\tif (!switchedToNone) this.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthis.ui.showError(\n\t\t\t\trollbackError\n\t\t\t\t\t? `${message}; rollback failed: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`\n\t\t\t\t\t: message,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async addExternalResourceRootFlow(): Promise<void> {\n\t\tconst rootPath = await new Promise<string | undefined>((resolve) => {\n\t\t\tthis.ui.showSelector((done) => {\n\t\t\t\tconst input = new ExtensionInputComponent(\n\t\t\t\t\t\"Add External Root\",\n\t\t\t\t\t\"Enter external root directory path\",\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(value);\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t},\n\t\t\t\t\t{ tui: this.ui.tui },\n\t\t\t\t);\n\t\t\t\treturn { component: input, focus: input, onSuperseded: () => resolve(undefined) };\n\t\t\t});\n\t\t});\n\n\t\tif (rootPath === undefined) {\n\t\t\tthis.ui.requestRender();\n\t\t\treturn;\n\t\t}\n\n\t\tconst trimmed = rootPath.trim();\n\t\tif (!trimmed) {\n\t\t\tthis.ui.showError(\"Directory path cannot be empty\");\n\t\t\treturn;\n\t\t}\n\n\t\tconst canonical = this.settingsManager.canonicalizePath(trimmed);\n\t\tif (!canonical) {\n\t\t\tthis.ui.showError(`Invalid path: ${trimmed}`);\n\t\t\treturn;\n\t\t}\n\n\t\t// Prompt for trust confirmation (Yes/No)\n\t\tconst trust = await new Promise<boolean>((resolve) => {\n\t\t\tthis.ui.showSelector((done) => {\n\t\t\t\tconst submenu = new SelectSubmenu(\n\t\t\t\t\t\"Trust external source?\",\n\t\t\t\t\t\"This directory can load custom extensions that execute arbitrary code on your machine.\",\n\t\t\t\t\t[\n\t\t\t\t\t\t{ value: \"yes\", label: \"Yes\", description: \"Trust this directory and enable loading resources.\" },\n\t\t\t\t\t\t{ value: \"no\", label: \"No\", description: \"Do not trust this directory. Skip loading resources.\" },\n\t\t\t\t\t],\n\t\t\t\t\t\"no\",\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(value === \"yes\");\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(false);\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tcomponent: submenu,\n\t\t\t\t\tfocus: submenu.getSelectList(),\n\t\t\t\t\tonSuperseded: () => resolve(false),\n\t\t\t\t};\n\t\t\t});\n\t\t});\n\n\t\tif (!trust) {\n\t\t\tthis.ui.showStatus(\"Aborted. External root was not trusted.\");\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst currentRoots = this.settingsManager.getExternalResourceRoots();\n\t\t\tif (!currentRoots.includes(canonical)) {\n\t\t\t\tthis.settingsManager.setExternalResourceRoots([...currentRoots, canonical], \"global\");\n\t\t\t}\n\t\t\tthis.settingsManager.addTrustedResourceRoot(canonical, \"global\");\n\t\t\tthis.ui.showStatus(`Added trusted external root: ${canonical}`);\n\t\t\tawait this.ui.handleReloadCommand();\n\t\t} catch (error) {\n\t\t\tthis.ui.showError(error instanceof Error ? error.message : String(error));\n\t\t}\n\t}\n\n\tprivate async removeExternalResourceRootFlow(root: string): Promise<void> {\n\t\ttry {\n\t\t\tconst currentRoots = this.settingsManager.getExternalResourceRoots();\n\t\t\tconst currentTrusted = this.settingsManager.getTrustedResourceRoots();\n\n\t\t\tconst newRoots = currentRoots.filter((r) => r !== root);\n\t\t\tconst newTrusted = currentTrusted.filter((r) => r !== root);\n\n\t\t\tthis.settingsManager.setExternalResourceRoots(newRoots, \"global\");\n\t\t\tthis.settingsManager.setTrustedResourceRoots(newTrusted, \"global\");\n\n\t\t\tthis.ui.showStatus(`Removed external root: ${root}`);\n\t\t\tawait this.ui.handleReloadCommand();\n\t\t} catch (error) {\n\t\t\tthis.ui.showError(error instanceof Error ? error.message : String(error));\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"profile-menu-controller.d.ts","sourceRoot":"","sources":["../../../src/modes/interactive/profile-menu-controller.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAErE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAqBhE,eAAO,MAAM,6BAA6B,wFAC4C,CAAC;AA8BvF,MAAM,WAAW,uBAAuB;IACvC,YAAY,CACX,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,IAAI,KAAK;QAC7B,SAAS,EAAE,SAAS,CAAC;QACrB,KAAK,EAAE,SAAS,CAAC;QACjB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;KAC1B,GACC,IAAI,CAAC;IACR,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,aAAa,IAAI,IAAI,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,kBAAkB,EAAE;QAAE,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG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EpB,gCAAgC;YAsChC,2BAA2B;IAkCnC,qBAAqB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA8B/D;YAEa,YAAY;IA+G1B,mFAAmF;IACnF,OAAO,CAAC,qBAAqB;IAgBvB,2BAA2B,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQpE;YAEa,iBAAiB;YAuDjB,kBAAkB;YA4ClB,oBAAoB;IAwDlC,OAAO,CAAC,oBAAoB;YAkBd,uBAAuB;YA0EvB,2BAA2B;YAmF3B,8BAA8B;CAiB5C","sourcesContent":["/**\n * Resource-profile & external-source menu controller.\n *\n * Extracted verbatim from interactive-mode.ts (god-file decomposition). Owns the /profiles command\n * and the resource-hub menu tree: active-profile selection, profile create/delete/persist, the\n * library (per-profile resource grants) editor, and external-source root management. It holds NO\n * state of its own — every profile/source fact lives in settingsManager / the profile registry /\n * the session resourceLoader — so it takes narrow deps (a live session accessor plus a UI callback\n * surface, including the editor-overlay-backed showSelector) rather than the whole InteractiveMode\n * instance.\n */\n\nimport * as fs from \"node:fs\";\nimport * as path from \"node:path\";\nimport type { Api, Model } from \"@caupulican/pi-ai\";\nimport type { Component, SelectItem, TUI } from \"@caupulican/pi-tui\";\nimport { getAgentDir, getProfilesDir } from \"../../config.ts\";\nimport type { AgentSession } from \"../../core/agent-session.ts\";\nimport { resolveCliModel } from \"../../core/model-resolver.ts\";\nimport type { NormalizedProfile } from \"../../core/profile-registry.ts\";\nimport { resourceProfileSettingsChangedKinds } from \"../../core/resource-profile-equality.ts\";\nimport type { SettingsReloadSnapshot } from \"../../core/settings-manager.ts\";\nimport { validateSkillName } from \"../../core/skills.ts\";\nimport { allToolNames } from \"../../core/tools/index.ts\";\nimport { parseFrontmatter } from \"../../utils/frontmatter.ts\";\nimport { ExtensionInputComponent } from \"./components/extension-input.ts\";\nimport {\n\tProfileResourceEditorComponent,\n\ttype ProfileResourceEditorKind,\n\tresolveResourceEditPath,\n} from \"./components/profile-resource-editor.ts\";\nimport { ProfileSelectorComponent } from \"./components/profile-selector.ts\";\nimport { SelectSubmenu } from \"./components/settings-selector.ts\";\nimport { captureProfileFiles, restoreProfileFiles } from \"./config-backup.ts\";\nimport { getAvailableThemesWithPaths } from \"./theme/theme.ts\";\n\ntype WritableProfileScope = \"session\" | \"directory\" | \"project\" | \"global\" | \"reusable-file\";\n\nexport const NO_ACTIVE_PROFILE_DESCRIPTION =\n\t\"Baseline resources; inline SDK extensions load, discovered extensions stay withheld\";\n\nfunction deletionScopeForProfile(profile: NormalizedProfile): WritableProfileScope | undefined {\n\tswitch (profile.source) {\n\t\tcase \"inline\":\n\t\t\treturn \"session\";\n\t\tcase \"directory-overlay\":\n\t\t\treturn \"directory\";\n\t\tcase \"project-settings\":\n\t\t\treturn \"project\";\n\t\tcase \"global-settings\":\n\t\t\treturn \"global\";\n\t\tcase \"profile-file\": {\n\t\t\tconst localProfilePath = path.resolve(getProfilesDir(), `${profile.name}.json`);\n\t\t\treturn profile.sourcePath && path.resolve(profile.sourcePath) === localProfilePath\n\t\t\t\t? \"reusable-file\"\n\t\t\t\t: undefined;\n\t\t}\n\t\tcase \"embedded\":\n\t\tcase \"external-settings\":\n\t\t\treturn undefined;\n\t}\n}\n\ninterface ProfileDefinitionRollbackTarget {\n\tprofileName: string;\n\tscope: WritableProfileScope;\n\tprofileFilesSnapshot?: ReturnType<typeof captureProfileFiles>;\n}\n\nexport interface ProfileMenuControllerUi {\n\tshowSelector(\n\t\tcreate: (done: () => void) => {\n\t\t\tcomponent: Component;\n\t\t\tfocus: Component;\n\t\t\tonSuperseded?: () => void;\n\t\t},\n\t): void;\n\tshowStatus(message: string): void;\n\tshowError(message: string): void;\n\tshowWarning(message: string): void;\n\trequestRender(): void;\n\treadonly tui: TUI;\n\treadonly footerDataProvider: { setExtensionStatus(key: string, text: string | undefined): void };\n\tinvalidateFooter(): void;\n\tupdateEditorBorderColor(): void;\n\topenEditorForPath(filePath: string): Promise<boolean>;\n\thandleReloadCommand(): Promise<boolean>;\n\tmaybeWarnAboutAnthropicSubscriptionAuth(model?: Model<Api>): void;\n\tcheckDaxnutsEasterEgg(model: { provider: string; id: string }): void;\n\tshowSettingsSelector(): void;\n\tgetAutoLearnModelOptions(): SelectItem[];\n}\n\nexport interface ProfileMenuControllerDeps {\n\tgetSession(): AgentSession;\n\tui: ProfileMenuControllerUi;\n}\n\nfunction portableBasename(filePath: string): string {\n\treturn filePath.split(/[\\\\/]/).filter(Boolean).pop() ?? filePath;\n}\n\nexport function getProfileExtensionDisplayLabel(filePath: string, description?: string): string {\n\tconst normalizedDescription = description?.trim();\n\tif (normalizedDescription) return normalizedDescription;\n\tconst fileName = portableBasename(filePath);\n\tif (!/^index\\.(?:ts|js)$/i.test(fileName)) return fileName;\n\tconst parentPath = filePath.slice(0, Math.max(0, filePath.length - fileName.length)).replace(/[\\\\/]$/, \"\");\n\treturn portableBasename(parentPath) || fileName;\n}\n\nexport class ProfileMenuController {\n\tprivate readonly deps: ProfileMenuControllerDeps;\n\n\tconstructor(deps: ProfileMenuControllerDeps) {\n\t\tthis.deps = deps;\n\t}\n\n\tprivate get session(): AgentSession {\n\t\treturn this.deps.getSession();\n\t}\n\tprivate get sessionManager() {\n\t\treturn this.deps.getSession().sessionManager;\n\t}\n\tprivate get settingsManager() {\n\t\treturn this.deps.getSession().settingsManager;\n\t}\n\tprivate get ui(): ProfileMenuControllerUi {\n\t\treturn this.deps.ui;\n\t}\n\n\tasync handleResourcesHubAction(action: string): Promise<void> {\n\t\tswitch (action) {\n\t\t\tcase \"nudge-add-source\":\n\t\t\t\tvoid this.addExternalResourceRootFlow().then(() => {\n\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\tcase \"active-profile\":\n\t\t\t\tvoid this.openActiveProfileSelector();\n\t\t\t\tbreak;\n\t\t\tcase \"manage-library\":\n\t\t\t\tvoid this.openLibraryManagerFlow();\n\t\t\t\tbreak;\n\t\t\tcase \"manage-profiles\":\n\t\t\t\tvoid this.openManageProfilesFlow();\n\t\t\t\tbreak;\n\t\t\tcase \"sources\":\n\t\t\t\tvoid this.openSourcesManagerFlow();\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tprivate async openActiveProfileSelector(): Promise<void> {\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst profiles = registry.listProfiles();\n\t\tconst activeNames = this.settingsManager.getActiveResourceProfileNames();\n\n\t\tconst options = [\n\t\t\t{ value: \"(none)\", label: \"(none)\", description: NO_ACTIVE_PROFILE_DESCRIPTION },\n\t\t\t...profiles.map((p) => ({\n\t\t\t\tvalue: p.name,\n\t\t\t\tlabel: p.name,\n\t\t\t\tdescription: p.description || p.source,\n\t\t\t})),\n\t\t];\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\"Profile / Situation\",\n\t\t\t\t\"Select the active runtime profile/situation for this session. This is session-only unless saved elsewhere.\",\n\t\t\t\toptions,\n\t\t\t\tactiveNames[0] || \"(none)\",\n\t\t\t\t(value) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.applyProfile(value === \"(none)\" ? \"\" : value).then(() => {\n\t\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tprivate async openManageProfilesFlow(): Promise<void> {\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst profiles = registry.listProfiles();\n\t\tconst editableProfiles = profiles.map((p) => ({\n\t\t\tvalue: p.name,\n\t\t\tlabel: p.name,\n\t\t\tdescription: p.description || p.source,\n\t\t}));\n\n\t\tconst options = [\n\t\t\t{\n\t\t\t\tvalue: \"create\",\n\t\t\t\tlabel: \"+ Create profile / situation...\",\n\t\t\t\tdescription: \"Create a new resource profile/situation definition.\",\n\t\t\t},\n\t\t];\n\n\t\tif (editableProfiles.length > 0) {\n\t\t\toptions.push({\n\t\t\t\tvalue: \"edit-model\",\n\t\t\t\tlabel: \"Edit profile model...\",\n\t\t\t\tdescription: \"Pin a model or inherit the session/default model.\",\n\t\t\t});\n\t\t}\n\n\t\tif (this.settingsManager.getActiveResourceProfileNames().length > 0) {\n\t\t\toptions.push({\n\t\t\t\tvalue: \"persist\",\n\t\t\t\tlabel: \"Persist active profile / situation to...\",\n\t\t\t\tdescription: \"Save the current active profile/situation selection so it survives restart.\",\n\t\t\t});\n\t\t}\n\n\t\tif (editableProfiles.length > 0) {\n\t\t\toptions.push({\n\t\t\t\tvalue: \"delete\",\n\t\t\t\tlabel: \"Delete profile / situation...\",\n\t\t\t\tdescription: \"Remove a profile/situation definition from where it is stored.\",\n\t\t\t});\n\t\t}\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\"Manage Profiles / Situations\",\n\t\t\t\t\"Create, edit, delete, or persist profile/situation definitions.\",\n\t\t\t\toptions,\n\t\t\t\t\"\",\n\t\t\t\t(value) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tif (value === \"create\") {\n\t\t\t\t\t\tvoid this.createProfileFlow().then(() => {\n\t\t\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t\t\t});\n\t\t\t\t\t} else if (value === \"edit-model\") {\n\t\t\t\t\t\tthis.openEditProfileModelSelector();\n\t\t\t\t\t} else if (value === \"persist\") {\n\t\t\t\t\t\tvoid this.openPersistProfileSelector();\n\t\t\t\t\t} else if (value === \"delete\") {\n\t\t\t\t\t\tvoid this.openDeleteProfileSelector();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tprivate openEditProfileModelSelector(): void {\n\t\tconst profiles = this.settingsManager\n\t\t\t.getProfileRegistry()\n\t\t\t.listProfiles()\n\t\t\t.filter((profile) => deletionScopeForProfile(profile) !== undefined);\n\t\tif (profiles.length === 0) {\n\t\t\tthis.ui.showStatus(\"No writable profiles available. External and embedded profiles are read-only.\");\n\t\t\treturn;\n\t\t}\n\t\tconst activeNames = this.settingsManager.getActiveResourceProfileNames();\n\t\tconst initialValue = profiles.find((profile) => activeNames.includes(profile.name))?.name ?? profiles[0].name;\n\t\tconst items = profiles.map((profile) => ({\n\t\t\tvalue: profile.name,\n\t\t\tlabel: profile.name,\n\t\t\tdescription: `${profile.model ? `Pinned: ${profile.model}` : \"Inherits session/default model\"} · ${profile.description || profile.source}`,\n\t\t}));\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\"Edit Profile Model\",\n\t\t\t\t\"Choose a writable profile, then pin or inherit its foreground model.\",\n\t\t\t\titems,\n\t\t\t\tinitialValue,\n\t\t\t\t(profileName) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.editProfileModel(profileName);\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.openManageProfilesFlow();\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tprivate async editProfileModel(profileName: string): Promise<void> {\n\t\tconst profile = this.settingsManager.getProfileRegistry().getProfile(profileName);\n\t\tif (!profile) {\n\t\t\tthis.ui.showError(`Profile \"${profileName}\" is no longer available.`);\n\t\t\treturn;\n\t\t}\n\t\tconst scope = deletionScopeForProfile(profile);\n\t\tif (!scope) {\n\t\t\tthis.ui.showError(`Profile \"${profileName}\" is read-only (${profile.source}).`);\n\t\t\treturn;\n\t\t}\n\t\tconst selectedModel = await this.selectProfileModel(profile.model);\n\t\tif (selectedModel === undefined) {\n\t\t\tvoid this.openManageProfilesFlow();\n\t\t\treturn;\n\t\t}\n\t\tconst model = selectedModel ?? undefined;\n\t\tif (model === profile.model) {\n\t\t\tthis.ui.showStatus(`Profile \"${profileName}\" model unchanged.`);\n\t\t\treturn;\n\t\t}\n\t\tawait this.saveProfileResources(\n\t\t\t{ ...profile, model },\n\t\t\tprofile.resources,\n\t\t\tprofile.resources,\n\t\t\tscope,\n\t\t\tthis.settingsManager.getActiveResourceProfileNames().includes(profile.name),\n\t\t\ttrue,\n\t\t);\n\t}\n\n\tprivate async openPersistProfileSelector(): Promise<void> {\n\t\tconst scopeOptions = [\n\t\t\t{ value: \"session\", label: \"session\", description: \"Runtime only (not written to disk)\" },\n\t\t\t{\n\t\t\t\tvalue: \"directory\",\n\t\t\t\tlabel: \"directory\",\n\t\t\t\tdescription: \"~/.pi/agent/profiles/directories/<hash>/settings.json\",\n\t\t\t},\n\t\t\t{ value: \"project\", label: \"project\", description: \".pi/settings.json\" },\n\t\t\t{ value: \"global\", label: \"global\", description: \"~/.pi/agent/settings.json\" },\n\t\t];\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\"Persist Active Profile / Situation\",\n\t\t\t\t\"Choose where to write the active profile/situation selection.\",\n\t\t\t\tscopeOptions,\n\t\t\t\t\"directory\",\n\t\t\t\t(value) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tthis.persistActiveProfile(value as \"session\" | \"directory\" | \"project\" | \"global\");\n\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.openManageProfilesFlow();\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tprivate async openDeleteProfileSelector(): Promise<void> {\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst editableProfiles = registry.listProfiles().map((p) => ({\n\t\t\tvalue: p.name,\n\t\t\tlabel: p.name,\n\t\t\tdescription: p.description || p.source,\n\t\t}));\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\"Delete Profile / Situation\",\n\t\t\t\t\"Pick a profile/situation to delete.\",\n\t\t\t\teditableProfiles,\n\t\t\t\t\"\",\n\t\t\t\t(value) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.deleteProfileFromSource(value).then(() => {\n\t\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.openManageProfilesFlow();\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tprivate async openSourcesManagerFlow(): Promise<void> {\n\t\tconst externalRoots = this.settingsManager.getExternalResourceRoots();\n\t\tconst trustedRoots = this.settingsManager.getTrustedResourceRoots();\n\n\t\tconst options = [\n\t\t\t{\n\t\t\t\tvalue: \"add\",\n\t\t\t\tlabel: \"+ Add external root...\",\n\t\t\t\tdescription: \"Register a new external directory root (requires trust)\",\n\t\t\t},\n\t\t];\n\n\t\tfor (const r of externalRoots) {\n\t\t\tconst isTrusted = trustedRoots.includes(r);\n\t\t\toptions.push({\n\t\t\t\tvalue: `remove:${r}`,\n\t\t\t\tlabel: `Remove: ${r}`,\n\t\t\t\tdescription: isTrusted ? \"Trusted external root\" : \"Untrusted external root\",\n\t\t\t});\n\t\t}\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\"Sources\",\n\t\t\t\t\"Manage external resource roots. Adding a root requires trust confirmation.\",\n\t\t\t\toptions,\n\t\t\t\t\"\",\n\t\t\t\t(value) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tif (value === \"add\") {\n\t\t\t\t\t\tvoid this.addExternalResourceRootFlow().then(() => {\n\t\t\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t\t\t});\n\t\t\t\t\t} else if (value.startsWith(\"remove:\")) {\n\t\t\t\t\t\tconst root = value.slice(\"remove:\".length);\n\t\t\t\t\t\tvoid this.removeExternalResourceRootFlow(root).then(() => {\n\t\t\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tprivate async openLibraryManagerFlow(): Promise<void> {\n\t\tconst activeNames = this.settingsManager.getActiveResourceProfileNames();\n\t\tconst activeName = activeNames[0];\n\n\t\tif (!activeName || activeName === \"(none)\") {\n\t\t\tthis.ui.showSelector((done) => {\n\t\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\t\"No Active Profile / Situation\",\n\t\t\t\t\t\"Select or create a profile/situation to manage the library.\",\n\t\t\t\t\t[\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tvalue: \"select\",\n\t\t\t\t\t\t\tlabel: \"Select existing profile / situation...\",\n\t\t\t\t\t\t\tdescription: \"Choose an existing profile/situation to activate.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tvalue: \"create\",\n\t\t\t\t\t\t\tlabel: \"Create new profile / situation...\",\n\t\t\t\t\t\t\tdescription: \"Create a new profile/situation definition.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\t\"select\",\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tif (value === \"create\") {\n\t\t\t\t\t\t\tvoid this.createProfileAndOpenLibraryFlow();\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tvoid this.selectProfileAndOpenLibraryFlow();\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tvoid this.ui.showSettingsSelector();\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst profile = registry.getProfile(activeName);\n\t\tif (!profile) {\n\t\t\tthis.ui.showError(`Active profile/situation \"${activeName}\" not found in registry.`);\n\t\t\treturn;\n\t\t}\n\t\tconst scope = this.scopeForProfileSource(profile.source);\n\t\tvoid this.openLibraryEditorForProfile(profile.name, scope);\n\t}\n\n\tprivate async createProfileAndOpenLibraryFlow(): Promise<void> {\n\t\tconst name = await new Promise<string | undefined>((resolve) => {\n\t\t\tthis.ui.showSelector((done) => {\n\t\t\t\tconst input = new ExtensionInputComponent(\n\t\t\t\t\t\"Create Profile / Situation\",\n\t\t\t\t\t\"Enter profile/situation name\",\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(value);\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t},\n\t\t\t\t\t{ tui: this.ui.tui },\n\t\t\t\t);\n\t\t\t\treturn { component: input, focus: input, onSuperseded: () => resolve(undefined) };\n\t\t\t});\n\t\t});\n\n\t\tif (name === undefined) {\n\t\t\tvoid this.openLibraryManagerFlow();\n\t\t\treturn;\n\t\t}\n\n\t\tconst trimmed = name.trim();\n\t\tif (!trimmed) {\n\t\t\tthis.ui.showWarning(\"Profile/situation name cannot be empty.\");\n\t\t\tvoid this.openLibraryManagerFlow();\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst profileModel = await this.selectProfileModel();\n\t\t\tif (profileModel === undefined) {\n\t\t\t\tvoid this.openLibraryManagerFlow();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.settingsManager.setProfileDefinition(\n\t\t\t\ttrimmed,\n\t\t\t\t{\n\t\t\t\t\tname: trimmed,\n\t\t\t\t\tmodel: profileModel ?? undefined,\n\t\t\t\t\tresources: {},\n\t\t\t\t},\n\t\t\t\t\"reusable-file\",\n\t\t\t);\n\t\t\tawait this.applyProfile(trimmed);\n\t\t\tvoid this.openLibraryEditorForProfile(trimmed, \"reusable-file\");\n\t\t} catch (error) {\n\t\t\tthis.ui.showError(error instanceof Error ? error.message : String(error));\n\t\t\tvoid this.openLibraryManagerFlow();\n\t\t}\n\t}\n\n\tprivate async selectProfileAndOpenLibraryFlow(): Promise<void> {\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst profiles = registry.listProfiles();\n\t\tconst editableProfiles = profiles.map((p) => ({\n\t\t\tvalue: p.name,\n\t\t\tlabel: p.name,\n\t\t\tdescription: p.description || p.source,\n\t\t}));\n\n\t\tif (editableProfiles.length === 0) {\n\t\t\tthis.ui.showWarning(\"No existing profiles/situations to select. Please create one.\");\n\t\t\tvoid this.createProfileAndOpenLibraryFlow();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\"Select Profile / Situation\",\n\t\t\t\t\"Pick a profile/situation to activate and edit.\",\n\t\t\t\teditableProfiles,\n\t\t\t\t\"\",\n\t\t\t\t(value) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.applyProfile(value).then(() => {\n\t\t\t\t\t\tconst profile = registry.getProfile(value)!;\n\t\t\t\t\t\tconst scope = this.scopeForProfileSource(profile.source);\n\t\t\t\t\t\tvoid this.openLibraryEditorForProfile(value, scope);\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.openLibraryManagerFlow();\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tprivate async getProfileResourceKinds(): Promise<ProfileResourceEditorKind[]> {\n\t\tconst loader = this.session.resourceLoader;\n\t\tconst base = portableBasename;\n\t\tconst allDiscoverableExtensions = await loader.getDiscoverableExtensionPaths();\n\t\t// Defined BEFORE the skills/prompts arrays below that call it (const = TDZ: defining it\n\t\t// later crashes the whole app with a ReferenceError when the library editor opens).\n\t\tconst getFrontmatterDescription = (filePath: string): string | undefined => {\n\t\t\ttry {\n\t\t\t\tconst content = fs.readFileSync(filePath, \"utf-8\");\n\t\t\t\tconst { frontmatter } = parseFrontmatter<Record<string, unknown>>(content);\n\t\t\t\tif (typeof frontmatter.description === \"string\") return frontmatter.description;\n\t\t\t} catch {}\n\t\t\treturn undefined;\n\t\t};\n\t\t// The editor's universe must be profile-INDEPENDENT (discovery, not loading): the loaded\n\t\t// getters are narrowed by the active profile, so building the lists from them makes\n\t\t// currently-blocked skills/prompts/context files ungrantable — including expanding the\n\t\t// very profile you are running under. Union the loaded (rich metadata) sets with the\n\t\t// full pre-filter discovery paths.\n\t\tconst loadedSkills = loader.getSkills().skills;\n\t\tconst loadedSkillPaths = new Set(loadedSkills.map((skill) => skill.filePath));\n\t\tconst skillIdFromPath = (skillPath: string): string => {\n\t\t\tconst parts = skillPath.split(/[\\\\/]/);\n\t\t\tconst last = parts.pop() ?? skillPath;\n\t\t\tif (/^skill\\.md$/i.test(last)) return parts.pop() ?? last;\n\t\t\treturn last.replace(/\\.md$/i, \"\");\n\t\t};\n\t\tconst skills = [\n\t\t\t...loadedSkills.map((skill) => ({ id: skill.name, path: skill.filePath, description: skill.description })),\n\t\t\t...loader\n\t\t\t\t.getDiscoverableSkillPaths()\n\t\t\t\t.filter((skillPath) => !loadedSkillPaths.has(skillPath))\n\t\t\t\t.map((skillPath) => ({\n\t\t\t\t\tid: skillIdFromPath(skillPath),\n\t\t\t\t\tpath: skillPath,\n\t\t\t\t\tdescription: getFrontmatterDescription(skillPath),\n\t\t\t\t})),\n\t\t];\n\t\tconst loadedPrompts = loader.getPrompts().prompts;\n\t\tconst loadedPromptPaths = new Set(loadedPrompts.map((prompt) => prompt.filePath));\n\t\tconst prompts = [\n\t\t\t...loadedPrompts.map((prompt) => ({\n\t\t\t\tid: prompt.name,\n\t\t\t\tpath: prompt.filePath,\n\t\t\t\tdescription: prompt.description,\n\t\t\t})),\n\t\t\t...loader\n\t\t\t\t.getDiscoverablePromptPaths()\n\t\t\t\t.filter((promptPath) => !loadedPromptPaths.has(promptPath))\n\t\t\t\t.map((promptPath) => ({\n\t\t\t\t\tid: (promptPath.split(/[\\\\/]/).pop() ?? promptPath).replace(/\\.md$/i, \"\"),\n\t\t\t\t\tpath: promptPath,\n\t\t\t\t\tdescription: getFrontmatterDescription(promptPath),\n\t\t\t\t})),\n\t\t];\n\t\tconst themes = getAvailableThemesWithPaths();\n\t\tconst loadedAgentPaths = new Set(loader.getAgentsFiles().agentsFiles.map((file) => file.path));\n\t\tconst agents = [\n\t\t\t...loader.getAgentsFiles().agentsFiles.map((file) => ({ path: file.path })),\n\t\t\t...loader\n\t\t\t\t.getDiscoverableAgentsFilePaths()\n\t\t\t\t.filter((agentPath) => !loadedAgentPaths.has(agentPath))\n\t\t\t\t.map((agentPath) => ({ path: agentPath })),\n\t\t];\n\n\t\tconst getAgentDescription = (filePath: string): string | undefined => {\n\t\t\ttry {\n\t\t\t\tconst content = fs.readFileSync(filePath, \"utf-8\");\n\t\t\t\tconst { frontmatter } = parseFrontmatter<Record<string, unknown>>(content);\n\t\t\t\tif (typeof frontmatter.description === \"string\") {\n\t\t\t\t\treturn frontmatter.description;\n\t\t\t\t}\n\t\t\t} catch {}\n\t\t\treturn undefined;\n\t\t};\n\n\t\tconst getExtensionDescription = (filePath: string): string | undefined => {\n\t\t\ttry {\n\t\t\t\tlet dir = filePath;\n\t\t\t\tif (fs.existsSync(filePath) && !fs.statSync(filePath).isDirectory()) {\n\t\t\t\t\tdir = path.dirname(filePath);\n\t\t\t\t}\n\t\t\t\tconst pkgPath = path.join(dir, \"package.json\");\n\t\t\t\tif (fs.existsSync(pkgPath)) {\n\t\t\t\t\tconst pkg = JSON.parse(fs.readFileSync(pkgPath, \"utf-8\"));\n\t\t\t\t\tif (typeof pkg.description === \"string\") {\n\t\t\t\t\t\treturn pkg.description;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} catch {}\n\t\t\treturn undefined;\n\t\t};\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: \"tools\",\n\t\t\t\tlabel: \"Tools\",\n\t\t\t\t// Built-ins plus every currently registered tool (extension tools included), so\n\t\t\t\t// an extension tool can be granted by name without hand-editing settings JSON.\n\t\t\t\titems: [...new Set([...allToolNames, ...this.session.getAllTools().map((tool) => tool.name)])].map(\n\t\t\t\t\t(name: string) => ({ id: name }),\n\t\t\t\t),\n\t\t\t},\n\t\t\t{\n\t\t\t\tkind: \"skills\",\n\t\t\t\tlabel: \"Skills\",\n\t\t\t\titems: skills,\n\t\t\t},\n\t\t\t{\n\t\t\t\tkind: \"extensions\",\n\t\t\t\tlabel: \"Extensions\",\n\t\t\t\titems: allDiscoverableExtensions.map((extensionPath) => {\n\t\t\t\t\tconst description = getExtensionDescription(extensionPath);\n\t\t\t\t\treturn {\n\t\t\t\t\t\tid: path.resolve(extensionPath),\n\t\t\t\t\t\tlabel: getProfileExtensionDisplayLabel(extensionPath, description),\n\t\t\t\t\t\tpath: extensionPath,\n\t\t\t\t\t\tdescription,\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t},\n\t\t\t{\n\t\t\t\tkind: \"agents\",\n\t\t\t\tlabel: \"Agents\",\n\t\t\t\titems: agents.map((f) => ({\n\t\t\t\t\tid: base(f.path),\n\t\t\t\t\tpath: f.path,\n\t\t\t\t\tdescription: getAgentDescription(f.path),\n\t\t\t\t})),\n\t\t\t},\n\t\t\t{\n\t\t\t\tkind: \"prompts\",\n\t\t\t\tlabel: \"Prompts\",\n\t\t\t\titems: prompts,\n\t\t\t},\n\t\t\t{\n\t\t\t\tkind: \"themes\",\n\t\t\t\tlabel: \"Themes\",\n\t\t\t\titems: themes.map((t) => ({\n\t\t\t\t\tid: t.name,\n\t\t\t\t\tpath: t.path,\n\t\t\t\t})),\n\t\t\t},\n\t\t];\n\t}\n\n\tprivate async openLibraryEditorForProfile(\n\t\tprofileName: string,\n\t\tinitialScope: \"session\" | \"directory\" | \"project\" | \"global\" | \"reusable-file\",\n\t): Promise<void> {\n\t\tconst currentScope = initialScope;\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst profile = registry.getProfile(profileName);\n\t\tif (!profile) {\n\t\t\tthis.ui.showError(`Profile not found: ${profileName}`);\n\t\t\treturn;\n\t\t}\n\n\t\tconst kinds = await this.getProfileResourceKinds();\n\t\tconst originalResources = profile.resources;\n\t\tconst isActiveProfile = this.settingsManager.getActiveResourceProfileNames().includes(profile.name);\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst editor = new ProfileResourceEditorComponent({\n\t\t\t\tprofileName: profile!.name,\n\t\t\t\tprofileScope: currentScope,\n\t\t\t\tinitialResources: profile!.resources,\n\t\t\t\tkinds,\n\t\t\t\tcwd: this.sessionManager.getCwd(),\n\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\texternalResourceRoots: this.settingsManager.getExternalResourceRoots(),\n\t\t\t\tonSave: (resources) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.saveProfileResources(profile, originalResources, resources, currentScope, isActiveProfile);\n\t\t\t\t},\n\t\t\t\tonCancel: () => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.openLibraryManagerFlow();\n\t\t\t\t},\n\t\t\t\tonScopeChange: () => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.promptScopeChangeForProfile(profileName, currentScope);\n\t\t\t\t},\n\t\t\t\tonEdit: async (id, pathValue, kind) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tconst resolvedEditPath = resolveResourceEditPath(id, pathValue, kind);\n\t\t\t\t\tif (!resolvedEditPath) {\n\t\t\t\t\t\tthis.ui.showWarning(`Resource \"${id}\" of kind \"${kind}\" has no editable file path.`);\n\t\t\t\t\t\tvoid this.openLibraryEditorForProfile(profileName, currentScope);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (!fs.existsSync(resolvedEditPath)) {\n\t\t\t\t\t\tthis.ui.showError(`Resolved path for \"${id}\" does not exist: ${resolvedEditPath}`);\n\t\t\t\t\t\tvoid this.openLibraryEditorForProfile(profileName, currentScope);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tawait this.ui.openEditorForPath(resolvedEditPath);\n\t\t\t\t\tawait this.ui.handleReloadCommand();\n\t\t\t\t\tvoid this.openLibraryEditorForProfile(profileName, currentScope);\n\t\t\t\t},\n\t\t\t});\n\n\t\t\treturn { component: editor, focus: editor };\n\t\t});\n\t}\n\n\tprivate async saveProfileResources(\n\t\tprofile: NormalizedProfile,\n\t\toriginalResources: NormalizedProfile[\"resources\"],\n\t\tresources: NormalizedProfile[\"resources\"],\n\t\tscope: WritableProfileScope,\n\t\tisActiveProfile: boolean,\n\t\truntimeMetadataChanged = false,\n\t): Promise<void> {\n\t\tconst definition = {\n\t\t\tname: profile.name,\n\t\t\tdescription: profile.description,\n\t\t\tmodel: profile.model,\n\t\t\tthinking: profile.thinking,\n\t\t\tmodelRouter: profile.modelRouter,\n\t\t\tsoul: profile.soul,\n\t\t\tresources,\n\t\t};\n\t\tconst changedKinds = resourceProfileSettingsChangedKinds(originalResources, resources);\n\t\tif (!isActiveProfile || (changedKinds.size === 0 && !runtimeMetadataChanged)) {\n\t\t\ttry {\n\t\t\t\tthis.settingsManager.setProfileDefinition(profile.name, definition, scope);\n\t\t\t\tthis.ui.showStatus(`Saved profile \"${profile.name}\" to ${scope}.`);\n\t\t\t\tthis.ui.requestRender();\n\t\t\t} catch (error) {\n\t\t\t\tthis.ui.showError(error instanceof Error ? error.message : String(error));\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst settingsSnapshot = this.settingsManager.createReloadSnapshot();\n\t\tconst profilesDir = getProfilesDir();\n\t\tconst profileFilesSnapshot = scope === \"reusable-file\" ? captureProfileFiles(profilesDir) : undefined;\n\t\tlet stagedRuntimeApplied = false;\n\t\ttry {\n\t\t\t// Validate the edited authority surface as a session overlay first. Persistent scopes are\n\t\t\t// written only after the complete runtime generation passes its reload doctor.\n\t\t\tthis.settingsManager.setProfileDefinition(profile.name, definition, \"session\");\n\t\t\tif (!(await this.ui.handleReloadCommand())) {\n\t\t\t\tthis.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstagedRuntimeApplied = true;\n\n\t\t\tif (scope !== \"session\") {\n\t\t\t\tthis.settingsManager.setProfileDefinition(profile.name, definition, scope);\n\t\t\t\tawait this.settingsManager.flush();\n\t\t\t\t// Drop the validation-only inline winner, then refresh the registry from the now-validated\n\t\t\t\t// persistent definition. The live runtime already represents the same profile definition.\n\t\t\t\tthis.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\t\tawait this.settingsManager.reload();\n\t\t\t}\n\n\t\t\tconst active = this.settingsManager.getActiveResourceProfileNames()[0] ?? \"(none)\";\n\t\t\tthis.ui.footerDataProvider.setExtensionStatus(\"profile\", active);\n\t\t\tthis.ui.invalidateFooter();\n\t\t\tthis.ui.updateEditorBorderColor();\n\t\t\tthis.ui.showStatus(`Saved profile \"${profile.name}\" to ${scope}.`);\n\t\t} catch (error) {\n\t\t\tconst rollbackError = stagedRuntimeApplied\n\t\t\t\t? await this.rollbackValidatedProfileMutation(settingsSnapshot, {\n\t\t\t\t\t\tprofileName: profile.name,\n\t\t\t\t\t\tscope,\n\t\t\t\t\t\tprofileFilesSnapshot,\n\t\t\t\t\t})\n\t\t\t\t: undefined;\n\t\t\tif (!stagedRuntimeApplied) this.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthis.ui.showError(\n\t\t\t\trollbackError\n\t\t\t\t\t? `${message}; rollback failed: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`\n\t\t\t\t\t: message,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async rollbackValidatedProfileMutation(\n\t\tsettingsSnapshot: SettingsReloadSnapshot,\n\t\tdefinition?: ProfileDefinitionRollbackTarget,\n\t): Promise<unknown> {\n\t\tconst errors: string[] = [];\n\t\ttry {\n\t\t\tif (definition?.scope === \"reusable-file\") {\n\t\t\t\trestoreProfileFiles(getProfilesDir(), definition.profileFilesSnapshot!);\n\t\t\t} else if (definition && definition.scope !== \"session\") {\n\t\t\t\tthis.settingsManager.restoreProfileDefinitionFromReloadSnapshot(\n\t\t\t\t\tdefinition.profileName,\n\t\t\t\t\tdefinition.scope,\n\t\t\t\t\tsettingsSnapshot,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst global = settingsSnapshot.globalSettings;\n\t\t\tthis.settingsManager.replaceGlobalResourceProfileConfiguration({\n\t\t\t\tresourceProfiles: global.resourceProfiles,\n\t\t\t\tactiveResourceProfile: global.activeResourceProfile,\n\t\t\t\tactiveResourceProfiles: global.activeResourceProfiles,\n\t\t\t\texternalResourceRoots: global.externalResourceRoots,\n\t\t\t\ttrustedResourceRoots: global.trustedResourceRoots,\n\t\t\t});\n\t\t\tawait this.settingsManager.flush();\n\t\t} catch (error) {\n\t\t\terrors.push(`persistence: ${error instanceof Error ? error.message : String(error)}`);\n\t\t}\n\t\tthis.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\ttry {\n\t\t\tif (!(await this.ui.handleReloadCommand())) {\n\t\t\t\terrors.push(\"runtime: the previous profile runtime could not be restored\");\n\t\t\t}\n\t\t} catch (error) {\n\t\t\terrors.push(`runtime: ${error instanceof Error ? error.message : String(error)}`);\n\t\t}\n\t\treturn errors.length > 0 ? new Error(errors.join(\"; \")) : undefined;\n\t}\n\n\tprivate async promptScopeChangeForProfile(\n\t\tprofileName: string,\n\t\tcurrentScope: \"session\" | \"directory\" | \"project\" | \"global\" | \"reusable-file\",\n\t): Promise<void> {\n\t\tconst scopeOptions = [\n\t\t\t{ value: \"session\", label: \"session\", description: \"Runtime only (not written to disk)\" },\n\t\t\t{\n\t\t\t\tvalue: \"directory\",\n\t\t\t\tlabel: \"directory\",\n\t\t\t\tdescription: \"~/.pi/agent/profiles/directories/<hash>/settings.json\",\n\t\t\t},\n\t\t\t{ value: \"project\", label: \"project\", description: \".pi/settings.json\" },\n\t\t\t{ value: \"global\", label: \"global\", description: \"~/.pi/agent/settings.json\" },\n\t\t];\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\"Change Profile / Situation Scope\",\n\t\t\t\t`Select new scope for profile/situation \"${profileName}\".`,\n\t\t\t\tscopeOptions,\n\t\t\t\tcurrentScope,\n\t\t\t\t(value) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.openLibraryEditorForProfile(profileName, value as any);\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.openLibraryEditorForProfile(profileName, currentScope);\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tasync handleProfilesCommand(profileName?: string): Promise<void> {\n\t\tif (profileName) {\n\t\t\tawait this.applyProfile(profileName);\n\t\t\treturn;\n\t\t}\n\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst profiles = registry.listProfiles();\n\t\tif (profiles.length === 0) {\n\t\t\tthis.ui.showWarning(\n\t\t\t\t\"No profiles found. Add resourceProfiles to settings or JSON files under ~/.pi/agent/profiles/.\",\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst selector = new ProfileSelectorComponent(\n\t\t\t\tprofiles,\n\t\t\t\tthis.settingsManager.getActiveResourceProfileNames(),\n\t\t\t\t(profile) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tvoid this.applyProfile(profile);\n\t\t\t\t},\n\t\t\t\t() => {\n\t\t\t\t\tdone();\n\t\t\t\t\tthis.ui.requestRender();\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn { component: selector, focus: selector.getSelectList() };\n\t\t});\n\t}\n\n\tprivate async applyProfile(profileName: string): Promise<void> {\n\t\tconst normalizedName = profileName.trim();\n\t\tconst normalizedLower = normalizedName.toLowerCase();\n\t\tif (normalizedName.length === 0 || normalizedLower === \"none\" || normalizedLower === \"(none)\") {\n\t\t\tconst settingsSnapshot = this.settingsManager.createReloadSnapshot();\n\t\t\tlet stagedRuntimeApplied = false;\n\t\t\ttry {\n\t\t\t\tthis.settingsManager.setRuntimeResourceProfiles([]);\n\t\t\t\tif (!(await this.ui.handleReloadCommand())) {\n\t\t\t\t\tthis.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tstagedRuntimeApplied = true;\n\t\t\t\t// Persist only after the new runtime generation passes its reload doctor.\n\t\t\t\tthis.settingsManager.setActiveProfile(undefined, \"global\");\n\t\t\t\tawait this.settingsManager.flush();\n\t\t\t\tthis.session.sessionManager.appendCustomEntry(\"pi.activeResourceProfiles\", {\n\t\t\t\t\tprofiles: [],\n\t\t\t\t});\n\t\t\t\tconst activeProfileName = this.settingsManager.getActiveResourceProfileNames()[0] ?? \"(none)\";\n\t\t\t\tthis.ui.footerDataProvider.setExtensionStatus(\"profile\", activeProfileName);\n\t\t\t\tthis.ui.invalidateFooter();\n\t\t\t\tthis.ui.updateEditorBorderColor();\n\t\t\t\tthis.ui.showStatus(`Profile: ${activeProfileName}`);\n\t\t\t} catch (error) {\n\t\t\t\tconst rollbackError = stagedRuntimeApplied\n\t\t\t\t\t? await this.rollbackValidatedProfileMutation(settingsSnapshot)\n\t\t\t\t\t: undefined;\n\t\t\t\tif (!stagedRuntimeApplied) this.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\tthis.ui.showError(\n\t\t\t\t\trollbackError\n\t\t\t\t\t\t? `${message}; rollback failed: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`\n\t\t\t\t\t\t: message,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst profile =\n\t\t\tnormalizedName.startsWith(\"./\") || normalizedName.startsWith(\"../\")\n\t\t\t\t? registry.resolveProfileRef(normalizedName, this.sessionManager.getCwd())\n\t\t\t\t: registry.getProfile(normalizedName);\n\t\tif (!profile) {\n\t\t\tthis.ui.showError(`Profile not found: ${profileName}`);\n\t\t\treturn;\n\t\t}\n\n\t\tconst settingsSnapshot = this.settingsManager.createReloadSnapshot();\n\t\tconst modelRegistrySnapshot = profile.model ? this.session.modelRegistry.createReloadSnapshot() : undefined;\n\t\tlet stagedRuntimeApplied = false;\n\t\ttry {\n\t\t\tconst activeProfileRef =\n\t\t\t\tnormalizedName.startsWith(\"./\") || normalizedName.startsWith(\"../\") ? normalizedName : profile.name;\n\t\t\tlet requestedModel: Model<Api> | undefined;\n\t\t\tif (profile.model) {\n\t\t\t\tthis.session.modelRegistry.refresh();\n\t\t\t\tconst resolved = resolveCliModel({ cliModel: profile.model, modelRegistry: this.session.modelRegistry });\n\t\t\t\t// The profile may grant an extension that contributes this model. The current generation\n\t\t\t\t// cannot validate that case; the atomic reload binds new providers before authoritative\n\t\t\t\t// profile resolution and rolls back if the model is still unresolved.\n\t\t\t\tif (!resolved.error && resolved.warning) {\n\t\t\t\t\tthis.ui.showWarning(resolved.warning);\n\t\t\t\t}\n\t\t\t\tif (!resolved.error) requestedModel = resolved.model;\n\t\t\t}\n\n\t\t\t// Stage the complete situation in memory. Runtime reload applies model/thinking, resource\n\t\t\t// grants, extensions, skills, prompts, and soul together; explicit launch overrides still win.\n\t\t\tthis.settingsManager.setRuntimeResourceProfiles([activeProfileRef]);\n\t\t\tif (!(await this.ui.handleReloadCommand())) {\n\t\t\t\tthis.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\t\tif (modelRegistrySnapshot) this.session.modelRegistry.restoreReloadSnapshot(modelRegistrySnapshot);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tstagedRuntimeApplied = true;\n\n\t\t\t// Selection survives restarts only after the new runtime generation passes its reload doctor.\n\t\t\tthis.settingsManager.setActiveProfile(activeProfileRef, \"global\");\n\t\t\tawait this.settingsManager.flush();\n\t\t\tthis.session.sessionManager.appendCustomEntry(\"pi.activeResourceProfiles\", {\n\t\t\t\tprofiles: [activeProfileRef],\n\t\t\t});\n\t\t\tthis.ui.footerDataProvider.setExtensionStatus(\"profile\", profile.name);\n\t\t\tthis.ui.invalidateFooter();\n\t\t\tthis.ui.updateEditorBorderColor();\n\t\t\tthis.ui.showStatus(`Profile: ${profile.name}`);\n\t\t\tif (\n\t\t\t\trequestedModel &&\n\t\t\t\tthis.session.model?.provider === requestedModel.provider &&\n\t\t\t\tthis.session.model.id === requestedModel.id\n\t\t\t) {\n\t\t\t\tvoid this.ui.maybeWarnAboutAnthropicSubscriptionAuth(requestedModel);\n\t\t\t\tthis.ui.checkDaxnutsEasterEgg(requestedModel);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst rollbackError = stagedRuntimeApplied\n\t\t\t\t? await this.rollbackValidatedProfileMutation(settingsSnapshot)\n\t\t\t\t: undefined;\n\t\t\tif (!stagedRuntimeApplied) this.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\tif (modelRegistrySnapshot) this.session.modelRegistry.restoreReloadSnapshot(modelRegistrySnapshot);\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthis.ui.showError(\n\t\t\t\trollbackError\n\t\t\t\t\t? `${message}; rollback failed: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`\n\t\t\t\t\t: message,\n\t\t\t);\n\t\t}\n\t}\n\n\t/** Map where a profile currently lives to the scope we should write it back to. */\n\tprivate scopeForProfileSource(source: string): WritableProfileScope {\n\t\tswitch (source) {\n\t\t\tcase \"profile-file\":\n\t\t\t\treturn \"reusable-file\";\n\t\t\tcase \"directory-overlay\":\n\t\t\tcase \"embedded\":\n\t\t\t\treturn \"directory\";\n\t\t\tcase \"project-settings\":\n\t\t\t\treturn \"project\";\n\t\t\tcase \"inline\":\n\t\t\t\treturn \"session\";\n\t\t\tdefault:\n\t\t\t\treturn \"global\";\n\t\t}\n\t}\n\n\tasync refreshAfterProfileMutation(profileName: string): Promise<void> {\n\t\tif (this.settingsManager.getActiveResourceProfileNames().includes(profileName)) {\n\t\t\tif (!(await this.ui.handleReloadCommand())) return;\n\t\t\tconst active = this.settingsManager.getActiveResourceProfileNames()[0] ?? \"(none)\";\n\t\t\tthis.ui.footerDataProvider.setExtensionStatus(\"profile\", active);\n\t\t\tthis.ui.invalidateFooter();\n\t\t\tthis.ui.updateEditorBorderColor();\n\t\t}\n\t}\n\n\tprivate async createProfileFlow(): Promise<void> {\n\t\tconst name = await new Promise<string | undefined>((resolve) => {\n\t\t\tthis.ui.showSelector((done) => {\n\t\t\t\tconst input = new ExtensionInputComponent(\n\t\t\t\t\t\"Create Profile / Situation\",\n\t\t\t\t\t\"Enter profile/situation name\",\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(value);\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t},\n\t\t\t\t\t{ tui: this.ui.tui },\n\t\t\t\t);\n\t\t\t\treturn { component: input, focus: input, onSuperseded: () => resolve(undefined) };\n\t\t\t});\n\t\t});\n\n\t\tif (name === undefined) {\n\t\t\tthis.ui.requestRender();\n\t\t\treturn;\n\t\t}\n\n\t\tconst trimmed = name.trim();\n\t\tif (!trimmed) {\n\t\t\tthis.ui.showError(\"Profile/situation name cannot be empty\");\n\t\t\treturn this.createProfileFlow();\n\t\t}\n\n\t\t// Validate name rules using validateSkillName\n\t\tconst errors = validateSkillName(trimmed);\n\t\tif (errors.length > 0) {\n\t\t\tthis.ui.showError(`Invalid profile/situation name: ${errors.join(\", \")}`);\n\t\t\treturn this.createProfileFlow();\n\t\t}\n\n\t\t// Collision check\n\t\tconst existing = this.settingsManager.getProfileRegistry().getProfile(trimmed);\n\t\tif (existing) {\n\t\t\tthis.ui.showError(`Profile/situation \"${trimmed}\" already exists`);\n\t\t\treturn this.createProfileFlow();\n\t\t}\n\n\t\tconst profileModel = await this.selectProfileModel();\n\t\tif (profileModel === undefined) {\n\t\t\tthis.ui.requestRender();\n\t\t\treturn;\n\t\t}\n\n\t\t// Open the resource editor on the NEW profile\n\t\tvoid this.openNewProfileEditor(trimmed, profileModel ?? undefined);\n\t}\n\n\tprivate async selectProfileModel(profileModel?: string): Promise<string | null | undefined> {\n\t\tconst inheritValue = \"(inherit)\";\n\t\tconst availableModelOptions = [...this.ui.getAutoLearnModelOptions()];\n\t\tif (profileModel && !availableModelOptions.some((option) => option.value === profileModel)) {\n\t\t\tavailableModelOptions.unshift({\n\t\t\t\tvalue: profileModel,\n\t\t\t\tlabel: profileModel,\n\t\t\t\tdescription: \"Current profile model (not currently available)\",\n\t\t\t});\n\t\t}\n\t\tconst modelOptions = [\n\t\t\t{\n\t\t\t\tvalue: inheritValue,\n\t\t\t\tlabel: \"Inherit session/default model\",\n\t\t\t\tdescription: \"Remove the profile model pin and use the current session/default model\",\n\t\t\t},\n\t\t\t...availableModelOptions,\n\t\t];\n\n\t\treturn await new Promise<string | null | undefined>((resolve) => {\n\t\t\tthis.ui.showSelector((done) => {\n\t\t\t\tconst selector = new SelectSubmenu(\n\t\t\t\t\t\"Profile Model\",\n\t\t\t\t\t\"Pin a foreground model for this profile or inherit the session/default model.\",\n\t\t\t\t\tmodelOptions,\n\t\t\t\t\tprofileModel ?? inheritValue,\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(value === inheritValue ? null : value);\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tcomponent: selector,\n\t\t\t\t\tfocus: selector.getSelectList(),\n\t\t\t\t\tonSuperseded: () => resolve(undefined),\n\t\t\t\t};\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate async openNewProfileEditor(profileName: string, profileModel?: string): Promise<void> {\n\t\tconst scope = \"reusable-file\";\n\t\tconst kinds = await this.getProfileResourceKinds();\n\t\tthis.ui.showSelector((done) => {\n\t\t\tconst editor = new ProfileResourceEditorComponent({\n\t\t\t\tprofileName,\n\t\t\t\tprofileScope: scope,\n\t\t\t\tinitialResources: {},\n\t\t\t\tkinds,\n\t\t\t\tcwd: this.sessionManager.getCwd(),\n\t\t\t\tagentDir: getAgentDir(),\n\t\t\t\texternalResourceRoots: this.settingsManager.getExternalResourceRoots(),\n\t\t\t\tonSave: (resources) => {\n\t\t\t\t\tdone();\n\t\t\t\t\ttry {\n\t\t\t\t\t\tthis.settingsManager.setProfileDefinition(\n\t\t\t\t\t\t\tprofileName,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tname: profileName,\n\t\t\t\t\t\t\t\tmodel: profileModel,\n\t\t\t\t\t\t\t\tresources,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tscope,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.ui.showStatus(`Saved profile \"${profileName}\" to ${scope}.`);\n\t\t\t\t\t\tthis.ui.requestRender();\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tthis.ui.showError(error instanceof Error ? error.message : String(error));\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\tonCancel: () => {\n\t\t\t\t\tdone();\n\t\t\t\t\tthis.ui.requestRender();\n\t\t\t\t},\n\t\t\t\tonEdit: async (id, pathValue, kind) => {\n\t\t\t\t\tdone();\n\t\t\t\t\tconst resolvedEditPath = resolveResourceEditPath(id, pathValue, kind);\n\t\t\t\t\tif (!resolvedEditPath) {\n\t\t\t\t\t\tthis.ui.showWarning(`Resource \"${id}\" of kind \"${kind}\" has no editable file path.`);\n\t\t\t\t\t\tvoid this.openNewProfileEditor(profileName, profileModel);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (!fs.existsSync(resolvedEditPath)) {\n\t\t\t\t\t\tthis.ui.showError(`Resolved path for \"${id}\" does not exist: ${resolvedEditPath}`);\n\t\t\t\t\t\tvoid this.openNewProfileEditor(profileName, profileModel);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tawait this.ui.openEditorForPath(resolvedEditPath);\n\t\t\t\t\tawait this.ui.handleReloadCommand();\n\t\t\t\t\tvoid this.openNewProfileEditor(profileName, profileModel);\n\t\t\t\t},\n\t\t\t});\n\t\t\treturn { component: editor, focus: editor };\n\t\t});\n\t}\n\n\tprivate persistActiveProfile(scope: \"session\" | \"directory\" | \"project\" | \"global\"): void {\n\t\tconst active = this.settingsManager.getActiveResourceProfileNames()[0];\n\t\tif (!active) {\n\t\t\tthis.ui.showError(\"No active profile to persist. Select one with /profiles first.\");\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tif (scope === \"session\") {\n\t\t\t\tthis.settingsManager.setRuntimeResourceProfiles([active]);\n\t\t\t} else {\n\t\t\t\tthis.settingsManager.setActiveProfile(active, scope);\n\t\t\t}\n\t\t\tthis.ui.showStatus(`Active profile \"${active}\" persisted to ${scope}.`);\n\t\t} catch (error) {\n\t\t\tthis.ui.showError(error instanceof Error ? error.message : String(error));\n\t\t}\n\t}\n\n\tprivate async deleteProfileFromSource(profileName: string): Promise<void> {\n\t\tconst registry = this.settingsManager.getProfileRegistry();\n\t\tconst profile = registry.getProfile(profileName);\n\t\tif (!profile) {\n\t\t\tthis.ui.showError(`Profile not found: ${profileName}`);\n\t\t\treturn;\n\t\t}\n\t\tconst scope = deletionScopeForProfile(profile);\n\t\tif (!scope) {\n\t\t\tconst location = profile.sourcePath ? ` at ${profile.sourcePath}` : \"\";\n\t\t\tthis.ui.showError(\n\t\t\t\t`Profile \"${profileName}\" comes from read-only source ${profile.source}${location}; edit or remove that source definition directly.`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst wasActive = this.settingsManager.getActiveResourceProfileNames().some((profileRef) => {\n\t\t\tif (profileRef === profileName || profileRef === profile.name) return true;\n\t\t\tconst activeProfile =\n\t\t\t\tprofileRef.startsWith(\"./\") || profileRef.startsWith(\"../\")\n\t\t\t\t\t? registry.resolveProfileRef(profileRef, this.sessionManager.getCwd())\n\t\t\t\t\t: registry.getProfile(profileRef);\n\t\t\treturn Boolean(\n\t\t\t\tactiveProfile && activeProfile.name === profile.name && activeProfile.sourcePath === profile.sourcePath,\n\t\t\t);\n\t\t});\n\t\tconst settingsSnapshot = this.settingsManager.createReloadSnapshot();\n\t\tconst profileFilesSnapshot = scope === \"reusable-file\" ? captureProfileFiles(getProfilesDir()) : undefined;\n\t\tlet switchedToNone = false;\n\t\ttry {\n\t\t\tif (wasActive) {\n\t\t\t\t// Stage an explicit empty runtime selection while the definition is still intact. The\n\t\t\t\t// full reload can now remove the profile's extensions, tools, providers, model, and\n\t\t\t\t// memory generation atomically. Persisting the deletion is deliberately deferred until\n\t\t\t\t// that generation passes its doctor, so a failed reload has no on-disk deletion to undo.\n\t\t\t\tthis.settingsManager.setRuntimeResourceProfiles([]);\n\t\t\t\tif (!(await this.ui.handleReloadCommand())) {\n\t\t\t\t\tthis.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tswitchedToNone = true;\n\t\t\t}\n\n\t\t\tthis.settingsManager.deleteProfile(profileName, scope);\n\t\t\tconst remaining = this.settingsManager.getProfileRegistry().getProfile(profileName);\n\t\t\tif (remaining && remaining.source === profile.source && remaining.sourcePath === profile.sourcePath) {\n\t\t\t\tthrow new Error(`Profile \"${profileName}\" was not removed from ${profile.source}.`);\n\t\t\t}\n\t\t\tif (wasActive) {\n\t\t\t\tthis.settingsManager.setActiveProfile(undefined, \"global\");\n\t\t\t\tawait this.settingsManager.flush();\n\t\t\t\tthis.session.sessionManager.appendCustomEntry(\"pi.activeResourceProfiles\", { profiles: [] });\n\t\t\t\tthis.ui.footerDataProvider.setExtensionStatus(\"profile\", \"(none)\");\n\t\t\t\tthis.ui.invalidateFooter();\n\t\t\t\tthis.ui.updateEditorBorderColor();\n\t\t\t}\n\t\t\tthis.ui.showStatus(`Deleted profile \"${profileName}\" from ${scope}.`);\n\t\t} catch (error) {\n\t\t\tconst rollbackError = switchedToNone\n\t\t\t\t? await this.rollbackValidatedProfileMutation(settingsSnapshot, {\n\t\t\t\t\t\tprofileName,\n\t\t\t\t\t\tscope,\n\t\t\t\t\t\tprofileFilesSnapshot,\n\t\t\t\t\t})\n\t\t\t\t: undefined;\n\t\t\tif (!switchedToNone) this.settingsManager.restoreReloadSnapshot(settingsSnapshot);\n\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\tthis.ui.showError(\n\t\t\t\trollbackError\n\t\t\t\t\t? `${message}; rollback failed: ${rollbackError instanceof Error ? rollbackError.message : String(rollbackError)}`\n\t\t\t\t\t: message,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate async addExternalResourceRootFlow(): Promise<void> {\n\t\tconst rootPath = await new Promise<string | undefined>((resolve) => {\n\t\t\tthis.ui.showSelector((done) => {\n\t\t\t\tconst input = new ExtensionInputComponent(\n\t\t\t\t\t\"Add External Root\",\n\t\t\t\t\t\"Enter external root directory path\",\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(value);\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t},\n\t\t\t\t\t{ tui: this.ui.tui },\n\t\t\t\t);\n\t\t\t\treturn { component: input, focus: input, onSuperseded: () => resolve(undefined) };\n\t\t\t});\n\t\t});\n\n\t\tif (rootPath === undefined) {\n\t\t\tthis.ui.requestRender();\n\t\t\treturn;\n\t\t}\n\n\t\tconst trimmed = rootPath.trim();\n\t\tif (!trimmed) {\n\t\t\tthis.ui.showError(\"Directory path cannot be empty\");\n\t\t\treturn;\n\t\t}\n\n\t\tconst canonical = this.settingsManager.canonicalizePath(trimmed);\n\t\tif (!canonical) {\n\t\t\tthis.ui.showError(`Invalid path: ${trimmed}`);\n\t\t\treturn;\n\t\t}\n\n\t\t// Prompt for trust confirmation (Yes/No)\n\t\tconst trust = await new Promise<boolean>((resolve) => {\n\t\t\tthis.ui.showSelector((done) => {\n\t\t\t\tconst submenu = new SelectSubmenu(\n\t\t\t\t\t\"Trust external source?\",\n\t\t\t\t\t\"This directory can load custom extensions that execute arbitrary code on your machine.\",\n\t\t\t\t\t[\n\t\t\t\t\t\t{ value: \"yes\", label: \"Yes\", description: \"Trust this directory and enable loading resources.\" },\n\t\t\t\t\t\t{ value: \"no\", label: \"No\", description: \"Do not trust this directory. Skip loading resources.\" },\n\t\t\t\t\t],\n\t\t\t\t\t\"no\",\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(value === \"yes\");\n\t\t\t\t\t},\n\t\t\t\t\t() => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(false);\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t\treturn {\n\t\t\t\t\tcomponent: submenu,\n\t\t\t\t\tfocus: submenu.getSelectList(),\n\t\t\t\t\tonSuperseded: () => resolve(false),\n\t\t\t\t};\n\t\t\t});\n\t\t});\n\n\t\tif (!trust) {\n\t\t\tthis.ui.showStatus(\"Aborted. External root was not trusted.\");\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tconst currentRoots = this.settingsManager.getExternalResourceRoots();\n\t\t\tif (!currentRoots.includes(canonical)) {\n\t\t\t\tthis.settingsManager.setExternalResourceRoots([...currentRoots, canonical], \"global\");\n\t\t\t}\n\t\t\tthis.settingsManager.addTrustedResourceRoot(canonical, \"global\");\n\t\t\tthis.ui.showStatus(`Added trusted external root: ${canonical}`);\n\t\t\tawait this.ui.handleReloadCommand();\n\t\t} catch (error) {\n\t\t\tthis.ui.showError(error instanceof Error ? error.message : String(error));\n\t\t}\n\t}\n\n\tprivate async removeExternalResourceRootFlow(root: string): Promise<void> {\n\t\ttry {\n\t\t\tconst currentRoots = this.settingsManager.getExternalResourceRoots();\n\t\t\tconst currentTrusted = this.settingsManager.getTrustedResourceRoots();\n\n\t\t\tconst newRoots = currentRoots.filter((r) => r !== root);\n\t\t\tconst newTrusted = currentTrusted.filter((r) => r !== root);\n\n\t\t\tthis.settingsManager.setExternalResourceRoots(newRoots, \"global\");\n\t\t\tthis.settingsManager.setTrustedResourceRoots(newTrusted, \"global\");\n\n\t\t\tthis.ui.showStatus(`Removed external root: ${root}`);\n\t\t\tawait this.ui.handleReloadCommand();\n\t\t} catch (error) {\n\t\t\tthis.ui.showError(error instanceof Error ? error.message : String(error));\n\t\t}\n\t}\n}\n"]}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import * as fs from "node:fs";
|
|
13
13
|
import * as path from "node:path";
|
|
14
|
-
import { getAgentDir } from "../../config.js";
|
|
14
|
+
import { getAgentDir, getProfilesDir } from "../../config.js";
|
|
15
15
|
import { resolveCliModel } from "../../core/model-resolver.js";
|
|
16
16
|
import { resourceProfileSettingsChangedKinds } from "../../core/resource-profile-equality.js";
|
|
17
17
|
import { validateSkillName } from "../../core/skills.js";
|
|
@@ -35,7 +35,7 @@ function deletionScopeForProfile(profile) {
|
|
|
35
35
|
case "global-settings":
|
|
36
36
|
return "global";
|
|
37
37
|
case "profile-file": {
|
|
38
|
-
const localProfilePath = path.resolve(
|
|
38
|
+
const localProfilePath = path.resolve(getProfilesDir(), `${profile.name}.json`);
|
|
39
39
|
return profile.sourcePath && path.resolve(profile.sourcePath) === localProfilePath
|
|
40
40
|
? "reusable-file"
|
|
41
41
|
: undefined;
|
|
@@ -237,7 +237,7 @@ export class ProfileMenuController {
|
|
|
237
237
|
{
|
|
238
238
|
value: "directory",
|
|
239
239
|
label: "directory",
|
|
240
|
-
description: "~/.pi/agent/
|
|
240
|
+
description: "~/.pi/agent/profiles/directories/<hash>/settings.json",
|
|
241
241
|
},
|
|
242
242
|
{ value: "project", label: "project", description: ".pi/settings.json" },
|
|
243
243
|
{ value: "global", label: "global", description: "~/.pi/agent/settings.json" },
|
|
@@ -645,7 +645,7 @@ export class ProfileMenuController {
|
|
|
645
645
|
return;
|
|
646
646
|
}
|
|
647
647
|
const settingsSnapshot = this.settingsManager.createReloadSnapshot();
|
|
648
|
-
const profilesDir =
|
|
648
|
+
const profilesDir = getProfilesDir();
|
|
649
649
|
const profileFilesSnapshot = scope === "reusable-file" ? captureProfileFiles(profilesDir) : undefined;
|
|
650
650
|
let stagedRuntimeApplied = false;
|
|
651
651
|
try {
|
|
@@ -691,7 +691,7 @@ export class ProfileMenuController {
|
|
|
691
691
|
const errors = [];
|
|
692
692
|
try {
|
|
693
693
|
if (definition?.scope === "reusable-file") {
|
|
694
|
-
restoreProfileFiles(
|
|
694
|
+
restoreProfileFiles(getProfilesDir(), definition.profileFilesSnapshot);
|
|
695
695
|
}
|
|
696
696
|
else if (definition && definition.scope !== "session") {
|
|
697
697
|
this.settingsManager.restoreProfileDefinitionFromReloadSnapshot(definition.profileName, definition.scope, settingsSnapshot);
|
|
@@ -726,7 +726,7 @@ export class ProfileMenuController {
|
|
|
726
726
|
{
|
|
727
727
|
value: "directory",
|
|
728
728
|
label: "directory",
|
|
729
|
-
description: "~/.pi/agent/
|
|
729
|
+
description: "~/.pi/agent/profiles/directories/<hash>/settings.json",
|
|
730
730
|
},
|
|
731
731
|
{ value: "project", label: "project", description: ".pi/settings.json" },
|
|
732
732
|
{ value: "global", label: "global", description: "~/.pi/agent/settings.json" },
|
|
@@ -1065,7 +1065,7 @@ export class ProfileMenuController {
|
|
|
1065
1065
|
return Boolean(activeProfile && activeProfile.name === profile.name && activeProfile.sourcePath === profile.sourcePath);
|
|
1066
1066
|
});
|
|
1067
1067
|
const settingsSnapshot = this.settingsManager.createReloadSnapshot();
|
|
1068
|
-
const profileFilesSnapshot = scope === "reusable-file" ? captureProfileFiles(
|
|
1068
|
+
const profileFilesSnapshot = scope === "reusable-file" ? captureProfileFiles(getProfilesDir()) : undefined;
|
|
1069
1069
|
let switchedToNone = false;
|
|
1070
1070
|
try {
|
|
1071
1071
|
if (wasActive) {
|