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,19 +0,0 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{V as r,Z as i,et as a}from"./TicketDetailModalContext-B-DySpKL.js";import{h as o,l as s,r as c}from"./useSharedWebSocket-BZMrX4jr.js";import{n as l,t as u}from"./createLucideIcon-Bjbbp_KS.js";import{a as d,r as f,s as p}from"./useDesktop-0unHDBJJ.js";import{r as m}from"./provider-capabilities-Vi1ZGvAK.js";import{u as h}from"./MinimizedChatsContext-CNx_0bZu.js";import{t as g}from"./circle-x-CMYsN4ZH.js";import{t as _}from"./git-branch-BRM0F5GN.js";import{t as v}from"./loader-circle-DcygOQpC.js";import{n as y,t as b}from"./square-Ci-PFcFe.js";import{t as x}from"./rotate-ccw-Wh4id13q.js";import{t as S}from"./search-Cq_gE3Ik.js";import{t as C}from"./triangle-alert-H9T4jAmh.js";import{t as w}from"./x-CBMI9ejn.js";import{t as T}from"./utils-BC4DHlz2.js";import{n as E,t as D}from"./lib-CGdyxIWg.js";import{t as O}from"./button-Ccc9Dc-D.js";import{n as k}from"./project-repositories-CSnfzUpg.js";import{t as ee}from"./useRuntimeRuns-BN1rhyEm.js";import{B as A,H as j,Ht as M,I as N,It as P,J as F,Jt as I,K as L,Pt as R,Rt as z,S as te,Tt as B,_ as ne,et as re,f as ie,g as ae,gt as V,ht as H,jt as oe,lt as U,m as W,p as se,q as ce,v as le,y as ue,z as de,zt as fe}from"./index-C4Mv6tV6.js";import{l as pe,n as me,p as he,r as ge,t as _e}from"./loop-layout-BF8xMiNv.js";import{t as ve}from"./lib-C7Mhm-gT.js";import{n as ye}from"./job-time-BCL7wee9.js";var be=u(`chevrons-down-up`,[[`path`,{d:`m7 20 5-5 5 5`,key:`13a0gw`}],[`path`,{d:`m7 4 5 5 5-5`,key:`1kwcof`}]]),xe=u(`chevrons-up-down`,[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]),Se=u(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}]]),Ce=u(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]),we=u(`hourglass`,[[`path`,{d:`M5 22h14`,key:`ehvnwv`}],[`path`,{d:`M5 2h14`,key:`pdyrp9`}],[`path`,{d:`M17 22v-4.172a2 2 0 0 0-.586-1.414L12 12l-4.414 4.414A2 2 0 0 0 7 17.828V22`,key:`1d314k`}],[`path`,{d:`M7 2v4.172a2 2 0 0 0 .586 1.414L12 12l4.414-4.414A2 2 0 0 0 17 6.172V2`,key:`1vvvr6`}]]),Te=u(`message-circle-question-mark`,[[`path`,{d:`M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719`,key:`1sd12s`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),G=e(t(),1),K=n();function Ee({phases:e,phaseDefinitions:t}){return t.length===0?null:(0,K.jsx)(`div`,{className:`flex items-center`,children:t.map((n,r)=>{let i=e[n.key]??`idle`,a=r<t.length-1?e[t[r+1].key]??`idle`:null;return(0,K.jsxs)(`div`,{className:`flex items-center`,children:[(0,K.jsxs)(de,{children:[(0,K.jsx)(j,{asChild:!0,children:(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-1.5 cursor-default px-4`,children:[(0,K.jsx)(De,{state:i}),(0,K.jsx)(`span`,{className:T(`text-xs font-medium transition-colors`,i===`running`?`text-blue-400 aurora-light:text-accent-info`:i===`done`?`text-emerald-400 aurora-light:text-accent-success`:i===`error`?`text-red-400 aurora-light:text-destructive`:`text-muted-foreground/40`),children:n.label})]})}),(0,K.jsxs)(A,{side:`bottom`,className:`max-w-[200px]`,children:[(0,K.jsx)(`p`,{className:`font-medium`,children:n.label}),(0,K.jsx)(`p`,{className:`text-muted-foreground mt-0.5`,children:n.description})]})]}),a!==null&&(0,K.jsx)(`div`,{className:T(`h-px w-12 -mt-5 shrink-0 transition-all duration-300`,a===`done`||i===`done`?`bg-emerald-500/30 aurora-light:bg-accent-success/40`:a===`running`?`bg-blue-400/40 aurora-light:bg-accent-info/40`:`bg-border/30`)})]},n.key)})})}function De({state:e}){return(0,K.jsxs)(`div`,{className:T(`flex items-center justify-center w-10 h-10 rounded-full transition-all duration-300`,e===`running`?`bg-blue-500/10 aurora-light:bg-accent-info/10 ring-1 ring-blue-400/30 aurora-light:ring-accent-info/30 animate-pulse`:e===`done`?`bg-emerald-500/10 aurora-light:bg-accent-success/10`:e===`error`?`bg-red-500/10 aurora-light:bg-destructive/10`:`bg-muted/20`),children:[e===`running`&&(0,K.jsx)(v,{className:`w-6 h-6 text-blue-400 aurora-light:text-accent-info animate-spin`}),e===`done`&&(0,K.jsx)(P,{className:`w-6 h-6 text-emerald-400 aurora-light:text-accent-success`}),e===`error`&&(0,K.jsx)(g,{className:`w-6 h-6 text-red-400 aurora-light:text-destructive`}),e===`idle`&&(0,K.jsx)(i,{className:`w-6 h-6 text-muted-foreground/20`})]})}function Oe(e,t){let n=ye(e??null),r=(typeof t==`number`?t:ye(t??null)?.getTime()??NaN)-(n?.getTime()??NaN);if(!Number.isFinite(r)||r<0)return`—`;let i=Math.round(r/1e3);if(i<60)return`${i}s`;let a=Math.floor(i/60),o=i%60;return a<60?`${a}m ${o}s`:`${Math.floor(a/60)}h ${a%60}m`}function ke(e){let t=new Set;for(let n of e)if(n.event_type===`log`)try{let e=(JSON.parse(n.payload).line??``).match(/(?:Writing|Editing|Created?|Updated?)\s+(?:file:\s*)?([\w./\-]+\.\w+)/i);e&&t.add(e[1])}catch{}return Array.from(t).slice(0,20)}var Ae={steps:0,actionKey:``,actionArg:``,turns:0,tokens:0,lastSeenIdx:0};function je(e){if(e.event_type!==`assistant`)return null;try{let t=JSON.parse(e.payload);if(!t||typeof t!=`object`||Array.isArray(t))return null;let n=t.message,r=(n&&typeof n==`object`&&!Array.isArray(n)?n:t).usage;if(!r||typeof r!=`object`||Array.isArray(r))return null;let i=r,a=e=>typeof e==`number`&&Number.isFinite(e)?e:0;return a(i.input_tokens)+a(i.output_tokens)+a(i.cache_read_input_tokens)+a(i.cache_creation_input_tokens)}catch{return null}}function Me(e,t){if(t.type===`reset`)return Ae;if(t.type===`consume`){let{events:n}=t,r=e.lastSeenIdx>n.length?n.length:e.lastSeenIdx;if(n.length<=r)return r===e.lastSeenIdx?e:{...e,lastSeenIdx:r};let{steps:i,actionKey:a,actionArg:o,turns:s,tokens:c}=e;for(let e=r;e<n.length;e++){let t=W(n[e]);t.step&&(i+=t.stepCount??1),t.actionKey&&(a=t.actionKey,o=t.actionArg??``);let r=je(n[e]);r!=null&&(s+=1,c+=r)}return{steps:i,actionKey:a,actionArg:o,turns:s,tokens:c,lastSeenIdx:n.length}}return e}function Ne(e,t){let[n,r]=(0,G.useReducer)(Me,Ae),i=(0,G.useRef)(e);return(0,G.useEffect)(()=>{i.current!==e&&(i.current=e,r({type:`reset`})),r({type:`consume`,events:t})},[e,t]),n}function Pe(e,t){let n=t&&e.steps===0?`connecting`:e.actionKey||`thinking`,r=n===`delegating`||ie.has(n),i=r&&e.actionArg!==``;return{key:r&&!i?`working`:n,arg:i?e.actionArg:null}}function Fe(e){return`${(e/1e3).toFixed(1)}k`}function Ie(e){let t=!!e.total_cost_usd_estimated,n=e.total_cost_usd==null?null:`${t?`~`:``}$${e.total_cost_usd.toFixed(4)}`,r=e.num_turns==null?null:String(e.num_turns),i=e.tokens_in==null?null:(e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0);return{cost:n,turns:r,tokens:i==null?null:Fe(i)}}function Le(e){if(e.length<=1)return null;let t=e=>e.tokens_in==null&&e.tokens_out==null&&e.tokens_cache_read==null&&e.tokens_cache_create==null;return{totalCostUsd:e.reduce((e,t)=>e+(t.total_cost_usd??0),0),hasNullCost:e.some(e=>e.total_cost_usd==null),costEstimated:e.some(e=>!!e.total_cost_usd_estimated),nullCostCount:e.filter(e=>e.total_cost_usd==null).length,costUnavailable:e.every(e=>e.total_cost_usd==null),totalTokensIn:e.reduce((e,t)=>e+(t.tokens_in??0),0),totalTokensOut:e.reduce((e,t)=>e+(t.tokens_out??0),0),totalTokensCacheRead:e.reduce((e,t)=>e+(t.tokens_cache_read??0),0),totalTokensCacheCreate:e.reduce((e,t)=>e+(t.tokens_cache_create??0),0),nullTokenCount:e.filter(t).length,tokensUnavailable:e.every(t),jobCount:e.length}}function Re(e){return e.costUnavailable?`—`:`${e.costEstimated?`~`:``}${e.hasNullCost?`≥`:``}$${e.totalCostUsd.toFixed(4)}`}function ze(e){if(e.tokensUnavailable)return`—`;let t=e.totalTokensIn+e.totalTokensOut+e.totalTokensCacheRead+e.totalTokensCacheCreate;return`${(e.nullTokenCount??0)>0?`≥`:``}${Fe(t)}`}var Be=`specrails-desktop:job-run-details`;function Ve(e){try{let t=localStorage.getItem(Be);return t?JSON.parse(t)?.[e]===!0:!1}catch{return!1}}function He(e,t){try{let n=localStorage.getItem(Be),r={};if(n)try{let e=JSON.parse(n);e&&typeof e==`object`&&(r=e)}catch{}r[e]=t,localStorage.setItem(Be,JSON.stringify(r))}catch{}}var Ue={running:{variant:`running`,labelKey:`statusLabel.running`,tooltipKey:`statusTooltip.running`},completed:{variant:`success`,labelKey:`statusLabel.completed`,tooltipKey:`statusTooltip.completed`},failed:{variant:`failed`,labelKey:`statusLabel.failed`,tooltipKey:`statusTooltip.failed`},canceled:{variant:`canceled`,labelKey:`statusLabel.canceled`,tooltipKey:`statusTooltip.canceled`},queued:{variant:`queued`,labelKey:`statusLabel.queued`,tooltipKey:`statusTooltip.queued`},zombie_terminated:{variant:`failed`,labelKey:`statusLabel.zombie`,tooltipKey:`statusTooltip.zombie`},skipped:{variant:`queued`,labelKey:`statusLabel.skipped`,tooltipKey:`statusTooltip.skipped`}};function We({job:e,events:t,phases:n,phaseDefinitions:r,projectId:i,variant:a,pipelineTotals:o,actions:s,onOpenRun:c}){let{t:u}=l(`jobs`),{t:d}=l(`agentRuntime`),f=e.status===`running`,p=e.status===`queued`,h=e.command.startsWith(`loop:`),g=Ue[e.status]??Ue.queued,[_,y]=(0,G.useState)(()=>Date.now());(0,G.useEffect)(()=>{if(!f)return;y(Date.now());let e=window.setInterval(()=>y(Date.now()),1e3);return()=>window.clearInterval(e)},[f]);let b=e.finished_at?Oe(e.started_at,e.finished_at):f?Oe(e.started_at,_):`—`,x=Ne(e.id,t),S=ee(i,{jobId:e.id,enabled:!!i}),C=S.runs[0],[w,E]=(0,G.useState)(()=>Ve(a)),D=e=>{E(e),He(a,e)},k=(0,G.useMemo)(()=>r.find(e=>n[e.key]===`running`)?.label??null,[n,r]),M=C?.nextStep?d(`roles.${C.nextStep}`,{defaultValue:C.nextStep}):null,N=k??M,{key:P,arg:F}=Pe(x,f),I=F==null?u(`statusPanel.activity.${P}`):u(`statusPanel.activity.${P}`,{arg:F}),L=f?N?u(`runHeader.phaseActivity`,{phase:N,activity:I}):I:C&&!C.active&&C.nextStep&&(C.canResume||C.pendingQuestion||C.pendingApproval)?u(`runHeader.phaseActivity`,{phase:d(`runs.status.${C.status}`,{defaultValue:C.status}),activity:d(`runs.phase`,{phase:M})}):null,R=h&&f&&x.steps>0?u(`statusPanel.steps`,{count:x.steps}):null,z=Ie(e),B=!f&&!p,re=(0,G.useMemo)(()=>B?ke(t):[],[t,B]),ie=f&&x.turns>0,V=S.runs.length>0?S.error:``,H=!!C?.pendingQuestion&&!!C.canResume&&!C.recoverableSteps.length,oe=B||ie||!!C&&!!i||!!V,U=S.busy!==null,W=C?(0,K.jsxs)(K.Fragment,{children:[C.canResume&&!H&&(C.engineVersion===2&&C.recoverableSteps.length>0?(0,K.jsx)(ue,{run:C,busy:U,onRecover:e=>void S.act(C,`recover`,e)},`${i}:${C.runId}`):(0,K.jsx)(O,{size:`sm`,className:`h-7`,disabled:U,onClick:()=>void S.act(C,C.recoverableSteps.length?`recover`:C.pendingApproval?`approve`:`resume`),children:C.recoverableSteps.length?d(`runs.recover`):C.pendingApproval?d(`runs.approve`):d(`runs.resume`)})),H&&(0,K.jsxs)(O,{size:`sm`,variant:`outline`,className:`h-7 border-accent-warning/40 text-accent-warning hover:bg-accent-warning/10`,onClick:()=>D(!0),children:[(0,K.jsx)(Te,{className:`w-3.5 h-3.5 mr-1.5`,"aria-hidden":!0}),u(`runHeader.questionPending`)]}),C.canSettle&&(0,K.jsx)(O,{size:`sm`,className:`h-7`,disabled:U,onClick:()=>void S.act(C,`settle`),children:d(`runs.prepareDelivery`)}),C.forkSuccessor&&c&&(0,K.jsx)(O,{size:`sm`,variant:`outline`,onClick:()=>c(C.forkSuccessor),children:u(`loopExplorer.openFork`)}),C.canCancel&&(0,K.jsx)(O,{size:`sm`,variant:`secondary`,className:`h-7`,disabled:U,onClick:()=>void S.act(C,`cancel`),children:d(`runs.cancel`)})]}):null;return(0,K.jsxs)(`div`,{"data-testid":`job-run-header`,className:T(`shrink-0`,a===`glass`?`border-b border-border/30 bg-surface/30`:`border-b border-border bg-background`),children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap px-3 py-2 min-w-0`,children:[(0,K.jsxs)(de,{children:[(0,K.jsx)(j,{asChild:!0,children:(0,K.jsx)(`div`,{children:(0,K.jsx)(te,{variant:g.variant,children:u(g.labelKey)})})}),(0,K.jsx)(A,{children:u(g.tooltipKey)})]}),(0,K.jsxs)(`span`,{className:T(`inline-flex items-center gap-1.5 text-xs tabular-nums`,f?`text-accent-info font-medium`:`text-muted-foreground`),title:u(f?`statusPanel.liveTooltip`:`statusPanel.duration`),children:[f&&(0,K.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-accent-info animate-pulse`,"aria-hidden":!0}),b]}),L&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0 flex-1 basis-40 text-xs text-muted-foreground`,children:[f&&(0,K.jsx)(v,{className:`w-3 h-3 shrink-0 text-accent-info animate-spin`,"aria-hidden":!0}),(0,K.jsx)(`span`,{className:`truncate`,"data-testid":`job-run-activity`,children:L})]}),!L&&(0,K.jsx)(`span`,{className:`flex-1`}),R&&(0,K.jsx)(`span`,{className:`text-[11px] text-muted-foreground/70 tabular-nums shrink-0`,children:R}),(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0 ml-auto`,children:[W,s,oe&&(0,K.jsxs)(`button`,{type:`button`,onClick:()=>D(!w),"aria-expanded":w,className:`inline-flex items-center gap-1 h-7 px-2 rounded-md text-[11px] text-muted-foreground hover:text-foreground hover:bg-surface/60 transition-colors`,children:[u(`runHeader.details`),(0,K.jsx)(fe,{className:T(`w-3.5 h-3.5 transition-transform duration-150`,w&&`rotate-180`),"aria-hidden":!0})]})]})]}),r.length>0&&(0,K.jsx)(`div`,{className:`px-3 pb-2 overflow-x-auto`,children:(0,K.jsx)(Ee,{phases:n,phaseDefinitions:r})}),oe&&w&&(0,K.jsxs)(`div`,{"data-testid":`job-run-details`,className:`px-3 pb-3 space-y-3 border-t border-border/20 pt-3 text-xs`,children:[ie&&(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 max-w-sm`,children:[(0,K.jsx)(q,{label:u(`statusPanel.turns`),value:String(x.turns)}),(0,K.jsx)(q,{label:u(`statusPanel.tokens`),value:Fe(x.tokens)})]}),(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/60 mt-1`,children:u(`runHeader.liveReported`)})]}),B&&(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-w-lg`,children:[(0,K.jsx)(q,{label:u(`statusPanel.cost`),value:z.cost,valueClass:`text-yellow-400 aurora-light:text-accent-warning`,naCaption:m(e.provider)?u(`statusPanel.costUnknownLocal`):u(`statusPanel.notAvailable`),naTooltip:m(e.provider)?u(`statusPanel.costUnknownLocalTooltip`):void 0}),(0,K.jsx)(q,{label:u(`statusPanel.turns`),value:z.turns,naCaption:u(`statusPanel.notAvailable`)}),(0,K.jsx)(q,{label:u(`statusPanel.tokens`),value:z.tokens,naCaption:u(`statusPanel.notAvailable`)})]}),B&&o&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:u(`statusPanel.pipelineTotal`,{count:o.jobCount})}),(0,K.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 max-w-sm`,children:[(0,K.jsx)(q,{label:u(`statusPanel.totalCost`),value:Re(o),valueClass:`text-yellow-400 aurora-light:text-accent-warning`}),(0,K.jsx)(q,{label:u(`statusPanel.totalTokens`),value:ze(o)})]}),o.hasNullCost&&!o.costUnavailable&&(0,K.jsx)(`p`,{"data-testid":`pipeline-partial-hint`,className:`text-[10px] text-muted-foreground/70 mt-1.5`,title:u(`statusPanel.pipelinePartialTooltip`),children:u(`statusPanel.pipelinePartial`,{count:o.nullCostCount??0})}),o.costUnavailable&&(0,K.jsx)(`p`,{"data-testid":`pipeline-cost-unavailable`,className:`text-[10px] text-muted-foreground/70 mt-1.5`,children:u(`statusPanel.pipelineCostUnavailable`)}),(o.nullTokenCount??0)>0&&(0,K.jsx)(`p`,{"data-testid":`pipeline-usage-coverage-hint`,className:`text-[10px] text-muted-foreground/70 mt-1`,title:u(`statusPanel.pipelineUsageTooltip`),children:o.tokensUnavailable?u(`statusPanel.pipelineUsageUnavailable`):u(`statusPanel.pipelineUsagePartial`,{count:o.nullTokenCount??0})})]}),re.length>0&&(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider mb-1.5`,children:u(`statusPanel.filesModified`)}),(0,K.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:re.map(e=>(0,K.jsx)(`code`,{className:`text-[10px] font-mono bg-muted/30 px-2 py-0.5 rounded text-cyan-400/80 aurora-light:text-accent-info`,children:e},e))})]}),(C||V)&&i&&(0,K.jsxs)(`section`,{"aria-label":d(`runs.implementation`),className:`space-y-2`,onClick:e=>e.stopPropagation(),onPointerDown:e=>e.stopPropagation(),children:[V&&(0,K.jsx)(`p`,{role:`alert`,className:`text-destructive`,children:V}),C?.historical&&(0,K.jsx)(`p`,{className:`text-muted-foreground`,children:d(`evidence.historical`)}),C?.status===`succeeded`&&(0,K.jsx)(`p`,{className:`text-muted-foreground`,children:d(`runs.reviewDelivery`)}),C?.canResume&&(0,K.jsx)(`p`,{className:`text-muted-foreground`,children:d(`runs.preserveProgress`)}),C?.error&&(0,K.jsx)(`p`,{className:`text-destructive`,children:C.error}),C?.pendingApproval?.reason&&(0,K.jsx)(`p`,{className:`text-muted-foreground`,children:C.pendingApproval.reason}),C?.pendingQuestion&&(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`font-medium`,children:d(`runs.question`)}),(0,K.jsx)(`p`,{className:`whitespace-pre-wrap`,children:C.pendingQuestion.question}),H&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`label`,{className:`block space-y-1`,children:[d(`runs.answerLabel`),(0,K.jsx)(`textarea`,{className:`min-h-20 w-full rounded-md border border-input bg-background px-2 py-1 text-sm`,maxLength:2e4,placeholder:d(`runs.answerPlaceholder`),value:S.answers[C.runId]??``,onChange:e=>S.setAnswer(C.runId,e.target.value)})]}),(0,K.jsx)(O,{size:`sm`,disabled:U||!S.answers[C.runId]?.trim(),onClick:()=>void S.act(C,`answer`),children:d(`runs.answer`)})]})]}),C?.metrics&&(0,K.jsx)(ae,{metrics:C.metrics}),C&&(0,K.jsx)(le,{projectId:i,runId:C.runId,summary:C.efficiencySummary,historical:C.historical}),C&&(0,K.jsx)(ne,{projectId:i,run:C,onAccepted:S.refresh})]})]})]})}function q({label:e,value:t,valueClass:n,naCaption:r,naTooltip:i}){return(0,K.jsxs)(`div`,{className:`bg-muted/20 rounded-lg px-2.5 py-1.5`,title:t==null?i:void 0,children:[(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/50 uppercase tracking-wider`,children:e}),(0,K.jsx)(`p`,{className:T(`text-sm font-semibold tabular-nums`,t==null?`text-muted-foreground`:n),children:t??`—`}),t==null&&r&&(0,K.jsx)(`p`,{className:`text-[10px] text-muted-foreground/40`,children:r})]})}function Ge(e){let t=e.trimStart();return!!(/^#{1,6}\s/.test(t)||/^[-*+]\s/.test(t)||/^\d+\.\s/.test(t)||/^\|.+\|/.test(t)||t.startsWith("```")||t.startsWith(`> `)||/\*\*[^*]+\*\*/.test(e)||/`[^`]+`/.test(e)||/\[.+\]\(.+\)/.test(e)||/^(-{3,}|_{3,}|\*{3,})$/.test(t)||/^- \[[ x]\]\s/.test(t))}var Ke=new Set;function qe({ticketId:e,onOpen:t,children:n}){let{t:r}=l(`agent`),i=r(`refs.openTicket`,{id:e});return(0,K.jsx)(`button`,{type:`button`,"data-testid":`log-ticket-ref`,onClick:n=>{n.stopPropagation(),t(e)},title:i,"aria-label":i,className:`inline cursor-pointer p-0 align-baseline text-accent-primary/90 underline decoration-accent-primary/50 decoration-dotted underline-offset-2 transition-colors hover:text-accent-primary hover:decoration-solid`,children:n})}function Je(e){if(!e.includes(`#`))return null;let t=F(e,Ke);return t.some(e=>e.kind===`ticket`)?t:null}function Ye(e,t){let n=Je(e);return n?n.map((e,n)=>e.kind===`ticket`?(0,K.jsx)(qe,{ticketId:e.ticketId,onOpen:t,children:e.label},n):(0,K.jsx)(G.Fragment,{children:e.kind===`text`?e.text:e.label},n)):e}var Xe=new Set([`code`,`inlineCode`,`link`,`linkReference`,`image`,`imageReference`,`definition`,`html`]);function Ze(e){return e.kind===`ticket`?{type:`link`,url:L({kind:`ticket`,ticketId:e.ticketId}),children:[{type:`text`,value:e.label}]}:{type:`text`,value:e.kind===`text`?e.text:e.label}}function Qe(e){let t=e.children;if(t)for(let e=t.length-1;e>=0;e--){let n=t[e];if(!Xe.has(n.type))if(n.type===`text`&&typeof n.value==`string`){let r=F(n.value,Ke);r.some(e=>e.kind===`ticket`)&&t.splice(e,1,...r.map(Ze))}else Qe(n)}}function $e(){return e=>Qe(e)}function et(e){let{activeProjectId:t}=f(),{openRef:n}=re(),r=e??t??void 0;return(0,G.useMemo)(()=>r?e=>{n(r,{kind:`ticket`,ticketId:e})}:void 0,[r,n])}function tt(e,t){let n=`${e.id??t}`,r=e.timestamp;if(e.event_type===`log`)try{let t=JSON.parse(e.payload).line??``;return t.trim()?t.startsWith(`▸`)||t.match(/^(architect|developer|reviewer|ship|analyst)\s*:/i)?{id:n,content:t,type:`phase`,timestamp:r}:e.source===`stderr`?{id:n,content:t,type:`stderr`,timestamp:r}:Ge(t)?{id:n,content:t,type:`assistant`,timestamp:r}:{id:n,content:t,type:`plain`,timestamp:r}:null}catch{return null}if(e.event_type!==`log`&&e.event_type!==`result`)return null;if(e.event_type===`result`)try{let t=JSON.parse(e.payload),i=[];return t.duration_ms&&i.push(`${(t.duration_ms/1e3).toFixed(1)}s`),t.total_cost_usd&&i.push(`$${t.total_cost_usd.toFixed(4)}`),t.num_turns&&i.push(o.t(`jobs:logViewer.turns`,{count:t.num_turns})),{id:n,content:`▸ ${o.t(`jobs:logViewer.completed`)}${i.length?` — ${i.join(` · `)}`:``}`,type:`result`,timestamp:r}}catch{return null}return null}function nt(e){let t=`none`,n=[];for(let r of e){let e=r.type;if(e!==`plain`&&e!==`log`){t=`none`,n.push(r);continue}let i=r.content;i.startsWith(`--- `)?(t=`saw_minus`,n.push({...r,type:`diff-meta`})):t===`saw_minus`&&i.startsWith(`+++ `)?(t=`active`,n.push({...r,type:`diff-meta`})):t===`active`&&i.startsWith(`@@ `)?n.push({...r,type:`diff-hunk`}):t===`active`&&i.startsWith(`+`)&&!i.startsWith(`+++`)?n.push({...r,type:`diff-add`}):t===`active`&&i.startsWith(`-`)&&!i.startsWith(`---`)?n.push({...r,type:`diff-remove`}):(t===`active`&&(i.startsWith(` `)||i===``)||(t=`none`),n.push(r))}return n}function rt(e){let t=[];for(let n of e){let e=t.length>0?t[t.length-1]:null;n.type===`assistant`&&e?.type===`assistant`?e.content+=`
2
- `+n.content:t.push({...n})}return t}function it(e){let t=[{key:`__preamble__`,header:null,lines:[]}];for(let n of e)n.type===`phase`?t.push({key:n.id,header:n,lines:[]}):t[t.length-1].lines.push(n);return t.filter(e=>e.header!==null||e.lines.length>0)}function at({events:e,isLoading:t,projectId:n}){let{t:r,i18n:i}=l(`jobs`),[a,o]=(0,G.useState)(``),[s,c]=(0,G.useState)(!0),[u,d]=(0,G.useState)(new Set),f=(0,G.useRef)(null),m=(0,G.useRef)(null),h=et(n),{processedLines:g,groups:_,totalLines:v}=(0,G.useMemo)(()=>{let t=nt(rt(e.map((e,t)=>tt(e,t)).filter(e=>e!==null)));return{processedLines:t,groups:it(t),totalLines:t.length}},[e,i.language]),y=(0,G.useMemo)(()=>{if(!a)return v;let e=a.toLowerCase();return g.filter(t=>t.content.toLowerCase().includes(e)).length},[a,g,v]),b=(0,G.useCallback)(()=>{let e=m.current;e&&(e.scrollTop=e.scrollHeight)},[]);(0,G.useEffect)(()=>{s&&b()},[e.length,s,b]);function x(){let e=m.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight<50;c(t)}function C(e){d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}return t?(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`logViewer.loading`)})}):v===0?(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`logViewer.empty`)})}):(0,K.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:`px-4 py-2 border-b border-border flex items-center gap-2`,children:[(0,K.jsxs)(`div`,{className:`relative flex-1 max-w-xs`,children:[(0,K.jsx)(S,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground`}),(0,K.jsx)(N,{placeholder:r(`logViewer.filterPlaceholder`),value:a,onChange:e=>o(e.target.value),className:`pl-7 h-7`})]}),(0,K.jsx)(O,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:()=>{let e=g.map(e=>e.content).join(`
3
- `);navigator.clipboard.writeText(e).then(()=>{p.success(r(`logViewer.copySuccess`))}).catch(()=>{p.error(r(`logViewer.copyFailed`))})},children:(0,K.jsx)(R,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:r(`logViewer.lineCount`,{filtered:y,total:v})})]}),(0,K.jsxs)(`div`,{ref:m,className:`flex-1 overflow-y-auto p-2 text-xs relative`,onScroll:x,children:[_.map(e=>(0,K.jsx)(ot,{group:e,filter:a,collapsed:u.has(e.key),onToggle:()=>C(e.key),onOpenTicket:h},e.key)),(0,K.jsx)(`div`,{ref:f})]}),!s&&(0,K.jsxs)(O,{size:`sm`,variant:`secondary`,onClick:()=>{c(!0),b()},className:`absolute bottom-16 right-6 h-7 gap-1 shadow-lg`,children:[(0,K.jsx)(fe,{className:`w-3 h-3`}),r(`logViewer.jumpToBottom`)]})]})}var ot=(0,G.memo)(function({group:e,filter:t,collapsed:n,onToggle:r,onOpenTicket:i}){let{t:a}=l(`jobs`),o=t?e.lines.filter(e=>e.content.toLowerCase().includes(t.toLowerCase())):e.lines;if(e.header===null)return o.length===0?null:(0,K.jsx)(`div`,{children:o.map((e,t)=>(0,K.jsx)(ut,{line:e,even:t%2==0,onOpenTicket:i},e.id))});let s=e.header.content;return(0,K.jsxs)(`div`,{className:`mt-3 rounded-md overflow-hidden border border-border/20`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:r,className:T(`flex items-center gap-2 w-full text-left px-3 py-2`,`bg-primary/5 border-b border-primary/20`,`hover:bg-primary/10 transition-colors duration-150 cursor-pointer`),children:[(0,K.jsx)(z,{className:T(`w-3 h-3 text-primary/60 shrink-0 transition-transform duration-150`,!n&&`rotate-90`)}),(0,K.jsx)(`span`,{className:`flex-1 text-[12px] font-semibold text-foreground leading-none`,children:s}),e.header.timestamp&&(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 font-mono tabular-nums shrink-0`,children:new Date(e.header.timestamp).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1})}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:a(`logViewer.phaseLines`,{count:e.lines.length})})]}),!n&&(0,K.jsx)(`div`,{className:`bg-muted/5`,children:o.length===0?(0,K.jsx)(`p`,{className:`px-4 py-2 text-[10px] text-muted-foreground/40 italic`,children:a(t?`logViewer.noMatchingLines`:`logViewer.noOutput`)}):o.map((e,t)=>(0,K.jsx)(ut,{line:e,even:t%2==0,onOpenTicket:i},e.id))})]})}),st=[ve],ct=[D],lt=[D,$e],ut=(0,G.memo)(function({line:e,even:t,onOpenTicket:n}){let r=e.type===`assistant`,i=e.type===`diff-add`,a=e.type===`diff-remove`,o=e.type===`diff-meta`,s=e.type===`diff-hunk`,c=i||a||o||s,l=n!=null&&(e.type===`plain`||e.type===`log`),u=(0,G.useMemo)(()=>l&&n?Ye(e.content,n):e.content,[l,n,e.content]),d=r&&n?lt:ct,f=(0,G.useMemo)(()=>n?{a:({href:e,children:t})=>{let r=ce(e);return r?.kind===`ticket`?(0,K.jsx)(qe,{ticketId:r.ticketId,onOpen:n,children:t}):(0,K.jsx)(`a`,{href:e,children:t})}}:void 0,[n]);return(0,K.jsxs)(`div`,{className:T(`flex items-start gap-2 group px-2 py-0.5 rounded-sm`,!c&&(t?`bg-muted/20`:`bg-transparent`),e.type===`result`&&`bg-emerald-500/5 aurora-light:bg-accent-success/10 border-l-2 border-emerald-500/40 aurora-light:border-accent-success/40 mt-2 py-2`,i&&`bg-emerald-500/8 aurora-light:bg-accent-success/10 border-l-2 border-emerald-500/50 aurora-light:border-accent-success/50`,a&&`bg-red-500/8 aurora-light:bg-destructive/10 border-l-2 border-red-500/50 aurora-light:border-destructive/50`,o&&`bg-accent-primary/5 border-l-2 border-accent-primary/30`,s&&`bg-accent-info/5 border-l-2 border-accent-info/30`),children:[e.timestamp&&(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0 mt-0.5 w-[52px] font-mono tabular-nums`,children:new Date(e.timestamp).toLocaleTimeString(`en`,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1})}),r?(0,K.jsx)(`div`,{className:`flex-1 min-w-0 prose prose-invert prose-xs max-w-none
4
- prose-p:my-1 prose-p:leading-relaxed
5
- prose-headings:mt-2 prose-headings:mb-1 prose-headings:text-sm prose-headings:font-semibold
6
- prose-ul:my-1 prose-ol:my-1 prose-li:my-0
7
- prose-code:text-cyan-300 prose-code:text-[11px] prose-code:bg-muted/40 prose-code:px-1 prose-code:py-0.5 prose-code:rounded
8
- prose-pre:my-1 prose-pre:bg-muted/30 prose-pre:rounded-md prose-pre:p-2 prose-pre:text-[11px]
9
- prose-strong:text-foreground prose-em:text-foreground/70
10
- prose-a:text-blue-400 prose-a:no-underline hover:prose-a:underline
11
- prose-table:my-2 prose-table:text-[11px]
12
- prose-thead:border-border prose-thead:bg-muted/30
13
- prose-th:px-3 prose-th:py-1.5 prose-th:text-left prose-th:font-semibold prose-th:text-foreground/90
14
- prose-td:px-3 prose-td:py-1.5 prose-td:border-border
15
- prose-tr:border-border
16
- text-foreground/80`,children:(0,K.jsx)(E,{remarkPlugins:d,rehypePlugins:st,components:f,children:e.content})}):(0,K.jsx)(`span`,{className:T(`flex-1 break-all leading-relaxed whitespace-pre-wrap font-mono`,e.type===`tool-use`&&`text-cyan-400/80 aurora-light:text-accent-info text-[11px]`,e.type===`stderr`&&`text-orange-400 aurora-light:text-accent-warning`,e.type===`result`&&`text-emerald-400 aurora-light:text-accent-success font-medium`,e.type===`log`&&`text-foreground/60`,e.type===`plain`&&`text-foreground/70`,e.type===`tool-result`&&`text-muted-foreground/50`,i&&`text-emerald-400 aurora-light:text-accent-success`,a&&`text-red-400 aurora-light:text-destructive`,o&&`text-accent-primary/80`,s&&`text-accent-info/80`),children:u})]})}),dt=e=>!!e&&typeof e==`object`&&!Array.isArray(e);function ft(e){if(!dt(e)||typeof e.entry!=`string`||!Array.isArray(e.nodes)||e.nodes.length>1e4)return null;let t=[];for(let n of e.nodes){if(!dt(n)||typeof n.id!=`string`||!n.id||typeof n.kind!=`string`||typeof n.label!=`string`||!dt(n.ends)||Object.values(n.ends).some(e=>e!==null&&typeof e!=`string`)||n.component!==void 0&&typeof n.component!=`string`)return null;t.push({id:n.id,kind:n.kind,label:n.label,ends:n.ends,...typeof n.component==`string`?{component:n.component}:{}})}let n=new Set(t.map(e=>e.id));return n.size!==t.length||!n.has(e.entry)||t.some(e=>Object.values(e.ends).some(e=>e!==null&&!n.has(e)))?null:{entry:e.entry,nodes:t}}function pt(e){let t=ft(e);if(!t||!dt(e)||e.components!==void 0&&!dt(e.components))return null;let n=Object.create(null);for(let[t,r]of Object.entries(e.components??{})){let e=ft(r);if(!e)return null;n[t]=e}return{...t,components:n}}var J=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Y=e=>typeof e==`number`&&Number.isFinite(e)&&e>=0,mt=e=>Array.isArray(e)&&e.every(e=>typeof e==`string`);function ht(e){if(!J(e)||e.version!==1||typeof e.execution!=`string`||!Y(e.steps)||!Y(e.deciderEvaluations)||!(e.turns===null||Y(e.turns))||!(e.costUsd===null||Y(e.costUsd))||typeof e.costUncertain!=`boolean`||e.engineVersion===2&&e.completion!==void 0&&(!J(e.completion)||typeof e.completion.ok!=`boolean`||typeof e.completion.verified!=`boolean`||!mt(e.completion.reasons)))return null;if(e.core!==null){let t=e.core;if(!J(t)||typeof t.change!=`string`||typeof t.recordedAt!=`string`||!J(t.completion)||![`implementation`,`validation`,`archive`,`delivery`].every(e=>typeof t.completion==`object`&&typeof t.completion[e]==`string`)||!mt(t.completion.reasons)||!mt(t.findings)||!Array.isArray(t.exceptions)||!Array.isArray(t.checks)||!Array.isArray(t.phases)||!t.exceptions.every(e=>J(e)&&[`requirement`,`reason`,`impact`,`acceptedBy`,`approvalEvidence`].every(t=>typeof e[t]==`string`))||!t.checks.every(e=>J(e)&&[`name`,`status`,`scope`,`limitations`].every(t=>typeof e[t]==`string`)&&typeof e.required==`boolean`&&mt(e.evidence))||!t.phases.every(e=>J(e)&&typeof e.name==`string`&&typeof e.status==`string`&&(e.durationMs===null||Y(e.durationMs))&&(e.attempts===null||Y(e.attempts))))return null}return e}function X(e){try{let t=JSON.parse(e);if(t&&typeof t==`object`&&!Array.isArray(t))return t}catch{}return null}var gt=/^\s*━+\s*Step\s+\d+\s*·/,_t=/\s*\(iteration\s+\d+\)\s*$/i;function vt(e){return e.replace(/^[\s\uFE0F\p{Extended_Pictographic}]+/u,``).trim()||e.trim()}function yt(e){let t=vt(e.title);return e.iteration==null?t:t.replace(_t,``)}function bt(e){return e.meta.nodeId??`${e.meta.kind}::${vt(e.meta.title).replace(_t,``)}`}function xt(e){let t=null,n=0,r=null,i=[[]],a=new Map,o=[];for(let s=0;s<e.length;s++){let c=e[s];if(c.event_type===`loop_completion`){r=ht(X(c.payload));continue}if(c.event_type===`runtime-graph`){let e=X(c.payload);if(e&&Array.isArray(e.nodes)&&Array.isArray(e.edges)){let n=e.nodes.filter(e=>!!(e&&typeof e==`object`&&typeof e.path==`string`)),r=e.edges.filter(e=>!!(e&&typeof e==`object`&&typeof e.from==`string`&&typeof e.to==`string`)),i=t;t={...i??{},runtimeTopology:pt(e.graph)??void 0,loopId:typeof e.workflowId==`string`?e.workflowId:i?.loopId,graph:{nodes:n.map((e,t)=>({id:String(e.path),type:`core`,position:{x:0,y:t*100},data:{label:String(e.label??e.path),kind:e.kind}})),edges:r.map((e,t)=>({id:`core-edge-${t}`,source:String(e.from),target:String(e.to),label:String(e.label)})),config:i?.graph.config??{maxIterations:1,timeoutMinutes:0}}}}continue}if(c.event_type===`loop_graph`){let e=X(c.payload);e&&e.graph&&typeof e.graph==`object`&&!Array.isArray(e.graph)&&(t={graph:e.graph,loopId:typeof e.loopId==`string`?e.loopId:void 0,loopName:typeof e.loopName==`string`?e.loopName:void 0,provider:typeof e.provider==`string`?e.provider:void 0,model:typeof e.model==`string`?e.model:void 0,iterationLimit:typeof e.iterationLimit==`number`?e.iterationLimit:void 0});continue}if(c.event_type===`loop_step`){let e=X(c.payload);if(!e||typeof e.index!=`number`)continue;let t=typeof e.iteration==`number`?e.iteration:null;t!=null&&t>n&&(n=t),o.push({meta:{index:e.index,traceId:typeof e.traceId==`string`?e.traceId:void 0,spanId:typeof e.spanId==`string`?e.spanId:void 0,nodePath:typeof e.nodePath==`string`?e.nodePath:void 0,scopeId:typeof e.scopeId==`string`?e.scopeId:void 0,branch:typeof e.branch==`string`?e.branch:void 0,attemptId:typeof e.attemptId==`string`?e.attemptId:void 0,attempt:typeof e.attempt==`number`?e.attempt:void 0,kind:typeof e.kind==`string`?e.kind:`ai-step`,title:typeof e.title==`string`?e.title:``,nodeId:typeof e.nodeId==`string`?e.nodeId:null,iteration:t,template:typeof e.template==`string`&&e.template?e.template:void 0,command:typeof e.command==`string`&&e.command?e.command:void 0},end:null,lastActivity:null}),typeof e.attemptId==`string`&&a.set(e.attemptId,o.length-1),i.push([]);continue}if(c.event_type===`loop_step_end`){let e=X(c.payload);if(!e||typeof e.index!=`number`)continue;for(let t=o.length-1;t>=0;t--)if(o[t].meta.index===e.index){o[t].end={index:e.index,nodeId:typeof e.nodeId==`string`?e.nodeId:null,status:e.status===`paused`?`paused`:e.status===`interrupted`?`interrupted`:e.status===`stalled`?`stalled`:e.status===`failed`?`failed`:`ok`,exitCode:typeof e.exitCode==`number`?e.exitCode:null,durationMs:typeof e.durationMs==`number`?e.durationMs:null,decision:e.decision===`continue`||e.decision===`stop`?e.decision:void 0,...e.reason===`idle_timeout`||e.reason===`provider_limit`?{reason:e.reason}:{},...typeof e.idleMs==`number`?{idleMs:e.idleMs}:{}};break}continue}let l=X(c.payload),u=l?.attemptId??(l?.event&&typeof l.event==`object`?l.event.attemptId:void 0),d=typeof u==`string`?a.get(u)??-1:-1,f=d>=0?d:u===void 0?o.length-1:-1,p=f>=0,m=tt(c,s);if(m&&!(p&&gt.test(m.content))&&i[f+1].push(m),p){let e=W(c);e.step&&e.actionKey&&(o[f].lastActivity={actionKey:e.actionKey,actionArg:e.actionArg})}}let s=e=>nt(rt(e)),c=s(i[0]),l=o.map((e,t)=>({key:`step-${t}-${e.meta.index}`,meta:e.meta,lines:s(i[t+1]),end:e.end,lastActivity:e.lastActivity})),u=c.length+l.reduce((e,t)=>e+t.lines.length,0);return{graphMeta:t,setup:c,segments:l,maxIteration:n,totalLines:u,...r?{completion:r}:{}}}function St(e,t){return e.end?e.end.status:t.isLast||e.meta.attemptId?t.jobSettled?`interrupted`:`running`:`unknown`}function Ct(e){return e===`continue`?0:e===`stop`?2:1}function wt(e){let t=new Map(e.nodes.map(e=>[e.id,e])),n=new Set,r=[],i=a=>{if(n.has(a))return;let o=t.get(a);if(!o)return;n.add(a),r.push(o);let s=e.edges.filter(e=>e.source===a).slice().sort((e,t)=>Ct(e.branch)-Ct(t.branch));for(let e of s)i(e.target)},a=e.nodes.find(e=>e.type===`start`);a&&i(a.id);for(let t of e.nodes)i(t.id);return r}function Tt(e){let t=e.data?.label;return typeof t==`string`&&t.trim()?t.trim():null}function Et(e,t){let n=e.segments.length-1,r=new Map,i=new Map;e.segments.forEach((e,t)=>{let n=bt(e);r.set(n,{seg:e,idx:t}),e.meta.kind===`decider`&&e.end?.decision&&i.set(n,e.end.decision)});let a=e=>{let r=St(e.seg,{isLast:e.idx===n,jobSettled:t.jobSettled});return r===`unknown`?`ok`:r===`stalled`?`failed`:r};if(e.graphMeta)return wt(e.graphMeta.graph).map(e=>{if(e.type===`start`)return{key:e.id,kind:`start`,label:Tt(e),state:`ok`,latestSegmentKey:null};if(e.type===`end`)return{key:e.id,kind:`end`,label:Tt(e),state:t.jobSettled?t.jobFailed?`failed`:`ok`:`pending`,latestSegmentKey:null};let n=r.get(e.id);return n?{key:e.id,kind:e.type,label:Tt(e)??yt(n.seg.meta),state:a(n),decision:e.type===`decider`?i.get(e.id):void 0,latestSegmentKey:n.seg.key}:{key:e.id,kind:e.type,label:Tt(e),state:`pending`,latestSegmentKey:null}});let o=[],s=new Map;return e.segments.forEach((e,t)=>{let n=bt(e),r={seg:e,idx:t},c=s.get(n),l=e.meta.kind===`decider`?i.get(n):void 0;if(c!=null){let t=o[c];t.state=a(r),t.decision=l,t.latestSegmentKey=e.key}else s.set(n,o.length),o.push({key:n,kind:e.meta.kind,label:yt(e.meta)||null,state:a(r),decision:l,latestSegmentKey:e.key})}),o}function Dt(e){if(!Number.isFinite(e)||e<0)return`—`;if(e<1e3)return`${Math.round(e)}ms`;let t=e/1e3;if(t<60)return`${t.toFixed(1)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}function Ot({topology:e,segments:t,settled:n,onFocus:r,onFork:i,forkBusy:a}){let{t:o}=l(`jobs`),s=I(),[c,u]=(0,G.useState)(!1),[d,f]=(0,G.useState)([]),[p,m]=(0,G.useState)(null),h=d[d.length-1]??{path:``,body:e},g=e=>h.path?`${h.path}/${e}`:e,_=t.filter(e=>(e.meta.nodePath??e.meta.nodeId)===p),v=(0,G.useMemo)(()=>{let e=h.body.nodes.flatMap(e=>Object.entries(e.ends).flatMap(([t,n])=>n===null?[]:[{id:`${e.id}:${t}`,source:e.id,target:n,label:t,markerEnd:{type:he.ArrowClosed}}])),r=new Map;for(let e of t){let t=e.meta.nodePath??e.meta.nodeId;if(!t)continue;let n=r.get(t)??new Map;n.set(e.meta.scopeId??`legacy`,e),r.set(t,n)}let i=h.body.nodes.map(e=>{let t=h.path?`${h.path}/${e.id}`:e.id,i=[...(r.get(t)??new Map).values()].map(e=>St(e,{isLast:!0,jobSettled:n})),a=[`running`,`paused`,`failed`,`stalled`,`interrupted`].find(e=>i.includes(e))??(i.length?`ok`:`pending`);return{id:e.id,type:`default`,position:{x:0,y:0},data:{kind:`core`,label:(0,K.jsxs)(`span`,{className:`block text-left`,children:[(0,K.jsx)(`strong`,{className:`block`,children:e.label}),(0,K.jsxs)(`span`,{className:`block text-[10px]`,children:[e.kind,` · `,o(`loopExplorer.graphState.${a}`)]})]})},style:{background:`var(--color-background)`,color:`var(--color-foreground)`,borderColor:a===`failed`?`var(--color-destructive)`:`var(--color-border)`}}});return i.sort((e,t)=>e.id===h.body.entry?-1:+(t.id===h.body.entry)),{nodes:_e(i,e,`vertical`),edges:e}},[h.body,h.path,t,n,o]),y=h.body.nodes.find(e=>g(e.id)===p),b=y?.component?e.components[y.component]:void 0;return(0,K.jsxs)(`details`,{className:`shrink-0 border-b border-border p-2`,onToggle:e=>u(e.currentTarget.open),children:[(0,K.jsx)(`summary`,{className:`cursor-pointer text-xs font-medium`,children:o(`loopExplorer.runtimeGraph`)}),c&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 py-2 text-xs`,children:[d.length>0&&(0,K.jsx)(O,{size:`sm`,variant:`ghost`,onClick:()=>{f(e=>e.slice(0,-1)),m(null)},children:o(`loopExplorer.graphBack`)}),(0,K.jsx)(`code`,{children:h.path||`/`})]}),(0,K.jsx)(`div`,{className:`h-72 rounded border border-border`,"aria-label":o(`loopExplorer.runtimeGraph`),children:(0,K.jsxs)(pe,{colorMode:s.scheme===`dark`?`dark`:`light`,nodes:v.nodes,edges:v.edges,nodesDraggable:!1,nodesConnectable:!1,edgesReconnectable:!1,deleteKeyCode:null,fitView:!0,minZoom:.1,onNodeClick:(e,t)=>m(g(t.id)),children:[(0,K.jsx)(me,{}),(0,K.jsx)(ge,{showInteractive:!1})]},h.path)}),p&&(0,K.jsxs)(`div`,{className:`space-y-2 py-2 text-xs`,children:[(0,K.jsx)(`code`,{className:`break-all`,children:p}),b&&d.length<16&&(0,K.jsx)(O,{size:`sm`,variant:`outline`,onClick:()=>{f(e=>[...e,{path:p,body:b}]),m(null)},children:o(`loopExplorer.graphOpenComponent`)}),_.length===0?(0,K.jsx)(`p`,{children:o(`loopExplorer.graphNoAttempts`)}):(0,K.jsx)(`ul`,{className:`max-h-40 space-y-1 overflow-auto`,children:_.map(e=>(0,K.jsxs)(`li`,{children:[(0,K.jsxs)(`button`,{className:`text-left underline underline-offset-2`,onClick:()=>r(e.key),children:[e.meta.scopeId??`/`,` · `,e.meta.attemptId??e.meta.index,` · `,o(`loopExplorer.graphState.${St(e,{isLast:!0,jobSettled:n})}`)]}),i&&e.end&&e.meta.nodePath&&e.meta.scopeId&&e.meta.iteration!=null&&(0,K.jsx)(O,{className:`ml-2`,size:`sm`,variant:`outline`,disabled:a,onClick:()=>i(e),children:o(`loopExplorer.repeatFromHere`)}),e.meta.traceId&&(0,K.jsxs)(`code`,{className:`block break-all text-[10px] text-muted-foreground`,children:[`traceId: `,e.meta.traceId,e.meta.spanId?` · spanId: ${e.meta.spanId}`:``]})]},e.key))})]})]})]})}function kt({result:e}){let{t}=l(`jobs`),{t:n}=l(`loops`),r=e.core,i=e=>t(`completion.status.${e}`,{defaultValue:e});return(0,K.jsxs)(`section`,{"aria-label":t(`completion.title`),className:`border-b border-border/40 px-4 py-3 text-xs space-y-2`,"data-testid":`loop-completion`,children:[(0,K.jsxs)(`p`,{className:`font-medium`,children:[t(`completion.execution`),`: `,i(e.execution)]}),e.completion?(0,K.jsxs)(`div`,{className:`space-y-1`,children:[(0,K.jsxs)(`p`,{className:e.completion.ok?`text-accent-success`:`text-accent-warning`,children:[n(`core.acceptance`),`: `,i(e.completion.ok?`complete`:`blocked`)]}),(0,K.jsxs)(`p`,{children:[n(`core.verified`),`: `,i(e.completion.verified?`verified`:`unverified`)]}),e.completion.reasons.map((e,t)=>(0,K.jsx)(`p`,{className:`text-foreground/70`,children:e},t))]}):r?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`dl`,{className:`grid grid-cols-2 gap-2 md:grid-cols-4`,children:[`implementation`,`validation`,`archive`,`delivery`].map(e=>(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`dt`,{className:`text-foreground/70`,children:t(`completion.${e}`)}),(0,K.jsx)(`dd`,{className:r.completion[e]===`with-exceptions`||r.completion[e]===`blocked`?`text-accent-warning font-medium`:`font-medium`,children:i(r.completion[e])})]},e))}),(0,K.jsxs)(`details`,{children:[(0,K.jsx)(`summary`,{className:`cursor-pointer`,children:t(`completion.evidence`)}),(0,K.jsxs)(`div`,{className:`space-y-2 pt-2 break-words`,children:[(0,K.jsx)(`p`,{className:`text-foreground/70`,children:t(`completion.snapshot`,{change:r.change,at:r.recordedAt})}),r.completion.reasons.map((e,t)=>(0,K.jsx)(`p`,{children:e},`reason-${t}`)),r.exceptions.map((e,n)=>(0,K.jsxs)(`div`,{children:[(0,K.jsx)(`p`,{className:`font-medium`,children:e.requirement}),(0,K.jsxs)(`p`,{children:[e.reason,` — `,e.impact]}),(0,K.jsxs)(`p`,{children:[t(`completion.acceptedBy`,{by:e.acceptedBy}),`: `,e.approvalEvidence]})]},`exception-${n}`)),r.checks.map((e,n)=>(0,K.jsxs)(`div`,{children:[(0,K.jsxs)(`p`,{className:`font-medium`,children:[e.name,`: `,i(e.status),` (`,t(e.required?`completion.required`:`completion.supplementary`),`)`]}),(0,K.jsxs)(`p`,{children:[e.scope,` — `,e.limitations]}),(0,K.jsx)(`p`,{className:`text-foreground/70`,children:e.evidence.join(`; `)})]},`check-${n}`)),r.findings.map((e,t)=>(0,K.jsx)(`p`,{children:e},`finding-${t}`)),r.phases.map(e=>(0,K.jsxs)(`p`,{children:[e.name,`: `,i(e.status),` · `,e.durationMs==null?t(`completion.unavailable`):`${(e.durationMs/1e3).toFixed(1)}s`,` · `,e.attempts==null?t(`completion.unavailable`):t(`completion.attempts`,{count:e.attempts})]},e.name)),(0,K.jsx)(`p`,{className:`text-foreground/70`,children:t(`completion.phaseCostUnavailable`)})]})]})]}):(0,K.jsx)(`p`,{className:`text-foreground/70`,children:t(`completion.noCoreEvidence`)})]})}var At={start:y,"ai-step":M,shell:U,decider:_,condition:_,end:oe},jt=b,Mt={start:`text-accent-success`,"ai-step":`text-accent-primary`,shell:`text-accent-warning`,decider:`text-accent-highlight`,condition:`text-accent-info`,end:`text-accent-secondary`},Nt={start:`border-accent-success/60`,"ai-step":`border-accent-primary/60`,shell:`border-accent-warning/60`,decider:`border-accent-highlight/60`,condition:`border-accent-info/60`,end:`border-accent-secondary/60`};function Pt(e){return At[e]??jt}function Ft({chips:e,iteration:t,onChipClick:n,variant:i}){let{t:o}=l(`jobs`);return e.length===0&&!t?null:(0,K.jsxs)(`div`,{"data-testid":`loop-overview-strip`,role:`list`,"aria-label":o(`loopExplorer.stepMapAria`),className:T(`flex items-center gap-1 overflow-x-auto border-b border-border/30 bg-surface/20`,i===`glass`?`px-3 py-1.5`:`px-4 py-2`),children:[e.map((e,t)=>{let i=Pt(e.kind),s=Mt[e.kind]??`text-foreground`,c=Nt[e.kind]??`border-border/40`,l=e.label??o(`loops:builder.nodes.${e.kind}`,{defaultValue:e.kind}),u=e.latestSegmentKey!=null;return(0,K.jsxs)(G.Fragment,{children:[t>0&&(0,K.jsx)(z,{className:`w-3 h-3 text-muted-foreground/30 shrink-0`}),(0,K.jsxs)(`button`,{type:`button`,role:`listitem`,"data-testid":`loop-node-chip`,"data-state":e.state,"data-kind":e.kind,"data-decision":e.decision,"aria-label":`${l} — ${e.state}`,disabled:!u,onClick:()=>e.latestSegmentKey&&n(e.latestSegmentKey),className:T(`relative flex items-center gap-1.5 shrink-0 rounded-full border bg-surface/40 px-2.5 py-1 text-[11px] transition-colors`,c,e.state===`pending`&&`opacity-45 border-border/40`,(e.state===`interrupted`||e.state===`paused`)&&`border-dashed border-accent-warning/50`,u?`cursor-pointer hover:bg-surface/70`:`cursor-default`),children:[e.state===`running`&&(0,K.jsx)(`span`,{"aria-hidden":!0,className:`absolute -inset-px rounded-full ring-2 ring-accent-primary/50 motion-safe:animate-pulse pointer-events-none`}),(0,K.jsx)(i,{className:T(`w-3 h-3 shrink-0`,s)}),(0,K.jsx)(`span`,{className:T(`max-w-[120px] truncate font-medium text-foreground/90`,e.state===`running`&&`title-shimmer`),children:l}),e.state===`paused`&&(0,K.jsx)(`span`,{className:`text-accent-warning`,children:o(`loopExplorer.paused`)}),e.state===`ok`&&(0,K.jsx)(h,{className:`w-3 h-3 text-accent-success shrink-0`}),e.state===`failed`&&(0,K.jsx)(w,{className:`w-3 h-3 text-destructive shrink-0`}),e.decision===`continue`&&(0,K.jsx)(r,{className:`w-3 h-3 text-accent-highlight shrink-0`}),e.decision===`stop`&&(0,K.jsx)(a,{className:`w-3 h-3 text-accent-success shrink-0`})]})]},e.key)}),t&&(0,K.jsxs)(`span`,{"data-testid":`loop-iteration-chip`,className:`ml-auto flex items-center gap-1.5 shrink-0 rounded-full border border-accent-highlight/40 bg-accent-highlight/10 px-2.5 py-1 text-[10px] font-medium text-accent-highlight tabular-nums`,children:[(0,K.jsx)(V,{className:`w-3 h-3`}),t.limit==null?o(`loopExplorer.iterationBadge`,{count:t.current}):o(`loopExplorer.iteration`,{current:t.current,limit:t.limit})]})]})}var It=(0,G.memo)(Ft);function Lt({className:e}){return(0,K.jsxs)(`span`,{className:T(`relative flex h-2 w-2 shrink-0`,e),children:[(0,K.jsx)(`span`,{className:`motion-safe:animate-ping absolute inline-flex h-full w-full rounded-full bg-accent-primary opacity-60`}),(0,K.jsx)(`span`,{className:`relative inline-flex rounded-full h-2 w-2 bg-accent-primary`})]})}function Rt(e,t){if(!t)return e;let n=t.toLowerCase();return e.filter(e=>e.content.toLowerCase().includes(n))}function zt(e,t,n,r){return e.length===0?(0,K.jsx)(`p`,{className:`px-4 py-2 text-[10px] text-muted-foreground/40 italic`,children:n(t?`logViewer.noMatchingLines`:`logViewer.noOutput`)}):e.map((e,t)=>(0,K.jsx)(ut,{line:e,even:t%2==0,onOpenTicket:r},e.id))}function Bt({label:e,value:t,copyLabel:n}){let[r,i]=(0,G.useState)(!1),a=async()=>{try{await navigator.clipboard.writeText(t),i(!0),window.setTimeout(()=>i(!1),1500)}catch{}};return(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`text-[9px] font-semibold uppercase tracking-wider text-muted-foreground/50`,children:e}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>void a(),"aria-label":`${n} — ${e}`,title:n,className:`p-0.5 text-muted-foreground/40 hover:text-foreground transition-colors cursor-pointer`,children:r?(0,K.jsx)(h,{className:`w-2.5 h-2.5 text-accent-success`}):(0,K.jsx)(R,{className:`w-2.5 h-2.5`})})]}),(0,K.jsx)(`pre`,{className:`mt-0.5 text-[10px] font-mono leading-relaxed text-foreground/75 whitespace-pre-wrap break-words`,children:t})]})}function Vt({segment:e,status:t,collapsed:n,filter:r,onToggle:i,onCopy:a,setRef:o,onOpenTicket:s}){let{t:c}=l(`jobs`),{meta:u,lines:d,end:f,lastActivity:p}=e,m=Pt(u.kind),g=Mt[u.kind]??`text-foreground`,_=Rt(d,r),v=t===`running`,y=!!(u.template||u.command),[b,x]=(0,G.useState)(!1);return(0,K.jsxs)(`div`,{ref:t=>o(e.key,t),"data-testid":`loop-step-section`,"data-status":t,"data-step-index":u.index,className:T(`mt-3 rounded-md overflow-hidden border animate-in fade-in duration-200`,t===`running`&&`border-accent-primary/40`,t===`failed`&&`border-destructive/30`,t===`stalled`&&`border-dashed border-destructive/40`,(t===`interrupted`||t===`paused`)&&`border-dashed border-accent-warning/40`,(t===`ok`||t===`unknown`)&&`border-border/20`),children:[(0,K.jsxs)(`div`,{className:T(`flex items-stretch bg-primary/5 border-b`,t===`failed`||t===`stalled`?`border-destructive/20`:`border-primary/20`),children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>i(e.key),className:`flex items-center gap-2 flex-1 min-w-0 text-left px-3 py-2 hover:bg-primary/10 transition-colors duration-150 cursor-pointer`,children:[(0,K.jsx)(z,{className:T(`w-3 h-3 text-primary/60 shrink-0 transition-transform duration-150`,!n&&`rotate-90`)}),(0,K.jsx)(`span`,{className:`text-[10px] font-mono tabular-nums text-muted-foreground/60 shrink-0 w-5 text-right`,children:u.index}),(0,K.jsx)(m,{className:T(`w-3.5 h-3.5 shrink-0`,g)}),(0,K.jsx)(`span`,{className:`text-[12px] font-semibold text-foreground leading-none truncate`,children:yt(u)}),u.branch&&(0,K.jsx)(`span`,{className:`max-w-40 truncate font-mono text-[10px] text-muted-foreground`,title:u.scopeId,children:u.branch}),t===`paused`&&(0,K.jsx)(`span`,{className:`text-[10px] text-accent-warning`,children:c(`loopExplorer.paused`,{defaultValue:`Paused`})}),u.iteration!=null&&u.iteration>=1&&(0,K.jsx)(`span`,{className:`shrink-0 rounded-full bg-muted/60 px-1.5 py-0.5 text-[9px] font-medium text-muted-foreground tabular-nums`,children:c(`loopExplorer.iterationBadge`,{count:u.iteration})}),v&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0 shrink-0 max-w-[40%]`,children:[(0,K.jsx)(Lt,{}),p&&(0,K.jsx)(`span`,{className:`title-shimmer text-[10px] truncate`,children:c(`statusPanel.activity.${p.actionKey}`,{arg:p.actionArg??``})})]}),t===`ok`&&(0,K.jsx)(h,{className:`w-3.5 h-3.5 text-accent-success shrink-0`}),t===`failed`&&f?.reason===`provider_limit`&&(0,K.jsx)(`span`,{className:`shrink-0 rounded border border-dashed border-destructive/50 px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-wide text-destructive`,title:c(`loopExplorer.providerLimitHint`),"data-testid":`loop-step-provider-limit`,children:c(`loopExplorer.providerLimit`)}),t===`failed`&&(0,K.jsx)(w,{className:`w-3.5 h-3.5 text-destructive shrink-0`}),t===`stalled`&&(0,K.jsx)(`span`,{className:`shrink-0 rounded border border-dashed border-destructive/50 px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-wide text-destructive`,title:f?.idleMs==null?void 0:c(`loopExplorer.stalledIdle`,{count:Math.max(1,Math.round(f.idleMs/6e4))}),children:c(`loopExplorer.stalled`)}),t===`interrupted`&&(0,K.jsx)(`span`,{className:`shrink-0 rounded border border-dashed border-accent-warning/50 px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-wide text-accent-warning`,children:c(`loopExplorer.interrupted`)}),(0,K.jsx)(`span`,{className:`flex-1`}),f?.durationMs!=null&&(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground/50 font-mono tabular-nums shrink-0`,children:Dt(f.durationMs)}),t===`failed`&&f?.exitCode!=null&&f.exitCode!==0&&(0,K.jsx)(`span`,{className:`text-[10px] text-destructive/70 font-mono shrink-0`,children:c(`activeJob.exitCode`,{code:f.exitCode})}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:c(`logViewer.phaseLines`,{count:d.length})})]}),y&&(0,K.jsx)(`button`,{type:`button`,onClick:()=>x(e=>!e),"aria-label":c(`loopExplorer.stepDetail`),"aria-expanded":b,title:c(`loopExplorer.stepDetail`),className:T(`px-2 flex items-center transition-colors cursor-pointer`,b?`text-foreground bg-primary/10`:`text-muted-foreground/40 hover:text-foreground hover:bg-primary/10`),children:(0,K.jsx)(B,{className:`w-3 h-3`})}),(0,K.jsx)(`button`,{type:`button`,onClick:()=>a(e.key),"aria-label":c(`loopExplorer.copyStep`),title:c(`loopExplorer.copyStep`),className:`px-2.5 flex items-center text-muted-foreground/40 hover:text-foreground hover:bg-primary/10 transition-colors cursor-pointer`,children:(0,K.jsx)(R,{className:`w-3 h-3`})})]}),b&&y&&(0,K.jsxs)(`div`,{"data-testid":`loop-step-detail`,className:T(`px-4 py-2.5 space-y-2.5 bg-muted/10 border-b animate-in fade-in duration-150`,t===`failed`?`border-destructive/20`:`border-primary/10`),children:[u.template&&(0,K.jsx)(Bt,{label:c(`loopExplorer.stepDetailTemplate`),value:u.template,copyLabel:c(`loopExplorer.copyCommand`)}),u.command&&(0,K.jsx)(Bt,{label:c(`loopExplorer.stepDetailCommand`),value:u.command,copyLabel:c(`loopExplorer.copyCommand`)})]}),!n&&(0,K.jsx)(`div`,{className:`bg-muted/5`,children:zt(_,r,c,s)})]})}var Ht=(0,G.memo)(Vt,(e,t)=>e.segment.key===t.segment.key&&e.segment.lines.length===t.segment.lines.length&&e.segment.lines[e.segment.lines.length-1]?.content===t.segment.lines[t.segment.lines.length-1]?.content&&e.segment.meta.template===t.segment.meta.template&&e.segment.meta.command===t.segment.meta.command&&e.segment.end?.status===t.segment.end?.status&&e.segment.end?.durationMs===t.segment.end?.durationMs&&e.segment.end?.decision===t.segment.end?.decision&&e.segment.end?.exitCode===t.segment.end?.exitCode&&e.segment.lastActivity?.actionKey===t.segment.lastActivity?.actionKey&&e.segment.lastActivity?.actionArg===t.segment.lastActivity?.actionArg&&e.status===t.status&&e.collapsed===t.collapsed&&e.filter===t.filter&&e.onOpenTicket===t.onOpenTicket),Ut=`__setup__`;function Wt({lines:e,collapsed:t,filter:n,onToggle:r,setRef:i,onOpenTicket:a}){let{t:o}=l(`jobs`),s=Rt(e,n);return(0,K.jsxs)(`div`,{ref:e=>i(Ut,e),"data-testid":`loop-setup-section`,className:`rounded-md overflow-hidden border border-border/20`,children:[(0,K.jsxs)(`button`,{type:`button`,onClick:()=>r(Ut),className:`flex items-center gap-2 w-full text-left px-3 py-2 bg-muted/10 border-b border-border/20 hover:bg-muted/20 transition-colors duration-150 cursor-pointer`,children:[(0,K.jsx)(z,{className:T(`w-3 h-3 text-muted-foreground/60 shrink-0 transition-transform duration-150`,!t&&`rotate-90`)}),(0,K.jsx)(y,{className:`w-3.5 h-3.5 text-accent-success/70 shrink-0`}),(0,K.jsx)(`span`,{className:`text-[11px] font-semibold text-muted-foreground leading-none uppercase tracking-wide`,children:o(`loopExplorer.setup`)}),(0,K.jsx)(`span`,{className:`flex-1`}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground/40 shrink-0`,children:o(`logViewer.phaseLines`,{count:e.length})})]}),!t&&(0,K.jsx)(`div`,{className:`bg-muted/5`,children:zt(s,n,o,a)})]})}var Gt=(0,G.memo)(Wt,(e,t)=>e.lines.length===t.lines.length&&e.lines[e.lines.length-1]?.content===t.lines[t.lines.length-1]?.content&&e.collapsed===t.collapsed&&e.filter===t.filter&&e.onOpenTicket===t.onOpenTicket);function Kt(e,t){let{t:n}=l(`jobs`),[r,i]=(0,G.useState)(!1),[a,o]=(0,G.useState)(``),[s,c]=(0,G.useState)(null),u=`${t??`active`}:${e??``}`,f=(0,G.useRef)(u),p=(0,G.useRef)(!1);f.current=u,(0,G.useEffect)(()=>(f.current=u,i(!1),o(``),c(null),p.current=!1,()=>{f.current=``}),[u]);async function m(r){if(!e||p.current||!r.meta.nodePath||!r.meta.scopeId||!r.meta.iteration)return;let a=u;p.current=!0,i(!0),o(``);try{let i=`${t?k(t):d()}/loop-runs/${encodeURIComponent(e)}`,o=await fetch(`${i}/recovery`,{cache:`no-store`});if(!o.ok)throw Error(n(`loopExplorer.forkFailed`));let s=await o.json();if(f.current!==a)return;if(s.forkAdopted&&s.forkRunId){c(s.forkRunId);return}let l={fromNodePath:r.meta.nodePath,scopeId:r.meta.scopeId,visit:r.meta.iteration};if(s.forkRequest&&(s.forkRequest.fromNodePath!==l.fromNodePath||s.forkRequest.scopeId!==l.scopeId||s.forkRequest.visit!==l.visit))throw Error(n(`loopExplorer.forkPending`));let u=s.forkRequest??{...l,requestId:crypto.randomUUID()},p=await fetch(`${i}/fork`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(u)}),m=await p.json();if(!p.ok||!m.loopRunId)throw Error(m.detail??n(`loopExplorer.forkFailed`));f.current===a&&c(m.loopRunId)}catch(e){f.current===a&&o(e instanceof Error?e.message:n(`loopExplorer.forkFailed`))}finally{f.current===a&&(p.current=!1,i(!1))}}return{busy:r,error:a,created:s,fork:m}}function qt(){return(0,K.jsxs)(`span`,{className:`relative flex h-1.5 w-1.5 shrink-0`,children:[(0,K.jsx)(`span`,{className:`motion-safe:animate-ping absolute inline-flex h-full w-full rounded-full bg-accent-primary opacity-60`}),(0,K.jsx)(`span`,{className:`relative inline-flex rounded-full h-1.5 w-1.5 bg-accent-primary`})]})}function Jt({events:e,jobStatus:t,isLoading:n,variant:r=`page`,projectId:i,onOpenRun:a}){let{t:o,i18n:s}=l(`jobs`),[c,u]=(0,G.useState)(``),[d,m]=(0,G.useState)(`follow`),[h,g]=(0,G.useState)(new Set),_=(0,G.useRef)(null),v=(0,G.useRef)(new Map),y=et(i),{activeProjectId:b}=f(),x=Kt(e[0]?.job_id,i??b??void 0),C=(0,G.useMemo)(()=>xt(e),[e,s.language]),w=t!=null&&t!==`running`&&t!==`queued`,E=t===`running`,D=(0,G.useMemo)(()=>C.segments.map((e,t)=>St(e,{isLast:t===C.segments.length-1,jobSettled:w})),[C,w]),k=(0,G.useMemo)(()=>{let e=C.segments.map(e=>e.key);return C.setup.length>0&&e.push(Ut),e},[C]),ee=C.segments.length>0?C.segments[C.segments.length-1].key:Ut,A=(0,G.useMemo)(()=>c?new Set(k):d===`follow`?new Set([ee]):h,[c,d,ee,h,k]),j=(0,G.useRef)(A);j.current=A;let M=(0,G.useRef)(C);M.current=C;let P=(0,G.useCallback)(e=>{let t=new Set(j.current);e?.(t),g(t),m(`manual`)},[]),F=(0,G.useCallback)(e=>{P(t=>{t.has(e)?t.delete(e):t.add(e)})},[P]),I=(0,G.useCallback)(e=>{P(t=>t.add(e)),requestAnimationFrame(()=>{v.current.get(e)?.scrollIntoView?.({behavior:`smooth`,block:`start`})})},[P]),L=(0,G.useCallback)(()=>{let e=_.current;e&&(e.scrollTop=e.scrollHeight)},[]),z=(0,G.useCallback)(()=>{m(`follow`),requestAnimationFrame(L)},[L]),te=(0,G.useCallback)(()=>{g(new Set(k)),m(`manual`)},[k]),B=(0,G.useCallback)(()=>{g(new Set),m(`manual`)},[]);(0,G.useEffect)(()=>{d===`follow`&&!c&&L()},[C.totalLines,C.segments.length,d,c,L]);let ne=(0,G.useCallback)(()=>{let e=_.current;!e||d!==`follow`||e.scrollHeight-e.scrollTop-e.clientHeight>80&&P()},[d,P]),re=(0,G.useCallback)((e,t)=>{t?v.current.set(e,t):v.current.delete(e)},[]),ie=(0,G.useCallback)(e=>{let t=M.current.segments.find(t=>t.key===e),n=e===`__setup__`?M.current.setup.map(e=>e.content).join(`
17
- `):(t?.lines??[]).map(e=>e.content).join(`
18
- `);navigator.clipboard.writeText(n).then(()=>p.success(o(`loopExplorer.copied`))).catch(()=>p.error(o(`logViewer.copyFailed`)))},[o]),ae=(0,G.useCallback)(()=>{let e=M.current,t=e.setup.map(e=>e.content);for(let n of e.segments){t.push(`── Step ${n.meta.index} · ${vt(n.meta.title)} ──`);for(let e of n.lines)t.push(e.content)}navigator.clipboard.writeText(t.join(`
19
- `)).then(()=>p.success(o(`logViewer.copySuccess`))).catch(()=>p.error(o(`logViewer.copyFailed`)))},[o]),V=(0,G.useMemo)(()=>Et(C,{jobSettled:w,jobFailed:t===`failed`}),[C,w,t]),H=C.graphMeta?.iterationLimit??C.graphMeta?.graph.config.maxIterations??null,oe=C.maxIteration>0?{current:C.maxIteration,limit:H}:null,U=(0,G.useMemo)(()=>{if(!c)return C.totalLines;let e=c.toLowerCase(),t=C.setup.filter(t=>t.content.toLowerCase().includes(e)).length;for(let n of C.segments)t+=n.lines.filter(t=>t.content.toLowerCase().includes(e)).length;return t},[c,C]),W=C.segments[C.segments.length-1],se=E&&(C.segments.length===0||W?.end!=null);return n?(0,K.jsx)(`div`,{className:`flex-1 flex items-center justify-center h-full`,children:(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`logViewer.loading`)})}):C.totalLines===0&&C.segments.length===0?(0,K.jsx)(`div`,{"data-testid":`loop-step-explorer`,className:`flex-1 flex items-center justify-center h-full`,children:(0,K.jsxs)(`p`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[E&&(0,K.jsx)(qt,{}),o(E?`loopExplorer.waiting`:`logViewer.empty`)]})}):(0,K.jsxs)(`div`,{"data-testid":`loop-step-explorer`,className:`relative flex min-h-0 flex-col h-full`,children:[(0,K.jsxs)(`div`,{className:T(`border-b border-border flex items-center gap-2`,r===`glass`?`px-3 py-1.5`:`px-4 py-2`),children:[(0,K.jsxs)(`div`,{className:`relative flex-1 max-w-xs`,children:[(0,K.jsx)(S,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground`}),(0,K.jsx)(N,{placeholder:o(`logViewer.filterPlaceholder`),value:c,onChange:e=>u(e.target.value),className:`pl-7 h-7`})]}),(0,K.jsx)(O,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:te,"aria-label":o(`loopExplorer.expandAll`),title:o(`loopExplorer.expandAll`),children:(0,K.jsx)(xe,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(O,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:B,"aria-label":o(`loopExplorer.collapseAll`),title:o(`loopExplorer.collapseAll`),children:(0,K.jsx)(be,{className:`w-3.5 h-3.5`})}),d===`follow`&&E&&(0,K.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[10px] text-accent-primary shrink-0`,children:[(0,K.jsx)(qt,{}),o(`loopExplorer.follow`)]}),(0,K.jsx)(`span`,{className:`flex-1`}),(0,K.jsx)(O,{variant:`ghost`,size:`sm`,className:`h-7 px-2 text-muted-foreground/50 hover:text-foreground`,onClick:ae,"aria-label":o(`logViewer.copySuccess`),children:(0,K.jsx)(R,{className:`w-3.5 h-3.5`})}),(0,K.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:o(`logViewer.lineCount`,{filtered:U,total:C.totalLines})})]}),C.completion&&(0,K.jsx)(`div`,{"data-testid":`loop-completion-scroll`,className:r===`glass`?`max-h-[45%] min-h-0 shrink-0 overflow-y-auto overscroll-contain`:void 0,tabIndex:r===`glass`?0:void 0,children:(0,K.jsx)(kt,{result:C.completion})}),C.graphMeta?.runtimeTopology&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Ot,{topology:C.graphMeta.runtimeTopology,segments:C.segments,settled:w,onFocus:I,onFork:x.fork,forkBusy:x.busy}),x.error&&(0,K.jsx)(`p`,{role:`alert`,className:`px-2 text-xs text-destructive`,children:x.error}),x.created&&(0,K.jsxs)(`div`,{className:`p-2 text-xs`,children:[(0,K.jsx)(`p`,{children:o(`loopExplorer.forkCreated`)}),(0,K.jsx)(O,{size:`sm`,variant:`outline`,onClick:()=>a?.(x.created),disabled:!a,children:o(`loopExplorer.openFork`)}),(0,K.jsx)(`code`,{className:`ml-2`,children:x.created})]})]}),(0,K.jsx)(It,{chips:V,iteration:oe,onChipClick:I,variant:r}),(0,K.jsxs)(`div`,{ref:_,onScroll:ne,className:`min-h-0 flex-1 overflow-y-auto p-2 text-xs`,children:[C.setup.length>0&&(0,K.jsx)(Gt,{lines:C.setup,collapsed:!A.has(`__setup__`),filter:c,onToggle:F,setRef:re,onOpenTicket:y}),C.segments.map((e,t)=>(0,K.jsx)(Ht,{segment:e,status:D[t],collapsed:!A.has(e.key),filter:c,onToggle:F,onCopy:ie,setRef:re,onOpenTicket:y},e.key)),se&&(0,K.jsxs)(`div`,{"data-testid":`loop-waiting-row`,className:`mt-3 flex items-center gap-2 px-3 py-2 text-[11px] text-muted-foreground/70 italic`,children:[(0,K.jsx)(qt,{}),o(`loopExplorer.waiting`)]})]}),d===`manual`&&E&&!c&&(0,K.jsxs)(`button`,{type:`button`,"data-testid":`resume-follow-pill`,onClick:z,className:`absolute bottom-4 left-1/2 -translate-x-1/2 z-10 flex items-center gap-1.5 rounded-full glass-card border border-accent-primary/30 px-3 py-1.5 text-[11px] font-medium text-foreground shadow-lg hover:border-accent-primary/60 transition-colors cursor-pointer animate-in fade-in slide-in-from-bottom-2 duration-200`,children:[(0,K.jsx)(qt,{}),o(`loopExplorer.resumeFollow`)]})]})}var Yt=new Set(`grep.rg.ag.ack.find.fd.ls.cat.head.tail.sed.awk.cut.sort.uniq.wc.jq.yq.tr.xargs.tee.column.less.more.cd.pwd.echo.printf.which.type.test.true.false.env.export.set.source.date.basename.dirname.realpath.readlink.stat.file.tree.diff.sleep.seq.hostname.whoami.uname.mkdir.rmdir.cp.mv.rm.touch.ln.chmod.chown.install.[[.[.]].].for.while.until.if.then.else.elif.fi.do.done.case.esac.exec.eval.trap.read.shift.wait`.split(`.`)),Xt=new Set([`status`,`diff`,`log`,`show`,`branch`,`rev-parse`,`ls-files`,`blame`,`describe`]),Zt=new Set([...Xt,`commit`,`add`,`stage`,`push`,`pull`,`fetch`,`checkout`,`switch`,`merge`,`rebase`,`reset`,`stash`,`tag`,`clone`,`worktree`,`cherry-pick`,`restore`,`apply`,`init`,`remote`,`config`,`update-ref`,`for-each-ref`]),Qt=new Set([`run`,`run-script`,`test`,`install`,`ci`,`i`,`add`,`exec`,`start`,`dlx`]),$t=[[/^(test|tests|test:.*|vitest|jest|spec)$/,`activity.testing`],[/^(build|compile|bundle|dist)$/,`activity.building`],[/^(typecheck|tsc|types?)$/,`activity.typechecking`],[/^(lint|lint:.*|eslint|format|fmt|prettier)$/,`activity.linting`]],en=new Set([`vitest`,`jest`,`pytest`,`mocha`,`ava`,`rspec`,`phpunit`]);function tn(e){for(let[t,n]of $t)if(t.test(e))return n;return null}function nn(e){return e.split(/\s+/).map(e=>e.replace(/^['"`]+/,``).replace(/['"`]+$/,``)).filter(e=>e.length>0&&!e.startsWith(`-`))}function rn(e){let t=nn(e);if(t.length===0)return{kind:`plumbing`};let n=t[0].split(`/`).pop()??t[0],r=t.slice(1);if(Yt.has(n))return{kind:`plumbing`};if(en.has(n))return{kind:`intent`,code:`activity.testing`};if((n===`npx`||n===`pnpm`||n===`yarn`||n===`bunx`)&&r.length>0){let e=r[0]===`dlx`||r[0]===`exec`?r[1]??``:r[0];if(en.has(e))return{kind:`intent`,code:`activity.testing`};let t=tn(e===`run`?r[r.indexOf(`run`)+1]??``:e);if(t)return{kind:`intent`,code:t};if(e===`tsc`)return{kind:`intent`,code:`activity.typechecking`}}if(n===`npm`||n===`yarn`||n===`pnpm`||n===`bun`){let e=r.findIndex(e=>Qt.has(e)),t=e===-1?``:r[e];if(t===`install`||t===`ci`||t===`i`||t===`add`)return{kind:`intent`,code:`activity.installing`};let i=tn(t===`run`||t===`run-script`?r[e+1]??``:t);return i?{kind:`intent`,code:i}:{kind:`named`,tool:n}}if(n===`git`){let e=r.find(e=>Zt.has(e))??``;return Xt.has(e)?{kind:`plumbing`}:e===`commit`||e===`add`||e===`stage`?{kind:`intent`,code:`activity.savingWork`}:{kind:`named`,tool:n}}if(n===`cargo`||n===`go`||n===`dotnet`||n===`mvn`||n===`mvnw`||n===`gradle`||n===`gradlew`){let e=r.find(e=>e===`test`||e===`build`||e===`compile`)??``;return e===`test`?{kind:`intent`,code:`activity.testing`}:e===`build`||e===`compile`?{kind:`intent`,code:`activity.building`}:{kind:`named`,tool:n}}return n===`tsc`?{kind:`intent`,code:`activity.typechecking`}:n===`openspec`?{kind:`intent`,code:`activity.checkingSpec`}:{kind:`named`,tool:n}}function an(e){try{let t=JSON.parse(e);return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}catch{return{}}}function on(e,t){return e&&/^main-\d+$/.test(e)?`step.role.work`:e===`verify`?`step.role.verify`:e===`decide`||t===`decider`?`step.role.decide`:e===`fix`?`step.role.fix`:null}function sn(e){return e.replace(/^[^\p{L}\p{N}(]+/u,``).trim()}var Z=e=>typeof e==`number`&&Number.isFinite(e)?e:null,Q=e=>typeof e==`string`&&e.length>0?e:null,cn=new Set([`thinking`,`reasoning`]),ln=/^(MEMORY\.md|confidence-score\.json|design-confidence\.json|\d{4}-\d{2}-\d{2}-.+|feedback_.+)$/,un=/^(proposal|design|tasks|spec|context-bundle)\.md$/,dn=new Set([`reading`,`writing`,`editing`]);function $(e,t,n,r,i,a=``){for(let t=e.length-1;t>=0;t--){let o=e[t];if(o.values.phaseBoundary===1)break;if(o.kind!==`activity`){if(o.stepIndex!==n)break;continue}if(o.stepIndex!==n)break;if((o.values.repository??``)===a&&o.values.action===r&&o.values.target===i){o.values.repeats=Number(o.values.repeats??1)+1;return}}e.push({seq:t,kind:`activity`,code:r===`intent`?i:i?`activity.${r}`:`activity.${r}Bare`,values:{action:r,target:i,repeats:1,repository:a},stepIndex:n,tone:`neutral`})}var fn=new Set([`architect`,`developer`,`fixer`,`verify`,`reviewer`,`archive`]),pn=3;function mn(e,t,n,r,i,a=``){for(let t=e.length-1;t>=0;t--){let o=e[t];if(o.values.phaseBoundary===1||o.stepIndex!==n)break;if(o.kind!==`activity`||(o.values.repository??``)!==a||o.values.action!==r||o.values.fileGroup!==1)continue;let s=String(o.values.allNames??``).split(`\0`).filter(Boolean),c=!!i&&!s.includes(i);c&&s.push(i),o.values.allNames=s.join(`\0`),o.values.files=s.length;let l=String(o.values.names??``).split(`, `).filter(Boolean);c&&l.length<pn&&(l.push(i),o.values.names=l.join(`, `)),o.code=s.length>1?`activity.${r}Files`:i?`activity.${r}`:`activity.${r}Bare`,o.values.repeats=s.length>1?1:Number(o.values.repeats??1)+1;return}e.push({seq:t,kind:`activity`,code:i?`activity.${r}`:`activity.${r}Bare`,values:{action:r,target:i,names:i,allNames:i,repository:a,files:+!!i,fileGroup:1,repeats:1},stepIndex:n,tone:`neutral`})}function hn({events:e,settled:t}){let n=[],r=new Map,i=new Set,a=null,o=!1,s=!1,c=e.some(e=>e.event_type===`workflow-event`);for(let t of e){if(t.event_type===`loop_graph`){o=!0;continue}if(t.event_type===`loop_step`){let e=an(t.payload),i=Z(e.index);if(i===null)continue;o=!0;let s=Q(e.kind)??`ai-step`,l={index:i,title:sn(Q(e.title)??``),roleCode:c?null:on(Q(e.nodeId),s),kind:s,iteration:Z(e.iteration),ended:!1};r.set(i,l),a=i;let u=Z(e.attempt);n.push({seq:t.seq,kind:`step-start`,code:u!==null&&u>1?`step.startResume`:l.iteration&&l.iteration>1?`step.startRetry`:`step.start`,values:{step:i,title:l.title,iteration:l.iteration??1,...u!==null&&u>1?{attempt:u}:{},...l.roleCode?{roleCode:l.roleCode}:{}},stepIndex:i,tone:`neutral`});continue}if(t.event_type===`loop_step_end`){let e=an(t.payload),i=Z(e.index);if(i===null)continue;let a=i===null?void 0:r.get(i);a&&(a.ended=!0);let o=Q(e.status),s=Z(e.durationMs),c=Z(e.exitCode),l=Z(e.idleMs),u=o===`stalled`,d=o===`failed`||u,f=o===`failed`&&Q(e.reason)===`provider_limit`;n.push({seq:t.seq,kind:`step-end`,code:e.recovered===!0&&o===`ok`?`step.recovered`:u?`step.stalled`:f?`step.providerLimit`:d?`step.failed`:s===null?`step.done`:s>=9e4?`step.doneTimedMin`:`step.doneTimed`,values:{step:i,title:a?.title??``,seconds:s===null?0:Math.max(1,Math.round(s/1e3)),minutes:s===null?0:Math.max(1,Math.round(s/6e4)),...u?{idleMinutes:l===null?0:Math.max(1,Math.round(l/6e4))}:{},...a?.roleCode?{roleCode:a.roleCode}:{},...c===null?{}:{exitCode:c}},stepIndex:i,tone:d?`bad`:`good`});let p=Q(e.decision);(p===`continue`||p===`stop`)&&n.push({seq:t.seq,kind:`decision`,code:p===`continue`?`decision.another`:`decision.satisfied`,values:{step:i},stepIndex:i,tone:p===`continue`?`neutral`:`good`});continue}if(t.event_type===`runtime-efficiency-event`){let e=an(t.payload),r=e.payload&&typeof e.payload==`object`&&!Array.isArray(e.payload)?e.payload:{},o=Q(e.eventId),s=Q(e.kind);if(e.schemaVersion!==1||!o||i.has(o))continue;i.add(o);let c=Q(r.label),l=Q(r.repositoryId);if(!c||!l||c.length>256||l.length>256)continue;let u=s===`check-started`?`started`:s===`check-reused`?`reused`:s===`check-invalidated`?`invalidated`:s===`check-finished`&&typeof r.exitCode==`number`?r.exitCode===0?`passed`:`failed`:null;u&&n.push({seq:t.seq,kind:`activity`,code:`activity.check.${u}`,values:{target:c,repository:l},stepIndex:a,tone:u===`failed`?`bad`:`neutral`});continue}if(t.event_type===`workflow-event`){let e=an(t.payload),r=e.event&&typeof e.event==`object`&&!Array.isArray(e.event)?e.event:{},i=Q(r.type),o=Q(r.stepId);if(i===`workflow_resumed`)s=!1,n.push({seq:t.seq,kind:`activity`,code:`activity.phase.resumed`,values:{phaseBoundary:1},stepIndex:a,tone:`neutral`});else if(i===`step_started`&&o&&fn.has(o)){let e=o===`developer`&&s;o===`developer`&&(s=!0),n.push({seq:t.seq,kind:`activity`,code:e?`activity.phase.corrections`:`activity.phase.${o}`,values:{phaseBoundary:1},stepIndex:a,tone:`neutral`})}else i===`step_succeeded`&&o===`verify`&&typeof r.message!=`string`||i===`step_blocked`||(i===`workflow_failed`||i===`workflow_blocked`||i===`workflow_cancelled`)&&n.push({seq:t.seq,kind:`activity`,code:`activity.phase.stopped`,values:{action:`intent`,target:Q(r.message)??i,repeats:1},stepIndex:a,tone:`bad`});continue}let e=t.event_type===`agent-event`?an(t.payload):{},l=Array.isArray(e.repositories)?e.repositories.map(e=>typeof e?.name==`string`?e.name:``).filter(Boolean).join(` + `):``,u=W(t);if(!(!u.step||!u.actionKey)&&!cn.has(u.actionKey)&&!(c&&u.actionKey===`working`)){if(c&&u.actionKey===`searching`){$(n,t.seq,a,`searching`,``,l);continue}if(u.actionKey===`running`){let e=se(t),r=e?rn(e):{kind:`named`,tool:u.actionArg??``};if(r.kind===`plumbing`){$(n,t.seq,a,`exploring`,``,l);continue}if(r.kind===`intent`){$(n,t.seq,a,`intent`,r.code,l);continue}$(n,t.seq,a,`running`,c?``:r.tool,l);continue}if(dn.has(u.actionKey)){let e=u.actionArg??``;if(ln.test(e)){$(n,t.seq,a,`intent`,`activity.bookkeeping`,l);continue}if(un.test(e)){$(n,t.seq,a,`intent`,`activity.writingSpec`,l);continue}mn(n,t.seq,a,u.actionKey,e,l);continue}$(n,t.seq,a,u.actionKey,u.actionArg??``,l)}}if(t)for(let e of r.values())e.ended||n.push({seq:2**53-1-(1e3-e.index),kind:`step-interrupted`,code:`step.interrupted`,values:{step:e.index,title:e.title},stepIndex:e.index,tone:`bad`});return{milestones:n,stepCount:r.size,plainJob:!o}}var gn={"step-start":Se,"step-end":h,"step-interrupted":C,decision:x,activity:Se},_n={neutral:`text-muted-foreground`,good:`text-accent-success`,bad:`text-accent-warning`};function vn({events:e,settled:t,durationRange:n,elapsedMs:r,variant:i=`page`}){let{t:a}=l(`narration`),o=(0,G.useMemo)(()=>hn({events:e,settled:t}),[e,t]),s=(0,G.useMemo)(()=>e.some(e=>e.event_type===`workflow-event`),[e]),c=(0,G.useMemo)(()=>[...o.milestones].sort((e,t)=>e.seq-t.seq),[o.milestones]);return(0,K.jsxs)(`div`,{className:i===`glass`?`flex h-full flex-col overflow-hidden`:`flex flex-col`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 border-b border-border/50 px-3 py-2 text-[11px] text-muted-foreground`,children:[typeof r==`number`&&r>0?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,K.jsx)(Ce,{className:`size-3`,"aria-hidden":!0}),a(`waiting.elapsed`,{minutes:Math.max(1,Math.round(r/6e4))})]}):null,n?(0,K.jsx)(`span`,{"data-testid":`narration-range`,children:a(`waiting.range`,{low:Math.max(1,Math.round(n.p25Ms/6e4)),high:Math.max(1,Math.round(n.p75Ms/6e4)),count:n.sampleCount})}):null,(0,K.jsx)(`span`,{className:`ml-auto italic opacity-70`,children:a(`aiNote`)})]}),(0,K.jsx)(`ol`,{className:`flex-1 space-y-1 px-3 py-2 ${i===`glass`?`overflow-y-auto`:``}`,"data-testid":`narration-list`,children:c.length===0?(0,K.jsx)(`li`,{className:`py-6 text-center text-xs text-muted-foreground`,children:a(t?`emptySettled`:`emptyLive`)}):c.map((e,t)=>{let n=gn[e.kind],r=e.kind===`step-start`||e.kind===`step-end`||e.kind===`step-interrupted`,i=Number(e.values.files??0)>1||s?1:Number(e.values.repeats??1);return(0,K.jsxs)(`li`,{className:`flex items-start gap-2 text-sm ${r||e.values.phaseBoundary===1?`font-medium text-foreground`:`text-muted-foreground`} ${e.kind===`step-start`&&t>0?`pt-2`:``}`,children:[(0,K.jsx)(n,{className:`mt-0.5 size-3.5 shrink-0 ${_n[e.tone]}`,"aria-hidden":!0}),(0,K.jsxs)(`span`,{className:`min-w-0 break-words`,children:[typeof e.values.repository==`string`&&e.values.repository&&(0,K.jsx)(`span`,{className:`mr-2 inline-block rounded border border-border px-1.5 py-0.5 text-xs font-medium text-foreground`,children:e.values.repository}),e.kind===`step-start`&&typeof e.values.roleCode==`string`?a(e.code,{...e.values,title:a(e.values.roleCode),defaultValue:e.code}):a(e.code,{...e.values,defaultValue:e.code}),i>1?(0,K.jsx)(`span`,{className:`ml-1.5 text-[11px] opacity-70`,children:a(`repeats`,{count:i})}):null]})]},`${e.seq}-${e.code}-${t}`)})})]})}var yn=`specrails-desktop:job-log-mode`;function bn(){try{let e=localStorage.getItem(yn);return e===`log`||e===`narrated`?e:`narrated`}catch{return`narrated`}}function xn(e){try{localStorage.setItem(yn,e)}catch{}}function Sn(e,t){switch(t.type){case`turn-user`:return{...e,streaming:!0,accepting:!0,queued:t.queued?e.queued+1:e.queued};case`turn-done`:{let n=Math.max(0,e.queued-1);return{...e,totals:t.totals,queued:n,streaming:e.queued>0}}case`finalized`:return{...e,streaming:!1,finalizing:!1,accepting:!1,queued:0,totals:t.totals??e.totals};case`accepting`:return t.accepting?{...e,accepting:!0}:{...e,accepting:!1,streaming:!1,queued:0};case`finalize-request`:return{...e,finalizing:!0};case`finalize-reject`:return{...e,finalizing:!1};case`blocked`:return{...e,accepting:!1,streaming:!1};default:return e}}function Cn(){try{return c()}catch{return null}}function wn({jobId:e,projectId:t,settleMode:n,initialAcceptingTurns:r,pendingInterrupts:i,kind:a=`job`,variant:o=`page`,onFinalized:c}){let{t:u}=l(`jobs`),{t:f}=l(`loops`),[m,h]=(0,G.useState)(i??[]),[g,_]=(0,G.useState)(i?.length===1?i[0].id:``);(0,G.useEffect)(()=>{h(i??[]),_(i?.length===1?i[0].id:``)},[i]);let y=m.find(e=>e.id===g),b=y!==void 0&&y.kind!==`question`,x=n??`finalize`,S=()=>t?`${s}/api/projects/${t}`:d(),[C,w]=(0,G.useReducer)(Sn,{streaming:!1,queued:0,totals:null,accepting:r??!0,finalizing:!1}),[E,D]=(0,G.useState)(``),[k,ee]=(0,G.useState)(!1),M=(0,G.useRef)(null);(0,G.useEffect)(()=>{r!==void 0&&w({type:`accepting`,accepting:r})},[r]);let N=(0,G.useRef)(c);N.current=c;let F=Cn(),I=(0,G.useId)();(0,G.useEffect)(()=>{if(!F)return;let t=`interactive-composer-${e}-${I}`;return F.registerHandler(t,t=>{let n=t;if(n.jobId===e){if(n.type===`job.turn_user`)w({type:`turn-user`,queued:!!n.queued});else if(n.type===`job.turn_done`)w({type:`turn-done`,totals:n.totals});else if(n.type===`job.finalized`)w({type:`finalized`,totals:n.totals??null}),N.current?.();else if(n.type===`job.interactive`&&(w({type:`accepting`,accepting:!!n.acceptingTurns}),Array.isArray(n.pendingInterrupts))){let e=n.pendingInterrupts;h(e),_(e.length===1?e[0].id:``)}}}),()=>F.unregisterHandler(t)},[F,e,I]);let L=a===`loop-step`&&!C.accepting;async function R(t=!1){let n=E.trim();if(!(!n&&!t||k||L||m.length>0&&!y||b&&!t)){ee(!0);try{let r=await fetch(`${S()}/jobs/${e}/messages`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:n,...y?{interruptId:y.id}:{},...t?{approve:!0}:{}})});if(r.ok)D(``),y&&(h([]),_(``),w({type:`accepting`,accepting:!1})),requestAnimationFrame(()=>M.current?.focus());else if(r.status===409&&a===`loop-step`&&!m.length)w({type:`blocked`});else{let e=await r.json().catch(()=>({}));p.error(u(`detail.toast.sendFailed`),{description:e.error})}}catch{p.error(u(`detail.toast.networkError`))}finally{ee(!1)}}}async function z(){if(!C.finalizing){w({type:`finalize-request`});try{let t=await fetch(`${S()}/jobs/${e}/finalize`,{method:`POST`});if(t.ok)p.success(u(x===`finalize`?`detail.toast.finalizeScheduled`:a===`loop-step`?`detail.toast.wrapUpStepScheduled`:`detail.toast.wrapUpScheduled`));else if(t.status===409&&a===`loop-step`)w({type:`blocked`}),w({type:`finalize-reject`});else{let e=await t.json().catch(()=>({}));p.error(u(`detail.toast.finalizeFailed`),{description:e.error}),w({type:`finalize-reject`})}}catch{p.error(u(`detail.toast.networkError`)),w({type:`finalize-reject`})}}}let te=k||L||!E.trim()||b||m.length>0&&!y,B=u(`detail.interactive.working`);return(0,K.jsxs)(`div`,{"data-testid":`interactive-job-composer`,className:T(`shrink-0 border-t px-3 py-2 space-y-1.5`,`motion-safe:animate-in motion-safe:fade-in motion-safe:slide-in-from-bottom-2 motion-safe:duration-300`,o===`glass`?`border-border/30 bg-surface/30`:`border-border/40 bg-surface/40`),children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-[11px] text-muted-foreground`,children:[(0,K.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[L?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,K.jsx)(we,{className:`h-3 w-3 motion-safe:animate-pulse`}),u(`detail.interactive.waitingForStepShort`)]}):C.streaming?(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,K.jsx)(v,{className:`h-3 w-3 animate-spin text-accent-primary`}),(0,K.jsxs)(`span`,{className:`relative`,children:[B,(0,K.jsx)(`span`,{"aria-hidden":!0,className:`title-shimmer pointer-events-none absolute inset-0`,children:B})]})]}):(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-accent-success motion-safe:animate-pulse`}),u(`detail.interactive.ready`)]}),C.queued>0&&(0,K.jsx)(`span`,{className:`rounded-full border border-accent-info/30 bg-accent-info/10 px-1.5 py-px text-[10px] tabular-nums text-accent-info motion-safe:animate-in motion-safe:fade-in`,children:u(`detail.interactive.queued`,{count:C.queued})})]}),(0,K.jsxs)(`span`,{className:`flex shrink-0 items-center gap-3`,children:[C.totals&&(0,K.jsx)(`span`,{className:`tabular-nums`,children:u(`detail.interactive.liveTotals`,{turns:C.totals.num_turns??u(`completion.unavailable`),cost:C.totals.total_cost_usd?.toFixed(4)??u(`completion.unavailable`)})}),m.length?null:x===`finalize`?(0,K.jsxs)(de,{children:[(0,K.jsx)(j,{asChild:!0,children:(0,K.jsxs)(O,{variant:`outline`,size:`sm`,onClick:()=>void z(),disabled:C.finalizing,className:`h-7 border-accent-success/40 text-accent-success hover:bg-accent-success/10`,children:[(0,K.jsx)(P,{className:`mr-1.5 h-3.5 w-3.5`}),C.finalizing?u(`detail.finalizing`):u(`detail.finalizeJob`)]})}),(0,K.jsx)(A,{children:u(`detail.finalizeJobTooltip`)})]}):(0,K.jsxs)(de,{children:[(0,K.jsx)(j,{asChild:!0,children:(0,K.jsx)(`button`,{type:`button`,onClick:()=>void z(),disabled:C.finalizing||L,className:T(`text-[11px] underline-offset-2 transition-colors`,L?`cursor-not-allowed text-muted-foreground/40`:`text-muted-foreground hover:text-accent-success hover:underline`),children:C.finalizing?u(`detail.interactive.wrappingUp`):u(a===`loop-step`?`detail.interactive.wrapUpStep`:`detail.interactive.wrapUp`)})}),(0,K.jsx)(A,{children:u(a===`loop-step`?`detail.interactive.wrapUpStepTooltip`:`detail.interactive.wrapUpTooltip`)})]})]})]}),m.length>0&&(0,K.jsxs)(`div`,{className:`space-y-2 rounded-md border border-accent-warning/30 bg-accent-warning/5 p-3`,children:[(0,K.jsxs)(`label`,{className:`block text-sm`,children:[f(`core.selectInterrupt`),(0,K.jsxs)(`select`,{"aria-label":f(`core.selectInterrupt`),className:`mt-1 w-full rounded border border-border bg-background p-2`,value:g,onChange:e=>_(e.target.value),children:[(0,K.jsx)(`option`,{value:``,children:f(`core.selectInterrupt`)}),m.map(e=>(0,K.jsxs)(`option`,{value:e.id,children:[e.nodePath,` · `,f(`core.${e.kind===`question`?`answerQuestion`:`approval`}`)]},e.id))]})]}),y&&typeof y.value==`object`&&y.value!==null&&typeof y.value.prompt==`string`&&(0,K.jsx)(`p`,{className:`whitespace-pre-wrap text-sm`,children:String(y.value.prompt)}),b&&(0,K.jsx)(O,{onClick:()=>void R(!0),disabled:k||L,children:f(`core.approveContinue`)})]}),x===`auto`&&!m.length&&(0,K.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground/60`,children:u(L?`detail.interactive.waitingForStep`:`detail.interactive.autoHint`)}),(0,K.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,K.jsx)(`textarea`,{ref:M,value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(!e.shiftKey||e.metaKey||e.ctrlKey)&&(e.preventDefault(),R())},rows:2,placeholder:u(L?`detail.interactive.waitingForStepShort`:`detail.interactive.placeholder`),"aria-label":u(`detail.interactive.placeholder`),disabled:L,className:T(`flex-1 resize-none rounded-md border border-border/50 bg-background px-2.5 py-1.5 text-sm transition-opacity focus:outline-none focus:ring-2 focus:ring-ring`,L&&`opacity-60`)}),(0,K.jsxs)(de,{children:[(0,K.jsx)(j,{asChild:!0,children:(0,K.jsx)(`span`,{className:`shrink-0`,children:(0,K.jsxs)(O,{size:`sm`,onClick:()=>void R(),disabled:te,className:`h-9`,children:[(0,K.jsx)(H,{className:`mr-1.5 h-3.5 w-3.5`}),u(`detail.interactive.send`)]})})}),te&&!k&&(0,K.jsx)(A,{children:u(L?`detail.interactive.sendDisabledWaiting`:`detail.interactive.sendDisabledEmpty`)})]})]})]})}export{Jt as a,Le as c,vn as i,bn as n,at as o,xn as r,We as s,wn as t};
@@ -1 +0,0 @@
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{ht as i,ut as a}from"./TicketDetailModalContext-B-DySpKL.js";import{a as o,c as s,l as c,m as l}from"./useSharedWebSocket-BZMrX4jr.js";import{n as u}from"./createLucideIcon-Bjbbp_KS.js";import{a as d,s as f}from"./useDesktop-0unHDBJJ.js";import{a as p,i as ee,n as m,o as h,r as g,s as te,t as ne}from"./InteractiveJobComposer-B3H1YHr6.js";import{t as re}from"./loader-circle-DcygOQpC.js";import{t as ie}from"./x-CBMI9ejn.js";import{M as ae,N as oe,j as se}from"./dialog-xXB2q5HJ.js";import{t as _}from"./formatDistanceToNow-aBss1Nai.js";import{t as v}from"./button-Ccc9Dc-D.js";import{L as y,R as b,V as x}from"./index-C4Mv6tV6.js";import{n as ce,t as S}from"./job-time-BCL7wee9.js";var C=e(r(),1),w=e(t(),1),T=[1e3,2e3,4e3,8e3,16e3];function E(e,t){let[n,r]=(0,w.useState)(`connecting`),i=(0,w.useRef)(t);return i.current=t,(0,w.useEffect)(()=>{let t=!1,n=!1,a=null,c=0,l=null;async function u(){if(!(t||n||a)){n=!0;try{await s()}catch{}finally{n=!1}!t&&!a&&f()}}function d(){if(t)return;l!==null&&clearTimeout(l),r(`connecting`);let e=T[c++]??3e4;l=setTimeout(()=>{l=null,u()},e)}function f(){if(t||a)return;let n=o(),s;try{s=n?new WebSocket(e,[`specrails-desktop`,n]):new WebSocket(e)}catch{d();return}a=s,r(`connecting`),s.onopen=()=>{t||a!==s||(c=0,r(`connected`))},s.onmessage=e=>{if(!(t||a!==s))try{i.current(JSON.parse(e.data))}catch{}},s.onclose=()=>{t||a!==s||(a=null,d())}}let p=()=>{t||a||(l!==null&&clearTimeout(l),l=null,u())};return window.addEventListener(`online`,p),window.addEventListener(`focus`,p),f(),()=>{t=!0,window.removeEventListener(`online`,p),window.removeEventListener(`focus`,p),l!==null&&clearTimeout(l);let e=a;if(a=null,e){e.onopen=null,e.onmessage=null,e.onclose=null,e.onerror=null;try{e.close()}catch{}}}},[e]),{connectionStatus:n}}var D=n();function O({jobId:e,onClose:t,projectId:n}){let[r,o]=(0,w.useState)(e);(0,w.useEffect)(()=>{o(e)},[e]);let{t:s}=u(`jobs`),{t:T}=u(`narration`),O=(0,w.useCallback)(()=>n?`${c}/api/projects/${n}`:d(),[n]),[k,le]=(0,w.useState)(m),ue=(0,w.useCallback)(e=>{le(e),g(e)},[]),[A,j]=(0,w.useState)(null),[M,N]=(0,w.useState)([]),[P,F]=(0,w.useState)([]),[I,L]=(0,w.useState)({}),[R,z]=(0,w.useState)(!0),[B,V]=(0,w.useState)(!1),[H,U]=(0,w.useState)(!1),[W,G]=(0,w.useState)(!1);(0,w.useEffect)(()=>{async function e(){try{let e=await fetch(`${O()}/jobs/${r}`);if(e.status===404){V(!0);return}if(!e.ok)throw Error(`Failed to fetch job`);let t=await e.json();if(j(t.job),N(t.events),t.phaseDefinitions){F(t.phaseDefinitions);let e={};for(let n of t.phaseDefinitions)e[n.key]=`idle`;L(e)}}catch{V(!0)}finally{z(!1)}}e()},[r,O]);let K=(0,w.useCallback)(()=>{fetch(`${O()}/jobs/${r}`).then(e=>e.ok?e.json():null).then(e=>{e?.job&&j(e.job)}).catch(()=>{})},[r,O]),q=(0,w.useRef)([]),J=(0,w.useRef)(null),Y=(0,w.useCallback)(()=>{J.current=null;let e=q.current;e.length!==0&&(q.current=[],N(t=>{let n=[...t,...e];return n.length>1e4?n.slice(n.length-8e3):n}))},[]);(0,w.useEffect)(()=>()=>{J.current&&cancelAnimationFrame(J.current)},[]),E(i,(0,w.useCallback)(e=>{let t=e;if(t.type===`event`&&t.jobId===r){let e={id:Date.now(),job_id:r,seq:0,event_type:t.event_type,source:t.source,payload:t.payload,timestamp:t.timestamp};q.current.push(e),J.current||=requestAnimationFrame(Y)}else if(t.type===`log`&&t.processId===r){let e={id:Date.now(),job_id:r,seq:0,event_type:`log`,source:t.source,payload:JSON.stringify({line:t.line}),timestamp:t.timestamp};q.current.push(e),J.current||=requestAnimationFrame(Y)}else if(t.type===`job.finalized`&&t.jobId===r||t.type===`runtime.continuation`&&t.jobId===r||t.type===`job.interactive`&&t.jobId===r||(t.type===`loop.run_paused`||t.type===`loop.run_resumed`)&&t.loopRunId===r)K();else if(t.type===`phase`){let e=t.phase,n=t.state;L(t=>({...t,[e]:n}))}else if(t.type===`queue`){let e=t.jobs?.find(e=>e.id===r);e&&A&&j(t=>t&&{...t,status:e.status})}},[r,A,Y,K])),(0,w.useEffect)(()=>{function e(e){if(e.key===`Escape`){if(H){U(!1);return}t()}}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,H]);let X=A?b(A):`job`,Z=X===`loop-run`;async function de(){G(!0);try{let e=await y({projectId:n??null,jobId:r,kind:X});e.ok?(f.success(s(Z?`modal.toast.stopSignalSent`:`modal.toast.cancelSignalSent`),{description:s(Z?`modal.toast.stopSignalSentDescription`:`modal.toast.cancelSignalSentDescription`)}),K()):f.error(s(`modal.toast.cancelFailed`),{description:e.error})}finally{G(!1)}}let fe=A?.status===`running`,Q=A?ce(S(A)):null,{panelRef:$,panelStyle:pe,headerHandleProps:me,resizeHandles:he,isFloating:ge,guardBackdrop:_e}=ae();return(0,C.createPortal)((0,D.jsx)(x,{delayDuration:400,children:(0,D.jsxs)(`div`,{style:oe(),className:`fixed inset-0 z-[65] flex items-stretch justify-center p-[clamp(12px,2vmin,24px)]`,children:[(0,D.jsx)(`div`,{className:`absolute inset-0 bg-black/50 backdrop-blur-sm`,onClick:_e(t)}),(0,D.jsxs)(`div`,{ref:$,className:`relative w-full min-w-0 rounded-xl glass-card border border-border/30 flex flex-col animate-in fade-in zoom-in-95 duration-200 overflow-hidden`,style:pe,children:[(0,D.jsxs)(`div`,{...me,className:`flex items-center justify-between px-4 py-3 border-b border-border/30${ge?` cursor-grab active:cursor-grabbing`:``}`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[A&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`code`,{className:`text-xs font-mono text-foreground/80 truncate`,children:A.command}),(0,D.jsx)(`span`,{className:`text-[10px] text-muted-foreground shrink-0`,children:Q?_(Q,{addSuffix:!0,locale:l()}):`—`})]}),R&&(0,D.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:s(`common:states.loading`)})]}),(0,D.jsx)(`button`,{onClick:t,className:`h-7 w-7 shrink-0 flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-surface/50 transition-colors cursor-pointer`,children:(0,D.jsx)(ie,{className:`w-4 h-4`})})]}),A&&(0,D.jsx)(te,{onOpenRun:o,job:A,events:M,phases:I,phaseDefinitions:P,projectId:n,variant:`glass`,actions:fe?(0,D.jsxs)(v,{variant:`ghost`,size:`sm`,onClick:()=>U(!0),disabled:W,className:`h-7 text-destructive hover:text-destructive hover:bg-destructive/10`,children:[W&&(0,D.jsx)(re,{className:`w-3.5 h-3.5 mr-1.5 animate-spin`,"aria-hidden":!0}),s(Z?`dashboard:railControls.stop`:X===`interactive`?`common:actions.discard`:`common:actions.cancel`)]}):null}),(0,D.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden relative`,children:B?(0,D.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,D.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:s(`modal.notFound`)})}):a&&A?(0,D.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[(0,D.jsx)(`div`,{className:`flex items-center gap-1 border-b border-border/40 px-3 py-1.5`,children:[`narrated`,`log`].map(e=>(0,D.jsx)(`button`,{type:`button`,onClick:()=>ue(e),"aria-pressed":k===e,"data-testid":`modal-narration-mode-${e}`,className:`rounded-md px-2 py-0.5 text-[11px] font-medium transition-colors ${k===e?`bg-accent-primary/15 text-accent-primary`:`text-muted-foreground hover:bg-surface/60`}`,children:T(e===`narrated`?`modeNarrated`:`modeLog`)},e))}),(0,D.jsx)(`div`,{className:`min-h-0 flex-1 overflow-hidden`,children:k===`narrated`?(0,D.jsx)(ee,{events:M,settled:A.status!==`running`&&A.status!==`queued`,elapsedMs:A.duration_ms??null,variant:`glass`}):A.command.startsWith(`loop:`)?(0,D.jsx)(p,{events:M,jobStatus:A.status,isLoading:R,variant:`glass`,projectId:n,onOpenRun:o}):(0,D.jsx)(h,{events:M,isLoading:R,projectId:n})})]}):A?.command.startsWith(`loop:`)?(0,D.jsx)(p,{events:M,jobStatus:A.status,isLoading:R,variant:`glass`,projectId:n,onOpenRun:o}):(0,D.jsx)(h,{events:M,isLoading:R,projectId:n})}),!!A?.interactive&&A.status===`running`&&(0,D.jsx)(ne,{jobId:r,projectId:n,settleMode:A.interactiveSettleMode,initialAcceptingTurns:A.interactiveAcceptingTurns,pendingInterrupts:A.pendingInterrupts,kind:A.command.startsWith(`loop:`)?`loop-step`:`job`,variant:`glass`,onFinalized:K})]}),(0,D.jsx)(se,{handles:he}),H&&(0,D.jsxs)(`div`,{"data-testid":`job-cancel-confirm`,className:`absolute inset-0 z-10 flex items-center justify-center p-4`,children:[(0,D.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:()=>U(!1)}),(0,D.jsxs)(`div`,{className:`relative w-full max-w-sm rounded-xl glass-card border border-border/30 p-5 shadow-xl animate-in fade-in zoom-in-95 duration-150`,children:[(0,D.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:s(Z?`modal.stopRunConfirmTitle`:`modal.cancelConfirmTitle`)}),(0,D.jsx)(`p`,{className:`mt-1.5 text-sm text-muted-foreground`,children:s(Z?`modal.stopRunConfirmDescription`:`modal.cancelConfirmDescription`)}),(0,D.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,D.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>U(!1),children:s(`modal.keepRunning`)}),(0,D.jsx)(v,{variant:`destructive`,size:`sm`,onClick:()=>{U(!1),de()},children:s(Z?`modal.stopRun`:X===`interactive`?`common:actions.discard`:`modal.cancelJob`)})]})]})]})]})}),document.body)}export{O as JobDetailModal};
@@ -1 +0,0 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{d as r,n as i,u as a}from"./chunk-KS7C4IRE-DEKu087k.js";import{n as o,ut as s}from"./TicketDetailModalContext-B-DySpKL.js";import{m as ee,r as te}from"./useSharedWebSocket-BZMrX4jr.js";import{n as c}from"./createLucideIcon-Bjbbp_KS.js";import{a as l,r as ne,s as u}from"./useDesktop-0unHDBJJ.js";import{l as d}from"./MinimizedChatsContext-CNx_0bZu.js";import{a as f,c as re,i as ie,n as ae,o as p,r as oe,s as se,t as ce}from"./InteractiveJobComposer-B3H1YHr6.js";import{t as le}from"./download-CFHyyHcw.js";import{t as ue}from"./rotate-ccw-Wh4id13q.js";import{t as m}from"./utils-BC4DHlz2.js";import{t as de}from"./formatDistanceToNow-aBss1Nai.js";import{t as h}from"./button-Ccc9Dc-D.js";import{B as g,Et as _,H as v,L as fe,Rt as pe,z as y,zt as b}from"./index-C4Mv6tV6.js";import{t as me}from"./format-command-C0D9IPmV.js";var x=e(t(),1),S=n(),C=4;function he({tickets:e,onTicketClick:t}){let{t:n}=c(`jobs`),[r,i]=(0,x.useState)(!1);if(e.length===0)return null;let a=e.length>=C&&!r?e.slice(0,1):e,o=e.length-a.length;return(0,S.jsxs)(`div`,{className:`rounded-xl border border-border/40 bg-card/40 px-4 py-3 space-y-1.5`,children:[a.map(e=>(0,S.jsx)(w,{ticket:e,onClick:()=>t(e.id)},e.id)),o>0&&(0,S.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[n(`ticketHeader.showMore`,{count:o}),(0,S.jsx)(b,{className:`w-3 h-3`})]}),r&&e.length>=C&&(0,S.jsxs)(`button`,{type:`button`,onClick:()=>i(!1),className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[n(`ticketHeader.showLess`),(0,S.jsx)(d,{className:`w-3 h-3`})]})]})}function w({ticket:e,onClick:t}){let{t:n}=c(`jobs`),r=e.title==null,i=`inline-flex items-center px-1.5 py-0.5 rounded-md text-[11px] font-mono tabular-nums shrink-0`;return r?(0,S.jsx)(`div`,{className:`flex items-center gap-2 min-w-0`,children:(0,S.jsx)(`span`,{className:m(i,`text-muted-foreground bg-muted/20 select-none`),title:n(`ticketHeader.deletedTooltip`),children:n(`ticketHeader.deletedTicket`,{id:e.id})})}):(0,S.jsxs)(`button`,{type:`button`,onClick:t,className:`flex items-center gap-2 min-w-0 w-full text-left group`,title:e.title??void 0,children:[(0,S.jsxs)(`span`,{className:m(i,`text-accent-primary bg-accent-primary/10 group-hover:bg-accent-primary/20 transition-colors`),children:[`#`,e.id]}),(0,S.jsx)(`span`,{className:`text-lg font-semibold text-foreground truncate group-hover:text-accent-primary transition-colors`,children:e.title})]})}function T(){let{t:e}=c(`jobs`),{t}=c(`narration`),{id:n}=r(),{activeProjectId:d,projects:b}=ne(),C=b.find(e=>e.id===d)?.provider,w=a(),{openTicketDetail:T}=o(),[E,D]=(0,x.useState)(null),[O,k]=(0,x.useState)([]),[ge,A]=(0,x.useState)([]),[_e,j]=(0,x.useState)({}),[ve,M]=(0,x.useState)([]),[ye,N]=(0,x.useState)(!0),[be,P]=(0,x.useState)(!1),[F,xe]=(0,x.useState)(ae),[Se,I]=(0,x.useState)(null),Ce=(0,x.useCallback)(e=>{xe(e),oe(e)},[]),L=E?.command??null;(0,x.useEffect)(()=>{if(!s||F!==`narrated`||!d||!L)return;let e=!1,t=`command=${encodeURIComponent(L)}`;try{Promise.resolve(fetch(`${l()}/run-duration-range?${t}`)).then(e=>e&&e.ok?e.json():null).then(t=>{e||I(t?.range??null)}).catch(()=>{e||I(null)})}catch{I(null)}return()=>{e=!0}},[d,L,F]);let[R,z]=(0,x.useState)(!1),B=(0,x.useRef)(!1),V=(0,x.useRef)(null);(0,x.useEffect)(()=>{B.current=!1,V.current=null,z(!1)},[n]),(0,x.useEffect)(()=>{if(!n)return;let e=new AbortController;D(null),k([]),A([]),j({}),N(!0),P(!1);async function t(){try{let t=await fetch(`${l()}/jobs/${n}`,{signal:e.signal});if(t.status===404){P(!0);return}if(!t.ok)throw Error(`Failed to fetch job`);let r=await t.json();D(r.job),k(r.events)}catch(e){if(e.name===`AbortError`)return;P(!0)}finally{e.signal.aborted||N(!1)}}return t(),()=>e.abort()},[n,d]),(0,x.useEffect)(()=>{if(!E?.pipeline_id){M([]);return}let e=E.pipeline_id;fetch(`${l()}/pipelines/${e}`).then(e=>e.ok?e.json():null).then(e=>{e?.jobs&&M(e.jobs)}).catch(()=>{})},[E?.pipeline_id,E?.status]);let H=(0,x.useRef)(d);H.current=d;let U=(0,x.useRef)(null);U.current=E?.status??null;let W=(0,x.useRef)([]),G=(0,x.useRef)(null),K=(0,x.useCallback)(()=>{G.current=null;let e=W.current;e.length!==0&&(W.current=[],k(t=>{let n=[...t,...e];return n.length>1e4?n.slice(n.length-8e3):n}))},[]),q=(0,x.useCallback)(e=>{let t=W.current;t.push(e),t.length>1e4&&(W.current=t.slice(-8e3)),G.current||=requestAnimationFrame(K)},[K]);(0,x.useEffect)(()=>()=>{G.current&&cancelAnimationFrame(G.current)},[]);let J=(0,x.useCallback)(e=>{let t=e;if(!(H.current&&t.projectId&&t.projectId!==H.current)){if(t.type===`init`){let e=t.phaseDefinitions??[];A(e);let n={};for(let r of e)n[r.key]=t.phases?.[r.key]??`idle`;j(n)}else if(t.type===`event`&&t.jobId===n){let e={id:Date.now(),job_id:n??``,seq:t.seq??0,event_type:t.event_type,source:t.source,payload:t.payload,timestamp:t.timestamp};q(e)}else if(t.type===`log`&&t.processId===n){let e={id:Date.now(),job_id:n??``,seq:0,event_type:`log`,source:t.source,payload:JSON.stringify({line:t.line}),timestamp:t.timestamp};q(e)}else if(t.type===`job.finalized`&&t.jobId===n||t.type===`runtime.continuation`&&t.jobId===n||t.type===`job.interactive`&&t.jobId===n||(t.type===`loop.run_paused`||t.type===`loop.run_resumed`)&&t.loopRunId===n)fetch(`${l()}/jobs/${n}`).then(e=>e.json()).then(e=>D(e.job)).catch(()=>{});else if(t.type===`phase`){let e=t.phase,n=t.state;j(t=>({...t,[e]:n}))}else if(t.type===`queue`){let e=t.jobs?.find(e=>e.id===n);if(e){let t=e.status,r=U.current;D(e=>e&&{...e,status:t}),(t===`completed`||t===`failed`||t===`canceled`||t===`running`&&r!==`running`)&&fetch(`${l()}/jobs/${n}`).then(e=>e.json()).then(e=>D(e.job)).catch(()=>{})}}}},[n,q]),{registerHandler:Y,unregisterHandler:X}=te();(0,x.useEffect)(()=>(Y(`job-detail-${n}`,J),()=>X(`job-detail-${n}`)),[n,J,Y,X]),(0,x.useEffect)(()=>{if(!n||!E||E.status!==`running`||E.hasTelemetry)return;let e=setInterval(()=>{fetch(`${l()}/jobs/${n}`).then(e=>e.ok?e.json():null).then(e=>{e?.job?.hasTelemetry&&D(e=>e&&{...e,hasTelemetry:!0})}).catch(()=>{})},8e3);return()=>clearInterval(e)},[n,E?.status,E?.hasTelemetry]);async function we(){if(!n)return;let t=await fe({projectId:null,jobId:n});t.ok?u.success(e(`detail.toast.cancelSignalSent`),{description:e(`detail.toast.cancelSignalSentDescription`)}):t.httpStatus===null?u.error(e(`detail.toast.networkError`)):u.error(e(`detail.toast.failed`),{description:t.error})}async function Te(){if(E)try{let t=await fetch(`${l()}/jobs/${E.id}/diagnostic`);if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n.error??e(`detail.toast.exportFailedHttp`,{status:t.status}))}let n=await t.blob(),r=URL.createObjectURL(n),i=new Date().toISOString().slice(0,10),a=document.createElement(`a`);a.href=r,a.download=`specrails-diagnostic-${E.id}-${i}.zip`,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(r)}catch(t){u.error(e(`detail.toast.exportFailed`),{description:t.message})}}async function Ee(){if(!(!E||B.current)){B.current=!0,z(!0),V.current||=typeof globalThis.crypto?.randomUUID==`function`?globalThis.crypto.randomUUID():`rerun-${E.id}-${Date.now()}-${Math.random().toString(36).slice(2)}`;try{let t=await fetch(`${l()}/spawn`,{method:`POST`,headers:{"Content-Type":`application/json`,"Idempotency-Key":V.current},body:JSON.stringify({rerunOfJobId:E.id})}),n=await t.json();if(!t.ok)throw Error(n.error??e(`detail.toast.spawnFailed`));V.current=null,u.success(e(`detail.toast.jobRequeued`)),w(`/jobs/${n.jobId}`)}catch(e){u.error(e.message)}finally{B.current=!1,z(!1)}}}if(ye)return(0,S.jsx)(`div`,{className:`max-w-5xl mx-auto px-4 py-6`,children:(0,S.jsxs)(`div`,{className:`space-y-3`,children:[(0,S.jsx)(`div`,{className:`h-4 w-48 bg-muted/30 rounded animate-pulse`}),(0,S.jsx)(`div`,{className:`h-20 bg-muted/30 rounded-lg animate-pulse`}),(0,S.jsx)(`div`,{className:`h-64 bg-muted/30 rounded-lg animate-pulse`})]})});if(be||!E)return(0,S.jsxs)(`div`,{className:`max-w-5xl mx-auto px-4 py-6 flex flex-col items-center gap-3 mt-12`,children:[(0,S.jsx)(`p`,{className:`text-lg font-semibold`,children:e(`detail.notFound`)}),(0,S.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`detail.notFoundDescription`,{id:n})}),(0,S.jsx)(h,{asChild:!0,variant:`outline`,size:`sm`,children:(0,S.jsxs)(i,{to:`/`,children:[(0,S.jsx)(_,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.backToDashboard`)]})})]});let Z=E.status===`running`,De=E.status===`completed`||E.status===`failed`,Q=!!E.interactive,Oe=Q&&Z,ke=(E.tickets?.length??0)>0,$=E.command.startsWith(`loop:`),Ae=re(ve);return(0,S.jsxs)(`div`,{"data-job-detail-surface":!0,className:`flex flex-col h-full max-w-5xl mx-auto w-full`,children:[(0,S.jsxs)(`div`,{className:`px-4 pt-3 pb-2 space-y-2`,children:[(0,S.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,S.jsxs)(i,{to:`/`,className:`hover:text-foreground transition-colors flex items-center gap-1`,children:[(0,S.jsx)(_,{className:`w-3 h-3`}),e(`detail.breadcrumbDashboard`)]}),(0,S.jsx)(pe,{className:`w-3 h-3`}),(0,S.jsx)(`span`,{className:`text-foreground font-mono`,children:e(`detail.breadcrumbJob`,{id:n?.slice(0,8)})})]}),ke&&(0,S.jsx)(he,{tickets:E.tickets??[],onTicketClick:T}),(0,S.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-muted-foreground flex-wrap min-w-0`,children:[(0,S.jsx)(`code`,{className:m(`font-mono text-foreground/90 truncate`,ke?`text-xs text-muted-foreground`:`text-sm`),children:me(E.command,C)}),(0,S.jsx)(`span`,{children:E.started_at?e(`detail.startedAgo`,{timeAgo:de(new Date(E.started_at),{addSuffix:!0,locale:ee()})}):e(`detail.queuedWaiting`)}),E.model&&(0,S.jsx)(`span`,{className:`text-muted-foreground/40`,children:E.model})]})]}),(0,S.jsx)(se,{onOpenRun:e=>w(`/jobs/${e}`),job:E,events:O,phases:_e,phaseDefinitions:ge,projectId:d,variant:`page`,pipelineTotals:Ae,actions:(0,S.jsxs)(S.Fragment,{children:[E.hasTelemetry&&(0,S.jsxs)(y,{children:[(0,S.jsx)(v,{asChild:!0,children:(0,S.jsxs)(h,{variant:`outline`,size:`sm`,className:`h-7`,onClick:Te,"aria-label":e(`detail.exportDiagnosticAria`),children:[(0,S.jsx)(le,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.exportDiagnostic`)]})}),(0,S.jsx)(g,{children:e(`detail.exportDiagnosticTooltip`)})]}),De&&(0,S.jsxs)(y,{children:[(0,S.jsx)(v,{asChild:!0,children:(0,S.jsxs)(h,{variant:`outline`,size:`sm`,onClick:Ee,disabled:R,"aria-busy":R,className:`h-7`,children:[(0,S.jsx)(ue,{className:`w-3.5 h-3.5 mr-1.5`}),e(`detail.reExecute`)]})}),(0,S.jsx)(g,{children:e(`detail.reExecuteTooltip`)})]}),Z&&(0,S.jsxs)(y,{children:[(0,S.jsx)(v,{asChild:!0,children:(0,S.jsx)(h,{variant:`outline`,size:`sm`,onClick:we,className:`h-7 border-destructive/30 text-destructive hover:bg-destructive/10`,children:e(Q?`detail.cancelInteractive`:`detail.cancelJob`)})}),(0,S.jsx)(g,{children:e(`detail.cancelJobTooltip`)})]})]})}),(0,S.jsx)(`div`,{className:`flex-1 overflow-hidden relative`,children:s?(0,S.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,S.jsx)(`div`,{className:`flex items-center gap-1 border-b border-border/50 px-3 py-1.5`,children:[`narrated`,`log`].map(e=>(0,S.jsx)(`button`,{type:`button`,onClick:()=>Ce(e),"aria-pressed":F===e,"data-testid":`job-narration-mode-${e}`,className:`rounded-md px-2 py-0.5 text-[11px] font-medium transition-colors ${F===e?`bg-accent-primary/15 text-accent-primary`:`text-muted-foreground hover:bg-surface`}`,children:t(e===`narrated`?`modeNarrated`:`modeLog`)},e))}),(0,S.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:F===`narrated`?(0,S.jsx)(ie,{events:O,settled:E.status!==`running`&&E.status!==`queued`,durationRange:Se,elapsedMs:E.duration_ms??null,variant:`page`}):$?(0,S.jsx)(f,{events:O,jobStatus:E.status,variant:`page`,onOpenRun:e=>w(`/jobs/${e}`)}):(0,S.jsx)(p,{events:O})})]}):$?(0,S.jsx)(f,{events:O,jobStatus:E.status,variant:`page`,onOpenRun:e=>w(`/jobs/${e}`)}):(0,S.jsx)(p,{events:O})}),Oe&&(0,S.jsx)(ce,{jobId:E.id,settleMode:E.interactiveSettleMode,initialAcceptingTurns:E.interactiveAcceptingTurns,pendingInterrupts:E.pendingInterrupts,kind:E.command.startsWith(`loop:`)?`loop-step`:`job`,variant:`page`})]})}export{T as default};
@@ -1 +0,0 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{u as r}from"./chunk-KS7C4IRE-DEKu087k.js";import{l as i,m as a,r as o}from"./useSharedWebSocket-BZMrX4jr.js";import{n as s,t as c}from"./createLucideIcon-Bjbbp_KS.js";import{a as l,i as u,r as d,s as f}from"./useDesktop-0unHDBJJ.js";import{t as p}from"./circle-x-CMYsN4ZH.js";import{t as m}from"./trash-2-BOU3WdZZ.js";import{t as h}from"./triangle-alert-H9T4jAmh.js";import{t as g}from"./x-CBMI9ejn.js";import{M as _,a as v,i as y,j as b,l as x,o as ee,r as te,t as ne}from"./dialog-xXB2q5HJ.js";import{n as re,t as ie}from"./lib-CGdyxIWg.js";import{t as S}from"./formatDistanceToNow-aBss1Nai.js";import{t as C}from"./button-Ccc9Dc-D.js";import{B as w,Ft as T,H as E,It as D,S as ae,h as O,t as k,wt as oe,z as A}from"./index-C4Mv6tV6.js";import{t as j}from"./format-command-C0D9IPmV.js";import{t as M}from"./ExportDropdown-BcMpvV89.js";import{n as N,t as P}from"./job-time-BCL7wee9.js";var se=c(`git-compare-arrows`,[[`circle`,{cx:`5`,cy:`6`,r:`3`,key:`1qnov2`}],[`path`,{d:`M12 6h5a2 2 0 0 1 2 2v7`,key:`1yj91y`}],[`path`,{d:`m15 9-3-3 3-3`,key:`1lwv8l`}],[`circle`,{cx:`19`,cy:`18`,r:`3`,key:`1qljk2`}],[`path`,{d:`M12 18H7a2 2 0 0 1-2-2V9`,key:`16sdep`}],[`path`,{d:`m9 15 3 3-3 3`,key:`1m3kbl`}]]),F=e(t(),1),I=n();function L(e){if(e==null)return`—`;let t=Math.round(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function R(e){return e==null?`—`:e===0?`$0`:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(3)}`}function z(e){return e==null?`—`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function B({label:e,a:t,b:n,highlight:r}){return(0,I.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 py-2 border-b border-border/20 last:border-0 text-xs`,children:[(0,I.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,I.jsx)(`span`,{className:`font-mono text-right ${r===`a`?`text-emerald-400 aurora-light:text-accent-success font-semibold`:``}`,children:t}),(0,I.jsx)(`span`,{className:`font-mono text-right ${r===`b`?`text-emerald-400 aurora-light:text-accent-success font-semibold`:``}`,children:n})]})}function V(e,t,n=!0){return e==null||t==null||e===t?null:n?e<t?`a`:`b`:e>t?`a`:`b`}function ce({jobIds:e,onClose:t}){let{t:n}=s(`jobs`),[r,i]=(0,F.useState)(null),[a,o]=(0,F.useState)(!0),[c,u]=(0,F.useState)(null),{panelRef:d,panelStyle:f,headerHandleProps:m,resizeHandles:h,isFloating:v,guardBackdrop:y}=_();(0,F.useEffect)(()=>{let t=new AbortController;return fetch(`${l()}/jobs/compare?jobIds=${e.join(`,`)}`,{signal:t.signal}).then(e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}).then(e=>{i(e),o(!1)}).catch(e=>{e.name!==`AbortError`&&(u(e.message),o(!1))}),()=>t.abort()},[e]);function x(e,t){return(0,I.jsxs)(`div`,{className:`text-center space-y-1`,children:[(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground font-medium uppercase tracking-wider`,children:n(`comparison.jobN`,{n:t+1})}),(0,I.jsx)(`code`,{className:`text-[10px] text-foreground/70 block truncate max-w-[160px] mx-auto`,children:e.command}),(0,I.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-[10px]`,children:[e.status===`completed`?(0,I.jsx)(D,{className:`w-3 h-3 text-emerald-400 aurora-light:text-accent-success`}):(0,I.jsx)(p,{className:`w-3 h-3 text-rose-400 aurora-light:text-destructive`}),(0,I.jsx)(`span`,{className:`capitalize text-muted-foreground`,children:n(`statusLabel.${e.status}`,{defaultValue:e.status})})]}),(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground font-mono`,children:e.id.slice(0,8)})]})}return(0,I.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:y(t),children:[(0,I.jsxs)(`div`,{ref:d,className:`w-full max-w-lg rounded-xl border border-border/30 bg-popover p-5 shadow-xl space-y-4 mx-4`,onClick:e=>e.stopPropagation(),style:f,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between ${v?`cursor-grab active:cursor-grabbing`:``}`,...m,children:[(0,I.jsx)(`h2`,{className:`text-sm font-semibold`,children:n(`comparison.title`)}),(0,I.jsx)(`button`,{type:`button`,onClick:t,className:`text-muted-foreground hover:text-foreground transition-colors`,children:(0,I.jsx)(g,{className:`w-4 h-4`})})]}),a&&(0,I.jsx)(`div`,{className:`space-y-2`,children:[0,1,2,3].map(e=>(0,I.jsx)(`div`,{className:`h-8 bg-muted/20 rounded animate-pulse`},e))}),c&&(0,I.jsx)(`p`,{className:`text-xs text-red-400 aurora-light:text-destructive`,children:n(`comparison.loadFailed`,{error:c})}),r&&(()=>{let[e,t]=r.jobs,i=V(e.durationMs,t.durationMs,!0),a=V(e.totalCostUsd,t.totalCostUsd,!0),o=V(e.tokensOut==null?null:e.tokensOut,t.tokensOut==null?null:t.tokensOut,!0);return(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 pb-3 border-b border-border/30 mb-1`,children:[(0,I.jsx)(`div`,{}),x(e,0),x(t,1)]}),(0,I.jsx)(B,{label:n(`comparison.duration`),a:L(e.durationMs),b:L(t.durationMs),highlight:i}),(0,I.jsx)(B,{label:n(`comparison.cost`),a:R(e.totalCostUsd),b:R(t.totalCostUsd),highlight:a}),(0,I.jsx)(B,{label:n(`comparison.tokensOut`),a:z(e.tokensOut),b:z(t.tokensOut),highlight:o}),(0,I.jsx)(B,{label:n(`comparison.tokensIn`),a:z(e.tokensIn),b:z(t.tokensIn),highlight:null}),(0,I.jsx)(B,{label:n(`comparison.cacheRead`),a:z(e.tokensCacheRead),b:z(t.tokensCacheRead),highlight:null}),(0,I.jsx)(B,{label:n(`comparison.model`),a:e.model??`—`,b:t.model??`—`,highlight:null}),(0,I.jsx)(B,{label:n(`comparison.phasesDone`),a:e.phasesCompleted.length>0?e.phasesCompleted.join(`, `):`—`,b:t.phasesCompleted.length>0?t.phasesCompleted.join(`, `):`—`,highlight:null})]})})(),r&&(0,I.jsx)(`p`,{className:`text-[10px] text-muted-foreground/60 text-center`,children:n(`comparison.betterValueHint`)})]}),(0,I.jsx)(b,{handles:h})]})}var le={running:{variant:`running`,labelKey:`statusLabel.running`,tooltipKey:`statusTooltip.running`},completed:{variant:`success`,labelKey:`statusLabel.done`,tooltipKey:`statusTooltip.completed`},failed:{variant:`failed`,labelKey:`statusLabel.failed`,tooltipKey:`statusTooltip.failed`},canceled:{variant:`canceled`,labelKey:`statusLabel.canceled`,tooltipKey:`statusTooltip.canceled`},queued:{variant:`queued`,labelKey:`statusLabel.queued`,tooltipKey:`statusTooltip.queuedToRun`},zombie_terminated:{variant:`failed`,labelKey:`statusLabel.zombie`,tooltipKey:`statusTooltip.zombie`},skipped:{variant:`warning`,labelKey:`statusLabel.skipped`,tooltipKey:`statusTooltip.skipped`}},ue=[`running`,`completed`,`failed`,`canceled`,`zombie_terminated`,`queued`,`skipped`],de={critical:{className:`bg-red-500/15 aurora-light:bg-destructive/10 text-red-400 aurora-light:text-destructive border-red-500/30 aurora-light:border-destructive/30`,labelKey:`recent.priority.critical`},high:{className:`bg-orange-500/15 aurora-light:bg-accent-warning/10 text-orange-400 aurora-light:text-accent-warning border-orange-500/30 aurora-light:border-accent-warning/30`,labelKey:`recent.priority.high`},normal:{className:``,labelKey:`recent.priority.normal`},low:{className:`bg-gray-500/15 aurora-light:bg-muted text-gray-400 aurora-light:text-muted-foreground border-gray-500/30 aurora-light:border-border`,labelKey:`recent.priority.low`}};function fe(e){return e==null||e===0?null:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(3)}`}function pe(e,t){let n=N(e),r=N(t);if(!n||!r)return null;let i=r.getTime()-n.getTime();if(i<0)return null;let a=Math.round(i/1e3);if(a<60)return`${a}s`;let o=Math.floor(a/60),s=a%60;return o<60?`${o}m ${s}s`:`${Math.floor(o/60)}h ${o%60}m`}function me(e){return e==null||e===0?null:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function he(e){let t=N(e);return t?S(t,{addSuffix:!0,locale:a()}):`—`}function ge(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r).getTime()}function _e(e){let[t,n,r]=e.split(`-`).map(Number);return new Date(t,n-1,r+1).getTime()-1}function ve(e,t,n){if(!t&&!n)return!0;let r=N(e);if(!r)return!0;let i=r.getTime();return!(t&&i<ge(t)||n&&i>_e(n))}var H=10;function U({jobs:e,isLoading:t,error:n,onRetry:i,onJobsCleared:a,onProposalClick:o,onProposalDelete:c}){let{t:u}=s(`jobs`),p=r(),{activeProjectId:g,projects:re}=d(),ie=re.find(e=>e.id===g)?.provider,[S,D]=(0,F.useState)(null),[O,k]=(0,F.useState)(``),[M,N]=(0,F.useState)(``),[L,R]=(0,F.useState)(!1),[z,B]=(0,F.useState)(``),[V,U]=(0,F.useState)(``),[W,G]=(0,F.useState)(!1),[K,q]=(0,F.useState)(null),[J,ye]=(0,F.useState)(H),[Y,be]=(0,F.useState)(!1),[X,Z]=(0,F.useState)([]),[xe,Q]=(0,F.useState)(null),{panelRef:Se,panelStyle:Ce,headerHandleProps:we,resizeHandles:Te,isFloating:Ee,guardBackdrop:De}=_();(0,F.useEffect)(()=>{ye(H)},[e.length]);function Oe(){be(e=>!e),Z([])}function ke(e){Z(t=>{if(t.includes(e))return t.filter(t=>t!==e);if(t.length>=2)return t;let n=[...t,e];return n.length===2&&Q(n),n})}let $=e.filter(e=>S&&e.status!==S?!1:ve(P(e),O,M)),Ae=e.filter(e=>ve(P(e),z,V)).length;async function je(e){G(!0);try{let t={};e===`range`&&(z&&(t.from=new Date(ge(z)).toISOString()),V&&(t.to=new Date(_e(V)).toISOString()));let n=await fetch(`${l()}/jobs`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});if(n.ok){let e=await n.json();f.success(u(`recent.toast.cleared`,{count:e.deleted})),R(!1),B(``),U(``),a?.()}else f.error(u(`recent.toast.clearFailed`))}catch{f.error(u(`recent.toast.networkError`))}finally{G(!1)}}let Me=n?(0,I.jsxs)(`div`,{role:`alert`,"data-testid":`jobs-load-error`,className:`flex items-center gap-2 rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive`,children:[(0,I.jsx)(h,{className:`h-4 w-4 shrink-0`}),(0,I.jsx)(`span`,{className:`flex-1`,children:u(`recent.loadFailed`)}),i&&(0,I.jsx)(C,{type:`button`,variant:`outline`,size:`sm`,className:`h-7`,onClick:i,disabled:t,children:u(`common:actions.retry`)})]}):null;return n&&e.length===0?(0,I.jsx)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4`,children:Me}):t&&e.length===0?(0,I.jsx)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4 space-y-1`,children:[0,1,2].map(e=>(0,I.jsx)(`div`,{className:`h-9 bg-muted/30 rounded-md animate-pulse`},e))}):e.length===0?(0,I.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border/40 bg-card/50 p-8 text-center space-y-2`,children:[(0,I.jsx)(T,{className:`w-8 h-8 text-muted-foreground/30 mx-auto`}),(0,I.jsx)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:u(`recent.emptyTitle`)}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground/60`,children:u(`recent.emptyDescription`)})]}):(0,I.jsxs)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4 space-y-2`,children:[Me,(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,I.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,I.jsx)(`button`,{type:`button`,onClick:()=>D(null),className:`px-2 py-0.5 rounded text-[10px] font-medium transition-colors ${S===null?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-accent/50`}`,children:u(`recent.filterAll`,{count:e.length})}),ue.map(t=>{let n=e.filter(e=>e.status===t).length;return n===0?null:(0,I.jsx)(`button`,{type:`button`,onClick:()=>D(S===t?null:t),className:`px-2 py-0.5 rounded text-[10px] font-medium capitalize transition-colors ${S===t?`bg-accent text-foreground`:`text-muted-foreground hover:text-foreground hover:bg-accent/50`}`,children:u(`recent.filterStatus`,{status:u(`statusName.${t}`),count:n})},t)})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(`input`,{type:`date`,value:O,onChange:e=>k(e.target.value),className:`h-6 rounded border border-border bg-input px-1.5 text-[10px] text-foreground`,title:u(`recent.fromDate`)}),(0,I.jsx)(`input`,{type:`date`,value:M,onChange:e=>N(e.target.value),className:`h-6 rounded border border-border bg-input px-1.5 text-[10px] text-foreground`,title:u(`recent.toDate`)}),(O||M)&&(0,I.jsx)(`button`,{type:`button`,onClick:()=>{k(``),N(``)},className:`text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:u(`recent.clear`)}),(0,I.jsxs)(A,{children:[(0,I.jsx)(E,{asChild:!0,children:(0,I.jsx)(C,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 transition-colors ${Y?`text-foreground bg-accent`:`text-muted-foreground hover:text-foreground`}`,onClick:Oe,children:(0,I.jsx)(se,{className:`w-3.5 h-3.5`})})}),(0,I.jsx)(w,{children:u(Y?`recent.exitCompareMode`:`recent.compareTwoJobs`)})]}),(0,I.jsxs)(A,{children:[(0,I.jsx)(E,{asChild:!0,children:(0,I.jsx)(C,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-muted-foreground hover:text-destructive`,onClick:()=>R(!0),children:(0,I.jsx)(m,{className:`w-3.5 h-3.5`})})}),(0,I.jsx)(w,{children:u(`recent.clearJobs`)})]})]})]}),Y&&(0,I.jsxs)(`div`,{className:`flex items-center justify-between rounded-md bg-accent/40 px-3 py-1.5 text-[10px] text-muted-foreground`,children:[(0,I.jsxs)(`span`,{children:[X.length===0&&u(`recent.selectTwoToCompare`),X.length===1&&u(`recent.selectOneMore`),X.length===2&&u(`recent.readyToCompare`)]}),X.length===2&&(0,I.jsx)(`button`,{type:`button`,className:`text-[10px] font-medium text-foreground hover:underline`,onClick:()=>Q(X),children:u(`recent.compareAction`)})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-1 text-[10px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,I.jsx)(`span`,{className:`w-14`,children:u(`recent.colStatus`)}),(0,I.jsx)(`span`,{className:`flex-1 min-w-0`,children:u(`recent.colCommand`)}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,I.jsx)(`span`,{className:`w-14 text-right`,children:u(`recent.colDuration`)}),(0,I.jsx)(`span`,{className:`w-12 text-right`,children:u(`recent.colTokens`)}),(0,I.jsx)(`span`,{className:`w-12 text-right`,children:u(`recent.colCost`)}),(0,I.jsx)(`span`,{className:`w-20 text-right`,children:u(`recent.colStarted`)})]})]}),(0,I.jsx)(`div`,{className:`space-y-0.5`,children:$.slice(0,J).map(e=>{let t=le[e.status]??le.queued,n=fe(e.total_cost_usd),r=pe(e.started_at,e.finished_at),i=me((e.tokens_in??0)+(e.tokens_out??0)+(e.tokens_cache_read??0)+(e.tokens_cache_create??0)||null),a=e.id.startsWith(`proposal:`),s=a?e.id.replace(`proposal:`,``):null,c=X.includes(e.id),l=Y&&!a&&X.length===2&&!c,d=()=>{if(Y&&!a){ke(e.id);return}a&&s?o?.(s):p(`/jobs/${e.id}`)};return(0,I.jsxs)(`div`,{role:`button`,tabIndex:0,className:`flex items-center gap-3 px-3 py-2 rounded-md transition-colors cursor-pointer group ${c?`bg-accent/70 ring-1 ring-border`:l?`opacity-40 cursor-not-allowed`:`hover:bg-accent/50`}`,onClick:d,onKeyDown:e=>{e.target===e.currentTarget&&(e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),d()))},children:[(0,I.jsxs)(A,{children:[(0,I.jsx)(E,{asChild:!0,children:(0,I.jsx)(`div`,{children:(0,I.jsx)(ae,{variant:t.variant,children:u(t.labelKey)})})}),(0,I.jsx)(w,{children:u(t.tooltipKey)})]}),e.priority&&e.priority!==`normal`&&(0,I.jsx)(`span`,{className:`inline-flex items-center rounded px-1.5 py-0.5 text-[9px] font-medium border ${de[e.priority].className}`,children:u(de[e.priority].labelKey)}),e.profile_name&&(0,I.jsxs)(A,{children:[(0,I.jsx)(E,{asChild:!0,children:(0,I.jsx)(`span`,{className:`inline-flex items-center rounded px-1.5 py-0.5 text-[9px] font-medium border border-accent-primary/40 bg-accent-primary/10 text-accent-primary/90`,children:e.profile_name})}),(0,I.jsx)(w,{children:u(`recent.profileTooltip`,{name:e.profile_name})})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-1 flex-1 min-w-0`,children:[e.pipeline_id&&(0,I.jsxs)(A,{children:[(0,I.jsx)(E,{asChild:!0,children:(0,I.jsx)(oe,{className:`w-3 h-3 text-accent-primary/60 shrink-0`})}),(0,I.jsxs)(w,{children:[u(`recent.pipelinePart`),e.depends_on_job_id&&` ${u(`recent.pipelineDependsOn`)}`,e.skip_reason&&` — ${e.skip_reason}`]})]}),(0,I.jsx)(`code`,{className:`text-xs text-foreground/80 truncate`,children:j(e.command,ie)})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3 text-[10px] text-muted-foreground shrink-0`,children:[(0,I.jsx)(`span`,{className:`w-14 text-right`,children:r??`—`}),(0,I.jsx)(`span`,{className:`w-12 text-right`,children:i?`${i}`:`—`}),(0,I.jsx)(`span`,{className:`w-12 text-right`,children:n??`—`}),(0,I.jsx)(`span`,{className:`w-20 text-right`,children:e.status===`queued`?`—`:he(e.started_at)}),a&&s&&(0,I.jsx)(`button`,{type:`button`,className:`w-4 h-4 md:opacity-0 md:group-hover:opacity-100 text-muted-foreground hover:text-destructive transition-all`,onClick:e=>{e.stopPropagation(),q(s)},title:u(`recent.deleteProposal`),children:(0,I.jsx)(m,{className:`w-3 h-3`})})]})]},e.id)})}),$.length>J&&(0,I.jsx)(`div`,{className:`pt-1 text-center`,children:(0,I.jsx)(`button`,{type:`button`,onClick:()=>ye(e=>e+H),className:`text-[10px] text-muted-foreground hover:text-foreground transition-colors px-3 py-1 rounded hover:bg-accent/50`,children:u(`recent.loadMore`,{count:$.length-J})})}),L&&(0,I.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:De(()=>R(!1)),children:[(0,I.jsxs)(`div`,{ref:Se,className:`w-80 rounded-xl border border-border/30 bg-popover p-4 shadow-lg space-y-4`,onClick:e=>e.stopPropagation(),style:Ce,children:[(0,I.jsxs)(`div`,{...we,className:Ee?`cursor-grab active:cursor-grabbing`:void 0,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:u(`recent.clearModal.title`)}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:u(`recent.clearModal.jobsInHistory`,{count:e.length})})]}),(0,I.jsx)(C,{variant:`destructive`,size:`sm`,className:`w-full`,disabled:W,onClick:()=>je(`all`),children:u(`recent.clearModal.clearAll`,{count:e.length})}),(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:u(`recent.clearModal.orByRange`)}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(`input`,{type:`date`,value:z,onChange:e=>B(e.target.value),className:`flex-1 h-7 rounded-md border border-border bg-input px-2 text-xs text-foreground`,placeholder:u(`recent.clearModal.fromPlaceholder`)}),(0,I.jsx)(`input`,{type:`date`,value:V,onChange:e=>U(e.target.value),className:`flex-1 h-7 rounded-md border border-border bg-input px-2 text-xs text-foreground`,placeholder:u(`recent.clearModal.toPlaceholder`)})]}),(0,I.jsx)(C,{variant:`outline`,size:`sm`,className:`w-full`,disabled:W||!z&&!V,onClick:()=>je(`range`),children:z||V?u(`recent.clearModal.clearInRange`,{count:Ae}):u(`recent.clearModal.clearRange`)})]}),(0,I.jsx)(C,{variant:`ghost`,size:`sm`,className:`w-full`,onClick:()=>R(!1),children:u(`common:actions.cancel`)})]}),(0,I.jsx)(b,{handles:Te})]}),(0,I.jsx)(ne,{open:K!==null,onOpenChange:e=>!e&&q(null),children:(0,I.jsxs)(te,{className:`max-w-sm`,children:[(0,I.jsxs)(ee,{children:[(0,I.jsx)(x,{children:u(`recent.deleteProposalConfirm.title`)}),(0,I.jsx)(y,{children:u(`recent.deleteProposalConfirm.description`)})]}),(0,I.jsxs)(v,{children:[(0,I.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>q(null),children:u(`common:actions.cancel`)}),(0,I.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{K&&c?.(K),q(null)},children:u(`common:actions.delete`)})]})]})}),xe&&(0,I.jsx)(ce,{jobIds:xe,onClose:()=>{Q(null),Z([]),be(!1)}})]})}var W={input:`page.proposal.status.input`,exploring:`page.proposal.status.exploring`,review:`page.proposal.status.review`,refining:`page.proposal.status.refining`,creating_issue:`page.proposal.status.creatingIssue`,created:`page.proposal.status.created`,cancelled:`page.proposal.status.cancelled`};function G(e){return`${i}/api/projects/${encodeURIComponent(e)}`}function K(){let[e,t]=(0,F.useState)(!1),{registerHandler:n,unregisterHandler:r}=o(),{t:i}=s(`jobs`),{activeProjectId:a}=d(),{recentJobs:c}=k(a),{data:p,isFirstLoad:m,isLoading:h,error:g,refresh:_}=u({namespace:`jobs`,projectId:a,initialValue:c,fetcher:async({projectId:e,signal:t})=>{let n=await fetch(`${G(e)}/jobs?limit=10`,{signal:t});if(!n.ok)throw Error(`Failed to fetch jobs: ${n.status}`);return(await n.json()).jobs},pollInterval:1e4});(0,F.useEffect)(()=>(n(`jobs-runtime-continuation`,e=>{let t=e;t.type===`runtime.continuation`&&t.projectId===a&&_()}),()=>r(`jobs-runtime-continuation`)),[a,_,n,r]);let{data:y,isFirstLoad:b,isLoading:S,error:w,refresh:T}=u({namespace:`proposals`,projectId:a,initialValue:[],fetcher:async({projectId:e,signal:t})=>{let n=await fetch(`${G(e)}/propose?limit=10`,{signal:t});if(!n.ok)throw Error(`Failed to fetch proposals: ${n.status}`);return(await n.json()).proposals},pollInterval:1e4}),E={input:`queued`,exploring:`running`,review:`running`,refining:`running`,creating_issue:`running`,created:`completed`,cancelled:`canceled`},D=y.map(e=>({id:`proposal:${e.id}`,command:`/specrails:propose-feature ${e.idea.length>60?e.idea.slice(0,57)+`...`:e.idea}`,started_at:e.created_at,enqueued_at:e.created_at,status:E[e.status]??`queued`})),oe=[...p,...D].sort((e,t)=>(N(P(t))?.getTime()??0)-(N(P(e))?.getTime()??0)),[A,j]=(0,F.useState)(null),se=(0,F.useCallback)(async e=>{try{let t=await fetch(`${l()}/propose/${e}`);if(!t.ok)return;let n=await t.json();j(n.proposal)}catch{}},[]),L=(0,F.useCallback)(async e=>{try{(await fetch(`${l()}/propose/${e}`,{method:`DELETE`})).ok&&(f.success(i(`page.proposalDeleted`)),await T())}catch{}},[T,i]);return(0,I.jsxs)(`div`,{className:`max-w-4xl mx-auto px-4 py-6`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,I.jsx)(`h1`,{className:`text-sm font-semibold`,children:i(`page.title`)}),(0,I.jsx)(M,{baseUrl:`${l()}/jobs/export`,label:i(`page.exportJobs`)})]}),a&&(0,I.jsxs)(`details`,{className:`mb-4 rounded-lg border border-border`,onToggle:e=>t(e.currentTarget.open),children:[(0,I.jsx)(`summary`,{className:`cursor-pointer p-3 text-sm`,children:i(`agentRuntime:runs.title`)}),e&&(0,I.jsx)(O,{projectId:a})]}),(0,I.jsx)(U,{jobs:oe,isLoading:m||b||h||S,error:g??w,onRetry:()=>{Promise.all([_(),T()])},onJobsCleared:_,onProposalClick:se,onProposalDelete:L}),(0,I.jsx)(ne,{open:A!==null,onOpenChange:e=>!e&&j(null),children:(0,I.jsx)(te,{className:`max-w-3xl glass-card`,children:A&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(ee,{children:(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(x,{className:`flex-1 min-w-0`,children:i(`page.proposal.title`)}),(0,I.jsx)(ae,{variant:A.status===`created`?`success`:A.status===`cancelled`?`destructive`:`secondary`,children:i(W[A.status]??`page.proposal.status.unknown`,{status:A.status})})]})}),(0,I.jsx)(`div`,{className:`text-xs text-muted-foreground bg-muted/20 rounded px-2 py-1 italic`,children:A.idea}),A.result_markdown?(0,I.jsx)(`div`,{className:`max-h-[400px] overflow-y-auto rounded-lg px-3 py-2 text-xs bg-muted/40`,children:(0,I.jsx)(`div`,{className:`prose prose-invert prose-xs max-w-none prose-p:my-1 prose-headings:mt-2 prose-headings:mb-1 prose-headings:text-sm prose-headings:font-semibold prose-ul:my-1 prose-ol:my-1 prose-li:my-0 prose-code:text-cyan-300 prose-code:text-[10px] prose-code:bg-muted/40 prose-code:px-1 prose-code:py-0.5 prose-code:rounded text-foreground/80`,children:(0,I.jsx)(re,{remarkPlugins:[ie],children:A.result_markdown})})}):(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground py-4 text-center`,children:i(`page.proposal.noContent`)}),A.issue_url&&(0,I.jsxs)(`div`,{className:`text-xs`,children:[i(`page.proposal.githubIssue`),` `,(0,I.jsx)(`a`,{href:A.issue_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-accent-primary hover:underline`,children:A.issue_url})]}),(0,I.jsxs)(v,{children:[(0,I.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{L(A.id),j(null)},children:i(`common:actions.delete`)}),(0,I.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>j(null),children:i(`common:actions.close`)})]})]})})})]})}export{K as default};
@@ -1 +0,0 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{d as r,u as i}from"./chunk-KS7C4IRE-DEKu087k.js";import{n as a,t as o}from"./createLucideIcon-Bjbbp_KS.js";import{a as s,r as c,s as l}from"./useDesktop-0unHDBJJ.js";import{n as u,t as d}from"./save-B6wGWwBR.js";import{t as f}from"./git-branch-BRM0F5GN.js";import{n as p,t as m}from"./square-Ci-PFcFe.js";import{t as h}from"./plus-CsnjfkmX.js";import{t as g}from"./rotate-ccw-Wh4id13q.js";import{t as _}from"./trash-2-BOU3WdZZ.js";import{t as ee}from"./triangle-alert-H9T4jAmh.js";import{t as te}from"./upload-DYMjAQ6M.js";import{t as v}from"./x-CBMI9ejn.js";import{a as ne,i as re,l as ie,o as ae,r as oe,t as se}from"./dialog-xXB2q5HJ.js";import{t as ce}from"./utils-BC4DHlz2.js";import{t as y}from"./button-Ccc9Dc-D.js";import{t as le}from"./project-repositories-CSnfzUpg.js";import{B as b,H as ue,Ht as x,Jt as de,Nt as fe,Tt as S,V as pe,X as me,Z as C,jt as w,lt as he,mt as ge,z as T}from"./index-C4Mv6tV6.js";import{a as _e,c as ve,d as ye,f as be,i as E,l as xe,m as D,n as Se,o as O,p as Ce,r as we,s as Te,t as Ee,u as De}from"./loop-layout-BF8xMiNv.js";var Oe=o(`grid-3x3`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}],[`path`,{d:`M3 15h18`,key:`5xshup`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),ke=o(`move-horizontal`,[[`path`,{d:`m18 8 4 4-4 4`,key:`1ak13k`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}],[`path`,{d:`m6 8-4 4 4 4`,key:`15zrgr`}]]),Ae=o(`move-vertical`,[[`path`,{d:`M12 2v20`,key:`t6zp3m`}],[`path`,{d:`m8 18 4 4 4-4`,key:`bh5tu3`}],[`path`,{d:`m8 6 4-4 4 4`,key:`ybng9g`}]]),k=e(t(),1);function A(e){let t=[],n=0;function r(i,a,o){if(!(o.length>=32||t.length>=1e4))for(let s of i.nodes){if(++n>1e4)return;if(s.type!==`core`)continue;let i=a+s.id,c=s.data?.kind,l=j(s.data?.params);c===`role-turn`&&t.push(i);let u=c===`component`?l.ref:c===`map`?l.body:void 0;typeof u==`string`&&!o.includes(u)&&e.components?.[u]&&r(e.components[u],i+`/`,[...o,u])}}return r(e,``,[]),t.sort()}var j=e=>typeof e==`object`&&e&&!Array.isArray(e)?e:{};function M(e){return typeof e.type==`string`?e.type:e.properties||e.additionalProperties?`object`:e.items?`array`:`string`}function N(e){if(`default`in e)return structuredClone(e.default);if(`const`in e)return structuredClone(e.const);if(Array.isArray(e.enum))return structuredClone(e.enum[0]);let t=e.oneOf??e.anyOf;if(Array.isArray(t)&&!e.properties)return N(j(t[0]));switch(M(e)){case`boolean`:return!1;case`number`:case`integer`:return typeof e.minimum==`number`?e.minimum:0;case`array`:return[];case`object`:{let t=j(e.properties);return Object.fromEntries((Array.isArray(e.required)?e.required:[]).filter(e=>typeof e==`string`).map(e=>[e,N(j(t[e]))]))}default:return``}}function je(e){let t=j(N(e.paramsSchema));return e.kind===`prompt`&&(t.text=``,t.engine={provider:`claude`},t.access=`read`),e.kind===`shell`&&(t.argv=[``]),e.kind===`assign`&&(t.set={}),{kind:`core`,coreKind:e.kind,params:t}}function Me(e,t,n={}){if(!e)return[];let r=e.outcomes;return e.kind===`prompt`&&(r=t.sentinel===`verification`?[`pass`,`fail`,`failed`]:t.sentinel===`blocked`?[`next`,`blocked`,`failed`]:[`next`,`failed`]),e.kind===`role-turn`&&(r=t.structuredOutput?[`next`,`invalid`,`failed`]:[`next`,`failed`]),e.kind===`component`?n[String(t.ref)]?.outputs??[`next`,`failed`]:r.filter(t=>e.outcomes.includes(t))}var Ne=e=>[`prompt`,`role-turn`,`decider`,`implementation`].includes(e)?`ai`:[`verify`,`shell`].includes(e)?`verification`:e.startsWith(`openspec-`)?`openspec`:`control`,P=n(),F=`w-full min-w-0 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary`;function I({schema:e,value:t,onChange:n,path:r=`params`,choices:i={},depth:o=0}){let{t:s}=a(`loops`),c=(0,k.useId)(),[l,u]=(0,k.useState)(``);if(o>24)return(0,P.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:s(`builder.core.tooDeep`)});let d=typeof e.title==`string`?e.title:r.split(`.`).slice(-1)[0],f=(e,n,a,s)=>(0,P.jsx)(I,{schema:n,value:a,onChange:s,path:`${r}.${e}`,choices:{...i,selectedProvider:typeof j(t).provider==`string`?String(j(t).provider):i.selectedProvider},depth:o+1},e),p=e.oneOf??e.anyOf;if(Array.isArray(p)&&!e.properties){let e=p.map(j),r=Math.max(0,e.findIndex(e=>`const`in e?t===e.const:Array.isArray(e.enum)?e.enum.includes(t):M(e)===(Array.isArray(t)?`array`:typeof t)));return(0,P.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,P.jsx)(`legend`,{className:`text-xs font-medium`,children:d}),(0,P.jsx)(`label`,{className:`sr-only`,htmlFor:c,children:s(`builder.core.variant`,{name:d})}),(0,P.jsx)(`select`,{id:c,className:F,value:r,onChange:t=>n(N(e[Number(t.target.value)])),children:e.map((e,t)=>(0,P.jsx)(`option`,{value:t,children:String(e.title??e.const??(Array.isArray(e.enum)?e.enum.join(` / `):M(e)))},t))}),f(`value`,e[r],t,n)]})}if(`const`in e)return(0,P.jsxs)(`p`,{className:`text-xs`,children:[(0,P.jsxs)(`span`,{className:`text-muted-foreground`,children:[d,`: `]}),String(e.const)]});if(Array.isArray(e.enum))return(0,P.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,(0,P.jsxs)(`select`,{className:F,value:JSON.stringify(t),onChange:e=>n(JSON.parse(e.target.value)),children:[!e.enum.includes(t)&&(0,P.jsx)(`option`,{value:JSON.stringify(t)??``,children:s(`builder.core.select`)}),e.enum.map((e,t)=>(0,P.jsx)(`option`,{value:JSON.stringify(e),children:String(e)},t))]})]});let m=M(e);if(m===`object`){let r=j(t),i=j(e.properties),a=new Set(Array.isArray(e.required)?e.required:[]),o=[...Object.keys(i),...Object.keys(r).filter(e=>!(e in i))],c=(e,t)=>{let a={...r};e===`provider`&&t!==r.provider&&i.model&&(delete a.model,delete a.effort),t===void 0?delete a[e]:Object.defineProperty(a,e,{value:t,enumerable:!0,configurable:!0,writable:!0}),n(a)},m=Array.isArray(p)?p.map(e=>j(e).required).filter(e=>Array.isArray(e)&&e.every(e=>typeof e==`string`)):[],g=t=>{let a={...r};if(m.some(e=>e.includes(t)))for(let e of m)for(let n of e)n!==t&&delete a[n];Object.defineProperty(a,t,{value:N(j(i[t]??e.additionalProperties)),enumerable:!0,configurable:!0,writable:!0}),n(a)};return(0,P.jsxs)(`fieldset`,{className:`space-y-2 min-w-0`,children:[(0,P.jsx)(`legend`,{className:`text-xs font-semibold text-foreground mb-1`,children:d}),o.map(t=>{let n=Object.prototype.hasOwnProperty.call(r,t),o=a.has(t);return!n&&!o?(0,P.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 text-xs rounded border border-border px-2 py-1 mr-1 hover:bg-muted`,onClick:()=>g(t),"aria-label":s(`builder.core.addField`,{name:t}),children:[(0,P.jsx)(h,{className:`h-3 w-3`}),t]},t):(0,P.jsxs)(`div`,{className:`relative border-l border-border pl-2 space-y-1`,children:[!o&&(0,P.jsx)(`button`,{type:`button`,className:`float-right text-muted-foreground hover:text-destructive`,onClick:()=>c(t,void 0),"aria-label":s(`builder.core.removeField`,{name:t}),children:(0,P.jsx)(v,{className:`h-3.5 w-3.5`})}),f(t,j(i[t]??e.additionalProperties),r[t],e=>c(t,e))]},t)}),e.additionalProperties!==!1&&(0,P.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,P.jsx)(`input`,{className:F,value:l,placeholder:s(`builder.core.fieldName`),"aria-label":s(`builder.core.fieldName`),onChange:e=>u(e.target.value)}),(0,P.jsx)(`button`,{type:`button`,className:`p-1.5 text-accent-primary disabled:opacity-40`,disabled:!l.trim()||Object.prototype.hasOwnProperty.call(r,l.trim())||[`__proto__`,`constructor`,`prototype`].includes(l.trim()),onClick:()=>{g(l.trim()),u(``)},"aria-label":s(`builder.core.addField`,{name:l}),children:(0,P.jsx)(h,{className:`h-4 w-4`})})]})]})}if(m===`array`){let r=Array.isArray(t)?t:[],i=j(e.items);return(0,P.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,P.jsx)(`legend`,{className:`text-xs font-semibold`,children:d}),r.map((e,t)=>(0,P.jsxs)(`div`,{className:`border-l border-border pl-2`,children:[(0,P.jsx)(`button`,{type:`button`,className:`float-right text-muted-foreground hover:text-destructive`,onClick:()=>n(r.filter((e,n)=>n!==t)),"aria-label":s(`builder.core.removeField`,{name:`${d} ${t+1}`}),children:(0,P.jsx)(v,{className:`h-3.5 w-3.5`})}),f(String(t+1),i,e,e=>n(r.map((n,r)=>r===t?e:n)))]},t)),(0,P.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 text-xs text-accent-primary`,disabled:typeof e.maxItems==`number`&&r.length>=e.maxItems,onClick:()=>n([...r,N(i)]),children:[(0,P.jsx)(h,{className:`h-3 w-3`}),s(`builder.core.addItem`)]})]})}if(!Object.keys(e).length){let e=t===null?`null`:Array.isArray(t)?`array`:typeof t,r=[`object`,`array`,`boolean`,`number`,`null`].includes(e)?e:`string`;return(0,P.jsxs)(`div`,{className:`space-y-1`,children:[(0,P.jsxs)(`label`,{className:`text-xs`,children:[s(`builder.core.valueType`),(0,P.jsx)(`select`,{className:F,value:r,onChange:e=>n(e.target.value===`null`?null:N({type:e.target.value})),children:[`string`,`number`,`boolean`,`object`,`array`,`null`].map(e=>(0,P.jsx)(`option`,{children:e},e))})]}),r===`null`?(0,P.jsx)(`span`,{className:`text-xs`,children:`null`}):f(`value`,{type:r},t,n)]})}if(m===`boolean`)return(0,P.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:t===!0,onChange:e=>n(e.target.checked),className:`accent-accent-primary`}),d]});if(m===`number`||m===`integer`)return(0,P.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,(0,P.jsx)(`input`,{type:`number`,className:F,value:typeof t==`number`?t:``,min:typeof e.minimum==`number`?e.minimum:void 0,max:typeof e.maximum==`number`?e.maximum:void 0,step:m===`integer`?1:`any`,onChange:e=>n(e.target.value===``?void 0:Number(e.target.value))})]});let g=d===`provider`?i.providers:d===`roleId`?i.roles:[`ref`,`body`].includes(d)?i.components:void 0,_=d===`model`?i.models?.[i.selectedProvider??``]:void 0,ee=[`text`,`prompt`,`question`,`message`,`goal`,`expr`,`commandLine`,`reason`].includes(d);return(0,P.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,g?.length?(0,P.jsxs)(`select`,{className:F,value:typeof t==`string`?t:``,onChange:e=>n(e.target.value),children:[(0,P.jsx)(`option`,{value:``,children:s(`builder.core.select`)}),t&&!g.includes(String(t))?(0,P.jsx)(`option`,{value:String(t),children:String(t)}):null,g.map(e=>(0,P.jsx)(`option`,{children:e},e))]}):ee?(0,P.jsx)(`textarea`,{className:`${F} min-h-24 resize-y font-mono`,value:typeof t==`string`?t:``,maxLength:typeof e.maxLength==`number`?e.maxLength:void 0,onChange:e=>n(e.target.value)}):(0,P.jsx)(`input`,{list:_?.length?c:void 0,className:F,value:typeof t==`string`?t:``,maxLength:typeof e.maxLength==`number`?e.maxLength:void 0,onChange:e=>n(e.target.value)}),_?.length?(0,P.jsx)(`datalist`,{id:c,children:_.map(e=>(0,P.jsx)(`option`,{value:e},e))}):null,typeof e.description==`string`&&(0,P.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.description})]})}var L=`w-full min-w-0 rounded border border-border bg-background px-2 py-1 text-xs`,R=[`journal`,`change`,`maxTokens`,`maxTransitions`,`policies`];function Pe({graph:e,canvas:t,schema:n,onChange:r,onOpenCanvas:i}){let{t:o}=a(`loops`),[s,c]=(0,k.useState)(``),l=j(n.properties),u={type:`object`,additionalProperties:!1,properties:{...Object.fromEntries(R.filter(e=>l[e]).map(e=>[e,l[e]])),...j(j(l.budget).properties).maxTokens?{maxTokens:j(j(l.budget).properties).maxTokens}:{}}},d=Object.fromEntries(Object.entries(e.config).filter(([e])=>R.includes(e))),f=t?e.components?.[t]:void 0,p=t?[]:A(e);return(0,P.jsxs)(P.Fragment,{children:[!t&&(0,P.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[(0,P.jsx)(`span`,{children:o(`builder.core.reviewerStep`)}),(0,P.jsxs)(`select`,{className:L,value:e.config.reviewerStepId??``,onChange:t=>r({...e,config:{...e.config,reviewerStepId:t.target.value||void 0}}),children:[(0,P.jsx)(`option`,{value:``,children:o(`builder.core.reviewerAutomatic`)}),e.config.reviewerStepId&&!p.includes(e.config.reviewerStepId)&&(0,P.jsx)(`option`,{value:e.config.reviewerStepId,children:e.config.reviewerStepId}),p.map(e=>(0,P.jsx)(`option`,{value:e,children:e},e))]}),(0,P.jsx)(`span`,{className:`block text-muted-foreground`,children:o(`builder.core.reviewerHint`)})]}),(0,P.jsx)(I,{schema:u,value:d,path:o(`builder.core.options`),onChange:t=>{let n=Object.fromEntries(Object.entries(e.config).filter(([e])=>!R.includes(e)));r({...e,config:{...n,...t}})}}),(0,P.jsxs)(`section`,{className:`space-y-2`,children:[(0,P.jsx)(`p`,{className:`text-xs font-semibold`,children:o(`builder.core.components`)}),(0,P.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(e.components??{}).map(e=>(0,P.jsx)(`button`,{type:`button`,onClick:()=>i(e),className:`text-xs rounded border border-border px-2 py-1 hover:bg-muted`,children:e},e))}),(0,P.jsxs)(`div`,{className:`flex gap-1`,children:[(0,P.jsx)(`input`,{className:L,value:s,"aria-label":o(`builder.core.componentName`),placeholder:o(`builder.core.componentName`),onChange:e=>c(e.target.value)}),(0,P.jsx)(`button`,{type:`button`,disabled:!/^[a-z][a-z0-9-]{0,63}$/.test(s)||!!e.components?.[s],onClick:()=>{i(s,!0),c(``)},"aria-label":o(`builder.core.addComponent`),className:`text-accent-primary disabled:opacity-40`,children:(0,P.jsx)(h,{className:`w-4 h-4`})})]}),f&&t&&(0,P.jsx)(I,{schema:{type:`object`,additionalProperties:!1,required:[`inputs`,`outputs`],properties:{inputs:{type:`array`,items:{type:`string`}},outputs:{type:`array`,items:{type:`string`}}}},value:{inputs:f.inputs??[],outputs:f.outputs??[`next`,`failed`]},path:t,onChange:n=>{r({...e,components:{...e.components,[t]:{...f,...n}}})}})]})]})}function Fe({nodeId:e,data:t,piece:n,choices:r,schema:i,onChange:o,onDelete:s,onOpenCanvas:c}){let{t:l}=a(`loops`),u=t.params?.ref??t.params?.body,d=j(j(i.$defs).retry),f=n?.paramsSchema??{},p=t.coreKind===`assign`?{set:l(`builder.core.assignment.set`),increment:l(`builder.core.assignment.increment`)}:t.coreKind===`decider`?{continueWhen:l(`builder.core.requiredContinue`)}:{},m=Object.keys(p).length?{...f,properties:Object.fromEntries(Object.entries(j(f.properties)).map(([e,t])=>[e,p[e]?{...j(t),title:p[e]}:t]))}:f;return(0,P.jsxs)(`div`,{className:`space-y-3`,children:[(0,P.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,P.jsx)(`h3`,{className:`text-sm font-semibold`,children:l(`builder.core.pieces.${t.coreKind}`)}),(0,P.jsx)(`button`,{type:`button`,onClick:s,"aria-label":l(`common:actions.delete`),className:`text-muted-foreground hover:text-destructive`,children:(0,P.jsx)(_,{className:`h-4 w-4`})})]}),(0,P.jsxs)(`label`,{className:`block text-xs`,children:[l(`builder.inspector.label`),(0,P.jsx)(`input`,{className:L,value:String(t.label??``),onChange:e=>o({label:e.target.value})})]}),n?(0,P.jsx)(I,{schema:m,value:t.params??{},onChange:e=>o({params:e}),choices:r},e):(0,P.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`builder.core.unavailable`)}),[`component`,`map`].includes(t.coreKind)&&typeof u==`string`&&(0,P.jsx)(`button`,{type:`button`,className:`text-xs text-accent-primary`,onClick:()=>c(u),children:l(`builder.core.openComponent`)}),Object.keys(d).length>0&&(0,P.jsx)(I,{schema:d,value:t.retry??{},path:`retry`,onChange:e=>o({retry:e})})]})}function z(e){return e===`continue`||e===`stop`?e:void 0}function B(e){switch(e){case`core`:return{kind:e,coreKind:`prompt`,params:{text:``,access:`write`,sessionContinuity:`run`}};case`ai-step`:return{kind:e,prompt:``,provider:`claude`,model:``,effort:`medium`,maxTurns:0};case`shell`:return{kind:e,command:``};case`decider`:return{kind:e,goal:``};case`condition`:return{kind:e,join:`AND`};case`end`:return{kind:e,outcome:`success`};default:return{kind:e}}}function V(){return globalThis.crypto?.randomUUID?.()??`n-${Date.now()}-${Math.floor(Math.random()*1e9)}`}function Ie(e,t){return{id:V(),type:`loop`,position:t,data:B(e)}}function Le(e){let t=(e.nodes??[]).map(e=>({id:e.id,type:`loop`,position:e.position??{x:0,y:0},data:{...e.data??{},...e.type===`core`?{coreKind:e.data?.kind}:{},kind:e.type}})),n=new Map((e.nodes??[]).map(e=>[e.id,e.type]));return{nodes:t,edges:(e.edges??[]).map(e=>{let t=e.branch??(n.get(e.source)===`decider`?n.get(e.target)===`end`?`stop`:`continue`:void 0);return{id:e.id,source:e.source,target:e.target,sourceHandle:e.label??t??void 0,type:`smoothstep`,markerEnd:{type:Ce.ArrowClosed,width:16,height:16},label:e.label??e.join,data:{...e.join?{join:e.join}:{},...t?{branch:t}:{},...e.label?{label:e.label}:{}},...t?{style:{stroke:t===`stop`?`var(--color-accent-success)`:`var(--color-accent-highlight)`}}:{}}})}}function Re(e,t,n,r){let i={...n};return i.legacyDeciderRole&&!e.some(e=>e.data.coreKind===`decider`&&e.data.params?.roleId===i.legacyDeciderRole)&&delete i.legacyDeciderRole,{nodes:e.map(e=>{let{kind:t,coreKind:n,...r}=e.data,i={id:e.id,type:t,position:e.position};return(Object.keys(r).length>0||n)&&(i.data={...r,...t===`core`?{kind:n}:{}}),i}),edges:t.map(t=>{let n=t.data?.join;if(e.find(e=>e.id===t.source)?.data.kind===`core`){let e=t.sourceHandle??t.data?.label;return{id:t.id,source:t.source,target:t.target,...e?{label:e}:{}}}let r=z(t.sourceHandle)??z(t.data?.branch);return{id:t.id,source:t.source,target:t.target,...n?{join:n}:{},...r?{branch:r}:{}}}),config:i,...r?{components:r}:{}}}var ze=`specrailsNodes`;function Be(e,t){let n=e.filter(e=>e.selected);if(n.length===0)return null;let r=new Set(n.map(e=>e.id));return{specrailsNodes:1,nodes:n,edges:t.filter(e=>r.has(e.source)&&r.has(e.target))}}function Ve(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}let n=t;return!n||n[ze]==null||!Array.isArray(n.nodes)?null:{nodes:n.nodes,edges:Array.isArray(n.edges)?n.edges:[]}}function He(e,t){let n=t.offset??{x:40,y:40},r=new Set(t.excludeKinds??[]),i=new Map;return{nodes:e.nodes.filter(e=>!r.has(String(e.data?.kind))).map(e=>{let r=t.mintId();return i.set(e.id,r),{...e,id:r,position:{x:e.position.x+n.x,y:e.position.y+n.y},selected:!0}}),edges:e.edges.filter(e=>i.has(e.source)&&i.has(e.target)).map(e=>({...e,id:t.mintId(),source:i.get(e.source),target:i.get(e.target),selected:!1}))}}function H(e){return typeof e!=`string`||e.trim().length===0}function U(e,t){let n=e.find(e=>e.data.kind===`start`),r=new Set;if(!n)return r;let i=new Map;for(let e of t)(i.get(e.source)??i.set(e.source,[]).get(e.source)).push(e.target);let a=[n.id];for(;a.length;){let e=a.shift();if(!r.has(e)){r.add(e);for(let t of i.get(e)??[])r.has(t)||a.push(t)}}return r}function Ue(e,t){let n=[],r=e.filter(e=>e.data.kind===`start`);r.length===0&&n.push({severity:`error`,code:`NO_START`});for(let e of r.slice(1))n.push({severity:`error`,code:`MULTIPLE_START`,nodeId:e.id});if(e.some(e=>e.data.kind===`end`||e.data.kind===`core`&&e.data.coreKind===`end`)||n.push({severity:`error`,code:`NO_END`}),e.some(e=>e.data.kind===`core`)&&e.some(e=>![`start`,`core`,`end`].includes(e.data.kind))&&n.push({severity:`error`,code:`MIXED_ENGINES`}),r.length===1){let r=U(e,t);for(let t of e)r.has(t.id)||n.push({severity:`error`,code:`ORPHAN`,nodeId:t.id})}let i=new Map;for(let e of t)(i.get(e.source)??i.set(e.source,[]).get(e.source)).push(e);for(let t of e){let e=i.get(t.id)??[];switch(t.data.kind){case`core`:{(!t.data.coreKind||!t.data.params||typeof t.data.params!=`object`||Array.isArray(t.data.params))&&n.push({severity:`error`,code:`CORE_PIECE`,nodeId:t.id});let r=e.map(e=>e.sourceHandle??e.data?.label);(t.data.coreKind===`end`?e.length>0:!r.length||r.some(e=>!e||!/^[a-z][a-z0-9-]{0,31}$/.test(e))||new Set(r).size!==r.length)&&n.push({severity:`error`,code:`CORE_OUTCOMES`,nodeId:t.id});break}case`decider`:{let r=new Set(e.map(e=>e.sourceHandle??e.data?.branch));(!r.has(`continue`)||!r.has(`stop`))&&n.push({severity:`error`,code:`DECIDER_BRANCHES`,nodeId:t.id}),H(t.data.goal)&&n.push({severity:`warning`,code:`EMPTY_GOAL`,nodeId:t.id});break}case`ai-step`:H(t.data.prompt)&&n.push({severity:`warning`,code:`EMPTY_PROMPT`,nodeId:t.id}),e.length===0&&n.push({severity:`warning`,code:`DEAD_END`,nodeId:t.id});break;case`shell`:H(t.data.command)&&n.push({severity:`warning`,code:`EMPTY_COMMAND`,nodeId:t.id}),e.length===0&&n.push({severity:`warning`,code:`DEAD_END`,nodeId:t.id});break;case`start`:e.length===0&&n.push({severity:`warning`,code:`DEAD_END`,nodeId:t.id});break;default:break}}return n}function We(e){let t=new Map;for(let n of e)n.nodeId&&(n.severity===`error`||!t.has(n.nodeId))&&t.set(n.nodeId,n.severity);return t}var Ge=(0,k.createContext)(new Map),Ke=(0,k.createContext)({pieces:[]}),qe=[`start`,`ai-step`,`shell`,`decider`,`end`],Je={core:x,start:p,"ai-step":x,shell:he,decider:f,condition:f,end:w},Ye={core:`border-accent-primary/60`,start:`border-accent-success/60`,"ai-step":`border-accent-primary/60`,shell:`border-accent-warning/60`,decider:`border-accent-highlight/60`,condition:`border-accent-info/60`,end:`border-accent-secondary/60`};function Xe({id:e,data:t,selected:n}){let{t:r}=a(`loops`),i=t.kind,o=Je[i]??m,s=String(t.label??``).trim(),c=(0,k.useContext)(Ge).get(e),l=(0,k.useContext)(Ke),u=Me(l.pieces.find(e=>e.kind===t.coreKind),t.params??{},l.components),d=i===`core`?String(t.params?.roleId??t.params?.ref??t.params?.body??t.params?.text??t.params?.expr??``):i===`ai-step`?String(t.model||t.provider||``):i===`shell`?String(t.command||``):i===`decider`?String(t.goal||``):i===`condition`?String(t.join||`AND`):i===`end`?String(t.outcome||`success`):``;return(0,P.jsxs)(`div`,{className:ce(`rounded-md border-2 bg-card px-3 py-2 min-w-[140px] shadow-sm`,Ye[i],c===`error`?`ring-2 ring-destructive`:n?`ring-2 ring-accent-primary`:c===`warning`?`ring-2 ring-accent-warning`:``),children:[i!==`start`&&(0,P.jsx)(E,{type:`target`,position:D.Top}),(0,P.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,P.jsx)(o,{className:`w-3.5 h-3.5 text-foreground flex-shrink-0`}),(0,P.jsx)(`span`,{className:`text-xs font-semibold text-foreground truncate max-w-[150px]`,children:s||r(i===`core`?`builder.core.pieces.${t.coreKind}`:`builder.nodes.${i}`)}),s&&(0,P.jsx)(`span`,{className:`text-[9px] text-muted-foreground/70 flex-shrink-0`,children:r(i===`core`?`builder.core.pieces.${t.coreKind}`:`builder.nodes.${i}`)})]}),d&&(0,P.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-1 truncate max-w-[160px]`,children:d}),i===`core`?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`div`,{className:`flex justify-around gap-2 mt-2 text-[9px] text-accent-primary`,children:u.map(e=>(0,P.jsx)(`span`,{children:e},e))}),u.map((e,t)=>(0,P.jsx)(E,{id:e,type:`source`,position:D.Bottom,style:{left:`${(t+1)*100/(u.length+1)}%`},"aria-label":e},e))]}):i===`decider`?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between gap-2 text-[9px] font-medium`,children:[(0,P.jsx)(`span`,{className:`text-accent-highlight`,children:r(`builder.branch.continue`)}),(0,P.jsx)(`span`,{className:`text-accent-success`,children:r(`builder.branch.stop`)})]}),(0,P.jsx)(E,{id:`continue`,type:`source`,position:D.Bottom,style:{left:`30%`},className:`!bg-accent-highlight`}),(0,P.jsx)(E,{id:`stop`,type:`source`,position:D.Bottom,style:{left:`70%`},className:`!bg-accent-success`})]}):i===`end`?null:(0,P.jsx)(E,{type:`source`,position:D.Bottom})]})}function W({loopId:e,onExit:t}){let{t:n}=a(`loops`),o=i(),{id:f}=r(),p=e??f,m=(0,k.useCallback)(()=>{t?t():o(`/loops`)},[t,o]),_=de(),{fitView:v,screenToFlowPosition:le}=be(),{activeProjectId:x}=c(),[w,he]=(0,k.useState)([]),[ge,E]=(0,k.useState)({}),[D,Te]=(0,k.useState)(!1),[A,j]=(0,k.useState)({}),[M,N]=(0,k.useState)([]),[F,I]=(0,k.useState)(null),[L,R]=(0,k.useState)(null);(0,k.useEffect)(()=>{let e=!1;return C.catalog().then(t=>{e||(he(t.nodeKinds),E(t.definitionSchema??{}),Te(!1))}).catch(()=>{e||Te(!0)}),()=>{e=!0}},[]),(0,k.useEffect)(()=>{let e=new AbortController;j({});let t=t=>fetch(t,{signal:e.signal}).then(e=>e.ok?e.json():null).catch(()=>null);return Promise.all([x?t(`${s()}/agent-runtime/config`):Promise.resolve(null),t(`/api/runtime-providers`)]).then(([t,n])=>{e.signal.aborted||j({providers:(t?.config?.providers??n?.providers??[]).map(e=>e.id),roles:[...new Set([...Object.keys(t?.config?.agents??{}),...Object.keys(t?.config?.roles??{}),...Object.keys(t?.workflowRoleDefaults??{})])],models:Object.fromEntries(Object.entries(n?.status??{}).map(([e,t])=>[e,t.models??[]]))})}),()=>e.abort()},[x]);let[z,B,ze]=ye([]),[H,U,Ye]=De([]),[W,Ze]=(0,k.useState)(``),[G,Qe]=(0,k.useState)(!1),[$e,K]=(0,k.useState)(!1),[q,rt]=(0,k.useState)(10),[it,at]=(0,k.useState)(30),[ot,st]=(0,k.useState)(null),[J,Y]=(0,k.useState)(null),[ct,lt]=(0,k.useState)(!0),[ut,dt]=(0,k.useState)(!1),[ft,pt]=(0,k.useState)(!1),[mt,ht]=(0,k.useState)(null),[gt,_t]=(0,k.useState)(!1),X=(0,k.useMemo)(()=>[...Ue(z,H),...M.map(e=>({severity:`error`,code:`CORE_VALIDATION`,nodeId:e.nodeId,message:e.message}))],[z,H,M]),vt=(0,k.useMemo)(()=>We(X),[X]),yt=X.filter(e=>e.severity===`error`).length,[bt,xt]=(0,k.useState)(`manual`),St=(0,k.useRef)(new Map),[Ct,wt]=(0,k.useState)([]),[Tt,Et]=(0,k.useState)(!1),Dt=(0,k.useCallback)(async()=>{try{wt(await C.loopConstants())}catch{}},[]);(0,k.useEffect)(()=>{Dt()},[Dt]);let Ot=(0,k.useMemo)(()=>({loop:Xe}),[]),kt=(0,k.useCallback)(e=>{I(e.graph),R(null);let{nodes:t,edges:n}=Le(e.graph);St.current=new Map(t.map(e=>[e.id,{...e.position}]));let r=e.graph.config?.layout,i=r===`vertical`||r===`horizontal`||r===`grid`?r:`manual`;xt(i),B(i===`manual`?t:Ee(t,n,i)),U(n),Ze(e.name),rt(e.graph.config?.maxIterations??10),at(e.graph.config?.timeoutMinutes??30),st(typeof e.graph.config?.maxCostUsd==`number`?e.graph.config.maxCostUsd:null),Qe(!!e.builtinId)},[B,U]);(0,k.useEffect)(()=>{if(!p)return;let e=!1;return C.get(p).then(t=>{e||kt(t)}).catch(()=>l.error(n(`errors.load`))).finally(()=>{e||lt(!1)}),()=>{e=!0}},[p,kt,n]);let At=(0,k.useCallback)(async()=>{if(p){K(!1);try{kt(await C.restoreBuiltin(p)),N([]),l.success(n(`builder.builtin.restored`))}catch(e){l.error(e instanceof Error&&e.message?e.message:n(`errors.save`))}}},[p,kt,n]),jt=(0,k.useCallback)(e=>{if(N([]),z.find(t=>t.id===e.source)?.data.kind===`core`){U(t=>ve({...e,label:e.sourceHandle,data:{label:e.sourceHandle}},t));return}let t=e.sourceHandle===`continue`||e.sourceHandle===`stop`?e.sourceHandle:void 0,n=t?{...e,data:{branch:t},style:{stroke:t===`stop`?`var(--color-accent-success)`:`var(--color-accent-highlight)`}}:e;U(e=>ve(n,e))},[U,z]),Mt=(0,k.useCallback)(e=>{if(!e.source||!e.target)return!1;let t=z.find(t=>t.id===e.source)?.data.kind,n=z.find(t=>t.id===e.target)?.data.kind;if(!t||!n||e.source===e.target&&t!==`core`||t===`end`)return!1;if(t===`core`){let t=z.find(t=>t.id===e.source),n=Me(w.find(e=>e.kind===t.data.coreKind),t.data.params??{},F?.components);if(!e.sourceHandle||!n.includes(e.sourceHandle)||H.some(t=>t.source===e.source&&t.sourceHandle===e.sourceHandle))return!1}return!(t===`start`&&H.some(t=>t.source===e.source)||n===`start`)},[z,H,w,F]),Nt=(0,k.useCallback)(e=>{xt(e==="default"?`manual`:e),B(t=>e==="default"?t.map(e=>{let t=St.current.get(e.id);return t?{...e,position:{...t}}:e}):Ee(t,H,e)),requestAnimationFrame(()=>v({padding:.25,maxZoom:.85,duration:300}))},[B,H,v]),Pt=(0,k.useCallback)(e=>{e.some(e=>e.type===`position`&&e.dragging===!1)&&xt(`manual`),ze(e)},[ze]),Ft=(0,k.useRef)(z);Ft.current=z;let It=(0,k.useRef)(H);It.current=H,(0,k.useEffect)(()=>{let e=()=>{let e=window.document.activeElement;return!!e&&(e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.isContentEditable)},t=t=>{if(e())return;let n=Be(Ft.current,It.current);!n||!t.clipboardData||(t.clipboardData.setData(`text/plain`,JSON.stringify(n)),t.preventDefault())},r=t=>{if(e())return;let r=Ve(t.clipboardData?.getData(`text/plain`)??``);if(!r)return;t.preventDefault();let i=He(r,{mintId:V,offset:{x:40,y:40},excludeKinds:Ft.current.some(e=>e.data.kind===`start`)?[`start`]:[]});i.nodes.length!==0&&(B(e=>[...e.map(e=>({...e,selected:!1})),...i.nodes]),U(e=>[...e,...i.edges]),xt(`manual`),l.success(n(`builder.paste.done`,{count:i.nodes.length})))};return window.addEventListener(`copy`,t),window.addEventListener(`paste`,r),()=>{window.removeEventListener(`copy`,t),window.removeEventListener(`paste`,r)}},[B,U,n]);let Lt=(0,k.useCallback)(e=>{let t=Ie(e,{x:120+Math.random()*120,y:80+Math.random()*240});B(e=>[...e,t]),Y(t.id)},[B]),Rt=(0,k.useCallback)(e=>{N([]),B(t=>t.map(t=>t.id===J?{...t,data:{...t.data,...e}}:t))},[J,B]),zt=(0,k.useCallback)(()=>{J&&(B(e=>e.filter(e=>e.id!==J)),U(e=>e.filter(e=>e.source!==J&&e.target!==J)),Y(null))},[J,B,U]),Z=!!F&&!z.some(e=>![`start`,`core`,`end`].includes(e.data.kind)),Q=(0,k.useCallback)(()=>{let e={...F?.config,maxIterations:q,timeoutMinutes:it,maxCostUsd:ot??void 0,layout:bt},t=L?F?.components?.[L]:F,n={...t,...Re(z,H,L?t?.config??e:e)};return L?{...F,config:e,components:{...F?.components,[L]:n}}:{...n,components:F?.components}},[F,L,z,H,q,it,ot,bt]),Bt=(0,k.useCallback)((e,t=!1)=>{let n=Q();e&&t&&!n.components?.[e]&&(n.components={...n.components,[e]:{nodes:[{id:V(),type:`start`,position:{x:160,y:40}},{id:V(),type:`core`,position:{x:160,y:220},data:{kind:`end`,params:{outcome:`success`}}}],edges:[],config:{maxIterations:10,timeoutMinutes:0},inputs:[],outputs:[`next`,`failed`]}});let r=e?n.components?.[e]:n;if(!r)return;let i=Le(r);I(n),R(e),B(i.nodes),U(i.edges),Y(null),N([]),requestAnimationFrame(()=>v({padding:.25}))},[Q,B,U,v]),Vt=(0,k.useCallback)((e,t)=>{let n={id:V(),type:`loop`,position:t??{x:160+z.length*20,y:100+z.length*30},data:je(e)};e.kind===`prompt`&&A.providers?.length&&(n.data.params.engine={provider:A.providers[0]}),B(e=>[...e,n]),Y(n.id)},[z.length,B,A.providers]),Ht=(0,k.useCallback)(async()=>{_t(!0);try{let e=Q(),{steps:t}=await C.previewLoop(e);ht(t)}catch{l.error(n(`builder.preview.error`))}finally{_t(!1)}},[Q,n]),Ut=(0,k.useCallback)(async()=>{if(!p)return!1;dt(!0);try{let e=Q();return await C.update(p,{name:W,graph:e}),!0}catch(e){return l.error(e instanceof Error&&e.message?e.message:n(`errors.save`)),!1}finally{dt(!1)}},[p,Q,W,n]),Wt=(0,k.useCallback)(async()=>{if(p&&await Ut())try{await C.publish(p),l.success(n(`builder.published`)),m()}catch(e){e instanceof me?(N(e.errors),pt(!0),l.error(n(`errors.publishInvalid`))):l.error(e instanceof Error&&e.message?e.message:n(`errors.save`))}},[p,Ut,m,n]),$=z.find(e=>e.id===J)??null;return(0,P.jsx)(Ge.Provider,{value:vt,children:(0,P.jsx)(Ke.Provider,{value:{pieces:w,components:F?.components},children:(0,P.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,P.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 h-12 border-b border-border flex-shrink-0`,children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,P.jsx)(`button`,{type:`button`,onClick:m,className:`text-muted-foreground hover:text-foreground`,"aria-label":n(`builder.back`),children:(0,P.jsx)(u,{className:`w-4 h-4`})}),(0,P.jsx)(`input`,{value:W,onChange:e=>Ze(e.target.value),className:`text-sm font-semibold bg-transparent text-foreground border-b border-transparent focus:border-border focus:outline-none min-w-0`,"aria-label":`name`})]}),(0,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.jsxs)(pe,{delayDuration:150,children:[(0,P.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[n(`builder.config.maxIterations`),(0,P.jsxs)(T,{children:[(0,P.jsx)(ue,{asChild:!0,children:(0,P.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":n(`builder.config.maxIterations`),children:(0,P.jsx)(S,{className:`w-3 h-3`})})}),(0,P.jsx)(b,{className:`max-w-xs leading-relaxed`,children:n(`builder.config.maxIterationsHint`)})]}),(0,P.jsx)(`input`,{type:`number`,min:1,value:q,onChange:e=>rt(Math.max(1,Number(e.target.value)||1)),className:`w-14 h-6 text-xs rounded border border-border bg-transparent px-1 text-foreground`})]}),(0,P.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[n(`builder.config.timeout`),(0,P.jsxs)(T,{children:[(0,P.jsx)(ue,{asChild:!0,children:(0,P.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":n(`builder.config.timeout`),children:(0,P.jsx)(S,{className:`w-3 h-3`})})}),(0,P.jsx)(b,{className:`max-w-xs leading-relaxed`,children:n(`builder.config.timeoutHint`)})]}),(0,P.jsx)(`input`,{type:`number`,min:0,"aria-label":n(`builder.config.timeout`),value:it,onChange:e=>at(Math.max(0,Number(e.target.value)||0)),className:`w-14 h-6 text-xs rounded border border-border bg-transparent px-1 text-foreground`})]}),(0,P.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[n(`builder.config.maxCost`),(0,P.jsxs)(T,{children:[(0,P.jsx)(ue,{asChild:!0,children:(0,P.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":n(`builder.config.maxCost`),children:(0,P.jsx)(S,{className:`w-3 h-3`})})}),(0,P.jsx)(b,{className:`max-w-xs leading-relaxed`,children:n(`builder.config.maxCostHint`)})]}),(0,P.jsx)(`input`,{type:`number`,min:0,step:.5,placeholder:`∞`,value:ot??``,onChange:e=>{let t=Number(e.target.value);st(e.target.value===``||!(t>0)?null:t)},className:`w-16 h-6 text-xs rounded border border-border bg-transparent px-1 text-foreground`})]})]}),G&&(0,P.jsxs)(`button`,{type:`button`,onClick:()=>K(!0),disabled:ut,"data-testid":`builder-restore-builtin`,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground disabled:opacity-50`,children:[(0,P.jsx)(g,{className:`w-3 h-3`}),` `,n(`actions.restoreBuiltin`)]}),(0,P.jsxs)(`button`,{type:`button`,onClick:()=>void Ht(),disabled:gt,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground disabled:opacity-50`,children:[(0,P.jsx)(fe,{className:`w-3 h-3`}),` `,n(`builder.preview.label`)]}),(0,P.jsxs)(`button`,{type:`button`,onClick:()=>void Ut().then(e=>e&&l.success(n(`builder.saved`))),disabled:ut,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground disabled:opacity-50`,children:[(0,P.jsx)(d,{className:`w-3 h-3`}),` `,n(`builder.save`)]}),(0,P.jsxs)(`button`,{type:`button`,onClick:()=>void Wt(),disabled:ut,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs bg-accent-primary text-white hover:bg-accent-primary/90 disabled:opacity-50`,children:[(0,P.jsx)(te,{className:`w-3 h-3`}),` `,n(`builder.publish`)]})]})]}),G&&(0,P.jsx)(`div`,{role:`note`,"data-testid":`builder-builtin-note`,className:`px-4 py-1.5 border-b border-border bg-accent-info/10 text-[11px] text-accent-info flex-shrink-0`,children:n(`builder.builtin.note`)}),(0,P.jsx)(se,{open:$e,onOpenChange:e=>{e||K(!1)},children:(0,P.jsxs)(oe,{className:`max-w-sm`,children:[(0,P.jsxs)(ae,{children:[(0,P.jsx)(ie,{children:n(`builder.builtin.confirmTitle`)}),(0,P.jsx)(re,{children:n(`builder.builtin.confirmBody`)})]}),(0,P.jsxs)(ne,{children:[(0,P.jsx)(y,{variant:`ghost`,onClick:()=>K(!1),children:n(`common:actions.cancel`)}),(0,P.jsx)(y,{"data-testid":`builder-restore-confirm`,onClick:()=>void At(),children:n(`actions.restoreBuiltin`)})]})]})}),(0,P.jsxs)(`div`,{className:`flex-1 flex min-h-0`,children:[(0,P.jsxs)(`div`,{className:`w-44 border-r border-border p-2 space-y-1 flex-shrink-0 overflow-y-auto`,children:[(0,P.jsx)(`p`,{className:`text-[10px] font-semibold uppercase tracking-wide text-muted-foreground px-1 mb-1`,children:n(`builder.addNode`)}),Z&&D&&(0,P.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground px-1`,children:n(`builder.core.unavailable`)}),Z&&w.length>0&&[`ai`,`verification`,`openspec`,`control`].map(e=>(0,P.jsxs)(`div`,{className:`pt-2`,children:[(0,P.jsx)(`p`,{className:`text-[10px] uppercase text-muted-foreground px-1`,children:n(`builder.core.groups.${e}`)}),w.filter(t=>Ne(t.kind)===e).map(e=>(0,P.jsxs)(`button`,{type:`button`,draggable:!0,onDragStart:t=>{t.dataTransfer.setData(`application/specrails-core-piece`,e.kind),t.dataTransfer.effectAllowed=`copy`},onClick:()=>Vt(e),className:`flex items-center gap-2 w-full min-h-8 px-2 rounded text-left text-xs hover:bg-muted focus-visible:ring-2 focus-visible:ring-accent-primary`,children:[(0,P.jsx)(h,{className:`h-3 w-3 flex-shrink-0`}),n(`builder.core.pieces.${e.kind}`)]},e.kind))]},e)),(Z?[`start`]:qe).map(e=>{let t=Je[e];return(0,P.jsxs)(`button`,{type:`button`,onClick:()=>Lt(e),disabled:e===`start`&&z.some(e=>e.data.kind===`start`),className:`flex items-center gap-2 w-full h-8 px-2 rounded-md text-xs text-muted-foreground hover:text-foreground hover:bg-muted/50`,children:[(0,P.jsx)(t,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,P.jsx)(`span`,{className:`truncate`,children:n(`builder.nodes.${e}`)}),(0,P.jsx)(h,{className:`w-3 h-3 ml-auto opacity-50`})]},e)})]}),(0,P.jsx)(`div`,{className:`flex-1 min-w-0 relative`,onDragOver:e=>{e.dataTransfer.types.includes(`application/specrails-core-piece`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},onDrop:e=>{let t=w.find(t=>t.kind===e.dataTransfer.getData(`application/specrails-core-piece`));!t||!Z||(e.preventDefault(),Vt(t,le({x:e.clientX,y:e.clientY})))},children:ct?(0,P.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,P.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`…`})}):(0,P.jsxs)(xe,{nodes:z,edges:H,onNodesChange:Pt,onEdgesChange:Ye,onConnect:jt,isValidConnection:Mt,onNodeClick:(e,t)=>Y(t.id),onPaneClick:()=>Y(null),nodeTypes:Ot,colorMode:_.scheme===`dark`?`dark`:`light`,fitView:!0,fitViewOptions:{padding:.25,maxZoom:.85},minZoom:.2,defaultEdgeOptions:{type:`smoothstep`,markerEnd:{type:Ce.ArrowClosed,width:16,height:16}},proOptions:{hideAttribution:!0},children:[Z&&(0,P.jsx)(O,{position:`top-center`,children:(0,P.jsxs)(`nav`,{className:`flex items-center gap-1 rounded border border-border bg-card/95 p-1 text-xs`,"aria-label":n(`builder.core.breadcrumbs`),children:[(0,P.jsx)(`button`,{type:`button`,onClick:()=>Bt(null),className:`px-2 py-1 hover:bg-muted`,children:W||n(`builder.core.root`)}),L&&(0,P.jsxs)(`span`,{"aria-current":`page`,children:[`/ `,L]})]})}),(0,P.jsx)(Se,{}),(0,P.jsx)(we,{}),(0,P.jsx)(_e,{pannable:!0,zoomable:!0}),(0,P.jsx)(O,{position:`top-left`,children:(0,P.jsx)(`div`,{className:`flex items-center gap-0.5 rounded-md border border-border bg-card/90 backdrop-blur p-0.5`,role:`group`,"aria-label":n(`builder.arrange.label`),children:[[`vertical`,Ae],[`horizontal`,ke],[`grid`,Oe],[`default`,g]].map(([e,t])=>{let r=e==="default"?`reset`:e,i=e==="default"?bt===`manual`:bt===e;return(0,P.jsx)(`button`,{type:`button`,title:n(`builder.arrange.${r}`),"aria-label":n(`builder.arrange.${r}`),"aria-pressed":i,onClick:()=>Nt(e),className:ce(`inline-flex items-center justify-center w-7 h-7 rounded hover:bg-muted`,i?`bg-muted text-accent-primary`:`text-muted-foreground hover:text-foreground`),children:(0,P.jsx)(t,{className:`w-3.5 h-3.5`})},e)})})}),(0,P.jsx)(O,{position:`top-right`,children:(0,P.jsx)(pe,{delayDuration:150,children:(0,P.jsxs)(T,{children:[(0,P.jsx)(ue,{asChild:!0,children:(0,P.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 h-6 px-2 rounded-md text-[10px] border border-border bg-card/90 text-muted-foreground hover:text-foreground backdrop-blur`,children:[(0,P.jsx)(S,{className:`w-3 h-3`}),n(`builder.edgesHelp.label`)]})}),(0,P.jsx)(b,{className:`max-w-xs leading-relaxed`,children:n(`builder.edgesHelp.body`)})]})})}),X.length>0&&(0,P.jsx)(O,{position:`bottom-center`,children:(0,P.jsxs)(`div`,{className:`rounded-md border border-border bg-card/95 backdrop-blur text-xs overflow-hidden max-w-md mb-2`,children:[(0,P.jsxs)(`button`,{type:`button`,onClick:()=>pt(e=>!e),className:ce(`flex items-center gap-1.5 w-full px-2.5 py-1.5 font-medium`,yt>0?`text-destructive`:`text-accent-warning`),children:[(0,P.jsx)(ee,{className:`w-3.5 h-3.5`}),n(`builder.problems.count`,{count:X.length})]}),ft&&(0,P.jsx)(`ul`,{className:`border-t border-border max-h-40 overflow-y-auto py-1`,children:X.map((e,t)=>(0,P.jsx)(`li`,{children:(0,P.jsxs)(`button`,{type:`button`,disabled:!e.nodeId,onClick:()=>e.nodeId&&Y(e.nodeId),className:`flex items-start gap-1.5 w-full text-left px-2.5 py-1 hover:bg-muted disabled:cursor-default`,children:[(0,P.jsx)(`span`,{className:ce(`mt-1 w-1.5 h-1.5 rounded-full flex-shrink-0`,e.severity===`error`?`bg-destructive`:`bg-accent-warning`)}),(0,P.jsx)(`span`,{className:`text-foreground`,children:`message`in e?String(e.message):n(`builder.problems.${e.code}`)})]})},`${e.code}-${e.nodeId??t}`))})]})})]})}),(0,P.jsxs)(`div`,{className:`w-80 border-l border-border p-3 flex-shrink-0 overflow-y-auto space-y-4`,children:[Z&&F&&(0,P.jsx)(Pe,{graph:F,canvas:L,schema:ge,onChange:I,onOpenCanvas:Bt}),$?$.data.kind===`core`?(0,P.jsx)(Fe,{nodeId:$.id,data:$.data,piece:w.find(e=>e.kind===$.data.coreKind),choices:{...A,components:Object.keys(F?.components??{})},schema:ge,onChange:Rt,onDelete:zt,onOpenCanvas:Bt}):(0,P.jsx)(nt,{data:$.data,onChange:Rt,onDelete:zt,constants:Ct,onManageConstants:()=>Et(!0)}):(0,P.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`builder.inspector.selectNode`)})]})]}),(0,P.jsx)(et,{open:Tt,onClose:()=>Et(!1),constants:Ct,onChanged:Dt,t:n}),(0,P.jsx)(tt,{steps:mt,onClose:()=>ht(null),t:n})]})})})}var Ze=[{labelKey:`builder.inspector.tokensSpec`,tokens:[{token:`{{spec.title}}`,label:`spec.title`},{token:`{{spec.description}}`,label:`spec.description`},{token:`{{spec.id}}`,label:`spec.id`},{token:`{{spec.status}}`,label:`spec.status`},{token:`{{spec.priority}}`,label:`spec.priority`},{token:`{{spec.labels}}`,label:`spec.labels`}]},{labelKey:`builder.inspector.tokensJira`,tokens:[{token:`{{spec.jira_key}}`,label:`spec.jira_key`},{token:`{{spec.jira_url}}`,label:`spec.jira_url`}]}];function G({token:e,label:t,description:n,onInsert:r}){return(0,P.jsx)(`button`,{type:`button`,draggable:!0,onDragStart:t=>t.dataTransfer.setData(`text/plain`,e),onClick:()=>r(e),title:n?`${e} — ${n}`:e,className:`px-1.5 py-0.5 rounded border border-border bg-surface/40 text-[10px] font-mono text-accent-primary hover:bg-accent-primary/10 cursor-grab active:cursor-grabbing`,children:t})}function Qe({t:e,onInsert:t}){let[n,r]=(0,k.useState)([]);return(0,k.useEffect)(()=>{let e=!1;return C.loopCommands().then(t=>{e||r(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,P.jsxs)(`div`,{className:`mb-2 space-y-1.5`,children:[Ze.map(n=>(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`span`,{className:`block text-[9px] uppercase tracking-wide text-muted-foreground/70 mb-0.5`,children:e(n.labelKey)}),(0,P.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.tokens.map(e=>(0,P.jsx)(G,{token:e.token,label:e.label,onInsert:t},e.token))})]},n.labelKey)),n.length>0&&(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`span`,{className:`block text-[9px] uppercase tracking-wide text-muted-foreground/70 mb-0.5`,children:e(`builder.inspector.tokensCommands`)}),(0,P.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>(0,P.jsx)(G,{token:`{{cmd:${e.name}}}`,label:`⚡ ${e.label}`,description:e.description,onInsert:t},e.name))})]})]})}function $e({t:e,constants:t,onInsert:n,onManage:r}){return(0,P.jsxs)(`div`,{className:`mb-2`,children:[(0,P.jsxs)(`div`,{className:`flex items-center justify-between mb-0.5`,children:[(0,P.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:e(`builder.constants.label`)}),(0,P.jsx)(`button`,{type:`button`,onClick:r,title:e(`builder.constants.manage`),"aria-label":e(`builder.constants.manage`),className:`text-muted-foreground hover:text-foreground`,children:(0,P.jsx)(ge,{className:`w-3 h-3`})})]}),(0,P.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.map(e=>(0,P.jsx)(G,{token:`{{const:${e.name}}}`,label:e.builtin?`🔒 ${e.name}`:e.name,description:e.value,onInsert:n},e.id))})]})}function K({c:e,onSave:t,onDelete:n}){let[r,i]=(0,k.useState)(e.value);return(0,P.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,P.jsx)(`code`,{className:`text-[10px] font-mono text-accent-primary w-28 truncate`,title:e.name,children:e.name}),(0,P.jsx)(`input`,{className:`flex-1 text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground`,value:r,onChange:e=>i(e.target.value)}),(0,P.jsx)(`button`,{type:`button`,disabled:r===e.value||!r,onClick:()=>t(r),className:`text-muted-foreground hover:text-foreground disabled:opacity-40`,"aria-label":`save`,children:(0,P.jsx)(d,{className:`w-3.5 h-3.5`})}),(0,P.jsx)(`button`,{type:`button`,onClick:n,className:`text-muted-foreground hover:text-destructive`,"aria-label":`delete`,children:(0,P.jsx)(_,{className:`w-3.5 h-3.5`})})]})}function et({open:e,onClose:t,constants:n,onChanged:r,t:i}){let[a,o]=(0,k.useState)(``),[s,c]=(0,k.useState)(``),[l,u]=(0,k.useState)(null),[d,f]=(0,k.useState)(!1),p=n.filter(e=>e.builtin),m=n.filter(e=>!e.builtin),h=async()=>{f(!0),u(null);try{await C.createConstant(a.trim(),s),o(``),c(``),await r()}catch(e){u(e instanceof Error?e.message:`error`)}finally{f(!1)}},g=`text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`;return(0,P.jsx)(se,{open:e,onOpenChange:e=>{e||t()},children:(0,P.jsxs)(oe,{className:`max-w-md`,children:[(0,P.jsx)(ae,{children:(0,P.jsx)(ie,{children:i(`builder.constants.title`)})}),(0,P.jsxs)(`div`,{className:`space-y-3`,children:[(0,P.jsxs)(`div`,{className:`space-y-1.5`,children:[m.length===0&&(0,P.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`builder.constants.empty`)}),m.map(e=>(0,P.jsx)(K,{c:e,onSave:t=>void C.updateConstant(e.id,t).then(r),onDelete:()=>void C.deleteConstant(e.id).then(r)},e.id))]}),(0,P.jsxs)(`div`,{className:`flex items-center gap-1.5 border-t border-border pt-2`,children:[(0,P.jsx)(`input`,{className:`${g} w-28`,placeholder:i(`builder.constants.name`),value:a,onChange:e=>o(e.target.value)}),(0,P.jsx)(`input`,{className:`${g} flex-1`,placeholder:i(`builder.constants.value`),value:s,onChange:e=>c(e.target.value)}),(0,P.jsx)(y,{size:`sm`,disabled:d||!a.trim()||!s,onClick:()=>void h(),children:i(`builder.constants.add`)})]}),l&&(0,P.jsx)(`p`,{className:`text-[10px] text-destructive`,children:l}),p.length>0&&(0,P.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[(0,P.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:i(`builder.constants.builtinBadge`)}),p.map(e=>(0,P.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px]`,children:[(0,P.jsx)(`code`,{className:`font-mono text-accent-primary w-28 truncate`,title:e.name,children:e.name}),(0,P.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.value})]},e.id))]})]}),(0,P.jsx)(ne,{children:(0,P.jsx)(y,{variant:`ghost`,onClick:t,children:i(`common:actions.close`)})})]})})}function tt({steps:e,onClose:t,t:n}){return(0,P.jsx)(se,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,P.jsxs)(oe,{className:`max-w-2xl`,children:[(0,P.jsx)(ae,{children:(0,P.jsx)(ie,{children:n(`builder.preview.title`)})}),(0,P.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:n(`builder.preview.sampleNote`)}),(0,P.jsxs)(`div`,{className:`space-y-2 max-h-[60vh] overflow-y-auto`,children:[e&&e.length===0&&(0,P.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`builder.preview.empty`)}),e?.map((e,t)=>(0,P.jsxs)(`div`,{className:`rounded-md border border-border`,children:[(0,P.jsxs)(`div`,{className:`px-2.5 py-1 text-[10px] border-b border-border flex items-center gap-1.5`,children:[(0,P.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label||n([`start`,`end`,`ai-step`,`shell`,`decider`,`condition`].includes(e.kind)?`builder.nodes.${e.kind}`:`builder.core.pieces.${e.kind}`)}),(0,P.jsxs)(`span`,{className:`text-muted-foreground`,children:[`· `,n([`start`,`end`,`ai-step`,`shell`,`decider`,`condition`].includes(e.kind)?`builder.nodes.${e.kind}`:`builder.core.pieces.${e.kind}`)]})]}),(0,P.jsx)(`pre`,{className:`px-2.5 py-2 text-[11px] text-foreground whitespace-pre-wrap break-words font-mono`,children:e.text||`—`})]},`${e.nodeId}-${t}`))]}),(0,P.jsx)(ne,{children:(0,P.jsx)(y,{variant:`ghost`,onClick:t,children:n(`common:actions.close`)})})]})})}function nt({data:e,onChange:t,onDelete:n,constants:r,onManageConstants:i}){let{t:o}=a(`loops`),{activeProjectId:s,projects:l}=c(),u=le(l.find(e=>e.id===s)),d=e.kind,f=`block text-[10px] font-medium text-muted-foreground mb-1`,p=`w-full text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`,m=(0,k.useRef)(null),h=(0,k.useRef)(null),g=(n,r,i)=>{let a=n.current,o=String(e[r]??``);if(!a){t({[r]:o+i});return}let s=a.selectionStart??o.length,c=a.selectionEnd??o.length;t({[r]:o.slice(0,s)+i+o.slice(c)}),requestAnimationFrame(()=>{a.focus();let e=s+i.length;a.setSelectionRange(e,e)})},ee=e=>g(m,`prompt`,e);return(0,P.jsxs)(`div`,{className:`space-y-3`,children:[(0,P.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,P.jsx)(`span`,{className:`text-xs font-semibold text-foreground`,children:o(`builder.nodes.${d}`)}),(0,P.jsx)(`button`,{type:`button`,onClick:n,"aria-label":o(`builder.deleteNode`),className:`text-muted-foreground hover:text-destructive`,children:(0,P.jsx)(_,{className:`w-3.5 h-3.5`})})]}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`label`,{className:f,children:o(`builder.inspector.label`)}),(0,P.jsx)(`input`,{className:p,value:String(e.label??``),onChange:e=>t({label:e.target.value}),placeholder:o(`builder.nodes.${d}`)})]}),d===`ai-step`&&(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`label`,{className:f,children:o(`builder.inspector.prompt`)}),(0,P.jsx)(Qe,{t:o,onInsert:ee}),(0,P.jsx)($e,{t:o,constants:r,onInsert:ee,onManage:i}),(0,P.jsx)(`textarea`,{ref:m,rows:7,className:p,value:String(e.prompt??``),onChange:e=>t({prompt:e.target.value})}),(0,P.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-1`,children:o(`builder.inspector.promptHint`)})]}),d===`shell`&&(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`label`,{className:f,children:o(`builder.inspector.command`)}),(0,P.jsx)(`input`,{className:p,value:String(e.command??``),onChange:e=>t({command:e.target.value}),placeholder:`npm test`}),(0,P.jsxs)(`label`,{className:`${f} mt-3`,children:[o(`common:repositories.shellTarget`),(0,P.jsxs)(`select`,{className:p,value:String(e.repositoryId??``),onChange:e=>t({repositoryId:e.target.value||void 0}),children:[(0,P.jsx)(`option`,{value:``,children:o(`common:repositories.shellDefault`)}),u.filter(e=>e.kind===`git`).map(e=>(0,P.jsx)(`option`,{value:e.id,children:e.name},e.id)),!!e.repositoryId&&!u.some(t=>t.id===e.repositoryId)&&(0,P.jsx)(`option`,{value:String(e.repositoryId),children:String(e.repositoryId)})]})]}),(0,P.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`common:repositories.shellHint`)})]}),d===`decider`&&(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`label`,{className:f,children:o(`builder.inspector.goal`)}),(0,P.jsx)($e,{t:o,constants:r,onInsert:e=>g(h,`goal`,e),onManage:i}),(0,P.jsx)(`textarea`,{ref:h,rows:4,className:p,value:String(e.goal??``),onChange:e=>t({goal:e.target.value})})]}),d===`condition`&&(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`label`,{className:f,children:o(`builder.inspector.join`)}),(0,P.jsxs)(`select`,{className:p,value:String(e.join??`AND`),onChange:e=>t({join:e.target.value}),children:[(0,P.jsx)(`option`,{value:`AND`,children:`AND`}),(0,P.jsx)(`option`,{value:`OR`,children:`OR`})]})]}),d===`end`&&(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`label`,{className:f,children:o(`builder.inspector.outcome`)}),(0,P.jsxs)(`select`,{className:p,value:String(e.outcome??`success`),onChange:e=>t({outcome:e.target.value}),children:[(0,P.jsx)(`option`,{value:`success`,children:`success`}),(0,P.jsx)(`option`,{value:`failure`,children:`failure`})]})]}),d===`start`&&(0,P.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:o(`builder.inspector.startNote`)})]})}function q({loopId:e,onExit:t}={}){return(0,P.jsx)(Te,{children:(0,P.jsx)(W,{loopId:e,onExit:t})})}export{q as default};
@@ -1,2 +0,0 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{u as r}from"./chunk-KS7C4IRE-DEKu087k.js";import{n as i,t as a}from"./createLucideIcon-Bjbbp_KS.js";import{n as o,r as s,s as c}from"./useDesktop-0unHDBJJ.js";import{_ as l,n as u,s as d,u as f}from"./provider-capabilities-Vi1ZGvAK.js";import{t as p}from"./download-CFHyyHcw.js";import{t as m}from"./pencil-C9RkrIPZ.js";import{n as h}from"./square-Ci-PFcFe.js";import{t as g}from"./plus-CsnjfkmX.js";import{t as _}from"./rotate-ccw-Wh4id13q.js";import{t as v}from"./sparkles-DrY8hb0X.js";import{t as y}from"./trash-2-BOU3WdZZ.js";import{t as b}from"./upload-DYMjAQ6M.js";import{a as x,i as S,l as C,o as w,r as T,t as E}from"./dialog-xXB2q5HJ.js";import{t as D}from"./utils-BC4DHlz2.js";import{t as O}from"./button-Ccc9Dc-D.js";import{t as ee}from"./RepositoryScopeSelector-C2mvWBQ6.js";import{$ as k,Nt as A,Pt as j,Q as te,U as M,W as N,X as P,Y as F,Z as I,ot as L}from"./index-C4Mv6tV6.js";import{n as R}from"./TemplatePreviewModal-C7DordpN.js";var z=a(`file-down`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 18v-6`,key:`17g6i2`}],[`path`,{d:`m9 15 3 3 3-3`,key:`1npd3o`}]]),ne=a(`file-up`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}],[`path`,{d:`m15 15-3-3-3 3`,key:`15xj92`}]]),B=e(t(),1),V=n(),H=[`invalid`,`needs_attention`,`convertible`,`running`,`current`];function re({onConvert:e}){let{t}=i(`loops`),[n,r]=(0,B.useState)(null),[a,o]=(0,B.useState)(!1),[s,c]=(0,B.useState)(``),l=(0,B.useRef)(!0);(0,B.useEffect)(()=>(l.current=!0,()=>{l.current=!1}),[]);async function u(){o(!0),c(``),r(null);try{let e=await I.migration();l.current&&r(e)}catch(e){l.current&&c(e instanceof Error&&e.message?e.message:t(`migration.failed`))}finally{l.current&&o(!1)}}let d=n?n.loops.filter(e=>e.state!==`current`):[];return(0,V.jsxs)(`section`,{className:`rounded-lg border border-border p-3 space-y-2`,"aria-label":t(`migration.title`),children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:t(`migration.title`)}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`migration.description`)})]}),(0,V.jsx)(O,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>void u(),children:t(a?`migration.checking`:`migration.check`)})]}),s&&(0,V.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:s}),n&&(0,V.jsxs)(`div`,{role:`status`,className:`space-y-2 text-xs`,children:[(0,V.jsx)(`p`,{children:H.filter(e=>n.summary[e]>0).map(e=>t(`migration.states.${e}`)+`: `+n.summary[e]).join(` · `)||t(`migration.empty`)}),d.length===0&&n.loops.length>0&&(0,V.jsx)(`p`,{className:`text-muted-foreground`,children:t(`migration.allCurrent`)}),(0,V.jsx)(`ul`,{className:`space-y-1`,children:d.map(n=>(0,V.jsxs)(`li`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(`span`,{className:`font-medium`,children:n.name}),(0,V.jsxs)(`span`,{className:`text-muted-foreground`,children:[t(`migration.states.${n.state}`),n.status===`published`?` · ${t(`status.published`)}`:``]}),n.issues.slice(0,3).map((e,t)=>(0,V.jsx)(`span`,{className:`text-destructive`,children:e.message},t)),n.state===`convertible`&&(0,V.jsx)(O,{size:`sm`,variant:`ghost`,onClick:()=>e(n.id),children:t(`actions.convert`)})]},n.id))})]})]})}function ie(e){return{specrailsLoops:1,loops:e.map(e=>({name:e.name,description:e.description,graph:e.graph}))}}function U(e){let t=e;return!!t&&typeof t.name==`string`&&!!t.graph&&typeof t.graph==`object`}function ae(e){let t;try{t=JSON.parse(e)}catch{throw Error(`invalid-json`)}let n=(Array.isArray(t)?t:Array.isArray(t?.loops)?t.loops:U(t)?[t]:[]).filter(U);if(n.length===0)throw Error(`no-loops`);return n.map(e=>({name:e.name,description:e.description??null,graph:e.graph}))}function oe(e){return e.length===1?`${e[0].name.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`loop`}.loop.json`:`specrails-loops-${e.length}.json`}var W=[`API`,`Automation`,`CI`,`Database`,`Debugging`,`DevOps`,`Docs`,`Git`,`Maintenance`,`Performance`,`Planning`,`Quality`,`Review`,`Security`,`Testing`];function se(e,t){let n=t.query.trim().toLowerCase(),r=t.categories;return e.filter(e=>r.length>0&&!(e.category&&r.includes(e.category))?!1:!n||`${e.name} ${e.description} ${e.tags.join(` `)} ${e.category??``} ${e.searchTerms??``}`.toLowerCase().includes(n))}function ce(e){let t=new Map;for(let n of e)n.category&&t.set(n.category,(t.get(n.category)??0)+1);let n=[];for(let e of W){let r=t.get(e);r&&(n.push({category:e,count:r}),t.delete(e))}for(let e of[...t.keys()].sort())n.push({category:e,count:t.get(e)});return n}function le({loop:e,projects:t,onClose:n,onExecute:r}){let{t:a}=i(`loops`),o=e!==null,[s,c]=(0,B.useState)(``),[p,m]=(0,B.useState)(``),[g,_]=(0,B.useState)(``),[v,y]=(0,B.useState)(``),[b,D]=(0,B.useState)(),A=t.find(e=>e.id===(s||t[0]?.id)),j=(0,B.useMemo)(()=>A?.providers??(A?.provider?[A.provider]:[]),[A]),P=p||j[0]||``,F=(0,B.useMemo)(()=>k(P),[P]),I=f(P),L=g&&(F.some(e=>e.value===g)||I&&N(g))?g:te(P),R=l(P,L),z=R.includes(v)?v:u(P,L)??``,ne=R.length>0;return(0,V.jsx)(E,{open:o,onOpenChange:e=>{e||n()},children:(0,V.jsx)(T,{movableResizable:!0,className:`max-w-sm`,children:e&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(w,{children:[(0,V.jsx)(C,{children:a(`run.title`,{name:e.name})}),(0,V.jsx)(S,{children:a(`run.subtitle`)})]}),(0,V.jsx)(`label`,{className:`block text-[11px] font-medium text-muted-foreground`,children:a(`run.project`)}),t.length===0?(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a(`run.noProjects`)}):(0,V.jsx)(`select`,{"aria-label":a(`run.project`),"data-testid":`run-project-select`,value:s||t[0]?.id,onChange:e=>{c(e.target.value),m(``),_(``),y(``),D(void 0)},className:`w-full text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`,children:t.map(e=>(0,V.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,V.jsx)(ee,{repositories:A?.repositories??[],value:b,onChange:D}),j.length>1&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`label`,{className:`block text-[11px] font-medium text-muted-foreground`,children:a(`run.provider`)}),(0,V.jsx)(`select`,{"aria-label":a(`run.provider`),value:P,onChange:e=>{m(e.target.value),_(``),y(``)},className:`w-full text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`,children:j.map(e=>(0,V.jsx)(`option`,{value:e,children:d(e)},e))})]}),F.length>0&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`label`,{className:`block text-[11px] font-medium text-muted-foreground`,children:a(`run.model`)}),I?(0,V.jsx)(M,{value:L,options:F,ariaLabel:a(`run.model`),testId:`run-model-select`,className:`w-full px-2 py-1 text-xs`,onCommit:e=>{_(e),y(u(P,e)??``)}}):(0,V.jsx)(`select`,{"aria-label":a(`run.model`),"data-testid":`run-model-select`,value:L,onChange:e=>{let t=e.target.value;_(t),y(u(P,t)??``)},className:`w-full text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`,children:F.map(e=>(0,V.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),ne&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`label`,{className:`block text-[11px] font-medium text-muted-foreground`,children:a(`run.effort`)}),(0,V.jsx)(`select`,{"aria-label":a(`run.effort`),value:z,onChange:e=>y(e.target.value),className:`w-full text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`,children:R.map(e=>(0,V.jsx)(`option`,{value:e,children:e},e))})]}),(0,V.jsxs)(x,{children:[(0,V.jsx)(O,{variant:`ghost`,onClick:n,children:a(`common:actions.cancel`)}),(0,V.jsxs)(O,{onClick:()=>{let e=s||t[0]?.id;e&&r({projectId:e,...b?{repositoryIds:b}:{},provider:j.length>1?P:void 0,model:F.length>0?L:void 0,effort:ne?z:void 0})},disabled:t.length===0,children:[(0,V.jsx)(h,{className:`w-3.5 h-3.5 mr-1.5`}),a(`run.execute`)]})]})]})})})}function ue({loop:e,projects:t,onClose:n,onConverted:r}){let{t:a}=i(`loops`),[o,s]=(0,B.useState)(``),[c,l]=(0,B.useState)(!1),[u,d]=(0,B.useState)(``),f=e.graph.nodes.some(e=>e.type===`shell`&&!e.data?.repositoryId),p=t.flatMap(e=>(e.repositories??[]).map(t=>({key:JSON.stringify([e.id,t.id]),id:t.id,label:`${e.name} / ${t.name}`}))),m=p.find(e=>e.key===o);async function h(){l(!0),d(``);try{r((await I.convert(e.id,m?.id)).loop)}catch(e){d(e instanceof P?e.errors.map(e=>`${e.nodeId?e.nodeId+`: `:``}${e.message}`).join(`
2
- `):e instanceof Error&&e.message===`engine_unsupported`?a(`conversion.coreRequired`):e instanceof Error?a(`conversion.error`)+`: `+e.message:a(`conversion.error`))}finally{l(!1)}}return(0,V.jsx)(E,{open:!0,onOpenChange:e=>{!e&&!c&&n()},children:(0,V.jsxs)(T,{children:[(0,V.jsxs)(w,{children:[(0,V.jsx)(C,{children:a(`conversion.title`,{name:e.name})}),(0,V.jsx)(S,{children:a(`conversion.description`)})]}),f&&(0,V.jsxs)(`label`,{className:`flex flex-col gap-2 text-sm`,children:[a(`conversion.repository`),(0,V.jsxs)(`select`,{className:`rounded border border-border bg-background p-2`,value:o,onChange:e=>s(e.target.value),disabled:c,children:[(0,V.jsx)(`option`,{value:``,children:a(`conversion.selectRepository`)}),p.map(e=>(0,V.jsx)(`option`,{value:e.key,children:e.label},e.key))]})]}),u&&(0,V.jsx)(`p`,{role:`alert`,className:`whitespace-pre-wrap text-sm text-destructive`,children:u}),(0,V.jsxs)(x,{children:[(0,V.jsx)(O,{variant:`outline`,disabled:c,onClick:n,children:a(`common:actions.cancel`)}),(0,V.jsx)(O,{disabled:c||f&&!m,onClick:()=>void h(),children:a(c?`conversion.pending`:`conversion.submit`)})]})]})})}var G={draft:`bg-accent-secondary/15 text-accent-secondary ring-accent-secondary/40`,published:`bg-accent-success/15 text-accent-success ring-accent-success/40`};function K({status:e}){let{t}=i(`loops`);return(0,V.jsx)(`span`,{className:D(`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium ring-1 ring-inset`,G[e]),children:t(`status.${e}`)})}function q({onOpenBuilder:e}={}){let{t}=i(`loops`),n=r(),a=(0,B.useCallback)(e=>e.replace(/:/g,`_`),[]),l=(0,B.useCallback)((e,n)=>t(`catalog.${a(e)}.name`,{defaultValue:n}),[t,a]),u=(0,B.useCallback)((e,n)=>t(`catalog.${a(e)}.description`,{defaultValue:n}),[t,a]),[d,f]=(0,B.useState)([]),[m,h]=(0,B.useState)([]),[b,ee]=(0,B.useState)(!0),[k,j]=(0,B.useState)(null),[te,M]=(0,B.useState)(null),[N,H]=(0,B.useState)(null),[U,W]=(0,B.useState)(null),[G,K]=(0,B.useState)(null),[q,J]=(0,B.useState)(new Set),pe=`specrails-desktop:loop-template-filter`,me=(()=>{try{let e=localStorage.getItem(pe),t=e?JSON.parse(e):null;return{query:typeof t?.query==`string`?t.query:``,categories:Array.isArray(t?.categories)?t.categories:[]}}catch{return{query:``,categories:[]}}})(),[Y,he]=(0,B.useState)(me.query),[X,ge]=(0,B.useState)(me.categories);(0,B.useEffect)(()=>{try{localStorage.setItem(pe,JSON.stringify({query:Y,categories:X}))}catch{}},[Y,X]);let _e=(0,B.useCallback)(e=>{ge(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),ve=(0,B.useCallback)(()=>{he(``),ge([])},[]),ye=(0,B.useRef)(null),{projects:be,setActiveProjectId:xe}=s(),Se=(0,B.useCallback)(e=>{J(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Z=(0,B.useCallback)(e=>{if(e.length===0)return;let t=new Blob([JSON.stringify(ie(e),null,2)],{type:`application/json`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=oe(e),r.click(),URL.revokeObjectURL(n)},[]),Ce=(0,B.useCallback)(async e=>{try{let n=await I.legacyGraph(e.id);Z([{...e,name:t(`actions.originalCopyName`,{name:e.name}),graph:n.graph}])}catch{c.error(t(`errors.exportLegacy`))}},[Z,t]),Q=(0,B.useCallback)(async()=>{try{let[e,t]=await Promise.all([I.list(),I.templates()]);f(e),h(t)}catch{c.error(t(`errors.load`))}finally{ee(!1)}},[t]);(0,B.useEffect)(()=>{Q()},[Q]);let we=(0,B.useCallback)(async e=>{try{let n=ae(await e.text()),{imported:r,skipped:i}=await I.importLoops(n);await Q(),r.length&&c.success(t(`import.done`,{count:r.length})),i.length&&c.warning(t(`import.skipped`,{count:i.length,names:i.join(`, `)})),!r.length&&!i.length&&c.warning(t(`import.invalid`))}catch(e){let n=e instanceof Error?e.message:``;c.error(t(n===`invalid-json`||n===`no-loops`?`import.invalid`:`errors.save`))}},[Q,t]),$=(0,B.useCallback)(t=>{e?e(t):n(`/loops/${t}/edit`)},[e,n]),Te=(0,B.useCallback)(async()=>{try{let e=await I.create({name:t(`newLoopName`)});$(e.id)}catch{c.error(t(`errors.save`))}},[t,$]),Ee=(0,B.useCallback)(async e=>{try{let t=await I.fromTemplate(e);$(t.id)}catch{c.error(t(`errors.save`))}},[t,$]),De=(0,B.useCallback)(async({projectId:e,provider:r,model:i,effort:a,repositoryIds:o})=>{let s=U;if(s){W(null);try{let{loopRunId:l}=await I.runStandalone(e,s.id,{aiEngine:r,model:i,reasoning_effort:a,...o?{repositoryIds:o}:{}});xe(e),n(`/jobs/${l}`),c.success(t(`run.launched`,{name:s.name}))}catch{c.error(t(`errors.save`))}}},[U,n,xe,t]),Oe=(0,B.useCallback)(async e=>{try{await I.publish(e),await Q()}catch(e){e instanceof P?c.error(t(`errors.publishInvalid`)):c.error(t(`errors.save`))}},[t,Q]),ke=(0,B.useCallback)(async e=>{try{await I.unpublish(e),await Q()}catch{c.error(t(`errors.save`))}},[t,Q]),Ae=(0,B.useCallback)(async e=>{try{await I.duplicate(e),await Q()}catch{c.error(t(`errors.save`))}},[t,Q]),je=(0,B.useCallback)(async()=>{let e=N;if(e){H(null);try{await I.restoreBuiltin(e),await Q(),c.success(t(`builder.builtin.restored`))}catch{c.error(t(`errors.save`))}}},[N,t,Q]),Me=(0,B.useCallback)(e=>j(e),[]),Ne=(0,B.useCallback)(async()=>{let e=k;if(e){j(null);try{await I.remove(e),await Q()}catch{c.error(t(`errors.save`))}}},[k,t,Q]),Pe=d.filter(e=>e.builtinId),Fe=d.filter(e=>!e.builtinId),Ie=Fe.filter(e=>e.status===`draft`),Le=Fe.filter(e=>e.status===`published`),Re=ce(m),ze=se(m.map(e=>({...e,searchTerms:`${l(e.id,e.name)} ${u(e.id,e.description)} ${e.category?t(`categories.${e.category}`,{defaultValue:e.category}):``}`})),{query:Y,categories:X}),Be=Y.trim()!==``||X.length>0;return(0,V.jsxs)(`div`,{className:`h-full overflow-y-auto`,children:[(0,V.jsxs)(`div`,{className:`max-w-5xl mx-auto px-6 py-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-start justify-between mb-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,V.jsx)(L,{className:`w-5 h-5 text-accent-primary`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h1`,{className:`text-lg font-semibold text-foreground`,children:t(`title`)}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:t(`subtitle`)})]})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[q.size>0&&(0,V.jsxs)(`button`,{type:`button`,onClick:()=>Z(d.filter(e=>q.has(e.id))),className:`inline-flex items-center gap-1.5 h-8 px-3 rounded-md text-xs font-medium border border-border text-foreground hover:bg-muted`,children:[(0,V.jsx)(z,{className:`w-3.5 h-3.5`}),t(`actions.export`),` (`,q.size,`)`]}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>ye.current?.click(),className:`inline-flex items-center gap-1.5 h-8 px-3 rounded-md text-xs font-medium border border-border text-foreground hover:bg-muted`,children:[(0,V.jsx)(ne,{className:`w-3.5 h-3.5`}),t(`actions.import`)]}),(0,V.jsx)(`input`,{ref:ye,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&we(t),e.target.value=``}}),(0,V.jsxs)(`button`,{type:`button`,onClick:Te,className:`inline-flex items-center gap-1.5 h-8 px-3 rounded-md text-xs font-medium bg-accent-primary text-white hover:bg-accent-primary/90`,children:[(0,V.jsx)(g,{className:`w-3.5 h-3.5`}),t(`newLoop`)]})]})]}),b?(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`…`}):(0,V.jsxs)(`div`,{className:`space-y-8`,children:[Ie.length===0&&Le.length===0&&(0,V.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-8 text-center`,children:[(0,V.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:t(`empty.title`)}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:t(`empty.body`)})]}),d.length>0&&(0,V.jsx)(re,{onConvert:e=>{let t=d.find(t=>t.id===e);t&&K(t)}}),Le.length>0&&(0,V.jsx)(de,{title:t(`sections.published`),children:Le.map(e=>(0,V.jsx)(fe,{loop:e,selected:q.has(e.id),onToggleSelect:()=>Se(e.id),onEdit:()=>$(e.id),onUnpublish:()=>ke(e.id),onDuplicate:()=>Ae(e.id),onExport:()=>Z([e]),onExportLegacy:e.hasLegacyGraph?()=>void Ce(e):void 0,onConvert:e.graph.nodes.some(e=>e.type===`core`)?void 0:()=>K(e),onDelete:()=>Me(e.id),onRun:F(e.graph)?void 0:()=>W(e)},e.id))}),Ie.length>0&&(0,V.jsx)(de,{title:t(`sections.drafts`),children:Ie.map(e=>(0,V.jsx)(fe,{loop:e,selected:q.has(e.id),onToggleSelect:()=>Se(e.id),onEdit:()=>$(e.id),onPublish:()=>Oe(e.id),onDuplicate:()=>Ae(e.id),onExport:()=>Z([e]),onExportLegacy:e.hasLegacyGraph?()=>void Ce(e):void 0,onConvert:e.graph.nodes.some(e=>e.type===`core`)?void 0:()=>K(e),onDelete:()=>Me(e.id)},e.id))}),Pe.length>0&&(0,V.jsx)(de,{title:t(`sections.builtIn`),children:Pe.map(e=>(0,V.jsx)(fe,{loop:{...e,name:e.builtinModified?e.name:l(e.id,e.name)},builtIn:!0,selected:q.has(e.id),onToggleSelect:()=>Se(e.id),onEdit:()=>$(e.id),onPublish:e.status===`draft`?()=>Oe(e.id):void 0,onDuplicate:()=>Ae(e.id),onExport:()=>Z([e]),onRestore:e.builtinModified?()=>H(e.id):void 0},e.id))}),m.length>0&&(0,V.jsxs)(`section`,{children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-3 mb-2 flex-wrap`,children:[(0,V.jsx)(`h2`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:t(`sections.templates`)}),(0,V.jsx)(`input`,{type:`search`,value:Y,onChange:e=>he(e.target.value),placeholder:t(`gallery.search`),"aria-label":t(`gallery.search`),"data-testid":`template-search`,className:`h-7 w-48 max-w-full rounded-md border border-border bg-surface/40 px-2.5 text-xs text-foreground placeholder:text-muted-foreground/70 focus:outline-none focus:ring-1 focus:ring-accent-primary`})]}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 mb-3`,"data-testid":`category-chips`,children:[Re.map(({category:e,count:n})=>{let r=X.includes(e);return(0,V.jsxs)(`button`,{type:`button`,"aria-pressed":r,onClick:()=>_e(e),className:D(`inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px] border transition-colors`,r?`border-accent-primary bg-accent-primary/15 text-accent-primary`:`border-border bg-surface/40 text-muted-foreground hover:text-foreground hover:bg-muted`),children:[t(`categories.${e}`,{defaultValue:e}),(0,V.jsx)(`span`,{className:`opacity-60 tabular-nums`,children:n})]},e)}),Be&&(0,V.jsx)(`button`,{type:`button`,onClick:ve,className:`inline-flex items-center h-6 px-2 rounded-full text-[11px] text-accent-primary hover:underline`,children:t(`gallery.clearFilter`)})]}),ze.length===0?(0,V.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-6 text-center`,"data-testid":`template-empty`,children:[(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`gallery.noResults`)}),(0,V.jsx)(`button`,{type:`button`,onClick:ve,className:`mt-2 text-xs text-accent-primary hover:underline`,children:t(`gallery.clearFilter`)})]}):(0,V.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:ze.map(e=>(0,V.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-3 flex flex-col gap-2`,"data-testid":`template-card`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(v,{className:`w-3.5 h-3.5 text-accent-highlight flex-shrink-0`}),(0,V.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate`,children:l(e.id,e.name)}),e.category&&(0,V.jsx)(`span`,{className:`ml-auto px-1.5 py-0.5 rounded text-[10px] bg-accent-info/15 text-accent-info flex-shrink-0`,children:t(`categories.${e.category}`,{defaultValue:e.category})})]}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground flex-1`,children:u(e.id,e.description)}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[F(e.graph)?(0,V.jsx)(`span`,{title:t(`gallery.needsSpecHint`),className:`px-1.5 py-0.5 rounded text-[10px] bg-accent-secondary/15 text-accent-secondary`,children:t(`gallery.needsSpec`)}):(0,V.jsx)(`span`,{title:t(`gallery.standaloneHint`),className:`px-1.5 py-0.5 rounded text-[10px] bg-accent-success/15 text-accent-success`,children:t(`gallery.standalone`)}),e.tags.map(e=>(0,V.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] bg-muted text-muted-foreground`,children:e},e))]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,V.jsxs)(`button`,{type:`button`,onClick:()=>M({...e,name:l(e.id,e.name),description:u(e.id,e.description)}),className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground`,children:[(0,V.jsx)(A,{className:`w-3 h-3`}),t(`actions.preview`)]}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>Ee(e.id),className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground`,children:[(0,V.jsx)(p,{className:`w-3 h-3`}),t(`actions.use`)]})]})]},e.id))})]})]})]}),(0,V.jsx)(E,{open:k!==null,onOpenChange:e=>{e||j(null)},children:(0,V.jsxs)(T,{className:`max-w-sm`,children:[(0,V.jsxs)(w,{children:[(0,V.jsxs)(C,{className:`flex items-center gap-2`,children:[(0,V.jsx)(y,{className:`w-4 h-4 text-destructive`}),d.find(e=>e.id===k)?.name??t(`actions.delete`)]}),(0,V.jsx)(S,{children:t(`confirmDelete`)})]}),(0,V.jsxs)(x,{children:[(0,V.jsx)(O,{variant:`ghost`,onClick:()=>j(null),children:t(`common:actions.cancel`)}),(0,V.jsx)(O,{variant:`destructive`,onClick:()=>void Ne(),children:t(`common:actions.delete`)})]})]})}),(0,V.jsx)(E,{open:N!==null,onOpenChange:e=>{e||H(null)},children:(0,V.jsxs)(T,{className:`max-w-sm`,children:[(0,V.jsxs)(w,{children:[(0,V.jsxs)(C,{className:`flex items-center gap-2`,children:[(0,V.jsx)(_,{className:`w-4 h-4`}),t(`builder.builtin.confirmTitle`)]}),(0,V.jsx)(S,{children:t(`builder.builtin.confirmBody`)})]}),(0,V.jsxs)(x,{children:[(0,V.jsx)(O,{variant:`ghost`,onClick:()=>H(null),children:t(`common:actions.cancel`)}),(0,V.jsx)(O,{"data-testid":`confirm-restore-builtin`,onClick:()=>void je(),children:t(`actions.restoreBuiltin`)})]})]})}),(0,V.jsx)(R,{template:te,onClose:()=>M(null),onUse:e=>{M(null),Ee(e)}}),G&&(0,V.jsx)(ue,{loop:G,projects:be,onClose:()=>K(null),onConverted:e=>{f(t=>t.map(t=>t.id===e.id?e:t)),K(null),$(e.id)}},G.id),(0,V.jsx)(le,{loop:U?{id:U.id,name:U.name}:null,projects:be.map(e=>({id:e.id,name:e.name,providers:o(e),repositories:e.repositories})),onClose:()=>W(null),onExecute:De})]})}function de({title:e,children:t}){return(0,V.jsxs)(`section`,{children:[(0,V.jsx)(`h2`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2`,children:e}),(0,V.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:t})]})}function fe({loop:e,builtIn:t=!1,selected:n,onToggleSelect:r,onEdit:a,onPublish:o,onUnpublish:s,onDuplicate:c,onExport:l,onExportLegacy:u,onConvert:d,onDelete:f,onRun:g,onRestore:v}){let{t:x}=i(`loops`),S=e.graph?.nodes?.length??0;return(0,V.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-3 flex flex-col gap-2`,"data-testid":t?`builtin-loop-card`:`loop-card`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:n,onChange:r,"aria-label":x(`actions.select`,{name:e.name}),className:`accent-accent-primary flex-shrink-0`}),(0,V.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate`,children:e.name})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[t&&(0,V.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] bg-muted text-muted-foreground`,"data-testid":`builtin-badge`,children:x(`builtInBadge`)}),(0,V.jsx)(K,{status:e.status})]})]}),(0,V.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[x(`card.nodes`,{count:S}),t&&e.builtinModified&&(0,V.jsxs)(`span`,{className:`ml-1.5 text-accent-secondary`,children:[`· `,x(`card.builtinModified`)]})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-1 flex-wrap`,children:[g&&(0,V.jsx)(J,{icon:h,label:x(`actions.run`),onClick:g}),(0,V.jsx)(J,{icon:m,label:x(`actions.edit`),onClick:a}),o&&(0,V.jsx)(J,{icon:b,label:x(`actions.publish`),onClick:o}),s&&(0,V.jsx)(J,{icon:p,label:x(`actions.unpublish`),onClick:s}),(0,V.jsx)(J,{icon:j,label:x(`actions.duplicate`),onClick:c}),(0,V.jsx)(J,{icon:z,label:x(`actions.export`),onClick:l}),u&&(0,V.jsx)(J,{icon:z,label:x(`actions.exportLegacy`),onClick:u}),d&&(0,V.jsx)(J,{icon:L,label:x(`actions.convert`),onClick:d}),v&&(0,V.jsx)(J,{icon:_,label:x(`actions.restoreBuiltin`),onClick:v}),f&&(0,V.jsx)(J,{icon:y,label:x(`actions.delete`),onClick:f,danger:!0})]})]})}function J({icon:e,label:t,onClick:n,danger:r}){return(0,V.jsx)(`button`,{type:`button`,onClick:n,title:t,"aria-label":t,className:D(`inline-flex items-center justify-center w-7 h-7 rounded-md transition-colors`,r?`text-muted-foreground hover:text-destructive hover:bg-destructive/10`:`text-muted-foreground hover:text-foreground hover:bg-muted`),children:(0,V.jsx)(e,{className:`w-3.5 h-3.5`})})}export{q as default};
@@ -1 +0,0 @@
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{u as i}from"./chunk-KS7C4IRE-DEKu087k.js";import{r as a}from"./useSharedWebSocket-BZMrX4jr.js";import{n as o,t as s}from"./createLucideIcon-Bjbbp_KS.js";import{r as c}from"./useDesktop-0unHDBJJ.js";import{t as l}from"./sparkles-DrY8hb0X.js";import{t as u}from"./x-CBMI9ejn.js";var d=s(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),f=s(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),p=s(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),m=s(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),h=s(`messages-square`,[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]),g=e(t(),1),_=[`title`,`description`,`labels`,`priority`,`acceptanceCriteria`,`repositoryIds`],v={title:``,description:``,labels:[],priority:`medium`,acceptanceCriteria:[]};function y(e){return!e||typeof e!=`object`?!1:e.type===`spec_draft.update`}var b=e(r(),1),x=n(),S=42;function C(e){let t=e.replace(/\s+/g,` `).trim();return t.length<=S?t:t.slice(0,S-1).trimEnd()+`…`}function w({chat:e,projectName:t,onRestore:n,onClose:r}){let{t:i}=o(`chat`),a=C(e.label);return(0,x.jsxs)(`div`,{"data-testid":`minimized-chat-chip-${e.id}`,className:`grid items-start gap-2 w-full max-w-full`,style:{gridTemplateColumns:`auto minmax(0, 1fr) auto`},children:[(0,x.jsx)(T,{kind:e.kind}),(0,x.jsxs)(`button`,{type:`button`,onClick:n,className:`min-w-0 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary/50 rounded overflow-hidden`,"aria-label":i(`chip.restore`,{label:e.label}),title:e.label,children:[(0,x.jsx)(`div`,{className:`text-sm font-medium text-foreground truncate`,children:a}),(0,x.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5 truncate`,children:i(`chip.continueEditing`,{projectName:t})})]}),(0,x.jsx)(`button`,{type:`button`,onClick:r,className:`flex items-center justify-center w-6 h-6 rounded text-muted-foreground hover:text-foreground hover:bg-accent/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary/50`,"aria-label":i(`chip.close`,{label:e.label}),children:(0,x.jsx)(u,{className:`w-3.5 h-3.5`})})]})}function T({kind:e}){let{t}=o(`chat`);return(0,x.jsx)(e===`ai-edit`?l:h,{className:`w-4 h-4 text-accent-primary flex-shrink-0 mt-0.5`,"aria-label":t(e===`ai-edit`?`chip.kindAiEdit`:`chip.kindExploreSpec`)})}function E({chats:e,projects:t,hidden:n,onRestore:r,onClose:i}){let{t:a}=o(`chat`),s=(0,g.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.id,n.name);return e},[t]),c=(0,g.useMemo)(()=>[...e].sort((e,t)=>t.createdAt-e.createdAt),[e]);return n||c.length===0?null:(0,b.createPortal)((0,x.jsxs)(`div`,{"data-testid":`minimized-chats-dock`,"aria-label":a(`dock.minimizedSessions`,{count:c.length}),className:`fixed bottom-4 right-14 z-[70] flex flex-col-reverse gap-2 w-[320px] max-w-[calc(100vw-15rem)] max-h-[70vh] overflow-y-auto pointer-events-none`,children:[c.map(e=>(0,x.jsx)(`div`,{className:`pointer-events-auto glass-card border border-border/30 rounded-lg p-3 shadow-lg w-full`,children:(0,x.jsx)(w,{chat:e,projectName:s.get(e.projectId)??a(`dock.unknownProject`),onRestore:()=>r(e.id),onClose:()=>i(e.id)})},e.id)),c.length>1&&(0,x.jsxs)(`div`,{className:`pointer-events-auto self-end inline-flex items-center gap-1 rounded-full bg-card/80 border border-border/40 px-2 py-0.5 text-[10px] text-muted-foreground backdrop-blur-sm`,children:[(0,x.jsx)(p,{className:`w-3 h-3`}),a(`dock.minimizedCount`,{count:c.length})]})]}),document.body)}var D=(0,g.createContext)(null),O=`specrails-desktop:minimized-chats`,k=`specrails-desktop:minimized-chats-pending`,A=50,j=8e3;function M(){return I(O)}function N(e){R(O,e)}function P(){return I(k)}function F(e){R(k,e)}function I(e){if(typeof window>`u`)return[];try{let t=window.localStorage.getItem(e);if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(z):[]}catch{return[]}}function L(e){return e.length<=A?e:[...e].sort((e,t)=>e.createdAt-t.createdAt).slice(e.length-A)}function R(e,t){if(!(typeof window>`u`))try{window.localStorage.setItem(e,JSON.stringify(L(t)))}catch{}}function z(e){if(!e||typeof e!=`object`)return!1;let t=e;return!(typeof t.id!=`string`||typeof t.projectId!=`string`||typeof t.label!=`string`||typeof t.restoreRoute!=`string`||typeof t.createdAt!=`number`||t.kind!==`explore-spec`&&t.kind!==`ai-edit`||!t.params||typeof t.params!=`object`)}function B(){return typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function V(e){return e.kind===`explore-spec`?e.params.resumeConversationId??`pending:${e.params.pendingSpecId}`:e.params.resumeRefineId??`agent:${e.params.agentId}`}function H(e,t){return e.kind!==t.kind||e.projectId!==t.projectId?!1:V(e)===V(t)}function U({children:e}){let{projects:t,activeProjectId:n,setActiveProjectId:r}=c(),o=i(),{registerHandler:s,unregisterHandler:l}=a(),[u,d]=(0,g.useState)(()=>M()),[f,p]=(0,g.useState)([]),m=(0,g.useRef)(u);m.current=u;let h=(0,g.useRef)(f);h.current=f;let _=(0,g.useRef)(new Map),v=(0,g.useRef)(t);v.current=t;let b=(0,g.useRef)(!1);(0,g.useEffect)(()=>{if(b.current)return;b.current=!0;let e=P();F([]),e.length!==0&&d(t=>{let n=[...t];for(let t of e)n.some(e=>e.id===t.id||H(e,t))||n.push(t);return N(n),m.current=n,n})},[]),(0,g.useEffect)(()=>{let e=_.current;return()=>{for(let t of e.values())clearTimeout(t);e.clear()}},[]),(0,g.useEffect)(()=>{N(u)},[u]),(0,g.useEffect)(()=>{F(f)},[f]);let S=(0,g.useRef)(()=>{}),C=(0,g.useRef)(()=>{});(0,g.useEffect)(()=>{let e=`minimized-chats:spec-draft`;return s(e,e=>{if(!y(e))return;let t=e.conversationId,n=m.current.find(e=>e.kind===`explore-spec`&&e.params.resumeConversationId===t);if(!n)return;let r=e.draft;r.title?.trim()&&S.current(n.id,r.title);let i={};r.title!==void 0&&(i.title=r.title),r.description!==void 0&&(i.description=r.description),r.priority!==void 0&&(i.priority=r.priority),r.labels!==void 0&&(i.labels=r.labels),r.repositoryIds!==void 0&&(i.repositoryIds=r.repositoryIds),r.acceptanceCriteria!==void 0&&(i.acceptanceCriteria=r.acceptanceCriteria),Object.keys(i).length>0&&C.current(n.id,i)}),()=>l(e)},[s,l]),(0,g.useEffect)(()=>{if(t.length===0)return;let e=new Set(t.map(e=>e.id));d(t=>{let n=t.filter(t=>e.has(t.projectId));return n.length===t.length?t:(N(n),m.current=n,n)}),p(t=>{let n=t.filter(t=>e.has(t.projectId));return n.length===t.length?t:(F(n),h.current=n,n)})},[t]);let w=(0,g.useCallback)(e=>{let t=B(),n={...e,id:t,createdAt:Date.now()};if(d(e=>{let t=L([...e.filter(e=>!H(e,n)),n]);return N(t),m.current=t,t}),e.kind===`explore-spec`){let t=e.params.resumeConversationId;t&&fetch(`/api/projects/${e.projectId}/chat/conversations/${t}/minimize`,{method:`POST`}).catch(()=>{})}return t},[]),T=(0,g.useCallback)(e=>{let t=_.current.get(e);t&&(clearTimeout(t),_.current.delete(e))},[]),O=(0,g.useCallback)(e=>{T(e),d(t=>{let n=t.filter(t=>t.id!==e);return N(n),m.current=n,n}),p(t=>{let n=t.filter(t=>t.id!==e);return n.length===t.length?t:(F(n),h.current=n,n)})},[T]),k=(0,g.useCallback)((e,t)=>{let n=t.trim();n&&d(t=>{let r=t.map(t=>t.id===e&&t.label!==n?{...t,label:n}:t);return r===t?t:(m.current=r,r)})},[]),A=(0,g.useCallback)((e,t)=>{d(n=>{let r=n.map(n=>{if(n.id!==e||n.kind!==`explore-spec`)return n;let r={...n.params.draftOverrides??{},...t};return{...n,params:{...n.params,draftOverrides:r}}});return m.current=r,r})},[]),I=(0,g.useCallback)(e=>{let t=m.current.find(t=>t.id===e);if(!t||v.current.length>0&&!v.current.some(e=>e.id===t.projectId))return;if(t.kind===`explore-spec`){let e=t.params.resumeConversationId;e&&fetch(`/api/projects/${t.projectId}/chat/conversations/${e}/restore`,{method:`POST`}).catch(()=>{})}n!==t.projectId&&r(t.projectId),o(t.restoreRoute),p(n=>{let r=[...n.filter(t=>t.id!==e),t];return F(r),h.current=r,r}),d(t=>{let n=t.filter(t=>t.id!==e);return N(n),m.current=n,n}),T(e);let i=setTimeout(()=>{_.current.delete(e),h.current.some(t=>t.id===e)&&(p(t=>{let n=t.filter(t=>t.id!==e);return F(n),h.current=n,n}),d(n=>{if(n.some(n=>n.id===e||H(n,t)))return n;let r=[...n,t];return N(r),m.current=r,r}))},j);_.current.set(e,i)},[n,r,o,T]),R=(0,g.useRef)(I);R.current=I;let z=(0,g.useRef)(O);z.current=O,S.current=k,C.current=A;let V=(0,g.useCallback)((e,t)=>{let n=h.current,r=n.findIndex(n=>n.kind===e&&n.projectId===t);if(r===-1)return null;let i=n[r];return T(i.id),p(e=>{let t=e.filter(e=>e.id!==i.id);return F(t),t}),h.current=n.filter(e=>e.id!==i.id),i},[T]),U=(0,g.useCallback)(e=>{let t=B(),i={...e,id:t,createdAt:Date.now()};n!==e.projectId&&r(e.projectId),o(e.restoreRoute),p(e=>{let t=[...e,i];return F(t),h.current=t,t}),T(t);let a=setTimeout(()=>{_.current.delete(t),h.current.some(e=>e.id===t)&&(p(e=>{let n=e.filter(e=>e.id!==t);return F(n),h.current=n,n}),d(e=>{if(e.some(e=>e.id===t||H(e,i)))return e;let n=[...e,i];return N(n),m.current=n,n}))},j);_.current.set(t,a)},[n,r,o,T]),W=(0,g.useMemo)(()=>({chats:u,pendingRestores:f,minimize:w,updateLabel:k,patchExploreSpecDraft:A,close:O,restore:I,takePendingRestore:V,triggerResume:U}),[u,f,w,k,A,O,I,V,U]);return(0,x.jsxs)(D.Provider,{value:W,children:[e,(0,x.jsx)(E,{chats:u,projects:t,hidden:!1,onRestore:I,onClose:O})]})}function W(){return(0,g.useContext)(D)||{chats:[],pendingRestores:[],minimize:()=>``,updateLabel:()=>{},patchExploreSpecDraft:()=>{},close:()=>{},restore:()=>{},takePendingRestore:()=>null,triggerResume:()=>{}}}function G(e,t,n){let{pendingRestores:r,takePendingRestore:i}=W(),a=(0,g.useRef)(n);a.current=n,(0,g.useEffect)(()=>{if(!t)return;let n=i(e,t);n&&a.current(n)},[r,e,t,i])}export{_ as a,m as c,d,v as i,p as l,W as n,y as o,G as r,h as s,U as t,f as u};