specrails-desktop 2.57.0 → 2.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (336) hide show
  1. package/README.md +1 -1
  2. package/cli/dist/args.js +10 -4
  3. package/cli/dist/help.js +1 -1
  4. package/client/dist/assets/{ActivityFeedPage-DdMNmVBk.js → ActivityFeedPage-BQGppIR0.js} +1 -1
  5. package/client/dist/assets/{AgentBrowserCapture-CeerUf--.js → AgentBrowserCapture-PI-cxyxi.js} +1 -1
  6. package/client/dist/assets/{AgentModeAnalyticsPane-BjGb-8rh.js → AgentModeAnalyticsPane-mQsOqdXx.js} +2 -2
  7. package/client/dist/assets/{AgentModeCodePane-8XRkQEo_.js → AgentModeCodePane-BL-vpmlY.js} +2 -2
  8. package/client/dist/assets/{AgentModeJobsPane-BN3dgJOA.js → AgentModeJobsPane-DR_06oqH.js} +1 -1
  9. package/client/dist/assets/AgentsPage-BKIKjm_1.js +118 -0
  10. package/client/dist/assets/{AnalyticsPage-CyfhYiBn.js → AnalyticsPage-069npRVo.js} +1 -1
  11. package/client/dist/assets/{CodePage-C2Nf-Q5W.js → CodePage-Alitorrv.js} +2 -2
  12. package/client/dist/assets/DesktopAnalyticsPage-qtWAPM47.js +1 -0
  13. package/client/dist/assets/{DocsDialog-Br3bczCp.js → DocsDialog-DwL6rgcT.js} +1 -1
  14. package/client/dist/assets/{DocsPage-BcDr2cBm.js → DocsPage-BA1hiJZ-.js} +1 -1
  15. package/client/dist/assets/{ExportDropdown-BVGKEgkd.js → ExportDropdown-BcMpvV89.js} +1 -1
  16. package/client/dist/assets/InteractiveJobComposer-B3H1YHr6.js +19 -0
  17. package/client/dist/assets/JobDetailModal-XZQ9eAAy.js +1 -0
  18. package/client/dist/assets/{JobDetailPage-vBbNeRuz.js → JobDetailPage-B-SIaq_q.js} +1 -1
  19. package/client/dist/assets/{JobsPage-CJCtPhIz.js → JobsPage-iQXAv2mx.js} +1 -1
  20. package/client/dist/assets/LoopBuilderPage-B_gbFAHn.js +1 -0
  21. package/client/dist/assets/LoopPreviewModal-je5pSCf-.js +1 -0
  22. package/client/dist/assets/LoopsPage-BZwcY5cu.js +2 -0
  23. package/client/dist/assets/{MinimizedChatsContext-D3QzgV0B.js → MinimizedChatsContext-CNx_0bZu.js} +1 -1
  24. package/client/dist/assets/{PluginsPage-DOpTV75p.js → PluginsPage-DFocnoHX.js} +2 -2
  25. package/client/dist/assets/{ProjectSettingsDialog-Dkwrn0z1.js → ProjectSettingsDialog-Bh3S6EBB.js} +1 -1
  26. package/client/dist/assets/{RepositoryDeliveries-Du2UCf1a.js → RepositoryDeliveries-BiwJuS8r.js} +1 -1
  27. package/client/dist/assets/{RepositoryScopeSelector-hPGZNRBm.js → RepositoryScopeSelector-C2mvWBQ6.js} +1 -1
  28. package/client/dist/assets/{ReviewPacketPage-DcOq-UTA.js → ReviewPacketPage-CrAf-WDy.js} +2 -2
  29. package/client/dist/assets/TemplatePreviewModal-C7DordpN.js +1 -0
  30. package/client/dist/assets/{TicketDetailModalContext-DAK-NoK6.js → TicketDetailModalContext-B-DySpKL.js} +1 -1
  31. package/client/dist/assets/{Trans-DEbgkuAY.js → Trans-D3AfDylf.js} +1 -1
  32. package/client/dist/assets/agentRuntime-BeUb3g9g.js +1 -0
  33. package/client/dist/assets/agentRuntime-Bg9tbmqm.js +1 -0
  34. package/client/dist/assets/agentRuntime-D-GJVGkj.js +1 -0
  35. package/client/dist/assets/agentRuntime-D2__CVI_.js +1 -0
  36. package/client/dist/assets/agentRuntime-D35dGVOP.js +1 -0
  37. package/client/dist/assets/agentRuntime-DGz_IqKW.js +1 -0
  38. package/client/dist/assets/agentRuntime-O1liDt6G.js +1 -0
  39. package/client/dist/assets/agentRuntime-hInH9Fzj.js +1 -0
  40. package/client/dist/assets/agentstudio-B2CTtQgZ.js +1 -0
  41. package/client/dist/assets/agentstudio-BWAKeGgB.js +1 -0
  42. package/client/dist/assets/{agentstudio-DR7doNBV.js → agentstudio-Cja8Sjcp.js} +1 -1
  43. package/client/dist/assets/agentstudio-DtfPcr99.js +1 -0
  44. package/client/dist/assets/agentstudio-QdAJIDef.js +1 -0
  45. package/client/dist/assets/agentstudio-X70BKf6u.js +1 -0
  46. package/client/dist/assets/agentstudio-fLXpRGIi.js +1 -0
  47. package/client/dist/assets/agentstudio-qXKqVnWS.js +1 -0
  48. package/client/dist/assets/{analytics-jzCkOec3.js → analytics-B1DIQd4m.js} +1 -1
  49. package/client/dist/assets/{analytics-CoEzWPx4.js → analytics-BAIZ9vE_.js} +1 -1
  50. package/client/dist/assets/{analytics-DjLlE7jS.js → analytics-BTqgmgBd.js} +1 -1
  51. package/client/dist/assets/analytics-BWynXPEm.js +1 -0
  52. package/client/dist/assets/{analytics-nZIjjtCc.js → analytics-DGcUsQ44.js} +1 -1
  53. package/client/dist/assets/{analytics-BNgZ1Nj7.js → analytics-GnSnpJ4W.js} +1 -1
  54. package/client/dist/assets/{analytics-DFh5lSOl.js → analytics-TWgYaoO0.js} +1 -1
  55. package/client/dist/assets/{analytics-DZp-DS2U.js → analytics-kJy6Tuko.js} +1 -1
  56. package/client/dist/assets/builder-C0FyvM83.js +1 -0
  57. package/client/dist/assets/builder-C1neIYGR.js +1 -0
  58. package/client/dist/assets/builder-CvnFm0im.js +1 -0
  59. package/client/dist/assets/builder-CzW5ovyI.js +1 -0
  60. package/client/dist/assets/builder-D06L7iPy.js +1 -0
  61. package/client/dist/assets/builder-DGETbtZj.js +1 -0
  62. package/client/dist/assets/builder-DXEJUlC0.js +1 -0
  63. package/client/dist/assets/builder-DyQperXU.js +1 -0
  64. package/client/dist/assets/common-BCK7c9Pv.js +1 -0
  65. package/client/dist/assets/common-C0BOdeNi.js +1 -0
  66. package/client/dist/assets/common-C4Yvvhp6.js +1 -0
  67. package/client/dist/assets/{common-BrlwEnL7.js → common-DmsclwjP.js} +1 -1
  68. package/client/dist/assets/common-DpLWwgI1.js +1 -0
  69. package/client/dist/assets/common-OCvl3c8t.js +1 -0
  70. package/client/dist/assets/common-c0aujEZC.js +1 -0
  71. package/client/dist/assets/common-od8WThlf.js +1 -0
  72. package/client/dist/assets/dashboard-B1ndRHuC.js +1 -0
  73. package/client/dist/assets/dashboard-BX7KXiqA.js +1 -0
  74. package/client/dist/assets/dashboard-B_BSNxcN.js +1 -0
  75. package/client/dist/assets/dashboard-CCeFN7-V.js +1 -0
  76. package/client/dist/assets/dashboard-CRl0WtFJ.js +1 -0
  77. package/client/dist/assets/dashboard-XGdQ5mjw.js +1 -0
  78. package/client/dist/assets/dashboard-_oltA6Jd.js +1 -0
  79. package/client/dist/assets/dashboard-bAuf5KVk.js +1 -0
  80. package/client/dist/assets/{formatDistanceToNow-Cc2u5FwQ.js → formatDistanceToNow-aBss1Nai.js} +1 -1
  81. package/client/dist/assets/{getTimezoneOffsetInMilliseconds-BHm2U-w1.js → getTimezoneOffsetInMilliseconds-DOGj1Mfz.js} +1 -1
  82. package/client/dist/assets/index-BS7KCWkV.css +2 -0
  83. package/client/dist/assets/{index-Cxb288Rj.js → index-C4Mv6tV6.js} +32 -32
  84. package/client/dist/assets/{jira-api-DrGxiD9p.js → jira-api-BYbEPlkr.js} +1 -1
  85. package/client/dist/assets/{jobs-DSp9DoD_.js → jobs-6_-r75yC.js} +1 -1
  86. package/client/dist/assets/{jobs-C6qmvUAi.js → jobs-B1yqyId5.js} +1 -1
  87. package/client/dist/assets/{jobs-DoFaEl9g.js → jobs-BFuV7ttH.js} +1 -1
  88. package/client/dist/assets/{jobs-DTQO08nJ.js → jobs-BKa8LuwA.js} +1 -1
  89. package/client/dist/assets/{jobs-DrF8Do8s.js → jobs-BKiK-ZWh.js} +1 -1
  90. package/client/dist/assets/{jobs-DLHdDkHc.js → jobs-DmKV7b7d.js} +1 -1
  91. package/client/dist/assets/{jobs-C9j2PuwW.js → jobs-KG4Sn12X.js} +1 -1
  92. package/client/dist/assets/{jobs-Dpw6AEOP.js → jobs-pPv4KWjb.js} +1 -1
  93. package/client/dist/assets/loop-layout-BF8xMiNv.js +7 -0
  94. package/client/dist/assets/loops-B4_D-nbg.js +1 -0
  95. package/client/dist/assets/loops-BJDY9FTh.js +1 -0
  96. package/client/dist/assets/loops-BO3V8244.js +1 -0
  97. package/client/dist/assets/loops-C-hZK8pf.js +1 -0
  98. package/client/dist/assets/loops-CDOWZ0ci.js +1 -0
  99. package/client/dist/assets/loops-Dv849ckF.js +1 -0
  100. package/client/dist/assets/loops-Q9LIgGkq.js +1 -0
  101. package/client/dist/assets/loops-eUnCfLjC.js +1 -0
  102. package/client/dist/assets/{project-repositories-9Wzs0coQ.js → project-repositories-CSnfzUpg.js} +1 -1
  103. package/client/dist/assets/settings-3o4Ntzi5.js +1 -0
  104. package/client/dist/assets/settings-B97jlkwD.js +1 -0
  105. package/client/dist/assets/settings-BTaT_bsS.js +1 -0
  106. package/client/dist/assets/settings-CT8w7WiC.js +1 -0
  107. package/client/dist/assets/settings-Cvr8_tvh.js +1 -0
  108. package/client/dist/assets/settings-Dn1qgAC8.js +1 -0
  109. package/client/dist/assets/settings-EShDdg4J.js +1 -0
  110. package/client/dist/assets/settings-tfLhQZRN.js +1 -0
  111. package/client/dist/assets/{setup-Dwzt5nO1.js → setup-CBMu3tqH.js} +1 -1
  112. package/client/dist/assets/{setup-B5FHuxvB.js → setup-CPh-e6J2.js} +1 -1
  113. package/client/dist/assets/{setup-DpqzaEEA.js → setup-CRKLp_ke.js} +1 -1
  114. package/client/dist/assets/{setup-CROyqD5N.js → setup-Cy302v4J.js} +1 -1
  115. package/client/dist/assets/{setup-C9Fy9PKQ.js → setup-D681vTPf.js} +1 -1
  116. package/client/dist/assets/{setup-BihzXadx.js → setup-DYK0VBkE.js} +1 -1
  117. package/client/dist/assets/{setup-BtC6Hg4K.js → setup-KAuiIiVs.js} +1 -1
  118. package/client/dist/assets/{setup-zLEDnG7N.js → setup-OGX-oCfI.js} +1 -1
  119. package/client/dist/assets/{spending-T5GM7wpn.js → spending-HBSk-6jv.js} +1 -1
  120. package/client/dist/assets/{useDesktop-QogiN0zR.js → useDesktop-0unHDBJJ.js} +1 -1
  121. package/client/dist/assets/useRuntimeRuns-BN1rhyEm.js +1 -0
  122. package/client/dist/assets/{useSharedWebSocket-Dz-HI6De.js → useSharedWebSocket-BZMrX4jr.js} +2 -2
  123. package/client/dist/index.html +25 -25
  124. package/docs/agent-live-steering.md +16 -0
  125. package/docs/cli.md +7 -7
  126. package/docs/codex.md +2 -2
  127. package/docs/customizing.md +1 -1
  128. package/docs/gemini.md +1 -1
  129. package/docs/getting-started.md +1 -1
  130. package/docs/guide/de/integrations/7-local-engines.md +1 -1
  131. package/docs/guide/de/pipeline/1-rails-and-jobs.md +8 -6
  132. package/docs/guide/de/pipeline/2-the-job-detail-view.md +11 -2
  133. package/docs/guide/de/pipeline/4-picking-an-engine-per-rail.md +2 -2
  134. package/docs/guide/de/pipeline/5-the-loop-builder.md +24 -5
  135. package/docs/guide/en/integrations/7-local-engines.md +1 -1
  136. package/docs/guide/en/pipeline/1-rails-and-jobs.md +8 -6
  137. package/docs/guide/en/pipeline/2-the-job-detail-view.md +11 -2
  138. package/docs/guide/en/pipeline/4-picking-an-engine-per-rail.md +2 -2
  139. package/docs/guide/en/pipeline/5-the-loop-builder.md +34 -5
  140. package/docs/guide/en/settings/3-pipeline-telemetry-and-diagnostics.md +1 -1
  141. package/docs/guide/es/integrations/7-local-engines.md +1 -1
  142. package/docs/guide/es/pipeline/1-rails-and-jobs.md +8 -6
  143. package/docs/guide/es/pipeline/2-the-job-detail-view.md +11 -2
  144. package/docs/guide/es/pipeline/4-picking-an-engine-per-rail.md +2 -2
  145. package/docs/guide/es/pipeline/5-the-loop-builder.md +30 -5
  146. package/docs/guide/es/settings/3-pipeline-telemetry-and-diagnostics.md +1 -2
  147. package/docs/guide/fr/integrations/7-local-engines.md +1 -1
  148. package/docs/guide/fr/pipeline/1-rails-and-jobs.md +8 -6
  149. package/docs/guide/fr/pipeline/2-the-job-detail-view.md +11 -2
  150. package/docs/guide/fr/pipeline/4-picking-an-engine-per-rail.md +2 -2
  151. package/docs/guide/fr/pipeline/5-the-loop-builder.md +24 -5
  152. package/docs/guide/it/integrations/7-local-engines.md +1 -1
  153. package/docs/guide/it/pipeline/1-rails-and-jobs.md +8 -6
  154. package/docs/guide/it/pipeline/2-the-job-detail-view.md +11 -2
  155. package/docs/guide/it/pipeline/4-picking-an-engine-per-rail.md +2 -2
  156. package/docs/guide/it/pipeline/5-the-loop-builder.md +24 -5
  157. package/docs/guide/ja/integrations/7-local-engines.md +1 -1
  158. package/docs/guide/ja/pipeline/1-rails-and-jobs.md +8 -6
  159. package/docs/guide/ja/pipeline/2-the-job-detail-view.md +11 -2
  160. package/docs/guide/ja/pipeline/4-picking-an-engine-per-rail.md +2 -2
  161. package/docs/guide/ja/pipeline/5-the-loop-builder.md +24 -5
  162. package/docs/guide/pt/integrations/7-local-engines.md +1 -1
  163. package/docs/guide/pt/pipeline/1-rails-and-jobs.md +8 -6
  164. package/docs/guide/pt/pipeline/2-the-job-detail-view.md +11 -2
  165. package/docs/guide/pt/pipeline/4-picking-an-engine-per-rail.md +2 -2
  166. package/docs/guide/pt/pipeline/5-the-loop-builder.md +24 -5
  167. package/docs/guide/zh/integrations/7-local-engines.md +1 -1
  168. package/docs/guide/zh/pipeline/1-rails-and-jobs.md +8 -6
  169. package/docs/guide/zh/pipeline/2-the-job-detail-view.md +11 -2
  170. package/docs/guide/zh/pipeline/4-picking-an-engine-per-rail.md +2 -2
  171. package/docs/guide/zh/pipeline/5-the-loop-builder.md +24 -5
  172. package/docs/internals/api-reference.md +2 -2
  173. package/docs/internals/ci-performance.md +71 -0
  174. package/docs/internals/companion-rails-as-loops-contract.md +4 -3
  175. package/docs/internals/configuration.md +3 -3
  176. package/docs/internals/core-runtime-updates.md +3 -2
  177. package/docs/internals/interactive-jobs.md +2 -2
  178. package/docs/internals/loop-step-log-explorer.md +42 -0
  179. package/docs/internals/mission-rail-cards.md +1 -1
  180. package/docs/internals/operations-runbook.md +22 -0
  181. package/docs/internals/programmatic-agent-runtime.md +130 -7
  182. package/docs/internals/project-builder.md +35 -16
  183. package/docs/internals/source-map.md +48 -2
  184. package/docs/kimi.md +2 -2
  185. package/docs/local-providers.md +1 -1
  186. package/docs/running-pipelines.md +26 -18
  187. package/docs/tracking-cost.md +10 -1
  188. package/package.json +2 -1
  189. package/server/dist/core-compat.js +8 -3
  190. package/server/dist/core-execution.js +49 -3
  191. package/server/dist/db/migrations.js +101 -0
  192. package/server/dist/desktop-db.js +28 -0
  193. package/server/dist/desktop-router.js +2 -0
  194. package/server/dist/mcp/guide.js +6 -3
  195. package/server/dist/mcp/tools/jobs.js +14 -1
  196. package/server/dist/mcp/tools/loops.js +17 -8
  197. package/server/dist/mcp/tools/rails.js +3 -3
  198. package/server/dist/modules/agent-runtime/runtime/agent-runtime-bridge.js +313 -9
  199. package/server/dist/modules/agent-runtime/runtime/agent-runtime-controls-router.js +34 -1
  200. package/server/dist/modules/agent-runtime/runtime/agent-runtime-controls.js +203 -21
  201. package/server/dist/modules/agent-runtime/runtime/agent-runtime-effective-config.js +46 -1
  202. package/server/dist/modules/agent-runtime/runtime/agent-runtime-engines.js +10 -0
  203. package/server/dist/modules/agent-runtime/runtime/agent-runtime-loader.js +68 -3
  204. package/server/dist/modules/agent-runtime/runtime/agent-runtime-metrics.js +16 -8
  205. package/server/dist/modules/agent-runtime/runtime/agent-runtime-package-gc.js +81 -0
  206. package/server/dist/modules/agent-runtime/runtime/agent-runtime-package-lock.js +37 -0
  207. package/server/dist/modules/agent-runtime/runtime/agent-runtime-package.js +30 -24
  208. package/server/dist/modules/agent-runtime/runtime/agent-runtime-retention-host.js +87 -0
  209. package/server/dist/modules/agent-runtime/runtime/agent-runtime-retention-quarantine.js +231 -0
  210. package/server/dist/modules/agent-runtime/runtime/agent-runtime-retention-records.js +32 -0
  211. package/server/dist/modules/agent-runtime/runtime/agent-runtime-retention.js +102 -0
  212. package/server/dist/modules/agent-runtime/runtime/agent-runtime-settings-router.js +12 -7
  213. package/server/dist/modules/agent-runtime/runtime/agent-runtime-settings.js +57 -13
  214. package/server/dist/modules/agents/runtime/agent-catalog.js +32 -0
  215. package/server/dist/modules/agents/runtime/agent-refine-manager.js +12 -0
  216. package/server/dist/modules/agents/runtime/agent-role-descriptor.js +64 -0
  217. package/server/dist/modules/agents/runtime/profiles-router.js +26 -34
  218. package/server/dist/modules/builder/runtime/milestone-chain.js +121 -73
  219. package/server/dist/modules/delivery/runtime/definition-fork.js +158 -0
  220. package/server/dist/modules/delivery/runtime/delivery-evidence.js +56 -10
  221. package/server/dist/modules/delivery/runtime/isolated-settlement-reconstruction.js +99 -0
  222. package/server/dist/modules/delivery/runtime/isolated-settlement-store.js +53 -0
  223. package/server/dist/modules/delivery/runtime/multi-repo-execution-store.js +3 -1
  224. package/server/dist/modules/delivery/runtime/rail-isolated-launch.js +388 -203
  225. package/server/dist/modules/delivery/runtime/rail-launch-parser.js +3 -2
  226. package/server/dist/modules/delivery/runtime/rail-pr-store.js +6 -1
  227. package/server/dist/modules/delivery/runtime/rails-router.js +66 -10
  228. package/server/dist/modules/execution/runtime/queue-manager.js +11 -2
  229. package/server/dist/modules/loops/runtime/builtin-loops.js +70 -0
  230. package/server/dist/modules/loops/runtime/definition-cancellation.js +31 -0
  231. package/server/dist/modules/loops/runtime/legacy-launch-telemetry.js +78 -0
  232. package/server/dist/modules/loops/runtime/loop-command-catalog.js +13 -12
  233. package/server/dist/modules/loops/runtime/loop-compat.js +219 -0
  234. package/server/dist/modules/loops/runtime/loop-core-factory.js +42 -0
  235. package/server/dist/modules/loops/runtime/loop-definition-controls.js +48 -0
  236. package/server/dist/modules/loops/runtime/loop-definition-events.js +145 -0
  237. package/server/dist/modules/loops/runtime/loop-definition-recovery.js +106 -0
  238. package/server/dist/modules/loops/runtime/loop-definition-run.js +36 -0
  239. package/server/dist/modules/loops/runtime/loop-definition.js +246 -0
  240. package/server/dist/modules/loops/runtime/loop-effect.js +10 -1
  241. package/server/dist/modules/loops/runtime/loop-executors.js +63 -3
  242. package/server/dist/modules/loops/runtime/loop-factory.js +35 -15
  243. package/server/dist/modules/loops/runtime/loop-graph.js +84 -8
  244. package/server/dist/modules/loops/runtime/loop-migration.js +36 -0
  245. package/server/dist/modules/loops/runtime/loop-preview.js +10 -0
  246. package/server/dist/modules/loops/runtime/loop-run-manager.js +206 -13
  247. package/server/dist/modules/loops/runtime/loop-runs-store.js +271 -7
  248. package/server/dist/modules/loops/runtime/loop-templates.js +205 -45
  249. package/server/dist/modules/loops/runtime/loops-router.js +246 -29
  250. package/server/dist/modules/loops/runtime/loops-store.js +140 -20
  251. package/server/dist/modules/missions/runtime/agent-operator-prompt.js +14 -11
  252. package/server/dist/modules/specs/runtime/spec-addenda.js +28 -0
  253. package/server/dist/project-registry.js +87 -51
  254. package/server/dist/project-router-jobs.js +17 -6
  255. package/server/dist/project-router-loop-runs.js +200 -0
  256. package/server/dist/project-router-spending.js +17 -0
  257. package/server/dist/project-router.js +8 -6
  258. package/server/dist/schemas/agent-runtime.schema.json +93 -1
  259. package/server/dist/schemas/workflow-definition.schema.json +312 -0
  260. package/server/dist/vitest-setup.js +22 -0
  261. package/server/dist/worktree-overlay.js +1 -1
  262. package/client/dist/assets/AgentsPage-DfHWgP_x.js +0 -87
  263. package/client/dist/assets/DesktopAnalyticsPage-tc0p4jJW.js +0 -1
  264. package/client/dist/assets/InteractiveJobComposer-DFPpdg2D.js +0 -19
  265. package/client/dist/assets/JobDetailModal-BdOv-l-M.js +0 -1
  266. package/client/dist/assets/LoopBuilderPage-BemvUOxy.js +0 -7
  267. package/client/dist/assets/LoopPreviewModal-C6hNAeYN.js +0 -1
  268. package/client/dist/assets/LoopsPage-BZr0quvh.js +0 -1
  269. package/client/dist/assets/TemplatePreviewModal-Cejcquah.js +0 -1
  270. package/client/dist/assets/agentRuntime-BUimiX__.js +0 -1
  271. package/client/dist/assets/agentRuntime-BcN97sAB.js +0 -1
  272. package/client/dist/assets/agentRuntime-Ckyg-ahT.js +0 -1
  273. package/client/dist/assets/agentRuntime-DJCwyX4t.js +0 -1
  274. package/client/dist/assets/agentRuntime-DVzPJOl0.js +0 -1
  275. package/client/dist/assets/agentRuntime-V9AZTG3c.js +0 -1
  276. package/client/dist/assets/agentRuntime-bAAjw1vw.js +0 -1
  277. package/client/dist/assets/agentRuntime-v4qKAYH-.js +0 -1
  278. package/client/dist/assets/agentstudio-BNUth0uj.js +0 -1
  279. package/client/dist/assets/agentstudio-BNdB5hkr.js +0 -1
  280. package/client/dist/assets/agentstudio-C7-bt8FO.js +0 -1
  281. package/client/dist/assets/agentstudio-C8uNchpV.js +0 -1
  282. package/client/dist/assets/agentstudio-CKabyMlg.js +0 -1
  283. package/client/dist/assets/agentstudio-CN2pokQu.js +0 -1
  284. package/client/dist/assets/agentstudio-y2dVDXeM.js +0 -1
  285. package/client/dist/assets/analytics-BlypLLR6.js +0 -1
  286. package/client/dist/assets/builder-765NeYTp.js +0 -1
  287. package/client/dist/assets/builder-8MG3V6ea.js +0 -1
  288. package/client/dist/assets/builder-B-1UBs5K.js +0 -1
  289. package/client/dist/assets/builder-BTiGnPT0.js +0 -1
  290. package/client/dist/assets/builder-Cx9Rz-7u.js +0 -1
  291. package/client/dist/assets/builder-DKFMELBl.js +0 -1
  292. package/client/dist/assets/builder-OcmKrC0h.js +0 -1
  293. package/client/dist/assets/builder-P9qVBXFZ.js +0 -1
  294. package/client/dist/assets/common-B5AZNYMH.js +0 -1
  295. package/client/dist/assets/common-BFZ0c_vN.js +0 -1
  296. package/client/dist/assets/common-BttQx3z4.js +0 -1
  297. package/client/dist/assets/common-CM65k_-e.js +0 -1
  298. package/client/dist/assets/common-D4mvFFlu.js +0 -1
  299. package/client/dist/assets/common-TZ9Ny96S.js +0 -1
  300. package/client/dist/assets/common-nFpSF4GC.js +0 -1
  301. package/client/dist/assets/dashboard-B9uWNGO2.js +0 -1
  302. package/client/dist/assets/dashboard-BIwmO9wc.js +0 -1
  303. package/client/dist/assets/dashboard-BV4vOZkR.js +0 -1
  304. package/client/dist/assets/dashboard-Bf6MPVsM.js +0 -1
  305. package/client/dist/assets/dashboard-C8klWVvZ.js +0 -1
  306. package/client/dist/assets/dashboard-D1ORhPF0.js +0 -1
  307. package/client/dist/assets/dashboard-DSubvs9x.js +0 -1
  308. package/client/dist/assets/dashboard-px_vlRx_.js +0 -1
  309. package/client/dist/assets/index-C51x61Bz.css +0 -2
  310. package/client/dist/assets/loops-B7YpGizO.js +0 -1
  311. package/client/dist/assets/loops-BomD2J-h.js +0 -1
  312. package/client/dist/assets/loops-BrQHSQw3.js +0 -1
  313. package/client/dist/assets/loops-BvBwvTPA.js +0 -1
  314. package/client/dist/assets/loops-CODk6Slz.js +0 -1
  315. package/client/dist/assets/loops-DC6k-Ym-.js +0 -1
  316. package/client/dist/assets/loops-DSEg8-uY.js +0 -1
  317. package/client/dist/assets/loops-DhCoXD_v.js +0 -1
  318. package/client/dist/assets/settings-BsehKpty.js +0 -1
  319. package/client/dist/assets/settings-CQWob3SB.js +0 -1
  320. package/client/dist/assets/settings-CgCl0hzy.js +0 -1
  321. package/client/dist/assets/settings-DLRLd22L.js +0 -1
  322. package/client/dist/assets/settings-Dn5prAFl.js +0 -1
  323. package/client/dist/assets/settings-HZSu-K4l.js +0 -1
  324. package/client/dist/assets/settings-p4OVIyRh.js +0 -1
  325. package/client/dist/assets/settings-rddaldUp.js +0 -1
  326. package/client/dist/assets/useRuntimeRuns-Dqmz9fS9.js +0 -1
  327. package/docs/guide/de/pipeline/3-batch-implement-and-multi-feature.md +0 -84
  328. package/docs/guide/en/pipeline/3-batch-implement-and-multi-feature.md +0 -126
  329. package/docs/guide/es/pipeline/3-batch-implement-and-multi-feature.md +0 -114
  330. package/docs/guide/fr/pipeline/3-batch-implement-and-multi-feature.md +0 -84
  331. package/docs/guide/it/pipeline/3-batch-implement-and-multi-feature.md +0 -84
  332. package/docs/guide/ja/pipeline/3-batch-implement-and-multi-feature.md +0 -84
  333. package/docs/guide/pt/pipeline/3-batch-implement-and-multi-feature.md +0 -84
  334. package/docs/guide/zh/pipeline/3-batch-implement-and-multi-feature.md +0 -84
  335. package/server/dist/modules/loops/runtime/loop-templates-ported.js +0 -675
  336. /package/client/dist/assets/{LoopBuilderPage-DtxX27Jz.css → loop-layout-DtxX27Jz.css} +0 -0
