@openchamber/web 1.19.0 → 1.20.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 (153) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-DAvopJvy.js → CodeMirrorCommentWidgets-C36E738Y.js} +1 -1
  2. package/dist/assets/{CommitSection-D9cV-qR9.js → CommitSection-C-F3AX6D.js} +1 -1
  3. package/dist/assets/{DiagramEditor-B9NCadU7.js → DiagramEditor-BPECg1jS.js} +1 -1
  4. package/dist/assets/DiagramView-D0YNMix8.js +1 -0
  5. package/dist/assets/DiffView-BHWaMYCC.js +4 -0
  6. package/dist/assets/FilesView-NMBCW2Tm.js +14 -0
  7. package/dist/assets/{GitView-DsWXqWx3.js → GitView-Rp8P1KEI.js} +4 -4
  8. package/dist/assets/{JsonTreeView-h4dHASlq.js → JsonTreeView-KnXFN2A-.js} +1 -1
  9. package/dist/assets/{MarkdownImageGallery-n0ikH-xm.js → MarkdownImageGallery-BMn3mtor.js} +1 -1
  10. package/dist/assets/MarkdownRendererImpl-kD6N03pH.js +12 -0
  11. package/dist/assets/{OnboardingScreen-CDjgzxEe.js → OnboardingScreen-CenIeD4v.js} +1 -1
  12. package/dist/assets/{PatchDiff-jPKTJje5.js → PatchDiff-BzVOVog8.js} +1 -1
  13. package/dist/assets/{PierreDiffViewer-D_Gt4A_6.js → PierreDiffViewer-Dlby4XqT.js} +2 -2
  14. package/dist/assets/PlanView-Czu1KMJa.js +4 -0
  15. package/dist/assets/SessionSwitcherDropdown-IETz58DB.js +1 -0
  16. package/dist/assets/SettingsView-B6vmuf-c.js +28 -0
  17. package/dist/assets/SettingsWindow-CauZpdD3.js +1 -0
  18. package/dist/assets/ToolOutputDialog-BB1c--Zr.js +15 -0
  19. package/dist/assets/ToolPartDiffPreview-DaOIDISD.js +8 -0
  20. package/dist/assets/{VirtualizedFileDiff-B37yB9jZ.js → VirtualizedFileDiff-lESMT-2b.js} +4 -4
  21. package/dist/assets/{WalkthroughView-Bxun3k66.js → WalkthroughView-CaSYE0lw.js} +1 -1
  22. package/dist/assets/{computeVirtualFileMetrics-DYFv_yZS.js → computeVirtualFileMetrics-DkRR5b75.js} +2 -2
  23. package/dist/assets/{contextPanelEmbeddedChat-BO1wRpaN.js → contextPanelEmbeddedChat-BEARQjgn.js} +1 -1
  24. package/dist/assets/de-DFdX3ABv.js +9 -0
  25. package/dist/assets/es-iC-FKvV9.js +15 -0
  26. package/dist/assets/fr-BBbi_1AL.js +13 -0
  27. package/dist/assets/{index-BSvmTvZl.js → index-BiEgzzkg.js} +1 -1
  28. package/dist/assets/index-Cwmuwk3V.js +7 -0
  29. package/dist/assets/index-GNm1wgUH.css +1 -0
  30. package/dist/assets/{isDiffPlainText-DwHKxDYc.js → isDiffPlainText-BG53Ixxy.js} +1 -1
  31. package/dist/assets/{isFilePlainText-Dwq6ILxo.js → isFilePlainText-BbV-39jl.js} +1 -1
  32. package/dist/assets/ja-DQLQJL2J.js +15 -0
  33. package/dist/assets/ko-BeElEB4Y.js +15 -0
  34. package/dist/assets/main-Dpzo18z7.js +2 -0
  35. package/dist/assets/main-WMjtYzJs.js +921 -0
  36. package/dist/assets/markdownCore--tDmyI_v.js +2 -0
  37. package/dist/assets/miniChat-ldEghBLB.js +2 -0
  38. package/dist/assets/mobile-Dk-VGreF.js +2 -0
  39. package/dist/assets/{patchFileDiff-BEDPDypx.js → patchFileDiff-BcFaMtMu.js} +2 -2
  40. package/dist/assets/pl-CLHt2_vV.js +15 -0
  41. package/dist/assets/pt-BR-C_MPUq7e.js +15 -0
  42. package/dist/assets/renderElectronMiniChatApp-DIgCOmXY.js +2 -0
  43. package/dist/assets/{renderMobileApp-BiMbzPq9.js → renderMobileApp-CDfHS5rr.js} +7 -7
  44. package/dist/assets/runtimeEndpointReset-ovNbaZ-x.js +15 -0
  45. package/dist/assets/{scheduledTasksApi-01zzfzqH.js → scheduledTasksApi-BFSlqgnG.js} +1 -1
  46. package/dist/assets/{shikiHighlight-DXYW46vW.js → shikiHighlight-DCT2Sq_z.js} +1 -1
  47. package/dist/assets/uk-PhsC-c4-.js +15 -0
  48. package/dist/assets/{useAppFontEffects-CbzHzFop.js → useAppFontEffects-B53Rb6m7.js} +166 -159
  49. package/dist/assets/useInlineCommentController-DSfrIBKT.js +2 -0
  50. package/dist/assets/{vendor-base-ui-BYlZTzrw.js → vendor-base-ui-DsHmyMwp.js} +1 -1
  51. package/dist/assets/{vendor-codemirror-language-data-CiAYDJXN.js → vendor-codemirror-language-data-vch3tJ4c.js} +2 -2
  52. package/dist/assets/vendor-zod-C9ioTTSo.js +39 -0
  53. package/dist/assets/{web-components-DCLjCO9n.js → web-components-pcwCTWjC.js} +4 -4
  54. package/dist/assets/zh-CN-wF-NOFHM.js +15 -0
  55. package/dist/assets/zh-TW-4m4-A7rT.js +15 -0
  56. package/dist/index.html +5 -4
  57. package/dist/mini-chat.html +4 -3
  58. package/dist/mobile.html +4 -3
  59. package/package.json +3 -5
  60. package/server/index.js +36 -0
  61. package/server/lib/agent-memory/project-resolution.js +10 -1
  62. package/server/lib/agent-memory/project-resolution.test.js +9 -0
  63. package/server/lib/agent-memory/runtime.js +7 -2
  64. package/server/lib/dictation/DOCUMENTATION.md +32 -8
  65. package/server/lib/dictation/local/sherpa-recognizer.js +35 -78
  66. package/server/lib/dictation/local/worker-process.js +2 -2
  67. package/server/lib/dictation/openai-compatible-session.js +3 -2
  68. package/server/lib/dictation/stream-manager.js +77 -34
  69. package/server/lib/dictation/stream-manager.test.js +60 -2
  70. package/server/lib/fs/routes.test.js +76 -0
  71. package/server/lib/git/routes.js +43 -0
  72. package/server/lib/git/service.js +85 -5
  73. package/server/lib/git/service.test.js +93 -0
  74. package/server/lib/opencode/DOCUMENTATION.md +6 -2
  75. package/server/lib/opencode/feature-routes-runtime.js +5 -9
  76. package/server/lib/opencode/lifecycle.js +202 -26
  77. package/server/lib/opencode/lifecycle.test.js +179 -1
  78. package/server/lib/opencode/providers.js +9 -4
  79. package/server/lib/opencode/providers.test.js +27 -0
  80. package/server/lib/opencode/restart-session-recovery.test.js +59 -0
  81. package/server/lib/opencode/session-runtime.js +39 -2
  82. package/server/lib/opencode/session-runtime.test.js +74 -0
  83. package/server/lib/opencode/settings-helpers.js +15 -0
  84. package/server/lib/opencode/settings-helpers.test.js +22 -0
  85. package/server/lib/opencode/settings-normalization-runtime.js +3 -0
  86. package/server/lib/opencode/settings-normalization-runtime.test.js +16 -0
  87. package/server/lib/opencode/settings-runtime.js +32 -10
  88. package/server/lib/opencode/settings-runtime.test.js +85 -0
  89. package/server/lib/opencode/skill-routes.js +29 -73
  90. package/server/lib/opencode/skill-routes.test.js +2 -5
  91. package/server/lib/project-context/DOCUMENTATION.md +2 -0
  92. package/server/lib/project-context/runtime.js +7 -2
  93. package/server/lib/projects/project-config.js +7 -2
  94. package/server/lib/quota/DOCUMENTATION.md +1 -1
  95. package/server/lib/quota/providers/claude/index.js +2 -2
  96. package/server/lib/quota/providers/command-code.js +1 -1
  97. package/server/lib/quota/providers/command-code.test.js +13 -0
  98. package/server/lib/quota/providers/index.js +12 -4
  99. package/server/lib/quota/providers/zai.js +26 -6
  100. package/server/lib/quota/providers/zai.test.js +33 -0
  101. package/server/lib/session-knowledge/DOCUMENTATION.md +2 -0
  102. package/server/lib/skills-catalog/DOCUMENTATION.md +18 -45
  103. package/server/lib/skills-catalog/cache.js +120 -1
  104. package/server/lib/skills-catalog/cache.test.js +77 -0
  105. package/server/lib/skills-catalog/curated-sources.js +21 -5
  106. package/server/lib/skills-catalog/curated-sources.test.js +4 -4
  107. package/server/lib/skills-catalog/disk-cache.js +52 -0
  108. package/server/lib/skills-catalog/github-meta.js +139 -0
  109. package/server/lib/skills-catalog/github-meta.test.js +71 -0
  110. package/server/lib/skills-catalog/source.js +0 -5
  111. package/server/lib/small-model/DOCUMENTATION.md +74 -6
  112. package/server/lib/small-model/call.js +46 -12
  113. package/server/lib/small-model/call.test.js +79 -0
  114. package/server/lib/small-model/index.js +51 -8
  115. package/server/lib/small-model/index.test.js +73 -3
  116. package/server/lib/small-model/routes.js +1 -1
  117. package/server/lib/small-model/runtime-providers.js +156 -0
  118. package/server/lib/small-model/runtime-providers.test.js +112 -0
  119. package/dist/assets/DiagramView-LKGBwf4G.js +0 -1
  120. package/dist/assets/DiffView-BWNq-0ov.js +0 -4
  121. package/dist/assets/FilesView-DB-Q0Gkz.js +0 -14
  122. package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +0 -12
  123. package/dist/assets/PlanView-UvuxIl9-.js +0 -4
  124. package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +0 -1
  125. package/dist/assets/SettingsView-3B9VN6Ys.js +0 -28
  126. package/dist/assets/SettingsWindow-CqQNDKNd.js +0 -1
  127. package/dist/assets/ToolOutputDialog-PmjlAxVE.js +0 -15
  128. package/dist/assets/ToolPartDiffPreview-B34Xw9wq.js +0 -8
  129. package/dist/assets/de-DbV6CLxv.js +0 -9
  130. package/dist/assets/es-CVDlyzZ4.js +0 -15
  131. package/dist/assets/fr-Czc-p0g-.js +0 -13
  132. package/dist/assets/index-1OhiMDBz.css +0 -1
  133. package/dist/assets/index-DzriVon2.js +0 -7
  134. package/dist/assets/ja-dwc9NM_S.js +0 -15
  135. package/dist/assets/ko-Ds1DZ8FX.js +0 -15
  136. package/dist/assets/main-BF51IOVF.js +0 -921
  137. package/dist/assets/main-D7UPARut.js +0 -2
  138. package/dist/assets/markdownCore-BgeBDwD3.js +0 -2
  139. package/dist/assets/miniChat-BISXSGOo.js +0 -2
  140. package/dist/assets/mobile-BnYxVuvw.js +0 -2
  141. package/dist/assets/pl-CLiTO7i-.js +0 -15
  142. package/dist/assets/pt-BR-GIimJgpK.js +0 -15
  143. package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +0 -2
  144. package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +0 -15
  145. package/dist/assets/uk-DLfgD1ki.js +0 -15
  146. package/dist/assets/useInlineCommentController-CegKdDXi.js +0 -2
  147. package/dist/assets/vendor-zod-adaMkgkm.js +0 -39
  148. package/dist/assets/zh-CN-DkeP5awK.js +0 -15
  149. package/dist/assets/zh-TW-BocaFm3d.js +0 -15
  150. package/server/lib/skills-catalog/clawdhub/api.js +0 -126
  151. package/server/lib/skills-catalog/clawdhub/install.js +0 -238
  152. package/server/lib/skills-catalog/clawdhub/install.test.js +0 -100
  153. package/server/lib/skills-catalog/clawdhub/scan.js +0 -61
@@ -0,0 +1,921 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/WalkthroughView-CaSYE0lw.js","assets/vendor-react-BUCujlKS.js","assets/vendor-scheduler-7OC5HNn7.js","assets/useAppFontEffects-B53Rb6m7.js","assets/index-Cwmuwk3V.js","assets/vendor-zod-C9ioTTSo.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-opencode-sdk-BJ73u-bH.js","assets/vendor-zustand-BAGL70zf.js","assets/index-GNm1wgUH.css","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-base-ui-DsHmyMwp.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-react-dom-DKpLs02S.js","assets/vendor-floating-ui-dom-WyXykhNi.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-use-sync-external-store-D6wYuSt-.js","assets/contextPanelEmbeddedChat-BEARQjgn.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-framer-motion-CRSgBxjL.js","assets/vendor-motion-dom-DJLgZh4Q.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-tanstack-react-virtual-g05Cx3z9.js","assets/vendor-tanstack-virtual-core-Dubg10g5.js","assets/vendor-sonner-DFyL3AvE.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-vch3tJ4c.js","assets/vendor-codemirror-lang-python-HahnQaAS.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-commands-B7H_j0iU.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/PierreDiffViewer-Dlby4XqT.js","assets/web-components-pcwCTWjC.js","assets/computeVirtualFileMetrics-DkRR5b75.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-lESMT-2b.js","assets/isDiffPlainText-BG53Ixxy.js","assets/vendor-diff-C3JhlQdm.js","assets/useInlineCommentController-DSfrIBKT.js","assets/runtimeEndpointReset-ovNbaZ-x.js","assets/appThemeRegistry-BK0dHKa6.js","assets/registerCustomTheme-BBXUCRnG.js","assets/patchFileDiff-BcFaMtMu.js","assets/SessionSwitcherDropdown-IETz58DB.js","assets/scheduledTasksApi-BFSlqgnG.js","assets/vendor-cron-parser-CUcP7OfX.js","assets/vendor-luxon-BZ0puJYg.js","assets/DiffView-BHWaMYCC.js","assets/FilesView-NMBCW2Tm.js","assets/shikiHighlight-DCT2Sq_z.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-KnXFN2A-.js","assets/Virtualizer-X_7XPoTH.js","assets/isFilePlainText-BbV-39jl.js","assets/DiagramEditor-BPECg1jS.js","assets/vendor-react-drawio-Ct3Q0DsD.js","assets/CodeMirrorCommentWidgets-C36E738Y.js","assets/GitView-Rp8P1KEI.js","assets/CommitSection-C-F3AX6D.js","assets/PlanView-Czu1KMJa.js","assets/DiagramView-D0YNMix8.js","assets/SettingsView-B6vmuf-c.js","assets/vendor-yaml-3778uTud.js","assets/vendor-qrcode-DTJ12-WC.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/SettingsWindow-CauZpdD3.js","assets/OnboardingScreen-CenIeD4v.js"])))=>i.map(i=>d[i]);
2
+ import{f as it,j as s,R as l,r as tt,h as Gm}from"./vendor-react-BUCujlKS.js";import{y as Wn,z as Wi,O as lc,D as qm,A as Ym,B as xu,r as bs,o as Vi,u as he,C as Qm,E as sr,F as Xm,G as jt,H as Tn,I as Hi,J as bu,K as yu,t as Ki,L as Yr,m as as,M as hr,N as Eo,e as pr,P as Jm,a as Ms,Q as Zm,R as eh,S as th,T as vu,n as Ln,v as an,U as sh,V as wu,W as nh,X as Su,Y as rh,Z as qr,_ as bl,$ as Ua,a0 as oh,a1 as ih,a2 as xs,d as Qr,i as ah,a3 as hi,a4 as pi,a5 as lh,a6 as cc,a7 as ch,a8 as dh,a9 as uh,aa as fh,ab as dc,ac as uc,ad as fc,ae as mc,af as mh,q as hc,ag as hh,ah as ph,ai as gh,w as xh,x as bh}from"./index-Cwmuwk3V.js";import{_ as hn}from"./vendor-vite-runtime-DD1OZmLC.js";import{I,f as gt,h as xe,aR as Ht,g as Zn,t as De,aS as cn,aT as ln,aU as dn,aV as un,L as Br,V as nr,aW as br,o as Gi,aX as pc,aY as ft,aZ as mt,a_ as ht,a$ as ju,b0 as yl,b1 as yh,y as nt,b2 as vh,b3 as wh,b4 as ku,b5 as Sh,b6 as gi,b7 as jh,b8 as kh,K as Cu,b9 as Ch,ba as xi,l as Yt,bb as Nh,A as Nu,u as Is,b as Jt,n as Es,aj as Fr,bc as Au,bd as Ah,be as Dh,bf as Ph,bg as Eh,p as Th,bh as Du,bi as Ih,bj as Mh,bk as Rh,bl as Pu,bm as Oh,bn as Fh,bo as Wa,bp as vl,bq as qi,br as Va,ak as wl,bs as Yi,bt as Ir,ae as Eu,bu as $s,bv as zs,bw as An,bx as fn,by as mn,bz as tr,B as lt,bA as Tu,bB as ya,P as Pi,i as Ha,j as Bh,bC as Iu,bD as Lh,bE as Mu,ac as us,G as _h,bF as $h,bG as zh,bH as on,bI as Qi,bJ as Ru,bK as Ka,bL as Uh,bM as Ys,bN as Qs,bO as Rs,bP as Xs,bQ as ls,S as er,bR as Xr,bS as gc,bT as Zr,M as Xi,a0 as Lo,a1 as Sl,bU as Ou,a4 as gr,bV as Ji,bW as $n,Z as jl,bX as Wh,bY as Vh,ab as Hh,bZ as Kh,b_ as Gh,b$ as qh,ad as kl,c0 as Cl,c1 as Co,c2 as Fu,c3 as Yh,c4 as Qh,c5 as _o,c6 as Xh,O as Bu,c7 as Jh,c8 as pn,c9 as Zh,ca as ep,cb as va,cc as Lu,cd as tp,ce as sp,cf as np,cg as xc,ch as jo,c as To,d as Zi,Y as _u,ci as $u,cj as xo,ck as ko,cl as rp,r as Zs,cm as op,cn as zu,W as Nl,co as ip,cp as ap,cq as lp,cr as cp,cs as Uu,ct as Un,cu as dp,cv as up,cw as bc,cx as Wu,cy as fp,cz as Vu,e as Rr,cA as Io,cB as mp,cC as yc,cD as xr,cE as Ga,cF as hp,cG as pp,cH as vc,cI as Gs,cJ as Hu,cK as Ku,cL as gp,cM as bi,cN as xp,Q as Al,N as Dl,R as Pl,cO as El,cP as qa,cQ as Gu,cR as bp,cS as qu,cT as yp,H as vp,cU as wc,cV as wp,cW as Sc,cX as Sp,cY as jp,cZ as Yu,c_ as kp,D as Cp,c$ as Np,d0 as Ap,d1 as Dp,d2 as jc,d3 as Pp,d4 as Ep,C as Tp,d5 as Qu,E as Ip,d6 as kc,d7 as Xu,d8 as Ju,d9 as Mp,da as Rp,db as Op,dc as Fp,dd as Bp,de as Lp,df as ea,a as ta,dg as _p,dh as wa,di as $p,dj as zp,dk as Cc,dl as Up,aw as Ya,dm as Zu,_ as Wp,$ as Vp,aA as Hp,F as Tl,dn as Kp,J as Gp,dp as qp,dq as Yp,dr as Qp,ds as ef,dt as tf,du as sf,dv as Xp,dw as Jp,dx as Zp,dy as eg,dz as tg,dA as sg,dB as ng,dC as rg,dD as og,dE as Ei,a2 as ig,a3 as ag,dF as lg,dG as Nc,dH as cg,dI as dg,dJ as ug,dK as fg,dL as Ac,dM as mg,dN as hg,dO as pg,dP as gg,dQ as xg,dR as bg,dS as yg,dT as yi,dU as nf,dV as vg,dW as wg,dX as Sg,dY as jg,af as kg,dZ as Cg,d_ as Ng,d$ as Ag,e0 as Dg,e1 as Dc,e2 as Pg,aq as Eg,ar as Tg,as as Ig,au as Pc,av as Ec,ay as Tc,ax as rf,az as of,e3 as Mg,aM as Rg,aN as Og,aO as Fg,aP as Bg,aQ as Lg,aI as _g,aJ as $g,aK as zg,aL as Ug}from"./useAppFontEffects-B53Rb6m7.js";import{h as Ic,i as Zt,n as Wg,j as Mc,t as Yn,k as Vg,l as Sa,m as Hg,o as Kg,U as af,b as Il,M as Gg,p as Rc,q as Ti,s as Ml,v as Ii,w as lf,x as qg,y as cf,z as df,A as uf,P as ff,T as mf,B as Yg,E as Qg,F as Xg,S as Oc,u as No,N as Jg,D as Zg,W as ex,L as Fc,G as tx,d as sx,g as nx,f as Qa,H as rx,I as ox,c as ix,e as ax,O as hf,C as lx}from"./runtimeEndpointReset-ovNbaZ-x.js";import{u as pf,S as cx,C as dx,W as gf,f as ux}from"./SessionSwitcherDropdown-IETz58DB.js";import{u as Ar,n as fx,f as mx,a as Bc,s as hx,d as px,b as gx,r as xx}from"./scheduledTasksApi-BFSlqgnG.js";import{c as Lr,u as Xn,d as xf,p as bx}from"./vendor-zustand-BAGL70zf.js";import{g as yx,b as vx,E as bf,c as wx,d as Sx,e as jx,f as kx,i as Cx}from"./contextPanelEmbeddedChat-BEARQjgn.js";import{f as Mi,h as eo,T as Nx,M as Ax,D as Ri,j as Oi,P as Xa,b as Dx,d as Px,k as Ja,i as Ex}from"./vendor-dnd-kit-core-BZknOX2w.js";import{a as yf,S as Za,v as el,u as Rl,s as Tx}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as Ol}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";import{u as Ix}from"./vendor-tanstack-react-virtual-g05Cx3z9.js";import{M as Lc,a as _c,b as $c,C as Mx,c as Rx,d as Ox,S as Fx,e as Bx,f as Lx}from"./vendor-base-ui-DsHmyMwp.js";import{d as vf}from"./vendor-cron-parser-CUcP7OfX.js";import{u as zc,a as Uc,m as Wc}from"./vendor-framer-motion-CRSgBxjL.js";function wf(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(I,{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 Vc(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 _x="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",$x="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",ja=t=>({...t,fallbackIconDataUrl:t.id==="finder"&&window.__OPENCHAMBER_PLATFORM__==="darwin"?_x:t.id==="terminal"?$x:void 0}),Hc=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 p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p=()=>c(!0),e[2]=p):p=e[2];let b;return e[3]!==u?(b=s.jsx("img",{src:u,alt:"",className:"h-4 w-4 rounded-sm",onError:p}),e[3]=u,e[4]=b):b=e[4],b}let m;e[5]===Symbol.for("react.memo_cache_sentinel")?(m=xe("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},zx=t=>{const e=it.c(75),{directory:n,className:r}=t,{t:o}=gt(),i=Ar(Ux),c=Ar(Wx),a=Ar(Vx),d=Ar(Hx),u=Ar(Kx),m=Ar(Gx),f=Ar(qx);let p,b;e[0]!==u?(p=()=>{u()},b=[u],e[0]=u,e[1]=p,e[2]=b):(p=e[1],b=e[2]),l.useEffect(p,b);const k=Wn()&&Wi();let v;e:{let H;e[3]!==c||e[4]!==i?(H=c.find(q=>q.id===i)??c.find(Yx)??c[0]??lc[0],e[3]=c,e[4]=i,e[5]=H):H=e[5];const Se=H;if(Se){let q;e[6]!==Se?(q=ja(Se),e[6]=Se,e[7]=q):q=e[7],v=q;break e}let ae;e[8]===Symbol.for("react.memo_cache_sentinel")?(ae=ja(lc[0]),e[8]=ae):ae=e[8],v=ae}const g=v;if(!k||!n||c.length===0)return null;let h;e[9]!==n?(h=async H=>{await Ym(n,H.id,H.appName)||await xu(n,H.appName)},e[9]=n,e[10]=h):h=e[10];const S=h;let y;e[11]!==S||e[12]!==f?(y=async H=>{await f(H.id),await S(H)},e[11]=S,e[12]=f,e[13]=y):y=e[13];const j=y;let C;e[14]!==n||e[15]!==o?(C=async()=>{(await Zn(n)).ok&&De.success(o("openInApp.toast.pathCopied"))},e[14]=n,e[15]=o,e[16]=C):C=e[16];const N=C;let w;e[17]!==r?(w=xe("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]=w):w=e[18];let A;e[19]!==S||e[20]!==g?(A=()=>{S(g)},e[19]=S,e[20]=g,e[21]=A):A=e[21];const D=d&&"animate-pulse";let P;e[22]!==D?(P=xe("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",D),e[22]=D,e[23]=P):P=e[23];let B;e[24]!==g.label||e[25]!==o?(B=o("openInApp.actions.openInAria",{app:g.label}),e[24]=g.label,e[25]=o,e[26]=B):B=e[26];let F;e[27]!==g.fallbackIconDataUrl||e[28]!==g.iconDataUrl||e[29]!==g.label?(F=s.jsx(Hc,{label:g.label,iconDataUrl:g.iconDataUrl,fallbackIconDataUrl:g.fallbackIconDataUrl}),e[27]=g.fallbackIconDataUrl,e[28]=g.iconDataUrl,e[29]=g.label,e[30]=F):F=e[30];let E;e[31]!==P||e[32]!==B||e[33]!==F||e[34]!==A?(E=s.jsx("button",{type:"button",onClick:A,className:P,"aria-label":B,children:F}),e[31]=P,e[32]=B,e[33]=F,e[34]=A,e[35]=E):E=e[35];let _;e[36]===Symbol.for("react.memo_cache_sentinel")?(_=xe("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]=_):_=e[36];let L;e[37]!==o?(L=o("openInApp.actions.chooseAppAria"),e[37]=o,e[38]=L):L=e[38];let W;e[39]===Symbol.for("react.memo_cache_sentinel")?(W=s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4"}),e[39]=W):W=e[39];let K;e[40]!==L?(K=s.jsx(cn,{asChild:!0,children:s.jsx("button",{type:"button",className:_,"aria-label":L,children:W})}),e[40]=L,e[41]=K):K=e[41];let x;e[42]!==N?(x=()=>{N()},e[42]=N,e[43]=x):x=e[43];let M;e[44]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(I,{name:"file-copy",className:"h-4 w-4"}),e[44]=M):M=e[44];let z;e[45]!==o?(z=o("openInApp.actions.copyPath"),e[45]=o,e[46]=z):z=e[46];let U;e[47]!==z?(U=s.jsx("span",{className:"typography-ui-label text-foreground",children:z}),e[47]=z,e[48]=U):U=e[48];let V;e[49]!==x||e[50]!==U?(V=s.jsxs(Ht,{className:"flex items-center gap-2",onClick:x,children:[M,U]}),e[49]=x,e[50]=U,e[51]=V):V=e[51];let Z;e[52]===Symbol.for("react.memo_cache_sentinel")?(Z=s.jsx(ln,{}),e[52]=Z):Z=e[52];let X;if(e[53]!==c||e[54]!==j||e[55]!==g.id){let H;e[57]!==j||e[58]!==g.id?(H=Se=>{const ae=ja(Se);return s.jsxs(Ht,{className:"flex items-center gap-2",onClick:()=>{j(Se)},children:[s.jsx(Hc,{label:Se.label,iconDataUrl:Se.iconDataUrl,fallbackIconDataUrl:ae.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Se.label}),g.id===Se.id?s.jsx(I,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},Se.id)},e[57]=j,e[58]=g.id,e[59]=H):H=e[59],X=c.map(H),e[53]=c,e[54]=j,e[55]=g.id,e[56]=X}else X=e[56];let le;e[60]!==a||e[61]!==m||e[62]!==o?(le=a?s.jsxs(Ht,{className:"flex items-center gap-2",onClick:()=>{m(!0)},children:[s.jsx(I,{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]!==V||e[65]!==X||e[66]!==le?(te=s.jsxs(dn,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[V,Z,X,le]}),e[64]=V,e[65]=X,e[66]=le,e[67]=te):te=e[67];let fe;e[68]!==K||e[69]!==te?(fe=s.jsxs(un,{children:[K,te]}),e[68]=K,e[69]=te,e[70]=fe):fe=e[70];let ge;return e[71]!==E||e[72]!==fe||e[73]!==w?(ge=s.jsxs("div",{className:w,children:[E,fe]}),e[71]=E,e[72]=fe,e[73]=w,e[74]=ge):ge=e[74],ge};function Ux(t){return t.selectedAppId}function Wx(t){return t.availableApps}function Vx(t){return t.isCacheStale}function Hx(t){return t.isScanning}function Kx(t){return t.initialize}function Gx(t){return t.loadInstalledApps}function qx(t){return t.selectApp}function Yx(t){return t.id===qm}const Fi=new Map,tl=new Set,Sf=()=>{for(const t of tl)t()},ka=(t,e)=>{const n=t.trim();n&&(e.length===0?Fi.delete(n):Fi.set(n,[...e]),Sf())},Qx=t=>{Fi.delete(t.trim())&&Sf()},jf=[],Xx=t=>Fi.get(t.trim())??jf,Jx=t=>(tl.add(t),()=>{tl.delete(t)}),Zx=t=>{const e=it.c(2);let n;return e[0]!==t?(n=()=>Xx(t),e[0]=t,e[1]=n):n=e[1],l.useSyncExternalStore(Jx,n,eb)};function eb(){return jf}const tb=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],sb=["dev","start","preview","serve"];async function nb(t,e,n){if(!t)return null;const r=ib(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id,previewUrlHint:r.openUrl};if(n){const o=ab(n);if(o){const i=await lb(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 rb(t)){const o=await ob(),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 rb(t){const e=`${t}/index.html`,n=await Bi(e,t);return typeof n=="string"&&n.trim().length>0}async function ob(){try{const t=await bs("/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 ib(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(sb.some(o=>n.includes(o)))return e}return null}function ab(t){for(const{pattern:e}of tb)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function lb(t){const e=await Bi(`${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 Bi(`${t}/${r}`,t);if(typeof i=="string"&&i.trim().length>0)return o}return"npm"}async function Bi(t,e){if(e?.trim())try{const r=new URLSearchParams({path:t,directory:e,optional:"true"}),o=await bs(`/api/fs/read?${r.toString()}`,{cache:"no-store"});if(o.ok)return o.text()}catch{}const n=Vi()?.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 bs(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return r.ok?r.text():null}catch{return null}}async function cb(t){try{const e=await Bi(`${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 db=(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)}),nn="__openchamber_auto_discover_preview__",ub=15e3,fb=3e3,mb=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},hb=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}},kf=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:o=!1})=>{const{t:i}=gt(),{currentTheme:c}=Br(),{terminal:a,runtime:d}=nr(),{isMobile:u}=br(),m=l.useMemo(()=>Wn(),[]),f=Ic(ie=>ie.instances),p=Ic(ie=>ie.load),b=he(ie=>ie.terminalShell),k=he(ie=>ie.terminalLoginShells.includes(ie.terminalShell)),v=he(ie=>ie.setSettingsPage),g=he(ie=>ie.setSettingsDialogOpen),h=he(ie=>ie.setSettingsProjectsSelectedId),S=he(ie=>ie.openContextPreview),y=Zt(ie=>ie.ensureDirectory),j=Zt(ie=>ie.setTabLabel),C=Zt(ie=>ie.setTabIconKey),N=Zt(ie=>ie.setActiveTab),w=Zt(ie=>ie.setConnecting),A=Zt(ie=>ie.setTabSessionId),D=Zt(ie=>ie.setTabPreviewUrl),P=Zt(ie=>ie.projectActionRuns),B=Zt(ie=>ie.setProjectActionRun),F=Zt(ie=>ie.updateProjectActionRunStatus),E=Zt(ie=>ie.removeProjectActionRun),[_,L]=l.useState([]),[W,K]=l.useState(null),[x,M]=l.useState(!1),z=l.useRef({}),U=l.useRef({}),V=l.useRef({}),Z=l.useRef({}),X=l.useRef(new Set),le=l.useRef(0),te=t?.id??null,fe=t?.path??"",ge=l.useMemo(()=>te?{id:te,path:fe}:null,[te,fe]);l.useEffect(()=>{m&&p().catch(()=>{})},[m,p]);const H=l.useCallback(async ie=>{await Gi(ie)},[]),Se=l.useCallback(async()=>{if(!ge)return;const ie=le.current+1;le.current=ie,M(!0);try{const Re=await pc(ge);if(le.current!==ie)return;const be=Re.actions;L(be),K(T=>T===nn||T&&be.some(ce=>ce.id===T)?T:null)}catch{if(le.current!==ie)return}finally{le.current===ie&&M(!1)}},[ge]),ae=l.useMemo(()=>Wg(e||ge?.path||""),[e,ge?.path]),q=l.useMemo(()=>W?_.find(ie=>ie.id===W)??null:null,[_,W]),me=l.useMemo(()=>({id:nn,name:i("projectActions.actions.autoDiscover"),command:"",icon:"scan-2",autoOpenUrl:!0}),[i]),pe=!u,Ie=l.useMemo(()=>pe?[me,..._]:_,[_,me,pe]);l.useEffect(()=>{Se()},[Se]),l.useEffect(()=>{if(typeof window>"u")return;const ie=Re=>{const be=Re.detail;te&&(be?.projectId&&be.projectId!==te||Se())};return window.addEventListener(Mc,ie),()=>{window.removeEventListener(Mc,ie)}},[Se,te]),l.useEffect(()=>{W&&(W===nn&&pe||_.some(ie=>ie.id===W)||K(null))},[_,pe,W]),l.useEffect(()=>{const ie=be=>{delete Z.current[be];const T=U.current[be];if(!T||T.openedUrl)return;const ce=Zt.getState(),ve=ce.projectActionRuns[be];if(!ve)return;const Ce=T.announced;if(Ce.length!==0){if(T.openedUrl=!0,ce.updateProjectActionRunStatus(be,"running"),Ce.length===1){ka(ve.directory,[]),D(ve.directory,ve.tabId,Ce[0],{locked:!1,autoOpened:!0}),S(ve.directory,Ce[0]);return}T.offering=!0,ka(ve.directory,Ce),he.getState().openContextSurface(ve.directory,"browser"),De.info(i("projectActions.toast.multipleServers"))}},Re=()=>{const be=Zt.getState(),T=be.sessions,ce=be.projectActionRuns;for(const[ve,Ce]of Object.entries(ce)){const ne=T.get(Ce.directory)?.tabs.find(st=>st.id===Ce.tabId);if(!ne||ne.terminalSessionId!==Ce.sessionId){E(ve);continue}const ke=U.current[ve]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1,announced:[],offering:!1};U.current[ve]=ke;const Ze=Ie.find(st=>st.id===Ce.actionId),Q=be.getBuffer(Ce.directory,Ce.tabId).chunks;if(!Ze||Q.length===0)continue;const ye=Q.filter(st=>ke.lastSeenChunkId===null||st.id>ke.lastSeenChunkId);if(ye.length===0)continue;const Qe=ye.map(st=>st.data).join(""),$e=`${ke.tail}${Qe}`;if(ke.openInPreview&&(!ke.openedUrl||ke.offering)){const st=Hg($e),ct=ke.announced.length;for(const It of st)ke.announced.includes(It)||ke.announced.push(It);const Pt=ke.announced.length-ct;ke.offering&&Pt>0?ka(Ce.directory,ke.announced):!ke.openedUrl&&ct===0&&ke.announced.length>0&&(window.clearTimeout(Z.current[ve]),Z.current[ve]=window.setTimeout(()=>ie(ve),fb))}const ze=!ke.openedUrl&&Ze.autoOpenUrl===!0&&!ke.openInPreview?Kg($e):null,Le=ye[ye.length-1]?.id??ke.lastSeenChunkId;if(ke.lastSeenChunkId=Le,ke.tail=$e.slice(-512),ze)if(ke.openedUrl=!0,ke.openInPreview){const st=ce[ve];st&&(D(st.directory,st.tabId,ze,{locked:!1,autoOpened:!1}),st.status==="waiting-for-preview"&&F(ve,"running"),window.clearTimeout(Z.current[ve]),delete Z.current[ve],S(st.directory,ze))}else H(ze),De.success(i("projectActions.toast.openedUrlFromOutput"));U.current[ve]=ke}for(const ve of Object.keys(U.current))ce[ve]||(delete U.current[ve],window.clearTimeout(Z.current[ve]),delete Z.current[ve])};return Re(),Zt.subscribe((be,T)=>{(be.sessions!==T.sessions||be.buffers!==T.buffers)&&Re()})},[Ie,S,H,P,E,D,i,F]);const Oe=l.useCallback(async(ie,Re={})=>{if(!ae)throw new Error(i("projectActions.error.noActiveDirectory"));const be=Yn(ae,ie.id);y(ae);const T=Zt.getState(),ce=T.getDirectoryState(ae);let ve=z.current[be]||null;const Ce=ve?!!ce?.tabs.some(ke=>ke.id===ve):!1;(!ve||!Ce)&&(ve=T.createTab(ae),z.current[be]=ve),j(ae,ve,`Action: ${ie.name}`),C(ae,ve,ie.icon||"play"),N(ae,ve),Re.revealTerminal!==!1&&he.getState().openContextPanelTab(ae,{mode:"terminal"});const ne=Zt.getState().getDirectoryState(ae)?.tabs.find(ke=>ke.id===ve);return{key:be,tabId:ve,sessionId:ne?.terminalSessionId??null}},[y,ae,N,C,j,i]),Me=l.useCallback(async ie=>{if(d.isVSCode||!o&&u)return;if(!ae){De.error(i("projectActions.error.noActiveDirectoryForAction"));return}const Re=Yn(ae,ie.id),be=P[Re];if(!(be&&be.status==="running")&&!X.current.has(Re)){X.current.add(Re);try{const T=ie.id===nn?await(async()=>{const[ze,Le]=await Promise.all([pc({id:ge?.id??"",path:ae}),cb(ae)]),st=await nb(ae,ze.actions,Le);if(!st)throw new Error(i("contextPanel.preview.noDevServer"));return{id:nn,name:i("projectActions.actions.autoDiscover"),command:st.command,icon:"scan-2",autoOpenUrl:!0,openUrl:st.previewUrlHint||""}})():ie,ce=T.autoOpenUrl===!0&&(T.openUrl||"").trim().length>0,ve=!ce&&ie.id!==nn,{key:Ce,tabId:Ae,sessionId:ne}=await Oe(T,{revealTerminal:ve});let ke=ne;if(!ke){w(ae,Ae,!0);try{ke=(await a.createSession({cwd:ae,sessionId:Ae,shell:b,loginShell:k,themeMode:c.metadata.variant==="light"?"light":"dark",terminalBackground:c.colors.surface.background,terminalForeground:c.colors.syntax.base.foreground})).sessionId,A(ae,Ae,ke)}finally{w(ae,Ae,!1)}}if(!ke)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));V.current[Ce]?.(),w(ae,Ae,!0);const Ze=a.connect(ke,{onEvent:ze=>{ze.type==="snapshot"&&(Zt.getState().replaceBuffer(ae,Ae,ze.data??"",ze.sequence??0),Zt.getState().setConnecting(ae,Ae,!1)),ze.type==="data"&&typeof ze.data=="string"&&ze.data.length>0&&Zt.getState().appendToBuffer(ae,Ae,ze.data,ze.sequence,ze.replayData),ze.type==="exit"&&(Zt.getState().setTabLifecycle(ae,Ae,"exited"),Zt.getState().setConnecting(ae,Ae,!1),Zt.getState().removeProjectActionRun(Ce),delete U.current[Ce],V.current[Ce]?.(),delete V.current[Ce],window.clearTimeout(Z.current[Ce]),delete Z.current[Ce])},onError:(ze,Le)=>{Zt.getState().setConnecting(ae,Ae,!1),Le&&(Zt.getState().setTabLifecycle(ae,Ae,"exited"),Zt.getState().setTabSessionId(ae,Ae,null),Zt.getState().removeProjectActionRun(Ce))}});V.current[Ce]=Ze.close;const Q=T.autoOpenUrl===!0&&m&&(T.desktopOpenSshForward||"").trim().length>0,ye=T.autoOpenUrl?hb(T.openUrl):null,Qe=T.autoOpenUrl&&m?Vg(T.desktopOpenSshForward,f):null;B({key:Ce,directory:ae,actionId:T.id,tabId:Ae,sessionId:ke,status:T.id===nn&&!ye?"waiting-for-preview":"running"}),window.clearTimeout(Z.current[Ce]),delete Z.current[Ce],T.id===nn&&!ye&&(Z.current[Ce]=window.setTimeout(()=>{const ze=Zt.getState(),Le=ze.projectActionRuns[Ce];ze.updateProjectActionRunStatus(Ce,"running"),Le&&(ze.setActiveTab(Le.directory,Le.tabId),he.getState().openContextPanelTab(Le.directory,{mode:"terminal"})),delete Z.current[Ce]},ub)),U.current[Ce]={lastSeenChunkId:null,openedUrl:!!Qe||!!ye||ce,tail:"",openInPreview:T.id===nn,announced:[],offering:!1};const $e=mb(T.command.trim().replace(/\r\n|\r/g,`
3
+ `));await a.sendInput(ke,`${$e}\r`),Qe?(D(ae,Ae,null,{locked:!0}),H(Qe),De.success(i("projectActions.toast.openedForwardedUrl"))):ye?(D(ae,Ae,ye,{locked:!0,autoOpened:!0}),S(ae,ye),De.success(i("projectActions.toast.openedActionUrl"))):ce?(D(ae,Ae,null,{locked:!0}),De.error(i("projectActions.error.invalidCustomUrlFormat"))):Q?(D(ae,Ae,null,{locked:!0}),De.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):D(ae,Ae,null,{locked:!1,autoOpened:!1})}catch(T){E(Re),delete U.current[Re],V.current[Re]?.(),delete V.current[Re],window.clearTimeout(Z.current[Re]),delete Z.current[Re],De.error(T instanceof Error?T.message:i("projectActions.error.failedToRunAction"))}finally{X.current.delete(Re)}}},[c.colors.surface.background,c.colors.syntax.base.foreground,c.metadata.variant,f,Oe,o,u,m,ae,k,b,H,S,P,d.isVSCode,E,w,B,D,A,ge?.id,i,a]),Fe=l.useCallback(async ie=>{const Re=Yn(ae,ie.id),be=P[Re];if(!be)return;F(Re,"stopping");const T=db(a,be.sessionId,1e3);try{await a.sendInput(be.sessionId,"")}catch{}const ce=await T;if(Zt.getState().getDirectoryState(be.directory)?.tabs.find(Ae=>Ae.id===be.tabId)?.terminalSessionId===be.sessionId&&!ce){if(typeof a.forceKill=="function")try{await a.forceKill({sessionId:be.sessionId})}catch{}else try{await a.close(be.sessionId)}catch{}A(be.directory,be.tabId,null)}E(Re),delete U.current[Re],V.current[Re]?.(),delete V.current[Re],window.clearTimeout(Z.current[Re]),delete Z.current[Re]},[ae,P,E,A,a,F]),je=l.useCallback(()=>{const ie=q??Ie[0];if(!ie)return;const Re=Yn(ae,ie.id),be=P[Re];if(be?.status!=="stopping"){if(be){Fe(ie);return}Me(ie)}},[Ie,ae,Me,P,q,Fe]),Ne=l.useCallback((ie,Re=!1)=>{if(K(ie.id),!Re){Me(ie);return}const be=Yn(ae,ie.id),T=P[be];if(T?.status!=="stopping"){if(T){Fe(ie);return}Me(ie)}},[ae,Me,P,Fe]),Pe=l.useCallback(()=>{ge?.id&&(h(ge.id),v("projects"),g(!0))},[g,v,h,ge?.id]),se=q??Ie[0]??null,oe=se?P[Yn(ae,se.id)]:null,Ee=Zt(ie=>oe?ie.sessions.get(oe.directory)?.tabs.find(Re=>Re.id===oe.tabId)?.previewUrl??null:null);if(d.isVSCode||!o&&u||!ge||!ae)return null;const J=q??Ie[0]??null;if(!J)return null;const re=J.icon||"play",ee=J.id===nn?"scan-2":Sa[re]||"play",$=Yn(ae,J.id),de=P[$],Y=de?.status==="stopping",ue=de?.status==="waiting-for-preview",Te=!!(de&&Ee),Ge=()=>{!de||!Ee||S(de.directory,Ee)},_e=J.id===nn;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:x||Y,className:xe("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:je,"aria-label":de?i("projectActions.actions.stopNamedAria",{name:J.name}):i("projectActions.actions.runNamedAria",{name:J.name}),children:Y||ue?s.jsx(I,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):de?s.jsx(I,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(I,{name:ee,className:"h-5 w-5"})})}),_e?s.jsx(ht,{sideOffset:6,children:i("projectActions.actions.autoDiscoverTooltip")}):null]}),Te?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:Ge,children:s.jsx(I,{name:"global",className:"h-4 w-4"})})}),s.jsx(ht,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(un,{children:[s.jsx(cn,{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(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})}),s.jsxs(dn,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(Ht,{className:"flex items-center gap-2",onClick:Pe,children:[s.jsx(I,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(ln,{}),Ie.map(ie=>{const Re=ie.icon||"play",be=ie.id===nn?"scan-2":Sa[Re]||"play",T=Yn(ae,ie.id),ce=P[T],ve=!!ce,Ce=ce?.status==="stopping";return s.jsxs(Ht,{className:"flex items-center gap-2",onClick:()=>{Ne(ie,!0)},children:[s.jsx(I,{name:be,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ie.name}),Ce||ce?.status==="waiting-for-preview"?s.jsx(I,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):ve?s.jsx(I,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},ie.id)})]})]})]}):s.jsxs("div",{className:xe("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:je,disabled:x||Y,className:xe("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":de?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:Y||ue?s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):de?s.jsx(I,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(I,{name:ee,className:"h-4 w-4"})})})}),_e?s.jsx(ht,{sideOffset:6,children:i("projectActions.actions.autoDiscoverTooltip")}):null]}),Te?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ge,className:xe(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(I,{name:"global",className:"h-4 w-4"})})}),s.jsx(ht,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(un,{children:[s.jsx(cn,{asChild:!0,children:s.jsx("button",{type:"button",className:xe(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(I,{name:"arrow-down-s",className:"h-4 w-4"})})}),s.jsxs(dn,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(Ht,{className:"flex items-center gap-2",onClick:Pe,children:[s.jsx(I,{name:"add",className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:i("projectActions.actions.addNewAction")})]}),s.jsx(ln,{}),Ie.map(ie=>{const Re=ie.icon||"play",be=ie.id===nn?"scan-2":Sa[Re]||"play",T=Yn(ae,ie.id),ce=P[T],ve=!!ce,Ce=ce?.status==="stopping";return s.jsxs(Ht,{className:"flex items-center gap-2",onClick:()=>{Ne(ie,!0)},children:[s.jsx(I,{name:be,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ie.name}),Ce||ce?.status==="waiting-for-preview"?s.jsx(I,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):ve?s.jsx(I,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},ie.id)})]})]})]})};function pb(t){if(typeof t!="number"||!Number.isFinite(t))return"";const e=new Date(t);if(Number.isNaN(e.getTime()))return"";const n=e.toLocaleString(yl(),{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 gb(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 xb(t){const e=t.info.role==="user"?"User":"Assistant",n=pb(t.info.time?.created),r=gb(t),o=n&&r?`${n} (${r})`:n||r;return o?`**${e}**
4
+
5
+ *${o}*`:`**${e}**`}function bb(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function Cf(t){const e=xb(t),n=bb(t.parts).trim();return n?`${e}
6
+
7
+ ${n}`:""}function Nf(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(Nf(a,e+1));return c.join(`
16
+
17
+ ---
18
+
19
+ `)}function Af(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=>Nf(u,1)).join(`
30
+
31
+ ---
32
+
33
+ `);a+=`
34
+
35
+ ---
36
+
37
+ `+d}return a}function Df(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 Pf(t,e){const n=await Qm(e,t);if(n)return n;if(!sr())return null;try{const r=await Vi()?.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 yb(t){const e=Vi()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await Xm(t)?!0:xu(t)}function vb(){return ju()}function Ef(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 Fl=Lr(()=>({pendingSessionIds:new Set})),Tf=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],Fl(n)},Kc=(t,e)=>{Fl.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}})},wb=async(t,e)=>{try{const d=(await kh(t,{mode:"light"})).current?.trim();if(d)return d}catch{}const n=jt(t),r=jt(e)??e,o=nt.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")},Gc=(t,e)=>{const n=jh(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")},Sb=async(t,e,n,r,o)=>{const i=[];for(const c of[...t].reverse())try{await ku(c,r,n,c.id===e),nt.getState().setWorktreeMetadata(c.id,o.get(c.id)??null)}catch(a){i.push(a)}return i},jb=async(t,e,n)=>{try{await Cu(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},kb=async t=>{if(Fl.getState().pendingSessionIds.has(t.root.id))throw new Error("Session move already in progress");Kc(t.root.id,!0);try{const e=yh(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,nt.getState().getWorktreeMetadata(a.id)]));Gc(n,t.sourceDirectory);const o=await wb(t.sourceDirectory,e.path),i=await vh(e,{startRef:o}),c=[];try{await wh(i.path),Gc(n,t.sourceDirectory);for(const[a,d]of n.entries())await ku(d,t.sourceDirectory,i.path,a===0),c.push(d),nt.getState().setWorktreeMetadata(d.id,Sh(i))}catch(a){if((await Sb(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 jb(e,i,a)}try{await gi([t.sourceDirectory,i.path])}catch(a){console.warn("[session-worktree-move] Failed to refresh moved sessions",a)}return i.path}finally{Kc(t.root.id,!1)}},If=t=>{kb(t).then(()=>De.success(t.successMessage)).catch(e=>De.error(t.failureMessage,{description:e instanceof Error?e.message:String(e)}))},Mo="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",Cb="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",Nb=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,p=m===void 0?!1:m;if(!f)return null;const b=a??Mo,k=p&&"bg-interactive-selection text-interactive-selection-foreground";let v;n[0]!==b||n[1]!==k?(v=xe(b,k),n[0]=b,n[1]=k,n[2]=v):v=n[2];const g=u??"h-[18px] w-[18px]";let h;n[3]!==d||n[4]!==g?(h=s.jsx(I,{name:d,className:g}),n[3]=d,n[4]=g,n[5]=h):h=n[5];let S;n[6]!==i||n[7]!==c||n[8]!==p||n[9]!==v||n[10]!==h?(S=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,"aria-label":i,"aria-pressed":p,className:v,children:h})}),n[6]=i,n[7]=c,n[8]=p,n[9]=v,n[10]=h,n[11]=S):S=n[11];let y;n[12]!==o?(y=s.jsx(ht,{children:s.jsx("p",{children:o})}),n[12]=o,n[13]=y):y=n[13];let j;return n[14]!==S||n[15]!==y?(j=s.jsxs(ft,{children:[S,y]}),n[14]=S,n[15]=y,n[16]=j):j=n[16],j}),Ab=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 k;n[0]===Symbol.for("react.memo_cache_sentinel")?(k=xe(Mo,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=k):k=n[0];let v;n[1]!==a||n[2]!==m?(v=a?m("header.github.connectedWithLogin",{login:a}):m("header.github.connected"),n[1]=a,n[2]=m,n[3]=v):v=n[3];let g;n[4]!==c||n[5]!==a||n[6]!==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(I,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[4]=c,n[5]=a,n[6]=m,n[7]=g):g=n[7];let h;n[8]!==d||n[9]!==v||n[10]!==g?(h=s.jsx(cn,{asChild:!0,children:s.jsx("button",{type:"button",className:k,title:v,disabled:d,children:g})}),n[8]=d,n[9]=v,n[10]=g,n[11]=h):h=n[11];let S;n[12]!==m?(S=m("header.github.accountsTitle"),n[12]=m,n[13]=S):S=n[13];let y;n[14]!==S?(y=s.jsx(xi,{className:"typography-ui-header font-semibold text-foreground",children:S}),n[14]=S,n[15]=y):y=n[15];let j;n[16]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(ln,{}),n[16]=j):j=n[16];let C;if(n[17]!==i||n[18]!==u||n[19]!==d||n[20]!==m){let A;n[22]!==u||n[23]!==d||n[24]!==m?(A=D=>{const P=D.user,B=!!D.current,F=D.source==="gh-cli"?m("header.github.accountSource.cli"):m("header.github.accountSource.oauth");return s.jsxs(Ht,{className:"gap-2",disabled:d,onSelect:()=>{B||u(D.id)},children:[P?.avatarUrl?s.jsx("img",{src:P.avatarUrl,alt:P.login?m("header.github.avatarWithLogin",{login:P.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(I,{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:P?.name?.trim()||P?.login||"GitHub"}),P?.login?s.jsxs("span",{className:"truncate typography-micro text-muted-foreground",children:[s.jsx("span",{className:"font-mono",children:P.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:F})]}):null]}),B?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]},D.id)},n[22]=u,n[23]=d,n[24]=m,n[25]=A):A=n[25],C=i.map(A),n[17]=i,n[18]=u,n[19]=d,n[20]=m,n[21]=C}else C=n[21];let N;n[26]!==y||n[27]!==C?(N=s.jsxs(dn,{align:"end",className:"w-64",children:[y,j,C]}),n[26]=y,n[27]=C,n[28]=N):N=n[28];let w;return n[29]!==h||n[30]!==N?(w=s.jsxs(un,{children:[h,N]}),n[29]=h,n[30]=N,n[31]=w):w=n[31],w}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 p;n[35]!==c||n[36]!==a||n[37]!==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(I,{name:"github-fill",className:"h-3.5 w-3.5 text-foreground"}),n[35]=c,n[36]=a,n[37]=m,n[38]=p):p=n[38];let b;return n[39]!==f||n[40]!==p?(b=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:p}),n[39]=f,n[40]=p,n[41]=b):b=n[41],b}),Db=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:p,remoteUpdateError:b,onOpenRemoteUpdate:k}=e,{t:v}=gt();let g;n[0]!==u||n[1]!==d?(g=E=>{d(E),E&&u()},n[0]=u,n[1]=d,n[2]=g):g=n[2];let h;n[3]!==o||n[4]!==r||n[5]!==v?(h=r?v("header.services.openWithCurrent",{current:o}):v("header.services.open"),n[3]=o,n[4]=r,n[5]=v,n[6]=h):h=n[6];const S=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let y;n[7]!==S?(y=xe(Mo,S),n[7]=S,n[8]=y):y=n[8];let j;n[9]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(I,{name:"server",className:"h-[18px] w-[18px]"}),n[9]=j):j=n[9];let C;n[10]!==i||n[11]!==r?(C=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:i}):null,n[10]=i,n[11]=r,n[12]=C):C=n[12];let N;n[13]!==h||n[14]!==y||n[15]!==C?(N=s.jsx(mt,{asChild:!0,children:s.jsx(cn,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":h,className:y,children:[j,C]})})}),n[13]=h,n[14]=y,n[15]=C,n[16]=N):N=n[16];let w;n[17]!==o||n[18]!==m||n[19]!==v?(w=v("header.services.tooltip.currentInstance",{current:o,toggle:m("toggle_services_menu")}),n[17]=o,n[18]=m,n[19]=v,n[20]=w):w=n[20];let A;n[21]!==w?(A=s.jsx(ht,{children:s.jsx("p",{children:w})}),n[21]=w,n[22]=A):A=n[22];let D;n[23]!==N||n[24]!==A?(D=s.jsxs(ft,{children:[N,A]}),n[23]=N,n[24]=A,n[25]=D):D=n[25];let P;n[26]!==c||n[27]!==r||n[28]!==a||n[29]!==k||n[30]!==p||n[31]!==b||n[32]!==f||n[33]!==d||n[34]!==v?(P=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:v("header.services.remoteUpdate.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:f?.available?v("header.services.remoteUpdate.available",{version:f.version||""}):p?v("header.services.remoteUpdate.checking"):b||v("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:k,children:v("header.services.remoteUpdate.actions.open")}):null]})}),s.jsx(Ch,{embedded:!0,open:a,onOpenChange:Ib,onHostSwitched:()=>d(!1)})]}):null,n[26]=c,n[27]=r,n[28]=a,n[29]=k,n[30]=p,n[31]=b,n[32]=f,n[33]=d,n[34]=v,n[35]=P):P=n[35];let B;n[36]!==P?(B=s.jsx(dn,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto p-0",children:P}),n[36]=P,n[37]=B):B=n[37];let F;return n[38]!==a||n[39]!==g||n[40]!==D||n[41]!==B?(F=s.jsxs(un,{open:a,onOpenChange:g,children:[D,B]}),n[38]=a,n[39]=g,n[40]=D,n[41]=B,n[42]=F):F=n[42],F}),Pb=(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??""),Eb=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},Tb=(t,e)=>{if(!t)return"-";try{return Mu(t,e,{fallback:"-"})}catch{return"-"}},Bn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},Ca=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,qc=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r})=>{Tn("ui.header.render");const{t:o}=gt(),i=he(O=>O.setSessionSwitcherOpen),c=he(O=>O.toggleSidebar),a=he(O=>O.isSidebarOpen),d=he(O=>O.openContextOverview),u=he(O=>O.openContextPlan),m=he(O=>O.closeContextPanel),f=he(O=>O.activeMainTab),p=he(O=>O.setActiveMainTab),b=he(O=>O.shortcutOverrides),k=he(O=>O.timeFormatPreference),v=Yt(O=>O.getCurrentModel),g=nr(),h=nt(O=>O.getContextUsage),S=nt(O=>!!O.newSessionDraft?.open),y=nt(O=>O.currentSessionId),j=Nh(y??""),C=Nu(y??""),N=Tf(y??""),w=Is(Xn(l.useCallback(O=>{if(!y)return null;const Ve=O.activeSessions.find(Nt=>Nt.id===y);if(!Ve)return null;const ot=Ve;return{title:Ve.title??null,directory:ot.directory??null,created:Ve.time?.created??null,slug:ot.slug??null,shareUrl:Ve.share?.url??null,parentId:Ve.parentID??null}},[y]))),A=Jt(Xn(O=>{if(!O.activeProjectId)return null;const Ve=O.projects.find(ot=>ot.id===O.activeProjectId);return Ve?{id:Ve.id,path:Ve.path,label:Ve.label}:null})),D=l.useMemo(()=>{if(!A)return null;const O=A.label?.trim();if(O)return O;const Ve=A.path.split(/[\\/]/).filter(Boolean);return Ve[Ve.length-1]??null},[A]),P=Es(O=>O.results),B=Es(O=>O.fetchAllQuotas),F=Es(O=>O.isLoading),E=Es(O=>O.lastUpdated),_=Es(O=>O.displayMode),L=Es(O=>O.dropdownProviderIds),W=Es(O=>O.loadSettings),K=Es(O=>O.setDisplayMode),{isMobile:x}=br(),M=Fr(O=>O.status),z=Fr(O=>O.setStatus),U=l.useRef(null),[V,Z]=l.useState(()=>typeof window>"u"?!1:Wn()),X=l.useMemo(()=>Hi(),[]),le=Au(),[te,fe]=l.useState(!1),ge=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),{usesFramelessChrome:H,side:Se}=pf(),ae=l.useMemo(()=>{if(typeof window>"u")return null;const O=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof O=="number"&&Number.isFinite(O)&&O>0)return O;if(typeof navigator>"u")return null;const Ve=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Ve)return null;const ot=Number.parseInt(Ve[1],10),Nt=Number.parseInt(Ve[2],10);return Number.isNaN(ot)?null:ot===10?Nt:ot},[]);tt.useEffect(()=>{typeof window>"u"||Z(Wn())},[]);const q=v(),me=q&&typeof q.limit=="object"&&q.limit!==null?q.limit:null,pe=me&&typeof me.context=="number"?me.context:0,Ie=me&&typeof me.output=="number"?me.output:0,Oe=h(pe,Ie),[Me,Fe]=l.useState(null),je=!y||j;tt.useEffect(()=>{if(!y){Fe(O=>O===null?O:null);return}if(Oe&&Oe.totalTokens>0){Fe(O=>Pb(O,Oe)?O:Oe);return}je&&Fe(O=>O===null?O:null)},[Oe,y,je]);const Ne=he(O=>O.isSessionSwitcherOpen),Pe=M?.connected?M.user?.avatarUrl??null:null,se=M?.connected?M.user?.login??null:null,oe=M?.accounts??[],[Ee,J]=l.useState(!1),[re,ee]=l.useState(!1),[$,de]=l.useState(!1),[Y,ue]=l.useState(!1),[Te,Ge]=l.useState("Local"),[_e,ie]=l.useState(!0),[Re,be]=l.useState(!1),[T,ce]=l.useState(null),[ve,Ce]=l.useState(!1),[Ae,ne]=l.useState(null),ke=l.useMemo(()=>Eb(Te),[Te]),[Ze,Q]=l.useState("usage"),ye=l.useMemo(()=>sr(),[]),Qe=he(O=>O.workStatusPanelVisible),$e=he(O=>O.workStatusPanelEnabled),ze=he(O=>O.setWorkStatusPanelEnabled),Le=he(O=>O.workStatusPanelFits),st=he(O=>O.workStatusOverlayOpen),ct=he(O=>O.setWorkStatusOverlayOpen),It=$e&&Le||st,Tt=l.useCallback(()=>{if($e&&!Le){ct(!st);return}ze(!$e)},[ct,ze,st,$e,Le]),et=!ye&&!Qe&&f==="chat"&&!!Me&&Me.totalTokens>0,Mt=Me&&Me.contextLimit>0?Math.min(999,Me.totalTokens/Me.contextLimit*100):0,kt=l.useCallback(async()=>{if(!(typeof window>"u"||!V))try{if(Wi()){Ge("Local"),ie(!0);return}ie(!1);const O=await bu(),Ve=Ah(),ot=Dh([Ph(Ve),...O.hosts]);if(ot.id===Eh){Ge("Local"),ie(!0);return}Ge(yu(ot.label.trim()||"Instance"))}catch{Ge("Local"),ie(!0)}},[V]);tt.useEffect(()=>(kt(),Ki(()=>{kt()})),[kt]);const bt=l.useCallback(async()=>{if(_e){ce(null),ne(null);return}Ce(!0),ne(null);try{const O=new URLSearchParams({appType:"web",instanceMode:"remote",reportUsage:"false"}),Ve=await bs(`/api/openchamber/update-check?${O.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!Ve.ok)throw new Error(`Server responded with ${Ve.status}`);const ot=await Ve.json();ce({available:ot.available??!1,version:ot.version,currentVersion:ot.currentVersion??"unknown",body:ot.body,nextSuggestedCheckInSec:typeof ot.nextSuggestedCheckInSec=="number"?ot.nextSuggestedCheckInSec:void 0,packageManager:ot.packageManager,updateCommand:ot.updateCommand})}catch(O){ce(null),ne(O instanceof Error?O.message:o("header.services.remoteUpdate.error"))}finally{Ce(!1)}},[_e,o]);l.useEffect(()=>{ce(null),ne(null),be(!1)},[_e,Te]),l.useEffect(()=>{if(!V||_e)return;const O=3e3,Ve=3600*1e3;let ot=!1,Nt=null;const qt=cs=>{Nt=window.setTimeout(()=>{if(ot||typeof document<"u"&&document.visibilityState!=="visible"){qt(Ve);return}bt().finally(()=>{ot||qt(Ve)})},cs)};return qt(O),()=>{ot=!0,Nt!==null&&window.clearTimeout(Nt)}},[bt,_e,Te,V]);const Bt=l.useCallback(()=>{if(T?.available){be(!0);return}bt()},[bt,T?.available]);Th();const wt=Es(O=>O.selectedModels),Rt=Es(O=>O.expandedFamilies),pt=Es(O=>O.toggleFamilyExpanded),yt=l.useMemo(()=>{const O=[];for(const Ve of Du){if(!L.includes(Ve.id))continue;const ot=P.find(ws=>ws.providerId===Ve.id),Nt=ot?.usage?.windows??{},qt=ot?.usage?.models,cs=Object.entries(Nt),is={providerId:Ve.id,providerName:Ve.name,entries:cs,error:ot&&!ot.ok&&ot.configured?ot.error:void 0};if(qt&&Object.keys(qt).length>0){const ws=wt[Ve.id]??[],On=ws.length>0,po=Ih(qt,Ve.id),qo=Mh(Ve.id),Vr=Rh(qo);is.modelFamilies=[];for(const yn of Vr){const sn=po.get(yn.id)??[];if(sn.length===0)continue;const Pn=On?sn.filter(jr=>ws.includes(jr)):sn;if(Pn.length===0)continue;const qn=[];for(const jr of Pn){const kr=qt[jr];if(kr?.windows){const Cr=Object.entries(kr.windows);Cr.length>0&&qn.push([jr,Cr[0][1]])}}qn.length>0&&is.modelFamilies.push({familyId:yn.id,familyLabel:yn.label,models:qn})}const go=po.get(null)??[],Hr=On?go.filter(yn=>ws.includes(yn)):go;if(Hr.length>0){const yn=[];for(const sn of Hr){const Pn=qt[sn];if(Pn?.windows){const qn=Object.entries(Pn.windows);qn.length>0&&yn.push([sn,qn[0][1]])}}yn.length>0&&is.modelFamilies.push({familyId:null,familyLabel:o("header.services.modelFamily.other"),models:yn})}}(cs.length>0||is.modelFamilies&&is.modelFamilies.length>0||is.error)&&O.push(is)}return O},[L,P,wt,o]),Ke=yt.length>0;l.useEffect(()=>{W()},[W]);const Ue=l.useCallback(async O=>{K(O);try{await Yr({usageDisplayMode:O})}catch(Ve){console.warn("Failed to update usage display mode:",Ve)}},[K]),xt=l.useCallback(()=>{if(Y)return;ue(!0);const O=new Promise(Ve=>setTimeout(Ve,500));Promise.all([B(),O]).finally(()=>{ue(!1)})},[B,Y]),Ft=y?w??null:null,$t=l.useRef(null),[ns,Kt]=l.useState(0);l.useEffect(()=>{if(!y){$t.current&&($t.current=null,Kt(Nt=>Nt+1));return}if(Ft){$t.current={sessionId:y,session:Ft,expiresAt:Date.now()+2e3};return}const O=$t.current;if(!O||O.sessionId!==y)return;const Ve=O.expiresAt-Date.now();if(Ve<=0){$t.current=null,Kt(Nt=>Nt+1);return}const ot=window.setTimeout(()=>{$t.current?.sessionId===y&&($t.current=null),Kt(Nt=>Nt+1)},Ve);return()=>{window.clearTimeout(ot)}},[y,Ft]);const St=(()=>{if(Ft)return Ft;if(!y)return null;const O=$t.current;return O&&O.sessionId===y&&O.expiresAt>Date.now()?O.session:null})(),zt=nt(O=>y?O.worktreeMetadata.get(y)?.path??"":""),ms=nt(O=>y?O.worktreeMetadata.get(y)?.branch?.trim()??null:null),ts=Pu(O=>y?O.getAttachment(y):void 0),ys=l.useMemo(()=>ts?Oh(ts,{pending:o("gitView.empty.worktreeSetupInProgress")}):null,[o,ts]),Vt=l.useMemo(()=>ts?ts.legacy?"legacy":ts.degraded?"degraded":ts.worktreeStatus==="pending"?"pending":ts.worktreeStatus==="missing"?"missing":ts.worktreeStatus==="invalid"?"invalid":ts.attentionReason?"attention":null:null,[ts]),Gt=l.useMemo(()=>Bn(zt||""),[zt]),Ut=l.useMemo(()=>{const O=typeof St?.directory=="string"?St.directory:"";return Bn(O||"")},[St?.directory]),Be=nt(O=>O.newSessionDraft?.open?Bn(O.newSessionDraft.bootstrapPendingDirectory??O.newSessionDraft.directoryOverride??""):""),Xe=nt(O=>O.newSessionDraft.target),Je=nt(O=>O.newSessionDraft.selectedProjectId),He=nt(O=>O.currentSessionDirectory),rt=as(O=>O.homeDirectory),Dt=l.useMemo(()=>Gt||Ut||Be,[Be,Ut,Gt]),Wt=he(l.useCallback(O=>{const Ve=Bn(Dt||"");return Ve?Ca(O.contextPanelByDirectory[Ve]):null},[Dt])),rs=nt(O=>{const Ve=Bn(Gt||Ut||"");if(!Ve)return null;for(const ot of O.availableWorktreesByProject.values()){const qt=ot.find(cs=>Bn(cs.path)===Ve)?.branch?.trim();if(qt)return qt}return null}),os=Fh(Dt||null)||ms||rs,es=S?Xe==="chat":Wa(Ut||He,rt),Us=!es&&!Qe&&!!(D||os||!S&&Vt),Ws=l.useMemo(()=>{if(!y)return D??"OpenChamber";const O=St?.title?.trim();return O&&O.length>0?O:"Untitled Session"},[D,St?.title,y]),Hn=vl(Dt||void 0,{bootstrap:!1}),gn=qi(),In=nt(O=>O.updateSessionTitle),xn=nt(O=>O.shareSession),As=nt(O=>O.unshareSession),Kn=nt(O=>O.archiveSessions),Os=nt(O=>O.deleteSessions),[Vs,Fs]=l.useState(!1),[rr,en]=l.useState(!1),js=l.useRef(!1),[Mn,Rn]=l.useState(""),[tn,G]=l.useState(null),Ye=l.useRef(null);l.useEffect(()=>{js.current=!1,en(!1),Fs(!1),Rn(""),G(null)},[y]);const at=l.useCallback(()=>{y&&(Rn(St?.title?.trim()||Ws),Fs(!0))},[St?.title,y,Ws]),ut=l.useCallback(async()=>{if(!y)return;const O=Mn.trim();O&&O!==St?.title?.trim()&&await In(y,O),Fs(!1)},[St?.title,y,Mn,In]);l.useEffect(()=>{if(!Vs)return;const O=Ve=>{const ot=Ve.target;(!ot||!Ye.current?.contains(ot))&&ut()};return document.addEventListener("mousedown",O),()=>document.removeEventListener("mousedown",O)},[Vs,ut]);const _t=l.useCallback(()=>{y&&Zn(y).then(O=>{De[O.ok?"success":"error"](o(O.ok?"sessions.sidebar.session.copyId.success":"sessions.sidebar.session.copyId.error"))}).catch(()=>De.error(o("sessions.sidebar.session.copyId.error")))},[y,o]),Et=l.useCallback(async()=>{if(!y)return;const O=await xn(y);if(O?.share?.url){const Ve=await Zn(O.share.url);De[Ve.ok?"success":"warning"](o("sessions.sidebar.session.share.successTitle"),{description:o(Ve.ok?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")});return}De.error(o("sessions.sidebar.session.share.error"))},[y,xn,o]),vt=l.useCallback(()=>{const O=St?.shareUrl;O&&Zn(O).then(Ve=>{De[Ve.ok?"success":"error"](o(Ve.ok?"sessions.sidebar.session.menu.copied":"sessions.sidebar.session.share.copyUrlError"))}).catch(()=>De.error(o("sessions.sidebar.session.share.copyUrlError")))},[St?.shareUrl,o]),fs=l.useCallback(async()=>{if(!y)return;const O=await As(y);De[O?"success":"error"](o(O?"sessions.sidebar.session.unshare.success":"sessions.sidebar.session.unshare.error"))},[y,o,As]),ks=l.useCallback(async()=>{if(!y||!Dt){De.error(o("sessions.sidebar.session.export.nothingToExport"));return}try{await gn.loadCompleteHistory(y,Dt)}catch{De.error(o("sessions.sidebar.session.export.failedLoadHistory"));return}const O=Va(Hn.getState(),y).list;if(O.length===0){De.error(o("sessions.sidebar.session.export.nothingToExport"));return}const Ve=Af(O,St?.title??null),ot=Ef(St?.title??null);await Pf(Ve,ot)||Df(Ve,ot),De.success(o("sessions.sidebar.session.export.success"))},[St?.title,y,Hn,Dt,gn,o]),Qt=C?.type==="busy"||C?.type==="retry",Bs=l.useCallback(()=>{if(!y||!Ut||Qt||N)return;const O=Is.getState().activeSessions,Ve=O.find(qt=>qt.id===y);if(!Ve)return;const ot=[],Nt=[y];for(let qt=0;qt<Nt.length;qt+=1){const cs=Nt[qt];for(const is of O)is.parentID===cs&&(ot.push(is),Nt.push(is.id))}If({root:Ve,descendants:ot,sourceDirectory:Ut,successMessage:o("sessions.sidebar.session.moveToWorktree.success"),failureMessage:o("sessions.sidebar.session.moveToWorktree.failed")})},[y,Qt,N,Ut,o]),Hs=l.useCallback(async()=>{if(!y||!tn)return;const O=Is.getState().activeSessions,Ve=[y];for(let cs=0;cs<Ve.length;cs+=1){const is=Ve[cs];for(const ws of O)ws.parentID===is&&!Ve.includes(ws.id)&&Ve.push(ws.id)}const ot=tn;if(G(null),(ot==="archive"?await Kn(Ve):await Os(Ve)).failedIds.length>0){De.error(o(ot==="archive"?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error"));return}De.success(o(ot==="archive"?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"))},[Kn,y,Os,tn,o]),or=he(O=>O.isScheduledTasksDialogOpen),Dn=he(O=>O.isArchivePageOpen),Gn=he(O=>O.worktreesPageProjectId),yr=he(O=>O.isMultiRunLauncherOpen),_r=Jt(O=>{if(!Gn)return null;const Ve=O.projects.find(ot=>ot.id===Gn);return Ve?.label?.trim()||Ve?.path?.split("/").pop()||null}),ir=l.useMemo(()=>or?{title:o("sessions.scheduledTasks.dialog.title"),subtitle:null}:Dn?{title:o("sessions.archivePage.title"),subtitle:null}:Gn?{title:o("sessions.worktreesPage.title",{project:_r??""}),subtitle:null}:yr?{title:o("sessions.sidebar.header.actions.newMultiRun"),subtitle:null}:null,[Dn,yr,or,o,Gn,_r]),we=l.useMemo(()=>Bn(Dt||A?.path||""),[A?.path,Dt]),At=l.useMemo(()=>A?{id:A.id,path:A.path}:null,[A]),Xt=l.useRef(null);l.useEffect(()=>{!At||!we||(Xt.current={projectRef:At,directory:we})},[we,At]);const ss=l.useMemo(()=>At&&we?{projectRef:At,directory:we}:Xt.current,[we,At]),hs=wl(O=>O.planModeEnabled),vs=nt(O=>O.isSessionPlanAvailable),Ls=hs&&y?vs(y):!1,Ds=Ls,Ks=l.useRef("");l.useEffect(()=>{if(!hs){he.getState().activeMainTab==="plan"&&he.getState().setActiveMainTab("chat");return}if(!y)return;const O=`${y||"none"}:${Ut||"none"}:${St?.created||0}:${St?.slug||"none"}`;Ks.current!==O&&(Ks.current=O),!Ls&&he.getState().activeMainTab==="plan"&&he.getState().setActiveMainTab("chat")},[hs,Ls,St?.slug,St?.created,y,Ut]);const vr=l.useCallback(async O=>{if(!(!O||Ee)){J(!0);try{const Ve=g.github?await g.github.authActivate(O):await(async()=>{const ot=await bs("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:O})}),Nt=await ot.json().catch(()=>null);if(!ot.ok||!Nt)throw new Error(Nt?.error||ot.statusText);return Nt})();z(Ve)}catch(Ve){console.error("Failed to switch GitHub account:",Ve)}finally{J(!1)}}},[Ee,g.github,z]),ds=l.useCallback(()=>{if(typeof document>"u")return;const O=document.activeElement;if(!O)return;const Ve=O.tagName;(Ve==="INPUT"||Ve==="TEXTAREA"||Ve==="SELECT"||O.isContentEditable)&&O.blur()},[]),ps=l.useCallback(()=>{if(x){ds(),i(!Ne);return}c()},[ds,x,Ne,i,c]),bn=l.useCallback(()=>{hr("desktop_open_draft_mini_chat_window",{directory:es?"":Be,projectId:es?null:Je,apiBaseUrl:pr(),clientToken:Eo()}).catch(O=>{console.warn("[header] failed to open draft mini chat window",O)})},[Be,Je,es]),oa=l.useCallback(()=>{if(S){bn();return}y&&hr("desktop_open_session_mini_chat_window",{sessionId:y,directory:Ut||Bn(He||"")||Gt,apiBaseUrl:pr(),clientToken:Eo()}).catch(O=>{console.warn("[header] failed to open session mini chat window",O)})},[y,bn,S,He,Ut,Gt]),ia=l.useCallback(()=>{const O=Bn(Dt||"");if(!O)return;const Ve=he.getState().contextPanelByDirectory[O];if(Ca(Ve)==="context"){m(O);return}d(O)},[m,d,Dt]),aa=Wt==="context",zo=l.useCallback(()=>{const O=Bn(Dt||"");if(!O)return;const Ve=he.getState().contextPanelByDirectory[O];if(Ca(Ve)==="plan"){m(O);return}u(O)},[m,u,Dt]),Uo=Mo,$r=Cb,zr=l.useMemo(()=>re?"services":n?"sessions":r?"git":f,[f,re,n,r]),co=l.useCallback(()=>{ee(!1),n&&t&&t(),r&&e&&e(),!t&&Ne&&i(!1)},[Ne,n,t,e,r,i]),la=l.useCallback(()=>{n||ee(!1),t?.()},[n,t]),uo=l.useCallback(()=>{r||ee(!1),e?.()},[e,r]),fo=l.useMemo(()=>V&&ge&&!te?"5.5rem":le?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":(!V||H)&&!ye?"calc(0.75rem + var(--oc-wco-left-inset, 0px))":"0.75rem",[V,te,ge,le,ye,H]);tt.useEffect(()=>{typeof document>"u"||document.documentElement.style.setProperty("--oc-titlebar-left-inset",fo)},[fo]);const Ur=a?"0.75rem":"var(--oc-titlebar-left-inset, 0.75rem)",Wo=a?"0px":"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)";tt.useEffect(()=>{if(!V||!ge){fe(!1);return}let O=!1;const Ve=async()=>{try{const Nt=await hr("desktop_is_window_fullscreen");O||fe(Nt===!0)}catch{O||fe(!1)}},ot=()=>{Ve()};return Ve(),window.addEventListener("openchamber:window-resized",ot),()=>{O=!0,window.removeEventListener("openchamber:window-resized",ot)}},[V,ge]);const mo=l.useMemo(()=>!V||!ge||ae===null?"":ae>=26?"h-12":ae<=15?"h-14":"",[V,ge,ae]),ca=l.useMemo(()=>{if(!(V&&!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))"}},[V,ye,H]),wr=l.useCallback(()=>{if(typeof document>"u")return;const O=U.current?.getBoundingClientRect().height;O&&document.documentElement.style.setProperty("--oc-header-height",`${O}px`)},[]);tt.useEffect(()=>{if(typeof window>"u")return;wr();const O=U.current;if(!O||typeof ResizeObserver>"u")return()=>{};let Ve=0;const ot=()=>{Ve||(Ve=requestAnimationFrame(()=>{Ve=0,wr()}))},Nt=new ResizeObserver(ot);return Nt.observe(O),window.addEventListener("resize",ot),window.addEventListener("orientationchange",ot),()=>{Ve&&cancelAnimationFrame(Ve),Nt.disconnect(),window.removeEventListener("resize",ot),window.removeEventListener("orientationchange",ot)}},[wr]),tt.useEffect(()=>{wr()},[wr,x,mo]);const da=l.useCallback(async O=>{const Ve=O.target;Ve.closest(".app-region-no-drag")||Ve.closest("button, a, input, select, textarea")||O.button===0&&V&&await Jm()},[V]),Cs=l.useMemo(()=>{if(x){const O=[{id:"chat",label:o("layout.mainTab.chat"),icon:"chat-4"}];return Ds&&O.push({id:"plan",label:o("layout.mainTab.plan"),icon:"file-text"}),O.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"}),O}return[]},[x,Ds,o]),ua=l.useCallback(O=>Yi(Ir(O,b)),[b]);tt.useEffect(()=>{!x&&f!=="chat"&&f!=="terminal"&&f!=="diagram"&&p("chat")},[f,x,p]);const ar=l.useMemo(()=>{const O=[];return V&&O.push({value:"instance",label:o("layout.services.instance"),icon:s.jsx(I,{name:"server",className:"h-3.5 w-3.5"})}),O},[V,o]),Vo=l.useMemo(()=>[{id:"usage",label:o("layout.services.usage"),icon:s.jsx(I,{name:"timer",className:"h-3.5 w-3.5"})},{id:"mcp",label:"MCP",icon:s.jsx(Eu,{className:"h-3.5 w-3.5"})}],[o]);tt.useEffect(()=>{const O=Ve=>{if(Tu(Ve)&&!Ve.shiftKey&&!Ve.altKey){const ot=parseInt(Ve.key,10);ot>=1&&ot<=Cs.length&&(Ve.preventDefault(),x&&(ds(),co()),p(Cs[ot-1].id))}};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[ds,co,x,p,Cs]),tt.useEffect(()=>{const O=Ve=>{const ot=Ir("toggle_services_menu",b);if(ya(Ve,ot)){Ve.preventDefault(),$?de(!1):(de(!0),kt());return}const Nt=Ir("cycle_services_tab",b);if(ya(Ve,Nt)){if(Ve.preventDefault(),ar.length===0)return;de(!0),kt();return}const qt=Ir("toggle_context_plan",b);ya(Ve,qt)&&(Ve.preventDefault(),zo())};return window.addEventListener("keydown",O),()=>window.removeEventListener("keydown",O)},[b,$,ar,P.length,B,kt,zo]);const ho=O=>{const Ve=f===O.id,ot=O.icon==="diff",Nt=ot?null:O.icon,qt=O.id==="chat",cs=ws=>ot?s.jsx(Vc,{size:ws}):Nt?s.jsx(I,{name:Nt,className:`h-${ws/4} w-${ws/4}`}):null,is=s.jsxs("button",{type:"button",onClick:()=>p(O.id),className:xe("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",Ve?"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",qt&&!x&&"min-w-[100px] justify-center"),"aria-label":O.label,"aria-selected":Ve,role:"tab",children:[x?cs(20):s.jsxs(s.Fragment,{children:[cs(16),s.jsx("span",{className:"header-tab-label",children:O.label})]}),O.badge!==void 0&&O.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:O.badge})]});return s.jsx(l.Fragment,{children:is},O.id)},Wr=s.jsxs(s.Fragment,{children:[s.jsx(zx,{directory:we,className:"mr-1"}),V?s.jsx(Db,{isDesktopApp:V,currentInstanceLabel:Te,compactCurrentInstanceLabel:ke,currentInstanceIsLocal:_e,isDesktopServicesOpen:$,setIsDesktopServicesOpen:de,refreshCurrentInstanceLabel:kt,shortcutLabel:ua,remoteUpdateInfo:T,remoteUpdateChecking:ve,remoteUpdateError:Ae,onOpenRemoteUpdate:Bt}):null,s.jsx(Ab,{isMobile:x,githubAuthStatus:M,githubAccounts:oe,githubAvatarUrl:Pe,githubLogin:se,isSwitchingGitHubAccount:Ee,handleGitHubAccountSwitch:vr})]}),Sr=X&&(S||!!y),Ho=()=>s.jsxs("div",{onMouseDown:da,className:xe("app-region-drag relative flex h-12 select-none items-center",H&&Se==="right"?"pr-0":"pr-3",mo),style:ca,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:Ur}}),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:Wo}}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[ir?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:ir.title}),ir.subtitle?s.jsx("span",{className:"truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75 max-w-full",children:ir.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(cx,{align:"start",children:s.jsx("button",{type:"button",className:Uo,"aria-label":o("sessions.switcher.openAria"),children:s.jsx(I,{name:"history",className:"h-[18px] w-[18px]"})})}),s.jsxs("div",{className:"flex min-w-0 flex-col justify-center px-1",children:[Vs?s.jsxs("form",{ref:Ye,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onSubmit:O=>{O.preventDefault(),ut()},children:[s.jsx("input",{value:Mn,onChange:O=>Rn(O.target.value),autoFocus:!0,onKeyDown:O=>{O.stopPropagation(),O.key==="Escape"&&Fs(!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(I,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:()=>Fs(!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(I,{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:S?o("sessions.switcher.draftTitle"):Ws}),Us?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:[D?s.jsx("span",{className:"truncate",children:D}):null,os?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-0.5",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0 text-muted-foreground/70"}),s.jsx("span",{className:"truncate",children:os})]}):null,!S&&Vt?s.jsxs("span",{className:xe("inline-flex min-w-0 items-center gap-0.5",Vt==="attention"||Vt==="invalid"||Vt==="missing"?"text-status-warning":"text-muted-foreground/60"),children:[s.jsx(I,{name:"alert",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:ys})]}):null]}):null]}),s.jsx("div",{className:xe("flex h-[18px] shrink-0 items-center justify-center",Us?"self-start":"self-center"),children:y&&!S&&!Vs?s.jsxs(un,{open:rr,onOpenChange:en,onOpenChangeComplete:O=>{!O&&js.current&&(js.current=!1,at())},children:[s.jsx(cn,{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(I,{name:"more",className:"size-4"})})}),s.jsxs(dn,{align:"end",className:"min-w-[190px]",children:[s.jsxs(Ht,{onClick:()=>{js.current=!0},children:[s.jsx(I,{name:"pencil-ai",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.rename")]}),s.jsxs(Ht,{onClick:_t,children:[s.jsx(I,{name:"file-copy",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.copyId")]}),s.jsx(ln,{}),St?.shareUrl?s.jsxs(s.Fragment,{children:[s.jsxs(Ht,{onClick:vt,children:[s.jsx(I,{name:"file-copy",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.copyLink")]}),s.jsxs(Ht,{onClick:()=>{fs()},children:[s.jsx(I,{name:"link-unlink-m",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(Ht,{onClick:()=>{Et()},children:[s.jsx(I,{name:"share-2",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.share")]}),s.jsxs(Ht,{onClick:()=>{ks()},children:[s.jsx(I,{name:"download",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.exportMarkdown")]}),!ye&&!es&&St&&!St.parentId?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(Ht,{disabled:!Ut||Qt||N,onClick:Bs,className:"w-full",children:[s.jsx(I,{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(N?"sessions.sidebar.session.moveToWorktree.tooltipMoving":Qt?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,s.jsx(ln,{}),s.jsxs(Ht,{onClick:()=>G("archive"),children:[s.jsx(I,{name:"inbox-archive",className:"mr-2 size-4"}),o("sessions.sidebar.bulkActions.archive")]}),s.jsxs(Ht,{className:"text-destructive focus:text-destructive",onClick:()=>G("delete"),children:[s.jsx(I,{name:"delete-bin",className:"mr-2 size-4"}),o("sessions.sidebar.bulkActions.delete")]})]})]}):null})]}),Cs.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:Cs.map(O=>ho(O))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[et&&Me?s.jsx(dx,{totalTokens:Me.totalTokens,percentage:Mt,colorPercentage:Me.percentage,contextLimit:Me.contextLimit,outputLimit:Me.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:ia,pressed:aa,className:Sr?"":"mr-3.5",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-4.5 w-4.5"}):null,s.jsx(Nb,{visible:Sr,title:o(S?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:o(S?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:oa,className:xe(Uo,"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":It,"aria-label":o("header.workStatusPanel.toggleAria"),onClick:Tt,className:xe(Mo,"mr-1",It?"text-foreground":"text-muted-foreground/50"),children:s.jsx(I,{name:"list-indefinite",className:"h-[18px] w-[18px]"})})}),s.jsx(ht,{side:"bottom",children:o($e&&!Le?st?"header.workStatusPanel.hide":"header.workStatusPanel.showOverlay":$e?"header.workStatusPanel.hide":"header.workStatusPanel.show")})]}):null,Wr,s.jsx(gf,{visible:H&&Se==="right",position:"right"})]})]})]}),Ko=()=>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:la,className:xe($r,zr==="sessions"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":o(n?"header.actions.closeSessionsAria":"header.actions.openSessionsAria"),children:s.jsx(I,{name:"layout-left",className:"h-5 w-5"})}):Ne?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(I,{name:"arrow-left-s",className:"h-5 w-5"})}):s.jsx("button",{type:"button",onClick:ps,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(I,{name:"play-list-add",className:"h-5 w-5"})}),!t&&Ne&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:o("header.sessions.title")})]}),(!Ne||!!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:Cs.map(O=>{const Ve=f===O.id,ot=O.icon==="diff",Nt=ot?null:O.icon;return s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{x&&(ds(),co()),p(O.id)},"aria-label":O.label,"aria-selected":Ve,role:"tab",className:xe($r,"relative rounded-lg",zr===O.id&&"bg-interactive-selection text-interactive-selection-foreground"),children:[ot?s.jsx(Vc,{className:"h-5 w-5"}):Nt?s.jsx(I,{name:Nt,className:"h-5 w-5"}):null,O.badge!==void 0&&O.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:O.badge}),O.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:O.label})})]},O.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[ss&&s.jsx(kf,{projectRef:ss.projectRef,directory:ss.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(un,{open:re,onOpenChange:O=>{O&&(n&&t&&t(),r&&e&&e()),ee(O),O&&P.length===0&&B()},children:[s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx(cn,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":o("header.services.viewAria"),className:xe($r,zr==="services"&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(I,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(ht,{children:s.jsx("p",{children:o("header.services.title")})})]}),s.jsx(dn,{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(Il,{items:Vo,activeId:Ze,onSelect:O=>{const Ve=O;Q(Ve),Ve==="usage"&&P.length===0&&B()},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:()=>ee(!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(I,{name:"close",className:"h-5 w-5"})})]})}),Ze==="mcp"&&s.jsx(Gg,{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:Tb(E,k)})]}),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:()=>Ue("usage"),className:xe("typography-ui-label px-1 pb-0.5 transition-colors",_==="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:()=>Ue("remaining"),className:xe("typography-ui-label px-1 pb-0.5 transition-colors",_==="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:xe("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:xt,disabled:F||Y,"aria-label":o("header.services.refreshRateLimitsAria"),children:s.jsx(I,{name:"refresh",className:xe("h-4 w-4",Y&&"animate-spin")})})]})]})}),!Ke&&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:yt.map((O,Ve)=>s.jsxs(l.Fragment,{children:[Ve>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(Pi,{providerId:O.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:O.providerName})]}),O.entries.length===0&&(!O.modelFamilies||O.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:O.error??o("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[O.entries.map(([ot,Nt])=>{const qt=_==="remaining"?Nt.remainingPercent:Nt.usedPercent,cs=Ha(Nt.valueLabel,qt),is=Bh(Nt.resetAt,Nt.resetAfterFormatted??Nt.resetAtFormatted,k);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:Iu(ot)}),is?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:is}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:cs==="-"?"":cs})]}),s.jsx(Rc,{percent:qt,tonePercent:Nt.usedPercent,className:"h-1.5"})]},`${O.providerId}-${ot}`)}),O.modelFamilies&&O.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:O.modelFamilies.map(ot=>{const qt=(Rt[O.providerId]??[]).includes(ot.familyId??"other");return s.jsxs(Ti,{open:qt,onOpenChange:()=>pt(O.providerId,ot.familyId??"other"),children:[s.jsxs(Ml,{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:ot.familyLabel}),qt?s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsx(Ii,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:ot.models.map(([cs,is])=>{const ws=_==="remaining"?is.remainingPercent:is.usedPercent,On=Ha(is.valueLabel,ws);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:Lh(cs)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:On==="-"?"":On})]}),s.jsx(Rc,{percent:ws,tonePercent:is.usedPercent,className:"h-1.5"})]},`${O.providerId}-${cs}`)})})})]},ot.familyId??"other")})})]})]},O.providerId))})]})]})})]}),e?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:uo,className:xe($r,"relative",zr==="git"&&"bg-interactive-selection text-interactive-selection-foreground"),"aria-label":r?"Close git sidebar":"Open git sidebar",children:s.jsx(I,{name:"layout-right",className:"h-5 w-5"})})}),s.jsx(ht,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),Go=xe("header-safe-area relative z-10 bg-background",x&&"border-b border-border/50");return s.jsxs(s.Fragment,{children:[s.jsx("header",{ref:U,className:Go,style:{"--padding-scale":"1"},children:x?Ko():Ho()}),s.jsx($s,{open:tn!==null,onOpenChange:O=>{O||G(null)},children:s.jsxs(zs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(An,{children:[s.jsx(fn,{children:o(tn==="delete"?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.archiveSession.title")}),s.jsx(mn,{children:tn==="delete"?o("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:Ws}):o("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:Ws})})]}),s.jsxs(tr,{children:[s.jsx(lt,{variant:"outline",size:"sm",onClick:()=>G(null),children:o("sessions.sidebar.dialogs.cancel")}),s.jsx(lt,{variant:"destructive",size:"sm",onClick:()=>{Hs()},children:o(tn==="delete"?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")})]})]})}),s.jsx(af,{open:Re,onOpenChange:be,info:T,downloading:!1,downloaded:!1,progress:null,error:Ae,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})};function Ib(){}const Yc=280,Qc=280,Xc=500,Mb=({isOpen:t,isMobile:e,children:n,className:r,topBar:o})=>{const{t:i}=gt(),c=he(w=>w.sidebarWidth),a=he(w=>w.setSidebarWidth),[d,u]=l.useState(!1),m=l.useRef(0),f=l.useRef(c||Yc),p=l.useRef(null),b=l.useRef(null),k=l.useRef(null),v=l.useCallback(w=>Math.min(Xc,Math.max(Qc,w)),[]),g=l.useCallback(w=>{const A=k.current;A&&(A.style.width=`${w}px`,A.style.minWidth=`${w}px`,A.style.maxWidth=`${w}px`,A.style.setProperty("--oc-left-sidebar-width",`${w}px`))},[]);if(l.useEffect(()=>{e&&d&&u(!1)},[e,d]),l.useEffect(()=>{d||(p.current=null,b.current=null)},[d]),e)return null;const h=Math.min(Xc,Math.max(Qc,c||Yc)),S=t?h:0,y=w=>{if(t){try{w.currentTarget.setPointerCapture(w.pointerId)}catch{}b.current=w.pointerId,u(!0),m.current=w.clientX,f.current=S,p.current=S,g(S),w.preventDefault()}},j=w=>{if(e||!d||b.current!==w.pointerId)return;const A=w.clientX-m.current,D=v(f.current+A);p.current!==D&&(p.current=D,g(D))},C=w=>{if(b.current!==w.pointerId||e)return;try{w.currentTarget.releasePointerCapture(w.pointerId)}catch{}const A=v(p.current??S);b.current=null,p.current=null,u(!1),a(A)},N=d?p.current??S:S;return s.jsxs("aside",{ref:k,className:xe("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:`${N}px`,minWidth:`${N}px`,maxWidth:`${N}px`,"--oc-left-sidebar-width":`${d?N: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||S===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:xe("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:y,onPointerMove:j,onPointerUp:C,onPointerCancel:C,role:"separator","aria-orientation":"vertical","aria-label":i("sidebar.resize.leftPanelAria")}),s.jsxs("div",{className:xe("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(us,{children:n})})]})]})},Rb=()=>{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},Jo=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function Ob(){const t=Jt(f=>f.activeProjectId?f.projects.find(p=>p.id===f.activeProjectId)??null:null),e=nt(f=>f.currentSessionId),n=_h(e??null),r=nt(f=>e?f.worktreeMetadata.get(e)?.path??"":""),o=nt(f=>f.newSessionDraft?.open?Jo(f.newSessionDraft.bootstrapPendingDirectory??f.newSessionDraft.directoryOverride??""):""),i=l.useMemo(()=>Jo(r||""),[r]),c=l.useMemo(()=>{const f=typeof n?.directory=="string"?n.directory:"";return Jo(f||"")},[n?.directory]),a=i||c||o,d=l.useMemo(()=>Jo(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 Jc="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",Fb=()=>{const t=it.c(35),{t:e}=gt(),n=he(Bb),r=he(Lb),o=Ob(),i=l.useRef(null),c=Yi(Ir("toggle_sidebar",r)),{usesFramelessChrome:a,side:d}=pf(),u=$b;let m,f;t[0]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{if(typeof document>"u")return;const _=i.current;if(!_)return;const L=()=>{const K=Math.max(_.getBoundingClientRect().width,_.scrollWidth);document.documentElement.style.setProperty("--oc-titlebar-controls-width",`${Math.round(K)}px`)};if(L(),typeof ResizeObserver>"u")return;const W=new ResizeObserver(L);return W.observe(_),()=>{W.disconnect()}},f=[],t[0]=m,t[1]=f):(m=t[0],f=t[1]),l.useEffect(m,f);const p="app-region-no-drag absolute left-0 top-0 z-30 flex select-none items-center pr-2";let b;t[2]===Symbol.for("react.memo_cache_sentinel")?(b={height:"var(--oc-header-height, 3rem)",paddingLeft:"var(--oc-titlebar-left-inset, 0.75rem)"},t[2]=b):b=t[2];const k="flex items-center gap-2";let v;t[3]!==a||t[4]!==d?(v=a&&d==="left"?s.jsx(gf,{visible:!0,position:"left"}):null,t[3]=a,t[4]=d,t[5]=v):v=t[5];let g;t[6]!==e||t[7]!==a?(g=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:xe(Jc,"shrink-0"),children:s.jsx(I,{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]=g):g=t[8];const h=ft;let S;t[9]!==e?(S=e("header.actions.openSessionsAria"),t[9]=e,t[10]=S):S=t[10];let y,j;t[11]===Symbol.for("react.memo_cache_sentinel")?(y=xe(Jc,"shrink-0"),j=s.jsx(I,{name:"layout-left",className:"h-[18px] w-[18px]"}),t[11]=y,t[12]=j):(y=t[11],j=t[12]);let C;t[13]!==S||t[14]!==n?(C=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":S,className:y,children:j})}),t[13]=S,t[14]=n,t[15]=C):C=t[15];const N=ht,w=e("header.actions.openSessionsWithShortcut",{shortcut:c});let A;t[16]!==w?(A=s.jsx("p",{children:w}),t[16]=w,t[17]=A):A=t[17];let D;t[18]!==N||t[19]!==A?(D=s.jsx(N,{children:A}),t[18]=N,t[19]=A,t[20]=D):D=t[20];let P;t[21]!==h||t[22]!==C||t[23]!==D?(P=s.jsxs(h,{children:[C,D]}),t[21]=h,t[22]=C,t[23]=D,t[24]=P):P=t[24];let B;t[25]!==o?(B=o?s.jsx(kf,{projectRef:o.projectRef,directory:o.directory}):null,t[25]=o,t[26]=B):B=t[26];let F;t[27]!==P||t[28]!==B||t[29]!==v||t[30]!==g?(F=s.jsxs("div",{ref:i,className:k,children:[v,g,P,B]}),t[27]=P,t[28]=B,t[29]=v,t[30]=g,t[31]=F):F=t[31];let E;return t[32]!==F||t[33]!==b?(E=s.jsx("div",{className:p,style:b,children:F}),t[32]=F,t[33]=b,t[34]=E):E=t[34],E};function Bb(t){return t.toggleSidebar}function Lb(t){return t.shortcutOverrides}function _b(t){console.warn("[titlebar] failed to open app menu",t)}function $b(t){const e=t.currentTarget.getBoundingClientRect();hr("desktop_show_app_menu",{x:e.left,y:e.bottom}).catch(_b)}const Zc=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function zb(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([$h(t),zh(t)]).catch(Ub);if(d)return;const f=Zc(u),p=Zc(m);if(!f||!p||p===f)return;const b=n||"",k=p.split("/").filter(Boolean).pop()||p;i({source:"sdk",path:p,projectDirectory:f,branch:b,label:b||k,name:k,worktreeRoot:p,worktreeStatus:"ready",headState:b?"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 Ub(){return["",""]}class sa 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 na="/api/walkthrough",Mf=t=>/^application\/(?:[\w.+-]+\+)?json\b/i.test(t.headers.get("content-type")??""),Rf=()=>new sa("This OpenChamber server has no walkthrough API",{code:"server-unsupported"}),Wb=t=>!Mf(t)&&(t.ok||t.status===404),Bl=async(t,e)=>{if(Wb(t))throw Rf();const n=await t.json().catch(()=>null);throw new sa(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})},Of=async t=>{if(!Mf(t))throw Rf();try{return await t.json()}catch{throw new sa("The server returned a malformed walkthrough response")}};async function Vb(t,e,n={}){const r=await bs(na,{query:{directory:t,source:JSON.stringify(e),...n.model?{model:n.model}:{},...n.language?{language:n.language}:{}},signal:n.signal});return r.ok?Of(r):Bl(r,"Failed to load walkthrough")}async function Hb(t,e,n={}){const r=await bs(`${na}/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?Of(r):Bl(r,"Failed to generate walkthrough")}async function Kb(t,e){const n=await bs(`${na}/cancel`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:t,source:e})});n.ok||await Bl(n,"Failed to cancel walkthrough generation")}async function Gb(t,e,n){const r=await bs(`${na}/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 bo={status:"idle",stage:null,result:null,readiness:null,error:null},qb=t=>t.kind==="working-tree"?`working-tree:${t.scope}`:t.kind==="branch"?`branch:${t.baseRef}...${t.headRef}`:`pr:${t.number}`,dr=(t,e)=>`${Ms()}\0${t}\0${qb(e)}`,ed=t=>t instanceof sa?{message:t.message,code:t.code,model:t.model,requiredChars:t.requiredChars,availableChars:t.availableChars}:{message:t instanceof Error?t.message:"Something went wrong"},Sn=new Map,yo=new Map,Yb=1e3,Qb=Lr()(xf((t,e)=>({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{},selectLanguage:(n,r,o)=>{const i=dr(n,r);t(c=>{const a={...c.selectedLanguage};return o?a[i]=o:delete a[i],{selectedLanguage:a}})},getSelectedLanguage:(n,r)=>e().selectedLanguage[dr(n,r)],selectModel:(n,r,o)=>{const i=dr(n,r);t(c=>{const a={...c.selectedModel};return o?a[i]=o:delete a[i],{selectedModel:a}})},getSelectedModel:(n,r)=>e().selectedModel[dr(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[dr(n,r)]??bo,load:async(n,r,o={})=>{if(!n)return;const i=dr(n,r);if(e().entries[i]?.status==="generating")return;Sn.get(i)?.abort();const a=new AbortController;Sn.set(i,a),t(d=>({entries:{...d.entries,[i]:{...d.entries[i]??bo,status:"loading",error:null}}}));try{const d=await Vb(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]??bo,status:"error",stage:null,error:ed(d)}}}))}finally{Sn.get(i)===a&&Sn.delete(i)}},generate:async(n,r,o={})=>{if(!n)return;const i=dr(n,r);Sn.get(i)?.abort();const c=new AbortController;Sn.set(i,c),t(d=>({entries:{...d.entries,[i]:{...d.entries[i]??bo,status:"generating",stage:"collecting",error:null}}}));const a=()=>{const d=yo.get(i);d!==void 0&&(clearInterval(d),yo.delete(i))};a(),yo.set(i,setInterval(()=>{Gb(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(()=>{})},Yb));try{const d=await Hb(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]??bo,status:"error",stage:null,error:ed(d)}}}))}finally{a(),Sn.get(i)===c&&Sn.delete(i)}},cancel:(n,r)=>{const o=dr(n,r);Kb(n,r).catch(()=>{}),Sn.get(o)?.abort(),Sn.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 Sn.values())n.abort();Sn.clear();for(const n of yo.values())clearInterval(n);yo.clear(),t({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{}})}}),{name:"walkthrough-store"})),Xb="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)]",Jb=3e4,td=20,Ff=(t,e)=>JSON.stringify([Ms(),t,e]),Zb=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}},sd=()=>({result:null,hasCheckDetails:!1,fetchedAt:0,isLoading:!1,error:null}),Zo=new Map,ey=t=>{const e=Object.entries(t);return e.length<=td?t:Object.fromEntries(e.sort(([,n],[,r])=>r.fetchedAt-n.fetchedAt).slice(0,td))},nd=Lr()((t,e)=>({entries:{},ensure:async(n,r,o,i)=>{const c=Ff(r,o),a=i?.includeCheckDetails??!1,d=e().entries[c],u=d&&d.result&&Date.now()-d.fetchedAt<Jb&&(d.hasCheckDetails||!a);if(!i?.force&&u)return d.result;const m=`${c}::${a?"details":"plain"}`,p=Zo.get(`${c}::details`)??(a?null:Zo.get(m));if(p&&!i?.force)return p;const b=(async()=>{t(k=>({entries:{...k.entries,[c]:{...k.entries[c]??sd(),isLoading:!0,error:null}}}));try{const k=await n.prContext(r,o,{includeDiff:!1,includeCheckDetails:a,sourceRepo:i?.sourceRepo??null});return t(v=>({entries:ey({...v.entries,[c]:{result:k,hasCheckDetails:a,fetchedAt:Date.now(),isLoading:!1,error:null}})})),k}catch(k){const v=k instanceof Error?k.message:"Failed to load pull request context";return t(g=>({entries:{...g.entries,[c]:{...g.entries[c]??sd(),isLoading:!1,error:v}}})),null}finally{Zo.delete(m)}})();return Zo.set(m,b),b},invalidate:(n,r)=>{t(o=>{const i={};for(const[c,a]of Object.entries(o.entries)){const d=Zb(c);d&&d.directory===n&&(r==null||d.number===r)||(i[c]=a)}return{entries:i}})}})),ty=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}:{}}},sy=35e3,Na=(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`},Aa=t=>{const e=typeof t=="string"?t.toLowerCase():"";return!!e&&!["success","neutral","skipped"].includes(e)},rd=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"}},ny=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"},ry=[2e3,5e3],od=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),fr=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):""},oy=(t,e)=>{const n=fr(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},iy=(t,e)=>`${t}::${e}`,Ll=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},Da=(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=Ll(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)},ay=t=>t.startsWith("pr-"),ly=(t,e)=>{const n=Ll(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=>!ay(c.name)).forEach(c=>i(c)),t.forEach(c=>i(c)),o},vo=new Map,ei=Gi;function cy(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 dy=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:o=[],remoteBranches:i=[],onGeneratedDescription:c})=>{const{t:a}=gt(),d=he(G=>G.timeFormatPreference),{github:u}=nr(),m=Fr(G=>G.status),f=Fr(G=>G.hasChecked),p=he(G=>G.setSettingsDialogOpen),b=he(G=>G.setSettingsPage),k=he(G=>G.setActiveMainTab),v=nt(G=>G.currentSessionId),g=nt(G=>!!G.newSessionDraft?.open),{isMobile:h,hasTouchInput:S,screenWidth:y}=br(),j=he(G=>G.openContextSurface),C=Qb(G=>G.requestSource),N=!h&&y>=768&&!sr(),w=l.useCallback(()=>{b("github"),p(!0)},[p,b]),A=l.useMemo(()=>iy(t,e),[t,e]),D=l.useMemo(()=>vo.get(A)??null,[A]),P=on(G=>G.ensureEntry),B=on(G=>G.setParams),F=on(G=>G.startWatching),E=on(G=>G.stopWatching),_=on(G=>G.refresh),L=on(G=>G.updateStatus),[W,K]=l.useState(()=>D?.title??od(e)),[x,M]=l.useState(()=>D?.body??""),[z,U]=l.useState(()=>D?.draft??!1),[V,Z]=l.useState(()=>D?.additionalContext??""),[X,le]=l.useState(()=>{const G=typeof D?.targetBaseBranch=="string"?fr(D.targetBaseBranch):"";return G||fr(n)}),[te,fe]=l.useState("squash"),[ge,H]=l.useState(!1),[Se,ae]=l.useState(!1),[q,me]=l.useState(!1),[pe,Ie]=l.useState(!1),[Oe,Me]=l.useState(!1),[Fe,je]=l.useState(!1),[Ne,Pe]=l.useState(null),[se,oe]=l.useState(""),[Ee,J]=l.useState(""),[re,ee]=l.useState(!1),[$,de]=l.useState(!1),[Y,ue]=l.useState(()=>Da(o,{selectedRemoteName:D?.selectedRemoteName,trackingBranch:r})),[Te,Ge]=l.useState(!1),{detectedUpstream:_e,upstreamBranches:ie}=cy(t,u);l.useEffect(()=>{Ge(!1)},[t]);const Re=o.some(G=>G.name==="upstream"),T=!!(t&&e&&n&&(e!==n||(Re||_e!==null))),ce=l.useMemo(()=>Qi(t,e,Y?.name??null),[t,e,Y?.name]),ve=on(G=>G.entries[ce]),Ce=ve?.isLoading??!1,Ae=ve?.status??null,ne=ve?.error??null,ke=ve?.isInitialStatusResolved??!1,Ze=l.useMemo(()=>{const G=Te?null:Y?.name?.trim()||null,Ye=new Set;for(const _t of i){const Et=oy(_t,G);!Et||Et==="HEAD"||Ye.add(Et)}if(Te)for(const _t of ie)_t&&_t!=="HEAD"&&Ye.add(_t);const at=fr(n);at&&at!=="HEAD"&&Ye.add(at);const ut=fr(X);return ut&&ut!=="HEAD"&&Ye.add(ut),Array.from(Ye).sort((_t,Et)=>_t.localeCompare(Et))},[n,i,Y?.name,X,ie,Te]);l.useEffect(()=>{if(o.length===0){Y&&ue(null);return}(!Y||!o.some(G=>G.name===Y.name))&&ue(Da(o,{selectedRemoteName:D?.selectedRemoteName,trackingBranch:r}))},[D?.selectedRemoteName,o,Y,r]),l.useEffect(()=>{const G=fr(n);if(!X&&G){le(G);return}if(Ze.length!==0&&!Ze.includes(X)){const Ye=Ze.includes(G)?G:Ze[0];Ye&&le(Ye)}},[Ze,n,X]);const[Q,ye]=l.useState(()=>D?.activeSegment??"overview"),[Qe,$e]=l.useState(new Set),[ze,Le]=l.useState(new Set),st=l.useRef(new Set),ct=l.useRef(null),Pt=l.useRef(!1),It=l.useRef(new Set),Tt=l.useRef([]);l.useEffect(()=>{_e&&!Re&&Ge(!0)},[_e,Re]),l.useEffect(()=>{Te&&_e?.defaultBranch&&le(_e.defaultBranch)},[Te,_e?.defaultBranch]);const et=Ae?.pr??null,Mt=et?.state==="merged"||et?.state==="closed",kt=Mt?null:et,bt=kt?Ff(t,kt.number):null,Bt=nd(G=>bt?G.entries[bt]:void 0),wt=nd(G=>G.ensure),Rt=Bt?.result??null,pt=Bt?.isLoading??!1,yt=l.useCallback(G=>{ye(G);const Ye=vo.get(A);Ye&&vo.set(A,{...Ye,activeSegment:G})},[A]);l.useEffect(()=>{!kt||!u?.prContext||Q==="overview"||wt(u,t,kt.number,{includeCheckDetails:Q==="checks",sourceRepo:Ae?.repo??null})},[Q,t,wt,u,kt,Ae?.repo]);const Ke=Ae?.checks??null,Ue=(Ke?.pending??0)>0,xt=Rt?.checkRuns??null,Ft=Rt?.fetchedAt;l.useEffect(()=>{if(!xt||xt.length===0)return;const G=ty(xt);L(ce,Ye=>{if(!Ye?.pr||typeof Ft=="number"&&typeof Ye.fetchedAt=="number"&&Ft<Ye.fetchedAt)return Ye;const at=Ye.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?Ye:{...Ye,checks:G,...typeof Ft=="number"?{fetchedAt:Ft}:{}}})},[xt,Ft,ce,L]),l.useEffect(()=>{if(Q!=="checks"||!Ue||!et||!u?.prContext)return;const G=window.setInterval(()=>{wt(u,t,et.number,{includeCheckDetails:!0,sourceRepo:Ae?.repo??null,force:!0})},sy);return()=>window.clearInterval(G)},[Q,Ue,t,wt,u,et,Ae?.repo]);const[$t,ns]=l.useState(()=>Date.now());l.useEffect(()=>{if(!Ue)return;ns(Date.now());const G=window.setInterval(()=>ns(Date.now()),3e4);return()=>window.clearInterval(G)},[Ue]);const Kt=et?`${t}#${et.number}`:null,St=!!(Kt&&Ne===Kt);l.useEffect(()=>{if(!u?.prContext||!et||typeof et.body=="string"&&et.body.length>0)return;const G=`${t}#${et.number}`;if(st.current.has(G))return;st.current.add(G),Pe(G);let Ye=!1;return wt(u,t,et.number,{sourceRepo:Ae?.repo??null}).then(at=>{if(Ye)return;const ut=at?.pr;ut&&L(ce,_t=>!_t?.pr||_t.pr.number!==et.number?_t:{..._t,pr:{..._t.pr,body:ut.body||""}})}).catch(()=>{}).finally(()=>{Ye||Pe(at=>at===G?null:at)}),()=>{Ye=!0}},[t,wt,u,et,ce,Ae?.repo,L]),l.useEffect(()=>{if(!et){je(!1),oe(""),J(""),ct.current=null;return}const G=ct.current!==null&&ct.current!==et.number;G&&je(!1),(!Fe||G)&&(oe(et.title||""),J(et.body||"")),ct.current=et.number},[Fe,et]);const zt=l.useCallback(G=>{if(!G)return"";const Ye=Date.parse(G);return Number.isFinite(Ye)?Ru(Ye,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]),ts=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)]",[]),ys=l.useCallback(G=>{const Ye=ms.toLowerCase(),at=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return G.replace(at,(ut,_t,Et)=>{const vt=`@${Et}`,fs=Et.toLowerCase();return`${_t}[${vt}](https://github.com/${fs}${Ye&&fs===Ye?"?oc-self-mention=1":""})`})},[ms]),Vt=l.useMemo(()=>{const G=(Rt?.issueComments??[]).map(ut=>({id:`issue-${ut.id}`,body:ut.body||"",authorName:ut.author?.name||ut.author?.login||a("gitView.pr.comments.unknownAuthor"),authorLogin:ut.author?.login||null,avatarUrl:ut.author?.avatarUrl||null,createdAt:ut.createdAt,context:a("gitView.pr.comments.generalContext"),path:null,line:null})),Ye=(Rt?.reviewComments??[]).map(ut=>({id:`review-${ut.id}`,body:ut.body||"",authorName:ut.author?.name||ut.author?.login||a("gitView.pr.comments.unknownAuthor"),authorLogin:ut.author?.login||null,avatarUrl:ut.author?.avatarUrl||null,createdAt:ut.createdAt,context:a("gitView.pr.comments.reviewContext"),path:ut.path||null,line:ut.line??null})),at=[...G,...Ye];return at.sort((ut,_t)=>{const Et=ut.createdAt?Date.parse(ut.createdAt):0,vt=_t.createdAt?Date.parse(_t.createdAt):0,fs=Number.isFinite(Et)?Et:0,ks=Number.isFinite(vt)?vt:0;return fs-ks}),at},[Rt,a]),Gt=l.useCallback(()=>{const G=v??(g?"draft":null);return G?{directory:t,sessionKey:G}:(De.error(a("gitView.pr.toast.noActiveSession"),{description:a("gitView.pr.toast.noActiveSessionDescription")}),null)},[v,t,g,a]),Ut=l.useCallback((G,Ye)=>{const at=Ye.authorLogin?`@${Ye.authorLogin}`:Ye.authorName,ut=Ye.path?` · ${Ye.path}${Ye.line?`:${Ye.line}`:""}`:"";Ka.getState().addDraft(G,{source:"pr-comment",fileLabel:`PR #${et?.number??""} ${at}${ut}`,startLine:Ye.line??0,endLine:Ye.line??0,code:Ye.body,language:"markdown",text:""})},[et?.number]),Be=l.useCallback((G,Ye)=>{const at=G.status||"unknown",ut=G.conclusion??void 0,_t=ut?`${at} / ${ut}`:at,Et=G.app?.name||G.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:Ye?.hideHeader?"flex items-start justify-end gap-3":"flex items-start justify-between gap-3",children:[Ye?.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:Et?`${Et} · ${_t}`:_t})]}),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(I,{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((vt,fs)=>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:[vt.title||vt.level||"Issue",vt.path?` · ${vt.path}`:"",typeof vt.startLine=="number"?`:${vt.startLine}`:"",typeof vt.endLine=="number"&&vt.endLine!==vt.startLine?`-${vt.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap break-words mt-1",children:vt.message}),vt.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:vt.rawDetails}):null]},`${vt.path||"file"}:${vt.startLine||fs}:${fs}`))})]}):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((vt,fs)=>{const ks=(vt.conclusion||"").toLowerCase(),Qt=ks&&!["success","neutral","skipped"].includes(ks),Bs=`${G.id??"run"}:${G.job?.jobId??"job"}:${vt.number??fs}:${vt.name}`,Hs=Qe.has(Bs);return Qt?s.jsxs(Ti,{open:Hs,children:[s.jsxs("button",{type:"button",onClick:()=>{$e(or=>{const Dn=new Set(or);return Dn.has(Bs)?Dn.delete(Bs):Dn.add(Bs),Dn})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(Qt?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[Hs?s.jsx(I,{name:"arrow-down-s",className:"size-4"}):s.jsx(I,{name:"arrow-right-s",className:"size-4"}),s.jsx("span",{className:"truncate",children:vt.name}),vt.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:vt.conclusion}):null]}),s.jsx(Ii,{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 vt.number=="number"?s.jsxs("div",{children:[a("gitView.pr.checks.stepLabel"),": ",vt.number]}):null,vt.status?s.jsxs("div",{children:[a("gitView.pr.checks.statusLabel"),": ",vt.status]}):null,vt.conclusion?s.jsxs("div",{children:[a("gitView.pr.checks.conclusionLabel"),": ",vt.conclusion]}):null,vt.startedAt?s.jsxs("div",{children:[a("gitView.pr.checks.startedLabel"),": ",zt(vt.startedAt)]}):null,vt.completedAt?s.jsxs("div",{children:[a("gitView.pr.checks.completedLabel"),": ",zt(vt.completedAt)]}):null]})})]},Bs):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:vt.name}),vt.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:vt.conclusion}):null]},Bs)})})]}):null]})},[Qe,zt,a]),[Xe,Je]=l.useState(!1),[He,rt]=l.useState(!1),Dt=l.useCallback(async()=>{if(!u?.prContext){De.error(a("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!et)return;const G=Gt();if(G){Je(!0);try{const Ye=await wt(u,t,et.number,{includeCheckDetails:!0,sourceRepo:Ae?.repo??null});if(!Ye){De.error(a("gitView.pr.toast.loadChecksFailed"));return}const ut=(Ye.checkRuns??[]).filter(Et=>Aa(Et.conclusion));if(ut.length===0){De.message(a("gitView.pr.toast.noFailedChecks"));return}const _t=Ka.getState();for(const Et of ut){const vt=(Et.annotations??[]).map(Qt=>[[Qt.level,Qt.title].filter(Boolean).join(" "),Qt.path?`${Qt.path}${typeof Qt.startLine=="number"?`:${Qt.startLine}`:""}`:null,Qt.message,Qt.rawDetails].filter(Boolean).join(`
38
+ `)),fs=(Et.job?.steps??[]).filter(Qt=>Aa(Qt.conclusion)).map(Qt=>`step ${Qt.number??"?"}: ${Qt.name} → ${Qt.conclusion}`),ks=[`check: ${Et.job?.workflowName?`${Et.job.workflowName} / ${Et.name}`:Et.name}`,`status: ${Et.status??"unknown"} / ${Et.conclusion??"unknown"}`,Et.detailsUrl?`url: ${Et.detailsUrl}`:null,Et.output?.title?`title: ${Et.output.title}`:null,Et.output?.summary?`summary:
39
+ ${Et.output.summary}`:null,fs.length>0?`failed steps:
40
+ ${fs.join(`
41
+ `)}`:null,vt.length>0?`annotations:
42
+ ${vt.join(`
43
+ ---
44
+ `)}`:null].filter(Boolean).join(`
45
+
46
+ `);_t.addDraft(G,{source:"pr-check",fileLabel:`PR #${et.number} · ${Et.name}`,startLine:0,endLine:0,code:ks,language:"text",text:""})}k("chat")}catch(Ye){const at=Ye instanceof Error?Ye.message:String(Ye);De.error(a("gitView.pr.toast.loadChecksFailed"),{description:at})}finally{Je(!1)}}},[t,wt,u,et,Gt,k,Ae?.repo,a]),Wt=l.useCallback(async()=>{if(!u?.prContext){De.error(a("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!et)return;const G=Gt();if(G){rt(!0);try{if(!await wt(u,t,et.number,{sourceRepo:Ae?.repo??null})){De.error(a("gitView.pr.toast.loadPrCommentsFailed"));return}if(Vt.length===0){De.message(a("gitView.pr.toast.noPrComments"));return}for(const at of Vt)Ut(G,at);k("chat")}catch(Ye){const at=Ye instanceof Error?Ye.message:String(Ye);De.error(a("gitView.pr.toast.loadPrCommentsFailed"),{description:at})}finally{rt(!1)}}},[Ut,t,wt,u,et,Gt,k,Ae?.repo,a,Vt]),rs=l.useCallback(async G=>{const Ye=Gt();Ye&&(Ut(Ye,G),k("chat"))},[Ut,Gt,k]),Lt=l.useCallback(async G=>{await _(ce,G)},[ce,_]),os=l.useCallback(()=>{Tt.current.forEach(G=>{window.clearTimeout(G)}),Tt.current=ry.map(G=>window.setTimeout(()=>{Lt({force:!0,silent:!0,markInitialResolved:!0})},G))},[Lt]);l.useEffect(()=>{if(!u?.prStatus||!T||o.length<=1||Pt.current||Ae?.pr)return;const G=`${A}::${Y?.name??""}`;if(It.current.has(G))return;It.current.add(G);const Ye=ly(o,r).filter(_t=>_t.name!==Y?.name);if(Ye.length===0)return;let at=!1;return(async()=>{for(const _t of Ye){if(at)return;try{if(!(await u.prStatus(t,e,_t.name))?.pr)continue;if(at)return;ue(vt=>vt?.name===_t.name?vt:_t);return}catch{}}})(),()=>{at=!0}},[e,T,t,u,o,Y?.name,A,Ae?.pr,r]),l.useEffect(()=>{P(ce),B(ce,{directory:t,branch:e,remoteName:Y?.name??null,canShow:T,github:u,githubAuthChecked:f,githubConnected:m?.connected??null})},[e,T,t,P,u,f,m?.connected,ce,Y?.name,B]),l.useEffect(()=>(F(ce),()=>{E(ce)}),[ce,F,E]),l.useEffect(()=>{const G=vo.get(A)??null;K(G?.title??od(e)),M(G?.body??""),U(G?.draft??!1),le(G?.targetBaseBranch?fr(G.targetBaseBranch):fr(n));const Ye=Da(o,{selectedRemoteName:G?.selectedRemoteName,trackingBranch:r});ue(at=>at?.name===Ye?.name?at:Ye)},[n,e,o,A,r]),l.useEffect(()=>{Lt({markInitialResolved:!0})},[ce,Lt]),l.useEffect(()=>{!T||!Y?.name||Lt({force:!0,silent:!0,markInitialResolved:!0})},[T,Lt,Y?.name]),l.useEffect(()=>{const G=Ae?.resolvedRemoteName?.trim();if(!G||Pt.current)return;const Ye=o.find(at=>at.name===G);Ye&&ue(at=>at?.name===Ye.name?at:Ye)},[o,Ae?.resolvedRemoteName]),l.useEffect(()=>{const G=()=>{const at=on.getState().entries[ce]?.lastRefreshAt??0;Date.now()-at>6e4&&Lt({force:!0,silent:!0})},Ye=()=>{document.visibilityState==="visible"&&G()};return window.addEventListener("focus",G),document.addEventListener("visibilitychange",Ye),()=>{window.removeEventListener("focus",G),document.removeEventListener("visibilitychange",Ye)}},[ce,Lt]),l.useEffect(()=>{f&&m?.connected===!1&&Lt({force:!0,silent:!0,markInitialResolved:!0})},[f,m,Lt]),l.useEffect(()=>{!t||!e||vo.set(A,{title:W,body:x,draft:z,additionalContext:V,targetBaseBranch:X,selectedRemoteName:Y?.name,activeSegment:Q})},[A,W,x,z,V,X,Y?.name,t,e,Q]),l.useEffect(()=>{const G=Tt.current;return()=>{G.forEach(Ye=>{window.clearTimeout(Ye)}),Tt.current=[]}},[]);const es=l.useCallback(async()=>{if(!ge&&t){H(!0);try{const Ye={base:Te&&_e?.defaultBranchSha?_e.defaultBranchSha:X,head:e};V&&(Ye.context=V);const at=await Uh(t,Ye);at.title?.trim()&&K(at.title.trim()),at.body?.trim()&&M(at.body.trim()),c?.()}catch(G){const Ye=G instanceof Error?G.message:String(G);De.error(a("gitView.pr.toast.generateDescriptionFailed"),{description:Ye})}finally{H(!1)}}},[V,e,_e?.defaultBranchSha,t,ge,c,X,a,Te]),Us=l.useCallback(async()=>{if(!u?.prCreate){De.error(a("gitView.pr.toast.githubApiUnavailable"));return}const G=W.trim();if(!G){De.error(a("gitView.pr.toast.titleRequired"));return}const Ye=X.trim();if(!Ye){De.error(a("gitView.pr.toast.baseBranchRequired"));return}if(!Te&&Ye===e){De.error(a("gitView.pr.toast.baseMustDifferFromHead"));return}ae(!0);try{const at=Ll(r),ut=Te&&_e,_t=await u.prCreate({directory:t,title:G,head:e,base:Ye,...x.trim()?{body:x}:{},draft:z,...ut?{targetRepo:{owner:_e.owner,repo:_e.repo},headRemote:"origin"}:{...Y?{remote:Y.name}:{},...at&&at!==Y?.name?{headRemote:at}:{}}});De.success(a("gitView.pr.toast.prCreated")),L(ce,Et=>Et&&{...Et,pr:_t}),await Lt({force:!0}),os()}catch(at){const ut=at instanceof Error?at.message:String(at);De.error(a("gitView.pr.toast.createPrFailed"),{description:ut})}finally{ae(!1)}},[x,e,_e,t,z,u,ce,Lt,os,Y,X,W,r,L,Te,a]),Ws=l.useCallback(async G=>{if(!u?.prMerge){De.error(a("gitView.pr.toast.githubApiUnavailable"));return}Ie(!0);try{const Ye=await u.prMerge({directory:t,number:G.number,method:te});Ye.merged?De.success(a("gitView.pr.toast.prMerged")):De.message(a("gitView.pr.toast.prNotMerged"),{description:Ye.message||a("gitView.pr.notMergeable")}),await Lt({force:!0}),os()}catch(Ye){const at=Ye instanceof Error?Ye.message:String(Ye);De.error(a("gitView.pr.toast.mergeFailed"),{description:at}),G.url&&ei(G.url)}finally{Ie(!1)}},[t,u,te,Lt,os,a]),Hn=l.useCallback(async G=>{if(!u?.prReady){De.error(a("gitView.pr.toast.githubApiUnavailable"));return}Me(!0);try{await u.prReady({directory:t,number:G.number}),De.success(a("gitView.pr.toast.markedReady")),await Lt({force:!0}),os()}catch(Ye){const at=Ye instanceof Error?Ye.message:String(Ye);De.error(a("gitView.pr.toast.markReadyFailed"),{description:at}),G.url&&ei(G.url)}finally{Me(!1)}},[t,u,Lt,os,a]),gn=l.useCallback(async G=>{if(!u?.prUpdate){De.error(a("gitView.pr.toast.githubApiUnavailable"));return}const Ye=se.trim();if(!Ye){De.error(a("gitView.pr.toast.titleRequired"));return}me(!0);try{const at=await u.prUpdate({directory:t,number:G.number,title:Ye,body:Ee});L(ce,ut=>ut&&{...ut,pr:{...ut.pr??G,...at}}),je(!1),De.success(a("gitView.pr.toast.prUpdated")),await Lt({force:!0}),os()}catch(at){const ut=at instanceof Error?at.message:String(at);De.error(a("gitView.pr.toast.updatePrFailed"),{description:ut})}finally{me(!1)}},[t,Ee,se,u,ce,Lt,os,L,a]);if(!T)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 In=Ae?.repo?.url||null,xn=Te&&_e?.url?_e.url:In,As=!!Ae?.canMerge,Kn=!!Ae?.connected,Os=f&&Ae?.connected===!1,Vs=ny(Ae),Fs=Vs?`var(--pr-${Vs})`:"var(--status-info)",rr=Vs==="draft"?"git-pr-draft":Vs==="merged"?"git-merge":Vs==="closed"?"git-close-pull-request":"git-pull-request",en=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(" · "):"",js=Ke?Ke.total>0?`${Ke.success}/${Ke.total} ${a("gitView.pr.checks.label")}`:`${Ke.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:()=>{ei(et.url)},"aria-label":a("gitView.pr.actions.openOnGitHubAria"),children:[s.jsx(I,{name:rr,className:"size-4 shrink-0",style:{color:Fs}}),a("gitView.pr.actions.openOnGitHub")]}):s.jsx(I,{name:rr,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(I,{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:()=>{Lt({force:!0})},"aria-label":a("gitView.pr.actions.refreshAria"),children:s.jsx(I,{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:Fs},children:en}),Ke?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${rd(Ke.state)}`}),js]}):null,r&&Y&&r.split("/")[0]!==Y.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",Y.name]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[N?s.jsxs(lt,{variant:"outline",size:"sm",className:xe("pr-actions__walkthrough-button h-7 shrink-0 gap-1.5 px-2",Xb),onClick:()=>{C(t,{kind:"pr",number:et.number}),j(t,"walkthrough")},"aria-label":a("walkthrough.action.open"),children:[s.jsx(I,{name:"route",className:"size-4"}),s.jsx("span",{className:"pr-actions__walkthrough-label typography-ui-label",children:a("walkthrough.action.open")})]}):null,As&&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:Oe||pe||q||Fe,"aria-label":a("gitView.pr.actions.markReadyAria"),children:Oe?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(ht,{children:s.jsx("p",{children:a("gitView.pr.actions.markReady")})})]}):null,As?s.jsxs(s.Fragment,{children:[s.jsxs(Ys,{value:te,onValueChange:G=>fe(G),disabled:pe||et.state!=="open",children:[s.jsx(Qs,{size:"sm",className:"h-7 w-auto min-w-0",children:s.jsx(Rs,{})}),s.jsxs(Xs,{children:[s.jsx(ls,{value:"squash",children:a("gitView.pr.mergeMethod.squash")}),s.jsx(ls,{value:"merge",children:a("gitView.pr.mergeMethod.merge")}),s.jsx(ls,{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:()=>Ws(et),disabled:pe||Oe||et.state!=="open"||et.draft||q||Fe,"aria-label":a("gitView.pr.actions.mergePrAria"),children:pe?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{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:[Os?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:w,className:"w-fit",children:a("gitView.pr.actions.openSettings")})]}):null,ne?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:ne}),xn?s.jsx(lt,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:xn,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!et&&!ke&&!ne&&!Os?s.jsxs("div",{className:"flex items-center gap-2 typography-micro text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),a("gitView.pr.checkingStatus")]}):et&&!Mt?s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("div",{className:"h-8 min-w-0",children:s.jsx(Il,{className:"h-full",items:[{id:"overview",label:a("gitView.pr.segment.overview")},{id:"checks",label:Ke&&Ke.total>0?`${a("gitView.pr.segment.checks")} ${Ke.success}/${Ke.total}`:a("gitView.pr.segment.checks"),icon:Ke?s.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${rd(Ke.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:Q,onSelect:G=>yt(G),layoutMode:"fit",variant:"active-pill",activePillButtonClassName:"h-7"})}),Q==="overview"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[As&&et.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:a("gitView.pr.draftMustBeReady")}):null,As?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:Fe?s.jsx(er,{value:se,onChange:G=>oe(G.target.value),placeholder:a("gitView.pr.placeholder.title"),autoCorrect:S?"on":"off",autoCapitalize:S?"sentences":"off",spellCheck:S}):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:Fe?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:()=>{je(!1),oe(et.title||""),J(et.body||"")},disabled:q,"aria-label":a("gitView.pr.actions.cancelEditingAria"),children:s.jsx(I,{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:()=>gn(et),disabled:q||!se.trim(),"aria-label":a("gitView.pr.actions.savePrAria"),children:q?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{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:()=>je(!0),"aria-label":a("gitView.pr.actions.editPrAria"),children:s.jsx(I,{name:"edit",className:"size-4"})})}),s.jsx(ht,{children:s.jsx("p",{children:a("gitView.pr.actions.editPr")})})]})}):null]}),Fe?s.jsx(Xr,{value:Ee,onChange:G=>J(G.target.value),outerClassName:"min-h-[60vh]",placeholder:a("gitView.pr.placeholder.description"),autoCorrect:S?"on":"off",autoCapitalize:S?"sentences":"off",spellCheck:S}):null,Fe?null:et.body?.trim()?s.jsx(gc,{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(St?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}):null,Q==="checks"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[Ke&&Ke.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:[Ke.success>0?s.jsx("div",{className:"bg-[color:var(--status-success)]",style:{width:`${Ke.success/Ke.total*100}%`}}):null,Ke.failure>0?s.jsx("div",{className:"bg-[color:var(--status-error)]",style:{width:`${Ke.failure/Ke.total*100}%`}}):null,Ke.pending>0?s.jsx("div",{className:"bg-[color:var(--status-warning)]",style:{width:`${Ke.pending/Ke.total*100}%`}}):null]}),s.jsxs("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:[Ke.success,"/",Ke.total," ",a("gitView.pr.checks.label")]}),(Ke.inProgress??0)>0?s.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 typography-micro text-[var(--status-warning)]",children:[s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}),Na(Ke.startedAt,void 0,$t)]}):null]}):null,Ke?.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:Dt,disabled:Xe,"aria-label":a("gitView.pr.actions.resolveFailedChecksAria"),children:[Xe?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{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,Ye)=>{const at=`${G.id??"run"}:${G.name}:${Ye}`,ut=G.status==="in_progress",_t=G.status==="queued",Et=Aa(G.conclusion),vt=ze.has(at),fs=!!(G.output?.title||G.output?.summary||G.output?.text||(G.annotations?.length??0)>0||(G.job?.steps?.length??0)>0||G.detailsUrl),ks=G.job?.workflowName,Qt=ut?Na(G.startedAt,void 0,$t):Na(G.startedAt,G.completedAt);return s.jsxs("div",{className:xe("rounded-md border border-border/40",Et&&"border-[var(--status-error-border)]"),children:[s.jsxs("button",{type:"button",disabled:!fs,onClick:()=>{Le(Bs=>{const Hs=new Set(Bs);return Hs.has(at)?Hs.delete(at):Hs.add(at),Hs})},className:"flex w-full items-center gap-2 px-2.5 py-2 text-left disabled:cursor-default",children:[ut?s.jsx(I,{name:"loader-4",className:"size-4 shrink-0 animate-spin text-[var(--status-warning)]"}):_t?s.jsx(I,{name:"time",className:"size-4 shrink-0 text-muted-foreground"}):Et?s.jsx(I,{name:"close-circle",className:"size-4 shrink-0 text-[var(--status-error)]"}):s.jsx(I,{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:ks&&ks!==G.name?`${ks} / ${G.name}`:G.name}),Qt?s.jsx("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:Qt}):null,fs?s.jsx(I,{name:"arrow-down-s",className:xe("size-4 shrink-0 text-muted-foreground transition-transform",vt&&"rotate-180")}):null]}),vt&&fs?s.jsx("div",{className:"min-w-0 overflow-hidden border-t border-border/40 p-2.5",children:Be(G,{hideHeader:!0})}):null]},at)})}):pt?s.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 typography-micro text-muted-foreground",children:[s.jsx(I,{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,Q==="comments"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[Vt.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:He,"aria-label":a("gitView.pr.actions.shareCommentsAria"),children:[He?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"ai-generate-2",className:"size-3.5"}),a("gitView.pr.comments.addAll")]})}):null,Vt.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Vt.map((G,Ye)=>{const at=(G.authorName||"?").charAt(0).toUpperCase(),ut=Ye===Vt.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[ut?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:zt(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:()=>{rs(G)},"aria-label":a("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(I,{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(gc,{content:ys(G.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",ts].filter(Boolean).join(" "),enableFileReferences:!1})]})]},G.id)})})}):pt&&!Rt?s.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 typography-micro text-muted-foreground",children:[s.jsx(I,{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&&Mt?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(I,{name:et.state==="merged"?"git-merge":"git-close-pull-request",className:"size-4 shrink-0",style:{color:Fs}}),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||X}):a("gitView.pr.history.closed",{number:et.number})}),s.jsx(lt,{type:"button",variant:"ghost",size:"xs",className:"shrink-0",onClick:()=>{ei(et.url)},"aria-label":a("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(I,{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)"})," → ",X," ",s.jsxs("span",{className:"opacity-60",children:["(",Te&&_e?"upstream":"remote",")"]})]})]}),xn?s.jsx(lt,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:xn,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{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(er,{value:W,onChange:G=>K(G.target.value),placeholder:a("gitView.pr.placeholder.title"),autoCorrect:S?"on":"off",autoCapitalize:S?"sentences":"off",spellCheck:S})]}),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(Ys,{value:X,onValueChange:le,children:[s.jsx(Qs,{size:"lg",children:s.jsx(Rs,{placeholder:a("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(Xs,{children:Ze.map(G=>s.jsx(ls,{value:G,children:G},G))})]}):s.jsx(er,{value:X,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(Xr,{value:x,onChange:G=>M(G.target.value),className:"min-h-[110px]",placeholder:a("gitView.pr.placeholder.whatChanged"),autoCorrect:S?"on":"off",autoCapitalize:S?"sentences":"off",spellCheck:S})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":z,onClick:()=>U(G=>!G),onKeyDown:G=>{(G.key===" "||G.key==="Enter")&&(G.preventDefault(),U(Ye=>!Ye))},children:[s.jsx(Zr,{size:"sm",checked:z,onChange:G=>U(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:()=>de(!0),children:V.trim()?a("gitView.pr.actions.edit"):a("gitView.pr.actions.add")})]}),V.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(Ti,{open:re,onOpenChange:ee,children:[s.jsxs(Ml,{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"):V.trim()?a("gitView.pr.actions.edit"):a("gitView.pr.actions.add")})]}),s.jsx(Ii,{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(Xr,{value:V,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(Xi,{open:$,onClose:()=>de(!1),title:a("gitView.pr.additionalContext.title"),footer:s.jsx(lt,{size:"sm",onClick:()=>de(!1),className:"w-full",children:a("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(Xr,{value:V,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:es,disabled:ge||Se,children:[ge?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{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:Us,disabled:Se||!Kn||!X.trim()||!Te&&X.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:Se?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-pull-request",className:"size-4"})}),s.jsx("span",{children:a("gitView.pr.actions.createPr")})]})]})]})]})]})},uy=t=>{const{remoteNames:e,localBranches:n,worktreeCreatedFromBranch:r,rootBranchHint:o,defaultBranch:i,headBranch:c}=t,a=typeof c=="string"?c.trim():"",d=b=>{if(!b)return"";let k=b.trim();if(!k||k==="HEAD")return"";if(n.includes(k))return k;k.startsWith("refs/heads/")&&(k=k.slice(11)),k.startsWith("heads/")&&(k=k.slice(6)),k.startsWith("remotes/")&&(k=k.slice(8));const v=k.indexOf("/");if(v>0){const g=k.slice(0,v);if(e.has(g)){const h=k.slice(v+1).trim();h&&(k=h)}}return k},u=b=>{const k=d(typeof b=="string"?b:"");return k&&k!==a?k:""},m=u(r);if(m)return m;const f=u(o);if(f)return f;const p=u(i);return p||(n.includes("main")?"main":n.includes("master")?"master":n.includes("develop")?"develop":"main")},DN=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})},Pa=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),ti=new Map,si=new Map,ur=t=>`${Ms()}::${t}`,fy=()=>{const t=it.c(86),{t:e}=gt(),{git:n}=nr(),r=Lo(),o=Sl(r??null),i=Ou(r??null),{ensureAll:c}=gr(Xn(my)),a=nt(hy),d=nt(py),u=nt(gy),m=nt(xy);let f;t[0]!==r?(f=Pa(r),t[0]=r,t[1]=f):f=t[1];const p=f;let b;if(t[2]!==m||t[3]!==p||t[4]!==u){e:{if(!p){b=void 0;break e}let je;if(t[6]!==m||t[7]!==p){let Pe;t[9]!==p?(Pe=se=>Pa(se.path)===p,t[9]=p,t[10]=Pe):Pe=t[10],je=m.find(Pe),t[6]=m,t[7]=p,t[8]=je}else je=t[8];const Ne=je;if(Ne){b=Ne;break e}for(const Pe of u.values())if(Pa(Pe.path)===p){b=Pe;break e}b=void 0}t[2]=m,t[3]=p,t[4]=u,t[5]=b}else b=t[5];const k=b;let v;t[11]!==a||t[12]!==k||t[13]!==d?.open||t[14]!==u?(v=()=>{if(a)return u.get(a)??k;if(d?.open)return k},t[11]=a,t[12]=k,t[13]=d?.open,t[14]=u,t[15]=v):v=t[15],d?.open;let g;t[16]!==v?(g=v(),t[16]=v,t[17]=g):g=t[17];const h=g;let S;t[18]!==a?(S=je=>a?je.getAttachment(a):void 0,t[18]=a,t[19]=S):S=t[19];const y=Pu(S),j=y&&!y.degraded&&!y.legacy?y.worktreeRoot??void 0:void 0,C=zb(r,h,o?.current??void 0);let N,w;t[20]!==r||t[21]!==c||t[22]!==n?(N=()=>{!r||!n||c(r,n)},w=[r,c,n],t[20]=r,t[21]=c,t[22]=n,t[23]=N,t[24]=w):(N=t[23],w=t[24]),l.useEffect(N,w);const[A,D]=l.useState(null);let P;t[25]!==j||t[26]!==C?.projectDirectory?(P=()=>{const je=j||C?.projectDirectory;if(!je){D(null);return}let Ne=!1;return Ji(je).then(Pe=>{if(Ne)return;const se=Pe.trim();D(se&&se!=="HEAD"?se:null)}).catch(()=>{Ne||D(null)}),()=>{Ne=!0}},t[25]=j,t[26]=C?.projectDirectory,t[27]=P):P=t[27];const B=C?.projectDirectory;let F;t[28]!==j||t[29]!==B?(F=[j,B],t[28]=j,t[29]=B,t[30]=F):F=t[30],l.useEffect(P,F);let E;t[31]!==r?(E=()=>(r?ti.get(ur(r)):void 0)??[],t[31]=r,t[32]=E):E=t[32];const[_,L]=l.useState(E);let W;t[33]!==r?(W=()=>(r?si.get(ur(r)):void 0)??null,t[33]=r,t[34]=W):W=t[34];const[K,x]=l.useState(W);let M,z;t[35]!==r||t[36]!==n?(M=()=>{if(!r||!n?.getRemotes){L([]);return}L(ti.get(ur(r))??[]);let je=!1;return n.getRemotes(r).then(Ne=>{je||(ti.set(ur(r),Ne??[]),L(Ne??[]))}).catch(()=>{je||L(ti.get(ur(r))??[])}),()=>{je=!0}},z=[r,n],t[35]=r,t[36]=n,t[37]=M,t[38]=z):(M=t[37],z=t[38]),l.useEffect(M,z);let U,V;t[39]!==r||t[40]!==n?(U=()=>{if(!r||!n?.getRemoteUrl){x(null);return}x(si.get(ur(r))??null);let je=!1;return n.getRemoteUrl(r).then(Ne=>{je||(si.set(ur(r),Ne),x(Ne))}).catch(()=>{je||x(si.get(ur(r))??null)}),()=>{je=!0}},V=[r,n],t[39]=r,t[40]=n,t[41]=U,t[42]=V):(U=t[41],V=t[42]),l.useEffect(U,V);let Z;e:{if(!i?.all){let Ne;t[43]===Symbol.for("react.memo_cache_sentinel")?(Ne=[],t[43]=Ne):Ne=t[43],Z=Ne;break e}let je;t[44]!==i.all?(je=i.all.filter(by).sort(),t[44]=i.all,t[45]=je):je=t[45],Z=je}const X=Z;let le;e:{if(!i?.all){let Ne;t[46]===Symbol.for("react.memo_cache_sentinel")?(Ne=[],t[46]=Ne):Ne=t[46],le=Ne;break e}let je;t[47]!==i.all?(je=i.all.filter(yy).map(vy).sort(),t[47]=i.all,t[48]=je):je=t[48],le=je}const te=le;let fe;t[49]!==te||t[50]!==K||t[51]!==_||t[52]!==o?.tracking?(fe=()=>{if(_.length>0)return _;const je=new Set,Ne=o?.tracking?.trim();Ne&&Ne.includes("/")&&je.add(Ne.split("/")[0]);for(const Pe of te){const se=Pe.indexOf("/");se>0&&je.add(Pe.slice(0,se))}return je.size===0&&K&&je.add("origin"),Array.from(je).map(Pe=>({name:Pe,fetchUrl:K??"",pushUrl:K??""}))},t[49]=te,t[50]=K,t[51]=_,t[52]=o?.tracking,t[53]=fe):fe=t[53],o?.tracking;let ge;t[54]!==fe?(ge=fe(),t[54]=fe,t[55]=ge):ge=t[55];const H=ge,Se=o?.current??null;o?.tracking;let ae;t[56]!==o?.tracking?(ae=o?.tracking?.trim().split("/")[0],t[56]=o?.tracking,t[57]=ae):ae=t[57];const q=ae,me=(q&&i?.defaultBranches?.[q])??i?.defaultBranches?.origin;let pe;t[58]!==Se||t[59]!==me||t[60]!==H||t[61]!==X||t[62]!==A||t[63]!==C?.createdFromBranch?(pe=()=>uy({remoteNames:new Set(H.map(wy)),localBranches:X,worktreeCreatedFromBranch:C?.createdFromBranch,rootBranchHint:A,defaultBranch:me,headBranch:Se}),t[58]=Se,t[59]=me,t[60]=H,t[61]=X,t[62]=A,t[63]=C?.createdFromBranch,t[64]=pe):pe=t[64],C?.createdFromBranch;let Ie;t[65]!==pe?(Ie=pe(),t[65]=pe,t[66]=Ie):Ie=t[66];const Oe=Ie;if(!r||!Se){let je;t[67]===Symbol.for("react.memo_cache_sentinel")?(je=s.jsx(I,{name:"git-pull-request",className:"h-12 w-12 text-muted-foreground/50"}),t[67]=je):je=t[67];let Ne;t[68]!==e?(Ne=e("gitView.pullRequest.title"),t[68]=e,t[69]=Ne):Ne=t[69];let Pe;t[70]!==Ne?(Pe=s.jsx("div",{className:"typography-ui-header text-foreground",children:Ne}),t[70]=Ne,t[71]=Pe):Pe=t[71];let se;t[72]!==e?(se=e("gitView.pullRequest.createHint"),t[72]=e,t[73]=se):se=t[73];let oe;t[74]!==se?(oe=s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:se}),t[74]=se,t[75]=oe):oe=t[75];let Ee;return t[76]!==Pe||t[77]!==oe?(Ee=s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[je,Pe,oe]}),t[76]=Pe,t[77]=oe,t[78]=Ee):Ee=t[78],Ee}const Me=o?.tracking??void 0;let Fe;return t[79]!==Oe||t[80]!==Se||t[81]!==r||t[82]!==te||t[83]!==_||t[84]!==Me?(Fe=s.jsx($n,{as:jl,outerClassName:"h-full min-h-0",className:"px-4 py-3",disableHorizontal:!0,preventOverscroll:!0,children:s.jsx(dy,{directory:r,branch:Se,baseBranch:Oe,trackingBranch:Me,remotes:_,remoteBranches:te})}),t[79]=Oe,t[80]=Se,t[81]=r,t[82]=te,t[83]=_,t[84]=Me,t[85]=Fe):Fe=t[85],Fe};function my(t){return{ensureAll:t.ensureAll}}function hy(t){return t.currentSessionId}function py(t){return t.newSessionDraft}function gy(t){return t.worktreeMetadata}function xy(t){return t.availableWorktrees}function by(t){return!t.startsWith("remotes/")}function yy(t){return t.startsWith("remotes/")}function vy(t){return t.replace(/^remotes\//,"")}function wy(t){return t.name}const sl=5e3,Sy=(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},ni=(t,e)=>Gh(qh.getState().dictionary,t,e),jy=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"},ky=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 bs(`/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()},Bf=async(t,e,n)=>{if(Wh(e)||Vh(e)||Hh(e))return{ok:!0};try{const r=await ky(t,e,n);return Kh(r)?{ok:!1,reason:"binary"}:Sy(r,sl)>sl?{ok:!1,reason:"too-large"}:{ok:!0}}catch(r){return{ok:!1,reason:jy(r)}}},Lf=t=>{if(t==="too-large"){const e=sl.toLocaleString(yl());return ni("contextFileOpen.failure.tooLarge",{count:e})}return ni(t==="missing"?"contextFileOpen.failure.missing":t==="binary"?"filesView.editor.cannotPreviewBinary":"contextFileOpen.failure.unreadable")},id=3,to=t=>Array.from(t.types).includes("Files"),Cy=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]:[]})},ad=t=>{const e=t.name;return!e||e==="."||e===".."||e.includes("/")||e.includes("\\")?null:e},Ny=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),gs=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},_l=(t,e)=>{const n=gs(e),r=gs(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},Ay=(t,e)=>{const n=_l(t,e);if(n!==".")return n;const r=gs(t);return r.split("/").filter(Boolean).pop()??r},Dy=t=>{const e=gs(t),n=e.lastIndexOf("/");return n<0?"":n===0?"/":e.slice(0,n)},Py=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),Ey=new Set(["node_modules"]),Ty=t=>Ey.has(t),Iy=t=>{const e=gs(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},My=8,_n=new Map,$l=t=>JSON.stringify([Ms(),t]),Ry=t=>{const e=$l(t),n=_n.get(e);return n?(n.touchedAt=Date.now(),_n.delete(e),_n.set(e,n),n):null},Ea=t=>{const e=$l(t),n=_n.get(e);if(n)return n.touchedAt=Date.now(),n;if(_n.size>=My){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},Oy=t=>{_n.delete($l(t))},_f=(t,e)=>s.jsx(kl,{filePath:t,extension:e}),Fy=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},By=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:p,onSelect:b,onToggle:k,onRevealPath:v,onOpenDialog:g,onSetDropTarget:h,onDropFiles:S}=t,{t:y}=gt(),j=n.type==="directory";let C;e[0]!==j||e[1]!==n.path?(C=j?n.path:Dy(n.path),e[0]=j,e[1]=n.path,e[2]=C):C=e[2];const N=C,{canRename:w,canCreateFile:A,canCreateFolder:D,canDelete:P,canReveal:B}=f,F=!j&&!!p,E=B&&!c,_=w||A||D||P||F||E,[L,W]=l.useState(!1),[K,x]=l.useState(!1);let M;e[3]!==_?(M=ee=>{_&&(ee?.preventDefault(),x(!0))},e[3]=_,e[4]=M):M=e[4];const z=M;let U;e[5]!==j||e[6]!==n||e[7]!==b||e[8]!==k?(U=()=>{j?k(n.path):b(n)},e[5]=j,e[6]=n,e[7]=b,e[8]=k,e[9]=U):U=e[9];const V=U;let Z;e[10]===Symbol.for("react.memo_cache_sentinel")?(Z=ee=>{ee.stopPropagation(),x(!1),W(!0)},e[10]=Z):Z=e[10];const X=Z;let le;e[11]!==A||e[12]!==D||e[13]!==P||e[14]!==w||e[15]!==E||e[16]!==p||e[17]!==c||e[18]!==j||e[19]!==n||e[20]!==g||e[21]!==v||e[22]!==y?(le=ee=>{const{Item:$,Separator:de}=ee;return s.jsxs(s.Fragment,{children:[w&&s.jsxs($,{onClick:Y=>{Y.stopPropagation(),g("rename",n)},children:[s.jsx(I,{name:"edit",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.rename")]}),s.jsxs($,{onClick:Y=>{Y.stopPropagation(),Zn(n.path).then(ue=>{if(ue.ok){De.success(y("sidebarFilesTree.toast.pathCopied"));return}De.error(y("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.copyPath")]}),!j&&p&&s.jsxs($,{onClick:Y=>{Y.stopPropagation(),p(n.path).catch(ue=>{console.error("Download failed:",ue),De.error(y("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(I,{name:"download",className:"mr-2 h-4 w-4"})," ",y(c?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),E&&s.jsxs($,{onClick:Y=>{Y.stopPropagation(),v(n.path)},children:[s.jsx(I,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",y(ju())]}),j&&(A||D)&&s.jsxs(s.Fragment,{children:[s.jsx(de,{}),A&&s.jsxs($,{onClick:Y=>{Y.stopPropagation(),g("createFile",n)},children:[s.jsx(I,{name:"file-add",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.newFile")]}),D&&s.jsxs($,{onClick:Y=>{Y.stopPropagation(),g("createFolder",n)},children:[s.jsx(I,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.newFolder")]})]}),P&&s.jsxs(s.Fragment,{children:[s.jsx(de,{}),s.jsxs($,{onClick:Y=>{Y.stopPropagation(),g("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",y("sidebarFilesTree.menu.delete")]})]})]})},e[11]=A,e[12]=D,e[13]=P,e[14]=w,e[15]=E,e[16]=p,e[17]=c,e[18]=j,e[19]=n,e[20]=g,e[21]=v,e[22]=y,e[23]=le):le=e[23];const te=le;let fe;e[24]!==n.path||e[25]!==r?(fe=ee=>{const $=_l(r,n.path);!$||$==="."||(ee.dataTransfer.setData("application/x-openchamber-file-path",$),ee.dataTransfer.effectAllowed="copy")},e[24]=n.path,e[25]=r,e[26]=fe):fe=e[26];const ge=fe;let H;e[27]!==m||e[28]!==h||e[29]!==N?(H=ee=>{!m||!N||!to(ee.dataTransfer)||(ee.preventDefault(),ee.stopPropagation(),ee.dataTransfer.dropEffect="copy",h(N))},e[27]=m,e[28]=h,e[29]=N,e[30]=H):H=e[30];const Se=H;let ae;e[31]!==m||e[32]!==h||e[33]!==N?(ae=ee=>{!m||!N||!to(ee.dataTransfer)||ee.relatedTarget instanceof Node&&ee.currentTarget.contains(ee.relatedTarget)||(ee.stopPropagation(),h(null))},e[31]=m,e[32]=h,e[33]=N,e[34]=ae):ae=e[34];const q=ae;let me;e[35]!==m||e[36]!==S||e[37]!==N?(me=ee=>{!m||!N||!to(ee.dataTransfer)||(ee.preventDefault(),ee.stopPropagation(),S(N,ee.dataTransfer))},e[35]=m,e[36]=S,e[37]=N,e[38]=me):me=e[38];const pe=me;let Ie;e[39]!==z||e[40]!==q||e[41]!==Se||e[42]!==pe?(Ie=s.jsx("div",{className:"group relative flex items-center",onContextMenu:z,onDragEnter:Se,onDragOver:Se,onDragLeave:q,onDrop:pe}),e[39]=z,e[40]=q,e[41]=Se,e[42]=pe,e[43]=Ie):Ie=e[43];const Oe=u?"bg-interactive-selection ring-2 ring-inset ring-primary":i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let Me;e[44]!==Oe?(Me=xe("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",Oe,"cursor-grab active:cursor-grabbing"),e[44]=Oe,e[45]=Me):Me=e[45];let Fe;e[46]!==j||e[47]!==o||e[48]!==n.extension||e[49]!==n.path?(Fe=j?o?s.jsx(I,{name:"folder-open",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):s.jsx(I,{name:"folder-3",className:"h-4 w-4 flex-shrink-0 text-muted-foreground"}):_f(n.path,n.extension),e[46]=j,e[47]=o,e[48]=n.extension,e[49]=n.path,e[50]=Fe):Fe=e[50];let je;e[51]!==n.name||e[52]!==n.path?(je=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]=je):je=e[53];let Ne;e[54]!==j||e[55]!==a?(Ne=!j&&a&&s.jsx(Fy,{status:a}),e[54]=j,e[55]=a,e[56]=Ne):Ne=e[56];let Pe;e[57]!==d||e[58]!==j?(Pe=j&&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]=j,e[59]=Pe):Pe=e[59];let se;e[60]!==z||e[61]!==ge||e[62]!==V||e[63]!==Me||e[64]!==Fe||e[65]!==je||e[66]!==Ne||e[67]!==Pe?(se=s.jsxs("button",{type:"button",onClick:V,onContextMenu:z,draggable:!0,onDragStart:ge,className:Me,children:[Fe,je,Ne,Pe]}),e[60]=z,e[61]=ge,e[62]=V,e[63]=Me,e[64]=Fe,e[65]=je,e[66]=Ne,e[67]=Pe,e[68]=se):se=e[68];let oe;e[69]!==L||e[70]!==_||e[71]!==te||e[72]!==y?(oe=_&&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(un,{open:L,onOpenChange:W,children:[s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(cn,{asChild:!0,children:s.jsx(lt,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:X,title:y("sidebarFilesTree.actions.fileMenuTitle"),"aria-label":y("sidebarFilesTree.actions.fileMenuTitle"),children:s.jsx(I,{name:"more-2-fill",className:"h-4 w-4"})})})})}),s.jsx(ht,{side:"bottom",sideOffset:6,children:y("sidebarFilesTree.actions.fileMenuTitle")})]}),s.jsx(dn,{align:"end",side:"bottom",onCloseAutoFocus:()=>W(!1),children:te({Item:Ht,Separator:ln})})]})}),e[69]=L,e[70]=_,e[71]=te,e[72]=y,e[73]=oe):oe=e[73];let Ee;e[74]!==Ie||e[75]!==se||e[76]!==oe?(Ee=s.jsxs(df,{render:Ie,children:[se,oe]}),e[74]=Ie,e[75]=se,e[76]=oe,e[77]=Ee):Ee=e[77];let J;e[78]!==te?(J=s.jsx(lf,{className:"min-w-[180px]",children:te({Item:cf,Separator:qg})}),e[78]=te,e[79]=J):J=e[79];let re;return e[80]!==K||e[81]!==Ee||e[82]!==J?(re=s.jsxs(uf,{open:K,onOpenChange:x,children:[Ee,J]}),e[80]=K,e[81]=Ee,e[82]=J,e[83]=re):re=e[83],re},Ly=(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,_y=l.memo(By,Ly),$y=()=>{const{t}=gt(),{files:e,runtime:n}=nr(),r=Zm(n.platform),o=Lo()??"",i=gs(o.trim()),c=eh(),a=th(),d=vu(Q=>Q.searchFiles),u=he(Q=>Q.openContextFile),m=Sl(o),[f,p]=l.useState(""),b=Cl(f,200),k=l.useRef(null),[v,g]=l.useState([]),[h,S]=l.useState(!1),[y,j]=l.useState(null),[C,N]=l.useState(!1),[w,A]=l.useState(null),D=l.useRef(!1),P=l.useRef(i);P.current=i;const[B,F]=l.useState({}),[E,_]=l.useState({}),L=l.useRef(new Set),W=l.useRef(new Set),K=l.useRef(null);l.useEffect(()=>{if(j(null),A(null),!i){F({}),_({}),L.current=new Set;return}const Q=Ry(i);Q?(F({...Q.childrenByDir}),_({...Q.loadErrorsByDir}),L.current=new Set(Q.loadedDirs)):(F({}),_({}),L.current=new Set)},[i]),l.useEffect(()=>{if(!i)return;const Q=Ea(i);Q.childrenByDir=B},[i,B]),l.useEffect(()=>{if(!i)return;const Q=Ea(i);Q.loadErrorsByDir=E},[i,E]),l.useEffect(()=>{if(!i)return;const Q=Ea(i);Q.loadedDirs=new Set(L.current)},[i,B,E]),l.useEffect(()=>()=>{if(!i)return;const Q=_n.get(i);Q&&Q.loadedDirs.size===0&&Object.keys(Q.childrenByDir).length===0&&Oy(i)},[i]);const x=l.useMemo(()=>[],[]),M=l.useMemo(()=>[],[]),z=Ln(Q=>i?Q.byRoot[i]?.expandedPaths??x:x),U=Ln(Q=>i?Q.byRoot[i]?.selectedPath??null:null),V=Ln(Q=>Q.setSelectedPath),Z=Ln(Q=>Q.addOpenPath),X=Ln(Q=>Q.removeOpenPathsByPrefix),le=Ln(Q=>Q.toggleExpandedPath),te=Ln(Q=>Q.collapseAllExpandedPaths),fe=he(Q=>i?Q.contextPanelByDirectory[i]?.tabs??M:M),ge=l.useMemo(()=>new Set(fe.map(Q=>Q.mode==="file"?Q.targetPath:null).filter(Q=>typeof Q=="string"&&Q.length>0).map(Q=>gs(Q))),[fe]),[H,Se]=l.useState(null),[ae,q]=l.useState(null),[me,pe]=l.useState(""),[Ie,Oe]=l.useState(!1),Me=!!e.writeFile,Fe=!!e.createDirectory,je=!!e.rename,Ne=!!e.delete,Pe=!!e.revealPath,se=!!e.uploadFile,oe=l.useMemo(()=>({canRename:je,canCreateFile:Me,canCreateFolder:Fe,canDelete:Ne,canReveal:Pe}),[je,Me,Fe,Ne,Pe]),Ee=l.useCallback(Q=>{e.revealPath&&e.revealPath(Q).catch(()=>{De.error(t("sidebarFilesTree.toast.revealFailed"))})},[e,t]),J=l.useCallback((Q,ye)=>{Se(Q),q(ye),pe(Q==="rename"&&ye.name||""),Oe(!1)},[]),re=l.useCallback((Q,ye)=>{const Qe=ye.filter($e=>$e&&typeof $e.name=="string"&&$e.name.length>0).filter($e=>c||!$e.name.startsWith(".")).filter($e=>a||!Ty($e.name)).map($e=>{const ze=$e.name,Le=gs($e.path||""),st=Le?Py(Le)?Le:gs(`${Q}/${Le}`):gs(`${Q}/${ze}`),ct=$e.isDirectory?"directory":"file",Pt=ct==="file"&&ze.includes(".")?ze.split(".").pop()?.toLowerCase():void 0;return{name:ze,path:st,type:ct,extension:Pt}});return Ny(Qe)},[a,c]),ee=l.useCallback(async(Q,ye)=>{const Qe=gs(Q.trim());if(!Qe||L.current.has(Qe)||W.current.has(Qe))return;W.current=new Set(W.current),W.current.add(Qe);const $e=e.listDirectory?e.listDirectory(Qe).then(ze=>ze.entries.map(Le=>({name:Le.name,path:Le.path,isDirectory:Le.isDirectory}))):an.listLocalDirectory(Qe).then(ze=>ze.map(Le=>({name:Le.name,path:Le.path,isDirectory:Le.isDirectory})));try{const ze=await $e;if(ye?.())return;const Le=re(Qe,ze);L.current=new Set(L.current),L.current.add(Qe),_(st=>{if(!st[Qe])return st;const ct={...st};return delete ct[Qe],ct}),F(st=>({...st,[Qe]:Le}))}catch(ze){if(ye?.())return;const Le=ze instanceof Error?ze.message:String(ze??"");console.error("Failed to load sidebar directory:",ze),_(st=>({...st,[Qe]:Le}))}finally{W.current=new Set(W.current),W.current.delete(Qe)}},[e,re]),$=l.useCallback(async()=>{if(!i)return;K.current?.abort();const Q=new AbortController;K.current=Q;try{const Qe=(Ln.getState().byRoot[i]?.expandedPaths??[]).map(Le=>gs(Le)).filter(Le=>!!Le&&Le!==i&&Le.startsWith(`${i}/`)),$e=[i,...Qe];L.current=new Set(L.current);for(const Le of $e)L.current.delete(Le);_(Le=>{if(Object.keys(Le).length===0)return Le;const st={...Le};let ct=!1;for(const Pt of $e)Pt in st&&(delete st[Pt],ct=!0);return ct?st:Le});const ze=()=>Q.signal.aborted;await ee(i,ze);for(let Le=0;Le<Qe.length&&!Q.signal.aborted;Le+=3){const st=Qe.slice(Le,Le+3);await Promise.all(st.map(ct=>ee(ct,ze)))}}catch(ye){if(Q.signal.aborted)return;console.error("Failed to refresh sidebar tree:",ye)}finally{K.current===Q&&(K.current=null)}},[ee,i]),de=l.useCallback(async Q=>{if(!Q){await $();return}const ye=gs(Q);L.current=new Set(L.current),L.current.delete(ye),W.current=new Set(W.current),W.current.delete(ye),await ee(ye)},[ee,$]);l.useEffect(()=>{i&&(K.current?.abort(),L.current=new Set,W.current=new Set,_({}),F(Q=>Object.keys(Q).length===0?Q:{}),ee(i))},[ee,i,c,a]),l.useEffect(()=>{if(!i||z.length===0)return;const Q=z.map($e=>gs($e)).filter($e=>!!$e&&$e!==i&&$e.startsWith(`${i}/`)&&!L.current.has($e)&&!W.current.has($e)).sort(($e,ze)=>$e.split("/").length-ze.split("/").length);if(Q.length===0)return;let ye=!1;const Qe=()=>ye;return(async()=>{for(let $e=0;$e<Q.length&&!ye;$e+=3){const ze=Q.slice($e,$e+3);await Promise.all(ze.map(Le=>ee(Le,Qe)))}})(),()=>{ye=!0}},[z,ee,i]),l.useEffect(()=>{if(!o){g([]),S(!1);return}const Q=b.trim();if(!Q){g([]),S(!1);return}let ye=!1;return S(!0),d(o,Q,150,{includeHidden:c,respectGitignore:!a,type:"file"}).then(Qe=>{if(ye)return;const ze=Qe.filter(Le=>a||!Iy(Le.path)).map(Le=>({name:Le.name,path:gs(Le.path),type:"file",extension:Le.extension,relativePath:Le.relativePath}));g(ze)}).catch(()=>{ye||g([])}).finally(()=>{ye||S(!1)}),()=>{ye=!0}},[o,b,d,c,a]);const Y=l.useMemo(()=>{const Q=new Map;if(!m?.files)return Q;for(const ye of m.files)ye.index==="A"||ye.working_dir==="?"?Q.set(ye.path,"git-added"):ye.index==="D"?Q.set(ye.path,"git-deleted"):(ye.index==="M"||ye.working_dir==="M")&&Q.set(ye.path,"git-modified");return Q},[m]),ue=l.useMemo(()=>{const Q=new Map;if(!m?.files||!i)return Q;for(const ye of m.files){const Qe=ye.index==="M"||ye.working_dir==="M",$e=ye.index==="A"||ye.working_dir==="?";if(!Qe&&!$e)continue;const ze=ye.path.split("/");if(ze.length<=1)continue;let Le=i;for(let st=0;st<ze.length-1;st++){Le=`${Le}/${ze[st]}`;let ct=Q.get(Le);ct||(ct={modified:0,added:0},Q.set(Le,ct)),Qe&&ct.modified++,$e&&ct.added++}}return Q},[m,i]),Te=l.useCallback(Q=>{if(ge.has(Q))return"open";if(Y.size===0)return null;const ye=Q.startsWith(i+"/")?Q.slice(i.length+1):Q;return Y.get(ye)??null},[ge,Y,i]),Ge=l.useCallback(Q=>{if(ue.size===0)return null;const ye=ue.get(Q);return ye&&ye.modified+ye.added>0?ye:null},[ue]),_e=l.useCallback(async Q=>{if(!i)return;const ye=await Bf(e,Q.path,{directory:i});if(!ye.ok){De.error(Lf(ye.reason));return}V(i,Q.path),Z(i,Q.path),u(i,Q.path)},[Z,e,u,i,V]),ie=l.useCallback(async Q=>{const ye=gs(Q);i&&(le(i,ye),L.current.has(ye)||await ee(ye))},[ee,i,le]),Re=l.useCallback(async(Q,ye,Qe=!1)=>{const $e=e.uploadFile;if(!$e||ye.length===0||D.current||!i)return;const ze=i,Le=Ms();D.current=!0,N(!0),j(Q),Qe&&A(null);const st=[];for(let Mt=0;Mt<ye.length;Mt+=id){const kt=ye.slice(Mt,Mt+id),bt=await Promise.all(kt.map(async Bt=>{const wt=ad(Bt);if(!wt||Ms()!==Le)return"failed";try{return(await $e(gs(`${Q}/${wt}`),Bt,{directory:ze,overwrite:Qe})).success?"uploaded":"failed"}catch(Rt){return!Qe&&sh(Rt)&&Rt.reason==="already-exists"?"conflict":"failed"}}));st.push(...bt)}const ct=st.filter(Mt=>Mt==="uploaded").length,Pt=st.filter(Mt=>Mt==="failed").length,It=ye.filter((Mt,kt)=>st[kt]==="conflict"),Tt=ye.flatMap((Mt,kt)=>{const bt=ad(Mt);return st[kt]==="uploaded"&&bt?[gs(`${Q}/${bt}`)]:[]}),et=P.current===ze&&Ms()===Le;try{Tt.length>0&&fx({runtimeKey:Le,paths:Tt}),ct>0&&et&&await de(Q),ct>0&&De.success(t(It.length>0?"sidebarFilesTree.toast.uploadedWithoutConflicts":"sidebarFilesTree.toast.uploaded")),Pt>0&&De.error(t("sidebarFilesTree.toast.uploadFailed")),It.length>0&&et&&A({directory:Q,files:It,runtimeKey:Le,workspaceRoot:ze})}finally{D.current=!1,N(!1),j(null)}},[e.uploadFile,de,i,t]),be=l.useCallback((Q,ye)=>{const Qe=Cy(ye);Qe.length!==0&&Re(Q,Qe)},[Re]),T=l.useCallback(Q=>{!se||D.current||!i||!to(Q.dataTransfer)||(Q.preventDefault(),Q.dataTransfer.dropEffect="copy",j(i))},[se,i]),ce=l.useCallback(Q=>{to(Q.dataTransfer)&&(Q.relatedTarget instanceof Node&&Q.currentTarget.contains(Q.relatedTarget)||j(null))},[]),ve=l.useCallback(Q=>{!se||D.current||!i||!to(Q.dataTransfer)||(Q.preventDefault(),be(i,Q.dataTransfer))},[se,be,i]),Ce=l.useCallback(async Q=>{if(Q?.preventDefault(),!ae||!H)return;Oe(!0);const ye=()=>Oe(!1),Qe=()=>Se(null);if(H==="createFile"){if(!me.trim()){De.error(t("sidebarFilesTree.toast.filenameRequired")),ye();return}if(!e.writeFile){De.error(t("sidebarFilesTree.toast.writeNotSupported")),ye();return}const $e=ae.path,ze=$e?`${$e}/`:"",Le=gs(`${ze}${me.trim()}`);await e.writeFile(Le,"").then(async st=>{st.success&&(De.success(t("sidebarFilesTree.toast.fileCreated")),await de($e)),Qe()}).catch(()=>De.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ye);return}if(H==="createFolder"){if(!me.trim()){De.error(t("sidebarFilesTree.toast.folderNameRequired")),ye();return}const $e=ae.path,ze=$e?`${$e}/`:"",Le=gs(`${ze}${me.trim()}`);await e.createDirectory(Le).then(async st=>{st.success&&(De.success(t("sidebarFilesTree.toast.folderCreated")),await de($e)),Qe()}).catch(()=>De.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ye);return}if(H==="rename"){if(!me.trim()){De.error(t("sidebarFilesTree.toast.nameRequired")),ye();return}if(!e.rename){De.error(t("sidebarFilesTree.toast.renameNotSupported")),ye();return}const $e=ae.path,ze=$e.split("/").slice(0,-1).join("/"),Le=ze?`${ze}/`:"",st=gs(`${Le}${me.trim()}`);await e.rename($e,st).then(async ct=>{ct.success&&(De.success(t("sidebarFilesTree.toast.renamedSuccessfully")),await de(ze),i&&X(i,$e),(U===$e||U&&U.startsWith(`${$e}/`))&&V(i,null)),Qe()}).catch(()=>De.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ye);return}if(H==="delete"){if(!e.delete){De.error(t("sidebarFilesTree.toast.deleteNotSupported")),ye();return}const $e=ae.path,ze=$e.split("/").slice(0,-1).join("/");await e.delete($e).then(async Le=>{Le.success&&(De.success(t("sidebarFilesTree.toast.deletedSuccessfully")),await de(ze),i&&X(i,$e),(U===$e||U&&U.startsWith($e+"/"))&&V(i,null)),Qe()}).catch(()=>De.error(t("sidebarFilesTree.toast.operationFailed"))).finally(ye);return}ye()},[H,ae,me,e,de,X,i,U,V,t]);function Ae(Q,ye){const Qe=B[Q]??[];return Qe.map(($e,ze)=>{const Le=$e.type==="directory",st=Le&&z.includes($e.path),ct=U===$e.path,Pt=ze===Qe.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"}),Pt&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(_y,{node:$e,root:i,isExpanded:st,isActive:ct,isBrowserClient:r,status:Le?void 0:Te($e.path),badge:Le?Ge($e.path):void 0,isDropTarget:Le&&y===$e.path,canUpload:se&&!C,permissions:oe,downloadFile:e.downloadFile,onSelect:_e,onToggle:ie,onRevealPath:Ee,onOpenDialog:J,onSetDropTarget:j,onDropFiles:be}),Le&&st&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[E[$e.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[$e.path],children:E[$e.path]}),s.jsxs(lt,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{de($e.path)},children:[s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):null,Ae($e.path,ye+1)]})]},$e.path)})}const ne=!!(i&&B[i]),ke=i?E[i]:null,Ze=y?Ay(i,y):"";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:[Me&&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(I,{name:"file-add",className:"h-4 w-4"})})})}),s.jsx(ht,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFileTitle")})]}),Fe&&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(I,{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:()=>{$()},className:"h-8 w-8 p-0 flex-shrink-0",title:t("sidebarFilesTree.actions.refreshTitle"),"aria-label":t("sidebarFilesTree.actions.refreshTitle"),children:s.jsx(I,{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(I,{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(I,{name:"search",className:"pointer-events-none absolute left-2 top-2 h-4 w-4 text-muted-foreground"}),s.jsx(er,{ref:k,value:f,onChange:Q=>p(Q.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:()=>{p(""),k.current?.focus()},children:s.jsx(I,{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:xe("p-2",y===i&&"bg-interactive-selection/10"),onDragEnter:T,onDragOver:T,onDragLeave:ce,onDrop:ve,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(I,{name:"loader-4",className:"h-4 w-4 animate-spin"}),t("sidebarFilesTree.state.searching")]}):v.length>0?v.map(Q=>{const ye=U===Q.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>_e(Q),draggable:!0,onDragStart:Qe=>{const $e=Q.relativePath||_l(i??"",Q.path);!$e||$e==="."||(Qe.dataTransfer.setData("application/x-openchamber-file-path",$e),Qe.dataTransfer.effectAllowed="copy")},className:xe("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:Q.path,children:[_f(Q.path,Q.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:Q.relativePath??Q.path})]})},Q.path)}):ke?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{children:ke}),s.jsxs(lt,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{$()},children:[s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):ne&&i?Ae(i,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:t("sidebarFilesTree.state.loading")})})}),y?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(I,{name:C?"loader-4":"folder-received",className:xe("size-4 flex-shrink-0",C&&"animate-spin")}),s.jsx("span",{className:"min-w-0 truncate typography-meta",title:Ze,children:t(C?"sidebarFilesTree.drop.uploading":"sidebarFilesTree.drop.target",{path:Ze})})]}):null]}),s.jsx($s,{open:!!w,onOpenChange:Q=>!Q&&A(null),children:s.jsxs(zs,{children:[s.jsxs(An,{children:[s.jsx(fn,{children:t("sidebarFilesTree.dialog.uploadConflicts.title")}),s.jsx(mn,{children:t("sidebarFilesTree.dialog.uploadConflicts.description",{path:w?.directory??""})})]}),s.jsx($n,{outerClassName:"max-h-52",className:"flex flex-col gap-1 pr-2",children:w?.files.map((Q,ye)=>s.jsx("div",{className:"truncate rounded-md bg-muted px-2 py-1 typography-meta",title:Q.name,children:Q.name},`${Q.name}-${Q.size}-${ye}`))}),s.jsxs(tr,{children:[s.jsx(lt,{variant:"outline",onClick:()=>A(null),disabled:C,children:t("sidebarFilesTree.dialog.cancel")}),s.jsx(lt,{onClick:()=>{if(w){if(w.runtimeKey!==Ms()||w.workspaceRoot!==i){A(null);return}Re(w.directory,w.files,!0)}},disabled:C,children:t("sidebarFilesTree.dialog.uploadConflicts.replace")})]})]})}),s.jsx($s,{open:!!H,onOpenChange:Q=>!Q&&Se(null),children:s.jsxs(zs,{children:[s.jsxs(An,{children:[s.jsxs(fn,{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(mn,{children:[H==="createFile"&&t("sidebarFilesTree.dialog.createFile.description",{path:ae?.path??t("sidebarFilesTree.dialog.rootFallback")}),H==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.description",{path:ae?.path??t("sidebarFilesTree.dialog.rootFallback")}),H==="rename"&&t("sidebarFilesTree.dialog.rename.description",{name:ae?.name??""}),H==="delete"&&t("sidebarFilesTree.dialog.delete.description",{name:ae?.name??""})]})]}),H!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(er,{value:me,onChange:Q=>pe(Q.target.value),placeholder:t(H==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:Q=>{Q.key==="Enter"&&Ce()},autoFocus:!0})}),s.jsxs(tr,{children:[s.jsx(lt,{variant:"outline",onClick:()=>Se(null),disabled:Ie,children:t("sidebarFilesTree.dialog.cancel")}),s.jsx(lt,{variant:H==="delete"?"destructive":"default",onClick:()=>{Ce()},disabled:Ie||H!=="delete"&&!me.trim(),children:Ie?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):t(H==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm")})]})]})})]})},ld=60,zy=t=>{try{return new URL(t).origin}catch{return""}},Ta=new Set,$f=Lr()((t,e)=>({byOrigin:{},resolve:(n,r)=>{const o=zy(n);!o||!r||e().byOrigin[o]||Ta.has(o)||(Ta.add(o),Co("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<=ld)return{byOrigin:d};for(const m of u.slice(0,u.length-ld))delete d[m];return{byOrigin:d}})}).catch(()=>{}).finally(()=>{Ta.delete(o)}))}})),zl=t=>t,nl=t=>{const e=zl(t).type;return typeof e=="string"?e:""},Uy=t=>{const e=zl(t).tool;return typeof e=="string"?e:""},Wy=t=>{const e=zl(t).text;return typeof e=="string"?e:""},Vy=t=>{const e=nl(t);return e==="tool"?Uy(t).trim().toLowerCase()||"tool":e||"unknown"},Hy=t=>{if(t.length===0)return"";const e=[];for(const n of t){const r=Vy(n);e.includes(r)||e.push(r)}return e.join(" + ")},Ky=t=>t.replace(/\s+/g," ").trim(),Gy=t=>{for(const n of t)if(nl(n)==="text"){const r=Ky(Wy(n));if(r.length===0)continue;return r}const e=t.filter(n=>nl(n)!=="text").length;return e===0?"":`${e} attachment${e===1?"":"s"}`},qy=(t,e,n)=>`${n(t)} / ${n(e)}`,Yy=t=>{if(t==="12h")return!0;if(t==="24h")return!1},Qy=(t,e)=>{if(!t||!Number.isFinite(t))return"-";const n=Yy(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}})},rl={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},vi={user:0,assistant:0,tool:0,other:0},mr=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,Ia=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{...rl,total:mr(n)};if(!n||typeof n!="object")return rl;const r=n,o=mr(r.input),i=mr(r.output),c=mr(r.reasoning),a=mr(r.cache?.read),d=mr(r.cache?.write),u=mr(r.total);return{input:o,output:i,reasoning:c,cacheRead:a,cacheWrite:d,total:u>0?u:o+i+c+a+d}},Xy=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},rn=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+rn(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+rn(n),0):0,Jy=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...vi,assistant:rn(n.text)+rn(n.content)};const o=Xy(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:rn(n.input)+rn(n.output)+rn(n.error)+rn(n.call?.input)+rn(n.call?.output)+rn(n.call?.error)+rn(n.raw)+Math.round(rn(n.metadata)*.25)+Math.round(rn(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}},cd=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),Zy=t=>{const e=_o(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},ev=(t,e)=>{if(t.length===0)return{...vi};const n=t.reduce((r,o)=>{const i=Zy(o);let c={...vi};for(const a of o.parts)c=cd(c,Jy(a,i));return cd(r,c)},{...vi});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)}},Er=t=>t.toLocaleString(yl()),tv=(t,e)=>!t||!Number.isFinite(t)?"-":Ru(t,e,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),sv=(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}},nv=()=>{const t=it.c(203),{t:e}=gt(),n=he(rv);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=nt(ov),m=nt(iv),f=Fu(m??void 0),p=Yh(u??"",m??void 0),b=Yt(av);let k;t[1]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{d.current!==null&&(window.clearTimeout(d.current),d.current=null),i(lv),a(null)},t[1]=k):k=t[1];let v;t[2]!==m||t[3]!==u?(v=[m,u],t[2]=m,t[3]=u,t[4]=v):v=t[4],l.useEffect(k,v);let g,h;t[5]===Symbol.for("react.memo_cache_sentinel")?(g=()=>()=>{d.current!==null&&(window.clearTimeout(d.current),d.current=null)},h=[],t[5]=g,t[6]=h):(g=t[5],h=t[6]),l.useEffect(g,h);let S;t[7]===Symbol.for("react.memo_cache_sentinel")?(S=async(pt,yt)=>{(await Zn(yt)).ok?(a(pt),d.current!==null&&window.clearTimeout(d.current),d.current=window.setTimeout(()=>{a(Ue=>Ue===pt?null:Ue),d.current=null},2e3)):a(null)},t[7]=S):S=t[7];const y=S;let j;t[8]!==u||t[9]!==f?(j=u?f.find(pt=>pt.id===u)??null:null,t[8]=u,t[9]=f,t[10]=j):j=t[10];const C=j;let N,w,A,D,P,B;if(t[11]!==b||t[12]!==p){N=p.filter(cv);let pt;t[19]!==p?(pt=p.filter(dv),t[19]=p,t[20]=pt):pt=t[20],B=pt;let yt=null;for(let Ue=N.length-1;Ue>=0;Ue=Ue-1,Ue){const xt=N[Ue];if(Ia(xt).total>0){yt=xt;break}}D=yt?Ia(yt):rl,w=Qh({input:D.input,cache:{read:D.cacheRead,write:D.cacheWrite}}),P=N.reduce(uv,0);const Ke=yt?.info??null;A=sv(b,Ke?.providerID||"",Ke?.modelID||""),t[11]=b,t[12]=p,t[13]=N,t[14]=w,t[15]=A,t[16]=D,t[17]=P,t[18]=B}else N=t[13],w=t[14],A=t[15],D=t[16],P=t[17],B=t[18];const F=A,E=F.contextLimit,_=E&&E>0?Math.min(999,D.total/E*100):0;let L;if(t[21]!==p){const pt=[...p].reverse().find(fv)?.info?.system||"";L=ev(p,pt),t[21]=p,t[22]=L}else L=t[22];const W=L,K=W.user,x=W.assistant,M=W.tool,z=Math.max(0,D.input-K-x-M),U=K+x+M+z,V=p[0]?.info?.time?.created,Z=p.length>0?p[p.length-1]?.info?.time?.created:null;let X;t[23]!==C?.title||t[24]!==e?(X=C?.title||e("contextSidebar.session.untitled"),t[23]=C?.title,t[24]=e,t[25]=X):X=t[25];const le=C?.time?.created??V??null,te=Z??C?.time?.created??null;let fe;t[26]!==x||t[27]!==z||t[28]!==M||t[29]!==K?(fe={user:K,assistant:x,tool:M,other:z},t[26]=x,t[27]=z,t[28]=M,t[29]=K,t[30]=fe):fe=t[30];let ge;t[31]!==N.length||t[32]!==U||t[33]!==w||t[34]!==E||t[35]!==F||t[36]!==p.length||t[37]!==le||t[38]!==te||t[39]!==fe||t[40]!==X||t[41]!==D||t[42]!==P||t[43]!==_||t[44]!==B.length?(ge={sessionTitle:X,messagesCount:p.length,userMessagesCount:B.length,assistantMessagesCount:N.length,createdAt:le,lastActivityAt:te,providerModel:F,tokenBreakdown:D,usagePercent:_,cacheHitRate:w,totalAssistantCost:P,contextLimit:E,breakdown:fe,breakdownTotal:U},t[31]=N.length,t[32]=U,t[33]=w,t[34]=E,t[35]=F,t[36]=p.length,t[37]=le,t[38]=te,t[39]=fe,t[40]=X,t[41]=D,t[42]=P,t[43]=_,t[44]=B.length,t[45]=ge):ge=t[45];const H=ge;if(!u){let pt;t[46]!==e?(pt=e("contextSidebar.empty.openSession"),t[46]=e,t[47]=pt):pt=t[47];let yt;return t[48]!==pt?(yt=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:pt}),t[48]=pt,t[49]=yt):yt=t[49],yt}let Se;t[50]!==e?(Se=e("contextSidebar.breakdown.user"),t[50]=e,t[51]=Se):Se=t[51];let ae;t[52]!==Se||t[53]!==H.breakdown.user?(ae={key:"user",label:Se,value:H.breakdown.user,color:"var(--status-success)"},t[52]=Se,t[53]=H.breakdown.user,t[54]=ae):ae=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 pe;t[60]!==e?(pe=e("contextSidebar.breakdown.toolCalls"),t[60]=e,t[61]=pe):pe=t[61];let Ie;t[62]!==pe||t[63]!==H.breakdown.tool?(Ie={key:"tool",label:pe,value:H.breakdown.tool,color:"var(--status-warning)"},t[62]=pe,t[63]=H.breakdown.tool,t[64]=Ie):Ie=t[64];let Oe;t[65]!==e?(Oe=e("contextSidebar.breakdown.other"),t[65]=e,t[66]=Oe):Oe=t[66];let Me;t[67]!==Oe||t[68]!==H.breakdown.other?(Me={key:"other",label:Oe,value:H.breakdown.other,color:"var(--surface-muted-foreground)"},t[67]=Oe,t[68]=H.breakdown.other,t[69]=Me):Me=t[69];let Fe;t[70]!==ae||t[71]!==me||t[72]!==Ie||t[73]!==Me?(Fe=[ae,me,Ie,Me],t[70]=ae,t[71]=me,t[72]=Ie,t[73]=Me,t[74]=Fe):Fe=t[74];const je=Fe;let Ne;t[75]!==H.sessionTitle?(Ne=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:H.sessionTitle}),t[75]=H.sessionTitle,t[76]=Ne):Ne=t[76];let Pe;t[77]!==H.providerModel.modelName||t[78]!==H.providerModel.providerName?(Pe=s.jsxs("span",{children:[H.providerModel.providerName," / ",H.providerModel.modelName]}),t[77]=H.providerModel.modelName,t[78]=H.providerModel.providerName,t[79]=Pe):Pe=t[79];let se;t[80]!==n||t[81]!==H.createdAt?(se=H.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:tv(H.createdAt,n)})]}),t[80]=n,t[81]=H.createdAt,t[82]=se):se=t[82];let oe;t[83]!==Pe||t[84]!==se?(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:[Pe,se]}),t[83]=Pe,t[84]=se,t[85]=oe):oe=t[85];let Ee;t[86]!==Ne||t[87]!==oe?(Ee=s.jsxs("div",{className:"mb-6",children:[Ne,oe]}),t[86]=Ne,t[87]=oe,t[88]=Ee):Ee=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 ee;t[93]!==H.tokenBreakdown.total?(ee=Er(H.tokenBreakdown.total),t[93]=H.tokenBreakdown.total,t[94]=ee):ee=t[94];let $;t[95]!==H.contextLimit?($=H.contextLimit?` / ${Er(H.contextLimit)}`:"",t[95]=H.contextLimit,t[96]=$):$=t[96];let de;t[97]!==ee||t[98]!==$?(de=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[ee,$]}),t[97]=ee,t[98]=$,t[99]=de):de=t[99];let Y;t[100]!==re||t[101]!==de?(Y=s.jsxs("div",{className:"flex items-baseline justify-between",children:[re,de]}),t[100]=re,t[101]=de,t[102]=Y):Y=t[102];let ue;t[103]!==H.usagePercent?(ue=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]=ue):ue=t[104];let Te;t[105]!==ue?(Te=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:ue}),t[105]=ue,t[106]=Te):Te=t[106];let Ge;t[107]!==e||t[108]!==H.usagePercent?(Ge=e("contextSidebar.context.percentUsed",{percent:H.usagePercent.toFixed(1)}),t[107]=e,t[108]=H.usagePercent,t[109]=Ge):Ge=t[109];let _e;t[110]!==Ge?(_e=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:Ge}),t[110]=Ge,t[111]=_e):_e=t[111];let ie;t[112]!==Y||t[113]!==Te||t[114]!==_e?(ie=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Y,Te,_e]}),t[112]=Y,t[113]=Te,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 be;t[118]!==H.messagesCount?(be=Er(H.messagesCount),t[118]=H.messagesCount,t[119]=be):be=t[119];let T;t[120]!==Re||t[121]!==be?(T={label:Re,value:be},t[120]=Re,t[121]=be,t[122]=T):T=t[122];let ce;t[123]!==e?(ce=e("contextSidebar.stats.user"),t[123]=e,t[124]=ce):ce=t[124];let ve;t[125]!==H.userMessagesCount?(ve=Er(H.userMessagesCount),t[125]=H.userMessagesCount,t[126]=ve):ve=t[126];let Ce;t[127]!==ce||t[128]!==ve?(Ce={label:ce,value:ve},t[127]=ce,t[128]=ve,t[129]=Ce):Ce=t[129];let Ae;t[130]!==e?(Ae=e("contextSidebar.stats.assistant"),t[130]=e,t[131]=Ae):Ae=t[131];let ne;t[132]!==H.assistantMessagesCount?(ne=Er(H.assistantMessagesCount),t[132]=H.assistantMessagesCount,t[133]=ne):ne=t[133];let ke;t[134]!==Ae||t[135]!==ne?(ke={label:Ae,value:ne},t[134]=Ae,t[135]=ne,t[136]=ke):ke=t[136];let Ze;t[137]!==e?(Ze=e("contextSidebar.stats.cost"),t[137]=e,t[138]=Ze):Ze=t[138];let Q;t[139]!==H.totalAssistantCost?(Q=ux(H.totalAssistantCost),t[139]=H.totalAssistantCost,t[140]=Q):Q=t[140];let ye;t[141]!==Ze||t[142]!==Q?(ye={label:Ze,value:Q},t[141]=Ze,t[142]=Q,t[143]=ye):ye=t[143];let Qe;t[144]!==T||t[145]!==Ce||t[146]!==ke||t[147]!==ye?(Qe=[T,Ce,ke,ye],t[144]=T,t[145]=Ce,t[146]=ke,t[147]=ye,t[148]=Qe):Qe=t[148];const $e=Qe;let ze;t[149]!==$e?(ze=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:$e.map(mv)}),t[149]=$e,t[150]=ze):ze=t[150];let Le;t[151]!==e?(Le=e("contextSidebar.section.lastAssistantMessage"),t[151]=e,t[152]=Le):Le=t[152];let st;t[153]!==Le?(st=s.jsx("div",{className:"typography-micro text-muted-foreground mb-2.5",children:Le}),t[153]=Le,t[154]=st):st=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(hv)}),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 Pt;t[164]!==st||t[165]!==ct?(Pt=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[st,ct]}),t[164]=st,t[165]=ct,t[166]=Pt):Pt=t[166];let It;t[167]!==je||t[168]!==H.breakdownTotal?(It=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:je.map(pt=>pt.value<=0||H.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${pt.value/H.breakdownTotal*100}%`,backgroundColor:pt.color}},pt.key))}),t[167]=je,t[168]=H.breakdownTotal,t[169]=It):It=t[169];let Tt;t[170]!==je||t[171]!==H.breakdownTotal?(Tt=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:je.map(pt=>{const yt=H.breakdownTotal>0?pt.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:pt.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[pt.label," ",s.jsxs("span",{className:"tabular-nums",children:[yt.toFixed(0),"%"]})]})]},pt.key)})}),t[170]=je,t[171]=H.breakdownTotal,t[172]=Tt):Tt=t[172];let et;t[173]!==It||t[174]!==Tt?(et=s.jsxs("div",{className:"mb-6",children:[It,Tt]}),t[173]=It,t[174]=Tt,t[175]=et):et=t[175];let Mt;t[176]!==e?(Mt=e("contextSidebar.section.rawMessages"),t[176]=e,t[177]=Mt):Mt=t[177];let kt;t[178]!==Mt?(kt=s.jsx("div",{className:"typography-micro text-muted-foreground",children:Mt}),t[178]=Mt,t[179]=kt):kt=t[179];let bt;if(t[180]!==c||t[181]!==o||t[182]!==p||t[183]!==e||t[184]!==n){let pt;t[186]!==c||t[187]!==o||t[188]!==e||t[189]!==n?(pt=yt=>{const Ue=_o(yt.info).role,xt=Ue==="assistant",Ft=Ue==="user",$t=o[yt.info.id]===!0,ns=c===yt.info.id,Kt=yt.info.time?.created??null,St=Hy(yt.parts),zt=xt?Ia({info:yt.info,parts:yt.parts}):null,ms=Ft?Gy(yt.parts):"",ts=Qy(Kt,n),ys=St||"—",Vt=zt?qy(zt.input,zt.output,Er):"",Gt=Ue||"unknown",Ut=St?`${Gt}: ${St}`:Gt,Be=$t?JSON.stringify({info:yt.info,parts:yt.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":$t,onClick:()=>{i(Xe=>({...Xe,[yt.info.id]:Xe[yt.info.id]!==!0}))},children:s.jsxs("div",{className:"grid items-center gap-x-2 whitespace-nowrap typography-micro",style:{gridTemplateColumns:xt?"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:xt?ys:Ut}),xt&&s.jsx("span",{className:"text-right text-muted-foreground tabular-nums",children:Vt})]}),s.jsx("span",{className:"text-right text-muted-foreground",children:ts})]})}),$t&&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:Xe=>{Xe.stopPropagation(),y(yt.info.id,Be)},"aria-label":e(ns?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(ns?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:ns?s.jsx(I,{name:"check",className:"size-3.5"}):s.jsx(I,{name:"file-copy",className:"size-3.5"})})}),s.jsx(Xh,{language:"json",code:Be,style:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},wrap:!0})]})})]},yt.info.id)},t[186]=c,t[187]=o,t[188]=e,t[189]=n,t[190]=pt):pt=t[190],bt=[...p].reverse().map(pt),t[180]=c,t[181]=o,t[182]=p,t[183]=e,t[184]=n,t[185]=bt}else bt=t[185];let Bt;t[191]!==bt?(Bt=s.jsx("div",{className:"mt-2.5 space-y-1",children:bt}),t[191]=bt,t[192]=Bt):Bt=t[192];let wt;t[193]!==kt||t[194]!==Bt?(wt=s.jsxs("div",{children:[kt,Bt]}),t[193]=kt,t[194]=Bt,t[195]=wt):wt=t[195];let Rt;return t[196]!==Ee||t[197]!==ie||t[198]!==ze||t[199]!==Pt||t[200]!==et||t[201]!==wt?(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:[Ee,ie,ze,Pt,et,wt]})}),t[196]=Ee,t[197]=ie,t[198]=ze,t[199]=Pt,t[200]=et,t[201]=wt,t[202]=Rt):Rt=t[202],Rt};function rv(t){return t.timeFormatPreference}function ov(t){return t.currentSessionId}function iv(t){return t.currentSessionDirectory}function av(t){return t.providers}function lv(t){return Object.keys(t).length>0?{}:t}function cv(t){return _o(t.info).role==="assistant"}function dv(t){return _o(t.info).isUser}function uv(t,e){const n=mr(e.info.cost);return t+n}function fv(t){return _o(t.info).isUser&&typeof t.info.system=="string"}function mv(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 hv(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)}%`:Er(t.value):"—"})]},t.label)}const zf=new Set(["localhost","127.0.0.1","0.0.0.0","::1","[::1]"]),pv=t=>{const e=t.split("/")[0]?.split("?")[0]??"",n=e.startsWith("[")?e.slice(0,e.indexOf("]")+1):e.split(":")[0]??"";return zf.has(n.toLowerCase())},Nn="about:blank",so=t=>{const e=t.trim();if(!e)return Nn;const n=e.includes("://")?e:`${pv(e)?"http":"https"}://${e}`;try{const r=new URL(n);return r.protocol!=="http:"&&r.protocol!=="https:"?Nn:r.toString()}catch{return Nn}},ao=t=>{try{return zf.has(new URL(t).hostname.toLowerCase())}catch{return!1}},Ul=t=>{if(!t||t===Nn)return"";try{return new URL(t).host||t}catch{return t}},gv=new Set([-2,-7,-101,-102,-104,-109,-118,-324]),xv=(t,e)=>gv.has(t)&&ao(e),bv=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"},yv=async t=>{try{const e=await bs("/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(bv)}:{kind:"unavailable"}}catch{return{kind:"unavailable"}}},vv=async t=>{try{const e=await bs("/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}},wv=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}},Sv=({announced:t,discovered:e})=>{const n=new Map;for(const r of t){const o=wv(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)},ol="__openchamberBrowserAnnotationActive",jv=`(() => {
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['${ol}']; } catch (error) { /* non-configurable */ }
56
+ })();`,kv=(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['${ol}'] = 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['${ol}']; } 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
+ });`},Cv={kind:"idle"},Vn=t=>typeof t=="object"&&t!==null,Jn=t=>typeof t=="number"&&Number.isFinite(t),dd=t=>Vn(t)&&Object.values(t).every(e=>typeof e=="string"),Wl=t=>Vn(t)&&Jn(t.x)&&Jn(t.y)&&Jn(t.width)&&Jn(t.height),Uf=t=>Vn(t)&&Jn(t.x)&&Jn(t.y),Nv=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"),Av=t=>Vn(t)&&typeof t.tag=="string"&&typeof t.text=="string"&&typeof t.selector=="string"&&typeof t.path=="string"&&Wl(t.bounds)&&Uf(t.center)&&dd(t.attributes)&&dd(t.computedStyle)&&Array.isArray(t.ancestry)&&t.ancestry.every(Nv),Dv=t=>Vn(t)&&typeof t.id=="string"&&Av(t.element),Pv=t=>Vn(t)&&typeof t.id=="string"&&Wl(t.rect),Ev=t=>Vn(t)&&typeof t.id=="string"&&Wl(t.bounds)&&Array.isArray(t.points)&&t.points.every(Uf),Tv=t=>Vn(t)&&typeof t.id=="string"&&typeof t.pageUrl=="string"&&typeof t.pageTitle=="string"&&typeof t.comment=="string"&&Vn(t.viewport)&&Jn(t.viewport.width)&&Jn(t.viewport.height)&&Jn(t.devicePixelRatio)&&Array.isArray(t.elements)&&t.elements.every(Dv)&&Array.isArray(t.regions)&&t.regions.every(Pv)&&Array.isArray(t.strokes)&&t.strokes.every(Ev),Iv=1600,Mv=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}),Rv=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 Mv(`data:${e};base64,${t}`),m=Math.max(1,u.naturalWidth||n),f=Math.max(1,u.naturalHeight||r),p=m/Math.max(1,o||m),b=f/Math.max(1,i||f),k=Math.min(1,Iv/m),v=document.createElement("canvas");v.width=Math.max(1,Math.floor(m*k)),v.height=Math.max(1,Math.floor(f*k));const g=v.getContext("2d");if(!g)return null;g.scale(k,k),g.drawImage(u,0,0,m,f);const h=C=>({x:C.x*p,y:C.y*b,width:C.width*p,height:C.height*b}),S=Math.max(2,2.5*p/Math.max(k,.2));g.strokeStyle=a,g.fillStyle=d;const y=C=>{const N=h(C);g.lineWidth=S,g.fillRect(N.x,N.y,N.width,N.height),g.strokeRect(N.x,N.y,N.width,N.height)};for(const C of c.elements)y(C.element.bounds);for(const C of c.regions)y(C.rect);for(const C of c.strokes)C.points.length<2||(g.beginPath(),C.points.forEach((N,w)=>{const A=N.x*p,D=N.y*b;w===0?g.moveTo(A,D):g.lineTo(A,D)}),g.lineCap="round",g.lineJoin="round",g.lineWidth=S*1.4,g.stroke());const j=await new Promise(C=>v.toBlob(C,"image/jpeg",.85));return j?new File([j],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},Ov="({ width: window.innerWidth, height: window.innerHeight })",Fv=async t=>{try{const e=await t.executeJavaScript(Ov,!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}},wi=async t=>{try{await t.executeJavaScript(jv,!1)}catch{}},Bv=async({host:t,theme:e,labels:n})=>{const r=kv(e,n),o=await t.executeJavaScript(r,!0);if(o==null)return null;if(!Tv(o))return await wi(t),null;const i=o;try{const c=await Fv(t)??i.viewport,a=await t.capturePage();if(!a||!a.base64)return{payload:i,screenshot:null};const d=await Rv({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}}},jn={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)"},Lv=()=>{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()}},_v=t=>{const e=Lv();if(!e)return{...jn,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)`)||jn.glassSurface,glassFilter:`blur(${i}) saturate(${c})`,primary:n("--primary",jn.primary),primarySoft:r("--primary",16,jn.primarySoft),primaryFaint:r("--primary",10,jn.primaryFaint),primaryContrast:n("--primary-foreground",jn.primaryContrast),surface:n("--surface-background",jn.surface),surfaceElevated:n("--surface-elevated",jn.surfaceElevated),border:n("--border",jn.border),text:n("--foreground",jn.text),mutedText:n("--muted-foreground",jn.mutedText)}}catch{return{...jn,colorScheme:t}}finally{e.dispose()}};let no=null,ro=null,Si=null,Ro=0,Li=null;const zn=new Set,$v=3e4,zv=45e3,Wf=()=>{Si&&(clearTimeout(Si),Si=null)},Vf=()=>{if(ro||zn.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(Ro,5)),$v);ro=setTimeout(()=>{ro=null,Ro+=1,Vl()},t)},Oo=()=>{Wf(),no&&no.close(),no=null},ud=()=>{Wf(),zn.size!==0&&(Si=setTimeout(()=>{Oo(),Vf()},zv))},Uv=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}},ri=t=>!t||typeof t!="object"?null:t,Wv=t=>{if(t.type==="openchamber:event-stream-ready"){Ro=0;return}if(t.type==="openchamber:heartbeat")return;if(t.type==="openchamber:agent-memory-changed"){const d=ri(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=ri(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 p of zn)p(f);return}if(t.type==="openchamber:browser-control-request"){const d=ri(t.properties),u=typeof d?.requestId=="string"?d.requestId:"",m=typeof d?.action=="string"?d.action:"";if(!u||!m)return;const f=d?.parameters,p={type:"browser-control-request",requestId:u,action:m,parameters:f&&typeof f=="object"&&!Array.isArray(f)?f:{}};for(const b of zn)b(p);return}if(t.type!=="openchamber:scheduled-task-ran")return;const e=ri(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)},Vl=()=>{if(typeof window>"u"||zn.size===0||typeof EventSource!="function"||no&&no.readyState!==EventSource.CLOSED)return;Oo();const t=typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,e=new EventSource(wu().sse("/api/openchamber/events",t?{browser:"1"}:void 0));e.onopen=()=>{ud()},e.onmessage=n=>{ud();const r=Uv(n.data);r&&Wv(r)},e.onerror=()=>{Oo(),Vf()},no=e},Vv=()=>{Li||typeof window>"u"||(Li=Ki(()=>{Oo(),Ro=0,Vl()}))},Hv=()=>{Li?.(),Li=null},ra=t=>(zn.add(t),Vv(),Vl(),()=>{zn.delete(t),zn.size===0&&(ro&&(clearTimeout(ro),ro=null),Ro=0,Oo(),Hv())}),Kv=2e3,Gv=50;let Or=null,oo=null,Ao=null;const qv=async t=>{try{const e=await bs("/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}},Gr=async(t,e)=>{try{const n=await bs("/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)}},Yv=async(t=Kv)=>{const e=Date.now()+t;for(;!Or&&Date.now()<e;)await new Promise(n=>setTimeout(n,Gv));return Or},Qv=async t=>{const e=t.action==="browser.open",n=Or;if(!(!n&&!(e&&oo))&&await qv(t.requestId))try{if(e&&!n){const o=typeof t.parameters.url=="string"?t.parameters.url:"";if(!o){await Gr(t.requestId,{ok:!1,error:"url is required"});return}oo?.(o);const i=typeof t.parameters.viewport=="string"?t.parameters.viewport:"";if(!i||i==="fill"){await Gr(t.requestId,{ok:!0,data:{url:o,opened:!0}});return}const c=await Yv();if(!c){await Gr(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 Gr(t.requestId,{ok:!0,data:{url:o,opened:!0,viewportApplied:!0,viewport:d}});return}const r=await n.run(t.action,t.parameters);await Gr(t.requestId,{ok:!0,data:r})}catch(r){await Gr(t.requestId,{ok:!1,error:r instanceof Error?r.message:String(r)})}},Hf=()=>{Ao||(Ao=ra(t=>{t.type==="browser-control-request"&&Qv({requestId:t.requestId,action:t.action,parameters:t.parameters})}))},Kf=()=>{Or||oo||!Ao||(Ao(),Ao=null)},Xv=t=>(Or=t,Hf(),()=>{Or===t&&(Or=null),Kf()}),Jv=t=>(oo=t,Hf(),()=>{oo===t&&(oo=null),Kf()}),Zv=50,ew=6,tw=2048,sw=200,Gf=t=>{const e=so(String(t??"").trim());if(!e||e.length>tw)return"";try{const n=new URL(e);return n.protocol!=="http:"&&n.protocol!=="https:"?"":n.toString()}catch{return""}},nw=(t,e)=>{const n=Gf(e.url);if(!n)return t;const r=t.find(c=>c.url===n),o=String(e.title??"").trim().slice(0,sw)||r?.title||"";return[{url:n,title:o,lastVisitedAt:e.at},...t.filter(c=>c.url!==n)].slice(0,Zv)},rw=(t,e)=>{const n=Gf(e);return t.filter(r=>r.url!==n)},ow=t=>`${t.url.replace(/^https?:\/\//,"")} ${t.title}`.toLowerCase(),qf=(t,e,n=ew)=>{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=ow(c);return c.url===r||a===i?!1:a.includes(i)}).slice(0,n)},fd=20,ji=t=>{const e=jt((t||"").trim());return e?JSON.stringify([Ms(),e]):""},iw=t=>{const e=Object.keys(t);if(e.length<=fd)return t;const n=e.map(r=>[r,t[r]?.[0]?.lastVisitedAt??0]).sort((r,o)=>o[1]-r[1]).slice(0,fd);return Object.fromEntries(n.map(([r])=>[r,t[r]??[]]))},io=Lr()(bx(t=>({byProject:{},recordVisit:(e,n)=>{const r=ji(e);r&&t(o=>{const i=o.byProject[r]??[],c=nw(i,{...n,at:Date.now()});return c===i?o:{byProject:iw({...o.byProject,[r]:c})}})},forget:(e,n)=>{const r=ji(e);r&&t(o=>{const i=o.byProject[r];return i?{byProject:{...o.byProject,[r]:rw(i,n)}}:o})},clear:e=>{const n=ji(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:nh(),partialize:t=>({byProject:t.byProject})})),aw=[],Yf=t=>e=>{const n=ji(t);return(n?e.byProject[n]:void 0)??aw},il=new Map,Fo=new Map,Qf=()=>typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,Xf=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:!ao(e.toString())}catch{return!1}},Jf=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}},md=(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 Do extends Error{constructor(e){super(e),this.name="DevTunnelUnavailableError"}}const hd=async t=>{if(!t||!Qf()||!ao(t))return t;const e=pr();if(!Xf(e))return t;const n=Jf(t);if(!n)return t;const r=`${e}|${n}`,o=il.get(r);if(o){try{Fo.set(o,new URL(t).origin)}catch{}return md(t,o)}try{const i=await Co("desktop_dev_tunnel_open",{baseUrl:e,port:n,clientToken:Eo(),requestHeaders:Su()});if(!i||!Number.isInteger(i.localPort)||i.localPort<=0)throw new Do(t);il.set(r,i.localPort);try{Fo.set(i.localPort,new URL(t).origin)}catch{}return md(t,i.localPort)}catch(i){throw i instanceof Do?i:new Do(t)}},pd=t=>{if(!t||!Qf()||!ao(t)||!Xf(pr()))return!1;const e=Jf(t);return e>0&&!Fo.has(e)},wo=t=>{if(!t)return t;try{const e=new URL(t);if(e.hostname!=="127.0.0.1")return t;const n=Fo.get(Number.parseInt(e.port||"0",10));return n?`${n}${e.pathname}${e.search}${e.hash}`:t}catch{return t}},lw=()=>{il.clear(),Fo.clear()};typeof window<"u"&&Ki(lw);const gd=6e3,cw=120,dw=80,uw=`
601
+ var MAX_ELEMENTS = ${cw};
602
+ var MAX_LABEL_CHARS = ${dw};
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
+ `,$o=t=>`(() => {
716
+ ${uw}
717
+ ${t}
718
+ })()`,fw=({selector:t}={})=>$o(`
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, ${gd}),
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 > ${gd}) {
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
+ `),mw=({selector:t,text:e})=>$o(`
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
+ `),hw=({selector:t,value:e,submit:n})=>$o(`
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
+ `),pw=({selector:t,direction:e})=>$o(`
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
+ `),gw=["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"],xw=({selector:t})=>$o(`
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(gw)};
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
+ `),bw=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=(p,b)=>s.jsxs("div",{role:"option","aria-selected":b===r,className:xe("group flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1",b===r?"bg-interactive-hover":"hover:bg-interactive-hover"),onPointerDown:k=>{k.preventDefault(),o(p.url)},onPointerEnter:()=>c(b),children:[s.jsx(I,{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:p.title||Ul(p.url)}),s.jsx("div",{className:"truncate typography-micro text-muted-foreground",children:p.url})]}),s.jsx("button",{type:"button",className:xe("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:k=>{k.preventDefault(),k.stopPropagation(),i(p.url)},children:s.jsx(I,{name:"close",className:"size-3","aria-hidden":"true"})})]},p.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},kn=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=xe("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(I,{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 p;e[12]!==r?(p=s.jsx(ht,{sideOffset:6,children:r}),e[12]=r,e[13]=p):p=e[13];let b;return e[14]!==f||e[15]!==p?(b=s.jsxs(ft,{children:[f,p]}),e[14]=f,e[15]=p,e[16]=b):b=e[16],b},Zf=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:p,isLoading:b,onAnnotate:k,onOpenDevTools:v,isAnnotating:g,onHardReload:h,onZoomIn:S,onZoomOut:y,onZoomReset:j,zoomPercent:C,onClearCookies:N,onClearCache:w,onToggleDeviceBar:A,isDeviceBarOpen:D}=t;let P;e[0]!==r?(P=r===void 0?[]:r,e[0]=r,e[1]=P):P=e[1];const B=P,F=C===void 0?100:C,{t:E}=gt(),[_,L]=l.useState(!1),[W,K]=l.useState(-1);let x;e[2]!==_||e[3]!==B?(x=_?B:[],e[2]=_,e[3]=B,e[4]=x):x=e[4];const M=x;let z;e[5]===Symbol.for("react.memo_cache_sentinel")?(z=()=>{K(-1)},e[5]=z):z=e[5];let U;e[6]!==n||e[7]!==_?(U=[n,_],e[6]=n,e[7]=_,e[8]=U):U=e[8],l.useEffect(z,U);let V;e[9]!==c?(V=ie=>{L(!1),K(-1),c(ie)},e[9]=c,e[10]=V):V=e[10];const Z=V;let X;e[11]!==W||e[12]!==Z||e[13]!==M?(X=ie=>{if(M.length!==0){if(ie.key==="ArrowDown"||ie.key==="ArrowUp"){ie.preventDefault();const Re=ie.key==="ArrowDown"?1:-1,be=M.length;K(T=>{const ce=T+Re;return ce<-1?be-1:ce>=be?-1:ce});return}if(ie.key==="Escape"&&W>=0){ie.preventDefault(),K(-1);return}if(ie.key==="Enter"&&W>=0){ie.preventDefault();const Re=M[W];Re&&Z(Re.url)}}},e[11]=W,e[12]=Z,e[13]=M,e[14]=X):X=e[14];const le=X;let te;e[15]!==E?(te=E("contextPanel.browser.back"),e[15]=E,e[16]=te):te=e[16];const fe=!f;let ge;e[17]!==a||e[18]!==fe||e[19]!==te?(ge=s.jsx(kn,{icon:"arrow-left",label:te,onClick:a,disabled:fe}),e[17]=a,e[18]=fe,e[19]=te,e[20]=ge):ge=e[20];let H;e[21]!==E?(H=E("contextPanel.browser.forward"),e[21]=E,e[22]=H):H=e[22];const Se=!p;let ae;e[23]!==d||e[24]!==H||e[25]!==Se?(ae=s.jsx(kn,{icon:"arrow-right",label:H,onClick:d,disabled:Se}),e[23]=d,e[24]=H,e[25]=Se,e[26]=ae):ae=e[26];let q;e[27]!==b||e[28]!==E?(q=E(b?"contextPanel.browser.stop":"contextPanel.browser.reload"),e[27]=b,e[28]=E,e[29]=q):q=e[29];let me;e[30]!==u||e[31]!==q?(me=s.jsx(kn,{icon:"refresh",label:q,onClick:u}),e[30]=u,e[31]=q,e[32]=me):me=e[32];let pe;e[33]!==h||e[34]!==E?(pe=h?s.jsx(kn,{icon:"restart",label:E("contextPanel.browser.hardReload"),onClick:h}):null,e[33]=h,e[34]=E,e[35]=pe):pe=e[35];let Ie;e[36]!==n||e[37]!==Z?(Ie=ie=>{ie.preventDefault(),Z(n)},e[36]=n,e[37]=Z,e[38]=Ie):Ie=e[38];let Oe;e[39]!==i?(Oe=ie=>i(ie.target.value),e[39]=i,e[40]=Oe):Oe=e[40];let Me,Fe;e[41]===Symbol.for("react.memo_cache_sentinel")?(Me=()=>L(!0),Fe=()=>L(!1),e[41]=Me,e[42]=Fe):(Me=e[41],Fe=e[42]);const je=M.length>0;let Ne;e[43]===Symbol.for("react.memo_cache_sentinel")?(Ne=xe("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]=Ne):Ne=e[43];let Pe;e[44]!==E?(Pe=E("contextPanel.browser.addressAria"),e[44]=E,e[45]=Pe):Pe=e[45];let se;e[46]!==n||e[47]!==le||e[48]!==Oe||e[49]!==je||e[50]!==Pe?(se=s.jsx("input",{value:n,onChange:Oe,onFocus:Me,onBlur:Fe,onKeyDown:le,spellCheck:!1,autoComplete:"off",role:"combobox","aria-expanded":je,"aria-controls":"openchamber-browser-address-suggestions",className:Ne,"aria-label":Pe}),e[46]=n,e[47]=le,e[48]=Oe,e[49]=je,e[50]=Pe,e[51]=se):se=e[51];let oe;e[52]!==o?(oe=ie=>o?.(ie),e[52]=o,e[53]=oe):oe=e[53];let Ee;e[54]!==W||e[55]!==Z||e[56]!==oe||e[57]!==M?(Ee=s.jsx("div",{id:"openchamber-browser-address-suggestions",children:s.jsx(bw,{entries:M,activeIndex:W,onSelect:Z,onForget:oe,onHighlight:K})}),e[54]=W,e[55]=Z,e[56]=oe,e[57]=M,e[58]=Ee):Ee=e[58];let J;e[59]!==Ie||e[60]!==se||e[61]!==Ee?(J=s.jsxs("form",{className:"relative min-w-0 flex-1",onSubmit:Ie,children:[se,Ee]}),e[59]=Ie,e[60]=se,e[61]=Ee,e[62]=J):J=e[62];let re;e[63]!==S||e[64]!==y||e[65]!==j||e[66]!==E||e[67]!==F?(re=y&&S?s.jsxs("div",{className:"flex shrink-0 items-center",children:[s.jsx(kn,{icon:"subtract",label:E("contextPanel.browser.zoomOut"),onClick:y}),F!==100&&j?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:j,"aria-label":E("contextPanel.browser.zoomReset"),children:[F,"%"]})}),s.jsx(ht,{sideOffset:6,children:E("contextPanel.browser.zoomReset")})]}):null,s.jsx(kn,{icon:"add",label:E("contextPanel.browser.zoomIn"),onClick:S})]}):null,e[63]=S,e[64]=y,e[65]=j,e[66]=E,e[67]=F,e[68]=re):re=e[68];let ee;e[69]!==N||e[70]!==E?(ee=N?s.jsx(kn,{icon:"delete-bin",label:E("contextPanel.browser.clearCookies"),onClick:N}):null,e[69]=N,e[70]=E,e[71]=ee):ee=e[71];let $;e[72]!==w||e[73]!==E?($=w?s.jsx(kn,{icon:"database-2",label:E("contextPanel.browser.clearCache"),onClick:w}):null,e[72]=w,e[73]=E,e[74]=$):$=e[74];let de;e[75]!==D||e[76]!==A||e[77]!==E?(de=A?s.jsx(kn,{icon:"smartphone",label:E("contextPanel.browser.deviceToolbar"),onClick:A,pressed:D}):null,e[75]=D,e[76]=A,e[77]=E,e[78]=de):de=e[78];let Y;e[79]!==g||e[80]!==k||e[81]!==E?(Y=k?s.jsx(kn,{icon:"markup",label:E("contextPanel.browser.annotate.toggle"),onClick:k,pressed:g}):null,e[79]=g,e[80]=k,e[81]=E,e[82]=Y):Y=e[82];let ue;e[83]!==v||e[84]!==E?(ue=v?s.jsx(kn,{icon:"terminal-box",label:E("contextPanel.browser.devTools"),onClick:v}):null,e[83]=v,e[84]=E,e[85]=ue):ue=e[85];let Te;e[86]!==E?(Te=E("contextPanel.browser.openExternal"),e[86]=E,e[87]=Te):Te=e[87];let Ge;e[88]!==m||e[89]!==Te?(Ge=s.jsx(kn,{icon:"external-link",label:Te,onClick:m}),e[88]=m,e[89]=Te,e[90]=Ge):Ge=e[90];let _e;return e[91]!==ge||e[92]!==ae||e[93]!==me||e[94]!==pe||e[95]!==J||e[96]!==re||e[97]!==ee||e[98]!==$||e[99]!==de||e[100]!==Y||e[101]!==ue||e[102]!==Ge?(_e=s.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[ge,ae,me,pe,J,re,ee,$,de,Y,ue,Ge]}),e[91]=ge,e[92]=ae,e[93]=me,e[94]=pe,e[95]=J,e[96]=re,e[97]=ee,e[98]=$,e[99]=de,e[100]=Y,e[101]=ue,e[102]=Ge,e[103]=_e):_e=e[103],_e},_i={kind:"fill"},xd=240,yw=3840,em=[{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}],bd=t=>Number.isFinite(t)?Math.round(Math.min(yw,Math.max(xd,t))):xd,$i=t=>t.kind==="fill"?null:{width:t.width,height:t.height},tm=t=>{const e=em.find(n=>n.id===t);return e?{kind:"preset",id:e.id,width:e.width,height:e.height}:null},vw=t=>t.kind==="fill"?t:{kind:"custom",width:t.height,height:t.width},ww=(t,e)=>{const n=$i(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}},Sw=["mobile","tablet","desktop","fill"],jw={mobile:"iphone-14",tablet:"ipad-mini",desktop:"desktop"},yd=t=>typeof t=="string"&&Sw.includes(t),al=t=>t==="fill"?_i:tm(jw[t])??_i,oi=t=>{const e=$i(t);if(!e)return{mode:"fill",width:null,height:null};for(const n of["mobile","tablet","desktop"]){const r=al(n),o=$i(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}},kw=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=$i(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=(fe,ge)=>{const H=Number.parseInt(ge,10);if(!Number.isFinite(H))return;const Se=u??{width:1280,height:800};r({kind:"custom",width:bd(fe==="width"?H:Se.width),height:bd(fe==="height"?H:Se.height)})},e[2]=r,e[3]=u,e[4]=f):f=e[4];const p=f;let b;e[5]===Symbol.for("react.memo_cache_sentinel")?(b=xe("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]=b):b=e[5];const k=b;let v;e[6]!==r?(v=fe=>{const ge=tm(fe.target.value);r(ge??_i)},e[6]=r,e[7]=v):v=e[7];let g;e[8]!==a?(g=a("contextPanel.browser.device.preset"),e[8]=a,e[9]=g):g=e[9];let h;e[10]===Symbol.for("react.memo_cache_sentinel")?(h=xe("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 S;e[11]!==a?(S=a("contextPanel.browser.device.responsive"),e[11]=a,e[12]=S):S=e[12];let y;e[13]!==S?(y=s.jsx("option",{value:"",children:S}),e[13]=S,e[14]=y):y=e[14];let j;e[15]===Symbol.for("react.memo_cache_sentinel")?(j=em.map(Cw),e[15]=j):j=e[15];let C;e[16]!==m||e[17]!==v||e[18]!==g||e[19]!==y?(C=s.jsxs("select",{value:m,onChange:v,"aria-label":g,className:h,children:[y,j]}),e[16]=m,e[17]=v,e[18]=g,e[19]=y,e[20]=C):C=e[20];const N=u?String(u.width):"";let w;e[21]!==p?(w=fe=>p("width",fe.target.value),e[21]=p,e[22]=w):w=e[22];let A;e[23]!==a?(A=a("contextPanel.browser.device.width"),e[23]=a,e[24]=A):A=e[24];let D;e[25]!==N||e[26]!==w||e[27]!==A?(D=s.jsx("input",{value:N,onChange:w,placeholder:"—",inputMode:"numeric","aria-label":A,className:k}),e[25]=N,e[26]=w,e[27]=A,e[28]=D):D=e[28];let P;e[29]===Symbol.for("react.memo_cache_sentinel")?(P=s.jsx("span",{className:"typography-micro text-muted-foreground",children:"×"}),e[29]=P):P=e[29];const B=u?String(u.height):"";let F;e[30]!==p?(F=fe=>p("height",fe.target.value),e[30]=p,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 _;e[34]!==B||e[35]!==F||e[36]!==E?(_=s.jsx("input",{value:B,onChange:F,placeholder:"—",inputMode:"numeric","aria-label":E,className:k}),e[34]=B,e[35]=F,e[36]=E,e[37]=_):_=e[37];let L;e[38]!==r||e[39]!==n?(L=()=>r(vw(n)),e[38]=r,e[39]=n,e[40]=L):L=e[40];const W=!u;let K;e[41]!==a?(K=a("contextPanel.browser.device.rotate"),e[41]=a,e[42]=K):K=e[42];let x;e[43]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(I,{name:"refresh",className:"size-3.5","aria-hidden":"true"}),e[43]=x):x=e[43];let M;e[44]!==L||e[45]!==W||e[46]!==K?(M=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:L,disabled:W,"aria-label":K,children:x})}),e[44]=L,e[45]=W,e[46]=K,e[47]=M):M=e[47];let z;e[48]!==a?(z=a("contextPanel.browser.device.rotate"),e[48]=a,e[49]=z):z=e[49];let U;e[50]!==z?(U=s.jsx(ht,{sideOffset:6,children:z}),e[50]=z,e[51]=U):U=e[51];let V;e[52]!==M||e[53]!==U?(V=s.jsxs(ft,{children:[M,U]}),e[52]=M,e[53]=U,e[54]=V):V=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 X;e[58]===Symbol.for("react.memo_cache_sentinel")?(X=["system","light","dark"],e[58]=X):X=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:X.map(fe=>s.jsx(lt,{type:"button",variant:o===fe?"secondary":"ghost",size:"xs",className:xe("shrink-0 rounded-full px-2.5 typography-micro",o===fe?"text-foreground":"text-muted-foreground hover:text-foreground"),onClick:()=>i(fe),"aria-pressed":o===fe,children:a(fe==="system"?"contextPanel.browser.device.schemeSystem":fe==="light"?"contextPanel.browser.device.schemeLight":"contextPanel.browser.device.schemeDark")},fe))}),e[59]=o,e[60]=i,e[61]=a,e[62]=le):le=e[62];let te;return e[63]!==C||e[64]!==D||e[65]!==_||e[66]!==V||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:[C,D,P,_,V,Z,le]}),e[63]=C,e[64]=D,e[65]=_,e[66]=V,e[67]=Z,e[68]=le,e[69]=te):te=e[69],te};function Cw(t){return s.jsx("option",{value:t.id,children:t.label},t.id)}const Nw=t=>{try{const e=new URL(t).pathname;return e==="/"?"":e}catch{return""}},Aw=2e3,Dw=()=>{if(typeof window>"u"||window.__OPENCHAMBER_ELECTRON__)return!1;const t=pr();if(!t)return!1;try{return!ao(new URL(t,window.location.href).toString())}catch{return!1}},sm=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=Zx(o),[m]=l.useState(Dw);let f,p;e[1]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{let D=!0,P=null;const B=new AbortController,F=()=>{yv(B.signal).then(E=>{D&&(d(E),P=setTimeout(F,Aw))})};return F(),()=>{D=!1,P&&clearTimeout(P),B.abort()}},p=[],e[1]=f,e[2]=p):(f=e[1],p=e[2]),l.useEffect(f,p);const b=a.kind==="ready"?a.servers:null;let k;e[3]!==u||e[4]!==b?(k=Sv({announced:u,discovered:b}),e[3]=u,e[4]=b,e[5]=k):k=e[5];const v=k;let g;e[6]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(Bu,{width:110,height:110,className:"shrink-0 opacity-20"}),e[6]=g):g=e[6];let h;e[7]!==i?(h=i("contextPanel.browser.empty"),e[7]=i,e[8]=h):h=e[8];let S;e[9]!==h?(S=s.jsx("span",{className:"typography-ui-header text-foreground",children:h}),e[9]=h,e[10]=S):S=e[10];let y;e[11]!==i?(y=i("contextPanel.browser.emptyHint"),e[11]=i,e[12]=y):y=e[12];let j;e[13]!==y?(j=s.jsx("span",{className:"typography-micro text-muted-foreground",children:y}),e[13]=y,e[14]=j):j=e[14];let C;e[15]!==j||e[16]!==S?(C=s.jsxs("div",{className:"flex shrink-0 flex-col gap-1",children:[S,j]}),e[15]=j,e[16]=S,e[17]=C):C=e[17];let N;e[18]!==u||e[19]!==v||e[20]!==o||e[21]!==n||e[22]!==m||e[23]!==i?(N=v.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:v.map(D=>s.jsxs(lt,{type:"button",variant:"outline",size:"sm",className:"w-full shrink-0 justify-start gap-2",onClick:()=>{Qx(o),n(D.url)},children:[s.jsx(I,{name:"global",className:"size-3.5 shrink-0","aria-hidden":"true"}),s.jsx("span",{className:"truncate",children:Ul(D.url)||D.url}),s.jsx("span",{className:"ml-auto truncate typography-micro text-muted-foreground",children:Nw(D.url)})]},D.port))})]}):null,e[18]=u,e[19]=v,e[20]=o,e[21]=n,e[22]=m,e[23]=i,e[24]=N):N=e[24];let w;e[25]!==v.length||e[26]!==a.kind||e[27]!==i?(w=v.length===0&&a.kind==="unavailable"?s.jsx("span",{className:"typography-micro text-muted-foreground",children:i("contextPanel.browser.devServers.unavailable")}):null,e[25]=v.length,e[26]=a.kind,e[27]=i,e[28]=w):w=e[28];let A;return e[29]!==C||e[30]!==N||e[31]!==w?(A=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:[g,C,N,w]}),e[29]=C,e[30]=N,e[31]=w,e[32]=A):A=e[32],A},Js=t=>Math.round(t),Pw=(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=${Js(c.x)}, y=${Js(c.y)}, width=${Js(c.width)}, height=${Js(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")},Ew=(t,e)=>{const n=t.rect;return`Region ${e+1}: x=${Js(n.x)}, y=${Js(n.y)}, width=${Js(n.width)}, height=${Js(n.height)}`},Tw=(t,e)=>{const n=t.bounds;return`Drawing ${e+1}: ${t.points.length} points over x=${Js(n.x)}, y=${Js(n.y)}, width=${Js(n.width)}, height=${Js(n.height)}`},Iw=({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: ${Js(t.viewport.width)}x${Js(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("",...Pw(a.element,c));return t.regions.length>0&&(i.push(""),t.regions.forEach((c,a)=>i.push(Ew(c,a)))),t.strokes.length>0&&(i.push(""),t.strokes.forEach((c,a)=>i.push(Tw(c,a)))),i.filter(c=>typeof c=="string").join(`
905
+ `)},Mw=t=>{const e=it.c(7),{t:n}=gt(),r=nt(Ow),o=nt(Fw),i=Ka(Bw),c=Jh(Lw);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){De.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:Iw({payload:d.payload,screenshotAttached:m,intro:n("contextPanel.browser.annotate.intro")}),language:"markdown",text:""}),De.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},Rw=()=>{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 Ow(t){return t.currentSessionId}function Fw(t){return t.newSessionDraft?.open}function Bw(t){return t.addDraft}function Lw(t){return t.addAttachedFile}const _w=3e4,$w=3,zw=250,Uw={attempts:0,windowStartedAt:null},Ww=(t,e)=>{const n=t.windowStartedAt===null||e-t.windowStartedAt>=_w,r=n?0:t.attempts;return r>=$w?null:{delayMs:zw*2**r,state:{attempts:r+1,windowStartedAt:n?e:t.windowStartedAt}}},Vw=-3,ii=t=>typeof t=="string"&&t.length>0&&t!=="about:blank",Jr=t=>{const e=t;return e.detail&&typeof e.detail=="object"?e.detail:t},Hw=(t,{initialUrl:e,onUrlChange:n})=>{const[r,o]=l.useState(e?{kind:"loading",url:e}:Cv),[i,c]=l.useState(e),[a,d]=l.useState(""),[u,m]=l.useState(!1),[f,p]=l.useState(!1),b=l.useRef(n);b.current=n;const k=l.useRef(Uw);return l.useEffect(()=>{if(!t)return;const v=()=>{try{const P=t.getURL();return ii(P)?P:""}catch{return""}},g=()=>{try{m(t.canGoBack()),p(t.canGoForward())}catch{}},h=P=>{ii(P)&&(c(P),b.current(P))},S=()=>{const P=v();o({kind:"loading",url:P})},y=()=>{const P=v();let B="";try{B=t.getTitle()||""}catch{B=""}d(B),h(P),g(),o(F=>F.kind==="failed"&&F.url===P?F:{kind:"ready",url:P,title:B})},j=P=>{const B=Jr(P);ii(B.url)&&(h(B.url),g())},C=P=>{const B=Jr(P),F=Array.isArray(B.favicons)?B.favicons.find(Boolean):"",E=v();F&&E&&$f.getState().resolve(E,F)},N=P=>{const B=Jr(P);typeof B.title=="string"&&d(B.title)},w=P=>{const B=Jr(P);if(B.isMainFrame===!1)return;const F=typeof B.errorCode=="number"?B.errorCode:0;F!==Vw&&o({kind:"failed",url:ii(B.validatedURL)?B.validatedURL:v(),code:F,description:typeof B.errorDescription=="string"?B.errorDescription:""})};let A=null;const D=()=>{const P=v(),B=Ww(k.current,Date.now());if(!B){o({kind:"failed",url:P,code:0,description:"",crashed:!0});return}k.current=B.state,o({kind:"loading",url:P}),A=setTimeout(()=>{A=null;try{t.reload()}catch{o({kind:"failed",url:P,code:0,description:"",crashed:!0})}},B.delayMs)};t.addEventListener("did-start-loading",S),t.addEventListener("did-stop-loading",y),t.addEventListener("did-navigate",j),t.addEventListener("did-navigate-in-page",j),t.addEventListener("page-title-updated",N),t.addEventListener("page-favicon-updated",C),t.addEventListener("did-fail-load",w),t.addEventListener("render-process-gone",D),t.addEventListener("crashed",D);try{!t.isLoading()&&v()&&y()}catch{}return()=>{A!==null&&clearTimeout(A),t.removeEventListener("render-process-gone",D),t.removeEventListener("crashed",D),t.removeEventListener("did-start-loading",S),t.removeEventListener("did-stop-loading",y),t.removeEventListener("did-navigate",j),t.removeEventListener("did-navigate-in-page",j),t.removeEventListener("page-title-updated",N),t.removeEventListener("page-favicon-updated",C),t.removeEventListener("did-fail-load",w)}},[t]),{status:r,url:i,title:a,canGoBack:u,canGoForward:f}},Kw=()=>typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,Gw=4e4,vd=.5,qw=-3,Yw=4,Qw="persist:openchamber-browser",wd=20,Xw=600,Jw=2e4,Zw=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=gt(),{currentTheme:o}=Br(),i=l.useRef(null),[c,a]=l.useState(null),d=l.useCallback(J=>{i.current=J,a(J)},[]),u=he(J=>J.setContextPanelTabTargetPath),m=l.useRef(so(t)),f=m.current!==Nn?m.current:"",[p,b]=l.useState(f?null:Nn),[k,v]=l.useState(f),[g,h]=l.useState(!1),[S,y]=l.useState(!1),[j,C]=l.useState(0),[N,w]=l.useState(!1),[A,D]=l.useState(_i),P=l.useRef(A);P.current=A;const B=l.useRef([]),[F,E]=l.useState("system"),[_,L]=l.useState({width:0,height:0}),W=l.useRef(null),K=l.useRef(null),x=l.useRef(!1),M=l.useRef(Date.now()),z=l.useCallback(J=>{!J||J===Nn||!e||!n||u(e,n,J)},[e,n,u]),U=Hw(c,{initialUrl:f,onUrlChange:l.useCallback(J=>{const re=wo(J);v(re),z(re)},[z])}),[V,Z]=l.useState(null),X=Mw(e),le=Rw(),te=U.status.kind==="loading",fe=io(Yf(e)),ge=io(J=>J.recordVisit),H=io(J=>J.forget);l.useEffect(()=>{U.status.kind==="ready"&&ge(e,{url:wo(U.status.url),title:U.status.title})},[e,U.status,ge]);const Se=l.useMemo(()=>qf(fe,k),[fe,k]),ae=l.useCallback(J=>{const re=so(J);re!==Nn&&(v(re),Z(null),hd(re).then(ee=>{const $=i.current;if(!$){b(ee);return}try{$.loadURL(ee)}catch{b(ee)}}).catch(ee=>{ee instanceof Do&&Z(re)}))},[]);l.useEffect(()=>{if(!f)return;let J=!0;return hd(f).then(re=>{J&&b(re)}).catch(re=>{if(J){if(re instanceof Do){Z(f),b(Nn);return}b(f)}}),()=>{J=!1}},[]);const q=l.useMemo(()=>({executeJavaScript:async(J,re)=>{const ee=i.current;if(!ee)throw new Error("Browser view is not available");return ee.executeJavaScript(J,re)},capturePage:async()=>{const J=i.current;if(!J)return null;const re=J.getWebContentsId();return Number.isFinite(re)?await Co("desktop_browser_capture_page",{webContentsId:re}):null}}),[]),me=l.useCallback(()=>{if(g){h(!1),wi(q);return}if(!U.url){De.error(r("contextPanel.browser.annotate.noPage"));return}const J=_v(o.metadata.variant==="light"?"light":"dark");h(!0),Bv({host:q,theme:J,labels:le}).then(async re=>{h(!1),re&&await X(re)}).catch(()=>{h(!1),De.error(r("contextPanel.browser.annotate.failed"))})},[q,X,o,g,U.url,le,r]);l.useEffect(()=>{if(!g)return;const J=re=>{re.key==="Escape"&&(re.preventDefault(),re.stopImmediatePropagation(),h(!1),wi(q))};return window.addEventListener("keydown",J,!0),()=>window.removeEventListener("keydown",J,!0)},[q,g]);const pe=l.useCallback(async(J=8e3)=>{const re=Date.now();for(;;){const ee=i.current;if(!ee)return!1;let $=!1;try{$=ee.isLoading()}catch{return!1}if(!$)return!0;if(Date.now()-re>J)return!1;await new Promise(de=>setTimeout(de,120))}},[]),Ie=l.useCallback(async(J,re)=>{const ee=i.current;if(!ee)throw new Error("The browser panel is not ready");const $=()=>{yd(re.viewport)&&(D(al(re.viewport)),w(!0))};if(J==="browser.back"||J==="browser.forward"){const _e=J==="browser.back";if(!(_e?ee.canGoBack():ee.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?ee.goBack():ee.goForward(),await new Promise(be=>setTimeout(be,150)),await pe();let Re="";try{Re=ee.getTitle()||""}catch{Re=""}return{url:wo(ee.getURL()),title:Re}}if(J==="browser.capture"){await pe();const _e=await q.capturePage();if(!_e)throw new Error("The page could not be captured");let ie="";try{ie=ee.getTitle()||""}catch{ie=""}return{..._e,url:wo(ee.getURL()),title:ie,viewport:oi(P.current)}}if(J==="browser.resize"){if(!yd(re.viewport))throw new Error("viewport is required");return $(),await new Promise(_e=>setTimeout(_e,200)),await pe(),{viewport:oi(al(re.viewport))}}if(J==="browser.open"){const _e=typeof re.url=="string"?re.url:"";if(!_e)throw new Error("url is required");$(),ae(_e),await new Promise(be=>setTimeout(be,150));const ie=await pe(25e3);let Re="";try{Re=ee.getTitle()||""}catch{Re=""}return{url:so(_e),title:Re,opened:!0,settled:ie,viewport:oi(P.current)}}await pe();const de=_e=>typeof _e=="string"&&_e?_e:void 0,ue=(()=>{switch(J){case"browser.snapshot":return fw({selector:de(re.selector)});case"browser.click":return mw({selector:de(re.selector),text:de(re.text)});case"browser.type":return hw({selector:String(re.selector??""),value:String(re.value??""),submit:re.submit===!0});case"browser.inspect":return xw({selector:String(re.selector??"")});case"browser.scroll":return pw({selector:de(re.selector),direction:de(re.direction)});default:return null}})();if(!ue)throw new Error(`Unsupported browser action: ${J}`);const Te=await ee.executeJavaScript(ue,!0);if(!Te||typeof Te!="object")throw new Error("The page returned no result");const Ge=Te;if(Ge.ok!==!0)throw new Error(typeof Ge.error=="string"&&Ge.error?Ge.error:"Browser action failed");if(J==="browser.snapshot"){const _e=B.current;return{...Ge,viewport:oi(P.current),..._e.length>0?{consoleProblems:[..._e]}:{}}}return(J==="browser.click"||J==="browser.type"&&re.submit===!0)&&(await new Promise(_e=>setTimeout(_e,150)),await pe()),Te},[q,ae,pe]);l.useEffect(()=>Xv({run:Ie}),[Ie]),l.useEffect(()=>{const J=q;return()=>{wi(J)}},[q]),l.useEffect(()=>{if(!c)return;const J=ee=>{const $=ee;if(typeof $.level!="number"||$.level<2)return;const de=$.sourceId?`${$.sourceId}${$.line?`:${$.line}`:""}`:"";B.current.push({level:$.level>=3?"error":"warning",message:String($.message??"").slice(0,400),source:de}),B.current.length>wd&&B.current.splice(0,B.current.length-wd)},re=()=>{B.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 Oe=l.useRef(new Set),Me=l.useCallback(J=>{Oe.current.clear(),ae(J)},[ae]);l.useEffect(()=>{if(!c)return;const J=ee=>{const $=Jr(ee),de=typeof $.url=="string"?$.url:"";!de||!pd(de)||(ee.preventDefault(),ae(de))},re=ee=>{const $=Jr(ee);if($.isMainFrame===!1||$.errorCode===-3)return;const de=typeof $.validatedURL=="string"?$.validatedURL:"";!de||!pd(de)||Oe.current.has(de)||(Oe.current.add(de),ae(de))};return c.addEventListener("will-navigate",J),c.addEventListener("did-fail-load",re),()=>{c.removeEventListener("will-navigate",J),c.removeEventListener("did-fail-load",re)}},[ae,c]),l.useEffect(()=>{if(!c)return;const J=re=>{const ee=re.detail;re.preventDefault(),ee?.url&&ae(ee.url)};return c.addEventListener("new-window",J),()=>c.removeEventListener("new-window",J)},[ae,c]);const Fe=l.useCallback(J=>{const re=Math.min(Yw,Math.max(qw,J));C(re);try{i.current?.setZoomLevel(re)}catch{}},[]),je=l.useCallback(J=>{Co("desktop_browser_clear_data",{partition:Qw,cookies:J==="cookies",cache:J==="cache"}).then(()=>{De.success(r(J==="cookies"?"contextPanel.browser.clearedCookies":"contextPanel.browser.clearedCache"));try{i.current?.reloadIgnoringCache()}catch{}}).catch(()=>De.error(r("contextPanel.browser.clearFailed")))},[r]);l.useEffect(()=>{const J=W.current;if(!J||typeof ResizeObserver>"u")return;const re=new ResizeObserver(ee=>{const $=ee[0]?.contentRect;$&&L({width:$.width,height:$.height})});return re.observe(J),()=>re.disconnect()},[]);const Ne=l.useCallback(J=>{E(J);const re=i.current;if(!re)return;let ee=-1;try{ee=re.getWebContentsId()}catch{return}Co("desktop_browser_set_color_scheme",{webContentsId:ee,scheme:J}).catch($=>{E("system"),De.error($ instanceof Error?$.message:r("contextPanel.browser.device.schemeFailed"))})},[r]),Pe=l.useCallback(()=>{try{te?i.current?.stop():i.current?.reload()}catch{}},[te]),se=U.status;l.useEffect(()=>{const J=()=>{y(!0);const $=setTimeout(()=>{try{i.current?.reload()}catch{}},Xw);return()=>clearTimeout($)};if(se.kind==="failed"){if(!xv(se.code,se.url)){y(!1);return}const $=Date.now(),de=K.current?.url===se.url?K.current:{url:se.url,startedAt:$};if(K.current=de,$-de.startedAt>Gw){y(!1);return}return J()}if(se.kind==="loading")return;if(K.current=null,se.kind!=="ready"||!se.url||!ao(se.url)){x.current=!0,y(!1);return}if(x.current||Date.now()-M.current>Jw){x.current=!0,y(!1);return}let re=!1,ee=null;return vv(wo(se.url)).then($=>{if(!re){if($===null||$<500){x.current=!0,y(!1);return}ee=J()}}),()=>{re=!0,ee?.()}},[se]);const oe=U.status.kind==="failed"&&!S?U.status:null,Ee=ww(A,_);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsx(Zf,{address:k,onAddressChange:v,onSubmit:Me,suggestions:Se,onForgetSuggestion:J=>H(e,J),onBack:()=>{try{i.current?.goBack()}catch{}},onForward:()=>{try{i.current?.goForward()}catch{}},onReload:Pe,onOpenExternal:()=>{Gi(U.url||k)},canGoBack:U.canGoBack,canGoForward:U.canGoForward,isLoading:te,onAnnotate:me,isAnnotating:g,onOpenDevTools:()=>{try{i.current?.openDevTools()}catch{}},onHardReload:()=>{try{i.current?.reloadIgnoringCache()}catch{}},onZoomIn:()=>Fe(j+vd),onZoomOut:()=>Fe(j-vd),onZoomReset:()=>Fe(0),zoomPercent:Math.round(Math.pow(1.2,j)*100),onClearCookies:()=>je("cookies"),onClearCache:()=>je("cache"),onToggleDeviceBar:()=>w(J=>!J),isDeviceBarOpen:N}),N?s.jsx(kw,{viewport:A,onViewportChange:D,colorScheme:F,onColorSchemeChange:Ne,scale:Ee?.scale??1}):null,s.jsxs("div",{ref:W,className:xe("relative min-h-0 flex-1 bg-background",Ee&&"flex items-center justify-center overflow-hidden bg-[var(--surface-muted)]"),children:[p!==null?s.jsx("webview",{ref:d,src:p,partition:"persist:openchamber-browser",allowpopups:!0,style:Ee?{width:`${Ee.width}px`,height:`${Ee.height}px`,transform:`scale(${Ee.scale})`,border:"none",flex:"none",boxShadow:"0 2px 18px rgba(0,0,0,.28)"}:{width:"100%",height:"100%",border:"none"}}):null,p!==null&&!f&&!U.url&&!te?s.jsx(sm,{onOpen:Me,directory:e}):null,S?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,V?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:V})})]}):null,oe&&!V?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]})]})},e1=t=>{const e=it.c(49),{initialUrl:n,directory:r,tabID:o}=t,{t:i}=gt(),c=he(s1);let a;e[0]!==n?(a=so(n),e[0]=n,e[1]=a):a=e[1];const d=a,u=d!==Nn?d:"",[m,f]=l.useState(u),[p,b]=l.useState(u);let k;e[2]!==u?(k=u?[u]:[],e[2]=u,e[3]=k):k=e[3];const[v,g]=l.useState(k),[h,S]=l.useState(u?0:-1),[y,j]=l.useReducer(n1,0);let C;e[4]!==r||e[5]!==c||e[6]!==o?(C=te=>{!te||te===Nn||!r||!o||c(r,o,te)},e[4]=r,e[5]=c,e[6]=o,e[7]=C):C=e[7];const N=C;let w;e[8]!==r?(w=Yf(r),e[8]=r,e[9]=w):w=e[9];const A=io(w),D=io(r1),P=io(o1);let B;e[10]!==m||e[11]!==A?(B=qf(A,m),e[10]=m,e[11]=A,e[12]=B):B=e[12];const F=B;let E;e[13]!==r||e[14]!==h||e[15]!==N||e[16]!==D?(E=te=>{const fe=so(te);fe!==Nn&&(f(fe),b(fe),N(fe),D(r,{url:fe}),g(ge=>{const H=h>=0?ge.slice(0,h+1):[];return H[H.length-1]===fe?(S(H.length-1),H):(S(H.length),[...H,fe])}))},e[13]=r,e[14]=h,e[15]=N,e[16]=D,e[17]=E):E=e[17];const _=E;let L;e[18]!==v||e[19]!==N?(L=te=>{const fe=v[te];fe&&(S(te),f(fe),b(fe),N(fe))},e[18]=v,e[19]=N,e[20]=L):L=e[20];const W=L;let K;e[21]!==r||e[22]!==P?(K=te=>P(r,te),e[21]=r,e[22]=P,e[23]=K):K=e[23];let x,M;e[24]!==W||e[25]!==h?(M=()=>W(h-1),x=()=>W(h+1),e[24]=W,e[25]=h,e[26]=x,e[27]=M):(x=e[26],M=e[27]);let z;e[28]!==m||e[29]!==p?(z=()=>{Gi(p||m)},e[28]=m,e[29]=p,e[30]=z):z=e[30];const U=h>0,V=h>=0&&h<v.length-1;let Z;e[31]!==m||e[32]!==_||e[33]!==F||e[34]!==x||e[35]!==z||e[36]!==U||e[37]!==V||e[38]!==K||e[39]!==M?(Z=s.jsx(Zf,{address:m,onAddressChange:f,onSubmit:_,suggestions:F,onForgetSuggestion:K,onBack:M,onForward:x,onReload:j,onOpenExternal:z,canGoBack:U,canGoForward:V,isLoading:!1}),e[31]=m,e[32]=_,e[33]=F,e[34]=x,e[35]=z,e[36]=U,e[37]=V,e[38]=K,e[39]=M,e[40]=Z):Z=e[40];let X;e[41]!==p||e[42]!==_||e[43]!==y||e[44]!==i?(X=s.jsx("div",{className:"relative min-h-0 flex-1 bg-background",children:p?s.jsx("iframe",{src:p,title:i("contextPanel.browser.frameTitle"),className:"h-full w-full border-none bg-white",sandbox:"allow-scripts allow-forms allow-same-origin allow-popups"},`${p}|${y}`):s.jsx(sm,{onOpen:_})}),e[41]=p,e[42]=_,e[43]=y,e[44]=i,e[45]=X):X=e[45];let le;return e[46]!==Z||e[47]!==X?(le=s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[Z,X]}),e[46]=Z,e[47]=X,e[48]=le):le=e[48],le},t1=t=>{const e=it.c(3),[n]=l.useState(Kw);let r;return e[0]!==n||e[1]!==t?(r=n?s.jsx(Zw,{...t}):s.jsx(e1,{...t}),e[0]=n,e[1]=t,e[2]=r):r=e[2],r};function s1(t){return t.setContextPanelTabTargetPath}function n1(t){return t+1}function r1(t){return t.recordVisit}function o1(t){return t.forget}const i1=pn(()=>hn(()=>import("./WalkthroughView-CaSYE0lw.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}))),a1=pn(()=>hn(()=>import("./DiffView-BHWaMYCC.js"),__vite__mapDeps([122,1,2,4,5,6,7,8,9,3,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}))),l1=pn(()=>hn(()=>import("./FilesView-NMBCW2Tm.js"),__vite__mapDeps([123,1,2,4,5,6,7,8,9,3,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}))),c1=pn(()=>hn(()=>import("./GitView-Rp8P1KEI.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}))),d1=pn(()=>hn(()=>import("./PlanView-Czu1KMJa.js"),__vite__mapDeps([136,1,2,4,5,6,7,8,9,124,57,58,59,60,61,62,79,55,56,63,125,126,127,3,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,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,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}))),u1=380,f1=1400,nm=600,m1=100,h1=24,zi=new Map,p1=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},Sd=t=>Number.isFinite(t)?Math.min(f1,Math.max(u1,Math.round(t))):nm,g1=t=>{const e=t?.parentElement?.clientWidth;return!e||e<=0?null:e},x1=(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},rm=(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"),b1=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},y1=(t,e,n)=>{if(t.mode==="chat"){const r=ll(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"?Ul(t.targetPath??"")||t.label||n("contextPanel.mode.browser"):t.label?t.label:t.mode==="file"?b1(t.targetPath)||n("contextPanel.mode.files"):t.mode==="diff"?n("contextPanel.mode.diff"):rm(t.mode,n)},jd=(t,e={})=>{if(t.mode==="file")return t.targetPath?s.jsx(kl,{filePath:t.targetPath,className:"h-3.5 w-3.5"}):void 0;if(t.mode==="diff")return s.jsx(wf,{className:"h-3.5 w-3.5"});if(t.mode==="walkthrough")return s.jsx(I,{name:"route",className:"h-3.5 w-3.5"});if(t.mode==="git")return s.jsx(I,{name:"git-branch",className:"h-3.5 w-3.5"});if(t.mode==="pr")return s.jsx(I,{name:"github",className:"h-3.5 w-3.5"});if(t.mode==="notes")return s.jsx(I,{name:"sticky-note",className:"h-3.5 w-3.5"});if(t.mode==="terminal")return s.jsx(I,{name:"terminal-box",className:"h-3.5 w-3.5"});if(t.mode==="plan")return s.jsx(I,{name:"file-text",className:"h-3.5 w-3.5"});if(t.mode==="context")return s.jsx(I,{name:"donut-chart-fill",className:"h-3.5 w-3.5"});if(t.mode==="chat")return s.jsx(I,{name:"chat-4",className:"h-3.5 w-3.5"});if(t.mode==="browser"){const n=v1(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(I,{name:"global",className:"h-3.5 w-3.5"})}},v1=(t,e)=>{try{return e[new URL(t).origin]??""}catch{return""}},w1=200,S1=480,j1=({visible:t})=>{const{t:e}=gt(),n=he(h=>h.contextEditorTreeWidth),r=he(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(S1,Math.max(w1,Math.round(h))),[]),p=l.useCallback(h=>{const S=m.current;S&&(S.style.width=`${h}px`,S.style.setProperty("--oc-editor-tree-width",`${h}px`))},[]),b=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()}},k=h=>{if(!o||u.current!==h.pointerId)return;const S=c.current-h.clientX,y=f(a.current+S);d.current!==y&&(d.current=y,p(y))},v=h=>{if(u.current!==h.pointerId)return;try{h.currentTarget.releasePointerCapture(h.pointerId)}catch{}const S=f(d.current??n);u.current=null,d.current=null,i(!1),r(S)},g=t?n:0;return s.jsxs("div",{ref:m,className:xe("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??g:g}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:xe("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:b,onPointerMove:k,onPointerUp:v,onPointerCancel:v,role:"separator","aria-orientation":"vertical","aria-label":e("contextPanel.actions.resizePanelAria")}),s.jsx("div",{className:xe("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($y,{})})]})},ll=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,k1=(t,e)=>{if(t.size!==e.size)return!1;for(const[n,r]of t)if(e.get(n)!==r)return!1;return!0},C1=(t,e)=>{if(e.length===0)return zi;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?zi:r},N1=(t,e)=>{const n=vl(t),r=l.useRef(zi),o=l.useRef(e);return o.current=e,l.useSyncExternalStore(n.subscribe,l.useCallback(()=>{const i=C1(n.getState().session,o.current);return k1(r.current,i)?r.current:(r.current=i,i)},[n]),()=>zi)},A1=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,D1=()=>{const{t}=gt(),e=Lo()??"",n=l.useMemo(()=>p1(e),[e]),r=he(ne=>n?ne.contextPanelByDirectory[n]:void 0),o=he(ne=>ne.closeContextPanel),i=he(ne=>ne.closeContextPanelTab),c=he(ne=>ne.openContextPanelTab),a=he(ne=>ne.toggleContextPanelExpanded),d=he(ne=>ne.setContextPanelWidth),u=he(ne=>ne.setActiveContextPanelTab),m=he(ne=>ne.openContextBrowser);l.useEffect(()=>{if(e)return Jv(ne=>m(e,ne))},[e,m]);const f=he(ne=>ne.reorderContextPanelTabs),p=Ln(ne=>ne.setSelectedPath),b=he(ne=>ne.contextEditorTreeVisible),k=he(ne=>ne.toggleContextEditorTree),v=he(ne=>ne.openNewContextBrowserTab),g=$f(ne=>ne.byOrigin),h=he(ne=>ne.allowPromptingSubagentSessions),{themeMode:S,setThemeMode:y,lightThemeId:j,darkThemeId:C,currentTheme:N}=Br(),w=l.useMemo(()=>r?.tabs??[],[r?.tabs]),A=w.find(ne=>ne.id===r?.activeTabId)??w[w.length-1]??null,D=!!(r?.isOpen&&A),P=!!(D&&r?.expanded),[B,F]=l.useState(null),E=A?.mode??null,_=E?r?.widthByMode?.[E]:void 0,L=E?Zh(E):.5,W=B??(typeof window<"u"?window.innerWidth:nm*2),K=Sd(_??Math.round(L*W)),x=l.useMemo(()=>{const ne=[];for(const ke of w){if(ke.mode!=="chat")continue;const Ze=ll(ke.dedupeKey);Ze&&!ne.includes(Ze)&&ne.push(Ze)}return ne},[w]),M=N1(n||void 0,x),[z,U]=l.useState(!1),V=l.useRef(0),Z=l.useRef(K),X=l.useRef(null),le=l.useRef(null),te=l.useRef(null),fe=l.useRef(new Map),ge=l.useRef(new Map),H=l.useRef(!1);l.useLayoutEffect(()=>{const ne=te.current?.parentElement;if(!ne||typeof ResizeObserver>"u")return;const ke=new ResizeObserver(()=>{F(ne.clientWidth||null)});return ke.observe(ne),F(ne.clientWidth||null),()=>ke.disconnect()},[]),l.useEffect(()=>{if(!D||H.current){H.current=D;return}const ne=window.requestAnimationFrame(()=>{te.current?.focus({preventScroll:!0})});return H.current=!0,()=>window.cancelAnimationFrame(ne)},[D]);const Se=l.useRef(null),ae=l.useRef(null),q=l.useCallback(()=>{ae.current=null;const ne=te.current,ke=X.current;!ne||ke===null||ne.style.setProperty("--oc-context-panel-width",`${ke}px`)},[]);l.useEffect(()=>()=>{ae.current!==null&&clearTimeout(ae.current)},[]);const me=l.useCallback(ne=>{const ke=Sd(ne),Ze=Se.current;return Ze===null?ke:Math.min(ke,Math.max(1,Ze))},[]),pe=l.useCallback(ne=>{!D||P||!n||(le.current=ne.pointerId,U(!0),V.current=ne.clientX,Z.current=K,X.current=K,Se.current=g1(te.current),document.documentElement.style.cursor="col-resize",ne.preventDefault())},[n,P,D,K]),Ie=l.useCallback(()=>{const ne=me(X.current??K);X.current=null,Se.current=null,ae.current!==null&&(clearTimeout(ae.current),ae.current=null),document.documentElement.style.cursor="",n&&E&&d(n,E,ne),U(!1),le.current=null},[E,me,n,d,K]);l.useEffect(()=>{if(!z)return;const ne=Q=>{if(le.current!==Q.pointerId)return;const ye=V.current-Q.clientX,Qe=me(Z.current+ye);X.current!==Qe&&(X.current=Qe,ae.current===null&&(ae.current=setTimeout(q,m1)))},ke=Q=>{le.current===Q.pointerId&&Ie()},Ze=()=>{Ie()};return window.addEventListener("pointermove",ne),window.addEventListener("pointerup",ke),window.addEventListener("pointercancel",ke),window.addEventListener("blur",Ze),()=>{window.removeEventListener("pointermove",ne),window.removeEventListener("pointerup",ke),window.removeEventListener("pointercancel",ke),window.removeEventListener("blur",Ze)}},[q,me,Ie,z]),l.useEffect(()=>{z||(X.current=null,document.documentElement.style.cursor="")},[z]);const Oe=l.useCallback(()=>{n&&o(n)},[o,n]),Me=l.useCallback(()=>{n&&a(n)},[n,a]),Fe=l.useCallback(ne=>{ne.key==="Escape"&&(ep(ne.target)||(ne.preventDefault(),ne.stopPropagation(),Oe()))},[Oe]);l.useEffect(()=>{if(!(!n||!A)&&A.mode==="file"&&A.targetPath){p(n,A.targetPath,{allowOutsideRoot:!0});return}},[A,n,p]);const je=l.useMemo(()=>w.filter(ne=>ne.mode==="chat"),[w]),Ne=D&&A?.mode==="chat"?A.id:null,Pe=D&&A?.mode==="chat"?ll(A.dedupeKey):null,se=yx(je,Ne);l.useEffect(()=>{if(!D||!n||!Pe||typeof window>"u")return;const ne=()=>{if(document.visibilityState==="hidden"||!document.hasFocus()){va(n,Pe,!1);return}Lu(Pe),va(n,Pe,!0)};ne();const ke=window.setInterval(ne,1e4);return window.addEventListener("focus",ne),window.addEventListener("blur",ne),document.addEventListener("visibilitychange",ne),()=>{window.clearInterval(ke),window.removeEventListener("focus",ne),window.removeEventListener("blur",ne),document.removeEventListener("visibilitychange",ne),va(n,Pe,!1)}},[Pe,n,D]);const oe=l.useCallback((ne,ke,Ze)=>vx(ge.current,ne,ke,n||null,Ze,{mode:S,lightThemeId:j,darkThemeId:C,currentTheme:N},{allowPromptingSubagentSessions:h}),[h,N,C,n,j,S]),Ee=se&&Pe?oe(se.id,Pe,se.readOnly):null;l.useEffect(()=>{const ne=new Set(w.map(ke=>ke.id));for(const ke of ge.current.keys())ne.has(ke)||ge.current.delete(ke)},[w]);const J=l.useCallback(ne=>{!n||A?.mode!=="diff"||c(n,{mode:"diff",targetPath:A.targetPath,stagedDiff:ne==="staged",diffScope:ne})},[A,n,c]),re=l.useCallback(()=>{if(typeof window>"u")return;const ne={themeMode:S,lightThemeId:j,darkThemeId:C,currentTheme:N};for(const ke of fe.current.values()){const Ze=ke.contentWindow;Ze&&Ze.postMessage({type:"openchamber:theme-sync",payload:ne},window.location.origin)}},[N,C,j,S]),ee=l.useCallback(()=>{if(typeof window>"u")return;const ne={allowPromptingSubagentSessions:h};for(const ke of fe.current.values()){const Ze=ke.contentWindow;Ze&&Ze.postMessage({type:"openchamber:chat-settings-sync",payload:ne},window.location.origin)}},[h]),$=l.useCallback((ne,ke,Ze)=>{const Q=ke.contentWindow;Q&&Q.postMessage({type:bf,payload:{visible:Ne===ne}},Ze)},[Ne]),de=l.useCallback(()=>{if(!(typeof window>"u"))for(const[ne,ke]of fe.current.entries())$(ne,ke,window.location.origin)},[$]);l.useEffect(()=>{if(typeof window>"u")return;const ne=ke=>{if(ke.origin!==window.location.origin)return;const Ze=Array.from(fe.current.entries()).find(([,ze])=>ze.contentWindow===ke.source);if(!Ze)return;const Q=ke.data;if(Q?.type===wx){const[ze,Le]=Ze;$(ze,Le,ke.origin);return}if(Q?.type===Sx){if(typeof Q.requestId!="string"||!Q.requestId)return;const ze=Ms(),Le={apiBaseUrl:pr(),clientToken:Eo(),localOrigin:typeof window.__OPENCHAMBER_LOCAL_ORIGIN__=="string"?window.__OPENCHAMBER_LOCAL_ORIGIN__:"",runtimeHeaders:Su(),relayHostId:ze.startsWith("host:")?ze.slice(5):"",relay:rh()??void 0};ke.source?.postMessage({type:jx,requestId:Q.requestId,payload:Le},ke.origin);return}if(Q?.type==="openchamber:theme-sync-request"){re();return}if(Q?.type==="openchamber:chat-settings-request"){ee();return}if(Q?.type!=="openchamber:cycle-theme-request")return;const ye=["light","dark","system"],$e=(ye.indexOf(S)+1)%ye.length;y(ye[$e])};return window.addEventListener("message",ne),()=>window.removeEventListener("message",ne)},[ee,$,re,y,S]),l.useLayoutEffect(()=>{w.some(ke=>ke.mode==="chat")&&(re(),ee(),de())},[C,j,ee,de,re,w,S]);const Y=A?.mode==="file"||A?.mode==="chat"||A?.mode==="browser",ue=l.useMemo(()=>A?w.filter(ne=>ne.mode===A.mode):[],[A,w]),Te=l.useMemo(()=>ue.map(ne=>{const ke=y1(ne,M,t),Ze=A1(ke,h1),Q=x1(ne.targetPath,e);return{id:ne.id,label:Ze,icon:jd(ne,g),title:Q?`${ke}: ${Q}`:ke,closeLabel:t("contextPanel.tab.closeTabAria",{label:Ze})}}),[ue,e,g,M,t]),Ge=A?.mode==="context"?s.jsx(nv,{}):A?.mode==="git"?s.jsx(l.Suspense,{fallback:null,children:s.jsx(c1,{isActive:D})}):A?.mode==="pr"?s.jsx(fy,{}):A?.mode==="notes"?s.jsx(ff,{}):A?.mode==="plan"?s.jsx(l.Suspense,{fallback:null,children:s.jsx(d1,{targetPath:A.targetPath,projectPlanId:A.projectPlanId})}):null,_e=l.useMemo(()=>w.filter(ne=>ne.mode==="browser"),[w]),ie=l.useMemo(()=>w.filter(ne=>ne.mode==="diff"),[w]),Re=l.useMemo(()=>w.some(ne=>ne.mode==="terminal"),[w]),be=l.useMemo(()=>w.some(ne=>ne.mode==="walkthrough"),[w]),T=l.useMemo(()=>w.some(ne=>ne.mode==="file"),[w]),ce=l.useMemo(()=>w.some(ne=>ne.mode==="file"&&ne.targetPath),[w]),ve=A?.mode==="file",Ce=s.jsxs("header",{className:"flex h-10 items-stretch border-b border-border",children:[Y?s.jsx(Il,{items:Te,activeId:A?.id??null,onSelect:ne=>{n&&u(n,ne)},onClose:ne=>{n&&i(n,ne)},onReorder:(ne,ke)=>{n&&f(n,ne,ke)},layoutMode:"scrollable",variant:"default"}):s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 px-3",children:[A?jd(A,g):null,s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:A?rm(A.mode,t):null})]}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[A?.mode==="browser"?s.jsx(lt,{type:"button",variant:"ghost",size:"sm",onClick:()=>{n&&v(n)},className:"h-7 w-7 p-0",title:t("contextPanel.browser.newTab"),"aria-label":t("contextPanel.browser.newTab"),children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})}):null,ve?s.jsx(lt,{type:"button",variant:"ghost",size:"sm",onClick:k,className:"h-7 w-7 p-0",title:t("contextRail.editorTree.toggle"),"aria-label":t("contextRail.editorTree.toggle"),"aria-pressed":b,children:s.jsx(I,{name:"layout-right",className:"h-3.5 w-3.5"})}):null,s.jsx(lt,{type:"button",variant:"ghost",size:"sm",onClick:Me,className:"h-7 w-7 p-0",title:t(P?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),"aria-label":t(P?"contextPanel.actions.collapsePanel":"contextPanel.actions.expandPanel"),children:P?s.jsx(I,{name:"fullscreen-exit",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"fullscreen",className:"h-3.5 w-3.5"})}),s.jsx(lt,{type:"button",variant:"ghost",size:"sm",onClick:Oe,className:"h-7 w-7 p-0",title:t("contextPanel.actions.closePanel"),"aria-label":t("contextPanel.actions.closePanel"),children:s.jsx(I,{name:"close",className:"h-3.5 w-3.5"})})]})]}),Ae=D?P?{"--oc-context-panel-width":B!==null?`${B}px`:"100%",width:B!==null?`${B}px`:"100%",maxWidth:"100%"}:{width:"min(var(--oc-context-panel-width), 100%)",maxWidth:"100%",overflowX:"clip","--oc-context-panel-width":`${K}px`}:{"--oc-context-panel-width":`${K}px`,width:0,maxWidth:"100%",overflowX:"clip"};return s.jsxs("aside",{ref:te,"data-context-panel":"true",tabIndex:-1,inert:!D||void 0,className:xe("flex min-h-0 flex-col overflow-hidden bg-background",P?"absolute inset-y-0 right-0 z-20 min-w-0":"relative h-full flex-shrink-0",!D&&"pointer-events-none","will-change-[width] motion-reduce:transition-none","transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]"),onKeyDownCapture:Fe,style:Ae,children:[D&&!P&&s.jsx("div",{"aria-hidden":"true",className:"absolute left-0 top-0 z-40 h-full w-px bg-border"}),D&&s.jsx("div",{"aria-hidden":"true",className:"absolute right-0 top-0 z-40 h-full w-px bg-border"}),!P&&s.jsx("div",{className:xe("absolute left-0 top-0 z-50 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",z&&"bg-[var(--interactive-border)]"),onPointerDown:pe,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),s.jsxs("div",{className:xe("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]",!D&&"pointer-events-none select-none opacity-0"),style:{width:P?B!==null?`${B}px`:"100%":"var(--oc-context-panel-width)"},"aria-hidden":!D,children:[Ce,s.jsxs("div",{className:xe("relative min-h-0 flex-1 overflow-hidden",z&&"pointer-events-none"),children:[T?s.jsxs("div",{className:xe("absolute inset-0 flex",ve?"flex":"hidden"),children:[s.jsx("div",{className:"h-full min-w-0 flex-1",children:ce?s.jsx(l.Suspense,{fallback:null,children:s.jsx(l1,{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(I,{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(j1,{visible:b})]}):null,se&&Pe&&Ee?s.jsx("iframe",{ref:ne=>{if(!ne){fe.current.delete(se.id);return}fe.current.set(se.id,ne)},src:Ee,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:Pe}),className:"absolute inset-0 h-full w-full border-0 bg-background",onLoad:()=>{re(),ee(),de()}},se.id):null,_e.map(ne=>s.jsx("div",{className:xe("absolute inset-0",A?.id!==ne.id&&"hidden"),children:s.jsx(t1,{initialUrl:ne.targetPath??"",directory:n,tabID:ne.id})},ne.id)),ie.map(ne=>s.jsx("div",{className:xe("absolute inset-0",A?.id!==ne.id&&"hidden"),children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(a1,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:ne.diffScope??(ne.stagedDiff?"staged":"working"),onDiffScopeChange:J,targetFilePath:ne.targetPath,flushContent:!0})})},ne.id)),Re?s.jsx("div",{className:xe("absolute inset-0",A?.mode==="terminal"?"block":"hidden"),children:s.jsx(mf,{visible:D&&A?.mode==="terminal"})}):null,be?s.jsx("div",{className:xe("absolute inset-0",A?.mode==="walkthrough"?"block":"hidden"),children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(i1,{directory:e})})}):null,A?.mode!=="chat"&&!ve&&A?.mode!=="browser"&&A?.mode!=="diff"&&A?.mode!=="terminal"&&A?.mode!=="walkthrough"?Ge:null]})]})]})},P1=150,E1=500,T1=[],I1=t=>t>99?"99+":String(t),M1=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:p}=t;let b;e[0]!==n.id?(b={id:n.id},e[0]=n.id,e[1]=b):b=e[1];const{attributes:k,listeners:v,setNodeRef:g,transform:h,transition:S,isDragging:y}=Rl(b);let j;e[2]!==a?(j=a!=null&&a>0?I1(a):null,e[2]=a,e[3]=j):j=e[3];const C=j;let N;e[4]!==h?(N=Ol.Translate.toString(h),e[4]=h,e[5]=N):N=e[5];let w;e[6]!==N||e[7]!==S?(w={transform:N,transition:S},e[6]=N,e[7]=S,e[8]=w):w=e[8];const A=y&&"z-10 opacity-70";let D;e[9]!==A?(D=xe("relative",A),e[9]=A,e[10]=D):D=e[10];let P;e[11]!==p||e[12]!==n?(P=()=>p(n),e[11]=p,e[12]=n,e[13]=P):P=e[13];const B=d??i,F=r?"text-primary":"text-muted-foreground hover:text-foreground";let E;e[14]!==F?(E=xe("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 _;e[16]!==n.icon||e[17]!==n.id?(_=n.id==="diff"?s.jsx(wf,{}):s.jsx(I,{name:n.icon,className:"h-[18px] w-[18px]"}),e[16]=n.icon,e[17]=n.id,e[18]=_):_=e[18];let L;e[19]!==C||e[20]!==m||e[21]!==o||e[22]!==f?(L=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}):C?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:C}):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]=C,e[20]=m,e[21]=o,e[22]=f,e[23]=L):L=e[23];let W;e[24]!==k||e[25]!==r||e[26]!==v||e[27]!==E||e[28]!==_||e[29]!==L||e[30]!==P||e[31]!==B?(W=s.jsx(mt,{asChild:!0,children:s.jsxs("button",{type:"button",...k,...v,onClick:P,"aria-label":B,"aria-pressed":r,className:E,children:[_,L]})}),e[24]=k,e[25]=r,e[26]=v,e[27]=E,e[28]=_,e[29]=L,e[30]=P,e[31]=B,e[32]=W):W=e[32];let K;e[33]!==i?(K=s.jsx("span",{children:i}),e[33]=i,e[34]=K):K=e[34];let x;e[35]!==c?(x=s.jsx("span",{className:"typography-micro text-muted-foreground",children:c}),e[35]=c,e[36]=x):x=e[36];let M;e[37]!==u?(M=u?s.jsx("span",{className:"typography-micro text-muted-foreground",children:u}):null,e[37]=u,e[38]=M):M=e[38];let z;e[39]!==K||e[40]!==x||e[41]!==M?(z=s.jsx(ht,{side:"left",sideOffset:8,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[K,x,M]})}),e[39]=K,e[40]=x,e[41]=M,e[42]=z):z=e[42];let U;e[43]!==W||e[44]!==z?(U=s.jsxs(ft,{delayDuration:P1,children:[W,z]}),e[43]=W,e[44]=z,e[45]=U):U=e[45];let V;return e[46]!==g||e[47]!==U||e[48]!==w||e[49]!==D?(V=s.jsx("div",{ref:g,style:w,className:D,children:U}),e[46]=g,e[47]=U,e[48]=w,e[49]=D,e[50]=V):V=e[50],V},R1=()=>{const t=it.c(52),{t:e}=gt(),n=Lo();let r;t[0]!==n?(r=n?qr(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=he(i),a=he(O1),d=he(F1),u=he(B1),m=he(L1),f=he(_1),p=wl($1),{screenWidth:b}=br(),k=Sl(o||null);let v;t[4]!==f?(v=tp("switch_context_surface",f),t[4]=f,t[5]=v):v=t[5];const g=v,[h,S]=l.useState(!1);let y,j;t[6]!==g?(y=()=>{const Z=new Set;let X=null,le=!1;const te=z1,fe=()=>{xc(g,Z)?!le&&X===null&&(X=setTimeout(()=>S(!0),E1)):(le=!1,X!==null&&(clearTimeout(X),X=null),S(!1))},ge=ae=>{if(Z.add(ae.key.toLowerCase()),te(ae.key)&&xc(g,Z)){le=!0,X!==null&&(clearTimeout(X),X=null),S(!1);return}fe()},H=ae=>{Z.delete(ae.key.toLowerCase()),fe()},Se=()=>{Z.clear(),le=!1,X!==null&&(clearTimeout(X),X=null),S(!1)};return window.addEventListener("keydown",ge,!0),window.addEventListener("keyup",H,!0),window.addEventListener("blur",Se),()=>{window.removeEventListener("keydown",ge,!0),window.removeEventListener("keyup",H,!0),window.removeEventListener("blur",Se),X!==null&&clearTimeout(X)}},j=[g],t[6]=g,t[7]=y,t[8]=j):(y=t[7],j=t[8]),l.useEffect(y,j);let C;t[9]===Symbol.for("react.memo_cache_sentinel")?(C={activationConstraint:{distance:8}},t[9]=C):C=t[9];let N;t[10]===Symbol.for("react.memo_cache_sentinel")?(N={activationConstraint:{delay:200,tolerance:6}},t[10]=N):N=t[10];const w=Mi(eo(Ax,C),eo(Nx,N)),A=c?.tabs??T1;let D;t[11]!==c?.activeTabId||t[12]!==A?(D=A.find(Z=>Z.id===c?.activeTabId)??null,t[11]=c?.activeTabId,t[12]=A,t[13]=D):D=t[13];const P=D,B=c?.isOpen?P?.mode??null:null,F=k?.files.length??0;let E;t[14]!==d||t[15]!==p||t[16]!==b||t[17]!==A?(E=sp({railOrder:d,planModeEnabled:p,isVSCode:sr(),screenWidth:b,tabs:A}),t[14]=d,t[15]=p,t[16]=b,t[17]=A,t[18]=E):E=t[18];const _=E;let L;t[19]!==u?(L=Z=>{const{active:X,over:le}=Z;if(!le||X.id===le.id)return;const te=np(he.getState().contextRailOrder).map(U1),fe=te.indexOf(X.id),ge=te.indexOf(le.id);fe===-1||ge===-1||u(yf(te,fe,ge))},t[19]=u,t[20]=L):L=t[20];const W=L;if(!o)return null;let K;t[21]!==e?(K=e("contextRail.aria.rail"),t[21]=e,t[22]=K):K=t[22];let x;t[23]!==_?(x=_.map(W1),t[23]=_,t[24]=x):x=t[24];let M;if(t[25]!==B||t[26]!==F||t[27]!==o||t[28]!==m||t[29]!==h||t[30]!==_||t[31]!==e||t[32]!==a){let Z;t[34]!==B||t[35]!==F||t[36]!==o||t[37]!==m||t[38]!==h||t[39]!==e||t[40]!==a?(Z=(X,le)=>{const te=e(X.labelKey),fe=X.id==="git"&&!a?F:0,ge=fe>0?fe:null;return s.jsx(M1,{surface:X,isActive:B===X.mode,showActivityDot:!1,label:te,description:e(X.descriptionKey),badgeCount:ge,badgeAriaLabel:ge!==null?e(ge===1?"contextRail.surface.git.changesCountAriaSingle":"contextRail.surface.git.changesCountAriaPlural",{label:te,count:ge}):null,badgeDescription:ge!==null?e(ge===1?"contextRail.surface.git.changesCountTooltipSingle":"contextRail.surface.git.changesCountTooltipPlural",{count:ge}):null,orderNumber:le+1,showOrderNumber:h,onSelect:H=>m(o,H.mode)},X.id)},t[34]=B,t[35]=F,t[36]=o,t[37]=m,t[38]=h,t[39]=e,t[40]=a,t[41]=Z):Z=t[41],M=_.map(Z),t[25]=B,t[26]=F,t[27]=o,t[28]=m,t[29]=h,t[30]=_,t[31]=e,t[32]=a,t[33]=M}else M=t[33];let z;t[42]!==x||t[43]!==M?(z=s.jsx(Za,{items:x,strategy:el,children:M}),t[42]=x,t[43]=M,t[44]=z):z=t[44];let U;t[45]!==W||t[46]!==w||t[47]!==z?(U=s.jsx(Ri,{sensors:w,collisionDetection:Oi,onDragEnd:W,children:z}),t[45]=W,t[46]=w,t[47]=z,t[48]=U):U=t[48];let V;return t[49]!==K||t[50]!==U?(V=s.jsx("nav",{"aria-label":K,className:"flex h-full w-11 flex-shrink-0 flex-col items-center gap-1 bg-background py-2",children:U}),t[49]=K,t[50]=U,t[51]=V):V=t[51],V};function O1(t){return t.workStatusPanelVisible}function F1(t){return t.contextRailOrder}function B1(t){return t.setContextRailOrder}function L1(t){return t.openContextSurface}function _1(t){return t.shortcutOverrides}function $1(t){return t.planModeEnabled}function z1(t){return t.length===1&&t>="0"&&t<="9"}function U1(t){return t.id}function W1(t){return t.id}const V1=(t,e)=>!t||e.length===0?"":JSON.stringify([t,e]),H1=(t,e,n,r)=>!n||r!==n||t.length===0?[]:jo(t,e,o=>o.name,{limit:10,threshold:.4}),K1=new Set,G1=[],cl=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},q1=()=>{const t=it.c(178),{t:e}=gt(),n=he(Y1),r=he(Q1),o=he(X1),i=he(J1),c=he(Z1),a=he(eS),d=he(tS),u=he(sS),m=he(nS),f=he(rS),p=he(oS),b=nt(iS),k=nt(aS);let v;t[0]!==n?(v=Ke=>n?Ke.activeSessions:G1,t[0]=n,t[1]=v):v=t[1];const g=Is(v);let h;t[2]!==n?(h=Ke=>n?Ke.ids:K1,t[2]=n,t[3]=h):h=t[3];const S=To(h);let y;t[4]!==n?(y=Ke=>n?Ke.rankById:Nl,t[4]=n,t[5]=y):y=t[5];const j=Zi(y),C=as(lS),N=Jt(cS),w=Jt(dS),A=Lo(),D=vu(uS),{files:P,git:B}=nr(),F=gr(fS),{isMobile:E}=br();let _;t[6]!==A?(_=A?cl(A):null,t[6]=A,t[7]=_):_=t[7];const L=_,[W,K]=l.useState(""),M=Cl(W,200).trim();let z;t[8]!==W?(z=W.trim(),t[8]=W,t[9]=z):z=t[9];const U=z;let V,Z;t[10]!==n?(V=()=>{n&&K("")},Z=[n],t[10]=n,t[11]=V,t[12]=Z):(V=t[11],Z=t[12]),l.useEffect(V,Z);let X,le;t[13]!==g||t[14]!==F||t[15]!==B||t[16]!==n?(X=()=>{if(!n||!B)return;const Ke=setTimeout(()=>{const Ue=new Set;for(const xt of g){const Ft=Zs(xt);!Ft||Ue.has(Ft)||(Ue.add(Ft),F(Ft,B))}},0);return()=>clearTimeout(Ke)},le=[n,g,B,F],t[13]=g,t[14]=F,t[15]=B,t[16]=n,t[17]=X,t[18]=le):(X=t[17],le=t[18]),l.useEffect(X,le);let te;t[19]!==r?(te=()=>r(!1),t[19]=r,t[20]=te):te=t[20];const fe=te;let ge;t[21]!==fe?(ge=Ke=>()=>{fe(),Ke()},t[21]=fe,t[22]=ge):ge=t[22];const H=ge;let Se;t[23]!==N?.id||t[24]!==N?.path||t[25]!==C||t[26]!==E||t[27]!==u||t[28]!==m||t[29]!==b||t[30]!==H||t[31]!==o||t[32]!==a||t[33]!==i||t[34]!==e||t[35]!==d?(Se=()=>{const Ke=[{id:"new-session",title:e("commandPalette.item.newSession"),icon:s.jsx(I,{name:"add",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat",searchText:e("commandPalette.item.newSession"),onSelect:H(()=>{o("chat"),a(!1),b()})},{id:"new-worktree",title:e("commandPalette.item.newWorktreeDraft"),icon:s.jsx(I,{name:"git-branch",className:"mr-2 h-4 w-4"}),shortcutId:"new_chat_worktree",searchText:e("commandPalette.item.newWorktreeDraft"),onSelect:H(mS)},{id:"add-project",title:e("commandPalette.item.addProject"),icon:s.jsx(I,{name:"folder-add",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.addProject"),onSelect:H(hS)},{id:"toggle-sidebar",title:e(E?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),icon:s.jsx(I,{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:Ue}=he.getState();a(!Ue)}else d()})},{id:"toggle-terminal",title:e("commandPalette.item.toggleTerminal"),icon:s.jsx(I,{name:"terminal-box",className:"mr-2 h-4 w-4"}),shortcutId:"toggle_terminal",searchText:e("commandPalette.item.toggleTerminal"),onSelect:H(()=>{C&&m(C,"terminal")})},{id:"context-usage",title:e("commandPalette.item.showContextUsage"),icon:s.jsx(I,{name:"pie-chart",className:"mr-2 h-4 w-4"}),searchText:e("commandPalette.item.showContextUsage"),onSelect:H(()=>{C&&u(C)})},{id:"open-settings",title:e("commandPalette.item.openSettings"),icon:s.jsx(I,{name:"settings-3",className:"mr-2 h-4 w-4"}),shortcutId:"open_settings",searchText:e("commandPalette.item.openSettings"),onSelect:H(()=>i(!0))}];return Hi()&&Ke.splice(1,0,{id:"new-mini-chat",title:e("commandPalette.item.newMiniChat"),icon:s.jsx(I,{name:"window",className:"mr-2 h-4 w-4"}),shortcutId:"new_mini_chat",searchText:e("commandPalette.item.newMiniChat"),onSelect:H(()=>{hr("desktop_open_draft_mini_chat_window",{directory:cl(C||N?.path||""),projectId:N?.id??null}).catch(pS)})}),Ke},t[23]=N?.id,t[24]=N?.path,t[25]=C,t[26]=E,t[27]=u,t[28]=m,t[29]=b,t[30]=H,t[31]=o,t[32]=a,t[33]=i,t[34]=e,t[35]=d,t[36]=Se):Se=t[36],N?.id,N?.path;let ae;t[37]!==Se?(ae=Se(),t[37]=Se,t[38]=ae):ae=t[38];const q=ae;let me;t[39]===Symbol.for("react.memo_cache_sentinel")?(me=Wn(),t[39]=me):me=t[39];const pe=me;let Ie,Oe;t[40]===Symbol.for("react.memo_cache_sentinel")?(Ie=sr(),Oe=!pe&&bl(),t[40]=Ie,t[41]=Oe):(Ie=t[40],Oe=t[41]);let Me;t[42]!==E?(Me={isVSCode:Ie,isWeb:Oe,isDesktop:pe,isMobile:E},t[42]=E,t[43]=Me):Me=t[43];const Fe=Me;let je;if(t[44]!==H||t[45]!==i||t[46]!==c||t[47]!==Fe){let Ke;t[49]!==Fe?(Ke=xt=>xt.isAvailable?xt.isAvailable(Fe):!0,t[49]=Fe,t[50]=Ke):Ke=t[50];let Ue;t[51]!==H||t[52]!==i||t[53]!==c?(Ue=xt=>{const Ft=Qg(xt.slug)??"settings-3",$t=(xt.keywords??[]).join(" ");return{id:`settings:${xt.slug}`,title:xt.title,icon:xt.slug==="mcp"?s.jsx(Eu,{className:"mr-2 h-4 w-4"}):s.jsx(I,{name:Ft,className:"mr-2 h-4 w-4"}),searchText:`${xt.title} ${xt.group} ${$t}`,onSelect:H(()=>{c(xt.slug),i(!0)})}},t[51]=H,t[52]=i,t[53]=c,t[54]=Ue):Ue=t[54],je=Yg.filter(gS).filter(Ke).map(Ue),t[44]=H,t[45]=i,t[46]=c,t[47]=Fe,t[48]=je}else je=t[48];const Ne=je;let Pe;if(t[55]!==g||t[56]!==S||t[57]!==j){const Ke=g.filter(xS);Pe=_u(Ke,S,j),t[55]=g,t[56]=S,t[57]=j,t[58]=Pe}else Pe=t[58];const se=Pe,oe=$u(),Ee=nt(bS);let J;t[59]!==oe||t[60]!==Ee?(J=(Ke,Ue)=>{const xt=Ee.get(Ke);return xt?.branch?xt.branch.trim()||null:Ue&&oe.get(Ue)?.trim()||null},t[59]=oe,t[60]=Ee,t[61]=J):J=t[61];const re=J;let ee;t[62]===Symbol.for("react.memo_cache_sentinel")?(ee=[],t[62]=ee):ee=t[62];const[$,de]=l.useState(ee),[Y,ue]=l.useState(""),Te=V1(L,M);let Ge;t[63]!==L||t[64]!==Te||t[65]!==n||t[66]!==D||t[67]!==de||t[68]!==ue||t[69]!==M?(Ge=()=>{if(!n){de([]),ue("");return}if(!Te){de([]),ue("");return}if(!L){de([]),ue("");return}let Ke=!1;return D(L,M,10,{type:"file"}).then(Ue=>{Ke||(de(Ue.map(yS)),ue(Te))}).catch(()=>{Ke||(de([]),ue(Te))}),()=>{Ke=!0}},t[63]=L,t[64]=Te,t[65]=n,t[66]=D,t[67]=de,t[68]=ue,t[69]=M,t[70]=Ge):Ge=t[70];let _e;t[71]!==L||t[72]!==Te||t[73]!==n||t[74]!==D||t[75]!==M?(_e=[n,L,M,Te,D],t[71]=L,t[72]=Te,t[73]=n,t[74]=D,t[75]=M,t[76]=_e):_e=t[76],l.useEffect(Ge,_e);const ie=U.length>0;let Re;e:{if(!ie){let Ue;t[77]!==q?(Ue=q.map(vS),t[77]=q,t[78]=Ue):Ue=t[78],Re=Ue;break e}let Ke;t[79]!==q||t[80]!==U?(Ke=jo(q,U,wS,{limit:7,noFuzzy:!0}),t[79]=q,t[80]=U,t[81]=Ke):Ke=t[81],Re=Ke}const be=Re;let T;e:{if(!ie){let Ue;t[82]===Symbol.for("react.memo_cache_sentinel")?(Ue=[],t[82]=Ue):Ue=t[82],T=Ue;break e}let Ke;t[83]!==U||t[84]!==Ne?(Ke=jo(Ne,U,SS,{limit:7,noFuzzy:!0}),t[83]=U,t[84]=Ne,t[85]=Ke):Ke=t[85],T=Ke}const ce=T;let ve;e:{if(!ie){let Ue;t[86]!==se?(Ue=se.slice(0,5).map(jS),t[86]=se,t[87]=Ue):Ue=t[87],ve=Ue;break e}let Ke;t[88]!==U||t[89]!==se?(Ke=jo(se,U,kS,{limit:7,threshold:.2}),t[88]=U,t[89]=se,t[90]=Ke):Ke=t[90],ve=Ke}const Ce=ve;let Ae;e:{if(!n){let Ue;t[91]===Symbol.for("react.memo_cache_sentinel")?(Ue=[],t[91]=Ue):Ue=t[91],Ae=Ue;break e}let Ke;t[92]!==$||t[93]!==Y||t[94]!==Te||t[95]!==M?(Ke=H1($,M,Te,Y),t[92]=$,t[93]=Y,t[94]=Te,t[95]=M,t[96]=Ke):Ke=t[96],Ae=Ke}const ne=Ae,ke=n&&Te.length>0&&Y!==Te;let Ze;e:{if(!ie){let Ue;t[97]===Symbol.for("react.memo_cache_sentinel")?(Ue=[],t[97]=Ue):Ue=t[97],Ze=Ue;break e}let Ke;if(t[98]!==U||t[99]!==w){const Ue=w.map(CS);Ke=jo(Ue,U,NS,{limit:7,threshold:.4}),t[98]=U,t[99]=w,t[100]=Ke}else Ke=t[100];Ze=Ke}const Q=Ze;let ye,Qe,$e,ze,Le,st,ct,Pt,It,Tt,et,Mt,kt,bt;if(t[101]!==re||t[102]!==fe||t[103]!==L||t[104]!==P||t[105]!==ie||t[106]!==n||t[107]!==f||t[108]!==b||t[109]!==W||t[110]!==be||t[111]!==ne||t[112]!==Q||t[113]!==Ce||t[114]!==ce||t[115]!==r||t[116]!==k||t[117]!==p||t[118]!==e){const Ke=be.map(AS),Ue=ce.map(DS),xt=Ce.map(PS),Ft=ie?ne.map(ES):[],$t=ie?Q.map(TS):[];let ns;e:{if(!ie){ns=["commands","sessions"];break e}const Je=IS,He=[{key:"commands",score:Je(be)},{key:"settings",score:Je(ce)},{key:"sessions",score:Je(Ce)},{key:"files",score:Je(ne)},{key:"projects",score:Je(Q)}];He.sort(MS),ns=He.map(RS)}const Kt=ns,St=Je=>{fe(),k(Je.id,Zs(Je))},zt=async Je=>{if(!L)return;const He=await Bf(P,Je,{directory:L});if(!He.ok){De.error(Lf(He.reason));return}f(L,Je),fe()},ms=(Je,He)=>{fe(),b({selectedProjectId:Je,directoryOverride:He})},ts=Je=>Yi(Ir(Je,p));ze=$s,Mt=n,kt=r;let ys;t[133]!==e?(ys=e("commandPalette.title"),t[133]=e,t[134]=ys):ys=t[134];let Vt;t[135]!==ys?(Vt=s.jsx(fn,{children:ys}),t[135]=ys,t[136]=Vt):Vt=t[136];let Gt;t[137]!==e?(Gt=e("commandPalette.description"),t[137]=e,t[138]=Gt):Gt=t[138];let Ut;t[139]!==Gt?(Ut=s.jsx(mn,{children:Gt}),t[139]=Gt,t[140]=Ut):Ut=t[140],t[141]!==Vt||t[142]!==Ut?(bt=s.jsxs(An,{className:"sr-only",children:[Vt,Ut]}),t[141]=Vt,t[142]=Ut,t[143]=bt):bt=t[143],$e=zs,Tt="overflow-hidden p-0",et=!0,Qe=ip,ct=!1,Pt="[&_[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 Be;t[144]!==e?(Be=e("commandPalette.input.placeholder"),t[144]=e,t[145]=Be):Be=t[145],t[146]!==W||t[147]!==Be?(It=s.jsx(ap,{value:W,onValueChange:K,placeholder:Be}),t[146]=W,t[147]=Be,t[148]=It):It=t[148],ye=lp;let Xe;t[149]!==e?(Xe=e("commandPalette.empty.noResults"),t[149]=e,t[150]=Xe):Xe=t[150],t[151]!==Xe?(Le=s.jsx(cp,{children:Xe}),t[151]=Xe,t[152]=Le):Le=t[152],st=Kt.map(Je=>Je==="commands"&&Ke.length>0?s.jsx(xo,{children:Ke.map(He=>s.jsxs(ko,{value:He.id,onSelect:He.onSelect,children:[He.icon,s.jsx("span",{children:He.title}),He.shortcutId?s.jsx(rp,{children:ts(He.shortcutId)}):null]},He.id))},"commands"):Je==="settings"&&Ue.length>0?s.jsx(xo,{children:Ue.map(OS)},"settings"):Je==="sessions"&&xt.length>0?s.jsx(xo,{children:xt.map(He=>{const rt=He.title||e("commandPalette.session.untitled"),Dt=Zs(He),Wt=re(He.id,Dt);return s.jsxs(ko,{value:`session:${He.id}`,onSelect:()=>St(He),children:[s.jsx(I,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:rt}),Wt?s.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-muted-foreground typography-meta",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3"}),s.jsx("span",{className:"truncate max-w-[160px]",children:Wt})]}):null]},He.id)})},"sessions"):Je==="files"&&Ft.length>0?s.jsx(xo,{children:Ft.map(He=>{const rt=op(He.relativePath||He.name,{maxLength:80});return s.jsxs(ko,{value:`file:${He.path}`,onSelect:()=>{zt(He.path)},children:[s.jsx(kl,{filePath:He.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":He.relativePath,children:rt})]},`file:${He.path}`)})},"files"):Je==="projects"&&$t.length>0?s.jsx(xo,{children:$t.map(He=>{const rt=He.displayName;return s.jsxs(ko,{value:`project:${He.id}`,onSelect:()=>ms(He.id,He.path),children:[s.jsx(I,{name:"folder",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:rt}),s.jsx("span",{className:"ml-auto inline-flex items-center text-muted-foreground typography-meta truncate max-w-[160px]",children:He.path})]},`project:${He.id}`)})},"projects"):null),t[101]=re,t[102]=fe,t[103]=L,t[104]=P,t[105]=ie,t[106]=n,t[107]=f,t[108]=b,t[109]=W,t[110]=be,t[111]=ne,t[112]=Q,t[113]=Ce,t[114]=ce,t[115]=r,t[116]=k,t[117]=p,t[118]=e,t[119]=ye,t[120]=Qe,t[121]=$e,t[122]=ze,t[123]=Le,t[124]=st,t[125]=ct,t[126]=Pt,t[127]=It,t[128]=Tt,t[129]=et,t[130]=Mt,t[131]=kt,t[132]=bt}else ye=t[119],Qe=t[120],$e=t[121],ze=t[122],Le=t[123],st=t[124],ct=t[125],Pt=t[126],It=t[127],Tt=t[128],et=t[129],Mt=t[130],kt=t[131],bt=t[132];let Bt;t[153]!==ke||t[154]!==e?(Bt=ke?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[153]=ke,t[154]=e,t[155]=Bt):Bt=t[155];let wt;t[156]!==ye||t[157]!==Le||t[158]!==st||t[159]!==Bt?(wt=s.jsxs(ye,{children:[Le,st,Bt]}),t[156]=ye,t[157]=Le,t[158]=st,t[159]=Bt,t[160]=wt):wt=t[160];let Rt;t[161]!==Qe||t[162]!==ct||t[163]!==Pt||t[164]!==It||t[165]!==wt?(Rt=s.jsxs(Qe,{shouldFilter:ct,className:Pt,children:[It,wt]}),t[161]=Qe,t[162]=ct,t[163]=Pt,t[164]=It,t[165]=wt,t[166]=Rt):Rt=t[166];let pt;t[167]!==$e||t[168]!==Tt||t[169]!==et||t[170]!==Rt?(pt=s.jsx($e,{className:Tt,showCloseButton:et,children:Rt}),t[167]=$e,t[168]=Tt,t[169]=et,t[170]=Rt,t[171]=pt):pt=t[171];let yt;return t[172]!==ze||t[173]!==Mt||t[174]!==kt||t[175]!==bt||t[176]!==pt?(yt=s.jsxs(ze,{open:Mt,onOpenChange:kt,children:[bt,pt]}),t[172]=ze,t[173]=Mt,t[174]=kt,t[175]=bt,t[176]=pt,t[177]=yt):yt=t[177],yt};function Y1(t){return t.isCommandPaletteOpen}function Q1(t){return t.setCommandPaletteOpen}function X1(t){return t.setActiveMainTab}function J1(t){return t.setSettingsDialogOpen}function Z1(t){return t.setSettingsPage}function eS(t){return t.setSessionSwitcherOpen}function tS(t){return t.toggleSidebar}function sS(t){return t.openContextOverview}function nS(t){return t.openContextSurface}function rS(t){return t.openContextFile}function oS(t){return t.shortcutOverrides}function iS(t){return t.openNewSessionDraft}function aS(t){return t.setCurrentSession}function lS(t){return t.currentDirectory}function cS(t){return t.getActiveProject()}function dS(t){return t.projects}function uS(t){return t.searchFiles}function fS(t){return t.ensureStatus}function mS(){Uu()}function hS(){Un.requestDirectoryDialog()}function pS(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function gS(t){return t.slug!=="home"}function xS(t){return!zu(t)}function bS(t){return t.worktreeMetadata}function yS(t){return{path:cl(t.path),name:t.name,relativePath:t.relativePath}}function vS(t){return{item:t,score:0}}function wS(t){return t.searchText}function SS(t){return t.searchText}function jS(t){return{item:t,score:0}}function kS(t){return t.title||""}function CS(t){return{...t,displayName:t.label||t.path.split("/").pop()||t.path,searchText:`${t.label||""} ${t.path}`}}function NS(t){return t.searchText}function AS(t){return t.item}function DS(t){return t.item}function PS(t){return t.item}function ES(t){return t.item}function TS(t){return t.item}function IS(t){return t.length?t[0].score:1/0}function MS(t,e){return t.score-e.score}function RS(t){return t.key}function OS(t){return s.jsxs(ko,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const kd=(t,e,n)=>up(t)?Yi(Ir(t,n)):e,FS=()=>{const t=it.c(69),{t:e}=gt(),n=he(BS),r=he(LS),o=he(_S);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=dp(),t[0]=i):i=t[0];const c=i;let a;t[1]===Symbol.for("react.memo_cache_sentinel")?(a=sr(),t[1]=a):a=t[1];const d=a;let u,m,f,p,b,k,v,g,h;if(t[2]!==n||t[3]!==r||t[4]!==o||t[5]!==e){const K=[{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=$s,g=n,h=r,u=zs,k="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let x;t[15]===Symbol.for("react.memo_cache_sentinel")?(x=s.jsx(I,{name:"command",className:"h-5 w-5"}),t[15]=x):x=t[15];let M;t[16]!==e?(M=e("helpDialog.title"),t[16]=e,t[17]=M):M=t[17];let z;t[18]!==M?(z=s.jsxs(fn,{className:"flex items-center gap-2",children:[x,M]}),t[18]=M,t[19]=z):z=t[19];let U;t[20]!==e?(U=e("helpDialog.description"),t[20]=e,t[21]=U):U=t[21];let V;t[22]!==U?(V=s.jsx(mn,{children:U}),t[22]=U,t[23]=V):V=t[23],t[24]!==z||t[25]!==V?(v=s.jsxs(An,{children:[z,V]}),t[24]=z,t[25]=V,t[26]=v):v=t[26],b="flex-1 overflow-y-auto mt-3 pr-1",f="space-y-4",p=K.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(X=>!(d&&X.id==="toggle_prompt_navigator")).map(X=>{const le=X.id?kd(X.id,Array.isArray(X.keys)?X.keys[0]:X.keys,o):Array.isArray(X.keys)?X.keys:X.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:[X.icon&&s.jsx(I,{name:X.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(X.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(le)?le:[le]).map((te,fe)=>s.jsxs(l.Fragment,{children:[fe>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}-${fe}`))})]},X.id||X.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]=p,t[10]=b,t[11]=k,t[12]=v,t[13]=g,t[14]=h}else u=t[6],m=t[7],f=t[8],p=t[9],b=t[10],k=t[11],v=t[12],g=t[13],h=t[14];let S;t[27]!==f||t[28]!==p?(S=s.jsx("div",{className:f,children:p}),t[27]=f,t[28]=p,t[29]=S):S=t[29];let y;t[30]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(I,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[30]=y):y=t[30];let j;t[31]!==e?(j=e("helpDialog.proTips.title"),t[31]=e,t[32]=j):j=t[32];let C;t[33]!==j?(C=s.jsx("p",{className:"font-medium mb-1",children:j}),t[33]=j,t[34]=C):C=t[34];let N;t[35]!==o||t[36]!==e?(N=e("helpDialog.proTips.commandPalette",{shortcut:kd("open_command_palette",`${c} P`,o)}),t[35]=o,t[36]=e,t[37]=N):N=t[37];let w;t[38]!==N?(w=s.jsxs("li",{children:["• ",N]}),t[38]=N,t[39]=w):w=t[39];let A;t[40]!==e?(A=e("helpDialog.proTips.recentSessions"),t[40]=e,t[41]=A):A=t[41];let D;t[42]!==A?(D=s.jsxs("li",{children:["• ",A]}),t[42]=A,t[43]=D):D=t[43];let P;t[44]!==e?(P=e("helpDialog.proTips.themeCycling"),t[44]=e,t[45]=P):P=t[45];let B;t[46]!==P?(B=s.jsxs("li",{children:["• ",P]}),t[46]=P,t[47]=B):B=t[47];let F;t[48]!==w||t[49]!==D||t[50]!==B?(F=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[w,D,B]}),t[48]=w,t[49]=D,t[50]=B,t[51]=F):F=t[51];let E;t[52]!==C||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:[y,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[C,F]})]})}),t[52]=C,t[53]=F,t[54]=E):E=t[54];let _;t[55]!==E||t[56]!==b||t[57]!==S?(_=s.jsxs("div",{className:b,children:[S,E]}),t[55]=E,t[56]=b,t[57]=S,t[58]=_):_=t[58];let L;t[59]!==u||t[60]!==_||t[61]!==k||t[62]!==v?(L=s.jsxs(u,{className:k,children:[v,_]}),t[59]=u,t[60]=_,t[61]=k,t[62]=v,t[63]=L):L=t[63];let W;return t[64]!==m||t[65]!==L||t[66]!==g||t[67]!==h?(W=s.jsx(m,{open:g,onOpenChange:h,children:L}),t[64]=m,t[65]=L,t[66]=g,t[67]=h,t[68]=W):W=t[68],W};function BS(t){return t.isHelpDialogOpen}function LS(t){return t.setHelpDialogOpen}function _S(t){return t.shortcutOverrides}const $S=()=>{const t=it.c(32),{t:e}=gt(),n=he(zS),r=he(US),o=he(WS);let i;t[0]!==o||t[1]!==e?(i=async()=>{if(!o)return;if((await Zn(o)).ok){De.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}De.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(fn,{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(mn,{children:u}),t[9]=u,t[10]=m):m=t[10];let f;t[11]!==d||t[12]!==m?(f=s.jsxs(An,{children:[d,m]}),t[11]=d,t[12]=m,t[13]=f):f=t[13];let p;t[14]!==e?(p=e("openCodeStatusDialog.actions.copy"),t[14]=e,t[15]=p):p=t[15];let b;t[16]!==c||t[17]!==p?(b=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:p})}),t[16]=c,t[17]=p,t[18]=b):b=t[18];let k;t[19]!==o||t[20]!==e?(k=o||e("openCodeStatusDialog.empty.noData"),t[19]=o,t[20]=e,t[21]=k):k=t[21];let v;t[22]!==k?(v=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:k}),t[22]=k,t[23]=v):v=t[23];let g;t[24]!==f||t[25]!==b||t[26]!==v?(g=s.jsxs(zs,{className:"max-w-2xl",children:[f,b,v]}),t[24]=f,t[25]=b,t[26]=v,t[27]=g):g=t[27];let h;return t[28]!==n||t[29]!==r||t[30]!==g?(h=s.jsx($s,{open:n,onOpenChange:r,children:g}),t[28]=n,t[29]=r,t[30]=g,t[31]=h):h=t[31],h};function zS(t){return t.isOpenCodeStatusDialogOpen}function US(t){return t.setOpenCodeStatusDialogOpen}function WS(t){return t.openCodeStatusText}function VS(t,e){const n=[...t],r=new Set(n.map(i=>i.id));return(i=>{i.forEach(c=>{r.has(c.id)||(r.add(c.id),n.push(c))})})(e),n}const HS=180,Cd=600,KS=1,GS=6,qS=t=>{const e=t?.directory;return typeof e=="string"&&e.trim()?e:null},YS=({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(()=>sr(),[]),m=l.useCallback(k=>`${k.directory}
906
+ ${k.sessionId}`,[]),f=l.useCallback(()=>{d.current+=1,c.current=[],i.current.forEach(k=>window.clearTimeout(k)),i.current.clear()},[]),p=l.useCallback(()=>{if(!(!t||u||typeof window>"u"))for(;a.current.size<KS&&c.current.length>0;){const k=c.current.shift();if(!k)break;if(k.generation!==d.current||nt.getState().currentSessionId===k.sessionId||bc(k.sessionId,k.directory).renderable)continue;const g=m(k);a.current.add(g),o(k.sessionId,k.directory).catch(()=>{}).finally(()=>{a.current.delete(g),p()})}},[t,u,o,m]),b=l.useCallback(k=>{const v=k?.id,g=qS(k);if(!t||u||!v||!g||v===e||typeof window>"u")return;const h={sessionId:v,directory:g,generation:d.current},S=m(h);if(bc(v,g).renderable||a.current.has(S)||c.current.some(C=>m(C)===S))return;const y=i.current.get(S);y!==void 0&&window.clearTimeout(y);const j=window.setTimeout(()=>{if(i.current.delete(S),h.generation!==d.current)return;const C=c.current;C.length>=GS&&C.shift(),C.push(h),p()},HS);i.current.set(S,j)},[e,t,u,p,m]);l.useEffect(()=>{f()},[f,e,t,u]),l.useEffect(()=>{if(!t||u||!e||n.length===0)return;const k=window.setTimeout(()=>{const v=n.findIndex(g=>g.id===e);v<0||(b(n[v-1]),b(n[v+1]))},Cd);return()=>window.clearTimeout(k)},[e,t,u,b,n]),l.useEffect(()=>{if(!t||u||!e||r.length===0)return;const k=window.setTimeout(()=>{const v=r.findIndex(g=>g.id===e);v<0||(b(r[v-1]),b(r[v+1]))},Cd);return()=>window.clearTimeout(k)},[e,t,u,r,b]),l.useEffect(()=>f,[f])},QS=t=>{const e=it.c(3),n=nt(XS);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],YS(r),null};function XS(t){return t.currentSessionId}const JS=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,p=r===void 0?!0:r;let b,k;e[0]!==f||e[1]!==m||e[2]!==p||e[3]!==u||e[4]!==c||e[5]!==i||e[6]!==a||e[7]!==n||e[8]!==o||e[9]!==d?(b=()=>{!p||i||!c||a||n.forEach(v=>{if(d.has(v.normalizedPath))return;const g=Wu(v.normalizedPath),h=o.archivedSessionsByProject.get(v.id)??[],S=u[g]??[],y=new Map(S.map(ZS));h.forEach(j=>{const C=fp(j,v.normalizedPath),N=C.toLowerCase();let w=y.get(N);w||(w=m(g,C),y.set(N,w)),w.sessionIds.includes(j.id)||f(g,w.id,j.id)})})},k=[n,p,o,i,c,a,d,u,m,f],e[0]=f,e[1]=m,e[2]=p,e[3]=u,e[4]=c,e[5]=i,e[6]=a,e[7]=n,e[8]=o,e[9]=d,e[10]=b,e[11]=k):(b=e[10],k=e[11]),l.useEffect(b,k)};function ZS(t){return[t.name.toLowerCase(),t]}const e0=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(t0)),u=[];a.forEach(p=>{const b=d.get(p);b&&(u.push(b),d.delete(p))});const m=[],f=[];return c.forEach(p=>{d.has(p.id)&&(p.isArchivedBucket?f.push(p):m.push(p))}),[...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 t0(t){return[t.id,t]}const s0=[],n0=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:p,foldersMap:b}=t,k=l.useRef(new Map),v=l.useMemo(()=>{const w=k.current,A=new Map;let D=0,P=0;const B=(E,_)=>E.length===_.length&&E.every((L,W)=>L===_[W]),F=e.map(E=>{const _=n(E.id),L=r(E.id),W=o.get(E.normalizedPath)??s0,K=i.has(E.id)?!!i.get(E.id):a,x=c.get(E.id)??null,M=w.get(E.id);if(M&&M.project===E&&B(M.activeSessions,_)&&B(M.archivedSessions,L)&&M.availableWorktrees===W&&M.rootBranch===x&&M.isRepo===K&&M.buildGroupedSessions===d)return D+=1,A.set(E.id,M),M.section;P+=1;const z=Vu([..._,...L]),U=d(z,E.normalizedPath,W,x,K),V={project:E,groups:U};return A.set(E.id,{project:E,activeSessions:_,archivedSessions:L,availableWorktrees:W,rootBranch:x,isRepo:K,buildGroupedSessions:d,section:V}),V});return k.current=A,D>0&&Tn("ui.sidebar.project_section.reused",D),P>0&&Tn("ui.sidebar.project_section.rebuilt",P),F},[e,n,r,o,i,a,d,c]),g=l.useMemo(()=>v,[v]),h=l.useMemo(()=>{const w=new WeakMap;if(!u)return w;const A=D=>D.reduce((P,B)=>P+1+A(B.children),0);return g.forEach(D=>{D.groups.forEach(P=>{const B=f(P.sessions,m),F=A(B),E=p(P).includes(m),_=jt(P.directory??null),W=(_?b[_]??[]:[]).filter(K=>K.name.toLowerCase().includes(m)).length;w.set(P,{filteredNodes:B,matchedSessionCount:F,folderNameMatchCount:W,groupMatches:E,hasMatch:E||F>0||W>0})})}),w},[u,g,f,m,p,b]),S=l.useMemo(()=>u?g.map(w=>({...w,groups:w.groups.filter(A=>h.get(A)?.hasMatch===!0)})).filter(w=>w.groups.length>0):g,[u,g,h]),y=u?S:g,j=l.useRef(new WeakMap),C=l.useMemo(()=>{const w=j.current;return y.map(A=>{const D=w.get(A);if(D&&D.query===m)return D.section;const P=A.groups.filter(K=>!K.isArchivedBucket),B=A.groups.filter(K=>K.isArchivedBucket),F=P.flatMap(K=>u?h.get(K)?.filteredNodes??[]:K.sessions),E=P.map(K=>({scopeKey:K.folderScopeKey??jt(K.directory??null),directory:K.directory??null})).filter(K=>!!K.scopeKey),_=P.find(K=>K.isMain)??null,L={id:"flat",label:_?.label??"",branch:_?.branch??null,description:_?.description??null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:_?.directory??A.project.normalizedPath,folderScopeKey:_?.folderScopeKey??A.project.normalizedPath,folderScopes:E,sessions:F};if(u){const K=P.map(x=>h.get(x)).filter(x=>!!x);h.set(L,{filteredNodes:F,matchedSessionCount:K.reduce((x,M)=>x+M.matchedSessionCount,0),folderNameMatchCount:K.reduce((x,M)=>x+M.folderNameMatchCount,0),groupMatches:K.some(x=>x.groupMatches),hasMatch:K.some(x=>x.hasMatch)})}const W={project:A.project,groups:[L,...B]};return w.set(A,{query:m,section:W}),W})},[h,u,m,y]),N=l.useMemo(()=>u?y.reduce((w,A)=>w+A.groups.reduce((D,P)=>{const B=h.get(P);if(!B)return D;const F=B.folderNameMatchCount+(B.groupMatches?1:0);return D+B.matchedSessionCount+F},0),0):0,[u,y,h]);return{projectSections:v,visibleProjectSections:g,groupSearchDataByGroup:h,searchableProjectSections:S,sectionsForRender:y,flatSectionsForRender:C,searchMatchCount:N}};function r0({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 o0=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:p,setSessionSwitcherOpen:b}=t;let k,v;if(e[0]!==n){v=new Map,k=new Map;const w=(A,D,P,B)=>{v.has(A)||v.set(A,new Map);const F=v.get(A);B.forEach(E=>{const _=jt(E.worktree?.path??E.session.directory??P??D);F.set(E.session.id,{directory:_}),k.has(A)||k.set(A,{id:E.session.id,directory:_}),E.children.length>0&&w(A,D,_,E.children)})};n.forEach(A=>{A.groups.forEach(D=>{w(A.project.id,A.project.normalizedPath,D.directory,D.sessions)})}),e[0]=n,e[1]=k,e[2]=v}else k=e[1],v=e[2];let g;e[3]!==k||e[4]!==v?(g={metaByProject:v,firstSessionByProject:k},e[3]=k,e[4]=v,e[5]=g):g=e[5];const h=g,S=l.useRef(null);let y,j;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]!==p||e[17]!==i||e[18]!==b?(y=()=>{if(!r||u||he.getState().isNewWorktreeDialogOpen||S.current===r)return;const w=n.find(B=>B.project.id===r);if(!w)return;const A=h.metaByProject.get(r);if(c&&A&&A.has(c)){S.current=r,i(B=>{if(B.get(r)===c)return B;const F=new Map(B);return F.set(r,c),F});return}const D=r0({activeProjectId:r,currentSessionId:c,currentSessionOwnerProjectId:a,projectMap:A,metaByProject:h.metaByProject,rememberedSessionId:o.get(r),fallbackSessionId:h.firstSessionByProject.get(r)?.id??null});if(D.kind==="preserve-current"){a===r&&(S.current=r);return}if(S.current=r,D.kind==="open-draft"){p("chat"),m&&b(!1),f({selectedProjectId:w.project.id,directoryOverride:w.project.normalizedPath});return}if(D.kind!=="select-session")return;const P=A?.get(D.sessionId)?.directory??null;d(D.sessionId,P)},j=[r,o,c,a,d,u,m,f,n,h,p,b,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]=p,e[17]=i,e[18]=b,e[19]=y,e[20]=j):(y=e[19],j=e[20]),l.useLayoutEffect(y,j);let C,N;e[21]!==r||e[22]!==c||e[23]!==h||e[24]!==i?(C=()=>{if(!r||!c)return;const w=h.metaByProject.get(r);!w||!w.has(c)||i(A=>{if(A.get(r)===c)return A;const D=new Map(A);return D.set(r,c),D})},N=[r,c,h,i],e[21]=r,e[22]=c,e[23]=h,e[24]=i,e[25]=C,e[26]=N):(C=e[25],N=e[26]),l.useEffect(C,N)},i0=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=nt(a0),a=nt(l0);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,p]=l.useState(m);let b;e[10]!==f||e[11]!==n||e[12]!==c||e[13]!==u||e[14]!==a?(b={...n,activeSessionByProject:f,setActiveSessionByProject:p,currentSessionId:c,currentSessionOwnerProjectId:u,newSessionDraftOpen:a},e[10]=f,e[11]=n,e[12]=c,e[13]=u,e[14]=a,e[15]=b):b=e[15],o0(b);let k,v;return e[16]!==f||e[17]!==o?(k=()=>{o(f)},v=[f,o],e[16]=f,e[17]=o,e[18]=k,e[19]=v):(k=e[18],v=e[19]),l.useEffect(k,v),null};function a0(t){return t.currentSessionId}function l0(t){return!!t.newSessionDraft?.open}const dl=new Map,c0=(t,e)=>{for(const n of t){const r=jt(n??null);r&&!dl.has(r)&&dl.set(r,e)}},Nd=t=>{const e=jt(t??null);return e?dl.get(e)??0:0},ai=t=>!!t.time?.archived,d0=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),p=Vu(c).sort((F,E)=>Rr(F,E,t.pinnedSessionIds,t.sessionOrderRanks)),b=new Map(p.map(F=>[F.id,F])),k=new Map;p.forEach(F=>{const E=F.parentID;if(!E)return;const _=b.get(E);if(!_||ai(_)!==ai(F))return;const L=k.get(E)??[];L.push(F),k.set(E,L)}),k.forEach(F=>F.sort((E,_)=>Rr(E,_,t.pinnedSessionIds,t.sessionOrderRanks)));const v=new Map;d.forEach(F=>{if(F.path){const E=jt(F.path)??F.path;v.set(E,F)}});const g=F=>{const E=jt(F.directory??null),_=t.worktreeMetadata.get(F.id)??null;if(_)return _;if(E){const L=v.get(E)??null;if(L&&E!==f)return L}return null},h=F=>{const E=k.get(F.id)??[];return{session:F,children:E.map(_=>h(_)),worktree:g(F)}},S=p.filter(F=>{const E=F.parentID;if(!E)return!0;const _=b.get(E);return _?ai(_)!==ai(F):!0}),y=new Map,j="__archived__",C=F=>{if(F.time?.archived)return j;if(t.isVSCode)return f??"__project_root__";const _=jt(t.worktreeMetadata.get(F.id)?.path??null)??Zs(F);return _?_!==f&&v.has(_)?_:_===f?f??"__project_root__":j:j};S.forEach(F=>{const E=h(F),_=C(F);y.has(_)||y.set(_,[]),y.get(_)?.push(E)});const N=f??"__project_root__",w=[{id:"root",label:m&&u&&u!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:u}):e("sessions.sidebar.grouping.projectRoot"),branch:u??null,description:f?Io(f,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:f,folderScopeKey:f,sessions:y.get(N)??[]}],A=new Map;d.forEach(F=>{const E=jt(F.path)??F.path,_=y.get(E)??[],L=_.length>0,W=_.reduce((K,x)=>{const M=mp(x.session,t.sessionOrderRanks);return Number.isFinite(M)?Math.max(K,M):K},0);A.set(E,{hasActiveSession:L,lastUpdatedAt:W})});const D=[...d].sort((F,E)=>{const _=jt(F.path)??F.path,L=jt(E.path)??E.path,W=A.get(_)??{hasActiveSession:!1,lastUpdatedAt:0},K=A.get(L)??{hasActiveSession:!1,lastUpdatedAt:0};if(W.hasActiveSession!==K.hasActiveSession)return W.hasActiveSession?-1:1;if(W.hasActiveSession&&K.hasActiveSession)return K.lastUpdatedAt-W.lastUpdatedAt;const x=Nd(F.path),M=Nd(E.path);if(x!==M)return M-x;const z=(F.label||F.branch||F.name||F.path||"").toLowerCase(),U=(E.label||E.branch||E.name||E.path||"").toLowerCase();return z.localeCompare(U)});(t.isVSCode?[]:D).forEach(F=>{const E=jt(F.path)??F.path,_=t.gitBranches.get(E)?.trim()||null,L=F.branch?.trim()||null,K=!!(_&&L&&F.label&&yc(F.label)===yc(L))?_:F.label||F.name||xr(E,t.homeDirectory)||E;w.push({id:`worktree:${E}`,label:K,branch:_||L,description:Io(E,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:F,directory:E,folderScopeKey:E,sessions:y.get(E)??[]})});const B=y.get(j)??[];return B.length>0&&w.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?Wu(f):null,sessions:B}),w},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.sessionOrderRanks,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:o,buildGroupedSessions:i}},u0=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 p=window.requestAnimationFrame(()=>{i.current?.focus(),i.current?.select()});return()=>window.cancelAnimationFrame(p)},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 p=b=>{c.current&&(c.current.contains(b.target)||o(!1))};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},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)},f0=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=(V,Z)=>{Ua("navigation.session_select"),he.getState().closeMainSurfaces();const X=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),V===nt.getState().currentSessionId){t.allowReselect&&t.onSessionSelected?.(V),X();return}Ua("navigation.session_state_set"),t.setCurrentSession(V,Z??null),t.onSessionSelected?.(V),X()},e[2]=t,e[3]=d):d=e[3];const u=d;let m;e[4]!==t?(m=(V,Z)=>{t.setEditingId(V),t.setEditTitle(Z)},e[4]=t,e[5]=m):m=e[5];const f=m;let p;e[6]!==t?(p=async V=>{if(!t.editingId)return;const Z=(V??t.editTitle).trim();Z&&await t.updateSessionTitle(t.editingId,Z),t.setEditingId(null),t.setEditTitle("")},e[6]=t,e[7]=p):p=e[7];const b=p;let k;e[8]!==t?(k=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=k):k=e[9];const v=k;let g;e[10]===Symbol.for("react.memo_cache_sentinel")?(g=async(V,Z)=>{try{return(await Zn(V)).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]=g):g=e[10];const h=g;let S;e[11]!==t||e[12]!==n?(S=async V=>{const Z=await t.shareSession(V.id);if(!Z?.share?.url){De.error(n("sessions.sidebar.session.share.error"));return}const X=await h(Z.share.url,V.id);De[X?"success":"warning"](n("sessions.sidebar.session.share.successTitle"),{description:n(X?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")})},e[11]=t,e[12]=n,e[13]=S):S=e[13];const y=S;let j;e[14]!==n?(j=(V,Z)=>{h(V,Z).then(X=>{X||De.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[14]=n,e[15]=j):j=e[15];const C=j;let N;e[16]!==n?(N=V=>{Zn(V).then(Z=>{if(Z.ok){De.success(n("sessions.sidebar.session.copyId.success"));return}De.error(n("sessions.sidebar.session.copyId.error"))}).catch(()=>De.error(n("sessions.sidebar.session.copyId.error")))},e[16]=n,e[17]=N):N=e[17];const w=N;let A;e[18]!==t||e[19]!==n?(A=async V=>{await t.unshareSession(V)?De.success(n("sessions.sidebar.session.unshare.success")):De.error(n("sessions.sidebar.session.unshare.error"))},e[18]=t,e[19]=n,e[20]=A):A=e[20];const D=A;let P;e[21]!==t.childrenMap?(P=V=>{const Z=[],X=le=>{(t.childrenMap.get(le)??[]).forEach(fe=>{Z.push(fe),X(fe.id)})};return X(V),Z},e[21]=t.childrenMap,e[22]=P):P=e[22];const B=P,F=h0;let E;e[23]!==t||e[24]!==B||e[25]!==n?(E=async(V,Z,X)=>{const le=Z?.archivedBucket===!0||Z?.hardDelete===!0,te=X?.descendantIds??F(B(V.id),le).map(p0);if(te.length===0){(le?await t.deleteSession(V.id):await t.archiveSession(V.id))?De.success(n(le?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):De.error(n(le?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const fe=[V.id,...te];if(le){const{deletedIds:Se,failedIds:ae}=await t.deleteSessions(fe);if(ae.length===0){const q=Se.length;De.success(q===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:q}):n("sessions.sidebar.bulkActions.deletedPlural",{count:q}))}else De.error(n("sessions.sidebar.session.delete.error"));return}const{archivedIds:ge,failedIds:H}=await t.archiveSessions(fe);ge.length>0&&De.success(ge.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:ge.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:ge.length})),H.length>0&&De.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]=B,e[25]=n,e[26]=E):E=e[26];const _=E;let L;e[27]!==t||e[28]!==B||e[29]!==_?(L=(V,Z)=>{const X=Z?.archivedBucket===!0||Z?.hardDelete===!0,le=F(B(V.id),X).map(g0);if(!t.showDeletionDialog||Z?.skipConfirm===!0){_(V,Z,{descendantIds:le});return}t.setDeleteSessionConfirm({session:V,descendantCount:le.length,descendantIds:le,archivedBucket:X})},e[27]=t,e[28]=B,e[29]=_,e[30]=L):L=e[30];const W=L;let K;e[31]!==t||e[32]!==_?(K=async()=>{if(!t.deleteSessionConfirm)return;const{session:V,archivedBucket:Z,descendantIds:X}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await _(V,{archivedBucket:Z},{descendantIds:X})},e[31]=t,e[32]=_,e[33]=K):K=e[33];const x=K;let M;e[34]!==t||e[35]!==n?(M=async V=>{await t.unarchiveSession(V.id)?De.success(n("sessions.sidebar.session.restore.success")):De.error(n("sessions.sidebar.session.restore.error"))},e[34]=t,e[35]=n,e[36]=M):M=e[36];const z=M;let U;return e[37]!==x||e[38]!==r||e[39]!==v||e[40]!==w||e[41]!==C||e[42]!==W||e[43]!==z||e[44]!==b||e[45]!==f||e[46]!==u||e[47]!==y||e[48]!==D?(U={copiedSessionId:r,handleSessionSelect:u,handleSessionDoubleClick:f,handleSaveEdit:b,handleCancelEdit:v,handleShareSession:y,handleCopyShareUrl:C,handleCopySessionId:w,handleUnshareSession:D,handleDeleteSession:W,handleRestoreSession:z,confirmDeleteSession:x},e[37]=x,e[38]=r,e[39]=v,e[40]=w,e[41]=C,e[42]=W,e[43]=z,e[44]=b,e[45]=f,e[46]=u,e[47]=y,e[48]=D,e[49]=U):U=e[49],U};function m0(t){return!t.time?.archived}function h0(t,e){return e?t:t.filter(m0)}function p0(t){return t.id}function g0(t){return t.id}const x0=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 A=m.current;if(m.current=null,u.current=null,!A)return;const{projects:D}=Jt.getState(),P=D.map(B=>({...B,sidebarCollapsed:A.has(B.id)}));Yr({projects:P}).catch(b0)},e[0]=n,e[1]=f):f=e[1];const p=f;let b;e[2]!==p||e[3]!==n?(b=A=>{typeof window>"u"||n||(m.current=A,u.current!==null&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>{p()},700))},e[2]=p,e[3]=n,e[4]=b):b=e[4];const k=b;let v,g;e[5]===Symbol.for("react.memo_cache_sentinel")?(v=()=>()=>{typeof window<"u"&&u.current!==null&&window.clearTimeout(u.current),u.current=null,m.current=null},g=[],e[5]=v,e[6]=g):(v=e[5],g=e[6]),l.useEffect(v,g);let h,S;e[7]!==o.projectCollapse||e[8]!==o.sessionExpanded||e[9]!==r||e[10]!==d||e[11]!==a?(h=()=>{try{const A=r.getItem(o.sessionExpanded);if(A){const P=JSON.parse(A);Array.isArray(P)&&a(new Set(P.filter(y0)))}const D=r.getItem(o.projectCollapse);if(D){const P=JSON.parse(D);Array.isArray(P)&&d(new Set(P.filter(v0)))}}catch{}},S=[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]=S):(h=e[12],S=e[13]),l.useEffect(h,S);let y,j;e[14]!==i||e[15]!==o.groupOrder||e[16]!==r?(y=()=>{try{const A=Object.fromEntries(i.entries());r.setItem(o.groupOrder,JSON.stringify(A))}catch{}},j=[i,o.groupOrder,r],e[14]=i,e[15]=o.groupOrder,e[16]=r,e[17]=y,e[18]=j):(y=e[17],j=e[18]),l.useEffect(y,j);let C,N;e[19]!==c||e[20]!==o.groupCollapse||e[21]!==r?(C=()=>{try{r.setItem(o.groupCollapse,JSON.stringify(Array.from(c)))}catch{}},N=[c,o.groupCollapse,r],e[19]=c,e[20]=o.groupCollapse,e[21]=r,e[22]=C,e[23]=N):(C=e[22],N=e[23]),l.useEffect(C,N);let w;return e[24]!==k?(w={scheduleCollapsedProjectsPersist:k},e[24]=k,e[25]=w):w=e[25],w};function b0(){}function y0(t){return typeof t=="string"}function v0(t){return typeof t=="string"}const w0=5*6e4,S0=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}=nr(),u=gr(j0);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(N=>{Ga(()=>u(N.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 p,b;e[7]!==a||e[8]!==o||e[9]!==n||e[10]!==i?(p=()=>{if(!a)return;const N=new Map;n.forEach(w=>{N.set(w.id,o.get(w.normalizedPath)?.isGitRepo??null)}),i(N)},b=[a,n,o,i],e[7]=a,e[8]=o,e[9]=n,e[10]=i,e[11]=p,e[12]=b):(p=e[11],b=e[12]),l.useEffect(p,b);let k;if(e[13]!==o||e[14]!==n){let N;e[16]!==o?(N=w=>{const A=o.get(w.normalizedPath)?.branch??"";return`${w.id}:${A}`},e[16]=o,e[17]=N):N=e[17],k=n.map(N).join("|"),e[13]=o,e[14]=n,e[15]=k}else k=e[15];const v=k;let g;e[18]===Symbol.for("react.memo_cache_sentinel")?(g=new Map,e[18]=g):g=e[18];const h=l.useRef(g);let S;e[19]===Symbol.for("react.memo_cache_sentinel")?(S=new Map,e[19]=S):S=e[19];const y=l.useRef(S);let j;e[20]!==a||e[21]!==o||e[22]!==n||e[23]!==c?(j=()=>{if(!a)return;let N=!1;const w=setTimeout(()=>{(async()=>{const D=new Set(n.map(k0));for(const L of h.current.keys())D.has(L)||(h.current.delete(L),y.current.delete(L));const P=Date.now(),B=n.filter(L=>{const W=o.get(L.normalizedPath);if(W?.isGitRepo===!1)return h.current.delete(L.id),y.current.delete(L.id),!1;if(W?.isGitRepo!==!0||W.branch===null)return!1;const K=W.branch.trim(),x=`${L.normalizedPath}\0${K}`,M=h.current.get(L.id);if(M===x){const z=y.current.get(L.id);return z&&(z.at=P),!1}return!(M!==void 0&&P-(y.current.get(L.id)?.at??0)<w0)});if(B.length===0)return;const F=await hp(B,2,async L=>{const W=o.get(L.normalizedPath)?.branch?.trim()??"",K=`${L.normalizedPath}\0${W}`,x=await Ga(()=>Ji(L.normalizedPath,W?{knownBranch:W}:void 0)).catch(C0);return{id:L.id,inputKey:K,branch:x}});if(N)return;const E=F.filter(N0);if(E.length===0)return;const _=Date.now();c(L=>{const W=new Map(L);return E.forEach(K=>{const{id:x,branch:M}=K;M&&W.set(x,M)}),W}),E.forEach(L=>{const{id:W,inputKey:K,branch:x}=L;h.current.set(W,K),x&&y.current.set(W,{branch:x,at:_})})})()},150);return()=>{N=!0,clearTimeout(w)}},e[20]=a,e[21]=o,e[22]=n,e[23]=c,e[24]=j):j=e[24];let C;e[25]!==a||e[26]!==o||e[27]!==n||e[28]!==v||e[29]!==c?(C=[a,n,v,o,c],e[25]=a,e[26]=o,e[27]=n,e[28]=v,e[29]=c,e[30]=C):C=e[30],l.useEffect(j,C)};function j0(t){return t.ensureStatus}function k0(t){return t.id}function C0(){return null}function N0(t){return t.branch}const A0=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},D0=t=>{const e=new Map;for(const n of t){const r=Zs(n);r&&e.set(n.id,{directory:r,sessionId:n.id})}return e},P0=(t,e)=>{if(!t)return[];const n=[];return t.forEach((r,o)=>{e.has(o)||n.push(r)}),n},E0=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=Ms(),m=D0(o),f=c.current?.runtimeKey===u?c.current.identities:null;for(const p of P0(f,m))pp({runtimeKey:u,...p});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)},T0=(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,Ad=(t,e,n)=>{T0(t.get(e),n)&&t.set(e,n)},I0=t=>{const e=t;return jt(e.directory)??jt(e.project?.worktree)},M0=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)},R0=(t,e,n,r,o=[])=>{const i=new Map,c=new Map;for(const k of e){const v=jt(k.normalizedPath);if(!v)continue;const g=c.get(v);(!g||k.id.localeCompare(g.id)<0)&&c.set(v,k),Ad(i,v,{projectId:k.id,projectRoot:v,scopeDirectory:v,kind:"project"})}if(!r)for(const[k,v]of n){const g=jt(k),h=g?c.get(g):void 0;if(!(!h||!g))for(const S of v){const y=jt(S.path);y&&Ad(i,y,{projectId:h.id,projectRoot:g,scopeDirectory:y,kind:"worktree"})}}const a=new Map,d=new Map,u=new Map,m=new Map,f=new Map,p=k=>{if(!k)return null;if(a.has(k))return a.get(k)??null;if(r){const S=i.get(k)??null;return a.set(k,S),S}const v=[];let g=k,h=null;for(;g;){if(a.has(g)){h=a.get(g)??null;break}if(v.push(g),h=i.get(g)??null,h)break;g=M0(g)}for(const S of v)a.set(S,h);return h},b=(k,v,g)=>{for(const h of k){const S=p(I0(h));if(!S)continue;d.set(h.id,S);const y=v.get(S.projectId);if(y?y.push(h):v.set(S.projectId,[h]),!g)continue;const j=g.get(S.scopeDirectory);j?j.add(h.id):g.set(S.scopeDirectory,new Set([h.id]))}};return b(t,u,f),b(o,m),{bySessionId:d,sessionsByProject:u,archivedSessionsByProject:m,sessionsByScope:f,directoryResolutions:a.size}},O0=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(F0);return}const b=Array.from(i.current.values()).find(B0)?.closest(".oc-sidebar-scroller")??null;if(!b)return;const k=new IntersectionObserver(v=>{u(g=>{const h=new Set(g);let S=!1;for(const y of v){const j=y.target.dataset.projectId;if(!j)continue;const C=y.rootBounds?.top??b.getBoundingClientRect().top,N=!y.isIntersecting&&y.boundingClientRect.top<C;h.has(j)!==N&&(S=!0,N?h.add(j):h.delete(j))}return S?h:g})},{root:b,threshold:0});return i.current.forEach(v=>{v&&k.observe(v)}),()=>k.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 F0(t){return t.size===0?t:new Set}function B0(t){return t!==null}const L0=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(Xg,{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(zs,{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($s,{open:n,onOpenChange:r,children:a}),e[6]=r,e[7]=n,e[8]=a,e[9]=d):d=e[9],d};function om(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=xe("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 _0=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:p,groupDirectory:b,projectId:k,mobileVariant:v,alwaysShowActions:g,isRenaming:h,renameDraft:S,onRenameDraftChange:y,onRenameSave:j,onRenameCancel:C,droppableRef:N,isDropTarget:w,onNewSession:A,depth:D,hideActions:P,archivedBucket:B}=t,F=a===void 0?null:a,_=g===void 0?v===void 0?!1:v:g,L=h===void 0?!1:h,W=S===void 0?"":S,K=w===void 0?!1:w,x=P===void 0?!1:P,M=B===void 0?!1:B,{t:z}=gt(),[U,V]=l.useState(!1),[Z,X]=l.useState(""),le=l.useRef(null),te=L||U,fe=L?W:Z;let ge;e[0]!==n.name?(ge=()=>{X(n.name),V(!0)},e[0]=n.name,e[1]=ge):ge=e[1];const H=ge;let Se;e[2]!==fe||e[3]!==n.name||e[4]!==L||e[5]!==u||e[6]!==j?(Se=()=>{const be=fe.trim();be&&be!==n.name&&u(be),L&&j&&j(),V(!1),X("")},e[2]=fe,e[3]=n.name,e[4]=L,e[5]=u,e[6]=j,e[7]=Se):Se=e[7];const ae=Se;let q;e[8]!==L||e[9]!==C?(q=()=>{L&&C&&C(),V(!1),X("")},e[8]=L,e[9]=C,e[10]=q):q=e[10];const me=q;let pe;e[11]!==L||e[12]!==y?(pe=be=>{L&&y?y(be):X(be)},e[11]=L,e[12]=y,e[13]=pe):pe=e[13];const Ie=pe;let Oe,Me;e[14]!==L?(Oe=()=>{if(!L)return;const be=()=>{const ve=le.current;ve&&(ve.focus(),ve.select())},T=requestAnimationFrame(be),ce=window.setTimeout(be,0);return()=>{cancelAnimationFrame(T),window.clearTimeout(ce)}},Me=[L],e[14]=L,e[15]=Oe,e[16]=Me):(Oe=e[15],Me=e[16]),l.useEffect(Oe,Me);const Fe=c?"folder":"folder-open",je=K&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let Ne;e[17]!==je?(Ne=xe("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",je),e[17]=je,e[18]=Ne):Ne=e[18];let Pe;e[19]!==d||e[20]!==te?(Pe=te?void 0:be=>{be.currentTarget.blur(),d()},e[19]=d,e[20]=te,e[21]=Pe):Pe=e[21];const se=te?void 0:"button",oe=te?void 0:0;let Ee;e[22]!==d||e[23]!==te?(Ee=te?void 0:be=>{(be.key==="Enter"||be.key===" ")&&(be.preventDefault(),d())},e[22]=d,e[23]=te,e[24]=Ee):Ee=e[24];let J;e[25]!==n.name||e[26]!==c||e[27]!==z?(J=c?z("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):z("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[25]=n.name,e[26]=c,e[27]=z,e[28]=J):J=e[28];const re=M?_?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":_?"pr-20":"group-hover/folder:pr-20 group-focus-within/folder:pr-20";let ee;e[29]!==re?(ee=xe("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",re),e[29]=re,e[30]=ee):ee=e[30];const $=K?"text-primary":"text-muted-foreground";let de;e[31]!==$?(de=xe("h-3.5 w-3.5 flex-shrink-0",$),e[31]=$,e[32]=de):de=e[32];let Y;e[33]!==Fe||e[34]!==de?(Y=s.jsx(I,{name:Fe,className:de}),e[33]=Fe,e[34]=de,e[35]=Y):Y=e[35];let ue;e[36]!==F||e[37]!==r||e[38]!==fe||e[39]!==n.name||e[40]!==me||e[41]!==Ie||e[42]!==ae||e[43]!==c||e[44]!==K||e[45]!==te||e[46]!==o||e[47]!==z?(ue=te?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:z0,onMouseDown:U0,onSubmit:be=>{be.preventDefault(),ae()},children:[s.jsx("input",{ref:le,value:fe,onChange:be=>Ie(be.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:z("sessions.sidebar.folderItem.namePlaceholder"),onClick:W0,onPointerDown:V0,onMouseDown:H0,onKeyDown:be=>{if(be.key==="Escape"){be.stopPropagation(),me();return}(be.key===" "||be.key==="Enter")&&be.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:K0,onPointerDown:G0,onMouseDown:q0,children:s.jsx(I,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:be=>{be.stopPropagation(),me()},onPointerDown:Y0,onMouseDown:Q0,className:"shrink-0 text-muted-foreground hover:text-foreground",children:s.jsx(I,{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:xe("typography-ui-label font-semibold truncate",K?"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(om,{state:F,activeLabel:z("sessions.sidebar.session.status.active"),unreadLabel:z("sessions.sidebar.session.status.unread")}):null,c?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(I,{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]=fe,e[39]=n.name,e[40]=me,e[41]=Ie,e[42]=ae,e[43]=c,e[44]=K,e[45]=te,e[46]=o,e[47]=z,e[48]=ue):ue=e[48];let Te;e[49]!==ee||e[50]!==Y||e[51]!==ue?(Te=s.jsxs("div",{className:ee,children:[Y,ue]}),e[49]=ee,e[50]=Y,e[51]=ue,e[52]=Te):Te=e[52];let Ge;e[53]!==_||e[54]!==M||e[55]!==n.name||e[56]!==H||e[57]!==x||e[58]!==m||e[59]!==A||e[60]!==te||e[61]!==z?(Ge=!te&&(!x||M)?s.jsx("div",{className:xe("absolute right-0.5 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",_?"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:[!M&&A?s.jsx("button",{type:"button",onClick:be=>{be.stopPropagation(),A()},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":z("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:z("sessions.sidebar.project.actions.newSession"),children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})}):null,M?null:s.jsx("button",{type:"button",onClick:be=>{be.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":z("sessions.sidebar.folderItem.renameAria",{folderName:n.name}),children:s.jsx(I,{name:"pencil-ai",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:be=>{be.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":M?z("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):z("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[53]=_,e[54]=M,e[55]=n.name,e[56]=H,e[57]=x,e[58]=m,e[59]=A,e[60]=te,e[61]=z,e[62]=Ge):Ge=e[62];let _e;e[63]!==N||e[64]!==Ne||e[65]!==Pe||e[66]!==se||e[67]!==oe||e[68]!==Ee||e[69]!==J||e[70]!==Te||e[71]!==Ge?(_e=s.jsxs("div",{ref:N,className:Ne,onClick:Pe,role:se,tabIndex:oe,onKeyDown:Ee,"aria-label":J,children:[Te,Ge]}),e[63]=N,e[64]=Ne,e[65]=Pe,e[66]=se,e[67]=oe,e[68]=Ee,e[69]=J,e[70]=Te,e[71]=Ge,e[72]=_e):_e=e[72];let ie;e[73]!==M||e[74]!==p||e[75]!==b||e[76]!==c||e[77]!==k||e[78]!==f||e[79]!==o||e[80]!==i||e[81]!==z?(ie=c?null:s.jsxs("div",{className:"pb-1",children:[i,o.length>0?s.jsx("div",{className:"pl-3",children:o.map(be=>f(be,0,b??null,k??null,M,void 0,"project",p?.(be)))}):i?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:z("sessions.sidebar.folderItem.emptyFolder")})]}),e[73]=M,e[74]=p,e[75]=b,e[76]=c,e[77]=k,e[78]=f,e[79]=o,e[80]=i,e[81]=z,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},$0=l.memo(_0);function z0(t){return t.stopPropagation()}function U0(t){return t.stopPropagation()}function W0(t){return t.stopPropagation()}function V0(t){return t.stopPropagation()}function H0(t){return t.stopPropagation()}function K0(t){return t.stopPropagation()}function G0(t){return t.stopPropagation()}function q0(t){return t.stopPropagation()}function Y0(t){return t.stopPropagation()}function Q0(t){return t.stopPropagation()}const X0=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:p}=Px(d);let b;e[7]!==m?(b=h=>{h.stopPropagation(),m?.onPointerDown&&m.onPointerDown(h)},e[7]=m,e[8]=b):b=e[8];const k=b,v=p?"opacity-30":void 0;let g;return e[9]!==u||e[10]!==i||e[11]!==k||e[12]!==f||e[13]!==v?(g=s.jsx("div",{ref:f,...u,onPointerDown:k,className:v,children:i}),e[9]=u,e[10]=i,e[11]=k,e[12]=f,e[13]=v,e[14]=g):g=e[14],g},J0=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}=Dx(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},Z0=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=Mi(eo(Xa,c)),[d,u]=l.useState(null),[m,f]=l.useState("Session"),[p,b]=l.useState(null),[k,v]=l.useState(null);if(!n){let w;return e[1]!==i?(w=s.jsx(s.Fragment,{children:i}),e[1]=i,e[2]=w):w=e[2],w}let g;e[3]!==o?(g=w=>{u(null),b(null),v(null);const{active:A,over:D}=w;if(!D)return;const P=A.data.current,B=D.data.current;P?.type==="session"&&P.sessionId&&B?.type==="folder"&&B.folderId&&o(P.sessionId,B.folderId)},e[3]=o,e[4]=g):g=e[4];const h=g;let S,y;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=w=>{const A=w.active.data.current;if(A?.type==="session"&&A.sessionId){u(A.sessionId),f(A.sessionTitle??"Session");const D=w.active.rect.current.initial?.width,P=w.active.rect.current.initial?.height;b(typeof D=="number"?D:null),v(typeof P=="number"?P:null)}},y=()=>{u(null),b(null),v(null)},e[5]=S,e[6]=y):(S=e[5],y=e[6]);let j;e[7]!==k||e[8]!==d||e[9]!==m||e[10]!==p||e[11]!==r?(j=d&&r?s.jsxs("div",{style:{width:p?`${p}px`:"auto",height:k?`${k}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(I,{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]=k,e[8]=d,e[9]=m,e[10]=p,e[11]=r,e[12]=j):j=e[12];let C;e[13]!==j?(C=s.jsx(Ja,{children:j}),e[13]=j,e[14]=C):C=e[14];let N;return e[15]!==i||e[16]!==h||e[17]!==a||e[18]!==C?(N=s.jsxs(Ri,{sensors:a,collisionDetection:Oi,onDragStart:S,onDragCancel:y,onDragEnd:h,children:[i,C]}),e[15]=i,e[16]=h,e[17]=a,e[18]=C,e[19]=N):N=e[19],N},ul=(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)},Qn=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(Qn(n,e))return!0;return!1},ej=(t,e,n)=>{const r=new Map,o=i=>{const c=Zs(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}))},tj=(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})},Dd=new WeakMap;let Pd=1;const sj=t=>{const e=Dd.get(t);if(e!==void 0)return e;const n=Pd;return Pd+=1,Dd.set(t,n),n},Ui=t=>t.children.length===0?"":t.children.map(n=>{const r=sj(n.session);return n.children.length===0?`${n.session.id}@${r}`:`${n.session.id}@${r}:${Ui(n)}`}).join("|"),im=(t,e,n,r,o,i)=>{const c=Ms(),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,p=vc(c,m??"",d.session.id),b=vc(c,f??"",u.session.id);return(p?n.has(p):!1)!==(b?r.has(b):!1)?!0:d.children.some((k,v)=>a(k,u.children[v]))};return a(t,e)},Bo=(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},Hl=(t,e)=>t==="active"||e==="active"?"active":t==="unread"||e==="unread"?"unread":null,am=(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=Hl(o,am(c,e,n,r)),o==="active")return o;return o},Ed=(t,e,n,r)=>{let o=null;for(const i of t)if(o=Hl(o,am(i,e,n,r)),o==="active")return o;return o},nj=50,rj=28,li=(t,e)=>e?t.sessions.some(n=>Qn(n,e)):!1,oj=(t,e,n)=>t.sessions.some(r=>im(r,r,e,n,t.directory,t.directory)),ij=(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)},Td=(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)},aj=(t,e)=>{const n=r=>e.has(r.session.id)?!0:r.children.some(n);return t.sessions.some(n)},lj=(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)},cj=(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.sessionBatchSize!==e.sessionBatchSize||t.collapsedGroups!==e.collapsedGroups&&t.collapsedGroups.has(t.groupKey)!==e.collapsedGroups.has(e.groupKey)||t.pinnedSessionIds!==e.pinnedSessionIds&&oj(e.group,t.pinnedSessionIds,e.pinnedSessionIds)||t.expandedParents!==e.expandedParents&&lj(e.group,t.expandedParents,e.expandedParents)||t.sessionOrderIndex!==e.sessionOrderIndex&&ij(e.group,t.sessionOrderIndex,e.sessionOrderIndex)||t.editingId!==e.editingId&&(li(t.group,t.editingId)||li(e.group,e.editingId))||t.editTitle!==e.editTitle&&(li(t.group,t.editingId)||li(e.group,e.editingId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=Bo(t.group.sessions,t.openSidebarMenuKey,"project",!!t.group.isArchivedBucket),r=Bo(e.group.sessions,e.openSidebarMenuKey,"project",!!e.group.isArchivedBucket);if(n||r)return!1}return t.activeActivitySessionIds!==e.activeActivitySessionIds&&Td(e.group,t.activeActivitySessionIds,e.activeActivitySessionIds)||t.unreadActivitySessionIds!==e.unreadActivitySessionIds&&Td(e.group,t.unreadActivitySessionIds,e.unreadActivitySessionIds)||t.notifyOnSubtasks!==e.notifyOnSubtasks&&aj(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 dj(t){const{t:e}=gt(),{group:n,groupKey:r,projectId:o,hideGroupLabel:i,hasSessionSearchQuery:c,normalizedSessionSearchQuery:a,groupSearchDataByGroup:d,visibleSessionCount:u,sessionBatchSize:m,collapsedGroups:f,hideDirectoryControls:p,collapsedFolderIds:b,toggleFolderCollapse:k,renameFolder:v,deleteFolder:g,showDeletionDialog:h,setDeleteFolderConfirm:S,renderSessionNode:y,showMoreGroupSessions:j,resetGroupSessionLimit:C,mobileVariant:N,alwaysShowActions:w,activeProjectId:A,setActiveProjectIdOnly:D,setActiveMainTab:P,setSessionSwitcherOpen:B,openNewSessionDraft:F,addSessionToFolder:E,createFolderAndStartRename:_,renamingFolderId:L,renameFolderDraft:W,setRenameFolderDraft:K,setRenamingFolderId:x,pinnedSessionIds:M,expandedParents:z,sessionOrderIndex:U,editingId:V,openSidebarMenuKey:Z,activeActivitySessionIds:X,unreadActivitySessionIds:le,notifyOnSubtasks:te,onToggleCollapsedGroup:fe,dragHandleProps:ge,compactBodyPadding:H=!1,scrollContainerRef:Se}=t,ae=l.useCallback((Be,Xe)=>{const Je=U.get(Be.session.id),He=U.get(Xe.session.id);if(Je!==void 0||He!==void 0){if(Je===void 0)return 1;if(He===void 0)return-1;if(Je!==He)return Je-He}return Rr(Be.session,Xe.session,M,Nl)},[M,U]),q=c?d.get(n):null,me=Gs(Be=>Be.foldersMap),pe=c?!1:f.has(r),Ie=l.useMemo(()=>{if(n.isMain||n.isArchivedBucket||i)return null;const Be=jt(n.directory??null),Xe=n.branch?.trim();return Be&&Xe?Qi(Be,Xe):null},[n.branch,n.directory,n.isArchivedBucket,n.isMain,i]),Oe=Hu(Ie),Me=Oe?`var(--pr-${Oe.visualState})`:void 0,Fe=Ku(),je=l.useMemo(()=>{const Be=n.folderScopes?.map(Xe=>jt(Xe.directory))??[jt(n.directory??null)];return[...new Set(Be.filter(Xe=>!!Xe))]},[n.directory,n.folderScopes]);l.useSyncExternalStore(l.useCallback(Be=>je.length>0?Fe.subscribeBootstrap(Be):()=>{},[je.length,Fe]),l.useCallback(()=>je.map(Be=>`${Be}\0${Fe.getBootstrapState(Be)??""}\0${Fe.getBootstrapFailure(Be)??""}`).join(""),[je,Fe]),l.useCallback(()=>"",[]));const Ne=je.some(Be=>{const Xe=Fe.getBootstrapState(Be);return Xe==="queued"||Xe==="running"}),Pe=je.find(Be=>Fe.getBootstrapState(Be)==="failed")??null,se=Pe?Fe.getBootstrapFailure(Pe):void 0,oe=se==="os-permission"&&oh(),[Ee,J]=l.useState(!1),re=l.useCallback(()=>{Pe&&Fe.requestBootstrap({directory:Pe,priority:pe?"visible":"expanded",reason:n.isMain?"project-expanded":"worktree-expanded",force:!0})},[Fe,Pe,n.isMain,pe]),ee=l.useCallback(async()=>{if(!(!Pe||!oe||Ee)){J(!0);try{(await ih(Pe)).success&&re()}finally{J(!1)}}},[oe,Pe,Ee,re]),$=m??(p?10:5),de=Math.max($,u??$),Y=c?q?.groupMatches===!0:!1,ue=c,Te=l.useMemo(()=>[...ue?q?.filteredNodes??[]:n.sessions].sort(ae),[ae,n.sessions,q?.filteredNodes,ue]),Ge=n.folderScopeKey??jt(n.directory??null),_e=l.useMemo(()=>n.folderScopes&&n.folderScopes.length>0?n.folderScopes:Ge?[{scopeKey:Ge,directory:n.directory??null}]:[],[Ge,n.directory,n.folderScopes]),ie=l.useMemo(()=>_e.flatMap(({scopeKey:Be,directory:Xe})=>(me[Be]??[]).map(Je=>({folder:Je,scopeKey:Be,scopeDirectory:Xe}))),[_e,me]),Re=l.useMemo(()=>{const Be=new Map,Xe=Je=>{Je.forEach(He=>{Be.set(He.session.id,He),He.children.length>0&&Xe(He.children)})};return Xe(Te),Be},[Te]),be=l.useMemo(()=>ie.map(({folder:Be,scopeKey:Xe,scopeDirectory:Je})=>{const He=tj(Be.sessionIds,Re).sort(ae);return{folder:Be,scopeKey:Xe,scopeDirectory:Je,nodes:He}}),[ie,Re,ae]),T=l.useMemo(()=>{const Be=new Map(be.map(rt=>[rt.folder.id,rt])),Xe=new Map;for(const{folder:rt}of be){if(!rt.parentId)continue;const Dt=Xe.get(rt.parentId);Dt?Dt.push(rt.id):Xe.set(rt.parentId,[rt.id])}const Je=new Map,He=rt=>{const Dt=Je.get(rt);if(Dt!==void 0)return Dt;const Wt=Be.get(rt);if(!Wt)return Je.set(rt,!1),!1;const rs=Xe.get(rt)??[];if(n.isArchivedBucket&&Wt.nodes.length===0){const es=rs.some(Us=>He(Us));return Je.set(rt,es),es}if(!c||Wt.folder.name.toLowerCase().includes(a)||Wt.nodes.length>0)return Je.set(rt,!0),!0;const os=rs.some(es=>He(es));return Je.set(rt,os),os};return be.filter(({folder:rt})=>He(rt.id))},[be,n.isArchivedBucket,c,a]),ce=l.useMemo(()=>new Set(T.flatMap(Be=>Be.folder.sessionIds)),[T]),ve=l.useMemo(()=>Te.filter(Be=>!ce.has(Be.session.id)),[Te,ce]),Ce=l.useMemo(()=>T.filter(({folder:Be})=>!Be.parentId),[T]),Ae=l.useMemo(()=>{const Be=new Map;return T.forEach(Xe=>{if(!Xe.folder.parentId)return;const Je=Be.get(Xe.folder.parentId)??[];Je.push(Xe),Be.set(Xe.folder.parentId,Je)}),Be},[T]),ne=l.useMemo(()=>{const Be=new Map(T.map(He=>[He.folder.id,He])),Xe=new Map,Je=(He,rt)=>{const Dt=Xe.get(He);if(Dt!==void 0)return Dt;if(rt.has(He))return null;rt.add(He);const Wt=Be.get(He);let rs=Wt?Ed(Wt.nodes,X,le,te):null;for(const Lt of Ae.get(He)??[])if(rs=Hl(rs,Je(Lt.folder.id,rt)),rs==="active")break;return Xe.set(He,rs),rs};return T.forEach(({folder:He})=>Je(He.id,new Set)),Xe},[X,T,Ae,te,le]),ke="project",Ze=l.useMemo(()=>{const Be=new Set;return ul(Te,V,Be),T.forEach(({nodes:Xe})=>{ul(Xe,V,Be)}),Be},[Te,T,V]),Q=l.useMemo(()=>{if(!Z)return null;const Be=Bo(Te,Z,ke,!!n.isArchivedBucket);if(Be)return Be;for(const{nodes:Xe}of T){const Je=Bo(Xe,Z,ke,!!n.isArchivedBucket);if(Je)return Je}return null},[Z,Te,T,n.isArchivedBucket]),ye=l.useCallback(Be=>{const Xe=new WeakMap,Je=He=>{Xe.set(He,Ui(He));for(const rt of He.children)Je(rt)};return Be.forEach(Je),Xe},[]),Qe=l.useMemo(()=>ye(Te),[ye,Te]),$e=l.useMemo(()=>{const Be=new WeakMap;return T.forEach(({nodes:Xe})=>{Xe.forEach(Je=>Be.set(Je,Ui(Je)))}),Be},[T]),ze=l.useCallback(Be=>Qe.get(Be)??$e.get(Be)??"",[Qe,$e]),Le=l.useCallback(Be=>({subtreeContainsEditing:Ze,menuOpenSessionId:Q,nodeStructureKey:ze(Be)}),[Ze,Q,ze]),st=ve.length,ct=n.isArchivedBucket||c?ve:ve.slice(0,de),Pt=st-ct.length,It=!n.isArchivedBucket&&!c&&st>$&&Pt===0,Tt=n.isArchivedBucket===!0&&!c&&ct.length>=nj,et=n.isArchivedBucket?"archived":"active",Mt=Tt&&ct.some(Be=>{if(Be.children.length===0)return!1;const Xe=`project:${et}:${Be.session.id}`;return z.has(Xe)}),kt=l.useRef(null),[bt,Bt]=l.useState(null),[wt,Rt]=l.useState(0),[,pt]=l.useState(0);l.useEffect(()=>{if(!Tt)return;const Be=kt.current;if(!Be||typeof ResizeObserver>"u")return;const Xe=new ResizeObserver(()=>pt(Je=>Je+1));return Xe.observe(Be),()=>Xe.disconnect()},[Tt]),l.useLayoutEffect(()=>{if(!Tt){bt!==null&&Bt(null),wt!==0&&Rt(0);return}const Be=kt.current;if(!Be)return;let Xe=bt;const Je=Se?.current??null;if(Je&&Je.contains(Be)){if(Xe=Je,Xe!==bt){Bt(Xe);return}}else if(!Xe||!Xe.contains(Be)){let rt=Be.parentElement;for(;rt;){const Dt=window.getComputedStyle(rt);if(Dt.overflowY==="auto"||Dt.overflowY==="scroll"){Xe=rt;break}rt=rt.parentElement}if(Xe!==bt){Bt(Xe);return}}if(!Xe)return;const He=Be.getBoundingClientRect().top-Xe.getBoundingClientRect().top+Xe.scrollTop;Rt(rt=>Math.abs(rt-He)<1?rt:He)});const yt=Tt&&bt!==null,Ke=Ix({count:ct.length,enabled:yt,getScrollElement:()=>bt,initialOffset:()=>bt?.scrollTop??0,estimateSize:()=>rj,overscan:Mt?20:8,scrollMargin:wt,getItemKey:Be=>ct[Be]?.session.id??Be}),Ue=l.useCallback(Be=>{const Xe=[],Je=He=>{He.forEach(rt=>{Xe.push(rt.session),rt.children.length>0&&Je(rt.children)})};return Je(Be),Xe},[]),xt=l.useMemo(()=>Ue(Te),[Ue,Te]),Ft=l.useMemo(()=>{if(!n.isArchivedBucket)return new Map;const Be=new Map,Xe=new Map;for(const{folder:He}of T){if(!He.parentId)continue;const rt=Xe.get(He.parentId)??[];rt.push(He.id),Xe.set(He.parentId,rt)}const Je=(He,rt)=>{if(rt.has(He))return[];rt.add(He);const Dt=T.find(({folder:Lt})=>Lt.id===He),Wt=Dt?Ue(Dt.nodes):[],rs=Xe.get(He)??[];for(const Lt of rs)Wt.push(...Je(Lt,rt));return Wt};for(const{folder:He}of T)Be.set(He.id,Je(He.id,new Set));return Be},[T,Ue,n.isArchivedBucket]);if(c&&!Y&&Ce.length===0&&ve.length===0)return null;const $t=!n.isMain&&!!n.branch,ns=n.branch&&gp(n.branch,n.label)?{label:n.branch}:null,Kt=pe?Ed(Te,X,le,te):null,St=Kt?s.jsx(om,{state:Kt,activeLabel:e("sessions.sidebar.session.status.active"),unreadLabel:e("sessions.sidebar.session.status.unread")}):null,zt=(Be,Xe)=>{const{folder:Je,scopeKey:He,scopeDirectory:rt,nodes:Dt}=Be,Wt=Ft.get(Je.id)??[],rs=c?!1:b.has(Je.id);return s.jsx(J0,{folderId:Je.id,children:(Lt,os)=>s.jsx($0,{folder:Je,displayName:Xe,sessions:Dt,isCollapsed:rs,collapsedActivityState:rs?ne.get(Je.id)??null:null,onToggle:()=>k(Je.id),onRename:es=>{v(He,Je.id,es)},onDelete:()=>{if(n.isArchivedBucket){Un.requestDelete({sessions:Wt,mode:"session"});return}if(!h){g(He,Je.id);return}const es=T.filter(({folder:Ws})=>Ws.parentId===Je.id).length,Us=Dt.length;S({scopeKey:He,folderId:Je.id,folderName:Je.name,subFolderCount:es,sessionCount:Us})},renderSessionNode:y,getRenderExtras:ze?es=>({subtreeContainsEditing:Ze,menuOpenSessionId:Q,nodeStructureKey:ze(es),childRenderExtrasFor:Le}):void 0,groupDirectory:rt??n.directory,projectId:o,mobileVariant:N,alwaysShowActions:w,isRenaming:L===Je.id,renameDraft:L===Je.id?W:void 0,onRenameDraftChange:es=>K(es),onRenameSave:()=>{const es=W.trim();es&&v(He,Je.id,es),x(null),K("")},onRenameCancel:()=>{x(null),K("")},droppableRef:Lt,isDropTarget:os,depth:0,onNewSession:()=>{o&&o!==A&&D(o),P("chat"),N&&B(!1),F({selectedProjectId:o,directoryOverride:rt??n.directory,targetFolderId:Je.id,target:n.draftTarget})},hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},Je.id)},ms=()=>{const Be=new Map;for(const He of T){const rt=He.folder.parentId;if(!rt)continue;const Dt=Be.get(rt);Dt?Dt.push(He):Be.set(rt,[He])}const Xe=[],Je=(He,rt)=>{const Dt=rt?`${rt} / ${He.folder.name}`:He.folder.name;Xe.push(zt(He,Dt)),!(!c&&b.has(He.folder.id))&&(Be.get(He.folder.id)??[]).forEach(rs=>Je(rs,Dt))};return Ce.forEach(He=>Je(He,"")),Xe},ts=!!(!n.isMain&&n.worktree),ys=w?ts?"pr-14":"pr-7":ts?"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",Vt=Pe?s.jsxs("span",{className:"inline-flex flex-wrap items-center gap-1.5",children:[e(se==="os-permission"?"sessions.sidebar.group.empty.permissionDenied":"sessions.sidebar.group.empty.loadFailed"),oe?s.jsx(lt,{variant:"link",size:"xs",className:"h-auto p-0 typography-micro",disabled:Ee,onClick:()=>{ee()},children:e("sessions.sidebar.group.empty.grantAccess")}):null,s.jsx(lt,{variant:"link",size:"xs",className:"h-auto p-0 typography-micro",onClick:re,children:e("sessions.sidebar.group.empty.retry")})]}):null,Gt=s.jsxs(Z0,{scopeKey:_e[0]?.scopeKey??Ge,hasFolders:T.length>0,onSessionDroppedOnFolder:(Be,Xe)=>{const Je=T.find(({folder:rt})=>rt.id===Xe);if(!Je)return;const He=Gs.getState();for(const{scopeKey:rt}of _e)rt!==Je.scopeKey&&He.getSessionFolderId(rt,Be)&&He.removeSessionFromFolder(rt,Be);E(Je.scopeKey,Xe,Be)},children:[ms(),Tt?s.jsx("div",{ref:kt,children:yt?s.jsx("div",{style:{height:Ke.getTotalSize(),position:"relative"},children:Ke.getVirtualItems().map(Be=>{const Xe=ct[Be.index];return Xe?s.jsx("div",{"data-index":Be.index,ref:Ke.measureElement,className:"[&_[data-session-row]]:my-px",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${Be.start-wt}px)`},children:y(Xe,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsEditing:Ze,menuOpenSessionId:Q,nodeStructureKey:ze(Xe),childRenderExtrasFor:Le})},Xe.session.id):null})}):ct.map(Be=>y(Be,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsEditing:Ze,menuOpenSessionId:Q,nodeStructureKey:ze(Be),childRenderExtrasFor:Le}))}):ct.map(Be=>y(Be,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsEditing:Ze,menuOpenSessionId:Q,nodeStructureKey:ze(Be),childRenderExtrasFor:Le})),st===0&&T.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(I,{name:"loader-4",className:"size-3 animate-spin"}),e("sessions.sidebar.group.empty.loadingSessions")]}):Vt||(n.emptyMessage??e("sessions.sidebar.group.empty.noSessionsInWorkspace"))}):null,st>0&&Vt?s.jsx("div",{className:"py-1 pl-[26px] text-left typography-micro text-status-error",children:Vt}):null,Pt>0?s.jsx("button",{type:"button",onClick:()=>j(r,ct.length,m??7),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,It?s.jsx("button",{type:"button",onClick:()=>C(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]}),Ut="pb-2";return i?s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:xe("oc-group-body",Ut),children:Gt})}):s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:xe("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>fe(r),role:"button",tabIndex:0,onKeyDown:Be=>{(Be.key==="Enter"||Be.key===" ")&&(Be.preventDefault(),fe(r))},"aria-label":pe?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!pe,children:[s.jsx("div",{ref:ge?.setActivatorNodeRef,className:xe("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-1.5 transition-[padding]",ys),...ge?.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(I,{name:"archive",className:xe("h-3.5 w-3.5 shrink-0 text-muted-foreground",w?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:xe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",w?"inline-flex":"hidden group-hover/gh:inline-flex"),children:pe?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:bi(n.label,a)}),St]}):!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(I,{name:"git-branch",className:xe("h-3.5 w-3.5 shrink-0",!Me&&"text-muted-foreground",w?"hidden":"group-hover/gh:hidden"),style:Me?{color:Me}:void 0}),s.jsx("span",{className:xe("text-muted-foreground h-3.5 w-3.5 items-center justify-center",w?"inline-flex":"hidden group-hover/gh:inline-flex"),children:pe?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{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:bi(n.label,a)}),St,Oe?s.jsxs("span",{className:"ml-auto flex-shrink-0 text-[0.72rem] font-medium leading-none",style:Me?{color:Me}:void 0,children:["#",Oe.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:bi(n.label,a)}),St]})}),$t&&ns?s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5 leading-tight",children:[n.isArchivedBucket?s.jsx(I,{name:"archive",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}):s.jsx(I,{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:ns.label})]}):null]})}),n.isArchivedBucket&&xt.length>0?s.jsx("div",{className:xe("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",w?"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:Be=>{Be.stopPropagation(),Un.requestDelete({sessions:xt,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(I,{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:xe("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",w?"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:Be=>{Be.stopPropagation(),Un.requestDelete({sessions:xt,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(I,{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:xe("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",w?"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:Be=>{Be.stopPropagation(),o&&o!==A&&D(o),P("chat"),N&&B(!1),F({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(I,{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]}),pe?null:s.jsx("div",{className:xe("oc-group-body",Ut),children:Gt})]})}const uj=l.memo(dj,cj);function fj(t){const e=it.c(213),{t:n}=gt(),{hideDirectoryControls:r,showProjectDisplayControls:o,showRecentControls:i,handleOpenDirectoryDialog:c,onOpenScheduled:a,onOpenMultiRun:d,canOpenMultiRun:u,onOpenArchive:m,headerActionIconClass:f,headerActionButtonClass:p,isSessionSearchOpen:b,setIsSessionSearchOpen:k,sessionSearchInputRef:v,sessionSearchQuery:g,setSessionSearchQuery:h,hasSessionSearchQuery:S,searchMatchCount:y,collapseAllProjects:j,expandAllProjects:C,selectionModeEnabled:N,onToggleSelectionMode:w}=t,A=xs(jj),D=xs(Sj),P=xs(wj),B=xs(vj),F=xs(yj),E=xs(bj),_=xs(xj),L=xs(gj),W=xs(pj),K=xs(hj),x=o&&W==="single";if(r)return null;let M;e[0]!==p?(M=xe(p,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[0]=p,e[1]=M):M=e[1];let z;e[2]!==n?(z=n("sessions.sidebar.header.actions.addProject"),e[2]=n,e[3]=z):z=e[3];let U;e[4]!==f?(U=s.jsx(I,{name:"folder-add",className:f}),e[4]=f,e[5]=U):U=e[5];let V;e[6]!==c||e[7]!==M||e[8]!==z||e[9]!==U?(V=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,className:M,"aria-label":z,children:U})}),e[6]=c,e[7]=M,e[8]=z,e[9]=U,e[10]=V):V=e[10];let Z;e[11]!==n?(Z=n("sessions.sidebar.header.actions.addProject"),e[11]=n,e[12]=Z):Z=e[12];let X;e[13]!==Z?(X=s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Z})}),e[13]=Z,e[14]=X):X=e[14];let le;e[15]!==V||e[16]!==X?(le=s.jsxs(ft,{delayDuration:500,children:[V,X]}),e[15]=V,e[16]=X,e[17]=le):le=e[17];let te;e[18]!==p?(te=xe(p,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[18]=p,e[19]=te):te=e[19];let fe;e[20]!==n?(fe=n("sessions.sidebar.header.actions.scheduledTasks"),e[20]=n,e[21]=fe):fe=e[21];let ge;e[22]!==f?(ge=s.jsx(I,{name:"calendar-schedule",className:f}),e[22]=f,e[23]=ge):ge=e[23];let H;e[24]!==a||e[25]!==te||e[26]!==fe||e[27]!==ge?(H=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:a,className:te,"aria-label":fe,children:ge})}),e[24]=a,e[25]=te,e[26]=fe,e[27]=ge,e[28]=H):H=e[28];let Se;e[29]!==n?(Se=n("sessions.sidebar.header.actions.scheduledTasks"),e[29]=n,e[30]=Se):Se=e[30];let ae;e[31]!==Se?(ae=s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Se})}),e[31]=Se,e[32]=ae):ae=e[32];let q;e[33]!==H||e[34]!==ae?(q=s.jsxs(ft,{delayDuration:500,children:[H,ae]}),e[33]=H,e[34]=ae,e[35]=q):q=e[35];let me;e[36]!==p?(me=xe(p,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[36]=p,e[37]=me):me=e[37];let pe;e[38]!==n?(pe=n("sessions.sidebar.header.actions.newMultiRun"),e[38]=n,e[39]=pe):pe=e[39];const Ie=!u;let Oe;e[40]!==f?(Oe=s.jsx(xp,{className:f}),e[40]=f,e[41]=Oe):Oe=e[41];let Me;e[42]!==d||e[43]!==me||e[44]!==pe||e[45]!==Ie||e[46]!==Oe?(Me=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:d,className:me,"aria-label":pe,disabled:Ie,children:Oe})}),e[42]=d,e[43]=me,e[44]=pe,e[45]=Ie,e[46]=Oe,e[47]=Me):Me=e[47];let Fe;e[48]!==n?(Fe=n("sessions.sidebar.header.actions.newMultiRun"),e[48]=n,e[49]=Fe):Fe=e[49];let je;e[50]!==Fe?(je=s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Fe})}),e[50]=Fe,e[51]=je):je=e[51];let Ne;e[52]!==Me||e[53]!==je?(Ne=s.jsxs(ft,{delayDuration:500,children:[Me,je]}),e[52]=Me,e[53]=je,e[54]=Ne):Ne=e[54];let Pe;e[55]!==p?(Pe=xe(p,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[55]=p,e[56]=Pe):Pe=e[56];let se;e[57]!==n?(se=n("sessions.sidebar.nav.archive"),e[57]=n,e[58]=se):se=e[58];let oe;e[59]!==f?(oe=s.jsx(I,{name:"archive",className:f}),e[59]=f,e[60]=oe):oe=e[60];let Ee;e[61]!==m||e[62]!==Pe||e[63]!==se||e[64]!==oe?(Ee=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:m,className:Pe,"aria-label":se,children:oe})}),e[61]=m,e[62]=Pe,e[63]=se,e[64]=oe,e[65]=Ee):Ee=e[65];let J;e[66]!==n?(J=n("sessions.sidebar.nav.archive"),e[66]=n,e[67]=J):J=e[67];let re;e[68]!==J?(re=s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:J})}),e[68]=J,e[69]=re):re=e[69];let ee;e[70]!==Ee||e[71]!==re?(ee=s.jsxs(ft,{delayDuration:500,children:[Ee,re]}),e[70]=Ee,e[71]=re,e[72]=ee):ee=e[72];let $;e[73]!==q||e[74]!==Ne||e[75]!==ee||e[76]!==le?($=s.jsxs("div",{className:"ml-[3px] flex items-center gap-1.5",children:[le,q,Ne,ee]}),e[73]=q,e[74]=Ne,e[75]=ee,e[76]=le,e[77]=$):$=e[77];let de;e[78]!==k?(de=()=>k(mj),e[78]=k,e[79]=de):de=e[79];let Y;e[80]!==p?(Y=xe(p,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[80]=p,e[81]=Y):Y=e[81];let ue;e[82]!==n?(ue=n("sessions.sidebar.header.actions.searchSessions"),e[82]=n,e[83]=ue):ue=e[83];let Te;e[84]!==f?(Te=s.jsx(I,{name:"search",className:f}),e[84]=f,e[85]=Te):Te=e[85];let Ge;e[86]!==b||e[87]!==de||e[88]!==Y||e[89]!==ue||e[90]!==Te?(Ge=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:de,className:Y,"aria-label":ue,"aria-expanded":b,children:Te})}),e[86]=b,e[87]=de,e[88]=Y,e[89]=ue,e[90]=Te,e[91]=Ge):Ge=e[91];let _e;e[92]!==n?(_e=n("sessions.sidebar.header.actions.searchSessions"),e[92]=n,e[93]=_e):_e=e[93];let ie;e[94]!==_e?(ie=s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:_e})}),e[94]=_e,e[95]=ie):ie=e[95];let Re;e[96]!==Ge||e[97]!==ie?(Re=s.jsxs(ft,{delayDuration:500,children:[Ge,ie]}),e[96]=Ge,e[97]=ie,e[98]=Re):Re=e[98];const be=N&&"bg-interactive-hover text-primary";let T;e[99]!==p||e[100]!==be?(T=xe(p,"text-muted-foreground hover:text-foreground hover:bg-transparent",be),e[99]=p,e[100]=be,e[101]=T):T=e[101];let ce;e[102]!==N||e[103]!==n?(ce=n(N?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[102]=N,e[103]=n,e[104]=ce):ce=e[104];let ve;e[105]!==f?(ve=s.jsx(I,{name:"checkbox-multiple",className:f}),e[105]=f,e[106]=ve):ve=e[106];let Ce;e[107]!==w||e[108]!==N||e[109]!==T||e[110]!==ce||e[111]!==ve?(Ce=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:w,className:T,"aria-label":ce,"aria-pressed":N,children:ve})}),e[107]=w,e[108]=N,e[109]=T,e[110]=ce,e[111]=ve,e[112]=Ce):Ce=e[112];let Ae;e[113]!==N||e[114]!==n?(Ae=n(N?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[113]=N,e[114]=n,e[115]=Ae):Ae=e[115];let ne;e[116]!==Ae?(ne=s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Ae})}),e[116]=Ae,e[117]=ne):ne=e[117];let ke;e[118]!==Ce||e[119]!==ne?(ke=s.jsxs(ft,{delayDuration:500,children:[Ce,ne]}),e[118]=Ce,e[119]=ne,e[120]=ke):ke=e[120];let Ze;e[121]!==p?(Ze=xe(p,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[121]=p,e[122]=Ze):Ze=e[122];let Q;e[123]!==n?(Q=n("sessions.sidebar.header.displayMode.label"),e[123]=n,e[124]=Q):Q=e[124];let ye;e[125]!==f?(ye=s.jsx(I,{name:"equalizer-2",className:f}),e[125]=f,e[126]=ye):ye=e[126];let Qe;e[127]!==Ze||e[128]!==Q||e[129]!==ye?(Qe=s.jsx(mt,{asChild:!0,children:s.jsx(cn,{asChild:!0,children:s.jsx("button",{type:"button",className:Ze,"aria-label":Q,children:ye})})}),e[127]=Ze,e[128]=Q,e[129]=ye,e[130]=Qe):Qe=e[130];let $e;e[131]!==n?($e=n("sessions.sidebar.header.displayMode.label"),e[131]=n,e[132]=$e):$e=e[132];let ze;e[133]!==$e?(ze=s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:$e})}),e[133]=$e,e[134]=ze):ze=e[134];let Le;e[135]!==Qe||e[136]!==ze?(Le=s.jsxs(ft,{delayDuration:500,children:[Qe,ze]}),e[135]=Qe,e[136]=ze,e[137]=Le):Le=e[137];let st;e[138]!==n?(st=n("sessions.sidebar.header.actions.sortProjects"),e[138]=n,e[139]=st):st=e[139];let ct;e[140]!==st?(ct=s.jsx(xi,{children:st}),e[140]=st,e[141]=ct):ct=e[141];let Pt;e[142]!==P||e[143]!==B||e[144]!==n?(Pt=[["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(St=>{const[zt,ms]=St;return s.jsxs(Ht,{onClick:()=>{B(zt),Yr({sidebarProjectSortOrder:zt})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n(ms)}),P===zt?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]},zt)}),e[142]=P,e[143]=B,e[144]=n,e[145]=Pt):Pt=e[145];let It;e[146]===Symbol.for("react.memo_cache_sentinel")?(It=s.jsx(ln,{}),e[146]=It):It=e[146];let Tt;e[147]!==W||e[148]!==K||e[149]!==o||e[150]!==n?(Tt=o?s.jsxs(s.Fragment,{children:[s.jsx(xi,{children:n("sessions.sidebar.header.projectDisplay.label")}),[["all","sessions.sidebar.header.projectDisplay.all"],["single","sessions.sidebar.header.projectDisplay.single"]].map(St=>{const[zt,ms]=St;return s.jsxs(Ht,{onClick:()=>{K(zt),Yr({sidebarProjectDisplayMode:zt})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n(ms)}),W===zt?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]},zt)}),s.jsx(ln,{})]}):null,e[147]=W,e[148]=K,e[149]=o,e[150]=n,e[151]=Tt):Tt=e[151];let et;e[152]!==n?(et=n("sessions.sidebar.header.grouping.label"),e[152]=n,e[153]=et):et=e[153];let Mt;e[154]!==et?(Mt=s.jsx(xi,{children:et}),e[154]=et,e[155]=Mt):Mt=e[155];let kt;e[156]!==F||e[157]!==E||e[158]!==n?(kt=[["by-worktree","sessions.sidebar.header.grouping.byWorktree"],["flat","sessions.sidebar.header.grouping.flat"]].map(St=>{const[zt,ms]=St;return s.jsxs(Ht,{onClick:()=>{E(zt),Yr({sidebarSessionGroupingMode:zt})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n(ms)}),F===zt?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]},zt)}),e[156]=F,e[157]=E,e[158]=n,e[159]=kt):kt=e[159];let bt;e[160]===Symbol.for("react.memo_cache_sentinel")?(bt=s.jsx(ln,{}),e[160]=bt):bt=e[160];let Bt;e[161]!==x||e[162]!==i||e[163]!==A||e[164]!==n||e[165]!==D?(Bt=i&&!x?s.jsxs(Ht,{onClick:()=>{D(),Yr({sidebarShowRecentSection:!A})},className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),A?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]}):null,e[161]=x,e[162]=i,e[163]=A,e[164]=n,e[165]=D,e[166]=Bt):Bt=e[166];let wt;e[167]!==n?(wt=n("sessions.sidebar.header.displayMode.stickyHeaders"),e[167]=n,e[168]=wt):wt=e[168];let Rt;e[169]!==wt?(Rt=s.jsx("span",{children:wt}),e[169]=wt,e[170]=Rt):Rt=e[170];let pt;e[171]!==_?(pt=_?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null,e[171]=_,e[172]=pt):pt=e[172];let yt;e[173]!==Rt||e[174]!==pt||e[175]!==L?(yt=s.jsxs(Ht,{onClick:L,className:"flex items-center justify-between",children:[Rt,pt]}),e[173]=Rt,e[174]=pt,e[175]=L,e[176]=yt):yt=e[176];let Ke;e[177]!==j||e[178]!==C||e[179]!==x||e[180]!==n?(Ke=x?null:s.jsxs(s.Fragment,{children:[s.jsx(ln,{}),s.jsxs(Ht,{onClick:j,className:"flex items-center gap-2",children:[s.jsx(I,{name:"contract-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.collapseAll")})]}),s.jsxs(Ht,{onClick:C,className:"flex items-center gap-2",children:[s.jsx(I,{name:"expand-up-down",className:"h-4 w-4"}),s.jsx("span",{children:n("sessions.sidebar.header.displayMode.expandAll")})]})]}),e[177]=j,e[178]=C,e[179]=x,e[180]=n,e[181]=Ke):Ke=e[181];let Ue;e[182]!==ct||e[183]!==Pt||e[184]!==Tt||e[185]!==Mt||e[186]!==kt||e[187]!==Bt||e[188]!==yt||e[189]!==Ke?(Ue=s.jsxs(dn,{align:"end",className:"min-w-[180px]",children:[ct,Pt,It,Tt,Mt,kt,bt,Bt,yt,Ke]}),e[182]=ct,e[183]=Pt,e[184]=Tt,e[185]=Mt,e[186]=kt,e[187]=Bt,e[188]=yt,e[189]=Ke,e[190]=Ue):Ue=e[190];let xt;e[191]!==Le||e[192]!==Ue?(xt=s.jsxs(un,{children:[Le,Ue]}),e[191]=Le,e[192]=Ue,e[193]=xt):xt=e[193];let Ft;e[194]!==Re||e[195]!==ke||e[196]!==xt?(Ft=s.jsxs("div",{className:"flex items-center gap-1.5",children:[Re,ke,xt]}),e[194]=Re,e[195]=ke,e[196]=xt,e[197]=Ft):Ft=e[197];let $t;e[198]!==$||e[199]!==Ft?($t=s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[$,Ft]}),e[198]=$,e[199]=Ft,e[200]=$t):$t=e[200];let ns;e[201]!==S||e[202]!==b||e[203]!==y||e[204]!==v||e[205]!==g||e[206]!==k||e[207]!==h||e[208]!==n?(ns=b?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:[S?s.jsx("span",{children:y===1?n("sessions.sidebar.header.search.matchCountSingle",{count:y}):n("sessions.sidebar.header.search.matchCountPlural",{count:y})}):s.jsx("span",{}),s.jsx("span",{children:n("sessions.sidebar.header.search.escapeHint")})]}),s.jsxs("div",{className:"relative",children:[s.jsx(I,{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:v,value:g,onChange:St=>h(St.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:St=>{St.key==="Escape"&&(St.stopPropagation(),S?h(""):k(!1))}}),g.length>0?s.jsx("button",{type:"button",onClick:()=>h(""),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(I,{name:"close",className:"h-3.5 w-3.5"})}):null]})]}):null,e[201]=S,e[202]=b,e[203]=y,e[204]=v,e[205]=g,e[206]=k,e[207]=h,e[208]=n,e[209]=ns):ns=e[209];let Kt;return e[210]!==$t||e[211]!==ns?(Kt=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:[$t,ns]})}),e[210]=$t,e[211]=ns,e[212]=Kt):Kt=e[212],Kt}function mj(t){return!t}function hj(t){return t.setProjectDisplayMode}function pj(t){return t.projectDisplayMode}function gj(t){return t.toggleStickyZoneHeaders}function xj(t){return t.stickyZoneHeaders}function bj(t){return t.setSessionGroupingMode}function yj(t){return t.sessionGroupingMode}function vj(t){return t.setProjectSortOrder}function wj(t){return t.projectSortOrder}function Sj(t){return t.toggleRecentSection}function jj(t){return t.showRecentSection}function kj(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(I,{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 Id=7;function Cj(t){const{sections:e,renderSessionNode:n,editingId:r,openSidebarMenuKey:o,variant:i="section",initialVisibleCount:c=Id,batchSize:a=Id}=t,{t:d}=gt(),u=xs(j=>j.stickyZoneHeaders),[m,f]=l.useState(new Set),[p,b]=l.useState(new Map),k=i==="flat",v=l.useCallback(j=>{b(C=>{if(!C.has(j))return C;const N=new Map(C);return N.delete(j),N})},[]),g=l.useCallback(j=>{v(j),f(C=>{const N=new Set(C);return N.has(j)?N.delete(j):N.add(j),N})},[v]),h=l.useCallback((j,C,N)=>{b(w=>{const A=Math.min(N,C+a),D=new Map(w);return D.set(j,A),D})},[a]),S=l.useCallback(j=>{const C=new Set;ul(j,r,C);const N=Bo(j,o,"recent",!1),w=new WeakMap,A=P=>{w.set(P,Ui(P)),P.children.forEach(A)};j.forEach(A);const D=P=>({subtreeContainsEditing:C,menuOpenSessionId:N,nodeStructureKey:w.get(P)??"",childRenderExtrasFor:D});return P=>({subtreeContainsEditing:C,menuOpenSessionId:N,nodeStructureKey:w.get(P)??"",childRenderExtrasFor:D})},[r,o]),y=e.filter(j=>j.items.length>0||j.key==="chats"&&t.onNewChat);return y.length===0?null:s.jsx("div",{className:xe(k?"space-y-0.5 pb-2":"space-y-2 pb-2"),children:y.map(j=>{const C=m.has(j.key),N=Math.max(c,p.get(j.key)??c),w=j.items.slice(0,N),A=j.items.length-w.length,D=j.key==="chats"&&!!t.renderChatsSection,P=!D&&!k&&j.items.length>c&&A===0,B=S(w.map(E=>E.node)),F=E=>n(E.node,0,E.groupDirectory,E.projectId,!1,E.secondaryMeta,"recent",B(E.node));return k?s.jsxs("div",{className:"space-y-0.5",children:[w.map(F),A>0?s.jsx("button",{type:"button",onClick:()=>h(j.key,w.length,j.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]},j.key):s.jsxs("div",{className:"relative space-y-1",children:[s.jsx("div",{className:"absolute h-px w-px pointer-events-none","data-sidebar-activity-sentinel":j.key,"aria-hidden":"true"}),s.jsxs("div",{className:xe("relative group/chats","-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:()=>g(j.key),className:xe("group flex w-full items-center gap-1.5 py-1 pl-4 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",j.key==="chats"&&t.onNewChat?"pr-10":"pr-3.5"),"aria-expanded":!C,children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 items-center justify-center",children:[s.jsx(I,{name:j.key==="chats"?"chat-4":"history",className:xe("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:C?s.jsx(I,{name:"arrow-right-s",className:"h-3.5 w-3.5"}):s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5"})})]}),s.jsx("span",{className:"text-[14px] font-semibold lowercase text-foreground",children:j.title})]}),j.key==="chats"&&t.onNewChat?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:E=>{E.stopPropagation(),t.onNewChat?.()},className:xe("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",t.alwaysShowActions?"opacity-100":"opacity-0 pointer-events-none group-hover/chats:opacity-100 group-hover/chats:pointer-events-auto group-focus-within/chats:opacity-100 group-focus-within/chats:pointer-events-auto"),"aria-label":d("sessions.sidebar.header.actions.newSession"),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})}),s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:d("sessions.sidebar.header.actions.newSession")})})]})}):null]}),C?null:s.jsxs("div",{className:xe("space-y-0.5"),children:[j.key==="chats"&&t.renderChatsSection?t.renderChatsSection(j.items):w.map(F),!D&&A>0?s.jsx("button",{type:"button",onClick:()=>h(j.key,w.length,j.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:()=>v(j.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]})]},j.key)})})}const Ma="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 Nj(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:Ma,"aria-label":m("sessions.sidebar.footer.actions.settings"),children:s.jsx(I,{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:Ma,"aria-label":m("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(I,{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:Ma,"aria-label":m("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(I,{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 p;e[6]!==i||e[7]!==u||e[8]!==m?(p=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]=p):p=e[9];let b;return e[10]!==f||e[11]!==p?(b=s.jsxs("div",{className:"flex shrink-0 items-center justify-start gap-1 px-2.5 py-2",children:[f,p]}),e[10]=f,e[11]=p,e[12]=b):b=e[12],b}const ki=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}=Br(),p=o?Al[o]:null,b=i?Dl[i]??null:null,k=d!==void 0,v=k?m?"hidden":"group-hover/project:hidden group-focus-within/project:hidden":void 0;let g;e[0]!==m||e[1]!==k||e[2]!==d?(g=k?s.jsx("span",{className:xe("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(I,{name:d?"arrow-right-s":"arrow-down-s",className:"h-3.5 w-3.5"})}):null,e[0]=m,e[1]=k,e[2]=d,e[3]=g):g=e[3];let h;e[4]!==m||e[5]!==f||e[6]!==k||e[7]!==b||e[8]!==v||e[9]!==n||e[10]!==a||e[11]!==c||e[12]!==p?(h=c?s.jsx("span",{className:xe("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",k&&m?"hidden":"inline-flex",v),style:a?{backgroundColor:a}:void 0,children:s.jsx(Pl,{project:{id:n,iconImage:c},options:{themeVariant:f.metadata.variant,iconColor:f.colors.surface.foreground},className:"h-full w-full object-contain",fallback:p?s.jsx(I,{name:p,className:"h-3.5 w-3.5",style:b?{color:b}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 text-muted-foreground/80",style:b?{color:b}:void 0})})}):p?s.jsx(I,{name:p,className:xe("h-3.5 w-3.5",v),style:b?{color:b}:void 0}):s.jsx(I,{name:"folder",className:xe("h-3.5 w-3.5 text-muted-foreground/80",v),style:b?{color:b}:void 0}),e[4]=m,e[5]=f,e[6]=k,e[7]=b,e[8]=v,e[9]=n,e[10]=a,e[11]=c,e[12]=p,e[13]=h):h=e[13];let S;e[14]!==g||e[15]!==h?(S=s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[g,h]}),e[14]=g,e[15]=h,e[16]=S):S=e[16];let y;e[17]!==r?(y=s.jsx("span",{className:"truncate text-[14px] font-semibold lowercase text-foreground",children:r}),e[17]=r,e[18]=y):y=e[18];let j;return e[19]!==S||e[20]!==y?(j=s.jsxs(s.Fragment,{children:[S,y]}),e[19]=S,e[20]=y,e[21]=j):j=e[21],j},Aj=t=>{const e=it.c(62),{id:n,disabled:r,projectLabel:o,projectDescription:i,projectIcon:c,projectColor:a,projectIconImage:d,projectIconBackground:u,isCollapsed:m,isRepo:f,isDesktopShell:p,hideDirectoryControls:b,alwaysShowActions:k,onToggle:v,onNewSession:g,onNewWorktreeSession:h,onManageWorktrees:S,onRenameStart:y,onClose:j,sentinelRef:C,children:N,showCreateButtons:w,hideHeader:A,openSidebarMenuKey:D,setOpenSidebarMenuKey:P,statusIndicator:B,projectPickerOptions:F,onProjectSelect:E}=t,_=r===void 0?!1:r,L=w===void 0?!0:w,W=A===void 0?!1:A,K=B===void 0?null:B,{t:x}=gt(),M=xs(Ej);let z;e[0]!==_||e[1]!==n?(z={id:n,disabled:_},e[0]=_,e[1]=n,e[2]=z):z=e[2];const{attributes:U,listeners:V,setNodeRef:Z,transform:X,transition:le,isDragging:te}=Rl(z),fe=l.useRef(!1),ge=`project:${n}`,H=D===ge,[Se,ae]=l.useState(!1);let q;e[3]!==ge||e[4]!==P?(q=Y=>{Y&&ae(!1),P(Y?ge:null)},e[3]=ge,e[4]=P,e[5]=q):q=e[5];const me=q;let pe;e[6]!==b||e[7]!==f||e[8]!==j||e[9]!==S||e[10]!==g||e[11]!==y||e[12]!==L||e[13]!==x?(pe=Y=>s.jsxs(s.Fragment,{children:[L&&!f&&!b&&g&&s.jsxs(Y,{onClick:g,children:[s.jsx(I,{name:"add",className:"mr-1.5 h-4 w-4"}),x("sessions.sidebar.project.actions.newSession")]}),f&&!b&&S&&s.jsxs(Y,{onClick:S,children:[s.jsx(I,{name:"node-tree",className:"mr-1.5 h-4 w-4"}),x("sessions.sidebar.project.actions.manageWorktrees")]}),s.jsxs(Y,{onClick:y,children:[s.jsx(I,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),x("sessions.sidebar.project.actions.edit")]}),s.jsxs(Y,{onClick:j,className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1.5 h-4 w-4"}),x("sessions.sidebar.project.actions.closeProject")]})]}),e[6]=b,e[7]=f,e[8]=j,e[9]=S,e[10]=g,e[11]=y,e[12]=L,e[13]=x,e[14]=pe):pe=e[14];const Ie=pe,Oe=Tj,Me=Ij,Fe=Mj;let je;e[15]===Symbol.for("react.memo_cache_sentinel")?(je=Y=>{(Y.button===2||Y.button===0&&Y.ctrlKey)&&(fe.current=!0)},e[15]=je):je=e[15];const Ne=je;let Pe;e[16]!==v?(Pe=Y=>{if(Y.currentTarget.blur(),fe.current){fe.current=!1;return}v()},e[16]=v,e[17]=Pe):Pe=e[17];const se=Pe,oe=!!(F&&E);let Ee;e[18]!==X?(Ee=Ol.Transform.toString(X),e[18]=X,e[19]=Ee):Ee=e[19];let J;e[20]!==Ee||e[21]!==le?(J={transform:Ee,transition:le},e[20]=Ee,e[21]=le,e[22]=J):J=e[22];const re=te&&"opacity-30";let ee;e[23]!==re?(ee=xe("relative",re),e[23]=re,e[24]=ee):ee=e[24];let $;e[25]!==k||e[26]!==U||e[27]!==me||e[28]!==se||e[29]!==b||e[30]!==W||e[31]!==n||e[32]!==m||e[33]!==Se||e[34]!==p||e[35]!==H||e[36]!==oe||e[37]!==f||e[38]!==V||e[39]!==g||e[40]!==h||e[41]!==E||e[42]!==a||e[43]!==i||e[44]!==c||e[45]!==u||e[46]!==d||e[47]!==o||e[48]!==F||e[49]!==Ie||e[50]!==C||e[51]!==L||e[52]!==K||e[53]!==M||e[54]!==x?($=W?null:s.jsxs(s.Fragment,{children:[p&&s.jsx("div",{ref:C,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsxs(uf,{open:Se,onOpenChange:ae,children:[s.jsx(df,{render:s.jsx("div",{className:xe("-ml-2.5 -mr-2 text-left group/project select-none",M&&"sticky top-0 z-20 bg-sidebar"),"data-sidebar-sticky-header":M?"true":void 0,onContextMenu:Y=>{b||(Y.preventDefault(),ae(!0))}}),children:s.jsxs("div",{className:"relative flex items-center gap-1 py-1 pl-4 pr-3.5",...U,children:[oe?s.jsxs(un,{children:[s.jsx(cn,{asChild:!0,children:s.jsxs("button",{type:"button",title:i,className:xe("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 transition-[padding]",f&&!b?k?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":k?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),"aria-label":x("sessions.sidebar.project.selectAria",{project:o}),children:[s.jsx(ki,{id:n,projectLabel:o,projectIcon:c,projectColor:a,projectIconImage:d,projectIconBackground:u}),s.jsx(I,{name:"arrow-down-s",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(dn,{align:"start",className:"min-w-[220px] max-w-[calc(100vw-2rem)] max-h-[min(var(--available-height),70vh)] overflow-y-auto overscroll-contain",children:F?.map(Y=>s.jsxs(Ht,{onClick:()=>E?.(Y.id),className:"flex items-center justify-between gap-3",title:Y.projectDescription,children:[s.jsx("span",{className:"flex min-w-0 items-center gap-1.5",children:s.jsx(ki,{id:Y.id,projectLabel:Y.projectLabel,projectIcon:Y.projectIcon,projectColor:Y.projectColor,projectIconImage:Y.projectIconImage,projectIconBackground:Y.projectIconBackground})}),Y.id===n?s.jsx(I,{name:"check",className:"h-4 w-4 flex-shrink-0 text-primary"}):null]},Y.id))})]}):s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:Ne,onClick:se,...V,className:xe("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&&!b?k?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":k?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsx(ki,{id:n,projectLabel:o,projectIcon:c,projectColor:a,projectIconImage:d,projectIconBackground:u,isCollapsed:m,alwaysShowActions:k}),K?s.jsx("span",{className:"ml-1 inline-flex flex-shrink-0 items-center",children:K}):null]})}),s.jsx(ht,{side:"right",sideOffset:8,children:i})]}),s.jsxs("div",{className:xe("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",L?"right-7":"right-0.5"),children:[L&&f&&!b&&h?s.jsxs(ft,{delayDuration:500,children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Y=>{Y.stopPropagation(),h()},className:xe("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",k?"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":x("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(I,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:x("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,b?null:s.jsxs(un,{open:H,onOpenChange:me,children:[s.jsx(cn,{asChild:!0,children:s.jsx("button",{type:"button",className:xe("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",H?"opacity-100 pointer-events-auto":k?"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":x("sessions.sidebar.project.actions.projectMenu"),onPointerDown:Me,onMouseDown:Fe,onClick:Oe,children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(dn,{align:"end",className:"min-w-[180px]",children:Ie(Ht)})]})]}),L&&g?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(),g()},className:xe("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",k?"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":x(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})}),s.jsx(ht,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:x(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})}),s.jsx(lf,{className:"min-w-[180px]",children:Ie(cf)})]})]}),e[25]=k,e[26]=U,e[27]=me,e[28]=se,e[29]=b,e[30]=W,e[31]=n,e[32]=m,e[33]=Se,e[34]=p,e[35]=H,e[36]=oe,e[37]=f,e[38]=V,e[39]=g,e[40]=h,e[41]=E,e[42]=a,e[43]=i,e[44]=c,e[45]=u,e[46]=d,e[47]=o,e[48]=F,e[49]=Ie,e[50]=C,e[51]=L,e[52]=K,e[53]=M,e[54]=x,e[55]=$):$=e[55];let de;return e[56]!==N||e[57]!==Z||e[58]!==J||e[59]!==ee||e[60]!==$?(de=s.jsxs("div",{ref:Z,style:J,className:ee,children:[$,N]}),e[56]=N,e[57]=Z,e[58]=J,e[59]=ee,e[60]=$,e[61]=de):de=e[61],de},Dj=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:p}=Rl(c);let b;e[3]!==a||e[4]!==u?(b={listeners:a,setActivatorNodeRef:u},e[3]=a,e[4]=u,e[5]=b):b=e[5];const k=b;let v;e[6]!==m?(v=Ol.Transform.toString(m),e[6]=m,e[7]=v):v=e[7];let g;e[8]!==v||e[9]!==f?(g={transform:v,transition:f},e[8]=v,e[9]=f,e[10]=g):g=e[10];const h=p&&"opacity-50";let S;e[11]!==h?(S=xe("space-y-0.5 rounded-md",h),e[11]=h,e[12]=S):S=e[12];let y;e[13]!==o||e[14]!==k?(y=typeof o=="function"?o(k):o,e[13]=o,e[14]=k,e[15]=y):y=e[15];let j;return e[16]!==d||e[17]!==g||e[18]!==S||e[19]!==y?(j=s.jsx("div",{ref:d,style:g,className:S,children:y}),e[16]=d,e[17]=g,e[18]=S,e[19]=y,e[20]=j):j=e[20],j},Pj=l.memo(Dj);function Ej(t){return t.stickyZoneHeaders}function Tj(t){t.stopPropagation()}function Ij(t){t.stopPropagation()}function Mj(t){t.stopPropagation()}const Rj=48,Oj=32,Fj=24,Ra=t=>{const e=t.getAttribute("data-sidebar-activity-sentinel");return e==="chats"||e==="active-now"?e:null},Oa=(t,e)=>El(t.label?.trim()||xr(t.normalizedPath,e)||t.normalizedPath);function Bj(t){Tn("ui.sidebar_projects_list.render");const{t:e}=gt(),n=t.isDesktopShellRuntime&&t.stickyZoneHeaders&&!t.singleProjectMode,r=Mi(eo(Xa,{activationConstraint:{distance:8}}),eo(Ex,{coordinateGetter:Tx})),o=Mi(eo(Xa,{activationConstraint:{distance:8}})),i=t.singleProjectMode?t.sectionsForRender.find(C=>C.project.id===t.singleProjectId):null,c=t.singleProjectMode?i?[i]:[]:t.sectionsForRender,a=l.useMemo(()=>t.projectPickerSections.map(C=>({id:C.project.id,projectLabel:Oa(C.project,t.homeDirectory),projectDescription:Io(C.project.normalizedPath,t.homeDirectory),projectIcon:C.project.icon,projectColor:C.project.color,projectIconImage:C.project.iconImage,projectIconBackground:C.project.iconBackground})),[t.homeDirectory,t.projectPickerSections]),d=l.useRef(new Map),u=l.useRef(t.getOrderedGroups);u.current!==t.getOrderedGroups&&(u.current=t.getOrderedGroups,d.current.clear());const m=(C,N)=>{const w=d.current,A=w.get(C);if(A&&A.groups===N)return A.ordered;const D=t.getOrderedGroups(C,N);if(w.set(C,{groups:N,ordered:D}),w.size>256){const P=w.keys().next().value;P!==void 0&&w.delete(P)}return D},f=l.useRef(null),[p,b]=l.useState("chats"),k=l.useRef(0),v=l.useCallback(C=>{const w=C.scrollTop>1?Math.min(Oj+C.scrollTop,Rj):0;k.current=w,C.style.setProperty("--scroll-shadow-top-size",`${w}px`),C.style.setProperty("--scroll-shadow-top-clear-size",`${Math.min(Math.max(w-8,0),Fj)}px`)},[]),g=l.useCallback(C=>{C.target.closest("[data-overlay-scrollbar-thumb], [data-sidebar-sticky-header]")||C.clientY-C.currentTarget.getBoundingClientRect().top>=k.current||(C.preventDefault(),C.stopPropagation())},[]),h=t.projectSections.length>0&&c.length>0;l.useLayoutEffect(()=>{n&&h&&f.current&&v(f.current)},[n,h,v]),l.useEffect(()=>{const C=f.current;if(!n||!C||!t.hasSharedSessions)return;const N=Array.from(C.querySelectorAll("[data-sidebar-activity-sentinel]"));if(N.length===0)return;const w=new Set,A=()=>{let P=N[0]?Ra(N[0]):null;for(const B of N){const F=Ra(B);F&&w.has(F)&&(P=F)}P&&b(B=>B===P?B:P)},D=new IntersectionObserver(P=>{const B=C.getBoundingClientRect().top;for(const F of P){const E=Ra(F.target);E&&(!F.isIntersecting&&F.boundingClientRect.top<(F.rootBounds?.top??B)?w.add(E):w.delete(E))}A()},{root:C,threshold:0});return N.forEach(P=>D.observe(P)),A(),()=>D.disconnect()},[n,t.hasSharedSessions,t.topContent]);let S=null;for(const C of t.projectSections)t.stuckProjectHeaders.has(C.project.id)&&(S=C.project);const y=S??(t.hasSharedSessions?null:c[0]?.project??null),j=y?Oa(y,t.homeDirectory):null;return t.sharedSessionsOnly?s.jsxs($n,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:xe("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:xe("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:xe("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?g:void 0,onClickCapture:n?g:void 0,onContextMenuCapture:n?g:void 0,children:[s.jsxs($n,{ref:f,useScrollShadow:!0,hideTopScrollShadow:!n,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:xe("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?C=>v(C.currentTarget):void 0,children:[t.topContent,t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const C=t.sectionsForRender.find(D=>D.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!C)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const N=C.groups.find(D=>D.isMain&&D.sessions.length>0)??C.groups.find(D=>D.sessions.length>0)??C.groups.find(D=>D.isMain)??C.groups[0];if(!N)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:e("sessions.sidebar.empty.noSessions.title")});const w=C.groups.find(D=>D.isArchivedBucket);return[N,...w&&w.id!==N.id?[w]:[]].map(D=>{const P=`${C.project.id}:${D.id}`,B=D.id===N.id;return s.jsx(l.Fragment,{children:t.renderGroupSessions(D,P,C.project.id,B,null,!0,f)},P)})})()}):s.jsxs(Ri,{sensors:r,collisionDetection:Oi,onDragEnd:C=>{if(t.isInlineEditing||t.projectSortOrder!=="manual")return;const{active:N,over:w}=C;if(!w||N.id===w.id)return;const A=t.sectionsForRender.findIndex(P=>P.project.id===N.id),D=t.sectionsForRender.findIndex(P=>P.project.id===w.id);A===-1||D===-1||A===D||t.reorderProjects(A,D)},children:[s.jsx(Za,{items:c.map(C=>C.project.id),strategy:el,children:c.map(C=>{const N=C.project,w=N.id,A=Oa(N,t.homeDirectory),D=Io(N.normalizedPath,t.homeDirectory),P=t.singleProjectMode?!1:t.collapsedProjects.has(w),B=t.projectRepoStatus.get(w);return s.jsx(Aj,{id:w,disabled:t.singleProjectMode||t.projectSortOrder!=="manual",projectLabel:A,projectDescription:D,projectIcon:N.icon,projectColor:N.color,projectIconImage:N.iconImage,projectIconBackground:N.iconBackground,isCollapsed:P,isRepo:!!B,isDesktopShell:t.isDesktopShellRuntime,hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,statusIndicator:P?t.renderProjectStatusIndicator?.(w,C.groups):null,onToggle:()=>{t.singleProjectMode||t.toggleProject(w)},onNewSession:()=>{w!==t.activeProjectId&&t.setActiveProjectIdOnly(w),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({selectedProjectId:w,directoryOverride:N.normalizedPath})},onNewWorktreeSession:()=>{w!==t.activeProjectId&&t.setActiveProjectIdOnly(w),t.setActiveMainTab("chat"),t.openNewWorktreeDialog()},onManageWorktrees:()=>t.openWorktreesPage(w),onRenameStart:()=>t.openProjectEditDialog(w),onClose:()=>t.removeProject(w),sentinelRef:F=>{t.projectHeaderSentinelRefs.current.set(w,F)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,projectPickerOptions:t.singleProjectMode?a:void 0,onProjectSelect:t.singleProjectMode?t.setSingleProjectId:void 0,children:P?null:s.jsx("div",{className:"space-y-0 pt-0.5 pb-0.5",children:(()=>{const F=m(w,C.groups),E=F.find(L=>L.isMain)??null,_=E?F.filter(L=>L.id!==E.id):F;return s.jsxs(Ri,{sensors:o,collisionDetection:Oi,onDragEnd:L=>{if(t.isInlineEditing)return;const{active:W,over:K}=L;if(!K||W.id===K.id)return;const x=_.findIndex(V=>V.id===W.id),M=_.findIndex(V=>V.id===K.id);if(x===-1||M===-1||x===M)return;const z=yf(_,x,M).map(V=>V.id),U=E?[E.id,...z]:z;t.setGroupOrderByProject(V=>{const Z=new Map(V);return Z.set(w,U),Z})},children:[E?t.renderGroupSessions(E,`${w}:${E.id}`,w,!0,null,void 0,f):null,s.jsx(Za,{items:_.map(L=>L.id),strategy:el,children:_.map(L=>{const W=`${w}:${L.id}`;return s.jsx(Pj,{id:L.id,disabled:t.isInlineEditing,children:K=>t.renderGroupSessions(L,W,w,!1,K,void 0,f)},L.id)})}),s.jsx(Ja,{dropAnimation:null})]})})()})},w)})}),s.jsx(Ja,{dropAnimation:null})]})]}),n&&(y||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:y&&j?s.jsx(ki,{id:y.id,projectLabel:j,projectIcon:y.icon,projectColor:y.color,projectIconImage:y.iconImage,projectIconBackground:y.iconBackground}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:p==="chats"?"chat-4":"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(p==="chats"?"sessions.sidebar.activity.chatsTitle":"sessions.sidebar.activity.recentTitle")})]})}):null]})}const Lj=l.memo(Bj),_j=(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},Ts=Lr()((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 p of m)c.delete(p);d===n&&(d=null)}else{for(const p of m)c.add(p);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,p]=u<=m?[u,m]:[m,u],b=o.slice(f,p+1),k=_j(b,c),g=i!==null&&a.scopeKey!==null&&i!==a.scopeKey?new Set:new Set(a.selectedIds);for(const h of k)g.add(h);t({selectedIds:g,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 fl=!1;const ml=new Set;let Md=!1;function $j(){for(const t of ml)t()}function Kl(t){fl!==t&&(fl=t,$j())}function zj(t){t.key==="Shift"&&Kl(!0)}function Uj(t){t.key==="Shift"&&Kl(!1)}function Wj(){Kl(!1)}function Vj(){Md||typeof window>"u"||(Md=!0,window.addEventListener("keydown",zj),window.addEventListener("keyup",Uj),window.addEventListener("blur",Wj))}function Hj(t){return Vj(),ml.add(t),()=>{ml.delete(t)}}function Kj(){return fl}function Gj(){return!1}function qj(){return tt.useSyncExternalStore(Hj,Kj,Gj)}const Yj=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,lm=/^g[1-9]\d*$/,So=(t,e,n,r,o)=>{if(!Yj.test(t)||e!==void 0&&!lm.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}},Ci=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 So(n,void 0,e[1],e[2],void 0);if(e.length===4){const[,a,d,u]=e;return lm.test(a)?So(n,a,d,u,void 0):So(n,void 0,a,d,u)}const[,r,o,i,c]=e;return r===""?So(n,void 0,o,i,c):So(n,r,o,i,c)},Qj=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("/")},Xj=(t,e,n,r)=>{const o=[t];return r&&o.push(r),o.push(e,n,"fusion"),o.join("/")},cm=t=>{const e=it.c(36),{value:n,onChange:r,className:o,disabled:i,id:c,portalToBody:a}=t,{t:d}=gt(),u=Yt(Jj),m=Yt(Zj),f=Yt(e2);let p;e[0]!==u?(p=u(),e[0]=u,e[1]=p):p=e[1];const b=p;let k;e[2]!==b?(k=b.filter(t2),e[2]=b,e[3]=k):k=e[3];const v=k;let g,h;e[4]!==b.length||e[5]!==m?(g=()=>{b.length===0&&m()},h=[b.length,m],e[4]=b.length,e[5]=m,e[6]=g,e[7]=h):(g=e[6],h=e[7]),l.useEffect(g,h);let S,y;e[8]!==f||e[9]!==i||e[10]!==r||e[11]!==v||e[12]!==n?(S=()=>{if(i)return;const F=n.trim();if(F.length>0&&v.some(L=>L.name===F))return;const E=typeof f=="string"&&f.trim().length>0?f.trim():null;if(E&&v.some(L=>L.name===E)){r(E);return}const _=v[0]?.name;_&&r(_)},y=[f,i,r,v,n],e[8]=f,e[9]=i,e[10]=r,e[11]=v,e[12]=n,e[13]=S,e[14]=y):(S=e[13],y=e[14]),l.useEffect(S,y);const j=n.trim().length>0?n:void 0;let C;e[15]!==o?(C=xe("max-w-full",o),e[15]=o,e[16]=C):C=e[16];let N;e[17]!==d?(N=d("multirun.agentSelector.placeholder"),e[17]=d,e[18]=N):N=e[18];let w;e[19]!==N?(w=s.jsx(Rs,{placeholder:N}),e[19]=N,e[20]=w):w=e[20];let A;e[21]!==c||e[22]!==C||e[23]!==w?(A=s.jsx(Qs,{id:c,size:"lg",className:C,children:w}),e[21]=c,e[22]=C,e[23]=w,e[24]=A):A=e[24];let D;e[25]!==v?(D=v.length>0&&s.jsx(qa,{children:v.map(s2)}),e[25]=v,e[26]=D):D=e[26];let P;e[27]!==a||e[28]!==D?(P=s.jsx(Xs,{fitContent:!0,portalToBody:a,children:D}),e[27]=a,e[28]=D,e[29]=P):P=e[29];let B;return e[30]!==i||e[31]!==r||e[32]!==j||e[33]!==A||e[34]!==P?(B=s.jsxs(Ys,{value:j,onValueChange:r,disabled:i,children:[A,P]}),e[30]=i,e[31]=r,e[32]=j,e[33]=A,e[34]=P,e[35]=B):B=e[35],B};function Jj(t){return t.getVisibleAgents}function Zj(t){return t.loadAgents}function e2(t){return t.currentAgentName}function t2(t){return Gu(t.mode)}function s2(t){return s.jsx(ls,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const n2="h-7",Po=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,r2=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=xe("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",n2),e[0]=d):d=e[0];let u;e[1]!==n.providerID?(u=s.jsx(Pi,{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(I,{name:"close",className:"h-3.5 w-3.5"}),e[5]=f):f=e[5];let p;e[6]!==i?(p=s.jsx("button",{type:"button",onClick:i,className:"text-muted-foreground hover:text-foreground ml-0.5",children:f}),e[6]=i,e[7]=p):p=e[7];let b;return e[8]!==u||e[9]!==m||e[10]!==p?(b=s.jsxs("div",{className:d,children:[u,m,p]}),e[8]=u,e[9]=m,e[10]=p,e[11]=b):b=e[11],b},dm=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:p,containerClassName:b,triggerIcon:k}=t,v=d===void 0?!0:d,g=f===void 0?"top":f,{t:h}=gt(),S=Yt(o2),y=Yt(i2),j=he(a2),C=he(l2),{favoriteModelsList:N,recentModelsList:w}=bp(),A=he(c2),D=he(d2),[P,B]=l.useState(!1),[F,E]=l.useState(""),[_,L]=l.useState(null),W=l.useRef(null),K=l.useRef(null),x=u===1,M=u===void 0||n.length<u||x;let z;if(e[0]!==n){z=new Map;for(const Ce of n){const Ae=`${Ce.providerID}:${Ce.modelID}`;z.set(Ae,(z.get(Ae)||0)+1)}e[0]=n,e[1]=z}else z=e[1];const U=z;let V;e[2]!==n?(V=Ce=>n.filter(ne=>ne.providerID===Ce.providerID&&ne.modelID===Ce.modelID).findIndex(ne=>ne.instanceId===Ce.instanceId)+1,e[2]=n,e[3]=V):V=e[3];const Z=V;let X,le;e[4]!==g||e[5]!==P?(X=()=>{if(!P||!K.current)return;const Ce=K.current.getBoundingClientRect();if(g==="bottom"){const ye=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-Ce.bottom-16-112;L(Math.max(160,Math.min(320,ye)));return}let Ae=K.current.parentElement;for(;Ae&&!(Ae.getAttribute("role")==="dialog"||Ae.hasAttribute("data-scroll-shadow"));){const Ze=getComputedStyle(Ae);if(Ze.overflow==="auto"||Ze.overflow==="hidden"||Ze.overflowY==="auto"||Ze.overflowY==="hidden")break;Ae=Ae.parentElement}const ne=Ae?Ae.getBoundingClientRect().top:0,ke=Ce.top-ne-16;L(Math.max(150,Math.min(300,ke)))},le=[g,P],e[4]=g,e[5]=P,e[6]=X,e[7]=le):(X=e[6],le=e[7]),l.useEffect(X,le);let te,fe;e[8]!==M||e[9]!==P?(te=()=>{!M&&P&&(B(!1),E(""))},fe=[M,P],e[8]=M,e[9]=P,e[10]=te,e[11]=fe):(te=e[10],fe=e[11]),l.useEffect(te,fe);let ge,H;e[12]!==P?(ge=()=>{if(!P)return;const Ce=Ae=>{W.current&&!W.current.contains(Ae.target)&&(B(!1),E(""))};return document.addEventListener("mousedown",Ce),()=>document.removeEventListener("mousedown",Ce)},H=[P],e[12]=P,e[13]=ge,e[14]=H):(ge=e[13],H=e[14]),l.useEffect(ge,H);let Se;e[15]!==x||e[16]!==r||e[17]!==i||e[18]!==n.length?(Se=Ce=>{const Ae={providerID:Ce.providerID,modelID:Ce.modelID,displayName:Ce.model.name||Ce.modelID,instanceId:Po()};x&&n.length>0&&i?i(0,Ae):r(Ae),x&&(B(!1),E(""))},e[15]=x,e[16]=r,e[17]=i,e[18]=n.length,e[19]=Se):Se=e[19];const ae=Se;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 pe;e[24]!==h?(pe=h("multirun.modelMultiSelect.sections.favorites"),e[24]=h,e[25]=pe):pe=e[25];let Ie;e[26]!==h?(Ie=h("multirun.modelMultiSelect.sections.recent"),e[26]=h,e[27]=Ie):Ie=e[27];let Oe;e[28]!==h?(Oe=h("multirun.modelMultiSelect.keyboard.hint"),e[28]=h,e[29]=Oe):Oe=e[29];let Me;e[30]!==h?(Me=h("settings.agents.modelSelector.actions.favorite"),e[30]=h,e[31]=Me):Me=e[31];let Fe;e[32]!==h?(Fe=h("settings.agents.modelSelector.actions.unfavorite"),e[32]=h,e[33]=Fe):Fe=e[33];let je;e[34]!==h?(je=h("chat.modelControls.capabilities"),e[34]=h,e[35]=je):je=e[35];let Ne;e[36]!==h?(Ne=h("chat.modelControls.capability.toolCalling"),e[36]=h,e[37]=Ne):Ne=e[37];let Pe;e[38]!==h?(Pe=h("chat.modelControls.capability.reasoning"),e[38]=h,e[39]=Pe):Pe=e[39];let se;e[40]!==h?(se=h("chat.modelControls.input"),e[40]=h,e[41]=se):se=e[41];let oe;e[42]!==h?(oe=h("chat.modelControls.output"),e[42]=h,e[43]=oe):oe=e[43];let Ee;e[44]!==h?(Ee=h("chat.modelControls.costPerMillion"),e[44]=h,e[45]=Ee):Ee=e[45];let J;e[46]!==q||e[47]!==me||e[48]!==pe||e[49]!==Ie||e[50]!==Oe||e[51]!==Me||e[52]!==Fe||e[53]!==je||e[54]!==Ne||e[55]!==Pe||e[56]!==se||e[57]!==oe||e[58]!==Ee?(J={searchPlaceholder:q,noResults:me,favorites:pe,recent:Ie,keyboardHint:Oe,favorite:Me,unfavorite:Fe,capabilities:je,capabilityToolCalling:Ne,capabilityReasoning:Pe,input:se,output:oe,costPerMillion:Ee},e[46]=q,e[47]=me,e[48]=pe,e[49]=Ie,e[50]=Oe,e[51]=Me,e[52]=Fe,e[53]=je,e[54]=Ne,e[55]=Pe,e[56]=se,e[57]=oe,e[58]=Ee,e[59]=J):J=e[59];const re=J;let ee;e[60]!==b?(ee=xe("relative",b),e[60]=b,e[61]=ee):ee=e[61];const $=P?"":void 0;let de;e[62]!==m?(de=xe(qu({size:"default"}),"w-fit",m),e[62]=m,e[63]=de):de=e[63];const Y=!M;let ue;e[64]!==P?(ue=()=>{B(!P)},e[64]=P,e[65]=ue):ue=e[65];let Te;e[66]!==k?(Te=k??s.jsx(I,{name:"add",className:"h-3.5 w-3.5 mr-1"}),e[66]=k,e[67]=Te):Te=e[67];let Ge;e[68]!==a||e[69]!==h?(Ge=a??h("multirun.modelMultiSelect.actions.addModel"),e[68]=a,e[69]=h,e[70]=Ge):Ge=e[70];let _e;e[71]!==$||e[72]!==de||e[73]!==Y||e[74]!==ue||e[75]!==Te||e[76]!==Ge?(_e=s.jsxs("button",{ref:K,type:"button","data-popup-open":$,className:de,disabled:Y,onClick:ue,children:[Te,Ge]}),e[71]=$,e[72]=de,e[73]=Y,e[74]=ue,e[75]=Te,e[76]=Ge,e[77]=_e):_e=e[77];let ie;e[78]!==_||e[79]!==M||e[80]!==p||e[81]!==g||e[82]!==N||e[83]!==ae||e[84]!==A||e[85]!==C||e[86]!==P||e[87]!==re||e[88]!==U||e[89]!==y||e[90]!==D||e[91]!==S||e[92]!==w||e[93]!==F||e[94]!==j?(ie=P?s.jsx("div",{className:xe("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",g==="top"?"bottom-full mb-1":"top-full mt-1",p),style:{background:"linear-gradient(var(--surface-elevated),var(--surface-elevated)),linear-gradient(var(--surface-background),var(--surface-background))"},children:s.jsx(yp,{providers:S,providerOrder:D,favoriteModels:N,recentModels:w,modelsMetadata:y,hiddenModels:A,searchQuery:F,onSearchQueryChange:E,onSelect:ae,labels:re,selectionCount:Ce=>U.get(`${Ce.providerID}:${Ce.modelID}`)||0,disabled:!M,maxHeightClassName:"flex-1",maxHeightStyle:{maxHeight:_?`${_}px`:"300px"},stickyHeaders:!0,tooltipsEnabled:P,isFavorite:Ce=>C(Ce.providerID,Ce.modelID),onToggleFavorite:Ce=>j(Ce.providerID,Ce.modelID),onEscape:()=>{B(!1),E("")}})}):null,e[78]=_,e[79]=M,e[80]=p,e[81]=g,e[82]=N,e[83]=ae,e[84]=A,e[85]=C,e[86]=P,e[87]=re,e[88]=U,e[89]=y,e[90]=D,e[91]=S,e[92]=w,e[93]=F,e[94]=j,e[95]=ie):ie=e[95];let Re;e[96]!==ee||e[97]!==_e||e[98]!==ie?(Re=s.jsxs("div",{className:ee,ref:W,children:[_e,ie]}),e[96]=ee,e[97]=_e,e[98]=ie,e[99]=Re):Re=e[99];let be;e[100]!==Z||e[101]!==U||e[102]!==o||e[103]!==i||e[104]!==S||e[105]!==n||e[106]!==v||e[107]!==h?(be=v&&n.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:n.map((Ce,Ae)=>{const ne=`${Ce.providerID}:${Ce.modelID}`,ke=U.get(ne)||1,Ze=Z(Ce),ye=S.find(Le=>Le.id===Ce.providerID)?.models?.find(Le=>Le.id===Ce.modelID),Qe=ye?.variants?Object.keys(ye.variants):[],$e=Qe.length>0,ze=Ce.variant??"__default__";return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(r2,{model:Ce,instanceIndex:Ze,totalSameModel:ke,onRemove:()=>o(Ae)}),$e&&s.jsxs(Ys,{value:ze,onValueChange:Le=>{if(!i)return;i(Ae,{...Ce,variant:Le==="__default__"?void 0:Le})},children:[s.jsxs(Qs,{size:"sm",className:"gap-1.5",children:[s.jsx(I,{name:"brain-ai-3",className:xe("h-3.5 w-3.5 flex-shrink-0",ze==="__default__"?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(Rs,{placeholder:h("multirun.modelMultiSelect.variant.placeholder"),children:Le=>Le==="__default__"?h("multirun.modelMultiSelect.variant.default"):Le})]}),s.jsxs(Xs,{fitContent:!0,children:[s.jsx(ls,{value:"__default__",className:"pr-2 [&>span:first-child]:hidden",children:h("multirun.modelMultiSelect.variant.default")}),Qe.map(u2)]})]})]},Ce.instanceId)})}),e[100]=Z,e[101]=U,e[102]=o,e[103]=i,e[104]=S,e[105]=n,e[106]=v,e[107]=h,e[108]=be):be=e[108];let T;e[109]!==Re||e[110]!==be?(T=s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[Re,be]}),e[109]=Re,e[110]=be,e[111]=T):T=e[111];let ce;e[112]!==u||e[113]!==c||e[114]!==n.length||e[115]!==h?(ce=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]=ce):ce=e[116];let ve;return e[117]!==T||e[118]!==ce?(ve=s.jsxs("div",{className:"space-y-2",children:[T,ce]}),e[117]=T,e[118]=ce,e[119]=ve):ve=e[119],ve};function o2(t){return t.providers}function i2(t){return t.modelsMetadata}function a2(t){return t.toggleFavoriteModel}function l2(t){return t.isFavoriteModel}function c2(t){return t.hiddenModels}function d2(t){return t.providerOrder}function u2(t){return s.jsx(ls,{value:t,className:"pr-2 [&>span:first-child]:hidden",children:t},t)}const f2=(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} ---`},Rd=(t,e)=>nt.getState().getWorktreeMetadata(t)?.projectDirectory??e,m2=async t=>{const e=t.directory??void 0,n=wp(t.session.id,e);if(n.length===0&&t.directory){const o=(await an.withDirectory(t.directory,()=>an.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 Sc(c.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const o=n[r];if(o.role==="assistant")return Sc(Sp(o.id,e)).trim()}return""};function h2({session:t,open:e,onOpenChange:n}){const{t:r}=gt(),o=vp(),i=Is(x=>x.activeSessions),c=Is(x=>x.archivedSessions),a=Yt(x=>x.providers),d=Yt(x=>x.currentProviderId),u=Yt(x=>x.currentModelId),m=Yt(x=>x.currentAgentName),[f,p]=l.useState(d??""),[b,k]=l.useState(u??""),[v,g]=l.useState(()=>d&&u?[{providerID:d,modelID:u,instanceId:Po()}]:[]),[h,S]=l.useState(""),[y,j]=l.useState(m??""),[C,N]=l.useState([]),[w,A]=l.useState(!1),D=l.useMemo(()=>Ci(t.title),[t.title]),P=l.useMemo(()=>{const x=new Map;for(const M of o)x.set(M.id,M);for(const M of i)x.set(M.id,M);for(const M of c)x.set(M.id,M);return t.id&&x.set(t.id,t),Array.from(x.values())},[i,c,o,t]);l.useEffect(()=>{if(!e||!D)return;const x=nt.getState().getDirectoryForSession(t.id),M=Rd(t.id,x),z=P.map(U=>{const V=Ci(U.title);if(!V||V.groupSlug!==D.groupSlug||V.fusion||(V.runGroup??null)!==(D.runGroup??null))return null;const Z=nt.getState().getDirectoryForSession(U.id)??Zs(U),X=Rd(U.id,Z);return M&&X&&M!==X?null:{session:U,directory:Z,projectDirectory:X}}).filter(U=>U!==null).sort((U,V)=>(U.session.time?.created??0)-(V.session.time?.created??0));N(z)},[P,e,D,t.id]);const F=a.find(x=>x.id===f)?.models.find(x=>x.id===b),E=F?.variants?Object.keys(F.variants):[],_=!!(D&&f&&b&&C.length>0&&!w),L=l.useCallback(x=>{g([x]),p(x.providerID),k(x.modelID),S("")},[]),W=v[0]?.displayName||v[0]?.modelID||r("multirun.fusion.model.placeholder"),K=async()=>{if(!(!D||!f||!b)){A(!0);try{const x=await Promise.all(C.map(le=>m2(le))),M=C.map((le,te)=>({source:le,text:x[te]??""})).filter(le=>le.text.trim().length>0);if(M.length===0){De.error(r("multirun.fusion.toast.noOutputs"));return}const z=C[0]?.projectDirectory??C[0]?.directory??null,U=Xj(D.groupSlug,f,b,D.runGroup),[V,Z]=await Promise.all([wc("session.fusion.visible"),wc("session.fusion.instructions")]),X=await nt.getState().createSession(U,z,null);if(!X)throw new Error("Failed to create fusion session");nt.getState().setCurrentSession(X.id,z),n(!1),await an.sendMessage({id:X.id,providerID:f,modelID:b,variant:h||void 0,agent:y||void 0,text:V,additionalParts:[{text:Z,synthetic:!0},...M.map((le,te)=>({text:f2(le.source,le.text,te),synthetic:!0})),{text:`
911
+
912
+ --- FUSION INPUTS END ---
913
+ Now write the final fused answer.`,synthetic:!0}],directory:z??an.getDirectory()})}catch(x){console.error("[MultiRunFusion] Failed to start fusion",x),De.error(r("multirun.fusion.toast.failed"))}finally{A(!1)}}};return s.jsx($s,{open:e,onOpenChange:n,children:s.jsxs(zs,{className:"max-w-xl overflow-visible",children:[s.jsxs(An,{children:[s.jsx(fn,{children:r("multirun.fusion.title")}),s.jsx(mn,{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(dm,{selectedModels:v,onAdd:L,onUpdate:(x,M)=>L(M),onRemove:()=>{g([]),p(""),k(""),S("")},maxModels:1,addButtonLabel:W,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(Pi,{providerId:f,className:"h-3.5 w-3.5 mr-1"}):void 0})}),E.length>0?s.jsxs(Ys,{value:h||"__default__",onValueChange:x=>S(x==="__default__"?"":x),children:[s.jsxs(Qs,{size:"lg",className:"w-fit",children:[s.jsx(I,{name:"brain-ai-3",className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Rs,{children:x=>x==="__default__"?r("multirun.modelMultiSelect.variant.default"):x})]}),s.jsxs(Xs,{fitContent:!0,portalToBody:!0,children:[s.jsx(ls,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),E.map(x=>s.jsx(ls,{value:x,children:x},x))]})]}):null,s.jsx(cm,{value:y,onChange:j,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:C.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:C.map(x=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(Pi,{providerId:Ci(x.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:x.session.title||x.session.id}),s.jsx("button",{type:"button",onClick:()=>N(M=>M.filter(z=>z.session.id!==x.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"h-4 w-4"})})]},x.session.id))})]}),s.jsxs(tr,{children:[s.jsx(lt,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(lt,{onClick:K,disabled:!_,children:r(w?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function p2(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 hl=6,ci=14,Od=hl+14+6,Fa=new WeakMap,g2=t=>{if(typeof window>"u")return;const e=t.closest("[data-session-row]"),n=e?.closest(".overlay-scrollbar-container");if(!e||!n)return;Fa.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,Fa.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,Tn("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}),Fa.set(n,a),c=window.requestAnimationFrame(d)},x2=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=qj(),p=f?o:r;let b;n[0]!==u||n[1]!==m||n[2]!==f?(b=N=>{if(f||N.shiftKey){m(N);return}u(N)},n[0]=u,n[1]=m,n[2]=f,n[3]=b):b=n[3];const k=b,v=f?"text-destructive hover:text-destructive":"text-muted-foreground hover:text-foreground";let g;n[4]!==i||n[5]!==v?(g=xe("inline-flex items-center justify-center rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",v,i),n[4]=i,n[5]=v,n[6]=g):g=n[6];const h=f?"delete-bin":"archive";let S;n[7]!==c||n[8]!==h?(S=s.jsx(I,{name:h,className:c}),n[7]=c,n[8]=h,n[9]=S):S=n[9];let y;n[10]!==k||n[11]!==p||n[12]!==d||n[13]!==a||n[14]!==g||n[15]!==S?(y=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",className:g,"aria-label":p,onPointerDown:a,onMouseDown:d,onClick:k,onKeyDown:k2,children:S})}),n[10]=k,n[11]=p,n[12]=d,n[13]=a,n[14]=g,n[15]=S,n[16]=y):y=n[16];let j;n[17]!==p?(j=s.jsx(ht,{side:"left",sideOffset:8,children:p}),n[17]=p,n[18]=j):j=n[18];let C;return n[19]!==y||n[20]!==j?(C=s.jsxs(ft,{delayDuration:500,children:[y,j]}),n[19]=y,n[20]=j,n[21]=C):C=n[21],C});function b2(t){Tn("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:p,setEditingId:b,editTitle:k,setEditTitle:v,handleSaveEdit:g,handleCancelEdit:h,toggleParent:S,handleSessionSelect:y,handleSessionDoubleClick:j,togglePinnedSession:C,handleShareSession:N,copiedSessionId:w,handleCopyShareUrl:A,handleCopySessionId:D,handleUnshareSession:P,openSidebarMenuKey:B,setOpenSidebarMenuKey:F,renamingFolderId:E,getFoldersForScope:_,getSessionFolderId:L,removeSessionFromFolder:W,addSessionToFolder:K,createFolderAndStartRename:x,openContextPanelTab:M,handleDeleteSession:z,handleRestoreSession:U,mobileVariant:V,alwaysShowActions:Z,renderSessionNode:X,secondaryMeta:le,renderContext:te="project",subtreeContainsEditing:fe,menuOpenSessionId:ge,childRenderExtrasFor:H}=t,Se=l.useMemo(()=>sr(),[]),ae=l.useMemo(()=>Hi(),[]),q=l.useContext(jp),me=Se?"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",pe=Se?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",Ie=Se,Oe=!c&&!V,Me=Se?Oe&&Ie?"group-hover:pr-18":Oe||Ie?"group-hover:pr-14":"group-hover:pr-8":Oe?"group-hover:pr-7 group-focus-within:pr-7":"group-hover:pr-3 group-focus-within:pr-3",Fe=Oe?"pr-13":"pr-7",je=l.useRef(!1),[Ne,Pe]=l.useState(!1),se=l.useRef(p);se.current=p;const oe=l.useRef(null),Ee=l.useRef(g);Ee.current=g;const[J,re]=l.useState(k),ee=l.useRef(J);ee.current=J;const $=l.useRef(null),de=l.useRef(null),Y=n.session,ue=Y,Te=Jt(l.useCallback(we=>{if(le?.projectLabel||!i)return null;const At=we.projects.find(Xt=>Xt.id===i);return At?At.label?.trim()||xr(jt(At.path)??At.path,null)||At.path:null},[i,le?.projectLabel])),Ge=le?.projectLabel??(Te?El(Te):null),_e=le?.branchLabel??n.worktree?.branch??null,ie=l.useMemo(()=>{if(Se)return null;const we=n.worktree?.branch?.trim(),At=jt(n.worktree?.path??null);return we&&At?Qi(At,we):null},[Se,n.worktree]),Re=Hu(ie),be=Re?`var(--pr-${Re.visualState})`:void 0,T=xs(we=>we.sessionGroupingMode),ce=!!_e&&(te==="recent"||T==="flat"),ve=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=nt(we=>we.currentSessionId===Y.id),Ae=jt(Y.directory??null)??jt(o??null),ne=i??Ae??null,ke=vl(Ae??void 0,{bootstrap:!1}),Ze=qi(),Q=Ts(we=>we.enabled),ye=Ts(l.useCallback(we=>we.selectedIds.has(Y.id),[Y.id])),Qe=Ts(we=>we.toggleSelected),$e=Ts(we=>we.setRange),ze=l.useCallback(we=>{const At=[],Xt=ss=>{ss.children.forEach(hs=>{At.push(hs.session.id),Xt(hs)})};return Xt(we),At},[]),Le=l.useCallback(we=>{const At=[],Xt=ss=>{ss.children.forEach(hs=>{At.push(hs.session),Xt(hs)})};return Xt(we),At},[]),[st,ct]=l.useState(!1),[Pt,It]=l.useState(!0),Tt=`${te}:${c?"archived":"active"}:${Y.id}`,et=Yu(l.useCallback(we=>!!we.sessionMemoryState.get(kp(Y.id))?.isZombie,[Y.id])),kt=Nu(Y.id)?.type??"idle",bt=kt==="busy"||kt==="retry",Bt=Cp(Y.id,bt),wt=Tf(Y.id),Rt=Np(Y.id,Ae??void 0,{bootstrap:!1}),pt=Ap(ue),yt=pt?s.jsx("span",{className:"inline-flex flex-shrink-0 items-center",title:e(jc[pt.status]),"aria-label":e(jc[pt.status]),children:s.jsx(I,{name:"target",className:"h-3 w-3",style:{color:Dp[pt.status]}})}):null,Ke=ue.title||e("sessions.sidebar.session.untitled"),Ue=n.children.length>0,xt=Pp(a,Ae,Y.id),Ft=Tt,$t=u?!0:d.has(Ft),ns=l.useMemo(()=>ej(n,$t,Ae),[$t,n,Ae]),Kt=Ep(ns),St=!!ue.parentID,ms=Tp(Y.id)>0&&(!St||f),ts=ue.time?.updated||ue.time?.created||Date.now(),ys=Qu(ts),Vt=Ip(ts),Gt=B===Tt,[Ut,Be]=l.useState(!1),Xe=Gt||Ut,Je=l.useMemo(()=>Ci(ue.title)!==null,[ue.title]),[He,rt]=l.useState(!1),Dt=l.useMemo(()=>ze(n).length,[ze,n]),Wt=l.useCallback(async we=>{const At=[];let Xt=0;for(const ss of we)try{if(!Ae)throw new Error("Session directory is required for export");await Ze.loadCompleteHistory(ss.session.id,Ae);const hs=Va(ke.getState(),ss.session.id).list,vs=ss.session.title||e("sessions.sidebar.session.export.untitledSubagent"),Ls=ss.session.agent,Ds=await Wt(ss.children);Xt+=Ds.skipped,At.push({title:vs,agent:Ls,records:hs,children:Ds.children})}catch{Xt+=ze(ss).length+1}return{children:At,skipped:Xt}},[ze,ke,Ae,Ze,e]),rs=l.useCallback(we=>{we<=0||De.warning(we===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:we}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:we}))},[e]),Lt=l.useCallback(async we=>{if(!Ae){De.error(e("sessions.sidebar.session.export.nothingToExport"));return}try{await Ze.loadCompleteHistory(Y.id,Ae)}catch{De.error(e("sessions.sidebar.session.export.failedLoadHistory"));return}const At=Va(ke.getState(),Y.id).list;if(At.length===0){De.error(e("sessions.sidebar.session.export.nothingToExport"));return}let Xt,ss=0;if(we&&n.children.length>0){const Ds=await Wt(n.children);Xt=Ds.children,ss=Ds.skipped}const hs=Af(At,ue.title??null,Xt),vs=Ef(ue.title??null),Ls=await Pf(hs,vs);if(Ls){De.success(e("sessions.sidebar.session.export.success"),{action:{label:e(vb()),onClick:()=>{yb(Ls).then(Ds=>{Ds||De.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),rs(ss);return}Df(hs,vs),De.success(e("sessions.sidebar.session.export.success")),rs(ss)},[Wt,ke,n.children,ue.title,Y.id,Ae,rs,Ze,e]),os=l.useCallback(async()=>{if(n.children.length>0){It(!0),ct(!0);return}await Lt(!1)},[Lt,n.children.length]),es=l.useCallback(()=>{Ae&&hr("desktop_open_session_mini_chat_window",{sessionId:Y.id,directory:Ae,apiBaseUrl:pr(),clientToken:Eo()}).catch(we=>{console.warn("[session-sidebar] failed to open mini chat window",we)})},[Y.id,Ae]);if(l.useEffect(()=>{if(p!==Y.id)return;const we=At=>{const ss=At.target?.closest?.(`[data-session-rename-form="${CSS.escape(Y.id)}"]`);de.current&&!ss&&Ee.current(ee.current)};return document.addEventListener("mousedown",we),()=>document.removeEventListener("mousedown",we)},[p,Y.id]),l.useLayoutEffect(()=>{if(p!==Y.id){$.current===Y.id&&($.current=null);return}$.current!==Y.id&&($.current=Y.id,re(k))},[p,k,Y.id]),p===Y.id)return s.jsx("div",{style:{paddingLeft:Od+r*ci},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:de,"data-session-rename-form":Y.id,className:"flex w-full items-center gap-2",onSubmit:we=>{we.preventDefault(),g(J)},children:[s.jsx("input",{value:J,onChange:we=>re(we.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:we=>{if(we.stopPropagation(),we.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(I,{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(I,{name:"close",className:"size-4"})})]})})},Y.id);const Us=Rt.length,Ws=Kt===1?e("sessions.sidebar.session.status.questionPendingSingle"):e("sessions.sidebar.session.status.questionPendingMany",{count:Kt}),Hn=!wt&&!bt&&ms&&!Ce,gn=bt||Hn,In=e(bt?"sessions.sidebar.session.status.active":"sessions.sidebar.session.status.unread"),xn=s.jsx("span",{className:xe("h-1.5 w-1.5 rounded-full",bt?"bg-primary":"bg-[var(--status-info)]"),"aria-label":In,title:In}),As=(bt||Hn)&&Bt,Kn=!Z&&Ue&&(wt||gn||xt),Os=xt&&!wt&&!gn,Vs=s.jsx(I,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}),Fs=wt||gn||Os?s.jsx("span",{style:{left:hl+r*ci},className:xe("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:wt?s.jsx(I,{name:"loader-4",className:"h-3 w-3 animate-spin text-primary","aria-label":e("sessions.sidebar.session.status.movingToWorktree")}):gn?xn:Os?Vs:null}):null,rr=Ue&&!Z&&(wt||gn||xt),en=Ue?s.jsx("span",{role:"button",tabIndex:0,onClick:we=>{we.stopPropagation(),we.currentTarget.blur(),S(Ft)},onKeyDown:we=>{(we.key==="Enter"||we.key===" ")&&(we.preventDefault(),we.stopPropagation(),S(Ft))},style:{minWidth:14,minHeight:14,left:hl+r*ci},className:xe("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",rr?"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($t?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:$t?s.jsx(I,{name:"arrow-down-s",className:"h-3 w-3"}):s.jsx(I,{name:"arrow-right-s",className:"h-3 w-3"})}):null,js=et?s.jsx(I,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,Mn=we=>{we&&Be(!1),F(we?Tt:null)},Rn=we=>{if(!we&&oe.current){const{id:At,title:Xt}=oe.current;oe.current=null,b(At),v(Xt)}},tn=we=>{Be(we)},G=we=>{we.preventDefault(),we.stopPropagation(),F(Gt?null:Tt)},Ye=we=>{we.preventDefault(),we.stopPropagation()},at=we=>{we.preventDefault(),we.stopPropagation()},ut=we=>{we.preventDefault(),we.stopPropagation()},_t=we=>{we.preventDefault(),we.stopPropagation()},Et=we=>{we.preventDefault(),we.stopPropagation(),F(null),z(Y,{archivedBucket:c})},vt=we=>{we.preventDefault(),we.stopPropagation(),F(null),z(Y,{archivedBucket:c,hardDelete:!0,skipConfirm:!0})},fs=we=>{we.preventDefault(),we.stopPropagation()},ks=we=>{we.preventDefault(),we.stopPropagation()},Qt=we=>{we.preventDefault(),we.stopPropagation(),q?.vscode?.executeCommand("openchamber.openSessionInEditor",Y.id,Ke)},Bs=we=>{if(je.current){je.current=!1;return}if(Q){if(we?.preventDefault(),we?.stopPropagation(),we?.shiftKey){const Xt=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(vs=>vs.getAttribute("data-session-row")).filter(vs=>typeof vs=="string"&&vs.length>0),ss=Ts.getState().anchorId,hs=new Map;hs.set(Y.id,ze(n)),$e(ss,Y.id,Xt,ne,hs);return}Qe(Y.id,ne,ze(n));return}we?.currentTarget&&g2(we.currentTarget),y(Y.id,Ae)},Hs=we=>{we.defaultPrevented||we.target?.closest('button, a, input, [role="menuitem"], [role="menu"]')||Bs(we)},or=we=>{(we.button===2||we.button===0&&we.ctrlKey&&!Q)&&(je.current=!0)},Dn=we=>{V&&we.pointerType==="touch"&&Pe(!0)},Gn=we=>{V&&we.pointerType==="touch"&&Pe(!1)},yr=({Item:we,Separator:At,Sub:Xt,SubTrigger:ss,SubContent:hs})=>s.jsxs(s.Fragment,{children:[s.jsxs(we,{onClick:()=>{oe.current={id:Y.id,title:Ke}},className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"pencil-ai",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.rename")]}),s.jsxs(we,{onClick:()=>D(Y.id),className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyId")]}),s.jsxs(we,{onClick:()=>Ae&&C({directory:Ae,sessionId:Y.id}),className:"[&>svg]:mr-1",children:[xt?s.jsx(I,{name:"unpin",className:"mr-1 h-4 w-4"}):s.jsx(I,{name:"pushpin",className:"mr-1 h-4 w-4"}),e(xt?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),ue.share?s.jsxs(s.Fragment,{children:[s.jsx(we,{onClick:()=>{ue.share?.url&&A(ue.share.url,Y.id)},className:"[&>svg]:mr-1",children:w===Y.id?s.jsxs(s.Fragment,{children:[s.jsx(I,{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(I,{name:"file-copy",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.copyLink")]})}),s.jsxs(we,{onClick:()=>P(Y.id),className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"link-unlink-m",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(we,{onClick:()=>N(ue),className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"share-2",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.share")]}),s.jsxs(we,{onClick:()=>{os()},className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),!St&&!c&&!Se&&!Xu(Ae)?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(we,{disabled:!Ae||bt||wt,onClick:()=>{!Ae||bt||wt||If({root:ue,descendants:Le(n),sourceDirectory:Ae,successMessage:e("sessions.sidebar.session.moveToWorktree.success"),failureMessage:e("sessions.sidebar.session.moveToWorktree.failed")})},className:"w-full [&>svg]:mr-1",children:[s.jsx(I,{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(wt?"sessions.sidebar.session.moveToWorktree.tooltipMoving":bt?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,Je?s.jsxs(we,{onClick:()=>rt(!0),className:"[&>svg]:mr-1",children:[s.jsx(p2,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,Ae&&!c?(()=>{const vs=[],Ls=ds=>{const ps=jt(ds??null);ps&&!vs.includes(ps)&&vs.push(ps)};if(i&&!Se){const ds=Jt.getState().projects.find(bn=>bn.id===i),ps=jt(ds?.path??null);Ls(ps),ps&&(nt.getState().availableWorktreesByProject.get(ps)??[]).forEach(bn=>Ls(bn.path))}Ls(Ju(Ae)),Ls(Ae);const Ds=vs.flatMap(ds=>_(ds).map(ps=>({scope:ds,folder:ps}))),Ks=Ds.find(({scope:ds,folder:ps})=>L(ds,Y.id)===ps.id)??null,vr=vs[0]??Ae;return s.jsxs(s.Fragment,{children:[s.jsx(At,{}),s.jsxs(Xt,{children:[s.jsxs(ss,{className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(hs,{className:"min-w-[180px]",children:[Ds.length===0?s.jsx(we,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):Ds.map(({scope:ds,folder:ps})=>{const bn=Ks?.folder.id===ps.id;return s.jsxs(we,{onClick:()=>{if(bn){W(ds,Y.id);return}Ks&&Ks.scope!==ds&&W(Ks.scope,Y.id),K(ds,ps.id,Y.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:ps.name}),bn?s.jsx(I,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},ps.id)}),s.jsx(At,{}),s.jsxs(we,{onClick:()=>{const ds=x(vr);ds&&(Ks&&Ks.scope!==vr&&W(Ks.scope,Y.id),K(vr,ds.id,Y.id))},children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),Ks?s.jsxs(we,{onClick:()=>{W(Ks.scope,Y.id)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.removeFromFolder")]}):null]})]})]})})():null,Se?null:s.jsxs(we,{disabled:!Ae,onClick:()=>{Ae&&M(Ae,{mode:"chat",dedupeKey:`session:${Y.id}`,label:Ke,sessionTitleFallback:Ke})},className:"[&>svg]:mr-1",children:[s.jsx(I,{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")})]}),ae?s.jsxs(we,{disabled:!Ae,onClick:es,className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"window",className:"mr-1 h-4 w-4"}),s.jsx("span",{className:"truncate",children:e("sessions.sidebar.session.menu.openMiniChatWindow")})]}):null,s.jsx(At,{}),c?null:s.jsxs(we,{className:"[&>svg]:mr-1",onClick:()=>z(Y,{archivedBucket:c}),children:[s.jsx(I,{name:"inbox-archive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.archive")]}),c?s.jsxs(we,{className:"[&>svg]:mr-1",onClick:()=>U(Y),children:[s.jsx(I,{name:"inbox-unarchive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.restore")]}):null,s.jsxs(we,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>z(Y,{archivedBucket:c,hardDelete:!0}),children:[s.jsx(I,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.delete")]})]}),_r=s.jsx(dn,{align:"end",className:"min-w-[180px]",finalFocus:()=>!(E||se.current),children:yr({Item:Ht,Separator:ln,Sub:Fp,SubTrigger:Bp,SubContent:Lp})}),ir=s.jsx(Lc,{children:s.jsx(_c,{className:"app-region-no-drag z-50",children:s.jsx($c,{"data-slot":"dropdown-menu-content",finalFocus:()=>!(E||se.current),style:{color:"var(--surface-elevated-foreground)"},className:xe(kc,"min-w-[180px]"),children:yr({Item:({className:we,...At})=>s.jsx(Ox,{className:xe(Mp,we),...At}),Separator:({className:we,...At})=>s.jsx(Fx,{className:xe(Rp,we),...At}),Sub:Bx,SubTrigger:({className:we,children:At,...Xt})=>s.jsxs(Lx,{className:xe(Op,we),...Xt,children:[At,s.jsx(I,{name:"arrow-right-s",className:"ml-auto size-3.5"})]}),SubContent:({className:we,children:At,...Xt})=>s.jsx(Lc,{children:s.jsx(_c,{className:"app-region-no-drag z-50",children:s.jsx($c,{"data-slot":"dropdown-menu-sub-content",style:{backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)"},className:xe(kc,we),...Xt,children:At})})})})})})});return s.jsxs(l.Fragment,{children:[s.jsx(X0,{sessionId:Y.id,sessionDirectory:Ae??null,sessionTitle:Ke,children:s.jsxs(Mx,{open:Ut,onOpenChange:tn,onOpenChangeComplete:Rn,children:[s.jsxs(Rx,{render:s.jsx("div",{"data-session-row":Y.id,"data-session-scope":ne??"","data-session-archived":c?"1":"0",onClick:Hs,style:{paddingLeft:Od+r*ci},className:xe("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:[Fs,en,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:Dn,onPointerUp:Gn,onPointerCancel:Gn,onMouseDown:or,onClick:we=>Bs(we),onDoubleClick:we=>{we.stopPropagation(),j(Y.id,Ke)},className:xe("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]",Ne&&"bg-interactive-hover/70",Z?Se?Me:Fe:Me),children:s.jsxs("div",{className:"flex w-full items-center min-w-0 flex-1 gap-1 overflow-hidden",children:[s.jsx("div",{className:xe("block min-w-0 flex-1 truncate typography-ui-label font-normal",Ce?"text-primary":ms?"text-foreground":"text-foreground/80"),children:bi(Ke,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:As?s.jsx(Oc,{sessionId:Y.id,running:bt}):s.jsxs(s.Fragment,{children:[yt,ce?s.jsx(I,{name:"git-branch",className:xe("h-3 w-3",!be&&"text-muted-foreground/60"),style:be?{color:be}:void 0}):null,Vt]})}):As||yt||ce?s.jsx("div",{className:"relative ml-1 flex h-4 flex-shrink-0 items-center justify-end",children:s.jsx("span",{className:xe("inline-flex items-center gap-1 whitespace-nowrap text-right transition-opacity duration-150",Xe?"opacity-0":pe),children:As?s.jsx(Oc,{sessionId:Y.id,running:bt,className:"text-[0.72rem]"}):s.jsxs(s.Fragment,{children:[yt,ce?s.jsx(I,{name:"git-branch",className:xe("h-3 w-3",!be&&"text-muted-foreground/60"),style:be?{color:be}:void 0}):null]})})}):null,Us>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(I,{name:"shield",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Us})]}):null,Kt>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:Ws,"aria-label":Ws,children:[s.jsx(I,{name:"question",className:"h-3 w-3"}),s.jsx("span",{className:"leading-none",children:Kt})]}):null]})})}),Se?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:Ke}),s.jsx("span",{className:"flex-shrink-0 text-muted-foreground",title:ys,children:Vt})]}),Ge?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[s.jsx(I,{name:"folder",className:"h-3 w-3 flex-shrink-0"}),s.jsx("span",{className:"min-w-0 truncate",children:Ge})]}):null,_e?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-muted-foreground",children:[s.jsx(I,{name:"git-branch",className:"h-3 w-3 flex-shrink-0",style:be?{color:be}:void 0}),s.jsx("span",{className:"min-w-0 truncate",children:_e})]}):null,Re&&ve?s.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx(I,{name:"git-pull-request",className:"h-3 w-3 flex-shrink-0",style:be?{color:be}:void 0}),s.jsxs("span",{className:"min-w-0 truncate",style:be?{color:be}:void 0,children:["#",Re.number," · ",ve]})]}):null]})})]})}),js&&!V?s.jsx("div",{className:"absolute right-0 top-1/2 -translate-y-1/2 z-10",children:js}):null,s.jsxs("div",{className:xe("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",Xe||Z&&!Se?"opacity-100":xe("opacity-0",me)),children:[Oe?s.jsx(x2,{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:ut,onMouseDown:_t,onArchive:Et,onDelete:vt}):null,Ie?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",className:xe("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:fs,onMouseDown:ks,onClick:Qt,onKeyDown:we=>we.stopPropagation(),children:s.jsx(I,{name:"external-link",className:xe(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(un,{open:Gt,onOpenChange:Mn,onOpenChangeComplete:Rn,children:[s.jsx(cn,{asChild:!0,children:s.jsx("button",{type:"button",className:xe("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":Xe?"h-4 w-4 opacity-100":xe("h-4 w-4 opacity-0",me)),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:Ye,onMouseDown:at,onClick:G,onKeyDown:we=>we.stopPropagation(),children:s.jsx(I,{name:"more-2",className:xe(Z?"h-3.5 w-3.5":"h-2.5 w-2.5")})})}),_r]})]})]}),ir]})}),Ue&&$t?n.children.map(we=>{const At=H?H(we):{subtreeContainsEditing:fe,menuOpenSessionId:ge,nodeStructureKey:""};return X(we,r+1,Ae??o,i,c,void 0,te,At)}):null,s.jsx($s,{open:st,onOpenChange:ct,children:s.jsxs(zs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(An,{children:[s.jsx(fn,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(mn,{children:Dt===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:Dt}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:Dt})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:Pt,onChange:we=>It(we.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(tr,{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),Lt(Pt)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),Je?s.jsx(h2,{session:ue,open:He,onOpenChange:rt}):null]},Y.id)}const Fd=t=>jt(t.session.directory??null),y2=(t,e)=>(t?.projectLabel??null)===(e?.projectLabel??null)&&(t?.branchLabel??null)===(e?.branchLabel??null),v2=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},di=t=>t.menuOpenSessionId??v2(t),ui=(t,e,n)=>e?n.has(t.node.session.id)?!0:Qn(t.node,e):!1,pl=(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(pl(t.children[c],e.children[c],n,r,o))return!0;return!1},w2=(t,e)=>{if(t.hasSessionSearchQuery||e.hasSessionSearchQuery)return!1;const n=t.archivedBucket?"archived":"active",r=e.archivedBucket?"archived":"active";return pl(t.node,e.node,t.expandedParents,e.expandedParents,o=>`${t.renderContext??"project"}:${n}:${o.session.id}`)||pl(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||Fd(t.node)!==Fd(e.node)||!y2(t.secondaryMeta,e.secondaryMeta)||t.pinnedSessionIds!==e.pinnedSessionIds&&im(t.node,e.node,t.pinnedSessionIds,e.pinnedSessionIds,t.groupDirectory,e.groupDirectory)||t.expandedParents!==e.expandedParents&&w2(t,e)||t.editingId!==e.editingId&&(ui(t,t.editingId,t.subtreeContainsEditing)||ui(e,e.editingId,e.subtreeContainsEditing))||t.editTitle!==e.editTitle&&(ui(t,t.editingId,t.subtreeContainsEditing)||ui(e,e.editingId,e.subtreeContainsEditing))||t.copiedSessionId!==e.copiedSessionId&&(Qn(t.node,t.copiedSessionId)||Qn(e.node,e.copiedSessionId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=di(t),r=di(e);if(Qn(t.node,n)||Qn(e.node,r))return!1}if(t.renamingFolderId!==e.renamingFolderId){const n=di(t),r=di(e);if(Qn(t.node,n)||Qn(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},j2=l.memo(b2,S2);function k2(t){return t.stopPropagation()}function C2(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,p,b,k,v,g,h;if(e[0]!==o||e[1]!==n||e[2]!==r){const M=n("sessions.sidebar.session.untitled");f=$s,g=!!r,e[13]!==o?(h=U=>{U||o(null)},e[13]=o,e[14]=h):h=e[14],m=zs,k=!1,v="max-w-sm gap-5",u=An;let z;e[15]!==n||e[16]!==r?.archivedBucket?(z=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=z):z=e[17],e[18]!==z?(b=s.jsx(fn,{children:z}),e[18]=z,e[19]=b):b=e[19],d=mn,p=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||M,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||M,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||M,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||M,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||M}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||M}),e[0]=o,e[1]=n,e[2]=r,e[3]=d,e[4]=u,e[5]=m,e[6]=f,e[7]=p,e[8]=b,e[9]=k,e[10]=v,e[11]=g,e[12]=h}else d=e[3],u=e[4],m=e[5],f=e[6],p=e[7],b=e[8],k=e[9],v=e[10],g=e[11],h=e[12];let S;e[20]!==d||e[21]!==p?(S=s.jsx(d,{children:p}),e[20]=d,e[21]=p,e[22]=S):S=e[22];let y;e[23]!==u||e[24]!==b||e[25]!==S?(y=s.jsxs(u,{children:[b,S]}),e[23]=u,e[24]=b,e[25]=S,e[26]=y):y=e[26];let j;e[27]!==c||e[28]!==i?(j=()=>c(!i),e[27]=c,e[28]=i,e[29]=j):j=e[29];const C=!i;let N;e[30]!==i?(N=i?s.jsx(I,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(I,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[30]=i,e[31]=N):N=e[31];let w;e[32]!==n?(w=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=w):w=e[33];let A;e[34]!==N||e[35]!==w||e[36]!==j||e[37]!==C?(A=s.jsxs("button",{type:"button",onClick:j,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":C,children:[N,w]}),e[34]=N,e[35]=w,e[36]=j,e[37]=C,e[38]=A):A=e[38];let D;e[39]!==o?(D=()=>o(null),e[39]=o,e[40]=D):D=e[40];let P;e[41]!==n?(P=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=P):P=e[42];let B;e[43]!==D||e[44]!==P?(B=s.jsx("button",{type:"button",onClick:D,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[43]=D,e[44]=P,e[45]=B):B=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 _;e[51]!==F||e[52]!==E?(_=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]=_):_=e[53];let L;e[54]!==B||e[55]!==_?(L=s.jsxs("div",{className:"flex items-center gap-2",children:[B,_]}),e[54]=B,e[55]=_,e[56]=L):L=e[56];let W;e[57]!==A||e[58]!==L?(W=s.jsxs(tr,{className:"w-full sm:items-center sm:justify-between",children:[A,L]}),e[57]=A,e[58]=L,e[59]=W):W=e[59];let K;e[60]!==m||e[61]!==k||e[62]!==W||e[63]!==v||e[64]!==y?(K=s.jsxs(m,{showCloseButton:k,className:v,children:[y,W]}),e[60]=m,e[61]=k,e[62]=W,e[63]=v,e[64]=y,e[65]=K):K=e[65];let x;return e[66]!==f||e[67]!==K||e[68]!==g||e[69]!==h?(x=s.jsx(f,{open:g,onOpenChange:h,children:K}),e[66]=f,e[67]=K,e[68]=g,e[69]=h,e[70]=x):x=e[70],x}function N2(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 p;e[4]!==d||e[5]!==u||e[6]!==n?(p=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]=p):p=e[7];const b=p,k=!!r;let v;e[8]!==o?(v=x=>{x||o(null)},e[8]=o,e[9]=v):v=e[9];let g;e[10]!==f?(g=s.jsx(fn,{children:f}),e[10]=f,e[11]=g):g=e[11];let h;e[12]!==b?(h=s.jsx(mn,{children:b}),e[12]=b,e[13]=h):h=e[13];let S;e[14]!==g||e[15]!==h?(S=s.jsxs(An,{children:[g,h]}),e[14]=g,e[15]=h,e[16]=S):S=e[16];let y;e[17]!==c||e[18]!==i?(y=()=>c(!i),e[17]=c,e[18]=i,e[19]=y):y=e[19];const j=!i;let C;e[20]!==i?(C=i?s.jsx(I,{name:"checkbox-blank",className:"h-4 w-4"}):s.jsx(I,{name:"checkbox",className:"h-4 w-4 text-primary"}),e[20]=i,e[21]=C):C=e[21];let N;e[22]!==n?(N=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=N):N=e[23];let w;e[24]!==N||e[25]!==y||e[26]!==j||e[27]!==C?(w=s.jsxs("button",{type:"button",onClick:y,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":j,children:[C,N]}),e[24]=N,e[25]=y,e[26]=j,e[27]=C,e[28]=w):w=e[28];let A;e[29]!==o?(A=()=>o(null),e[29]=o,e[30]=A):A=e[30];let D;e[31]!==n?(D=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=D):D=e[32];let P;e[33]!==A||e[34]!==D?(P=s.jsx("button",{type:"button",onClick:A,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[33]=A,e[34]=D,e[35]=P):P=e[35];let B;e[36]!==a?(B=()=>{a()},e[36]=a,e[37]=B):B=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]!==B||e[42]!==F?(E=s.jsx("button",{type:"button",onClick:B,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]=B,e[42]=F,e[43]=E):E=e[43];let _;e[44]!==P||e[45]!==E?(_=s.jsxs("div",{className:"flex items-center gap-2",children:[P,E]}),e[44]=P,e[45]=E,e[46]=_):_=e[46];let L;e[47]!==w||e[48]!==_?(L=s.jsxs(tr,{className:"w-full sm:items-center sm:justify-between",children:[w,_]}),e[47]=w,e[48]=_,e[49]=L):L=e[49];let W;e[50]!==L||e[51]!==S?(W=s.jsxs(zs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[S,L]}),e[50]=L,e[51]=S,e[52]=W):W=e[52];let K;return e[53]!==k||e[54]!==W||e[55]!==v?(K=s.jsx($s,{open:k,onOpenChange:v,children:W}),e[53]=k,e[54]=W,e[55]=v,e[56]=K):K=e[56],K}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=C=>{C||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(fn,{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(mn,{children:m}),e[9]=m,e[10]=f):f=e[10];let p;e[11]!==u||e[12]!==f?(p=s.jsxs(An,{children:[u,f]}),e[11]=u,e[12]=f,e[13]=p):p=e[13];let b;e[14]!==o?(b=()=>o(null),e[14]=o,e[15]=b):b=e[15];let k;e[16]!==n?(k=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=k):k=e[17];let v;e[18]!==b||e[19]!==k?(v=s.jsx("button",{type:"button",onClick:b,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:k}),e[18]=b,e[19]=k,e[20]=v):v=e[20];let g;e[21]!==n?(g=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=g):g=e[22];let h;e[23]!==i||e[24]!==g?(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:g}),e[23]=i,e[24]=g,e[25]=h):h=e[25];let S;e[26]!==h||e[27]!==v?(S=s.jsxs(tr,{children:[v,h]}),e[26]=h,e[27]=v,e[28]=S):S=e[28];let y;e[29]!==S||e[30]!==p?(y=s.jsxs(zs,{showCloseButton:!1,className:"max-w-sm gap-5",children:[p,S]}),e[29]=S,e[30]=p,e[31]=y):y=e[31];let j;return e[32]!==c||e[33]!==a||e[34]!==y?(j=s.jsx($s,{open:c,onOpenChange:a,children:y}),e[32]=c,e[33]=a,e[34]=y,e[35]=j):j=e[35],j}const D2=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:p}=t,{t:b}=gt(),k=!!r&&!i;let v;e[0]!==i||e[1]!==b?(v=b(i?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=i,e[1]=b,e[2]=v):v=e[2];const g=v;let h;e[3]!==n||e[4]!==b?(h=b("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=b,e[5]=h):h=e[5];let S;e[6]!==h?(S=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:h}),e[6]=h,e[7]=S):S=e[7];let y;e[8]!==k||e[9]!==u||e[10]!==a||e[11]!==c||e[12]!==d||e[13]!==o||e[14]!==b?(y=k?s.jsxs(un,{children:[s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx(cn,{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":b("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(I,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(ht,{side:"top",sideOffset:4,children:s.jsx("p",{children:b("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(dn,{align:"end",className:"min-w-[180px]",children:[o.length===0?s.jsx(Ht,{disabled:!0,className:"text-muted-foreground",children:b("sessions.sidebar.folders.none")}):o.map(x=>s.jsx(Ht,{onClick:()=>c(x.id),children:s.jsx("span",{className:"flex-1 truncate",children:x.name})},x.id)),s.jsx(ln,{}),s.jsxs(Ht,{onClick:a,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"}),b("sessions.sidebar.folders.newFolderEllipsis")]}),u?s.jsxs(Ht,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1 h-4 w-4"}),b("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=k,e[9]=u,e[10]=a,e[11]=c,e[12]=d,e[13]=o,e[14]=b,e[15]=y):y=e[15];let j;e[16]!==i||e[17]!==m||e[18]!==b?(j=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":b("sessions.sidebar.bulkActions.restore"),children:s.jsx(I,{name:"inbox-unarchive",className:"h-4 w-4"})})}),s.jsx(ht,{side:"top",sideOffset:4,children:s.jsx("p",{children:b("sessions.sidebar.bulkActions.restore")})})]}):null,e[16]=i,e[17]=m,e[18]=b,e[19]=j):j=e[19];let C;e[20]===Symbol.for("react.memo_cache_sentinel")?(C=xe("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]=C):C=e[20];let N;e[21]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx(I,{name:"delete-bin",className:"h-4 w-4"}),e[21]=N):N=e[21];let w;e[22]!==g||e[23]!==f?(w=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:f,className:C,"aria-label":g,children:N})}),e[22]=g,e[23]=f,e[24]=w):w=e[24];let A;e[25]!==g?(A=s.jsx(ht,{side:"top",sideOffset:4,children:s.jsx("p",{children:g})}),e[25]=g,e[26]=A):A=e[26];let D;e[27]!==w||e[28]!==A?(D=s.jsxs(ft,{children:[w,A]}),e[27]=w,e[28]=A,e[29]=D):D=e[29];let P;e[30]!==b?(P=b("sessions.sidebar.header.actions.exitSelection"),e[30]=b,e[31]=P):P=e[31];let B;e[32]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx(I,{name:"close",className:"h-4 w-4"}),e[32]=B):B=e[32];let F;e[33]!==p||e[34]!==P?(F=s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:p,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":P,children:B})}),e[33]=p,e[34]=P,e[35]=F):F=e[35];let E;e[36]!==b?(E=b("sessions.sidebar.header.actions.exitSelection"),e[36]=b,e[37]=E):E=e[37];let _;e[38]!==E?(_=s.jsx(ht,{side:"top",sideOffset:4,children:s.jsx("p",{children:E})}),e[38]=E,e[39]=_):_=e[39];let L;e[40]!==F||e[41]!==_?(L=s.jsxs(ft,{children:[F,_]}),e[40]=F,e[41]=_,e[42]=L):L=e[42];let W;e[43]!==D||e[44]!==L||e[45]!==y||e[46]!==j?(W=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[y,j,D,L]}),e[43]=D,e[44]=L,e[45]=y,e[46]=j,e[47]=W):W=e[47];let K;return e[48]!==W||e[49]!==S?(K=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[S,W]}),e[48]=W,e[49]=S,e[50]=K):K=e[50],K},P2=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:p}=t,b=Ts(x=>x.enabled),k=Ts(x=>x.selectedIds.size),v=k>0,g=Ts(x=>x.selectedIds),h=Ts(x=>x.scopeKey),S=l.useCallback(()=>{Ts.getState().toggleMode()},[]),y=l.useCallback(()=>{Ts.getState().disable()},[]),j=l.useMemo(()=>{if(!v||typeof document>"u")return!1;let x=!1,M=!1;for(const z of g){const U=document.querySelectorAll(`[data-session-row="${CSS.escape(z)}"]`);for(const V of U)V.getAttribute("data-session-archived")==="1"?M=!0:x=!0}return M&&!x},[v,g]),C=l.useMemo(()=>{if(h)return h;if(!v||typeof document>"u")return null;for(const x of g){const z=document.querySelector(`[data-session-row="${CSS.escape(x)}"]`)?.getAttribute("data-session-scope");if(z&&z.length>0)return z}return null},[v,g,h]),N=l.useMemo(()=>{if(!C)return[];const x=i.get(C);return x&&x.length>0?x.map(M=>M.scopeKey):[C]},[C,i]),w=l.useMemo(()=>N.flatMap(x=>o[x]??[]),[o,N]),A=l.useCallback(x=>{for(const M of N)if((o[M]??[]).some(z=>z.id===x))return M;return null},[o,N]),D=l.useMemo(()=>{if(!v)return!1;for(const x of N)for(const M of o[x]??[])for(const z of M.sessionIds)if(g.has(z))return!0;return!1},[o,N,v,g]),P=l.useCallback((x,M)=>{const z=Array.from(g);for(const U of N)U!==x&&a(U,z);c(x,M,z)},[c,a,g,N]),B=l.useCallback(x=>{if(!v)return;const M=A(x);M&&P(M,x)},[v,P,A]),F=l.useCallback(()=>{const x=N[0];if(!x||!v)return;const M=d(x);M&&P(x,M.id)},[d,v,P,N]),E=l.useCallback(()=>{if(!v)return;const x=Array.from(g);for(const M of N)a(M,x)},[a,g,N,v]),_=l.useCallback(async()=>{const x=Array.from(g);if(x.length!==0){if(j){const{deletedIds:M,failedIds:z}=await f(x);M.length>0&&De.success(M.length===1?e("sessions.sidebar.bulkActions.deletedSingle",{count:M.length}):e("sessions.sidebar.bulkActions.deletedPlural",{count:M.length})),z.length>0&&De.error(z.length===1?e("sessions.sidebar.bulkActions.failedDeleteSingle",{count:z.length}):e("sessions.sidebar.bulkActions.failedDeletePlural",{count:z.length}))}else{const{archivedIds:M,failedIds:z}=await u(x);M.length>0&&De.success(M.length===1?e("sessions.sidebar.bulkActions.archivedSingle",{count:M.length}):e("sessions.sidebar.bulkActions.archivedPlural",{count:M.length})),z.length>0&&De.error(z.length===1?e("sessions.sidebar.bulkActions.failedArchiveSingle",{count:z.length}):e("sessions.sidebar.bulkActions.failedArchivePlural",{count:z.length}))}Ts.getState().clear()}},[u,j,f,g,e]),L=l.useCallback(()=>{if(!v)return;const x=g.size;if(!r){_();return}p({sessionCount:x,archivedBucket:j})},[j,_,g,r,p,v]),W=l.useCallback(async()=>{if(!v||!j)return;const x=Array.from(g),{restoredIds:M,failedIds:z}=await m(x);M.length>0&&De.success(M.length===1?e("sessions.sidebar.bulkActions.restoredSingle",{count:M.length}):e("sessions.sidebar.bulkActions.restoredPlural",{count:M.length})),z.length>0&&De.error(z.length===1?e("sessions.sidebar.bulkActions.failedRestoreSingle",{count:z.length}):e("sessions.sidebar.bulkActions.failedRestorePlural",{count:z.length})),Ts.getState().clear()},[j,v,g,e,m]),K=l.useCallback(async()=>{p(null),await _()},[_]);return l.useEffect(()=>{if(!b)return;const x=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),M=z=>{if(n)return;const U=z.target;if(U&&(U.tagName==="INPUT"||U.tagName==="TEXTAREA"||U.isContentEditable))return;const V=x?z.metaKey:z.ctrlKey;if(z.key==="Escape"){z.preventDefault(),Ts.getState().disable();return}if(V&&z.key==="Backspace"){z.preventDefault(),L();return}if(V&&(z.key==="a"||z.key==="A")){const Z=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(Z.length===0)return;z.preventDefault();const le=Ts.getState().scopeKey??Z[0]?.getAttribute("data-session-scope")??null,te=ge=>le?ge.getAttribute("data-session-scope")===le:!0,fe=Z.filter(te).map(ge=>ge.getAttribute("data-session-row")).filter(ge=>typeof ge=="string"&&ge.length>0);if(fe.length===0)return;Ts.getState().replaceAll(fe,le||null)}};return window.addEventListener("keydown",M),()=>window.removeEventListener("keydown",M)},[L,n,b]),{selectionModeEnabled:b,hasSelection:v,selectedIdsSize:k,bulkScopeIsArchived:j,derivedSelectionScope:C,bulkScopeFolders:w,bulkCanRemoveFromFolder:D,handleToggleSelectionMode:S,handleExitSelectionMode:y,handleBulkMoveToFolder:B,handleBulkCreateFolderAndMove:F,handleBulkRemoveFromFolder:E,handleBulkDelete:L,handleBulkRestore:W,confirmBulkDelete:K}},E2=2880*60*1e3,T2=t=>!!t.parentID,I2=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},R2=(t,e,n=Date.now())=>{const r=n-E2;return t.filter(o=>I2(o)||T2(o)?!1:e.has(o.id)||M2(o)>=r)},Bd={selected:0,"active-project":1,expanded:2,visible:3,background:4};function O2(t){const e=new Map,n=(r,o,i)=>{const c=jt(r??null);if(!c)return;const a=e.get(c);a&&Bd[a.priority]<=Bd[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 fi="oc.sessions.projectCollapse",Ld="oc.sessions.groupOrder",_d="oc.sessions.groupCollapse",$d="oc.sessions.activeSessionByProject",zd="oc.sessions.expandedParents.v3",F2=(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},B2=(t,e,n)=>{if(t.time?.archived)return!0;const r=jt(Zs(t))?.toLowerCase();return r?e.size===0?n?.allowEmptyDirectorySet??!0:e.has(r):n?.allowUnknownDirectory??!0},L2=5*6e4,_2=new Set,Ba=[],Cn=t=>{const e=l.useRef(t);return e.current=t,l.useCallback((...n)=>e.current(...n),[])},$2=t=>{const e=it.c(14),{owner:n,childStores:r,projectSections:o,activeProjectId:i,collapsedProjects:c,collapsedGroups:a,currentDirectory:d}=t,u=nt(W2);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,O2({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 p,b;return e[10]!==r||e[11]!==n?(p=()=>()=>r.clearBootstrapDemand(n),b=[r,n],e[10]=r,e[11]=n,e[12]=p,e[13]=b):(p=e[12],b=e[13]),l.useEffect(p,b),null},z2=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 p=jt(f.directory)?.toLowerCase();if(p&&i.has(p))return!0}return!1},e[2]=i,e[3]=c):c=e[3];const a=ea(c);let d;e[4]!==i?(d=m=>{for(const[f,p]of Object.entries(m.index.project.unseenCount)){if(!p)continue;const b=jt(f)?.toLowerCase();if(b&&i.has(b))return!0}return!1},e[4]=i,e[5]=d):d=e[5];const u=ta(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 p;return e[10]!==m||e[11]!==f?(p=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]=p):p=e[12],p}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 p;return e[17]!==m||e[18]!==f?(p=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]=p):p=e[19],p}return null},U2=({isVisible:t=!0,mobileVariant:e=!1,onSessionSelected:n,allowReselect:r=!1,hideDirectoryControls:o=!1,showOnlyMainWorkspace:i=!1})=>{Ua("react.session_sidebar_render"),Tn("ui.session_sidebar.render"),Tn(`ui.session_sidebar.render.${e?"mobile":"desktop"}`),Tn(`ui.session_sidebar.render.${t?"visible":"hidden"}`);const{t:c}=gt(),[a,d]=l.useState(!1),[u,m]=l.useState(""),f=l.useRef(null),p=l.useRef(null),[b,k]=l.useState(null),[v,g]=l.useState(""),[h,S]=l.useState(null),[y,j]=l.useState(new Set),C=l.useMemo(()=>Qr(),[]),[N,w]=l.useState(new Set),[A,D]=l.useState(new Map),[P,B]=l.useState(new Map),F=he(R=>R.isNewWorktreeDialogOpen),E=he(R=>R.setNewWorktreeDialogOpen),[_,L]=l.useState(!1),[W,K]=l.useState(null),[x,M]=l.useState(null),[z,U]=l.useState(""),[V,Z]=l.useState(null),[X,le]=l.useState(null),[te,fe]=l.useState(null),ge=To(R=>R.ids),H=Zi(l.useCallback(R=>t?R.rankById:Nl,[t])),Se=ea(Xn(R=>t?[...R.statusById.keys()].sort():Ba)),ae=l.useMemo(()=>new Set(Se),[Se]),q=ta(Xn(R=>t?Object.entries(R.index.session.unseenCount).filter(([,We])=>We>0).map(([We])=>We).sort():Ba)),me=l.useMemo(()=>new Set(q),[q]),pe=To(R=>R.toggle),[Ie,Oe]=l.useState(()=>{try{const R=Qr().getItem(_d);if(!R)return new Set;const We=JSON.parse(R);return new Set(Array.isArray(We)?We.filter(qe=>typeof qe=="string"):[])}catch{return new Set}}),[Me,Fe]=l.useState(()=>{try{const R=Qr().getItem(Ld);if(!R)return new Map;const We=JSON.parse(R),qe=new Map;return Object.entries(We).forEach(([dt,Ct])=>{Array.isArray(Ct)&&qe.set(dt,Ct.filter(Ot=>typeof Ot=="string"))}),qe}catch{return new Map}}),je=l.useMemo(()=>{try{const R=Qr().getItem($d);if(!R)return new Map;const We=JSON.parse(R),qe=new Map;return Object.entries(We).forEach(([dt,Ct])=>{typeof Ct=="string"&&Ct.length>0&&qe.set(dt,Ct)}),qe}catch{return new Map}},[]),Ne=l.useCallback(R=>{try{C.setItem($d,JSON.stringify(Object.fromEntries(R.entries())))}catch{}},[C]),[Pe,se]=l.useState(new Map),oe=l.useRef(new Map),Ee=l.useRef(0),J=as(R=>R.homeDirectory),re=as(R=>R.currentDirectory),ee=Jt(R=>R.projects),$=Jt(R=>R.activeProjectId),de=Jt(R=>R.removeProject),Y=Jt(R=>R.setActiveProjectIdOnly),ue=Jt(R=>R.updateProjectMeta),Te=Jt(R=>R.reorderProjects),Ge=he(R=>R.setActiveMainTab),_e=he(R=>R.openContextPanelTab),ie=he(R=>R.setSettingsDialogOpen),Re=he(R=>R.toggleHelpDialog),be=he(R=>R.setAboutDialogOpen),T=he(R=>R.setSessionSwitcherOpen),ce=he(R=>R.setScheduledTasksDialogOpen),ve=he(R=>R.setArchivePageOpen),Ce=he(R=>R.setWorktreesPageProjectId),Ae=he(R=>R.openMultiRunLauncher),ne=he(R=>R.notifyOnSubtasks),ke=he(R=>R.showDeletionDialog),Ze=he(R=>R.setShowDeletionDialog),Q=Cl(u,120),ye=l.useMemo(()=>Q.trim().toLowerCase(),[Q]),Qe=ye.length>0,$e=Gs(R=>R.collapsedFolderIds),ze=Gs(R=>R.foldersMap),Le=Gs(R=>R.getFoldersForScope),st=Gs(R=>R.createFolder),ct=Gs(R=>R.renameFolder),Pt=Gs(R=>R.deleteFolder),It=Gs(R=>R.addSessionToFolder),Tt=Gs(R=>R.addSessionsToFolder),et=Gs(R=>R.removeSessionFromFolder),Mt=Gs(R=>R.removeSessionsFromFolders),kt=Gs(R=>R.toggleFolderCollapse),bt=Gs(R=>R.getSessionFolderId);u0({enabled:t,isSessionSearchOpen:a,setIsSessionSearchOpen:d,sessionSearchInputRef:p,sessionSearchContainerRef:f});const Bt=$u(t),wt=qi(),Rt=Ku(),pt=`session-sidebar:${l.useId()}`,yt=_p(),Ke=l.useMemo(()=>Array.from(yt.values()),[yt]),Ue=l.useMemo(()=>sr(),[]),xt=Ms(),Ft=Is(R=>R.status==="ready"),$t=Is(Xn(R=>R.activeSessions.map(wa).sort())),ns=Is(Xn(R=>R.archivedSessions.map(wa).sort())),Kt=Is(R=>R.activeSessions),St=Is(R=>R.archivedSessions),zt=l.useRef({signature:"",sessions:[]}),ms=l.useMemo(()=>new Set(Kt.map(R=>R.id)),[Kt]),ts=(()=>{const R=Ke.filter(qe=>!ms.has(qe.id)),We=R.map(wa).sort().join(`
914
+ `);return zt.current.signature===We?zt.current.sessions:(zt.current={signature:We,sessions:R},R)})(),ys=nt(R=>R.setCurrentSession),Vt=nt(R=>R.updateSessionTitle),Gt=nt(R=>R.shareSession),Ut=nt(R=>R.unshareSession),Be=nt(R=>R.worktreeMetadata),Xe=nt(R=>R.availableWorktreesByProject),Je=nt(R=>R.openNewSessionDraft),He=l.useCallback(R=>{he.getState().closeMainSurfaces(),Je(R),Ue&&window.dispatchEvent(new CustomEvent("openchamber:navigate",{detail:{view:"chat"}}))},[Ue,Je]),rt=No(Xn(R=>({checkForUpdates:R.checkForUpdates,available:R.available,runtimeType:R.runtimeType,info:R.info,downloading:R.downloading,downloaded:R.downloaded,progress:R.progress,error:R.error,downloadUpdate:R.downloadUpdate,restartToUpdate:R.restartToUpdate}))),Dt=l.useMemo(()=>F2(ee,Xe,{includeWorktrees:!Ue}),[Xe,Ue,ee]),Wt=l.useMemo(()=>VS(Kt,ts).filter(We=>!zu(We)&&(!Ue&&Xu(We.directory)||B2(We,Dt,{allowUnknownDirectory:!Ue,allowEmptyDirectorySet:!Ue}))),[Kt,Ue,Dt,ts]),rs=l.useMemo(()=>[...Kt,...St],[St,Kt]),Lt=l.useRef(Ke);l.useEffect(()=>{Lt.current=Ke},[Ke]);const os=l.useMemo(()=>`${xt}|${ee.map(R=>`${R.id}:${jt(R.path)??""}`).join("|")}`,[ee,xt]),[es,Us]=l.useState(Ue?os:null),[Ws,Hn]=l.useReducer(R=>R+1,0),gn=!Ue&&es!==os,[In,xn]=l.useState(new Set);l.useEffect(()=>{let R=!1;return(async()=>{const qe=xt,dt=Jt.getState().projects;if(dt.length===0||Ue){R||(xn(new Set),Us(os));return}const Ct=nt.getState().availableWorktreesByProject,Ot=new Map(Ct),Ps=new Set,Ss=3;let Fn=0;const vn=Array.from({length:Ss},async()=>{for(;;){const wn=Fn;if(Fn+=1,wn>=dt.length)return;const ac=dt[wn],cr=jt(ac.path);if(cr)try{const ba=await Ga(async()=>gr.getState().directories.get(cr)?.isGitRepo??await Zu(cr)?Wp({id:ac.id,path:cr}):null);if(ba===null){Ot.delete(cr);continue}if(R)return;ba.length===0?Ot.delete(cr):Ot.set(cr,ba)}catch{Ps.add(cr)}}});if(await Promise.all(vn),R||Ms()!==qe)return;const Kr=new Set(dt.map(wn=>jt(wn.path)).filter(Boolean));for(const wn of Ot.keys())Kr.has(wn)||Ot.delete(wn);const lr=Vp(dt,Ot),Xo=[...lr.values()].flat();c0(Xo.map(wn=>wn.path),Date.now()),Hp(lr,Ct)||nt.setState({availableWorktrees:Xo,availableWorktreesByProject:lr}),xn(Ps),Us(os)})(),()=>{R=!0}},[Ue,os,xt,Ws]),l.useEffect(()=>{let R=null,We=!1;const qe=new Set,dt=ra(Ct=>{if(Ct.type==="scheduled-task-ran")We=!0;else if(Ct.type==="session-created")qe.add(Ct.directory),Hn();else return;R&&clearTimeout(R),R=setTimeout(()=>{if(R=null,We){We=!1,qe.clear(),Tl(Lt.current);return}const Ot=[...qe];qe.clear(),Ot.length>0&&gi(Ot,Lt.current)},500)});return()=>{R&&clearTimeout(R),dt()}},[]);const As=l.useMemo(()=>Wn(),[]),{isTablet:Kn}=br(),Os=e||Kn,{buildGroupSearchText:Vs,filterSessionNodesForSearch:Fs,buildGroupedSessions:rr}=d0({homeDirectory:J,worktreeMetadata:Be,pinnedSessionIds:ge,sessionOrderRanks:H,gitBranches:Bt,isVSCode:Ue}),{scheduleCollapsedProjectsPersist:en}=x0({isVSCode:Ue,safeStorage:C,keys:{sessionExpanded:zd,projectCollapse:fi,groupOrder:Ld,groupCollapse:_d},groupOrderByProject:Me,collapsedGroups:Ie,setExpandedParents:j,setCollapsedProjects:w}),js=l.useMemo(()=>_u(Wt,ge,H),[ge,H,Wt]),Mn=l.useMemo(()=>js.map(R=>R.id).join("|"),[js]),Rn=l.useRef(null),tn=l.useMemo(()=>{const R=Rn.current;if(R&&R.signature===Mn)return R.map;const We=new Map(js.map((qe,dt)=>[qe.id,dt]));return Rn.current={signature:Mn,map:We},We},[js,Mn]),G=l.useMemo(()=>{const R=new Map;return js.forEach(We=>{const qe=We.parentID;if(!qe)return;const dt=R.get(qe)??[];dt.push(We),R.set(qe,dt)}),R.forEach(We=>We.sort((qe,dt)=>Rr(qe,dt,ge,H))),R},[js,ge,H]),Ye=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]),at=l.useMemo(()=>ee.find(R=>R.id===h)??null,[ee,h]),ut=l.useCallback(R=>{h&&ue(h,{label:R.label,icon:R.icon,color:R.color,iconBackground:R.iconBackground,defaultModel:R.defaultModel??null})},[h,ue]),_t=l.useCallback(()=>{E(!0)},[E]),Et=l.useCallback(()=>{const R=No.getState();if(R.available&&R.info){L(!0);return}rt.checkForUpdates().then(()=>{const{available:We,error:qe}=No.getState();if(qe){De.error(c("sessions.sidebar.updateCheck.errorTitle"),{description:qe});return}if(!We){De.success(c("sessions.sidebar.updateCheck.latestVersion"));return}L(!0)})},[c,rt]),vt=l.useCallback(()=>{e&&T(!1),ie(!0)},[e,T,ie]),fs=rt.available&&(rt.runtimeType==="desktop"||rt.runtimeType==="web"),ks=nt(R=>R.deleteSession),Qt=nt(R=>R.deleteSessions),Bs=nt(R=>R.archiveSession),Hs=nt(R=>R.archiveSessions),or=nt(R=>R.unarchiveSession),Dn=nt(R=>R.unarchiveSessions),{copiedSessionId:Gn,handleSessionSelect:yr,handleSessionDoubleClick:_r,handleSaveEdit:ir,handleCancelEdit:we,handleShareSession:At,handleCopyShareUrl:Xt,handleCopySessionId:ss,handleUnshareSession:hs,handleDeleteSession:vs,handleRestoreSession:Ls,confirmDeleteSession:Ds}=f0({mobileVariant:e,allowReselect:r,onSessionSelected:n,isSessionSearchOpen:a,sessionSearchQuery:u,setSessionSearchQuery:m,setIsSessionSearchOpen:d,setActiveMainTab:Ge,setSessionSwitcherOpen:T,setCurrentSession:ys,updateSessionTitle:Vt,shareSession:Gt,unshareSession:Ut,deleteSession:ks,deleteSessions:Qt,archiveSession:Bs,archiveSessions:Hs,unarchiveSession:or,childrenMap:G,showDeletionDialog:ke,setDeleteSessionConfirm:Z,deleteSessionConfirm:V,setEditingId:k,setEditTitle:g,editingId:b,editTitle:v}),Ks=l.useCallback(()=>{if(!X)return;const{scopeKey:R,folderId:We}=X;le(null),Pt(R,We)},[X,Pt]),vr=l.useCallback(()=>{Un.requestDirectoryDialog()},[]),ds=l.useCallback(R=>{j(We=>{const qe=$p(We,R);try{C.setItem(zd,JSON.stringify(Array.from(qe)))}catch{}return qe})},[C]),ps=l.useCallback((R,We)=>{if(!R)return null;We&&$e.has(We)&&kt(We);const qe=st(R,c("sessions.sidebar.folder.newFolderName"),We);return M(qe.id),U(qe.name),qe},[$e,kt,st,c]),bn=Cn(yr),oa=Cn(_r),ia=Cn(ir),aa=Cn(we),zo=Cn(At),Uo=Cn(Xt),$r=Cn(ss),zr=Cn(hs),co=Cn(vs),la=Cn(Ls),uo=Cn(ps),fo=l.useCallback((R,We,qe=7)=>{B(dt=>{const Ct=new Map(dt);return Ct.set(R,We+qe),Ct})},[]),Ur=l.useCallback(R=>{B(We=>{if(!We.has(R))return We;const qe=new Map(We);return qe.delete(R),qe})},[]),Wo=l.useCallback(R=>{B(We=>{let qe=!1;const dt=new Map(We),Ct=`${R}:`;for(const Ot of dt.keys())Ot.startsWith(Ct)&&(dt.delete(Ot),qe=!0);return qe?dt:We})},[]),mo=l.useRef([]),ca=l.useCallback(()=>{Ee.current=Date.now()+150,B(new Map),Oe(()=>{const R=new Set;return mo.current.forEach(We=>{We.groups.forEach(qe=>{qe.isMain||R.add(`${We.project.id}:${qe.id}`)})}),R}),w(()=>{const R=new Set(ee.map(We=>We.id));try{C.setItem(fi,JSON.stringify(Array.from(R)))}catch{}return Ue||en(R),R})},[ee,Ue,C,en]),wr=l.useCallback(()=>{Ee.current=Date.now()+150,B(new Map),Oe(new Set),w(()=>{const R=new Set;try{C.setItem(fi,JSON.stringify([]))}catch{}return Ue||en(R),R})},[Ue,C,en]),da=l.useCallback(R=>{Ee.current=Date.now()+150,Wo(R),w(We=>{const qe=new Set(We);qe.has(R)?qe.delete(R):qe.add(R);try{C.setItem(fi,JSON.stringify(Array.from(qe)))}catch{}return Ue||en(qe),qe})},[Ue,Wo,C,en]),Cs=l.useMemo(()=>ee.map(R=>({...R,normalizedPath:jt(R.path)})).filter(R=>!!R.normalizedPath),[ee]),ua=l.useMemo(()=>Cs.map(R=>R.normalizedPath),[Cs]),ar=l.useMemo(()=>{const R=new Set(Cs.map(We=>We.normalizedPath));if(!Ue)for(const We of Xe.values())for(const qe of We){const dt=jt(qe.path);dt&&R.add(dt)}return[...R].sort()},[Xe,Ue,Cs]),Vo=l.useRef(null);l.useEffect(()=>{const R=new Set(ar),We=Vo.current;if(Vo.current=R,!We){Ue&&ar.length>0&&gi(ar,Lt.current);return}const qe=ar.filter(dt=>!We.has(dt));qe.length!==0&&gi(qe,Lt.current)},[Ue,ar]);const{github:ho}=nr(),Wr=Fr(R=>R.status),Sr=Fr(R=>R.hasChecked),Ho=zp(t?ua:Ba),Ko=on(R=>R.ensureEntry),Go=on(R=>R.setParams),O=on(R=>R.refreshTargets);S0({enabled:t,normalizedProjects:Cs,gitRepoStatus:Ho,setProjectRepoStatus:D,setProjectRootBranches:se});const Ve=nt(R=>R.isLoading),ot=l.useMemo(()=>R0(Wt,Cs,Xe,Ue,St),[St,Xe,Ue,Cs,Wt]);E0({enabled:t,hasAuthoritativeGlobalSessions:Ft,sessions:rs});const{getSessionsForProject:Nt,getArchivedSessionsForProject:qt}=A0({ownership:ot});JS({enabled:t,normalizedProjects:Cs,ownership:ot,isSessionsLoading:Ve,hasAuthoritativeGlobalSessions:Ft,isWorktreeTopologyLoading:gn,unresolvedWorktreeProjectPaths:In,foldersMap:ze,createFolder:st,addSessionToFolder:It});const cs=l.useRef(!1);$&&A.has($)&&(cs.current=!!A.get($));const is=xs(R=>R.showRecentSection),ws=xs(R=>R.projectDisplayMode),On=xs(R=>R.singleProjectId),po=xs(R=>R.setSingleProjectId),qo=xs(R=>R.showArchivedSessions),Vr=xs(R=>R.projectSortOrder),go=xs(R=>R.stickyZoneHeaders),Hr=Jt(R=>R.manualProjectOrder),yn=!Ue&&!ah(),sn=ws==="single"&&yn,Pn=is&&!sn,qn=l.useRef(new Set),jr=l.useRef(new Set),kr=Cc(qn.current,y,"project"),Cr=Cc(jr.current,y,"recent");qn.current=kr,jr.current=Cr;const fa={isVisible:t,mobileVariant:e,onSessionSelected:n,allowReselect:r,hideDirectoryControls:o,showOnlyMainWorkspace:i,t:c,isTablet:Kn,liveSessions:Ke,activeSessionStructure:$t,archivedSessionStructure:ns,globalActiveSessions:Kt,archivedSessions:St,projects:ee,activeProjectId:$,manualProjectOrder:Hr,currentDirectory:re,worktreeMetadata:Be,availableWorktreesByProject:Xe,pinnedSessionIds:ge,sessionOrderRanks:H,foldersMap:ze,collapsedFolderIds:$e,gitBranches:Bt,gitRepoStatus:Ho,githubAuthStatus:Wr,githubAuthChecked:Sr,updateStore:rt,showRecentSection:Pn,showArchivedSessions:qo,projectSortOrder:Vr,projectRepoStatus:A,projectRootBranches:Pe,resolvedWorktreeTopologyKey:es,unresolvedWorktreeProjectPaths:In,isSessionSearchOpen:a,sessionSearchQuery:u,editingId:b,editTitle:v,editingProjectDialogId:h,expandedParents:y,collapsedProjects:N,visibleSessionCountByGroup:P,updateDialogOpen:_,openSidebarMenuKey:W,renamingFolderId:x,renameFolderDraft:z,deleteSessionConfirm:V,deleteFolderConfirm:X,bulkDeleteConfirm:te,collapsedGroups:Ie},Gl=l.useRef(null),ql=Gl.current;if(ql){let R=!1;for(const We of Object.keys(fa))Object.is(ql[We],fa[We])||(Tn(`ui.session_sidebar.source.${We}`),R=!0);R||Tn("ui.session_sidebar.source.parent_or_context")}Gl.current=fa;const ym=l.useMemo(()=>{const R=[...Cs];switch(Vr){case"a-z":R.sort((We,qe)=>{const dt=(We.label||We.path).toLowerCase(),Ct=(qe.label||qe.path).toLowerCase();return dt.localeCompare(Ct)});break;case"z-a":R.sort((We,qe)=>{const dt=(We.label||We.path).toLowerCase();return(qe.label||qe.path).toLowerCase().localeCompare(dt)});break;case"date-added":R.sort((We,qe)=>(qe.addedAt??0)-(We.addedAt??0));break;case"recent":R.sort((We,qe)=>(qe.lastOpenedAt??0)-(We.lastOpenedAt??0));break;case"manual":{const We=new Map(Hr.map((qe,dt)=>[qe,dt]));R.sort((qe,dt)=>{const Ct=We.get(qe.id)??1/0,Ot=We.get(dt.id)??1/0;return Ct-Ot});break}}return R},[Cs,Vr,Hr]),{projectSections:Ns,groupSearchDataByGroup:Yl,sectionsForRender:Ql,flatSectionsForRender:Yo,searchMatchCount:vm}=n0({normalizedProjects:ym,getSessionsForProject:Nt,getArchivedSessionsForProject:qt,availableWorktreesByProject:Xe,projectRepoStatus:A,projectRootBranches:Pe,lastRepoStatus:cs.current,buildGroupedSessions:rr,hasSessionSearchQuery:Qe,normalizedSessionSearchQuery:ye,filterSessionNodesForSearch:Fs,buildGroupSearchText:Vs,foldersMap:ze});mo.current=Ns;const wm=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:Sm}=e0(Me),Xl=l.useRef(!1);l.useEffect(()=>{if(Xl.current||Ns.length===0)return;const R=Ns.flatMap(We=>We.groups.filter(qe=>qe.isArchivedBucket).map(qe=>`${We.project.id}:${qe.id}`));R.length>0&&Oe(We=>new Set([...We,...R])),Xl.current=!0},[Ns]);const Jl=l.useMemo(()=>{const R=new Map,We=new Map;return Ns.forEach(qe=>{const dt=El(qe.project.label?.trim()||xr(qe.project.normalizedPath,J)||qe.project.normalizedPath);qe.groups.forEach(Ct=>{const Ot=Ct.branch&&Ct.branch!=="HEAD"&&Ct.branch!==dt?Ct.branch:null,Ps={projectLabel:dt,branchLabel:Ot},Ss=Fn=>{Fn.forEach(vn=>{const Kr=qe.project.normalizedPath.length,lr=We.get(vn.session.id)??-1;Kr<lr||(R.set(vn.session.id,{node:vn,projectId:qe.project.id,groupDirectory:Ct.directory,secondaryMeta:Ps}),We.set(vn.session.id,Kr),vn.children.length>0&&Ss(vn.children))})};Ss(Ct.sessions)})}),R},[Ns,J]),ma=l.useMemo(()=>!Pn||Ue?[]:R2(Wt.filter(R=>!Wa(R.directory,J)),ae).sort((R,We)=>Rr(R,We,ge,H)),[ae,J,Ue,ge,H,Wt,Pn]),Zl=l.useMemo(()=>Wt.filter(R=>!R.parentID&&!R.time?.archived&&Wa(R.directory,J)).sort((R,We)=>Rr(R,We,ge,H)),[J,ge,H,Wt]),Qo=l.useMemo(()=>{if(Ue)return[];const R=dt=>{const Ct=Jl.get(dt.id),Ot=jt(dt.directory??null),Ps=Ct?.node??{session:dt,children:[],worktree:null},Fn=(Qe?Fs([Ps],ye):[Ps])[0];if(!Fn)return null;const vn=Ct?.secondaryMeta?{projectLabel:Ct.secondaryMeta.projectLabel,branchLabel:Ue?null:Ct.secondaryMeta.branchLabel}:null;return{node:Fn,projectId:Ct?.projectId??null,groupDirectory:Ct?.groupDirectory??Ot,secondaryMeta:vn}},We=Pn?ma.map(R).filter(dt=>dt!==null):[],qe=Zl.map(R).filter(dt=>dt!==null);return[{key:"chats",title:c("sessions.sidebar.activity.chatsTitle"),items:qe},{key:"active-now",title:c("sessions.sidebar.activity.recentTitle"),items:We}]},[Zl,Fs,Qe,Ue,ye,ma,Jl,Pn,c]),ha=l.useMemo(()=>Qo.some(R=>R.key==="chats"||R.items.length>0),[Qo]),ec=Ue&&qo,pa=xs(R=>R.sessionGroupingMode),tc=pa==="by-worktree"&&!Ue,jm=l.useMemo(()=>{const R=tc?Ql:Yo;return ec?R:R.map(We=>We.groups.some(qe=>qe.isArchivedBucket)?{...We,groups:We.groups.filter(qe=>!qe.isArchivedBucket)}:We)},[Yo,Ql,ec,tc]),km=l.useMemo(()=>sn?On&&Ns.some(R=>R.project.id===On)?On:$&&Ns.some(R=>R.project.id===$)?$:Ns[0]?.project.id??null:null,[$,sn,Ns,On]),Cm=l.useCallback(R=>{po(R)},[po]),sc=l.useRef(new Set);l.useEffect(()=>{if(!t||!Sr||!Wr?.connected||!ho)return;const R=new Map,We=Date.now();Ns.forEach(qe=>{N.has(qe.project.id)||qe.groups.forEach(dt=>{if(dt.isArchivedBucket||dt.isMain)return;const Ct=jt(dt.directory??null),Ot=dt.branch?.trim()||Bt.get(Ct||"")?.trim();if(!Ct||!Ot)return;const Ps=Qi(Ct,Ot),Ss=on.getState().entries[Ps],Fn=Ss?.status?.pr?.state,vn=Fn==="closed"||Fn==="merged",Kr=!!Ss?.status?.pr&&!vn,lr=`${Ct}::${Ot}`,Xo=Math.max(Ss?.lastRefreshAt??0,Ss?.lastDiscoveryPollAt??0),wn=!!(Ss?.isInitialStatusResolved&&!Kr&&(!sc.current.has(lr)||We-Xo>=L2));(!Ss||!Ss.isInitialStatusResolved||wn)&&(wn&&sc.current.add(lr),R.has(Ps)||R.set(Ps,{directory:Ct,branch:Ot}))})}),R.size!==0&&(R.forEach((qe,dt)=>{Ko(dt),Go(dt,{directory:qe.directory,branch:qe.branch,remoteName:null,canShow:!0,github:ho,githubAuthChecked:Sr,githubConnected:Wr.connected})}),O([...R.values()],{silent:!0,markInitialResolved:!0}))},[N,Ko,ho,Sr,Wr?.connected,t,Bt,Ns,O,Go]);const Nm=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",Am="h-4.5 w-4.5",Dm=O0({enabled:t&&go,isDesktopShellRuntime:As,projectSections:Ns,projectHeaderSentinelRefs:oe}),Nr=Cn((R,We=0,qe,dt,Ct=!1,Ot,Ps="project",Ss)=>s.jsx(j2,{node:R,depth:We,groupDirectory:qe,projectId:dt,archivedBucket:Ct,pinnedSessionIds:ge,expandedParents:Ps==="recent"?Cr:kr,hasSessionSearchQuery:Qe,normalizedSessionSearchQuery:ye,notifyOnSubtasks:ne,editingId:b,setEditingId:k,editTitle:v,setEditTitle:g,handleSaveEdit:ia,handleCancelEdit:aa,toggleParent:ds,handleSessionSelect:bn,handleSessionDoubleClick:oa,togglePinnedSession:pe,handleShareSession:zo,copiedSessionId:Gn,handleCopyShareUrl:Uo,handleCopySessionId:$r,handleUnshareSession:zr,openSidebarMenuKey:W,setOpenSidebarMenuKey:K,renamingFolderId:x,getFoldersForScope:Le,getSessionFolderId:bt,removeSessionFromFolder:et,addSessionToFolder:It,createFolderAndStartRename:uo,openContextPanelTab:_e,handleDeleteSession:co,handleRestoreSession:la,mobileVariant:e,alwaysShowActions:Os,renderSessionNode:Nr,secondaryMeta:Ot,renderContext:Ps,subtreeContainsEditing:Ss?.subtreeContainsEditing??_2,menuOpenSessionId:Ss?.menuOpenSessionId??null,nodeStructureKey:Ss?.nodeStructureKey??"",childRenderExtrasFor:Ss?.childRenderExtrasFor})),Pm=l.useMemo(()=>{const R=new Map;return Yo.forEach(We=>{const qe=We.groups.find(dt=>!dt.isArchivedBucket);qe?.folderScopes&&qe.folderScopes.length>0&&R.set(We.project.id,qe.folderScopes)}),R},[Yo]),Em=l.useCallback((R,We)=>{const qe=[];return We.forEach(dt=>{dt.isArchivedBucket||(qe.push(dt.directory),dt.folderScopes?.forEach(Ct=>qe.push(Ct.directory)))}),s.jsx(z2,{directories:qe})},[]),nc=l.useCallback(R=>{Ur(R),Oe(We=>{const qe=new Set(We);return qe.has(R)?qe.delete(R):qe.add(R),qe})},[Ur]),ga=l.useCallback((R,We,qe,dt,Ct,Ot,Ps)=>s.jsx(uj,{group:R,groupKey:We,projectId:qe,hideGroupLabel:dt,dragHandleProps:Ct,compactBodyPadding:Ot,hasSessionSearchQuery:Qe,normalizedSessionSearchQuery:ye,groupSearchDataByGroup:Yl,visibleSessionCount:P.get(We),sessionBatchSize:sn&&pa==="flat"&&R.id!=="managed-chats"?20:void 0,collapsedGroups:Ie,hideDirectoryControls:o,collapsedFolderIds:$e,toggleFolderCollapse:kt,renameFolder:ct,deleteFolder:Pt,showDeletionDialog:ke,setDeleteFolderConfirm:le,renderSessionNode:Nr,showMoreGroupSessions:fo,resetGroupSessionLimit:Ur,mobileVariant:e,alwaysShowActions:Os,activeProjectId:$,setActiveProjectIdOnly:Y,setActiveMainTab:Ge,setSessionSwitcherOpen:T,openNewSessionDraft:He,addSessionToFolder:It,createFolderAndStartRename:uo,renamingFolderId:x,renameFolderDraft:z,setRenameFolderDraft:U,setRenamingFolderId:M,pinnedSessionIds:ge,expandedParents:kr,sessionOrderIndex:tn,editingId:b,editTitle:v,openSidebarMenuKey:W,activeActivitySessionIds:ae,unreadActivitySessionIds:me,notifyOnSubtasks:ne,onToggleCollapsedGroup:nc,scrollContainerRef:Ps}),[Qe,ye,Yl,P,sn,pa,Ie,o,$e,kt,ct,Pt,ke,Nr,fo,Ur,e,Os,$,Y,Ge,T,He,It,uo,x,z,ge,kr,tn,b,v,W,ae,me,ne,nc]),xa=l.useCallback(()=>{he.getState().closeMainSurfaces(),Ge("chat"),e&&T(!1),Je()},[e,Je,Ge,T]),rc=l.useCallback(R=>{const We=Up(J)??R.map(Ot=>Ju(Ot.node.session.directory)).find(Boolean)??null;if(!We)return R.map(Ot=>Nr(Ot.node,0,Ot.groupDirectory));const qe=[We,...R.map(Ot=>jt(Ot.node.session.directory??null)).filter(Ot=>!!Ot)],dt=Array.from(new Set(qe)).map(Ot=>({scopeKey:Ot,directory:Ot})),Ct={id:"managed-chats",label:"",branch:null,description:null,isMain:!0,worktree:null,directory:We,folderScopeKey:We,folderScopes:dt,draftTarget:"chat",emptyMessage:c("sessions.sidebar.activity.chatsEmpty"),sessions:R.map(Ot=>Ot.node)};return ga(Ct,"managed-chats",null,!0)},[J,ga,Nr,c]),Tm=l.useMemo(()=>!Ue&&!Qe&&ha?s.jsx(Cj,{sections:Qo,renderSessionNode:Nr,editingId:b,openSidebarMenuKey:W,expansionState:Cr,variant:"section",isDesktopShellRuntime:As,onNewChat:xa,alwaysShowActions:Os,renderChatsSection:rc}):null,[Qo,Os,b,xa,ha,Qe,As,Ue,W,Cr,rc,Nr]),oc=!!(x||b||h),{selectionModeEnabled:ic,hasSelection:Im,selectedIdsSize:Mm,bulkScopeIsArchived:Rm,derivedSelectionScope:Om,bulkScopeFolders:Fm,bulkCanRemoveFromFolder:Bm,handleToggleSelectionMode:Lm,handleExitSelectionMode:_m,handleBulkMoveToFolder:$m,handleBulkCreateFolderAndMove:zm,handleBulkRemoveFromFolder:Um,handleBulkDelete:Wm,handleBulkRestore:Vm,confirmBulkDelete:Hm}=P2({isInlineEditing:oc,showDeletionDialog:ke,foldersMap:ze,folderScopesByProject:Pm,addSessionsToFolder:Tt,removeSessionsFromFolders:Mt,createFolderAndStartRename:ps,archiveSessions:Hs,unarchiveSessions:Dn,deleteSessions:Qt,setBulkDeleteConfirm:fe}),Km=l.useCallback(()=>{Ge("chat"),e&&T(!1),Ae()},[e,Ae,Ge,T]);return s.jsx(Ya,{delay:0,closeDelay:150,timeout:600,children:s.jsxs("div",{ref:f,className:xe("relative flex h-full flex-col text-foreground overflow-x-hidden",e?"":"bg-transparent"),children:[s.jsx($2,{owner:pt,childStores:Rt,projectSections:Ns,activeProjectId:$,collapsedProjects:N,collapsedGroups:Ie,currentDirectory:re}),s.jsx(i0,{projectSections:Ns,activeProjectId:$,initialActiveSessionByProject:je,persistActiveSessionByProject:Ne,handleSessionSelect:bn,mobileVariant:e,openNewSessionDraft:Je,setActiveMainTab:Ge,setSessionSwitcherOpen:T,sessionOwnerBySessionId:ot.bySessionId}),s.jsx(QS,{enabled:t,sortedSessions:js,recentSessions:ma,prefetchSession:wt.prefetchSession}),!o&&!Ue?s.jsx(kj,{onNewSession:xa}):null,s.jsx(fj,{hideDirectoryControls:o,showProjectDisplayControls:yn,showRecentControls:!Ue,handleOpenDirectoryDialog:vr,onOpenScheduled:()=>{e&&T(!1),ce(!0)},onOpenMultiRun:Km,canOpenMultiRun:ee.length>0,onOpenArchive:()=>{e&&T(!1),ve(!0)},headerActionIconClass:Am,headerActionButtonClass:Nm,isSessionSearchOpen:a,setIsSessionSearchOpen:d,sessionSearchInputRef:p,sessionSearchQuery:u,setSessionSearchQuery:m,hasSessionSearchQuery:Qe,searchMatchCount:vm,collapseAllProjects:ca,expandAllProjects:wr,selectionModeEnabled:ic,onToggleSelectionMode:Lm}),t?s.jsx(Lj,{topContent:Tm,hasSharedSessions:ha,sectionsForRender:jm,projectSections:Ns,projectPickerSections:Ns,activeProjectId:$,singleProjectMode:sn,singleProjectId:km,setSingleProjectId:Cm,showOnlyMainWorkspace:i,hasSessionSearchQuery:Qe,emptyState:Ye,searchEmptyState:wm,renderGroupSessions:ga,homeDirectory:J,collapsedProjects:N,hideDirectoryControls:o,projectRepoStatus:A,isDesktopShellRuntime:As,stickyZoneHeaders:go,stuckProjectHeaders:Dm,mobileVariant:e,alwaysShowActions:Os,toggleProject:da,setActiveProjectIdOnly:Y,setActiveMainTab:Ge,setSessionSwitcherOpen:T,openNewSessionDraft:He,openNewWorktreeDialog:_t,openWorktreesPage:R=>{e&&T(!1),Ce(R)},openProjectEditDialog:S,removeProject:de,projectHeaderSentinelRefs:oe,reorderProjects:Te,projectSortOrder:Vr,getOrderedGroups:Sm,setGroupOrderByProject:Fe,renderProjectStatusIndicator:Em,openSidebarMenuKey:W,setOpenSidebarMenuKey:K,isInlineEditing:oc}):null,ic&&Im?s.jsx(D2,{selectedCount:Mm,scopeKey:Om,scopeFolders:Fm,archivedBucket:Rm,onMoveToFolder:$m,onCreateFolderAndMove:zm,onRemoveFromFolder:Um,canRemoveFromFolder:Bm,onRestore:Vm,onDelete:Wm,onDone:_m}):null,s.jsx(Nj,{onOpenSettings:vt,onOpenShortcuts:Re,onOpenAbout:()=>be(!0),onOpenUpdate:Et,showRuntimeButtons:!Ue,showUpdateButton:fs}),s.jsx(af,{open:_,onOpenChange:L,info:rt.info,downloading:rt.downloading,downloaded:rt.downloaded,progress:rt.progress,error:rt.error,onDownload:rt.downloadUpdate,onRestart:rt.restartToUpdate,runtimeType:rt.runtimeType}),s.jsx(L0,{open:!!at,onOpenChange:R=>{R||S(null)},project:at,onSave:ut}),s.jsx(Jg,{open:F,onOpenChange:E,onWorktreeCreated:(R,We)=>{if(Ge("chat"),e&&T(!1),We?.sessionId){ys(We.sessionId,R);return}Je({directoryOverride:R,preserveDirectoryOverride:!0})}}),s.jsx(C2,{value:V,setValue:Z,showDeletionDialog:ke,setShowDeletionDialog:Ze,onConfirm:Ds}),s.jsx(A2,{value:X,setValue:le,onConfirm:Ks}),s.jsx(N2,{value:te,setValue:fe,showDeletionDialog:ke,setShowDeletionDialog:Ze,onConfirm:Hm})]})})},Ud=l.memo(U2);function W2(t){return t.currentSessionDirectory}const Dr=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,En=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},V2=()=>{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,p]=l.useState(!1),[b,k]=l.useState(!1),[v,g]=l.useState(!1),[h,S]=l.useState(new Set),y=nt(oe=>oe.getWorktreeMetadata),j=nt(oe=>oe.newSessionDraft),C=nt(oe=>oe.setNewSessionDraftTarget),N=nt(oe=>oe.setDraftBootstrapPendingDirectory),w=Kp,A=qp,D=nt(oe=>oe.deleteSessions),P=nt(oe=>oe.archiveSessions),B=he(oe=>oe.showDeletionDialog),F=he(oe=>oe.setShowDeletionDialog),E=as(oe=>oe.currentDirectory),_=as(oe=>oe.homeDirectory),L=as(oe=>oe.isHomeReady),W=Jt(oe=>oe.projects),K=Jt(oe=>oe.activeProjectId),{isMobile:x,isTablet:M,hasTouchInput:z}=br(),U=x||M||z,V=l.useMemo(()=>{const Ee=(K?W.find(J=>J.id===K)??null:null)?.path??E;return En(Ee)},[K,E,W]),Z=l.useCallback(oe=>{const J=En(oe.projectDirectory)||V;return{id:(W.find(ee=>En(ee.path)===J)??null)?.id??`path:${J}`,path:J}},[V,W]),X=v&&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:Ee})=>typeof Ee.branch=="string"&&Ee.branch.trim().length>0)},[i?.worktree,a]),te=i?.mode==="worktree",fe=te,ge=b||!te||!le,H=b||!te;l.useEffect(()=>{r||!L||W.length>0||(o(!0),n(!0))},[r,L,W.length]);const Se=l.useCallback(oe=>{c({sessions:oe.sessions,dateLabel:oe.dateLabel,mode:oe.mode??"session",worktree:oe.worktree??null})},[]),ae=l.useCallback(()=>{c(null),d([]),m(!1),p(!1),k(!1),g(!1),S(new Set)},[]),q=l.useCallback(async oe=>{if(oe.sessions.length===0)return;if(oe.sessions.length===1){const ee=oe.sessions[0];await w(ee.id)?De.success(t("sessions.sidebar.session.delete.success")):De.error(t("sessions.sidebar.session.delete.error"));return}const Ee=oe.sessions.map(ee=>ee.id),{deletedIds:J,failedIds:re}=await D(Ee);if(J.length>0){const ee=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;De.success(J.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:J.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:J.length}),{description:Dr(ee)})}re.length>0&&De.error(re.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:re.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:re.length}),{description:Dr(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[w,D,t]);l.useEffect(()=>Un.onDeleteRequest(oe=>{if(!B&&(oe.mode??"session")==="session"){q(oe);return}Se(oe)}),[Se,B,q]),l.useEffect(()=>Un.onDirectoryRequest(()=>{n(!0)}),[]),l.useEffect(()=>{if(!i){d([]),m(!1),p(!1),g(!1),S(new Set);return}const oe=i.sessions.map(re=>{const ee=y(re.id);return ee?{session:re,metadata:ee}:null}).filter(re=>!!re);d(oe),m(!1),g(!1),S(new Set);const Ee=new Map;if(i.worktree?.path&&Ee.set(En(i.worktree.path),i.worktree),oe.forEach(({metadata:re})=>{re.path&&Ee.set(En(re.path),re)}),Ee.size===0){g(!0);return}let J=!1;return(async()=>{const re=new Map,ee=new Set;await Promise.all(Array.from(Ee.entries()).map(async([$,de])=>{try{const Y=await Gp(de.path);re.set($,Y),Y?.isDirty&&ee.add($)}catch{de.status&&(re.set($,de.status),de.status.isDirty&&ee.add($))}})).catch($=>{console.warn("Failed to inspect worktree status before deletion:",$)}),!J&&(S(ee),g(!0),c($=>{if(!$?.worktree?.path)return $;const de=En($.worktree.path),Y=re.get(de);if(!Y)return $;const ue=$.worktree.status;return ue?.isDirty===Y.isDirty&&ue?.ahead===Y.ahead&&ue?.behind===Y.behind&&ue?.upstream===Y.upstream?$:{...$,worktree:{...$.worktree,status:Y}}}),d($=>$.map(de=>{const Y=En(de.metadata.path),ue=re.get(Y);return ue?{session:de.session,metadata:{...de.metadata,status:ue}}:de})))})(),()=>{J=!0}},[i,y]),l.useEffect(()=>{le||m(!1)},[le]);const me=l.useCallback(async(oe,Ee)=>{const J=u&&le,re=Z(oe),ee=En(oe.path),$=En(re.path);try{await Cu(re,oe,{deleteRemoteBranch:J,deleteLocalBranch:Ee});const de=En(j?.directoryOverride);return j?.open&&ee&&de===ee&&$&&(N(null),C({projectId:re.id,directoryOverride:$},{force:!0})),En(E)===ee&&$&&as.getState().setDirectory($,{showOverlay:!1}),!0}catch(de){return De.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:Dr(de instanceof Error?de.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[le,E,u,Z,j?.directoryOverride,j?.open,N,C,t]),pe=l.useCallback((oe,Ee)=>{const J=u&&le;(async()=>{if(!await me(oe,Ee))return;const ee=t(J?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");De.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:Dr(ee)})})()},[le,u,me,t]),Ie=l.useCallback(async()=>{if(i){k(!0);try{const oe=fe,Ee=oe&&u,J=oe&&f;if(i.sessions.length===0&&te&&i.worktree){pe(i.worktree,J),ae();return}if(i.sessions.length===1){const re=i.sessions[0];if(!(te?await A(re.id):await w(re.id))){De.error(t(te?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),k(!1);return}const $=!te&&oe?t(Ee?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;De.success(t(te?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:Dr($),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const re=i.sessions.map(de=>de.id);let ee=[],$=[];if(te){const de=await P(re);ee=de.archivedIds,$=de.failedIds}else{const de=await D(re);ee=de.deletedIds,$=de.failedIds}if(te&&i.worktree&&$.length===0&&pe(i.worktree,J),ee.length>0){const de=!te&&oe?t(Ee?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,ue=[$.length>0?te?$.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:$.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:$.length}):$.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:$.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:$.length}):i.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:i.dateLabel}):void 0,de].filter(Boolean).join(" ");De.success(te?ee.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:ee.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:ee.length}):ee.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:ee.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:ee.length}),{description:Dr(ue||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if($.length>0&&(De.error(te?$.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:$.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:$.length}):$.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:$.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:$.length}),{description:Dr(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),ee.length===0)){k(!1);return}}te&&i.sessions.length===1&&i.worktree&&pe(i.worktree,J),ae()}finally{k(!1)}}},[i,u,f,w,D,A,P,ae,fe,te,pe,t]),Oe=i?.worktree??a[0]?.metadata??null,Me=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}):"",Fe=i?s.jsxs("div",{className:xe(te?"space-y-3":"space-y-2"),children:[i.sessions.length>0&&s.jsxs("div",{className:xe(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:xe(te?"mt-2 space-y-1":"space-y-0.5"),children:[i.sessions.slice(0,5).map(oe=>s.jsxs("li",{className:xe(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:xe(!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:xe(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(I,{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")}),Oe?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:Oe.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:Oe?Io(Oe.path,_):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),X&&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,je=te?le?s.jsxs("button",{type:"button",onClick:()=>{ge||m(oe=>!oe)},disabled:ge,className:xe("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",ge?"cursor-not-allowed opacity-60":"hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"),children:[u?s.jsx(I,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(I,{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,Ne=te?s.jsxs("button",{type:"button",onClick:()=>{H||p(oe=>!oe)},disabled:H,className:xe("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(I,{name:"checkbox",className:"size-4 text-primary"}):s.jsx(I,{name:"checkbox-blank",className:"size-4"}),t("sessions.sidebar.sessionDialogs.actions.deleteLocalBranch")]}):null,Pe=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:[Ne,je]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(lt,{variant:"ghost",onClick:ae,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(lt,{variant:"destructive",onClick:Ie,disabled:b,children:t(b?"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(!B),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":!B,children:[B?s.jsx(I,{name:"checkbox-blank",className:"size-4"}):s.jsx(I,{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:ae,disabled:b,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(lt,{variant:"destructive",onClick:Ie,disabled:b,children:b?t("sessions.sidebar.sessionDialogs.actions.deleting"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),se=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:[U?s.jsx(Xi,{open:!!i,onClose:()=>{b||ae()},title:se,footer:s.jsx("div",{className:"flex justify-end gap-2",children:Pe}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[Me&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:Me}),Fe]})}):s.jsx($s,{open:!!i,onOpenChange:oe=>{if(!oe){if(b)return;ae()}},children:s.jsxs(zs,{className:xe(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(An,{children:[s.jsxs(fn,{className:xe(te&&"flex items-center gap-2"),children:[te&&s.jsx(I,{name:"delete-bin",className:"h-5 w-5"}),se]}),Me&&s.jsx(mn,{children:Me})]}),s.jsx("div",{className:xe(te&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:Fe}),s.jsx(tr,{className:"mt-2 gap-2 pt-1 pb-1",children:Pe})]})}),s.jsx(Zg,{open:e,onOpenChange:n})]})};function um(t){if(!t||!t.trim())return{valid:!1,error:"required"};try{return vf.CronExpressionParser.parse(t),{valid:!0}}catch(e){return{valid:!1,error:e instanceof Error?e.message:"Invalid cron expression"}}}function H2(t,e,n=4){try{const r=e?{tz:e,currentDate:new Date}:{currentDate:new Date},o=vf.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 K2=[{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"}],G2={"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"},Mr=t=>G2[t]??t,fm=[0,1,2,3,4,5,6],Wd="flex h-6 w-6 cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0",gl=typeof Intl<"u"&&typeof Intl.supportedValuesOf=="function"?[...new Set(Intl.supportedValuesOf("timeZone").map(Mr))]:["UTC","Europe/Kyiv","Europe/London","Europe/Berlin","America/New_York","America/Los_Angeles","Asia/Tokyo"],Vd=()=>{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}`},Ni=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},Hd=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},q2=(t,e,n)=>{const r=Ni(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},Kd=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),Y2=(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 p=d+f;u.push({date:new Date(n,r-1,p),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},Q2=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}},Pr=(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")}`},lo=(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"},Gd=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:lo(t,{min:1,max:12}),mi=t=>/^[0-5][0-9]$/.test(t)?t:lo(t,{max:59}),X2=(t,e)=>lo(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),qd=(t,e)=>lo(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),J2=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}},Z2=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}},ek=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return fm.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},tk=(t,e)=>[...t.slice(e),...t.slice(0,e)],qs=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},Yd=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=Q2(n),e[0]=n,e[1]=m):m=e[1];const f=m,p=tt.useRef(null),b=tt.useRef(null),[k,v]=tt.useState(null),[g,h]=tt.useState(null),S=tt.useRef(null),y=tt.useRef(null);let j;e[2]===Symbol.for("react.memo_cache_sentinel")?(j=se=>{S.current=se,v(se)},e[2]=j):j=e[2];const C=j;let N;e[3]===Symbol.for("react.memo_cache_sentinel")?(N=se=>{y.current=se,h(se)},e[3]=N):N=e[3];const w=N,A=lk,D=ck,P=dk;let B;e[4]!==r||e[5]!==f.meridiem||e[6]!==f.minute||e[7]!==o?(B=se=>{const oe=se.replace(/\D/g,"").slice(0,2);C(oe),oe.length===2&&(r(o?P(A(oe),f.minute):Pr(Gd(oe),f.minute,f.meridiem)),C(null),b.current?.focus())},e[4]=r,e[5]=f.meridiem,e[6]=f.minute,e[7]=o,e[8]=B):B=e[8];const F=B;let E;e[9]!==r||e[10]!==f.meridiem||e[11]!==f.minute||e[12]!==o?(E=()=>{const se=S.current;if(se!==null&&(C(null),se.length!==0)){if(o){r(P(A(se.padStart(2,"0")),f.minute));return}r(Pr(Gd(se.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 _=E;let L;e[14]!==r||e[15]!==f.hour12||e[16]!==f.hour24||e[17]!==f.meridiem||e[18]!==o?(L=se=>{const oe=se.replace(/\D/g,"").slice(0,2);w(oe),oe.length===2&&(r(o?P(f.hour24,mi(oe)):Pr(f.hour12,mi(oe),f.meridiem)),w(null))},e[14]=r,e[15]=f.hour12,e[16]=f.hour24,e[17]=f.meridiem,e[18]=o,e[19]=L):L=e[19];const W=L;let K;e[20]!==r||e[21]!==f.hour12||e[22]!==f.hour24||e[23]!==f.meridiem||e[24]!==o?(K=()=>{const se=y.current;se!==null&&(w(null),se.length!==0&&r(o?P(f.hour24,mi(se.padStart(2,"0"))):Pr(f.hour12,mi(se.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]=K):K=e[25];const x=K;let M;e[26]!==r||e[27]!==f.hour12||e[28]!==f.hour24||e[29]!==f.meridiem||e[30]!==f.minute||e[31]!==o?(M=se=>r(o?P(D(f.hour24,se),f.minute):Pr(X2(f.hour12,se),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]=M):M=e[32];const z=M;let U;e[33]!==r||e[34]!==f.hour12||e[35]!==f.hour24||e[36]!==f.meridiem||e[37]!==f.minute||e[38]!==o?(U=se=>r(o?P(f.hour24,qd(f.minute,se)):Pr(f.hour12,qd(f.minute,se),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]=U):U=e[39];const V=U;let Z;e[40]!==r||e[41]!==f.hour12||e[42]!==f.meridiem||e[43]!==f.minute?(Z=se=>{se!==f.meridiem&&r(Pr(f.hour12,f.minute,se))},e[40]=r,e[41]=f.hour12,e[42]=f.meridiem,e[43]=f.minute,e[44]=Z):Z=e[44];const X=Z;let le;e[45]!==_||e[46]!==z?(le=se=>{if(se.key==="ArrowRight"){se.preventDefault(),_(),b.current?.focus();return}(se.key==="ArrowUp"||se.key==="ArrowDown")&&(se.preventDefault(),C(null),z(se.key==="ArrowUp"?1:-1))},e[45]=_,e[46]=z,e[47]=le):le=e[47];const te=le;let fe;e[48]!==x||e[49]!==V?(fe=se=>{if(se.key==="ArrowLeft"&&(se.currentTarget.selectionStart??0)===0){se.preventDefault(),x(),p.current?.focus();return}(se.key==="ArrowUp"||se.key==="ArrowDown")&&(se.preventDefault(),w(null),V(se.key==="ArrowUp"?1:-1))},e[48]=x,e[49]=V,e[50]=fe):fe=e[50];const ge=fe,H=o?"px-2":"pl-2 pr-1";let Se;e[51]!==H?(Se=xe("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]=Se):Se=e[52];const ae=k??(o?f.hour24:f.hour12);let q;e[53]!==F?(q=se=>F(se.target.value),e[53]=F,e[54]=q):q=e[54];let me;e[55]===Symbol.for("react.memo_cache_sentinel")?(me=()=>C(""),e[55]=me):me=e[55];let pe;e[56]!==_||e[57]!==i||e[58]!==te||e[59]!==ae||e[60]!==q?(pe=s.jsx("input",{ref:p,inputMode:"numeric",value:ae,onChange:q,onKeyDown:te,onFocus:me,onBlur:_,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]=_,e[57]=i,e[58]=te,e[59]=ae,e[60]=q,e[61]=pe):pe=e[61];let Ie;e[62]===Symbol.for("react.memo_cache_sentinel")?(Ie=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=Ie):Ie=e[62];const Oe=g??f.minute;let Me;e[63]!==W?(Me=se=>W(se.target.value),e[63]=W,e[64]=Me):Me=e[64];let Fe;e[65]===Symbol.for("react.memo_cache_sentinel")?(Fe=()=>w(""),e[65]=Fe):Fe=e[65];let je;e[66]!==x||e[67]!==c||e[68]!==ge||e[69]!==Oe||e[70]!==Me?(je=s.jsx("input",{ref:b,inputMode:"numeric",value:Oe,onChange:Me,onKeyDown:ge,onFocus:Fe,onBlur:x,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]=x,e[67]=c,e[68]=ge,e[69]=Oe,e[70]=Me,e[71]=je):je=e[71];let Ne;e[72]!==d||e[73]!==f.meridiem||e[74]!==a||e[75]!==u||e[76]!==X||e[77]!==o?(Ne=o?null:s.jsxs(Ys,{value:f.meridiem,onValueChange:se=>X(se),children:[s.jsx(Qs,{"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(Rs,{})}),s.jsxs(Xs,{children:[s.jsx(ls,{value:"AM",children:d}),s.jsx(ls,{value:"PM",children:u})]})]}),e[72]=d,e[73]=f.meridiem,e[74]=a,e[75]=u,e[76]=X,e[77]=o,e[78]=Ne):Ne=e[78];let Pe;return e[79]!==Se||e[80]!==pe||e[81]!==je||e[82]!==Ne?(Pe=s.jsxs("div",{className:Se,children:[pe,Ie,je,Ne]}),e[79]=Se,e[80]=pe,e[81]=je,e[82]=Ne,e[83]=Pe):Pe=e[83],Pe},Qd=t=>new Date(t.getFullYear(),t.getMonth(),1),sk=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},Xd=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),nk=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"]},Jd=(t,e)=>{const n=Mr(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:nk(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:Vd(),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:Mr(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:Vd(),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}}},rk=(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(!um(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")},ok=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))},ik=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()?um(c):null,e[0]=c,e[1]=a):a=e[1];const d=a;let u;e:{if(!d?.valid||!c.trim()){let M;e[2]===Symbol.for("react.memo_cache_sentinel")?(M=[],e[2]=M):M=e[2],u=M;break e}let x;e[3]!==c||e[4]!==n.schedule.timezone?(x=H2(c,n.schedule.timezone),e[3]=c,e[4]=n.schedule.timezone,e[5]=x):x=e[5],u=x}const m=u;let f;e[6]!==n.schedule.timezone||e[7]!==o?(f=x=>new Intl.DateTimeFormat(o,{timeZone:n.schedule.timezone,month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(x),e[6]=n.schedule.timezone,e[7]=o,e[8]=f):f=e[8];const p=f;let b;e[9]!==i?(b=i("sessions.scheduledTasks.editor.cronExpression.label"),e[9]=i,e[10]=b):b=e[10];let k;e[11]!==b?(k=s.jsx(qs,{htmlFor:"sched-cron",required:!0,children:b}),e[11]=b,e[12]=k):k=e[12];let v;e[13]!==r?(v=x=>r(M=>({...M,schedule:{...M.schedule,cronExpression:x.target.value}})),e[13]=r,e[14]=v):v=e[14];let g;e[15]!==i?(g=i("sessions.scheduledTasks.editor.cronExpression.placeholder"),e[15]=i,e[16]=g):g=e[16];let h;e[17]!==c||e[18]!==v||e[19]!==g?(h=s.jsx(er,{id:"sched-cron",value:c,onChange:v,placeholder:g,className:"w-full max-w-xs font-mono"}),e[17]=c,e[18]=v,e[19]=g,e[20]=h):h=e[20];let S;e[21]!==c||e[22]!==d||e[23]!==i?(S=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]=S):S=e[24];let y;e[25]!==k||e[26]!==h||e[27]!==S?(y=s.jsxs("div",{className:"flex flex-col gap-1",children:[k,h,S]}),e[25]=k,e[26]=h,e[27]=S,e[28]=y):y=e[28];let j;e[29]!==p||e[30]!==m||e[31]!==i?(j=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(p).join(", ")})]}):null,e[29]=p,e[30]=m,e[31]=i,e[32]=j):j=e[32];let C;e[33]!==i?(C=i("sessions.scheduledTasks.editor.cronExpression.examples"),e[33]=i,e[34]=C):C=e[34];let N;e[35]!==C?(N=s.jsx("span",{className:"typography-meta text-muted-foreground",children:C}),e[35]=C,e[36]=N):N=e[36];let w;e[37]!==r||e[38]!==i?(w=K2.map(x=>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(M=>({...M,schedule:{...M.schedule,cronExpression:x.expression}})),children:[s.jsx("span",{className:"font-mono",children:x.expression}),s.jsx("span",{className:"text-muted-foreground",children:i(x.labelKey)})]},x.expression)),e[37]=r,e[38]=i,e[39]=w):w=e[39];let A;e[40]!==w?(A=s.jsx("div",{className:"flex flex-wrap gap-1.5",children:w}),e[40]=w,e[41]=A):A=e[41];let D;e[42]!==N||e[43]!==A?(D=s.jsxs("div",{className:"flex flex-col gap-1",children:[N,A]}),e[42]=N,e[43]=A,e[44]=D):D=e[44];let P;e[45]!==i?(P=i("sessions.scheduledTasks.editor.timezone.label"),e[45]=i,e[46]=P):P=e[46];let B;e[47]!==P?(B=s.jsx(qs,{children:P}),e[47]=P,e[48]=B):B=e[48];let F;e[49]!==r?(F=x=>{r(M=>({...M,schedule:{...M.schedule,timezone:x}}))},e[49]=r,e[50]=F):F=e[50];let E;e[51]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(Qs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Rs,{})}),e[51]=E):E=e[51];let _;e[52]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx(Xs,{children:gl.map(uk)}),e[52]=_):_=e[52];let L;e[53]!==n.schedule.timezone||e[54]!==F?(L=s.jsxs(Ys,{value:n.schedule.timezone,onValueChange:F,children:[E,_]}),e[53]=n.schedule.timezone,e[54]=F,e[55]=L):L=e[55];let W;e[56]!==B||e[57]!==L?(W=s.jsxs("div",{className:"flex flex-col gap-1",children:[B,L]}),e[56]=B,e[57]=L,e[58]=W):W=e[58];let K;return e[59]!==y||e[60]!==j||e[61]!==D||e[62]!==W?(K=s.jsxs("div",{className:"flex flex-col gap-3",children:[y,j,D,W]}),e[59]=y,e[60]=j,e[61]=D,e[62]=W,e[63]=K):K=e[63],K};function ak(t){const{open:e,task:n,onOpenChange:r,onSave:o}=t,{t:i,locale:c}=gt(),a=Yt(T=>T.loadProviders),d=Yt(T=>T.loadAgents),u=Yt(T=>T.providers),m=Yt(T=>T.currentProviderId),f=Yt(T=>T.currentModelId),p=Yt(T=>T.currentVariant||""),b=Yt(T=>T.currentAgentName||""),k=he(T=>T.timeFormatPreference),v=he(T=>T.weekStartPreference),g=he(T=>T.isMobile),[h,S]=tt.useState(()=>Jd(n,{providerID:m,modelID:f,variant:p,agent:b})),[y,j]=tt.useState(!1),[C,N]=tt.useState(!1),[w,A]=tt.useState(!1),[D,P]=tt.useState(""),[B,F]=tt.useState(!1),[E,_]=tt.useState(""),[L,W]=tt.useState(!1),[K,x]=tt.useState(""),[M,z]=tt.useState(()=>{const T=Ni(n?.schedule?.date||"")||new Date;return new Date(T.getFullYear(),T.getMonth(),1)}),U=tt.useRef(null),V=tt.useRef(null),Z=tt.useRef(null),X=tt.useRef(null),le=tt.useRef(null),te=tt.useMemo(()=>Z2(c),[c]),fe=tt.useMemo(()=>J2(c),[c]),ge=tt.useMemo(()=>k==="24h"?!0:k==="12h"?!1:te,[k,te]),H=tt.useMemo(()=>v==="sunday"?0:v==="monday"?1:fe,[v,fe]),Se=tt.useMemo(()=>{const T=ek(c);return tk(fm.map(ce=>({value:ce,label:T[ce]||""})),H)},[c,H]);tt.useEffect(()=>{e&&(a({source:"scheduledTaskEditor"}),d({source:"scheduledTaskEditor"}))},[e,a,d]),tt.useEffect(()=>{if(!e)return;S(Jd(n,{providerID:m,modelID:f,variant:p,agent:b}));const T=Ni(n?.schedule?.date||"")||new Date;z(new Date(T.getFullYear(),T.getMonth(),1)),N(!1),F(!1),A(!1),_(""),P("")},[e,n,m,f,p,b]),tt.useEffect(()=>{if(!C)return;const T=ce=>{U.current&&!U.current.contains(ce.target)&&N(!1)};return document.addEventListener("mousedown",T),()=>{document.removeEventListener("mousedown",T)}},[C]);const ae=tt.useMemo(()=>{const ce=u.find(ve=>ve.id===h.execution.providerID)?.models?.find(ve=>ve.id===h.execution.modelID);return ce?.variants?Object.keys(ce.variants):[]},[u,h.execution.providerID,h.execution.modelID]),q=ae.length>0,me=tt.useMemo(()=>!q||!h.execution.variant?"__default":ae.includes(h.execution.variant)?h.execution.variant:"__default",[h.execution.variant,q,ae]);tt.useEffect(()=>{q||!h.execution.variant||S(T=>({...T,execution:{...T.execution,variant:""}}))},[q,h.execution.variant]);const pe=tt.useCallback((T,ce)=>{S(ve=>{const Ce=new Set(ve.schedule.weekdays);return ce?Ce.add(T):Ce.delete(T),{...ve,schedule:{...ve.schedule,weekdays:Array.from(Ce).sort((Ae,ne)=>Ae-ne)}}})},[]),Ie=tt.useCallback((T,ce)=>{S(ve=>{const Ce=ve.schedule.times.slice();return Ce[T]=ce,{...ve,schedule:{...ve.schedule,times:Ce}}})},[]),Oe=tt.useCallback(T=>{S(ce=>{const ve=ce.schedule.times.filter((Ce,Ae)=>Ae!==T);return{...ce,schedule:{...ce.schedule,times:ve.length>0?ve:["09:00"]}}})},[]),Me=tt.useCallback(()=>{S(T=>({...T,schedule:{...T.schedule,times:[...T.schedule.times,"12:00"]}}))},[]),Fe=tt.useMemo(()=>sk(),[]),je=tt.useMemo(()=>Qd(Fe),[Fe]),Ne=tt.useMemo(()=>{const T=Ni(h.schedule.onceDate);return T?Xd(T,Fe)?i("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(c,{weekday:"short"}).format(T):null},[h.schedule.onceDate,c,i,Fe]),Pe=tt.useMemo(()=>Qd(M).getTime()<=je.getTime(),[M,je]),se=tt.useMemo(()=>Se.map(T=>T.label),[Se]),oe=tt.useCallback(T=>{S(ce=>({...ce,schedule:{...ce.schedule,onceDate:T}}))},[]),Ee=tt.useCallback((T,ce)=>{if(T.startsWith("/")){const ne=T.indexOf(" "),ke=T.indexOf(`
915
+ `),Ze=Math.min(ne===-1?T.length:ne,ke===-1?T.length:ke);if(ce<=Ze&&ne===-1){_(T.substring(1,Ze)),F(!0),A(!1),W(!1);return}}F(!1);const ve=T.substring(0,ce),Ce=ve.lastIndexOf("#");if(Ce!==-1){const ne=Ce>0?ve[Ce-1]:null,ke=ve.substring(Ce+1);if((!ne||/\s/.test(ne))&&!ke.includes(" ")&&!ke.includes(`
916
+ `)){x(ke),W(!0),A(!1);return}}W(!1);const Ae=ve.lastIndexOf("@");if(Ae!==-1){const ne=Ae>0?ve[Ae-1]:null,ke=ve.substring(Ae+1);(!ne||/\s/.test(ne))&&!ke.includes(" ")&&!ke.includes(`
917
+ `)?(P(ke),A(!0)):A(!1);return}A(!1)},[]),J=tt.useCallback(T=>{S(ce=>({...ce,execution:{...ce.execution,prompt:T}}))},[]),re=tt.useCallback(T=>{const ce=h.execution.prompt,Ce=V.current?.selectionStart??ce.length,ne=ce.substring(0,Ce).lastIndexOf("@"),ke=T.relativePath&&T.relativePath.trim().length>0?T.relativePath.trim():T.path||T.name,Ze=ne!==-1?ne:Ce,Q=`${ce.substring(0,Ze)}@${ke} ${ce.substring(Ce)}`,ye=Ze+ke.length+2;J(Q),A(!1),P(""),requestAnimationFrame(()=>{const Qe=V.current;Qe&&(Qe.selectionStart=ye,Qe.selectionEnd=ye,Qe.focus()),Ee(Q,ye)})},[h.execution.prompt,J,Ee]),ee=tt.useCallback(T=>{const ce=h.execution.prompt,Ce=V.current?.selectionStart??ce.length,ne=ce.substring(0,Ce).lastIndexOf("@"),ke=ne!==-1?ne:Ce,Ze=`${ce.substring(0,ke)}@${T} ${ce.substring(Ce)}`,Q=ke+T.length+2;J(Ze),A(!1),P(""),requestAnimationFrame(()=>{const ye=V.current;ye&&(ye.selectionStart=Q,ye.selectionEnd=Q,ye.focus()),Ee(Ze,Q)})},[h.execution.prompt,J,Ee]),$=tt.useCallback(T=>{const ce=`/${T.name} `;J(ce),F(!1),_(""),W(!1),requestAnimationFrame(()=>{const ve=V.current;ve&&(ve.focus(),ve.selectionStart=ve.value.length,ve.selectionEnd=ve.value.length),Ee(ce,ce.length)})},[J,Ee]),de=tt.useCallback((T,ce)=>{const ve=h.execution.prompt,Ae=V.current?.selectionStart??ve.length,ke=ve.substring(0,Ae).lastIndexOf("#"),Ze=ke!==-1?ke:Ae,Q=`${ve.substring(0,Ze)}#${ce} ${ve.substring(Ae)}`,ye=Ze+ce.length+2;J(Q),W(!1),x(""),requestAnimationFrame(()=>{const Qe=V.current;Qe&&(Qe.selectionStart=ye,Qe.selectionEnd=ye,Qe.focus()),Ee(Q,ye)})},[h.execution.prompt,J,Ee]),Y=tt.useCallback(T=>{if(B&&X.current&&(T.key==="Enter"||T.key==="ArrowUp"||T.key==="ArrowDown"||T.key==="Escape"||T.key==="Tab")){T.preventDefault(),X.current.handleKeyDown(T.key);return}w&&Z.current&&(T.key==="Enter"||T.key==="ArrowUp"||T.key==="ArrowDown"||T.key==="Escape"||T.key==="Tab")&&(T.preventDefault(),Z.current.handleKeyDown(T.key)),L&&le.current&&(T.key==="Enter"||T.key==="ArrowUp"||T.key==="ArrowDown"||T.key==="Escape"||T.key==="Tab")&&(T.preventDefault(),le.current.handleKeyDown(T.key))},[B,w,L]),ue=tt.useCallback(async()=>{const T=rk(h,i);if(T){De.error(T);return}const ce={...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:ok(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}:{}};j(!0);try{await o(ce),r(!1)}catch(ve){De.error(ve instanceof Error?ve.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{j(!1)}},[h,r,o,i]),Te=tt.useId(),Ge=tt.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(qs,{htmlFor:"sched-name",required:!0,children:i("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(er,{id:"sched-name",value:h.name,onChange:T=>S(ce=>({...ce,name:T.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(qs,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(Ys,{value:h.schedule.kind,onValueChange:T=>{S(ce=>({...ce,schedule:{...ce.schedule,kind:T,...T==="cron"&&!ce.schedule.cronExpression?{cronExpression:"0 * * * *"}:{}}}))},children:[s.jsx(Qs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Rs,{children:T=>i(T==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":T==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":T==="cron"?"sessions.scheduledTasks.editor.scheduleType.cron":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(Xs,{children:[s.jsx(ls,{value:"daily",children:i("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(ls,{value:"weekly",children:i("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(ls,{value:"once",children:i("sessions.scheduledTasks.editor.scheduleType.once")}),s.jsx(ls,{value:"cron",children:i("sessions.scheduledTasks.editor.scheduleType.cron")})]})]})]})]}),h.schedule.kind==="cron"?s.jsx(ik,{draft:h,setDraft:S,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:U,children:[s.jsx(qs,{children:i("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:xe(qu({size:"default"}),"w-fit max-w-full"),onClick:()=>N(T=>!T),children:[s.jsxs("span",{className:"inline-flex items-center gap-2",children:[s.jsx(I,{name:"calendar",className:"h-4 w-4 text-muted-foreground"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:q2(h.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),c)})]}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),C?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:()=>z(T=>Kd(T,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:Pe,children:s.jsx(I,{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(M)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>z(T=>Kd(T,1)),"aria-label":i("sessions.scheduledTasks.editor.date.nextMonth"),children:s.jsx(I,{name:"arrow-right-s",className:"h-4 w-4"})})]}),s.jsx("div",{className:"mb-1 grid grid-cols-7 gap-1 px-1",children:se.map((T,ce)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:T},`${T}-${ce}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:Y2(M,H).map(({date:T,inCurrentMonth:ce})=>{const ve=Hd(T),Ce=ve===h.schedule.onceDate,Ae=Xd(T,Fe),ne=T.getTime()<Fe.getTime(),ke=Ce?"bg-interactive-selection text-interactive-selection-foreground":ne?"text-muted-foreground/40":ce?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{ne||(oe(ve),N(!1))},disabled:ne,className:["h-8 rounded-md typography-ui-label",ke,Ae&&!Ce?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",ne?"cursor-not-allowed opacity-45":""].join(" "),children:T.getDate()},ve)})}),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:Ne||""}),s.jsx(lt,{type:"button",size:"xs",variant:"ghost",onClick:()=>{oe(Hd(Fe)),z(new Date(Fe.getFullYear(),Fe.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(qs,{children:i("sessions.scheduledTasks.editor.time.label")}),s.jsx(Yd,{value:h.schedule.onceTime,use24Hour:ge,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:T=>S(ce=>({...ce,schedule:{...ce.schedule,onceTime:T}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(qs,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Ys,{value:h.schedule.timezone,onValueChange:T=>{S(ce=>({...ce,schedule:{...ce.schedule,timezone:T}}))},children:[s.jsx(Qs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Rs,{})}),s.jsx(Xs,{children:gl.map(T=>s.jsx(ls,{value:T,children:T},T))})]})]})]})]}):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(qs,{children:i("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:Se.map(T=>{const ce=h.schedule.weekdays.includes(T.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",ce?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(Zr,{checked:ce,onChange:ve=>pe(T.value,ve),ariaLabel:T.label}),s.jsx("button",{type:"button",onClick:()=>pe(T.value,!ce),className:"group-hover:text-foreground",children:T.label})]},T.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(qs,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:h.schedule.times.map((T,ce)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Yd,{value:T,use24Hour:ge,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:ve=>Ie(ce,ve)}),h.schedule.times.length>1?s.jsx(lt,{type:"button",size:"icon",variant:"ghost",onClick:()=>Oe(ce),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null]},ce))}),s.jsx("div",{children:s.jsxs(lt,{type:"button",size:"sm",variant:"outline",onClick:Me,children:[s.jsx(I,{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(qs,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(Ys,{value:h.schedule.timezone,onValueChange:T=>{S(ce=>({...ce,schedule:{...ce.schedule,timezone:T}}))},children:[s.jsx(Qs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Rs,{})}),s.jsx(Xs,{children:gl.map(T=>s.jsx(ls,{value:T,children:T},T))})]})]})]}),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(qs,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(Yp,{providerId:h.execution.providerID,modelId:h.execution.modelID,onChange:(T,ce)=>{S(ve=>({...ve,execution:{...ve.execution,providerID:T,modelID:ce,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(qs,{children:i("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(Ys,{value:me,disabled:!q,onValueChange:T=>{S(ce=>({...ce,execution:{...ce.execution,variant:T==="__default"?"":T}}))},children:[s.jsx(Qs,{size:"lg",className:"w-fit max-w-full",children:s.jsx(Rs,{children:T=>T==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):T})}),s.jsxs(Xs,{children:[s.jsx(ls,{value:"__default",children:i("sessions.scheduledTasks.editor.thinkingLevel.default")}),ae.map(T=>s.jsx(ls,{value:T,children:T},T))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(qs,{children:i("sessions.scheduledTasks.editor.agent.label")}),s.jsx(Qp,{agentName:h.execution.agent,filter:T=>Gu(T.mode),onChange:T=>S(ce=>({...ce,execution:{...ce.execution,agent:T}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(qs,{htmlFor:"sched-prompt",required:!0,children:i("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(Xr,{id:"sched-prompt",ref:V,value:h.execution.prompt,onChange:T=>{const ce=T.target.value;J(ce);const ve=T.target.selectionStart??ce.length;Ee(ce,ve)},onKeyDown:Y,rows:8,placeholder:i("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),B?s.jsx(ef,{ref:X,searchQuery:E,onCommandSelect:$,onClose:()=>F(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,w?s.jsx(tf,{ref:Z,searchQuery:D,onFileSelect:re,onAgentSelect:ee,onClose:()=>A(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,L?s.jsx(sf,{ref:le,searchQuery:K,onSnippetSelect:de,onClose:()=>W(!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(Zr,{checked:h.execution.goalTokenBudget!==null,onChange:T=>S(ce=>({...ce,execution:{...ce.execution,goalTokenBudget:T?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(Xp,{value:h.execution.goalTokenBudget,onValueChange:T=>{typeof T=="number"&&Number.isFinite(T)&&T>0&&S(ce=>({...ce,execution:{...ce.execution,goalTokenBudget:Math.floor(T)}}))},min:1e3,max:1e8,step:5e4}):null]}):null]}),be=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(Zr,{checked:h.enabled,onChange:T=>S(ce=>({...ce,enabled:T})),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:xe(Wd),onClick:()=>S(T=>({...T,execution:{...T.execution,permissionAutoAccept:!T.execution.permissionAutoAccept}})),"aria-pressed":h.execution.permissionAutoAccept,"aria-label":i("sessions.scheduledTasks.editor.permissionAutoAccept.aria"),children:h.execution.permissionAutoAccept?s.jsx(I,{name:"shield-check",className:"h-[18px] w-[18px]",style:{color:"var(--status-info)"},"aria-hidden":"true"}):s.jsx(I,{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:xe(Wd,h.execution.goalEnabled&&"text-[var(--status-info)]"),onClick:()=>S(T=>({...T,execution:{...T.execution,goalEnabled:!T.execution.goalEnabled}})),"aria-pressed":h.execution.goalEnabled,"aria-label":i("sessions.scheduledTasks.editor.goal.aria"),children:h.execution.goalEnabled?s.jsx(I,{name:"target-fill",className:"h-[18px] w-[18px] text-current","aria-hidden":"true"}):s.jsx(I,{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:y,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(lt,{type:"button",size:"sm",onClick:ue,disabled:y,children:i(y?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return g?s.jsx(Xi,{open:e,title:_e,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:T=>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}),T]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:ie})]}),footer:be,children:Re}):s.jsx($s,{open:e,onOpenChange:T=>{!T&&Ge()||r(T)},children:s.jsxs(zs,{"aria-describedby":Te,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(mn,{id:Te,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(fn,{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(jl,{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:be})})]})})}function lk(t){return lo(t,{min:0,max:23})}function ck(t,e){return lo(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function dk(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 uk(t){return s.jsx(ls,{value:t,children:t},t)}const fk=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))},mk=(t,e)=>{const n=fk(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:Mr(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:Mr(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:Mr(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:Mr(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.cron",{cron:t.schedule.cron||""})},hk=(t,e)=>!t||!Number.isFinite(t)?"":Mu(t,e),Zd=(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),p=Math.round(r%i/o),b=p>0?`${f}h ${p}m`:`${f}h`;return a?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:b}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:b})}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})},pk={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"}},gk=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function eu(){const{t}=gt(),e=he(x=>x.isScheduledTasksDialogOpen),n=he(x=>x.setScheduledTasksDialogOpen),r=he(x=>x.isMobile),o=he(x=>x.timeFormatPreference),i=Jt(x=>x.projects),c=Jt(x=>x.getActiveProject()),a=as(x=>x.homeDirectory),{currentTheme:d}=Br(),[u,m]=tt.useState(""),[f,p]=tt.useState([]),[b,k]=tt.useState(!0),[v,g]=tt.useState(!1),[h,S]=tt.useState(null),[y,j]=tt.useState(null),C=tt.useMemo(()=>i.find(x=>x.id===u)||null,[i,u]),N=tt.useCallback(x=>{const M=x.label?.trim()||xr(x.path,a||void 0),z=x.icon?Al[x.icon]:null,U=x.color?Dl[x.color]:void 0,V=z?s.jsx(I,{name:z,className:"h-3.5 w-3.5 shrink-0",style:U?{color:U}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:U?{color:U}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[x.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:x.iconBackground?{backgroundColor:x.iconBackground}:void 0,children:s.jsx(Pl,{project:{id:x.id,iconImage:x.iconImage??null},options:{themeVariant:d.metadata.variant,iconColor:d.colors.surface.foreground},className:"h-full w-full object-contain",fallback:V})}):V,s.jsx("span",{className:"truncate",children:M})]})},[a,d.metadata.variant,d.colors.surface.foreground]),w=tt.useCallback(async(x,M)=>{if(!x){p([]);return}M?.silent||k(!0);try{const z=await mx(x);z.sort((U,V)=>{if(U.enabled!==V.enabled)return U.enabled?-1:1;const Z=U.name.localeCompare(V.name);return Z!==0?Z:(U.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(V.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),p(z)}catch(z){De.error(z instanceof Error?z.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),M?.silent||p([])}finally{M?.silent||k(!1)}},[t]);tt.useEffect(()=>{if(!e)return;const x=c?.id||i[0]?.id||"";m(x),x?w(x):(p([]),k(!1))},[e,c,i,w]),tt.useEffect(()=>{if(!e)return;let x=null;const M=ra(z=>{z.type==="scheduled-task-ran"&&z.projectId===u&&(x&&clearTimeout(x),x=setTimeout(()=>{w(u,{silent:!0})},400))});return()=>{x&&clearTimeout(x),M()}},[e,u,w]);const A=tt.useCallback(async x=>{if(!u)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await Bc(u,x),await w(u),De.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[u,w,t]),D=tt.useCallback(async(x,M)=>{if(u){j(x.id),p(z=>z.map(U=>U.id===x.id?{...U,enabled:M}:U));try{x.loopFile?await hx(u,x.id,M):await Bc(u,{...x,enabled:M}),await w(u,{silent:!0})}catch(z){De.error(z instanceof Error?z.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await w(u,{silent:!0})}finally{j(null)}}},[u,w,t]),P=tt.useCallback(async x=>{if(!(!u||!window.confirm(x.loopFile?t("sessions.scheduledTasks.dialog.confirm.deleteLoopFile",{taskName:x.name}):t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:x.name})))){j(x.id);try{x.loopFile?await px(u,x.id):await gx(u,x.id),await w(u,{silent:!0}),De.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(z){De.error(z instanceof Error?z.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{j(null)}}},[u,w,t]),B=tt.useCallback(x=>{if(!x.loopFile){S(x),g(!0);return}if(C?.path){if(n(!1),r){Ln.getState().setSelectedPath(C.path,x.loopFile,{allowOutsideRoot:!0}),he.getState().setActiveMainTab("files");return}he.getState().openContextFile(C.path,x.loopFile)}},[r,C?.path,n]),F=tt.useCallback(async x=>{if(u){j(x.id);try{const{sessionId:M,persistError:z}=await xx(u,x.id);if(await Promise.all([w(u,{silent:!0}),Tl()]),z?De.warning(t("sessions.scheduledTasks.dialog.toast.startedPersistWarning")):De.success(t("sessions.scheduledTasks.dialog.toast.started")),M){const U=i.find(V=>V.id===u);nt.getState().setCurrentSession(M,U?.path??null),he.getState().setActiveMainTab("chat")}}catch(M){De.error(M instanceof Error?M.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{j(null)}}},[u,i,w,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(Ys,{value:u||"__none",onValueChange:x=>{const M=x==="__none"?"":x;m(M),M?w(M):p([])},children:[s.jsx(Qs,{size:"lg",className:r?"w-full":void 0,children:C?s.jsx(Rs,{children:N(C)}):s.jsx(Rs,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(Xs,{children:[i.length===0?s.jsx(ls,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,i.map(x=>s.jsx(ls,{value:x.id,children:N(x)},x.id))]})]})]}),_=()=>{S(null),g(!0)},L=x=>{m(x),x?w(x):p([])},W=s.jsx("div",{className:"min-h-[280px]",children:b?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(I,{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(x=>{const M=y===x.id,z=x.state?.lastStatus||"idle",U=pk[z],V=t(z==="success"?"sessions.scheduledTasks.dialog.status.success":z==="error"?"sessions.scheduledTasks.dialog.status.error":z==="running"?"sessions.scheduledTasks.dialog.status.running":"sessions.scheduledTasks.dialog.status.idle"),Z=x.state?.nextRunAt,X=x.state?.lastRunAt;return s.jsxs("div",{className:xe("rounded-lg border border-border p-4 transition-opacity",!x.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:x.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:mk(x,t)}),x.loopFile?s.jsx("div",{className:"typography-micro truncate text-muted-foreground/70",title:x.loopFile,children:t("sessions.scheduledTasks.dialog.loopFile.note",{file:x.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(I,{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:Zd(Z,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:hk(Z,o)})]}):s.jsx("span",{children:"—"})]}),s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx(I,{name:"history",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-medium text-foreground",children:t("sessions.scheduledTasks.dialog.lastRun.label")}),z==="running"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:"var(--status-warning)"},children:[s.jsx(I,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}),t("sessions.scheduledTasks.dialog.lastRun.runningNow")]}):X?s.jsxs(s.Fragment,{children:[U.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${U.tone})`},children:[s.jsx(I,{name:U.Icon,className:"h-3.5 w-3.5"}),V]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:Zd(X,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),x.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:gk("error"),children:[s.jsx(I,{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:x.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:xe("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",x.enabled?"text-foreground":"text-muted-foreground",M&&"cursor-not-allowed opacity-50"),children:[s.jsx(Zr,{checked:x.enabled,onChange:le=>{D(x,le)},ariaLabel:x.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:x.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:x.name}),disabled:M}),x.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(x)},disabled:M,children:[s.jsx(I,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(lt,{variant:"outline",size:"sm",onClick:()=>B(x),disabled:M,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:x.name}),children:[s.jsx(I,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(lt,{variant:"destructive",size:"sm",onClick:()=>{P(x)},disabled:M,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:x.name}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},x.id)})})}),K=s.jsxs("div",{className:"space-y-4",children:[E,W]});return s.jsxs(s.Fragment,{children:[r?s.jsx(Xi,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:x=>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")}),x]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(lt,{className:"w-full",onClick:_,disabled:!u,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:K}):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(x=>s.jsx("button",{type:"button",onClick:()=>L(x.id),className:xe("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===x.id?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground"),children:N(x)},x.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:_,disabled:!u,children:[s.jsx(I,{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:W})})]})]})}):null,s.jsx(ak,{open:v,task:h,onOpenChange:g,onSave:A})]})}const Ai=100;function tu(){const t=it.c(105),{t:e}=gt(),n=he(Ck),r=he(kk),o=he(jk),i=nt(Sk),c=nt(wk),a=as(vk);let d;t[0]!==n?(d=X=>n?X.archivedSessions:[],t[0]=n,t[1]=d):d=t[1];const u=Is(Xn(d)),[m,f]=l.useState(""),[p,b]=l.useState(null),[k,v]=l.useState(Ai);let g;t[2]!==m?(g=m.trim().toLowerCase(),t[2]=m,t[3]=g):g=t[3];const h=g;let S;e:{if(!n){let le;t[4]===Symbol.for("react.memo_cache_sentinel")?(le=[],t[4]=le):le=t[4],S=le;break e}let X;t[5]!==u?(X=[...u].sort(yk),t[5]=u,t[6]=X):X=t[6],S=X}const y=S;let j;if(t[7]!==a||t[8]!==y||t[9]!==e){const X=new Map;for(const le of y){const te=jt(Zs(le))??"",fe=X.get(te);if(fe){fe.sessions.push(le);continue}X.set(te,{directory:te,label:te?xr(te,a)||te:e("sessions.archivePage.otherProjects"),sessions:[le]})}j=[...X.values()].sort(bk),t[7]=a,t[8]=y,t[9]=e,t[10]=j}else j=t[10];const C=j;let N;e:{if(h){let le;if(t[11]!==h||t[12]!==y){let te;t[14]!==h?(te=fe=>(fe.title??"").toLowerCase().includes(h),t[14]=h,t[15]=te):te=t[15],le=y.filter(te),t[11]=h,t[12]=y,t[13]=le}else le=t[13];N=le;break e}if(p===null){N=y;break e}let X;t[16]!==C||t[17]!==p?(X=C.find(le=>le.directory===p)?.sessions??[],t[16]=C,t[17]=p,t[18]=X):X=t[18],N=X}const w=N;let A,D,P,B,F,E,_,L,W,K;if(t[19]!==u.length||t[20]!==C||t[21]!==w||t[22]!==a||t[23]!==h||t[24]!==n||t[25]!==m||t[26]!==p||t[27]!==o||t[28]!==i||t[29]!==r||t[30]!==e||t[31]!==c||t[32]!==k){F=Symbol.for("react.early_return_sentinel");e:{const X=w.slice(0,k);A=w.length-X.length;const le=u.length;let te;t[43]===Symbol.for("react.memo_cache_sentinel")?(te=se=>{b(se),v(Ai)},t[43]=te):te=t[43];const fe=te;let ge;t[44]!==o||t[45]!==i||t[46]!==r?(ge=se=>{const oe=jt(Zs(se));i(se.id,oe??void 0),o("chat"),r(!1)},t[44]=o,t[45]=i,t[46]=r,t[47]=ge):ge=t[47];const H=ge;let Se;t[48]!==e||t[49]!==c?(Se=se=>{c(se.id).then(oe=>{oe?De.success(e("sessions.sidebar.session.restore.success")):De.error(e("sessions.sidebar.session.restore.error"))})},t[48]=e,t[49]=c,t[50]=Se):Se=t[50];const ae=Se;if(!n){F=null;break e}let q;t[51]!==e?(q=(se,oe,Ee,J,re,ee,$)=>s.jsxs("div",{className:"group/dir relative",children:[s.jsxs("button",{type:"button",onClick:re,title:ee,className:xe("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",$?"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:Ee})]}),$?s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>Un.requestDelete({sessions:$,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(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})}),s.jsx(ht,{side:"bottom",sideOffset:4,children:e("sessions.archivePage.deleteProject")})]}):null]},se),t[51]=e,t[52]=q):q=t[52];const me=q;B="absolute inset-0 z-10 flex flex-col bg-background",D="flex min-h-0 flex-1";let pe;if(t[53]!==me||t[54]!==p||t[55]!==e||t[56]!==le){let se;t[58]===Symbol.for("react.memo_cache_sentinel")?(se=()=>fe(null),t[58]=se):se=t[58],pe=me("__all__",e("sessions.archivePage.allDirectories"),le,p===null,se),t[53]=me,t[54]=p,t[55]=e,t[56]=le,t[57]=pe}else pe=t[57];let Ie;if(t[59]!==C||t[60]!==me||t[61]!==p){let se;t[63]!==me||t[64]!==p?(se=oe=>me(oe.directory||"__none__",oe.label,oe.sessions.length,p===oe.directory,()=>fe(oe.directory),oe.directory||void 0,oe.sessions),t[63]=me,t[64]=p,t[65]=se):se=t[65],Ie=C.map(se),t[59]=C,t[60]=me,t[61]=p,t[62]=Ie}else Ie=t[62];t[66]!==pe||t[67]!==Ie?(P=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:[pe,Ie]})}),t[66]=pe,t[67]=Ie,t[68]=P):P=t[68],W="flex min-w-0 flex-1 flex-col";let Oe;t[69]===Symbol.for("react.memo_cache_sentinel")?(Oe=s.jsx(I,{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]=Oe):Oe=t[69];let Me;t[70]===Symbol.for("react.memo_cache_sentinel")?(Me=se=>{f(se.target.value),v(Ai)},t[70]=Me):Me=t[70];let Fe;t[71]!==e?(Fe=e("sessions.archivePage.searchPlaceholder"),t[71]=e,t[72]=Fe):Fe=t[72];let je;t[73]!==m||t[74]!==Fe?(je=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Oe,s.jsx("input",{value:m,onChange:Me,placeholder:Fe,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]=Fe,t[75]=je):je=t[75];let Ne;t[76]!==w.length||t[77]!==e?(Ne=w.length===1?e("sessions.archivePage.countSingle",{count:w.length}):e("sessions.archivePage.countPlural",{count:w.length}),t[76]=w.length,t[77]=e,t[78]=Ne):Ne=t[78];let Pe;t[79]!==Ne?(Pe=s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:Ne}),t[79]=Ne,t[80]=Pe):Pe=t[80],t[81]!==je||t[82]!==Pe?(K=s.jsxs("div",{className:"flex items-center gap-3 px-6 pt-3",children:[je,Pe]}),t[81]=je,t[82]=Pe,t[83]=K):K=t[83],L="min-h-0 flex-1 overflow-y-auto px-6 py-3",E="mx-auto w-full max-w-3xl space-y-0.5",_=X.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")})}):X.map(se=>{const oe=jt(Zs(se))??"",Ee=oe?xr(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(se),role:"button",tabIndex:0,onKeyDown:J=>{(J.key==="Enter"||J.key===" ")&&(J.preventDefault(),H(se))},children:[s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:se.title||e("sessions.sidebar.session.untitled")}),h&&Ee?s.jsx("span",{className:"max-w-40 flex-shrink-0 truncate text-[0.72rem] text-muted-foreground/70",title:oe,children:Ee}):null,s.jsx("span",{className:"flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:Qu(se.time?.archived??se.time?.updated??se.time?.created??Date.now())}),s.jsx("button",{type:"button",onClick:J=>{J.stopPropagation(),ae(se)},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:se.title||e("sessions.sidebar.session.untitled")}),children:s.jsx(I,{name:"inbox-unarchive",className:"h-3.5 w-3.5"})}),s.jsx("button",{type:"button",onClick:J=>{J.stopPropagation(),Un.requestDelete({sessions:[se],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:se.title||e("sessions.sidebar.session.untitled")}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},se.id)})}t[19]=u.length,t[20]=C,t[21]=w,t[22]=a,t[23]=h,t[24]=n,t[25]=m,t[26]=p,t[27]=o,t[28]=i,t[29]=r,t[30]=e,t[31]=c,t[32]=k,t[33]=A,t[34]=D,t[35]=P,t[36]=B,t[37]=F,t[38]=E,t[39]=_,t[40]=L,t[41]=W,t[42]=K}else A=t[33],D=t[34],P=t[35],B=t[36],F=t[37],E=t[38],_=t[39],L=t[40],W=t[41],K=t[42];if(F!==Symbol.for("react.early_return_sentinel"))return F;let x;t[84]!==A||t[85]!==e?(x=A>0?s.jsx("button",{type:"button",onClick:()=>v(xk),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]=A,t[85]=e,t[86]=x):x=t[86];let M;t[87]!==x||t[88]!==E||t[89]!==_?(M=s.jsxs("div",{className:E,children:[_,x]}),t[87]=x,t[88]=E,t[89]=_,t[90]=M):M=t[90];let z;t[91]!==M||t[92]!==L?(z=s.jsx("div",{className:L,children:M}),t[91]=M,t[92]=L,t[93]=z):z=t[93];let U;t[94]!==z||t[95]!==W||t[96]!==K?(U=s.jsxs("div",{className:W,children:[K,z]}),t[94]=z,t[95]=W,t[96]=K,t[97]=U):U=t[97];let V;t[98]!==D||t[99]!==P||t[100]!==U?(V=s.jsxs("div",{className:D,children:[P,U]}),t[98]=D,t[99]=P,t[100]=U,t[101]=V):V=t[101];let Z;return t[102]!==B||t[103]!==V?(Z=s.jsx("div",{className:B,children:V}),t[102]=B,t[103]=V,t[104]=Z):Z=t[104],Z}function xk(t){return t+Ai}function bk(t,e){return e.sessions.length-t.sessions.length}function yk(t,e){return(e.time?.archived??0)-(t.time?.archived??0)}function vk(t){return t.homeDirectory}function wk(t){return t.unarchiveSession}function Sk(t){return t.setCurrentSession}function jk(t){return t.setActiveMainTab}function kk(t){return t.setArchivePageOpen}function Ck(t){return t.isArchivePageOpen}function su(){const t=it.c(18),{t:e}=gt(),n=he(Dk),r=he(Ak),o=Jt(Nk);let i;t[0]!==n?(i=b=>b.projects.find(k=>k.id===n)??null,t[0]=n,t[1]=i):i=t[1];const c=Jt(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(I,{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(ex,{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 p;return t[15]!==m||t[16]!==f?(p=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]=p):p=t[17],p}function Nk(t){return t.setActiveProjectIdOnly}function Ak(t){return t.setNewWorktreeDialogOpen}function Dk(t){return t.worktreesPageProjectId}const xl=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),Pk=(t,e)=>{const n=xl(t),r=xl(e);return`${n}-${r}`.substring(0,60)},nu=(t,e)=>`${t}/${e}`,Ek=t=>{const e=t.replace(/\\/g,"/");return e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e},ru=(t,e)=>{const n=Ek(e),r=t.directory,o=typeof r=="string"&&r.trim().length>0?t:{...t,directory:n};og(t.id,n),nt.getState().markSessionAsOpenChamberCreated(t.id),Is.getState().upsertSession(o);try{Ei().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},Tk=()=>{const t=Jt.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=as.getState().currentDirectory??null;if(r&&r.trim().length>0){const o=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${o}`,path:o}}return null},La=Lr()(xf(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=Tk();if(!a)return t({error:"Select a project",isLoading:!1}),null;const d=a.path,m=await Zu(d)&&e.isolateRuns!==!1,f=xl(n),p=m?await Ji(d):void 0,b=m?await Jp(d):null,k=[],v=c?.filter(j=>j.trim().length>0)??[];for(let j=0;j<r.length;j++){const C=r[j],N=C.prompt,w=new Map;for(const D of C.models){const P=`${D.providerID}:${D.modelID}`;w.set(P,(w.get(P)||0)+1)}const A=new Map;for(const D of C.models){const P=`${D.providerID}:${D.modelID}`,B=w.get(P)||1,F=(A.get(P)||0)+1;A.set(P,F);const E=Pk(D.providerID,D.modelID),_=r.length>1?`g${j+1}`:void 0,L=B>1?nu(f,`${E}/${F}`):nu(f,E),W=_?`${_}/${L}`:L,K=Qj({groupSlug:f,runGroup:_,providerID:D.providerID,modelID:D.modelID,index:B>1?F:void 0});try{if(!m){const U=await an.withDirectory(d,()=>an.createSession({title:K}));ru(U,d),k.push({sessionId:U.id,worktreePath:d,providerID:D.providerID,modelID:D.modelID,variant:D.variant,prompt:N});continue}const x=await Zp(a,{preferredName:W,mode:"new",branchName:W,worktreeName:W,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:v,returnAfterDirectoryCreated:!0},{resolvedRootTrackingRemote:b}),M={...x,createdFromBranch:p,kind:"standard"};await eg(a)&&await tg(x.path);const z=await an.withDirectory(x.path,()=>an.createSession({title:K}));ru(z,x.path),nt.getState().setWorktreeMetadata(z.id,M),k.push({sessionId:z.id,worktreePath:x.path,providerID:D.providerID,modelID:D.modelID,variant:D.variant,prompt:N})}catch(x){console.warn("[MultiRun] Failed to create session:",x)}}}const g=c?.filter(j=>j.trim().length>0)??[];g.length>0&&sg(a,g).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const h=k.map(j=>j.sessionId),S=k[0]?.sessionId??null;if(h.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const y=i?.map(j=>({type:"file",mime:j.mime,filename:j.filename,url:j.url}));return(async()=>{try{const j=ng.getState().expandText;await Promise.allSettled(k.map(async C=>{try{const N=await j(C.prompt).catch(()=>C.prompt);await rg({sessionId:C.sessionId,directory:C.worktreePath,content:N,providerID:C.providerID,modelID:C.modelID,variant:C.variant,agent:o,files:y})}catch(N){console.warn("[MultiRun] Failed to start run:",N)}}))}catch(j){console.warn("[MultiRun] Failed to start runs:",j)}})(),t({isLoading:!1}),{groupSlug:f,sessionIds:h,firstSessionId:S}}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 mm(t){const e=it.c(30),{git:n}=nr(),r=Ou(t),o=ig(t),i=ag(t),c=lg(t),a=gr(Fk),d=gr(Ok);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 p=r?.all;let b;e[13]!==t||e[14]!==a||e[15]!==n||e[16]!==o||e[17]!==p?(b=[t,n,o,p,a],e[13]=t,e[14]=a,e[15]=n,e[16]=o,e[17]=p,e[18]=b):b=e[18],l.useEffect(f,b);const k=i||o===!0&&c;let v;e:{if(!r?.all){let w;e[19]===Symbol.for("react.memo_cache_sentinel")?(w=[],e[19]=w):w=e[19],v=w;break e}let N;e[20]!==r.all?(N=r.all.filter(Rk).sort(),e[20]=r.all,e[21]=N):N=e[21],v=N}const g=v;let h;e:{if(!r?.all){let w;e[22]===Symbol.for("react.memo_cache_sentinel")?(w=[],e[22]=w):w=e[22],h=w;break e}let N;e[23]!==r.all?(N=r.all.filter(Mk).map(Ik).sort(),e[23]=r.all,e[24]=N):N=e[24],h=N}const S=h;let y;e:{if(!t){y=null;break e}if(o!==null){y=o;break e}if(k){y=null;break e}y=r?.all?!0:null}const j=y;let C;return e[25]!==j||e[26]!==k||e[27]!==g||e[28]!==S?(C={localBranches:g,remoteBranches:S,isLoading:k,isGitRepository:j},e[25]=j,e[26]=k,e[27]=g,e[28]=S,e[29]=C):C=e[29],C}function Ik(t){return t.replace(/^remotes\//,"")}function Mk(t){return t.startsWith("remotes/")}function Rk(t){return!t.startsWith("remotes/")}function Ok(t){return t.fetchStatus}function Fk(t){return t.fetchBranches}const Bk=({directory:t,value:e,onChange:n,className:r,disabled:o,id:i})=>{const{t:c}=gt(),{localBranches:a,remoteBranches:d,isLoading:u,isGitRepository:m}=mm(t),f=l.useMemo(()=>[...a,...d.map(b=>`remotes/${b}`)],[a,d]);l.useEffect(()=>{if(o||u||f.length===0||e&&f.includes(e))return;const b=e;let k=!1;return(async()=>{try{const g=t?await Ji(t).catch(()=>null):null;if(k)return;const h=localStorage.getItem(Fc),{sourceBranch:S,shouldClearSavedSourceBranch:y}=tx({branches:f,savedSourceBranch:h,rootBranch:g});if(y&&localStorage.removeItem(Fc),k||b&&f.includes(b))return;S&&n(S)}catch{}})(),()=>{k=!0}},[f,t,o,u,n,e]);const p=o||!m||u;return s.jsxs("div",{children:[s.jsxs(Ys,{value:e,onValueChange:n,disabled:p,children:[s.jsx(Qs,{id:i,size:"lg",className:xe("min-w-0 max-w-full *:data-[slot=select-value]:truncate",r??"w-fit"),children:s.jsx(Rs,{placeholder:c(u?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(Xs,{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(qa,{children:[s.jsx(Nc,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.localBranches")}),a.map(b=>s.jsx(ls,{value:b,className:"whitespace-normal break-all",children:b},b))]}),a.length>0&&d.length>0&&s.jsx(cg,{}),d.length>0&&s.jsxs(qa,{children:[s.jsx(Nc,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.remoteBranches")}),d.map(b=>s.jsx(ls,{value:`remotes/${b}`,className:"whitespace-normal break-all",children:b},`remotes/${b}`))]})]})})]}),m===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:c("multiRun.branchSelector.status.notInGitRepository")})]})},Lk=10*1024*1024,_a=5,Di=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(I,{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},Tr=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},ou=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:o}=gt(),[i,c]=l.useState(""),[a,d]=l.useState(()=>[{id:Po(),prompt:"",models:[]}]),[u,m]=l.useState(""),[f,p]=l.useState([]),[b,k]=l.useState(!1),[v,g]=l.useState([]),[h,S]=l.useState(!1),[y,j]=l.useState(!1),[C,N]=l.useState(!0),w=l.useRef(null),A=as($=>$.currentDirectory??null),D=as($=>$.homeDirectory??null),P=l.useMemo(()=>{if(typeof window>"u")return null;const $=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof $=="string"&&$.trim().length>0?$.trim():null},[]),B=Jt($=>$.activeProjectId),F=Jt($=>$.setActiveProjectIdOnly),E=Jt($=>$.projects),[_,L]=l.useState(()=>B??null);l.useEffect(()=>{if(B){L(B);return}!_&&E.length>0&&L(E[0].id)},[B,E,_]);const W=l.useMemo(()=>_?E.find($=>$.id===_)??null:null,[E,_]),K=W?.path??A,x=l.useCallback($=>{L($),$!==B&&F($)},[B,F]),{currentTheme:M}=Br(),z=l.useCallback($=>{const de=$.label?.trim()||xr($.path,D),Y=$.icon?Al[$.icon]:null,ue=$.color?Dl[$.color]:void 0,Te=Y?s.jsx(I,{name:Y,className:"h-3.5 w-3.5 shrink-0",style:ue?{color:ue}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:ue?{color:ue}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[$.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:$.iconBackground?{backgroundColor:$.iconBackground}:void 0,children:s.jsx(Pl,{project:{id:$.id,iconImage:$.iconImage??null},options:{themeVariant:M.metadata.variant,iconColor:M.colors.surface.foreground},className:"h-full w-full object-contain",fallback:Te})}):Te,s.jsx("span",{className:"truncate",children:de})]})},[D,M.metadata.variant,M.colors.surface.foreground]),U=l.useMemo(()=>{if(W?.path)return{id:W.id,path:W.path};const $=A??P;return $?{id:`path:${$}`,path:$}:null},[W,A,P]),[V]=l.useState(()=>typeof window<"u"?Wn():!1),Z=l.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),X=Au(),le=l.useMemo(()=>{if(typeof window>"u")return null;const $=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof $=="number"&&Number.isFinite($)&&$>0)return $;if(typeof navigator>"u")return null;const de=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!de)return null;const Y=Number.parseInt(de[1],10),ue=Number.parseInt(de[2],10);return Number.isNaN(Y)?null:Y===10?ue:Y},[]),te=l.useMemo(()=>V&&Z||X?"pl-[5.5rem]":"pl-3",[V,Z,X]),fe=l.useMemo(()=>!V||!Z||le===null?"":le>=26?"h-12":le<=15?"h-14":"",[V,Z,le]),ge=l.useCallback(async $=>{$.target.closest("button, a, input, select, textarea")||$.button===0&&V&&await dg()},[V]);l.useEffect(()=>{if(!n)return;const $=de=>{de.key==="Escape"&&(de.preventDefault(),de.stopPropagation(),n())};return window.addEventListener("keydown",$,!0),()=>window.removeEventListener("keydown",$,!0)},[n]);const[H,Se]=l.useState(""),{isLoading:ae,isGitRepository:q}=mm(K),me=l.useRef(!1),pe=q===!0,Ie=pe&&C;l.useEffect(()=>{if(q===!1){me.current=!0,N(!1);return}q===!0&&me.current&&(me.current=!1,N(!0))},[q]);const Oe=La($=>$.createMultiRun),Me=La($=>$.error),Fe=La($=>$.clearError);l.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d($=>{const de=[...$];return de.length>0&&!de[0].prompt.trim()&&(de[0]={...de[0],prompt:t}),de})},[t]),l.useEffect(()=>{if(!U)return;let $=!1;return j(!0),(async()=>{try{const de=await ug(U);$||g(de)}catch{}finally{$||j(!1)}})(),()=>{$=!0}},[U]);const je=l.useCallback(($,de)=>{d(Y=>Y.map(ue=>ue.id===$?{...ue,...de}:ue))},[]),Ne=l.useCallback($=>{d(de=>de.filter(Y=>Y.id!==$))},[]),Pe=l.useCallback(()=>{d($=>[...$,{id:Po(),prompt:"",models:[]}])},[]),se=async $=>{const de=$.target.files;if(!de)return;let Y=0;for(let ue=0;ue<de.length;ue++){const Te=de[ue];if(Te.size>Lk){De.error(o("multirun.launcher.toast.fileTooLarge",{fileName:Te.name}));continue}try{const Ge=await new Promise((_e,ie)=>{const Re=new FileReader;Re.onload=()=>_e(Re.result),Re.onerror=ie,Re.readAsDataURL(Te)});p(_e=>[..._e,{id:Po(),filename:Te.name,mimeType:Te.type||"application/octet-stream",size:Te.size,dataUrl:Ge}]),Y++}catch(Ge){console.error("File attach failed",Ge),De.error(o("multirun.launcher.toast.attachFailed",{fileName:Te.name}))}}Y>0&&De.success(Y===1?o("multirun.launcher.toast.attachedSingle",{count:Y}):o("multirun.launcher.toast.attachedPlural",{count:Y})),w.current&&(w.current.value="")},oe=$=>{p(de=>de.filter(Y=>Y.id!==$))},Ee=l.useMemo(()=>a.reduce(($,de)=>$+de.models.length,0),[a]),J=async $=>{$.preventDefault();const de=a.filter(Y=>Y.prompt.trim()&&Y.models.length>=1);if(de.length!==0&&!(Ee<1)){k(!0),Fe();try{_&&_!==B&&F(_);const Y=f.map(ie=>({mime:ie.mimeType,filename:ie.filename,url:ie.dataUrl})),ue=v.filter(ie=>ie.trim().length>0),Te=de.map(ie=>({prompt:ie.prompt.trim(),models:ie.models.map(Re=>({providerID:Re.providerID,modelID:Re.modelID,displayName:Re.displayName,variant:Re.variant}))})),Ge={name:i.trim(),groups:Te,agent:u||void 0,worktreeBaseBranch:Ie?H:void 0,isolateRuns:Ie,files:Y.length>0?Y:void 0,setupCommands:ue.length>0?ue:void 0},_e=await Oe(Ge);_e&&(_e.firstSessionId&&nt.getState().setCurrentSession(_e.firstSessionId),e?.())}finally{k(!1)}}},re=!!(i.trim()&&a.some($=>$.prompt.trim()&&$.models.length>=1)&&Ee>=1&&K&&!ae&&(q===!1||!Ie||H)),ee=v.filter($=>$.trim()).length;return s.jsxs("form",{onSubmit:J,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:ge,className:xe("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",te,fe),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(I,{name:"close",className:"h-5 w-5"})})}),s.jsx(ht,{children:s.jsx("p",{children:o("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(jl,{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(Tr,{htmlFor:"multirun-project",required:!0,children:o("multirun.launcher.project.label")}),E.length>0?s.jsxs(Ys,{value:_??void 0,onValueChange:x,children:[s.jsx(Qs,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:W?s.jsx(Rs,{children:z(W)}):s.jsx(Rs,{placeholder:o("multirun.launcher.project.placeholder")})}),s.jsx(Xs,{fitContent:!0,children:E.map($=>s.jsx(ls,{value:$.id,className:"max-w-[24rem]",children:z($)},$.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(Tr,{htmlFor:"group-name",required:!0,info:s.jsx(Di,{children:o("multirun.launcher.groupName.info")}),children:o("multirun.launcher.groupName.label")}),s.jsx(er,{id:"group-name",value:i,onChange:$=>c($.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(Tr,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(Di,{children:o("multirun.launcher.baseBranch.info")}),children:o("multirun.launcher.baseBranch.label")}),s.jsx(Bk,{directory:K,value:H,onChange:Se,disabled:!Ie,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(Zr,{checked:C,onChange:N,disabled:!pe,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(Tr,{htmlFor:"multirun-agent",info:s.jsx(Di,{children:o("multirun.launcher.agent.info")}),children:o("multirun.launcher.agent.label")}),s.jsx(cm,{value:u,onChange:m,id:"multirun-agent"})]})]}),s.jsxs(Ti,{open:h,onOpenChange:S,children:[s.jsxs(Ml,{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(I,{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")}),ee>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:ee}),s.jsx(I,{name:"arrow-down-s",className:xe("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",h&&"rotate-180")})]}),s.jsx(Ii,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:y?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:o("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[v.map(($,de)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(er,{value:$,onChange:Y=>{const ue=[...v];ue[de]=Y.target.value,g(ue)},placeholder:o("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>g(v.filter((Y,ue)=>ue!==de)),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(I,{name:"close",className:"h-3.5 w-3.5"})})]},`${$}-${de}`)),s.jsxs("button",{type:"button",onClick:()=>g([...v,""]),className:"flex items-center gap-1 typography-meta text-muted-foreground hover:text-foreground transition-colors px-1",children:[s.jsx(I,{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(Tr,{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:w,type:"file",multiple:!0,className:"hidden",onChange:se,accept:"*/*"}),s.jsxs(ft,{children:[s.jsx(mt,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>w.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(I,{name:"attachment-2",className:"h-3 w-3"}),o("multirun.launcher.attachments.attach")]})}),s.jsx(ht,{children:o("multirun.launcher.attachments.tooltip")})]}),f.map($=>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:[$.mimeType.startsWith("image/")?s.jsx(I,{name:"file-image",className:"h-3 w-3 text-muted-foreground"}):s.jsx(I,{name:"file",className:"h-3 w-3 text-muted-foreground"}),s.jsx("span",{className:"truncate max-w-[100px]",title:$.filename,children:$.filename}),s.jsx("button",{type:"button",onClick:()=>oe($.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(I,{name:"close",className:"h-3 w-3"})})]},$.id))]})]}),a.map(($,de)=>s.jsx(_k,{group:$,groupIndex:de,canRemove:a.length>1,onUpdate:je,onRemove:Ne},$.id)),s.jsxs("button",{type:"button",onClick:Pe,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(I,{name:"add",className:"h-3.5 w-3.5"}),o("multirun.launcher.groups.addGroup")]}),Me&&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:Me})]})})}),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:[!Ie&&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(I,{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||b,children:b?o("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:o("multirun.launcher.actions.startWithRunCount",{count:Ee})})})]})})]})},_k=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(""),[p,b]=l.useState(!1),[k,v]=l.useState(""),[g,h]=l.useState(!1),[S,y]=l.useState(""),j=l.useRef(null),C=l.useRef(null),N=l.useRef(null),w=l.useRef(null);let A;e[0]!==n.id||e[1]!==n.models||e[2]!==i?(A=ue=>{n.models.length>=_a||i(n.id,{models:[...n.models,ue]})},e[0]=n.id,e[1]=n.models,e[2]=i,e[3]=A):A=e[3];const D=A;let P;e[4]!==n.id||e[5]!==n.models||e[6]!==i?(P=ue=>{i(n.id,{models:n.models.filter((Te,Ge)=>Ge!==ue)})},e[4]=n.id,e[5]=n.models,e[6]=i,e[7]=P):P=e[7];const B=P;let F;e[8]!==n.id||e[9]!==n.models||e[10]!==i?(F=(ue,Te)=>{i(n.id,{models:n.models.map((Ge,_e)=>_e===ue?Te:Ge)})},e[8]=n.id,e[9]=n.models,e[10]=i,e[11]=F):F=e[11];const E=F;let _;e[12]===Symbol.for("react.memo_cache_sentinel")?(_=(ue,Te)=>{if(ue.startsWith("/")){const Re=ue.indexOf(" "),be=ue.indexOf(`
918
+ `),T=Math.min(Re===-1?ue.length:Re,be===-1?ue.length:be);if(Te<=T&&Re===-1){v(ue.substring(1,T)),b(!0),u(!1),h(!1);return}}b(!1);const Ge=ue.substring(0,Te),_e=Ge.lastIndexOf("#");if(_e!==-1){const Re=_e>0?Ge[_e-1]:null,be=Ge.substring(_e+1);if((!Re||/\s/.test(Re))&&!be.includes(" ")&&!be.includes(`
919
+ `)){y(be),h(!0),u(!1);return}}h(!1);const ie=Ge.lastIndexOf("@");if(ie!==-1){const Re=ie>0?Ge[ie-1]:null,be=Ge.substring(ie+1);(!Re||/\s/.test(Re))&&!be.includes(" ")&&!be.includes(`
920
+ `)?(f(be),u(!0)):u(!1);return}u(!1)},e[12]=_):_=e[12];const L=_;let W;e[13]!==n.id||e[14]!==i?(W=ue=>{i(n.id,{prompt:ue})},e[13]=n.id,e[14]=i,e[15]=W):W=e[15];const K=W;let x;e[16]!==n.prompt||e[17]!==K?(x=ue=>{const Te=n.prompt,_e=j.current?.selectionStart??Te.length,Re=Te.substring(0,_e).lastIndexOf("@"),be=ue.relativePath&&ue.relativePath.trim().length>0?ue.relativePath.trim():ue.path||ue.name,T=Re!==-1?Re:_e,ce=`${Te.substring(0,T)}@${be} ${Te.substring(_e)}`,ve=T+be.length+2;K(ce),u(!1),f(""),requestAnimationFrame(()=>{const Ce=j.current;Ce&&(Ce.selectionStart=ve,Ce.selectionEnd=ve,Ce.focus()),L(ce,ve)})},e[16]=n.prompt,e[17]=K,e[18]=x):x=e[18];const M=x;let z;e[19]!==n.prompt||e[20]!==K?(z=ue=>{const Te=n.prompt,_e=j.current?.selectionStart??Te.length,Re=Te.substring(0,_e).lastIndexOf("@"),be=Re!==-1?Re:_e,T=`${Te.substring(0,be)}@${ue} ${Te.substring(_e)}`,ce=be+ue.length+2;K(T),u(!1),f(""),requestAnimationFrame(()=>{const ve=j.current;ve&&(ve.selectionStart=ce,ve.selectionEnd=ce,ve.focus()),L(T,ce)})},e[19]=n.prompt,e[20]=K,e[21]=z):z=e[21];const U=z;let V;e[22]!==K?(V=ue=>{const Te=`/${ue.name} `;K(Te),b(!1),v(""),h(!1),requestAnimationFrame(()=>{const Ge=j.current;Ge&&(Ge.focus(),Ge.selectionStart=Ge.value.length,Ge.selectionEnd=Ge.value.length),L(Te,Te.length)})},e[22]=K,e[23]=V):V=e[23];const Z=V;let X;e[24]!==n.prompt||e[25]!==K?(X=(ue,Te)=>{const Ge=n.prompt,ie=j.current?.selectionStart??Ge.length,be=Ge.substring(0,ie).lastIndexOf("#"),T=be!==-1?be:ie,ce=`${Ge.substring(0,T)}#${Te} ${Ge.substring(ie)}`,ve=T+Te.length+2;K(ce),h(!1),y(""),requestAnimationFrame(()=>{const Ce=j.current;Ce&&(Ce.selectionStart=ve,Ce.selectionEnd=ve,Ce.focus()),L(ce,ve)})},e[24]=n.prompt,e[25]=K,e[26]=X):X=e[26];const le=X;let te;e[27]!==p||e[28]!==d||e[29]!==g?(te=ue=>{if(p&&N.current&&(ue.key==="Enter"||ue.key==="ArrowUp"||ue.key==="ArrowDown"||ue.key==="Escape"||ue.key==="Tab")){ue.preventDefault(),N.current.handleKeyDown(ue.key);return}d&&C.current&&(ue.key==="Enter"||ue.key==="ArrowUp"||ue.key==="ArrowDown"||ue.key==="Escape"||ue.key==="Tab")&&(ue.preventDefault(),C.current.handleKeyDown(ue.key)),g&&w.current&&(ue.key==="Enter"||ue.key==="ArrowUp"||ue.key==="ArrowDown"||ue.key==="Escape"||ue.key==="Tab")&&(ue.preventDefault(),w.current.handleKeyDown(ue.key))},e[27]=p,e[28]=d,e[29]=g,e[30]=te):te=e[30];const fe=te,ge=r+1;let H;e[31]!==a||e[32]!==ge?(H=a("multirun.launcher.groups.groupLabel",{index:ge}),e[31]=a,e[32]=ge,e[33]=H):H=e[33];let Se;e[34]!==H?(Se=s.jsx("span",{className:"typography-meta font-medium text-foreground",children:H}),e[34]=H,e[35]=Se):Se=e[35];let ae;e[36]!==o||e[37]!==n.id||e[38]!==c||e[39]!==a?(ae=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(I,{name:"close",className:"h-3.5 w-3.5"})}),e[36]=o,e[37]=n.id,e[38]=c,e[39]=a,e[40]=ae):ae=e[40];let q;e[41]!==Se||e[42]!==ae?(q=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Se,ae]}),e[41]=Se,e[42]=ae,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 pe;e[46]!==me?(pe=s.jsx(Tr,{required:!0,children:me}),e[46]=me,e[47]=pe):pe=e[47];const Ie=n.prompt;let Oe;e[48]!==K?(Oe=ue=>{const Te=ue.target.value;K(Te);const Ge=ue.target.selectionStart??Te.length;L(Te,Ge)},e[48]=K,e[49]=Oe):Oe=e[49];let Me;e[50]!==a?(Me=a("multirun.launcher.groups.prompt.placeholder"),e[50]=a,e[51]=Me):Me=e[51];let Fe;e[52]!==n.prompt||e[53]!==fe||e[54]!==Oe||e[55]!==Me?(Fe=s.jsx(Xr,{ref:j,value:Ie,onChange:Oe,onKeyDown:fe,placeholder:Me,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]=fe,e[54]=Oe,e[55]=Me,e[56]=Fe):Fe=e[56];let je;e[57]!==k||e[58]!==Z||e[59]!==p?(je=p?s.jsx(ef,{ref:N,searchQuery:k,onCommandSelect:Z,onClose:()=>b(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[57]=k,e[58]=Z,e[59]=p,e[60]=je):je=e[60];let Ne;e[61]!==U||e[62]!==M||e[63]!==m||e[64]!==d?(Ne=d?s.jsx(tf,{ref:C,searchQuery:m,onFileSelect:M,onAgentSelect:U,onClose:()=>u(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[61]=U,e[62]=M,e[63]=m,e[64]=d,e[65]=Ne):Ne=e[65];let Pe;e[66]!==le||e[67]!==g||e[68]!==S?(Pe=g?s.jsx(sf,{ref:w,searchQuery:S,onSnippetSelect:le,onClose:()=>h(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[66]=le,e[67]=g,e[68]=S,e[69]=Pe):Pe=e[69];let se;e[70]!==Fe||e[71]!==je||e[72]!==Ne||e[73]!==Pe?(se=s.jsxs("div",{className:"relative",children:[Fe,je,Ne,Pe]}),e[70]=Fe,e[71]=je,e[72]=Ne,e[73]=Pe,e[74]=se):se=e[74];let oe;e[75]!==pe||e[76]!==se?(oe=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[pe,se]}),e[75]=pe,e[76]=se,e[77]=oe):oe=e[77];let Ee;e[78]!==a?(Ee=a("multirun.launcher.models.info",{max:_a}),e[78]=a,e[79]=Ee):Ee=e[79];let J;e[80]!==Ee?(J=s.jsx(Di,{children:Ee}),e[80]=Ee,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 ee;e[84]!==J||e[85]!==re?(ee=s.jsx(Tr,{required:!0,info:J,children:re}),e[84]=J,e[85]=re,e[86]=ee):ee=e[86];let $;e[87]!==n.models||e[88]!==D||e[89]!==B||e[90]!==E?($=s.jsx(dm,{selectedModels:n.models,onAdd:D,onRemove:B,onUpdate:E,minModels:1,maxModels:_a}),e[87]=n.models,e[88]=D,e[89]=B,e[90]=E,e[91]=$):$=e[91];let de;e[92]!==ee||e[93]!==$?(de=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[ee,$]}),e[92]=ee,e[93]=$,e[94]=de):de=e[94];let Y;return e[95]!==q||e[96]!==oe||e[97]!==de?(Y=s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[q,oe,de]}),e[95]=q,e[96]=oe,e[97]=de,e[98]=Y):Y=e[98],Y},$k=l.createContext(null),zk=t=>{const e=it.c(3),{children:n,value:r}=t;let o;return e[0]!==n||e[1]!==r?(o=s.jsx($k.Provider,{value:r,children:n}),e[0]=n,e[1]=r,e[2]=o):o=e[2],o},Uk=pn(()=>hn(()=>import("./PlanView-Czu1KMJa.js"),__vite__mapDeps([136,1,2,4,5,6,7,8,9,124,57,58,59,60,61,62,79,55,56,63,125,126,127,3,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,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,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}))),iu=pn(()=>hn(()=>import("./GitView-Rp8P1KEI.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}))),Wk=pn(()=>hn(()=>import("./DiffView-BHWaMYCC.js"),__vite__mapDeps([122,1,2,4,5,6,7,8,9,3,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}))),Vk=pn(()=>hn(()=>import("./FilesView-NMBCW2Tm.js"),__vite__mapDeps([123,1,2,4,5,6,7,8,9,3,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}))),Hk=pn(()=>hn(()=>import("./DiagramView-D0YNMix8.js"),__vite__mapDeps([137,1,2,4,5,6,7,8,9,3,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}))),Kk=pn(()=>hn(()=>import("./SettingsView-B6vmuf-c.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}))),Gk=pn(()=>hn(()=>import("./SettingsWindow-CauZpdD3.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}))),qk=()=>{const t=he(x=>x.isSidebarOpen),e=he(x=>x.activeSurface),n=he(x=>x.setIsMobile),r=he(x=>x.isSessionSwitcherOpen),o=he(x=>x.isSettingsDialogOpen),i=he(x=>x.setSettingsDialogOpen),[c,a]=l.useState(!1);l.useEffect(()=>{o&&a(!0)},[o]);const d=he(x=>x.isMultiRunLauncherOpen),u=he(x=>x.setMultiRunLauncherOpen),m=he(x=>x.multiRunLauncherPrefillPrompt),f=he(x=>x.isScheduledTasksDialogOpen),p=he(x=>x.isArchivePageOpen),b=he(x=>x.worktreesPageProjectId),k=f||p||!!b||d;l.useEffect(()=>{const x=()=>he.getState().closeMainSurfaces(),M=nt.subscribe((U,V)=>{const Z=!!U.currentSessionId&&U.currentSessionId!==V.currentSessionId,X=!!U.newSessionDraft?.open&&U.newSessionDraft!==V.newSessionDraft;(Z||X)&&x()}),z=he.subscribe((U,V)=>{U.activeSurface!==V.activeSurface&&x()});return()=>{M(),z()}},[]);const{isMobile:v}=br(),g=l.useRef(!1),[h,S]=l.useState(!1),[y,j]=l.useState(!1),[C,N]=l.useState(!1),[w,A]=l.useState(!1),D=l.useCallback(x=>{S(x),he.getState().setSessionSwitcherOpen(x)},[]),P=l.useRef(typeof window>"u"?0:window.innerWidth),B=zc(-P.current),F=tt.useRef(0),E=zc(P.current),_=tt.useRef(0);tt.useEffect(()=>{v&&(F.current=window.innerWidth,_.current=window.innerWidth)},[v]),tt.useEffect(()=>{if(!v){N(!1);return}h&&N(!0),Uc(B,h?0:-F.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[h,v,B]),tt.useEffect(()=>{if(!v){A(!1);return}y&&A(!0),Uc(E,y?0:_.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[v,y,E]),tt.useEffect(()=>{if(v)return B.on("change",x=>{const M=F.current||P.current,z=h||x>-M+.5;N(U=>U===z?U:z)})},[v,B,h]),tt.useEffect(()=>{if(v)return E.on("change",x=>{const M=_.current||P.current,z=y||x<M-.5;A(U=>U===z?U:z)})},[v,y,E]),tt.useEffect(()=>{v&&!r&&h&&D(!1)},[r,v,h,D]),tt.useEffect(()=>{if(!v){g.current=!1;return}g.current||(g.current=!0,D(!1),j(!1))},[v,D]),tt.useEffect(()=>{if(!v||e!=="chat"||h||y||o)return;let x=!1,M;const z=U=>{M=window.setTimeout(()=>{if(x)return;const V=nt.getState(),Z=he.getState();if(!(Z.activeMainTab!=="chat"||Z.isSettingsDialogOpen||V.currentSessionId||V.newSessionDraft?.open)){if(V.isLoading){z(250);return}V.openNewSessionDraft({automatic:!0})}},U)};return z(500),()=>{x=!0,M!==void 0&&window.clearTimeout(M)}},[e,v,o,h,y]),tt.useEffect(()=>{!v||!o||(D(!1),j(!1))},[v,o,D]),sx(),l.useEffect(()=>{he.getState().isMobile!==v&&n(v)},[v,n]);const L=l.useCallback(()=>{h&&D(!1),j(!y)},[h,y,D]),W=l.useMemo(()=>{if(!v&&e!=="terminal"&&e!=="diagram")return null;switch(e){case"plan":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(Uk,{})});case"git":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(iu,{isActive:!y})});case"diff":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(Wk,{})});case"terminal":return s.jsx(mf,{});case"files":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(Vk,{})});case"context":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(ff,{})});case"diagram":return s.jsx(l.Suspense,{fallback:null,children:s.jsx(Hk,{})});default:return null}},[e,v,y]),K=e==="chat";return s.jsx(nx,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:xe("main-content-safe-area",v?"flex h-[100dvh] flex-col":"relative flex h-[100dvh]","bg-background"),children:[s.jsx(q1,{}),s.jsx(FS,{}),s.jsx($S,{}),s.jsx(V2,{}),v?s.jsxs(zk,{value:{leftDrawerOpen:h,rightDrawerOpen:y,toggleLeftDrawer:()=>{const x=!h;y&&j(!1),D(x)},toggleRightDrawer:L,leftDrawerX:B,rightDrawerX:E,leftDrawerWidth:F,rightDrawerWidth:_,setMobileLeftDrawerOpen:D,setRightSidebarOpen:j},children:[!o&&s.jsx(qc,{onToggleLeftDrawer:()=>{const x=!h;y&&j(!1),D(x)},onToggleRightDrawer:()=>{L()},leftDrawerOpen:h,rightDrawerOpen:y}),s.jsx("div",{"data-page-scroll-lock":"true",className:xe("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:xe("absolute inset-0",(!K||k)&&"invisible"),children:s.jsx(us,{children:s.jsx(Qa,{active:K&&!o&&!k})})}),W&&s.jsx("div",{className:xe("absolute inset-0",k&&"invisible"),children:s.jsx(us,{children:W})}),d&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(us,{children:s.jsx(ou,{initialPrompt:m,onCreated:()=>u(!1),onCancel:()=>u(!1)})})}),s.jsx(us,{children:s.jsx(eu,{})}),s.jsx(us,{children:s.jsx(tu,{})}),s.jsx(us,{children:s.jsx(su,{})}),s.jsx(Wc.div,{className:xe("absolute inset-0 z-20 bg-sidebar",!C&&"pointer-events-none invisible"),"data-page-scroll-lock":"true",style:{x:B},"aria-hidden":!h,children:s.jsx(us,{children:s.jsx(Ud,{mobileVariant:!0,isVisible:C})})}),w&&s.jsx(Wc.div,{className:"absolute inset-0 z-20 bg-sidebar","data-page-scroll-lock":"true",style:{x:E},"aria-hidden":!y,children:s.jsx(us,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(iu,{isActive:y})})})})]})}),o&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(us,{children:s.jsx(l.Suspense,{fallback:null,children:s.jsx(Kk,{onClose:()=>i(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx(Fb,{}),s.jsxs("div",{className:"flex flex-1 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsx(Mb,{isOpen:t,isMobile:v,className:"border-border",topBar:s.jsx(Rb,{}),children:s.jsx(Ud,{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(qc,{}),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:xe("absolute inset-0",(!K||k)&&"invisible"),children:s.jsx(us,{children:s.jsx(Qa,{active:K&&!o&&!k})})}),W&&s.jsx("div",{className:xe("absolute inset-0",k&&"invisible"),children:s.jsx(us,{children:W})}),d&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(us,{children:s.jsx(ou,{isWindowed:!0,initialPrompt:m,onCreated:()=>u(!1),onCancel:()=>u(!1)})})}),s.jsx(us,{children:s.jsx(eu,{})}),s.jsx(us,{children:s.jsx(tu,{})}),s.jsx(us,{children:s.jsx(su,{})})]}),s.jsx(D1,{})]})})}),s.jsx("div",{className:"border-t border-border","data-page-scroll-lock":"true",children:s.jsx(us,{children:s.jsx(R1,{})})})]})]})]}),c?s.jsx(l.Suspense,{fallback:null,children:s.jsx(Gk,{open:o,onOpenChange:i})}):null]})]})})},hm=12,Yk=[{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"}],Qk=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?Yk:c,f=tt.useRef(!1);let p,b;e[0]!==n||e[1]!==a?(p=()=>{!n&&f.current&&a?.(),n&&(f.current=!0)},b=[n,a],e[0]=n,e[1]=a,e[2]=p,e[3]=b):(p=e[2],b=e[3]),tt.useEffect(p,b);let k;e[4]===Symbol.for("react.memo_cache_sentinel")?(k=Array.from({length:hm},Xk),e[4]=k):k=e[4];const v=k;if(!n)return null;let g;e[5]!==o?(g=xe("fireworks-overlay pointer-events-none",o),e[5]=o,e[6]=g):g=e[6];let h;if(e[7]!==d||e[8]!==m||e[9]!==u){let y;e[11]!==d||e[12]!==u?(y=j=>{const C={"--burst-delay":`${j.delay}ms`,"--burst-x":`${j.x}%`,"--burst-y":`${j.y}%`,"--firework-color":`var(${j.colorVar})`,"--firework-duration":`${u}ms`};return s.jsx("div",{className:"firework-burst",style:C,children:v.map((N,w)=>{const A=N.x*j.radius,D=N.y*j.radius,P={"--translate-x":`${A}px`,"--translate-y":`${D}px`,"--particle-delay":`${N.delay}ms`,color:`var(${j.colorVar})`};return s.jsx("span",{className:"firework-particle",style:P},`${j.id}-${w}-${d}`)})},`${j.id}-${d}`)},e[11]=d,e[12]=u,e[13]=y):y=e[13],h=m.map(y),e[7]=d,e[8]=m,e[9]=u,e[10]=h}else h=e[10];let S;return e[14]!==d||e[15]!==g||e[16]!==h?(S=s.jsx("div",{className:g,"aria-hidden":"true","data-burst-key":d,children:h}),e[14]=d,e[15]=g,e[16]=h,e[17]=S):S=e[17],S};function Xk(t,e){const n=Math.PI*2*e/hm;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const Jk=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]=tt.useState(i),d=tt.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(Zk)},e[4]=f):f=e[4];const p=f;let b;e[5]!==o?(b=()=>{m(),a(eC),d.current=window.setTimeout(()=>{a(tC),d.current=null},o)},e[5]=o,e[6]=b):b=e[6];const k=b;let v,g;e[7]===Symbol.for("react.memo_cache_sentinel")?(v=()=>()=>m(),g=[m],e[7]=v,e[8]=g):(v=e[7],g=e[8]),tt.useEffect(v,g);let h;return e[9]!==c.cycle||e[10]!==c.isActive||e[11]!==k?(h={isActive:c.isActive,burstKey:c.cycle,triggerFireworks:k,dismissFireworks:p},e[9]=c.cycle,e[10]=c.isActive,e[11]=k,e[12]=h):h=e[12],h};function Zk(t){return t.isActive?{...t,isActive:!1}:t}function eC(t){return{isActive:!0,cycle:t.cycle+1}}function tC(t){return t.isActive?{...t,isActive:!1}:t}const pm=l.createContext(void 0),sC=t=>{const e=it.c(10),{children:n}=t,{isActive:r,burstKey:o,triggerFireworks:i,dismissFireworks:c}=Jk();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(Qk,{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(pm.Provider,{value:d,children:[n,u]}),e[6]=n,e[7]=u,e[8]=d,e[9]=m):m=e[9],m},PN=()=>{const t=l.useContext(pm);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},nC=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`},_s=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},au=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(iC,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?nC(r.durationMs):i("memoryDebugPanel.common.idle"),e[12]=r.durationMs,e[13]=r.startedAt,e[14]=i,e[15]=f):f=e[15];let p;e[16]!==f?(p=s.jsx("div",{className:"typography-meta text-[var(--surface-muted-foreground)]",children:f}),e[16]=f,e[17]=p):p=e[17];let b;e[18]!==m||e[19]!==p?(b=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[m,p]}),e[18]=m,e[19]=p,e[20]=b):b=e[20];let k;e[21]!==i?(k=i("memoryDebugPanel.metric.metrics"),e[21]=i,e[22]=k):k=e[22];let v;e[23]!==r.entries.length||e[24]!==k?(v=s.jsx(_s,{label:k,value:r.entries.length}),e[23]=r.entries.length,e[24]=k,e[25]=v):v=e[25];let g;e[26]!==i?(g=i("memoryDebugPanel.metric.samples"),e[26]=i,e[27]=g):g=e[27];let h;e[28]!==g||e[29]!==u?(h=s.jsx(_s,{label:g,value:u}),e[28]=g,e[29]=u,e[30]=h):h=e[30];let S;e[31]!==i?(S=i("memoryDebugPanel.metric.lastUpdate"),e[31]=i,e[32]=S):S=e[32];let y;e[33]!==r.lastUpdatedAt||e[34]!==i?(y=r.lastUpdatedAt?i("memoryDebugPanel.common.live"):i("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=i,e[35]=y):y=e[35];let j;e[36]!==S||e[37]!==y?(j=s.jsx(_s,{label:S,value:y}),e[36]=S,e[37]=y,e[38]=j):j=e[38];let C;e[39]!==h||e[40]!==j||e[41]!==v?(C=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[v,h,j]}),e[39]=h,e[40]=j,e[41]=v,e[42]=C):C=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:[b,C,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(N=>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:N.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:N.count})}),s.jsx("span",{children:i("memoryDebugPanel.metric.avgValue",{value:N.avg})}),s.jsx("span",{children:i("memoryDebugPanel.metric.maxValue",{value:N.max})}),s.jsx("span",{children:i("memoryDebugPanel.metric.totalValue",{value:N.total})})]})]},N.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},rC=t=>{const e=it.c(99),{onClose:n}=t,{t:r}=gt(),[o,i]=l.useState("memory"),[c,a]=l.useState("idle"),d=nt(aC),u=Yu(lC),m=Fu(),f=fg(cC),p=on(dC),[b,k]=l.useState(uC),[v,g]=l.useState(fC);let h;e[0]!==b.entries?(h=new Map,b.entries.forEach(re=>{h.set(re.metric,re.count)}),e[0]=b.entries,e[1]=h):h=e[1];let S;e[2]!==h?(S=h.get("ui.message_list.render")??0,e[2]=h,e[3]=S):S=e[3];let y;e[4]!==h?(y=h.get("ui.message_list.render.streaming")??0,e[4]=h,e[5]=y):y=e[5];let j;e[6]!==h?(j=h.get("ui.chat_message.render")??0,e[6]=h,e[7]=j):j=e[7];let C;e[8]!==h?(C=h.get("ui.chat_message.render.streaming")??0,e[8]=h,e[9]=C):C=e[9];let N;e[10]!==h?(N=h.get("ui.chat_message.render.static_during_stream")??0,e[10]=h,e[11]=N):N=e[11];let w;e[12]!==h?(w=h.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=h,e[13]=w):w=e[13];let A;e[14]!==S||e[15]!==y||e[16]!==j||e[17]!==C||e[18]!==N||e[19]!==w?(A={messageListRender:S,messageListRenderStreaming:y,chatMessageRender:j,chatMessageRenderStreaming:C,chatMessageRenderStaticDuringStream:N,chatMessageRenderStaticOutsideActiveTurnDuringStream:w},e[14]=S,e[15]=y,e[16]=j,e[17]=C,e[18]=N,e[19]=w,e[20]=A):A=e[20];const D=A;let P,B;e[21]===Symbol.for("react.memo_cache_sentinel")?(P=()=>{const re=()=>{k(hi()),g(pi())};re();const ee=window.setInterval(re,500);return()=>window.clearInterval(ee)},B=[],e[21]=P,e[22]=B):(P=e[21],B=e[22]),l.useEffect(P,B);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 _=0,L=0,W=0;for(const re of Object.keys(f)){const ee=f[re]??[];L=L+ee.length;for(const $ of ee)$.role==="user"?W=W+1:$.role==="assistant"&&(_=_+1)}let K;e[26]!==_||e[27]!==L||e[28]!==W?(K={assistant:_,total:L,user:W},e[26]=_,e[27]=L,e[28]=W,e[29]=K):K=e[29];const x=K;let M;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=ee=>{const $=f[ee.id]??[];let de=0,Y=0;for(const Te of $)Te.role==="user"?Y=Y+1:Te.role==="assistant"&&(de=de+1);const ue=u.get(ee.id);return{id:ee.id,title:ee.title||r("memoryDebugPanel.common.untitled"),assistantMessageCount:de,messageCount:$.length,userMessageCount:Y,isStreaming:ue?.isStreaming||!1,isZombie:ue?.isZombie||!1,backgroundCount:ue?.backgroundMessageCount||0,lastAccessed:ue?.lastAccessedAt||0,isCurrent:ee.id===d}},e[36]=d,e[37]=f,e[38]=u,e[39]=r,e[40]=re):re=e[40],M=m.map(re).sort(mC),e[30]=d,e[31]=f,e[32]=u,e[33]=m,e[34]=r,e[35]=M}else M=e[35];const z=M;let U;e[41]!==f?(U=Object.keys(f),e[41]=f,e[42]=U):U=e[42];const V=U.length;let Z;e[43]===Symbol.for("react.memo_cache_sentinel")?(Z=async()=>{try{const re={generatedAt:new Date().toISOString(),ui:hi(),vscode:pi()};await navigator.clipboard.writeText(JSON.stringify(re,null,2)),a("copied")}catch{a("error")}},e[43]=Z):Z=e[43];const X=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(I,{name:"database-2",className:"h-4 w-4 text-[var(--surface-foreground)]"}):s.jsx(I,{name:"bar-chart-box",className:"h-4 w-4 text-[var(--surface-foreground)]"}),e[45]=o,e[46]=te):te=e[46];let fe;e[47]!==r?(fe=r("memoryDebugPanel.title"),e[47]=r,e[48]=fe):fe=e[48];let ge;e[49]!==fe?(ge=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:fe}),e[49]=fe,e[50]=ge):ge=e[50];let H;e[51]!==te||e[52]!==ge?(H=s.jsxs("div",{className:"flex items-center gap-2",children:[te,ge]}),e[51]=te,e[52]=ge,e[53]=H):H=e[53];let Se;e[54]!==o?(Se=o==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(lt,{size:"xs",variant:"ghost",onClick:X,children:s.jsx(I,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(lt,{size:"xs",variant:"ghost",onClick:()=>{lh(),k(hi()),g(pi())},children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[54]=o,e[55]=Se):Se=e[55];let ae;e[56]!==n?(ae=n?s.jsx(lt,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:n,children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null,e[56]=n,e[57]=ae):ae=e[57];let q;e[58]!==Se||e[59]!==ae?(q=s.jsxs("div",{className:"flex items-center gap-1",children:[Se,ae]}),e[58]=Se,e[59]=ae,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 pe;e[64]===Symbol.for("react.memo_cache_sentinel")?(pe={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[64]=pe):pe=e[64];const Ie=o==="memory"?"secondary":"ghost";let Oe;e[65]===Symbol.for("react.memo_cache_sentinel")?(Oe=()=>i("memory"),e[65]=Oe):Oe=e[65];let Me;e[66]!==r?(Me=r("memoryDebugPanel.tabs.memory"),e[66]=r,e[67]=Me):Me=e[67];let Fe;e[68]!==Ie||e[69]!==Me?(Fe=s.jsx(lt,{size:"sm",variant:Ie,className:"flex-1",onClick:Oe,children:Me}),e[68]=Ie,e[69]=Me,e[70]=Fe):Fe=e[70];const je=o==="streaming"?"secondary":"ghost";let Ne;e[71]===Symbol.for("react.memo_cache_sentinel")?(Ne=()=>i("streaming"),e[71]=Ne):Ne=e[71];let Pe;e[72]!==r?(Pe=r("memoryDebugPanel.tabs.streaming"),e[72]=r,e[73]=Pe):Pe=e[73];let se;e[74]!==je||e[75]!==Pe?(se=s.jsx(lt,{size:"sm",variant:je,className:"flex-1",onClick:Ne,children:Pe}),e[74]=je,e[75]=Pe,e[76]=se):se=e[76];let oe;e[77]!==Fe||e[78]!==se?(oe=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:pe,children:[Fe,se]}),e[77]=Fe,e[78]=se,e[79]=oe):oe=e[79];let Ee;e[80]!==o||e[81]!==V||e[82]!==c||e[83]!==d||e[84]!==f||e[85]!==x||e[86]!==u||e[87]!==z||e[88]!==m||e[89]!==D||e[90]!==b||e[91]!==r||e[92]!==p||e[93]!==v?(Ee=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(_s,{label:r("memoryDebugPanel.metric.totalMessages"),value:x.total}),s.jsx(_s,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${V} / ${Ac.MAX_SESSIONS}`}),s.jsx(_s,{label:r("memoryDebugPanel.metric.userMessages"),value:x.user}),s.jsx(_s,{label:r("memoryDebugPanel.metric.assistantMessages"),value:x.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:mg()})})]}),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:Ac.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:p})]})]}),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:z.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(I,{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(hC),currentSessionId:d,cachedSessions:Object.keys(f),messageRoleCounts:x,sessionMessageRoleCounts:z.map(pC),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:X,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(_s,{label:r("memoryDebugPanel.metric.uiMetrics"),value:b.entries.length}),s.jsx(_s,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:v.entries.length}),s.jsx(_s,{label:r("memoryDebugPanel.metric.messageListRenders"),value:D.messageListRender}),s.jsx(_s,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:D.messageListRenderStreaming}),s.jsx(_s,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:D.chatMessageRender}),s.jsx(_s,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:D.chatMessageRenderStreaming}),s.jsx(_s,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:D.chatMessageRenderStaticDuringStream}),s.jsx(_s,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:D.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(au,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:b,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),v.entries.length>0?s.jsx(au,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:v,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[80]=o,e[81]=V,e[82]=c,e[83]=d,e[84]=f,e[85]=x,e[86]=u,e[87]=z,e[88]=m,e[89]=D,e[90]=b,e[91]=r,e[92]=p,e[93]=v,e[94]=Ee):Ee=e[94];let J;return e[95]!==me||e[96]!==oe||e[97]!==Ee?(J=s.jsxs(hg,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:le,children:[me,oe,Ee]}),e[95]=me,e[96]=oe,e[97]=Ee,e[98]=J):J=e[98],J},oC=rC;function iC(t,e){return t+e.count}function aC(t){return t.currentSessionId}function lC(t){return t.sessionMemoryState}function cC(t){return t.message}function dC(t){return t.totalRequestCount}function uC(){return hi()}function fC(){return pi()}function mC(t,e){return e.lastAccessed-t.lastAccessed}function hC(t){return{id:t.id,title:t.title}}function pC(t){return{id:t.id,title:t.title,total:t.messageCount,user:t.userMessageCount,assistant:t.assistantMessageCount}}const gC=()=>{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()??"":""},xC=async()=>{const t=gC()||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")},lu="openchamber:menu-action",$a="openchamber:check-for-updates",bC=t=>{const e=nt(S=>S.openNewSessionDraft),n=he(S=>S.toggleCommandPalette),r=he(S=>S.setCommandPaletteOpen),o=he(S=>S.toggleHelpDialog),i=he(S=>S.toggleSidebar),c=he(S=>S.setSessionSwitcherOpen),a=he(S=>S.setActiveMainTab),d=he(S=>S.setSettingsDialogOpen),u=he(S=>S.setAboutDialogOpen),m=No(S=>S.checkForUpdates),{setThemeMode:f}=Br(),p=l.useRef(!1),b=l.useCallback(()=>{p.current||(p.current=!0,m().then(()=>{const{available:S,error:y}=No.getState();if(y){De.error("Failed to check for updates",{description:y});return}S||De.success("You are on the latest version")}).finally(()=>{p.current=!1}))},[m]),k=l.useCallback(()=>{Un.requestDirectoryDialog()},[]),v=l.useCallback(S=>{const y=pg();if(y.length===0)return;const j=nt.getState().currentSessionId,C=y.findIndex(A=>A.id===j);let N=S>0?0:y.length-1;C>=0&&(N=(C+S+y.length)%y.length);const w=y[N];w&&(a("chat"),c(!1),nt.getState().setCurrentSession(w.id))},[a,c]),g=l.useCallback(S=>{const{activeProjectId:y,projects:j,setActiveProject:C}=Jt.getState();if(j.length===0)return;const N=j.findIndex(D=>D.id===y);let w=S>0?0:j.length-1;N>=0&&(w=(N+S+j.length)%j.length);const A=j[w];A&&C(A.id)},[]),h=l.useCallback(S=>{switch(S){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);{const y=nt.getState(),j=as.getState().currentDirectory;e(y.currentSessionId&&j?{directoryOverride:j}:void 0)}break;case"new-worktree-session":a("chat"),c(!1),Uu();break;case"change-workspace":k();break;case"toggle-right-sidebar":{const y=as.getState().currentDirectory;if(!y)break;const j=he.getState(),C=qr(y),N=j.contextPanelByDirectory[C];N?.isOpen?j.closeContextPanel(C):N?.activeTabId?j.setActiveContextPanelTab(C,N.activeTabId):j.openContextSurface(C,"git");break}case"open-right-sidebar-git":{const y=as.getState().currentDirectory;if(!y)break;he.getState().openContextSurface(qr(y),"git");break}case"open-right-sidebar-files":{const y=as.getState().currentDirectory;if(!y)break;he.getState().openContextSurface(qr(y),"file");break}case"toggle-terminal":{const y=as.getState().currentDirectory;if(!y)break;he.getState().openContextSurface(qr(y),"terminal");break}case"toggle-terminal-expanded":{const y=as.getState().currentDirectory;if(!y)break;const j=qr(y),C=he.getState(),N=C.contextPanelByDirectory[j];(N?.isOpen?N.tabs.find(A=>A.id===N.activeTabId)?.mode:null)!=="terminal"&&C.openContextSurface(j,"terminal"),C.toggleContextPanelExpanded(j);break}case"copy":{const y=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(y)||xC();break}case"theme-light":f("light");break;case"theme-dark":f("dark");break;case"theme-system":f("system");break;case"add-selection-to-chat":xg();break;case"toggle-sidebar":i();break;case"toggle-memory-debug":t?.();break;case"go-back":as.getState().goBack();break;case"go-forward":as.getState().goForward();break;case"previous-session":v(-1);break;case"next-session":v(1);break;case"previous-project":g(-1);break;case"next-project":g(1);break;case"help-dialog":o();break;case"download-logs":{gg().catch(()=>{De.error("Failed to collect OpenCode status")});break}}},[k,g,v,t,e,u,a,c,r,d,f,n,o,i]);l.useEffect(()=>{const S=j=>{const C=j.detail;C&&h(C)},y=()=>{b()};return window.addEventListener(lu,S),window.addEventListener($a,y),()=>{window.removeEventListener(lu,S),window.removeEventListener($a,y)}},[h,b]),l.useEffect(()=>{if(typeof window>"u")return;const y=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof y!="function")return;let j=null,C=null;return y("openchamber:menu-action",N=>{const w=N?.payload;typeof w=="string"&&h(w)}).then(N=>{j=N}).catch(()=>{}),y("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event($a))}).then(N=>{C=N}).catch(()=>{}),()=>{(async()=>{try{const w=j?.();w instanceof Promise&&await w}catch{}try{const w=C?.();w instanceof Promise&&await w}catch{}})()}},[h])},yC="openchamber:tray-action",cu=5e3,vC=500,gm=20,du=()=>{if(typeof window>"u")return!1;const t=window.__OPENCHAMBER_PLATFORM__;return t==="darwin"||t==="win32"||t==="linux"},uu=()=>typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.trayEnabled!==!1,wC=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},SC=t=>{const e=Array.isArray(t.questions)?t.questions[0]:void 0;return e?.header||e?.question||"Question"},xm=(t,e)=>Rr(t,e,To.getState().ids,Zi.getState().rankById),jC=t=>{const e=t.replace(/\\/g,"/").replace(/\/+$/,""),n=e.lastIndexOf("/");return n>=0?e.slice(n+1):e},kC=(t,e,n,r,o)=>{if(!t)return"";const i=nf(n,r,t),c=e.project?.name,a=i?.label?.trim()||c?.trim()||jC(t),d=yi(t);let u=d&&o.get(d)||"";if(!u){for(const[m,f]of gr.getState().directories)if(yi(m)===d){u=f.status?.current??"";break}}if(!u)for(const m of r.values()){const f=m.find(p=>yi(p.path)===d);if(f?.branch){u=f.branch;break}}return u?`${a} · ${u}`:a},CC=()=>{const{results:t,dropdownProviderIds:e,displayMode:n}=Es.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 Du){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 p=r==="remaining"?f.remainingPercent:f.usedPercent;d.push({label:Iu(m),value:Ha(f.valueLabel,p)})}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}},NC=async()=>{try{if(Wi())return"Local OpenChamber";const t=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,e=pr();if(e&&cc(e,t))return"Local OpenChamber";const r=(await bu()).hosts.find(o=>e?cc(e,ch(o)):!1);return r?.label?.trim()?yu(r.label.trim()):"Instance"}catch{return""}},AC=()=>{const t=new Map,e=new Map,n=[],r=new Map;let o;try{o=Ei()}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(yi(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",p=t.get(d);(!p||p==="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:wC(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:SC(m),directory:i})}}return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}},DC=()=>{const t=Is.getState().activeSessions,e=new Set;t.filter(r=>r?.id&&!r.parentID).slice().sort(xm).slice(0,gm).forEach(r=>{const o=Zs(r);o&&e.add(o)});const n=new Map;for(const r of t){if(!r?.id)continue;const o=Zs(r);if(!o||!e.has(o))continue;const i=n.get(o)??[];i.push(r.id),n.set(o,i)}return n},PC=t=>{const e=AC(),n=ta.getState().index.session,r=Is.getState().activeSessions,o=new Map(e.titleById),i=new Map;for(const g of r)if(g?.id&&(g.title&&o.set(g.id,g.title),g.parentID)){const h=i.get(g.parentID)??[];h.push(g.id),i.set(g.parentID,h)}const c=g=>{const h=[],S=[...i.get(g)??[]],y=new Set;for(;S.length;){const j=S.pop();y.has(j)||(y.add(j),h.push(j),S.push(...i.get(j)??[]))}return h},a=ea.getState().statusById,d=g=>{const h=e.statusById.get(g);return h&&h!=="idle"?h:a.get(g)?.status.type??h??"idle"},u=g=>{const h=g.map(S=>d(S));return h.includes("busy")?"busy":h.includes("retry")?"retry":"idle"},m=Jt.getState().projects,f=nt.getState().availableWorktreesByProject,p=r.filter(g=>g?.id&&!g.parentID).slice().sort(xm).slice(0,gm).map(g=>{const h=[g.id,...c(g.id)],S=Zs(g)??"";return{id:g.id,title:g.title||"Untitled session",status:u(h),branch:S?e.branchByDirectory.get(S)??"":"",unseen:h.reduce((y,j)=>y+(n.unseenCount[j]??0),0),hasError:h.some(y=>n.unseenHasError[y]??!1),directory:S,subtitle:kC(S,g,m,f,e.branchByDirectory)}}),b=e.approvals.map(g=>({...g,sessionTitle:o.get(g.sessionId)||""})),k=he.getState();let v=0;if(k.dockBadgeEnabled)for(const g of r){if(!g?.id||g.parentID)continue;let h=n.unseenCount[g.id]??0;h===0&&k.notifyOnSubtasks&&(h=c(g.id).reduce((S,y)=>S+(n.unseenCount[y]??0),0)),h>0&&(v+=1)}return{sessions:p,approvals:b,instanceName:t,usage:CC(),dockBadgeCount:v}},EC=()=>{l.useEffect(()=>{if(!du()||!uu()||!Hi())return;let t=!1,e="",n=null,r="";const o=()=>{if(t)return;const N=PC(r),w=JSON.stringify(N);w!==e&&(e=w,hr("desktop_tray_update",N))};NC().then(N=>{t||(r=N,o())});const i=async()=>{const N=DC();await Promise.all([...N.entries()].map(async([w,A])=>{const D=await an.getSessionStatusForDirectory(w).catch(()=>null);t||D===null||bg(w,D,A)}))},c=()=>{t||n!==null||(n=window.setTimeout(()=>{n=null,o()},vC))},a=new Map,d=()=>{if(t)return;let N;try{N=Ei()}catch{return}const w=new Set;for(const[A,D]of N.children.entries())w.add(A),a.has(A)||a.set(A,D.subscribe(()=>c()));for(const[A,D]of a)w.has(A)||(D(),a.delete(A))};let u=null;try{u=Ei().subscribeRegistry(()=>{d(),c()})}catch{}d();const m=ta.subscribe(()=>c()),f=Is.subscribe(()=>c()),p=Jt.subscribe(()=>c()),b=nt.subscribe(()=>c()),k=gr.subscribe(()=>c()),v=he.subscribe(()=>c()),g=ea.subscribe(()=>c()),h=Zi.subscribe(()=>c()),S=To.subscribe(()=>c());i();const y=window.setInterval(()=>{i()},cu),j=Es.subscribe(()=>c());Es.getState().loadSettings().then(()=>{if(t)return;const{dropdownProviderIds:N,results:w}=Es.getState();N.length>0&&N.some(D=>!w.some(P=>P.providerId===D))&&Es.getState().fetchQuotas(N)});const C=window.setInterval(()=>{d(),o()},cu);return o(),()=>{t=!0,n!==null&&window.clearTimeout(n),window.clearInterval(C),window.clearInterval(y),m(),f(),p(),b(),k(),v(),g(),h(),S(),j(),u?.();for(const N of a.values())N();a.clear()}},[]),l.useEffect(()=>{if(!du()||!uu()||typeof window>"u")return;const e=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof e!="function")return;const n=o=>{o.type==="respond-permission"&&yg(o.sessionId,o.id,o.response).catch(()=>{De.error("Failed to respond to permission request")})};let r=null;return e(yC,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{}}},[])},TC=45e3,IC=(t,e,n=window.setInterval.bind(window),r=window.clearInterval.bind(window))=>{t();const o=n(e,TC);return()=>r(o)},MC=t=>{const e=it.c(3);let n,r;e[0]!==t?(n=()=>{if(t)return IC(RC,OC)},r=[t],e[0]=t,e[1]=n,e[2]=r):(n=e[1],r=e[2]),l.useEffect(n,r)};function RC(){vg(wg())}function OC(){Tl()}const FC="/api/notifications/stream",BC=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),LC=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}},_C=t=>{const e=it.c(3),n=t?.enabled??!0;let r,o;e[0]!==n?(r=()=>{if(!n||Wn()||!bl()||typeof window>"u"||typeof EventSource>"u")return;const i=new EventSource(wu().sse(FC));return i.onmessage=$C,()=>{i.close()}},o=[n],e[0]=n,e[1]=r,e[2]=o):(r=e[1],o=e[2]),l.useEffect(r,o)};function $C(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=he.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&BC())return;const r=LC(e);if(!r)return;Vi()?.notifications?.notifyAgentCompletion(r)}const zC=t=>{const e=it.c(14),n=he(UC),r=Jt(WC),o=nt(VC),i=t??"",c=Sg(HC);let a;e:{if(!i){a=null;break e}let b;e[0]!==o||e[1]!==i||e[2]!==r?(b=nf(r,o,i),e[0]=o,e[1]=i,e[2]=r,e[3]=b):b=e[3],a=b?.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,p;e[9]!==n||e[10]!==c||e[11]!==d?(f=()=>{if(n)return ra(b=>{b.type==="agent-memory-changed"&&c(d)})},p=[n,c,d],e[9]=n,e[10]=c,e[11]=d,e[12]=f,e[13]=p):(f=e[12],p=e[13]),l.useEffect(f,p)};function UC(t){return t.agentMemoryFeatureAvailable&&t.agentMemoryToolEnabled}function WC(t){return t.projects}function VC(t){return t.availableWorktreesByProject}function HC(t){return t.load}const fu="pwa-install-toast-shown",mu="pwa-install-toast-dismissed",KC=()=>{const t=it.c(6),{browserTab:e}=rx(),{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"||!bl()||!e)return;let d=null,u=null;const m=()=>{u!==null&&(De.dismiss(u),u=null)},f=async()=>{if(!d)return;const k=d;d=null,m(),await k.prompt();const{outcome:v}=await k.userChoice;v==="accepted"&&De.success(r.current("pwa.installPrompt.started"))},p=k=>{const v=k;if(typeof v.prompt!="function")return;v.preventDefault(),d=v;const g=Qr(),h=dh();ox({dismissed:g.getItem(mu),sessionShown:h.getItem(fu),hasActiveToast:u!==null})&&(h.setItem(fu,"true"),u=De.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:()=>{Qr().setItem(mu,"true"),m()}}}))},b=()=>{d=null,m(),De.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",p),window.addEventListener("appinstalled",b),()=>{m(),window.removeEventListener("beforeinstallprompt",p),window.removeEventListener("appinstalled",b)}},a=[e],t[3]=e,t[4]=c,t[5]=a):(c=t[4],a=t[5]),l.useEffect(c,a)},GC=({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),[p,b]=l.useState(null),[k,v]=l.useState(!1);l.useCallback(async()=>{},[p,d,r,n]),l.useEffect(()=>{if(!t)return;(async()=>{try{const S=await bs("/api/system/info");if(S.ok){const y=await S.json();if(typeof y.openchamberVersion=="string"&&y.openchamberVersion.trim()){i(y.openchamberVersion);return}}}catch{}i(await jg())})()},[t]),l.useEffect(()=>{if(!t)return;let h=!1;return(async()=>{try{const y=await bs("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!y.ok)return;const j=await y.json().catch(()=>null),C=typeof j?.currentVersion=="string"?j.currentVersion.trim():"";!h&&C&&a(C)}catch{}})(),()=>{h=!0}},[t]),l.useEffect(()=>{{b(null),v(!1);return}},[t,r]);const g=o;return s.jsx($s,{open:t,onOpenChange:e,children:s.jsx(zs,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(Bu,{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:[g&&s.jsx("p",{children:n("aboutDialog.openChamberVersionLabel",{version:g})}),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(I,{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(I,{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(I,{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")})]})})})},hu=t=>{if(!(typeof window>"u")){if(t){window.location.href="openchamber://focus/mcp-auth";return}window.location.replace("/")}},za=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},qC=(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},YC=()=>{const t=kg(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=za(a,"code"),u=Cg(a),m=Ng(a),f=za(a,"error"),p=za(a,"error_description");if(f){m&&bs(`/api/mcp/auth/pending?state=${encodeURIComponent(m)}`,{method:"DELETE"}).catch(()=>{}),n("error"),c(p??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 b=u,k=!1;if(m){const v=await bs(`/api/mcp/auth/pending?state=${encodeURIComponent(m)}`);if(v.ok){const g=await v.json().catch(()=>null);k=g?.origin===Ag,o(k),!b&&g?.name?.trim()&&(b={name:g.name.trim(),directory:typeof g.directory=="string"&&g.directory.trim()?g.directory.trim():null})}}if(!b?.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(b.name,d,b.directory),m&&await bs(`/api/mcp/auth/pending?state=${encodeURIComponent(m)}`,{method:"DELETE"}).catch(()=>{}),n("success"),k&&hu(!0),c("Authorization completed. You can close this tab and return to OpenChamber.")}catch(b){m&&await bs(`/api/mcp/auth/pending?state=${encodeURIComponent(m)}`,{method:"DELETE"}).catch(()=>{}),n("error"),c(qC(b,"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:Dg,children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"}),s.jsx("p",{className:xe("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:()=>hu(r),children:"Return to OpenChamber"})})]})})},pu=pn(()=>hn(()=>import("./OnboardingScreen-CenIeD4v.js"),__vite__mapDeps([143,1,2,4,5,6,7,8,9,3,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}))),QC=()=>{const t=it.c(3),e=he(sN),n=he(nN);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(GC,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},XC=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 p;return e[18]!==u||e[19]!==f?(p=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]=p):p=e[20],p},gu=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",JC=()=>{if(typeof window>"u"||!Cx())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}},ZC=()=>typeof window>"u"?!1:window.location.pathname===Mg,eN=t=>{const e=it.c(25),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:o}=t,i=as(rN),c=nt(oN),a=nt(iN),d=qi(),u=l.useRef(null);let m;e[0]!==n.directory?(m=gu(n.directory),e[0]=n.directory,e[1]=m):m=e[1];const f=m;let p;e[2]!==i?(p=gu(i),e[2]=i,e[3]=p):p=e[3];const b=p;let k,v;if(e[4]!==b||e[5]!==c||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==f||e[9]!==r||e[10]!==a||e[11]!==d?(k=()=>{if(r||f&&b!==f)return;const C=`${f}
921
+ ${n.sessionId}`;u.current===C&&c||(u.current=C,a(n.sessionId,n.directory),d.ensureSessionRenderable(n.sessionId,!0))},v=[b,c,n.directory,n.sessionId,f,r,a,d],e[4]=b,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]=k,e[13]=v):(k=e[12],v=e[13]),l.useEffect(k,v),f&&b!==f)return null;let g;e[14]!==o?(g=s.jsx(rf,{embeddedBackgroundWorkEnabled:o}),e[14]=o,e[15]=g):g=e[15];let h;e[16]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(hf,{}),e[16]=h):h=e[16];let S;e[17]!==o||e[18]!==n.allowPromptingSubagentSessions||e[19]!==n.readOnly?(S=s.jsx(Qa,{active:o,messagesEnabled:!0,readOnly:n.readOnly,initialAllowPromptingSubagentSessions:n.allowPromptingSubagentSessions}),e[17]=o,e[18]=n.allowPromptingSubagentSessions,e[19]=n.readOnly,e[20]=S):S=e[20];let y;e[21]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(of,{}),e[21]=y):y=e[21];let j;return e[22]!==g||e[23]!==S?(j=s.jsxs(s.Fragment,{children:[g,h,S,y]}),e[22]=g,e[23]=S,e[24]=j):j=e[24],j};function tN({apis:t}){l.useEffect(()=>{uh("App:mounted"),fh()&&console.info("[startup-trace] enabled. Run console.table(window.__OPENCHAMBER_STARTUP_TRACE__) after startup.")},[]);const e=Yt(q=>q.initializeApp),n=Yt(q=>q.isInitialized),r=Yt(q=>q.isConnected),o=Yt(q=>q.providers.length),i=Yt(q=>q.agents.length),c=Yt(q=>q.loadProviders),a=Yt(q=>q.loadAgents),d=nt(q=>q.error),u=nt(q=>q.clearError),m=as(q=>q.currentDirectory),f=as(q=>q.setDirectory),p=as(q=>q.isSwitchingDirectory),[b,k]=l.useState(!1),v=Fr(q=>q.refreshStatus),[g,h]=l.useState(()=>t.runtime.isVSCode),[S,y]=l.useState(!1),[j,C]=l.useState(!1),[N,w]=l.useState(0),[A,D]=l.useState(0),[P,B]=l.useState(!1),F=he(q=>q.wideChatLayoutEnabled),E=he(q=>q.mobileKeyboardMode),_=l.useMemo(()=>Wn(),[]),L=wl(q=>q.setPlanModeEnabled),[W,K]=l.useState(()=>dc()),[x,M]=l.useState(()=>{const q=uc();return q!==null?fc({isDesktopShell:!0,bootOutcome:q}):null}),z=l.useRef(!1),U=l.useMemo(()=>JC(),[]),V=!U||S,Z=l.useMemo(()=>ZC(),[]);l.useEffect(()=>(mc(b),()=>{mc(!1)}),[b]),l.useEffect(()=>{mh(E)},[E]),l.useEffect(()=>{h(t.runtime.isVSCode)},[t.runtime.isVSCode]),l.useEffect(()=>Ki(q=>{ix(q),D(me=>me+1),C(!1),w(me=>me+1)}),[]);const X=Dc(q=>{const me=Ms();return Object.values(q.runsByOriginalSessionID).filter(pe=>pe.status==="running"&&pe.runtimeKey===me).map(pe=>`${pe.originalSessionID}:${pe.phase}:${pe.lastForwardedMessageID??""}:${pe.expectedAssistantParentID??""}`).sort().join("|")});l.useEffect(()=>{if(U)return;const q=Ms(),me=Object.values(Dc.getState().runsByOriginalSessionID).filter(pe=>pe.status==="running"&&pe.runtimeKey===q);for(const pe of me)Pg(pe.originalSessionID)},[X,U,A]),l.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",F),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[F]),l.useEffect(()=>(hc(t),()=>hc(null)),[t]),l.useEffect(()=>{U||v(t.github,{force:!0})},[t.github,U,v]),Eg();const le=W==="valid",te=x?.screen==="main";l.useEffect(()=>{if(!hh({isDesktopShell:_,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)},[_,n,le,te]),l.useEffect(()=>{if(!_||W!=="malformed")return;const q=document.getElementById("initial-loading");q&&(q.textContent="Desktop startup failed — please restart the app.")},[_,W]),l.useEffect(()=>{if(_)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)},[_,n]),l.useEffect(()=>{let q=!1;return(async()=>{const pe=await bs("/health",{method:"GET"}).catch(()=>null);if(!pe||!pe.ok||q)return;const Ie=await pe.json().catch(()=>null);if(!Ie||q)return;const Oe=Ie.planModeExperimentalEnabled;L(Oe===!0||Oe===1||Oe==="1"||Oe==="true")})(),()=>{q=!0}},[L]),l.useEffect(()=>{g||e()},[e,g]),l.useEffect(()=>{if(g||n)return;let q=!0,me,pe=0;const Ie=10,Oe=1e3,Me=async()=>{if(!q)return;if(pe>=Ie){C(!0);return}const Fe=Yt.getState();if(Fe.isInitialized){C(!1);return}pe+=1,await Fe.initializeApp();const je=Yt.getState();if(!q)return;if(je.isInitialized){C(!1);return}if(pe>=Ie){C(!0);return}const Ne=Math.min(Oe*Math.pow(2,pe-1),16e3);me=setTimeout(Me,Ne)};return me=setTimeout(Me,Oe),()=>{q=!1,me&&clearTimeout(me)}},[N,n,g]),l.useEffect(()=>{n&&C(!1)},[n]),l.useEffect(()=>{if(!j)return;const q=document.getElementById("initial-loading");q&&(q.classList.add("fade-out"),setTimeout(()=>{q.remove()},300))},[j]),l.useEffect(()=>{if(g||!r||o>0&&i>0)return;let q=!0,me=0;const pe=15,Ie=async()=>{const Me=Yt.getState();if(!(Me.providers.length>0&&Me.agents.length>0))try{Me.providers.length===0&&await c({source:"startupRecovery"}),Yt.getState().agents.length===0&&await a({source:"startupRecovery"})}catch{}};Ie();const Oe=setInterval(()=>{if(q){if(++me>=pe){clearInterval(Oe);return}Ie()}},2e3);return()=>{q=!1,clearInterval(Oe)}},[r,g,a,c,o,i]),l.useEffect(()=>{p||g||r&&an.setDirectory(m)},[m,p,r,g]),l.useEffect(()=>{if(!U||typeof window>"u")return;const q=Ie=>{y(Ie?.visible===!0)},me=Ie=>{if(Ie.origin!==window.location.origin||Ie.source!==window.parent)return;const Oe=Ie.data;Oe?.type===bf&&q(Oe.payload)},pe=window;return pe.__openchamberSetEmbeddedVisibility=q,window.addEventListener("message",me),kx(),()=>{window.removeEventListener("message",me),pe.__openchamberSetEmbeddedVisibility===q&&delete pe.__openchamberSetEmbeddedVisibility}},[U]),l.useEffect(()=>{!U?.directory||g||m!==U.directory&&f(U.directory,{showOverlay:!1})},[m,U,g,f]),l.useEffect(()=>{if(!U||typeof window>"u")return;const q=me=>{me.storageArea===window.localStorage&&me.key==="ui-store"&&he.persist.rehydrate()};return window.addEventListener("storage",q),()=>{window.removeEventListener("storage",q)}},[U]),l.useEffect(()=>{if(typeof window>"u")return;const q=me=>{const pe=me.detail,Ie=typeof pe?.sessionId=="string"?pe.sessionId.trim():"";if(!Ie)return;const Oe=typeof pe?.directory=="string"&&pe.directory.trim().length>0?pe.directory.trim():null;he.getState().setActiveMainTab("chat"),nt.getState().setCurrentSession(Ie,Oe)};return window.addEventListener("openchamber:open-session",q),()=>window.removeEventListener("openchamber:open-session",q)},[]),l.useEffect(()=>{if(typeof window>"u")return;const q=()=>{hr("desktop_open_draft_mini_chat_window",{directory:"",projectId: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=nt.getState().currentSessionId;me&&Lu(me)};return window.addEventListener("focus",q),()=>window.removeEventListener("focus",q)},[]),l.useEffect(()=>{if(typeof window>"u")return;const q=me=>{const pe=me.detail,Ie=typeof pe?.directory=="string"&&pe.directory.trim().length>0?pe.directory.trim():null,Oe=typeof pe?.projectId=="string"&&pe.projectId.trim().length>0?pe.projectId.trim():null,Me=!!(Ie||Oe);he.getState().setActiveMainTab("chat"),he.getState().setSessionSwitcherOpen(!1),nt.getState().openNewSessionDraft({target:Me?"project":"chat",selectedProjectId:Me?Oe:null,directoryOverride:Me?Ie:null,preserveDirectoryOverride:!!Ie})};return window.addEventListener("openchamber:open-draft-session",q),()=>window.removeEventListener("openchamber:open-draft-session",q)},[]),l.useEffect(()=>{typeof window>"u"||!n||p||z.current||(z.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,p]),Tg({enabled:V}),_C({enabled:V}),zC(m||null),KC(),Ig(),ax();const fe=l.useCallback(()=>{k(q=>!q)},[]);bC(fe),EC(),MC(!U),l.useEffect(()=>{if(U)return;const q=me=>{Tu(me)&&me.shiftKey&&!me.altKey&&(me.code==="KeyD"||me.key.toLowerCase()==="d")&&(me.preventDefault(),k(Ie=>!Ie))};return window.addEventListener("keydown",q,!0),()=>window.removeEventListener("keydown",q,!0)},[U]),l.useEffect(()=>{U||d&&setTimeout(()=>u(),5e3)},[u,U,d]),l.useEffect(()=>{if(!_||W!=="not-injected")return;let q=!1,me=0;const pe=200,Ie=2e3,Oe=50,Me=()=>{if(q)return;me++;const Fe=dc();if(Fe!=="not-injected"){if(q=!0,K(Fe),Fe==="valid"){const Ne=uc();Ne&&M(fc({isDesktopShell:!0,bootOutcome:Ne}))}return}const je=Math.min(pe*Math.pow(1.1,me),Ie);if(me>=Oe){const Ne=document.getElementById("initial-loading");Ne&&!Ne.textContent?.includes("taking longer")&&(Ne.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(Me,je)};return window.setTimeout(Me,pe),()=>{q=!0}},[_,W]);const ge=l.useCallback(async()=>{if(ph({isDesktopShell:Wn(),isDesktopLocalOriginActive:Wi()})){await gh();return}window.location.reload()},[]),H=l.useCallback(async()=>{if(!P){C(!1),B(!0);try{await Yt.getState().initializeApp()}finally{B(!1)}Yt.getState().isInitialized||w(q=>q+1)}},[P]),Se=q=>{if(q.screen==="recovery")return q.variant};if(_&&x&&x.screen!=="main"){if(x.screen==="chooser")return s.jsx(us,{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(pu,{mode:"first-launch",localAvailable:x.localAvailable!==!1,onCliAvailable:ge,onChooseRemote:()=>{}})})})});const q=Se(x),me=x.screen==="recovery"&&"url"in x?x.url:void 0;return s.jsx(us,{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(pu,{mode:"recovery",recoveryVariant:q,recoveryHostUrl:me,recoveryHostLabel:void 0,localAvailable:x.localAvailable!==!1,onCliAvailable:ge})})})})}if(U)return s.jsx(us,{children:s.jsx(Pc,{sdk:an.getSdkClient(),directory:m||"",children:s.jsx(Ec,{apis:t,children:s.jsx(Ya,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:"h-full text-foreground bg-background",children:[s.jsx(eN,{embeddedSessionChat:U,isVSCodeRuntime:g,embeddedBackgroundWorkEnabled:V}),s.jsx(Tc,{})]})})})},A)});if(Z)return s.jsx(us,{children:s.jsx(YC,{})});if(j&&!n&&!g&&!U)return s.jsx(us,{children:s.jsx(XC,{onRetry:()=>{H()},isRetrying:P})});const ae=!n&&!_;return s.jsx(us,{children:s.jsx(Pc,{sdk:an.getSdkClient(),directory:m||"",children:s.jsx(Ec,{apis:t,children:s.jsx(sC,{children:s.jsx(Ya,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:_?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(rf,{embeddedBackgroundWorkEnabled:V}),s.jsx(hf,{}),s.jsx(qk,{}),s.jsx(of,{}),s.jsx(Tc,{}),!ae&&s.jsxs(s.Fragment,{children:[s.jsx(lx,{}),s.jsx(QC,{}),b&&s.jsx(oC,{onClose:()=>k(!1)})]})]})})})})},A)})}function sN(t){return t.isAboutDialogOpen}function nN(t){return t.setAboutDialogOpen}function rN(t){return t.currentDirectory}function oN(t){return t.currentSessionId}function iN(t){return t.setCurrentSession}const aN=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();Rg();xh().then(()=>{Promise.all([bh(),Og()]).catch(t=>{console.error("[main] settings init failed:",t)}),Fg(),Bg(),Lg()}).catch(t=>{console.error("[main] appearance init failed:",t)});const bm=document.getElementById("root");if(!bm)throw new Error("Root element not found");Gm.createRoot(bm).render(s.jsx(tt.StrictMode,{children:s.jsx(_g,{children:s.jsx($g,{children:s.jsx(zg,{children:s.jsx(Ug,{children:s.jsx(tN,{apis:aN})})})})})}));const EN=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));export{Xb as W,PN as a,Qb as b,uy as d,Lf as g,DN as h,EN as m,zb as u,Bf as v};