specrails-desktop 2.61.0 → 2.63.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 (230) hide show
  1. package/cli/dist/specrails-desktop.js +39 -5
  2. package/client/dist/assets/ActivityFeedPage-Bn2MpG5M.js +1 -0
  3. package/client/dist/assets/{AgentBrowserCapture-CkNWDZT3.js → AgentBrowserCapture-CHlXWdXq.js} +1 -1
  4. package/client/dist/assets/AgentModeAnalyticsPane-yj-YCgrK.js +2 -0
  5. package/client/dist/assets/AgentModeCodePane-Xczcyghb.js +2 -0
  6. package/client/dist/assets/{AgentModeJobsPane-U1J6PaBo.js → AgentModeJobsPane-DtOW01ln.js} +1 -1
  7. package/client/dist/assets/AgentsPage-BMfJ4mzU.js +118 -0
  8. package/client/dist/assets/AnalyticsPage-CGn5cgtc.js +1 -0
  9. package/client/dist/assets/BarChart-BDMqVFJy.js +55 -0
  10. package/client/dist/assets/CodePage-C8NIginr.js +3 -0
  11. package/client/dist/assets/DesktopAnalyticsPage-C87r4y26.js +1 -0
  12. package/client/dist/assets/{DocsDialog-CSlMPemn.js → DocsDialog-Z50a_KPv.js} +1 -1
  13. package/client/dist/assets/{DocsPage-BKlYAvWq.js → DocsPage-DIArbEPl.js} +1 -1
  14. package/client/dist/assets/{ExportDropdown-CweP_1GP.js → ExportDropdown-CJdCqYd7.js} +1 -1
  15. package/client/dist/assets/IntegrationsPage-EAipiDWm.js +1 -0
  16. package/client/dist/assets/InteractiveJobComposer-BxLh4me-.js +19 -0
  17. package/client/dist/assets/{JobDetailModal-DYyGq1Vp.js → JobDetailModal-C7dWoRu6.js} +1 -1
  18. package/client/dist/assets/JobDetailPage-Ilu294WS.js +1 -0
  19. package/client/dist/assets/JobsPage-fPq1hefb.js +1 -0
  20. package/client/dist/assets/LoopBuilderPage-5M7IypEP.js +1 -0
  21. package/client/dist/assets/{LoopPreviewModal-DkLRfsYX.js → LoopPreviewModal-ChI3NQC7.js} +1 -1
  22. package/client/dist/assets/{LoopWindowSurface-CuACkXFV.js → LoopWindowSurface-D1WB9i-9.js} +1 -1
  23. package/client/dist/assets/LoopsPage-CCwc0Biu.js +2 -0
  24. package/client/dist/assets/MinimizedChatsContext-eH_KaAZ1.js +1 -0
  25. package/client/dist/assets/PluginsPage-DfDfEfbW.js +2 -0
  26. package/client/dist/assets/ProjectSettingsDialog-9NHnG8JQ.js +1 -0
  27. package/client/dist/assets/RepositoryDeliveries-DgzNnJmn.js +5 -0
  28. package/client/dist/assets/{RepositoryScopeSelector-CeCr6Jz-.js → RepositoryScopeSelector-BSgUqk_u.js} +1 -1
  29. package/client/dist/assets/ReviewPacketPage-D34bGpSA.js +4 -0
  30. package/client/dist/assets/{TemplatePreviewModal-B8yd1AGU.js → TemplatePreviewModal-CcfSxWQ7.js} +1 -1
  31. package/client/dist/assets/TicketDetailModalContext-BoafEcm4.js +16 -0
  32. package/client/dist/assets/Trans-CVSryAL1.js +1 -0
  33. package/client/dist/assets/agent-5bSixVzz.js +1 -0
  34. package/client/dist/assets/agent-BR4EHfhq.js +1 -0
  35. package/client/dist/assets/agent-C0IKkJP8.js +1 -0
  36. package/client/dist/assets/agent-C7li9ayC.js +1 -0
  37. package/client/dist/assets/agent-D0dRmEen.js +1 -0
  38. package/client/dist/assets/{agent-BjttZLIl.js → agent-DZVGHm7H.js} +1 -1
  39. package/client/dist/assets/agent-Dip4h2YE.js +1 -0
  40. package/client/dist/assets/agent-Pp-P-n1p.js +1 -0
  41. package/client/dist/assets/ban-wqfdzoXt.js +1 -0
  42. package/client/dist/assets/{button-D1xExSTF.js → button-4FS1ZDTp.js} +1 -1
  43. package/client/dist/assets/chevron-up-6EFqEHBj.js +1 -0
  44. package/client/dist/assets/chunk-OB3PAWPO-B1EMk45A.js +3 -0
  45. package/client/dist/assets/circle-x-D2ttKotB.js +1 -0
  46. package/client/dist/assets/createLucideIcon-DtODIU64.js +1 -0
  47. package/client/dist/assets/{dialog-CMgps2MY.js → dialog-DtdR05v1.js} +1 -1
  48. package/client/dist/assets/download-C9wP_42h.js +1 -0
  49. package/client/dist/assets/external-link-CZ6Q-v1-.js +1 -0
  50. package/client/dist/assets/file-text-C0blZHLh.js +1 -0
  51. package/client/dist/assets/{formatDistanceToNow-DZ3VWsHq.js → formatDistanceToNow-NVM6rK3i.js} +1 -1
  52. package/client/dist/assets/{getTimezoneOffsetInMilliseconds-9JiGlFrx.js → getTimezoneOffsetInMilliseconds-ZHg7WpdH.js} +1 -1
  53. package/client/dist/assets/git-branch-yf6LE1Bw.js +1 -0
  54. package/client/dist/assets/index-Culan6y7.js +83 -0
  55. package/client/dist/assets/index-D1v33giW.css +2 -0
  56. package/client/dist/assets/jira-api-Bl8xEIpk.js +1 -0
  57. package/client/dist/assets/jsx-runtime-BbYvbtY8.js +1 -0
  58. package/client/dist/assets/layers-BCLTgHXO.js +1 -0
  59. package/client/dist/assets/{lib-C7Mhm-gT.js → lib-CQJT8S6Q.js} +1 -1
  60. package/client/dist/assets/{lib-CGdyxIWg.js → lib-DWJfei6y.js} +1 -1
  61. package/client/dist/assets/loader-circle-BqV9xYGf.js +1 -0
  62. package/client/dist/assets/{loop-layout-BF8xMiNv.js → loop-layout-CyXj9223.js} +1 -1
  63. package/client/dist/assets/pencil-CxrRbDwb.js +1 -0
  64. package/client/dist/assets/plus-fHDdjBk1.js +1 -0
  65. package/client/dist/assets/{project-repositories-CadLZOnr.js → project-repositories-CvJf1a6H.js} +1 -1
  66. package/client/dist/assets/react-dom-DDD8FYaU.js +1 -0
  67. package/client/dist/assets/rotate-ccw-DalJAQQX.js +1 -0
  68. package/client/dist/assets/save-LmPSfsvZ.js +1 -0
  69. package/client/dist/assets/search-BDVp3fkH.js +1 -0
  70. package/client/dist/assets/{settings-Dn-pXukr.js → settings-BO2N-oPf.js} +1 -1
  71. package/client/dist/assets/{settings-ByVE7jdZ.js → settings-BQChAs_w.js} +1 -1
  72. package/client/dist/assets/{settings-BBj_kZaD.js → settings-BzmYlcQB.js} +1 -1
  73. package/client/dist/assets/{settings-COlH_P33.js → settings-CGjXb6TX.js} +1 -1
  74. package/client/dist/assets/{settings-D77mC_Lb.js → settings-CMxEWY46.js} +1 -1
  75. package/client/dist/assets/{settings-DZKy7MqN.js → settings-C_dRSgI2.js} +1 -1
  76. package/client/dist/assets/{settings-B5Hy_Kol.js → settings-Hw7av-B1.js} +1 -1
  77. package/client/dist/assets/settings-nryN6wuS.js +1 -0
  78. package/client/dist/assets/sparkles-CCfUdFGY.js +1 -0
  79. package/client/dist/assets/spending-BfjSJjBd.js +1 -0
  80. package/client/dist/assets/square-D0JTbRSR.js +1 -0
  81. package/client/dist/assets/trash-D8zYUmTg.js +1 -0
  82. package/client/dist/assets/triangle-alert-Cxpn8bqr.js +1 -0
  83. package/client/dist/assets/upload-CCHvUkRs.js +1 -0
  84. package/client/dist/assets/{useDesktop-DKNbOF0u.js → useDesktop-C5JVBeur.js} +1 -1
  85. package/client/dist/assets/{useRuntimeRuns-D3YMw9qx.js → useRuntimeRuns-DohBmeg8.js} +1 -1
  86. package/client/dist/assets/useSharedWebSocket-CNOvmgTr.js +2 -0
  87. package/client/dist/assets/{value-s-gzBeyF.js → value-DtOOK0wQ.js} +1 -1
  88. package/client/dist/assets/x-Bu7X_eR2.js +1 -0
  89. package/client/dist/assets/zap-bugHyWzQ.js +1 -0
  90. package/client/dist/index.html +44 -41
  91. package/docs/ci-cd.md +8 -1
  92. package/docs/customizing.md +1 -0
  93. package/docs/getting-started.md +1 -1
  94. package/docs/guide/de/integrations/6-agent-chat.md +11 -0
  95. package/docs/guide/de/settings/5-project-environment.md +27 -0
  96. package/docs/guide/en/integrations/6-agent-chat.md +11 -0
  97. package/docs/guide/en/settings/5-project-environment.md +27 -0
  98. package/docs/guide/es/integrations/6-agent-chat.md +11 -0
  99. package/docs/guide/es/settings/5-project-environment.md +27 -0
  100. package/docs/guide/fr/integrations/6-agent-chat.md +11 -0
  101. package/docs/guide/fr/settings/5-project-environment.md +27 -0
  102. package/docs/guide/it/integrations/6-agent-chat.md +11 -0
  103. package/docs/guide/it/settings/5-project-environment.md +27 -0
  104. package/docs/guide/ja/integrations/6-agent-chat.md +11 -0
  105. package/docs/guide/ja/settings/5-project-environment.md +27 -0
  106. package/docs/guide/pt/integrations/6-agent-chat.md +11 -0
  107. package/docs/guide/pt/settings/5-project-environment.md +27 -0
  108. package/docs/guide/zh/integrations/6-agent-chat.md +11 -0
  109. package/docs/guide/zh/settings/5-project-environment.md +27 -0
  110. package/docs/internals/README.md +1 -0
  111. package/docs/internals/agent-sessions.md +157 -0
  112. package/docs/internals/api-reference.md +35 -4
  113. package/docs/internals/configuration.md +80 -5
  114. package/docs/internals/core-runtime-updates.md +10 -3
  115. package/docs/internals/operations-runbook.md +11 -0
  116. package/docs/internals/programmatic-agent-runtime.md +1 -1
  117. package/docs/internals/safe-pr-review-flow.md +15 -0
  118. package/docs/internals/source-map.md +42 -1
  119. package/docs/mcp.md +1 -1
  120. package/docs/platforms/macos.md +2 -0
  121. package/docs/platforms/windows-parity.md +4 -4
  122. package/docs/platforms/windows.md +9 -9
  123. package/local-runner/dist/specrails-local-runner.js +1 -1
  124. package/mcp-bridge/dist/specrails-mcp.js +82 -15
  125. package/package.json +8 -9
  126. package/server/dist/agent-mcp-config.js +41 -0
  127. package/server/dist/core-compat.js +2 -0
  128. package/server/dist/desktop-db.js +101 -4
  129. package/server/dist/desktop-router.js +31 -2
  130. package/server/dist/index.js +58 -0
  131. package/server/dist/mcp/tools/app-settings.js +11 -0
  132. package/server/dist/mcp/tools/env.js +38 -3
  133. package/server/dist/mcp/tools/mission.js +45 -2
  134. package/server/dist/mcp/tools/specs.js +2 -2
  135. package/server/dist/modules/accounting/runtime/result-event.js +9 -1
  136. package/server/dist/modules/agent-runtime/runtime/agent-runtime-controls.js +25 -0
  137. package/server/dist/modules/agent-sessions/adapters/host-process.js +73 -0
  138. package/server/dist/modules/agent-sessions/adapters/http.js +31 -0
  139. package/server/dist/modules/agent-sessions/adapters/rpc-client.js +147 -0
  140. package/server/dist/modules/agent-sessions/application/session-event-pump.js +99 -0
  141. package/server/dist/modules/agent-sessions/domain/availability.js +25 -0
  142. package/server/dist/modules/agent-sessions/domain/errors.js +23 -0
  143. package/server/dist/modules/agent-sessions/domain/host-state.js +80 -0
  144. package/server/dist/modules/agent-sessions/domain/projection.js +147 -0
  145. package/server/dist/modules/agent-sessions/domain/protocol.js +59 -0
  146. package/server/dist/modules/agent-sessions/domain/subagent-policy.js +34 -0
  147. package/server/dist/modules/agent-sessions/index.js +31 -0
  148. package/server/dist/modules/agent-sessions/ports.js +2 -0
  149. package/server/dist/modules/agent-sessions/runtime/core-sessions-availability.js +43 -0
  150. package/server/dist/modules/agent-sessions/runtime/session-host-registry.js +226 -0
  151. package/server/dist/modules/agents/runtime/agent-store.js +3 -1
  152. package/server/dist/modules/execution/runtime/queue-manager.js +8 -0
  153. package/server/dist/modules/loops/runtime/loop-executors.js +1 -0
  154. package/server/dist/modules/loops/runtime/loop-implement-recipe.js +15 -4
  155. package/server/dist/modules/loops/runtime/loop-run-manager.js +11 -0
  156. package/server/dist/modules/missions/runtime/agent-chat-manager.js +137 -40
  157. package/server/dist/modules/missions/runtime/agent-chat-router.js +68 -0
  158. package/server/dist/modules/missions/runtime/agent-operator-prompt.js +8 -9
  159. package/server/dist/modules/missions/runtime/agent-session-store.js +133 -0
  160. package/server/dist/modules/missions/runtime/core-session-runner.js +204 -0
  161. package/server/dist/modules/missions/runtime/mission-core-sessions.js +286 -0
  162. package/server/dist/modules/missions/runtime/mission-session-projector.js +168 -0
  163. package/server/dist/modules/project-settings/adapters/http.js +38 -2
  164. package/server/dist/modules/project-settings/adapters/sqlite.js +30 -2
  165. package/server/dist/modules/project-settings/domain.js +24 -0
  166. package/server/dist/modules/project-settings/index.js +2 -1
  167. package/server/dist/modules/specs/runtime/spec-models.js +1 -1
  168. package/server/dist/path-resolver.js +135 -20
  169. package/server/dist/plugins/codex-spawn.js +15 -7
  170. package/server/dist/project-env.js +265 -17
  171. package/server/dist/project-registry.js +46 -0
  172. package/server/dist/project-router-settings.js +24 -1
  173. package/server/dist/providers/claude-adapter.js +6 -1
  174. package/server/dist/worktree-node-modules.js +95 -1
  175. package/client/dist/assets/ActivityFeedPage-Wi5XNgoG.js +0 -1
  176. package/client/dist/assets/AgentModeAnalyticsPane-CXz2j-Bt.js +0 -2
  177. package/client/dist/assets/AgentModeCodePane-DnsBPtpS.js +0 -2
  178. package/client/dist/assets/AgentsPage-CXrqu5vo.js +0 -118
  179. package/client/dist/assets/AnalyticsPage-Cvtt-LOO.js +0 -1
  180. package/client/dist/assets/BarChart-nBOMNfiy.js +0 -33
  181. package/client/dist/assets/CodePage-D35o-MFO.js +0 -3
  182. package/client/dist/assets/DesktopAnalyticsPage-CsDFy5rp.js +0 -1
  183. package/client/dist/assets/IntegrationsPage-Bhy58lnQ.js +0 -1
  184. package/client/dist/assets/InteractiveJobComposer-CFKvbQeJ.js +0 -19
  185. package/client/dist/assets/JobDetailPage-C6gpdYvj.js +0 -1
  186. package/client/dist/assets/JobsPage-CgS0pnKd.js +0 -1
  187. package/client/dist/assets/LoopBuilderPage-jUp20DSZ.js +0 -1
  188. package/client/dist/assets/LoopsPage-ClSrWzDd.js +0 -2
  189. package/client/dist/assets/MinimizedChatsContext-CroAs6Kh.js +0 -1
  190. package/client/dist/assets/PluginsPage-nCKQOwRL.js +0 -2
  191. package/client/dist/assets/ProjectSettingsDialog-BVDYwllU.js +0 -1
  192. package/client/dist/assets/RepositoryDeliveries-DJCm1pZr.js +0 -5
  193. package/client/dist/assets/ReviewPacketPage-kTErrEjx.js +0 -4
  194. package/client/dist/assets/TicketDetailModalContext-YBJX3RmP.js +0 -16
  195. package/client/dist/assets/Trans-D5eOjfvG.js +0 -1
  196. package/client/dist/assets/agent--8QAfoXL.js +0 -1
  197. package/client/dist/assets/agent-3HxXkIWX.js +0 -1
  198. package/client/dist/assets/agent-CpFCz32T.js +0 -1
  199. package/client/dist/assets/agent-DVnw6ybO.js +0 -1
  200. package/client/dist/assets/agent-Z5s_GTP0.js +0 -1
  201. package/client/dist/assets/agent-hv57-zyG.js +0 -1
  202. package/client/dist/assets/agent-xGrZ_aN1.js +0 -1
  203. package/client/dist/assets/chunk-KS7C4IRE-DEKu087k.js +0 -3
  204. package/client/dist/assets/circle-x-CMYsN4ZH.js +0 -1
  205. package/client/dist/assets/createLucideIcon-Bjbbp_KS.js +0 -1
  206. package/client/dist/assets/download-CFHyyHcw.js +0 -1
  207. package/client/dist/assets/external-link-D6XxC_Cu.js +0 -1
  208. package/client/dist/assets/file-text-BcLCfcWZ.js +0 -1
  209. package/client/dist/assets/git-branch-BRM0F5GN.js +0 -1
  210. package/client/dist/assets/index-Bfunvi6w.css +0 -2
  211. package/client/dist/assets/index-lTGJJTuk.js +0 -83
  212. package/client/dist/assets/jira-api-Bp0zXwjg.js +0 -1
  213. package/client/dist/assets/jsx-runtime-zu2_FqZY.js +0 -1
  214. package/client/dist/assets/loader-circle-DcygOQpC.js +0 -1
  215. package/client/dist/assets/pencil-C9RkrIPZ.js +0 -1
  216. package/client/dist/assets/plus-CsnjfkmX.js +0 -1
  217. package/client/dist/assets/react-dom-DiWzBDP9.js +0 -1
  218. package/client/dist/assets/rotate-ccw-Wh4id13q.js +0 -1
  219. package/client/dist/assets/save-OsUqVn99.js +0 -1
  220. package/client/dist/assets/search-Cq_gE3Ik.js +0 -1
  221. package/client/dist/assets/settings-Dbyd6gmj.js +0 -1
  222. package/client/dist/assets/sparkles-DrY8hb0X.js +0 -1
  223. package/client/dist/assets/spending-DQDNtM8q.js +0 -1
  224. package/client/dist/assets/square-Ci-PFcFe.js +0 -1
  225. package/client/dist/assets/trash-2-BOU3WdZZ.js +0 -1
  226. package/client/dist/assets/triangle-alert-H9T4jAmh.js +0 -1
  227. package/client/dist/assets/upload-DYMjAQ6M.js +0 -1
  228. package/client/dist/assets/useSharedWebSocket-DaWuiO0S.js +0 -2
  229. package/client/dist/assets/x-CBMI9ejn.js +0 -1
  230. package/client/dist/assets/zap-CUOlvtT1.js +0 -1
