specrails-desktop 2.58.0 → 2.59.0

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 (425) hide show
  1. package/README.md +2 -5
  2. package/client/dist/assets/{ActivityFeedPage-BQGppIR0.js → ActivityFeedPage-DBFt8ZHP.js} +1 -1
  3. package/client/dist/assets/AgentBrowserCapture-DiQx0W67.js +1 -0
  4. package/client/dist/assets/AgentModeAnalyticsPane-BmDSXp_J.js +2 -0
  5. package/client/dist/assets/AgentModeCodePane-BLQLPSwr.js +2 -0
  6. package/client/dist/assets/{AgentModeJobsPane-DR_06oqH.js → AgentModeJobsPane-BbTXdKUa.js} +1 -1
  7. package/client/dist/assets/{AgentsPage-BKIKjm_1.js → AgentsPage-Dei1jGR8.js} +3 -3
  8. package/client/dist/assets/{AnalyticsPage-069npRVo.js → AnalyticsPage-BhkeGIGn.js} +1 -1
  9. package/client/dist/assets/CodePage-B_9yYWUx.js +3 -0
  10. package/client/dist/assets/{DesktopAnalyticsPage-qtWAPM47.js → DesktopAnalyticsPage-DAcfEJac.js} +1 -1
  11. package/client/dist/assets/DocsDialog-WCuiYgsc.js +11 -0
  12. package/client/dist/assets/DocsPage-bGVYTMTU.js +11 -0
  13. package/client/dist/assets/{ExportDropdown-BcMpvV89.js → ExportDropdown-CsodZ-yb.js} +1 -1
  14. package/client/dist/assets/InteractiveJobComposer-D5fh_eVL.js +19 -0
  15. package/client/dist/assets/JobDetailModal-DlpXF61O.js +1 -0
  16. package/client/dist/assets/JobDetailPage-2yR19_Lb.js +1 -0
  17. package/client/dist/assets/JobsPage-CS9IR6Dq.js +1 -0
  18. package/client/dist/assets/LoopBuilderPage-BwiAtmOr.js +1 -0
  19. package/client/dist/assets/{LoopPreviewModal-je5pSCf-.js → LoopPreviewModal--upwvgTv.js} +1 -1
  20. package/client/dist/assets/LoopWindowSurface-DRnUixtl.js +1 -0
  21. package/client/dist/assets/LoopsPage-Xm3nRToQ.js +2 -0
  22. package/client/dist/assets/MinimizedChatsContext-D_8L4EWZ.js +1 -0
  23. package/client/dist/assets/PluginsPage-CAFQ1B4Q.js +2 -0
  24. package/client/dist/assets/ProjectSettingsDialog-DYSO4v90.js +1 -0
  25. package/client/dist/assets/{RepositoryDeliveries-BiwJuS8r.js → RepositoryDeliveries-CbQmW7Qx.js} +1 -1
  26. package/client/dist/assets/RepositoryScopeSelector-DKzvIGSZ.js +2 -0
  27. package/client/dist/assets/ReviewPacketPage-SDBhYdQB.js +4 -0
  28. package/client/dist/assets/TemplatePreviewModal-DHBUds51.js +1 -0
  29. package/client/dist/assets/TicketDetailModalContext-UAeNm7BB.js +16 -0
  30. package/client/dist/assets/{Trans-D3AfDylf.js → Trans-DExd3Z00.js} +1 -1
  31. package/client/dist/assets/agent-BElLtdKP.js +1 -0
  32. package/client/dist/assets/agent-C-m9VugX.js +1 -0
  33. package/client/dist/assets/agent-CGSKxfZk.js +1 -0
  34. package/client/dist/assets/agent-CW74ODDP.js +1 -0
  35. package/client/dist/assets/agent-DeCAZDhL.js +1 -0
  36. package/client/dist/assets/agent-DrM4qned.js +1 -0
  37. package/client/dist/assets/agent-KdIXq3w5.js +1 -0
  38. package/client/dist/assets/agent-jK8mCisM.js +1 -0
  39. package/client/dist/assets/{agentRuntime-DGz_IqKW.js → agentRuntime-15Pkk6we.js} +1 -1
  40. package/client/dist/assets/agentRuntime-Bpx3yWHK.js +1 -0
  41. package/client/dist/assets/{agentRuntime-Bg9tbmqm.js → agentRuntime-C78n13To.js} +1 -1
  42. package/client/dist/assets/{agentRuntime-D-GJVGkj.js → agentRuntime-CCI7XF4c.js} +1 -1
  43. package/client/dist/assets/{agentRuntime-D2__CVI_.js → agentRuntime-CKDHe2-a.js} +1 -1
  44. package/client/dist/assets/{agentRuntime-D35dGVOP.js → agentRuntime-Ddqvp2bP.js} +1 -1
  45. package/client/dist/assets/{agentRuntime-hInH9Fzj.js → agentRuntime-TXPQowKJ.js} +1 -1
  46. package/client/dist/assets/{agentRuntime-O1liDt6G.js → agentRuntime-hqZRy08E.js} +1 -1
  47. package/client/dist/assets/{builder-DGETbtZj.js → builder-B9gorTnT.js} +1 -1
  48. package/client/dist/assets/{builder-DyQperXU.js → builder-Bvw5s3Mi.js} +1 -1
  49. package/client/dist/assets/{builder-C1neIYGR.js → builder-CL5l4dU3.js} +1 -1
  50. package/client/dist/assets/{builder-DXEJUlC0.js → builder-CVDTVrQX.js} +1 -1
  51. package/client/dist/assets/{builder-CzW5ovyI.js → builder-CpS9liE9.js} +1 -1
  52. package/client/dist/assets/{builder-CvnFm0im.js → builder-DNctIL9Q.js} +1 -1
  53. package/client/dist/assets/{builder-D06L7iPy.js → builder-De2NxX6o.js} +1 -1
  54. package/client/dist/assets/{builder-C0FyvM83.js → builder-DeYT7Y-m.js} +1 -1
  55. package/client/dist/assets/{button-Ccc9Dc-D.js → button-D1xExSTF.js} +1 -1
  56. package/client/dist/assets/{common-DmsclwjP.js → common-Bdi0qN4S.js} +1 -1
  57. package/client/dist/assets/{common-C4Yvvhp6.js → common-Bhb9zN1P.js} +1 -1
  58. package/client/dist/assets/{common-od8WThlf.js → common-BykKlZg1.js} +1 -1
  59. package/client/dist/assets/{common-C0BOdeNi.js → common-CvnNNSJA.js} +1 -1
  60. package/client/dist/assets/{common-BCK7c9Pv.js → common-D5zk_mqq.js} +1 -1
  61. package/client/dist/assets/{common-DpLWwgI1.js → common-DQNO_al5.js} +1 -1
  62. package/client/dist/assets/{common-OCvl3c8t.js → common-Dax30Vmp.js} +1 -1
  63. package/client/dist/assets/{common-c0aujEZC.js → common-DkllpVSb.js} +1 -1
  64. package/client/dist/assets/{dialog-xXB2q5HJ.js → dialog-CMgps2MY.js} +1 -1
  65. package/client/dist/assets/external-link-D6XxC_Cu.js +1 -0
  66. package/client/dist/assets/file-text-BcLCfcWZ.js +1 -0
  67. package/client/dist/assets/{formatDistanceToNow-aBss1Nai.js → formatDistanceToNow-aw7H5ORC.js} +1 -1
  68. package/client/dist/assets/{getTimezoneOffsetInMilliseconds-DOGj1Mfz.js → getTimezoneOffsetInMilliseconds-NyC7gZJX.js} +1 -1
  69. package/client/dist/assets/index-CahchzS5.css +2 -0
  70. package/client/dist/assets/index-JSTZVJfe.js +83 -0
  71. package/client/dist/assets/integrations-BkpRUbvp.js +1 -0
  72. package/client/dist/assets/integrations-Bo8qbJf4.js +1 -0
  73. package/client/dist/assets/integrations-CmSrKzZb.js +1 -0
  74. package/client/dist/assets/integrations-DGtq26Rr.js +1 -0
  75. package/client/dist/assets/integrations-De38GFnQ.js +1 -0
  76. package/client/dist/assets/integrations-Dw6zdtb-.js +1 -0
  77. package/client/dist/assets/integrations-Dwl9KQp0.js +1 -0
  78. package/client/dist/assets/integrations-Refg_d2I.js +1 -0
  79. package/client/dist/assets/jira-api-DlXaRwA3.js +1 -0
  80. package/client/dist/assets/{jobs-KG4Sn12X.js → jobs-1G3wodhl.js} +1 -1
  81. package/client/dist/assets/{jobs-6_-r75yC.js → jobs-B4pu8TdF.js} +1 -1
  82. package/client/dist/assets/{jobs-pPv4KWjb.js → jobs-BD47Ov11.js} +1 -1
  83. package/client/dist/assets/{jobs-B1yqyId5.js → jobs-BLOoVRRl.js} +1 -1
  84. package/client/dist/assets/{jobs-BKiK-ZWh.js → jobs-CSrRx5lD.js} +1 -1
  85. package/client/dist/assets/{jobs-BFuV7ttH.js → jobs-DZAbh1m2.js} +1 -1
  86. package/client/dist/assets/{jobs-DmKV7b7d.js → jobs-epP7gt8W.js} +1 -1
  87. package/client/dist/assets/{jobs-BKa8LuwA.js → jobs-tWjcDF_6.js} +1 -1
  88. package/client/dist/assets/loops--KWr0X-w.js +1 -0
  89. package/client/dist/assets/{loops-BO3V8244.js → loops-3IutojWt.js} +1 -1
  90. package/client/dist/assets/{loops-C-hZK8pf.js → loops-BAosWtXE.js} +1 -1
  91. package/client/dist/assets/{loops-eUnCfLjC.js → loops-BISDssL5.js} +1 -1
  92. package/client/dist/assets/{loops-Dv849ckF.js → loops-Cm55CXJ4.js} +1 -1
  93. package/client/dist/assets/{loops-CDOWZ0ci.js → loops-D7tL_Saw.js} +1 -1
  94. package/client/dist/assets/{loops-BJDY9FTh.js → loops-DHQtnfze.js} +1 -1
  95. package/client/dist/assets/{loops-Q9LIgGkq.js → loops-kIJJkaxf.js} +1 -1
  96. package/client/dist/assets/nav--u7iPYlS.js +1 -0
  97. package/client/dist/assets/nav-C5Jgfaby.js +1 -0
  98. package/client/dist/assets/nav-CAna_Wpt.js +1 -0
  99. package/client/dist/assets/nav-CCLqeyHo.js +1 -0
  100. package/client/dist/assets/nav-Cf3c90Jk.js +1 -0
  101. package/client/dist/assets/nav-DMYQaQjR.js +1 -0
  102. package/client/dist/assets/nav-Df_PkZ9F.js +1 -0
  103. package/client/dist/assets/nav-VyNGBJwj.js +1 -0
  104. package/client/dist/assets/{project-repositories-CSnfzUpg.js → project-repositories-DXhb9FP4.js} +1 -1
  105. package/client/dist/assets/provider-capabilities-lePfeT_Y.js +1 -0
  106. package/client/dist/assets/save-OsUqVn99.js +1 -0
  107. package/client/dist/assets/settings-B5Hy_Kol.js +1 -0
  108. package/client/dist/assets/settings-BBj_kZaD.js +1 -0
  109. package/client/dist/assets/settings-ByVE7jdZ.js +1 -0
  110. package/client/dist/assets/settings-COlH_P33.js +1 -0
  111. package/client/dist/assets/settings-D77mC_Lb.js +1 -0
  112. package/client/dist/assets/settings-DZKy7MqN.js +1 -0
  113. package/client/dist/assets/settings-Dbyd6gmj.js +1 -0
  114. package/client/dist/assets/settings-Dn-pXukr.js +1 -0
  115. package/client/dist/assets/setup-Be485n2u.js +1 -0
  116. package/client/dist/assets/setup-CKGUxKr-.js +1 -0
  117. package/client/dist/assets/setup-Ck1Uwd7_.js +1 -0
  118. package/client/dist/assets/setup-Cm774a6v.js +1 -0
  119. package/client/dist/assets/setup-DIqMQpxt.js +1 -0
  120. package/client/dist/assets/setup-DfCsoNFL.js +1 -0
  121. package/client/dist/assets/setup-DkeE8mP0.js +1 -0
  122. package/client/dist/assets/setup-xVntVaz1.js +1 -0
  123. package/client/dist/assets/{spending-HBSk-6jv.js → spending-BdcyVkcd.js} +1 -1
  124. package/client/dist/assets/subscriptionUsage-Cf87DeS_.js +1 -0
  125. package/client/dist/assets/subscriptionUsage-D6u7VBdz.js +1 -0
  126. package/client/dist/assets/subscriptionUsage-DQ02J25O.js +1 -0
  127. package/client/dist/assets/subscriptionUsage-DWF3zKp4.js +1 -0
  128. package/client/dist/assets/subscriptionUsage-DkIf6Zuh.js +1 -0
  129. package/client/dist/assets/subscriptionUsage-DoWQv7l1.js +1 -0
  130. package/client/dist/assets/subscriptionUsage-N9hB-ARf.js +1 -0
  131. package/client/dist/assets/subscriptionUsage-zRcRPHkP.js +1 -0
  132. package/client/dist/assets/tauri-shell-DE6LfGPw.js +2 -0
  133. package/client/dist/assets/{useDesktop-0unHDBJJ.js → useDesktop-D07TvesS.js} +1 -1
  134. package/client/dist/assets/{useRuntimeRuns-BN1rhyEm.js → useRuntimeRuns-pGLmtAC6.js} +1 -1
  135. package/client/dist/assets/useSharedWebSocket-TzKtPRp9.js +2 -0
  136. package/client/dist/index.html +33 -32
  137. package/docs/README.md +1 -9
  138. package/docs/agent-live-steering.md +0 -6
  139. package/docs/agents/README.md +0 -2
  140. package/docs/agents/mcp.md +1 -14
  141. package/docs/cli.md +0 -13
  142. package/docs/codex.md +2 -75
  143. package/docs/creating-specs.md +0 -39
  144. package/docs/customizing.md +1 -15
  145. package/docs/getting-started.md +0 -23
  146. package/docs/guide/de/agents/2-profiles-and-the-balanced-default.md +0 -8
  147. package/docs/guide/de/agents/4-custom-agents-catalog.md +0 -15
  148. package/docs/guide/de/getting-started/1-what-is-specrails.md +0 -2
  149. package/docs/guide/de/getting-started/2-installing-and-first-run.md +0 -2
  150. package/docs/guide/de/getting-started/3-adding-your-first-project.md +0 -4
  151. package/docs/guide/de/getting-started/4-the-dashboard-tour.md +0 -5
  152. package/docs/guide/de/integrations/1-ai-providers.md +2 -50
  153. package/docs/guide/de/integrations/2-plugins.md +0 -8
  154. package/docs/guide/de/integrations/5-mcp-server.md +1 -14
  155. package/docs/guide/de/integrations/6-agent-chat.md +0 -11
  156. package/docs/guide/de/integrations/7-local-engines.md +0 -4
  157. package/docs/guide/de/pipeline/1-rails-and-jobs.md +0 -13
  158. package/docs/guide/de/pipeline/2-the-job-detail-view.md +0 -3
  159. package/docs/guide/de/pipeline/4-picking-an-engine-per-rail.md +0 -20
  160. package/docs/guide/de/pipeline/5-the-loop-builder.md +0 -6
  161. package/docs/guide/de/specs/2-add-spec-quick-mode.md +0 -7
  162. package/docs/guide/en/agents/2-profiles-and-the-balanced-default.md +0 -10
  163. package/docs/guide/en/agents/4-custom-agents-catalog.md +0 -25
  164. package/docs/guide/en/getting-started/1-what-is-specrails.md +0 -2
  165. package/docs/guide/en/getting-started/2-installing-and-first-run.md +0 -2
  166. package/docs/guide/en/getting-started/3-adding-your-first-project.md +0 -4
  167. package/docs/guide/en/getting-started/4-the-dashboard-tour.md +0 -5
  168. package/docs/guide/en/insights/3-code-explorer.md +0 -5
  169. package/docs/guide/en/integrations/1-ai-providers.md +10 -99
  170. package/docs/guide/en/integrations/2-plugins.md +0 -8
  171. package/docs/guide/en/integrations/5-mcp-server.md +1 -1
  172. package/docs/guide/en/integrations/6-agent-chat.md +0 -17
  173. package/docs/guide/en/integrations/7-local-engines.md +0 -4
  174. package/docs/guide/en/pipeline/1-rails-and-jobs.md +2 -24
  175. package/docs/guide/en/pipeline/2-the-job-detail-view.md +0 -3
  176. package/docs/guide/en/pipeline/4-picking-an-engine-per-rail.md +10 -65
  177. package/docs/guide/en/pipeline/5-the-loop-builder.md +0 -7
  178. package/docs/guide/en/specs/2-add-spec-quick-mode.md +0 -11
  179. package/docs/guide/es/agents/2-profiles-and-the-balanced-default.md +0 -8
  180. package/docs/guide/es/agents/4-custom-agents-catalog.md +0 -15
  181. package/docs/guide/es/getting-started/1-what-is-specrails.md +0 -2
  182. package/docs/guide/es/getting-started/2-installing-and-first-run.md +0 -2
  183. package/docs/guide/es/getting-started/3-adding-your-first-project.md +0 -4
  184. package/docs/guide/es/getting-started/4-the-dashboard-tour.md +0 -5
  185. package/docs/guide/es/integrations/1-ai-providers.md +10 -75
  186. package/docs/guide/es/integrations/2-plugins.md +0 -8
  187. package/docs/guide/es/integrations/5-mcp-server.md +1 -1
  188. package/docs/guide/es/integrations/6-agent-chat.md +0 -11
  189. package/docs/guide/es/integrations/7-local-engines.md +0 -4
  190. package/docs/guide/es/pipeline/1-rails-and-jobs.md +3 -13
  191. package/docs/guide/es/pipeline/2-the-job-detail-view.md +0 -3
  192. package/docs/guide/es/pipeline/4-picking-an-engine-per-rail.md +10 -53
  193. package/docs/guide/es/pipeline/5-the-loop-builder.md +1 -6
  194. package/docs/guide/es/specs/2-add-spec-quick-mode.md +0 -7
  195. package/docs/guide/fr/agents/2-profiles-and-the-balanced-default.md +0 -8
  196. package/docs/guide/fr/agents/4-custom-agents-catalog.md +0 -15
  197. package/docs/guide/fr/getting-started/1-what-is-specrails.md +0 -2
  198. package/docs/guide/fr/getting-started/2-installing-and-first-run.md +0 -2
  199. package/docs/guide/fr/getting-started/3-adding-your-first-project.md +0 -4
  200. package/docs/guide/fr/getting-started/4-the-dashboard-tour.md +0 -5
  201. package/docs/guide/fr/integrations/1-ai-providers.md +2 -50
  202. package/docs/guide/fr/integrations/2-plugins.md +0 -8
  203. package/docs/guide/fr/integrations/5-mcp-server.md +1 -14
  204. package/docs/guide/fr/integrations/6-agent-chat.md +0 -11
  205. package/docs/guide/fr/integrations/7-local-engines.md +0 -4
  206. package/docs/guide/fr/pipeline/1-rails-and-jobs.md +0 -13
  207. package/docs/guide/fr/pipeline/2-the-job-detail-view.md +0 -3
  208. package/docs/guide/fr/pipeline/4-picking-an-engine-per-rail.md +0 -22
  209. package/docs/guide/fr/pipeline/5-the-loop-builder.md +0 -6
  210. package/docs/guide/fr/specs/2-add-spec-quick-mode.md +0 -7
  211. package/docs/guide/it/agents/2-profiles-and-the-balanced-default.md +0 -8
  212. package/docs/guide/it/agents/4-custom-agents-catalog.md +0 -15
  213. package/docs/guide/it/getting-started/1-what-is-specrails.md +0 -2
  214. package/docs/guide/it/getting-started/2-installing-and-first-run.md +0 -2
  215. package/docs/guide/it/getting-started/3-adding-your-first-project.md +0 -4
  216. package/docs/guide/it/getting-started/4-the-dashboard-tour.md +0 -5
  217. package/docs/guide/it/integrations/1-ai-providers.md +2 -48
  218. package/docs/guide/it/integrations/2-plugins.md +0 -8
  219. package/docs/guide/it/integrations/5-mcp-server.md +1 -14
  220. package/docs/guide/it/integrations/6-agent-chat.md +0 -11
  221. package/docs/guide/it/integrations/7-local-engines.md +0 -4
  222. package/docs/guide/it/pipeline/1-rails-and-jobs.md +2 -13
  223. package/docs/guide/it/pipeline/2-the-job-detail-view.md +0 -3
  224. package/docs/guide/it/pipeline/4-picking-an-engine-per-rail.md +0 -20
  225. package/docs/guide/it/pipeline/5-the-loop-builder.md +1 -6
  226. package/docs/guide/it/specs/2-add-spec-quick-mode.md +0 -7
  227. package/docs/guide/ja/agents/2-profiles-and-the-balanced-default.md +0 -9
  228. package/docs/guide/ja/agents/4-custom-agents-catalog.md +0 -15
  229. package/docs/guide/ja/getting-started/1-what-is-specrails.md +0 -2
  230. package/docs/guide/ja/getting-started/2-installing-and-first-run.md +0 -2
  231. package/docs/guide/ja/getting-started/3-adding-your-first-project.md +0 -4
  232. package/docs/guide/ja/getting-started/4-the-dashboard-tour.md +0 -5
  233. package/docs/guide/ja/integrations/1-ai-providers.md +1 -69
  234. package/docs/guide/ja/integrations/2-plugins.md +0 -8
  235. package/docs/guide/ja/integrations/5-mcp-server.md +1 -14
  236. package/docs/guide/ja/integrations/6-agent-chat.md +0 -10
  237. package/docs/guide/ja/integrations/7-local-engines.md +0 -4
  238. package/docs/guide/ja/pipeline/1-rails-and-jobs.md +0 -13
  239. package/docs/guide/ja/pipeline/2-the-job-detail-view.md +0 -3
  240. package/docs/guide/ja/pipeline/4-picking-an-engine-per-rail.md +0 -21
  241. package/docs/guide/ja/pipeline/5-the-loop-builder.md +0 -6
  242. package/docs/guide/ja/specs/2-add-spec-quick-mode.md +0 -7
  243. package/docs/guide/pt/agents/2-profiles-and-the-balanced-default.md +0 -8
  244. package/docs/guide/pt/agents/4-custom-agents-catalog.md +0 -15
  245. package/docs/guide/pt/getting-started/1-what-is-specrails.md +0 -2
  246. package/docs/guide/pt/getting-started/2-installing-and-first-run.md +0 -2
  247. package/docs/guide/pt/getting-started/3-adding-your-first-project.md +0 -4
  248. package/docs/guide/pt/getting-started/4-the-dashboard-tour.md +0 -5
  249. package/docs/guide/pt/integrations/1-ai-providers.md +2 -48
  250. package/docs/guide/pt/integrations/2-plugins.md +0 -8
  251. package/docs/guide/pt/integrations/5-mcp-server.md +1 -14
  252. package/docs/guide/pt/integrations/6-agent-chat.md +0 -10
  253. package/docs/guide/pt/integrations/7-local-engines.md +0 -4
  254. package/docs/guide/pt/pipeline/1-rails-and-jobs.md +0 -13
  255. package/docs/guide/pt/pipeline/2-the-job-detail-view.md +0 -2
  256. package/docs/guide/pt/pipeline/4-picking-an-engine-per-rail.md +0 -21
  257. package/docs/guide/pt/pipeline/5-the-loop-builder.md +0 -6
  258. package/docs/guide/pt/specs/2-add-spec-quick-mode.md +0 -7
  259. package/docs/guide/zh/agents/2-profiles-and-the-balanced-default.md +0 -7
  260. package/docs/guide/zh/agents/4-custom-agents-catalog.md +0 -15
  261. package/docs/guide/zh/getting-started/1-what-is-specrails.md +0 -2
  262. package/docs/guide/zh/getting-started/2-installing-and-first-run.md +0 -2
  263. package/docs/guide/zh/getting-started/3-adding-your-first-project.md +0 -4
  264. package/docs/guide/zh/getting-started/4-the-dashboard-tour.md +0 -5
  265. package/docs/guide/zh/integrations/1-ai-providers.md +1 -67
  266. package/docs/guide/zh/integrations/2-plugins.md +0 -8
  267. package/docs/guide/zh/integrations/5-mcp-server.md +1 -14
  268. package/docs/guide/zh/integrations/6-agent-chat.md +0 -9
  269. package/docs/guide/zh/integrations/7-local-engines.md +0 -4
  270. package/docs/guide/zh/pipeline/1-rails-and-jobs.md +0 -13
  271. package/docs/guide/zh/pipeline/2-the-job-detail-view.md +0 -2
  272. package/docs/guide/zh/pipeline/4-picking-an-engine-per-rail.md +0 -20
  273. package/docs/guide/zh/pipeline/5-the-loop-builder.md +0 -6
  274. package/docs/guide/zh/specs/2-add-spec-quick-mode.md +0 -7
  275. package/docs/internals/adding-a-provider.md +7 -0
  276. package/docs/internals/desktop-owned-workflows.md +121 -0
  277. package/docs/internals/operations-runbook.md +20 -0
  278. package/docs/internals/programmatic-agent-runtime.md +34 -28
  279. package/docs/internals/project-builder.md +34 -11
  280. package/docs/internals/source-map.md +51 -3
  281. package/docs/internals/spec-addenda.md +11 -5
  282. package/docs/local-providers.md +8 -13
  283. package/docs/mcp.md +1 -17
  284. package/docs/platforms/macos.md +0 -40
  285. package/docs/platforms/windows-parity.md +1 -1
  286. package/docs/platforms/windows.md +0 -8
  287. package/docs/running-pipelines.md +1 -46
  288. package/docs/subscription-usage.md +19 -0
  289. package/docs/terminal.md +0 -2
  290. package/docs/tracking-cost.md +2 -33
  291. package/package.json +1 -1
  292. package/server/dist/core-execution.js +24 -15
  293. package/server/dist/desktop-db.js +23 -10
  294. package/server/dist/desktop-router.js +8 -4
  295. package/server/dist/index.js +10 -5
  296. package/server/dist/mcp/guide.js +1 -0
  297. package/server/dist/mcp/tools/jobs.js +1 -1
  298. package/server/dist/mcp/tools/loops.js +2 -0
  299. package/server/dist/mcp/tools/meta.js +6 -7
  300. package/server/dist/mcp/tools/projects.js +31 -6
  301. package/server/dist/mcp/tools/rails.js +6 -3
  302. package/server/dist/mcp/tools/setup.js +10 -0
  303. package/server/dist/mcp/tools/specs.js +1 -1
  304. package/server/dist/modules/accounting/runtime/pricing.js +6 -1
  305. package/server/dist/modules/agent-runtime/runtime/agent-runtime-bridge.js +55 -12
  306. package/server/dist/modules/agent-runtime/runtime/agent-runtime-metrics.js +1 -1
  307. package/server/dist/modules/agent-runtime/runtime/agent-runtime-settings-router.js +1 -1
  308. package/server/dist/modules/agent-runtime/runtime/agent-runtime-settings.js +42 -0
  309. package/server/dist/modules/agent-runtime/runtime/agent-runtime-verification-suggestions.js +10 -4
  310. package/server/dist/modules/builder/runtime/milestone-chain.js +76 -10
  311. package/server/dist/modules/delivery/runtime/delivery-evidence.js +3 -2
  312. package/server/dist/modules/delivery/runtime/multi-repo-execution.js +3 -0
  313. package/server/dist/modules/delivery/runtime/rail-isolated-launch.js +1 -0
  314. package/server/dist/modules/delivery/runtime/rail-launch-parser.js +8 -0
  315. package/server/dist/modules/delivery/runtime/rails-router.js +48 -26
  316. package/server/dist/modules/delivery/runtime/review-packet.js +1 -1
  317. package/server/dist/modules/loops/runtime/loop-agent-defaults.json +6 -0
  318. package/server/dist/modules/loops/runtime/loop-agents.js +21 -0
  319. package/server/dist/modules/loops/runtime/loop-command-catalog.js +1 -1
  320. package/server/dist/modules/loops/runtime/loop-core-factory.js +19 -3
  321. package/server/dist/modules/loops/runtime/loop-definition.js +79 -12
  322. package/server/dist/modules/loops/runtime/loop-effect.js +1 -1
  323. package/server/dist/modules/loops/runtime/loop-executors.js +24 -9
  324. package/server/dist/modules/loops/runtime/loop-factory.js +1 -1
  325. package/server/dist/modules/loops/runtime/loop-graph.js +5 -14
  326. package/server/dist/modules/loops/runtime/loop-implement-recipe.js +49 -0
  327. package/server/dist/modules/loops/runtime/loop-run-manager.js +3 -3
  328. package/server/dist/modules/loops/runtime/loop-templates.js +29 -5
  329. package/server/dist/modules/loops/runtime/loops-router.js +17 -0
  330. package/server/dist/modules/missions/runtime/agent-context-resolver.js +1 -1
  331. package/server/dist/modules/missions/runtime/agent-operator-prompt.js +17 -8
  332. package/server/dist/modules/specs/runtime/spec-models.js +4 -7
  333. package/server/dist/modules/subscription-usage/adapters/claude.js +113 -0
  334. package/server/dist/modules/subscription-usage/adapters/codex.js +164 -0
  335. package/server/dist/modules/subscription-usage/adapters/errors.js +15 -0
  336. package/server/dist/modules/subscription-usage/adapters/http.js +20 -0
  337. package/server/dist/modules/subscription-usage/adapters/local-auth.js +61 -0
  338. package/server/dist/modules/subscription-usage/application.js +11 -0
  339. package/server/dist/modules/subscription-usage/domain.js +70 -0
  340. package/server/dist/modules/subscription-usage/index.js +2 -0
  341. package/server/dist/modules/subscription-usage/ports.js +2 -0
  342. package/server/dist/modules/subscription-usage/runtime/composition.js +20 -0
  343. package/server/dist/modules/subscription-usage/runtime/usage-service.js +111 -0
  344. package/server/dist/project-registry.js +16 -1
  345. package/server/dist/project-repositories.js +51 -2
  346. package/server/dist/project-router-helpers.js +1 -1
  347. package/server/dist/project-router-loop-runs.js +4 -1
  348. package/server/dist/providers/claude-adapter.js +6 -4
  349. package/server/dist/providers/codex-adapter.js +4 -5
  350. package/server/dist/schemas/workflow-definition.schema.json +2 -0
  351. package/client/dist/assets/AgentBrowserCapture-PI-cxyxi.js +0 -1
  352. package/client/dist/assets/AgentModeAnalyticsPane-mQsOqdXx.js +0 -2
  353. package/client/dist/assets/AgentModeCodePane-BL-vpmlY.js +0 -2
  354. package/client/dist/assets/CodePage-Alitorrv.js +0 -3
  355. package/client/dist/assets/DocsDialog-DwL6rgcT.js +0 -11
  356. package/client/dist/assets/DocsPage-BA1hiJZ-.js +0 -11
  357. package/client/dist/assets/InteractiveJobComposer-B3H1YHr6.js +0 -19
  358. package/client/dist/assets/JobDetailModal-XZQ9eAAy.js +0 -1
  359. package/client/dist/assets/JobDetailPage-B-SIaq_q.js +0 -1
  360. package/client/dist/assets/JobsPage-iQXAv2mx.js +0 -1
  361. package/client/dist/assets/LoopBuilderPage-B_gbFAHn.js +0 -1
  362. package/client/dist/assets/LoopsPage-BZwcY5cu.js +0 -2
  363. package/client/dist/assets/MinimizedChatsContext-CNx_0bZu.js +0 -1
  364. package/client/dist/assets/PluginsPage-DFocnoHX.js +0 -2
  365. package/client/dist/assets/ProjectSettingsDialog-Bh3S6EBB.js +0 -1
  366. package/client/dist/assets/RepositoryScopeSelector-C2mvWBQ6.js +0 -1
  367. package/client/dist/assets/ReviewPacketPage-CrAf-WDy.js +0 -4
  368. package/client/dist/assets/TemplatePreviewModal-C7DordpN.js +0 -1
  369. package/client/dist/assets/TicketDetailModalContext-B-DySpKL.js +0 -16
  370. package/client/dist/assets/agent-BaG10AN6.js +0 -1
  371. package/client/dist/assets/agent-CH4aJ884.js +0 -1
  372. package/client/dist/assets/agent-CLc9fA7v.js +0 -1
  373. package/client/dist/assets/agent-DHh9-AdL.js +0 -1
  374. package/client/dist/assets/agent-DkKnd6Wv.js +0 -1
  375. package/client/dist/assets/agent-aiVhqFW1.js +0 -1
  376. package/client/dist/assets/agent-dbznD3eO.js +0 -1
  377. package/client/dist/assets/agent-sMVFcPwL.js +0 -1
  378. package/client/dist/assets/agentRuntime-BeUb3g9g.js +0 -1
  379. package/client/dist/assets/file-text-CFT-xXKN.js +0 -1
  380. package/client/dist/assets/index-BS7KCWkV.css +0 -2
  381. package/client/dist/assets/index-C4Mv6tV6.js +0 -80
  382. package/client/dist/assets/integrations-CH0zy1Mw.js +0 -1
  383. package/client/dist/assets/integrations-CIAjhd7L.js +0 -1
  384. package/client/dist/assets/integrations-CZdwOe8A.js +0 -1
  385. package/client/dist/assets/integrations-Ct7omMld.js +0 -1
  386. package/client/dist/assets/integrations-D6MSxy3-.js +0 -1
  387. package/client/dist/assets/integrations-DbZa-Zyc.js +0 -1
  388. package/client/dist/assets/integrations-b8pH-vfl.js +0 -1
  389. package/client/dist/assets/integrations-mB-7zoyT.js +0 -1
  390. package/client/dist/assets/jira-api-BYbEPlkr.js +0 -1
  391. package/client/dist/assets/layers-eDMjG41I.js +0 -1
  392. package/client/dist/assets/loops-B4_D-nbg.js +0 -1
  393. package/client/dist/assets/nav-B-tpjyc2.js +0 -1
  394. package/client/dist/assets/nav-BJNXGg29.js +0 -1
  395. package/client/dist/assets/nav-BdhtRLP7.js +0 -1
  396. package/client/dist/assets/nav-ByYgyN5T.js +0 -1
  397. package/client/dist/assets/nav-DA0Mva2c.js +0 -1
  398. package/client/dist/assets/nav-DcJm_Jg_.js +0 -1
  399. package/client/dist/assets/nav-DhMPtAXc.js +0 -1
  400. package/client/dist/assets/nav-DhPb-Isc.js +0 -1
  401. package/client/dist/assets/provider-capabilities-Vi1ZGvAK.js +0 -1
  402. package/client/dist/assets/save-B6wGWwBR.js +0 -1
  403. package/client/dist/assets/settings-3o4Ntzi5.js +0 -1
  404. package/client/dist/assets/settings-B97jlkwD.js +0 -1
  405. package/client/dist/assets/settings-BTaT_bsS.js +0 -1
  406. package/client/dist/assets/settings-CT8w7WiC.js +0 -1
  407. package/client/dist/assets/settings-Cvr8_tvh.js +0 -1
  408. package/client/dist/assets/settings-Dn1qgAC8.js +0 -1
  409. package/client/dist/assets/settings-EShDdg4J.js +0 -1
  410. package/client/dist/assets/settings-tfLhQZRN.js +0 -1
  411. package/client/dist/assets/setup-CBMu3tqH.js +0 -1
  412. package/client/dist/assets/setup-CPh-e6J2.js +0 -1
  413. package/client/dist/assets/setup-CRKLp_ke.js +0 -1
  414. package/client/dist/assets/setup-Cy302v4J.js +0 -1
  415. package/client/dist/assets/setup-D681vTPf.js +0 -1
  416. package/client/dist/assets/setup-DYK0VBkE.js +0 -1
  417. package/client/dist/assets/setup-KAuiIiVs.js +0 -1
  418. package/client/dist/assets/setup-OGX-oCfI.js +0 -1
  419. package/client/dist/assets/useSharedWebSocket-BZMrX4jr.js +0 -2
  420. package/client/dist/assets/wrench-BfmNO9Vw.js +0 -1
  421. package/docs/agy-cli-provider-study.md +0 -257
  422. package/docs/gemini-cli-provider-study.md +0 -301
  423. package/docs/gemini-core-support-evaluation.md +0 -160
  424. package/docs/gemini.md +0 -257
  425. package/docs/kimi.md +0 -291
