@ai-agent-forge/agent-forge 0.88.2 → 0.88.3

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 (453) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +1 -1
  3. package/bundled-plugins/agent-loop-policy/agent-forge.json +1 -1
  4. package/bundled-plugins/agent-loop-policy/plugin.json +1 -1
  5. package/bundled-plugins/coding-tools/agent-forge.json +1 -1
  6. package/bundled-plugins/coding-tools/plugin.json +1 -1
  7. package/bundled-plugins/compaction-policy/agent-forge.json +1 -1
  8. package/bundled-plugins/compaction-policy/plugin.json +1 -1
  9. package/bundled-plugins/overflow-policy/agent-forge.json +1 -1
  10. package/bundled-plugins/overflow-policy/plugin.json +1 -1
  11. package/bundled-plugins/provider-failover/agent-forge.json +1 -1
  12. package/bundled-plugins/provider-failover/plugin.json +1 -1
  13. package/bundled-plugins/retry-policy/agent-forge.json +1 -1
  14. package/bundled-plugins/retry-policy/plugin.json +1 -1
  15. package/dist/artifacts/paged-read.d.ts +6 -1
  16. package/dist/artifacts/paged-read.d.ts.map +1 -1
  17. package/dist/artifacts/paged-read.js.map +1 -1
  18. package/dist/bundle/.build-manifest.json +240 -230
  19. package/dist/bundle/chunks/{anthropic-messages-PLAKXR73.js → anthropic-messages-3FJHRAJL.js} +2 -2
  20. package/dist/bundle/chunks/anthropic.js +1 -1
  21. package/dist/bundle/chunks/{azure-openai-responses-OUWQ2AZD.js → azure-openai-responses-GCL47IDS.js} +1 -1
  22. package/dist/bundle/chunks/bedrock-converse-stream.js +1 -1
  23. package/dist/bundle/chunks/{chunk-6F5JWGKE.js → chunk-32YDZI4J.js} +1 -1
  24. package/dist/bundle/chunks/{chunk-LSP24WNH.js → chunk-755VNWIF.js} +12 -12
  25. package/dist/bundle/chunks/{chunk-HTC5K5SM.js → chunk-B42Y2VME.js} +94 -89
  26. package/dist/bundle/chunks/{chunk-DRQDKNXA.js → chunk-BVVSHK6W.js} +1 -1
  27. package/dist/bundle/chunks/{chunk-6R7UI4IY.js → chunk-QDLOMKF6.js} +1 -1
  28. package/dist/bundle/chunks/{chunk-44I47ACN.js → chunk-V3ACW7VD.js} +1 -1
  29. package/dist/bundle/chunks/{google-generative-ai-DLII6DAT.js → google-generative-ai-6BMXWA44.js} +1 -1
  30. package/dist/bundle/chunks/{google-vertex-G7BZL7GM.js → google-vertex-6H7NLRTK.js} +1 -1
  31. package/dist/bundle/chunks/image-resize-worker.js +1 -1
  32. package/dist/bundle/chunks/{mistral-conversations-JXUK24ID.js → mistral-conversations-IXUHSFSJ.js} +1 -1
  33. package/dist/bundle/chunks/{openai-codex-responses-5GSGFIPG.js → openai-codex-responses-YHUAEVCM.js} +1 -1
  34. package/dist/bundle/chunks/openai-codex.js +1 -1
  35. package/dist/bundle/chunks/{openai-completions-EI2I6DTG.js → openai-completions-ULQCFC72.js} +1 -1
  36. package/dist/bundle/chunks/openai-responses-NLLAJDPS.js +2 -0
  37. package/dist/bundle/chunks/{openrouter-images-G4GQRUSG.js → openrouter-images-GZZQZXMS.js} +1 -1
  38. package/dist/bundle/chunks/openrouter.js +1 -1
  39. package/dist/bundle/chunks/{pi-messages-PWU2VJMR.js → pi-messages-EJTI2EJ3.js} +1 -1
  40. package/dist/bundle/chunks/virtual-modules-TQWEGNNZ.js +5 -0
  41. package/dist/bundle/cli.js +1 -1
  42. package/dist/bundle/client.js +1 -1
  43. package/dist/bundle/index.js +1 -1
  44. package/dist/bundle/rpc-entry.js +1 -1
  45. package/dist/cli/args.d.ts +0 -1
  46. package/dist/cli/args.d.ts.map +1 -1
  47. package/dist/cli/args.js +1 -4
  48. package/dist/cli/args.js.map +1 -1
  49. package/dist/cli/config-selector.d.ts.map +1 -1
  50. package/dist/cli/config-selector.js +1 -1
  51. package/dist/cli/config-selector.js.map +1 -1
  52. package/dist/cli/experimental/cli.d.ts +3 -3
  53. package/dist/cli/experimental/cli.d.ts.map +1 -1
  54. package/dist/cli/experimental/cli.js +2 -2
  55. package/dist/cli/experimental/cli.js.map +1 -1
  56. package/dist/cli/experimental/commands/agent-forge.d.ts +15 -0
  57. package/dist/cli/experimental/commands/agent-forge.d.ts.map +1 -0
  58. package/dist/cli/experimental/commands/{pi.js → agent-forge.js} +4 -4
  59. package/dist/cli/experimental/commands/agent-forge.js.map +1 -0
  60. package/dist/cli/startup-ui.d.ts.map +1 -1
  61. package/dist/cli/startup-ui.js +1 -1
  62. package/dist/cli/startup-ui.js.map +1 -1
  63. package/dist/config.d.ts +4 -4
  64. package/dist/config.d.ts.map +1 -1
  65. package/dist/config.js +7 -7
  66. package/dist/config.js.map +1 -1
  67. package/dist/core/agent-forge-manifest.d.ts +7 -0
  68. package/dist/core/agent-forge-manifest.d.ts.map +1 -0
  69. package/dist/core/{pi-manifest.js → agent-forge-manifest.js} +4 -4
  70. package/dist/core/agent-forge-manifest.js.map +1 -0
  71. package/dist/core/agent-session-compaction.d.ts +1 -1
  72. package/dist/core/agent-session-compaction.d.ts.map +1 -1
  73. package/dist/core/agent-session-compaction.js +3 -3
  74. package/dist/core/agent-session-compaction.js.map +1 -1
  75. package/dist/core/agent-session-lifecycle.d.ts.map +1 -1
  76. package/dist/core/agent-session-lifecycle.js +12 -1
  77. package/dist/core/agent-session-lifecycle.js.map +1 -1
  78. package/dist/core/agent-session-projection.d.ts.map +1 -1
  79. package/dist/core/agent-session-projection.js +3 -3
  80. package/dist/core/agent-session-projection.js.map +1 -1
  81. package/dist/core/agent-session-services.d.ts +1 -1
  82. package/dist/core/agent-session-services.d.ts.map +1 -1
  83. package/dist/core/agent-session-services.js +1 -1
  84. package/dist/core/agent-session-services.js.map +1 -1
  85. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  86. package/dist/core/compaction/branch-summarization.js +1 -1
  87. package/dist/core/compaction/branch-summarization.js.map +1 -1
  88. package/dist/core/experimental.d.ts.map +1 -1
  89. package/dist/core/experimental.js +1 -3
  90. package/dist/core/experimental.js.map +1 -1
  91. package/dist/core/extensions/capability-runtime-store.d.ts +20 -1
  92. package/dist/core/extensions/capability-runtime-store.d.ts.map +1 -1
  93. package/dist/core/extensions/capability-runtime-store.js +67 -0
  94. package/dist/core/extensions/capability-runtime-store.js.map +1 -1
  95. package/dist/core/extensions/capability-runtime-types.d.ts +14 -0
  96. package/dist/core/extensions/capability-runtime-types.d.ts.map +1 -1
  97. package/dist/core/extensions/capability-runtime-types.js +7 -1
  98. package/dist/core/extensions/capability-runtime-types.js.map +1 -1
  99. package/dist/core/extensions/capability-runtime.d.ts.map +1 -1
  100. package/dist/core/extensions/capability-runtime.js +144 -42
  101. package/dist/core/extensions/capability-runtime.js.map +1 -1
  102. package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
  103. package/dist/core/extensions/virtual-modules.js +6 -1
  104. package/dist/core/extensions/virtual-modules.js.map +1 -1
  105. package/dist/core/facade/coding-agent-facade.d.ts +1 -1
  106. package/dist/core/facade/coding-agent-facade.d.ts.map +1 -1
  107. package/dist/core/facade/coding-agent-facade.js +1 -1
  108. package/dist/core/facade/coding-agent-facade.js.map +1 -1
  109. package/dist/core/i18n/locales/zh-cn/core-contract-final.d.ts +1 -1
  110. package/dist/core/i18n/locales/zh-cn/core-contract-final.d.ts.map +1 -1
  111. package/dist/core/i18n/locales/zh-cn/core-contract-final.js +3 -3
  112. package/dist/core/i18n/locales/zh-cn/core-contract-final.js.map +1 -1
  113. package/dist/core/i18n/locales/zh-cn/core-contract-plugins.d.ts.map +1 -1
  114. package/dist/core/i18n/locales/zh-cn/core-contract-plugins.js +1 -1
  115. package/dist/core/i18n/locales/zh-cn/core-contract-plugins.js.map +1 -1
  116. package/dist/core/i18n/locales/zh-cn/core-errors.d.ts.map +1 -1
  117. package/dist/core/i18n/locales/zh-cn/core-errors.js +1 -1
  118. package/dist/core/i18n/locales/zh-cn/core-errors.js.map +1 -1
  119. package/dist/core/i18n/locales/zh-cn/tui-components-misc.d.ts.map +1 -1
  120. package/dist/core/i18n/locales/zh-cn/tui-components-misc.js +2 -0
  121. package/dist/core/i18n/locales/zh-cn/tui-components-misc.js.map +1 -1
  122. package/dist/core/model-resolver.d.ts +2 -0
  123. package/dist/core/model-resolver.d.ts.map +1 -1
  124. package/dist/core/model-resolver.js +4 -1
  125. package/dist/core/model-resolver.js.map +1 -1
  126. package/dist/core/package-resource-collection.d.ts.map +1 -1
  127. package/dist/core/package-resource-collection.js +5 -5
  128. package/dist/core/package-resource-collection.js.map +1 -1
  129. package/dist/core/provider-composer.d.ts.map +1 -1
  130. package/dist/core/provider-composer.js +3 -3
  131. package/dist/core/provider-composer.js.map +1 -1
  132. package/dist/core/resource-loader.d.ts.map +1 -1
  133. package/dist/core/resource-loader.js +1 -1
  134. package/dist/core/resource-loader.js.map +1 -1
  135. package/dist/core/sdk.d.ts +1 -1
  136. package/dist/core/sdk.d.ts.map +1 -1
  137. package/dist/core/sdk.js +6 -7
  138. package/dist/core/sdk.js.map +1 -1
  139. package/dist/core/session-manager.d.ts.map +1 -1
  140. package/dist/core/session-manager.js +4 -4
  141. package/dist/core/session-manager.js.map +1 -1
  142. package/dist/core/settings-manager.d.ts.map +1 -1
  143. package/dist/core/settings-manager.js +5 -10
  144. package/dist/core/settings-manager.js.map +1 -1
  145. package/dist/core/timings.d.ts.map +1 -1
  146. package/dist/core/timings.js +1 -3
  147. package/dist/core/timings.js.map +1 -1
  148. package/dist/core/tools/render-utils.d.ts +1 -1
  149. package/dist/core/tools/render-utils.d.ts.map +1 -1
  150. package/dist/core/tools/render-utils.js.map +1 -1
  151. package/dist/core/tools/tool-definition.d.ts +1 -1
  152. package/dist/core/tools/tool-definition.d.ts.map +1 -1
  153. package/dist/core/tools/tool-definition.js.map +1 -1
  154. package/dist/core/trace-retention.d.ts +16 -1
  155. package/dist/core/trace-retention.d.ts.map +1 -1
  156. package/dist/core/trace-retention.js +43 -20
  157. package/dist/core/trace-retention.js.map +1 -1
  158. package/dist/export-html/ansi-to-html.d.ts.map +1 -0
  159. package/dist/export-html/ansi-to-html.js.map +1 -0
  160. package/dist/{core/export-html → export-html}/index.d.ts +1 -1
  161. package/dist/export-html/index.d.ts.map +1 -0
  162. package/dist/{core/export-html → export-html}/index.js +5 -5
  163. package/dist/export-html/index.js.map +1 -0
  164. package/dist/{core/export-html → export-html}/tool-renderer.d.ts +2 -2
  165. package/dist/export-html/tool-renderer.d.ts.map +1 -0
  166. package/dist/export-html/tool-renderer.js.map +1 -0
  167. package/dist/{modes/interactive → host}/model-catalog-refresh.d.ts +1 -1
  168. package/dist/host/model-catalog-refresh.d.ts.map +1 -0
  169. package/dist/{modes/interactive → host}/model-catalog-refresh.js +1 -1
  170. package/dist/host/model-catalog-refresh.js.map +1 -0
  171. package/dist/index.d.ts +5 -5
  172. package/dist/index.d.ts.map +1 -1
  173. package/dist/index.js +12 -12
  174. package/dist/index.js.map +1 -1
  175. package/dist/main.d.ts.map +1 -1
  176. package/dist/main.js +25 -14
  177. package/dist/main.js.map +1 -1
  178. package/dist/modes/interactive/components/agents-view.d.ts.map +1 -1
  179. package/dist/modes/interactive/components/agents-view.js +1 -1
  180. package/dist/modes/interactive/components/agents-view.js.map +1 -1
  181. package/dist/modes/interactive/components/armin.d.ts.map +1 -1
  182. package/dist/modes/interactive/components/armin.js +1 -1
  183. package/dist/modes/interactive/components/armin.js.map +1 -1
  184. package/dist/modes/interactive/components/assistant-message.d.ts +3 -0
  185. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  186. package/dist/modes/interactive/components/assistant-message.js +83 -24
  187. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  188. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  189. package/dist/modes/interactive/components/bash-execution.js +1 -1
  190. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  191. package/dist/modes/interactive/components/bordered-loader.d.ts +1 -1
  192. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  193. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  194. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  195. package/dist/modes/interactive/components/branch-summary-message.js +1 -1
  196. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  197. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  198. package/dist/modes/interactive/components/compaction-summary-message.js +1 -1
  199. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  200. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  201. package/dist/modes/interactive/components/config-selector.js +1 -1
  202. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  203. package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
  204. package/dist/modes/interactive/components/custom-entry.js +1 -1
  205. package/dist/modes/interactive/components/custom-entry.js.map +1 -1
  206. package/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  207. package/dist/modes/interactive/components/custom-message.js +1 -1
  208. package/dist/modes/interactive/components/custom-message.js.map +1 -1
  209. package/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
  210. package/dist/modes/interactive/components/daxnuts.js +1 -1
  211. package/dist/modes/interactive/components/daxnuts.js.map +1 -1
  212. package/dist/modes/interactive/components/dialog-editor.d.ts.map +1 -1
  213. package/dist/modes/interactive/components/dialog-editor.js +1 -1
  214. package/dist/modes/interactive/components/dialog-editor.js.map +1 -1
  215. package/dist/modes/interactive/components/dialog-input.d.ts.map +1 -1
  216. package/dist/modes/interactive/components/dialog-input.js +1 -1
  217. package/dist/modes/interactive/components/dialog-input.js.map +1 -1
  218. package/dist/modes/interactive/components/dialog-selector.d.ts.map +1 -1
  219. package/dist/modes/interactive/components/dialog-selector.js +1 -1
  220. package/dist/modes/interactive/components/dialog-selector.js.map +1 -1
  221. package/dist/modes/interactive/components/diff.d.ts.map +1 -1
  222. package/dist/modes/interactive/components/diff.js +1 -1
  223. package/dist/modes/interactive/components/diff.js.map +1 -1
  224. package/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  225. package/dist/modes/interactive/components/dynamic-border.js +1 -1
  226. package/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  227. package/dist/modes/interactive/components/first-time-setup.d.ts +1 -1
  228. package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
  229. package/dist/modes/interactive/components/first-time-setup.js +1 -1
  230. package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
  231. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  232. package/dist/modes/interactive/components/footer.js +1 -1
  233. package/dist/modes/interactive/components/footer.js.map +1 -1
  234. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  235. package/dist/modes/interactive/components/keybinding-hints.js +1 -1
  236. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  237. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  238. package/dist/modes/interactive/components/login-dialog.js +1 -1
  239. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  240. package/dist/modes/interactive/components/mermaid.d.ts +1 -1
  241. package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
  242. package/dist/modes/interactive/components/mermaid.js.map +1 -1
  243. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  244. package/dist/modes/interactive/components/model-selector.js +2 -2
  245. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  246. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  247. package/dist/modes/interactive/components/oauth-selector.js +1 -1
  248. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  249. package/dist/modes/interactive/components/plugin-manager-entry.d.ts.map +1 -1
  250. package/dist/modes/interactive/components/plugin-manager-entry.js +1 -1
  251. package/dist/modes/interactive/components/plugin-manager-entry.js.map +1 -1
  252. package/dist/modes/interactive/components/plugin-selection-entry.d.ts.map +1 -1
  253. package/dist/modes/interactive/components/plugin-selection-entry.js +1 -1
  254. package/dist/modes/interactive/components/plugin-selection-entry.js.map +1 -1
  255. package/dist/modes/interactive/components/queue-manager-selector.d.ts.map +1 -1
  256. package/dist/modes/interactive/components/queue-manager-selector.js +1 -1
  257. package/dist/modes/interactive/components/queue-manager-selector.js.map +1 -1
  258. package/dist/modes/interactive/components/render-types.d.ts +1 -1
  259. package/dist/modes/interactive/components/render-types.d.ts.map +1 -1
  260. package/dist/modes/interactive/components/render-types.js.map +1 -1
  261. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  262. package/dist/modes/interactive/components/scoped-models-selector.js +1 -1
  263. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  264. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  265. package/dist/modes/interactive/components/session-selector.js +2 -2
  266. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  267. package/dist/modes/interactive/components/settings-selector.d.ts +1 -1
  268. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  269. package/dist/modes/interactive/components/settings-selector.js +1 -1
  270. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  271. package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -1
  272. package/dist/modes/interactive/components/settings-submenu.js +1 -1
  273. package/dist/modes/interactive/components/settings-submenu.js.map +1 -1
  274. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
  275. package/dist/modes/interactive/components/show-images-selector.js +1 -1
  276. package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
  277. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  278. package/dist/modes/interactive/components/skill-invocation-message.js +1 -1
  279. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  280. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
  281. package/dist/modes/interactive/components/status-indicator.js +1 -1
  282. package/dist/modes/interactive/components/status-indicator.js.map +1 -1
  283. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
  284. package/dist/modes/interactive/components/theme-selector.js +1 -1
  285. package/dist/modes/interactive/components/theme-selector.js.map +1 -1
  286. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  287. package/dist/modes/interactive/components/thinking-selector.js +1 -1
  288. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  289. package/dist/modes/interactive/components/tool-execution.d.ts +2 -0
  290. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  291. package/dist/modes/interactive/components/tool-execution.js +96 -4
  292. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  293. package/dist/modes/interactive/components/tool-run-group.d.ts.map +1 -1
  294. package/dist/modes/interactive/components/tool-run-group.js +1 -1
  295. package/dist/modes/interactive/components/tool-run-group.js.map +1 -1
  296. package/dist/modes/interactive/components/tree-list.d.ts.map +1 -1
  297. package/dist/modes/interactive/components/tree-list.js +1 -1
  298. package/dist/modes/interactive/components/tree-list.js.map +1 -1
  299. package/dist/modes/interactive/components/tree-render.d.ts.map +1 -1
  300. package/dist/modes/interactive/components/tree-render.js +1 -1
  301. package/dist/modes/interactive/components/tree-render.js.map +1 -1
  302. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  303. package/dist/modes/interactive/components/tree-selector.js +1 -1
  304. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  305. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  306. package/dist/modes/interactive/components/user-message-selector.js +1 -1
  307. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  308. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  309. package/dist/modes/interactive/components/user-message.js +1 -1
  310. package/dist/modes/interactive/components/user-message.js.map +1 -1
  311. package/dist/modes/interactive/components/workflow-view.d.ts.map +1 -1
  312. package/dist/modes/interactive/components/workflow-view.js +1 -1
  313. package/dist/modes/interactive/components/workflow-view.js.map +1 -1
  314. package/dist/modes/interactive/interactive-auth.d.ts +1 -1
  315. package/dist/modes/interactive/interactive-auth.d.ts.map +1 -1
  316. package/dist/modes/interactive/interactive-auth.js +1 -1
  317. package/dist/modes/interactive/interactive-auth.js.map +1 -1
  318. package/dist/modes/interactive/interactive-commands.d.ts +123 -6
  319. package/dist/modes/interactive/interactive-commands.d.ts.map +1 -1
  320. package/dist/modes/interactive/interactive-commands.js +691 -4
  321. package/dist/modes/interactive/interactive-commands.js.map +1 -1
  322. package/dist/modes/interactive/interactive-events.d.ts +174 -0
  323. package/dist/modes/interactive/interactive-events.d.ts.map +1 -0
  324. package/dist/modes/interactive/interactive-events.js +704 -0
  325. package/dist/modes/interactive/interactive-events.js.map +1 -0
  326. package/dist/modes/interactive/interactive-format.d.ts.map +1 -1
  327. package/dist/modes/interactive/interactive-format.js +1 -1
  328. package/dist/modes/interactive/interactive-format.js.map +1 -1
  329. package/dist/modes/interactive/interactive-lifecycle.d.ts +94 -0
  330. package/dist/modes/interactive/interactive-lifecycle.d.ts.map +1 -0
  331. package/dist/modes/interactive/interactive-lifecycle.js +177 -0
  332. package/dist/modes/interactive/interactive-lifecycle.js.map +1 -0
  333. package/dist/modes/interactive/interactive-mode.d.ts +240 -133
  334. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  335. package/dist/modes/interactive/interactive-mode.js +251 -2159
  336. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  337. package/dist/modes/interactive/interactive-queues.d.ts +96 -0
  338. package/dist/modes/interactive/interactive-queues.d.ts.map +1 -0
  339. package/dist/modes/interactive/interactive-queues.js +183 -0
  340. package/dist/modes/interactive/interactive-queues.js.map +1 -0
  341. package/dist/modes/interactive/interactive-selectors.d.ts +95 -5
  342. package/dist/modes/interactive/interactive-selectors.d.ts.map +1 -1
  343. package/dist/modes/interactive/interactive-selectors.js +517 -6
  344. package/dist/modes/interactive/interactive-selectors.js.map +1 -1
  345. package/dist/modes/interactive/startup-services.d.ts +31 -0
  346. package/dist/modes/interactive/startup-services.d.ts.map +1 -0
  347. package/dist/modes/interactive/startup-services.js +123 -0
  348. package/dist/modes/interactive/startup-services.js.map +1 -0
  349. package/dist/modes/memory-preheat.d.ts +11 -0
  350. package/dist/modes/memory-preheat.d.ts.map +1 -0
  351. package/dist/modes/memory-preheat.js +20 -0
  352. package/dist/modes/memory-preheat.js.map +1 -0
  353. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  354. package/dist/modes/rpc/rpc-mode.js +3 -1
  355. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  356. package/dist/remote/server-assembly.d.ts.map +1 -1
  357. package/dist/remote/server-assembly.js +7 -2
  358. package/dist/remote/server-assembly.js.map +1 -1
  359. package/dist/suites/builtin-suites.d.ts.map +1 -0
  360. package/dist/suites/builtin-suites.js.map +1 -0
  361. package/dist/suites/resolved-agent-profile.d.ts.map +1 -0
  362. package/dist/suites/resolved-agent-profile.js.map +1 -0
  363. package/dist/suites/suite-lifecycle.d.ts.map +1 -0
  364. package/dist/suites/suite-lifecycle.js.map +1 -0
  365. package/dist/suites/suite-loader.d.ts.map +1 -0
  366. package/dist/suites/suite-loader.js.map +1 -0
  367. package/dist/{modes/interactive/theme → theme}/dark.json +1 -1
  368. package/dist/{modes/interactive/theme → theme}/light.json +1 -1
  369. package/dist/{modes/interactive/theme → theme}/theme-controller.d.ts +1 -1
  370. package/dist/theme/theme-controller.d.ts.map +1 -0
  371. package/dist/{modes/interactive/theme → theme}/theme-controller.js +1 -1
  372. package/dist/theme/theme-controller.js.map +1 -0
  373. package/dist/{modes/interactive/theme → theme}/theme.d.ts +1 -1
  374. package/dist/theme/theme.d.ts.map +1 -0
  375. package/dist/{modes/interactive/theme → theme}/theme.js +5 -5
  376. package/dist/theme/theme.js.map +1 -0
  377. package/docs/compaction.md +7 -7
  378. package/docs/environment-variables.md +10 -4
  379. package/docs/keybindings.md +3 -3
  380. package/docs/models.md +17 -17
  381. package/docs/packages.md +1 -1
  382. package/docs/prompt-templates.md +1 -1
  383. package/docs/rpc.md +2 -2
  384. package/docs/sdk.md +5 -5
  385. package/docs/session-format.md +3 -3
  386. package/docs/settings.md +15 -1
  387. package/docs/shell-aliases.md +1 -1
  388. package/docs/skills.md +1 -1
  389. package/docs/terminal-setup.md +17 -17
  390. package/docs/themes.md +5 -5
  391. package/docs/tmux.md +4 -4
  392. package/docs/tui.md +1 -1
  393. package/docs/usage.md +292 -292
  394. package/docs/windows.md +1 -1
  395. package/examples/extensions/bash-spawn-hook/index.ts +1 -1
  396. package/examples/extensions/dynamic-resources/dynamic.json +1 -1
  397. package/examples/extensions/mcp-stdio/index.d.ts +64 -0
  398. package/examples/extensions/mcp-stdio/index.d.ts.map +1 -0
  399. package/examples/extensions/mcp-stdio/index.js +292 -0
  400. package/examples/extensions/mcp-stdio/index.js.map +1 -0
  401. package/examples/extensions/with-deps/package-lock.json +2 -2
  402. package/examples/extensions/with-deps/package.json +1 -6
  403. package/examples/extensions/with-deps/plugin.json +1 -1
  404. package/package.json +2 -2
  405. package/dist/bundle/chunks/openai-responses-AUJQ3NWT.js +0 -2
  406. package/dist/bundle/chunks/virtual-modules-MRXD3RWG.js +0 -5
  407. package/dist/cli/experimental/commands/pi.d.ts +0 -15
  408. package/dist/cli/experimental/commands/pi.d.ts.map +0 -1
  409. package/dist/cli/experimental/commands/pi.js.map +0 -1
  410. package/dist/core/export-html/ansi-to-html.d.ts.map +0 -1
  411. package/dist/core/export-html/ansi-to-html.js.map +0 -1
  412. package/dist/core/export-html/index.d.ts.map +0 -1
  413. package/dist/core/export-html/index.js.map +0 -1
  414. package/dist/core/export-html/tool-renderer.d.ts.map +0 -1
  415. package/dist/core/export-html/tool-renderer.js.map +0 -1
  416. package/dist/core/pi-manifest.d.ts +0 -7
  417. package/dist/core/pi-manifest.d.ts.map +0 -1
  418. package/dist/core/pi-manifest.js.map +0 -1
  419. package/dist/modes/interactive/model-catalog-refresh.d.ts.map +0 -1
  420. package/dist/modes/interactive/model-catalog-refresh.js.map +0 -1
  421. package/dist/modes/interactive/theme/theme-controller.d.ts.map +0 -1
  422. package/dist/modes/interactive/theme/theme-controller.js.map +0 -1
  423. package/dist/modes/interactive/theme/theme.d.ts.map +0 -1
  424. package/dist/modes/interactive/theme/theme.js.map +0 -1
  425. package/dist/profiles/builtin-suites.d.ts.map +0 -1
  426. package/dist/profiles/builtin-suites.js.map +0 -1
  427. package/dist/profiles/resolved-agent-profile.d.ts.map +0 -1
  428. package/dist/profiles/resolved-agent-profile.js.map +0 -1
  429. package/dist/profiles/suite-lifecycle.d.ts.map +0 -1
  430. package/dist/profiles/suite-lifecycle.js.map +0 -1
  431. package/dist/profiles/suite-loader.d.ts.map +0 -1
  432. package/dist/profiles/suite-loader.js.map +0 -1
  433. package/dist/utils/deprecation.d.ts +0 -4
  434. package/dist/utils/deprecation.d.ts.map +0 -1
  435. package/dist/utils/deprecation.js +0 -13
  436. package/dist/utils/deprecation.js.map +0 -1
  437. /package/dist/{core/export-html → export-html}/ansi-to-html.d.ts +0 -0
  438. /package/dist/{core/export-html → export-html}/ansi-to-html.js +0 -0
  439. /package/dist/{core/export-html → export-html}/template.css +0 -0
  440. /package/dist/{core/export-html → export-html}/template.html +0 -0
  441. /package/dist/{core/export-html → export-html}/template.js +0 -0
  442. /package/dist/{core/export-html → export-html}/tool-renderer.js +0 -0
  443. /package/dist/{core/export-html → export-html}/vendor/highlight.min.js +0 -0
  444. /package/dist/{core/export-html → export-html}/vendor/marked.min.js +0 -0
  445. /package/dist/{profiles → suites}/builtin-suites.d.ts +0 -0
  446. /package/dist/{profiles → suites}/builtin-suites.js +0 -0
  447. /package/dist/{profiles → suites}/resolved-agent-profile.d.ts +0 -0
  448. /package/dist/{profiles → suites}/resolved-agent-profile.js +0 -0
  449. /package/dist/{profiles → suites}/suite-lifecycle.d.ts +0 -0
  450. /package/dist/{profiles → suites}/suite-lifecycle.js +0 -0
  451. /package/dist/{profiles → suites}/suite-loader.d.ts +0 -0
  452. /package/dist/{profiles → suites}/suite-loader.js +0 -0
  453. /package/dist/{modes/interactive/theme → theme}/theme-schema.json +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"scoped-models-selector.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/scoped-models-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,iBAAiB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K,CAAC,GAAG,CAAC,EAAE,EAAE,eAAe,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI,CAgBnF;IAED,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,IAAI,CAE7E;IAED,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,aAAa;IAsBrB,OAAO,CAAC,OAAO;IAef,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,UAAU;IAuDlB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAoH9B;IAED,cAAc,IAAI,KAAK,CAEtB;CACD","sourcesContent":["import type { Api, Model } from \"@agent-forge/ai\";\nimport { Container, type Focusable, fuzzyFilter, getKeybindings, Input, Spacer, Text } from \"@agent-forge/tui\";\nimport { t } from \"../../../core/i18n/index.ts\";\nimport { getModelSearchText } from \"../model-search.ts\";\nimport { theme } from \"../theme/theme.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyDisplayText } from \"./keybinding-hints.ts\";\n\n// EnabledIds: null = all enabled (no filter), string[] = explicit ordered list\ntype EnabledIds = string[] | null;\n\nfunction isEnabled(enabledIds: EnabledIds, id: string): boolean {\n\treturn enabledIds === null || enabledIds.includes(id);\n}\n\nfunction toggle(enabledIds: EnabledIds, id: string): EnabledIds {\n\tif (enabledIds === null) return [id]; // First toggle: start with only this one\n\tconst index = enabledIds.indexOf(id);\n\tif (index >= 0) return [...enabledIds.slice(0, index), ...enabledIds.slice(index + 1)];\n\treturn [...enabledIds, id];\n}\n\nfunction enableAll(enabledIds: EnabledIds, allIds: string[], targetIds?: string[]): EnabledIds {\n\tif (enabledIds === null) return null; // Already all enabled\n\tconst targets = targetIds ?? allIds;\n\tconst result = [...enabledIds];\n\tfor (const id of targets) {\n\t\tif (!result.includes(id)) result.push(id);\n\t}\n\treturn result.length === allIds.length && result.every((id) => allIds.includes(id)) ? null : result;\n}\n\nfunction clearAll(enabledIds: EnabledIds, allIds: string[], targetIds?: string[]): EnabledIds {\n\tif (enabledIds === null) {\n\t\treturn targetIds ? allIds.filter((id) => !targetIds.includes(id)) : [];\n\t}\n\tconst targets = new Set(targetIds ?? enabledIds);\n\treturn enabledIds.filter((id) => !targets.has(id));\n}\n\nfunction move(enabledIds: EnabledIds, id: string, delta: number): EnabledIds {\n\tif (enabledIds === null) return null;\n\tconst list = [...enabledIds];\n\tconst index = list.indexOf(id);\n\tif (index < 0) return list;\n\tconst newIndex = index + delta;\n\tif (newIndex < 0 || newIndex >= list.length) return list;\n\tconst result = [...list];\n\t[result[index], result[newIndex]] = [result[newIndex], result[index]];\n\treturn result;\n}\n\nfunction getSortedIds(enabledIds: EnabledIds, allIds: string[]): string[] {\n\tif (enabledIds === null) return allIds;\n\tconst enabledSet = new Set(enabledIds);\n\treturn [...enabledIds, ...allIds.filter((id) => !enabledSet.has(id))];\n}\n\ninterface ModelItem {\n\tfullId: string;\n\tmodel: Model<Api> | undefined;\n\tenabled: boolean;\n}\n\nexport interface ModelsConfig {\n\tallModels: Model<Api>[];\n\tenabledModelIds: string[] | null;\n\trefreshStatus?: string;\n}\n\nexport interface ModelsCallbacks {\n\t/** Called whenever the enabled model set or order changes (session-only, no persist) */\n\tonChange: (enabledModelIds: string[] | null) => void | Promise<void>;\n\t/** Called when user wants to persist current selection to settings */\n\tonPersist: (enabledModelIds: string[] | null) => void | Promise<void>;\n\tonCancel: () => void;\n}\n\n/**\n * Component for enabling/disabling models in the /model cycling scope.\n * Changes are session-only until explicitly persisted with Ctrl+S.\n */\nexport class ScopedModelsSelectorComponent extends Container implements Focusable {\n\tprivate modelsById: Map<string, Model<Api>> = new Map();\n\tprivate allIds: string[] = [];\n\tprivate enabledIds: EnabledIds = null;\n\tprivate filteredItems: ModelItem[] = [];\n\tprivate selectedIndex = 0;\n\tprivate searchInput: Input;\n\n\t// Focusable implementation - propagate to searchInput for IME cursor positioning\n\tprivate _focused = false;\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\tprivate listContainer: Container;\n\tprivate footerText: Text;\n\tprivate callbacks: ModelsCallbacks;\n\tprivate maxVisible = 8;\n\tprivate isDirty = false;\n\tprivate refreshStatusText?: Text;\n\n\tconstructor(config: ModelsConfig, callbacks: ModelsCallbacks) {\n\t\tsuper();\n\t\tthis.callbacks = callbacks;\n\n\t\tfor (const model of config.allModels) {\n\t\t\tconst fullId = `${model.provider}/${model.id}`;\n\t\t\tthis.modelsById.set(fullId, model);\n\t\t\tthis.allIds.push(fullId);\n\t\t}\n\n\t\tthis.enabledIds = config.enabledModelIds === null ? null : [...config.enabledModelIds];\n\t\tthis.filteredItems = this.buildItems();\n\n\t\t// Header\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.fg(\"accent\", theme.bold(t(\"Model Configuration\"))), 0, 0));\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\ttheme.fg(\n\t\t\t\t\t\"muted\",\n\t\t\t\t\tt(\"Session-only. {key} to save to settings.\", { key: keyDisplayText(\"app.models.save\") }),\n\t\t\t\t),\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Search input\n\t\tthis.searchInput = new Input();\n\t\tthis.addChild(this.searchInput);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// List container\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\n\t\t// Footer hint\n\t\tthis.addChild(new Spacer(1));\n\t\tif (config.refreshStatus) {\n\t\t\tthis.refreshStatusText = new Text(theme.fg(\"muted\", ` ${config.refreshStatus}`), 0, 0);\n\t\t\tthis.addChild(this.refreshStatusText);\n\t\t}\n\t\tthis.footerText = new Text(this.getFooterText(), 0, 0);\n\t\tthis.addChild(this.footerText);\n\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.updateList();\n\t}\n\n\tupdateModels(models: readonly Model<Api>[], enabledModelIds?: string[] | null): void {\n\t\tconst selectedId = this.filteredItems[this.selectedIndex]?.fullId;\n\t\tif (enabledModelIds !== undefined) this.enabledIds = enabledModelIds === null ? null : [...enabledModelIds];\n\t\tthis.modelsById.clear();\n\t\tthis.allIds = [];\n\t\tfor (const model of models) {\n\t\t\tconst fullId = `${model.provider}/${model.id}`;\n\t\t\tthis.modelsById.set(fullId, model);\n\t\t\tthis.allIds.push(fullId);\n\t\t}\n\t\tthis.refresh();\n\t\tconst refreshedIndex = selectedId ? this.filteredItems.findIndex((item) => item.fullId === selectedId) : -1;\n\t\tif (refreshedIndex >= 0) {\n\t\t\tthis.selectedIndex = refreshedIndex;\n\t\t\tthis.updateList();\n\t\t}\n\t}\n\n\tsetRefreshStatus(message: string, kind: \"muted\" | \"success\" | \"warning\"): void {\n\t\tthis.refreshStatusText?.setText(theme.fg(kind, ` ${message}`));\n\t}\n\n\tprivate buildItems(): ModelItem[] {\n\t\treturn getSortedIds(this.enabledIds, this.allIds).map((id) => ({\n\t\t\tfullId: id,\n\t\t\tmodel: this.modelsById.get(id),\n\t\t\tenabled: isEnabled(this.enabledIds, id),\n\t\t}));\n\t}\n\n\tprivate getFooterText(): string {\n\t\tconst enabledCount = this.enabledIds?.filter((id) => this.modelsById.has(id)).length ?? this.allIds.length;\n\t\tconst unavailableCount = this.enabledIds?.filter((id) => !this.modelsById.has(id)).length ?? 0;\n\t\tconst allEnabled = this.enabledIds === null;\n\t\tconst countText = allEnabled\n\t\t\t? t(\"all enabled\")\n\t\t\t: t(\"{enabled}/{total} enabled\", { enabled: enabledCount, total: this.allIds.length }) +\n\t\t\t\t(unavailableCount ? ` · ${t(\"{count} unavailable\", { count: unavailableCount })}` : \"\");\n\t\tconst parts = [\n\t\t\t`${keyDisplayText(\"tui.select.confirm\")} ${t(\"toggle\")}`,\n\t\t\t`${keyDisplayText(\"app.models.enableAll\")} ${t(\"all\")}`,\n\t\t\t`${keyDisplayText(\"app.models.clearAll\")} ${t(\"clear\")}`,\n\t\t\t`${keyDisplayText(\"app.models.toggleProvider\")} ${t(\"provider\")}`,\n\t\t\t`${keyDisplayText(\"app.models.reorderUp\")}/${keyDisplayText(\"app.models.reorderDown\")} ${t(\"reorder\")}`,\n\t\t\t`${keyDisplayText(\"app.models.save\")} ${t(\"save\")}`,\n\t\t\tcountText,\n\t\t];\n\t\treturn this.isDirty\n\t\t\t? theme.fg(\"dim\", ` ${parts.join(\" · \")} `) + theme.fg(\"warning\", t(\"(unsaved)\"))\n\t\t\t: theme.fg(\"dim\", ` ${parts.join(\" · \")}`);\n\t}\n\n\tprivate refresh(): void {\n\t\tconst query = this.searchInput.getValue();\n\t\tconst items = this.buildItems();\n\t\tthis.filteredItems = query\n\t\t\t? fuzzyFilter(items, query, (item) =>\n\t\t\t\t\titem.model\n\t\t\t\t\t\t? getModelSearchText({ id: item.model.id, provider: item.model.provider, name: item.model.name })\n\t\t\t\t\t\t: item.fullId,\n\t\t\t\t)\n\t\t\t: items;\n\t\tthis.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredItems.length - 1));\n\t\tthis.updateList();\n\t\tthis.footerText.setText(this.getFooterText());\n\t}\n\n\tprivate notifyChange(): void {\n\t\tthis.callbacks.onChange(this.enabledIds === null ? null : [...this.enabledIds]);\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\n\t\tif (this.filteredItems.length === 0) {\n\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", ` ${t(\"No matching models\")}`), 0, 0));\n\t\t\treturn;\n\t\t}\n\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredItems.length - this.maxVisible),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + this.maxVisible, this.filteredItems.length);\n\t\tconst allEnabled = this.enabledIds === null;\n\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst item = this.filteredItems[i]!;\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tconst prefix = isSelected ? theme.fg(\"accent\", \"→ \") : \" \";\n\t\t\tconst id = item.model?.id ?? item.fullId;\n\t\t\tconst modelText = isSelected ? theme.fg(\"accent\", id) : id;\n\t\t\tconst providerBadge = theme.fg(\"muted\", item.model ? ` [${item.model.provider}]` : ` ${t(\"[unavailable]\")}`);\n\t\t\tconst status = item.model\n\t\t\t\t? allEnabled\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: item.enabled\n\t\t\t\t\t\t? theme.fg(\"success\", \" ✓\")\n\t\t\t\t\t\t: theme.fg(\"dim\", \" ✗\")\n\t\t\t\t: theme.fg(\"dim\", \" ✗\");\n\t\t\tthis.listContainer.addChild(new Text(`${prefix}${modelText}${providerBadge}${status}`, 0, 0));\n\t\t}\n\n\t\t// Add scroll indicator if needed\n\t\tif (startIndex > 0 || endIndex < this.filteredItems.length) {\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew Text(theme.fg(\"muted\", ` (${this.selectedIndex + 1}/${this.filteredItems.length})`), 0, 0),\n\t\t\t);\n\t\t}\n\n\t\tif (this.filteredItems.length > 0) {\n\t\t\tconst selected = this.filteredItems[this.selectedIndex];\n\t\t\tthis.listContainer.addChild(new Spacer(1));\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew Text(\n\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\"muted\",\n\t\t\t\t\t\t` ${selected.model ? t(\"Model Name: {name}\", { name: selected.model.name }) : t(\"Model unavailable\")}`,\n\t\t\t\t\t),\n\t\t\t\t\t0,\n\t\t\t\t\t0,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\thandleInput(data: string): void {\n\t\tconst kb = getKeybindings();\n\n\t\t// Navigation\n\t\tif (kb.matches(data, \"tui.select.up\")) {\n\t\t\tif (this.filteredItems.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === 0 ? this.filteredItems.length - 1 : this.selectedIndex - 1;\n\t\t\tthis.updateList();\n\t\t\treturn;\n\t\t}\n\t\tif (kb.matches(data, \"tui.select.down\")) {\n\t\t\tif (this.filteredItems.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === this.filteredItems.length - 1 ? 0 : this.selectedIndex + 1;\n\t\t\tthis.updateList();\n\t\t\treturn;\n\t\t}\n\n\t\t// Reorder enabled models\n\t\tconst reorderUp = kb.matches(data, \"app.models.reorderUp\");\n\t\tconst reorderDown = kb.matches(data, \"app.models.reorderDown\");\n\t\tif (reorderUp || reorderDown) {\n\t\t\tif (this.enabledIds === null) return;\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item && isEnabled(this.enabledIds, item.fullId)) {\n\t\t\t\tconst delta = reorderUp ? -1 : 1;\n\t\t\t\tconst currentIndex = this.enabledIds.indexOf(item.fullId);\n\t\t\t\tconst newIndex = currentIndex + delta;\n\t\t\t\t// Only move if within bounds\n\t\t\t\tif (newIndex >= 0 && newIndex < this.enabledIds.length) {\n\t\t\t\t\tthis.enabledIds = move(this.enabledIds, item.fullId, delta);\n\t\t\t\t\tthis.isDirty = true;\n\t\t\t\t\tthis.selectedIndex += delta;\n\t\t\t\t\tthis.refresh();\n\t\t\t\t\tthis.notifyChange();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Toggle on Enter\n\t\tif (kb.matches(data, \"tui.select.confirm\")) {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item) {\n\t\t\t\tthis.enabledIds = toggle(this.enabledIds, item.fullId);\n\t\t\t\tthis.isDirty = true;\n\t\t\t\tthis.refresh();\n\t\t\t\tthis.notifyChange();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Enable all (filtered if search active, otherwise all)\n\t\tif (kb.matches(data, \"app.models.enableAll\")) {\n\t\t\tconst targetIds = this.searchInput.getValue() ? this.filteredItems.map((i) => i.fullId) : undefined;\n\t\t\tthis.enabledIds = enableAll(this.enabledIds, this.allIds, targetIds);\n\t\t\tthis.isDirty = true;\n\t\t\tthis.refresh();\n\t\t\tthis.notifyChange();\n\t\t\treturn;\n\t\t}\n\n\t\t// Clear all (filtered if search active, otherwise all)\n\t\tif (kb.matches(data, \"app.models.clearAll\")) {\n\t\t\tconst targetIds = this.searchInput.getValue() ? this.filteredItems.map((i) => i.fullId) : undefined;\n\t\t\tthis.enabledIds = clearAll(this.enabledIds, this.allIds, targetIds);\n\t\t\tthis.isDirty = true;\n\t\t\tthis.refresh();\n\t\t\tthis.notifyChange();\n\t\t\treturn;\n\t\t}\n\n\t\t// Toggle provider of current item\n\t\tif (kb.matches(data, \"app.models.toggleProvider\")) {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item?.model) {\n\t\t\t\tconst provider = item.model.provider;\n\t\t\t\tconst providerIds = this.allIds.filter((id) => this.modelsById.get(id)!.provider === provider);\n\t\t\t\tconst allEnabled = providerIds.every((id) => isEnabled(this.enabledIds, id));\n\t\t\t\tthis.enabledIds = allEnabled\n\t\t\t\t\t? clearAll(this.enabledIds, this.allIds, providerIds)\n\t\t\t\t\t: enableAll(this.enabledIds, this.allIds, providerIds);\n\t\t\t\tthis.isDirty = true;\n\t\t\t\tthis.refresh();\n\t\t\t\tthis.notifyChange();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Save/persist to settings\n\t\tif (kb.matches(data, \"app.models.save\")) {\n\t\t\tthis.callbacks.onPersist(this.enabledIds === null ? null : [...this.enabledIds]);\n\t\t\tthis.isDirty = false;\n\t\t\tthis.footerText.setText(this.getFooterText());\n\t\t\treturn;\n\t\t}\n\n\t\t// Ctrl+C - clear search or cancel if empty\n\t\tif (kb.matches(data, \"app.models.cancel\")) {\n\t\t\tif (this.searchInput.getValue()) {\n\t\t\t\tthis.searchInput.setValue(\"\");\n\t\t\t\tthis.refresh();\n\t\t\t} else {\n\t\t\t\tthis.callbacks.onCancel();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Escape - cancel (via the shared select-cancel binding; ctrl+c is consumed by app.models.cancel above)\n\t\tif (kb.matches(data, \"tui.select.cancel\")) {\n\t\t\tthis.callbacks.onCancel();\n\t\t\treturn;\n\t\t}\n\n\t\t// Pass everything else to search input\n\t\tthis.searchInput.handleInput(data);\n\t\tthis.refresh();\n\t}\n\n\tgetSearchInput(): Input {\n\t\treturn this.searchInput;\n\t}\n}\n"]}
