@caupulican/pi-adaptative 0.81.32 → 0.81.35

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.
Files changed (237) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/bundled-resources/extensions/tmux-agent-manager/README.md +69 -0
  3. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts +53 -0
  4. package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -0
  5. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +1282 -0
  6. package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -0
  7. package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +1453 -0
  8. package/dist/bundled-resources/extensions/tmux-agent-manager/templates/builder-validator.json +14 -0
  9. package/dist/bundled-resources/extensions/tmux-agent-manager/templates/claude-trio.json +32 -0
  10. package/dist/bundled-resources/extensions/tmux-agent-manager/templates/full-provider-review.json +15 -0
  11. package/dist/bundled-resources/extensions/tmux-agent-manager/templates/provider-prompt-smoke.json +14 -0
  12. package/dist/bundled-resources/prompts/extensionify.md +5 -4
  13. package/dist/bundled-resources/prompts/skillify.md +5 -5
  14. package/dist/bundled-resources/skills/pi-harness-learning/SKILL.md +6 -3
  15. package/dist/config.d.ts +5 -1
  16. package/dist/config.d.ts.map +1 -1
  17. package/dist/config.js +10 -2
  18. package/dist/config.js.map +1 -1
  19. package/dist/core/agent-session.d.ts +7 -0
  20. package/dist/core/agent-session.d.ts.map +1 -1
  21. package/dist/core/agent-session.js +25 -2
  22. package/dist/core/agent-session.js.map +1 -1
  23. package/dist/core/background-lane-controller.d.ts +12 -3
  24. package/dist/core/background-lane-controller.d.ts.map +1 -1
  25. package/dist/core/background-lane-controller.js +67 -26
  26. package/dist/core/background-lane-controller.js.map +1 -1
  27. package/dist/core/bash-executor.d.ts.map +1 -1
  28. package/dist/core/bash-executor.js +7 -3
  29. package/dist/core/bash-executor.js.map +1 -1
  30. package/dist/core/context/context-store-retention.d.ts +4 -1
  31. package/dist/core/context/context-store-retention.d.ts.map +1 -1
  32. package/dist/core/context/context-store-retention.js +42 -151
  33. package/dist/core/context/context-store-retention.js.map +1 -1
  34. package/dist/core/context-pipeline.d.ts.map +1 -1
  35. package/dist/core/context-pipeline.js +6 -6
  36. package/dist/core/context-pipeline.js.map +1 -1
  37. package/dist/core/exec.d.ts.map +1 -1
  38. package/dist/core/exec.js +25 -39
  39. package/dist/core/exec.js.map +1 -1
  40. package/dist/core/extensions/loader.d.ts +9 -2
  41. package/dist/core/extensions/loader.d.ts.map +1 -1
  42. package/dist/core/extensions/loader.js +105 -21
  43. package/dist/core/extensions/loader.js.map +1 -1
  44. package/dist/core/footer-data-provider.d.ts.map +1 -1
  45. package/dist/core/footer-data-provider.js +2 -0
  46. package/dist/core/footer-data-provider.js.map +1 -1
  47. package/dist/core/goals/goal-state.d.ts +10 -0
  48. package/dist/core/goals/goal-state.d.ts.map +1 -1
  49. package/dist/core/goals/goal-state.js +37 -0
  50. package/dist/core/goals/goal-state.js.map +1 -1
  51. package/dist/core/goals/goal-tool-core.d.ts +11 -0
  52. package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
  53. package/dist/core/goals/goal-tool-core.js +51 -1
  54. package/dist/core/goals/goal-tool-core.js.map +1 -1
  55. package/dist/core/improvement-loop.d.ts.map +1 -1
  56. package/dist/core/improvement-loop.js +26 -5
  57. package/dist/core/improvement-loop.js.map +1 -1
  58. package/dist/core/models/fitness-store.d.ts.map +1 -1
  59. package/dist/core/models/fitness-store.js +1 -1
  60. package/dist/core/models/fitness-store.js.map +1 -1
  61. package/dist/core/models/local-runtime.d.ts +6 -4
  62. package/dist/core/models/local-runtime.d.ts.map +1 -1
  63. package/dist/core/models/local-runtime.js +108 -36
  64. package/dist/core/models/local-runtime.js.map +1 -1
  65. package/dist/core/output-guard.d.ts.map +1 -1
  66. package/dist/core/output-guard.js +23 -8
  67. package/dist/core/output-guard.js.map +1 -1
  68. package/dist/core/package-manager.d.ts.map +1 -1
  69. package/dist/core/package-manager.js +44 -59
  70. package/dist/core/package-manager.js.map +1 -1
  71. package/dist/core/profile-resource-selection.d.ts +16 -0
  72. package/dist/core/profile-resource-selection.d.ts.map +1 -1
  73. package/dist/core/profile-resource-selection.js +41 -0
  74. package/dist/core/profile-resource-selection.js.map +1 -1
  75. package/dist/core/reflection-controller.d.ts.map +1 -1
  76. package/dist/core/reflection-controller.js +18 -1
  77. package/dist/core/reflection-controller.js.map +1 -1
  78. package/dist/core/reload-blockers.d.ts +1 -0
  79. package/dist/core/reload-blockers.d.ts.map +1 -1
  80. package/dist/core/reload-blockers.js +6 -2
  81. package/dist/core/reload-blockers.js.map +1 -1
  82. package/dist/core/resource-loader.d.ts +2 -0
  83. package/dist/core/resource-loader.d.ts.map +1 -1
  84. package/dist/core/resource-loader.js +50 -28
  85. package/dist/core/resource-loader.js.map +1 -1
  86. package/dist/core/settings-manager.d.ts.map +1 -1
  87. package/dist/core/settings-manager.js +1 -1
  88. package/dist/core/settings-manager.js.map +1 -1
  89. package/dist/core/slash-commands.d.ts.map +1 -1
  90. package/dist/core/slash-commands.js +1 -1
  91. package/dist/core/slash-commands.js.map +1 -1
  92. package/dist/core/toolkit/script-runner.d.ts.map +1 -1
  93. package/dist/core/toolkit/script-runner.js +58 -24
  94. package/dist/core/toolkit/script-runner.js.map +1 -1
  95. package/dist/core/tools/bash.d.ts.map +1 -1
  96. package/dist/core/tools/bash.js +13 -26
  97. package/dist/core/tools/bash.js.map +1 -1
  98. package/dist/core/tools/extensionify.d.ts +2 -1
  99. package/dist/core/tools/extensionify.d.ts.map +1 -1
  100. package/dist/core/tools/extensionify.js +11 -8
  101. package/dist/core/tools/extensionify.js.map +1 -1
  102. package/dist/core/tools/find.d.ts.map +1 -1
  103. package/dist/core/tools/find.js +54 -48
  104. package/dist/core/tools/find.js.map +1 -1
  105. package/dist/core/tools/git-filter.d.ts.map +1 -1
  106. package/dist/core/tools/git-filter.js +20 -32
  107. package/dist/core/tools/git-filter.js.map +1 -1
  108. package/dist/core/tools/goal.d.ts +1 -1
  109. package/dist/core/tools/goal.d.ts.map +1 -1
  110. package/dist/core/tools/goal.js +10 -3
  111. package/dist/core/tools/goal.js.map +1 -1
  112. package/dist/core/tools/grep.d.ts.map +1 -1
  113. package/dist/core/tools/grep.js +89 -80
  114. package/dist/core/tools/grep.js.map +1 -1
  115. package/dist/core/tools/output-accumulator.d.ts +2 -0
  116. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  117. package/dist/core/tools/output-accumulator.js +7 -4
  118. package/dist/core/tools/output-accumulator.js.map +1 -1
  119. package/dist/core/tools/read.d.ts.map +1 -1
  120. package/dist/core/tools/read.js +4 -3
  121. package/dist/core/tools/read.js.map +1 -1
  122. package/dist/index.d.ts +2 -1
  123. package/dist/index.d.ts.map +1 -1
  124. package/dist/index.js +2 -1
  125. package/dist/index.js.map +1 -1
  126. package/dist/main.d.ts +2 -0
  127. package/dist/main.d.ts.map +1 -1
  128. package/dist/main.js +23 -4
  129. package/dist/main.js.map +1 -1
  130. package/dist/migrations.d.ts.map +1 -1
  131. package/dist/migrations.js +18 -4
  132. package/dist/migrations.js.map +1 -1
  133. package/dist/modes/interactive/auth-dialogs-controller.d.ts +10 -0
  134. package/dist/modes/interactive/auth-dialogs-controller.d.ts.map +1 -1
  135. package/dist/modes/interactive/auth-dialogs-controller.js +94 -27
  136. package/dist/modes/interactive/auth-dialogs-controller.js.map +1 -1
  137. package/dist/modes/interactive/auto-learn-controller.d.ts.map +1 -1
  138. package/dist/modes/interactive/auto-learn-controller.js +2 -1
  139. package/dist/modes/interactive/auto-learn-controller.js.map +1 -1
  140. package/dist/modes/interactive/components/bordered-loader.d.ts +1 -0
  141. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  142. package/dist/modes/interactive/components/bordered-loader.js +8 -0
  143. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  144. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  145. package/dist/modes/interactive/components/extension-editor.js +6 -15
  146. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  147. package/dist/modes/interactive/components/login-dialog.d.ts +3 -1
  148. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  149. package/dist/modes/interactive/components/login-dialog.js +20 -8
  150. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  151. package/dist/modes/interactive/components/profile-resource-editor.d.ts +4 -1
  152. package/dist/modes/interactive/components/profile-resource-editor.d.ts.map +1 -1
  153. package/dist/modes/interactive/components/profile-resource-editor.js +22 -39
  154. package/dist/modes/interactive/components/profile-resource-editor.js.map +1 -1
  155. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  156. package/dist/modes/interactive/components/session-selector.js +1 -1
  157. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  158. package/dist/modes/interactive/config-backup.d.ts +1 -0
  159. package/dist/modes/interactive/config-backup.d.ts.map +1 -1
  160. package/dist/modes/interactive/config-backup.js +14 -3
  161. package/dist/modes/interactive/config-backup.js.map +1 -1
  162. package/dist/modes/interactive/editor-overlay-host.d.ts +12 -0
  163. package/dist/modes/interactive/editor-overlay-host.d.ts.map +1 -1
  164. package/dist/modes/interactive/editor-overlay-host.js +55 -0
  165. package/dist/modes/interactive/editor-overlay-host.js.map +1 -1
  166. package/dist/modes/interactive/extension-ui-host.d.ts +2 -1
  167. package/dist/modes/interactive/extension-ui-host.d.ts.map +1 -1
  168. package/dist/modes/interactive/extension-ui-host.js +161 -96
  169. package/dist/modes/interactive/extension-ui-host.js.map +1 -1
  170. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  171. package/dist/modes/interactive/external-editor.js +23 -28
  172. package/dist/modes/interactive/external-editor.js.map +1 -1
  173. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  174. package/dist/modes/interactive/interactive-mode.js +14 -8
  175. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  176. package/dist/modes/interactive/profile-menu-controller.d.ts +5 -1
  177. package/dist/modes/interactive/profile-menu-controller.d.ts.map +1 -1
  178. package/dist/modes/interactive/profile-menu-controller.js +118 -24
  179. package/dist/modes/interactive/profile-menu-controller.js.map +1 -1
  180. package/dist/modes/interactive/resource-shell-commands.d.ts +1 -0
  181. package/dist/modes/interactive/resource-shell-commands.d.ts.map +1 -1
  182. package/dist/modes/interactive/resource-shell-commands.js +5 -1
  183. package/dist/modes/interactive/resource-shell-commands.js.map +1 -1
  184. package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
  185. package/dist/modes/interactive/session-flow-commands.js +100 -7
  186. package/dist/modes/interactive/session-flow-commands.js.map +1 -1
  187. package/dist/modes/interactive/session-io-commands.d.ts.map +1 -1
  188. package/dist/modes/interactive/session-io-commands.js +80 -50
  189. package/dist/modes/interactive/session-io-commands.js.map +1 -1
  190. package/dist/modes/interactive/startup-checks.d.ts.map +1 -1
  191. package/dist/modes/interactive/startup-checks.js +14 -17
  192. package/dist/modes/interactive/startup-checks.js.map +1 -1
  193. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  194. package/dist/modes/rpc/rpc-client.js +20 -19
  195. package/dist/modes/rpc/rpc-client.js.map +1 -1
  196. package/dist/package-manager-cli.d.ts.map +1 -1
  197. package/dist/package-manager-cli.js +10 -19
  198. package/dist/package-manager-cli.js.map +1 -1
  199. package/dist/utils/child-process.d.ts +13 -7
  200. package/dist/utils/child-process.d.ts.map +1 -1
  201. package/dist/utils/child-process.js +56 -3
  202. package/dist/utils/child-process.js.map +1 -1
  203. package/dist/utils/clipboard-image.d.ts.map +1 -1
  204. package/dist/utils/clipboard-image.js +3 -2
  205. package/dist/utils/clipboard-image.js.map +1 -1
  206. package/dist/utils/clipboard.d.ts.map +1 -1
  207. package/dist/utils/clipboard.js +17 -10
  208. package/dist/utils/clipboard.js.map +1 -1
  209. package/dist/utils/external-editor-command.d.ts +8 -0
  210. package/dist/utils/external-editor-command.d.ts.map +1 -0
  211. package/dist/utils/external-editor-command.js +60 -0
  212. package/dist/utils/external-editor-command.js.map +1 -0
  213. package/dist/utils/paths.d.ts.map +1 -1
  214. package/dist/utils/paths.js +10 -2
  215. package/dist/utils/paths.js.map +1 -1
  216. package/dist/utils/tools-manager.d.ts.map +1 -1
  217. package/dist/utils/tools-manager.js +23 -10
  218. package/dist/utils/tools-manager.js.map +1 -1
  219. package/dist/utils/work-directory.d.ts +36 -0
  220. package/dist/utils/work-directory.d.ts.map +1 -0
  221. package/dist/utils/work-directory.js +462 -0
  222. package/dist/utils/work-directory.js.map +1 -0
  223. package/docs/index.md +2 -0
  224. package/docs/resources.md +2 -2
  225. package/docs/rpc.md +1 -1
  226. package/docs/tmux-agent-manager.md +48 -0
  227. package/docs/windows.md +100 -7
  228. package/docs/work-directory.md +41 -0
  229. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  230. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  231. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  232. package/examples/extensions/sandbox/package-lock.json +2 -2
  233. package/examples/extensions/sandbox/package.json +1 -1
  234. package/examples/extensions/with-deps/package-lock.json +2 -2
  235. package/examples/extensions/with-deps/package.json +1 -1
  236. package/npm-shrinkwrap.json +12 -12
  237. package/package.json +4 -4
