specrails-desktop 2.62.0 → 2.63.1

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 (181) hide show
  1. package/cli/dist/specrails-desktop.js +39 -5
  2. package/client/dist/assets/{ActivityFeedPage-C_pqc281.js → ActivityFeedPage-B1bpTy7O.js} +1 -1
  3. package/client/dist/assets/{AgentBrowserCapture-vz6rbDtu.js → AgentBrowserCapture-BussBbN3.js} +1 -1
  4. package/client/dist/assets/AgentModeAnalyticsPane-BiT1n3BU.js +2 -0
  5. package/client/dist/assets/AgentModeCodePane-CUjNfeKa.js +2 -0
  6. package/client/dist/assets/{AgentModeJobsPane-99fBBLri.js → AgentModeJobsPane-RVEwyS59.js} +1 -1
  7. package/client/dist/assets/AgentsPage-DKE-eMC5.js +118 -0
  8. package/client/dist/assets/AnalyticsPage-Bser2Ly3.js +1 -0
  9. package/client/dist/assets/BarChart-BDMqVFJy.js +55 -0
  10. package/client/dist/assets/CodePage-BK0grm6e.js +3 -0
  11. package/client/dist/assets/DesktopAnalyticsPage-DEBidZbs.js +1 -0
  12. package/client/dist/assets/{DocsDialog-XUCYKoq0.js → DocsDialog-Dhyo57n9.js} +1 -1
  13. package/client/dist/assets/{DocsPage-dOLC8bXA.js → DocsPage-BcEkPXd6.js} +1 -1
  14. package/client/dist/assets/{ExportDropdown-BvKQgwM9.js → ExportDropdown-mRmqdkjr.js} +1 -1
  15. package/client/dist/assets/IntegrationsPage-EAipiDWm.js +1 -0
  16. package/client/dist/assets/InteractiveJobComposer-BlCe3vrU.js +19 -0
  17. package/client/dist/assets/{JobDetailModal-CkiubrkZ.js → JobDetailModal-CkAejD1F.js} +1 -1
  18. package/client/dist/assets/{JobDetailPage-CNe4Wn7l.js → JobDetailPage-P-FS_lKz.js} +1 -1
  19. package/client/dist/assets/JobsPage-CoUXgYse.js +1 -0
  20. package/client/dist/assets/LoopBuilderPage-iFylNk68.js +1 -0
  21. package/client/dist/assets/{LoopPreviewModal-Dv3dxHr_.js → LoopPreviewModal-4obS_Ptg.js} +1 -1
  22. package/client/dist/assets/{LoopWindowSurface-DN2lbSnL.js → LoopWindowSurface-CLr5OPqj.js} +1 -1
  23. package/client/dist/assets/LoopsPage-eKpWFtCp.js +2 -0
  24. package/client/dist/assets/MinimizedChatsContext-BHIUPVmC.js +1 -0
  25. package/client/dist/assets/PluginsPage-BgTC2CQx.js +2 -0
  26. package/client/dist/assets/ProjectSettingsDialog-B4chTfU8.js +1 -0
  27. package/client/dist/assets/RepositoryDeliveries-DAIxIYsl.js +5 -0
  28. package/client/dist/assets/{RepositoryScopeSelector-DrtPqvc_.js → RepositoryScopeSelector-DeCoUsRN.js} +1 -1
  29. package/client/dist/assets/ReviewPacketPage-Cktv0-9b.js +4 -0
  30. package/client/dist/assets/{TemplatePreviewModal-DcFlhUxy.js → TemplatePreviewModal-BZTV1TM1.js} +1 -1
  31. package/client/dist/assets/TicketDetailModalContext-DiPngt2g.js +16 -0
  32. package/client/dist/assets/Trans-ZiXIfj50.js +1 -0
  33. package/client/dist/assets/{agentRuntime-TKQyg137.js → agentRuntime-BDvbJMmS.js} +1 -1
  34. package/client/dist/assets/{agentRuntime-DvhEe1um.js → agentRuntime-BKJfv5YD.js} +1 -1
  35. package/client/dist/assets/{agentRuntime-DxC6-9rN.js → agentRuntime-BxF81z52.js} +1 -1
  36. package/client/dist/assets/{agentRuntime-C_yLPKDy.js → agentRuntime-BxYS5V7u.js} +1 -1
  37. package/client/dist/assets/{agentRuntime-WSv8G0pW.js → agentRuntime-BzuwQQgn.js} +1 -1
  38. package/client/dist/assets/{agentRuntime-D2kYQqNO.js → agentRuntime-Dc9HG3BA.js} +1 -1
  39. package/client/dist/assets/{agentRuntime-Bjt7Ij6_.js → agentRuntime-DiCldqGG.js} +1 -1
  40. package/client/dist/assets/{agentRuntime-B-myNBUP.js → agentRuntime-es2ymSl-.js} +1 -1
  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-DlQY1Lm_.js → formatDistanceToNow-CdN5lTyD.js} +1 -1
  52. package/client/dist/assets/{getTimezoneOffsetInMilliseconds-COUeq65G.js → getTimezoneOffsetInMilliseconds-62h40I4t.js} +1 -1
  53. package/client/dist/assets/git-branch-yf6LE1Bw.js +1 -0
  54. package/client/dist/assets/index-BgbCbIua.css +2 -0
  55. package/client/dist/assets/{index-CONHvEJw.js → index-CECj3joE.js} +40 -40
  56. package/client/dist/assets/jira-api-C_D_RDhl.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-Cc3oNv8X.js → project-repositories-Be0CWklo.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-BKJZ2KEM.js → settings-BO2N-oPf.js} +1 -1
  71. package/client/dist/assets/{settings-LfFnl1UH.js → settings-BQChAs_w.js} +1 -1
  72. package/client/dist/assets/{settings-BV3jocIx.js → settings-BzmYlcQB.js} +1 -1
  73. package/client/dist/assets/{settings-BjM2Dw8_.js → settings-CGjXb6TX.js} +1 -1
  74. package/client/dist/assets/{settings-DA77M48m.js → settings-CMxEWY46.js} +1 -1
  75. package/client/dist/assets/{settings-P1IQvhnL.js → settings-C_dRSgI2.js} +1 -1
  76. package/client/dist/assets/{settings-eIMJjyK_.js → settings-Hw7av-B1.js} +1 -1
  77. package/client/dist/assets/{settings-CKu0LTib.js → settings-nryN6wuS.js} +1 -1
  78. package/client/dist/assets/sparkles-CCfUdFGY.js +1 -0
  79. package/client/dist/assets/spending-eWiZGhC_.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-9Lwoel_8.js → useDesktop-C0mRIlHT.js} +1 -1
  85. package/client/dist/assets/{useRuntimeRuns-DL0xYoZ2.js → useRuntimeRuns-B1a6GChu.js} +1 -1
  86. package/client/dist/assets/useSharedWebSocket-CcsE5986.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 -45
  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/settings/5-project-environment.md +27 -0
  95. package/docs/guide/en/settings/5-project-environment.md +27 -0
  96. package/docs/guide/es/settings/5-project-environment.md +27 -0
  97. package/docs/guide/fr/settings/5-project-environment.md +27 -0
  98. package/docs/guide/it/settings/5-project-environment.md +27 -0
  99. package/docs/guide/ja/settings/5-project-environment.md +27 -0
  100. package/docs/guide/pt/settings/5-project-environment.md +27 -0
  101. package/docs/guide/zh/settings/5-project-environment.md +27 -0
  102. package/docs/internals/api-reference.md +3 -1
  103. package/docs/internals/configuration.md +46 -5
  104. package/docs/internals/core-runtime-updates.md +3 -3
  105. package/docs/internals/desktop-owned-workflows.md +10 -0
  106. package/docs/internals/programmatic-agent-runtime.md +16 -0
  107. package/docs/internals/safe-pr-review-flow.md +15 -0
  108. package/docs/internals/source-map.md +6 -1
  109. package/docs/mcp.md +1 -1
  110. package/docs/platforms/macos.md +2 -0
  111. package/docs/platforms/windows-parity.md +4 -4
  112. package/docs/platforms/windows.md +9 -9
  113. package/local-runner/dist/specrails-local-runner.js +1 -1
  114. package/package.json +8 -9
  115. package/server/dist/mcp/tools/env.js +38 -3
  116. package/server/dist/mcp/tools/loops.js +1 -1
  117. package/server/dist/modules/agent-runtime/runtime/agent-runtime-bridge.js +13 -3
  118. package/server/dist/modules/delivery/runtime/rail-isolated-launch.js +1 -1
  119. package/server/dist/modules/execution/runtime/queue-manager.js +8 -0
  120. package/server/dist/modules/loops/runtime/loop-executors.js +1 -0
  121. package/server/dist/modules/loops/runtime/loop-implement-recipe.js +13 -6
  122. package/server/dist/modules/loops/runtime/loop-run-manager.js +7 -0
  123. package/server/dist/modules/loops/runtime/loop-turn-limits.js +64 -0
  124. package/server/dist/modules/loops/runtime/loops-router.js +3 -1
  125. package/server/dist/modules/missions/runtime/agent-operator-prompt.js +8 -0
  126. package/server/dist/modules/project-settings/adapters/http.js +24 -0
  127. package/server/dist/path-resolver.js +135 -20
  128. package/server/dist/project-env.js +265 -17
  129. package/server/dist/project-registry.js +14 -0
  130. package/server/dist/project-router-settings.js +17 -0
  131. package/server/dist/schemas/agent-runtime.schema.json +1 -1
  132. package/server/dist/worktree-node-modules.js +95 -1
  133. package/client/dist/assets/AgentModeAnalyticsPane-BHCcUahS.js +0 -2
  134. package/client/dist/assets/AgentModeCodePane-DhmxgG3W.js +0 -2
  135. package/client/dist/assets/AgentsPage-CTwm_6T8.js +0 -118
  136. package/client/dist/assets/AnalyticsPage-YD8MLoPa.js +0 -1
  137. package/client/dist/assets/BarChart-nBOMNfiy.js +0 -33
  138. package/client/dist/assets/CodePage-CLJn2F2e.js +0 -3
  139. package/client/dist/assets/DesktopAnalyticsPage-MWGQVbwp.js +0 -1
  140. package/client/dist/assets/IntegrationsPage-Bhy58lnQ.js +0 -1
  141. package/client/dist/assets/InteractiveJobComposer-DxOvwmBF.js +0 -19
  142. package/client/dist/assets/JobsPage-DSts_L_d.js +0 -1
  143. package/client/dist/assets/LoopBuilderPage-C9D9eer5.js +0 -1
  144. package/client/dist/assets/LoopsPage-DHgIreEW.js +0 -2
  145. package/client/dist/assets/MinimizedChatsContext-Ds2-R6qJ.js +0 -1
  146. package/client/dist/assets/PluginsPage-D1EJ9oja.js +0 -2
  147. package/client/dist/assets/ProjectSettingsDialog-DKpa1wKk.js +0 -1
  148. package/client/dist/assets/RepositoryDeliveries-CW4eKG3x.js +0 -5
  149. package/client/dist/assets/ReviewPacketPage-BtjPI0Cc.js +0 -4
  150. package/client/dist/assets/TicketDetailModalContext-Dea22CI-.js +0 -16
  151. package/client/dist/assets/Trans-CAY2Rd2f.js +0 -1
  152. package/client/dist/assets/ban-E4EaZe3a.js +0 -1
  153. package/client/dist/assets/chevron-up-CwGUHd6D.js +0 -1
  154. package/client/dist/assets/chunk-KS7C4IRE-DEKu087k.js +0 -3
  155. package/client/dist/assets/circle-x-CMYsN4ZH.js +0 -1
  156. package/client/dist/assets/createLucideIcon-Bjbbp_KS.js +0 -1
  157. package/client/dist/assets/dist-Bq10nS2m.js +0 -1
  158. package/client/dist/assets/download-CFHyyHcw.js +0 -1
  159. package/client/dist/assets/external-link-D6XxC_Cu.js +0 -1
  160. package/client/dist/assets/file-text-BcLCfcWZ.js +0 -1
  161. package/client/dist/assets/git-branch-BRM0F5GN.js +0 -1
  162. package/client/dist/assets/index-BacrO_ub.css +0 -2
  163. package/client/dist/assets/jira-api-C94VNHNY.js +0 -1
  164. package/client/dist/assets/jsx-runtime-zu2_FqZY.js +0 -1
  165. package/client/dist/assets/layers-eDMjG41I.js +0 -1
  166. package/client/dist/assets/loader-circle-DcygOQpC.js +0 -1
  167. package/client/dist/assets/pencil-C9RkrIPZ.js +0 -1
  168. package/client/dist/assets/plus-CsnjfkmX.js +0 -1
  169. package/client/dist/assets/react-dom-DiWzBDP9.js +0 -1
  170. package/client/dist/assets/rotate-ccw-Wh4id13q.js +0 -1
  171. package/client/dist/assets/save-B6wGWwBR.js +0 -1
  172. package/client/dist/assets/search-Cq_gE3Ik.js +0 -1
  173. package/client/dist/assets/sparkles-DrY8hb0X.js +0 -1
  174. package/client/dist/assets/spending-DemeFfrH.js +0 -1
  175. package/client/dist/assets/square-Ci-PFcFe.js +0 -1
  176. package/client/dist/assets/trash-2-BOU3WdZZ.js +0 -1
  177. package/client/dist/assets/triangle-alert-H9T4jAmh.js +0 -1
  178. package/client/dist/assets/upload-DYMjAQ6M.js +0 -1
  179. package/client/dist/assets/useSharedWebSocket-BEHPeU1Y.js +0 -2
  180. package/client/dist/assets/x-CBMI9ejn.js +0 -1
  181. package/client/dist/assets/zap-CHo3aCD1.js +0 -1