@@ -0,0 +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{d as r,u as i}from"./chunk-KS7C4IRE-DEKu087k.js";import{n as a,t as o}from"./createLucideIcon-Bjbbp_KS.js";import{a as s,r as c,s as l}from"./useDesktop-0unHDBJJ.js";import{n as u,t as d}from"./save-B6wGWwBR.js";import{t as f}from"./git-branch-BRM0F5GN.js";import{n as p,t as m}from"./square-Ci-PFcFe.js";import{t as h}from"./plus-CsnjfkmX.js";import{t as g}from"./rotate-ccw-Wh4id13q.js";import{t as _}from"./trash-2-BOU3WdZZ.js";import{t as ee}from"./triangle-alert-H9T4jAmh.js";import{t as te}from"./upload-DYMjAQ6M.js";import{t as v}from"./x-CBMI9ejn.js";import{a as ne,i as re,l as ie,o as ae,r as oe,t as se}from"./dialog-xXB2q5HJ.js";import{t as ce}from"./utils-BC4DHlz2.js";import{t as y}from"./button-Ccc9Dc-D.js";import{t as le}from"./project-repositories-CSnfzUpg.js";import{B as b,H as ue,Ht as x,Jt as de,Nt as fe,Tt as S,V as pe,X as me,Z as C,jt as w,lt as he,mt as ge,z as T}from"./index-C4Mv6tV6.js";import{a as _e,c as ve,d as ye,f as be,i as E,l as xe,m as D,n as Se,o as O,p as Ce,r as we,s as Te,t as Ee,u as De}from"./loop-layout-BF8xMiNv.js";var Oe=o(`grid-3x3`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M3 9h18`,key:`1pudct`}],[`path`,{d:`M3 15h18`,key:`5xshup`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),ke=o(`move-horizontal`,[[`path`,{d:`m18 8 4 4-4 4`,key:`1ak13k`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}],[`path`,{d:`m6 8-4 4 4 4`,key:`15zrgr`}]]),Ae=o(`move-vertical`,[[`path`,{d:`M12 2v20`,key:`t6zp3m`}],[`path`,{d:`m8 18 4 4 4-4`,key:`bh5tu3`}],[`path`,{d:`m8 6 4-4 4 4`,key:`ybng9g`}]]),k=e(t(),1);function A(e){let t=[],n=0;function r(i,a,o){if(!(o.length>=32||t.length>=1e4))for(let s of i.nodes){if(++n>1e4)return;if(s.type!==`core`)continue;let i=a+s.id,c=s.data?.kind,l=j(s.data?.params);c===`role-turn`&&t.push(i);let u=c===`component`?l.ref:c===`map`?l.body:void 0;typeof u==`string`&&!o.includes(u)&&e.components?.[u]&&r(e.components[u],i+`/`,[...o,u])}}return r(e,``,[]),t.sort()}var j=e=>typeof e==`object`&&e&&!Array.isArray(e)?e:{};function M(e){return typeof e.type==`string`?e.type:e.properties||e.additionalProperties?`object`:e.items?`array`:`string`}function N(e){if(`default`in e)return structuredClone(e.default);if(`const`in e)return structuredClone(e.const);if(Array.isArray(e.enum))return structuredClone(e.enum[0]);let t=e.oneOf??e.anyOf;if(Array.isArray(t)&&!e.properties)return N(j(t[0]));switch(M(e)){case`boolean`:return!1;case`number`:case`integer`:return typeof e.minimum==`number`?e.minimum:0;case`array`:return[];case`object`:{let t=j(e.properties);return Object.fromEntries((Array.isArray(e.required)?e.required:[]).filter(e=>typeof e==`string`).map(e=>[e,N(j(t[e]))]))}default:return``}}function je(e){let t=j(N(e.paramsSchema));return e.kind===`prompt`&&(t.text=``,t.engine={provider:`claude`},t.access=`read`),e.kind===`shell`&&(t.argv=[``]),e.kind===`assign`&&(t.set={}),{kind:`core`,coreKind:e.kind,params:t}}function Me(e,t,n={}){if(!e)return[];let r=e.outcomes;return e.kind===`prompt`&&(r=t.sentinel===`verification`?[`pass`,`fail`,`failed`]:t.sentinel===`blocked`?[`next`,`blocked`,`failed`]:[`next`,`failed`]),e.kind===`role-turn`&&(r=t.structuredOutput?[`next`,`invalid`,`failed`]:[`next`,`failed`]),e.kind===`component`?n[String(t.ref)]?.outputs??[`next`,`failed`]:r.filter(t=>e.outcomes.includes(t))}var Ne=e=>[`prompt`,`role-turn`,`decider`,`implementation`].includes(e)?`ai`:[`verify`,`shell`].includes(e)?`verification`:e.startsWith(`openspec-`)?`openspec`:`control`,P=n(),F=`w-full min-w-0 rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary`;function I({schema:e,value:t,onChange:n,path:r=`params`,choices:i={},depth:o=0}){let{t:s}=a(`loops`),c=(0,k.useId)(),[l,u]=(0,k.useState)(``);if(o>24)return(0,P.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:s(`builder.core.tooDeep`)});let d=typeof e.title==`string`?e.title:r.split(`.`).slice(-1)[0],f=(e,n,a,s)=>(0,P.jsx)(I,{schema:n,value:a,onChange:s,path:`${r}.${e}`,choices:{...i,selectedProvider:typeof j(t).provider==`string`?String(j(t).provider):i.selectedProvider},depth:o+1},e),p=e.oneOf??e.anyOf;if(Array.isArray(p)&&!e.properties){let e=p.map(j),r=Math.max(0,e.findIndex(e=>`const`in e?t===e.const:Array.isArray(e.enum)?e.enum.includes(t):M(e)===(Array.isArray(t)?`array`:typeof t)));return(0,P.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,P.jsx)(`legend`,{className:`text-xs font-medium`,children:d}),(0,P.jsx)(`label`,{className:`sr-only`,htmlFor:c,children:s(`builder.core.variant`,{name:d})}),(0,P.jsx)(`select`,{id:c,className:F,value:r,onChange:t=>n(N(e[Number(t.target.value)])),children:e.map((e,t)=>(0,P.jsx)(`option`,{value:t,children:String(e.title??e.const??(Array.isArray(e.enum)?e.enum.join(` / `):M(e)))},t))}),f(`value`,e[r],t,n)]})}if(`const`in e)return(0,P.jsxs)(`p`,{className:`text-xs`,children:[(0,P.jsxs)(`span`,{className:`text-muted-foreground`,children:[d,`: `]}),String(e.const)]});if(Array.isArray(e.enum))return(0,P.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,(0,P.jsxs)(`select`,{className:F,value:JSON.stringify(t),onChange:e=>n(JSON.parse(e.target.value)),children:[!e.enum.includes(t)&&(0,P.jsx)(`option`,{value:JSON.stringify(t)??``,children:s(`builder.core.select`)}),e.enum.map((e,t)=>(0,P.jsx)(`option`,{value:JSON.stringify(e),children:String(e)},t))]})]});let m=M(e);if(m===`object`){let r=j(t),i=j(e.properties),a=new Set(Array.isArray(e.required)?e.required:[]),o=[...Object.keys(i),...Object.keys(r).filter(e=>!(e in i))],c=(e,t)=>{let a={...r};e===`provider`&&t!==r.provider&&i.model&&(delete a.model,delete a.effort),t===void 0?delete a[e]:Object.defineProperty(a,e,{value:t,enumerable:!0,configurable:!0,writable:!0}),n(a)},m=Array.isArray(p)?p.map(e=>j(e).required).filter(e=>Array.isArray(e)&&e.every(e=>typeof e==`string`)):[],g=t=>{let a={...r};if(m.some(e=>e.includes(t)))for(let e of m)for(let n of e)n!==t&&delete a[n];Object.defineProperty(a,t,{value:N(j(i[t]??e.additionalProperties)),enumerable:!0,configurable:!0,writable:!0}),n(a)};return(0,P.jsxs)(`fieldset`,{className:`space-y-2 min-w-0`,children:[(0,P.jsx)(`legend`,{className:`text-xs font-semibold text-foreground mb-1`,children:d}),o.map(t=>{let n=Object.prototype.hasOwnProperty.call(r,t),o=a.has(t);return!n&&!o?(0,P.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 text-xs rounded border border-border px-2 py-1 mr-1 hover:bg-muted`,onClick:()=>g(t),"aria-label":s(`builder.core.addField`,{name:t}),children:[(0,P.jsx)(h,{className:`h-3 w-3`}),t]},t):(0,P.jsxs)(`div`,{className:`relative border-l border-border pl-2 space-y-1`,children:[!o&&(0,P.jsx)(`button`,{type:`button`,className:`float-right text-muted-foreground hover:text-destructive`,onClick:()=>c(t,void 0),"aria-label":s(`builder.core.removeField`,{name:t}),children:(0,P.jsx)(v,{className:`h-3.5 w-3.5`})}),f(t,j(i[t]??e.additionalProperties),r[t],e=>c(t,e))]},t)}),e.additionalProperties!==!1&&(0,P.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,P.jsx)(`input`,{className:F,value:l,placeholder:s(`builder.core.fieldName`),"aria-label":s(`builder.core.fieldName`),onChange:e=>u(e.target.value)}),(0,P.jsx)(`button`,{type:`button`,className:`p-1.5 text-accent-primary disabled:opacity-40`,disabled:!l.trim()||Object.prototype.hasOwnProperty.call(r,l.trim())||[`__proto__`,`constructor`,`prototype`].includes(l.trim()),onClick:()=>{g(l.trim()),u(``)},"aria-label":s(`builder.core.addField`,{name:l}),children:(0,P.jsx)(h,{className:`h-4 w-4`})})]})]})}if(m===`array`){let r=Array.isArray(t)?t:[],i=j(e.items);return(0,P.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,P.jsx)(`legend`,{className:`text-xs font-semibold`,children:d}),r.map((e,t)=>(0,P.jsxs)(`div`,{className:`border-l border-border pl-2`,children:[(0,P.jsx)(`button`,{type:`button`,className:`float-right text-muted-foreground hover:text-destructive`,onClick:()=>n(r.filter((e,n)=>n!==t)),"aria-label":s(`builder.core.removeField`,{name:`${d} ${t+1}`}),children:(0,P.jsx)(v,{className:`h-3.5 w-3.5`})}),f(String(t+1),i,e,e=>n(r.map((n,r)=>r===t?e:n)))]},t)),(0,P.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 text-xs text-accent-primary`,disabled:typeof e.maxItems==`number`&&r.length>=e.maxItems,onClick:()=>n([...r,N(i)]),children:[(0,P.jsx)(h,{className:`h-3 w-3`}),s(`builder.core.addItem`)]})]})}if(!Object.keys(e).length){let e=t===null?`null`:Array.isArray(t)?`array`:typeof t,r=[`object`,`array`,`boolean`,`number`,`null`].includes(e)?e:`string`;return(0,P.jsxs)(`div`,{className:`space-y-1`,children:[(0,P.jsxs)(`label`,{className:`text-xs`,children:[s(`builder.core.valueType`),(0,P.jsx)(`select`,{className:F,value:r,onChange:e=>n(e.target.value===`null`?null:N({type:e.target.value})),children:[`string`,`number`,`boolean`,`object`,`array`,`null`].map(e=>(0,P.jsx)(`option`,{children:e},e))})]}),r===`null`?(0,P.jsx)(`span`,{className:`text-xs`,children:`null`}):f(`value`,{type:r},t,n)]})}if(m===`boolean`)return(0,P.jsxs)(`label`,{className:`flex items-center gap-2 text-xs`,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:t===!0,onChange:e=>n(e.target.checked),className:`accent-accent-primary`}),d]});if(m===`number`||m===`integer`)return(0,P.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,(0,P.jsx)(`input`,{type:`number`,className:F,value:typeof t==`number`?t:``,min:typeof e.minimum==`number`?e.minimum:void 0,max:typeof e.maximum==`number`?e.maximum:void 0,step:m===`integer`?1:`any`,onChange:e=>n(e.target.value===``?void 0:Number(e.target.value))})]});let g=d===`provider`?i.providers:d===`roleId`?i.roles:[`ref`,`body`].includes(d)?i.components:void 0,_=d===`model`?i.models?.[i.selectedProvider??``]:void 0,ee=[`text`,`prompt`,`question`,`message`,`goal`,`expr`,`commandLine`,`reason`].includes(d);return(0,P.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[d,g?.length?(0,P.jsxs)(`select`,{className:F,value:typeof t==`string`?t:``,onChange:e=>n(e.target.value),children:[(0,P.jsx)(`option`,{value:``,children:s(`builder.core.select`)}),t&&!g.includes(String(t))?(0,P.jsx)(`option`,{value:String(t),children:String(t)}):null,g.map(e=>(0,P.jsx)(`option`,{children:e},e))]}):ee?(0,P.jsx)(`textarea`,{className:`${F} min-h-24 resize-y font-mono`,value:typeof t==`string`?t:``,maxLength:typeof e.maxLength==`number`?e.maxLength:void 0,onChange:e=>n(e.target.value)}):(0,P.jsx)(`input`,{list:_?.length?c:void 0,className:F,value:typeof t==`string`?t:``,maxLength:typeof e.maxLength==`number`?e.maxLength:void 0,onChange:e=>n(e.target.value)}),_?.length?(0,P.jsx)(`datalist`,{id:c,children:_.map(e=>(0,P.jsx)(`option`,{value:e},e))}):null,typeof e.description==`string`&&(0,P.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e.description})]})}var L=`w-full min-w-0 rounded border border-border bg-background px-2 py-1 text-xs`,R=[`journal`,`change`,`maxTokens`,`maxTransitions`,`policies`];function Pe({graph:e,canvas:t,schema:n,onChange:r,onOpenCanvas:i}){let{t:o}=a(`loops`),[s,c]=(0,k.useState)(``),l=j(n.properties),u={type:`object`,additionalProperties:!1,properties:{...Object.fromEntries(R.filter(e=>l[e]).map(e=>[e,l[e]])),...j(j(l.budget).properties).maxTokens?{maxTokens:j(j(l.budget).properties).maxTokens}:{}}},d=Object.fromEntries(Object.entries(e.config).filter(([e])=>R.includes(e))),f=t?e.components?.[t]:void 0,p=t?[]:A(e);return(0,P.jsxs)(P.Fragment,{children:[!t&&(0,P.jsxs)(`label`,{className:`block space-y-1 text-xs`,children:[(0,P.jsx)(`span`,{children:o(`builder.core.reviewerStep`)}),(0,P.jsxs)(`select`,{className:L,value:e.config.reviewerStepId??``,onChange:t=>r({...e,config:{...e.config,reviewerStepId:t.target.value||void 0}}),children:[(0,P.jsx)(`option`,{value:``,children:o(`builder.core.reviewerAutomatic`)}),e.config.reviewerStepId&&!p.includes(e.config.reviewerStepId)&&(0,P.jsx)(`option`,{value:e.config.reviewerStepId,children:e.config.reviewerStepId}),p.map(e=>(0,P.jsx)(`option`,{value:e,children:e},e))]}),(0,P.jsx)(`span`,{className:`block text-muted-foreground`,children:o(`builder.core.reviewerHint`)})]}),(0,P.jsx)(I,{schema:u,value:d,path:o(`builder.core.options`),onChange:t=>{let n=Object.fromEntries(Object.entries(e.config).filter(([e])=>!R.includes(e)));r({...e,config:{...n,...t}})}}),(0,P.jsxs)(`section`,{className:`space-y-2`,children:[(0,P.jsx)(`p`,{className:`text-xs font-semibold`,children:o(`builder.core.components`)}),(0,P.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.keys(e.components??{}).map(e=>(0,P.jsx)(`button`,{type:`button`,onClick:()=>i(e),className:`text-xs rounded border border-border px-2 py-1 hover:bg-muted`,children:e},e))}),(0,P.jsxs)(`div`,{className:`flex gap-1`,children:[(0,P.jsx)(`input`,{className:L,value:s,"aria-label":o(`builder.core.componentName`),placeholder:o(`builder.core.componentName`),onChange:e=>c(e.target.value)}),(0,P.jsx)(`button`,{type:`button`,disabled:!/^[a-z][a-z0-9-]{0,63}$/.test(s)||!!e.components?.[s],onClick:()=>{i(s,!0),c(``)},"aria-label":o(`builder.core.addComponent`),className:`text-accent-primary disabled:opacity-40`,children:(0,P.jsx)(h,{className:`w-4 h-4`})})]}),f&&t&&(0,P.jsx)(I,{schema:{type:`object`,additionalProperties:!1,required:[`inputs`,`outputs`],properties:{inputs:{type:`array`,items:{type:`string`}},outputs:{type:`array`,items:{type:`string`}}}},value:{inputs:f.inputs??[],outputs:f.outputs??[`next`,`failed`]},path:t,onChange:n=>{r({...e,components:{...e.components,[t]:{...f,...n}}})}})]})]})}function Fe({nodeId:e,data:t,piece:n,choices:r,schema:i,onChange:o,onDelete:s,onOpenCanvas:c}){let{t:l}=a(`loops`),u=t.params?.ref??t.params?.body,d=j(j(i.$defs).retry),f=n?.paramsSchema??{},p=t.coreKind===`assign`?{set:l(`builder.core.assignment.set`),increment:l(`builder.core.assignment.increment`)}:t.coreKind===`decider`?{continueWhen:l(`builder.core.requiredContinue`)}:{},m=Object.keys(p).length?{...f,properties:Object.fromEntries(Object.entries(j(f.properties)).map(([e,t])=>[e,p[e]?{...j(t),title:p[e]}:t]))}:f;return(0,P.jsxs)(`div`,{className:`space-y-3`,children:[(0,P.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,P.jsx)(`h3`,{className:`text-sm font-semibold`,children:l(`builder.core.pieces.${t.coreKind}`)}),(0,P.jsx)(`button`,{type:`button`,onClick:s,"aria-label":l(`common:actions.delete`),className:`text-muted-foreground hover:text-destructive`,children:(0,P.jsx)(_,{className:`h-4 w-4`})})]}),(0,P.jsxs)(`label`,{className:`block text-xs`,children:[l(`builder.inspector.label`),(0,P.jsx)(`input`,{className:L,value:String(t.label??``),onChange:e=>o({label:e.target.value})})]}),n?(0,P.jsx)(I,{schema:m,value:t.params??{},onChange:e=>o({params:e}),choices:r},e):(0,P.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l(`builder.core.unavailable`)}),[`component`,`map`].includes(t.coreKind)&&typeof u==`string`&&(0,P.jsx)(`button`,{type:`button`,className:`text-xs text-accent-primary`,onClick:()=>c(u),children:l(`builder.core.openComponent`)}),Object.keys(d).length>0&&(0,P.jsx)(I,{schema:d,value:t.retry??{},path:`retry`,onChange:e=>o({retry:e})})]})}function z(e){return e===`continue`||e===`stop`?e:void 0}function B(e){switch(e){case`core`:return{kind:e,coreKind:`prompt`,params:{text:``,access:`write`,sessionContinuity:`run`}};case`ai-step`:return{kind:e,prompt:``,provider:`claude`,model:``,effort:`medium`,maxTurns:0};case`shell`:return{kind:e,command:``};case`decider`:return{kind:e,goal:``};case`condition`:return{kind:e,join:`AND`};case`end`:return{kind:e,outcome:`success`};default:return{kind:e}}}function V(){return globalThis.crypto?.randomUUID?.()??`n-${Date.now()}-${Math.floor(Math.random()*1e9)}`}function Ie(e,t){return{id:V(),type:`loop`,position:t,data:B(e)}}function Le(e){let t=(e.nodes??[]).map(e=>({id:e.id,type:`loop`,position:e.position??{x:0,y:0},data:{...e.data??{},...e.type===`core`?{coreKind:e.data?.kind}:{},kind:e.type}})),n=new Map((e.nodes??[]).map(e=>[e.id,e.type]));return{nodes:t,edges:(e.edges??[]).map(e=>{let t=e.branch??(n.get(e.source)===`decider`?n.get(e.target)===`end`?`stop`:`continue`:void 0);return{id:e.id,source:e.source,target:e.target,sourceHandle:e.label??t??void 0,type:`smoothstep`,markerEnd:{type:Ce.ArrowClosed,width:16,height:16},label:e.label??e.join,data:{...e.join?{join:e.join}:{},...t?{branch:t}:{},...e.label?{label:e.label}:{}},...t?{style:{stroke:t===`stop`?`var(--color-accent-success)`:`var(--color-accent-highlight)`}}:{}}})}}function Re(e,t,n,r){let i={...n};return i.legacyDeciderRole&&!e.some(e=>e.data.coreKind===`decider`&&e.data.params?.roleId===i.legacyDeciderRole)&&delete i.legacyDeciderRole,{nodes:e.map(e=>{let{kind:t,coreKind:n,...r}=e.data,i={id:e.id,type:t,position:e.position};return(Object.keys(r).length>0||n)&&(i.data={...r,...t===`core`?{kind:n}:{}}),i}),edges:t.map(t=>{let n=t.data?.join;if(e.find(e=>e.id===t.source)?.data.kind===`core`){let e=t.sourceHandle??t.data?.label;return{id:t.id,source:t.source,target:t.target,...e?{label:e}:{}}}let r=z(t.sourceHandle)??z(t.data?.branch);return{id:t.id,source:t.source,target:t.target,...n?{join:n}:{},...r?{branch:r}:{}}}),config:i,...r?{components:r}:{}}}var ze=`specrailsNodes`;function Be(e,t){let n=e.filter(e=>e.selected);if(n.length===0)return null;let r=new Set(n.map(e=>e.id));return{specrailsNodes:1,nodes:n,edges:t.filter(e=>r.has(e.source)&&r.has(e.target))}}function Ve(e){if(!e)return null;let t;try{t=JSON.parse(e)}catch{return null}let n=t;return!n||n[ze]==null||!Array.isArray(n.nodes)?null:{nodes:n.nodes,edges:Array.isArray(n.edges)?n.edges:[]}}function He(e,t){let n=t.offset??{x:40,y:40},r=new Set(t.excludeKinds??[]),i=new Map;return{nodes:e.nodes.filter(e=>!r.has(String(e.data?.kind))).map(e=>{let r=t.mintId();return i.set(e.id,r),{...e,id:r,position:{x:e.position.x+n.x,y:e.position.y+n.y},selected:!0}}),edges:e.edges.filter(e=>i.has(e.source)&&i.has(e.target)).map(e=>({...e,id:t.mintId(),source:i.get(e.source),target:i.get(e.target),selected:!1}))}}function H(e){return typeof e!=`string`||e.trim().length===0}function U(e,t){let n=e.find(e=>e.data.kind===`start`),r=new Set;if(!n)return r;let i=new Map;for(let e of t)(i.get(e.source)??i.set(e.source,[]).get(e.source)).push(e.target);let a=[n.id];for(;a.length;){let e=a.shift();if(!r.has(e)){r.add(e);for(let t of i.get(e)??[])r.has(t)||a.push(t)}}return r}function Ue(e,t){let n=[],r=e.filter(e=>e.data.kind===`start`);r.length===0&&n.push({severity:`error`,code:`NO_START`});for(let e of r.slice(1))n.push({severity:`error`,code:`MULTIPLE_START`,nodeId:e.id});if(e.some(e=>e.data.kind===`end`||e.data.kind===`core`&&e.data.coreKind===`end`)||n.push({severity:`error`,code:`NO_END`}),e.some(e=>e.data.kind===`core`)&&e.some(e=>![`start`,`core`,`end`].includes(e.data.kind))&&n.push({severity:`error`,code:`MIXED_ENGINES`}),r.length===1){let r=U(e,t);for(let t of e)r.has(t.id)||n.push({severity:`error`,code:`ORPHAN`,nodeId:t.id})}let i=new Map;for(let e of t)(i.get(e.source)??i.set(e.source,[]).get(e.source)).push(e);for(let t of e){let e=i.get(t.id)??[];switch(t.data.kind){case`core`:{(!t.data.coreKind||!t.data.params||typeof t.data.params!=`object`||Array.isArray(t.data.params))&&n.push({severity:`error`,code:`CORE_PIECE`,nodeId:t.id});let r=e.map(e=>e.sourceHandle??e.data?.label);(t.data.coreKind===`end`?e.length>0:!r.length||r.some(e=>!e||!/^[a-z][a-z0-9-]{0,31}$/.test(e))||new Set(r).size!==r.length)&&n.push({severity:`error`,code:`CORE_OUTCOMES`,nodeId:t.id});break}case`decider`:{let r=new Set(e.map(e=>e.sourceHandle??e.data?.branch));(!r.has(`continue`)||!r.has(`stop`))&&n.push({severity:`error`,code:`DECIDER_BRANCHES`,nodeId:t.id}),H(t.data.goal)&&n.push({severity:`warning`,code:`EMPTY_GOAL`,nodeId:t.id});break}case`ai-step`:H(t.data.prompt)&&n.push({severity:`warning`,code:`EMPTY_PROMPT`,nodeId:t.id}),e.length===0&&n.push({severity:`warning`,code:`DEAD_END`,nodeId:t.id});break;case`shell`:H(t.data.command)&&n.push({severity:`warning`,code:`EMPTY_COMMAND`,nodeId:t.id}),e.length===0&&n.push({severity:`warning`,code:`DEAD_END`,nodeId:t.id});break;case`start`:e.length===0&&n.push({severity:`warning`,code:`DEAD_END`,nodeId:t.id});break;default:break}}return n}function We(e){let t=new Map;for(let n of e)n.nodeId&&(n.severity===`error`||!t.has(n.nodeId))&&t.set(n.nodeId,n.severity);return t}var Ge=(0,k.createContext)(new Map),Ke=(0,k.createContext)({pieces:[]}),qe=[`start`,`ai-step`,`shell`,`decider`,`end`],Je={core:x,start:p,"ai-step":x,shell:he,decider:f,condition:f,end:w},Ye={core:`border-accent-primary/60`,start:`border-accent-success/60`,"ai-step":`border-accent-primary/60`,shell:`border-accent-warning/60`,decider:`border-accent-highlight/60`,condition:`border-accent-info/60`,end:`border-accent-secondary/60`};function Xe({id:e,data:t,selected:n}){let{t:r}=a(`loops`),i=t.kind,o=Je[i]??m,s=String(t.label??``).trim(),c=(0,k.useContext)(Ge).get(e),l=(0,k.useContext)(Ke),u=Me(l.pieces.find(e=>e.kind===t.coreKind),t.params??{},l.components),d=i===`core`?String(t.params?.roleId??t.params?.ref??t.params?.body??t.params?.text??t.params?.expr??``):i===`ai-step`?String(t.model||t.provider||``):i===`shell`?String(t.command||``):i===`decider`?String(t.goal||``):i===`condition`?String(t.join||`AND`):i===`end`?String(t.outcome||`success`):``;return(0,P.jsxs)(`div`,{className:ce(`rounded-md border-2 bg-card px-3 py-2 min-w-[140px] shadow-sm`,Ye[i],c===`error`?`ring-2 ring-destructive`:n?`ring-2 ring-accent-primary`:c===`warning`?`ring-2 ring-accent-warning`:``),children:[i!==`start`&&(0,P.jsx)(E,{type:`target`,position:D.Top}),(0,P.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,P.jsx)(o,{className:`w-3.5 h-3.5 text-foreground flex-shrink-0`}),(0,P.jsx)(`span`,{className:`text-xs font-semibold text-foreground truncate max-w-[150px]`,children:s||r(i===`core`?`builder.core.pieces.${t.coreKind}`:`builder.nodes.${i}`)}),s&&(0,P.jsx)(`span`,{className:`text-[9px] text-muted-foreground/70 flex-shrink-0`,children:r(i===`core`?`builder.core.pieces.${t.coreKind}`:`builder.nodes.${i}`)})]}),d&&(0,P.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-1 truncate max-w-[160px]`,children:d}),i===`core`?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`div`,{className:`flex justify-around gap-2 mt-2 text-[9px] text-accent-primary`,children:u.map(e=>(0,P.jsx)(`span`,{children:e},e))}),u.map((e,t)=>(0,P.jsx)(E,{id:e,type:`source`,position:D.Bottom,style:{left:`${(t+1)*100/(u.length+1)}%`},"aria-label":e},e))]}):i===`decider`?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between gap-2 text-[9px] font-medium`,children:[(0,P.jsx)(`span`,{className:`text-accent-highlight`,children:r(`builder.branch.continue`)}),(0,P.jsx)(`span`,{className:`text-accent-success`,children:r(`builder.branch.stop`)})]}),(0,P.jsx)(E,{id:`continue`,type:`source`,position:D.Bottom,style:{left:`30%`},className:`!bg-accent-highlight`}),(0,P.jsx)(E,{id:`stop`,type:`source`,position:D.Bottom,style:{left:`70%`},className:`!bg-accent-success`})]}):i===`end`?null:(0,P.jsx)(E,{type:`source`,position:D.Bottom})]})}function W({loopId:e,onExit:t}){let{t:n}=a(`loops`),o=i(),{id:f}=r(),p=e??f,m=(0,k.useCallback)(()=>{t?t():o(`/loops`)},[t,o]),_=de(),{fitView:v,screenToFlowPosition:le}=be(),{activeProjectId:x}=c(),[w,he]=(0,k.useState)([]),[ge,E]=(0,k.useState)({}),[D,Te]=(0,k.useState)(!1),[A,j]=(0,k.useState)({}),[M,N]=(0,k.useState)([]),[F,I]=(0,k.useState)(null),[L,R]=(0,k.useState)(null);(0,k.useEffect)(()=>{let e=!1;return C.catalog().then(t=>{e||(he(t.nodeKinds),E(t.definitionSchema??{}),Te(!1))}).catch(()=>{e||Te(!0)}),()=>{e=!0}},[]),(0,k.useEffect)(()=>{let e=new AbortController;j({});let t=t=>fetch(t,{signal:e.signal}).then(e=>e.ok?e.json():null).catch(()=>null);return Promise.all([x?t(`${s()}/agent-runtime/config`):Promise.resolve(null),t(`/api/runtime-providers`)]).then(([t,n])=>{e.signal.aborted||j({providers:(t?.config?.providers??n?.providers??[]).map(e=>e.id),roles:[...new Set([...Object.keys(t?.config?.agents??{}),...Object.keys(t?.config?.roles??{}),...Object.keys(t?.workflowRoleDefaults??{})])],models:Object.fromEntries(Object.entries(n?.status??{}).map(([e,t])=>[e,t.models??[]]))})}),()=>e.abort()},[x]);let[z,B,ze]=ye([]),[H,U,Ye]=De([]),[W,Ze]=(0,k.useState)(``),[G,Qe]=(0,k.useState)(!1),[$e,K]=(0,k.useState)(!1),[q,rt]=(0,k.useState)(10),[it,at]=(0,k.useState)(30),[ot,st]=(0,k.useState)(null),[J,Y]=(0,k.useState)(null),[ct,lt]=(0,k.useState)(!0),[ut,dt]=(0,k.useState)(!1),[ft,pt]=(0,k.useState)(!1),[mt,ht]=(0,k.useState)(null),[gt,_t]=(0,k.useState)(!1),X=(0,k.useMemo)(()=>[...Ue(z,H),...M.map(e=>({severity:`error`,code:`CORE_VALIDATION`,nodeId:e.nodeId,message:e.message}))],[z,H,M]),vt=(0,k.useMemo)(()=>We(X),[X]),yt=X.filter(e=>e.severity===`error`).length,[bt,xt]=(0,k.useState)(`manual`),St=(0,k.useRef)(new Map),[Ct,wt]=(0,k.useState)([]),[Tt,Et]=(0,k.useState)(!1),Dt=(0,k.useCallback)(async()=>{try{wt(await C.loopConstants())}catch{}},[]);(0,k.useEffect)(()=>{Dt()},[Dt]);let Ot=(0,k.useMemo)(()=>({loop:Xe}),[]),kt=(0,k.useCallback)(e=>{I(e.graph),R(null);let{nodes:t,edges:n}=Le(e.graph);St.current=new Map(t.map(e=>[e.id,{...e.position}]));let r=e.graph.config?.layout,i=r===`vertical`||r===`horizontal`||r===`grid`?r:`manual`;xt(i),B(i===`manual`?t:Ee(t,n,i)),U(n),Ze(e.name),rt(e.graph.config?.maxIterations??10),at(e.graph.config?.timeoutMinutes??30),st(typeof e.graph.config?.maxCostUsd==`number`?e.graph.config.maxCostUsd:null),Qe(!!e.builtinId)},[B,U]);(0,k.useEffect)(()=>{if(!p)return;let e=!1;return C.get(p).then(t=>{e||kt(t)}).catch(()=>l.error(n(`errors.load`))).finally(()=>{e||lt(!1)}),()=>{e=!0}},[p,kt,n]);let At=(0,k.useCallback)(async()=>{if(p){K(!1);try{kt(await C.restoreBuiltin(p)),N([]),l.success(n(`builder.builtin.restored`))}catch(e){l.error(e instanceof Error&&e.message?e.message:n(`errors.save`))}}},[p,kt,n]),jt=(0,k.useCallback)(e=>{if(N([]),z.find(t=>t.id===e.source)?.data.kind===`core`){U(t=>ve({...e,label:e.sourceHandle,data:{label:e.sourceHandle}},t));return}let t=e.sourceHandle===`continue`||e.sourceHandle===`stop`?e.sourceHandle:void 0,n=t?{...e,data:{branch:t},style:{stroke:t===`stop`?`var(--color-accent-success)`:`var(--color-accent-highlight)`}}:e;U(e=>ve(n,e))},[U,z]),Mt=(0,k.useCallback)(e=>{if(!e.source||!e.target)return!1;let t=z.find(t=>t.id===e.source)?.data.kind,n=z.find(t=>t.id===e.target)?.data.kind;if(!t||!n||e.source===e.target&&t!==`core`||t===`end`)return!1;if(t===`core`){let t=z.find(t=>t.id===e.source),n=Me(w.find(e=>e.kind===t.data.coreKind),t.data.params??{},F?.components);if(!e.sourceHandle||!n.includes(e.sourceHandle)||H.some(t=>t.source===e.source&&t.sourceHandle===e.sourceHandle))return!1}return!(t===`start`&&H.some(t=>t.source===e.source)||n===`start`)},[z,H,w,F]),Nt=(0,k.useCallback)(e=>{xt(e==="default"?`manual`:e),B(t=>e==="default"?t.map(e=>{let t=St.current.get(e.id);return t?{...e,position:{...t}}:e}):Ee(t,H,e)),requestAnimationFrame(()=>v({padding:.25,maxZoom:.85,duration:300}))},[B,H,v]),Pt=(0,k.useCallback)(e=>{e.some(e=>e.type===`position`&&e.dragging===!1)&&xt(`manual`),ze(e)},[ze]),Ft=(0,k.useRef)(z);Ft.current=z;let It=(0,k.useRef)(H);It.current=H,(0,k.useEffect)(()=>{let e=()=>{let e=window.document.activeElement;return!!e&&(e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.isContentEditable)},t=t=>{if(e())return;let n=Be(Ft.current,It.current);!n||!t.clipboardData||(t.clipboardData.setData(`text/plain`,JSON.stringify(n)),t.preventDefault())},r=t=>{if(e())return;let r=Ve(t.clipboardData?.getData(`text/plain`)??``);if(!r)return;t.preventDefault();let i=He(r,{mintId:V,offset:{x:40,y:40},excludeKinds:Ft.current.some(e=>e.data.kind===`start`)?[`start`]:[]});i.nodes.length!==0&&(B(e=>[...e.map(e=>({...e,selected:!1})),...i.nodes]),U(e=>[...e,...i.edges]),xt(`manual`),l.success(n(`builder.paste.done`,{count:i.nodes.length})))};return window.addEventListener(`copy`,t),window.addEventListener(`paste`,r),()=>{window.removeEventListener(`copy`,t),window.removeEventListener(`paste`,r)}},[B,U,n]);let Lt=(0,k.useCallback)(e=>{let t=Ie(e,{x:120+Math.random()*120,y:80+Math.random()*240});B(e=>[...e,t]),Y(t.id)},[B]),Rt=(0,k.useCallback)(e=>{N([]),B(t=>t.map(t=>t.id===J?{...t,data:{...t.data,...e}}:t))},[J,B]),zt=(0,k.useCallback)(()=>{J&&(B(e=>e.filter(e=>e.id!==J)),U(e=>e.filter(e=>e.source!==J&&e.target!==J)),Y(null))},[J,B,U]),Z=!!F&&!z.some(e=>![`start`,`core`,`end`].includes(e.data.kind)),Q=(0,k.useCallback)(()=>{let e={...F?.config,maxIterations:q,timeoutMinutes:it,maxCostUsd:ot??void 0,layout:bt},t=L?F?.components?.[L]:F,n={...t,...Re(z,H,L?t?.config??e:e)};return L?{...F,config:e,components:{...F?.components,[L]:n}}:{...n,components:F?.components}},[F,L,z,H,q,it,ot,bt]),Bt=(0,k.useCallback)((e,t=!1)=>{let n=Q();e&&t&&!n.components?.[e]&&(n.components={...n.components,[e]:{nodes:[{id:V(),type:`start`,position:{x:160,y:40}},{id:V(),type:`core`,position:{x:160,y:220},data:{kind:`end`,params:{outcome:`success`}}}],edges:[],config:{maxIterations:10,timeoutMinutes:0},inputs:[],outputs:[`next`,`failed`]}});let r=e?n.components?.[e]:n;if(!r)return;let i=Le(r);I(n),R(e),B(i.nodes),U(i.edges),Y(null),N([]),requestAnimationFrame(()=>v({padding:.25}))},[Q,B,U,v]),Vt=(0,k.useCallback)((e,t)=>{let n={id:V(),type:`loop`,position:t??{x:160+z.length*20,y:100+z.length*30},data:je(e)};e.kind===`prompt`&&A.providers?.length&&(n.data.params.engine={provider:A.providers[0]}),B(e=>[...e,n]),Y(n.id)},[z.length,B,A.providers]),Ht=(0,k.useCallback)(async()=>{_t(!0);try{let e=Q(),{steps:t}=await C.previewLoop(e);ht(t)}catch{l.error(n(`builder.preview.error`))}finally{_t(!1)}},[Q,n]),Ut=(0,k.useCallback)(async()=>{if(!p)return!1;dt(!0);try{let e=Q();return await C.update(p,{name:W,graph:e}),!0}catch(e){return l.error(e instanceof Error&&e.message?e.message:n(`errors.save`)),!1}finally{dt(!1)}},[p,Q,W,n]),Wt=(0,k.useCallback)(async()=>{if(p&&await Ut())try{await C.publish(p),l.success(n(`builder.published`)),m()}catch(e){e instanceof me?(N(e.errors),pt(!0),l.error(n(`errors.publishInvalid`))):l.error(e instanceof Error&&e.message?e.message:n(`errors.save`))}},[p,Ut,m,n]),$=z.find(e=>e.id===J)??null;return(0,P.jsx)(Ge.Provider,{value:vt,children:(0,P.jsx)(Ke.Provider,{value:{pieces:w,components:F?.components},children:(0,P.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,P.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-4 h-12 border-b border-border flex-shrink-0`,children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,P.jsx)(`button`,{type:`button`,onClick:m,className:`text-muted-foreground hover:text-foreground`,"aria-label":n(`builder.back`),children:(0,P.jsx)(u,{className:`w-4 h-4`})}),(0,P.jsx)(`input`,{value:W,onChange:e=>Ze(e.target.value),className:`text-sm font-semibold bg-transparent text-foreground border-b border-transparent focus:border-border focus:outline-none min-w-0`,"aria-label":`name`})]}),(0,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.jsxs)(pe,{delayDuration:150,children:[(0,P.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[n(`builder.config.maxIterations`),(0,P.jsxs)(T,{children:[(0,P.jsx)(ue,{asChild:!0,children:(0,P.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":n(`builder.config.maxIterations`),children:(0,P.jsx)(S,{className:`w-3 h-3`})})}),(0,P.jsx)(b,{className:`max-w-xs leading-relaxed`,children:n(`builder.config.maxIterationsHint`)})]}),(0,P.jsx)(`input`,{type:`number`,min:1,value:q,onChange:e=>rt(Math.max(1,Number(e.target.value)||1)),className:`w-14 h-6 text-xs rounded border border-border bg-transparent px-1 text-foreground`})]}),(0,P.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[n(`builder.config.timeout`),(0,P.jsxs)(T,{children:[(0,P.jsx)(ue,{asChild:!0,children:(0,P.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":n(`builder.config.timeout`),children:(0,P.jsx)(S,{className:`w-3 h-3`})})}),(0,P.jsx)(b,{className:`max-w-xs leading-relaxed`,children:n(`builder.config.timeoutHint`)})]}),(0,P.jsx)(`input`,{type:`number`,min:0,"aria-label":n(`builder.config.timeout`),value:it,onChange:e=>at(Math.max(0,Number(e.target.value)||0)),className:`w-14 h-6 text-xs rounded border border-border bg-transparent px-1 text-foreground`})]}),(0,P.jsxs)(`label`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[n(`builder.config.maxCost`),(0,P.jsxs)(T,{children:[(0,P.jsx)(ue,{asChild:!0,children:(0,P.jsx)(`button`,{type:`button`,onClick:e=>e.preventDefault(),className:`text-muted-foreground/60 hover:text-foreground`,"aria-label":n(`builder.config.maxCost`),children:(0,P.jsx)(S,{className:`w-3 h-3`})})}),(0,P.jsx)(b,{className:`max-w-xs leading-relaxed`,children:n(`builder.config.maxCostHint`)})]}),(0,P.jsx)(`input`,{type:`number`,min:0,step:.5,placeholder:`∞`,value:ot??``,onChange:e=>{let t=Number(e.target.value);st(e.target.value===``||!(t>0)?null:t)},className:`w-16 h-6 text-xs rounded border border-border bg-transparent px-1 text-foreground`})]})]}),G&&(0,P.jsxs)(`button`,{type:`button`,onClick:()=>K(!0),disabled:ut,"data-testid":`builder-restore-builtin`,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground disabled:opacity-50`,children:[(0,P.jsx)(g,{className:`w-3 h-3`}),` `,n(`actions.restoreBuiltin`)]}),(0,P.jsxs)(`button`,{type:`button`,onClick:()=>void Ht(),disabled:gt,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground disabled:opacity-50`,children:[(0,P.jsx)(fe,{className:`w-3 h-3`}),` `,n(`builder.preview.label`)]}),(0,P.jsxs)(`button`,{type:`button`,onClick:()=>void Ut().then(e=>e&&l.success(n(`builder.saved`))),disabled:ut,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground disabled:opacity-50`,children:[(0,P.jsx)(d,{className:`w-3 h-3`}),` `,n(`builder.save`)]}),(0,P.jsxs)(`button`,{type:`button`,onClick:()=>void Wt(),disabled:ut,className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs bg-accent-primary text-white hover:bg-accent-primary/90 disabled:opacity-50`,children:[(0,P.jsx)(te,{className:`w-3 h-3`}),` `,n(`builder.publish`)]})]})]}),G&&(0,P.jsx)(`div`,{role:`note`,"data-testid":`builder-builtin-note`,className:`px-4 py-1.5 border-b border-border bg-accent-info/10 text-[11px] text-accent-info flex-shrink-0`,children:n(`builder.builtin.note`)}),(0,P.jsx)(se,{open:$e,onOpenChange:e=>{e||K(!1)},children:(0,P.jsxs)(oe,{className:`max-w-sm`,children:[(0,P.jsxs)(ae,{children:[(0,P.jsx)(ie,{children:n(`builder.builtin.confirmTitle`)}),(0,P.jsx)(re,{children:n(`builder.builtin.confirmBody`)})]}),(0,P.jsxs)(ne,{children:[(0,P.jsx)(y,{variant:`ghost`,onClick:()=>K(!1),children:n(`common:actions.cancel`)}),(0,P.jsx)(y,{"data-testid":`builder-restore-confirm`,onClick:()=>void At(),children:n(`actions.restoreBuiltin`)})]})]})}),(0,P.jsxs)(`div`,{className:`flex-1 flex min-h-0`,children:[(0,P.jsxs)(`div`,{className:`w-44 border-r border-border p-2 space-y-1 flex-shrink-0 overflow-y-auto`,children:[(0,P.jsx)(`p`,{className:`text-[10px] font-semibold uppercase tracking-wide text-muted-foreground px-1 mb-1`,children:n(`builder.addNode`)}),Z&&D&&(0,P.jsx)(`p`,{role:`status`,className:`text-xs text-muted-foreground px-1`,children:n(`builder.core.unavailable`)}),Z&&w.length>0&&[`ai`,`verification`,`openspec`,`control`].map(e=>(0,P.jsxs)(`div`,{className:`pt-2`,children:[(0,P.jsx)(`p`,{className:`text-[10px] uppercase text-muted-foreground px-1`,children:n(`builder.core.groups.${e}`)}),w.filter(t=>Ne(t.kind)===e).map(e=>(0,P.jsxs)(`button`,{type:`button`,draggable:!0,onDragStart:t=>{t.dataTransfer.setData(`application/specrails-core-piece`,e.kind),t.dataTransfer.effectAllowed=`copy`},onClick:()=>Vt(e),className:`flex items-center gap-2 w-full min-h-8 px-2 rounded text-left text-xs hover:bg-muted focus-visible:ring-2 focus-visible:ring-accent-primary`,children:[(0,P.jsx)(h,{className:`h-3 w-3 flex-shrink-0`}),n(`builder.core.pieces.${e.kind}`)]},e.kind))]},e)),(Z?[`start`]:qe).map(e=>{let t=Je[e];return(0,P.jsxs)(`button`,{type:`button`,onClick:()=>Lt(e),disabled:e===`start`&&z.some(e=>e.data.kind===`start`),className:`flex items-center gap-2 w-full h-8 px-2 rounded-md text-xs text-muted-foreground hover:text-foreground hover:bg-muted/50`,children:[(0,P.jsx)(t,{className:`w-3.5 h-3.5 flex-shrink-0`}),(0,P.jsx)(`span`,{className:`truncate`,children:n(`builder.nodes.${e}`)}),(0,P.jsx)(h,{className:`w-3 h-3 ml-auto opacity-50`})]},e)})]}),(0,P.jsx)(`div`,{className:`flex-1 min-w-0 relative`,onDragOver:e=>{e.dataTransfer.types.includes(`application/specrails-core-piece`)&&(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},onDrop:e=>{let t=w.find(t=>t.kind===e.dataTransfer.getData(`application/specrails-core-piece`));!t||!Z||(e.preventDefault(),Vt(t,le({x:e.clientX,y:e.clientY})))},children:ct?(0,P.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,P.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`…`})}):(0,P.jsxs)(xe,{nodes:z,edges:H,onNodesChange:Pt,onEdgesChange:Ye,onConnect:jt,isValidConnection:Mt,onNodeClick:(e,t)=>Y(t.id),onPaneClick:()=>Y(null),nodeTypes:Ot,colorMode:_.scheme===`dark`?`dark`:`light`,fitView:!0,fitViewOptions:{padding:.25,maxZoom:.85},minZoom:.2,defaultEdgeOptions:{type:`smoothstep`,markerEnd:{type:Ce.ArrowClosed,width:16,height:16}},proOptions:{hideAttribution:!0},children:[Z&&(0,P.jsx)(O,{position:`top-center`,children:(0,P.jsxs)(`nav`,{className:`flex items-center gap-1 rounded border border-border bg-card/95 p-1 text-xs`,"aria-label":n(`builder.core.breadcrumbs`),children:[(0,P.jsx)(`button`,{type:`button`,onClick:()=>Bt(null),className:`px-2 py-1 hover:bg-muted`,children:W||n(`builder.core.root`)}),L&&(0,P.jsxs)(`span`,{"aria-current":`page`,children:[`/ `,L]})]})}),(0,P.jsx)(Se,{}),(0,P.jsx)(we,{}),(0,P.jsx)(_e,{pannable:!0,zoomable:!0}),(0,P.jsx)(O,{position:`top-left`,children:(0,P.jsx)(`div`,{className:`flex items-center gap-0.5 rounded-md border border-border bg-card/90 backdrop-blur p-0.5`,role:`group`,"aria-label":n(`builder.arrange.label`),children:[[`vertical`,Ae],[`horizontal`,ke],[`grid`,Oe],[`default`,g]].map(([e,t])=>{let r=e==="default"?`reset`:e,i=e==="default"?bt===`manual`:bt===e;return(0,P.jsx)(`button`,{type:`button`,title:n(`builder.arrange.${r}`),"aria-label":n(`builder.arrange.${r}`),"aria-pressed":i,onClick:()=>Nt(e),className:ce(`inline-flex items-center justify-center w-7 h-7 rounded hover:bg-muted`,i?`bg-muted text-accent-primary`:`text-muted-foreground hover:text-foreground`),children:(0,P.jsx)(t,{className:`w-3.5 h-3.5`})},e)})})}),(0,P.jsx)(O,{position:`top-right`,children:(0,P.jsx)(pe,{delayDuration:150,children:(0,P.jsxs)(T,{children:[(0,P.jsx)(ue,{asChild:!0,children:(0,P.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 h-6 px-2 rounded-md text-[10px] border border-border bg-card/90 text-muted-foreground hover:text-foreground backdrop-blur`,children:[(0,P.jsx)(S,{className:`w-3 h-3`}),n(`builder.edgesHelp.label`)]})}),(0,P.jsx)(b,{className:`max-w-xs leading-relaxed`,children:n(`builder.edgesHelp.body`)})]})})}),X.length>0&&(0,P.jsx)(O,{position:`bottom-center`,children:(0,P.jsxs)(`div`,{className:`rounded-md border border-border bg-card/95 backdrop-blur text-xs overflow-hidden max-w-md mb-2`,children:[(0,P.jsxs)(`button`,{type:`button`,onClick:()=>pt(e=>!e),className:ce(`flex items-center gap-1.5 w-full px-2.5 py-1.5 font-medium`,yt>0?`text-destructive`:`text-accent-warning`),children:[(0,P.jsx)(ee,{className:`w-3.5 h-3.5`}),n(`builder.problems.count`,{count:X.length})]}),ft&&(0,P.jsx)(`ul`,{className:`border-t border-border max-h-40 overflow-y-auto py-1`,children:X.map((e,t)=>(0,P.jsx)(`li`,{children:(0,P.jsxs)(`button`,{type:`button`,disabled:!e.nodeId,onClick:()=>e.nodeId&&Y(e.nodeId),className:`flex items-start gap-1.5 w-full text-left px-2.5 py-1 hover:bg-muted disabled:cursor-default`,children:[(0,P.jsx)(`span`,{className:ce(`mt-1 w-1.5 h-1.5 rounded-full flex-shrink-0`,e.severity===`error`?`bg-destructive`:`bg-accent-warning`)}),(0,P.jsx)(`span`,{className:`text-foreground`,children:`message`in e?String(e.message):n(`builder.problems.${e.code}`)})]})},`${e.code}-${e.nodeId??t}`))})]})})]})}),(0,P.jsxs)(`div`,{className:`w-80 border-l border-border p-3 flex-shrink-0 overflow-y-auto space-y-4`,children:[Z&&F&&(0,P.jsx)(Pe,{graph:F,canvas:L,schema:ge,onChange:I,onOpenCanvas:Bt}),$?$.data.kind===`core`?(0,P.jsx)(Fe,{nodeId:$.id,data:$.data,piece:w.find(e=>e.kind===$.data.coreKind),choices:{...A,components:Object.keys(F?.components??{})},schema:ge,onChange:Rt,onDelete:zt,onOpenCanvas:Bt}):(0,P.jsx)(nt,{data:$.data,onChange:Rt,onDelete:zt,constants:Ct,onManageConstants:()=>Et(!0)}):(0,P.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`builder.inspector.selectNode`)})]})]}),(0,P.jsx)(et,{open:Tt,onClose:()=>Et(!1),constants:Ct,onChanged:Dt,t:n}),(0,P.jsx)(tt,{steps:mt,onClose:()=>ht(null),t:n})]})})})}var Ze=[{labelKey:`builder.inspector.tokensSpec`,tokens:[{token:`{{spec.title}}`,label:`spec.title`},{token:`{{spec.description}}`,label:`spec.description`},{token:`{{spec.id}}`,label:`spec.id`},{token:`{{spec.status}}`,label:`spec.status`},{token:`{{spec.priority}}`,label:`spec.priority`},{token:`{{spec.labels}}`,label:`spec.labels`}]},{labelKey:`builder.inspector.tokensJira`,tokens:[{token:`{{spec.jira_key}}`,label:`spec.jira_key`},{token:`{{spec.jira_url}}`,label:`spec.jira_url`}]}];function G({token:e,label:t,description:n,onInsert:r}){return(0,P.jsx)(`button`,{type:`button`,draggable:!0,onDragStart:t=>t.dataTransfer.setData(`text/plain`,e),onClick:()=>r(e),title:n?`${e} — ${n}`:e,className:`px-1.5 py-0.5 rounded border border-border bg-surface/40 text-[10px] font-mono text-accent-primary hover:bg-accent-primary/10 cursor-grab active:cursor-grabbing`,children:t})}function Qe({t:e,onInsert:t}){let[n,r]=(0,k.useState)([]);return(0,k.useEffect)(()=>{let e=!1;return C.loopCommands().then(t=>{e||r(t)}).catch(()=>{}),()=>{e=!0}},[]),(0,P.jsxs)(`div`,{className:`mb-2 space-y-1.5`,children:[Ze.map(n=>(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`span`,{className:`block text-[9px] uppercase tracking-wide text-muted-foreground/70 mb-0.5`,children:e(n.labelKey)}),(0,P.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.tokens.map(e=>(0,P.jsx)(G,{token:e.token,label:e.label,onInsert:t},e.token))})]},n.labelKey)),n.length>0&&(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`span`,{className:`block text-[9px] uppercase tracking-wide text-muted-foreground/70 mb-0.5`,children:e(`builder.inspector.tokensCommands`)}),(0,P.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>(0,P.jsx)(G,{token:`{{cmd:${e.name}}}`,label:`⚡ ${e.label}`,description:e.description,onInsert:t},e.name))})]})]})}function $e({t:e,constants:t,onInsert:n,onManage:r}){return(0,P.jsxs)(`div`,{className:`mb-2`,children:[(0,P.jsxs)(`div`,{className:`flex items-center justify-between mb-0.5`,children:[(0,P.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:e(`builder.constants.label`)}),(0,P.jsx)(`button`,{type:`button`,onClick:r,title:e(`builder.constants.manage`),"aria-label":e(`builder.constants.manage`),className:`text-muted-foreground hover:text-foreground`,children:(0,P.jsx)(ge,{className:`w-3 h-3`})})]}),(0,P.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:t.map(e=>(0,P.jsx)(G,{token:`{{const:${e.name}}}`,label:e.builtin?`🔒 ${e.name}`:e.name,description:e.value,onInsert:n},e.id))})]})}function K({c:e,onSave:t,onDelete:n}){let[r,i]=(0,k.useState)(e.value);return(0,P.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,P.jsx)(`code`,{className:`text-[10px] font-mono text-accent-primary w-28 truncate`,title:e.name,children:e.name}),(0,P.jsx)(`input`,{className:`flex-1 text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground`,value:r,onChange:e=>i(e.target.value)}),(0,P.jsx)(`button`,{type:`button`,disabled:r===e.value||!r,onClick:()=>t(r),className:`text-muted-foreground hover:text-foreground disabled:opacity-40`,"aria-label":`save`,children:(0,P.jsx)(d,{className:`w-3.5 h-3.5`})}),(0,P.jsx)(`button`,{type:`button`,onClick:n,className:`text-muted-foreground hover:text-destructive`,"aria-label":`delete`,children:(0,P.jsx)(_,{className:`w-3.5 h-3.5`})})]})}function et({open:e,onClose:t,constants:n,onChanged:r,t:i}){let[a,o]=(0,k.useState)(``),[s,c]=(0,k.useState)(``),[l,u]=(0,k.useState)(null),[d,f]=(0,k.useState)(!1),p=n.filter(e=>e.builtin),m=n.filter(e=>!e.builtin),h=async()=>{f(!0),u(null);try{await C.createConstant(a.trim(),s),o(``),c(``),await r()}catch(e){u(e instanceof Error?e.message:`error`)}finally{f(!1)}},g=`text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`;return(0,P.jsx)(se,{open:e,onOpenChange:e=>{e||t()},children:(0,P.jsxs)(oe,{className:`max-w-md`,children:[(0,P.jsx)(ae,{children:(0,P.jsx)(ie,{children:i(`builder.constants.title`)})}),(0,P.jsxs)(`div`,{className:`space-y-3`,children:[(0,P.jsxs)(`div`,{className:`space-y-1.5`,children:[m.length===0&&(0,P.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`builder.constants.empty`)}),m.map(e=>(0,P.jsx)(K,{c:e,onSave:t=>void C.updateConstant(e.id,t).then(r),onDelete:()=>void C.deleteConstant(e.id).then(r)},e.id))]}),(0,P.jsxs)(`div`,{className:`flex items-center gap-1.5 border-t border-border pt-2`,children:[(0,P.jsx)(`input`,{className:`${g} w-28`,placeholder:i(`builder.constants.name`),value:a,onChange:e=>o(e.target.value)}),(0,P.jsx)(`input`,{className:`${g} flex-1`,placeholder:i(`builder.constants.value`),value:s,onChange:e=>c(e.target.value)}),(0,P.jsx)(y,{size:`sm`,disabled:d||!a.trim()||!s,onClick:()=>void h(),children:i(`builder.constants.add`)})]}),l&&(0,P.jsx)(`p`,{className:`text-[10px] text-destructive`,children:l}),p.length>0&&(0,P.jsxs)(`div`,{className:`border-t border-border pt-2 space-y-1`,children:[(0,P.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:i(`builder.constants.builtinBadge`)}),p.map(e=>(0,P.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px]`,children:[(0,P.jsx)(`code`,{className:`font-mono text-accent-primary w-28 truncate`,title:e.name,children:e.name}),(0,P.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.value})]},e.id))]})]}),(0,P.jsx)(ne,{children:(0,P.jsx)(y,{variant:`ghost`,onClick:t,children:i(`common:actions.close`)})})]})})}function tt({steps:e,onClose:t,t:n}){return(0,P.jsx)(se,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,P.jsxs)(oe,{className:`max-w-2xl`,children:[(0,P.jsx)(ae,{children:(0,P.jsx)(ie,{children:n(`builder.preview.title`)})}),(0,P.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:n(`builder.preview.sampleNote`)}),(0,P.jsxs)(`div`,{className:`space-y-2 max-h-[60vh] overflow-y-auto`,children:[e&&e.length===0&&(0,P.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`builder.preview.empty`)}),e?.map((e,t)=>(0,P.jsxs)(`div`,{className:`rounded-md border border-border`,children:[(0,P.jsxs)(`div`,{className:`px-2.5 py-1 text-[10px] border-b border-border flex items-center gap-1.5`,children:[(0,P.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label||n([`start`,`end`,`ai-step`,`shell`,`decider`,`condition`].includes(e.kind)?`builder.nodes.${e.kind}`:`builder.core.pieces.${e.kind}`)}),(0,P.jsxs)(`span`,{className:`text-muted-foreground`,children:[`· `,n([`start`,`end`,`ai-step`,`shell`,`decider`,`condition`].includes(e.kind)?`builder.nodes.${e.kind}`:`builder.core.pieces.${e.kind}`)]})]}),(0,P.jsx)(`pre`,{className:`px-2.5 py-2 text-[11px] text-foreground whitespace-pre-wrap break-words font-mono`,children:e.text||`—`})]},`${e.nodeId}-${t}`))]}),(0,P.jsx)(ne,{children:(0,P.jsx)(y,{variant:`ghost`,onClick:t,children:n(`common:actions.close`)})})]})})}function nt({data:e,onChange:t,onDelete:n,constants:r,onManageConstants:i}){let{t:o}=a(`loops`),{activeProjectId:s,projects:l}=c(),u=le(l.find(e=>e.id===s)),d=e.kind,f=`block text-[10px] font-medium text-muted-foreground mb-1`,p=`w-full text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`,m=(0,k.useRef)(null),h=(0,k.useRef)(null),g=(n,r,i)=>{let a=n.current,o=String(e[r]??``);if(!a){t({[r]:o+i});return}let s=a.selectionStart??o.length,c=a.selectionEnd??o.length;t({[r]:o.slice(0,s)+i+o.slice(c)}),requestAnimationFrame(()=>{a.focus();let e=s+i.length;a.setSelectionRange(e,e)})},ee=e=>g(m,`prompt`,e);return(0,P.jsxs)(`div`,{className:`space-y-3`,children:[(0,P.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,P.jsx)(`span`,{className:`text-xs font-semibold text-foreground`,children:o(`builder.nodes.${d}`)}),(0,P.jsx)(`button`,{type:`button`,onClick:n,"aria-label":o(`builder.deleteNode`),className:`text-muted-foreground hover:text-destructive`,children:(0,P.jsx)(_,{className:`w-3.5 h-3.5`})})]}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`label`,{className:f,children:o(`builder.inspector.label`)}),(0,P.jsx)(`input`,{className:p,value:String(e.label??``),onChange:e=>t({label:e.target.value}),placeholder:o(`builder.nodes.${d}`)})]}),d===`ai-step`&&(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`label`,{className:f,children:o(`builder.inspector.prompt`)}),(0,P.jsx)(Qe,{t:o,onInsert:ee}),(0,P.jsx)($e,{t:o,constants:r,onInsert:ee,onManage:i}),(0,P.jsx)(`textarea`,{ref:m,rows:7,className:p,value:String(e.prompt??``),onChange:e=>t({prompt:e.target.value})}),(0,P.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-1`,children:o(`builder.inspector.promptHint`)})]}),d===`shell`&&(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`label`,{className:f,children:o(`builder.inspector.command`)}),(0,P.jsx)(`input`,{className:p,value:String(e.command??``),onChange:e=>t({command:e.target.value}),placeholder:`npm test`}),(0,P.jsxs)(`label`,{className:`${f} mt-3`,children:[o(`common:repositories.shellTarget`),(0,P.jsxs)(`select`,{className:p,value:String(e.repositoryId??``),onChange:e=>t({repositoryId:e.target.value||void 0}),children:[(0,P.jsx)(`option`,{value:``,children:o(`common:repositories.shellDefault`)}),u.filter(e=>e.kind===`git`).map(e=>(0,P.jsx)(`option`,{value:e.id,children:e.name},e.id)),!!e.repositoryId&&!u.some(t=>t.id===e.repositoryId)&&(0,P.jsx)(`option`,{value:String(e.repositoryId),children:String(e.repositoryId)})]})]}),(0,P.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o(`common:repositories.shellHint`)})]}),d===`decider`&&(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`label`,{className:f,children:o(`builder.inspector.goal`)}),(0,P.jsx)($e,{t:o,constants:r,onInsert:e=>g(h,`goal`,e),onManage:i}),(0,P.jsx)(`textarea`,{ref:h,rows:4,className:p,value:String(e.goal??``),onChange:e=>t({goal:e.target.value})})]}),d===`condition`&&(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`label`,{className:f,children:o(`builder.inspector.join`)}),(0,P.jsxs)(`select`,{className:p,value:String(e.join??`AND`),onChange:e=>t({join:e.target.value}),children:[(0,P.jsx)(`option`,{value:`AND`,children:`AND`}),(0,P.jsx)(`option`,{value:`OR`,children:`OR`})]})]}),d===`end`&&(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`label`,{className:f,children:o(`builder.inspector.outcome`)}),(0,P.jsxs)(`select`,{className:p,value:String(e.outcome??`success`),onChange:e=>t({outcome:e.target.value}),children:[(0,P.jsx)(`option`,{value:`success`,children:`success`}),(0,P.jsx)(`option`,{value:`failure`,children:`failure`})]})]}),d===`start`&&(0,P.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:o(`builder.inspector.startNote`)})]})}function q({loopId:e,onExit:t}={}){return(0,P.jsx)(Te,{children:(0,P.jsx)(W,{loopId:e,onExit:t})})}export{q as default};
@@ -0,0 +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-Ccc9Dc-D.js";import{Ht as u}from"./index-C4Mv6tV6.js";import{r as d,t as f}from"./TemplatePreviewModal-C7DordpN.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};
@@ -0,0 +1,2 @@
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{u as r}from"./chunk-KS7C4IRE-DEKu087k.js";import{n as i,t as a}from"./createLucideIcon-Bjbbp_KS.js";import{n as o,r as s,s as c}from"./useDesktop-0unHDBJJ.js";import{_ as l,n as u,s as d,u as f}from"./provider-capabilities-Vi1ZGvAK.js";import{t as p}from"./download-CFHyyHcw.js";import{t as m}from"./pencil-C9RkrIPZ.js";import{n as h}from"./square-Ci-PFcFe.js";import{t as g}from"./plus-CsnjfkmX.js";import{t as _}from"./rotate-ccw-Wh4id13q.js";import{t as v}from"./sparkles-DrY8hb0X.js";import{t as y}from"./trash-2-BOU3WdZZ.js";import{t as b}from"./upload-DYMjAQ6M.js";import{a as x,i as S,l as C,o as w,r as T,t as E}from"./dialog-xXB2q5HJ.js";import{t as D}from"./utils-BC4DHlz2.js";import{t as O}from"./button-Ccc9Dc-D.js";import{t as ee}from"./RepositoryScopeSelector-C2mvWBQ6.js";import{$ as k,Nt as A,Pt as j,Q as te,U as M,W as N,X as P,Y as F,Z as I,ot as L}from"./index-C4Mv6tV6.js";import{n as R}from"./TemplatePreviewModal-C7DordpN.js";var z=a(`file-down`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 18v-6`,key:`17g6i2`}],[`path`,{d:`m9 15 3 3 3-3`,key:`1npd3o`}]]),ne=a(`file-up`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M12 12v6`,key:`3ahymv`}],[`path`,{d:`m15 15-3-3-3 3`,key:`15xj92`}]]),B=e(t(),1),V=n(),H=[`invalid`,`needs_attention`,`convertible`,`running`,`current`];function re({onConvert:e}){let{t}=i(`loops`),[n,r]=(0,B.useState)(null),[a,o]=(0,B.useState)(!1),[s,c]=(0,B.useState)(``),l=(0,B.useRef)(!0);(0,B.useEffect)(()=>(l.current=!0,()=>{l.current=!1}),[]);async function u(){o(!0),c(``),r(null);try{let e=await I.migration();l.current&&r(e)}catch(e){l.current&&c(e instanceof Error&&e.message?e.message:t(`migration.failed`))}finally{l.current&&o(!1)}}let d=n?n.loops.filter(e=>e.state!==`current`):[];return(0,V.jsxs)(`section`,{className:`rounded-lg border border-border p-3 space-y-2`,"aria-label":t(`migration.title`),children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h2`,{className:`text-sm font-medium text-foreground`,children:t(`migration.title`)}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`migration.description`)})]}),(0,V.jsx)(O,{size:`sm`,variant:`secondary`,disabled:a,onClick:()=>void u(),children:t(a?`migration.checking`:`migration.check`)})]}),s&&(0,V.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:s}),n&&(0,V.jsxs)(`div`,{role:`status`,className:`space-y-2 text-xs`,children:[(0,V.jsx)(`p`,{children:H.filter(e=>n.summary[e]>0).map(e=>t(`migration.states.${e}`)+`: `+n.summary[e]).join(` · `)||t(`migration.empty`)}),d.length===0&&n.loops.length>0&&(0,V.jsx)(`p`,{className:`text-muted-foreground`,children:t(`migration.allCurrent`)}),(0,V.jsx)(`ul`,{className:`space-y-1`,children:d.map(n=>(0,V.jsxs)(`li`,{className:`flex flex-wrap items-center gap-2`,children:[(0,V.jsx)(`span`,{className:`font-medium`,children:n.name}),(0,V.jsxs)(`span`,{className:`text-muted-foreground`,children:[t(`migration.states.${n.state}`),n.status===`published`?` · ${t(`status.published`)}`:``]}),n.issues.slice(0,3).map((e,t)=>(0,V.jsx)(`span`,{className:`text-destructive`,children:e.message},t)),n.state===`convertible`&&(0,V.jsx)(O,{size:`sm`,variant:`ghost`,onClick:()=>e(n.id),children:t(`actions.convert`)})]},n.id))})]})]})}function ie(e){return{specrailsLoops:1,loops:e.map(e=>({name:e.name,description:e.description,graph:e.graph}))}}function U(e){let t=e;return!!t&&typeof t.name==`string`&&!!t.graph&&typeof t.graph==`object`}function ae(e){let t;try{t=JSON.parse(e)}catch{throw Error(`invalid-json`)}let n=(Array.isArray(t)?t:Array.isArray(t?.loops)?t.loops:U(t)?[t]:[]).filter(U);if(n.length===0)throw Error(`no-loops`);return n.map(e=>({name:e.name,description:e.description??null,graph:e.graph}))}function oe(e){return e.length===1?`${e[0].name.trim().toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`loop`}.loop.json`:`specrails-loops-${e.length}.json`}var W=[`API`,`Automation`,`CI`,`Database`,`Debugging`,`DevOps`,`Docs`,`Git`,`Maintenance`,`Performance`,`Planning`,`Quality`,`Review`,`Security`,`Testing`];function se(e,t){let n=t.query.trim().toLowerCase(),r=t.categories;return e.filter(e=>r.length>0&&!(e.category&&r.includes(e.category))?!1:!n||`${e.name} ${e.description} ${e.tags.join(` `)} ${e.category??``} ${e.searchTerms??``}`.toLowerCase().includes(n))}function ce(e){let t=new Map;for(let n of e)n.category&&t.set(n.category,(t.get(n.category)??0)+1);let n=[];for(let e of W){let r=t.get(e);r&&(n.push({category:e,count:r}),t.delete(e))}for(let e of[...t.keys()].sort())n.push({category:e,count:t.get(e)});return n}function le({loop:e,projects:t,onClose:n,onExecute:r}){let{t:a}=i(`loops`),o=e!==null,[s,c]=(0,B.useState)(``),[p,m]=(0,B.useState)(``),[g,_]=(0,B.useState)(``),[v,y]=(0,B.useState)(``),[b,D]=(0,B.useState)(),A=t.find(e=>e.id===(s||t[0]?.id)),j=(0,B.useMemo)(()=>A?.providers??(A?.provider?[A.provider]:[]),[A]),P=p||j[0]||``,F=(0,B.useMemo)(()=>k(P),[P]),I=f(P),L=g&&(F.some(e=>e.value===g)||I&&N(g))?g:te(P),R=l(P,L),z=R.includes(v)?v:u(P,L)??``,ne=R.length>0;return(0,V.jsx)(E,{open:o,onOpenChange:e=>{e||n()},children:(0,V.jsx)(T,{movableResizable:!0,className:`max-w-sm`,children:e&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(w,{children:[(0,V.jsx)(C,{children:a(`run.title`,{name:e.name})}),(0,V.jsx)(S,{children:a(`run.subtitle`)})]}),(0,V.jsx)(`label`,{className:`block text-[11px] font-medium text-muted-foreground`,children:a(`run.project`)}),t.length===0?(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a(`run.noProjects`)}):(0,V.jsx)(`select`,{"aria-label":a(`run.project`),"data-testid":`run-project-select`,value:s||t[0]?.id,onChange:e=>{c(e.target.value),m(``),_(``),y(``),D(void 0)},className:`w-full text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`,children:t.map(e=>(0,V.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,V.jsx)(ee,{repositories:A?.repositories??[],value:b,onChange:D}),j.length>1&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`label`,{className:`block text-[11px] font-medium text-muted-foreground`,children:a(`run.provider`)}),(0,V.jsx)(`select`,{"aria-label":a(`run.provider`),value:P,onChange:e=>{m(e.target.value),_(``),y(``)},className:`w-full text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`,children:j.map(e=>(0,V.jsx)(`option`,{value:e,children:d(e)},e))})]}),F.length>0&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`label`,{className:`block text-[11px] font-medium text-muted-foreground`,children:a(`run.model`)}),I?(0,V.jsx)(M,{value:L,options:F,ariaLabel:a(`run.model`),testId:`run-model-select`,className:`w-full px-2 py-1 text-xs`,onCommit:e=>{_(e),y(u(P,e)??``)}}):(0,V.jsx)(`select`,{"aria-label":a(`run.model`),"data-testid":`run-model-select`,value:L,onChange:e=>{let t=e.target.value;_(t),y(u(P,t)??``)},className:`w-full text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`,children:F.map(e=>(0,V.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),ne&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`label`,{className:`block text-[11px] font-medium text-muted-foreground`,children:a(`run.effort`)}),(0,V.jsx)(`select`,{"aria-label":a(`run.effort`),value:z,onChange:e=>y(e.target.value),className:`w-full text-xs rounded border border-border bg-transparent px-2 py-1 text-foreground focus:outline-none focus:ring-1 focus:ring-accent-primary/40`,children:R.map(e=>(0,V.jsx)(`option`,{value:e,children:e},e))})]}),(0,V.jsxs)(x,{children:[(0,V.jsx)(O,{variant:`ghost`,onClick:n,children:a(`common:actions.cancel`)}),(0,V.jsxs)(O,{onClick:()=>{let e=s||t[0]?.id;e&&r({projectId:e,...b?{repositoryIds:b}:{},provider:j.length>1?P:void 0,model:F.length>0?L:void 0,effort:ne?z:void 0})},disabled:t.length===0,children:[(0,V.jsx)(h,{className:`w-3.5 h-3.5 mr-1.5`}),a(`run.execute`)]})]})]})})})}function ue({loop:e,projects:t,onClose:n,onConverted:r}){let{t:a}=i(`loops`),[o,s]=(0,B.useState)(``),[c,l]=(0,B.useState)(!1),[u,d]=(0,B.useState)(``),f=e.graph.nodes.some(e=>e.type===`shell`&&!e.data?.repositoryId),p=t.flatMap(e=>(e.repositories??[]).map(t=>({key:JSON.stringify([e.id,t.id]),id:t.id,label:`${e.name} / ${t.name}`}))),m=p.find(e=>e.key===o);async function h(){l(!0),d(``);try{r((await I.convert(e.id,m?.id)).loop)}catch(e){d(e instanceof P?e.errors.map(e=>`${e.nodeId?e.nodeId+`: `:``}${e.message}`).join(`
2
+ `):e instanceof Error&&e.message===`engine_unsupported`?a(`conversion.coreRequired`):e instanceof Error?a(`conversion.error`)+`: `+e.message:a(`conversion.error`))}finally{l(!1)}}return(0,V.jsx)(E,{open:!0,onOpenChange:e=>{!e&&!c&&n()},children:(0,V.jsxs)(T,{children:[(0,V.jsxs)(w,{children:[(0,V.jsx)(C,{children:a(`conversion.title`,{name:e.name})}),(0,V.jsx)(S,{children:a(`conversion.description`)})]}),f&&(0,V.jsxs)(`label`,{className:`flex flex-col gap-2 text-sm`,children:[a(`conversion.repository`),(0,V.jsxs)(`select`,{className:`rounded border border-border bg-background p-2`,value:o,onChange:e=>s(e.target.value),disabled:c,children:[(0,V.jsx)(`option`,{value:``,children:a(`conversion.selectRepository`)}),p.map(e=>(0,V.jsx)(`option`,{value:e.key,children:e.label},e.key))]})]}),u&&(0,V.jsx)(`p`,{role:`alert`,className:`whitespace-pre-wrap text-sm text-destructive`,children:u}),(0,V.jsxs)(x,{children:[(0,V.jsx)(O,{variant:`outline`,disabled:c,onClick:n,children:a(`common:actions.cancel`)}),(0,V.jsx)(O,{disabled:c||f&&!m,onClick:()=>void h(),children:a(c?`conversion.pending`:`conversion.submit`)})]})]})})}var G={draft:`bg-accent-secondary/15 text-accent-secondary ring-accent-secondary/40`,published:`bg-accent-success/15 text-accent-success ring-accent-success/40`};function K({status:e}){let{t}=i(`loops`);return(0,V.jsx)(`span`,{className:D(`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium ring-1 ring-inset`,G[e]),children:t(`status.${e}`)})}function q({onOpenBuilder:e}={}){let{t}=i(`loops`),n=r(),a=(0,B.useCallback)(e=>e.replace(/:/g,`_`),[]),l=(0,B.useCallback)((e,n)=>t(`catalog.${a(e)}.name`,{defaultValue:n}),[t,a]),u=(0,B.useCallback)((e,n)=>t(`catalog.${a(e)}.description`,{defaultValue:n}),[t,a]),[d,f]=(0,B.useState)([]),[m,h]=(0,B.useState)([]),[b,ee]=(0,B.useState)(!0),[k,j]=(0,B.useState)(null),[te,M]=(0,B.useState)(null),[N,H]=(0,B.useState)(null),[U,W]=(0,B.useState)(null),[G,K]=(0,B.useState)(null),[q,J]=(0,B.useState)(new Set),pe=`specrails-desktop:loop-template-filter`,me=(()=>{try{let e=localStorage.getItem(pe),t=e?JSON.parse(e):null;return{query:typeof t?.query==`string`?t.query:``,categories:Array.isArray(t?.categories)?t.categories:[]}}catch{return{query:``,categories:[]}}})(),[Y,he]=(0,B.useState)(me.query),[X,ge]=(0,B.useState)(me.categories);(0,B.useEffect)(()=>{try{localStorage.setItem(pe,JSON.stringify({query:Y,categories:X}))}catch{}},[Y,X]);let _e=(0,B.useCallback)(e=>{ge(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},[]),ve=(0,B.useCallback)(()=>{he(``),ge([])},[]),ye=(0,B.useRef)(null),{projects:be,setActiveProjectId:xe}=s(),Se=(0,B.useCallback)(e=>{J(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Z=(0,B.useCallback)(e=>{if(e.length===0)return;let t=new Blob([JSON.stringify(ie(e),null,2)],{type:`application/json`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=oe(e),r.click(),URL.revokeObjectURL(n)},[]),Ce=(0,B.useCallback)(async e=>{try{let n=await I.legacyGraph(e.id);Z([{...e,name:t(`actions.originalCopyName`,{name:e.name}),graph:n.graph}])}catch{c.error(t(`errors.exportLegacy`))}},[Z,t]),Q=(0,B.useCallback)(async()=>{try{let[e,t]=await Promise.all([I.list(),I.templates()]);f(e),h(t)}catch{c.error(t(`errors.load`))}finally{ee(!1)}},[t]);(0,B.useEffect)(()=>{Q()},[Q]);let we=(0,B.useCallback)(async e=>{try{let n=ae(await e.text()),{imported:r,skipped:i}=await I.importLoops(n);await Q(),r.length&&c.success(t(`import.done`,{count:r.length})),i.length&&c.warning(t(`import.skipped`,{count:i.length,names:i.join(`, `)})),!r.length&&!i.length&&c.warning(t(`import.invalid`))}catch(e){let n=e instanceof Error?e.message:``;c.error(t(n===`invalid-json`||n===`no-loops`?`import.invalid`:`errors.save`))}},[Q,t]),$=(0,B.useCallback)(t=>{e?e(t):n(`/loops/${t}/edit`)},[e,n]),Te=(0,B.useCallback)(async()=>{try{let e=await I.create({name:t(`newLoopName`)});$(e.id)}catch{c.error(t(`errors.save`))}},[t,$]),Ee=(0,B.useCallback)(async e=>{try{let t=await I.fromTemplate(e);$(t.id)}catch{c.error(t(`errors.save`))}},[t,$]),De=(0,B.useCallback)(async({projectId:e,provider:r,model:i,effort:a,repositoryIds:o})=>{let s=U;if(s){W(null);try{let{loopRunId:l}=await I.runStandalone(e,s.id,{aiEngine:r,model:i,reasoning_effort:a,...o?{repositoryIds:o}:{}});xe(e),n(`/jobs/${l}`),c.success(t(`run.launched`,{name:s.name}))}catch{c.error(t(`errors.save`))}}},[U,n,xe,t]),Oe=(0,B.useCallback)(async e=>{try{await I.publish(e),await Q()}catch(e){e instanceof P?c.error(t(`errors.publishInvalid`)):c.error(t(`errors.save`))}},[t,Q]),ke=(0,B.useCallback)(async e=>{try{await I.unpublish(e),await Q()}catch{c.error(t(`errors.save`))}},[t,Q]),Ae=(0,B.useCallback)(async e=>{try{await I.duplicate(e),await Q()}catch{c.error(t(`errors.save`))}},[t,Q]),je=(0,B.useCallback)(async()=>{let e=N;if(e){H(null);try{await I.restoreBuiltin(e),await Q(),c.success(t(`builder.builtin.restored`))}catch{c.error(t(`errors.save`))}}},[N,t,Q]),Me=(0,B.useCallback)(e=>j(e),[]),Ne=(0,B.useCallback)(async()=>{let e=k;if(e){j(null);try{await I.remove(e),await Q()}catch{c.error(t(`errors.save`))}}},[k,t,Q]),Pe=d.filter(e=>e.builtinId),Fe=d.filter(e=>!e.builtinId),Ie=Fe.filter(e=>e.status===`draft`),Le=Fe.filter(e=>e.status===`published`),Re=ce(m),ze=se(m.map(e=>({...e,searchTerms:`${l(e.id,e.name)} ${u(e.id,e.description)} ${e.category?t(`categories.${e.category}`,{defaultValue:e.category}):``}`})),{query:Y,categories:X}),Be=Y.trim()!==``||X.length>0;return(0,V.jsxs)(`div`,{className:`h-full overflow-y-auto`,children:[(0,V.jsxs)(`div`,{className:`max-w-5xl mx-auto px-6 py-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-start justify-between mb-6`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,V.jsx)(L,{className:`w-5 h-5 text-accent-primary`}),(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`h1`,{className:`text-lg font-semibold text-foreground`,children:t(`title`)}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:t(`subtitle`)})]})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[q.size>0&&(0,V.jsxs)(`button`,{type:`button`,onClick:()=>Z(d.filter(e=>q.has(e.id))),className:`inline-flex items-center gap-1.5 h-8 px-3 rounded-md text-xs font-medium border border-border text-foreground hover:bg-muted`,children:[(0,V.jsx)(z,{className:`w-3.5 h-3.5`}),t(`actions.export`),` (`,q.size,`)`]}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>ye.current?.click(),className:`inline-flex items-center gap-1.5 h-8 px-3 rounded-md text-xs font-medium border border-border text-foreground hover:bg-muted`,children:[(0,V.jsx)(ne,{className:`w-3.5 h-3.5`}),t(`actions.import`)]}),(0,V.jsx)(`input`,{ref:ye,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&we(t),e.target.value=``}}),(0,V.jsxs)(`button`,{type:`button`,onClick:Te,className:`inline-flex items-center gap-1.5 h-8 px-3 rounded-md text-xs font-medium bg-accent-primary text-white hover:bg-accent-primary/90`,children:[(0,V.jsx)(g,{className:`w-3.5 h-3.5`}),t(`newLoop`)]})]})]}),b?(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`…`}):(0,V.jsxs)(`div`,{className:`space-y-8`,children:[Ie.length===0&&Le.length===0&&(0,V.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-8 text-center`,children:[(0,V.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:t(`empty.title`)}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:t(`empty.body`)})]}),d.length>0&&(0,V.jsx)(re,{onConvert:e=>{let t=d.find(t=>t.id===e);t&&K(t)}}),Le.length>0&&(0,V.jsx)(de,{title:t(`sections.published`),children:Le.map(e=>(0,V.jsx)(fe,{loop:e,selected:q.has(e.id),onToggleSelect:()=>Se(e.id),onEdit:()=>$(e.id),onUnpublish:()=>ke(e.id),onDuplicate:()=>Ae(e.id),onExport:()=>Z([e]),onExportLegacy:e.hasLegacyGraph?()=>void Ce(e):void 0,onConvert:e.graph.nodes.some(e=>e.type===`core`)?void 0:()=>K(e),onDelete:()=>Me(e.id),onRun:F(e.graph)?void 0:()=>W(e)},e.id))}),Ie.length>0&&(0,V.jsx)(de,{title:t(`sections.drafts`),children:Ie.map(e=>(0,V.jsx)(fe,{loop:e,selected:q.has(e.id),onToggleSelect:()=>Se(e.id),onEdit:()=>$(e.id),onPublish:()=>Oe(e.id),onDuplicate:()=>Ae(e.id),onExport:()=>Z([e]),onExportLegacy:e.hasLegacyGraph?()=>void Ce(e):void 0,onConvert:e.graph.nodes.some(e=>e.type===`core`)?void 0:()=>K(e),onDelete:()=>Me(e.id)},e.id))}),Pe.length>0&&(0,V.jsx)(de,{title:t(`sections.builtIn`),children:Pe.map(e=>(0,V.jsx)(fe,{loop:{...e,name:e.builtinModified?e.name:l(e.id,e.name)},builtIn:!0,selected:q.has(e.id),onToggleSelect:()=>Se(e.id),onEdit:()=>$(e.id),onPublish:e.status===`draft`?()=>Oe(e.id):void 0,onDuplicate:()=>Ae(e.id),onExport:()=>Z([e]),onRestore:e.builtinModified?()=>H(e.id):void 0},e.id))}),m.length>0&&(0,V.jsxs)(`section`,{children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-3 mb-2 flex-wrap`,children:[(0,V.jsx)(`h2`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:t(`sections.templates`)}),(0,V.jsx)(`input`,{type:`search`,value:Y,onChange:e=>he(e.target.value),placeholder:t(`gallery.search`),"aria-label":t(`gallery.search`),"data-testid":`template-search`,className:`h-7 w-48 max-w-full rounded-md border border-border bg-surface/40 px-2.5 text-xs text-foreground placeholder:text-muted-foreground/70 focus:outline-none focus:ring-1 focus:ring-accent-primary`})]}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 mb-3`,"data-testid":`category-chips`,children:[Re.map(({category:e,count:n})=>{let r=X.includes(e);return(0,V.jsxs)(`button`,{type:`button`,"aria-pressed":r,onClick:()=>_e(e),className:D(`inline-flex items-center gap-1 h-6 px-2 rounded-full text-[11px] border transition-colors`,r?`border-accent-primary bg-accent-primary/15 text-accent-primary`:`border-border bg-surface/40 text-muted-foreground hover:text-foreground hover:bg-muted`),children:[t(`categories.${e}`,{defaultValue:e}),(0,V.jsx)(`span`,{className:`opacity-60 tabular-nums`,children:n})]},e)}),Be&&(0,V.jsx)(`button`,{type:`button`,onClick:ve,className:`inline-flex items-center h-6 px-2 rounded-full text-[11px] text-accent-primary hover:underline`,children:t(`gallery.clearFilter`)})]}),ze.length===0?(0,V.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-6 text-center`,"data-testid":`template-empty`,children:[(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t(`gallery.noResults`)}),(0,V.jsx)(`button`,{type:`button`,onClick:ve,className:`mt-2 text-xs text-accent-primary hover:underline`,children:t(`gallery.clearFilter`)})]}):(0,V.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:ze.map(e=>(0,V.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-3 flex flex-col gap-2`,"data-testid":`template-card`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(v,{className:`w-3.5 h-3.5 text-accent-highlight flex-shrink-0`}),(0,V.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate`,children:l(e.id,e.name)}),e.category&&(0,V.jsx)(`span`,{className:`ml-auto px-1.5 py-0.5 rounded text-[10px] bg-accent-info/15 text-accent-info flex-shrink-0`,children:t(`categories.${e.category}`,{defaultValue:e.category})})]}),(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground flex-1`,children:u(e.id,e.description)}),(0,V.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[F(e.graph)?(0,V.jsx)(`span`,{title:t(`gallery.needsSpecHint`),className:`px-1.5 py-0.5 rounded text-[10px] bg-accent-secondary/15 text-accent-secondary`,children:t(`gallery.needsSpec`)}):(0,V.jsx)(`span`,{title:t(`gallery.standaloneHint`),className:`px-1.5 py-0.5 rounded text-[10px] bg-accent-success/15 text-accent-success`,children:t(`gallery.standalone`)}),e.tags.map(e=>(0,V.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] bg-muted text-muted-foreground`,children:e},e))]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,V.jsxs)(`button`,{type:`button`,onClick:()=>M({...e,name:l(e.id,e.name),description:u(e.id,e.description)}),className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground`,children:[(0,V.jsx)(A,{className:`w-3 h-3`}),t(`actions.preview`)]}),(0,V.jsxs)(`button`,{type:`button`,onClick:()=>Ee(e.id),className:`inline-flex items-center gap-1.5 h-7 px-2.5 rounded-md text-xs border border-border hover:bg-muted text-foreground`,children:[(0,V.jsx)(p,{className:`w-3 h-3`}),t(`actions.use`)]})]})]},e.id))})]})]})]}),(0,V.jsx)(E,{open:k!==null,onOpenChange:e=>{e||j(null)},children:(0,V.jsxs)(T,{className:`max-w-sm`,children:[(0,V.jsxs)(w,{children:[(0,V.jsxs)(C,{className:`flex items-center gap-2`,children:[(0,V.jsx)(y,{className:`w-4 h-4 text-destructive`}),d.find(e=>e.id===k)?.name??t(`actions.delete`)]}),(0,V.jsx)(S,{children:t(`confirmDelete`)})]}),(0,V.jsxs)(x,{children:[(0,V.jsx)(O,{variant:`ghost`,onClick:()=>j(null),children:t(`common:actions.cancel`)}),(0,V.jsx)(O,{variant:`destructive`,onClick:()=>void Ne(),children:t(`common:actions.delete`)})]})]})}),(0,V.jsx)(E,{open:N!==null,onOpenChange:e=>{e||H(null)},children:(0,V.jsxs)(T,{className:`max-w-sm`,children:[(0,V.jsxs)(w,{children:[(0,V.jsxs)(C,{className:`flex items-center gap-2`,children:[(0,V.jsx)(_,{className:`w-4 h-4`}),t(`builder.builtin.confirmTitle`)]}),(0,V.jsx)(S,{children:t(`builder.builtin.confirmBody`)})]}),(0,V.jsxs)(x,{children:[(0,V.jsx)(O,{variant:`ghost`,onClick:()=>H(null),children:t(`common:actions.cancel`)}),(0,V.jsx)(O,{"data-testid":`confirm-restore-builtin`,onClick:()=>void je(),children:t(`actions.restoreBuiltin`)})]})]})}),(0,V.jsx)(R,{template:te,onClose:()=>M(null),onUse:e=>{M(null),Ee(e)}}),G&&(0,V.jsx)(ue,{loop:G,projects:be,onClose:()=>K(null),onConverted:e=>{f(t=>t.map(t=>t.id===e.id?e:t)),K(null),$(e.id)}},G.id),(0,V.jsx)(le,{loop:U?{id:U.id,name:U.name}:null,projects:be.map(e=>({id:e.id,name:e.name,providers:o(e),repositories:e.repositories})),onClose:()=>W(null),onExecute:De})]})}function de({title:e,children:t}){return(0,V.jsxs)(`section`,{children:[(0,V.jsx)(`h2`,{className:`text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-2`,children:e}),(0,V.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:t})]})}function fe({loop:e,builtIn:t=!1,selected:n,onToggleSelect:r,onEdit:a,onPublish:o,onUnpublish:s,onDuplicate:c,onExport:l,onExportLegacy:u,onConvert:d,onDelete:f,onRun:g,onRestore:v}){let{t:x}=i(`loops`),S=e.graph?.nodes?.length??0;return(0,V.jsxs)(`div`,{className:`rounded-lg border border-border bg-card p-3 flex flex-col gap-2`,"data-testid":t?`builtin-loop-card`:`loop-card`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:n,onChange:r,"aria-label":x(`actions.select`,{name:e.name}),className:`accent-accent-primary flex-shrink-0`}),(0,V.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate`,children:e.name})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[t&&(0,V.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] bg-muted text-muted-foreground`,"data-testid":`builtin-badge`,children:x(`builtInBadge`)}),(0,V.jsx)(K,{status:e.status})]})]}),(0,V.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[x(`card.nodes`,{count:S}),t&&e.builtinModified&&(0,V.jsxs)(`span`,{className:`ml-1.5 text-accent-secondary`,children:[`· `,x(`card.builtinModified`)]})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-1 flex-wrap`,children:[g&&(0,V.jsx)(J,{icon:h,label:x(`actions.run`),onClick:g}),(0,V.jsx)(J,{icon:m,label:x(`actions.edit`),onClick:a}),o&&(0,V.jsx)(J,{icon:b,label:x(`actions.publish`),onClick:o}),s&&(0,V.jsx)(J,{icon:p,label:x(`actions.unpublish`),onClick:s}),(0,V.jsx)(J,{icon:j,label:x(`actions.duplicate`),onClick:c}),(0,V.jsx)(J,{icon:z,label:x(`actions.export`),onClick:l}),u&&(0,V.jsx)(J,{icon:z,label:x(`actions.exportLegacy`),onClick:u}),d&&(0,V.jsx)(J,{icon:L,label:x(`actions.convert`),onClick:d}),v&&(0,V.jsx)(J,{icon:_,label:x(`actions.restoreBuiltin`),onClick:v}),f&&(0,V.jsx)(J,{icon:y,label:x(`actions.delete`),onClick:f,danger:!0})]})]})}function J({icon:e,label:t,onClick:n,danger:r}){return(0,V.jsx)(`button`,{type:`button`,onClick:n,title:t,"aria-label":t,className:D(`inline-flex items-center justify-center w-7 h-7 rounded-md transition-colors`,r?`text-muted-foreground hover:text-destructive hover:bg-destructive/10`:`text-muted-foreground hover:text-foreground hover:bg-muted`),children:(0,V.jsx)(e,{className:`w-3.5 h-3.5`})})}export{q as default};
@@ -1 +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{r as a}from"./useSharedWebSocket-Dz-HI6De.js";import{n as o,t as s}from"./createLucideIcon-Bjbbp_KS.js";import{r as c}from"./useDesktop-QogiN0zR.js";import{t as l}from"./sparkles-DrY8hb0X.js";import{t as u}from"./x-CBMI9ejn.js";var d=s(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),f=s(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),p=s(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),m=s(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),h=s(`messages-square`,[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]),g=e(t(),1),_=[`title`,`description`,`labels`,`priority`,`acceptanceCriteria`,`repositoryIds`],v={title:``,description:``,labels:[],priority:`medium`,acceptanceCriteria:[]};function y(e){return!e||typeof e!=`object`?!1:e.type===`spec_draft.update`}var b=e(r(),1),x=n(),S=42;function C(e){let t=e.replace(/\s+/g,` `).trim();return t.length<=S?t:t.slice(0,S-1).trimEnd()+`…`}function w({chat:e,projectName:t,onRestore:n,onClose:r}){let{t:i}=o(`chat`),a=C(e.label);return(0,x.jsxs)(`div`,{"data-testid":`minimized-chat-chip-${e.id}`,className:`grid items-start gap-2 w-full max-w-full`,style:{gridTemplateColumns:`auto minmax(0, 1fr) auto`},children:[(0,x.jsx)(T,{kind:e.kind}),(0,x.jsxs)(`button`,{type:`button`,onClick:n,className:`min-w-0 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary/50 rounded overflow-hidden`,"aria-label":i(`chip.restore`,{label:e.label}),title:e.label,children:[(0,x.jsx)(`div`,{className:`text-sm font-medium text-foreground truncate`,children:a}),(0,x.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5 truncate`,children:i(`chip.continueEditing`,{projectName:t})})]}),(0,x.jsx)(`button`,{type:`button`,onClick:r,className:`flex items-center justify-center w-6 h-6 rounded text-muted-foreground hover:text-foreground hover:bg-accent/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary/50`,"aria-label":i(`chip.close`,{label:e.label}),children:(0,x.jsx)(u,{className:`w-3.5 h-3.5`})})]})}function T({kind:e}){let{t}=o(`chat`);return(0,x.jsx)(e===`ai-edit`?l:h,{className:`w-4 h-4 text-accent-primary flex-shrink-0 mt-0.5`,"aria-label":t(e===`ai-edit`?`chip.kindAiEdit`:`chip.kindExploreSpec`)})}function E({chats:e,projects:t,hidden:n,onRestore:r,onClose:i}){let{t:a}=o(`chat`),s=(0,g.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.id,n.name);return e},[t]),c=(0,g.useMemo)(()=>[...e].sort((e,t)=>t.createdAt-e.createdAt),[e]);return n||c.length===0?null:(0,b.createPortal)((0,x.jsxs)(`div`,{"data-testid":`minimized-chats-dock`,"aria-label":a(`dock.minimizedSessions`,{count:c.length}),className:`fixed bottom-4 right-14 z-[70] flex flex-col-reverse gap-2 w-[320px] max-w-[calc(100vw-15rem)] max-h-[70vh] overflow-y-auto pointer-events-none`,children:[c.map(e=>(0,x.jsx)(`div`,{className:`pointer-events-auto glass-card border border-border/30 rounded-lg p-3 shadow-lg w-full`,children:(0,x.jsx)(w,{chat:e,projectName:s.get(e.projectId)??a(`dock.unknownProject`),onRestore:()=>r(e.id),onClose:()=>i(e.id)})},e.id)),c.length>1&&(0,x.jsxs)(`div`,{className:`pointer-events-auto self-end inline-flex items-center gap-1 rounded-full bg-card/80 border border-border/40 px-2 py-0.5 text-[10px] text-muted-foreground backdrop-blur-sm`,children:[(0,x.jsx)(p,{className:`w-3 h-3`}),a(`dock.minimizedCount`,{count:c.length})]})]}),document.body)}var D=(0,g.createContext)(null),O=`specrails-desktop:minimized-chats`,k=`specrails-desktop:minimized-chats-pending`,A=50,j=8e3;function M(){return I(O)}function N(e){R(O,e)}function P(){return I(k)}function F(e){R(k,e)}function I(e){if(typeof window>`u`)return[];try{let t=window.localStorage.getItem(e);if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(z):[]}catch{return[]}}function L(e){return e.length<=A?e:[...e].sort((e,t)=>e.createdAt-t.createdAt).slice(e.length-A)}function R(e,t){if(!(typeof window>`u`))try{window.localStorage.setItem(e,JSON.stringify(L(t)))}catch{}}function z(e){if(!e||typeof e!=`object`)return!1;let t=e;return!(typeof t.id!=`string`||typeof t.projectId!=`string`||typeof t.label!=`string`||typeof t.restoreRoute!=`string`||typeof t.createdAt!=`number`||t.kind!==`explore-spec`&&t.kind!==`ai-edit`||!t.params||typeof t.params!=`object`)}function B(){return typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function V(e){return e.kind===`explore-spec`?e.params.resumeConversationId??`pending:${e.params.pendingSpecId}`:e.params.resumeRefineId??`agent:${e.params.agentId}`}function H(e,t){return e.kind!==t.kind||e.projectId!==t.projectId?!1:V(e)===V(t)}function U({children:e}){let{projects:t,activeProjectId:n,setActiveProjectId:r}=c(),o=i(),{registerHandler:s,unregisterHandler:l}=a(),[u,d]=(0,g.useState)(()=>M()),[f,p]=(0,g.useState)([]),m=(0,g.useRef)(u);m.current=u;let h=(0,g.useRef)(f);h.current=f;let _=(0,g.useRef)(new Map),v=(0,g.useRef)(t);v.current=t;let b=(0,g.useRef)(!1);(0,g.useEffect)(()=>{if(b.current)return;b.current=!0;let e=P();F([]),e.length!==0&&d(t=>{let n=[...t];for(let t of e)n.some(e=>e.id===t.id||H(e,t))||n.push(t);return N(n),m.current=n,n})},[]),(0,g.useEffect)(()=>{let e=_.current;return()=>{for(let t of e.values())clearTimeout(t);e.clear()}},[]),(0,g.useEffect)(()=>{N(u)},[u]),(0,g.useEffect)(()=>{F(f)},[f]);let S=(0,g.useRef)(()=>{}),C=(0,g.useRef)(()=>{});(0,g.useEffect)(()=>{let e=`minimized-chats:spec-draft`;return s(e,e=>{if(!y(e))return;let t=e.conversationId,n=m.current.find(e=>e.kind===`explore-spec`&&e.params.resumeConversationId===t);if(!n)return;let r=e.draft;r.title?.trim()&&S.current(n.id,r.title);let i={};r.title!==void 0&&(i.title=r.title),r.description!==void 0&&(i.description=r.description),r.priority!==void 0&&(i.priority=r.priority),r.labels!==void 0&&(i.labels=r.labels),r.repositoryIds!==void 0&&(i.repositoryIds=r.repositoryIds),r.acceptanceCriteria!==void 0&&(i.acceptanceCriteria=r.acceptanceCriteria),Object.keys(i).length>0&&C.current(n.id,i)}),()=>l(e)},[s,l]),(0,g.useEffect)(()=>{if(t.length===0)return;let e=new Set(t.map(e=>e.id));d(t=>{let n=t.filter(t=>e.has(t.projectId));return n.length===t.length?t:(N(n),m.current=n,n)}),p(t=>{let n=t.filter(t=>e.has(t.projectId));return n.length===t.length?t:(F(n),h.current=n,n)})},[t]);let w=(0,g.useCallback)(e=>{let t=B(),n={...e,id:t,createdAt:Date.now()};if(d(e=>{let t=L([...e.filter(e=>!H(e,n)),n]);return N(t),m.current=t,t}),e.kind===`explore-spec`){let t=e.params.resumeConversationId;t&&fetch(`/api/projects/${e.projectId}/chat/conversations/${t}/minimize`,{method:`POST`}).catch(()=>{})}return t},[]),T=(0,g.useCallback)(e=>{let t=_.current.get(e);t&&(clearTimeout(t),_.current.delete(e))},[]),O=(0,g.useCallback)(e=>{T(e),d(t=>{let n=t.filter(t=>t.id!==e);return N(n),m.current=n,n}),p(t=>{let n=t.filter(t=>t.id!==e);return n.length===t.length?t:(F(n),h.current=n,n)})},[T]),k=(0,g.useCallback)((e,t)=>{let n=t.trim();n&&d(t=>{let r=t.map(t=>t.id===e&&t.label!==n?{...t,label:n}:t);return r===t?t:(m.current=r,r)})},[]),A=(0,g.useCallback)((e,t)=>{d(n=>{let r=n.map(n=>{if(n.id!==e||n.kind!==`explore-spec`)return n;let r={...n.params.draftOverrides??{},...t};return{...n,params:{...n.params,draftOverrides:r}}});return m.current=r,r})},[]),I=(0,g.useCallback)(e=>{let t=m.current.find(t=>t.id===e);if(!t||v.current.length>0&&!v.current.some(e=>e.id===t.projectId))return;if(t.kind===`explore-spec`){let e=t.params.resumeConversationId;e&&fetch(`/api/projects/${t.projectId}/chat/conversations/${e}/restore`,{method:`POST`}).catch(()=>{})}n!==t.projectId&&r(t.projectId),o(t.restoreRoute),p(n=>{let r=[...n.filter(t=>t.id!==e),t];return F(r),h.current=r,r}),d(t=>{let n=t.filter(t=>t.id!==e);return N(n),m.current=n,n}),T(e);let i=setTimeout(()=>{_.current.delete(e),h.current.some(t=>t.id===e)&&(p(t=>{let n=t.filter(t=>t.id!==e);return F(n),h.current=n,n}),d(n=>{if(n.some(n=>n.id===e||H(n,t)))return n;let r=[...n,t];return N(r),m.current=r,r}))},j);_.current.set(e,i)},[n,r,o,T]),R=(0,g.useRef)(I);R.current=I;let z=(0,g.useRef)(O);z.current=O,S.current=k,C.current=A;let V=(0,g.useCallback)((e,t)=>{let n=h.current,r=n.findIndex(n=>n.kind===e&&n.projectId===t);if(r===-1)return null;let i=n[r];return T(i.id),p(e=>{let t=e.filter(e=>e.id!==i.id);return F(t),t}),h.current=n.filter(e=>e.id!==i.id),i},[T]),U=(0,g.useCallback)(e=>{let t=B(),i={...e,id:t,createdAt:Date.now()};n!==e.projectId&&r(e.projectId),o(e.restoreRoute),p(e=>{let t=[...e,i];return F(t),h.current=t,t}),T(t);let a=setTimeout(()=>{_.current.delete(t),h.current.some(e=>e.id===t)&&(p(e=>{let n=e.filter(e=>e.id!==t);return F(n),h.current=n,n}),d(e=>{if(e.some(e=>e.id===t||H(e,i)))return e;let n=[...e,i];return N(n),m.current=n,n}))},j);_.current.set(t,a)},[n,r,o,T]),W=(0,g.useMemo)(()=>({chats:u,pendingRestores:f,minimize:w,updateLabel:k,patchExploreSpecDraft:A,close:O,restore:I,takePendingRestore:V,triggerResume:U}),[u,f,w,k,A,O,I,V,U]);return(0,x.jsxs)(D.Provider,{value:W,children:[e,(0,x.jsx)(E,{chats:u,projects:t,hidden:!1,onRestore:I,onClose:O})]})}function W(){return(0,g.useContext)(D)||{chats:[],pendingRestores:[],minimize:()=>``,updateLabel:()=>{},patchExploreSpecDraft:()=>{},close:()=>{},restore:()=>{},takePendingRestore:()=>null,triggerResume:()=>{}}}function G(e,t,n){let{pendingRestores:r,takePendingRestore:i}=W(),a=(0,g.useRef)(n);a.current=n,(0,g.useEffect)(()=>{if(!t)return;let n=i(e,t);n&&a.current(n)},[r,e,t,i])}export{_ as a,m as c,d,v as i,p as l,W as n,y as o,G as r,h as s,U as t,f as u};
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{t as r}from"./react-dom-DiWzBDP9.js";import{u as i}from"./chunk-KS7C4IRE-DEKu087k.js";import{r as a}from"./useSharedWebSocket-BZMrX4jr.js";import{n as o,t as s}from"./createLucideIcon-Bjbbp_KS.js";import{r as c}from"./useDesktop-0unHDBJJ.js";import{t as l}from"./sparkles-DrY8hb0X.js";import{t as u}from"./x-CBMI9ejn.js";var d=s(`arrow-up`,[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]),f=s(`check`,[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]),p=s(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),m=s(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]),h=s(`messages-square`,[[`path`,{d:`M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z`,key:`1n2ejm`}],[`path`,{d:`M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1`,key:`1qfcsi`}]]),g=e(t(),1),_=[`title`,`description`,`labels`,`priority`,`acceptanceCriteria`,`repositoryIds`],v={title:``,description:``,labels:[],priority:`medium`,acceptanceCriteria:[]};function y(e){return!e||typeof e!=`object`?!1:e.type===`spec_draft.update`}var b=e(r(),1),x=n(),S=42;function C(e){let t=e.replace(/\s+/g,` `).trim();return t.length<=S?t:t.slice(0,S-1).trimEnd()+`…`}function w({chat:e,projectName:t,onRestore:n,onClose:r}){let{t:i}=o(`chat`),a=C(e.label);return(0,x.jsxs)(`div`,{"data-testid":`minimized-chat-chip-${e.id}`,className:`grid items-start gap-2 w-full max-w-full`,style:{gridTemplateColumns:`auto minmax(0, 1fr) auto`},children:[(0,x.jsx)(T,{kind:e.kind}),(0,x.jsxs)(`button`,{type:`button`,onClick:n,className:`min-w-0 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary/50 rounded overflow-hidden`,"aria-label":i(`chip.restore`,{label:e.label}),title:e.label,children:[(0,x.jsx)(`div`,{className:`text-sm font-medium text-foreground truncate`,children:a}),(0,x.jsx)(`div`,{className:`text-[11px] text-muted-foreground mt-0.5 truncate`,children:i(`chip.continueEditing`,{projectName:t})})]}),(0,x.jsx)(`button`,{type:`button`,onClick:r,className:`flex items-center justify-center w-6 h-6 rounded text-muted-foreground hover:text-foreground hover:bg-accent/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary/50`,"aria-label":i(`chip.close`,{label:e.label}),children:(0,x.jsx)(u,{className:`w-3.5 h-3.5`})})]})}function T({kind:e}){let{t}=o(`chat`);return(0,x.jsx)(e===`ai-edit`?l:h,{className:`w-4 h-4 text-accent-primary flex-shrink-0 mt-0.5`,"aria-label":t(e===`ai-edit`?`chip.kindAiEdit`:`chip.kindExploreSpec`)})}function E({chats:e,projects:t,hidden:n,onRestore:r,onClose:i}){let{t:a}=o(`chat`),s=(0,g.useMemo)(()=>{let e=new Map;for(let n of t)e.set(n.id,n.name);return e},[t]),c=(0,g.useMemo)(()=>[...e].sort((e,t)=>t.createdAt-e.createdAt),[e]);return n||c.length===0?null:(0,b.createPortal)((0,x.jsxs)(`div`,{"data-testid":`minimized-chats-dock`,"aria-label":a(`dock.minimizedSessions`,{count:c.length}),className:`fixed bottom-4 right-14 z-[70] flex flex-col-reverse gap-2 w-[320px] max-w-[calc(100vw-15rem)] max-h-[70vh] overflow-y-auto pointer-events-none`,children:[c.map(e=>(0,x.jsx)(`div`,{className:`pointer-events-auto glass-card border border-border/30 rounded-lg p-3 shadow-lg w-full`,children:(0,x.jsx)(w,{chat:e,projectName:s.get(e.projectId)??a(`dock.unknownProject`),onRestore:()=>r(e.id),onClose:()=>i(e.id)})},e.id)),c.length>1&&(0,x.jsxs)(`div`,{className:`pointer-events-auto self-end inline-flex items-center gap-1 rounded-full bg-card/80 border border-border/40 px-2 py-0.5 text-[10px] text-muted-foreground backdrop-blur-sm`,children:[(0,x.jsx)(p,{className:`w-3 h-3`}),a(`dock.minimizedCount`,{count:c.length})]})]}),document.body)}var D=(0,g.createContext)(null),O=`specrails-desktop:minimized-chats`,k=`specrails-desktop:minimized-chats-pending`,A=50,j=8e3;function M(){return I(O)}function N(e){R(O,e)}function P(){return I(k)}function F(e){R(k,e)}function I(e){if(typeof window>`u`)return[];try{let t=window.localStorage.getItem(e);if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(z):[]}catch{return[]}}function L(e){return e.length<=A?e:[...e].sort((e,t)=>e.createdAt-t.createdAt).slice(e.length-A)}function R(e,t){if(!(typeof window>`u`))try{window.localStorage.setItem(e,JSON.stringify(L(t)))}catch{}}function z(e){if(!e||typeof e!=`object`)return!1;let t=e;return!(typeof t.id!=`string`||typeof t.projectId!=`string`||typeof t.label!=`string`||typeof t.restoreRoute!=`string`||typeof t.createdAt!=`number`||t.kind!==`explore-spec`&&t.kind!==`ai-edit`||!t.params||typeof t.params!=`object`)}function B(){return typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function V(e){return e.kind===`explore-spec`?e.params.resumeConversationId??`pending:${e.params.pendingSpecId}`:e.params.resumeRefineId??`agent:${e.params.agentId}`}function H(e,t){return e.kind!==t.kind||e.projectId!==t.projectId?!1:V(e)===V(t)}function U({children:e}){let{projects:t,activeProjectId:n,setActiveProjectId:r}=c(),o=i(),{registerHandler:s,unregisterHandler:l}=a(),[u,d]=(0,g.useState)(()=>M()),[f,p]=(0,g.useState)([]),m=(0,g.useRef)(u);m.current=u;let h=(0,g.useRef)(f);h.current=f;let _=(0,g.useRef)(new Map),v=(0,g.useRef)(t);v.current=t;let b=(0,g.useRef)(!1);(0,g.useEffect)(()=>{if(b.current)return;b.current=!0;let e=P();F([]),e.length!==0&&d(t=>{let n=[...t];for(let t of e)n.some(e=>e.id===t.id||H(e,t))||n.push(t);return N(n),m.current=n,n})},[]),(0,g.useEffect)(()=>{let e=_.current;return()=>{for(let t of e.values())clearTimeout(t);e.clear()}},[]),(0,g.useEffect)(()=>{N(u)},[u]),(0,g.useEffect)(()=>{F(f)},[f]);let S=(0,g.useRef)(()=>{}),C=(0,g.useRef)(()=>{});(0,g.useEffect)(()=>{let e=`minimized-chats:spec-draft`;return s(e,e=>{if(!y(e))return;let t=e.conversationId,n=m.current.find(e=>e.kind===`explore-spec`&&e.params.resumeConversationId===t);if(!n)return;let r=e.draft;r.title?.trim()&&S.current(n.id,r.title);let i={};r.title!==void 0&&(i.title=r.title),r.description!==void 0&&(i.description=r.description),r.priority!==void 0&&(i.priority=r.priority),r.labels!==void 0&&(i.labels=r.labels),r.repositoryIds!==void 0&&(i.repositoryIds=r.repositoryIds),r.acceptanceCriteria!==void 0&&(i.acceptanceCriteria=r.acceptanceCriteria),Object.keys(i).length>0&&C.current(n.id,i)}),()=>l(e)},[s,l]),(0,g.useEffect)(()=>{if(t.length===0)return;let e=new Set(t.map(e=>e.id));d(t=>{let n=t.filter(t=>e.has(t.projectId));return n.length===t.length?t:(N(n),m.current=n,n)}),p(t=>{let n=t.filter(t=>e.has(t.projectId));return n.length===t.length?t:(F(n),h.current=n,n)})},[t]);let w=(0,g.useCallback)(e=>{let t=B(),n={...e,id:t,createdAt:Date.now()};if(d(e=>{let t=L([...e.filter(e=>!H(e,n)),n]);return N(t),m.current=t,t}),e.kind===`explore-spec`){let t=e.params.resumeConversationId;t&&fetch(`/api/projects/${e.projectId}/chat/conversations/${t}/minimize`,{method:`POST`}).catch(()=>{})}return t},[]),T=(0,g.useCallback)(e=>{let t=_.current.get(e);t&&(clearTimeout(t),_.current.delete(e))},[]),O=(0,g.useCallback)(e=>{T(e),d(t=>{let n=t.filter(t=>t.id!==e);return N(n),m.current=n,n}),p(t=>{let n=t.filter(t=>t.id!==e);return n.length===t.length?t:(F(n),h.current=n,n)})},[T]),k=(0,g.useCallback)((e,t)=>{let n=t.trim();n&&d(t=>{let r=t.map(t=>t.id===e&&t.label!==n?{...t,label:n}:t);return r===t?t:(m.current=r,r)})},[]),A=(0,g.useCallback)((e,t)=>{d(n=>{let r=n.map(n=>{if(n.id!==e||n.kind!==`explore-spec`)return n;let r={...n.params.draftOverrides??{},...t};return{...n,params:{...n.params,draftOverrides:r}}});return m.current=r,r})},[]),I=(0,g.useCallback)(e=>{let t=m.current.find(t=>t.id===e);if(!t||v.current.length>0&&!v.current.some(e=>e.id===t.projectId))return;if(t.kind===`explore-spec`){let e=t.params.resumeConversationId;e&&fetch(`/api/projects/${t.projectId}/chat/conversations/${e}/restore`,{method:`POST`}).catch(()=>{})}n!==t.projectId&&r(t.projectId),o(t.restoreRoute),p(n=>{let r=[...n.filter(t=>t.id!==e),t];return F(r),h.current=r,r}),d(t=>{let n=t.filter(t=>t.id!==e);return N(n),m.current=n,n}),T(e);let i=setTimeout(()=>{_.current.delete(e),h.current.some(t=>t.id===e)&&(p(t=>{let n=t.filter(t=>t.id!==e);return F(n),h.current=n,n}),d(n=>{if(n.some(n=>n.id===e||H(n,t)))return n;let r=[...n,t];return N(r),m.current=r,r}))},j);_.current.set(e,i)},[n,r,o,T]),R=(0,g.useRef)(I);R.current=I;let z=(0,g.useRef)(O);z.current=O,S.current=k,C.current=A;let V=(0,g.useCallback)((e,t)=>{let n=h.current,r=n.findIndex(n=>n.kind===e&&n.projectId===t);if(r===-1)return null;let i=n[r];return T(i.id),p(e=>{let t=e.filter(e=>e.id!==i.id);return F(t),t}),h.current=n.filter(e=>e.id!==i.id),i},[T]),U=(0,g.useCallback)(e=>{let t=B(),i={...e,id:t,createdAt:Date.now()};n!==e.projectId&&r(e.projectId),o(e.restoreRoute),p(e=>{let t=[...e,i];return F(t),h.current=t,t}),T(t);let a=setTimeout(()=>{_.current.delete(t),h.current.some(e=>e.id===t)&&(p(e=>{let n=e.filter(e=>e.id!==t);return F(n),h.current=n,n}),d(e=>{if(e.some(e=>e.id===t||H(e,i)))return e;let n=[...e,i];return N(n),m.current=n,n}))},j);_.current.set(t,a)},[n,r,o,T]),W=(0,g.useMemo)(()=>({chats:u,pendingRestores:f,minimize:w,updateLabel:k,patchExploreSpecDraft:A,close:O,restore:I,takePendingRestore:V,triggerResume:U}),[u,f,w,k,A,O,I,V,U]);return(0,x.jsxs)(D.Provider,{value:W,children:[e,(0,x.jsx)(E,{chats:u,projects:t,hidden:!1,onRestore:I,onClose:O})]})}function W(){return(0,g.useContext)(D)||{chats:[],pendingRestores:[],minimize:()=>``,updateLabel:()=>{},patchExploreSpecDraft:()=>{},close:()=>{},restore:()=>{},takePendingRestore:()=>null,triggerResume:()=>{}}}function G(e,t,n){let{pendingRestores:r,takePendingRestore:i}=W(),a=(0,g.useRef)(n);a.current=n,(0,g.useEffect)(()=>{if(!t)return;let n=i(e,t);n&&a.current(n)},[r,e,t,i])}export{_ as a,m as c,d,v as i,p as l,W as n,y as o,G as r,h as s,U as t,f as u};
@@ -1,2 +1,2 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{l as r,r as i}from"./useSharedWebSocket-Dz-HI6De.js";import{n as a,t as o}from"./createLucideIcon-Bjbbp_KS.js";import{n as s,r as c,s as l}from"./useDesktop-QogiN0zR.js";import{s as u}from"./provider-capabilities-Vi1ZGvAK.js";import{t as d}from"./download-CFHyyHcw.js";import{t as f}from"./loader-circle-DcygOQpC.js";import{t as p}from"./search-Cq_gE3Ik.js";import{t as m}from"./trash-2-BOU3WdZZ.js";import{t as h}from"./triangle-alert-H9T4jAmh.js";import{t as g}from"./wrench-BfmNO9Vw.js";import{i as _,l as v,o as y,r as b,t as x}from"./dialog-xXB2q5HJ.js";import{t as S}from"./utils-BC4DHlz2.js";import{t as C}from"./button-Ccc9Dc-D.js";import{t as w}from"./jira-api-DrGxiD9p.js";import{Ft as T,P as E,_t as D,dt as O,gt as k,lt as A,ut as j,zt as ee}from"./index-Cxb288Rj.js";var M=o(`earth`,[[`path`,{d:`M21.54 15H17a2 2 0 0 0-2 2v4.54`,key:`1djwo0`}],[`path`,{d:`M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17`,key:`1tzkfa`}],[`path`,{d:`M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05`,key:`14pb5j`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),te=o(`folder-kanban`,[[`path`,{d:`M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z`,key:`1fr9dc`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M12 10v2`,key:`hh53o1`}],[`path`,{d:`M16 10v6`,key:`1d6xys`}]]),N=o(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),P=o(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),F=e(t(),1),I=n(),ne=[`todo`,`in_progress`,`on_review`,`done`,`cancelled`],L={todo:`todo`,in_progress:`inProgress`,on_review:`onReview`,done:`done`,cancelled:`cancelled`};function R({onConnected:e,onSkip:t,apiBase:n}){let{t:r}=a(`jira`),[i,o]=(0,F.useState)(1),[s,c]=(0,F.useState)(``),[u,d]=(0,F.useState)(``),[f,p]=(0,F.useState)(``),[m,h]=(0,F.useState)(`idle`),[g,_]=(0,F.useState)(null),[v,y]=(0,F.useState)(`cloud`),[b,x]=(0,F.useState)([]),[S,T]=(0,F.useState)(``),[D,O]=(0,F.useState)(``),[k,A]=(0,F.useState)(``),[j,ee]=(0,F.useState)(!1),[M,te]=(0,F.useState)([]),[N,P]=(0,F.useState)({}),[R,re]=(0,F.useState)(``),[H,U]=(0,F.useState)(!1),W=()=>({baseUrl:s.trim(),accountEmail:u.trim()||null,token:f});async function G(){h(`testing`);try{let e=await w.test(W(),n);h(`ok`),_(e.displayName),y(e.deployment)}catch(e){h(`error`),l.error(V(e,r))}}async function K(){o(2),ee(!0);try{let{projects:e}=await w.discoverProjects({...W(),query:S.trim()||void 0},n);x(e)}catch(e){l.error(V(e,r))}finally{ee(!1)}}async function q(){if(o(3),D)try{let{statuses:e}=await w.discoverStatuses({...W(),projectKey:D},n);te(e)}catch{te([])}}async function J(){U(!0);try{let t=Object.fromEntries(Object.entries(N).filter(([,e])=>e));await w.connect({...W(),jiraProjectKey:D.trim(),statusMap:Object.keys(t).length?t:null,discardStatus:R.trim()||null},n),l.success(r(`status.connected`,{key:D.trim()})),e()}catch(e){l.error(V(e,r))}finally{U(!1)}}return(0,I.jsxs)(`div`,{className:`space-y-4`,"data-testid":`jira-wizard`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`wizard.step`,{current:i,total:4})}),t&&(0,I.jsx)(`button`,{type:`button`,onClick:t,className:`text-xs text-muted-foreground hover:text-foreground hover:underline`,"data-testid":`jira-later`,children:r(`wizard.later`)})]}),i===1&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step1Title`)}),(0,I.jsx)(z,{label:r(`creds.baseUrlLabel`),help:r(`creds.baseUrlHelp`),children:(0,I.jsx)(E,{value:s,onChange:e=>{c(e.target.value),h(`idle`)},placeholder:r(`creds.baseUrlPlaceholder`)})}),(0,I.jsx)(z,{label:r(`creds.emailLabel`),help:r(`creds.emailHelp`),children:(0,I.jsx)(E,{value:u,onChange:e=>{d(e.target.value),h(`idle`)},placeholder:r(`creds.emailPlaceholder`)})}),(0,I.jsx)(z,{label:r(`creds.tokenLabel`),help:r(`creds.tokenHelp`),children:(0,I.jsx)(E,{type:`password`,value:f,onChange:e=>{p(e.target.value),h(`idle`)}})}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,I.jsx)(C,{size:`sm`,variant:`outline`,onClick:G,disabled:!s.trim()||!f.trim()||m===`testing`,children:r(m===`testing`?`creds.testing`:m===`ok`?`creds.retest`:`creds.test`)}),m===`ok`&&(0,I.jsxs)(`span`,{className:`text-xs text-accent-success`,"data-testid":`jira-test-ok`,children:[`✓ `,r(`creds.testOk`,{name:g??``}),` · `,r(v===`cloud`?`review.cloud`:`review.dc`)]})]}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsx)(C,{size:`sm`,onClick:K,disabled:m!==`ok`,children:r(`wizard.next`)})})]}),i===2&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step2Title`)}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(E,{value:S,onChange:e=>T(e.target.value),placeholder:r(`project.searchPlaceholder`)}),(0,I.jsx)(C,{size:`sm`,variant:`outline`,onClick:K,children:r(`project.searchPlaceholder`)})]}),j?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`project.loading`)}):b.length===0?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`project.none`)}):(0,I.jsx)(`div`,{className:`max-h-48 space-y-1 overflow-y-auto`,"data-testid":`jira-project-list`,children:b.map(e=>(0,I.jsxs)(`button`,{type:`button`,onClick:()=>{O(e.key),A(e.name)},className:`flex w-full items-center justify-between rounded px-2 py-1.5 text-left text-sm hover:bg-muted ${D===e.key?`bg-muted`:``}`,children:[(0,I.jsx)(`span`,{className:`font-medium`,children:e.key}),(0,I.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.name})]},e.id))}),(0,I.jsx)(z,{label:r(`project.manualLabel`),children:(0,I.jsx)(E,{value:D,onChange:e=>{O(e.target.value.toUpperCase()),A(``)},placeholder:r(`project.manualPlaceholder`)})}),(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>o(1),children:r(`wizard.back`)}),(0,I.jsx)(C,{size:`sm`,onClick:q,disabled:!D.trim(),children:r(`wizard.next`)})]})]}),i===3&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step3Title`)}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`mapping.intro`)}),ne.map(e=>(0,I.jsx)(z,{label:r(`mapping.${L[e]}`),children:(0,I.jsxs)(`select`,{value:N[e]??``,onChange:t=>P(n=>({...n,[e]:t.target.value||void 0})),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm`,children:[(0,I.jsx)(`option`,{value:``,children:r(`mapping.auto`)}),M.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id))]})},e)),(0,I.jsx)(z,{label:r(`discard.configLabel`),help:r(`discard.configHelp`),children:(0,I.jsxs)(`select`,{value:R,onChange:e=>re(e.target.value),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-discard-status-select`,children:[(0,I.jsx)(`option`,{value:``,children:r(`discard.configNone`)}),M.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id))]})}),(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>o(2),children:r(`wizard.back`)}),(0,I.jsx)(C,{size:`sm`,onClick:()=>o(4),children:r(`wizard.next`)})]})]}),i===4&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step4Title`)}),(0,I.jsxs)(`dl`,{className:`space-y-1 text-sm`,children:[(0,I.jsx)(B,{label:r(`review.site`),value:s}),(0,I.jsx)(B,{label:r(`review.project`),value:k?`${D} — ${k}`:D}),(0,I.jsx)(B,{label:r(`review.account`),value:g??u}),(0,I.jsx)(B,{label:r(`review.type`),value:r(v===`cloud`?`review.cloud`:`review.dc`)}),(0,I.jsx)(B,{label:r(`discard.reviewLabel`),value:R||r(`discard.configNone`)})]}),(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>o(3),children:r(`wizard.back`)}),(0,I.jsx)(C,{size:`sm`,onClick:J,disabled:H,children:r(H?`wizard.connecting`:`wizard.connect`)})]})]})]})}function z({label:e,help:t,children:n}){return(0,I.jsxs)(`label`,{className:`block space-y-1`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:e}),n,t&&(0,I.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:t})]})}function B({label:e,value:t}){return(0,I.jsxs)(`div`,{className:`flex justify-between gap-4`,children:[(0,I.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),(0,I.jsx)(`dd`,{className:`truncate text-right font-medium`,children:t})]})}function V(e,t){return e instanceof Error?e.message:t(`errors.generic`)}var re=[`todo`,`in_progress`,`on_review`,`done`,`cancelled`],H={todo:`todo`,in_progress:`inProgress`,on_review:`onReview`,done:`done`,cancelled:`cancelled`};function U({state:e,onChanged:t,apiBase:n}){let{t:r}=a(`jira`),i=e.connection,[o,s]=(0,F.useState)(i.enabled),[c,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)(!1),[p,m]=(0,F.useState)([]),[h,g]=(0,F.useState)([]),[_,v]=(0,F.useState)(i.discardStatus??``),[y,b]=(0,F.useState)(i.statusMap??{}),x=e.outbox??{pending:0,inflight:0,done:0,dead:0},S=(0,F.useCallback)(async()=>{try{let{ops:e}=n?await w.listOutbox(`dead`,n):await w.listOutbox(`dead`);m(e)}catch{m([])}},[n]);(0,F.useEffect)(()=>{S()},[S]),(0,F.useEffect)(()=>{let e=!1;return w.listStatuses(n).then(({statuses:t})=>{e||g(t)}).catch(()=>{e||g([])}),()=>{e=!0}},[n]);async function T(e){let i=_;v(e);try{n?await w.patchConnection({discardStatus:e||null},n):await w.patchConnection({discardStatus:e||null}),t()}catch(e){v(i),l.error(G(e,r))}}async function E(e,i){let a=y,o={...y,[e]:i||void 0};b(o);let s=Object.fromEntries(Object.entries(o).filter(([,e])=>e));try{n?await w.patchConnection({statusMap:Object.keys(s).length?s:null},n):await w.patchConnection({statusMap:Object.keys(s).length?s:null}),t()}catch(e){b(a),l.error(G(e,r))}}async function D(){let e=!o;s(e),f(!0);try{n?await w.setEnabled(e,n):await w.setEnabled(e)}catch(t){s(!e),l.error(G(t,r))}finally{f(!1)}}async function O(){u(!0);try{let e=n?await w.syncNow(n):await w.syncNow();l.success(r(`status.syncedToast`,{count:e.upserted}))}catch(e){l.error(G(e,r))}finally{u(!1)}}async function k(){if(window.confirm(r(`status.disconnectConfirm`))){f(!0);try{n?await w.disconnect(n):await w.disconnect(),l.success(r(`status.disconnectedToast`)),t()}catch(e){l.error(G(e,r))}finally{f(!1)}}}async function A(e){try{n?await w.retryOutbox(e,n):await w.retryOutbox(e),await S()}catch(e){l.error(G(e,r))}}let j=x.pending+x.inflight;return(0,I.jsxs)(`div`,{className:`space-y-4`,"data-testid":`jira-connected`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:r(`status.connected`,{key:i.jiraProjectKey})}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[i.baseUrl,` · `,i.deployment===`cloud`?r(`review.cloud`):r(`review.dc`)]})]}),(0,I.jsx)(`a`,{href:`${i.baseUrl}/browse/${i.jiraProjectKey}`,target:`_blank`,rel:`noreferrer`,className:`text-xs text-accent-primary hover:underline`,children:r(`badge.openInJira`)})]}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border border-border p-3`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:r(`status.enabledLabel`)}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(o?`status.enabledHelp`:`status.pausedHelp`)})]}),(0,I.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":o,"aria-label":r(`status.enabledLabel`),disabled:d,onClick:D,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 ${o?`bg-accent-success`:`bg-input`}`,children:(0,I.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-background shadow-sm transition-transform ${o?`translate-x-4`:`translate-x-0.5`}`})})]}),(0,I.jsxs)(`div`,{className:`rounded-md border border-border p-3`,"data-testid":`jira-status-map`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:r(`wizard.step3Title`)}),(0,I.jsx)(`p`,{className:`mt-0.5 mb-2 text-xs text-muted-foreground`,children:r(`mapping.intro`)}),(0,I.jsx)(`div`,{className:`space-y-2`,children:re.map(e=>(0,I.jsxs)(`label`,{className:`flex items-center justify-between gap-3`,children:[(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r(`mapping.${H[e]}`)}),(0,I.jsxs)(`select`,{value:y[e]??``,onChange:t=>void E(e,t.target.value),className:`w-44 rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-statusmap-${e}`,children:[(0,I.jsx)(`option`,{value:``,children:r(`mapping.auto`)}),h.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id)),y[e]&&!h.some(t=>t.name===y[e])&&(0,I.jsx)(`option`,{value:y[e],children:y[e]})]})]},e))})]}),(0,I.jsxs)(`div`,{className:`rounded-md border border-border p-3`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:r(`discard.configLabel`)}),(0,I.jsx)(`p`,{className:`mt-0.5 mb-2 text-xs text-muted-foreground`,children:r(`discard.configHelp`)}),(0,I.jsxs)(`select`,{value:_,onChange:e=>void T(e.target.value),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-discard-status-select`,children:[(0,I.jsx)(`option`,{value:``,children:r(`discard.configNone`)}),h.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id)),_&&!h.some(e=>e.name===_)&&(0,I.jsx)(`option`,{value:_,children:_})]})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(C,{variant:`outline`,size:`sm`,onClick:O,disabled:c,children:r(c?`status.syncing`:`status.syncNow`)}),(0,I.jsx)(C,{variant:`ghost`,size:`sm`,onClick:k,disabled:d,className:`text-destructive`,children:r(`status.disconnect`)})]}),(0,I.jsxs)(`div`,{className:`rounded-md border border-border p-3`,"data-testid":`jira-outbox`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:r(`outbox.title`)}),x.dead>0?(0,I.jsx)(`p`,{className:`mt-1 text-xs text-accent-warning`,children:r(`outbox.dead`,{count:x.dead})}):j>0?(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:r(`outbox.pending`,{count:j})}):(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:r(`outbox.allSynced`)}),p.length>0&&(0,I.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`outbox.deadHelp`)}),p.map(e=>(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded border border-border/60 px-2 py-1`,children:[(0,I.jsxs)(`span`,{className:`truncate text-xs`,children:[W(e,r),` · `,e.deadReason??e.lastError??``]}),(0,I.jsx)(C,{variant:`outline`,size:`sm`,onClick:()=>A(e.id),children:r(`outbox.retry`)})]},e.id))]})]})]})}function W(e,t){return e.opType===`transition`?t(`outbox.opTransition`):e.opType===`comment`?t(`outbox.opComment`):t(`outbox.opCreate`)}function G(e,t){return e instanceof Error?e.message:t(`errors.generic`)}var K=new Set([`claude`,`codex`,`kimi`]);function q(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 J(){return{updatedAt:null,proxyStatsAvailable:!1,durableSavingsAvailable:!1,outputSavingsAvailable:!1,outputSavingsMethod:null,outputConfidence:null,providers:{codex:q(`codex`),claude:q(`claude`)},lastIssue:null}}var Y={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:J(),lastIssue:null,updatedAt:null};function ie(e){let t=e?.metrics??J();return{...Y,...e,activeProviders:{...Y.activeProviders,...e?.activeProviders},availableProviders:{...Y.availableProviders,...e?.availableProviders},detectedRoutes:{...Y.detectedRoutes,...e?.detectedRoutes},learning:{...Y.learning,...e?.learning},metrics:{...J(),...t,providers:{codex:{...q(`codex`),...t.providers?.codex},claude:{...q(`claude`),...t.providers?.claude}}}}}async function X(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 Z(e){return`${r}/api/projects/${e}`}function Q(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`${Q(e,t)} ${n}`}function ae(){let{t:e}=a(`integrations`),{projects:t}=c(),{registerHandler:n,unregisterHandler:o}=i(),[s,l]=(0,F.useState)(``),[u,d]=(0,F.useState)(`all`),[f,m]=(0,F.useState)(Y),[h,g]=(0,F.useState)(!0),[C,w]=(0,F.useState)(null),[T,E]=(0,F.useState)([]),[ee,M]=(0,F.useState)(!1),[N,P]=(0,F.useState)(!1),[ne,L]=(0,F.useState)(null),[R,z]=(0,F.useState)({jira:0,serena:0,projects:0}),B=(0,F.useCallback)(async()=>{try{let e=await fetch(`${r}/api/global-plugins/headroom`).then(e=>X(e));m(ie(e.state))}finally{g(!1)}},[]);(0,F.useEffect)(()=>{B()},[B]),(0,F.useEffect)(()=>(n(`plugins-page`,e=>{let t=e;t.type===`plugin.headroom_progress`&&(t.line&&E(e=>[...e.slice(-80),t.line]),B())}),()=>o(`plugins-page`)),[n,o,B]),(0,F.useEffect)(()=>{let e=!1;async function n(){let n=await Promise.all(t.map(async e=>{let[t,n]=await Promise.all([fetch(`${Z(e.id)}/jira/connection`).then(e=>X(e)).catch(()=>({connected:!1})),fetch(`${Z(e.id)}/plugins`).then(e=>X(e)).catch(()=>({plugins:[]}))]),r=n.plugins.find(e=>e.name===`serena`);return{jira:+!!t.connected,serena:r&&r.status!==`not-installed`&&r.status!==`orphan`?1:0}}));e||z({jira:n.reduce((e,t)=>e+t.jira,0),serena:n.reduce((e,t)=>e+t.serena,0),projects:t.length})}return n(),()=>{e=!0}},[t]);async function V(e,t){w(e),E([]);try{let e=(await t()).state;e&&m(ie(e))}catch(e){let t=e.payload;t?.state&&m(ie(t.state))}finally{w(null),B()}}let re=(0,F.useMemo)(()=>[{id:`headroom-ai`,title:`Headroom AI`,scope:`global`,icon:D,description:e(`plugins.catalog.headroom.description`),installed:f.installed,status:f.lastIssue?`attention`:f.installed?f.activeProviders.codex||f.activeProviders.claude?f.installSource===`system`?`external-active`:`active`:f.installSource===`system`?`external`:`installed`:`available`,statusLabel:f.lastIssue?e(`plugins.status.attention`):f.installed?f.activeProviders.codex||f.activeProviders.claude?f.installSource===`system`?e(`plugins.status.externalActive`):e(`plugins.status.active`):f.installSource===`system`?e(`plugins.status.external`):e(`plugins.status.installed`):e(`plugins.status.available`),actionKind:f.lastIssue?`review`:f.installed?`manage`:`install`,actionLabel:f.lastIssue?e(`plugins.actions.review`):f.installed?e(`plugins.actions.manage`):e(`plugins.actions.install`),busy:C===`install`,action:()=>{if(f.lastIssue||f.installed){M(!0);return}V(`install`,()=>fetch(`${r}/api/global-plugins/headroom/install`,{method:`POST`}).then(e=>X(e)))}}],[f,C,e]),H=(0,F.useMemo)(()=>[{id:`jira`,title:`Jira`,scope:`project`,icon:te,description:e(`plugins.catalog.jira.description`),installed:R.jira>0,status:R.jira>0?`configured`:`available`,statusLabel:R.jira>0?e(`plugins.status.configuredCount`,{count:R.jira}):e(`plugins.status.available`),actionKind:R.jira>0?`manage`:`install`,actionLabel:R.jira>0?e(`plugins.actions.manage`):e(`plugins.actions.install`),action:()=>L(`jira`)},{id:`serena`,title:`Serena`,scope:`project`,icon:A,description:e(`plugins.catalog.serena.description`),installed:R.serena>0,status:R.serena>0?`installed`:`available`,statusLabel:R.serena>0?e(`plugins.status.installedCount`,{count:R.serena}):e(`plugins.status.available`),actionKind:R.serena>0?`manage`:`install`,actionLabel:R.serena>0?e(`plugins.actions.manage`):e(`plugins.actions.install`),action:()=>L(`serena`)}],[R,e]),U=s.trim().toLowerCase(),W=t=>`${t.title} ${t.description} ${t.statusLabel} ${e(`plugins.scope.${t.scope}`)}`.toLowerCase().includes(U),G=[...re,...H].filter(e=>u!==`all`&&e.scope!==u?!1:W(e)),K=G.filter(e=>e.scope===`global`&&e.installed),q=G.filter(e=>e.scope===`project`&&e.installed),J=G.filter(e=>e.scope===`global`&&!e.installed),Q=G.filter(e=>e.scope===`project`&&!e.installed),$=K.length>0||q.length>0,ae=J.length>0||Q.length>0,ce=[f.installed,R.jira>0,R.serena>0].filter(Boolean).length;return(0,I.jsxs)(`div`,{className:`flex h-full flex-col bg-background`,children:[(0,I.jsxs)(`div`,{className:`border-b border-border px-6 py-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,I.jsx)(`div`,{className:`grid h-9 w-9 place-items-center rounded-lg border border-accent-primary/25 bg-accent-primary/10 text-accent-primary`,children:(0,I.jsx)(k,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`h1`,{className:`text-lg font-semibold tracking-normal`,children:e(`plugins.page.title`)}),(0,I.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:e(`plugins.page.subtitle`)})]}),(0,I.jsxs)(`div`,{className:`mr-12 flex items-center gap-2 rounded-lg border border-border bg-card/60 px-3 py-2 text-xs`,children:[(0,I.jsx)(O,{className:`h-3.5 w-3.5 text-accent-success`}),(0,I.jsx)(`span`,{className:`text-muted-foreground`,children:e(`plugins.page.readyCount`,{count:ce})})]})]}),(0,I.jsxs)(`div`,{className:`mt-4 flex flex-col gap-3 md:flex-row md:items-center`,children:[(0,I.jsxs)(`label`,{className:`relative flex-1`,children:[(0,I.jsx)(p,{className:`pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,I.jsx)(`input`,{value:s,onChange:e=>l(e.target.value),placeholder:e(`plugins.search.placeholder`),className:`h-9 w-full rounded-lg border border-border bg-background pl-9 pr-3 text-sm outline-none transition-colors focus:border-accent-primary/60`})]}),(0,I.jsx)(`div`,{className:`inline-flex h-9 rounded-lg border border-border bg-card p-1`,children:[`all`,`global`,`project`].map(t=>(0,I.jsx)(`button`,{type:`button`,onClick:()=>d(t),className:S(`rounded-md px-3 text-xs capitalize transition-colors`,u===t?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`),children:e(`plugins.filters.${t}`)},t))})]})]}),(0,I.jsxs)(`div`,{className:`flex-1 overflow-auto px-6 py-5`,children:[(0,I.jsxs)(`section`,{className:`mb-6`,children:[(0,I.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,I.jsx)(j,{className:`h-3.5 w-3.5`}),e(`plugins.sections.installed`)]}),$?(0,I.jsx)(oe,{globalPlugins:K,projectPlugins:q}):(0,I.jsx)(se,{text:e(U?`plugins.empty.installedSearch`:`plugins.empty.installed`)})]}),(0,I.jsxs)(`section`,{children:[(0,I.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,I.jsx)(k,{className:`h-3.5 w-3.5`}),e(`plugins.sections.available`)]}),ae?(0,I.jsx)(oe,{globalPlugins:J,projectPlugins:Q}):(0,I.jsx)(se,{text:e(U?`plugins.empty.availableSearch`:`plugins.empty.allInstalled`)})]})]}),(0,I.jsx)(x,{open:ee,onOpenChange:M,children:(0,I.jsxs)(b,{className:`w-[calc(100vw-2rem)] max-w-xl overflow-x-hidden p-4 sm:p-6`,children:[(0,I.jsxs)(y,{children:[(0,I.jsx)(v,{children:e(`plugins.headroom.title`)}),(0,I.jsx)(_,{children:e(`plugins.headroom.dialogDescription`)})]}),(0,I.jsx)(de,{state:f,loading:h,busy:C,logs:T,onInstall:()=>V(`install`,()=>fetch(`${r}/api/global-plugins/headroom/install`,{method:`POST`}).then(e=>X(e))),onToggleProvider:(e,t)=>V(`${t?`deactivate`:`activate`}-${e}`,()=>fetch(`${r}/api/global-plugins/headroom/${t?`deactivate`:`activate`}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:e})}).then(e=>X(e))),onDeactivateAll:()=>V(`deactivate-all`,async()=>{let e={state:f};for(let t of[`codex`,`claude`])f.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=>X(e)));return e}),onUninstall:()=>V(`uninstall`,()=>fetch(`${r}/api/global-plugins/headroom/uninstall`,{method:`POST`}).then(e=>X(e))),onSetPort:e=>V(`port`,()=>fetch(`${r}/api/global-plugins/headroom/port`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({port:e})}).then(e=>X(e))),onOpenDiagnostics:()=>P(!0)})]})}),(0,I.jsx)(ve,{plugin:ne,projects:t,onClose:()=>L(null)}),(0,I.jsx)(xe,{open:N,onClose:()=>P(!1)})]})}function oe({globalPlugins:e,projectPlugins:t}){let{t:n}=a(`integrations`);return(0,I.jsxs)(`div`,{className:S(`grid grid-cols-1 gap-4`,e.length>0&&t.length>0&&`xl:grid-cols-2`),children:[e.length>0&&(0,I.jsxs)(`section`,{children:[(0,I.jsx)(le,{title:n(`plugins.groups.global.title`),detail:n(`plugins.groups.global.detail`),scope:`global`}),(0,I.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,320px))] justify-start gap-3`,children:e.map(e=>(0,I.jsx)(ue,{plugin:e},e.id))})]}),t.length>0&&(0,I.jsxs)(`section`,{children:[(0,I.jsx)(le,{title:n(`plugins.groups.project.title`),detail:n(`plugins.groups.project.detail`),scope:`project`}),(0,I.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,320px))] justify-start gap-3`,children:t.map(e=>(0,I.jsx)(ue,{plugin:e},e.id))})]})]})}function se({text:e}){return(0,I.jsx)(`div`,{className:`flex h-[74px] max-w-[320px] items-center rounded-lg border border-dashed border-border bg-card/35 px-3 text-xs text-muted-foreground`,children:e})}function ce({scope:e}){let{t}=a(`integrations`);return(0,I.jsx)(`span`,{className:S(`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 le({title:e,detail:t,scope:n}){return(0,I.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,I.jsx)(`div`,{className:S(`h-px flex-1`,n===`global`?`bg-accent-primary/30`:`bg-accent-info/30`)}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-card/70 px-2 py-1`,children:[(0,I.jsx)(ce,{scope:n}),(0,I.jsx)(`span`,{className:`text-xs font-medium`,children:e}),(0,I.jsx)(`span`,{className:`hidden text-[11px] text-muted-foreground sm:inline`,children:t})]}),(0,I.jsx)(`div`,{className:S(`h-px flex-1`,n===`global`?`bg-accent-primary/30`:`bg-accent-info/30`)})]})}function ue({plugin:e}){let{t}=a(`integrations`),n=e.icon,r=e.scope===`global`,i=e.status===`attention`,o=e.busy?f:e.actionKind===`install`?d:e.actionKind===`review`?h:P,s=S(`shrink-0 rounded border px-1.5 py-0.5 text-[10px] leading-none`,i?`border-accent-warning/30 bg-accent-warning/10 text-accent-warning`:e.installed?`border-accent-success/25 bg-accent-success/10 text-accent-success`:`border-border bg-muted text-muted-foreground`);return(0,I.jsxs)(`article`,{className:`grid h-[88px] w-full grid-cols-[38px_minmax(0,1fr)_auto] items-center gap-3 rounded-lg border border-border bg-card/70 px-3 transition-colors hover:border-accent-primary/35 hover:bg-card`,children:[(0,I.jsx)(`div`,{className:S(`grid h-[38px] w-[38px] shrink-0 place-items-center rounded-lg border`,r?`border-accent-primary/25 bg-accent-primary/10 text-accent-primary`:`border-accent-info/25 bg-accent-info/10 text-accent-info`),children:(0,I.jsx)(n,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`h2`,{className:`truncate text-sm font-semibold leading-5`,children:e.title}),(0,I.jsx)(`p`,{className:`mt-1 truncate text-[11px] leading-4 text-muted-foreground`,children:e.description}),(0,I.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-1.5`,children:[(0,I.jsx)(ce,{scope:e.scope}),(0,I.jsx)(`span`,{className:s,children:e.statusLabel})]})]}),(0,I.jsxs)(`button`,{type:`button`,disabled:e.busy,onClick:e.action,className:`flex h-7 shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-2.5 text-xs font-medium transition-colors hover:bg-muted disabled:opacity-50`,children:[(0,I.jsx)(o,{className:S(`h-3.5 w-3.5`,e.busy&&`animate-spin`)}),e.busy?t(`plugins.actions.installing`):e.actionLabel]})]})}function de({state:e,loading:t,busy:n,logs:r,onInstall:i,onToggleProvider:o,onDeactivateAll:s,onUninstall:c,onSetPort:l,onOpenDiagnostics:u}){let{t:p}=a(`integrations`),[h,_]=(0,F.useState)(String(e.port)),[v,y]=(0,F.useState)(!1);(0,F.useEffect)(()=>_(String(e.port)),[e.port]),(0,F.useEffect)(()=>{e.installed||y(!1)},[e.installed]);let b=e.activeProviders.codex||e.activeProviders.claude,x=e.installSource===`system`;return(0,I.jsxs)(`aside`,{className:`w-full min-w-0 overflow-hidden rounded-lg border border-border bg-card/80 p-4`,children:[(0,I.jsxs)(`div`,{className:`mb-4 flex items-start gap-3`,children:[(0,I.jsx)(`div`,{className:`grid h-10 w-10 place-items-center rounded-lg border border-accent-primary/25 bg-accent-primary/10 text-accent-primary`,children:(0,I.jsx)(D,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`h2`,{className:`text-sm font-semibold`,children:p(`plugins.headroom.title`)}),(0,I.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:p(`plugins.headroom.panelDescription`)})]})]}),(0,I.jsxs)(`div`,{className:`mb-4 grid grid-cols-3 gap-2 text-xs`,children:[(0,I.jsx)(fe,{label:p(`plugins.headroom.metrics.install`),value:t?p(`plugins.headroom.metrics.checking`):e.installed?p(`plugins.headroom.metrics.ready`):p(`plugins.headroom.metrics.missing`),good:e.installed}),(0,I.jsx)(fe,{label:p(`plugins.headroom.metrics.source`),value:e.installSource===`system`?p(`plugins.headroom.metrics.system`):e.installSource===`managed`?p(`plugins.headroom.metrics.specrails`):p(`plugins.headroom.metrics.none`),good:e.installed}),(0,I.jsx)(fe,{label:p(`plugins.headroom.metrics.proxy`),value:e.proxyRunning?`:${e.port}`:p(b?`plugins.headroom.metrics.starting`:`plugins.headroom.metrics.off`),good:e.proxyRunning||!b})]}),e.lastIssue&&(0,I.jsx)(pe,{issue:e.lastIssue}),e.installed?(0,I.jsxs)(`div`,{className:`mb-4 space-y-2`,children:[(0,I.jsx)(_e,{provider:`codex`,active:e.activeProviders.codex,available:e.availableProviders.codex,detectedRoute:e.detectedRoutes.codex,busy:n===`activate-codex`||n===`deactivate-codex`,onClick:()=>o(`codex`,e.activeProviders.codex)}),(0,I.jsx)(_e,{provider:`claude`,active:e.activeProviders.claude,available:e.availableProviders.claude,detectedRoute:e.detectedRoutes.claude,busy:n===`activate-claude`||n===`deactivate-claude`,onClick:()=>o(`claude`,e.activeProviders.claude)}),b&&(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:s,className:`flex h-8 w-full items-center justify-center gap-2 rounded-lg border border-border bg-background/45 text-xs hover:bg-muted/50 disabled:opacity-50`,children:[n===`deactivate-all`?(0,I.jsx)(f,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(N,{className:`h-3.5 w-3.5`}),p(`plugins.headroom.actions.disableAllRoutes`)]})]}):(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:i,className:`mb-3 flex h-9 w-full items-center justify-center gap-2 rounded-lg bg-accent-primary px-3 text-xs font-medium text-white disabled:opacity-50`,children:[n===`install`?(0,I.jsx)(f,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(d,{className:`h-3.5 w-3.5`}),p(`plugins.headroom.actions.installWithUv`)]}),e.installed&&(0,I.jsx)(me,{state:e}),(0,I.jsxs)(`div`,{className:`mb-4 rounded-lg border border-border bg-background/45 p-3`,children:[(0,I.jsx)(`label`,{className:`mb-1 block text-[11px] font-medium text-muted-foreground`,children:p(`plugins.headroom.port.label`)}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(`input`,{value:h,onChange:e=>_(e.target.value),className:`h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-sm`}),(0,I.jsx)(`button`,{type:`button`,disabled:!!n||Number(h)===e.port,onClick:()=>l(Number(h)),className:`rounded-md border border-border px-2 text-xs hover:bg-muted disabled:opacity-50`,children:p(`plugins.headroom.port.apply`)})]})]}),r.length>0&&(0,I.jsx)(`pre`,{className:`mb-3 max-h-32 overflow-y-auto overflow-x-hidden whitespace-pre-wrap break-words rounded-lg border border-border bg-background/60 p-2 text-[10px] text-muted-foreground`,children:r.join(`
2
- `)}),(0,I.jsxs)(`button`,{type:`button`,onClick:u,className:`mb-2 flex h-8 w-full items-center justify-center gap-2 rounded-lg border border-border text-xs hover:bg-muted/50`,children:[(0,I.jsx)(g,{className:`h-3.5 w-3.5`}),p(`plugins.headroom.actions.viewDiagnostics`)]}),e.installed&&(0,I.jsx)(`div`,{className:`rounded-lg border border-destructive/25 bg-destructive/5 p-3`,children:v?(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`p`,{className:`text-[11px] leading-relaxed text-muted-foreground`,children:p(x?`plugins.headroom.confirmDetach`:`plugins.headroom.confirmUninstall`)}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,I.jsx)(`button`,{type:`button`,disabled:!!n,onClick:()=>y(!1),className:`h-8 rounded-md border border-border text-xs hover:bg-muted/50 disabled:opacity-50`,children:p(`plugins.actions.cancel`)}),(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:c,className:`flex h-8 items-center justify-center gap-2 rounded-md bg-destructive px-2 text-xs font-medium text-destructive-foreground disabled:opacity-50`,children:[n===`uninstall`?(0,I.jsx)(f,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(m,{className:`h-3.5 w-3.5`}),p(x?`plugins.headroom.actions.detach`:`plugins.headroom.actions.uninstall`)]})]})]}):(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:()=>y(!0),className:`flex h-8 w-full items-center justify-center gap-2 rounded-md text-xs font-medium text-destructive hover:bg-destructive/10 disabled:opacity-50`,children:[(0,I.jsx)(m,{className:`h-3.5 w-3.5`}),p(x?`plugins.headroom.actions.detachHeadroom`:`plugins.headroom.actions.uninstallHeadroom`)]})})]})}function fe({label:e,value:t,good:n}){return(0,I.jsxs)(`div`,{className:`rounded-lg border border-border bg-background/45 p-2`,children:[(0,I.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e}),(0,I.jsx)(`div`,{className:S(`mt-0.5 font-medium`,n?`text-foreground`:`text-accent-warning`),children:t})]})}function pe({issue:e}){let{t}=a(`integrations`),n=`plugins.headroom.issues.${e.code}`,r=t(`${n}.title`,{defaultValue:e.title}),i=t(`${n}.guidance`,{defaultValue:e.guidance});return(0,I.jsx)(`div`,{className:`mb-3 rounded-lg border border-accent-warning/35 bg-accent-warning/10 p-3`,children:(0,I.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,I.jsx)(h,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-warning`}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`div`,{className:`text-xs font-medium`,children:r}),(0,I.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-muted-foreground`,children:i}),(0,I.jsx)(`div`,{className:`mt-1 text-[10px] text-muted-foreground`,children:t(`plugins.headroom.issueCode`,{code:e.code})})]})]})})}function me({state:e}){let{t,i18n:n}=a(`integrations`),r=e.metrics,i=r.outputSavingsAvailable,o=[`codex`,`claude`].map(e=>({provider:e,metric:r.providers[e]})),s=t(`plugins.headroom.savings.tokens`),c=o.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=o.some(({metric:e})=>e.inputTokensSaved>0),u=o.some(({metric:e})=>e.active),d=t(i?`plugins.headroom.savings.statusInputOutput`:l?`plugins.headroom.savings.statusInputOnly`:u?`plugins.headroom.savings.statusRouting`:`plugins.headroom.savings.statusInactive`),f=i||l;return(0,I.jsxs)(`div`,{className:`mb-4 rounded-lg border border-border bg-background/45 p-3`,children:[(0,I.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,I.jsx)(ee,{className:`h-3.5 w-3.5 text-accent-primary`}),(0,I.jsx)(`div`,{className:`truncate text-xs font-medium`,children:t(`plugins.headroom.savings.title`)})]}),(0,I.jsx)(`span`,{className:S(`shrink-0 rounded border px-1.5 py-0.5 text-[10px]`,f?`border-accent-success/25 bg-accent-success/10 text-accent-success`:u?`border-accent-primary/25 bg-accent-primary/10 text-accent-primary`:`border-border bg-muted text-muted-foreground`),children:d})]}),(0,I.jsxs)(`div`,{className:`mb-2 rounded-md bg-muted/35 px-2.5 py-2`,children:[(0,I.jsx)(`div`,{className:`mb-1.5 text-[10px] font-medium uppercase text-muted-foreground`,children:t(`plugins.headroom.savings.totals`)}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,I.jsx)(he,{label:t(`plugins.headroom.savings.input`),processed:c.inputTokens>0?$(c.inputTokens,n.language,s):t(`plugins.headroom.savings.noData`),saved:$(c.inputTokensSaved,n.language,s)}),(0,I.jsx)(he,{align:`right`,label:t(`plugins.headroom.savings.output`),processed:c.outputTokens>0?$(c.outputTokens,n.language,s):t(`plugins.headroom.savings.noData`),saved:i?$(c.outputTokensSaved,n.language,s):t(`plugins.headroom.savings.noData`)})]})]}),(0,I.jsx)(`div`,{className:`grid gap-2`,children:o.map(({provider:e,metric:t})=>(0,I.jsx)(ge,{metric:t,outputAvailable:r.outputSavingsAvailable},e))}),(0,I.jsx)(`div`,{className:`mt-2 flex items-center justify-end gap-2 text-[10px] text-muted-foreground`,children:r.updatedAt?t(`plugins.headroom.savings.updatedLive`):t(`plugins.headroom.savings.baselineSamples`,{count:e.learning.baselineSamples})})]})}function he({label:e,processed:t,saved:n,detail:r,align:i=`left`}){let{t:o}=a(`integrations`);return(0,I.jsxs)(`div`,{className:S(`min-w-0`,i===`right`&&`text-right`),children:[(0,I.jsx)(`div`,{className:`text-[10px] font-medium uppercase text-muted-foreground`,children:e}),(0,I.jsxs)(`div`,{className:`mt-1 space-y-0.5 text-[11px]`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-baseline justify-between gap-2`,children:[(0,I.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:o(`plugins.headroom.savings.processed`)}),(0,I.jsx)(`span`,{className:`truncate font-semibold tabular-nums text-foreground`,children:t})]}),(0,I.jsxs)(`div`,{className:`flex min-w-0 items-baseline justify-between gap-2`,children:[(0,I.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:o(`plugins.headroom.savings.saved`)}),(0,I.jsx)(`span`,{className:`truncate font-semibold tabular-nums text-foreground`,children:n})]})]}),r&&(0,I.jsx)(`div`,{className:`mt-1 truncate text-[10px] text-muted-foreground`,children:r})]})}function ge({metric:e,outputAvailable:t}){let{t:n,i18n:r}=a(`integrations`),i=!e.available,o=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:Q(e.requests,r.language)}):i?n(`plugins.headroom.provider.noProjectUsesProvider`):e.active?n(`plugins.headroom.savings.inputSavingsActive`):n(`plugins.headroom.savings.routeDisabled`);return(0,I.jsxs)(`div`,{className:S(`rounded-md border border-border bg-card/45 px-2.5 py-2`,o&&`opacity-70`),children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium`,children:e.label}),e.detectedRoute&&(0,I.jsx)(`span`,{className:`rounded bg-accent-primary/10 px-1.5 py-0.5 text-[9px] uppercase text-accent-primary`,children:n(`plugins.headroom.savings.detected`)})]}),(0,I.jsx)(`div`,{className:`mt-0.5 truncate text-[10px] text-muted-foreground`,children:f}),(0,I.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-3`,children:[(0,I.jsx)(he,{label:n(`plugins.headroom.savings.input`),processed:c,saved:l}),(0,I.jsx)(he,{align:`right`,label:n(`plugins.headroom.savings.output`),processed:u,saved:d})]})]})}function _e({provider:e,active:t,available:n,detectedRoute:r,busy:i,onClick:o}){let{t:s}=a(`integrations`),c=s(n?t?`plugins.headroom.provider.routedThroughHeadroom`:r?`plugins.headroom.provider.detectedExternalRoute`:`plugins.headroom.provider.notRouted`:`plugins.headroom.provider.noProjectUsesProvider`);return(0,I.jsxs)(`button`,{type:`button`,onClick:o,disabled:i||!n,className:`flex w-full items-center gap-3 rounded-lg border border-border bg-background/45 p-3 text-left hover:bg-muted/35 disabled:opacity-50`,children:[(0,I.jsx)(`div`,{className:S(`grid h-8 w-8 place-items-center rounded-md`,t?`bg-accent-success/15 text-accent-success`:`bg-muted text-muted-foreground`),children:i?(0,I.jsx)(f,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(M,{className:`h-3.5 w-3.5`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`div`,{className:`text-xs font-medium capitalize`,children:e}),(0,I.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:c})]}),(0,I.jsx)(`span`,{className:S(`h-5 w-9 rounded-full p-0.5 transition-colors`,t?`bg-accent-success`:`bg-muted`),children:(0,I.jsx)(`span`,{className:S(`block h-4 w-4 rounded-full bg-white shadow transition-transform`,t&&`translate-x-4`)})})]})}function ve({plugin:e,projects:t,onClose:n}){let{t:r}=a(`integrations`),[i,o]=(0,F.useState)(``);(0,F.useEffect)(()=>o(``),[e]);let c=t.find(e=>e.id===i)??null;return(0,I.jsx)(x,{open:!!e,onOpenChange:e=>{e||n()},children:(0,I.jsxs)(b,{className:`w-[calc(100vw-2rem)] max-w-3xl overflow-x-hidden p-4 sm:p-6`,children:[(0,I.jsxs)(y,{children:[(0,I.jsx)(v,{children:r(e===`jira`?`plugins.projectWizard.configureJira`:`plugins.projectWizard.installSerena`)}),(0,I.jsx)(_,{children:r(`plugins.projectWizard.description`)})]}),(0,I.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-[260px_minmax(0,1fr)]`,children:[(0,I.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/70 p-3`,children:[(0,I.jsx)(`div`,{className:`mb-2 text-xs font-medium text-muted-foreground`,children:r(`plugins.projectWizard.chooseProject`)}),(0,I.jsx)(`div`,{className:`max-h-[52vh] space-y-1 overflow-auto`,children:t.map(t=>{let n=e===`serena`&&!s(t).some(e=>K.has(e));return(0,I.jsxs)(`button`,{type:`button`,disabled:n,onClick:()=>o(t.id),className:S(`w-full rounded-md px-2 py-2 text-left transition-colors`,t.id===i?`bg-muted text-foreground`:`text-muted-foreground hover:bg-muted/45 hover:text-foreground`,n&&`cursor-not-allowed opacity-45`),children:[(0,I.jsx)(`div`,{className:`truncate text-xs font-medium`,children:t.name}),(0,I.jsx)(`div`,{className:`truncate text-[10px]`,children:n?r(`plugins.projectWizard.requiresSupportedProvider`,{defaultValue:`Requires Claude, Codex, or Kimi`}):t.path})]},t.id)})})]}),(0,I.jsx)(`div`,{className:`min-h-[360px] rounded-lg border border-border bg-card/70 p-4`,children:c?e===`jira`?(0,I.jsx)(ye,{project:c,onDone:n}):(0,I.jsx)(be,{project:c,onDone:n}):(0,I.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:r(`plugins.projectWizard.selectProjectToContinue`)})})]})]})})}function ye({project:e,onDone:t}){let{t:n}=a(`integrations`),r=Z(e.id),[i,o]=(0,F.useState)(null),[s,c]=(0,F.useState)(!0),[l,u]=(0,F.useState)(null),d=(0,F.useCallback)(async()=>{c(!0),u(null);try{let e=await fetch(`${r}/jira/connection`).then(e=>X(e));o(e)}catch(e){o({connected:!1}),u(e.message)}finally{c(!1)}},[r]);return(0,F.useEffect)(()=>{d()},[d]),s?(0,I.jsxs)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:[(0,I.jsx)(f,{className:`mr-2 h-4 w-4 animate-spin`}),n(`plugins.jira.loading`,{defaultValue:`Loading Jira...`})]}):i?.connected&&i.connection?(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:n(`plugins.jira.titleForProject`,{name:e.name,defaultValue:`Jira for ${e.name}`})}),(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`plugins.jira.configuredDescription`,{defaultValue:`Manage the Jira project, status mapping, discard status, sync, and connection state.`})})]}),(0,I.jsx)(U,{state:i,apiBase:r,onChanged:()=>{d()}})]}):(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:n(`plugins.jira.titleForProject`,{name:e.name,defaultValue:`Jira for ${e.name}`})}),(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:l?n(`plugins.jira.loadFailed`,{message:l,defaultValue:`Could not load the current Jira configuration: ${l}`}):n(`plugins.jira.notConfiguredDescription`,{defaultValue:`Connect this project to Jira.`})})]}),(0,I.jsx)(R,{apiBase:r,onConnected:()=>{d()},onSkip:t})]})}function be({project:e,onDone:t}){let{t:n}=a(`integrations`),r=(0,F.useMemo)(()=>s(e).filter(e=>K.has(e)),[e]),i=r.includes(e.provider)?e.provider:r[0]??e.provider,[o,c]=(0,F.useState)(i),[l,p]=(0,F.useState)(null),[m,g]=(0,F.useState)(null),[_,v]=(0,F.useState)(!1),[y,b]=(0,F.useState)(null),x=(0,F.useRef)(0);(0,F.useEffect)(()=>{c(i),p(null),g(null)},[e.id,i]);let S=(0,F.useCallback)(async()=>{let t=++x.current;b(null);try{let n=`?provider=${encodeURIComponent(o)}`,r=await fetch(`${Z(e.id)}/plugins${n}`).then(e=>X(e));if(t!==x.current)return;let i=r.plugins.find(e=>e.name===`serena`)??null;if(p(i),g(null),i?.status===`not-installed`){let r=await fetch(`${Z(e.id)}/plugins/serena/preview-install${n}`).then(e=>X(e));t===x.current&&g(r)}}catch(e){t===x.current&&b(e.message)}},[e.id,o]);(0,F.useEffect)(()=>{S()},[S]);async function C(){v(!0),b(null);try{await fetch(`${Z(e.id)}/plugins/serena/install`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:o})}).then(e=>X(e)),await S(),t()}catch(e){b(e.message)}finally{v(!1)}}let w=(m?.requirements??[]).every(e=>e.installed&&e.executable&&e.meetsMinimum),E=l?n(`plugins.projectStatus.${l.status}`,{defaultValue:l.status}):``,D=l?.name===`serena`?n(`plugins.catalog.serena.description`):l?.description;return!l&&!y?(0,I.jsxs)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:[(0,I.jsx)(f,{className:`mr-2 h-4 w-4 animate-spin`}),` `,n(`plugins.serena.loading`)]}):(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:n(`plugins.serena.titleForProject`,{name:e.name})}),(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`plugins.serena.description`)})]}),(0,I.jsxs)(`label`,{className:`block space-y-1`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium`,children:n(`plugins.serena.provider`,{defaultValue:`AI provider`})}),(0,I.jsx)(`select`,{"aria-label":n(`plugins.serena.provider`,{defaultValue:`AI provider`}),value:o,disabled:_,onChange:e=>{p(null),g(null),c(e.target.value)},className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-xs`,children:r.map(e=>(0,I.jsx)(`option`,{value:e,children:u(e)},e))})]}),l&&(0,I.jsxs)(`div`,{className:`rounded-lg border border-border bg-background/45 p-3`,children:[(0,I.jsx)(`div`,{className:`text-xs font-medium`,children:n(`plugins.serena.status`,{status:E})}),D&&(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:D})]}),m&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`mb-1 text-xs font-medium`,children:n(`plugins.serena.files`)}),(0,I.jsx)(`ul`,{className:`space-y-1 text-xs font-mono`,children:m.files.map(e=>(0,I.jsxs)(`li`,{className:e.op===`create`?`text-accent-success`:`text-accent-info`,children:[e.op===`create`?`+ `:`~ `,e.path]},e.path))})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`mb-1 text-xs font-medium`,children:n(`plugins.serena.prerequisites`)}),(0,I.jsx)(`ul`,{className:`space-y-1 text-xs`,children:m.requirements.map(e=>(0,I.jsxs)(`li`,{className:`flex items-center gap-2`,children:[e.installed&&e.executable&&e.meetsMinimum?(0,I.jsx)(T,{className:`h-3 w-3 text-accent-success`}):(0,I.jsx)(h,{className:`h-3 w-3 text-accent-warning`}),(0,I.jsxs)(`span`,{children:[e.name,e.minVersion?` >= ${e.minVersion}`:``]}),e.version&&(0,I.jsxs)(`span`,{className:`text-muted-foreground`,children:[`(`,e.version,`)`]})]},e.name))})]})]}),y&&(0,I.jsx)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/10 p-3 text-xs text-destructive`,children:y}),(0,I.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,I.jsx)(`button`,{type:`button`,onClick:t,className:`rounded-md border border-border px-3 py-1.5 text-xs`,children:n(`plugins.actions.cancel`)}),(0,I.jsxs)(`button`,{type:`button`,disabled:_||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:[_?(0,I.jsx)(f,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(d,{className:`h-3.5 w-3.5`}),n(`plugins.actions.install`)]})]})]})}function xe({open:e,onClose:t}){let{t:n}=a(`integrations`),[i,o]=(0,F.useState)(null);return(0,F.useEffect)(()=>{e&&fetch(`${r}/api/global-plugins/headroom/diagnostics`).then(e=>X(e)).then(o).catch(e=>o({error:e.message}))},[e]),(0,I.jsx)(x,{open:e,onOpenChange:e=>{e||t()},children:(0,I.jsxs)(b,{className:`max-w-3xl`,children:[(0,I.jsxs)(y,{children:[(0,I.jsxs)(v,{className:`flex items-center gap-2`,children:[(0,I.jsx)(P,{className:`h-4 w-4`}),` `,n(`plugins.diagnostics.title`)]}),(0,I.jsx)(_,{children:n(`plugins.diagnostics.description`)})]}),(0,I.jsx)(`pre`,{className:`max-h-[62vh] overflow-y-auto overflow-x-hidden whitespace-pre-wrap break-words rounded-lg border border-border bg-background p-3 text-xs`,children:JSON.stringify(i,null,2)})]})})}export{ae as default};
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{l as r,r as i}from"./useSharedWebSocket-BZMrX4jr.js";import{n as a,t as o}from"./createLucideIcon-Bjbbp_KS.js";import{n as s,r as c,s as l}from"./useDesktop-0unHDBJJ.js";import{s as u}from"./provider-capabilities-Vi1ZGvAK.js";import{t as d}from"./download-CFHyyHcw.js";import{t as f}from"./loader-circle-DcygOQpC.js";import{t as p}from"./search-Cq_gE3Ik.js";import{t as m}from"./trash-2-BOU3WdZZ.js";import{t as h}from"./triangle-alert-H9T4jAmh.js";import{t as g}from"./wrench-BfmNO9Vw.js";import{i as _,l as v,o as y,r as b,t as x}from"./dialog-xXB2q5HJ.js";import{t as S}from"./utils-BC4DHlz2.js";import{t as C}from"./button-Ccc9Dc-D.js";import{t as w}from"./jira-api-BYbEPlkr.js";import{Bt as T,I as E,It as D,dt as O,ft as k,pt as A,vt as j,yt as ee}from"./index-C4Mv6tV6.js";var M=o(`earth`,[[`path`,{d:`M21.54 15H17a2 2 0 0 0-2 2v4.54`,key:`1djwo0`}],[`path`,{d:`M7 3.34V5a3 3 0 0 0 3 3a2 2 0 0 1 2 2c0 1.1.9 2 2 2a2 2 0 0 0 2-2c0-1.1.9-2 2-2h3.17`,key:`1tzkfa`}],[`path`,{d:`M11 21.95V18a2 2 0 0 0-2-2a2 2 0 0 1-2-2v-1a2 2 0 0 0-2-2H2.05`,key:`14pb5j`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),te=o(`folder-kanban`,[[`path`,{d:`M4 20h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.93a2 2 0 0 1-1.66-.9l-.82-1.2A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13c0 1.1.9 2 2 2Z`,key:`1fr9dc`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M12 10v2`,key:`hh53o1`}],[`path`,{d:`M16 10v6`,key:`1d6xys`}]]),N=o(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),P=o(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),F=e(t(),1),I=n(),ne=[`todo`,`in_progress`,`on_review`,`done`,`cancelled`],L={todo:`todo`,in_progress:`inProgress`,on_review:`onReview`,done:`done`,cancelled:`cancelled`};function R({onConnected:e,onSkip:t,apiBase:n}){let{t:r}=a(`jira`),[i,o]=(0,F.useState)(1),[s,c]=(0,F.useState)(``),[u,d]=(0,F.useState)(``),[f,p]=(0,F.useState)(``),[m,h]=(0,F.useState)(`idle`),[g,_]=(0,F.useState)(null),[v,y]=(0,F.useState)(`cloud`),[b,x]=(0,F.useState)([]),[S,T]=(0,F.useState)(``),[D,O]=(0,F.useState)(``),[k,A]=(0,F.useState)(``),[j,ee]=(0,F.useState)(!1),[M,te]=(0,F.useState)([]),[N,P]=(0,F.useState)({}),[R,re]=(0,F.useState)(``),[H,U]=(0,F.useState)(!1),W=()=>({baseUrl:s.trim(),accountEmail:u.trim()||null,token:f});async function G(){h(`testing`);try{let e=await w.test(W(),n);h(`ok`),_(e.displayName),y(e.deployment)}catch(e){h(`error`),l.error(V(e,r))}}async function K(){o(2),ee(!0);try{let{projects:e}=await w.discoverProjects({...W(),query:S.trim()||void 0},n);x(e)}catch(e){l.error(V(e,r))}finally{ee(!1)}}async function q(){if(o(3),D)try{let{statuses:e}=await w.discoverStatuses({...W(),projectKey:D},n);te(e)}catch{te([])}}async function J(){U(!0);try{let t=Object.fromEntries(Object.entries(N).filter(([,e])=>e));await w.connect({...W(),jiraProjectKey:D.trim(),statusMap:Object.keys(t).length?t:null,discardStatus:R.trim()||null},n),l.success(r(`status.connected`,{key:D.trim()})),e()}catch(e){l.error(V(e,r))}finally{U(!1)}}return(0,I.jsxs)(`div`,{className:`space-y-4`,"data-testid":`jira-wizard`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`wizard.step`,{current:i,total:4})}),t&&(0,I.jsx)(`button`,{type:`button`,onClick:t,className:`text-xs text-muted-foreground hover:text-foreground hover:underline`,"data-testid":`jira-later`,children:r(`wizard.later`)})]}),i===1&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step1Title`)}),(0,I.jsx)(z,{label:r(`creds.baseUrlLabel`),help:r(`creds.baseUrlHelp`),children:(0,I.jsx)(E,{value:s,onChange:e=>{c(e.target.value),h(`idle`)},placeholder:r(`creds.baseUrlPlaceholder`)})}),(0,I.jsx)(z,{label:r(`creds.emailLabel`),help:r(`creds.emailHelp`),children:(0,I.jsx)(E,{value:u,onChange:e=>{d(e.target.value),h(`idle`)},placeholder:r(`creds.emailPlaceholder`)})}),(0,I.jsx)(z,{label:r(`creds.tokenLabel`),help:r(`creds.tokenHelp`),children:(0,I.jsx)(E,{type:`password`,value:f,onChange:e=>{p(e.target.value),h(`idle`)}})}),(0,I.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,I.jsx)(C,{size:`sm`,variant:`outline`,onClick:G,disabled:!s.trim()||!f.trim()||m===`testing`,children:r(m===`testing`?`creds.testing`:m===`ok`?`creds.retest`:`creds.test`)}),m===`ok`&&(0,I.jsxs)(`span`,{className:`text-xs text-accent-success`,"data-testid":`jira-test-ok`,children:[`✓ `,r(`creds.testOk`,{name:g??``}),` · `,r(v===`cloud`?`review.cloud`:`review.dc`)]})]}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsx)(C,{size:`sm`,onClick:K,disabled:m!==`ok`,children:r(`wizard.next`)})})]}),i===2&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step2Title`)}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(E,{value:S,onChange:e=>T(e.target.value),placeholder:r(`project.searchPlaceholder`)}),(0,I.jsx)(C,{size:`sm`,variant:`outline`,onClick:K,children:r(`project.searchPlaceholder`)})]}),j?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`project.loading`)}):b.length===0?(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`project.none`)}):(0,I.jsx)(`div`,{className:`max-h-48 space-y-1 overflow-y-auto`,"data-testid":`jira-project-list`,children:b.map(e=>(0,I.jsxs)(`button`,{type:`button`,onClick:()=>{O(e.key),A(e.name)},className:`flex w-full items-center justify-between rounded px-2 py-1.5 text-left text-sm hover:bg-muted ${D===e.key?`bg-muted`:``}`,children:[(0,I.jsx)(`span`,{className:`font-medium`,children:e.key}),(0,I.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.name})]},e.id))}),(0,I.jsx)(z,{label:r(`project.manualLabel`),children:(0,I.jsx)(E,{value:D,onChange:e=>{O(e.target.value.toUpperCase()),A(``)},placeholder:r(`project.manualPlaceholder`)})}),(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>o(1),children:r(`wizard.back`)}),(0,I.jsx)(C,{size:`sm`,onClick:q,disabled:!D.trim(),children:r(`wizard.next`)})]})]}),i===3&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step3Title`)}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`mapping.intro`)}),ne.map(e=>(0,I.jsx)(z,{label:r(`mapping.${L[e]}`),children:(0,I.jsxs)(`select`,{value:N[e]??``,onChange:t=>P(n=>({...n,[e]:t.target.value||void 0})),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm`,children:[(0,I.jsx)(`option`,{value:``,children:r(`mapping.auto`)}),M.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id))]})},e)),(0,I.jsx)(z,{label:r(`discard.configLabel`),help:r(`discard.configHelp`),children:(0,I.jsxs)(`select`,{value:R,onChange:e=>re(e.target.value),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-discard-status-select`,children:[(0,I.jsx)(`option`,{value:``,children:r(`discard.configNone`)}),M.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id))]})}),(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>o(2),children:r(`wizard.back`)}),(0,I.jsx)(C,{size:`sm`,onClick:()=>o(4),children:r(`wizard.next`)})]})]}),i===4&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:r(`wizard.step4Title`)}),(0,I.jsxs)(`dl`,{className:`space-y-1 text-sm`,children:[(0,I.jsx)(B,{label:r(`review.site`),value:s}),(0,I.jsx)(B,{label:r(`review.project`),value:k?`${D} — ${k}`:D}),(0,I.jsx)(B,{label:r(`review.account`),value:g??u}),(0,I.jsx)(B,{label:r(`review.type`),value:r(v===`cloud`?`review.cloud`:`review.dc`)}),(0,I.jsx)(B,{label:r(`discard.reviewLabel`),value:R||r(`discard.configNone`)})]}),(0,I.jsxs)(`div`,{className:`flex justify-between`,children:[(0,I.jsx)(C,{size:`sm`,variant:`ghost`,onClick:()=>o(3),children:r(`wizard.back`)}),(0,I.jsx)(C,{size:`sm`,onClick:J,disabled:H,children:r(H?`wizard.connecting`:`wizard.connect`)})]})]})]})}function z({label:e,help:t,children:n}){return(0,I.jsxs)(`label`,{className:`block space-y-1`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:e}),n,t&&(0,I.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:t})]})}function B({label:e,value:t}){return(0,I.jsxs)(`div`,{className:`flex justify-between gap-4`,children:[(0,I.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),(0,I.jsx)(`dd`,{className:`truncate text-right font-medium`,children:t})]})}function V(e,t){return e instanceof Error?e.message:t(`errors.generic`)}var re=[`todo`,`in_progress`,`on_review`,`done`,`cancelled`],H={todo:`todo`,in_progress:`inProgress`,on_review:`onReview`,done:`done`,cancelled:`cancelled`};function U({state:e,onChanged:t,apiBase:n}){let{t:r}=a(`jira`),i=e.connection,[o,s]=(0,F.useState)(i.enabled),[c,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)(!1),[p,m]=(0,F.useState)([]),[h,g]=(0,F.useState)([]),[_,v]=(0,F.useState)(i.discardStatus??``),[y,b]=(0,F.useState)(i.statusMap??{}),x=e.outbox??{pending:0,inflight:0,done:0,dead:0},S=(0,F.useCallback)(async()=>{try{let{ops:e}=n?await w.listOutbox(`dead`,n):await w.listOutbox(`dead`);m(e)}catch{m([])}},[n]);(0,F.useEffect)(()=>{S()},[S]),(0,F.useEffect)(()=>{let e=!1;return w.listStatuses(n).then(({statuses:t})=>{e||g(t)}).catch(()=>{e||g([])}),()=>{e=!0}},[n]);async function T(e){let i=_;v(e);try{n?await w.patchConnection({discardStatus:e||null},n):await w.patchConnection({discardStatus:e||null}),t()}catch(e){v(i),l.error(G(e,r))}}async function E(e,i){let a=y,o={...y,[e]:i||void 0};b(o);let s=Object.fromEntries(Object.entries(o).filter(([,e])=>e));try{n?await w.patchConnection({statusMap:Object.keys(s).length?s:null},n):await w.patchConnection({statusMap:Object.keys(s).length?s:null}),t()}catch(e){b(a),l.error(G(e,r))}}async function D(){let e=!o;s(e),f(!0);try{n?await w.setEnabled(e,n):await w.setEnabled(e)}catch(t){s(!e),l.error(G(t,r))}finally{f(!1)}}async function O(){u(!0);try{let e=n?await w.syncNow(n):await w.syncNow();l.success(r(`status.syncedToast`,{count:e.upserted}))}catch(e){l.error(G(e,r))}finally{u(!1)}}async function k(){if(window.confirm(r(`status.disconnectConfirm`))){f(!0);try{n?await w.disconnect(n):await w.disconnect(),l.success(r(`status.disconnectedToast`)),t()}catch(e){l.error(G(e,r))}finally{f(!1)}}}async function A(e){try{n?await w.retryOutbox(e,n):await w.retryOutbox(e),await S()}catch(e){l.error(G(e,r))}}let j=x.pending+x.inflight;return(0,I.jsxs)(`div`,{className:`space-y-4`,"data-testid":`jira-connected`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:r(`status.connected`,{key:i.jiraProjectKey})}),(0,I.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[i.baseUrl,` · `,i.deployment===`cloud`?r(`review.cloud`):r(`review.dc`)]})]}),(0,I.jsx)(`a`,{href:`${i.baseUrl}/browse/${i.jiraProjectKey}`,target:`_blank`,rel:`noreferrer`,className:`text-xs text-accent-primary hover:underline`,children:r(`badge.openInJira`)})]}),(0,I.jsxs)(`div`,{className:`flex items-center justify-between rounded-md border border-border p-3`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:r(`status.enabledLabel`)}),(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(o?`status.enabledHelp`:`status.pausedHelp`)})]}),(0,I.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":o,"aria-label":r(`status.enabledLabel`),disabled:d,onClick:D,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 ${o?`bg-accent-success`:`bg-input`}`,children:(0,I.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 rounded-full bg-background shadow-sm transition-transform ${o?`translate-x-4`:`translate-x-0.5`}`})})]}),(0,I.jsxs)(`div`,{className:`rounded-md border border-border p-3`,"data-testid":`jira-status-map`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:r(`wizard.step3Title`)}),(0,I.jsx)(`p`,{className:`mt-0.5 mb-2 text-xs text-muted-foreground`,children:r(`mapping.intro`)}),(0,I.jsx)(`div`,{className:`space-y-2`,children:re.map(e=>(0,I.jsxs)(`label`,{className:`flex items-center justify-between gap-3`,children:[(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:r(`mapping.${H[e]}`)}),(0,I.jsxs)(`select`,{value:y[e]??``,onChange:t=>void E(e,t.target.value),className:`w-44 rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-statusmap-${e}`,children:[(0,I.jsx)(`option`,{value:``,children:r(`mapping.auto`)}),h.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id)),y[e]&&!h.some(t=>t.name===y[e])&&(0,I.jsx)(`option`,{value:y[e],children:y[e]})]})]},e))})]}),(0,I.jsxs)(`div`,{className:`rounded-md border border-border p-3`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:r(`discard.configLabel`)}),(0,I.jsx)(`p`,{className:`mt-0.5 mb-2 text-xs text-muted-foreground`,children:r(`discard.configHelp`)}),(0,I.jsxs)(`select`,{value:_,onChange:e=>void T(e.target.value),className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-sm`,"data-testid":`jira-discard-status-select`,children:[(0,I.jsx)(`option`,{value:``,children:r(`discard.configNone`)}),h.map(e=>(0,I.jsx)(`option`,{value:e.name,children:e.name},e.id)),_&&!h.some(e=>e.name===_)&&(0,I.jsx)(`option`,{value:_,children:_})]})]}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(C,{variant:`outline`,size:`sm`,onClick:O,disabled:c,children:r(c?`status.syncing`:`status.syncNow`)}),(0,I.jsx)(C,{variant:`ghost`,size:`sm`,onClick:k,disabled:d,className:`text-destructive`,children:r(`status.disconnect`)})]}),(0,I.jsxs)(`div`,{className:`rounded-md border border-border p-3`,"data-testid":`jira-outbox`,children:[(0,I.jsx)(`p`,{className:`text-sm font-medium`,children:r(`outbox.title`)}),x.dead>0?(0,I.jsx)(`p`,{className:`mt-1 text-xs text-accent-warning`,children:r(`outbox.dead`,{count:x.dead})}):j>0?(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:r(`outbox.pending`,{count:j})}):(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:r(`outbox.allSynced`)}),p.length>0&&(0,I.jsxs)(`div`,{className:`mt-2 space-y-2`,children:[(0,I.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`outbox.deadHelp`)}),p.map(e=>(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded border border-border/60 px-2 py-1`,children:[(0,I.jsxs)(`span`,{className:`truncate text-xs`,children:[W(e,r),` · `,e.deadReason??e.lastError??``]}),(0,I.jsx)(C,{variant:`outline`,size:`sm`,onClick:()=>A(e.id),children:r(`outbox.retry`)})]},e.id))]})]})]})}function W(e,t){return e.opType===`transition`?t(`outbox.opTransition`):e.opType===`comment`?t(`outbox.opComment`):t(`outbox.opCreate`)}function G(e,t){return e instanceof Error?e.message:t(`errors.generic`)}var K=new Set([`claude`,`codex`,`kimi`]);function q(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 J(){return{updatedAt:null,proxyStatsAvailable:!1,durableSavingsAvailable:!1,outputSavingsAvailable:!1,outputSavingsMethod:null,outputConfidence:null,providers:{codex:q(`codex`),claude:q(`claude`)},lastIssue:null}}var Y={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:J(),lastIssue:null,updatedAt:null};function ie(e){let t=e?.metrics??J();return{...Y,...e,activeProviders:{...Y.activeProviders,...e?.activeProviders},availableProviders:{...Y.availableProviders,...e?.availableProviders},detectedRoutes:{...Y.detectedRoutes,...e?.detectedRoutes},learning:{...Y.learning,...e?.learning},metrics:{...J(),...t,providers:{codex:{...q(`codex`),...t.providers?.codex},claude:{...q(`claude`),...t.providers?.claude}}}}}async function X(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 Z(e){return`${r}/api/projects/${e}`}function Q(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`${Q(e,t)} ${n}`}function ae(){let{t:e}=a(`integrations`),{projects:t}=c(),{registerHandler:n,unregisterHandler:o}=i(),[s,l]=(0,F.useState)(``),[u,d]=(0,F.useState)(`all`),[f,m]=(0,F.useState)(Y),[h,g]=(0,F.useState)(!0),[C,w]=(0,F.useState)(null),[T,E]=(0,F.useState)([]),[D,M]=(0,F.useState)(!1),[N,P]=(0,F.useState)(!1),[ne,L]=(0,F.useState)(null),[R,z]=(0,F.useState)({jira:0,serena:0,projects:0}),B=(0,F.useCallback)(async()=>{try{let e=await fetch(`${r}/api/global-plugins/headroom`).then(e=>X(e));m(ie(e.state))}finally{g(!1)}},[]);(0,F.useEffect)(()=>{B()},[B]),(0,F.useEffect)(()=>(n(`plugins-page`,e=>{let t=e;t.type===`plugin.headroom_progress`&&(t.line&&E(e=>[...e.slice(-80),t.line]),B())}),()=>o(`plugins-page`)),[n,o,B]),(0,F.useEffect)(()=>{let e=!1;async function n(){let n=await Promise.all(t.map(async e=>{let[t,n]=await Promise.all([fetch(`${Z(e.id)}/jira/connection`).then(e=>X(e)).catch(()=>({connected:!1})),fetch(`${Z(e.id)}/plugins`).then(e=>X(e)).catch(()=>({plugins:[]}))]),r=n.plugins.find(e=>e.name===`serena`);return{jira:+!!t.connected,serena:r&&r.status!==`not-installed`&&r.status!==`orphan`?1:0}}));e||z({jira:n.reduce((e,t)=>e+t.jira,0),serena:n.reduce((e,t)=>e+t.serena,0),projects:t.length})}return n(),()=>{e=!0}},[t]);async function V(e,t){w(e),E([]);try{let e=(await t()).state;e&&m(ie(e))}catch(e){let t=e.payload;t?.state&&m(ie(t.state))}finally{w(null),B()}}let re=(0,F.useMemo)(()=>[{id:`headroom-ai`,title:`Headroom AI`,scope:`global`,icon:ee,description:e(`plugins.catalog.headroom.description`),installed:f.installed,status:f.lastIssue?`attention`:f.installed?f.activeProviders.codex||f.activeProviders.claude?f.installSource===`system`?`external-active`:`active`:f.installSource===`system`?`external`:`installed`:`available`,statusLabel:f.lastIssue?e(`plugins.status.attention`):f.installed?f.activeProviders.codex||f.activeProviders.claude?f.installSource===`system`?e(`plugins.status.externalActive`):e(`plugins.status.active`):f.installSource===`system`?e(`plugins.status.external`):e(`plugins.status.installed`):e(`plugins.status.available`),actionKind:f.lastIssue?`review`:f.installed?`manage`:`install`,actionLabel:f.lastIssue?e(`plugins.actions.review`):f.installed?e(`plugins.actions.manage`):e(`plugins.actions.install`),busy:C===`install`,action:()=>{if(f.lastIssue||f.installed){M(!0);return}V(`install`,()=>fetch(`${r}/api/global-plugins/headroom/install`,{method:`POST`}).then(e=>X(e)))}}],[f,C,e]),H=(0,F.useMemo)(()=>[{id:`jira`,title:`Jira`,scope:`project`,icon:te,description:e(`plugins.catalog.jira.description`),installed:R.jira>0,status:R.jira>0?`configured`:`available`,statusLabel:R.jira>0?e(`plugins.status.configuredCount`,{count:R.jira}):e(`plugins.status.available`),actionKind:R.jira>0?`manage`:`install`,actionLabel:R.jira>0?e(`plugins.actions.manage`):e(`plugins.actions.install`),action:()=>L(`jira`)},{id:`serena`,title:`Serena`,scope:`project`,icon:O,description:e(`plugins.catalog.serena.description`),installed:R.serena>0,status:R.serena>0?`installed`:`available`,statusLabel:R.serena>0?e(`plugins.status.installedCount`,{count:R.serena}):e(`plugins.status.available`),actionKind:R.serena>0?`manage`:`install`,actionLabel:R.serena>0?e(`plugins.actions.manage`):e(`plugins.actions.install`),action:()=>L(`serena`)}],[R,e]),U=s.trim().toLowerCase(),W=t=>`${t.title} ${t.description} ${t.statusLabel} ${e(`plugins.scope.${t.scope}`)}`.toLowerCase().includes(U),G=[...re,...H].filter(e=>u!==`all`&&e.scope!==u?!1:W(e)),K=G.filter(e=>e.scope===`global`&&e.installed),q=G.filter(e=>e.scope===`project`&&e.installed),J=G.filter(e=>e.scope===`global`&&!e.installed),Q=G.filter(e=>e.scope===`project`&&!e.installed),$=K.length>0||q.length>0,ae=J.length>0||Q.length>0,ce=[f.installed,R.jira>0,R.serena>0].filter(Boolean).length;return(0,I.jsxs)(`div`,{className:`flex h-full flex-col bg-background`,children:[(0,I.jsxs)(`div`,{className:`border-b border-border px-6 py-4`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,I.jsx)(`div`,{className:`grid h-9 w-9 place-items-center rounded-lg border border-accent-primary/25 bg-accent-primary/10 text-accent-primary`,children:(0,I.jsx)(j,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`h1`,{className:`text-lg font-semibold tracking-normal`,children:e(`plugins.page.title`)}),(0,I.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:e(`plugins.page.subtitle`)})]}),(0,I.jsxs)(`div`,{className:`mr-12 flex items-center gap-2 rounded-lg border border-border bg-card/60 px-3 py-2 text-xs`,children:[(0,I.jsx)(A,{className:`h-3.5 w-3.5 text-accent-success`}),(0,I.jsx)(`span`,{className:`text-muted-foreground`,children:e(`plugins.page.readyCount`,{count:ce})})]})]}),(0,I.jsxs)(`div`,{className:`mt-4 flex flex-col gap-3 md:flex-row md:items-center`,children:[(0,I.jsxs)(`label`,{className:`relative flex-1`,children:[(0,I.jsx)(p,{className:`pointer-events-none absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,I.jsx)(`input`,{value:s,onChange:e=>l(e.target.value),placeholder:e(`plugins.search.placeholder`),className:`h-9 w-full rounded-lg border border-border bg-background pl-9 pr-3 text-sm outline-none transition-colors focus:border-accent-primary/60`})]}),(0,I.jsx)(`div`,{className:`inline-flex h-9 rounded-lg border border-border bg-card p-1`,children:[`all`,`global`,`project`].map(t=>(0,I.jsx)(`button`,{type:`button`,onClick:()=>d(t),className:S(`rounded-md px-3 text-xs capitalize transition-colors`,u===t?`bg-muted text-foreground`:`text-muted-foreground hover:text-foreground`),children:e(`plugins.filters.${t}`)},t))})]})]}),(0,I.jsxs)(`div`,{className:`flex-1 overflow-auto px-6 py-5`,children:[(0,I.jsxs)(`section`,{className:`mb-6`,children:[(0,I.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,I.jsx)(k,{className:`h-3.5 w-3.5`}),e(`plugins.sections.installed`)]}),$?(0,I.jsx)(oe,{globalPlugins:K,projectPlugins:q}):(0,I.jsx)(se,{text:e(U?`plugins.empty.installedSearch`:`plugins.empty.installed`)})]}),(0,I.jsxs)(`section`,{children:[(0,I.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,I.jsx)(j,{className:`h-3.5 w-3.5`}),e(`plugins.sections.available`)]}),ae?(0,I.jsx)(oe,{globalPlugins:J,projectPlugins:Q}):(0,I.jsx)(se,{text:e(U?`plugins.empty.availableSearch`:`plugins.empty.allInstalled`)})]})]}),(0,I.jsx)(x,{open:D,onOpenChange:M,children:(0,I.jsxs)(b,{className:`w-[calc(100vw-2rem)] max-w-xl overflow-x-hidden p-4 sm:p-6`,children:[(0,I.jsxs)(y,{children:[(0,I.jsx)(v,{children:e(`plugins.headroom.title`)}),(0,I.jsx)(_,{children:e(`plugins.headroom.dialogDescription`)})]}),(0,I.jsx)(de,{state:f,loading:h,busy:C,logs:T,onInstall:()=>V(`install`,()=>fetch(`${r}/api/global-plugins/headroom/install`,{method:`POST`}).then(e=>X(e))),onToggleProvider:(e,t)=>V(`${t?`deactivate`:`activate`}-${e}`,()=>fetch(`${r}/api/global-plugins/headroom/${t?`deactivate`:`activate`}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:e})}).then(e=>X(e))),onDeactivateAll:()=>V(`deactivate-all`,async()=>{let e={state:f};for(let t of[`codex`,`claude`])f.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=>X(e)));return e}),onUninstall:()=>V(`uninstall`,()=>fetch(`${r}/api/global-plugins/headroom/uninstall`,{method:`POST`}).then(e=>X(e))),onSetPort:e=>V(`port`,()=>fetch(`${r}/api/global-plugins/headroom/port`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({port:e})}).then(e=>X(e))),onOpenDiagnostics:()=>P(!0)})]})}),(0,I.jsx)(ve,{plugin:ne,projects:t,onClose:()=>L(null)}),(0,I.jsx)(xe,{open:N,onClose:()=>P(!1)})]})}function oe({globalPlugins:e,projectPlugins:t}){let{t:n}=a(`integrations`);return(0,I.jsxs)(`div`,{className:S(`grid grid-cols-1 gap-4`,e.length>0&&t.length>0&&`xl:grid-cols-2`),children:[e.length>0&&(0,I.jsxs)(`section`,{children:[(0,I.jsx)(le,{title:n(`plugins.groups.global.title`),detail:n(`plugins.groups.global.detail`),scope:`global`}),(0,I.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,320px))] justify-start gap-3`,children:e.map(e=>(0,I.jsx)(ue,{plugin:e},e.id))})]}),t.length>0&&(0,I.jsxs)(`section`,{children:[(0,I.jsx)(le,{title:n(`plugins.groups.project.title`),detail:n(`plugins.groups.project.detail`),scope:`project`}),(0,I.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(260px,320px))] justify-start gap-3`,children:t.map(e=>(0,I.jsx)(ue,{plugin:e},e.id))})]})]})}function se({text:e}){return(0,I.jsx)(`div`,{className:`flex h-[74px] max-w-[320px] items-center rounded-lg border border-dashed border-border bg-card/35 px-3 text-xs text-muted-foreground`,children:e})}function ce({scope:e}){let{t}=a(`integrations`);return(0,I.jsx)(`span`,{className:S(`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 le({title:e,detail:t,scope:n}){return(0,I.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,I.jsx)(`div`,{className:S(`h-px flex-1`,n===`global`?`bg-accent-primary/30`:`bg-accent-info/30`)}),(0,I.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border bg-card/70 px-2 py-1`,children:[(0,I.jsx)(ce,{scope:n}),(0,I.jsx)(`span`,{className:`text-xs font-medium`,children:e}),(0,I.jsx)(`span`,{className:`hidden text-[11px] text-muted-foreground sm:inline`,children:t})]}),(0,I.jsx)(`div`,{className:S(`h-px flex-1`,n===`global`?`bg-accent-primary/30`:`bg-accent-info/30`)})]})}function ue({plugin:e}){let{t}=a(`integrations`),n=e.icon,r=e.scope===`global`,i=e.status===`attention`,o=e.busy?f:e.actionKind===`install`?d:e.actionKind===`review`?h:P,s=S(`shrink-0 rounded border px-1.5 py-0.5 text-[10px] leading-none`,i?`border-accent-warning/30 bg-accent-warning/10 text-accent-warning`:e.installed?`border-accent-success/25 bg-accent-success/10 text-accent-success`:`border-border bg-muted text-muted-foreground`);return(0,I.jsxs)(`article`,{className:`grid h-[88px] w-full grid-cols-[38px_minmax(0,1fr)_auto] items-center gap-3 rounded-lg border border-border bg-card/70 px-3 transition-colors hover:border-accent-primary/35 hover:bg-card`,children:[(0,I.jsx)(`div`,{className:S(`grid h-[38px] w-[38px] shrink-0 place-items-center rounded-lg border`,r?`border-accent-primary/25 bg-accent-primary/10 text-accent-primary`:`border-accent-info/25 bg-accent-info/10 text-accent-info`),children:(0,I.jsx)(n,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`h2`,{className:`truncate text-sm font-semibold leading-5`,children:e.title}),(0,I.jsx)(`p`,{className:`mt-1 truncate text-[11px] leading-4 text-muted-foreground`,children:e.description}),(0,I.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-1.5`,children:[(0,I.jsx)(ce,{scope:e.scope}),(0,I.jsx)(`span`,{className:s,children:e.statusLabel})]})]}),(0,I.jsxs)(`button`,{type:`button`,disabled:e.busy,onClick:e.action,className:`flex h-7 shrink-0 items-center gap-1.5 rounded-md border border-border bg-background px-2.5 text-xs font-medium transition-colors hover:bg-muted disabled:opacity-50`,children:[(0,I.jsx)(o,{className:S(`h-3.5 w-3.5`,e.busy&&`animate-spin`)}),e.busy?t(`plugins.actions.installing`):e.actionLabel]})]})}function de({state:e,loading:t,busy:n,logs:r,onInstall:i,onToggleProvider:o,onDeactivateAll:s,onUninstall:c,onSetPort:l,onOpenDiagnostics:u}){let{t:p}=a(`integrations`),[h,_]=(0,F.useState)(String(e.port)),[v,y]=(0,F.useState)(!1);(0,F.useEffect)(()=>_(String(e.port)),[e.port]),(0,F.useEffect)(()=>{e.installed||y(!1)},[e.installed]);let b=e.activeProviders.codex||e.activeProviders.claude,x=e.installSource===`system`;return(0,I.jsxs)(`aside`,{className:`w-full min-w-0 overflow-hidden rounded-lg border border-border bg-card/80 p-4`,children:[(0,I.jsxs)(`div`,{className:`mb-4 flex items-start gap-3`,children:[(0,I.jsx)(`div`,{className:`grid h-10 w-10 place-items-center rounded-lg border border-accent-primary/25 bg-accent-primary/10 text-accent-primary`,children:(0,I.jsx)(ee,{className:`h-4 w-4`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`h2`,{className:`text-sm font-semibold`,children:p(`plugins.headroom.title`)}),(0,I.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:p(`plugins.headroom.panelDescription`)})]})]}),(0,I.jsxs)(`div`,{className:`mb-4 grid grid-cols-3 gap-2 text-xs`,children:[(0,I.jsx)(fe,{label:p(`plugins.headroom.metrics.install`),value:t?p(`plugins.headroom.metrics.checking`):e.installed?p(`plugins.headroom.metrics.ready`):p(`plugins.headroom.metrics.missing`),good:e.installed}),(0,I.jsx)(fe,{label:p(`plugins.headroom.metrics.source`),value:e.installSource===`system`?p(`plugins.headroom.metrics.system`):e.installSource===`managed`?p(`plugins.headroom.metrics.specrails`):p(`plugins.headroom.metrics.none`),good:e.installed}),(0,I.jsx)(fe,{label:p(`plugins.headroom.metrics.proxy`),value:e.proxyRunning?`:${e.port}`:p(b?`plugins.headroom.metrics.starting`:`plugins.headroom.metrics.off`),good:e.proxyRunning||!b})]}),e.lastIssue&&(0,I.jsx)(pe,{issue:e.lastIssue}),e.installed?(0,I.jsxs)(`div`,{className:`mb-4 space-y-2`,children:[(0,I.jsx)(_e,{provider:`codex`,active:e.activeProviders.codex,available:e.availableProviders.codex,detectedRoute:e.detectedRoutes.codex,busy:n===`activate-codex`||n===`deactivate-codex`,onClick:()=>o(`codex`,e.activeProviders.codex)}),(0,I.jsx)(_e,{provider:`claude`,active:e.activeProviders.claude,available:e.availableProviders.claude,detectedRoute:e.detectedRoutes.claude,busy:n===`activate-claude`||n===`deactivate-claude`,onClick:()=>o(`claude`,e.activeProviders.claude)}),b&&(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:s,className:`flex h-8 w-full items-center justify-center gap-2 rounded-lg border border-border bg-background/45 text-xs hover:bg-muted/50 disabled:opacity-50`,children:[n===`deactivate-all`?(0,I.jsx)(f,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(N,{className:`h-3.5 w-3.5`}),p(`plugins.headroom.actions.disableAllRoutes`)]})]}):(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:i,className:`mb-3 flex h-9 w-full items-center justify-center gap-2 rounded-lg bg-accent-primary px-3 text-xs font-medium text-white disabled:opacity-50`,children:[n===`install`?(0,I.jsx)(f,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(d,{className:`h-3.5 w-3.5`}),p(`plugins.headroom.actions.installWithUv`)]}),e.installed&&(0,I.jsx)(me,{state:e}),(0,I.jsxs)(`div`,{className:`mb-4 rounded-lg border border-border bg-background/45 p-3`,children:[(0,I.jsx)(`label`,{className:`mb-1 block text-[11px] font-medium text-muted-foreground`,children:p(`plugins.headroom.port.label`)}),(0,I.jsxs)(`div`,{className:`flex gap-2`,children:[(0,I.jsx)(`input`,{value:h,onChange:e=>_(e.target.value),className:`h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-sm`}),(0,I.jsx)(`button`,{type:`button`,disabled:!!n||Number(h)===e.port,onClick:()=>l(Number(h)),className:`rounded-md border border-border px-2 text-xs hover:bg-muted disabled:opacity-50`,children:p(`plugins.headroom.port.apply`)})]})]}),r.length>0&&(0,I.jsx)(`pre`,{className:`mb-3 max-h-32 overflow-y-auto overflow-x-hidden whitespace-pre-wrap break-words rounded-lg border border-border bg-background/60 p-2 text-[10px] text-muted-foreground`,children:r.join(`
2
+ `)}),(0,I.jsxs)(`button`,{type:`button`,onClick:u,className:`mb-2 flex h-8 w-full items-center justify-center gap-2 rounded-lg border border-border text-xs hover:bg-muted/50`,children:[(0,I.jsx)(g,{className:`h-3.5 w-3.5`}),p(`plugins.headroom.actions.viewDiagnostics`)]}),e.installed&&(0,I.jsx)(`div`,{className:`rounded-lg border border-destructive/25 bg-destructive/5 p-3`,children:v?(0,I.jsxs)(`div`,{className:`space-y-2`,children:[(0,I.jsx)(`p`,{className:`text-[11px] leading-relaxed text-muted-foreground`,children:p(x?`plugins.headroom.confirmDetach`:`plugins.headroom.confirmUninstall`)}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,I.jsx)(`button`,{type:`button`,disabled:!!n,onClick:()=>y(!1),className:`h-8 rounded-md border border-border text-xs hover:bg-muted/50 disabled:opacity-50`,children:p(`plugins.actions.cancel`)}),(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:c,className:`flex h-8 items-center justify-center gap-2 rounded-md bg-destructive px-2 text-xs font-medium text-destructive-foreground disabled:opacity-50`,children:[n===`uninstall`?(0,I.jsx)(f,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(m,{className:`h-3.5 w-3.5`}),p(x?`plugins.headroom.actions.detach`:`plugins.headroom.actions.uninstall`)]})]})]}):(0,I.jsxs)(`button`,{type:`button`,disabled:!!n,onClick:()=>y(!0),className:`flex h-8 w-full items-center justify-center gap-2 rounded-md text-xs font-medium text-destructive hover:bg-destructive/10 disabled:opacity-50`,children:[(0,I.jsx)(m,{className:`h-3.5 w-3.5`}),p(x?`plugins.headroom.actions.detachHeadroom`:`plugins.headroom.actions.uninstallHeadroom`)]})})]})}function fe({label:e,value:t,good:n}){return(0,I.jsxs)(`div`,{className:`rounded-lg border border-border bg-background/45 p-2`,children:[(0,I.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e}),(0,I.jsx)(`div`,{className:S(`mt-0.5 font-medium`,n?`text-foreground`:`text-accent-warning`),children:t})]})}function pe({issue:e}){let{t}=a(`integrations`),n=`plugins.headroom.issues.${e.code}`,r=t(`${n}.title`,{defaultValue:e.title}),i=t(`${n}.guidance`,{defaultValue:e.guidance});return(0,I.jsx)(`div`,{className:`mb-3 rounded-lg border border-accent-warning/35 bg-accent-warning/10 p-3`,children:(0,I.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,I.jsx)(h,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-accent-warning`}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`div`,{className:`text-xs font-medium`,children:r}),(0,I.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-muted-foreground`,children:i}),(0,I.jsx)(`div`,{className:`mt-1 text-[10px] text-muted-foreground`,children:t(`plugins.headroom.issueCode`,{code:e.code})})]})]})})}function me({state:e}){let{t,i18n:n}=a(`integrations`),r=e.metrics,i=r.outputSavingsAvailable,o=[`codex`,`claude`].map(e=>({provider:e,metric:r.providers[e]})),s=t(`plugins.headroom.savings.tokens`),c=o.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=o.some(({metric:e})=>e.inputTokensSaved>0),u=o.some(({metric:e})=>e.active),d=t(i?`plugins.headroom.savings.statusInputOutput`:l?`plugins.headroom.savings.statusInputOnly`:u?`plugins.headroom.savings.statusRouting`:`plugins.headroom.savings.statusInactive`),f=i||l;return(0,I.jsxs)(`div`,{className:`mb-4 rounded-lg border border-border bg-background/45 p-3`,children:[(0,I.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,I.jsx)(T,{className:`h-3.5 w-3.5 text-accent-primary`}),(0,I.jsx)(`div`,{className:`truncate text-xs font-medium`,children:t(`plugins.headroom.savings.title`)})]}),(0,I.jsx)(`span`,{className:S(`shrink-0 rounded border px-1.5 py-0.5 text-[10px]`,f?`border-accent-success/25 bg-accent-success/10 text-accent-success`:u?`border-accent-primary/25 bg-accent-primary/10 text-accent-primary`:`border-border bg-muted text-muted-foreground`),children:d})]}),(0,I.jsxs)(`div`,{className:`mb-2 rounded-md bg-muted/35 px-2.5 py-2`,children:[(0,I.jsx)(`div`,{className:`mb-1.5 text-[10px] font-medium uppercase text-muted-foreground`,children:t(`plugins.headroom.savings.totals`)}),(0,I.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,I.jsx)(he,{label:t(`plugins.headroom.savings.input`),processed:c.inputTokens>0?$(c.inputTokens,n.language,s):t(`plugins.headroom.savings.noData`),saved:$(c.inputTokensSaved,n.language,s)}),(0,I.jsx)(he,{align:`right`,label:t(`plugins.headroom.savings.output`),processed:c.outputTokens>0?$(c.outputTokens,n.language,s):t(`plugins.headroom.savings.noData`),saved:i?$(c.outputTokensSaved,n.language,s):t(`plugins.headroom.savings.noData`)})]})]}),(0,I.jsx)(`div`,{className:`grid gap-2`,children:o.map(({provider:e,metric:t})=>(0,I.jsx)(ge,{metric:t,outputAvailable:r.outputSavingsAvailable},e))}),(0,I.jsx)(`div`,{className:`mt-2 flex items-center justify-end gap-2 text-[10px] text-muted-foreground`,children:r.updatedAt?t(`plugins.headroom.savings.updatedLive`):t(`plugins.headroom.savings.baselineSamples`,{count:e.learning.baselineSamples})})]})}function he({label:e,processed:t,saved:n,detail:r,align:i=`left`}){let{t:o}=a(`integrations`);return(0,I.jsxs)(`div`,{className:S(`min-w-0`,i===`right`&&`text-right`),children:[(0,I.jsx)(`div`,{className:`text-[10px] font-medium uppercase text-muted-foreground`,children:e}),(0,I.jsxs)(`div`,{className:`mt-1 space-y-0.5 text-[11px]`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-baseline justify-between gap-2`,children:[(0,I.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:o(`plugins.headroom.savings.processed`)}),(0,I.jsx)(`span`,{className:`truncate font-semibold tabular-nums text-foreground`,children:t})]}),(0,I.jsxs)(`div`,{className:`flex min-w-0 items-baseline justify-between gap-2`,children:[(0,I.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:o(`plugins.headroom.savings.saved`)}),(0,I.jsx)(`span`,{className:`truncate font-semibold tabular-nums text-foreground`,children:n})]})]}),r&&(0,I.jsx)(`div`,{className:`mt-1 truncate text-[10px] text-muted-foreground`,children:r})]})}function ge({metric:e,outputAvailable:t}){let{t:n,i18n:r}=a(`integrations`),i=!e.available,o=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:Q(e.requests,r.language)}):i?n(`plugins.headroom.provider.noProjectUsesProvider`):e.active?n(`plugins.headroom.savings.inputSavingsActive`):n(`plugins.headroom.savings.routeDisabled`);return(0,I.jsxs)(`div`,{className:S(`rounded-md border border-border bg-card/45 px-2.5 py-2`,o&&`opacity-70`),children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium`,children:e.label}),e.detectedRoute&&(0,I.jsx)(`span`,{className:`rounded bg-accent-primary/10 px-1.5 py-0.5 text-[9px] uppercase text-accent-primary`,children:n(`plugins.headroom.savings.detected`)})]}),(0,I.jsx)(`div`,{className:`mt-0.5 truncate text-[10px] text-muted-foreground`,children:f}),(0,I.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-3`,children:[(0,I.jsx)(he,{label:n(`plugins.headroom.savings.input`),processed:c,saved:l}),(0,I.jsx)(he,{align:`right`,label:n(`plugins.headroom.savings.output`),processed:u,saved:d})]})]})}function _e({provider:e,active:t,available:n,detectedRoute:r,busy:i,onClick:o}){let{t:s}=a(`integrations`),c=s(n?t?`plugins.headroom.provider.routedThroughHeadroom`:r?`plugins.headroom.provider.detectedExternalRoute`:`plugins.headroom.provider.notRouted`:`plugins.headroom.provider.noProjectUsesProvider`);return(0,I.jsxs)(`button`,{type:`button`,onClick:o,disabled:i||!n,className:`flex w-full items-center gap-3 rounded-lg border border-border bg-background/45 p-3 text-left hover:bg-muted/35 disabled:opacity-50`,children:[(0,I.jsx)(`div`,{className:S(`grid h-8 w-8 place-items-center rounded-md`,t?`bg-accent-success/15 text-accent-success`:`bg-muted text-muted-foreground`),children:i?(0,I.jsx)(f,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(M,{className:`h-3.5 w-3.5`})}),(0,I.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,I.jsx)(`div`,{className:`text-xs font-medium capitalize`,children:e}),(0,I.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:c})]}),(0,I.jsx)(`span`,{className:S(`h-5 w-9 rounded-full p-0.5 transition-colors`,t?`bg-accent-success`:`bg-muted`),children:(0,I.jsx)(`span`,{className:S(`block h-4 w-4 rounded-full bg-white shadow transition-transform`,t&&`translate-x-4`)})})]})}function ve({plugin:e,projects:t,onClose:n}){let{t:r}=a(`integrations`),[i,o]=(0,F.useState)(``);(0,F.useEffect)(()=>o(``),[e]);let c=t.find(e=>e.id===i)??null;return(0,I.jsx)(x,{open:!!e,onOpenChange:e=>{e||n()},children:(0,I.jsxs)(b,{className:`w-[calc(100vw-2rem)] max-w-3xl overflow-x-hidden p-4 sm:p-6`,children:[(0,I.jsxs)(y,{children:[(0,I.jsx)(v,{children:r(e===`jira`?`plugins.projectWizard.configureJira`:`plugins.projectWizard.installSerena`)}),(0,I.jsx)(_,{children:r(`plugins.projectWizard.description`)})]}),(0,I.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-[260px_minmax(0,1fr)]`,children:[(0,I.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/70 p-3`,children:[(0,I.jsx)(`div`,{className:`mb-2 text-xs font-medium text-muted-foreground`,children:r(`plugins.projectWizard.chooseProject`)}),(0,I.jsx)(`div`,{className:`max-h-[52vh] space-y-1 overflow-auto`,children:t.map(t=>{let n=e===`serena`&&!s(t).some(e=>K.has(e));return(0,I.jsxs)(`button`,{type:`button`,disabled:n,onClick:()=>o(t.id),className:S(`w-full rounded-md px-2 py-2 text-left transition-colors`,t.id===i?`bg-muted text-foreground`:`text-muted-foreground hover:bg-muted/45 hover:text-foreground`,n&&`cursor-not-allowed opacity-45`),children:[(0,I.jsx)(`div`,{className:`truncate text-xs font-medium`,children:t.name}),(0,I.jsx)(`div`,{className:`truncate text-[10px]`,children:n?r(`plugins.projectWizard.requiresSupportedProvider`,{defaultValue:`Requires Claude, Codex, or Kimi`}):t.path})]},t.id)})})]}),(0,I.jsx)(`div`,{className:`min-h-[360px] rounded-lg border border-border bg-card/70 p-4`,children:c?e===`jira`?(0,I.jsx)(ye,{project:c,onDone:n}):(0,I.jsx)(be,{project:c,onDone:n}):(0,I.jsx)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:r(`plugins.projectWizard.selectProjectToContinue`)})})]})]})})}function ye({project:e,onDone:t}){let{t:n}=a(`integrations`),r=Z(e.id),[i,o]=(0,F.useState)(null),[s,c]=(0,F.useState)(!0),[l,u]=(0,F.useState)(null),d=(0,F.useCallback)(async()=>{c(!0),u(null);try{let e=await fetch(`${r}/jira/connection`).then(e=>X(e));o(e)}catch(e){o({connected:!1}),u(e.message)}finally{c(!1)}},[r]);return(0,F.useEffect)(()=>{d()},[d]),s?(0,I.jsxs)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:[(0,I.jsx)(f,{className:`mr-2 h-4 w-4 animate-spin`}),n(`plugins.jira.loading`,{defaultValue:`Loading Jira...`})]}):i?.connected&&i.connection?(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:n(`plugins.jira.titleForProject`,{name:e.name,defaultValue:`Jira for ${e.name}`})}),(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`plugins.jira.configuredDescription`,{defaultValue:`Manage the Jira project, status mapping, discard status, sync, and connection state.`})})]}),(0,I.jsx)(U,{state:i,apiBase:r,onChanged:()=>{d()}})]}):(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:n(`plugins.jira.titleForProject`,{name:e.name,defaultValue:`Jira for ${e.name}`})}),(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:l?n(`plugins.jira.loadFailed`,{message:l,defaultValue:`Could not load the current Jira configuration: ${l}`}):n(`plugins.jira.notConfiguredDescription`,{defaultValue:`Connect this project to Jira.`})})]}),(0,I.jsx)(R,{apiBase:r,onConnected:()=>{d()},onSkip:t})]})}function be({project:e,onDone:t}){let{t:n}=a(`integrations`),r=(0,F.useMemo)(()=>s(e).filter(e=>K.has(e)),[e]),i=r.includes(e.provider)?e.provider:r[0]??e.provider,[o,c]=(0,F.useState)(i),[l,p]=(0,F.useState)(null),[m,g]=(0,F.useState)(null),[_,v]=(0,F.useState)(!1),[y,b]=(0,F.useState)(null),x=(0,F.useRef)(0);(0,F.useEffect)(()=>{c(i),p(null),g(null)},[e.id,i]);let S=(0,F.useCallback)(async()=>{let t=++x.current;b(null);try{let n=`?provider=${encodeURIComponent(o)}`,r=await fetch(`${Z(e.id)}/plugins${n}`).then(e=>X(e));if(t!==x.current)return;let i=r.plugins.find(e=>e.name===`serena`)??null;if(p(i),g(null),i?.status===`not-installed`){let r=await fetch(`${Z(e.id)}/plugins/serena/preview-install${n}`).then(e=>X(e));t===x.current&&g(r)}}catch(e){t===x.current&&b(e.message)}},[e.id,o]);(0,F.useEffect)(()=>{S()},[S]);async function C(){v(!0),b(null);try{await fetch(`${Z(e.id)}/plugins/serena/install`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({provider:o})}).then(e=>X(e)),await S(),t()}catch(e){b(e.message)}finally{v(!1)}}let w=(m?.requirements??[]).every(e=>e.installed&&e.executable&&e.meetsMinimum),T=l?n(`plugins.projectStatus.${l.status}`,{defaultValue:l.status}):``,E=l?.name===`serena`?n(`plugins.catalog.serena.description`):l?.description;return!l&&!y?(0,I.jsxs)(`div`,{className:`flex h-full items-center justify-center text-sm text-muted-foreground`,children:[(0,I.jsx)(f,{className:`mr-2 h-4 w-4 animate-spin`}),` `,n(`plugins.serena.loading`)]}):(0,I.jsxs)(`div`,{className:`space-y-4`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h3`,{className:`text-sm font-semibold`,children:n(`plugins.serena.titleForProject`,{name:e.name})}),(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:n(`plugins.serena.description`)})]}),(0,I.jsxs)(`label`,{className:`block space-y-1`,children:[(0,I.jsx)(`span`,{className:`text-xs font-medium`,children:n(`plugins.serena.provider`,{defaultValue:`AI provider`})}),(0,I.jsx)(`select`,{"aria-label":n(`plugins.serena.provider`,{defaultValue:`AI provider`}),value:o,disabled:_,onChange:e=>{p(null),g(null),c(e.target.value)},className:`w-full rounded-md border border-border bg-background px-2 py-1.5 text-xs`,children:r.map(e=>(0,I.jsx)(`option`,{value:e,children:u(e)},e))})]}),l&&(0,I.jsxs)(`div`,{className:`rounded-lg border border-border bg-background/45 p-3`,children:[(0,I.jsx)(`div`,{className:`text-xs font-medium`,children:n(`plugins.serena.status`,{status:T})}),E&&(0,I.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:E})]}),m&&(0,I.jsxs)(`div`,{className:`space-y-3`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`mb-1 text-xs font-medium`,children:n(`plugins.serena.files`)}),(0,I.jsx)(`ul`,{className:`space-y-1 text-xs font-mono`,children:m.files.map(e=>(0,I.jsxs)(`li`,{className:e.op===`create`?`text-accent-success`:`text-accent-info`,children:[e.op===`create`?`+ `:`~ `,e.path]},e.path))})]}),(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`div`,{className:`mb-1 text-xs font-medium`,children:n(`plugins.serena.prerequisites`)}),(0,I.jsx)(`ul`,{className:`space-y-1 text-xs`,children:m.requirements.map(e=>(0,I.jsxs)(`li`,{className:`flex items-center gap-2`,children:[e.installed&&e.executable&&e.meetsMinimum?(0,I.jsx)(D,{className:`h-3 w-3 text-accent-success`}):(0,I.jsx)(h,{className:`h-3 w-3 text-accent-warning`}),(0,I.jsxs)(`span`,{children:[e.name,e.minVersion?` >= ${e.minVersion}`:``]}),e.version&&(0,I.jsxs)(`span`,{className:`text-muted-foreground`,children:[`(`,e.version,`)`]})]},e.name))})]})]}),y&&(0,I.jsx)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/10 p-3 text-xs text-destructive`,children:y}),(0,I.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,I.jsx)(`button`,{type:`button`,onClick:t,className:`rounded-md border border-border px-3 py-1.5 text-xs`,children:n(`plugins.actions.cancel`)}),(0,I.jsxs)(`button`,{type:`button`,disabled:_||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:[_?(0,I.jsx)(f,{className:`h-3.5 w-3.5 animate-spin`}):(0,I.jsx)(d,{className:`h-3.5 w-3.5`}),n(`plugins.actions.install`)]})]})]})}function xe({open:e,onClose:t}){let{t:n}=a(`integrations`),[i,o]=(0,F.useState)(null);return(0,F.useEffect)(()=>{e&&fetch(`${r}/api/global-plugins/headroom/diagnostics`).then(e=>X(e)).then(o).catch(e=>o({error:e.message}))},[e]),(0,I.jsx)(x,{open:e,onOpenChange:e=>{e||t()},children:(0,I.jsxs)(b,{className:`max-w-3xl`,children:[(0,I.jsxs)(y,{children:[(0,I.jsxs)(v,{className:`flex items-center gap-2`,children:[(0,I.jsx)(P,{className:`h-4 w-4`}),` `,n(`plugins.diagnostics.title`)]}),(0,I.jsx)(_,{children:n(`plugins.diagnostics.description`)})]}),(0,I.jsx)(`pre`,{className:`max-h-[62vh] overflow-y-auto overflow-x-hidden whitespace-pre-wrap break-words rounded-lg border border-border bg-background p-3 text-xs`,children:JSON.stringify(i,null,2)})]})})}export{ae 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{n as r,t as i}from"./createLucideIcon-Bjbbp_KS.js";import{r as a}from"./useDesktop-QogiN0zR.js";import{t as o}from"./git-branch-BRM0F5GN.js";import{i as s,l as c,o as l,r as u,t as d}from"./dialog-xXB2q5HJ.js";import{t as f}from"./utils-BC4DHlz2.js";import{Gt as p,Ht as m,a as h,c as g,ft as _,i as v,l as y,lt as b,n as x,o as S,ot as C,r as w,s as T,ut as E}from"./index-Cxb288Rj.js";var D=i(`key-round`,[[`path`,{d:`M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z`,key:`1s6t7t`}],[`circle`,{cx:`16.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`w0ekpg`}]]),O=e(t(),1),k=n(),A=[{id:`general`,icon:E,labelKey:`projectDialog.nav.general`},{id:`agentRuntime`,icon:m,labelKey:`projectDialog.nav.agentRuntime`},{id:`branch`,icon:o,labelKey:`projectDialog.nav.branch`},{id:`environment`,icon:D,labelKey:`projectDialog.nav.environment`},{id:`budget`,icon:C,labelKey:`projectDialog.nav.budget`},{id:`telemetry`,icon:p,labelKey:`projectDialog.nav.telemetry`},{id:`terminal`,icon:b,labelKey:`projectDialog.nav.terminal`}];function j({open:e,onClose:t}){let{t:n}=r(`settings`),{activeProjectId:i,projects:o}=a(),p=o.find(e=>e.id===i),[m,b]=(0,O.useState)(`general`),C=e=>f(`space-y-5`,m===e?``:`hidden`);return(0,k.jsx)(d,{open:e,onOpenChange:e=>{e||t()},children:(0,k.jsxs)(u,{movableResizable:!0,className:`flex max-w-5xl w-[92vw] h-[82vh] flex-col overflow-hidden`,children:[(0,k.jsxs)(l,{children:[(0,k.jsxs)(c,{className:`flex items-center gap-2`,children:[(0,k.jsx)(_,{className:`w-4 h-4`}),p?n(`projectDialog.title`,{name:p.name}):n(`page.title`)]}),(0,k.jsx)(s,{children:n(`projectDialog.description`)})]}),(0,k.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-5 py-2`,children:[(0,k.jsx)(`nav`,{className:`w-40 shrink-0 space-y-0.5 overflow-y-auto border-r border-border pr-2`,children:A.map(e=>{let t=e.icon;return(0,k.jsxs)(`button`,{type:`button`,onClick:()=>b(e.id),className:f(`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left text-xs transition-colors`,m===e.id?`bg-accent-primary/15 font-medium text-foreground`:`text-muted-foreground hover:bg-muted/40 hover:text-foreground`),children:[(0,k.jsx)(t,{className:`w-3.5 h-3.5 shrink-0`}),(0,k.jsx)(`span`,{className:`truncate`,children:n(e.labelKey)})]},e.id)})}),(0,k.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-y-auto pr-1`,children:[(0,k.jsxs)(`div`,{className:C(`general`),children:[(0,k.jsx)(g,{}),(0,k.jsx)(v,{})]}),(0,k.jsx)(`div`,{className:C(`agentRuntime`),children:(0,k.jsx)(T,{})}),(0,k.jsx)(`div`,{className:C(`branch`),children:(0,k.jsx)(w,{})}),(0,k.jsx)(`div`,{className:C(`environment`),children:(0,k.jsx)(S,{})}),(0,k.jsx)(`div`,{className:C(`budget`),children:(0,k.jsx)(x,{})}),(0,k.jsx)(`div`,{className:C(`telemetry`),children:(0,k.jsx)(h,{})}),(0,k.jsx)(`div`,{className:C(`terminal`),children:(0,k.jsx)(y,{mode:`project`})})]})]})]})})}export{j as ProjectSettingsDialog};
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{n as r,t as i}from"./createLucideIcon-Bjbbp_KS.js";import{r as a}from"./useDesktop-0unHDBJJ.js";import{t as o}from"./git-branch-BRM0F5GN.js";import{i as s,l as c,o as l,r as u,t as d}from"./dialog-xXB2q5HJ.js";import{t as f}from"./utils-BC4DHlz2.js";import{Kt as p,Ut as m,a as h,c as g,ct as _,dt as v,ft as y,i as b,l as x,mt as S,n as C,o as w,r as T,s as E}from"./index-C4Mv6tV6.js";var D=i(`key-round`,[[`path`,{d:`M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z`,key:`1s6t7t`}],[`circle`,{cx:`16.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`w0ekpg`}]]),O=e(t(),1),k=n(),A=[{id:`general`,icon:y,labelKey:`projectDialog.nav.general`},{id:`agentRuntime`,icon:m,labelKey:`projectDialog.nav.agentRuntime`},{id:`branch`,icon:o,labelKey:`projectDialog.nav.branch`},{id:`environment`,icon:D,labelKey:`projectDialog.nav.environment`},{id:`budget`,icon:_,labelKey:`projectDialog.nav.budget`},{id:`telemetry`,icon:p,labelKey:`projectDialog.nav.telemetry`},{id:`terminal`,icon:v,labelKey:`projectDialog.nav.terminal`}];function j({open:e,onClose:t}){let{t:n}=r(`settings`),{activeProjectId:i,projects:o}=a(),p=o.find(e=>e.id===i),[m,_]=(0,O.useState)(`general`),v=e=>f(`space-y-5`,m===e?``:`hidden`);return(0,k.jsx)(d,{open:e,onOpenChange:e=>{e||t()},children:(0,k.jsxs)(u,{movableResizable:!0,className:`flex max-w-5xl w-[92vw] h-[82vh] flex-col overflow-hidden`,children:[(0,k.jsxs)(l,{children:[(0,k.jsxs)(c,{className:`flex items-center gap-2`,children:[(0,k.jsx)(S,{className:`w-4 h-4`}),p?n(`projectDialog.title`,{name:p.name}):n(`page.title`)]}),(0,k.jsx)(s,{children:n(`projectDialog.description`)})]}),(0,k.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-5 py-2`,children:[(0,k.jsx)(`nav`,{className:`w-40 shrink-0 space-y-0.5 overflow-y-auto border-r border-border pr-2`,children:A.map(e=>{let t=e.icon;return(0,k.jsxs)(`button`,{type:`button`,onClick:()=>_(e.id),className:f(`flex w-full items-center gap-2 rounded-lg px-2.5 py-1.5 text-left text-xs transition-colors`,m===e.id?`bg-accent-primary/15 font-medium text-foreground`:`text-muted-foreground hover:bg-muted/40 hover:text-foreground`),children:[(0,k.jsx)(t,{className:`w-3.5 h-3.5 shrink-0`}),(0,k.jsx)(`span`,{className:`truncate`,children:n(e.labelKey)})]},e.id)})}),(0,k.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-y-auto pr-1`,children:[(0,k.jsxs)(`div`,{className:v(`general`),children:[(0,k.jsx)(g,{}),(0,k.jsx)(b,{})]}),(0,k.jsx)(`div`,{className:v(`agentRuntime`),children:(0,k.jsx)(E,{})}),(0,k.jsx)(`div`,{className:v(`branch`),children:(0,k.jsx)(T,{})}),(0,k.jsx)(`div`,{className:v(`environment`),children:(0,k.jsx)(w,{})}),(0,k.jsx)(`div`,{className:v(`budget`),children:(0,k.jsx)(C,{})}),(0,k.jsx)(`div`,{className:v(`telemetry`),children:(0,k.jsx)(h,{})}),(0,k.jsx)(`div`,{className:v(`terminal`),children:(0,k.jsx)(x,{mode:`project`})})]})]})]})})}export{j as ProjectSettingsDialog};
@@ -1,4 +1,4 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{t as r}from"./useSharedWebSocket-Dz-HI6De.js";import{n as i,t as a}from"./createLucideIcon-Bjbbp_KS.js";import{i as o}from"./useDesktop-QogiN0zR.js";import{a as s,i as c,l,o as u,r as d,t as f}from"./dialog-xXB2q5HJ.js";import{t as p}from"./button-Ccc9Dc-D.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`,`partial_success`,`partial_delivery`,`existing_pr_updated`,`no_changes`,`commit_failed`,`branch_verification_failed`,`push_failed`,`settlement_interrupted`,`recovery_unavailable`,`operation_interrupted`,`delivery_failed`,`pr_draft_ready`,`pr_ready`,`pr_closed`,`merged`,`discarded`,`superseded`,`cleanup_incomplete`,`status_failed`,`ref_mismatch`]);function b(e){return typeof e==`string`&&y.has(e)}var x=`previous delivery action was interrupted by restart`;function S(e,t){return e===`operation_interrupted`||typeof t==`string`&&t.toLowerCase().includes(x)}var C=e=>typeof e==`string`&&e.length>0?e:null,w=e=>typeof e==`string`&&e.length>0?e:null;function T(e){if(!e)return null;let t=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(e)?`${e.replace(` `,`T`)}Z`:e,n=Date.parse(t);return Number.isFinite(n)?n:null}function ee(e,t){let n=T(e),r=T(t);return n==null||r==null?null:r<n?-1:+(r>n)}function te(e){if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.ticketId!=`number`||!Number.isFinite(t.ticketId)||typeof t.branch!=`string`)return null;let n=typeof t.implementationOutcome==`string`&&g.has(t.implementationOutcome)?t.implementationOutcome:void 0,r=typeof t.deliveryOutcome==`string`&&_.has(t.deliveryOutcome)?t.deliveryOutcome:void 0;return{ticketId:t.ticketId,branch:t.branch,succeeded:t.succeeded===!0,...C(t.runId)?{runId:C(t.runId)}:{},...n?{implementationOutcome:n}:{},...r?{deliveryOutcome:r}:{},initialSha:w(t.initialSha),finalSha:w(t.finalSha),...typeof t.changed==`boolean`?{changed:t.changed}:{},failureCode:w(t.failureCode),...t.branchOwnership===`created`||t.branchOwnership===`preexisting`||t.branchOwnership===`borrowed-pr`?{branchOwnership:t.branchOwnership}:{},worktreePath:w(t.worktreePath)}}function E(e,t){if(!e||typeof e!=`object`)return null;let n=e,r=C(n.prDeliveryId)??C(n.id),i=typeof n.railIndex==`number`&&Number.isFinite(n.railIndex)?n.railIndex:t;if(!r||i==null||typeof n.decision!=`string`||!m.has(n.decision))return null;let a=typeof n.implementationOutcome==`string`&&g.has(n.implementationOutcome)?n.implementationOutcome:void 0,o=typeof n.deliveryOutcome==`string`&&_.has(n.deliveryOutcome)?n.deliveryOutcome:void 0,s=(Array.isArray(n.units)?n.units:Array.isArray(n.branches)?n.branches:[]).map(te).filter(e=>e!==null);return{prDeliveryId:r,railIndex:i,railKey:typeof n.railKey==`string`?n.railKey:``,ticketIds:Array.isArray(n.ticketIds)?n.ticketIds.filter(e=>typeof e==`number`&&Number.isFinite(e)):[],baseBranch:typeof n.baseBranch==`string`?n.baseBranch:``,branch:w(n.branch),prUrl:w(n.prUrl),prNumber:typeof n.prNumber==`number`&&Number.isInteger(n.prNumber)&&n.prNumber>0?n.prNumber:null,prState:typeof n.prState==`string`&&h.has(n.prState)?n.prState:`none`,decision:n.decision,runIds:Array.isArray(n.runIds)?n.runIds.filter(e=>typeof e==`string`&&e.length>0):s.map(e=>e.runId).filter(e=>typeof e==`string`&&e.length>0),originConversationId:w(n.originConversationId),createdAt:typeof n.createdAt==`string`?n.createdAt:void 0,updatedAt:typeof n.updatedAt==`string`?n.updatedAt:void 0,...a?{implementationOutcome:a}:{},...o?{deliveryOutcome:o}:{},statusCode:w(n.statusCode),statusDetail:w(n.statusDetail),deliverySha:w(n.deliverySha),isContinuation:n.isContinuation===!0,supersedesDeliveryId:w(n.supersedesDeliveryId),restoredFromDeliveryId:w(n.restoredFromDeliveryId),operation:typeof n.operation==`string`&&v.has(n.operation)?n.operation:null,cleanupWarnings:Array.isArray(n.cleanupWarnings)?n.cleanupWarnings.filter(e=>typeof e==`string`&&e.length>0):[],safetyArchives:Array.isArray(n.safetyArchives)?n.safetyArchives.filter(e=>typeof e==`string`&&e.length>0):[],units:s,executionManifest:n.executionManifest&&typeof n.executionManifest==`object`&&n.executionManifest.version===1?n.executionManifest:void 0,repositoryDeliveries:Array.isArray(n.repositoryDeliveries)?n.repositoryDeliveries.slice(0,100).flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e;if(typeof t.repositoryId!=`string`||typeof t.deliveryId!=`string`||typeof t.name!=`string`||typeof t.path!=`string`)return[];let n=E({...t,prDeliveryId:t.deliveryId,repositoryDeliveries:void 0},i);return n?[{repositoryId:t.repositoryId,deliveryId:t.deliveryId,name:t.name,path:t.path,baseBranch:n.baseBranch,...C(t.integrationBranch)?{integrationBranch:C(t.integrationBranch)}:{},branch:n.branch,deliverySha:n.deliverySha??null,decision:n.decision,implementationOutcome:n.implementationOutcome??`unknown`,deliveryOutcome:n.deliveryOutcome??`unknown`,statusCode:n.statusCode??null,statusDetail:n.statusDetail??null,prUrl:n.prUrl,prNumber:n.prNumber,runIds:n.runIds,worktreeIds:Array.isArray(t.worktreeIds)?t.worktreeIds.filter(e=>typeof e==`string`):[]}]:[]}):void 0}}function ne(e){let t=D(e);if(t.terminal||t.deliveryBlocked||t.implementationFailed||t.noChanges||e.decision===`building`||e.decision===`implementation_failed`)return null;if(e.branch||e.deliverySha)return e.branch&&/^[0-9a-f]{40,64}$/i.test(e.deliverySha??``)?e.branch:null;let n=e.units??[];if(n.length!==1)return null;let r=n[0];return!r.succeeded||r.implementationOutcome===`failed`||r.deliveryOutcome===`blocked`||r.deliveryOutcome===`no_changes`||r.changed===!1?null:r.branch&&/^[0-9a-f]{40,64}$/i.test(r.finalSha??``)?r.branch:null}function D(e){let t=e.units??[],n=t.length>0?t.filter(e=>e.implementationOutcome===`succeeded`||e.implementationOutcome==null&&e.succeeded).length:e.implementationOutcome===`failed`?0:e.ticketIds.length,r=t.length>0?t.filter(e=>e.implementationOutcome===`failed`||e.implementationOutcome==null&&!e.succeeded).length:e.implementationOutcome===`failed`?e.ticketIds.length:0,i=e.decision===`no_changes`||e.decision===`completed`||e.deliveryOutcome===`no_changes`||e.statusCode===`no_changes`,a=e.implementationOutcome===`partially_succeeded`||e.deliveryOutcome===`partial`||n>0&&r>0,o=t.length>0?t.filter(e=>e.deliveryOutcome===`ready`||e.deliveryOutcome===`delivered`||e.deliveryOutcome==null&&e.succeeded).length:a?0:n,s=a&&o===0,c=e.implementationOutcome===`failed`||e.implementationOutcome==null&&e.decision===`implementation_failed`,l=e.deliveryOutcome===`retryable_failure`,u=!c&&!l&&(s||e.deliveryOutcome===`blocked`||[`commit_failed`,`branch_verification_failed`,`settlement_interrupted`,`recovery_unavailable`,`status_failed`,`ref_mismatch`,`delivery_failed`].includes(e.statusCode??``)),d=e.isContinuation===!0,f=[...new Set((e.runIds??[]).filter(e=>typeof e==`string`&&e.length>0))],p=f.length===1?f[0]:null,m=p&&e.branch?t.filter(t=>t.runId===p&&t.branch===e.branch):[],h=[...new Set(m.map(e=>e.worktreePath).filter(e=>!!e))],g=(e.statusCode===`settlement_interrupted`||e.statusCode===`recovery_unavailable`)&&d?h:[...new Set(t.map(e=>e.worktreePath).filter(e=>!!e))],_=e.decision===`pr_failed`&&e.deliveryOutcome===`blocked`&&u&&d&&!!e.prUrl&&!!e.branch&&f.length===1&&m.length>0&&h.length<=1&&e.statusCode===`settlement_interrupted`&&(e.implementationOutcome===`succeeded`||e.implementationOutcome===`partially_succeeded`),v=e.decision===`pr_failed`&&e.deliveryOutcome===`blocked`&&u&&d&&e.statusCode===`recovery_unavailable`,y=v&&!!e.prUrl&&!!e.branch&&f.length===1&&m.length>0&&h.length<=1&&(e.implementationOutcome===`succeeded`||e.implementationOutcome===`partially_succeeded`),b=g.length>0||v&&!!e.deliverySha,x=!c&&l&&(e.statusCode===`push_failed`||d||!!e.prUrl),S=!c&&l&&!x,C=e.decision===`pr_closed`,w=e.decision===`superseded`;return{noChanges:i,partial:a,partialUndeliverable:s,implementationFailed:c,deliveryBlocked:u,retryablePush:x,retryablePrCreation:S,manualRecovery:_,recoveryUnavailable:v,recoveryRecheck:y,hasDiscardableRecoveryResult:b,continuation:d,localOnly:e.prState===`local-only`,closed:C,superseded:w,terminal:e.decision===`merged`||e.decision===`discarded`||e.decision===`completed`||w,succeededCount:n,deliverableCount:o,failedCount:r,totalCount:t.length>0?t.length:e.ticketIds.length,units:t,cleanupWarnings:e.cleanupWarnings??[],safetyArchives:e.safetyArchives??[],recoveryWorktreePaths:g}}var re=a(`send-horizontal`,[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]]),O=e(t(),1),ie=`"\\/bfnrtu`;function k(e){return e===` `||e===` `||e===`\r`||e===`
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{n as t,t as n}from"./jsx-runtime-zu2_FqZY.js";import{t as r}from"./useSharedWebSocket-BZMrX4jr.js";import{n as i,t as a}from"./createLucideIcon-Bjbbp_KS.js";import{i as o}from"./useDesktop-0unHDBJJ.js";import{a as s,i as c,l,o as u,r as d,t as f}from"./dialog-xXB2q5HJ.js";import{t as p}from"./button-Ccc9Dc-D.js";var m=new Set([`building`,`on_review`,`pr_draft`,`pr_ready`,`no_changes`,`completed`,`pr_closed`,`superseded`,`merged`,`discarded`,`implementation_failed`,`pr_failed`]),h=new Set([`none`,`local-only`,`pushed`,`pr-created`]),g=new Set([`running`,`succeeded`,`partially_succeeded`,`failed`,`unknown`]),_=new Set([`pending`,`ready`,`delivered`,`partial`,`no_changes`,`retryable_failure`,`blocked`,`not_started`,`unknown`]),v=new Set([`create-pr`,`publish`,`discard`,`poll-merge`,`merge-local`,`dismiss`,`reopen`,`acknowledge-no-changes`,`recover-and-retry`,`checkout`]),y=new Set([`implementation_running`,`implementation_failed`,`ready_for_review`,`restart_pending`,`partial_success`,`partial_delivery`,`existing_pr_updated`,`no_changes`,`commit_failed`,`branch_verification_failed`,`push_failed`,`settlement_interrupted`,`recovery_unavailable`,`operation_interrupted`,`delivery_failed`,`pr_draft_ready`,`pr_ready`,`pr_closed`,`merged`,`discarded`,`superseded`,`cleanup_incomplete`,`status_failed`,`ref_mismatch`]);function b(e){return typeof e==`string`&&y.has(e)}var x=`previous delivery action was interrupted by restart`;function S(e,t){return e===`operation_interrupted`||typeof t==`string`&&t.toLowerCase().includes(x)}var C=e=>typeof e==`string`&&e.length>0?e:null,w=e=>typeof e==`string`&&e.length>0?e:null;function T(e){if(!e)return null;let t=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(e)?`${e.replace(` `,`T`)}Z`:e,n=Date.parse(t);return Number.isFinite(n)?n:null}function ee(e,t){let n=T(e),r=T(t);return n==null||r==null?null:r<n?-1:+(r>n)}function te(e){if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.ticketId!=`number`||!Number.isFinite(t.ticketId)||typeof t.branch!=`string`)return null;let n=typeof t.implementationOutcome==`string`&&g.has(t.implementationOutcome)?t.implementationOutcome:void 0,r=typeof t.deliveryOutcome==`string`&&_.has(t.deliveryOutcome)?t.deliveryOutcome:void 0;return{ticketId:t.ticketId,branch:t.branch,succeeded:t.succeeded===!0,...C(t.runId)?{runId:C(t.runId)}:{},...n?{implementationOutcome:n}:{},...r?{deliveryOutcome:r}:{},initialSha:w(t.initialSha),finalSha:w(t.finalSha),...typeof t.changed==`boolean`?{changed:t.changed}:{},failureCode:w(t.failureCode),...t.branchOwnership===`created`||t.branchOwnership===`preexisting`||t.branchOwnership===`borrowed-pr`?{branchOwnership:t.branchOwnership}:{},worktreePath:w(t.worktreePath)}}function E(e,t){if(!e||typeof e!=`object`)return null;let n=e,r=C(n.prDeliveryId)??C(n.id),i=typeof n.railIndex==`number`&&Number.isFinite(n.railIndex)?n.railIndex:t;if(!r||i==null||typeof n.decision!=`string`||!m.has(n.decision))return null;let a=typeof n.implementationOutcome==`string`&&g.has(n.implementationOutcome)?n.implementationOutcome:void 0,o=typeof n.deliveryOutcome==`string`&&_.has(n.deliveryOutcome)?n.deliveryOutcome:void 0,s=(Array.isArray(n.units)?n.units:Array.isArray(n.branches)?n.branches:[]).map(te).filter(e=>e!==null);return{prDeliveryId:r,railIndex:i,railKey:typeof n.railKey==`string`?n.railKey:``,ticketIds:Array.isArray(n.ticketIds)?n.ticketIds.filter(e=>typeof e==`number`&&Number.isFinite(e)):[],baseBranch:typeof n.baseBranch==`string`?n.baseBranch:``,branch:w(n.branch),prUrl:w(n.prUrl),prNumber:typeof n.prNumber==`number`&&Number.isInteger(n.prNumber)&&n.prNumber>0?n.prNumber:null,prState:typeof n.prState==`string`&&h.has(n.prState)?n.prState:`none`,decision:n.decision,runIds:Array.isArray(n.runIds)?n.runIds.filter(e=>typeof e==`string`&&e.length>0):s.map(e=>e.runId).filter(e=>typeof e==`string`&&e.length>0),originConversationId:w(n.originConversationId),createdAt:typeof n.createdAt==`string`?n.createdAt:void 0,updatedAt:typeof n.updatedAt==`string`?n.updatedAt:void 0,...a?{implementationOutcome:a}:{},...o?{deliveryOutcome:o}:{},statusCode:w(n.statusCode),statusDetail:w(n.statusDetail),deliverySha:w(n.deliverySha),isContinuation:n.isContinuation===!0,supersedesDeliveryId:w(n.supersedesDeliveryId),restoredFromDeliveryId:w(n.restoredFromDeliveryId),operation:typeof n.operation==`string`&&v.has(n.operation)?n.operation:null,cleanupWarnings:Array.isArray(n.cleanupWarnings)?n.cleanupWarnings.filter(e=>typeof e==`string`&&e.length>0):[],safetyArchives:Array.isArray(n.safetyArchives)?n.safetyArchives.filter(e=>typeof e==`string`&&e.length>0):[],units:s,executionManifest:n.executionManifest&&typeof n.executionManifest==`object`&&n.executionManifest.version===1?n.executionManifest:void 0,repositoryDeliveries:Array.isArray(n.repositoryDeliveries)?n.repositoryDeliveries.slice(0,100).flatMap(e=>{if(!e||typeof e!=`object`)return[];let t=e;if(typeof t.repositoryId!=`string`||typeof t.deliveryId!=`string`||typeof t.name!=`string`||typeof t.path!=`string`)return[];let n=E({...t,prDeliveryId:t.deliveryId,repositoryDeliveries:void 0},i);return n?[{repositoryId:t.repositoryId,deliveryId:t.deliveryId,name:t.name,path:t.path,baseBranch:n.baseBranch,...C(t.integrationBranch)?{integrationBranch:C(t.integrationBranch)}:{},branch:n.branch,deliverySha:n.deliverySha??null,decision:n.decision,implementationOutcome:n.implementationOutcome??`unknown`,deliveryOutcome:n.deliveryOutcome??`unknown`,statusCode:n.statusCode??null,statusDetail:n.statusDetail??null,prUrl:n.prUrl,prNumber:n.prNumber,runIds:n.runIds,worktreeIds:Array.isArray(t.worktreeIds)?t.worktreeIds.filter(e=>typeof e==`string`):[]}]:[]}):void 0}}function ne(e){let t=D(e);if(t.terminal||t.deliveryBlocked||t.implementationFailed||t.noChanges||e.decision===`building`||e.decision===`implementation_failed`)return null;if(e.branch||e.deliverySha)return e.branch&&/^[0-9a-f]{40,64}$/i.test(e.deliverySha??``)?e.branch:null;let n=e.units??[];if(n.length!==1)return null;let r=n[0];return!r.succeeded||r.implementationOutcome===`failed`||r.deliveryOutcome===`blocked`||r.deliveryOutcome===`no_changes`||r.changed===!1?null:r.branch&&/^[0-9a-f]{40,64}$/i.test(r.finalSha??``)?r.branch:null}function D(e){let t=e.units??[],n=t.length>0?t.filter(e=>e.implementationOutcome===`succeeded`||e.implementationOutcome==null&&e.succeeded).length:e.implementationOutcome===`failed`?0:e.ticketIds.length,r=t.length>0?t.filter(e=>e.implementationOutcome===`failed`||e.implementationOutcome==null&&!e.succeeded).length:e.implementationOutcome===`failed`?e.ticketIds.length:0,i=e.decision===`no_changes`||e.decision===`completed`||e.deliveryOutcome===`no_changes`||e.statusCode===`no_changes`,a=e.implementationOutcome===`partially_succeeded`||e.deliveryOutcome===`partial`||n>0&&r>0,o=t.length>0?t.filter(e=>e.deliveryOutcome===`ready`||e.deliveryOutcome===`delivered`||e.deliveryOutcome==null&&e.succeeded).length:a?0:n,s=a&&o===0,c=e.implementationOutcome===`failed`||e.implementationOutcome==null&&e.decision===`implementation_failed`,l=e.deliveryOutcome===`retryable_failure`,u=!c&&!l&&(s||e.deliveryOutcome===`blocked`||[`commit_failed`,`branch_verification_failed`,`settlement_interrupted`,`recovery_unavailable`,`status_failed`,`ref_mismatch`,`delivery_failed`].includes(e.statusCode??``)),d=e.isContinuation===!0,f=[...new Set((e.runIds??[]).filter(e=>typeof e==`string`&&e.length>0))],p=f.length===1?f[0]:null,m=p&&e.branch?t.filter(t=>t.runId===p&&t.branch===e.branch):[],h=[...new Set(m.map(e=>e.worktreePath).filter(e=>!!e))],g=(e.statusCode===`settlement_interrupted`||e.statusCode===`recovery_unavailable`)&&d?h:[...new Set(t.map(e=>e.worktreePath).filter(e=>!!e))],_=e.decision===`pr_failed`&&e.deliveryOutcome===`blocked`&&u&&d&&!!e.prUrl&&!!e.branch&&f.length===1&&m.length>0&&h.length<=1&&e.statusCode===`settlement_interrupted`&&(e.implementationOutcome===`succeeded`||e.implementationOutcome===`partially_succeeded`),v=e.decision===`pr_failed`&&e.deliveryOutcome===`blocked`&&u&&d&&e.statusCode===`recovery_unavailable`,y=v&&!!e.prUrl&&!!e.branch&&f.length===1&&m.length>0&&h.length<=1&&(e.implementationOutcome===`succeeded`||e.implementationOutcome===`partially_succeeded`),b=g.length>0||v&&!!e.deliverySha,x=!c&&l&&(e.statusCode===`push_failed`||d||!!e.prUrl),S=!c&&l&&!x,C=e.decision===`pr_closed`,w=e.decision===`superseded`;return{noChanges:i,partial:a,partialUndeliverable:s,implementationFailed:c,deliveryBlocked:u,retryablePush:x,retryablePrCreation:S,manualRecovery:_,recoveryUnavailable:v,recoveryRecheck:y,hasDiscardableRecoveryResult:b,continuation:d,localOnly:e.prState===`local-only`,closed:C,superseded:w,terminal:e.decision===`merged`||e.decision===`discarded`||e.decision===`completed`||w,succeededCount:n,deliverableCount:o,failedCount:r,totalCount:t.length>0?t.length:e.ticketIds.length,units:t,cleanupWarnings:e.cleanupWarnings??[],safetyArchives:e.safetyArchives??[],recoveryWorktreePaths:g}}var re=a(`send-horizontal`,[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]]),O=e(t(),1),ie=`"\\/bfnrtu`;function k(e){return e===` `||e===` `||e===`\r`||e===`
2
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
3
  `?`\\n`:i,e+=1,t.add(`invalid_escape`);continue}if(r===`"`){let i=e+1;for(;i<n.length&&k(n[i]);)i+=1;let a=n[i];if(a===void 0||a===`,`||a===`}`||a===`]`||a===`:`){c=!1,s+=r;continue}s+=`\\"`,t.add(`inner_quote`);continue}if(r===`
4
4
  `){s+=`\\n`,t.add(`raw_newline`);continue}if(r===`\r`){t.add(`raw_newline`);continue}if(r===` `){s+=`\\t`,t.add(`raw_control`);continue}let i=r.charCodeAt(0);if(i<32){s+=`\\u`+i.toString(16).padStart(4,`0`),t.add(`raw_control`);continue}s+=r;continue}if(r===`"`){c=!0,s+=r;continue}if(r===`,`){let i=e+1;for(;i<n.length&&k(n[i]);)i+=1;if(n[i]===`}`||n[i]===`]`){t.add(`trailing_comma`);continue}s+=r;continue}if(r===`/`&&n[e+1]===`/`){let r=n.indexOf(`
@@ -1 +1 @@
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-QogiN0zR.js";import{t as r}from"./project-repositories-9Wzs0coQ.js";var i=e();function a({value:e,onChange:a,disabled:o=!1,repositories:s}){let{t:c}=t(`common`),{activeProjectId:l,projects:u}=n(),d=s??r(u.find(e=>e.id===l)),f=d.find(e=>e.isPrimary),p=e??(f?[f.id]:[]),m=p.some(e=>!d.some(t=>t.id===e));return d.length<=1&&!m?null:(0,i.jsxs)(`fieldset`,{className:`space-y-2`,disabled:o,children:[(0,i.jsx)(`legend`,{className:`mb-1 text-xs font-medium`,children:c(`repositories.specScope`)}),(0,i.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c(`repositories.scopeHint`)}),(0,i.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[d.map(e=>(0,i.jsxs)(`label`,{title: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`,checked:p.includes(e.id),disabled:o||e.kind===`folder`&&!e.isPrimary&&!p.includes(e.id)||p.length===1&&p[0]===e.id,onChange:t=>a(t.target.checked?[...p,e.id]:p.filter(t=>t!==e.id))}),e.name,e.kind===`folder`&&!e.isPrimary&&(0,i.jsx)(`span`,{className:`text-muted-foreground`,children:c(`repositories.contextOnly`)})]},e.id)),p.filter(e=>!d.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`,checked:!0,disabled:o||p.length===1,onChange:()=>a(p.filter(t=>t!==e))}),c(`repositories.unavailable`),`: `,e]},e))]}),m&&(0,i.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:c(`repositories.invalidSelection`)})]})}export{a as t};
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-0unHDBJJ.js";import{t as r}from"./project-repositories-CSnfzUpg.js";var i=e();function a({value:e,onChange:a,disabled:o=!1,repositories:s}){let{t:c}=t(`common`),{activeProjectId:l,projects:u}=n(),d=s??r(u.find(e=>e.id===l)),f=d.find(e=>e.isPrimary),p=e??(f?[f.id]:[]),m=p.some(e=>!d.some(t=>t.id===e));return d.length<=1&&!m?null:(0,i.jsxs)(`fieldset`,{className:`space-y-2`,disabled:o,children:[(0,i.jsx)(`legend`,{className:`mb-1 text-xs font-medium`,children:c(`repositories.specScope`)}),(0,i.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c(`repositories.scopeHint`)}),(0,i.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[d.map(e=>(0,i.jsxs)(`label`,{title: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`,checked:p.includes(e.id),disabled:o||e.kind===`folder`&&!e.isPrimary&&!p.includes(e.id)||p.length===1&&p[0]===e.id,onChange:t=>a(t.target.checked?[...p,e.id]:p.filter(t=>t!==e.id))}),e.name,e.kind===`folder`&&!e.isPrimary&&(0,i.jsx)(`span`,{className:`text-muted-foreground`,children:c(`repositories.contextOnly`)})]},e.id)),p.filter(e=>!d.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`,checked:!0,disabled:o||p.length===1,onChange:()=>a(p.filter(t=>t!==e))}),c(`repositories.unavailable`),`: `,e]},e))]}),m&&(0,i.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,children:c(`repositories.invalidSelection`)})]})}export{a as t};