@openchamber/web 1.18.3 → 1.19.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 (215) hide show
  1. package/README.md +1 -0
  2. package/dist/assets/{CodeMirrorCommentWidgets-DbUi6I9s.js → CodeMirrorCommentWidgets-DAvopJvy.js} +1 -1
  3. package/dist/assets/{CommitSection-Jc2_hNPE.js → CommitSection-D9cV-qR9.js} +1 -1
  4. package/dist/assets/{DiagramEditor-PCrYHBko.js → DiagramEditor-B9NCadU7.js} +1 -1
  5. package/dist/assets/DiagramView-LKGBwf4G.js +1 -0
  6. package/dist/assets/{DiffView-DEGlNjMH.js → DiffView-BWNq-0ov.js} +2 -2
  7. package/dist/assets/FilesView-DB-Q0Gkz.js +14 -0
  8. package/dist/assets/{GitView-C-n17voy.js → GitView-DsWXqWx3.js} +3 -3
  9. package/dist/assets/{JsonTreeView-BYcgdTOQ.js → JsonTreeView-h4dHASlq.js} +1 -1
  10. package/dist/assets/MarkdownImageGallery-n0ikH-xm.js +1 -0
  11. package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +12 -0
  12. package/dist/assets/OnboardingScreen-CDjgzxEe.js +1 -0
  13. package/dist/assets/{PatchDiff-Bn7bfgUv.js → PatchDiff-jPKTJje5.js} +1 -1
  14. package/dist/assets/{PierreDiffViewer-D1fWvrUn.js → PierreDiffViewer-D_Gt4A_6.js} +1 -1
  15. package/dist/assets/PlanView-UvuxIl9-.js +4 -0
  16. package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +1 -0
  17. package/dist/assets/SettingsView-3B9VN6Ys.js +28 -0
  18. package/dist/assets/SettingsWindow-CqQNDKNd.js +1 -0
  19. package/dist/assets/{ToolOutputDialog-BtIJkFno.js → ToolOutputDialog-PmjlAxVE.js} +6 -6
  20. package/dist/assets/{ToolPartDiffPreview-i3PQo6_0.js → ToolPartDiffPreview-B34Xw9wq.js} +1 -1
  21. package/dist/assets/{VirtualizedFileDiff-DkcusvMa.js → VirtualizedFileDiff-B37yB9jZ.js} +3 -3
  22. package/dist/assets/{WalkthroughView-Cc5Hd6P5.js → WalkthroughView-Bxun3k66.js} +2 -2
  23. package/dist/assets/{computeVirtualFileMetrics-xPena3W2.js → computeVirtualFileMetrics-DYFv_yZS.js} +2 -2
  24. package/dist/assets/contextPanelEmbeddedChat-BO1wRpaN.js +1 -0
  25. package/dist/assets/de-DbV6CLxv.js +9 -0
  26. package/dist/assets/document-attachments-DFAWlG3U.js +31 -0
  27. package/dist/assets/es-CVDlyzZ4.js +15 -0
  28. package/dist/assets/fr-Czc-p0g-.js +13 -0
  29. package/dist/assets/index-1OhiMDBz.css +1 -0
  30. package/dist/assets/index-BSvmTvZl.js +1 -0
  31. package/dist/assets/index-DzriVon2.js +7 -0
  32. package/dist/assets/{isDiffPlainText-Dudf-dWx.js → isDiffPlainText-DwHKxDYc.js} +1 -1
  33. package/dist/assets/{isFilePlainText-DS4QV1dd.js → isFilePlainText-Dwq6ILxo.js} +1 -1
  34. package/dist/assets/ja-dwc9NM_S.js +15 -0
  35. package/dist/assets/ko-Ds1DZ8FX.js +15 -0
  36. package/dist/assets/{lua-BgMRiT3U.js → lua-VAEuO923.js} +1 -1
  37. package/dist/assets/main-BF51IOVF.js +921 -0
  38. package/dist/assets/{main-C0DyIwTb.js → main-D7UPARut.js} +2 -2
  39. package/dist/assets/markdownCore-BgeBDwD3.js +2 -0
  40. package/dist/assets/{miniChat-CGfrxKpJ.js → miniChat-BISXSGOo.js} +2 -2
  41. package/dist/assets/mobile-BnYxVuvw.js +2 -0
  42. package/dist/assets/{patchFileDiff-C5D1OPCa.js → patchFileDiff-BEDPDypx.js} +2 -2
  43. package/dist/assets/pl-CLiTO7i-.js +15 -0
  44. package/dist/assets/pt-BR-GIimJgpK.js +15 -0
  45. package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +2 -0
  46. package/dist/assets/{renderMobileApp-B5HA4qbi.js → renderMobileApp-BiMbzPq9.js} +7 -7
  47. package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +15 -0
  48. package/dist/assets/scheduledTasksApi-01zzfzqH.js +1 -0
  49. package/dist/assets/{shikiHighlight-CmanopUB.js → shikiHighlight-DXYW46vW.js} +1 -1
  50. package/dist/assets/uk-DLfgD1ki.js +15 -0
  51. package/dist/assets/{useAppFontEffects-sHmU5b8u.js → useAppFontEffects-CbzHzFop.js} +139 -142
  52. package/dist/assets/{useInlineCommentController-gt56WkxJ.js → useInlineCommentController-CegKdDXi.js} +2 -2
  53. package/dist/assets/{vendor-base-ui-D_V6hAcE.js → vendor-base-ui-BYlZTzrw.js} +1 -1
  54. package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +1 -0
  55. package/dist/assets/vendor-codemirror-commands-B7H_j0iU.js +1 -0
  56. package/dist/assets/{vendor-codemirror-lang-angular-CgY7_gQ1.js → vendor-codemirror-lang-angular-DEPs2M5t.js} +1 -1
  57. package/dist/assets/{vendor-codemirror-lang-cpp-B5Ta4enQ.js → vendor-codemirror-lang-cpp-DhkseaMo.js} +1 -1
  58. package/dist/assets/{vendor-codemirror-lang-css-VgNqFSH-.js → vendor-codemirror-lang-css-O0cZX78y.js} +1 -1
  59. package/dist/assets/{vendor-codemirror-lang-go-LxLz62pp.js → vendor-codemirror-lang-go-fMdQYcON.js} +1 -1
  60. package/dist/assets/vendor-codemirror-lang-html-CfgK872x.js +1 -0
  61. package/dist/assets/{vendor-codemirror-lang-java-Bksi1PH4.js → vendor-codemirror-lang-java-CQj4S3zl.js} +1 -1
  62. package/dist/assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js +13 -0
  63. package/dist/assets/{vendor-codemirror-lang-jinja-C7npuDD7.js → vendor-codemirror-lang-jinja-BmZZv8g-.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-json-ryCw7nab.js → vendor-codemirror-lang-json-CMBS2tG9.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-less-BxsZJD6N.js → vendor-codemirror-lang-less-C6Eo8hVS.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-liquid-De6qch10.js → vendor-codemirror-lang-liquid-DSTR47-H.js} +1 -1
  67. package/dist/assets/vendor-codemirror-lang-markdown-BPGOH9ye.js +1 -0
  68. package/dist/assets/{vendor-codemirror-lang-php-Cm1es33p.js → vendor-codemirror-lang-php-DD9udfPH.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-python-N414WYK-.js → vendor-codemirror-lang-python-HahnQaAS.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-rust-C_WuUStH.js → vendor-codemirror-lang-rust-nLTovbjv.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-sass-8UHTCAOM.js → vendor-codemirror-lang-sass-pL2Yc72v.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-sql-CV3sMA5D.js → vendor-codemirror-lang-sql-BVBnan19.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-vue-DzvC1Dhk.js → vendor-codemirror-lang-vue-BqGzJVm1.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-wast-jlr-LDdA.js → vendor-codemirror-lang-wast-B0_m5DqU.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-xml-CrO63OVp.js → vendor-codemirror-lang-xml-Dj3voadT.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-yaml-dxi6CISW.js → vendor-codemirror-lang-yaml-yu-9Z5u7.js} +1 -1
  77. package/dist/assets/vendor-codemirror-language-BgPj_McA.js +3 -0
  78. package/dist/assets/{vendor-codemirror-language-data-Dihw9MtL.js → vendor-codemirror-language-data-CiAYDJXN.js} +2 -2
  79. package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +2 -0
  80. package/dist/assets/{vendor-codemirror-state-CNWM3Q8V.js → vendor-codemirror-state-C9awkmn-.js} +5 -5
  81. package/dist/assets/vendor-codemirror-view-CiLROUVV.js +4 -0
  82. package/dist/assets/vendor-replit-codemirror-vim-B2DJlAhT.js +6 -0
  83. package/dist/assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js +34 -0
  84. package/dist/assets/vendor-zod-adaMkgkm.js +39 -0
  85. package/dist/assets/{web-components-BL-Ur2Tb.js → web-components-DCLjCO9n.js} +1 -1
  86. package/dist/assets/zh-CN-DkeP5awK.js +15 -0
  87. package/dist/assets/zh-TW-BocaFm3d.js +15 -0
  88. package/dist/index.html +4 -4
  89. package/dist/mini-chat.html +3 -3
  90. package/dist/mobile.html +3 -3
  91. package/package.json +1 -1
  92. package/server/index.js +116 -3
  93. package/server/lib/agent-memory/actions.js +243 -0
  94. package/server/lib/agent-memory/actions.test.js +343 -0
  95. package/server/lib/agent-memory/feature-flag.js +19 -0
  96. package/server/lib/agent-memory/feature-flag.test.js +38 -0
  97. package/server/lib/agent-memory/project-resolution.js +56 -0
  98. package/server/lib/agent-memory/project-resolution.test.js +85 -0
  99. package/server/lib/agent-memory/routes.http.test.js +270 -0
  100. package/server/lib/agent-memory/routes.js +169 -0
  101. package/server/lib/agent-memory/runtime.js +427 -0
  102. package/server/lib/agent-memory/runtime.test.js +344 -0
  103. package/server/lib/agent-memory/threat-patterns.js +61 -0
  104. package/server/lib/agent-memory/threat-patterns.test.js +61 -0
  105. package/server/lib/agent-tool/DOCUMENTATION.md +14 -0
  106. package/server/lib/agent-tool/runtime.js +63 -13
  107. package/server/lib/agent-tool/runtime.test.js +85 -2
  108. package/server/lib/context-obligatory/runtime.js +34 -3
  109. package/server/lib/context-obligatory/runtime.test.js +114 -0
  110. package/server/lib/dev-tunnel/client.js +20 -1
  111. package/server/lib/dev-tunnel/tunnel.test.js +9 -0
  112. package/server/lib/fs/DOCUMENTATION.md +3 -0
  113. package/server/lib/fs/routes.js +149 -32
  114. package/server/lib/fs/routes.test.js +225 -0
  115. package/server/lib/git/DOCUMENTATION.md +8 -0
  116. package/server/lib/git/service.js +121 -67
  117. package/server/lib/git/service.test.js +129 -0
  118. package/server/lib/github/DOCUMENTATION.md +14 -3
  119. package/server/lib/github/pr-status.js +188 -83
  120. package/server/lib/github/pr-status.test.js +182 -0
  121. package/server/lib/github/routes.js +36 -30
  122. package/server/lib/markdown-image-grants/DOCUMENTATION.md +36 -0
  123. package/server/lib/markdown-image-grants/routes.js +340 -0
  124. package/server/lib/markdown-image-grants/routes.test.js +221 -0
  125. package/server/lib/notifications/template-runtime.js +2 -3
  126. package/server/lib/openchamber-control/action-resolution.test.js +65 -0
  127. package/server/lib/openchamber-control/actions.js +78 -0
  128. package/server/lib/openchamber-control/service.js +7 -0
  129. package/server/lib/openchamber-sessions/routes.js +14 -0
  130. package/server/lib/opencode/DOCUMENTATION.md +6 -4
  131. package/server/lib/opencode/claude-cli-auth.js +60 -0
  132. package/server/lib/opencode/claude-cli-auth.test.js +54 -0
  133. package/server/lib/opencode/feature-routes-runtime.js +22 -0
  134. package/server/lib/opencode/plugins.js +12 -3
  135. package/server/lib/opencode/plugins.test.js +18 -0
  136. package/server/lib/opencode/proxy-agent-wiring.test.js +152 -0
  137. package/server/lib/opencode/proxy.js +116 -6
  138. package/server/lib/opencode/proxy.test.js +158 -1
  139. package/server/lib/opencode/routes.js +4 -1
  140. package/server/lib/opencode/server-startup-runtime.js +22 -1
  141. package/server/lib/opencode/server-startup-runtime.test.js +44 -0
  142. package/server/lib/opencode/settings-helpers.js +11 -0
  143. package/server/lib/opencode/settings-helpers.test.js +35 -0
  144. package/server/lib/opencode/settings-runtime.js +51 -0
  145. package/server/lib/opencode/shared.js +120 -16
  146. package/server/lib/opencode/shared.test.js +185 -1
  147. package/server/lib/project-context/DOCUMENTATION.md +158 -0
  148. package/server/lib/project-context/routes.http.test.js +264 -0
  149. package/server/lib/project-context/routes.js +237 -0
  150. package/server/lib/project-context/runtime.js +667 -0
  151. package/server/lib/project-context/runtime.test.js +498 -0
  152. package/server/lib/quota/DOCUMENTATION.md +16 -1
  153. package/server/lib/quota/providers/claude/auth.js +113 -0
  154. package/server/lib/quota/providers/claude/auth.test.js +117 -0
  155. package/server/lib/quota/providers/claude/index.js +151 -0
  156. package/server/lib/quota/providers/claude/index.test.js +147 -0
  157. package/server/lib/quota/providers/claude/transforms.js +127 -0
  158. package/server/lib/quota/providers/claude/transforms.test.js +82 -0
  159. package/server/lib/quota/providers/command-code.js +90 -0
  160. package/server/lib/quota/providers/command-code.test.js +72 -0
  161. package/server/lib/quota/providers/index.js +22 -2
  162. package/server/lib/quota/providers/index.test.js +10 -1
  163. package/server/lib/quota/utils/formatters.js +2 -1
  164. package/server/lib/scheduled-tasks/runtime.js +21 -2
  165. package/server/lib/session-knowledge/DOCUMENTATION.md +87 -0
  166. package/server/lib/session-knowledge/routes.js +107 -0
  167. package/server/lib/session-knowledge/runtime.js +331 -0
  168. package/server/lib/session-knowledge/runtime.test.js +275 -0
  169. package/server/lib/skills-catalog/DOCUMENTATION.md +22 -22
  170. package/server/lib/skills-catalog/curated-sources.js +1 -1
  171. package/server/lib/skills-catalog/curated-sources.test.js +10 -0
  172. package/server/lib/small-model/index.js +8 -0
  173. package/server/lib/small-model/index.test.js +31 -1
  174. package/server/lib/small-model/routes.js +3 -1
  175. package/dist/assets/DiagramView-CndEcZNu.js +0 -1
  176. package/dist/assets/FilesView-CzUgIvUm.js +0 -14
  177. package/dist/assets/MarkdownImageGallery-DzHwkVIH.js +0 -1
  178. package/dist/assets/MarkdownRendererImpl-DUcIcWgs.js +0 -12
  179. package/dist/assets/OnboardingScreen-BmN0lhk4.js +0 -1
  180. package/dist/assets/PlanView-CWM0iyFk.js +0 -4
  181. package/dist/assets/SessionSwitcherDropdown-Cez-9xRh.js +0 -1
  182. package/dist/assets/SettingsView-Bl1drwPw.js +0 -28
  183. package/dist/assets/SettingsWindow-DL5axjDZ.js +0 -1
  184. package/dist/assets/contextPanelEmbeddedChat-tQekJUAF.js +0 -1
  185. package/dist/assets/de-u7gSnqWs.js +0 -9
  186. package/dist/assets/document-attachments-CX_YaDsu.js +0 -30
  187. package/dist/assets/es-T9O7aAOr.js +0 -15
  188. package/dist/assets/fr-Oor7ewbE.js +0 -13
  189. package/dist/assets/index-CVNuER6G.css +0 -1
  190. package/dist/assets/index-Crz1YOFl.js +0 -1
  191. package/dist/assets/index-iFY_N5aO.js +0 -7
  192. package/dist/assets/ja-DHpqbVmr.js +0 -15
  193. package/dist/assets/ko-CwLkS3nx.js +0 -15
  194. package/dist/assets/main-CAxX6DAN.js +0 -915
  195. package/dist/assets/markdownCore-DhfzuGXu.js +0 -2
  196. package/dist/assets/markdownImageAssets-BTNlRyjd.js +0 -1
  197. package/dist/assets/mobile-DEmhwNcV.js +0 -2
  198. package/dist/assets/pl-CcZILN8q.js +0 -15
  199. package/dist/assets/pt-BR-DYHhVK6o.js +0 -15
  200. package/dist/assets/renderElectronMiniChatApp-Dpbswpom.js +0 -2
  201. package/dist/assets/runtimeEndpointReset-cbahJ3hD.js +0 -13
  202. package/dist/assets/scheduledTasksApi-BxgGWTL8.js +0 -1
  203. package/dist/assets/uk-BA2kZR38.js +0 -15
  204. package/dist/assets/vendor-codemirror-autocomplete-BjbBRsUA.js +0 -1
  205. package/dist/assets/vendor-codemirror-commands-ARAOgp1x.js +0 -1
  206. package/dist/assets/vendor-codemirror-lang-html-B3Qe3OpS.js +0 -1
  207. package/dist/assets/vendor-codemirror-lang-javascript-Bbw3D7r0.js +0 -13
  208. package/dist/assets/vendor-codemirror-lang-markdown-FGQydhTc.js +0 -1
  209. package/dist/assets/vendor-codemirror-language-DUOssd4j.js +0 -3
  210. package/dist/assets/vendor-codemirror-search-8kyQdB3f.js +0 -2
  211. package/dist/assets/vendor-codemirror-view-DSzLbZiS.js +0 -4
  212. package/dist/assets/vendor-replit-codemirror-vim-B0Ecqnlh.js +0 -39
  213. package/dist/assets/zh-CN-dlOQK6v9.js +0 -15
  214. package/dist/assets/zh-TW-BnqQ-WL5.js +0 -15
  215. package/server/lib/quota/providers/claude.js +0 -107
@@ -0,0 +1,921 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/WalkthroughView-Bxun3k66.js","assets/vendor-react-BUCujlKS.js","assets/vendor-scheduler-7OC5HNn7.js","assets/useAppFontEffects-CbzHzFop.js","assets/index-DzriVon2.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-opencode-sdk-BJ73u-bH.js","assets/vendor-zustand-BAGL70zf.js","assets/index-1OhiMDBz.css","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-base-ui-BYlZTzrw.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-dom-WyXykhNi.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-floating-ui-react-dom-DKpLs02S.js","assets/vendor-use-sync-external-store-D6wYuSt-.js","assets/contextPanelEmbeddedChat-BO1wRpaN.js","assets/vendor-class-variance-authority-5VPnzWs2.js","assets/vendor-clsx-B-dksMZM.js","assets/vendor-dnd-kit-core-BZknOX2w.js","assets/vendor-dnd-kit-utilities-B_MdXhJC.js","assets/vendor-dnd-kit-accessibility-BHxJPORy.js","assets/vendor-dnd-kit-sortable-CsEagZ81.js","assets/vendor-cmdk-DgLInKvT.js","assets/vendor-radix-ui-react-dialog-B94Bt2qq.js","assets/vendor-radix-ui-primitive-Dc_FVRD7.js","assets/vendor-radix-ui-react-compose-refs-DcAh5WdT.js","assets/vendor-radix-ui-react-context-Czxm7Z62.js","assets/vendor-radix-ui-react-id-f5BLKEVw.js","assets/vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js","assets/vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js","assets/vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js","assets/vendor-radix-ui-react-primitive-DhVoX9SD.js","assets/vendor-radix-ui-react-slot-BQgQOasS.js","assets/vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js","assets/vendor-radix-ui-react-use-escape-keydown-oph88g-F.js","assets/vendor-radix-ui-react-focus-scope-CiaxW4dD.js","assets/vendor-radix-ui-react-portal-BMJYHWck.js","assets/vendor-radix-ui-react-presence-CNxf-uq4.js","assets/vendor-radix-ui-react-focus-guards-B6qJXYua.js","assets/vendor-react-remove-scroll-DO7dCTnK.js","assets/vendor-tslib-De9GV7Vy.js","assets/vendor-react-remove-scroll-bar-BcFYyj3E.js","assets/vendor-react-style-singleton-q6EMHnwf.js","assets/vendor-get-nonce-C-Z93AgS.js","assets/vendor-use-sidecar-zDC0RhA3.js","assets/vendor-use-callback-ref-D3RC8gqK.js","assets/vendor-aria-hidden-DvXkyWUv.js","assets/vendor-codemirror-language-BgPj_McA.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-C9awkmn-.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-CiLROUVV.js","assets/vendor-style-mod-NZ5MEPvj.js","assets/vendor-w3c-keyname-Vcq4gwWv.js","assets/vendor-crelt-C8TCjufn.js","assets/vendor-lezer-highlight-CDMHUZ74.js","assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-DzPz9Wgq.js","assets/vendor-codemirror-lang-json-CMBS2tG9.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-O0cZX78y.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-CfgK872x.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-BPGOH9ye.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-CiAYDJXN.js","assets/vendor-codemirror-lang-python-HahnQaAS.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-B7H_j0iU.js","assets/vendor-tanstack-react-virtual-g05Cx3z9.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-framer-motion-CRSgBxjL.js","assets/vendor-motion-dom-DJLgZh4Q.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-sonner-DFyL3AvE.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/vendor-zod-adaMkgkm.js","assets/PierreDiffViewer-D_Gt4A_6.js","assets/web-components-DCLjCO9n.js","assets/computeVirtualFileMetrics-DYFv_yZS.js","assets/vendor-shiki-Bbf2GEcE.js","assets/vendor-shikijs-core-CGM_jqPK.js","assets/vendor-shikijs-types-CPSbSeK6.js","assets/vendor-shikijs-vscode-textmate-BgLrS_2D.js","assets/vendor-hast-util-to-html-BKBhbTDb.js","assets/vendor-html-void-elements-CkdplsNl.js","assets/vendor-property-information-rJCbAzvX.js","assets/vendor-zwitch-C2o2j-tx.js","assets/vendor-stringify-entities-CsH1VEn9.js","assets/vendor-character-entities-legacy-BpoLgcEt.js","assets/vendor-character-entities-html4-D7taRCQ7.js","assets/vendor-ccount-c2V3InAJ.js","assets/vendor-comma-separated-tokens-D8TqSuIK.js","assets/vendor-space-separated-tokens-DD3iYX1K.js","assets/vendor-hast-util-whitespace-D4Wp6AEg.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.js","assets/themeResolver-BmJyTmjJ.js","assets/vendor-pierre-theming-C6Z4M5_u.js","assets/vendor-shikijs-engine-javascript-Cme4830A.js","assets/vendor-oniguruma-to-es-DLBnFDCE.js","assets/vendor-oniguruma-parser-C0D4_9rT.js","assets/vendor-regex-BBWcyTkg.js","assets/vendor-regex-utilities-2BQyy0xI.js","assets/vendor-regex-recursion-JU4mF-dD.js","assets/vendor-shikijs-transformers-CZWsLLKm.js","assets/VirtualizedFileDiff-B37yB9jZ.js","assets/isDiffPlainText-DwHKxDYc.js","assets/vendor-diff-C3JhlQdm.js","assets/useInlineCommentController-CegKdDXi.js","assets/runtimeEndpointReset-BMBRhIbf.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/patchFileDiff-BEDPDypx.js","assets/SessionSwitcherDropdown-xKU4LRuQ.js","assets/scheduledTasksApi-01zzfzqH.js","assets/vendor-cron-parser-CUcP7OfX.js","assets/vendor-luxon-BZ0puJYg.js","assets/DiffView-BWNq-0ov.js","assets/FilesView-DB-Q0Gkz.js","assets/shikiHighlight-DXYW46vW.js","assets/vendor-codemirror-search-BmS-GmcX.js","assets/vendor-replit-codemirror-vim-B2DJlAhT.js","assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js","assets/JsonTreeView-h4dHASlq.js","assets/Virtualizer-X_7XPoTH.js","assets/isFilePlainText-Dwq6ILxo.js","assets/DiagramEditor-B9NCadU7.js","assets/vendor-react-drawio-Ct3Q0DsD.js","assets/CodeMirrorCommentWidgets-DAvopJvy.js","assets/GitView-DsWXqWx3.js","assets/CommitSection-D9cV-qR9.js","assets/PlanView-UvuxIl9-.js","assets/DiagramView-LKGBwf4G.js","assets/SettingsView-3B9VN6Ys.js","assets/vendor-yaml-3778uTud.js","assets/vendor-qrcode-DTJ12-WC.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/SettingsWindow-CqQNDKNd.js","assets/OnboardingScreen-CDjgzxEe.js"])))=>i.map(i=>d[i]);
2
+ import{f as it,j as s,R as l,r as nt,h as Rm}from"./vendor-react-BUCujlKS.js";import{y as Wn,z as Mi,O as Gl,D as Mm,A as Om,B as su,r as gs,o as Oi,u as pe,C as Fm,E as nr,F as Lm,G as jt,H as In,I as Fi,J as nu,K as ru,t as Li,L as ou,M as mr,N as Co,e as hr,P as Bm,a as Ps,Q as _m,R as $m,S as zm,T as iu,n as Bn,v as sn,U as Um,V as au,W as Wm,X as lu,Y as Vm,Z as Vr,m as ls,_ as il,$ as Ea,a0 as Hm,a1 as Km,d as Hr,a2 as oi,a3 as ii,a4 as Gm,a5 as ql,a6 as qm,a7 as Ym,a8 as Qm,a9 as Xm,aa as Yl,ab as Ql,ac as Xl,ad as Jl,ae as Jm,q as Zl,af as Zm,ag as eh,ah as th,w as sh,x as nh}from"./index-DzriVon2.js";import{_ as on}from"./vendor-vite-runtime-DD1OZmLC.js";import{I as T,f as gt,h as ge,aQ as Xt,g as er,t as Ae,aR as wn,aS as vn,aT as Sn,aU as jn,L as _r,V as rr,aV as xr,o as Bi,aW as ec,aX as ft,aY as mt,aZ as ht,a_ as cu,a$ as al,b0 as rh,y as ot,b1 as oh,b2 as ih,b3 as du,b4 as ah,b5 as ai,b6 as lh,b7 as ch,K as uu,b8 as dh,b9 as Ta,l as Kt,ba as uh,A as fu,u as Fs,b as Gt,n as Ns,aj as Br,bb as mu,bc as fh,bd as mh,be as hh,bf as ph,p as gh,bg as hu,bh as xh,bi as bh,bj as yh,bk as pu,bl as vh,bm as wh,bn as ll,bo as _i,bp as Ia,ak as cl,bq as $i,br as Or,ae as gu,bs as Ls,bt as Bs,bu as kn,bv as nn,bw as rn,bx as sr,B as lt,by as xu,bz as ca,P as bi,i as Ra,j as Sh,bA as bu,bB as jh,bC as yu,ac as ds,G as kh,bD as Ch,bE as Nh,bF as tn,bG as zi,bH as vu,bI as Ma,bJ as Ah,bK as Ks,bL as Gs,bM as Es,bN as qs,bO as is,S as tr,bP as Kr,bQ as tc,bR as qr,M as Ui,a0 as Io,a1 as dl,bS as wu,a4 as pr,bT as Wi,bU as $n,Z as ul,bV as Dh,bW as Ph,ab as Eh,bX as Th,bY as Ih,bZ as Rh,ad as fl,b_ as ml,b$ as vo,c0 as Su,c1 as Mh,c2 as Oh,c3 as Ro,c4 as Fh,O as ju,c5 as Lh,c6 as an,c7 as Bh,c8 as _h,c9 as da,ca as ku,cb as $h,cc as zh,cd as Uh,ce as sc,cf as bo,c as No,d as Vi,Y as Cu,cg as Nu,ch as fo,ci as yo,cj as Wh,r as Qs,ck as Vh,W as hl,cl as Hh,cm as Kh,cn as Gh,co as qh,cp as Au,cq as Un,cr as Yh,cs as Qh,ct as nc,cu as Du,cv as Xh,cw as Pu,e as so,cx as yi,cy as Jh,cz as rc,cA as gr,cB as Oa,cC as Zh,cD as ep,cE as oc,cF as Vs,cG as Eu,cH as Tu,cI as tp,cJ as li,cK as sp,Q as pl,N as gl,R as xl,cL as bl,cM as Fa,cN as Iu,cO as np,cP as Ru,cQ as rp,H as op,cR as ic,cS as ip,cT as ac,cU as ap,cV as lp,cW as Mu,cX as cp,D as dp,cY as up,cZ as fp,c_ as mp,c$ as lc,d0 as hp,d1 as pp,C as gp,d2 as Ou,E as xp,d3 as cc,d4 as bp,d5 as yp,d6 as vp,d7 as wp,d8 as Sp,d9 as jp,da as Hi,a as Ki,db as kp,dc as ua,F as vi,dd as Cp,de as Np,df as dc,aw as La,dg as Fu,_ as Ap,$ as Dp,az as Pp,dh as Ep,J as Tp,di as Ip,dj as Rp,dk as Mp,dl as Lu,dm as Bu,dn as _u,dp as Op,dq as Fp,dr as Lp,ds as Bp,dt as _p,du as $p,dv as zp,dw as Up,dx as Wp,dy as wi,a2 as Vp,a3 as Hp,dz as Kp,dA as uc,dB as Gp,dC as qp,dD as Yp,dE as Qp,dF as fc,dG as Xp,dH as Jp,dI as Zp,dJ as eg,dK as tg,dL as sg,dM as ng,dN as rg,dO as og,dP as ci,dQ as $u,dR as ig,dS as ag,af as lg,dT as cg,dU as dg,dV as ug,dW as fg,dX as mc,dY as mg,aq as hg,ar as pg,as as gg,au as hc,av as pc,ax as zu,ay as Uu,dZ as xg,aL as bg,aM as yg,aN as vg,aO as wg,aP as Sg,aH as jg,aI as kg,aJ as Cg,aK as Ng}from"./useAppFontEffects-CbzHzFop.js";import{h as gc,i as es,n as Ag,j as xc,t as Qn,k as Dg,l as fa,m as Pg,o as Eg,U as Wu,b as yl,M as Tg,p as bc,q as Si,s as vl,v as ji,w as Vu,x as Ig,y as Hu,z as Ku,A as Gu,P as qu,T as Yu,B as Rg,E as Mg,F as Og,S as yc,u as wo,N as Fg,D as Lg,W as Bg,L as vc,G as _g,d as $g,g as zg,f as Ba,H as Ug,I as Wg,c as Vg,e as Hg,O as Qu,C as Kg}from"./runtimeEndpointReset-BMBRhIbf.js";import{u as Xu,S as Gg,C as qg,W as Ju,f as Yg}from"./SessionSwitcherDropdown-xKU4LRuQ.js";import{u as Er,n as Qg,f as Xg,a as wc,s as Jg,d as Zg,b as ex,r as tx}from"./scheduledTasksApi-01zzfzqH.js";import{c as br,u as Jn,d as Zu,p as ef}from"./vendor-zustand-BAGL70zf.js";import{g as sx,b as nx,E as tf,c as rx,d as ox,e as ix,f as ax,i as lx}from"./contextPanelEmbeddedChat-BO1wRpaN.js";import{f as ki,h as Yr,T as cx,M as dx,D as Ci,j as Ni,P as _a,b as ux,d as fx,k as $a,i as mx}from"./vendor-dnd-kit-core-BZknOX2w.js";import{a as sf,S as za,v as Ua,u as wl,s as hx}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as Sl}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";import{u as px}from"./vendor-tanstack-react-virtual-g05Cx3z9.js";import{M as Sc,a as jc,b as kc,C as gx,c as xx,d as bx,S as yx,e as vx,f as wx}from"./vendor-base-ui-BYlZTzrw.js";import{d as nf}from"./vendor-cron-parser-CUcP7OfX.js";import{u as Cc,a as Nc,m as Ac}from"./vendor-framer-motion-CRSgBxjL.js";function rf(t){const e=it.c(5),{className:n}=t,o=`relative inline-block overflow-hidden rounded-[2px] ${n===void 0?"h-5 w-5":n}`;let i,c,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=s.jsx("span",{className:"absolute left-[20%] top-[20%] h-[60%] w-[25%] bg-[var(--status-error)]/25"}),c=s.jsx("span",{className:"absolute right-[20%] top-[20%] h-[60%] w-[25%] bg-[var(--status-success)]/25"}),a=s.jsx(T,{name:"layout-column",className:"absolute inset-0 h-full w-full"}),e[0]=i,e[1]=c,e[2]=a):(i=e[0],c=e[1],a=e[2]);let d;return e[3]!==o?(d=s.jsxs("span",{"aria-hidden":"true",className:o,children:[i,c,a]}),e[3]=o,e[4]=d):d=e[4],d}function Dc(t){const e=it.c(14);let n,r,o,i;e[0]!==t?({size:o,className:n,style:i,...r}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=i):(n=e[1],r=e[2],o=e[3],i=e[4]);const c=typeof o=="number"?`${o}px`:o,a=typeof o=="number"?`${o}px`:o;let d;e[5]!==i||e[6]!==c||e[7]!==a?(d={width:c,height:a,...i},e[5]=i,e[6]=c,e[7]=a,e[8]=d):d=e[8];let u;e[9]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx("path",{d:"M112,148a12,12,0,0,0-12,12v19L69.17,148.2A4,4,0,0,1,68,145.37V97.94a36,36,0,1,0-24,0v47.43a27.81,27.81,0,0,0,8.2,19.8L83,196H64a12,12,0,0,0,0,24h48a12,12,0,0,0,12-12V160A12,12,0,0,0,112,148ZM56,52A12,12,0,1,1,44,64,12,12,0,0,1,56,52ZM212,158.06V110.63a27.81,27.81,0,0,0-8.2-19.8L173,60h19a12,12,0,0,0,0-24H144a12,12,0,0,0-12,12V96a12,12,0,0,0,24,0V77l30.83,30.83a4,4,0,0,1,1.17,2.83v47.43a36,36,0,1,0,24,0ZM200,204a12,12,0,1,1,12-12A12,12,0,0,1,200,204Z"}),e[9]=u):u=e[9];let m;return e[10]!==n||e[11]!==r||e[12]!==d?(m=s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 256 256",fill:"currentColor",className:n,style:d,...r,children:u}),e[10]=n,e[11]=r,e[12]=d,e[13]=m):m=e[13],m}const Sx="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAXaSURBVFgJ7VddbBRVFP5mdme6dOnu2tZawOAPjfxU+bGQYCRAsvw8qNGEQPTRJ0I0amL0wfjgA/HBR8KLD8YgDxJEUkVFxSYYTSRii6DQQCMGIQqlW7p0u+zMzo/fuTuzO9Nt0Td94CRn7pl7z5zznZ977y5wh/7jDGiz+T979qD5Ujbfd90xlll+stOF1uI40B1+4HhkjnZk9CgLQ9iXp2/BdcbgVc/h0sAgduywudJEMwLY9Of4ugtW5p3CpL7W1jTN88VmjdQYvnDKF1mczkYuNZLeCVg3X8fa9u+nqzUB2HRpdN2pSseRQknPoUL1Jo2ICTrPGcCzdwPdHENcAnicKRqcAk7cpL5J1r0JlAtPYV1XDETM/FtH3m19r+f5by+XjNX/xnmCX3/cCzydi4CKiC7lw+PArhGgoPPFq/6E0+9vwM6d5VBNpuv03cLNfeNTRh9KnJIiV2/PvSngycC5RD+dE5zb3g7s6QESzAZc2l6wuY9SnWIAxv10r81uU85Vt1FvtpEtlc/SMFUkUofeZ2IBta0DWDmXgkfbyTRz1qAYAMczOz3p1elOxYPyEllj421hdELViPO6Kudk3ia3UGe5ABDbvtnJZ52SdYmCZ3stdeexBabFdeAbYopEowtagVUZqFapBrtAGqpiVaFrGgyjZlrmTD5yEqoEJj4iFMuA62i6L3WPZkAiuHgarZ/vbWSBkTzO2rfTR4XOJVJhjfX44MBn+OTocVWbcF5MalxXPeVL6zYonoGo44YOtDI7qHC1lkL5nHnOc+tJRi3K6iygLNGMjt1A1XVV6iUzOvVtAvMlS2I/yBYlRf8MgA6szmXQ1jDfKhSgjft6DRtrkgarAiAw5nI9v2WDSn+Zxfd9DawGxIlPPQUg0A2HGABfEIYlCDU4+q0d8O+jRzHCCFYy+nu4BaeYAoksBCDrPYsXQQ6iitgiSQaS1FHHtMzFil4DpxTl4UhORSn4WOaaiGsbu4iFRkMnYQlEV0oSJQGQ4FyYgSRDjpqPZcCR6EOOWonIEsBqArAIQOMLzw0VXRRERF2VoA6Atk1+MzsASekMJYgaFEeHR4Cr85lNGntYzgKCYd/NSNIDCXr0ZJ2jwTsjSvEMzFQCCVmKHBRahn2DNb4rDRx8pnbXOOIg0JELLMHOF1AUkaRj1V8c2TookkMS83WK9QCVpRwtf5wCykQWRKDyJ44Ytc452QUV6inmN9IDIv/6y2+YLDuqTywBEHxv8rsoxQC4Fpf4cZ2pbJ4/huxXr0EvFmoRCrAIVymLQ3Eid0GJYPsPfISBLwdwi79YQnCqBNS7LQDP5qYSAKEDypOrX4WVWYLsFy+i9cwh6CUmUKIJI2Gq5cSbnLLw849D2Ld3L4olC1u3P0c1ow5Ozgixa3puWChONG1D3eLZUQOglvng+Vp5dBfseesx5/yHyI4cBTL3wsssRGs2g6/ppHijiMLoNSSMNHofy6Nn6SPsAR02nUoTtrDTSrdoi8CTni55rlOsCf1ypaDxlFMNU1epCV5XL6Y6dmOq+BeS48NIlq7Anpjg5dOFbPdDWLQyj/aubnUKSkMKi3NhkUd4kieYtbRbYS0bFAOQKI8NO363z1RJHmamtnlwhGksxV2w/gl29WRtm8kWtWUnRShLnQvXgDOXmLg2HzlvbDiyHD8Y517YP2i4FtueFPbB9FFqKcyobk4A5y7zquUFa7IXojyHoeXmAFcY755vaI6A56Xsofm/7+cmblBTpOldQ5vs3PJDVS+RVSAaus2SpJTO80t4NTNSOQfCDrtFkBevA0ME6HGvPdDpFlekzm7rf3nFQNRQEwBZTL9warObWfx21Uv1+fx1ERqVNampGoOHpF1tsdp07RnoGMxK1vT97rbK4IP6+Tc+fWXVsahaYGL6VO09d//GXHXr7jVeqmuppqU6ff4x0RO6lqRxgxHJpWKSlcw5eWfjq5rq/CdhaL5l6JWxjDc6bP7w5sn+/uMs2B36H2bgb6v9raK0+o9IAAAAAElFTkSuQmCC",jx="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAeGVYSWZNTQAqAAAACAAEARoABQAAAAEAAAA+ARsABQAAAAEAAABGASgAAwAAAAEAAgAAh2kABAAAAAEAAABOAAAAAAAAAJAAAAABAAAAkAAAAAEAA6ABAAMAAAABAAEAAKACAAQAAAABAAAAIKADAAQAAAABAAAAIAAAAAB+C9pSAAAACXBIWXMAABYlAAAWJQFJUiTwAAABnWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iWE1QIENvcmUgNi4wLjAiPgogICA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPgogICAgICA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIgogICAgICAgICAgICB4bWxuczpleGlmPSJodHRwOi8vbnMuYWRvYmUuY29tL2V4aWYvMS4wLyI+CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yNTY8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpQaXhlbFlEaW1lbnNpb24+MjU2PC9leGlmOlBpeGVsWURpbWVuc2lvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24+CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE+Cl6wHhsAAAQzSURBVFgJ7VZNbBNHFH67Xv9RxwnBDqlUoQglcZK6qSIEJIQWAYJQoVY9IE5RTzn20FMvqdpDesq9B24+NdwthAJCkZChJg1JSOXYQIwQKQIaBdtENbs73t2+N8miGWOcpFHUHniyd97OvJ9v3nv7ZgDe038cAeVd/jOZjC94sKdfU+Bj24G9igpexwYPyiu2bauKqqqirkOTqmrjnIOyFsoyUKDocSCj/7mU7ujoMER5l68JYOFZ4YSiwPjd9O0jjx7ch1KhAJZVAcdx0LxDv3XetYKjggr4I4bzHo8G4aYmONjZBYf6+2dUzfd9PNowJajUZmef/PX5zcWl0rmvvnbQHrra+f/M+S+dqYXs2t3Hz09Ve5UicCmZ3NPb1Zv66btv+65dSULA64WGxkbw+Xx8V9XK9d4pWowxeFUqgW6acHroC/j5l0sLD/PZY98MDf3t6mouQ+On3X1H7/2e7rtOztHpgbY2+CAUgperq+D3+7cNgtLSEA7D0+VluDF5FS7cSff2HT56DF1dd/3KhQTWJ/lclsc8jIrk9IfRURgZGQEvRqNSWa8D2t1W/liXXK8Ro0i0lF0ExaPEXec0SgAqhrm3VCzwdS9GQNd1GBsbg0AgAIlEAlpbW7EYLVF/U56AagieiGwbuhERlSQApmEE8c/XKXxU0fF4HNowFfPz81Aul7edBjLGbeHITANsZga4g42HVAM2Y74KM/kSIQ/izgcHB2FiYgJmZmZ4MZpYULRG5PF4+Bx/2cLDxuhhYUqFLwGoWCaQEBGhNjAa4+Pj/J3SQA6pHpqbm/kcNitIJpOgaZIZvlbrQbZNJvcjSZOZDKhwRKLic4l2Pjc3B8FgkE+trKxAVUN0RWuOZNtCHyJJACj/bgREIZcnA9PT029SQM63unuywSOwUWOuTQmAhfmnlluPxIjUk6u1RrbJh0jyV0Ap2OZnJhrbjOcRqEqBBMDCAtltAORDJAkAVj2mWS5CUXinPDUx+oxFkgBYjO0qANu2wKoqQgkAfgW7C4AiYMmfoQSgwpjj7GYRUh/Q66SAmdisNxql227FfP1bXrRlVExdtCNHwDRLdPkgwmi8OUREhe3y1NLJFpEfbWMNvBRtSI2o+KqYi+zbx4NQwptMCO8E1HjEHYjKm/HknG5FZIsCG4lEoLS2lhP1JAB3bt1KH//s+GJPd3dPJpvlN5kwXiYIhHukisr1eAItXsm6YzGItrTcn5+dvS3qSQBSqVQhFouNnj039CsaCC7mcqDjgbNT6op1AtrU8Wo3Ojk5KaVAOptdR8PDwxf3t7SMvXjxvJNOPP31a35Krt8CXKl3j2SUDip/IAjRaBRaP9z/cHW18GMikbhcrVUTAAm1t7d/NDAwcDIUCvVqmtqkyLe3ajtvvTtg4x3SLpbLa3+kUr9N5fP55beE3k/8HyLwDx2/HIx7q3WfAAAAAElFTkSuQmCC",ma=t=>({...t,fallbackIconDataUrl:t.id==="finder"&&window.__OPENCHAMBER_PLATFORM__==="darwin"?Sx:t.id==="terminal"?jx:void 0}),Pc=t=>{const e=it.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:o}=t,[i,c]=l.useState(!1);let a;e[0]!==n?(a=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=a):a=e[1];const d=a,u=r||o;if(u&&!i){let g;e[2]===Symbol.for("react.memo_cache_sentinel")?(g=()=>c(!0),e[2]=g):g=e[2];let x;return e[3]!==u?(x=s.jsx("img",{src:u,alt:"",className:"h-4 w-4 rounded-sm",onError:g}),e[3]=u,e[4]=x):x=e[4],x}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=ge("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=m):m=e[5];let f;return e[6]!==d?(f=s.jsx("span",{className:m,children:d}),e[6]=d,e[7]=f):f=e[7],f},kx=t=>{const e=it.c(75),{directory:n,className:r}=t,{t:o}=gt(),i=Er(Cx),c=Er(Nx),a=Er(Ax),d=Er(Dx),u=Er(Px),m=Er(Ex),f=Er(Tx);let g,x;e[0]!==u?(g=()=>{u()},x=[u],e[0]=u,e[1]=g,e[2]=x):(g=e[1],x=e[2]),l.useEffect(g,x);const j=Wn()&&Mi();let w;e:{let H;e[3]!==c||e[4]!==i?(H=c.find(q=>q.id===i)??c.find(Ix)??c[0]??Gl[0],e[3]=c,e[4]=i,e[5]=H):H=e[5];const we=H;if(we){let q;e[6]!==we?(q=ma(we),e[6]=we,e[7]=q):q=e[7],w=q;break e}let de;e[8]===Symbol.for("react.memo_cache_sentinel")?(de=ma(Gl[0]),e[8]=de):de=e[8],w=de}const p=w;if(!j||!n||c.length===0)return null;let h;e[9]!==n?(h=async H=>{await Om(n,H.id,H.appName)||await su(n,H.appName)},e[9]=n,e[10]=h):h=e[10];const b=h;let v;e[11]!==b||e[12]!==f?(v=async H=>{await f(H.id),await b(H)},e[11]=b,e[12]=f,e[13]=v):v=e[13];const S=v;let N;e[14]!==n||e[15]!==o?(N=async()=>{(await er(n)).ok&&Ae.success(o("openInApp.toast.pathCopied"))},e[14]=n,e[15]=o,e[16]=N):N=e[16];const A=N;let k;e[17]!==r?(k=ge("app-region-no-drag inline-flex h-7 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r),e[17]=r,e[18]=k):k=e[18];let C;e[19]!==b||e[20]!==p?(C=()=>{b(p)},e[19]=b,e[20]=p,e[21]=C):C=e[21];const P=d&&"animate-pulse";let D;e[22]!==P?(D=ge("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",P),e[22]=P,e[23]=D):D=e[23];let O;e[24]!==p.label||e[25]!==o?(O=o("openInApp.actions.openInAria",{app:p.label}),e[24]=p.label,e[25]=o,e[26]=O):O=e[26];let F;e[27]!==p.fallbackIconDataUrl||e[28]!==p.iconDataUrl||e[29]!==p.label?(F=s.jsx(Pc,{label:p.label,iconDataUrl:p.iconDataUrl,fallbackIconDataUrl:p.fallbackIconDataUrl}),e[27]=p.fallbackIconDataUrl,e[28]=p.iconDataUrl,e[29]=p.label,e[30]=F):F=e[30];let E;e[31]!==D||e[32]!==O||e[33]!==F||e[34]!==C?(E=s.jsx("button",{type:"button",onClick:C,className:D,"aria-label":O,children:F}),e[31]=D,e[32]=O,e[33]=F,e[34]=C,e[35]=E):E=e[35];let B;e[36]===Symbol.for("react.memo_cache_sentinel")?(B=ge("inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors"),e[36]=B):B=e[36];let $;e[37]!==o?($=o("openInApp.actions.chooseAppAria"),e[37]=o,e[38]=$):$=e[38];let z;e[39]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(T,{name:"arrow-down-s",className:"h-4 w-4"}),e[39]=z):z=e[39];let V;e[40]!==$?(V=s.jsx(wn,{asChild:!0,children:s.jsx("button",{type:"button",className:B,"aria-label":$,children:z})}),e[40]=$,e[41]=V):V=e[41];let y;e[42]!==A?(y=()=>{A()},e[42]=A,e[43]=y):y=e[43];let I;e[44]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx(T,{name:"file-copy",className:"h-4 w-4"}),e[44]=I):I=e[44];let _;e[45]!==o?(_=o("openInApp.actions.copyPath"),e[45]=o,e[46]=_):_=e[46];let W;e[47]!==_?(W=s.jsx("span",{className:"typography-ui-label text-foreground",children:_}),e[47]=_,e[48]=W):W=e[48];let K;e[49]!==y||e[50]!==W?(K=s.jsxs(Xt,{className:"flex items-center gap-2",onClick:y,children:[I,W]}),e[49]=y,e[50]=W,e[51]=K):K=e[51];let Z;e[52]===Symbol.for("react.memo_cache_sentinel")?(Z=s.jsx(vn,{}),e[52]=Z):Z=e[52];let Q;if(e[53]!==c||e[54]!==S||e[55]!==p.id){let H;e[57]!==S||e[58]!==p.id?(H=we=>{const de=ma(we);return s.jsxs(Xt,{className:"flex items-center gap-2",onClick:()=>{S(we)},children:[s.jsx(Pc,{label:we.label,iconDataUrl:we.iconDataUrl,fallbackIconDataUrl:de.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:we.label}),p.id===we.id?s.jsx(T,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},we.id)},e[57]=S,e[58]=p.id,e[59]=H):H=e[59],Q=c.map(H),e[53]=c,e[54]=S,e[55]=p.id,e[56]=Q}else Q=e[56];let le;e[60]!==a||e[61]!==m||e[62]!==o?(le=a?s.jsxs(Xt,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(T,{name:"refresh",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:o("openInApp.actions.refreshApps")})]}):null,e[60]=a,e[61]=m,e[62]=o,e[63]=le):le=e[63];let te;e[64]!==K||e[65]!==Q||e[66]!==le?(te=s.jsxs(Sn,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[K,Z,Q,le]}),e[64]=K,e[65]=Q,e[66]=le,e[67]=te):te=e[67];let he;e[68]!==V||e[69]!==te?(he=s.jsxs(jn,{children:[V,te]}),e[68]=V,e[69]=te,e[70]=he):he=e[70];let xe;return e[71]!==E||e[72]!==he||e[73]!==k?(xe=s.jsxs("div",{className:k,children:[E,he]}),e[71]=E,e[72]=he,e[73]=k,e[74]=xe):xe=e[74],xe};function Cx(t){return t.selectedAppId}function Nx(t){return t.availableApps}function Ax(t){return t.isCacheStale}function Dx(t){return t.isScanning}function Px(t){return t.initialize}function Ex(t){return t.loadInstalledApps}function Tx(t){return t.selectApp}function Ix(t){return t.id===Mm}const Ai=new Map,Wa=new Set,of=()=>{for(const t of Wa)t()},ha=(t,e)=>{const n=t.trim();n&&(e.length===0?Ai.delete(n):Ai.set(n,[...e]),of())},Rx=t=>{Ai.delete(t.trim())&&of()},af=[],Mx=t=>Ai.get(t.trim())??af,Ox=t=>(Wa.add(t),()=>{Wa.delete(t)}),Fx=t=>{const e=it.c(2);let n;return e[0]!==t?(n=()=>Mx(t),e[0]=t,e[1]=n):n=e[1],l.useSyncExternalStore(Ox,n,Lx)};function Lx(){return af}const Bx=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],_x=["dev","start","preview","serve"];async function $x(t,e,n){if(!t)return null;const r=Wx(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id,previewUrlHint:r.openUrl};if(n){const o=Vx(n);if(o){const i=await Hx(t);return{command:`${i==="npm"?"npm run":i==="yarn"?"yarn":i==="pnpm"?"pnpm":i==="bun"?"bun run --shell=bun":"npm run"} ${o}`,label:`Start (${o})`}}}if(await zx(t)){const o=await Ux(),i=typeof o=="number"&&Number.isFinite(o)&&o>0?o:8e3;return{command:`python3 -m http.server ${i}`,label:"Static preview",previewUrlHint:`http://127.0.0.1:${i}/`}}return null}async function zx(t){const e=`${t}/index.html`,n=await Di(e,t);return typeof n=="string"&&n.trim().length>0}async function Ux(){try{const t=await gs("/api/system/free-port",{cache:"no-store"});if(!t.ok)return null;const e=await t.json().catch(()=>null),n=typeof e?.port=="number"?e.port:null;return n&&Number.isFinite(n)?n:null}catch{return null}}function Wx(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(_x.some(o=>n.includes(o)))return e}return null}function Vx(t){for(const{pattern:e}of Bx)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function Hx(t){const e=await Di(`${t}/package.json`,t);if(e)try{const r=JSON.parse(e),o=typeof r.packageManager=="string"?r.packageManager.toLowerCase():"";if(o.startsWith("bun@"))return"bun";if(o.startsWith("pnpm@"))return"pnpm";if(o.startsWith("yarn@"))return"yarn";if(o.startsWith("npm@"))return"npm"}catch{}const n=[["bun.lock","bun"],["bun.lockb","bun"],["pnpm-lock.yaml","pnpm"],["yarn.lock","yarn"],["package-lock.json","npm"]];for(const[r,o]of n){const i=await Di(`${t}/${r}`,t);if(typeof i=="string"&&i.trim().length>0)return o}return"npm"}async function Di(t,e){if(e?.trim())try{const r=new URLSearchParams({path:t,directory:e,optional:"true"}),o=await gs(`/api/fs/read?${r.toString()}`,{cache:"no-store"});if(o.ok)return o.text()}catch{}const n=Oi()?.files;if(n?.readFile)try{const r=await n.readFile(t,{optional:!0});return typeof r?.content=="string"?r.content:null}catch{return null}try{const r=await gs(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return r.ok?r.text():null}catch{return null}}async function Kx(t){try{const e=await Di(`${t}/package.json`,t);if(e==null)return null;const r=JSON.parse(e).scripts;return r&&typeof r=="object"&&!Array.isArray(r)?r:null}catch{return null}}const Gx=(t,e,n)=>new Promise(r=>{let o=!1,i=null,c=null;const a=d=>{o||(o=!0,c&&clearTimeout(c),i?.close(),r(d))};i=t.connect(e,{onEvent:d=>{(d.type==="exit"||d.type==="snapshot"&&d.status==="exited")&&a(!0)},onError:(d,u)=>{u&&a(!0)}}),o?i.close():c=setTimeout(()=>a(!1),n)}),Zs="__openchamber_auto_discover_preview__",qx=15e3,Yx=3e3,Qx=t=>{let e="";for(let n=0;n<t.length;n+=1){const r=t.charCodeAt(n);r>=0&&r<=8||r===11||r===12||r>=14&&r<=31||r===127||(e+=t[n])}return e},Xx=t=>{const e=(t||"").trim();if(!e)return null;const n=/^https?:\/\//i.test(e)?e:`http://${e}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?null:r.toString()}catch{return null}},lf=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:o=!1})=>{const{t:i}=gt(),{currentTheme:c}=_r(),{terminal:a,runtime:d}=rr(),{isMobile:u}=xr(),m=l.useMemo(()=>Wn(),[]),f=gc(ie=>ie.instances),g=gc(ie=>ie.load),x=pe(ie=>ie.terminalShell),j=pe(ie=>ie.terminalLoginShells.includes(ie.terminalShell)),w=pe(ie=>ie.setSettingsPage),p=pe(ie=>ie.setSettingsDialogOpen),h=pe(ie=>ie.setSettingsProjectsSelectedId),b=pe(ie=>ie.openContextPreview),v=es(ie=>ie.ensureDirectory),S=es(ie=>ie.setTabLabel),N=es(ie=>ie.setTabIconKey),A=es(ie=>ie.setActiveTab),k=es(ie=>ie.setConnecting),C=es(ie=>ie.setTabSessionId),P=es(ie=>ie.setTabPreviewUrl),D=es(ie=>ie.projectActionRuns),O=es(ie=>ie.setProjectActionRun),F=es(ie=>ie.updateProjectActionRunStatus),E=es(ie=>ie.removeProjectActionRun),[B,$]=l.useState([]),[z,V]=l.useState(null),[y,I]=l.useState(!1),_=l.useRef({}),W=l.useRef({}),K=l.useRef({}),Z=l.useRef({}),Q=l.useRef(new Set),le=l.useRef(0),te=t?.id??null,he=t?.path??"",xe=l.useMemo(()=>te?{id:te,path:he}:null,[te,he]);l.useEffect(()=>{m&&g().catch(()=>{})},[m,g]);const H=l.useCallback(async ie=>{await Bi(ie)},[]),we=l.useCallback(async()=>{if(!xe)return;const ie=le.current+1;le.current=ie,I(!0);try{const Re=await ec(xe);if(le.current!==ie)return;const ue=Re.actions;$(ue),V(R=>R===Zs||R&&ue.some(ae=>ae.id===R)?R:null)}catch{if(le.current!==ie)return}finally{le.current===ie&&I(!1)}},[xe]),de=l.useMemo(()=>Ag(e||xe?.path||""),[e,xe?.path]),q=l.useMemo(()=>z?B.find(ie=>ie.id===z)??null:null,[B,z]),me=l.useMemo(()=>({id:Zs,name:i("projectActions.actions.autoDiscover"),command:"",icon:"scan-2",autoOpenUrl:!0}),[i]),be=!u,Pe=l.useMemo(()=>be?[me,...B]:B,[B,me,be]);l.useEffect(()=>{we()},[we]),l.useEffect(()=>{if(typeof window>"u")return;const ie=Re=>{const ue=Re.detail;te&&(ue?.projectId&&ue.projectId!==te||we())};return window.addEventListener(xc,ie),()=>{window.removeEventListener(xc,ie)}},[we,te]),l.useEffect(()=>{z&&(z===Zs&&be||B.some(ie=>ie.id===z)||V(null))},[B,be,z]),l.useEffect(()=>{const ie=ue=>{delete Z.current[ue];const R=W.current[ue];if(!R||R.openedUrl)return;const ae=es.getState(),Se=ae.projectActionRuns[ue];if(!Se)return;const Ce=R.announced;if(Ce.length!==0){if(R.openedUrl=!0,ae.updateProjectActionRunStatus(ue,"running"),Ce.length===1){ha(Se.directory,[]),P(Se.directory,Se.tabId,Ce[0],{locked:!1,autoOpened:!0}),b(Se.directory,Ce[0]);return}R.offering=!0,ha(Se.directory,Ce),pe.getState().openContextSurface(Se.directory,"browser"),Ae.info(i("projectActions.toast.multipleServers"))}},Re=()=>{const ue=es.getState(),R=ue.sessions,ae=ue.projectActionRuns;for(const[Se,Ce]of Object.entries(ae)){const se=R.get(Ce.directory)?.tabs.find(tt=>tt.id===Ce.tabId);if(!se||se.terminalSessionId!==Ce.sessionId){E(Se);continue}const je=W.current[Se]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1,announced:[],offering:!1};W.current[Se]=je;const Ze=Pe.find(tt=>tt.id===Ce.actionId),X=ue.getBuffer(Ce.directory,Ce.tabId).chunks;if(!Ze||X.length===0)continue;const ye=X.filter(tt=>je.lastSeenChunkId===null||tt.id>je.lastSeenChunkId);if(ye.length===0)continue;const Xe=ye.map(tt=>tt.data).join(""),Be=`${je.tail}${Xe}`;if(je.openInPreview&&(!je.openedUrl||je.offering)){const tt=Pg(Be),ct=je.announced.length;for(const Nt of tt)je.announced.includes(Nt)||je.announced.push(Nt);const Et=je.announced.length-ct;je.offering&&Et>0?ha(Ce.directory,je.announced):!je.openedUrl&&ct===0&&je.announced.length>0&&(window.clearTimeout(Z.current[Se]),Z.current[Se]=window.setTimeout(()=>ie(Se),Yx))}const We=!je.openedUrl&&Ze.autoOpenUrl===!0&&!je.openInPreview?Eg(Be):null,_e=ye[ye.length-1]?.id??je.lastSeenChunkId;if(je.lastSeenChunkId=_e,je.tail=Be.slice(-512),We)if(je.openedUrl=!0,je.openInPreview){const tt=ae[Se];tt&&(P(tt.directory,tt.tabId,We,{locked:!1,autoOpened:!1}),tt.status==="waiting-for-preview"&&F(Se,"running"),window.clearTimeout(Z.current[Se]),delete Z.current[Se],b(tt.directory,We))}else H(We),Ae.success(i("projectActions.toast.openedUrlFromOutput"));W.current[Se]=je}for(const Se of Object.keys(W.current))ae[Se]||(delete W.current[Se],window.clearTimeout(Z.current[Se]),delete Z.current[Se])};return Re(),es.subscribe((ue,R)=>{(ue.sessions!==R.sessions||ue.buffers!==R.buffers)&&Re()})},[Pe,b,H,D,E,P,i,F]);const Ie=l.useCallback(async(ie,Re={})=>{if(!de)throw new Error(i("projectActions.error.noActiveDirectory"));const ue=Qn(de,ie.id);v(de);const R=es.getState(),ae=R.getDirectoryState(de);let Se=_.current[ue]||null;const Ce=Se?!!ae?.tabs.some(je=>je.id===Se):!1;(!Se||!Ce)&&(Se=R.createTab(de),_.current[ue]=Se),S(de,Se,`Action: ${ie.name}`),N(de,Se,ie.icon||"play"),A(de,Se),Re.revealTerminal!==!1&&pe.getState().openContextPanelTab(de,{mode:"terminal"});const se=es.getState().getDirectoryState(de)?.tabs.find(je=>je.id===Se);return{key:ue,tabId:Se,sessionId:se?.terminalSessionId??null}},[v,de,A,N,S,i]),De=l.useCallback(async ie=>{if(d.isVSCode||!o&&u)return;if(!de){Ae.error(i("projectActions.error.noActiveDirectoryForAction"));return}const Re=Qn(de,ie.id),ue=D[Re];if(!(ue&&ue.status==="running")&&!Q.current.has(Re)){Q.current.add(Re);try{const R=ie.id===Zs?await(async()=>{const[We,_e]=await Promise.all([ec({id:xe?.id??"",path:de}),Kx(de)]),tt=await $x(de,We.actions,_e);if(!tt)throw new Error(i("contextPanel.preview.noDevServer"));return{id:Zs,name:i("projectActions.actions.autoDiscover"),command:tt.command,icon:"scan-2",autoOpenUrl:!0,openUrl:tt.previewUrlHint||""}})():ie,ae=R.autoOpenUrl===!0&&(R.openUrl||"").trim().length>0,Se=!ae&&ie.id!==Zs,{key:Ce,tabId:Ee,sessionId:se}=await Ie(R,{revealTerminal:Se});let je=se;if(!je){k(de,Ee,!0);try{je=(await a.createSession({cwd:de,sessionId:Ee,shell:x,loginShell:j,themeMode:c.metadata.variant==="light"?"light":"dark",terminalBackground:c.colors.surface.background,terminalForeground:c.colors.syntax.base.foreground})).sessionId,C(de,Ee,je)}finally{k(de,Ee,!1)}}if(!je)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));K.current[Ce]?.(),k(de,Ee,!0);const Ze=a.connect(je,{onEvent:We=>{We.type==="snapshot"&&(es.getState().replaceBuffer(de,Ee,We.data??"",We.sequence??0),es.getState().setConnecting(de,Ee,!1)),We.type==="data"&&typeof We.data=="string"&&We.data.length>0&&es.getState().appendToBuffer(de,Ee,We.data,We.sequence,We.replayData),We.type==="exit"&&(es.getState().setTabLifecycle(de,Ee,"exited"),es.getState().setConnecting(de,Ee,!1),es.getState().removeProjectActionRun(Ce),delete W.current[Ce],K.current[Ce]?.(),delete K.current[Ce],window.clearTimeout(Z.current[Ce]),delete Z.current[Ce])},onError:(We,_e)=>{es.getState().setConnecting(de,Ee,!1),_e&&(es.getState().setTabLifecycle(de,Ee,"exited"),es.getState().setTabSessionId(de,Ee,null),es.getState().removeProjectActionRun(Ce))}});K.current[Ce]=Ze.close;const X=R.autoOpenUrl===!0&&m&&(R.desktopOpenSshForward||"").trim().length>0,ye=R.autoOpenUrl?Xx(R.openUrl):null,Xe=R.autoOpenUrl&&m?Dg(R.desktopOpenSshForward,f):null;O({key:Ce,directory:de,actionId:R.id,tabId:Ee,sessionId:je,status:R.id===Zs&&!ye?"waiting-for-preview":"running"}),window.clearTimeout(Z.current[Ce]),delete Z.current[Ce],R.id===Zs&&!ye&&(Z.current[Ce]=window.setTimeout(()=>{const We=es.getState(),_e=We.projectActionRuns[Ce];We.updateProjectActionRunStatus(Ce,"running"),_e&&(We.setActiveTab(_e.directory,_e.tabId),pe.getState().openContextPanelTab(_e.directory,{mode:"terminal"})),delete Z.current[Ce]},qx)),W.current[Ce]={lastSeenChunkId:null,openedUrl:!!Xe||!!ye||ae,tail:"",openInPreview:R.id===Zs,announced:[],offering:!1};const Be=Qx(R.command.trim().replace(/\r\n|\r/g,`
3
+ `));await a.sendInput(je,`${Be}\r`),Xe?(P(de,Ee,null,{locked:!0}),H(Xe),Ae.success(i("projectActions.toast.openedForwardedUrl"))):ye?(P(de,Ee,ye,{locked:!0,autoOpened:!0}),b(de,ye),Ae.success(i("projectActions.toast.openedActionUrl"))):ae?(P(de,Ee,null,{locked:!0}),Ae.error(i("projectActions.error.invalidCustomUrlFormat"))):X?(P(de,Ee,null,{locked:!0}),Ae.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):P(de,Ee,null,{locked:!1,autoOpened:!1})}catch(R){E(Re),delete W.current[Re],K.current[Re]?.(),delete K.current[Re],window.clearTimeout(Z.current[Re]),delete Z.current[Re],Ae.error(R instanceof Error?R.message:i("projectActions.error.failedToRunAction"))}finally{Q.current.delete(Re)}}},[c.colors.surface.background,c.colors.syntax.base.foreground,c.metadata.variant,f,Ie,o,u,m,de,j,x,H,b,D,d.isVSCode,E,k,O,P,C,xe?.id,i,a]),Le=l.useCallback(async ie=>{const Re=Qn(de,ie.id),ue=D[Re];if(!ue)return;F(Re,"stopping");const R=Gx(a,ue.sessionId,1e3);try{await a.sendInput(ue.sessionId,"")}catch{}const ae=await R;if(es.getState().getDirectoryState(ue.directory)?.tabs.find(Ee=>Ee.id===ue.tabId)?.terminalSessionId===ue.sessionId&&!ae){if(typeof a.forceKill=="function")try{await a.forceKill({sessionId:ue.sessionId})}catch{}else try{await a.close(ue.sessionId)}catch{}C(ue.directory,ue.tabId,null)}E(Re),delete W.current[Re],K.current[Re]?.(),delete K.current[Re],window.clearTimeout(Z.current[Re]),delete Z.current[Re]},[de,D,E,C,a,F]),Ne=l.useCallback(()=>{const ie=q??Pe[0];if(!ie)return;const Re=Qn(de,ie.id),ue=D[Re];if(ue?.status!=="stopping"){if(ue){Le(ie);return}De(ie)}},[Pe,de,De,D,q,Le]),ve=l.useCallback((ie,Re=!1)=>{if(V(ie.id),!Re){De(ie);return}const ue=Qn(de,ie.id),R=D[ue];if(R?.status!=="stopping"){if(R){Le(ie);return}De(ie)}},[de,De,D,Le]),Me=l.useCallback(()=>{xe?.id&&(h(xe.id),w("projects"),p(!0))},[p,w,h,xe?.id]),ee=q??Pe[0]??null,oe=ee?D[Qn(de,ee.id)]:null,Te=es(ie=>oe?ie.sessions.get(oe.directory)?.tabs.find(Re=>Re.id===oe.tabId)?.previewUrl??null:null);if(d.isVSCode||!o&&u||!xe||!de)return null;const J=q??Pe[0]??null;if(!J)return null;const re=J.icon||"play",Y=J.id===Zs?"scan-2":fa[re]||"play",U=Qn(de,J.id),fe=D[U],ne=fe?.status==="stopping",ce=fe?.status==="waiting-for-preview",Fe=!!(fe&&Te),Ye=()=>{!fe||!Te||b(fe.directory,Te)},$e=J.id===Zs;return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",disabled:y||ne,className:ge("app-region-no-drag inline-flex h-9 w-9 items-center justify-center rounded-[10px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px] p-2","typography-ui-label font-medium text-muted-foreground hover:bg-interactive-hover hover:text-foreground transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","disabled:cursor-not-allowed",n),onClick:Ne,"aria-label":fe?i("projectActions.actions.stopNamedAria",{name:J.name}):i("projectActions.actions.runNamedAria",{name:J.name}),children:ne||ce?s.jsx(T,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):fe?s.jsx(T,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(T,{name:Y,className:"h-5 w-5"})})}),$e?s.jsx(ht,{sideOffset:6,children:i("projectActions.actions.autoDiscoverTooltip")}):null]}),Fe?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-7 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":i("projectActions.actions.openPreview"),onClick:Ye,children:s.jsx(T,{name:"global",className:"h-4 w-4"})})}),s.jsx(ht,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(jn,{children:[s.jsx(wn,{asChild:!0,children:s.jsx("button",{type:"button",className:"app-region-no-drag -ml-1 inline-flex h-9 w-5 items-center justify-center rounded-[10px] text-muted-foreground hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(T,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(Sn,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(Xt,{className:"flex items-center gap-2",onClick:Me,children:[s.jsx(T,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(vn,{}),Pe.map(ie=>{const Re=ie.icon||"play",ue=ie.id===Zs?"scan-2":fa[Re]||"play",R=Qn(de,ie.id),ae=D[R],Se=!!ae,Ce=ae?.status==="stopping";return s.jsxs(Xt,{className:"flex items-center gap-2",onClick:()=>{ve(ie,!0)},children:[s.jsx(T,{name:ue,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ie.name}),Ce||ae?.status==="waiting-for-preview"?s.jsx(T,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):Se?s.jsx(T,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},ie.id)})]})]})]}):s.jsxs("div",{className:ge("app-region-no-drag inline-flex shrink-0 items-center self-center rounded-[9px] [corner-shape:squircle] supports-[corner-shape:squircle]:rounded-[50px]","bg-[var(--surface-elevated)] overflow-hidden","border border-border/60",r?"h-9":"h-7",n),children:[s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ne,disabled:y||ne,className:ge("inline-flex h-full items-center justify-center typography-ui-label font-medium text-foreground hover:bg-interactive-hover",r?"w-9 px-0":"px-2.5","transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed"),"aria-label":fe?i("projectActions.actions.stopNamedAria",{name:J.name}):i("projectActions.actions.runNamedAria",{name:J.name}),children:s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:ne||ce?s.jsx(T,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):fe?s.jsx(T,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(T,{name:Y,className:"h-4 w-4"})})})}),$e?s.jsx(ht,{sideOffset:6,children:i("projectActions.actions.autoDiscoverTooltip")}):null]}),Fe?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ye,className:ge(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-foreground","hover:bg-interactive-hover transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.openPreview"),children:s.jsx(T,{name:"global",className:"h-4 w-4"})})}),s.jsx(ht,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(jn,{children:[s.jsx(wn,{asChild:!0,children:s.jsx("button",{type:"button",className:ge(r?"inline-flex h-full w-8 items-center justify-center":"inline-flex h-full w-7 items-center justify-center","border-l border-[var(--interactive-border)] text-muted-foreground","hover:bg-interactive-hover hover:text-foreground transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),"aria-label":i("projectActions.actions.chooseActionAria"),children:s.jsx(T,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(Sn,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(Xt,{className:"flex items-center gap-2",onClick:Me,children:[s.jsx(T,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(vn,{}),Pe.map(ie=>{const Re=ie.icon||"play",ue=ie.id===Zs?"scan-2":fa[Re]||"play",R=Qn(de,ie.id),ae=D[R],Se=!!ae,Ce=ae?.status==="stopping";return s.jsxs(Xt,{className:"flex items-center gap-2",onClick:()=>{ve(ie,!0)},children:[s.jsx(T,{name:ue,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ie.name}),Ce||ae?.status==="waiting-for-preview"?s.jsx(T,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):Se?s.jsx(T,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},ie.id)})]})]})]})};function Jx(t){if(typeof t!="number"||!Number.isFinite(t))return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";const n=e.toLocaleString(al(),{month:"short"}),r=e.getDate(),o=e.getFullYear(),i=String(e.getHours()).padStart(2,"0"),c=String(e.getMinutes()).padStart(2,"0");return`${n} ${r}, ${o}, ${i}:${c}`}function Zx(t){if(t.info.role==="user")return"";const e=typeof t.info.providerID=="string"?t.info.providerID.trim():"",n=typeof t.info.modelID=="string"?t.info.modelID.trim():"";return e&&n?`${e}/${n}`:n||e}function eb(t){const e=t.info.role==="user"?"User":"Assistant",n=Jx(t.info.time?.created),r=Zx(t),o=n&&r?`${n} (${r})`:n||r;return o?`**${e}**
4
+
5
+ *${o}*`:`**${e}**`}function tb(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function cf(t){const e=eb(t),n=tb(t.parts).trim();return n?`${e}
6
+
7
+ ${n}`:""}function df(t,e){const n="#".repeat(Math.min(e+1,6)),r=t.agent?` — ${t.agent}`:"",o=`${n} Sub-agent: ${t.title}${r}
8
+
9
+ ---
10
+
11
+ `,i=t.records.map(cf).filter(Boolean).join(`
12
+
13
+ ---
14
+
15
+ `),c=[o+i];for(const a of t.children)c.push(df(a,e+1));return c.join(`
16
+
17
+ ---
18
+
19
+ `)}function uf(t,e,n){const r=e?.trim()||"Session",o=new Date().toISOString().split("T")[0],i=`# ${r}
20
+
21
+ *Exported on ${o}*
22
+
23
+ ---
24
+
25
+ `,c=t.map(cf).filter(Boolean).join(`
26
+
27
+ ---
28
+
29
+ `);let a=i+c;if(n&&n.length>0){const d=n.map(u=>df(u,1)).join(`
30
+
31
+ ---
32
+
33
+ `);a+=`
34
+
35
+ ---
36
+
37
+ `+d}return a}function ff(t,e){const n=new Blob([t],{type:"text/markdown;charset=utf-8"}),r=URL.createObjectURL(n),o=document.createElement("a");o.href=r,o.download=e,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(r)}async function mf(t,e){const n=await Fm(e,t);if(n)return n;if(!nr())return null;try{const r=await Oi()?.vscode?.saveMarkdown?.({fileName:e,content:t});if(!r||r.saved!==!0)return null;const o=typeof r.path=="string"?r.path.trim():"";return o.length>0?o:null}catch{return null}}async function sb(t){const e=Oi()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await Lm(t)?!0:su(t)}function nb(){return cu()}function hf(t){const r=(t?.trim()||"session").normalize("NFKC").toLowerCase().replace(/[^\p{L}\p{N}]+/gu,"-").replace(/^-+|-+$/g,"").slice(0,60)||"session",o=new Date().toISOString().split("T")[0];return`${r}-${o}.md`}const jl=br(()=>({pendingSessionIds:new Set})),pf=t=>{const e=it.c(2);let n;return e[0]!==t?(n=r=>r.pendingSessionIds.has(t),e[0]=t,e[1]=n):n=e[1],jl(n)},Ec=(t,e)=>{jl.setState(n=>{if(n.pendingSessionIds.has(t)===e)return n;const r=new Set(n.pendingSessionIds);return e?r.add(t):r.delete(t),{pendingSessionIds:r}})},rb=async(t,e)=>{try{const d=(await ch(t,{mode:"light"})).current?.trim();if(d)return d}catch{}const n=jt(t),r=jt(e)??e,o=ot.getState().availableWorktreesByProject,c=(o.get(r)??o.get(e)??[]).find(a=>jt(a.path)===n)?.branch?.trim();if(c)return c;throw new Error("Unable to determine the current branch")},Tc=(t,e)=>{const n=lh(e);if(!n)throw new Error("Session status is unavailable");const r=n.session_status;if(t.some(i=>{const c=r[i.id]?.type;return c==="busy"||c==="retry"}))throw new Error("Session is not idle")},ob=async(t,e,n,r,o)=>{const i=[];for(const c of[...t].reverse())try{await du(c,r,n,c.id===e),ot.getState().setWorktreeMetadata(c.id,o.get(c.id)??null)}catch(a){i.push(a)}return i},ib=async(t,e,n)=>{try{await uu(t,e,{deleteLocalBranch:!0})}catch{const r=n instanceof Error?n.message:String(n);throw new Error(`Session move failed and the new worktree could not be removed: ${r}`)}throw n},ab=async t=>{if(jl.getState().pendingSessionIds.has(t.root.id))throw new Error("Session move already in progress");Ec(t.root.id,!0);try{const e=rh(t.sourceDirectory);if(!e)throw new Error("Unable to find the project for this session");const n=[t.root,...t.descendants],r=new Map(n.map(a=>[a.id,ot.getState().getWorktreeMetadata(a.id)]));Tc(n,t.sourceDirectory);const o=await rb(t.sourceDirectory,e.path),i=await oh(e,{startRef:o}),c=[];try{await ih(i.path),Tc(n,t.sourceDirectory);for(const[a,d]of n.entries())await du(d,t.sourceDirectory,i.path,a===0),c.push(d),ot.getState().setWorktreeMetadata(d.id,ah(i))}catch(a){if((await ob(c,t.root.id,t.sourceDirectory,i.path,r)).length>0)throw new Error(`Session move partially failed and could not be fully rolled back: ${a instanceof Error?a.message:String(a)}`);return ib(e,i,a)}try{await ai([t.sourceDirectory,i.path])}catch(a){console.warn("[session-worktree-move] Failed to refresh moved sessions",a)}return i.path}finally{Ec(t.root.id,!1)}},gf=t=>{ab(t).then(()=>Ae.success(t.successMessage)).catch(e=>Ae.error(t.failureMessage,{description:e instanceof Error?e.message:String(e)}))},Ao="app-region-no-drag inline-flex h-8 w-8 items-center justify-center gap-2 rounded-md typography-ui-label font-medium text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50 hover:bg-interactive-hover transition-colors",lb="app-region-no-drag inline-flex h-9 w-9 items-center justify-center gap-2 p-2 rounded-md typography-ui-label font-medium text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:pointer-events-none disabled:opacity-50 hover:text-foreground hover:bg-interactive-hover transition-colors",cb=l.memo(function(e){const n=it.c(17),{visible:r,title:o,ariaLabel:i,onClick:c,className:a,Icon:d,iconClassName:u,pressed:m}=e,f=r===void 0?!0:r,g=m===void 0?!1:m;if(!f)return null;const x=a??Ao,j=g&&"bg-interactive-selection text-interactive-selection-foreground";let w;n[0]!==x||n[1]!==j?(w=ge(x,j),n[0]=x,n[1]=j,n[2]=w):w=n[2];const p=u??"h-[18px] w-[18px]";let h;n[3]!==d||n[4]!==p?(h=s.jsx(T,{name:d,className:p}),n[3]=d,n[4]=p,n[5]=h):h=n[5];let b;n[6]!==i||n[7]!==c||n[8]!==g||n[9]!==w||n[10]!==h?(b=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,"aria-label":i,"aria-pressed":g,className:w,children:h})}),n[6]=i,n[7]=c,n[8]=g,n[9]=w,n[10]=h,n[11]=b):b=n[11];let v;n[12]!==o?(v=s.jsx(ht,{children:s.jsx("p",{children:o})}),n[12]=o,n[13]=v):v=n[13];let S;return n[14]!==b||n[15]!==v?(S=s.jsxs(ft,{children:[b,v]}),n[14]=b,n[15]=v,n[16]=S):S=n[16],S}),db=l.memo(function(e){const n=it.c(42),{isMobile:r,githubAuthStatus:o,githubAccounts:i,githubAvatarUrl:c,githubLogin:a,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:u}=e,{t:m}=gt();if(!o?.connected||r)return null;if(i.length>1){let j;n[0]===Symbol.for("react.memo_cache_sentinel")?(j=ge(Ao,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=j):j=n[0];let w;n[1]!==a||n[2]!==m?(w=a?m("header.github.connectedWithLogin",{login:a}):m("header.github.connected"),n[1]=a,n[2]=m,n[3]=w):w=n[3];let p;n[4]!==c||n[5]!==a||n[6]!==m?(p=c?s.jsx("img",{src:c,alt:a?m("header.github.avatarWithLogin",{login:a}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(T,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[4]=c,n[5]=a,n[6]=m,n[7]=p):p=n[7];let h;n[8]!==d||n[9]!==w||n[10]!==p?(h=s.jsx(wn,{asChild:!0,children:s.jsx("button",{type:"button",className:j,title:w,disabled:d,children:p})}),n[8]=d,n[9]=w,n[10]=p,n[11]=h):h=n[11];let b;n[12]!==m?(b=m("header.github.accountsTitle"),n[12]=m,n[13]=b):b=n[13];let v;n[14]!==b?(v=s.jsx(Ta,{className:"typography-ui-header font-semibold text-foreground",children:b}),n[14]=b,n[15]=v):v=n[15];let S;n[16]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(vn,{}),n[16]=S):S=n[16];let N;if(n[17]!==i||n[18]!==u||n[19]!==d||n[20]!==m){let C;n[22]!==u||n[23]!==d||n[24]!==m?(C=P=>{const D=P.user,O=!!P.current,F=P.source==="gh-cli"?m("header.github.accountSource.cli"):m("header.github.accountSource.oauth");return s.jsxs(Xt,{className:"gap-2",disabled:d,onSelect:()=>{O||u(P.id)},children:[D?.avatarUrl?s.jsx("img",{src:D.avatarUrl,alt:D.login?m("header.github.avatarWithLogin",{login:D.login}):m("header.github.avatar"),className:"h-6 w-6 rounded-full border border-border/60 bg-muted object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 items-center justify-center rounded-full border border-border/60 bg-muted",children:s.jsx(T,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:D?.name?.trim()||D?.login||"GitHub"}),D?.login?s.jsxs("span",{className:"truncate typography-micro text-muted-foreground",children:[s.jsx("span",{className:"font-mono",children:D.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:F})]}):null]}),O?s.jsx(T,{name:"check",className:"h-4 w-4 text-primary"}):null]},P.id)},n[22]=u,n[23]=d,n[24]=m,n[25]=C):C=n[25],N=i.map(C),n[17]=i,n[18]=u,n[19]=d,n[20]=m,n[21]=N}else N=n[21];let A;n[26]!==v||n[27]!==N?(A=s.jsxs(Sn,{align:"end",className:"w-64",children:[v,S,N]}),n[26]=v,n[27]=N,n[28]=A):A=n[28];let k;return n[29]!==h||n[30]!==A?(k=s.jsxs(jn,{children:[h,A]}),n[29]=h,n[30]=A,n[31]=k):k=n[31],k}let f;n[32]!==a||n[33]!==m?(f=a?m("header.github.connectedWithLogin",{login:a}):m("header.github.connected"),n[32]=a,n[33]=m,n[34]=f):f=n[34];let g;n[35]!==c||n[36]!==a||n[37]!==m?(g=c?s.jsx("img",{src:c,alt:a?m("header.github.avatarWithLogin",{login:a}):m("header.github.avatar"),className:"h-full w-full object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx(T,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=c,n[36]=a,n[37]=m,n[38]=g):g=n[38];let x;return n[39]!==f||n[40]!==g?(x=s.jsx("div",{className:"app-region-no-drag flex h-7 w-7 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",title:f,children:g}),n[39]=f,n[40]=g,n[41]=x):x=n[41],x}),ub=l.memo(function(e){const n=it.c(43),{isDesktopApp:r,currentInstanceLabel:o,compactCurrentInstanceLabel:i,currentInstanceIsLocal:c,isDesktopServicesOpen:a,setIsDesktopServicesOpen:d,refreshCurrentInstanceLabel:u,shortcutLabel:m,remoteUpdateInfo:f,remoteUpdateChecking:g,remoteUpdateError:x,onOpenRemoteUpdate:j}=e,{t:w}=gt();let p;n[0]!==u||n[1]!==d?(p=E=>{d(E),E&&u()},n[0]=u,n[1]=d,n[2]=p):p=n[2];let h;n[3]!==o||n[4]!==r||n[5]!==w?(h=r?w("header.services.openWithCurrent",{current:o}):w("header.services.open"),n[3]=o,n[4]=r,n[5]=w,n[6]=h):h=n[6];const b=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let v;n[7]!==b?(v=ge(Ao,b),n[7]=b,n[8]=v):v=n[8];let S;n[9]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(T,{name:"server",className:"h-[18px] w-[18px]"}),n[9]=S):S=n[9];let N;n[10]!==i||n[11]!==r?(N=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:i}):null,n[10]=i,n[11]=r,n[12]=N):N=n[12];let A;n[13]!==h||n[14]!==v||n[15]!==N?(A=s.jsx(mt,{asChild:!0,children:s.jsx(wn,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":h,className:v,children:[S,N]})})}),n[13]=h,n[14]=v,n[15]=N,n[16]=A):A=n[16];let k;n[17]!==o||n[18]!==m||n[19]!==w?(k=w("header.services.tooltip.currentInstance",{current:o,toggle:m("toggle_services_menu")}),n[17]=o,n[18]=m,n[19]=w,n[20]=k):k=n[20];let C;n[21]!==k?(C=s.jsx(ht,{children:s.jsx("p",{children:k})}),n[21]=k,n[22]=C):C=n[22];let P;n[23]!==A||n[24]!==C?(P=s.jsxs(ft,{children:[A,C]}),n[23]=A,n[24]=C,n[25]=P):P=n[25];let D;n[26]!==c||n[27]!==r||n[28]!==a||n[29]!==j||n[30]!==g||n[31]!==x||n[32]!==f||n[33]!==d||n[34]!==w?(D=r?s.jsxs("div",{children:[c?null:s.jsx("div",{className:"border-b border-[var(--interactive-border)] px-4 py-2.5",children:s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label font-medium text-foreground",children:w("header.services.remoteUpdate.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:f?.available?w("header.services.remoteUpdate.available",{version:f.version||""}):g?w("header.services.remoteUpdate.checking"):x||w("header.services.remoteUpdate.upToDate")})]}),f?.available?s.jsx("button",{type:"button",className:"shrink-0 rounded-md bg-[var(--primary-base)] px-3 py-1.5 typography-ui-label font-medium text-[var(--primary-foreground)] hover:opacity-90",onClick:j,children:w("header.services.remoteUpdate.actions.open")}):null]})}),s.jsx(dh,{embedded:!0,open:a,onOpenChange:pb,onHostSwitched:()=>d(!1)})]}):null,n[26]=c,n[27]=r,n[28]=a,n[29]=j,n[30]=g,n[31]=x,n[32]=f,n[33]=d,n[34]=w,n[35]=D):D=n[35];let O;n[36]!==D?(O=s.jsx(Sn,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto p-0",children:D}),n[36]=D,n[37]=O):O=n[37];let F;return n[38]!==a||n[39]!==p||n[40]!==P||n[41]!==O?(F=s.jsxs(jn,{open:a,onOpenChange:p,children:[P,O]}),n[38]=a,n[39]=p,n[40]=P,n[41]=O,n[42]=F):F=n[42],F}),fb=(t,e)=>t===e?!0:!t||!e?!1:t.totalTokens===e.totalTokens&&t.percentage===e.percentage&&t.contextLimit===e.contextLimit&&(t.outputLimit??0)===(e.outputLimit??0)&&(t.normalizedOutput??0)===(e.normalizedOutput??0)&&t.thresholdLimit===e.thresholdLimit&&(t.lastMessageId??"")===(e.lastMessageId??""),mb=t=>{const e=t.trim();if(!e)return"";const n=e.split(/\s+/).filter(Boolean);if(n.length>=2){const r=n[0],o=n[1].slice(0,3),i=`${r} ${o}`.trim();return n.length>2||i.length<e.length?`${i}...`:i}return e.length>12?`${e.slice(0,9).trimEnd()}...`:e},hb=(t,e)=>{if(!t)return"-";try{return yu(t,e,{fallback:"-"})}catch{return"-"}},En=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},pa=t=>!t?.isOpen||!Array.isArray(t.tabs)||t.tabs.length===0?null:(t.tabs.find(n=>n.id===t.activeTabId)??t.tabs[t.tabs.length-1])?.mode??null,Ic=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r})=>{In("ui.header.render");const{t:o}=gt(),i=pe(M=>M.setSessionSwitcherOpen),c=pe(M=>M.toggleSidebar),a=pe(M=>M.isSidebarOpen),d=pe(M=>M.openContextOverview),u=pe(M=>M.openContextPlan),m=pe(M=>M.closeContextPanel),f=pe(M=>M.activeMainTab),g=pe(M=>M.setActiveMainTab),x=pe(M=>M.shortcutOverrides),j=pe(M=>M.timeFormatPreference),w=Kt(M=>M.getCurrentModel),p=rr(),h=ot(M=>M.getContextUsage),b=ot(M=>!!M.newSessionDraft?.open),v=ot(M=>M.currentSessionId),S=uh(v??""),N=fu(v??""),A=pf(v??""),k=Fs(Jn(l.useCallback(M=>{if(!v)return null;const ze=M.activeSessions.find(St=>St.id===v);if(!ze)return null;const rt=ze;return{title:ze.title??null,directory:rt.directory??null,created:ze.time?.created??null,slug:rt.slug??null,shareUrl:ze.share?.url??null,parentId:ze.parentID??null}},[v]))),C=Gt(Jn(M=>{if(!M.activeProjectId)return null;const ze=M.projects.find(rt=>rt.id===M.activeProjectId);return ze?{id:ze.id,path:ze.path,label:ze.label}:null})),P=l.useMemo(()=>{if(!C)return null;const M=C.label?.trim();if(M)return M;const ze=C.path.split(/[\\/]/).filter(Boolean);return ze[ze.length-1]??null},[C]),D=Ns(M=>M.results),O=Ns(M=>M.fetchAllQuotas),F=Ns(M=>M.isLoading),E=Ns(M=>M.lastUpdated),B=Ns(M=>M.displayMode),$=Ns(M=>M.dropdownProviderIds),z=Ns(M=>M.loadSettings),V=Ns(M=>M.setDisplayMode),{isMobile:y}=xr(),I=Br(M=>M.status),_=Br(M=>M.setStatus),W=l.useRef(null),[K,Z]=l.useState(()=>typeof window>"u"?!1:Wn()),Q=l.useMemo(()=>Fi(),[]),le=mu(),[te,he]=l.useState(!1),xe=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),{usesFramelessChrome:H,side:we}=Xu(),de=l.useMemo(()=>{if(typeof window>"u")return null;const M=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof M=="number"&&Number.isFinite(M)&&M>0)return M;if(typeof navigator>"u")return null;const ze=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!ze)return null;const rt=Number.parseInt(ze[1],10),St=Number.parseInt(ze[2],10);return Number.isNaN(rt)?null:rt===10?St:rt},[]);nt.useEffect(()=>{typeof window>"u"||Z(Wn())},[]);const q=w(),me=q&&typeof q.limit=="object"&&q.limit!==null?q.limit:null,be=me&&typeof me.context=="number"?me.context:0,Pe=me&&typeof me.output=="number"?me.output:0,Ie=h(be,Pe),[De,Le]=l.useState(null),Ne=!v||S;nt.useEffect(()=>{if(!v){Le(M=>M===null?M:null);return}if(Ie&&Ie.totalTokens>0){Le(M=>fb(M,Ie)?M:Ie);return}Ne&&Le(M=>M===null?M:null)},[Ie,v,Ne]);const ve=pe(M=>M.isSessionSwitcherOpen),Me=I?.connected?I.user?.avatarUrl??null:null,ee=I?.connected?I.user?.login??null:null,oe=I?.accounts??[],[Te,J]=l.useState(!1),[re,Y]=l.useState(!1),[U,fe]=l.useState(!1),[ne,ce]=l.useState(!1),[Fe,Ye]=l.useState("Local"),[$e,ie]=l.useState(!0),[Re,ue]=l.useState(!1),[R,ae]=l.useState(null),[Se,Ce]=l.useState(!1),[Ee,se]=l.useState(null),je=l.useMemo(()=>mb(Fe),[Fe]),[Ze,X]=l.useState("usage"),ye=l.useMemo(()=>nr(),[]),Xe=pe(M=>M.workStatusPanelVisible),Be=pe(M=>M.workStatusPanelEnabled),We=pe(M=>M.setWorkStatusPanelEnabled),_e=pe(M=>M.workStatusPanelFits),tt=pe(M=>M.workStatusOverlayOpen),ct=pe(M=>M.setWorkStatusOverlayOpen),Nt=Be&&_e||tt,Ot=l.useCallback(()=>{if(Be&&!_e){ct(!tt);return}We(!Be)},[ct,We,tt,Be,_e]),et=!ye&&!Xe&&f==="chat"&&!!De&&De.totalTokens>0,Tt=De&&De.contextLimit>0?Math.min(999,De.totalTokens/De.contextLimit*100):0,xt=l.useCallback(async()=>{if(!(typeof window>"u"||!K))try{if(Mi()){Ye("Local"),ie(!0);return}ie(!1);const M=await nu(),ze=fh(),rt=mh([hh(ze),...M.hosts]);if(rt.id===ph){Ye("Local"),ie(!0);return}Ye(ru(rt.label.trim()||"Instance"))}catch{Ye("Local"),ie(!0)}},[K]);nt.useEffect(()=>(xt(),Li(()=>{xt()})),[xt]);const vt=l.useCallback(async()=>{if($e){ae(null),se(null);return}Ce(!0),se(null);try{const M=new URLSearchParams({appType:"web",instanceMode:"remote",reportUsage:"false"}),ze=await gs(`/api/openchamber/update-check?${M.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!ze.ok)throw new Error(`Server responded with ${ze.status}`);const rt=await ze.json();ae({available:rt.available??!1,version:rt.version,currentVersion:rt.currentVersion??"unknown",body:rt.body,nextSuggestedCheckInSec:typeof rt.nextSuggestedCheckInSec=="number"?rt.nextSuggestedCheckInSec:void 0,packageManager:rt.packageManager,updateCommand:rt.updateCommand})}catch(M){ae(null),se(M instanceof Error?M.message:o("header.services.remoteUpdate.error"))}finally{Ce(!1)}},[$e,o]);l.useEffect(()=>{ae(null),se(null),ue(!1)},[$e,Fe]),l.useEffect(()=>{if(!K||$e)return;const M=3e3,ze=3600*1e3;let rt=!1,St=null;const Ht=as=>{St=window.setTimeout(()=>{if(rt||typeof document<"u"&&document.visibilityState!=="visible"){Ht(ze);return}vt().finally(()=>{rt||Ht(ze)})},as)};return Ht(M),()=>{rt=!0,St!==null&&window.clearTimeout(St)}},[vt,$e,Fe,K]);const _t=l.useCallback(()=>{if(R?.available){ue(!0);return}vt()},[vt,R?.available]);gh();const Ct=Ns(M=>M.selectedModels),Rt=Ns(M=>M.expandedFamilies),ut=Ns(M=>M.toggleFamilyExpanded),bt=l.useMemo(()=>{const M=[];for(const ze of hu){if(!$.includes(ze.id))continue;const rt=D.find(vs=>vs.providerId===ze.id),St=rt?.usage?.windows??{},Ht=rt?.usage?.models,as=Object.entries(St),rs={providerId:ze.id,providerName:ze.name,entries:as,error:rt&&!rt.ok&&rt.configured?rt.error:void 0};if(Ht&&Object.keys(Ht).length>0){const vs=Ct[ze.id]??[],Ar=vs.length>0,zr=xh(Ht,ze.id),ra=bh(ze.id),oa=yh(ra);rs.modelFamilies=[];for(const fn of oa){const Pn=zr.get(fn.id)??[];if(Pn.length===0)continue;const ir=Ar?Pn.filter(Dr=>vs.includes(Dr)):Pn;if(ir.length===0)continue;const Fn=[];for(const Dr of ir){const co=Ht[Dr];if(co?.windows){const Pr=Object.entries(co.windows);Pr.length>0&&Fn.push([Dr,Pr[0][1]])}}Fn.length>0&&rs.modelFamilies.push({familyId:fn.id,familyLabel:fn.label,models:Fn})}const lo=zr.get(null)??[],On=Ar?lo.filter(fn=>vs.includes(fn)):lo;if(On.length>0){const fn=[];for(const Pn of On){const ir=Ht[Pn];if(ir?.windows){const Fn=Object.entries(ir.windows);Fn.length>0&&fn.push([Pn,Fn[0][1]])}}fn.length>0&&rs.modelFamilies.push({familyId:null,familyLabel:o("header.services.modelFamily.other"),models:fn})}}(as.length>0||rs.modelFamilies&&rs.modelFamilies.length>0||rs.error)&&M.push(rs)}return M},[$,D,Ct,o]),He=bt.length>0;l.useEffect(()=>{z()},[z]);const Ve=l.useCallback(async M=>{V(M);try{await ou({usageDisplayMode:M})}catch(ze){console.warn("Failed to update usage display mode:",ze)}},[V]),wt=l.useCallback(()=>{if(ne)return;ce(!0);const M=new Promise(ze=>setTimeout(ze,500));Promise.all([O(),M]).finally(()=>{ce(!1)})},[O,ne]),Ft=v?k??null:null,Lt=l.useRef(null),[ns,$t]=l.useState(0);l.useEffect(()=>{if(!v){Lt.current&&(Lt.current=null,$t(St=>St+1));return}if(Ft){Lt.current={sessionId:v,session:Ft,expiresAt:Date.now()+2e3};return}const M=Lt.current;if(!M||M.sessionId!==v)return;const ze=M.expiresAt-Date.now();if(ze<=0){Lt.current=null,$t(St=>St+1);return}const rt=window.setTimeout(()=>{Lt.current?.sessionId===v&&(Lt.current=null),$t(St=>St+1)},ze);return()=>{window.clearTimeout(rt)}},[v,Ft]);const At=(()=>{if(Ft)return Ft;if(!v)return null;const M=Lt.current;return M&&M.sessionId===v&&M.expiresAt>Date.now()?M.session:null})(),ss=ot(M=>v?M.worktreeMetadata.get(v)?.path??"":""),ms=ot(M=>v?M.worktreeMetadata.get(v)?.branch?.trim()??null:null),zt=pu(M=>v?M.getAttachment(v):void 0),qt=l.useMemo(()=>zt?vh(zt,{pending:o("gitView.empty.worktreeSetupInProgress")}):null,[o,zt]),Ut=l.useMemo(()=>zt?zt.legacy?"legacy":zt.degraded?"degraded":zt.worktreeStatus==="pending"?"pending":zt.worktreeStatus==="missing"?"missing":zt.worktreeStatus==="invalid"?"invalid":zt.attentionReason?"attention":null:null,[zt]),Jt=l.useMemo(()=>En(ss||""),[ss]),Oe=l.useMemo(()=>{const M=typeof At?.directory=="string"?At.directory:"";return En(M||"")},[At?.directory]),st=ot(M=>M.newSessionDraft?.open?En(M.newSessionDraft.bootstrapPendingDirectory??M.newSessionDraft.directoryOverride??""):""),Ke=l.useMemo(()=>Jt||Oe||st,[st,Oe,Jt]),Je=pe(l.useCallback(M=>{const ze=En(Ke||"");return ze?pa(M.contextPanelByDirectory[ze]):null},[Ke])),Qe=ot(M=>{const ze=En(Jt||Oe||"");if(!ze)return null;for(const rt of M.availableWorktreesByProject.values()){const Ht=rt.find(as=>En(as.path)===ze)?.branch?.trim();if(Ht)return Ht}return null}),ts=wh(Ke||null)||ms||Qe,Wt=!Xe&&!!(P||ts||!b&&Ut),us=l.useMemo(()=>{if(!v)return P??"OpenChamber";const M=At?.title?.trim();return M&&M.length>0?M:"Untitled Session"},[P,At?.title,v]),Bt=ll(Ke||void 0,{bootstrap:!1}),Vt=_i(),js=ot(M=>M.updateSessionTitle),ln=ot(M=>M.shareSession),Rn=ot(M=>M.unshareSession),Hn=ot(M=>M.archiveSessions),cn=ot(M=>M.deleteSessions),[Cn,Ts]=l.useState(!1),[Xs,Kn]=l.useState(!1),Is=l.useRef(!1),[_s,$s]=l.useState(""),[zs,Us]=l.useState(null),Gn=l.useRef(null);l.useEffect(()=>{Is.current=!1,Kn(!1),Ts(!1),$s(""),Us(null)},[v]);const Nn=l.useCallback(()=>{v&&($s(At?.title?.trim()||us),Ts(!0))},[At?.title,v,us]),Rs=l.useCallback(async()=>{if(!v)return;const M=_s.trim();M&&M!==At?.title?.trim()&&await js(v,M),Ts(!1)},[At?.title,v,_s,js]);l.useEffect(()=>{if(!Cn)return;const M=ze=>{const rt=ze.target;(!rt||!Gn.current?.contains(rt))&&Rs()};return document.addEventListener("mousedown",M),()=>document.removeEventListener("mousedown",M)},[Cn,Rs]);const or=l.useCallback(()=>{v&&er(v).then(M=>{Ae[M.ok?"success":"error"](o(M.ok?"sessions.sidebar.session.copyId.success":"sessions.sidebar.session.copyId.error"))}).catch(()=>Ae.error(o("sessions.sidebar.session.copyId.error")))},[v,o]),G=l.useCallback(async()=>{if(!v)return;const M=await ln(v);if(M?.share?.url){const ze=await er(M.share.url);Ae[ze.ok?"success":"warning"](o("sessions.sidebar.session.share.successTitle"),{description:o(ze.ok?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")});return}Ae.error(o("sessions.sidebar.session.share.error"))},[v,ln,o]),qe=l.useCallback(()=>{const M=At?.shareUrl;M&&er(M).then(ze=>{Ae[ze.ok?"success":"error"](o(ze.ok?"sessions.sidebar.session.menu.copied":"sessions.sidebar.session.share.copyUrlError"))}).catch(()=>Ae.error(o("sessions.sidebar.session.share.copyUrlError")))},[At?.shareUrl,o]),at=l.useCallback(async()=>{if(!v)return;const M=await Rn(v);Ae[M?"success":"error"](o(M?"sessions.sidebar.session.unshare.success":"sessions.sidebar.session.unshare.error"))},[v,o,Rn]),pt=l.useCallback(async()=>{if(!v||!Ke){Ae.error(o("sessions.sidebar.session.export.nothingToExport"));return}try{await Vt.loadCompleteHistory(v,Ke)}catch{Ae.error(o("sessions.sidebar.session.export.failedLoadHistory"));return}const M=Ia(Bt.getState(),v).list;if(M.length===0){Ae.error(o("sessions.sidebar.session.export.nothingToExport"));return}const ze=uf(M,At?.title??null),rt=hf(At?.title??null);await mf(ze,rt)||ff(ze,rt),Ae.success(o("sessions.sidebar.session.export.success"))},[At?.title,v,Bt,Ke,Vt,o]),It=N?.type==="busy"||N?.type==="retry",Dt=l.useCallback(()=>{if(!v||!Oe||It||A)return;const M=Fs.getState().activeSessions,ze=M.find(Ht=>Ht.id===v);if(!ze)return;const rt=[],St=[v];for(let Ht=0;Ht<St.length;Ht+=1){const as=St[Ht];for(const rs of M)rs.parentID===as&&(rt.push(rs),St.push(rs.id))}gf({root:ze,descendants:rt,sourceDirectory:Oe,successMessage:o("sessions.sidebar.session.moveToWorktree.success"),failureMessage:o("sessions.sidebar.session.moveToWorktree.failed")})},[v,It,A,Oe,o]),yt=l.useCallback(async()=>{if(!v||!zs)return;const M=Fs.getState().activeSessions,ze=[v];for(let as=0;as<ze.length;as+=1){const rs=ze[as];for(const vs of M)vs.parentID===rs&&!ze.includes(vs.id)&&ze.push(vs.id)}const rt=zs;if(Us(null),(rt==="archive"?await Hn(ze):await cn(ze)).failedIds.length>0){Ae.error(o(rt==="archive"?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error"));return}Ae.success(o(rt==="archive"?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"))},[Hn,v,cn,zs,o]),cs=pe(M=>M.isScheduledTasksDialogOpen),ws=pe(M=>M.isArchivePageOpen),Zt=pe(M=>M.worktreesPageProjectId),ks=pe(M=>M.isMultiRunLauncherOpen),Ms=Gt(M=>{if(!Zt)return null;const ze=M.projects.find(rt=>rt.id===Zt);return ze?.label?.trim()||ze?.path?.split("/").pop()||null}),Mn=l.useMemo(()=>cs?{title:o("sessions.scheduledTasks.dialog.title"),subtitle:null}:ws?{title:o("sessions.archivePage.title"),subtitle:null}:Zt?{title:o("sessions.worktreesPage.title",{project:Ms??""}),subtitle:null}:ks?{title:o("sessions.sidebar.header.actions.newMultiRun"),subtitle:null}:null,[ws,ks,cs,o,Zt,Ms]),Ss=l.useMemo(()=>En(Ke||C?.path||""),[C?.path,Ke]),An=l.useMemo(()=>C?{id:C.id,path:C.path}:null,[C]),yr=l.useRef(null);l.useEffect(()=>{!An||!Ss||(yr.current={projectRef:An,directory:Ss})},[Ss,An]);const vr=l.useMemo(()=>An&&Ss?{projectRef:An,directory:Ss}:yr.current,[Ss,An]),wr=cl(M=>M.planModeEnabled),ke=ot(M=>M.isSessionPlanAvailable),Pt=wr&&v?ke(v):!1,Yt=Pt,os=l.useRef("");l.useEffect(()=>{if(!wr){pe.getState().activeMainTab==="plan"&&pe.getState().setActiveMainTab("chat");return}if(!v)return;const M=`${v||"none"}:${Oe||"none"}:${At?.created||0}:${At?.slug||"none"}`;os.current!==M&&(os.current=M),!Pt&&pe.getState().activeMainTab==="plan"&&pe.getState().setActiveMainTab("chat")},[wr,Pt,At?.slug,At?.created,v,Oe]);const bs=l.useCallback(async M=>{if(!(!M||Te)){J(!0);try{const ze=p.github?await p.github.authActivate(M):await(async()=>{const rt=await gs("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:M})}),St=await rt.json().catch(()=>null);if(!rt.ok||!St)throw new Error(St?.error||rt.statusText);return St})();_(ze)}catch(ze){console.error("Failed to switch GitHub account:",ze)}finally{J(!1)}}},[Te,p.github,_]),fs=l.useCallback(()=>{if(typeof document>"u")return;const M=document.activeElement;if(!M)return;const ze=M.tagName;(ze==="INPUT"||ze==="TEXTAREA"||ze==="SELECT"||M.isContentEditable)&&M.blur()},[]),dn=l.useCallback(()=>{if(y){fs(),i(!ve);return}c()},[fs,y,ve,i,c]),Cs=l.useCallback(()=>{mr("desktop_open_draft_mini_chat_window",{directory:En(Ke||C?.path||""),projectId:C?.id??null,apiBaseUrl:hr(),clientToken:Co()}).catch(M=>{console.warn("[header] failed to open draft mini chat window",M)})},[C?.id,C?.path,Ke]),Js=l.useCallback(()=>{if(b){Cs();return}v&&mr("desktop_open_session_mini_chat_window",{sessionId:v,directory:En(Ke||C?.path||""),apiBaseUrl:hr(),clientToken:Co()}).catch(M=>{console.warn("[header] failed to open session mini chat window",M)})},[C?.path,v,Cs,b,Ke]),Sr=l.useCallback(()=>{const M=En(Ke||"");if(!M)return;const ze=pe.getState().contextPanelByDirectory[M];if(pa(ze)==="context"){m(M);return}d(M)},[m,d,Ke]),ys=Je==="context",hs=l.useCallback(()=>{const M=En(Ke||"");if(!M)return;const ze=pe.getState().contextPanelByDirectory[M];if(pa(ze)==="plan"){m(M);return}u(M)},[m,u,Ke]),Dn=Ao,jr=lb,kr=l.useMemo(()=>re?"services":n?"sessions":r?"git":f,[f,re,n,r]),oo=l.useCallback(()=>{Y(!1),n&&t&&t(),r&&e&&e(),!t&&ve&&i(!1)},[ve,n,t,e,r,i]),Qi=l.useCallback(()=>{n||Y(!1),t?.()},[n,t]),Xi=l.useCallback(()=>{r||Y(!1),e?.()},[e,r]),Oo=l.useMemo(()=>K&&xe&&!te?"5.5rem":le?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":(!K||H)&&!ye?"calc(0.75rem + var(--oc-wco-left-inset, 0px))":"0.75rem",[K,te,xe,le,ye,H]);nt.useEffect(()=>{typeof document>"u"||document.documentElement.style.setProperty("--oc-titlebar-left-inset",Oo)},[Oo]);const Ji=a?"0.75rem":"var(--oc-titlebar-left-inset, 0.75rem)",Zi=a?"0px":"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)";nt.useEffect(()=>{if(!K||!xe){he(!1);return}let M=!1;const ze=async()=>{try{const St=await mr("desktop_is_window_fullscreen");M||he(St===!0)}catch{M||he(!1)}},rt=()=>{ze()};return ze(),window.addEventListener("openchamber:window-resized",rt),()=>{M=!0,window.removeEventListener("openchamber:window-resized",rt)}},[K,xe]);const Fo=l.useMemo(()=>!K||!xe||de===null?"":de>=26?"h-12":de<=15?"h-14":"",[K,xe,de]),ea=l.useMemo(()=>{if(!(K&&!H||ye))return{paddingRight:"calc(0.75rem + var(--oc-wco-right-inset, 0px))",minHeight:"max(3rem, var(--oc-wco-titlebar-height, 0px))",height:"max(3rem, var(--oc-wco-titlebar-height, 0px))"}},[K,ye,H]),Cr=l.useCallback(()=>{if(typeof document>"u")return;const M=W.current?.getBoundingClientRect().height;M&&document.documentElement.style.setProperty("--oc-header-height",`${M}px`)},[]);nt.useEffect(()=>{if(typeof window>"u")return;Cr();const M=W.current;if(!M||typeof ResizeObserver>"u")return()=>{};let ze=0;const rt=()=>{ze||(ze=requestAnimationFrame(()=>{ze=0,Cr()}))},St=new ResizeObserver(rt);return St.observe(M),window.addEventListener("resize",rt),window.addEventListener("orientationchange",rt),()=>{ze&&cancelAnimationFrame(ze),St.disconnect(),window.removeEventListener("resize",rt),window.removeEventListener("orientationchange",rt)}},[Cr]),nt.useEffect(()=>{Cr()},[Cr,y,Fo]);const io=l.useCallback(async M=>{const ze=M.target;ze.closest(".app-region-no-drag")||ze.closest("button, a, input, select, textarea")||M.button===0&&K&&await Bm()},[K]),qn=l.useMemo(()=>{if(y){const M=[{id:"chat",label:o("layout.mainTab.chat"),icon:"chat-4"}];return Yt&&M.push({id:"plan",label:o("layout.mainTab.plan"),icon:"file-text"}),M.push({id:"diff",label:o("layout.mainTab.diff"),icon:"diff"},{id:"files",label:o("layout.mainTab.files"),icon:"folder-6"},{id:"terminal",label:o("layout.mainTab.terminal"),icon:"terminal-box"},{id:"context",label:o("layout.mainTab.context"),icon:"file-list-2"},{id:"diagram",label:o("layout.mainTab.diagram"),icon:"file"}),M}return[]},[y,Yt,o]),$r=l.useCallback(M=>$i(Or(M,x)),[x]);nt.useEffect(()=>{!y&&f!=="chat"&&f!=="terminal"&&f!=="diagram"&&g("chat")},[f,y,g]);const ao=l.useMemo(()=>{const M=[];return K&&M.push({value:"instance",label:o("layout.services.instance"),icon:s.jsx(T,{name:"server",className:"h-3.5 w-3.5"})}),M},[K,o]),Lo=l.useMemo(()=>[{id:"usage",label:o("layout.services.usage"),icon:s.jsx(T,{name:"timer",className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(gu,{className:"h-3.5 w-3.5"})}],[o]);nt.useEffect(()=>{const M=ze=>{if(xu(ze)&&!ze.shiftKey&&!ze.altKey){const rt=parseInt(ze.key,10);rt>=1&&rt<=qn.length&&(ze.preventDefault(),y&&(fs(),oo()),g(qn[rt-1].id))}};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[fs,oo,y,g,qn]),nt.useEffect(()=>{const M=ze=>{const rt=Or("toggle_services_menu",x);if(ca(ze,rt)){ze.preventDefault(),U?fe(!1):(fe(!0),xt());return}const St=Or("cycle_services_tab",x);if(ca(ze,St)){if(ze.preventDefault(),ao.length===0)return;fe(!0),xt();return}const Ht=Or("toggle_context_plan",x);ca(ze,Ht)&&(ze.preventDefault(),hs())};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[x,U,ao,D.length,O,xt,hs]);const ta=M=>{const ze=f===M.id,rt=M.icon==="diff",St=rt?null:M.icon,Ht=M.id==="chat",as=vs=>rt?s.jsx(Dc,{size:vs}):St?s.jsx(T,{name:St,className:`h-${vs/4} w-${vs/4}`}):null,rs=s.jsxs("button",{type:"button",onClick:()=>g(M.id),className:ge("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",ze?"app-region-no-drag bg-interactive-selection text-interactive-selection-foreground shadow-none":"app-region-no-drag text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",Ht&&!y&&"min-w-[100px] justify-center"),"aria-label":M.label,"aria-selected":ze,role:"tab",children:[y?as(20):s.jsxs(s.Fragment,{children:[as(16),s.jsx("span",{className:"header-tab-label",children:M.label})]}),M.badge!==void 0&&M.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:M.badge})]});return s.jsx(l.Fragment,{children:rs},M.id)},sa=s.jsxs(s.Fragment,{children:[s.jsx(kx,{directory:Ss,className:"mr-1"}),K?s.jsx(ub,{isDesktopApp:K,currentInstanceLabel:Fe,compactCurrentInstanceLabel:je,currentInstanceIsLocal:$e,isDesktopServicesOpen:U,setIsDesktopServicesOpen:fe,refreshCurrentInstanceLabel:xt,shortcutLabel:$r,remoteUpdateInfo:R,remoteUpdateChecking:Se,remoteUpdateError:Ee,onOpenRemoteUpdate:_t}):null,s.jsx(db,{isMobile:y,githubAuthStatus:I,githubAccounts:oe,githubAvatarUrl:Me,githubLogin:ee,isSwitchingGitHubAccount:Te,handleGitHubAccountSwitch:bs})]}),Bo=Q&&(b||!!v),un=()=>s.jsxs("div",{onMouseDown:io,className:ge("app-region-drag relative flex h-12 select-none items-center pr-3",Fo),style:ea,role:"tablist","aria-label":o("header.navigation.mainAria"),children:[s.jsx("div",{"aria-hidden":!0,className:"shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{width:Ji}}),s.jsx("div",{"aria-hidden":!0,className:"app-region-no-drag shrink-0 self-stretch transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",style:{width:Zi}}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[Mn?s.jsxs("div",{className:"mr-3 flex min-w-0 flex-col items-start px-1 py-0.5 -my-0.5 text-left",children:[s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:Mn.title}),Mn.subtitle?s.jsx("span",{className:"truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75 max-w-full",children:Mn.subtitle}):null]}):s.jsxs("div",{className:"app-region-no-drag mr-3 flex min-w-0 max-w-full items-center gap-0.5 py-0.5 -my-0.5 text-left",children:[a?null:s.jsx(Gg,{align:"start",children:s.jsx("button",{type:"button",className:Dn,"aria-label":o("sessions.switcher.openAria"),children:s.jsx(T,{name:"history",className:"h-[18px] w-[18px]"})})}),s.jsxs("div",{className:"flex min-w-0 flex-col justify-center px-1",children:[Cn?s.jsxs("form",{ref:Gn,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onSubmit:M=>{M.preventDefault(),Rs()},children:[s.jsx("input",{value:_s,onChange:M=>$s(M.target.value),autoFocus:!0,onKeyDown:M=>{M.stopPropagation(),M.key==="Escape"&&Ts(!1)},placeholder:o("sessions.sidebar.session.menu.rename"),className:"min-w-0 flex-1 bg-transparent typography-ui-label text-[14px] font-normal leading-tight outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"submit","aria-label":o("sessions.sidebar.session.rename.save"),title:o("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(T,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:()=>Ts(!1),"aria-label":o("sessions.sidebar.session.rename.cancel"),title:o("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(T,{name:"close",className:"size-4"})})]}):s.jsx("span",{className:"truncate typography-ui-label text-[14px] font-normal leading-tight text-foreground max-w-full",children:b?o("sessions.switcher.draftTitle"):us}),Wt?s.jsxs("span",{className:"flex min-w-0 max-w-full items-center gap-1.5 truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75",children:[P?s.jsx("span",{className:"truncate",children:P}):null,ts?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(T,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:ts})]}):null,!b&&Ut?s.jsxs("span",{className:ge("inline-flex min-w-0 items-center gap-0.5",Ut==="attention"||Ut==="invalid"||Ut==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(T,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:qt})]}):null]}):null]}),s.jsx("div",{className:ge("flex h-[18px] shrink-0 items-center justify-center",Wt?"self-start":"self-center"),children:v&&!b&&!Cn?s.jsxs(jn,{open:Xs,onOpenChange:Kn,onOpenChangeComplete:M=>{!M&&Is.current&&(Is.current=!1,Nn())},children:[s.jsx(wn,{asChild:!0,children:s.jsx(lt,{variant:"ghost",size:"xs",className:"h-[18px] w-6 px-0 text-muted-foreground hover:bg-transparent hover:text-foreground","aria-label":o("header.sessionActions.openAria"),children:s.jsx(T,{name:"more",className:"size-4"})})}),s.jsxs(Sn,{align:"end",className:"min-w-[190px]",children:[s.jsxs(Xt,{onClick:()=>{Is.current=!0},children:[s.jsx(T,{name:"pencil-ai",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.rename")]}),s.jsxs(Xt,{onClick:or,children:[s.jsx(T,{name:"file-copy",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.copyId")]}),s.jsx(vn,{}),At?.shareUrl?s.jsxs(s.Fragment,{children:[s.jsxs(Xt,{onClick:qe,children:[s.jsx(T,{name:"file-copy",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.copyLink")]}),s.jsxs(Xt,{onClick:()=>{at()},children:[s.jsx(T,{name:"link-unlink-m",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(Xt,{onClick:()=>{G()},children:[s.jsx(T,{name:"share-2",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.share")]}),s.jsxs(Xt,{onClick:()=>{pt()},children:[s.jsx(T,{name:"download",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.exportMarkdown")]}),!ye&&At&&!At.parentId?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(Xt,{disabled:!Oe||It||A,onClick:Dt,className:"w-full",children:[s.jsx(T,{name:"folder-shared",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.moveToWorktree")]})})}),s.jsx(ht,{side:"right",className:"max-w-72",children:o(A?"sessions.sidebar.session.moveToWorktree.tooltipMoving":It?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,s.jsx(vn,{}),s.jsxs(Xt,{onClick:()=>Us("archive"),children:[s.jsx(T,{name:"inbox-archive",className:"mr-2 size-4"}),o("sessions.sidebar.bulkActions.archive")]}),s.jsxs(Xt,{className:"text-destructive focus:text-destructive",onClick:()=>Us("delete"),children:[s.jsx(T,{name:"delete-bin",className:"mr-2 size-4"}),o("sessions.sidebar.bulkActions.delete")]})]})]}):null})]}),qn.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:qn.map(M=>ta(M))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[et&&De?s.jsx(qg,{totalTokens:De.totalTokens,percentage:Tt,colorPercentage:De.percentage,contextLimit:De.contextLimit,outputLimit:De.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:Sr,pressed:ys,className:Bo?"":"mr-3.5",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-4.5 w-4.5"}):null,s.jsx(cb,{visible:Bo,title:o(b?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:o(b?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:Js,className:ge(Dn,"mr-1"),Icon:"picture-in-picture-2"}),f==="chat"&&!ye?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button","data-work-status-toggle":"true","aria-pressed":Nt,"aria-label":o("header.workStatusPanel.toggleAria"),onClick:Ot,className:ge(Ao,"mr-1",Nt?"text-foreground":"text-muted-foreground/50"),children:s.jsx(T,{name:"list-indefinite",className:"h-[18px] w-[18px]"})})}),s.jsx(ht,{side:"bottom",children:o(Be&&!_e?tt?"header.workStatusPanel.hide":"header.workStatusPanel.showOverlay":Be?"header.workStatusPanel.hide":"header.workStatusPanel.show")})]}):null,sa,s.jsx(Ju,{visible:H&&we==="right",position:"right"})]})]})]}),na=()=>s.jsxs("div",{className:"app-region-drag relative flex items-center gap-2 px-3 py-2 select-none",children:[s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[t?s.jsx("button",{type:"button",onClick:Qi,className:ge(jr,kr==="sessions"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":o(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(T,{name:"layout-left",className:"h-5 w-5"})}):ve?s.jsx("button",{type:"button",onClick:()=>i(!1),className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":o("header.actions.backAria"),children:s.jsx(T,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:dn,className:"app-region-no-drag h-9 w-9 p-2 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary rounded-md active:bg-interactive-active","aria-label":o("header.actions.openSessionsAria"),children:s.jsx(T,{name:"play-list-add",className:"h-5 w-5"})}),!t&&ve&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:o("header.sessions.title")})]}),(!ve||!!t)&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"app-region-no-drag flex min-w-0 flex-1 items-center",children:s.jsx("div",{className:"flex min-w-0 flex-1 overflow-x-auto overflow-y-hidden scrollbar-hidden touch-pan-x overscroll-x-contain",children:s.jsx("div",{className:"flex w-max items-center gap-1 pr-1",children:s.jsx("div",{className:"flex items-center gap-0.5 rounded-lg bg-[var(--surface-muted)]/50 p-0.5",role:"tablist","aria-label":o("header.navigation.mainAria"),children:qn.map(M=>{const ze=f===M.id,rt=M.icon==="diff",St=rt?null:M.icon;return s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{y&&(fs(),oo()),g(M.id)},"aria-label":M.label,"aria-selected":ze,role:"tab",className:ge(jr,"relative rounded-lg",kr===M.id&&"bg-interactive-selection text-interactive-selection-foreground"),children:[rt?s.jsx(Dc,{className:"h-5 w-5"}):St?s.jsx(T,{name:St,className:"h-5 w-5"}):null,M.badge!==void 0&&M.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:M.badge}),M.showDot&&s.jsx("span",{className:"absolute top-1.5 right-1.5 h-2 w-2 rounded-full bg-primary","aria-label":o("header.changes.availableAria")})]})}),s.jsx(ht,{children:s.jsx("p",{children:M.label})})]},M.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[vr&&s.jsx(lf,{projectRef:vr.projectRef,directory:vr.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(jn,{open:re,onOpenChange:M=>{M&&(n&&t&&t(),r&&e&&e()),Y(M),M&&D.length===0&&O()},children:[s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx(wn,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":o("header.services.viewAria"),className:ge(jr,kr==="services"&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(T,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(ht,{children:s.jsx("p",{children:o("header.services.title")})})]}),s.jsx(Sn,{align:"end",sideOffset:0,positionerClassName:"!fixed !bottom-0 !left-0 !right-0 !top-[var(--oc-header-height,56px)] !transform-none",className:"h-full w-screen max-h-none rounded-none border-0 p-0 pt-1 overflow-hidden",children:s.jsxs("div",{className:"flex h-full flex-col bg-[var(--surface-elevated)]",children:[s.jsx("div",{className:"sticky top-0 z-20 bg-[var(--surface-elevated)] px-2 py-px",children:s.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-0",children:[s.jsx("div",{className:"h-10 min-w-0 flex-1",children:s.jsx(yl,{items:Lo,activeId:Ze,onSelect:M=>{const ze=M;X(ze),ze==="usage"&&D.length===0&&O()},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})}),s.jsx("button",{type:"button",onClick:()=>Y(!1),className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover","aria-label":o("header.services.closeAria"),children:s.jsx(T,{name:"close",className:"h-5 w-5"})})]})}),Ze==="mcp"&&s.jsx(Tg,{active:re&&Ze==="mcp"}),Ze==="usage"&&s.jsxs("div",{className:"flex-1 overflow-y-auto overflow-x-hidden pb-[calc(4rem+env(safe-area-inset-bottom))]",children:[s.jsx("div",{className:"border-b border-[var(--interactive-border)]",children:s.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-3",children:[s.jsxs("div",{className:"flex flex-col min-w-0 gap-0.5",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:o("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:hb(E,j)})]}),s.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[s.jsxs("div",{className:"flex items-center h-6",children:[s.jsx("button",{type:"button",onClick:()=>Ve("usage"),className:ge("typography-ui-label px-1 pb-0.5 transition-colors",B==="usage"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:o("header.services.used")}),s.jsx("span",{className:"text-muted-foreground typography-ui-label px-0.5",children:"·"}),s.jsx("button",{type:"button",onClick:()=>Ve("remaining"),className:ge("typography-ui-label px-1 pb-0.5 transition-colors",B==="remaining"?"text-foreground border-b-2 border-[var(--primary-base)]":"text-muted-foreground hover:text-foreground"),children:o("header.services.remaining")})]}),s.jsx("button",{type:"button",className:ge("inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors","hover:text-foreground hover:bg-interactive-hover","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),onClick:wt,disabled:F||ne,"aria-label":o("header.services.refreshRateLimitsAria"),children:s.jsx(T,{name:"refresh",className:ge("h-4 w-4",ne&&"animate-spin")})})]})]})}),!He&&s.jsx("div",{className:"px-4 py-6 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:o("header.services.noRateLimits")})}),s.jsx("div",{className:"py-1",children:bt.map((M,ze)=>s.jsxs(l.Fragment,{children:[ze>0?s.jsx("div",{className:"mx-4 my-1 border-t border-[var(--interactive-border)]"}):null,s.jsxs("div",{className:"flex items-center gap-2 px-4 py-2",children:[s.jsx(bi,{providerId:M.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:M.providerName})]}),M.entries.length===0&&(!M.modelFamilies||M.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:M.error??o("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[M.entries.map(([rt,St])=>{const Ht=B==="remaining"?St.remainingPercent:St.usedPercent,as=Ra(St.valueLabel,Ht),rs=Sh(St.resetAt,St.resetAfterFormatted??St.resetAtFormatted,j);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0 flex items-center gap-2",children:[s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:bu(rt)}),rs?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:rs}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:as==="-"?"":as})]}),s.jsx(bc,{percent:Ht,tonePercent:St.usedPercent,className:"h-1.5"})]},`${M.providerId}-${rt}`)}),M.modelFamilies&&M.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:M.modelFamilies.map(rt=>{const Ht=(Rt[M.providerId]??[]).includes(rt.familyId??"other");return s.jsxs(Si,{open:Ht,onOpenChange:()=>ut(M.providerId,rt.familyId??"other"),children:[s.jsxs(vl,{className:"flex w-full items-center justify-between rounded-md px-1 py-1.5 text-left hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:rt.familyLabel}),Ht?s.jsx(T,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(T,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(ji,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:rt.models.map(([as,rs])=>{const vs=B==="remaining"?rs.remainingPercent:rs.usedPercent,Ar=Ra(rs.valueLabel,vs);return s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsxs("div",{className:"flex min-w-0 items-center justify-between gap-3",children:[s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:jh(as)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Ar==="-"?"":Ar})]}),s.jsx(bc,{percent:vs,tonePercent:rs.usedPercent,className:"h-1.5"})]},`${M.providerId}-${as}`)})})})]},rt.familyId??"other")})})]})]},M.providerId))})]})]})})]}),e?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Xi,className:ge(jr,"relative",kr==="git"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(T,{name:"layout-right",className:"h-5 w-5"})})}),s.jsx(ht,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Nr=ge("header-safe-area relative z-10 bg-background",y&&"border-b border-border/50");return s.jsxs(s.Fragment,{children:[s.jsx("header",{ref:W,className:Nr,style:{"--padding-scale":"1"},children:y?na():un()}),s.jsx(Ls,{open:zs!==null,onOpenChange:M=>{M||Us(null)},children:s.jsxs(Bs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(kn,{children:[s.jsx(nn,{children:o(zs==="delete"?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.archiveSession.title")}),s.jsx(rn,{children:zs==="delete"?o("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:us}):o("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:us})})]}),s.jsxs(sr,{children:[s.jsx(lt,{variant:"outline",size:"sm",onClick:()=>Us(null),children:o("sessions.sidebar.dialogs.cancel")}),s.jsx(lt,{variant:"destructive",size:"sm",onClick:()=>{yt()},children:o(zs==="delete"?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")})]})]})}),s.jsx(Wu,{open:Re,onOpenChange:ue,info:R,downloading:!1,downloaded:!1,progress:null,error:Ee,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})};function pb(){}const Rc=280,Mc=280,Oc=500,gb=({isOpen:t,isMobile:e,children:n,className:r,topBar:o})=>{const{t:i}=gt(),c=pe(k=>k.sidebarWidth),a=pe(k=>k.setSidebarWidth),[d,u]=l.useState(!1),m=l.useRef(0),f=l.useRef(c||Rc),g=l.useRef(null),x=l.useRef(null),j=l.useRef(null),w=l.useCallback(k=>Math.min(Oc,Math.max(Mc,k)),[]),p=l.useCallback(k=>{const C=j.current;C&&(C.style.width=`${k}px`,C.style.minWidth=`${k}px`,C.style.maxWidth=`${k}px`,C.style.setProperty("--oc-left-sidebar-width",`${k}px`))},[]);if(l.useEffect(()=>{e&&d&&u(!1)},[e,d]),l.useEffect(()=>{d||(g.current=null,x.current=null)},[d]),e)return null;const h=Math.min(Oc,Math.max(Mc,c||Rc)),b=t?h:0,v=k=>{if(t){try{k.currentTarget.setPointerCapture(k.pointerId)}catch{}x.current=k.pointerId,u(!0),m.current=k.clientX,f.current=b,g.current=b,p(b),k.preventDefault()}},S=k=>{if(e||!d||x.current!==k.pointerId)return;const C=k.clientX-m.current,P=w(f.current+C);g.current!==P&&(g.current=P,p(P))},N=k=>{if(x.current!==k.pointerId||e)return;try{k.currentTarget.releasePointerCapture(k.pointerId)}catch{}const C=w(g.current??b);x.current=null,g.current=null,u(!1),a(C)},A=d?g.current??b:b;return s.jsxs("aside",{ref:j,className:ge("relative flex h-full overflow-hidden border-r border-border will-change-[width] motion-reduce:transition-none","bg-sidebar",!t&&"border-r-0",r),style:{width:`${A}px`,minWidth:`${A}px`,maxWidth:`${A}px`,"--oc-left-sidebar-width":`${d?A:h}px`,overflowX:"clip",transitionProperty:d?"none":"width, min-width, max-width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t||b===0,children:[t&&s.jsx("div",{className:"pointer-events-none absolute inset-0 z-30 shadow-[inset_-2px_0_10px_-2px_rgb(0_0_0_/_0.06)]","aria-hidden":"true"}),t&&s.jsx("div",{className:ge("absolute right-0 top-0 z-20 h-full w-[3px] cursor-col-resize hover:bg-[var(--interactive-border)]/80 transition-colors",d&&"bg-[var(--interactive-border)]"),onPointerDown:v,onPointerMove:S,onPointerUp:N,onPointerCancel:N,role:"separator","aria-orientation":"vertical","aria-label":i("sidebar.resize.leftPanelAria")}),s.jsxs("div",{className:ge("relative z-10 flex h-full shrink-0 flex-col transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",d&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-left-sidebar-width)",overflowX:"hidden"},"aria-hidden":!t,children:[o,s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s.jsx(ds,{children:n})})]})]})},xb=()=>{const t=it.c(3);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e={height:"var(--oc-header-height, 3rem)"},t[0]=e):e=t[0];let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("div",{className:"app-region-drag shrink-0",style:{width:"var(--oc-titlebar-left-inset, 0.75rem)"}}),t[1]=n):n=t[1];let r;return t[2]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsxs("div",{"aria-hidden":!0,className:"flex shrink-0",style:e,children:[n,s.jsx("div",{className:"app-region-no-drag shrink-0",style:{width:"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)"}}),s.jsx("div",{className:"app-region-drag flex-1"})]}),t[2]=r):r=t[2],r},Wo=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function bb(){const t=Gt(f=>f.activeProjectId?f.projects.find(g=>g.id===f.activeProjectId)??null:null),e=ot(f=>f.currentSessionId),n=kh(e??null),r=ot(f=>e?f.worktreeMetadata.get(e)?.path??"":""),o=ot(f=>f.newSessionDraft?.open?Wo(f.newSessionDraft.bootstrapPendingDirectory??f.newSessionDraft.directoryOverride??""):""),i=l.useMemo(()=>Wo(r||""),[r]),c=l.useMemo(()=>{const f=typeof n?.directory=="string"?n.directory:"";return Wo(f||"")},[n?.directory]),a=i||c||o,d=l.useMemo(()=>Wo(a||t?.path||""),[t?.path,a]),u=l.useMemo(()=>t?{id:t.id,path:t.path}:null,[t]),m=l.useRef(null);return l.useEffect(()=>{u&&d&&(m.current={projectRef:u,directory:d})},[d,u]),l.useMemo(()=>u&&d?{projectRef:u,directory:d}:m.current,[u,d])}const Fc="app-region-no-drag inline-flex h-8 w-8 items-center justify-center gap-2 rounded-md typography-ui-label font-medium text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary hover:bg-interactive-hover transition-colors",yb=()=>{const t=it.c(35),{t:e}=gt(),n=pe(vb),r=pe(wb),o=bb(),i=l.useRef(null),c=$i(Or("toggle_sidebar",r)),{usesFramelessChrome:a,side:d}=Xu(),u=jb;let m,f;t[0]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{if(typeof document>"u")return;const B=i.current;if(!B)return;const $=()=>{const V=Math.max(B.getBoundingClientRect().width,B.scrollWidth);document.documentElement.style.setProperty("--oc-titlebar-controls-width",`${Math.round(V)}px`)};if($(),typeof ResizeObserver>"u")return;const z=new ResizeObserver($);return z.observe(B),()=>{z.disconnect()}},f=[],t[0]=m,t[1]=f):(m=t[0],f=t[1]),l.useEffect(m,f);const g="app-region-no-drag absolute left-0 top-0 z-30 flex select-none items-center pr-2";let x;t[2]===Symbol.for("react.memo_cache_sentinel")?(x={height:"var(--oc-header-height, 3rem)",paddingLeft:"var(--oc-titlebar-left-inset, 0.75rem)"},t[2]=x):x=t[2];const j="flex items-center gap-2";let w;t[3]!==a||t[4]!==d?(w=a&&d==="left"?s.jsx(Ju,{visible:!0,position:"left"}):null,t[3]=a,t[4]=d,t[5]=w):w=t[5];let p;t[6]!==e||t[7]!==a?(p=a?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,"aria-label":e("header.actions.openAppMenuAria"),className:ge(Fc,"shrink-0"),children:s.jsx(T,{name:"menu-2",className:"h-[18px] w-[18px]"})})}),s.jsx(ht,{children:s.jsx("p",{children:e("header.actions.openAppMenu")})})]}):null,t[6]=e,t[7]=a,t[8]=p):p=t[8];const h=ft;let b;t[9]!==e?(b=e("header.actions.openSessionsAria"),t[9]=e,t[10]=b):b=t[10];let v,S;t[11]===Symbol.for("react.memo_cache_sentinel")?(v=ge(Fc,"shrink-0"),S=s.jsx(T,{name:"layout-left",className:"h-[18px] w-[18px]"}),t[11]=v,t[12]=S):(v=t[11],S=t[12]);let N;t[13]!==b||t[14]!==n?(N=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":b,className:v,children:S})}),t[13]=b,t[14]=n,t[15]=N):N=t[15];const A=ht,k=e("header.actions.openSessionsWithShortcut",{shortcut:c});let C;t[16]!==k?(C=s.jsx("p",{children:k}),t[16]=k,t[17]=C):C=t[17];let P;t[18]!==A||t[19]!==C?(P=s.jsx(A,{children:C}),t[18]=A,t[19]=C,t[20]=P):P=t[20];let D;t[21]!==h||t[22]!==N||t[23]!==P?(D=s.jsxs(h,{children:[N,P]}),t[21]=h,t[22]=N,t[23]=P,t[24]=D):D=t[24];let O;t[25]!==o?(O=o?s.jsx(lf,{projectRef:o.projectRef,directory:o.directory}):null,t[25]=o,t[26]=O):O=t[26];let F;t[27]!==D||t[28]!==O||t[29]!==w||t[30]!==p?(F=s.jsxs("div",{ref:i,className:j,children:[w,p,D,O]}),t[27]=D,t[28]=O,t[29]=w,t[30]=p,t[31]=F):F=t[31];let E;return t[32]!==F||t[33]!==x?(E=s.jsx("div",{className:g,style:x,children:F}),t[32]=F,t[33]=x,t[34]=E):E=t[34],E};function vb(t){return t.toggleSidebar}function wb(t){return t.shortcutOverrides}function Sb(t){console.warn("[titlebar] failed to open app menu",t)}function jb(t){const e=t.currentTarget.getBoundingClientRect();mr("desktop_show_app_menu",{x:e.left,y:e.bottom}).catch(Sb)}const Lc=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function kb(t,e,n){const r=it.c(5),[o,i]=l.useState();let c,a;return r[0]!==n||r[1]!==t||r[2]!==e?(c=()=>{if(e){i(void 0);return}if(!t){i(void 0);return}i(void 0);let d=!1;return(async()=>{const[u,m]=await Promise.all([Ch(t),Nh(t)]).catch(Cb);if(d)return;const f=Lc(u),g=Lc(m);if(!f||!g||g===f)return;const x=n||"",j=g.split("/").filter(Boolean).pop()||g;i({source:"sdk",path:g,projectDirectory:f,branch:x,label:x||j,name:j,worktreeRoot:g,worktreeStatus:"ready",headState:x?"branch":"unborn",worktreeSource:"existing"})})(),()=>{d=!0}},a=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=c,r[4]=a):(c=r[3],a=r[4]),l.useEffect(c,a),e??o}function Cb(){return["",""]}class Gi extends Error{code;model;requiredChars;availableChars;constructor(e,n={}){super(e),this.name="WalkthroughError",this.code=n.code,this.model=n.model,this.requiredChars=n.requiredChars,this.availableChars=n.availableChars}}const qi="/api/walkthrough",xf=t=>/^application\/(?:[\w.+-]+\+)?json\b/i.test(t.headers.get("content-type")??""),bf=()=>new Gi("This OpenChamber server has no walkthrough API",{code:"server-unsupported"}),Nb=t=>!xf(t)&&(t.ok||t.status===404),kl=async(t,e)=>{if(Nb(t))throw bf();const n=await t.json().catch(()=>null);throw new Gi(typeof n?.error=="string"?n.error:e,{code:typeof n?.code=="string"?n.code:void 0,model:n?.model??void 0,requiredChars:typeof n?.requiredChars=="number"?n.requiredChars:void 0,availableChars:typeof n?.availableChars=="number"?n.availableChars:void 0})},yf=async t=>{if(!xf(t))throw bf();try{return await t.json()}catch{throw new Gi("The server returned a malformed walkthrough response")}};async function Ab(t,e,n={}){const r=await gs(qi,{query:{directory:t,source:JSON.stringify(e),...n.model?{model:n.model}:{},...n.language?{language:n.language}:{}},signal:n.signal});return r.ok?yf(r):kl(r,"Failed to load walkthrough")}async function Db(t,e,n={}){const r=await gs(`${qi}/generate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:t,source:e,force:n.force===!0,...n.model?{model:n.model}:{},...n.language?{language:n.language}:{}}),signal:n.signal});return r.ok?yf(r):kl(r,"Failed to generate walkthrough")}async function Pb(t,e){const n=await gs(`${qi}/cancel`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:t,source:e})});n.ok||await kl(n,"Failed to cancel walkthrough generation")}async function Eb(t,e,n){const r=await gs(`${qi}/progress`,{query:{directory:t,source:JSON.stringify(e)},signal:n});if(!r.ok)return null;const o=await r.json().catch(()=>null);return typeof o?.stage=="string"?o.stage:null}const mo={status:"idle",stage:null,result:null,readiness:null,error:null},Tb=t=>t.kind==="working-tree"?`working-tree:${t.scope}`:t.kind==="branch"?`branch:${t.baseRef}...${t.headRef}`:`pr:${t.number}`,cr=(t,e)=>`${Ps()}\0${t}\0${Tb(e)}`,Bc=t=>t instanceof Gi?{message:t.message,code:t.code,model:t.model,requiredChars:t.requiredChars,availableChars:t.availableChars}:{message:t instanceof Error?t.message:"Something went wrong"},pn=new Map,ho=new Map,Ib=1e3,Rb=br()(Zu((t,e)=>({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{},selectLanguage:(n,r,o)=>{const i=cr(n,r);t(c=>{const a={...c.selectedLanguage};return o?a[i]=o:delete a[i],{selectedLanguage:a}})},getSelectedLanguage:(n,r)=>e().selectedLanguage[cr(n,r)],selectModel:(n,r,o)=>{const i=cr(n,r);t(c=>{const a={...c.selectedModel};return o?a[i]=o:delete a[i],{selectedModel:a}})},getSelectedModel:(n,r)=>e().selectedModel[cr(n,r)],requestSource:(n,r)=>{t(o=>({requestedSource:{...o.requestedSource,[n]:r}}))},clearRequestedSource:n=>{t(r=>{if(!r.requestedSource[n])return r;const o={...r.requestedSource};return delete o[n],{requestedSource:o}})},getEntry:(n,r)=>e().entries[cr(n,r)]??mo,load:async(n,r,o={})=>{if(!n)return;const i=cr(n,r);if(e().entries[i]?.status==="generating")return;pn.get(i)?.abort();const a=new AbortController;pn.set(i,a),t(d=>({entries:{...d.entries,[i]:{...d.entries[i]??mo,status:"loading",error:null}}}));try{const d=await Ab(n,r,{model:e().selectedModel[i],language:o.language,signal:a.signal});if(a.signal.aborted)return;t(u=>({entries:{...u.entries,[i]:{status:"ready",stage:null,result:d,readiness:d.readiness??null,error:null}}})),d.generating&&e().generate(n,r,{language:o.language})}catch(d){if(a.signal.aborted)return;t(u=>({entries:{...u.entries,[i]:{...u.entries[i]??mo,status:"error",stage:null,error:Bc(d)}}}))}finally{pn.get(i)===a&&pn.delete(i)}},generate:async(n,r,o={})=>{if(!n)return;const i=cr(n,r);pn.get(i)?.abort();const c=new AbortController;pn.set(i,c),t(d=>({entries:{...d.entries,[i]:{...d.entries[i]??mo,status:"generating",stage:"collecting",error:null}}}));const a=()=>{const d=ho.get(i);d!==void 0&&(clearInterval(d),ho.delete(i))};a(),ho.set(i,setInterval(()=>{Eb(n,r).then(d=>{!d||c.signal.aborted||t(u=>{const m=u.entries[i];return!m||m.status!=="generating"||m.stage===d?u:{entries:{...u.entries,[i]:{...m,stage:d}}}})}).catch(()=>{})},Ib));try{const d=await Db(n,r,{force:o.force,model:e().selectedModel[i],language:o.language,signal:c.signal});if(c.signal.aborted)return;t(u=>({entries:{...u.entries,[i]:{status:"ready",stage:null,result:d,readiness:u.entries[i]?.readiness??null,error:null}}}))}catch(d){if(c.signal.aborted)return;t(u=>({entries:{...u.entries,[i]:{...u.entries[i]??mo,status:"error",stage:null,error:Bc(d)}}}))}finally{a(),pn.get(i)===c&&pn.delete(i)}},cancel:(n,r)=>{const o=cr(n,r);Pb(n,r).catch(()=>{}),pn.get(o)?.abort(),pn.delete(o),t(i=>{const c=i.entries[o];return c?{entries:{...i.entries,[o]:{...c,status:c.result?"ready":"idle",stage:null,error:null}}}:i})},reset:()=>{for(const n of pn.values())n.abort();pn.clear();for(const n of ho.values())clearInterval(n);ho.clear(),t({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{}})}}),{name:"walkthrough-store"})),Mb="border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)] hover:text-[var(--status-info)]",Ob=3e4,_c=20,vf=(t,e)=>JSON.stringify([Ps(),t,e]),Fb=t=>{try{const e=JSON.parse(t);if(!Array.isArray(e)||e.length!==3)return null;const[n,r,o]=e;return typeof n!="string"||typeof r!="string"||typeof o!="number"?null:{runtimeKey:n,directory:r,number:o}}catch{return null}},$c=()=>({result:null,hasCheckDetails:!1,fetchedAt:0,isLoading:!1,error:null}),Vo=new Map,Lb=t=>{const e=Object.entries(t);return e.length<=_c?t:Object.fromEntries(e.sort(([,n],[,r])=>r.fetchedAt-n.fetchedAt).slice(0,_c))},zc=br()((t,e)=>({entries:{},ensure:async(n,r,o,i)=>{const c=vf(r,o),a=i?.includeCheckDetails??!1,d=e().entries[c],u=d&&d.result&&Date.now()-d.fetchedAt<Ob&&(d.hasCheckDetails||!a);if(!i?.force&&u)return d.result;const m=`${c}::${a?"details":"plain"}`,g=Vo.get(`${c}::details`)??(a?null:Vo.get(m));if(g&&!i?.force)return g;const x=(async()=>{t(j=>({entries:{...j.entries,[c]:{...j.entries[c]??$c(),isLoading:!0,error:null}}}));try{const j=await n.prContext(r,o,{includeDiff:!1,includeCheckDetails:a,sourceRepo:i?.sourceRepo??null});return t(w=>({entries:Lb({...w.entries,[c]:{result:j,hasCheckDetails:a,fetchedAt:Date.now(),isLoading:!1,error:null}})})),j}catch(j){const w=j instanceof Error?j.message:"Failed to load pull request context";return t(p=>({entries:{...p.entries,[c]:{...p.entries[c]??$c(),isLoading:!1,error:w}}})),null}finally{Vo.delete(m)}})();return Vo.set(m,x),x},invalidate:(n,r)=>{t(o=>{const i={};for(const[c,a]of Object.entries(o.entries)){const d=Fb(c);d&&d.directory===n&&(r==null||d.number===r)||(i[c]=a)}return{entries:i}})}})),Bb=t=>{const e={success:0,failure:0,pending:0,inProgress:0,queued:0};let n;for(const i of t){if(i.status==="in_progress"){e.pending+=1,e.inProgress+=1,i.startedAt&&(!n||i.startedAt<n)&&(n=i.startedAt);continue}if(i.status==="queued"){e.pending+=1,e.queued+=1;continue}const c=typeof i.conclusion=="string"?i.conclusion.toLowerCase():"";if(!c){e.pending+=1;continue}c==="success"||c==="neutral"||c==="skipped"?e.success+=1:e.failure+=1}const r=e.success+e.failure+e.pending;return{state:e.failure>0?"failure":e.pending>0?"pending":r>0?"success":"unknown",total:r,...e,...n?{startedAt:n}:{}}},_b=35e3,ga=(t,e,n)=>{if(!t)return null;const r=Date.parse(t);if(!Number.isFinite(r))return null;const o=e?Date.parse(e):n??Date.now();if(!Number.isFinite(o)||o<=r)return null;const i=Math.floor((o-r)/6e4);if(i<1)return"<1m";if(i<60)return`${i}m`;const c=Math.floor(i/60),a=i%60;return a>0?`${c}h ${a}m`:`${c}h`},xa=t=>{const e=typeof t=="string"?t.toLowerCase():"";return!!e&&!["success","neutral","skipped"].includes(e)},Uc=t=>{switch(t){case"success":return"bg-[color:var(--status-success)]";case"failure":return"bg-[color:var(--status-error)]";case"pending":return"bg-[color:var(--status-warning)]";default:return"bg-muted-foreground/40"}},$b=t=>{const e=t?.pr;if(!e)return null;if(e.state==="merged")return"merged";if(e.state==="closed")return"closed";if(e.draft)return"draft";const n=t?.checks?.state==="failure",r=typeof e.mergeableState=="string"?e.mergeableState:"",o=e.mergeable===!1||r==="blocked"||r==="dirty";return n||o?"blocked":"open"},zb=[2e3,5e3],Wc=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),ur=t=>{let e=t.trim();return e?(e.startsWith("refs/heads/")&&(e=e.slice(11)),e.startsWith("heads/")&&(e=e.slice(6)),e.startsWith("remotes/")&&(e=e.slice(8)),e):""},Ub=(t,e)=>{const n=ur(t);if(!n||n.includes("->"))return"";if(e){const o=`${e}/`;return n.startsWith(o)?n.slice(o.length).trim():""}const r=n.indexOf("/");return r>0?n.slice(r+1).trim():n},Wb=(t,e)=>`${t}::${e}`,Cl=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},ba=(t,e)=>{if(t.length===0)return null;const n=String(e.selectedRemoteName||"").trim();if(n){const i=t.find(c=>c.name===n);if(i)return i}const r=Cl(e.trackingBranch);if(r){const i=r==="origin"?t.find(a=>a.name==="upstream"):null;if(i)return i;const c=t.find(a=>a.name===r);if(c)return c}const o=t.find(i=>i.name==="origin");return o||(t[0]??null)},Vb=t=>t.startsWith("pr-"),Hb=(t,e)=>{const n=Cl(e),r=new Map(t.map(c=>[c.name,c])),o=[],i=c=>{c&&(o.some(a=>a.name===c.name)||o.push(c))};return n&&i(r.get(n)),i(r.get("upstream")),i(r.get("origin")),t.filter(c=>!Vb(c.name)).forEach(c=>i(c)),t.forEach(c=>i(c)),o},po=new Map,Ho=Bi;function Kb(t,e){const[n,r]=l.useState(null),[o,i]=l.useState([]),c=l.useRef(null);return l.useEffect(()=>{r(null),i([])},[t]),l.useEffect(()=>{if(!t||!e?.repoUpstream||c.current===t)return;c.current=t;let a=!1;return(async()=>{try{const d=await e.repoUpstream(t);if(a||!d?.isFork||!d.upstream||(r(d.upstream),!e.repoBranches))return;try{const u=await e.repoBranches(d.upstream.owner,d.upstream.repo);a||i(u)}catch{}}catch{}})(),()=>{a=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:o}}const Gb=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:o=[],remoteBranches:i=[],onGeneratedDescription:c})=>{const{t:a}=gt(),d=pe(G=>G.timeFormatPreference),{github:u}=rr(),m=Br(G=>G.status),f=Br(G=>G.hasChecked),g=pe(G=>G.setSettingsDialogOpen),x=pe(G=>G.setSettingsPage),j=pe(G=>G.setActiveMainTab),w=ot(G=>G.currentSessionId),p=ot(G=>!!G.newSessionDraft?.open),{isMobile:h,hasTouchInput:b,screenWidth:v}=xr(),S=pe(G=>G.openContextSurface),N=Rb(G=>G.requestSource),A=!h&&v>=768&&!nr(),k=l.useCallback(()=>{x("github"),g(!0)},[g,x]),C=l.useMemo(()=>Wb(t,e),[t,e]),P=l.useMemo(()=>po.get(C)??null,[C]),D=tn(G=>G.ensureEntry),O=tn(G=>G.setParams),F=tn(G=>G.startWatching),E=tn(G=>G.stopWatching),B=tn(G=>G.refresh),$=tn(G=>G.updateStatus),[z,V]=l.useState(()=>P?.title??Wc(e)),[y,I]=l.useState(()=>P?.body??""),[_,W]=l.useState(()=>P?.draft??!1),[K,Z]=l.useState(()=>P?.additionalContext??""),[Q,le]=l.useState(()=>{const G=typeof P?.targetBaseBranch=="string"?ur(P.targetBaseBranch):"";return G||ur(n)}),[te,he]=l.useState("squash"),[xe,H]=l.useState(!1),[we,de]=l.useState(!1),[q,me]=l.useState(!1),[be,Pe]=l.useState(!1),[Ie,De]=l.useState(!1),[Le,Ne]=l.useState(!1),[ve,Me]=l.useState(null),[ee,oe]=l.useState(""),[Te,J]=l.useState(""),[re,Y]=l.useState(!1),[U,fe]=l.useState(!1),[ne,ce]=l.useState(()=>ba(o,{selectedRemoteName:P?.selectedRemoteName,trackingBranch:r})),[Fe,Ye]=l.useState(!1),{detectedUpstream:$e,upstreamBranches:ie}=Kb(t,u);l.useEffect(()=>{Ye(!1)},[t]);const Re=o.some(G=>G.name==="upstream"),R=!!(t&&e&&n&&(e!==n||(Re||$e!==null))),ae=l.useMemo(()=>zi(t,e,ne?.name??null),[t,e,ne?.name]),Se=tn(G=>G.entries[ae]),Ce=Se?.isLoading??!1,Ee=Se?.status??null,se=Se?.error??null,je=Se?.isInitialStatusResolved??!1,Ze=l.useMemo(()=>{const G=Fe?null:ne?.name?.trim()||null,qe=new Set;for(const It of i){const Dt=Ub(It,G);!Dt||Dt==="HEAD"||qe.add(Dt)}if(Fe)for(const It of ie)It&&It!=="HEAD"&&qe.add(It);const at=ur(n);at&&at!=="HEAD"&&qe.add(at);const pt=ur(Q);return pt&&pt!=="HEAD"&&qe.add(pt),Array.from(qe).sort((It,Dt)=>It.localeCompare(Dt))},[n,i,ne?.name,Q,ie,Fe]);l.useEffect(()=>{if(o.length===0){ne&&ce(null);return}(!ne||!o.some(G=>G.name===ne.name))&&ce(ba(o,{selectedRemoteName:P?.selectedRemoteName,trackingBranch:r}))},[P?.selectedRemoteName,o,ne,r]),l.useEffect(()=>{const G=ur(n);if(!Q&&G){le(G);return}if(Ze.length!==0&&!Ze.includes(Q)){const qe=Ze.includes(G)?G:Ze[0];qe&&le(qe)}},[Ze,n,Q]);const[X,ye]=l.useState(()=>P?.activeSegment??"overview"),[Xe,Be]=l.useState(new Set),[We,_e]=l.useState(new Set),tt=l.useRef(new Set),ct=l.useRef(null),Et=l.useRef(!1),Nt=l.useRef(new Set),Ot=l.useRef([]);l.useEffect(()=>{$e&&!Re&&Ye(!0)},[$e,Re]),l.useEffect(()=>{Fe&&$e?.defaultBranch&&le($e.defaultBranch)},[Fe,$e?.defaultBranch]);const et=Ee?.pr??null,Tt=et?.state==="merged"||et?.state==="closed",xt=Tt?null:et,vt=xt?vf(t,xt.number):null,_t=zc(G=>vt?G.entries[vt]:void 0),Ct=zc(G=>G.ensure),Rt=_t?.result??null,ut=_t?.isLoading??!1,bt=l.useCallback(G=>{ye(G);const qe=po.get(C);qe&&po.set(C,{...qe,activeSegment:G})},[C]);l.useEffect(()=>{!xt||!u?.prContext||X==="overview"||Ct(u,t,xt.number,{includeCheckDetails:X==="checks",sourceRepo:Ee?.repo??null})},[X,t,Ct,u,xt,Ee?.repo]);const He=Ee?.checks??null,Ve=(He?.pending??0)>0,wt=Rt?.checkRuns??null,Ft=Rt?.fetchedAt;l.useEffect(()=>{if(!wt||wt.length===0)return;const G=Bb(wt);$(ae,qe=>{if(!qe?.pr||typeof Ft=="number"&&typeof qe.fetchedAt=="number"&&Ft<qe.fetchedAt)return qe;const at=qe.checks;return at&&at.state===G.state&&at.total===G.total&&at.success===G.success&&at.failure===G.failure&&at.pending===G.pending&&at.inProgress===G.inProgress&&at.queued===G.queued&&at.startedAt===G.startedAt?qe:{...qe,checks:G,...typeof Ft=="number"?{fetchedAt:Ft}:{}}})},[wt,Ft,ae,$]),l.useEffect(()=>{if(X!=="checks"||!Ve||!et||!u?.prContext)return;const G=window.setInterval(()=>{Ct(u,t,et.number,{includeCheckDetails:!0,sourceRepo:Ee?.repo??null,force:!0})},_b);return()=>window.clearInterval(G)},[X,Ve,t,Ct,u,et,Ee?.repo]);const[Lt,ns]=l.useState(()=>Date.now());l.useEffect(()=>{if(!Ve)return;ns(Date.now());const G=window.setInterval(()=>ns(Date.now()),3e4);return()=>window.clearInterval(G)},[Ve]);const $t=et?`${t}#${et.number}`:null,At=!!($t&&ve===$t);l.useEffect(()=>{if(!u?.prContext||!et||typeof et.body=="string"&&et.body.length>0)return;const G=`${t}#${et.number}`;if(tt.current.has(G))return;tt.current.add(G),Me(G);let qe=!1;return Ct(u,t,et.number,{sourceRepo:Ee?.repo??null}).then(at=>{if(qe)return;const pt=at?.pr;pt&&$(ae,It=>!It?.pr||It.pr.number!==et.number?It:{...It,pr:{...It.pr,body:pt.body||""}})}).catch(()=>{}).finally(()=>{qe||Me(at=>at===G?null:at)}),()=>{qe=!0}},[t,Ct,u,et,ae,Ee?.repo,$]),l.useEffect(()=>{if(!et){Ne(!1),oe(""),J(""),ct.current=null;return}const G=ct.current!==null&&ct.current!==et.number;G&&Ne(!1),(!Le||G)&&(oe(et.title||""),J(et.body||"")),ct.current=et.number},[Le,et]);const ss=l.useCallback(G=>{if(!G)return"";const qe=Date.parse(G);return Number.isFinite(qe)?vu(qe,d,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):G},[d]),ms=l.useMemo(()=>{const G=m?.user?.login;return typeof G=="string"?G.trim():""},[m]),zt=l.useMemo(()=>"[&_a[href*='oc-self-mention=1']]:!text-[var(--primary-base)] [&_a[href*='oc-self-mention=1']]:font-semibold [&_a[href*='oc-self-mention=1']]:!no-underline [&_a[href*='oc-self-mention=1']:hover]:!text-[var(--primary-hover)]",[]),qt=l.useCallback(G=>{const qe=ms.toLowerCase(),at=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return G.replace(at,(pt,It,Dt)=>{const yt=`@${Dt}`,cs=Dt.toLowerCase();return`${It}[${yt}](https://github.com/${cs}${qe&&cs===qe?"?oc-self-mention=1":""})`})},[ms]),Ut=l.useMemo(()=>{const G=(Rt?.issueComments??[]).map(pt=>({id:`issue-${pt.id}`,body:pt.body||"",authorName:pt.author?.name||pt.author?.login||a("gitView.pr.comments.unknownAuthor"),authorLogin:pt.author?.login||null,avatarUrl:pt.author?.avatarUrl||null,createdAt:pt.createdAt,context:a("gitView.pr.comments.generalContext"),path:null,line:null})),qe=(Rt?.reviewComments??[]).map(pt=>({id:`review-${pt.id}`,body:pt.body||"",authorName:pt.author?.name||pt.author?.login||a("gitView.pr.comments.unknownAuthor"),authorLogin:pt.author?.login||null,avatarUrl:pt.author?.avatarUrl||null,createdAt:pt.createdAt,context:a("gitView.pr.comments.reviewContext"),path:pt.path||null,line:pt.line??null})),at=[...G,...qe];return at.sort((pt,It)=>{const Dt=pt.createdAt?Date.parse(pt.createdAt):0,yt=It.createdAt?Date.parse(It.createdAt):0,cs=Number.isFinite(Dt)?Dt:0,ws=Number.isFinite(yt)?yt:0;return cs-ws}),at},[Rt,a]),Jt=l.useCallback(()=>{const G=w??(p?"draft":null);return G?{directory:t,sessionKey:G}:(Ae.error(a("gitView.pr.toast.noActiveSession"),{description:a("gitView.pr.toast.noActiveSessionDescription")}),null)},[w,t,p,a]),Oe=l.useCallback((G,qe)=>{const at=qe.authorLogin?`@${qe.authorLogin}`:qe.authorName,pt=qe.path?` · ${qe.path}${qe.line?`:${qe.line}`:""}`:"";Ma.getState().addDraft(G,{source:"pr-comment",fileLabel:`PR #${et?.number??""} ${at}${pt}`,startLine:qe.line??0,endLine:qe.line??0,code:qe.body,language:"markdown",text:""})},[et?.number]),st=l.useCallback((G,qe)=>{const at=G.status||"unknown",pt=G.conclusion??void 0,It=pt?`${at} / ${pt}`:at,Dt=G.app?.name||G.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:qe?.hideHeader?"flex items-start justify-end gap-3":"flex items-start justify-between gap-3",children:[qe?.hideHeader?null:s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:G.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:Dt?`${Dt} · ${It}`:It})]}),G.detailsUrl?s.jsx(lt,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:G.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(T,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),G.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:G.output.title}):null,G.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words",children:G.output.summary}):null,G.output?.text?s.jsx("div",{className:"rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground whitespace-pre-wrap break-words max-h-48 overflow-y-auto",children:G.output.text}):null,Array.isArray(G.annotations)&&G.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",G.annotations.length>20?` (showing 20/${G.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:G.annotations.slice(0,20).map((yt,cs)=>s.jsxs("div",{className:"rounded border border-[var(--status-error-border)] bg-[var(--status-error-background)]/40 px-2 py-2",children:[s.jsxs("div",{className:"typography-micro break-words text-[var(--status-error)]",children:[yt.title||yt.level||"Issue",yt.path?` · ${yt.path}`:"",typeof yt.startLine=="number"?`:${yt.startLine}`:"",typeof yt.endLine=="number"&&yt.endLine!==yt.startLine?`-${yt.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap break-words mt-1",children:yt.message}),yt.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:yt.rawDetails}):null]},`${yt.path||"file"}:${yt.startLine||cs}:${cs}`))})]}):null,G.job?.steps&&G.job.steps.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.checks.steps")}),s.jsx("div",{className:"space-y-1",children:G.job.steps.map((yt,cs)=>{const ws=(yt.conclusion||"").toLowerCase(),Zt=ws&&!["success","neutral","skipped"].includes(ws),ks=`${G.id??"run"}:${G.job?.jobId??"job"}:${yt.number??cs}:${yt.name}`,Ms=Xe.has(ks);return Zt?s.jsxs(Si,{open:Ms,children:[s.jsxs("button",{type:"button",onClick:()=>{Be(Mn=>{const Ss=new Set(Mn);return Ss.has(ks)?Ss.delete(ks):Ss.add(ks),Ss})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(Zt?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[Ms?s.jsx(T,{name:"arrow-down-s",className:"size-4"}):s.jsx(T,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:yt.name}),yt.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:yt.conclusion}):null]}),s.jsx(ji,{children:s.jsxs("div",{className:"ml-6 mt-1 rounded border border-border/40 bg-transparent px-2 py-2 typography-micro text-muted-foreground space-y-1",children:[typeof yt.number=="number"?s.jsxs("div",{children:[a("gitView.pr.checks.stepLabel"),": ",yt.number]}):null,yt.status?s.jsxs("div",{children:[a("gitView.pr.checks.statusLabel"),": ",yt.status]}):null,yt.conclusion?s.jsxs("div",{children:[a("gitView.pr.checks.conclusionLabel"),": ",yt.conclusion]}):null,yt.startedAt?s.jsxs("div",{children:[a("gitView.pr.checks.startedLabel"),": ",ss(yt.startedAt)]}):null,yt.completedAt?s.jsxs("div",{children:[a("gitView.pr.checks.completedLabel"),": ",ss(yt.completedAt)]}):null]})})]},ks):s.jsxs("div",{className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-muted-foreground",children:[s.jsx("span",{className:"truncate",children:yt.name}),yt.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:yt.conclusion}):null]},ks)})})]}):null]})},[Xe,ss,a]),[Ke,Je]=l.useState(!1),[Qe,kt]=l.useState(!1),ts=l.useCallback(async()=>{if(!u?.prContext){Ae.error(a("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!et)return;const G=Jt();if(G){Je(!0);try{const qe=await Ct(u,t,et.number,{includeCheckDetails:!0,sourceRepo:Ee?.repo??null});if(!qe){Ae.error(a("gitView.pr.toast.loadChecksFailed"));return}const pt=(qe.checkRuns??[]).filter(Dt=>xa(Dt.conclusion));if(pt.length===0){Ae.message(a("gitView.pr.toast.noFailedChecks"));return}const It=Ma.getState();for(const Dt of pt){const yt=(Dt.annotations??[]).map(Zt=>[[Zt.level,Zt.title].filter(Boolean).join(" "),Zt.path?`${Zt.path}${typeof Zt.startLine=="number"?`:${Zt.startLine}`:""}`:null,Zt.message,Zt.rawDetails].filter(Boolean).join(`
38
+ `)),cs=(Dt.job?.steps??[]).filter(Zt=>xa(Zt.conclusion)).map(Zt=>`step ${Zt.number??"?"}: ${Zt.name} → ${Zt.conclusion}`),ws=[`check: ${Dt.job?.workflowName?`${Dt.job.workflowName} / ${Dt.name}`:Dt.name}`,`status: ${Dt.status??"unknown"} / ${Dt.conclusion??"unknown"}`,Dt.detailsUrl?`url: ${Dt.detailsUrl}`:null,Dt.output?.title?`title: ${Dt.output.title}`:null,Dt.output?.summary?`summary:
39
+ ${Dt.output.summary}`:null,cs.length>0?`failed steps:
40
+ ${cs.join(`
41
+ `)}`:null,yt.length>0?`annotations:
42
+ ${yt.join(`
43
+ ---
44
+ `)}`:null].filter(Boolean).join(`
45
+
46
+ `);It.addDraft(G,{source:"pr-check",fileLabel:`PR #${et.number} · ${Dt.name}`,startLine:0,endLine:0,code:ws,language:"text",text:""})}j("chat")}catch(qe){const at=qe instanceof Error?qe.message:String(qe);Ae.error(a("gitView.pr.toast.loadChecksFailed"),{description:at})}finally{Je(!1)}}},[t,Ct,u,et,Jt,j,Ee?.repo,a]),Wt=l.useCallback(async()=>{if(!u?.prContext){Ae.error(a("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!et)return;const G=Jt();if(G){kt(!0);try{if(!await Ct(u,t,et.number,{sourceRepo:Ee?.repo??null})){Ae.error(a("gitView.pr.toast.loadPrCommentsFailed"));return}if(Ut.length===0){Ae.message(a("gitView.pr.toast.noPrComments"));return}for(const at of Ut)Oe(G,at);j("chat")}catch(qe){const at=qe instanceof Error?qe.message:String(qe);Ae.error(a("gitView.pr.toast.loadPrCommentsFailed"),{description:at})}finally{kt(!1)}}},[Oe,t,Ct,u,et,Jt,j,Ee?.repo,a,Ut]),us=l.useCallback(async G=>{const qe=Jt();qe&&(Oe(qe,G),j("chat"))},[Oe,Jt,j]),Bt=l.useCallback(async G=>{await B(ae,G)},[ae,B]),Vt=l.useCallback(()=>{Ot.current.forEach(G=>{window.clearTimeout(G)}),Ot.current=zb.map(G=>window.setTimeout(()=>{Bt({force:!0,silent:!0,markInitialResolved:!0})},G))},[Bt]);l.useEffect(()=>{if(!u?.prStatus||!R||o.length<=1||Et.current||Ee?.pr)return;const G=`${C}::${ne?.name??""}`;if(Nt.current.has(G))return;Nt.current.add(G);const qe=Hb(o,r).filter(It=>It.name!==ne?.name);if(qe.length===0)return;let at=!1;return(async()=>{for(const It of qe){if(at)return;try{if(!(await u.prStatus(t,e,It.name))?.pr)continue;if(at)return;ce(yt=>yt?.name===It.name?yt:It);return}catch{}}})(),()=>{at=!0}},[e,R,t,u,o,ne?.name,C,Ee?.pr,r]),l.useEffect(()=>{D(ae),O(ae,{directory:t,branch:e,remoteName:ne?.name??null,canShow:R,github:u,githubAuthChecked:f,githubConnected:m?.connected??null})},[e,R,t,D,u,f,m?.connected,ae,ne?.name,O]),l.useEffect(()=>(F(ae),()=>{E(ae)}),[ae,F,E]),l.useEffect(()=>{const G=po.get(C)??null;V(G?.title??Wc(e)),I(G?.body??""),W(G?.draft??!1),le(G?.targetBaseBranch?ur(G.targetBaseBranch):ur(n));const qe=ba(o,{selectedRemoteName:G?.selectedRemoteName,trackingBranch:r});ce(at=>at?.name===qe?.name?at:qe)},[n,e,o,C,r]),l.useEffect(()=>{Bt({markInitialResolved:!0})},[ae,Bt]),l.useEffect(()=>{!R||!ne?.name||Bt({force:!0,silent:!0,markInitialResolved:!0})},[R,Bt,ne?.name]),l.useEffect(()=>{const G=Ee?.resolvedRemoteName?.trim();if(!G||Et.current)return;const qe=o.find(at=>at.name===G);qe&&ce(at=>at?.name===qe.name?at:qe)},[o,Ee?.resolvedRemoteName]),l.useEffect(()=>{const G=()=>{const at=tn.getState().entries[ae]?.lastRefreshAt??0;Date.now()-at>6e4&&Bt({force:!0,silent:!0})},qe=()=>{document.visibilityState==="visible"&&G()};return window.addEventListener("focus",G),document.addEventListener("visibilitychange",qe),()=>{window.removeEventListener("focus",G),document.removeEventListener("visibilitychange",qe)}},[ae,Bt]),l.useEffect(()=>{f&&m?.connected===!1&&Bt({force:!0,silent:!0,markInitialResolved:!0})},[f,m,Bt]),l.useEffect(()=>{!t||!e||po.set(C,{title:z,body:y,draft:_,additionalContext:K,targetBaseBranch:Q,selectedRemoteName:ne?.name,activeSegment:X})},[C,z,y,_,K,Q,ne?.name,t,e,X]),l.useEffect(()=>{const G=Ot.current;return()=>{G.forEach(qe=>{window.clearTimeout(qe)}),Ot.current=[]}},[]);const js=l.useCallback(async()=>{if(!xe&&t){H(!0);try{const qe={base:Fe&&$e?.defaultBranchSha?$e.defaultBranchSha:Q,head:e};K&&(qe.context=K);const at=await Ah(t,qe);at.title?.trim()&&V(at.title.trim()),at.body?.trim()&&I(at.body.trim()),c?.()}catch(G){const qe=G instanceof Error?G.message:String(G);Ae.error(a("gitView.pr.toast.generateDescriptionFailed"),{description:qe})}finally{H(!1)}}},[K,e,$e?.defaultBranchSha,t,xe,c,Q,a,Fe]),ln=l.useCallback(async()=>{if(!u?.prCreate){Ae.error(a("gitView.pr.toast.githubApiUnavailable"));return}const G=z.trim();if(!G){Ae.error(a("gitView.pr.toast.titleRequired"));return}const qe=Q.trim();if(!qe){Ae.error(a("gitView.pr.toast.baseBranchRequired"));return}if(!Fe&&qe===e){Ae.error(a("gitView.pr.toast.baseMustDifferFromHead"));return}de(!0);try{const at=Cl(r),pt=Fe&&$e,It=await u.prCreate({directory:t,title:G,head:e,base:qe,...y.trim()?{body:y}:{},draft:_,...pt?{targetRepo:{owner:$e.owner,repo:$e.repo},headRemote:"origin"}:{...ne?{remote:ne.name}:{},...at&&at!==ne?.name?{headRemote:at}:{}}});Ae.success(a("gitView.pr.toast.prCreated")),$(ae,Dt=>Dt&&{...Dt,pr:It}),await Bt({force:!0}),Vt()}catch(at){const pt=at instanceof Error?at.message:String(at);Ae.error(a("gitView.pr.toast.createPrFailed"),{description:pt})}finally{de(!1)}},[y,e,$e,t,_,u,ae,Bt,Vt,ne,Q,z,r,$,Fe,a]),Rn=l.useCallback(async G=>{if(!u?.prMerge){Ae.error(a("gitView.pr.toast.githubApiUnavailable"));return}Pe(!0);try{const qe=await u.prMerge({directory:t,number:G.number,method:te});qe.merged?Ae.success(a("gitView.pr.toast.prMerged")):Ae.message(a("gitView.pr.toast.prNotMerged"),{description:qe.message||a("gitView.pr.notMergeable")}),await Bt({force:!0}),Vt()}catch(qe){const at=qe instanceof Error?qe.message:String(qe);Ae.error(a("gitView.pr.toast.mergeFailed"),{description:at}),G.url&&Ho(G.url)}finally{Pe(!1)}},[t,u,te,Bt,Vt,a]),Hn=l.useCallback(async G=>{if(!u?.prReady){Ae.error(a("gitView.pr.toast.githubApiUnavailable"));return}De(!0);try{await u.prReady({directory:t,number:G.number}),Ae.success(a("gitView.pr.toast.markedReady")),await Bt({force:!0}),Vt()}catch(qe){const at=qe instanceof Error?qe.message:String(qe);Ae.error(a("gitView.pr.toast.markReadyFailed"),{description:at}),G.url&&Ho(G.url)}finally{De(!1)}},[t,u,Bt,Vt,a]),cn=l.useCallback(async G=>{if(!u?.prUpdate){Ae.error(a("gitView.pr.toast.githubApiUnavailable"));return}const qe=ee.trim();if(!qe){Ae.error(a("gitView.pr.toast.titleRequired"));return}me(!0);try{const at=await u.prUpdate({directory:t,number:G.number,title:qe,body:Te});$(ae,pt=>pt&&{...pt,pr:{...pt.pr??G,...at}}),Ne(!1),Ae.success(a("gitView.pr.toast.prUpdated")),await Bt({force:!0}),Vt()}catch(at){const pt=at instanceof Error?at.message:String(at);Ae.error(a("gitView.pr.toast.updatePrFailed"),{description:pt})}finally{me(!1)}},[t,Te,ee,u,ae,Bt,Vt,$,a]);if(!R)return s.jsx("section",{className:"border-0 bg-transparent rounded-none",children:s.jsxs("div",{className:"space-y-1 pt-3",children:[s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:a("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pullRequest.availableOnFeatureBranches")})]})});const Cn=Ee?.repo?.url||null,Ts=Fe&&$e?.url?$e.url:Cn,Xs=!!Ee?.canMerge,Kn=!!Ee?.connected,Is=f&&Ee?.connected===!1,_s=$b(Ee),$s=_s?`var(--pr-${_s})`:"var(--status-info)",zs=_s==="draft"?"git-pr-draft":_s==="merged"?"git-merge":_s==="closed"?"git-close-pull-request":"git-pull-request",Us=et?[`${et.state}${et.draft?" (draft)":""}`,et.mergeable===!1?a("gitView.pr.notMergeable"):null,et.state==="open"&&typeof et.mergeableState=="string"&&et.mergeableState&&et.mergeableState!=="unknown"?et.mergeableState:null].filter(Boolean).join(" · "):"",Gn=He?He.total>0?`${He.success}/${He.total} ${a("gitView.pr.checks.label")}`:`${He.state} ${a("gitView.pr.checks.label")}`:"";return s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex flex-col gap-1",children:[s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[et?s.jsxs(lt,{type:"button",variant:"outline",size:"xs",className:"shrink-0",onClick:()=>{Ho(et.url)},"aria-label":a("gitView.pr.actions.openOnGitHubAria"),children:[s.jsx(T,{name:zs,className:"size-4 shrink-0",style:{color:$s}}),a("gitView.pr.actions.openOnGitHub")]}):s.jsx(T,{name:zs,className:"size-4 shrink-0",style:{color:"var(--surface-muted-foreground)"}}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:a("gitView.pullRequest.title")}),et?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",et.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[Ce?s.jsx(T,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-5 items-center justify-center rounded hover:bg-interactive-hover/60 disabled:opacity-40",disabled:Ce,onClick:()=>{Bt({force:!0})},"aria-label":a("gitView.pr.actions.refreshAria"),children:s.jsx(T,{name:"refresh",className:"size-3.5 text-muted-foreground"})})}),s.jsx(ht,{children:s.jsx("p",{children:a("gitView.pr.actions.refresh")})})]})]})]}),et?s.jsxs("div",{className:"@container/pr-actions flex min-w-0 items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1 typography-micro text-muted-foreground",children:[s.jsx("span",{style:{color:$s},children:Us}),He?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${Uc(He.state)}`}),Gn]}):null,r&&ne&&r.split("/")[0]!==ne.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",ne.name]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[A?s.jsxs(lt,{variant:"outline",size:"sm",className:ge("pr-actions__walkthrough-button h-7 shrink-0 gap-1.5 px-2",Mb),onClick:()=>{N(t,{kind:"pr",number:et.number}),S(t,"walkthrough")},"aria-label":a("walkthrough.action.open"),children:[s.jsx(T,{name:"route",className:"size-4"}),s.jsx("span",{className:"pr-actions__walkthrough-label typography-ui-label",children:a("walkthrough.action.open")})]}):null,Xs&&et.draft&&et.state==="open"?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx(lt,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Hn(et),disabled:Ie||be||q||Le,"aria-label":a("gitView.pr.actions.markReadyAria"),children:Ie?s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(T,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(ht,{children:s.jsx("p",{children:a("gitView.pr.actions.markReady")})})]}):null,Xs?s.jsxs(s.Fragment,{children:[s.jsxs(Ks,{value:te,onValueChange:G=>he(G),disabled:be||et.state!=="open",children:[s.jsx(Gs,{size:"sm",className:"h-7 w-auto min-w-0",children:s.jsx(Es,{})}),s.jsxs(qs,{children:[s.jsx(is,{value:"squash",children:a("gitView.pr.mergeMethod.squash")}),s.jsx(is,{value:"merge",children:a("gitView.pr.mergeMethod.merge")}),s.jsx(is,{value:"rebase",children:a("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx(lt,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>Rn(et),disabled:be||Ie||et.state!=="open"||et.draft||q||Le,"aria-label":a("gitView.pr.actions.mergePrAria"),children:be?s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(T,{name:"git-merge",className:"size-4"})})}),s.jsx(ht,{children:s.jsx("p",{children:a("gitView.pr.actions.mergePr")})})]})]}):null]})]}):null]}),s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[Is?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta text-muted-foreground",children:a("gitView.pr.githubNotConnected")}),s.jsx(lt,{variant:"outline",size:"sm",onClick:k,className:"w-fit",children:a("gitView.pr.actions.openSettings")})]}):null,se?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:a("gitView.pr.statusUnavailable")}),s.jsx("div",{className:"typography-meta text-muted-foreground break-words",children:se}),Ts?s.jsx(lt,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:Ts,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(T,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!et&&!je&&!se&&!Is?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.pr.checkingStatus")]}):et&&!Tt?s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("div",{className:"h-8 min-w-0",children:s.jsx(yl,{className:"h-full",items:[{id:"overview",label:a("gitView.pr.segment.overview")},{id:"checks",label:He&&He.total>0?`${a("gitView.pr.segment.checks")} ${He.success}/${He.total}`:a("gitView.pr.segment.checks"),icon:He?s.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${Uc(He.state)}`}):void 0},{id:"comments",label:Rt?`${a("gitView.pr.segment.comments")} ${(Rt.issueComments?.length??0)+(Rt.reviewComments?.length??0)}`:a("gitView.pr.segment.comments")}],activeId:X,onSelect:G=>bt(G),layoutMode:"fit",variant:"active-pill",activePillButtonClassName:"h-7"})}),X==="overview"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[Xs&&et.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.draftMustBeReady")}):null,Xs?null:s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.noMergePermission")}),s.jsxs("div",{className:"flex items-start justify-between gap-2",children:[s.jsx("div",{className:"min-w-0 flex-1",children:Le?s.jsx(tr,{value:ee,onChange:G=>oe(G.target.value),placeholder:a("gitView.pr.placeholder.title"),autoCorrect:b?"on":"off",autoCapitalize:b?"sentences":"off",spellCheck:b}):s.jsx("div",{className:"typography-markdown text-xl font-semibold text-foreground break-words leading-snug",children:et.title})}),et.state==="open"?s.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:Le?s.jsxs(s.Fragment,{children:[s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx(lt,{variant:"outline",size:"sm",className:"h-9 w-9 px-0",onClick:()=>{Ne(!1),oe(et.title||""),J(et.body||"")},disabled:q,"aria-label":a("gitView.pr.actions.cancelEditingAria"),children:s.jsx(T,{name:"close",className:"size-4"})})}),s.jsx(ht,{children:s.jsx("p",{children:a("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx(lt,{size:"sm",className:"h-9 w-9 px-0",onClick:()=>cn(et),disabled:q||!ee.trim(),"aria-label":a("gitView.pr.actions.savePrAria"),children:q?s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(T,{name:"check",className:"size-4"})})}),s.jsx(ht,{children:s.jsx("p",{children:a("gitView.pr.actions.savePr")})})]})]}):s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx(lt,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Ne(!0),"aria-label":a("gitView.pr.actions.editPrAria"),children:s.jsx(T,{name:"edit",className:"size-4"})})}),s.jsx(ht,{children:s.jsx("p",{children:a("gitView.pr.actions.editPr")})})]})}):null]}),Le?s.jsx(Kr,{value:Te,onChange:G=>J(G.target.value),outerClassName:"min-h-[60vh]",placeholder:a("gitView.pr.placeholder.description"),autoCorrect:b?"on":"off",autoCapitalize:b?"sentences":"off",spellCheck:b}):null,Le?null:et.body?.trim()?s.jsx(tc,{content:et.body,className:"typography-markdown-body min-w-0 text-muted-foreground break-words",enableFileReferences:!1}):s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words",children:a(At?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}):null,X==="checks"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[He&&He.total>0?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"flex h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-muted/40",children:[He.success>0?s.jsx("div",{className:"bg-[color:var(--status-success)]",style:{width:`${He.success/He.total*100}%`}}):null,He.failure>0?s.jsx("div",{className:"bg-[color:var(--status-error)]",style:{width:`${He.failure/He.total*100}%`}}):null,He.pending>0?s.jsx("div",{className:"bg-[color:var(--status-warning)]",style:{width:`${He.pending/He.total*100}%`}}):null]}),s.jsxs("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:[He.success,"/",He.total," ",a("gitView.pr.checks.label")]}),(He.inProgress??0)>0?s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 typography-micro text-[var(--status-warning)]",children:[s.jsx(T,{name:"loader-4",className:"size-3.5 animate-spin"}),ga(He.startedAt,void 0,Lt)]}):null]}):null,He?.failure?s.jsxs(lt,{variant:"outline",size:"sm",className:"w-fit gap-1.5 border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)]",onClick:ts,disabled:Ke,"aria-label":a("gitView.pr.actions.resolveFailedChecksAria"),children:[Ke?s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(T,{name:"ai-generate-2",className:"size-4"}),a("gitView.pr.actions.resolveFailedChecks")]}):null,(Rt?.checkRuns?.length??0)>0?s.jsx("div",{className:"flex flex-col gap-1.5",children:(Rt?.checkRuns??[]).map((G,qe)=>{const at=`${G.id??"run"}:${G.name}:${qe}`,pt=G.status==="in_progress",It=G.status==="queued",Dt=xa(G.conclusion),yt=We.has(at),cs=!!(G.output?.title||G.output?.summary||G.output?.text||(G.annotations?.length??0)>0||(G.job?.steps?.length??0)>0||G.detailsUrl),ws=G.job?.workflowName,Zt=pt?ga(G.startedAt,void 0,Lt):ga(G.startedAt,G.completedAt);return s.jsxs("div",{className:ge("rounded-md border border-border/40",Dt&&"border-[var(--status-error-border)]"),children:[s.jsxs("button",{type:"button",disabled:!cs,onClick:()=>{_e(ks=>{const Ms=new Set(ks);return Ms.has(at)?Ms.delete(at):Ms.add(at),Ms})},className:"flex w-full items-center gap-2 px-2.5 py-2 text-left disabled:cursor-default",children:[pt?s.jsx(T,{name:"loader-4",className:"size-4 shrink-0 animate-spin text-[var(--status-warning)]"}):It?s.jsx(T,{name:"time",className:"size-4 shrink-0 text-muted-foreground"}):Dt?s.jsx(T,{name:"close-circle",className:"size-4 shrink-0 text-[var(--status-error)]"}):s.jsx(T,{name:"checkbox-circle",className:"size-4 shrink-0 text-[var(--status-success)]"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:ws&&ws!==G.name?`${ws} / ${G.name}`:G.name}),Zt?s.jsx("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:Zt}):null,cs?s.jsx(T,{name:"arrow-down-s",className:ge("size-4 shrink-0 text-muted-foreground transition-transform",yt&&"rotate-180")}):null]}),yt&&cs?s.jsx("div",{className:"min-w-0 overflow-hidden border-t border-border/40 p-2.5",children:st(G,{hideHeader:!0})}):null]},at)})}):ut?s.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 typography-micro text-muted-foreground",children:[s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.loading.loading")]}):s.jsx("div",{className:"py-6 text-center typography-micro text-muted-foreground",children:a("gitView.pr.checkDetails.empty")})]}):null,X==="comments"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[Ut.length>0?s.jsx("div",{className:"flex items-center justify-end",children:s.jsxs(lt,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)]",onClick:Wt,disabled:Qe,"aria-label":a("gitView.pr.actions.shareCommentsAria"),children:[Qe?s.jsx(T,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(T,{name:"ai-generate-2",className:"size-3.5"}),a("gitView.pr.comments.addAll")]})}):null,Ut.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Ut.map((G,qe)=>{const at=(G.authorName||"?").charAt(0).toUpperCase(),pt=qe===Ut.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[pt?null:s.jsx("div",{className:"absolute left-4 top-[2.375rem] bottom-[0.375rem] w-px bg-border/60"}),s.jsx("div",{className:"absolute left-0 top-0 z-10 flex size-8 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-surface-elevated text-xs text-muted-foreground",children:G.avatarUrl?s.jsx("img",{src:G.avatarUrl,alt:G.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:at})}),s.jsxs("div",{className:"rounded-lg bg-surface-elevated px-3 pt-0 pb-3 space-y-2",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1 typography-micro text-muted-foreground sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-1 sm:gap-y-1",children:[s.jsxs("span",{className:"text-foreground whitespace-nowrap",children:[G.authorName,G.authorLogin&&G.authorLogin!==G.authorName?` · @${G.authorLogin}`:""]}),G.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:ss(G.createdAt)}):null,s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsxs(lt,{variant:"ghost",size:"sm",className:"h-6 px-0 has-[>svg]:px-0 sm:px-2 sm:has-[>svg]:px-2.5 text-[var(--status-success)] hover:bg-[var(--status-success-background)] hover:text-[var(--status-success)] justify-start",onClick:()=>{us(G)},"aria-label":a("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(T,{name:"ai-generate-2",className:"size-3.5"}),a("gitView.pr.actions.sendToAgent")]})}),s.jsx(ht,{children:s.jsx("p",{children:a("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[G.context,G.path?` · ${G.path}`:"",G.line?`:${G.line}`:""]}),s.jsx(tc,{content:qt(G.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",zt].filter(Boolean).join(" "),enableFileReferences:!1})]})]},G.id)})})}):ut&&!Rt?s.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 typography-micro text-muted-foreground",children:[s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.loading.loading")]}):s.jsx("div",{className:"py-6 text-center typography-micro text-muted-foreground",children:a("gitView.pr.comments.empty")})]}):null]}):s.jsxs("div",{className:"flex flex-col gap-3",children:[et&&Tt?s.jsxs("div",{className:"flex min-w-0 items-center gap-2 rounded-md border border-border/60 bg-surface-muted/40 px-2.5 py-2",children:[s.jsx(T,{name:et.state==="merged"?"git-merge":"git-close-pull-request",className:"size-4 shrink-0",style:{color:$s}}),s.jsx("div",{className:"min-w-0 flex-1 typography-micro text-muted-foreground",children:et.state==="merged"?a("gitView.pr.history.merged",{number:et.number,base:et.base||Q}):a("gitView.pr.history.closed",{number:et.number})}),s.jsx(lt,{type:"button",variant:"ghost",size:"xs",className:"shrink-0",onClick:()=>{Ho(et.url)},"aria-label":a("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(T,{name:"external-link",className:"size-3.5"})})]}):null,s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:a("gitView.pr.createTitle")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," ",s.jsx("span",{className:"opacity-60",children:"(local)"})," → ",Q," ",s.jsxs("span",{className:"opacity-60",children:["(",Fe&&$e?"upstream":"remote",")"]})]})]}),Ts?s.jsx(lt,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:Ts,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(T,{name:"external-link",className:"size-4"}),a("gitView.pr.actions.repo")]})}):null]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.field.title")}),s.jsx(tr,{value:z,onChange:G=>V(G.target.value),placeholder:a("gitView.pr.placeholder.title"),autoCorrect:b?"on":"off",autoCapitalize:b?"sentences":"off",spellCheck:b})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.field.baseBranch")}),Ze.length>0?s.jsxs(Ks,{value:Q,onValueChange:le,children:[s.jsx(Gs,{size:"lg",children:s.jsx(Es,{placeholder:a("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(qs,{children:Ze.map(G=>s.jsx(is,{value:G,children:G},G))})]}):s.jsx(tr,{value:Q,onChange:G=>le(G.target.value),placeholder:a("gitView.pr.placeholder.main")})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.field.description")}),s.jsx(Kr,{value:y,onChange:G=>I(G.target.value),className:"min-h-[110px]",placeholder:a("gitView.pr.placeholder.whatChanged"),autoCorrect:b?"on":"off",autoCapitalize:b?"sentences":"off",spellCheck:b})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":_,onClick:()=>W(G=>!G),onKeyDown:G=>{(G.key===" "||G.key==="Enter")&&(G.preventDefault(),W(qe=>!qe))},children:[s.jsx(qr,{size:"sm",checked:_,onChange:G=>W(G),ariaLabel:a("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:a("gitView.pr.field.draft")})]}),h?s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.additionalContext.optional")}),s.jsx(lt,{variant:"outline",size:"sm",onClick:()=>fe(!0),children:K.trim()?a("gitView.pr.actions.edit"):a("gitView.pr.actions.add")})]}),K.trim()&&s.jsx("div",{className:"flex items-center gap-2",children:s.jsx("span",{className:"inline-flex items-center rounded-full bg-[var(--interactive-selection)] px-2 py-0.5 text-xs text-[var(--interactive-selection-foreground)]",children:a("gitView.pr.additionalContext.added")})})]}):s.jsxs(Si,{open:re,onOpenChange:Y,children:[s.jsxs(vl,{className:"flex w-full items-center justify-between rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-3 py-2 hover:bg-[var(--interactive-hover)]",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.additionalContext.optional")}),s.jsx("span",{className:"typography-micro text-[var(--primary-base)]",children:re?a("gitView.pr.actions.hide"):K.trim()?a("gitView.pr.actions.edit"):a("gitView.pr.actions.add")})]}),s.jsx(ji,{children:s.jsxs("div",{className:"mt-2 space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[s.jsx(Kr,{value:K,onChange:G=>Z(G.target.value),className:"min-h-[100px] bg-transparent",placeholder:a("gitView.pr.placeholder.additionalContext")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.additionalContext.hint")})]})})]}),s.jsx(Ui,{open:U,onClose:()=>fe(!1),title:a("gitView.pr.additionalContext.title"),footer:s.jsx(lt,{size:"sm",onClick:()=>fe(!1),className:"w-full",children:a("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(Kr,{value:K,onChange:G=>Z(G.target.value),className:"min-h-[200px] bg-transparent",placeholder:a("gitView.pr.placeholder.additionalContext"),autoFocus:!0}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.additionalContext.hint")})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(lt,{variant:"outline",size:"sm",onClick:js,disabled:xe||we,children:[xe?s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(T,{name:"ai-generate-2",className:"size-4 text-primary"}),a("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(lt,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:ln,disabled:we||!Kn||!Q.trim()||!Fe&&Q.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:we?s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(T,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:a("gitView.pr.actions.createPr")})]})]})]})]})]})},qb=t=>{const{remoteNames:e,localBranches:n,worktreeCreatedFromBranch:r,rootBranchHint:o,defaultBranch:i,headBranch:c}=t,a=typeof c=="string"?c.trim():"",d=x=>{if(!x)return"";let j=x.trim();if(!j||j==="HEAD")return"";if(n.includes(j))return j;j.startsWith("refs/heads/")&&(j=j.slice(11)),j.startsWith("heads/")&&(j=j.slice(6)),j.startsWith("remotes/")&&(j=j.slice(8));const w=j.indexOf("/");if(w>0){const p=j.slice(0,w);if(e.has(p)){const h=j.slice(w+1).trim();h&&(j=h)}}return j},u=x=>{const j=d(typeof x=="string"?x:"");return j&&j!==a?j:""},m=u(r);if(m)return m;const f=u(o);if(f)return f;const g=u(i);return g||(n.includes("main")?"main":n.includes("master")?"master":n.includes("develop")?"develop":"main")},oN=t=>{const{baseBranch:e,localBranches:n,remoteBranches:r}=t;return n.includes(e)?!0:r.some(o=>{const i=o.indexOf("/");return i>0&&o.slice(i+1)===e})},ya=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Ko=new Map,Go=new Map,dr=t=>`${Ps()}::${t}`,Yb=()=>{const t=it.c(86),{t:e}=gt(),{git:n}=rr(),r=Io(),o=dl(r??null),i=wu(r??null),{ensureAll:c}=pr(Jn(Qb)),a=ot(Xb),d=ot(Jb),u=ot(Zb),m=ot(ey);let f;t[0]!==r?(f=ya(r),t[0]=r,t[1]=f):f=t[1];const g=f;let x;if(t[2]!==m||t[3]!==g||t[4]!==u){e:{if(!g){x=void 0;break e}let Ne;if(t[6]!==m||t[7]!==g){let Me;t[9]!==g?(Me=ee=>ya(ee.path)===g,t[9]=g,t[10]=Me):Me=t[10],Ne=m.find(Me),t[6]=m,t[7]=g,t[8]=Ne}else Ne=t[8];const ve=Ne;if(ve){x=ve;break e}for(const Me of u.values())if(ya(Me.path)===g){x=Me;break e}x=void 0}t[2]=m,t[3]=g,t[4]=u,t[5]=x}else x=t[5];const j=x;let w;t[11]!==a||t[12]!==j||t[13]!==d?.open||t[14]!==u?(w=()=>{if(a)return u.get(a)??j;if(d?.open)return j},t[11]=a,t[12]=j,t[13]=d?.open,t[14]=u,t[15]=w):w=t[15],d?.open;let p;t[16]!==w?(p=w(),t[16]=w,t[17]=p):p=t[17];const h=p;let b;t[18]!==a?(b=Ne=>a?Ne.getAttachment(a):void 0,t[18]=a,t[19]=b):b=t[19];const v=pu(b),S=v&&!v.degraded&&!v.legacy?v.worktreeRoot??void 0:void 0,N=kb(r,h,o?.current??void 0);let A,k;t[20]!==r||t[21]!==c||t[22]!==n?(A=()=>{!r||!n||c(r,n)},k=[r,c,n],t[20]=r,t[21]=c,t[22]=n,t[23]=A,t[24]=k):(A=t[23],k=t[24]),l.useEffect(A,k);const[C,P]=l.useState(null);let D;t[25]!==S||t[26]!==N?.projectDirectory?(D=()=>{const Ne=S||N?.projectDirectory;if(!Ne){P(null);return}let ve=!1;return Wi(Ne).then(Me=>{if(ve)return;const ee=Me.trim();P(ee&&ee!=="HEAD"?ee:null)}).catch(()=>{ve||P(null)}),()=>{ve=!0}},t[25]=S,t[26]=N?.projectDirectory,t[27]=D):D=t[27];const O=N?.projectDirectory;let F;t[28]!==S||t[29]!==O?(F=[S,O],t[28]=S,t[29]=O,t[30]=F):F=t[30],l.useEffect(D,F);let E;t[31]!==r?(E=()=>(r?Ko.get(dr(r)):void 0)??[],t[31]=r,t[32]=E):E=t[32];const[B,$]=l.useState(E);let z;t[33]!==r?(z=()=>(r?Go.get(dr(r)):void 0)??null,t[33]=r,t[34]=z):z=t[34];const[V,y]=l.useState(z);let I,_;t[35]!==r||t[36]!==n?(I=()=>{if(!r||!n?.getRemotes){$([]);return}$(Ko.get(dr(r))??[]);let Ne=!1;return n.getRemotes(r).then(ve=>{Ne||(Ko.set(dr(r),ve??[]),$(ve??[]))}).catch(()=>{Ne||$(Ko.get(dr(r))??[])}),()=>{Ne=!0}},_=[r,n],t[35]=r,t[36]=n,t[37]=I,t[38]=_):(I=t[37],_=t[38]),l.useEffect(I,_);let W,K;t[39]!==r||t[40]!==n?(W=()=>{if(!r||!n?.getRemoteUrl){y(null);return}y(Go.get(dr(r))??null);let Ne=!1;return n.getRemoteUrl(r).then(ve=>{Ne||(Go.set(dr(r),ve),y(ve))}).catch(()=>{Ne||y(Go.get(dr(r))??null)}),()=>{Ne=!0}},K=[r,n],t[39]=r,t[40]=n,t[41]=W,t[42]=K):(W=t[41],K=t[42]),l.useEffect(W,K);let Z;e:{if(!i?.all){let ve;t[43]===Symbol.for("react.memo_cache_sentinel")?(ve=[],t[43]=ve):ve=t[43],Z=ve;break e}let Ne;t[44]!==i.all?(Ne=i.all.filter(ty).sort(),t[44]=i.all,t[45]=Ne):Ne=t[45],Z=Ne}const Q=Z;let le;e:{if(!i?.all){let ve;t[46]===Symbol.for("react.memo_cache_sentinel")?(ve=[],t[46]=ve):ve=t[46],le=ve;break e}let Ne;t[47]!==i.all?(Ne=i.all.filter(sy).map(ny).sort(),t[47]=i.all,t[48]=Ne):Ne=t[48],le=Ne}const te=le;let he;t[49]!==te||t[50]!==V||t[51]!==B||t[52]!==o?.tracking?(he=()=>{if(B.length>0)return B;const Ne=new Set,ve=o?.tracking?.trim();ve&&ve.includes("/")&&Ne.add(ve.split("/")[0]);for(const Me of te){const ee=Me.indexOf("/");ee>0&&Ne.add(Me.slice(0,ee))}return Ne.size===0&&V&&Ne.add("origin"),Array.from(Ne).map(Me=>({name:Me,fetchUrl:V??"",pushUrl:V??""}))},t[49]=te,t[50]=V,t[51]=B,t[52]=o?.tracking,t[53]=he):he=t[53],o?.tracking;let xe;t[54]!==he?(xe=he(),t[54]=he,t[55]=xe):xe=t[55];const H=xe,we=o?.current??null;o?.tracking;let de;t[56]!==o?.tracking?(de=o?.tracking?.trim().split("/")[0],t[56]=o?.tracking,t[57]=de):de=t[57];const q=de,me=(q&&i?.defaultBranches?.[q])??i?.defaultBranches?.origin;let be;t[58]!==we||t[59]!==me||t[60]!==H||t[61]!==Q||t[62]!==C||t[63]!==N?.createdFromBranch?(be=()=>qb({remoteNames:new Set(H.map(ry)),localBranches:Q,worktreeCreatedFromBranch:N?.createdFromBranch,rootBranchHint:C,defaultBranch:me,headBranch:we}),t[58]=we,t[59]=me,t[60]=H,t[61]=Q,t[62]=C,t[63]=N?.createdFromBranch,t[64]=be):be=t[64],N?.createdFromBranch;let Pe;t[65]!==be?(Pe=be(),t[65]=be,t[66]=Pe):Pe=t[66];const Ie=Pe;if(!r||!we){let Ne;t[67]===Symbol.for("react.memo_cache_sentinel")?(Ne=s.jsx(T,{name:"git-pull-request",className:"h-12 w-12 text-muted-foreground/50"}),t[67]=Ne):Ne=t[67];let ve;t[68]!==e?(ve=e("gitView.pullRequest.title"),t[68]=e,t[69]=ve):ve=t[69];let Me;t[70]!==ve?(Me=s.jsx("div",{className:"typography-ui-header text-foreground",children:ve}),t[70]=ve,t[71]=Me):Me=t[71];let ee;t[72]!==e?(ee=e("gitView.pullRequest.createHint"),t[72]=e,t[73]=ee):ee=t[73];let oe;t[74]!==ee?(oe=s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:ee}),t[74]=ee,t[75]=oe):oe=t[75];let Te;return t[76]!==Me||t[77]!==oe?(Te=s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[Ne,Me,oe]}),t[76]=Me,t[77]=oe,t[78]=Te):Te=t[78],Te}const De=o?.tracking??void 0;let Le;return t[79]!==Ie||t[80]!==we||t[81]!==r||t[82]!==te||t[83]!==B||t[84]!==De?(Le=s.jsx($n,{as:ul,outerClassName:"h-full min-h-0",className:"px-4 py-3",disableHorizontal:!0,preventOverscroll:!0,children:s.jsx(Gb,{directory:r,branch:we,baseBranch:Ie,trackingBranch:De,remotes:B,remoteBranches:te})}),t[79]=Ie,t[80]=we,t[81]=r,t[82]=te,t[83]=B,t[84]=De,t[85]=Le):Le=t[85],Le};function Qb(t){return{ensureAll:t.ensureAll}}function Xb(t){return t.currentSessionId}function Jb(t){return t.newSessionDraft}function Zb(t){return t.worktreeMetadata}function ey(t){return t.availableWorktrees}function ty(t){return!t.startsWith("remotes/")}function sy(t){return t.startsWith("remotes/")}function ny(t){return t.replace(/^remotes\//,"")}function ry(t){return t.name}const Va=5e3,oy=(t,e)=>{if(!t)return 1;let n=1;for(let r=0;r<t.length;r+=1)if(t.charCodeAt(r)===10&&(n+=1,n>e))return n;return n},qo=(t,e)=>Ih(Rh.getState().dictionary,t,e),iy=t=>{const n=(t instanceof Error?t.message:String(t??"")).toLowerCase();return n.includes("file not found")||n.includes("not found")||n.includes("enoent")||n.includes("no such file")||n.includes("does not exist")?"missing":"unreadable"},ay=async(t,e,n)=>{if(t.readFile)return(await t.readFile(e,{optional:!0,directory:n?.directory})).content??"";const r=new URLSearchParams({path:e,optional:"true"});n?.directory&&r.set("directory",n.directory);const o=await gs(`/api/fs/read?${r.toString()}`,{cache:"no-store",headers:n?.directory?{"x-opencode-directory":n.directory}:void 0});if(!o.ok){const i=await o.json().catch(()=>({error:o.statusText}));throw new Error(i.error||"Failed to read file")}return o.text()},wf=async(t,e,n)=>{if(Dh(e)||Ph(e)||Eh(e))return{ok:!0};try{const r=await ay(t,e,n);return Th(r)?{ok:!1,reason:"binary"}:oy(r,Va)>Va?{ok:!1,reason:"too-large"}:{ok:!0}}catch(r){return{ok:!1,reason:iy(r)}}},Sf=t=>{if(t==="too-large"){const e=Va.toLocaleString(al());return qo("contextFileOpen.failure.tooLarge",{count:e})}return qo(t==="missing"?"contextFileOpen.failure.missing":t==="binary"?"filesView.editor.cannotPreviewBinary":"contextFileOpen.failure.unreadable")},Vc=3,Qr=t=>Array.from(t.types).includes("Files"),ly=t=>{const e=Array.from(t.items);return e.length===0?Array.from(t.files):e.flatMap(n=>{if(n.kind!=="file"||n.webkitGetAsEntry()?.isDirectory)return[];const r=n.getAsFile();return r?[r]:[]})},Hc=t=>{const e=t.name;return!e||e==="."||e===".."||e.includes("/")||e.includes("\\")?null:e},cy=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),ps=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},Nl=(t,e)=>{const n=ps(e),r=ps(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},dy=(t,e)=>{const n=Nl(t,e);if(n!==".")return n;const r=ps(t);return r.split("/").filter(Boolean).pop()??r},uy=t=>{const e=ps(t),n=e.lastIndexOf("/");return n<0?"":n===0?"/":e.slice(0,n)},fy=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),my=new Set(["node_modules"]),hy=t=>my.has(t),py=t=>{const e=ps(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},gy=8,_n=new Map,Al=t=>JSON.stringify([Ps(),t]),xy=t=>{const e=Al(t),n=_n.get(e);return n?(n.touchedAt=Date.now(),_n.delete(e),_n.set(e,n),n):null},va=t=>{const e=Al(t),n=_n.get(e);if(n)return n.touchedAt=Date.now(),n;if(_n.size>=gy){const o=_n.keys().next().value;o!==void 0&&_n.delete(o)}const r={childrenByDir:{},loadErrorsByDir:{},loadedDirs:new Set,touchedAt:Date.now()};return _n.set(e,r),r},by=t=>{_n.delete(Al(t))},jf=(t,e)=>s.jsx(fl,{filePath:t,extension:e}),yy=t=>{const e=it.c(3),{status:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=r):r=e[0];const o=r[n];let i;return e[1]!==o?(i=s.jsx("span",{className:"h-2 w-2 rounded-full",style:{backgroundColor:o}}),e[1]=o,e[2]=i):i=e[2],i},vy=t=>{const e=it.c(84),{node:n,root:r,isExpanded:o,isActive:i,isBrowserClient:c,status:a,badge:d,isDropTarget:u,canUpload:m,permissions:f,downloadFile:g,onSelect:x,onToggle:j,onRevealPath:w,onOpenDialog:p,onSetDropTarget:h,onDropFiles:b}=t,{t:v}=gt(),S=n.type==="directory";let N;e[0]!==S||e[1]!==n.path?(N=S?n.path:uy(n.path),e[0]=S,e[1]=n.path,e[2]=N):N=e[2];const A=N,{canRename:k,canCreateFile:C,canCreateFolder:P,canDelete:D,canReveal:O}=f,F=!S&&!!g,E=O&&!c,B=k||C||P||D||F||E,[$,z]=l.useState(!1),[V,y]=l.useState(!1);let I;e[3]!==B?(I=Y=>{B&&(Y?.preventDefault(),y(!0))},e[3]=B,e[4]=I):I=e[4];const _=I;let W;e[5]!==S||e[6]!==n||e[7]!==x||e[8]!==j?(W=()=>{S?j(n.path):x(n)},e[5]=S,e[6]=n,e[7]=x,e[8]=j,e[9]=W):W=e[9];const K=W;let Z;e[10]===Symbol.for("react.memo_cache_sentinel")?(Z=Y=>{Y.stopPropagation(),y(!1),z(!0)},e[10]=Z):Z=e[10];const Q=Z;let le;e[11]!==C||e[12]!==P||e[13]!==D||e[14]!==k||e[15]!==E||e[16]!==g||e[17]!==c||e[18]!==S||e[19]!==n||e[20]!==p||e[21]!==w||e[22]!==v?(le=Y=>{const{Item:U,Separator:fe}=Y;return s.jsxs(s.Fragment,{children:[k&&s.jsxs(U,{onClick:ne=>{ne.stopPropagation(),p("rename",n)},children:[s.jsx(T,{name:"edit",className:"mr-2 h-4 w-4"})," ",v("sidebarFilesTree.menu.rename")]}),s.jsxs(U,{onClick:ne=>{ne.stopPropagation(),er(n.path).then(ce=>{if(ce.ok){Ae.success(v("sidebarFilesTree.toast.pathCopied"));return}Ae.error(v("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(T,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",v("sidebarFilesTree.menu.copyPath")]}),!S&&g&&s.jsxs(U,{onClick:ne=>{ne.stopPropagation(),g(n.path).catch(ce=>{console.error("Download failed:",ce),Ae.error(v("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(T,{name:"download",className:"mr-2 h-4 w-4"})," ",v(c?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),E&&s.jsxs(U,{onClick:ne=>{ne.stopPropagation(),w(n.path)},children:[s.jsx(T,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",v(cu())]}),S&&(C||P)&&s.jsxs(s.Fragment,{children:[s.jsx(fe,{}),C&&s.jsxs(U,{onClick:ne=>{ne.stopPropagation(),p("createFile",n)},children:[s.jsx(T,{name:"file-add",className:"mr-2 h-4 w-4"})," ",v("sidebarFilesTree.menu.newFile")]}),P&&s.jsxs(U,{onClick:ne=>{ne.stopPropagation(),p("createFolder",n)},children:[s.jsx(T,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",v("sidebarFilesTree.menu.newFolder")]})]}),D&&s.jsxs(s.Fragment,{children:[s.jsx(fe,{}),s.jsxs(U,{onClick:ne=>{ne.stopPropagation(),p("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(T,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",v("sidebarFilesTree.menu.delete")]})]})]})},e[11]=C,e[12]=P,e[13]=D,e[14]=k,e[15]=E,e[16]=g,e[17]=c,e[18]=S,e[19]=n,e[20]=p,e[21]=w,e[22]=v,e[23]=le):le=e[23];const te=le;let he;e[24]!==n.path||e[25]!==r?(he=Y=>{const U=Nl(r,n.path);!U||U==="."||(Y.dataTransfer.setData("application/x-openchamber-file-path",U),Y.dataTransfer.effectAllowed="copy")},e[24]=n.path,e[25]=r,e[26]=he):he=e[26];const xe=he;let H;e[27]!==m||e[28]!==h||e[29]!==A?(H=Y=>{!m||!A||!Qr(Y.dataTransfer)||(Y.preventDefault(),Y.stopPropagation(),Y.dataTransfer.dropEffect="copy",h(A))},e[27]=m,e[28]=h,e[29]=A,e[30]=H):H=e[30];const we=H;let de;e[31]!==m||e[32]!==h||e[33]!==A?(de=Y=>{!m||!A||!Qr(Y.dataTransfer)||Y.relatedTarget instanceof Node&&Y.currentTarget.contains(Y.relatedTarget)||(Y.stopPropagation(),h(null))},e[31]=m,e[32]=h,e[33]=A,e[34]=de):de=e[34];const q=de;let me;e[35]!==m||e[36]!==b||e[37]!==A?(me=Y=>{!m||!A||!Qr(Y.dataTransfer)||(Y.preventDefault(),Y.stopPropagation(),b(A,Y.dataTransfer))},e[35]=m,e[36]=b,e[37]=A,e[38]=me):me=e[38];const be=me;let Pe;e[39]!==_||e[40]!==q||e[41]!==we||e[42]!==be?(Pe=s.jsx("div",{className:"group relative flex items-center",onContextMenu:_,onDragEnter:we,onDragOver:we,onDragLeave:q,onDrop:be}),e[39]=_,e[40]=q,e[41]=we,e[42]=be,e[43]=Pe):Pe=e[43];const Ie=u?"bg-interactive-selection ring-2 ring-inset ring-primary":i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let De;e[44]!==Ie?(De=ge("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",Ie,"cursor-grab active:cursor-grabbing"),e[44]=Ie,e[45]=De):De=e[45];let Le;e[46]!==S||e[47]!==o||e[48]!==n.extension||e[49]!==n.path?(Le=S?o?s.jsx(T,{name:"folder-open",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):s.jsx(T,{name:"folder-3",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):jf(n.path,n.extension),e[46]=S,e[47]=o,e[48]=n.extension,e[49]=n.path,e[50]=Le):Le=e[50];let Ne;e[51]!==n.name||e[52]!==n.path?(Ne=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[51]=n.name,e[52]=n.path,e[53]=Ne):Ne=e[53];let ve;e[54]!==S||e[55]!==a?(ve=!S&&a&&s.jsx(yy,{status:a}),e[54]=S,e[55]=a,e[56]=ve):ve=e[56];let Me;e[57]!==d||e[58]!==S?(Me=S&&d&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[d.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",d.modified]}),d.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",d.added]})]}),e[57]=d,e[58]=S,e[59]=Me):Me=e[59];let ee;e[60]!==_||e[61]!==xe||e[62]!==K||e[63]!==De||e[64]!==Le||e[65]!==Ne||e[66]!==ve||e[67]!==Me?(ee=s.jsxs("button",{type:"button",onClick:K,onContextMenu:_,draggable:!0,onDragStart:xe,className:De,children:[Le,Ne,ve,Me]}),e[60]=_,e[61]=xe,e[62]=K,e[63]=De,e[64]=Le,e[65]=Ne,e[66]=ve,e[67]=Me,e[68]=ee):ee=e[68];let oe;e[69]!==$||e[70]!==B||e[71]!==te||e[72]!==v?(oe=B&&s.jsx("div",{className:"absolute right-1 top-1/2 -translate-y-1/2 opacity-0 focus-within:opacity-100 group-hover:opacity-100",children:s.jsxs(jn,{open:$,onOpenChange:z,children:[s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(wn,{asChild:!0,children:s.jsx(lt,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:Q,title:v("sidebarFilesTree.actions.fileMenuTitle"),"aria-label":v("sidebarFilesTree.actions.fileMenuTitle"),children:s.jsx(T,{name:"more-2-fill",className:"h-4 w-4"})})})})}),s.jsx(ht,{side:"bottom",sideOffset:6,children:v("sidebarFilesTree.actions.fileMenuTitle")})]}),s.jsx(Sn,{align:"end",side:"bottom",onCloseAutoFocus:()=>z(!1),children:te({Item:Xt,Separator:vn})})]})}),e[69]=$,e[70]=B,e[71]=te,e[72]=v,e[73]=oe):oe=e[73];let Te;e[74]!==Pe||e[75]!==ee||e[76]!==oe?(Te=s.jsxs(Ku,{render:Pe,children:[ee,oe]}),e[74]=Pe,e[75]=ee,e[76]=oe,e[77]=Te):Te=e[77];let J;e[78]!==te?(J=s.jsx(Vu,{className:"min-w-[180px]",children:te({Item:Hu,Separator:Ig})}),e[78]=te,e[79]=J):J=e[79];let re;return e[80]!==V||e[81]!==Te||e[82]!==J?(re=s.jsxs(Gu,{open:V,onOpenChange:y,children:[Te,J]}),e[80]=V,e[81]=Te,e[82]=J,e[83]=re):re=e[83],re},wy=(t,e)=>t.node===e.node&&t.root===e.root&&t.isExpanded===e.isExpanded&&t.isActive===e.isActive&&t.isBrowserClient===e.isBrowserClient&&t.status===e.status&&t.badge===e.badge&&t.isDropTarget===e.isDropTarget&&t.canUpload===e.canUpload&&t.permissions===e.permissions&&t.downloadFile===e.downloadFile&&t.onSelect===e.onSelect&&t.onToggle===e.onToggle&&t.onRevealPath===e.onRevealPath&&t.onOpenDialog===e.onOpenDialog&&t.onSetDropTarget===e.onSetDropTarget&&t.onDropFiles===e.onDropFiles,Sy=l.memo(vy,wy),jy=()=>{const{t}=gt(),{files:e,runtime:n}=rr(),r=_m(n.platform),o=Io()??"",i=ps(o.trim()),c=$m(),a=zm(),d=iu(X=>X.searchFiles),u=pe(X=>X.openContextFile),m=dl(o),[f,g]=l.useState(""),x=ml(f,200),j=l.useRef(null),[w,p]=l.useState([]),[h,b]=l.useState(!1),[v,S]=l.useState(null),[N,A]=l.useState(!1),[k,C]=l.useState(null),P=l.useRef(!1),D=l.useRef(i);D.current=i;const[O,F]=l.useState({}),[E,B]=l.useState({}),$=l.useRef(new Set),z=l.useRef(new Set),V=l.useRef(null);l.useEffect(()=>{if(S(null),C(null),!i){F({}),B({}),$.current=new Set;return}const X=xy(i);X?(F({...X.childrenByDir}),B({...X.loadErrorsByDir}),$.current=new Set(X.loadedDirs)):(F({}),B({}),$.current=new Set)},[i]),l.useEffect(()=>{if(!i)return;const X=va(i);X.childrenByDir=O},[i,O]),l.useEffect(()=>{if(!i)return;const X=va(i);X.loadErrorsByDir=E},[i,E]),l.useEffect(()=>{if(!i)return;const X=va(i);X.loadedDirs=new Set($.current)},[i,O,E]),l.useEffect(()=>()=>{if(!i)return;const X=_n.get(i);X&&X.loadedDirs.size===0&&Object.keys(X.childrenByDir).length===0&&by(i)},[i]);const y=l.useMemo(()=>[],[]),I=l.useMemo(()=>[],[]),_=Bn(X=>i?X.byRoot[i]?.expandedPaths??y:y),W=Bn(X=>i?X.byRoot[i]?.selectedPath??null:null),K=Bn(X=>X.setSelectedPath),Z=Bn(X=>X.addOpenPath),Q=Bn(X=>X.removeOpenPathsByPrefix),le=Bn(X=>X.toggleExpandedPath),te=Bn(X=>X.collapseAllExpandedPaths),he=pe(X=>i?X.contextPanelByDirectory[i]?.tabs??I:I),xe=l.useMemo(()=>new Set(he.map(X=>X.mode==="file"?X.targetPath:null).filter(X=>typeof X=="string"&&X.length>0).map(X=>ps(X))),[he]),[H,we]=l.useState(null),[de,q]=l.useState(null),[me,be]=l.useState(""),[Pe,Ie]=l.useState(!1),De=!!e.writeFile,Le=!!e.createDirectory,Ne=!!e.rename,ve=!!e.delete,Me=!!e.revealPath,ee=!!e.uploadFile,oe=l.useMemo(()=>({canRename:Ne,canCreateFile:De,canCreateFolder:Le,canDelete:ve,canReveal:Me}),[Ne,De,Le,ve,Me]),Te=l.useCallback(X=>{e.revealPath&&e.revealPath(X).catch(()=>{Ae.error(t("sidebarFilesTree.toast.revealFailed"))})},[e,t]),J=l.useCallback((X,ye)=>{we(X),q(ye),be(X==="rename"&&ye.name||""),Ie(!1)},[]),re=l.useCallback((X,ye)=>{const Xe=ye.filter(Be=>Be&&typeof Be.name=="string"&&Be.name.length>0).filter(Be=>c||!Be.name.startsWith(".")).filter(Be=>a||!hy(Be.name)).map(Be=>{const We=Be.name,_e=ps(Be.path||""),tt=_e?fy(_e)?_e:ps(`${X}/${_e}`):ps(`${X}/${We}`),ct=Be.isDirectory?"directory":"file",Et=ct==="file"&&We.includes(".")?We.split(".").pop()?.toLowerCase():void 0;return{name:We,path:tt,type:ct,extension:Et}});return cy(Xe)},[a,c]),Y=l.useCallback(async(X,ye)=>{const Xe=ps(X.trim());if(!Xe||$.current.has(Xe)||z.current.has(Xe))return;z.current=new Set(z.current),z.current.add(Xe);const Be=e.listDirectory?e.listDirectory(Xe).then(We=>We.entries.map(_e=>({name:_e.name,path:_e.path,isDirectory:_e.isDirectory}))):sn.listLocalDirectory(Xe).then(We=>We.map(_e=>({name:_e.name,path:_e.path,isDirectory:_e.isDirectory})));try{const We=await Be;if(ye?.())return;const _e=re(Xe,We);$.current=new Set($.current),$.current.add(Xe),B(tt=>{if(!tt[Xe])return tt;const ct={...tt};return delete ct[Xe],ct}),F(tt=>({...tt,[Xe]:_e}))}catch(We){if(ye?.())return;const _e=We instanceof Error?We.message:String(We??"");console.error("Failed to load sidebar directory:",We),B(tt=>({...tt,[Xe]:_e}))}finally{z.current=new Set(z.current),z.current.delete(Xe)}},[e,re]),U=l.useCallback(async()=>{if(!i)return;V.current?.abort();const X=new AbortController;V.current=X;try{const Xe=(Bn.getState().byRoot[i]?.expandedPaths??[]).map(_e=>ps(_e)).filter(_e=>!!_e&&_e!==i&&_e.startsWith(`${i}/`)),Be=[i,...Xe];$.current=new Set($.current);for(const _e of Be)$.current.delete(_e);B(_e=>{if(Object.keys(_e).length===0)return _e;const tt={..._e};let ct=!1;for(const Et of Be)Et in tt&&(delete tt[Et],ct=!0);return ct?tt:_e});const We=()=>X.signal.aborted;await Y(i,We);for(let _e=0;_e<Xe.length&&!X.signal.aborted;_e+=3){const tt=Xe.slice(_e,_e+3);await Promise.all(tt.map(ct=>Y(ct,We)))}}catch(ye){if(X.signal.aborted)return;console.error("Failed to refresh sidebar tree:",ye)}finally{V.current===X&&(V.current=null)}},[Y,i]),fe=l.useCallback(async X=>{if(!X){await U();return}const ye=ps(X);$.current=new Set($.current),$.current.delete(ye),z.current=new Set(z.current),z.current.delete(ye),await Y(ye)},[Y,U]);l.useEffect(()=>{i&&(V.current?.abort(),$.current=new Set,z.current=new Set,B({}),F(X=>Object.keys(X).length===0?X:{}),Y(i))},[Y,i,c,a]),l.useEffect(()=>{if(!i||_.length===0)return;const X=_.map(Be=>ps(Be)).filter(Be=>!!Be&&Be!==i&&Be.startsWith(`${i}/`)&&!$.current.has(Be)&&!z.current.has(Be)).sort((Be,We)=>Be.split("/").length-We.split("/").length);if(X.length===0)return;let ye=!1;const Xe=()=>ye;return(async()=>{for(let Be=0;Be<X.length&&!ye;Be+=3){const We=X.slice(Be,Be+3);await Promise.all(We.map(_e=>Y(_e,Xe)))}})(),()=>{ye=!0}},[_,Y,i]),l.useEffect(()=>{if(!o){p([]),b(!1);return}const X=x.trim();if(!X){p([]),b(!1);return}let ye=!1;return b(!0),d(o,X,150,{includeHidden:c,respectGitignore:!a,type:"file"}).then(Xe=>{if(ye)return;const We=Xe.filter(_e=>a||!py(_e.path)).map(_e=>({name:_e.name,path:ps(_e.path),type:"file",extension:_e.extension,relativePath:_e.relativePath}));p(We)}).catch(()=>{ye||p([])}).finally(()=>{ye||b(!1)}),()=>{ye=!0}},[o,x,d,c,a]);const ne=l.useMemo(()=>{const X=new Map;if(!m?.files)return X;for(const ye of m.files)ye.index==="A"||ye.working_dir==="?"?X.set(ye.path,"git-added"):ye.index==="D"?X.set(ye.path,"git-deleted"):(ye.index==="M"||ye.working_dir==="M")&&X.set(ye.path,"git-modified");return X},[m]),ce=l.useMemo(()=>{const X=new Map;if(!m?.files||!i)return X;for(const ye of m.files){const Xe=ye.index==="M"||ye.working_dir==="M",Be=ye.index==="A"||ye.working_dir==="?";if(!Xe&&!Be)continue;const We=ye.path.split("/");if(We.length<=1)continue;let _e=i;for(let tt=0;tt<We.length-1;tt++){_e=`${_e}/${We[tt]}`;let ct=X.get(_e);ct||(ct={modified:0,added:0},X.set(_e,ct)),Xe&&ct.modified++,Be&&ct.added++}}return X},[m,i]),Fe=l.useCallback(X=>{if(xe.has(X))return"open";if(ne.size===0)return null;const ye=X.startsWith(i+"/")?X.slice(i.length+1):X;return ne.get(ye)??null},[xe,ne,i]),Ye=l.useCallback(X=>{if(ce.size===0)return null;const ye=ce.get(X);return ye&&ye.modified+ye.added>0?ye:null},[ce]),$e=l.useCallback(async X=>{if(!i)return;const ye=await wf(e,X.path,{directory:i});if(!ye.ok){Ae.error(Sf(ye.reason));return}K(i,X.path),Z(i,X.path),u(i,X.path)},[Z,e,u,i,K]),ie=l.useCallback(async X=>{const ye=ps(X);i&&(le(i,ye),$.current.has(ye)||await Y(ye))},[Y,i,le]),Re=l.useCallback(async(X,ye,Xe=!1)=>{const Be=e.uploadFile;if(!Be||ye.length===0||P.current||!i)return;const We=i,_e=Ps();P.current=!0,A(!0),S(X),Xe&&C(null);const tt=[];for(let Tt=0;Tt<ye.length;Tt+=Vc){const xt=ye.slice(Tt,Tt+Vc),vt=await Promise.all(xt.map(async _t=>{const Ct=Hc(_t);if(!Ct||Ps()!==_e)return"failed";try{return(await Be(ps(`${X}/${Ct}`),_t,{directory:We,overwrite:Xe})).success?"uploaded":"failed"}catch(Rt){return!Xe&&Um(Rt)&&Rt.reason==="already-exists"?"conflict":"failed"}}));tt.push(...vt)}const ct=tt.filter(Tt=>Tt==="uploaded").length,Et=tt.filter(Tt=>Tt==="failed").length,Nt=ye.filter((Tt,xt)=>tt[xt]==="conflict"),Ot=ye.flatMap((Tt,xt)=>{const vt=Hc(Tt);return tt[xt]==="uploaded"&&vt?[ps(`${X}/${vt}`)]:[]}),et=D.current===We&&Ps()===_e;try{Ot.length>0&&Qg({runtimeKey:_e,paths:Ot}),ct>0&&et&&await fe(X),ct>0&&Ae.success(t(Nt.length>0?"sidebarFilesTree.toast.uploadedWithoutConflicts":"sidebarFilesTree.toast.uploaded")),Et>0&&Ae.error(t("sidebarFilesTree.toast.uploadFailed")),Nt.length>0&&et&&C({directory:X,files:Nt,runtimeKey:_e,workspaceRoot:We})}finally{P.current=!1,A(!1),S(null)}},[e.uploadFile,fe,i,t]),ue=l.useCallback((X,ye)=>{const Xe=ly(ye);Xe.length!==0&&Re(X,Xe)},[Re]),R=l.useCallback(X=>{!ee||P.current||!i||!Qr(X.dataTransfer)||(X.preventDefault(),X.dataTransfer.dropEffect="copy",S(i))},[ee,i]),ae=l.useCallback(X=>{Qr(X.dataTransfer)&&(X.relatedTarget instanceof Node&&X.currentTarget.contains(X.relatedTarget)||S(null))},[]),Se=l.useCallback(X=>{!ee||P.current||!i||!Qr(X.dataTransfer)||(X.preventDefault(),ue(i,X.dataTransfer))},[ee,ue,i]),Ce=l.useCallback(async X=>{if(X?.preventDefault(),!de||!H)return;Ie(!0);const ye=()=>Ie(!1),Xe=()=>we(null);if(H==="createFile"){if(!me.trim()){Ae.error(t("sidebarFilesTree.toast.filenameRequired")),ye();return}if(!e.writeFile){Ae.error(t("sidebarFilesTree.toast.writeNotSupported")),ye();return}const Be=de.path,We=Be?`${Be}/`:"",_e=ps(`${We}${me.trim()}`);await e.writeFile(_e,"").then(async tt=>{tt.success&&(Ae.success(t("sidebarFilesTree.toast.fileCreated")),await fe(Be)),Xe()}).catch(()=>Ae.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ye);return}if(H==="createFolder"){if(!me.trim()){Ae.error(t("sidebarFilesTree.toast.folderNameRequired")),ye();return}const Be=de.path,We=Be?`${Be}/`:"",_e=ps(`${We}${me.trim()}`);await e.createDirectory(_e).then(async tt=>{tt.success&&(Ae.success(t("sidebarFilesTree.toast.folderCreated")),await fe(Be)),Xe()}).catch(()=>Ae.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ye);return}if(H==="rename"){if(!me.trim()){Ae.error(t("sidebarFilesTree.toast.nameRequired")),ye();return}if(!e.rename){Ae.error(t("sidebarFilesTree.toast.renameNotSupported")),ye();return}const Be=de.path,We=Be.split("/").slice(0,-1).join("/"),_e=We?`${We}/`:"",tt=ps(`${_e}${me.trim()}`);await e.rename(Be,tt).then(async ct=>{ct.success&&(Ae.success(t("sidebarFilesTree.toast.renamedSuccessfully")),await fe(We),i&&Q(i,Be),(W===Be||W&&W.startsWith(`${Be}/`))&&K(i,null)),Xe()}).catch(()=>Ae.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ye);return}if(H==="delete"){if(!e.delete){Ae.error(t("sidebarFilesTree.toast.deleteNotSupported")),ye();return}const Be=de.path,We=Be.split("/").slice(0,-1).join("/");await e.delete(Be).then(async _e=>{_e.success&&(Ae.success(t("sidebarFilesTree.toast.deletedSuccessfully")),await fe(We),i&&Q(i,Be),(W===Be||W&&W.startsWith(Be+"/"))&&K(i,null)),Xe()}).catch(()=>Ae.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ye);return}ye()},[H,de,me,e,fe,Q,i,W,K,t]);function Ee(X,ye){const Xe=O[X]??[];return Xe.map((Be,We)=>{const _e=Be.type==="directory",tt=_e&&_.includes(Be.path),ct=W===Be.path,Et=We===Xe.length-1;return s.jsxs("li",{className:"relative",children:[ye>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),Et&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(Sy,{node:Be,root:i,isExpanded:tt,isActive:ct,isBrowserClient:r,status:_e?void 0:Fe(Be.path),badge:_e?Ye(Be.path):void 0,isDropTarget:_e&&v===Be.path,canUpload:ee&&!N,permissions:oe,downloadFile:e.downloadFile,onSelect:$e,onToggle:ie,onRevealPath:Te,onOpenDialog:J,onSetDropTarget:S,onDropFiles:ue}),_e&&tt&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[E[Be.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:E[Be.path],children:E[Be.path]}),s.jsxs(lt,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{fe(Be.path)},children:[s.jsx(T,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):null,Ee(Be.path,ye+1)]})]},Be.path)})}const se=!!(i&&O[i]),je=i?E[i]:null,Ze=v?dy(i,v):"";return s.jsxs("section",{className:"flex h-full min-h-0 flex-col overflow-hidden",children:[s.jsxs("div",{className:"flex flex-col gap-2 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-end gap-2",children:[De&&s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(lt,{variant:"ghost",size:"sm",onClick:()=>J("createFile",{path:o,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.newFileTitle"),"aria-label":t("sidebarFilesTree.actions.newFileTitle"),children:s.jsx(T,{name:"file-add",className:"h-4 w-4"})})})}),s.jsx(ht,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFileTitle")})]}),Le&&s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(lt,{variant:"ghost",size:"sm",onClick:()=>J("createFolder",{path:o,type:"directory"}),className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.newFolderTitle"),"aria-label":t("sidebarFilesTree.actions.newFolderTitle"),children:s.jsx(T,{name:"folder-add",className:"h-4 w-4"})})})}),s.jsx(ht,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFolderTitle")})]}),s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(lt,{variant:"ghost",size:"sm",onClick:()=>{U()},className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.refreshTitle"),"aria-label":t("sidebarFilesTree.actions.refreshTitle"),children:s.jsx(T,{name:"refresh",className:"h-4 w-4"})})})}),s.jsx(ht,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.refreshTitle")})]}),s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(lt,{variant:"ghost",size:"sm",onClick:()=>{i&&te(i)},className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.collapseAllTitle"),"aria-label":t("sidebarFilesTree.actions.collapseAllTitle"),children:s.jsx(T,{name:"collapse-vertical",className:"h-4 w-4"})})})}),s.jsx(ht,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.collapseAllTitle")})]})]}),s.jsxs("div",{className:"relative min-w-0",children:[s.jsx(T,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),s.jsx(tr,{ref:j,value:f,onChange:X=>g(X.target.value),placeholder:t("sidebarFilesTree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),f.trim().length>0?s.jsx("button",{type:"button","aria-label":t("sidebarFilesTree.search.clearAria"),className:"absolute right-2 top-2 inline-flex h-4 w-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{g(""),j.current?.focus()},children:s.jsx(T,{name:"close",className:"h-4 w-4"})}):null]})]}),s.jsxs("div",{className:"relative flex-1 min-h-0",children:[s.jsx($n,{outerClassName:"h-full min-h-0",className:ge("p-2",v===i&&"bg-interactive-selection/10"),onDragEnter:R,onDragOver:R,onDragLeave:ae,onDrop:Se,children:s.jsx("ul",{className:"flex flex-col",children:h?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(T,{name:"loader-4",className:"h-4 w-4 animate-spin"}),t("sidebarFilesTree.state.searching")]}):w.length>0?w.map(X=>{const ye=W===X.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>$e(X),draggable:!0,onDragStart:Xe=>{const Be=X.relativePath||Nl(i??"",X.path);!Be||Be==="."||(Xe.dataTransfer.setData("application/x-openchamber-file-path",Be),Xe.dataTransfer.effectAllowed="copy")},className:ge("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors cursor-grab active:cursor-grabbing",ye?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:X.path,children:[jf(X.path,X.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:X.relativePath??X.path})]})},X.path)}):je?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{children:je}),s.jsxs(lt,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{U()},children:[s.jsx(T,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):se&&i?Ee(i,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:t("sidebarFilesTree.state.loading")})})}),v?s.jsxs("div",{className:"pointer-events-none absolute left-2 right-2 top-2 z-50 flex items-center gap-2 rounded-md border border-primary bg-background/95 px-2 py-1.5 shadow-sm",children:[s.jsx(T,{name:N?"loader-4":"folder-received",className:ge("size-4 flex-shrink-0",N&&"animate-spin")}),s.jsx("span",{className:"min-w-0 truncate typography-meta",title:Ze,children:t(N?"sidebarFilesTree.drop.uploading":"sidebarFilesTree.drop.target",{path:Ze})})]}):null]}),s.jsx(Ls,{open:!!k,onOpenChange:X=>!X&&C(null),children:s.jsxs(Bs,{children:[s.jsxs(kn,{children:[s.jsx(nn,{children:t("sidebarFilesTree.dialog.uploadConflicts.title")}),s.jsx(rn,{children:t("sidebarFilesTree.dialog.uploadConflicts.description",{path:k?.directory??""})})]}),s.jsx($n,{outerClassName:"max-h-52",className:"flex flex-col gap-1 pr-2",children:k?.files.map((X,ye)=>s.jsx("div",{className:"truncate rounded-md bg-muted px-2 py-1 typography-meta",title:X.name,children:X.name},`${X.name}-${X.size}-${ye}`))}),s.jsxs(sr,{children:[s.jsx(lt,{variant:"outline",onClick:()=>C(null),disabled:N,children:t("sidebarFilesTree.dialog.cancel")}),s.jsx(lt,{onClick:()=>{if(k){if(k.runtimeKey!==Ps()||k.workspaceRoot!==i){C(null);return}Re(k.directory,k.files,!0)}},disabled:N,children:t("sidebarFilesTree.dialog.uploadConflicts.replace")})]})]})}),s.jsx(Ls,{open:!!H,onOpenChange:X=>!X&&we(null),children:s.jsxs(Bs,{children:[s.jsxs(kn,{children:[s.jsxs(nn,{children:[H==="createFile"&&t("sidebarFilesTree.dialog.createFile.title"),H==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.title"),H==="rename"&&t("sidebarFilesTree.dialog.rename.title"),H==="delete"&&t("sidebarFilesTree.dialog.delete.title")]}),s.jsxs(rn,{children:[H==="createFile"&&t("sidebarFilesTree.dialog.createFile.description",{path:de?.path??t("sidebarFilesTree.dialog.rootFallback")}),H==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.description",{path:de?.path??t("sidebarFilesTree.dialog.rootFallback")}),H==="rename"&&t("sidebarFilesTree.dialog.rename.description",{name:de?.name??""}),H==="delete"&&t("sidebarFilesTree.dialog.delete.description",{name:de?.name??""})]})]}),H!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(tr,{value:me,onChange:X=>be(X.target.value),placeholder:t(H==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:X=>{X.key==="Enter"&&Ce()},autoFocus:!0})}),s.jsxs(sr,{children:[s.jsx(lt,{variant:"outline",onClick:()=>we(null),disabled:Pe,children:t("sidebarFilesTree.dialog.cancel")}),s.jsx(lt,{variant:H==="delete"?"destructive":"default",onClick:()=>{Ce()},disabled:Pe||H!=="delete"&&!me.trim(),children:Pe?s.jsx(T,{name:"loader-4",className:"size-4 animate-spin"}):t(H==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm")})]})]})})]})},Kc=60,ky=t=>{try{return new URL(t).origin}catch{return""}},wa=new Set,kf=br()((t,e)=>({byOrigin:{},resolve:(n,r)=>{const o=ky(n);!o||!r||e().byOrigin[o]||wa.has(o)||(wa.add(o),vo("desktop_browser_fetch_favicon",{url:r}).then(i=>{const c=typeof i?.dataUrl=="string"?i.dataUrl:"";c&&t(a=>{const d={...a.byOrigin,[o]:c},u=Object.keys(d);if(u.length<=Kc)return{byOrigin:d};for(const m of u.slice(0,u.length-Kc))delete d[m];return{byOrigin:d}})}).catch(()=>{}).finally(()=>{wa.delete(o)}))}})),Dl=t=>t,Ha=t=>{const e=Dl(t).type;return typeof e=="string"?e:""},Cy=t=>{const e=Dl(t).tool;return typeof e=="string"?e:""},Ny=t=>{const e=Dl(t).text;return typeof e=="string"?e:""},Ay=t=>{const e=Ha(t);return e==="tool"?Cy(t).trim().toLowerCase()||"tool":e||"unknown"},Dy=t=>{if(t.length===0)return"";const e=[];for(const n of t){const r=Ay(n);e.includes(r)||e.push(r)}return e.join(" + ")},Py=t=>t.replace(/\s+/g," ").trim(),Ey=t=>{for(const n of t)if(Ha(n)==="text"){const r=Py(Ny(n));if(r.length===0)continue;return r}const e=t.filter(n=>Ha(n)!=="text").length;return e===0?"":`${e} attachment${e===1?"":"s"}`},Ty=(t,e,n)=>`${n(t)} / ${n(e)}`,Iy=t=>{if(t==="12h")return!0;if(t==="24h")return!1},Ry=(t,e)=>{if(!t||!Number.isFinite(t))return"-";const n=Iy(e);return new Date(t).toLocaleString(void 0,{month:"numeric",day:"numeric",hour:n===!1?"2-digit":"numeric",minute:"2-digit",...n===void 0?{}:{hour12:n}})},Ka={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},di={user:0,assistant:0,tool:0,other:0},fr=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,Sa=t=>{const e=t.info.tokens,n=e!==void 0?e:t.parts.find(m=>m.tokens!==void 0)?.tokens;if(typeof n=="number")return{...Ka,total:fr(n)};if(!n||typeof n!="object")return Ka;const r=n,o=fr(r.input),i=fr(r.output),c=fr(r.reasoning),a=fr(r.cache?.read),d=fr(r.cache?.write),u=fr(r.total);return{input:o,output:i,reasoning:c,cacheRead:a,cacheWrite:d,total:u>0?u:o+i+c+a+d}},My=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},en=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+en(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+en(n),0):0,Oy=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...di,assistant:en(n.text)+en(n.content)};const o=My(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:en(n.input)+en(n.output)+en(n.error)+en(n.call?.input)+en(n.call?.output)+en(n.call?.error)+en(n.raw)+Math.round(en(n.metadata)*.25)+Math.round(en(n.state)*.1),other:0}:e==="user"?{user:o.length,assistant:0,tool:0,other:0}:e==="assistant"?{user:0,assistant:o.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:o.length}},Gc=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),Fy=t=>{const e=Ro(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},Ly=(t,e)=>{if(t.length===0)return{...di};const n=t.reduce((r,o)=>{const i=Fy(o);let c={...di};for(const a of o.parts)c=Gc(c,Oy(a,i));return Gc(r,c)},{...di});return n.user+=e.length,{user:Math.ceil(n.user/4),assistant:Math.ceil(n.assistant/4),tool:Math.ceil(n.tool/4),other:Math.ceil(n.other/4)}},Rr=t=>t.toLocaleString(al()),By=(t,e)=>!t||!Number.isFinite(t)?"-":vu(t,e,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),_y=(t,e,n)=>{const r=t.find(i=>i.id===e),o=r?.models?.find(i=>i.id===n);return{providerName:r?.name||e||"-",modelName:o?.name||n||"-",contextLimit:typeof o?.limit?.context=="number"?o.limit.context:null}},$y=()=>{const t=it.c(203),{t:e}=gt(),n=pe(zy);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r={},t[0]=r):r=t[0];const[o,i]=l.useState(r),[c,a]=l.useState(null),d=l.useRef(null),u=ot(Uy),m=ot(Wy),f=Su(m??void 0),g=Mh(u??"",m??void 0),x=Kt(Vy);let j;t[1]===Symbol.for("react.memo_cache_sentinel")?(j=()=>{d.current!==null&&(window.clearTimeout(d.current),d.current=null),i(Hy),a(null)},t[1]=j):j=t[1];let w;t[2]!==m||t[3]!==u?(w=[m,u],t[2]=m,t[3]=u,t[4]=w):w=t[4],l.useEffect(j,w);let p,h;t[5]===Symbol.for("react.memo_cache_sentinel")?(p=()=>()=>{d.current!==null&&(window.clearTimeout(d.current),d.current=null)},h=[],t[5]=p,t[6]=h):(p=t[5],h=t[6]),l.useEffect(p,h);let b;t[7]===Symbol.for("react.memo_cache_sentinel")?(b=async(ut,bt)=>{(await er(bt)).ok?(a(ut),d.current!==null&&window.clearTimeout(d.current),d.current=window.setTimeout(()=>{a(Ve=>Ve===ut?null:Ve),d.current=null},2e3)):a(null)},t[7]=b):b=t[7];const v=b;let S;t[8]!==u||t[9]!==f?(S=u?f.find(ut=>ut.id===u)??null:null,t[8]=u,t[9]=f,t[10]=S):S=t[10];const N=S;let A,k,C,P,D,O;if(t[11]!==x||t[12]!==g){A=g.filter(Ky);let ut;t[19]!==g?(ut=g.filter(Gy),t[19]=g,t[20]=ut):ut=t[20],O=ut;let bt=null;for(let Ve=A.length-1;Ve>=0;Ve=Ve-1,Ve){const wt=A[Ve];if(Sa(wt).total>0){bt=wt;break}}P=bt?Sa(bt):Ka,k=Oh({input:P.input,cache:{read:P.cacheRead,write:P.cacheWrite}}),D=A.reduce(qy,0);const He=bt?.info??null;C=_y(x,He?.providerID||"",He?.modelID||""),t[11]=x,t[12]=g,t[13]=A,t[14]=k,t[15]=C,t[16]=P,t[17]=D,t[18]=O}else A=t[13],k=t[14],C=t[15],P=t[16],D=t[17],O=t[18];const F=C,E=F.contextLimit,B=E&&E>0?Math.min(999,P.total/E*100):0;let $;if(t[21]!==g){const ut=[...g].reverse().find(Yy)?.info?.system||"";$=Ly(g,ut),t[21]=g,t[22]=$}else $=t[22];const z=$,V=z.user,y=z.assistant,I=z.tool,_=Math.max(0,P.input-V-y-I),W=V+y+I+_,K=g[0]?.info?.time?.created,Z=g.length>0?g[g.length-1]?.info?.time?.created:null;let Q;t[23]!==N?.title||t[24]!==e?(Q=N?.title||e("contextSidebar.session.untitled"),t[23]=N?.title,t[24]=e,t[25]=Q):Q=t[25];const le=N?.time?.created??K??null,te=Z??N?.time?.created??null;let he;t[26]!==y||t[27]!==_||t[28]!==I||t[29]!==V?(he={user:V,assistant:y,tool:I,other:_},t[26]=y,t[27]=_,t[28]=I,t[29]=V,t[30]=he):he=t[30];let xe;t[31]!==A.length||t[32]!==W||t[33]!==k||t[34]!==E||t[35]!==F||t[36]!==g.length||t[37]!==le||t[38]!==te||t[39]!==he||t[40]!==Q||t[41]!==P||t[42]!==D||t[43]!==B||t[44]!==O.length?(xe={sessionTitle:Q,messagesCount:g.length,userMessagesCount:O.length,assistantMessagesCount:A.length,createdAt:le,lastActivityAt:te,providerModel:F,tokenBreakdown:P,usagePercent:B,cacheHitRate:k,totalAssistantCost:D,contextLimit:E,breakdown:he,breakdownTotal:W},t[31]=A.length,t[32]=W,t[33]=k,t[34]=E,t[35]=F,t[36]=g.length,t[37]=le,t[38]=te,t[39]=he,t[40]=Q,t[41]=P,t[42]=D,t[43]=B,t[44]=O.length,t[45]=xe):xe=t[45];const H=xe;if(!u){let ut;t[46]!==e?(ut=e("contextSidebar.empty.openSession"),t[46]=e,t[47]=ut):ut=t[47];let bt;return t[48]!==ut?(bt=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:ut}),t[48]=ut,t[49]=bt):bt=t[49],bt}let we;t[50]!==e?(we=e("contextSidebar.breakdown.user"),t[50]=e,t[51]=we):we=t[51];let de;t[52]!==we||t[53]!==H.breakdown.user?(de={key:"user",label:we,value:H.breakdown.user,color:"var(--status-success)"},t[52]=we,t[53]=H.breakdown.user,t[54]=de):de=t[54];let q;t[55]!==e?(q=e("contextSidebar.breakdown.assistant"),t[55]=e,t[56]=q):q=t[56];let me;t[57]!==q||t[58]!==H.breakdown.assistant?(me={key:"assistant",label:q,value:H.breakdown.assistant,color:"var(--primary-base)"},t[57]=q,t[58]=H.breakdown.assistant,t[59]=me):me=t[59];let be;t[60]!==e?(be=e("contextSidebar.breakdown.toolCalls"),t[60]=e,t[61]=be):be=t[61];let Pe;t[62]!==be||t[63]!==H.breakdown.tool?(Pe={key:"tool",label:be,value:H.breakdown.tool,color:"var(--status-warning)"},t[62]=be,t[63]=H.breakdown.tool,t[64]=Pe):Pe=t[64];let Ie;t[65]!==e?(Ie=e("contextSidebar.breakdown.other"),t[65]=e,t[66]=Ie):Ie=t[66];let De;t[67]!==Ie||t[68]!==H.breakdown.other?(De={key:"other",label:Ie,value:H.breakdown.other,color:"var(--surface-muted-foreground)"},t[67]=Ie,t[68]=H.breakdown.other,t[69]=De):De=t[69];let Le;t[70]!==de||t[71]!==me||t[72]!==Pe||t[73]!==De?(Le=[de,me,Pe,De],t[70]=de,t[71]=me,t[72]=Pe,t[73]=De,t[74]=Le):Le=t[74];const Ne=Le;let ve;t[75]!==H.sessionTitle?(ve=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:H.sessionTitle}),t[75]=H.sessionTitle,t[76]=ve):ve=t[76];let Me;t[77]!==H.providerModel.modelName||t[78]!==H.providerModel.providerName?(Me=s.jsxs("span",{children:[H.providerModel.providerName," / ",H.providerModel.modelName]}),t[77]=H.providerModel.modelName,t[78]=H.providerModel.providerName,t[79]=Me):Me=t[79];let ee;t[80]!==n||t[81]!==H.createdAt?(ee=H.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:By(H.createdAt,n)})]}),t[80]=n,t[81]=H.createdAt,t[82]=ee):ee=t[82];let oe;t[83]!==Me||t[84]!==ee?(oe=s.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 typography-micro text-muted-foreground/70",children:[Me,ee]}),t[83]=Me,t[84]=ee,t[85]=oe):oe=t[85];let Te;t[86]!==ve||t[87]!==oe?(Te=s.jsxs("div",{className:"mb-6",children:[ve,oe]}),t[86]=ve,t[87]=oe,t[88]=Te):Te=t[88];let J;t[89]!==e?(J=e("contextSidebar.section.context"),t[89]=e,t[90]=J):J=t[90];let re;t[91]!==J?(re=s.jsx("span",{className:"typography-micro text-muted-foreground",children:J}),t[91]=J,t[92]=re):re=t[92];let Y;t[93]!==H.tokenBreakdown.total?(Y=Rr(H.tokenBreakdown.total),t[93]=H.tokenBreakdown.total,t[94]=Y):Y=t[94];let U;t[95]!==H.contextLimit?(U=H.contextLimit?` / ${Rr(H.contextLimit)}`:"",t[95]=H.contextLimit,t[96]=U):U=t[96];let fe;t[97]!==Y||t[98]!==U?(fe=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[Y,U]}),t[97]=Y,t[98]=U,t[99]=fe):fe=t[99];let ne;t[100]!==re||t[101]!==fe?(ne=s.jsxs("div",{className:"flex items-baseline justify-between",children:[re,fe]}),t[100]=re,t[101]=fe,t[102]=ne):ne=t[102];let ce;t[103]!==H.usagePercent?(ce=H.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,H.usagePercent)}%`,backgroundColor:H.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[103]=H.usagePercent,t[104]=ce):ce=t[104];let Fe;t[105]!==ce?(Fe=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:ce}),t[105]=ce,t[106]=Fe):Fe=t[106];let Ye;t[107]!==e||t[108]!==H.usagePercent?(Ye=e("contextSidebar.context.percentUsed",{percent:H.usagePercent.toFixed(1)}),t[107]=e,t[108]=H.usagePercent,t[109]=Ye):Ye=t[109];let $e;t[110]!==Ye?($e=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:Ye}),t[110]=Ye,t[111]=$e):$e=t[111];let ie;t[112]!==ne||t[113]!==Fe||t[114]!==$e?(ie=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[ne,Fe,$e]}),t[112]=ne,t[113]=Fe,t[114]=$e,t[115]=ie):ie=t[115];let Re;t[116]!==e?(Re=e("contextSidebar.stats.messages"),t[116]=e,t[117]=Re):Re=t[117];let ue;t[118]!==H.messagesCount?(ue=Rr(H.messagesCount),t[118]=H.messagesCount,t[119]=ue):ue=t[119];let R;t[120]!==Re||t[121]!==ue?(R={label:Re,value:ue},t[120]=Re,t[121]=ue,t[122]=R):R=t[122];let ae;t[123]!==e?(ae=e("contextSidebar.stats.user"),t[123]=e,t[124]=ae):ae=t[124];let Se;t[125]!==H.userMessagesCount?(Se=Rr(H.userMessagesCount),t[125]=H.userMessagesCount,t[126]=Se):Se=t[126];let Ce;t[127]!==ae||t[128]!==Se?(Ce={label:ae,value:Se},t[127]=ae,t[128]=Se,t[129]=Ce):Ce=t[129];let Ee;t[130]!==e?(Ee=e("contextSidebar.stats.assistant"),t[130]=e,t[131]=Ee):Ee=t[131];let se;t[132]!==H.assistantMessagesCount?(se=Rr(H.assistantMessagesCount),t[132]=H.assistantMessagesCount,t[133]=se):se=t[133];let je;t[134]!==Ee||t[135]!==se?(je={label:Ee,value:se},t[134]=Ee,t[135]=se,t[136]=je):je=t[136];let Ze;t[137]!==e?(Ze=e("contextSidebar.stats.cost"),t[137]=e,t[138]=Ze):Ze=t[138];let X;t[139]!==H.totalAssistantCost?(X=Yg(H.totalAssistantCost),t[139]=H.totalAssistantCost,t[140]=X):X=t[140];let ye;t[141]!==Ze||t[142]!==X?(ye={label:Ze,value:X},t[141]=Ze,t[142]=X,t[143]=ye):ye=t[143];let Xe;t[144]!==R||t[145]!==Ce||t[146]!==je||t[147]!==ye?(Xe=[R,Ce,je,ye],t[144]=R,t[145]=Ce,t[146]=je,t[147]=ye,t[148]=Xe):Xe=t[148];const Be=Xe;let We;t[149]!==Be?(We=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:Be.map(Qy)}),t[149]=Be,t[150]=We):We=t[150];let _e;t[151]!==e?(_e=e("contextSidebar.section.lastAssistantMessage"),t[151]=e,t[152]=_e):_e=t[152];let tt;t[153]!==_e?(tt=s.jsx("div",{className:"typography-micro text-muted-foreground mb-2.5",children:_e}),t[153]=_e,t[154]=tt):tt=t[154];let ct;t[155]!==e||t[156]!==H.cacheHitRate.hasInput||t[157]!==H.cacheHitRate.percent||t[158]!==H.tokenBreakdown.cacheRead||t[159]!==H.tokenBreakdown.cacheWrite||t[160]!==H.tokenBreakdown.input||t[161]!==H.tokenBreakdown.output||t[162]!==H.tokenBreakdown.reasoning?(ct=s.jsx("div",{className:"grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:H.tokenBreakdown.input,format:"count"},{label:e("contextSidebar.tokens.output"),value:H.tokenBreakdown.output,format:"count"},{label:e("contextSidebar.tokens.reasoning"),value:H.tokenBreakdown.reasoning,format:"count"},{label:e("contextSidebar.tokens.cacheRead"),value:H.tokenBreakdown.cacheRead,format:"count"},{label:e("contextSidebar.tokens.cacheWrite"),value:H.tokenBreakdown.cacheWrite,format:"count"},{label:e("contextSidebar.tokens.cacheHit"),value:H.cacheHitRate.hasInput?H.cacheHitRate.percent:null,format:"percent"}].map(Xy)}),t[155]=e,t[156]=H.cacheHitRate.hasInput,t[157]=H.cacheHitRate.percent,t[158]=H.tokenBreakdown.cacheRead,t[159]=H.tokenBreakdown.cacheWrite,t[160]=H.tokenBreakdown.input,t[161]=H.tokenBreakdown.output,t[162]=H.tokenBreakdown.reasoning,t[163]=ct):ct=t[163];let Et;t[164]!==tt||t[165]!==ct?(Et=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[tt,ct]}),t[164]=tt,t[165]=ct,t[166]=Et):Et=t[166];let Nt;t[167]!==Ne||t[168]!==H.breakdownTotal?(Nt=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:Ne.map(ut=>ut.value<=0||H.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${ut.value/H.breakdownTotal*100}%`,backgroundColor:ut.color}},ut.key))}),t[167]=Ne,t[168]=H.breakdownTotal,t[169]=Nt):Nt=t[169];let Ot;t[170]!==Ne||t[171]!==H.breakdownTotal?(Ot=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:Ne.map(ut=>{const bt=H.breakdownTotal>0?ut.value/H.breakdownTotal*100:0;return s.jsxs("div",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:ut.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[ut.label," ",s.jsxs("span",{className:"tabular-nums",children:[bt.toFixed(0),"%"]})]})]},ut.key)})}),t[170]=Ne,t[171]=H.breakdownTotal,t[172]=Ot):Ot=t[172];let et;t[173]!==Nt||t[174]!==Ot?(et=s.jsxs("div",{className:"mb-6",children:[Nt,Ot]}),t[173]=Nt,t[174]=Ot,t[175]=et):et=t[175];let Tt;t[176]!==e?(Tt=e("contextSidebar.section.rawMessages"),t[176]=e,t[177]=Tt):Tt=t[177];let xt;t[178]!==Tt?(xt=s.jsx("div",{className:"typography-micro text-muted-foreground",children:Tt}),t[178]=Tt,t[179]=xt):xt=t[179];let vt;if(t[180]!==c||t[181]!==o||t[182]!==g||t[183]!==e||t[184]!==n){let ut;t[186]!==c||t[187]!==o||t[188]!==e||t[189]!==n?(ut=bt=>{const Ve=Ro(bt.info).role,wt=Ve==="assistant",Ft=Ve==="user",Lt=o[bt.info.id]===!0,ns=c===bt.info.id,$t=bt.info.time?.created??null,At=Dy(bt.parts),ss=wt?Sa({info:bt.info,parts:bt.parts}):null,ms=Ft?Ey(bt.parts):"",zt=Ry($t,n),qt=At||"—",Ut=ss?Ty(ss.input,ss.output,Rr):"",Jt=Ve||"unknown",Oe=At?`${Jt}: ${At}`:Jt,st=Lt?JSON.stringify({info:bt.info,parts:bt.parts},null,2):"";return s.jsxs("div",{className:"overflow-hidden rounded-lg bg-[var(--surface-elevated)]/70",children:[s.jsx("button",{type:"button",className:"w-full cursor-pointer px-3 py-1.5 text-left hover:bg-[var(--interactive-hover)]","aria-expanded":Lt,onClick:()=>{i(Ke=>({...Ke,[bt.info.id]:Ke[bt.info.id]!==!0}))},children:s.jsxs("div",{className:"grid items-center gap-x-2 whitespace-nowrap typography-micro",style:{gridTemplateColumns:wt?"minmax(0, 1fr) 7.5rem max-content":"minmax(0, 1fr) max-content"},children:[Ft?s.jsxs("span",{className:"min-w-0 truncate text-muted-foreground",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"user:"})," ",ms]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"min-w-0 truncate text-muted-foreground",children:wt?qt:Oe}),wt&&s.jsx("span",{className:"text-right text-muted-foreground tabular-nums",children:Ut})]}),s.jsx("span",{className:"text-right text-muted-foreground",children:zt})]})}),Lt&&s.jsx("div",{className:"border-t border-[var(--surface-subtle)] p-0",children:s.jsxs("div",{className:"group relative max-h-[26rem] w-full overflow-auto bg-[var(--surface-background)]",children:[s.jsx("div",{className:"absolute top-1 right-2 z-10 opacity-0 transition-opacity group-hover:opacity-100",children:s.jsx("button",{type:"button",className:"rounded p-1 text-muted-foreground transition-colors hover:bg-interactive-hover/60 hover:text-foreground",onClick:Ke=>{Ke.stopPropagation(),v(bt.info.id,st)},"aria-label":e(ns?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(ns?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:ns?s.jsx(T,{name:"check",className:"size-3.5"}):s.jsx(T,{name:"file-copy",className:"size-3.5"})})}),s.jsx(Fh,{language:"json",code:st,style:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},wrap:!0})]})})]},bt.info.id)},t[186]=c,t[187]=o,t[188]=e,t[189]=n,t[190]=ut):ut=t[190],vt=[...g].reverse().map(ut),t[180]=c,t[181]=o,t[182]=g,t[183]=e,t[184]=n,t[185]=vt}else vt=t[185];let _t;t[191]!==vt?(_t=s.jsx("div",{className:"mt-2.5 space-y-1",children:vt}),t[191]=vt,t[192]=_t):_t=t[192];let Ct;t[193]!==xt||t[194]!==_t?(Ct=s.jsxs("div",{children:[xt,_t]}),t[193]=xt,t[194]=_t,t[195]=Ct):Ct=t[195];let Rt;return t[196]!==Te||t[197]!==ie||t[198]!==We||t[199]!==Et||t[200]!==et||t[201]!==Ct?(Rt=s.jsx("div",{className:"h-full overflow-y-auto bg-background",children:s.jsxs("div",{className:"mx-auto w-full max-w-[52rem] px-5 py-6",children:[Te,ie,We,Et,et,Ct]})}),t[196]=Te,t[197]=ie,t[198]=We,t[199]=Et,t[200]=et,t[201]=Ct,t[202]=Rt):Rt=t[202],Rt};function zy(t){return t.timeFormatPreference}function Uy(t){return t.currentSessionId}function Wy(t){return t.currentSessionDirectory}function Vy(t){return t.providers}function Hy(t){return Object.keys(t).length>0?{}:t}function Ky(t){return Ro(t.info).role==="assistant"}function Gy(t){return Ro(t.info).isUser}function qy(t,e){const n=fr(e.info.cost);return t+n}function Yy(t){return Ro(t.info).isUser&&typeof t.info.system=="string"}function Qy(t){return s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 px-3 py-2.5",children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:t.value})]},t.label)}function Xy(t){return s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:t.label}),s.jsx("div",{className:"mt-0.5 typography-ui-label tabular-nums text-foreground",children:t.value!==null&&t.value!==void 0?t.format==="percent"?`${t.value.toFixed(1)}%`:Rr(t.value):"—"})]},t.label)}const Cf=new Set(["localhost","127.0.0.1","0.0.0.0","::1","[::1]"]),Jy=t=>{const e=t.split("/")[0]?.split("?")[0]??"",n=e.startsWith("[")?e.slice(0,e.indexOf("]")+1):e.split(":")[0]??"";return Cf.has(n.toLowerCase())},yn="about:blank",Xr=t=>{const e=t.trim();if(!e)return yn;const n=e.includes("://")?e:`${Jy(e)?"http":"https"}://${e}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?yn:r.toString()}catch{return yn}},no=t=>{try{return Cf.has(new URL(t).hostname.toLowerCase())}catch{return!1}},Pl=t=>{if(!t||t===yn)return"";try{return new URL(t).host||t}catch{return t}},Zy=new Set([-2,-7,-101,-102,-104,-109,-118,-324]),ev=(t,e)=>Zy.has(t)&&no(e),tv=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.port=="number"&&Number.isFinite(e.port)&&typeof e.url=="string"&&e.url.length>0&&typeof e.command=="string"},sv=async t=>{try{const e=await gs("/api/dev-servers",{signal:t});if(!e.ok)return{kind:"unavailable"};const n=await e.json();if(!n||typeof n!="object")return{kind:"unavailable"};const r=n.servers;return Array.isArray(r)?{kind:"ready",servers:r.filter(tv)}:{kind:"unavailable"}}catch{return{kind:"unavailable"}}},nv=async t=>{try{const e=await gs("/api/system/probe-url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:t})});if(!e.ok)return null;const n=await e.json();if(!n||typeof n!="object")return null;const r=n.status;return typeof r=="number"&&Number.isFinite(r)?r:null}catch{return null}},rv=t=>{try{const e=new URL(t),n=Number.parseInt(e.port||(e.protocol==="https:"?"443":"80"),10);return Number.isInteger(n)&&n>0?n:null}catch{return null}},ov=({announced:t,discovered:e})=>{const n=new Map;for(const r of t){const o=rv(r);o!==null&&!n.has(o)&&n.set(o,r)}return e?e.map(r=>{const o=n.get(r.port);return{url:o??r.url,port:r.port,announced:o!==void 0}}).sort((r,o)=>r.announced!==o.announced?r.announced?-1:1:r.port-o.port):[...n.entries()].map(([r,o])=>({url:o,port:r,announced:!0})).sort((r,o)=>r.port-o.port)},Ga="__openchamberBrowserAnnotationActive",iv=`(() => {
47
+ try {
48
+ var host = document.querySelector('[data-openchamber-annotation]');
49
+ if (host && host.parentNode) host.parentNode.removeChild(host);
50
+ } catch (error) { /* page navigated away */ }
51
+ try {
52
+ var cursor = document.getElementById('openchamber-annotation-cursor');
53
+ if (cursor && cursor.parentNode) cursor.parentNode.removeChild(cursor);
54
+ } catch (error) { /* page navigated away */ }
55
+ try { delete window['${Ga}']; } catch (error) { /* non-configurable */ }
56
+ })();`,av=(t,e)=>{const n=JSON.stringify({theme:t,labels:e});return String.raw`new Promise((resolve) => {
57
+ var CONFIG = ${n};
58
+ var THEME = CONFIG.theme;
59
+ var LABELS = CONFIG.labels;
60
+ var OVERLAY_ATTR = 'data-openchamber-annotation';
61
+ var Z_OVERLAY = 2147483646;
62
+ var MAX_TEXT = 400;
63
+ var MIN_RECT = 3;
64
+ var EDITOR_GAP = 10;
65
+
66
+ try {
67
+ var stale = document.querySelector('[' + OVERLAY_ATTR + ']');
68
+ if (stale && stale.parentNode) stale.parentNode.removeChild(stale);
69
+ } catch (error) { /* nothing to clean */ }
70
+
71
+ window['${Ga}'] = true;
72
+
73
+ var counter = 0;
74
+ var nextId = function (prefix) { counter += 1; return prefix + '-' + counter; };
75
+
76
+ var selected = null;
77
+ var regions = [];
78
+ var strokes = [];
79
+ var tool = 'select';
80
+ var settled = false;
81
+
82
+ // ---------------------------------------------------------------- geometry
83
+
84
+ var rectFrom = function (domRect) {
85
+ return { x: domRect.left, y: domRect.top, width: domRect.width, height: domRect.height };
86
+ };
87
+ var normalizeRect = function (ax, ay, bx, by) {
88
+ return { x: Math.min(ax, bx), y: Math.min(ay, by), width: Math.abs(bx - ax), height: Math.abs(by - ay) };
89
+ };
90
+ var usableRect = function (rect) { return rect.width >= MIN_RECT && rect.height >= MIN_RECT; };
91
+
92
+ // ------------------------------------------------------------- description
93
+
94
+ var isOverlayNode = function (element) {
95
+ var node = element;
96
+ while (node) {
97
+ if (node.nodeType === 1 && node.hasAttribute && node.hasAttribute(OVERLAY_ATTR)) return true;
98
+ node = node.parentNode || (node.host || null);
99
+ }
100
+ return false;
101
+ };
102
+
103
+ var elementFromPoint = function (x, y) {
104
+ var found = document.elementFromPoint(x, y);
105
+ if (!found || isOverlayNode(found)) return null;
106
+ return found;
107
+ };
108
+
109
+ var selectorPart = function (element) {
110
+ var part = element.tagName.toLowerCase();
111
+ if (element.id) return part + '#' + element.id;
112
+ var className = typeof element.className === 'string' ? element.className.trim() : '';
113
+ if (className) {
114
+ var first = className.split(/\s+/).filter(Boolean).slice(0, 2).join('.');
115
+ if (first) part += '.' + first;
116
+ }
117
+ return part;
118
+ };
119
+
120
+ var buildSelector = function (element) {
121
+ if (element.id) return '#' + element.id;
122
+ var parts = [];
123
+ var node = element;
124
+ var depth = 0;
125
+ while (node && node.nodeType === 1 && depth < 5) {
126
+ var part = selectorPart(node);
127
+ var parent = node.parentElement;
128
+ if (parent) {
129
+ var siblings = Array.prototype.filter.call(parent.children, function (child) {
130
+ return child.tagName === node.tagName;
131
+ });
132
+ if (siblings.length > 1) part += ':nth-of-type(' + (siblings.indexOf(node) + 1) + ')';
133
+ }
134
+ parts.unshift(part);
135
+ if (node.id) break;
136
+ node = parent;
137
+ depth += 1;
138
+ }
139
+ return parts.join(' > ');
140
+ };
141
+
142
+ var INTERESTING_ATTRS = ['id', 'class', 'name', 'type', 'href', 'src', 'alt', 'title', 'role', 'placeholder', 'aria-label', 'data-testid'];
143
+ var STYLE_PROPS = [
144
+ 'display', 'position', 'color', 'backgroundColor', 'fontSize', 'fontWeight', 'fontFamily',
145
+ 'lineHeight', 'padding', 'margin', 'border', 'borderRadius', 'width', 'height', 'opacity',
146
+ 'zIndex', 'flexDirection', 'justifyContent', 'alignItems', 'gap', 'textAlign'
147
+ ];
148
+
149
+ var describe = function (element) {
150
+ var computed = window.getComputedStyle(element);
151
+ var attributes = {};
152
+ for (var i = 0; i < INTERESTING_ATTRS.length; i += 1) {
153
+ var name = INTERESTING_ATTRS[i];
154
+ var value = element.getAttribute(name);
155
+ if (value) attributes[name] = String(value).slice(0, 200);
156
+ }
157
+ var computedStyle = {};
158
+ for (var j = 0; j < STYLE_PROPS.length; j += 1) {
159
+ var prop = STYLE_PROPS[j];
160
+ computedStyle[prop] = String(computed[prop] == null ? '' : computed[prop]);
161
+ }
162
+ var ancestry = [];
163
+ var node = element.parentElement;
164
+ var depth = 0;
165
+ while (node && node.nodeType === 1 && depth < 4) {
166
+ var entry = { tag: node.tagName.toLowerCase(), selectorPart: selectorPart(node) };
167
+ if (node.id) entry.id = node.id;
168
+ var cls = typeof node.className === 'string' ? node.className.trim() : '';
169
+ if (cls) entry.className = cls.slice(0, 200);
170
+ ancestry.unshift(entry);
171
+ node = node.parentElement;
172
+ depth += 1;
173
+ }
174
+ var box = element.getBoundingClientRect();
175
+ var text = (element.textContent == null ? '' : String(element.textContent)).replace(/\s+/g, ' ').trim();
176
+ return {
177
+ tag: element.tagName.toLowerCase(),
178
+ text: text.slice(0, MAX_TEXT),
179
+ selector: buildSelector(element),
180
+ path: ancestry.map(function (e) { return e.selectorPart; }).concat([selectorPart(element)]).join(' > '),
181
+ bounds: rectFrom(box),
182
+ center: { x: box.left + box.width / 2, y: box.top + box.height / 2 },
183
+ attributes: attributes,
184
+ computedStyle: computedStyle,
185
+ ancestry: ancestry
186
+ };
187
+ };
188
+
189
+ // ------------------------------------------------------------------ chrome
190
+
191
+ var host = document.createElement('div');
192
+ host.setAttribute(OVERLAY_ATTR, '');
193
+ host.style.cssText = 'position:fixed;inset:0;z-index:' + Z_OVERLAY + ';pointer-events:none';
194
+ var shadow = host.attachShadow({ mode: 'closed' });
195
+
196
+ var style = document.createElement('style');
197
+ style.textContent = [
198
+ ':host{all:initial}',
199
+ '*{box-sizing:border-box;font-family:ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif}',
200
+ '.layer{position:fixed;inset:0;pointer-events:none}',
201
+ '.box{position:fixed;left:0;top:0;display:none;pointer-events:none;border:1.5px solid ' + THEME.primary + ';background:' + THEME.primarySoft + ';border-radius:2px}',
202
+ '.label{position:fixed;left:0;top:0;display:none;pointer-events:none;padding:1px 6px;border-radius:4px;background:' + THEME.primary + ';color:' + THEME.primaryContrast + ';font-size:11px;line-height:17px;white-space:nowrap;font-weight:600}',
203
+ '.tools{position:fixed;top:14px;left:50%;transform:translateX(-50%);display:flex;gap:2px;padding:4px;border-radius:999px;border:1px solid ' + THEME.border + ';background:' + THEME.glassSurface + ';-webkit-backdrop-filter:' + THEME.glassFilter + ';backdrop-filter:' + THEME.glassFilter + ';box-shadow:0 6px 20px rgba(0,0,0,.24);pointer-events:auto}',
204
+ '.tools button{appearance:none;border:none;background:transparent;color:' + THEME.mutedText + ';border-radius:999px;padding:5px 14px;font-size:12px;line-height:18px;font-weight:500;cursor:pointer;white-space:nowrap}',
205
+ '.tools button:hover{background:' + THEME.primaryFaint + '}',
206
+ '.tools button[aria-pressed="true"]{background:' + THEME.primarySoft + ';color:' + THEME.primary + ';font-weight:600}',
207
+ '.editor{position:fixed;left:0;top:0;display:none;align-items:center;gap:8px;width:min(420px,calc(100vw - 24px));padding:6px;padding-left:16px;border-radius:22px;border:1px solid ' + THEME.border + ';background:' + THEME.glassSurface + ';-webkit-backdrop-filter:' + THEME.glassFilter + ';backdrop-filter:' + THEME.glassFilter + ';box-shadow:0 8px 28px rgba(0,0,0,.3);pointer-events:auto}',
208
+ '.editor textarea{flex:1;min-width:0;resize:none;border:none;background:transparent;color:' + THEME.text + ';font-size:13px;line-height:20px;outline:none;padding:6px 0;min-height:32px;max-height:104px;display:block}',
209
+ '.editor textarea::placeholder{color:' + THEME.mutedText + '}',
210
+ '.editor button{appearance:none;border:none;background:' + THEME.primary + ';color:' + THEME.primaryContrast + ';border-radius:999px;padding:8px 18px;font-size:12px;line-height:18px;font-weight:600;cursor:pointer;white-space:nowrap}',
211
+ '.editor button[disabled]{opacity:.5;cursor:default}'
212
+ ].join('');
213
+ shadow.appendChild(style);
214
+
215
+ var cursorStyle = document.createElement('style');
216
+ cursorStyle.id = 'openchamber-annotation-cursor';
217
+ document.head.appendChild(cursorStyle);
218
+ var setCursor = function (value) {
219
+ cursorStyle.textContent = value ? '*{cursor:' + value + ' !important}' : '';
220
+ };
221
+
222
+ var svgNS = 'http://www.w3.org/2000/svg';
223
+ var svg = document.createElementNS(svgNS, 'svg');
224
+ svg.setAttribute('class', 'layer');
225
+ svg.style.overflow = 'visible';
226
+ shadow.appendChild(svg);
227
+
228
+ var hoverBox = document.createElement('div');
229
+ hoverBox.className = 'box';
230
+ var hoverLabel = document.createElement('div');
231
+ hoverLabel.className = 'label';
232
+ var marqueeBox = document.createElement('div');
233
+ marqueeBox.className = 'box';
234
+ shadow.append(hoverBox, hoverLabel, marqueeBox);
235
+
236
+ var positionBox = function (node, rect) {
237
+ node.style.display = 'block';
238
+ node.style.transform = 'translate(' + rect.x + 'px,' + rect.y + 'px)';
239
+ node.style.width = rect.width + 'px';
240
+ node.style.height = rect.height + 'px';
241
+ };
242
+
243
+ var tools = document.createElement('div');
244
+ tools.className = 'tools';
245
+ shadow.appendChild(tools);
246
+
247
+ var toolButtons = {};
248
+ [['select', LABELS.select], ['marquee', LABELS.marquee], ['draw', LABELS.draw]].forEach(function (entry) {
249
+ var button = document.createElement('button');
250
+ button.type = 'button';
251
+ button.textContent = entry[1];
252
+ button.addEventListener('click', function () { setTool(entry[0]); });
253
+ toolButtons[entry[0]] = button;
254
+ tools.appendChild(button);
255
+ });
256
+
257
+ var editor = document.createElement('div');
258
+ editor.className = 'editor';
259
+ shadow.appendChild(editor);
260
+
261
+ var comment = document.createElement('textarea');
262
+ comment.rows = 1;
263
+ comment.placeholder = LABELS.commentPlaceholder;
264
+ var submit = document.createElement('button');
265
+ submit.type = 'button';
266
+ submit.textContent = LABELS.submit;
267
+ editor.append(comment, submit);
268
+
269
+ /**
270
+ * Grows the box with its content.
271
+ *
272
+ * A hidden element reports scrollHeight 0, so measuring one collapses the
273
+ * field to nothing — which is what left a sliver of a click target and an
274
+ * invisible caret. Measuring only while visible, and never below the CSS
275
+ * min-height, keeps it usable.
276
+ */
277
+ var resizeComment = function () {
278
+ if (editor.style.display === 'none') return;
279
+ comment.style.height = 'auto';
280
+ comment.style.height = Math.max(32, Math.min(comment.scrollHeight, 104)) + 'px';
281
+ };
282
+ comment.addEventListener('input', resizeComment);
283
+
284
+ // -------------------------------------------------------------- selection
285
+
286
+ var lastTargetRect = null;
287
+
288
+ /** Places the comment box under whatever was just marked, kept on screen. */
289
+ var positionEditor = function () {
290
+ if (!lastTargetRect) {
291
+ editor.style.display = 'none';
292
+ return;
293
+ }
294
+ var wasHidden = editor.style.display === 'none';
295
+ editor.style.display = 'flex';
296
+ // Measured now that it is laid out, not while it was still hidden.
297
+ if (wasHidden) resizeComment();
298
+ var box = editor.getBoundingClientRect();
299
+ var left = lastTargetRect.x + lastTargetRect.width / 2 - box.width / 2;
300
+ var top = lastTargetRect.y + lastTargetRect.height + EDITOR_GAP;
301
+ // Above the target when there is no room below, so the box is never left
302
+ // half off the bottom of the page.
303
+ if (top + box.height > window.innerHeight - 8) {
304
+ top = Math.max(8, lastTargetRect.y - box.height - EDITOR_GAP);
305
+ }
306
+ left = Math.max(8, Math.min(left, window.innerWidth - box.width - 8));
307
+ editor.style.transform = 'translate(' + Math.round(left) + 'px,' + Math.round(top) + 'px)';
308
+ };
309
+
310
+ /** Focus after layout: focusing a zero-height field puts the caret nowhere. */
311
+ var focusComment = function () {
312
+ requestAnimationFrame(function () {
313
+ try {
314
+ comment.focus({ preventScroll: true });
315
+ comment.setSelectionRange(comment.value.length, comment.value.length);
316
+ } catch (error) { /* field went away */ }
317
+ });
318
+ };
319
+
320
+ var hasTargets = function () {
321
+ return Boolean(selected) || regions.length > 0 || strokes.length > 0;
322
+ };
323
+
324
+ var syncChrome = function () {
325
+ submit.disabled = !hasTargets();
326
+ if (!hasTargets()) {
327
+ lastTargetRect = null;
328
+ editor.style.display = 'none';
329
+ return;
330
+ }
331
+ positionEditor();
332
+ };
333
+
334
+ var syncSelectionVisuals = function () {
335
+ if (!selected) return;
336
+ var rect = rectFrom(selected.element.getBoundingClientRect());
337
+ if (!usableRect(rect)) {
338
+ selected.outline.style.display = 'none';
339
+ selected.badge.style.display = 'none';
340
+ return;
341
+ }
342
+ positionBox(selected.outline, rect);
343
+ selected.badge.style.display = 'block';
344
+ selected.badge.style.transform = 'translate(' + Math.max(2, rect.x) + 'px,' + Math.max(2, rect.y - 19) + 'px)';
345
+ lastTargetRect = rect;
346
+ };
347
+
348
+ var dropSelection = function () {
349
+ if (!selected) return;
350
+ selected.outline.remove();
351
+ selected.badge.remove();
352
+ selected = null;
353
+ };
354
+
355
+ var selectElement = function (element) {
356
+ var wasSelected = selected && selected.element === element;
357
+ dropSelection();
358
+ if (wasSelected) {
359
+ // Clicking the chosen element again clears it, so a misclick costs one
360
+ // click rather than starting over.
361
+ lastTargetRect = null;
362
+ syncChrome();
363
+ return;
364
+ }
365
+ var outline = document.createElement('div');
366
+ outline.className = 'box';
367
+ var badge = document.createElement('div');
368
+ badge.className = 'label';
369
+ badge.textContent = selectorPart(element);
370
+ shadow.append(outline, badge);
371
+ selected = { id: nextId('element'), element: element, outline: outline, badge: badge };
372
+ syncSelectionVisuals();
373
+ syncChrome();
374
+ focusComment();
375
+ };
376
+
377
+ var setTool = function (next) {
378
+ tool = next;
379
+ hoverBox.style.display = 'none';
380
+ hoverLabel.style.display = 'none';
381
+ marqueeBox.style.display = 'none';
382
+ setCursor(next === 'select' ? '' : 'crosshair');
383
+ for (var key in toolButtons) {
384
+ if (Object.prototype.hasOwnProperty.call(toolButtons, key)) {
385
+ toolButtons[key].setAttribute('aria-pressed', key === next ? 'true' : 'false');
386
+ }
387
+ }
388
+ };
389
+
390
+ // ------------------------------------------------------------- interaction
391
+
392
+ var drag = null;
393
+
394
+ var onPointerMove = function (event) {
395
+ if (drag) {
396
+ if (drag.kind === 'marquee') {
397
+ drag.rect = normalizeRect(drag.startX, drag.startY, event.clientX, event.clientY);
398
+ positionBox(marqueeBox, drag.rect);
399
+ } else if (drag.kind === 'draw') {
400
+ drag.points.push({ x: event.clientX, y: event.clientY });
401
+ drag.path.setAttribute('d', drag.points.map(function (point, index) {
402
+ return (index === 0 ? 'M' : 'L') + point.x + ' ' + point.y;
403
+ }).join(' '));
404
+ }
405
+ return;
406
+ }
407
+
408
+ if (tool !== 'select') return;
409
+ var element = elementFromPoint(event.clientX, event.clientY);
410
+ if (!element) {
411
+ hoverBox.style.display = 'none';
412
+ hoverLabel.style.display = 'none';
413
+ return;
414
+ }
415
+ var rect = rectFrom(element.getBoundingClientRect());
416
+ positionBox(hoverBox, rect);
417
+ hoverLabel.textContent = selectorPart(element);
418
+ hoverLabel.style.display = 'block';
419
+ hoverLabel.style.transform = 'translate(' + Math.max(2, rect.x) + 'px,' + Math.max(2, rect.y - 19) + 'px)';
420
+ };
421
+
422
+ var onPointerDown = function (event) {
423
+ if (event.button !== 0) return;
424
+ if (isOverlayNode(event.target)) return;
425
+ event.preventDefault();
426
+ event.stopPropagation();
427
+
428
+ if (tool === 'select') {
429
+ var element = elementFromPoint(event.clientX, event.clientY);
430
+ if (element) selectElement(element);
431
+ return;
432
+ }
433
+
434
+ if (tool === 'marquee') {
435
+ drag = { kind: 'marquee', startX: event.clientX, startY: event.clientY, rect: null };
436
+ return;
437
+ }
438
+
439
+ var path = document.createElementNS(svgNS, 'path');
440
+ path.setAttribute('fill', 'none');
441
+ path.setAttribute('stroke', THEME.primary);
442
+ path.setAttribute('stroke-width', '2.5');
443
+ path.setAttribute('stroke-linecap', 'round');
444
+ path.setAttribute('stroke-linejoin', 'round');
445
+ svg.appendChild(path);
446
+ drag = { kind: 'draw', path: path, points: [{ x: event.clientX, y: event.clientY }] };
447
+ };
448
+
449
+ var onPointerUp = function () {
450
+ if (!drag) return;
451
+ var finished = drag;
452
+ drag = null;
453
+
454
+ if (finished.kind === 'marquee') {
455
+ marqueeBox.style.display = 'none';
456
+ var rect = finished.rect;
457
+ if (!rect || !usableRect(rect)) return;
458
+ // A region marks an area, not the elements inside it: expanding it into a
459
+ // selection made the result depend on the page's markup rather than on
460
+ // what was drawn.
461
+ regions.push({ id: nextId('region'), rect: rect });
462
+ var outline = document.createElementNS(svgNS, 'rect');
463
+ outline.setAttribute('x', String(rect.x));
464
+ outline.setAttribute('y', String(rect.y));
465
+ outline.setAttribute('width', String(rect.width));
466
+ outline.setAttribute('height', String(rect.height));
467
+ outline.style.fill = THEME.primarySoft;
468
+ outline.setAttribute('stroke', THEME.primary);
469
+ outline.setAttribute('stroke-width', '1.5');
470
+ outline.setAttribute('rx', '2');
471
+ svg.appendChild(outline);
472
+ lastTargetRect = rect;
473
+ syncChrome();
474
+ focusComment();
475
+ return;
476
+ }
477
+
478
+ var points = finished.points;
479
+ if (points.length < 2) {
480
+ if (finished.path.parentNode) finished.path.parentNode.removeChild(finished.path);
481
+ return;
482
+ }
483
+ var minX = points[0].x, minY = points[0].y, maxX = points[0].x, maxY = points[0].y;
484
+ for (var p = 1; p < points.length; p += 1) {
485
+ minX = Math.min(minX, points[p].x);
486
+ minY = Math.min(minY, points[p].y);
487
+ maxX = Math.max(maxX, points[p].x);
488
+ maxY = Math.max(maxY, points[p].y);
489
+ }
490
+ var bounds = { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
491
+ strokes.push({ id: nextId('stroke'), points: points, bounds: bounds });
492
+ lastTargetRect = bounds;
493
+ syncChrome();
494
+ focusComment();
495
+ };
496
+
497
+ /**
498
+ * Swallows the page's own mouse handling while annotating.
499
+ *
500
+ * Blocking pointerdown is not enough: a click still follows it, so marking a
501
+ * button pressed that button and marking a link navigated away from the page
502
+ * being annotated. These are the events that reach page code, so these are
503
+ * the ones that have to stop.
504
+ */
505
+ var blockPageInteraction = function (event) {
506
+ if (isOverlayNode(event.target)) return;
507
+ event.preventDefault();
508
+ event.stopPropagation();
509
+ };
510
+ var BLOCKED_EVENTS = ['click', 'auxclick', 'dblclick', 'mousedown', 'mouseup', 'contextmenu'];
511
+
512
+ var onScrollOrResize = function () {
513
+ syncSelectionVisuals();
514
+ positionEditor();
515
+ };
516
+
517
+ var onKeyDown = function (event) {
518
+ if (event.key === 'Escape') {
519
+ event.preventDefault();
520
+ event.stopImmediatePropagation();
521
+ finish(null);
522
+ }
523
+ };
524
+
525
+ var onCommentKeyDown = function (event) {
526
+ // Do not let the annotated page treat typed letters as its own shortcuts.
527
+ event.stopPropagation();
528
+ if (event.key === 'Enter' && !event.shiftKey) {
529
+ event.preventDefault();
530
+ attach();
531
+ }
532
+ };
533
+
534
+ document.addEventListener('pointermove', onPointerMove, true);
535
+ document.addEventListener('pointerdown', onPointerDown, true);
536
+ document.addEventListener('pointerup', onPointerUp, true);
537
+ BLOCKED_EVENTS.forEach(function (name) {
538
+ window.addEventListener(name, blockPageInteraction, { capture: true, passive: false });
539
+ });
540
+ window.addEventListener('scroll', onScrollOrResize, true);
541
+ window.addEventListener('resize', onScrollOrResize, true);
542
+ window.addEventListener('keydown', onKeyDown, true);
543
+ comment.addEventListener('keydown', onCommentKeyDown);
544
+
545
+ // ------------------------------------------------------------------ finish
546
+
547
+ var teardown = function () {
548
+ document.removeEventListener('pointermove', onPointerMove, true);
549
+ document.removeEventListener('pointerdown', onPointerDown, true);
550
+ document.removeEventListener('pointerup', onPointerUp, true);
551
+ BLOCKED_EVENTS.forEach(function (name) {
552
+ window.removeEventListener(name, blockPageInteraction, true);
553
+ });
554
+ window.removeEventListener('scroll', onScrollOrResize, true);
555
+ window.removeEventListener('resize', onScrollOrResize, true);
556
+ window.removeEventListener('keydown', onKeyDown, true);
557
+ comment.removeEventListener('keydown', onCommentKeyDown);
558
+ setCursor('');
559
+ if (cursorStyle.parentNode) cursorStyle.parentNode.removeChild(cursorStyle);
560
+ if (host.parentNode) host.parentNode.removeChild(host);
561
+ try { delete window['${Ga}']; } catch (error) { /* non-configurable */ }
562
+ };
563
+
564
+ var finish = function (payload) {
565
+ if (settled) return;
566
+ settled = true;
567
+ teardown();
568
+ // Removing the chrome is not enough: the host screenshots this page right
569
+ // after we resolve, and the compositor can still hold a frame containing
570
+ // our outlines. Yield two frames so the page has actually repainted.
571
+ requestAnimationFrame(function () {
572
+ requestAnimationFrame(function () { resolve(payload); });
573
+ });
574
+ };
575
+
576
+ var attach = function () {
577
+ if (!hasTargets()) return;
578
+ finish({
579
+ id: 'annotation-' + Date.now(),
580
+ pageUrl: String(location.href),
581
+ pageTitle: String(document.title || ''),
582
+ viewport: { width: window.innerWidth, height: window.innerHeight },
583
+ devicePixelRatio: window.devicePixelRatio || 1,
584
+ comment: comment.value,
585
+ // Zero or one element, never more. Kept as a list so elements, regions
586
+ // and strokes stay one uniform shape for everything downstream.
587
+ elements: selected ? [{ id: selected.id, element: describe(selected.element) }] : [],
588
+ regions: regions.map(function (entry) { return { id: entry.id, rect: entry.rect }; }),
589
+ strokes: strokes.map(function (entry) {
590
+ return { id: entry.id, points: entry.points, bounds: entry.bounds };
591
+ })
592
+ });
593
+ };
594
+
595
+ submit.addEventListener('click', attach);
596
+
597
+ (document.body || document.documentElement).appendChild(host);
598
+ setTool('select');
599
+ syncChrome();
600
+ });`},lv={kind:"idle"},Vn=t=>typeof t=="object"&&t!==null,Zn=t=>typeof t=="number"&&Number.isFinite(t),qc=t=>Vn(t)&&Object.values(t).every(e=>typeof e=="string"),El=t=>Vn(t)&&Zn(t.x)&&Zn(t.y)&&Zn(t.width)&&Zn(t.height),Nf=t=>Vn(t)&&Zn(t.x)&&Zn(t.y),cv=t=>Vn(t)&&typeof t.tag=="string"&&typeof t.selectorPart=="string"&&(t.id===void 0||typeof t.id=="string")&&(t.className===void 0||typeof t.className=="string"),dv=t=>Vn(t)&&typeof t.tag=="string"&&typeof t.text=="string"&&typeof t.selector=="string"&&typeof t.path=="string"&&El(t.bounds)&&Nf(t.center)&&qc(t.attributes)&&qc(t.computedStyle)&&Array.isArray(t.ancestry)&&t.ancestry.every(cv),uv=t=>Vn(t)&&typeof t.id=="string"&&dv(t.element),fv=t=>Vn(t)&&typeof t.id=="string"&&El(t.rect),mv=t=>Vn(t)&&typeof t.id=="string"&&El(t.bounds)&&Array.isArray(t.points)&&t.points.every(Nf),hv=t=>Vn(t)&&typeof t.id=="string"&&typeof t.pageUrl=="string"&&typeof t.pageTitle=="string"&&typeof t.comment=="string"&&Vn(t.viewport)&&Zn(t.viewport.width)&&Zn(t.viewport.height)&&Zn(t.devicePixelRatio)&&Array.isArray(t.elements)&&t.elements.every(uv)&&Array.isArray(t.regions)&&t.regions.every(fv)&&Array.isArray(t.strokes)&&t.strokes.every(mv),pv=1600,gv=t=>new Promise((e,n)=>{const r=new Image;r.onload=()=>e(r),r.onerror=()=>n(new Error("Failed to decode browser page capture")),r.src=t}),xv=async({base64:t,mime:e,captureWidth:n,captureHeight:r,cssWidth:o,cssHeight:i,payload:c,accentColor:a,accentFill:d})=>{if(!t)return null;try{const u=await gv(`data:${e};base64,${t}`),m=Math.max(1,u.naturalWidth||n),f=Math.max(1,u.naturalHeight||r),g=m/Math.max(1,o||m),x=f/Math.max(1,i||f),j=Math.min(1,pv/m),w=document.createElement("canvas");w.width=Math.max(1,Math.floor(m*j)),w.height=Math.max(1,Math.floor(f*j));const p=w.getContext("2d");if(!p)return null;p.scale(j,j),p.drawImage(u,0,0,m,f);const h=N=>({x:N.x*g,y:N.y*x,width:N.width*g,height:N.height*x}),b=Math.max(2,2.5*g/Math.max(j,.2));p.strokeStyle=a,p.fillStyle=d;const v=N=>{const A=h(N);p.lineWidth=b,p.fillRect(A.x,A.y,A.width,A.height),p.strokeRect(A.x,A.y,A.width,A.height)};for(const N of c.elements)v(N.element.bounds);for(const N of c.regions)v(N.rect);for(const N of c.strokes)N.points.length<2||(p.beginPath(),N.points.forEach((A,k)=>{const C=A.x*g,P=A.y*x;k===0?p.moveTo(C,P):p.lineTo(C,P)}),p.lineCap="round",p.lineJoin="round",p.lineWidth=b*1.4,p.stroke());const S=await new Promise(N=>w.toBlob(N,"image/jpeg",.85));return S?new File([S],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},bv="({ width: window.innerWidth, height: window.innerHeight })",yv=async t=>{try{const e=await t.executeJavaScript(bv,!0);if(!e||typeof e!="object")return null;const n=e;return typeof n.width!="number"||typeof n.height!="number"||!Number.isFinite(n.width)||!Number.isFinite(n.height)?null:{width:n.width,height:n.height}}catch{return null}},ui=async t=>{try{await t.executeJavaScript(iv,!1)}catch{}},vv=async({host:t,theme:e,labels:n})=>{const r=av(e,n),o=await t.executeJavaScript(r,!0);if(o==null)return null;if(!hv(o))return await ui(t),null;const i=o;try{const c=await yv(t)??i.viewport,a=await t.capturePage();if(!a||!a.base64)return{payload:i,screenshot:null};const d=await xv({base64:a.base64,mime:a.mime||"image/jpeg",captureWidth:a.width,captureHeight:a.height,cssWidth:c.width,cssHeight:c.height,payload:i,accentColor:e.primary,accentFill:e.primarySoft});return{payload:i,screenshot:d}}catch{return{payload:i,screenshot:null}}},gn={colorScheme:"dark",primary:"rgb(59, 130, 246)",primarySoft:"rgba(59, 130, 246, 0.16)",primaryFaint:"rgba(59, 130, 246, 0.10)",primaryContrast:"rgb(255, 255, 255)",surface:"rgb(24, 24, 27)",surfaceElevated:"rgb(32, 32, 36)",glassSurface:"rgba(32, 32, 36, 0.64)",glassFilter:"blur(26px) saturate(1.16)",border:"rgba(255, 255, 255, 0.14)",text:"rgb(244, 244, 245)",mutedText:"rgba(244, 244, 245, 0.62)"},wv=()=>{if(typeof document>"u"||!document.body)return null;const t=document.createElement("div");return t.setAttribute("aria-hidden","true"),t.style.cssText="position:fixed;left:-9999px;top:-9999px;width:1px;height:1px;pointer-events:none",document.body.appendChild(t),{read:e=>{t.style.backgroundColor="",t.style.backgroundColor=e;const n=window.getComputedStyle(t).backgroundColor;return n&&n!=="rgba(0, 0, 0, 0)"?n:""},readVariable:e=>window.getComputedStyle(document.documentElement).getPropertyValue(e).trim(),dispose:()=>t.remove()}},Sv=t=>{const e=wv();if(!e)return{...gn,colorScheme:t};try{const n=(a,d)=>e.read(`var(${a})`)||d,r=(a,d,u)=>e.read(`color-mix(in srgb, var(${a}) ${d}%, transparent)`)||u,o=e.readVariable("--oc-glass-tooltip-opacity")||"62%",i=e.readVariable("--oc-glass-blur")||"26px",c=e.readVariable("--oc-glass-saturation")||"1.16";return{colorScheme:t,glassSurface:e.read(`color-mix(in srgb, var(--surface-elevated) ${o}, transparent)`)||gn.glassSurface,glassFilter:`blur(${i}) saturate(${c})`,primary:n("--primary",gn.primary),primarySoft:r("--primary",16,gn.primarySoft),primaryFaint:r("--primary",10,gn.primaryFaint),primaryContrast:n("--primary-foreground",gn.primaryContrast),surface:n("--surface-background",gn.surface),surfaceElevated:n("--surface-elevated",gn.surfaceElevated),border:n("--border",gn.border),text:n("--foreground",gn.text),mutedText:n("--muted-foreground",gn.mutedText)}}catch{return{...gn,colorScheme:t}}finally{e.dispose()}};let Jr=null,Zr=null,fi=null,Do=0,Pi=null;const zn=new Set,jv=3e4,kv=45e3,Af=()=>{fi&&(clearTimeout(fi),fi=null)},Df=()=>{if(Zr||zn.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(Do,5)),jv);Zr=setTimeout(()=>{Zr=null,Do+=1,Tl()},t)},Po=()=>{Af(),Jr&&Jr.close(),Jr=null},Yc=()=>{Af(),zn.size!==0&&(fi=setTimeout(()=>{Po(),Df()},kv))},Cv=t=>{if(!t||t.trim().length===0)return null;try{const e=JSON.parse(t),n=typeof e?.type=="string"?e.type:"",r=e?.properties;return n?{type:n,properties:r}:null}catch{return null}},Yo=t=>!t||typeof t!="object"?null:t,Nv=t=>{if(t.type==="openchamber:event-stream-ready"){Do=0;return}if(t.type==="openchamber:heartbeat")return;if(t.type==="openchamber:agent-memory-changed"){const d=Yo(t.properties),m={type:"agent-memory-changed",scope:d?.scope==="project"?"project":"global",...typeof d?.projectId=="string"&&d.projectId.length>0?{projectId:d.projectId}:{}};for(const f of zn)f(m);return}if(t.type==="openchamber:session-created"){const d=Yo(t.properties),u=typeof d?.sessionId=="string"?d.sessionId:"",m=typeof d?.directory=="string"?d.directory:"";if(!u||!m)return;const f={type:"session-created",sessionId:u,directory:m,createdAt:typeof d?.createdAt=="number"?d.createdAt:Date.now(),promptDispatched:d?.promptDispatched===!0,dispatchedAsCommand:d?.dispatchedAsCommand===!0,...typeof d?.projectId=="string"&&d.projectId.length>0?{projectId:d.projectId}:{}};for(const g of zn)g(f);return}if(t.type==="openchamber:browser-control-request"){const d=Yo(t.properties),u=typeof d?.requestId=="string"?d.requestId:"",m=typeof d?.action=="string"?d.action:"";if(!u||!m)return;const f=d?.parameters,g={type:"browser-control-request",requestId:u,action:m,parameters:f&&typeof f=="object"&&!Array.isArray(f)?f:{}};for(const x of zn)x(g);return}if(t.type!=="openchamber:scheduled-task-ran")return;const e=Yo(t.properties),n=typeof e?.projectId=="string"?e.projectId:"",r=typeof e?.taskId=="string"?e.taskId:"",o=typeof e?.ranAt=="number"?e.ranAt:Date.now(),i=e?.status,c=i==="running"||i==="error"?i:"success";if(!n||!r)return;const a={type:"scheduled-task-ran",projectId:n,taskId:r,ranAt:o,status:c,...typeof e?.sessionId=="string"&&e.sessionId.length>0?{sessionId:e.sessionId}:{}};for(const d of zn)d(a)},Tl=()=>{if(typeof window>"u"||zn.size===0||typeof EventSource!="function"||Jr&&Jr.readyState!==EventSource.CLOSED)return;Po();const t=typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,e=new EventSource(au().sse("/api/openchamber/events",t?{browser:"1"}:void 0));e.onopen=()=>{Yc()},e.onmessage=n=>{Yc();const r=Cv(n.data);r&&Nv(r)},e.onerror=()=>{Po(),Df()},Jr=e},Av=()=>{Pi||typeof window>"u"||(Pi=Li(()=>{Po(),Do=0,Tl()}))},Dv=()=>{Pi?.(),Pi=null},Yi=t=>(zn.add(t),Av(),Tl(),()=>{zn.delete(t),zn.size===0&&(Zr&&(clearTimeout(Zr),Zr=null),Do=0,Po(),Dv())}),Pv=2e3,Ev=50;let Lr=null,eo=null,So=null;const Tv=async t=>{try{const e=await gs("/api/browser-control/claim",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({requestId:t})});return e.ok?(await e.json())?.granted===!0:!1}catch{return!1}},Wr=async(t,e)=>{try{const n=await gs("/api/browser-control/result",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({requestId:t,...e})});n.ok||console.warn(`[browser-control] the server rejected the result for ${t} (HTTP ${n.status}); the agent will see this action time out`)}catch(n){console.warn(`[browser-control] could not deliver the result for ${t}:`,n)}},Iv=async(t=Pv)=>{const e=Date.now()+t;for(;!Lr&&Date.now()<e;)await new Promise(n=>setTimeout(n,Ev));return Lr},Rv=async t=>{const e=t.action==="browser.open",n=Lr;if(!(!n&&!(e&&eo))&&await Tv(t.requestId))try{if(e&&!n){const o=typeof t.parameters.url=="string"?t.parameters.url:"";if(!o){await Wr(t.requestId,{ok:!1,error:"url is required"});return}eo?.(o);const i=typeof t.parameters.viewport=="string"?t.parameters.viewport:"";if(!i||i==="fill"){await Wr(t.requestId,{ok:!0,data:{url:o,opened:!0}});return}const c=await Iv();if(!c){await Wr(t.requestId,{ok:!0,data:{url:o,opened:!0,viewportApplied:!1,note:"The panel had no browser view yet, so the viewport was not applied. Call browser.resize now that one exists."}});return}const a=await c.run("browser.resize",{viewport:i}),d=a&&typeof a=="object"?a.viewport??null:null;await Wr(t.requestId,{ok:!0,data:{url:o,opened:!0,viewportApplied:!0,viewport:d}});return}const r=await n.run(t.action,t.parameters);await Wr(t.requestId,{ok:!0,data:r})}catch(r){await Wr(t.requestId,{ok:!1,error:r instanceof Error?r.message:String(r)})}},Pf=()=>{So||(So=Yi(t=>{t.type==="browser-control-request"&&Rv({requestId:t.requestId,action:t.action,parameters:t.parameters})}))},Ef=()=>{Lr||eo||!So||(So(),So=null)},Mv=t=>(Lr=t,Pf(),()=>{Lr===t&&(Lr=null),Ef()}),Ov=t=>(eo=t,Pf(),()=>{eo===t&&(eo=null),Ef()}),Fv=50,Lv=6,Bv=2048,_v=200,Tf=t=>{const e=Xr(String(t??"").trim());if(!e||e.length>Bv)return"";try{const n=new URL(e);return n.protocol!=="http:"&&n.protocol!=="https:"?"":n.toString()}catch{return""}},$v=(t,e)=>{const n=Tf(e.url);if(!n)return t;const r=t.find(c=>c.url===n),o=String(e.title??"").trim().slice(0,_v)||r?.title||"";return[{url:n,title:o,lastVisitedAt:e.at},...t.filter(c=>c.url!==n)].slice(0,Fv)},zv=(t,e)=>{const n=Tf(e);return t.filter(r=>r.url!==n)},Uv=t=>`${t.url.replace(/^https?:\/\//,"")} ${t.title}`.toLowerCase(),If=(t,e,n=Lv)=>{const r=String(e??"").trim().toLowerCase(),o=[...t].sort((c,a)=>a.lastVisitedAt-c.lastVisitedAt);if(!r)return o.slice(0,n);const i=r.replace(/^https?:\/\//,"");return o.filter(c=>{const a=Uv(c);return c.url===r||a===i?!1:a.includes(i)}).slice(0,n)},Qc=20,mi=t=>{const e=jt((t||"").trim());return e?JSON.stringify([Ps(),e]):""},Wv=t=>{const e=Object.keys(t);if(e.length<=Qc)return t;const n=e.map(r=>[r,t[r]?.[0]?.lastVisitedAt??0]).sort((r,o)=>o[1]-r[1]).slice(0,Qc);return Object.fromEntries(n.map(([r])=>[r,t[r]??[]]))},to=br()(ef(t=>({byProject:{},recordVisit:(e,n)=>{const r=mi(e);r&&t(o=>{const i=o.byProject[r]??[],c=$v(i,{...n,at:Date.now()});return c===i?o:{byProject:Wv({...o.byProject,[r]:c})}})},forget:(e,n)=>{const r=mi(e);r&&t(o=>{const i=o.byProject[r];return i?{byProject:{...o.byProject,[r]:zv(i,n)}}:o})},clear:e=>{const n=mi(e);n&&t(r=>{if(!(n in r.byProject))return r;const o={...r.byProject};return delete o[n],{byProject:o}})}}),{name:"openchamber-browser-history",version:1,storage:Wm(),partialize:t=>({byProject:t.byProject})})),Vv=[],Rf=t=>e=>{const n=mi(t);return(n?e.byProject[n]:void 0)??Vv},qa=new Map,Eo=new Map,Mf=()=>typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,Of=t=>{if(!t)return!1;try{const e=new URL(t,typeof window<"u"?window.location.href:void 0),n=typeof window<"u"?window.__OPENCHAMBER_LOCAL_ORIGIN__:"";return n&&e.origin===n?!1:!no(e.toString())}catch{return!1}},Ff=t=>{try{const e=new URL(t),n=Number.parseInt(e.port||(e.protocol==="https:"?"443":"80"),10);return Number.isInteger(n)&&n>0?n:0}catch{return 0}},Xc=(t,e)=>{try{const n=new URL(t);return n.protocol="http:",n.hostname="127.0.0.1",n.port=String(e),n.toString()}catch{return t}};class jo extends Error{constructor(e){super(e),this.name="DevTunnelUnavailableError"}}const Jc=async t=>{if(!t||!Mf()||!no(t))return t;const e=hr();if(!Of(e))return t;const n=Ff(t);if(!n)return t;const r=`${e}|${n}`,o=qa.get(r);if(o){try{Eo.set(o,new URL(t).origin)}catch{}return Xc(t,o)}try{const i=await vo("desktop_dev_tunnel_open",{baseUrl:e,port:n,clientToken:Co(),requestHeaders:lu()});if(!i||!Number.isInteger(i.localPort)||i.localPort<=0)throw new jo(t);qa.set(r,i.localPort);try{Eo.set(i.localPort,new URL(t).origin)}catch{}return Xc(t,i.localPort)}catch(i){throw i instanceof jo?i:new jo(t)}},Zc=t=>{if(!t||!Mf()||!no(t)||!Of(hr()))return!1;const e=Ff(t);return e>0&&!Eo.has(e)},go=t=>{if(!t)return t;try{const e=new URL(t);if(e.hostname!=="127.0.0.1")return t;const n=Eo.get(Number.parseInt(e.port||"0",10));return n?`${n}${e.pathname}${e.search}${e.hash}`:t}catch{return t}},Hv=()=>{qa.clear(),Eo.clear()};typeof window<"u"&&Li(Hv);const ed=6e3,Kv=120,Gv=80,qv=`
601
+ var MAX_ELEMENTS = ${Kv};
602
+ var MAX_LABEL_CHARS = ${Gv};
603
+ var visible = function (element) {
604
+ var rect = element.getBoundingClientRect();
605
+ if (rect.width < 1 || rect.height < 1) return false;
606
+ var style = window.getComputedStyle(element);
607
+ return style.visibility !== 'hidden' && style.display !== 'none' && Number(style.opacity) !== 0;
608
+ };
609
+ var label = function (element) {
610
+ var aria = element.getAttribute('aria-label');
611
+ if (aria) return aria.trim();
612
+ var value = element.getAttribute('value');
613
+ var text = (element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim();
614
+ if (text) return text.slice(0, MAX_LABEL_CHARS);
615
+ if (value) return String(value).slice(0, MAX_LABEL_CHARS);
616
+ var placeholder = element.getAttribute('placeholder');
617
+ return placeholder ? placeholder.trim().slice(0, MAX_LABEL_CHARS) : '';
618
+ };
619
+ var isUnique = function (selector) {
620
+ try {
621
+ return document.querySelectorAll(selector).length === 1;
622
+ } catch (error) {
623
+ return false;
624
+ }
625
+ };
626
+
627
+ /**
628
+ * Names an element by what it is, falling back to where it sits.
629
+ *
630
+ * A positional chain like 'main > section:nth-of-type(3) > div > a' survives
631
+ * only until the markup shifts, and says nothing about what it points at.
632
+ * Anything the page states about identity — an id, a test id, an accessible
633
+ * name — outlives edits and reads as the thing it selects. The chain remains
634
+ * as the last resort, because something always has to work.
635
+ */
636
+ var cssPath = function (element) {
637
+ var tag = element.tagName.toLowerCase();
638
+
639
+ if (element.id) {
640
+ var byId = '#' + CSS.escape(element.id);
641
+ if (isUnique(byId)) return byId;
642
+ }
643
+ var stableAttrs = ['data-testid', 'data-test-id', 'data-test', 'name', 'aria-label'];
644
+ for (var a = 0; a < stableAttrs.length; a += 1) {
645
+ var value = element.getAttribute(stableAttrs[a]);
646
+ if (!value) continue;
647
+ var raw = String(value);
648
+ // A value containing a quote would need escaping for no real gain: such
649
+ // attributes are rare, and the positional chain still covers them.
650
+ if (raw.indexOf('"') !== -1) continue;
651
+ var byAttr = tag + '[' + stableAttrs[a] + '="' + raw + '"]';
652
+ if (isUnique(byAttr)) return byAttr;
653
+ }
654
+ var className = typeof element.className === 'string' ? element.className.trim() : '';
655
+ if (className) {
656
+ var classes = className.split(/\\s+/).filter(Boolean);
657
+ for (var c = 0; c < classes.length; c += 1) {
658
+ var byClass = tag + '.' + CSS.escape(classes[c]);
659
+ if (isUnique(byClass)) return byClass;
660
+ }
661
+ }
662
+
663
+ var parts = [];
664
+ var node = element;
665
+ var depth = 0;
666
+ while (node && node.nodeType === 1 && depth < 6) {
667
+ var part = node.tagName.toLowerCase();
668
+ var parent = node.parentElement;
669
+ if (!parent) { parts.unshift(part); break; }
670
+ var siblings = Array.prototype.filter.call(parent.children, function (child) {
671
+ return child.tagName === node.tagName;
672
+ });
673
+ if (siblings.length > 1) part += ':nth-of-type(' + (siblings.indexOf(node) + 1) + ')';
674
+ parts.unshift(part);
675
+ if (node.id) { parts[0] = '#' + CSS.escape(node.id); break; }
676
+ node = parent;
677
+ depth += 1;
678
+ }
679
+ return parts.join(' > ');
680
+ };
681
+
682
+ /** What a screen reader would announce, or '' when there is nothing to say. */
683
+ var accessibleName = function (element) {
684
+ var aria = element.getAttribute('aria-label');
685
+ if (aria && aria.trim()) return aria.trim();
686
+ var labelled = element.getAttribute('aria-labelledby');
687
+ if (labelled) {
688
+ var source = document.getElementById(labelled.split(/\\s+/)[0]);
689
+ if (source && (source.innerText || '').trim()) return source.innerText.trim();
690
+ }
691
+ var title = element.getAttribute('title');
692
+ if (title && title.trim()) return title.trim();
693
+ var alt = element.getAttribute('alt');
694
+ if (alt && alt.trim()) return alt.trim();
695
+ var text = (element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim();
696
+ if (text) return text;
697
+ var value = element.getAttribute('value');
698
+ return value && String(value).trim() ? String(value).trim() : '';
699
+ };
700
+ var findByText = function (needle) {
701
+ var wanted = String(needle).replace(/\\s+/g, ' ').trim().toLowerCase();
702
+ var candidates = document.querySelectorAll('a, button, [role="button"], [role="link"], input[type="submit"], input[type="button"], summary, label');
703
+ var exact = null;
704
+ var partial = null;
705
+ for (var i = 0; i < candidates.length; i += 1) {
706
+ var element = candidates[i];
707
+ if (!visible(element)) continue;
708
+ var text = label(element).toLowerCase();
709
+ if (!text) continue;
710
+ if (text === wanted) { exact = element; break; }
711
+ if (!partial && text.indexOf(wanted) !== -1) partial = element;
712
+ }
713
+ return exact || partial;
714
+ };
715
+ `,Mo=t=>`(() => {
716
+ ${qv}
717
+ ${t}
718
+ })()`,Yv=({selector:t}={})=>Mo(`
719
+ var scopeSelector = ${JSON.stringify(t??"")};
720
+ var root = document;
721
+ if (scopeSelector) {
722
+ try { root = document.querySelector(scopeSelector); }
723
+ catch (error) { return { ok: false, error: 'Invalid selector: ' + scopeSelector }; }
724
+ if (!root) return { ok: false, error: 'No element matches ' + scopeSelector };
725
+ }
726
+ var interactive = root.querySelectorAll('a[href], button, input, select, textarea, [role="button"], [role="link"], [role="tab"], [contenteditable="true"]');
727
+ var elements = [];
728
+ var visibleTotal = 0;
729
+ for (var i = 0; i < interactive.length; i += 1) {
730
+ var element = interactive[i];
731
+ if (!visible(element)) continue;
732
+ visibleTotal += 1;
733
+ if (elements.length >= MAX_ELEMENTS) continue;
734
+
735
+ var rect = element.getBoundingClientRect();
736
+ // Empty and default-valued fields are left out rather than serialized as
737
+ // "" and false. Repeated across a hundred entries that overhead dwarfed
738
+ // the information it carried.
739
+ var entry = {
740
+ selector: cssPath(element),
741
+ tag: element.tagName.toLowerCase(),
742
+ bounds: { x: Math.round(rect.x), y: Math.round(rect.y), width: Math.round(rect.width), height: Math.round(rect.height) }
743
+ };
744
+ // The list covers the whole document so anything can be clicked without
745
+ // scrolling to it first, which means bounds alone do not say what is on
746
+ // screen — a negative y reads as a bug otherwise.
747
+ if (rect.bottom > 0 && rect.top < window.innerHeight) entry.inViewport = true;
748
+ var type = element.getAttribute('type');
749
+ if (type) entry.type = type;
750
+ var role = element.getAttribute('role');
751
+ if (role) entry.role = role;
752
+ var labelText = label(element);
753
+ if (labelText) entry.label = labelText;
754
+ if (element.disabled === true) entry.disabled = true;
755
+ // Flagged rather than described: reporting the accessible name of every
756
+ // element would cost more than it tells, while its absence on something
757
+ // clickable is a defect worth naming.
758
+ if (!accessibleName(element)) entry.missingAccessibleName = true;
759
+ elements.push(entry);
760
+ }
761
+ var body = document.body ? (document.body.innerText || '') : '';
762
+ var text = body.replace(/\\n{3,}/g, '\\n\\n').trim();
763
+ var docEl = document.documentElement;
764
+ var result = {
765
+ ok: true,
766
+ url: String(location.href),
767
+ title: String(document.title || ''),
768
+ scope: scopeSelector || 'document',
769
+ scrollY: Math.round(window.scrollY),
770
+ maxScrollY: Math.max(0, Math.round(docEl.scrollHeight - window.innerHeight)),
771
+ text: text.slice(0, ${ed}),
772
+ elements: elements
773
+ };
774
+ // State what was dropped. A capped list that reports only its own length
775
+ // reads as the whole page, and the agent acts as if it had seen everything.
776
+ if (text.length > ${ed}) {
777
+ result.textTruncated = true;
778
+ result.textTotalChars = text.length;
779
+ }
780
+ if (visibleTotal > elements.length) {
781
+ result.elementsTruncated = true;
782
+ result.interactiveElementsOnPage = visibleTotal;
783
+ }
784
+ return result;
785
+ `),Qv=({selector:t,text:e})=>Mo(`
786
+ var selector = ${JSON.stringify(t??"")};
787
+ var text = ${JSON.stringify(e??"")};
788
+ var target = null;
789
+ if (selector) {
790
+ try { target = document.querySelector(selector); }
791
+ catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
792
+ if (!target) return { ok: false, error: 'No element matches ' + selector };
793
+ } else {
794
+ target = findByText(text);
795
+ if (!target) return { ok: false, error: 'No clickable element has the label ' + text };
796
+ }
797
+ if (target.disabled === true) return { ok: false, error: 'Element is disabled' };
798
+ target.scrollIntoView({ block: 'center', inline: 'center' });
799
+ target.click();
800
+ return { ok: true, clicked: cssPath(target), label: label(target), url: String(location.href) };
801
+ `),Xv=({selector:t,value:e,submit:n})=>Mo(`
802
+ var selector = ${JSON.stringify(t)};
803
+ var value = ${JSON.stringify(e)};
804
+ var target = null;
805
+ try { target = document.querySelector(selector); }
806
+ catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
807
+ if (!target) return { ok: false, error: 'No element matches ' + selector };
808
+
809
+ var editable = target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable;
810
+ if (!editable) return { ok: false, error: selector + ' is not a text field' };
811
+ if (target.disabled === true || target.readOnly === true) return { ok: false, error: 'Field is not editable' };
812
+
813
+ target.scrollIntoView({ block: 'center' });
814
+ target.focus();
815
+ if (target.isContentEditable) {
816
+ target.textContent = value;
817
+ } else {
818
+ // Frameworks track the value through the native setter; assigning the
819
+ // property directly leaves React and friends unaware of the change.
820
+ var prototype = target.tagName === 'TEXTAREA' ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
821
+ var setter = Object.getOwnPropertyDescriptor(prototype, 'value');
822
+ if (setter && setter.set) setter.set.call(target, value);
823
+ else target.value = value;
824
+ }
825
+ target.dispatchEvent(new Event('input', { bubbles: true }));
826
+ target.dispatchEvent(new Event('change', { bubbles: true }));
827
+
828
+ if (${n?"true":"false"}) {
829
+ var enter = { key: 'Enter', code: 'Enter', keyCode: 13, which: 13, bubbles: true };
830
+ target.dispatchEvent(new KeyboardEvent('keydown', enter));
831
+ target.dispatchEvent(new KeyboardEvent('keyup', enter));
832
+ var form = target.form;
833
+ if (form && typeof form.requestSubmit === 'function') form.requestSubmit();
834
+ }
835
+ return { ok: true, selector: cssPath(target), url: String(location.href) };
836
+ `),Jv=({selector:t,direction:e})=>Mo(`
837
+ var selector = ${JSON.stringify(t??"")};
838
+ var direction = ${JSON.stringify(e??"")};
839
+
840
+ var settle = function (extra) {
841
+ return new Promise(function (resolve) {
842
+ requestAnimationFrame(function () {
843
+ requestAnimationFrame(function () {
844
+ var doc = document.documentElement;
845
+ var maxScrollY = Math.max(0, doc.scrollHeight - window.innerHeight);
846
+ var scrollY = Math.round(window.scrollY);
847
+ var result = { ok: true, scrollY: scrollY, maxScrollY: Math.round(maxScrollY) };
848
+ result.atTop = scrollY <= 1;
849
+ result.atBottom = scrollY >= maxScrollY - 1;
850
+ for (var key in extra) {
851
+ if (Object.prototype.hasOwnProperty.call(extra, key)) result[key] = extra[key];
852
+ }
853
+ resolve(result);
854
+ });
855
+ });
856
+ });
857
+ };
858
+
859
+ if (selector) {
860
+ var target = null;
861
+ try { target = document.querySelector(selector); }
862
+ catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
863
+ if (!target) return { ok: false, error: 'No element matches ' + selector };
864
+ // Instant on purpose: the page's own smooth scrolling would still be
865
+ // animating when the next action runs against it.
866
+ target.scrollIntoView({ block: 'center', behavior: 'instant' });
867
+ return settle({ scrolledTo: cssPath(target) });
868
+ }
869
+
870
+ var doc = document.documentElement;
871
+ var page = Math.round(window.innerHeight * 0.85);
872
+ var bottom = Math.max(0, doc.scrollHeight - window.innerHeight);
873
+ if (direction === 'down') window.scrollTo({ top: window.scrollY + page, behavior: 'instant' });
874
+ else if (direction === 'up') window.scrollTo({ top: window.scrollY - page, behavior: 'instant' });
875
+ else if (direction === 'top') window.scrollTo({ top: 0, behavior: 'instant' });
876
+ else if (direction === 'bottom') window.scrollTo({ top: bottom, behavior: 'instant' });
877
+ else return { ok: false, error: 'Unknown scroll direction: ' + direction };
878
+ return settle({ direction: direction });
879
+ `),Zv=["color","background-color","background-image","opacity","font-family","font-size","font-weight","line-height","letter-spacing","text-align","border-radius","border-width","border-style","border-color","box-shadow","display","position","width","height","padding","margin","gap","flex-direction","justify-content","align-items","z-index","overflow","visibility"],e1=({selector:t})=>Mo(`
880
+ var selector = ${JSON.stringify(t)};
881
+ var target = null;
882
+ try { target = document.querySelector(selector); }
883
+ catch (error) { return { ok: false, error: 'Invalid selector: ' + selector }; }
884
+ if (!target) return { ok: false, error: 'No element matches ' + selector };
885
+
886
+ var computed = window.getComputedStyle(target);
887
+ var styles = {};
888
+ var props = ${JSON.stringify(Zv)};
889
+ for (var i = 0; i < props.length; i += 1) {
890
+ var value = computed.getPropertyValue(props[i]);
891
+ if (value) styles[props[i]] = String(value).trim();
892
+ }
893
+
894
+ var rect = target.getBoundingClientRect();
895
+ return {
896
+ ok: true,
897
+ selector: cssPath(target),
898
+ tag: target.tagName.toLowerCase(),
899
+ label: label(target),
900
+ bounds: { x: Math.round(rect.x), y: Math.round(rect.y), width: Math.round(rect.width), height: Math.round(rect.height) },
901
+ inViewport: rect.bottom > 0 && rect.top < window.innerHeight,
902
+ styles: styles
903
+ };
904
+ `),t1=t=>{const e=it.c(18),{entries:n,activeIndex:r,onSelect:o,onForget:i,onHighlight:c}=t,{t:a}=gt();if(n.length===0)return null;let d;e[0]!==a?(d=a("contextPanel.browser.history.label"),e[0]=a,e[1]=d):d=e[1];let u;if(e[2]!==r||e[3]!==n||e[4]!==i||e[5]!==c||e[6]!==o||e[7]!==a){let f;e[9]!==r||e[10]!==i||e[11]!==c||e[12]!==o||e[13]!==a?(f=(g,x)=>s.jsxs("div",{role:"option","aria-selected":x===r,className:ge("group flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1",x===r?"bg-interactive-hover":"hover:bg-interactive-hover"),onPointerDown:j=>{j.preventDefault(),o(g.url)},onPointerEnter:()=>c(x),children:[s.jsx(T,{name:"global",className:"size-3.5 shrink-0 text-muted-foreground","aria-hidden":"true"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate typography-micro text-foreground",children:g.title||Pl(g.url)}),s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:g.url})]}),s.jsx("button",{type:"button",className:ge("shrink-0 rounded-md p-1 text-muted-foreground opacity-0 transition-opacity","hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100"),"aria-label":a("contextPanel.browser.history.forget"),title:a("contextPanel.browser.history.forget"),onPointerDown:j=>{j.preventDefault(),j.stopPropagation(),i(g.url)},children:s.jsx(T,{name:"close",className:"size-3","aria-hidden":"true"})})]},g.url),e[9]=r,e[10]=i,e[11]=c,e[12]=o,e[13]=a,e[14]=f):f=e[14],u=n.map(f),e[2]=r,e[3]=n,e[4]=i,e[5]=c,e[6]=o,e[7]=a,e[8]=u}else u=e[8];let m;return e[15]!==d||e[16]!==u?(m=s.jsx("div",{className:"oc-glass-popover oc-glass-floating absolute inset-x-0 top-full z-50 mt-1 overflow-hidden rounded-xl p-1",role:"listbox","aria-label":d,children:u}),e[15]=d,e[16]=u,e[17]=m):m=e[17],m},xn=t=>{const e=it.c(17),{icon:n,label:r,onClick:o,disabled:i,pressed:c}=t,a=c?"secondary":"ghost",d=c&&"text-foreground";let u;e[0]!==d?(u=ge("w-6 shrink-0 rounded-full px-0 text-muted-foreground","hover:text-foreground",d),e[0]=d,e[1]=u):u=e[1];let m;e[2]!==n?(m=s.jsx(T,{name:n,className:"size-3.5","aria-hidden":"true"}),e[2]=n,e[3]=m):m=e[3];let f;e[4]!==i||e[5]!==r||e[6]!==o||e[7]!==c||e[8]!==a||e[9]!==u||e[10]!==m?(f=s.jsx(mt,{asChild:!0,children:s.jsx(lt,{type:"button",variant:a,size:"xs",className:u,onClick:o,disabled:i,"aria-label":r,"aria-pressed":c,children:m})}),e[4]=i,e[5]=r,e[6]=o,e[7]=c,e[8]=a,e[9]=u,e[10]=m,e[11]=f):f=e[11];let g;e[12]!==r?(g=s.jsx(ht,{sideOffset:6,children:r}),e[12]=r,e[13]=g):g=e[13];let x;return e[14]!==f||e[15]!==g?(x=s.jsxs(ft,{children:[f,g]}),e[14]=f,e[15]=g,e[16]=x):x=e[16],x},Lf=t=>{const e=it.c(104),{address:n,suggestions:r,onForgetSuggestion:o,onAddressChange:i,onSubmit:c,onBack:a,onForward:d,onReload:u,onOpenExternal:m,canGoBack:f,canGoForward:g,isLoading:x,onAnnotate:j,onOpenDevTools:w,isAnnotating:p,onHardReload:h,onZoomIn:b,onZoomOut:v,onZoomReset:S,zoomPercent:N,onClearCookies:A,onClearCache:k,onToggleDeviceBar:C,isDeviceBarOpen:P}=t;let D;e[0]!==r?(D=r===void 0?[]:r,e[0]=r,e[1]=D):D=e[1];const O=D,F=N===void 0?100:N,{t:E}=gt(),[B,$]=l.useState(!1),[z,V]=l.useState(-1);let y;e[2]!==B||e[3]!==O?(y=B?O:[],e[2]=B,e[3]=O,e[4]=y):y=e[4];const I=y;let _;e[5]===Symbol.for("react.memo_cache_sentinel")?(_=()=>{V(-1)},e[5]=_):_=e[5];let W;e[6]!==n||e[7]!==B?(W=[n,B],e[6]=n,e[7]=B,e[8]=W):W=e[8],l.useEffect(_,W);let K;e[9]!==c?(K=ie=>{$(!1),V(-1),c(ie)},e[9]=c,e[10]=K):K=e[10];const Z=K;let Q;e[11]!==z||e[12]!==Z||e[13]!==I?(Q=ie=>{if(I.length!==0){if(ie.key==="ArrowDown"||ie.key==="ArrowUp"){ie.preventDefault();const Re=ie.key==="ArrowDown"?1:-1,ue=I.length;V(R=>{const ae=R+Re;return ae<-1?ue-1:ae>=ue?-1:ae});return}if(ie.key==="Escape"&&z>=0){ie.preventDefault(),V(-1);return}if(ie.key==="Enter"&&z>=0){ie.preventDefault();const Re=I[z];Re&&Z(Re.url)}}},e[11]=z,e[12]=Z,e[13]=I,e[14]=Q):Q=e[14];const le=Q;let te;e[15]!==E?(te=E("contextPanel.browser.back"),e[15]=E,e[16]=te):te=e[16];const he=!f;let xe;e[17]!==a||e[18]!==he||e[19]!==te?(xe=s.jsx(xn,{icon:"arrow-left",label:te,onClick:a,disabled:he}),e[17]=a,e[18]=he,e[19]=te,e[20]=xe):xe=e[20];let H;e[21]!==E?(H=E("contextPanel.browser.forward"),e[21]=E,e[22]=H):H=e[22];const we=!g;let de;e[23]!==d||e[24]!==H||e[25]!==we?(de=s.jsx(xn,{icon:"arrow-right",label:H,onClick:d,disabled:we}),e[23]=d,e[24]=H,e[25]=we,e[26]=de):de=e[26];let q;e[27]!==x||e[28]!==E?(q=E(x?"contextPanel.browser.stop":"contextPanel.browser.reload"),e[27]=x,e[28]=E,e[29]=q):q=e[29];let me;e[30]!==u||e[31]!==q?(me=s.jsx(xn,{icon:"refresh",label:q,onClick:u}),e[30]=u,e[31]=q,e[32]=me):me=e[32];let be;e[33]!==h||e[34]!==E?(be=h?s.jsx(xn,{icon:"restart",label:E("contextPanel.browser.hardReload"),onClick:h}):null,e[33]=h,e[34]=E,e[35]=be):be=e[35];let Pe;e[36]!==n||e[37]!==Z?(Pe=ie=>{ie.preventDefault(),Z(n)},e[36]=n,e[37]=Z,e[38]=Pe):Pe=e[38];let Ie;e[39]!==i?(Ie=ie=>i(ie.target.value),e[39]=i,e[40]=Ie):Ie=e[40];let De,Le;e[41]===Symbol.for("react.memo_cache_sentinel")?(De=()=>$(!0),Le=()=>$(!1),e[41]=De,e[42]=Le):(De=e[41],Le=e[42]);const Ne=I.length>0;let ve;e[43]===Symbol.for("react.memo_cache_sentinel")?(ve=ge("h-6 w-full rounded-full border border-border/50 bg-[var(--surface-elevated)] px-3","typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]"),e[43]=ve):ve=e[43];let Me;e[44]!==E?(Me=E("contextPanel.browser.addressAria"),e[44]=E,e[45]=Me):Me=e[45];let ee;e[46]!==n||e[47]!==le||e[48]!==Ie||e[49]!==Ne||e[50]!==Me?(ee=s.jsx("input",{value:n,onChange:Ie,onFocus:De,onBlur:Le,onKeyDown:le,spellCheck:!1,autoComplete:"off",role:"combobox","aria-expanded":Ne,"aria-controls":"openchamber-browser-address-suggestions",className:ve,"aria-label":Me}),e[46]=n,e[47]=le,e[48]=Ie,e[49]=Ne,e[50]=Me,e[51]=ee):ee=e[51];let oe;e[52]!==o?(oe=ie=>o?.(ie),e[52]=o,e[53]=oe):oe=e[53];let Te;e[54]!==z||e[55]!==Z||e[56]!==oe||e[57]!==I?(Te=s.jsx("div",{id:"openchamber-browser-address-suggestions",children:s.jsx(t1,{entries:I,activeIndex:z,onSelect:Z,onForget:oe,onHighlight:V})}),e[54]=z,e[55]=Z,e[56]=oe,e[57]=I,e[58]=Te):Te=e[58];let J;e[59]!==Pe||e[60]!==ee||e[61]!==Te?(J=s.jsxs("form",{className:"relative min-w-0 flex-1",onSubmit:Pe,children:[ee,Te]}),e[59]=Pe,e[60]=ee,e[61]=Te,e[62]=J):J=e[62];let re;e[63]!==b||e[64]!==v||e[65]!==S||e[66]!==E||e[67]!==F?(re=v&&b?s.jsxs("div",{className:"flex shrink-0 items-center",children:[s.jsx(xn,{icon:"subtract",label:E("contextPanel.browser.zoomOut"),onClick:v}),F!==100&&S?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsxs(lt,{type:"button",variant:"ghost",size:"xs",className:"shrink-0 rounded-full px-1.5 typography-micro tabular-nums text-muted-foreground",onClick:S,"aria-label":E("contextPanel.browser.zoomReset"),children:[F,"%"]})}),s.jsx(ht,{sideOffset:6,children:E("contextPanel.browser.zoomReset")})]}):null,s.jsx(xn,{icon:"add",label:E("contextPanel.browser.zoomIn"),onClick:b})]}):null,e[63]=b,e[64]=v,e[65]=S,e[66]=E,e[67]=F,e[68]=re):re=e[68];let Y;e[69]!==A||e[70]!==E?(Y=A?s.jsx(xn,{icon:"delete-bin",label:E("contextPanel.browser.clearCookies"),onClick:A}):null,e[69]=A,e[70]=E,e[71]=Y):Y=e[71];let U;e[72]!==k||e[73]!==E?(U=k?s.jsx(xn,{icon:"database-2",label:E("contextPanel.browser.clearCache"),onClick:k}):null,e[72]=k,e[73]=E,e[74]=U):U=e[74];let fe;e[75]!==P||e[76]!==C||e[77]!==E?(fe=C?s.jsx(xn,{icon:"smartphone",label:E("contextPanel.browser.deviceToolbar"),onClick:C,pressed:P}):null,e[75]=P,e[76]=C,e[77]=E,e[78]=fe):fe=e[78];let ne;e[79]!==p||e[80]!==j||e[81]!==E?(ne=j?s.jsx(xn,{icon:"markup",label:E("contextPanel.browser.annotate.toggle"),onClick:j,pressed:p}):null,e[79]=p,e[80]=j,e[81]=E,e[82]=ne):ne=e[82];let ce;e[83]!==w||e[84]!==E?(ce=w?s.jsx(xn,{icon:"terminal-box",label:E("contextPanel.browser.devTools"),onClick:w}):null,e[83]=w,e[84]=E,e[85]=ce):ce=e[85];let Fe;e[86]!==E?(Fe=E("contextPanel.browser.openExternal"),e[86]=E,e[87]=Fe):Fe=e[87];let Ye;e[88]!==m||e[89]!==Fe?(Ye=s.jsx(xn,{icon:"external-link",label:Fe,onClick:m}),e[88]=m,e[89]=Fe,e[90]=Ye):Ye=e[90];let $e;return e[91]!==xe||e[92]!==de||e[93]!==me||e[94]!==be||e[95]!==J||e[96]!==re||e[97]!==Y||e[98]!==U||e[99]!==fe||e[100]!==ne||e[101]!==ce||e[102]!==Ye?($e=s.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[xe,de,me,be,J,re,Y,U,fe,ne,ce,Ye]}),e[91]=xe,e[92]=de,e[93]=me,e[94]=be,e[95]=J,e[96]=re,e[97]=Y,e[98]=U,e[99]=fe,e[100]=ne,e[101]=ce,e[102]=Ye,e[103]=$e):$e=e[103],$e},Ei={kind:"fill"},td=240,s1=3840,Bf=[{id:"iphone-se",label:"iPhone SE",width:375,height:667},{id:"iphone-14",label:"iPhone 14",width:390,height:844},{id:"iphone-14-pro-max",label:"iPhone 14 Pro Max",width:430,height:932},{id:"pixel-7",label:"Pixel 7",width:412,height:915},{id:"ipad-mini",label:"iPad mini",width:768,height:1024},{id:"ipad-pro",label:"iPad Pro",width:1024,height:1366},{id:"laptop",label:"Laptop",width:1280,height:800},{id:"desktop",label:"Desktop",width:1440,height:900}],sd=t=>Number.isFinite(t)?Math.round(Math.min(s1,Math.max(td,t))):td,Ti=t=>t.kind==="fill"?null:{width:t.width,height:t.height},_f=t=>{const e=Bf.find(n=>n.id===t);return e?{kind:"preset",id:e.id,width:e.width,height:e.height}:null},n1=t=>t.kind==="fill"?t:{kind:"custom",width:t.height,height:t.width},r1=(t,e)=>{const n=Ti(t);if(!n)return null;const r=Math.max(1,e.width),o=Math.max(1,e.height),i=Math.min(1,r/n.width,o/n.height);return{width:n.width,height:n.height,scale:i}},o1=["mobile","tablet","desktop","fill"],i1={mobile:"iphone-14",tablet:"ipad-mini",desktop:"desktop"},nd=t=>typeof t=="string"&&o1.includes(t),Ya=t=>t==="fill"?Ei:_f(i1[t])??Ei,Qo=t=>{const e=Ti(t);if(!e)return{mode:"fill",width:null,height:null};for(const n of["mobile","tablet","desktop"]){const r=Ya(n),o=Ti(r);if(o&&o.width===e.width&&o.height===e.height)return{mode:n,width:e.width,height:e.height}}return{mode:"custom",width:e.width,height:e.height}},a1=t=>{const e=it.c(70),{viewport:n,onViewportChange:r,colorScheme:o,onColorSchemeChange:i,scale:c}=t,{t:a}=gt();let d;e[0]!==n?(d=Ti(n),e[0]=n,e[1]=d):d=e[1];const u=d,m=n.kind==="preset"?n.id:"";let f;e[2]!==r||e[3]!==u?(f=(he,xe)=>{const H=Number.parseInt(xe,10);if(!Number.isFinite(H))return;const we=u??{width:1280,height:800};r({kind:"custom",width:sd(he==="width"?H:we.width),height:sd(he==="height"?H:we.height)})},e[2]=r,e[3]=u,e[4]=f):f=e[4];const g=f;let x;e[5]===Symbol.for("react.memo_cache_sentinel")?(x=ge("h-6 w-14 rounded-full border border-border/50 bg-[var(--surface-elevated)] px-2 text-center","typography-micro tabular-nums text-foreground outline-none focus:border-[var(--interactive-focus-ring)]"),e[5]=x):x=e[5];const j=x;let w;e[6]!==r?(w=he=>{const xe=_f(he.target.value);r(xe??Ei)},e[6]=r,e[7]=w):w=e[7];let p;e[8]!==a?(p=a("contextPanel.browser.device.preset"),e[8]=a,e[9]=p):p=e[9];let h;e[10]===Symbol.for("react.memo_cache_sentinel")?(h=ge("h-6 shrink-0 rounded-full border border-border/50 bg-[var(--surface-elevated)] px-2","typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]"),e[10]=h):h=e[10];let b;e[11]!==a?(b=a("contextPanel.browser.device.responsive"),e[11]=a,e[12]=b):b=e[12];let v;e[13]!==b?(v=s.jsx("option",{value:"",children:b}),e[13]=b,e[14]=v):v=e[14];let S;e[15]===Symbol.for("react.memo_cache_sentinel")?(S=Bf.map(l1),e[15]=S):S=e[15];let N;e[16]!==m||e[17]!==w||e[18]!==p||e[19]!==v?(N=s.jsxs("select",{value:m,onChange:w,"aria-label":p,className:h,children:[v,S]}),e[16]=m,e[17]=w,e[18]=p,e[19]=v,e[20]=N):N=e[20];const A=u?String(u.width):"";let k;e[21]!==g?(k=he=>g("width",he.target.value),e[21]=g,e[22]=k):k=e[22];let C;e[23]!==a?(C=a("contextPanel.browser.device.width"),e[23]=a,e[24]=C):C=e[24];let P;e[25]!==A||e[26]!==k||e[27]!==C?(P=s.jsx("input",{value:A,onChange:k,placeholder:"—",inputMode:"numeric","aria-label":C,className:j}),e[25]=A,e[26]=k,e[27]=C,e[28]=P):P=e[28];let D;e[29]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsx("span",{className:"typography-micro text-muted-foreground",children:"×"}),e[29]=D):D=e[29];const O=u?String(u.height):"";let F;e[30]!==g?(F=he=>g("height",he.target.value),e[30]=g,e[31]=F):F=e[31];let E;e[32]!==a?(E=a("contextPanel.browser.device.height"),e[32]=a,e[33]=E):E=e[33];let B;e[34]!==O||e[35]!==F||e[36]!==E?(B=s.jsx("input",{value:O,onChange:F,placeholder:"—",inputMode:"numeric","aria-label":E,className:j}),e[34]=O,e[35]=F,e[36]=E,e[37]=B):B=e[37];let $;e[38]!==r||e[39]!==n?($=()=>r(n1(n)),e[38]=r,e[39]=n,e[40]=$):$=e[40];const z=!u;let V;e[41]!==a?(V=a("contextPanel.browser.device.rotate"),e[41]=a,e[42]=V):V=e[42];let y;e[43]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(T,{name:"refresh",className:"size-3.5","aria-hidden":"true"}),e[43]=y):y=e[43];let I;e[44]!==$||e[45]!==z||e[46]!==V?(I=s.jsx(mt,{asChild:!0,children:s.jsx(lt,{type:"button",variant:"ghost",size:"xs",className:"w-6 shrink-0 rounded-full px-0 text-muted-foreground hover:text-foreground",onClick:$,disabled:z,"aria-label":V,children:y})}),e[44]=$,e[45]=z,e[46]=V,e[47]=I):I=e[47];let _;e[48]!==a?(_=a("contextPanel.browser.device.rotate"),e[48]=a,e[49]=_):_=e[49];let W;e[50]!==_?(W=s.jsx(ht,{sideOffset:6,children:_}),e[50]=_,e[51]=W):W=e[51];let K;e[52]!==I||e[53]!==W?(K=s.jsxs(ft,{children:[I,W]}),e[52]=I,e[53]=W,e[54]=K):K=e[54];let Z;e[55]!==c||e[56]!==u?(Z=u&&c<1?s.jsxs("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:[Math.round(c*100),"%"]}):null,e[55]=c,e[56]=u,e[57]=Z):Z=e[57];let Q;e[58]===Symbol.for("react.memo_cache_sentinel")?(Q=["system","light","dark"],e[58]=Q):Q=e[58];let le;e[59]!==o||e[60]!==i||e[61]!==a?(le=s.jsx("div",{className:"ml-auto flex shrink-0 items-center gap-1",children:Q.map(he=>s.jsx(lt,{type:"button",variant:o===he?"secondary":"ghost",size:"xs",className:ge("shrink-0 rounded-full px-2.5 typography-micro",o===he?"text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>i(he),"aria-pressed":o===he,children:a(he==="system"?"contextPanel.browser.device.schemeSystem":he==="light"?"contextPanel.browser.device.schemeLight":"contextPanel.browser.device.schemeDark")},he))}),e[59]=o,e[60]=i,e[61]=a,e[62]=le):le=e[62];let te;return e[63]!==N||e[64]!==P||e[65]!==B||e[66]!==K||e[67]!==Z||e[68]!==le?(te=s.jsxs("div",{className:"flex items-center gap-1.5 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[N,P,D,B,K,Z,le]}),e[63]=N,e[64]=P,e[65]=B,e[66]=K,e[67]=Z,e[68]=le,e[69]=te):te=e[69],te};function l1(t){return s.jsx("option",{value:t.id,children:t.label},t.id)}const c1=t=>{try{const e=new URL(t).pathname;return e==="/"?"":e}catch{return""}},d1=2e3,u1=()=>{if(typeof window>"u"||window.__OPENCHAMBER_ELECTRON__)return!1;const t=hr();if(!t)return!1;try{return!no(new URL(t,window.location.href).toString())}catch{return!1}},$f=t=>{const e=it.c(33),{onOpen:n,directory:r}=t,o=r===void 0?"":r,{t:i}=gt();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={kind:"loading"},e[0]=c):c=e[0];const[a,d]=l.useState(c),u=Fx(o),[m]=l.useState(u1);let f,g;e[1]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{let P=!0,D=null;const O=new AbortController,F=()=>{sv(O.signal).then(E=>{P&&(d(E),D=setTimeout(F,d1))})};return F(),()=>{P=!1,D&&clearTimeout(D),O.abort()}},g=[],e[1]=f,e[2]=g):(f=e[1],g=e[2]),l.useEffect(f,g);const x=a.kind==="ready"?a.servers:null;let j;e[3]!==u||e[4]!==x?(j=ov({announced:u,discovered:x}),e[3]=u,e[4]=x,e[5]=j):j=e[5];const w=j;let p;e[6]===Symbol.for("react.memo_cache_sentinel")?(p=s.jsx(ju,{width:110,height:110,className:"shrink-0 opacity-20"}),e[6]=p):p=e[6];let h;e[7]!==i?(h=i("contextPanel.browser.empty"),e[7]=i,e[8]=h):h=e[8];let b;e[9]!==h?(b=s.jsx("span",{className:"typography-ui-header text-foreground",children:h}),e[9]=h,e[10]=b):b=e[10];let v;e[11]!==i?(v=i("contextPanel.browser.emptyHint"),e[11]=i,e[12]=v):v=e[12];let S;e[13]!==v?(S=s.jsx("span",{className:"typography-micro text-muted-foreground",children:v}),e[13]=v,e[14]=S):S=e[14];let N;e[15]!==S||e[16]!==b?(N=s.jsxs("div",{className:"flex shrink-0 flex-col gap-1",children:[b,S]}),e[15]=S,e[16]=b,e[17]=N):N=e[17];let A;e[18]!==u||e[19]!==w||e[20]!==o||e[21]!==n||e[22]!==m||e[23]!==i?(A=w.length>0?s.jsxs("div",{className:"flex min-h-0 w-full max-w-sm flex-col gap-1",children:[s.jsx("span",{className:"shrink-0 typography-micro text-left text-muted-foreground",children:u.length>0?i("contextPanel.browser.devServers.justStarted"):i("contextPanel.browser.devServers.title")}),m?s.jsx("span",{className:"shrink-0 pb-1 text-left typography-micro text-muted-foreground",children:i("contextPanel.browser.devServers.remoteOnly")}):null,s.jsx("div",{className:"flex min-h-0 flex-col gap-1 overflow-y-auto pr-0.5",children:w.map(P=>s.jsxs(lt,{type:"button",variant:"outline",size:"sm",className:"w-full shrink-0 justify-start gap-2",onClick:()=>{Rx(o),n(P.url)},children:[s.jsx(T,{name:"global",className:"size-3.5 shrink-0","aria-hidden":"true"}),s.jsx("span",{className:"truncate",children:Pl(P.url)||P.url}),s.jsx("span",{className:"ml-auto truncate typography-micro text-muted-foreground",children:c1(P.url)})]},P.port))})]}):null,e[18]=u,e[19]=w,e[20]=o,e[21]=n,e[22]=m,e[23]=i,e[24]=A):A=e[24];let k;e[25]!==w.length||e[26]!==a.kind||e[27]!==i?(k=w.length===0&&a.kind==="unavailable"?s.jsx("span",{className:"typography-micro text-muted-foreground",children:i("contextPanel.browser.devServers.unavailable")}):null,e[25]=w.length,e[26]=a.kind,e[27]=i,e[28]=k):k=e[28];let C;return e[29]!==N||e[30]!==A||e[31]!==k?(C=s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-5 overflow-hidden bg-background p-6 text-center",children:[p,N,A,k]}),e[29]=N,e[30]=A,e[31]=k,e[32]=C):C=e[32],C},Ys=t=>Math.round(t),f1=(t,e)=>{const n=t.text.trim(),r=Object.entries(t.attributes).map(([a,d])=>`${a}="${d}"`).join(" "),o=t.ancestry.map(a=>a.selectorPart).join(" > "),i=t.computedStyle,c=t.bounds;return[`Element ${e+1}: ${t.tag}`,n?`- Text: ${n}`:null,`- Selector: ${t.selector}`,`- Path: ${t.path}`,o?`- Ancestry: ${o}`:null,r?`- Attributes: ${r}`:null,`- Bounds: x=${Ys(c.x)}, y=${Ys(c.y)}, width=${Ys(c.width)}, height=${Ys(c.height)}`,`- Styles: display=${i.display??""}; position=${i.position??""}; font=${i.fontWeight??""} ${i.fontSize??""} / ${i.lineHeight??""} ${i.fontFamily??""}; color=${i.color??""}; background=${i.backgroundColor??""}`].filter(a=>typeof a=="string")},m1=(t,e)=>{const n=t.rect;return`Region ${e+1}: x=${Ys(n.x)}, y=${Ys(n.y)}, width=${Ys(n.width)}, height=${Ys(n.height)}`},h1=(t,e)=>{const n=t.bounds;return`Drawing ${e+1}: ${t.points.length} points over x=${Ys(n.x)}, y=${Ys(n.y)}, width=${Ys(n.width)}, height=${Ys(n.height)}`},p1=({payload:t,screenshotAttached:e,intro:n})=>{const r=n.replace(/[.:]+$/g,""),o=t.comment.trim(),i=[`${r}:`,`Page: ${t.pageTitle.trim()||t.pageUrl||"browser"}`,t.pageTitle.trim()&&t.pageUrl?`URL: ${t.pageUrl}`:null,`Viewport: ${Ys(t.viewport.width)}x${Ys(t.viewport.height)}, DPR ${t.devicePixelRatio}`,`Screenshot: ${e?"attached":"not attached"}`,o?`Comment: ${o}`:null];for(const[c,a]of t.elements.entries())i.push("",...f1(a.element,c));return t.regions.length>0&&(i.push(""),t.regions.forEach((c,a)=>i.push(m1(c,a)))),t.strokes.length>0&&(i.push(""),t.strokes.forEach((c,a)=>i.push(h1(c,a)))),i.filter(c=>typeof c=="string").join(`
905
+ `)},g1=t=>{const e=it.c(7),{t:n}=gt(),r=ot(b1),o=ot(y1),i=Ma(v1),c=Lh(w1);let a;return e[0]!==c||e[1]!==i||e[2]!==r||e[3]!==t||e[4]!==o||e[5]!==n?(a=async d=>{const u=r??(o?"draft":null);if(!u){Ae.error(n("contextPanel.browser.annotate.noSession"));return}let m=!1;if(d.screenshot)try{await c(d.screenshot),m=!0}catch{m=!1}i({directory:t,sessionKey:u},{source:"preview-annotation",fileLabel:d.payload.pageUrl||"browser",startLine:1,endLine:1,code:p1({payload:d.payload,screenshotAttached:m,intro:n("contextPanel.browser.annotate.intro")}),language:"markdown",text:""}),Ae.success(n("contextPanel.browser.annotate.attached"))},e[0]=c,e[1]=i,e[2]=r,e[3]=t,e[4]=o,e[5]=n,e[6]=a):a=e[6],a},x1=()=>{const t=it.c(16),{t:e}=gt();let n;t[0]!==e?(n=e("contextPanel.browser.annotate.tool.element"),t[0]=e,t[1]=n):n=t[1];let r;t[2]!==e?(r=e("contextPanel.browser.annotate.tool.region"),t[2]=e,t[3]=r):r=t[3];let o;t[4]!==e?(o=e("contextPanel.browser.annotate.tool.draw"),t[4]=e,t[5]=o):o=t[5];let i;t[6]!==e?(i=e("contextPanel.browser.annotate.commentPlaceholder"),t[6]=e,t[7]=i):i=t[7];let c;t[8]!==e?(c=e("contextPanel.browser.annotate.submit"),t[8]=e,t[9]=c):c=t[9];let a;return t[10]!==n||t[11]!==r||t[12]!==o||t[13]!==i||t[14]!==c?(a={select:n,marquee:r,draw:o,commentPlaceholder:i,submit:c},t[10]=n,t[11]=r,t[12]=o,t[13]=i,t[14]=c,t[15]=a):a=t[15],a};function b1(t){return t.currentSessionId}function y1(t){return t.newSessionDraft?.open}function v1(t){return t.addDraft}function w1(t){return t.addAttachedFile}const S1=3e4,j1=3,k1=250,C1={attempts:0,windowStartedAt:null},N1=(t,e)=>{const n=t.windowStartedAt===null||e-t.windowStartedAt>=S1,r=n?0:t.attempts;return r>=j1?null:{delayMs:k1*2**r,state:{attempts:r+1,windowStartedAt:n?e:t.windowStartedAt}}},A1=-3,Xo=t=>typeof t=="string"&&t.length>0&&t!=="about:blank",Gr=t=>{const e=t;return e.detail&&typeof e.detail=="object"?e.detail:t},D1=(t,{initialUrl:e,onUrlChange:n})=>{const[r,o]=l.useState(e?{kind:"loading",url:e}:lv),[i,c]=l.useState(e),[a,d]=l.useState(""),[u,m]=l.useState(!1),[f,g]=l.useState(!1),x=l.useRef(n);x.current=n;const j=l.useRef(C1);return l.useEffect(()=>{if(!t)return;const w=()=>{try{const D=t.getURL();return Xo(D)?D:""}catch{return""}},p=()=>{try{m(t.canGoBack()),g(t.canGoForward())}catch{}},h=D=>{Xo(D)&&(c(D),x.current(D))},b=()=>{const D=w();o({kind:"loading",url:D})},v=()=>{const D=w();let O="";try{O=t.getTitle()||""}catch{O=""}d(O),h(D),p(),o(F=>F.kind==="failed"&&F.url===D?F:{kind:"ready",url:D,title:O})},S=D=>{const O=Gr(D);Xo(O.url)&&(h(O.url),p())},N=D=>{const O=Gr(D),F=Array.isArray(O.favicons)?O.favicons.find(Boolean):"",E=w();F&&E&&kf.getState().resolve(E,F)},A=D=>{const O=Gr(D);typeof O.title=="string"&&d(O.title)},k=D=>{const O=Gr(D);if(O.isMainFrame===!1)return;const F=typeof O.errorCode=="number"?O.errorCode:0;F!==A1&&o({kind:"failed",url:Xo(O.validatedURL)?O.validatedURL:w(),code:F,description:typeof O.errorDescription=="string"?O.errorDescription:""})};let C=null;const P=()=>{const D=w(),O=N1(j.current,Date.now());if(!O){o({kind:"failed",url:D,code:0,description:"",crashed:!0});return}j.current=O.state,o({kind:"loading",url:D}),C=setTimeout(()=>{C=null;try{t.reload()}catch{o({kind:"failed",url:D,code:0,description:"",crashed:!0})}},O.delayMs)};t.addEventListener("did-start-loading",b),t.addEventListener("did-stop-loading",v),t.addEventListener("did-navigate",S),t.addEventListener("did-navigate-in-page",S),t.addEventListener("page-title-updated",A),t.addEventListener("page-favicon-updated",N),t.addEventListener("did-fail-load",k),t.addEventListener("render-process-gone",P),t.addEventListener("crashed",P);try{!t.isLoading()&&w()&&v()}catch{}return()=>{C!==null&&clearTimeout(C),t.removeEventListener("render-process-gone",P),t.removeEventListener("crashed",P),t.removeEventListener("did-start-loading",b),t.removeEventListener("did-stop-loading",v),t.removeEventListener("did-navigate",S),t.removeEventListener("did-navigate-in-page",S),t.removeEventListener("page-title-updated",A),t.removeEventListener("page-favicon-updated",N),t.removeEventListener("did-fail-load",k)}},[t]),{status:r,url:i,title:a,canGoBack:u,canGoForward:f}},P1=()=>typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,E1=4e4,rd=.5,T1=-3,I1=4,R1="persist:openchamber-browser",od=20,M1=600,O1=2e4,F1=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=gt(),{currentTheme:o}=_r(),i=l.useRef(null),[c,a]=l.useState(null),d=l.useCallback(J=>{i.current=J,a(J)},[]),u=pe(J=>J.setContextPanelTabTargetPath),m=l.useRef(Xr(t)),f=m.current!==yn?m.current:"",[g,x]=l.useState(f?null:yn),[j,w]=l.useState(f),[p,h]=l.useState(!1),[b,v]=l.useState(!1),[S,N]=l.useState(0),[A,k]=l.useState(!1),[C,P]=l.useState(Ei),D=l.useRef(C);D.current=C;const O=l.useRef([]),[F,E]=l.useState("system"),[B,$]=l.useState({width:0,height:0}),z=l.useRef(null),V=l.useRef(null),y=l.useRef(!1),I=l.useRef(Date.now()),_=l.useCallback(J=>{!J||J===yn||!e||!n||u(e,n,J)},[e,n,u]),W=D1(c,{initialUrl:f,onUrlChange:l.useCallback(J=>{const re=go(J);w(re),_(re)},[_])}),[K,Z]=l.useState(null),Q=g1(e),le=x1(),te=W.status.kind==="loading",he=to(Rf(e)),xe=to(J=>J.recordVisit),H=to(J=>J.forget);l.useEffect(()=>{W.status.kind==="ready"&&xe(e,{url:go(W.status.url),title:W.status.title})},[e,W.status,xe]);const we=l.useMemo(()=>If(he,j),[he,j]),de=l.useCallback(J=>{const re=Xr(J);re!==yn&&(w(re),Z(null),Jc(re).then(Y=>{const U=i.current;if(!U){x(Y);return}try{U.loadURL(Y)}catch{x(Y)}}).catch(Y=>{Y instanceof jo&&Z(re)}))},[]);l.useEffect(()=>{if(!f)return;let J=!0;return Jc(f).then(re=>{J&&x(re)}).catch(re=>{if(J){if(re instanceof jo){Z(f),x(yn);return}x(f)}}),()=>{J=!1}},[]);const q=l.useMemo(()=>({executeJavaScript:async(J,re)=>{const Y=i.current;if(!Y)throw new Error("Browser view is not available");return Y.executeJavaScript(J,re)},capturePage:async()=>{const J=i.current;if(!J)return null;const re=J.getWebContentsId();return Number.isFinite(re)?await vo("desktop_browser_capture_page",{webContentsId:re}):null}}),[]),me=l.useCallback(()=>{if(p){h(!1),ui(q);return}if(!W.url){Ae.error(r("contextPanel.browser.annotate.noPage"));return}const J=Sv(o.metadata.variant==="light"?"light":"dark");h(!0),vv({host:q,theme:J,labels:le}).then(async re=>{h(!1),re&&await Q(re)}).catch(()=>{h(!1),Ae.error(r("contextPanel.browser.annotate.failed"))})},[q,Q,o,p,W.url,le,r]);l.useEffect(()=>{if(!p)return;const J=re=>{re.key==="Escape"&&(re.preventDefault(),re.stopImmediatePropagation(),h(!1),ui(q))};return window.addEventListener("keydown",J,!0),()=>window.removeEventListener("keydown",J,!0)},[q,p]);const be=l.useCallback(async(J=8e3)=>{const re=Date.now();for(;;){const Y=i.current;if(!Y)return!1;let U=!1;try{U=Y.isLoading()}catch{return!1}if(!U)return!0;if(Date.now()-re>J)return!1;await new Promise(fe=>setTimeout(fe,120))}},[]),Pe=l.useCallback(async(J,re)=>{const Y=i.current;if(!Y)throw new Error("The browser panel is not ready");const U=()=>{nd(re.viewport)&&(P(Ya(re.viewport)),k(!0))};if(J==="browser.back"||J==="browser.forward"){const $e=J==="browser.back";if(!($e?Y.canGoBack():Y.canGoForward()))throw new Error($e?"There is nothing to go back to in this tab":"There is nothing to go forward to in this tab");$e?Y.goBack():Y.goForward(),await new Promise(ue=>setTimeout(ue,150)),await be();let Re="";try{Re=Y.getTitle()||""}catch{Re=""}return{url:go(Y.getURL()),title:Re}}if(J==="browser.capture"){await be();const $e=await q.capturePage();if(!$e)throw new Error("The page could not be captured");let ie="";try{ie=Y.getTitle()||""}catch{ie=""}return{...$e,url:go(Y.getURL()),title:ie,viewport:Qo(D.current)}}if(J==="browser.resize"){if(!nd(re.viewport))throw new Error("viewport is required");return U(),await new Promise($e=>setTimeout($e,200)),await be(),{viewport:Qo(Ya(re.viewport))}}if(J==="browser.open"){const $e=typeof re.url=="string"?re.url:"";if(!$e)throw new Error("url is required");U(),de($e),await new Promise(ue=>setTimeout(ue,150));const ie=await be(25e3);let Re="";try{Re=Y.getTitle()||""}catch{Re=""}return{url:Xr($e),title:Re,opened:!0,settled:ie,viewport:Qo(D.current)}}await be();const fe=$e=>typeof $e=="string"&&$e?$e:void 0,ce=(()=>{switch(J){case"browser.snapshot":return Yv({selector:fe(re.selector)});case"browser.click":return Qv({selector:fe(re.selector),text:fe(re.text)});case"browser.type":return Xv({selector:String(re.selector??""),value:String(re.value??""),submit:re.submit===!0});case"browser.inspect":return e1({selector:String(re.selector??"")});case"browser.scroll":return Jv({selector:fe(re.selector),direction:fe(re.direction)});default:return null}})();if(!ce)throw new Error(`Unsupported browser action: ${J}`);const Fe=await Y.executeJavaScript(ce,!0);if(!Fe||typeof Fe!="object")throw new Error("The page returned no result");const Ye=Fe;if(Ye.ok!==!0)throw new Error(typeof Ye.error=="string"&&Ye.error?Ye.error:"Browser action failed");if(J==="browser.snapshot"){const $e=O.current;return{...Ye,viewport:Qo(D.current),...$e.length>0?{consoleProblems:[...$e]}:{}}}return(J==="browser.click"||J==="browser.type"&&re.submit===!0)&&(await new Promise($e=>setTimeout($e,150)),await be()),Fe},[q,de,be]);l.useEffect(()=>Mv({run:Pe}),[Pe]),l.useEffect(()=>{const J=q;return()=>{ui(J)}},[q]),l.useEffect(()=>{if(!c)return;const J=Y=>{const U=Y;if(typeof U.level!="number"||U.level<2)return;const fe=U.sourceId?`${U.sourceId}${U.line?`:${U.line}`:""}`:"";O.current.push({level:U.level>=3?"error":"warning",message:String(U.message??"").slice(0,400),source:fe}),O.current.length>od&&O.current.splice(0,O.current.length-od)},re=()=>{O.current=[]};return c.addEventListener("console-message",J),c.addEventListener("did-start-loading",re),()=>{c.removeEventListener("console-message",J),c.removeEventListener("did-start-loading",re)}},[c]);const Ie=l.useRef(new Set),De=l.useCallback(J=>{Ie.current.clear(),de(J)},[de]);l.useEffect(()=>{if(!c)return;const J=Y=>{const U=Gr(Y),fe=typeof U.url=="string"?U.url:"";!fe||!Zc(fe)||(Y.preventDefault(),de(fe))},re=Y=>{const U=Gr(Y);if(U.isMainFrame===!1||U.errorCode===-3)return;const fe=typeof U.validatedURL=="string"?U.validatedURL:"";!fe||!Zc(fe)||Ie.current.has(fe)||(Ie.current.add(fe),de(fe))};return c.addEventListener("will-navigate",J),c.addEventListener("did-fail-load",re),()=>{c.removeEventListener("will-navigate",J),c.removeEventListener("did-fail-load",re)}},[de,c]),l.useEffect(()=>{if(!c)return;const J=re=>{const Y=re.detail;re.preventDefault(),Y?.url&&de(Y.url)};return c.addEventListener("new-window",J),()=>c.removeEventListener("new-window",J)},[de,c]);const Le=l.useCallback(J=>{const re=Math.min(I1,Math.max(T1,J));N(re);try{i.current?.setZoomLevel(re)}catch{}},[]),Ne=l.useCallback(J=>{vo("desktop_browser_clear_data",{partition:R1,cookies:J==="cookies",cache:J==="cache"}).then(()=>{Ae.success(r(J==="cookies"?"contextPanel.browser.clearedCookies":"contextPanel.browser.clearedCache"));try{i.current?.reloadIgnoringCache()}catch{}}).catch(()=>Ae.error(r("contextPanel.browser.clearFailed")))},[r]);l.useEffect(()=>{const J=z.current;if(!J||typeof ResizeObserver>"u")return;const re=new ResizeObserver(Y=>{const U=Y[0]?.contentRect;U&&$({width:U.width,height:U.height})});return re.observe(J),()=>re.disconnect()},[]);const ve=l.useCallback(J=>{E(J);const re=i.current;if(!re)return;let Y=-1;try{Y=re.getWebContentsId()}catch{return}vo("desktop_browser_set_color_scheme",{webContentsId:Y,scheme:J}).catch(U=>{E("system"),Ae.error(U instanceof Error?U.message:r("contextPanel.browser.device.schemeFailed"))})},[r]),Me=l.useCallback(()=>{try{te?i.current?.stop():i.current?.reload()}catch{}},[te]),ee=W.status;l.useEffect(()=>{const J=()=>{v(!0);const U=setTimeout(()=>{try{i.current?.reload()}catch{}},M1);return()=>clearTimeout(U)};if(ee.kind==="failed"){if(!ev(ee.code,ee.url)){v(!1);return}const U=Date.now(),fe=V.current?.url===ee.url?V.current:{url:ee.url,startedAt:U};if(V.current=fe,U-fe.startedAt>E1){v(!1);return}return J()}if(ee.kind==="loading")return;if(V.current=null,ee.kind!=="ready"||!ee.url||!no(ee.url)){y.current=!0,v(!1);return}if(y.current||Date.now()-I.current>O1){y.current=!0,v(!1);return}let re=!1,Y=null;return nv(go(ee.url)).then(U=>{if(!re){if(U===null||U<500){y.current=!0,v(!1);return}Y=J()}}),()=>{re=!0,Y?.()}},[ee]);const oe=W.status.kind==="failed"&&!b?W.status:null,Te=r1(C,B);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsx(Lf,{address:j,onAddressChange:w,onSubmit:De,suggestions:we,onForgetSuggestion:J=>H(e,J),onBack:()=>{try{i.current?.goBack()}catch{}},onForward:()=>{try{i.current?.goForward()}catch{}},onReload:Me,onOpenExternal:()=>{Bi(W.url||j)},canGoBack:W.canGoBack,canGoForward:W.canGoForward,isLoading:te,onAnnotate:me,isAnnotating:p,onOpenDevTools:()=>{try{i.current?.openDevTools()}catch{}},onHardReload:()=>{try{i.current?.reloadIgnoringCache()}catch{}},onZoomIn:()=>Le(S+rd),onZoomOut:()=>Le(S-rd),onZoomReset:()=>Le(0),zoomPercent:Math.round(Math.pow(1.2,S)*100),onClearCookies:()=>Ne("cookies"),onClearCache:()=>Ne("cache"),onToggleDeviceBar:()=>k(J=>!J),isDeviceBarOpen:A}),A?s.jsx(a1,{viewport:C,onViewportChange:P,colorScheme:F,onColorSchemeChange:ve,scale:Te?.scale??1}):null,s.jsxs("div",{ref:z,className:ge("relative min-h-0 flex-1 bg-background",Te&&"flex items-center justify-center overflow-hidden bg-[var(--surface-muted)]"),children:[g!==null?s.jsx("webview",{ref:d,src:g,partition:"persist:openchamber-browser",allowpopups:!0,style:Te?{width:`${Te.width}px`,height:`${Te.height}px`,transform:`scale(${Te.scale})`,border:"none",flex:"none",boxShadow:"0 2px 18px rgba(0,0,0,.28)"}:{width:"100%",height:"100%",border:"none"}}):null,g!==null&&!f&&!W.url&&!te?s.jsx($f,{onOpen:De,directory:e}):null,b?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 bg-background p-6 text-center",children:[s.jsx("span",{className:"typography-ui-header text-foreground",children:r("contextPanel.browser.waitingForServer")}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:r("contextPanel.browser.waitingForServerHint")})]}):null,K?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 bg-background p-6 text-center",children:[s.jsx("span",{className:"typography-ui-header text-foreground",children:r("contextPanel.browser.tunnelFailed")}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:r("contextPanel.browser.tunnelFailedHint",{url:K})})]}):null,oe&&!K?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 bg-background p-6 text-center",children:[s.jsx("span",{className:"typography-ui-header text-foreground",children:oe.crashed?r("contextPanel.browser.crashed"):r("contextPanel.browser.loadFailed")}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:oe.crashed?r("contextPanel.browser.crashedHint"):oe.description||r("contextPanel.browser.loadFailedUnknown")})]}):null,te?s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-0.5 overflow-hidden",children:s.jsx("div",{className:"h-full w-1/3 animate-[browser-progress_1.1s_ease-in-out_infinite] bg-[var(--primary)]"})}):null]})]})},L1=t=>{const e=it.c(49),{initialUrl:n,directory:r,tabID:o}=t,{t:i}=gt(),c=pe(_1);let a;e[0]!==n?(a=Xr(n),e[0]=n,e[1]=a):a=e[1];const d=a,u=d!==yn?d:"",[m,f]=l.useState(u),[g,x]=l.useState(u);let j;e[2]!==u?(j=u?[u]:[],e[2]=u,e[3]=j):j=e[3];const[w,p]=l.useState(j),[h,b]=l.useState(u?0:-1),[v,S]=l.useReducer($1,0);let N;e[4]!==r||e[5]!==c||e[6]!==o?(N=te=>{!te||te===yn||!r||!o||c(r,o,te)},e[4]=r,e[5]=c,e[6]=o,e[7]=N):N=e[7];const A=N;let k;e[8]!==r?(k=Rf(r),e[8]=r,e[9]=k):k=e[9];const C=to(k),P=to(z1),D=to(U1);let O;e[10]!==m||e[11]!==C?(O=If(C,m),e[10]=m,e[11]=C,e[12]=O):O=e[12];const F=O;let E;e[13]!==r||e[14]!==h||e[15]!==A||e[16]!==P?(E=te=>{const he=Xr(te);he!==yn&&(f(he),x(he),A(he),P(r,{url:he}),p(xe=>{const H=h>=0?xe.slice(0,h+1):[];return H[H.length-1]===he?(b(H.length-1),H):(b(H.length),[...H,he])}))},e[13]=r,e[14]=h,e[15]=A,e[16]=P,e[17]=E):E=e[17];const B=E;let $;e[18]!==w||e[19]!==A?($=te=>{const he=w[te];he&&(b(te),f(he),x(he),A(he))},e[18]=w,e[19]=A,e[20]=$):$=e[20];const z=$;let V;e[21]!==r||e[22]!==D?(V=te=>D(r,te),e[21]=r,e[22]=D,e[23]=V):V=e[23];let y,I;e[24]!==z||e[25]!==h?(I=()=>z(h-1),y=()=>z(h+1),e[24]=z,e[25]=h,e[26]=y,e[27]=I):(y=e[26],I=e[27]);let _;e[28]!==m||e[29]!==g?(_=()=>{Bi(g||m)},e[28]=m,e[29]=g,e[30]=_):_=e[30];const W=h>0,K=h>=0&&h<w.length-1;let Z;e[31]!==m||e[32]!==B||e[33]!==F||e[34]!==y||e[35]!==_||e[36]!==W||e[37]!==K||e[38]!==V||e[39]!==I?(Z=s.jsx(Lf,{address:m,onAddressChange:f,onSubmit:B,suggestions:F,onForgetSuggestion:V,onBack:I,onForward:y,onReload:S,onOpenExternal:_,canGoBack:W,canGoForward:K,isLoading:!1}),e[31]=m,e[32]=B,e[33]=F,e[34]=y,e[35]=_,e[36]=W,e[37]=K,e[38]=V,e[39]=I,e[40]=Z):Z=e[40];let Q;e[41]!==g||e[42]!==B||e[43]!==v||e[44]!==i?(Q=s.jsx("div",{className:"relative min-h-0 flex-1 bg-background",children:g?s.jsx("iframe",{src:g,title:i("contextPanel.browser.frameTitle"),className:"h-full w-full border-none bg-white",sandbox:"allow-scripts allow-forms allow-same-origin allow-popups"},`${g}|${v}`):s.jsx($f,{onOpen:B})}),e[41]=g,e[42]=B,e[43]=v,e[44]=i,e[45]=Q):Q=e[45];let le;return e[46]!==Z||e[47]!==Q?(le=s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[Z,Q]}),e[46]=Z,e[47]=Q,e[48]=le):le=e[48],le},B1=t=>{const e=it.c(3),[n]=l.useState(P1);let r;return e[0]!==n||e[1]!==t?(r=n?s.jsx(F1,{...t}):s.jsx(L1,{...t}),e[0]=n,e[1]=t,e[2]=r):r=e[2],r};function _1(t){return t.setContextPanelTabTargetPath}function $1(t){return t+1}function z1(t){return t.recordVisit}function U1(t){return t.forget}const W1=an(()=>on(()=>import("./WalkthroughView-Bxun3k66.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121])).then(t=>({default:t.WalkthroughView}))),V1=an(()=>on(()=>import("./DiffView-BWNq-0ov.js"),__vite__mapDeps([122,1,2,4,5,6,7,8,3,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121])).then(t=>({default:t.DiffView}))),H1=an(()=>on(()=>import("./FilesView-DB-Q0Gkz.js"),__vite__mapDeps([123,1,2,4,5,6,7,8,3,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,114,124,125,126,127,128,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,129,130,115,116,119,131,132,113,133])).then(t=>({default:t.FilesView}))),K1=an(()=>on(()=>import("./GitView-DsWXqWx3.js"),__vite__mapDeps([134,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,114,135,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,115,116,118,119,120,121])).then(t=>({default:t.GitView}))),G1=an(()=>on(()=>import("./PlanView-UvuxIl9-.js"),__vite__mapDeps([136,1,2,4,5,6,7,8,124,50,51,52,53,54,55,72,48,49,56,125,126,127,3,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,73,74,75,76,77,78,79,80,81,113,114,133,115,116,101,102,86,87,88,89,90,91,92,93,94,95,96,97,98,99])).then(t=>({default:t.PlanView}))),q1=380,Y1=1400,zf=600,Q1=100,X1=24,Ii=new Map,J1=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+$/g,"");return r=r.replace(/\/+/g,"/"),n&&!r.startsWith("//")&&(r=`/${r}`),r===""?e.startsWith("/")?"/":"":r},id=t=>Number.isFinite(t)?Math.min(Y1,Math.max(q1,Math.round(t))):zf,Z1=t=>{const e=t?.parentElement?.clientWidth;return!e||e<=0?null:e},ew=(t,e)=>{if(!t)return"";const n=t.replace(/\\/g,"/"),r=e.replace(/\\/g,"/").replace(/\/+$/,"");return r&&n.startsWith(r+"/")?n.slice(r.length+1):n},Uf=(t,e)=>e(t==="chat"?"contextPanel.mode.chat":t==="file"?"contextPanel.mode.files":t==="diff"?"contextPanel.mode.diff":t==="walkthrough"?"contextPanel.mode.walkthrough":t==="plan"?"contextPanel.mode.plan":t==="browser"?"contextPanel.mode.browser":t==="git"?"layout.rightSidebar.git":t==="pr"?"contextPanel.mode.pr":t==="notes"?"contextRail.surface.notes":t==="terminal"?"layout.mainTab.terminal":"contextPanel.mode.context"),tw=t=>{if(!t)return null;const e=t.replace(/\\/g,"/").trim();if(!e)return null;const n=e.split("/").filter(Boolean);return n.length===0?e:n[n.length-1]||null},sw=(t,e,n)=>{if(t.mode==="chat"){const r=Qa(t.dedupeKey);if(r){const i=e.get(r)?.trim();if(i)return i}const o=t.sessionTitleFallback?.trim();return o||n("contextPanel.mode.chat")}return t.mode==="browser"?Pl(t.targetPath??"")||t.label||n("contextPanel.mode.browser"):t.label?t.label:t.mode==="file"?tw(t.targetPath)||n("contextPanel.mode.files"):t.mode==="diff"?n("contextPanel.mode.diff"):Uf(t.mode,n)},ad=(t,e={})=>{if(t.mode==="file")return t.targetPath?s.jsx(fl,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(rf,{className:"h-3.5 w-3.5"});if(t.mode==="walkthrough")return s.jsx(T,{name:"route",className:"h-3.5 w-3.5"});if(t.mode==="git")return s.jsx(T,{name:"git-branch",className:"h-3.5 w-3.5"});if(t.mode==="pr")return s.jsx(T,{name:"github",className:"h-3.5 w-3.5"});if(t.mode==="notes")return s.jsx(T,{name:"sticky-note",className:"h-3.5 w-3.5"});if(t.mode==="terminal")return s.jsx(T,{name:"terminal-box",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(T,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(T,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(T,{name:"chat-4",className:"h-3.5 w-3.5"});if(t.mode==="browser"){const n=nw(t.targetPath??"",e);return n?s.jsx("img",{src:n,alt:"","aria-hidden":"true",className:"h-3.5 w-3.5 rounded-[3px] object-contain"}):s.jsx(T,{name:"global",className:"h-3.5 w-3.5"})}},nw=(t,e)=>{try{return e[new URL(t).origin]??""}catch{return""}},rw=200,ow=480,iw=({visible:t})=>{const{t:e}=gt(),n=pe(h=>h.contextEditorTreeWidth),r=pe(h=>h.setContextEditorTreeWidth),[o,i]=l.useState(!1),c=l.useRef(0),a=l.useRef(n),d=l.useRef(null),u=l.useRef(null),m=l.useRef(null),f=l.useCallback(h=>Math.min(ow,Math.max(rw,Math.round(h))),[]),g=l.useCallback(h=>{const b=m.current;b&&(b.style.width=`${h}px`,b.style.setProperty("--oc-editor-tree-width",`${h}px`))},[]),x=h=>{if(t){try{h.currentTarget.setPointerCapture(h.pointerId)}catch{}u.current=h.pointerId,i(!0),c.current=h.clientX,a.current=n,d.current=n,h.preventDefault()}},j=h=>{if(!o||u.current!==h.pointerId)return;const b=c.current-h.clientX,v=f(a.current+b);d.current!==v&&(d.current=v,g(v))},w=h=>{if(u.current!==h.pointerId)return;try{h.currentTarget.releasePointerCapture(h.pointerId)}catch{}const b=f(d.current??n);u.current=null,d.current=null,i(!1),r(b)},p=t?n:0;return s.jsxs("div",{ref:m,className:ge("relative h-full flex-shrink-0 overflow-hidden border-l border-border bg-background will-change-[width] motion-reduce:transition-none",!t&&"border-l-0"),style:{width:`${o?d.current??p:p}px`,"--oc-editor-tree-width":`${o?d.current??n:n}px`,overflowX:"clip",transitionProperty:o?"none":"width",transitionDuration:"200ms",transitionTimingFunction:"cubic-bezier(0.22, 1, 0.36, 1)"},"aria-hidden":!t,children:[t&&s.jsx("div",{className:ge("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",o&&"bg-[var(--interactive-border)]"),onPointerDown:x,onPointerMove:j,onPointerUp:w,onPointerCancel:w,role:"separator","aria-orientation":"vertical","aria-label":e("contextPanel.actions.resizePanelAria")}),s.jsx("div",{className:ge("relative z-10 h-full shrink-0 transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none",o&&"pointer-events-none",!t&&"pointer-events-none select-none opacity-0"),style:{width:"var(--oc-editor-tree-width)"},"aria-hidden":!t,children:s.jsx(jy,{})})]})},Qa=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,aw=(t,e)=>{if(t.size!==e.size)return!1;for(const[n,r]of t)if(e.get(n)!==r)return!1;return!0},lw=(t,e)=>{if(e.length===0)return Ii;const n=new Set(e),r=new Map;for(const o of t){if(!n.has(o.id))continue;const i=o.title?.trim();i&&r.set(o.id,i)}return r.size===0?Ii:r},cw=(t,e)=>{const n=ll(t),r=l.useRef(Ii),o=l.useRef(e);return o.current=e,l.useSyncExternalStore(n.subscribe,l.useCallback(()=>{const i=lw(n.getState().session,o.current);return aw(r.current,i)?r.current:(r.current=i,i)},[n]),()=>Ii)},dw=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,uw=()=>{const{t}=gt(),e=Io()??"",n=l.useMemo(()=>J1(e),[e]),r=pe(se=>n?se.contextPanelByDirectory[n]:void 0),o=pe(se=>se.closeContextPanel),i=pe(se=>se.closeContextPanelTab),c=pe(se=>se.openContextPanelTab),a=pe(se=>se.toggleContextPanelExpanded),d=pe(se=>se.setContextPanelWidth),u=pe(se=>se.setActiveContextPanelTab),m=pe(se=>se.openContextBrowser);l.useEffect(()=>{if(e)return Ov(se=>m(e,se))},[e,m]);const f=pe(se=>se.reorderContextPanelTabs),g=Bn(se=>se.setSelectedPath),x=pe(se=>se.contextEditorTreeVisible),j=pe(se=>se.toggleContextEditorTree),w=pe(se=>se.openNewContextBrowserTab),p=kf(se=>se.byOrigin),h=pe(se=>se.allowPromptingSubagentSessions),{themeMode:b,setThemeMode:v,lightThemeId:S,darkThemeId:N,currentTheme:A}=_r(),k=l.useMemo(()=>r?.tabs??[],[r?.tabs]),C=k.find(se=>se.id===r?.activeTabId)??k[k.length-1]??null,P=!!(r?.isOpen&&C),D=!!(P&&r?.expanded),[O,F]=l.useState(null),E=C?.mode??null,B=E?r?.widthByMode?.[E]:void 0,$=E?Bh(E):.5,z=O??(typeof window<"u"?window.innerWidth:zf*2),V=id(B??Math.round($*z)),y=l.useMemo(()=>{const se=[];for(const je of k){if(je.mode!=="chat")continue;const Ze=Qa(je.dedupeKey);Ze&&!se.includes(Ze)&&se.push(Ze)}return se},[k]),I=cw(n||void 0,y),[_,W]=l.useState(!1),K=l.useRef(0),Z=l.useRef(V),Q=l.useRef(null),le=l.useRef(null),te=l.useRef(null),he=l.useRef(new Map),xe=l.useRef(new Map),H=l.useRef(!1);l.useLayoutEffect(()=>{const se=te.current?.parentElement;if(!se||typeof ResizeObserver>"u")return;const je=new ResizeObserver(()=>{F(se.clientWidth||null)});return je.observe(se),F(se.clientWidth||null),()=>je.disconnect()},[]),l.useEffect(()=>{if(!P||H.current){H.current=P;return}const se=window.requestAnimationFrame(()=>{te.current?.focus({preventScroll:!0})});return H.current=!0,()=>window.cancelAnimationFrame(se)},[P]);const we=l.useRef(null),de=l.useRef(null),q=l.useCallback(()=>{de.current=null;const se=te.current,je=Q.current;!se||je===null||se.style.setProperty("--oc-context-panel-width",`${je}px`)},[]);l.useEffect(()=>()=>{de.current!==null&&clearTimeout(de.current)},[]);const me=l.useCallback(se=>{const je=id(se),Ze=we.current;return Ze===null?je:Math.min(je,Math.max(1,Ze))},[]),be=l.useCallback(se=>{!P||D||!n||(le.current=se.pointerId,W(!0),K.current=se.clientX,Z.current=V,Q.current=V,we.current=Z1(te.current),document.documentElement.style.cursor="col-resize",se.preventDefault())},[n,D,P,V]),Pe=l.useCallback(()=>{const se=me(Q.current??V);Q.current=null,we.current=null,de.current!==null&&(clearTimeout(de.current),de.current=null),document.documentElement.style.cursor="",n&&E&&d(n,E,se),W(!1),le.current=null},[E,me,n,d,V]);l.useEffect(()=>{if(!_)return;const se=X=>{if(le.current!==X.pointerId)return;const ye=K.current-X.clientX,Xe=me(Z.current+ye);Q.current!==Xe&&(Q.current=Xe,de.current===null&&(de.current=setTimeout(q,Q1)))},je=X=>{le.current===X.pointerId&&Pe()},Ze=()=>{Pe()};return window.addEventListener("pointermove",se),window.addEventListener("pointerup",je),window.addEventListener("pointercancel",je),window.addEventListener("blur",Ze),()=>{window.removeEventListener("pointermove",se),window.removeEventListener("pointerup",je),window.removeEventListener("pointercancel",je),window.removeEventListener("blur",Ze)}},[q,me,Pe,_]),l.useEffect(()=>{_||(Q.current=null,document.documentElement.style.cursor="")},[_]);const Ie=l.useCallback(()=>{n&&o(n)},[o,n]),De=l.useCallback(()=>{n&&a(n)},[n,a]),Le=l.useCallback(se=>{se.key==="Escape"&&(_h(se.target)||(se.preventDefault(),se.stopPropagation(),Ie()))},[Ie]);l.useEffect(()=>{if(!(!n||!C)&&C.mode==="file"&&C.targetPath){g(n,C.targetPath,{allowOutsideRoot:!0});return}},[C,n,g]);const Ne=l.useMemo(()=>k.filter(se=>se.mode==="chat"),[k]),ve=P&&C?.mode==="chat"?C.id:null,Me=P&&C?.mode==="chat"?Qa(C.dedupeKey):null,ee=sx(Ne,ve);l.useEffect(()=>{if(!P||!n||!Me||typeof window>"u")return;const se=()=>{if(document.visibilityState==="hidden"||!document.hasFocus()){da(n,Me,!1);return}ku(Me),da(n,Me,!0)};se();const je=window.setInterval(se,1e4);return window.addEventListener("focus",se),window.addEventListener("blur",se),document.addEventListener("visibilitychange",se),()=>{window.clearInterval(je),window.removeEventListener("focus",se),window.removeEventListener("blur",se),document.removeEventListener("visibilitychange",se),da(n,Me,!1)}},[Me,n,P]);const oe=l.useCallback((se,je,Ze)=>nx(xe.current,se,je,n||null,Ze,{mode:b,lightThemeId:S,darkThemeId:N,currentTheme:A},{allowPromptingSubagentSessions:h}),[h,A,N,n,S,b]),Te=ee&&Me?oe(ee.id,Me,ee.readOnly):null;l.useEffect(()=>{const se=new Set(k.map(je=>je.id));for(const je of xe.current.keys())se.has(je)||xe.current.delete(je)},[k]);const J=l.useCallback(se=>{!n||C?.mode!=="diff"||c(n,{mode:"diff",targetPath:C.targetPath,stagedDiff:se==="staged",diffScope:se})},[C,n,c]),re=l.useCallback(()=>{if(typeof window>"u")return;const se={themeMode:b,lightThemeId:S,darkThemeId:N,currentTheme:A};for(const je of he.current.values()){const Ze=je.contentWindow;Ze&&Ze.postMessage({type:"openchamber:theme-sync",payload:se},window.location.origin)}},[A,N,S,b]),Y=l.useCallback(()=>{if(typeof window>"u")return;const se={allowPromptingSubagentSessions:h};for(const je of he.current.values()){const Ze=je.contentWindow;Ze&&Ze.postMessage({type:"openchamber:chat-settings-sync",payload:se},window.location.origin)}},[h]),U=l.useCallback((se,je,Ze)=>{const X=je.contentWindow;X&&X.postMessage({type:tf,payload:{visible:ve===se}},Ze)},[ve]),fe=l.useCallback(()=>{if(!(typeof window>"u"))for(const[se,je]of he.current.entries())U(se,je,window.location.origin)},[U]);l.useEffect(()=>{if(typeof window>"u")return;const se=je=>{if(je.origin!==window.location.origin)return;const Ze=Array.from(he.current.entries()).find(([,We])=>We.contentWindow===je.source);if(!Ze)return;const X=je.data;if(X?.type===rx){const[We,_e]=Ze;U(We,_e,je.origin);return}if(X?.type===ox){if(typeof X.requestId!="string"||!X.requestId)return;const We=Ps(),_e={apiBaseUrl:hr(),clientToken:Co(),localOrigin:typeof window.__OPENCHAMBER_LOCAL_ORIGIN__=="string"?window.__OPENCHAMBER_LOCAL_ORIGIN__:"",runtimeHeaders:lu(),relayHostId:We.startsWith("host:")?We.slice(5):"",relay:Vm()??void 0};je.source?.postMessage({type:ix,requestId:X.requestId,payload:_e},je.origin);return}if(X?.type==="openchamber:theme-sync-request"){re();return}if(X?.type==="openchamber:chat-settings-request"){Y();return}if(X?.type!=="openchamber:cycle-theme-request")return;const ye=["light","dark","system"],Be=(ye.indexOf(b)+1)%ye.length;v(ye[Be])};return window.addEventListener("message",se),()=>window.removeEventListener("message",se)},[Y,U,re,v,b]),l.useLayoutEffect(()=>{k.some(je=>je.mode==="chat")&&(re(),Y(),fe())},[N,S,Y,fe,re,k,b]);const ne=C?.mode==="file"||C?.mode==="chat"||C?.mode==="browser",ce=l.useMemo(()=>C?k.filter(se=>se.mode===C.mode):[],[C,k]),Fe=l.useMemo(()=>ce.map(se=>{const je=sw(se,I,t),Ze=dw(je,X1),X=ew(se.targetPath,e);return{id:se.id,label:Ze,icon:ad(se,p),title:X?`${je}: ${X}`:je,closeLabel:t("contextPanel.tab.closeTabAria",{label:Ze})}}),[ce,e,p,I,t]),Ye=C?.mode==="context"?s.jsx($y,{}):C?.mode==="git"?s.jsx(l.Suspense,{fallback:null,children:s.jsx(K1,{isActive:P})}):C?.mode==="pr"?s.jsx(Yb,{}):C?.mode==="notes"?s.jsx(qu,{}):C?.mode==="plan"?s.jsx(l.Suspense,{fallback:null,children:s.jsx(G1,{targetPath:C.targetPath,projectPlanId:C.projectPlanId})}):null,$e=l.useMemo(()=>k.filter(se=>se.mode==="browser"),[k]),ie=l.useMemo(()=>k.filter(se=>se.mode==="diff"),[k]),Re=l.useMemo(()=>k.some(se=>se.mode==="terminal"),[k]),ue=l.useMemo(()=>k.some(se=>se.mode==="walkthrough"),[k]),R=l.useMemo(()=>k.some(se=>se.mode==="file"),[k]),ae=l.useMemo(()=>k.some(se=>se.mode==="file"&&se.targetPath),[k]),Se=C?.mode==="file",Ce=s.jsxs("header",{className:"flex h-10 items-stretch border-b border-border",children:[ne?s.jsx(yl,{items:Fe,activeId:C?.id??null,onSelect:se=>{n&&u(n,se)},onClose:se=>{n&&i(n,se)},onReorder:(se,je)=>{n&&f(n,se,je)},layoutMode:"scrollable",variant:"default"}):s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 px-3",children:[C?ad(C,p):null,s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:C?Uf(C.mode,t):null})]}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[C?.mode==="browser"?s.jsx(lt,{type:"button",variant:"ghost",size:"sm",onClick:()=>{n&&w(n)},className:"h-7 w-7 p-0",title:t("contextPanel.browser.newTab"),"aria-label":t("contextPanel.browser.newTab"),children:s.jsx(T,{name:"add",className:"h-3.5 w-3.5"})}):null,Se?s.jsx(lt,{type:"button",variant:"ghost",size:"sm",onClick:j,className:"h-7 w-7 p-0",title:t("contextRail.editorTree.toggle"),"aria-label":t("contextRail.editorTree.toggle"),"aria-pressed":x,children:s.jsx(T,{name:"layout-right",className:"h-3.5 w-3.5"})}):null,s.jsx(lt,{type:"button",variant:"ghost",size:"sm",onClick:De,className:"h-7 w-7 p-0",title:t(D?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(D?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:D?s.jsx(T,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(T,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(lt,{type:"button",variant:"ghost",size:"sm",onClick:Ie,className:"h-7 w-7 p-0",title:t("contextPanel.actions.closePanel"),"aria-label":t("contextPanel.actions.closePanel"),children:s.jsx(T,{name:"close",className:"h-3.5 w-3.5"})})]})]}),Ee=P?D?{"--oc-context-panel-width":O!==null?`${O}px`:"100%",width:O!==null?`${O}px`:"100%",maxWidth:"100%"}:{width:"min(var(--oc-context-panel-width), 100%)",maxWidth:"100%",overflowX:"clip","--oc-context-panel-width":`${V}px`}:{"--oc-context-panel-width":`${V}px`,width:0,maxWidth:"100%",overflowX:"clip"};return s.jsxs("aside",{ref:te,"data-context-panel":"true",tabIndex:-1,inert:!P||void 0,className:ge("flex min-h-0 flex-col overflow-hidden bg-background",D?"absolute inset-y-0 right-0 z-20 min-w-0":"relative h-full flex-shrink-0",!P&&"pointer-events-none","will-change-[width] motion-reduce:transition-none","transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]"),onKeyDownCapture:Le,style:Ee,children:[P&&!D&&s.jsx("div",{"aria-hidden":"true",className:"absolute left-0 top-0 z-40 h-full w-px bg-border"}),P&&s.jsx("div",{"aria-hidden":"true",className:"absolute right-0 top-0 z-40 h-full w-px bg-border"}),!D&&s.jsx("div",{className:ge("absolute left-0 top-0 z-50 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",_&&"bg-[var(--interactive-border)]"),onPointerDown:be,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),s.jsxs("div",{className:ge("relative z-10 flex h-full min-h-0 shrink-0 flex-col duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none","transition-[width,opacity]",!P&&"pointer-events-none select-none opacity-0"),style:{width:D?O!==null?`${O}px`:"100%":"var(--oc-context-panel-width)"},"aria-hidden":!P,children:[Ce,s.jsxs("div",{className:ge("relative min-h-0 flex-1 overflow-hidden",_&&"pointer-events-none"),children:[R?s.jsxs("div",{className:ge("absolute inset-0 flex",Se?"flex":"hidden"),children:[s.jsx("div",{className:"h-full min-w-0 flex-1",children:ae?s.jsx(l.Suspense,{fallback:null,children:s.jsx(H1,{mode:"editor-only"})}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(T,{name:"file-code",className:"h-12 w-12 text-muted-foreground/50"}),s.jsx("div",{className:"typography-ui-header text-foreground",children:t("contextPanel.editorEmpty.title")}),s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:t("contextPanel.editorEmpty.description")})]})}),s.jsx(iw,{visible:x})]}):null,ee&&Me&&Te?s.jsx("iframe",{ref:se=>{if(!se){he.current.delete(ee.id);return}he.current.set(ee.id,se)},src:Te,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:Me}),className:"absolute inset-0 h-full w-full border-0 bg-background",onLoad:()=>{re(),Y(),fe()}},ee.id):null,$e.map(se=>s.jsx("div",{className:ge("absolute inset-0",C?.id!==se.id&&"hidden"),children:s.jsx(B1,{initialUrl:se.targetPath??"",directory:n,tabID:se.id})},se.id)),ie.map(se=>s.jsx("div",{className:ge("absolute inset-0",C?.id!==se.id&&"hidden"),children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(V1,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:se.diffScope??(se.stagedDiff?"staged":"working"),onDiffScopeChange:J,targetFilePath:se.targetPath,flushContent:!0})})},se.id)),Re?s.jsx("div",{className:ge("absolute inset-0",C?.mode==="terminal"?"block":"hidden"),children:s.jsx(Yu,{visible:P&&C?.mode==="terminal"})}):null,ue?s.jsx("div",{className:ge("absolute inset-0",C?.mode==="walkthrough"?"block":"hidden"),children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(W1,{directory:e})})}):null,C?.mode!=="chat"&&!Se&&C?.mode!=="browser"&&C?.mode!=="diff"&&C?.mode!=="terminal"&&C?.mode!=="walkthrough"?Ye:null]})]})]})},fw=150,mw=500,hw=[],pw=t=>t>99?"99+":String(t),gw=t=>{const e=it.c(51),{surface:n,isActive:r,showActivityDot:o,label:i,description:c,badgeCount:a,badgeAriaLabel:d,badgeDescription:u,orderNumber:m,showOrderNumber:f,onSelect:g}=t;let x;e[0]!==n.id?(x={id:n.id},e[0]=n.id,e[1]=x):x=e[1];const{attributes:j,listeners:w,setNodeRef:p,transform:h,transition:b,isDragging:v}=wl(x);let S;e[2]!==a?(S=a!=null&&a>0?pw(a):null,e[2]=a,e[3]=S):S=e[3];const N=S;let A;e[4]!==h?(A=Sl.Translate.toString(h),e[4]=h,e[5]=A):A=e[5];let k;e[6]!==A||e[7]!==b?(k={transform:A,transition:b},e[6]=A,e[7]=b,e[8]=k):k=e[8];const C=v&&"z-10 opacity-70";let P;e[9]!==C?(P=ge("relative",C),e[9]=C,e[10]=P):P=e[10];let D;e[11]!==g||e[12]!==n?(D=()=>g(n),e[11]=g,e[12]=n,e[13]=D):D=e[13];const O=d??i,F=r?"text-primary":"text-muted-foreground hover:text-foreground";let E;e[14]!==F?(E=ge("flex h-9 w-9 touch-none select-none items-center justify-center rounded-md transition-colors",F),e[14]=F,e[15]=E):E=e[15];let B;e[16]!==n.icon||e[17]!==n.id?(B=n.id==="diff"?s.jsx(rf,{}):s.jsx(T,{name:n.icon,className:"h-[18px] w-[18px]"}),e[16]=n.icon,e[17]=n.id,e[18]=B):B=e[18];let $;e[19]!==N||e[20]!==m||e[21]!==o||e[22]!==f?($=f&&m!=null?s.jsx("span",{"aria-hidden":"true",className:"absolute right-0 top-0 flex h-4 min-w-4 items-center justify-center rounded-full bg-surface-muted px-1 text-[0.625rem] font-medium leading-none text-muted-foreground",children:m===10?"0":m}):N?s.jsx("span",{"aria-hidden":"true",className:"absolute -right-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-[0.625rem] font-semibold leading-none",style:{backgroundColor:"var(--status-info-background)",color:"var(--status-info)"},children:N}):o?s.jsx("span",{"aria-hidden":"true",className:"absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-[var(--status-info)]"}):null,e[19]=N,e[20]=m,e[21]=o,e[22]=f,e[23]=$):$=e[23];let z;e[24]!==j||e[25]!==r||e[26]!==w||e[27]!==E||e[28]!==B||e[29]!==$||e[30]!==D||e[31]!==O?(z=s.jsx(mt,{asChild:!0,children:s.jsxs("button",{type:"button",...j,...w,onClick:D,"aria-label":O,"aria-pressed":r,className:E,children:[B,$]})}),e[24]=j,e[25]=r,e[26]=w,e[27]=E,e[28]=B,e[29]=$,e[30]=D,e[31]=O,e[32]=z):z=e[32];let V;e[33]!==i?(V=s.jsx("span",{children:i}),e[33]=i,e[34]=V):V=e[34];let y;e[35]!==c?(y=s.jsx("span",{className:"typography-micro text-muted-foreground",children:c}),e[35]=c,e[36]=y):y=e[36];let I;e[37]!==u?(I=u?s.jsx("span",{className:"typography-micro text-muted-foreground",children:u}):null,e[37]=u,e[38]=I):I=e[38];let _;e[39]!==V||e[40]!==y||e[41]!==I?(_=s.jsx(ht,{side:"left",sideOffset:8,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[V,y,I]})}),e[39]=V,e[40]=y,e[41]=I,e[42]=_):_=e[42];let W;e[43]!==z||e[44]!==_?(W=s.jsxs(ft,{delayDuration:fw,children:[z,_]}),e[43]=z,e[44]=_,e[45]=W):W=e[45];let K;return e[46]!==p||e[47]!==W||e[48]!==k||e[49]!==P?(K=s.jsx("div",{ref:p,style:k,className:P,children:W}),e[46]=p,e[47]=W,e[48]=k,e[49]=P,e[50]=K):K=e[50],K},xw=()=>{const t=it.c(52),{t:e}=gt(),n=Io();let r;t[0]!==n?(r=n?Vr(n):"",t[0]=n,t[1]=r):r=t[1];const o=r;let i;t[2]!==o?(i=Z=>o?Z.contextPanelByDirectory[o]:void 0,t[2]=o,t[3]=i):i=t[3];const c=pe(i),a=pe(bw),d=pe(yw),u=pe(vw),m=pe(ww),f=pe(Sw),g=cl(jw),{screenWidth:x}=xr(),j=dl(o||null);let w;t[4]!==f?(w=$h("switch_context_surface",f),t[4]=f,t[5]=w):w=t[5];const p=w,[h,b]=l.useState(!1);let v,S;t[6]!==p?(v=()=>{const Z=new Set;let Q=null,le=!1;const te=kw,he=()=>{sc(p,Z)?!le&&Q===null&&(Q=setTimeout(()=>b(!0),mw)):(le=!1,Q!==null&&(clearTimeout(Q),Q=null),b(!1))},xe=de=>{if(Z.add(de.key.toLowerCase()),te(de.key)&&sc(p,Z)){le=!0,Q!==null&&(clearTimeout(Q),Q=null),b(!1);return}he()},H=de=>{Z.delete(de.key.toLowerCase()),he()},we=()=>{Z.clear(),le=!1,Q!==null&&(clearTimeout(Q),Q=null),b(!1)};return window.addEventListener("keydown",xe,!0),window.addEventListener("keyup",H,!0),window.addEventListener("blur",we),()=>{window.removeEventListener("keydown",xe,!0),window.removeEventListener("keyup",H,!0),window.removeEventListener("blur",we),Q!==null&&clearTimeout(Q)}},S=[p],t[6]=p,t[7]=v,t[8]=S):(v=t[7],S=t[8]),l.useEffect(v,S);let N;t[9]===Symbol.for("react.memo_cache_sentinel")?(N={activationConstraint:{distance:8}},t[9]=N):N=t[9];let A;t[10]===Symbol.for("react.memo_cache_sentinel")?(A={activationConstraint:{delay:200,tolerance:6}},t[10]=A):A=t[10];const k=ki(Yr(dx,N),Yr(cx,A)),C=c?.tabs??hw;let P;t[11]!==c?.activeTabId||t[12]!==C?(P=C.find(Z=>Z.id===c?.activeTabId)??null,t[11]=c?.activeTabId,t[12]=C,t[13]=P):P=t[13];const D=P,O=c?.isOpen?D?.mode??null:null,F=j?.files.length??0;let E;t[14]!==d||t[15]!==g||t[16]!==x||t[17]!==C?(E=zh({railOrder:d,planModeEnabled:g,isVSCode:nr(),screenWidth:x,tabs:C}),t[14]=d,t[15]=g,t[16]=x,t[17]=C,t[18]=E):E=t[18];const B=E;let $;t[19]!==u?($=Z=>{const{active:Q,over:le}=Z;if(!le||Q.id===le.id)return;const te=Uh(pe.getState().contextRailOrder).map(Cw),he=te.indexOf(Q.id),xe=te.indexOf(le.id);he===-1||xe===-1||u(sf(te,he,xe))},t[19]=u,t[20]=$):$=t[20];const z=$;if(!o)return null;let V;t[21]!==e?(V=e("contextRail.aria.rail"),t[21]=e,t[22]=V):V=t[22];let y;t[23]!==B?(y=B.map(Nw),t[23]=B,t[24]=y):y=t[24];let I;if(t[25]!==O||t[26]!==F||t[27]!==o||t[28]!==m||t[29]!==h||t[30]!==B||t[31]!==e||t[32]!==a){let Z;t[34]!==O||t[35]!==F||t[36]!==o||t[37]!==m||t[38]!==h||t[39]!==e||t[40]!==a?(Z=(Q,le)=>{const te=e(Q.labelKey),he=Q.id==="git"&&!a?F:0,xe=he>0?he:null;return s.jsx(gw,{surface:Q,isActive:O===Q.mode,showActivityDot:!1,label:te,description:e(Q.descriptionKey),badgeCount:xe,badgeAriaLabel:xe!==null?e(xe===1?"contextRail.surface.git.changesCountAriaSingle":"contextRail.surface.git.changesCountAriaPlural",{label:te,count:xe}):null,badgeDescription:xe!==null?e(xe===1?"contextRail.surface.git.changesCountTooltipSingle":"contextRail.surface.git.changesCountTooltipPlural",{count:xe}):null,orderNumber:le+1,showOrderNumber:h,onSelect:H=>m(o,H.mode)},Q.id)},t[34]=O,t[35]=F,t[36]=o,t[37]=m,t[38]=h,t[39]=e,t[40]=a,t[41]=Z):Z=t[41],I=B.map(Z),t[25]=O,t[26]=F,t[27]=o,t[28]=m,t[29]=h,t[30]=B,t[31]=e,t[32]=a,t[33]=I}else I=t[33];let _;t[42]!==y||t[43]!==I?(_=s.jsx(za,{items:y,strategy:Ua,children:I}),t[42]=y,t[43]=I,t[44]=_):_=t[44];let W;t[45]!==z||t[46]!==k||t[47]!==_?(W=s.jsx(Ci,{sensors:k,collisionDetection:Ni,onDragEnd:z,children:_}),t[45]=z,t[46]=k,t[47]=_,t[48]=W):W=t[48];let K;return t[49]!==V||t[50]!==W?(K=s.jsx("nav",{"aria-label":V,className:"flex h-full w-11 flex-shrink-0 flex-col items-center gap-1 bg-background py-2",children:W}),t[49]=V,t[50]=W,t[51]=K):K=t[51],K};function bw(t){return t.workStatusPanelVisible}function yw(t){return t.contextRailOrder}function vw(t){return t.setContextRailOrder}function ww(t){return t.openContextSurface}function Sw(t){return t.shortcutOverrides}function jw(t){return t.planModeEnabled}function kw(t){return t.length===1&&t>="0"&&t<="9"}function Cw(t){return t.id}function Nw(t){return t.id}const Aw=(t,e)=>!t||e.length===0?"":JSON.stringify([t,e]),Dw=(t,e,n,r)=>!n||r!==n||t.length===0?[]:bo(t,e,o=>o.name,{limit:10,threshold:.4}),Pw=new Set,Ew=[],Xa=t=>{if(!t)return"";const e=t.replace(/\\/g,"/"),n=e.startsWith("//");let r=e.replace(/\/+/g,"/");n&&!r.startsWith("//")&&(r=`/${r}`);const o=r==="/",i=/^[A-Za-z]:\/$/.test(r);return!o&&!i&&(r=r.replace(/\/+$/,"")),r},Tw=()=>{const t=it.c(178),{t:e}=gt(),n=pe(Iw),r=pe(Rw),o=pe(Mw),i=pe(Ow),c=pe(Fw),a=pe(Lw),d=pe(Bw),u=pe(_w),m=pe($w),f=pe(zw),g=pe(Uw),x=ot(Ww),j=ot(Vw);let w;t[0]!==n?(w=He=>n?He.activeSessions:Ew,t[0]=n,t[1]=w):w=t[1];const p=Fs(w);let h;t[2]!==n?(h=He=>n?He.ids:Pw,t[2]=n,t[3]=h):h=t[3];const b=No(h);let v;t[4]!==n?(v=He=>n?He.rankById:hl,t[4]=n,t[5]=v):v=t[5];const S=Vi(v),N=ls(Hw),A=Gt(Kw),k=Gt(Gw),C=Io(),P=iu(qw),{files:D,git:O}=rr(),F=pr(Yw),{isMobile:E}=xr();let B;t[6]!==C?(B=C?Xa(C):null,t[6]=C,t[7]=B):B=t[7];const $=B,[z,V]=l.useState(""),I=ml(z,200).trim();let _;t[8]!==z?(_=z.trim(),t[8]=z,t[9]=_):_=t[9];const W=_;let K,Z;t[10]!==n?(K=()=>{n&&V("")},Z=[n],t[10]=n,t[11]=K,t[12]=Z):(K=t[11],Z=t[12]),l.useEffect(K,Z);let Q,le;t[13]!==p||t[14]!==F||t[15]!==O||t[16]!==n?(Q=()=>{if(!n||!O)return;const He=setTimeout(()=>{const Ve=new Set;for(const wt of p){const Ft=Qs(wt);!Ft||Ve.has(Ft)||(Ve.add(Ft),F(Ft,O))}},0);return()=>clearTimeout(He)},le=[n,p,O,F],t[13]=p,t[14]=F,t[15]=O,t[16]=n,t[17]=Q,t[18]=le):(Q=t[17],le=t[18]),l.useEffect(Q,le);let te;t[19]!==r?(te=()=>r(!1),t[19]=r,t[20]=te):te=t[20];const he=te;let xe;t[21]!==he?(xe=He=>()=>{he(),He()},t[21]=he,t[22]=xe):xe=t[22];const H=xe;let we;t[23]!==A?.id||t[24]!==A?.path||t[25]!==N||t[26]!==E||t[27]!==u||t[28]!==m||t[29]!==x||t[30]!==H||t[31]!==o||t[32]!==a||t[33]!==i||t[34]!==e||t[35]!==d?(we=()=>{const He=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(T,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:H(()=>{o("chat"),a(!1),x()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(T,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:H(Qw)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(T,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:H(Xw)},{id:"toggle-sidebar",title:e(E?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(T,{name:"layout-left",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_sidebar",searchText:e(E?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:H(()=>{if(E){const{isSessionSwitcherOpen:Ve}=pe.getState();a(!Ve)}else d()})},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(T,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:H(()=>{N&&m(N,"terminal")})},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(T,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:H(()=>{N&&u(N)})},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(T,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:H(()=>i(!0))}];return Fi()&&He.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(T,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:H(()=>{mr("desktop_open_draft_mini_chat_window",{directory:Xa(N||A?.path||""),projectId:A?.id??null}).catch(Jw)})}),He},t[23]=A?.id,t[24]=A?.path,t[25]=N,t[26]=E,t[27]=u,t[28]=m,t[29]=x,t[30]=H,t[31]=o,t[32]=a,t[33]=i,t[34]=e,t[35]=d,t[36]=we):we=t[36],A?.id,A?.path;let de;t[37]!==we?(de=we(),t[37]=we,t[38]=de):de=t[38];const q=de;let me;t[39]===Symbol.for("react.memo_cache_sentinel")?(me=Wn(),t[39]=me):me=t[39];const be=me;let Pe,Ie;t[40]===Symbol.for("react.memo_cache_sentinel")?(Pe=nr(),Ie=!be&&il(),t[40]=Pe,t[41]=Ie):(Pe=t[40],Ie=t[41]);let De;t[42]!==E?(De={isVSCode:Pe,isWeb:Ie,isDesktop:be,isMobile:E},t[42]=E,t[43]=De):De=t[43];const Le=De;let Ne;if(t[44]!==H||t[45]!==i||t[46]!==c||t[47]!==Le){let He;t[49]!==Le?(He=wt=>wt.isAvailable?wt.isAvailable(Le):!0,t[49]=Le,t[50]=He):He=t[50];let Ve;t[51]!==H||t[52]!==i||t[53]!==c?(Ve=wt=>{const Ft=Mg(wt.slug)??"settings-3",Lt=(wt.keywords??[]).join(" ");return{id:`settings:${wt.slug}`,title:wt.title,icon:wt.slug==="mcp"?s.jsx(gu,{className:"mr-2 h-4 w-4"}):s.jsx(T,{name:Ft,className:"mr-2 h-4 w-4"}),searchText:`${wt.title} ${wt.group} ${Lt}`,onSelect:H(()=>{c(wt.slug),i(!0)})}},t[51]=H,t[52]=i,t[53]=c,t[54]=Ve):Ve=t[54],Ne=Rg.filter(Zw).filter(He).map(Ve),t[44]=H,t[45]=i,t[46]=c,t[47]=Le,t[48]=Ne}else Ne=t[48];const ve=Ne;let Me;t[55]!==p||t[56]!==b||t[57]!==S?(Me=Cu(p,b,S),t[55]=p,t[56]=b,t[57]=S,t[58]=Me):Me=t[58];const ee=Me,oe=Nu(),Te=ot(eS);let J;t[59]!==oe||t[60]!==Te?(J=(He,Ve)=>{const wt=Te.get(He);return wt?.branch?wt.branch.trim()||null:Ve&&oe.get(Ve)?.trim()||null},t[59]=oe,t[60]=Te,t[61]=J):J=t[61];const re=J;let Y;t[62]===Symbol.for("react.memo_cache_sentinel")?(Y=[],t[62]=Y):Y=t[62];const[U,fe]=l.useState(Y),[ne,ce]=l.useState(""),Fe=Aw($,I);let Ye;t[63]!==$||t[64]!==Fe||t[65]!==n||t[66]!==P||t[67]!==fe||t[68]!==ce||t[69]!==I?(Ye=()=>{if(!n){fe([]),ce("");return}if(!Fe){fe([]),ce("");return}if(!$){fe([]),ce("");return}let He=!1;return P($,I,10,{type:"file"}).then(Ve=>{He||(fe(Ve.map(tS)),ce(Fe))}).catch(()=>{He||(fe([]),ce(Fe))}),()=>{He=!0}},t[63]=$,t[64]=Fe,t[65]=n,t[66]=P,t[67]=fe,t[68]=ce,t[69]=I,t[70]=Ye):Ye=t[70];let $e;t[71]!==$||t[72]!==Fe||t[73]!==n||t[74]!==P||t[75]!==I?($e=[n,$,I,Fe,P],t[71]=$,t[72]=Fe,t[73]=n,t[74]=P,t[75]=I,t[76]=$e):$e=t[76],l.useEffect(Ye,$e);const ie=W.length>0;let Re;e:{if(!ie){let Ve;t[77]!==q?(Ve=q.map(sS),t[77]=q,t[78]=Ve):Ve=t[78],Re=Ve;break e}let He;t[79]!==q||t[80]!==W?(He=bo(q,W,nS,{limit:7,noFuzzy:!0}),t[79]=q,t[80]=W,t[81]=He):He=t[81],Re=He}const ue=Re;let R;e:{if(!ie){let Ve;t[82]===Symbol.for("react.memo_cache_sentinel")?(Ve=[],t[82]=Ve):Ve=t[82],R=Ve;break e}let He;t[83]!==W||t[84]!==ve?(He=bo(ve,W,rS,{limit:7,noFuzzy:!0}),t[83]=W,t[84]=ve,t[85]=He):He=t[85],R=He}const ae=R;let Se;e:{if(!ie){let Ve;t[86]!==ee?(Ve=ee.slice(0,5).map(oS),t[86]=ee,t[87]=Ve):Ve=t[87],Se=Ve;break e}let He;t[88]!==W||t[89]!==ee?(He=bo(ee,W,iS,{limit:7,threshold:.2}),t[88]=W,t[89]=ee,t[90]=He):He=t[90],Se=He}const Ce=Se;let Ee;e:{if(!n){let Ve;t[91]===Symbol.for("react.memo_cache_sentinel")?(Ve=[],t[91]=Ve):Ve=t[91],Ee=Ve;break e}let He;t[92]!==U||t[93]!==ne||t[94]!==Fe||t[95]!==I?(He=Dw(U,I,Fe,ne),t[92]=U,t[93]=ne,t[94]=Fe,t[95]=I,t[96]=He):He=t[96],Ee=He}const se=Ee,je=n&&Fe.length>0&&ne!==Fe;let Ze;e:{if(!ie){let Ve;t[97]===Symbol.for("react.memo_cache_sentinel")?(Ve=[],t[97]=Ve):Ve=t[97],Ze=Ve;break e}let He;if(t[98]!==W||t[99]!==k){const Ve=k.map(aS);He=bo(Ve,W,lS,{limit:7,threshold:.4}),t[98]=W,t[99]=k,t[100]=He}else He=t[100];Ze=He}const X=Ze;let ye,Xe,Be,We,_e,tt,ct,Et,Nt,Ot,et,Tt,xt,vt;if(t[101]!==re||t[102]!==he||t[103]!==$||t[104]!==D||t[105]!==ie||t[106]!==n||t[107]!==f||t[108]!==x||t[109]!==z||t[110]!==ue||t[111]!==se||t[112]!==X||t[113]!==Ce||t[114]!==ae||t[115]!==r||t[116]!==j||t[117]!==g||t[118]!==e){const He=ue.map(cS),Ve=ae.map(dS),wt=Ce.map(uS),Ft=ie?se.map(fS):[],Lt=ie?X.map(mS):[];let ns;e:{if(!ie){ns=["commands","sessions"];break e}const Je=hS,Qe=[{key:"commands",score:Je(ue)},{key:"settings",score:Je(ae)},{key:"sessions",score:Je(Ce)},{key:"files",score:Je(se)},{key:"projects",score:Je(X)}];Qe.sort(pS),ns=Qe.map(gS)}const $t=ns,At=Je=>{he(),j(Je.id,Qs(Je))},ss=async Je=>{if(!$)return;const Qe=await wf(D,Je,{directory:$});if(!Qe.ok){Ae.error(Sf(Qe.reason));return}f($,Je),he()},ms=(Je,Qe)=>{he(),x({selectedProjectId:Je,directoryOverride:Qe})},zt=Je=>$i(Or(Je,g));We=Ls,Tt=n,xt=r;let qt;t[133]!==e?(qt=e("commandPalette.title"),t[133]=e,t[134]=qt):qt=t[134];let Ut;t[135]!==qt?(Ut=s.jsx(nn,{children:qt}),t[135]=qt,t[136]=Ut):Ut=t[136];let Jt;t[137]!==e?(Jt=e("commandPalette.description"),t[137]=e,t[138]=Jt):Jt=t[138];let Oe;t[139]!==Jt?(Oe=s.jsx(rn,{children:Jt}),t[139]=Jt,t[140]=Oe):Oe=t[140],t[141]!==Ut||t[142]!==Oe?(vt=s.jsxs(kn,{className:"sr-only",children:[Ut,Oe]}),t[141]=Ut,t[142]=Oe,t[143]=vt):vt=t[143],Be=Bs,Ot="overflow-hidden p-0",et=!0,Xe=Hh,ct=!1,Et="[&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-4 [&_[cmdk-input-wrapper]_svg]:w-4 [&_[cmdk-input]]:h-8 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-1.5 [&_[cmdk-item]_svg]:h-4 [&_[cmdk-item]_svg]:w-4 [&_[cmdk-item]]:typography-meta";let st;t[144]!==e?(st=e("commandPalette.input.placeholder"),t[144]=e,t[145]=st):st=t[145],t[146]!==z||t[147]!==st?(Nt=s.jsx(Kh,{value:z,onValueChange:V,placeholder:st}),t[146]=z,t[147]=st,t[148]=Nt):Nt=t[148],ye=Gh;let Ke;t[149]!==e?(Ke=e("commandPalette.empty.noResults"),t[149]=e,t[150]=Ke):Ke=t[150],t[151]!==Ke?(_e=s.jsx(qh,{children:Ke}),t[151]=Ke,t[152]=_e):_e=t[152],tt=$t.map(Je=>Je==="commands"&&He.length>0?s.jsx(fo,{children:He.map(Qe=>s.jsxs(yo,{value:Qe.id,onSelect:Qe.onSelect,children:[Qe.icon,s.jsx("span",{children:Qe.title}),Qe.shortcutId?s.jsx(Wh,{children:zt(Qe.shortcutId)}):null]},Qe.id))},"commands"):Je==="settings"&&Ve.length>0?s.jsx(fo,{children:Ve.map(xS)},"settings"):Je==="sessions"&&wt.length>0?s.jsx(fo,{children:wt.map(Qe=>{const kt=Qe.title||e("commandPalette.session.untitled"),ts=Qs(Qe),Wt=re(Qe.id,ts);return s.jsxs(yo,{value:`session:${Qe.id}`,onSelect:()=>At(Qe),children:[s.jsx(T,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:kt}),Wt?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(T,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:Wt})]}):null]},Qe.id)})},"sessions"):Je==="files"&&Ft.length>0?s.jsx(fo,{children:Ft.map(Qe=>{const kt=Vh(Qe.relativePath||Qe.name,{maxLength:80});return s.jsxs(yo,{value:`file:${Qe.path}`,onSelect:()=>{ss(Qe.path)},children:[s.jsx(fl,{filePath:Qe.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":Qe.relativePath,children:kt})]},`file:${Qe.path}`)})},"files"):Je==="projects"&&Lt.length>0?s.jsx(fo,{children:Lt.map(Qe=>{const kt=Qe.displayName;return s.jsxs(yo,{value:`project:${Qe.id}`,onSelect:()=>ms(Qe.id,Qe.path),children:[s.jsx(T,{name:"folder",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:kt}),s.jsx("span",{className:"ml-auto inline-flex items-center text-muted-foreground typography-meta truncate max-w-[160px]",children:Qe.path})]},`project:${Qe.id}`)})},"projects"):null),t[101]=re,t[102]=he,t[103]=$,t[104]=D,t[105]=ie,t[106]=n,t[107]=f,t[108]=x,t[109]=z,t[110]=ue,t[111]=se,t[112]=X,t[113]=Ce,t[114]=ae,t[115]=r,t[116]=j,t[117]=g,t[118]=e,t[119]=ye,t[120]=Xe,t[121]=Be,t[122]=We,t[123]=_e,t[124]=tt,t[125]=ct,t[126]=Et,t[127]=Nt,t[128]=Ot,t[129]=et,t[130]=Tt,t[131]=xt,t[132]=vt}else ye=t[119],Xe=t[120],Be=t[121],We=t[122],_e=t[123],tt=t[124],ct=t[125],Et=t[126],Nt=t[127],Ot=t[128],et=t[129],Tt=t[130],xt=t[131],vt=t[132];let _t;t[153]!==je||t[154]!==e?(_t=je?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[153]=je,t[154]=e,t[155]=_t):_t=t[155];let Ct;t[156]!==ye||t[157]!==_e||t[158]!==tt||t[159]!==_t?(Ct=s.jsxs(ye,{children:[_e,tt,_t]}),t[156]=ye,t[157]=_e,t[158]=tt,t[159]=_t,t[160]=Ct):Ct=t[160];let Rt;t[161]!==Xe||t[162]!==ct||t[163]!==Et||t[164]!==Nt||t[165]!==Ct?(Rt=s.jsxs(Xe,{shouldFilter:ct,className:Et,children:[Nt,Ct]}),t[161]=Xe,t[162]=ct,t[163]=Et,t[164]=Nt,t[165]=Ct,t[166]=Rt):Rt=t[166];let ut;t[167]!==Be||t[168]!==Ot||t[169]!==et||t[170]!==Rt?(ut=s.jsx(Be,{className:Ot,showCloseButton:et,children:Rt}),t[167]=Be,t[168]=Ot,t[169]=et,t[170]=Rt,t[171]=ut):ut=t[171];let bt;return t[172]!==We||t[173]!==Tt||t[174]!==xt||t[175]!==vt||t[176]!==ut?(bt=s.jsxs(We,{open:Tt,onOpenChange:xt,children:[vt,ut]}),t[172]=We,t[173]=Tt,t[174]=xt,t[175]=vt,t[176]=ut,t[177]=bt):bt=t[177],bt};function Iw(t){return t.isCommandPaletteOpen}function Rw(t){return t.setCommandPaletteOpen}function Mw(t){return t.setActiveMainTab}function Ow(t){return t.setSettingsDialogOpen}function Fw(t){return t.setSettingsPage}function Lw(t){return t.setSessionSwitcherOpen}function Bw(t){return t.toggleSidebar}function _w(t){return t.openContextOverview}function $w(t){return t.openContextSurface}function zw(t){return t.openContextFile}function Uw(t){return t.shortcutOverrides}function Ww(t){return t.openNewSessionDraft}function Vw(t){return t.setCurrentSession}function Hw(t){return t.currentDirectory}function Kw(t){return t.getActiveProject()}function Gw(t){return t.projects}function qw(t){return t.searchFiles}function Yw(t){return t.ensureStatus}function Qw(){Au()}function Xw(){Un.requestDirectoryDialog()}function Jw(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function Zw(t){return t.slug!=="home"}function eS(t){return t.worktreeMetadata}function tS(t){return{path:Xa(t.path),name:t.name,relativePath:t.relativePath}}function sS(t){return{item:t,score:0}}function nS(t){return t.searchText}function rS(t){return t.searchText}function oS(t){return{item:t,score:0}}function iS(t){return t.title||""}function aS(t){return{...t,displayName:t.label||t.path.split("/").pop()||t.path,searchText:`${t.label||""} ${t.path}`}}function lS(t){return t.searchText}function cS(t){return t.item}function dS(t){return t.item}function uS(t){return t.item}function fS(t){return t.item}function mS(t){return t.item}function hS(t){return t.length?t[0].score:1/0}function pS(t,e){return t.score-e.score}function gS(t){return t.key}function xS(t){return s.jsxs(yo,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const ld=(t,e,n)=>Qh(t)?$i(Or(t,n)):e,bS=()=>{const t=it.c(69),{t:e}=gt(),n=pe(yS),r=pe(vS),o=pe(wS);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=Yh(),t[0]=i):i=t[0];const c=i;let a;t[1]===Symbol.for("react.memo_cache_sentinel")?(a=nr(),t[1]=a):a=t[1];const d=a;let u,m,f,g,x,j,w,p,h;if(t[2]!==n||t[3]!==r||t[4]!==o||t[5]!==e){const V=[{categoryKey:"helpDialog.section.navigationCommands",items:[{id:"open_command_palette",descriptionKey:"helpDialog.item.openCommandPalette",icon:"command",keys:""},{id:"open_help",descriptionKey:"helpDialog.item.showKeyboardShortcuts",icon:"question",keys:""},{id:"toggle_sidebar",descriptionKey:"helpDialog.item.toggleSessionSidebar",icon:"layout-left",keys:""},{id:"add_selection_to_chat",descriptionKey:"helpDialog.item.addSelectionToChat",icon:"add",keys:""},{id:"cycle_agent",keys:"",descriptionKey:"helpDialog.item.cycleAgent",icon:"ai-agent"},{id:"open_model_selector",descriptionKey:"helpDialog.item.openModelSelector",icon:"ai-generate-2",keys:""},{keys:["↑↓"],descriptionKey:"helpDialog.item.navigateModels",icon:"ai-generate-2"},{keys:["←→"],descriptionKey:"helpDialog.item.adjustThinkingMode",icon:"brain-ai-3"},{id:"cycle_thinking_variant",descriptionKey:"helpDialog.item.cycleThinkingVariant",icon:"brain-ai-3",keys:""},{keys:[`Shift + Alt + ${c} + N`],descriptionKey:"helpDialog.item.newWindow",icon:"window"}]},{categoryKey:"helpDialog.section.sessionManagement",items:[{id:"new_chat",descriptionKey:"helpDialog.item.createNewSession",icon:"add",keys:""},{id:"new_chat_worktree",descriptionKey:"helpDialog.item.createNewWorktreeDraft",icon:"git-branch",keys:""},{id:"focus_input",descriptionKey:"helpDialog.item.focusChatInput",icon:"text",keys:""},{id:"toggle_prompt_navigator",descriptionKey:"helpDialog.item.togglePromptNavigator",icon:"list-unordered",keys:""},{id:"abort_run",descriptionKey:"helpDialog.item.abortActiveRun",icon:"close-circle",keys:""}]},{categoryKey:"helpDialog.section.panels",items:[{id:"toggle_right_sidebar",descriptionKey:"helpDialog.item.toggleRightSidebar",icon:"layout-right",keys:""},{id:"open_right_sidebar_git",descriptionKey:"helpDialog.item.openRightSidebarGitTab",icon:"git-branch",keys:""},{id:"open_right_sidebar_files",descriptionKey:"helpDialog.item.openRightSidebarFilesTab",icon:"layout-right",keys:""},{id:"toggle_terminal",descriptionKey:"helpDialog.item.toggleTerminalDock",icon:"window",keys:""},{id:"toggle_terminal_expanded",descriptionKey:"helpDialog.item.toggleTerminalExpanded",icon:"window",keys:""},{id:"toggle_context_plan",descriptionKey:"helpDialog.item.togglePlanContextPanel",icon:"time",keys:""},{keys:[`${c} + 1...0`],descriptionKey:"helpDialog.item.switchContextSurface",icon:"layout-right"}]},{categoryKey:"helpDialog.section.interface",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:"palette",keys:""},{id:"toggle_services_menu",descriptionKey:"helpDialog.item.toggleServicesMenu",icon:"stack",keys:""},{id:"cycle_services_tab",descriptionKey:"helpDialog.item.cycleServicesTab",icon:"stack",keys:""},{id:"open_settings",descriptionKey:"helpDialog.item.openSettings",icon:"settings-3",keys:""}]}];m=Ls,p=n,h=r,u=Bs,j="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let y;t[15]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(T,{name:"command",className:"h-5 w-5"}),t[15]=y):y=t[15];let I;t[16]!==e?(I=e("helpDialog.title"),t[16]=e,t[17]=I):I=t[17];let _;t[18]!==I?(_=s.jsxs(nn,{className:"flex items-center gap-2",children:[y,I]}),t[18]=I,t[19]=_):_=t[19];let W;t[20]!==e?(W=e("helpDialog.description"),t[20]=e,t[21]=W):W=t[21];let K;t[22]!==W?(K=s.jsx(rn,{children:W}),t[22]=W,t[23]=K):K=t[23],t[24]!==_||t[25]!==K?(w=s.jsxs(kn,{children:[_,K]}),t[24]=_,t[25]=K,t[26]=w):w=t[26],x="flex-1 overflow-y-auto mt-3 pr-1",f="space-y-4",g=V.map(Z=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(Z.categoryKey)}),s.jsx("div",{className:"space-y-1",children:Z.items.filter(Q=>!(d&&Q.id==="toggle_prompt_navigator")).map(Q=>{const le=Q.id?ld(Q.id,Array.isArray(Q.keys)?Q.keys[0]:Q.keys,o):Array.isArray(Q.keys)?Q.keys:Q.keys.split(" / ");return s.jsxs("div",{className:"flex items-center justify-between py-1 px-2",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[Q.icon&&s.jsx(T,{name:Q.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(Q.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(le)?le:[le]).map((te,he)=>s.jsxs(l.Fragment,{children:[he>0&&s.jsx("span",{className:"typography-meta text-muted-foreground mx-1",children:e("helpDialog.keyCombiner.or")}),s.jsx("kbd",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 typography-meta font-mono bg-muted rounded border border-border/20",children:te})]},`${te}-${he}`))})]},Q.id||Q.descriptionKey)})})]},Z.categoryKey)),t[2]=n,t[3]=r,t[4]=o,t[5]=e,t[6]=u,t[7]=m,t[8]=f,t[9]=g,t[10]=x,t[11]=j,t[12]=w,t[13]=p,t[14]=h}else u=t[6],m=t[7],f=t[8],g=t[9],x=t[10],j=t[11],w=t[12],p=t[13],h=t[14];let b;t[27]!==f||t[28]!==g?(b=s.jsx("div",{className:f,children:g}),t[27]=f,t[28]=g,t[29]=b):b=t[29];let v;t[30]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(T,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[30]=v):v=t[30];let S;t[31]!==e?(S=e("helpDialog.proTips.title"),t[31]=e,t[32]=S):S=t[32];let N;t[33]!==S?(N=s.jsx("p",{className:"font-medium mb-1",children:S}),t[33]=S,t[34]=N):N=t[34];let A;t[35]!==o||t[36]!==e?(A=e("helpDialog.proTips.commandPalette",{shortcut:ld("open_command_palette",`${c} P`,o)}),t[35]=o,t[36]=e,t[37]=A):A=t[37];let k;t[38]!==A?(k=s.jsxs("li",{children:["• ",A]}),t[38]=A,t[39]=k):k=t[39];let C;t[40]!==e?(C=e("helpDialog.proTips.recentSessions"),t[40]=e,t[41]=C):C=t[41];let P;t[42]!==C?(P=s.jsxs("li",{children:["• ",C]}),t[42]=C,t[43]=P):P=t[43];let D;t[44]!==e?(D=e("helpDialog.proTips.themeCycling"),t[44]=e,t[45]=D):D=t[45];let O;t[46]!==D?(O=s.jsxs("li",{children:["• ",D]}),t[46]=D,t[47]=O):O=t[47];let F;t[48]!==k||t[49]!==P||t[50]!==O?(F=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[k,P,O]}),t[48]=k,t[49]=P,t[50]=O,t[51]=F):F=t[51];let E;t[52]!==N||t[53]!==F?(E=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[v,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[N,F]})]})}),t[52]=N,t[53]=F,t[54]=E):E=t[54];let B;t[55]!==E||t[56]!==x||t[57]!==b?(B=s.jsxs("div",{className:x,children:[b,E]}),t[55]=E,t[56]=x,t[57]=b,t[58]=B):B=t[58];let $;t[59]!==u||t[60]!==B||t[61]!==j||t[62]!==w?($=s.jsxs(u,{className:j,children:[w,B]}),t[59]=u,t[60]=B,t[61]=j,t[62]=w,t[63]=$):$=t[63];let z;return t[64]!==m||t[65]!==$||t[66]!==p||t[67]!==h?(z=s.jsx(m,{open:p,onOpenChange:h,children:$}),t[64]=m,t[65]=$,t[66]=p,t[67]=h,t[68]=z):z=t[68],z};function yS(t){return t.isHelpDialogOpen}function vS(t){return t.setHelpDialogOpen}function wS(t){return t.shortcutOverrides}const SS=()=>{const t=it.c(32),{t:e}=gt(),n=pe(jS),r=pe(kS),o=pe(CS);let i;t[0]!==o||t[1]!==e?(i=async()=>{if(!o)return;if((await er(o)).ok){Ae.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}Ae.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=o,t[1]=e,t[2]=i):i=t[2];const c=i;let a;t[3]!==e?(a=e("openCodeStatusDialog.title"),t[3]=e,t[4]=a):a=t[4];let d;t[5]!==a?(d=s.jsx(nn,{children:a}),t[5]=a,t[6]=d):d=t[6];let u;t[7]!==e?(u=e("openCodeStatusDialog.description"),t[7]=e,t[8]=u):u=t[8];let m;t[9]!==u?(m=s.jsx(rn,{children:u}),t[9]=u,t[10]=m):m=t[10];let f;t[11]!==d||t[12]!==m?(f=s.jsxs(kn,{children:[d,m]}),t[11]=d,t[12]=m,t[13]=f):f=t[13];let g;t[14]!==e?(g=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=g):g=t[15];let x;t[16]!==c||t[17]!==g?(x=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:c,className:"app-region-no-drag inline-flex h-9 items-center justify-center rounded-md px-3 typography-ui-label font-medium text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:g})}),t[16]=c,t[17]=g,t[18]=x):x=t[18];let j;t[19]!==o||t[20]!==e?(j=o||e("openCodeStatusDialog.empty.noData"),t[19]=o,t[20]=e,t[21]=j):j=t[21];let w;t[22]!==j?(w=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:j}),t[22]=j,t[23]=w):w=t[23];let p;t[24]!==f||t[25]!==x||t[26]!==w?(p=s.jsxs(Bs,{className:"max-w-2xl",children:[f,x,w]}),t[24]=f,t[25]=x,t[26]=w,t[27]=p):p=t[27];let h;return t[28]!==n||t[29]!==r||t[30]!==p?(h=s.jsx(Ls,{open:n,onOpenChange:r,children:p}),t[28]=n,t[29]=r,t[30]=p,t[31]=h):h=t[31],h};function jS(t){return t.isOpenCodeStatusDialogOpen}function kS(t){return t.setOpenCodeStatusDialogOpen}function CS(t){return t.openCodeStatusText}const NS=180,cd=600,AS=1,DS=6,PS=t=>{const e=t?.directory;return typeof e=="string"&&e.trim()?e:null},ES=({enabled:t=!0,currentSessionId:e,sortedSessions:n,recentSessions:r=[],prefetchSession:o})=>{const i=l.useRef(new Map),c=l.useRef([]),a=l.useRef(new Set),d=l.useRef(0),u=l.useMemo(()=>nr(),[]),m=l.useCallback(j=>`${j.directory}
906
+ ${j.sessionId}`,[]),f=l.useCallback(()=>{d.current+=1,c.current=[],i.current.forEach(j=>window.clearTimeout(j)),i.current.clear()},[]),g=l.useCallback(()=>{if(!(!t||u||typeof window>"u"))for(;a.current.size<AS&&c.current.length>0;){const j=c.current.shift();if(!j)break;if(j.generation!==d.current||ot.getState().currentSessionId===j.sessionId||nc(j.sessionId,j.directory).renderable)continue;const p=m(j);a.current.add(p),o(j.sessionId,j.directory).catch(()=>{}).finally(()=>{a.current.delete(p),g()})}},[t,u,o,m]),x=l.useCallback(j=>{const w=j?.id,p=PS(j);if(!t||u||!w||!p||w===e||typeof window>"u")return;const h={sessionId:w,directory:p,generation:d.current},b=m(h);if(nc(w,p).renderable||a.current.has(b)||c.current.some(N=>m(N)===b))return;const v=i.current.get(b);v!==void 0&&window.clearTimeout(v);const S=window.setTimeout(()=>{if(i.current.delete(b),h.generation!==d.current)return;const N=c.current;N.length>=DS&&N.shift(),N.push(h),g()},NS);i.current.set(b,S)},[e,t,u,g,m]);l.useEffect(()=>{f()},[f,e,t,u]),l.useEffect(()=>{if(!t||u||!e||n.length===0)return;const j=window.setTimeout(()=>{const w=n.findIndex(p=>p.id===e);w<0||(x(n[w-1]),x(n[w+1]))},cd);return()=>window.clearTimeout(j)},[e,t,u,x,n]),l.useEffect(()=>{if(!t||u||!e||r.length===0)return;const j=window.setTimeout(()=>{const w=r.findIndex(p=>p.id===e);w<0||(x(r[w-1]),x(r[w+1]))},cd);return()=>window.clearTimeout(j)},[e,t,u,r,x]),l.useEffect(()=>f,[f])},TS=t=>{const e=it.c(3),n=ot(IS);let r;return e[0]!==t||e[1]!==n?(r={...t,currentSessionId:n},e[0]=t,e[1]=n,e[2]=r):r=e[2],ES(r),null};function IS(t){return t.currentSessionId}const RS=t=>{const e=it.c(12),{normalizedProjects:n,enabled:r,ownership:o,isSessionsLoading:i,hasAuthoritativeGlobalSessions:c,isWorktreeTopologyLoading:a,unresolvedWorktreeProjectPaths:d,foldersMap:u,createFolder:m,addSessionToFolder:f}=t,g=r===void 0?!0:r;let x,j;e[0]!==f||e[1]!==m||e[2]!==g||e[3]!==u||e[4]!==c||e[5]!==i||e[6]!==a||e[7]!==n||e[8]!==o||e[9]!==d?(x=()=>{!g||i||!c||a||n.forEach(w=>{if(d.has(w.normalizedPath))return;const p=Du(w.normalizedPath),h=o.archivedSessionsByProject.get(w.id)??[],b=u[p]??[],v=new Map(b.map(MS));h.forEach(S=>{const N=Xh(S,w.normalizedPath),A=N.toLowerCase();let k=v.get(A);k||(k=m(p,N),v.set(A,k)),k.sessionIds.includes(S.id)||f(p,k.id,S.id)})})},j=[n,g,o,i,c,a,d,u,m,f],e[0]=f,e[1]=m,e[2]=g,e[3]=u,e[4]=c,e[5]=i,e[6]=a,e[7]=n,e[8]=o,e[9]=d,e[10]=x,e[11]=j):(x=e[10],j=e[11]),l.useEffect(x,j)};function MS(t){return[t.name.toLowerCase(),t]}const OS=t=>{const e=it.c(4);let n;e[0]!==t?(n=(i,c)=>{const a=t.get(i);if(!a||a.length===0)return c;const d=new Map(c.map(FS)),u=[];a.forEach(g=>{const x=d.get(g);x&&(u.push(x),d.delete(g))});const m=[],f=[];return c.forEach(g=>{d.has(g.id)&&(g.isArchivedBucket?f.push(g):m.push(g))}),[...m,...u,...f]},e[0]=t,e[1]=n):n=e[1];const r=n;let o;return e[2]!==r?(o={getOrderedGroups:r},e[2]=r,e[3]=o):o=e[3],o};function FS(t){return[t.id,t]}const LS=[],BS=t=>{const{normalizedProjects:e,getSessionsForProject:n,getArchivedSessionsForProject:r,availableWorktreesByProject:o,projectRepoStatus:i,projectRootBranches:c,lastRepoStatus:a,buildGroupedSessions:d,hasSessionSearchQuery:u,normalizedSessionSearchQuery:m,filterSessionNodesForSearch:f,buildGroupSearchText:g,foldersMap:x}=t,j=l.useRef(new Map),w=l.useMemo(()=>{const k=j.current,C=new Map;let P=0,D=0;const O=(E,B)=>E.length===B.length&&E.every(($,z)=>$===B[z]),F=e.map(E=>{const B=n(E.id),$=r(E.id),z=o.get(E.normalizedPath)??LS,V=i.has(E.id)?!!i.get(E.id):a,y=c.get(E.id)??null,I=k.get(E.id);if(I&&I.project===E&&O(I.activeSessions,B)&&O(I.archivedSessions,$)&&I.availableWorktrees===z&&I.rootBranch===y&&I.isRepo===V&&I.buildGroupedSessions===d)return P+=1,C.set(E.id,I),I.section;D+=1;const _=Pu([...B,...$]),W=d(_,E.normalizedPath,z,y,V),K={project:E,groups:W};return C.set(E.id,{project:E,activeSessions:B,archivedSessions:$,availableWorktrees:z,rootBranch:y,isRepo:V,buildGroupedSessions:d,section:K}),K});return j.current=C,P>0&&In("ui.sidebar.project_section.reused",P),D>0&&In("ui.sidebar.project_section.rebuilt",D),F},[e,n,r,o,i,a,d,c]),p=l.useMemo(()=>w,[w]),h=l.useMemo(()=>{const k=new WeakMap;if(!u)return k;const C=P=>P.reduce((D,O)=>D+1+C(O.children),0);return p.forEach(P=>{P.groups.forEach(D=>{const O=f(D.sessions,m),F=C(O),E=g(D).includes(m),B=jt(D.directory??null),z=(B?x[B]??[]:[]).filter(V=>V.name.toLowerCase().includes(m)).length;k.set(D,{filteredNodes:O,matchedSessionCount:F,folderNameMatchCount:z,groupMatches:E,hasMatch:E||F>0||z>0})})}),k},[u,p,f,m,g,x]),b=l.useMemo(()=>u?p.map(k=>({...k,groups:k.groups.filter(C=>h.get(C)?.hasMatch===!0)})).filter(k=>k.groups.length>0):p,[u,p,h]),v=u?b:p,S=l.useRef(new WeakMap),N=l.useMemo(()=>{const k=S.current;return v.map(C=>{const P=k.get(C);if(P&&P.query===m)return P.section;const D=C.groups.filter(V=>!V.isArchivedBucket),O=C.groups.filter(V=>V.isArchivedBucket),F=D.flatMap(V=>u?h.get(V)?.filteredNodes??[]:V.sessions),E=D.map(V=>({scopeKey:V.folderScopeKey??jt(V.directory??null),directory:V.directory??null})).filter(V=>!!V.scopeKey),B=D.find(V=>V.isMain)??null,$={id:"flat",label:B?.label??"",branch:B?.branch??null,description:B?.description??null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:B?.directory??C.project.normalizedPath,folderScopeKey:B?.folderScopeKey??C.project.normalizedPath,folderScopes:E,sessions:F};if(u){const V=D.map(y=>h.get(y)).filter(y=>!!y);h.set($,{filteredNodes:F,matchedSessionCount:V.reduce((y,I)=>y+I.matchedSessionCount,0),folderNameMatchCount:V.reduce((y,I)=>y+I.folderNameMatchCount,0),groupMatches:V.some(y=>y.groupMatches),hasMatch:V.some(y=>y.hasMatch)})}const z={project:C.project,groups:[$,...O]};return k.set(C,{query:m,section:z}),z})},[h,u,m,v]),A=l.useMemo(()=>u?v.reduce((k,C)=>k+C.groups.reduce((P,D)=>{const O=h.get(D);if(!O)return P;const F=O.folderNameMatchCount+(O.groupMatches?1:0);return P+O.matchedSessionCount+F},0),0):0,[u,v,h]);return{projectSections:w,visibleProjectSections:p,groupSearchDataByGroup:h,searchableProjectSections:b,sectionsForRender:v,flatSectionsForRender:N,searchMatchCount:A}};function _S({activeProjectId:t,currentSessionId:e,currentSessionOwnerProjectId:n,projectMap:r,metaByProject:o,rememberedSessionId:i,fallbackSessionId:c}){if(e&&n===t)return{kind:"preserve-current"};if(n==null){const u=!!(e&&Array.from(o.entries()).some(([m,f])=>m!==t&&f.has(e)));if(e&&r&&!u)return{kind:"preserve-current"}}if(!r||r.size===0)return{kind:"open-draft"};const d=(i&&r.has(i)?i:null)??c;return!d||d===e?{kind:"none"}:{kind:"select-session",sessionId:d}}const $S=t=>{const e=it.c(27),{projectSections:n,activeProjectId:r,activeSessionByProject:o,setActiveSessionByProject:i,currentSessionId:c,currentSessionOwnerProjectId:a,handleSessionSelect:d,newSessionDraftOpen:u,mobileVariant:m,openNewSessionDraft:f,setActiveMainTab:g,setSessionSwitcherOpen:x}=t;let j,w;if(e[0]!==n){w=new Map,j=new Map;const k=(C,P,D,O)=>{w.has(C)||w.set(C,new Map);const F=w.get(C);O.forEach(E=>{const B=jt(E.worktree?.path??E.session.directory??D??P);F.set(E.session.id,{directory:B}),j.has(C)||j.set(C,{id:E.session.id,directory:B}),E.children.length>0&&k(C,P,B,E.children)})};n.forEach(C=>{C.groups.forEach(P=>{k(C.project.id,C.project.normalizedPath,P.directory,P.sessions)})}),e[0]=n,e[1]=j,e[2]=w}else j=e[1],w=e[2];let p;e[3]!==j||e[4]!==w?(p={metaByProject:w,firstSessionByProject:j},e[3]=j,e[4]=w,e[5]=p):p=e[5];const h=p,b=l.useRef(null);let v,S;e[6]!==r||e[7]!==o||e[8]!==c||e[9]!==a||e[10]!==d||e[11]!==m||e[12]!==u||e[13]!==f||e[14]!==n||e[15]!==h||e[16]!==g||e[17]!==i||e[18]!==x?(v=()=>{if(!r||u||pe.getState().isNewWorktreeDialogOpen||b.current===r)return;const k=n.find(O=>O.project.id===r);if(!k)return;const C=h.metaByProject.get(r);if(c&&C&&C.has(c)){b.current=r,i(O=>{if(O.get(r)===c)return O;const F=new Map(O);return F.set(r,c),F});return}const P=_S({activeProjectId:r,currentSessionId:c,currentSessionOwnerProjectId:a,projectMap:C,metaByProject:h.metaByProject,rememberedSessionId:o.get(r),fallbackSessionId:h.firstSessionByProject.get(r)?.id??null});if(P.kind==="preserve-current"){a===r&&(b.current=r);return}if(b.current=r,P.kind==="open-draft"){g("chat"),m&&x(!1),f({selectedProjectId:k.project.id,directoryOverride:k.project.normalizedPath});return}if(P.kind!=="select-session")return;const D=C?.get(P.sessionId)?.directory??null;d(P.sessionId,D)},S=[r,o,c,a,d,u,m,f,n,h,g,x,i],e[6]=r,e[7]=o,e[8]=c,e[9]=a,e[10]=d,e[11]=m,e[12]=u,e[13]=f,e[14]=n,e[15]=h,e[16]=g,e[17]=i,e[18]=x,e[19]=v,e[20]=S):(v=e[19],S=e[20]),l.useLayoutEffect(v,S);let N,A;e[21]!==r||e[22]!==c||e[23]!==h||e[24]!==i?(N=()=>{if(!r||!c)return;const k=h.metaByProject.get(r);!k||!k.has(c)||i(C=>{if(C.get(r)===c)return C;const P=new Map(C);return P.set(r,c),P})},A=[r,c,h,i],e[21]=r,e[22]=c,e[23]=h,e[24]=i,e[25]=N,e[26]=A):(N=e[25],A=e[26]),l.useEffect(N,A)},zS=t=>{const e=it.c(20);let n,r,o,i;e[0]!==t?({initialActiveSessionByProject:r,persistActiveSessionByProject:o,sessionOwnerBySessionId:i,...n}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o,e[4]=i):(n=e[1],r=e[2],o=e[3],i=e[4]);const c=ot(US),a=ot(WS);let d;e[5]!==c||e[6]!==i?(d=c?i?.get(c)?.projectId??null:null,e[5]=c,e[6]=i,e[7]=d):d=e[7];const u=d;let m;e[8]!==r?(m=()=>new Map(r),e[8]=r,e[9]=m):m=e[9];const[f,g]=l.useState(m);let x;e[10]!==f||e[11]!==n||e[12]!==c||e[13]!==u||e[14]!==a?(x={...n,activeSessionByProject:f,setActiveSessionByProject:g,currentSessionId:c,currentSessionOwnerProjectId:u,newSessionDraftOpen:a},e[10]=f,e[11]=n,e[12]=c,e[13]=u,e[14]=a,e[15]=x):x=e[15],$S(x);let j,w;return e[16]!==f||e[17]!==o?(j=()=>{o(f)},w=[f,o],e[16]=f,e[17]=o,e[18]=j,e[19]=w):(j=e[18],w=e[19]),l.useEffect(j,w),null};function US(t){return t.currentSessionId}function WS(t){return!!t.newSessionDraft?.open}const Ja=new Map,VS=(t,e)=>{for(const n of t){const r=jt(n??null);r&&!Ja.has(r)&&Ja.set(r,e)}},dd=t=>{const e=jt(t??null);return e?Ja.get(e)??0:0},Jo=t=>!!t.time?.archived,HS=t=>{const{t:e}=gt(),n=l.useCallback(c=>[c.label,c.branch??"",c.description??"",c.directory??""].join(" ").toLowerCase(),[]),r=l.useCallback(c=>{const a=jt(c.directory??null)??"";return`${(c.title||e("sessions.sidebar.session.untitled")).trim()} ${a}`.toLowerCase()},[e]),o=l.useCallback((c,a)=>a?c.flatMap(d=>{if(r(d.session).includes(a))return[d];const m=o(d.children,a);return m.length===0?[]:[{...d,children:m}]}):c,[r]),i=l.useCallback((c,a,d,u,m)=>{const f=jt(a??null),g=Pu(c).sort((F,E)=>so(F,E,t.pinnedSessionIds,t.sessionOrderRanks)),x=new Map(g.map(F=>[F.id,F])),j=new Map;g.forEach(F=>{const E=F.parentID;if(!E)return;const B=x.get(E);if(!B||Jo(B)!==Jo(F))return;const $=j.get(E)??[];$.push(F),j.set(E,$)}),j.forEach(F=>F.sort((E,B)=>so(E,B,t.pinnedSessionIds,t.sessionOrderRanks)));const w=new Map;d.forEach(F=>{if(F.path){const E=jt(F.path)??F.path;w.set(E,F)}});const p=F=>{const E=jt(F.directory??null),B=t.worktreeMetadata.get(F.id)??null;if(B)return B;if(E){const $=w.get(E)??null;if($&&E!==f)return $}return null},h=F=>{const E=j.get(F.id)??[];return{session:F,children:E.map(B=>h(B)),worktree:p(F)}},b=g.filter(F=>{const E=F.parentID;if(!E)return!0;const B=x.get(E);return B?Jo(B)!==Jo(F):!0}),v=new Map,S="__archived__",N=F=>{if(F.time?.archived)return S;if(t.isVSCode)return f??"__project_root__";const B=jt(t.worktreeMetadata.get(F.id)?.path??null)??Qs(F);return B?B!==f&&w.has(B)?B:B===f?f??"__project_root__":S:S};b.forEach(F=>{const E=h(F),B=N(F);v.has(B)||v.set(B,[]),v.get(B)?.push(E)});const A=f??"__project_root__",k=[{id:"root",label:m&&u&&u!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:u}):e("sessions.sidebar.grouping.projectRoot"),branch:u??null,description:f?yi(f,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:f,folderScopeKey:f,sessions:v.get(A)??[]}],C=new Map;d.forEach(F=>{const E=jt(F.path)??F.path,B=v.get(E)??[],$=B.length>0,z=B.reduce((V,y)=>{const I=Jh(y.session,t.sessionOrderRanks);return Number.isFinite(I)?Math.max(V,I):V},0);C.set(E,{hasActiveSession:$,lastUpdatedAt:z})});const P=[...d].sort((F,E)=>{const B=jt(F.path)??F.path,$=jt(E.path)??E.path,z=C.get(B)??{hasActiveSession:!1,lastUpdatedAt:0},V=C.get($)??{hasActiveSession:!1,lastUpdatedAt:0};if(z.hasActiveSession!==V.hasActiveSession)return z.hasActiveSession?-1:1;if(z.hasActiveSession&&V.hasActiveSession)return V.lastUpdatedAt-z.lastUpdatedAt;const y=dd(F.path),I=dd(E.path);if(y!==I)return I-y;const _=(F.label||F.branch||F.name||F.path||"").toLowerCase(),W=(E.label||E.branch||E.name||E.path||"").toLowerCase();return _.localeCompare(W)});(t.isVSCode?[]:P).forEach(F=>{const E=jt(F.path)??F.path,B=t.gitBranches.get(E)?.trim()||null,$=F.branch?.trim()||null,V=!!(B&&$&&F.label&&rc(F.label)===rc($))?B:F.label||F.name||gr(E,t.homeDirectory)||E;k.push({id:`worktree:${E}`,label:V,branch:B||$,description:yi(E,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:F,directory:E,folderScopeKey:E,sessions:v.get(E)??[]})});const O=v.get(S)??[];return O.length>0&&k.push({id:"archived",label:e("sessions.sidebar.grouping.archived"),branch:null,description:e("sessions.sidebar.grouping.archivedDescription"),isMain:!1,isArchivedBucket:!0,worktree:null,directory:null,folderScopeKey:!t.isVSCode&&f?Du(f):null,sessions:O}),k},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.sessionOrderRanks,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:o,buildGroupedSessions:i}},KS=t=>{const e=it.c(11),{enabled:n,isSessionSearchOpen:r,setIsSessionSearchOpen:o,sessionSearchInputRef:i,sessionSearchContainerRef:c}=t,a=n===void 0?!0:n;let d,u;e[0]!==a||e[1]!==r||e[2]!==i?(d=()=>{if(!a||!r||typeof window>"u")return;const g=window.requestAnimationFrame(()=>{i.current?.focus(),i.current?.select()});return()=>window.cancelAnimationFrame(g)},u=[a,r,i],e[0]=a,e[1]=r,e[2]=i,e[3]=d,e[4]=u):(d=e[3],u=e[4]),l.useEffect(d,u);let m,f;e[5]!==a||e[6]!==r||e[7]!==c||e[8]!==o?(m=()=>{if(!a||!r||typeof document>"u")return;const g=x=>{c.current&&(c.current.contains(x.target)||o(!1))};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},f=[a,r,o,c],e[5]=a,e[6]=r,e[7]=c,e[8]=o,e[9]=m,e[10]=f):(m=e[9],f=e[10]),l.useEffect(m,f)},GS=t=>{const e=it.c(50),{t:n}=gt(),[r,o]=l.useState(null),i=l.useRef(null);let c,a;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=()=>()=>{i.current&&clearTimeout(i.current)},a=[],e[0]=c,e[1]=a):(c=e[0],a=e[1]),l.useEffect(c,a);let d;e[2]!==t?(d=(K,Z)=>{Ea("navigation.session_select"),pe.getState().closeMainSurfaces();const Q=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),K===ot.getState().currentSessionId){t.allowReselect&&t.onSessionSelected?.(K),Q();return}Ea("navigation.session_state_set"),t.setCurrentSession(K,Z??null),t.onSessionSelected?.(K),Q()},e[2]=t,e[3]=d):d=e[3];const u=d;let m;e[4]!==t?(m=(K,Z)=>{t.setEditingId(K),t.setEditTitle(Z)},e[4]=t,e[5]=m):m=e[5];const f=m;let g;e[6]!==t?(g=async K=>{if(!t.editingId)return;const Z=(K??t.editTitle).trim();Z&&await t.updateSessionTitle(t.editingId,Z),t.setEditingId(null),t.setEditTitle("")},e[6]=t,e[7]=g):g=e[7];const x=g;let j;e[8]!==t?(j=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=j):j=e[9];const w=j;let p;e[10]===Symbol.for("react.memo_cache_sentinel")?(p=async(K,Z)=>{try{return(await er(K)).ok?(o(Z),i.current&&clearTimeout(i.current),i.current=window.setTimeout(()=>{o(null),i.current=null},2e3),!0):!1}catch{return!1}},e[10]=p):p=e[10];const h=p;let b;e[11]!==t||e[12]!==n?(b=async K=>{const Z=await t.shareSession(K.id);if(!Z?.share?.url){Ae.error(n("sessions.sidebar.session.share.error"));return}const Q=await h(Z.share.url,K.id);Ae[Q?"success":"warning"](n("sessions.sidebar.session.share.successTitle"),{description:n(Q?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")})},e[11]=t,e[12]=n,e[13]=b):b=e[13];const v=b;let S;e[14]!==n?(S=(K,Z)=>{h(K,Z).then(Q=>{Q||Ae.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[14]=n,e[15]=S):S=e[15];const N=S;let A;e[16]!==n?(A=K=>{er(K).then(Z=>{if(Z.ok){Ae.success(n("sessions.sidebar.session.copyId.success"));return}Ae.error(n("sessions.sidebar.session.copyId.error"))}).catch(()=>Ae.error(n("sessions.sidebar.session.copyId.error")))},e[16]=n,e[17]=A):A=e[17];const k=A;let C;e[18]!==t||e[19]!==n?(C=async K=>{await t.unshareSession(K)?Ae.success(n("sessions.sidebar.session.unshare.success")):Ae.error(n("sessions.sidebar.session.unshare.error"))},e[18]=t,e[19]=n,e[20]=C):C=e[20];const P=C;let D;e[21]!==t.childrenMap?(D=K=>{const Z=[],Q=le=>{(t.childrenMap.get(le)??[]).forEach(he=>{Z.push(he),Q(he.id)})};return Q(K),Z},e[21]=t.childrenMap,e[22]=D):D=e[22];const O=D,F=YS;let E;e[23]!==t||e[24]!==O||e[25]!==n?(E=async(K,Z,Q)=>{const le=Z?.archivedBucket===!0||Z?.hardDelete===!0,te=Q?.descendantIds??F(O(K.id),le).map(QS);if(te.length===0){(le?await t.deleteSession(K.id):await t.archiveSession(K.id))?Ae.success(n(le?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):Ae.error(n(le?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const he=[K.id,...te];if(le){const{deletedIds:we,failedIds:de}=await t.deleteSessions(he);if(de.length===0){const q=we.length;Ae.success(q===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:q}):n("sessions.sidebar.bulkActions.deletedPlural",{count:q}))}else Ae.error(n("sessions.sidebar.session.delete.error"));return}const{archivedIds:xe,failedIds:H}=await t.archiveSessions(he);xe.length>0&&Ae.success(xe.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:xe.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:xe.length})),H.length>0&&Ae.error(H.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:H.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:H.length}))},e[23]=t,e[24]=O,e[25]=n,e[26]=E):E=e[26];const B=E;let $;e[27]!==t||e[28]!==O||e[29]!==B?($=(K,Z)=>{const Q=Z?.archivedBucket===!0||Z?.hardDelete===!0,le=F(O(K.id),Q).map(XS);if(!t.showDeletionDialog||Z?.skipConfirm===!0){B(K,Z,{descendantIds:le});return}t.setDeleteSessionConfirm({session:K,descendantCount:le.length,descendantIds:le,archivedBucket:Q})},e[27]=t,e[28]=O,e[29]=B,e[30]=$):$=e[30];const z=$;let V;e[31]!==t||e[32]!==B?(V=async()=>{if(!t.deleteSessionConfirm)return;const{session:K,archivedBucket:Z,descendantIds:Q}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await B(K,{archivedBucket:Z},{descendantIds:Q})},e[31]=t,e[32]=B,e[33]=V):V=e[33];const y=V;let I;e[34]!==t||e[35]!==n?(I=async K=>{await t.unarchiveSession(K.id)?Ae.success(n("sessions.sidebar.session.restore.success")):Ae.error(n("sessions.sidebar.session.restore.error"))},e[34]=t,e[35]=n,e[36]=I):I=e[36];const _=I;let W;return e[37]!==y||e[38]!==r||e[39]!==w||e[40]!==k||e[41]!==N||e[42]!==z||e[43]!==_||e[44]!==x||e[45]!==f||e[46]!==u||e[47]!==v||e[48]!==P?(W={copiedSessionId:r,handleSessionSelect:u,handleSessionDoubleClick:f,handleSaveEdit:x,handleCancelEdit:w,handleShareSession:v,handleCopyShareUrl:N,handleCopySessionId:k,handleUnshareSession:P,handleDeleteSession:z,handleRestoreSession:_,confirmDeleteSession:y},e[37]=y,e[38]=r,e[39]=w,e[40]=k,e[41]=N,e[42]=z,e[43]=_,e[44]=x,e[45]=f,e[46]=u,e[47]=v,e[48]=P,e[49]=W):W=e[49],W};function qS(t){return!t.time?.archived}function YS(t,e){return e?t:t.filter(qS)}function QS(t){return t.id}function XS(t){return t.id}const JS=t=>{const e=it.c(26),{isVSCode:n,safeStorage:r,keys:o,groupOrderByProject:i,collapsedGroups:c,setExpandedParents:a,setCollapsedProjects:d}=t,u=l.useRef(null),m=l.useRef(null);let f;e[0]!==n?(f=()=>{if(n)return;const C=m.current;if(m.current=null,u.current=null,!C)return;const{projects:P}=Gt.getState(),D=P.map(O=>({...O,sidebarCollapsed:C.has(O.id)}));ou({projects:D}).catch(ZS)},e[0]=n,e[1]=f):f=e[1];const g=f;let x;e[2]!==g||e[3]!==n?(x=C=>{typeof window>"u"||n||(m.current=C,u.current!==null&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>{g()},700))},e[2]=g,e[3]=n,e[4]=x):x=e[4];const j=x;let w,p;e[5]===Symbol.for("react.memo_cache_sentinel")?(w=()=>()=>{typeof window<"u"&&u.current!==null&&window.clearTimeout(u.current),u.current=null,m.current=null},p=[],e[5]=w,e[6]=p):(w=e[5],p=e[6]),l.useEffect(w,p);let h,b;e[7]!==o.projectCollapse||e[8]!==o.sessionExpanded||e[9]!==r||e[10]!==d||e[11]!==a?(h=()=>{try{const C=r.getItem(o.sessionExpanded);if(C){const D=JSON.parse(C);Array.isArray(D)&&a(new Set(D.filter(e0)))}const P=r.getItem(o.projectCollapse);if(P){const D=JSON.parse(P);Array.isArray(D)&&d(new Set(D.filter(t0)))}}catch{}},b=[o.projectCollapse,o.sessionExpanded,r,d,a],e[7]=o.projectCollapse,e[8]=o.sessionExpanded,e[9]=r,e[10]=d,e[11]=a,e[12]=h,e[13]=b):(h=e[12],b=e[13]),l.useEffect(h,b);let v,S;e[14]!==i||e[15]!==o.groupOrder||e[16]!==r?(v=()=>{try{const C=Object.fromEntries(i.entries());r.setItem(o.groupOrder,JSON.stringify(C))}catch{}},S=[i,o.groupOrder,r],e[14]=i,e[15]=o.groupOrder,e[16]=r,e[17]=v,e[18]=S):(v=e[17],S=e[18]),l.useEffect(v,S);let N,A;e[19]!==c||e[20]!==o.groupCollapse||e[21]!==r?(N=()=>{try{r.setItem(o.groupCollapse,JSON.stringify(Array.from(c)))}catch{}},A=[c,o.groupCollapse,r],e[19]=c,e[20]=o.groupCollapse,e[21]=r,e[22]=N,e[23]=A):(N=e[22],A=e[23]),l.useEffect(N,A);let k;return e[24]!==j?(k={scheduleCollapsedProjectsPersist:j},e[24]=j,e[25]=k):k=e[25],k};function ZS(){}function e0(t){return typeof t=="string"}function t0(t){return typeof t=="string"}const s0=5*6e4,n0=t=>{const e=it.c(31),{normalizedProjects:n,enabled:r,gitRepoStatus:o,setProjectRepoStatus:i,setProjectRootBranches:c}=t,a=r===void 0?!0:r,{git:d}=rr(),u=pr(r0);let m,f;e[0]!==a||e[1]!==u||e[2]!==d||e[3]!==n||e[4]!==i?(m=()=>{if(!a||!d||n.length===0){i(new Map);return}n.forEach(A=>{Oa(()=>u(A.normalizedPath,d))})},f=[a,n,d,u,i],e[0]=a,e[1]=u,e[2]=d,e[3]=n,e[4]=i,e[5]=m,e[6]=f):(m=e[5],f=e[6]),l.useEffect(m,f);let g,x;e[7]!==a||e[8]!==o||e[9]!==n||e[10]!==i?(g=()=>{if(!a)return;const A=new Map;n.forEach(k=>{A.set(k.id,o.get(k.normalizedPath)?.isGitRepo??null)}),i(A)},x=[a,n,o,i],e[7]=a,e[8]=o,e[9]=n,e[10]=i,e[11]=g,e[12]=x):(g=e[11],x=e[12]),l.useEffect(g,x);let j;if(e[13]!==o||e[14]!==n){let A;e[16]!==o?(A=k=>{const C=o.get(k.normalizedPath)?.branch??"";return`${k.id}:${C}`},e[16]=o,e[17]=A):A=e[17],j=n.map(A).join("|"),e[13]=o,e[14]=n,e[15]=j}else j=e[15];const w=j;let p;e[18]===Symbol.for("react.memo_cache_sentinel")?(p=new Map,e[18]=p):p=e[18];const h=l.useRef(p);let b;e[19]===Symbol.for("react.memo_cache_sentinel")?(b=new Map,e[19]=b):b=e[19];const v=l.useRef(b);let S;e[20]!==a||e[21]!==o||e[22]!==n||e[23]!==c?(S=()=>{if(!a)return;let A=!1;const k=setTimeout(()=>{(async()=>{const P=new Set(n.map(o0));for(const $ of h.current.keys())P.has($)||(h.current.delete($),v.current.delete($));const D=Date.now(),O=n.filter($=>{const z=o.get($.normalizedPath);if(z?.isGitRepo===!1)return h.current.delete($.id),v.current.delete($.id),!1;if(z?.isGitRepo!==!0||z.branch===null)return!1;const V=z.branch.trim(),y=`${$.normalizedPath}\0${V}`,I=h.current.get($.id);if(I===y){const _=v.current.get($.id);return _&&(_.at=D),!1}return!(I!==void 0&&D-(v.current.get($.id)?.at??0)<s0)});if(O.length===0)return;const F=await Zh(O,2,async $=>{const z=o.get($.normalizedPath)?.branch?.trim()??"",V=`${$.normalizedPath}\0${z}`,y=await Oa(()=>Wi($.normalizedPath,z?{knownBranch:z}:void 0)).catch(i0);return{id:$.id,inputKey:V,branch:y}});if(A)return;const E=F.filter(a0);if(E.length===0)return;const B=Date.now();c($=>{const z=new Map($);return E.forEach(V=>{const{id:y,branch:I}=V;I&&z.set(y,I)}),z}),E.forEach($=>{const{id:z,inputKey:V,branch:y}=$;h.current.set(z,V),y&&v.current.set(z,{branch:y,at:B})})})()},150);return()=>{A=!0,clearTimeout(k)}},e[20]=a,e[21]=o,e[22]=n,e[23]=c,e[24]=S):S=e[24];let N;e[25]!==a||e[26]!==o||e[27]!==n||e[28]!==w||e[29]!==c?(N=[a,n,w,o,c],e[25]=a,e[26]=o,e[27]=n,e[28]=w,e[29]=c,e[30]=N):N=e[30],l.useEffect(S,N)};function r0(t){return t.ensureStatus}function o0(t){return t.id}function i0(){return null}function a0(t){return t.branch}const l0=t=>{const e=it.c(7),{ownership:n}=t;let r;e[0]!==n?(r=d=>n.sessionsByProject.get(d)??[],e[0]=n,e[1]=r):r=e[1];const o=r;let i;e[2]!==n?(i=d=>n.archivedSessionsByProject.get(d)??[],e[2]=n,e[3]=i):i=e[3];const c=i;let a;return e[4]!==c||e[5]!==o?(a={getSessionsForProject:o,getArchivedSessionsForProject:c},e[4]=c,e[5]=o,e[6]=a):a=e[6],a},c0=t=>{const e=new Map;for(const n of t){const r=Qs(n);r&&e.set(n.id,{directory:r,sessionId:n.id})}return e},d0=(t,e)=>{if(!t)return[];const n=[];return t.forEach((r,o)=>{e.has(o)||n.push(r)}),n},u0=t=>{const e=it.c(5),{enabled:n,hasAuthoritativeGlobalSessions:r,sessions:o}=t,i=n===void 0?!0:n,c=l.useRef(null);let a,d;e[0]!==i||e[1]!==r||e[2]!==o?(a=()=>{if(!i||!r)return;const u=Ps(),m=c0(o),f=c.current?.runtimeKey===u?c.current.identities:null;for(const g of d0(f,m))ep({runtimeKey:u,...g});c.current={runtimeKey:u,identities:m}},d=[i,r,o],e[0]=i,e[1]=r,e[2]=o,e[3]=a,e[4]=d):(a=e[3],d=e[4]),l.useEffect(a,d)},f0=(t,e)=>t?e.kind!==t.kind?e.kind==="project":e.projectRoot.length!==t.projectRoot.length?e.projectRoot.length>t.projectRoot.length:e.projectId.localeCompare(t.projectId)<0:!0,ud=(t,e,n)=>{f0(t.get(e),n)&&t.set(e,n)},m0=t=>{const e=t;return jt(e.directory)??jt(e.project?.worktree)},h0=t=>{if(t==="/"||/^[A-Z]:$/.test(t))return null;const e=t.lastIndexOf("/");return e<0?null:e===0?"/":e===2&&/^[A-Z]:\//.test(t)?t.slice(0,2):t.slice(0,e)},p0=(t,e,n,r,o=[])=>{const i=new Map,c=new Map;for(const j of e){const w=jt(j.normalizedPath);if(!w)continue;const p=c.get(w);(!p||j.id.localeCompare(p.id)<0)&&c.set(w,j),ud(i,w,{projectId:j.id,projectRoot:w,scopeDirectory:w,kind:"project"})}if(!r)for(const[j,w]of n){const p=jt(j),h=p?c.get(p):void 0;if(!(!h||!p))for(const b of w){const v=jt(b.path);v&&ud(i,v,{projectId:h.id,projectRoot:p,scopeDirectory:v,kind:"worktree"})}}const a=new Map,d=new Map,u=new Map,m=new Map,f=new Map,g=j=>{if(!j)return null;if(a.has(j))return a.get(j)??null;if(r){const b=i.get(j)??null;return a.set(j,b),b}const w=[];let p=j,h=null;for(;p;){if(a.has(p)){h=a.get(p)??null;break}if(w.push(p),h=i.get(p)??null,h)break;p=h0(p)}for(const b of w)a.set(b,h);return h},x=(j,w,p)=>{for(const h of j){const b=g(m0(h));if(!b)continue;d.set(h.id,b);const v=w.get(b.projectId);if(v?v.push(h):w.set(b.projectId,[h]),!p)continue;const S=p.get(b.scopeDirectory);S?S.add(h.id):p.set(b.scopeDirectory,new Set([h.id]))}};return x(t,u,f),x(o,m),{bySessionId:d,sessionsByProject:u,archivedSessionsByProject:m,sessionsByScope:f,directoryResolutions:a.size}},g0=t=>{const e=it.c(10),{enabled:n,isDesktopShellRuntime:r,projectSections:o,projectHeaderSentinelRefs:i}=t,c=n===void 0?!0:n;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a=new Set,e[0]=a):a=e[0];const[d,u]=l.useState(a);let m;e[1]!==c||e[2]!==r||e[3]!==i?(m=()=>{if(!c||!r){u(x0);return}const x=Array.from(i.current.values()).find(b0)?.closest(".oc-sidebar-scroller")??null;if(!x)return;const j=new IntersectionObserver(w=>{u(p=>{const h=new Set(p);let b=!1;for(const v of w){const S=v.target.dataset.projectId;if(!S)continue;const N=v.rootBounds?.top??x.getBoundingClientRect().top,A=!v.isIntersecting&&v.boundingClientRect.top<N;h.has(S)!==A&&(b=!0,A?h.add(S):h.delete(S))}return b?h:p})},{root:x,threshold:0});return i.current.forEach(w=>{w&&j.observe(w)}),()=>j.disconnect()},e[1]=c,e[2]=r,e[3]=i,e[4]=m):m=e[4];let f;return e[5]!==c||e[6]!==r||e[7]!==i||e[8]!==o?(f=[c,r,i,o],e[5]=c,e[6]=r,e[7]=i,e[8]=o,e[9]=f):f=e[9],l.useEffect(m,f),d};function x0(t){return t.size===0?t:new Set}function b0(t){return t!==null}const y0=t=>{const e=it.c(10),{open:n,onOpenChange:r,project:o,onSave:i}=t;let c;e[0]!==i||e[1]!==n||e[2]!==o?(c=n&&o?s.jsx(Og,{project:o,onIdentitySave:i,showWorktrees:!1}):null,e[0]=i,e[1]=n,e[2]=o,e[3]=c):c=e[3];let a;e[4]!==c?(a=s.jsx(Bs,{className:"w-full max-w-2xl gap-0 overflow-hidden p-0",children:s.jsx($n,{outerClassName:"max-h-[min(90vh,48rem)]",className:"w-full bg-background",children:s.jsx("div",{className:"w-full p-3 sm:p-6 sm:pt-8",children:c})})}),e[4]=c,e[5]=a):a=e[5];let d;return e[6]!==r||e[7]!==n||e[8]!==a?(d=s.jsx(Ls,{open:n,onOpenChange:r,children:a}),e[6]=r,e[7]=n,e[8]=a,e[9]=d):d=e[9],d};function Wf(t){const e=it.c(6),{state:n,activeLabel:r,unreadLabel:o,className:i}=t,c=n==="active"?r:o,a=n==="active"?"bg-primary":"bg-[var(--status-info)]";let d;e[0]!==i||e[1]!==a?(d=ge("h-1.5 w-1.5 shrink-0 rounded-full",a,i),e[0]=i,e[1]=a,e[2]=d):d=e[2];let u;return e[3]!==c||e[4]!==d?(u=s.jsx("span",{className:d,"aria-label":c,title:c}),e[3]=c,e[4]=d,e[5]=u):u=e[5],u}const v0=t=>{const e=it.c(86),{folder:n,displayName:r,sessions:o,subFolderItems:i,isCollapsed:c,collapsedActivityState:a,onToggle:d,onRename:u,onDelete:m,renderSessionNode:f,getRenderExtras:g,groupDirectory:x,projectId:j,mobileVariant:w,alwaysShowActions:p,isRenaming:h,renameDraft:b,onRenameDraftChange:v,onRenameSave:S,onRenameCancel:N,droppableRef:A,isDropTarget:k,onNewSession:C,depth:P,hideActions:D,archivedBucket:O}=t,F=a===void 0?null:a,B=p===void 0?w===void 0?!1:w:p,$=h===void 0?!1:h,z=b===void 0?"":b,V=k===void 0?!1:k,y=D===void 0?!1:D,I=O===void 0?!1:O,{t:_}=gt(),[W,K]=l.useState(!1),[Z,Q]=l.useState(""),le=l.useRef(null),te=$||W,he=$?z:Z;let xe;e[0]!==n.name?(xe=()=>{Q(n.name),K(!0)},e[0]=n.name,e[1]=xe):xe=e[1];const H=xe;let we;e[2]!==he||e[3]!==n.name||e[4]!==$||e[5]!==u||e[6]!==S?(we=()=>{const ue=he.trim();ue&&ue!==n.name&&u(ue),$&&S&&S(),K(!1),Q("")},e[2]=he,e[3]=n.name,e[4]=$,e[5]=u,e[6]=S,e[7]=we):we=e[7];const de=we;let q;e[8]!==$||e[9]!==N?(q=()=>{$&&N&&N(),K(!1),Q("")},e[8]=$,e[9]=N,e[10]=q):q=e[10];const me=q;let be;e[11]!==$||e[12]!==v?(be=ue=>{$&&v?v(ue):Q(ue)},e[11]=$,e[12]=v,e[13]=be):be=e[13];const Pe=be;let Ie,De;e[14]!==$?(Ie=()=>{if(!$)return;const ue=()=>{const Se=le.current;Se&&(Se.focus(),Se.select())},R=requestAnimationFrame(ue),ae=window.setTimeout(ue,0);return()=>{cancelAnimationFrame(R),window.clearTimeout(ae)}},De=[$],e[14]=$,e[15]=Ie,e[16]=De):(Ie=e[15],De=e[16]),l.useEffect(Ie,De);const Le=c?"folder":"folder-open",Ne=V&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let ve;e[17]!==Ne?(ve=ge("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",Ne),e[17]=Ne,e[18]=ve):ve=e[18];let Me;e[19]!==d||e[20]!==te?(Me=te?void 0:ue=>{ue.currentTarget.blur(),d()},e[19]=d,e[20]=te,e[21]=Me):Me=e[21];const ee=te?void 0:"button",oe=te?void 0:0;let Te;e[22]!==d||e[23]!==te?(Te=te?void 0:ue=>{(ue.key==="Enter"||ue.key===" ")&&(ue.preventDefault(),d())},e[22]=d,e[23]=te,e[24]=Te):Te=e[24];let J;e[25]!==n.name||e[26]!==c||e[27]!==_?(J=c?_("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):_("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[25]=n.name,e[26]=c,e[27]=_,e[28]=J):J=e[28];const re=I?B?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":B?"pr-20":"group-hover/folder:pr-20 group-focus-within/folder:pr-20";let Y;e[29]!==re?(Y=ge("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",re),e[29]=re,e[30]=Y):Y=e[30];const U=V?"text-primary":"text-muted-foreground";let fe;e[31]!==U?(fe=ge("h-3.5 w-3.5 flex-shrink-0",U),e[31]=U,e[32]=fe):fe=e[32];let ne;e[33]!==Le||e[34]!==fe?(ne=s.jsx(T,{name:Le,className:fe}),e[33]=Le,e[34]=fe,e[35]=ne):ne=e[35];let ce;e[36]!==F||e[37]!==r||e[38]!==he||e[39]!==n.name||e[40]!==me||e[41]!==Pe||e[42]!==de||e[43]!==c||e[44]!==V||e[45]!==te||e[46]!==o||e[47]!==_?(ce=te?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:S0,onMouseDown:j0,onSubmit:ue=>{ue.preventDefault(),de()},children:[s.jsx("input",{ref:le,value:he,onChange:ue=>Pe(ue.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:_("sessions.sidebar.folderItem.namePlaceholder"),onClick:k0,onPointerDown:C0,onMouseDown:N0,onKeyDown:ue=>{if(ue.key==="Escape"){ue.stopPropagation(),me();return}(ue.key===" "||ue.key==="Enter")&&ue.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:A0,onPointerDown:D0,onMouseDown:P0,children:s.jsx(T,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:ue=>{ue.stopPropagation(),me()},onPointerDown:E0,onMouseDown:T0,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(T,{name:"close",className:"size-4"})})]}):s.jsxs("div",{className:"min-w-0 flex items-center gap-1.5 flex-1",children:[s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("span",{className:ge("typography-ui-label font-semibold truncate",V?"text-primary":"text-muted-foreground"),children:r??n.name})}),s.jsx(ht,{side:"right",sideOffset:8,className:"max-w-xs",children:r??n.name})]}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70 flex-shrink-0",children:["• ",o.length]}),F?s.jsx(Wf,{state:F,activeLabel:_("sessions.sidebar.session.status.active"),unreadLabel:_("sessions.sidebar.session.status.unread")}):null,c?s.jsx(T,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(T,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]}),e[36]=F,e[37]=r,e[38]=he,e[39]=n.name,e[40]=me,e[41]=Pe,e[42]=de,e[43]=c,e[44]=V,e[45]=te,e[46]=o,e[47]=_,e[48]=ce):ce=e[48];let Fe;e[49]!==Y||e[50]!==ne||e[51]!==ce?(Fe=s.jsxs("div",{className:Y,children:[ne,ce]}),e[49]=Y,e[50]=ne,e[51]=ce,e[52]=Fe):Fe=e[52];let Ye;e[53]!==B||e[54]!==I||e[55]!==n.name||e[56]!==H||e[57]!==y||e[58]!==m||e[59]!==C||e[60]!==te||e[61]!==_?(Ye=!te&&(!y||I)?s.jsx("div",{className:ge("absolute right-0.5 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",B?"opacity-100":"opacity-0 pointer-events-none group-hover/folder:opacity-100 group-hover/folder:pointer-events-auto group-focus-within/folder:opacity-100 group-focus-within/folder:pointer-events-auto"),children:s.jsxs("div",{className:"flex items-center gap-0.5",children:[!I&&C?s.jsx("button",{type:"button",onClick:ue=>{ue.stopPropagation(),C()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":_("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:_("sessions.sidebar.project.actions.newSession"),children:s.jsx(T,{name:"add",className:"h-3.5 w-3.5"})}):null,I?null:s.jsx("button",{type:"button",onClick:ue=>{ue.stopPropagation(),H()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":_("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(T,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:ue=>{ue.stopPropagation(),m()},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":I?_("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):_("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(T,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[53]=B,e[54]=I,e[55]=n.name,e[56]=H,e[57]=y,e[58]=m,e[59]=C,e[60]=te,e[61]=_,e[62]=Ye):Ye=e[62];let $e;e[63]!==A||e[64]!==ve||e[65]!==Me||e[66]!==ee||e[67]!==oe||e[68]!==Te||e[69]!==J||e[70]!==Fe||e[71]!==Ye?($e=s.jsxs("div",{ref:A,className:ve,onClick:Me,role:ee,tabIndex:oe,onKeyDown:Te,"aria-label":J,children:[Fe,Ye]}),e[63]=A,e[64]=ve,e[65]=Me,e[66]=ee,e[67]=oe,e[68]=Te,e[69]=J,e[70]=Fe,e[71]=Ye,e[72]=$e):$e=e[72];let ie;e[73]!==I||e[74]!==g||e[75]!==x||e[76]!==c||e[77]!==j||e[78]!==f||e[79]!==o||e[80]!==i||e[81]!==_?(ie=c?null:s.jsxs("div",{className:"pb-1",children:[i,o.length>0?o.map(ue=>f(ue,0,x??null,j??null,I,void 0,"project",g?.(ue))):i?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:_("sessions.sidebar.folderItem.emptyFolder")})]}),e[73]=I,e[74]=g,e[75]=x,e[76]=c,e[77]=j,e[78]=f,e[79]=o,e[80]=i,e[81]=_,e[82]=ie):ie=e[82];let Re;return e[83]!==$e||e[84]!==ie?(Re=s.jsxs("div",{className:"oc-folder",children:[$e,ie]}),e[83]=$e,e[84]=ie,e[85]=Re):Re=e[85],Re},w0=l.memo(v0);function S0(t){return t.stopPropagation()}function j0(t){return t.stopPropagation()}function k0(t){return t.stopPropagation()}function C0(t){return t.stopPropagation()}function N0(t){return t.stopPropagation()}function A0(t){return t.stopPropagation()}function D0(t){return t.stopPropagation()}function P0(t){return t.stopPropagation()}function E0(t){return t.stopPropagation()}function T0(t){return t.stopPropagation()}const I0=t=>{const e=it.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:o,children:i}=t,c=`session-drag:${n}`;let a;e[0]!==r||e[1]!==n||e[2]!==o?(a={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:o},e[0]=r,e[1]=n,e[2]=o,e[3]=a):a=e[3];let d;e[4]!==c||e[5]!==a?(d={id:c,data:a},e[4]=c,e[5]=a,e[6]=d):d=e[6];const{attributes:u,listeners:m,setNodeRef:f,isDragging:g}=fx(d);let x;e[7]!==m?(x=h=>{h.stopPropagation(),m?.onPointerDown&&m.onPointerDown(h)},e[7]=m,e[8]=x):x=e[8];const j=x,w=g?"opacity-30":void 0;let p;return e[9]!==u||e[10]!==i||e[11]!==j||e[12]!==f||e[13]!==w?(p=s.jsx("div",{ref:f,...u,onPointerDown:j,className:w,children:i}),e[9]=u,e[10]=i,e[11]=j,e[12]=f,e[13]=w,e[14]=p):p=e[14],p},R0=t=>{const e=it.c(11),{folderId:n,children:r}=t,o=`folder-drop:${n}`;let i;e[0]!==n?(i={type:"folder",folderId:n},e[0]=n,e[1]=i):i=e[1];let c;e[2]!==o||e[3]!==i?(c={id:o,data:i},e[2]=o,e[3]=i,e[4]=c):c=e[4];const{setNodeRef:a,isOver:d}=ux(c);let u;e[5]!==r||e[6]!==d||e[7]!==a?(u=r(a,d),e[5]=r,e[6]=d,e[7]=a,e[8]=u):u=e[8];let m;return e[9]!==u?(m=s.jsx(s.Fragment,{children:u}),e[9]=u,e[10]=m):m=e[10],m},M0=t=>{const e=it.c(20),{scopeKey:n,hasFolders:r,onSessionDroppedOnFolder:o,children:i}=t;let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c={activationConstraint:{distance:8}},e[0]=c):c=e[0];const a=ki(Yr(_a,c)),[d,u]=l.useState(null),[m,f]=l.useState("Session"),[g,x]=l.useState(null),[j,w]=l.useState(null);if(!n){let k;return e[1]!==i?(k=s.jsx(s.Fragment,{children:i}),e[1]=i,e[2]=k):k=e[2],k}let p;e[3]!==o?(p=k=>{u(null),x(null),w(null);const{active:C,over:P}=k;if(!P)return;const D=C.data.current,O=P.data.current;D?.type==="session"&&D.sessionId&&O?.type==="folder"&&O.folderId&&o(D.sessionId,O.folderId)},e[3]=o,e[4]=p):p=e[4];const h=p;let b,v;e[5]===Symbol.for("react.memo_cache_sentinel")?(b=k=>{const C=k.active.data.current;if(C?.type==="session"&&C.sessionId){u(C.sessionId),f(C.sessionTitle??"Session");const P=k.active.rect.current.initial?.width,D=k.active.rect.current.initial?.height;x(typeof P=="number"?P:null),w(typeof D=="number"?D:null)}},v=()=>{u(null),x(null),w(null)},e[5]=b,e[6]=v):(b=e[5],v=e[6]);let S;e[7]!==j||e[8]!==d||e[9]!==m||e[10]!==g||e[11]!==r?(S=d&&r?s.jsxs("div",{style:{width:g?`${g}px`:"auto",height:j?`${j}px`:"auto"},className:"flex items-center rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] px-2.5 py-1 shadow-none pointer-events-none",children:[s.jsx(T,{name:"sticky-note",className:"h-4 w-4 text-muted-foreground mr-2 flex-shrink-0"}),s.jsx("div",{className:"min-w-0 flex-1 truncate typography-ui-label font-normal text-foreground",children:m})]}):null,e[7]=j,e[8]=d,e[9]=m,e[10]=g,e[11]=r,e[12]=S):S=e[12];let N;e[13]!==S?(N=s.jsx($a,{children:S}),e[13]=S,e[14]=N):N=e[14];let A;return e[15]!==i||e[16]!==h||e[17]!==a||e[18]!==N?(A=s.jsxs(Ci,{sensors:a,collisionDetection:Ni,onDragStart:b,onDragCancel:v,onDragEnd:h,children:[i,N]}),e[15]=i,e[16]=h,e[17]=a,e[18]=N,e[19]=A):A=e[19],A},Za=(t,e,n)=>{if(!e)return;const r=o=>{let i=o.session.id===e;for(const c of o.children)i=r(c)||i;return i&&n.add(o.session.id),i};for(const o of t)r(o)},Xn=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(Xn(n,e))return!0;return!1},O0=(t,e,n)=>{const r=new Map,o=i=>{const c=Qs(i.session)??jt(i.worktree?.path)??n;if(c){const a=r.get(c)??[];a.push(i.session.id),r.set(c,a)}if(!(i===t&&e))for(const a of i.children)o(a)};return o(t),[...r].map(([i,c])=>({directory:i,sessionIDs:c}))},F0=(t,e)=>{const n=new Set(t);return t.map(r=>e.get(r)).filter(r=>{if(!r)return!1;const o=new Set;let i=r.session.parentID??null;for(;i&&!o.has(i);){if(n.has(i)&&e.has(i))return!1;o.add(i),i=e.get(i)?.session?.parentID??null}return!0})},fd=new WeakMap;let md=1;const L0=t=>{const e=fd.get(t);if(e!==void 0)return e;const n=md;return md+=1,fd.set(t,n),n},Ri=t=>t.children.length===0?"":t.children.map(n=>{const r=L0(n.session);return n.children.length===0?`${n.session.id}@${r}`:`${n.session.id}@${r}:${Ri(n)}`}).join("|"),Vf=(t,e,n,r,o,i)=>{const c=Ps(),a=(d,u)=>{if(d.session.id!==u.session.id||d.children.length!==u.children.length)return!0;const m=d.session.directory??o,f=u.session.directory??i,g=oc(c,m??"",d.session.id),x=oc(c,f??"",u.session.id);return(g?n.has(g):!1)!==(x?r.has(x):!1)?!0:d.children.some((j,w)=>a(j,u.children[w]))};return a(t,e)},To=(t,e,n,r)=>{if(!e)return null;const o=r?"archived":"active";let i=null;const c=a=>{if(`${n}:${o}:${a.session.id}`===e)return i=a.session.id,!0;for(const u of a.children)if(c(u))return!0;return!1};return t.forEach(a=>c(a)),i},Il=(t,e)=>t==="active"||e==="active"?"active":t==="unread"||e==="unread"?"unread":null,Hf=(t,e,n,r)=>{if(e.has(t.session.id))return"active";let o=null;const i=!!t.session.parentID;n.has(t.session.id)&&(r||!i)&&(o="unread");for(const c of t.children)if(o=Il(o,Hf(c,e,n,r)),o==="active")return o;return o},hd=(t,e,n,r)=>{let o=null;for(const i of t)if(o=Il(o,Hf(i,e,n,r)),o==="active")return o;return o},B0=50,_0=28,Zo=(t,e)=>e?t.sessions.some(n=>Xn(n,e)):!1,$0=(t,e,n)=>t.sessions.some(r=>Vf(r,r,e,n,t.directory,t.directory)),z0=(t,e,n)=>{const r=o=>{const i=o.session.id;return e.get(i)!==n.get(i)?!0:o.children.some(r)};return t.sessions.some(r)},pd=(t,e,n)=>{const r=o=>e.has(o.session.id)!==n.has(o.session.id)?!0:o.children.some(r);return t.sessions.some(r)},U0=(t,e)=>{const n=r=>e.has(r.session.id)?!0:r.children.some(n);return t.sessions.some(n)},W0=(t,e,n)=>{const r=t.isArchivedBucket?"archived":"active",o=i=>{const c=`project:${r}:${i.session.id}`;return e.has(c)!==n.has(c)?!0:i.children.some(o)};return t.sessions.some(o)},V0=(t,e)=>{if(t.group!==e.group||t.groupKey!==e.groupKey||t.projectId!==e.projectId||t.hideGroupLabel!==e.hideGroupLabel||t.compactBodyPadding!==e.compactBodyPadding||t.groupSearchDataByGroup!==e.groupSearchDataByGroup||t.visibleSessionCount!==e.visibleSessionCount||t.collapsedGroups!==e.collapsedGroups&&t.collapsedGroups.has(t.groupKey)!==e.collapsedGroups.has(e.groupKey)||t.pinnedSessionIds!==e.pinnedSessionIds&&$0(e.group,t.pinnedSessionIds,e.pinnedSessionIds)||t.expandedParents!==e.expandedParents&&W0(e.group,t.expandedParents,e.expandedParents)||t.sessionOrderIndex!==e.sessionOrderIndex&&z0(e.group,t.sessionOrderIndex,e.sessionOrderIndex)||t.editingId!==e.editingId&&(Zo(t.group,t.editingId)||Zo(e.group,e.editingId))||t.editTitle!==e.editTitle&&(Zo(t.group,t.editingId)||Zo(e.group,e.editingId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=To(t.group.sessions,t.openSidebarMenuKey,"project",!!t.group.isArchivedBucket),r=To(e.group.sessions,e.openSidebarMenuKey,"project",!!e.group.isArchivedBucket);if(n||r)return!1}return t.activeActivitySessionIds!==e.activeActivitySessionIds&&pd(e.group,t.activeActivitySessionIds,e.activeActivitySessionIds)||t.unreadActivitySessionIds!==e.unreadActivitySessionIds&&pd(e.group,t.unreadActivitySessionIds,e.unreadActivitySessionIds)||t.notifyOnSubtasks!==e.notifyOnSubtasks&&U0(e.group,e.unreadActivitySessionIds)?!1:t.hasSessionSearchQuery===e.hasSessionSearchQuery&&t.normalizedSessionSearchQuery===e.normalizedSessionSearchQuery&&t.hideDirectoryControls===e.hideDirectoryControls&&t.collapsedFolderIds===e.collapsedFolderIds&&t.toggleFolderCollapse===e.toggleFolderCollapse&&t.renameFolder===e.renameFolder&&t.deleteFolder===e.deleteFolder&&t.showDeletionDialog===e.showDeletionDialog&&t.setDeleteFolderConfirm===e.setDeleteFolderConfirm&&t.renderSessionNode===e.renderSessionNode&&t.showMoreGroupSessions===e.showMoreGroupSessions&&t.resetGroupSessionLimit===e.resetGroupSessionLimit&&t.mobileVariant===e.mobileVariant&&t.alwaysShowActions===e.alwaysShowActions&&t.activeProjectId===e.activeProjectId&&t.setActiveProjectIdOnly===e.setActiveProjectIdOnly&&t.setActiveMainTab===e.setActiveMainTab&&t.setSessionSwitcherOpen===e.setSessionSwitcherOpen&&t.openNewSessionDraft===e.openNewSessionDraft&&t.addSessionToFolder===e.addSessionToFolder&&t.createFolderAndStartRename===e.createFolderAndStartRename&&t.renamingFolderId===e.renamingFolderId&&t.renameFolderDraft===e.renameFolderDraft&&t.setRenameFolderDraft===e.setRenameFolderDraft&&t.setRenamingFolderId===e.setRenamingFolderId&&t.onToggleCollapsedGroup===e.onToggleCollapsedGroup&&t.dragHandleProps===e.dragHandleProps&&t.scrollContainerRef===e.scrollContainerRef};function H0(t){const{t:e}=gt(),{group:n,groupKey:r,projectId:o,hideGroupLabel:i,hasSessionSearchQuery:c,normalizedSessionSearchQuery:a,groupSearchDataByGroup:d,visibleSessionCount:u,collapsedGroups:m,hideDirectoryControls:f,collapsedFolderIds:g,toggleFolderCollapse:x,renameFolder:j,deleteFolder:w,showDeletionDialog:p,setDeleteFolderConfirm:h,renderSessionNode:b,showMoreGroupSessions:v,resetGroupSessionLimit:S,mobileVariant:N,alwaysShowActions:A,activeProjectId:k,setActiveProjectIdOnly:C,setActiveMainTab:P,setSessionSwitcherOpen:D,openNewSessionDraft:O,addSessionToFolder:F,createFolderAndStartRename:E,renamingFolderId:B,renameFolderDraft:$,setRenameFolderDraft:z,setRenamingFolderId:V,pinnedSessionIds:y,expandedParents:I,sessionOrderIndex:_,editingId:W,openSidebarMenuKey:K,activeActivitySessionIds:Z,unreadActivitySessionIds:Q,notifyOnSubtasks:le,onToggleCollapsedGroup:te,dragHandleProps:he,compactBodyPadding:xe=!1,scrollContainerRef:H}=t,we=l.useCallback((Oe,st)=>{const Ke=_.get(Oe.session.id),Je=_.get(st.session.id);if(Ke!==void 0||Je!==void 0){if(Ke===void 0)return 1;if(Je===void 0)return-1;if(Ke!==Je)return Ke-Je}return so(Oe.session,st.session,y,hl)},[y,_]),de=c?d.get(n):null,q=Vs(Oe=>Oe.foldersMap),me=c?!1:m.has(r),be=l.useMemo(()=>{if(n.isMain||n.isArchivedBucket||i)return null;const Oe=jt(n.directory??null),st=n.branch?.trim();return Oe&&st?zi(Oe,st):null},[n.branch,n.directory,n.isArchivedBucket,n.isMain,i]),Pe=Eu(be),Ie=Pe?`var(--pr-${Pe.visualState})`:void 0,De=Tu(),Le=l.useMemo(()=>{const Oe=n.folderScopes?.map(st=>jt(st.directory))??[jt(n.directory??null)];return[...new Set(Oe.filter(st=>!!st))]},[n.directory,n.folderScopes]);l.useSyncExternalStore(l.useCallback(Oe=>Le.length>0?De.subscribeBootstrap(Oe):()=>{},[Le.length,De]),l.useCallback(()=>Le.map(Oe=>`${Oe}\0${De.getBootstrapState(Oe)??""}\0${De.getBootstrapFailure(Oe)??""}`).join(""),[Le,De]),l.useCallback(()=>"",[]));const Ne=Le.some(Oe=>{const st=De.getBootstrapState(Oe);return st==="queued"||st==="running"}),ve=Le.find(Oe=>De.getBootstrapState(Oe)==="failed")??null,Me=ve?De.getBootstrapFailure(ve):void 0,ee=Me==="os-permission"&&Hm(),[oe,Te]=l.useState(!1),J=l.useCallback(()=>{ve&&De.requestBootstrap({directory:ve,priority:me?"visible":"expanded",reason:n.isMain?"project-expanded":"worktree-expanded",force:!0})},[De,ve,n.isMain,me]),re=l.useCallback(async()=>{if(!(!ve||!ee||oe)){Te(!0);try{(await Km(ve)).success&&J()}finally{Te(!1)}}},[ee,ve,oe,J]),Y=f?10:5,U=Math.max(Y,u??Y),fe=c?de?.groupMatches===!0:!1,ne=c,ce=l.useMemo(()=>[...ne?de?.filteredNodes??[]:n.sessions].sort(we),[we,n.sessions,de?.filteredNodes,ne]),Fe=n.folderScopeKey??jt(n.directory??null),Ye=l.useMemo(()=>n.folderScopes&&n.folderScopes.length>0?n.folderScopes:Fe?[{scopeKey:Fe,directory:n.directory??null}]:[],[Fe,n.directory,n.folderScopes]),$e=l.useMemo(()=>Ye.flatMap(({scopeKey:Oe,directory:st})=>(q[Oe]??[]).map(Ke=>({folder:Ke,scopeKey:Oe,scopeDirectory:st}))),[Ye,q]),ie=l.useMemo(()=>{const Oe=new Map,st=Ke=>{Ke.forEach(Je=>{Oe.set(Je.session.id,Je),Je.children.length>0&&st(Je.children)})};return st(ce),Oe},[ce]),Re=l.useMemo(()=>$e.map(({folder:Oe,scopeKey:st,scopeDirectory:Ke})=>{const Je=F0(Oe.sessionIds,ie).sort(we);return{folder:Oe,scopeKey:st,scopeDirectory:Ke,nodes:Je}}),[$e,ie,we]),ue=l.useMemo(()=>{const Oe=new Map(Re.map(Qe=>[Qe.folder.id,Qe])),st=new Map;for(const{folder:Qe}of Re){if(!Qe.parentId)continue;const kt=st.get(Qe.parentId);kt?kt.push(Qe.id):st.set(Qe.parentId,[Qe.id])}const Ke=new Map,Je=Qe=>{const kt=Ke.get(Qe);if(kt!==void 0)return kt;const ts=Oe.get(Qe);if(!ts)return Ke.set(Qe,!1),!1;const Wt=st.get(Qe)??[];if(n.isArchivedBucket&&ts.nodes.length===0){const Vt=Wt.some(js=>Je(js));return Ke.set(Qe,Vt),Vt}if(!c||ts.folder.name.toLowerCase().includes(a)||ts.nodes.length>0)return Ke.set(Qe,!0),!0;const Bt=Wt.some(Vt=>Je(Vt));return Ke.set(Qe,Bt),Bt};return Re.filter(({folder:Qe})=>Je(Qe.id))},[Re,n.isArchivedBucket,c,a]),R=l.useMemo(()=>new Set(ue.flatMap(Oe=>Oe.folder.sessionIds)),[ue]),ae=l.useMemo(()=>ce.filter(Oe=>!R.has(Oe.session.id)),[ce,R]),Se=l.useMemo(()=>ue.filter(({folder:Oe})=>!Oe.parentId),[ue]),Ce=l.useMemo(()=>{const Oe=new Map;return ue.forEach(st=>{if(!st.folder.parentId)return;const Ke=Oe.get(st.folder.parentId)??[];Ke.push(st),Oe.set(st.folder.parentId,Ke)}),Oe},[ue]),Ee=l.useMemo(()=>{const Oe=new Map(ue.map(Je=>[Je.folder.id,Je])),st=new Map,Ke=(Je,Qe)=>{const kt=st.get(Je);if(kt!==void 0)return kt;if(Qe.has(Je))return null;Qe.add(Je);const ts=Oe.get(Je);let Wt=ts?hd(ts.nodes,Z,Q,le):null;for(const us of Ce.get(Je)??[])if(Wt=Il(Wt,Ke(us.folder.id,Qe)),Wt==="active")break;return st.set(Je,Wt),Wt};return ue.forEach(({folder:Je})=>Ke(Je.id,new Set)),st},[Z,ue,Ce,le,Q]),se="project",je=l.useMemo(()=>{const Oe=new Set;return Za(ce,W,Oe),ue.forEach(({nodes:st})=>{Za(st,W,Oe)}),Oe},[ce,ue,W]),Ze=l.useMemo(()=>{if(!K)return null;const Oe=To(ce,K,se,!!n.isArchivedBucket);if(Oe)return Oe;for(const{nodes:st}of ue){const Ke=To(st,K,se,!!n.isArchivedBucket);if(Ke)return Ke}return null},[K,ce,ue,n.isArchivedBucket]),X=l.useCallback(Oe=>{const st=new WeakMap,Ke=Je=>{st.set(Je,Ri(Je));for(const Qe of Je.children)Ke(Qe)};return Oe.forEach(Ke),st},[]),ye=l.useMemo(()=>X(ce),[X,ce]),Xe=l.useMemo(()=>{const Oe=new WeakMap;return ue.forEach(({nodes:st})=>{st.forEach(Ke=>Oe.set(Ke,Ri(Ke)))}),Oe},[ue]),Be=l.useCallback(Oe=>ye.get(Oe)??Xe.get(Oe)??"",[ye,Xe]),We=l.useCallback(Oe=>({subtreeContainsEditing:je,menuOpenSessionId:Ze,nodeStructureKey:Be(Oe)}),[je,Ze,Be]),_e=ae.length,tt=n.isArchivedBucket||c?ae:ae.slice(0,U),ct=_e-tt.length,Et=!n.isArchivedBucket&&!c&&_e>Y&&ct===0,Nt=n.isArchivedBucket===!0&&!c&&tt.length>=B0,Ot=n.isArchivedBucket?"archived":"active",et=Nt&&tt.some(Oe=>{if(Oe.children.length===0)return!1;const st=`project:${Ot}:${Oe.session.id}`;return I.has(st)}),Tt=l.useRef(null),[xt,vt]=l.useState(null),[_t,Ct]=l.useState(0),[,Rt]=l.useState(0);l.useEffect(()=>{if(!Nt)return;const Oe=Tt.current;if(!Oe||typeof ResizeObserver>"u")return;const st=new ResizeObserver(()=>Rt(Ke=>Ke+1));return st.observe(Oe),()=>st.disconnect()},[Nt]),l.useLayoutEffect(()=>{if(!Nt){xt!==null&&vt(null),_t!==0&&Ct(0);return}const Oe=Tt.current;if(!Oe)return;let st=xt;const Ke=H?.current??null;if(Ke&&Ke.contains(Oe)){if(st=Ke,st!==xt){vt(st);return}}else if(!st||!st.contains(Oe)){let Qe=Oe.parentElement;for(;Qe;){const kt=window.getComputedStyle(Qe);if(kt.overflowY==="auto"||kt.overflowY==="scroll"){st=Qe;break}Qe=Qe.parentElement}if(st!==xt){vt(st);return}}if(!st)return;const Je=Oe.getBoundingClientRect().top-st.getBoundingClientRect().top+st.scrollTop;Ct(Qe=>Math.abs(Qe-Je)<1?Qe:Je)});const ut=Nt&&xt!==null,bt=px({count:tt.length,enabled:ut,getScrollElement:()=>xt,initialOffset:()=>xt?.scrollTop??0,estimateSize:()=>_0,overscan:et?20:8,scrollMargin:_t,getItemKey:Oe=>tt[Oe]?.session.id??Oe}),He=l.useCallback(Oe=>{const st=[],Ke=Je=>{Je.forEach(Qe=>{st.push(Qe.session),Qe.children.length>0&&Ke(Qe.children)})};return Ke(Oe),st},[]),Ve=l.useMemo(()=>He(ce),[He,ce]),wt=l.useMemo(()=>{if(!n.isArchivedBucket)return new Map;const Oe=new Map,st=new Map;for(const{folder:Je}of ue){if(!Je.parentId)continue;const Qe=st.get(Je.parentId)??[];Qe.push(Je.id),st.set(Je.parentId,Qe)}const Ke=(Je,Qe)=>{if(Qe.has(Je))return[];Qe.add(Je);const kt=ue.find(({folder:us})=>us.id===Je),ts=kt?He(kt.nodes):[],Wt=st.get(Je)??[];for(const us of Wt)ts.push(...Ke(us,Qe));return ts};for(const{folder:Je}of ue)Oe.set(Je.id,Ke(Je.id,new Set));return Oe},[ue,He,n.isArchivedBucket]);if(c&&!fe&&Se.length===0&&ae.length===0)return null;const Ft=!n.isMain&&!!n.branch,Lt=n.branch&&tp(n.branch,n.label)?{label:n.branch}:null,ns=me?hd(ce,Z,Q,le):null,$t=ns?s.jsx(Wf,{state:ns,activeLabel:e("sessions.sidebar.session.status.active"),unreadLabel:e("sessions.sidebar.session.status.unread")}):null,At=(Oe,st)=>{const{folder:Ke,scopeKey:Je,scopeDirectory:Qe,nodes:kt}=Oe,ts=wt.get(Ke.id)??[],Wt=c?!1:g.has(Ke.id);return s.jsx(R0,{folderId:Ke.id,children:(us,Bt)=>s.jsx(w0,{folder:Ke,displayName:st,sessions:kt,isCollapsed:Wt,collapsedActivityState:Wt?Ee.get(Ke.id)??null:null,onToggle:()=>x(Ke.id),onRename:Vt=>{j(Je,Ke.id,Vt)},onDelete:()=>{if(n.isArchivedBucket){Un.requestDelete({sessions:ts,mode:"session"});return}if(!p){w(Je,Ke.id);return}const Vt=ue.filter(({folder:ln})=>ln.parentId===Ke.id).length,js=kt.length;h({scopeKey:Je,folderId:Ke.id,folderName:Ke.name,subFolderCount:Vt,sessionCount:js})},renderSessionNode:b,getRenderExtras:Be?Vt=>({subtreeContainsEditing:je,menuOpenSessionId:Ze,nodeStructureKey:Be(Vt),childRenderExtrasFor:We}):void 0,groupDirectory:Qe??n.directory,projectId:o,mobileVariant:N,alwaysShowActions:A,isRenaming:B===Ke.id,renameDraft:B===Ke.id?$:void 0,onRenameDraftChange:Vt=>z(Vt),onRenameSave:()=>{const Vt=$.trim();Vt&&j(Je,Ke.id,Vt),V(null),z("")},onRenameCancel:()=>{V(null),z("")},droppableRef:us,isDropTarget:Bt,depth:0,onNewSession:()=>{o&&o!==k&&C(o),P("chat"),N&&D(!1),O({selectedProjectId:o,directoryOverride:Qe??n.directory,targetFolderId:Ke.id})},hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},Ke.id)},ss=()=>{const Oe=new Map;for(const Je of ue){const Qe=Je.folder.parentId;if(!Qe)continue;const kt=Oe.get(Qe);kt?kt.push(Je):Oe.set(Qe,[Je])}const st=[],Ke=(Je,Qe)=>{const kt=Qe?`${Qe} / ${Je.folder.name}`:Je.folder.name;st.push(At(Je,kt)),!(!c&&g.has(Je.folder.id))&&(Oe.get(Je.folder.id)??[]).forEach(Wt=>Ke(Wt,kt))};return Se.forEach(Je=>Ke(Je,"")),st},ms=!!(!n.isMain&&n.worktree),zt=A?ms?"pr-14":"pr-7":ms?"pr-2 group-hover/gh:pr-14 group-focus-within/gh:pr-14":"pr-2 group-hover/gh:pr-7 group-focus-within/gh:pr-7",qt=ve?s.jsxs("span",{className:"inline-flex flex-wrap items-center gap-1.5",children:[e(Me==="os-permission"?"sessions.sidebar.group.empty.permissionDenied":"sessions.sidebar.group.empty.loadFailed"),ee?s.jsx(lt,{variant:"link",size:"xs",className:"h-auto p-0 typography-micro",disabled:oe,onClick:()=>{re()},children:e("sessions.sidebar.group.empty.grantAccess")}):null,s.jsx(lt,{variant:"link",size:"xs",className:"h-auto p-0 typography-micro",onClick:J,children:e("sessions.sidebar.group.empty.retry")})]}):null,Ut=s.jsxs(M0,{scopeKey:Ye[0]?.scopeKey??Fe,hasFolders:ue.length>0,onSessionDroppedOnFolder:(Oe,st)=>{const Ke=ue.find(({folder:Qe})=>Qe.id===st);if(!Ke)return;const Je=Vs.getState();for(const{scopeKey:Qe}of Ye)Qe!==Ke.scopeKey&&Je.getSessionFolderId(Qe,Oe)&&Je.removeSessionFromFolder(Qe,Oe);F(Ke.scopeKey,st,Oe)},children:[ss(),Nt?s.jsx("div",{ref:Tt,children:ut?s.jsx("div",{style:{height:bt.getTotalSize(),position:"relative"},children:bt.getVirtualItems().map(Oe=>{const st=tt[Oe.index];return st?s.jsx("div",{"data-index":Oe.index,ref:bt.measureElement,className:"[&_[data-session-row]]:my-px",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${Oe.start-_t}px)`},children:b(st,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsEditing:je,menuOpenSessionId:Ze,nodeStructureKey:Be(st),childRenderExtrasFor:We})},st.session.id):null})}):tt.map(Oe=>b(Oe,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsEditing:je,menuOpenSessionId:Ze,nodeStructureKey:Be(Oe),childRenderExtrasFor:We}))}):tt.map(Oe=>b(Oe,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsEditing:je,menuOpenSessionId:Ze,nodeStructureKey:Be(Oe),childRenderExtrasFor:We})),_e===0&&ue.length===0?s.jsx("div",{className:"py-1 pl-[26px] text-left typography-micro text-muted-foreground",children:n.isArchivedBucket?e("sessions.sidebar.group.empty.noArchivedSessions"):Ne?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(T,{name:"loader-4",className:"size-3 animate-spin"}),e("sessions.sidebar.group.empty.loadingSessions")]}):qt||e("sessions.sidebar.group.empty.noSessionsInWorkspace")}):null,_e>0&&qt?s.jsx("div",{className:"py-1 pl-[26px] text-left typography-micro text-status-error",children:qt}):null,ct>0?s.jsx("button",{type:"button",onClick:()=>v(r,tt.length),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showMore")}):null,Et?s.jsx("button",{type:"button",onClick:()=>S(r),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showFewer")}):null]}),Jt="pb-2";return i?s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:ge("oc-group-body",Jt),children:Ut})}):s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:ge("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>te(r),role:"button",tabIndex:0,onKeyDown:Oe=>{(Oe.key==="Enter"||Oe.key===" ")&&(Oe.preventDefault(),te(r))},"aria-label":me?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!me,children:[s.jsx("div",{ref:he?.setActivatorNodeRef,className:ge("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-1.5 transition-[padding]",zt),...he?.listeners??{},children:s.jsxs("div",{className:"min-w-0 flex flex-1 flex-col justify-center gap-0.5 overflow-hidden",children:[s.jsx("p",{className:"text-[14px] font-normal truncate text-foreground/92",children:n.isArchivedBucket?s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(T,{name:"archive",className:ge("h-3.5 w-3.5 shrink-0 text-muted-foreground",A?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:ge("text-muted-foreground h-3.5 w-3.5 items-center justify-center",A?"inline-flex":"hidden group-hover/gh:inline-flex"),children:me?s.jsx(T,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(T,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:li(n.label,a)}),$t]}):!n.isMain||n.worktree?s.jsxs("span",{className:"flex w-full min-w-0 items-center gap-1.5",children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center",children:[s.jsx(T,{name:"git-branch",className:ge("h-3.5 w-3.5 shrink-0",!Ie&&"text-muted-foreground",A?"hidden":"group-hover/gh:hidden"),style:Ie?{color:Ie}:void 0}),s.jsx("span",{className:ge("text-muted-foreground h-3.5 w-3.5 items-center justify-center",A?"inline-flex":"hidden group-hover/gh:inline-flex"),children:me?s.jsx(T,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(T,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 truncate typography-ui-label font-semibold text-muted-foreground",children:li(n.label,a)}),$t,Pe?s.jsxs("span",{className:"ml-auto flex-shrink-0 text-[0.72rem] font-medium leading-none",style:Ie?{color:Ie}:void 0,children:["#",Pe.number]}):null]}):s.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1",children:[s.jsx("span",{className:"min-w-0 truncate",children:li(n.label,a)}),$t]})}),Ft&&Lt?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(T,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(T,{name:"git-branch",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}),s.jsx("span",{className:"min-w-0 truncate text-[11px] font-medium text-muted-foreground/80",children:Lt.label})]}):null]})}),n.isArchivedBucket&&Ve.length>0?s.jsx("div",{className:ge("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",A?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(ft,{delayDuration:500,children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Oe=>{Oe.stopPropagation(),Un.requestDelete({sessions:Ve,mode:"session"})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteArchivedInGroupAria",{label:n.label}),children:s.jsx(T,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteArchivedSessions")})})]})}):null,n.directory&&!n.isMain&&n.worktree?s.jsx("div",{className:ge("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",A?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(ft,{delayDuration:500,children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Oe=>{Oe.stopPropagation(),Un.requestDelete({sessions:Ve,mode:"worktree",worktree:n.worktree})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.deleteGroupAria",{label:n.label}),children:s.jsx(T,{name:"delete-bin",className:"h-4 w-4"})})}),s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:ge("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",A?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(ft,{delayDuration:500,children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Oe=>{Oe.stopPropagation(),o&&o!==k&&C(o),P("chat"),N&&D(!1),O({selectedProjectId:o,directoryOverride:n.directory})},className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.sidebar.group.actions.newDraftInGroupAria",{label:n.label}),children:s.jsx(T,{name:"add",className:"h-4 w-4"})})}),s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),me?null:s.jsx("div",{className:ge("oc-group-body",Jt),children:Ut})]})}const K0=l.memo(H0,V0),G0=(t,e)=>{const n=t??{};return e<2&&(n.projectSortOrder="manual"),e<3&&n.projectSortOrder==="recent"&&(n.projectSortOrder="manual"),e<4&&delete n.displayMode,n},Ds=br()(ef(t=>({sessionGroupingMode:"by-worktree",setSessionGroupingMode:e=>t({sessionGroupingMode:e}),stickyZoneHeaders:!0,toggleStickyZoneHeaders:()=>t(e=>({stickyZoneHeaders:!e.stickyZoneHeaders})),showRecentSection:!0,showArchivedSessions:!1,projectSortOrder:"manual",setShowRecentSection:e=>t({showRecentSection:e}),setShowArchivedSessions:e=>t({showArchivedSessions:e}),toggleRecentSection:()=>t(e=>({showRecentSection:!e.showRecentSection})),toggleArchivedSessions:()=>t(e=>({showArchivedSessions:!e.showArchivedSessions})),setProjectSortOrder:e=>t({projectSortOrder:e})}),{name:"session-display-mode",version:4,migrate:G0}));function q0(t){const e=it.c(219),{t:n}=gt(),{hideDirectoryControls:r,showRecentControls:o,handleOpenDirectoryDialog:i,onOpenScheduled:c,onOpenMultiRun:a,canOpenMultiRun:d,onOpenArchive:u,headerActionIconClass:m,headerActionButtonClass:f,isSessionSearchOpen:g,setIsSessionSearchOpen:x,sessionSearchInputRef:j,sessionSearchQuery:w,setSessionSearchQuery:p,hasSessionSearchQuery:h,searchMatchCount:b,collapseAllProjects:v,expandAllProjects:S,selectionModeEnabled:N,onToggleSelectionMode:A}=t,k=Ds(nj),C=Ds(sj),P=Ds(tj),D=Ds(ej),O=Ds(Z0),F=Ds(J0),E=Ds(X0),B=Ds(Q0);if(r)return null;let $;e[0]!==f?($=ge(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[0]=f,e[1]=$):$=e[1];let z;e[2]!==n?(z=n("sessions.sidebar.header.actions.addProject"),e[2]=n,e[3]=z):z=e[3];let V;e[4]!==m?(V=s.jsx(T,{name:"folder-add",className:m}),e[4]=m,e[5]=V):V=e[5];let y;e[6]!==i||e[7]!==$||e[8]!==z||e[9]!==V?(y=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:$,"aria-label":z,children:V})}),e[6]=i,e[7]=$,e[8]=z,e[9]=V,e[10]=y):y=e[10];let I;e[11]!==n?(I=n("sessions.sidebar.header.actions.addProject"),e[11]=n,e[12]=I):I=e[12];let _;e[13]!==I?(_=s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:I})}),e[13]=I,e[14]=_):_=e[14];let W;e[15]!==y||e[16]!==_?(W=s.jsxs(ft,{delayDuration:500,children:[y,_]}),e[15]=y,e[16]=_,e[17]=W):W=e[17];let K;e[18]!==f?(K=ge(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[18]=f,e[19]=K):K=e[19];let Z;e[20]!==n?(Z=n("sessions.sidebar.header.actions.scheduledTasks"),e[20]=n,e[21]=Z):Z=e[21];let Q;e[22]!==m?(Q=s.jsx(T,{name:"calendar-schedule",className:m}),e[22]=m,e[23]=Q):Q=e[23];let le;e[24]!==c||e[25]!==K||e[26]!==Z||e[27]!==Q?(le=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,className:K,"aria-label":Z,children:Q})}),e[24]=c,e[25]=K,e[26]=Z,e[27]=Q,e[28]=le):le=e[28];let te;e[29]!==n?(te=n("sessions.sidebar.header.actions.scheduledTasks"),e[29]=n,e[30]=te):te=e[30];let he;e[31]!==te?(he=s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:te})}),e[31]=te,e[32]=he):he=e[32];let xe;e[33]!==le||e[34]!==he?(xe=s.jsxs(ft,{delayDuration:500,children:[le,he]}),e[33]=le,e[34]=he,e[35]=xe):xe=e[35];let H;e[36]!==f?(H=ge(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[36]=f,e[37]=H):H=e[37];let we;e[38]!==n?(we=n("sessions.sidebar.header.actions.newMultiRun"),e[38]=n,e[39]=we):we=e[39];const de=!d;let q;e[40]!==m?(q=s.jsx(sp,{className:m}),e[40]=m,e[41]=q):q=e[41];let me;e[42]!==a||e[43]!==H||e[44]!==we||e[45]!==de||e[46]!==q?(me=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:H,"aria-label":we,disabled:de,children:q})}),e[42]=a,e[43]=H,e[44]=we,e[45]=de,e[46]=q,e[47]=me):me=e[47];let be;e[48]!==n?(be=n("sessions.sidebar.header.actions.newMultiRun"),e[48]=n,e[49]=be):be=e[49];let Pe;e[50]!==be?(Pe=s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:be})}),e[50]=be,e[51]=Pe):Pe=e[51];let Ie;e[52]!==me||e[53]!==Pe?(Ie=s.jsxs(ft,{delayDuration:500,children:[me,Pe]}),e[52]=me,e[53]=Pe,e[54]=Ie):Ie=e[54];let De;e[55]!==f?(De=ge(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[55]=f,e[56]=De):De=e[56];let Le;e[57]!==n?(Le=n("sessions.sidebar.nav.archive"),e[57]=n,e[58]=Le):Le=e[58];let Ne;e[59]!==m?(Ne=s.jsx(T,{name:"archive",className:m}),e[59]=m,e[60]=Ne):Ne=e[60];let ve;e[61]!==u||e[62]!==De||e[63]!==Le||e[64]!==Ne?(ve=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:De,"aria-label":Le,children:Ne})}),e[61]=u,e[62]=De,e[63]=Le,e[64]=Ne,e[65]=ve):ve=e[65];let Me;e[66]!==n?(Me=n("sessions.sidebar.nav.archive"),e[66]=n,e[67]=Me):Me=e[67];let ee;e[68]!==Me?(ee=s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Me})}),e[68]=Me,e[69]=ee):ee=e[69];let oe;e[70]!==ve||e[71]!==ee?(oe=s.jsxs(ft,{delayDuration:500,children:[ve,ee]}),e[70]=ve,e[71]=ee,e[72]=oe):oe=e[72];let Te;e[73]!==xe||e[74]!==Ie||e[75]!==oe||e[76]!==W?(Te=s.jsxs("div",{className:"ml-[3px] flex items-center gap-1.5",children:[W,xe,Ie,oe]}),e[73]=xe,e[74]=Ie,e[75]=oe,e[76]=W,e[77]=Te):Te=e[77];let J;e[78]!==x?(J=()=>x(Y0),e[78]=x,e[79]=J):J=e[79];let re;e[80]!==f?(re=ge(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[80]=f,e[81]=re):re=e[81];let Y;e[82]!==n?(Y=n("sessions.sidebar.header.actions.searchSessions"),e[82]=n,e[83]=Y):Y=e[83];let U;e[84]!==m?(U=s.jsx(T,{name:"search",className:m}),e[84]=m,e[85]=U):U=e[85];let fe;e[86]!==g||e[87]!==J||e[88]!==re||e[89]!==Y||e[90]!==U?(fe=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:J,className:re,"aria-label":Y,"aria-expanded":g,children:U})}),e[86]=g,e[87]=J,e[88]=re,e[89]=Y,e[90]=U,e[91]=fe):fe=e[91];let ne;e[92]!==n?(ne=n("sessions.sidebar.header.actions.searchSessions"),e[92]=n,e[93]=ne):ne=e[93];let ce;e[94]!==ne?(ce=s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ne})}),e[94]=ne,e[95]=ce):ce=e[95];let Fe;e[96]!==fe||e[97]!==ce?(Fe=s.jsxs(ft,{delayDuration:500,children:[fe,ce]}),e[96]=fe,e[97]=ce,e[98]=Fe):Fe=e[98];const Ye=N&&"bg-interactive-hover text-primary";let $e;e[99]!==f||e[100]!==Ye?($e=ge(f,"text-muted-foreground hover:text-foreground hover:bg-transparent",Ye),e[99]=f,e[100]=Ye,e[101]=$e):$e=e[101];let ie;e[102]!==N||e[103]!==n?(ie=n(N?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[102]=N,e[103]=n,e[104]=ie):ie=e[104];let Re;e[105]!==m?(Re=s.jsx(T,{name:"checkbox-multiple",className:m}),e[105]=m,e[106]=Re):Re=e[106];let ue;e[107]!==A||e[108]!==N||e[109]!==$e||e[110]!==ie||e[111]!==Re?(ue=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:A,className:$e,"aria-label":ie,"aria-pressed":N,children:Re})}),e[107]=A,e[108]=N,e[109]=$e,e[110]=ie,e[111]=Re,e[112]=ue):ue=e[112];let R;e[113]!==N||e[114]!==n?(R=n(N?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[113]=N,e[114]=n,e[115]=R):R=e[115];let ae;e[116]!==R?(ae=s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:R})}),e[116]=R,e[117]=ae):ae=e[117];let Se;e[118]!==ue||e[119]!==ae?(Se=s.jsxs(ft,{delayDuration:500,children:[ue,ae]}),e[118]=ue,e[119]=ae,e[120]=Se):Se=e[120];let Ce;e[121]!==f?(Ce=ge(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[121]=f,e[122]=Ce):Ce=e[122];let Ee;e[123]!==n?(Ee=n("sessions.sidebar.header.displayMode.label"),e[123]=n,e[124]=Ee):Ee=e[124];let se;e[125]!==m?(se=s.jsx(T,{name:"equalizer-2",className:m}),e[125]=m,e[126]=se):se=e[126];let je;e[127]!==Ce||e[128]!==Ee||e[129]!==se?(je=s.jsx(mt,{asChild:!0,children:s.jsx(wn,{asChild:!0,children:s.jsx("button",{type:"button",className:Ce,"aria-label":Ee,children:se})})}),e[127]=Ce,e[128]=Ee,e[129]=se,e[130]=je):je=e[130];let Ze;e[131]!==n?(Ze=n("sessions.sidebar.header.displayMode.label"),e[131]=n,e[132]=Ze):Ze=e[132];let X;e[133]!==Ze?(X=s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Ze})}),e[133]=Ze,e[134]=X):X=e[134];let ye;e[135]!==je||e[136]!==X?(ye=s.jsxs(ft,{delayDuration:500,children:[je,X]}),e[135]=je,e[136]=X,e[137]=ye):ye=e[137];let Xe;e[138]!==n?(Xe=n("sessions.sidebar.header.actions.sortProjects"),e[138]=n,e[139]=Xe):Xe=e[139];let Be;e[140]!==Xe?(Be=s.jsx(Ta,{children:Xe}),e[140]=Xe,e[141]=Be):Be=e[141];let We;e[142]!==P||e[143]!==D||e[144]!==n?(We=[["manual","sessions.sidebar.header.projectSort.manual"],["a-z","sessions.sidebar.header.projectSort.aToZ"],["z-a","sessions.sidebar.header.projectSort.zToA"],["date-added","sessions.sidebar.header.projectSort.dateAdded"],["recent","sessions.sidebar.header.projectSort.recent"]].map(zt=>{const[qt,Ut]=zt;return s.jsxs(Xt,{onClick:()=>D(qt),className:"flex items-center justify-between",children:[s.jsx("span",{children:n(Ut)}),P===qt?s.jsx(T,{name:"check",className:"h-4 w-4 text-primary"}):null]},qt)}),e[142]=P,e[143]=D,e[144]=n,e[145]=We):We=e[145];let _e;e[146]===Symbol.for("react.memo_cache_sentinel")?(_e=s.jsx(vn,{}),e[146]=_e):_e=e[146];let tt;e[147]!==n?(tt=n("sessions.sidebar.header.grouping.label"),e[147]=n,e[148]=tt):tt=e[148];let ct;e[149]!==tt?(ct=s.jsx(Ta,{children:tt}),e[149]=tt,e[150]=ct):ct=e[150];let Et;e[151]!==O||e[152]!==F||e[153]!==n?(Et=[["by-worktree","sessions.sidebar.header.grouping.byWorktree"],["flat","sessions.sidebar.header.grouping.flat"]].map(zt=>{const[qt,Ut]=zt;return s.jsxs(Xt,{onClick:()=>F(qt),className:"flex items-center justify-between",children:[s.jsx("span",{children:n(Ut)}),O===qt?s.jsx(T,{name:"check",className:"h-4 w-4 text-primary"}):null]},qt)}),e[151]=O,e[152]=F,e[153]=n,e[154]=Et):Et=e[154];let Nt;e[155]===Symbol.for("react.memo_cache_sentinel")?(Nt=s.jsx(vn,{}),e[155]=Nt):Nt=e[155];let Ot;e[156]!==o||e[157]!==k||e[158]!==n||e[159]!==C?(Ot=o?s.jsxs(Xt,{onClick:C,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),k?s.jsx(T,{name:"check",className:"h-4 w-4 text-primary"}):null]}):null,e[156]=o,e[157]=k,e[158]=n,e[159]=C,e[160]=Ot):Ot=e[160];let et;e[161]!==n?(et=n("sessions.sidebar.header.displayMode.stickyHeaders"),e[161]=n,e[162]=et):et=e[162];let Tt;e[163]!==et?(Tt=s.jsx("span",{children:et}),e[163]=et,e[164]=Tt):Tt=e[164];let xt;e[165]!==E?(xt=E?s.jsx(T,{name:"check",className:"h-4 w-4 text-primary"}):null,e[165]=E,e[166]=xt):xt=e[166];let vt;e[167]!==Tt||e[168]!==xt||e[169]!==B?(vt=s.jsxs(Xt,{onClick:B,className:"flex items-center justify-between",children:[Tt,xt]}),e[167]=Tt,e[168]=xt,e[169]=B,e[170]=vt):vt=e[170];let _t;e[171]===Symbol.for("react.memo_cache_sentinel")?(_t=s.jsx(vn,{}),e[171]=_t):_t=e[171];let Ct;e[172]===Symbol.for("react.memo_cache_sentinel")?(Ct=s.jsx(T,{name:"contract-up-down",className:"h-4 w-4"}),e[172]=Ct):Ct=e[172];let Rt;e[173]!==n?(Rt=n("sessions.sidebar.header.displayMode.collapseAll"),e[173]=n,e[174]=Rt):Rt=e[174];let ut;e[175]!==Rt?(ut=s.jsx("span",{children:Rt}),e[175]=Rt,e[176]=ut):ut=e[176];let bt;e[177]!==v||e[178]!==ut?(bt=s.jsxs(Xt,{onClick:v,className:"flex items-center gap-2",children:[Ct,ut]}),e[177]=v,e[178]=ut,e[179]=bt):bt=e[179];let He;e[180]===Symbol.for("react.memo_cache_sentinel")?(He=s.jsx(T,{name:"expand-up-down",className:"h-4 w-4"}),e[180]=He):He=e[180];let Ve;e[181]!==n?(Ve=n("sessions.sidebar.header.displayMode.expandAll"),e[181]=n,e[182]=Ve):Ve=e[182];let wt;e[183]!==Ve?(wt=s.jsx("span",{children:Ve}),e[183]=Ve,e[184]=wt):wt=e[184];let Ft;e[185]!==S||e[186]!==wt?(Ft=s.jsxs(Xt,{onClick:S,className:"flex items-center gap-2",children:[He,wt]}),e[185]=S,e[186]=wt,e[187]=Ft):Ft=e[187];let Lt;e[188]!==Be||e[189]!==We||e[190]!==ct||e[191]!==Et||e[192]!==Ot||e[193]!==vt||e[194]!==bt||e[195]!==Ft?(Lt=s.jsxs(Sn,{align:"end",className:"min-w-[180px]",children:[Be,We,_e,ct,Et,Nt,Ot,vt,_t,bt,Ft]}),e[188]=Be,e[189]=We,e[190]=ct,e[191]=Et,e[192]=Ot,e[193]=vt,e[194]=bt,e[195]=Ft,e[196]=Lt):Lt=e[196];let ns;e[197]!==ye||e[198]!==Lt?(ns=s.jsxs(jn,{children:[ye,Lt]}),e[197]=ye,e[198]=Lt,e[199]=ns):ns=e[199];let $t;e[200]!==Fe||e[201]!==Se||e[202]!==ns?($t=s.jsxs("div",{className:"flex items-center gap-1.5",children:[Fe,Se,ns]}),e[200]=Fe,e[201]=Se,e[202]=ns,e[203]=$t):$t=e[203];let At;e[204]!==Te||e[205]!==$t?(At=s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[Te,$t]}),e[204]=Te,e[205]=$t,e[206]=At):At=e[206];let ss;e[207]!==h||e[208]!==g||e[209]!==b||e[210]!==j||e[211]!==w||e[212]!==x||e[213]!==p||e[214]!==n?(ss=g?s.jsxs("div",{className:"pb-1",children:[s.jsxs("div",{className:"mb-1 flex items-center justify-between px-0.5 typography-micro text-muted-foreground/80",children:[h?s.jsx("span",{children:b===1?n("sessions.sidebar.header.search.matchCountSingle",{count:b}):n("sessions.sidebar.header.search.matchCountPlural",{count:b})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(T,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx("input",{ref:j,value:w,onChange:zt=>p(zt.target.value),placeholder:n("sessions.sidebar.header.search.placeholder"),className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-8 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50",onKeyDown:zt=>{zt.key==="Escape"&&(zt.stopPropagation(),h?p(""):x(!1))}}),w.length>0?s.jsx("button",{type:"button",onClick:()=>p(""),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/60 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":n("sessions.sidebar.header.search.clear"),children:s.jsx(T,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null,e[207]=h,e[208]=g,e[209]=b,e[210]=j,e[211]=w,e[212]=x,e[213]=p,e[214]=n,e[215]=ss):ss=e[215];let ms;return e[216]!==At||e[217]!==ss?(ms=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 py-1",children:s.jsxs("div",{className:"flex h-auto min-h-8 flex-col gap-1",children:[At,ss]})}),e[216]=At,e[217]=ss,e[218]=ms):ms=e[218],ms}function Y0(t){return!t}function Q0(t){return t.toggleStickyZoneHeaders}function X0(t){return t.stickyZoneHeaders}function J0(t){return t.setSessionGroupingMode}function Z0(t){return t.sessionGroupingMode}function ej(t){return t.setProjectSortOrder}function tj(t){return t.projectSortOrder}function sj(t){return t.toggleRecentSection}function nj(t){return t.showRecentSection}function rj(t){const e=it.c(8),{t:n}=gt(),r=t.onNewSession;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx(T,{name:"chat-new",className:"h-4 w-4 flex-shrink-0"}),e[0]=o):o=e[0];let i;e[1]!==n?(i=n("sessions.sidebar.header.actions.newSession"),e[1]=n,e[2]=i):i=e[2];let c;e[3]!==i?(c=s.jsx("span",{className:"truncate",children:i}),e[3]=i,e[4]=c):c=e[4];let a;return e[5]!==t.onNewSession||e[6]!==c?(a=s.jsx("div",{className:"select-none flex-shrink-0 px-2.5 pt-1.5",children:s.jsxs("button",{type:"button",onClick:r,className:"flex w-full min-w-0 items-center gap-2 rounded-md px-1.5 py-1 text-left typography-ui-label font-normal text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[o,c]})}),e[5]=t.onNewSession,e[6]=c,e[7]=a):a=e[7],a}const gd=7;function oj(t){const{sections:e,renderSessionNode:n,editingId:r,openSidebarMenuKey:o,variant:i="section",initialVisibleCount:c=gd,batchSize:a=gd}=t,{t:d}=gt(),u=Ds(S=>S.stickyZoneHeaders),[m,f]=l.useState(new Set),[g,x]=l.useState(new Map),j=i==="flat",w=l.useCallback(S=>{x(N=>{if(!N.has(S))return N;const A=new Map(N);return A.delete(S),A})},[]),p=l.useCallback(S=>{w(S),f(N=>{const A=new Set(N);return A.has(S)?A.delete(S):A.add(S),A})},[w]),h=l.useCallback((S,N,A)=>{x(k=>{const C=Math.min(A,N+a),P=new Map(k);return P.set(S,C),P})},[a]),b=l.useCallback(S=>{const N=new Set;Za(S,r,N);const A=To(S,o,"recent",!1),k=new WeakMap,C=D=>{k.set(D,Ri(D)),D.children.forEach(C)};S.forEach(C);const P=D=>({subtreeContainsEditing:N,menuOpenSessionId:A,nodeStructureKey:k.get(D)??"",childRenderExtrasFor:P});return D=>({subtreeContainsEditing:N,menuOpenSessionId:A,nodeStructureKey:k.get(D)??"",childRenderExtrasFor:P})},[r,o]),v=e.filter(S=>S.items.length>0);return v.length===0?null:s.jsx("div",{className:ge(j?"space-y-0.5 pb-2":"space-y-2 pb-2"),children:v.map(S=>{const N=m.has(S.key),A=Math.max(c,g.get(S.key)??c),k=S.items.slice(0,A),C=S.items.length-k.length,P=!j&&S.items.length>c&&C===0,D=b(k.map(F=>F.node)),O=F=>n(F.node,0,F.groupDirectory,F.projectId,!1,F.secondaryMeta,"recent",D(F.node));return j?s.jsxs("div",{className:"space-y-0.5",children:[k.map(O),C>0?s.jsx("button",{type:"button",onClick:()=>h(S.key,k.length,S.items.length),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:d("sessions.sidebar.group.showMore")}):null]},S.key):s.jsxs("div",{className:"relative space-y-1",children:[s.jsx("div",{className:ge("-ml-2.5 -mr-2",u&&"sticky top-0 z-20 bg-sidebar"),"data-sidebar-sticky-header":u?"true":void 0,children:s.jsxs("button",{type:"button",onClick:()=>p(S.key),className:"group flex w-full items-center gap-1.5 py-1 pl-4 pr-3.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-expanded":!N,children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 items-center justify-center",children:[s.jsx(T,{name:"history",className:ge("h-3.5 w-3.5 text-muted-foreground/80","group-hover:hidden")}),s.jsx("span",{className:"hidden h-3.5 w-3.5 items-center justify-center text-muted-foreground group-hover:inline-flex",children:N?s.jsx(T,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(T,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"text-[14px] font-semibold lowercase text-foreground",children:S.title})]})}),N?null:s.jsxs("div",{className:ge("space-y-0.5"),children:[k.map(O),C>0?s.jsx("button",{type:"button",onClick:()=>h(S.key,k.length,S.items.length),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:d("sessions.sidebar.group.showMore")}):null,P?s.jsx("button",{type:"button",onClick:()=>w(S.key),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:d("sessions.sidebar.group.showFewer")}):null]})]},S.key)})})}const ja="inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50";function ij(t){const e=it.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:o,onOpenUpdate:i,showRuntimeButtons:c,showUpdateButton:a}=t,d=c===void 0?!0:c,u=a===void 0?!0:a,{t:m}=gt();if(!d&&!u)return null;let f;e[0]!==o||e[1]!==n||e[2]!==r||e[3]!==d||e[4]!==m?(f=d?s.jsxs(s.Fragment,{children:[s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:ja,"aria-label":m("sessions.sidebar.footer.actions.settings"),children:s.jsx(T,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(ht,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:ja,"aria-label":m("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(T,{name:"command",className:"h-4.5 w-4.5"})})}),s.jsx(ht,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,className:ja,"aria-label":m("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(T,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(ht,{side:"top",sideOffset:4,children:s.jsx("p",{children:m("sessions.sidebar.footer.actions.aboutOpenChamber")})})]})]}):null,e[0]=o,e[1]=n,e[2]=r,e[3]=d,e[4]=m,e[5]=f):f=e[5];let g;e[6]!==i||e[7]!==u||e[8]!==m?(g=u?s.jsx(lt,{type:"button",variant:"default",size:"xs",className:"ml-auto border-[var(--status-info-border)] bg-[var(--status-info-background)] text-[var(--status-info)] hover:bg-[var(--status-info-background)]/80 hover:text-[var(--status-info)] dark:border-[var(--status-info-border)] dark:bg-[var(--status-info-background)] dark:hover:bg-[var(--status-info-background)]/80",onClick:i,children:m("sessions.sidebar.footer.actions.update")}):null,e[6]=i,e[7]=u,e[8]=m,e[9]=g):g=e[9];let x;return e[10]!==f||e[11]!==g?(x=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[f,g]}),e[10]=f,e[11]=g,e[12]=x):x=e[12],x}const Kf=t=>{const e=it.c(22),{id:n,projectLabel:r,projectIcon:o,projectColor:i,projectIconImage:c,projectIconBackground:a,isCollapsed:d,alwaysShowActions:u}=t,m=u===void 0?!1:u,{currentTheme:f}=_r(),g=o?pl[o]:null,x=i?gl[i]??null:null,j=d!==void 0,w=j?m?"hidden":"group-hover/project:hidden group-focus-within/project:hidden":void 0;let p;e[0]!==m||e[1]!==j||e[2]!==d?(p=j?s.jsx("span",{className:ge("h-3.5 w-3.5 items-center justify-center text-muted-foreground",m?"inline-flex":"hidden group-hover/project:inline-flex group-focus-within/project:inline-flex"),children:s.jsx(T,{name:d?"arrow-right-s":"arrow-down-s",className:"h-3.5 w-3.5"})}):null,e[0]=m,e[1]=j,e[2]=d,e[3]=p):p=e[3];let h;e[4]!==m||e[5]!==f||e[6]!==j||e[7]!==x||e[8]!==w||e[9]!==n||e[10]!==a||e[11]!==c||e[12]!==g?(h=c?s.jsx("span",{className:ge("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",j&&m?"hidden":"inline-flex",w),style:a?{backgroundColor:a}:void 0,children:s.jsx(xl,{project:{id:n,iconImage:c},options:{themeVariant:f.metadata.variant,iconColor:f.colors.surface.foreground},className:"h-full w-full object-contain",fallback:g?s.jsx(T,{name:g,className:"h-3.5 w-3.5",style:x?{color:x}:void 0}):s.jsx(T,{name:"folder",className:"h-3.5 w-3.5 text-muted-foreground/80",style:x?{color:x}:void 0})})}):g?s.jsx(T,{name:g,className:ge("h-3.5 w-3.5",w),style:x?{color:x}:void 0}):s.jsx(T,{name:"folder",className:ge("h-3.5 w-3.5 text-muted-foreground/80",w),style:x?{color:x}:void 0}),e[4]=m,e[5]=f,e[6]=j,e[7]=x,e[8]=w,e[9]=n,e[10]=a,e[11]=c,e[12]=g,e[13]=h):h=e[13];let b;e[14]!==p||e[15]!==h?(b=s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[p,h]}),e[14]=p,e[15]=h,e[16]=b):b=e[16];let v;e[17]!==r?(v=s.jsx("span",{className:"truncate text-[14px] font-semibold lowercase text-foreground",children:r}),e[17]=r,e[18]=v):v=e[18];let S;return e[19]!==b||e[20]!==v?(S=s.jsxs(s.Fragment,{children:[b,v]}),e[19]=b,e[20]=v,e[21]=S):S=e[21],S},aj=t=>{const e=it.c(59),{id:n,disabled:r,projectLabel:o,projectDescription:i,projectIcon:c,projectColor:a,projectIconImage:d,projectIconBackground:u,isCollapsed:m,isRepo:f,isDesktopShell:g,hideDirectoryControls:x,alwaysShowActions:j,onToggle:w,onNewSession:p,onNewWorktreeSession:h,onManageWorktrees:b,onRenameStart:v,onClose:S,sentinelRef:N,children:A,showCreateButtons:k,hideHeader:C,openSidebarMenuKey:P,setOpenSidebarMenuKey:D,statusIndicator:O}=t,F=r===void 0?!1:r,E=k===void 0?!0:k,B=C===void 0?!1:C,$=O===void 0?null:O,{t:z}=gt(),V=Ds(dj);let y;e[0]!==F||e[1]!==n?(y={id:n,disabled:F},e[0]=F,e[1]=n,e[2]=y):y=e[2];const{attributes:I,listeners:_,setNodeRef:W,transform:K,transition:Z,isDragging:Q}=wl(y),le=l.useRef(!1),te=`project:${n}`,he=P===te,[xe,H]=l.useState(!1);let we;e[3]!==te||e[4]!==D?(we=Y=>{Y&&H(!1),D(Y?te:null)},e[3]=te,e[4]=D,e[5]=we):we=e[5];const de=we;let q;e[6]!==x||e[7]!==f||e[8]!==S||e[9]!==b||e[10]!==p||e[11]!==v||e[12]!==E||e[13]!==z?(q=Y=>s.jsxs(s.Fragment,{children:[E&&!f&&!x&&p&&s.jsxs(Y,{onClick:p,children:[s.jsx(T,{name:"add",className:"mr-1.5 h-4 w-4"}),z("sessions.sidebar.project.actions.newSession")]}),f&&!x&&b&&s.jsxs(Y,{onClick:b,children:[s.jsx(T,{name:"node-tree",className:"mr-1.5 h-4 w-4"}),z("sessions.sidebar.project.actions.manageWorktrees")]}),s.jsxs(Y,{onClick:v,children:[s.jsx(T,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),z("sessions.sidebar.project.actions.edit")]}),s.jsxs(Y,{onClick:S,className:"text-destructive focus:text-destructive",children:[s.jsx(T,{name:"close",className:"mr-1.5 h-4 w-4"}),z("sessions.sidebar.project.actions.closeProject")]})]}),e[6]=x,e[7]=f,e[8]=S,e[9]=b,e[10]=p,e[11]=v,e[12]=E,e[13]=z,e[14]=q):q=e[14];const me=q,be=uj,Pe=fj,Ie=mj;let De;e[15]===Symbol.for("react.memo_cache_sentinel")?(De=Y=>{(Y.button===2||Y.button===0&&Y.ctrlKey)&&(le.current=!0)},e[15]=De):De=e[15];const Le=De;let Ne;e[16]!==w?(Ne=Y=>{if(Y.currentTarget.blur(),le.current){le.current=!1;return}w()},e[16]=w,e[17]=Ne):Ne=e[17];const ve=Ne;let Me;e[18]!==K?(Me=Sl.Transform.toString(K),e[18]=K,e[19]=Me):Me=e[19];let ee;e[20]!==Me||e[21]!==Z?(ee={transform:Me,transition:Z},e[20]=Me,e[21]=Z,e[22]=ee):ee=e[22];const oe=Q&&"opacity-30";let Te;e[23]!==oe?(Te=ge("relative",oe),e[23]=oe,e[24]=Te):Te=e[24];let J;e[25]!==j||e[26]!==I||e[27]!==de||e[28]!==ve||e[29]!==x||e[30]!==B||e[31]!==n||e[32]!==m||e[33]!==xe||e[34]!==g||e[35]!==he||e[36]!==f||e[37]!==_||e[38]!==p||e[39]!==h||e[40]!==a||e[41]!==i||e[42]!==c||e[43]!==u||e[44]!==d||e[45]!==o||e[46]!==me||e[47]!==N||e[48]!==E||e[49]!==$||e[50]!==V||e[51]!==z?(J=B?null:s.jsxs(s.Fragment,{children:[g&&s.jsx("div",{ref:N,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsxs(Gu,{open:xe,onOpenChange:H,children:[s.jsx(Ku,{render:s.jsx("div",{className:ge("-ml-2.5 -mr-2 text-left group/project select-none",V&&"sticky top-0 z-20 bg-sidebar"),"data-sidebar-sticky-header":V?"true":void 0,onContextMenu:Y=>{x||(Y.preventDefault(),H(!0))}}),children:s.jsxs("div",{className:"relative flex items-center gap-1 py-1 pl-4 pr-3.5",...I,children:[s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:Le,onClick:ve,..._,className:ge("flex-1 min-w-0 flex items-center gap-1.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 rounded-md cursor-grab active:cursor-grabbing transition-[padding]",f&&!x?j?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":j?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsx(Kf,{id:n,projectLabel:o,projectIcon:c,projectColor:a,projectIconImage:d,projectIconBackground:u,isCollapsed:m,alwaysShowActions:j}),$?s.jsx("span",{className:"ml-1 inline-flex flex-shrink-0 items-center",children:$}):null]})}),s.jsx(ht,{side:"right",sideOffset:8,children:i})]}),s.jsxs("div",{className:ge("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",E?"right-7":"right-0.5"),children:[E&&f&&!x&&h?s.jsxs(ft,{delayDuration:500,children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Y=>{Y.stopPropagation(),h()},className:ge("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground transition-opacity",j?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":z("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(T,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:z("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,x?null:s.jsxs(jn,{open:he,onOpenChange:de,children:[s.jsx(wn,{asChild:!0,children:s.jsx("button",{type:"button",className:ge("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition-opacity focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 hover:text-foreground",he?"opacity-100 pointer-events-auto":j?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":z("sessions.sidebar.project.actions.projectMenu"),onPointerDown:Pe,onMouseDown:Ie,onClick:be,children:s.jsx(T,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Sn,{align:"end",className:"min-w-[180px]",children:me(Xt)})]})]}),E&&p?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(ft,{delayDuration:500,children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Y=>{Y.stopPropagation(),p()},className:ge("inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",j?"opacity-100":"opacity-0 pointer-events-none group-hover/project:opacity-100 group-hover/project:pointer-events-auto group-focus-within/project:opacity-100 group-focus-within/project:pointer-events-auto"),"aria-label":z(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(T,{name:"add",className:"h-4 w-4"})})}),s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:z(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})}),s.jsx(Vu,{className:"min-w-[180px]",children:me(Hu)})]})]}),e[25]=j,e[26]=I,e[27]=de,e[28]=ve,e[29]=x,e[30]=B,e[31]=n,e[32]=m,e[33]=xe,e[34]=g,e[35]=he,e[36]=f,e[37]=_,e[38]=p,e[39]=h,e[40]=a,e[41]=i,e[42]=c,e[43]=u,e[44]=d,e[45]=o,e[46]=me,e[47]=N,e[48]=E,e[49]=$,e[50]=V,e[51]=z,e[52]=J):J=e[52];let re;return e[53]!==A||e[54]!==W||e[55]!==ee||e[56]!==Te||e[57]!==J?(re=s.jsxs("div",{ref:W,style:ee,className:Te,children:[J,A]}),e[53]=A,e[54]=W,e[55]=ee,e[56]=Te,e[57]=J,e[58]=re):re=e[58],re},lj=t=>{const e=it.c(21),{id:n,disabled:r,children:o}=t,i=r===void 0?!1:r;let c;e[0]!==i||e[1]!==n?(c={id:n,disabled:i},e[0]=i,e[1]=n,e[2]=c):c=e[2];const{listeners:a,setNodeRef:d,setActivatorNodeRef:u,transform:m,transition:f,isDragging:g}=wl(c);let x;e[3]!==a||e[4]!==u?(x={listeners:a,setActivatorNodeRef:u},e[3]=a,e[4]=u,e[5]=x):x=e[5];const j=x;let w;e[6]!==m?(w=Sl.Transform.toString(m),e[6]=m,e[7]=w):w=e[7];let p;e[8]!==w||e[9]!==f?(p={transform:w,transition:f},e[8]=w,e[9]=f,e[10]=p):p=e[10];const h=g&&"opacity-50";let b;e[11]!==h?(b=ge("space-y-0.5 rounded-md",h),e[11]=h,e[12]=b):b=e[12];let v;e[13]!==o||e[14]!==j?(v=typeof o=="function"?o(j):o,e[13]=o,e[14]=j,e[15]=v):v=e[15];let S;return e[16]!==d||e[17]!==p||e[18]!==b||e[19]!==v?(S=s.jsx("div",{ref:d,style:p,className:b,children:v}),e[16]=d,e[17]=p,e[18]=b,e[19]=v,e[20]=S):S=e[20],S},cj=l.memo(lj);function dj(t){return t.stickyZoneHeaders}function uj(t){t.stopPropagation()}function fj(t){t.stopPropagation()}function mj(t){t.stopPropagation()}const hj=48,pj=32,gj=24,xd=(t,e)=>bl(t.label?.trim()||gr(t.normalizedPath,e)||t.normalizedPath);function xj(t){In("ui.sidebar_projects_list.render");const{t:e}=gt(),n=t.isDesktopShellRuntime&&t.stickyZoneHeaders,r=ki(Yr(_a,{activationConstraint:{distance:8}}),Yr(mx,{coordinateGetter:hx})),o=ki(Yr(_a,{activationConstraint:{distance:8}})),i=l.useRef(new Map),c=l.useRef(t.getOrderedGroups);c.current!==t.getOrderedGroups&&(c.current=t.getOrderedGroups,i.current.clear());const a=(p,h)=>{const b=i.current,v=b.get(p);if(v&&v.groups===h)return v.ordered;const S=t.getOrderedGroups(p,h);if(b.set(p,{groups:h,ordered:S}),b.size>256){const N=b.keys().next().value;N!==void 0&&b.delete(N)}return S},d=l.useRef(null),u=l.useRef(0),m=l.useCallback(p=>{const b=p.scrollTop>1?Math.min(pj+p.scrollTop,hj):0;u.current=b,p.style.setProperty("--scroll-shadow-top-size",`${b}px`),p.style.setProperty("--scroll-shadow-top-clear-size",`${Math.min(Math.max(b-8,0),gj)}px`)},[]),f=l.useCallback(p=>{p.target.closest("[data-overlay-scrollbar-thumb], [data-sidebar-sticky-header]")||p.clientY-p.currentTarget.getBoundingClientRect().top>=u.current||(p.preventDefault(),p.stopPropagation())},[]),g=t.projectSections.length>0&&t.sectionsForRender.length>0;l.useLayoutEffect(()=>{n&&g&&d.current&&m(d.current)},[n,g,m]);let x=null;for(const p of t.projectSections)t.stuckProjectHeaders.has(p.project.id)&&(x=p.project);const j=x??(t.hasSharedSessions?null:t.sectionsForRender[0]?.project??null),w=j?xd(j,t.homeDirectory):null;return t.sharedSessionsOnly?s.jsxs($n,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:ge("space-y-1 pb-1 pr-2",(t.mobileVariant,"")),children:[t.topContent,t.hasSharedSessions?null:t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState]}):t.projectSections.length===0?s.jsxs($n,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:ge("space-y-1 pb-1 pl-2.5 pr-2",(t.mobileVariant,"")),children:[t.topContent,t.emptyState]}):t.sectionsForRender.length===0?s.jsx($n,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:ge("space-y-1 pb-1 pl-2.5 pr-2",(t.mobileVariant,"")),children:t.searchEmptyState}):s.jsxs("div",{className:"oc-sticky-fade-root relative flex min-h-0 flex-1",onPointerDownCapture:n?f:void 0,onClickCapture:n?f:void 0,onContextMenuCapture:n?f:void 0,children:[s.jsxs($n,{ref:d,useScrollShadow:!0,hideTopScrollShadow:!n,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:ge("oc-sidebar-scroller oc-sticky-fade-scroller space-y-1.5 pb-1 pl-2.5 pr-2 [overflow-anchor:none]",(t.mobileVariant,"")),style:n?{"--scroll-shadow-top-size":"0px"}:void 0,onScroll:n?p=>m(p.currentTarget):void 0,children:[t.topContent,t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const p=t.sectionsForRender.find(S=>S.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!p)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const h=p.groups.find(S=>S.isMain&&S.sessions.length>0)??p.groups.find(S=>S.sessions.length>0)??p.groups.find(S=>S.isMain)??p.groups[0];if(!h)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:e("sessions.sidebar.empty.noSessions.title")});const b=p.groups.find(S=>S.isArchivedBucket);return[h,...b&&b.id!==h.id?[b]:[]].map(S=>{const N=`${p.project.id}:${S.id}`,A=S.id===h.id;return s.jsx(l.Fragment,{children:t.renderGroupSessions(S,N,p.project.id,A,null,!0,d)},N)})})()}):s.jsxs(Ci,{sensors:r,collisionDetection:Ni,onDragEnd:p=>{if(t.isInlineEditing||t.projectSortOrder!=="manual")return;const{active:h,over:b}=p;if(!b||h.id===b.id)return;const v=t.sectionsForRender.findIndex(N=>N.project.id===h.id),S=t.sectionsForRender.findIndex(N=>N.project.id===b.id);v===-1||S===-1||v===S||t.reorderProjects(v,S)},children:[s.jsx(za,{items:t.sectionsForRender.map(p=>p.project.id),strategy:Ua,children:t.sectionsForRender.map(p=>{const h=p.project,b=h.id,v=xd(h,t.homeDirectory),S=yi(h.normalizedPath,t.homeDirectory),N=t.collapsedProjects.has(b),A=t.projectRepoStatus.get(b);return s.jsx(aj,{id:b,disabled:t.projectSortOrder!=="manual",projectLabel:v,projectDescription:S,projectIcon:h.icon,projectColor:h.color,projectIconImage:h.iconImage,projectIconBackground:h.iconBackground,isCollapsed:N,isRepo:!!A,isDesktopShell:t.isDesktopShellRuntime,hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,statusIndicator:N?t.renderProjectStatusIndicator?.(b,p.groups):null,onToggle:()=>t.toggleProject(b),onNewSession:()=>{b!==t.activeProjectId&&t.setActiveProjectIdOnly(b),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({selectedProjectId:b,directoryOverride:h.normalizedPath})},onNewWorktreeSession:()=>{b!==t.activeProjectId&&t.setActiveProjectIdOnly(b),t.setActiveMainTab("chat"),t.openNewWorktreeDialog()},onManageWorktrees:()=>t.openWorktreesPage(b),onRenameStart:()=>t.openProjectEditDialog(b),onClose:()=>t.removeProject(b),sentinelRef:k=>{t.projectHeaderSentinelRefs.current.set(b,k)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:N?null:s.jsx("div",{className:"space-y-0 pt-0.5 pb-0.5",children:(()=>{const k=a(b,p.groups),C=k.find(D=>D.isMain)??null,P=C?k.filter(D=>D.id!==C.id):k;return s.jsxs(Ci,{sensors:o,collisionDetection:Ni,onDragEnd:D=>{if(t.isInlineEditing)return;const{active:O,over:F}=D;if(!F||O.id===F.id)return;const E=P.findIndex(V=>V.id===O.id),B=P.findIndex(V=>V.id===F.id);if(E===-1||B===-1||E===B)return;const $=sf(P,E,B).map(V=>V.id),z=C?[C.id,...$]:$;t.setGroupOrderByProject(V=>{const y=new Map(V);return y.set(b,z),y})},children:[C?t.renderGroupSessions(C,`${b}:${C.id}`,b,!0,null,void 0,d):null,s.jsx(za,{items:P.map(D=>D.id),strategy:Ua,children:P.map(D=>{const O=`${b}:${D.id}`;return s.jsx(cj,{id:D.id,disabled:t.isInlineEditing,children:F=>t.renderGroupSessions(D,O,b,!1,F,void 0,d)},D.id)})}),s.jsx($a,{dropAnimation:null})]})})()})},b)})}),s.jsx($a,{dropAnimation:null})]})]}),n&&(j||t.hasSharedSessions)?s.jsx("div",{className:"oc-sticky-fade-overlay pointer-events-none absolute inset-x-0 top-0 z-30 flex items-center gap-1.5 py-1 pl-4 pr-5","aria-hidden":"true",children:j&&w?s.jsx(Kf,{id:j.id,projectLabel:w,projectIcon:j.icon,projectColor:j.color,projectIconImage:j.iconImage,projectIconBackground:j.iconBackground}):s.jsxs(s.Fragment,{children:[s.jsx(T,{name:"history",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"truncate text-[14px] font-semibold lowercase text-foreground",children:e("sessions.sidebar.activity.recentTitle")})]})}):null]})}const bj=l.memo(xj),yj=(t,e)=>{if(!e)return Array.from(t);const n=[],r=new Set;for(const o of t){r.has(o)||(r.add(o),n.push(o));const i=e.get(o);if(i)for(const c of i)r.has(c)||(r.add(c),n.push(c))}return n},As=br()((t,e)=>({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null,enable:()=>{e().enabled||t({enabled:!0})},disable:()=>{t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null})},toggleMode:()=>{e().enabled?t({enabled:!1,selectedIds:new Set,scopeKey:null,anchorId:null}):t({enabled:!0})},toggleSelected:(n,r,o)=>{const i=e(),c=new Set(i.selectedIds);let a=i.scopeKey,d=i.anchorId;r!==null&&i.scopeKey!==null&&r!==i.scopeKey?(c.clear(),a=r,d=null):a===null&&r!==null&&(a=r);const m=o&&o.length>0?[n,...o]:[n];if(c.has(n)){for(const g of m)c.delete(g);d===n&&(d=null)}else{for(const g of m)c.add(g);d=n}c.size===0?t({selectedIds:c,scopeKey:null,anchorId:null}):t({selectedIds:c,scopeKey:a,anchorId:d})},setRange:(n,r,o,i,c)=>{const a=e();if(o.length===0)return;const d=n&&o.includes(n)?n:o[0],u=o.indexOf(d),m=o.indexOf(r);if(u<0||m<0)return;const[f,g]=u<=m?[u,m]:[m,u],x=o.slice(f,g+1),j=yj(x,c),p=i!==null&&a.scopeKey!==null&&i!==a.scopeKey?new Set:new Set(a.selectedIds);for(const h of j)p.add(h);t({selectedIds:p,scopeKey:i??a.scopeKey,anchorId:d})},replaceAll:(n,r)=>{if(n.length===0){t({selectedIds:new Set,scopeKey:null,anchorId:null});return}t({selectedIds:new Set(n),scopeKey:r,anchorId:n[0]??null})},clear:()=>{t({selectedIds:new Set,scopeKey:null,anchorId:null})},removeMany:n=>{const r=e();if(r.selectedIds.size===0||n.length===0)return;const o=new Set(r.selectedIds);for(const i of n)o.delete(i);o.size!==r.selectedIds.size&&(o.size===0?t({selectedIds:o,scopeKey:null,anchorId:null}):t({selectedIds:o}))}}));let el=!1;const tl=new Set;let bd=!1;function vj(){for(const t of tl)t()}function Rl(t){el!==t&&(el=t,vj())}function wj(t){t.key==="Shift"&&Rl(!0)}function Sj(t){t.key==="Shift"&&Rl(!1)}function jj(){Rl(!1)}function kj(){bd||typeof window>"u"||(bd=!0,window.addEventListener("keydown",wj),window.addEventListener("keyup",Sj),window.addEventListener("blur",jj))}function Cj(t){return kj(),tl.add(t),()=>{tl.delete(t)}}function Nj(){return el}function Aj(){return!1}function Dj(){return nt.useSyncExternalStore(Cj,Nj,Aj)}const Pj=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,Gf=/^g[1-9]\d*$/,xo=(t,e,n,r,o)=>{if(!Pj.test(t)||e!==void 0&&!Gf.test(e)||!n?.trim()||!r?.trim()||n!==n.trim()||r!==r.trim())return null;if(o===void 0)return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!1};if(o==="fusion")return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!0};if(!/^\d+$/.test(o))return null;const i=Number.parseInt(o,10);return!Number.isSafeInteger(i)||i<=0?null:{groupSlug:t,runGroup:e,providerID:n,modelID:r,index:i,fusion:!1}},hi=t=>{if(!t)return null;const e=t.split("/");if(e.length<3||e.length>5)return null;const[n]=e;if(e.length===3)return xo(n,void 0,e[1],e[2],void 0);if(e.length===4){const[,a,d,u]=e;return Gf.test(a)?xo(n,a,d,u,void 0):xo(n,void 0,a,d,u)}const[,r,o,i,c]=e;return r===""?xo(n,void 0,o,i,c):xo(n,r,o,i,c)},Ej=t=>{const e=[t.groupSlug];return t.runGroup&&e.push(t.runGroup),e.push(t.providerID,t.modelID),t.index!==void 0&&e.push(String(t.index)),e.join("/")},Tj=(t,e,n,r)=>{const o=[t];return r&&o.push(r),o.push(e,n,"fusion"),o.join("/")},qf=t=>{const e=it.c(36),{value:n,onChange:r,className:o,disabled:i,id:c,portalToBody:a}=t,{t:d}=gt(),u=Kt(Ij),m=Kt(Rj),f=Kt(Mj);let g;e[0]!==u?(g=u(),e[0]=u,e[1]=g):g=e[1];const x=g;let j;e[2]!==x?(j=x.filter(Oj),e[2]=x,e[3]=j):j=e[3];const w=j;let p,h;e[4]!==x.length||e[5]!==m?(p=()=>{x.length===0&&m()},h=[x.length,m],e[4]=x.length,e[5]=m,e[6]=p,e[7]=h):(p=e[6],h=e[7]),l.useEffect(p,h);let b,v;e[8]!==f||e[9]!==i||e[10]!==r||e[11]!==w||e[12]!==n?(b=()=>{if(i)return;const F=n.trim();if(F.length>0&&w.some($=>$.name===F))return;const E=typeof f=="string"&&f.trim().length>0?f.trim():null;if(E&&w.some($=>$.name===E)){r(E);return}const B=w[0]?.name;B&&r(B)},v=[f,i,r,w,n],e[8]=f,e[9]=i,e[10]=r,e[11]=w,e[12]=n,e[13]=b,e[14]=v):(b=e[13],v=e[14]),l.useEffect(b,v);const S=n.trim().length>0?n:void 0;let N;e[15]!==o?(N=ge("max-w-full",o),e[15]=o,e[16]=N):N=e[16];let A;e[17]!==d?(A=d("multirun.agentSelector.placeholder"),e[17]=d,e[18]=A):A=e[18];let k;e[19]!==A?(k=s.jsx(Es,{placeholder:A}),e[19]=A,e[20]=k):k=e[20];let C;e[21]!==c||e[22]!==N||e[23]!==k?(C=s.jsx(Gs,{id:c,size:"lg",className:N,children:k}),e[21]=c,e[22]=N,e[23]=k,e[24]=C):C=e[24];let P;e[25]!==w?(P=w.length>0&&s.jsx(Fa,{children:w.map(Fj)}),e[25]=w,e[26]=P):P=e[26];let D;e[27]!==a||e[28]!==P?(D=s.jsx(qs,{fitContent:!0,portalToBody:a,children:P}),e[27]=a,e[28]=P,e[29]=D):D=e[29];let O;return e[30]!==i||e[31]!==r||e[32]!==S||e[33]!==C||e[34]!==D?(O=s.jsxs(Ks,{value:S,onValueChange:r,disabled:i,children:[C,D]}),e[30]=i,e[31]=r,e[32]=S,e[33]=C,e[34]=D,e[35]=O):O=e[35],O};function Ij(t){return t.getVisibleAgents}function Rj(t){return t.loadAgents}function Mj(t){return t.currentAgentName}function Oj(t){return Iu(t.mode)}function Fj(t){return s.jsx(is,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const Lj="h-7",ko=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,Bj=t=>{const e=it.c(12),{model:n,instanceIndex:r,totalSameModel:o,onRemove:i}=t,c=n.displayName||`${n.providerID}/${n.modelID}`,a=o>1?`${c} (${r})`:c;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=ge("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",Lj),e[0]=d):d=e[0];let u;e[1]!==n.providerID?(u=s.jsx(bi,{providerId:n.providerID,className:"h-3.5 w-3.5"}),e[1]=n.providerID,e[2]=u):u=e[2];let m;e[3]!==a?(m=s.jsx("span",{className:"typography-meta font-medium truncate max-w-[140px]",children:a}),e[3]=a,e[4]=m):m=e[4];let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(T,{name:"close",className:"h-3.5 w-3.5"}),e[5]=f):f=e[5];let g;e[6]!==i?(g=s.jsx("button",{type:"button",onClick:i,className:"text-muted-foreground hover:text-foreground ml-0.5",children:f}),e[6]=i,e[7]=g):g=e[7];let x;return e[8]!==u||e[9]!==m||e[10]!==g?(x=s.jsxs("div",{className:d,children:[u,m,g]}),e[8]=u,e[9]=m,e[10]=g,e[11]=x):x=e[11],x},Yf=t=>{const e=it.c(120),{selectedModels:n,onAdd:r,onRemove:o,onUpdate:i,minModels:c,addButtonLabel:a,showChips:d,maxModels:u,addButtonClassName:m,dropdownSide:f,dropdownClassName:g,containerClassName:x,triggerIcon:j}=t,w=d===void 0?!0:d,p=f===void 0?"top":f,{t:h}=gt(),b=Kt(_j),v=Kt($j),S=pe(zj),N=pe(Uj),{favoriteModelsList:A,recentModelsList:k}=np(),C=pe(Wj),P=pe(Vj),[D,O]=l.useState(!1),[F,E]=l.useState(""),[B,$]=l.useState(null),z=l.useRef(null),V=l.useRef(null),y=u===1,I=u===void 0||n.length<u||y;let _;if(e[0]!==n){_=new Map;for(const Ce of n){const Ee=`${Ce.providerID}:${Ce.modelID}`;_.set(Ee,(_.get(Ee)||0)+1)}e[0]=n,e[1]=_}else _=e[1];const W=_;let K;e[2]!==n?(K=Ce=>n.filter(se=>se.providerID===Ce.providerID&&se.modelID===Ce.modelID).findIndex(se=>se.instanceId===Ce.instanceId)+1,e[2]=n,e[3]=K):K=e[3];const Z=K;let Q,le;e[4]!==p||e[5]!==D?(Q=()=>{if(!D||!V.current)return;const Ce=V.current.getBoundingClientRect();if(p==="bottom"){const ye=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-Ce.bottom-16-112;$(Math.max(160,Math.min(320,ye)));return}let Ee=V.current.parentElement;for(;Ee&&!(Ee.getAttribute("role")==="dialog"||Ee.hasAttribute("data-scroll-shadow"));){const Ze=getComputedStyle(Ee);if(Ze.overflow==="auto"||Ze.overflow==="hidden"||Ze.overflowY==="auto"||Ze.overflowY==="hidden")break;Ee=Ee.parentElement}const se=Ee?Ee.getBoundingClientRect().top:0,je=Ce.top-se-16;$(Math.max(150,Math.min(300,je)))},le=[p,D],e[4]=p,e[5]=D,e[6]=Q,e[7]=le):(Q=e[6],le=e[7]),l.useEffect(Q,le);let te,he;e[8]!==I||e[9]!==D?(te=()=>{!I&&D&&(O(!1),E(""))},he=[I,D],e[8]=I,e[9]=D,e[10]=te,e[11]=he):(te=e[10],he=e[11]),l.useEffect(te,he);let xe,H;e[12]!==D?(xe=()=>{if(!D)return;const Ce=Ee=>{z.current&&!z.current.contains(Ee.target)&&(O(!1),E(""))};return document.addEventListener("mousedown",Ce),()=>document.removeEventListener("mousedown",Ce)},H=[D],e[12]=D,e[13]=xe,e[14]=H):(xe=e[13],H=e[14]),l.useEffect(xe,H);let we;e[15]!==y||e[16]!==r||e[17]!==i||e[18]!==n.length?(we=Ce=>{const Ee={providerID:Ce.providerID,modelID:Ce.modelID,displayName:Ce.model.name||Ce.modelID,instanceId:ko()};y&&n.length>0&&i?i(0,Ee):r(Ee),y&&(O(!1),E(""))},e[15]=y,e[16]=r,e[17]=i,e[18]=n.length,e[19]=we):we=e[19];const de=we;let q;e[20]!==h?(q=h("multirun.modelMultiSelect.search.placeholder"),e[20]=h,e[21]=q):q=e[21];let me;e[22]!==h?(me=h("multirun.modelMultiSelect.search.noResults"),e[22]=h,e[23]=me):me=e[23];let be;e[24]!==h?(be=h("multirun.modelMultiSelect.sections.favorites"),e[24]=h,e[25]=be):be=e[25];let Pe;e[26]!==h?(Pe=h("multirun.modelMultiSelect.sections.recent"),e[26]=h,e[27]=Pe):Pe=e[27];let Ie;e[28]!==h?(Ie=h("multirun.modelMultiSelect.keyboard.hint"),e[28]=h,e[29]=Ie):Ie=e[29];let De;e[30]!==h?(De=h("settings.agents.modelSelector.actions.favorite"),e[30]=h,e[31]=De):De=e[31];let Le;e[32]!==h?(Le=h("settings.agents.modelSelector.actions.unfavorite"),e[32]=h,e[33]=Le):Le=e[33];let Ne;e[34]!==h?(Ne=h("chat.modelControls.capabilities"),e[34]=h,e[35]=Ne):Ne=e[35];let ve;e[36]!==h?(ve=h("chat.modelControls.capability.toolCalling"),e[36]=h,e[37]=ve):ve=e[37];let Me;e[38]!==h?(Me=h("chat.modelControls.capability.reasoning"),e[38]=h,e[39]=Me):Me=e[39];let ee;e[40]!==h?(ee=h("chat.modelControls.input"),e[40]=h,e[41]=ee):ee=e[41];let oe;e[42]!==h?(oe=h("chat.modelControls.output"),e[42]=h,e[43]=oe):oe=e[43];let Te;e[44]!==h?(Te=h("chat.modelControls.costPerMillion"),e[44]=h,e[45]=Te):Te=e[45];let J;e[46]!==q||e[47]!==me||e[48]!==be||e[49]!==Pe||e[50]!==Ie||e[51]!==De||e[52]!==Le||e[53]!==Ne||e[54]!==ve||e[55]!==Me||e[56]!==ee||e[57]!==oe||e[58]!==Te?(J={searchPlaceholder:q,noResults:me,favorites:be,recent:Pe,keyboardHint:Ie,favorite:De,unfavorite:Le,capabilities:Ne,capabilityToolCalling:ve,capabilityReasoning:Me,input:ee,output:oe,costPerMillion:Te},e[46]=q,e[47]=me,e[48]=be,e[49]=Pe,e[50]=Ie,e[51]=De,e[52]=Le,e[53]=Ne,e[54]=ve,e[55]=Me,e[56]=ee,e[57]=oe,e[58]=Te,e[59]=J):J=e[59];const re=J;let Y;e[60]!==x?(Y=ge("relative",x),e[60]=x,e[61]=Y):Y=e[61];const U=D?"":void 0;let fe;e[62]!==m?(fe=ge(Ru({size:"default"}),"w-fit",m),e[62]=m,e[63]=fe):fe=e[63];const ne=!I;let ce;e[64]!==D?(ce=()=>{O(!D)},e[64]=D,e[65]=ce):ce=e[65];let Fe;e[66]!==j?(Fe=j??s.jsx(T,{name:"add",className:"h-3.5 w-3.5 mr-1"}),e[66]=j,e[67]=Fe):Fe=e[67];let Ye;e[68]!==a||e[69]!==h?(Ye=a??h("multirun.modelMultiSelect.actions.addModel"),e[68]=a,e[69]=h,e[70]=Ye):Ye=e[70];let $e;e[71]!==U||e[72]!==fe||e[73]!==ne||e[74]!==ce||e[75]!==Fe||e[76]!==Ye?($e=s.jsxs("button",{ref:V,type:"button","data-popup-open":U,className:fe,disabled:ne,onClick:ce,children:[Fe,Ye]}),e[71]=U,e[72]=fe,e[73]=ne,e[74]=ce,e[75]=Fe,e[76]=Ye,e[77]=$e):$e=e[77];let ie;e[78]!==B||e[79]!==I||e[80]!==g||e[81]!==p||e[82]!==A||e[83]!==de||e[84]!==C||e[85]!==N||e[86]!==D||e[87]!==re||e[88]!==W||e[89]!==v||e[90]!==P||e[91]!==b||e[92]!==k||e[93]!==F||e[94]!==S?(ie=D?s.jsx("div",{className:ge("absolute left-0 z-50 w-[min(420px,calc(100vw-2rem))] max-w-[calc(100vw-2rem)] flex flex-col overflow-hidden rounded-xl border border-border/50 shadow-lg",p==="top"?"bottom-full mb-1":"top-full mt-1",g),style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:s.jsx(rp,{providers:b,providerOrder:P,favoriteModels:A,recentModels:k,modelsMetadata:v,hiddenModels:C,searchQuery:F,onSearchQueryChange:E,onSelect:de,labels:re,selectionCount:Ce=>W.get(`${Ce.providerID}:${Ce.modelID}`)||0,disabled:!I,maxHeightClassName:"flex-1",maxHeightStyle:{maxHeight:B?`${B}px`:"300px"},stickyHeaders:!0,tooltipsEnabled:D,isFavorite:Ce=>N(Ce.providerID,Ce.modelID),onToggleFavorite:Ce=>S(Ce.providerID,Ce.modelID),onEscape:()=>{O(!1),E("")}})}):null,e[78]=B,e[79]=I,e[80]=g,e[81]=p,e[82]=A,e[83]=de,e[84]=C,e[85]=N,e[86]=D,e[87]=re,e[88]=W,e[89]=v,e[90]=P,e[91]=b,e[92]=k,e[93]=F,e[94]=S,e[95]=ie):ie=e[95];let Re;e[96]!==Y||e[97]!==$e||e[98]!==ie?(Re=s.jsxs("div",{className:Y,ref:z,children:[$e,ie]}),e[96]=Y,e[97]=$e,e[98]=ie,e[99]=Re):Re=e[99];let ue;e[100]!==Z||e[101]!==W||e[102]!==o||e[103]!==i||e[104]!==b||e[105]!==n||e[106]!==w||e[107]!==h?(ue=w&&n.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:n.map((Ce,Ee)=>{const se=`${Ce.providerID}:${Ce.modelID}`,je=W.get(se)||1,Ze=Z(Ce),ye=b.find(_e=>_e.id===Ce.providerID)?.models?.find(_e=>_e.id===Ce.modelID),Xe=ye?.variants?Object.keys(ye.variants):[],Be=Xe.length>0,We=Ce.variant??"__default__";return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Bj,{model:Ce,instanceIndex:Ze,totalSameModel:je,onRemove:()=>o(Ee)}),Be&&s.jsxs(Ks,{value:We,onValueChange:_e=>{if(!i)return;i(Ee,{...Ce,variant:_e==="__default__"?void 0:_e})},children:[s.jsxs(Gs,{size:"sm",className:"gap-1.5",children:[s.jsx(T,{name:"brain-ai-3",className:ge("h-3.5 w-3.5 flex-shrink-0",We==="__default__"?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(Es,{placeholder:h("multirun.modelMultiSelect.variant.placeholder"),children:_e=>_e==="__default__"?h("multirun.modelMultiSelect.variant.default"):_e})]}),s.jsxs(qs,{fitContent:!0,children:[s.jsx(is,{value:"__default__",className:"pr-2 [&>span:first-child]:hidden",children:h("multirun.modelMultiSelect.variant.default")}),Xe.map(Hj)]})]})]},Ce.instanceId)})}),e[100]=Z,e[101]=W,e[102]=o,e[103]=i,e[104]=b,e[105]=n,e[106]=w,e[107]=h,e[108]=ue):ue=e[108];let R;e[109]!==Re||e[110]!==ue?(R=s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[Re,ue]}),e[109]=Re,e[110]=ue,e[111]=R):R=e[111];let ae;e[112]!==u||e[113]!==c||e[114]!==n.length||e[115]!==h?(ae=c!==void 0&&n.length<c&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:u!==void 0?h("multirun.modelMultiSelect.validation.minToMax",{min:c,max:u}):h("multirun.modelMultiSelect.validation.minOnly",{min:c})}),e[112]=u,e[113]=c,e[114]=n.length,e[115]=h,e[116]=ae):ae=e[116];let Se;return e[117]!==R||e[118]!==ae?(Se=s.jsxs("div",{className:"space-y-2",children:[R,ae]}),e[117]=R,e[118]=ae,e[119]=Se):Se=e[119],Se};function _j(t){return t.providers}function $j(t){return t.modelsMetadata}function zj(t){return t.toggleFavoriteModel}function Uj(t){return t.isFavoriteModel}function Wj(t){return t.hiddenModels}function Vj(t){return t.providerOrder}function Hj(t){return s.jsx(is,{value:t,className:"pr-2 [&>span:first-child]:hidden",children:t},t)}const Kj=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
907
+
908
+ --- RESULT ${n+1}: ${r} ---
909
+ ${e.trim()}
910
+ --- END RESULT ${n+1} ---`},yd=(t,e)=>ot.getState().getWorktreeMetadata(t)?.projectDirectory??e,Gj=async t=>{const e=t.directory??void 0,n=ip(t.session.id,e);if(n.length===0&&t.directory){const o=(await sn.withDirectory(t.directory,()=>sn.getSdkClient().session.messages({sessionID:t.session.id,directory:t.directory??void 0,limit:50}))).data??[];for(let i=o.length-1;i>=0;i-=1){const c=o[i];if(c.info?.role==="assistant")return ac(c.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const o=n[r];if(o.role==="assistant")return ac(ap(o.id,e)).trim()}return""};function qj({session:t,open:e,onOpenChange:n}){const{t:r}=gt(),o=op(),i=Fs(y=>y.activeSessions),c=Fs(y=>y.archivedSessions),a=Kt(y=>y.providers),d=Kt(y=>y.currentProviderId),u=Kt(y=>y.currentModelId),m=Kt(y=>y.currentAgentName),[f,g]=l.useState(d??""),[x,j]=l.useState(u??""),[w,p]=l.useState(()=>d&&u?[{providerID:d,modelID:u,instanceId:ko()}]:[]),[h,b]=l.useState(""),[v,S]=l.useState(m??""),[N,A]=l.useState([]),[k,C]=l.useState(!1),P=l.useMemo(()=>hi(t.title),[t.title]),D=l.useMemo(()=>{const y=new Map;for(const I of o)y.set(I.id,I);for(const I of i)y.set(I.id,I);for(const I of c)y.set(I.id,I);return t.id&&y.set(t.id,t),Array.from(y.values())},[i,c,o,t]);l.useEffect(()=>{if(!e||!P)return;const y=ot.getState().getDirectoryForSession(t.id),I=yd(t.id,y),_=D.map(W=>{const K=hi(W.title);if(!K||K.groupSlug!==P.groupSlug||K.fusion||(K.runGroup??null)!==(P.runGroup??null))return null;const Z=ot.getState().getDirectoryForSession(W.id)??Qs(W),Q=yd(W.id,Z);return I&&Q&&I!==Q?null:{session:W,directory:Z,projectDirectory:Q}}).filter(W=>W!==null).sort((W,K)=>(W.session.time?.created??0)-(K.session.time?.created??0));A(_)},[D,e,P,t.id]);const F=a.find(y=>y.id===f)?.models.find(y=>y.id===x),E=F?.variants?Object.keys(F.variants):[],B=!!(P&&f&&x&&N.length>0&&!k),$=l.useCallback(y=>{p([y]),g(y.providerID),j(y.modelID),b("")},[]),z=w[0]?.displayName||w[0]?.modelID||r("multirun.fusion.model.placeholder"),V=async()=>{if(!(!P||!f||!x)){C(!0);try{const y=await Promise.all(N.map(le=>Gj(le))),I=N.map((le,te)=>({source:le,text:y[te]??""})).filter(le=>le.text.trim().length>0);if(I.length===0){Ae.error(r("multirun.fusion.toast.noOutputs"));return}const _=N[0]?.projectDirectory??N[0]?.directory??null,W=Tj(P.groupSlug,f,x,P.runGroup),[K,Z]=await Promise.all([ic("session.fusion.visible"),ic("session.fusion.instructions")]),Q=await ot.getState().createSession(W,_,null);if(!Q)throw new Error("Failed to create fusion session");ot.getState().setCurrentSession(Q.id,_),n(!1),await sn.sendMessage({id:Q.id,providerID:f,modelID:x,variant:h||void 0,agent:v||void 0,text:K,additionalParts:[{text:Z,synthetic:!0},...I.map((le,te)=>({text:Kj(le.source,le.text,te),synthetic:!0})),{text:`
911
+
912
+ --- FUSION INPUTS END ---
913
+ Now write the final fused answer.`,synthetic:!0}],directory:_??sn.getDirectory()})}catch(y){console.error("[MultiRunFusion] Failed to start fusion",y),Ae.error(r("multirun.fusion.toast.failed"))}finally{C(!1)}}};return s.jsx(Ls,{open:e,onOpenChange:n,children:s.jsxs(Bs,{className:"max-w-xl overflow-visible",children:[s.jsxs(kn,{children:[s.jsx(nn,{children:r("multirun.fusion.title")}),s.jsx(rn,{children:r("multirun.fusion.description")})]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("div",{className:"max-w-full",children:s.jsx(Yf,{selectedModels:w,onAdd:$,onUpdate:(y,I)=>$(I),onRemove:()=>{p([]),g(""),j(""),b("")},maxModels:1,addButtonLabel:z,showChips:!1,addButtonClassName:"w-fit max-w-[min(28rem,calc(100vw-8rem))] justify-start",dropdownSide:"bottom",dropdownClassName:"w-[min(28rem,calc(100vw-8rem))]",triggerIcon:f?s.jsx(bi,{providerId:f,className:"h-3.5 w-3.5 mr-1"}):void 0})}),E.length>0?s.jsxs(Ks,{value:h||"__default__",onValueChange:y=>b(y==="__default__"?"":y),children:[s.jsxs(Gs,{size:"lg",className:"w-fit",children:[s.jsx(T,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Es,{children:y=>y==="__default__"?r("multirun.modelMultiSelect.variant.default"):y})]}),s.jsxs(qs,{fitContent:!0,portalToBody:!0,children:[s.jsx(is,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),E.map(y=>s.jsx(is,{value:y,children:y},y))]})]}):null,s.jsx(qf,{value:v,onChange:S,portalToBody:!0})]}),s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-meta font-medium text-foreground",children:r("multirun.fusion.sources.label",{count:N.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:N.map(y=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(bi,{providerId:hi(y.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:y.session.title||y.session.id}),s.jsx("button",{type:"button",onClick:()=>A(I=>I.filter(_=>_.session.id!==y.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(T,{name:"close",className:"h-4 w-4"})})]},y.session.id))})]}),s.jsxs(sr,{children:[s.jsx(lt,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(lt,{onClick:V,disabled:!B,children:r(k?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function Yj(t){const e=it.c(7);let n,r,o,i,c;e[0]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("path",{d:"M12 4.5v6.25M12 10.75v3.5M12 10.75H7.25A3.25 3.25 0 0 0 4 14v1.25M12 10.75h4.75A3.25 3.25 0 0 1 20 14v1.25",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),r=s.jsx("path",{d:"M9.25 7.25 12 4.5l2.75 2.75",stroke:"currentColor",strokeWidth:"1.65",strokeLinecap:"round",strokeLinejoin:"round"}),o=s.jsx("circle",{cx:"4",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),i=s.jsx("circle",{cx:"12",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),c=s.jsx("circle",{cx:"20",cy:"17.25",r:"1.55",stroke:"currentColor",strokeWidth:"1.65"}),e[0]=n,e[1]=r,e[2]=o,e[3]=i,e[4]=c):(n=e[0],r=e[1],o=e[2],i=e[3],c=e[4]);let a;return e[5]!==t?(a=s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",...t,children:[n,r,o,i,c]}),e[5]=t,e[6]=a):a=e[6],a}const sl=6,ei=14,vd=sl+14+6,ka=new WeakMap,Qj=t=>{if(typeof window>"u")return;const e=t.closest("[data-session-row]"),n=e?.closest(".overlay-scrollbar-container");if(!e||!n)return;ka.get(n)?.();const r=e.getBoundingClientRect().top;let o=3,i=!1,c=null;const a=()=>{i=!0,c!==null&&window.cancelAnimationFrame(c),c=null,ka.delete(n),n.removeEventListener("wheel",a),n.removeEventListener("touchstart",a)},d=()=>{if(i||!e.isConnected||!n.isConnected){a();return}const u=e.getBoundingClientRect().top-r;if(Math.abs(u)>.5&&(n.scrollTop+=u,In("ui.sidebar.selection_scroll_anchor_adjustment")),o-=1,o<=0){a();return}c=window.requestAnimationFrame(d)};n.addEventListener("wheel",a,{passive:!0}),n.addEventListener("touchstart",a,{passive:!0}),ka.set(n,a),c=window.requestAnimationFrame(d)},Xj=l.memo(function(e){const n=it.c(22),{archiveLabel:r,deleteLabel:o,buttonSizeClass:i,iconSizeClass:c,onPointerDown:a,onMouseDown:d,onArchive:u,onDelete:m}=e,f=Dj(),g=f?o:r;let x;n[0]!==u||n[1]!==m||n[2]!==f?(x=A=>{if(f||A.shiftKey){m(A);return}u(A)},n[0]=u,n[1]=m,n[2]=f,n[3]=x):x=n[3];const j=x,w=f?"text-destructive hover:text-destructive":"text-muted-foreground hover:text-foreground";let p;n[4]!==i||n[5]!==w?(p=ge("inline-flex items-center justify-center rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",w,i),n[4]=i,n[5]=w,n[6]=p):p=n[6];const h=f?"delete-bin":"archive";let b;n[7]!==c||n[8]!==h?(b=s.jsx(T,{name:h,className:c}),n[7]=c,n[8]=h,n[9]=b):b=n[9];let v;n[10]!==j||n[11]!==g||n[12]!==d||n[13]!==a||n[14]!==p||n[15]!==b?(v=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",className:p,"aria-label":g,onPointerDown:a,onMouseDown:d,onClick:j,onKeyDown:r2,children:b})}),n[10]=j,n[11]=g,n[12]=d,n[13]=a,n[14]=p,n[15]=b,n[16]=v):v=n[16];let S;n[17]!==g?(S=s.jsx(ht,{side:"left",sideOffset:8,children:g}),n[17]=g,n[18]=S):S=n[18];let N;return n[19]!==v||n[20]!==S?(N=s.jsxs(ft,{delayDuration:500,children:[v,S]}),n[19]=v,n[20]=S,n[21]=N):N=n[21],N});function Jj(t){In("ui.sidebar_session_node.render");const{t:e}=gt(),{node:n,depth:r=0,groupDirectory:o,projectId:i,archivedBucket:c=!1,pinnedSessionIds:a,expandedParents:d,hasSessionSearchQuery:u,normalizedSessionSearchQuery:m,notifyOnSubtasks:f,editingId:g,setEditingId:x,editTitle:j,setEditTitle:w,handleSaveEdit:p,handleCancelEdit:h,toggleParent:b,handleSessionSelect:v,handleSessionDoubleClick:S,togglePinnedSession:N,handleShareSession:A,copiedSessionId:k,handleCopyShareUrl:C,handleCopySessionId:P,handleUnshareSession:D,openSidebarMenuKey:O,setOpenSidebarMenuKey:F,renamingFolderId:E,getFoldersForScope:B,getSessionFolderId:$,removeSessionFromFolder:z,addSessionToFolder:V,createFolderAndStartRename:y,openContextPanelTab:I,handleDeleteSession:_,handleRestoreSession:W,mobileVariant:K,alwaysShowActions:Z,renderSessionNode:Q,secondaryMeta:le,renderContext:te="project",subtreeContainsEditing:he,menuOpenSessionId:xe,childRenderExtrasFor:H}=t,we=l.useMemo(()=>nr(),[]),de=l.useMemo(()=>Fi(),[]),q=l.useContext(lp),me=we?"group-hover:opacity-100 group-hover:pointer-events-auto":"group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto",be=we?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",Pe=we,Ie=!c&&!K,De=we?Ie&&Pe?"group-hover:pr-18":Ie||Pe?"group-hover:pr-14":"group-hover:pr-8":Ie?"group-hover:pr-7 group-focus-within:pr-7":"group-hover:pr-3 group-focus-within:pr-3",Le=Ie?"pr-13":"pr-7",Ne=l.useRef(!1),[ve,Me]=l.useState(!1),ee=l.useRef(g);ee.current=g;const oe=l.useRef(null),Te=l.useRef(p);Te.current=p;const[J,re]=l.useState(j),Y=l.useRef(J);Y.current=J;const U=l.useRef(null),fe=l.useRef(null),ne=n.session,ce=ne,Fe=Gt(l.useCallback(ke=>{if(le?.projectLabel||!i)return null;const Pt=ke.projects.find(Yt=>Yt.id===i);return Pt?Pt.label?.trim()||gr(jt(Pt.path)??Pt.path,null)||Pt.path:null},[i,le?.projectLabel])),Ye=le?.projectLabel??(Fe?bl(Fe):null),$e=le?.branchLabel??n.worktree?.branch??null,ie=l.useMemo(()=>{if(we)return null;const ke=n.worktree?.branch?.trim(),Pt=jt(n.worktree?.path??null);return ke&&Pt?zi(Pt,ke):null},[we,n.worktree]),Re=Eu(ie),ue=Re?`var(--pr-${Re.visualState})`:void 0,R=Ds(ke=>ke.sessionGroupingMode),ae=!!$e&&(te==="recent"||R==="flat"),Se=l.useMemo(()=>{if(!Re)return null;switch(Re.visualState){case"merged":return e("sessions.sidebar.group.pr.status.merged");case"open":return Re.canMerge===!0||Re.mergeableState==="clean"||Re.checks?.state==="success"?e("sessions.sidebar.group.pr.status.readyToMerge"):e("sessions.sidebar.group.pr.status.open");case"blocked":return Re.mergeableState==="dirty"?e("sessions.sidebar.group.pr.status.mergeConflicts"):e("sessions.sidebar.group.pr.status.mergeBlocked");case"draft":return e("sessions.sidebar.group.pr.status.draft");case"closed":return e("sessions.sidebar.group.pr.status.closed");default:return null}},[Re,e]),Ce=ot(ke=>ke.currentSessionId===ne.id),Ee=jt(ne.directory??null)??jt(o??null),se=i??Ee??null,je=ll(Ee??void 0,{bootstrap:!1}),Ze=_i(),X=As(ke=>ke.enabled),ye=As(l.useCallback(ke=>ke.selectedIds.has(ne.id),[ne.id])),Xe=As(ke=>ke.toggleSelected),Be=As(ke=>ke.setRange),We=l.useCallback(ke=>{const Pt=[],Yt=os=>{os.children.forEach(bs=>{Pt.push(bs.session.id),Yt(bs)})};return Yt(ke),Pt},[]),_e=l.useCallback(ke=>{const Pt=[],Yt=os=>{os.children.forEach(bs=>{Pt.push(bs.session),Yt(bs)})};return Yt(ke),Pt},[]),[tt,ct]=l.useState(!1),[Et,Nt]=l.useState(!0),Ot=`${te}:${c?"archived":"active"}:${ne.id}`,et=Mu(l.useCallback(ke=>!!ke.sessionMemoryState.get(cp(ne.id))?.isZombie,[ne.id])),xt=fu(ne.id)?.type??"idle",vt=xt==="busy"||xt==="retry",_t=dp(ne.id,vt),Ct=pf(ne.id),Rt=up(ne.id,Ee??void 0,{bootstrap:!1}),ut=fp(ce),bt=ut?s.jsx("span",{className:"inline-flex flex-shrink-0 items-center",title:e(lc[ut.status]),"aria-label":e(lc[ut.status]),children:s.jsx(T,{name:"target",className:"h-3 w-3",style:{color:mp[ut.status]}})}):null,He=ce.title||e("sessions.sidebar.session.untitled"),Ve=n.children.length>0,wt=hp(a,Ee,ne.id),Ft=Ot,Lt=u?!0:d.has(Ft),ns=l.useMemo(()=>O0(n,Lt,Ee),[Lt,n,Ee]),$t=pp(ns),At=!!ce.parentID,ms=gp(ne.id)>0&&(!At||f),zt=ce.time?.updated||ce.time?.created||Date.now(),qt=Ou(zt),Ut=xp(zt),Jt=O===Ot,[Oe,st]=l.useState(!1),Ke=Jt||Oe,Je=l.useMemo(()=>hi(ce.title)!==null,[ce.title]),[Qe,kt]=l.useState(!1),ts=l.useMemo(()=>We(n).length,[We,n]),Wt=l.useCallback(async ke=>{const Pt=[];let Yt=0;for(const os of ke)try{if(!Ee)throw new Error("Session directory is required for export");await Ze.loadCompleteHistory(os.session.id,Ee);const bs=Ia(je.getState(),os.session.id).list,fs=os.session.title||e("sessions.sidebar.session.export.untitledSubagent"),dn=os.session.agent,Cs=await Wt(os.children);Yt+=Cs.skipped,Pt.push({title:fs,agent:dn,records:bs,children:Cs.children})}catch{Yt+=We(os).length+1}return{children:Pt,skipped:Yt}},[We,je,Ee,Ze,e]),us=l.useCallback(ke=>{ke<=0||Ae.warning(ke===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:ke}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:ke}))},[e]),Bt=l.useCallback(async ke=>{if(!Ee){Ae.error(e("sessions.sidebar.session.export.nothingToExport"));return}try{await Ze.loadCompleteHistory(ne.id,Ee)}catch{Ae.error(e("sessions.sidebar.session.export.failedLoadHistory"));return}const Pt=Ia(je.getState(),ne.id).list;if(Pt.length===0){Ae.error(e("sessions.sidebar.session.export.nothingToExport"));return}let Yt,os=0;if(ke&&n.children.length>0){const Cs=await Wt(n.children);Yt=Cs.children,os=Cs.skipped}const bs=uf(Pt,ce.title??null,Yt),fs=hf(ce.title??null),dn=await mf(bs,fs);if(dn){Ae.success(e("sessions.sidebar.session.export.success"),{action:{label:e(nb()),onClick:()=>{sb(dn).then(Cs=>{Cs||Ae.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),us(os);return}ff(bs,fs),Ae.success(e("sessions.sidebar.session.export.success")),us(os)},[Wt,je,n.children,ce.title,ne.id,Ee,us,Ze,e]),Vt=l.useCallback(async()=>{if(n.children.length>0){Nt(!0),ct(!0);return}await Bt(!1)},[Bt,n.children.length]),js=l.useCallback(()=>{Ee&&mr("desktop_open_session_mini_chat_window",{sessionId:ne.id,directory:Ee,apiBaseUrl:hr(),clientToken:Co()}).catch(ke=>{console.warn("[session-sidebar] failed to open mini chat window",ke)})},[ne.id,Ee]);if(l.useEffect(()=>{if(g!==ne.id)return;const ke=Pt=>{const os=Pt.target?.closest?.(`[data-session-rename-form="${CSS.escape(ne.id)}"]`);fe.current&&!os&&Te.current(Y.current)};return document.addEventListener("mousedown",ke),()=>document.removeEventListener("mousedown",ke)},[g,ne.id]),l.useLayoutEffect(()=>{if(g!==ne.id){U.current===ne.id&&(U.current=null);return}U.current!==ne.id&&(U.current=ne.id,re(j))},[g,j,ne.id]),g===ne.id)return s.jsx("div",{style:{paddingLeft:vd+r*ei},className:"group relative my-0.5 flex items-center rounded-sm py-1 pr-1.5",children:s.jsx("div",{className:"flex min-w-0 flex-1 flex-col gap-0",children:s.jsxs("form",{ref:fe,"data-session-rename-form":ne.id,className:"flex w-full items-center gap-2",onSubmit:ke=>{ke.preventDefault(),p(J)},children:[s.jsx("input",{value:J,onChange:ke=>re(ke.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:e("sessions.sidebar.session.menu.rename"),onKeyDown:ke=>{if(ke.stopPropagation(),ke.key==="Escape"){h();return}}}),s.jsx("button",{type:"submit","aria-label":e("sessions.sidebar.session.rename.save"),title:e("sessions.sidebar.session.rename.save"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(T,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:h,"aria-label":e("sessions.sidebar.session.rename.cancel"),title:e("sessions.sidebar.session.rename.cancel"),className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(T,{name:"close",className:"size-4"})})]})})},ne.id);const ln=Rt.length,Rn=$t===1?e("sessions.sidebar.session.status.questionPendingSingle"):e("sessions.sidebar.session.status.questionPendingMany",{count:$t}),Hn=!Ct&&!vt&&ms&&!Ce,cn=vt||Hn,Cn=e(vt?"sessions.sidebar.session.status.active":"sessions.sidebar.session.status.unread"),Ts=s.jsx("span",{className:ge("h-1.5 w-1.5 rounded-full",vt?"bg-primary":"bg-[var(--status-info)]"),"aria-label":Cn,title:Cn}),Xs=(vt||Hn)&&_t,Kn=!Z&&Ve&&(Ct||cn||wt),Is=wt&&!Ct&&!cn,_s=s.jsx(T,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}),$s=Ct||cn||Is?s.jsx("span",{style:{left:sl+r*ei},className:ge("pointer-events-none absolute top-1/2 inline-flex h-3.5 w-3.5 -translate-y-1/2 items-center justify-center transition-opacity",Kn?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:Ct?s.jsx(T,{name:"loader-4",className:"h-3 w-3 animate-spin text-primary","aria-label":e("sessions.sidebar.session.status.movingToWorktree")}):cn?Ts:Is?_s:null}):null,zs=Ve&&!Z&&(Ct||cn||wt),Us=Ve?s.jsx("span",{role:"button",tabIndex:0,onClick:ke=>{ke.stopPropagation(),ke.currentTarget.blur(),b(Ft)},onKeyDown:ke=>{(ke.key==="Enter"||ke.key===" ")&&(ke.preventDefault(),ke.stopPropagation(),b(Ft))},style:{minWidth:14,minHeight:14,left:sl+r*ei},className:ge("absolute top-1/2 inline-flex h-3.5 w-3.5 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",zs?"opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto group-focus-within:opacity-100 group-focus-within:pointer-events-auto":""),"aria-label":e(Lt?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Lt?s.jsx(T,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(T,{name:"arrow-right-s",className:"h-3 w-3"})}):null,Gn=et?s.jsx(T,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,Nn=ke=>{ke&&st(!1),F(ke?Ot:null)},Rs=ke=>{if(!ke&&oe.current){const{id:Pt,title:Yt}=oe.current;oe.current=null,x(Pt),w(Yt)}},or=ke=>{st(ke)},G=ke=>{ke.preventDefault(),ke.stopPropagation(),F(Jt?null:Ot)},qe=ke=>{ke.preventDefault(),ke.stopPropagation()},at=ke=>{ke.preventDefault(),ke.stopPropagation()},pt=ke=>{ke.preventDefault(),ke.stopPropagation()},It=ke=>{ke.preventDefault(),ke.stopPropagation()},Dt=ke=>{ke.preventDefault(),ke.stopPropagation(),F(null),_(ne,{archivedBucket:c})},yt=ke=>{ke.preventDefault(),ke.stopPropagation(),F(null),_(ne,{archivedBucket:c,hardDelete:!0,skipConfirm:!0})},cs=ke=>{ke.preventDefault(),ke.stopPropagation()},ws=ke=>{ke.preventDefault(),ke.stopPropagation()},Zt=ke=>{ke.preventDefault(),ke.stopPropagation(),q?.vscode?.executeCommand("openchamber.openSessionInEditor",ne.id,He)},ks=ke=>{if(Ne.current){Ne.current=!1;return}if(X){if(ke?.preventDefault(),ke?.stopPropagation(),ke?.shiftKey){const Yt=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(fs=>fs.getAttribute("data-session-row")).filter(fs=>typeof fs=="string"&&fs.length>0),os=As.getState().anchorId,bs=new Map;bs.set(ne.id,We(n)),Be(os,ne.id,Yt,se,bs);return}Xe(ne.id,se,We(n));return}ke?.currentTarget&&Qj(ke.currentTarget),v(ne.id,Ee)},Ms=ke=>{ke.defaultPrevented||ke.target?.closest('button, a, input, [role="menuitem"], [role="menu"]')||ks(ke)},Mn=ke=>{(ke.button===2||ke.button===0&&ke.ctrlKey&&!X)&&(Ne.current=!0)},Ss=ke=>{K&&ke.pointerType==="touch"&&Me(!0)},An=ke=>{K&&ke.pointerType==="touch"&&Me(!1)},yr=({Item:ke,Separator:Pt,Sub:Yt,SubTrigger:os,SubContent:bs})=>s.jsxs(s.Fragment,{children:[s.jsxs(ke,{onClick:()=>{oe.current={id:ne.id,title:He}},className:"[&>svg]:mr-1",children:[s.jsx(T,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(ke,{onClick:()=>P(ne.id),className:"[&>svg]:mr-1",children:[s.jsx(T,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyId")]}),s.jsxs(ke,{onClick:()=>Ee&&N({directory:Ee,sessionId:ne.id}),className:"[&>svg]:mr-1",children:[wt?s.jsx(T,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(T,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(wt?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),ce.share?s.jsxs(s.Fragment,{children:[s.jsx(ke,{onClick:()=>{ce.share?.url&&C(ce.share.url,ne.id)},className:"[&>svg]:mr-1",children:k===ne.id?s.jsxs(s.Fragment,{children:[s.jsx(T,{name:"check",className:"mr-1 h-4 w-4",style:{color:"var(--status-success)"}}),e("sessions.sidebar.session.menu.copied")]}):s.jsxs(s.Fragment,{children:[s.jsx(T,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(ke,{onClick:()=>D(ne.id),className:"[&>svg]:mr-1",children:[s.jsx(T,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(ke,{onClick:()=>A(ce),className:"[&>svg]:mr-1",children:[s.jsx(T,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(ke,{onClick:()=>{Vt()},className:"[&>svg]:mr-1",children:[s.jsx(T,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),!At&&!c&&!we?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(ke,{disabled:!Ee||vt||Ct,onClick:()=>{!Ee||vt||Ct||gf({root:ce,descendants:_e(n),sourceDirectory:Ee,successMessage:e("sessions.sidebar.session.moveToWorktree.success"),failureMessage:e("sessions.sidebar.session.moveToWorktree.failed")})},className:"w-full [&>svg]:mr-1",children:[s.jsx(T,{name:"folder-shared",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.moveToWorktree")]})})}),s.jsx(ht,{side:"right",className:"max-w-72",children:e(Ct?"sessions.sidebar.session.moveToWorktree.tooltipMoving":vt?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,Je?s.jsxs(ke,{onClick:()=>kt(!0),className:"[&>svg]:mr-1",children:[s.jsx(Yj,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,Ee&&!c?(()=>{const fs=[],dn=ys=>{const hs=jt(ys??null);hs&&!fs.includes(hs)&&fs.push(hs)};if(i&&!we){const ys=Gt.getState().projects.find(Dn=>Dn.id===i),hs=jt(ys?.path??null);dn(hs),hs&&(ot.getState().availableWorktreesByProject.get(hs)??[]).forEach(Dn=>dn(Dn.path))}dn(Ee);const Cs=fs.flatMap(ys=>B(ys).map(hs=>({scope:ys,folder:hs}))),Js=Cs.find(({scope:ys,folder:hs})=>$(ys,ne.id)===hs.id)??null,Sr=fs[0]??Ee;return s.jsxs(s.Fragment,{children:[s.jsx(Pt,{}),s.jsxs(Yt,{children:[s.jsxs(os,{className:"[&>svg]:mr-1",children:[s.jsx(T,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(bs,{className:"min-w-[180px]",children:[Cs.length===0?s.jsx(ke,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):Cs.map(({scope:ys,folder:hs})=>{const Dn=Js?.folder.id===hs.id;return s.jsxs(ke,{onClick:()=>{if(Dn){z(ys,ne.id);return}Js&&Js.scope!==ys&&z(Js.scope,ne.id),V(ys,hs.id,ne.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:hs.name}),Dn?s.jsx(T,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},hs.id)}),s.jsx(Pt,{}),s.jsxs(ke,{onClick:()=>{const ys=y(Sr);ys&&(Js&&Js.scope!==Sr&&z(Js.scope,ne.id),V(Sr,ys.id,ne.id))},children:[s.jsx(T,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),Js?s.jsxs(ke,{onClick:()=>{z(Js.scope,ne.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(T,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,we?null:s.jsxs(ke,{disabled:!Ee,onClick:()=>{Ee&&I(Ee,{mode:"chat",dedupeKey:`session:${ne.id}`,label:He,sessionTitleFallback:He})},className:"[&>svg]:mr-1",children:[s.jsx(T,{name:"chat-4",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openInSidePanel")}),s.jsx("span",{className:"shrink-0 typography-micro px-1 rounded leading-none pb-px text-[var(--status-warning)] bg-[var(--status-warning)]/10",children:e("sessions.sidebar.session.menu.betaBadge")})]}),de?s.jsxs(ke,{disabled:!Ee,onClick:js,className:"[&>svg]:mr-1",children:[s.jsx(T,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(Pt,{}),c?null:s.jsxs(ke,{className:"[&>svg]:mr-1",onClick:()=>_(ne,{archivedBucket:c}),children:[s.jsx(T,{name:"inbox-archive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.archive")]}),c?s.jsxs(ke,{className:"[&>svg]:mr-1",onClick:()=>W(ne),children:[s.jsx(T,{name:"inbox-unarchive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.restore")]}):null,s.jsxs(ke,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>_(ne,{archivedBucket:c,hardDelete:!0}),children:[s.jsx(T,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.delete")]})]}),vr=s.jsx(Sn,{align:"end",className:"min-w-[180px]",finalFocus:()=>!(E||ee.current),children:yr({Item:Xt,Separator:vn,Sub:wp,SubTrigger:Sp,SubContent:jp})}),wr=s.jsx(Sc,{children:s.jsx(jc,{className:"app-region-no-drag z-50",children:s.jsx(kc,{"data-slot":"dropdown-menu-content",finalFocus:()=>!(E||ee.current),style:{color:"var(--surface-elevated-foreground)"},className:ge(cc,"min-w-[180px]"),children:yr({Item:({className:ke,...Pt})=>s.jsx(bx,{className:ge(bp,ke),...Pt}),Separator:({className:ke,...Pt})=>s.jsx(yx,{className:ge(yp,ke),...Pt}),Sub:vx,SubTrigger:({className:ke,children:Pt,...Yt})=>s.jsxs(wx,{className:ge(vp,ke),...Yt,children:[Pt,s.jsx(T,{name:"arrow-right-s",className:"ml-auto size-3.5"})]}),SubContent:({className:ke,children:Pt,...Yt})=>s.jsx(Sc,{children:s.jsx(jc,{className:"app-region-no-drag z-50",children:s.jsx(kc,{"data-slot":"dropdown-menu-sub-content",style:{backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)"},className:ge(cc,ke),...Yt,children:Pt})})})})})})});return s.jsxs(l.Fragment,{children:[s.jsx(I0,{sessionId:ne.id,sessionDirectory:Ee??null,sessionTitle:He,children:s.jsxs(gx,{open:Oe,onOpenChange:or,onOpenChangeComplete:Rs,children:[s.jsxs(xx,{render:s.jsx("div",{"data-session-row":ne.id,"data-session-scope":se??"","data-session-archived":c?"1":"0",onClick:Ms,style:{paddingLeft:vd+r*ei},className:ge("group relative my-0.5 flex cursor-pointer items-center rounded-md py-1 pr-1.5",Ce&&!ye&&"bg-primary/10",ye&&"bg-interactive-selection")}),children:[$s,Us,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onPointerDown:Ss,onPointerUp:An,onPointerCancel:An,onMouseDown:Mn,onClick:ke=>ks(ke),onDoubleClick:ke=>{ke.stopPropagation(),S(ne.id,He)},className:ge("flex min-w-0 flex-1 cursor-pointer flex-col gap-0 overflow-hidden text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 text-foreground select-none transition-[padding]",ve&&"bg-interactive-hover/70",Z?we?De:Le:De),children:s.jsxs("div",{className:"flex w-full items-center min-w-0 flex-1 gap-1 overflow-hidden",children:[s.jsx("div",{className:ge("block min-w-0 flex-1 truncate typography-ui-label font-normal",Ce?"text-primary":ms?"text-foreground":"text-foreground/80"),children:li(He,m)}),Z?s.jsx("span",{className:"ml-2 inline-flex flex-shrink-0 items-center gap-1 text-[0.72rem] text-muted-foreground/75",children:Xs?s.jsx(yc,{sessionId:ne.id,running:vt}):s.jsxs(s.Fragment,{children:[bt,ae?s.jsx(T,{name:"git-branch",className:ge("h-3 w-3",!ue&&"text-muted-foreground/60"),style:ue?{color:ue}:void 0}):null,Ut]})}):Xs||bt||ae?s.jsx("div",{className:"relative ml-1 flex h-4 flex-shrink-0 items-center justify-end",children:s.jsx("span",{className:ge("inline-flex items-center gap-1 whitespace-nowrap text-right transition-opacity duration-150",Ke?"opacity-0":be),children:Xs?s.jsx(yc,{sessionId:ne.id,running:vt,className:"text-[0.72rem]"}):s.jsxs(s.Fragment,{children:[bt,ae?s.jsx(T,{name:"git-branch",className:ge("h-3 w-3",!ue&&"text-muted-foreground/60"),style:ue?{color:ue}:void 0}):null]})})}):null,ln>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-destructive/10 px-1 py-0.5 text-[0.7rem] text-destructive flex-shrink-0",title:e("sessions.sidebar.session.status.permissionRequired"),"aria-label":e("sessions.sidebar.session.status.permissionRequired"),children:[s.jsx(T,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:ln})]}):null,$t>0?s.jsxs("span",{className:"inline-flex items-center gap-1 rounded bg-status-info/10 px-1 py-0.5 text-[0.7rem] text-status-info flex-shrink-0",title:Rn,"aria-label":Rn,children:[s.jsx(T,{name:"question",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:$t})]}):null]})})}),we?null:s.jsx(ht,{side:"right",sideOffset:8,className:"max-w-xs text-left",children:s.jsxs("div",{className:"flex min-w-44 flex-col gap-1.5 text-left text-xs",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsx("span",{className:"min-w-0 truncate font-medium text-foreground",children:He}),s.jsx("span",{className:"flex-shrink-0 text-muted-foreground",title:qt,children:Ut})]}),Ye?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[s.jsx(T,{name:"folder",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 truncate",children:Ye})]}):null,$e?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[s.jsx(T,{name:"git-branch",className:"h-3 w-3 flex-shrink-0",style:ue?{color:ue}:void 0}),s.jsx("span",{className:"min-w-0 truncate",children:$e})]}):null,Re&&Se?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx(T,{name:"git-pull-request",className:"h-3 w-3 flex-shrink-0",style:ue?{color:ue}:void 0}),s.jsxs("span",{className:"min-w-0 truncate",style:ue?{color:ue}:void 0,children:["#",Re.number," · ",Se]})]}):null]})})]})}),Gn&&!K?s.jsx("div",{className:"absolute right-0 top-1/2 -translate-y-1/2 z-10",children:Gn}):null,s.jsxs("div",{className:ge("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",Ke||Z&&!we?"opacity-100":ge("opacity-0",me)),children:[Ie?s.jsx(Xj,{archiveLabel:e("sessions.sidebar.bulkActions.archive"),deleteLabel:e("sessions.sidebar.bulkActions.delete"),buttonSizeClass:Z?"h-6 w-6":"h-4 w-4",iconSizeClass:Z?"h-3.5 w-3.5":"h-2.5 w-2.5",onPointerDown:pt,onMouseDown:It,onArchive:Dt,onDelete:yt}):null,Pe?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",className:ge("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",Z?"h-6 w-6":"h-4 w-4"),"aria-label":e("sessions.sidebar.session.actions.openInEditor"),onPointerDown:cs,onMouseDown:ws,onClick:Zt,onKeyDown:ke=>ke.stopPropagation(),children:s.jsx(T,{name:"external-link",className:ge(Z?"h-3.5 w-3.5":"h-2.5 w-2.5")})})}),s.jsx(ht,{side:"left",sideOffset:8,children:e("sessions.sidebar.session.actions.openInEditor")})]}):null,s.jsxs(jn,{open:Jt,onOpenChange:Nn,onOpenChangeComplete:Rs,children:[s.jsx(wn,{asChild:!0,children:s.jsx("button",{type:"button",className:ge("inline-flex items-center justify-center rounded-md text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",Z?"h-6 w-6 opacity-100":Ke?"h-4 w-4 opacity-100":ge("h-4 w-4 opacity-0",me)),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:qe,onMouseDown:at,onClick:G,onKeyDown:ke=>ke.stopPropagation(),children:s.jsx(T,{name:"more-2",className:ge(Z?"h-3.5 w-3.5":"h-2.5 w-2.5")})})}),vr]})]})]}),wr]})}),Ve&&Lt?n.children.map(ke=>{const Pt=H?H(ke):{subtreeContainsEditing:he,menuOpenSessionId:xe,nodeStructureKey:""};return Q(ke,r+1,Ee??o,i,c,void 0,te,Pt)}):null,s.jsx(Ls,{open:tt,onOpenChange:ct,children:s.jsxs(Bs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(kn,{children:[s.jsx(nn,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(rn,{children:ts===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:ts}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:ts})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:Et,onChange:ke=>Nt(ke.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(sr,{children:[s.jsx(lt,{type:"button",onClick:()=>ct(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(lt,{type:"button",onClick:()=>{ct(!1),Bt(Et)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),Je?s.jsx(qj,{session:ce,open:Qe,onOpenChange:kt}):null]},ne.id)}const wd=t=>jt(t.session.directory??null),Zj=(t,e)=>(t?.projectLabel??null)===(e?.projectLabel??null)&&(t?.branchLabel??null)===(e?.branchLabel??null),e2=t=>{if(!t.openSidebarMenuKey)return null;const e=t.archivedBucket?"archived":"active",n=`${t.renderContext??"project"}:${e}:`;return t.openSidebarMenuKey.startsWith(n)?t.openSidebarMenuKey.slice(n.length):null},ti=t=>t.menuOpenSessionId??e2(t),si=(t,e,n)=>e?n.has(t.node.session.id)?!0:Xn(t.node,e):!1,nl=(t,e,n,r,o)=>{if(t.session.id!==e.session.id)return!0;const i=o(t);if(n.has(i)!==r.has(i)||t.children.length!==e.children.length)return!0;for(let c=0;c<t.children.length;c+=1)if(nl(t.children[c],e.children[c],n,r,o))return!0;return!1},t2=(t,e)=>{if(t.hasSessionSearchQuery||e.hasSessionSearchQuery)return!1;const n=t.archivedBucket?"archived":"active",r=e.archivedBucket?"archived":"active";return nl(t.node,e.node,t.expandedParents,e.expandedParents,o=>`${t.renderContext??"project"}:${n}:${o.session.id}`)||nl(t.node,e.node,t.expandedParents,e.expandedParents,o=>`${e.renderContext??"project"}:${r}:${o.session.id}`)},s2=(t,e)=>{if(t.node.session.id!==e.node.session.id||t.node.session!==e.node.session||t.depth!==e.depth||t.groupDirectory!==e.groupDirectory||t.projectId!==e.projectId||t.archivedBucket!==e.archivedBucket||(t.renderContext??"project")!==(e.renderContext??"project")||t.mobileVariant!==e.mobileVariant||t.alwaysShowActions!==e.alwaysShowActions||t.hasSessionSearchQuery!==e.hasSessionSearchQuery||t.normalizedSessionSearchQuery!==e.normalizedSessionSearchQuery||t.notifyOnSubtasks!==e.notifyOnSubtasks||t.nodeStructureKey!==e.nodeStructureKey||wd(t.node)!==wd(e.node)||!Zj(t.secondaryMeta,e.secondaryMeta)||t.pinnedSessionIds!==e.pinnedSessionIds&&Vf(t.node,e.node,t.pinnedSessionIds,e.pinnedSessionIds,t.groupDirectory,e.groupDirectory)||t.expandedParents!==e.expandedParents&&t2(t,e)||t.editingId!==e.editingId&&(si(t,t.editingId,t.subtreeContainsEditing)||si(e,e.editingId,e.subtreeContainsEditing))||t.editTitle!==e.editTitle&&(si(t,t.editingId,t.subtreeContainsEditing)||si(e,e.editingId,e.subtreeContainsEditing))||t.copiedSessionId!==e.copiedSessionId&&(Xn(t.node,t.copiedSessionId)||Xn(e.node,e.copiedSessionId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=ti(t),r=ti(e);if(Xn(t.node,n)||Xn(e.node,r))return!1}if(t.renamingFolderId!==e.renamingFolderId){const n=ti(t),r=ti(e);if(Xn(t.node,n)||Xn(e.node,r))return!1}return t.setEditingId===e.setEditingId&&t.setEditTitle===e.setEditTitle&&t.handleSaveEdit===e.handleSaveEdit&&t.handleCancelEdit===e.handleCancelEdit&&t.toggleParent===e.toggleParent&&t.handleSessionSelect===e.handleSessionSelect&&t.handleSessionDoubleClick===e.handleSessionDoubleClick&&t.togglePinnedSession===e.togglePinnedSession&&t.handleShareSession===e.handleShareSession&&t.handleCopyShareUrl===e.handleCopyShareUrl&&t.handleCopySessionId===e.handleCopySessionId&&t.handleUnshareSession===e.handleUnshareSession&&t.setOpenSidebarMenuKey===e.setOpenSidebarMenuKey&&t.getFoldersForScope===e.getFoldersForScope&&t.getSessionFolderId===e.getSessionFolderId&&t.removeSessionFromFolder===e.removeSessionFromFolder&&t.addSessionToFolder===e.addSessionToFolder&&t.createFolderAndStartRename===e.createFolderAndStartRename&&t.openContextPanelTab===e.openContextPanelTab&&t.handleDeleteSession===e.handleDeleteSession&&t.handleRestoreSession===e.handleRestoreSession&&t.renderSessionNode===e.renderSessionNode},n2=l.memo(Jj,s2);function r2(t){return t.stopPropagation()}function o2(t){const e=it.c(71),{t:n}=gt(),{value:r,setValue:o,showDeletionDialog:i,setShowDeletionDialog:c,onConfirm:a}=t;let d,u,m,f,g,x,j,w,p,h;if(e[0]!==o||e[1]!==n||e[2]!==r){const I=n("sessions.sidebar.session.untitled");f=Ls,p=!!r,e[13]!==o?(h=W=>{W||o(null)},e[13]=o,e[14]=h):h=e[14],m=Bs,j=!1,w="max-w-sm gap-5",u=kn;let _;e[15]!==n||e[16]!==r?.archivedBucket?(_=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=_):_=e[17],e[18]!==_?(x=s.jsx(nn,{children:_}),e[18]=_,e[19]=x):x=e[19],d=rn,g=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||I,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||I,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||I,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||I,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||I}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||I}),e[0]=o,e[1]=n,e[2]=r,e[3]=d,e[4]=u,e[5]=m,e[6]=f,e[7]=g,e[8]=x,e[9]=j,e[10]=w,e[11]=p,e[12]=h}else d=e[3],u=e[4],m=e[5],f=e[6],g=e[7],x=e[8],j=e[9],w=e[10],p=e[11],h=e[12];let b;e[20]!==d||e[21]!==g?(b=s.jsx(d,{children:g}),e[20]=d,e[21]=g,e[22]=b):b=e[22];let v;e[23]!==u||e[24]!==x||e[25]!==b?(v=s.jsxs(u,{children:[x,b]}),e[23]=u,e[24]=x,e[25]=b,e[26]=v):v=e[26];let S;e[27]!==c||e[28]!==i?(S=()=>c(!i),e[27]=c,e[28]=i,e[29]=S):S=e[29];const N=!i;let A;e[30]!==i?(A=i?s.jsx(T,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(T,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=i,e[31]=A):A=e[31];let k;e[32]!==n?(k=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=k):k=e[33];let C;e[34]!==A||e[35]!==k||e[36]!==S||e[37]!==N?(C=s.jsxs("button",{type:"button",onClick:S,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":N,children:[A,k]}),e[34]=A,e[35]=k,e[36]=S,e[37]=N,e[38]=C):C=e[38];let P;e[39]!==o?(P=()=>o(null),e[39]=o,e[40]=P):P=e[40];let D;e[41]!==n?(D=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=D):D=e[42];let O;e[43]!==P||e[44]!==D?(O=s.jsx("button",{type:"button",onClick:P,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:D}),e[43]=P,e[44]=D,e[45]=O):O=e[45];let F;e[46]!==a?(F=()=>{a()},e[46]=a,e[47]=F):F=e[47];let E;e[48]!==n||e[49]!==r?.archivedBucket?(E=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=E):E=e[50];let B;e[51]!==F||e[52]!==E?(B=s.jsx("button",{type:"button",onClick:F,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:E}),e[51]=F,e[52]=E,e[53]=B):B=e[53];let $;e[54]!==O||e[55]!==B?($=s.jsxs("div",{className:"flex items-center gap-2",children:[O,B]}),e[54]=O,e[55]=B,e[56]=$):$=e[56];let z;e[57]!==C||e[58]!==$?(z=s.jsxs(sr,{className:"w-full sm:items-center sm:justify-between",children:[C,$]}),e[57]=C,e[58]=$,e[59]=z):z=e[59];let V;e[60]!==m||e[61]!==j||e[62]!==z||e[63]!==w||e[64]!==v?(V=s.jsxs(m,{showCloseButton:j,className:w,children:[v,z]}),e[60]=m,e[61]=j,e[62]=z,e[63]=w,e[64]=v,e[65]=V):V=e[65];let y;return e[66]!==f||e[67]!==V||e[68]!==p||e[69]!==h?(y=s.jsx(f,{open:p,onOpenChange:h,children:V}),e[66]=f,e[67]=V,e[68]=p,e[69]=h,e[70]=y):y=e[70],y}function i2(t){const e=it.c(57),{t:n}=gt(),{value:r,setValue:o,showDeletionDialog:i,setShowDeletionDialog:c,onConfirm:a}=t,d=r?.archivedBucket===!0,u=r?.sessionCount??0;let m;e[0]!==d||e[1]!==u||e[2]!==n?(m=n(d?u===1?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.deleteSessions.title":u===1?"sessions.sidebar.dialogs.archiveSession.title":"sessions.sidebar.dialogs.archiveSessions.title"),e[0]=d,e[1]=u,e[2]=n,e[3]=m):m=e[3];const f=m;let g;e[4]!==d||e[5]!==u||e[6]!==n?(g=d?u===1?n("sessions.sidebar.dialogs.deleteSessions.singleDescription",{count:u}):n("sessions.sidebar.dialogs.deleteSessions.pluralDescription",{count:u}):u===1?n("sessions.sidebar.dialogs.archiveSessions.singleDescription",{count:u}):n("sessions.sidebar.dialogs.archiveSessions.pluralDescription",{count:u}),e[4]=d,e[5]=u,e[6]=n,e[7]=g):g=e[7];const x=g,j=!!r;let w;e[8]!==o?(w=y=>{y||o(null)},e[8]=o,e[9]=w):w=e[9];let p;e[10]!==f?(p=s.jsx(nn,{children:f}),e[10]=f,e[11]=p):p=e[11];let h;e[12]!==x?(h=s.jsx(rn,{children:x}),e[12]=x,e[13]=h):h=e[13];let b;e[14]!==p||e[15]!==h?(b=s.jsxs(kn,{children:[p,h]}),e[14]=p,e[15]=h,e[16]=b):b=e[16];let v;e[17]!==c||e[18]!==i?(v=()=>c(!i),e[17]=c,e[18]=i,e[19]=v):v=e[19];const S=!i;let N;e[20]!==i?(N=i?s.jsx(T,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(T,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=i,e[21]=N):N=e[21];let A;e[22]!==n?(A=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=A):A=e[23];let k;e[24]!==A||e[25]!==v||e[26]!==S||e[27]!==N?(k=s.jsxs("button",{type:"button",onClick:v,className:"inline-flex items-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":S,children:[N,A]}),e[24]=A,e[25]=v,e[26]=S,e[27]=N,e[28]=k):k=e[28];let C;e[29]!==o?(C=()=>o(null),e[29]=o,e[30]=C):C=e[30];let P;e[31]!==n?(P=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=P):P=e[32];let D;e[33]!==C||e[34]!==P?(D=s.jsx("button",{type:"button",onClick:C,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:P}),e[33]=C,e[34]=P,e[35]=D):D=e[35];let O;e[36]!==a?(O=()=>{a()},e[36]=a,e[37]=O):O=e[37];let F;e[38]!==d||e[39]!==n?(F=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=F):F=e[40];let E;e[41]!==O||e[42]!==F?(E=s.jsx("button",{type:"button",onClick:O,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:F}),e[41]=O,e[42]=F,e[43]=E):E=e[43];let B;e[44]!==D||e[45]!==E?(B=s.jsxs("div",{className:"flex items-center gap-2",children:[D,E]}),e[44]=D,e[45]=E,e[46]=B):B=e[46];let $;e[47]!==k||e[48]!==B?($=s.jsxs(sr,{className:"w-full sm:items-center sm:justify-between",children:[k,B]}),e[47]=k,e[48]=B,e[49]=$):$=e[49];let z;e[50]!==$||e[51]!==b?(z=s.jsxs(Bs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[b,$]}),e[50]=$,e[51]=b,e[52]=z):z=e[52];let V;return e[53]!==j||e[54]!==z||e[55]!==w?(V=s.jsx(Ls,{open:j,onOpenChange:w,children:z}),e[53]=j,e[54]=z,e[55]=w,e[56]=V):V=e[56],V}function a2(t){const e=it.c(36),{t:n}=gt(),{value:r,setValue:o,onConfirm:i}=t,c=!!r;let a;e[0]!==o?(a=N=>{N||o(null)},e[0]=o,e[1]=a):a=e[1];let d;e[2]!==n?(d=n("sessions.sidebar.dialogs.deleteFolder.title"),e[2]=n,e[3]=d):d=e[3];let u;e[4]!==d?(u=s.jsx(nn,{children:d}),e[4]=d,e[5]=u):u=e[5];let m;e[6]!==n||e[7]!==r?(m=r&&(r.subFolderCount>0||r.sessionCount>0)?r.subFolderCount>0?r.subFolderCount===1?n("sessions.sidebar.dialogs.deleteFolder.withOneSubfolder",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withManySubfolders",{folderName:r.folderName,count:r.subFolderCount}):n("sessions.sidebar.dialogs.deleteFolder.withContentsNoSubfolders",{folderName:r.folderName}):n("sessions.sidebar.dialogs.deleteFolder.single",{folderName:r?.folderName??""}),e[6]=n,e[7]=r,e[8]=m):m=e[8];let f;e[9]!==m?(f=s.jsx(rn,{children:m}),e[9]=m,e[10]=f):f=e[10];let g;e[11]!==u||e[12]!==f?(g=s.jsxs(kn,{children:[u,f]}),e[11]=u,e[12]=f,e[13]=g):g=e[13];let x;e[14]!==o?(x=()=>o(null),e[14]=o,e[15]=x):x=e[15];let j;e[16]!==n?(j=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=j):j=e[17];let w;e[18]!==x||e[19]!==j?(w=s.jsx("button",{type:"button",onClick:x,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:j}),e[18]=x,e[19]=j,e[20]=w):w=e[20];let p;e[21]!==n?(p=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=p):p=e[22];let h;e[23]!==i||e[24]!==p?(h=s.jsx("button",{type:"button",onClick:i,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:p}),e[23]=i,e[24]=p,e[25]=h):h=e[25];let b;e[26]!==h||e[27]!==w?(b=s.jsxs(sr,{children:[w,h]}),e[26]=h,e[27]=w,e[28]=b):b=e[28];let v;e[29]!==b||e[30]!==g?(v=s.jsxs(Bs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[g,b]}),e[29]=b,e[30]=g,e[31]=v):v=e[31];let S;return e[32]!==c||e[33]!==a||e[34]!==v?(S=s.jsx(Ls,{open:c,onOpenChange:a,children:v}),e[32]=c,e[33]=a,e[34]=v,e[35]=S):S=e[35],S}const l2=t=>{const e=it.c(51),{selectedCount:n,scopeKey:r,scopeFolders:o,archivedBucket:i,onMoveToFolder:c,onCreateFolderAndMove:a,onRemoveFromFolder:d,canRemoveFromFolder:u,onRestore:m,onDelete:f,onDone:g}=t,{t:x}=gt(),j=!!r&&!i;let w;e[0]!==i||e[1]!==x?(w=x(i?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=i,e[1]=x,e[2]=w):w=e[2];const p=w;let h;e[3]!==n||e[4]!==x?(h=x("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=x,e[5]=h):h=e[5];let b;e[6]!==h?(b=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:h}),e[6]=h,e[7]=b):b=e[7];let v;e[8]!==j||e[9]!==u||e[10]!==a||e[11]!==c||e[12]!==d||e[13]!==o||e[14]!==x?(v=j?s.jsxs(jn,{children:[s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx(wn,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":x("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(T,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(ht,{side:"top",sideOffset:4,children:s.jsx("p",{children:x("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(Sn,{align:"end",className:"min-w-[180px]",children:[o.length===0?s.jsx(Xt,{disabled:!0,className:"text-muted-foreground",children:x("sessions.sidebar.folders.none")}):o.map(y=>s.jsx(Xt,{onClick:()=>c(y.id),children:s.jsx("span",{className:"flex-1 truncate",children:y.name})},y.id)),s.jsx(vn,{}),s.jsxs(Xt,{onClick:a,children:[s.jsx(T,{name:"add",className:"mr-1 h-4 w-4"}),x("sessions.sidebar.folders.newFolderEllipsis")]}),u?s.jsxs(Xt,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(T,{name:"close",className:"mr-1 h-4 w-4"}),x("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=j,e[9]=u,e[10]=a,e[11]=c,e[12]=d,e[13]=o,e[14]=x,e[15]=v):v=e[15];let S;e[16]!==i||e[17]!==m||e[18]!==x?(S=i?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":x("sessions.sidebar.bulkActions.restore"),children:s.jsx(T,{name:"inbox-unarchive",className:"h-4 w-4"})})}),s.jsx(ht,{side:"top",sideOffset:4,children:s.jsx("p",{children:x("sessions.sidebar.bulkActions.restore")})})]}):null,e[16]=i,e[17]=m,e[18]=x,e[19]=S):S=e[19];let N;e[20]===Symbol.for("react.memo_cache_sentinel")?(N=ge("inline-flex h-7 w-7 items-center justify-center rounded-md text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50"),e[20]=N):N=e[20];let A;e[21]===Symbol.for("react.memo_cache_sentinel")?(A=s.jsx(T,{name:"delete-bin",className:"h-4 w-4"}),e[21]=A):A=e[21];let k;e[22]!==p||e[23]!==f?(k=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:f,className:N,"aria-label":p,children:A})}),e[22]=p,e[23]=f,e[24]=k):k=e[24];let C;e[25]!==p?(C=s.jsx(ht,{side:"top",sideOffset:4,children:s.jsx("p",{children:p})}),e[25]=p,e[26]=C):C=e[26];let P;e[27]!==k||e[28]!==C?(P=s.jsxs(ft,{children:[k,C]}),e[27]=k,e[28]=C,e[29]=P):P=e[29];let D;e[30]!==x?(D=x("sessions.sidebar.header.actions.exitSelection"),e[30]=x,e[31]=D):D=e[31];let O;e[32]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(T,{name:"close",className:"h-4 w-4"}),e[32]=O):O=e[32];let F;e[33]!==g||e[34]!==D?(F=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:g,className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":D,children:O})}),e[33]=g,e[34]=D,e[35]=F):F=e[35];let E;e[36]!==x?(E=x("sessions.sidebar.header.actions.exitSelection"),e[36]=x,e[37]=E):E=e[37];let B;e[38]!==E?(B=s.jsx(ht,{side:"top",sideOffset:4,children:s.jsx("p",{children:E})}),e[38]=E,e[39]=B):B=e[39];let $;e[40]!==F||e[41]!==B?($=s.jsxs(ft,{children:[F,B]}),e[40]=F,e[41]=B,e[42]=$):$=e[42];let z;e[43]!==P||e[44]!==$||e[45]!==v||e[46]!==S?(z=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[v,S,P,$]}),e[43]=P,e[44]=$,e[45]=v,e[46]=S,e[47]=z):z=e[47];let V;return e[48]!==z||e[49]!==b?(V=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[b,z]}),e[48]=z,e[49]=b,e[50]=V):V=e[50],V},c2=t=>{const{t:e}=gt(),{isInlineEditing:n,showDeletionDialog:r,foldersMap:o,folderScopesByProject:i,addSessionsToFolder:c,removeSessionsFromFolders:a,createFolderAndStartRename:d,archiveSessions:u,unarchiveSessions:m,deleteSessions:f,setBulkDeleteConfirm:g}=t,x=As(y=>y.enabled),j=As(y=>y.selectedIds.size),w=j>0,p=As(y=>y.selectedIds),h=As(y=>y.scopeKey),b=l.useCallback(()=>{As.getState().toggleMode()},[]),v=l.useCallback(()=>{As.getState().disable()},[]),S=l.useMemo(()=>{if(!w||typeof document>"u")return!1;let y=!1,I=!1;for(const _ of p){const W=document.querySelectorAll(`[data-session-row="${CSS.escape(_)}"]`);for(const K of W)K.getAttribute("data-session-archived")==="1"?I=!0:y=!0}return I&&!y},[w,p]),N=l.useMemo(()=>{if(h)return h;if(!w||typeof document>"u")return null;for(const y of p){const _=document.querySelector(`[data-session-row="${CSS.escape(y)}"]`)?.getAttribute("data-session-scope");if(_&&_.length>0)return _}return null},[w,p,h]),A=l.useMemo(()=>{if(!N)return[];const y=i.get(N);return y&&y.length>0?y.map(I=>I.scopeKey):[N]},[N,i]),k=l.useMemo(()=>A.flatMap(y=>o[y]??[]),[o,A]),C=l.useCallback(y=>{for(const I of A)if((o[I]??[]).some(_=>_.id===y))return I;return null},[o,A]),P=l.useMemo(()=>{if(!w)return!1;for(const y of A)for(const I of o[y]??[])for(const _ of I.sessionIds)if(p.has(_))return!0;return!1},[o,A,w,p]),D=l.useCallback((y,I)=>{const _=Array.from(p);for(const W of A)W!==y&&a(W,_);c(y,I,_)},[c,a,p,A]),O=l.useCallback(y=>{if(!w)return;const I=C(y);I&&D(I,y)},[w,D,C]),F=l.useCallback(()=>{const y=A[0];if(!y||!w)return;const I=d(y);I&&D(y,I.id)},[d,w,D,A]),E=l.useCallback(()=>{if(!w)return;const y=Array.from(p);for(const I of A)a(I,y)},[a,p,A,w]),B=l.useCallback(async()=>{const y=Array.from(p);if(y.length!==0){if(S){const{deletedIds:I,failedIds:_}=await f(y);I.length>0&&Ae.success(I.length===1?e("sessions.sidebar.bulkActions.deletedSingle",{count:I.length}):e("sessions.sidebar.bulkActions.deletedPlural",{count:I.length})),_.length>0&&Ae.error(_.length===1?e("sessions.sidebar.bulkActions.failedDeleteSingle",{count:_.length}):e("sessions.sidebar.bulkActions.failedDeletePlural",{count:_.length}))}else{const{archivedIds:I,failedIds:_}=await u(y);I.length>0&&Ae.success(I.length===1?e("sessions.sidebar.bulkActions.archivedSingle",{count:I.length}):e("sessions.sidebar.bulkActions.archivedPlural",{count:I.length})),_.length>0&&Ae.error(_.length===1?e("sessions.sidebar.bulkActions.failedArchiveSingle",{count:_.length}):e("sessions.sidebar.bulkActions.failedArchivePlural",{count:_.length}))}As.getState().clear()}},[u,S,f,p,e]),$=l.useCallback(()=>{if(!w)return;const y=p.size;if(!r){B();return}g({sessionCount:y,archivedBucket:S})},[S,B,p,r,g,w]),z=l.useCallback(async()=>{if(!w||!S)return;const y=Array.from(p),{restoredIds:I,failedIds:_}=await m(y);I.length>0&&Ae.success(I.length===1?e("sessions.sidebar.bulkActions.restoredSingle",{count:I.length}):e("sessions.sidebar.bulkActions.restoredPlural",{count:I.length})),_.length>0&&Ae.error(_.length===1?e("sessions.sidebar.bulkActions.failedRestoreSingle",{count:_.length}):e("sessions.sidebar.bulkActions.failedRestorePlural",{count:_.length})),As.getState().clear()},[S,w,p,e,m]),V=l.useCallback(async()=>{g(null),await B()},[B]);return l.useEffect(()=>{if(!x)return;const y=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),I=_=>{if(n)return;const W=_.target;if(W&&(W.tagName==="INPUT"||W.tagName==="TEXTAREA"||W.isContentEditable))return;const K=y?_.metaKey:_.ctrlKey;if(_.key==="Escape"){_.preventDefault(),As.getState().disable();return}if(K&&_.key==="Backspace"){_.preventDefault(),$();return}if(K&&(_.key==="a"||_.key==="A")){const Z=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(Z.length===0)return;_.preventDefault();const le=As.getState().scopeKey??Z[0]?.getAttribute("data-session-scope")??null,te=xe=>le?xe.getAttribute("data-session-scope")===le:!0,he=Z.filter(te).map(xe=>xe.getAttribute("data-session-row")).filter(xe=>typeof xe=="string"&&xe.length>0);if(he.length===0)return;As.getState().replaceAll(he,le||null)}};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[$,n,x]),{selectionModeEnabled:x,hasSelection:w,selectedIdsSize:j,bulkScopeIsArchived:S,derivedSelectionScope:N,bulkScopeFolders:k,bulkCanRemoveFromFolder:P,handleToggleSelectionMode:b,handleExitSelectionMode:v,handleBulkMoveToFolder:O,handleBulkCreateFolderAndMove:F,handleBulkRemoveFromFolder:E,handleBulkDelete:$,handleBulkRestore:z,confirmBulkDelete:V}},d2=2880*60*1e3,u2=t=>!!t.parentID,f2=t=>!!t.time?.archived,m2=t=>{const e=t.time?.updated,n=t.time?.created;return typeof e=="number"&&Number.isFinite(e)?e:typeof n=="number"&&Number.isFinite(n)?n:0},h2=(t,e,n=Date.now())=>{const r=n-d2;return t.filter(o=>f2(o)||u2(o)?!1:e.has(o.id)||m2(o)>=r)},Sd={selected:0,"active-project":1,expanded:2,visible:3,background:4};function p2(t){const e=new Map,n=(r,o,i)=>{const c=jt(r??null);if(!c)return;const a=e.get(c);a&&Sd[a.priority]<=Sd[o]||e.set(c,{directory:c,priority:o,reason:i})};for(const r of t.projectSections){const o=!t.collapsedProjects.has(r.project.id);let i="background";r.project.id===t.activeProjectId?i="active-project":o&&(i="expanded"),n(r.project.normalizedPath,i,o?"project-expanded":"known-project");for(const c of r.groups){if(!c.directory||c.isArchivedBucket||c.isMain)continue;const a=o&&!t.collapsedGroups.has(`${r.project.id}:${c.id}`);let d="background";a?d="expanded":o&&(d="visible"),n(c.directory,d,a?"worktree-expanded":"known-worktree")}}return n(t.currentDirectory,"selected","current-directory"),n(t.currentSessionDirectory,"selected","selected-session"),[...e.values()]}const ni="oc.sessions.projectCollapse",jd="oc.sessions.groupOrder",kd="oc.sessions.groupCollapse",Cd="oc.sessions.activeSessionByProject",Nd="oc.sessions.expandedParents.v3",g2=(t,e,n)=>{const r=new Set;for(const o of t){const i=jt(o.path)?.toLowerCase();i&&r.add(i)}if(n?.includeWorktrees===!1)return r;for(const o of e.values())for(const i of o){const c=jt(i.path)?.toLowerCase();c&&r.add(c)}return r},x2=(t,e,n)=>{if(t.time?.archived)return!0;const r=jt(Qs(t))?.toLowerCase();return r?e.size===0?n?.allowEmptyDirectorySet??!0:e.has(r):n?.allowUnknownDirectory??!0},b2=5*6e4,y2=new Set,Ca=[],bn=t=>{const e=l.useRef(t);return e.current=t,l.useCallback((...n)=>e.current(...n),[])},v2=t=>{const e=it.c(14),{owner:n,childStores:r,projectSections:o,activeProjectId:i,collapsedProjects:c,collapsedGroups:a,currentDirectory:d}=t,u=ot(j2);let m,f;e[0]!==i||e[1]!==r||e[2]!==a||e[3]!==c||e[4]!==d||e[5]!==u||e[6]!==n||e[7]!==o?(m=()=>{r.setBootstrapDemand(n,p2({projectSections:o,activeProjectId:i,collapsedProjects:c,collapsedGroups:a,currentDirectory:d,currentSessionDirectory:u}))},f=[i,r,a,c,d,u,n,o],e[0]=i,e[1]=r,e[2]=a,e[3]=c,e[4]=d,e[5]=u,e[6]=n,e[7]=o,e[8]=m,e[9]=f):(m=e[8],f=e[9]),l.useEffect(m,f);let g,x;return e[10]!==r||e[11]!==n?(g=()=>()=>r.clearBootstrapDemand(n),x=[r,n],e[10]=r,e[11]=n,e[12]=g,e[13]=x):(g=e[12],x=e[13]),l.useEffect(g,x),null},w2=t=>{const e=it.c(20),{directories:n}=t,{t:r}=gt();let o;e[0]!==n?(o=new Set,n.forEach(m=>{const f=jt(m)?.toLowerCase();f&&o.add(f)}),e[0]=n,e[1]=o):o=e[1];const i=o;let c;e[2]!==i?(c=m=>{for(const f of m.statusById.values()){if(f.status.type!=="busy"&&f.status.type!=="retry")continue;const g=jt(f.directory)?.toLowerCase();if(g&&i.has(g))return!0}return!1},e[2]=i,e[3]=c):c=e[3];const a=Hi(c);let d;e[4]!==i?(d=m=>{for(const[f,g]of Object.entries(m.index.project.unseenCount)){if(!g)continue;const x=jt(f)?.toLowerCase();if(x&&i.has(x))return!0}return!1},e[4]=i,e[5]=d):d=e[5];const u=Ki(d);if(a){let m;e[6]!==r?(m=r("sessions.sidebar.session.status.active"),e[6]=r,e[7]=m):m=e[7];let f;e[8]!==r?(f=r("sessions.sidebar.session.status.active"),e[8]=r,e[9]=f):f=e[9];let g;return e[10]!==m||e[11]!==f?(g=s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary","aria-label":m,title:f}),e[10]=m,e[11]=f,e[12]=g):g=e[12],g}if(u){let m;e[13]!==r?(m=r("sessions.sidebar.session.status.unread"),e[13]=r,e[14]=m):m=e[14];let f;e[15]!==r?(f=r("sessions.sidebar.session.status.unread"),e[15]=r,e[16]=f):f=e[16];let g;return e[17]!==m||e[18]!==f?(g=s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--status-info)]","aria-label":m,title:f}),e[17]=m,e[18]=f,e[19]=g):g=e[19],g}return null},S2=({isVisible:t=!0,mobileVariant:e=!1,onSessionSelected:n,allowReselect:r=!1,hideDirectoryControls:o=!1,showOnlyMainWorkspace:i=!1})=>{Ea("react.session_sidebar_render"),In("ui.session_sidebar.render"),In(`ui.session_sidebar.render.${e?"mobile":"desktop"}`),In(`ui.session_sidebar.render.${t?"visible":"hidden"}`);const{t:c}=gt(),[a,d]=l.useState(!1),[u,m]=l.useState(""),f=l.useRef(null),g=l.useRef(null),[x,j]=l.useState(null),[w,p]=l.useState(""),[h,b]=l.useState(null),[v,S]=l.useState(new Set),N=l.useMemo(()=>Hr(),[]),[A,k]=l.useState(new Set),[C,P]=l.useState(new Map),[D,O]=l.useState(new Map),F=pe(L=>L.isNewWorktreeDialogOpen),E=pe(L=>L.setNewWorktreeDialogOpen),[B,$]=l.useState(!1),[z,V]=l.useState(null),[y,I]=l.useState(null),[_,W]=l.useState(""),[K,Z]=l.useState(null),[Q,le]=l.useState(null),[te,he]=l.useState(null),xe=No(L=>L.ids),H=Vi(l.useCallback(L=>t?L.rankById:hl,[t])),we=Hi(Jn(L=>t?[...L.statusById.keys()].sort():Ca)),de=l.useMemo(()=>new Set(we),[we]),q=Ki(Jn(L=>t?Object.entries(L.index.session.unseenCount).filter(([,Ge])=>Ge>0).map(([Ge])=>Ge).sort():Ca)),me=l.useMemo(()=>new Set(q),[q]),be=No(L=>L.toggle),[Pe,Ie]=l.useState(()=>{try{const L=Hr().getItem(kd);if(!L)return new Set;const Ge=JSON.parse(L);return new Set(Array.isArray(Ge)?Ge.filter(Ue=>typeof Ue=="string"):[])}catch{return new Set}}),[De,Le]=l.useState(()=>{try{const L=Hr().getItem(jd);if(!L)return new Map;const Ge=JSON.parse(L),Ue=new Map;return Object.entries(Ge).forEach(([dt,Mt])=>{Array.isArray(Mt)&&Ue.set(dt,Mt.filter(Qt=>typeof Qt=="string"))}),Ue}catch{return new Map}}),Ne=l.useMemo(()=>{try{const L=Hr().getItem(Cd);if(!L)return new Map;const Ge=JSON.parse(L),Ue=new Map;return Object.entries(Ge).forEach(([dt,Mt])=>{typeof Mt=="string"&&Mt.length>0&&Ue.set(dt,Mt)}),Ue}catch{return new Map}},[]),ve=l.useCallback(L=>{try{N.setItem(Cd,JSON.stringify(Object.fromEntries(L.entries())))}catch{}},[N]),[Me,ee]=l.useState(new Map),oe=l.useRef(new Map),Te=l.useRef(0),J=ls(L=>L.homeDirectory),re=ls(L=>L.currentDirectory),Y=Gt(L=>L.projects),U=Gt(L=>L.activeProjectId),fe=Gt(L=>L.removeProject),ne=Gt(L=>L.setActiveProjectIdOnly),ce=Gt(L=>L.updateProjectMeta),Fe=Gt(L=>L.reorderProjects),Ye=pe(L=>L.setActiveMainTab),$e=pe(L=>L.openContextPanelTab),ie=pe(L=>L.setSettingsDialogOpen),Re=pe(L=>L.toggleHelpDialog),ue=pe(L=>L.setAboutDialogOpen),R=pe(L=>L.setSessionSwitcherOpen),ae=pe(L=>L.setScheduledTasksDialogOpen),Se=pe(L=>L.setArchivePageOpen),Ce=pe(L=>L.setWorktreesPageProjectId),Ee=pe(L=>L.openMultiRunLauncher),se=pe(L=>L.notifyOnSubtasks),je=pe(L=>L.showDeletionDialog),Ze=pe(L=>L.setShowDeletionDialog),X=ml(u,120),ye=l.useMemo(()=>X.trim().toLowerCase(),[X]),Xe=ye.length>0,Be=Vs(L=>L.collapsedFolderIds),We=Vs(L=>L.foldersMap),_e=Vs(L=>L.getFoldersForScope),tt=Vs(L=>L.createFolder),ct=Vs(L=>L.renameFolder),Et=Vs(L=>L.deleteFolder),Nt=Vs(L=>L.addSessionToFolder),Ot=Vs(L=>L.addSessionsToFolder),et=Vs(L=>L.removeSessionFromFolder),Tt=Vs(L=>L.removeSessionsFromFolders),xt=Vs(L=>L.toggleFolderCollapse),vt=Vs(L=>L.getSessionFolderId);KS({enabled:t,isSessionSearchOpen:a,setIsSessionSearchOpen:d,sessionSearchInputRef:g,sessionSearchContainerRef:f});const _t=Nu(t),Ct=_i(),Rt=Tu(),ut=`session-sidebar:${l.useId()}`,bt=kp(),He=l.useMemo(()=>Array.from(bt.values()),[bt]),Ve=l.useMemo(()=>nr(),[]),wt=Fs(L=>L.status==="ready"),Ft=Fs(Jn(L=>L.activeSessions.map(ua).sort())),Lt=Fs(Jn(L=>L.archivedSessions.map(ua).sort())),ns=Fs.getState(),$t=ns.activeSessions,At=ns.archivedSessions,ss=l.useRef({signature:"",sessions:[]}),ms=l.useMemo(()=>new Set($t.map(L=>L.id)),[$t]),zt=(()=>{const L=He.filter(Ue=>!ms.has(Ue.id)),Ge=L.map(ua).sort().join(`
914
+ `);return ss.current.signature===Ge?ss.current.sessions:(ss.current={signature:Ge,sessions:L},L)})(),qt=ot(L=>L.setCurrentSession),Ut=ot(L=>L.updateSessionTitle),Jt=ot(L=>L.shareSession),Oe=ot(L=>L.unshareSession),st=ot(L=>L.worktreeMetadata),Ke=ot(L=>L.availableWorktreesByProject),Je=ot(L=>L.openNewSessionDraft),Qe=l.useCallback(L=>{pe.getState().closeMainSurfaces(),Je(L),Ve&&window.dispatchEvent(new CustomEvent("openchamber:navigate",{detail:{view:"chat"}}))},[Ve,Je]),kt=wo(Jn(L=>({checkForUpdates:L.checkForUpdates,available:L.available,runtimeType:L.runtimeType,info:L.info,downloading:L.downloading,downloaded:L.downloaded,progress:L.progress,error:L.error,downloadUpdate:L.downloadUpdate,restartToUpdate:L.restartToUpdate}))),ts=l.useMemo(()=>g2(Y,Ke,{includeWorktrees:!Ve}),[Ke,Ve,Y]),Wt=l.useMemo(()=>{const L=[...$t],Ge=new Set(L.map(Ue=>Ue.id));return zt.forEach(Ue=>{Ge.has(Ue.id)||L.push(Ue)}),L.filter(Ue=>x2(Ue,ts,{allowUnknownDirectory:!Ve,allowEmptyDirectorySet:!Ve}))},[$t,Ve,ts,zt]),us=l.useMemo(()=>[...$t,...At],[At,$t]),Bt=l.useRef(He);l.useEffect(()=>{Bt.current=He},[He]);const Vt=Ps(),js=l.useMemo(()=>`${Vt}|${Y.map(L=>`${L.id}:${jt(L.path)??""}`).join("|")}`,[Y,Vt]),[ln,Rn]=l.useState(Ve?js:null),[Hn,cn]=l.useReducer(L=>L+1,0),Cn=!Ve&&ln!==js,[Ts,Xs]=l.useState(new Set),Kn=l.useRef(!1);l.useEffect(()=>{Kn.current||(Kn.current=!0,vi(Bt.current))},[]),l.useEffect(()=>{let L=!1;return(async()=>{const Ue=Vt,dt=Gt.getState().projects;if(dt.length===0||Ve){L||(Xs(new Set),Rn(js));return}const Mt=ot.getState().availableWorktreesByProject,Qt=new Map(Mt),Ws=new Set,xs=3;let Yn=0;const Ln=Array.from({length:xs},async()=>{for(;;){const hn=Yn;if(Yn+=1,hn>=dt.length)return;const Kl=dt[hn],lr=jt(Kl.path);if(lr)try{const la=await Oa(async()=>pr.getState().directories.get(lr)?.isGitRepo??await Fu(lr)?Ap({id:Kl.id,path:lr}):null);if(la===null){Qt.delete(lr);continue}if(L)return;la.length===0?Qt.delete(lr):Qt.set(lr,la)}catch{Ws.add(lr)}}});if(await Promise.all(Ln),L||Ps()!==Ue)return;const Ur=new Set(dt.map(hn=>jt(hn.path)).filter(Boolean));for(const hn of Qt.keys())Ur.has(hn)||Qt.delete(hn);const ar=Dp(dt,Qt),Uo=[...ar.values()].flat();VS(Uo.map(hn=>hn.path),Date.now()),Pp(ar,Mt)||ot.setState({availableWorktrees:Uo,availableWorktreesByProject:ar}),Xs(Ws),Rn(js)})(),()=>{L=!0}},[Ve,js,Vt,Hn]),l.useEffect(()=>{let L=null,Ge=!1;const Ue=new Set,dt=Yi(Mt=>{if(Mt.type==="scheduled-task-ran")Ge=!0;else if(Mt.type==="session-created")Ue.add(Mt.directory),cn();else return;L&&clearTimeout(L),L=setTimeout(()=>{if(L=null,Ge){Ge=!1,Ue.clear(),vi(Bt.current);return}const Qt=[...Ue];Ue.clear(),Qt.length>0&&ai(Qt,Bt.current)},500)});return()=>{L&&clearTimeout(L),dt()}},[]);const Is=l.useMemo(()=>Wn(),[]),{isTablet:_s}=xr(),$s=e||_s,{buildGroupSearchText:zs,filterSessionNodesForSearch:Us,buildGroupedSessions:Gn}=HS({homeDirectory:J,worktreeMetadata:st,pinnedSessionIds:xe,sessionOrderRanks:H,gitBranches:_t,isVSCode:Ve}),{scheduleCollapsedProjectsPersist:Nn}=JS({isVSCode:Ve,safeStorage:N,keys:{sessionExpanded:Nd,projectCollapse:ni,groupOrder:jd,groupCollapse:kd},groupOrderByProject:De,collapsedGroups:Pe,setExpandedParents:S,setCollapsedProjects:k}),Rs=l.useMemo(()=>Cu(Wt,xe,H),[xe,H,Wt]),or=l.useMemo(()=>Rs.map(L=>L.id).join("|"),[Rs]),G=l.useRef(null),qe=l.useMemo(()=>{const L=G.current;if(L&&L.signature===or)return L.map;const Ge=new Map(Rs.map((Ue,dt)=>[Ue.id,dt]));return G.current={signature:or,map:Ge},Ge},[Rs,or]),at=l.useMemo(()=>{const L=new Map;return Rs.forEach(Ge=>{const Ue=Ge.parentID;if(!Ue)return;const dt=L.get(Ue)??[];dt.push(Ge),L.set(Ue,dt)}),L.forEach(Ge=>Ge.sort((Ue,dt)=>so(Ue,dt,xe,H))),L},[Rs,xe,H]),pt=l.useMemo(()=>s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:c("sessions.sidebar.empty.noSessions.title")}),s.jsx("p",{className:"typography-meta mt-1",children:c("sessions.sidebar.empty.noSessions.description")})]}),[c]),It=l.useMemo(()=>Y.find(L=>L.id===h)??null,[Y,h]),Dt=l.useCallback(L=>{h&&ce(h,{label:L.label,icon:L.icon,color:L.color,iconBackground:L.iconBackground,defaultModel:L.defaultModel??null})},[h,ce]),yt=l.useCallback(()=>{E(!0)},[E]),cs=l.useCallback(()=>{const L=wo.getState();if(L.available&&L.info){$(!0);return}kt.checkForUpdates().then(()=>{const{available:Ge,error:Ue}=wo.getState();if(Ue){Ae.error(c("sessions.sidebar.updateCheck.errorTitle"),{description:Ue});return}if(!Ge){Ae.success(c("sessions.sidebar.updateCheck.latestVersion"));return}$(!0)})},[c,kt]),ws=l.useCallback(()=>{e&&R(!1),ie(!0)},[e,R,ie]),Zt=kt.available&&(kt.runtimeType==="desktop"||kt.runtimeType==="web"),ks=ot(L=>L.deleteSession),Ms=ot(L=>L.deleteSessions),Mn=ot(L=>L.archiveSession),Ss=ot(L=>L.archiveSessions),An=ot(L=>L.unarchiveSession),yr=ot(L=>L.unarchiveSessions),{copiedSessionId:vr,handleSessionSelect:wr,handleSessionDoubleClick:ke,handleSaveEdit:Pt,handleCancelEdit:Yt,handleShareSession:os,handleCopyShareUrl:bs,handleCopySessionId:fs,handleUnshareSession:dn,handleDeleteSession:Cs,handleRestoreSession:Js,confirmDeleteSession:Sr}=GS({mobileVariant:e,allowReselect:r,onSessionSelected:n,isSessionSearchOpen:a,sessionSearchQuery:u,setSessionSearchQuery:m,setIsSessionSearchOpen:d,setActiveMainTab:Ye,setSessionSwitcherOpen:R,setCurrentSession:qt,updateSessionTitle:Ut,shareSession:Jt,unshareSession:Oe,deleteSession:ks,deleteSessions:Ms,archiveSession:Mn,archiveSessions:Ss,unarchiveSession:An,childrenMap:at,showDeletionDialog:je,setDeleteSessionConfirm:Z,deleteSessionConfirm:K,setEditingId:j,setEditTitle:p,editingId:x,editTitle:w}),ys=l.useCallback(()=>{if(!Q)return;const{scopeKey:L,folderId:Ge}=Q;le(null),Et(L,Ge)},[Q,Et]),hs=l.useCallback(()=>{Un.requestDirectoryDialog()},[]),Dn=l.useCallback(L=>{S(Ge=>{const Ue=Cp(Ge,L);try{N.setItem(Nd,JSON.stringify(Array.from(Ue)))}catch{}return Ue})},[N]),jr=l.useCallback((L,Ge)=>{if(!L)return null;Ge&&Be.has(Ge)&&xt(Ge);const Ue=tt(L,c("sessions.sidebar.folder.newFolderName"),Ge);return I(Ue.id),W(Ue.name),Ue},[Be,xt,tt,c]),kr=bn(wr),oo=bn(ke),Qi=bn(Pt),Xi=bn(Yt),Oo=bn(os),Ji=bn(bs),Zi=bn(fs),Fo=bn(dn),ea=bn(Cs),Cr=bn(Js),io=bn(jr),qn=l.useCallback((L,Ge)=>{O(Ue=>{const dt=new Map(Ue);return dt.set(L,Ge+7),dt})},[]),$r=l.useCallback(L=>{O(Ge=>{if(!Ge.has(L))return Ge;const Ue=new Map(Ge);return Ue.delete(L),Ue})},[]),ao=l.useCallback(L=>{O(Ge=>{let Ue=!1;const dt=new Map(Ge),Mt=`${L}:`;for(const Qt of dt.keys())Qt.startsWith(Mt)&&(dt.delete(Qt),Ue=!0);return Ue?dt:Ge})},[]),Lo=l.useRef([]),ta=l.useCallback(()=>{Te.current=Date.now()+150,O(new Map),Ie(()=>{const L=new Set;return Lo.current.forEach(Ge=>{Ge.groups.forEach(Ue=>{Ue.isMain||L.add(`${Ge.project.id}:${Ue.id}`)})}),L}),k(()=>{const L=new Set(Y.map(Ge=>Ge.id));try{N.setItem(ni,JSON.stringify(Array.from(L)))}catch{}return Ve||Nn(L),L})},[Y,Ve,N,Nn]),sa=l.useCallback(()=>{Te.current=Date.now()+150,O(new Map),Ie(new Set),k(()=>{const L=new Set;try{N.setItem(ni,JSON.stringify([]))}catch{}return Ve||Nn(L),L})},[Ve,N,Nn]),Bo=l.useCallback(L=>{Te.current=Date.now()+150,ao(L),k(Ge=>{const Ue=new Set(Ge);Ue.has(L)?Ue.delete(L):Ue.add(L);try{N.setItem(ni,JSON.stringify(Array.from(Ue)))}catch{}return Ve||Nn(Ue),Ue})},[Ve,ao,N,Nn]),un=l.useMemo(()=>Y.map(L=>({...L,normalizedPath:jt(L.path)})).filter(L=>!!L.normalizedPath),[Y]),na=l.useMemo(()=>un.map(L=>L.normalizedPath),[un]),Nr=l.useMemo(()=>{const L=new Set(un.map(Ge=>Ge.normalizedPath));if(!Ve)for(const Ge of Ke.values())for(const Ue of Ge){const dt=jt(Ue.path);dt&&L.add(dt)}return[...L].sort()},[Ke,Ve,un]),M=l.useRef(null);l.useEffect(()=>{const L=new Set(Nr),Ge=M.current;if(M.current=L,!Ge){Ve&&Nr.length>0&&ai(Nr,Bt.current);return}const Ue=Nr.filter(dt=>!Ge.has(dt));Ue.length!==0&&ai(Ue,Bt.current)},[Ve,Nr]);const{github:ze}=rr(),rt=Br(L=>L.status),St=Br(L=>L.hasChecked),Ht=Np(t?na:Ca),as=tn(L=>L.ensureEntry),rs=tn(L=>L.setParams),vs=tn(L=>L.refreshTargets);n0({enabled:t,normalizedProjects:un,gitRepoStatus:Ht,setProjectRepoStatus:P,setProjectRootBranches:ee});const Ar=ot(L=>L.isLoading),zr=l.useMemo(()=>p0(Wt,un,Ke,Ve,At),[At,Ke,Ve,un,Wt]);u0({enabled:t,hasAuthoritativeGlobalSessions:wt,sessions:us});const{getSessionsForProject:ra,getArchivedSessionsForProject:oa}=l0({ownership:zr});RS({enabled:t,normalizedProjects:un,ownership:zr,isSessionsLoading:Ar,hasAuthoritativeGlobalSessions:wt,isWorktreeTopologyLoading:Cn,unresolvedWorktreeProjectPaths:Ts,foldersMap:We,createFolder:tt,addSessionToFolder:Nt});const lo=l.useRef(!1);U&&C.has(U)&&(lo.current=!!C.get(U));const On=Ds(L=>L.showRecentSection),fn=Ds(L=>L.showArchivedSessions),Pn=Ds(L=>L.projectSortOrder),ir=Ds(L=>L.stickyZoneHeaders),Fn=Gt(L=>L.manualProjectOrder),Dr=l.useRef(new Set),co=l.useRef(new Set),Pr=dc(Dr.current,v,"project"),_o=dc(co.current,v,"recent");Dr.current=Pr,co.current=_o;const ia={isVisible:t,mobileVariant:e,onSessionSelected:n,allowReselect:r,hideDirectoryControls:o,showOnlyMainWorkspace:i,t:c,isTablet:_s,liveSessions:He,activeSessionStructure:Ft,archivedSessionStructure:Lt,globalActiveSessions:$t,archivedSessions:At,projects:Y,activeProjectId:U,manualProjectOrder:Fn,currentDirectory:re,worktreeMetadata:st,availableWorktreesByProject:Ke,pinnedSessionIds:xe,sessionOrderRanks:H,foldersMap:We,collapsedFolderIds:Be,gitBranches:_t,gitRepoStatus:Ht,githubAuthStatus:rt,githubAuthChecked:St,updateStore:kt,showRecentSection:On,showArchivedSessions:fn,projectSortOrder:Pn,projectRepoStatus:C,projectRootBranches:Me,resolvedWorktreeTopologyKey:ln,unresolvedWorktreeProjectPaths:Ts,isSessionSearchOpen:a,sessionSearchQuery:u,editingId:x,editTitle:w,editingProjectDialogId:h,expandedParents:v,collapsedProjects:A,visibleSessionCountByGroup:D,updateDialogOpen:B,openSidebarMenuKey:z,renamingFolderId:y,renameFolderDraft:_,deleteSessionConfirm:K,deleteFolderConfirm:Q,bulkDeleteConfirm:te,collapsedGroups:Pe},Ml=l.useRef(null),Ol=Ml.current;if(Ol){let L=!1;for(const Ge of Object.keys(ia))Object.is(Ol[Ge],ia[Ge])||(In(`ui.session_sidebar.source.${Ge}`),L=!0);L||In("ui.session_sidebar.source.parent_or_context")}Ml.current=ia;const rm=l.useMemo(()=>{const L=[...un];switch(Pn){case"a-z":L.sort((Ge,Ue)=>{const dt=(Ge.label||Ge.path).toLowerCase(),Mt=(Ue.label||Ue.path).toLowerCase();return dt.localeCompare(Mt)});break;case"z-a":L.sort((Ge,Ue)=>{const dt=(Ge.label||Ge.path).toLowerCase();return(Ue.label||Ue.path).toLowerCase().localeCompare(dt)});break;case"date-added":L.sort((Ge,Ue)=>(Ue.addedAt??0)-(Ge.addedAt??0));break;case"recent":L.sort((Ge,Ue)=>(Ue.lastOpenedAt??0)-(Ge.lastOpenedAt??0));break;case"manual":{const Ge=new Map(Fn.map((Ue,dt)=>[Ue,dt]));L.sort((Ue,dt)=>{const Mt=Ge.get(Ue.id)??1/0,Qt=Ge.get(dt.id)??1/0;return Mt-Qt});break}}return L},[un,Pn,Fn]),{projectSections:mn,groupSearchDataByGroup:Fl,sectionsForRender:Ll,flatSectionsForRender:$o,searchMatchCount:om}=BS({normalizedProjects:rm,getSessionsForProject:ra,getArchivedSessionsForProject:oa,availableWorktreesByProject:Ke,projectRepoStatus:C,projectRootBranches:Me,lastRepoStatus:lo.current,buildGroupedSessions:Gn,hasSessionSearchQuery:Xe,normalizedSessionSearchQuery:ye,filterSessionNodesForSearch:Us,buildGroupSearchText:zs,foldersMap:We});Lo.current=mn;const im=l.useMemo(()=>s.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-ui-label font-semibold",children:c("sessions.sidebar.empty.noMatches.title")}),s.jsx("p",{className:"typography-meta mt-1",children:c("sessions.sidebar.empty.noMatches.description")})]}),[c]),{getOrderedGroups:am}=OS(De),Bl=l.useRef(!1);l.useEffect(()=>{if(Bl.current||mn.length===0)return;const L=mn.flatMap(Ge=>Ge.groups.filter(Ue=>Ue.isArchivedBucket).map(Ue=>`${Ge.project.id}:${Ue.id}`));L.length>0&&Ie(Ge=>new Set([...Ge,...L])),Bl.current=!0},[mn]);const _l=l.useMemo(()=>{const L=new Map,Ge=new Map;return mn.forEach(Ue=>{const dt=bl(Ue.project.label?.trim()||gr(Ue.project.normalizedPath,J)||Ue.project.normalizedPath);Ue.groups.forEach(Mt=>{const Qt=Mt.branch&&Mt.branch!=="HEAD"&&Mt.branch!==dt?Mt.branch:null,Ws={projectLabel:dt,branchLabel:Qt},xs=Yn=>{Yn.forEach(Ln=>{const Ur=Ue.project.normalizedPath.length,ar=Ge.get(Ln.session.id)??-1;Ur<ar||(L.set(Ln.session.id,{node:Ln,projectId:Ue.project.id,groupDirectory:Mt.directory,secondaryMeta:Ws}),Ge.set(Ln.session.id,Ur),Ln.children.length>0&&xs(Ln.children))})};xs(Mt.sessions)})}),L},[mn,J]),aa=l.useMemo(()=>!On||Ve?[]:h2(Wt,de).sort((L,Ge)=>so(L,Ge,xe,H)),[de,Ve,xe,H,Wt,On]),zo=l.useMemo(()=>{if(Ve||!On)return[];const L=Ue=>{const dt=_l.get(Ue.id),Mt=jt(Ue.directory??null),Qt=dt?.node??{session:Ue,children:[],worktree:null},xs=(Xe?Us([Qt],ye):[Qt])[0];if(!xs)return null;const Yn=dt?.secondaryMeta?{projectLabel:dt.secondaryMeta.projectLabel,branchLabel:Ve?null:dt.secondaryMeta.branchLabel}:null;return{node:xs,projectId:dt?.projectId??null,groupDirectory:dt?.groupDirectory??Mt,secondaryMeta:Yn}},Ge=aa.map(L).filter(Ue=>Ue!==null);return[{key:"active-now",title:c("sessions.sidebar.activity.recentTitle"),items:Ge}]},[Us,Xe,Ve,ye,aa,_l,On,c]),lm=l.useMemo(()=>zo.some(L=>L.items.length>0),[zo]),$l=Ve&&fn,zl=Ds(L=>L.sessionGroupingMode)==="by-worktree"&&!Ve,cm=l.useMemo(()=>{const L=zl?Ll:$o;return $l?L:L.map(Ge=>Ge.groups.some(Ue=>Ue.isArchivedBucket)?{...Ge,groups:Ge.groups.filter(Ue=>!Ue.isArchivedBucket)}:Ge)},[$o,Ll,$l,zl]),Ul=l.useRef(new Set);l.useEffect(()=>{if(!t||!St||!rt?.connected||!ze)return;const L=new Map,Ge=Date.now();mn.forEach(Ue=>{A.has(Ue.project.id)||Ue.groups.forEach(dt=>{if(dt.isArchivedBucket||dt.isMain)return;const Mt=jt(dt.directory??null),Qt=dt.branch?.trim()||_t.get(Mt||"")?.trim();if(!Mt||!Qt)return;const Ws=zi(Mt,Qt),xs=tn.getState().entries[Ws],Yn=xs?.status?.pr?.state,Ln=Yn==="closed"||Yn==="merged",Ur=!!xs?.status?.pr&&!Ln,ar=`${Mt}::${Qt}`,Uo=Math.max(xs?.lastRefreshAt??0,xs?.lastDiscoveryPollAt??0),hn=!!(xs?.isInitialStatusResolved&&!Ur&&(!Ul.current.has(ar)||Ge-Uo>=b2));(!xs||!xs.isInitialStatusResolved||hn)&&(hn&&Ul.current.add(ar),L.has(Ws)||L.set(Ws,{directory:Mt,branch:Qt}))})}),L.size!==0&&(L.forEach((Ue,dt)=>{as(dt),rs(dt,{directory:Ue.directory,branch:Ue.branch,remoteName:null,canShow:!0,github:ze,githubAuthChecked:St,githubConnected:rt.connected})}),vs([...L.values()],{silent:!0,markInitialResolved:!0}))},[A,as,ze,St,rt?.connected,t,_t,mn,vs,rs]);const dm=e?"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed":"inline-flex h-6 w-6 cursor-pointer items-center justify-center rounded-md leading-none text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 disabled:cursor-not-allowed",um="h-4.5 w-4.5",fm=g0({enabled:t&&ir,isDesktopShellRuntime:Is,projectSections:mn,projectHeaderSentinelRefs:oe}),uo=bn((L,Ge=0,Ue,dt,Mt=!1,Qt,Ws="project",xs)=>s.jsx(n2,{node:L,depth:Ge,groupDirectory:Ue,projectId:dt,archivedBucket:Mt,pinnedSessionIds:xe,expandedParents:Ws==="recent"?_o:Pr,hasSessionSearchQuery:Xe,normalizedSessionSearchQuery:ye,notifyOnSubtasks:se,editingId:x,setEditingId:j,editTitle:w,setEditTitle:p,handleSaveEdit:Qi,handleCancelEdit:Xi,toggleParent:Dn,handleSessionSelect:kr,handleSessionDoubleClick:oo,togglePinnedSession:be,handleShareSession:Oo,copiedSessionId:vr,handleCopyShareUrl:Ji,handleCopySessionId:Zi,handleUnshareSession:Fo,openSidebarMenuKey:z,setOpenSidebarMenuKey:V,renamingFolderId:y,getFoldersForScope:_e,getSessionFolderId:vt,removeSessionFromFolder:et,addSessionToFolder:Nt,createFolderAndStartRename:io,openContextPanelTab:$e,handleDeleteSession:ea,handleRestoreSession:Cr,mobileVariant:e,alwaysShowActions:$s,renderSessionNode:uo,secondaryMeta:Qt,renderContext:Ws,subtreeContainsEditing:xs?.subtreeContainsEditing??y2,menuOpenSessionId:xs?.menuOpenSessionId??null,nodeStructureKey:xs?.nodeStructureKey??"",childRenderExtrasFor:xs?.childRenderExtrasFor})),mm=l.useMemo(()=>{const L=new Map;return $o.forEach(Ge=>{const Ue=Ge.groups.find(dt=>!dt.isArchivedBucket);Ue?.folderScopes&&Ue.folderScopes.length>0&&L.set(Ge.project.id,Ue.folderScopes)}),L},[$o]),hm=l.useCallback((L,Ge)=>{const Ue=[];return Ge.forEach(dt=>{dt.isArchivedBucket||(Ue.push(dt.directory),dt.folderScopes?.forEach(Mt=>Ue.push(Mt.directory)))}),s.jsx(w2,{directories:Ue})},[]),Wl=l.useCallback(L=>{$r(L),Ie(Ge=>{const Ue=new Set(Ge);return Ue.has(L)?Ue.delete(L):Ue.add(L),Ue})},[$r]),pm=l.useCallback((L,Ge,Ue,dt,Mt,Qt,Ws)=>s.jsx(K0,{group:L,groupKey:Ge,projectId:Ue,hideGroupLabel:dt,dragHandleProps:Mt,compactBodyPadding:Qt,hasSessionSearchQuery:Xe,normalizedSessionSearchQuery:ye,groupSearchDataByGroup:Fl,visibleSessionCount:D.get(Ge),collapsedGroups:Pe,hideDirectoryControls:o,collapsedFolderIds:Be,toggleFolderCollapse:xt,renameFolder:ct,deleteFolder:Et,showDeletionDialog:je,setDeleteFolderConfirm:le,renderSessionNode:uo,showMoreGroupSessions:qn,resetGroupSessionLimit:$r,mobileVariant:e,alwaysShowActions:$s,activeProjectId:U,setActiveProjectIdOnly:ne,setActiveMainTab:Ye,setSessionSwitcherOpen:R,openNewSessionDraft:Qe,addSessionToFolder:Nt,createFolderAndStartRename:io,renamingFolderId:y,renameFolderDraft:_,setRenameFolderDraft:W,setRenamingFolderId:I,pinnedSessionIds:xe,expandedParents:Pr,sessionOrderIndex:qe,editingId:x,editTitle:w,openSidebarMenuKey:z,activeActivitySessionIds:de,unreadActivitySessionIds:me,notifyOnSubtasks:se,onToggleCollapsedGroup:Wl,scrollContainerRef:Ws}),[Xe,ye,Fl,D,Pe,o,Be,xt,ct,Et,je,uo,qn,$r,e,$s,U,ne,Ye,R,Qe,Nt,io,y,_,xe,Pr,qe,x,w,z,de,me,se,Wl]),gm=l.useMemo(()=>!Ve&&On&&!Xe?s.jsx(oj,{sections:zo,renderSessionNode:uo,editingId:x,openSidebarMenuKey:z,expansionState:_o,variant:"section",isDesktopShellRuntime:Is}):null,[zo,x,Xe,Is,Ve,z,_o,uo,On]),Vl=!!(y||x||h),{selectionModeEnabled:Hl,hasSelection:xm,selectedIdsSize:bm,bulkScopeIsArchived:ym,derivedSelectionScope:vm,bulkScopeFolders:wm,bulkCanRemoveFromFolder:Sm,handleToggleSelectionMode:jm,handleExitSelectionMode:km,handleBulkMoveToFolder:Cm,handleBulkCreateFolderAndMove:Nm,handleBulkRemoveFromFolder:Am,handleBulkDelete:Dm,handleBulkRestore:Pm,confirmBulkDelete:Em}=c2({isInlineEditing:Vl,showDeletionDialog:je,foldersMap:We,folderScopesByProject:mm,addSessionsToFolder:Ot,removeSessionsFromFolders:Tt,createFolderAndStartRename:jr,archiveSessions:Ss,unarchiveSessions:yr,deleteSessions:Ms,setBulkDeleteConfirm:he}),Tm=l.useCallback(()=>{Ye("chat"),e&&R(!1),Ee()},[e,Ee,Ye,R]),Im=l.useCallback(()=>{pe.getState().closeMainSurfaces(),Ye("chat"),e&&R(!1),Je()},[e,Je,Ye,R]);return s.jsx(La,{delay:0,closeDelay:150,timeout:600,children:s.jsxs("div",{ref:f,className:ge("relative flex h-full flex-col text-foreground overflow-x-hidden",e?"":"bg-transparent"),children:[s.jsx(v2,{owner:ut,childStores:Rt,projectSections:mn,activeProjectId:U,collapsedProjects:A,collapsedGroups:Pe,currentDirectory:re}),s.jsx(zS,{projectSections:mn,activeProjectId:U,initialActiveSessionByProject:Ne,persistActiveSessionByProject:ve,handleSessionSelect:kr,mobileVariant:e,openNewSessionDraft:Je,setActiveMainTab:Ye,setSessionSwitcherOpen:R,sessionOwnerBySessionId:zr.bySessionId}),s.jsx(TS,{enabled:t,sortedSessions:Rs,recentSessions:aa,prefetchSession:Ct.prefetchSession}),!o&&!Ve?s.jsx(rj,{onNewSession:Im}):null,s.jsx(q0,{hideDirectoryControls:o,showRecentControls:!Ve,handleOpenDirectoryDialog:hs,onOpenScheduled:()=>{e&&R(!1),ae(!0)},onOpenMultiRun:Tm,canOpenMultiRun:Y.length>0,onOpenArchive:()=>{e&&R(!1),Se(!0)},headerActionIconClass:um,headerActionButtonClass:dm,isSessionSearchOpen:a,setIsSessionSearchOpen:d,sessionSearchInputRef:g,sessionSearchQuery:u,setSessionSearchQuery:m,hasSessionSearchQuery:Xe,searchMatchCount:om,collapseAllProjects:ta,expandAllProjects:sa,selectionModeEnabled:Hl,onToggleSelectionMode:jm}),t?s.jsx(bj,{topContent:gm,hasSharedSessions:lm,sectionsForRender:cm,projectSections:mn,activeProjectId:U,showOnlyMainWorkspace:i,hasSessionSearchQuery:Xe,emptyState:pt,searchEmptyState:im,renderGroupSessions:pm,homeDirectory:J,collapsedProjects:A,hideDirectoryControls:o,projectRepoStatus:C,isDesktopShellRuntime:Is,stickyZoneHeaders:ir,stuckProjectHeaders:fm,mobileVariant:e,alwaysShowActions:$s,toggleProject:Bo,setActiveProjectIdOnly:ne,setActiveMainTab:Ye,setSessionSwitcherOpen:R,openNewSessionDraft:Qe,openNewWorktreeDialog:yt,openWorktreesPage:L=>{e&&R(!1),Ce(L)},openProjectEditDialog:b,removeProject:fe,projectHeaderSentinelRefs:oe,reorderProjects:Fe,projectSortOrder:Pn,getOrderedGroups:am,setGroupOrderByProject:Le,renderProjectStatusIndicator:hm,openSidebarMenuKey:z,setOpenSidebarMenuKey:V,isInlineEditing:Vl}):null,Hl&&xm?s.jsx(l2,{selectedCount:bm,scopeKey:vm,scopeFolders:wm,archivedBucket:ym,onMoveToFolder:Cm,onCreateFolderAndMove:Nm,onRemoveFromFolder:Am,canRemoveFromFolder:Sm,onRestore:Pm,onDelete:Dm,onDone:km}):null,s.jsx(ij,{onOpenSettings:ws,onOpenShortcuts:Re,onOpenAbout:()=>ue(!0),onOpenUpdate:cs,showRuntimeButtons:!Ve,showUpdateButton:Zt}),s.jsx(Wu,{open:B,onOpenChange:$,info:kt.info,downloading:kt.downloading,downloaded:kt.downloaded,progress:kt.progress,error:kt.error,onDownload:kt.downloadUpdate,onRestart:kt.restartToUpdate,runtimeType:kt.runtimeType}),s.jsx(y0,{open:!!It,onOpenChange:L=>{L||b(null)},project:It,onSave:Dt}),s.jsx(Fg,{open:F,onOpenChange:E,onWorktreeCreated:(L,Ge)=>{if(Ye("chat"),e&&R(!1),Ge?.sessionId){qt(Ge.sessionId,L);return}Je({directoryOverride:L,preserveDirectoryOverride:!0})}}),s.jsx(o2,{value:K,setValue:Z,showDeletionDialog:je,setShowDeletionDialog:Ze,onConfirm:Sr}),s.jsx(a2,{value:Q,setValue:le,onConfirm:ys}),s.jsx(i2,{value:te,setValue:he,showDeletionDialog:je,setShowDeletionDialog:Ze,onConfirm:Em})]})})},Ad=l.memo(S2);function j2(t){return t.currentSessionDirectory}const Tr=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,Tn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},k2=()=>{const{t}=gt(),[e,n]=l.useState(!1),[r,o]=l.useState(!1),[i,c]=l.useState(null),[a,d]=l.useState([]),[u,m]=l.useState(!1),[f,g]=l.useState(!1),[x,j]=l.useState(!1),[w,p]=l.useState(!1),[h,b]=l.useState(new Set),v=ot(oe=>oe.getWorktreeMetadata),S=ot(oe=>oe.newSessionDraft),N=ot(oe=>oe.setNewSessionDraftTarget),A=ot(oe=>oe.setDraftBootstrapPendingDirectory),k=Ep,C=Ip,P=ot(oe=>oe.deleteSessions),D=ot(oe=>oe.archiveSessions),O=pe(oe=>oe.showDeletionDialog),F=pe(oe=>oe.setShowDeletionDialog),E=ls(oe=>oe.currentDirectory),B=ls(oe=>oe.homeDirectory),$=ls(oe=>oe.isHomeReady),z=Gt(oe=>oe.projects),V=Gt(oe=>oe.activeProjectId),{isMobile:y,isTablet:I,hasTouchInput:_}=xr(),W=y||I||_,K=l.useMemo(()=>{const Te=(V?z.find(J=>J.id===V)??null:null)?.path??E;return Tn(Te)},[V,E,z]),Z=l.useCallback(oe=>{const J=Tn(oe.projectDirectory)||K;return{id:(z.find(Y=>Tn(Y.path)===J)??null)?.id??`path:${J}`,path:J}},[K,z]),Q=w&&h.size>0,le=l.useMemo(()=>{const oe=i?.worktree;return oe&&typeof oe.branch=="string"&&oe.branch.trim().length>0?!0:a.length>0&&a.every(({metadata:Te})=>typeof Te.branch=="string"&&Te.branch.trim().length>0)},[i?.worktree,a]),te=i?.mode==="worktree",he=te,xe=x||!te||!le,H=x||!te;l.useEffect(()=>{r||!$||z.length>0||(o(!0),n(!0))},[r,$,z.length]);const we=l.useCallback(oe=>{c({sessions:oe.sessions,dateLabel:oe.dateLabel,mode:oe.mode??"session",worktree:oe.worktree??null})},[]),de=l.useCallback(()=>{c(null),d([]),m(!1),g(!1),j(!1),p(!1),b(new Set)},[]),q=l.useCallback(async oe=>{if(oe.sessions.length===0)return;if(oe.sessions.length===1){const Y=oe.sessions[0];await k(Y.id)?Ae.success(t("sessions.sidebar.session.delete.success")):Ae.error(t("sessions.sidebar.session.delete.error"));return}const Te=oe.sessions.map(Y=>Y.id),{deletedIds:J,failedIds:re}=await P(Te);if(J.length>0){const Y=re.length>0?re.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:re.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:re.length}):oe.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:oe.dateLabel}):void 0;Ae.success(J.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:J.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:J.length}),{description:Tr(Y)})}re.length>0&&Ae.error(re.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:re.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:re.length}),{description:Tr(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[k,P,t]);l.useEffect(()=>Un.onDeleteRequest(oe=>{if(!O&&(oe.mode??"session")==="session"){q(oe);return}we(oe)}),[we,O,q]),l.useEffect(()=>Un.onDirectoryRequest(()=>{n(!0)}),[]),l.useEffect(()=>{if(!i){d([]),m(!1),g(!1),p(!1),b(new Set);return}const oe=i.sessions.map(re=>{const Y=v(re.id);return Y?{session:re,metadata:Y}:null}).filter(re=>!!re);d(oe),m(!1),p(!1),b(new Set);const Te=new Map;if(i.worktree?.path&&Te.set(Tn(i.worktree.path),i.worktree),oe.forEach(({metadata:re})=>{re.path&&Te.set(Tn(re.path),re)}),Te.size===0){p(!0);return}let J=!1;return(async()=>{const re=new Map,Y=new Set;await Promise.all(Array.from(Te.entries()).map(async([U,fe])=>{try{const ne=await Tp(fe.path);re.set(U,ne),ne?.isDirty&&Y.add(U)}catch{fe.status&&(re.set(U,fe.status),fe.status.isDirty&&Y.add(U))}})).catch(U=>{console.warn("Failed to inspect worktree status before deletion:",U)}),!J&&(b(Y),p(!0),c(U=>{if(!U?.worktree?.path)return U;const fe=Tn(U.worktree.path),ne=re.get(fe);if(!ne)return U;const ce=U.worktree.status;return ce?.isDirty===ne.isDirty&&ce?.ahead===ne.ahead&&ce?.behind===ne.behind&&ce?.upstream===ne.upstream?U:{...U,worktree:{...U.worktree,status:ne}}}),d(U=>U.map(fe=>{const ne=Tn(fe.metadata.path),ce=re.get(ne);return ce?{session:fe.session,metadata:{...fe.metadata,status:ce}}:fe})))})(),()=>{J=!0}},[i,v]),l.useEffect(()=>{le||m(!1)},[le]);const me=l.useCallback(async(oe,Te)=>{const J=u&&le,re=Z(oe),Y=Tn(oe.path),U=Tn(re.path);try{await uu(re,oe,{deleteRemoteBranch:J,deleteLocalBranch:Te});const fe=Tn(S?.directoryOverride);return S?.open&&Y&&fe===Y&&U&&(A(null),N({projectId:re.id,directoryOverride:U},{force:!0})),Tn(E)===Y&&U&&ls.getState().setDirectory(U,{showOverlay:!1}),!0}catch(fe){return Ae.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:Tr(fe instanceof Error?fe.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[le,E,u,Z,S?.directoryOverride,S?.open,A,N,t]),be=l.useCallback((oe,Te)=>{const J=u&&le;(async()=>{if(!await me(oe,Te))return;const Y=t(J?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");Ae.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:Tr(Y)})})()},[le,u,me,t]),Pe=l.useCallback(async()=>{if(i){j(!0);try{const oe=he,Te=oe&&u,J=oe&&f;if(i.sessions.length===0&&te&&i.worktree){be(i.worktree,J),de();return}if(i.sessions.length===1){const re=i.sessions[0];if(!(te?await C(re.id):await k(re.id))){Ae.error(t(te?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),j(!1);return}const U=!te&&oe?t(Te?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;Ae.success(t(te?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:Tr(U),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const re=i.sessions.map(fe=>fe.id);let Y=[],U=[];if(te){const fe=await D(re);Y=fe.archivedIds,U=fe.failedIds}else{const fe=await P(re);Y=fe.deletedIds,U=fe.failedIds}if(te&&i.worktree&&U.length===0&&be(i.worktree,J),Y.length>0){const fe=!te&&oe?t(Te?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,ce=[U.length>0?te?U.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:U.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:U.length}):U.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:U.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:U.length}):i.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:i.dateLabel}):void 0,fe].filter(Boolean).join(" ");Ae.success(te?Y.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:Y.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:Y.length}):Y.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Y.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Y.length}),{description:Tr(ce||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(U.length>0&&(Ae.error(te?U.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:U.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:U.length}):U.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:U.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:U.length}),{description:Tr(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),Y.length===0)){j(!1);return}}te&&i.sessions.length===1&&i.worktree&&be(i.worktree,J),de()}finally{j(!1)}}},[i,u,f,k,P,C,D,de,he,te,be,t]),Ie=i?.worktree??a[0]?.metadata??null,De=i?i.mode==="worktree"?i.sessions.length===0?t("sessions.sidebar.dialogs.worktreeDelete.descriptionNoLinked"):i.sessions.length===1?t("sessions.sidebar.dialogs.worktreeDelete.descriptionOneLinked",{count:i.sessions.length}):t("sessions.sidebar.dialogs.worktreeDelete.descriptionManyLinked",{count:i.sessions.length}):i.sessions.length===1?i.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionOneWithDate",{dateLabel:i.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionOne"):i.dateLabel?t("sessions.sidebar.dialogs.sessionDelete.descriptionManyWithDate",{count:i.sessions.length,dateLabel:i.dateLabel}):t("sessions.sidebar.dialogs.sessionDelete.descriptionMany",{count:i.sessions.length}):"",Le=i?s.jsxs("div",{className:ge(te?"space-y-3":"space-y-2"),children:[i.sessions.length>0&&s.jsxs("div",{className:ge(te?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[te&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-meta font-medium text-foreground",children:i.sessions.length===1?t("sessions.sidebar.sessionDialogs.linkedSessionSingle"):t("sessions.sidebar.sessionDialogs.linkedSessionPlural")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:i.sessions.length})]}),s.jsxs("ul",{className:ge(te?"mt-2 space-y-1":"space-y-0.5"),children:[i.sessions.slice(0,5).map(oe=>s.jsxs("li",{className:ge(te?"flex items-center gap-2 rounded-md px-2.5 py-1.5 text-sm text-muted-foreground":"typography-micro text-muted-foreground/80"),children:[s.jsx("span",{className:ge(!te&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:oe.title||t("sessions.sidebar.session.untitled")})]},oe.id)),i.sessions.length>5&&s.jsx("li",{className:ge(te?"px-2.5 py-1 text-xs text-muted-foreground/70":"typography-micro text-muted-foreground/70"),children:t("sessions.sidebar.dialogs.sessionList.more",{count:i.sessions.length-5})})]})]}),te?s.jsxs("div",{className:"space-y-2 rounded-lg bg-muted/30 p-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(T,{name:"git-branch",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-meta font-medium text-foreground",children:t("sessions.sidebar.sessionDialogs.worktree.label")}),Ie?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:Ie.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:Ie?yi(Ie.path,B):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),Q&&s.jsx("p",{className:"typography-micro text-status-warning",children:t("sessions.sidebar.sessionDialogs.worktree.uncommittedWarning")})]}):s.jsx("div",{className:"rounded-xl border border-border/40 bg-sidebar/60 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("sessions.sidebar.sessionDialogs.delete.note")})})]}):null,Ne=te?le?s.jsxs("button",{type:"button",onClick:()=>{xe||m(oe=>!oe)},disabled:xe,className:ge("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",xe?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(T,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(T,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteRemoteBranch")]}):s.jsx("span",{className:"text-xs text-muted-foreground/70",children:t("sessions.sidebar.sessionDialogs.actions.remoteBranchInfoUnavailable")}):null,ve=te?s.jsxs("button",{type:"button",onClick:()=>{H||g(oe=>!oe)},disabled:H,className:ge("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",H?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[f?s.jsx(T,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(T,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,Me=te?s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[ve,Ne]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(lt,{variant:"ghost",onClick:de,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(lt,{variant:"destructive",onClick:Pe,disabled:x,children:t(x?"sessions.sidebar.sessionDialogs.actions.deleting":"sessions.sidebar.sessionDialogs.actions.deleteWorktree")})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>F(!O),className:"inline-flex items-center gap-1.5 typography-meta text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":!O,children:[O?s.jsx(T,{name:"checkbox-blank",className:"size-4"}):s.jsx(T,{name:"checkbox",className:"size-4 text-primary"}),t("sessions.sidebar.dialogs.neverAsk")]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(lt,{variant:"ghost",onClick:de,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(lt,{variant:"destructive",onClick:Pe,disabled:x,children:x?t("sessions.sidebar.sessionDialogs.actions.deleting"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),ee=te?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[W?s.jsx(Ui,{open:!!i,onClose:()=>{x||de()},title:ee,footer:s.jsx("div",{className:"flex justify-end gap-2",children:Me}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[De&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:De}),Le]})}):s.jsx(Ls,{open:!!i,onOpenChange:oe=>{if(!oe){if(x)return;de()}},children:s.jsxs(Bs,{className:ge(te?"max-w-xl max-h-[70vh] flex flex-col overflow-hidden gap-3":"max-w-[min(520px,100vw-2rem)] space-y-2 pb-2"),children:[s.jsxs(kn,{children:[s.jsxs(nn,{className:ge(te&&"flex items-center gap-2"),children:[te&&s.jsx(T,{name:"delete-bin",className:"h-5 w-5"}),ee]}),De&&s.jsx(rn,{children:De})]}),s.jsx("div",{className:ge(te&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:Le}),s.jsx(sr,{className:"mt-2 gap-2 pt-1 pb-1",children:Me})]})}),s.jsx(Lg,{open:e,onOpenChange:n})]})};function Qf(t){if(!t||!t.trim())return{valid:!1,error:"required"};try{return nf.CronExpressionParser.parse(t),{valid:!0}}catch(e){return{valid:!1,error:e instanceof Error?e.message:"Invalid cron expression"}}}function C2(t,e,n=4){try{const r=e?{tz:e,currentDate:new Date}:{currentDate:new Date},o=nf.CronExpressionParser.parse(t,r),i=[];for(let c=0;c<n;c+=1){const a=o.next();a&&i.push(a.toDate())}return i}catch{return[]}}const N2=[{expression:"*/5 * * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.every5min"},{expression:"0 * * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.everyHour"},{expression:"0 9 * * 1",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.monday9am"},{expression:"0 9,17 * * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.9am5pm"},{expression:"0 0 1 * *",labelKey:"sessions.scheduledTasks.editor.cronExpression.examples.firstOfMonth"}],A2={"Europe/Kiev":"Europe/Kyiv","Asia/Calcutta":"Asia/Kolkata","Asia/Saigon":"Asia/Ho_Chi_Minh","Asia/Rangoon":"Asia/Yangon","Asia/Katmandu":"Asia/Kathmandu","America/Godthab":"America/Nuuk","Atlantic/Faeroe":"Atlantic/Faroe","Pacific/Enderbury":"Pacific/Kanton"},Fr=t=>A2[t]??t,Xf=[0,1,2,3,4,5,6],Dd="flex h-6 w-6 cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0",rl=typeof Intl<"u"&&typeof Intl.supportedValuesOf=="function"?[...new Set(Intl.supportedValuesOf("timeZone").map(Fr))]:["UTC","Europe/Kyiv","Europe/London","Europe/Berlin","America/New_York","America/Los_Angeles","Asia/Tokyo"],Pd=()=>{const t=new Date,e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},pi=t=>{const e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(t);if(!e)return null;const n=Number(e[1]),r=Number(e[2]),o=Number(e[3]),i=new Date(n,r-1,o);return Number.isNaN(i.getTime())||i.getFullYear()!==n||i.getMonth()!==r-1||i.getDate()!==o?null:i},Ed=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},D2=(t,e,n)=>{const r=pi(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},Td=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),P2=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),c=(new Date(n,r,1).getDay()-e+7)%7,a=new Date(n,r+1,0).getDate(),d=new Date(n,r,0).getDate(),u=[];for(let m=0;m<42;m+=1){const f=m-c+1;if(f<=0){const g=d+f;u.push({date:new Date(n,r-1,g),inCurrentMonth:!1});continue}if(f>a){u.push({date:new Date(n,r+1,f-a),inCurrentMonth:!1});continue}u.push({date:new Date(n,r,f),inCurrentMonth:!0})}return u},E2=t=>{const e=/^([01]\d|2[0-3]):([0-5]\d)$/.exec(t);if(!e)return{hour24:"00",hour12:"12",minute:"00",meridiem:"AM"};const n=Number(e[1]),r=e[2],o=n>=12?"PM":"AM",i=n%12===0?12:n%12;return{hour24:String(n).padStart(2,"0"),hour12:String(i).padStart(2,"0"),minute:r,meridiem:o}},Ir=(t,e,n)=>{const r=Number(t),o=Number(e),i=Number.isFinite(r)?Math.min(12,Math.max(1,r)):12,c=Number.isFinite(o)?Math.min(59,Math.max(0,o)):0;let a=i%12;return n==="PM"&&(a+=12),`${String(a).padStart(2,"0")}:${String(c).padStart(2,"0")}`},ro=(t,e)=>{const{max:n,min:r=0,loop:o=!1}=e;let i=Number.parseInt(t,10);return Number.isFinite(i)?(o?(i>n&&(i=r),i<r&&(i=n)):(i>n&&(i=n),i<r&&(i=r)),String(i).padStart(2,"0")):"00"},Id=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:ro(t,{min:1,max:12}),ri=t=>/^[0-5][0-9]$/.test(t)?t:ro(t,{max:59}),T2=(t,e)=>ro(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),Rd=(t,e)=>ro(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),I2=t=>{try{const e=Intl.Locale;if(typeof e!="function")return 1;const r=new e(t).weekInfo?.firstDay;return typeof r!="number"?1:r%7}catch{return 1}},R2=t=>{try{const e=new Intl.DateTimeFormat(t,{hour:"numeric"}).resolvedOptions();return typeof e.hour12=="boolean"?!e.hour12:e.hourCycle==="h23"||e.hourCycle==="h24"}catch{return!0}},M2=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return Xf.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},O2=(t,e)=>[...t.slice(e),...t.slice(0,e)],Hs=t=>{const e=it.c(6),{htmlFor:n,required:r,children:o}=t;let i;e[0]!==r?(i=r&&s.jsx("span",{className:"ml-0.5 text-destructive",children:"*"}),e[0]=r,e[1]=i):i=e[1];let c;return e[2]!==o||e[3]!==n||e[4]!==i?(c=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[o,i]})}),e[2]=o,e[3]=n,e[4]=i,e[5]=c):c=e[5],c},Md=t=>{const e=it.c(84),{value:n,onChange:r,use24Hour:o,hourAriaLabel:i,minuteAriaLabel:c,periodAriaLabel:a,amLabel:d,pmLabel:u}=t;let m;e[0]!==n?(m=E2(n),e[0]=n,e[1]=m):m=e[1];const f=m,g=nt.useRef(null),x=nt.useRef(null),[j,w]=nt.useState(null),[p,h]=nt.useState(null),b=nt.useRef(null),v=nt.useRef(null);let S;e[2]===Symbol.for("react.memo_cache_sentinel")?(S=ee=>{b.current=ee,w(ee)},e[2]=S):S=e[2];const N=S;let A;e[3]===Symbol.for("react.memo_cache_sentinel")?(A=ee=>{v.current=ee,h(ee)},e[3]=A):A=e[3];const k=A,C=U2,P=W2,D=V2;let O;e[4]!==r||e[5]!==f.meridiem||e[6]!==f.minute||e[7]!==o?(O=ee=>{const oe=ee.replace(/\D/g,"").slice(0,2);N(oe),oe.length===2&&(r(o?D(C(oe),f.minute):Ir(Id(oe),f.minute,f.meridiem)),N(null),x.current?.focus())},e[4]=r,e[5]=f.meridiem,e[6]=f.minute,e[7]=o,e[8]=O):O=e[8];const F=O;let E;e[9]!==r||e[10]!==f.meridiem||e[11]!==f.minute||e[12]!==o?(E=()=>{const ee=b.current;if(ee!==null&&(N(null),ee.length!==0)){if(o){r(D(C(ee.padStart(2,"0")),f.minute));return}r(Ir(Id(ee.padStart(2,"0")),f.minute,f.meridiem))}},e[9]=r,e[10]=f.meridiem,e[11]=f.minute,e[12]=o,e[13]=E):E=e[13];const B=E;let $;e[14]!==r||e[15]!==f.hour12||e[16]!==f.hour24||e[17]!==f.meridiem||e[18]!==o?($=ee=>{const oe=ee.replace(/\D/g,"").slice(0,2);k(oe),oe.length===2&&(r(o?D(f.hour24,ri(oe)):Ir(f.hour12,ri(oe),f.meridiem)),k(null))},e[14]=r,e[15]=f.hour12,e[16]=f.hour24,e[17]=f.meridiem,e[18]=o,e[19]=$):$=e[19];const z=$;let V;e[20]!==r||e[21]!==f.hour12||e[22]!==f.hour24||e[23]!==f.meridiem||e[24]!==o?(V=()=>{const ee=v.current;ee!==null&&(k(null),ee.length!==0&&r(o?D(f.hour24,ri(ee.padStart(2,"0"))):Ir(f.hour12,ri(ee.padStart(2,"0")),f.meridiem)))},e[20]=r,e[21]=f.hour12,e[22]=f.hour24,e[23]=f.meridiem,e[24]=o,e[25]=V):V=e[25];const y=V;let I;e[26]!==r||e[27]!==f.hour12||e[28]!==f.hour24||e[29]!==f.meridiem||e[30]!==f.minute||e[31]!==o?(I=ee=>r(o?D(P(f.hour24,ee),f.minute):Ir(T2(f.hour12,ee),f.minute,f.meridiem)),e[26]=r,e[27]=f.hour12,e[28]=f.hour24,e[29]=f.meridiem,e[30]=f.minute,e[31]=o,e[32]=I):I=e[32];const _=I;let W;e[33]!==r||e[34]!==f.hour12||e[35]!==f.hour24||e[36]!==f.meridiem||e[37]!==f.minute||e[38]!==o?(W=ee=>r(o?D(f.hour24,Rd(f.minute,ee)):Ir(f.hour12,Rd(f.minute,ee),f.meridiem)),e[33]=r,e[34]=f.hour12,e[35]=f.hour24,e[36]=f.meridiem,e[37]=f.minute,e[38]=o,e[39]=W):W=e[39];const K=W;let Z;e[40]!==r||e[41]!==f.hour12||e[42]!==f.meridiem||e[43]!==f.minute?(Z=ee=>{ee!==f.meridiem&&r(Ir(f.hour12,f.minute,ee))},e[40]=r,e[41]=f.hour12,e[42]=f.meridiem,e[43]=f.minute,e[44]=Z):Z=e[44];const Q=Z;let le;e[45]!==B||e[46]!==_?(le=ee=>{if(ee.key==="ArrowRight"){ee.preventDefault(),B(),x.current?.focus();return}(ee.key==="ArrowUp"||ee.key==="ArrowDown")&&(ee.preventDefault(),N(null),_(ee.key==="ArrowUp"?1:-1))},e[45]=B,e[46]=_,e[47]=le):le=e[47];const te=le;let he;e[48]!==y||e[49]!==K?(he=ee=>{if(ee.key==="ArrowLeft"&&(ee.currentTarget.selectionStart??0)===0){ee.preventDefault(),y(),g.current?.focus();return}(ee.key==="ArrowUp"||ee.key==="ArrowDown")&&(ee.preventDefault(),k(null),K(ee.key==="ArrowUp"?1:-1))},e[48]=y,e[49]=K,e[50]=he):he=e[50];const xe=he,H=o?"px-2":"pl-2 pr-1";let we;e[51]!==H?(we=ge("inline-flex h-9 w-fit items-center gap-1 rounded-md border border-border bg-background focus-within:ring-1 focus-within:ring-interactive-focusRing focus-within:border-interactive-focusRing",H),e[51]=H,e[52]=we):we=e[52];const de=j??(o?f.hour24:f.hour12);let q;e[53]!==F?(q=ee=>F(ee.target.value),e[53]=F,e[54]=q):q=e[54];let me;e[55]===Symbol.for("react.memo_cache_sentinel")?(me=()=>N(""),e[55]=me):me=e[55];let be;e[56]!==B||e[57]!==i||e[58]!==te||e[59]!==de||e[60]!==q?(be=s.jsx("input",{ref:g,inputMode:"numeric",value:de,onChange:q,onKeyDown:te,onFocus:me,onBlur:B,maxLength:2,"aria-label":i,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[56]=B,e[57]=i,e[58]=te,e[59]=de,e[60]=q,e[61]=be):be=e[61];let Pe;e[62]===Symbol.for("react.memo_cache_sentinel")?(Pe=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=Pe):Pe=e[62];const Ie=p??f.minute;let De;e[63]!==z?(De=ee=>z(ee.target.value),e[63]=z,e[64]=De):De=e[64];let Le;e[65]===Symbol.for("react.memo_cache_sentinel")?(Le=()=>k(""),e[65]=Le):Le=e[65];let Ne;e[66]!==y||e[67]!==c||e[68]!==xe||e[69]!==Ie||e[70]!==De?(Ne=s.jsx("input",{ref:x,inputMode:"numeric",value:Ie,onChange:De,onKeyDown:xe,onFocus:Le,onBlur:y,maxLength:2,"aria-label":c,className:"h-7 w-7 shrink-0 rounded-sm bg-transparent text-center font-mono text-sm tabular-nums text-foreground outline-none caret-transparent focus:bg-interactive-hover"}),e[66]=y,e[67]=c,e[68]=xe,e[69]=Ie,e[70]=De,e[71]=Ne):Ne=e[71];let ve;e[72]!==d||e[73]!==f.meridiem||e[74]!==a||e[75]!==u||e[76]!==Q||e[77]!==o?(ve=o?null:s.jsxs(Ks,{value:f.meridiem,onValueChange:ee=>Q(ee),children:[s.jsx(Gs,{"aria-label":a,className:"ml-1 h-7 w-fit border-0 bg-transparent pl-2 pr-1 shadow-none hover:bg-interactive-hover focus:ring-0",children:s.jsx(Es,{})}),s.jsxs(qs,{children:[s.jsx(is,{value:"AM",children:d}),s.jsx(is,{value:"PM",children:u})]})]}),e[72]=d,e[73]=f.meridiem,e[74]=a,e[75]=u,e[76]=Q,e[77]=o,e[78]=ve):ve=e[78];let Me;return e[79]!==we||e[80]!==be||e[81]!==Ne||e[82]!==ve?(Me=s.jsxs("div",{className:we,children:[be,Pe,Ne,ve]}),e[79]=we,e[80]=be,e[81]=Ne,e[82]=ve,e[83]=Me):Me=e[83],Me},Od=t=>new Date(t.getFullYear(),t.getMonth(),1),F2=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},Fd=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),L2=t=>{if(!t)return["09:00"];const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(o=>typeof o=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(o)).map(o=>o.trim()),r=Array.from(new Set(n)).sort((o,i)=>o.localeCompare(i));return r.length>0?r:["09:00"]},Ld=(t,e)=>{const n=Fr(Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC");return t?{id:t.id,name:t.name,enabled:t.enabled,schedule:{kind:t.schedule.kind==="cron"?"cron":t.schedule.kind==="once"?"once":t.schedule.kind==="weekly"?"weekly":"daily",times:L2(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:Pd(),onceTime:typeof t.schedule.time=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.time)?t.schedule.time:"09:00",weekdays:Array.isArray(t.schedule.weekdays)?t.schedule.weekdays:[1],timezone:Fr(t.schedule.timezone||n),cronExpression:t.schedule.kind==="cron"&&typeof t.schedule.cron=="string"?t.schedule.cron:""},execution:{prompt:t.execution.prompt,providerID:t.execution.providerID,modelID:t.execution.modelID,variant:t.execution.variant||"",agent:t.execution.agent||"",goalEnabled:t.execution.goalEnabled===!0,goalTokenBudget:typeof t.execution.goalTokenBudget=="number"&&t.execution.goalTokenBudget>0?t.execution.goalTokenBudget:null,permissionAutoAccept:t.execution.permissionAutoAccept===!0},state:t.state}:{name:"",enabled:!0,schedule:{kind:"daily",times:["09:00"],onceDate:Pd(),onceTime:"09:00",weekdays:[1],timezone:n,cronExpression:""},execution:{prompt:"",providerID:e.providerID,modelID:e.modelID,variant:e.variant,agent:e.agent,goalEnabled:!1,goalTokenBudget:null,permissionAutoAccept:!1}}},B2=(t,e)=>{if(!t.name.trim())return e("sessions.scheduledTasks.editor.validation.taskNameRequired");if(!t.execution.prompt.trim())return e("sessions.scheduledTasks.editor.validation.promptRequired");if(!t.execution.providerID.trim()||!t.execution.modelID.trim())return e("sessions.scheduledTasks.editor.validation.modelRequired");if(t.schedule.kind==="once"){if(!/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.onceDate))return e("sessions.scheduledTasks.editor.validation.dateFormat");if(!/^([01]\d|2[0-3]):([0-5]\d)$/.test(t.schedule.onceTime))return e("sessions.scheduledTasks.editor.validation.timeFormat")}else if(t.schedule.kind==="cron"){if(!t.schedule.cronExpression.trim())return e("sessions.scheduledTasks.editor.validation.cronRequired");if(!Qf(t.schedule.cronExpression).valid)return e("sessions.scheduledTasks.editor.validation.cronInvalid")}else if(t.schedule.times.filter(r=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(r)).length===0)return e("sessions.scheduledTasks.editor.validation.atLeastOneTime");return t.schedule.kind==="weekly"&&t.schedule.weekdays.length===0?e("sessions.scheduledTasks.editor.validation.atLeastOneWeekday"):t.schedule.timezone.trim()?null:e("sessions.scheduledTasks.editor.validation.timezoneRequired")},_2=t=>{const e=t.filter(n=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(n));return Array.from(new Set(e)).sort((n,r)=>n.localeCompare(r))},$2=t=>{const e=it.c(64),{draft:n,setDraft:r,locale:o,t:i}=t,c=n.schedule.cronExpression;let a;e[0]!==c?(a=c.trim()?Qf(c):null,e[0]=c,e[1]=a):a=e[1];const d=a;let u;e:{if(!d?.valid||!c.trim()){let I;e[2]===Symbol.for("react.memo_cache_sentinel")?(I=[],e[2]=I):I=e[2],u=I;break e}let y;e[3]!==c||e[4]!==n.schedule.timezone?(y=C2(c,n.schedule.timezone),e[3]=c,e[4]=n.schedule.timezone,e[5]=y):y=e[5],u=y}const m=u;let f;e[6]!==n.schedule.timezone||e[7]!==o?(f=y=>new Intl.DateTimeFormat(o,{timeZone:n.schedule.timezone,month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(y),e[6]=n.schedule.timezone,e[7]=o,e[8]=f):f=e[8];const g=f;let x;e[9]!==i?(x=i("sessions.scheduledTasks.editor.cronExpression.label"),e[9]=i,e[10]=x):x=e[10];let j;e[11]!==x?(j=s.jsx(Hs,{htmlFor:"sched-cron",required:!0,children:x}),e[11]=x,e[12]=j):j=e[12];let w;e[13]!==r?(w=y=>r(I=>({...I,schedule:{...I.schedule,cronExpression:y.target.value}})),e[13]=r,e[14]=w):w=e[14];let p;e[15]!==i?(p=i("sessions.scheduledTasks.editor.cronExpression.placeholder"),e[15]=i,e[16]=p):p=e[16];let h;e[17]!==c||e[18]!==w||e[19]!==p?(h=s.jsx(tr,{id:"sched-cron",value:c,onChange:w,placeholder:p,className:"w-full max-w-xs font-mono"}),e[17]=c,e[18]=w,e[19]=p,e[20]=h):h=e[20];let b;e[21]!==c||e[22]!==d||e[23]!==i?(b=d&&!d.valid&&c.trim()?s.jsx("span",{className:"typography-micro text-destructive",children:i("sessions.scheduledTasks.editor.validation.cronInvalid")}):null,e[21]=c,e[22]=d,e[23]=i,e[24]=b):b=e[24];let v;e[25]!==j||e[26]!==h||e[27]!==b?(v=s.jsxs("div",{className:"flex flex-col gap-1",children:[j,h,b]}),e[25]=j,e[26]=h,e[27]=b,e[28]=v):v=e[28];let S;e[29]!==g||e[30]!==m||e[31]!==i?(S=m.length>0?s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:i("sessions.scheduledTasks.editor.cronExpression.nextRuns")}),s.jsx("span",{className:"typography-micro text-foreground",children:m.map(g).join(", ")})]}):null,e[29]=g,e[30]=m,e[31]=i,e[32]=S):S=e[32];let N;e[33]!==i?(N=i("sessions.scheduledTasks.editor.cronExpression.examples"),e[33]=i,e[34]=N):N=e[34];let A;e[35]!==N?(A=s.jsx("span",{className:"typography-meta text-muted-foreground",children:N}),e[35]=N,e[36]=A):A=e[36];let k;e[37]!==r||e[38]!==i?(k=N2.map(y=>s.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 rounded-md border border-border px-2 py-1 typography-micro text-foreground hover:bg-interactive-hover",onClick:()=>r(I=>({...I,schedule:{...I.schedule,cronExpression:y.expression}})),children:[s.jsx("span",{className:"font-mono",children:y.expression}),s.jsx("span",{className:"text-muted-foreground",children:i(y.labelKey)})]},y.expression)),e[37]=r,e[38]=i,e[39]=k):k=e[39];let C;e[40]!==k?(C=s.jsx("div",{className:"flex flex-wrap gap-1.5",children:k}),e[40]=k,e[41]=C):C=e[41];let P;e[42]!==A||e[43]!==C?(P=s.jsxs("div",{className:"flex flex-col gap-1",children:[A,C]}),e[42]=A,e[43]=C,e[44]=P):P=e[44];let D;e[45]!==i?(D=i("sessions.scheduledTasks.editor.timezone.label"),e[45]=i,e[46]=D):D=e[46];let O;e[47]!==D?(O=s.jsx(Hs,{children:D}),e[47]=D,e[48]=O):O=e[48];let F;e[49]!==r?(F=y=>{r(I=>({...I,schedule:{...I.schedule,timezone:y}}))},e[49]=r,e[50]=F):F=e[50];let E;e[51]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(Gs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Es,{})}),e[51]=E):E=e[51];let B;e[52]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(qs,{children:rl.map(H2)}),e[52]=B):B=e[52];let $;e[53]!==n.schedule.timezone||e[54]!==F?($=s.jsxs(Ks,{value:n.schedule.timezone,onValueChange:F,children:[E,B]}),e[53]=n.schedule.timezone,e[54]=F,e[55]=$):$=e[55];let z;e[56]!==O||e[57]!==$?(z=s.jsxs("div",{className:"flex flex-col gap-1",children:[O,$]}),e[56]=O,e[57]=$,e[58]=z):z=e[58];let V;return e[59]!==v||e[60]!==S||e[61]!==P||e[62]!==z?(V=s.jsxs("div",{className:"flex flex-col gap-3",children:[v,S,P,z]}),e[59]=v,e[60]=S,e[61]=P,e[62]=z,e[63]=V):V=e[63],V};function z2(t){const{open:e,task:n,onOpenChange:r,onSave:o}=t,{t:i,locale:c}=gt(),a=Kt(R=>R.loadProviders),d=Kt(R=>R.loadAgents),u=Kt(R=>R.providers),m=Kt(R=>R.currentProviderId),f=Kt(R=>R.currentModelId),g=Kt(R=>R.currentVariant||""),x=Kt(R=>R.currentAgentName||""),j=pe(R=>R.timeFormatPreference),w=pe(R=>R.weekStartPreference),p=pe(R=>R.isMobile),[h,b]=nt.useState(()=>Ld(n,{providerID:m,modelID:f,variant:g,agent:x})),[v,S]=nt.useState(!1),[N,A]=nt.useState(!1),[k,C]=nt.useState(!1),[P,D]=nt.useState(""),[O,F]=nt.useState(!1),[E,B]=nt.useState(""),[$,z]=nt.useState(!1),[V,y]=nt.useState(""),[I,_]=nt.useState(()=>{const R=pi(n?.schedule?.date||"")||new Date;return new Date(R.getFullYear(),R.getMonth(),1)}),W=nt.useRef(null),K=nt.useRef(null),Z=nt.useRef(null),Q=nt.useRef(null),le=nt.useRef(null),te=nt.useMemo(()=>R2(c),[c]),he=nt.useMemo(()=>I2(c),[c]),xe=nt.useMemo(()=>j==="24h"?!0:j==="12h"?!1:te,[j,te]),H=nt.useMemo(()=>w==="sunday"?0:w==="monday"?1:he,[w,he]),we=nt.useMemo(()=>{const R=M2(c);return O2(Xf.map(ae=>({value:ae,label:R[ae]||""})),H)},[c,H]);nt.useEffect(()=>{e&&(a({source:"scheduledTaskEditor"}),d({source:"scheduledTaskEditor"}))},[e,a,d]),nt.useEffect(()=>{if(!e)return;b(Ld(n,{providerID:m,modelID:f,variant:g,agent:x}));const R=pi(n?.schedule?.date||"")||new Date;_(new Date(R.getFullYear(),R.getMonth(),1)),A(!1),F(!1),C(!1),B(""),D("")},[e,n,m,f,g,x]),nt.useEffect(()=>{if(!N)return;const R=ae=>{W.current&&!W.current.contains(ae.target)&&A(!1)};return document.addEventListener("mousedown",R),()=>{document.removeEventListener("mousedown",R)}},[N]);const de=nt.useMemo(()=>{const ae=u.find(Se=>Se.id===h.execution.providerID)?.models?.find(Se=>Se.id===h.execution.modelID);return ae?.variants?Object.keys(ae.variants):[]},[u,h.execution.providerID,h.execution.modelID]),q=de.length>0,me=nt.useMemo(()=>!q||!h.execution.variant?"__default":de.includes(h.execution.variant)?h.execution.variant:"__default",[h.execution.variant,q,de]);nt.useEffect(()=>{q||!h.execution.variant||b(R=>({...R,execution:{...R.execution,variant:""}}))},[q,h.execution.variant]);const be=nt.useCallback((R,ae)=>{b(Se=>{const Ce=new Set(Se.schedule.weekdays);return ae?Ce.add(R):Ce.delete(R),{...Se,schedule:{...Se.schedule,weekdays:Array.from(Ce).sort((Ee,se)=>Ee-se)}}})},[]),Pe=nt.useCallback((R,ae)=>{b(Se=>{const Ce=Se.schedule.times.slice();return Ce[R]=ae,{...Se,schedule:{...Se.schedule,times:Ce}}})},[]),Ie=nt.useCallback(R=>{b(ae=>{const Se=ae.schedule.times.filter((Ce,Ee)=>Ee!==R);return{...ae,schedule:{...ae.schedule,times:Se.length>0?Se:["09:00"]}}})},[]),De=nt.useCallback(()=>{b(R=>({...R,schedule:{...R.schedule,times:[...R.schedule.times,"12:00"]}}))},[]),Le=nt.useMemo(()=>F2(),[]),Ne=nt.useMemo(()=>Od(Le),[Le]),ve=nt.useMemo(()=>{const R=pi(h.schedule.onceDate);return R?Fd(R,Le)?i("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(c,{weekday:"short"}).format(R):null},[h.schedule.onceDate,c,i,Le]),Me=nt.useMemo(()=>Od(I).getTime()<=Ne.getTime(),[I,Ne]),ee=nt.useMemo(()=>we.map(R=>R.label),[we]),oe=nt.useCallback(R=>{b(ae=>({...ae,schedule:{...ae.schedule,onceDate:R}}))},[]),Te=nt.useCallback((R,ae)=>{if(R.startsWith("/")){const se=R.indexOf(" "),je=R.indexOf(`
915
+ `),Ze=Math.min(se===-1?R.length:se,je===-1?R.length:je);if(ae<=Ze&&se===-1){B(R.substring(1,Ze)),F(!0),C(!1),z(!1);return}}F(!1);const Se=R.substring(0,ae),Ce=Se.lastIndexOf("#");if(Ce!==-1){const se=Ce>0?Se[Ce-1]:null,je=Se.substring(Ce+1);if((!se||/\s/.test(se))&&!je.includes(" ")&&!je.includes(`
916
+ `)){y(je),z(!0),C(!1);return}}z(!1);const Ee=Se.lastIndexOf("@");if(Ee!==-1){const se=Ee>0?Se[Ee-1]:null,je=Se.substring(Ee+1);(!se||/\s/.test(se))&&!je.includes(" ")&&!je.includes(`
917
+ `)?(D(je),C(!0)):C(!1);return}C(!1)},[]),J=nt.useCallback(R=>{b(ae=>({...ae,execution:{...ae.execution,prompt:R}}))},[]),re=nt.useCallback(R=>{const ae=h.execution.prompt,Ce=K.current?.selectionStart??ae.length,se=ae.substring(0,Ce).lastIndexOf("@"),je=R.relativePath&&R.relativePath.trim().length>0?R.relativePath.trim():R.path||R.name,Ze=se!==-1?se:Ce,X=`${ae.substring(0,Ze)}@${je} ${ae.substring(Ce)}`,ye=Ze+je.length+2;J(X),C(!1),D(""),requestAnimationFrame(()=>{const Xe=K.current;Xe&&(Xe.selectionStart=ye,Xe.selectionEnd=ye,Xe.focus()),Te(X,ye)})},[h.execution.prompt,J,Te]),Y=nt.useCallback(R=>{const ae=h.execution.prompt,Ce=K.current?.selectionStart??ae.length,se=ae.substring(0,Ce).lastIndexOf("@"),je=se!==-1?se:Ce,Ze=`${ae.substring(0,je)}@${R} ${ae.substring(Ce)}`,X=je+R.length+2;J(Ze),C(!1),D(""),requestAnimationFrame(()=>{const ye=K.current;ye&&(ye.selectionStart=X,ye.selectionEnd=X,ye.focus()),Te(Ze,X)})},[h.execution.prompt,J,Te]),U=nt.useCallback(R=>{const ae=`/${R.name} `;J(ae),F(!1),B(""),z(!1),requestAnimationFrame(()=>{const Se=K.current;Se&&(Se.focus(),Se.selectionStart=Se.value.length,Se.selectionEnd=Se.value.length),Te(ae,ae.length)})},[J,Te]),fe=nt.useCallback((R,ae)=>{const Se=h.execution.prompt,Ee=K.current?.selectionStart??Se.length,je=Se.substring(0,Ee).lastIndexOf("#"),Ze=je!==-1?je:Ee,X=`${Se.substring(0,Ze)}#${ae} ${Se.substring(Ee)}`,ye=Ze+ae.length+2;J(X),z(!1),y(""),requestAnimationFrame(()=>{const Xe=K.current;Xe&&(Xe.selectionStart=ye,Xe.selectionEnd=ye,Xe.focus()),Te(X,ye)})},[h.execution.prompt,J,Te]),ne=nt.useCallback(R=>{if(O&&Q.current&&(R.key==="Enter"||R.key==="ArrowUp"||R.key==="ArrowDown"||R.key==="Escape"||R.key==="Tab")){R.preventDefault(),Q.current.handleKeyDown(R.key);return}k&&Z.current&&(R.key==="Enter"||R.key==="ArrowUp"||R.key==="ArrowDown"||R.key==="Escape"||R.key==="Tab")&&(R.preventDefault(),Z.current.handleKeyDown(R.key)),$&&le.current&&(R.key==="Enter"||R.key==="ArrowUp"||R.key==="ArrowDown"||R.key==="Escape"||R.key==="Tab")&&(R.preventDefault(),le.current.handleKeyDown(R.key))},[O,k,$]),ce=nt.useCallback(async()=>{const R=B2(h,i);if(R){Ae.error(R);return}const ae={...h.id?{id:h.id}:{},name:h.name.trim(),enabled:h.enabled,schedule:{kind:h.schedule.kind,timezone:h.schedule.timezone.trim(),...h.schedule.kind==="cron"?{cron:h.schedule.cronExpression.trim()}:h.schedule.kind==="once"?{date:h.schedule.onceDate,time:h.schedule.onceTime}:{times:_2(h.schedule.times),...h.schedule.kind==="weekly"?{weekdays:h.schedule.weekdays}:{}}},execution:{prompt:h.execution.prompt,providerID:h.execution.providerID,modelID:h.execution.modelID,...h.execution.variant.trim()?{variant:h.execution.variant.trim()}:{},...h.execution.agent.trim()?{agent:h.execution.agent.trim()}:{},...h.execution.permissionAutoAccept?{permissionAutoAccept:!0}:{},...h.execution.goalEnabled?{goalEnabled:!0}:{},...h.execution.goalEnabled&&h.execution.goalTokenBudget?{goalTokenBudget:h.execution.goalTokenBudget}:{}},...h.state?{state:h.state}:{}};S(!0);try{await o(ae),r(!1)}catch(Se){Ae.error(Se instanceof Error?Se.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{S(!1)}},[h,r,o,i]),Fe=nt.useId(),Ye=nt.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"][data-open], [data-slot="select-content"][data-open]'),[]),$e=i(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),ie=i("sessions.scheduledTasks.editor.description"),Re=s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Hs,{htmlFor:"sched-name",required:!0,children:i("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(tr,{id:"sched-name",value:h.name,onChange:R=>b(ae=>({...ae,name:R.target.value})),placeholder:i("sessions.scheduledTasks.editor.taskName.placeholder"),maxLength:80,className:"w-full sm:max-w-[220px]"})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Hs,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(Ks,{value:h.schedule.kind,onValueChange:R=>{b(ae=>({...ae,schedule:{...ae.schedule,kind:R,...R==="cron"&&!ae.schedule.cronExpression?{cronExpression:"0 * * * *"}:{}}}))},children:[s.jsx(Gs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Es,{children:R=>i(R==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":R==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":R==="cron"?"sessions.scheduledTasks.editor.scheduleType.cron":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(qs,{children:[s.jsx(is,{value:"daily",children:i("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(is,{value:"weekly",children:i("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(is,{value:"once",children:i("sessions.scheduledTasks.editor.scheduleType.once")}),s.jsx(is,{value:"cron",children:i("sessions.scheduledTasks.editor.scheduleType.cron")})]})]})]})]}),h.schedule.kind==="cron"?s.jsx($2,{draft:h,setDraft:b,locale:c,t:i}):h.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:W,children:[s.jsx(Hs,{children:i("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:ge(Ru({size:"default"}),"w-fit max-w-full"),onClick:()=>A(R=>!R),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(T,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:D2(h.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),c)})]}),s.jsx(T,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),N?s.jsxs("div",{className:"absolute left-0 top-[calc(100%+6px)] z-50 w-[288px] rounded-xl border border-border bg-background p-3 shadow-sm",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>_(R=>Td(R,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:Me,children:s.jsx(T,{name:"arrow-left-s",className:"h-4 w-4"})}),s.jsx("div",{className:"typography-ui-label text-foreground",children:new Intl.DateTimeFormat(c,{month:"long",year:"numeric"}).format(I)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>_(R=>Td(R,1)),"aria-label":i("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(T,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:ee.map((R,ae)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:R},`${R}-${ae}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:P2(I,H).map(({date:R,inCurrentMonth:ae})=>{const Se=Ed(R),Ce=Se===h.schedule.onceDate,Ee=Fd(R,Le),se=R.getTime()<Le.getTime(),je=Ce?"bg-interactive-selection text-interactive-selection-foreground":se?"text-muted-foreground/40":ae?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{se||(oe(Se),A(!1))},disabled:se,className:["h-8 rounded-md typography-ui-label",je,Ee&&!Ce?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",se?"cursor-not-allowed opacity-45":""].join(" "),children:R.getDate()},Se)})}),s.jsxs("div",{className:"mt-2 flex items-center justify-between border-t border-border pt-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:ve||""}),s.jsx(lt,{type:"button",size:"xs",variant:"ghost",onClick:()=>{oe(Ed(Le)),_(new Date(Le.getFullYear(),Le.getMonth(),1))},children:i("sessions.scheduledTasks.editor.date.jumpToToday")})]})]}):null]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Hs,{children:i("sessions.scheduledTasks.editor.time.label")}),s.jsx(Md,{value:h.schedule.onceTime,use24Hour:xe,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:R=>b(ae=>({...ae,schedule:{...ae.schedule,onceTime:R}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(Hs,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Ks,{value:h.schedule.timezone,onValueChange:R=>{b(ae=>({...ae,schedule:{...ae.schedule,timezone:R}}))},children:[s.jsx(Gs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Es,{})}),s.jsx(qs,{children:rl.map(R=>s.jsx(is,{value:R,children:R},R))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[h.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(Hs,{children:i("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:we.map(R=>{const ae=h.schedule.weekdays.includes(R.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",ae?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(qr,{checked:ae,onChange:Se=>be(R.value,Se),ariaLabel:R.label}),s.jsx("button",{type:"button",onClick:()=>be(R.value,!ae),className:"group-hover:text-foreground",children:R.label})]},R.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(Hs,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:h.schedule.times.map((R,ae)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Md,{value:R,use24Hour:xe,hourAriaLabel:i("sessions.scheduledTasks.editor.time.hourAria"),minuteAriaLabel:i("sessions.scheduledTasks.editor.time.minuteAria"),periodAriaLabel:i("sessions.scheduledTasks.editor.time.periodAria"),amLabel:i("sessions.scheduledTasks.editor.time.period.am"),pmLabel:i("sessions.scheduledTasks.editor.time.period.pm"),onChange:Se=>Pe(ae,Se)}),h.schedule.times.length>1?s.jsx(lt,{type:"button",size:"icon",variant:"ghost",onClick:()=>Ie(ae),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(T,{name:"close",className:"h-4 w-4"})}):null]},ae))}),s.jsx("div",{children:s.jsxs(lt,{type:"button",size:"sm",variant:"outline",onClick:De,children:[s.jsx(T,{name:"add",className:"mr-1 h-4 w-4"})," ",i("sessions.scheduledTasks.editor.times.add")]})})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Hs,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Ks,{value:h.schedule.timezone,onValueChange:R=>{b(ae=>({...ae,schedule:{...ae.schedule,timezone:R}}))},children:[s.jsx(Gs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Es,{})}),s.jsx(qs,{children:rl.map(R=>s.jsx(is,{value:R,children:R},R))})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Hs,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(Rp,{providerId:h.execution.providerID,modelId:h.execution.modelID,onChange:(R,ae)=>{b(Se=>({...Se,execution:{...Se.execution,providerID:R,modelID:ae,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Hs,{children:i("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(Ks,{value:me,disabled:!q,onValueChange:R=>{b(ae=>({...ae,execution:{...ae.execution,variant:R==="__default"?"":R}}))},children:[s.jsx(Gs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Es,{children:R=>R==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):R})}),s.jsxs(qs,{children:[s.jsx(is,{value:"__default",children:i("sessions.scheduledTasks.editor.thinkingLevel.default")}),de.map(R=>s.jsx(is,{value:R,children:R},R))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Hs,{children:i("sessions.scheduledTasks.editor.agent.label")}),s.jsx(Mp,{agentName:h.execution.agent,filter:R=>Iu(R.mode),onChange:R=>b(ae=>({...ae,execution:{...ae.execution,agent:R}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Hs,{htmlFor:"sched-prompt",required:!0,children:i("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(Kr,{id:"sched-prompt",ref:K,value:h.execution.prompt,onChange:R=>{const ae=R.target.value;J(ae);const Se=R.target.selectionStart??ae.length;Te(ae,Se)},onKeyDown:ne,rows:8,placeholder:i("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),O?s.jsx(Lu,{ref:Q,searchQuery:E,onCommandSelect:U,onClose:()=>F(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,k?s.jsx(Bu,{ref:Z,searchQuery:P,onFileSelect:re,onAgentSelect:Y,onClose:()=>C(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,$?s.jsx(_u,{ref:le,searchQuery:V,onSnippetSelect:fe,onClose:()=>z(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]}),h.execution.goalEnabled?s.jsxs("div",{className:"flex flex-wrap items-center gap-x-8 gap-y-2",children:[s.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-2",children:[s.jsx(qr,{checked:h.execution.goalTokenBudget!==null,onChange:R=>b(ae=>({...ae,execution:{...ae.execution,goalTokenBudget:R?2e5:null}})),ariaLabel:i("sessions.scheduledTasks.editor.goal.budgetAria")}),s.jsx("span",{className:"typography-meta",children:i("sessions.scheduledTasks.editor.goal.budgetLabel")})]}),h.execution.goalTokenBudget!==null?s.jsx(Op,{value:h.execution.goalTokenBudget,onValueChange:R=>{typeof R=="number"&&Number.isFinite(R)&&R>0&&b(ae=>({...ae,execution:{...ae.execution,goalTokenBudget:Math.floor(R)}}))},min:1e3,max:1e8,step:5e4}):null]}):null]}),ue=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[s.jsxs("label",{className:"inline-flex items-center gap-2",children:[s.jsx(qr,{checked:h.enabled,onChange:R=>b(ae=>({...ae,enabled:R})),ariaLabel:i("sessions.scheduledTasks.editor.enabled.aria")}),s.jsx("span",{className:"typography-meta",children:i("sessions.scheduledTasks.editor.enabled.label")})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",className:ge(Dd),onClick:()=>b(R=>({...R,execution:{...R.execution,permissionAutoAccept:!R.execution.permissionAutoAccept}})),"aria-pressed":h.execution.permissionAutoAccept,"aria-label":i("sessions.scheduledTasks.editor.permissionAutoAccept.aria"),children:h.execution.permissionAutoAccept?s.jsx(T,{name:"shield-check",className:"h-[18px] w-[18px]",style:{color:"var(--status-info)"},"aria-hidden":"true"}):s.jsx(T,{name:"shield-user",className:"h-[18px] w-[18px]","aria-hidden":"true"})})}),s.jsx(ht,{side:"top",sideOffset:6,children:i("sessions.scheduledTasks.editor.permissionAutoAccept.label")})]}),s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",className:ge(Dd,h.execution.goalEnabled&&"text-[var(--status-info)]"),onClick:()=>b(R=>({...R,execution:{...R.execution,goalEnabled:!R.execution.goalEnabled}})),"aria-pressed":h.execution.goalEnabled,"aria-label":i("sessions.scheduledTasks.editor.goal.aria"),children:h.execution.goalEnabled?s.jsx(T,{name:"target-fill",className:"h-[18px] w-[18px] text-current","aria-hidden":"true"}):s.jsx(T,{name:"target",className:"h-[18px] w-[18px] text-current","aria-hidden":"true"})})}),s.jsx(ht,{side:"top",sideOffset:6,children:i("sessions.scheduledTasks.editor.goal.label")})]}),s.jsx(lt,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:v,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(lt,{type:"button",size:"sm",onClick:ce,disabled:v,children:i(v?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return p?s.jsx(Ui,{open:e,title:$e,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:R=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:$e}),R]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:ie})]}),footer:ue,children:Re}):s.jsx(Ls,{open:e,onOpenChange:R=>{!R&&Ye()||r(R)},children:s.jsxs(Bs,{"aria-describedby":Fe,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(rn,{id:Fe,className:"sr-only",children:ie}),s.jsx("header",{className:"shrink-0 px-4 sm:px-6 pt-5 pb-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl",children:[s.jsx(nn,{className:"typography-ui-label font-medium text-foreground",children:$e}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:ie})]})}),s.jsx(ul,{className:"flex-1 min-h-0 overflow-auto [scrollbar-gutter:stable_both-edges]",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 pb-5",children:Re})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsx("div",{className:"mx-auto w-full max-w-2xl",children:ue})})]})})}function U2(t){return ro(t,{min:0,max:23})}function W2(t,e){return ro(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function V2(t,e){const n=Number(t),r=Number(e),o=Number.isFinite(n)?Math.min(23,Math.max(0,n)):0,i=Number.isFinite(r)?Math.min(59,Math.max(0,r)):0;return`${String(o).padStart(2,"0")}:${String(i).padStart(2,"0")}`}function H2(t){return s.jsx(is,{value:t,children:t},t)}const K2=t=>{const n=(Array.isArray(t.schedule.times)?t.schedule.times:t.schedule.time?[t.schedule.time]:[]).filter(r=>typeof r=="string"&&/^([01]\d|2[0-3]):([0-5]\d)$/.test(r));return Array.from(new Set(n)).sort((r,o)=>r.localeCompare(o))},G2=(t,e)=>{const n=K2(t).join(", ")||"--:--",r=o=>e(o===0?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sun":o===1?"sessions.scheduledTasks.dialog.schedule.weekdayShort.mon":o===2?"sessions.scheduledTasks.dialog.schedule.weekdayShort.tue":o===3?"sessions.scheduledTasks.dialog.schedule.weekdayShort.wed":o===4?"sessions.scheduledTasks.dialog.schedule.weekdayShort.thu":o===5?"sessions.scheduledTasks.dialog.schedule.weekdayShort.fri":o===6?"sessions.scheduledTasks.dialog.schedule.weekdayShort.sat":"sessions.scheduledTasks.dialog.schedule.weekdayShort.unknown");if(t.schedule.kind==="daily")return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.dailyWithTimezone",{time:n,timezone:Fr(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.daily",{time:n});if(t.schedule.kind==="weekly"){const o=Array.isArray(t.schedule.weekdays)?t.schedule.weekdays.map(i=>r(i)).join(", "):"";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.weeklyWithTimezone",{days:o,time:n,timezone:Fr(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.weekly",{days:o,time:n})}if(t.schedule.kind==="once"){const o=typeof t.schedule.date=="string"&&t.schedule.date.trim().length>0?t.schedule.date:e("sessions.scheduledTasks.dialog.schedule.unknownDate"),i=typeof t.schedule.time=="string"&&t.schedule.time.trim().length>0?t.schedule.time:"--:--";return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.onceWithTimezone",{date:o,time:i,timezone:Fr(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.once",{date:o,time:i})}return t.schedule.timezone?e("sessions.scheduledTasks.dialog.schedule.cronWithTimezone",{cron:t.schedule.cron||"",timezone:Fr(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.cron",{cron:t.schedule.cron||""})},q2=(t,e)=>!t||!Number.isFinite(t)?"":yu(t,e),Bd=(t,e)=>{if(!t||!Number.isFinite(t))return"";const n=t-Date.now(),r=Math.abs(n),o=6e4,i=60*o,c=24*i,a=n>=0;if(r<o)return e(a?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<i){const f=Math.round(r/o);return a?e("sessions.scheduledTasks.dialog.relativeTime.inMinutes",{count:f}):e("sessions.scheduledTasks.dialog.relativeTime.minutesAgo",{count:f})}if(r<c){const f=Math.floor(r/i),g=Math.round(r%i/o),x=g>0?`${f}h ${g}m`:`${f}h`;return a?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:x}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:x})}const d=Math.floor(r/c),u=Math.round(r%c/i),m=u>0?`${d}d ${u}h`:`${d}d`;return a?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:m}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:m})},Y2={success:{tone:"success",Icon:"checkbox-circle"},error:{tone:"error",Icon:"error-warning"},running:{tone:"warning",Icon:"loader-4",spin:!0},idle:{tone:"muted",Icon:"pulse"}},Q2=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function _d(){const{t}=gt(),e=pe(y=>y.isScheduledTasksDialogOpen),n=pe(y=>y.setScheduledTasksDialogOpen),r=pe(y=>y.isMobile),o=pe(y=>y.timeFormatPreference),i=Gt(y=>y.projects),c=Gt(y=>y.getActiveProject()),a=ls(y=>y.homeDirectory),{currentTheme:d}=_r(),[u,m]=nt.useState(""),[f,g]=nt.useState([]),[x,j]=nt.useState(!0),[w,p]=nt.useState(!1),[h,b]=nt.useState(null),[v,S]=nt.useState(null),N=nt.useMemo(()=>i.find(y=>y.id===u)||null,[i,u]),A=nt.useCallback(y=>{const I=y.label?.trim()||gr(y.path,a||void 0),_=y.icon?pl[y.icon]:null,W=y.color?gl[y.color]:void 0,K=_?s.jsx(T,{name:_,className:"h-3.5 w-3.5 shrink-0",style:W?{color:W}:void 0}):s.jsx(T,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:W?{color:W}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[y.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:y.iconBackground?{backgroundColor:y.iconBackground}:void 0,children:s.jsx(xl,{project:{id:y.id,iconImage:y.iconImage??null},options:{themeVariant:d.metadata.variant,iconColor:d.colors.surface.foreground},className:"h-full w-full object-contain",fallback:K})}):K,s.jsx("span",{className:"truncate",children:I})]})},[a,d.metadata.variant,d.colors.surface.foreground]),k=nt.useCallback(async(y,I)=>{if(!y){g([]);return}I?.silent||j(!0);try{const _=await Xg(y);_.sort((W,K)=>{if(W.enabled!==K.enabled)return W.enabled?-1:1;const Z=W.name.localeCompare(K.name);return Z!==0?Z:(W.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(K.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),g(_)}catch(_){Ae.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),I?.silent||g([])}finally{I?.silent||j(!1)}},[t]);nt.useEffect(()=>{if(!e)return;const y=c?.id||i[0]?.id||"";m(y),y?k(y):(g([]),j(!1))},[e,c,i,k]),nt.useEffect(()=>{if(!e)return;let y=null;const I=Yi(_=>{_.type==="scheduled-task-ran"&&_.projectId===u&&(y&&clearTimeout(y),y=setTimeout(()=>{k(u,{silent:!0})},400))});return()=>{y&&clearTimeout(y),I()}},[e,u,k]);const C=nt.useCallback(async y=>{if(!u)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await wc(u,y),await k(u),Ae.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[u,k,t]),P=nt.useCallback(async(y,I)=>{if(u){S(y.id),g(_=>_.map(W=>W.id===y.id?{...W,enabled:I}:W));try{y.loopFile?await Jg(u,y.id,I):await wc(u,{...y,enabled:I}),await k(u,{silent:!0})}catch(_){Ae.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await k(u,{silent:!0})}finally{S(null)}}},[u,k,t]),D=nt.useCallback(async y=>{if(!(!u||!window.confirm(y.loopFile?t("sessions.scheduledTasks.dialog.confirm.deleteLoopFile",{taskName:y.name}):t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:y.name})))){S(y.id);try{y.loopFile?await Zg(u,y.id):await ex(u,y.id),await k(u,{silent:!0}),Ae.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(_){Ae.error(_ instanceof Error?_.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{S(null)}}},[u,k,t]),O=nt.useCallback(y=>{if(!y.loopFile){b(y),p(!0);return}if(N?.path){if(n(!1),r){Bn.getState().setSelectedPath(N.path,y.loopFile,{allowOutsideRoot:!0}),pe.getState().setActiveMainTab("files");return}pe.getState().openContextFile(N.path,y.loopFile)}},[r,N?.path,n]),F=nt.useCallback(async y=>{if(u){S(y.id);try{const{sessionId:I,persistError:_}=await tx(u,y.id);if(await Promise.all([k(u,{silent:!0}),vi()]),_?Ae.warning(t("sessions.scheduledTasks.dialog.toast.startedPersistWarning")):Ae.success(t("sessions.scheduledTasks.dialog.toast.started")),I){const W=i.find(K=>K.id===u);ot.getState().setCurrentSession(I,W?.path??null),pe.getState().setActiveMainTab("chat")}}catch(I){Ae.error(I instanceof Error?I.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{S(null)}}},[u,i,k,t]),E=s.jsxs("div",{className:"flex flex-col items-start gap-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.label")}),s.jsxs(Ks,{value:u||"__none",onValueChange:y=>{const I=y==="__none"?"":y;m(I),I?k(I):g([])},children:[s.jsx(Gs,{size:"lg",className:r?"w-full":void 0,children:N?s.jsx(Es,{children:A(N)}):s.jsx(Es,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(qs,{children:[i.length===0?s.jsx(is,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,i.map(y=>s.jsx(is,{value:y.id,children:A(y)},y.id))]})]})]}),B=()=>{b(null),p(!0)},$=y=>{m(y),y?k(y):g([])},z=s.jsx("div",{className:"min-h-[280px]",children:x?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(T,{name:"loader-4",className:"h-4 w-4 animate-spin"})," ",t("sessions.scheduledTasks.dialog.loading")]}):f.length===0?s.jsx("div",{className:"rounded-lg border border-dashed border-border p-4 typography-meta text-muted-foreground",children:t(u?"sessions.scheduledTasks.dialog.empty.noTasks":"sessions.scheduledTasks.dialog.empty.selectProject")}):s.jsx("div",{className:"space-y-2.5",children:f.map(y=>{const I=v===y.id,_=y.state?.lastStatus||"idle",W=Y2[_],K=t(_==="success"?"sessions.scheduledTasks.dialog.status.success":_==="error"?"sessions.scheduledTasks.dialog.status.error":_==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),Z=y.state?.nextRunAt,Q=y.state?.lastRunAt;return s.jsxs("div",{className:ge("rounded-lg border border-border p-4 transition-opacity",!y.enabled&&"opacity-60"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-header truncate font-semibold text-foreground",children:y.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:G2(y,t)}),y.loopFile?s.jsx("div",{className:"typography-micro truncate text-muted-foreground/70",title:y.loopFile,children:t("sessions.scheduledTasks.dialog.loopFile.note",{file:y.loopFile})}):null]}),s.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-5 gap-y-1 typography-micro text-muted-foreground",children:[s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(T,{name:"timer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.nextRun.label")}),Z?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:Bd(Z,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:q2(Z,o)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(T,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),_==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(T,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):Q?s.jsxs(s.Fragment,{children:[W.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${W.tone})`},children:[s.jsx(T,{name:W.Icon,className:"h-3.5 w-3.5"}),K]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:Bd(Q,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),y.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:Q2("error"),children:[s.jsx(T,{name:"error-warning",className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"min-w-0 break-words",children:y.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:ge("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",y.enabled?"text-foreground":"text-muted-foreground",I&&"cursor-not-allowed opacity-50"),children:[s.jsx(qr,{checked:y.enabled,onChange:le=>{P(y,le)},ariaLabel:y.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:y.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:y.name}),disabled:I}),y.enabled?t("sessions.scheduledTasks.dialog.taskToggle.enabled"):t("sessions.scheduledTasks.dialog.taskToggle.paused")]}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsxs(lt,{variant:"outline",size:"sm",onClick:()=>{F(y)},disabled:I,children:[s.jsx(T,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(lt,{variant:"outline",size:"sm",onClick:()=>O(y),disabled:I,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:y.name}),children:[s.jsx(T,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(lt,{variant:"destructive",size:"sm",onClick:()=>{D(y)},disabled:I,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:y.name}),children:s.jsx(T,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},y.id)})})}),V=s.jsxs("div",{className:"space-y-4",children:[E,z]});return s.jsxs(s.Fragment,{children:[r?s.jsx(Ui,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:y=>s.jsxs("div",{className:"flex flex-col gap-1 border-b border-border/40 px-3 py-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("h2",{className:"typography-ui-label font-semibold text-foreground",children:t("sessions.scheduledTasks.dialog.title")}),y]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(lt,{className:"w-full",onClick:B,disabled:!u,children:[s.jsx(T,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:V}):e?s.jsx("div",{className:"absolute inset-0 z-10 flex flex-col bg-background",children:s.jsxs("div",{className:"flex min-h-0 flex-1",children:[s.jsx("div",{className:"flex w-60 flex-shrink-0 flex-col border-r border-border/50",children:s.jsx("div",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:i.length===0?s.jsx("div",{className:"px-2 py-2 typography-meta text-muted-foreground",children:t("sessions.scheduledTasks.dialog.project.empty")}):i.map(y=>s.jsx("button",{type:"button",onClick:()=>$(y.id),className:ge("flex w-full min-w-0 items-center rounded-md px-2 py-1.5 text-left typography-ui-label focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",u===y.id?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground"),children:A(y)},y.id))})}),s.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[s.jsx("div",{className:"flex items-center px-6 pt-3",children:s.jsxs(lt,{size:"sm",onClick:B,disabled:!u,children:[s.jsx(T,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]})}),s.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-6 py-4",children:s.jsx("div",{className:"mx-auto w-full max-w-3xl",children:z})})]})]})}):null,s.jsx(z2,{open:w,task:h,onOpenChange:p,onSave:C})]})}const gi=100;function $d(){const t=it.c(105),{t:e}=gt(),n=pe(ok),r=pe(rk),o=pe(nk),i=ot(sk),c=ot(tk),a=ls(ek);let d;t[0]!==n?(d=Q=>n?Q.archivedSessions:[],t[0]=n,t[1]=d):d=t[1];const u=Fs(Jn(d)),[m,f]=l.useState(""),[g,x]=l.useState(null),[j,w]=l.useState(gi);let p;t[2]!==m?(p=m.trim().toLowerCase(),t[2]=m,t[3]=p):p=t[3];const h=p;let b;e:{if(!n){let le;t[4]===Symbol.for("react.memo_cache_sentinel")?(le=[],t[4]=le):le=t[4],b=le;break e}let Q;t[5]!==u?(Q=[...u].sort(Z2),t[5]=u,t[6]=Q):Q=t[6],b=Q}const v=b;let S;if(t[7]!==a||t[8]!==v||t[9]!==e){const Q=new Map;for(const le of v){const te=jt(Qs(le))??"",he=Q.get(te);if(he){he.sessions.push(le);continue}Q.set(te,{directory:te,label:te?gr(te,a)||te:e("sessions.archivePage.otherProjects"),sessions:[le]})}S=[...Q.values()].sort(J2),t[7]=a,t[8]=v,t[9]=e,t[10]=S}else S=t[10];const N=S;let A;e:{if(h){let le;if(t[11]!==h||t[12]!==v){let te;t[14]!==h?(te=he=>(he.title??"").toLowerCase().includes(h),t[14]=h,t[15]=te):te=t[15],le=v.filter(te),t[11]=h,t[12]=v,t[13]=le}else le=t[13];A=le;break e}if(g===null){A=v;break e}let Q;t[16]!==N||t[17]!==g?(Q=N.find(le=>le.directory===g)?.sessions??[],t[16]=N,t[17]=g,t[18]=Q):Q=t[18],A=Q}const k=A;let C,P,D,O,F,E,B,$,z,V;if(t[19]!==u.length||t[20]!==N||t[21]!==k||t[22]!==a||t[23]!==h||t[24]!==n||t[25]!==m||t[26]!==g||t[27]!==o||t[28]!==i||t[29]!==r||t[30]!==e||t[31]!==c||t[32]!==j){F=Symbol.for("react.early_return_sentinel");e:{const Q=k.slice(0,j);C=k.length-Q.length;const le=u.length;let te;t[43]===Symbol.for("react.memo_cache_sentinel")?(te=ee=>{x(ee),w(gi)},t[43]=te):te=t[43];const he=te;let xe;t[44]!==o||t[45]!==i||t[46]!==r?(xe=ee=>{const oe=jt(Qs(ee));i(ee.id,oe??void 0),o("chat"),r(!1)},t[44]=o,t[45]=i,t[46]=r,t[47]=xe):xe=t[47];const H=xe;let we;t[48]!==e||t[49]!==c?(we=ee=>{c(ee.id).then(oe=>{oe?Ae.success(e("sessions.sidebar.session.restore.success")):Ae.error(e("sessions.sidebar.session.restore.error"))})},t[48]=e,t[49]=c,t[50]=we):we=t[50];const de=we;if(!n){F=null;break e}let q;t[51]!==e?(q=(ee,oe,Te,J,re,Y,U)=>s.jsxs("div",{className:"group/dir relative",children:[s.jsxs("button",{type:"button",onClick:re,title:Y,className:ge("flex w-full min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left typography-ui-label transition-[padding] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",U?"group-hover/dir:pr-8 group-focus-within/dir:pr-8":"",J?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground"),children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:oe}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground/70",children:Te})]}),U?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>Un.requestDelete({sessions:U,mode:"session"}),className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover/dir:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.archivePage.deleteProjectAria",{label:oe}),children:s.jsx(T,{name:"delete-bin",className:"h-3.5 w-3.5"})})}),s.jsx(ht,{side:"bottom",sideOffset:4,children:e("sessions.archivePage.deleteProject")})]}):null]},ee),t[51]=e,t[52]=q):q=t[52];const me=q;O="absolute inset-0 z-10 flex flex-col bg-background",P="flex min-h-0 flex-1";let be;if(t[53]!==me||t[54]!==g||t[55]!==e||t[56]!==le){let ee;t[58]===Symbol.for("react.memo_cache_sentinel")?(ee=()=>he(null),t[58]=ee):ee=t[58],be=me("__all__",e("sessions.archivePage.allDirectories"),le,g===null,ee),t[53]=me,t[54]=g,t[55]=e,t[56]=le,t[57]=be}else be=t[57];let Pe;if(t[59]!==N||t[60]!==me||t[61]!==g){let ee;t[63]!==me||t[64]!==g?(ee=oe=>me(oe.directory||"__none__",oe.label,oe.sessions.length,g===oe.directory,()=>he(oe.directory),oe.directory||void 0,oe.sessions),t[63]=me,t[64]=g,t[65]=ee):ee=t[65],Pe=N.map(ee),t[59]=N,t[60]=me,t[61]=g,t[62]=Pe}else Pe=t[62];t[66]!==be||t[67]!==Pe?(D=s.jsx("div",{className:"flex w-64 flex-shrink-0 flex-col border-r border-border/50",children:s.jsxs("div",{className:"flex-1 space-y-0.5 overflow-y-auto p-2",children:[be,Pe]})}),t[66]=be,t[67]=Pe,t[68]=D):D=t[68],z="flex min-w-0 flex-1 flex-col";let Ie;t[69]===Symbol.for("react.memo_cache_sentinel")?(Ie=s.jsx(T,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),t[69]=Ie):Ie=t[69];let De;t[70]===Symbol.for("react.memo_cache_sentinel")?(De=ee=>{f(ee.target.value),w(gi)},t[70]=De):De=t[70];let Le;t[71]!==e?(Le=e("sessions.archivePage.searchPlaceholder"),t[71]=e,t[72]=Le):Le=t[72];let Ne;t[73]!==m||t[74]!==Le?(Ne=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Ie,s.jsx("input",{value:m,onChange:De,placeholder:Le,className:"h-8 w-full rounded-md border border-border bg-transparent pl-8 pr-3 typography-ui-label text-foreground outline-none focus-visible:ring-2 focus-visible:ring-primary/50"})]}),t[73]=m,t[74]=Le,t[75]=Ne):Ne=t[75];let ve;t[76]!==k.length||t[77]!==e?(ve=k.length===1?e("sessions.archivePage.countSingle",{count:k.length}):e("sessions.archivePage.countPlural",{count:k.length}),t[76]=k.length,t[77]=e,t[78]=ve):ve=t[78];let Me;t[79]!==ve?(Me=s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:ve}),t[79]=ve,t[80]=Me):Me=t[80],t[81]!==Ne||t[82]!==Me?(V=s.jsxs("div",{className:"flex items-center gap-3 px-6 pt-3",children:[Ne,Me]}),t[81]=Ne,t[82]=Me,t[83]=V):V=t[83],$="min-h-0 flex-1 overflow-y-auto px-6 py-3",E="mx-auto w-full max-w-3xl space-y-0.5",B=Q.length===0?s.jsx("div",{className:"py-10 text-center text-muted-foreground",children:s.jsx("p",{className:"typography-ui-label font-semibold",children:e(h?"sessions.archivePage.empty.noMatches":"sessions.archivePage.empty.noArchived")})}):Q.map(ee=>{const oe=jt(Qs(ee))??"",Te=oe?gr(oe,a)||oe:null;return s.jsxs("div",{className:"group relative flex cursor-pointer items-center gap-3 rounded-md py-1 pl-2 pr-2 transition-[padding] hover:bg-interactive-hover/40 hover:pr-14 focus-within:pr-14",onClick:()=>H(ee),role:"button",tabIndex:0,onKeyDown:J=>{(J.key==="Enter"||J.key===" ")&&(J.preventDefault(),H(ee))},children:[s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:ee.title||e("sessions.sidebar.session.untitled")}),h&&Te?s.jsx("span",{className:"max-w-40 flex-shrink-0 truncate text-[0.72rem] text-muted-foreground/70",title:oe,children:Te}):null,s.jsx("span",{className:"flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Ou(ee.time?.archived??ee.time?.updated??ee.time?.created??Date.now())}),s.jsx("button",{type:"button",onClick:J=>{J.stopPropagation(),de(ee)},className:"absolute right-7 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-foreground group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.archivePage.restoreSessionAria",{title:ee.title||e("sessions.sidebar.session.untitled")}),children:s.jsx(T,{name:"inbox-unarchive",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:J=>{J.stopPropagation(),Un.requestDelete({sessions:[ee],mode:"session"})},className:"absolute right-1 top-1/2 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-md text-muted-foreground opacity-0 transition-opacity pointer-events-none hover:text-destructive group-hover:opacity-100 group-hover:pointer-events-auto focus-visible:opacity-100 focus-visible:pointer-events-auto focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":e("sessions.archivePage.deleteSessionAria",{title:ee.title||e("sessions.sidebar.session.untitled")}),children:s.jsx(T,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},ee.id)})}t[19]=u.length,t[20]=N,t[21]=k,t[22]=a,t[23]=h,t[24]=n,t[25]=m,t[26]=g,t[27]=o,t[28]=i,t[29]=r,t[30]=e,t[31]=c,t[32]=j,t[33]=C,t[34]=P,t[35]=D,t[36]=O,t[37]=F,t[38]=E,t[39]=B,t[40]=$,t[41]=z,t[42]=V}else C=t[33],P=t[34],D=t[35],O=t[36],F=t[37],E=t[38],B=t[39],$=t[40],z=t[41],V=t[42];if(F!==Symbol.for("react.early_return_sentinel"))return F;let y;t[84]!==C||t[85]!==e?(y=C>0?s.jsx("button",{type:"button",onClick:()=>w(X2),className:"mt-1 flex items-center justify-start rounded-md px-2 py-1 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showMore")}):null,t[84]=C,t[85]=e,t[86]=y):y=t[86];let I;t[87]!==y||t[88]!==E||t[89]!==B?(I=s.jsxs("div",{className:E,children:[B,y]}),t[87]=y,t[88]=E,t[89]=B,t[90]=I):I=t[90];let _;t[91]!==I||t[92]!==$?(_=s.jsx("div",{className:$,children:I}),t[91]=I,t[92]=$,t[93]=_):_=t[93];let W;t[94]!==_||t[95]!==z||t[96]!==V?(W=s.jsxs("div",{className:z,children:[V,_]}),t[94]=_,t[95]=z,t[96]=V,t[97]=W):W=t[97];let K;t[98]!==P||t[99]!==D||t[100]!==W?(K=s.jsxs("div",{className:P,children:[D,W]}),t[98]=P,t[99]=D,t[100]=W,t[101]=K):K=t[101];let Z;return t[102]!==O||t[103]!==K?(Z=s.jsx("div",{className:O,children:K}),t[102]=O,t[103]=K,t[104]=Z):Z=t[104],Z}function X2(t){return t+gi}function J2(t,e){return e.sessions.length-t.sessions.length}function Z2(t,e){return(e.time?.archived??0)-(t.time?.archived??0)}function ek(t){return t.homeDirectory}function tk(t){return t.unarchiveSession}function sk(t){return t.setCurrentSession}function nk(t){return t.setActiveMainTab}function rk(t){return t.setArchivePageOpen}function ok(t){return t.isArchivePageOpen}function zd(){const t=it.c(18),{t:e}=gt(),n=pe(lk),r=pe(ak),o=Gt(ik);let i;t[0]!==n?(i=x=>x.projects.find(j=>j.id===n)??null,t[0]=n,t[1]=i):i=t[1];const c=Gt(i);if(!n||!c)return null;let a;t[2]!==c.id||t[3]!==o||t[4]!==r?(a=()=>{o(c.id),r(!0)},t[2]=c.id,t[3]=o,t[4]=r,t[5]=a):a=t[5];let d;t[6]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(T,{name:"node-tree",className:"mr-1 h-3.5 w-3.5"}),t[6]=d):d=t[6];let u;t[7]!==e?(u=e("sessions.sidebar.project.actions.newWorktree"),t[7]=e,t[8]=u):u=t[8];let m;t[9]!==a||t[10]!==u?(m=s.jsx("div",{className:"flex items-center",children:s.jsxs(lt,{size:"sm",onClick:a,children:[d,u]})}),t[9]=a,t[10]=u,t[11]=m):m=t[11];let f;t[12]!==c.id||t[13]!==c.path?(f=s.jsx(Bg,{projectRef:{id:c.id,path:c.path},sections:"list-only"}),t[12]=c.id,t[13]=c.path,t[14]=f):f=t[14];let g;return t[15]!==m||t[16]!==f?(g=s.jsx("div",{className:"absolute inset-0 z-10 flex flex-col bg-background",children:s.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-4",children:s.jsxs("div",{className:"mx-auto w-full max-w-4xl space-y-4",children:[m,f]})})}),t[15]=m,t[16]=f,t[17]=g):g=t[17],g}function ik(t){return t.setActiveProjectIdOnly}function ak(t){return t.setNewWorktreeDialogOpen}function lk(t){return t.worktreesPageProjectId}const ol=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),ck=(t,e)=>{const n=ol(t),r=ol(e);return`${n}-${r}`.substring(0,60)},Ud=(t,e)=>`${t}/${e}`,dk=t=>{const e=t.replace(/\\/g,"/");return e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e},Wd=(t,e)=>{const n=dk(e),r=t.directory,o=typeof r=="string"&&r.trim().length>0?t:{...t,directory:n};Wp(t.id,n),ot.getState().markSessionAsOpenChamberCreated(t.id),Fs.getState().upsertSession(o);try{wi().ensureChild(n,{bootstrap:!1}).setState(c=>{const a=c.session.findIndex(u=>u.id===t.id);if(a>=0&&c.session[a]===o)return c;const d=a>=0?c.session.map((u,m)=>m===a?o:u):[...c.session,o].sort((u,m)=>u.id.localeCompare(m.id));return{session:d,sessionTotal:Math.max(c.sessionTotal,d.length),limit:Math.max(c.limit,d.length)}})}catch{}return o},uk=()=>{const t=Gt.getState(),e=t.activeProjectId;if(!e)return null;const n=t.projects.find(o=>o.id===e);if(n?.path)return{id:n.id,path:n.path};const r=ls.getState().currentDirectory??null;if(r&&r.trim().length>0){const o=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${o}`,path:o}}return null},Na=br()(Zu(t=>({isLoading:!1,error:null,createMultiRun:async e=>{const n=e.name.trim(),{groups:r,agent:o,files:i,setupCommands:c}=e;if(!n)return t({error:"Group name is required"}),null;if(!r||r.length===0)return t({error:"At least one run group is required"}),null;for(let a=0;a<r.length;a++){if(!r[a].prompt.trim())return t({error:`Group ${a+1}: prompt is required`}),null;if(r[a].models.length<1)return t({error:`Group ${a+1}: select at least 1 model`}),null;if(r[a].models.length>5)return t({error:`Group ${a+1}: maximum 5 models allowed`}),null}t({isLoading:!0,error:null});try{const a=uk();if(!a)return t({error:"Select a project",isLoading:!1}),null;const d=a.path,m=await Fu(d)&&e.isolateRuns!==!1,f=ol(n),g=m?await Wi(d):void 0,x=m?await Fp(d):null,j=[],w=c?.filter(S=>S.trim().length>0)??[];for(let S=0;S<r.length;S++){const N=r[S],A=N.prompt,k=new Map;for(const P of N.models){const D=`${P.providerID}:${P.modelID}`;k.set(D,(k.get(D)||0)+1)}const C=new Map;for(const P of N.models){const D=`${P.providerID}:${P.modelID}`,O=k.get(D)||1,F=(C.get(D)||0)+1;C.set(D,F);const E=ck(P.providerID,P.modelID),B=r.length>1?`g${S+1}`:void 0,$=O>1?Ud(f,`${E}/${F}`):Ud(f,E),z=B?`${B}/${$}`:$,V=Ej({groupSlug:f,runGroup:B,providerID:P.providerID,modelID:P.modelID,index:O>1?F:void 0});try{if(!m){const W=await sn.withDirectory(d,()=>sn.createSession({title:V}));Wd(W,d),j.push({sessionId:W.id,worktreePath:d,providerID:P.providerID,modelID:P.modelID,variant:P.variant,prompt:A});continue}const y=await Lp(a,{preferredName:z,mode:"new",branchName:z,worktreeName:z,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:w,returnAfterDirectoryCreated:!0},{resolvedRootTrackingRemote:x}),I={...y,createdFromBranch:g,kind:"standard"};await Bp(a)&&await _p(y.path);const _=await sn.withDirectory(y.path,()=>sn.createSession({title:V}));Wd(_,y.path),ot.getState().setWorktreeMetadata(_.id,I),j.push({sessionId:_.id,worktreePath:y.path,providerID:P.providerID,modelID:P.modelID,variant:P.variant,prompt:A})}catch(y){console.warn("[MultiRun] Failed to create session:",y)}}}const p=c?.filter(S=>S.trim().length>0)??[];p.length>0&&$p(a,p).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const h=j.map(S=>S.sessionId),b=j[0]?.sessionId??null;if(h.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const v=i?.map(S=>({type:"file",mime:S.mime,filename:S.filename,url:S.url}));return(async()=>{try{const S=zp.getState().expandText;await Promise.allSettled(j.map(async N=>{try{const A=await S(N.prompt).catch(()=>N.prompt);await Up({sessionId:N.sessionId,directory:N.worktreePath,content:A,providerID:N.providerID,modelID:N.modelID,variant:N.variant,agent:o,files:v})}catch(A){console.warn("[MultiRun] Failed to start run:",A)}}))}catch(S){console.warn("[MultiRun] Failed to start runs:",S)}})(),t({isLoading:!1}),{groupSlug:f,sessionIds:h,firstSessionId:b}}catch(a){return t({error:a instanceof Error?a.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"}));function Jf(t){const e=it.c(30),{git:n}=rr(),r=wu(t),o=Vp(t),i=Hp(t),c=Kp(t),a=pr(gk),d=pr(pk);let u,m;e[0]!==t||e[1]!==d||e[2]!==n||e[3]!==o||e[4]!==i?(u=()=>{!t||!n||o!==null||i||d(t,n,{silent:!0})},m=[t,n,d,o,i],e[0]=t,e[1]=d,e[2]=n,e[3]=o,e[4]=i,e[5]=u,e[6]=m):(u=e[5],m=e[6]),l.useEffect(u,m);let f;e[7]!==r?.all||e[8]!==t||e[9]!==a||e[10]!==n||e[11]!==o?(f=()=>{!t||!n||o===!0&&(r?.all||a(t,n))},e[7]=r?.all,e[8]=t,e[9]=a,e[10]=n,e[11]=o,e[12]=f):f=e[12];const g=r?.all;let x;e[13]!==t||e[14]!==a||e[15]!==n||e[16]!==o||e[17]!==g?(x=[t,n,o,g,a],e[13]=t,e[14]=a,e[15]=n,e[16]=o,e[17]=g,e[18]=x):x=e[18],l.useEffect(f,x);const j=i||o===!0&&c;let w;e:{if(!r?.all){let k;e[19]===Symbol.for("react.memo_cache_sentinel")?(k=[],e[19]=k):k=e[19],w=k;break e}let A;e[20]!==r.all?(A=r.all.filter(hk).sort(),e[20]=r.all,e[21]=A):A=e[21],w=A}const p=w;let h;e:{if(!r?.all){let k;e[22]===Symbol.for("react.memo_cache_sentinel")?(k=[],e[22]=k):k=e[22],h=k;break e}let A;e[23]!==r.all?(A=r.all.filter(mk).map(fk).sort(),e[23]=r.all,e[24]=A):A=e[24],h=A}const b=h;let v;e:{if(!t){v=null;break e}if(o!==null){v=o;break e}if(j){v=null;break e}v=r?.all?!0:null}const S=v;let N;return e[25]!==S||e[26]!==j||e[27]!==p||e[28]!==b?(N={localBranches:p,remoteBranches:b,isLoading:j,isGitRepository:S},e[25]=S,e[26]=j,e[27]=p,e[28]=b,e[29]=N):N=e[29],N}function fk(t){return t.replace(/^remotes\//,"")}function mk(t){return t.startsWith("remotes/")}function hk(t){return!t.startsWith("remotes/")}function pk(t){return t.fetchStatus}function gk(t){return t.fetchBranches}const xk=({directory:t,value:e,onChange:n,className:r,disabled:o,id:i})=>{const{t:c}=gt(),{localBranches:a,remoteBranches:d,isLoading:u,isGitRepository:m}=Jf(t),f=l.useMemo(()=>[...a,...d.map(x=>`remotes/${x}`)],[a,d]);l.useEffect(()=>{if(o||u||f.length===0||e&&f.includes(e))return;const x=e;let j=!1;return(async()=>{try{const p=t?await Wi(t).catch(()=>null):null;if(j)return;const h=localStorage.getItem(vc),{sourceBranch:b,shouldClearSavedSourceBranch:v}=_g({branches:f,savedSourceBranch:h,rootBranch:p});if(v&&localStorage.removeItem(vc),j||x&&f.includes(x))return;b&&n(b)}catch{}})(),()=>{j=!0}},[f,t,o,u,n,e]);const g=o||!m||u;return s.jsxs("div",{children:[s.jsxs(Ks,{value:e,onValueChange:n,disabled:g,children:[s.jsx(Gs,{id:i,size:"lg",className:ge("min-w-0 max-w-full *:data-[slot=select-value]:truncate",r??"w-fit"),children:s.jsx(Es,{placeholder:c(u?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(qs,{className:"max-h-[280px] max-w-[320px]",children:u?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:c("multiRun.branchSelector.status.loadingBranches")}):a.length===0&&d.length===0?s.jsx("div",{className:"px-2 py-4 text-center typography-meta text-muted-foreground",children:c("multiRun.branchSelector.status.noBranchesFound")}):s.jsxs(s.Fragment,{children:[a.length>0&&s.jsxs(Fa,{children:[s.jsx(uc,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.localBranches")}),a.map(x=>s.jsx(is,{value:x,className:"whitespace-normal break-all",children:x},x))]}),a.length>0&&d.length>0&&s.jsx(Gp,{}),d.length>0&&s.jsxs(Fa,{children:[s.jsx(uc,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.remoteBranches")}),d.map(x=>s.jsx(is,{value:`remotes/${x}`,className:"whitespace-normal break-all",children:x},`remotes/${x}`))]})]})})]}),m===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:c("multiRun.branchSelector.status.notInGitRepository")})]})},bk=10*1024*1024,Aa=5,xi=t=>{const e=it.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",tabIndex:-1,className:"inline-flex items-center justify-center text-muted-foreground/50 hover:text-muted-foreground transition-colors",children:s.jsx(T,{name:"information",className:"h-3.5 w-3.5"})})}),e[0]=r):r=e[0];let o;return e[1]!==n?(o=s.jsxs(ft,{children:[r,s.jsx(ht,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=o):o=e[2],o},Mr=t=>{const e=it.c(9),{htmlFor:n,required:r,children:o,info:i}=t;let c;e[0]!==r?(c=r&&s.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),e[0]=r,e[1]=c):c=e[1];let a;e[2]!==o||e[3]!==n||e[4]!==c?(a=s.jsxs("label",{htmlFor:n,className:"typography-meta font-medium text-foreground",children:[o,c]}),e[2]=o,e[3]=n,e[4]=c,e[5]=a):a=e[5];const d=i&&i;let u;return e[6]!==a||e[7]!==d?(u=s.jsxs("div",{className:"flex items-center gap-1.5",children:[a,d]}),e[6]=a,e[7]=d,e[8]=u):u=e[8],u},Vd=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:o}=gt(),[i,c]=l.useState(""),[a,d]=l.useState(()=>[{id:ko(),prompt:"",models:[]}]),[u,m]=l.useState(""),[f,g]=l.useState([]),[x,j]=l.useState(!1),[w,p]=l.useState([]),[h,b]=l.useState(!1),[v,S]=l.useState(!1),[N,A]=l.useState(!0),k=l.useRef(null),C=ls(U=>U.currentDirectory??null),P=ls(U=>U.homeDirectory??null),D=l.useMemo(()=>{if(typeof window>"u")return null;const U=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof U=="string"&&U.trim().length>0?U.trim():null},[]),O=Gt(U=>U.activeProjectId),F=Gt(U=>U.setActiveProjectIdOnly),E=Gt(U=>U.projects),[B,$]=l.useState(()=>O??null);l.useEffect(()=>{if(O){$(O);return}!B&&E.length>0&&$(E[0].id)},[O,E,B]);const z=l.useMemo(()=>B?E.find(U=>U.id===B)??null:null,[E,B]),V=z?.path??C,y=l.useCallback(U=>{$(U),U!==O&&F(U)},[O,F]),{currentTheme:I}=_r(),_=l.useCallback(U=>{const fe=U.label?.trim()||gr(U.path,P),ne=U.icon?pl[U.icon]:null,ce=U.color?gl[U.color]:void 0,Fe=ne?s.jsx(T,{name:ne,className:"h-3.5 w-3.5 shrink-0",style:ce?{color:ce}:void 0}):s.jsx(T,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:ce?{color:ce}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[U.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:U.iconBackground?{backgroundColor:U.iconBackground}:void 0,children:s.jsx(xl,{project:{id:U.id,iconImage:U.iconImage??null},options:{themeVariant:I.metadata.variant,iconColor:I.colors.surface.foreground},className:"h-full w-full object-contain",fallback:Fe})}):Fe,s.jsx("span",{className:"truncate",children:fe})]})},[P,I.metadata.variant,I.colors.surface.foreground]),W=l.useMemo(()=>{if(z?.path)return{id:z.id,path:z.path};const U=C??D;return U?{id:`path:${U}`,path:U}:null},[z,C,D]),[K]=l.useState(()=>typeof window<"u"?Wn():!1),Z=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),Q=mu(),le=l.useMemo(()=>{if(typeof window>"u")return null;const U=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof U=="number"&&Number.isFinite(U)&&U>0)return U;if(typeof navigator>"u")return null;const fe=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!fe)return null;const ne=Number.parseInt(fe[1],10),ce=Number.parseInt(fe[2],10);return Number.isNaN(ne)?null:ne===10?ce:ne},[]),te=l.useMemo(()=>K&&Z||Q?"pl-[5.5rem]":"pl-3",[K,Z,Q]),he=l.useMemo(()=>!K||!Z||le===null?"":le>=26?"h-12":le<=15?"h-14":"",[K,Z,le]),xe=l.useCallback(async U=>{U.target.closest("button, a, input, select, textarea")||U.button===0&&K&&await qp()},[K]);l.useEffect(()=>{if(!n)return;const U=fe=>{fe.key==="Escape"&&(fe.preventDefault(),fe.stopPropagation(),n())};return window.addEventListener("keydown",U,!0),()=>window.removeEventListener("keydown",U,!0)},[n]);const[H,we]=l.useState(""),{isLoading:de,isGitRepository:q}=Jf(V),me=l.useRef(!1),be=q===!0,Pe=be&&N;l.useEffect(()=>{if(q===!1){me.current=!0,A(!1);return}q===!0&&me.current&&(me.current=!1,A(!0))},[q]);const Ie=Na(U=>U.createMultiRun),De=Na(U=>U.error),Le=Na(U=>U.clearError);l.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(U=>{const fe=[...U];return fe.length>0&&!fe[0].prompt.trim()&&(fe[0]={...fe[0],prompt:t}),fe})},[t]),l.useEffect(()=>{if(!W)return;let U=!1;return S(!0),(async()=>{try{const fe=await Yp(W);U||p(fe)}catch{}finally{U||S(!1)}})(),()=>{U=!0}},[W]);const Ne=l.useCallback((U,fe)=>{d(ne=>ne.map(ce=>ce.id===U?{...ce,...fe}:ce))},[]),ve=l.useCallback(U=>{d(fe=>fe.filter(ne=>ne.id!==U))},[]),Me=l.useCallback(()=>{d(U=>[...U,{id:ko(),prompt:"",models:[]}])},[]),ee=async U=>{const fe=U.target.files;if(!fe)return;let ne=0;for(let ce=0;ce<fe.length;ce++){const Fe=fe[ce];if(Fe.size>bk){Ae.error(o("multirun.launcher.toast.fileTooLarge",{fileName:Fe.name}));continue}try{const Ye=await new Promise(($e,ie)=>{const Re=new FileReader;Re.onload=()=>$e(Re.result),Re.onerror=ie,Re.readAsDataURL(Fe)});g($e=>[...$e,{id:ko(),filename:Fe.name,mimeType:Fe.type||"application/octet-stream",size:Fe.size,dataUrl:Ye}]),ne++}catch(Ye){console.error("File attach failed",Ye),Ae.error(o("multirun.launcher.toast.attachFailed",{fileName:Fe.name}))}}ne>0&&Ae.success(ne===1?o("multirun.launcher.toast.attachedSingle",{count:ne}):o("multirun.launcher.toast.attachedPlural",{count:ne})),k.current&&(k.current.value="")},oe=U=>{g(fe=>fe.filter(ne=>ne.id!==U))},Te=l.useMemo(()=>a.reduce((U,fe)=>U+fe.models.length,0),[a]),J=async U=>{U.preventDefault();const fe=a.filter(ne=>ne.prompt.trim()&&ne.models.length>=1);if(fe.length!==0&&!(Te<1)){j(!0),Le();try{B&&B!==O&&F(B);const ne=f.map(ie=>({mime:ie.mimeType,filename:ie.filename,url:ie.dataUrl})),ce=w.filter(ie=>ie.trim().length>0),Fe=fe.map(ie=>({prompt:ie.prompt.trim(),models:ie.models.map(Re=>({providerID:Re.providerID,modelID:Re.modelID,displayName:Re.displayName,variant:Re.variant}))})),Ye={name:i.trim(),groups:Fe,agent:u||void 0,worktreeBaseBranch:Pe?H:void 0,isolateRuns:Pe,files:ne.length>0?ne:void 0,setupCommands:ce.length>0?ce:void 0},$e=await Ie(Ye);$e&&($e.firstSessionId&&ot.getState().setCurrentSession($e.firstSessionId),e?.())}finally{j(!1)}}},re=!!(i.trim()&&a.some(U=>U.prompt.trim()&&U.models.length>=1)&&Te>=1&&V&&!de&&(q===!1||!Pe||H)),Y=w.filter(U=>U.trim()).length;return s.jsxs("form",{onSubmit:J,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:xe,className:ge("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",te,he),style:{borderColor:"var(--interactive-border)"},children:[s.jsx("h1",{className:"typography-ui-label font-medium",children:o("multirun.launcher.title")}),n&&s.jsx("div",{className:"absolute right-0 flex items-center pr-3",children:s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":o("multirun.launcher.actions.closeEsc"),className:"inline-flex h-9 w-9 items-center justify-center p-2 rounded-lg text-muted-foreground hover:text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary app-region-no-drag",children:s.jsx(T,{name:"close",className:"h-5 w-5"})})}),s.jsx(ht,{children:s.jsx("p",{children:o("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(ul,{className:"flex-1 min-h-0 overflow-auto",size:64,hideTopShadow:!0,children:s.jsx("div",{className:"mx-auto w-full max-w-2xl px-4 sm:px-6 py-5",children:s.jsxs("div",{className:"flex flex-col gap-5",children:[s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:[s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Mr,{htmlFor:"multirun-project",required:!0,children:o("multirun.launcher.project.label")}),E.length>0?s.jsxs(Ks,{value:B??void 0,onValueChange:y,children:[s.jsx(Gs,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:z?s.jsx(Es,{children:_(z)}):s.jsx(Es,{placeholder:o("multirun.launcher.project.placeholder")})}),s.jsx(qs,{fitContent:!0,children:E.map(U=>s.jsx(is,{value:U.id,className:"max-w-[24rem]",children:_(U)},U.id))})]}):s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:o("multirun.launcher.project.empty")})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Mr,{htmlFor:"group-name",required:!0,info:s.jsx(xi,{children:o("multirun.launcher.groupName.info")}),children:o("multirun.launcher.groupName.label")}),s.jsx(tr,{id:"group-name",value:i,onChange:U=>c(U.target.value),placeholder:o("multirun.launcher.groupName.placeholder"),className:"typography-meta w-full",required:!0})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Mr,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(xi,{children:o("multirun.launcher.baseBranch.info")}),children:o("multirun.launcher.baseBranch.label")}),s.jsx(xk,{directory:V,value:H,onChange:we,disabled:!Pe,id:"multirun-worktree-base-branch"}),s.jsxs("label",{className:"mt-1.5 flex w-fit items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(qr,{checked:N,onChange:A,disabled:!be,ariaLabel:o("multirun.launcher.isolateRuns.label")}),s.jsx("span",{children:o("multirun.launcher.isolateRuns.label")})]})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Mr,{htmlFor:"multirun-agent",info:s.jsx(xi,{children:o("multirun.launcher.agent.info")}),children:o("multirun.launcher.agent.label")}),s.jsx(qf,{value:u,onChange:m,id:"multirun-agent"})]})]}),s.jsxs(Si,{open:h,onOpenChange:b,children:[s.jsxs(vl,{className:"w-full flex items-center gap-2 py-1.5 px-2 -mx-2 rounded-lg hover:bg-[var(--interactive-hover)]/50 transition-colors group",children:[s.jsx(T,{name:"terminal",className:"h-3.5 w-3.5 text-muted-foreground/70"}),s.jsx("span",{className:"typography-meta font-medium text-muted-foreground group-hover:text-foreground transition-colors",children:o("multirun.launcher.setupCommands.label")}),Y>0&&s.jsx("span",{className:"inline-flex items-center justify-center h-4 min-w-4 px-1 rounded-full typography-micro font-medium",style:{backgroundColor:"var(--primary-base)",color:"var(--primary-foreground)",fontSize:"0.625rem",lineHeight:1},children:Y}),s.jsx(T,{name:"arrow-down-s",className:ge("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",h&&"rotate-180")})]}),s.jsx(ji,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:v?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:o("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[w.map((U,fe)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(tr,{value:U,onChange:ne=>{const ce=[...w];ce[fe]=ne.target.value,p(ce)},placeholder:o("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>p(w.filter((ne,ce)=>ce!==fe)),className:"flex-shrink-0 flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-label":o("multirun.launcher.setupCommands.removeCommandAria"),children:s.jsx(T,{name:"close",className:"h-3.5 w-3.5"})})]},`${U}-${fe}`)),s.jsxs("button",{type:"button",onClick:()=>p([...w,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(T,{name:"add",className:"h-3 w-3"}),o("multirun.launcher.setupCommands.addCommand")]})]})})})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Mr,{htmlFor:"prompt",required:!0,children:o("multirun.launcher.attachments.label")}),s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[s.jsx("input",{ref:k,type:"file",multiple:!0,className:"hidden",onChange:ee,accept:"*/*"}),s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>k.current?.click(),className:"inline-flex items-center gap-1 h-6 px-2 rounded-md typography-micro text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(T,{name:"attachment-2",className:"h-3 w-3"}),o("multirun.launcher.attachments.attach")]})}),s.jsx(ht,{children:o("multirun.launcher.attachments.tooltip")})]}),f.map(U=>s.jsxs("div",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-md typography-micro border",style:{backgroundColor:"var(--surface-elevated)",borderColor:"var(--interactive-border)"},children:[U.mimeType.startsWith("image/")?s.jsx(T,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(T,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:U.filename,children:U.filename}),s.jsx("button",{type:"button",onClick:()=>oe(U.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(T,{name:"close",className:"h-3 w-3"})})]},U.id))]})]}),a.map((U,fe)=>s.jsx(yk,{group:U,groupIndex:fe,canRemove:a.length>1,onUpdate:Ne,onRemove:ve},U.id)),s.jsxs("button",{type:"button",onClick:Me,className:"flex items-center gap-1.5 py-2 px-3 -mx-3 rounded-lg typography-meta font-medium text-muted-foreground hover:text-foreground hover:bg-[var(--interactive-hover)]/50 transition-colors",children:[s.jsx(T,{name:"add",className:"h-3.5 w-3.5"}),o("multirun.launcher.groups.addGroup")]}),De&&s.jsx("div",{className:"px-3 py-2 rounded-lg typography-meta",style:{backgroundColor:"var(--status-error-background)",color:"var(--status-error)",borderWidth:1,borderColor:"var(--status-error-border)"},children:De})]})})}),s.jsx("div",{className:"shrink-0 px-4 sm:px-6 py-3",children:s.jsxs("div",{className:"mx-auto w-full max-w-2xl flex items-center justify-end gap-2",children:[!Pe&&q!==null?s.jsxs("div",{className:"mr-auto flex min-w-0 items-center gap-1.5 typography-micro text-muted-foreground",children:[s.jsx(T,{name:"information",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:o("multirun.launcher.project.gitRequired")})]}):null,!r&&n?s.jsx(lt,{type:"button",variant:"ghost",size:"sm",onClick:n,children:o("multirun.launcher.actions.cancel")}):null,s.jsx(lt,{type:"submit",size:"sm",disabled:!re||x,children:x?o("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:o("multirun.launcher.actions.startWithRunCount",{count:Te})})})]})})]})},yk=t=>{const e=it.c(99),{group:n,groupIndex:r,canRemove:o,onUpdate:i,onRemove:c}=t,{t:a}=gt(),[d,u]=l.useState(!1),[m,f]=l.useState(""),[g,x]=l.useState(!1),[j,w]=l.useState(""),[p,h]=l.useState(!1),[b,v]=l.useState(""),S=l.useRef(null),N=l.useRef(null),A=l.useRef(null),k=l.useRef(null);let C;e[0]!==n.id||e[1]!==n.models||e[2]!==i?(C=ce=>{n.models.length>=Aa||i(n.id,{models:[...n.models,ce]})},e[0]=n.id,e[1]=n.models,e[2]=i,e[3]=C):C=e[3];const P=C;let D;e[4]!==n.id||e[5]!==n.models||e[6]!==i?(D=ce=>{i(n.id,{models:n.models.filter((Fe,Ye)=>Ye!==ce)})},e[4]=n.id,e[5]=n.models,e[6]=i,e[7]=D):D=e[7];const O=D;let F;e[8]!==n.id||e[9]!==n.models||e[10]!==i?(F=(ce,Fe)=>{i(n.id,{models:n.models.map((Ye,$e)=>$e===ce?Fe:Ye)})},e[8]=n.id,e[9]=n.models,e[10]=i,e[11]=F):F=e[11];const E=F;let B;e[12]===Symbol.for("react.memo_cache_sentinel")?(B=(ce,Fe)=>{if(ce.startsWith("/")){const Re=ce.indexOf(" "),ue=ce.indexOf(`
918
+ `),R=Math.min(Re===-1?ce.length:Re,ue===-1?ce.length:ue);if(Fe<=R&&Re===-1){w(ce.substring(1,R)),x(!0),u(!1),h(!1);return}}x(!1);const Ye=ce.substring(0,Fe),$e=Ye.lastIndexOf("#");if($e!==-1){const Re=$e>0?Ye[$e-1]:null,ue=Ye.substring($e+1);if((!Re||/\s/.test(Re))&&!ue.includes(" ")&&!ue.includes(`
919
+ `)){v(ue),h(!0),u(!1);return}}h(!1);const ie=Ye.lastIndexOf("@");if(ie!==-1){const Re=ie>0?Ye[ie-1]:null,ue=Ye.substring(ie+1);(!Re||/\s/.test(Re))&&!ue.includes(" ")&&!ue.includes(`
920
+ `)?(f(ue),u(!0)):u(!1);return}u(!1)},e[12]=B):B=e[12];const $=B;let z;e[13]!==n.id||e[14]!==i?(z=ce=>{i(n.id,{prompt:ce})},e[13]=n.id,e[14]=i,e[15]=z):z=e[15];const V=z;let y;e[16]!==n.prompt||e[17]!==V?(y=ce=>{const Fe=n.prompt,$e=S.current?.selectionStart??Fe.length,Re=Fe.substring(0,$e).lastIndexOf("@"),ue=ce.relativePath&&ce.relativePath.trim().length>0?ce.relativePath.trim():ce.path||ce.name,R=Re!==-1?Re:$e,ae=`${Fe.substring(0,R)}@${ue} ${Fe.substring($e)}`,Se=R+ue.length+2;V(ae),u(!1),f(""),requestAnimationFrame(()=>{const Ce=S.current;Ce&&(Ce.selectionStart=Se,Ce.selectionEnd=Se,Ce.focus()),$(ae,Se)})},e[16]=n.prompt,e[17]=V,e[18]=y):y=e[18];const I=y;let _;e[19]!==n.prompt||e[20]!==V?(_=ce=>{const Fe=n.prompt,$e=S.current?.selectionStart??Fe.length,Re=Fe.substring(0,$e).lastIndexOf("@"),ue=Re!==-1?Re:$e,R=`${Fe.substring(0,ue)}@${ce} ${Fe.substring($e)}`,ae=ue+ce.length+2;V(R),u(!1),f(""),requestAnimationFrame(()=>{const Se=S.current;Se&&(Se.selectionStart=ae,Se.selectionEnd=ae,Se.focus()),$(R,ae)})},e[19]=n.prompt,e[20]=V,e[21]=_):_=e[21];const W=_;let K;e[22]!==V?(K=ce=>{const Fe=`/${ce.name} `;V(Fe),x(!1),w(""),h(!1),requestAnimationFrame(()=>{const Ye=S.current;Ye&&(Ye.focus(),Ye.selectionStart=Ye.value.length,Ye.selectionEnd=Ye.value.length),$(Fe,Fe.length)})},e[22]=V,e[23]=K):K=e[23];const Z=K;let Q;e[24]!==n.prompt||e[25]!==V?(Q=(ce,Fe)=>{const Ye=n.prompt,ie=S.current?.selectionStart??Ye.length,ue=Ye.substring(0,ie).lastIndexOf("#"),R=ue!==-1?ue:ie,ae=`${Ye.substring(0,R)}#${Fe} ${Ye.substring(ie)}`,Se=R+Fe.length+2;V(ae),h(!1),v(""),requestAnimationFrame(()=>{const Ce=S.current;Ce&&(Ce.selectionStart=Se,Ce.selectionEnd=Se,Ce.focus()),$(ae,Se)})},e[24]=n.prompt,e[25]=V,e[26]=Q):Q=e[26];const le=Q;let te;e[27]!==g||e[28]!==d||e[29]!==p?(te=ce=>{if(g&&A.current&&(ce.key==="Enter"||ce.key==="ArrowUp"||ce.key==="ArrowDown"||ce.key==="Escape"||ce.key==="Tab")){ce.preventDefault(),A.current.handleKeyDown(ce.key);return}d&&N.current&&(ce.key==="Enter"||ce.key==="ArrowUp"||ce.key==="ArrowDown"||ce.key==="Escape"||ce.key==="Tab")&&(ce.preventDefault(),N.current.handleKeyDown(ce.key)),p&&k.current&&(ce.key==="Enter"||ce.key==="ArrowUp"||ce.key==="ArrowDown"||ce.key==="Escape"||ce.key==="Tab")&&(ce.preventDefault(),k.current.handleKeyDown(ce.key))},e[27]=g,e[28]=d,e[29]=p,e[30]=te):te=e[30];const he=te,xe=r+1;let H;e[31]!==a||e[32]!==xe?(H=a("multirun.launcher.groups.groupLabel",{index:xe}),e[31]=a,e[32]=xe,e[33]=H):H=e[33];let we;e[34]!==H?(we=s.jsx("span",{className:"typography-meta font-medium text-foreground",children:H}),e[34]=H,e[35]=we):we=e[35];let de;e[36]!==o||e[37]!==n.id||e[38]!==c||e[39]!==a?(de=o&&s.jsx("button",{type:"button",onClick:()=>c(n.id),className:"inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10","aria-label":a("multirun.launcher.groups.removeGroup"),children:s.jsx(T,{name:"close",className:"h-3.5 w-3.5"})}),e[36]=o,e[37]=n.id,e[38]=c,e[39]=a,e[40]=de):de=e[40];let q;e[41]!==we||e[42]!==de?(q=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[we,de]}),e[41]=we,e[42]=de,e[43]=q):q=e[43];let me;e[44]!==a?(me=a("multirun.launcher.groups.prompt.label"),e[44]=a,e[45]=me):me=e[45];let be;e[46]!==me?(be=s.jsx(Mr,{required:!0,children:me}),e[46]=me,e[47]=be):be=e[47];const Pe=n.prompt;let Ie;e[48]!==V?(Ie=ce=>{const Fe=ce.target.value;V(Fe);const Ye=ce.target.selectionStart??Fe.length;$(Fe,Ye)},e[48]=V,e[49]=Ie):Ie=e[49];let De;e[50]!==a?(De=a("multirun.launcher.groups.prompt.placeholder"),e[50]=a,e[51]=De):De=e[51];let Le;e[52]!==n.prompt||e[53]!==he||e[54]!==Ie||e[55]!==De?(Le=s.jsx(Kr,{ref:S,value:Pe,onChange:Ie,onKeyDown:he,placeholder:De,className:"typography-meta min-h-[80px] max-h-[200px] resize-none overflow-y-auto field-sizing-content",required:!0}),e[52]=n.prompt,e[53]=he,e[54]=Ie,e[55]=De,e[56]=Le):Le=e[56];let Ne;e[57]!==j||e[58]!==Z||e[59]!==g?(Ne=g?s.jsx(Lu,{ref:A,searchQuery:j,onCommandSelect:Z,onClose:()=>x(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[57]=j,e[58]=Z,e[59]=g,e[60]=Ne):Ne=e[60];let ve;e[61]!==W||e[62]!==I||e[63]!==m||e[64]!==d?(ve=d?s.jsx(Bu,{ref:N,searchQuery:m,onFileSelect:I,onAgentSelect:W,onClose:()=>u(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[61]=W,e[62]=I,e[63]=m,e[64]=d,e[65]=ve):ve=e[65];let Me;e[66]!==le||e[67]!==p||e[68]!==b?(Me=p?s.jsx(_u,{ref:k,searchQuery:b,onSnippetSelect:le,onClose:()=>h(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[66]=le,e[67]=p,e[68]=b,e[69]=Me):Me=e[69];let ee;e[70]!==Le||e[71]!==Ne||e[72]!==ve||e[73]!==Me?(ee=s.jsxs("div",{className:"relative",children:[Le,Ne,ve,Me]}),e[70]=Le,e[71]=Ne,e[72]=ve,e[73]=Me,e[74]=ee):ee=e[74];let oe;e[75]!==be||e[76]!==ee?(oe=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[be,ee]}),e[75]=be,e[76]=ee,e[77]=oe):oe=e[77];let Te;e[78]!==a?(Te=a("multirun.launcher.models.info",{max:Aa}),e[78]=a,e[79]=Te):Te=e[79];let J;e[80]!==Te?(J=s.jsx(xi,{children:Te}),e[80]=Te,e[81]=J):J=e[81];let re;e[82]!==a?(re=a("multirun.launcher.models.label"),e[82]=a,e[83]=re):re=e[83];let Y;e[84]!==J||e[85]!==re?(Y=s.jsx(Mr,{required:!0,info:J,children:re}),e[84]=J,e[85]=re,e[86]=Y):Y=e[86];let U;e[87]!==n.models||e[88]!==P||e[89]!==O||e[90]!==E?(U=s.jsx(Yf,{selectedModels:n.models,onAdd:P,onRemove:O,onUpdate:E,minModels:1,maxModels:Aa}),e[87]=n.models,e[88]=P,e[89]=O,e[90]=E,e[91]=U):U=e[91];let fe;e[92]!==Y||e[93]!==U?(fe=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[Y,U]}),e[92]=Y,e[93]=U,e[94]=fe):fe=e[94];let ne;return e[95]!==q||e[96]!==oe||e[97]!==fe?(ne=s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[q,oe,fe]}),e[95]=q,e[96]=oe,e[97]=fe,e[98]=ne):ne=e[98],ne},vk=l.createContext(null),wk=t=>{const e=it.c(3),{children:n,value:r}=t;let o;return e[0]!==n||e[1]!==r?(o=s.jsx(vk.Provider,{value:r,children:n}),e[0]=n,e[1]=r,e[2]=o):o=e[2],o},Sk=an(()=>on(()=>import("./PlanView-UvuxIl9-.js"),__vite__mapDeps([136,1,2,4,5,6,7,8,124,50,51,52,53,54,55,72,48,49,56,125,126,127,3,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,73,74,75,76,77,78,79,80,81,113,114,133,115,116,101,102,86,87,88,89,90,91,92,93,94,95,96,97,98,99])).then(t=>({default:t.PlanView}))),Hd=an(()=>on(()=>import("./GitView-DsWXqWx3.js"),__vite__mapDeps([134,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,114,135,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,115,116,118,119,120,121])).then(t=>({default:t.GitView}))),jk=an(()=>on(()=>import("./DiffView-BWNq-0ov.js"),__vite__mapDeps([122,1,2,4,5,6,7,8,3,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121])).then(t=>({default:t.DiffView}))),kk=an(()=>on(()=>import("./FilesView-DB-Q0Gkz.js"),__vite__mapDeps([123,1,2,4,5,6,7,8,3,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,114,124,125,126,127,128,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,129,130,115,116,119,131,132,113,133])).then(t=>({default:t.FilesView}))),Ck=an(()=>on(()=>import("./DiagramView-LKGBwf4G.js"),__vite__mapDeps([137,1,2,4,5,6,7,8,3,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,131,132])).then(t=>({default:t.DiagramView}))),Nk=an(()=>on(()=>import("./SettingsView-3B9VN6Ys.js").then(t=>t.a),__vite__mapDeps([138,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,114,139,124,125,126,127,115,116,101,102,86,87,88,89,90,91,92,93,94,95,96,97,98,99,140,141])).then(t=>({default:t.SettingsView}))),Ak=an(()=>on(()=>import("./SettingsWindow-CqQNDKNd.js"),__vite__mapDeps([142,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,138,114,139,124,125,126,127,115,116,101,102,86,87,88,89,90,91,92,93,94,95,96,97,98,99,140,141])).then(t=>({default:t.SettingsWindow}))),Dk=()=>{const t=pe(y=>y.isSidebarOpen),e=pe(y=>y.activeMainTab),n=pe(y=>y.setIsMobile),r=pe(y=>y.isSessionSwitcherOpen),o=pe(y=>y.isSettingsDialogOpen),i=pe(y=>y.setSettingsDialogOpen),[c,a]=l.useState(!1);l.useEffect(()=>{o&&a(!0)},[o]);const d=pe(y=>y.isMultiRunLauncherOpen),u=pe(y=>y.setMultiRunLauncherOpen),m=pe(y=>y.multiRunLauncherPrefillPrompt),f=pe(y=>y.isScheduledTasksDialogOpen),g=pe(y=>y.isArchivePageOpen),x=pe(y=>y.worktreesPageProjectId),j=f||g||!!x||d;l.useEffect(()=>{const y=()=>pe.getState().closeMainSurfaces(),I=ot.subscribe((W,K)=>{const Z=!!W.currentSessionId&&W.currentSessionId!==K.currentSessionId,Q=!!W.newSessionDraft?.open&&W.newSessionDraft!==K.newSessionDraft;(Z||Q)&&y()}),_=pe.subscribe((W,K)=>{W.activeMainTab!==K.activeMainTab&&y()});return()=>{I(),_()}},[]);const{isMobile:w}=xr(),p=l.useRef(!1),[h,b]=l.useState(!1),[v,S]=l.useState(!1),[N,A]=l.useState(!1),[k,C]=l.useState(!1),P=l.useCallback(y=>{b(y),pe.getState().setSessionSwitcherOpen(y)},[]),D=l.useRef(typeof window>"u"?0:window.innerWidth),O=Cc(-D.current),F=nt.useRef(0),E=Cc(D.current),B=nt.useRef(0);nt.useEffect(()=>{w&&(F.current=window.innerWidth,B.current=window.innerWidth)},[w]),nt.useEffect(()=>{if(!w){A(!1);return}h&&A(!0),Nc(O,h?0:-F.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[h,w,O]),nt.useEffect(()=>{if(!w){C(!1);return}v&&C(!0),Nc(E,v?0:B.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[w,v,E]),nt.useEffect(()=>{if(w)return O.on("change",y=>{const I=F.current||D.current,_=h||y>-I+.5;A(W=>W===_?W:_)})},[w,O,h]),nt.useEffect(()=>{if(w)return E.on("change",y=>{const I=B.current||D.current,_=v||y<I-.5;C(W=>W===_?W:_)})},[w,v,E]),nt.useEffect(()=>{w&&!r&&h&&P(!1)},[r,w,h,P]),nt.useEffect(()=>{if(!w){p.current=!1;return}p.current||(p.current=!0,P(!1),S(!1))},[w,P]),nt.useEffect(()=>{if(!w||e!=="chat"||h||v||o)return;let y=!1,I;const _=W=>{I=window.setTimeout(()=>{if(y)return;const K=ot.getState(),Z=pe.getState();if(!(Z.activeMainTab!=="chat"||Z.isSettingsDialogOpen||K.currentSessionId||K.newSessionDraft?.open)){if(K.isLoading){_(250);return}K.openNewSessionDraft({automatic:!0})}},W)};return _(500),()=>{y=!0,I!==void 0&&window.clearTimeout(I)}},[e,w,o,h,v]),nt.useEffect(()=>{!w||!o||(P(!1),S(!1))},[w,o,P]),$g(),l.useEffect(()=>{pe.getState().isMobile!==w&&n(w)},[w,n]);const $=l.useCallback(()=>{h&&P(!1),S(!v)},[h,v,P]),z=l.useMemo(()=>{if(!w&&e!=="terminal"&&e!=="diagram")return null;switch(e){case"plan":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(Sk,{})});case"git":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(Hd,{isActive:!v})});case"diff":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(jk,{})});case"terminal":return s.jsx(Yu,{});case"files":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(kk,{})});case"context":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(qu,{})});case"diagram":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(Ck,{})});default:return null}},[e,w,v]),V=e==="chat";return s.jsx(zg,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:ge("main-content-safe-area",w?"flex h-[100dvh] flex-col":"relative flex h-[100dvh]","bg-background"),children:[s.jsx(Tw,{}),s.jsx(bS,{}),s.jsx(SS,{}),s.jsx(k2,{}),w?s.jsxs(wk,{value:{leftDrawerOpen:h,rightDrawerOpen:v,toggleLeftDrawer:()=>{const y=!h;v&&S(!1),P(y)},toggleRightDrawer:$,leftDrawerX:O,rightDrawerX:E,leftDrawerWidth:F,rightDrawerWidth:B,setMobileLeftDrawerOpen:P,setRightSidebarOpen:S},children:[!o&&s.jsx(Ic,{onToggleLeftDrawer:()=>{const y=!h;v&&S(!1),P(y)},onToggleRightDrawer:()=>{$()},leftDrawerOpen:h,rightDrawerOpen:v}),s.jsx("div",{"data-page-scroll-lock":"true",className:ge("flex flex-1 overflow-hidden relative",o&&"hidden"),children:s.jsxs("main",{className:"w-full h-full overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:ge("absolute inset-0",(!V||j)&&"invisible"),children:s.jsx(ds,{children:s.jsx(Ba,{active:V&&!o&&!j})})}),z&&s.jsx("div",{className:ge("absolute inset-0",j&&"invisible"),children:s.jsx(ds,{children:z})}),d&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(ds,{children:s.jsx(Vd,{initialPrompt:m,onCreated:()=>u(!1),onCancel:()=>u(!1)})})}),s.jsx(ds,{children:s.jsx(_d,{})}),s.jsx(ds,{children:s.jsx($d,{})}),s.jsx(ds,{children:s.jsx(zd,{})}),s.jsx(Ac.div,{className:ge("absolute inset-0 z-20 bg-sidebar",!N&&"pointer-events-none invisible"),"data-page-scroll-lock":"true",style:{x:O},"aria-hidden":!h,children:s.jsx(ds,{children:s.jsx(Ad,{mobileVariant:!0,isVisible:N})})}),k&&s.jsx(Ac.div,{className:"absolute inset-0 z-20 bg-sidebar","data-page-scroll-lock":"true",style:{x:E},"aria-hidden":!v,children:s.jsx(ds,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(Hd,{isActive:v})})})})]})}),o&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(ds,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(Nk,{onClose:()=>i(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx(yb,{}),s.jsxs("div",{className:"flex flex-1 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsx(gb,{isOpen:t,isMobile:w,className:"border-border",topBar:s.jsx(xb,{}),children:s.jsx(Ad,{isVisible:t})}),s.jsxs("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden bg-background","data-page-scroll-lock":"true",children:[s.jsx(Ic,{}),s.jsxs("div",{className:"relative flex flex-1 min-h-0 overflow-hidden bg-background","data-page-scroll-lock":"true",children:[s.jsx("div",{className:"relative flex flex-1 min-w-0 flex-col overflow-hidden border-t border-border bg-background","data-page-scroll-lock":"true",children:s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden","data-page-scroll-lock":"true",children:s.jsxs("div",{className:"relative flex flex-1 min-h-0 min-w-0 overflow-hidden","data-page-scroll-lock":"true","data-chat-area":"true",children:[s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:ge("absolute inset-0",(!V||j)&&"invisible"),children:s.jsx(ds,{children:s.jsx(Ba,{active:V&&!o&&!j})})}),z&&s.jsx("div",{className:ge("absolute inset-0",j&&"invisible"),children:s.jsx(ds,{children:z})}),d&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(ds,{children:s.jsx(Vd,{isWindowed:!0,initialPrompt:m,onCreated:()=>u(!1),onCancel:()=>u(!1)})})}),s.jsx(ds,{children:s.jsx(_d,{})}),s.jsx(ds,{children:s.jsx($d,{})}),s.jsx(ds,{children:s.jsx(zd,{})})]}),s.jsx(uw,{})]})})}),s.jsx("div",{className:"border-t border-border","data-page-scroll-lock":"true",children:s.jsx(ds,{children:s.jsx(xw,{})})})]})]})]}),c?s.jsx(l.Suspense,{fallback:null,children:s.jsx(Ak,{open:o,onOpenChange:i})}):null]})]})})},Zf=12,Pk=[{id:"left",x:22,y:58,delay:0,radius:120,colorVar:"--status-success"},{id:"center",x:50,y:42,delay:120,radius:150,colorVar:"--primary-base"},{id:"right",x:78,y:55,delay:200,radius:130,colorVar:"--status-info"}],Ek=t=>{const e=it.c(18),{isActive:n,burstKey:r,className:o,durationMs:i,bursts:c,onComplete:a}=t,d=r===void 0?0:r,u=i===void 0?900:i,m=c===void 0?Pk:c,f=nt.useRef(!1);let g,x;e[0]!==n||e[1]!==a?(g=()=>{!n&&f.current&&a?.(),n&&(f.current=!0)},x=[n,a],e[0]=n,e[1]=a,e[2]=g,e[3]=x):(g=e[2],x=e[3]),nt.useEffect(g,x);let j;e[4]===Symbol.for("react.memo_cache_sentinel")?(j=Array.from({length:Zf},Tk),e[4]=j):j=e[4];const w=j;if(!n)return null;let p;e[5]!==o?(p=ge("fireworks-overlay pointer-events-none",o),e[5]=o,e[6]=p):p=e[6];let h;if(e[7]!==d||e[8]!==m||e[9]!==u){let v;e[11]!==d||e[12]!==u?(v=S=>{const N={"--burst-delay":`${S.delay}ms`,"--burst-x":`${S.x}%`,"--burst-y":`${S.y}%`,"--firework-color":`var(${S.colorVar})`,"--firework-duration":`${u}ms`};return s.jsx("div",{className:"firework-burst",style:N,children:w.map((A,k)=>{const C=A.x*S.radius,P=A.y*S.radius,D={"--translate-x":`${C}px`,"--translate-y":`${P}px`,"--particle-delay":`${A.delay}ms`,color:`var(${S.colorVar})`};return s.jsx("span",{className:"firework-particle",style:D},`${S.id}-${k}-${d}`)})},`${S.id}-${d}`)},e[11]=d,e[12]=u,e[13]=v):v=e[13],h=m.map(v),e[7]=d,e[8]=m,e[9]=u,e[10]=h}else h=e[10];let b;return e[14]!==d||e[15]!==p||e[16]!==h?(b=s.jsx("div",{className:p,"aria-hidden":"true","data-burst-key":d,children:h}),e[14]=d,e[15]=p,e[16]=h,e[17]=b):b=e[17],b};function Tk(t,e){const n=Math.PI*2*e/Zf;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const Ik=t=>{const e=it.c(13);let n;e[0]!==t?(n={},e[0]=t,e[1]=n):n=e[1];const{durationMs:r}=n,o=r===void 0?3400:r;let i;e[2]===Symbol.for("react.memo_cache_sentinel")?(i={isActive:!1,cycle:0},e[2]=i):i=e[2];const[c,a]=nt.useState(i),d=nt.useRef(null);let u;e[3]===Symbol.for("react.memo_cache_sentinel")?(u=()=>{d.current&&(window.clearTimeout(d.current),d.current=null)},e[3]=u):u=e[3];const m=u;let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{m(),a(Rk)},e[4]=f):f=e[4];const g=f;let x;e[5]!==o?(x=()=>{m(),a(Mk),d.current=window.setTimeout(()=>{a(Ok),d.current=null},o)},e[5]=o,e[6]=x):x=e[6];const j=x;let w,p;e[7]===Symbol.for("react.memo_cache_sentinel")?(w=()=>()=>m(),p=[m],e[7]=w,e[8]=p):(w=e[7],p=e[8]),nt.useEffect(w,p);let h;return e[9]!==c.cycle||e[10]!==c.isActive||e[11]!==j?(h={isActive:c.isActive,burstKey:c.cycle,triggerFireworks:j,dismissFireworks:g},e[9]=c.cycle,e[10]=c.isActive,e[11]=j,e[12]=h):h=e[12],h};function Rk(t){return t.isActive?{...t,isActive:!1}:t}function Mk(t){return{isActive:!0,cycle:t.cycle+1}}function Ok(t){return t.isActive?{...t,isActive:!1}:t}const em=l.createContext(void 0),Fk=t=>{const e=it.c(10),{children:n}=t,{isActive:r,burstKey:o,triggerFireworks:i,dismissFireworks:c}=Ik();let a;e[0]!==c||e[1]!==i?(a={triggerFireworks:i,dismissFireworks:c},e[0]=c,e[1]=i,e[2]=a):a=e[2];const d=a;let u;e[3]!==o||e[4]!==r?(u=s.jsx(Ek,{isActive:r,burstKey:o}),e[3]=o,e[4]=r,e[5]=u):u=e[5];let m;return e[6]!==n||e[7]!==u||e[8]!==d?(m=s.jsxs(em.Provider,{value:d,children:[n,u]}),e[6]=n,e[7]=u,e[8]=d,e[9]=m):m=e[9],m},iN=()=>{const t=l.useContext(em);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},Lk=t=>{if(t<1e3)return`${Math.round(t)}ms`;const e=t/1e3;if(e<60)return`${e.toFixed(1)}s`;const n=Math.floor(e/60),r=Math.round(e%60);return`${n}m ${r}s`},Os=t=>{const e=it.c(8),{label:n,value:r}=t;let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[0]=o):o=e[0];let i;e[1]!==n?(i=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:n}),e[1]=n,e[2]=i):i=e[2];let c;e[3]!==r?(c=s.jsx("div",{className:"typography-markdown font-semibold text-[var(--surface-foreground)]",children:r}),e[3]=r,e[4]=c):c=e[4];let a;return e[5]!==i||e[6]!==c?(a=s.jsxs("div",{className:"rounded-md p-2",style:o,children:[i,c]}),e[5]=i,e[6]=c,e[7]=a):a=e[7],a},Kd=t=>{const e=it.c(43),{title:n,snapshot:r,emptyLabel:o}=t,{t:i}=gt();let c;if(e[0]!==o||e[1]!==r.durationMs||e[2]!==r.entries||e[3]!==r.lastUpdatedAt||e[4]!==r.startedAt||e[5]!==i||e[6]!==n){const a=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce($k,0),e[8]=r.entries,e[9]=d):d=e[9];const u=d;let m;e[10]!==n?(m=s.jsx("div",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:n}),e[10]=n,e[11]=m):m=e[11];let f;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==i?(f=r.startedAt?Lk(r.durationMs):i("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=i,e[15]=f):f=e[15];let g;e[16]!==f?(g=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:f}),e[16]=f,e[17]=g):g=e[17];let x;e[18]!==m||e[19]!==g?(x=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,g]}),e[18]=m,e[19]=g,e[20]=x):x=e[20];let j;e[21]!==i?(j=i("memoryDebugPanel.metric.metrics"),e[21]=i,e[22]=j):j=e[22];let w;e[23]!==r.entries.length||e[24]!==j?(w=s.jsx(Os,{label:j,value:r.entries.length}),e[23]=r.entries.length,e[24]=j,e[25]=w):w=e[25];let p;e[26]!==i?(p=i("memoryDebugPanel.metric.samples"),e[26]=i,e[27]=p):p=e[27];let h;e[28]!==p||e[29]!==u?(h=s.jsx(Os,{label:p,value:u}),e[28]=p,e[29]=u,e[30]=h):h=e[30];let b;e[31]!==i?(b=i("memoryDebugPanel.metric.lastUpdate"),e[31]=i,e[32]=b):b=e[32];let v;e[33]!==r.lastUpdatedAt||e[34]!==i?(v=r.lastUpdatedAt?i("memoryDebugPanel.common.live"):i("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=i,e[35]=v):v=e[35];let S;e[36]!==b||e[37]!==v?(S=s.jsx(Os,{label:b,value:v}),e[36]=b,e[37]=v,e[38]=S):S=e[38];let N;e[39]!==h||e[40]!==S||e[41]!==w?(N=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[w,h,S]}),e[39]=h,e[40]=S,e[41]=w,e[42]=N):N=e[42],c=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[x,N,a.length===0?s.jsx("div",{className:"rounded-md p-3 typography-meta text-[var(--surface-muted-foreground)]",style:{backgroundColor:"color-mix(in srgb, var(--surface-muted) 45%, transparent)"},children:o}):s.jsx($n,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:a.map(A=>s.jsxs("div",{className:"rounded-md border border-[var(--interactive-border)] p-2",style:{backgroundColor:"color-mix(in srgb, var(--surface-elevated) 88%, transparent)"},children:[s.jsx("div",{className:"typography-meta font-medium text-[var(--surface-foreground)] break-all",children:A.metric}),s.jsxs("div",{className:"mt-1 grid grid-cols-4 gap-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:i("memoryDebugPanel.metric.countValue",{value:A.count})}),s.jsx("span",{children:i("memoryDebugPanel.metric.avgValue",{value:A.avg})}),s.jsx("span",{children:i("memoryDebugPanel.metric.maxValue",{value:A.max})}),s.jsx("span",{children:i("memoryDebugPanel.metric.totalValue",{value:A.total})})]})]},A.metric))})})]}),e[0]=o,e[1]=r.durationMs,e[2]=r.entries,e[3]=r.lastUpdatedAt,e[4]=r.startedAt,e[5]=i,e[6]=n,e[7]=c}else c=e[7];return c},Bk=t=>{const e=it.c(99),{onClose:n}=t,{t:r}=gt(),[o,i]=l.useState("memory"),[c,a]=l.useState("idle"),d=ot(zk),u=Mu(Uk),m=Su(),f=Qp(Wk),g=tn(Vk),[x,j]=l.useState(Hk),[w,p]=l.useState(Kk);let h;e[0]!==x.entries?(h=new Map,x.entries.forEach(re=>{h.set(re.metric,re.count)}),e[0]=x.entries,e[1]=h):h=e[1];let b;e[2]!==h?(b=h.get("ui.message_list.render")??0,e[2]=h,e[3]=b):b=e[3];let v;e[4]!==h?(v=h.get("ui.message_list.render.streaming")??0,e[4]=h,e[5]=v):v=e[5];let S;e[6]!==h?(S=h.get("ui.chat_message.render")??0,e[6]=h,e[7]=S):S=e[7];let N;e[8]!==h?(N=h.get("ui.chat_message.render.streaming")??0,e[8]=h,e[9]=N):N=e[9];let A;e[10]!==h?(A=h.get("ui.chat_message.render.static_during_stream")??0,e[10]=h,e[11]=A):A=e[11];let k;e[12]!==h?(k=h.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=h,e[13]=k):k=e[13];let C;e[14]!==b||e[15]!==v||e[16]!==S||e[17]!==N||e[18]!==A||e[19]!==k?(C={messageListRender:b,messageListRenderStreaming:v,chatMessageRender:S,chatMessageRenderStreaming:N,chatMessageRenderStaticDuringStream:A,chatMessageRenderStaticOutsideActiveTurnDuringStream:k},e[14]=b,e[15]=v,e[16]=S,e[17]=N,e[18]=A,e[19]=k,e[20]=C):C=e[20];const P=C;let D,O;e[21]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{const re=()=>{j(oi()),p(ii())};re();const Y=window.setInterval(re,500);return()=>window.clearInterval(Y)},O=[],e[21]=D,e[22]=O):(D=e[21],O=e[22]),l.useEffect(D,O);let F,E;e[23]!==c?(F=()=>{if(c==="idle")return;const re=window.setTimeout(()=>{a("idle")},1500);return()=>window.clearTimeout(re)},E=[c],e[23]=c,e[24]=F,e[25]=E):(F=e[24],E=e[25]),l.useEffect(F,E);let B=0,$=0,z=0;for(const re of Object.keys(f)){const Y=f[re]??[];$=$+Y.length;for(const U of Y)U.role==="user"?z=z+1:U.role==="assistant"&&(B=B+1)}let V;e[26]!==B||e[27]!==$||e[28]!==z?(V={assistant:B,total:$,user:z},e[26]=B,e[27]=$,e[28]=z,e[29]=V):V=e[29];const y=V;let I;if(e[30]!==d||e[31]!==f||e[32]!==u||e[33]!==m||e[34]!==r){let re;e[36]!==d||e[37]!==f||e[38]!==u||e[39]!==r?(re=Y=>{const U=f[Y.id]??[];let fe=0,ne=0;for(const Fe of U)Fe.role==="user"?ne=ne+1:Fe.role==="assistant"&&(fe=fe+1);const ce=u.get(Y.id);return{id:Y.id,title:Y.title||r("memoryDebugPanel.common.untitled"),assistantMessageCount:fe,messageCount:U.length,userMessageCount:ne,isStreaming:ce?.isStreaming||!1,isZombie:ce?.isZombie||!1,backgroundCount:ce?.backgroundMessageCount||0,lastAccessed:ce?.lastAccessedAt||0,isCurrent:Y.id===d}},e[36]=d,e[37]=f,e[38]=u,e[39]=r,e[40]=re):re=e[40],I=m.map(re).sort(Gk),e[30]=d,e[31]=f,e[32]=u,e[33]=m,e[34]=r,e[35]=I}else I=e[35];const _=I;let W;e[41]!==f?(W=Object.keys(f),e[41]=f,e[42]=W):W=e[42];const K=W.length;let Z;e[43]===Symbol.for("react.memo_cache_sentinel")?(Z=async()=>{try{const re={generatedAt:new Date().toISOString(),ui:oi(),vscode:ii()};await navigator.clipboard.writeText(JSON.stringify(re,null,2)),a("copied")}catch{a("error")}},e[43]=Z):Z=e[43];const Q=Z;let le;e[44]===Symbol.for("react.memo_cache_sentinel")?(le={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[44]=le):le=e[44];let te;e[45]!==o?(te=o==="memory"?s.jsx(T,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(T,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[45]=o,e[46]=te):te=e[46];let he;e[47]!==r?(he=r("memoryDebugPanel.title"),e[47]=r,e[48]=he):he=e[48];let xe;e[49]!==he?(xe=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:he}),e[49]=he,e[50]=xe):xe=e[50];let H;e[51]!==te||e[52]!==xe?(H=s.jsxs("div",{className:"flex items-center gap-2",children:[te,xe]}),e[51]=te,e[52]=xe,e[53]=H):H=e[53];let we;e[54]!==o?(we=o==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(lt,{size:"xs",variant:"ghost",onClick:Q,children:s.jsx(T,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(lt,{size:"xs",variant:"ghost",onClick:()=>{Gm(),j(oi()),p(ii())},children:s.jsx(T,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[54]=o,e[55]=we):we=e[55];let de;e[56]!==n?(de=n?s.jsx(lt,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(T,{name:"close",className:"h-4 w-4"})}):null,e[56]=n,e[57]=de):de=e[57];let q;e[58]!==we||e[59]!==de?(q=s.jsxs("div",{className:"flex items-center gap-1",children:[we,de]}),e[58]=we,e[59]=de,e[60]=q):q=e[60];let me;e[61]!==H||e[62]!==q?(me=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[H,q]}),e[61]=H,e[62]=q,e[63]=me):me=e[63];let be;e[64]===Symbol.for("react.memo_cache_sentinel")?(be={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[64]=be):be=e[64];const Pe=o==="memory"?"secondary":"ghost";let Ie;e[65]===Symbol.for("react.memo_cache_sentinel")?(Ie=()=>i("memory"),e[65]=Ie):Ie=e[65];let De;e[66]!==r?(De=r("memoryDebugPanel.tabs.memory"),e[66]=r,e[67]=De):De=e[67];let Le;e[68]!==Pe||e[69]!==De?(Le=s.jsx(lt,{size:"sm",variant:Pe,className:"flex-1",onClick:Ie,children:De}),e[68]=Pe,e[69]=De,e[70]=Le):Le=e[70];const Ne=o==="streaming"?"secondary":"ghost";let ve;e[71]===Symbol.for("react.memo_cache_sentinel")?(ve=()=>i("streaming"),e[71]=ve):ve=e[71];let Me;e[72]!==r?(Me=r("memoryDebugPanel.tabs.streaming"),e[72]=r,e[73]=Me):Me=e[73];let ee;e[74]!==Ne||e[75]!==Me?(ee=s.jsx(lt,{size:"sm",variant:Ne,className:"flex-1",onClick:ve,children:Me}),e[74]=Ne,e[75]=Me,e[76]=ee):ee=e[76];let oe;e[77]!==Le||e[78]!==ee?(oe=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:be,children:[Le,ee]}),e[77]=Le,e[78]=ee,e[79]=oe):oe=e[79];let Te;e[80]!==o||e[81]!==K||e[82]!==c||e[83]!==d||e[84]!==f||e[85]!==y||e[86]!==u||e[87]!==_||e[88]!==m||e[89]!==P||e[90]!==x||e[91]!==r||e[92]!==g||e[93]!==w?(Te=o==="memory"?s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"grid grid-cols-2 gap-2 typography-meta",children:[s.jsx(Os,{label:r("memoryDebugPanel.metric.totalMessages"),value:y.total}),s.jsx(Os,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${K} / ${fc.MAX_SESSIONS}`}),s.jsx(Os,{label:r("memoryDebugPanel.metric.userMessages"),value:y.user}),s.jsx(Os,{label:r("memoryDebugPanel.metric.assistantMessages"),value:y.assistant})]}),s.jsxs("div",{className:"typography-meta space-y-1 border-t border-[var(--interactive-border)] pt-2",children:[s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.viewportWindow")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.messagesValue",{count:Xp()})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.zombieTimeout")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.minutesValue",{count:fc.ZOMBIE_TIMEOUT/1e3/60})})]}),s.jsxs("div",{className:"flex justify-between gap-2",children:[s.jsx("span",{className:"text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.githubTotalRequests")}),s.jsx("span",{className:"text-[var(--surface-foreground)]",children:g})]})]}),s.jsxs("div",{className:"border-t border-[var(--interactive-border)] pt-2",children:[s.jsx("div",{className:"mb-1 typography-meta font-semibold text-[var(--surface-foreground)]",children:r("memoryDebugPanel.section.sessionsInMemory")}),s.jsx($n,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:_.map(re=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:re.isCurrent?"color-mix(in srgb, var(--interactive-selection) 22%, transparent)":"color-mix(in srgb, var(--surface-muted) 35%, transparent)"},children:[s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"truncate text-[var(--surface-foreground)]",children:re.title}),re.isStreaming?s.jsx(T,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,re.isZombie?s.jsx("span",{className:"text-[var(--status-warning)]",children:"!"}):null]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"font-mono text-[var(--surface-muted-foreground)]",children:r("memoryDebugPanel.metric.roleMsgsValue",{assistant:re.assistantMessageCount,user:re.userMessageCount})}),s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:re.messageCount})}),re.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",re.backgroundCount]}):null]})]},re.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx(lt,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:m.map(qk),currentSessionId:d,cachedSessions:Object.keys(f),messageRoleCounts:y,sessionMessageRoleCounts:_.map(Yk),memoryStates:Object.fromEntries(u)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(ht,{side:"top",children:r("memoryDebugPanel.tooltip.logCurrentState")})]})})]}):s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-[var(--interactive-border)] px-3 py-2 typography-meta text-[var(--surface-muted-foreground)]",children:[s.jsx("span",{children:r(c==="copied"?"memoryDebugPanel.streaming.copy.copied":c==="error"?"memoryDebugPanel.streaming.copy.failed":"memoryDebugPanel.streaming.copy.hint")}),s.jsx(lt,{size:"xs",variant:"outline",onClick:Q,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(Os,{label:r("memoryDebugPanel.metric.uiMetrics"),value:x.entries.length}),s.jsx(Os,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:w.entries.length}),s.jsx(Os,{label:r("memoryDebugPanel.metric.messageListRenders"),value:P.messageListRender}),s.jsx(Os,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:P.messageListRenderStreaming}),s.jsx(Os,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:P.chatMessageRender}),s.jsx(Os,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:P.chatMessageRenderStreaming}),s.jsx(Os,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:P.chatMessageRenderStaticDuringStream}),s.jsx(Os,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:P.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(Kd,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:x,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),w.entries.length>0?s.jsx(Kd,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:w,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[80]=o,e[81]=K,e[82]=c,e[83]=d,e[84]=f,e[85]=y,e[86]=u,e[87]=_,e[88]=m,e[89]=P,e[90]=x,e[91]=r,e[92]=g,e[93]=w,e[94]=Te):Te=e[94];let J;return e[95]!==me||e[96]!==oe||e[97]!==Te?(J=s.jsxs(Jp,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:le,children:[me,oe,Te]}),e[95]=me,e[96]=oe,e[97]=Te,e[98]=J):J=e[98],J},_k=Bk;function $k(t,e){return t+e.count}function zk(t){return t.currentSessionId}function Uk(t){return t.sessionMemoryState}function Wk(t){return t.message}function Vk(t){return t.totalRequestCount}function Hk(){return oi()}function Kk(){return ii()}function Gk(t,e){return e.lastAccessed-t.lastAccessed}function qk(t){return{id:t.id,title:t.title}}function Yk(t){return{id:t.id,title:t.title,total:t.messageCount,user:t.userMessageCount,assistant:t.assistantMessageCount}}const Qk=()=>{if(typeof document>"u")return"";const t=document.activeElement;if(t instanceof HTMLTextAreaElement)return t.value.slice(t.selectionStart??0,t.selectionEnd??0);if(t instanceof HTMLInputElement){const e=t.type?.toLowerCase()??"text";if(["text","search","url","tel","password"].includes(e))return t.value.slice(t.selectionStart??0,t.selectionEnd??0)}return t instanceof HTMLElement&&t.isContentEditable?t.ownerDocument.defaultView?.getSelection?.()?.toString()??"":""},Xk=async()=>{const t=Qk()||window.getSelection()?.toString()||"";if(!t.trim())return!1;try{if(typeof navigator<"u"&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(t),!0}catch{}return document.execCommand("copy")},Gd="openchamber:menu-action",Da="openchamber:check-for-updates",Jk=t=>{const e=ot(b=>b.openNewSessionDraft),n=pe(b=>b.toggleCommandPalette),r=pe(b=>b.setCommandPaletteOpen),o=pe(b=>b.toggleHelpDialog),i=pe(b=>b.toggleSidebar),c=pe(b=>b.setSessionSwitcherOpen),a=pe(b=>b.setActiveMainTab),d=pe(b=>b.setSettingsDialogOpen),u=pe(b=>b.setAboutDialogOpen),m=wo(b=>b.checkForUpdates),{setThemeMode:f}=_r(),g=l.useRef(!1),x=l.useCallback(()=>{g.current||(g.current=!0,m().then(()=>{const{available:b,error:v}=wo.getState();if(v){Ae.error("Failed to check for updates",{description:v});return}b||Ae.success("You are on the latest version")}).finally(()=>{g.current=!1}))},[m]),j=l.useCallback(()=>{Un.requestDirectoryDialog()},[]),w=l.useCallback(b=>{const v=Zp();if(v.length===0)return;const S=ot.getState().currentSessionId,N=v.findIndex(C=>C.id===S);let A=b>0?0:v.length-1;N>=0&&(A=(N+b+v.length)%v.length);const k=v[A];k&&(a("chat"),c(!1),ot.getState().setCurrentSession(k.id))},[a,c]),p=l.useCallback(b=>{const{activeProjectId:v,projects:S,setActiveProject:N}=Gt.getState();if(S.length===0)return;const A=S.findIndex(P=>P.id===v);let k=b>0?0:S.length-1;A>=0&&(k=(A+b+S.length)%S.length);const C=S[k];C&&N(C.id)},[]),h=l.useCallback(b=>{switch(b){case"about":u(!0);break;case"settings":d(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":a("chat"),c(!1),e();break;case"new-worktree-session":a("chat"),c(!1),Au();break;case"change-workspace":j();break;case"toggle-right-sidebar":{const v=ls.getState().currentDirectory;if(!v)break;const S=pe.getState(),N=Vr(v),A=S.contextPanelByDirectory[N];A?.isOpen?S.closeContextPanel(N):A?.activeTabId?S.setActiveContextPanelTab(N,A.activeTabId):S.openContextSurface(N,"git");break}case"open-right-sidebar-git":{const v=ls.getState().currentDirectory;if(!v)break;pe.getState().openContextSurface(Vr(v),"git");break}case"open-right-sidebar-files":{const v=ls.getState().currentDirectory;if(!v)break;pe.getState().openContextSurface(Vr(v),"file");break}case"toggle-terminal":{const v=ls.getState().currentDirectory;if(!v)break;pe.getState().openContextSurface(Vr(v),"terminal");break}case"toggle-terminal-expanded":{const v=ls.getState().currentDirectory;if(!v)break;const S=Vr(v),N=pe.getState(),A=N.contextPanelByDirectory[S];(A?.isOpen?A.tabs.find(C=>C.id===A.activeTabId)?.mode:null)!=="terminal"&&N.openContextSurface(S,"terminal"),N.toggleContextPanelExpanded(S);break}case"copy":{const v=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(v)||Xk();break}case"theme-light":f("light");break;case"theme-dark":f("dark");break;case"theme-system":f("system");break;case"add-selection-to-chat":tg();break;case"toggle-sidebar":i();break;case"toggle-memory-debug":t?.();break;case"go-back":ls.getState().goBack();break;case"go-forward":ls.getState().goForward();break;case"previous-session":w(-1);break;case"next-session":w(1);break;case"previous-project":p(-1);break;case"next-project":p(1);break;case"help-dialog":o();break;case"download-logs":{eg().catch(()=>{Ae.error("Failed to collect OpenCode status")});break}}},[j,p,w,t,e,u,a,c,r,d,f,n,o,i]);l.useEffect(()=>{const b=S=>{const N=S.detail;N&&h(N)},v=()=>{x()};return window.addEventListener(Gd,b),window.addEventListener(Da,v),()=>{window.removeEventListener(Gd,b),window.removeEventListener(Da,v)}},[h,x]),l.useEffect(()=>{if(typeof window>"u")return;const v=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof v!="function")return;let S=null,N=null;return v("openchamber:menu-action",A=>{const k=A?.payload;typeof k=="string"&&h(k)}).then(A=>{S=A}).catch(()=>{}),v("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(Da))}).then(A=>{N=A}).catch(()=>{}),()=>{(async()=>{try{const k=S?.();k instanceof Promise&&await k}catch{}try{const k=N?.();k instanceof Promise&&await k}catch{}})()}},[h])},Zk="openchamber:tray-action",qd=5e3,eC=500,tC=45e3,tm=20,Yd=()=>{if(typeof window>"u")return!1;const t=window.__OPENCHAMBER_PLATFORM__;return t==="darwin"||t==="win32"||t==="linux"},Qd=()=>typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.trayEnabled!==!1,sC=t=>{const e=typeof t.permission=="string"?t.permission:"Permission",n=Array.isArray(t.patterns)?t.patterns.find(r=>typeof r=="string"&&r.trim()):"";return n?`${e}: ${n}`:e},nC=t=>{const e=Array.isArray(t.questions)?t.questions[0]:void 0;return e?.header||e?.question||"Question"},sm=(t,e)=>so(t,e,No.getState().ids,Vi.getState().rankById),rC=t=>{const e=t.replace(/\\/g,"/").replace(/\/+$/,""),n=e.lastIndexOf("/");return n>=0?e.slice(n+1):e},oC=(t,e,n,r,o)=>{if(!t)return"";const i=$u(n,r,t),c=e.project?.name,a=i?.label?.trim()||c?.trim()||rC(t),d=ci(t);let u=d&&o.get(d)||"";if(!u){for(const[m,f]of pr.getState().directories)if(ci(m)===d){u=f.status?.current??"";break}}if(!u)for(const m of r.values()){const f=m.find(g=>ci(g.path)===d);if(f?.branch){u=f.branch;break}}return u?`${a} · ${u}`:a},iC=()=>{const{results:t,dropdownProviderIds:e,displayMode:n}=Ns.getState(),r=n==="remaining"?"remaining":"usage";if(!e.length)return{mode:r,groups:[]};const o=new Map(t.map(c=>[c.providerId,c])),i=[];for(const c of hu){if(!e.includes(c.id))continue;const a=o.get(c.id);if(!a||a.configured!==!0)continue;const d=[];for(const[m,f]of Object.entries(a.usage?.windows??{})){const g=r==="remaining"?f.remainingPercent:f.usedPercent;d.push({label:bu(m),value:Ra(f.valueLabel,g)})}const u=!a.ok&&a.error?a.error:d.length===0?"No rate limits reported":null;i.push({provider:c.name,rows:d,status:u})}return{mode:r,groups:i}},aC=async()=>{try{if(Mi())return"Local OpenChamber";const t=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,e=hr();if(e&&ql(e,t))return"Local OpenChamber";const r=(await nu()).hosts.find(o=>e?ql(e,qm(o)):!1);return r?.label?.trim()?ru(r.label.trim()):"Instance"}catch{return""}},lC=()=>{const t=new Map,e=new Map,n=[],r=new Map;let o;try{o=wi()}catch{return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}}for(const[i,c]of o.children.entries()){const a=c.getState();a.vcs?.branch&&e.set(ci(i)??i,a.vcs.branch);for(const d of a.session)d?.id&&r.set(d.id,d.title);for(const[d,u]of Object.entries(a.session_status??{})){const m=u?.type,f=m==="busy"?"busy":m==="retry"?"retry":"idle",g=t.get(d);(!g||g==="idle")&&t.set(d,f)}for(const[d,u]of Object.entries(a.permission??{}))for(const m of u??[]){if(!m?.id)continue;const f=m.sessionID||d;n.push({kind:"permission",id:m.id,sessionId:f,sessionTitle:"",label:sC(m),directory:i})}for(const[d,u]of Object.entries(a.question??{}))for(const m of u??[]){if(!m?.id)continue;const f=m.sessionID||d;n.push({kind:"question",id:m.id,sessionId:f,sessionTitle:"",label:nC(m),directory:i})}}return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}},cC=()=>{const t=Fs.getState().activeSessions,e=new Set;t.filter(r=>r?.id&&!r.parentID).slice().sort(sm).slice(0,tm).forEach(r=>{const o=Qs(r);o&&e.add(o)});const n=new Map;for(const r of t){if(!r?.id)continue;const o=Qs(r);if(!o||!e.has(o))continue;const i=n.get(o)??[];i.push(r.id),n.set(o,i)}return n},dC=t=>{const e=lC(),n=Ki.getState().index.session,r=Fs.getState().activeSessions,o=new Map(e.titleById),i=new Map;for(const p of r)if(p?.id&&(p.title&&o.set(p.id,p.title),p.parentID)){const h=i.get(p.parentID)??[];h.push(p.id),i.set(p.parentID,h)}const c=p=>{const h=[],b=[...i.get(p)??[]],v=new Set;for(;b.length;){const S=b.pop();v.has(S)||(v.add(S),h.push(S),b.push(...i.get(S)??[]))}return h},a=Hi.getState().statusById,d=p=>{const h=e.statusById.get(p);return h&&h!=="idle"?h:a.get(p)?.status.type??h??"idle"},u=p=>{const h=p.map(b=>d(b));return h.includes("busy")?"busy":h.includes("retry")?"retry":"idle"},m=Gt.getState().projects,f=ot.getState().availableWorktreesByProject,g=r.filter(p=>p?.id&&!p.parentID).slice().sort(sm).slice(0,tm).map(p=>{const h=[p.id,...c(p.id)],b=Qs(p)??"";return{id:p.id,title:p.title||"Untitled session",status:u(h),branch:b?e.branchByDirectory.get(b)??"":"",unseen:h.reduce((v,S)=>v+(n.unseenCount[S]??0),0),hasError:h.some(v=>n.unseenHasError[v]??!1),directory:b,subtitle:oC(b,p,m,f,e.branchByDirectory)}}),x=e.approvals.map(p=>({...p,sessionTitle:o.get(p.sessionId)||""})),j=pe.getState();let w=0;if(j.dockBadgeEnabled)for(const p of r){if(!p?.id||p.parentID)continue;let h=n.unseenCount[p.id]??0;h===0&&j.notifyOnSubtasks&&(h=c(p.id).reduce((b,v)=>b+(n.unseenCount[v]??0),0)),h>0&&(w+=1)}return{sessions:g,approvals:x,instanceName:t,usage:iC(),dockBadgeCount:w}},uC=()=>{l.useEffect(()=>{if(!Yd()||!Qd()||!Fi())return;let t=!1,e="",n=null,r="";const o=()=>{if(t)return;const k=dC(r),C=JSON.stringify(k);C!==e&&(e=C,mr("desktop_tray_update",k))};aC().then(k=>{t||(r=k,o())});const i=async()=>{const k=cC();await Promise.all([...k.entries()].map(async([C,P])=>{const D=await sn.getSessionStatusForDirectory(C).catch(()=>null);t||D===null||rg(C,D,P)}))},c=()=>{t||n!==null||(n=window.setTimeout(()=>{n=null,o()},eC))},a=new Map,d=()=>{if(t)return;let k;try{k=wi()}catch{return}const C=new Set;for(const[P,D]of k.children.entries())C.add(P),a.has(P)||a.set(P,D.subscribe(()=>c()));for(const[P,D]of a)C.has(P)||(D(),a.delete(P))};let u=null;try{u=wi().subscribeRegistry(()=>{d(),c()})}catch{}d();const m=Ki.subscribe(()=>c()),f=Fs.subscribe(()=>c()),g=Gt.subscribe(()=>c()),x=ot.subscribe(()=>c()),j=pr.subscribe(()=>c()),w=pe.subscribe(()=>c()),p=Hi.subscribe(()=>c()),h=Vi.subscribe(()=>c()),b=No.subscribe(()=>c());sg(ng());const v=window.setInterval(()=>{vi()},tC);i();const S=window.setInterval(()=>{i()},qd),N=Ns.subscribe(()=>c());Ns.getState().loadSettings().then(()=>{if(t)return;const{dropdownProviderIds:k,results:C}=Ns.getState();k.length>0&&k.some(D=>!C.some(O=>O.providerId===D))&&Ns.getState().fetchQuotas(k)});const A=window.setInterval(()=>{d(),o()},qd);return o(),()=>{t=!0,n!==null&&window.clearTimeout(n),window.clearInterval(A),window.clearInterval(v),window.clearInterval(S),m(),f(),g(),x(),j(),w(),p(),h(),b(),N(),u?.();for(const k of a.values())k();a.clear()}},[]),l.useEffect(()=>{if(!Yd()||!Qd()||typeof window>"u")return;const e=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof e!="function")return;const n=o=>{o.type==="respond-permission"&&og(o.sessionId,o.id,o.response).catch(()=>{Ae.error("Failed to respond to permission request")})};let r=null;return e(Zk,o=>{const i=o?.payload;!i||typeof i!="object"||typeof i.type!="string"||n(i)}).then(o=>{r=o}).catch(()=>{}),()=>{try{const o=r?.();o instanceof Promise&&o.catch(()=>{})}catch{}}},[])},fC="/api/notifications/stream",mC=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),hC=t=>{if(!t||typeof t!="object")return null;const e=t,n=e.properties&&typeof e.properties=="object"?e.properties:null;return e.type!=="openchamber:notification"||!n?null:{title:typeof n.title=="string"?n.title:void 0,body:typeof n.body=="string"?n.body:void 0,tag:typeof n.tag=="string"?n.tag:void 0}},pC=t=>{const e=it.c(3),n=t?.enabled??!0;let r,o;e[0]!==n?(r=()=>{if(!n||Wn()||!il()||typeof window>"u"||typeof EventSource>"u")return;const i=new EventSource(au().sse(fC));return i.onmessage=gC,()=>{i.close()}},o=[n],e[0]=n,e[1]=r,e[2]=o):(r=e[1],o=e[2]),l.useEffect(r,o)};function gC(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=pe.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&mC())return;const r=hC(e);if(!r)return;Oi()?.notifications?.notifyAgentCompletion(r)}const xC=t=>{const e=it.c(14),n=pe(bC),r=Gt(yC),o=ot(vC),i=t??"",c=ig(wC);let a;e:{if(!i){a=null;break e}let x;e[0]!==o||e[1]!==i||e[2]!==r?(x=$u(r,o,i),e[0]=o,e[1]=i,e[2]=r,e[3]=x):x=e[3],a=x?.path??null}const d=a;let u,m;e[4]!==n||e[5]!==c||e[6]!==d?(u=()=>{n&&c(d)},m=[n,c,d],e[4]=n,e[5]=c,e[6]=d,e[7]=u,e[8]=m):(u=e[7],m=e[8]),l.useEffect(u,m);let f,g;e[9]!==n||e[10]!==c||e[11]!==d?(f=()=>{if(n)return Yi(x=>{x.type==="agent-memory-changed"&&c(d)})},g=[n,c,d],e[9]=n,e[10]=c,e[11]=d,e[12]=f,e[13]=g):(f=e[12],g=e[13]),l.useEffect(f,g)};function bC(t){return t.agentMemoryFeatureAvailable&&t.agentMemoryToolEnabled}function yC(t){return t.projects}function vC(t){return t.availableWorktreesByProject}function wC(t){return t.load}const Xd="pwa-install-toast-shown",Jd="pwa-install-toast-dismissed",SC=()=>{const t=it.c(6),{browserTab:e}=Ug(),{t:n}=gt(),r=l.useRef(n);let o,i;t[0]!==n?(o=()=>{r.current=n},i=[n],t[0]=n,t[1]=o,t[2]=i):(o=t[1],i=t[2]),l.useEffect(o,i);let c,a;t[3]!==e?(c=()=>{if(typeof window>"u"||!il()||!e)return;let d=null,u=null;const m=()=>{u!==null&&(Ae.dismiss(u),u=null)},f=async()=>{if(!d)return;const j=d;d=null,m(),await j.prompt();const{outcome:w}=await j.userChoice;w==="accepted"&&Ae.success(r.current("pwa.installPrompt.started"))},g=j=>{const w=j;if(typeof w.prompt!="function")return;w.preventDefault(),d=w;const p=Hr(),h=Ym();Wg({dismissed:p.getItem(Jd),sessionShown:h.getItem(Xd),hasActiveToast:u!==null})&&(h.setItem(Xd,"true"),u=Ae.info(r.current("pwa.installPrompt.description"),{duration:1/0,action:{label:r.current("pwa.installPrompt.action"),onClick:()=>{f()}},cancel:{label:r.current("pwa.installPrompt.dismiss"),onClick:()=>{Hr().setItem(Jd,"true"),m()}}}))},x=()=>{d=null,m(),Ae.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",g),window.addEventListener("appinstalled",x),()=>{m(),window.removeEventListener("beforeinstallprompt",g),window.removeEventListener("appinstalled",x)}},a=[e],t[3]=e,t[4]=c,t[5]=a):(c=t[4],a=t[5]),l.useEffect(c,a)},jC=({open:t,onOpenChange:e})=>{const{t:n}=gt(),r=!1,[o,i]=l.useState(null),[c,a]=l.useState(null),[d,u]=l.useState(!1),[m,f]=l.useState(!1),[g,x]=l.useState(null),[j,w]=l.useState(!1);l.useCallback(async()=>{},[g,d,r,n]),l.useEffect(()=>{if(!t)return;(async()=>{try{const b=await gs("/api/system/info");if(b.ok){const v=await b.json();if(typeof v.openchamberVersion=="string"&&v.openchamberVersion.trim()){i(v.openchamberVersion);return}}}catch{}i(await ag())})()},[t]),l.useEffect(()=>{if(!t)return;let h=!1;return(async()=>{try{const v=await gs("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!v.ok)return;const S=await v.json().catch(()=>null),N=typeof S?.currentVersion=="string"?S.currentVersion.trim():"";!h&&N&&a(N)}catch{}})(),()=>{h=!0}},[t]),l.useEffect(()=>{{x(null),w(!1);return}},[t,r]);const p=o;return s.jsx(Ls,{open:t,onOpenChange:e,children:s.jsx(Bs,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(ju,{width:64,height:64}),s.jsxs("div",{className:"space-y-1",children:[s.jsx("h2",{className:"text-lg font-semibold",children:"OpenChamber"}),s.jsxs("div",{className:"space-y-0.5 typography-meta text-muted-foreground",children:[p&&s.jsx("p",{children:n("aboutDialog.openChamberVersionLabel",{version:p})}),c&&s.jsx("p",{children:n("aboutDialog.openCodeVersionLabel",{version:c})})]})]}),r,s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsxs("div",{className:"flex items-center justify-center gap-4",children:[s.jsxs("a",{href:"https://github.com/openchamber/openchamber",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(T,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:"https://discord.gg/ZYRSdnwwKA",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(T,{name:"discord-fill",className:"h-4 w-4"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:"https://x.com/openchamber_dev",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1.5 typography-meta text-muted-foreground hover:text-foreground transition-colors",children:[s.jsx(T,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@openchamber_dev"})]})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/60 pt-2",children:n("aboutDialog.footerNote")})]})})})},Zd=t=>{if(!(typeof window>"u")){if(t){window.location.href="openchamber://focus/mcp-auth";return}window.location.replace("/")}},Pa=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},kC=(t,e)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?"Authorization session expired or was cleared during reload. Return to OpenChamber and click Authorize again.":n},CC=()=>{const t=lg(a=>a.completeAuth),[e,n]=l.useState("working"),[r,o]=l.useState(!1),[i,c]=l.useState("Completing MCP authorization...");return l.useEffect(()=>{if(typeof window>"u"){n("error"),c("Browser context unavailable.");return}const a=new URLSearchParams(window.location.search),d=Pa(a,"code"),u=cg(a),m=dg(a),f=Pa(a,"error"),g=Pa(a,"error_description");if(f){m&&gs(`/api/mcp/auth/pending?state=${encodeURIComponent(m)}`,{method:"DELETE"}).catch(()=>{}),n("error"),c(g??f);return}(async()=>{try{if(!d)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");let x=u,j=!1;if(m){const w=await gs(`/api/mcp/auth/pending?state=${encodeURIComponent(m)}`);if(w.ok){const p=await w.json().catch(()=>null);j=p?.origin===ug,o(j),!x&&p?.name?.trim()&&(x={name:p.name.trim(),directory:typeof p.directory=="string"&&p.directory.trim()?p.directory.trim():null})}}if(!x?.name)throw new Error("Authorization session details were not available. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");await t(x.name,d,x.directory),m&&await gs(`/api/mcp/auth/pending?state=${encodeURIComponent(m)}`,{method:"DELETE"}).catch(()=>{}),n("success"),j&&Zd(!0),c("Authorization completed. You can close this tab and return to OpenChamber.")}catch(x){m&&await gs(`/api/mcp/auth/pending?state=${encodeURIComponent(m)}`,{method:"DELETE"}).catch(()=>{}),n("error"),c(kC(x,"Failed to complete MCP authorization."))}})()},[t]),s.jsx("div",{className:"flex min-h-screen items-center justify-center bg-background px-6 py-12 text-foreground",children:s.jsxs("div",{className:"w-full max-w-xl rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-8 shadow-sm",children:[s.jsxs("div",{className:"space-y-3 text-center",children:[s.jsx("h1",{className:fg,children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"}),s.jsx("p",{className:ge("typography-body",e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]"),children:i})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(lt,{type:"button",onClick:()=>Zd(r),children:"Return to OpenChamber"})})]})})},eu=an(()=>on(()=>import("./OnboardingScreen-CDjgzxEe.js"),__vite__mapDeps([143,1,2,4,5,6,7,8,3,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81])).then(t=>({default:t.OnboardingScreen}))),NC=()=>{const t=it.c(3),e=pe(IC),n=pe(RC);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(jC,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},AC=t=>{const e=it.c(21),{onRetry:n,isRetrying:r}=t,{t:o}=gt();let i;e[0]!==o?(i=o("startup.initRecovery.title"),e[0]=o,e[1]=i):i=e[1];let c;e[2]!==i?(c=s.jsx("h1",{className:"typography-title text-foreground",children:i}),e[2]=i,e[3]=c):c=e[3];let a;e[4]!==o?(a=o("startup.initRecovery.description"),e[4]=o,e[5]=a):a=e[5];let d;e[6]!==a?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:a}),e[6]=a,e[7]=d):d=e[7];let u;e[8]!==c||e[9]!==d?(u=s.jsxs("div",{className:"flex flex-col gap-2",children:[c,d]}),e[8]=c,e[9]=d,e[10]=u):u=e[10];let m;e[11]!==r||e[12]!==o?(m=o(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=o,e[13]=m):m=e[13];let f;e[14]!==r||e[15]!==n||e[16]!==m?(f=s.jsx(lt,{type:"button",onClick:n,disabled:r,children:m}),e[14]=r,e[15]=n,e[16]=m,e[17]=f):f=e[17];let g;return e[18]!==u||e[19]!==f?(g=s.jsx("div",{className:"flex h-full items-center justify-center bg-background px-6 text-foreground",children:s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[u,f]})}),e[18]=u,e[19]=f,e[20]=g):g=e[20],g},tu=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",DC=()=>{if(typeof window>"u"||!lx())return null;const t=new URLSearchParams(window.location.search),e=t.get("sessionId"),n=typeof e=="string"?e.trim():"";if(!n)return null;const r=t.get("directory"),o=typeof r=="string"&&r.trim().length>0?r.trim():null;return{sessionId:n,directory:o,readOnly:t.get("readOnly")==="1"||t.get("readOnly")==="true",allowPromptingSubagentSessions:t.has("allowPromptingSubagentSessions")?t.get("allowPromptingSubagentSessions")==="1":void 0}},PC=()=>typeof window>"u"?!1:window.location.pathname===xg,EC=t=>{const e=it.c(25),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:o}=t,i=ls(MC),c=ot(OC),a=ot(FC),d=_i(),u=l.useRef(null);let m;e[0]!==n.directory?(m=tu(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const f=m;let g;e[2]!==i?(g=tu(i),e[2]=i,e[3]=g):g=e[3];const x=g;let j,w;if(e[4]!==x||e[5]!==c||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==f||e[9]!==r||e[10]!==a||e[11]!==d?(j=()=>{if(r||f&&x!==f)return;const N=`${f}
921
+ ${n.sessionId}`;u.current===N&&c||(u.current=N,a(n.sessionId,n.directory),d.ensureSessionRenderable(n.sessionId,!0))},w=[x,c,n.directory,n.sessionId,f,r,a,d],e[4]=x,e[5]=c,e[6]=n.directory,e[7]=n.sessionId,e[8]=f,e[9]=r,e[10]=a,e[11]=d,e[12]=j,e[13]=w):(j=e[12],w=e[13]),l.useEffect(j,w),f&&x!==f)return null;let p;e[14]!==o?(p=s.jsx(zu,{embeddedBackgroundWorkEnabled:o}),e[14]=o,e[15]=p):p=e[15];let h;e[16]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(Qu,{}),e[16]=h):h=e[16];let b;e[17]!==o||e[18]!==n.allowPromptingSubagentSessions||e[19]!==n.readOnly?(b=s.jsx(Ba,{active:o,messagesEnabled:!0,readOnly:n.readOnly,initialAllowPromptingSubagentSessions:n.allowPromptingSubagentSessions}),e[17]=o,e[18]=n.allowPromptingSubagentSessions,e[19]=n.readOnly,e[20]=b):b=e[20];let v;e[21]===Symbol.for("react.memo_cache_sentinel")?(v=s.jsx(Uu,{}),e[21]=v):v=e[21];let S;return e[22]!==p||e[23]!==b?(S=s.jsxs(s.Fragment,{children:[p,h,b,v]}),e[22]=p,e[23]=b,e[24]=S):S=e[24],S};function TC({apis:t}){l.useEffect(()=>{Qm("App:mounted"),Xm()&&console.info("[startup-trace] enabled. Run console.table(window.__OPENCHAMBER_STARTUP_TRACE__) after startup.")},[]);const e=Kt(q=>q.initializeApp),n=Kt(q=>q.isInitialized),r=Kt(q=>q.isConnected),o=Kt(q=>q.providers.length),i=Kt(q=>q.agents.length),c=Kt(q=>q.loadProviders),a=Kt(q=>q.loadAgents),d=ot(q=>q.error),u=ot(q=>q.clearError),m=ls(q=>q.currentDirectory),f=ls(q=>q.setDirectory),g=ls(q=>q.isSwitchingDirectory),[x,j]=l.useState(!1),w=Br(q=>q.refreshStatus),[p,h]=l.useState(()=>t.runtime.isVSCode),[b,v]=l.useState(!1),[S,N]=l.useState(!1),[A,k]=l.useState(0),[C,P]=l.useState(0),[D,O]=l.useState(!1),F=pe(q=>q.wideChatLayoutEnabled),E=pe(q=>q.mobileKeyboardMode),B=l.useMemo(()=>Wn(),[]),$=cl(q=>q.setPlanModeEnabled),[z,V]=l.useState(()=>Yl()),[y,I]=l.useState(()=>{const q=Ql();return q!==null?Xl({isDesktopShell:!0,bootOutcome:q}):null}),_=l.useRef(!1),W=l.useMemo(()=>DC(),[]),K=!W||b,Z=l.useMemo(()=>PC(),[]);l.useEffect(()=>(Jl(x),()=>{Jl(!1)}),[x]),l.useEffect(()=>{Jm(E)},[E]),l.useEffect(()=>{h(t.runtime.isVSCode)},[t.runtime.isVSCode]),l.useEffect(()=>Li(q=>{Vg(q),P(me=>me+1),N(!1),k(me=>me+1)}),[]);const Q=mc(q=>{const me=Ps();return Object.values(q.runsByOriginalSessionID).filter(be=>be.status==="running"&&be.runtimeKey===me).map(be=>`${be.originalSessionID}:${be.phase}:${be.lastForwardedMessageID??""}:${be.expectedAssistantParentID??""}`).sort().join("|")});l.useEffect(()=>{if(W)return;const q=Ps(),me=Object.values(mc.getState().runsByOriginalSessionID).filter(be=>be.status==="running"&&be.runtimeKey===q);for(const be of me)mg(be.originalSessionID)},[Q,W,C]),l.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",F),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[F]),l.useEffect(()=>(Zl(t),()=>Zl(null)),[t]),l.useEffect(()=>{W||w(t.github,{force:!0})},[t.github,W,w]),hg();const le=z==="valid",te=y?.screen==="main";l.useEffect(()=>{if(!Zm({isDesktopShell:B,isInitialized:n,bootOutcomeKnown:le,bootViewIsMain:te}))return;const q=setTimeout(()=>{const me=document.getElementById("initial-loading");me&&(me.classList.add("fade-out"),setTimeout(()=>{me.remove()},300))},150);return()=>clearTimeout(q)},[B,n,le,te]),l.useEffect(()=>{if(!B||z!=="malformed")return;const q=document.getElementById("initial-loading");q&&(q.textContent="Desktop startup failed — please restart the app.")},[B,z]),l.useEffect(()=>{if(B)return;const q=setTimeout(()=>{const me=document.getElementById("initial-loading");me&&!n&&(me.classList.add("fade-out"),setTimeout(()=>{me.remove()},300))},5e3);return()=>clearTimeout(q)},[B,n]),l.useEffect(()=>{let q=!1;return(async()=>{const be=await gs("/health",{method:"GET"}).catch(()=>null);if(!be||!be.ok||q)return;const Pe=await be.json().catch(()=>null);if(!Pe||q)return;const Ie=Pe.planModeExperimentalEnabled;$(Ie===!0||Ie===1||Ie==="1"||Ie==="true")})(),()=>{q=!0}},[$]),l.useEffect(()=>{p||e()},[e,p]),l.useEffect(()=>{if(p||n)return;let q=!0,me,be=0;const Pe=10,Ie=1e3,De=async()=>{if(!q)return;if(be>=Pe){N(!0);return}const Le=Kt.getState();if(Le.isInitialized){N(!1);return}be+=1,await Le.initializeApp();const Ne=Kt.getState();if(!q)return;if(Ne.isInitialized){N(!1);return}if(be>=Pe){N(!0);return}const ve=Math.min(Ie*Math.pow(2,be-1),16e3);me=setTimeout(De,ve)};return me=setTimeout(De,Ie),()=>{q=!1,me&&clearTimeout(me)}},[A,n,p]),l.useEffect(()=>{n&&N(!1)},[n]),l.useEffect(()=>{if(!S)return;const q=document.getElementById("initial-loading");q&&(q.classList.add("fade-out"),setTimeout(()=>{q.remove()},300))},[S]),l.useEffect(()=>{if(p||!r||o>0&&i>0)return;let q=!0,me=0;const be=15,Pe=async()=>{const De=Kt.getState();if(!(De.providers.length>0&&De.agents.length>0))try{De.providers.length===0&&await c({source:"startupRecovery"}),Kt.getState().agents.length===0&&await a({source:"startupRecovery"})}catch{}};Pe();const Ie=setInterval(()=>{if(q){if(++me>=be){clearInterval(Ie);return}Pe()}},2e3);return()=>{q=!1,clearInterval(Ie)}},[r,p,a,c,o,i]),l.useEffect(()=>{g||p||r&&sn.setDirectory(m)},[m,g,r,p]),l.useEffect(()=>{if(!W||typeof window>"u")return;const q=Pe=>{v(Pe?.visible===!0)},me=Pe=>{if(Pe.origin!==window.location.origin||Pe.source!==window.parent)return;const Ie=Pe.data;Ie?.type===tf&&q(Ie.payload)},be=window;return be.__openchamberSetEmbeddedVisibility=q,window.addEventListener("message",me),ax(),()=>{window.removeEventListener("message",me),be.__openchamberSetEmbeddedVisibility===q&&delete be.__openchamberSetEmbeddedVisibility}},[W]),l.useEffect(()=>{!W?.directory||p||m!==W.directory&&f(W.directory,{showOverlay:!1})},[m,W,p,f]),l.useEffect(()=>{if(!W||typeof window>"u")return;const q=me=>{me.storageArea===window.localStorage&&me.key==="ui-store"&&pe.persist.rehydrate()};return window.addEventListener("storage",q),()=>{window.removeEventListener("storage",q)}},[W]),l.useEffect(()=>{if(typeof window>"u")return;const q=me=>{const be=me.detail,Pe=typeof be?.sessionId=="string"?be.sessionId.trim():"";if(!Pe)return;const Ie=typeof be?.directory=="string"&&be.directory.trim().length>0?be.directory.trim():null;pe.getState().setActiveMainTab("chat"),ot.getState().setCurrentSession(Pe,Ie)};return window.addEventListener("openchamber:open-session",q),()=>window.removeEventListener("openchamber:open-session",q)},[]),l.useEffect(()=>{if(typeof window>"u")return;const q=()=>{const me=ls.getState().currentDirectory,{activeProjectId:be,projects:Pe}=Gt.getState(),Ie=Pe.find(De=>De.id===be)??null;mr("desktop_open_draft_mini_chat_window",{directory:me||Ie?.path||"",projectId:Ie?.id??null})};return window.addEventListener("openchamber:open-mini-chat",q),()=>window.removeEventListener("openchamber:open-mini-chat",q)},[]),l.useEffect(()=>{if(typeof window>"u")return;const q=()=>{const me=ot.getState().currentSessionId;me&&ku(me)};return window.addEventListener("focus",q),()=>window.removeEventListener("focus",q)},[]),l.useEffect(()=>{if(typeof window>"u")return;const q=me=>{const be=me.detail,Pe=typeof be?.directory=="string"&&be.directory.trim().length>0?be.directory.trim():null,Ie=typeof be?.projectId=="string"&&be.projectId.trim().length>0?be.projectId.trim():null;pe.getState().setActiveMainTab("chat"),pe.getState().setSessionSwitcherOpen(!1),ot.getState().openNewSessionDraft({selectedProjectId:Ie,directoryOverride:Pe,preserveDirectoryOverride:!!Pe})};return window.addEventListener("openchamber:open-draft-session",q),()=>window.removeEventListener("openchamber:open-draft-session",q)},[]),l.useEffect(()=>{typeof window>"u"||!n||g||_.current||(_.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,g]),pg({enabled:K}),pC({enabled:K}),xC(m||null),SC(),gg(),Hg();const he=l.useCallback(()=>{j(q=>!q)},[]);Jk(he),uC(),l.useEffect(()=>{if(W)return;const q=me=>{xu(me)&&me.shiftKey&&!me.altKey&&(me.code==="KeyD"||me.key.toLowerCase()==="d")&&(me.preventDefault(),j(Pe=>!Pe))};return window.addEventListener("keydown",q,!0),()=>window.removeEventListener("keydown",q,!0)},[W]),l.useEffect(()=>{W||d&&setTimeout(()=>u(),5e3)},[u,W,d]),l.useEffect(()=>{if(!B||z!=="not-injected")return;let q=!1,me=0;const be=200,Pe=2e3,Ie=50,De=()=>{if(q)return;me++;const Le=Yl();if(Le!=="not-injected"){if(q=!0,V(Le),Le==="valid"){const ve=Ql();ve&&I(Xl({isDesktopShell:!0,bootOutcome:ve}))}return}const Ne=Math.min(be*Math.pow(1.1,me),Pe);if(me>=Ie){const ve=document.getElementById("initial-loading");ve&&!ve.textContent?.includes("taking longer")&&(ve.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(De,Ne)};return window.setTimeout(De,be),()=>{q=!0}},[B,z]);const xe=l.useCallback(async()=>{if(eh({isDesktopShell:Wn(),isDesktopLocalOriginActive:Mi()})){await th();return}window.location.reload()},[]),H=l.useCallback(async()=>{if(!D){N(!1),O(!0);try{await Kt.getState().initializeApp()}finally{O(!1)}Kt.getState().isInitialized||k(q=>q+1)}},[D]),we=q=>{if(q.screen==="recovery")return q.variant};if(B&&y&&y.screen!=="main"){if(y.screen==="chooser")return s.jsx(ds,{children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(l.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(eu,{mode:"first-launch",localAvailable:y.localAvailable!==!1,onCliAvailable:xe,onChooseRemote:()=>{}})})})});const q=we(y),me=y.screen==="recovery"&&"url"in y?y.url:void 0;return s.jsx(ds,{children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(l.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(eu,{mode:"recovery",recoveryVariant:q,recoveryHostUrl:me,recoveryHostLabel:void 0,localAvailable:y.localAvailable!==!1,onCliAvailable:xe})})})})}if(W)return s.jsx(ds,{children:s.jsx(hc,{sdk:sn.getSdkClient(),directory:m||"",children:s.jsx(pc,{apis:t,children:s.jsx(La,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(EC,{embeddedSessionChat:W,isVSCodeRuntime:p,embeddedBackgroundWorkEnabled:K})})})})},C)});if(Z)return s.jsx(ds,{children:s.jsx(CC,{})});if(S&&!n&&!p&&!W)return s.jsx(ds,{children:s.jsx(AC,{onRetry:()=>{H()},isRetrying:D})});const de=!n&&!B;return s.jsx(ds,{children:s.jsx(hc,{sdk:sn.getSdkClient(),directory:m||"",children:s.jsx(pc,{apis:t,children:s.jsx(Fk,{children:s.jsx(La,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:B?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(zu,{embeddedBackgroundWorkEnabled:K}),s.jsx(Qu,{}),s.jsx(Dk,{}),s.jsx(Uu,{}),!de&&s.jsxs(s.Fragment,{children:[s.jsx(Kg,{}),s.jsx(NC,{}),x&&s.jsx(_k,{onClose:()=>j(!1)})]})]})})})})},C)})}function IC(t){return t.isAboutDialogOpen}function RC(t){return t.setAboutDialogOpen}function MC(t){return t.currentDirectory}function OC(t){return t.currentSessionId}function FC(t){return t.setCurrentSession}const LC=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();bg();sh().then(()=>{Promise.all([nh(),yg()]).catch(t=>{console.error("[main] settings init failed:",t)}),vg(),wg(),Sg()}).catch(t=>{console.error("[main] appearance init failed:",t)});const nm=document.getElementById("root");if(!nm)throw new Error("Root element not found");Rm.createRoot(nm).render(s.jsx(nt.StrictMode,{children:s.jsx(jg,{children:s.jsx(kg,{children:s.jsx(Cg,{children:s.jsx(Ng,{children:s.jsx(TC,{apis:LC})})})})})}));const aN=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{Mb as W,iN as a,Rb as b,qb as d,Sf as g,oN as h,aN as m,kb as u,wf as v};