@@ -0,0 +1 @@
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-BbYvbtY8.js";import{d as r,u as i}from"./chunk-OB3PAWPO-B1EMk45A.js";import{n as a,t as o}from"./createLucideIcon-DtODIU64.js";import{a as s,r as c,s as l}from"./useDesktop-C0mRIlHT.js";import{r as u}from"./provider-capabilities-lePfeT_Y.js";import{n as d,t as f}from"./save-LmPSfsvZ.js";import{t as p}from"./external-link-CZ6Q-v1-.js";import{t as m}from"./git-branch-yf6LE1Bw.js";import{n as h,t as g}from"./square-D0JTbRSR.js";import{t as _}from"./plus-fHDdjBk1.js";import{t as v}from"./rotate-ccw-DalJAQQX.js";import{t as y}from"./trash-D8zYUmTg.js";import{t as ee}from"./triangle-alert-Cxpn8bqr.js";import{t as te}from"./upload-CCHvUkRs.js";import{t as b}from"./x-Bu7X_eR2.js";import{a as ne,i as re,l as ie,o as ae,r as x,t as oe}from"./dialog-DtdR05v1.js";import{t as S}from"./utils-BC4DHlz2.js";import{t as C}from"./button-4FS1ZDTp.js";import{n as se,t as ce}from"./project-repositories-Be0CWklo.js";import{$t as w,Ht as le,It as T,J as ue,Kt as de,Rt as fe,St as pe,W as E,Wt as me,X as he,Xt as D,Y as ge,_t as _e,an as ve,at as O,c as ye,cn as be,d as k,f as A,it as xe,l as j,m as M,p as Se,q as Ce,sn as we,st as N,u as P,xt as Te}from"./index-CECj3joE.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-CyXj9223.js";var L={name:`grid-3x3`,size:24,node:[[`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`}]],aliases:[`grid`,`grid-3-x-3`]};L.node;var Re=o(L),ze={name:`move-horizontal`,size:24,node:[[`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`}]]};ze.node;var Be=o(ze),Ve={name:`move-vertical`,size:24,node:[[`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`}]]};Ve.node;var He=o(Ve),R=e(t(),1),z=n(),Ue=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function We({roles:e={},provider:t,supported:n,onChange:r,renderEngine:i,visibleRoleIds:o,manageRoles:s=!0}){let{t:c}=a(`agentRuntime`),[l,u]=(0,R.useState)(``),[d,f]=(0,R.useState)(!1),p=Object.entries(e).filter(([e])=>!A.includes(e)&&(!o||o.includes(e)));function m(){if(!ye.test(l)||l===`fixer`||A.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,z.jsxs)(`section`,{className:`space-y-3`,"aria-labelledby":`custom-runtime-roles`,children:[s&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h3`,{id:`custom-runtime-roles`,className:`text-sm font-medium`,children:c(`customRoles.title`)}),(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c(`customRoles.hint`)})]}),!n&&(0,z.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,z.jsxs)(`fieldset`,{className:`space-y-3 rounded-lg border p-3`,"aria-label":t,children:[(0,z.jsx)(`legend`,{className:`px-1 font-mono text-sm`,children:t}),s&&(0,z.jsx)(`div`,{className:`flex justify-end`,children:(0,z.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>{let n={...e};delete n[t],r(n)},children:c(`customRoles.remove`,{id:t})})}),(0,z.jsxs)(`fieldset`,{disabled:!n,className:`space-y-3`,children:[i(t),(0,z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,z.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[c(`customRoles.access`),(0,z.jsxs)(`select`,{className:Ue,value:a.access,onChange:e=>o({access:e.target.value}),children:[(0,z.jsx)(`option`,{value:`read`,children:c(`customRoles.read`)}),(0,z.jsx)(`option`,{value:`write`,children:c(`customRoles.write`)})]})]}),(0,z.jsxs)(`label`,{className:`space-y-1 text-xs`,children:[c(`customRoles.artifacts`),(0,z.jsxs)(`select`,{className:Ue,value:a.artifacts,onChange:e=>o({artifacts:e.target.value}),children:[(0,z.jsx)(`option`,{value:`none`,children:c(`customRoles.none`)}),(0,z.jsx)(`option`,{value:`tasks-checkboxes`,children:c(`customRoles.tasks`)}),(0,z.jsx)(`option`,{value:`all`,children:c(`customRoles.all`)})]})]})]}),(0,z.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[c(`customRoles.skill`),(0,z.jsxs)(`select`,{className:Ue,value:a.openspecSkill??``,onChange:e=>o({openspecSkill:e.target.value||void 0}),children:[(0,z.jsx)(`option`,{value:``,children:c(`customRoles.noSkill`)}),[`openspec-ff-change`,`openspec-apply-change`,`openspec-verify-change`].map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]})]}),(0,z.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[c(`customRoles.prompt`),(0,z.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,z.jsxs)(`fieldset`,{disabled:!n||!t,className:`flex items-end gap-2`,children:[(0,z.jsxs)(`label`,{className:`min-w-0 flex-1 space-y-1 text-xs`,children:[c(`customRoles.id`),(0,z.jsx)(E,{value:l,maxLength:64,placeholder:`security-reviewer`,onChange:e=>{u(e.target.value),f(!1)}})]}),(0,z.jsx)(C,{variant:`secondary`,onClick:m,children:c(`customRoles.add`)})]}),d&&(0,z.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:c(`customRoles.invalidId`)})]})}var Ge={architect:de,developer:fe,host:_e};function Ke({projectId:e,catalogUrl:t,guardrails:n,onChange:r}){let{t:i,i18n:o}=a(`agentRuntime`),[s,c]=(0,R.useState)(!0),[l,u]=(0,R.useState)({status:`loading`});(0,R.useEffect)(()=>{let n=!1;return u({status:`loading`}),fetch(t??`${se(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(!Se(i))throw Error(`guardrails`);n||u({status:`ready`,supported:i.supported,catalog:i.catalog})}).catch(()=>{n||u({status:`unsupported`})}),()=>{n=!0}},[e,t]);let d=l.status===`ready`?l.catalog:[],f=l.status===`ready`&&l.supported,p=d.filter(e=>n?.[e.id]===!1).length,m=d.length,h=e=>o.exists(`agentRuntime:guardrails.items.${e}.title`),g=`pipeline-guardrails-body`;return(0,z.jsxs)(`fieldset`,{id:`pipeline-guardrails`,"data-testid":`phase-card-guardrails`,className:`scroll-mt-4 rounded-lg border border-border transition-shadow`,children:[(0,z.jsx)(`legend`,{className:`sr-only`,children:i(`guardrails.title`)}),(0,z.jsxs)(`button`,{type:`button`,"aria-expanded":s,"aria-controls":g,"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,z.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,z.jsx)(Te,{className:`h-3.5 w-3.5`,"aria-hidden":!0})}),(0,z.jsx)(`span`,{className:`text-xs font-medium`,children:i(`guardrails.title`)}),(0,z.jsxs)(`span`,{className:`ml-auto flex items-center gap-2`,children:[l.status===`ready`&&f&&(0,z.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`,p?`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:m-p,total:m})}),(0,z.jsx)(D,{className:`h-3.5 w-3.5 text-muted-foreground transition-transform ${s?``:`-rotate-90`}`,"aria-hidden":!0})]})]}),(0,z.jsxs)(`div`,{id:g,hidden:!s,className:`space-y-3 px-3 pb-3`,children:[(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`guardrails.intro`)}),l.status===`loading`&&(0,z.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:i(`loading`)}),(l.status===`unsupported`||l.status===`ready`&&!f)&&(0,z.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,z.jsxs)(`fieldset`,{disabled:!f,className:`space-y-3 disabled:opacity-60`,children:[p>0&&(0,z.jsx)(`div`,{className:`flex justify-end`,children:(0,z.jsx)(`button`,{type:`button`,className:`text-[11px] text-accent-primary underline-offset-2 hover:underline`,onClick:()=>r(void 0),children:i(`guardrails.reset`)})}),j.map(e=>{let t=d.filter(t=>t.phase===e);if(!t.length)return null;let a=Ge[e];return(0,z.jsxs)(`div`,{className:`space-y-2`,"data-testid":`guardrails-phase-${e}`,children:[(0,z.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:[(0,z.jsx)(a,{className:`h-3.5 w-3.5`,"aria-hidden":!0}),i(`guardrails.phases.${e}`)]}),(0,z.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=h(e.id)?i(`guardrails.items.${e.id}.title`):e.id,o=h(e.id)?i(`guardrails.items.${e.id}.description`):i(`guardrails.unknown`),s=h(e.id)?i(`guardrails.items.${e.id}.why`):null,c=`guardrail-${e.id}-title`;return(0,z.jsxs)(`li`,{className:`flex items-start gap-3 px-3 py-2`,children:[(0,z.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t,"aria-labelledby":c,"data-testid":`guardrail-${e.id}`,onClick:()=>r(M(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,z.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,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`p`,{id:c,className:S(`text-xs font-medium`,!t&&`text-muted-foreground line-through decoration-muted-foreground/50`),children:a}),(0,z.jsx)(`p`,{className:`mt-0.5 text-[11px] leading-4 text-muted-foreground`,children:o}),s&&(0,z.jsx)(`p`,{className:`mt-0.5 text-[10px] italic leading-4 text-muted-foreground/70`,children:s})]})]},e.id)})})]},e)})]})]})]})}var qe=`h-9 w-full rounded-md border border-input bg-background px-2 text-sm`;function Je({config:e,onChange:t}){let{t:n}=a(`agentRuntime`),r=e.efficiency??{schemaVersion:1};return(0,z.jsxs)(`section`,{className:`space-y-3`,"aria-label":n(`efficiency.title`),children:[(0,z.jsx)(`h3`,{className:`text-sm font-medium`,children:n(`efficiency.title`)}),(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`efficiency.scope`)}),(0,z.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[`contextMode`,`reviewMode`,`planning`].map(i=>(0,z.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`efficiency.${i}`),(0,z.jsxs)(`select`,{className:qe,value:r[i]??(i===`planning`?`proportional`:`incremental`),onChange:n=>t({...e,efficiency:{...r,[i]:n.target.value}}),children:[(0,z.jsx)(`option`,{value:i===`planning`?`proportional`:`incremental`,children:n(`efficiency.adaptive`)}),(0,z.jsx)(`option`,{value:`full`,children:n(`efficiency.full`)})]})]},i))}),(0,z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:r.acceptDeveloperChecks!==!1,onChange:n=>t({...e,efficiency:{...r,acceptDeveloperChecks:n.target.checked}})}),n(`efficiency.developerChecks`)]}),(0,z.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[n(`efficiency.concurrency`),(0,z.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,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`efficiency.concurrencyHint`)})]})}function Ye(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=B(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 B=e=>typeof e==`object`&&e&&!Array.isArray(e)?e:{};function V(e){return typeof e.type==`string`?e.type:e.properties||e.additionalProperties?`object`:e.items?`array`:`string`}function H(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 H(B(t[0]));switch(V(e)){case`boolean`:return!1;case`number`:case`integer`:return typeof e.minimum==`number`?e.minimum:0;case`array`:return[];case`object`:{let t=B(e.properties);return Object.fromEntries((Array.isArray(e.required)?e.required:[]).filter(e=>typeof e==`string`).map(e=>[e,H(B(t[e]))]))}default:return``}}function Xe(e){let t=B(H(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 Ze(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 Qe=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 $e(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 U(e){let t=new Set,n=new Set;function r(i){for(let a of i.nodes){if(a.type!==`core`)continue;let i=B(a.data?.params),o=a.data?.kind;$e(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=[`architect`,`developer`,`reviewer`];function G(e,t){return t===`fixer`?e.fixer??e.agents.developer:W.includes(t)?e.agents[t]:e.roles?.[t]}function et(e,t,n){return t===`fixer`?{...e,fixer:n}:W.includes(t)?{...e,agents:{...e.agents,[t]:n}}:{...e,roles:{...e.roles,[t]:{...e.roles[t],...n}}}}function tt(e){let t=new Map,n=e=>{for(let n of e.nodes){if(n.type!==`core`)continue;let e=n.data?.params&&typeof n.data.params==`object`?n.data.params:{},r=typeof n.data?.label==`string`&&n.data.label?n.data.label:n.id;for(let i of $e(n.id,n.data?.kind,e))t.set(i,[...t.get(i)??[],r])}};n(e);for(let t of Object.values(e.components??{}))n(t);return t}function nt({graph:e,value:t,onChange:n}){let{t:r}=a(`agentRuntime`),i=[...tt(e)].filter(([e])=>G(t,e));return i.length?(0,z.jsxs)(`details`,{open:!0,className:`rounded-md border border-border p-2`,"aria-label":r(`loopAgents.turnLimits.title`),children:[(0,z.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium`,children:r(`loopAgents.turnLimits.title`)}),(0,z.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:r(`loopAgents.turnLimits.hint`,{turns:100})}),(0,z.jsx)(`div`,{className:`mt-3 space-y-2`,children:i.map(([e,i])=>{let a=G(t,e);return(0,z.jsxs)(`label`,{className:`grid grid-cols-[1fr_6rem] items-center gap-2 text-xs`,children:[(0,z.jsxs)(`span`,{className:`min-w-0`,children:[(0,z.jsx)(`span`,{className:`block truncate font-medium text-foreground`,children:i.join(` · `)}),(0,z.jsx)(`span`,{className:`block truncate text-muted-foreground`,children:r(`loopAgents.turnLimits.role`,{role:e})})]}),(0,z.jsx)(E,{type:`number`,min:1,inputMode:`numeric`,"aria-label":r(`loopAgents.turnLimits.input`,{steps:i.join(`, `),role:e}),placeholder:`100`,value:a.maxTurns??``,onChange:r=>n(et(t,e,{...a,maxTurns:r.target.value?Math.max(1,Math.floor(Number(r.target.value))):void 0}))})]},e)})})]}):null}var K=`w-full rounded-md border border-input bg-background px-2 py-1 text-xs`,q=[`architect`,`developer`,`reviewer`,`fixer`];function rt({value:e,onChange:t,selectedRole:n,graph:r,mode:i=`all`}){let{t:o}=a(`agentRuntime`),{activeProjectId:l}=c(),d=(0,R.useRef)(l);d.current=l;let[f,p]=(0,R.useState)([]),[m,h]=(0,R.useState)({}),[g,_]=(0,R.useState)(),[v,y]=(0,R.useState)(null),[ee,te]=(0,R.useState)(``),[b,ne]=(0,R.useState)(!1),[re,ie]=(0,R.useState)(!1),ae=r?U(r):[...q,...Object.keys(e?.roles??{})],x=i===`step`?[n??``]:re?void 0:ae,oe=i!==`workflow`,S=i!==`step`,se=i===`step`?`loopAgents.stepTitle`:i===`workflow`?`loopAgents.policy`:`loopAgents.title`,ce=[...q,...Object.keys(e?.roles??{})].some(e=>!ae.includes(e));(0,R.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),y(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 w(){let e=l;ne(!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:y,guardrails:ee}=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])=>q.includes(e))),limits:m,review:h,architect:_,approvalBeforeArchive:v,efficiency:y,guardrails:ee})}catch{te(o(`loadFailed`))}finally{ne(!1)}}function le(n){if(!e)return null;let r=G(e,n);if(!r)return null;let i=r=>t(et(e,n,r)),a=f.find(e=>e.id===r.provider),s=a?.kind===`cli`?N(a.cli).map(e=>e.value):m[r.provider]??[];return(0,z.jsxs)(`div`,{className:`space-y-2`,children:[(0,z.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.provider`),(0,z.jsxs)(`select`,{className:K,value:r.provider,onChange:e=>i({provider:e.target.value,maxTurns:r.maxTurns}),children:[(0,z.jsx)(`option`,{value:`inherit`,children:o(`loopAgents.inheritProvider`)}),!a&&r.provider!==`inherit`&&u(r.provider)&&(0,z.jsx)(`option`,{value:r.provider,children:r.provider}),f.filter(e=>u(e.kind===`cli`?e.cli:e.id)).map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.kind===`openai-compatible`?e.label??e.id:e.id},e.id))]})]}),(0,z.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.model`),(0,z.jsx)(E,{value:r.model??``,list:`loop-models-${n}`,onChange:e=>i({...r,model:e.target.value||void 0})}),(0,z.jsx)(`datalist`,{id:`loop-models-${n}`,children:s.map(e=>(0,z.jsx)(`option`,{value:e},e))})]}),(0,z.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.effort`),(0,z.jsx)(E,{value:r.effort??``,onChange:e=>i({...r,effort:e.target.value||void 0})})]}),(0,z.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.maxTurns`,{turns:100}),(0,z.jsx)(E,{type:`number`,min:1,placeholder:`100`,value:r.maxTurns??``,onChange:e=>i({...r,maxTurns:e.target.value?Math.max(1,Math.floor(Number(e.target.value))):void 0})}),(0,z.jsx)(`span`,{className:`mt-1 block text-muted-foreground`,children:o(`loopAgents.turnLimits.stepHint`,{role:n,turns:r.maxTurns??100})})]}),(0,z.jsxs)(`label`,{className:`block text-xs`,children:[o(`agents.thinking`),(0,z.jsxs)(`select`,{className:K,value:r.thinking??``,onChange:e=>i({...r,thinking:e.target.value?e.target.value:void 0}),children:[(0,z.jsx)(`option`,{value:``,children:o(`loopAgents.default`)}),(0,z.jsx)(`option`,{value:`off`,children:o(`agents.thinking_off`)}),(0,z.jsx)(`option`,{value:`on`,children:o(`agents.thinking_on`)})]})]}),(0,z.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.escalationModel`),(0,z.jsx)(E,{value:r.escalation?.model??``,onChange:e=>i({...r,escalation:e.target.value?{...r.escalation,model:e.target.value}:void 0})})]}),r.escalation&&(0,z.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.escalationEffort`),(0,z.jsx)(E,{value:r.escalation.effort??``,onChange:e=>i({...r,escalation:{model:r.escalation.model,effort:e.target.value||void 0}})})]})]})}let T=e?{...e,enabled:!0,providers:f,verification:[]}:void 0;return(0,z.jsxs)(`section`,{className:`space-y-3 border-b border-border pb-4`,"aria-label":o(se),children:[(0,z.jsx)(`h3`,{className:`text-sm font-medium`,children:o(se)}),oe&&(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(i===`step`?`loopAgents.stepHint`:`loopAgents.hint`)}),ee&&(0,z.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:ee}),i===`workflow`&&e&&r&&(0,z.jsx)(nt,{graph:r,value:e,onChange:t}),!e&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`p`,{className:`text-xs text-accent-warning`,children:o(`loopAgents.legacy`)}),(0,z.jsx)(C,{size:`sm`,disabled:!g,onClick:()=>g&&t(structuredClone(g)),children:o(`loopAgents.enable`)})]}),i!==`step`&&(0,z.jsx)(C,{size:`sm`,variant:`secondary`,disabled:!l||!g||b,onClick:()=>void w(),children:o(`loopAgents.import`)}),e&&(0,z.jsxs)(z.Fragment,{children:[i===`all`&&ce&&(0,z.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:re,onChange:e=>ie(e.target.checked)}),o(`loopAgents.showUnused`)]}),oe&&q.filter(e=>!x||x.includes(e)).map(r=>(0,z.jsxs)(`details`,{open:n===r,className:`rounded-md border border-border p-2`,children:[(0,z.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium`,children:r}),(0,z.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[le(r),e.rolePrompts?.[r]===`inherit`?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`loopAgents.inheritDefinition`)}),(0,z.jsx)(`textarea`,{readOnly:!0,"aria-label":o(`customRoles.prompt`),className:`${K} opacity-80`,rows:8,value:v?.[r]??o(`loopAgents.coreDefinitionUnavailable`)}),(0,z.jsx)(C,{size:`sm`,variant:`ghost`,disabled:!v?.[r],onClick:()=>t({...e,rolePrompts:{...e.rolePrompts,[r]:v?.[r]??``}}),children:o(`loopAgents.customizeDefinition`)})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`label`,{className:`block text-xs`,children:[o(`customRoles.prompt`),(0,z.jsx)(`textarea`,{className:K,rows:10,maxLength:2e4,value:e.rolePrompts?.[r]??``,onChange:n=>t({...e,rolePrompts:{...e.rolePrompts,[r]:n.target.value}})})]}),(0,z.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>t({...e,rolePrompts:{...e.rolePrompts,[r]:`inherit`}}),children:o(`loopAgents.restoreDefinition`)})]})]})]},r)),i===`step`&&n&&![...q,`archive`,`verify`].includes(n)&&!e.roles?.[n]&&(0,z.jsx)(C,{size:`sm`,disabled:!f.length,onClick:()=>t({...e,roles:{...e.roles,[n]:{provider:`inherit`,access:`read`,artifacts:`none`}}}),children:o(`customRoles.add`)}),(oe||i===`workflow`)&&(0,z.jsx)(We,{manageRoles:i!==`step`,visibleRoleIds:i===`workflow`?[]:x,roles:e.roles,provider:`inherit`,supported:!0,onChange:n=>{Object.keys(n).some(t=>!e.roles?.[t])&&ie(!0),t({...e,roles:n,rolePrompts:Object.fromEntries(Object.entries(e.rolePrompts??{}).filter(([e])=>q.includes(e)))})},renderEngine:le}),(0,z.jsxs)(`div`,{className:`space-y-3`,children:[S&&(0,z.jsxs)(`details`,{className:`rounded-md border border-border p-2`,children:[(0,z.jsx)(`summary`,{className:`cursor-pointer text-sm`,children:o(`loopAgents.policy`)}),(0,z.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[[`maxAttempts`,`maxTokens`,`maxCostUsd`,`timeoutMs`].map(n=>(0,z.jsxs)(`label`,{className:`block text-xs`,children:[o(`loopAgents.${n}`),(0,z.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,z.jsx)(Ke,{catalogUrl:`/api/loop-agent-defaults`,guardrails:e.guardrails,onChange:n=>t({...e,guardrails:n})}),T&&(0,z.jsx)(Je,{config:T,onChange:n=>t({...e,efficiency:n.efficiency})})]})]}),(i===`all`||i===`step`&&n===`reviewer`)&&(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`label`,{className:`block text-xs`,children:[o(`review.minScore`,{score:70}),(0,z.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}})})]}),P.map(n=>(0,z.jsxs)(`label`,{className:`block text-xs`,children:[o(`review.aspects.${n}`,{score:k.aspects[n]}),(0,z.jsx)(E,{type:`number`,min:k.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,z.jsxs)(`label`,{className:`block text-xs`,children:[o(`architect.onLowConfidence`),(0,z.jsxs)(`select`,{className:K,value:e.architect?.onLowConfidence??`ask`,onChange:n=>t({...e,architect:{onLowConfidence:n.target.value}}),children:[(0,z.jsx)(`option`,{value:`ask`,children:o(`architect.ask`)}),(0,z.jsx)(`option`,{value:`proceed`,children:o(`architect.proceed`)})]})]}),(i===`all`||i===`step`&&n===`archive`)&&(0,z.jsxs)(`label`,{className:`flex gap-2 text-xs`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:e.approvalBeforeArchive??!1,onChange:n=>t({...e,approvalBeforeArchive:n.target.checked})}),o(`approvalBeforeArchive`)]})]})]})]})}var J=`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 Y({schema:e,value:t,onChange:n,path:r=`params`,choices:i={},depth:o=0}){let{t:s}=a(`loops`),c=(0,R.useId)(),[l,u]=(0,R.useState)(``);if(o>24)return(0,z.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,z.jsx)(Y,{schema:n,value:a,onChange:s,path:`${r}.${e}`,choices:{...i,selectedProvider:typeof B(t).provider==`string`?String(B(t).provider):i.selectedProvider},depth:o+1},e),p=e.oneOf??e.anyOf;if(Array.isArray(p)&&!e.properties){let e=p.map(B),r=Math.max(0,e.findIndex(e=>`const`in e?t===e.const:Array.isArray(e.enum)?e.enum.includes(t):V(e)===(Array.isArray(t)?`array`:typeof t)));return(0,z.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,z.jsx)(`legend`,{className:`text-xs font-medium`,children:d}),(0,z.jsx)(`label`,{className:`sr-only`,htmlFor:c,children:s(`builder.core.variant`,{name:d})}),(0,z.jsx)(`select`,{id:c,className:J,value:r,onChange:t=>n(H(e[Number(t.target.value)])),children:e.map((e,t)=>(0,z.jsx)(`option`,{value:t,children:String(e.title??e.const??(Array.isArray(e.enum)?e.enum.join(` / `):V(e)))},t))}),f(`value`,e[r],t,n)]})}if(`const`in e)return(0,z.jsxs)(`p`,{className:`text-xs`,children:[(0,z.jsxs)(`span`,{className:`text-muted-foreground`,children:[d,`: `]}),String(e.const)]});if(Array.isArray(e.enum))return(0,z.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,(0,z.jsxs)(`select`,{className:J,value:JSON.stringify(t),onChange:e=>n(JSON.parse(e.target.value)),children:[!e.enum.includes(t)&&(0,z.jsx)(`option`,{value:JSON.stringify(t)??``,children:s(`builder.core.select`)}),e.enum.map((e,t)=>(0,z.jsx)(`option`,{value:JSON.stringify(e),children:String(e)},t))]})]});let m=V(e);if(m===`object`){let r=B(t),i=B(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=>B(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:H(B(i[t]??e.additionalProperties)),enumerable:!0,configurable:!0,writable:!0}),n(a)};return(0,z.jsxs)(`fieldset`,{className:`space-y-2 min-w-0`,children:[(0,z.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,z.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,z.jsx)(_,{className:`h-3 w-3`}),t]},t):(0,z.jsxs)(`div`,{className:`relative border-l border-border pl-2 space-y-1`,children:[!o&&(0,z.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,z.jsx)(b,{className:`h-3.5 w-3.5`})}),f(t,B(i[t]??e.additionalProperties),r[t],e=>c(t,e))]},t)}),e.additionalProperties!==!1&&(0,z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,z.jsx)(`input`,{className:J,value:l,placeholder:s(`builder.core.fieldName`),"aria-label":s(`builder.core.fieldName`),onChange:e=>u(e.target.value)}),(0,z.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,z.jsx)(_,{className:`h-4 w-4`})})]})]})}if(m===`array`){let r=Array.isArray(t)?t:[],i=B(e.items);return(0,z.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,z.jsx)(`legend`,{className:`text-xs font-semibold`,children:d}),r.map((e,t)=>(0,z.jsxs)(`div`,{className:`border-l border-border pl-2`,children:[(0,z.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,z.jsx)(b,{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,z.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,H(i)]),children:[(0,z.jsx)(_,{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,z.jsxs)(`div`,{className:`space-y-1`,children:[(0,z.jsxs)(`label`,{className:`text-xs`,children:[s(`builder.core.valueType`),(0,z.jsx)(`select`,{className:J,value:r,onChange:e=>n(e.target.value===`null`?null:H({type:e.target.value})),children:[`string`,`number`,`boolean`,`object`,`array`,`null`].map(e=>(0,z.jsx)(`option`,{children:e},e))})]}),r===`null`?(0,z.jsx)(`span`,{className:`text-xs`,children:`null`}):f(`value`,{type:r},t,n)]})}if(m===`boolean`)return(0,z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,z.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,z.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,(0,z.jsx)(`input`,{type:`number`,className:J,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,v=[`text`,`prompt`,`question`,`message`,`goal`,`expr`,`commandLine`,`reason`].includes(d);return(0,z.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,h?.length&&d!==`roleId`?(0,z.jsxs)(`select`,{className:J,value:typeof t==`string`?t:``,onChange:e=>n(e.target.value),children:[(0,z.jsx)(`option`,{value:``,children:s(`builder.core.select`)}),t&&!h.includes(String(t))?(0,z.jsx)(`option`,{value:String(t),children:String(t)}):null,h.map(e=>(0,z.jsx)(`option`,{children:e},e))]}):v?(0,z.jsx)(`textarea`,{className:`${J} 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,z.jsx)(`input`,{list:g?.length||d===`roleId`&&h?.length?c:void 0,className:J,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,z.jsx)(`datalist`,{id:c,children:(g??h??[]).map(e=>(0,z.jsx)(`option`,{value:e},e))}):null,typeof e.description==`string`&&(0,z.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.description})]})}var it=`w-full min-w-0 rounded border border-border bg-background px-2 py-1 text-xs`,at=[`journal`,`change`,`maxTokens`,`maxTransitions`,`policies`];function ot({graph:e,canvas:t,schema:n,onChange:r,onOpenCanvas:i}){let{t:o}=a(`loops`),[s,c]=(0,R.useState)(``),l=B(n.properties),u={type:`object`,additionalProperties:!1,properties:{...Object.fromEntries(at.filter(e=>l[e]).map(e=>[e,l[e]])),...B(B(l.budget).properties).maxTokens?{maxTokens:B(B(l.budget).properties).maxTokens}:{}}},d=Object.fromEntries(Object.entries(e.config).filter(([e])=>at.includes(e))),f=t?e.components?.[t]:void 0,p=t?[]:Ye(e);return(0,z.jsxs)(z.Fragment,{children:[!t&&(0,z.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[(0,z.jsx)(`span`,{children:o(`builder.core.reviewerStep`)}),(0,z.jsxs)(`select`,{className:it,value:e.config.reviewerStepId??``,onChange:t=>r({...e,config:{...e.config,reviewerStepId:t.target.value||void 0}}),children:[(0,z.jsx)(`option`,{value:``,children:o(`builder.core.reviewerAutomatic`)}),e.config.reviewerStepId&&!p.includes(e.config.reviewerStepId)&&(0,z.jsx)(`option`,{value:e.config.reviewerStepId,children:e.config.reviewerStepId}),p.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]}),(0,z.jsx)(`span`,{className:`block text-muted-foreground`,children:o(`builder.core.reviewerHint`)})]}),(0,z.jsx)(Y,{schema:u,value:d,path:o(`builder.core.options`),onChange:t=>{let n=Object.fromEntries(Object.entries(e.config).filter(([e])=>!at.includes(e)));r({...e,config:{...n,...t}})}}),(0,z.jsxs)(`section`,{className:`space-y-2`,children:[(0,z.jsx)(`p`,{className:`text-xs font-semibold`,children:o(`builder.core.components`)}),(0,z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(e.components??{}).map(e=>(0,z.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,z.jsxs)(`div`,{className:`flex gap-1`,children:[(0,z.jsx)(`input`,{className:it,value:s,"aria-label":o(`builder.core.componentName`),placeholder:o(`builder.core.componentName`),onChange:e=>c(e.target.value)}),(0,z.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,z.jsx)(_,{className:`w-4 h-4`})})]}),f&&t&&(0,z.jsx)(Y,{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 st({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=B(B(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(B(f.properties)).map(([e,t])=>[e,p[e]?{...B(t),title:p[e]}:t]))}:f;return(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,z.jsx)(`h3`,{className:`text-sm font-semibold`,children:l(`builder.core.pieces.${t.coreKind}`)}),(0,z.jsx)(`button`,{type:`button`,onClick:s,"aria-label":l(`common:actions.delete`),className:`text-muted-foreground hover:text-destructive`,children:(0,z.jsx)(y,{className:`h-4 w-4`})})]}),(0,z.jsxs)(`label`,{className:`block text-xs`,children:[l(`builder.inspector.label`),(0,z.jsx)(`input`,{className:it,value:String(t.label??``),onChange:e=>o({label:e.target.value})})]}),[`implementation`,`implementation-step`].includes(t.coreKind??``)&&(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`builder.core.legacyImplementation`)}),n?(0,z.jsx)(Y,{schema:m,value:t.params??{},onChange:e=>o({params:e}),choices:r},e):(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`builder.core.unavailable`)}),[`component`,`map`].includes(t.coreKind)&&typeof u==`string`&&(0,z.jsx)(`button`,{type:`button`,className:`text-xs text-accent-primary`,onClick:()=>c(u),children:l(`builder.core.openComponent`)}),Object.keys(d).length>0&&(0,z.jsx)(Y,{schema:d,value:t.retry??{},path:`retry`,onChange:e=>o({retry:e})})]})}function ct(e){return e===`continue`||e===`stop`?e:void 0}function X(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 lt(){return globalThis.crypto?.randomUUID?.()??`n-${Date.now()}-${Math.floor(Math.random()*1e9)}`}function ut(e,t){return{id:lt(),type:`loop`,position:t,data:X(e)}}function dt(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 ft(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=ct(t.sourceHandle)??ct(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 pt=`specrailsNodes`;function mt(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 ht(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}let n=t;return!n||n[pt]==null||!Array.isArray(n.nodes)?null:{nodes:n.nodes,edges:Array.isArray(n.edges)?n.edges:[]}}function gt(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 _t(e){return typeof e!=`string`||e.trim().length===0}function vt(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 yt(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=vt(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}),_t(t.data.goal)&&n.push({severity:`warning`,code:`EMPTY_GOAL`,nodeId:t.id});break}case`ai-step`:_t(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`:_t(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 bt(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 xt=(0,R.createContext)(new Map),St=(0,R.createContext)({pieces:[]}),Ct=[`start`,`ai-step`,`shell`,`decider`,`end`],wt={core:w,start:h,"ai-step":w,shell:_e,decider:m,condition:m,end:le},Tt={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 Et({id:e,data:t,selected:n}){let{t:r}=a(`loops`),i=t.kind,o=wt[i]??g,s=String(t.label??``).trim(),c=(0,R.useContext)(xt).get(e),l=(0,R.useContext)(St),u=Ze(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,z.jsxs)(`div`,{className:S(`rounded-md border-2 bg-card px-3 py-2 min-w-[140px] shadow-sm`,Tt[i],c===`error`?`ring-2 ring-destructive`:n?`ring-2 ring-accent-primary`:c===`warning`?`ring-2 ring-accent-warning`:``),children:[i!==`start`&&(0,z.jsx)(F,{type:`target`,position:I.Top}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,z.jsx)(o,{className:`w-3.5 h-3.5 text-foreground flex-shrink-0`}),(0,z.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,z.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,z.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-1 truncate max-w-[160px]`,children:d}),i===`core`?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`flex justify-around gap-2 mt-2 text-[9px] text-accent-primary`,children:u.map(e=>(0,z.jsx)(`span`,{children:e},e))}),u.map((e,t)=>(0,z.jsx)(F,{id:e,type:`source`,position:I.Bottom,style:{left:`${(t+1)*100/(u.length+1)}%`},"aria-label":e},e))]}):i===`decider`?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between gap-2 text-[9px] font-medium`,children:[(0,z.jsx)(`span`,{className:`text-accent-highlight`,children:r(`builder.branch.continue`)}),(0,z.jsx)(`span`,{className:`text-accent-success`,children:r(`builder.branch.stop`)})]}),(0,z.jsx)(F,{id:`continue`,type:`source`,position:I.Bottom,style:{left:`30%`},className:`!bg-accent-highlight`}),(0,z.jsx)(F,{id:`stop`,type:`source`,position:I.Bottom,style:{left:`70%`},className:`!bg-accent-success`})]}):i===`end`?null:(0,z.jsx)(F,{type:`source`,position:I.Bottom})]})}function Dt({loopId:e,onExit:t,onWindowOpened:n}){let{t:o}=a(`loops`),u=i(),{id:m}=r(),h=e??m,g=(0,R.useCallback)(()=>{t?t():u(`/loops`)},[t,u]),y=ve(),{fitView:b,screenToFlowPosition:se}=ke(),{activeProjectId:ce}=c(),[w,le]=(0,R.useState)([]),[de,fe]=(0,R.useState)({}),[pe,E]=(0,R.useState)(!1),[D,_e]=(0,R.useState)({}),[ye,k]=(0,R.useState)([]),[A,j]=(0,R.useState)(null),[M,Se]=(0,R.useState)(null);(0,R.useEffect)(()=>{let e=!1;return O.catalog().then(t=>{e||(le(t.nodeKinds),fe(t.definitionSchema??{}),E(!1))}).catch(()=>{e||E(!0)}),()=>{e=!0}},[]),(0,R.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([ce&&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()},[ce,!!A,!!A?.config.agents]);let[N,P,Te]=Oe([]),[F,I,Fe]=Le([]),[L,ze]=(0,R.useState)(``),[Ve,Ue]=(0,R.useState)(!1),[We,Ge]=(0,R.useState)(!1),[Ke,qe]=(0,R.useState)(10),[Je,Ye]=(0,R.useState)(30),[B,V]=(0,R.useState)(null),[H,U]=(0,R.useState)(null),[W,G]=(0,R.useState)(!1);(0,R.useEffect)(()=>G(!1),[h]);let[et,tt]=(0,R.useState)(!0),[nt,K]=(0,R.useState)(!1),[q,J]=(0,R.useState)(!1),[Y,it]=(0,R.useState)(null),[at,ct]=(0,R.useState)(!1),X=(0,R.useMemo)(()=>[...yt(N,F),...ye.map(e=>({severity:`error`,code:`CORE_VALIDATION`,nodeId:e.nodeId,message:e.message}))],[N,F,ye]),pt=(0,R.useMemo)(()=>bt(X),[X]),_t=X.filter(e=>e.severity===`error`).length,[vt,Tt]=(0,R.useState)(`manual`),Dt=(0,R.useRef)(new Map),[Ot,kt]=(0,R.useState)([]),[At,jt]=(0,R.useState)(!1),Mt=(0,R.useCallback)(async()=>{try{kt(await O.loopConstants())}catch{}},[]);(0,R.useEffect)(()=>{Mt()},[Mt]);let It=(0,R.useMemo)(()=>({loop:Et}),[]),Lt=(0,R.useCallback)(e=>{j(e.graph),Se(null);let{nodes:t,edges:n}=dt(e.graph);Dt.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`;Tt(i),P(i===`manual`?t:Ie(t,n,i)),I(n),ze(e.name),qe(e.graph.config?.maxIterations??10),Ye(e.graph.config?.timeoutMinutes??30),V(typeof e.graph.config?.maxCostUsd==`number`?e.graph.config.maxCostUsd:null),Ue(!!e.builtinId)},[P,I]);(0,R.useEffect)(()=>{if(!h)return;let e=!1;return O.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,R.useCallback)(async()=>{if(h){Ge(!1);try{Lt(await O.restoreBuiltin(h)),k([]),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,R.useCallback)(e=>{if(k([]),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,R.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=Ze(w.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,w,A]),Vt=(0,R.useCallback)(e=>{Tt(e==="default"?`manual`:e),P(t=>e==="default"?t.map(e=>{let t=Dt.current.get(e.id);return t?{...e,position:{...t}}:e}):Ie(t,F,e)),requestAnimationFrame(()=>b({padding:.25,maxZoom:.85,duration:300}))},[P,F,b]),Ht=(0,R.useCallback)(e=>{e.some(e=>e.type===`position`&&e.dragging===!1)&&Tt(`manual`),Te(e)},[Te]),Ut=(0,R.useRef)(N);Ut.current=N;let Wt=(0,R.useRef)(F);Wt.current=F,(0,R.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=mt(Ut.current,Wt.current);!n||!t.clipboardData||(t.clipboardData.setData(`text/plain`,JSON.stringify(n)),t.preventDefault())},n=t=>{if(e())return;let n=ht(t.clipboardData?.getData(`text/plain`)??``);if(!n)return;t.preventDefault();let r=gt(n,{mintId:lt,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]),Tt(`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,R.useCallback)(e=>{let t=ut(e,{x:120+Math.random()*120,y:80+Math.random()*240});P(e=>[...e,t]),G(!1),U(t.id)},[P]),Kt=(0,R.useCallback)(e=>{k([]),P(t=>t.map(t=>t.id===H?{...t,data:{...t.data,...e}}:t))},[H,P]),qt=(0,R.useCallback)(()=>{H&&(P(e=>e.filter(e=>e.id!==H)),I(e=>e.filter(e=>e.source!==H&&e.target!==H)),U(null))},[H,P,I]),Z=!!A&&!N.some(e=>![`start`,`core`,`end`].includes(e.data.kind)),Q=(0,R.useCallback)(()=>{let e={...A?.config,maxIterations:Ke,timeoutMinutes:Je,maxCostUsd:B??void 0,layout:vt},t=M?A?.components?.[M]:A,n={...t,...ft(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,Ke,Je,B,vt]),Jt=(0,R.useCallback)((e,t=!1)=>{let n=Q();e&&t&&!n.components?.[e]&&(n.components={...n.components,[e]:{nodes:[{id:lt(),type:`start`,position:{x:160,y:40}},{id:lt(),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=dt(r);j(n),Se(e),P(i.nodes),I(i.edges),U(null),k([]),requestAnimationFrame(()=>b({padding:.25}))},[Q,P,I,b]),Yt=(0,R.useCallback)((e,t)=>{let n={id:lt(),type:`loop`,position:t??{x:160+N.length*20,y:100+N.length*30},data:Xe(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]),G(!1),U(n.id)},[N.length,P,D.providers,A,o]),Xt=(0,R.useCallback)(async()=>{ct(!0);try{let e=Q(),{steps:t}=await O.previewLoop(e);it(t)}catch{l.error(o(`builder.preview.error`))}finally{ct(!1)}},[Q,o]),Zt=(0,R.useCallback)(async()=>{if(!h)return!1;K(!0);try{let e=Q();return await O.update(h,{name:L,graph:e}),!0}catch(e){return l.error(e instanceof Error&&e.message?e.message:o(`errors.save`)),!1}finally{K(!1)}},[h,Q,L,o]),Qt=(0,R.useCallback)(async()=>{if(h&&await Zt())try{await O.publish(h),l.success(o(`builder.published`)),g()}catch(e){e instanceof xe?(k(e.errors),J(!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===H)??null;return(0,z.jsx)(xt.Provider,{value:pt,children:(0,z.jsx)(St.Provider,{value:{pieces:w,components:A?.components},children:(0,z.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 h-12 border-b border-border flex-shrink-0`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,z.jsx)(`button`,{type:`button`,onClick:g,className:`text-muted-foreground hover:text-foreground`,"aria-label":o(`builder.back`),children:(0,z.jsx)(d,{className:`w-4 h-4`})}),(0,z.jsx)(`input`,{value:L,onChange:e=>ze(e.target.value),className:`text-sm font-semibold bg-transparent text-foreground border-b border-transparent focus:border-border focus:outline-none min-w-0`,"aria-label":`name`})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsxs)(ge,{delayDuration:150,children:[(0,z.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[o(`builder.config.maxIterations`),(0,z.jsxs)(Ce,{children:[(0,z.jsx)(he,{asChild:!0,children:(0,z.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":o(`builder.config.maxIterations`),children:(0,z.jsx)(T,{className:`w-3 h-3`})})}),(0,z.jsx)(ue,{className:`max-w-xs leading-relaxed`,children:o(`builder.config.maxIterationsHint`)})]}),(0,z.jsx)(`input`,{type:`number`,min:1,value:Ke,onChange:e=>qe(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,z.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[o(`builder.config.timeout`),(0,z.jsxs)(Ce,{children:[(0,z.jsx)(he,{asChild:!0,children:(0,z.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":o(`builder.config.timeout`),children:(0,z.jsx)(T,{className:`w-3 h-3`})})}),(0,z.jsx)(ue,{className:`max-w-xs leading-relaxed`,children:o(`builder.config.timeoutHint`)})]}),(0,z.jsx)(`input`,{type:`number`,min:0,"aria-label":o(`builder.config.timeout`),value:Je,onChange:e=>Ye(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,z.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[o(`builder.config.maxCost`),(0,z.jsxs)(Ce,{children:[(0,z.jsx)(he,{asChild:!0,children:(0,z.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":o(`builder.config.maxCost`),children:(0,z.jsx)(T,{className:`w-3 h-3`})})}),(0,z.jsx)(ue,{className:`max-w-xs leading-relaxed`,children:o(`builder.config.maxCostHint`)})]}),(0,z.jsx)(`input`,{type:`number`,min:0,step:.5,placeholder:`∞`,value:B??``,onChange:e=>{let t=Number(e.target.value);V(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,z.jsx)(`button`,{type:`button`,"aria-pressed":W,onClick:()=>G(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`)}),Ve&&(0,z.jsxs)(`button`,{type:`button`,onClick:()=>Ge(!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,z.jsx)(v,{className:`w-3 h-3`}),` `,o(`actions.restoreBuiltin`)]}),(0,z.jsxs)(`button`,{type:`button`,onClick:()=>void Xt(),disabled:at,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,z.jsx)(me,{className:`w-3 h-3`}),` `,o(`builder.preview.label`)]}),!we()&&(0,z.jsxs)(`button`,{type:`button`,disabled:nt,onClick:()=>void Zt().then(async e=>{if(!(!e||!h))try{await be(ce,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,z.jsx)(p,{className:`w-3 h-3`}),o(`window.open`)]}),(0,z.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,z.jsx)(f,{className:`w-3 h-3`}),` `,o(`builder.save`)]}),(0,z.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,z.jsx)(te,{className:`w-3 h-3`}),` `,o(`builder.publish`)]})]})]}),Ve&&(0,z.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,z.jsx)(oe,{open:We,onOpenChange:e=>{e||Ge(!1)},children:(0,z.jsxs)(x,{className:`max-w-sm`,children:[(0,z.jsxs)(ae,{children:[(0,z.jsx)(ie,{children:o(`builder.builtin.confirmTitle`)}),(0,z.jsx)(re,{children:o(`builder.builtin.confirmBody`)})]}),(0,z.jsxs)(ne,{children:[(0,z.jsx)(C,{variant:`ghost`,onClick:()=>Ge(!1),children:o(`common:actions.cancel`)}),(0,z.jsx)(C,{"data-testid":`builder-restore-confirm`,onClick:()=>void Rt(),children:o(`actions.restoreBuiltin`)})]})]})}),(0,z.jsxs)(`div`,{className:`flex-1 flex min-h-0`,children:[(0,z.jsxs)(`div`,{className:`w-44 border-r border-border p-2 space-y-1 flex-shrink-0 overflow-y-auto`,children:[(0,z.jsx)(`p`,{className:`text-[10px] font-semibold uppercase tracking-wide text-muted-foreground px-1 mb-1`,children:o(`builder.addNode`)}),Z&&pe&&(0,z.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground px-1`,children:o(`builder.core.unavailable`)}),Z&&w.length>0&&[`ai`,`verification`,`openspec`,`control`].map(e=>(0,z.jsxs)(`div`,{className:`pt-2`,children:[(0,z.jsx)(`p`,{className:`text-[10px] uppercase text-muted-foreground px-1`,children:o(`builder.core.groups.${e}`)}),w.filter(t=>![`implementation`,`implementation-step`].includes(t.kind)&&Qe(t.kind)===e).map(e=>(0,z.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,z.jsx)(_,{className:`h-3 w-3 flex-shrink-0`}),o(`builder.core.pieces.${e.kind}`)]},e.kind))]},e)),(Z?[`start`]:Ct).map(e=>{let t=wt[e];return(0,z.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,z.jsx)(t,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,z.jsx)(`span`,{className:`truncate`,children:o(`builder.nodes.${e}`)}),(0,z.jsx)(_,{className:`w-3 h-3 ml-auto opacity-50`})]},e)})]}),(0,z.jsx)(`div`,{className:`flex-1 min-w-0 relative`,onDragOver:e=>{e.dataTransfer.types.includes(`application/specrails-core-piece`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},onDrop:e=>{let t=w.find(t=>t.kind===e.dataTransfer.getData(`application/specrails-core-piece`));!t||!Z||(e.preventDefault(),Yt(t,se({x:e.clientX,y:e.clientY})))},children:et?(0,z.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,z.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`…`})}):(0,z.jsxs)(Ae,{nodes:N,edges:F,onNodesChange:Ht,onEdgesChange:Fe,onConnect:zt,isValidConnection:Bt,onNodeClick:(e,t)=>{G(!1),U(t.id)},onPaneClick:()=>{G(!1),U(null)},nodeTypes:It,colorMode:y.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,z.jsx)(Me,{position:`top-center`,children:(0,z.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,z.jsx)(`button`,{type:`button`,onClick:()=>Jt(null),className:`px-2 py-1 hover:bg-muted`,children:L||o(`builder.core.root`)}),M&&(0,z.jsxs)(`span`,{"aria-current":`page`,children:[`/ `,M]})]})}),(0,z.jsx)(je,{}),(0,z.jsx)(Pe,{}),(0,z.jsx)(Ee,{pannable:!0,zoomable:!0}),(0,z.jsx)(Me,{position:`top-left`,children:(0,z.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`,He],[`horizontal`,Be],[`grid`,Re],[`default`,v]].map(([e,t])=>{let n=e==="default"?`reset`:e,r=e==="default"?vt===`manual`:vt===e;return(0,z.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,z.jsx)(t,{className:`w-3.5 h-3.5`})},e)})})}),(0,z.jsx)(Me,{position:`top-right`,children:(0,z.jsx)(ge,{delayDuration:150,children:(0,z.jsxs)(Ce,{children:[(0,z.jsx)(he,{asChild:!0,children:(0,z.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,z.jsx)(T,{className:`w-3 h-3`}),o(`builder.edgesHelp.label`)]})}),(0,z.jsx)(ue,{className:`max-w-xs leading-relaxed`,children:o(`builder.edgesHelp.body`)})]})})}),X.length>0&&(0,z.jsx)(Me,{position:`bottom-center`,children:(0,z.jsxs)(`div`,{className:`rounded-md border border-border bg-card/95 backdrop-blur text-xs overflow-hidden max-w-md mb-2`,children:[(0,z.jsxs)(`button`,{type:`button`,onClick:()=>J(e=>!e),className:S(`flex items-center gap-1.5 w-full px-2.5 py-1.5 font-medium`,_t>0?`text-destructive`:`text-accent-warning`),children:[(0,z.jsx)(ee,{className:`w-3.5 h-3.5`}),o(`builder.problems.count`,{count:X.length})]}),q&&(0,z.jsx)(`ul`,{className:`border-t border-border max-h-40 overflow-y-auto py-1`,children:X.map((e,t)=>(0,z.jsx)(`li`,{children:(0,z.jsxs)(`button`,{type:`button`,disabled:!e.nodeId,onClick:()=>{e.nodeId&&(G(!1),U(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,z.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,z.jsx)(`span`,{className:`text-foreground`,children:`message`in e?String(e.message):o(`builder.problems.${e.code}`)})]})},`${e.code}-${e.nodeId??t}`))})]})})]})}),(0,z.jsxs)(`div`,{className:`w-80 border-l border-border p-3 flex-shrink-0 overflow-y-auto space-y-4`,children:[!W&&($?$.data.kind===`core`?(0,z.jsx)(st,{nodeId:$.id,data:$.data,piece:w.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:de,onChange:Kt,onDelete:qt,onOpenCanvas:Jt}):(0,z.jsx)(Ft,{data:$.data,onChange:Kt,onDelete:qt,constants:Ot,onManageConstants:()=>jt(!0)}):(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`builder.inspector.selectNode`)})),!W&&Z&&A&&$&&($e($.id,$.data.coreKind,$.data.params??{}).length>0||$.data.coreKind===`implementation-step`&&$.data.params?.phase===`archive`)&&(0,z.jsx)(rt,{mode:$.data.coreKind===`implementation`?`all`:`step`,graph:Q(),value:A.config.agents,selectedRole:String($.data.params?.phase??$e($.id,$.data.coreKind,$.data.params??{})[0]??``),onChange:e=>j({...A,config:{...A.config,agents:e}})},`${h}:${$.id}`),W&&Z&&A&&(0,z.jsx)(rt,{mode:`workflow`,graph:Q(),value:A.config.agents,selectedRole:$?$e($.id,$.data.coreKind,$.data.params??{})[0]:void 0,onChange:e=>j({...A,config:{...A.config,agents:e}})},h),W&&Z&&A&&(0,z.jsx)(ot,{graph:A,canvas:M,schema:de,onChange:j,onOpenCanvas:Jt})]})]}),(0,z.jsx)(Nt,{open:At,onClose:()=>jt(!1),constants:Ot,onChanged:Mt,t:o}),(0,z.jsx)(Pt,{steps:Y,onClose:()=>it(null),t:o})]})})})}var Ot=[{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 kt({token:e,label:t,description:n,onInsert:r}){return(0,z.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 At({t:e,onInsert:t}){let[n,r]=(0,R.useState)([]);return(0,R.useEffect)(()=>{let e=!1;return O.loopCommands().then(t=>{e||r(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,z.jsxs)(`div`,{className:`mb-2 space-y-1.5`,children:[Ot.map(n=>(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`block text-[9px] uppercase tracking-wide text-muted-foreground/70 mb-0.5`,children:e(n.labelKey)}),(0,z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.tokens.map(e=>(0,z.jsx)(kt,{token:e.token,label:e.label,onInsert:t},e.token))})]},n.labelKey)),n.length>0&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`span`,{className:`block text-[9px] uppercase tracking-wide text-muted-foreground/70 mb-0.5`,children:e(`builder.inspector.tokensCommands`)}),(0,z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>(0,z.jsx)(kt,{token:`{{cmd:${e.name}}}`,label:`⚡ ${e.label}`,description:e.description,onInsert:t},e.name))})]})]})}function jt({t:e,constants:t,onInsert:n,onManage:r}){return(0,z.jsxs)(`div`,{className:`mb-2`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between mb-0.5`,children:[(0,z.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:e(`builder.constants.label`)}),(0,z.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,z.jsx)(pe,{className:`w-3 h-3`})})]}),(0,z.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.map(e=>(0,z.jsx)(kt,{token:`{{const:${e.name}}}`,label:e.builtin?`🔒 ${e.name}`:e.name,description:e.value,onInsert:n},e.id))})]})}function Mt({c:e,onSave:t,onDelete:n}){let[r,i]=(0,R.useState)(e.value);return(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,z.jsx)(`code`,{className:`text-[10px] font-mono text-accent-primary w-28 truncate`,title:e.name,children:e.name}),(0,z.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,z.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,z.jsx)(f,{className:`w-3.5 h-3.5`})}),(0,z.jsx)(`button`,{type:`button`,onClick:n,className:`text-muted-foreground hover:text-destructive`,"aria-label":`delete`,children:(0,z.jsx)(y,{className:`w-3.5 h-3.5`})})]})}function Nt({open:e,onClose:t,constants:n,onChanged:r,t:i}){let[a,o]=(0,R.useState)(``),[s,c]=(0,R.useState)(``),[l,u]=(0,R.useState)(null),[d,f]=(0,R.useState)(!1),p=n.filter(e=>e.builtin),m=n.filter(e=>!e.builtin),h=async()=>{f(!0),u(null);try{await O.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,z.jsx)(oe,{open:e,onOpenChange:e=>{e||t()},children:(0,z.jsxs)(x,{className:`max-w-md`,children:[(0,z.jsx)(ae,{children:(0,z.jsx)(ie,{children:i(`builder.constants.title`)})}),(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsxs)(`div`,{className:`space-y-1.5`,children:[m.length===0&&(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`builder.constants.empty`)}),m.map(e=>(0,z.jsx)(Mt,{c:e,onSave:t=>void O.updateConstant(e.id,t).then(r),onDelete:()=>void O.deleteConstant(e.id).then(r)},e.id))]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 border-t border-border pt-2`,children:[(0,z.jsx)(`input`,{className:`${g} w-28`,placeholder:i(`builder.constants.name`),value:a,onChange:e=>o(e.target.value)}),(0,z.jsx)(`input`,{className:`${g} flex-1`,placeholder:i(`builder.constants.value`),value:s,onChange:e=>c(e.target.value)}),(0,z.jsx)(C,{size:`sm`,disabled:d||!a.trim()||!s,onClick:()=>void h(),children:i(`builder.constants.add`)})]}),l&&(0,z.jsx)(`p`,{className:`text-[10px] text-destructive`,children:l}),p.length>0&&(0,z.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[(0,z.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:i(`builder.constants.builtinBadge`)}),p.map(e=>(0,z.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px]`,children:[(0,z.jsx)(`code`,{className:`font-mono text-accent-primary w-28 truncate`,title:e.name,children:e.name}),(0,z.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.value})]},e.id))]})]}),(0,z.jsx)(ne,{children:(0,z.jsx)(C,{variant:`ghost`,onClick:t,children:i(`common:actions.close`)})})]})})}function Pt({steps:e,onClose:t,t:n}){return(0,z.jsx)(oe,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,z.jsxs)(x,{className:`max-w-2xl`,children:[(0,z.jsx)(ae,{children:(0,z.jsx)(ie,{children:n(`builder.preview.title`)})}),(0,z.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:n(`builder.preview.sampleNote`)}),(0,z.jsxs)(`div`,{className:`space-y-2 max-h-[60vh] overflow-y-auto`,children:[e&&e.length===0&&(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`builder.preview.empty`)}),e?.map((e,t)=>(0,z.jsxs)(`div`,{className:`rounded-md border border-border`,children:[(0,z.jsxs)(`div`,{className:`px-2.5 py-1 text-[10px] border-b border-border flex items-center gap-1.5`,children:[(0,z.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,z.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,z.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,z.jsx)(ne,{children:(0,z.jsx)(C,{variant:`ghost`,onClick:t,children:n(`common:actions.close`)})})]})})}function Ft({data:e,onChange:t,onDelete:n,constants:r,onManageConstants:i}){let{t:o}=a(`loops`),{activeProjectId:s,projects:l}=c(),u=ce(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,R.useRef)(null),h=(0,R.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,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,z.jsx)(`span`,{className:`text-xs font-semibold text-foreground`,children:o(`builder.nodes.${d}`)}),(0,z.jsx)(`button`,{type:`button`,onClick:n,"aria-label":o(`builder.deleteNode`),className:`text-muted-foreground hover:text-destructive`,children:(0,z.jsx)(y,{className:`w-3.5 h-3.5`})})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:f,children:o(`builder.inspector.label`)}),(0,z.jsx)(`input`,{className:p,value:String(e.label??``),onChange:e=>t({label:e.target.value}),placeholder:o(`builder.nodes.${d}`)})]}),d===`ai-step`&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:f,children:o(`builder.inspector.prompt`)}),(0,z.jsx)(At,{t:o,onInsert:_}),(0,z.jsx)(jt,{t:o,constants:r,onInsert:_,onManage:i}),(0,z.jsx)(`textarea`,{ref:m,rows:7,className:p,value:String(e.prompt??``),onChange:e=>t({prompt:e.target.value})}),(0,z.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-1`,children:o(`builder.inspector.promptHint`)})]}),d===`shell`&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:f,children:o(`builder.inspector.command`)}),(0,z.jsx)(`input`,{className:p,value:String(e.command??``),onChange:e=>t({command:e.target.value}),placeholder:`npm test`}),(0,z.jsxs)(`label`,{className:`${f} mt-3`,children:[o(`common:repositories.shellTarget`),(0,z.jsxs)(`select`,{className:p,value:String(e.repositoryId??``),onChange:e=>t({repositoryId:e.target.value||void 0}),children:[(0,z.jsx)(`option`,{value:``,children:o(`common:repositories.shellDefault`)}),u.filter(e=>e.kind===`git`).map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.name},e.id)),!!e.repositoryId&&!u.some(t=>t.id===e.repositoryId)&&(0,z.jsx)(`option`,{value:String(e.repositoryId),children:String(e.repositoryId)})]})]}),(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`common:repositories.shellHint`)})]}),d===`decider`&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:f,children:o(`builder.inspector.goal`)}),(0,z.jsx)(jt,{t:o,constants:r,onInsert:e=>g(h,`goal`,e),onManage:i}),(0,z.jsx)(`textarea`,{ref:h,rows:4,className:p,value:String(e.goal??``),onChange:e=>t({goal:e.target.value})})]}),d===`condition`&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:f,children:o(`builder.inspector.join`)}),(0,z.jsxs)(`select`,{className:p,value:String(e.join??`AND`),onChange:e=>t({join:e.target.value}),children:[(0,z.jsx)(`option`,{value:`AND`,children:`AND`}),(0,z.jsx)(`option`,{value:`OR`,children:`OR`})]})]}),d===`end`&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:f,children:o(`builder.inspector.outcome`)}),(0,z.jsxs)(`select`,{className:p,value:String(e.outcome??`success`),onChange:e=>t({outcome:e.target.value}),children:[(0,z.jsx)(`option`,{value:`success`,children:`success`}),(0,z.jsx)(`option`,{value:`failure`,children:`failure`})]})]}),d===`start`&&(0,z.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:o(`builder.inspector.startNote`)})]})}function It({loopId:e,onExit:t,onWindowOpened:n}={}){return(0,z.jsx)(Fe,{children:(0,z.jsx)(Dt,{loopId:e,onExit:t,onWindowOpened:n})})}export{It as default};
@@ -1 +1 @@
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{n as a}from"./createLucideIcon-Bjbbp_KS.js";import{t as o}from"./pencil-C9RkrIPZ.js";import{t as s}from"./square-Ci-PFcFe.js";import{t as c}from"./utils-BC4DHlz2.js";import{t as l}from"./button-D1xExSTF.js";import{$t as u}from"./index-CONHvEJw.js";import{r as d,t as f}from"./TemplatePreviewModal-DcFlhUxy.js";var p=e(t(),1),m=e(r(),1),h=n();function g({loop:e,onClose:t}){let{t:n}=a(`loops`),r=i();return(0,p.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,m.createPortal)((0,h.jsxs)(`div`,{"data-testid":`loop-preview-modal`,className:`fixed inset-0 z-[65] flex items-center justify-center p-4`,children:[(0,h.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t,"aria-hidden":!0}),(0,h.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":e.name,className:`relative flex max-h-[80vh] w-full max-w-lg flex-col gap-4 overflow-hidden rounded-xl border border-border/30 bg-popover p-6 shadow-xl backdrop-blur-md`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2 pr-6`,children:[(0,h.jsx)(u,{className:`h-4 w-4 shrink-0 text-accent-highlight`}),(0,h.jsx)(`span`,{className:`min-w-0 truncate text-base font-semibold text-foreground`,children:e.name}),(0,h.jsx)(`span`,{className:c(`inline-flex shrink-0 items-center gap-1 rounded-full border px-1.5 py-px text-[10px] font-medium uppercase tracking-wide`,e.builtin?`border-accent-info/40 bg-accent-info/10 text-accent-info`:e.status===`published`?`border-accent-success/40 bg-accent-success/10 text-accent-success`:`border-border/60 bg-surface/60 text-foreground/60`),children:e.builtin?n(`preview.builtin`):n(`status.${e.status??`draft`}`,{defaultValue:e.status??``})})]}),e.description&&(0,h.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description})]}),(0,h.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e.graph.config.timeoutMinutes>0?n(`preview.limits`,{iterations:e.graph.config.maxIterations,timeout:e.graph.config.timeoutMinutes}):n(`preview.limitsNoTimeout`,{iterations:e.graph.config.maxIterations})}),(0,h.jsxs)(`div`,{className:`min-h-0 space-y-1.5 overflow-y-auto pr-1`,children:[(0,h.jsx)(`span`,{className:`block text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:n(`preview.steps`)}),e.graph.nodes.map((e,t)=>{let r=f[e.type]??s,i=d(e);return(0,h.jsxs)(`div`,{className:`rounded border border-border bg-surface/30 p-2`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium text-foreground`,children:[(0,h.jsxs)(`span`,{className:`text-[10px] tabular-nums text-muted-foreground`,children:[t+1,`.`]}),(0,h.jsx)(r,{className:`h-3.5 w-3.5 text-accent-primary`}),n(`builder.nodes.${e.type}`)]}),i&&(0,h.jsx)(`pre`,{className:`mt-1 whitespace-pre-wrap break-words font-mono text-[11px] text-muted-foreground`,children:i})]},e.id)})]}),(0,h.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2`,children:[(0,h.jsx)(l,{variant:`ghost`,onClick:t,children:n(`common:actions.close`)}),!e.locked&&(0,h.jsxs)(l,{"data-testid":`loop-preview-open-builder`,onClick:()=>{t(),r(`/loops/${encodeURIComponent(e.id)}/edit`)},children:[(0,h.jsx)(o,{className:`mr-1.5 h-3.5 w-3.5`}),n(`preview.openInBuilder`)]})]})]})]}),document.body)}export{g as LoopPreviewModal};
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-BbYvbtY8.js";import{t as r}from"./react-dom-DDD8FYaU.js";import{u as i}from"./chunk-OB3PAWPO-B1EMk45A.js";import{n as a}from"./createLucideIcon-DtODIU64.js";import{t as o}from"./pencil-CxrRbDwb.js";import{t as s}from"./square-D0JTbRSR.js";import{t as c}from"./utils-BC4DHlz2.js";import{t as l}from"./button-4FS1ZDTp.js";import{$t as u}from"./index-CECj3joE.js";import{r as d,t as f}from"./TemplatePreviewModal-BZTV1TM1.js";var p=e(t(),1),m=e(r(),1),h=n();function g({loop:e,onClose:t}){let{t:n}=a(`loops`),r=i();return(0,p.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),(0,m.createPortal)((0,h.jsxs)(`div`,{"data-testid":`loop-preview-modal`,className:`fixed inset-0 z-[65] flex items-center justify-center p-4`,children:[(0,h.jsx)(`div`,{className:`absolute inset-0 bg-black/60 backdrop-blur-sm`,onClick:t,"aria-hidden":!0}),(0,h.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":e.name,className:`relative flex max-h-[80vh] w-full max-w-lg flex-col gap-4 overflow-hidden rounded-xl border border-border/30 bg-popover p-6 shadow-xl backdrop-blur-md`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-2 pr-6`,children:[(0,h.jsx)(u,{className:`h-4 w-4 shrink-0 text-accent-highlight`}),(0,h.jsx)(`span`,{className:`min-w-0 truncate text-base font-semibold text-foreground`,children:e.name}),(0,h.jsx)(`span`,{className:c(`inline-flex shrink-0 items-center gap-1 rounded-full border px-1.5 py-px text-[10px] font-medium uppercase tracking-wide`,e.builtin?`border-accent-info/40 bg-accent-info/10 text-accent-info`:e.status===`published`?`border-accent-success/40 bg-accent-success/10 text-accent-success`:`border-border/60 bg-surface/60 text-foreground/60`),children:e.builtin?n(`preview.builtin`):n(`status.${e.status??`draft`}`,{defaultValue:e.status??``})})]}),e.description&&(0,h.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description})]}),(0,h.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e.graph.config.timeoutMinutes>0?n(`preview.limits`,{iterations:e.graph.config.maxIterations,timeout:e.graph.config.timeoutMinutes}):n(`preview.limitsNoTimeout`,{iterations:e.graph.config.maxIterations})}),(0,h.jsxs)(`div`,{className:`min-h-0 space-y-1.5 overflow-y-auto pr-1`,children:[(0,h.jsx)(`span`,{className:`block text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:n(`preview.steps`)}),e.graph.nodes.map((e,t)=>{let r=f[e.type]??s,i=d(e);return(0,h.jsxs)(`div`,{className:`rounded border border-border bg-surface/30 p-2`,children:[(0,h.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium text-foreground`,children:[(0,h.jsxs)(`span`,{className:`text-[10px] tabular-nums text-muted-foreground`,children:[t+1,`.`]}),(0,h.jsx)(r,{className:`h-3.5 w-3.5 text-accent-primary`}),n(`builder.nodes.${e.type}`)]}),i&&(0,h.jsx)(`pre`,{className:`mt-1 whitespace-pre-wrap break-words font-mono text-[11px] text-muted-foreground`,children:i})]},e.id)})]}),(0,h.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2`,children:[(0,h.jsx)(l,{variant:`ghost`,onClick:t,children:n(`common:actions.close`)}),!e.locked&&(0,h.jsxs)(l,{"data-testid":`loop-preview-open-builder`,onClick:()=>{t(),r(`/loops/${encodeURIComponent(e.id)}/edit`)},children:[(0,h.jsx)(o,{className:`mr-1.5 h-3.5 w-3.5`}),n(`preview.openInBuilder`)]})]})]})]}),document.body)}export{g as LoopPreviewModal};
@@ -1 +1 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{r}from"./useDesktop-9Lwoel_8.js";import i from"./LoopsPage-DHgIreEW.js";import a from"./LoopBuilderPage-C9D9eer5.js";var o=e(t(),1),s=n();function c(){let{projects:e,isLoading:t,setActiveProjectId:n}=r(),[c,l]=(0,o.useState)(()=>new URLSearchParams(window.location.search).get(`loopId`)),u=(0,o.useRef)(!1),d=new URLSearchParams(window.location.search).get(`projectId`);return(0,o.useEffect)(()=>{!t&&!u.current&&(u.current=!0,n(e.some(e=>e.id===d)?d:null))},[t,d,e,n]),(0,s.jsx)(`div`,{className:`flex-1 min-h-0 bg-background`,children:c?(0,s.jsx)(a,{loopId:c,onExit:()=>l(null)},c):(0,s.jsx)(i,{onOpenBuilder:l})})}export{c as LoopWindowSurface};
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-BbYvbtY8.js";import{r}from"./useDesktop-C0mRIlHT.js";import i from"./LoopsPage-eKpWFtCp.js";import a from"./LoopBuilderPage-iFylNk68.js";var o=e(t(),1),s=n();function c(){let{projects:e,isLoading:t,setActiveProjectId:n}=r(),[c,l]=(0,o.useState)(()=>new URLSearchParams(window.location.search).get(`loopId`)),u=(0,o.useRef)(!1),d=new URLSearchParams(window.location.search).get(`projectId`);return(0,o.useEffect)(()=>{!t&&!u.current&&(u.current=!0,n(e.some(e=>e.id===d)?d:null))},[t,d,e,n]),(0,s.jsx)(`div`,{className:`flex-1 min-h-0 bg-background`,children:c?(0,s.jsx)(a,{loopId:c,onExit:()=>l(null)},c):(0,s.jsx)(i,{onOpenBuilder:l})})}export{c as LoopWindowSurface};
@@ -0,0 +1,2 @@
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-BbYvbtY8.js";import{u as r}from"./chunk-OB3PAWPO-B1EMk45A.js";import{n as i,t as a}from"./createLucideIcon-DtODIU64.js";import{n as o,r as s,s as c}from"./useDesktop-C0mRIlHT.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-C9wP_42h.js";import{t as m}from"./external-link-CZ6Q-v1-.js";import{t as h}from"./pencil-CxrRbDwb.js";import{n as g}from"./square-D0JTbRSR.js";import{t as _}from"./plus-fHDdjBk1.js";import{t as v}from"./rotate-ccw-DalJAQQX.js";import{t as y}from"./sparkles-CCfUdFGY.js";import{t as b}from"./trash-D8zYUmTg.js";import{t as x}from"./upload-CCHvUkRs.js";import{a as S,i as C,l as w,o as T,r as E,t as D}from"./dialog-DtdR05v1.js";import{t as O}from"./utils-BC4DHlz2.js";import{t as k}from"./button-4FS1ZDTp.js";import{t as ee}from"./RepositoryScopeSelector-DeCoUsRN.js";import{Gt as A,Q as j,Wt as M,Z as N,at as P,cn as te,it as F,mt as I,ot as ne,rt as L,sn as re,st as R}from"./index-CECj3joE.js";import{n as ie}from"./TemplatePreviewModal-BZTV1TM1.js";var z={name:`file-down`,size:24,node:[[`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`}]]};z.node;var ae=a(z),B={name:`file-up`,size:24,node:[[`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.node;var oe=a(B),V=e(t(),1),H=n(),U=[`invalid`,`needs_attention`,`convertible`,`running`,`current`];function se({onConvert:e}){let{t}=i(`loops`),[n,r]=(0,V.useState)(null),[a,o]=(0,V.useState)(!1),[s,c]=(0,V.useState)(``),l=(0,V.useRef)(!0);(0,V.useEffect)(()=>(l.current=!0,()=>{l.current=!1}),[]);async function u(){o(!0),c(``),r(null);try{let e=await P.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,H.jsxs)(`section`,{className:`rounded-lg border border-border p-3 space-y-2`,"aria-label":t(`migration.title`),children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:t(`migration.title`)}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`migration.description`)})]}),(0,H.jsx)(k,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>void u(),children:t(a?`migration.checking`:`migration.check`)})]}),s&&(0,H.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:s}),n&&(0,H.jsxs)(`div`,{role:`status`,className:`space-y-2 text-xs`,children:[(0,H.jsx)(`p`,{children:U.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,H.jsx)(`p`,{className:`text-muted-foreground`,children:t(`migration.allCurrent`)}),(0,H.jsx)(`ul`,{className:`space-y-1`,children:d.map(n=>(0,H.jsxs)(`li`,{className:`flex flex-wrap items-center gap-2`,children:[(0,H.jsx)(`span`,{className:`font-medium`,children:n.name}),(0,H.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,H.jsx)(`span`,{className:`text-destructive`,children:e.message},t)),n.state===`convertible`&&(0,H.jsx)(k,{size:`sm`,variant:`ghost`,onClick:()=>e(n.id),children:t(`actions.convert`)})]},n.id))})]})]})}function ce(e){return{specrailsLoops:1,loops:e.map(e=>({name:e.name,description:e.description,graph:e.graph}))}}function W(e){let t=e;return!!t&&typeof t.name==`string`&&!!t.graph&&typeof t.graph==`object`}function le(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:W(t)?[t]:[]).filter(W);if(n.length===0)throw Error(`no-loops`);return n.map(e=>({name:e.name,description:e.description??null,graph:e.graph}))}function ue(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 G=[`API`,`Automation`,`CI`,`Database`,`Debugging`,`DevOps`,`Docs`,`Git`,`Maintenance`,`Performance`,`Planning`,`Quality`,`Review`,`Security`,`Testing`];function de(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 fe(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 G){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 pe({loop:e,projects:t,onClose:n,onExecute:r}){let{t:a}=i(`loops`),o=e!==null,[s,c]=(0,V.useState)(``),[p,m]=(0,V.useState)(``),[h,_]=(0,V.useState)(``),[v,y]=(0,V.useState)(``),[b,x]=(0,V.useState)(),O=t.find(e=>e.id===(s||t[0]?.id)),A=(0,V.useMemo)(()=>O?.providers??(O?.provider?[O.provider]:[]),[O]),M=p||A[0]||``,P=(0,V.useMemo)(()=>R(M),[M]),te=f(M),F=h&&(P.some(e=>e.value===h)||te&&j(h))?h:ne(M),I=l(M,F),L=I.includes(v)?v:d(M,F)??``,re=I.length>0;return(0,H.jsx)(D,{open:o,onOpenChange:e=>{e||n()},children:(0,H.jsx)(E,{movableResizable:!0,className:`max-w-sm`,children:e&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(T,{children:[(0,H.jsx)(w,{children:a(`run.title`,{name:e.name})}),(0,H.jsx)(C,{children:a(`run.subtitle`)})]}),(0,H.jsx)(`label`,{className:`block text-[11px] font-medium text-muted-foreground`,children:a(`run.project`)}),t.length===0?(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a(`run.noProjects`)}):(0,H.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,H.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,H.jsx)(ee,{repositories:O?.repositories??[],value:b,onChange:x}),A.length>1&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`label`,{className:`block text-[11px] font-medium text-muted-foreground`,children:a(`run.provider`)}),(0,H.jsx)(`select`,{"aria-label":a(`run.provider`),value:M,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,H.jsx)(`option`,{value:e,children:u(e)},e))})]}),P.length>0&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`label`,{className:`block text-[11px] font-medium text-muted-foreground`,children:a(`run.model`)}),te?(0,H.jsx)(N,{value:F,options:P,ariaLabel:a(`run.model`),testId:`run-model-select`,className:`w-full px-2 py-1 text-xs`,onCommit:e=>{_(e),y(d(M,e)??``)}}):(0,H.jsx)(`select`,{"aria-label":a(`run.model`),"data-testid":`run-model-select`,value:F,onChange:e=>{let t=e.target.value;_(t),y(d(M,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,H.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),re&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`label`,{className:`block text-[11px] font-medium text-muted-foreground`,children:a(`run.effort`)}),(0,H.jsx)(`select`,{"aria-label":a(`run.effort`),value:L,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:I.map(e=>(0,H.jsx)(`option`,{value:e,children:e},e))})]}),(0,H.jsxs)(S,{children:[(0,H.jsx)(k,{variant:`ghost`,onClick:n,children:a(`common:actions.cancel`)}),(0,H.jsxs)(k,{onClick:()=>{let e=s||t[0]?.id;e&&r({projectId:e,...b?{repositoryIds:b}:{},provider:A.length>1?M:void 0,model:P.length>0?F:void 0,effort:re?L:void 0})},disabled:t.length===0,children:[(0,H.jsx)(g,{className:`w-3.5 h-3.5 mr-1.5`}),a(`run.execute`)]})]})]})})})}function me({loop:e,projects:t,onClose:n,onConverted:r}){let{t:a}=i(`loops`),[o,s]=(0,V.useState)(``),[c,l]=(0,V.useState)(!1),[u,d]=(0,V.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 P.convert(e.id,m?.id)).loop)}catch(e){d(e instanceof F?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,H.jsx)(D,{open:!0,onOpenChange:e=>{!e&&!c&&n()},children:(0,H.jsxs)(E,{children:[(0,H.jsxs)(T,{children:[(0,H.jsx)(w,{children:a(`conversion.title`,{name:e.name})}),(0,H.jsx)(C,{children:a(`conversion.description`)})]}),f&&(0,H.jsxs)(`label`,{className:`flex flex-col gap-2 text-sm`,children:[a(`conversion.repository`),(0,H.jsxs)(`select`,{className:`rounded border border-border bg-background p-2`,value:o,onChange:e=>s(e.target.value),disabled:c,children:[(0,H.jsx)(`option`,{value:``,children:a(`conversion.selectRepository`)}),p.map(e=>(0,H.jsx)(`option`,{value:e.key,children:e.label},e.key))]})]}),u&&(0,H.jsx)(`p`,{role:`alert`,className:`whitespace-pre-wrap text-sm text-destructive`,children:u}),(0,H.jsxs)(S,{children:[(0,H.jsx)(k,{variant:`outline`,disabled:c,onClick:n,children:a(`common:actions.cancel`)}),(0,H.jsx)(k,{disabled:c||f&&!m,onClick:()=>void h(),children:a(c?`conversion.pending`:`conversion.submit`)})]})]})})}var K={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 q({status:e}){let{t}=i(`loops`);return(0,H.jsx)(`span`,{className:O(`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium ring-1 ring-inset`,K[e]),children:t(`status.${e}`)})}function he({onOpenBuilder:e,onWindowOpened:t}={}){let{t:n}=i(`loops`),a=r(),l=(0,V.useCallback)(e=>e.replace(/:/g,`_`),[]),u=(0,V.useCallback)((e,t)=>n(`catalog.${l(e)}.name`,{defaultValue:t}),[n,l]),d=(0,V.useCallback)((e,t)=>n(`catalog.${l(e)}.description`,{defaultValue:t}),[n,l]),[f,h]=(0,V.useState)([]),[g,x]=(0,V.useState)([]),[ee,A]=(0,V.useState)(!0),[j,N]=(0,V.useState)(null),[ne,R]=(0,V.useState)(null),[z,B]=(0,V.useState)(null),[U,W]=(0,V.useState)(null),[G,K]=(0,V.useState)(null),[q,he]=(0,V.useState)(new Set),J=`specrails-desktop:loop-template-filter`,ve=(()=>{try{let e=localStorage.getItem(J),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,V.useState)(ve.query),[X,be]=(0,V.useState)(ve.categories);(0,V.useEffect)(()=>{try{localStorage.setItem(J,JSON.stringify({query:Y,categories:X}))}catch{}},[Y,X]);let xe=(0,V.useCallback)(e=>{be(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),Se=(0,V.useCallback)(()=>{ye(``),be([])},[]),Ce=(0,V.useRef)(null),{projects:we,activeProjectId:Te,setActiveProjectId:Ee}=s(),De=(0,V.useCallback)(e=>{he(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Z=(0,V.useCallback)(e=>{if(e.length===0)return;let t=new Blob([JSON.stringify(ce(e),null,2)],{type:`application/json`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=ue(e),r.click(),URL.revokeObjectURL(n)},[]),Oe=(0,V.useCallback)(async e=>{try{let t=await P.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,V.useCallback)(async()=>{try{let[e,t]=await Promise.all([P.list(),P.templates()]);h(e),x(t)}catch{c.error(n(`errors.load`))}finally{A(!1)}},[n]);(0,V.useEffect)(()=>{Q()},[Q]);let ke=(0,V.useCallback)(async e=>{try{let t=le(await e.text()),{imported:r,skipped:i}=await P.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,V.useCallback)(t=>{e?e(t):a(`/loops/${t}/edit`)},[e,a]),Ae=(0,V.useCallback)(async()=>{try{let e=await P.create({name:n(`newLoopName`)});$(e.id)}catch{c.error(n(`errors.save`))}},[n,$]),je=(0,V.useCallback)(async e=>{try{let t=await P.fromTemplate(e);$(t.id)}catch{c.error(n(`errors.save`))}},[n,$]),Me=(0,V.useCallback)(async({projectId:e,provider:t,model:r,effort:i,repositoryIds:o})=>{let s=U;if(s){W(null);try{let{loopRunId:l}=await P.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`))}}},[U,a,Ee,n]),Ne=(0,V.useCallback)(async e=>{try{await P.publish(e),await Q()}catch(e){e instanceof F?c.error(n(`errors.publishInvalid`)):c.error(n(`errors.save`))}},[n,Q]),Pe=(0,V.useCallback)(async e=>{try{await P.unpublish(e),await Q()}catch{c.error(n(`errors.save`))}},[n,Q]),Fe=(0,V.useCallback)(async e=>{try{await P.duplicate(e),await Q()}catch{c.error(n(`errors.save`))}},[n,Q]),Ie=(0,V.useCallback)(async()=>{let e=z;if(e){B(null);try{await P.restoreBuiltin(e),await Q(),c.success(n(`builder.builtin.restored`))}catch{c.error(n(`errors.save`))}}},[z,n,Q]),Le=(0,V.useCallback)(e=>N(e),[]),Re=(0,V.useCallback)(async()=>{let e=j;if(e){N(null);try{await P.remove(e),await Q()}catch{c.error(n(`errors.save`))}}},[j,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=fe(g),We=de(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,H.jsxs)(`div`,{className:`h-full overflow-y-auto`,children:[(0,H.jsxs)(`div`,{className:`max-w-5xl mx-auto px-6 py-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-start justify-between mb-6`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,H.jsx)(I,{className:`w-5 h-5 text-accent-primary`}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h1`,{className:`text-lg font-semibold text-foreground`,children:n(`title`)}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:n(`subtitle`)})]})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!re()&&(0,H.jsxs)(`button`,{type:`button`,onClick:()=>void te(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,H.jsx)(m,{className:`w-3.5 h-3.5`}),n(`window.open`)]}),q.size>0&&(0,H.jsxs)(`button`,{type:`button`,onClick:()=>Z(f.filter(e=>q.has(e.id))),className:`inline-flex items-center gap-1.5 h-8 px-3 rounded-md text-xs font-medium border border-border text-foreground hover:bg-muted`,children:[(0,H.jsx)(ae,{className:`w-3.5 h-3.5`}),n(`actions.export`),` (`,q.size,`)`]}),(0,H.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,H.jsx)(oe,{className:`w-3.5 h-3.5`}),n(`actions.import`)]}),(0,H.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,H.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,H.jsx)(_,{className:`w-3.5 h-3.5`}),n(`newLoop`)]})]})]}),ee?(0,H.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`…`}):(0,H.jsxs)(`div`,{className:`space-y-8`,children:[Ve.length===0&&He.length===0&&(0,H.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-8 text-center`,children:[(0,H.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:n(`empty.title`)}),(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:n(`empty.body`)})]}),f.length>0&&(0,H.jsx)(se,{onConvert:e=>{let t=f.find(t=>t.id===e);t&&K(t)}}),He.length>0&&(0,H.jsx)(ge,{title:n(`sections.published`),children:He.map(e=>(0,H.jsx)(_e,{loop:e,selected:q.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:()=>K(e),onDelete:()=>Le(e.id),onRun:L(e.graph)?void 0:()=>W(e)},e.id))}),Ve.length>0&&(0,H.jsx)(ge,{title:n(`sections.drafts`),children:Ve.map(e=>(0,H.jsx)(_e,{loop:e,selected:q.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:()=>K(e),onDelete:()=>Le(e.id)},e.id))}),ze.length>0&&(0,H.jsx)(ge,{title:n(`sections.builtIn`),children:ze.map(e=>(0,H.jsx)(_e,{loop:{...e,name:e.builtinModified?e.name:u(e.id,e.name)},builtIn:!0,selected:q.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?()=>B(e.id):void 0},e.id))}),g.length>0&&(0,H.jsxs)(`section`,{children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3 mb-2 flex-wrap`,children:[(0,H.jsx)(`h2`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:n(`sections.templates`)}),(0,H.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,H.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,H.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,H.jsx)(`span`,{className:`opacity-60 tabular-nums`,children:t})]},e)}),Ge&&(0,H.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,H.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-6 text-center`,"data-testid":`template-empty`,children:[(0,H.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`gallery.noResults`)}),(0,H.jsx)(`button`,{type:`button`,onClick:Se,className:`mt-2 text-xs text-accent-primary hover:underline`,children:n(`gallery.clearFilter`)})]}):(0,H.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:We.map(e=>(0,H.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-3 flex flex-col gap-2`,"data-testid":`template-card`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(y,{className:`w-3.5 h-3.5 text-accent-highlight flex-shrink-0`}),(0,H.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate`,children:u(e.id,e.name)}),e.category&&(0,H.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,H.jsx)(`p`,{className:`text-xs text-muted-foreground flex-1`,children:d(e.id,e.description)}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[L(e.graph)?(0,H.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,H.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,H.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] bg-muted text-muted-foreground`,children:e},e))]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,H.jsxs)(`button`,{type:`button`,onClick:()=>R({...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,H.jsx)(M,{className:`w-3 h-3`}),n(`actions.preview`)]}),(0,H.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,H.jsx)(p,{className:`w-3 h-3`}),n(`actions.use`)]})]})]},e.id))})]})]})]}),(0,H.jsx)(D,{open:j!==null,onOpenChange:e=>{e||N(null)},children:(0,H.jsxs)(E,{className:`max-w-sm`,children:[(0,H.jsxs)(T,{children:[(0,H.jsxs)(w,{className:`flex items-center gap-2`,children:[(0,H.jsx)(b,{className:`w-4 h-4 text-destructive`}),f.find(e=>e.id===j)?.name??n(`actions.delete`)]}),(0,H.jsx)(C,{children:n(`confirmDelete`)})]}),(0,H.jsxs)(S,{children:[(0,H.jsx)(k,{variant:`ghost`,onClick:()=>N(null),children:n(`common:actions.cancel`)}),(0,H.jsx)(k,{variant:`destructive`,onClick:()=>void Re(),children:n(`common:actions.delete`)})]})]})}),(0,H.jsx)(D,{open:z!==null,onOpenChange:e=>{e||B(null)},children:(0,H.jsxs)(E,{className:`max-w-sm`,children:[(0,H.jsxs)(T,{children:[(0,H.jsxs)(w,{className:`flex items-center gap-2`,children:[(0,H.jsx)(v,{className:`w-4 h-4`}),n(`builder.builtin.confirmTitle`)]}),(0,H.jsx)(C,{children:n(`builder.builtin.confirmBody`)})]}),(0,H.jsxs)(S,{children:[(0,H.jsx)(k,{variant:`ghost`,onClick:()=>B(null),children:n(`common:actions.cancel`)}),(0,H.jsx)(k,{"data-testid":`confirm-restore-builtin`,onClick:()=>void Ie(),children:n(`actions.restoreBuiltin`)})]})]})}),(0,H.jsx)(ie,{template:ne,onClose:()=>R(null),onUse:e=>{R(null),je(e)}}),G&&(0,H.jsx)(me,{loop:G,projects:we,onClose:()=>K(null),onConverted:e=>{h(t=>t.map(t=>t.id===e.id?e:t)),K(null),$(e.id)}},G.id),(0,H.jsx)(pe,{loop:U?{id:U.id,name:U.name}:null,projects:we.map(e=>({id:e.id,name:e.name,providers:o(e),repositories:e.repositories})),onClose:()=>W(null),onExecute:Me})]})}function ge({title:e,children:t}){return(0,H.jsxs)(`section`,{children:[(0,H.jsx)(`h2`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2`,children:e}),(0,H.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:t})]})}function _e({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,H.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,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,H.jsx)(`input`,{type:`checkbox`,checked:n,onChange:r,"aria-label":y(`actions.select`,{name:e.name}),className:`accent-accent-primary flex-shrink-0`}),(0,H.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate`,children:e.name})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[t&&(0,H.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,H.jsx)(q,{status:e.status})]})]}),(0,H.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[y(`card.nodes`,{count:S}),t&&e.builtinModified&&(0,H.jsxs)(`span`,{className:`ml-1.5 text-accent-secondary`,children:[`· `,y(`card.builtinModified`)]})]}),(0,H.jsxs)(`div`,{className:`flex items-center gap-1 flex-wrap`,children:[m&&(0,H.jsx)(J,{icon:g,label:y(`actions.run`),onClick:m}),(0,H.jsx)(J,{icon:h,label:y(`actions.edit`),onClick:a}),o&&(0,H.jsx)(J,{icon:x,label:y(`actions.publish`),onClick:o}),s&&(0,H.jsx)(J,{icon:p,label:y(`actions.unpublish`),onClick:s}),(0,H.jsx)(J,{icon:A,label:y(`actions.duplicate`),onClick:c}),(0,H.jsx)(J,{icon:ae,label:y(`actions.export`),onClick:l}),u&&(0,H.jsx)(J,{icon:ae,label:y(`actions.exportLegacy`),onClick:u}),d&&(0,H.jsx)(J,{icon:I,label:y(`actions.convert`),onClick:d}),_&&(0,H.jsx)(J,{icon:v,label:y(`actions.restoreBuiltin`),onClick:_}),f&&(0,H.jsx)(J,{icon:b,label:y(`actions.delete`),onClick:f,danger:!0})]})]})}function J({icon:e,label:t,onClick:n,danger:r}){return(0,H.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,H.jsx)(e,{className:`w-3.5 h-3.5`})})}export{he as default};
@@ -0,0 +1 @@
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-BbYvbtY8.js";import{t as r}from"./react-dom-DDD8FYaU.js";import{u as i}from"./chunk-OB3PAWPO-B1EMk45A.js";import{r as a}from"./useSharedWebSocket-CcsE5986.js";import{n as o,t as s}from"./createLucideIcon-DtODIU64.js";import{r as c}from"./useDesktop-C0mRIlHT.js";import{t as l}from"./chevron-up-6EFqEHBj.js";import{t as u}from"./sparkles-CCfUdFGY.js";import{t as d}from"./x-Bu7X_eR2.js";var f={name:`arrow-up`,size:24,node:[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]};f.node;var p=s(f),m={name:`messages-square`,size:24,node:[[`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`}]]};m.node;var h=s(m),g=e(t(),1),_=[`title`,`description`,`labels`,`priority`,`acceptanceCriteria`,`repositoryIds`],v={title:``,description:``,labels:[],priority:`medium`,acceptanceCriteria:[]};function y(e){return!e||typeof e!=`object`?!1:e.type===`spec_draft.update`}var b=e(r(),1),x=n(),S=42;function C(e){let t=e.replace(/\s+/g,` `).trim();return t.length<=S?t:t.slice(0,S-1).trimEnd()+`…`}function w({chat:e,projectName:t,onRestore:n,onClose:r}){let{t:i}=o(`chat`),a=C(e.label);return(0,x.jsxs)(`div`,{"data-testid":`minimized-chat-chip-${e.id}`,className:`grid items-start gap-2 w-full max-w-full`,style:{gridTemplateColumns:`auto minmax(0, 1fr) auto`},children:[(0,x.jsx)(T,{kind:e.kind}),(0,x.jsxs)(`button`,{type:`button`,onClick:n,className:`min-w-0 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary/50 rounded overflow-hidden`,"aria-label":i(`chip.restore`,{label:e.label}),title:e.label,children:[(0,x.jsx)(`div`,{className:`text-sm font-medium text-foreground truncate`,children:a}),(0,x.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5 truncate`,children:i(`chip.continueEditing`,{projectName:t})})]}),(0,x.jsx)(`button`,{type:`button`,onClick:r,className:`flex items-center justify-center w-6 h-6 rounded text-muted-foreground hover:text-foreground hover:bg-accent/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary/50`,"aria-label":i(`chip.close`,{label:e.label}),children:(0,x.jsx)(d,{className:`w-3.5 h-3.5`})})]})}function T({kind:e}){let{t}=o(`chat`);return(0,x.jsx)(e===`ai-edit`?u:h,{className:`w-4 h-4 text-accent-primary flex-shrink-0 mt-0.5`,"aria-label":t(e===`ai-edit`?`chip.kindAiEdit`:`chip.kindExploreSpec`)})}function E({chats:e,projects:t,hidden:n,onRestore:r,onClose:i}){let{t:a}=o(`chat`),s=(0,g.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.id,n.name);return e},[t]),c=(0,g.useMemo)(()=>[...e].sort((e,t)=>t.createdAt-e.createdAt),[e]);return n||c.length===0?null:(0,b.createPortal)((0,x.jsxs)(`div`,{"data-testid":`minimized-chats-dock`,"aria-label":a(`dock.minimizedSessions`,{count:c.length}),className:`fixed bottom-4 right-14 z-[70] flex flex-col-reverse gap-2 w-[320px] max-w-[calc(100vw-15rem)] max-h-[70vh] overflow-y-auto pointer-events-none`,children:[c.map(e=>(0,x.jsx)(`div`,{className:`pointer-events-auto glass-card border border-border/30 rounded-lg p-3 shadow-lg w-full`,children:(0,x.jsx)(w,{chat:e,projectName:s.get(e.projectId)??a(`dock.unknownProject`),onRestore:()=>r(e.id),onClose:()=>i(e.id)})},e.id)),c.length>1&&(0,x.jsxs)(`div`,{className:`pointer-events-auto self-end inline-flex items-center gap-1 rounded-full bg-card/80 border border-border/40 px-2 py-0.5 text-[10px] text-muted-foreground backdrop-blur-sm`,children:[(0,x.jsx)(l,{className:`w-3 h-3`}),a(`dock.minimizedCount`,{count:c.length})]})]}),document.body)}var D=(0,g.createContext)(null),O=`specrails-desktop:minimized-chats`,k=`specrails-desktop:minimized-chats-pending`,A=50,j=8e3;function M(){return I(O)}function N(e){R(O,e)}function P(){return I(k)}function F(e){R(k,e)}function I(e){if(typeof window>`u`)return[];try{let t=window.localStorage.getItem(e);if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(z):[]}catch{return[]}}function L(e){return e.length<=A?e:[...e].sort((e,t)=>e.createdAt-t.createdAt).slice(e.length-A)}function R(e,t){if(!(typeof window>`u`))try{window.localStorage.setItem(e,JSON.stringify(L(t)))}catch{}}function z(e){if(!e||typeof e!=`object`)return!1;let t=e;return!(typeof t.id!=`string`||typeof t.projectId!=`string`||typeof t.label!=`string`||typeof t.restoreRoute!=`string`||typeof t.createdAt!=`number`||t.kind!==`explore-spec`&&t.kind!==`ai-edit`||!t.params||typeof t.params!=`object`)}function B(){return typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function V(e){return e.kind===`explore-spec`?e.params.resumeConversationId??`pending:${e.params.pendingSpecId}`:e.params.resumeRefineId??`agent:${e.params.agentId}`}function H(e,t){return e.kind!==t.kind||e.projectId!==t.projectId?!1:V(e)===V(t)}function U({children:e}){let{projects:t,activeProjectId:n,setActiveProjectId:r}=c(),o=i(),{registerHandler:s,unregisterHandler:l}=a(),[u,d]=(0,g.useState)(()=>M()),[f,p]=(0,g.useState)([]),m=(0,g.useRef)(u);m.current=u;let h=(0,g.useRef)(f);h.current=f;let _=(0,g.useRef)(new Map),v=(0,g.useRef)(t);v.current=t;let b=(0,g.useRef)(!1);(0,g.useEffect)(()=>{if(b.current)return;b.current=!0;let e=P();F([]),e.length!==0&&d(t=>{let n=[...t];for(let t of e)n.some(e=>e.id===t.id||H(e,t))||n.push(t);return N(n),m.current=n,n})},[]),(0,g.useEffect)(()=>{let e=_.current;return()=>{for(let t of e.values())clearTimeout(t);e.clear()}},[]),(0,g.useEffect)(()=>{N(u)},[u]),(0,g.useEffect)(()=>{F(f)},[f]);let S=(0,g.useRef)(()=>{}),C=(0,g.useRef)(()=>{});(0,g.useEffect)(()=>{let e=`minimized-chats:spec-draft`;return s(e,e=>{if(!y(e))return;let t=e.conversationId,n=m.current.find(e=>e.kind===`explore-spec`&&e.params.resumeConversationId===t);if(!n)return;let r=e.draft;r.title?.trim()&&S.current(n.id,r.title);let i={};r.title!==void 0&&(i.title=r.title),r.description!==void 0&&(i.description=r.description),r.priority!==void 0&&(i.priority=r.priority),r.labels!==void 0&&(i.labels=r.labels),r.repositoryIds!==void 0&&(i.repositoryIds=r.repositoryIds),r.acceptanceCriteria!==void 0&&(i.acceptanceCriteria=r.acceptanceCriteria),Object.keys(i).length>0&&C.current(n.id,i)}),()=>l(e)},[s,l]),(0,g.useEffect)(()=>{if(t.length===0)return;let e=new Set(t.map(e=>e.id));d(t=>{let n=t.filter(t=>e.has(t.projectId));return n.length===t.length?t:(N(n),m.current=n,n)}),p(t=>{let n=t.filter(t=>e.has(t.projectId));return n.length===t.length?t:(F(n),h.current=n,n)})},[t]);let w=(0,g.useCallback)(e=>{let t=B(),n={...e,id:t,createdAt:Date.now()};if(d(e=>{let t=L([...e.filter(e=>!H(e,n)),n]);return N(t),m.current=t,t}),e.kind===`explore-spec`){let t=e.params.resumeConversationId;t&&fetch(`/api/projects/${e.projectId}/chat/conversations/${t}/minimize`,{method:`POST`}).catch(()=>{})}return t},[]),T=(0,g.useCallback)(e=>{let t=_.current.get(e);t&&(clearTimeout(t),_.current.delete(e))},[]),O=(0,g.useCallback)(e=>{T(e),d(t=>{let n=t.filter(t=>t.id!==e);return N(n),m.current=n,n}),p(t=>{let n=t.filter(t=>t.id!==e);return n.length===t.length?t:(F(n),h.current=n,n)})},[T]),k=(0,g.useCallback)((e,t)=>{let n=t.trim();n&&d(t=>{let r=t.map(t=>t.id===e&&t.label!==n?{...t,label:n}:t);return r===t?t:(m.current=r,r)})},[]),A=(0,g.useCallback)((e,t)=>{d(n=>{let r=n.map(n=>{if(n.id!==e||n.kind!==`explore-spec`)return n;let r={...n.params.draftOverrides??{},...t};return{...n,params:{...n.params,draftOverrides:r}}});return m.current=r,r})},[]),I=(0,g.useCallback)(e=>{let t=m.current.find(t=>t.id===e);if(!t||v.current.length>0&&!v.current.some(e=>e.id===t.projectId))return;if(t.kind===`explore-spec`){let e=t.params.resumeConversationId;e&&fetch(`/api/projects/${t.projectId}/chat/conversations/${e}/restore`,{method:`POST`}).catch(()=>{})}n!==t.projectId&&r(t.projectId),o(t.restoreRoute),p(n=>{let r=[...n.filter(t=>t.id!==e),t];return F(r),h.current=r,r}),d(t=>{let n=t.filter(t=>t.id!==e);return N(n),m.current=n,n}),T(e);let i=setTimeout(()=>{_.current.delete(e),h.current.some(t=>t.id===e)&&(p(t=>{let n=t.filter(t=>t.id!==e);return F(n),h.current=n,n}),d(n=>{if(n.some(n=>n.id===e||H(n,t)))return n;let r=[...n,t];return N(r),m.current=r,r}))},j);_.current.set(e,i)},[n,r,o,T]),R=(0,g.useRef)(I);R.current=I;let z=(0,g.useRef)(O);z.current=O,S.current=k,C.current=A;let V=(0,g.useCallback)((e,t)=>{let n=h.current,r=n.findIndex(n=>n.kind===e&&n.projectId===t);if(r===-1)return null;let i=n[r];return T(i.id),p(e=>{let t=e.filter(e=>e.id!==i.id);return F(t),t}),h.current=n.filter(e=>e.id!==i.id),i},[T]),U=(0,g.useCallback)(e=>{let t=B(),i={...e,id:t,createdAt:Date.now()};n!==e.projectId&&r(e.projectId),o(e.restoreRoute),p(e=>{let t=[...e,i];return F(t),h.current=t,t}),T(t);let a=setTimeout(()=>{_.current.delete(t),h.current.some(e=>e.id===t)&&(p(e=>{let n=e.filter(e=>e.id!==t);return F(n),h.current=n,n}),d(e=>{if(e.some(e=>e.id===t||H(e,i)))return e;let n=[...e,i];return N(n),m.current=n,n}))},j);_.current.set(t,a)},[n,r,o,T]),W=(0,g.useMemo)(()=>({chats:u,pendingRestores:f,minimize:w,updateLabel:k,patchExploreSpecDraft:A,close:O,restore:I,takePendingRestore:V,triggerResume:U}),[u,f,w,k,A,O,I,V,U]);return(0,x.jsxs)(D.Provider,{value:W,children:[e,(0,x.jsx)(E,{chats:u,projects:t,hidden:!1,onRestore:I,onClose:O})]})}function W(){return(0,g.useContext)(D)||{chats:[],pendingRestores:[],minimize:()=>``,updateLabel:()=>{},patchExploreSpecDraft:()=>{},close:()=>{},restore:()=>{},takePendingRestore:()=>null,triggerResume:()=>{}}}function G(e,t,n){let{pendingRestores:r,takePendingRestore:i}=W(),a=(0,g.useRef)(n);a.current=n,(0,g.useEffect)(()=>{if(!t)return;let n=i(e,t);n&&a.current(n)},[r,e,t,i])}export{_ as a,p as c,v as i,W as n,y as o,G as r,h as s,U as t};
@@ -0,0 +1,2 @@
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-BbYvbtY8.js";import{l as r,r as i,t as a}from"./useSharedWebSocket-CcsE5986.js";import{n as o,t as s}from"./createLucideIcon-DtODIU64.js";import{n as c,r as l,s as u}from"./useDesktop-C0mRIlHT.js";import{s as d}from"./provider-capabilities-lePfeT_Y.js";import{t as f}from"./download-C9wP_42h.js";import{t as p}from"./external-link-CZ6Q-v1-.js";import{t as m}from"./loader-circle-BqV9xYGf.js";import{t as h}from"./search-BDVp3fkH.js";import{t as g}from"./trash-D8zYUmTg.js";import{t as _}from"./triangle-alert-Cxpn8bqr.js";import{n as v,t as y}from"./jira-api-C_D_RDhl.js";import{i as b,l as x,o as S,r as C,t as w}from"./dialog-DtdR05v1.js";import{t as T}from"./utils-BC4DHlz2.js";import{t as E}from"./button-4FS1ZDTp.js";import{Ct as D,Jt as O,Ot as k,W as A,Zt as j,bt as M,kt as N,ln as ee,un as te,xt as ne,yt as re}from"./index-CECj3joE.js";var P={name:`earth`,size:24,node:[[`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`}]],aliases:[`globe-2`]};P.node;var ie=s(P),F={name:`folder-kanban`,size:24,node:[[`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`}]]};F.node;var ae=s(F),I={name:`power`,size:24,node:[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]};I.node;var L=s(I),R=e(t(),1),z=n(),B=[`todo`,`in_progress`,`on_review`,`done`,`cancelled`],oe={todo:`todo`,in_progress:`inProgress`,on_review:`onReview`,done:`done`,cancelled:`cancelled`};function V(e){let{activeProjectId:t}=l();return(0,z.jsx)(H,{...e},e.apiBase??t??`legacy`)}function H({onConnected:e,onSkip:t,apiBase:n}){let{t:r}=o(`jira`),[i,a]=(0,R.useState)(1),[s,c]=(0,R.useState)(``),[l,d]=(0,R.useState)(``),[f,p]=(0,R.useState)(``),[m,h]=(0,R.useState)(`idle`),[g,_]=(0,R.useState)(null),[v,b]=(0,R.useState)(`cloud`),[x,S]=(0,R.useState)([]),[C,w]=(0,R.useState)(``),[T,D]=(0,R.useState)(``),[O,k]=(0,R.useState)(``),[j,M]=(0,R.useState)(!1),[N,ee]=(0,R.useState)([]),[te,ne]=(0,R.useState)({}),[re,P]=(0,R.useState)(``),[ie,F]=(0,R.useState)(!1),[ae,I]=(0,R.useState)(!1),L=(0,R.useRef)(0),V=(0,R.useRef)(!0);(0,R.useEffect)(()=>(V.current=!0,()=>{V.current=!1,L.current++}),[]);let[H,se]=(0,R.useState)(!1),K=()=>({baseUrl:s.trim(),accountEmail:l.trim()||null,token:f});async function ce(){h(`testing`);try{let e=await y.test(K(),n);if(!V.current)return;h(`ok`),_(e.displayName),b(e.deployment)}catch(e){if(!V.current)return;h(`error`),u.error(G(e,r))}}async function q(){a(2),M(!0);try{let{projects:e}=await y.discoverProjects({...K(),query:C.trim()||void 0},n);if(!V.current)return;S(e)}catch(e){V.current&&u.error(G(e,r))}finally{V.current&&M(!1)}}async function le(){a(3),await J()}async function J(){if(!T)return;let e=++L.current;F(!0);try{let{statuses:t}=await y.discoverStatuses({...K(),projectKey:T},n);if(!V.current||e!==L.current)return;ee(t),I(!1)}catch{V.current&&e===L.current&&I(!0)}finally{V.current&&e===L.current&&F(!1)}}function ue(e,t){e!==T&&(L.current++,ee([]),ne({}),P(``),I(!1),F(!1)),D(e),k(t)}async function Y(){se(!0);try{let t=Object.fromEntries(Object.entries(te).filter(([,e])=>e));if(await y.connect({...K(),jiraProjectKey:T.trim(),statusMap:Object.keys(t).length?t:null,discardStatus:re.trim()||null},n),!V.current)return;u.success(r(`status.connected`,{key:T.trim()})),e()}catch(e){V.current&&u.error(G(e,r))}finally{V.current&&se(!1)}}return(0,z.jsxs)(`div`,{className:`space-y-4`,"data-testid":`jira-wizard`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`wizard.step`,{current:i,total:4})}),t&&(0,z.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,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step1Title`)}),(0,z.jsx)(U,{label:r(`creds.baseUrlLabel`),help:r(`creds.baseUrlHelp`),children:(0,z.jsx)(A,{value:s,onChange:e=>{c(e.target.value),h(`idle`)},placeholder:r(`creds.baseUrlPlaceholder`)})}),(0,z.jsx)(U,{label:r(`creds.emailLabel`),help:r(`creds.emailHelp`),children:(0,z.jsx)(A,{value:l,onChange:e=>{d(e.target.value),h(`idle`)},placeholder:r(`creds.emailPlaceholder`)})}),(0,z.jsx)(U,{label:r(`creds.tokenLabel`),help:r(`creds.tokenHelp`),children:(0,z.jsx)(A,{type:`password`,value:f,onChange:e=>{p(e.target.value),h(`idle`)}})}),(0,z.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,z.jsx)(E,{size:`sm`,variant:`outline`,onClick:ce,disabled:!s.trim()||!f.trim()||m===`testing`,children:r(m===`testing`?`creds.testing`:m===`ok`?`creds.retest`:`creds.test`)}),m===`ok`&&(0,z.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,z.jsx)(`div`,{className:`flex justify-end`,children:(0,z.jsx)(E,{size:`sm`,onClick:q,disabled:m!==`ok`,children:r(`wizard.next`)})})]}),i===2&&(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step2Title`)}),(0,z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,z.jsx)(A,{value:C,onChange:e=>w(e.target.value),placeholder:r(`project.searchPlaceholder`)}),(0,z.jsx)(E,{size:`sm`,variant:`outline`,onClick:q,children:r(`project.searchPlaceholder`)})]}),j?(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`project.loading`)}):x.length===0?(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`project.none`)}):(0,z.jsx)(`div`,{className:`max-h-48 space-y-1 overflow-y-auto`,"data-testid":`jira-project-list`,children:x.map(e=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>ue(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,z.jsx)(`span`,{className:`font-medium`,children:e.key}),(0,z.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.name})]},e.id))}),(0,z.jsx)(U,{label:r(`project.manualLabel`),children:(0,z.jsx)(A,{value:T,onChange:e=>ue(e.target.value.toUpperCase(),``),placeholder:r(`project.manualPlaceholder`)})}),(0,z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,z.jsx)(E,{size:`sm`,variant:`ghost`,onClick:()=>a(1),children:r(`wizard.back`)}),(0,z.jsx)(E,{size:`sm`,onClick:le,disabled:!T.trim(),children:r(`wizard.next`)})]})]}),i===3&&(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step3Title`)}),(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`mapping.intro`)}),ae&&(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,z.jsx)(`p`,{role:`alert`,className:`text-xs text-accent-warning`,children:r(`mapping.loadFailed`)}),(0,z.jsx)(E,{size:`sm`,variant:`outline`,disabled:ie,onClick:()=>void J(),children:r(`mapping.retry`)})]}),ie&&(0,z.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground`,children:r(`mapping.loading`)}),B.map(e=>(0,z.jsx)(U,{label:r(`mapping.${oe[e]}`),children:(0,z.jsxs)(`select`,{value:te[e]??``,onChange:t=>ne(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,z.jsx)(`option`,{value:``,children:r(`mapping.auto`)}),N.map(e=>(0,z.jsx)(`option`,{value:e.name,children:e.name},e.id))]})},e)),(0,z.jsx)(U,{label:r(`discard.configLabel`),help:r(`discard.configHelp`),children:(0,z.jsxs)(`select`,{value:re,onChange:e=>P(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,z.jsx)(`option`,{value:``,children:r(`discard.configNone`)}),N.map(e=>(0,z.jsx)(`option`,{value:e.name,children:e.name},e.id))]})}),(0,z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,z.jsx)(E,{size:`sm`,variant:`ghost`,onClick:()=>a(2),children:r(`wizard.back`)}),(0,z.jsx)(E,{size:`sm`,onClick:()=>a(4),children:r(`wizard.next`)})]})]}),i===4&&(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step4Title`)}),(0,z.jsxs)(`dl`,{className:`space-y-1 text-sm`,children:[(0,z.jsx)(W,{label:r(`review.site`),value:s}),(0,z.jsx)(W,{label:r(`review.project`),value:O?`${T} — ${O}`:T}),(0,z.jsx)(W,{label:r(`review.account`),value:g??l}),(0,z.jsx)(W,{label:r(`review.type`),value:r(v===`cloud`?`review.cloud`:`review.dc`)}),(0,z.jsx)(W,{label:r(`discard.reviewLabel`),value:re||r(`discard.configNone`)})]}),(0,z.jsxs)(`div`,{className:`flex justify-between`,children:[(0,z.jsx)(E,{size:`sm`,variant:`ghost`,onClick:()=>a(3),children:r(`wizard.back`)}),(0,z.jsx)(E,{size:`sm`,onClick:Y,disabled:H,children:r(H?`wizard.connecting`:`wizard.connect`)})]})]})]})}function U({label:e,help:t,children:n}){return(0,z.jsxs)(`label`,{className:`block space-y-1`,children:[(0,z.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:e}),n,t&&(0,z.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:t})]})}function W({label:e,value:t}){return(0,z.jsxs)(`div`,{className:`flex justify-between gap-4`,children:[(0,z.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),(0,z.jsx)(`dd`,{className:`truncate text-right font-medium`,children:t})]})}function G(e,t){return e instanceof Error?e.message:t(`errors.generic`)}var se={pending:0,inflight:0,done:0,dead:0};function K({projectId:e,baseUrl:t,apiBase:n,initialCounts:r,refreshToken:i}){let{t:s}=o(`jira`),[c,l]=(0,R.useState)(null),[d,f]=(0,R.useState)(!1),[p,m]=(0,R.useState)(()=>new Set),h=(0,R.useRef)(!0),g=(0,R.useRef)(0),_=(0,R.useContext)(a),v=(0,R.useId)(),b=(0,R.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,R.useEffect)(()=>(h.current=!0,b(),()=>{h.current=!1,g.current++}),[b,i,r?.dead,r?.pending,r?.inflight,r?.done,r?.superseded]),(0,R.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??se,C=S.pending+S.inflight;return(0,z.jsxs)(`div`,{className:`rounded-md border border-border p-3`,"data-testid":`jira-outbox`,children:[(0,z.jsx)(`p`,{className:`text-sm font-medium`,children:s(`outbox.title`)}),(0,z.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,z.jsxs)(`div`,{className:`mt-2 flex items-center justify-between gap-2`,children:[(0,z.jsx)(`p`,{role:`alert`,className:`text-xs text-accent-warning`,children:s(`outbox.loadFailed`)}),(0,z.jsx)(E,{variant:`outline`,size:`sm`,onClick:()=>void b(),children:s(`outbox.retry`)})]}),!!c?.ops.length&&(0,z.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:s(`outbox.deadHelp`)}),c.ops.map(e=>{let n=e.targetStatus||(e.logicalState?s(`mapping.${ce(e.logicalState)}`):null),r=e.deadReason??e.lastError??``;return(0,z.jsxs)(`div`,{className:`flex items-start justify-between gap-2 rounded border border-border/60 px-2 py-2`,children:[(0,z.jsxs)(`div`,{className:`min-w-0 space-y-1 text-xs`,children:[(0,z.jsxs)(`p`,{className:`break-words`,children:[e.jiraKey?(0,z.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,z.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,z.jsx)(`p`,{className:`break-words text-muted-foreground`,children:s(`outbox.target`,{status:n})}),(0,z.jsx)(`p`,{className:`max-h-32 overflow-y-auto whitespace-pre-wrap break-words text-muted-foreground`,children:r})]}),(0,z.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 ce(e){return e===`in_progress`?`inProgress`:e===`on_review`?`onReview`:e}var q=[`todo`,`in_progress`,`on_review`,`done`,`cancelled`],le={todo:`todo`,in_progress:`inProgress`,on_review:`onReview`,done:`done`,cancelled:`cancelled`};function J(e){let{activeProjectId:t}=l(),n=`${e.apiBase??t??``}:${e.state.connection.projectId}`;return(0,z.jsx)(ue,{...e},n)}function ue({state:e,onChanged:t,apiBase:n}){let{t:r}=o(`jira`),i=e.connection,[a,s]=(0,R.useState)(i.enabled),[c,l]=(0,R.useState)(!1),[d,f]=(0,R.useState)(!1),[p,m]=(0,R.useState)(0),[h,g]=(0,R.useState)([]),[_,v]=(0,R.useState)(i.discardStatus??``),[b,x]=(0,R.useState)(i.statusMap??{}),[S,C]=(0,R.useState)(!1),[w,T]=(0,R.useState)(!1),D=(0,R.useRef)(0),O=(0,R.useRef)(!0),k=(0,R.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,R.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(Y(e,r))}}async function j(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(Y(e,r))}}async function M(){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(Y(t,r))}finally{O.current&&f(!1)}}async function N(){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(Y(e,r))}finally{O.current&&l(!1)}}async function ee(){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(Y(e,r))}finally{O.current&&f(!1)}}}return(0,z.jsxs)(`div`,{className:`space-y-4`,"data-testid":`jira-connected`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:r(`status.connected`,{key:i.jiraProjectKey})}),(0,z.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[i.baseUrl,` · `,i.deployment===`cloud`?r(`review.cloud`):r(`review.dc`)]})]}),(0,z.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,z.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border border-border p-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`p`,{className:`text-sm font-medium`,children:r(`status.enabledLabel`)}),(0,z.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(a?`status.enabledHelp`:`status.pausedHelp`)})]}),(0,z.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":a,"aria-label":r(`status.enabledLabel`),disabled:d,onClick:M,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,z.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,z.jsxs)(`div`,{className:`rounded-md border border-border p-3`,"data-testid":`jira-status-map`,children:[(0,z.jsx)(`p`,{className:`text-sm font-medium`,children:r(`wizard.step3Title`)}),(0,z.jsx)(`p`,{className:`mt-0.5 mb-2 text-xs text-muted-foreground`,children:r(`mapping.intro`)}),S&&(0,z.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,z.jsx)(`p`,{role:`alert`,className:`text-xs text-accent-warning`,children:r(`mapping.loadFailed`)}),(0,z.jsx)(E,{variant:`outline`,size:`sm`,disabled:w,onClick:()=>void k(),children:r(`mapping.retry`)})]}),w&&(0,z.jsx)(`p`,{role:`status`,className:`mb-2 text-xs text-muted-foreground`,children:r(`mapping.loading`)}),(0,z.jsx)(`div`,{className:`space-y-2`,children:q.map(e=>(0,z.jsxs)(`label`,{className:`flex items-center justify-between gap-3`,children:[(0,z.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r(`mapping.${le[e]}`)}),(0,z.jsxs)(`select`,{value:b[e]??``,onChange:t=>void j(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,z.jsx)(`option`,{value:``,children:r(`mapping.auto`)}),h.map(e=>(0,z.jsx)(`option`,{value:e.name,children:e.name},e.id)),b[e]&&!h.some(t=>t.name===b[e])&&(0,z.jsx)(`option`,{value:b[e],children:b[e]})]})]},e))})]}),(0,z.jsxs)(`div`,{className:`rounded-md border border-border p-3`,children:[(0,z.jsx)(`p`,{className:`text-sm font-medium`,children:r(`discard.configLabel`)}),(0,z.jsx)(`p`,{className:`mt-0.5 mb-2 text-xs text-muted-foreground`,children:r(`discard.configHelp`)}),(0,z.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,z.jsx)(`option`,{value:``,children:r(`discard.configNone`)}),h.map(e=>(0,z.jsx)(`option`,{value:e.name,children:e.name},e.id)),_&&!h.some(e=>e.name===_)&&(0,z.jsx)(`option`,{value:_,children:_})]})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,z.jsx)(E,{variant:`outline`,size:`sm`,onClick:N,disabled:c,children:r(c?`status.syncing`:`status.syncNow`)}),(0,z.jsx)(E,{variant:`ghost`,size:`sm`,onClick:ee,disabled:d,className:`text-destructive`,children:r(`status.disconnect`)})]}),(0,z.jsx)(K,{projectId:i.projectId,baseUrl:i.baseUrl,apiBase:n,initialCounts:e.outbox,refreshToken:p})]})}function Y(e,t){return e instanceof Error?e.message:t(`errors.generic`)}var de=new Set([`claude`,`codex`,`kimi`]);function fe(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 pe(){return{updatedAt:null,proxyStatsAvailable:!1,durableSavingsAvailable:!1,outputSavingsAvailable:!1,outputSavingsMethod:null,outputConfidence:null,providers:{codex:fe(`codex`),claude:fe(`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:pe(),lastIssue:null,updatedAt:null};function me(e){let t=e?.metrics??pe();return{...X,...e,activeProviders:{...X.activeProviders,...e?.activeProviders},availableProviders:{...X.availableProviders,...e?.availableProviders},detectedRoutes:{...X.detectedRoutes,...e?.detectedRoutes},learning:{...X.learning,...e?.learning},metrics:{...pe(),...t,providers:{codex:{...fe(`codex`),...t.providers?.codex},claude:{...fe(`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 he(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`${he(e,t)} ${n}`}function ge({onWindowOpened:e}={}){let{t}=o(`integrations`),{projects:n}=l(),{registerHandler:a,unregisterHandler:s}=i(),[c,d]=(0,R.useState)(``),[f,m]=(0,R.useState)(`all`),[g,_]=(0,R.useState)(X),[v,y]=(0,R.useState)(!0),[E,D]=(0,R.useState)(null),[O,A]=(0,R.useState)([]),[j,P]=(0,R.useState)(!1),[ie,F]=(0,R.useState)(!1),[I,L]=(0,R.useState)(null),[B,oe]=(0,R.useState)({jira:0,serena:0,projects:0}),V=(0,R.useCallback)(async()=>{try{let e=await fetch(`${r}/api/global-plugins/headroom`).then(e=>Z(e));_(me(e.state))}finally{y(!1)}},[]);(0,R.useEffect)(()=>{V()},[V]),(0,R.useEffect)(()=>(a(`plugins-page`,e=>{let t=e;t.type===`plugin.headroom_progress`&&(t.line&&A(e=>[...e.slice(-80),t.line]),V())}),()=>s(`plugins-page`)),[a,s,V]),(0,R.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||oe({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 H(e,t){D(e),A([]);try{let e=(await t()).state;e&&_(me(e))}catch(e){let t=e.payload;t?.state&&_(me(t.state))}finally{D(null),V()}}let U=(0,R.useMemo)(()=>[{id:`headroom-ai`,title:`Headroom AI`,scope:`global`,icon:N,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){P(!0);return}H(`install`,()=>fetch(`${r}/api/global-plugins/headroom/install`,{method:`POST`}).then(e=>Z(e)))}}],[g,E,t]),W=(0,R.useMemo)(()=>[{id:`jira`,title:`Jira`,scope:`project`,icon:ae,description:t(`plugins.catalog.jira.description`),installed:B.jira>0,status:B.jira>0?`configured`:`available`,statusLabel:B.jira>0?t(`plugins.status.configuredCount`,{count:B.jira}):t(`plugins.status.available`),actionKind:B.jira>0?`manage`:`install`,actionLabel:B.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:B.serena>0,status:B.serena>0?`installed`:`available`,statusLabel:B.serena>0?t(`plugins.status.installedCount`,{count:B.serena}):t(`plugins.status.available`),actionKind:B.serena>0?`manage`:`install`,actionLabel:B.serena>0?t(`plugins.actions.manage`):t(`plugins.actions.install`),action:()=>L(`serena`)}],[B,t]),G=c.trim().toLowerCase(),se=e=>`${e.title} ${e.description} ${e.statusLabel} ${t(`plugins.scope.${e.scope}`)}`.toLowerCase().includes(G),K=[...U,...W].filter(e=>f!==`all`&&e.scope!==f?!1:se(e)),ce=K.filter(e=>e.scope===`global`&&e.installed),q=K.filter(e=>e.scope===`project`&&e.installed),le=K.filter(e=>e.scope===`global`&&!e.installed),J=K.filter(e=>e.scope===`project`&&!e.installed),ue=ce.length>0||q.length>0,Y=le.length>0||J.length>0,de=[g.installed,B.jira>0,B.serena>0].filter(Boolean).length;return(0,z.jsxs)(`div`,{className:`flex h-full flex-col bg-background`,children:[(0,z.jsxs)(`div`,{className:`border-b border-border px-6 py-4`,children:[(0,z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,z.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,z.jsx)(k,{className:`h-4 w-4`})}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`h1`,{className:`text-lg font-semibold tracking-normal`,children:t(`plugins.page.title`)}),(0,z.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:t(`plugins.page.subtitle`)})]}),!ee()&&(0,z.jsxs)(`button`,{type:`button`,onClick:()=>void te().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,z.jsx)(p,{className:`h-3.5 w-3.5`}),t(`plugins.page.openWindow`)]}),(0,z.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,z.jsx)(ne,{className:`h-3.5 w-3.5 text-accent-success`}),(0,z.jsx)(`span`,{className:`text-muted-foreground`,children:t(`plugins.page.readyCount`,{count:de})})]})]}),(0,z.jsxs)(`div`,{className:`mt-4 flex flex-col gap-3 md:flex-row md:items-center`,children:[(0,z.jsxs)(`label`,{className:`relative flex-1`,children:[(0,z.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,z.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,z.jsx)(`div`,{className:`inline-flex h-9 rounded-lg border border-border bg-card p-1`,children:[`all`,`global`,`project`].map(e=>(0,z.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,z.jsxs)(`div`,{className:`flex-1 overflow-auto px-6 py-5`,children:[(0,z.jsxs)(`section`,{className:`mb-6`,children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,z.jsx)(M,{className:`h-3.5 w-3.5`}),t(`plugins.sections.installed`)]}),ue?(0,z.jsx)(_e,{globalPlugins:ce,projectPlugins:q}):(0,z.jsx)(ve,{text:t(G?`plugins.empty.installedSearch`:`plugins.empty.installed`)})]}),(0,z.jsxs)(`section`,{children:[(0,z.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,z.jsx)(k,{className:`h-3.5 w-3.5`}),t(`plugins.sections.available`)]}),Y?(0,z.jsx)(_e,{globalPlugins:le,projectPlugins:J}):(0,z.jsx)(ve,{text:t(G?`plugins.empty.availableSearch`:`plugins.empty.allInstalled`)})]})]}),(0,z.jsx)(w,{open:j,onOpenChange:P,children:(0,z.jsxs)(C,{className:`w-[calc(100vw-2rem)] max-w-xl overflow-x-hidden p-4 sm:p-6`,children:[(0,z.jsxs)(S,{children:[(0,z.jsx)(x,{children:t(`plugins.headroom.title`)}),(0,z.jsx)(b,{children:t(`plugins.headroom.dialogDescription`)})]}),(0,z.jsx)(Se,{state:g,loading:v,busy:E,logs:O,onInstall:()=>H(`install`,()=>fetch(`${r}/api/global-plugins/headroom/install`,{method:`POST`}).then(e=>Z(e))),onToggleProvider:(e,t)=>H(`${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:()=>H(`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:()=>H(`uninstall`,()=>fetch(`${r}/api/global-plugins/headroom/uninstall`,{method:`POST`}).then(e=>Z(e))),onSetPort:e=>H(`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:()=>F(!0)})]})}),(0,z.jsx)(ke,{plugin:I,projects:n,onClose:()=>L(null)}),(0,z.jsx)(Me,{open:ie,onClose:()=>F(!1)})]})}function _e({globalPlugins:e,projectPlugins:t}){let{t:n}=o(`integrations`);return(0,z.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,z.jsxs)(`section`,{children:[(0,z.jsx)(be,{title:n(`plugins.groups.global.title`),detail:n(`plugins.groups.global.detail`),scope:`global`}),(0,z.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,320px))] justify-start gap-3`,children:e.map(e=>(0,z.jsx)(xe,{plugin:e},e.id))})]}),t.length>0&&(0,z.jsxs)(`section`,{children:[(0,z.jsx)(be,{title:n(`plugins.groups.project.title`),detail:n(`plugins.groups.project.detail`),scope:`project`}),(0,z.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,320px))] justify-start gap-3`,children:t.map(e=>(0,z.jsx)(xe,{plugin:e},e.id))})]})]})}function ve({text:e}){return(0,z.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 ye({scope:e}){let{t}=o(`integrations`);return(0,z.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 be({title:e,detail:t,scope:n}){return(0,z.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,z.jsx)(`div`,{className:T(`h-px flex-1`,n===`global`?`bg-accent-primary/30`:`bg-accent-info/30`)}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-card/70 px-2 py-1`,children:[(0,z.jsx)(ye,{scope:n}),(0,z.jsx)(`span`,{className:`text-xs font-medium`,children:e}),(0,z.jsx)(`span`,{className:`hidden text-[11px] text-muted-foreground sm:inline`,children:t})]}),(0,z.jsx)(`div`,{className:T(`h-px flex-1`,n===`global`?`bg-accent-primary/30`:`bg-accent-info/30`)})]})}function xe({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`?_:D,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,z.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,z.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,z.jsx)(n,{className:`h-4 w-4`})}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`h2`,{className:`truncate text-sm font-semibold leading-5`,children:e.title}),(0,z.jsx)(`p`,{className:`mt-1 truncate text-[11px] leading-4 text-muted-foreground`,children:e.description}),(0,z.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-1.5`,children:[(0,z.jsx)(ye,{scope:e.scope}),(0,z.jsx)(`span`,{className:s,children:e.statusLabel})]})]}),(0,z.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,z.jsx)(a,{className:T(`h-3.5 w-3.5`,e.busy&&`animate-spin`)}),e.busy?t(`plugins.actions.installing`):e.actionLabel]})]})}function Se({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,R.useState)(String(e.port)),[_,y]=(0,R.useState)(!1);(0,R.useEffect)(()=>h(String(e.port)),[e.port]),(0,R.useEffect)(()=>{e.installed||y(!1)},[e.installed]);let b=e.activeProviders.codex||e.activeProviders.claude,x=e.installSource===`system`;return(0,z.jsxs)(`aside`,{className:`w-full min-w-0 overflow-hidden rounded-lg border border-border bg-card/80 p-4`,children:[(0,z.jsxs)(`div`,{className:`mb-4 flex items-start gap-3`,children:[(0,z.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,z.jsx)(N,{className:`h-4 w-4`})}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`h2`,{className:`text-sm font-semibold`,children:d(`plugins.headroom.title`)}),(0,z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:d(`plugins.headroom.panelDescription`)})]})]}),(0,z.jsxs)(`div`,{className:`mb-4 grid grid-cols-3 gap-2 text-xs`,children:[(0,z.jsx)(Ce,{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,z.jsx)(Ce,{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,z.jsx)(Ce,{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,z.jsx)(we,{issue:e.lastIssue}),e.installed?(0,z.jsxs)(`div`,{className:`mb-4 space-y-2`,children:[(0,z.jsx)(Oe,{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,z.jsx)(Oe,{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,z.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,z.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}):(0,z.jsx)(L,{className:`h-3.5 w-3.5`}),d(`plugins.headroom.actions.disableAllRoutes`)]})]}):(0,z.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,z.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}):(0,z.jsx)(f,{className:`h-3.5 w-3.5`}),d(`plugins.headroom.actions.installWithUv`)]}),e.installed&&(0,z.jsx)(Te,{state:e}),(0,z.jsxs)(`div`,{className:`mb-4 rounded-lg border border-border bg-background/45 p-3`,children:[(0,z.jsx)(`label`,{className:`mb-1 block text-[11px] font-medium text-muted-foreground`,children:d(`plugins.headroom.port.label`)}),(0,z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,z.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,z.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,z.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,z.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,z.jsx)(v,{className:`h-3.5 w-3.5`}),d(`plugins.headroom.actions.viewDiagnostics`)]}),e.installed&&(0,z.jsx)(`div`,{className:`rounded-lg border border-destructive/25 bg-destructive/5 p-3`,children:_?(0,z.jsxs)(`div`,{className:`space-y-2`,children:[(0,z.jsx)(`p`,{className:`text-[11px] leading-relaxed text-muted-foreground`,children:d(x?`plugins.headroom.confirmDetach`:`plugins.headroom.confirmUninstall`)}),(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,z.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,z.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,z.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}):(0,z.jsx)(g,{className:`h-3.5 w-3.5`}),d(x?`plugins.headroom.actions.detach`:`plugins.headroom.actions.uninstall`)]})]})]}):(0,z.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,z.jsx)(g,{className:`h-3.5 w-3.5`}),d(x?`plugins.headroom.actions.detachHeadroom`:`plugins.headroom.actions.uninstallHeadroom`)]})})]})}function Ce({label:e,value:t,good:n}){return(0,z.jsxs)(`div`,{className:`rounded-lg border border-border bg-background/45 p-2`,children:[(0,z.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e}),(0,z.jsx)(`div`,{className:T(`mt-0.5 font-medium`,n?`text-foreground`:`text-accent-warning`),children:t})]})}function we({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,z.jsx)(`div`,{className:`mb-3 rounded-lg border border-accent-warning/35 bg-accent-warning/10 p-3`,children:(0,z.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,z.jsx)(_,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-warning`}),(0,z.jsxs)(`div`,{className:`min-w-0`,children:[(0,z.jsx)(`div`,{className:`text-xs font-medium`,children:r}),(0,z.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-muted-foreground`,children:i}),(0,z.jsx)(`div`,{className:`mt-1 text-[10px] text-muted-foreground`,children:t(`plugins.headroom.issueCode`,{code:e.code})})]})]})})}function Te({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,z.jsxs)(`div`,{className:`mb-4 rounded-lg border border-border bg-background/45 p-3`,children:[(0,z.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,z.jsx)(j,{className:`h-3.5 w-3.5 text-accent-primary`}),(0,z.jsx)(`div`,{className:`truncate text-xs font-medium`,children:t(`plugins.headroom.savings.title`)})]}),(0,z.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,z.jsxs)(`div`,{className:`mb-2 rounded-md bg-muted/35 px-2.5 py-2`,children:[(0,z.jsx)(`div`,{className:`mb-1.5 text-[10px] font-medium uppercase text-muted-foreground`,children:t(`plugins.headroom.savings.totals`)}),(0,z.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,z.jsx)(Ee,{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,z.jsx)(Ee,{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,z.jsx)(`div`,{className:`grid gap-2`,children:a.map(({provider:e,metric:t})=>(0,z.jsx)(De,{metric:t,outputAvailable:r.outputSavingsAvailable},e))}),(0,z.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 Ee({label:e,processed:t,saved:n,detail:r,align:i=`left`}){let{t:a}=o(`integrations`);return(0,z.jsxs)(`div`,{className:T(`min-w-0`,i===`right`&&`text-right`),children:[(0,z.jsx)(`div`,{className:`text-[10px] font-medium uppercase text-muted-foreground`,children:e}),(0,z.jsxs)(`div`,{className:`mt-1 space-y-0.5 text-[11px]`,children:[(0,z.jsxs)(`div`,{className:`flex min-w-0 items-baseline justify-between gap-2`,children:[(0,z.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:a(`plugins.headroom.savings.processed`)}),(0,z.jsx)(`span`,{className:`truncate font-semibold tabular-nums text-foreground`,children:t})]}),(0,z.jsxs)(`div`,{className:`flex min-w-0 items-baseline justify-between gap-2`,children:[(0,z.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:a(`plugins.headroom.savings.saved`)}),(0,z.jsx)(`span`,{className:`truncate font-semibold tabular-nums text-foreground`,children:n})]})]}),r&&(0,z.jsx)(`div`,{className:`mt-1 truncate text-[10px] text-muted-foreground`,children:r})]})}function De({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:he(e.requests,r.language)}):i?n(`plugins.headroom.provider.noProjectUsesProvider`):e.active?n(`plugins.headroom.savings.inputSavingsActive`):n(`plugins.headroom.savings.routeDisabled`);return(0,z.jsxs)(`div`,{className:T(`rounded-md border border-border bg-card/45 px-2.5 py-2`,a&&`opacity-70`),children:[(0,z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,z.jsx)(`span`,{className:`text-xs font-medium`,children:e.label}),e.detectedRoute&&(0,z.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,z.jsx)(`div`,{className:`mt-0.5 truncate text-[10px] text-muted-foreground`,children:f}),(0,z.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-3`,children:[(0,z.jsx)(Ee,{label:n(`plugins.headroom.savings.input`),processed:c,saved:l}),(0,z.jsx)(Ee,{align:`right`,label:n(`plugins.headroom.savings.output`),processed:u,saved:d})]})]})}function Oe({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,z.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,z.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,z.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}):(0,z.jsx)(ie,{className:`h-3.5 w-3.5`})}),(0,z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,z.jsx)(`div`,{className:`text-xs font-medium capitalize`,children:e}),(0,z.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:c})]}),(0,z.jsx)(`span`,{className:T(`h-5 w-9 rounded-full p-0.5 transition-colors`,t?`bg-accent-success`:`bg-muted`),children:(0,z.jsx)(`span`,{className:T(`block h-4 w-4 rounded-full bg-white shadow transition-transform`,t&&`translate-x-4`)})})]})}function ke({plugin:e,projects:t,onClose:n}){let{t:r}=o(`integrations`),[i,a]=(0,R.useState)(``);(0,R.useEffect)(()=>a(``),[e]);let s=t.find(e=>e.id===i)??null;return(0,z.jsx)(w,{open:!!e,onOpenChange:e=>{e||n()},children:(0,z.jsxs)(C,{className:`w-[calc(100vw-2rem)] max-w-3xl overflow-x-hidden p-4 sm:p-6`,children:[(0,z.jsxs)(S,{children:[(0,z.jsx)(x,{children:r(e===`jira`?`plugins.projectWizard.configureJira`:`plugins.projectWizard.installSerena`)}),(0,z.jsx)(b,{children:r(`plugins.projectWizard.description`)})]}),(0,z.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-[260px_minmax(0,1fr)]`,children:[(0,z.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/70 p-3`,children:[(0,z.jsx)(`div`,{className:`mb-2 text-xs font-medium text-muted-foreground`,children:r(`plugins.projectWizard.chooseProject`)}),(0,z.jsx)(`div`,{className:`max-h-[52vh] space-y-1 overflow-auto`,children:t.map(t=>{let n=e===`serena`&&!c(t).some(e=>de.has(e));return(0,z.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,z.jsx)(`div`,{className:`truncate text-xs font-medium`,children:t.name}),(0,z.jsx)(`div`,{className:`truncate text-[10px]`,children:n?r(`plugins.projectWizard.requiresSupportedProvider`,{defaultValue:`Requires Claude or Codex`}):t.path})]},t.id)})})]}),(0,z.jsx)(`div`,{className:`min-h-[360px] rounded-lg border border-border bg-card/70 p-4`,children:s?e===`jira`?(0,z.jsx)(Ae,{project:s,onDone:n}):(0,z.jsx)(je,{project:s,onDone:n}):(0,z.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:r(`plugins.projectWizard.selectProjectToContinue`)})})]})]})})}function Ae({project:e,onDone:t}){let{t:n}=o(`integrations`),r=Q(e.id),[i,a]=(0,R.useState)(null),[s,c]=(0,R.useState)(!0),[l,u]=(0,R.useState)(null),d=(0,R.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,R.useEffect)(()=>{d()},[d]),s?(0,z.jsxs)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:[(0,z.jsx)(m,{className:`mr-2 h-4 w-4 animate-spin`}),n(`plugins.jira.loading`,{defaultValue:`Loading Jira...`})]}):i?.connected&&i.connection?(0,z.jsxs)(`div`,{className:`space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h3`,{className:`text-sm font-semibold`,children:n(`plugins.jira.titleForProject`,{name:e.name,defaultValue:`Jira for ${e.name}`})}),(0,z.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,z.jsx)(J,{state:i,apiBase:r,onChanged:()=>{d()}})]}):(0,z.jsxs)(`div`,{className:`space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h3`,{className:`text-sm font-semibold`,children:n(`plugins.jira.titleForProject`,{name:e.name,defaultValue:`Jira for ${e.name}`})}),(0,z.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,z.jsx)(V,{apiBase:r,onConnected:()=>{d()},onSkip:t})]})}function je({project:e,onDone:t}){let{t:n}=o(`integrations`),r=(0,R.useMemo)(()=>c(e).filter(e=>de.has(e)),[e]),i=r.includes(e.provider)?e.provider:r[0]??e.provider,[a,s]=(0,R.useState)(i),[l,u]=(0,R.useState)(null),[p,h]=(0,R.useState)(null),[g,v]=(0,R.useState)(!1),[y,b]=(0,R.useState)(null),x=(0,R.useRef)(0);(0,R.useEffect)(()=>{s(i),u(null),h(null)},[e.id,i]);let S=(0,R.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,R.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,z.jsxs)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:[(0,z.jsx)(m,{className:`mr-2 h-4 w-4 animate-spin`}),` `,n(`plugins.serena.loading`)]}):(0,z.jsxs)(`div`,{className:`space-y-4`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h3`,{className:`text-sm font-semibold`,children:n(`plugins.serena.titleForProject`,{name:e.name})}),(0,z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`plugins.serena.description`)})]}),(0,z.jsxs)(`label`,{className:`block space-y-1`,children:[(0,z.jsx)(`span`,{className:`text-xs font-medium`,children:n(`plugins.serena.provider`,{defaultValue:`AI provider`})}),(0,z.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,z.jsx)(`option`,{value:e,children:d(e)},e))})]}),l&&(0,z.jsxs)(`div`,{className:`rounded-lg border border-border bg-background/45 p-3`,children:[(0,z.jsx)(`div`,{className:`text-xs font-medium`,children:n(`plugins.serena.status`,{status:T})}),E&&(0,z.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:E})]}),p&&(0,z.jsxs)(`div`,{className:`space-y-3`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`mb-1 text-xs font-medium`,children:n(`plugins.serena.files`)}),(0,z.jsx)(`ul`,{className:`space-y-1 text-xs font-mono`,children:p.files.map(e=>(0,z.jsxs)(`li`,{className:e.op===`create`?`text-accent-success`:`text-accent-info`,children:[e.op===`create`?`+ `:`~ `,e.path]},e.path))})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`div`,{className:`mb-1 text-xs font-medium`,children:n(`plugins.serena.prerequisites`)}),(0,z.jsx)(`ul`,{className:`space-y-1 text-xs`,children:p.requirements.map(e=>(0,z.jsxs)(`li`,{className:`flex items-center gap-2`,children:[e.installed&&e.executable&&e.meetsMinimum?(0,z.jsx)(O,{className:`h-3 w-3 text-accent-success`}):(0,z.jsx)(_,{className:`h-3 w-3 text-accent-warning`}),(0,z.jsxs)(`span`,{children:[e.name,e.minVersion?` >= ${e.minVersion}`:``]}),e.version&&(0,z.jsxs)(`span`,{className:`text-muted-foreground`,children:[`(`,e.version,`)`]})]},e.name))})]})]}),y&&(0,z.jsx)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/10 p-3 text-xs text-destructive`,children:y}),(0,z.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,z.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,z.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,z.jsx)(m,{className:`h-3.5 w-3.5 animate-spin`}):(0,z.jsx)(f,{className:`h-3.5 w-3.5`}),n(`plugins.actions.install`)]})]})]})}function Me({open:e,onClose:t}){let{t:n}=o(`integrations`),[i,a]=(0,R.useState)(null);return(0,R.useEffect)(()=>{e&&fetch(`${r}/api/global-plugins/headroom/diagnostics`).then(e=>Z(e)).then(a).catch(e=>a({error:e.message}))},[e]),(0,z.jsx)(w,{open:e,onOpenChange:e=>{e||t()},children:(0,z.jsxs)(C,{className:`max-w-3xl`,children:[(0,z.jsxs)(S,{children:[(0,z.jsxs)(x,{className:`flex items-center gap-2`,children:[(0,z.jsx)(D,{className:`h-4 w-4`}),` `,n(`plugins.diagnostics.title`)]}),(0,z.jsx)(b,{children:n(`plugins.diagnostics.description`)})]}),(0,z.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{ge as default};
@@ -0,0 +1 @@
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-BbYvbtY8.js";import{n as r,t as i}from"./createLucideIcon-DtODIU64.js";import{r as a}from"./useDesktop-C0mRIlHT.js";import{t as o}from"./git-branch-yf6LE1Bw.js";import{i as s,l as c,o as l,r as u,t as d}from"./dialog-DtdR05v1.js";import{t as f}from"./utils-BC4DHlz2.js";import{St as p,_ as m,a as h,bt as g,en as _,g as v,gt as y,h as b,i as x,jt as S,n as C,o as w,r as T,rn as E,s as D,yt as O}from"./index-CECj3joE.js";var k={name:`key-round`,size:24,node:[[`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`}]]};k.node;var A=i(k),j=e(t(),1),M=n(),N=[{id:`general`,icon:g,labelKey:`projectDialog.nav.general`},{id:`agentRuntime`,icon:_,labelKey:`projectDialog.nav.agentRuntime`},{id:`subagents`,icon:S,labelKey:`projectDialog.nav.subagents`},{id:`branch`,icon:o,labelKey:`projectDialog.nav.branch`},{id:`environment`,icon:A,labelKey:`projectDialog.nav.environment`},{id:`budget`,icon:y,labelKey:`projectDialog.nav.budget`},{id:`telemetry`,icon:E,labelKey:`projectDialog.nav.telemetry`},{id:`terminal`,icon:O,labelKey:`projectDialog.nav.terminal`}];function P({open:e,onClose:t}){let{t:n}=r(`settings`),{activeProjectId:i,projects:o}=a(),g=o.find(e=>e.id===i),[_,y]=(0,j.useState)(`general`),S=e=>f(`space-y-5`,_===e?``:`hidden`);return(0,M.jsx)(d,{open:e,onOpenChange:e=>{e||t()},children:(0,M.jsxs)(u,{movableResizable:!0,className:`flex max-w-5xl w-[92vw] h-[82vh] flex-col overflow-hidden`,children:[(0,M.jsxs)(l,{children:[(0,M.jsxs)(c,{className:`flex items-center gap-2`,children:[(0,M.jsx)(p,{className:`w-4 h-4`}),g?n(`projectDialog.title`,{name:g.name}):n(`page.title`)]}),(0,M.jsx)(s,{children:n(`projectDialog.description`)})]}),(0,M.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-5 py-2`,children:[(0,M.jsx)(`nav`,{className:`w-40 shrink-0 space-y-0.5 overflow-y-auto border-r border-border pr-2`,children:N.map(e=>{let t=e.icon;return(0,M.jsxs)(`button`,{type:`button`,onClick:()=>y(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`,_===e.id?`bg-accent-primary/15 font-medium text-foreground`:`text-muted-foreground hover:bg-muted/40 hover:text-foreground`),children:[(0,M.jsx)(t,{className:`w-3.5 h-3.5 shrink-0`}),(0,M.jsx)(`span`,{className:`truncate`,children:n(e.labelKey)})]},e.id)})}),(0,M.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-y-auto pr-1`,children:[(0,M.jsxs)(`div`,{className:S(`general`),children:[(0,M.jsx)(b,{}),(0,M.jsx)(x,{})]}),(0,M.jsx)(`div`,{className:S(`agentRuntime`),children:(0,M.jsx)(D,{})}),(0,M.jsx)(`div`,{className:S(`subagents`),children:(0,M.jsx)(m,{})}),(0,M.jsx)(`div`,{className:S(`branch`),children:(0,M.jsx)(T,{})}),(0,M.jsx)(`div`,{className:S(`environment`),children:(0,M.jsx)(w,{})}),(0,M.jsx)(`div`,{className:S(`budget`),children:(0,M.jsx)(C,{})}),(0,M.jsx)(`div`,{className:S(`telemetry`),children:(0,M.jsx)(h,{})}),(0,M.jsx)(`div`,{className:S(`terminal`),children:(0,M.jsx)(v,{mode:`project`})})]})]})]})})}export{P as ProjectSettingsDialog};
@@ -0,0 +1,5 @@
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-BbYvbtY8.js";import{t as r}from"./useSharedWebSocket-CcsE5986.js";import{n as i,t as a}from"./createLucideIcon-DtODIU64.js";import{i as o}from"./useDesktop-C0mRIlHT.js";import{a as s,i as c,l,o as u,r as d,t as f}from"./dialog-DtdR05v1.js";import{t as p}from"./button-4FS1ZDTp.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 O={name:`send-horizontal`,size:24,node:[[`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`}]],aliases:[`send-horizonal`]};O.node;var re=a(O),k=e(t(),1),ie=`"\\/bfnrtu`;function A(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&&A(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&&A(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 j(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 M=`specrails:git-changed`;function se(e){typeof window>`u`||window.dispatchEvent(new CustomEvent(M,{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(M,t),()=>window.removeEventListener(M,t)}var N=/```blueprint-draft\s*\n([\s\S]*?)\n\s*```/g,P=/```blueprint-draft(?![\s\S]*?\n\s*```)/,F=/```(?:json|JSON)?[ \t]*\r?\n(?=[ \t]*\{)([\s\S]*?)\r?\n[ \t]*```(?=[ \t]*(?:\r?\n|$))/g,I=/```(?: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 L(e){return typeof e==`string`?e:``}function R(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:L(t.name),pitch:L(t.pitch),audience:L(t.audience)}}function me(e){let t=e&&typeof e==`object`&&!Array.isArray(e)?e:{},n={language:L(t.language),framework:L(t.framework),db:L(t.db)};return typeof t.notes==`string`&&t.notes!==``&&(n.notes=t.notes),n}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=L(e.id),i=L(e.title);if(r===``&&i===``)continue;let a={id:r,title:i,goal:L(e.goal),status:ue.has(e.status)?e.status:`planned`,plannedSpecs:R(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 he(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=L(e.title);if(r===``)continue;let i={kind:de.has(e.kind)?e.kind:`feature`,title:r,shortSummary:L(e.shortSummary),description:L(e.description),acceptanceCriteria:R(e.acceptanceCriteria),priority:fe.has(e.priority)?e.priority:`medium`,labels:R(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:L(t.coreFlow),platform:L(t.platform),stack:me(t.stack),assumptions:R(t.assumptions),milestones:z(t.milestones),specsComplete:t.specsComplete===!0,m1Specs:he(t.m1Specs)}}var ge=/^[ \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 _e(e){if(!e||!e.includes(`"blueprintVersion"`))return e??``;let t=e=>!e.includes("```")||!e.includes(`"blueprintVersion"`)?e:(F.lastIndex=0,e.replace(F,(e,t)=>{if(!t.includes(`"blueprintVersion"`))return e;let n=j(t);return!n.ok||!B(n.value)?e:"```blueprint-draft\n"+t+"\n```"})),n=``,r=0;N.lastIndex=0;let i;for(;(i=N.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 ve(e){let t=_e(e??``);if(!t||!t.includes("```blueprint-draft")&&!I.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;N.lastIndex=0;let u;for(;(u=N.exec(t))!==null;){a=!0,s+=t.slice(c,u.index),c=u.index+u[0].length;let e=ge.exec(t.slice(c));e&&(c+=e[0].length,N.lastIndex=c);let d=l;l+=1;let f=j(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=P.exec(d)??I.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 ye(e){if(!e)return{generating:!1,specsStarted:0};if(e.includes("```blueprint-draft")){let t=P.exec(e);if(t)return{generating:!0,specsStarted:V(e.slice(t.index))}}let t=I.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 be(e){if(!e)return``;let t=(/```(?:blueprint-draft|spec-detail|spec-audit)/.test(e)?le.exec(e):null)??I.exec(e);return t?e.slice(0,t.index):e}function xe(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 Se(e){return`M${e}`}var H=new Set([`planned`,`committed`,`running`,`delivered`,`done`]),Ce=new Set([`running`,`waiting`,`paused`,`awaiting_approval`,`completed`,`cancelled`]),U=(e,t=0)=>typeof e==`number`&&Number.isFinite(e)?e:t,W=e=>typeof e==`string`?e:null,G=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:U(t.total),done:U(t.done),onReview:U(t.onReview),inProgress:U(t.inProgress),todo:U(t.todo),failed:U(t.failed)}}function Ee(e){if(!e||typeof e!=`object`)return null;let t=e,n=W(t.id);return n?{id:n,railIndex:U(t.railIndex,-1),ticketIds:G(t.ticketIds),decision:W(t.decision)??`building`,branch:W(t.branch),baseBranch:W(t.baseBranch)??``,prUrl:W(t.prUrl),prNumber:typeof t.prNumber==`number`?t.prNumber:null,prState:W(t.prState)??`none`,createdAt:W(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:W(t.name),ticketIds:G(t.ticketIds),active:t.active===!0,runId:W(t.runId),startedAt:W(t.startedAt),delivery:Ee(t.delivery),chunkIndex:typeof t.chunkIndex==`number`?t.chunkIndex:null}:null}function K(e){if(!e||typeof e!=`object`)return null;let t=e,n=W(t.id),r=W(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:G(t.ticketIds),runIds:we(t.runIds),deliveryId:W(t.deliveryId)}]}):[];return{id:n,milestoneN:U(t.milestoneN,0),mode:t.mode===`parallel`?`parallel`:`sequential`,status:r,pauseReason:W(t.pauseReason),autoAdvance:t.autoAdvance!==!1,nextChunk:U(t.nextChunk),totalChunks:U(t.totalChunks),currentRailIndex:typeof t.currentRailIndex==`number`?t.currentRailIndex:null,headBranch:W(t.headBranch),launched:i,updatedAt:W(t.updatedAt)??``}}function q(e){return Array.isArray(e)?e.flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e,n=W(t.id);if(!n||typeof t.n!=`number`)return[];let r=W(t.state),i=W(t.storedStatus);return[{id:n,n:t.n,title:W(t.title)??``,storedStatus:i===`done`||i===`committed`?i:`planned`,state:r&&H.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:K(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 J(e){return e!==null&&(e.status===`running`||e.status===`waiting`)}function Y(e){return e!==null&&e.status===`awaiting_approval`}function Ae(e){return e.counts.todo>0&&!J(e.chain)&&e.chain?.status!==`paused`&&!Y(e.chain)}function je(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 Me(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 Ne(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,k.createContext)(null);function Pe(){try{return r??Z}catch{return Z}}var Fe=Pe(),Ie=0;function Q(e){let t=(0,k.useContext)(Fe),{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:q(r.progress)}}}),[a,s]=(0,k.useState)(null),c=(0,k.useRef)(e);(0,k.useEffect)(()=>{c.current=e,s(null)},[e]),(0,k.useEffect)(()=>{if(!t)return;let{registerHandler:e,unregisterHandler:n}=t,r=`milestone-progress:${++Ie}`;return e(r,e=>{let t=e;!t||t.type!==`blueprint.milestone_progress`||!t.projectId||t.projectId!==c.current||s({projectId:t.projectId,progress:q(t.progress)})}),()=>n(r)},[t]);let l=(0,k.useMemo)(()=>a&&a.projectId===e?a.progress:n?.progress??[],[a,e,n]),u=n===null?null:n.blueprint!==null,d=(0,k.useCallback)(async()=>{s(null),await i()},[i]);return{blueprint:n?.blueprint??null,progress:l,hasBlueprint:u,loading:r,refresh:d}}function Le(e){let{progress:t}=Q(e);return(0,k.useMemo)(()=>je(t),[t])}var $=n();function Re({deliveryId:e,repositories:t,busy:n,onAct:r,onCheckout:a}){let{t:o}=i(`dashboard`),[m,h]=(0,k.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,j as S,ee as T,xe as _,Y as a,se as b,K as c,Ae as d,Se as f,be as g,B as h,X as i,ne as k,q as l,Ne as m,Q as n,J as o,Oe as p,Le as r,Me as s,Re as t,ke as u,ye as v,E as w,ce as x,ve as y};
@@ -1,2 +1,2 @@
1
- import{t as e}from"./jsx-runtime-zu2_FqZY.js";import{n as t}from"./createLucideIcon-Bjbbp_KS.js";import{r as n}from"./useDesktop-9Lwoel_8.js";import{t as r}from"./project-repositories-Cc3oNv8X.js";var i=e();function a({value:e,onChange:a,disabled:o=!1,repositories:s,workspaceOnly:c=!1,workspaceSelection:l,onWorkspaceChange:u,showSingle:d=!1,label:f,hint:p}){let{t:m}=t(`common`),{activeProjectId:h,projects:g}=n(),_=s??r(g.find(e=>e.id===h)),v=_.find(e=>e.isPrimary),y=e??(v?[v.id]:[]),b=y.some(e=>!_.some(t=>t.id===e));if(c){let e=_.filter(e=>y.includes(e.id)&&(e.workspacePaths?.length||e.workspacePath));return e.length?(0,i.jsxs)(`fieldset`,{className:`space-y-2`,disabled:o,children:[(0,i.jsx)(`legend`,{className:`text-xs font-medium`,children:m(`repositories.launchWorkspaces`)}),(0,i.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:m(`repositories.launchWorkspaceHint`)}),e.map(e=>{let t=e.workspacePaths??[e.workspacePath],n=l?.[e.id]??t;return(0,i.jsxs)(`div`,{className:`space-y-1`,children:[(0,i.jsx)(`span`,{className:`text-xs font-medium`,children:e.name}),t.map(t=>(0,i.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,title:t,children:[(0,i.jsx)(`input`,{type:`checkbox`,"data-agent-interactive":!0,checked:n.includes(t),disabled:o||n.length===1&&n[0]===t,onChange:r=>u?.({...Object.fromEntries(Object.entries(l??{}).filter(([e])=>y.includes(e))),[e.id]:r.target.checked?[...n,t]:n.filter(e=>e!==t)})}),(0,i.jsx)(`span`,{className:`break-all`,children:t})]},t))]},e.id)})]}):null}return!d&&_.length<=1&&!b?null:(0,i.jsxs)(`fieldset`,{className:`space-y-2`,disabled:o,children:[(0,i.jsx)(`legend`,{className:`mb-1 text-xs font-medium`,children:f??m(`repositories.specScope`)}),(0,i.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p??m(`repositories.scopeHint`)}),(0,i.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[_.map(e=>(0,i.jsxs)(`label`,{title:e.workspacePaths?.join(`
1
+ import{t as e}from"./jsx-runtime-BbYvbtY8.js";import{n as t}from"./createLucideIcon-DtODIU64.js";import{r as n}from"./useDesktop-C0mRIlHT.js";import{t as r}from"./project-repositories-Be0CWklo.js";var i=e();function a({value:e,onChange:a,disabled:o=!1,repositories:s,workspaceOnly:c=!1,workspaceSelection:l,onWorkspaceChange:u,showSingle:d=!1,label:f,hint:p}){let{t:m}=t(`common`),{activeProjectId:h,projects:g}=n(),_=s??r(g.find(e=>e.id===h)),v=_.find(e=>e.isPrimary),y=e??(v?[v.id]:[]),b=y.some(e=>!_.some(t=>t.id===e));if(c){let e=_.filter(e=>y.includes(e.id)&&(e.workspacePaths?.length||e.workspacePath));return e.length?(0,i.jsxs)(`fieldset`,{className:`space-y-2`,disabled:o,children:[(0,i.jsx)(`legend`,{className:`text-xs font-medium`,children:m(`repositories.launchWorkspaces`)}),(0,i.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:m(`repositories.launchWorkspaceHint`)}),e.map(e=>{let t=e.workspacePaths??[e.workspacePath],n=l?.[e.id]??t;return(0,i.jsxs)(`div`,{className:`space-y-1`,children:[(0,i.jsx)(`span`,{className:`text-xs font-medium`,children:e.name}),t.map(t=>(0,i.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,title:t,children:[(0,i.jsx)(`input`,{type:`checkbox`,"data-agent-interactive":!0,checked:n.includes(t),disabled:o||n.length===1&&n[0]===t,onChange:r=>u?.({...Object.fromEntries(Object.entries(l??{}).filter(([e])=>y.includes(e))),[e.id]:r.target.checked?[...n,t]:n.filter(e=>e!==t)})}),(0,i.jsx)(`span`,{className:`break-all`,children:t})]},t))]},e.id)})]}):null}return!d&&_.length<=1&&!b?null:(0,i.jsxs)(`fieldset`,{className:`space-y-2`,disabled:o,children:[(0,i.jsx)(`legend`,{className:`mb-1 text-xs font-medium`,children:f??m(`repositories.specScope`)}),(0,i.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p??m(`repositories.scopeHint`)}),(0,i.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[_.map(e=>(0,i.jsxs)(`label`,{title:e.workspacePaths?.join(`
2
2
  `)??e.workspacePath??e.path,className:`flex items-center gap-2 rounded border border-border px-2 py-1.5 text-xs`,children:[(0,i.jsx)(`input`,{type:`checkbox`,"data-agent-interactive":!0,checked:y.includes(e.id),"aria-label":e.available===!1?`${m(`repositories.unavailable`)}: ${e.name}`:void 0,disabled:o||(e.available===!1||e.kind===`folder`&&!e.isPrimary)&&!y.includes(e.id)||y.length===1&&y[0]===e.id,onChange:t=>a(t.target.checked?[...y,e.id]:y.filter(t=>t!==e.id))}),(0,i.jsx)(`span`,{children:e.name}),e.available===!1&&(0,i.jsxs)(`span`,{className:`text-destructive`,children:[` `,m(`repositories.unavailable`)]}),e.workspacePaths?.map(e=>(0,i.jsx)(`span`,{className:`text-muted-foreground`,children:e},e)),!e.workspacePaths&&e.workspacePath&&(0,i.jsx)(`span`,{className:`text-muted-foreground`,children:e.workspacePath}),e.kind===`folder`&&!e.isPrimary&&(0,i.jsx)(`span`,{className:`text-muted-foreground`,children:m(`repositories.contextOnly`)})]},e.id)),y.filter(e=>!_.some(t=>t.id===e)).map(e=>(0,i.jsxs)(`label`,{className:`flex items-center gap-2 rounded border border-destructive px-2 py-1.5 text-xs`,children:[(0,i.jsx)(`input`,{type:`checkbox`,"data-agent-interactive":!0,checked:!0,disabled:o||y.length===1,onChange:()=>a(y.filter(t=>t!==e))}),m(`repositories.unavailable`),`: `,e]},e))]}),b&&(0,i.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:m(`repositories.invalidSelection`)})]})}export{a as t};