@@ -1,4 +1,4 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{t as r}from"./react-dom-DiWzBDP9.js";import{h as i,r as a}from"./useSharedWebSocket-BZMrX4jr.js";import{t as o}from"./Trans-D3AfDylf.js";import{n as s,t as c}from"./createLucideIcon-Bjbbp_KS.js";import{a as l,r as u,s as d}from"./useDesktop-0unHDBJJ.js";import{c as f,s as p}from"./provider-capabilities-Vi1ZGvAK.js";import{n as m,t as h}from"./save-B6wGWwBR.js";import{c as g,d as _,n as v,r as y,u as b}from"./MinimizedChatsContext-CNx_0bZu.js";import{t as x}from"./file-text-CFT-xXKN.js";import{t as S}from"./loader-circle-DcygOQpC.js";import{t as C}from"./pencil-C9RkrIPZ.js";import{t as ee}from"./plus-CsnjfkmX.js";import{t as te}from"./search-Cq_gE3Ik.js";import{t as w}from"./sparkles-DrY8hb0X.js";import{t as T}from"./trash-2-BOU3WdZZ.js";import{t as E}from"./triangle-alert-H9T4jAmh.js";import{t as ne}from"./x-CBMI9ejn.js";import{M as D,a as O,i as k,j as re,l as A,o as j,r as M,t as N}from"./dialog-xXB2q5HJ.js";import{t as P}from"./button-Ccc9Dc-D.js";import{A as F,C as ie,D as ae,Dt as oe,E as I,Gt as L,I as se,Lt as ce,M as R,N as le,O as ue,Ot as de,P as fe,Pt as pe,Q as me,Rt as z,T as he,U as ge,_t as _e,b as ve,bt as B,j as ye,k as V,st as be,u as H,ut as xe,w as Se,xt as Ce,zt as we}from"./index-C4Mv6tV6.js";import{t as Te}from"./format-command-C0D9IPmV.js";var Ee=c(`flask-conical`,[[`path`,{d:`M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2`,key:`18mbvz`}],[`path`,{d:`M6.453 15h11.094`,key:`3shlmq`}],[`path`,{d:`M8.5 2h7`,key:`csnxdl`}]]),U=e(t(),1),W=n(),De=/^[a-z0-9][a-z0-9-]*$/;function Oe({open:e,mode:t=`add`,initial:n,chainAgents:r,onConfirm:i,onCancel:a}){let{t:c}=s(`agents`),[l,u]=(0,U.useState)(``),[d,f]=(0,U.useState)(r[0]??``);(0,U.useEffect)(()=>{e&&(t===`edit`&&n?(u(n.tags.join(`, `)),f(r.includes(n.agent)?n.agent:r[0]??``)):(u(``),f(r[0]??``)))},[e,t,n,r]);let p=l.split(`,`).map(e=>e.trim()).filter(Boolean),m=p.filter(e=>!De.test(e)),h=p.length>0&&m.length===0&&r.includes(d);return(0,W.jsx)(N,{open:e,onOpenChange:e=>{e||a()},children:(0,W.jsxs)(M,{movableResizable:!0,className:`max-w-md`,children:[(0,W.jsxs)(j,{children:[(0,W.jsx)(A,{children:c(t===`edit`?`routingRule.editTitle`:`routingRule.addTitle`)}),(0,W.jsx)(k,{children:c(t===`edit`?`routingRule.editDescription`:`routingRule.addDescription`)})]}),(0,W.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:c(`routingRule.tagsLabel`)}),(0,W.jsx)(se,{autoFocus:!0,value:l,onChange:e=>u(e.target.value),placeholder:`frontend, ui`,"aria-label":c(`routingRule.tagsLabel`),className:`text-sm font-mono`}),(0,W.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,W.jsx)(o,{t:c,i18nKey:`routingRule.tagsHint`,components:{code:(0,W.jsx)(`code`,{})}})}),m.length>0&&(0,W.jsx)(`p`,{className:`text-[11px] text-red-400 aurora-light:text-destructive mt-1`,children:c(`routingRule.invalidTags`,{count:m.length,tags:m.join(`, `)})})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:c(`routingRule.routeToLabel`)}),(0,W.jsx)(`select`,{value:d,onChange:e=>f(e.target.value),"aria-label":c(`routingRule.routeToLabel`),className:`w-full h-9 px-2 text-sm rounded-md border border-border bg-background`,children:r.map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))}),(0,W.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:c(`routingRule.routeToHint`)})]})]}),(0,W.jsxs)(O,{children:[(0,W.jsx)(P,{variant:`ghost`,size:`sm`,onClick:a,children:c(`common:actions.cancel`)}),(0,W.jsx)(P,{size:`sm`,onClick:()=>i(p,d),disabled:!h,children:c(t===`edit`?`routingRule.saveChanges`:`routingRule.addRule`)})]})]})})}var ke=new Set([`sr-architect`,`sr-developer`,`sr-reviewer`,`sr-merge-resolver`]),Ae=[`sonnet`,`fable`,`opus`,`haiku`],je=/^[a-z0-9][a-z0-9-]*$/,Me=Ae.map(e=>({value:e,label:e})),Ne=[...ke];function Pe({profile:e,onChange:t,footer:n,provider:r=e.provider??`claude`,modelCatalog:i=Me,defaultModel:a=i[0]?.value??``,customModelAliases:c=!1,baselineAgents:u=Ne,onValidityChange:d,onSoftWarningsChange:f}){let{t:p}=s(`agentstudio`),[m,h]=(0,U.useState)([]),[g,_]=(0,U.useState)(!1),[v,y]=(0,U.useState)(!1),[b,x]=(0,U.useState)(null),S=(0,U.useMemo)(()=>new Set(u),[u]);(0,U.useEffect)(()=>{let e=!1;return fetch(`${l()}/profiles/catalog?provider=${encodeURIComponent(r)}`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||h(t.agents)}).catch(()=>{e||h([])}),()=>{e=!0}},[r]);let C=n=>{let r=JSON.parse(JSON.stringify(e));n(r),t(r)},te=new Set(e.agents.map(e=>e.id)),w=m.filter(e=>!te.has(e.id)),T=(0,U.useMemo)(()=>{let t=[];for(let n of S)e.agents.some(e=>e.id===n)||t.push(p(`profileEditor.validation.missingBaseline`,{agent:n}));let n=e.routing.filter(e=>`default`in e&&e.default===!0);if(n.length>1&&t.push(p(`profileEditor.validation.multipleDefaultRules`,{found:n.length})),n.length===1){let n=e.routing[e.routing.length-1];`default`in n&&n.default===!0||t.push(p(`profileEditor.validation.defaultRuleNotLast`))}for(let n of e.routing)if(e.agents.some(e=>e.id===n.agent)||t.push(p(`profileEditor.validation.unknownRoutingAgent`,{agent:n.agent})),`tags`in n){let e=n.tags.filter(e=>!je.test(e));e.length>0&&t.push(p(`profileEditor.validation.invalidTags`,{agent:n.agent,tags:e.join(`, `)}))}return t},[e,S,p]),E=(0,U.useMemo)(()=>{if(e.routing.length===0)return[];let t=new Set(e.routing.map(e=>e.agent));return e.agents.filter(e=>!S.has(e.id)&&!t.has(e.id)).map(e=>e.id)},[e,S]),D=(0,U.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,U.useEffect)(()=>{d&&d(T)},[T,d]),(0,U.useEffect)(()=>{f&&f({agentsMissingRouting:E})},[E,f]);let O=e=>{C(t=>{let n={id:e,model:a},r=t.agents.findIndex(e=>e.id===`sr-merge-resolver`);r>=0?t.agents.splice(r,0,n):t.agents.push(n)}),_(!1)},k=t=>{let n=e.agents[t];S.has(n.id)||C(e=>{e.agents.splice(t,1),e.routing=e.routing.filter(e=>e.agent!==n.id)})},re=(t,n)=>{if(t===n)return;let r=e.agents.findIndex(e=>e.id===t),i=e.agents.findIndex(e=>e.id===n);if(r<0||i<0)return;let a=Se(e.agents,r,i),o=a.findIndex(e=>e.id===`sr-architect`);if(o>0){let[e]=a.splice(o,1);a.unshift(e)}let s=a.findIndex(e=>e.id===`sr-merge-resolver`);if(s>=0&&s!==a.length-1){let[e]=a.splice(s,1);a.push(e)}C(e=>{e.agents=a})},A=le(R(F,{activationConstraint:{distance:4}}),R(V,{coordinateGetter:he})),j=e=>{let{active:t,over:n}=e;n&&re(String(t.id),String(n.id))},M=(e,t)=>{C(n=>{n.agents[e].model=t})},N=(e,t)=>{C(n=>{let r={tags:e,agent:t},i=n.routing.findIndex(e=>`default`in e&&e.default===!0);i>=0?n.routing.splice(i,0,r):n.routing.push(r)}),y(!1)},oe=()=>{C(e=>{e.routing.some(e=>`default`in e&&e.default===!0)||e.agents.some(e=>e.id===`sr-developer`)&&e.routing.push({default:!0,agent:`sr-developer`})})},I=e=>`default`in e&&e.default===!0,L=(e,t)=>{C(n=>{let r=n.routing[e];r&&(I(r)||(r.agent=t))})},ce=(e,t,n)=>{C(r=>{let i=r.routing[e];i&&(I(i)||(i.tags=t,i.agent=n))})},de=e=>{C(t=>{let n=t.routing[e];n&&(I(n)||t.routing.splice(e,1))})},fe=(t,n)=>{let r=t+n;if(r<0||r>=e.routing.length)return;let i=e.routing[t],a=e.routing[r];I(i)||I(a)||C(e=>{let[n]=e.routing.splice(t,1);e.routing.splice(r,0,n)})};return(0,W.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,W.jsx)(Oe,{open:v,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:N,onCancel:()=>y(!1)}),(0,W.jsx)(Oe,{open:b!==null,mode:`edit`,initial:b!==null&&e.routing[b]&&!(`default`in e.routing[b])?{tags:e.routing[b].tags,agent:e.routing[b].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{b!==null&&(ce(b,e,t),x(null))},onCancel:()=>x(null)}),T.length>0&&(0,W.jsxs)(`div`,{className:`px-3 py-2 text-xs rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:[(0,W.jsx)(`div`,{className:`font-medium mb-1`,children:p(`profileEditor.validationSummary`,{count:T.length})}),(0,W.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:T.map((e,t)=>(0,W.jsx)(`li`,{children:e},t))})]}),(0,W.jsxs)(`section`,{className:`space-y-3`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:p(`profileEditor.nameLabel`)}),(0,W.jsx)(se,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:p(`profileEditor.descriptionLabel`)}),(0,W.jsx)(se,{value:e.description??``,onChange:e=>C(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:p(`profileEditor.descriptionPlaceholder`)})]})]}),(0,W.jsxs)(`section`,{children:[(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:p(`profileEditor.legacyWorkflowNotice`)}),(0,W.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:p(`profileEditor.orchestrator.heading`)}),(0,W.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsx)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:Te(`/specrails:implement`,r)}),(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:p(`profileEditor.orchestrator.description`)})]}),(0,W.jsx)(G,{value:e.orchestrator.model,models:i,customModelAliases:c,testId:`profile-orchestrator-model`,onChange:e=>C(t=>{t.orchestrator.model=e})})]})]}),(0,W.jsxs)(`section`,{children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,W.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:p(`profileEditor.agentChain.heading`,{n:e.agents.length})}),(0,W.jsxs)(P,{size:`sm`,variant:`ghost`,onClick:()=>_(e=>!e),disabled:w.length===0,title:w.length===0?p(`profileEditor.agentChain.addDisabledTitle`):p(`profileEditor.agentChain.addTitle`),children:[(0,W.jsx)(ee,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`common:actions.add`)]})]}),g&&(0,W.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,W.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:p(`profileEditor.agentChain.pickFromCatalog`,{n:w.length})}),(0,W.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>_(!1),title:p(`common:actions.close`),children:(0,W.jsx)(ne,{className:`w-3 h-3`})})]}),w.length===0?(0,W.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:p(`profileEditor.agentChain.emptyCatalog`)}):(0,W.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:w.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>O(e.id),className:`w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left rounded hover:bg-accent transition-colors`,children:[(0,W.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,W.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded `+(e.kind===`custom`?`bg-purple-500/15 aurora-light:bg-accent-secondary/15 text-purple-400 aurora-light:text-accent-secondary`:`bg-muted text-muted-foreground`),children:p(`profileEditor.agentChain.kind.${e.kind}`)})]},e.id))})]}),(0,W.jsx)(ue,{sensors:A,collisionDetection:ye,onDragEnd:j,children:(0,W.jsx)(ie,{items:e.agents.map(e=>e.id),strategy:ae,children:(0,W.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,W.jsx)(Fe,{agent:e,required:S.has(e.id),canRemove:!S.has(e.id),models:i,defaultModel:a,customModelAliases:c,onModel:e=>M(t,e),onRemove:()=>k(t)},e.id))})})})]}),(0,W.jsxs)(`section`,{children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,W.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:p(`profileEditor.routing.heading`,{n:e.routing.length})}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!D&&(0,W.jsxs)(P,{size:`sm`,variant:`ghost`,onClick:oe,disabled:e.agents.length===0,title:e.agents.length===0?p(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,W.jsx)(ee,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`profileEditor.routing.addDefault`)]}),(0,W.jsxs)(P,{size:`sm`,variant:`ghost`,onClick:()=>y(!0),disabled:e.agents.length===0,title:e.agents.length===0?p(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,W.jsx)(ee,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`profileEditor.routing.addRule`)]})]})]}),(0,W.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:p(`profileEditor.routing.explainer`)}),E.length>0&&(0,W.jsxs)(`div`,{className:`mb-2 px-3 py-2 text-xs rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:[(0,W.jsx)(`div`,{className:`font-medium mb-1`,children:p(`profileEditor.routing.untargetedTitle`)}),(0,W.jsx)(`div`,{children:(0,W.jsx)(o,{t:p,i18nKey:`profileEditor.routing.untargetedDetail`,values:{agents:E.join(`, `)},components:{mono:(0,W.jsx)(`span`,{className:`font-mono`})}})})]}),(0,W.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,W.jsx)(Ie,{rule:t,ordinal:n+1,isLast:n===e.routing.length-1,canMove:!r,canRemove:!r,canEdit:!r,chainAgents:e.agents.map(e=>e.id),onAgentChange:e=>L(n,e),onEdit:()=>x(n),onUp:()=>fe(n,-1),onDown:()=>fe(n,1),onRemove:()=>de(n)},n)})})]}),n&&(0,W.jsx)(`div`,{className:`pt-3 border-t border-border`,children:n})]})}function Fe({agent:e,required:t,canRemove:n,models:r,defaultModel:i,customModelAliases:a,onModel:o,onRemove:c}){let{t:l}=s(`agentstudio`),u=t,d=e.id===`sr-architect`,f=e.id===`sr-merge-resolver`,{attributes:p,listeners:m,setNodeRef:h,transform:g,transition:_,isDragging:v}=I({id:e.id});return(0,W.jsxs)(`div`,{ref:h,style:{transform:fe.Transform.toString(g),transition:_,opacity:v?.5:void 0,zIndex:v?10:void 0},className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors bg-background`,children:[(0,W.jsx)(`button`,{type:`button`,className:`flex-shrink-0 p-0.5 rounded text-muted-foreground cursor-grab active:cursor-grabbing hover:text-foreground`,title:l(`profileEditor.agentRow.dragTitle`),"aria-label":l(`profileEditor.agentRow.dragHandleAria`),...p,...m,children:(0,W.jsx)(de,{className:`w-3.5 h-3.5`})}),(0,W.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),d&&(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:l(`profileEditor.agentRow.pinnedFirstTitle`),children:[(0,W.jsx)(B,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` `,l(`profileEditor.agentRow.pinnedFirst`)]}),f&&(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:l(`profileEditor.agentRow.pinnedLastTitle`),children:[(0,W.jsx)(B,{className:`w-2.5 h-2.5 rotate-45`}),` `,l(`profileEditor.agentRow.pinnedLast`)]}),u&&!d&&!f&&(0,W.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:l(`profileEditor.agentRow.required`)}),(0,W.jsx)(G,{value:e.model??i,models:r,customModelAliases:a,testId:`profile-agent-model-${e.id}`,onChange:o}),(0,W.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 aurora-light:hover:bg-destructive/15 text-red-400 aurora-light:text-destructive rounded disabled:opacity-30 disabled:cursor-not-allowed opacity-0 group-hover:opacity-100 transition-opacity`,onClick:c,disabled:!n,title:l(n?`common:actions.remove`:`profileEditor.agentRow.requiredRemoveTitle`),children:(0,W.jsx)(ne,{className:`w-3 h-3`})})]})}function Ie({rule:e,ordinal:t,isLast:n,canMove:r,canRemove:i,canEdit:a,chainAgents:o,onAgentChange:c,onEdit:l,onUp:u,onDown:d,onRemove:f}){let{t:p}=s(`agentstudio`),m=`default`in e&&e.default===!0;return(0,W.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors`,children:[(0,W.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[t,`.`]}),m?(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:p(`profileEditor.routingRow.everythingElse`)}):(0,W.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,W.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),m?(0,W.jsx)(`span`,{className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-muted/40 text-muted-foreground inline-flex items-center`,"aria-label":p(`profileEditor.routingRow.defaultTargetAria`),title:p(`profileEditor.routingRow.defaultTargetTitle`),children:e.agent}):(0,W.jsx)(`select`,{value:e.agent,onChange:e=>c(e.target.value),"aria-label":p(`profileEditor.routingRow.targetAria`,{ordinal:t}),className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-background`,children:o.map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))}),(0,W.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[a&&(0,W.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:p(`profileEditor.routingRow.editTitle`),"aria-label":p(`profileEditor.routingRow.editAria`,{ordinal:t}),children:(0,W.jsx)(C,{className:`w-3 h-3`})}),r&&!n&&(0,W.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:d,title:p(`profileEditor.routingRow.moveDown`),children:(0,W.jsx)(L,{className:`w-3 h-3`})}),r&&t>1&&(0,W.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:p(`profileEditor.routingRow.moveUp`),children:(0,W.jsx)(_,{className:`w-3 h-3`})}),i&&(0,W.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 aurora-light:hover:bg-destructive/15 text-red-400 aurora-light:text-destructive rounded`,onClick:f,title:p(`common:actions.remove`),children:(0,W.jsx)(ne,{className:`w-3 h-3`})})]}),m&&(0,W.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:p(`profileEditor.routingRow.coreDefaultTitle`),children:p(`profileEditor.routingRow.coreDefaultBadge`)})]})}function G({value:e,models:t,customModelAliases:n,testId:r,onChange:i}){return n?(0,W.jsx)(ge,{value:e,options:t,ariaLabel:`Model alias`,testId:r,className:`h-7 w-52 bg-background px-2 text-xs`,onCommit:i}):(0,W.jsx)(`select`,{value:e,onChange:e=>i(e.target.value),className:`h-7 px-2 text-xs rounded border border-border bg-background`,children:(t.some(t=>t.value===e)?t:[...t,{value:e,label:e}]).map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})}function Le({open:e,title:t,description:n,placeholder:r,initialValue:i=``,confirmLabel:a,inputPattern:o,inputInvalidHint:c,onConfirm:l,onCancel:u}){let{t:d}=s(),[f,p]=(0,U.useState)(i);(0,U.useEffect)(()=>{e&&p(i)},[e,i]);let m=f.trim(),h=!o||o.test(m),g=m.length>0&&h;return(0,W.jsx)(N,{open:e,onOpenChange:e=>{e||u()},children:(0,W.jsxs)(M,{movableResizable:!0,className:`max-w-md`,children:[(0,W.jsx)(j,{children:(0,W.jsx)(A,{children:t})}),(0,W.jsxs)(`div`,{className:`py-2 space-y-2`,children:[n&&(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}),(0,W.jsx)(se,{autoFocus:!0,value:f,placeholder:r,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&g&&l(m)},className:`text-sm font-mono`}),m.length>0&&!h&&c&&(0,W.jsx)(`p`,{className:`text-[11px] text-yellow-500 aurora-light:text-accent-warning`,children:c})]}),(0,W.jsxs)(O,{children:[(0,W.jsx)(P,{variant:`ghost`,size:`sm`,onClick:u,children:d(`actions.cancel`)}),(0,W.jsx)(P,{size:`sm`,onClick:()=>l(m),disabled:!g,children:a??d(`actions.confirm`)})]})]})})}function Re({open:e,title:t,description:n,confirmLabel:r,destructive:i=!1,onConfirm:a,onCancel:o}){let{t:c}=s();return(0,W.jsx)(N,{open:e,onOpenChange:e=>{e||o()},children:(0,W.jsxs)(M,{movableResizable:!0,className:`max-w-md`,children:[(0,W.jsx)(j,{children:(0,W.jsx)(A,{children:t})}),n&&(0,W.jsx)(`div`,{className:`py-2`,children:(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})}),(0,W.jsxs)(O,{children:[(0,W.jsx)(P,{variant:`ghost`,size:`sm`,onClick:o,children:c(`actions.cancel`)}),(0,W.jsx)(P,{size:`sm`,onClick:a,className:i?`bg-red-500 hover:bg-red-600 text-white`:void 0,children:r??c(`actions.confirm`)})]})]})})}var ze={models:Ae.map(e=>({value:e,label:e})),defaultModel:`sonnet`,baselineAgents:[...ke],customModelAliases:!1},Be={primaryProvider:`claude`,providers:[`claude`],catalogs:{claude:ze}};function Ve(e,t,n){return{schemaVersion:1,name:e,description:``,provider:t,orchestrator:{model:n.defaultModel},agents:n.baselineAgents.map(e=>({id:e,model:n.defaultModel,required:!0})),routing:[{default:!0,agent:`sr-developer`}]}}function He(){let{t:e}=s(`agents`),[t,n]=(0,U.useState)([]),[r,i]=(0,U.useState)(Be),[a,c]=(0,U.useState)(``),[u,f]=(0,U.useState)(null),[m,g]=(0,U.useState)(null),[_,v]=(0,U.useState)(!0),[y,b]=(0,U.useState)(null),[x,S]=(0,U.useState)(!1),[C,te]=(0,U.useState)([]),[w,E]=(0,U.useState)([]),[ne,D]=(0,U.useState)(!1),[O,k]=(0,U.useState)(null),[re,A]=(0,U.useState)(null),j=a,M=r.catalogs[j]??ze;(0,U.useEffect)(()=>{let e=!1;return fetch(`${l()}/profiles/context`).then(e=>{if(!e.ok)throw Error(`profile context unavailable`);return e.json()}).then(t=>{if(e)return;let n=Array.isArray(t.providers)&&t.providers.length>0?t.providers:[t.primaryProvider||`claude`],r=n.includes(t.primaryProvider)?t.primaryProvider:n[0];i({...t,providers:n,primaryProvider:r}),c(r)}).catch(()=>{e||(i(Be),c(Be.primaryProvider))}),()=>{e=!0}},[]);let N=(0,U.useCallback)(async()=>{if(j){v(!0),b(null);try{let t=await fetch(`${l()}/profiles?provider=${encodeURIComponent(j)}`);if(!t.ok)throw Error(e(`profiles.errors.listFailed`,{status:t.status}));let r=await t.json();n(r.profiles),f(e=>e&&r.profiles.some(t=>t.name===e)?e:r.profiles[0]?.name??null)}catch(e){b(e.message)}finally{v(!1)}}},[j,e]);(0,U.useEffect)(()=>{j&&N()},[j,N]),(0,U.useEffect)(()=>{if(!u){g(null);return}let t=!1;return fetch(`${l()}/profiles/${encodeURIComponent(u)}?provider=${encodeURIComponent(j)}`).then(t=>{if(!t.ok)throw Error(e(`profiles.errors.loadFailed`,{status:t.status}));return t.json()}).then(e=>{t||g(e.profile)}).catch(e=>{t||b(e.message)}),()=>{t=!0}},[j,u,e]);let F=(0,U.useCallback)(async()=>{S(!0),b(null);try{let t=await fetch(`${l()}/profiles/migrate-from-settings?provider=${encodeURIComponent(j)}`,{method:`POST`});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`profiles.errors.migrationFailed`,{status:t.status}))}await N(),f(`default`),d.success(e(`profiles.toasts.migrated`),{description:e(`profiles.toasts.migratedDescription`)})}catch(t){let n=t.message;b(n),d.error(e(`profiles.toasts.migrationFailed`),{description:n})}finally{S(!1)}},[j,N,e]),ie=(0,U.useCallback)(async t=>{D(!1),S(!0),b(null);try{let n=Ve(t,j,M),r=await fetch(`${l()}/profiles?provider=${encodeURIComponent(j)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.createFailed`,{status:r.status}))}await N(),f(t),d.success(e(`profiles.toasts.created`),{description:t})}catch(t){let n=t.message;b(n),d.error(e(`profiles.toasts.createFailed`),{description:n})}finally{S(!1)}},[M,j,N,e]),ae=(0,U.useCallback)(async(t,n)=>{k(null),S(!0),b(null);try{let r=await fetch(`${l()}/profiles/${encodeURIComponent(t)}/duplicate?provider=${encodeURIComponent(j)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n,provider:j})});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.duplicateFailed`,{status:r.status}))}await N(),f(n),d.success(e(`profiles.toasts.duplicated`),{description:e(`profiles.toasts.duplicatedDescription`,{from:t,to:n})})}catch(t){let n=t.message;b(n),d.error(e(`profiles.toasts.duplicateFailed`),{description:n})}finally{S(!1)}},[j,N,e]),oe=(0,U.useCallback)(async t=>{A(null),S(!0),b(null);try{let n=await fetch(`${l()}/profiles/${encodeURIComponent(t)}?provider=${encodeURIComponent(j)}`,{method:`DELETE`});if(!n.ok){let t=await n.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.deleteFailed`,{status:n.status}))}f(e=>e===t?null:e),await N(),d.success(e(`profiles.toasts.deleted`),{description:t})}catch(t){let n=t.message;b(n),d.error(e(`profiles.toasts.deleteFailed`),{description:n})}finally{S(!1)}},[j,N,e]),I=(0,U.useCallback)(()=>D(!0),[]),L=(0,U.useCallback)(e=>k({from:e}),[]),se=(0,U.useCallback)(e=>A({name:e}),[]),ce=(0,U.useCallback)(async(t,n)=>{S(!0),b(null);try{let r=await fetch(`${l()}/profiles/${encodeURIComponent(t.name)}?provider=${encodeURIComponent(j)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...t,provider:j})});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.saveFailed`,{status:r.status}))}g(t),n.length>0?d.warning(e(`profiles.toasts.savedWithUntargeted`),{description:e(`profiles.toasts.savedWithUntargetedDescription`,{agents:n.join(`, `)}),duration:6e3}):d.success(e(`profiles.toasts.saved`),{description:t.name})}catch(t){let n=t.message;b(n),d.error(e(`profiles.toasts.saveFailed`),{description:n})}finally{S(!1)}},[j,e]),R=(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(Le,{open:ne,title:e(`profiles.createDialog.title`),description:e(`profiles.createDialog.description`),placeholder:`my-profile`,confirmLabel:e(`profiles.createDialog.confirmLabel`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.createDialog.invalidHint`),onConfirm:e=>void ie(e),onCancel:()=>D(!1)}),O&&(0,W.jsx)(Le,{open:!0,title:e(`profiles.duplicateDialog.title`,{name:O.from}),description:e(`profiles.duplicateDialog.description`),placeholder:`${O.from}-copy`,initialValue:`${O.from}-copy`,confirmLabel:e(`common:actions.duplicate`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.duplicateDialog.invalidHint`),onConfirm:e=>void ae(O.from,e),onCancel:()=>k(null)}),re&&(0,W.jsx)(Re,{open:!0,title:e(`profiles.deleteDialog.title`,{name:re.name}),description:e(`profiles.deleteDialog.description`),confirmLabel:e(`common:actions.delete`),destructive:!0,onConfirm:()=>void oe(re.name),onCancel:()=>A(null)})]});return _?(0,W.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.loading`)})}):t.length===0?(0,W.jsxs)(W.Fragment,{children:[R,(0,W.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,W.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,W.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`profiles.empty.title`)}),(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:e(`profiles.empty.body`)}),r.providers.length>1&&(0,W.jsx)(`select`,{value:j,"aria-label":e(`profiles.providerLabel`),onChange:e=>{f(null),g(null),c(e.target.value)},className:`mb-4 h-8 w-full rounded border border-border bg-background px-2 text-xs`,children:r.providers.map(e=>(0,W.jsx)(`option`,{value:e,children:p(e)},e))}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,W.jsxs)(P,{size:`sm`,onClick:F,disabled:x,children:[(0,W.jsx)(be,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.migrateButton`)]}),(0,W.jsxs)(P,{size:`sm`,variant:`ghost`,onClick:I,disabled:x,children:[(0,W.jsx)(ee,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.blankButton`)]})]}),(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:(0,W.jsx)(o,{t:e,i18nKey:`profiles.empty.migrateExplainer`,components:{code:(0,W.jsx)(`code`,{className:`text-foreground`})}})}),y&&(0,W.jsx)(`div`,{className:`mt-3 text-xs text-red-400 aurora-light:text-destructive`,children:y})]})})]}):(0,W.jsxs)(`div`,{className:`flex flex-col h-full`,children:[R,(0,W.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,W.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,W.jsxs)(`div`,{className:`p-3 space-y-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e(`profiles.sidebar.title`)}),(0,W.jsx)(P,{size:`sm`,variant:`ghost`,onClick:I,disabled:x,children:(0,W.jsx)(ee,{className:`w-3.5 h-3.5`})})]}),r.providers.length>1&&(0,W.jsx)(`select`,{value:j,"aria-label":e(`profiles.providerLabel`),onChange:e=>{f(null),g(null),c(e.target.value)},className:`h-7 w-full rounded border border-border bg-background px-2 text-xs`,children:r.providers.map(e=>(0,W.jsx)(`option`,{value:e,children:p(e)},e))})]}),(0,W.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:t.map(t=>(0,W.jsxs)(`div`,{className:`group mb-1 rounded-md px-2 py-1.5 text-xs cursor-pointer transition-colors flex items-center justify-between `+(t.name===u?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),onClick:()=>f(t.name),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&f(t.name)},children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,W.jsx)(`span`,{className:`truncate font-medium`,children:t.name}),t.isDefault&&(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e(`profiles.sidebar.teamDefault`)})]}),(0,W.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,W.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,title:e(`common:actions.duplicate`),onClick:e=>{e.stopPropagation(),L(t.name)},children:(0,W.jsx)(pe,{className:`w-3 h-3`})}),!t.isDefault&&(0,W.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 aurora-light:text-destructive rounded`,title:e(`common:actions.delete`),onClick:e=>{e.stopPropagation(),se(t.name)},children:(0,W.jsx)(T,{className:`w-3 h-3`})})]})]},t.name))})]}),(0,W.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[y&&(0,W.jsx)(`div`,{className:`mx-4 mt-4 px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:y}),m?(0,W.jsx)(Pe,{profile:m,provider:j,modelCatalog:M.models,defaultModel:M.defaultModel,customModelAliases:M.customModelAliases===!0,baselineAgents:M.baselineAgents,onChange:g,onValidityChange:te,onSoftWarningsChange:e=>E(e.agentsMissingRouting),footer:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsxs)(P,{size:`sm`,onClick:()=>void ce(m,w),disabled:x||C.length>0,title:C.length>0?e(`profiles.editorFooter.fixValidationIssues`):void 0,children:[(0,W.jsx)(h,{className:`w-3.5 h-3.5 mr-1.5`}),e(`common:actions.save`)]}),x&&(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`common:states.saving`)}),C.length>0&&(0,W.jsx)(`span`,{className:`text-xs text-yellow-500 aurora-light:text-accent-warning`,children:e(`profiles.editorFooter.issuesToResolve`,{count:C.length})})]})},`${j}:${m.name}`):(0,W.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.selectPrompt`)})})]})]})]})}function Ue(e){return e==null}function We(e){return typeof e==`object`&&!!e}function Ge(e){return Array.isArray(e)?e:Ue(e)?[]:[e]}function Ke(e,t){var n,r,i,a;if(t)for(a=Object.keys(t),n=0,r=a.length;n<r;n+=1)i=a[n],e[i]=t[i];return e}function qe(e,t){var n=``,r;for(r=0;r<t;r+=1)n+=e;return n}function Je(e){return e===0&&1/e==-1/0}var K={isNothing:Ue,isObject:We,toArray:Ge,repeat:qe,isNegativeZero:Je,extend:Ke};function Ye(e,t){var n=``,r=e.reason||`(unknown reason)`;return e.mark?(e.mark.name&&(n+=`in "`+e.mark.name+`" `),n+=`(`+(e.mark.line+1)+`:`+(e.mark.column+1)+`)`,!t&&e.mark.snippet&&(n+=`
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{t as r}from"./react-dom-DiWzBDP9.js";import{h as i,r as a}from"./useSharedWebSocket-TzKtPRp9.js";import{t as o}from"./Trans-DExd3Z00.js";import{n as s,t as c}from"./createLucideIcon-Bjbbp_KS.js";import{a as l,r as u,s as d}from"./useDesktop-D07TvesS.js";import{c as f,s as p}from"./provider-capabilities-lePfeT_Y.js";import{n as m,r as h,t as g}from"./save-OsUqVn99.js";import{l as _,n as v,r as y,u as b}from"./MinimizedChatsContext-D_8L4EWZ.js";import{n as x,t as S}from"./file-text-BcLCfcWZ.js";import{t as C}from"./external-link-D6XxC_Cu.js";import{t as ee}from"./loader-circle-DcygOQpC.js";import{t as te}from"./pencil-C9RkrIPZ.js";import{t as ne}from"./plus-CsnjfkmX.js";import{t as re}from"./search-Cq_gE3Ik.js";import{t as w}from"./sparkles-DrY8hb0X.js";import{t as T}from"./trash-2-BOU3WdZZ.js";import{t as E}from"./triangle-alert-H9T4jAmh.js";import{t as D}from"./x-CBMI9ejn.js";import{F as O,P as k,a as A,i as j,l as M,o as N,r as P,t as F}from"./dialog-CMgps2MY.js";import{t as I}from"./button-D1xExSTF.js";import{A as ie,B as L,D as ae,Dt as R,F as oe,Ht as se,I as ce,It as z,Kt as le,L as ue,M as de,N as fe,Ot as pe,P as me,Pt as he,Qt as ge,R as B,U as _e,V as ve,X as V,_ as H,_t as ye,at as be,j as xe,mt as Se,wt as Ce,z as we}from"./index-JSTZVJfe.js";import{t as Te}from"./format-command-C0D9IPmV.js";var Ee=c(`flask-conical`,[[`path`,{d:`M14 2v6a2 2 0 0 0 .245.96l5.51 10.08A2 2 0 0 1 18 22H6a2 2 0 0 1-1.755-2.96l5.51-10.08A2 2 0 0 0 10 8V2`,key:`18mbvz`}],[`path`,{d:`M6.453 15h11.094`,key:`3shlmq`}],[`path`,{d:`M8.5 2h7`,key:`csnxdl`}]]),U=e(t(),1),W=n(),De=/^[a-z0-9][a-z0-9-]*$/;function Oe({open:e,mode:t=`add`,initial:n,chainAgents:r,onConfirm:i,onCancel:a}){let{t:c}=s(`agents`),[l,u]=(0,U.useState)(``),[d,f]=(0,U.useState)(r[0]??``);(0,U.useEffect)(()=>{e&&(t===`edit`&&n?(u(n.tags.join(`, `)),f(r.includes(n.agent)?n.agent:r[0]??``)):(u(``),f(r[0]??``)))},[e,t,n,r]);let p=l.split(`,`).map(e=>e.trim()).filter(Boolean),m=p.filter(e=>!De.test(e)),h=p.length>0&&m.length===0&&r.includes(d);return(0,W.jsx)(F,{open:e,onOpenChange:e=>{e||a()},children:(0,W.jsxs)(P,{movableResizable:!0,className:`max-w-md`,children:[(0,W.jsxs)(N,{children:[(0,W.jsx)(M,{children:c(t===`edit`?`routingRule.editTitle`:`routingRule.addTitle`)}),(0,W.jsx)(j,{children:c(t===`edit`?`routingRule.editDescription`:`routingRule.addDescription`)})]}),(0,W.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:c(`routingRule.tagsLabel`)}),(0,W.jsx)(_e,{autoFocus:!0,value:l,onChange:e=>u(e.target.value),placeholder:`frontend, ui`,"aria-label":c(`routingRule.tagsLabel`),className:`text-sm font-mono`}),(0,W.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,W.jsx)(o,{t:c,i18nKey:`routingRule.tagsHint`,components:{code:(0,W.jsx)(`code`,{})}})}),m.length>0&&(0,W.jsx)(`p`,{className:`text-[11px] text-red-400 aurora-light:text-destructive mt-1`,children:c(`routingRule.invalidTags`,{count:m.length,tags:m.join(`, `)})})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:c(`routingRule.routeToLabel`)}),(0,W.jsx)(`select`,{value:d,onChange:e=>f(e.target.value),"aria-label":c(`routingRule.routeToLabel`),className:`w-full h-9 px-2 text-sm rounded-md border border-border bg-background`,children:r.map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))}),(0,W.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:c(`routingRule.routeToHint`)})]})]}),(0,W.jsxs)(A,{children:[(0,W.jsx)(I,{variant:`ghost`,size:`sm`,onClick:a,children:c(`common:actions.cancel`)}),(0,W.jsx)(I,{size:`sm`,onClick:()=>i(p,d),disabled:!h,children:c(t===`edit`?`routingRule.saveChanges`:`routingRule.addRule`)})]})]})})}var ke=new Set([`sr-architect`,`sr-developer`,`sr-reviewer`,`sr-merge-resolver`]),Ae=[`sonnet`,`fable`,`opus`,`haiku`],je=/^[a-z0-9][a-z0-9-]*$/,Me=Ae.map(e=>({value:e,label:e})),Ne=[...ke];function Pe({profile:e,onChange:t,footer:n,provider:r=e.provider??`claude`,modelCatalog:i=Me,defaultModel:a=i[0]?.value??``,customModelAliases:c=!1,baselineAgents:u=Ne,onValidityChange:d,onSoftWarningsChange:f}){let{t:p}=s(`agentstudio`),[m,h]=(0,U.useState)([]),[g,_]=(0,U.useState)(!1),[v,y]=(0,U.useState)(!1),[b,x]=(0,U.useState)(null),S=(0,U.useMemo)(()=>new Set(u),[u]);(0,U.useEffect)(()=>{let e=!1;return fetch(`${l()}/profiles/catalog?provider=${encodeURIComponent(r)}`).then(e=>e.ok?e.json():{agents:[]}).then(t=>{e||h(t.agents)}).catch(()=>{e||h([])}),()=>{e=!0}},[r]);let C=n=>{let r=JSON.parse(JSON.stringify(e));n(r),t(r)},ee=new Set(e.agents.map(e=>e.id)),te=m.filter(e=>!ee.has(e.id)),re=(0,U.useMemo)(()=>{let t=[];for(let n of S)e.agents.some(e=>e.id===n)||t.push(p(`profileEditor.validation.missingBaseline`,{agent:n}));let n=e.routing.filter(e=>`default`in e&&e.default===!0);if(n.length>1&&t.push(p(`profileEditor.validation.multipleDefaultRules`,{found:n.length})),n.length===1){let n=e.routing[e.routing.length-1];`default`in n&&n.default===!0||t.push(p(`profileEditor.validation.defaultRuleNotLast`))}for(let n of e.routing)if(e.agents.some(e=>e.id===n.agent)||t.push(p(`profileEditor.validation.unknownRoutingAgent`,{agent:n.agent})),`tags`in n){let e=n.tags.filter(e=>!je.test(e));e.length>0&&t.push(p(`profileEditor.validation.invalidTags`,{agent:n.agent,tags:e.join(`, `)}))}return t},[e,S,p]),w=(0,U.useMemo)(()=>{if(e.routing.length===0)return[];let t=new Set(e.routing.map(e=>e.agent));return e.agents.filter(e=>!S.has(e.id)&&!t.has(e.id)).map(e=>e.id)},[e,S]),T=(0,U.useMemo)(()=>e.routing.some(e=>`default`in e&&e.default===!0),[e.routing]);(0,U.useEffect)(()=>{d&&d(re)},[re,d]),(0,U.useEffect)(()=>{f&&f({agentsMissingRouting:w})},[w,f]);let E=e=>{C(t=>{let n={id:e,model:a},r=t.agents.findIndex(e=>e.id===`sr-merge-resolver`);r>=0?t.agents.splice(r,0,n):t.agents.push(n)}),_(!1)},O=t=>{let n=e.agents[t];S.has(n.id)||C(e=>{e.agents.splice(t,1),e.routing=e.routing.filter(e=>e.agent!==n.id)})},k=(t,n)=>{if(t===n)return;let r=e.agents.findIndex(e=>e.id===t),i=e.agents.findIndex(e=>e.id===n);if(r<0||i<0)return;let a=xe(e.agents,r,i),o=a.findIndex(e=>e.id===`sr-architect`);if(o>0){let[e]=a.splice(o,1);a.unshift(e)}let s=a.findIndex(e=>e.id===`sr-merge-resolver`);if(s>=0&&s!==a.length-1){let[e]=a.splice(s,1);a.push(e)}C(e=>{e.agents=a})},A=L(we(ue,{activationConstraint:{distance:4}}),we(ce,{coordinateGetter:de})),j=e=>{let{active:t,over:n}=e;n&&k(String(t.id),String(n.id))},M=(e,t)=>{C(n=>{n.agents[e].model=t})},N=(e,t)=>{C(n=>{let r={tags:e,agent:t},i=n.routing.findIndex(e=>`default`in e&&e.default===!0);i>=0?n.routing.splice(i,0,r):n.routing.push(r)}),y(!1)},P=()=>{C(e=>{e.routing.some(e=>`default`in e&&e.default===!0)||e.agents.some(e=>e.id===`sr-developer`)&&e.routing.push({default:!0,agent:`sr-developer`})})},F=e=>`default`in e&&e.default===!0,ae=(e,t)=>{C(n=>{let r=n.routing[e];r&&(F(r)||(r.agent=t))})},R=(e,t,n)=>{C(r=>{let i=r.routing[e];i&&(F(i)||(i.tags=t,i.agent=n))})},se=e=>{C(t=>{let n=t.routing[e];n&&(F(n)||t.routing.splice(e,1))})},z=(t,n)=>{let r=t+n;if(r<0||r>=e.routing.length)return;let i=e.routing[t],a=e.routing[r];F(i)||F(a)||C(e=>{let[n]=e.routing.splice(t,1);e.routing.splice(r,0,n)})};return(0,W.jsxs)(`div`,{className:`p-6 space-y-6 max-w-3xl`,children:[(0,W.jsx)(Oe,{open:v,mode:`add`,chainAgents:e.agents.map(e=>e.id),onConfirm:N,onCancel:()=>y(!1)}),(0,W.jsx)(Oe,{open:b!==null,mode:`edit`,initial:b!==null&&e.routing[b]&&!(`default`in e.routing[b])?{tags:e.routing[b].tags,agent:e.routing[b].agent}:void 0,chainAgents:e.agents.map(e=>e.id),onConfirm:(e,t)=>{b!==null&&(R(b,e,t),x(null))},onCancel:()=>x(null)}),re.length>0&&(0,W.jsxs)(`div`,{className:`px-3 py-2 text-xs rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:[(0,W.jsx)(`div`,{className:`font-medium mb-1`,children:p(`profileEditor.validationSummary`,{count:re.length})}),(0,W.jsx)(`ul`,{className:`list-disc list-inside space-y-0.5`,children:re.map((e,t)=>(0,W.jsx)(`li`,{children:e},t))})]}),(0,W.jsxs)(`section`,{className:`space-y-3`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:p(`profileEditor.nameLabel`)}),(0,W.jsx)(_e,{value:e.name,disabled:!0,className:`text-sm`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:p(`profileEditor.descriptionLabel`)}),(0,W.jsx)(_e,{value:e.description??``,onChange:e=>C(t=>{t.description=e.target.value}),className:`text-sm`,placeholder:p(`profileEditor.descriptionPlaceholder`)})]})]}),(0,W.jsxs)(`section`,{children:[(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:p(`profileEditor.legacyWorkflowNotice`)}),(0,W.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide mb-2`,children:p(`profileEditor.orchestrator.heading`)}),(0,W.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-md border border-border`,children:[(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsx)(`div`,{className:`text-sm font-mono text-foreground truncate`,children:Te(`/specrails:implement`,r)}),(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:p(`profileEditor.orchestrator.description`)})]}),(0,W.jsx)(G,{value:e.orchestrator.model,models:i,customModelAliases:c,testId:`profile-orchestrator-model`,onChange:e=>C(t=>{t.orchestrator.model=e})})]})]}),(0,W.jsxs)(`section`,{children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,W.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:p(`profileEditor.agentChain.heading`,{n:e.agents.length})}),(0,W.jsxs)(I,{size:`sm`,variant:`ghost`,onClick:()=>_(e=>!e),disabled:te.length===0,title:te.length===0?p(`profileEditor.agentChain.addDisabledTitle`):p(`profileEditor.agentChain.addTitle`),children:[(0,W.jsx)(ne,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`common:actions.add`)]})]}),g&&(0,W.jsxs)(`div`,{className:`mb-2 p-2 rounded-md border border-border bg-muted/30`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 px-1`,children:[(0,W.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:p(`profileEditor.agentChain.pickFromCatalog`,{n:te.length})}),(0,W.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:()=>_(!1),title:p(`common:actions.close`),children:(0,W.jsx)(D,{className:`w-3 h-3`})})]}),te.length===0?(0,W.jsx)(`div`,{className:`px-2 py-3 text-xs text-muted-foreground text-center`,children:p(`profileEditor.agentChain.emptyCatalog`)}):(0,W.jsx)(`div`,{className:`space-y-0.5 max-h-64 overflow-auto`,children:te.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>E(e.id),className:`w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left rounded hover:bg-accent transition-colors`,children:[(0,W.jsx)(`span`,{className:`text-sm font-mono`,children:e.id}),(0,W.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded `+(e.kind===`custom`?`bg-purple-500/15 aurora-light:bg-accent-secondary/15 text-purple-400 aurora-light:text-accent-secondary`:`bg-muted text-muted-foreground`),children:p(`profileEditor.agentChain.kind.${e.kind}`)})]},e.id))})]}),(0,W.jsx)(oe,{sensors:A,collisionDetection:B,onDragEnd:j,children:(0,W.jsx)(ie,{items:e.agents.map(e=>e.id),strategy:me,children:(0,W.jsx)(`div`,{className:`space-y-1.5`,children:e.agents.map((e,t)=>(0,W.jsx)(Fe,{agent:e,required:S.has(e.id),canRemove:!S.has(e.id),models:i,defaultModel:a,customModelAliases:c,onModel:e=>M(t,e),onRemove:()=>O(t)},e.id))})})})]}),(0,W.jsxs)(`section`,{children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,W.jsx)(`h2`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:p(`profileEditor.routing.heading`,{n:e.routing.length})}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!T&&(0,W.jsxs)(I,{size:`sm`,variant:`ghost`,onClick:P,disabled:e.agents.length===0,title:e.agents.length===0?p(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,W.jsx)(ne,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`profileEditor.routing.addDefault`)]}),(0,W.jsxs)(I,{size:`sm`,variant:`ghost`,onClick:()=>y(!0),disabled:e.agents.length===0,title:e.agents.length===0?p(`profileEditor.routing.needAgentsTitle`):void 0,children:[(0,W.jsx)(ne,{className:`w-3.5 h-3.5 mr-1`}),` `,p(`profileEditor.routing.addRule`)]})]})]}),(0,W.jsx)(`p`,{className:`text-[11px] text-muted-foreground mb-2`,children:p(`profileEditor.routing.explainer`)}),w.length>0&&(0,W.jsxs)(`div`,{className:`mb-2 px-3 py-2 text-xs rounded-md border border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:[(0,W.jsx)(`div`,{className:`font-medium mb-1`,children:p(`profileEditor.routing.untargetedTitle`)}),(0,W.jsx)(`div`,{children:(0,W.jsx)(o,{t:p,i18nKey:`profileEditor.routing.untargetedDetail`,values:{agents:w.join(`, `)},components:{mono:(0,W.jsx)(`span`,{className:`font-mono`})}})})]}),(0,W.jsx)(`div`,{className:`space-y-1.5`,children:e.routing.map((t,n)=>{let r=`default`in t&&t.default===!0;return(0,W.jsx)(Ie,{rule:t,ordinal:n+1,isLast:n===e.routing.length-1,canMove:!r,canRemove:!r,canEdit:!r,chainAgents:e.agents.map(e=>e.id),onAgentChange:e=>ae(n,e),onEdit:()=>x(n),onUp:()=>z(n,-1),onDown:()=>z(n,1),onRemove:()=>se(n)},n)})})]}),n&&(0,W.jsx)(`div`,{className:`pt-3 border-t border-border`,children:n})]})}function Fe({agent:e,required:t,canRemove:n,models:r,defaultModel:i,customModelAliases:a,onModel:o,onRemove:c}){let{t:l}=s(`agentstudio`),u=t,d=e.id===`sr-architect`,f=e.id===`sr-merge-resolver`,{attributes:p,listeners:m,setNodeRef:h,transform:g,transition:_,isDragging:v}=fe({id:e.id});return(0,W.jsxs)(`div`,{ref:h,style:{transform:ve.Transform.toString(g),transition:_,opacity:v?.5:void 0,zIndex:v?10:void 0},className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors bg-background`,children:[(0,W.jsx)(`button`,{type:`button`,className:`flex-shrink-0 p-0.5 rounded text-muted-foreground cursor-grab active:cursor-grabbing hover:text-foreground`,title:l(`profileEditor.agentRow.dragTitle`),"aria-label":l(`profileEditor.agentRow.dragHandleAria`),...p,...m,children:(0,W.jsx)(z,{className:`w-3.5 h-3.5`})}),(0,W.jsx)(`span`,{className:`text-sm font-mono flex-1 truncate`,children:e.id}),d&&(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:l(`profileEditor.agentRow.pinnedFirstTitle`),children:[(0,W.jsx)(R,{className:`w-2.5 h-2.5 rotate-[135deg]`}),` `,l(`profileEditor.agentRow.pinnedFirst`)]}),f&&(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-accent-primary/15 text-accent-primary`,title:l(`profileEditor.agentRow.pinnedLastTitle`),children:[(0,W.jsx)(R,{className:`w-2.5 h-2.5 rotate-45`}),` `,l(`profileEditor.agentRow.pinnedLast`)]}),u&&!d&&!f&&(0,W.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:l(`profileEditor.agentRow.required`)}),(0,W.jsx)(G,{value:e.model??i,models:r,customModelAliases:a,testId:`profile-agent-model-${e.id}`,onChange:o}),(0,W.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 aurora-light:hover:bg-destructive/15 text-red-400 aurora-light:text-destructive rounded disabled:opacity-30 disabled:cursor-not-allowed opacity-0 group-hover:opacity-100 transition-opacity`,onClick:c,disabled:!n,title:l(n?`common:actions.remove`:`profileEditor.agentRow.requiredRemoveTitle`),children:(0,W.jsx)(D,{className:`w-3 h-3`})})]})}function Ie({rule:e,ordinal:t,isLast:n,canMove:r,canRemove:i,canEdit:a,chainAgents:o,onAgentChange:c,onEdit:l,onUp:u,onDown:d,onRemove:f}){let{t:p}=s(`agentstudio`),m=`default`in e&&e.default===!0;return(0,W.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-1.5 rounded-md border border-border group hover:bg-accent/30 transition-colors`,children:[(0,W.jsxs)(`span`,{className:`text-[10px] font-mono text-muted-foreground w-5 text-center flex-shrink-0`,children:[t,`.`]}),m?(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground flex-1`,children:p(`profileEditor.routingRow.everythingElse`)}):(0,W.jsx)(`span`,{className:`text-xs flex-1 flex gap-1 flex-wrap items-center`,children:e.tags.map(e=>(0,W.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-muted font-mono text-[11px]`,children:e},e))}),(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`→`}),m?(0,W.jsx)(`span`,{className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-muted/40 text-muted-foreground inline-flex items-center`,"aria-label":p(`profileEditor.routingRow.defaultTargetAria`),title:p(`profileEditor.routingRow.defaultTargetTitle`),children:e.agent}):(0,W.jsx)(`select`,{value:e.agent,onChange:e=>c(e.target.value),"aria-label":p(`profileEditor.routingRow.targetAria`,{ordinal:t}),className:`h-7 max-w-[15rem] px-2 text-xs font-mono rounded border border-border bg-background`,children:o.map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))}),(0,W.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[a&&(0,W.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:l,title:p(`profileEditor.routingRow.editTitle`),"aria-label":p(`profileEditor.routingRow.editAria`,{ordinal:t}),children:(0,W.jsx)(te,{className:`w-3 h-3`})}),r&&!n&&(0,W.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:d,title:p(`profileEditor.routingRow.moveDown`),children:(0,W.jsx)(ge,{className:`w-3 h-3`})}),r&&t>1&&(0,W.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,onClick:u,title:p(`profileEditor.routingRow.moveUp`),children:(0,W.jsx)(b,{className:`w-3 h-3`})}),i&&(0,W.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 aurora-light:hover:bg-destructive/15 text-red-400 aurora-light:text-destructive rounded`,onClick:f,title:p(`common:actions.remove`),children:(0,W.jsx)(D,{className:`w-3 h-3`})})]}),m&&(0,W.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,title:p(`profileEditor.routingRow.coreDefaultTitle`),children:p(`profileEditor.routingRow.coreDefaultBadge`)})]})}function G({value:e,models:t,customModelAliases:n,testId:r,onChange:i}){return n?(0,W.jsx)(V,{value:e,options:t,ariaLabel:`Model alias`,testId:r,className:`h-7 w-52 bg-background px-2 text-xs`,onCommit:i}):(0,W.jsx)(`select`,{value:e,onChange:e=>i(e.target.value),className:`h-7 px-2 text-xs rounded border border-border bg-background`,children:(t.some(t=>t.value===e)?t:[...t,{value:e,label:e}]).map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))})}function Le({open:e,title:t,description:n,placeholder:r,initialValue:i=``,confirmLabel:a,inputPattern:o,inputInvalidHint:c,onConfirm:l,onCancel:u}){let{t:d}=s(),[f,p]=(0,U.useState)(i);(0,U.useEffect)(()=>{e&&p(i)},[e,i]);let m=f.trim(),h=!o||o.test(m),g=m.length>0&&h;return(0,W.jsx)(F,{open:e,onOpenChange:e=>{e||u()},children:(0,W.jsxs)(P,{movableResizable:!0,className:`max-w-md`,children:[(0,W.jsx)(N,{children:(0,W.jsx)(M,{children:t})}),(0,W.jsxs)(`div`,{className:`py-2 space-y-2`,children:[n&&(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n}),(0,W.jsx)(_e,{autoFocus:!0,value:f,placeholder:r,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&g&&l(m)},className:`text-sm font-mono`}),m.length>0&&!h&&c&&(0,W.jsx)(`p`,{className:`text-[11px] text-yellow-500 aurora-light:text-accent-warning`,children:c})]}),(0,W.jsxs)(A,{children:[(0,W.jsx)(I,{variant:`ghost`,size:`sm`,onClick:u,children:d(`actions.cancel`)}),(0,W.jsx)(I,{size:`sm`,onClick:()=>l(m),disabled:!g,children:a??d(`actions.confirm`)})]})]})})}function Re({open:e,title:t,description:n,confirmLabel:r,destructive:i=!1,onConfirm:a,onCancel:o}){let{t:c}=s();return(0,W.jsx)(F,{open:e,onOpenChange:e=>{e||o()},children:(0,W.jsxs)(P,{movableResizable:!0,className:`max-w-md`,children:[(0,W.jsx)(N,{children:(0,W.jsx)(M,{children:t})}),n&&(0,W.jsx)(`div`,{className:`py-2`,children:(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})}),(0,W.jsxs)(A,{children:[(0,W.jsx)(I,{variant:`ghost`,size:`sm`,onClick:o,children:c(`actions.cancel`)}),(0,W.jsx)(I,{size:`sm`,onClick:a,className:i?`bg-red-500 hover:bg-red-600 text-white`:void 0,children:r??c(`actions.confirm`)})]})]})})}var ze={models:Ae.map(e=>({value:e,label:e})),defaultModel:`sonnet`,baselineAgents:[...ke],customModelAliases:!1},Be={primaryProvider:`claude`,providers:[`claude`],catalogs:{claude:ze}};function Ve(e,t,n){return{schemaVersion:1,name:e,description:``,provider:t,orchestrator:{model:n.defaultModel},agents:n.baselineAgents.map(e=>({id:e,model:n.defaultModel,required:!0})),routing:[{default:!0,agent:`sr-developer`}]}}function He(){let{t:e}=s(`agents`),[t,n]=(0,U.useState)([]),[r,i]=(0,U.useState)(Be),[a,c]=(0,U.useState)(``),[u,f]=(0,U.useState)(null),[m,h]=(0,U.useState)(null),[_,v]=(0,U.useState)(!0),[y,b]=(0,U.useState)(null),[x,S]=(0,U.useState)(!1),[C,ee]=(0,U.useState)([]),[te,re]=(0,U.useState)([]),[w,E]=(0,U.useState)(!1),[D,O]=(0,U.useState)(null),[k,A]=(0,U.useState)(null),j=a,M=r.catalogs[j]??ze;(0,U.useEffect)(()=>{let e=!1;return fetch(`${l()}/profiles/context`).then(e=>{if(!e.ok)throw Error(`profile context unavailable`);return e.json()}).then(t=>{if(e)return;let n=Array.isArray(t.providers)&&t.providers.length>0?t.providers:[t.primaryProvider||`claude`],r=n.includes(t.primaryProvider)?t.primaryProvider:n[0];i({...t,providers:n,primaryProvider:r}),c(r)}).catch(()=>{e||(i(Be),c(Be.primaryProvider))}),()=>{e=!0}},[]);let N=(0,U.useCallback)(async()=>{if(j){v(!0),b(null);try{let t=await fetch(`${l()}/profiles?provider=${encodeURIComponent(j)}`);if(!t.ok)throw Error(e(`profiles.errors.listFailed`,{status:t.status}));let r=await t.json();n(r.profiles),f(e=>e&&r.profiles.some(t=>t.name===e)?e:r.profiles[0]?.name??null)}catch(e){b(e.message)}finally{v(!1)}}},[j,e]);(0,U.useEffect)(()=>{j&&N()},[j,N]),(0,U.useEffect)(()=>{if(!u){h(null);return}let t=!1;return fetch(`${l()}/profiles/${encodeURIComponent(u)}?provider=${encodeURIComponent(j)}`).then(t=>{if(!t.ok)throw Error(e(`profiles.errors.loadFailed`,{status:t.status}));return t.json()}).then(e=>{t||h(e.profile)}).catch(e=>{t||b(e.message)}),()=>{t=!0}},[j,u,e]);let P=(0,U.useCallback)(async()=>{S(!0),b(null);try{let t=await fetch(`${l()}/profiles/migrate-from-settings?provider=${encodeURIComponent(j)}`,{method:`POST`});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`profiles.errors.migrationFailed`,{status:t.status}))}await N(),f(`default`),d.success(e(`profiles.toasts.migrated`),{description:e(`profiles.toasts.migratedDescription`)})}catch(t){let n=t.message;b(n),d.error(e(`profiles.toasts.migrationFailed`),{description:n})}finally{S(!1)}},[j,N,e]),F=(0,U.useCallback)(async t=>{E(!1),S(!0),b(null);try{let n=Ve(t,j,M),r=await fetch(`${l()}/profiles?provider=${encodeURIComponent(j)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.createFailed`,{status:r.status}))}await N(),f(t),d.success(e(`profiles.toasts.created`),{description:t})}catch(t){let n=t.message;b(n),d.error(e(`profiles.toasts.createFailed`),{description:n})}finally{S(!1)}},[M,j,N,e]),ie=(0,U.useCallback)(async(t,n)=>{O(null),S(!0),b(null);try{let r=await fetch(`${l()}/profiles/${encodeURIComponent(t)}/duplicate?provider=${encodeURIComponent(j)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:n,provider:j})});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.duplicateFailed`,{status:r.status}))}await N(),f(n),d.success(e(`profiles.toasts.duplicated`),{description:e(`profiles.toasts.duplicatedDescription`,{from:t,to:n})})}catch(t){let n=t.message;b(n),d.error(e(`profiles.toasts.duplicateFailed`),{description:n})}finally{S(!1)}},[j,N,e]),L=(0,U.useCallback)(async t=>{A(null),S(!0),b(null);try{let n=await fetch(`${l()}/profiles/${encodeURIComponent(t)}?provider=${encodeURIComponent(j)}`,{method:`DELETE`});if(!n.ok){let t=await n.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.deleteFailed`,{status:n.status}))}f(e=>e===t?null:e),await N(),d.success(e(`profiles.toasts.deleted`),{description:t})}catch(t){let n=t.message;b(n),d.error(e(`profiles.toasts.deleteFailed`),{description:n})}finally{S(!1)}},[j,N,e]),ae=(0,U.useCallback)(()=>E(!0),[]),R=(0,U.useCallback)(e=>O({from:e}),[]),oe=(0,U.useCallback)(e=>A({name:e}),[]),ce=(0,U.useCallback)(async(t,n)=>{S(!0),b(null);try{let r=await fetch(`${l()}/profiles/${encodeURIComponent(t.name)}?provider=${encodeURIComponent(j)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...t,provider:j})});if(!r.ok){let t=await r.json().catch(()=>({}));throw Error(t.error??e(`profiles.errors.saveFailed`,{status:r.status}))}h(t),n.length>0?d.warning(e(`profiles.toasts.savedWithUntargeted`),{description:e(`profiles.toasts.savedWithUntargetedDescription`,{agents:n.join(`, `)}),duration:6e3}):d.success(e(`profiles.toasts.saved`),{description:t.name})}catch(t){let n=t.message;b(n),d.error(e(`profiles.toasts.saveFailed`),{description:n})}finally{S(!1)}},[j,e]),z=(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(Le,{open:w,title:e(`profiles.createDialog.title`),description:e(`profiles.createDialog.description`),placeholder:`my-profile`,confirmLabel:e(`profiles.createDialog.confirmLabel`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.createDialog.invalidHint`),onConfirm:e=>void F(e),onCancel:()=>E(!1)}),D&&(0,W.jsx)(Le,{open:!0,title:e(`profiles.duplicateDialog.title`,{name:D.from}),description:e(`profiles.duplicateDialog.description`),placeholder:`${D.from}-copy`,initialValue:`${D.from}-copy`,confirmLabel:e(`common:actions.duplicate`),inputPattern:/^[a-z0-9][a-z0-9-]*$/,inputInvalidHint:e(`profiles.duplicateDialog.invalidHint`),onConfirm:e=>void ie(D.from,e),onCancel:()=>O(null)}),k&&(0,W.jsx)(Re,{open:!0,title:e(`profiles.deleteDialog.title`,{name:k.name}),description:e(`profiles.deleteDialog.description`),confirmLabel:e(`common:actions.delete`),destructive:!0,onConfirm:()=>void L(k.name),onCancel:()=>A(null)})]});return _?(0,W.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.loading`)})}):t.length===0?(0,W.jsxs)(W.Fragment,{children:[z,(0,W.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,W.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,W.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`profiles.empty.title`)}),(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:e(`profiles.empty.body`)}),r.providers.length>1&&(0,W.jsx)(`select`,{value:j,"aria-label":e(`profiles.providerLabel`),onChange:e=>{f(null),h(null),c(e.target.value)},className:`mb-4 h-8 w-full rounded border border-border bg-background px-2 text-xs`,children:r.providers.map(e=>(0,W.jsx)(`option`,{value:e,children:p(e)},e))}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2 justify-center`,children:[(0,W.jsxs)(I,{size:`sm`,onClick:P,disabled:x,children:[(0,W.jsx)(Se,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.migrateButton`)]}),(0,W.jsxs)(I,{size:`sm`,variant:`ghost`,onClick:ae,disabled:x,children:[(0,W.jsx)(ne,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`profiles.empty.blankButton`)]})]}),(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-3`,children:(0,W.jsx)(o,{t:e,i18nKey:`profiles.empty.migrateExplainer`,components:{code:(0,W.jsx)(`code`,{className:`text-foreground`})}})}),y&&(0,W.jsx)(`div`,{className:`mt-3 text-xs text-red-400 aurora-light:text-destructive`,children:y})]})})]}):(0,W.jsxs)(`div`,{className:`flex flex-col h-full`,children:[z,(0,W.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,W.jsxs)(`aside`,{className:`w-64 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,W.jsxs)(`div`,{className:`p-3 space-y-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:e(`profiles.sidebar.title`)}),(0,W.jsx)(I,{size:`sm`,variant:`ghost`,onClick:ae,disabled:x,children:(0,W.jsx)(ne,{className:`w-3.5 h-3.5`})})]}),r.providers.length>1&&(0,W.jsx)(`select`,{value:j,"aria-label":e(`profiles.providerLabel`),onChange:e=>{f(null),h(null),c(e.target.value)},className:`h-7 w-full rounded border border-border bg-background px-2 text-xs`,children:r.providers.map(e=>(0,W.jsx)(`option`,{value:e,children:p(e)},e))})]}),(0,W.jsx)(`div`,{className:`flex-1 overflow-auto px-2 pb-3`,children:t.map(t=>(0,W.jsxs)(`div`,{className:`group mb-1 rounded-md px-2 py-1.5 text-xs cursor-pointer transition-colors flex items-center justify-between `+(t.name===u?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),onClick:()=>f(t.name),role:`button`,tabIndex:0,onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&f(t.name)},children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,W.jsx)(`span`,{className:`truncate font-medium`,children:t.name}),t.isDefault&&(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e(`profiles.sidebar.teamDefault`)})]}),(0,W.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:[(0,W.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-accent rounded`,title:e(`common:actions.duplicate`),onClick:e=>{e.stopPropagation(),R(t.name)},children:(0,W.jsx)(se,{className:`w-3 h-3`})}),!t.isDefault&&(0,W.jsx)(`button`,{type:`button`,className:`p-1 hover:bg-red-500/20 text-red-400 aurora-light:text-destructive rounded`,title:e(`common:actions.delete`),onClick:e=>{e.stopPropagation(),oe(t.name)},children:(0,W.jsx)(T,{className:`w-3 h-3`})})]})]},t.name))})]}),(0,W.jsxs)(`main`,{className:`flex-1 overflow-auto`,children:[y&&(0,W.jsx)(`div`,{className:`mx-4 mt-4 px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:y}),m?(0,W.jsx)(Pe,{profile:m,provider:j,modelCatalog:M.models,defaultModel:M.defaultModel,customModelAliases:M.customModelAliases===!0,baselineAgents:M.baselineAgents,onChange:h,onValidityChange:ee,onSoftWarningsChange:e=>re(e.agentsMissingRouting),footer:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsxs)(I,{size:`sm`,onClick:()=>void ce(m,te),disabled:x||C.length>0,title:C.length>0?e(`profiles.editorFooter.fixValidationIssues`):void 0,children:[(0,W.jsx)(g,{className:`w-3.5 h-3.5 mr-1.5`}),e(`common:actions.save`)]}),x&&(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`common:states.saving`)}),C.length>0&&(0,W.jsx)(`span`,{className:`text-xs text-yellow-500 aurora-light:text-accent-warning`,children:e(`profiles.editorFooter.issuesToResolve`,{count:C.length})})]})},`${j}:${m.name}`):(0,W.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`profiles.selectPrompt`)})})]})]})]})}function Ue(e){return e==null}function We(e){return typeof e==`object`&&!!e}function Ge(e){return Array.isArray(e)?e:Ue(e)?[]:[e]}function Ke(e,t){var n,r,i,a;if(t)for(a=Object.keys(t),n=0,r=a.length;n<r;n+=1)i=a[n],e[i]=t[i];return e}function qe(e,t){var n=``,r;for(r=0;r<t;r+=1)n+=e;return n}function Je(e){return e===0&&1/e==-1/0}var K={isNothing:Ue,isObject:We,toArray:Ge,repeat:qe,isNegativeZero:Je,extend:Ke};function Ye(e,t){var n=``,r=e.reason||`(unknown reason)`;return e.mark?(e.mark.name&&(n+=`in "`+e.mark.name+`" `),n+=`(`+(e.mark.line+1)+`:`+(e.mark.column+1)+`)`,!t&&e.mark.snippet&&(n+=`
2
2
 
3
3
  `+e.mark.snippet),r+` `+n):r}function Xe(e,t){Error.call(this),this.name=`YAMLException`,this.reason=e,this.mark=t,this.message=Ye(this,!1),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=Error().stack||``}Xe.prototype=Object.create(Error.prototype),Xe.prototype.constructor=Xe,Xe.prototype.toString=function(e){return this.name+`: `+Ye(this,e)};var q=Xe;function Ze(e,t,n,r,i){var a=``,o=``,s=Math.floor(i/2)-1;return r-t>s&&(a=` ... `,t=r-s+a.length),n-r>s&&(o=` ...`,n=r+s-o.length),{str:a+e.slice(t,n).replace(/\t/g,`→`)+o,pos:r-t+a.length}}function Qe(e,t){return K.repeat(` `,t-e.length)+e}function $e(e,t){if(t=Object.create(t||null),!e.buffer)return null;t.maxLength||=79,typeof t.indent!=`number`&&(t.indent=1),typeof t.linesBefore!=`number`&&(t.linesBefore=3),typeof t.linesAfter!=`number`&&(t.linesAfter=2);for(var n=/\r?\n|\r|\0/g,r=[0],i=[],a,o=-1;a=n.exec(e.buffer);)i.push(a.index),r.push(a.index+a[0].length),e.position<=a.index&&o<0&&(o=r.length-2);o<0&&(o=r.length-1);var s=``,c,l,u=Math.min(e.line+t.linesAfter,i.length).toString().length,d=t.maxLength-(t.indent+u+3);for(c=1;c<=t.linesBefore&&!(o-c<0);c++)l=Ze(e.buffer,r[o-c],i[o-c],e.position-(r[o]-r[o-c]),d),s=K.repeat(` `,t.indent)+Qe((e.line-c+1).toString(),u)+` | `+l.str+`
4
4
  `+s;for(l=Ze(e.buffer,r[o],i[o],e.position,d),s+=K.repeat(` `,t.indent)+Qe((e.line+1).toString(),u)+` | `+l.str+`
@@ -108,11 +108,11 @@ You are ...
108
108
  - **risk_tolerance**: conservative
109
109
  - **detail_level**: full
110
110
  - **focus_areas**: ...
111
- `}function Mi(e,t){let n=e.match(/^---(\r?\n)([\s\S]*?)\r?\n---/);if(!n)return e;let r=n[1],i=/^name:\s*.*$/m.test(n[2])?n[2].replace(/^name:\s*.*$/m,`name: ${t}`):`name: ${t}${r}${n[2]}`;return e.replace(n[0],`---${r}${i}${r}---`)}function Ni(e,t){return e===`kimi`?`.kimi-code/skills/${t}/SKILL.md`:e===`codex`?`.codex/skills/rails/${t}/SKILL.md`:e===`gemini`?`.gemini/agents/${t}.md`:`.claude/agents/${t}.md`}function Pi({agentId:e,initialBody:t,initialName:n,draftFromRefine:r,provider:i=`claude`,defaultModel:a=`sonnet`,onClose:c,onSaved:u,onResumeRefine:f,automationEnabled:p=!0}){let{t:g}=s(`agentstudio`),_=!e,v=e??n??``,[y,b]=(0,U.useState)(v),[x,C]=(0,U.useState)(t??ji(i,a,v||void 0)),[ee,te]=(0,U.useState)(!_&&!t&&!r),[w,E]=(0,U.useState)(!!r&&!_),[ne,D]=(0,U.useState)(!1),[O,k]=(0,U.useState)(null),[re,A]=(0,U.useState)([]),[j,M]=(0,U.useState)(!1),[N,F]=(0,U.useState)(!!t&&_),[ie,ae]=(0,U.useState)(!1),[I,L]=(0,U.useState)(``),[R,le]=(0,U.useState)(!1),[ue,de]=(0,U.useState)(null),[fe,pe]=(0,U.useState)(null),[me,z]=(0,U.useState)(!1);(0,U.useEffect)(()=>{if(_||t!==void 0)return;if(r){let t=!1;return fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}/refine/${r}?provider=${encodeURIComponent(i)}`).then(e=>{if(!e.ok)throw Error(g(`studio.errors.loadDraftFailed`,{status:e.status}));return e.json()}).then(e=>{!t&&e.draftBody&&(C(e.draftBody),F(!0))}).catch(e=>{t||k(e.message)}).finally(()=>{t||E(!1)}),()=>{t=!0}}let n=!1;return fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}?provider=${encodeURIComponent(i)}`).then(e=>{if(!e.ok)throw Error(g(`studio.errors.loadFailed`,{status:e.status}));return e.json()}).then(e=>{n||C(e.body)}).catch(e=>{n||k(e.message)}).finally(()=>{n||te(!1)}),()=>{n=!0}},[e,r,t,_,i,g]);let he=(0,U.useCallback)(()=>{_||fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}/versions?provider=${encodeURIComponent(i)}`).then(e=>e.ok?e.json():{versions:[]}).then(e=>A(e.versions)).catch(()=>A([]))},[e,_,i]);(0,U.useEffect)(()=>{j&&he()},[j,he]);let ge=/^custom-[a-z][a-z0-9-]{0,63}$/.test(y)&&![`custom-architect`,`custom-developer`,`custom-reviewer`,`custom-fixer`].includes(y),_e=x.trim().length>0,ve=/^---\s*\n[\s\S]*?\n---/.test(x),B=_e&&ve&&(!_||ge)&&N,ye=(0,U.useCallback)(async()=>{D(!0),k(null);try{let t,n=_?Mi(x,y):x;if(t=_?await fetch(`${l()}/profiles/catalog?provider=${encodeURIComponent(i)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:y,body:n,provider:i})}):await fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}?provider=${encodeURIComponent(i)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({body:x})}),!t.ok){let e=await t.json().catch(()=>({})),n=Array.isArray(e.details)?e.details.filter(e=>typeof e==`string`).join(`; `):``;throw Error(n||e.error||g(`studio.errors.saveFailed`,{status:t.status}))}F(!1),n!==x&&C(n),d.success(g(_?`studio.toasts.agentCreated`:`studio.toasts.agentSaved`),{description:_?y:e}),u&&u(_?y:e)}catch(e){let t=e.message;k(t),d.error(g(_?`studio.toasts.createFailed`:`studio.toasts.saveFailed`),{description:t})}finally{D(!1)}},[e,x,y,_,u,i,g]),V=(0,U.useCallback)(async()=>{if(!_){z(!1),D(!0),k(null);try{let t=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}?provider=${encodeURIComponent(i)}`,{method:`DELETE`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??g(`studio.errors.deleteFailed`,{status:t.status}))}d.success(g(`studio.toasts.agentDeleted`),{description:e}),u&&u(e),c()}catch(e){let t=e.message;k(t),d.error(g(`studio.toasts.deleteFailed`),{description:t})}finally{D(!1)}}},[e,_,c,u,i,g]),H=(0,U.useCallback)(e=>{C(e.body),F(!0),M(!1)},[]),xe=(0,U.useCallback)(async()=>{if(p){le(!0),pe(null),de(null);try{let t=await fetch(`${l()}/profiles/catalog/test?provider=${encodeURIComponent(i)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({agentId:_?y||`draft`:e,draftBody:x,sampleTask:I})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??g(`studio.errors.testFailed`,{status:t.status}))}let n=await t.json();de(n)}catch(e){pe(e.message)}finally{le(!1)}}},[e,p,x,y,_,i,I,g]);return ee?(0,W.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:g(`studio.loadingAgent`)})}):(0,W.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!_&&(0,W.jsx)(Re,{open:me,title:g(`studio.deleteConfirm.title`,{agentId:e}),description:g(`studio.deleteConfirm.description`),confirmLabel:g(`common:actions.delete`),destructive:!0,onConfirm:V,onCancel:()=>z(!1)}),(0,W.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 border-b border-border`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:c,className:`p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground`,title:g(`common:actions.back`),children:(0,W.jsx)(m,{className:`w-4 h-4`})}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground uppercase tracking-wide`,children:g(_?`studio.modeCreate`:`studio.modeEdit`)}),_?(0,W.jsx)(se,{value:y,onChange:e=>{let t=e.target.value;b(t),C(e=>Mi(e,t||`custom-<name>`)),F(!0)},placeholder:`custom-my-agent`,className:`text-sm font-mono mt-1 max-w-sm`}):(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`div`,{className:`text-sm font-mono`,children:e}),p&&r&&(0,W.jsxs)(`button`,{type:`button`,onClick:async()=>{if(!(!f||!e))try{let t=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}?provider=${encodeURIComponent(i)}`);if(!t.ok)return;f(r,e,(await t.json()).body)}catch{}},className:`inline-flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-full border border-accent-primary/40 bg-accent-primary/15 text-accent-primary hover:bg-accent-primary/25 focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none`,title:g(`studio.resumeAiEditTitle`),children:[(0,W.jsx)(be,{className:`w-3 h-3`}),` `,g(`studio.resumeAiEdit`)]}),w&&(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,W.jsx)(S,{className:`w-3 h-3 animate-spin`}),` `,g(`studio.loadingAiDraft`)]})]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[p&&(0,W.jsxs)(P,{size:`sm`,variant:`ghost`,onClick:()=>{ae(e=>!e),ie||M(!1)},title:g(`studio.testButtonTitle`),children:[(0,W.jsx)(Ee,{className:`w-3.5 h-3.5 mr-1`}),g(`studio.testButton`)]}),!_&&(0,W.jsxs)(P,{size:`sm`,variant:`ghost`,onClick:()=>{M(e=>!e),j||ae(!1)},title:g(`studio.historyButtonTitle`),children:[(0,W.jsx)(oe,{className:`w-3.5 h-3.5 mr-1`}),g(`studio.historyButton`)]}),!_&&(0,W.jsxs)(P,{size:`sm`,variant:`ghost`,onClick:()=>z(!0),disabled:ne,className:`text-red-400 hover:text-red-300 aurora-light:text-destructive aurora-light:hover:text-destructive`,children:[(0,W.jsx)(T,{className:`w-3.5 h-3.5 mr-1`}),g(`common:actions.delete`)]}),(0,W.jsxs)(P,{size:`sm`,onClick:ye,disabled:!B||ne,children:[(0,W.jsx)(h,{className:`w-3.5 h-3.5 mr-1`}),g(ne?`common:states.saving`:_?`studio.create`:`common:actions.save`)]})]})]}),O&&(0,W.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 text-xs border-b border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:[(0,W.jsx)(ce,{className:`w-3.5 h-3.5 flex-shrink-0`}),O]}),_&&y.length>0&&!ge&&(0,W.jsx)(`div`,{className:`px-4 py-1.5 text-[11px] border-b border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:(0,W.jsx)(o,{t:g,i18nKey:`studio.validation.namePattern`,components:{code:(0,W.jsx)(`code`,{})}})}),!ve&&(0,W.jsx)(`div`,{className:`px-4 py-1.5 text-[11px] border-b border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:(0,W.jsx)(o,{t:g,i18nKey:`studio.validation.missingFrontmatter`,components:{code:(0,W.jsx)(`code`,{})}})}),(_||e?.startsWith(`custom-`))&&(0,W.jsx)(Di,{body:x,onChange:e=>{C(e),F(!0)}}),(0,W.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,W.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0`,children:[(0,W.jsxs)(`div`,{className:`px-4 py-1.5 border-b border-border text-[11px] font-mono text-muted-foreground flex items-center justify-between`,children:[(0,W.jsx)(`span`,{children:Ni(i,_?y||`custom-…`:e)}),N&&(0,W.jsx)(`span`,{className:`text-yellow-500 aurora-light:text-accent-warning`,children:g(`studio.unsaved`)})]}),(0,W.jsx)(`textarea`,{value:x,onChange:e=>{C(e.target.value),F(!0)},spellCheck:!1,className:`flex-1 w-full p-4 text-xs font-mono bg-background text-foreground outline-none resize-none leading-relaxed`})]}),p&&ie&&(0,W.jsxs)(`aside`,{className:`w-96 flex-shrink-0 border-l border-border flex flex-col min-h-0`,children:[(0,W.jsxs)(`div`,{className:`px-3 py-2 border-b border-border text-xs font-medium text-muted-foreground uppercase tracking-wide flex items-center gap-2`,children:[(0,W.jsx)(Ee,{className:`w-3.5 h-3.5`}),` `,g(`studio.testPane.header`)]}),(0,W.jsxs)(`div`,{className:`p-3 border-b border-border`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,W.jsx)(`label`,{className:`text-[11px] text-muted-foreground`,children:g(`studio.testPane.sampleTaskLabel`)}),(0,W.jsx)(`select`,{className:`h-6 text-[11px] rounded border border-border bg-background px-1`,value:``,onChange:e=>{let t=parseInt(e.target.value,10);!isNaN(t)&&t>0&&L(Ai[t].prompt)},disabled:R,children:Ai.map((e,t)=>(0,W.jsx)(`option`,{value:t,children:g(e.labelKey)},t))})]}),(0,W.jsx)(`textarea`,{value:I,onChange:e=>L(e.target.value),placeholder:g(`studio.testPane.placeholder`),className:`w-full text-xs p-2 rounded border border-border bg-background min-h-[80px] resize-y font-mono`,disabled:R}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,W.jsx)(P,{size:`sm`,onClick:xe,disabled:R||!I.trim()||!x.trim(),children:R?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(S,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` `,g(`studio.testPane.running`)]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(Ee,{className:`w-3.5 h-3.5 mr-1.5`}),` `,g(`studio.testPane.run`)]})}),(0,W.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:g(`studio.testPane.sandboxNote`)})]})]}),(0,W.jsxs)(`div`,{className:`flex-1 overflow-auto p-3 min-h-0`,children:[fe&&(0,W.jsx)(`div`,{className:`px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive mb-2`,children:fe}),ue&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] text-muted-foreground mb-2`,children:[(0,W.jsx)(`span`,{children:ue.tokens===null?(0,W.jsx)(`span`,{className:`text-foreground font-mono`,title:g(`studio.testPane.tokensUnavailable`),"aria-label":g(`studio.testPane.tokensUnavailable`),children:`—`}):(0,W.jsx)(o,{t:g,i18nKey:`studio.testPane.tokens`,count:ue.tokens,components:{mono:(0,W.jsx)(`span`,{className:`text-foreground font-mono`})}})}),(0,W.jsx)(`span`,{children:(0,W.jsxs)(`span`,{className:`text-foreground font-mono`,children:[(ue.durationMs/1e3).toFixed(1),`s`]})})]}),(0,W.jsx)(`pre`,{className:`text-xs font-mono whitespace-pre-wrap leading-relaxed rounded border border-border bg-background p-3`,children:ue.output})]}),!R&&!ue&&!fe&&(0,W.jsx)(`p`,{className:`text-[11px] text-muted-foreground italic`,children:g(`studio.testPane.emptyHint`)})]})]}),j&&!_&&(0,W.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-l border-border flex flex-col`,children:[(0,W.jsx)(`div`,{className:`px-3 py-2 border-b border-border text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:g(`studio.versions.header`)}),(0,W.jsx)(`div`,{className:`flex-1 overflow-auto p-2 space-y-1`,children:re.length===0?(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic px-2 py-2`,children:g(`studio.versions.empty`)}):re.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>H(e),className:`w-full text-left px-2 py-1.5 rounded hover:bg-accent/50 transition-colors`,children:[(0,W.jsxs)(`div`,{className:`text-xs font-mono text-foreground`,children:[`v`,e.version]}),(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:new Date(e.createdAt).toLocaleString()})]},e.version))}),(0,W.jsx)(`div`,{className:`px-3 py-2 border-t border-border text-[11px] text-muted-foreground`,children:g(`studio.versions.restoreHint`)})]})]})]})}var Fi={refineId:null,agentId:null,uiState:`closed`,phase:`idle`,history:[],streamingText:``,draftBody:null,baseBody:null,autoTest:!1,testResult:null,appliedVersion:null,errorMessage:null,applyConflict:null};function Ii(e){return e.replace(/<!--tool:[^>]+-->/g,``)}function Li(e,t){switch(t.type){case`OPEN`:return{...Fi,agentId:t.agentId,baseBody:t.baseBody,uiState:`composing`};case`START_TURN`:return{...e,refineId:t.refineId,uiState:`streaming`,phase:`reading`,streamingText:``,errorMessage:null,applyConflict:null,history:[...e.history,t.userTurn]};case`STREAM_DELTA`:return e.refineId===t.refineId?{...e,streamingText:e.streamingText+t.delta}:e;case`PHASE`:return e.refineId===t.refineId?{...e,phase:t.phase}:e;case`READY`:return e.refineId===t.refineId?{...e,uiState:`reviewing`,phase:`done`,draftBody:t.draftBody,streamingText:``,history:[...e.history,{role:`assistant`,content:Ii(t.draftBody),timestamp:Date.now()}]}:e;case`TEST_RESULT`:return e.refineId===t.refineId?{...e,testResult:t.result,history:[...e.history,{role:`system`,kind:`test_result`,content:t.result.output,timestamp:Date.now()}]}:e;case`APPLIED`:return e.refineId===t.refineId?{...e,uiState:`applied`,appliedVersion:t.version}:e;case`CANCELLED`:return{...e,uiState:`cancelled`};case`ERROR`:return t.refineId!==null&&e.refineId!==t.refineId?e:{...e,uiState:`error`,errorMessage:t.message};case`CONFLICT`:return e.refineId===t.refineId?{...e,applyConflict:t.reason}:e;case`TOGGLE_AUTO_TEST`:return{...e,autoTest:t.enabled};case`REHYDRATE`:return{...e,...t.payload};case`CLOSE`:return Fi;default:return e}}function Ri(e){switch(e.status){case`streaming`:return`streaming`;case`ready`:return`reviewing`;case`applied`:return`applied`;case`cancelled`:return`cancelled`;case`error`:return`error`;default:return e.draftBody?`reviewing`:`composing`}}function zi(e){let[t,n]=(0,U.useReducer)(Li,Fi),{t:r}=s(`aiedit`),{registerHandler:i,unregisterHandler:o}=a(),c=(0,U.useRef)(null);c.current=t.refineId;let u=(0,U.useRef)(null);u.current=t.agentId;let d=(0,U.useRef)(e);d.current=e;let f=(0,U.useRef)(e);(0,U.useEffect)(()=>{e!==f.current&&(f.current=e,n({type:`CLOSE`}))},[e]),(0,U.useEffect)(()=>{let e=`agent-refine-${Math.random().toString(36).slice(2,9)}`;return i(e,e=>{let t=e;if(typeof t.type!=`string`||t.projectId!==d.current||t.refineId!==c.current)return;let r=t.refineId;switch(t.type){case`agent_refine_stream`:n({type:`STREAM_DELTA`,refineId:r,delta:t.delta});break;case`agent_refine_phase`:n({type:`PHASE`,refineId:r,phase:t.phase});break;case`agent_refine_ready`:n({type:`READY`,refineId:r,draftBody:t.draftBody});break;case`agent_refine_test`:n({type:`TEST_RESULT`,refineId:r,result:t.result});break;case`agent_refine_applied`:n({type:`APPLIED`,refineId:r,version:t.version});break;case`agent_refine_cancelled`:n({type:`CANCELLED`,refineId:r});break;case`agent_refine_error`:n({type:`ERROR`,refineId:r,message:t.error});break}}),()=>o(e)},[i,o]);let p=(0,U.useCallback)((e,t)=>{n({type:`OPEN`,agentId:e,baseBody:t})},[]),m=(0,U.useCallback)(()=>{n({type:`CLOSE`})},[]);return{state:t,open:p,start:(0,U.useCallback)(async e=>{let i=u.current;if(i)try{let a=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(i)}/refine`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({instruction:e,autoTest:t.autoTest})});if(!a.ok){let e=await a.json().catch(()=>({}));n({type:`ERROR`,refineId:null,message:e.error??r(`refine.serverError`,{status:a.status})});return}let o=await a.json();c.current=o.refineId,n({type:`START_TURN`,refineId:o.refineId,userTurn:{role:`user`,content:e,timestamp:Date.now()}})}catch(e){n({type:`ERROR`,refineId:null,message:r(`refine.connectionFailed`,{message:e.message})})}},[t.autoTest,r]),sendTurn:(0,U.useCallback)(async e=>{let t=c.current,i=u.current;if(!(!t||!i)){n({type:`START_TURN`,refineId:t,userTurn:{role:`user`,content:e,timestamp:Date.now()}});try{let a=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(i)}/refine/${t}/turn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({instruction:e})});if(!a.ok){let e=await a.json().catch(()=>({}));n({type:`ERROR`,refineId:t,message:e.error??r(`refine.serverError`,{status:a.status})})}}catch(e){n({type:`ERROR`,refineId:t,message:r(`refine.connectionFailed`,{message:e.message})})}}},[r]),cancel:(0,U.useCallback)(async()=>{let e=c.current,t=u.current;if(!(!e||!t))try{await fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}/refine/${e}`,{method:`DELETE`})}catch{}},[]),apply:(0,U.useCallback)(async e=>{let t=c.current,i=u.current;if(!(!t||!i))try{let a=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(i)}/refine/${t}/apply`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({force:!!e})});if(a.status===409){let e=await a.json().catch(()=>({}));if(e.reason===`disk_changed`||e.reason===`name_changed`){n({type:`CONFLICT`,refineId:t,reason:e.reason});return}}if(!a.ok){let e=await a.json().catch(()=>({}));n({type:`ERROR`,refineId:t,message:e.error??r(`refine.applyFailed`,{status:a.status})});return}let o=await a.json();n({type:`APPLIED`,refineId:t,version:o.version})}catch(e){n({type:`ERROR`,refineId:t,message:r(`refine.connectionFailed`,{message:e.message})})}},[r]),toggleAutoTest:(0,U.useCallback)(async e=>{let t=c.current,r=u.current;if(n({type:`TOGGLE_AUTO_TEST`,enabled:e}),!(!t||!r))try{await fetch(`${l()}/profiles/catalog/${encodeURIComponent(r)}/refine/${t}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({autoTest:e})})}catch{}},[]),rehydrate:(0,U.useCallback)(async(e,t)=>{try{let i=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}`);if(!i.ok)throw Error(r(`refine.loadAgentFailed`,{status:i.status}));let a=await i.json(),o=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}/refine/${e}`);if(!o.ok)throw Error(r(`refine.loadSessionFailed`,{status:o.status}));let s=await o.json();c.current=e,u.current=t,n({type:`REHYDRATE`,payload:{refineId:e,agentId:t,baseBody:a.body,draftBody:s.draftBody,history:s.history,autoTest:s.autoTest,phase:s.phase,uiState:Ri(s),streamingText:``}})}catch(e){n({type:`ERROR`,refineId:null,message:r(`refine.rehydrateFailed`,{message:e.message})})}},[r]),close:m}}var Bi=e(r(),1);function Vi(){return typeof window>`u`||!(`__TAURI_INTERNALS__`in window)?!1:/mac/i.test(navigator.platform)}function Hi(e){let[t,n]=(0,U.useState)(!1),r=(0,U.useRef)(null),{panelRef:i,panelStyle:a,headerHandleProps:o,resizeHandles:s,isFloating:c}=D();(0,U.useEffect)(()=>(r.current=document.activeElement,()=>{let e=r.current;e&&e instanceof HTMLElement&&e.focus()}),[]);let l=(0,U.useCallback)(()=>{e.uiPhase===`streaming`||e.uiPhase===`reviewing`?n(!0):e.onClose()},[e]),u=(0,U.useCallback)(()=>{n(!1),e.onDiscard()},[e]);(0,U.useEffect)(()=>{let t=t=>{if(t.key===`Escape`){t.preventDefault(),l();return}if((t.metaKey||t.ctrlKey)&&t.key===`Enter`&&e.uiPhase===`reviewing`&&e.canApply&&!e.applyConflict){t.preventDefault(),e.onApply();return}e.onKeyDown?.(t)};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,l]);let d=e.uiPhase===`composing`||e.uiPhase===`streaming`||e.uiPhase===`error`,f=e.uiPhase===`reviewing`||e.uiPhase===`applied`;return(0,Bi.createPortal)((0,W.jsxs)(`div`,{className:`fixed inset-0 z-50 flex p-3 pt-10 sm:p-6 sm:pt-12 bg-black/40 backdrop-blur-sm animate-in fade-in duration-150`,"data-testid":`ai-edit-backdrop`,children:[(0,W.jsxs)(`div`,{ref:i,role:`dialog`,"aria-modal":`true`,"aria-label":`${e.eyebrow} · ${e.targetLabel}`,className:`m-auto w-full h-full max-w-[1600px] flex flex-col bg-background rounded-xl border border-border/40 shadow-2xl overflow-hidden`,style:a,children:[(0,W.jsx)(Ui,{eyebrow:e.eyebrow,targetLabel:e.targetLabel,targetLabelMono:e.targetLabelMono??!0,showApply:e.uiPhase===`reviewing`&&e.canApply&&!e.applyConflict,showDiscard:e.uiPhase!==`applied`,onApply:e.onApply,onDiscard:l,onMinimize:e.onMinimize,headerHandleProps:o,isFloating:c}),d&&(0,W.jsx)(Wi,{uiPhase:e.uiPhase,headline:e.uiPhase===`streaming`?e.streamingHeadline:e.headline,description:e.description,chips:e.chips,onChipSubmit:e.onChipSubmit,streamingText:e.streamingText,composer:e.composer,composerAccessory:e.composerAccessory,history:e.history??[],baseBody:e.baseBody,baseBodyDisclosureLabel:e.baseBodyDisclosureLabel,errorMessage:e.errorMessage}),f&&(0,W.jsx)(Yi,{state:e,appliedNotice:e.appliedNotice}),t&&(0,W.jsx)(ta,{onCancel:()=>n(!1),onConfirm:u})]}),(0,W.jsx)(re,{handles:s})]}),document.body)}function Ui({eyebrow:e,targetLabel:t,targetLabelMono:n,showApply:r,showDiscard:i,onApply:a,onDiscard:o,onMinimize:c,headerHandleProps:l,isFloating:u}){let{t:d}=s(`aiedit`),f=Vi()?`pl-[88px]`:`pl-4`;return(0,W.jsxs)(`div`,{...l,className:`flex-shrink-0 flex items-center justify-between ${f} pr-4 h-14 border-b border-border bg-card/60 backdrop-blur-sm${u?` cursor-grab active:cursor-grabbing`:``}`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:o,className:`flex items-center gap-2 group p-1 -ml-1 rounded hover:bg-accent focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none max-w-[60vw]`,"aria-label":d(`shell.backAriaLabel`),children:[(0,W.jsx)(m,{className:`w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors flex-shrink-0`}),(0,W.jsxs)(`div`,{className:`text-left min-w-0`,children:[(0,W.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground/70 leading-none`,children:e}),n?(0,W.jsx)(`code`,{className:`text-sm font-mono font-medium text-foreground truncate block`,children:t}):(0,W.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate block`,children:t})]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c&&(0,W.jsx)(P,{variant:`ghost`,size:`sm`,onClick:c,"aria-label":d(`common:actions.minimize`),"data-testid":`ai-edit-minimize`,children:(0,W.jsx)(Ce,{className:`w-4 h-4`})}),i&&(0,W.jsx)(P,{variant:`ghost`,size:`sm`,onClick:o,children:d(`common:actions.discard`)}),r&&(0,W.jsxs)(P,{size:`sm`,onClick:a,className:`gap-1.5`,children:[(0,W.jsx)(b,{className:`w-3.5 h-3.5`}),` `,d(`shell.apply`),(0,W.jsx)(`span`,{className:`text-[10px] opacity-70 ml-1`,children:H(`⌘⏎`)})]})]})]})}function Wi({uiPhase:e,headline:t,description:n,chips:r,onChipSubmit:i,streamingText:a,composer:o,composerAccessory:c,history:l,baseBody:u,baseBodyDisclosureLabel:d,errorMessage:f}){let{t:p}=s(`aiedit`),m=e===`composing`&&(r?.length??0)>0&&l.length===0,h=e===`error`,g=l.filter(e=>e.role===`user`||e.role===`system`&&e.kind===`test_result`);return(0,W.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:(0,W.jsxs)(`div`,{className:`mx-auto max-w-2xl px-6 py-12 pb-32 flex flex-col gap-6`,children:[(0,W.jsxs)(`header`,{className:`text-center space-y-2`,children:[(0,W.jsx)(`div`,{className:`inline-flex items-center justify-center w-10 h-10 rounded-full ring-1 mx-auto `+(h?`bg-red-500/10 aurora-light:bg-destructive/10 ring-red-500/30 aurora-light:ring-destructive/30`:`bg-accent-primary/15 ring-accent-primary/30`),children:h?(0,W.jsx)(E,{className:`w-5 h-5 text-red-400 aurora-light:text-destructive`}):(0,W.jsx)(w,{className:`w-5 h-5 text-accent-primary`})}),(0,W.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:h?p(`shell.somethingWentWrong`):t}),h&&f&&(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-md mx-auto font-mono break-words`,children:f}),!h&&n&&(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-md mx-auto leading-relaxed`,children:n})]}),e===`streaming`&&(0,W.jsx)(Ki,{streamingText:a}),m&&r&&i&&(0,W.jsx)(Gi,{chips:r,onPick:i}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[o,c&&(0,W.jsx)(`div`,{children:c})]}),g.length>0&&(0,W.jsx)(qi,{history:g}),u&&(0,W.jsx)(Ji,{body:u,label:d??p(`shell.viewCurrentContent`)})]})})}function Gi({chips:e,onPick:t}){let{t:n}=s(`aiedit`);return(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground/70`,children:n(`shell.quickPrompts`)}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>t(e),className:`text-xs px-3 py-1.5 rounded-full border border-border bg-card/40 hover:border-accent-primary/50 hover:bg-accent-primary/10 hover:text-accent-primary text-foreground/80 transition-colors focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none`,children:e},e))})]})}function Ki({streamingText:e}){let{t}=s(`aiedit`);return(0,W.jsx)(`div`,{className:`rounded-xl border border-accent-primary/30 bg-accent-primary/5 p-4`,children:e?(0,W.jsxs)(`div`,{className:`text-xs font-mono whitespace-pre-wrap break-words text-foreground/80 max-h-64 overflow-y-auto leading-relaxed`,children:[ra(e),(0,W.jsx)(`span`,{className:`inline-block w-1.5 h-3 bg-accent-primary animate-pulse align-middle ml-0.5`})]}):(0,W.jsxs)(`div`,{className:`text-xs text-muted-foreground italic flex items-center gap-1.5`,children:[(0,W.jsx)(S,{className:`w-3 h-3 animate-spin`}),t(`shell.workingOnRefinement`)]})})}function qi({history:e}){let{t}=s(`aiedit`);return e.length===0?null:(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground/70`,children:t(`shell.history`)}),(0,W.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,W.jsx)(Qi,{turn:e},t))})]})}function Ji({body:e,label:t}){let[n,r]=(0,U.useState)(!1);return(0,W.jsxs)(`div`,{className:`border-t border-border/60 pt-4`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none rounded px-1 -ml-1`,children:[n?(0,W.jsx)(we,{className:`w-3.5 h-3.5`}):(0,W.jsx)(z,{className:`w-3.5 h-3.5`}),t]}),n&&(0,W.jsx)(`pre`,{className:`mt-2 p-3 rounded-md bg-muted/40 border border-border text-[11px] font-mono whitespace-pre-wrap break-words max-h-72 overflow-y-auto text-foreground/80`,children:e})]})}function Yi({state:e,appliedNotice:t}){return(0,W.jsxs)(`div`,{className:`flex-1 min-h-0 grid grid-cols-1 md:grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)]`,children:[(0,W.jsx)(Xi,{history:e.history??[],composer:e.composer,composerAccessory:e.composerAccessory,secondaryAction:e.secondaryAction,appliedNotice:t,uiPhase:e.uiPhase}),(0,W.jsx)($i,{diff:e.diff,label:e.diffHeaderLabel,applyConflict:e.applyConflict??null,onForceApply:e.onForceApply})]})}function Xi({history:e,composer:t,composerAccessory:n,secondaryAction:r,appliedNotice:i,uiPhase:a}){let{t:o}=s(`aiedit`);return(0,W.jsxs)(`section`,{"aria-label":o(`shell.conversation`),className:`flex flex-col min-h-0 border-r border-border bg-card/20`,children:[(0,W.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 pb-32 space-y-3`,"aria-live":`polite`,children:[e.map((e,t)=>(0,W.jsx)(Qi,{turn:e},t)),a===`applied`&&(i??(0,W.jsx)(Zi,{}))]}),(0,W.jsxs)(`div`,{className:`flex-shrink-0 border-t border-border p-3 space-y-2`,children:[t,n,r&&(0,W.jsxs)(`button`,{type:`button`,onClick:r.onClick,className:`w-full inline-flex items-center justify-center gap-1.5 text-[11px] text-muted-foreground hover:text-foreground py-1.5 rounded hover:bg-accent/50 focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none`,children:[r.icon??(0,W.jsx)(g,{className:`w-3 h-3`}),r.label]})]})]})}function Zi(){let{t:e}=s(`aiedit`);return(0,W.jsxs)(`div`,{className:`rounded-md border border-green-500/40 aurora-light:border-accent-success/40 bg-green-500/10 aurora-light:bg-accent-success/10 p-3 text-xs text-green-300 aurora-light:text-accent-success flex items-center gap-2`,children:[(0,W.jsx)(b,{className:`w-3.5 h-3.5`}),e(`shell.applied`)]})}function Qi({turn:e}){let{t}=s(`aiedit`);return e.role===`user`?(0,W.jsxs)(`div`,{className:`flex flex-col items-end`,children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-1`,children:t(`shell.you`)}),(0,W.jsx)(`div`,{className:`max-w-[90%] rounded-2xl rounded-br-sm bg-accent-primary/15 text-foreground text-sm px-3 py-2 whitespace-pre-wrap break-words`,children:e.content})]}):e.role===`system`&&e.kind===`test_result`?(0,W.jsxs)(`div`,{className:`rounded-md border border-accent-info/30 bg-accent-info/5 p-3 text-xs`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium mb-1 text-accent-info`,children:[(0,W.jsx)(w,{className:`w-3 h-3`}),` `,t(`shell.autoTestResult`)]}),(0,W.jsx)(`pre`,{className:`text-[11px] font-mono whitespace-pre-wrap break-words text-foreground/80 max-h-48 overflow-y-auto`,children:e.content})]}):(0,W.jsxs)(`div`,{className:`flex flex-col items-start`,children:[(0,W.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mb-1 inline-flex items-center gap-1`,children:[(0,W.jsx)(w,{className:`w-3 h-3 text-accent-primary`}),` `,t(`shell.ai`)]}),(0,W.jsx)(`div`,{className:`max-w-[90%] rounded-2xl rounded-bl-sm border border-border bg-muted/30 text-xs px-3 py-2 text-muted-foreground italic`,children:t(`shell.refinementReady`)})]})}function $i({diff:e,label:t,applyConflict:n,onForceApply:r}){let{t:i}=s(`aiedit`);return(0,W.jsxs)(`section`,{"aria-label":i(`shell.diffPreview`),className:`flex flex-col min-h-0`,children:[(0,W.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between px-4 h-9 border-b border-border bg-card/40`,children:[(0,W.jsx)(`span`,{className:`text-xs font-mono text-muted-foreground truncate`,children:t??i(`shell.proposedChanges`)}),(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`shell.wordLevelDiff`)})]}),n===`disk_changed`&&(0,W.jsx)(ea,{kind:`disk_changed`,action:r&&(0,W.jsxs)(P,{variant:`ghost`,size:`sm`,onClick:r,children:[(0,W.jsx)(_e,{className:`w-3 h-3 mr-1`}),` `,i(`shell.forceApply`)]})}),n===`name_changed`&&(0,W.jsx)(ea,{kind:`name_changed`}),(0,W.jsx)(`div`,{className:`flex-1 overflow-auto p-4 pb-32`,children:e})]})}function ea({kind:e,action:t}){let{t:n}=s(`aiedit`),r=n(e===`disk_changed`?`shell.conflict.diskChanged`:`shell.conflict.nameChanged`);return(0,W.jsxs)(`div`,{role:`alert`,className:`flex items-start justify-between gap-3 px-4 py-2 border-b border-yellow-500/40 aurora-light:border-accent-warning/40 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-200 aurora-light:text-accent-warning text-xs`,children:[(0,W.jsxs)(`div`,{className:`flex items-start gap-2 min-w-0`,children:[(0,W.jsx)(E,{className:`w-3.5 h-3.5 mt-0.5 flex-shrink-0`}),(0,W.jsx)(`span`,{children:r})]}),t]})}function ta({onCancel:e,onConfirm:t}){let{t:n}=s(`aiedit`);return(0,W.jsx)(`div`,{role:`alertdialog`,"aria-modal":`true`,"aria-label":n(`shell.discardDialog.ariaLabel`),className:`absolute inset-0 z-10 flex items-center justify-center bg-black/40`,children:(0,W.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-5 max-w-sm shadow-xl`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,W.jsx)(E,{className:`w-4 h-4 text-yellow-400 aurora-light:text-accent-warning`}),(0,W.jsx)(`h2`,{className:`text-sm font-medium`,children:n(`shell.discardDialog.title`)})]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground mb-4`,children:n(`shell.discardDialog.body`)}),(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(P,{variant:`ghost`,size:`sm`,onClick:e,children:n(`shell.discardDialog.keepEditing`)}),(0,W.jsx)(P,{size:`sm`,onClick:t,children:n(`common:actions.discard`)})]})]})})}function na({hunks:e}){return(0,W.jsx)(`pre`,{className:`font-mono text-xs leading-5 whitespace-pre-wrap break-words`,children:e.map((e,t)=>e.type===`eq`?(0,W.jsx)(`span`,{className:`text-foreground/70`,children:e.text},t):e.type===`add`?(0,W.jsxs)(`span`,{"data-hunk":`add`,className:`bg-green-500/20 aurora-light:bg-accent-success/15 text-green-200 aurora-light:text-accent-success rounded px-0.5 ring-1 ring-green-500/30 aurora-light:ring-accent-success/30`,children:[(0,W.jsx)(`span`,{"aria-hidden":`true`,children:`+ `}),e.text]},t):(0,W.jsxs)(`span`,{"data-hunk":`del`,className:`bg-red-500/20 aurora-light:bg-destructive/15 text-red-200 aurora-light:text-destructive line-through rounded px-0.5 ring-1 ring-red-500/30 aurora-light:ring-destructive/30`,children:[(0,W.jsx)(`span`,{"aria-hidden":`true`,children:`− `}),e.text]},t))})}function ra(e){return e.replace(/<!--tool:[^>]+-->/g,``)}function ia(e,t){let n=/(\s+)/,r=e.split(n),i=t.split(n);if(r.length>2e4||i.length>2e4)return aa(e,t);let a=r.length,o=i.length,s=new Uint16Array((a+1)*(o+1)),c=o+1;for(let e=a-1;e>=0;e--)for(let t=o-1;t>=0;t--)r[e]===i[t]?s[e*c+t]=s[(e+1)*c+(t+1)]+1:s[e*c+t]=Math.max(s[(e+1)*c+t],s[e*c+(t+1)]);let l=[],u=0,d=0,f=null,p=``,m=()=>{f!==null&&p&&l.push({type:f,text:p}),f=null,p=``},h=(e,t)=>{f===e?p+=t:(m(),f=e,p=t)};for(;u<a&&d<o;)r[u]===i[d]?(h(`eq`,r[u]),u++,d++):s[(u+1)*c+d]>=s[u*c+(d+1)]?(h(`del`,r[u]),u++):(h(`add`,i[d]),d++);for(;u<a;)h(`del`,r[u++]);for(;d<o;)h(`add`,i[d++]);return m(),l}function aa(e,t){let n=e.split(`
111
+ `}function Mi(e,t){let n=e.match(/^---(\r?\n)([\s\S]*?)\r?\n---/);if(!n)return e;let r=n[1],i=/^name:\s*.*$/m.test(n[2])?n[2].replace(/^name:\s*.*$/m,`name: ${t}`):`name: ${t}${r}${n[2]}`;return e.replace(n[0],`---${r}${i}${r}---`)}function Ni(e,t){return e===`kimi`?`.kimi-code/skills/${t}/SKILL.md`:e===`codex`?`.codex/skills/rails/${t}/SKILL.md`:e===`gemini`?`.gemini/agents/${t}.md`:`.claude/agents/${t}.md`}function Pi({agentId:e,initialBody:t,initialName:n,draftFromRefine:r,provider:i=`claude`,defaultModel:a=`sonnet`,onClose:c,onSaved:u,onResumeRefine:f,automationEnabled:p=!0}){let{t:m}=s(`agentstudio`),_=!e,v=e??n??``,[y,b]=(0,U.useState)(v),[x,S]=(0,U.useState)(t??ji(i,a,v||void 0)),[C,te]=(0,U.useState)(!_&&!t&&!r),[ne,re]=(0,U.useState)(!!r&&!_),[w,E]=(0,U.useState)(!1),[D,O]=(0,U.useState)(null),[k,A]=(0,U.useState)([]),[j,M]=(0,U.useState)(!1),[N,P]=(0,U.useState)(!!t&&_),[F,ie]=(0,U.useState)(!1),[L,ae]=(0,U.useState)(``),[R,oe]=(0,U.useState)(!1),[se,ce]=(0,U.useState)(null),[z,ue]=(0,U.useState)(null),[de,fe]=(0,U.useState)(!1);(0,U.useEffect)(()=>{if(_||t!==void 0)return;if(r){let t=!1;return fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}/refine/${r}?provider=${encodeURIComponent(i)}`).then(e=>{if(!e.ok)throw Error(m(`studio.errors.loadDraftFailed`,{status:e.status}));return e.json()}).then(e=>{!t&&e.draftBody&&(S(e.draftBody),P(!0))}).catch(e=>{t||O(e.message)}).finally(()=>{t||re(!1)}),()=>{t=!0}}let n=!1;return fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}?provider=${encodeURIComponent(i)}`).then(e=>{if(!e.ok)throw Error(m(`studio.errors.loadFailed`,{status:e.status}));return e.json()}).then(e=>{n||S(e.body)}).catch(e=>{n||O(e.message)}).finally(()=>{n||te(!1)}),()=>{n=!0}},[e,r,t,_,i,m]);let pe=(0,U.useCallback)(()=>{_||fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}/versions?provider=${encodeURIComponent(i)}`).then(e=>e.ok?e.json():{versions:[]}).then(e=>A(e.versions)).catch(()=>A([]))},[e,_,i]);(0,U.useEffect)(()=>{j&&pe()},[j,pe]);let me=/^custom-[a-z][a-z0-9-]{0,63}$/.test(y)&&![`custom-architect`,`custom-developer`,`custom-reviewer`,`custom-fixer`].includes(y),ge=x.trim().length>0,B=/^---\s*\n[\s\S]*?\n---/.test(x),ve=ge&&B&&(!_||me)&&N,V=(0,U.useCallback)(async()=>{E(!0),O(null);try{let t,n=_?Mi(x,y):x;if(t=_?await fetch(`${l()}/profiles/catalog?provider=${encodeURIComponent(i)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:y,body:n,provider:i})}):await fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}?provider=${encodeURIComponent(i)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({body:x})}),!t.ok){let e=await t.json().catch(()=>({})),n=Array.isArray(e.details)?e.details.filter(e=>typeof e==`string`).join(`; `):``;throw Error(n||e.error||m(`studio.errors.saveFailed`,{status:t.status}))}P(!1),n!==x&&S(n),d.success(m(_?`studio.toasts.agentCreated`:`studio.toasts.agentSaved`),{description:_?y:e}),u&&u(_?y:e)}catch(e){let t=e.message;O(t),d.error(m(_?`studio.toasts.createFailed`:`studio.toasts.saveFailed`),{description:t})}finally{E(!1)}},[e,x,y,_,u,i,m]),H=(0,U.useCallback)(async()=>{if(!_){fe(!1),E(!0),O(null);try{let t=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}?provider=${encodeURIComponent(i)}`,{method:`DELETE`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??m(`studio.errors.deleteFailed`,{status:t.status}))}d.success(m(`studio.toasts.agentDeleted`),{description:e}),u&&u(e),c()}catch(e){let t=e.message;O(t),d.error(m(`studio.toasts.deleteFailed`),{description:t})}finally{E(!1)}}},[e,_,c,u,i,m]),ye=(0,U.useCallback)(e=>{S(e.body),P(!0),M(!1)},[]),be=(0,U.useCallback)(async()=>{if(p){oe(!0),ue(null),ce(null);try{let t=await fetch(`${l()}/profiles/catalog/test?provider=${encodeURIComponent(i)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({agentId:_?y||`draft`:e,draftBody:x,sampleTask:L})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error??m(`studio.errors.testFailed`,{status:t.status}))}let n=await t.json();ce(n)}catch(e){ue(e.message)}finally{oe(!1)}}},[e,p,x,y,_,i,L,m]);return C?(0,W.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:m(`studio.loadingAgent`)})}):(0,W.jsxs)(`div`,{className:`flex flex-col h-full`,children:[!_&&(0,W.jsx)(Re,{open:de,title:m(`studio.deleteConfirm.title`,{agentId:e}),description:m(`studio.deleteConfirm.description`),confirmLabel:m(`common:actions.delete`),destructive:!0,onConfirm:H,onCancel:()=>fe(!1)}),(0,W.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 border-b border-border`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:c,className:`p-1 rounded hover:bg-accent text-muted-foreground hover:text-foreground`,title:m(`common:actions.back`),children:(0,W.jsx)(h,{className:`w-4 h-4`})}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground uppercase tracking-wide`,children:m(_?`studio.modeCreate`:`studio.modeEdit`)}),_?(0,W.jsx)(_e,{value:y,onChange:e=>{let t=e.target.value;b(t),S(e=>Mi(e,t||`custom-<name>`)),P(!0)},placeholder:`custom-my-agent`,className:`text-sm font-mono mt-1 max-w-sm`}):(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`div`,{className:`text-sm font-mono`,children:e}),p&&r&&(0,W.jsxs)(`button`,{type:`button`,onClick:async()=>{if(!(!f||!e))try{let t=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(e)}?provider=${encodeURIComponent(i)}`);if(!t.ok)return;f(r,e,(await t.json()).body)}catch{}},className:`inline-flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-full border border-accent-primary/40 bg-accent-primary/15 text-accent-primary hover:bg-accent-primary/25 focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none`,title:m(`studio.resumeAiEditTitle`),children:[(0,W.jsx)(Se,{className:`w-3 h-3`}),` `,m(`studio.resumeAiEdit`)]}),ne&&(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,W.jsx)(ee,{className:`w-3 h-3 animate-spin`}),` `,m(`studio.loadingAiDraft`)]})]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[p&&(0,W.jsxs)(I,{size:`sm`,variant:`ghost`,onClick:()=>{ie(e=>!e),F||M(!1)},title:m(`studio.testButtonTitle`),children:[(0,W.jsx)(Ee,{className:`w-3.5 h-3.5 mr-1`}),m(`studio.testButton`)]}),!_&&(0,W.jsxs)(I,{size:`sm`,variant:`ghost`,onClick:()=>{M(e=>!e),j||ie(!1)},title:m(`studio.historyButtonTitle`),children:[(0,W.jsx)(he,{className:`w-3.5 h-3.5 mr-1`}),m(`studio.historyButton`)]}),!_&&(0,W.jsxs)(I,{size:`sm`,variant:`ghost`,onClick:()=>fe(!0),disabled:w,className:`text-red-400 hover:text-red-300 aurora-light:text-destructive aurora-light:hover:text-destructive`,children:[(0,W.jsx)(T,{className:`w-3.5 h-3.5 mr-1`}),m(`common:actions.delete`)]}),(0,W.jsxs)(I,{size:`sm`,onClick:V,disabled:!ve||w,children:[(0,W.jsx)(g,{className:`w-3.5 h-3.5 mr-1`}),m(w?`common:states.saving`:_?`studio.create`:`common:actions.save`)]})]})]}),D&&(0,W.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-2 text-xs border-b border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:[(0,W.jsx)(le,{className:`w-3.5 h-3.5 flex-shrink-0`}),D]}),_&&y.length>0&&!me&&(0,W.jsx)(`div`,{className:`px-4 py-1.5 text-[11px] border-b border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:(0,W.jsx)(o,{t:m,i18nKey:`studio.validation.namePattern`,components:{code:(0,W.jsx)(`code`,{})}})}),!B&&(0,W.jsx)(`div`,{className:`px-4 py-1.5 text-[11px] border-b border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-500 aurora-light:text-accent-warning`,children:(0,W.jsx)(o,{t:m,i18nKey:`studio.validation.missingFrontmatter`,components:{code:(0,W.jsx)(`code`,{})}})}),(_||e?.startsWith(`custom-`))&&(0,W.jsx)(Di,{body:x,onChange:e=>{S(e),P(!0)}}),(0,W.jsxs)(`div`,{className:`flex flex-1 min-h-0`,children:[(0,W.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0`,children:[(0,W.jsxs)(`div`,{className:`px-4 py-1.5 border-b border-border text-[11px] font-mono text-muted-foreground flex items-center justify-between`,children:[(0,W.jsx)(`span`,{children:Ni(i,_?y||`custom-…`:e)}),N&&(0,W.jsx)(`span`,{className:`text-yellow-500 aurora-light:text-accent-warning`,children:m(`studio.unsaved`)})]}),(0,W.jsx)(`textarea`,{value:x,onChange:e=>{S(e.target.value),P(!0)},spellCheck:!1,className:`flex-1 w-full p-4 text-xs font-mono bg-background text-foreground outline-none resize-none leading-relaxed`})]}),p&&F&&(0,W.jsxs)(`aside`,{className:`w-96 flex-shrink-0 border-l border-border flex flex-col min-h-0`,children:[(0,W.jsxs)(`div`,{className:`px-3 py-2 border-b border-border text-xs font-medium text-muted-foreground uppercase tracking-wide flex items-center gap-2`,children:[(0,W.jsx)(Ee,{className:`w-3.5 h-3.5`}),` `,m(`studio.testPane.header`)]}),(0,W.jsxs)(`div`,{className:`p-3 border-b border-border`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,W.jsx)(`label`,{className:`text-[11px] text-muted-foreground`,children:m(`studio.testPane.sampleTaskLabel`)}),(0,W.jsx)(`select`,{className:`h-6 text-[11px] rounded border border-border bg-background px-1`,value:``,onChange:e=>{let t=parseInt(e.target.value,10);!isNaN(t)&&t>0&&ae(Ai[t].prompt)},disabled:R,children:Ai.map((e,t)=>(0,W.jsx)(`option`,{value:t,children:m(e.labelKey)},t))})]}),(0,W.jsx)(`textarea`,{value:L,onChange:e=>ae(e.target.value),placeholder:m(`studio.testPane.placeholder`),className:`w-full text-xs p-2 rounded border border-border bg-background min-h-[80px] resize-y font-mono`,disabled:R}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,W.jsx)(I,{size:`sm`,onClick:be,disabled:R||!L.trim()||!x.trim(),children:R?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(ee,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` `,m(`studio.testPane.running`)]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(Ee,{className:`w-3.5 h-3.5 mr-1.5`}),` `,m(`studio.testPane.run`)]})}),(0,W.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:m(`studio.testPane.sandboxNote`)})]})]}),(0,W.jsxs)(`div`,{className:`flex-1 overflow-auto p-3 min-h-0`,children:[z&&(0,W.jsx)(`div`,{className:`px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive mb-2`,children:z}),se&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] text-muted-foreground mb-2`,children:[(0,W.jsx)(`span`,{children:se.tokens===null?(0,W.jsx)(`span`,{className:`text-foreground font-mono`,title:m(`studio.testPane.tokensUnavailable`),"aria-label":m(`studio.testPane.tokensUnavailable`),children:`—`}):(0,W.jsx)(o,{t:m,i18nKey:`studio.testPane.tokens`,count:se.tokens,components:{mono:(0,W.jsx)(`span`,{className:`text-foreground font-mono`})}})}),(0,W.jsx)(`span`,{children:(0,W.jsxs)(`span`,{className:`text-foreground font-mono`,children:[(se.durationMs/1e3).toFixed(1),`s`]})})]}),(0,W.jsx)(`pre`,{className:`text-xs font-mono whitespace-pre-wrap leading-relaxed rounded border border-border bg-background p-3`,children:se.output})]}),!R&&!se&&!z&&(0,W.jsx)(`p`,{className:`text-[11px] text-muted-foreground italic`,children:m(`studio.testPane.emptyHint`)})]})]}),j&&!_&&(0,W.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-l border-border flex flex-col`,children:[(0,W.jsx)(`div`,{className:`px-3 py-2 border-b border-border text-xs font-medium text-muted-foreground uppercase tracking-wide`,children:m(`studio.versions.header`)}),(0,W.jsx)(`div`,{className:`flex-1 overflow-auto p-2 space-y-1`,children:k.length===0?(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic px-2 py-2`,children:m(`studio.versions.empty`)}):k.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>ye(e),className:`w-full text-left px-2 py-1.5 rounded hover:bg-accent/50 transition-colors`,children:[(0,W.jsxs)(`div`,{className:`text-xs font-mono text-foreground`,children:[`v`,e.version]}),(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:new Date(e.createdAt).toLocaleString()})]},e.version))}),(0,W.jsx)(`div`,{className:`px-3 py-2 border-t border-border text-[11px] text-muted-foreground`,children:m(`studio.versions.restoreHint`)})]})]})]})}var Fi={refineId:null,agentId:null,uiState:`closed`,phase:`idle`,history:[],streamingText:``,draftBody:null,baseBody:null,autoTest:!1,testResult:null,appliedVersion:null,errorMessage:null,applyConflict:null};function Ii(e){return e.replace(/<!--tool:[^>]+-->/g,``)}function Li(e,t){switch(t.type){case`OPEN`:return{...Fi,agentId:t.agentId,baseBody:t.baseBody,uiState:`composing`};case`START_TURN`:return{...e,refineId:t.refineId,uiState:`streaming`,phase:`reading`,streamingText:``,errorMessage:null,applyConflict:null,history:[...e.history,t.userTurn]};case`STREAM_DELTA`:return e.refineId===t.refineId?{...e,streamingText:e.streamingText+t.delta}:e;case`PHASE`:return e.refineId===t.refineId?{...e,phase:t.phase}:e;case`READY`:return e.refineId===t.refineId?{...e,uiState:`reviewing`,phase:`done`,draftBody:t.draftBody,streamingText:``,history:[...e.history,{role:`assistant`,content:Ii(t.draftBody),timestamp:Date.now()}]}:e;case`TEST_RESULT`:return e.refineId===t.refineId?{...e,testResult:t.result,history:[...e.history,{role:`system`,kind:`test_result`,content:t.result.output,timestamp:Date.now()}]}:e;case`APPLIED`:return e.refineId===t.refineId?{...e,uiState:`applied`,appliedVersion:t.version}:e;case`CANCELLED`:return{...e,uiState:`cancelled`};case`ERROR`:return t.refineId!==null&&e.refineId!==t.refineId?e:{...e,uiState:`error`,errorMessage:t.message};case`CONFLICT`:return e.refineId===t.refineId?{...e,applyConflict:t.reason}:e;case`TOGGLE_AUTO_TEST`:return{...e,autoTest:t.enabled};case`REHYDRATE`:return{...e,...t.payload};case`CLOSE`:return Fi;default:return e}}function Ri(e){switch(e.status){case`streaming`:return`streaming`;case`ready`:return`reviewing`;case`applied`:return`applied`;case`cancelled`:return`cancelled`;case`error`:return`error`;default:return e.draftBody?`reviewing`:`composing`}}function zi(e){let[t,n]=(0,U.useReducer)(Li,Fi),{t:r}=s(`aiedit`),{registerHandler:i,unregisterHandler:o}=a(),c=(0,U.useRef)(null);c.current=t.refineId;let u=(0,U.useRef)(null);u.current=t.agentId;let d=(0,U.useRef)(e);d.current=e;let f=(0,U.useRef)(e);(0,U.useEffect)(()=>{e!==f.current&&(f.current=e,n({type:`CLOSE`}))},[e]),(0,U.useEffect)(()=>{let e=`agent-refine-${Math.random().toString(36).slice(2,9)}`;return i(e,e=>{let t=e;if(typeof t.type!=`string`||t.projectId!==d.current||t.refineId!==c.current)return;let r=t.refineId;switch(t.type){case`agent_refine_stream`:n({type:`STREAM_DELTA`,refineId:r,delta:t.delta});break;case`agent_refine_phase`:n({type:`PHASE`,refineId:r,phase:t.phase});break;case`agent_refine_ready`:n({type:`READY`,refineId:r,draftBody:t.draftBody});break;case`agent_refine_test`:n({type:`TEST_RESULT`,refineId:r,result:t.result});break;case`agent_refine_applied`:n({type:`APPLIED`,refineId:r,version:t.version});break;case`agent_refine_cancelled`:n({type:`CANCELLED`,refineId:r});break;case`agent_refine_error`:n({type:`ERROR`,refineId:r,message:t.error});break}}),()=>o(e)},[i,o]);let p=(0,U.useCallback)((e,t)=>{n({type:`OPEN`,agentId:e,baseBody:t})},[]),m=(0,U.useCallback)(()=>{n({type:`CLOSE`})},[]);return{state:t,open:p,start:(0,U.useCallback)(async e=>{let i=u.current;if(i)try{let a=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(i)}/refine`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({instruction:e,autoTest:t.autoTest})});if(!a.ok){let e=await a.json().catch(()=>({}));n({type:`ERROR`,refineId:null,message:e.error??r(`refine.serverError`,{status:a.status})});return}let o=await a.json();c.current=o.refineId,n({type:`START_TURN`,refineId:o.refineId,userTurn:{role:`user`,content:e,timestamp:Date.now()}})}catch(e){n({type:`ERROR`,refineId:null,message:r(`refine.connectionFailed`,{message:e.message})})}},[t.autoTest,r]),sendTurn:(0,U.useCallback)(async e=>{let t=c.current,i=u.current;if(!(!t||!i)){n({type:`START_TURN`,refineId:t,userTurn:{role:`user`,content:e,timestamp:Date.now()}});try{let a=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(i)}/refine/${t}/turn`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({instruction:e})});if(!a.ok){let e=await a.json().catch(()=>({}));n({type:`ERROR`,refineId:t,message:e.error??r(`refine.serverError`,{status:a.status})})}}catch(e){n({type:`ERROR`,refineId:t,message:r(`refine.connectionFailed`,{message:e.message})})}}},[r]),cancel:(0,U.useCallback)(async()=>{let e=c.current,t=u.current;if(!(!e||!t))try{await fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}/refine/${e}`,{method:`DELETE`})}catch{}},[]),apply:(0,U.useCallback)(async e=>{let t=c.current,i=u.current;if(!(!t||!i))try{let a=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(i)}/refine/${t}/apply`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({force:!!e})});if(a.status===409){let e=await a.json().catch(()=>({}));if(e.reason===`disk_changed`||e.reason===`name_changed`){n({type:`CONFLICT`,refineId:t,reason:e.reason});return}}if(!a.ok){let e=await a.json().catch(()=>({}));n({type:`ERROR`,refineId:t,message:e.error??r(`refine.applyFailed`,{status:a.status})});return}let o=await a.json();n({type:`APPLIED`,refineId:t,version:o.version})}catch(e){n({type:`ERROR`,refineId:t,message:r(`refine.connectionFailed`,{message:e.message})})}},[r]),toggleAutoTest:(0,U.useCallback)(async e=>{let t=c.current,r=u.current;if(n({type:`TOGGLE_AUTO_TEST`,enabled:e}),!(!t||!r))try{await fetch(`${l()}/profiles/catalog/${encodeURIComponent(r)}/refine/${t}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({autoTest:e})})}catch{}},[]),rehydrate:(0,U.useCallback)(async(e,t)=>{try{let i=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}`);if(!i.ok)throw Error(r(`refine.loadAgentFailed`,{status:i.status}));let a=await i.json(),o=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}/refine/${e}`);if(!o.ok)throw Error(r(`refine.loadSessionFailed`,{status:o.status}));let s=await o.json();c.current=e,u.current=t,n({type:`REHYDRATE`,payload:{refineId:e,agentId:t,baseBody:a.body,draftBody:s.draftBody,history:s.history,autoTest:s.autoTest,phase:s.phase,uiState:Ri(s),streamingText:``}})}catch(e){n({type:`ERROR`,refineId:null,message:r(`refine.rehydrateFailed`,{message:e.message})})}},[r]),close:m}}var Bi=e(r(),1);function Vi(){return typeof window>`u`||!(`__TAURI_INTERNALS__`in window)?!1:/mac/i.test(navigator.platform)}function Hi(e){let[t,n]=(0,U.useState)(!1),r=(0,U.useRef)(null),{panelRef:i,panelStyle:a,headerHandleProps:o,resizeHandles:s,isFloating:c}=O();(0,U.useEffect)(()=>(r.current=document.activeElement,()=>{let e=r.current;e&&e instanceof HTMLElement&&e.focus()}),[]);let l=(0,U.useCallback)(()=>{e.uiPhase===`streaming`||e.uiPhase===`reviewing`?n(!0):e.onClose()},[e]),u=(0,U.useCallback)(()=>{n(!1),e.onDiscard()},[e]);(0,U.useEffect)(()=>{let t=t=>{if(t.key===`Escape`){t.preventDefault(),l();return}if((t.metaKey||t.ctrlKey)&&t.key===`Enter`&&e.uiPhase===`reviewing`&&e.canApply&&!e.applyConflict){t.preventDefault(),e.onApply();return}e.onKeyDown?.(t)};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,l]);let d=e.uiPhase===`composing`||e.uiPhase===`streaming`||e.uiPhase===`error`,f=e.uiPhase===`reviewing`||e.uiPhase===`applied`;return(0,Bi.createPortal)((0,W.jsxs)(`div`,{className:`fixed inset-0 z-50 flex p-3 pt-10 sm:p-6 sm:pt-12 bg-black/40 backdrop-blur-sm animate-in fade-in duration-150`,"data-testid":`ai-edit-backdrop`,children:[(0,W.jsxs)(`div`,{ref:i,role:`dialog`,"aria-modal":`true`,"aria-label":`${e.eyebrow} · ${e.targetLabel}`,className:`m-auto w-full h-full max-w-[1600px] flex flex-col bg-background rounded-xl border border-border/40 shadow-2xl overflow-hidden`,style:a,children:[(0,W.jsx)(Ui,{eyebrow:e.eyebrow,targetLabel:e.targetLabel,targetLabelMono:e.targetLabelMono??!0,showApply:e.uiPhase===`reviewing`&&e.canApply&&!e.applyConflict,showDiscard:e.uiPhase!==`applied`,onApply:e.onApply,onDiscard:l,onMinimize:e.onMinimize,headerHandleProps:o,isFloating:c}),d&&(0,W.jsx)(Wi,{uiPhase:e.uiPhase,headline:e.uiPhase===`streaming`?e.streamingHeadline:e.headline,description:e.description,chips:e.chips,onChipSubmit:e.onChipSubmit,streamingText:e.streamingText,composer:e.composer,composerAccessory:e.composerAccessory,history:e.history??[],baseBody:e.baseBody,baseBodyDisclosureLabel:e.baseBodyDisclosureLabel,errorMessage:e.errorMessage}),f&&(0,W.jsx)(Yi,{state:e,appliedNotice:e.appliedNotice}),t&&(0,W.jsx)(ta,{onCancel:()=>n(!1),onConfirm:u})]}),(0,W.jsx)(k,{handles:s})]}),document.body)}function Ui({eyebrow:e,targetLabel:t,targetLabelMono:n,showApply:r,showDiscard:i,onApply:a,onDiscard:o,onMinimize:c,headerHandleProps:l,isFloating:u}){let{t:d}=s(`aiedit`),f=Vi()?`pl-[88px]`:`pl-4`;return(0,W.jsxs)(`div`,{...l,className:`flex-shrink-0 flex items-center justify-between ${f} pr-4 h-14 border-b border-border bg-card/60 backdrop-blur-sm${u?` cursor-grab active:cursor-grabbing`:``}`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:o,className:`flex items-center gap-2 group p-1 -ml-1 rounded hover:bg-accent focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none max-w-[60vw]`,"aria-label":d(`shell.backAriaLabel`),children:[(0,W.jsx)(h,{className:`w-4 h-4 text-muted-foreground group-hover:text-foreground transition-colors flex-shrink-0`}),(0,W.jsxs)(`div`,{className:`text-left min-w-0`,children:[(0,W.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground/70 leading-none`,children:e}),n?(0,W.jsx)(`code`,{className:`text-sm font-mono font-medium text-foreground truncate block`,children:t}):(0,W.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate block`,children:t})]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c&&(0,W.jsx)(I,{variant:`ghost`,size:`sm`,onClick:c,"aria-label":d(`common:actions.minimize`),"data-testid":`ai-edit-minimize`,children:(0,W.jsx)(pe,{className:`w-4 h-4`})}),i&&(0,W.jsx)(I,{variant:`ghost`,size:`sm`,onClick:o,children:d(`common:actions.discard`)}),r&&(0,W.jsxs)(I,{size:`sm`,onClick:a,className:`gap-1.5`,children:[(0,W.jsx)(_,{className:`w-3.5 h-3.5`}),` `,d(`shell.apply`),(0,W.jsx)(`span`,{className:`text-[10px] opacity-70 ml-1`,children:H(`⌘⏎`)})]})]})]})}function Wi({uiPhase:e,headline:t,description:n,chips:r,onChipSubmit:i,streamingText:a,composer:o,composerAccessory:c,history:l,baseBody:u,baseBodyDisclosureLabel:d,errorMessage:f}){let{t:p}=s(`aiedit`),m=e===`composing`&&(r?.length??0)>0&&l.length===0,h=e===`error`,g=l.filter(e=>e.role===`user`||e.role===`system`&&e.kind===`test_result`);return(0,W.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:(0,W.jsxs)(`div`,{className:`mx-auto max-w-2xl px-6 py-12 pb-32 flex flex-col gap-6`,children:[(0,W.jsxs)(`header`,{className:`text-center space-y-2`,children:[(0,W.jsx)(`div`,{className:`inline-flex items-center justify-center w-10 h-10 rounded-full ring-1 mx-auto `+(h?`bg-red-500/10 aurora-light:bg-destructive/10 ring-red-500/30 aurora-light:ring-destructive/30`:`bg-accent-primary/15 ring-accent-primary/30`),children:h?(0,W.jsx)(E,{className:`w-5 h-5 text-red-400 aurora-light:text-destructive`}):(0,W.jsx)(w,{className:`w-5 h-5 text-accent-primary`})}),(0,W.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:h?p(`shell.somethingWentWrong`):t}),h&&f&&(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-md mx-auto font-mono break-words`,children:f}),!h&&n&&(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-md mx-auto leading-relaxed`,children:n})]}),e===`streaming`&&(0,W.jsx)(Ki,{streamingText:a}),m&&r&&i&&(0,W.jsx)(Gi,{chips:r,onPick:i}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[o,c&&(0,W.jsx)(`div`,{children:c})]}),g.length>0&&(0,W.jsx)(qi,{history:g}),u&&(0,W.jsx)(Ji,{body:u,label:d??p(`shell.viewCurrentContent`)})]})})}function Gi({chips:e,onPick:t}){let{t:n}=s(`aiedit`);return(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground/70`,children:n(`shell.quickPrompts`)}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>t(e),className:`text-xs px-3 py-1.5 rounded-full border border-border bg-card/40 hover:border-accent-primary/50 hover:bg-accent-primary/10 hover:text-accent-primary text-foreground/80 transition-colors focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none`,children:e},e))})]})}function Ki({streamingText:e}){let{t}=s(`aiedit`);return(0,W.jsx)(`div`,{className:`rounded-xl border border-accent-primary/30 bg-accent-primary/5 p-4`,children:e?(0,W.jsxs)(`div`,{className:`text-xs font-mono whitespace-pre-wrap break-words text-foreground/80 max-h-64 overflow-y-auto leading-relaxed`,children:[ra(e),(0,W.jsx)(`span`,{className:`inline-block w-1.5 h-3 bg-accent-primary animate-pulse align-middle ml-0.5`})]}):(0,W.jsxs)(`div`,{className:`text-xs text-muted-foreground italic flex items-center gap-1.5`,children:[(0,W.jsx)(ee,{className:`w-3 h-3 animate-spin`}),t(`shell.workingOnRefinement`)]})})}function qi({history:e}){let{t}=s(`aiedit`);return e.length===0?null:(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground/70`,children:t(`shell.history`)}),(0,W.jsx)(`div`,{className:`space-y-2`,children:e.map((e,t)=>(0,W.jsx)(Qi,{turn:e},t))})]})}function Ji({body:e,label:t}){let[n,r]=(0,U.useState)(!1);return(0,W.jsxs)(`div`,{className:`border-t border-border/60 pt-4`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none rounded px-1 -ml-1`,children:[n?(0,W.jsx)(m,{className:`w-3.5 h-3.5`}):(0,W.jsx)(x,{className:`w-3.5 h-3.5`}),t]}),n&&(0,W.jsx)(`pre`,{className:`mt-2 p-3 rounded-md bg-muted/40 border border-border text-[11px] font-mono whitespace-pre-wrap break-words max-h-72 overflow-y-auto text-foreground/80`,children:e})]})}function Yi({state:e,appliedNotice:t}){return(0,W.jsxs)(`div`,{className:`flex-1 min-h-0 grid grid-cols-1 md:grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)]`,children:[(0,W.jsx)(Xi,{history:e.history??[],composer:e.composer,composerAccessory:e.composerAccessory,secondaryAction:e.secondaryAction,appliedNotice:t,uiPhase:e.uiPhase}),(0,W.jsx)($i,{diff:e.diff,label:e.diffHeaderLabel,applyConflict:e.applyConflict??null,onForceApply:e.onForceApply})]})}function Xi({history:e,composer:t,composerAccessory:n,secondaryAction:r,appliedNotice:i,uiPhase:a}){let{t:o}=s(`aiedit`);return(0,W.jsxs)(`section`,{"aria-label":o(`shell.conversation`),className:`flex flex-col min-h-0 border-r border-border bg-card/20`,children:[(0,W.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 pb-32 space-y-3`,"aria-live":`polite`,children:[e.map((e,t)=>(0,W.jsx)(Qi,{turn:e},t)),a===`applied`&&(i??(0,W.jsx)(Zi,{}))]}),(0,W.jsxs)(`div`,{className:`flex-shrink-0 border-t border-border p-3 space-y-2`,children:[t,n,r&&(0,W.jsxs)(`button`,{type:`button`,onClick:r.onClick,className:`w-full inline-flex items-center justify-center gap-1.5 text-[11px] text-muted-foreground hover:text-foreground py-1.5 rounded hover:bg-accent/50 focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none`,children:[r.icon??(0,W.jsx)(C,{className:`w-3 h-3`}),r.label]})]})]})}function Zi(){let{t:e}=s(`aiedit`);return(0,W.jsxs)(`div`,{className:`rounded-md border border-green-500/40 aurora-light:border-accent-success/40 bg-green-500/10 aurora-light:bg-accent-success/10 p-3 text-xs text-green-300 aurora-light:text-accent-success flex items-center gap-2`,children:[(0,W.jsx)(_,{className:`w-3.5 h-3.5`}),e(`shell.applied`)]})}function Qi({turn:e}){let{t}=s(`aiedit`);return e.role===`user`?(0,W.jsxs)(`div`,{className:`flex flex-col items-end`,children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-1`,children:t(`shell.you`)}),(0,W.jsx)(`div`,{className:`max-w-[90%] rounded-2xl rounded-br-sm bg-accent-primary/15 text-foreground text-sm px-3 py-2 whitespace-pre-wrap break-words`,children:e.content})]}):e.role===`system`&&e.kind===`test_result`?(0,W.jsxs)(`div`,{className:`rounded-md border border-accent-info/30 bg-accent-info/5 p-3 text-xs`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium mb-1 text-accent-info`,children:[(0,W.jsx)(w,{className:`w-3 h-3`}),` `,t(`shell.autoTestResult`)]}),(0,W.jsx)(`pre`,{className:`text-[11px] font-mono whitespace-pre-wrap break-words text-foreground/80 max-h-48 overflow-y-auto`,children:e.content})]}):(0,W.jsxs)(`div`,{className:`flex flex-col items-start`,children:[(0,W.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mb-1 inline-flex items-center gap-1`,children:[(0,W.jsx)(w,{className:`w-3 h-3 text-accent-primary`}),` `,t(`shell.ai`)]}),(0,W.jsx)(`div`,{className:`max-w-[90%] rounded-2xl rounded-bl-sm border border-border bg-muted/30 text-xs px-3 py-2 text-muted-foreground italic`,children:t(`shell.refinementReady`)})]})}function $i({diff:e,label:t,applyConflict:n,onForceApply:r}){let{t:i}=s(`aiedit`);return(0,W.jsxs)(`section`,{"aria-label":i(`shell.diffPreview`),className:`flex flex-col min-h-0`,children:[(0,W.jsxs)(`div`,{className:`flex-shrink-0 flex items-center justify-between px-4 h-9 border-b border-border bg-card/40`,children:[(0,W.jsx)(`span`,{className:`text-xs font-mono text-muted-foreground truncate`,children:t??i(`shell.proposedChanges`)}),(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:i(`shell.wordLevelDiff`)})]}),n===`disk_changed`&&(0,W.jsx)(ea,{kind:`disk_changed`,action:r&&(0,W.jsxs)(I,{variant:`ghost`,size:`sm`,onClick:r,children:[(0,W.jsx)(Ce,{className:`w-3 h-3 mr-1`}),` `,i(`shell.forceApply`)]})}),n===`name_changed`&&(0,W.jsx)(ea,{kind:`name_changed`}),(0,W.jsx)(`div`,{className:`flex-1 overflow-auto p-4 pb-32`,children:e})]})}function ea({kind:e,action:t}){let{t:n}=s(`aiedit`),r=n(e===`disk_changed`?`shell.conflict.diskChanged`:`shell.conflict.nameChanged`);return(0,W.jsxs)(`div`,{role:`alert`,className:`flex items-start justify-between gap-3 px-4 py-2 border-b border-yellow-500/40 aurora-light:border-accent-warning/40 bg-yellow-500/10 aurora-light:bg-accent-warning/10 text-yellow-200 aurora-light:text-accent-warning text-xs`,children:[(0,W.jsxs)(`div`,{className:`flex items-start gap-2 min-w-0`,children:[(0,W.jsx)(E,{className:`w-3.5 h-3.5 mt-0.5 flex-shrink-0`}),(0,W.jsx)(`span`,{children:r})]}),t]})}function ta({onCancel:e,onConfirm:t}){let{t:n}=s(`aiedit`);return(0,W.jsx)(`div`,{role:`alertdialog`,"aria-modal":`true`,"aria-label":n(`shell.discardDialog.ariaLabel`),className:`absolute inset-0 z-10 flex items-center justify-center bg-black/40`,children:(0,W.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-5 max-w-sm shadow-xl`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,W.jsx)(E,{className:`w-4 h-4 text-yellow-400 aurora-light:text-accent-warning`}),(0,W.jsx)(`h2`,{className:`text-sm font-medium`,children:n(`shell.discardDialog.title`)})]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground mb-4`,children:n(`shell.discardDialog.body`)}),(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(I,{variant:`ghost`,size:`sm`,onClick:e,children:n(`shell.discardDialog.keepEditing`)}),(0,W.jsx)(I,{size:`sm`,onClick:t,children:n(`common:actions.discard`)})]})]})})}function na({hunks:e}){return(0,W.jsx)(`pre`,{className:`font-mono text-xs leading-5 whitespace-pre-wrap break-words`,children:e.map((e,t)=>e.type===`eq`?(0,W.jsx)(`span`,{className:`text-foreground/70`,children:e.text},t):e.type===`add`?(0,W.jsxs)(`span`,{"data-hunk":`add`,className:`bg-green-500/20 aurora-light:bg-accent-success/15 text-green-200 aurora-light:text-accent-success rounded px-0.5 ring-1 ring-green-500/30 aurora-light:ring-accent-success/30`,children:[(0,W.jsx)(`span`,{"aria-hidden":`true`,children:`+ `}),e.text]},t):(0,W.jsxs)(`span`,{"data-hunk":`del`,className:`bg-red-500/20 aurora-light:bg-destructive/15 text-red-200 aurora-light:text-destructive line-through rounded px-0.5 ring-1 ring-red-500/30 aurora-light:ring-destructive/30`,children:[(0,W.jsx)(`span`,{"aria-hidden":`true`,children:`− `}),e.text]},t))})}function ra(e){return e.replace(/<!--tool:[^>]+-->/g,``)}function ia(e,t){let n=/(\s+)/,r=e.split(n),i=t.split(n);if(r.length>2e4||i.length>2e4)return aa(e,t);let a=r.length,o=i.length,s=new Uint16Array((a+1)*(o+1)),c=o+1;for(let e=a-1;e>=0;e--)for(let t=o-1;t>=0;t--)r[e]===i[t]?s[e*c+t]=s[(e+1)*c+(t+1)]+1:s[e*c+t]=Math.max(s[(e+1)*c+t],s[e*c+(t+1)]);let l=[],u=0,d=0,f=null,p=``,m=()=>{f!==null&&p&&l.push({type:f,text:p}),f=null,p=``},h=(e,t)=>{f===e?p+=t:(m(),f=e,p=t)};for(;u<a&&d<o;)r[u]===i[d]?(h(`eq`,r[u]),u++,d++):s[(u+1)*c+d]>=s[u*c+(d+1)]?(h(`del`,r[u]),u++):(h(`add`,i[d]),d++);for(;u<a;)h(`del`,r[u++]);for(;d<o;)h(`add`,i[d++]);return m(),l}function aa(e,t){let n=e.split(`
112
112
  `),r=t.split(`
113
113
  `),i=[],a=0,o=0;for(;a<n.length&&o<r.length;)if(n[a]===r[o])i.push({type:`eq`,text:n[a]+`
114
114
  `}),a++,o++;else{let e=r.indexOf(n[a],o),t=n.indexOf(r[o],a);e!==-1&&(t===-1||e-o<=t-a)?(i.push({type:`add`,text:r[o]+`
115
115
  `}),o++):(i.push({type:`del`,text:n[a]+`
116
116
  `}),a++)}for(;a<n.length;)i.push({type:`del`,text:n[a++]+`
117
117
  `});for(;o<r.length;)i.push({type:`add`,text:r[o++]+`
118
- `});return i}function oa({value:e,onChange:t,onSubmit:n,disabled:r,placeholder:i,autoFocus:a,inputRef:o}){let{t:c}=s(`aiedit`);return(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(`div`,{className:`relative rounded-xl border border-border bg-card/40 focus-within:border-accent-primary/40 focus-within:ring-2 focus-within:ring-accent-primary/20 transition-all`,children:[(0,W.jsx)(`textarea`,{ref:o,value:e,onChange:e=>t(e.target.value),placeholder:i,rows:3,disabled:r,autoFocus:a,className:`w-full text-sm p-3 pr-14 bg-transparent resize-none focus:outline-none disabled:opacity-50 placeholder:text-muted-foreground/60`,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),n())}}),(0,W.jsx)(`button`,{type:`button`,onClick:n,disabled:!e.trim()||r,"aria-label":c(`shell.composer.sendAriaLabel`),className:`absolute bottom-2.5 right-2.5 p-2 rounded-md bg-accent-primary text-white hover:bg-accent-primary/90 disabled:opacity-30 disabled:cursor-not-allowed focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none transition-opacity`,children:r?(0,W.jsx)(S,{className:`w-3.5 h-3.5 animate-spin`}):(0,W.jsx)(sa,{})})]}),(0,W.jsx)(`div`,{className:`flex items-center justify-end text-[11px] text-muted-foreground/70`,children:(0,W.jsxs)(`span`,{children:[(0,W.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted/60 text-[10px] font-mono`,children:H(`⌘⏎`)}),` `,c(`shell.composer.kbdSubmit`),(0,W.jsx)(`span`,{className:`mx-1.5`,children:`·`}),(0,W.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted/60 text-[10px] font-mono`,children:`Esc`}),` `,c(`shell.composer.kbdCancel`)]})})]})}function sa(){return(0,W.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-3.5 h-3.5`,children:[(0,W.jsx)(`path`,{d:`M22 2 11 13`}),(0,W.jsx)(`path`,{d:`M22 2 15 22l-4-9-9-4Z`})]})}var ca=[`refine.chips.tightenTools`,`refine.chips.stricterPersonality`,`refine.chips.workflowSection`,`refine.chips.sharpenDescription`,`refine.chips.matchDeveloperStyle`];function la({agentId:e,baseBody:t,resumeRefineId:n,onClose:r,onMinimize:i,onStateChange:a,onOpenInStudio:o,onApplied:c}){let{t:l}=s(`agentstudio`),{activeProjectId:d}=u(),f=zi(d),[p,m]=(0,U.useState)(``),h=(0,U.useRef)(null),_=(0,U.useRef)(!1);(0,U.useEffect)(()=>{_.current||(_.current=!0,n?f.rehydrate(n,e):f.open(e,t))},[e,t,n,f]),(0,U.useEffect)(()=>{let e=setTimeout(()=>h.current?.focus(),50);return()=>clearTimeout(e)},[]);let v=(0,U.useRef)(a);v.current=a,(0,U.useEffect)(()=>{v.current?.({refineId:f.state.refineId??null})},[f.state.refineId]);let y=(0,U.useRef)(null);(0,U.useEffect)(()=>{f.state.uiState===`applied`&&f.state.appliedVersion!==null&&f.state.appliedVersion!==y.current&&(y.current=f.state.appliedVersion,c&&f.state.agentId&&c(f.state.agentId,f.state.appliedVersion))},[f.state.uiState,f.state.appliedVersion,f.state.agentId,c]);let b=(0,U.useCallback)(async e=>{let t=e.trim();t&&(m(``),f.state.refineId?await f.sendTurn(t):await f.start(t))},[f]),x=(0,U.useCallback)(()=>{b(p)},[p,b]),S=(0,U.useCallback)(async()=>{f.state.refineId&&(f.state.uiState===`streaming`||f.state.uiState===`reviewing`)&&await f.cancel(),r()},[f,r]),C=ua(f.state),ee=(0,U.useMemo)(()=>!f.state.draftBody||!f.state.baseBody?null:(0,W.jsx)(na,{hunks:ia(f.state.baseBody,f.state.draftBody)}),[f.state.baseBody,f.state.draftBody]);return(0,W.jsx)(Hi,{uiPhase:C,errorMessage:f.state.errorMessage,applyConflict:f.state.applyConflict,eyebrow:l(`refine.eyebrow`),targetLabel:e,targetLabelMono:!0,headline:l(`refine.headline`),streamingHeadline:l(`refine.streamingHeadline`),description:da(t),chips:ca.map(e=>l(e)),onChipSubmit:e=>void b(e),composer:(0,W.jsx)(oa,{value:p,onChange:m,onSubmit:x,disabled:C===`streaming`||C===`applied`,placeholder:f.state.refineId?l(`refine.placeholderFollowUp`):l(`refine.placeholderInitial`),inputRef:h}),streamingText:f.state.streamingText,history:f.state.history,diff:ee,diffHeaderLabel:`.claude/agents/${e}.md`,baseBody:t,baseBodyDisclosureLabel:l(`refine.viewCurrentBody`),appliedNotice:f.state.appliedVersion===null?void 0:(0,W.jsx)(`div`,{className:`rounded-md border border-green-500/40 aurora-light:border-accent-success/40 bg-green-500/10 aurora-light:bg-accent-success/10 p-3 text-xs text-green-300 aurora-light:text-accent-success`,children:l(`refine.appliedAsVersion`,{version:f.state.appliedVersion})}),canApply:f.state.uiState===`reviewing`&&!!f.state.draftBody&&!f.state.applyConflict,onApply:()=>void f.apply(),onForceApply:()=>void f.apply(!0),onDiscard:()=>void S(),onClose:()=>void S(),onMinimize:i?()=>i(f.state.refineId??null):void 0,secondaryAction:o&&f.state.draftBody&&f.state.refineId?{label:l(`refine.openInStudio`),icon:(0,W.jsx)(g,{className:`w-3 h-3`}),onClick:()=>{f.state.refineId&&f.state.draftBody&&o&&o(f.state.refineId,f.state.draftBody)}}:void 0})}function ua(e){switch(e.uiState){case`streaming`:return`streaming`;case`reviewing`:return`reviewing`;case`applied`:return`applied`;case`error`:return`error`;default:return`composing`}}function da(e){let t=e.match(/^---\r?\n([\s\S]*?)\r?\n---/);if(!t)return null;let n=t[1].match(/^description:\s*([\s\S]*?)(?=^[a-z_]+:\s|\Z)/m);if(!n)return null;let r=n[1].trim();return(r.startsWith(`"`)&&r.endsWith(`"`)||r.startsWith(`'`)&&r.endsWith(`'`))&&(r=r.slice(1,-1)),r=r.replace(/\\n/g,` `).replace(/\\t/g,` `).replace(/\\"/g,`"`).replace(/\\'/g,`'`).replace(/\\\\/g,`\\`).replace(/\s+/g,` `).trim(),r.length>240&&(r=r.slice(0,237)+`…`),r||null}function fa(){let{t:e}=s(`agents`),[t,n]=(0,U.useState)([]),[r,i]=(0,U.useState)(null),[a,c]=(0,U.useState)(null),[d,p]=(0,U.useState)(!0),[m,h]=(0,U.useState)(!1),[g,_]=(0,U.useState)(null),[b,T]=(0,U.useState)({kind:`closed`}),[E,D]=(0,U.useState)({kind:`closed`}),[k,re]=(0,U.useState)(!1),[F,ie]=(0,U.useState)(``),[ae,oe]=(0,U.useState)(`all`),[I,L]=(0,U.useState)(null),[ce,R]=(0,U.useState)(!1),[le,ue]=(0,U.useState)(``),[de,fe]=(0,U.useState)(``),[z,he]=(0,U.useState)(!1),[ge,_e]=(0,U.useState)(null),{activeProjectId:B,projects:ye}=u(),V=ye.find(e=>e.id===B)?.provider??`claude`,H=f(V),{minimize:Se}=v(),Ce=(0,U.useRef)({refineId:null}),we=(0,U.useRef)(E);we.current=E;let Te=(0,U.useCallback)(()=>{let t=we.current;t.kind!==`open`||!t.projectId||Se({kind:`ai-edit`,projectId:t.projectId,label:e(`catalog.aiEditChipLabel`,{agentId:t.agentId}),restoreRoute:`/agents`,params:{agentId:t.agentId,baseBody:t.baseBody,resumeRefineId:Ce.current.refineId??t.resumeRefineId}})},[Se,e]);y(`ai-edit`,B,e=>{e.kind!==`ai-edit`||!H||(Te(),Ce.current={refineId:e.params.resumeRefineId??null},D({kind:`open`,projectId:e.projectId,agentId:e.params.agentId,baseBody:e.params.baseBody,resumeRefineId:e.params.resumeRefineId}))});let Ee=(0,U.useCallback)(()=>{let t=!1;return p(!0),fetch(`${l()}/profiles/catalog?provider=${encodeURIComponent(V)}`).then(t=>{if(!t.ok)throw Error(e(`catalog.errors.loadFailed`,{status:t.status}));return t.json()}).then(e=>{t||(n(e.agents),e.agents.length>0&&!r&&i(e.agents[0].id))}).catch(e=>{t||_(e.message)}).finally(()=>{t||p(!1)}),()=>{t=!0}},[V,r,e]);(0,U.useEffect)(()=>Ee(),[Ee]);let De=(0,U.useCallback)(t=>{let n=!1;return h(!0),c(null),fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}?provider=${encodeURIComponent(V)}`).then(t=>{if(!t.ok)throw Error(e(`catalog.errors.bodyLoadFailed`,{status:t.status}));return t.json()}).then(e=>{n||c(e.body)}).catch(e=>{n||_(e.message)}).finally(()=>{n||h(!1)}),()=>{n=!0}},[V,e]);if((0,U.useEffect)(()=>{if(r)return De(r)},[r,De]),d)return(0,W.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`catalog.loading`)})});if(b.kind!==`closed`)return(0,W.jsx)(Pi,{agentId:b.kind===`edit`?b.agentId:void 0,initialBody:b.kind===`duplicate`||b.kind===`create`?b.initialBody:void 0,initialName:b.kind===`create`?b.initialName:void 0,draftFromRefine:b.kind===`edit`?b.draftFromRefine:void 0,provider:V,defaultModel:me(V),automationEnabled:H,onClose:()=>T({kind:`closed`}),onSaved:e=>{i(e),T({kind:`closed`}),Ee()},onResumeRefine:(e,t,n)=>{T({kind:`closed`}),B&&(Te(),Ce.current={refineId:e},D({kind:`open`,projectId:B,agentId:t,baseBody:n,resumeRefineId:e}))}});if(E.kind===`open`&&H)return(0,W.jsx)(ve,{onClose:()=>D({kind:`closed`}),children:(0,W.jsx)(la,{agentId:E.agentId,baseBody:E.baseBody,resumeRefineId:E.resumeRefineId,onStateChange:e=>{Ce.current=e},onClose:()=>D({kind:`closed`}),onMinimize:t=>{let n=E.kind===`open`?E.projectId:B;if(!n){D({kind:`closed`});return}let r=E.kind===`open`?E.agentId:``,i=E.kind===`open`?E.baseBody:``;Se({kind:`ai-edit`,projectId:n,label:e(`catalog.aiEditChipLabel`,{agentId:r}),restoreRoute:`/agents`,params:{agentId:r,baseBody:i,resumeRefineId:t??void 0}}),D({kind:`closed`})},onApplied:e=>{D({kind:`closed`}),i(e),Ee()},onOpenInStudio:(e,t)=>{D({kind:`closed`}),T({kind:`edit`,agentId:E.agentId,draftFromRefine:e})}},`${E.agentId}:${E.resumeRefineId??`fresh`}`)});let Oe=(()=>{let e=F.trim().toLowerCase();return Oi.filter(t=>!(ae!==`all`&&t.category!==ae||I&&!t.tags.includes(I)||e&&!(t.label+` `+t.blurb+` `+t.tags.join(` `)+` `+t.category).toLowerCase().includes(e)))})(),ke=(()=>{let e=new Map;for(let t of Oi)e.set(t.category,(e.get(t.category)??0)+1);return e})(),Ae=()=>{re(!1),ie(``),oe(`all`),L(null)},je=()=>(0,W.jsx)(N,{open:k,onOpenChange:e=>{e||Ae()},children:(0,W.jsxs)(M,{className:`max-w-4xl p-0 h-[85vh] flex flex-col overflow-hidden`,children:[(0,W.jsxs)(`div`,{className:`flex-shrink-0 px-6 pt-5 pb-3 border-b border-border`,children:[(0,W.jsxs)(j,{children:[(0,W.jsxs)(A,{className:`flex items-center gap-2 text-base`,children:[(0,W.jsx)(x,{className:`w-4 h-4 text-accent-primary`}),` `,e(`catalog.templates.title`),(0,W.jsx)(`span`,{className:`text-[11px] font-normal text-muted-foreground ml-1`,children:e(`catalog.templates.countOf`,{shown:Oe.length,total:Oi.length})})]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e(`catalog.templates.description`)})]}),(0,W.jsxs)(`div`,{className:`mt-3 relative`,children:[(0,W.jsx)(te,{className:`w-3.5 h-3.5 absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none`}),(0,W.jsx)(`input`,{value:F,onChange:e=>ie(e.target.value),placeholder:e(`catalog.templates.searchPlaceholder`),className:`w-full h-9 pl-8 pr-8 text-sm rounded-md border border-border bg-background focus:outline-none focus:ring-1 focus:ring-primary/40`,autoFocus:!0}),F&&(0,W.jsx)(`button`,{type:`button`,onClick:()=>ie(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded hover:bg-accent text-muted-foreground`,children:(0,W.jsx)(ne,{className:`w-3.5 h-3.5`})})]}),(0,W.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto mt-3 pb-1 scrollbar-thin`,children:[(0,W.jsx)(pa,{label:e(`catalog.templates.allCategories`),count:Oi.length,active:ae===`all`,onClick:()=>oe(`all`)}),ki.map(e=>(0,W.jsx)(pa,{label:e,count:ke.get(e)??0,active:ae===e,onClick:()=>oe(e)},e))]}),I&&(0,W.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,W.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e(`catalog.templates.tagFilter`)}),(0,W.jsxs)(`button`,{type:`button`,onClick:()=>L(null),className:`inline-flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-full bg-accent-primary/20 text-accent-primary hover:bg-accent-primary/30`,children:[(0,W.jsx)(xe,{className:`w-3 h-3`}),` `,I,(0,W.jsx)(ne,{className:`w-3 h-3`})]})]})]}),(0,W.jsx)(`div`,{className:`flex-1 overflow-y-auto px-6 py-4`,children:Oe.length===0?(0,W.jsx)(`div`,{className:`h-full flex items-center justify-center text-center`,children:(0,W.jsxs)(`div`,{className:`max-w-sm`,children:[(0,W.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e(`catalog.templates.noMatch`)}),(0,W.jsx)(`button`,{type:`button`,onClick:()=>{ie(``),oe(`all`),L(null)},className:`text-xs text-accent-primary hover:underline mt-2`,children:e(`catalog.templates.clearFilters`)})]})}):(0,W.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:Oe.map(t=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>{Ae(),T({kind:`create`,initialBody:t.body,initialName:t.nameHint})},className:`group text-left p-4 rounded-lg border border-border bg-card/40 hover:border-accent-primary/50 hover:bg-accent/40 hover:shadow-sm transition-all`,children:[(0,W.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,W.jsx)(`span`,{className:`text-2xl leading-none mt-0.5`,children:t.emoji}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsx)(`div`,{className:`text-sm font-semibold text-foreground group-hover:text-accent-primary truncate`,children:t.label}),(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:t.category})]})]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2 min-h-[2lh]`,children:t.blurb}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:t.tags.slice(0,5).map(e=>(0,W.jsx)(`span`,{role:`button`,tabIndex:0,onClick:t=>{t.stopPropagation(),L(e)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),L(e))},className:`text-[10px] px-1.5 py-0.5 rounded bg-muted/50 text-muted-foreground hover:bg-accent-primary/20 hover:text-accent-primary cursor-pointer transition-colors `+(I===e?`bg-accent-primary/20 text-accent-primary`:``),children:e},e))}),(0,W.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-border/40 flex items-center justify-between`,children:[(0,W.jsx)(`code`,{className:`text-[10px] font-mono text-muted-foreground/70 truncate`,children:t.nameHint}),(0,W.jsx)(`span`,{className:`text-[10px] text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity`,children:e(`catalog.templates.openInStudio`)})]})]},t.id))})}),(0,W.jsxs)(`div`,{className:`flex-shrink-0 px-6 py-3 border-t border-border flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e(`catalog.templates.tip`)}),(0,W.jsx)(P,{variant:`ghost`,size:`sm`,onClick:Ae,children:e(`common:actions.cancel`)})]})]})}),Me=()=>H?(0,W.jsx)(N,{open:ce,onOpenChange:e=>{!e&&!z&&(R(!1),_e(null))},children:(0,W.jsxs)(M,{className:`max-w-lg`,children:[(0,W.jsx)(j,{children:(0,W.jsxs)(A,{className:`flex items-center gap-2`,children:[(0,W.jsx)(w,{className:`w-4 h-4 text-accent-primary`}),` `,e(`catalog.generate.title`)]})}),(0,W.jsxs)(`div`,{className:`space-y-3 py-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:e(`catalog.generate.agentIdLabel`)}),(0,W.jsx)(se,{value:le,onChange:e=>ue(e.target.value),placeholder:`custom-my-agent`,className:`text-sm font-mono`,disabled:z}),(0,W.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,W.jsx)(o,{t:e,i18nKey:`catalog.generate.agentIdHint`,components:{code:(0,W.jsx)(`code`,{})}})})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:e(`catalog.generate.descriptionLabel`)}),(0,W.jsx)(`textarea`,{value:de,onChange:e=>fe(e.target.value),placeholder:e(`catalog.generate.descriptionPlaceholder`),className:`w-full text-sm p-2 rounded border border-border bg-background min-h-[120px] resize-y`,disabled:z})]}),ge&&(0,W.jsx)(`div`,{className:`px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:ge}),(0,W.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:(0,W.jsx)(o,{t:e,i18nKey:`catalog.generate.note`,components:{code:(0,W.jsx)(`code`,{})}})})]}),(0,W.jsxs)(O,{children:[(0,W.jsx)(P,{variant:`ghost`,size:`sm`,onClick:()=>R(!1),disabled:z,children:e(`common:actions.cancel`)}),(0,W.jsx)(P,{size:`sm`,onClick:Ne,disabled:z||!le.trim()||!de.trim(),children:z?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(S,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` `,e(`catalog.generate.generating`)]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(w,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.generate.generateButton`)]})})]})]})}):null,Ne=async()=>{if(H){he(!0),_e(null);try{let t=await fetch(`${l()}/profiles/catalog/generate?provider=${encodeURIComponent(V)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:le.trim(),description:de.trim()})});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`catalog.errors.generateFailed`,{status:t.status}))}let n=await t.json();R(!1),T({kind:`create`,initialBody:n.draft,initialName:le.trim()})}catch(e){_e(e.message)}finally{he(!1)}}},Pe=async t=>{try{let n=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}?provider=${encodeURIComponent(V)}`);if(!n.ok)throw Error(e(`catalog.errors.agentLoadFailed`,{status:n.status}));let r=await n.json();T({kind:`duplicate`,from:t,initialBody:r.body})}catch(e){_(e.message)}};if(t.length===0)return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,W.jsxs)(`div`,{className:`text-center max-w-sm`,children:[(0,W.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`catalog.empty.title`)}),(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:(0,W.jsx)(o,{t:e,i18nKey:`catalog.empty.body`,values:{command:`npx specrails-core@latest update`},components:{code:(0,W.jsx)(`code`,{className:`text-foreground`})}})}),(0,W.jsxs)(`div`,{className:`flex gap-2 justify-center flex-wrap`,children:[H&&(0,W.jsxs)(P,{size:`sm`,onClick:()=>R(!0),children:[(0,W.jsx)(w,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.generateWithAi`)]}),(0,W.jsxs)(P,{size:`sm`,variant:`ghost`,onClick:()=>re(!0),children:[(0,W.jsx)(x,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.template`)]}),(0,W.jsxs)(P,{size:`sm`,variant:`ghost`,onClick:()=>T({kind:`create`}),children:[(0,W.jsx)(ee,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.blank`)]})]})]})}),je(),Me()]});let Fe=t.filter(e=>e.kind===`upstream`),Ie=t.filter(e=>e.kind===`custom`),G=t.find(e=>e.id===r);return(0,W.jsxs)(W.Fragment,{children:[je(),Me(),(0,W.jsxs)(`div`,{className:`flex h-full`,children:[(0,W.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,W.jsxs)(`div`,{className:`px-3 py-2 border-b border-border`,children:[(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground uppercase tracking-wide mb-1.5`,children:e(`catalog.sidebar.title`)}),(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground/70 mb-2`,children:e(`catalog.sidebar.createLabel`)}),(0,W.jsxs)(`div`,{className:`flex gap-1`,children:[(0,W.jsxs)(P,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>re(!0),title:e(`catalog.actions.templateTitle`),children:[(0,W.jsx)(x,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.template`)]}),H&&(0,W.jsxs)(P,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>R(!0),title:e(`catalog.actions.generateWithAi`),children:[(0,W.jsx)(w,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.generate`)]}),(0,W.jsxs)(P,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>T({kind:`create`}),title:e(`catalog.actions.blankTitle`),children:[(0,W.jsx)(ee,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.blank`)]})]})]}),(0,W.jsxs)(`div`,{className:`flex-1 overflow-auto p-2`,children:[(0,W.jsx)(ma,{title:e(`catalog.sections.upstream`,{count:Fe.length}),description:e(`catalog.sections.upstreamDescription`),children:Fe.map(e=>(0,W.jsx)(ha,{agent:e,selected:e.id===r,onSelect:()=>i(e.id)},e.id))}),(0,W.jsx)(ma,{title:e(`catalog.sections.custom`,{count:Ie.length}),description:e(`catalog.sections.customDescription`),children:Ie.length===0?(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground px-2 py-2 italic`,children:e(`catalog.sections.noCustomAgents`)}):Ie.map(e=>(0,W.jsx)(ha,{agent:e,selected:e.id===r,onSelect:()=>i(e.id)},e.id))})]})]}),(0,W.jsxs)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:[g&&(0,W.jsx)(`div`,{className:`m-4 px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:g}),G&&(0,W.jsxs)(`div`,{className:`p-6 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-1`,children:[(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,W.jsx)(`h2`,{className:`text-base font-mono font-semibold`,children:G.id}),(0,W.jsx)(ga,{kind:G.kind}),G.model&&(0,W.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:e(`catalog.detail.defaultModel`,{model:G.model})})]}),G.description&&(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 break-words`,children:G.description})]}),(0,W.jsxs)(`div`,{className:`flex gap-2 flex-shrink-0`,children:[(0,W.jsxs)(P,{size:`sm`,variant:`ghost`,onClick:()=>void Pe(G.id),children:[(0,W.jsx)(pe,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`common:actions.duplicate`)]}),G.kind===`custom`&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(P,{size:`sm`,variant:`ghost`,onClick:()=>T({kind:`edit`,agentId:G.id}),children:[(0,W.jsx)(C,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`common:actions.edit`)]}),H&&(0,W.jsxs)(P,{size:`sm`,onClick:async()=>{if(B)try{let e=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(G.id)}?provider=${encodeURIComponent(V)}`);if(!e.ok)throw Error(`Load failed: ${e.status}`);let t=await e.json();Te(),Ce.current={refineId:null},D({kind:`open`,projectId:B,agentId:G.id,baseBody:t.body})}catch(e){_(e.message)}},title:e(`catalog.detail.aiEditTitle`),children:[(0,W.jsx)(be,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`catalog.detail.aiEdit`)]})]})]})]}),(0,W.jsxs)(`div`,{className:`rounded-md border border-border bg-muted/30 mt-4 min-w-0 overflow-hidden`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border`,children:[(0,W.jsx)(`span`,{className:`text-[11px] font-mono text-muted-foreground truncate`,children:Ni(V,G.id)}),(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground flex-shrink-0 ml-2`,children:G.kind===`upstream`?e(`catalog.detail.readOnly`):e(`catalog.detail.editableHint`)})]}),(0,W.jsx)(`pre`,{className:`p-4 text-xs font-mono overflow-auto max-h-[60vh] whitespace-pre-wrap break-all`,children:m?e(`common:states.loading`):a??``})]})]})]})]})]})}function pa({label:e,count:t,active:n,onClick:r}){return(0,W.jsxs)(`button`,{type:`button`,onClick:r,className:`flex-shrink-0 inline-flex items-center gap-1 h-7 px-2.5 text-[11px] rounded-full border transition-colors whitespace-nowrap `+(n?`bg-accent-primary/20 border-accent-primary/50 text-accent-primary`:`bg-transparent border-border text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[e,(0,W.jsx)(`span`,{className:`text-[9px] px-1 rounded `+(n?`bg-accent-primary/30`:`bg-muted/60`),children:t})]})}function ma({title:e,description:t,children:n}){return(0,W.jsxs)(`div`,{className:`mb-4`,children:[(0,W.jsxs)(`div`,{className:`px-2 pb-1`,children:[(0,W.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wide`,children:e}),t&&(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-0.5`,children:t})]}),(0,W.jsx)(`div`,{className:`space-y-0.5`,children:n})]})}function ha({agent:e,selected:t,onSelect:n}){return(0,W.jsxs)(`button`,{type:`button`,onClick:n,className:`w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left rounded transition-colors `+(t?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[(0,W.jsx)(`span`,{className:`text-sm font-mono truncate`,children:e.id}),(0,W.jsx)(ga,{kind:e.kind})]})}function ga({kind:e}){let{t}=s(`agents`);return(0,W.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 `+(e===`custom`?`bg-purple-500/15 aurora-light:bg-accent-secondary/15 text-purple-400 aurora-light:text-accent-secondary`:`bg-muted text-muted-foreground`),children:t(e===`custom`?`catalog.kind.custom`:`catalog.kind.upstream`)})}var _a=[{days:7},{days:30},{days:90}];function va(){let{t:e}=s(`agents`),[t,n]=(0,U.useState)(null),[r,i]=(0,U.useState)(30),[a,o]=(0,U.useState)(!0);if((0,U.useEffect)(()=>{let e=!1;return o(!0),fetch(`${l()}/profiles/analytics?windowDays=${r}`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&n(t)}).catch(()=>{}).finally(()=>{e||o(!1)}),()=>{e=!0}},[r]),a&&!t)return null;if(!t||t.rows.length===0)return(0,W.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:e(`usage.title`)}),(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:e(`usage.subtitleEmpty`)})]}),(0,W.jsx)(`div`,{className:`flex gap-0.5`,children:_a.map(t=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>i(t.days),className:`text-[10px] px-2 py-1 rounded transition-colors `+(r===t.days?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:e(`usage.windowLabel`,{days:t.days})},t.days))})]}),(0,W.jsx)(`div`,{className:`px-4 py-8 text-xs text-muted-foreground`,children:e(`usage.empty`)})]});let c=Math.max(...t.rows.map(e=>e.jobs),1);return(0,W.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:e(`usage.title`)}),(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:e(`usage.subtitle`,{count:t.windowDays})})]}),(0,W.jsx)(`div`,{className:`flex gap-0.5`,children:_a.map(t=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>i(t.days),className:`text-[10px] px-2 py-1 rounded transition-colors `+(r===t.days?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:e(`usage.windowLabel`,{days:t.days})},t.days))})]}),(0,W.jsx)(`div`,{className:`p-4 space-y-2`,children:t.rows.map(t=>(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`w-32 text-xs font-mono truncate`,children:t.profileName}),(0,W.jsx)(`div`,{className:`flex-1 h-4 bg-muted/50 rounded overflow-hidden`,children:(0,W.jsx)(`div`,{className:`h-full bg-accent-primary/70`,style:{width:`${Math.max(6,Math.round(t.jobs/c*100))}%`}})}),(0,W.jsxs)(`div`,{className:`flex gap-4 text-[11px] text-muted-foreground min-w-0 flex-shrink-0`,children:[(0,W.jsxs)(`span`,{title:e(`usage.jobsTooltip`),children:[(0,W.jsx)(`span`,{className:`text-foreground font-mono`,children:t.jobs}),` `,e(`usage.jobsLabel`,{count:t.jobs})]}),(0,W.jsxs)(`span`,{title:e(`usage.successRateTooltip`),children:[(0,W.jsxs)(`span`,{className:`text-foreground font-mono`,children:[Math.round(t.successRate*100),`%`]}),` `,e(`usage.okSuffix`)]}),t.avgDurationMs!=null&&(0,W.jsx)(`span`,{title:e(`usage.avgDurationTooltip`),children:(0,W.jsx)(`span`,{className:`text-foreground font-mono`,children:ya(t.avgDurationMs)})}),t.avgTokens!=null&&(0,W.jsxs)(`span`,{title:e(`usage.avgTokensTooltip`),children:[(0,W.jsx)(`span`,{className:`text-foreground font-mono`,children:ba(t.avgTokens)}),` `,e(`usage.tokensSuffix`)]})]})]},t.profileName))})]})}function ya(e){let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m`:`${Math.floor(n/60)}h${n%60}m`}function ba(e){return e<1e3?Math.round(e).toString():e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}var xa=`specrails-desktop:agents-tab`;function Sa(){try{let e=localStorage.getItem(xa);if(e===`profiles`||e===`usage`||e===`catalog`)return e}catch{}return`profiles`}function Ca(){let{t:e}=s(`agents`),[t,n]=(0,U.useState)(()=>Sa()),r=e=>{n(e);try{localStorage.setItem(xa,e)}catch{}},[i,a]=(0,U.useState)(null),{activeProjectId:c}=u(),{pendingRestores:d}=v(),f=(0,U.useRef)(!1);return(0,U.useEffect)(()=>{if(!c)return;let e=d.some(e=>e.kind===`ai-edit`&&e.projectId===c);e&&!f.current&&t!==`catalog`&&r(`catalog`),f.current=e},[d,c,t]),(0,U.useEffect)(()=>{let e=!1;return fetch(`${l()}/profiles/core-version`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&a(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,W.jsxs)(`div`,{className:`flex flex-col h-full`,children:[i!==null&&!i.profileAware&&(0,W.jsxs)(`div`,{className:`flex-shrink-0 flex items-start gap-3 px-6 py-3 border-b border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10`,children:[(0,W.jsx)(E,{className:`w-4 h-4 text-yellow-500 aurora-light:text-accent-warning mt-0.5 flex-shrink-0`}),(0,W.jsxs)(`div`,{className:`text-xs`,children:[(0,W.jsx)(`div`,{className:`font-medium text-yellow-500 aurora-light:text-accent-warning`,children:e(`page.banner.title`,{required:i.required})}),(0,W.jsx)(`div`,{className:`text-yellow-500/80 aurora-light:text-accent-warning mt-0.5`,children:(0,W.jsx)(o,{t:e,i18nKey:`page.banner.body`,values:{version:i.version??e(`page.banner.unknownVersion`),command:`npx specrails-core@latest update`},components:{code:(0,W.jsx)(`code`,{className:`px-1 rounded bg-yellow-500/20 aurora-light:bg-accent-warning/20`})}})})]})]}),(0,W.jsxs)(`div`,{className:`flex-shrink-0 border-b border-border`,children:[(0,W.jsxs)(`div`,{className:`px-6 pt-4`,children:[(0,W.jsx)(`h1`,{className:`text-lg font-semibold`,children:e(`page.title`)}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e(`page.subtitle`)})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1 px-4 pt-3`,children:[(0,W.jsx)(Ta,{active:t===`profiles`,onClick:()=>r(`profiles`),children:e(`page.tabs.profiles`)}),(0,W.jsx)(Ta,{active:t===`usage`,onClick:()=>r(`usage`),children:e(`page.tabs.usage`)}),(0,W.jsx)(Ta,{active:t===`catalog`,onClick:()=>r(`catalog`),children:e(`page.tabs.catalog`)})]})]}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0 overflow-auto`,children:[t===`profiles`&&(0,W.jsx)(He,{}),t===`usage`&&(0,W.jsx)(wa,{}),t===`catalog`&&(0,W.jsx)(fa,{})]})]})}function wa(){return(0,W.jsx)(`div`,{className:`min-h-full`,children:(0,W.jsx)(va,{})})}function Ta({active:e,children:t,onClick:n}){return(0,W.jsx)(`button`,{type:`button`,onClick:n,className:`h-8 px-3 text-xs font-medium rounded-t-md border-b-2 transition-colors `+(e?`text-foreground border-foreground`:`text-muted-foreground border-transparent hover:text-foreground hover:border-border`),children:t})}export{Ca as default};
118
+ `});return i}function oa({value:e,onChange:t,onSubmit:n,disabled:r,placeholder:i,autoFocus:a,inputRef:o}){let{t:c}=s(`aiedit`);return(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(`div`,{className:`relative rounded-xl border border-border bg-card/40 focus-within:border-accent-primary/40 focus-within:ring-2 focus-within:ring-accent-primary/20 transition-all`,children:[(0,W.jsx)(`textarea`,{ref:o,value:e,onChange:e=>t(e.target.value),placeholder:i,rows:3,disabled:r,autoFocus:a,className:`w-full text-sm p-3 pr-14 bg-transparent resize-none focus:outline-none disabled:opacity-50 placeholder:text-muted-foreground/60`,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),n())}}),(0,W.jsx)(`button`,{type:`button`,onClick:n,disabled:!e.trim()||r,"aria-label":c(`shell.composer.sendAriaLabel`),className:`absolute bottom-2.5 right-2.5 p-2 rounded-md bg-accent-primary text-white hover:bg-accent-primary/90 disabled:opacity-30 disabled:cursor-not-allowed focus-visible:ring-2 focus-visible:ring-primary/40 focus-visible:outline-none transition-opacity`,children:r?(0,W.jsx)(ee,{className:`w-3.5 h-3.5 animate-spin`}):(0,W.jsx)(sa,{})})]}),(0,W.jsx)(`div`,{className:`flex items-center justify-end text-[11px] text-muted-foreground/70`,children:(0,W.jsxs)(`span`,{children:[(0,W.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted/60 text-[10px] font-mono`,children:H(`⌘⏎`)}),` `,c(`shell.composer.kbdSubmit`),(0,W.jsx)(`span`,{className:`mx-1.5`,children:`·`}),(0,W.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted/60 text-[10px] font-mono`,children:`Esc`}),` `,c(`shell.composer.kbdCancel`)]})})]})}function sa(){return(0,W.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`w-3.5 h-3.5`,children:[(0,W.jsx)(`path`,{d:`M22 2 11 13`}),(0,W.jsx)(`path`,{d:`M22 2 15 22l-4-9-9-4Z`})]})}var ca=[`refine.chips.tightenTools`,`refine.chips.stricterPersonality`,`refine.chips.workflowSection`,`refine.chips.sharpenDescription`,`refine.chips.matchDeveloperStyle`];function la({agentId:e,baseBody:t,resumeRefineId:n,onClose:r,onMinimize:i,onStateChange:a,onOpenInStudio:o,onApplied:c}){let{t:l}=s(`agentstudio`),{activeProjectId:d}=u(),f=zi(d),[p,m]=(0,U.useState)(``),h=(0,U.useRef)(null),g=(0,U.useRef)(!1);(0,U.useEffect)(()=>{g.current||(g.current=!0,n?f.rehydrate(n,e):f.open(e,t))},[e,t,n,f]),(0,U.useEffect)(()=>{let e=setTimeout(()=>h.current?.focus(),50);return()=>clearTimeout(e)},[]);let _=(0,U.useRef)(a);_.current=a,(0,U.useEffect)(()=>{_.current?.({refineId:f.state.refineId??null})},[f.state.refineId]);let v=(0,U.useRef)(null);(0,U.useEffect)(()=>{f.state.uiState===`applied`&&f.state.appliedVersion!==null&&f.state.appliedVersion!==v.current&&(v.current=f.state.appliedVersion,c&&f.state.agentId&&c(f.state.agentId,f.state.appliedVersion))},[f.state.uiState,f.state.appliedVersion,f.state.agentId,c]);let y=(0,U.useCallback)(async e=>{let t=e.trim();t&&(m(``),f.state.refineId?await f.sendTurn(t):await f.start(t))},[f]),b=(0,U.useCallback)(()=>{y(p)},[p,y]),x=(0,U.useCallback)(async()=>{f.state.refineId&&(f.state.uiState===`streaming`||f.state.uiState===`reviewing`)&&await f.cancel(),r()},[f,r]),S=ua(f.state),ee=(0,U.useMemo)(()=>!f.state.draftBody||!f.state.baseBody?null:(0,W.jsx)(na,{hunks:ia(f.state.baseBody,f.state.draftBody)}),[f.state.baseBody,f.state.draftBody]);return(0,W.jsx)(Hi,{uiPhase:S,errorMessage:f.state.errorMessage,applyConflict:f.state.applyConflict,eyebrow:l(`refine.eyebrow`),targetLabel:e,targetLabelMono:!0,headline:l(`refine.headline`),streamingHeadline:l(`refine.streamingHeadline`),description:da(t),chips:ca.map(e=>l(e)),onChipSubmit:e=>void y(e),composer:(0,W.jsx)(oa,{value:p,onChange:m,onSubmit:b,disabled:S===`streaming`||S===`applied`,placeholder:f.state.refineId?l(`refine.placeholderFollowUp`):l(`refine.placeholderInitial`),inputRef:h}),streamingText:f.state.streamingText,history:f.state.history,diff:ee,diffHeaderLabel:`.claude/agents/${e}.md`,baseBody:t,baseBodyDisclosureLabel:l(`refine.viewCurrentBody`),appliedNotice:f.state.appliedVersion===null?void 0:(0,W.jsx)(`div`,{className:`rounded-md border border-green-500/40 aurora-light:border-accent-success/40 bg-green-500/10 aurora-light:bg-accent-success/10 p-3 text-xs text-green-300 aurora-light:text-accent-success`,children:l(`refine.appliedAsVersion`,{version:f.state.appliedVersion})}),canApply:f.state.uiState===`reviewing`&&!!f.state.draftBody&&!f.state.applyConflict,onApply:()=>void f.apply(),onForceApply:()=>void f.apply(!0),onDiscard:()=>void x(),onClose:()=>void x(),onMinimize:i?()=>i(f.state.refineId??null):void 0,secondaryAction:o&&f.state.draftBody&&f.state.refineId?{label:l(`refine.openInStudio`),icon:(0,W.jsx)(C,{className:`w-3 h-3`}),onClick:()=>{f.state.refineId&&f.state.draftBody&&o&&o(f.state.refineId,f.state.draftBody)}}:void 0})}function ua(e){switch(e.uiState){case`streaming`:return`streaming`;case`reviewing`:return`reviewing`;case`applied`:return`applied`;case`error`:return`error`;default:return`composing`}}function da(e){let t=e.match(/^---\r?\n([\s\S]*?)\r?\n---/);if(!t)return null;let n=t[1].match(/^description:\s*([\s\S]*?)(?=^[a-z_]+:\s|\Z)/m);if(!n)return null;let r=n[1].trim();return(r.startsWith(`"`)&&r.endsWith(`"`)||r.startsWith(`'`)&&r.endsWith(`'`))&&(r=r.slice(1,-1)),r=r.replace(/\\n/g,` `).replace(/\\t/g,` `).replace(/\\"/g,`"`).replace(/\\'/g,`'`).replace(/\\\\/g,`\\`).replace(/\s+/g,` `).trim(),r.length>240&&(r=r.slice(0,237)+`…`),r||null}function fa(){let{t:e}=s(`agents`),[t,n]=(0,U.useState)([]),[r,i]=(0,U.useState)(null),[a,c]=(0,U.useState)(null),[d,p]=(0,U.useState)(!0),[m,h]=(0,U.useState)(!1),[g,_]=(0,U.useState)(null),[b,x]=(0,U.useState)({kind:`closed`}),[C,T]=(0,U.useState)({kind:`closed`}),[E,O]=(0,U.useState)(!1),[k,j]=(0,U.useState)(``),[ie,L]=(0,U.useState)(`all`),[R,oe]=(0,U.useState)(null),[ce,z]=(0,U.useState)(!1),[le,ue]=(0,U.useState)(``),[de,fe]=(0,U.useState)(``),[pe,me]=(0,U.useState)(!1),[he,ge]=(0,U.useState)(null),{activeProjectId:B,projects:ve}=u(),V=ve.find(e=>e.id===B)?.provider??`claude`,H=f(V),{minimize:xe}=v(),Ce=(0,U.useRef)({refineId:null}),we=(0,U.useRef)(C);we.current=C;let Te=(0,U.useCallback)(()=>{let t=we.current;t.kind!==`open`||!t.projectId||xe({kind:`ai-edit`,projectId:t.projectId,label:e(`catalog.aiEditChipLabel`,{agentId:t.agentId}),restoreRoute:`/agents`,params:{agentId:t.agentId,baseBody:t.baseBody,resumeRefineId:Ce.current.refineId??t.resumeRefineId}})},[xe,e]);y(`ai-edit`,B,e=>{e.kind!==`ai-edit`||!H||(Te(),Ce.current={refineId:e.params.resumeRefineId??null},T({kind:`open`,projectId:e.projectId,agentId:e.params.agentId,baseBody:e.params.baseBody,resumeRefineId:e.params.resumeRefineId}))});let Ee=(0,U.useCallback)(()=>{let t=!1;return p(!0),fetch(`${l()}/profiles/catalog?provider=${encodeURIComponent(V)}`).then(t=>{if(!t.ok)throw Error(e(`catalog.errors.loadFailed`,{status:t.status}));return t.json()}).then(e=>{t||(n(e.agents),e.agents.length>0&&!r&&i(e.agents[0].id))}).catch(e=>{t||_(e.message)}).finally(()=>{t||p(!1)}),()=>{t=!0}},[V,r,e]);(0,U.useEffect)(()=>Ee(),[Ee]);let De=(0,U.useCallback)(t=>{let n=!1;return h(!0),c(null),fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}?provider=${encodeURIComponent(V)}`).then(t=>{if(!t.ok)throw Error(e(`catalog.errors.bodyLoadFailed`,{status:t.status}));return t.json()}).then(e=>{n||c(e.body)}).catch(e=>{n||_(e.message)}).finally(()=>{n||h(!1)}),()=>{n=!0}},[V,e]);if((0,U.useEffect)(()=>{if(r)return De(r)},[r,De]),d)return(0,W.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`catalog.loading`)})});if(b.kind!==`closed`)return(0,W.jsx)(Pi,{agentId:b.kind===`edit`?b.agentId:void 0,initialBody:b.kind===`duplicate`||b.kind===`create`?b.initialBody:void 0,initialName:b.kind===`create`?b.initialName:void 0,draftFromRefine:b.kind===`edit`?b.draftFromRefine:void 0,provider:V,defaultModel:be(V),automationEnabled:H,onClose:()=>x({kind:`closed`}),onSaved:e=>{i(e),x({kind:`closed`}),Ee()},onResumeRefine:(e,t,n)=>{x({kind:`closed`}),B&&(Te(),Ce.current={refineId:e},T({kind:`open`,projectId:B,agentId:t,baseBody:n,resumeRefineId:e}))}});if(C.kind===`open`&&H)return(0,W.jsx)(ae,{onClose:()=>T({kind:`closed`}),children:(0,W.jsx)(la,{agentId:C.agentId,baseBody:C.baseBody,resumeRefineId:C.resumeRefineId,onStateChange:e=>{Ce.current=e},onClose:()=>T({kind:`closed`}),onMinimize:t=>{let n=C.kind===`open`?C.projectId:B;if(!n){T({kind:`closed`});return}let r=C.kind===`open`?C.agentId:``,i=C.kind===`open`?C.baseBody:``;xe({kind:`ai-edit`,projectId:n,label:e(`catalog.aiEditChipLabel`,{agentId:r}),restoreRoute:`/agents`,params:{agentId:r,baseBody:i,resumeRefineId:t??void 0}}),T({kind:`closed`})},onApplied:e=>{T({kind:`closed`}),i(e),Ee()},onOpenInStudio:(e,t)=>{T({kind:`closed`}),x({kind:`edit`,agentId:C.agentId,draftFromRefine:e})}},`${C.agentId}:${C.resumeRefineId??`fresh`}`)});let Oe=(()=>{let e=k.trim().toLowerCase();return Oi.filter(t=>!(ie!==`all`&&t.category!==ie||R&&!t.tags.includes(R)||e&&!(t.label+` `+t.blurb+` `+t.tags.join(` `)+` `+t.category).toLowerCase().includes(e)))})(),ke=(()=>{let e=new Map;for(let t of Oi)e.set(t.category,(e.get(t.category)??0)+1);return e})(),Ae=()=>{O(!1),j(``),L(`all`),oe(null)},je=()=>(0,W.jsx)(F,{open:E,onOpenChange:e=>{e||Ae()},children:(0,W.jsxs)(P,{className:`max-w-4xl p-0 h-[85vh] flex flex-col overflow-hidden`,children:[(0,W.jsxs)(`div`,{className:`flex-shrink-0 px-6 pt-5 pb-3 border-b border-border`,children:[(0,W.jsxs)(N,{children:[(0,W.jsxs)(M,{className:`flex items-center gap-2 text-base`,children:[(0,W.jsx)(S,{className:`w-4 h-4 text-accent-primary`}),` `,e(`catalog.templates.title`),(0,W.jsx)(`span`,{className:`text-[11px] font-normal text-muted-foreground ml-1`,children:e(`catalog.templates.countOf`,{shown:Oe.length,total:Oi.length})})]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e(`catalog.templates.description`)})]}),(0,W.jsxs)(`div`,{className:`mt-3 relative`,children:[(0,W.jsx)(re,{className:`w-3.5 h-3.5 absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none`}),(0,W.jsx)(`input`,{value:k,onChange:e=>j(e.target.value),placeholder:e(`catalog.templates.searchPlaceholder`),className:`w-full h-9 pl-8 pr-8 text-sm rounded-md border border-border bg-background focus:outline-none focus:ring-1 focus:ring-primary/40`,autoFocus:!0}),k&&(0,W.jsx)(`button`,{type:`button`,onClick:()=>j(``),className:`absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded hover:bg-accent text-muted-foreground`,children:(0,W.jsx)(D,{className:`w-3.5 h-3.5`})})]}),(0,W.jsxs)(`div`,{className:`flex gap-1.5 overflow-x-auto mt-3 pb-1 scrollbar-thin`,children:[(0,W.jsx)(pa,{label:e(`catalog.templates.allCategories`),count:Oi.length,active:ie===`all`,onClick:()=>L(`all`)}),ki.map(e=>(0,W.jsx)(pa,{label:e,count:ke.get(e)??0,active:ie===e,onClick:()=>L(e)},e))]}),R&&(0,W.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,W.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e(`catalog.templates.tagFilter`)}),(0,W.jsxs)(`button`,{type:`button`,onClick:()=>oe(null),className:`inline-flex items-center gap-1 text-[11px] px-2 py-0.5 rounded-full bg-accent-primary/20 text-accent-primary hover:bg-accent-primary/30`,children:[(0,W.jsx)(ye,{className:`w-3 h-3`}),` `,R,(0,W.jsx)(D,{className:`w-3 h-3`})]})]})]}),(0,W.jsx)(`div`,{className:`flex-1 overflow-y-auto px-6 py-4`,children:Oe.length===0?(0,W.jsx)(`div`,{className:`h-full flex items-center justify-center text-center`,children:(0,W.jsxs)(`div`,{className:`max-w-sm`,children:[(0,W.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e(`catalog.templates.noMatch`)}),(0,W.jsx)(`button`,{type:`button`,onClick:()=>{j(``),L(`all`),oe(null)},className:`text-xs text-accent-primary hover:underline mt-2`,children:e(`catalog.templates.clearFilters`)})]})}):(0,W.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-3`,children:Oe.map(t=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>{Ae(),x({kind:`create`,initialBody:t.body,initialName:t.nameHint})},className:`group text-left p-4 rounded-lg border border-border bg-card/40 hover:border-accent-primary/50 hover:bg-accent/40 hover:shadow-sm transition-all`,children:[(0,W.jsxs)(`div`,{className:`flex items-start gap-3 mb-2`,children:[(0,W.jsx)(`span`,{className:`text-2xl leading-none mt-0.5`,children:t.emoji}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsx)(`div`,{className:`text-sm font-semibold text-foreground group-hover:text-accent-primary truncate`,children:t.label}),(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:t.category})]})]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2 min-h-[2lh]`,children:t.blurb}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:t.tags.slice(0,5).map(e=>(0,W.jsx)(`span`,{role:`button`,tabIndex:0,onClick:t=>{t.stopPropagation(),oe(e)},onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),t.stopPropagation(),oe(e))},className:`text-[10px] px-1.5 py-0.5 rounded bg-muted/50 text-muted-foreground hover:bg-accent-primary/20 hover:text-accent-primary cursor-pointer transition-colors `+(R===e?`bg-accent-primary/20 text-accent-primary`:``),children:e},e))}),(0,W.jsxs)(`div`,{className:`mt-3 pt-2 border-t border-border/40 flex items-center justify-between`,children:[(0,W.jsx)(`code`,{className:`text-[10px] font-mono text-muted-foreground/70 truncate`,children:t.nameHint}),(0,W.jsx)(`span`,{className:`text-[10px] text-accent-primary opacity-0 group-hover:opacity-100 transition-opacity`,children:e(`catalog.templates.openInStudio`)})]})]},t.id))})}),(0,W.jsxs)(`div`,{className:`flex-shrink-0 px-6 py-3 border-t border-border flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:e(`catalog.templates.tip`)}),(0,W.jsx)(I,{variant:`ghost`,size:`sm`,onClick:Ae,children:e(`common:actions.cancel`)})]})]})}),Me=()=>H?(0,W.jsx)(F,{open:ce,onOpenChange:e=>{!e&&!pe&&(z(!1),ge(null))},children:(0,W.jsxs)(P,{className:`max-w-lg`,children:[(0,W.jsx)(N,{children:(0,W.jsxs)(M,{className:`flex items-center gap-2`,children:[(0,W.jsx)(w,{className:`w-4 h-4 text-accent-primary`}),` `,e(`catalog.generate.title`)]})}),(0,W.jsxs)(`div`,{className:`space-y-3 py-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:e(`catalog.generate.agentIdLabel`)}),(0,W.jsx)(_e,{value:le,onChange:e=>ue(e.target.value),placeholder:`custom-my-agent`,className:`text-sm font-mono`,disabled:pe}),(0,W.jsx)(`p`,{className:`text-[11px] text-muted-foreground mt-1`,children:(0,W.jsx)(o,{t:e,i18nKey:`catalog.generate.agentIdHint`,components:{code:(0,W.jsx)(`code`,{})}})})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:e(`catalog.generate.descriptionLabel`)}),(0,W.jsx)(`textarea`,{value:de,onChange:e=>fe(e.target.value),placeholder:e(`catalog.generate.descriptionPlaceholder`),className:`w-full text-sm p-2 rounded border border-border bg-background min-h-[120px] resize-y`,disabled:pe})]}),he&&(0,W.jsx)(`div`,{className:`px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:he}),(0,W.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:(0,W.jsx)(o,{t:e,i18nKey:`catalog.generate.note`,components:{code:(0,W.jsx)(`code`,{})}})})]}),(0,W.jsxs)(A,{children:[(0,W.jsx)(I,{variant:`ghost`,size:`sm`,onClick:()=>z(!1),disabled:pe,children:e(`common:actions.cancel`)}),(0,W.jsx)(I,{size:`sm`,onClick:Ne,disabled:pe||!le.trim()||!de.trim(),children:pe?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(ee,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`}),` `,e(`catalog.generate.generating`)]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(w,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.generate.generateButton`)]})})]})]})}):null,Ne=async()=>{if(H){me(!0),ge(null);try{let t=await fetch(`${l()}/profiles/catalog/generate?provider=${encodeURIComponent(V)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:le.trim(),description:de.trim()})});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`catalog.errors.generateFailed`,{status:t.status}))}let n=await t.json();z(!1),x({kind:`create`,initialBody:n.draft,initialName:le.trim()})}catch(e){ge(e.message)}finally{me(!1)}}},Pe=async t=>{try{let n=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(t)}?provider=${encodeURIComponent(V)}`);if(!n.ok)throw Error(e(`catalog.errors.agentLoadFailed`,{status:n.status}));let r=await n.json();x({kind:`duplicate`,from:t,initialBody:r.body})}catch(e){_(e.message)}};if(t.length===0)return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,W.jsxs)(`div`,{className:`text-center max-w-sm`,children:[(0,W.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:e(`catalog.empty.title`)}),(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 mb-4`,children:(0,W.jsx)(o,{t:e,i18nKey:`catalog.empty.body`,values:{command:`npx specrails-core@latest update`},components:{code:(0,W.jsx)(`code`,{className:`text-foreground`})}})}),(0,W.jsxs)(`div`,{className:`flex gap-2 justify-center flex-wrap`,children:[H&&(0,W.jsxs)(I,{size:`sm`,onClick:()=>z(!0),children:[(0,W.jsx)(w,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.generateWithAi`)]}),(0,W.jsxs)(I,{size:`sm`,variant:`ghost`,onClick:()=>O(!0),children:[(0,W.jsx)(S,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.template`)]}),(0,W.jsxs)(I,{size:`sm`,variant:`ghost`,onClick:()=>x({kind:`create`}),children:[(0,W.jsx)(ne,{className:`w-3.5 h-3.5 mr-1.5`}),` `,e(`catalog.actions.blank`)]})]})]})}),je(),Me()]});let Fe=t.filter(e=>e.kind===`upstream`),Ie=t.filter(e=>e.kind===`custom`),G=t.find(e=>e.id===r);return(0,W.jsxs)(W.Fragment,{children:[je(),Me(),(0,W.jsxs)(`div`,{className:`flex h-full`,children:[(0,W.jsxs)(`aside`,{className:`w-72 flex-shrink-0 border-r border-border flex flex-col`,children:[(0,W.jsxs)(`div`,{className:`px-3 py-2 border-b border-border`,children:[(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground uppercase tracking-wide mb-1.5`,children:e(`catalog.sidebar.title`)}),(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground/70 mb-2`,children:e(`catalog.sidebar.createLabel`)}),(0,W.jsxs)(`div`,{className:`flex gap-1`,children:[(0,W.jsxs)(I,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>O(!0),title:e(`catalog.actions.templateTitle`),children:[(0,W.jsx)(S,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.template`)]}),H&&(0,W.jsxs)(I,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>z(!0),title:e(`catalog.actions.generateWithAi`),children:[(0,W.jsx)(w,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.generate`)]}),(0,W.jsxs)(I,{size:`sm`,variant:`ghost`,className:`flex-1 h-7 text-[11px] px-2`,onClick:()=>x({kind:`create`}),title:e(`catalog.actions.blankTitle`),children:[(0,W.jsx)(ne,{className:`w-3 h-3 mr-1`}),` `,e(`catalog.actions.blank`)]})]})]}),(0,W.jsxs)(`div`,{className:`flex-1 overflow-auto p-2`,children:[(0,W.jsx)(ma,{title:e(`catalog.sections.upstream`,{count:Fe.length}),description:e(`catalog.sections.upstreamDescription`),children:Fe.map(e=>(0,W.jsx)(ha,{agent:e,selected:e.id===r,onSelect:()=>i(e.id)},e.id))}),(0,W.jsx)(ma,{title:e(`catalog.sections.custom`,{count:Ie.length}),description:e(`catalog.sections.customDescription`),children:Ie.length===0?(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground px-2 py-2 italic`,children:e(`catalog.sections.noCustomAgents`)}):Ie.map(e=>(0,W.jsx)(ha,{agent:e,selected:e.id===r,onSelect:()=>i(e.id)},e.id))})]})]}),(0,W.jsxs)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:[g&&(0,W.jsx)(`div`,{className:`m-4 px-3 py-2 text-xs rounded border border-red-500/30 aurora-light:border-destructive/30 bg-red-500/10 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive`,children:g}),G&&(0,W.jsxs)(`div`,{className:`p-6 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-4 mb-1`,children:[(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,W.jsx)(`h2`,{className:`text-base font-mono font-semibold`,children:G.id}),(0,W.jsx)(ga,{kind:G.kind}),G.model&&(0,W.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:e(`catalog.detail.defaultModel`,{model:G.model})})]}),G.description&&(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 break-words`,children:G.description})]}),(0,W.jsxs)(`div`,{className:`flex gap-2 flex-shrink-0`,children:[(0,W.jsxs)(I,{size:`sm`,variant:`ghost`,onClick:()=>void Pe(G.id),children:[(0,W.jsx)(se,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`common:actions.duplicate`)]}),G.kind===`custom`&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(I,{size:`sm`,variant:`ghost`,onClick:()=>x({kind:`edit`,agentId:G.id}),children:[(0,W.jsx)(te,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`common:actions.edit`)]}),H&&(0,W.jsxs)(I,{size:`sm`,onClick:async()=>{if(B)try{let e=await fetch(`${l()}/profiles/catalog/${encodeURIComponent(G.id)}?provider=${encodeURIComponent(V)}`);if(!e.ok)throw Error(`Load failed: ${e.status}`);let t=await e.json();Te(),Ce.current={refineId:null},T({kind:`open`,projectId:B,agentId:G.id,baseBody:t.body})}catch(e){_(e.message)}},title:e(`catalog.detail.aiEditTitle`),children:[(0,W.jsx)(Se,{className:`w-3.5 h-3.5 mr-1`}),` `,e(`catalog.detail.aiEdit`)]})]})]})]}),(0,W.jsxs)(`div`,{className:`rounded-md border border-border bg-muted/30 mt-4 min-w-0 overflow-hidden`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-border`,children:[(0,W.jsx)(`span`,{className:`text-[11px] font-mono text-muted-foreground truncate`,children:Ni(V,G.id)}),(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground flex-shrink-0 ml-2`,children:G.kind===`upstream`?e(`catalog.detail.readOnly`):e(`catalog.detail.editableHint`)})]}),(0,W.jsx)(`pre`,{className:`p-4 text-xs font-mono overflow-auto max-h-[60vh] whitespace-pre-wrap break-all`,children:m?e(`common:states.loading`):a??``})]})]})]})]})]})}function pa({label:e,count:t,active:n,onClick:r}){return(0,W.jsxs)(`button`,{type:`button`,onClick:r,className:`flex-shrink-0 inline-flex items-center gap-1 h-7 px-2.5 text-[11px] rounded-full border transition-colors whitespace-nowrap `+(n?`bg-accent-primary/20 border-accent-primary/50 text-accent-primary`:`bg-transparent border-border text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[e,(0,W.jsx)(`span`,{className:`text-[9px] px-1 rounded `+(n?`bg-accent-primary/30`:`bg-muted/60`),children:t})]})}function ma({title:e,description:t,children:n}){return(0,W.jsxs)(`div`,{className:`mb-4`,children:[(0,W.jsxs)(`div`,{className:`px-2 pb-1`,children:[(0,W.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wide`,children:e}),t&&(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70 mt-0.5`,children:t})]}),(0,W.jsx)(`div`,{className:`space-y-0.5`,children:n})]})}function ha({agent:e,selected:t,onSelect:n}){return(0,W.jsxs)(`button`,{type:`button`,onClick:n,className:`w-full flex items-center justify-between gap-2 px-2 py-1.5 text-left rounded transition-colors `+(t?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:[(0,W.jsx)(`span`,{className:`text-sm font-mono truncate`,children:e.id}),(0,W.jsx)(ga,{kind:e.kind})]})}function ga({kind:e}){let{t}=s(`agents`);return(0,W.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded flex-shrink-0 `+(e===`custom`?`bg-purple-500/15 aurora-light:bg-accent-secondary/15 text-purple-400 aurora-light:text-accent-secondary`:`bg-muted text-muted-foreground`),children:t(e===`custom`?`catalog.kind.custom`:`catalog.kind.upstream`)})}var _a=[{days:7},{days:30},{days:90}];function va(){let{t:e}=s(`agents`),[t,n]=(0,U.useState)(null),[r,i]=(0,U.useState)(30),[a,o]=(0,U.useState)(!0);if((0,U.useEffect)(()=>{let e=!1;return o(!0),fetch(`${l()}/profiles/analytics?windowDays=${r}`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&n(t)}).catch(()=>{}).finally(()=>{e||o(!1)}),()=>{e=!0}},[r]),a&&!t)return null;if(!t||t.rows.length===0)return(0,W.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:e(`usage.title`)}),(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:e(`usage.subtitleEmpty`)})]}),(0,W.jsx)(`div`,{className:`flex gap-0.5`,children:_a.map(t=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>i(t.days),className:`text-[10px] px-2 py-1 rounded transition-colors `+(r===t.days?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:e(`usage.windowLabel`,{days:t.days})},t.days))})]}),(0,W.jsx)(`div`,{className:`px-4 py-8 text-xs text-muted-foreground`,children:e(`usage.empty`)})]});let c=Math.max(...t.rows.map(e=>e.jobs),1);return(0,W.jsxs)(`div`,{className:`mx-6 my-4 rounded-md border border-border bg-muted/20`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-border`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-xs font-medium text-foreground`,children:e(`usage.title`)}),(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:e(`usage.subtitle`,{count:t.windowDays})})]}),(0,W.jsx)(`div`,{className:`flex gap-0.5`,children:_a.map(t=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>i(t.days),className:`text-[10px] px-2 py-1 rounded transition-colors `+(r===t.days?`bg-accent text-foreground`:`text-muted-foreground hover:bg-accent/50 hover:text-foreground`),children:e(`usage.windowLabel`,{days:t.days})},t.days))})]}),(0,W.jsx)(`div`,{className:`p-4 space-y-2`,children:t.rows.map(t=>(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`div`,{className:`w-32 text-xs font-mono truncate`,children:t.profileName}),(0,W.jsx)(`div`,{className:`flex-1 h-4 bg-muted/50 rounded overflow-hidden`,children:(0,W.jsx)(`div`,{className:`h-full bg-accent-primary/70`,style:{width:`${Math.max(6,Math.round(t.jobs/c*100))}%`}})}),(0,W.jsxs)(`div`,{className:`flex gap-4 text-[11px] text-muted-foreground min-w-0 flex-shrink-0`,children:[(0,W.jsxs)(`span`,{title:e(`usage.jobsTooltip`),children:[(0,W.jsx)(`span`,{className:`text-foreground font-mono`,children:t.jobs}),` `,e(`usage.jobsLabel`,{count:t.jobs})]}),(0,W.jsxs)(`span`,{title:e(`usage.successRateTooltip`),children:[(0,W.jsxs)(`span`,{className:`text-foreground font-mono`,children:[Math.round(t.successRate*100),`%`]}),` `,e(`usage.okSuffix`)]}),t.avgDurationMs!=null&&(0,W.jsx)(`span`,{title:e(`usage.avgDurationTooltip`),children:(0,W.jsx)(`span`,{className:`text-foreground font-mono`,children:ya(t.avgDurationMs)})}),t.avgTokens!=null&&(0,W.jsxs)(`span`,{title:e(`usage.avgTokensTooltip`),children:[(0,W.jsx)(`span`,{className:`text-foreground font-mono`,children:ba(t.avgTokens)}),` `,e(`usage.tokensSuffix`)]})]})]},t.profileName))})]})}function ya(e){let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m`:`${Math.floor(n/60)}h${n%60}m`}function ba(e){return e<1e3?Math.round(e).toString():e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}var xa=`specrails-desktop:agents-tab`;function Sa(){try{let e=localStorage.getItem(xa);if(e===`profiles`||e===`usage`||e===`catalog`)return e}catch{}return`profiles`}function Ca(){let{t:e}=s(`agents`),[t,n]=(0,U.useState)(()=>Sa()),r=e=>{n(e);try{localStorage.setItem(xa,e)}catch{}},[i,a]=(0,U.useState)(null),{activeProjectId:c}=u(),{pendingRestores:d}=v(),f=(0,U.useRef)(!1);return(0,U.useEffect)(()=>{if(!c)return;let e=d.some(e=>e.kind===`ai-edit`&&e.projectId===c);e&&!f.current&&t!==`catalog`&&r(`catalog`),f.current=e},[d,c,t]),(0,U.useEffect)(()=>{let e=!1;return fetch(`${l()}/profiles/core-version`).then(e=>e.ok?e.json():null).then(t=>{!e&&t&&a(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,W.jsxs)(`div`,{className:`flex flex-col h-full`,children:[i!==null&&!i.profileAware&&(0,W.jsxs)(`div`,{className:`flex-shrink-0 flex items-start gap-3 px-6 py-3 border-b border-yellow-500/30 aurora-light:border-accent-warning/30 bg-yellow-500/10 aurora-light:bg-accent-warning/10`,children:[(0,W.jsx)(E,{className:`w-4 h-4 text-yellow-500 aurora-light:text-accent-warning mt-0.5 flex-shrink-0`}),(0,W.jsxs)(`div`,{className:`text-xs`,children:[(0,W.jsx)(`div`,{className:`font-medium text-yellow-500 aurora-light:text-accent-warning`,children:e(`page.banner.title`,{required:i.required})}),(0,W.jsx)(`div`,{className:`text-yellow-500/80 aurora-light:text-accent-warning mt-0.5`,children:(0,W.jsx)(o,{t:e,i18nKey:`page.banner.body`,values:{version:i.version??e(`page.banner.unknownVersion`),command:`npx specrails-core@latest update`},components:{code:(0,W.jsx)(`code`,{className:`px-1 rounded bg-yellow-500/20 aurora-light:bg-accent-warning/20`})}})})]})]}),(0,W.jsxs)(`div`,{className:`flex-shrink-0 border-b border-border`,children:[(0,W.jsxs)(`div`,{className:`px-6 pt-4`,children:[(0,W.jsx)(`h1`,{className:`text-lg font-semibold`,children:e(`page.title`)}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:e(`page.subtitle`)})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1 px-4 pt-3`,children:[(0,W.jsx)(Ta,{active:t===`profiles`,onClick:()=>r(`profiles`),children:e(`page.tabs.profiles`)}),(0,W.jsx)(Ta,{active:t===`usage`,onClick:()=>r(`usage`),children:e(`page.tabs.usage`)}),(0,W.jsx)(Ta,{active:t===`catalog`,onClick:()=>r(`catalog`),children:e(`page.tabs.catalog`)})]})]}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0 overflow-auto`,children:[t===`profiles`&&(0,W.jsx)(He,{}),t===`usage`&&(0,W.jsx)(wa,{}),t===`catalog`&&(0,W.jsx)(fa,{})]})]})}function wa(){return(0,W.jsx)(`div`,{className:`min-h-full`,children:(0,W.jsx)(va,{})})}function Ta({active:e,children:t,onClick:n}){return(0,W.jsx)(`button`,{type:`button`,onClick:n,className:`h-8 px-3 text-xs font-medium rounded-t-md border-b-2 transition-colors `+(e?`text-foreground border-foreground`:`text-muted-foreground border-transparent hover:text-foreground hover:border-border`),children:t})}export{Ca as default};