@@ -17,6 +17,7 @@ export interface ProfileMenuControllerUi {
17
17
  showSelector(create: (done: () => void) => {
18
18
  component: Component;
19
19
  focus: Component;
20
+ onSuperseded?: () => void;
20
21
  }): void;
21
22
  showStatus(message: string): void;
22
23
  showError(message: string): void;
@@ -42,6 +43,7 @@ export interface ProfileMenuControllerDeps {
42
43
  getSession(): AgentSession;
43
44
  ui: ProfileMenuControllerUi;
44
45
  }
46
+ export declare function getProfileExtensionDisplayLabel(filePath: string, description?: string): string;
45
47
  export declare class ProfileMenuController {
46
48
  private readonly deps;
47
49
  constructor(deps: ProfileMenuControllerDeps);
@@ -52,6 +54,8 @@ export declare class ProfileMenuController {
52
54
  handleResourcesHubAction(action: string): Promise<void>;
53
55
  private openActiveProfileSelector;
54
56
  private openManageProfilesFlow;
57
+ private openEditProfileModelSelector;
58
+ private editProfileModel;
55
59
  private openPersistProfileSelector;
56
60
  private openDeleteProfileSelector;
57
61
  private openSourcesManagerFlow;
@@ -69,7 +73,7 @@ export declare class ProfileMenuController {
69
73
  private scopeForProfileSource;
70
74
  refreshAfterProfileMutation(profileName: string): Promise<void>;
71
75
  private createProfileFlow;
72
- private selectProfileModelForCreate;
76
+ private selectProfileModel;
73
77
  private openNewProfileEditor;
74
78
  private persistActiveProfile;
75
79
  private deleteProfileFromSource;
@@ -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,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,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,IAAI,KAAK;QAAE,SAAS,EAAE,SAAS,CAAC;QAAC,KAAK,EAAE,SAAS,CAAA;KAAE,GAAG,IAAI,CAAC;IAC7F,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,SAAS,GAAG,IAAI,CAAA;KAAE,CAAC;IACjG,gBAAgB,IAAI,IAAI,CAAC;IACzB,uBAAuB,IAAI,IAAI,CAAC;IAChC,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACtD,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACxC,uCAAuC,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAClE,qBAAqB,CAAC,KAAK,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACrE,oBAAoB,IAAI,IAAI,CAAC;IAC7B,wBAAwB,IAAI,UAAU,EAAE,CAAC;CACzC;AAED,MAAM,WAAW,yBAAyB;IACzC,UAAU,IAAI,YAAY,CAAC;IAC3B,EAAE,EAAE,uBAAuB,CAAC;CAC5B;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;YA4DtB,0BAA0B;YAgC1B,yBAAyB;YA6BzB,sBAAsB;YAiDtB,sBAAsB;YAkDtB,+BAA+B;YAuD/B,+BAA+B;YAsC/B,uBAAuB;YA8IvB,2BAA2B;YA4D3B,oBAAoB;YA0EpB,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,2BAA2B;YA+B3B,oBAAoB;IAwDlC,OAAO,CAAC,oBAAoB;YAkBd,uBAAuB;YA2EvB,2BAA2B;YA+E3B,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(create: (done: () => void) => { component: Component; focus: Component }): 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\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 (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, 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 === \"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 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 };\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.selectProfileModelForCreate();\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 = (p: string) => p.split(/[\\\\/]/).pop() ?? p;\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((e) => ({\n\t\t\t\t\tid: base(e),\n\t\t\t\t\tpath: e,\n\t\t\t\t\tdescription: getExtensionDescription(e),\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): 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) {\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 these identical resources.\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 };\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.selectProfileModelForCreate();\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 selectProfileModelForCreate(): Promise<string | null | undefined> {\n\t\tconst modelOptions = [\n\t\t\t{\n\t\t\t\tvalue: \"(none)\",\n\t\t\t\tlabel: \"(none)\",\n\t\t\t\tdescription: \"Do not pin a foreground profile model; use the session/default model\",\n\t\t\t},\n\t\t\t...this.ui.getAutoLearnModelOptions(),\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\"Pick the foreground model for this profile from authenticated/configured providers.\",\n\t\t\t\t\tmodelOptions,\n\t\t\t\t\t\"(none)\",\n\t\t\t\t\t(value) => {\n\t\t\t\t\t\tdone();\n\t\t\t\t\t\tresolve(value === \"(none)\" ? 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 { component: selector, focus: selector.getSelectList() };\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 };\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 { component: submenu, focus: submenu.getSelectList() };\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,SAAS,GAAG,IAAI,CAAA;KAAE,CAAC;IACjG,gBAAgB,IAAI,IAAI,CAAC;IACzB,uBAAuB,IAAI,IAAI,CAAC;IAChC,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACtD,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACxC,uCAAuC,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IAClE,qBAAqB,CAAC,KAAK,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IACrE,oBAAoB,IAAI,IAAI,CAAC;IAC7B,wBAAwB,IAAI,UAAU,EAAE,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"]}
@@ -45,6 +45,19 @@ function deletionScopeForProfile(profile) {
45
45
  return undefined;
46
46
  }
47
47
  }
48
+ function portableBasename(filePath) {
49
+ return filePath.split(/[\\/]/).filter(Boolean).pop() ?? filePath;
50
+ }
51
+ export function getProfileExtensionDisplayLabel(filePath, description) {
52
+ const normalizedDescription = description?.trim();
53
+ if (normalizedDescription)
54
+ return normalizedDescription;
55
+ const fileName = portableBasename(filePath);
56
+ if (!/^index\.(?:ts|js)$/i.test(fileName))
57
+ return fileName;
58
+ const parentPath = filePath.slice(0, Math.max(0, filePath.length - fileName.length)).replace(/[\\/]$/, "");
59
+ return portableBasename(parentPath) || fileName;
60
+ }
48
61
  export class ProfileMenuController {
49
62
  deps;
50
63
  constructor(deps) {
@@ -123,6 +136,13 @@ export class ProfileMenuController {
123
136
  description: "Create a new resource profile/situation definition.",
124
137
  },
125
138
  ];
139
+ if (editableProfiles.length > 0) {
140
+ options.push({
141
+ value: "edit-model",
142
+ label: "Edit profile model...",
143
+ description: "Pin a model or inherit the session/default model.",
144
+ });
145
+ }
126
146
  if (this.settingsManager.getActiveResourceProfileNames().length > 0) {
127
147
  options.push({
128
148
  value: "persist",
@@ -138,13 +158,16 @@ export class ProfileMenuController {
138
158
  });
139
159
  }
140
160
  this.ui.showSelector((done) => {
141
- const selector = new SelectSubmenu("Manage Profiles / Situations", "Create, delete, or persist profile/situation definitions.", options, "", (value) => {
161
+ const selector = new SelectSubmenu("Manage Profiles / Situations", "Create, edit, delete, or persist profile/situation definitions.", options, "", (value) => {
142
162
  done();
143
163
  if (value === "create") {
144
164
  void this.createProfileFlow().then(() => {
145
165
  void this.ui.showSettingsSelector();
146
166
  });
147
167
  }
168
+ else if (value === "edit-model") {
169
+ this.openEditProfileModelSelector();
170
+ }
148
171
  else if (value === "persist") {
149
172
  void this.openPersistProfileSelector();
150
173
  }
@@ -158,6 +181,56 @@ export class ProfileMenuController {
158
181
  return { component: selector, focus: selector.getSelectList() };
159
182
  });
160
183
  }
184
+ openEditProfileModelSelector() {
185
+ const profiles = this.settingsManager
186
+ .getProfileRegistry()
187
+ .listProfiles()
188
+ .filter((profile) => deletionScopeForProfile(profile) !== undefined);
189
+ if (profiles.length === 0) {
190
+ this.ui.showStatus("No writable profiles available. External and embedded profiles are read-only.");
191
+ return;
192
+ }
193
+ const activeNames = this.settingsManager.getActiveResourceProfileNames();
194
+ const initialValue = profiles.find((profile) => activeNames.includes(profile.name))?.name ?? profiles[0].name;
195
+ const items = profiles.map((profile) => ({
196
+ value: profile.name,
197
+ label: profile.name,
198
+ description: `${profile.model ? `Pinned: ${profile.model}` : "Inherits session/default model"} · ${profile.description || profile.source}`,
199
+ }));
200
+ this.ui.showSelector((done) => {
201
+ const selector = new SelectSubmenu("Edit Profile Model", "Choose a writable profile, then pin or inherit its foreground model.", items, initialValue, (profileName) => {
202
+ done();
203
+ void this.editProfileModel(profileName);
204
+ }, () => {
205
+ done();
206
+ void this.openManageProfilesFlow();
207
+ });
208
+ return { component: selector, focus: selector.getSelectList() };
209
+ });
210
+ }
211
+ async editProfileModel(profileName) {
212
+ const profile = this.settingsManager.getProfileRegistry().getProfile(profileName);
213
+ if (!profile) {
214
+ this.ui.showError(`Profile "${profileName}" is no longer available.`);
215
+ return;
216
+ }
217
+ const scope = deletionScopeForProfile(profile);
218
+ if (!scope) {
219
+ this.ui.showError(`Profile "${profileName}" is read-only (${profile.source}).`);
220
+ return;
221
+ }
222
+ const selectedModel = await this.selectProfileModel(profile.model);
223
+ if (selectedModel === undefined) {
224
+ void this.openManageProfilesFlow();
225
+ return;
226
+ }
227
+ const model = selectedModel ?? undefined;
228
+ if (model === profile.model) {
229
+ this.ui.showStatus(`Profile "${profileName}" model unchanged.`);
230
+ return;
231
+ }
232
+ await this.saveProfileResources({ ...profile, model }, profile.resources, profile.resources, scope, this.settingsManager.getActiveResourceProfileNames().includes(profile.name), true);
233
+ }
161
234
  async openPersistProfileSelector() {
162
235
  const scopeOptions = [
163
236
  { value: "session", label: "session", description: "Runtime only (not written to disk)" },
@@ -291,7 +364,7 @@ export class ProfileMenuController {
291
364
  done();
292
365
  resolve(undefined);
293
366
  }, { tui: this.ui.tui });
294
- return { component: input, focus: input };
367
+ return { component: input, focus: input, onSuperseded: () => resolve(undefined) };
295
368
  });
296
369
  });
297
370
  if (name === undefined) {
@@ -305,7 +378,7 @@ export class ProfileMenuController {
305
378
  return;
306
379
  }
307
380
  try {
308
- const profileModel = await this.selectProfileModelForCreate();
381
+ const profileModel = await this.selectProfileModel();
309
382
  if (profileModel === undefined) {
310
383
  void this.openLibraryManagerFlow();
311
384
  return;
@@ -353,7 +426,7 @@ export class ProfileMenuController {
353
426
  }
354
427
  async getProfileResourceKinds() {
355
428
  const loader = this.session.resourceLoader;
356
- const base = (p) => p.split(/[\\/]/).pop() ?? p;
429
+ const base = portableBasename;
357
430
  const allDiscoverableExtensions = await loader.getDiscoverableExtensionPaths();
358
431
  // Defined BEFORE the skills/prompts arrays below that call it (const = TDZ: defining it
359
432
  // later crashes the whole app with a ReferenceError when the library editor opens).
@@ -462,11 +535,15 @@ export class ProfileMenuController {
462
535
  {
463
536
  kind: "extensions",
464
537
  label: "Extensions",
465
- items: allDiscoverableExtensions.map((e) => ({
466
- id: base(e),
467
- path: e,
468
- description: getExtensionDescription(e),
469
- })),
538
+ items: allDiscoverableExtensions.map((extensionPath) => {
539
+ const description = getExtensionDescription(extensionPath);
540
+ return {
541
+ id: path.resolve(extensionPath),
542
+ label: getProfileExtensionDisplayLabel(extensionPath, description),
543
+ path: extensionPath,
544
+ description,
545
+ };
546
+ }),
470
547
  },
471
548
  {
472
549
  kind: "agents",
@@ -545,7 +622,7 @@ export class ProfileMenuController {
545
622
  return { component: editor, focus: editor };
546
623
  });
547
624
  }
548
- async saveProfileResources(profile, originalResources, resources, scope, isActiveProfile) {
625
+ async saveProfileResources(profile, originalResources, resources, scope, isActiveProfile, runtimeMetadataChanged = false) {
549
626
  const definition = {
550
627
  name: profile.name,
551
628
  description: profile.description,
@@ -556,7 +633,7 @@ export class ProfileMenuController {
556
633
  resources,
557
634
  };
558
635
  const changedKinds = resourceProfileSettingsChangedKinds(originalResources, resources);
559
- if (!isActiveProfile || changedKinds.size === 0) {
636
+ if (!isActiveProfile || (changedKinds.size === 0 && !runtimeMetadataChanged)) {
560
637
  try {
561
638
  this.settingsManager.setProfileDefinition(profile.name, definition, scope);
562
639
  this.ui.showStatus(`Saved profile "${profile.name}" to ${scope}.`);
@@ -584,7 +661,7 @@ export class ProfileMenuController {
584
661
  this.settingsManager.setProfileDefinition(profile.name, definition, scope);
585
662
  await this.settingsManager.flush();
586
663
  // Drop the validation-only inline winner, then refresh the registry from the now-validated
587
- // persistent definition. The live runtime already represents these identical resources.
664
+ // persistent definition. The live runtime already represents the same profile definition.
588
665
  this.settingsManager.restoreReloadSnapshot(settingsSnapshot);
589
666
  await this.settingsManager.reload();
590
667
  }
@@ -828,7 +905,7 @@ export class ProfileMenuController {
828
905
  done();
829
906
  resolve(undefined);
830
907
  }, { tui: this.ui.tui });
831
- return { component: input, focus: input };
908
+ return { component: input, focus: input, onSuperseded: () => resolve(undefined) };
832
909
  });
833
910
  });
834
911
  if (name === undefined) {
@@ -852,7 +929,7 @@ export class ProfileMenuController {
852
929
  this.ui.showError(`Profile/situation "${trimmed}" already exists`);
853
930
  return this.createProfileFlow();
854
931
  }
855
- const profileModel = await this.selectProfileModelForCreate();
932
+ const profileModel = await this.selectProfileModel();
856
933
  if (profileModel === undefined) {
857
934
  this.ui.requestRender();
858
935
  return;
@@ -860,25 +937,38 @@ export class ProfileMenuController {
860
937
  // Open the resource editor on the NEW profile
861
938
  void this.openNewProfileEditor(trimmed, profileModel ?? undefined);
862
939
  }
863
- async selectProfileModelForCreate() {
940
+ async selectProfileModel(profileModel) {
941
+ const inheritValue = "(inherit)";
942
+ const availableModelOptions = [...this.ui.getAutoLearnModelOptions()];
943
+ if (profileModel && !availableModelOptions.some((option) => option.value === profileModel)) {
944
+ availableModelOptions.unshift({
945
+ value: profileModel,
946
+ label: profileModel,
947
+ description: "Current profile model (not currently available)",
948
+ });
949
+ }
864
950
  const modelOptions = [
865
951
  {
866
- value: "(none)",
867
- label: "(none)",
868
- description: "Do not pin a foreground profile model; use the session/default model",
952
+ value: inheritValue,
953
+ label: "Inherit session/default model",
954
+ description: "Remove the profile model pin and use the current session/default model",
869
955
  },
870
- ...this.ui.getAutoLearnModelOptions(),
956
+ ...availableModelOptions,
871
957
  ];
872
958
  return await new Promise((resolve) => {
873
959
  this.ui.showSelector((done) => {
874
- const selector = new SelectSubmenu("Profile Model", "Pick the foreground model for this profile from authenticated/configured providers.", modelOptions, "(none)", (value) => {
960
+ const selector = new SelectSubmenu("Profile Model", "Pin a foreground model for this profile or inherit the session/default model.", modelOptions, profileModel ?? inheritValue, (value) => {
875
961
  done();
876
- resolve(value === "(none)" ? null : value);
962
+ resolve(value === inheritValue ? null : value);
877
963
  }, () => {
878
964
  done();
879
965
  resolve(undefined);
880
966
  });
881
- return { component: selector, focus: selector.getSelectList() };
967
+ return {
968
+ component: selector,
969
+ focus: selector.getSelectList(),
970
+ onSuperseded: () => resolve(undefined),
971
+ };
882
972
  });
883
973
  });
884
974
  }
@@ -1031,7 +1121,7 @@ export class ProfileMenuController {
1031
1121
  done();
1032
1122
  resolve(undefined);
1033
1123
  }, { tui: this.ui.tui });
1034
- return { component: input, focus: input };
1124
+ return { component: input, focus: input, onSuperseded: () => resolve(undefined) };
1035
1125
  });
1036
1126
  });
1037
1127
  if (rootPath === undefined) {
@@ -1061,7 +1151,11 @@ export class ProfileMenuController {
1061
1151
  done();
1062
1152
  resolve(false);
1063
1153
  });
1064
- return { component: submenu, focus: submenu.getSelectList() };
1154
+ return {
1155
+ component: submenu,
1156
+ focus: submenu.getSelectList(),
1157
+ onSuperseded: () => resolve(false),
1158
+ };
1065
1159
  });
1066
1160
  });
1067
1161
  if (!trust) {