@@ -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-DaWuiO0S.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-DKNbOF0u.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{F as _,P as v,a as y,i as b,l as x,o as ee,r as te,t as ne}from"./dialog-CMgps2MY.js";import{n as re,t as ie}from"./lib-CGdyxIWg.js";import{t as S}from"./formatDistanceToNow-DZ3VWsHq.js";import{t as C}from"./button-D1xExSTF.js";import{Gt as w,K as T,S as E,Wt as ae,Y as D,jt as oe,k as se,q as O,t as k}from"./index-lTGJJTuk.js";import{t as A}from"./format-command-C0D9IPmV.js";import{t as j}from"./ExportDropdown-CweP_1GP.js";import{n as M,t as N}from"./job-time-BCL7wee9.js";var ce=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`}]]),P=e(t(),1),F=n();function I(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 L(e){return e==null?`—`:e===0?`$0`:e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(3)}`}function R(e){return e==null?`—`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function z({label:e,a:t,b:n,highlight:r}){return(0,F.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 py-2 border-b border-border/20 last:border-0 text-xs`,children:[(0,F.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,F.jsx)(`span`,{className:`font-mono text-right ${r===`a`?`text-emerald-400 aurora-light:text-accent-success font-semibold`:``}`,children:t}),(0,F.jsx)(`span`,{className:`font-mono text-right ${r===`b`?`text-emerald-400 aurora-light:text-accent-success font-semibold`:``}`,children:n})]})}function B(e,t,n=!0){return e==null||t==null||e===t?null:n?e<t?`a`:`b`:e>t?`a`:`b`}function le({jobIds:e,onClose:t}){let{t:n}=s(`jobs`),[r,i]=(0,P.useState)(null),[a,o]=(0,P.useState)(!0),[c,u]=(0,P.useState)(null),{panelRef:d,panelStyle:f,headerHandleProps:m,resizeHandles:h,isFloating:y,guardBackdrop:b}=_();(0,P.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,F.jsxs)(`div`,{className:`text-center space-y-1`,children:[(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground font-medium uppercase tracking-wider`,children:n(`comparison.jobN`,{n:t+1})}),(0,F.jsx)(`code`,{className:`text-[10px] text-foreground/70 block truncate max-w-[160px] mx-auto`,children:e.command}),(0,F.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-[10px]`,children:[e.status===`completed`?(0,F.jsx)(w,{className:`w-3 h-3 text-emerald-400 aurora-light:text-accent-success`}):(0,F.jsx)(p,{className:`w-3 h-3 text-rose-400 aurora-light:text-destructive`}),(0,F.jsx)(`span`,{className:`capitalize text-muted-foreground`,children:n(`statusLabel.${e.status}`,{defaultValue:e.status})})]}),(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground font-mono`,children:e.id.slice(0,8)})]})}return(0,F.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:b(t),children:[(0,F.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,F.jsxs)(`div`,{className:`flex items-center justify-between ${y?`cursor-grab active:cursor-grabbing`:``}`,...m,children:[(0,F.jsx)(`h2`,{className:`text-sm font-semibold`,children:n(`comparison.title`)}),(0,F.jsx)(`button`,{type:`button`,onClick:t,className:`text-muted-foreground hover:text-foreground transition-colors`,children:(0,F.jsx)(g,{className:`w-4 h-4`})})]}),a&&(0,F.jsx)(`div`,{className:`space-y-2`,children:[0,1,2,3].map(e=>(0,F.jsx)(`div`,{className:`h-8 bg-muted/20 rounded animate-pulse`},e))}),c&&(0,F.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=B(e.durationMs,t.durationMs,!0),a=B(e.totalCostUsd,t.totalCostUsd,!0),o=B(e.tokensOut==null?null:e.tokensOut,t.tokensOut==null?null:t.tokensOut,!0);return(0,F.jsxs)(`div`,{children:[(0,F.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 pb-3 border-b border-border/30 mb-1`,children:[(0,F.jsx)(`div`,{}),x(e,0),x(t,1)]}),(0,F.jsx)(z,{label:n(`comparison.duration`),a:I(e.durationMs),b:I(t.durationMs),highlight:i}),(0,F.jsx)(z,{label:n(`comparison.cost`),a:L(e.totalCostUsd),b:L(t.totalCostUsd),highlight:a}),(0,F.jsx)(z,{label:n(`comparison.tokensOut`),a:R(e.tokensOut),b:R(t.tokensOut),highlight:o}),(0,F.jsx)(z,{label:n(`comparison.tokensIn`),a:R(e.tokensIn),b:R(t.tokensIn),highlight:null}),(0,F.jsx)(z,{label:n(`comparison.cacheRead`),a:R(e.tokensCacheRead),b:R(t.tokensCacheRead),highlight:null}),(0,F.jsx)(z,{label:n(`comparison.model`),a:e.model??`—`,b:t.model??`—`,highlight:null}),(0,F.jsx)(z,{label:n(`comparison.phasesDone`),a:e.phasesCompleted.length>0?e.phasesCompleted.join(`, `):`—`,b:t.phasesCompleted.length>0?t.phasesCompleted.join(`, `):`—`,highlight:null})]})})(),r&&(0,F.jsx)(`p`,{className:`text-[10px] text-muted-foreground/60 text-center`,children:n(`comparison.betterValueHint`)})]}),(0,F.jsx)(v,{handles:h})]})}var V={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=M(e),r=M(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=M(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=M(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,w]=(0,P.useState)(null),[E,k]=(0,P.useState)(``),[j,M]=(0,P.useState)(``),[I,L]=(0,P.useState)(!1),[R,z]=(0,P.useState)(``),[B,U]=(0,P.useState)(``),[W,G]=(0,P.useState)(!1),[K,q]=(0,P.useState)(null),[J,ye]=(0,P.useState)(H),[Y,be]=(0,P.useState)(!1),[X,Z]=(0,P.useState)([]),[xe,Q]=(0,P.useState)(null),{panelRef:Se,panelStyle:Ce,headerHandleProps:we,resizeHandles:Te,isFloating:Ee,guardBackdrop:De}=_();(0,P.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(N(e),E,j)),Ae=e.filter(e=>ve(N(e),R,B)).length;async function je(e){G(!0);try{let t={};e===`range`&&(R&&(t.from=new Date(ge(R)).toISOString()),B&&(t.to=new Date(_e(B)).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})),L(!1),z(``),U(``),a?.()}else f.error(u(`recent.toast.clearFailed`))}catch{f.error(u(`recent.toast.networkError`))}finally{G(!1)}}let Me=n?(0,F.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,F.jsx)(h,{className:`h-4 w-4 shrink-0`}),(0,F.jsx)(`span`,{className:`flex-1`,children:u(`recent.loadFailed`)}),i&&(0,F.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,F.jsx)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4`,children:Me}):t&&e.length===0?(0,F.jsx)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4 space-y-1`,children:[0,1,2].map(e=>(0,F.jsx)(`div`,{className:`h-9 bg-muted/30 rounded-md animate-pulse`},e))}):e.length===0?(0,F.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border/40 bg-card/50 p-8 text-center space-y-2`,children:[(0,F.jsx)(ae,{className:`w-8 h-8 text-muted-foreground/30 mx-auto`}),(0,F.jsx)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:u(`recent.emptyTitle`)}),(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground/60`,children:u(`recent.emptyDescription`)})]}):(0,F.jsxs)(`div`,{className:`rounded-lg border border-border/40 bg-card/50 p-4 space-y-2`,children:[Me,(0,F.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,F.jsx)(`button`,{type:`button`,onClick:()=>w(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,F.jsx)(`button`,{type:`button`,onClick:()=>w(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,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(`input`,{type:`date`,value:E,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,F.jsx)(`input`,{type:`date`,value:j,onChange:e=>M(e.target.value),className:`h-6 rounded border border-border bg-input px-1.5 text-[10px] text-foreground`,title:u(`recent.toDate`)}),(E||j)&&(0,F.jsx)(`button`,{type:`button`,onClick:()=>{k(``),M(``)},className:`text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:u(`recent.clear`)}),(0,F.jsxs)(T,{children:[(0,F.jsx)(D,{asChild:!0,children:(0,F.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,F.jsx)(ce,{className:`w-3.5 h-3.5`})})}),(0,F.jsx)(O,{children:u(Y?`recent.exitCompareMode`:`recent.compareTwoJobs`)})]}),(0,F.jsxs)(T,{children:[(0,F.jsx)(D,{asChild:!0,children:(0,F.jsx)(C,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-muted-foreground hover:text-destructive`,onClick:()=>L(!0),children:(0,F.jsx)(m,{className:`w-3.5 h-3.5`})})}),(0,F.jsx)(O,{children:u(`recent.clearJobs`)})]})]})]}),Y&&(0,F.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,F.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,F.jsx)(`button`,{type:`button`,className:`text-[10px] font-medium text-foreground hover:underline`,onClick:()=>Q(X),children:u(`recent.compareAction`)})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-1 text-[10px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,F.jsx)(`span`,{className:`w-14`,children:u(`recent.colStatus`)}),(0,F.jsx)(`span`,{className:`flex-1 min-w-0`,children:u(`recent.colCommand`)}),(0,F.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[(0,F.jsx)(`span`,{className:`w-14 text-right`,children:u(`recent.colDuration`)}),(0,F.jsx)(`span`,{className:`w-12 text-right`,children:u(`recent.colTokens`)}),(0,F.jsx)(`span`,{className:`w-12 text-right`,children:u(`recent.colCost`)}),(0,F.jsx)(`span`,{className:`w-20 text-right`,children:u(`recent.colStarted`)})]})]}),(0,F.jsx)(`div`,{className:`space-y-0.5`,children:$.slice(0,J).map(e=>{let t=V[e.status]??V.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,F.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,F.jsxs)(T,{children:[(0,F.jsx)(D,{asChild:!0,children:(0,F.jsx)(`div`,{children:(0,F.jsx)(se,{variant:t.variant,children:u(t.labelKey)})})}),(0,F.jsx)(O,{children:u(t.tooltipKey)})]}),e.priority&&e.priority!==`normal`&&(0,F.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,F.jsxs)(T,{children:[(0,F.jsx)(D,{asChild:!0,children:(0,F.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,F.jsx)(O,{children:u(`recent.profileTooltip`,{name:e.profile_name})})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-1 flex-1 min-w-0`,children:[e.pipeline_id&&(0,F.jsxs)(T,{children:[(0,F.jsx)(D,{asChild:!0,children:(0,F.jsx)(oe,{className:`w-3 h-3 text-accent-primary/60 shrink-0`})}),(0,F.jsxs)(O,{children:[u(`recent.pipelinePart`),e.depends_on_job_id&&` ${u(`recent.pipelineDependsOn`)}`,e.skip_reason&&` — ${e.skip_reason}`]})]}),(0,F.jsx)(`code`,{className:`text-xs text-foreground/80 truncate`,children:A(e.command,ie)})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-3 text-[10px] text-muted-foreground shrink-0`,children:[(0,F.jsx)(`span`,{className:`w-14 text-right`,children:r??`—`}),(0,F.jsx)(`span`,{className:`w-12 text-right`,children:i?`${i}`:`—`}),(0,F.jsx)(`span`,{className:`w-12 text-right`,children:n??`—`}),(0,F.jsx)(`span`,{className:`w-20 text-right`,children:e.status===`queued`?`—`:he(e.started_at)}),a&&s&&(0,F.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,F.jsx)(m,{className:`w-3 h-3`})})]})]},e.id)})}),$.length>J&&(0,F.jsx)(`div`,{className:`pt-1 text-center`,children:(0,F.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})})}),I&&(0,F.jsxs)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:De(()=>L(!1)),children:[(0,F.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,F.jsxs)(`div`,{...we,className:Ee?`cursor-grab active:cursor-grabbing`:void 0,children:[(0,F.jsx)(`h3`,{className:`text-sm font-semibold`,children:u(`recent.clearModal.title`)}),(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:u(`recent.clearModal.jobsInHistory`,{count:e.length})})]}),(0,F.jsx)(C,{variant:`destructive`,size:`sm`,className:`w-full`,disabled:W,onClick:()=>je(`all`),children:u(`recent.clearModal.clearAll`,{count:e.length})}),(0,F.jsxs)(`div`,{className:`space-y-2`,children:[(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:u(`recent.clearModal.orByRange`)}),(0,F.jsxs)(`div`,{className:`flex gap-2`,children:[(0,F.jsx)(`input`,{type:`date`,value:R,onChange:e=>z(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,F.jsx)(`input`,{type:`date`,value:B,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,F.jsx)(C,{variant:`outline`,size:`sm`,className:`w-full`,disabled:W||!R&&!B,onClick:()=>je(`range`),children:R||B?u(`recent.clearModal.clearInRange`,{count:Ae}):u(`recent.clearModal.clearRange`)})]}),(0,F.jsx)(C,{variant:`ghost`,size:`sm`,className:`w-full`,onClick:()=>L(!1),children:u(`common:actions.cancel`)})]}),(0,F.jsx)(v,{handles:Te})]}),(0,F.jsx)(ne,{open:K!==null,onOpenChange:e=>!e&&q(null),children:(0,F.jsxs)(te,{className:`max-w-sm`,children:[(0,F.jsxs)(ee,{children:[(0,F.jsx)(x,{children:u(`recent.deleteProposalConfirm.title`)}),(0,F.jsx)(b,{children:u(`recent.deleteProposalConfirm.description`)})]}),(0,F.jsxs)(y,{children:[(0,F.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>q(null),children:u(`common:actions.cancel`)}),(0,F.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{K&&c?.(K),q(null)},children:u(`common:actions.delete`)})]})]})}),xe&&(0,F.jsx)(le,{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,P.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,P.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:v,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}),ae={input:`queued`,exploring:`running`,review:`running`,refining:`running`,creating_issue:`running`,created:`completed`,cancelled:`canceled`},D=v.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:ae[e.status]??`queued`})),oe=[...p,...D].sort((e,t)=>(M(N(t))?.getTime()??0)-(M(N(e))?.getTime()??0)),[O,A]=(0,P.useState)(null),ce=(0,P.useCallback)(async e=>{try{let t=await fetch(`${l()}/propose/${e}`);if(!t.ok)return;let n=await t.json();A(n.proposal)}catch{}},[]),I=(0,P.useCallback)(async e=>{try{(await fetch(`${l()}/propose/${e}`,{method:`DELETE`})).ok&&(f.success(i(`page.proposalDeleted`)),await T())}catch{}},[T,i]);return(0,F.jsxs)(`div`,{className:`max-w-4xl mx-auto px-4 py-6`,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,F.jsx)(`h1`,{className:`text-sm font-semibold`,children:i(`page.title`)}),(0,F.jsx)(j,{baseUrl:`${l()}/jobs/export`,label:i(`page.exportJobs`)})]}),a&&(0,F.jsxs)(`details`,{className:`mb-4 rounded-lg border border-border`,onToggle:e=>t(e.currentTarget.open),children:[(0,F.jsx)(`summary`,{className:`cursor-pointer p-3 text-sm`,children:i(`agentRuntime:runs.title`)}),e&&(0,F.jsx)(E,{projectId:a})]}),(0,F.jsx)(U,{jobs:oe,isLoading:m||b||h||S,error:g??w,onRetry:()=>{Promise.all([_(),T()])},onJobsCleared:_,onProposalClick:ce,onProposalDelete:I}),(0,F.jsx)(ne,{open:O!==null,onOpenChange:e=>!e&&A(null),children:(0,F.jsx)(te,{className:`max-w-3xl glass-card`,children:O&&(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(ee,{children:(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(x,{className:`flex-1 min-w-0`,children:i(`page.proposal.title`)}),(0,F.jsx)(se,{variant:O.status===`created`?`success`:O.status===`cancelled`?`destructive`:`secondary`,children:i(W[O.status]??`page.proposal.status.unknown`,{status:O.status})})]})}),(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground bg-muted/20 rounded px-2 py-1 italic`,children:O.idea}),O.result_markdown?(0,F.jsx)(`div`,{className:`max-h-[400px] overflow-y-auto rounded-lg px-3 py-2 text-xs bg-muted/40`,children:(0,F.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,F.jsx)(re,{remarkPlugins:[ie],children:O.result_markdown})})}):(0,F.jsx)(`p`,{className:`text-xs text-muted-foreground py-4 text-center`,children:i(`page.proposal.noContent`)}),O.issue_url&&(0,F.jsxs)(`div`,{className:`text-xs`,children:[i(`page.proposal.githubIssue`),` `,(0,F.jsx)(`a`,{href:O.issue_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-accent-primary hover:underline`,children:O.issue_url})]}),(0,F.jsxs)(y,{children:[(0,F.jsx)(C,{variant:`destructive`,size:`sm`,onClick:()=>{I(O.id),A(null)},children:i(`common:actions.delete`)}),(0,F.jsx)(C,{variant:`ghost`,size:`sm`,onClick:()=>A(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-DKNbOF0u.js";import{r as u}from"./provider-capabilities-lePfeT_Y.js";import{n as d,r as f,t as p}from"./save-OsUqVn99.js";import{t as m}from"./external-link-D6XxC_Cu.js";import{t as h}from"./git-branch-BRM0F5GN.js";import{n as g,t as _}from"./square-Ci-PFcFe.js";import{t as v}from"./plus-CsnjfkmX.js";import{t as ee}from"./rotate-ccw-Wh4id13q.js";import{t as y}from"./trash-2-BOU3WdZZ.js";import{t as te}from"./triangle-alert-H9T4jAmh.js";import{t as ne}from"./upload-DYMjAQ6M.js";import{t as re}from"./x-CBMI9ejn.js";import{a as ie,i as ae,l as oe,o as b,r as x,t as se}from"./dialog-CMgps2MY.js";import{t as S}from"./utils-BC4DHlz2.js";import{t as C}from"./button-D1xExSTF.js";import{n as w,t as T}from"./project-repositories-CadLZOnr.js";import{Ft as ce,J as le,K as ue,Mt as de,U as E,Ut as fe,Vt as pe,Y as me,Yt as he,bt as ge,c as D,d as _e,f as ve,gt as O,in as ye,it as k,l as A,m as j,ot as M,p as be,q as xe,rn as Se,rt as Ce,tn as we,u as N,xt as P,zt as Te}from"./index-lTGJJTuk.js";import{a as Ee,c as De,d as Oe,f as ke,i as F,l as Ae,m as I,n as je,o as Me,p as Ne,r as Pe,s as Fe,t as Ie,u as Le}from"./loop-layout-BF8xMiNv.js";var Re=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`}]]),ze=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`}]]),Be=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`}]]),L=e(t(),1),R=n(),z=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function Ve({roles:e={},provider:t,supported:n,onChange:r,renderEngine:i,visibleRoleIds:o,manageRoles:s=!0}){let{t:c}=a(`agentRuntime`),[l,u]=(0,L.useState)(``),[d,f]=(0,L.useState)(!1),p=Object.entries(e).filter(([e])=>!ve.includes(e)&&(!o||o.includes(e)));function m(){if(!D.test(l)||l===`fixer`||ve.includes(l)||Object.prototype.hasOwnProperty.call(e,l)){f(!0);return}r({...e,[l]:{provider:t,access:`read`,artifacts:`none`}}),u(``),f(!1)}return(0,R.jsxs)(`section`,{className:`space-y-3`,"aria-labelledby":`custom-runtime-roles`,children:[s&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h3`,{id:`custom-runtime-roles`,className:`text-sm font-medium`,children:c(`customRoles.title`)}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c(`customRoles.hint`)})]}),!n&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c(`customRoles.unsupported`)}),p.map(([t,a])=>{let o=n=>r({...e,[t]:{...a,...n}});return(0,R.jsxs)(`fieldset`,{className:`space-y-3 rounded-lg border p-3`,"aria-label":t,children:[(0,R.jsx)(`legend`,{className:`px-1 font-mono text-sm`,children:t}),s&&(0,R.jsx)(`div`,{className:`flex justify-end`,children:(0,R.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>{let n={...e};delete n[t],r(n)},children:c(`customRoles.remove`,{id:t})})}),(0,R.jsxs)(`fieldset`,{disabled:!n,className:`space-y-3`,children:[i(t),(0,R.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,R.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[c(`customRoles.access`),(0,R.jsxs)(`select`,{className:z,value:a.access,onChange:e=>o({access:e.target.value}),children:[(0,R.jsx)(`option`,{value:`read`,children:c(`customRoles.read`)}),(0,R.jsx)(`option`,{value:`write`,children:c(`customRoles.write`)})]})]}),(0,R.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[c(`customRoles.artifacts`),(0,R.jsxs)(`select`,{className:z,value:a.artifacts,onChange:e=>o({artifacts:e.target.value}),children:[(0,R.jsx)(`option`,{value:`none`,children:c(`customRoles.none`)}),(0,R.jsx)(`option`,{value:`tasks-checkboxes`,children:c(`customRoles.tasks`)}),(0,R.jsx)(`option`,{value:`all`,children:c(`customRoles.all`)})]})]})]}),(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[c(`customRoles.skill`),(0,R.jsxs)(`select`,{className:z,value:a.openspecSkill??``,onChange:e=>o({openspecSkill:e.target.value||void 0}),children:[(0,R.jsx)(`option`,{value:``,children:c(`customRoles.noSkill`)}),[`openspec-ff-change`,`openspec-apply-change`,`openspec-verify-change`].map(e=>(0,R.jsx)(`option`,{value:e,children:e},e))]})]}),(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[c(`customRoles.prompt`),(0,R.jsx)(`textarea`,{className:`w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,value:a.prompt??``,rows:5,maxLength:2e4,onChange:e=>o({prompt:e.target.value||void 0})})]})]})]},t)}),s&&(0,R.jsxs)(`fieldset`,{disabled:!n||!t,className:`flex items-end gap-2`,children:[(0,R.jsxs)(`label`,{className:`min-w-0 flex-1 space-y-1 text-xs`,children:[c(`customRoles.id`),(0,R.jsx)(E,{value:l,maxLength:64,placeholder:`security-reviewer`,onChange:e=>{u(e.target.value),f(!1)}})]}),(0,R.jsx)(C,{variant:`secondary`,onClick:m,children:c(`customRoles.add`)})]}),d&&(0,R.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:c(`customRoles.invalidId`)})]})}var He={architect:fe,developer:ce,host:O};function Ue({projectId:e,catalogUrl:t,guardrails:n,onChange:r}){let{t:i,i18n:o}=a(`agentRuntime`),[s,c]=(0,L.useState)(!0),[l,u]=(0,L.useState)({status:`loading`});(0,L.useEffect)(()=>{let n=!1;return u({status:`loading`}),fetch(t??`${w(e)}/agent-runtime/guardrails`,{cache:`no-store`}).then(async e=>{if(!e.ok)throw Error(`guardrails`);let r=await e.json(),i=t?r.guardrails:r;if(!be(i))throw Error(`guardrails`);n||u({status:`ready`,supported:i.supported,catalog:i.catalog})}).catch(()=>{n||u({status:`unsupported`})}),()=>{n=!0}},[e,t]);let f=l.status===`ready`?l.catalog:[],p=l.status===`ready`&&l.supported,m=f.filter(e=>n?.[e.id]===!1).length,h=f.length,g=e=>o.exists(`agentRuntime:guardrails.items.${e}.title`),_=`pipeline-guardrails-body`;return(0,R.jsxs)(`fieldset`,{id:`pipeline-guardrails`,"data-testid":`phase-card-guardrails`,className:`scroll-mt-4 rounded-lg border border-border transition-shadow`,children:[(0,R.jsx)(`legend`,{className:`sr-only`,children:i(`guardrails.title`)}),(0,R.jsxs)(`button`,{type:`button`,"aria-expanded":s,"aria-controls":_,"aria-label":`${i(s?`pipeline.collapse`:`pipeline.open`)}: ${i(`guardrails.title`)}`,onClick:()=>c(e=>!e),className:`flex w-full flex-wrap items-center gap-2 rounded-t-lg px-3 py-2 text-left hover:bg-muted/40`,children:[(0,R.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center rounded-full bg-accent-success/15 text-accent-success`,children:(0,R.jsx)(ge,{className:`h-3.5 w-3.5`,"aria-hidden":!0})}),(0,R.jsx)(`span`,{className:`text-xs font-medium`,children:i(`guardrails.title`)}),(0,R.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[l.status===`ready`&&p&&(0,R.jsx)(`span`,{"data-testid":`guardrails-active`,className:S(`inline-flex items-center rounded-md border px-1.5 py-0.5 text-[11px] leading-4`,m?`border-accent-warning/40 bg-accent-warning/10 text-accent-warning`:`border-accent-success/30 bg-accent-success/10 text-accent-success`),children:i(`guardrails.active`,{on:h-m,total:h})}),(0,R.jsx)(d,{className:`h-3.5 w-3.5 text-muted-foreground transition-transform ${s?``:`-rotate-90`}`,"aria-hidden":!0})]})]}),(0,R.jsxs)(`div`,{id:_,hidden:!s,className:`space-y-3 px-3 pb-3`,children:[(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`guardrails.intro`)}),l.status===`loading`&&(0,R.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:i(`loading`)}),(l.status===`unsupported`||l.status===`ready`&&!p)&&(0,R.jsx)(`p`,{role:`status`,className:`rounded-md border border-accent-warning/40 p-3 text-xs text-accent-warning`,children:i(`guardrails.unsupported`)}),l.status===`ready`&&(0,R.jsxs)(`fieldset`,{disabled:!p,className:`space-y-3 disabled:opacity-60`,children:[m>0&&(0,R.jsx)(`div`,{className:`flex justify-end`,children:(0,R.jsx)(`button`,{type:`button`,className:`text-[11px] text-accent-primary underline-offset-2 hover:underline`,onClick:()=>r(void 0),children:i(`guardrails.reset`)})}),A.map(e=>{let t=f.filter(t=>t.phase===e);if(!t.length)return null;let a=He[e];return(0,R.jsxs)(`div`,{className:`space-y-2`,"data-testid":`guardrails-phase-${e}`,children:[(0,R.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:[(0,R.jsx)(a,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),i(`guardrails.phases.${e}`)]}),(0,R.jsx)(`ul`,{className:`divide-y divide-border/60 rounded-md border border-border/60`,children:t.map(e=>{let t=n?.[e.id]!==!1,a=g(e.id)?i(`guardrails.items.${e.id}.title`):e.id,o=g(e.id)?i(`guardrails.items.${e.id}.description`):i(`guardrails.unknown`),s=g(e.id)?i(`guardrails.items.${e.id}.why`):null,c=`guardrail-${e.id}-title`;return(0,R.jsxs)(`li`,{className:`flex items-start gap-3 px-3 py-2`,children:[(0,R.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t,"aria-labelledby":c,"data-testid":`guardrail-${e.id}`,onClick:()=>r(j(n,e.id,!t)),className:S(`relative mt-0.5 inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors`,t?`bg-accent-primary/70`:`bg-muted-foreground/30`),children:(0,R.jsx)(`span`,{className:S(`absolute h-3 w-3 rounded-full bg-background shadow transition-transform`,t?`translate-x-3.5`:`translate-x-0.5`)})}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`p`,{id:c,className:S(`text-xs font-medium`,!t&&`text-muted-foreground line-through decoration-muted-foreground/50`),children:a}),(0,R.jsx)(`p`,{className:`mt-0.5 text-[11px] leading-4 text-muted-foreground`,children:o}),s&&(0,R.jsx)(`p`,{className:`mt-0.5 text-[10px] italic leading-4 text-muted-foreground/70`,children:s})]})]},e.id)})})]},e)})]})]})]})}var We=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function B({config:e,onChange:t}){let{t:n}=a(`agentRuntime`),r=e.efficiency??{schemaVersion:1};return(0,R.jsxs)(`section`,{className:`space-y-3`,"aria-label":n(`efficiency.title`),children:[(0,R.jsx)(`h3`,{className:`text-sm font-medium`,children:n(`efficiency.title`)}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`efficiency.scope`)}),(0,R.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[`contextMode`,`reviewMode`,`planning`].map(i=>(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`efficiency.${i}`),(0,R.jsxs)(`select`,{className:We,value:r[i]??(i===`planning`?`proportional`:`incremental`),onChange:n=>t({...e,efficiency:{...r,[i]:n.target.value}}),children:[(0,R.jsx)(`option`,{value:i===`planning`?`proportional`:`incremental`,children:n(`efficiency.adaptive`)}),(0,R.jsx)(`option`,{value:`full`,children:n(`efficiency.full`)})]})]},i))}),(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:r.acceptDeveloperChecks!==!1,onChange:n=>t({...e,efficiency:{...r,acceptDeveloperChecks:n.target.checked}})}),n(`efficiency.developerChecks`)]}),(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`efficiency.concurrency`),(0,R.jsx)(E,{type:`number`,min:`1`,max:`4`,step:`1`,value:r.verification?.maxConcurrency??1,onChange:n=>t({...e,efficiency:{...r,verification:{...r.verification,maxConcurrency:Number(n.target.value)}}})})]}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`efficiency.concurrencyHint`)})]})}function Ge(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=V(s.data?.params);(c===`role-turn`||c===`implementation-step`&&l.phase===`reviewer`)&&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 V=e=>typeof e==`object`&&e&&!Array.isArray(e)?e:{};function H(e){return typeof e.type==`string`?e.type:e.properties||e.additionalProperties?`object`:e.items?`array`:`string`}function U(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 U(V(t[0]));switch(H(e)){case`boolean`:return!1;case`number`:case`integer`:return typeof e.minimum==`number`?e.minimum:0;case`array`:return[];case`object`:{let t=V(e.properties);return Object.fromEntries((Array.isArray(e.required)?e.required:[]).filter(e=>typeof e==`string`).map(e=>[e,U(V(t[e]))]))}default:return``}}function Ke(e){let t=V(U(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 qe(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===`verify`&&t.hostBlockers!==!0&&(r=r.filter(e=>e!==`blocked`)),e.kind===`component`?n[String(t.ref)]?.outputs??[`next`,`failed`]:r.filter(t=>e.outcomes.includes(t))}var Je=e=>[`prompt`,`role-turn`,`decider`,`implementation`,`implementation-step`].includes(e)?`ai`:[`verify`,`shell`].includes(e)?`verification`:e===`artifact-contract`||e.startsWith(`openspec-`)?`openspec`:`control`;function Ye(e,t,n){return t===`implementation`?[`architect`,`developer`,`reviewer`,`fixer`]:t===`implementation-step`?[`architect`,`developer`,`reviewer`,`fixer`].includes(String(n.phase))?[String(n.phase)]:[]:t===`prompt`?[e===`fix`?`fixer`:e===`prepare`?`architect`:n.access===`read`?`reviewer`:`developer`]:(t===`role-turn`||t===`decider`)&&typeof n.roleId==`string`?[n.roleId]:[]}function Xe(e){let t=new Set,n=new Set;function r(i){for(let a of i.nodes){if(a.type!==`core`)continue;let i=V(a.data?.params),o=a.data?.kind;Ye(a.id,o,i).forEach(e=>t.add(e));let s=o===`component`?i.ref:o===`map`?i.body:void 0;typeof s==`string`&&!n.has(s)&&e.components?.[s]&&(n.add(s),r(e.components[s]))}}return r(e),[...t]}var W=`w-full rounded-md border border-input bg-background px-2 py-1 text-xs`,G=[`architect`,`developer`,`reviewer`,`fixer`];function Ze({value:e,onChange:t,selectedRole:n,graph:r,mode:i=`all`}){let{t:o}=a(`agentRuntime`),{activeProjectId:l}=c(),d=(0,L.useRef)(l);d.current=l;let[f,p]=(0,L.useState)([]),[m,h]=(0,L.useState)({}),[g,_]=(0,L.useState)(),[v,ee]=(0,L.useState)(null),[y,te]=(0,L.useState)(``),[ne,re]=(0,L.useState)(!1),[ie,ae]=(0,L.useState)(!1),oe=r?Xe(r):[...G,...Object.keys(e?.roles??{})],b=i===`step`?[n??``]:ie?void 0:oe,x=i!==`workflow`,se=i!==`step`,S=i===`step`?`loopAgents.stepTitle`:i===`workflow`?`loopAgents.policy`:`loopAgents.title`,w=[...G,...Object.keys(e?.roles??{})].some(e=>!oe.includes(e));(0,L.useEffect)(()=>{let e=new AbortController;return Promise.all([`/api/runtime-providers`,`/api/loop-agent-defaults`].map(t=>fetch(t,{signal:e.signal}).then(async e=>{if(!e.ok)throw Error(o(`loadFailed`));return e.json()}))).then(([t,n])=>{e.signal.aborted||(p(t.providers??[]),_(n.agents),ee(n.rolePromptDefaults??null),h(Object.fromEntries(Object.entries(t.status??{}).map(([e,t])=>[e,t.models??[]]))))}).catch(()=>{e.signal.aborted||te(o(`loadFailed`))}),()=>e.abort()},[o]);async function T(){let e=l;re(!0),te(``);try{let n=s(),[r,i]=await Promise.all([fetch(`${n}/agent-runtime/config`),fetch(`${n}/agent-runtime/loop-roles`)]);if(!r.ok||!i.ok)throw Error(o(`loadFailed`));let a=await r.json(),c=await i.json(),{agents:l,fixer:u,roles:f,rolePrompts:p,limits:m,review:h,architect:_,approvalBeforeArchive:v,efficiency:ee,guardrails:y}=a.config;if(!e||d.current!==e)return;t({schemaVersion:1,agents:l,fixer:u,roles:{...g?.roles,...Object.fromEntries(Object.entries(f??{}).map(([e,t])=>[e,{...t,prompt:p?.[e]??t.prompt}])),...c.roles?.decider?{"loop-decider":{...g.roles[`loop-decider`],...c.roles.decider}}:{}},rolePrompts:Object.fromEntries(Object.entries({...g?.rolePrompts,...p}).filter(([e])=>G.includes(e))),limits:m,review:h,architect:_,approvalBeforeArchive:v,efficiency:ee,guardrails:y})}catch{te(o(`loadFailed`))}finally{re(!1)}}function ce(n){if(!e)return null;let r=G.includes(n),i=n===`fixer`?e.fixer??e.agents.developer:r?e.agents[n]:e.roles?.[n];if(!i)return null;let a=i=>t(n===`fixer`?{...e,fixer:i}:r?{...e,agents:{...e.agents,[n]:i}}:{...e,roles:{...e.roles,[n]:{...e.roles[n],...i}}}),s=f.find(e=>e.id===i.provider),c=s?.kind===`cli`?M(s.cli).map(e=>e.value):m[i.provider]??[];return(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.provider`),(0,R.jsxs)(`select`,{className:W,value:i.provider,onChange:e=>a({provider:e.target.value,maxTurns:i.maxTurns}),children:[(0,R.jsx)(`option`,{value:`inherit`,children:o(`loopAgents.inheritProvider`)}),!s&&i.provider!==`inherit`&&u(i.provider)&&(0,R.jsx)(`option`,{value:i.provider,children:i.provider}),f.filter(e=>u(e.kind===`cli`?e.cli:e.id)).map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.kind===`openai-compatible`?e.label??e.id:e.id},e.id))]})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.model`),(0,R.jsx)(E,{value:i.model??``,list:`loop-models-${n}`,onChange:e=>a({...i,model:e.target.value||void 0})}),(0,R.jsx)(`datalist`,{id:`loop-models-${n}`,children:c.map(e=>(0,R.jsx)(`option`,{value:e},e))})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.effort`),(0,R.jsx)(E,{value:i.effort??``,onChange:e=>a({...i,effort:e.target.value||void 0})})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.maxTurns`,{turns:100}),(0,R.jsx)(E,{type:`number`,min:1,value:i.maxTurns??``,onChange:e=>a({...i,maxTurns:e.target.value?Number(e.target.value):void 0})})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.thinking`),(0,R.jsxs)(`select`,{className:W,value:i.thinking??``,onChange:e=>a({...i,thinking:e.target.value?e.target.value:void 0}),children:[(0,R.jsx)(`option`,{value:``,children:o(`loopAgents.default`)}),(0,R.jsx)(`option`,{value:`off`,children:o(`agents.thinking_off`)}),(0,R.jsx)(`option`,{value:`on`,children:o(`agents.thinking_on`)})]})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.escalationModel`),(0,R.jsx)(E,{value:i.escalation?.model??``,onChange:e=>a({...i,escalation:e.target.value?{...i.escalation,model:e.target.value}:void 0})})]}),i.escalation&&(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.escalationEffort`),(0,R.jsx)(E,{value:i.escalation.effort??``,onChange:e=>a({...i,escalation:{model:i.escalation.model,effort:e.target.value||void 0}})})]})]})}let le=e?{...e,enabled:!0,providers:f,verification:[]}:void 0;return(0,R.jsxs)(`section`,{className:`space-y-3 border-b border-border pb-4`,"aria-label":o(S),children:[(0,R.jsx)(`h3`,{className:`text-sm font-medium`,children:o(S)}),x&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(i===`step`?`loopAgents.stepHint`:`loopAgents.hint`)}),y&&(0,R.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:y}),!e&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`p`,{className:`text-xs text-accent-warning`,children:o(`loopAgents.legacy`)}),(0,R.jsx)(C,{size:`sm`,disabled:!g,onClick:()=>g&&t(structuredClone(g)),children:o(`loopAgents.enable`)})]}),i!==`step`&&(0,R.jsx)(C,{size:`sm`,variant:`secondary`,disabled:!l||!g||ne,onClick:()=>void T(),children:o(`loopAgents.import`)}),e&&(0,R.jsxs)(R.Fragment,{children:[i===`all`&&w&&(0,R.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:ie,onChange:e=>ae(e.target.checked)}),o(`loopAgents.showUnused`)]}),x&&G.filter(e=>!b||b.includes(e)).map(r=>(0,R.jsxs)(`details`,{open:n===r,className:`rounded-md border border-border p-2`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium`,children:r}),(0,R.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[ce(r),e.rolePrompts?.[r]===`inherit`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`loopAgents.inheritDefinition`)}),(0,R.jsx)(`textarea`,{readOnly:!0,"aria-label":o(`customRoles.prompt`),className:`${W} opacity-80`,rows:8,value:v?.[r]??o(`loopAgents.coreDefinitionUnavailable`)}),(0,R.jsx)(C,{size:`sm`,variant:`ghost`,disabled:!v?.[r],onClick:()=>t({...e,rolePrompts:{...e.rolePrompts,[r]:v?.[r]??``}}),children:o(`loopAgents.customizeDefinition`)})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`customRoles.prompt`),(0,R.jsx)(`textarea`,{className:W,rows:10,maxLength:2e4,value:e.rolePrompts?.[r]??``,onChange:n=>t({...e,rolePrompts:{...e.rolePrompts,[r]:n.target.value}})})]}),(0,R.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>t({...e,rolePrompts:{...e.rolePrompts,[r]:`inherit`}}),children:o(`loopAgents.restoreDefinition`)})]})]})]},r)),i===`step`&&n&&![...G,`archive`,`verify`].includes(n)&&!e.roles?.[n]&&(0,R.jsx)(C,{size:`sm`,disabled:!f.length,onClick:()=>t({...e,roles:{...e.roles,[n]:{provider:`inherit`,access:`read`,artifacts:`none`}}}),children:o(`customRoles.add`)}),(x||i===`workflow`)&&(0,R.jsx)(Ve,{manageRoles:i!==`step`,visibleRoleIds:i===`workflow`?[]:b,roles:e.roles,provider:`inherit`,supported:!0,onChange:n=>{Object.keys(n).some(t=>!e.roles?.[t])&&ae(!0),t({...e,roles:n,rolePrompts:Object.fromEntries(Object.entries(e.rolePrompts??{}).filter(([e])=>G.includes(e)))})},renderEngine:ce}),(0,R.jsxs)(`div`,{className:`space-y-3`,children:[se&&(0,R.jsxs)(`details`,{className:`rounded-md border border-border p-2`,children:[(0,R.jsx)(`summary`,{className:`cursor-pointer text-sm`,children:o(`loopAgents.policy`)}),(0,R.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[[`maxAttempts`,`maxTokens`,`maxCostUsd`,`timeoutMs`].map(n=>(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.${n}`),(0,R.jsx)(E,{type:`number`,min:1,value:e.limits?.[n]??``,onChange:r=>t({...e,limits:{...e.limits,[n]:r.target.value?Number(r.target.value):void 0}})})]},n)),(0,R.jsx)(Ue,{catalogUrl:`/api/loop-agent-defaults`,guardrails:e.guardrails,onChange:n=>t({...e,guardrails:n})}),le&&(0,R.jsx)(B,{config:le,onChange:n=>t({...e,efficiency:n.efficiency})})]})]}),(i===`all`||i===`step`&&n===`reviewer`)&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`review.minScore`,{score:70}),(0,R.jsx)(E,{type:`number`,min:70,max:100,value:e.review?.minScore??``,onChange:n=>t({...e,review:{...e.review,minScore:n.target.value?Number(n.target.value):void 0}})})]}),N.map(n=>(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`review.aspects.${n}`,{score:_e.aspects[n]}),(0,R.jsx)(E,{type:`number`,min:_e.aspects[n],max:100,value:e.review?.aspects?.[n]??``,onChange:r=>t({...e,review:{...e.review,aspects:{...e.review?.aspects,[n]:r.target.value?Number(r.target.value):void 0}}})})]},n))]}),(i===`all`||i===`step`&&n===`architect`)&&(0,R.jsxs)(`label`,{className:`block text-xs`,children:[o(`architect.onLowConfidence`),(0,R.jsxs)(`select`,{className:W,value:e.architect?.onLowConfidence??`ask`,onChange:n=>t({...e,architect:{onLowConfidence:n.target.value}}),children:[(0,R.jsx)(`option`,{value:`ask`,children:o(`architect.ask`)}),(0,R.jsx)(`option`,{value:`proceed`,children:o(`architect.proceed`)})]})]}),(i===`all`||i===`step`&&n===`archive`)&&(0,R.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:e.approvalBeforeArchive??!1,onChange:n=>t({...e,approvalBeforeArchive:n.target.checked})}),o(`approvalBeforeArchive`)]})]})]})]})}var K=`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 q({schema:e,value:t,onChange:n,path:r=`params`,choices:i={},depth:o=0}){let{t:s}=a(`loops`),c=(0,L.useId)(),[l,u]=(0,L.useState)(``);if(o>24)return(0,R.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,R.jsx)(q,{schema:n,value:a,onChange:s,path:`${r}.${e}`,choices:{...i,selectedProvider:typeof V(t).provider==`string`?String(V(t).provider):i.selectedProvider},depth:o+1},e),p=e.oneOf??e.anyOf;if(Array.isArray(p)&&!e.properties){let e=p.map(V),r=Math.max(0,e.findIndex(e=>`const`in e?t===e.const:Array.isArray(e.enum)?e.enum.includes(t):H(e)===(Array.isArray(t)?`array`:typeof t)));return(0,R.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,R.jsx)(`legend`,{className:`text-xs font-medium`,children:d}),(0,R.jsx)(`label`,{className:`sr-only`,htmlFor:c,children:s(`builder.core.variant`,{name:d})}),(0,R.jsx)(`select`,{id:c,className:K,value:r,onChange:t=>n(U(e[Number(t.target.value)])),children:e.map((e,t)=>(0,R.jsx)(`option`,{value:t,children:String(e.title??e.const??(Array.isArray(e.enum)?e.enum.join(` / `):H(e)))},t))}),f(`value`,e[r],t,n)]})}if(`const`in e)return(0,R.jsxs)(`p`,{className:`text-xs`,children:[(0,R.jsxs)(`span`,{className:`text-muted-foreground`,children:[d,`: `]}),String(e.const)]});if(Array.isArray(e.enum))return(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,(0,R.jsxs)(`select`,{className:K,value:JSON.stringify(t),onChange:e=>n(JSON.parse(e.target.value)),children:[!e.enum.includes(t)&&(0,R.jsx)(`option`,{value:JSON.stringify(t)??``,children:s(`builder.core.select`)}),e.enum.map((e,t)=>(0,R.jsx)(`option`,{value:JSON.stringify(e),children:String(e)},t))]})]});let m=H(e);if(m===`object`){let r=V(t),i=V(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=>V(e).required).filter(e=>Array.isArray(e)&&e.every(e=>typeof e==`string`)):[],h=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:U(V(i[t]??e.additionalProperties)),enumerable:!0,configurable:!0,writable:!0}),n(a)};return(0,R.jsxs)(`fieldset`,{className:`space-y-2 min-w-0`,children:[(0,R.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,R.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:()=>h(t),"aria-label":s(`builder.core.addField`,{name:t}),children:[(0,R.jsx)(v,{className:`h-3 w-3`}),t]},t):(0,R.jsxs)(`div`,{className:`relative border-l border-border pl-2 space-y-1`,children:[!o&&(0,R.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,R.jsx)(re,{className:`h-3.5 w-3.5`})}),f(t,V(i[t]??e.additionalProperties),r[t],e=>c(t,e))]},t)}),e.additionalProperties!==!1&&(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(`input`,{className:K,value:l,placeholder:s(`builder.core.fieldName`),"aria-label":s(`builder.core.fieldName`),onChange:e=>u(e.target.value)}),(0,R.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:()=>{h(l.trim()),u(``)},"aria-label":s(`builder.core.addField`,{name:l}),children:(0,R.jsx)(v,{className:`h-4 w-4`})})]})]})}if(m===`array`){let r=Array.isArray(t)?t:[],i=V(e.items);return(0,R.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,R.jsx)(`legend`,{className:`text-xs font-semibold`,children:d}),r.map((e,t)=>(0,R.jsxs)(`div`,{className:`border-l border-border pl-2`,children:[(0,R.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,R.jsx)(re,{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,R.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,U(i)]),children:[(0,R.jsx)(v,{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,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsxs)(`label`,{className:`text-xs`,children:[s(`builder.core.valueType`),(0,R.jsx)(`select`,{className:K,value:r,onChange:e=>n(e.target.value===`null`?null:U({type:e.target.value})),children:[`string`,`number`,`boolean`,`object`,`array`,`null`].map(e=>(0,R.jsx)(`option`,{children:e},e))})]}),r===`null`?(0,R.jsx)(`span`,{className:`text-xs`,children:`null`}):f(`value`,{type:r},t,n)]})}if(m===`boolean`)return(0,R.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,R.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,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,(0,R.jsx)(`input`,{type:`number`,className:K,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 h=d===`provider`?i.providers:d===`roleId`?i.roles:[`ref`,`body`].includes(d)?i.components:void 0,g=d===`model`?i.models?.[i.selectedProvider??``]:void 0,_=[`text`,`prompt`,`question`,`message`,`goal`,`expr`,`commandLine`,`reason`].includes(d);return(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,h?.length&&d!==`roleId`?(0,R.jsxs)(`select`,{className:K,value:typeof t==`string`?t:``,onChange:e=>n(e.target.value),children:[(0,R.jsx)(`option`,{value:``,children:s(`builder.core.select`)}),t&&!h.includes(String(t))?(0,R.jsx)(`option`,{value:String(t),children:String(t)}):null,h.map(e=>(0,R.jsx)(`option`,{children:e},e))]}):_?(0,R.jsx)(`textarea`,{className:`${K} 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,R.jsx)(`input`,{list:g?.length||d===`roleId`&&h?.length?c:void 0,className:K,value:typeof t==`string`?t:``,maxLength:typeof e.maxLength==`number`?e.maxLength:void 0,onChange:e=>n(e.target.value)}),g?.length||d===`roleId`&&h?.length?(0,R.jsx)(`datalist`,{id:c,children:(g??h??[]).map(e=>(0,R.jsx)(`option`,{value:e},e))}):null,typeof e.description==`string`&&(0,R.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.description})]})}var J=`w-full min-w-0 rounded border border-border bg-background px-2 py-1 text-xs`,Qe=[`journal`,`change`,`maxTokens`,`maxTransitions`,`policies`];function $e({graph:e,canvas:t,schema:n,onChange:r,onOpenCanvas:i}){let{t:o}=a(`loops`),[s,c]=(0,L.useState)(``),l=V(n.properties),u={type:`object`,additionalProperties:!1,properties:{...Object.fromEntries(Qe.filter(e=>l[e]).map(e=>[e,l[e]])),...V(V(l.budget).properties).maxTokens?{maxTokens:V(V(l.budget).properties).maxTokens}:{}}},d=Object.fromEntries(Object.entries(e.config).filter(([e])=>Qe.includes(e))),f=t?e.components?.[t]:void 0,p=t?[]:Ge(e);return(0,R.jsxs)(R.Fragment,{children:[!t&&(0,R.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[(0,R.jsx)(`span`,{children:o(`builder.core.reviewerStep`)}),(0,R.jsxs)(`select`,{className:J,value:e.config.reviewerStepId??``,onChange:t=>r({...e,config:{...e.config,reviewerStepId:t.target.value||void 0}}),children:[(0,R.jsx)(`option`,{value:``,children:o(`builder.core.reviewerAutomatic`)}),e.config.reviewerStepId&&!p.includes(e.config.reviewerStepId)&&(0,R.jsx)(`option`,{value:e.config.reviewerStepId,children:e.config.reviewerStepId}),p.map(e=>(0,R.jsx)(`option`,{value:e,children:e},e))]}),(0,R.jsx)(`span`,{className:`block text-muted-foreground`,children:o(`builder.core.reviewerHint`)})]}),(0,R.jsx)(q,{schema:u,value:d,path:o(`builder.core.options`),onChange:t=>{let n=Object.fromEntries(Object.entries(e.config).filter(([e])=>!Qe.includes(e)));r({...e,config:{...n,...t}})}}),(0,R.jsxs)(`section`,{className:`space-y-2`,children:[(0,R.jsx)(`p`,{className:`text-xs font-semibold`,children:o(`builder.core.components`)}),(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(e.components??{}).map(e=>(0,R.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,R.jsxs)(`div`,{className:`flex gap-1`,children:[(0,R.jsx)(`input`,{className:J,value:s,"aria-label":o(`builder.core.componentName`),placeholder:o(`builder.core.componentName`),onChange:e=>c(e.target.value)}),(0,R.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,R.jsx)(v,{className:`w-4 h-4`})})]}),f&&t&&(0,R.jsx)(q,{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 et({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=V(V(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(V(f.properties)).map(([e,t])=>[e,p[e]?{...V(t),title:p[e]}:t]))}:f;return(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(`h3`,{className:`text-sm font-semibold`,children:l(`builder.core.pieces.${t.coreKind}`)}),(0,R.jsx)(`button`,{type:`button`,onClick:s,"aria-label":l(`common:actions.delete`),className:`text-muted-foreground hover:text-destructive`,children:(0,R.jsx)(y,{className:`h-4 w-4`})})]}),(0,R.jsxs)(`label`,{className:`block text-xs`,children:[l(`builder.inspector.label`),(0,R.jsx)(`input`,{className:J,value:String(t.label??``),onChange:e=>o({label:e.target.value})})]}),[`implementation`,`implementation-step`].includes(t.coreKind??``)&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`builder.core.legacyImplementation`)}),n?(0,R.jsx)(q,{schema:m,value:t.params??{},onChange:e=>o({params:e}),choices:r},e):(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`builder.core.unavailable`)}),[`component`,`map`].includes(t.coreKind)&&typeof u==`string`&&(0,R.jsx)(`button`,{type:`button`,className:`text-xs text-accent-primary`,onClick:()=>c(u),children:l(`builder.core.openComponent`)}),Object.keys(d).length>0&&(0,R.jsx)(q,{schema:d,value:t.retry??{},path:`retry`,onChange:e=>o({retry:e})})]})}function tt(e){return e===`continue`||e===`stop`?e:void 0}function nt(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 Y(){return globalThis.crypto?.randomUUID?.()??`n-${Date.now()}-${Math.floor(Math.random()*1e9)}`}function rt(e,t){return{id:Y(),type:`loop`,position:t,data:nt(e)}}function it(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:Ne.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 at(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=tt(t.sourceHandle)??tt(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 ot=`specrailsNodes`;function st(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 ct(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}let n=t;return!n||n[ot]==null||!Array.isArray(n.nodes)?null:{nodes:n.nodes,edges:Array.isArray(n.edges)?n.edges:[]}}function lt(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 ut(e){return typeof e!=`string`||e.trim().length===0}function dt(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 ft(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=dt(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}),ut(t.data.goal)&&n.push({severity:`warning`,code:`EMPTY_GOAL`,nodeId:t.id});break}case`ai-step`:ut(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`:ut(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 pt(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 mt=(0,L.createContext)(new Map),ht=(0,L.createContext)({pieces:[]}),gt=[`start`,`ai-step`,`shell`,`decider`,`end`],_t={core:he,start:g,"ai-step":he,shell:O,decider:h,condition:h,end:Te},vt={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 yt({id:e,data:t,selected:n}){let{t:r}=a(`loops`),i=t.kind,o=_t[i]??_,s=String(t.label??``).trim(),c=(0,L.useContext)(mt).get(e),l=(0,L.useContext)(ht),u=qe(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,R.jsxs)(`div`,{className:S(`rounded-md border-2 bg-card px-3 py-2 min-w-[140px] shadow-sm`,vt[i],c===`error`?`ring-2 ring-destructive`:n?`ring-2 ring-accent-primary`:c===`warning`?`ring-2 ring-accent-warning`:``),children:[i!==`start`&&(0,R.jsx)(F,{type:`target`,position:I.Top}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(o,{className:`w-3.5 h-3.5 text-foreground flex-shrink-0`}),(0,R.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,R.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,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-1 truncate max-w-[160px]`,children:d}),i===`core`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`div`,{className:`flex justify-around gap-2 mt-2 text-[9px] text-accent-primary`,children:u.map(e=>(0,R.jsx)(`span`,{children:e},e))}),u.map((e,t)=>(0,R.jsx)(F,{id:e,type:`source`,position:I.Bottom,style:{left:`${(t+1)*100/(u.length+1)}%`},"aria-label":e},e))]}):i===`decider`?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between gap-2 text-[9px] font-medium`,children:[(0,R.jsx)(`span`,{className:`text-accent-highlight`,children:r(`builder.branch.continue`)}),(0,R.jsx)(`span`,{className:`text-accent-success`,children:r(`builder.branch.stop`)})]}),(0,R.jsx)(F,{id:`continue`,type:`source`,position:I.Bottom,style:{left:`30%`},className:`!bg-accent-highlight`}),(0,R.jsx)(F,{id:`stop`,type:`source`,position:I.Bottom,style:{left:`70%`},className:`!bg-accent-success`})]}):i===`end`?null:(0,R.jsx)(F,{type:`source`,position:I.Bottom})]})}function bt({loopId:e,onExit:t,onWindowOpened:n}){let{t:o}=a(`loops`),u=i(),{id:d}=r(),h=e??d,g=(0,L.useCallback)(()=>{t?t():u(`/loops`)},[t,u]),_=we(),{fitView:y,screenToFlowPosition:re}=ke(),{activeProjectId:w}=c(),[T,ce]=(0,L.useState)([]),[E,fe]=(0,L.useState)({}),[he,ge]=(0,L.useState)(!1),[D,_e]=(0,L.useState)({}),[ve,O]=(0,L.useState)([]),[A,j]=(0,L.useState)(null),[M,be]=(0,L.useState)(null);(0,L.useEffect)(()=>{let e=!1;return k.catalog().then(t=>{e||(ce(t.nodeKinds),fe(t.definitionSchema??{}),ge(!1))}).catch(()=>{e||ge(!0)}),()=>{e=!0}},[]),(0,L.useEffect)(()=>{let e=new AbortController;_e({});let t=t=>fetch(t,{signal:e.signal}).then(e=>e.ok?e.json():null).catch(()=>null);return Promise.all([w&&A&&!A.config.agents?t(`${s()}/agent-runtime/config`):Promise.resolve(null),t(`/api/runtime-providers`)]).then(([t,n])=>{e.signal.aborted||_e({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()},[w,!!A,!!A?.config.agents]);let[N,P,Te]=Oe([]),[F,I,Fe]=Le([]),[z,Ve]=(0,L.useState)(``),[He,Ue]=(0,L.useState)(!1),[We,B]=(0,L.useState)(!1),[Ge,V]=(0,L.useState)(10),[H,U]=(0,L.useState)(30),[Xe,W]=(0,L.useState)(null),[G,K]=(0,L.useState)(null),[q,J]=(0,L.useState)(!1);(0,L.useEffect)(()=>J(!1),[h]);let[Qe,tt]=(0,L.useState)(!0),[nt,ot]=(0,L.useState)(!1),[ut,dt]=(0,L.useState)(!1),[vt,bt]=(0,L.useState)(null),[xt,St]=(0,L.useState)(!1),X=(0,L.useMemo)(()=>[...ft(N,F),...ve.map(e=>({severity:`error`,code:`CORE_VALIDATION`,nodeId:e.nodeId,message:e.message}))],[N,F,ve]),Ct=(0,L.useMemo)(()=>pt(X),[X]),wt=X.filter(e=>e.severity===`error`).length,[Ot,kt]=(0,L.useState)(`manual`),At=(0,L.useRef)(new Map),[jt,Mt]=(0,L.useState)([]),[Nt,Pt]=(0,L.useState)(!1),Ft=(0,L.useCallback)(async()=>{try{Mt(await k.loopConstants())}catch{}},[]);(0,L.useEffect)(()=>{Ft()},[Ft]);let It=(0,L.useMemo)(()=>({loop:yt}),[]),Lt=(0,L.useCallback)(e=>{j(e.graph),be(null);let{nodes:t,edges:n}=it(e.graph);At.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`;kt(i),P(i===`manual`?t:Ie(t,n,i)),I(n),Ve(e.name),V(e.graph.config?.maxIterations??10),U(e.graph.config?.timeoutMinutes??30),W(typeof e.graph.config?.maxCostUsd==`number`?e.graph.config.maxCostUsd:null),Ue(!!e.builtinId)},[P,I]);(0,L.useEffect)(()=>{if(!h)return;let e=!1;return k.get(h).then(t=>{e||Lt(t)}).catch(()=>l.error(o(`errors.load`))).finally(()=>{e||tt(!1)}),()=>{e=!0}},[h,Lt,o]);let Rt=(0,L.useCallback)(async()=>{if(h){B(!1);try{Lt(await k.restoreBuiltin(h)),O([]),l.success(o(`builder.builtin.restored`))}catch(e){l.error(e instanceof Error&&e.message?e.message:o(`errors.save`))}}},[h,Lt,o]),zt=(0,L.useCallback)(e=>{if(O([]),N.find(t=>t.id===e.source)?.data.kind===`core`){I(t=>De({...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;I(e=>De(n,e))},[I,N]),Bt=(0,L.useCallback)(e=>{if(!e.source||!e.target)return!1;let t=N.find(t=>t.id===e.source)?.data.kind,n=N.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=N.find(t=>t.id===e.source),n=qe(T.find(e=>e.kind===t.data.coreKind),t.data.params??{},A?.components);if(!e.sourceHandle||!n.includes(e.sourceHandle)||F.some(t=>t.source===e.source&&t.sourceHandle===e.sourceHandle))return!1}return!(t===`start`&&F.some(t=>t.source===e.source)||n===`start`)},[N,F,T,A]),Vt=(0,L.useCallback)(e=>{kt(e==="default"?`manual`:e),P(t=>e==="default"?t.map(e=>{let t=At.current.get(e.id);return t?{...e,position:{...t}}:e}):Ie(t,F,e)),requestAnimationFrame(()=>y({padding:.25,maxZoom:.85,duration:300}))},[P,F,y]),Ht=(0,L.useCallback)(e=>{e.some(e=>e.type===`position`&&e.dragging===!1)&&kt(`manual`),Te(e)},[Te]),Ut=(0,L.useRef)(N);Ut.current=N;let Wt=(0,L.useRef)(F);Wt.current=F,(0,L.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=st(Ut.current,Wt.current);!n||!t.clipboardData||(t.clipboardData.setData(`text/plain`,JSON.stringify(n)),t.preventDefault())},n=t=>{if(e())return;let n=ct(t.clipboardData?.getData(`text/plain`)??``);if(!n)return;t.preventDefault();let r=lt(n,{mintId:Y,offset:{x:40,y:40},excludeKinds:Ut.current.some(e=>e.data.kind===`start`)?[`start`]:[]});r.nodes.length!==0&&(P(e=>[...e.map(e=>({...e,selected:!1})),...r.nodes]),I(e=>[...e,...r.edges]),kt(`manual`),l.success(o(`builder.paste.done`,{count:r.nodes.length})))};return window.addEventListener(`copy`,t),window.addEventListener(`paste`,n),()=>{window.removeEventListener(`copy`,t),window.removeEventListener(`paste`,n)}},[P,I,o]);let Gt=(0,L.useCallback)(e=>{let t=rt(e,{x:120+Math.random()*120,y:80+Math.random()*240});P(e=>[...e,t]),J(!1),K(t.id)},[P]),Kt=(0,L.useCallback)(e=>{O([]),P(t=>t.map(t=>t.id===G?{...t,data:{...t.data,...e}}:t))},[G,P]),qt=(0,L.useCallback)(()=>{G&&(P(e=>e.filter(e=>e.id!==G)),I(e=>e.filter(e=>e.source!==G&&e.target!==G)),K(null))},[G,P,I]),Z=!!A&&!N.some(e=>![`start`,`core`,`end`].includes(e.data.kind)),Q=(0,L.useCallback)(()=>{let e={...A?.config,maxIterations:Ge,timeoutMinutes:H,maxCostUsd:Xe??void 0,layout:Ot},t=M?A?.components?.[M]:A,n={...t,...at(N,F,M?t?.config??e:e)};return M?{...A,config:e,components:{...A?.components,[M]:n}}:{...n,components:A?.components}},[A,M,N,F,Ge,H,Xe,Ot]),Jt=(0,L.useCallback)((e,t=!1)=>{let n=Q();e&&t&&!n.components?.[e]&&(n.components={...n.components,[e]:{nodes:[{id:Y(),type:`start`,position:{x:160,y:40}},{id:Y(),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=it(r);j(n),be(e),P(i.nodes),I(i.edges),K(null),O([]),requestAnimationFrame(()=>y({padding:.25}))},[Q,P,I,y]),Yt=(0,L.useCallback)((e,t)=>{let n={id:Y(),type:`loop`,position:t??{x:160+N.length*20,y:100+N.length*30},data:Ke(e)};if(e.kind===`role-turn`&&A){let e=D.providers?.[0]??`claude`,t=(`agent-`+n.id.replace(/[^a-z0-9-]/g,`-`)).slice(0,64),r=A.config.agents??{schemaVersion:1,agents:{architect:{provider:e},developer:{provider:e},reviewer:{provider:e}}};n.data.params={roleId:t,prompt:o(`builder.core.agentTaskDefault`)},j({...A,config:{...A.config,agents:{...r,roles:{...r.roles,[t]:{provider:e,access:`write`,artifacts:`none`,prompt:``}}}}})}e.kind===`prompt`&&D.providers?.length&&(n.data.params.engine={provider:D.providers[0]}),P(e=>[...e,n]),J(!1),K(n.id)},[N.length,P,D.providers,A,o]),Xt=(0,L.useCallback)(async()=>{St(!0);try{let e=Q(),{steps:t}=await k.previewLoop(e);bt(t)}catch{l.error(o(`builder.preview.error`))}finally{St(!1)}},[Q,o]),Zt=(0,L.useCallback)(async()=>{if(!h)return!1;ot(!0);try{let e=Q();return await k.update(h,{name:z,graph:e}),!0}catch(e){return l.error(e instanceof Error&&e.message?e.message:o(`errors.save`)),!1}finally{ot(!1)}},[h,Q,z,o]),Qt=(0,L.useCallback)(async()=>{if(h&&await Zt())try{await k.publish(h),l.success(o(`builder.published`)),g()}catch(e){e instanceof Ce?(O(e.errors),dt(!0),l.error(o(`errors.publishInvalid`))):l.error(e instanceof Error&&e.message?e.message:o(`errors.save`))}},[h,Zt,g,o]),$=N.find(e=>e.id===G)??null;return(0,R.jsx)(mt.Provider,{value:Ct,children:(0,R.jsx)(ht.Provider,{value:{pieces:T,components:A?.components},children:(0,R.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 h-12 border-b border-border flex-shrink-0`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,R.jsx)(`button`,{type:`button`,onClick:g,className:`text-muted-foreground hover:text-foreground`,"aria-label":o(`builder.back`),children:(0,R.jsx)(f,{className:`w-4 h-4`})}),(0,R.jsx)(`input`,{value:z,onChange:e=>Ve(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,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsxs)(le,{delayDuration:150,children:[(0,R.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[o(`builder.config.maxIterations`),(0,R.jsxs)(ue,{children:[(0,R.jsx)(me,{asChild:!0,children:(0,R.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":o(`builder.config.maxIterations`),children:(0,R.jsx)(de,{className:`w-3 h-3`})})}),(0,R.jsx)(xe,{className:`max-w-xs leading-relaxed`,children:o(`builder.config.maxIterationsHint`)})]}),(0,R.jsx)(`input`,{type:`number`,min:1,value:Ge,onChange:e=>V(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,R.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[o(`builder.config.timeout`),(0,R.jsxs)(ue,{children:[(0,R.jsx)(me,{asChild:!0,children:(0,R.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":o(`builder.config.timeout`),children:(0,R.jsx)(de,{className:`w-3 h-3`})})}),(0,R.jsx)(xe,{className:`max-w-xs leading-relaxed`,children:o(`builder.config.timeoutHint`)})]}),(0,R.jsx)(`input`,{type:`number`,min:0,"aria-label":o(`builder.config.timeout`),value:H,onChange:e=>U(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,R.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[o(`builder.config.maxCost`),(0,R.jsxs)(ue,{children:[(0,R.jsx)(me,{asChild:!0,children:(0,R.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":o(`builder.config.maxCost`),children:(0,R.jsx)(de,{className:`w-3 h-3`})})}),(0,R.jsx)(xe,{className:`max-w-xs leading-relaxed`,children:o(`builder.config.maxCostHint`)})]}),(0,R.jsx)(`input`,{type:`number`,min:0,step:.5,placeholder:`∞`,value:Xe??``,onChange:e=>{let t=Number(e.target.value);W(e.target.value===``||!(t>0)?null:t)},className:`w-16 h-6 text-xs rounded border border-border bg-transparent px-1 text-foreground`})]})]}),Z&&(0,R.jsx)(`button`,{type:`button`,"aria-pressed":q,onClick:()=>J(e=>!e),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:o(`builder.loopSettings`)}),He&&(0,R.jsxs)(`button`,{type:`button`,onClick:()=>B(!0),disabled:nt,"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,R.jsx)(ee,{className:`w-3 h-3`}),` `,o(`actions.restoreBuiltin`)]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>void Xt(),disabled:xt,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,R.jsx)(pe,{className:`w-3 h-3`}),` `,o(`builder.preview.label`)]}),!Se()&&(0,R.jsxs)(`button`,{type:`button`,disabled:nt,onClick:()=>void Zt().then(async e=>{if(!(!e||!h))try{await ye(w,h),n?n():g()}catch(e){l.error(String(e))}}),className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted disabled:opacity-50`,children:[(0,R.jsx)(m,{className:`w-3 h-3`}),o(`window.open`)]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>void Zt().then(e=>e&&l.success(o(`builder.saved`))),disabled:nt,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,R.jsx)(p,{className:`w-3 h-3`}),` `,o(`builder.save`)]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>void Qt(),disabled:nt,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,R.jsx)(ne,{className:`w-3 h-3`}),` `,o(`builder.publish`)]})]})]}),He&&(0,R.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:o(`builder.builtin.note`)}),(0,R.jsx)(se,{open:We,onOpenChange:e=>{e||B(!1)},children:(0,R.jsxs)(x,{className:`max-w-sm`,children:[(0,R.jsxs)(b,{children:[(0,R.jsx)(oe,{children:o(`builder.builtin.confirmTitle`)}),(0,R.jsx)(ae,{children:o(`builder.builtin.confirmBody`)})]}),(0,R.jsxs)(ie,{children:[(0,R.jsx)(C,{variant:`ghost`,onClick:()=>B(!1),children:o(`common:actions.cancel`)}),(0,R.jsx)(C,{"data-testid":`builder-restore-confirm`,onClick:()=>void Rt(),children:o(`actions.restoreBuiltin`)})]})]})}),(0,R.jsxs)(`div`,{className:`flex-1 flex min-h-0`,children:[(0,R.jsxs)(`div`,{className:`w-44 border-r border-border p-2 space-y-1 flex-shrink-0 overflow-y-auto`,children:[(0,R.jsx)(`p`,{className:`text-[10px] font-semibold uppercase tracking-wide text-muted-foreground px-1 mb-1`,children:o(`builder.addNode`)}),Z&&he&&(0,R.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground px-1`,children:o(`builder.core.unavailable`)}),Z&&T.length>0&&[`ai`,`verification`,`openspec`,`control`].map(e=>(0,R.jsxs)(`div`,{className:`pt-2`,children:[(0,R.jsx)(`p`,{className:`text-[10px] uppercase text-muted-foreground px-1`,children:o(`builder.core.groups.${e}`)}),T.filter(t=>![`implementation`,`implementation-step`].includes(t.kind)&&Je(t.kind)===e).map(e=>(0,R.jsxs)(`button`,{type:`button`,draggable:!0,onDragStart:t=>{t.dataTransfer.setData(`application/specrails-core-piece`,e.kind),t.dataTransfer.effectAllowed=`copy`},onClick:()=>Yt(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,R.jsx)(v,{className:`h-3 w-3 flex-shrink-0`}),o(`builder.core.pieces.${e.kind}`)]},e.kind))]},e)),(Z?[`start`]:gt).map(e=>{let t=_t[e];return(0,R.jsxs)(`button`,{type:`button`,onClick:()=>Gt(e),disabled:e===`start`&&N.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,R.jsx)(t,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,R.jsx)(`span`,{className:`truncate`,children:o(`builder.nodes.${e}`)}),(0,R.jsx)(v,{className:`w-3 h-3 ml-auto opacity-50`})]},e)})]}),(0,R.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=T.find(t=>t.kind===e.dataTransfer.getData(`application/specrails-core-piece`));!t||!Z||(e.preventDefault(),Yt(t,re({x:e.clientX,y:e.clientY})))},children:Qe?(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`…`})}):(0,R.jsxs)(Ae,{nodes:N,edges:F,onNodesChange:Ht,onEdgesChange:Fe,onConnect:zt,isValidConnection:Bt,onNodeClick:(e,t)=>{J(!1),K(t.id)},onPaneClick:()=>{J(!1),K(null)},nodeTypes:It,colorMode:_.scheme===`dark`?`dark`:`light`,fitView:!0,fitViewOptions:{padding:.25,maxZoom:.85},minZoom:.2,defaultEdgeOptions:{type:`smoothstep`,markerEnd:{type:Ne.ArrowClosed,width:16,height:16}},proOptions:{hideAttribution:!0},children:[Z&&(0,R.jsx)(Me,{position:`top-center`,children:(0,R.jsxs)(`nav`,{className:`flex items-center gap-1 rounded border border-border bg-card/95 p-1 text-xs`,"aria-label":o(`builder.core.breadcrumbs`),children:[(0,R.jsx)(`button`,{type:`button`,onClick:()=>Jt(null),className:`px-2 py-1 hover:bg-muted`,children:z||o(`builder.core.root`)}),M&&(0,R.jsxs)(`span`,{"aria-current":`page`,children:[`/ `,M]})]})}),(0,R.jsx)(je,{}),(0,R.jsx)(Pe,{}),(0,R.jsx)(Ee,{pannable:!0,zoomable:!0}),(0,R.jsx)(Me,{position:`top-left`,children:(0,R.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":o(`builder.arrange.label`),children:[[`vertical`,Be],[`horizontal`,ze],[`grid`,Re],[`default`,ee]].map(([e,t])=>{let n=e==="default"?`reset`:e,r=e==="default"?Ot===`manual`:Ot===e;return(0,R.jsx)(`button`,{type:`button`,title:o(`builder.arrange.${n}`),"aria-label":o(`builder.arrange.${n}`),"aria-pressed":r,onClick:()=>Vt(e),className:S(`inline-flex items-center justify-center w-7 h-7 rounded hover:bg-muted`,r?`bg-muted text-accent-primary`:`text-muted-foreground hover:text-foreground`),children:(0,R.jsx)(t,{className:`w-3.5 h-3.5`})},e)})})}),(0,R.jsx)(Me,{position:`top-right`,children:(0,R.jsx)(le,{delayDuration:150,children:(0,R.jsxs)(ue,{children:[(0,R.jsx)(me,{asChild:!0,children:(0,R.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,R.jsx)(de,{className:`w-3 h-3`}),o(`builder.edgesHelp.label`)]})}),(0,R.jsx)(xe,{className:`max-w-xs leading-relaxed`,children:o(`builder.edgesHelp.body`)})]})})}),X.length>0&&(0,R.jsx)(Me,{position:`bottom-center`,children:(0,R.jsxs)(`div`,{className:`rounded-md border border-border bg-card/95 backdrop-blur text-xs overflow-hidden max-w-md mb-2`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>dt(e=>!e),className:S(`flex items-center gap-1.5 w-full px-2.5 py-1.5 font-medium`,wt>0?`text-destructive`:`text-accent-warning`),children:[(0,R.jsx)(te,{className:`w-3.5 h-3.5`}),o(`builder.problems.count`,{count:X.length})]}),ut&&(0,R.jsx)(`ul`,{className:`border-t border-border max-h-40 overflow-y-auto py-1`,children:X.map((e,t)=>(0,R.jsx)(`li`,{children:(0,R.jsxs)(`button`,{type:`button`,disabled:!e.nodeId,onClick:()=>{e.nodeId&&(J(!1),K(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,R.jsx)(`span`,{className:S(`mt-1 w-1.5 h-1.5 rounded-full flex-shrink-0`,e.severity===`error`?`bg-destructive`:`bg-accent-warning`)}),(0,R.jsx)(`span`,{className:`text-foreground`,children:`message`in e?String(e.message):o(`builder.problems.${e.code}`)})]})},`${e.code}-${e.nodeId??t}`))})]})})]})}),(0,R.jsxs)(`div`,{className:`w-80 border-l border-border p-3 flex-shrink-0 overflow-y-auto space-y-4`,children:[!q&&($?$.data.kind===`core`?(0,R.jsx)(et,{nodeId:$.id,data:$.data,piece:T.find(e=>e.kind===$.data.coreKind),choices:{...D,roles:A?.config.agents?[...Object.keys(A.config.agents.agents),...Object.keys(A.config.agents.roles??{})]:D.roles,components:Object.keys(A?.components??{})},schema:E,onChange:Kt,onDelete:qt,onOpenCanvas:Jt}):(0,R.jsx)(Dt,{data:$.data,onChange:Kt,onDelete:qt,constants:jt,onManageConstants:()=>Pt(!0)}):(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`builder.inspector.selectNode`)})),!q&&Z&&A&&$&&(Ye($.id,$.data.coreKind,$.data.params??{}).length>0||$.data.coreKind===`implementation-step`&&$.data.params?.phase===`archive`)&&(0,R.jsx)(Ze,{mode:$.data.coreKind===`implementation`?`all`:`step`,graph:Q(),value:A.config.agents,selectedRole:String($.data.params?.phase??Ye($.id,$.data.coreKind,$.data.params??{})[0]??``),onChange:e=>j({...A,config:{...A.config,agents:e}})},`${h}:${$.id}`),q&&Z&&A&&(0,R.jsx)(Ze,{mode:`workflow`,graph:Q(),value:A.config.agents,selectedRole:$?Ye($.id,$.data.coreKind,$.data.params??{})[0]:void 0,onChange:e=>j({...A,config:{...A.config,agents:e}})},h),q&&Z&&A&&(0,R.jsx)($e,{graph:A,canvas:M,schema:E,onChange:j,onOpenCanvas:Jt})]})]}),(0,R.jsx)(Tt,{open:Nt,onClose:()=>Pt(!1),constants:jt,onChanged:Ft,t:o}),(0,R.jsx)(Et,{steps:vt,onClose:()=>bt(null),t:o})]})})})}var xt=[{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 St({token:e,label:t,description:n,onInsert:r}){return(0,R.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 X({t:e,onInsert:t}){let[n,r]=(0,L.useState)([]);return(0,L.useEffect)(()=>{let e=!1;return k.loopCommands().then(t=>{e||r(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,R.jsxs)(`div`,{className:`mb-2 space-y-1.5`,children:[xt.map(n=>(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`span`,{className:`block text-[9px] uppercase tracking-wide text-muted-foreground/70 mb-0.5`,children:e(n.labelKey)}),(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.tokens.map(e=>(0,R.jsx)(St,{token:e.token,label:e.label,onInsert:t},e.token))})]},n.labelKey)),n.length>0&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`span`,{className:`block text-[9px] uppercase tracking-wide text-muted-foreground/70 mb-0.5`,children:e(`builder.inspector.tokensCommands`)}),(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>(0,R.jsx)(St,{token:`{{cmd:${e.name}}}`,label:`⚡ ${e.label}`,description:e.description,onInsert:t},e.name))})]})]})}function Ct({t:e,constants:t,onInsert:n,onManage:r}){return(0,R.jsxs)(`div`,{className:`mb-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between mb-0.5`,children:[(0,R.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:e(`builder.constants.label`)}),(0,R.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,R.jsx)(P,{className:`w-3 h-3`})})]}),(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.map(e=>(0,R.jsx)(St,{token:`{{const:${e.name}}}`,label:e.builtin?`🔒 ${e.name}`:e.name,description:e.value,onInsert:n},e.id))})]})}function wt({c:e,onSave:t,onDelete:n}){let[r,i]=(0,L.useState)(e.value);return(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`code`,{className:`text-[10px] font-mono text-accent-primary w-28 truncate`,title:e.name,children:e.name}),(0,R.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,R.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,R.jsx)(p,{className:`w-3.5 h-3.5`})}),(0,R.jsx)(`button`,{type:`button`,onClick:n,className:`text-muted-foreground hover:text-destructive`,"aria-label":`delete`,children:(0,R.jsx)(y,{className:`w-3.5 h-3.5`})})]})}function Tt({open:e,onClose:t,constants:n,onChanged:r,t:i}){let[a,o]=(0,L.useState)(``),[s,c]=(0,L.useState)(``),[l,u]=(0,L.useState)(null),[d,f]=(0,L.useState)(!1),p=n.filter(e=>e.builtin),m=n.filter(e=>!e.builtin),h=async()=>{f(!0),u(null);try{await k.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,R.jsx)(se,{open:e,onOpenChange:e=>{e||t()},children:(0,R.jsxs)(x,{className:`max-w-md`,children:[(0,R.jsx)(b,{children:(0,R.jsx)(oe,{children:i(`builder.constants.title`)})}),(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[m.length===0&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`builder.constants.empty`)}),m.map(e=>(0,R.jsx)(wt,{c:e,onSave:t=>void k.updateConstant(e.id,t).then(r),onDelete:()=>void k.deleteConstant(e.id).then(r)},e.id))]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5 border-t border-border pt-2`,children:[(0,R.jsx)(`input`,{className:`${g} w-28`,placeholder:i(`builder.constants.name`),value:a,onChange:e=>o(e.target.value)}),(0,R.jsx)(`input`,{className:`${g} flex-1`,placeholder:i(`builder.constants.value`),value:s,onChange:e=>c(e.target.value)}),(0,R.jsx)(C,{size:`sm`,disabled:d||!a.trim()||!s,onClick:()=>void h(),children:i(`builder.constants.add`)})]}),l&&(0,R.jsx)(`p`,{className:`text-[10px] text-destructive`,children:l}),p.length>0&&(0,R.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[(0,R.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:i(`builder.constants.builtinBadge`)}),p.map(e=>(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px]`,children:[(0,R.jsx)(`code`,{className:`font-mono text-accent-primary w-28 truncate`,title:e.name,children:e.name}),(0,R.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.value})]},e.id))]})]}),(0,R.jsx)(ie,{children:(0,R.jsx)(C,{variant:`ghost`,onClick:t,children:i(`common:actions.close`)})})]})})}function Et({steps:e,onClose:t,t:n}){return(0,R.jsx)(se,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,R.jsxs)(x,{className:`max-w-2xl`,children:[(0,R.jsx)(b,{children:(0,R.jsx)(oe,{children:n(`builder.preview.title`)})}),(0,R.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:n(`builder.preview.sampleNote`)}),(0,R.jsxs)(`div`,{className:`space-y-2 max-h-[60vh] overflow-y-auto`,children:[e&&e.length===0&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`builder.preview.empty`)}),e?.map((e,t)=>(0,R.jsxs)(`div`,{className:`rounded-md border border-border`,children:[(0,R.jsxs)(`div`,{className:`px-2.5 py-1 text-[10px] border-b border-border flex items-center gap-1.5`,children:[(0,R.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,R.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,R.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,R.jsx)(ie,{children:(0,R.jsx)(C,{variant:`ghost`,onClick:t,children:n(`common:actions.close`)})})]})})}function Dt({data:e,onChange:t,onDelete:n,constants:r,onManageConstants:i}){let{t:o}=a(`loops`),{activeProjectId:s,projects:l}=c(),u=T(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,L.useRef)(null),h=(0,L.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)})},_=e=>g(m,`prompt`,e);return(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(`span`,{className:`text-xs font-semibold text-foreground`,children:o(`builder.nodes.${d}`)}),(0,R.jsx)(`button`,{type:`button`,onClick:n,"aria-label":o(`builder.deleteNode`),className:`text-muted-foreground hover:text-destructive`,children:(0,R.jsx)(y,{className:`w-3.5 h-3.5`})})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.label`)}),(0,R.jsx)(`input`,{className:p,value:String(e.label??``),onChange:e=>t({label:e.target.value}),placeholder:o(`builder.nodes.${d}`)})]}),d===`ai-step`&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.prompt`)}),(0,R.jsx)(X,{t:o,onInsert:_}),(0,R.jsx)(Ct,{t:o,constants:r,onInsert:_,onManage:i}),(0,R.jsx)(`textarea`,{ref:m,rows:7,className:p,value:String(e.prompt??``),onChange:e=>t({prompt:e.target.value})}),(0,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-1`,children:o(`builder.inspector.promptHint`)})]}),d===`shell`&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.command`)}),(0,R.jsx)(`input`,{className:p,value:String(e.command??``),onChange:e=>t({command:e.target.value}),placeholder:`npm test`}),(0,R.jsxs)(`label`,{className:`${f} mt-3`,children:[o(`common:repositories.shellTarget`),(0,R.jsxs)(`select`,{className:p,value:String(e.repositoryId??``),onChange:e=>t({repositoryId:e.target.value||void 0}),children:[(0,R.jsx)(`option`,{value:``,children:o(`common:repositories.shellDefault`)}),u.filter(e=>e.kind===`git`).map(e=>(0,R.jsx)(`option`,{value:e.id,children:e.name},e.id)),!!e.repositoryId&&!u.some(t=>t.id===e.repositoryId)&&(0,R.jsx)(`option`,{value:String(e.repositoryId),children:String(e.repositoryId)})]})]}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`common:repositories.shellHint`)})]}),d===`decider`&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.goal`)}),(0,R.jsx)(Ct,{t:o,constants:r,onInsert:e=>g(h,`goal`,e),onManage:i}),(0,R.jsx)(`textarea`,{ref:h,rows:4,className:p,value:String(e.goal??``),onChange:e=>t({goal:e.target.value})})]}),d===`condition`&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.join`)}),(0,R.jsxs)(`select`,{className:p,value:String(e.join??`AND`),onChange:e=>t({join:e.target.value}),children:[(0,R.jsx)(`option`,{value:`AND`,children:`AND`}),(0,R.jsx)(`option`,{value:`OR`,children:`OR`})]})]}),d===`end`&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`label`,{className:f,children:o(`builder.inspector.outcome`)}),(0,R.jsxs)(`select`,{className:p,value:String(e.outcome??`success`),onChange:e=>t({outcome:e.target.value}),children:[(0,R.jsx)(`option`,{value:`success`,children:`success`}),(0,R.jsx)(`option`,{value:`failure`,children:`failure`})]})]}),d===`start`&&(0,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:o(`builder.inspector.startNote`)})]})}function Ot({loopId:e,onExit:t,onWindowOpened:n}={}){return(0,R.jsx)(Fe,{children:(0,R.jsx)(bt,{loopId:e,onExit:t,onWindowOpened:n})})}export{Ot 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-DKNbOF0u.js";import{_ as l,s as u,t as d,u as f}from"./provider-capabilities-lePfeT_Y.js";import{t as p}from"./download-CFHyyHcw.js";import{t as m}from"./external-link-D6XxC_Cu.js";import{t as h}from"./pencil-C9RkrIPZ.js";import{n as g}from"./square-Ci-PFcFe.js";import{t as _}from"./plus-CsnjfkmX.js";import{t as v}from"./rotate-ccw-Wh4id13q.js";import{t as y}from"./sparkles-DrY8hb0X.js";import{t as b}from"./trash-2-BOU3WdZZ.js";import{t as x}from"./upload-DYMjAQ6M.js";import{a as S,i as C,l as w,o as T,r as E,t as D}from"./dialog-CMgps2MY.js";import{t as O}from"./utils-BC4DHlz2.js";import{t as k}from"./button-D1xExSTF.js";import{t as ee}from"./RepositoryScopeSelector-CeCr6Jz-.js";import{Ht as A,Vt as j,X as M,Z as N,at as te,in as P,it as F,nt as I,ot as L,pt as R,rn as ne,rt as z}from"./index-lTGJJTuk.js";import{n as re}from"./TemplatePreviewModal-B8yd1AGU.js";var ie=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`}]]),ae=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 oe({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 F.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)(k,{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)(k,{size:`sm`,variant:`ghost`,onClick:()=>e(n.id),children:t(`actions.convert`)})]},n.id))})]})]})}function se(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 ce(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 le(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 ue(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 de(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 fe({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)(``),[h,_]=(0,B.useState)(``),[v,y]=(0,B.useState)(``),[b,x]=(0,B.useState)(),O=t.find(e=>e.id===(s||t[0]?.id)),A=(0,B.useMemo)(()=>O?.providers??(O?.provider?[O.provider]:[]),[O]),j=p||A[0]||``,P=(0,B.useMemo)(()=>L(j),[j]),F=f(j),I=h&&(P.some(e=>e.value===h)||F&&N(h))?h:te(j),R=l(j,I),ne=R.includes(v)?v:d(j,I)??``,z=R.length>0;return(0,V.jsx)(D,{open:o,onOpenChange:e=>{e||n()},children:(0,V.jsx)(E,{movableResizable:!0,className:`max-w-sm`,children:e&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(T,{children:[(0,V.jsx)(w,{children:a(`run.title`,{name:e.name})}),(0,V.jsx)(C,{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(``),x(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:O?.repositories??[],value:b,onChange:x}),A.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:j,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:A.map(e=>(0,V.jsx)(`option`,{value:e,children:u(e)},e))})]}),P.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`)}),F?(0,V.jsx)(M,{value:I,options:P,ariaLabel:a(`run.model`),testId:`run-model-select`,className:`w-full px-2 py-1 text-xs`,onCommit:e=>{_(e),y(d(j,e)??``)}}):(0,V.jsx)(`select`,{"aria-label":a(`run.model`),"data-testid":`run-model-select`,value:I,onChange:e=>{let t=e.target.value;_(t),y(d(j,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:P.map(e=>(0,V.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),z&&(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:ne,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)(S,{children:[(0,V.jsx)(k,{variant:`ghost`,onClick:n,children:a(`common:actions.cancel`)}),(0,V.jsxs)(k,{onClick:()=>{let e=s||t[0]?.id;e&&r({projectId:e,...b?{repositoryIds:b}:{},provider:A.length>1?j:void 0,model:P.length>0?I:void 0,effort:z?ne:void 0})},disabled:t.length===0,children:[(0,V.jsx)(g,{className:`w-3.5 h-3.5 mr-1.5`}),a(`run.execute`)]})]})]})})})}function pe({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 F.convert(e.id,m?.id)).loop)}catch(e){d(e instanceof z?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)(D,{open:!0,onOpenChange:e=>{!e&&!c&&n()},children:(0,V.jsxs)(E,{children:[(0,V.jsxs)(T,{children:[(0,V.jsx)(w,{children:a(`conversion.title`,{name:e.name})}),(0,V.jsx)(C,{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)(S,{children:[(0,V.jsx)(k,{variant:`outline`,disabled:c,onClick:n,children:a(`common:actions.cancel`)}),(0,V.jsx)(k,{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:O(`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,onWindowOpened:t}={}){let{t:n}=i(`loops`),a=r(),l=(0,B.useCallback)(e=>e.replace(/:/g,`_`),[]),u=(0,B.useCallback)((e,t)=>n(`catalog.${l(e)}.name`,{defaultValue:t}),[n,l]),d=(0,B.useCallback)((e,t)=>n(`catalog.${l(e)}.description`,{defaultValue:t}),[n,l]),[f,h]=(0,B.useState)([]),[g,x]=(0,B.useState)([]),[ee,A]=(0,B.useState)(!0),[M,N]=(0,B.useState)(null),[te,L]=(0,B.useState)(null),[H,U]=(0,B.useState)(null),[W,G]=(0,B.useState)(null),[K,q]=(0,B.useState)(null),[J,ge]=(0,B.useState)(new Set),_e=`specrails-desktop:loop-template-filter`,ve=(()=>{try{let e=localStorage.getItem(_e),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,ye]=(0,B.useState)(ve.query),[X,be]=(0,B.useState)(ve.categories);(0,B.useEffect)(()=>{try{localStorage.setItem(_e,JSON.stringify({query:Y,categories:X}))}catch{}},[Y,X]);let xe=(0,B.useCallback)(e=>{be(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),Se=(0,B.useCallback)(()=>{ye(``),be([])},[]),Ce=(0,B.useRef)(null),{projects:we,activeProjectId:Te,setActiveProjectId:Ee}=s(),De=(0,B.useCallback)(e=>{ge(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(se(e),null,2)],{type:`application/json`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=le(e),r.click(),URL.revokeObjectURL(n)},[]),Oe=(0,B.useCallback)(async e=>{try{let t=await F.legacyGraph(e.id);Z([{...e,name:n(`actions.originalCopyName`,{name:e.name}),graph:t.graph}])}catch{c.error(n(`errors.exportLegacy`))}},[Z,n]),Q=(0,B.useCallback)(async()=>{try{let[e,t]=await Promise.all([F.list(),F.templates()]);h(e),x(t)}catch{c.error(n(`errors.load`))}finally{A(!1)}},[n]);(0,B.useEffect)(()=>{Q()},[Q]);let ke=(0,B.useCallback)(async e=>{try{let t=ce(await e.text()),{imported:r,skipped:i}=await F.importLoops(t);await Q(),r.length&&c.success(n(`import.done`,{count:r.length})),i.length&&c.warning(n(`import.skipped`,{count:i.length,names:i.join(`, `)})),!r.length&&!i.length&&c.warning(n(`import.invalid`))}catch(e){let t=e instanceof Error?e.message:``;c.error(n(t===`invalid-json`||t===`no-loops`?`import.invalid`:`errors.save`))}},[Q,n]),$=(0,B.useCallback)(t=>{e?e(t):a(`/loops/${t}/edit`)},[e,a]),Ae=(0,B.useCallback)(async()=>{try{let e=await F.create({name:n(`newLoopName`)});$(e.id)}catch{c.error(n(`errors.save`))}},[n,$]),je=(0,B.useCallback)(async e=>{try{let t=await F.fromTemplate(e);$(t.id)}catch{c.error(n(`errors.save`))}},[n,$]),Me=(0,B.useCallback)(async({projectId:e,provider:t,model:r,effort:i,repositoryIds:o})=>{let s=W;if(s){G(null);try{let{loopRunId:l}=await F.runStandalone(e,s.id,{aiEngine:t,model:r,reasoning_effort:i,...o?{repositoryIds:o}:{}});Ee(e),a(`/jobs/${l}`),c.success(n(`run.launched`,{name:s.name}))}catch{c.error(n(`errors.save`))}}},[W,a,Ee,n]),Ne=(0,B.useCallback)(async e=>{try{await F.publish(e),await Q()}catch(e){e instanceof z?c.error(n(`errors.publishInvalid`)):c.error(n(`errors.save`))}},[n,Q]),Pe=(0,B.useCallback)(async e=>{try{await F.unpublish(e),await Q()}catch{c.error(n(`errors.save`))}},[n,Q]),Fe=(0,B.useCallback)(async e=>{try{await F.duplicate(e),await Q()}catch{c.error(n(`errors.save`))}},[n,Q]),Ie=(0,B.useCallback)(async()=>{let e=H;if(e){U(null);try{await F.restoreBuiltin(e),await Q(),c.success(n(`builder.builtin.restored`))}catch{c.error(n(`errors.save`))}}},[H,n,Q]),Le=(0,B.useCallback)(e=>N(e),[]),Re=(0,B.useCallback)(async()=>{let e=M;if(e){N(null);try{await F.remove(e),await Q()}catch{c.error(n(`errors.save`))}}},[M,n,Q]),ze=f.filter(e=>e.builtinId),Be=f.filter(e=>!e.builtinId),Ve=Be.filter(e=>e.status===`draft`),He=Be.filter(e=>e.status===`published`),Ue=de(g),We=ue(g.map(e=>({...e,searchTerms:`${u(e.id,e.name)} ${d(e.id,e.description)} ${e.category?n(`categories.${e.category}`,{defaultValue:e.category}):``}`})),{query:Y,categories:X}),Ge=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)(R,{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:n(`title`)}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:n(`subtitle`)})]})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!ne()&&(0,V.jsxs)(`button`,{type:`button`,onClick:()=>void P(Te).then(()=>t?.()).catch(e=>c.error(String(e))),className:`inline-flex items-center gap-1.5 h-8 px-3 rounded-md text-xs border border-border hover:bg-muted`,children:[(0,V.jsx)(m,{className:`w-3.5 h-3.5`}),n(`window.open`)]}),J.size>0&&(0,V.jsxs)(`button`,{type:`button`,onClick:()=>Z(f.filter(e=>J.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)(ie,{className:`w-3.5 h-3.5`}),n(`actions.export`),` (`,J.size,`)`]}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>Ce.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)(ae,{className:`w-3.5 h-3.5`}),n(`actions.import`)]}),(0,V.jsx)(`input`,{ref:Ce,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&ke(t),e.target.value=``}}),(0,V.jsxs)(`button`,{type:`button`,onClick:Ae,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)(_,{className:`w-3.5 h-3.5`}),n(`newLoop`)]})]})]}),ee?(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`…`}):(0,V.jsxs)(`div`,{className:`space-y-8`,children:[Ve.length===0&&He.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:n(`empty.title`)}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:n(`empty.body`)})]}),f.length>0&&(0,V.jsx)(oe,{onConvert:e=>{let t=f.find(t=>t.id===e);t&&q(t)}}),He.length>0&&(0,V.jsx)(me,{title:n(`sections.published`),children:He.map(e=>(0,V.jsx)(he,{loop:e,selected:J.has(e.id),onToggleSelect:()=>De(e.id),onEdit:()=>$(e.id),onUnpublish:()=>Pe(e.id),onDuplicate:()=>Fe(e.id),onExport:()=>Z([e]),onExportLegacy:e.hasLegacyGraph?()=>void Oe(e):void 0,onConvert:e.graph.nodes.some(e=>e.type===`core`)?void 0:()=>q(e),onDelete:()=>Le(e.id),onRun:I(e.graph)?void 0:()=>G(e)},e.id))}),Ve.length>0&&(0,V.jsx)(me,{title:n(`sections.drafts`),children:Ve.map(e=>(0,V.jsx)(he,{loop:e,selected:J.has(e.id),onToggleSelect:()=>De(e.id),onEdit:()=>$(e.id),onPublish:()=>Ne(e.id),onDuplicate:()=>Fe(e.id),onExport:()=>Z([e]),onExportLegacy:e.hasLegacyGraph?()=>void Oe(e):void 0,onConvert:e.graph.nodes.some(e=>e.type===`core`)?void 0:()=>q(e),onDelete:()=>Le(e.id)},e.id))}),ze.length>0&&(0,V.jsx)(me,{title:n(`sections.builtIn`),children:ze.map(e=>(0,V.jsx)(he,{loop:{...e,name:e.builtinModified?e.name:u(e.id,e.name)},builtIn:!0,selected:J.has(e.id),onToggleSelect:()=>De(e.id),onEdit:()=>$(e.id),onPublish:e.status===`draft`?()=>Ne(e.id):void 0,onDuplicate:()=>Fe(e.id),onExport:()=>Z([e]),onRestore:e.builtinModified?()=>U(e.id):void 0},e.id))}),g.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:n(`sections.templates`)}),(0,V.jsx)(`input`,{type:`search`,value:Y,onChange:e=>ye(e.target.value),placeholder:n(`gallery.search`),"aria-label":n(`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:[Ue.map(({category:e,count:t})=>{let r=X.includes(e);return(0,V.jsxs)(`button`,{type:`button`,"aria-pressed":r,onClick:()=>xe(e),className:O(`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:[n(`categories.${e}`,{defaultValue:e}),(0,V.jsx)(`span`,{className:`opacity-60 tabular-nums`,children:t})]},e)}),Ge&&(0,V.jsx)(`button`,{type:`button`,onClick:Se,className:`inline-flex items-center h-6 px-2 rounded-full text-[11px] text-accent-primary hover:underline`,children:n(`gallery.clearFilter`)})]}),We.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:n(`gallery.noResults`)}),(0,V.jsx)(`button`,{type:`button`,onClick:Se,className:`mt-2 text-xs text-accent-primary hover:underline`,children:n(`gallery.clearFilter`)})]}):(0,V.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:We.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)(y,{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:u(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:n(`categories.${e.category}`,{defaultValue:e.category})})]}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground flex-1`,children:d(e.id,e.description)}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[I(e.graph)?(0,V.jsx)(`span`,{title:n(`gallery.needsSpecHint`),className:`px-1.5 py-0.5 rounded text-[10px] bg-accent-secondary/15 text-accent-secondary`,children:n(`gallery.needsSpec`)}):(0,V.jsx)(`span`,{title:n(`gallery.standaloneHint`),className:`px-1.5 py-0.5 rounded text-[10px] bg-accent-success/15 text-accent-success`,children:n(`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:()=>L({...e,name:u(e.id,e.name),description:d(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)(j,{className:`w-3 h-3`}),n(`actions.preview`)]}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>je(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`}),n(`actions.use`)]})]})]},e.id))})]})]})]}),(0,V.jsx)(D,{open:M!==null,onOpenChange:e=>{e||N(null)},children:(0,V.jsxs)(E,{className:`max-w-sm`,children:[(0,V.jsxs)(T,{children:[(0,V.jsxs)(w,{className:`flex items-center gap-2`,children:[(0,V.jsx)(b,{className:`w-4 h-4 text-destructive`}),f.find(e=>e.id===M)?.name??n(`actions.delete`)]}),(0,V.jsx)(C,{children:n(`confirmDelete`)})]}),(0,V.jsxs)(S,{children:[(0,V.jsx)(k,{variant:`ghost`,onClick:()=>N(null),children:n(`common:actions.cancel`)}),(0,V.jsx)(k,{variant:`destructive`,onClick:()=>void Re(),children:n(`common:actions.delete`)})]})]})}),(0,V.jsx)(D,{open:H!==null,onOpenChange:e=>{e||U(null)},children:(0,V.jsxs)(E,{className:`max-w-sm`,children:[(0,V.jsxs)(T,{children:[(0,V.jsxs)(w,{className:`flex items-center gap-2`,children:[(0,V.jsx)(v,{className:`w-4 h-4`}),n(`builder.builtin.confirmTitle`)]}),(0,V.jsx)(C,{children:n(`builder.builtin.confirmBody`)})]}),(0,V.jsxs)(S,{children:[(0,V.jsx)(k,{variant:`ghost`,onClick:()=>U(null),children:n(`common:actions.cancel`)}),(0,V.jsx)(k,{"data-testid":`confirm-restore-builtin`,onClick:()=>void Ie(),children:n(`actions.restoreBuiltin`)})]})]})}),(0,V.jsx)(re,{template:te,onClose:()=>L(null),onUse:e=>{L(null),je(e)}}),K&&(0,V.jsx)(pe,{loop:K,projects:we,onClose:()=>q(null),onConverted:e=>{h(t=>t.map(t=>t.id===e.id?e:t)),q(null),$(e.id)}},K.id),(0,V.jsx)(fe,{loop:W?{id:W.id,name:W.name}:null,projects:we.map(e=>({id:e.id,name:e.name,providers:o(e),repositories:e.repositories})),onClose:()=>G(null),onExecute:Me})]})}function me({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 he({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:m,onRestore:_}){let{t:y}=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":y(`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:y(`builtInBadge`)}),(0,V.jsx)(K,{status:e.status})]})]}),(0,V.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[y(`card.nodes`,{count:S}),t&&e.builtinModified&&(0,V.jsxs)(`span`,{className:`ml-1.5 text-accent-secondary`,children:[`· `,y(`card.builtinModified`)]})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-1 flex-wrap`,children:[m&&(0,V.jsx)(J,{icon:g,label:y(`actions.run`),onClick:m}),(0,V.jsx)(J,{icon:h,label:y(`actions.edit`),onClick:a}),o&&(0,V.jsx)(J,{icon:x,label:y(`actions.publish`),onClick:o}),s&&(0,V.jsx)(J,{icon:p,label:y(`actions.unpublish`),onClick:s}),(0,V.jsx)(J,{icon:A,label:y(`actions.duplicate`),onClick:c}),(0,V.jsx)(J,{icon:ie,label:y(`actions.export`),onClick:l}),u&&(0,V.jsx)(J,{icon:ie,label:y(`actions.exportLegacy`),onClick:u}),d&&(0,V.jsx)(J,{icon:R,label:y(`actions.convert`),onClick:d}),_&&(0,V.jsx)(J,{icon:v,label:y(`actions.restoreBuiltin`),onClick:_}),f&&(0,V.jsx)(J,{icon:b,label:y(`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:O(`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-DaWuiO0S.js";import{n as o,t as s}from"./createLucideIcon-Bjbbp_KS.js";import{r as c}from"./useDesktop-DKNbOF0u.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(`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`}]]),h=e(t(),1),g=[`title`,`description`,`labels`,`priority`,`acceptanceCriteria`,`repositoryIds`],_={title:``,description:``,labels:[],priority:`medium`,acceptanceCriteria:[]};function v(e){return!e||typeof e!=`object`?!1:e.type===`spec_draft.update`}var y=e(r(),1),b=n(),x=42;function S(e){let t=e.replace(/\s+/g,` `).trim();return t.length<=x?t:t.slice(0,x-1).trimEnd()+`…`}function C({chat:e,projectName:t,onRestore:n,onClose:r}){let{t:i}=o(`chat`),a=S(e.label);return(0,b.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,b.jsx)(w,{kind:e.kind}),(0,b.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,b.jsx)(`div`,{className:`text-sm font-medium text-foreground truncate`,children:a}),(0,b.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5 truncate`,children:i(`chip.continueEditing`,{projectName:t})})]}),(0,b.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,b.jsx)(u,{className:`w-3.5 h-3.5`})})]})}function w({kind:e}){let{t}=o(`chat`);return(0,b.jsx)(e===`ai-edit`?l:m,{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 T({chats:e,projects:t,hidden:n,onRestore:r,onClose:i}){let{t:a}=o(`chat`),s=(0,h.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.id,n.name);return e},[t]),c=(0,h.useMemo)(()=>[...e].sort((e,t)=>t.createdAt-e.createdAt),[e]);return n||c.length===0?null:(0,y.createPortal)((0,b.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,b.jsx)(`div`,{className:`pointer-events-auto glass-card border border-border/30 rounded-lg p-3 shadow-lg w-full`,children:(0,b.jsx)(C,{chat:e,projectName:s.get(e.projectId)??a(`dock.unknownProject`),onRestore:()=>r(e.id),onClose:()=>i(e.id)})},e.id)),c.length>1&&(0,b.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,b.jsx)(p,{className:`w-3 h-3`}),a(`dock.minimizedCount`,{count:c.length})]})]}),document.body)}var E=(0,h.createContext)(null),D=`specrails-desktop:minimized-chats`,O=`specrails-desktop:minimized-chats-pending`,k=50,A=8e3;function j(){return F(D)}function M(e){L(D,e)}function N(){return F(O)}function P(e){L(O,e)}function F(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(R):[]}catch{return[]}}function I(e){return e.length<=k?e:[...e].sort((e,t)=>e.createdAt-t.createdAt).slice(e.length-k)}function L(e,t){if(!(typeof window>`u`))try{window.localStorage.setItem(e,JSON.stringify(I(t)))}catch{}}function R(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 z(){return typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function B(e){return e.kind===`explore-spec`?e.params.resumeConversationId??`pending:${e.params.pendingSpecId}`:e.params.resumeRefineId??`agent:${e.params.agentId}`}function V(e,t){return e.kind!==t.kind||e.projectId!==t.projectId?!1:B(e)===B(t)}function H({children:e}){let{projects:t,activeProjectId:n,setActiveProjectId:r}=c(),o=i(),{registerHandler:s,unregisterHandler:l}=a(),[u,d]=(0,h.useState)(()=>j()),[f,p]=(0,h.useState)([]),m=(0,h.useRef)(u);m.current=u;let g=(0,h.useRef)(f);g.current=f;let _=(0,h.useRef)(new Map),y=(0,h.useRef)(t);y.current=t;let x=(0,h.useRef)(!1);(0,h.useEffect)(()=>{if(x.current)return;x.current=!0;let e=N();P([]),e.length!==0&&d(t=>{let n=[...t];for(let t of e)n.some(e=>e.id===t.id||V(e,t))||n.push(t);return M(n),m.current=n,n})},[]),(0,h.useEffect)(()=>{let e=_.current;return()=>{for(let t of e.values())clearTimeout(t);e.clear()}},[]),(0,h.useEffect)(()=>{M(u)},[u]),(0,h.useEffect)(()=>{P(f)},[f]);let S=(0,h.useRef)(()=>{}),C=(0,h.useRef)(()=>{});(0,h.useEffect)(()=>{let e=`minimized-chats:spec-draft`;return s(e,e=>{if(!v(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,h.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:(M(n),m.current=n,n)}),p(t=>{let n=t.filter(t=>e.has(t.projectId));return n.length===t.length?t:(P(n),g.current=n,n)})},[t]);let w=(0,h.useCallback)(e=>{let t=z(),n={...e,id:t,createdAt:Date.now()};if(d(e=>{let t=I([...e.filter(e=>!V(e,n)),n]);return M(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},[]),D=(0,h.useCallback)(e=>{let t=_.current.get(e);t&&(clearTimeout(t),_.current.delete(e))},[]),O=(0,h.useCallback)(e=>{D(e),d(t=>{let n=t.filter(t=>t.id!==e);return M(n),m.current=n,n}),p(t=>{let n=t.filter(t=>t.id!==e);return n.length===t.length?t:(P(n),g.current=n,n)})},[D]),k=(0,h.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)})},[]),F=(0,h.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})},[]),L=(0,h.useCallback)(e=>{let t=m.current.find(t=>t.id===e);if(!t||y.current.length>0&&!y.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 P(r),g.current=r,r}),d(t=>{let n=t.filter(t=>t.id!==e);return M(n),m.current=n,n}),D(e);let i=setTimeout(()=>{_.current.delete(e),g.current.some(t=>t.id===e)&&(p(t=>{let n=t.filter(t=>t.id!==e);return P(n),g.current=n,n}),d(n=>{if(n.some(n=>n.id===e||V(n,t)))return n;let r=[...n,t];return M(r),m.current=r,r}))},A);_.current.set(e,i)},[n,r,o,D]),R=(0,h.useRef)(L);R.current=L;let B=(0,h.useRef)(O);B.current=O,S.current=k,C.current=F;let H=(0,h.useCallback)((e,t)=>{let n=g.current,r=n.findIndex(n=>n.kind===e&&n.projectId===t);if(r===-1)return null;let i=n[r];return D(i.id),p(e=>{let t=e.filter(e=>e.id!==i.id);return P(t),t}),g.current=n.filter(e=>e.id!==i.id),i},[D]),U=(0,h.useCallback)(e=>{let t=z(),i={...e,id:t,createdAt:Date.now()};n!==e.projectId&&r(e.projectId),o(e.restoreRoute),p(e=>{let t=[...e,i];return P(t),g.current=t,t}),D(t);let a=setTimeout(()=>{_.current.delete(t),g.current.some(e=>e.id===t)&&(p(e=>{let n=e.filter(e=>e.id!==t);return P(n),g.current=n,n}),d(e=>{if(e.some(e=>e.id===t||V(e,i)))return e;let n=[...e,i];return M(n),m.current=n,n}))},A);_.current.set(t,a)},[n,r,o,D]),W=(0,h.useMemo)(()=>({chats:u,pendingRestores:f,minimize:w,updateLabel:k,patchExploreSpecDraft:F,close:O,restore:L,takePendingRestore:H,triggerResume:U}),[u,f,w,k,F,O,L,H,U]);return(0,b.jsxs)(E.Provider,{value:W,children:[e,(0,b.jsx)(T,{chats:u,projects:t,hidden:!1,onRestore:L,onClose:O})]})}function U(){return(0,h.useContext)(E)||{chats:[],pendingRestores:[],minimize:()=>``,updateLabel:()=>{},patchExploreSpecDraft:()=>{},close:()=>{},restore:()=>{},takePendingRestore:()=>null,triggerResume:()=>{}}}function W(e,t,n){let{pendingRestores:r,takePendingRestore:i}=U(),a=(0,h.useRef)(n);a.current=n,(0,h.useEffect)(()=>{if(!t)return;let n=i(e,t);n&&a.current(n)},[r,e,t,i])}export{g as a,p as c,_ as i,f as l,U as n,v as o,W as r,m as s,H as t,d as u};
@@ -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{l as r,r as i,t as a}from"./useSharedWebSocket-DaWuiO0S.js";import{n as o,t as s}from"./createLucideIcon-Bjbbp_KS.js";import{n as c,r as l,s as u}from"./useDesktop-DKNbOF0u.js";import{s as d}from"./provider-capabilities-lePfeT_Y.js";import{t as f}from"./download-CFHyyHcw.js";import{t as p}from"./external-link-D6XxC_Cu.js";import{t as m}from"./loader-circle-DcygOQpC.js";import{t as h}from"./search-Cq_gE3Ik.js";import{t as g}from"./trash-2-BOU3WdZZ.js";import{t as _}from"./triangle-alert-H9T4jAmh.js";import{n as v,t as y}from"./jira-api-Bp0zXwjg.js";import{i as b,l as x,o as S,r as C,t as w}from"./dialog-CMgps2MY.js";import{t as T}from"./utils-BC4DHlz2.js";import{t as E}from"./button-D1xExSTF.js";import{Et as D,Gt as O,Tt as k,U as A,an as ee,bt as te,on as ne,qt as j,vt as re,yt as ie}from"./index-lTGJJTuk.js";var M=s(`earth`,[[`path`,{d:`M21.54 15H17a2 2 0 0 0-2 2v4.54`,key:`1djwo0`}],[`path`,{d:`M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17`,key:`1tzkfa`}],[`path`,{d:`M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05`,key:`14pb5j`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),ae=s(`folder-kanban`,[[`path`,{d:`M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z`,key:`1fr9dc`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M12 10v2`,key:`hh53o1`}],[`path`,{d:`M16 10v6`,key:`1d6xys`}]]),N=s(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),P=s(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),F=e(t(),1),I=n(),oe=[`todo`,`in_progress`,`on_review`,`done`,`cancelled`],se={todo:`todo`,in_progress:`inProgress`,on_review:`onReview`,done:`done`,cancelled:`cancelled`};function L(e){let{activeProjectId:t}=l();return(0,I.jsx)(R,{...e},e.apiBase??t??`legacy`)}function R({onConnected:e,onSkip:t,apiBase:n}){let{t:r}=o(`jira`),[i,a]=(0,F.useState)(1),[s,c]=(0,F.useState)(``),[l,d]=(0,F.useState)(``),[f,p]=(0,F.useState)(``),[m,h]=(0,F.useState)(`idle`),[g,_]=(0,F.useState)(null),[v,b]=(0,F.useState)(`cloud`),[x,S]=(0,F.useState)([]),[C,w]=(0,F.useState)(``),[T,D]=(0,F.useState)(``),[O,k]=(0,F.useState)(``),[ee,te]=(0,F.useState)(!1),[ne,j]=(0,F.useState)([]),[re,ie]=(0,F.useState)({}),[M,ae]=(0,F.useState)(``),[N,P]=(0,F.useState)(!1),[L,R]=(0,F.useState)(!1),H=(0,F.useRef)(0),U=(0,F.useRef)(!0);(0,F.useEffect)(()=>(U.current=!0,()=>{U.current=!1,H.current++}),[]);let[W,ce]=(0,F.useState)(!1),G=()=>({baseUrl:s.trim(),accountEmail:l.trim()||null,token:f});async function le(){h(`testing`);try{let e=await y.test(G(),n);if(!U.current)return;h(`ok`),_(e.displayName),b(e.deployment)}catch(e){if(!U.current)return;h(`error`),u.error(V(e,r))}}async function K(){a(2),te(!0);try{let{projects:e}=await y.discoverProjects({...G(),query:C.trim()||void 0},n);if(!U.current)return;S(e)}catch(e){U.current&&u.error(V(e,r))}finally{U.current&&te(!1)}}async function q(){a(3),await J()}async function J(){if(!T)return;let e=++H.current;P(!0);try{let{statuses:t}=await y.discoverStatuses({...G(),projectKey:T},n);if(!U.current||e!==H.current)return;j(t),R(!1)}catch{U.current&&e===H.current&&R(!0)}finally{U.current&&e===H.current&&P(!1)}}function Y(e,t){e!==T&&(H.current++,j([]),ie({}),ae(``),R(!1),P(!1)),D(e),k(t)}async function ue(){ce(!0);try{let t=Object.fromEntries(Object.entries(re).filter(([,e])=>e));if(await y.connect({...G(),jiraProjectKey:T.trim(),statusMap:Object.keys(t).length?t:null,discardStatus:M.trim()||null},n),!U.current)return;u.success(r(`status.connected`,{key:T.trim()})),e()}catch(e){U.current&&u.error(V(e,r))}finally{U.current&&ce(!1)}}return(0,I.jsxs)(`div`,{className:`space-y-4`,"data-testid":`jira-wizard`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`wizard.step`,{current:i,total:4})}),t&&(0,I.jsx)(`button`,{type:`button`,onClick:t,className:`text-xs text-muted-foreground hover:text-foreground hover:underline`,"data-testid":`jira-later`,children:r(`wizard.later`)})]}),i===1&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step1Title`)}),(0,I.jsx)(z,{label:r(`creds.baseUrlLabel`),help:r(`creds.baseUrlHelp`),children:(0,I.jsx)(A,{value:s,onChange:e=>{c(e.target.value),h(`idle`)},placeholder:r(`creds.baseUrlPlaceholder`)})}),(0,I.jsx)(z,{label:r(`creds.emailLabel`),help:r(`creds.emailHelp`),children:(0,I.jsx)(A,{value:l,onChange:e=>{d(e.target.value),h(`idle`)},placeholder:r(`creds.emailPlaceholder`)})}),(0,I.jsx)(z,{label:r(`creds.tokenLabel`),help:r(`creds.tokenHelp`),children:(0,I.jsx)(A,{type:`password`,value:f,onChange:e=>{p(e.target.value),h(`idle`)}})}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,I.jsx)(E,{size:`sm`,variant:`outline`,onClick:le,disabled:!s.trim()||!f.trim()||m===`testing`,children:r(m===`testing`?`creds.testing`:m===`ok`?`creds.retest`:`creds.test`)}),m===`ok`&&(0,I.jsxs)(`span`,{className:`text-xs text-accent-success`,"data-testid":`jira-test-ok`,children:[`✓ `,r(`creds.testOk`,{name:g??``}),` · `,r(v===`cloud`?`review.cloud`:`review.dc`)]})]}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsx)(E,{size:`sm`,onClick:K,disabled:m!==`ok`,children:r(`wizard.next`)})})]}),i===2&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step2Title`)}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(A,{value:C,onChange:e=>w(e.target.value),placeholder:r(`project.searchPlaceholder`)}),(0,I.jsx)(E,{size:`sm`,variant:`outline`,onClick:K,children:r(`project.searchPlaceholder`)})]}),ee?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`project.loading`)}):x.length===0?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`project.none`)}):(0,I.jsx)(`div`,{className:`max-h-48 space-y-1 overflow-y-auto`,"data-testid":`jira-project-list`,children:x.map(e=>(0,I.jsxs)(`button`,{type:`button`,onClick:()=>Y(e.key,e.name),className:`flex w-full items-center justify-between rounded px-2 py-1.5 text-left text-sm hover:bg-muted ${T===e.key?`bg-muted`:``}`,children:[(0,I.jsx)(`span`,{className:`font-medium`,children:e.key}),(0,I.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.name})]},e.id))}),(0,I.jsx)(z,{label:r(`project.manualLabel`),children:(0,I.jsx)(A,{value:T,onChange:e=>Y(e.target.value.toUpperCase(),``),placeholder:r(`project.manualPlaceholder`)})}),(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(E,{size:`sm`,variant:`ghost`,onClick:()=>a(1),children:r(`wizard.back`)}),(0,I.jsx)(E,{size:`sm`,onClick:q,disabled:!T.trim(),children:r(`wizard.next`)})]})]}),i===3&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step3Title`)}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`mapping.intro`)}),L&&(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,I.jsx)(`p`,{role:`alert`,className:`text-xs text-accent-warning`,children:r(`mapping.loadFailed`)}),(0,I.jsx)(E,{size:`sm`,variant:`outline`,disabled:N,onClick:()=>void J(),children:r(`mapping.retry`)})]}),N&&(0,I.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:r(`mapping.loading`)}),oe.map(e=>(0,I.jsx)(z,{label:r(`mapping.${se[e]}`),children:(0,I.jsxs)(`select`,{value:re[e]??``,onChange:t=>ie(n=>({...n,[e]:t.target.value||void 0})),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm`,children:[(0,I.jsx)(`option`,{value:``,children:r(`mapping.auto`)}),ne.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id))]})},e)),(0,I.jsx)(z,{label:r(`discard.configLabel`),help:r(`discard.configHelp`),children:(0,I.jsxs)(`select`,{value:M,onChange:e=>ae(e.target.value),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-discard-status-select`,children:[(0,I.jsx)(`option`,{value:``,children:r(`discard.configNone`)}),ne.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id))]})}),(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(E,{size:`sm`,variant:`ghost`,onClick:()=>a(2),children:r(`wizard.back`)}),(0,I.jsx)(E,{size:`sm`,onClick:()=>a(4),children:r(`wizard.next`)})]})]}),i===4&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step4Title`)}),(0,I.jsxs)(`dl`,{className:`space-y-1 text-sm`,children:[(0,I.jsx)(B,{label:r(`review.site`),value:s}),(0,I.jsx)(B,{label:r(`review.project`),value:O?`${T} — ${O}`:T}),(0,I.jsx)(B,{label:r(`review.account`),value:g??l}),(0,I.jsx)(B,{label:r(`review.type`),value:r(v===`cloud`?`review.cloud`:`review.dc`)}),(0,I.jsx)(B,{label:r(`discard.reviewLabel`),value:M||r(`discard.configNone`)})]}),(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(E,{size:`sm`,variant:`ghost`,onClick:()=>a(3),children:r(`wizard.back`)}),(0,I.jsx)(E,{size:`sm`,onClick:ue,disabled:W,children:r(W?`wizard.connecting`:`wizard.connect`)})]})]})]})}function z({label:e,help:t,children:n}){return(0,I.jsxs)(`label`,{className:`block space-y-1`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:e}),n,t&&(0,I.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:t})]})}function B({label:e,value:t}){return(0,I.jsxs)(`div`,{className:`flex justify-between gap-4`,children:[(0,I.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),(0,I.jsx)(`dd`,{className:`truncate text-right font-medium`,children:t})]})}function V(e,t){return e instanceof Error?e.message:t(`errors.generic`)}var H={pending:0,inflight:0,done:0,dead:0};function U({projectId:e,baseUrl:t,apiBase:n,initialCounts:r,refreshToken:i}){let{t:s}=o(`jira`),[c,l]=(0,F.useState)(null),[d,f]=(0,F.useState)(!1),[p,m]=(0,F.useState)(()=>new Set),h=(0,F.useRef)(!0),g=(0,F.useRef)(0),_=(0,F.useContext)(a),v=(0,F.useId)(),b=(0,F.useCallback)(async()=>{if(!h.current)return;let e=++g.current;try{let t=n?await y.listOutbox(`dead`,n):await y.listOutbox(`dead`);if(!h.current||e!==g.current)return;l({...t,ops:t.ops.filter(e=>e.state===`dead`)}),f(!1)}catch{h.current&&e===g.current&&f(!0)}},[n]);(0,F.useEffect)(()=>(h.current=!0,b(),()=>{h.current=!1,g.current++}),[b,i,r?.dead,r?.pending,r?.inflight,r?.done,r?.superseded]),(0,F.useEffect)(()=>{if(_)return _.registerHandler(v,t=>{if(!t||typeof t!=`object`)return;let n=t;n.type===`jira.outbox_changed`&&n.projectId===e&&b()}),()=>_.unregisterHandler(v)},[_,v,e,b]);async function x(e){if(!p.has(e)){m(t=>new Set(t).add(e));try{n?await y.retryOutbox(e,n):await y.retryOutbox(e),h.current&&await b()}catch(e){h.current&&u.error(e instanceof Error?e.message:s(`errors.generic`))}finally{h.current&&m(t=>{let n=new Set(t);return n.delete(e),n})}}}let S=c?.counts??r??H,C=S.pending+S.inflight;return(0,I.jsxs)(`div`,{className:`rounded-md border border-border p-3`,"data-testid":`jira-outbox`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:s(`outbox.title`)}),(0,I.jsx)(`p`,{className:`mt-1 text-xs ${S.dead>0?`text-accent-warning`:`text-muted-foreground`}`,children:S.dead>0?s(`outbox.dead`,{count:S.dead}):C>0?s(`outbox.pending`,{count:C}):s(S.superseded?`outbox.nonePending`:`outbox.allSynced`)}),d&&(0,I.jsxs)(`div`,{className:`mt-2 flex items-center justify-between gap-2`,children:[(0,I.jsx)(`p`,{role:`alert`,className:`text-xs text-accent-warning`,children:s(`outbox.loadFailed`)}),(0,I.jsx)(E,{variant:`outline`,size:`sm`,onClick:()=>void b(),children:s(`outbox.retry`)})]}),!!c?.ops.length&&(0,I.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:s(`outbox.deadHelp`)}),c.ops.map(e=>{let n=e.targetStatus||(e.logicalState?s(`mapping.${W(e.logicalState)}`):null),r=e.deadReason??e.lastError??``;return(0,I.jsxs)(`div`,{className:`flex items-start justify-between gap-2 rounded border border-border/60 px-2 py-2`,children:[(0,I.jsxs)(`div`,{className:`min-w-0 space-y-1 text-xs`,children:[(0,I.jsxs)(`p`,{className:`break-words`,children:[e.jiraKey?(0,I.jsx)(`a`,{href:`${t.replace(/\/$/,``)}/browse/${encodeURIComponent(e.jiraKey)}`,target:`_blank`,rel:`noreferrer`,className:`font-medium text-accent-primary hover:underline`,children:e.jiraKey}):(0,I.jsx)(`span`,{className:`font-medium`,children:s(`outbox.issueFallback`,{id:e.jiraIssueId})}),` · `,s(e.opType===`transition`?`outbox.opTransition`:e.opType===`comment`?`outbox.opComment`:e.opType===`update`?`outbox.opUpdate`:`outbox.opCreate`)]}),n&&(0,I.jsx)(`p`,{className:`break-words text-muted-foreground`,children:s(`outbox.target`,{status:n})}),(0,I.jsx)(`p`,{className:`max-h-32 overflow-y-auto whitespace-pre-wrap break-words text-muted-foreground`,children:r})]}),(0,I.jsx)(E,{className:`shrink-0`,variant:`outline`,size:`sm`,disabled:p.has(e.id),onClick:()=>void x(e.id),children:s(p.has(e.id)?`outbox.retrying`:`outbox.retry`)})]},e.id)})]})]})}function W(e){return e===`in_progress`?`inProgress`:e===`on_review`?`onReview`:e}var ce=[`todo`,`in_progress`,`on_review`,`done`,`cancelled`],G={todo:`todo`,in_progress:`inProgress`,on_review:`onReview`,done:`done`,cancelled:`cancelled`};function le(e){let{activeProjectId:t}=l(),n=`${e.apiBase??t??``}:${e.state.connection.projectId}`;return(0,I.jsx)(K,{...e},n)}function K({state:e,onChanged:t,apiBase:n}){let{t:r}=o(`jira`),i=e.connection,[a,s]=(0,F.useState)(i.enabled),[c,l]=(0,F.useState)(!1),[d,f]=(0,F.useState)(!1),[p,m]=(0,F.useState)(0),[h,g]=(0,F.useState)([]),[_,v]=(0,F.useState)(i.discardStatus??``),[b,x]=(0,F.useState)(i.statusMap??{}),[S,C]=(0,F.useState)(!1),[w,T]=(0,F.useState)(!1),D=(0,F.useRef)(0),O=(0,F.useRef)(!0),k=(0,F.useCallback)(async()=>{let e=++D.current;T(!0);try{let{statuses:t}=await y.listStatuses(n);if(!O.current||e!==D.current)return;g(t),C(!1)}catch{O.current&&e===D.current&&C(!0)}finally{O.current&&e===D.current&&T(!1)}},[n]);(0,F.useEffect)(()=>(O.current=!0,k(),()=>{O.current=!1,D.current++}),[k]);async function A(e){let i=_;v(e);try{if(n?await y.patchConnection({discardStatus:e||null},n):await y.patchConnection({discardStatus:e||null}),!O.current)return;t()}catch(e){if(!O.current)return;v(i),u.error(q(e,r))}}async function ee(e,i){let a=b,o={...b,[e]:i||void 0};x(o);let s=Object.fromEntries(Object.entries(o).filter(([,e])=>e));try{if(n?await y.patchConnection({statusMap:Object.keys(s).length?s:null},n):await y.patchConnection({statusMap:Object.keys(s).length?s:null}),!O.current)return;m(e=>e+1),t()}catch(e){if(!O.current)return;x(a),u.error(q(e,r))}}async function te(){let e=!a;s(e),f(!0);try{n?await y.setEnabled(e,n):await y.setEnabled(e)}catch(t){if(!O.current)return;s(!e),u.error(q(t,r))}finally{O.current&&f(!1)}}async function ne(){l(!0);try{let e=n?await y.syncNow(n):await y.syncNow();if(!O.current)return;u.success(r(`status.syncedToast`,{count:e.upserted})),m(e=>e+1)}catch(e){O.current&&u.error(q(e,r))}finally{O.current&&l(!1)}}async function j(){if(window.confirm(r(`status.disconnectConfirm`))){f(!0);try{if(n?await y.disconnect(n):await y.disconnect(),!O.current)return;u.success(r(`status.disconnectedToast`)),t()}catch(e){O.current&&u.error(q(e,r))}finally{O.current&&f(!1)}}}return(0,I.jsxs)(`div`,{className:`space-y-4`,"data-testid":`jira-connected`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:r(`status.connected`,{key:i.jiraProjectKey})}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[i.baseUrl,` · `,i.deployment===`cloud`?r(`review.cloud`):r(`review.dc`)]})]}),(0,I.jsx)(`a`,{href:`${i.baseUrl}/browse/${i.jiraProjectKey}`,target:`_blank`,rel:`noreferrer`,className:`text-xs text-accent-primary hover:underline`,children:r(`badge.openInJira`)})]}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border border-border p-3`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:r(`status.enabledLabel`)}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(a?`status.enabledHelp`:`status.pausedHelp`)})]}),(0,I.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":r(`status.enabledLabel`),disabled:d,onClick:te,className:`relative inline-flex h-5 w-9 shrink-0 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 ${a?`bg-accent-success`:`bg-input`}`,children:(0,I.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-background shadow-sm transition-transform ${a?`translate-x-4`:`translate-x-0.5`}`})})]}),(0,I.jsxs)(`div`,{className:`rounded-md border border-border p-3`,"data-testid":`jira-status-map`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:r(`wizard.step3Title`)}),(0,I.jsx)(`p`,{className:`mt-0.5 mb-2 text-xs text-muted-foreground`,children:r(`mapping.intro`)}),S&&(0,I.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,I.jsx)(`p`,{role:`alert`,className:`text-xs text-accent-warning`,children:r(`mapping.loadFailed`)}),(0,I.jsx)(E,{variant:`outline`,size:`sm`,disabled:w,onClick:()=>void k(),children:r(`mapping.retry`)})]}),w&&(0,I.jsx)(`p`,{role:`status`,className:`mb-2 text-xs text-muted-foreground`,children:r(`mapping.loading`)}),(0,I.jsx)(`div`,{className:`space-y-2`,children:ce.map(e=>(0,I.jsxs)(`label`,{className:`flex items-center justify-between gap-3`,children:[(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r(`mapping.${G[e]}`)}),(0,I.jsxs)(`select`,{value:b[e]??``,onChange:t=>void ee(e,t.target.value),className:`w-44 rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-statusmap-${e}`,children:[(0,I.jsx)(`option`,{value:``,children:r(`mapping.auto`)}),h.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id)),b[e]&&!h.some(t=>t.name===b[e])&&(0,I.jsx)(`option`,{value:b[e],children:b[e]})]})]},e))})]}),(0,I.jsxs)(`div`,{className:`rounded-md border border-border p-3`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:r(`discard.configLabel`)}),(0,I.jsx)(`p`,{className:`mt-0.5 mb-2 text-xs text-muted-foreground`,children:r(`discard.configHelp`)}),(0,I.jsxs)(`select`,{value:_,onChange:e=>void A(e.target.value),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-discard-status-select`,children:[(0,I.jsx)(`option`,{value:``,children:r(`discard.configNone`)}),h.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id)),_&&!h.some(e=>e.name===_)&&(0,I.jsx)(`option`,{value:_,children:_})]})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(E,{variant:`outline`,size:`sm`,onClick:ne,disabled:c,children:r(c?`status.syncing`:`status.syncNow`)}),(0,I.jsx)(E,{variant:`ghost`,size:`sm`,onClick:j,disabled:d,className:`text-destructive`,children:r(`status.disconnect`)})]}),(0,I.jsx)(U,{projectId:i.projectId,baseUrl:i.baseUrl,apiBase:n,initialCounts:e.outbox,refreshToken:p})]})}function q(e,t){return e instanceof Error?e.message:t(`errors.generic`)}var J=new Set([`claude`,`codex`,`kimi`]);function Y(e){return{provider:e,label:e===`codex`?`Codex`:`Claude`,active:!1,available:!1,detectedRoute:!1,requests:0,inputTokens:0,inputTokensSaved:0,outputTokens:0,outputTokensSaved:0,outputSavingsPercent:0,outputSavingsMethod:`none`,outputSavingsAllocated:!1}}function ue(){return{updatedAt:null,proxyStatsAvailable:!1,durableSavingsAvailable:!1,outputSavingsAvailable:!1,outputSavingsMethod:null,outputConfidence:null,providers:{codex:Y(`codex`),claude:Y(`claude`)},lastIssue:null}}var X={installed:!1,installSource:null,version:null,executablePath:null,uvPath:null,port:8787,phase:`idle`,activeProviders:{codex:!1,claude:!1},availableProviders:{codex:!1,claude:!1},detectedRoutes:{codex:!1,claude:!1},proxyRunning:!1,proxyPid:null,learning:{enabled:!1,baselineReady:!1,baselineSamples:0,updatedAt:null,lastIssue:null},metrics:ue(),lastIssue:null,updatedAt:null};function de(e){let t=e?.metrics??ue();return{...X,...e,activeProviders:{...X.activeProviders,...e?.activeProviders},availableProviders:{...X.availableProviders,...e?.availableProviders},detectedRoutes:{...X.detectedRoutes,...e?.detectedRoutes},learning:{...X.learning,...e?.learning},metrics:{...ue(),...t,providers:{codex:{...Y(`codex`),...t.providers?.codex},claude:{...Y(`claude`),...t.providers?.claude}}}}}async function Z(e){let t=await e.text(),n=t?JSON.parse(t):{};if(!e.ok){let t=n.issue;throw Object.assign(Error(t?.title??n.error??`HTTP ${e.status}`),{payload:n})}return n}function Q(e){return`${r}/api/projects/${e}`}function fe(e,t=`en`){if(!Number.isFinite(e))return`0`;try{return Intl.NumberFormat(t,{notation:`compact`,maximumFractionDigits:1}).format(Math.max(0,e))}catch{return Intl.NumberFormat(`en`,{notation:`compact`,maximumFractionDigits:1}).format(Math.max(0,e))}}function $(e,t,n){return`${fe(e,t)} ${n}`}function pe({onWindowOpened:e}={}){let{t}=o(`integrations`),{projects:n}=l(),{registerHandler:a,unregisterHandler:s}=i(),[c,d]=(0,F.useState)(``),[f,m]=(0,F.useState)(`all`),[g,_]=(0,F.useState)(X),[v,y]=(0,F.useState)(!0),[E,O]=(0,F.useState)(null),[A,j]=(0,F.useState)([]),[M,N]=(0,F.useState)(!1),[P,oe]=(0,F.useState)(!1),[se,L]=(0,F.useState)(null),[R,z]=(0,F.useState)({jira:0,serena:0,projects:0}),B=(0,F.useCallback)(async()=>{try{let e=await fetch(`${r}/api/global-plugins/headroom`).then(e=>Z(e));_(de(e.state))}finally{y(!1)}},[]);(0,F.useEffect)(()=>{B()},[B]),(0,F.useEffect)(()=>(a(`plugins-page`,e=>{let t=e;t.type===`plugin.headroom_progress`&&(t.line&&j(e=>[...e.slice(-80),t.line]),B())}),()=>s(`plugins-page`)),[a,s,B]),(0,F.useEffect)(()=>{let e=!1;async function t(){let t=await Promise.all(n.map(async e=>{let[t,n]=await Promise.all([fetch(`${Q(e.id)}/jira/connection`).then(e=>Z(e)).catch(()=>({connected:!1})),fetch(`${Q(e.id)}/plugins`).then(e=>Z(e)).catch(()=>({plugins:[]}))]),r=n.plugins.find(e=>e.name===`serena`);return{jira:+!!t.connected,serena:r&&r.status!==`not-installed`&&r.status!==`orphan`?1:0}}));e||z({jira:t.reduce((e,t)=>e+t.jira,0),serena:t.reduce((e,t)=>e+t.serena,0),projects:n.length})}return t(),()=>{e=!0}},[n]);async function V(e,t){O(e),j([]);try{let e=(await t()).state;e&&_(de(e))}catch(e){let t=e.payload;t?.state&&_(de(t.state))}finally{O(null),B()}}let H=(0,F.useMemo)(()=>[{id:`headroom-ai`,title:`Headroom AI`,scope:`global`,icon:D,description:t(`plugins.catalog.headroom.description`),installed:g.installed,status:g.lastIssue?`attention`:g.installed?g.activeProviders.codex||g.activeProviders.claude?g.installSource===`system`?`external-active`:`active`:g.installSource===`system`?`external`:`installed`:`available`,statusLabel:g.lastIssue?t(`plugins.status.attention`):g.installed?g.activeProviders.codex||g.activeProviders.claude?g.installSource===`system`?t(`plugins.status.externalActive`):t(`plugins.status.active`):g.installSource===`system`?t(`plugins.status.external`):t(`plugins.status.installed`):t(`plugins.status.available`),actionKind:g.lastIssue?`review`:g.installed?`manage`:`install`,actionLabel:g.lastIssue?t(`plugins.actions.review`):g.installed?t(`plugins.actions.manage`):t(`plugins.actions.install`),busy:E===`install`,action:()=>{if(g.lastIssue||g.installed){N(!0);return}V(`install`,()=>fetch(`${r}/api/global-plugins/headroom/install`,{method:`POST`}).then(e=>Z(e)))}}],[g,E,t]),U=(0,F.useMemo)(()=>[{id:`jira`,title:`Jira`,scope:`project`,icon:ae,description:t(`plugins.catalog.jira.description`),installed:R.jira>0,status:R.jira>0?`configured`:`available`,statusLabel:R.jira>0?t(`plugins.status.configuredCount`,{count:R.jira}):t(`plugins.status.available`),actionKind:R.jira>0?`manage`:`install`,actionLabel:R.jira>0?t(`plugins.actions.manage`):t(`plugins.actions.install`),action:()=>L(`jira`)},{id:`serena`,title:`Serena`,scope:`project`,icon:re,description:t(`plugins.catalog.serena.description`),installed:R.serena>0,status:R.serena>0?`installed`:`available`,statusLabel:R.serena>0?t(`plugins.status.installedCount`,{count:R.serena}):t(`plugins.status.available`),actionKind:R.serena>0?`manage`:`install`,actionLabel:R.serena>0?t(`plugins.actions.manage`):t(`plugins.actions.install`),action:()=>L(`serena`)}],[R,t]),W=c.trim().toLowerCase(),ce=e=>`${e.title} ${e.description} ${e.statusLabel} ${t(`plugins.scope.${e.scope}`)}`.toLowerCase().includes(W),G=[...H,...U].filter(e=>f!==`all`&&e.scope!==f?!1:ce(e)),le=G.filter(e=>e.scope===`global`&&e.installed),K=G.filter(e=>e.scope===`project`&&e.installed),q=G.filter(e=>e.scope===`global`&&!e.installed),J=G.filter(e=>e.scope===`project`&&!e.installed),Y=le.length>0||K.length>0,ue=q.length>0||J.length>0,fe=[g.installed,R.jira>0,R.serena>0].filter(Boolean).length;return(0,I.jsxs)(`div`,{className:`flex h-full flex-col bg-background`,children:[(0,I.jsxs)(`div`,{className:`border-b border-border px-6 py-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,I.jsx)(`div`,{className:`grid h-9 w-9 place-items-center rounded-lg border border-accent-primary/25 bg-accent-primary/10 text-accent-primary`,children:(0,I.jsx)(k,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`h1`,{className:`text-lg font-semibold tracking-normal`,children:t(`plugins.page.title`)}),(0,I.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:t(`plugins.page.subtitle`)})]}),!ee()&&(0,I.jsxs)(`button`,{type:`button`,onClick:()=>void ne().then(()=>e?.()).catch(e=>u.error(String(e))),className:`inline-flex items-center gap-1.5 rounded-md border border-border px-3 py-2 text-xs hover:bg-muted`,children:[(0,I.jsx)(p,{className:`h-3.5 w-3.5`}),t(`plugins.page.openWindow`)]}),(0,I.jsxs)(`div`,{className:`mr-12 flex items-center gap-2 rounded-lg border border-border bg-card/60 px-3 py-2 text-xs`,children:[(0,I.jsx)(te,{className:`h-3.5 w-3.5 text-accent-success`}),(0,I.jsx)(`span`,{className:`text-muted-foreground`,children:t(`plugins.page.readyCount`,{count:fe})})]})]}),(0,I.jsxs)(`div`,{className:`mt-4 flex flex-col gap-3 md:flex-row md:items-center`,children:[(0,I.jsxs)(`label`,{className:`relative flex-1`,children:[(0,I.jsx)(h,{className:`pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,I.jsx)(`input`,{value:c,onChange:e=>d(e.target.value),placeholder:t(`plugins.search.placeholder`),className:`h-9 w-full rounded-lg border border-border bg-background pl-9 pr-3 text-sm outline-none transition-colors focus:border-accent-primary/60`})]}),(0,I.jsx)(`div`,{className:`inline-flex h-9 rounded-lg border border-border bg-card p-1`,children:[`all`,`global`,`project`].map(e=>(0,I.jsx)(`button`,{type:`button`,onClick:()=>m(e),className:T(`rounded-md px-3 text-xs capitalize transition-colors`,f===e?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`),children:t(`plugins.filters.${e}`)},e))})]})]}),(0,I.jsxs)(`div`,{className:`flex-1 overflow-auto px-6 py-5`,children:[(0,I.jsxs)(`section`,{className:`mb-6`,children:[(0,I.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,I.jsx)(ie,{className:`h-3.5 w-3.5`}),t(`plugins.sections.installed`)]}),Y?(0,I.jsx)(me,{globalPlugins:le,projectPlugins:K}):(0,I.jsx)(he,{text:t(W?`plugins.empty.installedSearch`:`plugins.empty.installed`)})]}),(0,I.jsxs)(`section`,{children:[(0,I.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,I.jsx)(k,{className:`h-3.5 w-3.5`}),t(`plugins.sections.available`)]}),ue?(0,I.jsx)(me,{globalPlugins:q,projectPlugins:J}):(0,I.jsx)(he,{text:t(W?`plugins.empty.availableSearch`:`plugins.empty.allInstalled`)})]})]}),(0,I.jsx)(w,{open:M,onOpenChange:N,children:(0,I.jsxs)(C,{className:`w-[calc(100vw-2rem)] max-w-xl overflow-x-hidden p-4 sm:p-6`,children:[(0,I.jsxs)(S,{children:[(0,I.jsx)(x,{children:t(`plugins.headroom.title`)}),(0,I.jsx)(b,{children:t(`plugins.headroom.dialogDescription`)})]}),(0,I.jsx)(ye,{state:g,loading:v,busy:E,logs:A,onInstall:()=>V(`install`,()=>fetch(`${r}/api/global-plugins/headroom/install`,{method:`POST`}).then(e=>Z(e))),onToggleProvider:(e,t)=>V(`${t?`deactivate`:`activate`}-${e}`,()=>fetch(`${r}/api/global-plugins/headroom/${t?`deactivate`:`activate`}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:e})}).then(e=>Z(e))),onDeactivateAll:()=>V(`deactivate-all`,async()=>{let e={state:g};for(let t of[`codex`,`claude`])g.activeProviders[t]&&(e=await fetch(`${r}/api/global-plugins/headroom/deactivate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:t})}).then(e=>Z(e)));return e}),onUninstall:()=>V(`uninstall`,()=>fetch(`${r}/api/global-plugins/headroom/uninstall`,{method:`POST`}).then(e=>Z(e))),onSetPort:e=>V(`port`,()=>fetch(`${r}/api/global-plugins/headroom/port`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({port:e})}).then(e=>Z(e))),onOpenDiagnostics:()=>oe(!0)})]})}),(0,I.jsx)(Ee,{plugin:se,projects:n,onClose:()=>L(null)}),(0,I.jsx)(ke,{open:P,onClose:()=>oe(!1)})]})}function me({globalPlugins:e,projectPlugins:t}){let{t:n}=o(`integrations`);return(0,I.jsxs)(`div`,{className:T(`grid grid-cols-1 gap-4`,e.length>0&&t.length>0&&`xl:grid-cols-2`),children:[e.length>0&&(0,I.jsxs)(`section`,{children:[(0,I.jsx)(_e,{title:n(`plugins.groups.global.title`),detail:n(`plugins.groups.global.detail`),scope:`global`}),(0,I.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,320px))] justify-start gap-3`,children:e.map(e=>(0,I.jsx)(ve,{plugin:e},e.id))})]}),t.length>0&&(0,I.jsxs)(`section`,{children:[(0,I.jsx)(_e,{title:n(`plugins.groups.project.title`),detail:n(`plugins.groups.project.detail`),scope:`project`}),(0,I.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,320px))] justify-start gap-3`,children:t.map(e=>(0,I.jsx)(ve,{plugin:e},e.id))})]})]})}function he({text:e}){return(0,I.jsx)(`div`,{className:`flex h-[74px] max-w-[320px] items-center rounded-lg border border-dashed border-border bg-card/35 px-3 text-xs text-muted-foreground`,children:e})}function ge({scope:e}){let{t}=o(`integrations`);return(0,I.jsx)(`span`,{className:T(`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wide`,e===`global`?`bg-accent-primary/10 text-accent-primary`:`bg-accent-info/10 text-accent-info`),children:t(`plugins.scope.${e}`)})}function _e({title:e,detail:t,scope:n}){return(0,I.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,I.jsx)(`div`,{className:T(`h-px flex-1`,n===`global`?`bg-accent-primary/30`:`bg-accent-info/30`)}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-card/70 px-2 py-1`,children:[(0,I.jsx)(ge,{scope:n}),(0,I.jsx)(`span`,{className:`text-xs font-medium`,children:e}),(0,I.jsx)(`span`,{className:`hidden text-[11px] text-muted-foreground sm:inline`,children:t})]}),(0,I.jsx)(`div`,{className:T(`h-px flex-1`,n===`global`?`bg-accent-primary/30`:`bg-accent-info/30`)})]})}function ve({plugin:e}){let{t}=o(`integrations`),n=e.icon,r=e.scope===`global`,i=e.status===`attention`,a=e.busy?m:e.actionKind===`install`?f:e.actionKind===`review`?_:P,s=T(`shrink-0 rounded border px-1.5 py-0.5 text-[10px] leading-none`,i?`border-accent-warning/30 bg-accent-warning/10 text-accent-warning`:e.installed?`border-accent-success/25 bg-accent-success/10 text-accent-success`:`border-border bg-muted text-muted-foreground`);return(0,I.jsxs)(`article`,{className:`grid h-[88px] w-full grid-cols-[38px_minmax(0,1fr)_auto] items-center gap-3 rounded-lg border border-border bg-card/70 px-3 transition-colors hover:border-accent-primary/35 hover:bg-card`,children:[(0,I.jsx)(`div`,{className:T(`grid h-[38px] w-[38px] shrink-0 place-items-center rounded-lg border`,r?`border-accent-primary/25 bg-accent-primary/10 text-accent-primary`:`border-accent-info/25 bg-accent-info/10 text-accent-info`),children:(0,I.jsx)(n,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`h2`,{className:`truncate text-sm font-semibold leading-5`,children:e.title}),(0,I.jsx)(`p`,{className:`mt-1 truncate text-[11px] leading-4 text-muted-foreground`,children:e.description}),(0,I.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-1.5`,children:[(0,I.jsx)(ge,{scope:e.scope}),(0,I.jsx)(`span`,{className:s,children:e.statusLabel})]})]}),(0,I.jsxs)(`button`,{type:`button`,disabled:e.busy,onClick:e.action,className:`flex h-7 shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-2.5 text-xs font-medium transition-colors hover:bg-muted disabled:opacity-50`,children:[(0,I.jsx)(a,{className:T(`h-3.5 w-3.5`,e.busy&&`animate-spin`)}),e.busy?t(`plugins.actions.installing`):e.actionLabel]})]})}function ye({state:e,loading:t,busy:n,logs:r,onInstall:i,onToggleProvider:a,onDeactivateAll:s,onUninstall:c,onSetPort:l,onOpenDiagnostics:u}){let{t:d}=o(`integrations`),[p,h]=(0,F.useState)(String(e.port)),[_,y]=(0,F.useState)(!1);(0,F.useEffect)(()=>h(String(e.port)),[e.port]),(0,F.useEffect)(()=>{e.installed||y(!1)},[e.installed]);let b=e.activeProviders.codex||e.activeProviders.claude,x=e.installSource===`system`;return(0,I.jsxs)(`aside`,{className:`w-full min-w-0 overflow-hidden rounded-lg border border-border bg-card/80 p-4`,children:[(0,I.jsxs)(`div`,{className:`mb-4 flex items-start gap-3`,children:[(0,I.jsx)(`div`,{className:`grid h-10 w-10 place-items-center rounded-lg border border-accent-primary/25 bg-accent-primary/10 text-accent-primary`,children:(0,I.jsx)(D,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`h2`,{className:`text-sm font-semibold`,children:d(`plugins.headroom.title`)}),(0,I.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:d(`plugins.headroom.panelDescription`)})]})]}),(0,I.jsxs)(`div`,{className:`mb-4 grid grid-cols-3 gap-2 text-xs`,children:[(0,I.jsx)(be,{label:d(`plugins.headroom.metrics.install`),value:t?d(`plugins.headroom.metrics.checking`):e.installed?d(`plugins.headroom.metrics.ready`):d(`plugins.headroom.metrics.missing`),good:e.installed}),(0,I.jsx)(be,{label:d(`plugins.headroom.metrics.source`),value:e.installSource===`system`?d(`plugins.headroom.metrics.system`):e.installSource===`managed`?d(`plugins.headroom.metrics.specrails`):d(`plugins.headroom.metrics.none`),good:e.installed}),(0,I.jsx)(be,{label:d(`plugins.headroom.metrics.proxy`),value:e.proxyRunning?`:${e.port}`:d(b?`plugins.headroom.metrics.starting`:`plugins.headroom.metrics.off`),good:e.proxyRunning||!b})]}),e.lastIssue&&(0,I.jsx)(xe,{issue:e.lastIssue}),e.installed?(0,I.jsxs)(`div`,{className:`mb-4 space-y-2`,children:[(0,I.jsx)(Te,{provider:`codex`,active:e.activeProviders.codex,available:e.availableProviders.codex,detectedRoute:e.detectedRoutes.codex,busy:n===`activate-codex`||n===`deactivate-codex`,onClick:()=>a(`codex`,e.activeProviders.codex)}),(0,I.jsx)(Te,{provider:`claude`,active:e.activeProviders.claude,available:e.availableProviders.claude,detectedRoute:e.detectedRoutes.claude,busy:n===`activate-claude`||n===`deactivate-claude`,onClick:()=>a(`claude`,e.activeProviders.claude)}),b&&(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:s,className:`flex h-8 w-full items-center justify-center gap-2 rounded-lg border border-border bg-background/45 text-xs hover:bg-muted/50 disabled:opacity-50`,children:[n===`deactivate-all`?(0,I.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(N,{className:`h-3.5 w-3.5`}),d(`plugins.headroom.actions.disableAllRoutes`)]})]}):(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:i,className:`mb-3 flex h-9 w-full items-center justify-center gap-2 rounded-lg bg-accent-primary px-3 text-xs font-medium text-white disabled:opacity-50`,children:[n===`install`?(0,I.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(f,{className:`h-3.5 w-3.5`}),d(`plugins.headroom.actions.installWithUv`)]}),e.installed&&(0,I.jsx)(Se,{state:e}),(0,I.jsxs)(`div`,{className:`mb-4 rounded-lg border border-border bg-background/45 p-3`,children:[(0,I.jsx)(`label`,{className:`mb-1 block text-[11px] font-medium text-muted-foreground`,children:d(`plugins.headroom.port.label`)}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(`input`,{value:p,onChange:e=>h(e.target.value),className:`h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-sm`}),(0,I.jsx)(`button`,{type:`button`,disabled:!!n||Number(p)===e.port,onClick:()=>l(Number(p)),className:`rounded-md border border-border px-2 text-xs hover:bg-muted disabled:opacity-50`,children:d(`plugins.headroom.port.apply`)})]})]}),r.length>0&&(0,I.jsx)(`pre`,{className:`mb-3 max-h-32 overflow-y-auto overflow-x-hidden whitespace-pre-wrap break-words rounded-lg border border-border bg-background/60 p-2 text-[10px] text-muted-foreground`,children:r.join(`
2
- `)}),(0,I.jsxs)(`button`,{type:`button`,onClick:u,className:`mb-2 flex h-8 w-full items-center justify-center gap-2 rounded-lg border border-border text-xs hover:bg-muted/50`,children:[(0,I.jsx)(v,{className:`h-3.5 w-3.5`}),d(`plugins.headroom.actions.viewDiagnostics`)]}),e.installed&&(0,I.jsx)(`div`,{className:`rounded-lg border border-destructive/25 bg-destructive/5 p-3`,children:_?(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`p`,{className:`text-[11px] leading-relaxed text-muted-foreground`,children:d(x?`plugins.headroom.confirmDetach`:`plugins.headroom.confirmUninstall`)}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,I.jsx)(`button`,{type:`button`,disabled:!!n,onClick:()=>y(!1),className:`h-8 rounded-md border border-border text-xs hover:bg-muted/50 disabled:opacity-50`,children:d(`plugins.actions.cancel`)}),(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:c,className:`flex h-8 items-center justify-center gap-2 rounded-md bg-destructive px-2 text-xs font-medium text-destructive-foreground disabled:opacity-50`,children:[n===`uninstall`?(0,I.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(g,{className:`h-3.5 w-3.5`}),d(x?`plugins.headroom.actions.detach`:`plugins.headroom.actions.uninstall`)]})]})]}):(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:()=>y(!0),className:`flex h-8 w-full items-center justify-center gap-2 rounded-md text-xs font-medium text-destructive hover:bg-destructive/10 disabled:opacity-50`,children:[(0,I.jsx)(g,{className:`h-3.5 w-3.5`}),d(x?`plugins.headroom.actions.detachHeadroom`:`plugins.headroom.actions.uninstallHeadroom`)]})})]})}function be({label:e,value:t,good:n}){return(0,I.jsxs)(`div`,{className:`rounded-lg border border-border bg-background/45 p-2`,children:[(0,I.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e}),(0,I.jsx)(`div`,{className:T(`mt-0.5 font-medium`,n?`text-foreground`:`text-accent-warning`),children:t})]})}function xe({issue:e}){let{t}=o(`integrations`),n=`plugins.headroom.issues.${e.code}`,r=t(`${n}.title`,{defaultValue:e.title}),i=t(`${n}.guidance`,{defaultValue:e.guidance});return(0,I.jsx)(`div`,{className:`mb-3 rounded-lg border border-accent-warning/35 bg-accent-warning/10 p-3`,children:(0,I.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,I.jsx)(_,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-warning`}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`div`,{className:`text-xs font-medium`,children:r}),(0,I.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-muted-foreground`,children:i}),(0,I.jsx)(`div`,{className:`mt-1 text-[10px] text-muted-foreground`,children:t(`plugins.headroom.issueCode`,{code:e.code})})]})]})})}function Se({state:e}){let{t,i18n:n}=o(`integrations`),r=e.metrics,i=r.outputSavingsAvailable,a=[`codex`,`claude`].map(e=>({provider:e,metric:r.providers[e]})),s=t(`plugins.headroom.savings.tokens`),c=a.reduce((e,{metric:t})=>({inputTokens:e.inputTokens+t.inputTokens,inputTokensSaved:e.inputTokensSaved+t.inputTokensSaved,outputTokens:e.outputTokens+t.outputTokens,outputTokensSaved:e.outputTokensSaved+t.outputTokensSaved}),{inputTokens:0,inputTokensSaved:0,outputTokens:0,outputTokensSaved:0}),l=a.some(({metric:e})=>e.inputTokensSaved>0),u=a.some(({metric:e})=>e.active),d=t(i?`plugins.headroom.savings.statusInputOutput`:l?`plugins.headroom.savings.statusInputOnly`:u?`plugins.headroom.savings.statusRouting`:`plugins.headroom.savings.statusInactive`),f=i||l;return(0,I.jsxs)(`div`,{className:`mb-4 rounded-lg border border-border bg-background/45 p-3`,children:[(0,I.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,I.jsx)(j,{className:`h-3.5 w-3.5 text-accent-primary`}),(0,I.jsx)(`div`,{className:`truncate text-xs font-medium`,children:t(`plugins.headroom.savings.title`)})]}),(0,I.jsx)(`span`,{className:T(`shrink-0 rounded border px-1.5 py-0.5 text-[10px]`,f?`border-accent-success/25 bg-accent-success/10 text-accent-success`:u?`border-accent-primary/25 bg-accent-primary/10 text-accent-primary`:`border-border bg-muted text-muted-foreground`),children:d})]}),(0,I.jsxs)(`div`,{className:`mb-2 rounded-md bg-muted/35 px-2.5 py-2`,children:[(0,I.jsx)(`div`,{className:`mb-1.5 text-[10px] font-medium uppercase text-muted-foreground`,children:t(`plugins.headroom.savings.totals`)}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,I.jsx)(Ce,{label:t(`plugins.headroom.savings.input`),processed:c.inputTokens>0?$(c.inputTokens,n.language,s):t(`plugins.headroom.savings.noData`),saved:$(c.inputTokensSaved,n.language,s)}),(0,I.jsx)(Ce,{align:`right`,label:t(`plugins.headroom.savings.output`),processed:c.outputTokens>0?$(c.outputTokens,n.language,s):t(`plugins.headroom.savings.noData`),saved:i?$(c.outputTokensSaved,n.language,s):t(`plugins.headroom.savings.noData`)})]})]}),(0,I.jsx)(`div`,{className:`grid gap-2`,children:a.map(({provider:e,metric:t})=>(0,I.jsx)(we,{metric:t,outputAvailable:r.outputSavingsAvailable},e))}),(0,I.jsx)(`div`,{className:`mt-2 flex items-center justify-end gap-2 text-[10px] text-muted-foreground`,children:r.updatedAt?t(`plugins.headroom.savings.updatedLive`):t(`plugins.headroom.savings.baselineSamples`,{count:e.learning.baselineSamples})})]})}function Ce({label:e,processed:t,saved:n,detail:r,align:i=`left`}){let{t:a}=o(`integrations`);return(0,I.jsxs)(`div`,{className:T(`min-w-0`,i===`right`&&`text-right`),children:[(0,I.jsx)(`div`,{className:`text-[10px] font-medium uppercase text-muted-foreground`,children:e}),(0,I.jsxs)(`div`,{className:`mt-1 space-y-0.5 text-[11px]`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-baseline justify-between gap-2`,children:[(0,I.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:a(`plugins.headroom.savings.processed`)}),(0,I.jsx)(`span`,{className:`truncate font-semibold tabular-nums text-foreground`,children:t})]}),(0,I.jsxs)(`div`,{className:`flex min-w-0 items-baseline justify-between gap-2`,children:[(0,I.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:a(`plugins.headroom.savings.saved`)}),(0,I.jsx)(`span`,{className:`truncate font-semibold tabular-nums text-foreground`,children:n})]})]}),r&&(0,I.jsx)(`div`,{className:`mt-1 truncate text-[10px] text-muted-foreground`,children:r})]})}function we({metric:e,outputAvailable:t}){let{t:n,i18n:r}=o(`integrations`),i=!e.available,a=i||!e.active,s=n(`plugins.headroom.savings.tokens`),c=e.inputTokens>0?$(e.inputTokens,r.language,s):n(`plugins.headroom.savings.noData`),l=$(e.inputTokensSaved,r.language,s),u=e.outputTokens>0?$(e.outputTokens,r.language,s):n(`plugins.headroom.savings.noData`),d=t?$(e.outputTokensSaved,r.language,s):e.active?n(`plugins.headroom.savings.noData`):n(`plugins.headroom.savings.off`),f=e.requests>0?n(`plugins.headroom.savings.requestCount`,{count:fe(e.requests,r.language)}):i?n(`plugins.headroom.provider.noProjectUsesProvider`):e.active?n(`plugins.headroom.savings.inputSavingsActive`):n(`plugins.headroom.savings.routeDisabled`);return(0,I.jsxs)(`div`,{className:T(`rounded-md border border-border bg-card/45 px-2.5 py-2`,a&&`opacity-70`),children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium`,children:e.label}),e.detectedRoute&&(0,I.jsx)(`span`,{className:`rounded bg-accent-primary/10 px-1.5 py-0.5 text-[9px] uppercase text-accent-primary`,children:n(`plugins.headroom.savings.detected`)})]}),(0,I.jsx)(`div`,{className:`mt-0.5 truncate text-[10px] text-muted-foreground`,children:f}),(0,I.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-3`,children:[(0,I.jsx)(Ce,{label:n(`plugins.headroom.savings.input`),processed:c,saved:l}),(0,I.jsx)(Ce,{align:`right`,label:n(`plugins.headroom.savings.output`),processed:u,saved:d})]})]})}function Te({provider:e,active:t,available:n,detectedRoute:r,busy:i,onClick:a}){let{t:s}=o(`integrations`),c=s(n?t?`plugins.headroom.provider.routedThroughHeadroom`:r?`plugins.headroom.provider.detectedExternalRoute`:`plugins.headroom.provider.notRouted`:`plugins.headroom.provider.noProjectUsesProvider`);return(0,I.jsxs)(`button`,{type:`button`,onClick:a,disabled:i||!n,className:`flex w-full items-center gap-3 rounded-lg border border-border bg-background/45 p-3 text-left hover:bg-muted/35 disabled:opacity-50`,children:[(0,I.jsx)(`div`,{className:T(`grid h-8 w-8 place-items-center rounded-md`,t?`bg-accent-success/15 text-accent-success`:`bg-muted text-muted-foreground`),children:i?(0,I.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(M,{className:`h-3.5 w-3.5`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`div`,{className:`text-xs font-medium capitalize`,children:e}),(0,I.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:c})]}),(0,I.jsx)(`span`,{className:T(`h-5 w-9 rounded-full p-0.5 transition-colors`,t?`bg-accent-success`:`bg-muted`),children:(0,I.jsx)(`span`,{className:T(`block h-4 w-4 rounded-full bg-white shadow transition-transform`,t&&`translate-x-4`)})})]})}function Ee({plugin:e,projects:t,onClose:n}){let{t:r}=o(`integrations`),[i,a]=(0,F.useState)(``);(0,F.useEffect)(()=>a(``),[e]);let s=t.find(e=>e.id===i)??null;return(0,I.jsx)(w,{open:!!e,onOpenChange:e=>{e||n()},children:(0,I.jsxs)(C,{className:`w-[calc(100vw-2rem)] max-w-3xl overflow-x-hidden p-4 sm:p-6`,children:[(0,I.jsxs)(S,{children:[(0,I.jsx)(x,{children:r(e===`jira`?`plugins.projectWizard.configureJira`:`plugins.projectWizard.installSerena`)}),(0,I.jsx)(b,{children:r(`plugins.projectWizard.description`)})]}),(0,I.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-[260px_minmax(0,1fr)]`,children:[(0,I.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/70 p-3`,children:[(0,I.jsx)(`div`,{className:`mb-2 text-xs font-medium text-muted-foreground`,children:r(`plugins.projectWizard.chooseProject`)}),(0,I.jsx)(`div`,{className:`max-h-[52vh] space-y-1 overflow-auto`,children:t.map(t=>{let n=e===`serena`&&!c(t).some(e=>J.has(e));return(0,I.jsxs)(`button`,{type:`button`,disabled:n,onClick:()=>a(t.id),className:T(`w-full rounded-md px-2 py-2 text-left transition-colors`,t.id===i?`bg-muted text-foreground`:`text-muted-foreground hover:bg-muted/45 hover:text-foreground`,n&&`cursor-not-allowed opacity-45`),children:[(0,I.jsx)(`div`,{className:`truncate text-xs font-medium`,children:t.name}),(0,I.jsx)(`div`,{className:`truncate text-[10px]`,children:n?r(`plugins.projectWizard.requiresSupportedProvider`,{defaultValue:`Requires Claude or Codex`}):t.path})]},t.id)})})]}),(0,I.jsx)(`div`,{className:`min-h-[360px] rounded-lg border border-border bg-card/70 p-4`,children:s?e===`jira`?(0,I.jsx)(De,{project:s,onDone:n}):(0,I.jsx)(Oe,{project:s,onDone:n}):(0,I.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:r(`plugins.projectWizard.selectProjectToContinue`)})})]})]})})}function De({project:e,onDone:t}){let{t:n}=o(`integrations`),r=Q(e.id),[i,a]=(0,F.useState)(null),[s,c]=(0,F.useState)(!0),[l,u]=(0,F.useState)(null),d=(0,F.useCallback)(async()=>{c(!0),u(null);try{let e=await fetch(`${r}/jira/connection`).then(e=>Z(e));a(e)}catch(e){a({connected:!1}),u(e.message)}finally{c(!1)}},[r]);return(0,F.useEffect)(()=>{d()},[d]),s?(0,I.jsxs)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:[(0,I.jsx)(m,{className:`mr-2 h-4 w-4 animate-spin`}),n(`plugins.jira.loading`,{defaultValue:`Loading Jira...`})]}):i?.connected&&i.connection?(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:n(`plugins.jira.titleForProject`,{name:e.name,defaultValue:`Jira for ${e.name}`})}),(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`plugins.jira.configuredDescription`,{defaultValue:`Manage the Jira project, status mapping, discard status, sync, and connection state.`})})]}),(0,I.jsx)(le,{state:i,apiBase:r,onChanged:()=>{d()}})]}):(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:n(`plugins.jira.titleForProject`,{name:e.name,defaultValue:`Jira for ${e.name}`})}),(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:l?n(`plugins.jira.loadFailed`,{message:l,defaultValue:`Could not load the current Jira configuration: ${l}`}):n(`plugins.jira.notConfiguredDescription`,{defaultValue:`Connect this project to Jira.`})})]}),(0,I.jsx)(L,{apiBase:r,onConnected:()=>{d()},onSkip:t})]})}function Oe({project:e,onDone:t}){let{t:n}=o(`integrations`),r=(0,F.useMemo)(()=>c(e).filter(e=>J.has(e)),[e]),i=r.includes(e.provider)?e.provider:r[0]??e.provider,[a,s]=(0,F.useState)(i),[l,u]=(0,F.useState)(null),[p,h]=(0,F.useState)(null),[g,v]=(0,F.useState)(!1),[y,b]=(0,F.useState)(null),x=(0,F.useRef)(0);(0,F.useEffect)(()=>{s(i),u(null),h(null)},[e.id,i]);let S=(0,F.useCallback)(async()=>{let t=++x.current;b(null);try{let n=`?provider=${encodeURIComponent(a)}`,r=await fetch(`${Q(e.id)}/plugins${n}`).then(e=>Z(e));if(t!==x.current)return;let i=r.plugins.find(e=>e.name===`serena`)??null;if(u(i),h(null),i?.status===`not-installed`){let r=await fetch(`${Q(e.id)}/plugins/serena/preview-install${n}`).then(e=>Z(e));t===x.current&&h(r)}}catch(e){t===x.current&&b(e.message)}},[e.id,a]);(0,F.useEffect)(()=>{S()},[S]);async function C(){v(!0),b(null);try{await fetch(`${Q(e.id)}/plugins/serena/install`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:a})}).then(e=>Z(e)),await S(),t()}catch(e){b(e.message)}finally{v(!1)}}let w=(p?.requirements??[]).every(e=>e.installed&&e.executable&&e.meetsMinimum),T=l?n(`plugins.projectStatus.${l.status}`,{defaultValue:l.status}):``,E=l?.name===`serena`?n(`plugins.catalog.serena.description`):l?.description;return!l&&!y?(0,I.jsxs)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:[(0,I.jsx)(m,{className:`mr-2 h-4 w-4 animate-spin`}),` `,n(`plugins.serena.loading`)]}):(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:n(`plugins.serena.titleForProject`,{name:e.name})}),(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`plugins.serena.description`)})]}),(0,I.jsxs)(`label`,{className:`block space-y-1`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium`,children:n(`plugins.serena.provider`,{defaultValue:`AI provider`})}),(0,I.jsx)(`select`,{"aria-label":n(`plugins.serena.provider`,{defaultValue:`AI provider`}),value:a,disabled:g,onChange:e=>{u(null),h(null),s(e.target.value)},className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-xs`,children:r.map(e=>(0,I.jsx)(`option`,{value:e,children:d(e)},e))})]}),l&&(0,I.jsxs)(`div`,{className:`rounded-lg border border-border bg-background/45 p-3`,children:[(0,I.jsx)(`div`,{className:`text-xs font-medium`,children:n(`plugins.serena.status`,{status:T})}),E&&(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:E})]}),p&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`mb-1 text-xs font-medium`,children:n(`plugins.serena.files`)}),(0,I.jsx)(`ul`,{className:`space-y-1 text-xs font-mono`,children:p.files.map(e=>(0,I.jsxs)(`li`,{className:e.op===`create`?`text-accent-success`:`text-accent-info`,children:[e.op===`create`?`+ `:`~ `,e.path]},e.path))})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`mb-1 text-xs font-medium`,children:n(`plugins.serena.prerequisites`)}),(0,I.jsx)(`ul`,{className:`space-y-1 text-xs`,children:p.requirements.map(e=>(0,I.jsxs)(`li`,{className:`flex items-center gap-2`,children:[e.installed&&e.executable&&e.meetsMinimum?(0,I.jsx)(O,{className:`h-3 w-3 text-accent-success`}):(0,I.jsx)(_,{className:`h-3 w-3 text-accent-warning`}),(0,I.jsxs)(`span`,{children:[e.name,e.minVersion?` >= ${e.minVersion}`:``]}),e.version&&(0,I.jsxs)(`span`,{className:`text-muted-foreground`,children:[`(`,e.version,`)`]})]},e.name))})]})]}),y&&(0,I.jsx)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/10 p-3 text-xs text-destructive`,children:y}),(0,I.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,I.jsx)(`button`,{type:`button`,onClick:t,className:`rounded-md border border-border px-3 py-1.5 text-xs`,children:n(`plugins.actions.cancel`)}),(0,I.jsxs)(`button`,{type:`button`,disabled:g||l?.status!==`not-installed`||!w,onClick:C,className:`flex items-center gap-2 rounded-md bg-accent-primary px-3 py-1.5 text-xs text-white disabled:opacity-50`,children:[g?(0,I.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(f,{className:`h-3.5 w-3.5`}),n(`plugins.actions.install`)]})]})]})}function ke({open:e,onClose:t}){let{t:n}=o(`integrations`),[i,a]=(0,F.useState)(null);return(0,F.useEffect)(()=>{e&&fetch(`${r}/api/global-plugins/headroom/diagnostics`).then(e=>Z(e)).then(a).catch(e=>a({error:e.message}))},[e]),(0,I.jsx)(w,{open:e,onOpenChange:e=>{e||t()},children:(0,I.jsxs)(C,{className:`max-w-3xl`,children:[(0,I.jsxs)(S,{children:[(0,I.jsxs)(x,{className:`flex items-center gap-2`,children:[(0,I.jsx)(P,{className:`h-4 w-4`}),` `,n(`plugins.diagnostics.title`)]}),(0,I.jsx)(b,{children:n(`plugins.diagnostics.description`)})]}),(0,I.jsx)(`pre`,{className:`max-h-[62vh] overflow-y-auto overflow-x-hidden whitespace-pre-wrap break-words rounded-lg border border-border bg-background p-3 text-xs`,children:JSON.stringify(i,null,2)})]})})}export{pe 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{n as r,t as i}from"./createLucideIcon-Bjbbp_KS.js";import{r as a}from"./useDesktop-DKNbOF0u.js";import{t as o}from"./git-branch-BRM0F5GN.js";import{i as s,l as c,o as l,r as u,t as d}from"./dialog-CMgps2MY.js";import{t as f}from"./utils-BC4DHlz2.js";import{$t as p,Xt as m,a as h,g,h as _,ht as v,i as y,n as b,o as x,r as S,s as C,vt as w,xt as T,yt as E}from"./index-lTGJJTuk.js";var D=i(`key-round`,[[`path`,{d:`M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z`,key:`1s6t7t`}],[`circle`,{cx:`16.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`w0ekpg`}]]),O=e(t(),1),k=n(),A=[{id:`general`,icon:E,labelKey:`projectDialog.nav.general`},{id:`agentRuntime`,icon:m,labelKey:`projectDialog.nav.agentRuntime`},{id:`branch`,icon:o,labelKey:`projectDialog.nav.branch`},{id:`environment`,icon:D,labelKey:`projectDialog.nav.environment`},{id:`budget`,icon:v,labelKey:`projectDialog.nav.budget`},{id:`telemetry`,icon:p,labelKey:`projectDialog.nav.telemetry`},{id:`terminal`,icon:w,labelKey:`projectDialog.nav.terminal`}];function j({open:e,onClose:t}){let{t:n}=r(`settings`),{activeProjectId:i,projects:o}=a(),p=o.find(e=>e.id===i),[m,v]=(0,O.useState)(`general`),w=e=>f(`space-y-5`,m===e?``:`hidden`);return(0,k.jsx)(d,{open:e,onOpenChange:e=>{e||t()},children:(0,k.jsxs)(u,{movableResizable:!0,className:`flex max-w-5xl w-[92vw] h-[82vh] flex-col overflow-hidden`,children:[(0,k.jsxs)(l,{children:[(0,k.jsxs)(c,{className:`flex items-center gap-2`,children:[(0,k.jsx)(T,{className:`w-4 h-4`}),p?n(`projectDialog.title`,{name:p.name}):n(`page.title`)]}),(0,k.jsx)(s,{children:n(`projectDialog.description`)})]}),(0,k.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-5 py-2`,children:[(0,k.jsx)(`nav`,{className:`w-40 shrink-0 space-y-0.5 overflow-y-auto border-r border-border pr-2`,children:A.map(e=>{let t=e.icon;return(0,k.jsxs)(`button`,{type:`button`,onClick:()=>v(e.id),className:f(`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left text-xs transition-colors`,m===e.id?`bg-accent-primary/15 font-medium text-foreground`:`text-muted-foreground hover:bg-muted/40 hover:text-foreground`),children:[(0,k.jsx)(t,{className:`w-3.5 h-3.5 shrink-0`}),(0,k.jsx)(`span`,{className:`truncate`,children:n(e.labelKey)})]},e.id)})}),(0,k.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-y-auto pr-1`,children:[(0,k.jsxs)(`div`,{className:w(`general`),children:[(0,k.jsx)(_,{}),(0,k.jsx)(y,{})]}),(0,k.jsx)(`div`,{className:w(`agentRuntime`),children:(0,k.jsx)(C,{})}),(0,k.jsx)(`div`,{className:w(`branch`),children:(0,k.jsx)(S,{})}),(0,k.jsx)(`div`,{className:w(`environment`),children:(0,k.jsx)(x,{})}),(0,k.jsx)(`div`,{className:w(`budget`),children:(0,k.jsx)(b,{})}),(0,k.jsx)(`div`,{className:w(`telemetry`),children:(0,k.jsx)(h,{})}),(0,k.jsx)(`div`,{className:w(`terminal`),children:(0,k.jsx)(g,{mode:`project`})})]})]})]})})}export{j as ProjectSettingsDialog};
@@ -1,5 +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"./useSharedWebSocket-DaWuiO0S.js";import{n as i,t as a}from"./createLucideIcon-Bjbbp_KS.js";import{i as o}from"./useDesktop-DKNbOF0u.js";import{a as s,i as c,l,o as u,r as d,t as f}from"./dialog-CMgps2MY.js";import{t as p}from"./button-D1xExSTF.js";var m=new Set([`building`,`on_review`,`pr_draft`,`pr_ready`,`no_changes`,`completed`,`pr_closed`,`superseded`,`merged`,`discarded`,`implementation_failed`,`pr_failed`]),h=new Set([`none`,`local-only`,`pushed`,`pr-created`]),g=new Set([`running`,`succeeded`,`partially_succeeded`,`failed`,`unknown`]),_=new Set([`pending`,`ready`,`delivered`,`partial`,`no_changes`,`retryable_failure`,`blocked`,`not_started`,`unknown`]),v=new Set([`create-pr`,`publish`,`discard`,`poll-merge`,`merge-local`,`dismiss`,`reopen`,`acknowledge-no-changes`,`recover-and-retry`,`checkout`]),y=new Set([`implementation_running`,`implementation_failed`,`ready_for_review`,`restart_pending`,`partial_success`,`partial_delivery`,`existing_pr_updated`,`no_changes`,`commit_failed`,`branch_verification_failed`,`push_failed`,`settlement_interrupted`,`recovery_unavailable`,`operation_interrupted`,`delivery_failed`,`pr_draft_ready`,`pr_ready`,`pr_closed`,`merged`,`discarded`,`superseded`,`cleanup_incomplete`,`status_failed`,`ref_mismatch`]);function b(e){return typeof e==`string`&&y.has(e)}var x=`previous delivery action was interrupted by restart`;function S(e,t){return e===`operation_interrupted`||typeof t==`string`&&t.toLowerCase().includes(x)}var C=e=>typeof e==`string`&&e.length>0?e:null,w=e=>typeof e==`string`&&e.length>0?e:null;function T(e){if(!e)return null;let t=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(e)?`${e.replace(` `,`T`)}Z`:e,n=Date.parse(t);return Number.isFinite(n)?n:null}function ee(e,t){let n=T(e),r=T(t);return n==null||r==null?null:r<n?-1:+(r>n)}function te(e){if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.ticketId!=`number`||!Number.isFinite(t.ticketId)||typeof t.branch!=`string`)return null;let n=typeof t.implementationOutcome==`string`&&g.has(t.implementationOutcome)?t.implementationOutcome:void 0,r=typeof t.deliveryOutcome==`string`&&_.has(t.deliveryOutcome)?t.deliveryOutcome:void 0;return{ticketId:t.ticketId,branch:t.branch,succeeded:t.succeeded===!0,...C(t.runId)?{runId:C(t.runId)}:{},...n?{implementationOutcome:n}:{},...r?{deliveryOutcome:r}:{},initialSha:w(t.initialSha),finalSha:w(t.finalSha),...typeof t.changed==`boolean`?{changed:t.changed}:{},failureCode:w(t.failureCode),...t.branchOwnership===`created`||t.branchOwnership===`preexisting`||t.branchOwnership===`borrowed-pr`?{branchOwnership:t.branchOwnership}:{},worktreePath:w(t.worktreePath)}}function E(e,t){if(!e||typeof e!=`object`)return null;let n=e,r=C(n.prDeliveryId)??C(n.id),i=typeof n.railIndex==`number`&&Number.isFinite(n.railIndex)?n.railIndex:t;if(!r||i==null||typeof n.decision!=`string`||!m.has(n.decision))return null;let a=typeof n.implementationOutcome==`string`&&g.has(n.implementationOutcome)?n.implementationOutcome:void 0,o=typeof n.deliveryOutcome==`string`&&_.has(n.deliveryOutcome)?n.deliveryOutcome:void 0,s=(Array.isArray(n.units)?n.units:Array.isArray(n.branches)?n.branches:[]).map(te).filter(e=>e!==null);return{prDeliveryId:r,railIndex:i,railKey:typeof n.railKey==`string`?n.railKey:``,ticketIds:Array.isArray(n.ticketIds)?n.ticketIds.filter(e=>typeof e==`number`&&Number.isFinite(e)):[],baseBranch:typeof n.baseBranch==`string`?n.baseBranch:``,branch:w(n.branch),prUrl:w(n.prUrl),prNumber:typeof n.prNumber==`number`&&Number.isInteger(n.prNumber)&&n.prNumber>0?n.prNumber:null,prState:typeof n.prState==`string`&&h.has(n.prState)?n.prState:`none`,decision:n.decision,runIds:Array.isArray(n.runIds)?n.runIds.filter(e=>typeof e==`string`&&e.length>0):s.map(e=>e.runId).filter(e=>typeof e==`string`&&e.length>0),originConversationId:w(n.originConversationId),createdAt:typeof n.createdAt==`string`?n.createdAt:void 0,updatedAt:typeof n.updatedAt==`string`?n.updatedAt:void 0,...a?{implementationOutcome:a}:{},...o?{deliveryOutcome:o}:{},statusCode:w(n.statusCode),statusDetail:w(n.statusDetail),deliverySha:w(n.deliverySha),isContinuation:n.isContinuation===!0,supersedesDeliveryId:w(n.supersedesDeliveryId),restoredFromDeliveryId:w(n.restoredFromDeliveryId),operation:typeof n.operation==`string`&&v.has(n.operation)?n.operation:null,cleanupWarnings:Array.isArray(n.cleanupWarnings)?n.cleanupWarnings.filter(e=>typeof e==`string`&&e.length>0):[],safetyArchives:Array.isArray(n.safetyArchives)?n.safetyArchives.filter(e=>typeof e==`string`&&e.length>0):[],units:s,executionManifest:n.executionManifest&&typeof n.executionManifest==`object`&&n.executionManifest.version===1?n.executionManifest:void 0,repositoryDeliveries:Array.isArray(n.repositoryDeliveries)?n.repositoryDeliveries.slice(0,100).flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e;if(typeof t.repositoryId!=`string`||typeof t.deliveryId!=`string`||typeof t.name!=`string`||typeof t.path!=`string`)return[];let n=E({...t,prDeliveryId:t.deliveryId,repositoryDeliveries:void 0},i);return n?[{repositoryId:t.repositoryId,deliveryId:t.deliveryId,name:t.name,path:t.path,baseBranch:n.baseBranch,...C(t.integrationBranch)?{integrationBranch:C(t.integrationBranch)}:{},branch:n.branch,deliverySha:n.deliverySha??null,decision:n.decision,implementationOutcome:n.implementationOutcome??`unknown`,deliveryOutcome:n.deliveryOutcome??`unknown`,statusCode:n.statusCode??null,statusDetail:n.statusDetail??null,prUrl:n.prUrl,prNumber:n.prNumber,runIds:n.runIds,worktreeIds:Array.isArray(t.worktreeIds)?t.worktreeIds.filter(e=>typeof e==`string`):[]}]:[]}):void 0}}function ne(e){let t=D(e);if(t.terminal||t.deliveryBlocked||t.implementationFailed||t.noChanges||e.decision===`building`||e.decision===`implementation_failed`)return null;if(e.branch||e.deliverySha)return e.branch&&/^[0-9a-f]{40,64}$/i.test(e.deliverySha??``)?e.branch:null;let n=e.units??[];if(n.length!==1)return null;let r=n[0];return!r.succeeded||r.implementationOutcome===`failed`||r.deliveryOutcome===`blocked`||r.deliveryOutcome===`no_changes`||r.changed===!1?null:r.branch&&/^[0-9a-f]{40,64}$/i.test(r.finalSha??``)?r.branch:null}function D(e){let t=e.units??[],n=t.length>0?t.filter(e=>e.implementationOutcome===`succeeded`||e.implementationOutcome==null&&e.succeeded).length:e.implementationOutcome===`failed`?0:e.ticketIds.length,r=t.length>0?t.filter(e=>e.implementationOutcome===`failed`||e.implementationOutcome==null&&!e.succeeded).length:e.implementationOutcome===`failed`?e.ticketIds.length:0,i=e.decision===`no_changes`||e.decision===`completed`||e.deliveryOutcome===`no_changes`||e.statusCode===`no_changes`,a=e.implementationOutcome===`partially_succeeded`||e.deliveryOutcome===`partial`||n>0&&r>0,o=t.length>0?t.filter(e=>e.deliveryOutcome===`ready`||e.deliveryOutcome===`delivered`||e.deliveryOutcome==null&&e.succeeded).length:a?0:n,s=a&&o===0,c=e.implementationOutcome===`failed`||e.implementationOutcome==null&&e.decision===`implementation_failed`,l=e.deliveryOutcome===`retryable_failure`,u=!c&&!l&&(s||e.deliveryOutcome===`blocked`||[`commit_failed`,`branch_verification_failed`,`settlement_interrupted`,`recovery_unavailable`,`status_failed`,`ref_mismatch`,`delivery_failed`].includes(e.statusCode??``)),d=e.isContinuation===!0,f=[...new Set((e.runIds??[]).filter(e=>typeof e==`string`&&e.length>0))],p=f.length===1?f[0]:null,m=p&&e.branch?t.filter(t=>t.runId===p&&t.branch===e.branch):[],h=[...new Set(m.map(e=>e.worktreePath).filter(e=>!!e))],g=(e.statusCode===`settlement_interrupted`||e.statusCode===`recovery_unavailable`)&&d?h:[...new Set(t.map(e=>e.worktreePath).filter(e=>!!e))],_=e.decision===`pr_failed`&&e.deliveryOutcome===`blocked`&&u&&d&&!!e.prUrl&&!!e.branch&&f.length===1&&m.length>0&&h.length<=1&&e.statusCode===`settlement_interrupted`&&(e.implementationOutcome===`succeeded`||e.implementationOutcome===`partially_succeeded`),v=e.decision===`pr_failed`&&e.deliveryOutcome===`blocked`&&u&&d&&e.statusCode===`recovery_unavailable`,y=v&&!!e.prUrl&&!!e.branch&&f.length===1&&m.length>0&&h.length<=1&&(e.implementationOutcome===`succeeded`||e.implementationOutcome===`partially_succeeded`),b=g.length>0||v&&!!e.deliverySha,x=!c&&l&&(e.statusCode===`push_failed`||d||!!e.prUrl),S=!c&&l&&!x,C=e.decision===`pr_closed`,w=e.decision===`superseded`;return{noChanges:i,partial:a,partialUndeliverable:s,implementationFailed:c,deliveryBlocked:u,retryablePush:x,retryablePrCreation:S,manualRecovery:_,recoveryUnavailable:v,recoveryRecheck:y,hasDiscardableRecoveryResult:b,continuation:d,localOnly:e.prState===`local-only`,closed:C,superseded:w,terminal:e.decision===`merged`||e.decision===`discarded`||e.decision===`completed`||w,succeededCount:n,deliverableCount:o,failedCount:r,totalCount:t.length>0?t.length:e.ticketIds.length,units:t,cleanupWarnings:e.cleanupWarnings??[],safetyArchives:e.safetyArchives??[],recoveryWorktreePaths:g}}var re=a(`send-horizontal`,[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]]),O=e(t(),1),ie=`"\\/bfnrtu`;function k(e){return e===` `||e===` `||e===`\r`||e===`
2
- `}function ae(e){let t=new Set,n=e.trim(),r=/^```[A-Za-z0-9_-]*[ \t]*\r?\n/.exec(n);r&&(n=n.slice(r[0].length),t.add(`nested_fence`));let i=/\r?\n[ \t]*```[ \t]*$/.exec(n);i&&(n=n.slice(0,i.index),t.add(`nested_fence`));let a=n.indexOf(`{`),o=n.lastIndexOf(`}`);a!==-1&&o>a&&(a>0||o<n.length-1)&&(n=n.slice(a,o+1),t.add(`trimmed_wrapper`));let s=``,c=!1;for(let e=0;e<n.length;e++){let r=n[e];if(c){if(r===`\\`){let i=n[e+1];if(i===void 0){t.add(`dangling_escape`);break}if(ie.includes(i)){s+=r+i,e+=1;continue}s+=i===`
3
- `?`\\n`:i,e+=1,t.add(`invalid_escape`);continue}if(r===`"`){let i=e+1;for(;i<n.length&&k(n[i]);)i+=1;let a=n[i];if(a===void 0||a===`,`||a===`}`||a===`]`||a===`:`){c=!1,s+=r;continue}s+=`\\"`,t.add(`inner_quote`);continue}if(r===`
4
- `){s+=`\\n`,t.add(`raw_newline`);continue}if(r===`\r`){t.add(`raw_newline`);continue}if(r===` `){s+=`\\t`,t.add(`raw_control`);continue}let i=r.charCodeAt(0);if(i<32){s+=`\\u`+i.toString(16).padStart(4,`0`),t.add(`raw_control`);continue}s+=r;continue}if(r===`"`){c=!0,s+=r;continue}if(r===`,`){let i=e+1;for(;i<n.length&&k(n[i]);)i+=1;if(n[i]===`}`||n[i]===`]`){t.add(`trailing_comma`);continue}s+=r;continue}if(r===`/`&&n[e+1]===`/`){let r=n.indexOf(`
5
- `,e);e=r===-1?n.length:r,t.add(`comment`);continue}if(r===`/`&&n[e+1]===`*`){let r=n.indexOf(`*/`,e+2);e=r===-1?n.length:r+1,t.add(`comment`);continue}s+=r}return{text:s,repairs:[...t]}}function oe(e,t){let n=e instanceof Error?e.message:String(e),r=/position (\d+)/i.exec(n),i=r?Number(r[1]):null,a=null;if(i!==null&&Number.isFinite(i)){let e=Math.max(0,i-40),n=Math.min(t.length,i+40);a=t.slice(e,n).replace(/\s+/g,` `)}return{error:n,position:i,excerpt:a}}function A(e){try{return{ok:!0,value:JSON.parse(e),repaired:!1,repairs:[]}}catch(t){let{text:n,repairs:r}=ae(e);try{return{ok:!0,value:JSON.parse(n),repaired:!0,repairs:r}}catch{return{ok:!1,...oe(t,e)}}}}var j=`specrails:git-changed`;function se(e){typeof window>`u`||window.dispatchEvent(new CustomEvent(j,{detail:{projectId:e}}))}function ce(e){if(typeof window>`u`)return()=>{};let t=t=>{let n=t.detail?.projectId;typeof n==`string`&&n&&e(n)};return window.addEventListener(j,t),()=>window.removeEventListener(j,t)}var M=/```blueprint-draft\s*\n([\s\S]*?)\n\s*```/g,N=/```blueprint-draft(?![\s\S]*?\n\s*```)/,P=/```(?:json|JSON)?[ \t]*\r?\n(?=[ \t]*\{)([\s\S]*?)\r?\n[ \t]*```(?=[ \t]*(?:\r?\n|$))/g,F=/```(?:json|JSON)?[ \t]*\r?\n[ \t]*\{(?=[\s\S]*"blueprintVersion")(?![\s\S]*?\n[ \t]*```)/,le=/```(?:blueprint-draft|spec-detail|spec-audit)(?![\s\S]*?\n\s*```)/,ue=new Set([`planned`,`committed`,`done`]),de=new Set([`scaffold`,`feature`,`verification`]),fe=new Set([`critical`,`high`,`medium`,`low`]);function I(e){return typeof e==`string`?e:``}function L(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function pe(e){let t=e&&typeof e==`object`&&!Array.isArray(e)?e:{};return{name:I(t.name),pitch:I(t.pitch),audience:I(t.audience)}}function me(e){let t=e&&typeof e==`object`&&!Array.isArray(e)?e:{},n={language:I(t.language),framework:I(t.framework),db:I(t.db)};return typeof t.notes==`string`&&t.notes!==``&&(n.notes=t.notes),n}function R(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(!n||typeof n!=`object`||Array.isArray(n))continue;let e=n,r=I(e.id),i=I(e.title);if(r===``&&i===``)continue;let a={id:r,title:i,goal:I(e.goal),status:ue.has(e.status)?e.status:`planned`,plannedSpecs:L(e.plannedSpecs)};if(Array.isArray(e.ticketIds)){let t=e.ticketIds.filter(e=>typeof e==`number`&&Number.isInteger(e));t.length>0&&(a.ticketIds=t)}t.push(a)}return t}function z(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(!n||typeof n!=`object`||Array.isArray(n))continue;let e=n,r=I(e.title);if(r===``)continue;let i={kind:de.has(e.kind)?e.kind:`feature`,title:r,shortSummary:I(e.shortSummary),description:I(e.description),acceptanceCriteria:L(e.acceptanceCriteria),priority:fe.has(e.priority)?e.priority:`medium`,labels:L(e.labels)};typeof e.dependsOnIndex==`number`&&Number.isInteger(e.dependsOnIndex)&&e.dependsOnIndex>=0&&(i.dependsOnIndex=e.dependsOnIndex),Array.isArray(e.repositoryIds)&&e.repositoryIds.length>0&&e.repositoryIds.every(e=>typeof e==`string`&&e.trim())&&new Set(e.repositoryIds).size===e.repositoryIds.length&&(i.repositoryIds=[...e.repositoryIds]),t.push(i)}return t}function B(e){if(!e||typeof e!=`object`||Array.isArray(e))return null;let t=e;return typeof t.blueprintVersion!=`number`||!Number.isInteger(t.blueprintVersion)?null:{blueprintVersion:t.blueprintVersion,product:pe(t.product),coreFlow:I(t.coreFlow),platform:I(t.platform),stack:me(t.stack),assumptions:L(t.assumptions),milestones:R(t.milestones),specsComplete:t.specsComplete===!0,m1Specs:z(t.m1Specs)}}var he=/^[ \t]*\r?\n?[ \t]*```[ \t]*(?=\r?\n|$)/;function V(e){let t=e.indexOf(`"m1Specs"`);return t===-1?0:(e.slice(t).match(/"title"\s*:/g)??[]).length}function ge(e){if(!e||!e.includes(`"blueprintVersion"`))return e??``;let t=e=>!e.includes("```")||!e.includes(`"blueprintVersion"`)?e:(P.lastIndex=0,e.replace(P,(e,t)=>{if(!t.includes(`"blueprintVersion"`))return e;let n=A(t);return!n.ok||!B(n.value)?e:"```blueprint-draft\n"+t+"\n```"})),n=``,r=0;M.lastIndex=0;let i;for(;(i=M.exec(e))!==null;)n+=t(e.slice(r,i.index))+i[0],r=i.index+i[0].length;return n+t(e.slice(r))}function _e(e){let t=ge(e??``);if(!t||!t.includes("```blueprint-draft")&&!F.test(t))return{stripped:t??``,blueprint:null,rawBlueprint:null,hadBlocks:!1,rejected:[],repaired:!1,truncated:!1};let n=null,r=null,i=!1,a=!1,o=[],s=``,c=0,l=0;M.lastIndex=0;let u;for(;(u=M.exec(t))!==null;){a=!0,s+=t.slice(c,u.index),c=u.index+u[0].length;let e=he.exec(t.slice(c));e&&(c+=e[0].length,M.lastIndex=c);let d=l;l+=1;let f=A(u[1]);if(!f.ok){let e=f.excerpt?` near: …${f.excerpt}…`:``;o.push({index:d,reason:`invalid_json`,detail:`${f.error}${e}`});continue}let p=B(f.value);if(!p){o.push({index:d,reason:`missing_version`,detail:`the payload is not a blueprint object with an integer blueprintVersion`});continue}n=p,r=f.value,i=f.repaired}let d=t.slice(c),f=N.exec(d)??F.exec(d),p=!1;if(f){a=!0,p=!0;let e=V(d.slice(f.index));o.push({index:l,reason:`truncated`,detail:e>0?`the block was cut off before its closing fence after ${e} spec title(s) had started`:`the block was cut off before its closing fence`}),s+=d.slice(0,f.index)}else s+=d;return{stripped:s,blueprint:n,rawBlueprint:r,hadBlocks:a,rejected:o,repaired:i,truncated:p}}function ve(e){if(!e)return{generating:!1,specsStarted:0};if(e.includes("```blueprint-draft")){let t=N.exec(e);if(t)return{generating:!0,specsStarted:V(e.slice(t.index))}}let t=F.exec(e);if(t)return{generating:!0,specsStarted:V(e.slice(t.index))};let n=/```spec-(?:detail|audit)(?![\s\S]*?\n\s*```)/.exec(e);return n?{generating:!0,specsStarted:(e.slice(n.index).match(/"title"\s*:/g)??[]).length}:{generating:!1,specsStarted:0}}function ye(e){if(!e)return``;let t=(/```(?:blueprint-draft|spec-detail|spec-audit)/.test(e)?le.exec(e):null)??F.exec(e);return t?e.slice(0,t.index):e}function be(e){return e?{product:e.product.name!==``&&e.product.pitch!==``,coreFlow:e.coreFlow!==``,platform:e.platform!==``,stack:e.stack.language!==``||e.stack.framework!==``,milestones:e.milestones.length>0}:{product:!1,coreFlow:!1,platform:!1,stack:!1,milestones:!1}}function xe(e){return`M${e}`}var Se=new Set([`planned`,`committed`,`running`,`delivered`,`done`]),Ce=new Set([`running`,`waiting`,`paused`,`awaiting_approval`,`completed`,`cancelled`]),H=(e,t=0)=>typeof e==`number`&&Number.isFinite(e)?e:t,U=e=>typeof e==`string`?e:null,W=e=>Array.isArray(e)?e.filter(e=>typeof e==`number`):[],we=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[];function Te(e){let t=e&&typeof e==`object`?e:{};return{total:H(t.total),done:H(t.done),onReview:H(t.onReview),inProgress:H(t.inProgress),todo:H(t.todo),failed:H(t.failed)}}function Ee(e){if(!e||typeof e!=`object`)return null;let t=e,n=U(t.id);return n?{id:n,railIndex:H(t.railIndex,-1),ticketIds:W(t.ticketIds),decision:U(t.decision)??`building`,branch:U(t.branch),baseBranch:U(t.baseBranch)??``,prUrl:U(t.prUrl),prNumber:typeof t.prNumber==`number`?t.prNumber:null,prState:U(t.prState)??`none`,createdAt:U(t.createdAt)}:null}function De(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.railIndex==`number`?{railIndex:t.railIndex,name:U(t.name),ticketIds:W(t.ticketIds),active:t.active===!0,runId:U(t.runId),startedAt:U(t.startedAt),delivery:Ee(t.delivery),chunkIndex:typeof t.chunkIndex==`number`?t.chunkIndex:null}:null}function G(e){if(!e||typeof e!=`object`)return null;let t=e,n=U(t.id),r=U(t.status);if(!n||!r||!Ce.has(r))return null;let i=Array.isArray(t.launched)?t.launched.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e;return typeof t.chunk!=`number`||typeof t.railIndex!=`number`?[]:[{chunk:t.chunk,railIndex:t.railIndex,ticketIds:W(t.ticketIds),runIds:we(t.runIds),deliveryId:U(t.deliveryId)}]}):[];return{id:n,milestoneN:H(t.milestoneN,0),mode:t.mode===`parallel`?`parallel`:`sequential`,status:r,pauseReason:U(t.pauseReason),autoAdvance:t.autoAdvance!==!1,nextChunk:H(t.nextChunk),totalChunks:H(t.totalChunks),currentRailIndex:typeof t.currentRailIndex==`number`?t.currentRailIndex:null,headBranch:U(t.headBranch),launched:i,updatedAt:U(t.updatedAt)??``}}function K(e){return Array.isArray(e)?e.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e,n=U(t.id);if(!n||typeof t.n!=`number`)return[];let r=U(t.state),i=U(t.storedStatus);return[{id:n,n:t.n,title:U(t.title)??``,storedStatus:i===`done`||i===`committed`?i:`planned`,state:r&&Se.has(r)?r:`planned`,counts:Te(t.counts),rails:Array.isArray(t.rails)?t.rails.flatMap(e=>{let t=De(e);return t?[t]:[]}):[],chain:G(t.chain)}]}):[]}function Oe(e){let t=Math.max(0,e.total);if(t===0)return[];let n=Math.min(e.failed,e.todo);return[[`done`,e.done],[`onReview`,e.onReview],[`inProgress`,e.inProgress],[`failed`,n],[`todo`,Math.max(0,e.todo-n)]].filter(([,e])=>e>0).map(([e,n])=>({key:e,count:n,pct:Math.round(n/t*1e3)/10}))}function ke(e){return e.done+e.onReview}function q(e){return e!==null&&(e.status===`running`||e.status===`waiting`)}function J(e){return e!==null&&e.status===`awaiting_approval`}function Y(e){return e.counts.todo>0&&!q(e.chain)&&e.chain?.status!==`paused`&&!J(e.chain)}function Ae(e){let t=new Set;for(let n of e){let e=n.chain;if(!e||e.mode!==`sequential`)continue;let r=[...e.launched].sort((e,t)=>e.chunk-t.chunk);for(let e=0;e<r.length-1;e++){let n=r[e].deliveryId;n&&t.add(n)}}return t}function je(e){if(!e)return{key:`unknown`,detail:``};let t=e.indexOf(`:`);return t<0?{key:e,detail:``}:{key:e.slice(0,t),detail:e.slice(t+1)}}var X=new Set([`on_review`,`no_changes`,`pr_draft`,`pr_ready`,`pr_failed`,`implementation_failed`,`pr_closed`]);function Me(e){let t=e.rails.map(e=>e.delivery).filter(e=>e!==null&&X.has(e.decision));return t.length===0?null:t.find(e=>e.decision===`on_review`)??t[0]}var Z=(0,O.createContext)(null);function Ne(){try{return r??Z}catch{return Z}}var Pe=Ne(),Fe=0;function Q(e){let t=(0,O.useContext)(Pe),{data:n,isLoading:r,refresh:i}=o({namespace:`milestone-progress`,projectId:e,initialValue:null,fetcher:async({projectId:e,signal:t})=>{let n=await fetch(`/api/projects/${e}/blueprint`,{cache:`no-store`,signal:t});if(n.status===404)return{blueprint:null,progress:[]};if(!n.ok)throw Error(`HTTP ${n.status}`);let r=await n.json();return{blueprint:B(r.blueprint),progress:K(r.progress)}}}),[a,s]=(0,O.useState)(null),c=(0,O.useRef)(e);(0,O.useEffect)(()=>{c.current=e,s(null)},[e]),(0,O.useEffect)(()=>{if(!t)return;let{registerHandler:e,unregisterHandler:n}=t,r=`milestone-progress:${++Fe}`;return e(r,e=>{let t=e;!t||t.type!==`blueprint.milestone_progress`||!t.projectId||t.projectId!==c.current||s({projectId:t.projectId,progress:K(t.progress)})}),()=>n(r)},[t]);let l=(0,O.useMemo)(()=>a&&a.projectId===e?a.progress:n?.progress??[],[a,e,n]),u=n===null?null:n.blueprint!==null,d=(0,O.useCallback)(async()=>{s(null),await i()},[i]);return{blueprint:n?.blueprint??null,progress:l,hasBlueprint:u,loading:r,refresh:d}}function Ie(e){let{progress:t}=Q(e);return(0,O.useMemo)(()=>Ae(t),[t])}var $=n();function Le({deliveryId:e,repositories:t,busy:n,onAct:r,onCheckout:a}){let{t:o}=i(`dashboard`),[m,h]=(0,O.useState)(null);if(!t?.length)return null;let g=m?.deliveryId===e?t.find(e=>e.repositoryId===m.repositoryId&&![`merged`,`completed`,`discarded`,`superseded`].includes(e.decision)):null;return(0,$.jsxs)(`div`,{className:`w-full space-y-2`,"data-testid":`repository-deliveries`,children:[t.map(t=>{let i=[`merged`,`completed`,`discarded`,`superseded`].includes(t.decision),s=t.deliveryOutcome===`blocked`,c=!!t.deliverySha&&!s&&t.implementationOutcome===`succeeded`,l=(i,a,o=!1)=>(0,$.jsx)(p,{size:`sm`,variant:`outline`,disabled:n,onClick:()=>{o?h({deliveryId:e,repositoryId:t.repositoryId,action:i}):r(i,t.repositoryId)},children:a});return(0,$.jsxs)(`section`,{className:`rounded-md border border-border/60 p-2 text-xs`,"aria-label":t.name,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`strong`,{children:t.name}),(0,$.jsxs)(`span`,{className:`font-mono text-muted-foreground`,children:[t.branch??`…`,` → `,t.integrationBranch??t.baseBranch]}),(0,$.jsx)(`span`,{className:`ml-auto text-muted-foreground`,children:o(`common:repositoryDelivery.${t.decision}`)})]}),(0,$.jsx)(`p`,{className:`mt-1 break-all text-muted-foreground`,children:t.path}),t.deliverySha&&(0,$.jsx)(`p`,{className:`font-mono text-muted-foreground`,children:t.deliverySha.slice(0,12)}),t.statusDetail&&(0,$.jsx)(`p`,{className:`mt-1 whitespace-pre-wrap text-muted-foreground`,children:t.statusDetail}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:[t.prUrl&&(0,$.jsxs)(`a`,{className:`underline`,href:t.prUrl,target:`_blank`,rel:`noreferrer`,children:[`PR #`,t.prNumber]}),!i&&(0,$.jsxs)($.Fragment,{children:[c&&!t.prUrl&&l(`create-pr`,o(`railPr.createPr`)),c&&t.prUrl&&t.deliveryOutcome===`retryable_failure`&&l(`create-pr`,o(`railPr.retryPush`)),c&&l(`merge-local`,o(`railPr.mergeLocal`),!0),c&&t.branch&&a&&(0,$.jsx)(p,{size:`sm`,variant:`outline`,disabled:n,onClick:()=>void a(t.repositoryId),children:o(`railPr.checkout`)}),t.prUrl&&t.decision===`pr_draft`&&l(`publish`,o(`railPr.publish`)),t.prUrl&&t.decision===`pr_closed`&&l(`reopen`,o(`railPr.reopen`)),t.prUrl&&l(`poll-merge`,o(`railPr.verifyPr`)),t.decision===`no_changes`&&l(`acknowledge-no-changes`,o(`railPr.markDone`),!0),s&&l(`recover-and-retry`,o(`railPr.retry`))]})]})]},t.repositoryId)}),(0,$.jsx)(f,{open:!!g,onOpenChange:e=>{e||h(null)},children:(0,$.jsxs)(d,{children:[(0,$.jsxs)(u,{children:[(0,$.jsx)(l,{children:o(m?.action===`merge-local`?`railPr.mergeLocalConfirmTitle`:`railPr.markDoneConfirmTitle`)}),(0,$.jsxs)(c,{children:[g?.name,` · `,o(m?.action===`merge-local`?`railPr.mergeLocalConfirmBody`:`railPr.markDoneConfirmBody`,{base:g?.integrationBranch??g?.baseBranch})]})]}),(0,$.jsxs)(s,{children:[(0,$.jsx)(p,{variant:`ghost`,onClick:()=>h(null),children:o(`common:actions.cancel`)}),(0,$.jsx)(p,{disabled:n||!g,onClick:()=>{let t=m;h(null),t&&t.deliveryId===e&&g&&r(t.action,t.repositoryId)},children:o(`common:actions.confirm`)})]})]})})]})}export{re as C,S as D,D as E,b as O,A as S,ee as T,be as _,J as a,se as b,G as c,Y as d,xe as f,ye as g,B as h,X as i,ne as k,K as l,Me as m,Q as n,q as o,Oe as p,Ie as r,je as s,Le as t,ke as u,ve as v,E as w,ce as x,_e as y};