1
+ {"version":3,"file":"scoped-models-selector.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/scoped-models-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,KAAK,SAAS,EAA+B,KAAK,EAAgB,MAAM,kBAAkB,CAAC;AA+D/G,MAAM,WAAW,YAAY;IAC5B,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;IACxB,eAAe,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,eAAe;IAC/B,wFAAwF;IACxF,QAAQ,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,GAAG,IAAI,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrE,sEAAsE;IACtE,SAAS,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,GAAG,IAAI,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE,QAAQ,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;GAGG;AACH,qBAAa,6BAA8B,SAAQ,SAAU,YAAW,SAAS;IAChF,OAAO,CAAC,UAAU,CAAsC;IACxD,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,UAAU,CAAoB;IACtC,OAAO,CAAC,aAAa,CAAmB;IACxC,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,WAAW,CAAQ;IAG3B,OAAO,CAAC,QAAQ,CAAS;IACzB,IAAI,OAAO,IAAI,OAAO,CAErB;IACD,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAGzB;IACD,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,UAAU,CAAO;IACzB,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,iBAAiB,CAAC,CAAO;IAEjC,YAAY,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAiD3D;IAED,YAAY,CAAC,MAAM,EAAE,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,eAAe,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,GAAG,IAAI,CAgBnF;IAED,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,IAAI,CAE7E;IAED,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,aAAa;IAsBrB,OAAO,CAAC,OAAO;IAef,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,UAAU;IAuDlB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAoH9B;IAED,cAAc,IAAI,KAAK,CAEtB;CACD","sourcesContent":["import type { Api, Model } from \"@agent-forge/ai\";\nimport { Container, type Focusable, fuzzyFilter, getKeybindings, Input, Spacer, Text } from \"@agent-forge/tui\";\nimport { t } from \"../../../core/i18n/index.ts\";\nimport { theme } from \"../../../theme/theme.ts\";\nimport { getModelSearchText } from \"../model-search.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyDisplayText } from \"./keybinding-hints.ts\";\n\n// EnabledIds: null = all enabled (no filter), string[] = explicit ordered list\ntype EnabledIds = string[] | null;\n\nfunction isEnabled(enabledIds: EnabledIds, id: string): boolean {\n\treturn enabledIds === null || enabledIds.includes(id);\n}\n\nfunction toggle(enabledIds: EnabledIds, id: string): EnabledIds {\n\tif (enabledIds === null) return [id]; // First toggle: start with only this one\n\tconst index = enabledIds.indexOf(id);\n\tif (index >= 0) return [...enabledIds.slice(0, index), ...enabledIds.slice(index + 1)];\n\treturn [...enabledIds, id];\n}\n\nfunction enableAll(enabledIds: EnabledIds, allIds: string[], targetIds?: string[]): EnabledIds {\n\tif (enabledIds === null) return null; // Already all enabled\n\tconst targets = targetIds ?? allIds;\n\tconst result = [...enabledIds];\n\tfor (const id of targets) {\n\t\tif (!result.includes(id)) result.push(id);\n\t}\n\treturn result.length === allIds.length && result.every((id) => allIds.includes(id)) ? null : result;\n}\n\nfunction clearAll(enabledIds: EnabledIds, allIds: string[], targetIds?: string[]): EnabledIds {\n\tif (enabledIds === null) {\n\t\treturn targetIds ? allIds.filter((id) => !targetIds.includes(id)) : [];\n\t}\n\tconst targets = new Set(targetIds ?? enabledIds);\n\treturn enabledIds.filter((id) => !targets.has(id));\n}\n\nfunction move(enabledIds: EnabledIds, id: string, delta: number): EnabledIds {\n\tif (enabledIds === null) return null;\n\tconst list = [...enabledIds];\n\tconst index = list.indexOf(id);\n\tif (index < 0) return list;\n\tconst newIndex = index + delta;\n\tif (newIndex < 0 || newIndex >= list.length) return list;\n\tconst result = [...list];\n\t[result[index], result[newIndex]] = [result[newIndex], result[index]];\n\treturn result;\n}\n\nfunction getSortedIds(enabledIds: EnabledIds, allIds: string[]): string[] {\n\tif (enabledIds === null) return allIds;\n\tconst enabledSet = new Set(enabledIds);\n\treturn [...enabledIds, ...allIds.filter((id) => !enabledSet.has(id))];\n}\n\ninterface ModelItem {\n\tfullId: string;\n\tmodel: Model<Api> | undefined;\n\tenabled: boolean;\n}\n\nexport interface ModelsConfig {\n\tallModels: Model<Api>[];\n\tenabledModelIds: string[] | null;\n\trefreshStatus?: string;\n}\n\nexport interface ModelsCallbacks {\n\t/** Called whenever the enabled model set or order changes (session-only, no persist) */\n\tonChange: (enabledModelIds: string[] | null) => void | Promise<void>;\n\t/** Called when user wants to persist current selection to settings */\n\tonPersist: (enabledModelIds: string[] | null) => void | Promise<void>;\n\tonCancel: () => void;\n}\n\n/**\n * Component for enabling/disabling models in the /model cycling scope.\n * Changes are session-only until explicitly persisted with Ctrl+S.\n */\nexport class ScopedModelsSelectorComponent extends Container implements Focusable {\n\tprivate modelsById: Map<string, Model<Api>> = new Map();\n\tprivate allIds: string[] = [];\n\tprivate enabledIds: EnabledIds = null;\n\tprivate filteredItems: ModelItem[] = [];\n\tprivate selectedIndex = 0;\n\tprivate searchInput: Input;\n\n\t// Focusable implementation - propagate to searchInput for IME cursor positioning\n\tprivate _focused = false;\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\tprivate listContainer: Container;\n\tprivate footerText: Text;\n\tprivate callbacks: ModelsCallbacks;\n\tprivate maxVisible = 8;\n\tprivate isDirty = false;\n\tprivate refreshStatusText?: Text;\n\n\tconstructor(config: ModelsConfig, callbacks: ModelsCallbacks) {\n\t\tsuper();\n\t\tthis.callbacks = callbacks;\n\n\t\tfor (const model of config.allModels) {\n\t\t\tconst fullId = `${model.provider}/${model.id}`;\n\t\t\tthis.modelsById.set(fullId, model);\n\t\t\tthis.allIds.push(fullId);\n\t\t}\n\n\t\tthis.enabledIds = config.enabledModelIds === null ? null : [...config.enabledModelIds];\n\t\tthis.filteredItems = this.buildItems();\n\n\t\t// Header\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.fg(\"accent\", theme.bold(t(\"Model Configuration\"))), 0, 0));\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\ttheme.fg(\n\t\t\t\t\t\"muted\",\n\t\t\t\t\tt(\"Session-only. {key} to save to settings.\", { key: keyDisplayText(\"app.models.save\") }),\n\t\t\t\t),\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Search input\n\t\tthis.searchInput = new Input();\n\t\tthis.addChild(this.searchInput);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// List container\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\n\t\t// Footer hint\n\t\tthis.addChild(new Spacer(1));\n\t\tif (config.refreshStatus) {\n\t\t\tthis.refreshStatusText = new Text(theme.fg(\"muted\", ` ${config.refreshStatus}`), 0, 0);\n\t\t\tthis.addChild(this.refreshStatusText);\n\t\t}\n\t\tthis.footerText = new Text(this.getFooterText(), 0, 0);\n\t\tthis.addChild(this.footerText);\n\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.updateList();\n\t}\n\n\tupdateModels(models: readonly Model<Api>[], enabledModelIds?: string[] | null): void {\n\t\tconst selectedId = this.filteredItems[this.selectedIndex]?.fullId;\n\t\tif (enabledModelIds !== undefined) this.enabledIds = enabledModelIds === null ? null : [...enabledModelIds];\n\t\tthis.modelsById.clear();\n\t\tthis.allIds = [];\n\t\tfor (const model of models) {\n\t\t\tconst fullId = `${model.provider}/${model.id}`;\n\t\t\tthis.modelsById.set(fullId, model);\n\t\t\tthis.allIds.push(fullId);\n\t\t}\n\t\tthis.refresh();\n\t\tconst refreshedIndex = selectedId ? this.filteredItems.findIndex((item) => item.fullId === selectedId) : -1;\n\t\tif (refreshedIndex >= 0) {\n\t\t\tthis.selectedIndex = refreshedIndex;\n\t\t\tthis.updateList();\n\t\t}\n\t}\n\n\tsetRefreshStatus(message: string, kind: \"muted\" | \"success\" | \"warning\"): void {\n\t\tthis.refreshStatusText?.setText(theme.fg(kind, ` ${message}`));\n\t}\n\n\tprivate buildItems(): ModelItem[] {\n\t\treturn getSortedIds(this.enabledIds, this.allIds).map((id) => ({\n\t\t\tfullId: id,\n\t\t\tmodel: this.modelsById.get(id),\n\t\t\tenabled: isEnabled(this.enabledIds, id),\n\t\t}));\n\t}\n\n\tprivate getFooterText(): string {\n\t\tconst enabledCount = this.enabledIds?.filter((id) => this.modelsById.has(id)).length ?? this.allIds.length;\n\t\tconst unavailableCount = this.enabledIds?.filter((id) => !this.modelsById.has(id)).length ?? 0;\n\t\tconst allEnabled = this.enabledIds === null;\n\t\tconst countText = allEnabled\n\t\t\t? t(\"all enabled\")\n\t\t\t: t(\"{enabled}/{total} enabled\", { enabled: enabledCount, total: this.allIds.length }) +\n\t\t\t\t(unavailableCount ? ` · ${t(\"{count} unavailable\", { count: unavailableCount })}` : \"\");\n\t\tconst parts = [\n\t\t\t`${keyDisplayText(\"tui.select.confirm\")} ${t(\"toggle\")}`,\n\t\t\t`${keyDisplayText(\"app.models.enableAll\")} ${t(\"all\")}`,\n\t\t\t`${keyDisplayText(\"app.models.clearAll\")} ${t(\"clear\")}`,\n\t\t\t`${keyDisplayText(\"app.models.toggleProvider\")} ${t(\"provider\")}`,\n\t\t\t`${keyDisplayText(\"app.models.reorderUp\")}/${keyDisplayText(\"app.models.reorderDown\")} ${t(\"reorder\")}`,\n\t\t\t`${keyDisplayText(\"app.models.save\")} ${t(\"save\")}`,\n\t\t\tcountText,\n\t\t];\n\t\treturn this.isDirty\n\t\t\t? theme.fg(\"dim\", ` ${parts.join(\" · \")} `) + theme.fg(\"warning\", t(\"(unsaved)\"))\n\t\t\t: theme.fg(\"dim\", ` ${parts.join(\" · \")}`);\n\t}\n\n\tprivate refresh(): void {\n\t\tconst query = this.searchInput.getValue();\n\t\tconst items = this.buildItems();\n\t\tthis.filteredItems = query\n\t\t\t? fuzzyFilter(items, query, (item) =>\n\t\t\t\t\titem.model\n\t\t\t\t\t\t? getModelSearchText({ id: item.model.id, provider: item.model.provider, name: item.model.name })\n\t\t\t\t\t\t: item.fullId,\n\t\t\t\t)\n\t\t\t: items;\n\t\tthis.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredItems.length - 1));\n\t\tthis.updateList();\n\t\tthis.footerText.setText(this.getFooterText());\n\t}\n\n\tprivate notifyChange(): void {\n\t\tthis.callbacks.onChange(this.enabledIds === null ? null : [...this.enabledIds]);\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\n\t\tif (this.filteredItems.length === 0) {\n\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", ` ${t(\"No matching models\")}`), 0, 0));\n\t\t\treturn;\n\t\t}\n\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredItems.length - this.maxVisible),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + this.maxVisible, this.filteredItems.length);\n\t\tconst allEnabled = this.enabledIds === null;\n\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst item = this.filteredItems[i]!;\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tconst prefix = isSelected ? theme.fg(\"accent\", \"→ \") : \" \";\n\t\t\tconst id = item.model?.id ?? item.fullId;\n\t\t\tconst modelText = isSelected ? theme.fg(\"accent\", id) : id;\n\t\t\tconst providerBadge = theme.fg(\"muted\", item.model ? ` [${item.model.provider}]` : ` ${t(\"[unavailable]\")}`);\n\t\t\tconst status = item.model\n\t\t\t\t? allEnabled\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: item.enabled\n\t\t\t\t\t\t? theme.fg(\"success\", \" ✓\")\n\t\t\t\t\t\t: theme.fg(\"dim\", \" ✗\")\n\t\t\t\t: theme.fg(\"dim\", \" ✗\");\n\t\t\tthis.listContainer.addChild(new Text(`${prefix}${modelText}${providerBadge}${status}`, 0, 0));\n\t\t}\n\n\t\t// Add scroll indicator if needed\n\t\tif (startIndex > 0 || endIndex < this.filteredItems.length) {\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew Text(theme.fg(\"muted\", ` (${this.selectedIndex + 1}/${this.filteredItems.length})`), 0, 0),\n\t\t\t);\n\t\t}\n\n\t\tif (this.filteredItems.length > 0) {\n\t\t\tconst selected = this.filteredItems[this.selectedIndex];\n\t\t\tthis.listContainer.addChild(new Spacer(1));\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew Text(\n\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\"muted\",\n\t\t\t\t\t\t` ${selected.model ? t(\"Model Name: {name}\", { name: selected.model.name }) : t(\"Model unavailable\")}`,\n\t\t\t\t\t),\n\t\t\t\t\t0,\n\t\t\t\t\t0,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\thandleInput(data: string): void {\n\t\tconst kb = getKeybindings();\n\n\t\t// Navigation\n\t\tif (kb.matches(data, \"tui.select.up\")) {\n\t\t\tif (this.filteredItems.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === 0 ? this.filteredItems.length - 1 : this.selectedIndex - 1;\n\t\t\tthis.updateList();\n\t\t\treturn;\n\t\t}\n\t\tif (kb.matches(data, \"tui.select.down\")) {\n\t\t\tif (this.filteredItems.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === this.filteredItems.length - 1 ? 0 : this.selectedIndex + 1;\n\t\t\tthis.updateList();\n\t\t\treturn;\n\t\t}\n\n\t\t// Reorder enabled models\n\t\tconst reorderUp = kb.matches(data, \"app.models.reorderUp\");\n\t\tconst reorderDown = kb.matches(data, \"app.models.reorderDown\");\n\t\tif (reorderUp || reorderDown) {\n\t\t\tif (this.enabledIds === null) return;\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item && isEnabled(this.enabledIds, item.fullId)) {\n\t\t\t\tconst delta = reorderUp ? -1 : 1;\n\t\t\t\tconst currentIndex = this.enabledIds.indexOf(item.fullId);\n\t\t\t\tconst newIndex = currentIndex + delta;\n\t\t\t\t// Only move if within bounds\n\t\t\t\tif (newIndex >= 0 && newIndex < this.enabledIds.length) {\n\t\t\t\t\tthis.enabledIds = move(this.enabledIds, item.fullId, delta);\n\t\t\t\t\tthis.isDirty = true;\n\t\t\t\t\tthis.selectedIndex += delta;\n\t\t\t\t\tthis.refresh();\n\t\t\t\t\tthis.notifyChange();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Toggle on Enter\n\t\tif (kb.matches(data, \"tui.select.confirm\")) {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item) {\n\t\t\t\tthis.enabledIds = toggle(this.enabledIds, item.fullId);\n\t\t\t\tthis.isDirty = true;\n\t\t\t\tthis.refresh();\n\t\t\t\tthis.notifyChange();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Enable all (filtered if search active, otherwise all)\n\t\tif (kb.matches(data, \"app.models.enableAll\")) {\n\t\t\tconst targetIds = this.searchInput.getValue() ? this.filteredItems.map((i) => i.fullId) : undefined;\n\t\t\tthis.enabledIds = enableAll(this.enabledIds, this.allIds, targetIds);\n\t\t\tthis.isDirty = true;\n\t\t\tthis.refresh();\n\t\t\tthis.notifyChange();\n\t\t\treturn;\n\t\t}\n\n\t\t// Clear all (filtered if search active, otherwise all)\n\t\tif (kb.matches(data, \"app.models.clearAll\")) {\n\t\t\tconst targetIds = this.searchInput.getValue() ? this.filteredItems.map((i) => i.fullId) : undefined;\n\t\t\tthis.enabledIds = clearAll(this.enabledIds, this.allIds, targetIds);\n\t\t\tthis.isDirty = true;\n\t\t\tthis.refresh();\n\t\t\tthis.notifyChange();\n\t\t\treturn;\n\t\t}\n\n\t\t// Toggle provider of current item\n\t\tif (kb.matches(data, \"app.models.toggleProvider\")) {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item?.model) {\n\t\t\t\tconst provider = item.model.provider;\n\t\t\t\tconst providerIds = this.allIds.filter((id) => this.modelsById.get(id)!.provider === provider);\n\t\t\t\tconst allEnabled = providerIds.every((id) => isEnabled(this.enabledIds, id));\n\t\t\t\tthis.enabledIds = allEnabled\n\t\t\t\t\t? clearAll(this.enabledIds, this.allIds, providerIds)\n\t\t\t\t\t: enableAll(this.enabledIds, this.allIds, providerIds);\n\t\t\t\tthis.isDirty = true;\n\t\t\t\tthis.refresh();\n\t\t\t\tthis.notifyChange();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Save/persist to settings\n\t\tif (kb.matches(data, \"app.models.save\")) {\n\t\t\tthis.callbacks.onPersist(this.enabledIds === null ? null : [...this.enabledIds]);\n\t\t\tthis.isDirty = false;\n\t\t\tthis.footerText.setText(this.getFooterText());\n\t\t\treturn;\n\t\t}\n\n\t\t// Ctrl+C - clear search or cancel if empty\n\t\tif (kb.matches(data, \"app.models.cancel\")) {\n\t\t\tif (this.searchInput.getValue()) {\n\t\t\t\tthis.searchInput.setValue(\"\");\n\t\t\t\tthis.refresh();\n\t\t\t} else {\n\t\t\t\tthis.callbacks.onCancel();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Escape - cancel (via the shared select-cancel binding; ctrl+c is consumed by app.models.cancel above)\n\t\tif (kb.matches(data, \"tui.select.cancel\")) {\n\t\t\tthis.callbacks.onCancel();\n\t\t\treturn;\n\t\t}\n\n\t\t// Pass everything else to search input\n\t\tthis.searchInput.handleInput(data);\n\t\tthis.refresh();\n\t}\n\n\tgetSearchInput(): Input {\n\t\treturn this.searchInput;\n\t}\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { Container, fuzzyFilter, getKeybindings, Input, Spacer, Text } from "@agent-forge/tui";
2
2
  import { t } from "../../../core/i18n/index.js";
3
+ import { theme } from "../../../theme/theme.js";
3
4
  import { getModelSearchText } from "../model-search.js";
4
- import { theme } from "../theme/theme.js";
5
5
  import { DynamicBorder } from "./dynamic-border.js";
6
6
  import { keyDisplayText } from "./keybinding-hints.js";
7
7
  function isEnabled(enabledIds, id) {
@@ -1 +1 @@
1
- {"version":3,"file":"scoped-models-selector.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/scoped-models-selector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAkB,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;QACvC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,CAAC,OAAO,EAAE,CAAC;IAAA,CACf;IAED,cAAc,GAAU;QACvB,OAAO,IAAI,CAAC,WAAW,CAAC;IAAA,CACxB;CACD","sourcesContent":["import type { Api, Model } from \"@agent-forge/ai\";\nimport { Container, type Focusable, fuzzyFilter, getKeybindings, Input, Spacer, Text } from \"@agent-forge/tui\";\nimport { t } from \"../../../core/i18n/index.ts\";\nimport { getModelSearchText } from \"../model-search.ts\";\nimport { theme } from \"../theme/theme.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyDisplayText } from \"./keybinding-hints.ts\";\n\n// EnabledIds: null = all enabled (no filter), string[] = explicit ordered list\ntype EnabledIds = string[] | null;\n\nfunction isEnabled(enabledIds: EnabledIds, id: string): boolean {\n\treturn enabledIds === null || enabledIds.includes(id);\n}\n\nfunction toggle(enabledIds: EnabledIds, id: string): EnabledIds {\n\tif (enabledIds === null) return [id]; // First toggle: start with only this one\n\tconst index = enabledIds.indexOf(id);\n\tif (index >= 0) return [...enabledIds.slice(0, index), ...enabledIds.slice(index + 1)];\n\treturn [...enabledIds, id];\n}\n\nfunction enableAll(enabledIds: EnabledIds, allIds: string[], targetIds?: string[]): EnabledIds {\n\tif (enabledIds === null) return null; // Already all enabled\n\tconst targets = targetIds ?? allIds;\n\tconst result = [...enabledIds];\n\tfor (const id of targets) {\n\t\tif (!result.includes(id)) result.push(id);\n\t}\n\treturn result.length === allIds.length && result.every((id) => allIds.includes(id)) ? null : result;\n}\n\nfunction clearAll(enabledIds: EnabledIds, allIds: string[], targetIds?: string[]): EnabledIds {\n\tif (enabledIds === null) {\n\t\treturn targetIds ? allIds.filter((id) => !targetIds.includes(id)) : [];\n\t}\n\tconst targets = new Set(targetIds ?? enabledIds);\n\treturn enabledIds.filter((id) => !targets.has(id));\n}\n\nfunction move(enabledIds: EnabledIds, id: string, delta: number): EnabledIds {\n\tif (enabledIds === null) return null;\n\tconst list = [...enabledIds];\n\tconst index = list.indexOf(id);\n\tif (index < 0) return list;\n\tconst newIndex = index + delta;\n\tif (newIndex < 0 || newIndex >= list.length) return list;\n\tconst result = [...list];\n\t[result[index], result[newIndex]] = [result[newIndex], result[index]];\n\treturn result;\n}\n\nfunction getSortedIds(enabledIds: EnabledIds, allIds: string[]): string[] {\n\tif (enabledIds === null) return allIds;\n\tconst enabledSet = new Set(enabledIds);\n\treturn [...enabledIds, ...allIds.filter((id) => !enabledSet.has(id))];\n}\n\ninterface ModelItem {\n\tfullId: string;\n\tmodel: Model<Api> | undefined;\n\tenabled: boolean;\n}\n\nexport interface ModelsConfig {\n\tallModels: Model<Api>[];\n\tenabledModelIds: string[] | null;\n\trefreshStatus?: string;\n}\n\nexport interface ModelsCallbacks {\n\t/** Called whenever the enabled model set or order changes (session-only, no persist) */\n\tonChange: (enabledModelIds: string[] | null) => void | Promise<void>;\n\t/** Called when user wants to persist current selection to settings */\n\tonPersist: (enabledModelIds: string[] | null) => void | Promise<void>;\n\tonCancel: () => void;\n}\n\n/**\n * Component for enabling/disabling models in the /model cycling scope.\n * Changes are session-only until explicitly persisted with Ctrl+S.\n */\nexport class ScopedModelsSelectorComponent extends Container implements Focusable {\n\tprivate modelsById: Map<string, Model<Api>> = new Map();\n\tprivate allIds: string[] = [];\n\tprivate enabledIds: EnabledIds = null;\n\tprivate filteredItems: ModelItem[] = [];\n\tprivate selectedIndex = 0;\n\tprivate searchInput: Input;\n\n\t// Focusable implementation - propagate to searchInput for IME cursor positioning\n\tprivate _focused = false;\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\tprivate listContainer: Container;\n\tprivate footerText: Text;\n\tprivate callbacks: ModelsCallbacks;\n\tprivate maxVisible = 8;\n\tprivate isDirty = false;\n\tprivate refreshStatusText?: Text;\n\n\tconstructor(config: ModelsConfig, callbacks: ModelsCallbacks) {\n\t\tsuper();\n\t\tthis.callbacks = callbacks;\n\n\t\tfor (const model of config.allModels) {\n\t\t\tconst fullId = `${model.provider}/${model.id}`;\n\t\t\tthis.modelsById.set(fullId, model);\n\t\t\tthis.allIds.push(fullId);\n\t\t}\n\n\t\tthis.enabledIds = config.enabledModelIds === null ? null : [...config.enabledModelIds];\n\t\tthis.filteredItems = this.buildItems();\n\n\t\t// Header\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.fg(\"accent\", theme.bold(t(\"Model Configuration\"))), 0, 0));\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\ttheme.fg(\n\t\t\t\t\t\"muted\",\n\t\t\t\t\tt(\"Session-only. {key} to save to settings.\", { key: keyDisplayText(\"app.models.save\") }),\n\t\t\t\t),\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Search input\n\t\tthis.searchInput = new Input();\n\t\tthis.addChild(this.searchInput);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// List container\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\n\t\t// Footer hint\n\t\tthis.addChild(new Spacer(1));\n\t\tif (config.refreshStatus) {\n\t\t\tthis.refreshStatusText = new Text(theme.fg(\"muted\", ` ${config.refreshStatus}`), 0, 0);\n\t\t\tthis.addChild(this.refreshStatusText);\n\t\t}\n\t\tthis.footerText = new Text(this.getFooterText(), 0, 0);\n\t\tthis.addChild(this.footerText);\n\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.updateList();\n\t}\n\n\tupdateModels(models: readonly Model<Api>[], enabledModelIds?: string[] | null): void {\n\t\tconst selectedId = this.filteredItems[this.selectedIndex]?.fullId;\n\t\tif (enabledModelIds !== undefined) this.enabledIds = enabledModelIds === null ? null : [...enabledModelIds];\n\t\tthis.modelsById.clear();\n\t\tthis.allIds = [];\n\t\tfor (const model of models) {\n\t\t\tconst fullId = `${model.provider}/${model.id}`;\n\t\t\tthis.modelsById.set(fullId, model);\n\t\t\tthis.allIds.push(fullId);\n\t\t}\n\t\tthis.refresh();\n\t\tconst refreshedIndex = selectedId ? this.filteredItems.findIndex((item) => item.fullId === selectedId) : -1;\n\t\tif (refreshedIndex >= 0) {\n\t\t\tthis.selectedIndex = refreshedIndex;\n\t\t\tthis.updateList();\n\t\t}\n\t}\n\n\tsetRefreshStatus(message: string, kind: \"muted\" | \"success\" | \"warning\"): void {\n\t\tthis.refreshStatusText?.setText(theme.fg(kind, ` ${message}`));\n\t}\n\n\tprivate buildItems(): ModelItem[] {\n\t\treturn getSortedIds(this.enabledIds, this.allIds).map((id) => ({\n\t\t\tfullId: id,\n\t\t\tmodel: this.modelsById.get(id),\n\t\t\tenabled: isEnabled(this.enabledIds, id),\n\t\t}));\n\t}\n\n\tprivate getFooterText(): string {\n\t\tconst enabledCount = this.enabledIds?.filter((id) => this.modelsById.has(id)).length ?? this.allIds.length;\n\t\tconst unavailableCount = this.enabledIds?.filter((id) => !this.modelsById.has(id)).length ?? 0;\n\t\tconst allEnabled = this.enabledIds === null;\n\t\tconst countText = allEnabled\n\t\t\t? t(\"all enabled\")\n\t\t\t: t(\"{enabled}/{total} enabled\", { enabled: enabledCount, total: this.allIds.length }) +\n\t\t\t\t(unavailableCount ? ` · ${t(\"{count} unavailable\", { count: unavailableCount })}` : \"\");\n\t\tconst parts = [\n\t\t\t`${keyDisplayText(\"tui.select.confirm\")} ${t(\"toggle\")}`,\n\t\t\t`${keyDisplayText(\"app.models.enableAll\")} ${t(\"all\")}`,\n\t\t\t`${keyDisplayText(\"app.models.clearAll\")} ${t(\"clear\")}`,\n\t\t\t`${keyDisplayText(\"app.models.toggleProvider\")} ${t(\"provider\")}`,\n\t\t\t`${keyDisplayText(\"app.models.reorderUp\")}/${keyDisplayText(\"app.models.reorderDown\")} ${t(\"reorder\")}`,\n\t\t\t`${keyDisplayText(\"app.models.save\")} ${t(\"save\")}`,\n\t\t\tcountText,\n\t\t];\n\t\treturn this.isDirty\n\t\t\t? theme.fg(\"dim\", ` ${parts.join(\" · \")} `) + theme.fg(\"warning\", t(\"(unsaved)\"))\n\t\t\t: theme.fg(\"dim\", ` ${parts.join(\" · \")}`);\n\t}\n\n\tprivate refresh(): void {\n\t\tconst query = this.searchInput.getValue();\n\t\tconst items = this.buildItems();\n\t\tthis.filteredItems = query\n\t\t\t? fuzzyFilter(items, query, (item) =>\n\t\t\t\t\titem.model\n\t\t\t\t\t\t? getModelSearchText({ id: item.model.id, provider: item.model.provider, name: item.model.name })\n\t\t\t\t\t\t: item.fullId,\n\t\t\t\t)\n\t\t\t: items;\n\t\tthis.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredItems.length - 1));\n\t\tthis.updateList();\n\t\tthis.footerText.setText(this.getFooterText());\n\t}\n\n\tprivate notifyChange(): void {\n\t\tthis.callbacks.onChange(this.enabledIds === null ? null : [...this.enabledIds]);\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\n\t\tif (this.filteredItems.length === 0) {\n\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", ` ${t(\"No matching models\")}`), 0, 0));\n\t\t\treturn;\n\t\t}\n\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredItems.length - this.maxVisible),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + this.maxVisible, this.filteredItems.length);\n\t\tconst allEnabled = this.enabledIds === null;\n\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst item = this.filteredItems[i]!;\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tconst prefix = isSelected ? theme.fg(\"accent\", \"→ \") : \" \";\n\t\t\tconst id = item.model?.id ?? item.fullId;\n\t\t\tconst modelText = isSelected ? theme.fg(\"accent\", id) : id;\n\t\t\tconst providerBadge = theme.fg(\"muted\", item.model ? ` [${item.model.provider}]` : ` ${t(\"[unavailable]\")}`);\n\t\t\tconst status = item.model\n\t\t\t\t? allEnabled\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: item.enabled\n\t\t\t\t\t\t? theme.fg(\"success\", \" ✓\")\n\t\t\t\t\t\t: theme.fg(\"dim\", \" ✗\")\n\t\t\t\t: theme.fg(\"dim\", \" ✗\");\n\t\t\tthis.listContainer.addChild(new Text(`${prefix}${modelText}${providerBadge}${status}`, 0, 0));\n\t\t}\n\n\t\t// Add scroll indicator if needed\n\t\tif (startIndex > 0 || endIndex < this.filteredItems.length) {\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew Text(theme.fg(\"muted\", ` (${this.selectedIndex + 1}/${this.filteredItems.length})`), 0, 0),\n\t\t\t);\n\t\t}\n\n\t\tif (this.filteredItems.length > 0) {\n\t\t\tconst selected = this.filteredItems[this.selectedIndex];\n\t\t\tthis.listContainer.addChild(new Spacer(1));\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew Text(\n\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\"muted\",\n\t\t\t\t\t\t` ${selected.model ? t(\"Model Name: {name}\", { name: selected.model.name }) : t(\"Model unavailable\")}`,\n\t\t\t\t\t),\n\t\t\t\t\t0,\n\t\t\t\t\t0,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\thandleInput(data: string): void {\n\t\tconst kb = getKeybindings();\n\n\t\t// Navigation\n\t\tif (kb.matches(data, \"tui.select.up\")) {\n\t\t\tif (this.filteredItems.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === 0 ? this.filteredItems.length - 1 : this.selectedIndex - 1;\n\t\t\tthis.updateList();\n\t\t\treturn;\n\t\t}\n\t\tif (kb.matches(data, \"tui.select.down\")) {\n\t\t\tif (this.filteredItems.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === this.filteredItems.length - 1 ? 0 : this.selectedIndex + 1;\n\t\t\tthis.updateList();\n\t\t\treturn;\n\t\t}\n\n\t\t// Reorder enabled models\n\t\tconst reorderUp = kb.matches(data, \"app.models.reorderUp\");\n\t\tconst reorderDown = kb.matches(data, \"app.models.reorderDown\");\n\t\tif (reorderUp || reorderDown) {\n\t\t\tif (this.enabledIds === null) return;\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item && isEnabled(this.enabledIds, item.fullId)) {\n\t\t\t\tconst delta = reorderUp ? -1 : 1;\n\t\t\t\tconst currentIndex = this.enabledIds.indexOf(item.fullId);\n\t\t\t\tconst newIndex = currentIndex + delta;\n\t\t\t\t// Only move if within bounds\n\t\t\t\tif (newIndex >= 0 && newIndex < this.enabledIds.length) {\n\t\t\t\t\tthis.enabledIds = move(this.enabledIds, item.fullId, delta);\n\t\t\t\t\tthis.isDirty = true;\n\t\t\t\t\tthis.selectedIndex += delta;\n\t\t\t\t\tthis.refresh();\n\t\t\t\t\tthis.notifyChange();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Toggle on Enter\n\t\tif (kb.matches(data, \"tui.select.confirm\")) {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item) {\n\t\t\t\tthis.enabledIds = toggle(this.enabledIds, item.fullId);\n\t\t\t\tthis.isDirty = true;\n\t\t\t\tthis.refresh();\n\t\t\t\tthis.notifyChange();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Enable all (filtered if search active, otherwise all)\n\t\tif (kb.matches(data, \"app.models.enableAll\")) {\n\t\t\tconst targetIds = this.searchInput.getValue() ? this.filteredItems.map((i) => i.fullId) : undefined;\n\t\t\tthis.enabledIds = enableAll(this.enabledIds, this.allIds, targetIds);\n\t\t\tthis.isDirty = true;\n\t\t\tthis.refresh();\n\t\t\tthis.notifyChange();\n\t\t\treturn;\n\t\t}\n\n\t\t// Clear all (filtered if search active, otherwise all)\n\t\tif (kb.matches(data, \"app.models.clearAll\")) {\n\t\t\tconst targetIds = this.searchInput.getValue() ? this.filteredItems.map((i) => i.fullId) : undefined;\n\t\t\tthis.enabledIds = clearAll(this.enabledIds, this.allIds, targetIds);\n\t\t\tthis.isDirty = true;\n\t\t\tthis.refresh();\n\t\t\tthis.notifyChange();\n\t\t\treturn;\n\t\t}\n\n\t\t// Toggle provider of current item\n\t\tif (kb.matches(data, \"app.models.toggleProvider\")) {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item?.model) {\n\t\t\t\tconst provider = item.model.provider;\n\t\t\t\tconst providerIds = this.allIds.filter((id) => this.modelsById.get(id)!.provider === provider);\n\t\t\t\tconst allEnabled = providerIds.every((id) => isEnabled(this.enabledIds, id));\n\t\t\t\tthis.enabledIds = allEnabled\n\t\t\t\t\t? clearAll(this.enabledIds, this.allIds, providerIds)\n\t\t\t\t\t: enableAll(this.enabledIds, this.allIds, providerIds);\n\t\t\t\tthis.isDirty = true;\n\t\t\t\tthis.refresh();\n\t\t\t\tthis.notifyChange();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Save/persist to settings\n\t\tif (kb.matches(data, \"app.models.save\")) {\n\t\t\tthis.callbacks.onPersist(this.enabledIds === null ? null : [...this.enabledIds]);\n\t\t\tthis.isDirty = false;\n\t\t\tthis.footerText.setText(this.getFooterText());\n\t\t\treturn;\n\t\t}\n\n\t\t// Ctrl+C - clear search or cancel if empty\n\t\tif (kb.matches(data, \"app.models.cancel\")) {\n\t\t\tif (this.searchInput.getValue()) {\n\t\t\t\tthis.searchInput.setValue(\"\");\n\t\t\t\tthis.refresh();\n\t\t\t} else {\n\t\t\t\tthis.callbacks.onCancel();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Escape - cancel (via the shared select-cancel binding; ctrl+c is consumed by app.models.cancel above)\n\t\tif (kb.matches(data, \"tui.select.cancel\")) {\n\t\t\tthis.callbacks.onCancel();\n\t\t\treturn;\n\t\t}\n\n\t\t// Pass everything else to search input\n\t\tthis.searchInput.handleInput(data);\n\t\tthis.refresh();\n\t}\n\n\tgetSearchInput(): Input {\n\t\treturn this.searchInput;\n\t}\n}\n"]}
1
+ {"version":3,"file":"scoped-models-selector.js","sourceRoot":"","sources":["../../../../src/modes/interactive/components/scoped-models-selector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAkB,WAAW,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC/G,OAAO,EAAE,CAAC,EAAE,MAAM,6BAA6B,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAKvD,SAAS,SAAS,CAAC,UAAsB,EAAE,EAAU,EAAW;IAC/D,OAAO,UAAU,KAAK,IAAI,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAAA,CACtD;AAED,SAAS,MAAM,CAAC,UAAsB,EAAE,EAAU,EAAc;IAC/D,IAAI,UAAU,KAAK,IAAI;QAAE,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,yCAAyC;IAC/E,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACrC,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;IACvF,OAAO,CAAC,GAAG,UAAU,EAAE,EAAE,CAAC,CAAC;AAAA,CAC3B;AAED,SAAS,SAAS,CAAC,UAAsB,EAAE,MAAgB,EAAE,SAAoB,EAAc;IAC9F,IAAI,UAAU,KAAK,IAAI;QAAE,OAA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AC3B,CAAC;YACD,OAAO;QACR,CAAC;QAED,wGAAwG;QACxG,IAAI,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,mBAAmB,CAAC,EAAE,CAAC;YAC3C,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC;YAC1B,OAAO;QACR,CAAC;QAED,uCAAuC;QACvC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,CAAC,OAAO,EAAE,CAAC;IAAA,CACf;IAED,cAAc,GAAU;QACvB,OAAO,IAAI,CAAC,WAAW,CAAC;IAAA,CACxB;CACD","sourcesContent":["import type { Api, Model } from \"@agent-forge/ai\";\nimport { Container, type Focusable, fuzzyFilter, getKeybindings, Input, Spacer, Text } from \"@agent-forge/tui\";\nimport { t } from \"../../../core/i18n/index.ts\";\nimport { theme } from \"../../../theme/theme.ts\";\nimport { getModelSearchText } from \"../model-search.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyDisplayText } from \"./keybinding-hints.ts\";\n\n// EnabledIds: null = all enabled (no filter), string[] = explicit ordered list\ntype EnabledIds = string[] | null;\n\nfunction isEnabled(enabledIds: EnabledIds, id: string): boolean {\n\treturn enabledIds === null || enabledIds.includes(id);\n}\n\nfunction toggle(enabledIds: EnabledIds, id: string): EnabledIds {\n\tif (enabledIds === null) return [id]; // First toggle: start with only this one\n\tconst index = enabledIds.indexOf(id);\n\tif (index >= 0) return [...enabledIds.slice(0, index), ...enabledIds.slice(index + 1)];\n\treturn [...enabledIds, id];\n}\n\nfunction enableAll(enabledIds: EnabledIds, allIds: string[], targetIds?: string[]): EnabledIds {\n\tif (enabledIds === null) return null; // Already all enabled\n\tconst targets = targetIds ?? allIds;\n\tconst result = [...enabledIds];\n\tfor (const id of targets) {\n\t\tif (!result.includes(id)) result.push(id);\n\t}\n\treturn result.length === allIds.length && result.every((id) => allIds.includes(id)) ? null : result;\n}\n\nfunction clearAll(enabledIds: EnabledIds, allIds: string[], targetIds?: string[]): EnabledIds {\n\tif (enabledIds === null) {\n\t\treturn targetIds ? allIds.filter((id) => !targetIds.includes(id)) : [];\n\t}\n\tconst targets = new Set(targetIds ?? enabledIds);\n\treturn enabledIds.filter((id) => !targets.has(id));\n}\n\nfunction move(enabledIds: EnabledIds, id: string, delta: number): EnabledIds {\n\tif (enabledIds === null) return null;\n\tconst list = [...enabledIds];\n\tconst index = list.indexOf(id);\n\tif (index < 0) return list;\n\tconst newIndex = index + delta;\n\tif (newIndex < 0 || newIndex >= list.length) return list;\n\tconst result = [...list];\n\t[result[index], result[newIndex]] = [result[newIndex], result[index]];\n\treturn result;\n}\n\nfunction getSortedIds(enabledIds: EnabledIds, allIds: string[]): string[] {\n\tif (enabledIds === null) return allIds;\n\tconst enabledSet = new Set(enabledIds);\n\treturn [...enabledIds, ...allIds.filter((id) => !enabledSet.has(id))];\n}\n\ninterface ModelItem {\n\tfullId: string;\n\tmodel: Model<Api> | undefined;\n\tenabled: boolean;\n}\n\nexport interface ModelsConfig {\n\tallModels: Model<Api>[];\n\tenabledModelIds: string[] | null;\n\trefreshStatus?: string;\n}\n\nexport interface ModelsCallbacks {\n\t/** Called whenever the enabled model set or order changes (session-only, no persist) */\n\tonChange: (enabledModelIds: string[] | null) => void | Promise<void>;\n\t/** Called when user wants to persist current selection to settings */\n\tonPersist: (enabledModelIds: string[] | null) => void | Promise<void>;\n\tonCancel: () => void;\n}\n\n/**\n * Component for enabling/disabling models in the /model cycling scope.\n * Changes are session-only until explicitly persisted with Ctrl+S.\n */\nexport class ScopedModelsSelectorComponent extends Container implements Focusable {\n\tprivate modelsById: Map<string, Model<Api>> = new Map();\n\tprivate allIds: string[] = [];\n\tprivate enabledIds: EnabledIds = null;\n\tprivate filteredItems: ModelItem[] = [];\n\tprivate selectedIndex = 0;\n\tprivate searchInput: Input;\n\n\t// Focusable implementation - propagate to searchInput for IME cursor positioning\n\tprivate _focused = false;\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\tprivate listContainer: Container;\n\tprivate footerText: Text;\n\tprivate callbacks: ModelsCallbacks;\n\tprivate maxVisible = 8;\n\tprivate isDirty = false;\n\tprivate refreshStatusText?: Text;\n\n\tconstructor(config: ModelsConfig, callbacks: ModelsCallbacks) {\n\t\tsuper();\n\t\tthis.callbacks = callbacks;\n\n\t\tfor (const model of config.allModels) {\n\t\t\tconst fullId = `${model.provider}/${model.id}`;\n\t\t\tthis.modelsById.set(fullId, model);\n\t\t\tthis.allIds.push(fullId);\n\t\t}\n\n\t\tthis.enabledIds = config.enabledModelIds === null ? null : [...config.enabledModelIds];\n\t\tthis.filteredItems = this.buildItems();\n\n\t\t// Header\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.fg(\"accent\", theme.bold(t(\"Model Configuration\"))), 0, 0));\n\t\tthis.addChild(\n\t\t\tnew Text(\n\t\t\t\ttheme.fg(\n\t\t\t\t\t\"muted\",\n\t\t\t\t\tt(\"Session-only. {key} to save to settings.\", { key: keyDisplayText(\"app.models.save\") }),\n\t\t\t\t),\n\t\t\t\t0,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Search input\n\t\tthis.searchInput = new Input();\n\t\tthis.addChild(this.searchInput);\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// List container\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\n\t\t// Footer hint\n\t\tthis.addChild(new Spacer(1));\n\t\tif (config.refreshStatus) {\n\t\t\tthis.refreshStatusText = new Text(theme.fg(\"muted\", ` ${config.refreshStatus}`), 0, 0);\n\t\t\tthis.addChild(this.refreshStatusText);\n\t\t}\n\t\tthis.footerText = new Text(this.getFooterText(), 0, 0);\n\t\tthis.addChild(this.footerText);\n\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.updateList();\n\t}\n\n\tupdateModels(models: readonly Model<Api>[], enabledModelIds?: string[] | null): void {\n\t\tconst selectedId = this.filteredItems[this.selectedIndex]?.fullId;\n\t\tif (enabledModelIds !== undefined) this.enabledIds = enabledModelIds === null ? null : [...enabledModelIds];\n\t\tthis.modelsById.clear();\n\t\tthis.allIds = [];\n\t\tfor (const model of models) {\n\t\t\tconst fullId = `${model.provider}/${model.id}`;\n\t\t\tthis.modelsById.set(fullId, model);\n\t\t\tthis.allIds.push(fullId);\n\t\t}\n\t\tthis.refresh();\n\t\tconst refreshedIndex = selectedId ? this.filteredItems.findIndex((item) => item.fullId === selectedId) : -1;\n\t\tif (refreshedIndex >= 0) {\n\t\t\tthis.selectedIndex = refreshedIndex;\n\t\t\tthis.updateList();\n\t\t}\n\t}\n\n\tsetRefreshStatus(message: string, kind: \"muted\" | \"success\" | \"warning\"): void {\n\t\tthis.refreshStatusText?.setText(theme.fg(kind, ` ${message}`));\n\t}\n\n\tprivate buildItems(): ModelItem[] {\n\t\treturn getSortedIds(this.enabledIds, this.allIds).map((id) => ({\n\t\t\tfullId: id,\n\t\t\tmodel: this.modelsById.get(id),\n\t\t\tenabled: isEnabled(this.enabledIds, id),\n\t\t}));\n\t}\n\n\tprivate getFooterText(): string {\n\t\tconst enabledCount = this.enabledIds?.filter((id) => this.modelsById.has(id)).length ?? this.allIds.length;\n\t\tconst unavailableCount = this.enabledIds?.filter((id) => !this.modelsById.has(id)).length ?? 0;\n\t\tconst allEnabled = this.enabledIds === null;\n\t\tconst countText = allEnabled\n\t\t\t? t(\"all enabled\")\n\t\t\t: t(\"{enabled}/{total} enabled\", { enabled: enabledCount, total: this.allIds.length }) +\n\t\t\t\t(unavailableCount ? ` · ${t(\"{count} unavailable\", { count: unavailableCount })}` : \"\");\n\t\tconst parts = [\n\t\t\t`${keyDisplayText(\"tui.select.confirm\")} ${t(\"toggle\")}`,\n\t\t\t`${keyDisplayText(\"app.models.enableAll\")} ${t(\"all\")}`,\n\t\t\t`${keyDisplayText(\"app.models.clearAll\")} ${t(\"clear\")}`,\n\t\t\t`${keyDisplayText(\"app.models.toggleProvider\")} ${t(\"provider\")}`,\n\t\t\t`${keyDisplayText(\"app.models.reorderUp\")}/${keyDisplayText(\"app.models.reorderDown\")} ${t(\"reorder\")}`,\n\t\t\t`${keyDisplayText(\"app.models.save\")} ${t(\"save\")}`,\n\t\t\tcountText,\n\t\t];\n\t\treturn this.isDirty\n\t\t\t? theme.fg(\"dim\", ` ${parts.join(\" · \")} `) + theme.fg(\"warning\", t(\"(unsaved)\"))\n\t\t\t: theme.fg(\"dim\", ` ${parts.join(\" · \")}`);\n\t}\n\n\tprivate refresh(): void {\n\t\tconst query = this.searchInput.getValue();\n\t\tconst items = this.buildItems();\n\t\tthis.filteredItems = query\n\t\t\t? fuzzyFilter(items, query, (item) =>\n\t\t\t\t\titem.model\n\t\t\t\t\t\t? getModelSearchText({ id: item.model.id, provider: item.model.provider, name: item.model.name })\n\t\t\t\t\t\t: item.fullId,\n\t\t\t\t)\n\t\t\t: items;\n\t\tthis.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredItems.length - 1));\n\t\tthis.updateList();\n\t\tthis.footerText.setText(this.getFooterText());\n\t}\n\n\tprivate notifyChange(): void {\n\t\tthis.callbacks.onChange(this.enabledIds === null ? null : [...this.enabledIds]);\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\n\t\tif (this.filteredItems.length === 0) {\n\t\t\tthis.listContainer.addChild(new Text(theme.fg(\"muted\", ` ${t(\"No matching models\")}`), 0, 0));\n\t\t\treturn;\n\t\t}\n\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredItems.length - this.maxVisible),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + this.maxVisible, this.filteredItems.length);\n\t\tconst allEnabled = this.enabledIds === null;\n\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst item = this.filteredItems[i]!;\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tconst prefix = isSelected ? theme.fg(\"accent\", \"→ \") : \" \";\n\t\t\tconst id = item.model?.id ?? item.fullId;\n\t\t\tconst modelText = isSelected ? theme.fg(\"accent\", id) : id;\n\t\t\tconst providerBadge = theme.fg(\"muted\", item.model ? ` [${item.model.provider}]` : ` ${t(\"[unavailable]\")}`);\n\t\t\tconst status = item.model\n\t\t\t\t? allEnabled\n\t\t\t\t\t? \"\"\n\t\t\t\t\t: item.enabled\n\t\t\t\t\t\t? theme.fg(\"success\", \" ✓\")\n\t\t\t\t\t\t: theme.fg(\"dim\", \" ✗\")\n\t\t\t\t: theme.fg(\"dim\", \" ✗\");\n\t\t\tthis.listContainer.addChild(new Text(`${prefix}${modelText}${providerBadge}${status}`, 0, 0));\n\t\t}\n\n\t\t// Add scroll indicator if needed\n\t\tif (startIndex > 0 || endIndex < this.filteredItems.length) {\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew Text(theme.fg(\"muted\", ` (${this.selectedIndex + 1}/${this.filteredItems.length})`), 0, 0),\n\t\t\t);\n\t\t}\n\n\t\tif (this.filteredItems.length > 0) {\n\t\t\tconst selected = this.filteredItems[this.selectedIndex];\n\t\t\tthis.listContainer.addChild(new Spacer(1));\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew Text(\n\t\t\t\t\ttheme.fg(\n\t\t\t\t\t\t\"muted\",\n\t\t\t\t\t\t` ${selected.model ? t(\"Model Name: {name}\", { name: selected.model.name }) : t(\"Model unavailable\")}`,\n\t\t\t\t\t),\n\t\t\t\t\t0,\n\t\t\t\t\t0,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\thandleInput(data: string): void {\n\t\tconst kb = getKeybindings();\n\n\t\t// Navigation\n\t\tif (kb.matches(data, \"tui.select.up\")) {\n\t\t\tif (this.filteredItems.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === 0 ? this.filteredItems.length - 1 : this.selectedIndex - 1;\n\t\t\tthis.updateList();\n\t\t\treturn;\n\t\t}\n\t\tif (kb.matches(data, \"tui.select.down\")) {\n\t\t\tif (this.filteredItems.length === 0) return;\n\t\t\tthis.selectedIndex = this.selectedIndex === this.filteredItems.length - 1 ? 0 : this.selectedIndex + 1;\n\t\t\tthis.updateList();\n\t\t\treturn;\n\t\t}\n\n\t\t// Reorder enabled models\n\t\tconst reorderUp = kb.matches(data, \"app.models.reorderUp\");\n\t\tconst reorderDown = kb.matches(data, \"app.models.reorderDown\");\n\t\tif (reorderUp || reorderDown) {\n\t\t\tif (this.enabledIds === null) return;\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item && isEnabled(this.enabledIds, item.fullId)) {\n\t\t\t\tconst delta = reorderUp ? -1 : 1;\n\t\t\t\tconst currentIndex = this.enabledIds.indexOf(item.fullId);\n\t\t\t\tconst newIndex = currentIndex + delta;\n\t\t\t\t// Only move if within bounds\n\t\t\t\tif (newIndex >= 0 && newIndex < this.enabledIds.length) {\n\t\t\t\t\tthis.enabledIds = move(this.enabledIds, item.fullId, delta);\n\t\t\t\t\tthis.isDirty = true;\n\t\t\t\t\tthis.selectedIndex += delta;\n\t\t\t\t\tthis.refresh();\n\t\t\t\t\tthis.notifyChange();\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Toggle on Enter\n\t\tif (kb.matches(data, \"tui.select.confirm\")) {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item) {\n\t\t\t\tthis.enabledIds = toggle(this.enabledIds, item.fullId);\n\t\t\t\tthis.isDirty = true;\n\t\t\t\tthis.refresh();\n\t\t\t\tthis.notifyChange();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Enable all (filtered if search active, otherwise all)\n\t\tif (kb.matches(data, \"app.models.enableAll\")) {\n\t\t\tconst targetIds = this.searchInput.getValue() ? this.filteredItems.map((i) => i.fullId) : undefined;\n\t\t\tthis.enabledIds = enableAll(this.enabledIds, this.allIds, targetIds);\n\t\t\tthis.isDirty = true;\n\t\t\tthis.refresh();\n\t\t\tthis.notifyChange();\n\t\t\treturn;\n\t\t}\n\n\t\t// Clear all (filtered if search active, otherwise all)\n\t\tif (kb.matches(data, \"app.models.clearAll\")) {\n\t\t\tconst targetIds = this.searchInput.getValue() ? this.filteredItems.map((i) => i.fullId) : undefined;\n\t\t\tthis.enabledIds = clearAll(this.enabledIds, this.allIds, targetIds);\n\t\t\tthis.isDirty = true;\n\t\t\tthis.refresh();\n\t\t\tthis.notifyChange();\n\t\t\treturn;\n\t\t}\n\n\t\t// Toggle provider of current item\n\t\tif (kb.matches(data, \"app.models.toggleProvider\")) {\n\t\t\tconst item = this.filteredItems[this.selectedIndex];\n\t\t\tif (item?.model) {\n\t\t\t\tconst provider = item.model.provider;\n\t\t\t\tconst providerIds = this.allIds.filter((id) => this.modelsById.get(id)!.provider === provider);\n\t\t\t\tconst allEnabled = providerIds.every((id) => isEnabled(this.enabledIds, id));\n\t\t\t\tthis.enabledIds = allEnabled\n\t\t\t\t\t? clearAll(this.enabledIds, this.allIds, providerIds)\n\t\t\t\t\t: enableAll(this.enabledIds, this.allIds, providerIds);\n\t\t\t\tthis.isDirty = true;\n\t\t\t\tthis.refresh();\n\t\t\t\tthis.notifyChange();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Save/persist to settings\n\t\tif (kb.matches(data, \"app.models.save\")) {\n\t\t\tthis.callbacks.onPersist(this.enabledIds === null ? null : [...this.enabledIds]);\n\t\t\tthis.isDirty = false;\n\t\t\tthis.footerText.setText(this.getFooterText());\n\t\t\treturn;\n\t\t}\n\n\t\t// Ctrl+C - clear search or cancel if empty\n\t\tif (kb.matches(data, \"app.models.cancel\")) {\n\t\t\tif (this.searchInput.getValue()) {\n\t\t\t\tthis.searchInput.setValue(\"\");\n\t\t\t\tthis.refresh();\n\t\t\t} else {\n\t\t\t\tthis.callbacks.onCancel();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Escape - cancel (via the shared select-cancel binding; ctrl+c is consumed by app.models.cancel above)\n\t\tif (kb.matches(data, \"tui.select.cancel\")) {\n\t\t\tthis.callbacks.onCancel();\n\t\t\treturn;\n\t\t}\n\n\t\t// Pass everything else to search input\n\t\tthis.searchInput.handleInput(data);\n\t\tthis.refresh();\n\t}\n\n\tgetSearchInput(): Input {\n\t\treturn this.searchInput;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"session-selector.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/session-selector.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,KAAK,SAAS,EACd,SAAS,EACT,KAAK,SAAS,EAOd,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAMzF,OAAO,EAAyC,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAIrH,kGAA6F;AAC7F,KAAK,WAAW,GAAG,SAAS,GAAG,KAAK,CAAC;AAErC,qFAAqF;AACrF,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK,MAAM,GAAG,SAAS,CAAC;AAEhF,MAAM,WAAW,yBAAyB;IACzC,sFAAsF;IACtF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,4FAA4F;IAC5F,iBAAiB,EAAE,oBAAoB,CAAC;CACxC;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAgClF;AA+RD;;GAEG;AACH,cAAM,WAAY,YAAW,SAAS,EAAE,SAAS;IACzC,sBAAsB,IAAI,MAAM,GAAG,SAAS,CAGlD;IACD,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,gBAA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AAwF;QACxF,WAAW,CAAC,EAAE,yBAAyB,CAAC;KACxC,EACD,sBAAsB,CAAC,EAAE,MAAM,EAyH/B;IAED,OAAO,CAAC,WAAW;IAanB,OAAO,CAAC,eAAe;IA6BvB,OAAO,CAAC,cAAc;YASR,aAAa;YAiCb,SAAS;IAyEvB,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,UAAU;IAOlB;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;YAQX,4BAA4B;IAO1C,OAAO,CAAC,WAAW;IAWnB,cAAc,IAAI,WAAW,CAE5B;CACD","sourcesContent":["import { spawnSync } from \"node:child_process\";\nimport { closeSync, existsSync, openSync, readSync } from \"node:fs\";\nimport { unlink } from \"node:fs/promises\";\nimport * as os from \"node:os\";\nimport { StringDecoder } from \"node:string_decoder\";\nimport {\n\ttype Component,\n\tContainer,\n\ttype Focusable,\n\tgetKeybindings,\n\tInput,\n\tSpacer,\n\tText,\n\ttruncateToWidth,\n\tvisibleWidth,\n} from \"@agent-forge/tui\";\nimport { t } from \"../../../core/i18n/index.ts\";\nimport { KeybindingsManager } from \"../../../core/keybindings.ts\";\nimport { removeSessionFromIndex } from \"../../../core/session-index.ts\";\nimport type { SessionInfo, SessionListProgress } from \"../../../core/session-manager.ts\";\nimport { SUITE_SESSION_ENTRY_TYPE } from \"../../../profiles/suite-loader.ts\";\nimport { canonicalizePath as _canonicalizePath } from \"../../../utils/paths.ts\";\nimport { theme } from \"../theme/theme.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyHint, keyText } from \"./keybinding-hints.ts\";\nimport { filterAndSortSessions, hasSessionName, type NameFilter, type SortMode } from \"./session-selector-search.ts\";\n\ntype SessionScope = \"current\" | \"all\";\n\n/** Suite dimension of the session list (设计 §10.1): bound to the current suite by default. */\ntype SuiteFilter = \"current\" | \"all\";\n\n/** Suite id extracted from a session file; undefined = unbound (legacy sessions). */\nexport type SessionSuiteIdReader = (session: SessionInfo) => string | undefined;\n\nexport interface SessionSuiteFilterOptions {\n\t/** Suite id of the session that opened the selector; undefined = unbound (legacy). */\n\tcurrentSuiteId?: string;\n\t/** Reads the bound suite id for a listed session. Undefined results are cached per path. */\n\tgetSessionSuiteId: SessionSuiteIdReader;\n}\n\n/**\n * Scan the head of a session JSONL file for the suite binding entry (设计\n * §10.1: recorded as a custom entry when the session is created; resumed\n * sessions keep their original binding). Returns undefined when the session is\n * unbound, the file is unreadable, or no binding entry is found in the scanned\n * head.\n */\nexport function readSessionSuiteIdFromFile(sessionPath: string): string | undefined {\n\tconst scanLimitBytes = 64 * 1024;\n\tlet fd: number;\n\ttry {\n\t\tfd = openSync(sessionPath, \"r\");\n\t} catch {\n\t\treturn undefined;\n\t}\n\ttry {\n\t\tconst decoder = new StringDecoder(\"utf8\");\n\t\tconst buffer = Buffer.allocUnsafe(4096);\n\t\tlet scannedBytes = 0;\n\t\tlet leftover = \"\";\n\t\twhile (scannedBytes < scanLimitBytes) {\n\t\t\tconst readLength = Math.min(buffer.length, scanLimitBytes - scannedBytes);\n\t\t\tconst bytesRead = readSync(fd, buffer, 0, readLength, null);\n\t\t\tif (bytesRead === 0) break;\n\t\t\tscannedBytes += bytesRead;\n\t\t\tconst lines = (leftover + decoder.write(buffer.subarray(0, bytesRead))).split(\"\\n\");\n\t\t\tleftover = lines.pop() ?? \"\";\n\t\t\tfor (const line of lines) {\n\t\t\t\tconst suiteId = parseSuiteBindingLine(line);\n\t\t\t\tif (suiteId !== undefined) return suiteId;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t} catch {\n\t\t// One unreadable file must not break the selector; treat it as unbound.\n\t\treturn undefined;\n\t} finally {\n\t\tcloseSync(fd);\n\t}\n}\n\nfunction parseSuiteBindingLine(line: string): string | undefined {\n\tconst trimmed = line.trim();\n\tif (trimmed.length === 0) return undefined;\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(trimmed);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n\tconst record = value as Record<string, unknown>;\n\tif (record.type !== \"custom\" || record.customType !== SUITE_SESSION_ENTRY_TYPE) return undefined;\n\tconst suiteId = (record.data as { suiteId?: unknown } | undefined)?.suiteId;\n\treturn typeof suiteId === \"string\" && suiteId.trim().length > 0 ? suiteId : undefined;\n}\n\nfunction shortenPath(path: string): string {\n\tconst home = os.homedir();\n\t// v8 ignore next -- shortenPath is only called with non-empty paths\n\tif (!path) return path;\n\tif (path.startsWith(home)) {\n\t\treturn `~${path.slice(home.length)}`;\n\t}\n\treturn path;\n}\n\nfunction formatSessionDate(date: Date): string {\n\tconst now = new Date();\n\tconst diffMs = now.getTime() - date.getTime();\n\tconst diffMins = Math.floor(diffMs / 60000);\n\tconst diffHours = Math.floor(diffMs / 3600000);\n\tconst diffDays = Math.floor(diffMs / 86400000);\n\n\tif (diffMins < 1) return \"now\";\n\tif (diffMins < 60) return `${diffMins}m`;\n\tif (diffHours < 24) return `${diffHours}h`;\n\tif (diffDays < 7) return `${diffDays}d`;\n\tif (diffDays < 30) return `${Math.floor(diffDays / 7)}w`;\n\tif (diffDays < 365) return `${Math.floor(diffDays / 30)}mo`;\n\treturn `${Math.floor(diffDays / 365)}y`;\n}\n\nfunction canonicalizePath(path: string | undefined): string | undefined {\n\tif (!path) return path;\n\treturn _canonicalizePath(path);\n}\n\nclass SessionSelectorHeader implements Component {\n\tprivate scope: SessionScope;\n\tprivate sortMode: SortMode;\n\tprivate nameFilter: NameFilter;\n\tprivate requestRender: () => void;\n\tprivate loading = false;\n\tprivate loadProgress: { loaded: number; total: number } | null = null;\n\tprivate showPath = false;\n\tprivate confirmingDeletePath: string | null = null;\n\tprivate statusMessage: { type: \"info\" | \"error\"; message: string } | null = null;\n\tprivate statusTimeout: ReturnType<typeof setTimeout> | null = null;\n\tprivate showRenameHint = false;\n\tprivate suiteTitle: string | undefined = undefined;\n\n\tconstructor(scope: SessionScope, sortMode: SortMode, nameFilter: NameFilter, requestRender: () => void) {\n\t\tthis.scope = scope;\n\t\tthis.sortMode = sortMode;\n\t\tthis.nameFilter = nameFilter;\n\t\tthis.requestRender = requestRender;\n\t}\n\n\t/**\n\t * Override the title with the suite dimension of the list (设计 §10.1).\n\t * Undefined restores the folder-scope-only title.\n\t */\n\tsetSuiteTitle(title: string | undefined): void {\n\t\tthis.suiteTitle = title;\n\t}\n\n\tsetScope(scope: SessionScope): void {\n\t\tthis.scope = scope;\n\t}\n\n\tsetSortMode(sortMode: SortMode): void {\n\t\tthis.sortMode = sortMode;\n\t}\n\n\tsetNameFilter(nameFilter: NameFilter): void {\n\t\tthis.nameFilter = nameFilter;\n\t}\n\n\tsetLoading(loading: boolean): void {\n\t\tthis.loading = loading;\n\t\t// Progress is scoped to the current load; clear whenever the loading state is set\n\t\tthis.loadProgress = null;\n\t}\n\n\tsetProgress(loaded: number, total: number): void {\n\t\tthis.loadProgress = { loaded, total };\n\t}\n\n\tsetShowPath(showPath: boolean): void {\n\t\tthis.showPath = showPath;\n\t}\n\n\tsetShowRenameHint(show: boolean): void {\n\t\tthis.showRenameHint = show;\n\t}\n\n\tsetConfirmingDeletePath(path: string | null): void {\n\t\tthis.confirmingDeletePath = path;\n\t}\n\n\tprivate clearStatusTimeout(): void {\n\t\tif (!this.statusTimeout) return;\n\t\tclearTimeout(this.statusTimeout);\n\t\tthis.statusTimeout = null;\n\t}\n\n\tsetStatusMessage(msg: { type: \"info\" | \"error\"; message: string } | null, autoHideMs?: number): void {\n\t\tthis.clearStatusTimeout();\n\t\tthis.statusMessage = msg;\n\t\tif (!msg || !autoHideMs) return;\n\n\t\tthis.statusTimeout = setTimeout(() => {\n\t\t\tthis.statusMessage = null;\n\t\t\tthis.statusTimeout = null;\n\t\t\tthis.requestRender();\n\t\t}, autoHideMs);\n\t}\n\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tconst title =\n\t\t\tthis.suiteTitle ??\n\t\t\t(this.scope === \"current\" ? t(\"Resume Session (Current Folder)\") : t(\"Resume Session (All)\"));\n\t\tconst leftText = theme.bold(title);\n\n\t\tconst sortLabel =\n\t\t\tthis.sortMode === \"threaded\" ? t(\"Threaded\") : this.sortMode === \"recent\" ? t(\"Recent\") : t(\"Fuzzy\");\n\t\tconst sortText = theme.fg(\"muted\", `${t(\"Sort:\")} `) + theme.fg(\"accent\", sortLabel);\n\n\t\tconst nameLabel = this.nameFilter === \"all\" ? t(\"All\") : t(\"Named\");\n\t\tconst nameText = theme.fg(\"muted\", `${t(\"Name:\")} `) + theme.fg(\"accent\", nameLabel);\n\n\t\tlet scopeText: string;\n\t\tif (this.loading) {\n\t\t\tconst progressText = this.loadProgress ? `${this.loadProgress.loaded}/${this.loadProgress.total}` : \"...\";\n\t\t\tscopeText = `${theme.fg(\"muted\", `${t(\"○ Current Folder\")} | `)}${theme.fg(\"accent\", t(\"Loading {progress}\", { progress: progressText }))}`;\n\t\t} else if (this.scope === \"current\") {\n\t\t\tscopeText = `${theme.fg(\"accent\", t(\"◉ Current Folder\"))}${theme.fg(\"muted\", ` | ${t(\"○ All\")}`)}`;\n\t\t} else {\n\t\t\tscopeText = `${theme.fg(\"muted\", `${t(\"○ Current Folder\")} | `)}${theme.fg(\"accent\", t(\"◉ All\"))}`;\n\t\t}\n\n\t\tconst rightText = truncateToWidth(`${scopeText} ${nameText} ${sortText}`, width, \"\");\n\t\tconst availableLeft = Math.max(0, width - visibleWidth(rightText) - 1);\n\t\tconst left = truncateToWidth(leftText, availableLeft, \"\");\n\t\tconst spacing = Math.max(0, width - visibleWidth(left) - visibleWidth(rightText));\n\n\t\t// Build hint lines - changes based on state (all branches truncate to width)\n\t\tlet hintLine1: string;\n\t\tlet hintLine2: string;\n\t\tif (this.confirmingDeletePath !== null) {\n\t\t\tconst confirmHint = t(\"Delete session? {confirm} · {cancel}\", {\n\t\t\t\tconfirm: keyHint(\"tui.select.confirm\", t(\"confirm\")),\n\t\t\t\tcancel: keyHint(\"tui.select.cancel\", t(\"cancel\")),\n\t\t\t});\n\t\t\thintLine1 = theme.fg(\"error\", truncateToWidth(confirmHint, width, \"…\"));\n\t\t\thintLine2 = \"\";\n\t\t} else if (this.statusMessage) {\n\t\t\tconst color = this.statusMessage.type === \"error\" ? \"error\" : \"accent\";\n\t\t\thintLine1 = theme.fg(color, truncateToWidth(this.statusMessage.message, width, \"…\"));\n\t\t\thintLine2 = \"\";\n\t\t} else {\n\t\t\tconst pathState = this.showPath ? t(\"path (on)\") : t(\"path (off)\");\n\t\t\tconst sep = theme.fg(\"muted\", \" · \");\n\t\t\tconst hint1 =\n\t\t\t\tkeyHint(\"tui.input.tab\", t(\"scope\")) + sep + theme.fg(\"muted\", t('re:<pattern> regex · \"phrase\" exact'));\n\t\t\tconst hint2Parts = [\n\t\t\t\tkeyHint(\"app.session.toggleSort\", t(\"sort\")),\n\t\t\t\tkeyHint(\"app.session.toggleNamedFilter\", t(\"named\")),\n\t\t\t\tkeyHint(\"app.session.delete\", t(\"delete\")),\n\t\t\t\tkeyHint(\"app.session.togglePath\", pathState),\n\t\t\t];\n\t\t\tif (this.showRenameHint) {\n\t\t\t\thint2Parts.push(keyHint(\"app.session.rename\", t(\"rename\")));\n\t\t\t}\n\t\t\tconst hint2 = hint2Parts.join(sep);\n\t\t\thintLine1 = truncateToWidth(hint1, width, \"…\");\n\t\t\thintLine2 = truncateToWidth(hint2, width, \"…\");\n\t\t}\n\n\t\treturn [`${left}${\" \".repeat(spacing)}${rightText}`, hintLine1, hintLine2];\n\t}\n}\n\n/** A session tree node for hierarchical display */\ninterface SessionTreeNode {\n\tsession: SessionInfo;\n\tchildren: SessionTreeNode[];\n\tlatestActivity: number;\n}\n\n/**\n * A row of the flattened session list: either a session tree node or the\n * explicit \"show all / show current suite\" toggle action (设计 §10.1).\n */\ntype FlatSessionNode =\n\t| { kind: \"session\"; session: SessionInfo; depth: number; isLast: boolean; ancestorContinues: boolean[] }\n\t| { kind: \"suite-toggle\"; target: SuiteFilter };\n\n/**\n * Build a tree structure from sessions based on parentSessionPath.\n * Returns root nodes sorted by modified date (descending).\n */\nfunction buildSessionTree(sessions: SessionInfo[]): SessionTreeNode[] {\n\tconst byPath = new Map<string, SessionTreeNode>();\n\n\tfor (const session of sessions) {\n\t\tconst sessionPath = canonicalizePath(session.path) ?? session.path;\n\t\tbyPath.set(sessionPath, { session, children: [], latestActivity: session.modified.getTime() });\n\t}\n\n\tconst roots: SessionTreeNode[] = [];\n\n\tfor (const session of sessions) {\n\t\tconst sessionPath = canonicalizePath(session.path) ?? session.path;\n\t\tconst node = byPath.get(sessionPath)!;\n\t\tconst parentPath = canonicalizePath(session.parentSessionPath);\n\n\t\tif (parentPath && byPath.has(parentPath)) {\n\t\t\tbyPath.get(parentPath)!.children.push(node);\n\t\t} else {\n\t\t\troots.push(node);\n\t\t}\n\t}\n\n\tconst updateLatestActivity = (node: SessionTreeNode): number => {\n\t\tlet latestActivity = node.session.modified.getTime();\n\t\tfor (const child of node.children) {\n\t\t\tlatestActivity = Math.max(latestActivity, updateLatestActivity(child));\n\t\t}\n\t\tnode.latestActivity = latestActivity;\n\t\treturn latestActivity;\n\t};\n\n\tfor (const root of roots) {\n\t\tupdateLatestActivity(root);\n\t}\n\n\t// Sort children and roots by latest activity in each subtree (descending)\n\tconst sortNodes = (nodes: SessionTreeNode[]): void => {\n\t\tnodes.sort((a, b) => b.latestActivity - a.latestActivity);\n\t\tfor (const node of nodes) {\n\t\t\tsortNodes(node.children);\n\t\t}\n\t};\n\tsortNodes(roots);\n\n\treturn roots;\n}\n\n/**\n * Flatten tree into display list with tree structure metadata.\n */\nfunction flattenSessionTree(roots: SessionTreeNode[]): FlatSessionNode[] {\n\tconst result: FlatSessionNode[] = [];\n\n\tconst walk = (node: SessionTreeNode, depth: number, ancestorContinues: boolean[], isLast: boolean): void => {\n\t\tresult.push({ kind: \"session\", session: node.session, depth, isLast, ancestorContinues });\n\n\t\tfor (let i = 0; i < node.children.length; i++) {\n\t\t\tconst childIsLast = i === node.children.length - 1;\n\t\t\t// Only show continuation line for non-root ancestors\n\t\t\tconst continues = depth > 0 ? !isLast : false;\n\t\t\twalk(node.children[i]!, depth + 1, [...ancestorContinues, continues], childIsLast);\n\t\t}\n\t};\n\n\tfor (let i = 0; i < roots.length; i++) {\n\t\twalk(roots[i]!, 0, [], i === roots.length - 1);\n\t}\n\n\treturn result;\n}\n\n/**\n * Custom session list component with multi-line items and search\n */\nclass SessionList implements Component, Focusable {\n\tpublic getSelectedSessionPath(): string | undefined {\n\t\tconst selected = this.filteredSessions[this.selectedIndex];\n\t\treturn selected?.kind === \"session\" ? selected.session.path : undefined;\n\t}\n\tprivate allSessions: SessionInfo[] = [];\n\tprivate filteredSessions: FlatSessionNode[] = [];\n\tprivate selectedIndex: number = 0;\n\tprivate selectionTouched = false;\n\tprivate searchInput: Input;\n\tprivate showCwd = false;\n\tprivate sortMode: SortMode = \"threaded\";\n\tprivate nameFilter: NameFilter = \"all\";\n\tprivate keybindings: KeybindingsManager;\n\tprivate showPath = false;\n\tprivate confirmingDeletePath: string | null = null;\n\tprivate currentSessionCanonicalPath?: string;\n\t/** Suite dimension state (设计 §10.1); inert until a suite context is injected. */\n\tprivate suiteFilter: SuiteFilter = \"current\";\n\tprivate currentSuiteId?: string;\n\tprivate getSessionSuiteId: SessionSuiteIdReader | undefined = undefined;\n\tprivate suiteIdCache = new Map<string, string | undefined>();\n\tpublic onSelect?: (sessionPath: string) => void;\n\tpublic onCancel?: () => void;\n\tpublic onExit: () => void = () => {};\n\tpublic onToggleScope?: () => void;\n\tpublic onToggleSuiteFilter?: () => void;\n\tpublic onToggleSort?: () => void;\n\tpublic onToggleNameFilter?: () => void;\n\tpublic onTogglePath?: (showPath: boolean) => void;\n\tpublic onDeleteConfirmationChange?: (path: string | null) => void;\n\tpublic onDeleteSession?: (sessionPath: string) => Promise<void>;\n\tpublic onRenameSession?: (sessionPath: string) => void;\n\tpublic onError?: (message: string) => void;\n\tprivate maxVisible: number = 10; // Max sessions visible (one line each)\n\n\t// Focusable implementation - propagate to searchInput for IME cursor positioning\n\tprivate _focused = false;\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\n\tconstructor(\n\t\tsessions: SessionInfo[],\n\t\tshowCwd: boolean,\n\t\tsortMode: SortMode,\n\t\tnameFilter: NameFilter,\n\t\tkeybindings: KeybindingsManager,\n\t\tcurrentSessionFilePath?: string,\n\t) {\n\t\tthis.allSessions = sessions;\n\t\tthis.filteredSessions = [];\n\t\tthis.searchInput = new Input();\n\t\tthis.showCwd = showCwd;\n\t\tthis.sortMode = sortMode;\n\t\tthis.nameFilter = nameFilter;\n\t\tthis.keybindings = keybindings;\n\t\tthis.currentSessionCanonicalPath = canonicalizePath(currentSessionFilePath);\n\t\tthis.filterSessions(\"\");\n\n\t\t// Handle Enter in search input - select current item\n\t\tthis.searchInput.onSubmit = () => {\n\t\t\t// v8 ignore next -- the search input never receives the confirm key; the list intercepts it\n\t\t\tconst selected = this.filteredSessions[this.selectedIndex];\n\t\t\t// v8 ignore next -- the search input never receives the confirm key; the list intercepts it\n\t\t\tif (selected && selected.kind === \"session\" && this.onSelect) {\n\t\t\t\tthis.onSelect(selected.session.path);\n\t\t\t}\n\t\t};\n\t}\n\n\tsetSortMode(sortMode: SortMode): void {\n\t\tthis.sortMode = sortMode;\n\t\tthis.filterSessions(this.searchInput.getValue());\n\t}\n\n\tsetNameFilter(nameFilter: NameFilter): void {\n\t\tthis.nameFilter = nameFilter;\n\t\tthis.filterSessions(this.searchInput.getValue());\n\t}\n\n\tsetSessions(sessions: SessionInfo[], showCwd: boolean): void {\n\t\tconst selectedPath = this.selectionTouched ? this.getSelectedSessionPath() : undefined;\n\t\tthis.allSessions = sessions;\n\t\tthis.showCwd = showCwd;\n\t\tthis.filterSessions(this.searchInput.getValue());\n\t\tif (!this.selectionTouched) {\n\t\t\tthis.selectedIndex = 0;\n\t\t} else if (selectedPath) {\n\t\t\tconst selectedIndex = this.filteredSessions.findIndex(\n\t\t\t\t(node) => node.kind === \"session\" && node.session.path === selectedPath,\n\t\t\t);\n\t\t\tif (selectedIndex >= 0) this.selectedIndex = selectedIndex;\n\t\t}\n\t}\n\n\t/**\n\t * Inject the suite dimension (设计 §10.1): \"current\" keeps only sessions\n\t * bound to the same suite as the current session (unbound matches unbound,\n\t * so legacy sessions stay visible to legacy sessions); \"all\" is reached\n\t * only through the explicit list toggle entry.\n\t */\n\tsetSuiteFilterContext(options: SessionSuiteFilterOptions): void {\n\t\tthis.currentSuiteId = options.currentSuiteId;\n\t\tthis.getSessionSuiteId = options.getSessionSuiteId;\n\t\tthis.filterSessions(this.searchInput.getValue());\n\t}\n\n\tsetSuiteFilter(filter: SuiteFilter): void {\n\t\tthis.suiteFilter = filter;\n\t\tthis.filterSessions(this.searchInput.getValue());\n\t}\n\n\tgetSuiteFilter(): SuiteFilter {\n\t\treturn this.suiteFilter;\n\t}\n\n\tprivate hasSuiteFilterContext(): boolean {\n\t\treturn this.getSessionSuiteId !== undefined;\n\t}\n\n\t/** Cached suite lookup; reader results are stable per session file. */\n\tprivate suiteIdOf(session: SessionInfo): string | undefined {\n\t\tconst reader = this.getSessionSuiteId;\n\t\tif (!reader) return undefined;\n\t\tif (this.suiteIdCache.has(session.path)) return this.suiteIdCache.get(session.path);\n\t\tconst suiteId = reader(session);\n\t\tthis.suiteIdCache.set(session.path, suiteId);\n\t\treturn suiteId;\n\t}\n\n\tprivate applySuiteFilter(sessions: SessionInfo[]): SessionInfo[] {\n\t\tif (this.suiteFilter === \"all\" || !this.hasSuiteFilterContext()) return sessions;\n\t\treturn sessions.filter((session) => this.suiteIdOf(session) === this.currentSuiteId);\n\t}\n\n\tprivate filterSessions(query: string): void {\n\t\tconst trimmed = query.trim();\n\t\tconst suiteFiltered = this.applySuiteFilter(this.allSessions);\n\t\tconst nameFiltered =\n\t\t\tthis.nameFilter === \"all\" ? suiteFiltered : suiteFiltered.filter((session) => hasSessionName(session));\n\n\t\tif (this.sortMode === \"threaded\" && !trimmed) {\n\t\t\t// Threaded mode without search: show tree structure\n\t\t\tconst roots = buildSessionTree(nameFiltered);\n\t\t\tthis.filteredSessions = flattenSessionTree(roots);\n\t\t} else {\n\t\t\t// Other modes or with search: flat list\n\t\t\tconst filtered = filterAndSortSessions(nameFiltered, query, this.sortMode, \"all\");\n\t\t\tthis.filteredSessions = filtered.map((session) => ({\n\t\t\t\tkind: \"session\" as const,\n\t\t\t\tsession,\n\t\t\t\tdepth: 0,\n\t\t\t\tisLast: true,\n\t\t\t\tancestorContinues: [],\n\t\t\t}));\n\t\t}\n\t\t// The explicit \"show all suites / current suite\" action is offered as the\n\t\t// first row (设计 §10.1); hidden while searching so queries stay clean.\n\t\tif (this.hasSuiteFilterContext() && !trimmed) {\n\t\t\tthis.filteredSessions = [\n\t\t\t\t{ kind: \"suite-toggle\", target: this.suiteFilter === \"current\" ? \"all\" : \"current\" },\n\t\t\t\t...this.filteredSessions,\n\t\t\t];\n\t\t}\n\t\tthis.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredSessions.length - 1));\n\t}\n\n\tprivate setConfirmingDeletePath(path: string | null): void {\n\t\tthis.confirmingDeletePath = path;\n\t\tthis.onDeleteConfirmationChange?.(path);\n\t}\n\n\tprivate startDeleteConfirmationForSelectedSession(): void {\n\t\tconst selected = this.filteredSessions[this.selectedIndex];\n\t\t// The suite toggle row is an action, not a deletable session.\n\t\tif (!selected || selected.kind !== \"session\") return;\n\n\t\t// Prevent deleting current session\n\t\tif (this.isCurrentSessionPath(selected.session.path)) {\n\t\t\tthis.onError?.(t(\"Cannot delete the currently active session\"));\n\t\t\treturn;\n\t\t}\n\n\t\tthis.setConfirmingDeletePath(selected.session.path);\n\t}\n\n\tprivate isCurrentSessionPath(path: string): boolean {\n\t\tif (!this.currentSessionCanonicalPath) return false;\n\t\treturn (canonicalizePath(path) ?? path) === this.currentSessionCanonicalPath;\n\t}\n\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tconst lines: string[] = [];\n\n\t\t// Render search input\n\t\tlines.push(...this.searchInput.render(width));\n\t\tlines.push(\"\"); // Blank line after search\n\n\t\tif (this.filteredSessions.length === 0) {\n\t\t\tlet emptyMessage: string;\n\t\t\tif (this.nameFilter === \"named\") {\n\t\t\t\tconst toggleKey = keyText(\"app.session.toggleNamedFilter\");\n\t\t\t\tif (this.showCwd) {\n\t\t\t\t\temptyMessage = t(\"No named sessions found. Press {key} to show all.\", { key: toggleKey });\n\t\t\t\t} else {\n\t\t\t\t\temptyMessage = t(\"No named sessions in current folder. Press {key} to show all, or Tab to view all.\", {\n\t\t\t\t\t\tkey: toggleKey,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else if (this.showCwd) {\n\t\t\t\t// \"All\" scope - no sessions anywhere that match filter\n\t\t\t\temptyMessage = t(\"No sessions found\");\n\t\t\t} else {\n\t\t\t\t// \"Current folder\" scope - hint to try \"all\"\n\t\t\t\temptyMessage = t(\"No sessions in current folder. Press Tab to view all.\");\n\t\t\t}\n\t\t\tlines.push(theme.fg(\"muted\", truncateToWidth(` ${emptyMessage}`, width, \"…\")));\n\t\t\treturn lines;\n\t\t}\n\n\t\t// Calculate visible range with scrolling\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredSessions.length - this.maxVisible),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + this.maxVisible, this.filteredSessions.length);\n\n\t\t// Render visible sessions (one line each with tree structure)\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst node = this.filteredSessions[i]!;\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tif (node.kind === \"suite-toggle\") {\n\t\t\t\tconst label =\n\t\t\t\t\tnode.target === \"all\" ? t(\"Show sessions from all suites\") : t(\"Show current suite sessions only\");\n\t\t\t\tconst cursor = isSelected ? theme.fg(\"accent\", \"› \") : \" \";\n\t\t\t\tlet toggleLine = cursor + theme.fg(\"muted\", `· ${label}`);\n\t\t\t\tif (isSelected) {\n\t\t\t\t\ttoggleLine = theme.bg(\"selectedBg\", theme.bold(toggleLine));\n\t\t\t\t}\n\t\t\t\tlines.push(truncateToWidth(toggleLine, width));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst session = node.session;\n\t\t\tconst isConfirmingDelete = session.path === this.confirmingDeletePath;\n\t\t\tconst isCurrent = this.isCurrentSessionPath(session.path);\n\n\t\t\t// Build tree prefix\n\t\t\tconst prefix = this.buildTreePrefix(node);\n\n\t\t\t// Session display text (name or first message)\n\t\t\tconst hasName = !!session.name;\n\t\t\tconst displayText = session.name ?? session.firstMessage;\n\t\t\tconst normalizedMessage = displayText.replace(/[\\x00-\\x1f\\x7f]/g, \" \").trim();\n\n\t\t\t// Right side: message count and age\n\t\t\tconst age = formatSessionDate(session.modified);\n\t\t\tconst msgCount = String(session.messageCount);\n\t\t\tlet rightPart = `${msgCount} ${age}`;\n\t\t\tif (this.showCwd && session.cwd) {\n\t\t\t\trightPart = `${shortenPath(session.cwd)} ${rightPart}`;\n\t\t\t}\n\t\t\tif (this.showPath) {\n\t\t\t\trightPart = `${shortenPath(session.path)} ${rightPart}`;\n\t\t\t}\n\n\t\t\t// Cursor\n\t\t\tconst cursor = isSelected ? theme.fg(\"accent\", \"› \") : \" \";\n\n\t\t\t// Calculate available width for message\n\t\t\tconst prefixWidth = visibleWidth(prefix);\n\t\t\tconst rightWidth = visibleWidth(rightPart) + 2; // +2 for spacing\n\t\t\tconst availableForMsg = width - 2 - prefixWidth - rightWidth; // -2 for cursor\n\n\t\t\tconst truncatedMsg = truncateToWidth(normalizedMessage, Math.max(10, availableForMsg), \"…\");\n\n\t\t\t// Style message\n\t\t\tlet messageColor: \"error\" | \"warning\" | \"accent\" | null = null;\n\t\t\tif (isConfirmingDelete) {\n\t\t\t\tmessageColor = \"error\";\n\t\t\t} else if (isCurrent) {\n\t\t\t\tmessageColor = \"accent\";\n\t\t\t} else if (hasName) {\n\t\t\t\tmessageColor = \"warning\";\n\t\t\t}\n\t\t\tlet styledMsg = messageColor ? theme.fg(messageColor, truncatedMsg) : truncatedMsg;\n\t\t\tif (isSelected) {\n\t\t\t\tstyledMsg = theme.bold(styledMsg);\n\t\t\t}\n\n\t\t\t// Build line\n\t\t\tconst leftPart = cursor + theme.fg(\"dim\", prefix) + styledMsg;\n\t\t\tconst leftWidth = visibleWidth(leftPart);\n\t\t\tconst spacing = Math.max(1, width - leftWidth - visibleWidth(rightPart));\n\t\t\tconst styledRight = theme.fg(isConfirmingDelete ? \"error\" : \"dim\", rightPart);\n\n\t\t\tlet line = leftPart + \" \".repeat(spacing) + styledRight;\n\t\t\tif (isSelected) {\n\t\t\t\tline = theme.bg(\"selectedBg\", line);\n\t\t\t}\n\t\t\tlines.push(truncateToWidth(line, width));\n\t\t}\n\n\t\t// Add scroll indicator if needed\n\t\tif (startIndex > 0 || endIndex < this.filteredSessions.length) {\n\t\t\tconst scrollText = ` (${this.selectedIndex + 1}/${this.filteredSessions.length})`;\n\t\t\tconst scrollInfo = theme.fg(\"muted\", truncateToWidth(scrollText, width, \"\"));\n\t\t\tlines.push(scrollInfo);\n\t\t}\n\n\t\treturn lines;\n\t}\n\n\tprivate buildTreePrefix(node: Extract<FlatSessionNode, { kind: \"session\" }>): string {\n\t\tif (node.depth === 0) {\n\t\t\treturn \"\";\n\t\t}\n\n\t\tconst parts = node.ancestorContinues.map((continues) => (continues ? \"│ \" : \" \"));\n\t\tconst branch = node.isLast ? \"└─ \" : \"├─ \";\n\t\treturn parts.join(\"\") + branch;\n\t}\n\n\thandleInput(keyData: string): void {\n\t\tconst kb = getKeybindings();\n\n\t\t// Handle delete confirmation state first - intercept all keys\n\t\tif (this.confirmingDeletePath !== null) {\n\t\t\tif (kb.matches(keyData, \"tui.select.confirm\")) {\n\t\t\t\tconst pathToDelete = this.confirmingDeletePath;\n\t\t\t\tthis.setConfirmingDeletePath(null);\n\t\t\t\tvoid this.onDeleteSession?.(pathToDelete);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (kb.matches(keyData, \"tui.select.cancel\")) {\n\t\t\t\tthis.setConfirmingDeletePath(null);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Ignore all other keys while confirming\n\t\t\treturn;\n\t\t}\n\n\t\tif (kb.matches(keyData, \"tui.input.tab\")) {\n\t\t\t// v8 ignore next -- onToggleScope is always assigned by SessionSelectorComponent\n\t\t\tif (this.onToggleScope) {\n\t\t\t\tthis.onToggleScope();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (kb.matches(keyData, \"app.session.toggleSort\")) {\n\t\t\tthis.onToggleSort?.();\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.keybindings.matches(keyData, \"app.session.toggleNamedFilter\")) {\n\t\t\tthis.onToggleNameFilter?.();\n\t\t\treturn;\n\t\t}\n\n\t\t// Ctrl+P: toggle path display\n\t\tif (kb.matches(keyData, \"app.session.togglePath\")) {\n\t\t\tthis.showPath = !this.showPath;\n\t\t\tthis.onTogglePath?.(this.showPath);\n\t\t\treturn;\n\t\t}\n\n\t\t// Ctrl+D: initiate delete confirmation (useful on terminals that don't distinguish Ctrl+Backspace from Backspace)\n\t\tif (kb.matches(keyData, \"app.session.delete\")) {\n\t\t\tthis.startDeleteConfirmationForSelectedSession();\n\t\t\treturn;\n\t\t}\n\n\t\t// Rename selected session\n\t\tif (kb.matches(keyData, \"app.session.rename\")) {\n\t\t\tconst selected = this.filteredSessions[this.selectedIndex];\n\t\t\tif (selected && selected.kind === \"session\") {\n\t\t\t\tthis.onRenameSession?.(selected.session.path);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Ctrl+Backspace: non-invasive convenience alias for delete\n\t\t// Only triggers deletion when the query is empty; otherwise it is forwarded to the input\n\t\tif (kb.matches(keyData, \"app.session.deleteNoninvasive\")) {\n\t\t\tif (this.searchInput.getValue().length > 0) {\n\t\t\t\tthis.searchInput.handleInput(keyData);\n\t\t\t\tthis.filterSessions(this.searchInput.getValue());\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.startDeleteConfirmationForSelectedSession();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.selectionTouched = true;\n\t\t// Up arrow\n\t\tif (kb.matches(keyData, \"tui.select.up\")) {\n\t\t\tthis.selectedIndex = Math.max(0, this.selectedIndex - 1);\n\t\t}\n\t\t// Down arrow\n\t\telse if (kb.matches(keyData, \"tui.select.down\")) {\n\t\t\tthis.selectedIndex = Math.min(this.filteredSessions.length - 1, this.selectedIndex + 1);\n\t\t}\n\t\t// Page up - jump up by maxVisible items\n\t\telse if (kb.matches(keyData, \"tui.select.pageUp\")) {\n\t\t\tthis.selectedIndex = Math.max(0, this.selectedIndex - this.maxVisible);\n\t\t}\n\t\t// Page down - jump down by maxVisible items\n\t\telse if (kb.matches(keyData, \"tui.select.pageDown\")) {\n\t\t\tthis.selectedIndex = Math.min(this.filteredSessions.length - 1, this.selectedIndex + this.maxVisible);\n\t\t}\n\t\t// Enter\n\t\telse if (kb.matches(keyData, \"tui.select.confirm\")) {\n\t\t\tconst selected = this.filteredSessions[this.selectedIndex];\n\t\t\tif (selected && selected.kind === \"suite-toggle\") {\n\t\t\t\t// Explicit \"show all / current suite\" action (设计 §10.1).\n\t\t\t\tthis.onToggleSuiteFilter?.();\n\t\t\t} else if (selected && selected.kind === \"session\" && this.onSelect) {\n\t\t\t\tthis.onSelect(selected.session.path);\n\t\t\t}\n\t\t}\n\t\t// Escape - cancel\n\t\telse if (kb.matches(keyData, \"tui.select.cancel\")) {\n\t\t\t// v8 ignore next -- onCancel is always assigned by SessionSelectorComponent\n\t\t\tif (this.onCancel) {\n\t\t\t\tthis.onCancel();\n\t\t\t}\n\t\t}\n\t\t// Pass everything else to search input\n\t\telse {\n\t\t\tthis.searchInput.handleInput(keyData);\n\t\t\tthis.filterSessions(this.searchInput.getValue());\n\t\t}\n\t}\n}\n\ntype SessionsLoader = (onProgress?: SessionListProgress, signal?: AbortSignal) => Promise<SessionInfo[]>;\n\n/**\n * Delete a session file, trying the `trash` CLI first, then falling back to unlink\n */\nasync function deleteSessionFile(\n\tsessionPath: string,\n): Promise<{ ok: boolean; method: \"trash\" | \"unlink\"; error?: string }> {\n\t// Try `trash` first (if installed)\n\tconst trashArgs = sessionPath.startsWith(\"-\") ? [\"--\", sessionPath] : [sessionPath];\n\tconst trashResult = spawnSync(\"trash\", trashArgs, { encoding: \"utf-8\" });\n\n\tconst getTrashErrorHint = (): string | null => {\n\t\tconst parts: string[] = [];\n\t\tif (trashResult.error) {\n\t\t\tparts.push(trashResult.error.message);\n\t\t}\n\t\tconst stderr = trashResult.stderr?.trim();\n\t\tif (stderr) {\n\t\t\t// v8 ignore next -- split always returns at least one element\n\t\t\tparts.push(stderr.split(\"\\n\")[0] ?? stderr);\n\t\t}\n\t\tif (parts.length === 0) return null;\n\t\treturn `trash: ${parts.join(\" · \").slice(0, 200)}`;\n\t};\n\n\t// If trash reports success, or the file is gone afterwards, treat it as successful\n\tif (trashResult.status === 0 || !existsSync(sessionPath)) {\n\t\treturn { ok: true, method: \"trash\" };\n\t}\n\n\t// Fallback to permanent deletion\n\ttry {\n\t\tawait unlink(sessionPath);\n\t\treturn { ok: true, method: \"unlink\" };\n\t} catch (err) {\n\t\t// v8 ignore next -- unlink always rejects with Error instances\n\t\tconst unlinkError = err instanceof Error ? err.message : String(err);\n\t\tconst trashErrorHint = getTrashErrorHint();\n\t\tconst error = trashErrorHint ? `${unlinkError} (${trashErrorHint})` : unlinkError;\n\t\treturn { ok: false, method: \"unlink\", error };\n\t}\n}\n\n/**\n * Component that renders a session selector\n */\nexport class SessionSelectorComponent extends Container implements Focusable {\n\thandleInput(data: string): void {\n\t\tif (this.mode === \"rename\") {\n\t\t\tconst kb = getKeybindings();\n\t\t\tif (kb.matches(data, \"tui.select.cancel\")) {\n\t\t\t\tthis.exitRenameMode();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.renameInput.handleInput(data);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.sessionList.handleInput(data);\n\t}\n\n\tprivate canRename = true;\n\tprivate sessionList: SessionList;\n\tprivate header: SessionSelectorHeader;\n\tprivate keybindings: KeybindingsManager;\n\tprivate scope: SessionScope = \"current\";\n\tprivate sortMode: SortMode = \"threaded\";\n\tprivate nameFilter: NameFilter = \"all\";\n\tprivate suiteFilterOptions: SessionSuiteFilterOptions | undefined = undefined;\n\tprivate suiteFilter: SuiteFilter = \"current\";\n\tprivate currentSessions: SessionInfo[] | null = null;\n\tprivate allSessions: SessionInfo[] | null = null;\n\tprivate currentSessionsLoader: SessionsLoader;\n\tprivate allSessionsLoader: SessionsLoader;\n\tprivate requestRender: () => void;\n\tprivate renameSession?: (sessionPath: string, currentName: string | undefined) => Promise<void>;\n\tprivate currentLoad: AbortController | null = null;\n\tprivate allLoad: AbortController | null = null;\n\n\tprivate mode: \"list\" | \"rename\" = \"list\";\n\tprivate renameInput = new Input();\n\tprivate renameTargetPath: string | null = null;\n\n\t// Focusable implementation - propagate to sessionList for IME cursor positioning\n\tprivate _focused = false;\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.sessionList.focused = value;\n\t\tthis.renameInput.focused = value;\n\t\tif (value && this.mode === \"rename\") {\n\t\t\tthis.renameInput.focused = true;\n\t\t}\n\t}\n\n\tprivate buildBaseLayout(content: Component, options?: { showHeader?: boolean }): void {\n\t\tthis.clear();\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder((s) => theme.fg(\"accent\", s)));\n\t\tthis.addChild(new Spacer(1));\n\t\tif (options?.showHeader ?? true) {\n\t\t\tthis.addChild(this.header);\n\t\t\tthis.addChild(new Spacer(1));\n\t\t}\n\t\tthis.addChild(content);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder((s) => theme.fg(\"accent\", s)));\n\t}\n\n\tconstructor(\n\t\tcurrentSessionsLoader: SessionsLoader,\n\t\tallSessionsLoader: SessionsLoader,\n\t\tonSelect: (sessionPath: string) => void,\n\t\tonCancel: () => void,\n\t\tonExit: () => void,\n\t\trequestRender: () => void,\n\t\toptions?: {\n\t\t\trenameSession?: (sessionPath: string, currentName: string | undefined) => Promise<void>;\n\t\t\tshowRenameHint?: boolean;\n\t\t\tkeybindings?: KeybindingsManager;\n\t\t\t/** Suite dimension of the list (设计 §10.1); omit to keep the unfiltered folder views. */\n\t\t\tsuiteFilter?: SessionSuiteFilterOptions;\n\t\t},\n\t\tcurrentSessionFilePath?: string,\n\t) {\n\t\tsuper();\n\t\tthis.keybindings = options?.keybindings ?? KeybindingsManager.create();\n\t\tthis.currentSessionsLoader = currentSessionsLoader;\n\t\tthis.allSessionsLoader = allSessionsLoader;\n\t\tthis.requestRender = requestRender;\n\t\tthis.suiteFilterOptions = options?.suiteFilter;\n\t\tthis.header = new SessionSelectorHeader(this.scope, this.sortMode, this.nameFilter, this.requestRender);\n\t\tif (this.suiteFilterOptions) {\n\t\t\tthis.header.setSuiteTitle(this.suiteTitle());\n\t\t}\n\t\tconst renameSession = options?.renameSession;\n\t\tthis.renameSession = renameSession;\n\t\tthis.canRename = !!renameSession;\n\t\tthis.header.setShowRenameHint(options?.showRenameHint ?? this.canRename);\n\n\t\t// Create session list (starts empty, will be populated after load)\n\t\tthis.sessionList = new SessionList(\n\t\t\t[],\n\t\t\tfalse,\n\t\t\tthis.sortMode,\n\t\t\tthis.nameFilter,\n\t\t\tthis.keybindings,\n\t\t\tcurrentSessionFilePath,\n\t\t);\n\t\tif (this.suiteFilterOptions) {\n\t\t\tthis.sessionList.setSuiteFilterContext(this.suiteFilterOptions);\n\t\t}\n\t\tthis.sessionList.onToggleSuiteFilter = () => this.toggleSuiteFilter();\n\n\t\tthis.buildBaseLayout(this.sessionList);\n\n\t\tthis.renameInput.onSubmit = (value) => {\n\t\t\tvoid this.confirmRename(value);\n\t\t};\n\n\t\t// Ensure header status timeouts are cleared when leaving the selector\n\t\tconst clearStatusMessage = () => this.header.setStatusMessage(null);\n\t\tthis.sessionList.onSelect = (sessionPath) => {\n\t\t\tclearStatusMessage();\n\t\t\tthis.cancelLoads();\n\t\t\tonSelect(sessionPath);\n\t\t};\n\t\tthis.sessionList.onCancel = () => {\n\t\t\tclearStatusMessage();\n\t\t\tthis.cancelLoads();\n\t\t\tonCancel();\n\t\t};\n\t\tthis.sessionList.onExit = () => {\n\t\t\tclearStatusMessage();\n\t\t\tthis.cancelLoads();\n\t\t\tonExit();\n\t\t};\n\t\tthis.sessionList.onToggleScope = () => this.toggleScope();\n\t\tthis.sessionList.onToggleSort = () => this.toggleSortMode();\n\t\tthis.sessionList.onToggleNameFilter = () => this.toggleNameFilter();\n\t\tthis.sessionList.onRenameSession = (sessionPath) => {\n\t\t\tif (!renameSession) return;\n\t\t\t// v8 ignore next -- rename requires a visible selection, impossible while the current load is pending\n\t\t\tif (this.scope === \"current\" ? this.currentLoad : this.allLoad) return;\n\n\t\t\tconst sessions = this.scope === \"all\" ? (this.allSessions ?? []) : (this.currentSessions ?? []);\n\t\t\tconst session = sessions.find((s) => s.path === sessionPath);\n\t\t\tthis.enterRenameMode(sessionPath, session?.name);\n\t\t};\n\n\t\t// Sync list events to header\n\t\tthis.sessionList.onTogglePath = (showPath) => {\n\t\t\tthis.header.setShowPath(showPath);\n\t\t\tthis.requestRender();\n\t\t};\n\t\tthis.sessionList.onDeleteConfirmationChange = (path) => {\n\t\t\tthis.header.setConfirmingDeletePath(path);\n\t\t\tthis.requestRender();\n\t\t};\n\t\tthis.sessionList.onError = (msg) => {\n\t\t\tthis.header.setStatusMessage({ type: \"error\", message: msg }, 3000);\n\t\t\tthis.requestRender();\n\t\t};\n\n\t\t// Handle session deletion\n\t\tthis.sessionList.onDeleteSession = async (sessionPath: string) => {\n\t\t\tconst result = await deleteSessionFile(sessionPath);\n\n\t\t\tif (result.ok) {\n\t\t\t\t// 删除不经 SessionManager(设计 docs/design/会话索引.md §4):成功后同步\n\t\t\t\t// 移除索引条目;失败吞掉,对账会在下次读取自愈。\n\t\t\t\ttry {\n\t\t\t\t\tremoveSessionFromIndex(sessionPath);\n\t\t\t\t} catch {\n\t\t\t\t\t// Index maintenance must never break the delete flow.\n\t\t\t\t}\n\t\t\t\tif (this.currentSessions) {\n\t\t\t\t\tthis.currentSessions = this.currentSessions.filter((s) => s.path !== sessionPath);\n\t\t\t\t}\n\t\t\t\tif (this.allSessions) {\n\t\t\t\t\tthis.allSessions = this.allSessions.filter((s) => s.path !== sessionPath);\n\t\t\t\t}\n\n\t\t\t\tconst sessions = this.scope === \"all\" ? (this.allSessions ?? []) : (this.currentSessions ?? []);\n\t\t\t\tconst showCwd = this.scope === \"all\";\n\t\t\t\tthis.sessionList.setSessions(sessions, showCwd);\n\n\t\t\t\tconst msg = result.method === \"trash\" ? t(\"Session moved to trash\") : t(\"Session deleted\");\n\t\t\t\tthis.header.setStatusMessage({ type: \"info\", message: msg }, 2000);\n\t\t\t\tawait this.refreshSessionsAfterMutation();\n\t\t\t} else {\n\t\t\t\t// v8 ignore next -- deleteSessionFile always reports an error when ok is false\n\t\t\t\tconst errorMessage = result.error ?? t(\"Unknown error\");\n\t\t\t\tthis.header.setStatusMessage(\n\t\t\t\t\t{ type: \"error\", message: t(\"Failed to delete: {error}\", { error: errorMessage }) },\n\t\t\t\t\t3000,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.requestRender();\n\t\t};\n\n\t\t// Start loading current sessions immediately\n\t\tvoid this.loadScope(\"current\");\n\t}\n\n\tprivate cancelLoads(): void {\n\t\tif (this.currentLoad) {\n\t\t\tthis.currentLoad.abort();\n\t\t\tthis.currentLoad = null;\n\t\t\tthis.currentSessions = null;\n\t\t}\n\t\tif (this.allLoad) {\n\t\t\tthis.allLoad.abort();\n\t\t\tthis.allLoad = null;\n\t\t\tthis.allSessions = null;\n\t\t}\n\t}\n\n\tprivate enterRenameMode(sessionPath: string, currentName: string | undefined): void {\n\t\tthis.mode = \"rename\";\n\t\tthis.renameTargetPath = sessionPath;\n\t\tthis.renameInput.setValue(currentName ?? \"\");\n\t\tthis.renameInput.focused = true;\n\n\t\tconst panel = new Container();\n\t\tpanel.addChild(new Text(theme.bold(t(\"Rename Session\")), 1, 0));\n\t\tpanel.addChild(new Spacer(1));\n\t\tpanel.addChild(this.renameInput);\n\t\tpanel.addChild(new Spacer(1));\n\t\tpanel.addChild(\n\t\t\tnew Text(\n\t\t\t\ttheme.fg(\n\t\t\t\t\t\"muted\",\n\t\t\t\t\tt(\"{confirm} to save · {cancel} to cancel\", {\n\t\t\t\t\t\tconfirm: keyText(\"tui.select.confirm\"),\n\t\t\t\t\t\tcancel: keyText(\"tui.select.cancel\"),\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t\t1,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\n\t\tthis.buildBaseLayout(panel, { showHeader: false });\n\t\tthis.requestRender();\n\t}\n\n\tprivate exitRenameMode(): void {\n\t\tthis.mode = \"list\";\n\t\tthis.renameTargetPath = null;\n\n\t\tthis.buildBaseLayout(this.sessionList);\n\n\t\tthis.requestRender();\n\t}\n\n\tprivate async confirmRename(value: string): Promise<void> {\n\t\tconst next = value.trim();\n\t\tif (!next) return;\n\t\tconst target = this.renameTargetPath;\n\t\t// v8 ignore next -- rename mode is only entered with a target path\n\t\tif (!target) {\n\t\t\tthis.exitRenameMode();\n\t\t\treturn;\n\t\t}\n\n\t\t// Find current name for callback\n\t\tconst renameSession = this.renameSession;\n\t\t// v8 ignore next -- rename mode is only entered with a rename callback\n\t\tif (!renameSession) {\n\t\t\tthis.exitRenameMode();\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait renameSession(target, next);\n\t\t\tawait this.refreshSessionsAfterMutation();\n\t\t} catch (error) {\n\t\t\t// 与删除失败一致:向用户呈现错误状态,而不是让拒绝逃逸成 unhandled rejection。\n\t\t\tthis.header.setStatusMessage(\n\t\t\t\t{ type: \"error\", message: error instanceof Error ? error.message : String(error) },\n\t\t\t\t3000,\n\t\t\t);\n\t\t\tthis.requestRender();\n\t\t} finally {\n\t\t\tthis.exitRenameMode();\n\t\t}\n\t}\n\n\tprivate async loadScope(scope: SessionScope): Promise<void> {\n\t\tif (scope === \"current\" ? this.currentLoad : this.allLoad) return;\n\n\t\tconst showCwd = scope === \"all\";\n\t\tconst controller = new AbortController();\n\t\tif (scope === \"current\") {\n\t\t\tthis.currentLoad = controller;\n\t\t} else {\n\t\t\tthis.allLoad = controller;\n\t\t}\n\t\tthis.header.setScope(scope);\n\t\tthis.header.setLoading(true);\n\t\tthis.requestRender();\n\n\t\tconst isActive = () => (scope === \"current\" ? this.currentLoad : this.allLoad) === controller;\n\t\tconst onProgress: SessionListProgress = (loaded, total, partialSessions) => {\n\t\t\tif (!isActive()) return;\n\t\t\tif (partialSessions) {\n\t\t\t\tconst sessions = [...partialSessions];\n\t\t\t\tif (scope === \"current\") {\n\t\t\t\t\tthis.currentSessions = sessions;\n\t\t\t\t} else {\n\t\t\t\t\tthis.allSessions = sessions;\n\t\t\t\t}\n\t\t\t\tif (scope === this.scope) this.sessionList.setSessions(sessions, showCwd);\n\t\t\t}\n\t\t\tif (scope !== this.scope) return;\n\t\t\tthis.header.setProgress(loaded, total);\n\t\t\tthis.requestRender();\n\t\t};\n\n\t\ttry {\n\t\t\tconst sessions = await (scope === \"current\"\n\t\t\t\t? this.currentSessionsLoader(onProgress, controller.signal)\n\t\t\t\t: this.allSessionsLoader(onProgress, controller.signal));\n\t\t\tif (!isActive()) return;\n\n\t\t\tif (scope === \"current\") {\n\t\t\t\tthis.currentSessions = sessions;\n\t\t\t\tthis.currentLoad = null;\n\t\t\t} else {\n\t\t\t\tthis.allSessions = sessions;\n\t\t\t\tthis.allLoad = null;\n\t\t\t}\n\n\t\t\tif (scope !== this.scope) return;\n\n\t\t\tthis.header.setLoading(false);\n\t\t\tthis.sessionList.setSessions(sessions, showCwd);\n\t\t\tthis.requestRender();\n\t\t} catch (err) {\n\t\t\tif (!isActive()) return;\n\t\t\tif (scope === \"current\") {\n\t\t\t\tthis.currentLoad = null;\n\t\t\t\tthis.currentSessions = null;\n\t\t\t} else {\n\t\t\t\tthis.allLoad = null;\n\t\t\t\tthis.allSessions = null;\n\t\t\t}\n\n\t\t\tif (scope !== this.scope) return;\n\n\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\tthis.header.setLoading(false);\n\t\t\tthis.header.setStatusMessage(\n\t\t\t\t{ type: \"error\", message: t(\"Failed to load sessions: {message}\", { message }) },\n\t\t\t\t4000,\n\t\t\t);\n\t\t\tthis.sessionList.setSessions([], showCwd);\n\t\t\tthis.requestRender();\n\t\t}\n\t}\n\n\tprivate toggleSortMode(): void {\n\t\t// Cycle: threaded -> recent -> relevance -> threaded\n\t\tthis.sortMode = this.sortMode === \"threaded\" ? \"recent\" : this.sortMode === \"recent\" ? \"relevance\" : \"threaded\";\n\t\tthis.header.setSortMode(this.sortMode);\n\t\tthis.sessionList.setSortMode(this.sortMode);\n\t\tthis.requestRender();\n\t}\n\n\tprivate toggleNameFilter(): void {\n\t\tthis.nameFilter = this.nameFilter === \"all\" ? \"named\" : \"all\";\n\t\tthis.header.setNameFilter(this.nameFilter);\n\t\tthis.sessionList.setNameFilter(this.nameFilter);\n\t\tthis.requestRender();\n\t}\n\n\tprivate suiteTitle(): string {\n\t\tif (this.suiteFilter === \"all\") return t(\"Resume Session (All Suites)\");\n\t\treturn t(\"Resume Session (Suite: {suite})\", {\n\t\t\tsuite: this.suiteFilterOptions?.currentSuiteId ?? \"unbound\",\n\t\t});\n\t}\n\n\t/**\n\t * Explicit \"show all\" switch for the suite dimension (设计 §10.1): sessions\n\t * from other suites (and unbound legacy sessions when the current session is\n\t * bound) are only visible after this explicit action.\n\t */\n\tprivate toggleSuiteFilter(): void {\n\t\tif (!this.suiteFilterOptions) return;\n\t\tthis.suiteFilter = this.suiteFilter === \"current\" ? \"all\" : \"current\";\n\t\tthis.header.setSuiteTitle(this.suiteTitle());\n\t\tthis.sessionList.setSuiteFilter(this.suiteFilter);\n\t\tthis.requestRender();\n\t}\n\n\tprivate async refreshSessionsAfterMutation(): Promise<void> {\n\t\tthis.cancelLoads();\n\t\tthis.currentSessions = null;\n\t\tthis.allSessions = null;\n\t\tawait this.loadScope(this.scope);\n\t}\n\n\tprivate toggleScope(): void {\n\t\tthis.scope = this.scope === \"current\" ? \"all\" : \"current\";\n\t\tconst sessions = this.scope === \"current\" ? this.currentSessions : this.allSessions;\n\t\tconst loading = (this.scope === \"current\" ? this.currentLoad : this.allLoad) !== null;\n\t\tthis.header.setScope(this.scope);\n\t\tthis.header.setLoading(loading);\n\t\tthis.sessionList.setSessions(sessions ?? [], this.scope === \"all\");\n\t\tthis.requestRender();\n\t\tif (sessions === null && !loading) void this.loadScope(this.scope);\n\t}\n\n\tgetSessionList(): SessionList {\n\t\treturn this.sessionList;\n\t}\n}\n"]}
1
+ {"version":3,"file":"session-selector.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/session-selector.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,KAAK,SAAS,EACd,SAAS,EACT,KAAK,SAAS,EAOd,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAElE,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAMzF,OAAO,EAAyC,KAAK,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAIrH,kGAA6F;AAC7F,KAAK,WAAW,GAAG,SAAS,GAAG,KAAK,CAAC;AAErC,qFAAqF;AACrF,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK,MAAM,GAAG,SAAS,CAAC;AAEhF,MAAM,WAAW,yBAAyB;IACzC,sFAAsF;IACtF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,4FAA4F;IAC5F,iB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MAAM,EAAE,MAAM,IAAI,EAClB,aAAa,EAAE,MAAM,IAAI,EACzB,OAAO,CAAC,EAAE;QACT,aAAa,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;QACxF,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,WAAW,CAAC,EAAE,kBAAkB,CAAC;QACjC,6FAAwF;QACxF,WAAW,CAAC,EAAE,yBAAyB,CAAC;KACxC,EACD,sBAAsB,CAAC,EAAE,MAAM,EAyH/B;IAED,OAAO,CAAC,WAAW;IAanB,OAAO,CAAC,eAAe;IA6BvB,OAAO,CAAC,cAAc;YASR,aAAa;YAiCb,SAAS;IAyEvB,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,UAAU;IAOlB;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;YAQX,4BAA4B;IAO1C,OAAO,CAAC,WAAW;IAWnB,cAAc,IAAI,WAAW,CAE5B;CACD","sourcesContent":["import { spawnSync } from \"node:child_process\";\nimport { closeSync, existsSync, openSync, readSync } from \"node:fs\";\nimport { unlink } from \"node:fs/promises\";\nimport * as os from \"node:os\";\nimport { StringDecoder } from \"node:string_decoder\";\nimport {\n\ttype Component,\n\tContainer,\n\ttype Focusable,\n\tgetKeybindings,\n\tInput,\n\tSpacer,\n\tText,\n\ttruncateToWidth,\n\tvisibleWidth,\n} from \"@agent-forge/tui\";\nimport { t } from \"../../../core/i18n/index.ts\";\nimport { KeybindingsManager } from \"../../../core/keybindings.ts\";\nimport { removeSessionFromIndex } from \"../../../core/session-index.ts\";\nimport type { SessionInfo, SessionListProgress } from \"../../../core/session-manager.ts\";\nimport { SUITE_SESSION_ENTRY_TYPE } from \"../../../suites/suite-loader.ts\";\nimport { theme } from \"../../../theme/theme.ts\";\nimport { canonicalizePath as _canonicalizePath } from \"../../../utils/paths.ts\";\nimport { DynamicBorder } from \"./dynamic-border.ts\";\nimport { keyHint, keyText } from \"./keybinding-hints.ts\";\nimport { filterAndSortSessions, hasSessionName, type NameFilter, type SortMode } from \"./session-selector-search.ts\";\n\ntype SessionScope = \"current\" | \"all\";\n\n/** Suite dimension of the session list (设计 §10.1): bound to the current suite by default. */\ntype SuiteFilter = \"current\" | \"all\";\n\n/** Suite id extracted from a session file; undefined = unbound (legacy sessions). */\nexport type SessionSuiteIdReader = (session: SessionInfo) => string | undefined;\n\nexport interface SessionSuiteFilterOptions {\n\t/** Suite id of the session that opened the selector; undefined = unbound (legacy). */\n\tcurrentSuiteId?: string;\n\t/** Reads the bound suite id for a listed session. Undefined results are cached per path. */\n\tgetSessionSuiteId: SessionSuiteIdReader;\n}\n\n/**\n * Scan the head of a session JSONL file for the suite binding entry (设计\n * §10.1: recorded as a custom entry when the session is created; resumed\n * sessions keep their original binding). Returns undefined when the session is\n * unbound, the file is unreadable, or no binding entry is found in the scanned\n * head.\n */\nexport function readSessionSuiteIdFromFile(sessionPath: string): string | undefined {\n\tconst scanLimitBytes = 64 * 1024;\n\tlet fd: number;\n\ttry {\n\t\tfd = openSync(sessionPath, \"r\");\n\t} catch {\n\t\treturn undefined;\n\t}\n\ttry {\n\t\tconst decoder = new StringDecoder(\"utf8\");\n\t\tconst buffer = Buffer.allocUnsafe(4096);\n\t\tlet scannedBytes = 0;\n\t\tlet leftover = \"\";\n\t\twhile (scannedBytes < scanLimitBytes) {\n\t\t\tconst readLength = Math.min(buffer.length, scanLimitBytes - scannedBytes);\n\t\t\tconst bytesRead = readSync(fd, buffer, 0, readLength, null);\n\t\t\tif (bytesRead === 0) break;\n\t\t\tscannedBytes += bytesRead;\n\t\t\tconst lines = (leftover + decoder.write(buffer.subarray(0, bytesRead))).split(\"\\n\");\n\t\t\tleftover = lines.pop() ?? \"\";\n\t\t\tfor (const line of lines) {\n\t\t\t\tconst suiteId = parseSuiteBindingLine(line);\n\t\t\t\tif (suiteId !== undefined) return suiteId;\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t} catch {\n\t\t// One unreadable file must not break the selector; treat it as unbound.\n\t\treturn undefined;\n\t} finally {\n\t\tcloseSync(fd);\n\t}\n}\n\nfunction parseSuiteBindingLine(line: string): string | undefined {\n\tconst trimmed = line.trim();\n\tif (trimmed.length === 0) return undefined;\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(trimmed);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n\tconst record = value as Record<string, unknown>;\n\tif (record.type !== \"custom\" || record.customType !== SUITE_SESSION_ENTRY_TYPE) return undefined;\n\tconst suiteId = (record.data as { suiteId?: unknown } | undefined)?.suiteId;\n\treturn typeof suiteId === \"string\" && suiteId.trim().length > 0 ? suiteId : undefined;\n}\n\nfunction shortenPath(path: string): string {\n\tconst home = os.homedir();\n\t// v8 ignore next -- shortenPath is only called with non-empty paths\n\tif (!path) return path;\n\tif (path.startsWith(home)) {\n\t\treturn `~${path.slice(home.length)}`;\n\t}\n\treturn path;\n}\n\nfunction formatSessionDate(date: Date): string {\n\tconst now = new Date();\n\tconst diffMs = now.getTime() - date.getTime();\n\tconst diffMins = Math.floor(diffMs / 60000);\n\tconst diffHours = Math.floor(diffMs / 3600000);\n\tconst diffDays = Math.floor(diffMs / 86400000);\n\n\tif (diffMins < 1) return \"now\";\n\tif (diffMins < 60) return `${diffMins}m`;\n\tif (diffHours < 24) return `${diffHours}h`;\n\tif (diffDays < 7) return `${diffDays}d`;\n\tif (diffDays < 30) return `${Math.floor(diffDays / 7)}w`;\n\tif (diffDays < 365) return `${Math.floor(diffDays / 30)}mo`;\n\treturn `${Math.floor(diffDays / 365)}y`;\n}\n\nfunction canonicalizePath(path: string | undefined): string | undefined {\n\tif (!path) return path;\n\treturn _canonicalizePath(path);\n}\n\nclass SessionSelectorHeader implements Component {\n\tprivate scope: SessionScope;\n\tprivate sortMode: SortMode;\n\tprivate nameFilter: NameFilter;\n\tprivate requestRender: () => void;\n\tprivate loading = false;\n\tprivate loadProgress: { loaded: number; total: number } | null = null;\n\tprivate showPath = false;\n\tprivate confirmingDeletePath: string | null = null;\n\tprivate statusMessage: { type: \"info\" | \"error\"; message: string } | null = null;\n\tprivate statusTimeout: ReturnType<typeof setTimeout> | null = null;\n\tprivate showRenameHint = false;\n\tprivate suiteTitle: string | undefined = undefined;\n\n\tconstructor(scope: SessionScope, sortMode: SortMode, nameFilter: NameFilter, requestRender: () => void) {\n\t\tthis.scope = scope;\n\t\tthis.sortMode = sortMode;\n\t\tthis.nameFilter = nameFilter;\n\t\tthis.requestRender = requestRender;\n\t}\n\n\t/**\n\t * Override the title with the suite dimension of the list (设计 §10.1).\n\t * Undefined restores the folder-scope-only title.\n\t */\n\tsetSuiteTitle(title: string | undefined): void {\n\t\tthis.suiteTitle = title;\n\t}\n\n\tsetScope(scope: SessionScope): void {\n\t\tthis.scope = scope;\n\t}\n\n\tsetSortMode(sortMode: SortMode): void {\n\t\tthis.sortMode = sortMode;\n\t}\n\n\tsetNameFilter(nameFilter: NameFilter): void {\n\t\tthis.nameFilter = nameFilter;\n\t}\n\n\tsetLoading(loading: boolean): void {\n\t\tthis.loading = loading;\n\t\t// Progress is scoped to the current load; clear whenever the loading state is set\n\t\tthis.loadProgress = null;\n\t}\n\n\tsetProgress(loaded: number, total: number): void {\n\t\tthis.loadProgress = { loaded, total };\n\t}\n\n\tsetShowPath(showPath: boolean): void {\n\t\tthis.showPath = showPath;\n\t}\n\n\tsetShowRenameHint(show: boolean): void {\n\t\tthis.showRenameHint = show;\n\t}\n\n\tsetConfirmingDeletePath(path: string | null): void {\n\t\tthis.confirmingDeletePath = path;\n\t}\n\n\tprivate clearStatusTimeout(): void {\n\t\tif (!this.statusTimeout) return;\n\t\tclearTimeout(this.statusTimeout);\n\t\tthis.statusTimeout = null;\n\t}\n\n\tsetStatusMessage(msg: { type: \"info\" | \"error\"; message: string } | null, autoHideMs?: number): void {\n\t\tthis.clearStatusTimeout();\n\t\tthis.statusMessage = msg;\n\t\tif (!msg || !autoHideMs) return;\n\n\t\tthis.statusTimeout = setTimeout(() => {\n\t\t\tthis.statusMessage = null;\n\t\t\tthis.statusTimeout = null;\n\t\t\tthis.requestRender();\n\t\t}, autoHideMs);\n\t}\n\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tconst title =\n\t\t\tthis.suiteTitle ??\n\t\t\t(this.scope === \"current\" ? t(\"Resume Session (Current Folder)\") : t(\"Resume Session (All)\"));\n\t\tconst leftText = theme.bold(title);\n\n\t\tconst sortLabel =\n\t\t\tthis.sortMode === \"threaded\" ? t(\"Threaded\") : this.sortMode === \"recent\" ? t(\"Recent\") : t(\"Fuzzy\");\n\t\tconst sortText = theme.fg(\"muted\", `${t(\"Sort:\")} `) + theme.fg(\"accent\", sortLabel);\n\n\t\tconst nameLabel = this.nameFilter === \"all\" ? t(\"All\") : t(\"Named\");\n\t\tconst nameText = theme.fg(\"muted\", `${t(\"Name:\")} `) + theme.fg(\"accent\", nameLabel);\n\n\t\tlet scopeText: string;\n\t\tif (this.loading) {\n\t\t\tconst progressText = this.loadProgress ? `${this.loadProgress.loaded}/${this.loadProgress.total}` : \"...\";\n\t\t\tscopeText = `${theme.fg(\"muted\", `${t(\"○ Current Folder\")} | `)}${theme.fg(\"accent\", t(\"Loading {progress}\", { progress: progressText }))}`;\n\t\t} else if (this.scope === \"current\") {\n\t\t\tscopeText = `${theme.fg(\"accent\", t(\"◉ Current Folder\"))}${theme.fg(\"muted\", ` | ${t(\"○ All\")}`)}`;\n\t\t} else {\n\t\t\tscopeText = `${theme.fg(\"muted\", `${t(\"○ Current Folder\")} | `)}${theme.fg(\"accent\", t(\"◉ All\"))}`;\n\t\t}\n\n\t\tconst rightText = truncateToWidth(`${scopeText} ${nameText} ${sortText}`, width, \"\");\n\t\tconst availableLeft = Math.max(0, width - visibleWidth(rightText) - 1);\n\t\tconst left = truncateToWidth(leftText, availableLeft, \"\");\n\t\tconst spacing = Math.max(0, width - visibleWidth(left) - visibleWidth(rightText));\n\n\t\t// Build hint lines - changes based on state (all branches truncate to width)\n\t\tlet hintLine1: string;\n\t\tlet hintLine2: string;\n\t\tif (this.confirmingDeletePath !== null) {\n\t\t\tconst confirmHint = t(\"Delete session? {confirm} · {cancel}\", {\n\t\t\t\tconfirm: keyHint(\"tui.select.confirm\", t(\"confirm\")),\n\t\t\t\tcancel: keyHint(\"tui.select.cancel\", t(\"cancel\")),\n\t\t\t});\n\t\t\thintLine1 = theme.fg(\"error\", truncateToWidth(confirmHint, width, \"…\"));\n\t\t\thintLine2 = \"\";\n\t\t} else if (this.statusMessage) {\n\t\t\tconst color = this.statusMessage.type === \"error\" ? \"error\" : \"accent\";\n\t\t\thintLine1 = theme.fg(color, truncateToWidth(this.statusMessage.message, width, \"…\"));\n\t\t\thintLine2 = \"\";\n\t\t} else {\n\t\t\tconst pathState = this.showPath ? t(\"path (on)\") : t(\"path (off)\");\n\t\t\tconst sep = theme.fg(\"muted\", \" · \");\n\t\t\tconst hint1 =\n\t\t\t\tkeyHint(\"tui.input.tab\", t(\"scope\")) + sep + theme.fg(\"muted\", t('re:<pattern> regex · \"phrase\" exact'));\n\t\t\tconst hint2Parts = [\n\t\t\t\tkeyHint(\"app.session.toggleSort\", t(\"sort\")),\n\t\t\t\tkeyHint(\"app.session.toggleNamedFilter\", t(\"named\")),\n\t\t\t\tkeyHint(\"app.session.delete\", t(\"delete\")),\n\t\t\t\tkeyHint(\"app.session.togglePath\", pathState),\n\t\t\t];\n\t\t\tif (this.showRenameHint) {\n\t\t\t\thint2Parts.push(keyHint(\"app.session.rename\", t(\"rename\")));\n\t\t\t}\n\t\t\tconst hint2 = hint2Parts.join(sep);\n\t\t\thintLine1 = truncateToWidth(hint1, width, \"…\");\n\t\t\thintLine2 = truncateToWidth(hint2, width, \"…\");\n\t\t}\n\n\t\treturn [`${left}${\" \".repeat(spacing)}${rightText}`, hintLine1, hintLine2];\n\t}\n}\n\n/** A session tree node for hierarchical display */\ninterface SessionTreeNode {\n\tsession: SessionInfo;\n\tchildren: SessionTreeNode[];\n\tlatestActivity: number;\n}\n\n/**\n * A row of the flattened session list: either a session tree node or the\n * explicit \"show all / show current suite\" toggle action (设计 §10.1).\n */\ntype FlatSessionNode =\n\t| { kind: \"session\"; session: SessionInfo; depth: number; isLast: boolean; ancestorContinues: boolean[] }\n\t| { kind: \"suite-toggle\"; target: SuiteFilter };\n\n/**\n * Build a tree structure from sessions based on parentSessionPath.\n * Returns root nodes sorted by modified date (descending).\n */\nfunction buildSessionTree(sessions: SessionInfo[]): SessionTreeNode[] {\n\tconst byPath = new Map<string, SessionTreeNode>();\n\n\tfor (const session of sessions) {\n\t\tconst sessionPath = canonicalizePath(session.path) ?? session.path;\n\t\tbyPath.set(sessionPath, { session, children: [], latestActivity: session.modified.getTime() });\n\t}\n\n\tconst roots: SessionTreeNode[] = [];\n\n\tfor (const session of sessions) {\n\t\tconst sessionPath = canonicalizePath(session.path) ?? session.path;\n\t\tconst node = byPath.get(sessionPath)!;\n\t\tconst parentPath = canonicalizePath(session.parentSessionPath);\n\n\t\tif (parentPath && byPath.has(parentPath)) {\n\t\t\tbyPath.get(parentPath)!.children.push(node);\n\t\t} else {\n\t\t\troots.push(node);\n\t\t}\n\t}\n\n\tconst updateLatestActivity = (node: SessionTreeNode): number => {\n\t\tlet latestActivity = node.session.modified.getTime();\n\t\tfor (const child of node.children) {\n\t\t\tlatestActivity = Math.max(latestActivity, updateLatestActivity(child));\n\t\t}\n\t\tnode.latestActivity = latestActivity;\n\t\treturn latestActivity;\n\t};\n\n\tfor (const root of roots) {\n\t\tupdateLatestActivity(root);\n\t}\n\n\t// Sort children and roots by latest activity in each subtree (descending)\n\tconst sortNodes = (nodes: SessionTreeNode[]): void => {\n\t\tnodes.sort((a, b) => b.latestActivity - a.latestActivity);\n\t\tfor (const node of nodes) {\n\t\t\tsortNodes(node.children);\n\t\t}\n\t};\n\tsortNodes(roots);\n\n\treturn roots;\n}\n\n/**\n * Flatten tree into display list with tree structure metadata.\n */\nfunction flattenSessionTree(roots: SessionTreeNode[]): FlatSessionNode[] {\n\tconst result: FlatSessionNode[] = [];\n\n\tconst walk = (node: SessionTreeNode, depth: number, ancestorContinues: boolean[], isLast: boolean): void => {\n\t\tresult.push({ kind: \"session\", session: node.session, depth, isLast, ancestorContinues });\n\n\t\tfor (let i = 0; i < node.children.length; i++) {\n\t\t\tconst childIsLast = i === node.children.length - 1;\n\t\t\t// Only show continuation line for non-root ancestors\n\t\t\tconst continues = depth > 0 ? !isLast : false;\n\t\t\twalk(node.children[i]!, depth + 1, [...ancestorContinues, continues], childIsLast);\n\t\t}\n\t};\n\n\tfor (let i = 0; i < roots.length; i++) {\n\t\twalk(roots[i]!, 0, [], i === roots.length - 1);\n\t}\n\n\treturn result;\n}\n\n/**\n * Custom session list component with multi-line items and search\n */\nclass SessionList implements Component, Focusable {\n\tpublic getSelectedSessionPath(): string | undefined {\n\t\tconst selected = this.filteredSessions[this.selectedIndex];\n\t\treturn selected?.kind === \"session\" ? selected.session.path : undefined;\n\t}\n\tprivate allSessions: SessionInfo[] = [];\n\tprivate filteredSessions: FlatSessionNode[] = [];\n\tprivate selectedIndex: number = 0;\n\tprivate selectionTouched = false;\n\tprivate searchInput: Input;\n\tprivate showCwd = false;\n\tprivate sortMode: SortMode = \"threaded\";\n\tprivate nameFilter: NameFilter = \"all\";\n\tprivate keybindings: KeybindingsManager;\n\tprivate showPath = false;\n\tprivate confirmingDeletePath: string | null = null;\n\tprivate currentSessionCanonicalPath?: string;\n\t/** Suite dimension state (设计 §10.1); inert until a suite context is injected. */\n\tprivate suiteFilter: SuiteFilter = \"current\";\n\tprivate currentSuiteId?: string;\n\tprivate getSessionSuiteId: SessionSuiteIdReader | undefined = undefined;\n\tprivate suiteIdCache = new Map<string, string | undefined>();\n\tpublic onSelect?: (sessionPath: string) => void;\n\tpublic onCancel?: () => void;\n\tpublic onExit: () => void = () => {};\n\tpublic onToggleScope?: () => void;\n\tpublic onToggleSuiteFilter?: () => void;\n\tpublic onToggleSort?: () => void;\n\tpublic onToggleNameFilter?: () => void;\n\tpublic onTogglePath?: (showPath: boolean) => void;\n\tpublic onDeleteConfirmationChange?: (path: string | null) => void;\n\tpublic onDeleteSession?: (sessionPath: string) => Promise<void>;\n\tpublic onRenameSession?: (sessionPath: string) => void;\n\tpublic onError?: (message: string) => void;\n\tprivate maxVisible: number = 10; // Max sessions visible (one line each)\n\n\t// Focusable implementation - propagate to searchInput for IME cursor positioning\n\tprivate _focused = false;\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\n\tconstructor(\n\t\tsessions: SessionInfo[],\n\t\tshowCwd: boolean,\n\t\tsortMode: SortMode,\n\t\tnameFilter: NameFilter,\n\t\tkeybindings: KeybindingsManager,\n\t\tcurrentSessionFilePath?: string,\n\t) {\n\t\tthis.allSessions = sessions;\n\t\tthis.filteredSessions = [];\n\t\tthis.searchInput = new Input();\n\t\tthis.showCwd = showCwd;\n\t\tthis.sortMode = sortMode;\n\t\tthis.nameFilter = nameFilter;\n\t\tthis.keybindings = keybindings;\n\t\tthis.currentSessionCanonicalPath = canonicalizePath(currentSessionFilePath);\n\t\tthis.filterSessions(\"\");\n\n\t\t// Handle Enter in search input - select current item\n\t\tthis.searchInput.onSubmit = () => {\n\t\t\t// v8 ignore next -- the search input never receives the confirm key; the list intercepts it\n\t\t\tconst selected = this.filteredSessions[this.selectedIndex];\n\t\t\t// v8 ignore next -- the search input never receives the confirm key; the list intercepts it\n\t\t\tif (selected && selected.kind === \"session\" && this.onSelect) {\n\t\t\t\tthis.onSelect(selected.session.path);\n\t\t\t}\n\t\t};\n\t}\n\n\tsetSortMode(sortMode: SortMode): void {\n\t\tthis.sortMode = sortMode;\n\t\tthis.filterSessions(this.searchInput.getValue());\n\t}\n\n\tsetNameFilter(nameFilter: NameFilter): void {\n\t\tthis.nameFilter = nameFilter;\n\t\tthis.filterSessions(this.searchInput.getValue());\n\t}\n\n\tsetSessions(sessions: SessionInfo[], showCwd: boolean): void {\n\t\tconst selectedPath = this.selectionTouched ? this.getSelectedSessionPath() : undefined;\n\t\tthis.allSessions = sessions;\n\t\tthis.showCwd = showCwd;\n\t\tthis.filterSessions(this.searchInput.getValue());\n\t\tif (!this.selectionTouched) {\n\t\t\tthis.selectedIndex = 0;\n\t\t} else if (selectedPath) {\n\t\t\tconst selectedIndex = this.filteredSessions.findIndex(\n\t\t\t\t(node) => node.kind === \"session\" && node.session.path === selectedPath,\n\t\t\t);\n\t\t\tif (selectedIndex >= 0) this.selectedIndex = selectedIndex;\n\t\t}\n\t}\n\n\t/**\n\t * Inject the suite dimension (设计 §10.1): \"current\" keeps only sessions\n\t * bound to the same suite as the current session (unbound matches unbound,\n\t * so legacy sessions stay visible to legacy sessions); \"all\" is reached\n\t * only through the explicit list toggle entry.\n\t */\n\tsetSuiteFilterContext(options: SessionSuiteFilterOptions): void {\n\t\tthis.currentSuiteId = options.currentSuiteId;\n\t\tthis.getSessionSuiteId = options.getSessionSuiteId;\n\t\tthis.filterSessions(this.searchInput.getValue());\n\t}\n\n\tsetSuiteFilter(filter: SuiteFilter): void {\n\t\tthis.suiteFilter = filter;\n\t\tthis.filterSessions(this.searchInput.getValue());\n\t}\n\n\tgetSuiteFilter(): SuiteFilter {\n\t\treturn this.suiteFilter;\n\t}\n\n\tprivate hasSuiteFilterContext(): boolean {\n\t\treturn this.getSessionSuiteId !== undefined;\n\t}\n\n\t/** Cached suite lookup; reader results are stable per session file. */\n\tprivate suiteIdOf(session: SessionInfo): string | undefined {\n\t\tconst reader = this.getSessionSuiteId;\n\t\tif (!reader) return undefined;\n\t\tif (this.suiteIdCache.has(session.path)) return this.suiteIdCache.get(session.path);\n\t\tconst suiteId = reader(session);\n\t\tthis.suiteIdCache.set(session.path, suiteId);\n\t\treturn suiteId;\n\t}\n\n\tprivate applySuiteFilter(sessions: SessionInfo[]): SessionInfo[] {\n\t\tif (this.suiteFilter === \"all\" || !this.hasSuiteFilterContext()) return sessions;\n\t\treturn sessions.filter((session) => this.suiteIdOf(session) === this.currentSuiteId);\n\t}\n\n\tprivate filterSessions(query: string): void {\n\t\tconst trimmed = query.trim();\n\t\tconst suiteFiltered = this.applySuiteFilter(this.allSessions);\n\t\tconst nameFiltered =\n\t\t\tthis.nameFilter === \"all\" ? suiteFiltered : suiteFiltered.filter((session) => hasSessionName(session));\n\n\t\tif (this.sortMode === \"threaded\" && !trimmed) {\n\t\t\t// Threaded mode without search: show tree structure\n\t\t\tconst roots = buildSessionTree(nameFiltered);\n\t\t\tthis.filteredSessions = flattenSessionTree(roots);\n\t\t} else {\n\t\t\t// Other modes or with search: flat list\n\t\t\tconst filtered = filterAndSortSessions(nameFiltered, query, this.sortMode, \"all\");\n\t\t\tthis.filteredSessions = filtered.map((session) => ({\n\t\t\t\tkind: \"session\" as const,\n\t\t\t\tsession,\n\t\t\t\tdepth: 0,\n\t\t\t\tisLast: true,\n\t\t\t\tancestorContinues: [],\n\t\t\t}));\n\t\t}\n\t\t// The explicit \"show all suites / current suite\" action is offered as the\n\t\t// first row (设计 §10.1); hidden while searching so queries stay clean.\n\t\tif (this.hasSuiteFilterContext() && !trimmed) {\n\t\t\tthis.filteredSessions = [\n\t\t\t\t{ kind: \"suite-toggle\", target: this.suiteFilter === \"current\" ? \"all\" : \"current\" },\n\t\t\t\t...this.filteredSessions,\n\t\t\t];\n\t\t}\n\t\tthis.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredSessions.length - 1));\n\t}\n\n\tprivate setConfirmingDeletePath(path: string | null): void {\n\t\tthis.confirmingDeletePath = path;\n\t\tthis.onDeleteConfirmationChange?.(path);\n\t}\n\n\tprivate startDeleteConfirmationForSelectedSession(): void {\n\t\tconst selected = this.filteredSessions[this.selectedIndex];\n\t\t// The suite toggle row is an action, not a deletable session.\n\t\tif (!selected || selected.kind !== \"session\") return;\n\n\t\t// Prevent deleting current session\n\t\tif (this.isCurrentSessionPath(selected.session.path)) {\n\t\t\tthis.onError?.(t(\"Cannot delete the currently active session\"));\n\t\t\treturn;\n\t\t}\n\n\t\tthis.setConfirmingDeletePath(selected.session.path);\n\t}\n\n\tprivate isCurrentSessionPath(path: string): boolean {\n\t\tif (!this.currentSessionCanonicalPath) return false;\n\t\treturn (canonicalizePath(path) ?? path) === this.currentSessionCanonicalPath;\n\t}\n\n\tinvalidate(): void {}\n\n\trender(width: number): string[] {\n\t\tconst lines: string[] = [];\n\n\t\t// Render search input\n\t\tlines.push(...this.searchInput.render(width));\n\t\tlines.push(\"\"); // Blank line after search\n\n\t\tif (this.filteredSessions.length === 0) {\n\t\t\tlet emptyMessage: string;\n\t\t\tif (this.nameFilter === \"named\") {\n\t\t\t\tconst toggleKey = keyText(\"app.session.toggleNamedFilter\");\n\t\t\t\tif (this.showCwd) {\n\t\t\t\t\temptyMessage = t(\"No named sessions found. Press {key} to show all.\", { key: toggleKey });\n\t\t\t\t} else {\n\t\t\t\t\temptyMessage = t(\"No named sessions in current folder. Press {key} to show all, or Tab to view all.\", {\n\t\t\t\t\t\tkey: toggleKey,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else if (this.showCwd) {\n\t\t\t\t// \"All\" scope - no sessions anywhere that match filter\n\t\t\t\temptyMessage = t(\"No sessions found\");\n\t\t\t} else {\n\t\t\t\t// \"Current folder\" scope - hint to try \"all\"\n\t\t\t\temptyMessage = t(\"No sessions in current folder. Press Tab to view all.\");\n\t\t\t}\n\t\t\tlines.push(theme.fg(\"muted\", truncateToWidth(` ${emptyMessage}`, width, \"…\")));\n\t\t\treturn lines;\n\t\t}\n\n\t\t// Calculate visible range with scrolling\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredSessions.length - this.maxVisible),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + this.maxVisible, this.filteredSessions.length);\n\n\t\t// Render visible sessions (one line each with tree structure)\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst node = this.filteredSessions[i]!;\n\t\t\tconst isSelected = i === this.selectedIndex;\n\t\t\tif (node.kind === \"suite-toggle\") {\n\t\t\t\tconst label =\n\t\t\t\t\tnode.target === \"all\" ? t(\"Show sessions from all suites\") : t(\"Show current suite sessions only\");\n\t\t\t\tconst cursor = isSelected ? theme.fg(\"accent\", \"› \") : \" \";\n\t\t\t\tlet toggleLine = cursor + theme.fg(\"muted\", `· ${label}`);\n\t\t\t\tif (isSelected) {\n\t\t\t\t\ttoggleLine = theme.bg(\"selectedBg\", theme.bold(toggleLine));\n\t\t\t\t}\n\t\t\t\tlines.push(truncateToWidth(toggleLine, width));\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst session = node.session;\n\t\t\tconst isConfirmingDelete = session.path === this.confirmingDeletePath;\n\t\t\tconst isCurrent = this.isCurrentSessionPath(session.path);\n\n\t\t\t// Build tree prefix\n\t\t\tconst prefix = this.buildTreePrefix(node);\n\n\t\t\t// Session display text (name or first message)\n\t\t\tconst hasName = !!session.name;\n\t\t\tconst displayText = session.name ?? session.firstMessage;\n\t\t\tconst normalizedMessage = displayText.replace(/[\\x00-\\x1f\\x7f]/g, \" \").trim();\n\n\t\t\t// Right side: message count and age\n\t\t\tconst age = formatSessionDate(session.modified);\n\t\t\tconst msgCount = String(session.messageCount);\n\t\t\tlet rightPart = `${msgCount} ${age}`;\n\t\t\tif (this.showCwd && session.cwd) {\n\t\t\t\trightPart = `${shortenPath(session.cwd)} ${rightPart}`;\n\t\t\t}\n\t\t\tif (this.showPath) {\n\t\t\t\trightPart = `${shortenPath(session.path)} ${rightPart}`;\n\t\t\t}\n\n\t\t\t// Cursor\n\t\t\tconst cursor = isSelected ? theme.fg(\"accent\", \"› \") : \" \";\n\n\t\t\t// Calculate available width for message\n\t\t\tconst prefixWidth = visibleWidth(prefix);\n\t\t\tconst rightWidth = visibleWidth(rightPart) + 2; // +2 for spacing\n\t\t\tconst availableForMsg = width - 2 - prefixWidth - rightWidth; // -2 for cursor\n\n\t\t\tconst truncatedMsg = truncateToWidth(normalizedMessage, Math.max(10, availableForMsg), \"…\");\n\n\t\t\t// Style message\n\t\t\tlet messageColor: \"error\" | \"warning\" | \"accent\" | null = null;\n\t\t\tif (isConfirmingDelete) {\n\t\t\t\tmessageColor = \"error\";\n\t\t\t} else if (isCurrent) {\n\t\t\t\tmessageColor = \"accent\";\n\t\t\t} else if (hasName) {\n\t\t\t\tmessageColor = \"warning\";\n\t\t\t}\n\t\t\tlet styledMsg = messageColor ? theme.fg(messageColor, truncatedMsg) : truncatedMsg;\n\t\t\tif (isSelected) {\n\t\t\t\tstyledMsg = theme.bold(styledMsg);\n\t\t\t}\n\n\t\t\t// Build line\n\t\t\tconst leftPart = cursor + theme.fg(\"dim\", prefix) + styledMsg;\n\t\t\tconst leftWidth = visibleWidth(leftPart);\n\t\t\tconst spacing = Math.max(1, width - leftWidth - visibleWidth(rightPart));\n\t\t\tconst styledRight = theme.fg(isConfirmingDelete ? \"error\" : \"dim\", rightPart);\n\n\t\t\tlet line = leftPart + \" \".repeat(spacing) + styledRight;\n\t\t\tif (isSelected) {\n\t\t\t\tline = theme.bg(\"selectedBg\", line);\n\t\t\t}\n\t\t\tlines.push(truncateToWidth(line, width));\n\t\t}\n\n\t\t// Add scroll indicator if needed\n\t\tif (startIndex > 0 || endIndex < this.filteredSessions.length) {\n\t\t\tconst scrollText = ` (${this.selectedIndex + 1}/${this.filteredSessions.length})`;\n\t\t\tconst scrollInfo = theme.fg(\"muted\", truncateToWidth(scrollText, width, \"\"));\n\t\t\tlines.push(scrollInfo);\n\t\t}\n\n\t\treturn lines;\n\t}\n\n\tprivate buildTreePrefix(node: Extract<FlatSessionNode, { kind: \"session\" }>): string {\n\t\tif (node.depth === 0) {\n\t\t\treturn \"\";\n\t\t}\n\n\t\tconst parts = node.ancestorContinues.map((continues) => (continues ? \"│ \" : \" \"));\n\t\tconst branch = node.isLast ? \"└─ \" : \"├─ \";\n\t\treturn parts.join(\"\") + branch;\n\t}\n\n\thandleInput(keyData: string): void {\n\t\tconst kb = getKeybindings();\n\n\t\t// Handle delete confirmation state first - intercept all keys\n\t\tif (this.confirmingDeletePath !== null) {\n\t\t\tif (kb.matches(keyData, \"tui.select.confirm\")) {\n\t\t\t\tconst pathToDelete = this.confirmingDeletePath;\n\t\t\t\tthis.setConfirmingDeletePath(null);\n\t\t\t\tvoid this.onDeleteSession?.(pathToDelete);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (kb.matches(keyData, \"tui.select.cancel\")) {\n\t\t\t\tthis.setConfirmingDeletePath(null);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// Ignore all other keys while confirming\n\t\t\treturn;\n\t\t}\n\n\t\tif (kb.matches(keyData, \"tui.input.tab\")) {\n\t\t\t// v8 ignore next -- onToggleScope is always assigned by SessionSelectorComponent\n\t\t\tif (this.onToggleScope) {\n\t\t\t\tthis.onToggleScope();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (kb.matches(keyData, \"app.session.toggleSort\")) {\n\t\t\tthis.onToggleSort?.();\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.keybindings.matches(keyData, \"app.session.toggleNamedFilter\")) {\n\t\t\tthis.onToggleNameFilter?.();\n\t\t\treturn;\n\t\t}\n\n\t\t// Ctrl+P: toggle path display\n\t\tif (kb.matches(keyData, \"app.session.togglePath\")) {\n\t\t\tthis.showPath = !this.showPath;\n\t\t\tthis.onTogglePath?.(this.showPath);\n\t\t\treturn;\n\t\t}\n\n\t\t// Ctrl+D: initiate delete confirmation (useful on terminals that don't distinguish Ctrl+Backspace from Backspace)\n\t\tif (kb.matches(keyData, \"app.session.delete\")) {\n\t\t\tthis.startDeleteConfirmationForSelectedSession();\n\t\t\treturn;\n\t\t}\n\n\t\t// Rename selected session\n\t\tif (kb.matches(keyData, \"app.session.rename\")) {\n\t\t\tconst selected = this.filteredSessions[this.selectedIndex];\n\t\t\tif (selected && selected.kind === \"session\") {\n\t\t\t\tthis.onRenameSession?.(selected.session.path);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Ctrl+Backspace: non-invasive convenience alias for delete\n\t\t// Only triggers deletion when the query is empty; otherwise it is forwarded to the input\n\t\tif (kb.matches(keyData, \"app.session.deleteNoninvasive\")) {\n\t\t\tif (this.searchInput.getValue().length > 0) {\n\t\t\t\tthis.searchInput.handleInput(keyData);\n\t\t\t\tthis.filterSessions(this.searchInput.getValue());\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.startDeleteConfirmationForSelectedSession();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.selectionTouched = true;\n\t\t// Up arrow\n\t\tif (kb.matches(keyData, \"tui.select.up\")) {\n\t\t\tthis.selectedIndex = Math.max(0, this.selectedIndex - 1);\n\t\t}\n\t\t// Down arrow\n\t\telse if (kb.matches(keyData, \"tui.select.down\")) {\n\t\t\tthis.selectedIndex = Math.min(this.filteredSessions.length - 1, this.selectedIndex + 1);\n\t\t}\n\t\t// Page up - jump up by maxVisible items\n\t\telse if (kb.matches(keyData, \"tui.select.pageUp\")) {\n\t\t\tthis.selectedIndex = Math.max(0, this.selectedIndex - this.maxVisible);\n\t\t}\n\t\t// Page down - jump down by maxVisible items\n\t\telse if (kb.matches(keyData, \"tui.select.pageDown\")) {\n\t\t\tthis.selectedIndex = Math.min(this.filteredSessions.length - 1, this.selectedIndex + this.maxVisible);\n\t\t}\n\t\t// Enter\n\t\telse if (kb.matches(keyData, \"tui.select.confirm\")) {\n\t\t\tconst selected = this.filteredSessions[this.selectedIndex];\n\t\t\tif (selected && selected.kind === \"suite-toggle\") {\n\t\t\t\t// Explicit \"show all / current suite\" action (设计 §10.1).\n\t\t\t\tthis.onToggleSuiteFilter?.();\n\t\t\t} else if (selected && selected.kind === \"session\" && this.onSelect) {\n\t\t\t\tthis.onSelect(selected.session.path);\n\t\t\t}\n\t\t}\n\t\t// Escape - cancel\n\t\telse if (kb.matches(keyData, \"tui.select.cancel\")) {\n\t\t\t// v8 ignore next -- onCancel is always assigned by SessionSelectorComponent\n\t\t\tif (this.onCancel) {\n\t\t\t\tthis.onCancel();\n\t\t\t}\n\t\t}\n\t\t// Pass everything else to search input\n\t\telse {\n\t\t\tthis.searchInput.handleInput(keyData);\n\t\t\tthis.filterSessions(this.searchInput.getValue());\n\t\t}\n\t}\n}\n\ntype SessionsLoader = (onProgress?: SessionListProgress, signal?: AbortSignal) => Promise<SessionInfo[]>;\n\n/**\n * Delete a session file, trying the `trash` CLI first, then falling back to unlink\n */\nasync function deleteSessionFile(\n\tsessionPath: string,\n): Promise<{ ok: boolean; method: \"trash\" | \"unlink\"; error?: string }> {\n\t// Try `trash` first (if installed)\n\tconst trashArgs = sessionPath.startsWith(\"-\") ? [\"--\", sessionPath] : [sessionPath];\n\tconst trashResult = spawnSync(\"trash\", trashArgs, { encoding: \"utf-8\" });\n\n\tconst getTrashErrorHint = (): string | null => {\n\t\tconst parts: string[] = [];\n\t\tif (trashResult.error) {\n\t\t\tparts.push(trashResult.error.message);\n\t\t}\n\t\tconst stderr = trashResult.stderr?.trim();\n\t\tif (stderr) {\n\t\t\t// v8 ignore next -- split always returns at least one element\n\t\t\tparts.push(stderr.split(\"\\n\")[0] ?? stderr);\n\t\t}\n\t\tif (parts.length === 0) return null;\n\t\treturn `trash: ${parts.join(\" · \").slice(0, 200)}`;\n\t};\n\n\t// If trash reports success, or the file is gone afterwards, treat it as successful\n\tif (trashResult.status === 0 || !existsSync(sessionPath)) {\n\t\treturn { ok: true, method: \"trash\" };\n\t}\n\n\t// Fallback to permanent deletion\n\ttry {\n\t\tawait unlink(sessionPath);\n\t\treturn { ok: true, method: \"unlink\" };\n\t} catch (err) {\n\t\t// v8 ignore next -- unlink always rejects with Error instances\n\t\tconst unlinkError = err instanceof Error ? err.message : String(err);\n\t\tconst trashErrorHint = getTrashErrorHint();\n\t\tconst error = trashErrorHint ? `${unlinkError} (${trashErrorHint})` : unlinkError;\n\t\treturn { ok: false, method: \"unlink\", error };\n\t}\n}\n\n/**\n * Component that renders a session selector\n */\nexport class SessionSelectorComponent extends Container implements Focusable {\n\thandleInput(data: string): void {\n\t\tif (this.mode === \"rename\") {\n\t\t\tconst kb = getKeybindings();\n\t\t\tif (kb.matches(data, \"tui.select.cancel\")) {\n\t\t\t\tthis.exitRenameMode();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.renameInput.handleInput(data);\n\t\t\treturn;\n\t\t}\n\n\t\tthis.sessionList.handleInput(data);\n\t}\n\n\tprivate canRename = true;\n\tprivate sessionList: SessionList;\n\tprivate header: SessionSelectorHeader;\n\tprivate keybindings: KeybindingsManager;\n\tprivate scope: SessionScope = \"current\";\n\tprivate sortMode: SortMode = \"threaded\";\n\tprivate nameFilter: NameFilter = \"all\";\n\tprivate suiteFilterOptions: SessionSuiteFilterOptions | undefined = undefined;\n\tprivate suiteFilter: SuiteFilter = \"current\";\n\tprivate currentSessions: SessionInfo[] | null = null;\n\tprivate allSessions: SessionInfo[] | null = null;\n\tprivate currentSessionsLoader: SessionsLoader;\n\tprivate allSessionsLoader: SessionsLoader;\n\tprivate requestRender: () => void;\n\tprivate renameSession?: (sessionPath: string, currentName: string | undefined) => Promise<void>;\n\tprivate currentLoad: AbortController | null = null;\n\tprivate allLoad: AbortController | null = null;\n\n\tprivate mode: \"list\" | \"rename\" = \"list\";\n\tprivate renameInput = new Input();\n\tprivate renameTargetPath: string | null = null;\n\n\t// Focusable implementation - propagate to sessionList for IME cursor positioning\n\tprivate _focused = false;\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.sessionList.focused = value;\n\t\tthis.renameInput.focused = value;\n\t\tif (value && this.mode === \"rename\") {\n\t\t\tthis.renameInput.focused = true;\n\t\t}\n\t}\n\n\tprivate buildBaseLayout(content: Component, options?: { showHeader?: boolean }): void {\n\t\tthis.clear();\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder((s) => theme.fg(\"accent\", s)));\n\t\tthis.addChild(new Spacer(1));\n\t\tif (options?.showHeader ?? true) {\n\t\t\tthis.addChild(this.header);\n\t\t\tthis.addChild(new Spacer(1));\n\t\t}\n\t\tthis.addChild(content);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder((s) => theme.fg(\"accent\", s)));\n\t}\n\n\tconstructor(\n\t\tcurrentSessionsLoader: SessionsLoader,\n\t\tallSessionsLoader: SessionsLoader,\n\t\tonSelect: (sessionPath: string) => void,\n\t\tonCancel: () => void,\n\t\tonExit: () => void,\n\t\trequestRender: () => void,\n\t\toptions?: {\n\t\t\trenameSession?: (sessionPath: string, currentName: string | undefined) => Promise<void>;\n\t\t\tshowRenameHint?: boolean;\n\t\t\tkeybindings?: KeybindingsManager;\n\t\t\t/** Suite dimension of the list (设计 §10.1); omit to keep the unfiltered folder views. */\n\t\t\tsuiteFilter?: SessionSuiteFilterOptions;\n\t\t},\n\t\tcurrentSessionFilePath?: string,\n\t) {\n\t\tsuper();\n\t\tthis.keybindings = options?.keybindings ?? KeybindingsManager.create();\n\t\tthis.currentSessionsLoader = currentSessionsLoader;\n\t\tthis.allSessionsLoader = allSessionsLoader;\n\t\tthis.requestRender = requestRender;\n\t\tthis.suiteFilterOptions = options?.suiteFilter;\n\t\tthis.header = new SessionSelectorHeader(this.scope, this.sortMode, this.nameFilter, this.requestRender);\n\t\tif (this.suiteFilterOptions) {\n\t\t\tthis.header.setSuiteTitle(this.suiteTitle());\n\t\t}\n\t\tconst renameSession = options?.renameSession;\n\t\tthis.renameSession = renameSession;\n\t\tthis.canRename = !!renameSession;\n\t\tthis.header.setShowRenameHint(options?.showRenameHint ?? this.canRename);\n\n\t\t// Create session list (starts empty, will be populated after load)\n\t\tthis.sessionList = new SessionList(\n\t\t\t[],\n\t\t\tfalse,\n\t\t\tthis.sortMode,\n\t\t\tthis.nameFilter,\n\t\t\tthis.keybindings,\n\t\t\tcurrentSessionFilePath,\n\t\t);\n\t\tif (this.suiteFilterOptions) {\n\t\t\tthis.sessionList.setSuiteFilterContext(this.suiteFilterOptions);\n\t\t}\n\t\tthis.sessionList.onToggleSuiteFilter = () => this.toggleSuiteFilter();\n\n\t\tthis.buildBaseLayout(this.sessionList);\n\n\t\tthis.renameInput.onSubmit = (value) => {\n\t\t\tvoid this.confirmRename(value);\n\t\t};\n\n\t\t// Ensure header status timeouts are cleared when leaving the selector\n\t\tconst clearStatusMessage = () => this.header.setStatusMessage(null);\n\t\tthis.sessionList.onSelect = (sessionPath) => {\n\t\t\tclearStatusMessage();\n\t\t\tthis.cancelLoads();\n\t\t\tonSelect(sessionPath);\n\t\t};\n\t\tthis.sessionList.onCancel = () => {\n\t\t\tclearStatusMessage();\n\t\t\tthis.cancelLoads();\n\t\t\tonCancel();\n\t\t};\n\t\tthis.sessionList.onExit = () => {\n\t\t\tclearStatusMessage();\n\t\t\tthis.cancelLoads();\n\t\t\tonExit();\n\t\t};\n\t\tthis.sessionList.onToggleScope = () => this.toggleScope();\n\t\tthis.sessionList.onToggleSort = () => this.toggleSortMode();\n\t\tthis.sessionList.onToggleNameFilter = () => this.toggleNameFilter();\n\t\tthis.sessionList.onRenameSession = (sessionPath) => {\n\t\t\tif (!renameSession) return;\n\t\t\t// v8 ignore next -- rename requires a visible selection, impossible while the current load is pending\n\t\t\tif (this.scope === \"current\" ? this.currentLoad : this.allLoad) return;\n\n\t\t\tconst sessions = this.scope === \"all\" ? (this.allSessions ?? []) : (this.currentSessions ?? []);\n\t\t\tconst session = sessions.find((s) => s.path === sessionPath);\n\t\t\tthis.enterRenameMode(sessionPath, session?.name);\n\t\t};\n\n\t\t// Sync list events to header\n\t\tthis.sessionList.onTogglePath = (showPath) => {\n\t\t\tthis.header.setShowPath(showPath);\n\t\t\tthis.requestRender();\n\t\t};\n\t\tthis.sessionList.onDeleteConfirmationChange = (path) => {\n\t\t\tthis.header.setConfirmingDeletePath(path);\n\t\t\tthis.requestRender();\n\t\t};\n\t\tthis.sessionList.onError = (msg) => {\n\t\t\tthis.header.setStatusMessage({ type: \"error\", message: msg }, 3000);\n\t\t\tthis.requestRender();\n\t\t};\n\n\t\t// Handle session deletion\n\t\tthis.sessionList.onDeleteSession = async (sessionPath: string) => {\n\t\t\tconst result = await deleteSessionFile(sessionPath);\n\n\t\t\tif (result.ok) {\n\t\t\t\t// 删除不经 SessionManager(设计 docs/design/会话索引.md §4):成功后同步\n\t\t\t\t// 移除索引条目;失败吞掉,对账会在下次读取自愈。\n\t\t\t\ttry {\n\t\t\t\t\tremoveSessionFromIndex(sessionPath);\n\t\t\t\t} catch {\n\t\t\t\t\t// Index maintenance must never break the delete flow.\n\t\t\t\t}\n\t\t\t\tif (this.currentSessions) {\n\t\t\t\t\tthis.currentSessions = this.currentSessions.filter((s) => s.path !== sessionPath);\n\t\t\t\t}\n\t\t\t\tif (this.allSessions) {\n\t\t\t\t\tthis.allSessions = this.allSessions.filter((s) => s.path !== sessionPath);\n\t\t\t\t}\n\n\t\t\t\tconst sessions = this.scope === \"all\" ? (this.allSessions ?? []) : (this.currentSessions ?? []);\n\t\t\t\tconst showCwd = this.scope === \"all\";\n\t\t\t\tthis.sessionList.setSessions(sessions, showCwd);\n\n\t\t\t\tconst msg = result.method === \"trash\" ? t(\"Session moved to trash\") : t(\"Session deleted\");\n\t\t\t\tthis.header.setStatusMessage({ type: \"info\", message: msg }, 2000);\n\t\t\t\tawait this.refreshSessionsAfterMutation();\n\t\t\t} else {\n\t\t\t\t// v8 ignore next -- deleteSessionFile always reports an error when ok is false\n\t\t\t\tconst errorMessage = result.error ?? t(\"Unknown error\");\n\t\t\t\tthis.header.setStatusMessage(\n\t\t\t\t\t{ type: \"error\", message: t(\"Failed to delete: {error}\", { error: errorMessage }) },\n\t\t\t\t\t3000,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.requestRender();\n\t\t};\n\n\t\t// Start loading current sessions immediately\n\t\tvoid this.loadScope(\"current\");\n\t}\n\n\tprivate cancelLoads(): void {\n\t\tif (this.currentLoad) {\n\t\t\tthis.currentLoad.abort();\n\t\t\tthis.currentLoad = null;\n\t\t\tthis.currentSessions = null;\n\t\t}\n\t\tif (this.allLoad) {\n\t\t\tthis.allLoad.abort();\n\t\t\tthis.allLoad = null;\n\t\t\tthis.allSessions = null;\n\t\t}\n\t}\n\n\tprivate enterRenameMode(sessionPath: string, currentName: string | undefined): void {\n\t\tthis.mode = \"rename\";\n\t\tthis.renameTargetPath = sessionPath;\n\t\tthis.renameInput.setValue(currentName ?? \"\");\n\t\tthis.renameInput.focused = true;\n\n\t\tconst panel = new Container();\n\t\tpanel.addChild(new Text(theme.bold(t(\"Rename Session\")), 1, 0));\n\t\tpanel.addChild(new Spacer(1));\n\t\tpanel.addChild(this.renameInput);\n\t\tpanel.addChild(new Spacer(1));\n\t\tpanel.addChild(\n\t\t\tnew Text(\n\t\t\t\ttheme.fg(\n\t\t\t\t\t\"muted\",\n\t\t\t\t\tt(\"{confirm} to save · {cancel} to cancel\", {\n\t\t\t\t\t\tconfirm: keyText(\"tui.select.confirm\"),\n\t\t\t\t\t\tcancel: keyText(\"tui.select.cancel\"),\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t\t1,\n\t\t\t\t0,\n\t\t\t),\n\t\t);\n\n\t\tthis.buildBaseLayout(panel, { showHeader: false });\n\t\tthis.requestRender();\n\t}\n\n\tprivate exitRenameMode(): void {\n\t\tthis.mode = \"list\";\n\t\tthis.renameTargetPath = null;\n\n\t\tthis.buildBaseLayout(this.sessionList);\n\n\t\tthis.requestRender();\n\t}\n\n\tprivate async confirmRename(value: string): Promise<void> {\n\t\tconst next = value.trim();\n\t\tif (!next) return;\n\t\tconst target = this.renameTargetPath;\n\t\t// v8 ignore next -- rename mode is only entered with a target path\n\t\tif (!target) {\n\t\t\tthis.exitRenameMode();\n\t\t\treturn;\n\t\t}\n\n\t\t// Find current name for callback\n\t\tconst renameSession = this.renameSession;\n\t\t// v8 ignore next -- rename mode is only entered with a rename callback\n\t\tif (!renameSession) {\n\t\t\tthis.exitRenameMode();\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\tawait renameSession(target, next);\n\t\t\tawait this.refreshSessionsAfterMutation();\n\t\t} catch (error) {\n\t\t\t// 与删除失败一致:向用户呈现错误状态,而不是让拒绝逃逸成 unhandled rejection。\n\t\t\tthis.header.setStatusMessage(\n\t\t\t\t{ type: \"error\", message: error instanceof Error ? error.message : String(error) },\n\t\t\t\t3000,\n\t\t\t);\n\t\t\tthis.requestRender();\n\t\t} finally {\n\t\t\tthis.exitRenameMode();\n\t\t}\n\t}\n\n\tprivate async loadScope(scope: SessionScope): Promise<void> {\n\t\tif (scope === \"current\" ? this.currentLoad : this.allLoad) return;\n\n\t\tconst showCwd = scope === \"all\";\n\t\tconst controller = new AbortController();\n\t\tif (scope === \"current\") {\n\t\t\tthis.currentLoad = controller;\n\t\t} else {\n\t\t\tthis.allLoad = controller;\n\t\t}\n\t\tthis.header.setScope(scope);\n\t\tthis.header.setLoading(true);\n\t\tthis.requestRender();\n\n\t\tconst isActive = () => (scope === \"current\" ? this.currentLoad : this.allLoad) === controller;\n\t\tconst onProgress: SessionListProgress = (loaded, total, partialSessions) => {\n\t\t\tif (!isActive()) return;\n\t\t\tif (partialSessions) {\n\t\t\t\tconst sessions = [...partialSessions];\n\t\t\t\tif (scope === \"current\") {\n\t\t\t\t\tthis.currentSessions = sessions;\n\t\t\t\t} else {\n\t\t\t\t\tthis.allSessions = sessions;\n\t\t\t\t}\n\t\t\t\tif (scope === this.scope) this.sessionList.setSessions(sessions, showCwd);\n\t\t\t}\n\t\t\tif (scope !== this.scope) return;\n\t\t\tthis.header.setProgress(loaded, total);\n\t\t\tthis.requestRender();\n\t\t};\n\n\t\ttry {\n\t\t\tconst sessions = await (scope === \"current\"\n\t\t\t\t? this.currentSessionsLoader(onProgress, controller.signal)\n\t\t\t\t: this.allSessionsLoader(onProgress, controller.signal));\n\t\t\tif (!isActive()) return;\n\n\t\t\tif (scope === \"current\") {\n\t\t\t\tthis.currentSessions = sessions;\n\t\t\t\tthis.currentLoad = null;\n\t\t\t} else {\n\t\t\t\tthis.allSessions = sessions;\n\t\t\t\tthis.allLoad = null;\n\t\t\t}\n\n\t\t\tif (scope !== this.scope) return;\n\n\t\t\tthis.header.setLoading(false);\n\t\t\tthis.sessionList.setSessions(sessions, showCwd);\n\t\t\tthis.requestRender();\n\t\t} catch (err) {\n\t\t\tif (!isActive()) return;\n\t\t\tif (scope === \"current\") {\n\t\t\t\tthis.currentLoad = null;\n\t\t\t\tthis.currentSessions = null;\n\t\t\t} else {\n\t\t\t\tthis.allLoad = null;\n\t\t\t\tthis.allSessions = null;\n\t\t\t}\n\n\t\t\tif (scope !== this.scope) return;\n\n\t\t\tconst message = err instanceof Error ? err.message : String(err);\n\t\t\tthis.header.setLoading(false);\n\t\t\tthis.header.setStatusMessage(\n\t\t\t\t{ type: \"error\", message: t(\"Failed to load sessions: {message}\", { message }) },\n\t\t\t\t4000,\n\t\t\t);\n\t\t\tthis.sessionList.setSessions([], showCwd);\n\t\t\tthis.requestRender();\n\t\t}\n\t}\n\n\tprivate toggleSortMode(): void {\n\t\t// Cycle: threaded -> recent -> relevance -> threaded\n\t\tthis.sortMode = this.sortMode === \"threaded\" ? \"recent\" : this.sortMode === \"recent\" ? \"relevance\" : \"threaded\";\n\t\tthis.header.setSortMode(this.sortMode);\n\t\tthis.sessionList.setSortMode(this.sortMode);\n\t\tthis.requestRender();\n\t}\n\n\tprivate toggleNameFilter(): void {\n\t\tthis.nameFilter = this.nameFilter === \"all\" ? \"named\" : \"all\";\n\t\tthis.header.setNameFilter(this.nameFilter);\n\t\tthis.sessionList.setNameFilter(this.nameFilter);\n\t\tthis.requestRender();\n\t}\n\n\tprivate suiteTitle(): string {\n\t\tif (this.suiteFilter === \"all\") return t(\"Resume Session (All Suites)\");\n\t\treturn t(\"Resume Session (Suite: {suite})\", {\n\t\t\tsuite: this.suiteFilterOptions?.currentSuiteId ?? \"unbound\",\n\t\t});\n\t}\n\n\t/**\n\t * Explicit \"show all\" switch for the suite dimension (设计 §10.1): sessions\n\t * from other suites (and unbound legacy sessions when the current session is\n\t * bound) are only visible after this explicit action.\n\t */\n\tprivate toggleSuiteFilter(): void {\n\t\tif (!this.suiteFilterOptions) return;\n\t\tthis.suiteFilter = this.suiteFilter === \"current\" ? \"all\" : \"current\";\n\t\tthis.header.setSuiteTitle(this.suiteTitle());\n\t\tthis.sessionList.setSuiteFilter(this.suiteFilter);\n\t\tthis.requestRender();\n\t}\n\n\tprivate async refreshSessionsAfterMutation(): Promise<void> {\n\t\tthis.cancelLoads();\n\t\tthis.currentSessions = null;\n\t\tthis.allSessions = null;\n\t\tawait this.loadScope(this.scope);\n\t}\n\n\tprivate toggleScope(): void {\n\t\tthis.scope = this.scope === \"current\" ? \"all\" : \"current\";\n\t\tconst sessions = this.scope === \"current\" ? this.currentSessions : this.allSessions;\n\t\tconst loading = (this.scope === \"current\" ? this.currentLoad : this.allLoad) !== null;\n\t\tthis.header.setScope(this.scope);\n\t\tthis.header.setLoading(loading);\n\t\tthis.sessionList.setSessions(sessions ?? [], this.scope === \"all\");\n\t\tthis.requestRender();\n\t\tif (sessions === null && !loading) void this.loadScope(this.scope);\n\t}\n\n\tgetSessionList(): SessionList {\n\t\treturn this.sessionList;\n\t}\n}\n"]}
@@ -7,9 +7,9 @@ import { Container, getKeybindings, Input, Spacer, Text, truncateToWidth, visibl
7
7
  import { t } from "../../../core/i18n/index.js";
8
8
  import { KeybindingsManager } from "../../../core/keybindings.js";
9
9
  import { removeSessionFromIndex } from "../../../core/session-index.js";
10
- import { SUITE_SESSION_ENTRY_TYPE } from "../../../profiles/suite-loader.js";
10
+ import { SUITE_SESSION_ENTRY_TYPE } from "../../../suites/suite-loader.js";
11
+ import { theme } from "../../../theme/theme.js";
11
12
  import { canonicalizePath as _canonicalizePath } from "../../../utils/paths.js";
12
- import { theme } from "../theme/theme.js";
13
13
  import { DynamicBorder } from "./dynamic-border.js";
14
14
  import { keyHint, keyText } from "./keybinding-hints.js";
15
15
  import { filterAndSortSessions, hasSessionName } from "./session-selector-search.js";