@openchamber/web 1.18.0 → 1.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/assets/{DiagramView-1-LZVuzn.js → DiagramView-DZmf30ko.js} +1 -1
  2. package/dist/assets/{FilesView-BDRX8vU2.js → FilesView-cJPeFhDe.js} +6 -6
  3. package/dist/assets/{MarkdownRendererImpl-fZSdR7PD.js → MarkdownRendererImpl-DZezL90a.js} +1 -1
  4. package/dist/assets/{OnboardingScreen-D81UrlA4.js → OnboardingScreen-ChYr0xqs.js} +1 -1
  5. package/dist/assets/{SessionSwitcherDropdown-cSK3t3TR.js → SessionSwitcherDropdown-BV7FfPbT.js} +1 -1
  6. package/dist/assets/{SettingsWindow-CozowJLm.js → SettingsWindow-UybkBD1p.js} +1 -1
  7. package/dist/assets/{contextPanelEmbeddedChat-CQYNvKbk.js → contextPanelEmbeddedChat-DW3atb4h.js} +1 -1
  8. package/dist/assets/{de-C2n4oo1Z.js → de-rVJ-hXrd.js} +3 -3
  9. package/dist/assets/es-D7ZyOToq.js +15 -0
  10. package/dist/assets/{fr-DDFUp5jS.js → fr-hl5i-ZI0.js} +2 -2
  11. package/dist/assets/{index-BCCcokur.css → index-CL9MYe8V.css} +1 -1
  12. package/dist/assets/{ja-B7SxobKm.js → ja-DqakdvOp.js} +2 -2
  13. package/dist/assets/{ko-CWGq93SO.js → ko-dNl8A3Xf.js} +2 -2
  14. package/dist/assets/main-B5TIsU2y.js +209 -0
  15. package/dist/assets/{main-Cts0BwVk.js → main-_m6HD9-a.js} +2 -2
  16. package/dist/assets/{markdownCore-BqzEkymd.js → markdownCore-DpT1vbbv.js} +2 -2
  17. package/dist/assets/{miniChat-ChuQD2KK.js → miniChat-wYb8p9vG.js} +2 -2
  18. package/dist/assets/{mobile-c-CRD1Cz.js → mobile-ExXAVUcv.js} +2 -2
  19. package/dist/assets/{pl-DZmyxLo7.js → pl-C5HQx1Hf.js} +3 -3
  20. package/dist/assets/pt-BR-CNCoBDAM.js +15 -0
  21. package/dist/assets/{renderElectronMiniChatApp-9uaZAJjw.js → renderElectronMiniChatApp-DPDzIT8W.js} +2 -2
  22. package/dist/assets/{renderMobileApp-Dm1tmU2a.js → renderMobileApp-CzWvxR9e.js} +3 -3
  23. package/dist/assets/runtimeEndpointReset-DKzVWH1w.js +180 -0
  24. package/dist/assets/uk-Bn-3AMpk.js +15 -0
  25. package/dist/assets/{useAppFontEffects-pyTMaGQu.js → useAppFontEffects-DdvGxoPX.js} +133 -133
  26. package/dist/assets/zh-CN-BCwvQpZm.js +15 -0
  27. package/dist/assets/zh-TW-TRHrkN9l.js +15 -0
  28. package/dist/index.html +4 -4
  29. package/dist/mini-chat.html +3 -3
  30. package/dist/mobile.html +3 -3
  31. package/package.json +2 -2
  32. package/server/lib/openchamber-control/DOCUMENTATION.md +9 -1
  33. package/server/lib/openchamber-sessions/routes.js +117 -4
  34. package/server/lib/openchamber-sessions/routes.test.js +129 -16
  35. package/server/lib/opencode/DOCUMENTATION.md +2 -0
  36. package/server/lib/opencode/proxy.js +21 -3
  37. package/server/lib/small-model/DOCUMENTATION.md +11 -4
  38. package/server/lib/small-model/call.js +19 -3
  39. package/server/lib/small-model/call.test.js +9 -2
  40. package/server/lib/small-model/index.js +10 -1
  41. package/server/lib/small-model/index.test.js +20 -1
  42. package/server/lib/walkthrough/DOCUMENTATION.md +23 -0
  43. package/server/lib/walkthrough/index.js +17 -0
  44. package/server/lib/walkthrough/reproduce-2607.test.js +148 -0
  45. package/server/opencode-proxy.test.js +83 -0
  46. package/dist/assets/es-DP7jRKkr.js +0 -15
  47. package/dist/assets/main-Cqfcxvqq.js +0 -209
  48. package/dist/assets/pt-BR-BKR5oHQ7.js +0 -15
  49. package/dist/assets/runtimeEndpointReset-DL5z84w2.js +0 -180
  50. package/dist/assets/uk-D7oAI_Wc.js +0 -15
  51. package/dist/assets/zh-CN-Ddjz1_9w.js +0 -15
  52. package/dist/assets/zh-TW-D3X01YXj.js +0 -15
  53. /package/dist/assets/{index-ChZvuURI.js → index-DjZ4W8hy.js} +0 -0
@@ -1,209 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/DiagramView-1-LZVuzn.js","assets/vendor-react-BUCujlKS.js","assets/vendor-scheduler-7OC5HNn7.js","assets/index-ChZvuURI.js","assets/vendor-vite-runtime-DD1OZmLC.js","assets/vendor-opencode-sdk-BJ73u-bH.js","assets/vendor-zustand-BAGL70zf.js","assets/index-BCCcokur.css","assets/useAppFontEffects-pyTMaGQu.js","assets/vendor-simplewebauthn-browser-VDA66rT_.js","assets/vendor-base-ui-BuzaMvKv.js","assets/vendor-floating-ui-utils-BzXdqYpP.js","assets/vendor-floating-ui-dom-WyXykhNi.js","assets/vendor-floating-ui-core-CXmKXOXc.js","assets/vendor-floating-ui-react-dom-DKpLs02S.js","assets/vendor-use-sync-external-store-D6wYuSt-.js","assets/contextPanelEmbeddedChat-CQYNvKbk.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-pierre-diffs-B1TeaSIY.js","assets/vendor-lru_map-Tstukz9J.js","assets/vendor-pierre-theming-D_y07OK2.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-diff-C3JhlQdm.js","assets/vendor-shiki-DuWDB27E.js","assets/vendor-shikijs-engine-oniguruma-DPWuIF1G.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/vendor-tanstack-react-virtual-g05Cx3z9.js","assets/vendor-tanstack-virtual-core-Dubg10g5.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-CTJVwiVf.js","assets/vendor-lezer-common-B3-cUCR_.js","assets/vendor-codemirror-state-CNWM3Q8V.js","assets/vendor-marijn-find-cluster-break-DXwl3gUT.js","assets/vendor-codemirror-view-DSzLbZiS.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-B3NPxZ-7.js","assets/vendor-lezer-javascript-D7Tj24ot.js","assets/vendor-lezer-lr-bhwg1HMg.js","assets/vendor-codemirror-autocomplete-CWhyzlcb.js","assets/vendor-codemirror-lang-json-Bty2AtQK.js","assets/vendor-lezer-json-Iaex0UN-.js","assets/vendor-codemirror-lang-css-D_jk9hVN.js","assets/vendor-lezer-css-C5xB6jxd.js","assets/vendor-codemirror-lang-html-Dxy5thAH.js","assets/vendor-lezer-html-C0I1p52t.js","assets/vendor-codemirror-lang-markdown-dH8tblNV.js","assets/vendor-lezer-markdown-C6g-d6P3.js","assets/vendor-codemirror-language-data-o9e2Fm3f.js","assets/vendor-codemirror-lang-python-PETDP1TX.js","assets/vendor-lezer-python-CvuFxeZl.js","assets/vendor-codemirror-legacy-modes-DBXLFsoH.js","assets/vendor-codemirror-commands-eyb3xW_0.js","assets/vendor-framer-motion-CRSgBxjL.js","assets/vendor-motion-dom-DJLgZh4Q.js","assets/vendor-motion-utils-BGh8QBgx.js","assets/vendor-sonner-DFyL3AvE.js","assets/vendor-tailwind-merge-CPcsbTWB.js","assets/vendor-fuse.js-Dw8P0qyA.js","assets/FilesView-BDRX8vU2.js","assets/runtimeEndpointReset-DL5z84w2.js","assets/vendor-yaml-3778uTud.js","assets/vendor-codemirror-search-8kyQdB3f.js","assets/vendor-replit-codemirror-vim-D0xSkRWg.js","assets/vendor-qrcode-DTJ12-WC.js","assets/vendor-dijkstrajs-COg3n3zL.js","assets/vendor-ghostty-web-CfpAcbEe.js","assets/vendor-react-drawio-Ct3Q0DsD.js","assets/SettingsWindow-CozowJLm.js","assets/OnboardingScreen-D81UrlA4.js"])))=>i.map(i=>d[i]);
2
- import{f as nt,j as s,R as a,r as $e,h as gh}from"./vendor-react-BUCujlKS.js";import{w as hr,x as ua,O as kc,D as xh,y as bh,z as Wu,r as hs,m as fa,u as Re,A as yh,B as ir,C as wh,E as Vt,F as sr,G as ma,H as Uu,e as Cr,I as Qi,J as Hu,K as Ku,L as Fl,M as Ar,N as Xi,P as vh,a as $n,Q as jh,R as Sh,S as kh,T as Gu,l as jr,q as Fn,U as Nh,V as Ch,W as qu,X as ha,Y as xo,k as js,Z as Ol,_ as dl,o as Yu,d as yo,$ as Oi,a0 as Li,a1 as Ah,a2 as Dh,a3 as Ph,a4 as Ih,a5 as Nc,a6 as Cc,a7 as Ac,a8 as Dc,a9 as Rh,n as Pc,aa as Mh,ab as Th,ac as Eh,t as Fh,v as Oh}from"./index-ChZvuURI.js";import{_ as Oo}from"./vendor-vite-runtime-DD1OZmLC.js";import{I,f as ft,g as De,aI as is,aJ as rr,t as fe,aK as qs,aL as Ln,aM as Ys,aN as Qs,G as co,R as _n,aO as Pr,o as Io,aP as Ic,aQ as Nt,aR as Ct,aS as At,aT as Qu,aU as ii,aV as Lh,v as et,aW as Bh,aX as $h,aY as Xu,aZ as _h,a_ as Bi,a$ as zh,b0 as Vh,F as Ju,b1 as Wh,P as ai,b2 as Ji,b3 as _r,q as li,s as Zu,k as Ll,b4 as ef,b5 as So,i as ts,b6 as Uh,x as tf,u as pn,b as ms,af as Dr,b7 as sf,b8 as Bl,b9 as Hh,ba as Kh,bb as $l,bc as pa,bd as ul,ag as _l,be as ga,bf as ro,bg as Ts,bh as Es,bi as Hs,bj as $s,bk as Ks,bl as ar,B as He,bm as nf,bn as Ea,a8 as Cs,C as Gh,bo as qh,bp as Yh,a7 as ko,bq as Qh,br as Xh,bs as Jh,a6 as zl,a0 as tn,a9 as Lo,bt as rf,Y as Wr,_ as Vl,Z as Bo,$ as Wl,h as Zh,bu as Kn,bv as ep,bw as tp,bx as sp,by as oo,bz as fl,bA as On,bB as np,bC as rp,bD as op,bE as Ro,bF as lo,bG as xa,bH as ba,bI as ya,bJ as wa,bK as va,bL as kr,bM as Nr,bN as ip,bO as ap,L as or,bP as lp,bQ as cp,bR as dp,bS as up,bT as fp,bU as Ul,bV as mp,bW as hp,bX as pp,bY as gp,bZ as xp,b_ as bp,b$ as yp,c0 as gn,c1 as xn,c2 as sn,c3 as bn,c4 as bs,c5 as wp,c6 as ao,c7 as vp,c8 as jp,c9 as ja,ca as Sp,cb as kp,cc as Np,cd as pi,a5 as Cp,V as Sa,ce as Ap,cf as Fa,cg as ci,ch as Dp,ci as wo,cj as Rc,M as ka,ck as Hl,cl as Kl,cm as of,cn as Pp,co as Ip,cp as gi,cq as Rp,cr as Oa,cs as af,ct as Mp,O as Gl,cu as ei,c as di,d as Na,U as lf,cv as cf,cw as Tp,r as Bn,cx as Ep,S as ql,cy as df,cz as Fp,cA as Op,cB as Mc,cC as uf,cD as Lp,cE as ff,e as Mo,cF as Zi,cG as Bp,cH as Tc,cI as Vr,cJ as ml,cK as $p,cL as _p,cM as Ec,cN as Nn,cO as mf,cP as zp,cQ as $i,cR as Vp,J as Yl,H as Ql,K as Xl,cS as Jl,cT as hl,cU as hf,cV as Wp,cW as Up,D as Hp,cX as Kp,cY as Fc,cZ as Gp,c_ as qp,c$ as pf,d0 as Yp,d1 as Qp,d2 as Xp,d3 as Jp,d4 as Oc,d5 as Zp,y as eg,d6 as gf,z as tg,d7 as Lc,d8 as sg,d9 as ng,da as rg,db as og,dc as ig,dd as ag,de as Ca,a as Aa,df as lg,dg as La,A as ea,dh as cg,di as dg,dj as Bc,ap as pl,dk as xf,W as ug,X as fg,as as mg,dl as hg,E as pg,dm as gg,dn as xg,dp as bf,dq as yf,dr as wf,ds as bg,dt as yg,du as wg,dv as vg,dw as jg,dx as Sg,dy as kg,dz as Ng,dA as Cg,dB as ta,dC as Ag,dD as $c,dE as Dg,dF as Pg,dG as Ig,dH as Da,dI as Rg,dJ as _c,dK as Mg,dL as Tg,dM as Eg,dN as Fg,dO as Og,dP as Lg,dQ as Bg,dR as $g,dS as _i,dT as _g,dU as zg,dV as zc,dW as Vg,aj as Wg,ak as Ug,al as Hg,an as Vc,ao as Wc,aq as vf,ar as jf,aD as Kg,aE as Gg,aF as qg,aG as Yg,aH as Qg,az as Xg,aA as Jg,aB as Zg,aC as ex}from"./useAppFontEffects-pyTMaGQu.js";import{s as Uc,t as gs,v as tx,w as Hc,x as wr,y as sx,z as Ba,d as ui,U as sa,B as na,E as To,F as xi,G as Eo,g as Sf,i as kf,a as Us,b as nx,Q as Nf,H as rx,I as ox,J as ix,M as gl,K as Cf,P as Zl,L as ax,R as en,V as Af,W as lx,C as cx,c as dx,X as bi,Y as Df,Z as ux,_ as Pf,$ as If,a0 as Rf,e as Mf,o as Tf,T as Ef,a1 as fx,a2 as mx,a3 as hx,a4 as Ff,u as ti,N as px,D as gx,a5 as xx,a6 as Kc,a7 as bx,k as yx,q as wx,n as xl,a8 as vx,a9 as jx,f as Sx,aa as kx,ab as Nx,ac as Cx,j as Ax,l as Dx,O as Of,m as Px,ad as Ix}from"./runtimeEndpointReset-DL5z84w2.js";import{u as Lf,S as Rx,C as Mx,W as Bf}from"./SessionSwitcherDropdown-cSK3t3TR.js";import{u as Xr,F as $f}from"./FilesView-BDRX8vU2.js";import{c as $o,u as nr,d as _f,p as Tx}from"./vendor-zustand-BAGL70zf.js";import{p as Ex,t as Fx,a as Ox,b as Lx}from"./vendor-pierre-diffs-B1TeaSIY.js";import{g as Bx,E as $x,b as _x,i as zx}from"./contextPanelEmbeddedChat-CQYNvKbk.js";import{f as ra,h as No,T as Vx,M as Wx,D as oa,j as ia,P as bl,b as Ux,d as Hx,k as yl,i as Kx}from"./vendor-dnd-kit-core-BZknOX2w.js";import{a as zf,S as wl,v as vl,u as ec,s as Gx}from"./vendor-dnd-kit-sortable-CsEagZ81.js";import{C as tc}from"./vendor-dnd-kit-utilities-B_MdXhJC.js";import{u as qx}from"./vendor-tanstack-react-virtual-g05Cx3z9.js";import{M as Gc,a as qc,b as Yc,C as Yx,c as Qx,d as Xx,S as Jx,e as Zx,f as eb}from"./vendor-base-ui-BuzaMvKv.js";import{d as Vf}from"./vendor-cron-parser-CUcP7OfX.js";import{u as Qc,a as Xc,m as Jc}from"./vendor-framer-motion-CRSgBxjL.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-CTJVwiVf.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-CNWM3Q8V.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-DSzLbZiS.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-B3NPxZ-7.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-CWhyzlcb.js";import"./vendor-codemirror-lang-json-Bty2AtQK.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-D_jk9hVN.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-Dxy5thAH.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-dH8tblNV.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-o9e2Fm3f.js";import"./vendor-codemirror-lang-python-PETDP1TX.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-legacy-modes-DBXLFsoH.js";import"./vendor-codemirror-commands-eyb3xW_0.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-yaml-3778uTud.js";import"./vendor-codemirror-search-8kyQdB3f.js";import"./vendor-replit-codemirror-vim-D0xSkRWg.js";import"./vendor-qrcode-DTJ12-WC.js";import"./vendor-dijkstrajs-COg3n3zL.js";import"./vendor-ghostty-web-CfpAcbEe.js";import"./vendor-react-drawio-Ct3Q0DsD.js";import"./vendor-lru_map-Tstukz9J.js";import"./vendor-pierre-theming-D_y07OK2.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-diff-C3JhlQdm.js";import"./vendor-shiki-DuWDB27E.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-floating-ui-utils-BzXdqYpP.js";import"./vendor-floating-ui-dom-WyXykhNi.js";import"./vendor-floating-ui-core-CXmKXOXc.js";import"./vendor-floating-ui-react-dom-DKpLs02S.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-luxon-BZ0puJYg.js";import"./vendor-motion-dom-DJLgZh4Q.js";import"./vendor-motion-utils-BGh8QBgx.js";function Wf(t){const e=nt.c(5),{className:n}=t,o=`relative inline-block overflow-hidden rounded-[2px] ${n===void 0?"h-5 w-5":n}`;let i,c,l;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"}),l=s.jsx(I,{name:"layout-column",className:"absolute inset-0 h-full w-full"}),e[0]=i,e[1]=c,e[2]=l):(i=e[0],c=e[1],l=e[2]);let d;return e[3]!==o?(d=s.jsxs("span",{"aria-hidden":"true",className:o,children:[i,c,l]}),e[3]=o,e[4]=d):d=e[4],d}function Zc(t){const e=nt.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,l=typeof o=="number"?`${o}px`:o;let d;e[5]!==i||e[6]!==c||e[7]!==l?(d={width:c,height:l,...i},e[5]=i,e[6]=c,e[7]=l,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 h;return e[10]!==n||e[11]!==r||e[12]!==d?(h=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]=h):h=e[13],h}const tb="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",sb="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",$a=t=>({...t,fallbackIconDataUrl:t.id==="finder"&&window.__OPENCHAMBER_PLATFORM__==="darwin"?tb:t.id==="terminal"?sb:void 0}),ed=t=>{const e=nt.c(8),{label:n,iconDataUrl:r,fallbackIconDataUrl:o}=t,[i,c]=a.useState(!1);let l;e[0]!==n?(l=n.trim().slice(0,1).toUpperCase()||"?",e[0]=n,e[1]=l):l=e[1];const d=l,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 x;return e[3]!==u?(x=s.jsx("img",{src:u,alt:"",className:"h-4 w-4 rounded-sm",onError:p}),e[3]=u,e[4]=x):x=e[4],x}let h;e[5]===Symbol.for("react.memo_cache_sentinel")?(h=De("h-4 w-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=h):h=e[5];let f;return e[6]!==d?(f=s.jsx("span",{className:h,children:d}),e[6]=d,e[7]=f):f=e[7],f},nb=t=>{const e=nt.c(75),{directory:n,className:r}=t,{t:o}=ft(),i=Xr(rb),c=Xr(ob),l=Xr(ib),d=Xr(ab),u=Xr(lb),h=Xr(cb),f=Xr(db);let p,x;e[0]!==u?(p=()=>{u()},x=[u],e[0]=u,e[1]=p,e[2]=x):(p=e[1],x=e[2]),a.useEffect(p,x);const b=hr()&&ua();let S;e:{let G;e[3]!==c||e[4]!==i?(G=c.find(V=>V.id===i)??c.find(ub)??c[0]??kc[0],e[3]=c,e[4]=i,e[5]=G):G=e[5];const Ie=G;if(Ie){let V;e[6]!==Ie?(V=$a(Ie),e[6]=Ie,e[7]=V):V=e[7],S=V;break e}let pe;e[8]===Symbol.for("react.memo_cache_sentinel")?(pe=$a(kc[0]),e[8]=pe):pe=e[8],S=pe}const g=S;if(!b||!n||c.length===0)return null;let m;e[9]!==n?(m=async G=>{await bh(n,G.id,G.appName)||await Wu(n,G.appName)},e[9]=n,e[10]=m):m=e[10];const y=m;let C;e[11]!==y||e[12]!==f?(C=async G=>{await f(G.id),await y(G)},e[11]=y,e[12]=f,e[13]=C):C=e[13];const j=C;let w;e[14]!==n||e[15]!==o?(w=async()=>{(await rr(n)).ok&&fe.success(o("openInApp.toast.pathCopied"))},e[14]=n,e[15]=o,e[16]=w):w=e[16];const N=w;let v;e[17]!==r?(v=De("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]=v):v=e[18];let P;e[19]!==y||e[20]!==g?(P=()=>{y(g)},e[19]=y,e[20]=g,e[21]=P):P=e[21];const F=d&&"animate-pulse";let k;e[22]!==F?(k=De("inline-flex h-full items-center px-2.5 typography-ui-label font-medium","text-foreground hover:bg-interactive-hover transition-colors",F),e[22]=F,e[23]=k):k=e[23];let E;e[24]!==g.label||e[25]!==o?(E=o("openInApp.actions.openInAria",{app:g.label}),e[24]=g.label,e[25]=o,e[26]=E):E=e[26];let O;e[27]!==g.fallbackIconDataUrl||e[28]!==g.iconDataUrl||e[29]!==g.label?(O=s.jsx(ed,{label:g.label,iconDataUrl:g.iconDataUrl,fallbackIconDataUrl:g.fallbackIconDataUrl}),e[27]=g.fallbackIconDataUrl,e[28]=g.iconDataUrl,e[29]=g.label,e[30]=O):O=e[30];let M;e[31]!==k||e[32]!==E||e[33]!==O||e[34]!==P?(M=s.jsx("button",{type:"button",onClick:P,className:k,"aria-label":E,children:O}),e[31]=k,e[32]=E,e[33]=O,e[34]=P,e[35]=M):M=e[35];let L;e[36]===Symbol.for("react.memo_cache_sentinel")?(L=De("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]=L):L=e[36];let _;e[37]!==o?(_=o("openInApp.actions.chooseAppAria"),e[37]=o,e[38]=_):_=e[38];let D;e[39]===Symbol.for("react.memo_cache_sentinel")?(D=s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4"}),e[39]=D):D=e[39];let A;e[40]!==_?(A=s.jsx(qs,{asChild:!0,children:s.jsx("button",{type:"button",className:L,"aria-label":_,children:D})}),e[40]=_,e[41]=A):A=e[41];let T;e[42]!==N?(T=()=>{N()},e[42]=N,e[43]=T):T=e[43];let z;e[44]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(I,{name:"file-copy",className:"h-4 w-4"}),e[44]=z):z=e[44];let R;e[45]!==o?(R=o("openInApp.actions.copyPath"),e[45]=o,e[46]=R):R=e[46];let W;e[47]!==R?(W=s.jsx("span",{className:"typography-ui-label text-foreground",children:R}),e[47]=R,e[48]=W):W=e[48];let J;e[49]!==T||e[50]!==W?(J=s.jsxs(is,{className:"flex items-center gap-2",onClick:T,children:[z,W]}),e[49]=T,e[50]=W,e[51]=J):J=e[51];let U;e[52]===Symbol.for("react.memo_cache_sentinel")?(U=s.jsx(Ln,{}),e[52]=U):U=e[52];let te;if(e[53]!==c||e[54]!==j||e[55]!==g.id){let G;e[57]!==j||e[58]!==g.id?(G=Ie=>{const pe=$a(Ie);return s.jsxs(is,{className:"flex items-center gap-2",onClick:()=>{j(Ie)},children:[s.jsx(ed,{label:Ie.label,iconDataUrl:Ie.iconDataUrl,fallbackIconDataUrl:pe.fallbackIconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:Ie.label}),g.id===Ie.id?s.jsx(I,{name:"check",className:"ml-auto h-4 w-4 text-primary"}):null]},Ie.id)},e[57]=j,e[58]=g.id,e[59]=G):G=e[59],te=c.map(G),e[53]=c,e[54]=j,e[55]=g.id,e[56]=te}else te=e[56];let Z;e[60]!==l||e[61]!==h||e[62]!==o?(Z=l?s.jsxs(is,{className:"flex items-center gap-2",onClick:()=>{h(!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]=l,e[61]=h,e[62]=o,e[63]=Z):Z=e[63];let ue;e[64]!==J||e[65]!==te||e[66]!==Z?(ue=s.jsxs(Ys,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[J,U,te,Z]}),e[64]=J,e[65]=te,e[66]=Z,e[67]=ue):ue=e[67];let Oe;e[68]!==A||e[69]!==ue?(Oe=s.jsxs(Qs,{children:[A,ue]}),e[68]=A,e[69]=ue,e[70]=Oe):Oe=e[70];let se;return e[71]!==M||e[72]!==Oe||e[73]!==v?(se=s.jsxs("div",{className:v,children:[M,Oe]}),e[71]=M,e[72]=Oe,e[73]=v,e[74]=se):se=e[74],se};function rb(t){return t.selectedAppId}function ob(t){return t.availableApps}function ib(t){return t.isCacheStale}function ab(t){return t.isScanning}function lb(t){return t.initialize}function cb(t){return t.loadInstalledApps}function db(t){return t.selectApp}function ub(t){return t.id===xh}const fb=[{pattern:/^dev(:.*)?$/i},{pattern:/^start(:.*)?$/i},{pattern:/^preview(:.*)?$/i},{pattern:/^serve(:.*)?$/i},{pattern:/^develop(:.*)?$/i}],mb=["dev","start","preview","serve"];async function hb(t,e,n){if(!t)return null;const r=xb(e);if(r)return{command:r.command,label:r.name||"Start Preview",actionId:r.id,previewUrlHint:r.openUrl};if(n){const o=bb(n);if(o){const i=await yb(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 pb(t)){const o=await gb(),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 pb(t){const e=`${t}/index.html`,n=await aa(e,t);return typeof n=="string"&&n.trim().length>0}async function gb(){try{const t=await hs("/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 xb(t){for(const e of t){const n=`${e.name} ${e.command}`.toLowerCase();if(mb.some(o=>n.includes(o)))return e}return null}function bb(t){for(const{pattern:e}of fb)for(const n of Object.keys(t))if(e.test(n))return n;return null}async function yb(t){const e=await aa(`${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 aa(`${t}/${r}`,t);if(typeof i=="string"&&i.trim().length>0)return o}return"npm"}async function aa(t,e){if(e?.trim())try{const r=new URLSearchParams({path:t,directory:e,optional:"true"}),o=await hs(`/api/fs/read?${r.toString()}`,{cache:"no-store"});if(o.ok)return o.text()}catch{}const n=fa()?.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 hs(`/api/fs/read?path=${encodeURIComponent(t)}&optional=true`,{cache:"no-store"});return r.ok?r.text():null}catch{return null}}async function wb(t){try{const e=await aa(`${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 vb=(t,e,n)=>new Promise(r=>{let o=!1,i=null,c=null;const l=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")&&l(!0)},onError:(d,u)=>{u&&l(!0)}}),o?i.close():c=setTimeout(()=>l(!1),n)}),jb="\x1B",Sb=new RegExp(`${jb}\\[[0-9;?]*[ -/]*[@-~]`,"g"),kb=/https?:\/\/[^\s<>'"`]+/gi,Mn="__openchamber_auto_discover_preview__",Nb=15e3,Cb=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},Ab=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}},Db=t=>{const n=t.replace(Sb,"").match(kb);if(!n||n.length===0)return null;const r=n.map(i=>i.replace(/[),.;]+$/,"")).filter(Boolean);if(r.length===0)return null;const o=[];for(const i of r)try{const c=new URL(i);c.port&&c.port.length>0&&o.push({raw:i,parsed:c})}catch{}if(o.length>0){const i=c=>{const{parsed:l}=c,d=l.hostname.toLowerCase(),u=d==="localhost"||d==="127.0.0.1"||d==="0.0.0.0"||d==="::1",h=l.pathname||"/",f=h.split("/").filter(Boolean).length,p=h==="/"||h==="",x=!!(l.search||l.hash);let b=0;return u&&(b+=50),p&&(b+=30),b-=Math.min(f*5,20),x&&(b-=10),b};return o.sort((c,l)=>i(l)-i(c)),o[0]?.parsed.origin??o[0]?.raw??null}return r[0]??null},Uf=({projectRef:t,directory:e,className:n,compact:r=!1,allowMobile:o=!1})=>{const{t:i}=ft(),{currentTheme:c}=co(),{terminal:l,runtime:d}=_n(),{isMobile:u}=Pr(),h=a.useMemo(()=>hr(),[]),f=Uc(re=>re.instances),p=Uc(re=>re.load),x=Re(re=>re.terminalShell),b=Re(re=>re.terminalLoginShells.includes(re.terminalShell)),S=Re(re=>re.setSettingsPage),g=Re(re=>re.setSettingsDialogOpen),m=Re(re=>re.setSettingsProjectsSelectedId),y=Re(re=>re.openContextPreview),C=gs(re=>re.ensureDirectory),j=gs(re=>re.setTabLabel),w=gs(re=>re.setTabIconKey),N=gs(re=>re.setActiveTab),v=gs(re=>re.setConnecting),P=gs(re=>re.setTabSessionId),F=gs(re=>re.setTabPreviewUrl),k=gs(re=>re.projectActionRuns),E=gs(re=>re.setProjectActionRun),O=gs(re=>re.updateProjectActionRunStatus),M=gs(re=>re.removeProjectActionRun),[L,_]=a.useState([]),[D,A]=a.useState(null),[T,z]=a.useState(!1),R=a.useRef({}),W=a.useRef({}),J=a.useRef({}),U=a.useRef({}),te=a.useRef(new Set),Z=a.useRef(0),ue=t?.id??null,Oe=t?.path??"",se=a.useMemo(()=>ue?{id:ue,path:Oe}:null,[ue,Oe]);a.useEffect(()=>{h&&p().catch(()=>{})},[h,p]);const G=a.useCallback(async re=>{await Io(re)},[]),Ie=a.useCallback(async()=>{if(!se)return;const re=Z.current+1;Z.current=re,z(!0);try{const me=await Ic(se);if(Z.current!==re)return;const ge=me.actions;_(ge),A($=>$===Mn||$&&ge.some(B=>B.id===$)?$:null)}catch{if(Z.current!==re)return}finally{Z.current===re&&z(!1)}},[se]),pe=a.useMemo(()=>tx(e||se?.path||""),[e,se?.path]),V=a.useMemo(()=>D?L.find(re=>re.id===D)??null:null,[L,D]),Q=a.useMemo(()=>({id:Mn,name:i("projectActions.actions.autoDiscover"),command:"",icon:"scan-2",autoOpenUrl:!0}),[i]),ne=!u,oe=a.useMemo(()=>ne?[Q,...L]:L,[L,Q,ne]);a.useEffect(()=>{Ie()},[Ie]),a.useEffect(()=>{if(typeof window>"u")return;const re=me=>{const ge=me.detail;ue&&(ge?.projectId&&ge.projectId!==ue||Ie())};return window.addEventListener(Hc,re),()=>{window.removeEventListener(Hc,re)}},[Ie,ue]),a.useEffect(()=>{D&&(D===Mn&&ne||L.some(re=>re.id===D)||A(null))},[L,ne,D]),a.useEffect(()=>{const re=()=>{const me=gs.getState(),ge=me.sessions,$=me.projectActionRuns;for(const[B,xe]of Object.entries($)){const Le=ge.get(xe.directory)?.tabs.find(bt=>bt.id===xe.tabId);if(!Le||Le.terminalSessionId!==xe.sessionId){M(B);continue}const Ke=W.current[B]??{lastSeenChunkId:null,openedUrl:!1,tail:"",openInPreview:!1};W.current[B]=Ke;const st=oe.find(bt=>bt.id===xe.actionId),ut=me.getBuffer(xe.directory,xe.tabId).chunks;if(!st||ut.length===0)continue;const mt=ut.filter(bt=>Ke.lastSeenChunkId===null||bt.id>Ke.lastSeenChunkId);if(mt.length===0)continue;const pt=mt.map(bt=>bt.data).join(""),ht=`${Ke.tail}${pt}`,xt=!Ke.openedUrl&&st.autoOpenUrl===!0?Db(ht):null,wt=mt[mt.length-1]?.id??Ke.lastSeenChunkId;if(Ke.lastSeenChunkId=wt,Ke.tail=ht.slice(-512),xt)if(Ke.openedUrl=!0,Ke.openInPreview){const bt=$[B];bt&&(F(bt.directory,bt.tabId,xt,{locked:!1,autoOpened:!1}),bt.status==="waiting-for-preview"&&O(B,"running"),window.clearTimeout(U.current[B]),delete U.current[B],y(bt.directory,xt))}else G(xt),fe.success(i("projectActions.toast.openedUrlFromOutput"));W.current[B]=Ke}for(const B of Object.keys(W.current))$[B]||(delete W.current[B],window.clearTimeout(U.current[B]),delete U.current[B])};return re(),gs.subscribe((me,ge)=>{(me.sessions!==ge.sessions||me.buffers!==ge.buffers)&&re()})},[oe,y,G,k,M,F,i,O]);const ce=a.useCallback(async(re,me={})=>{if(!pe)throw new Error(i("projectActions.error.noActiveDirectory"));const ge=wr(pe,re.id);C(pe);const $=gs.getState(),B=$.getDirectoryState(pe);let xe=R.current[ge]||null;const be=xe?!!B?.tabs.some(st=>st.id===xe):!1;(!xe||!be)&&(xe=$.createTab(pe),R.current[ge]=xe),j(pe,xe,`Action: ${re.name}`),w(pe,xe,re.icon||"play"),N(pe,xe),me.revealTerminal!==!1&&Re.getState().openContextPanelTab(pe,{mode:"terminal"});const Ke=gs.getState().getDirectoryState(pe)?.tabs.find(st=>st.id===xe);return{key:ge,tabId:xe,sessionId:Ke?.terminalSessionId??null}},[C,pe,N,w,j,i]),ke=a.useCallback(async re=>{if(d.isVSCode||!o&&u)return;if(!pe){fe.error(i("projectActions.error.noActiveDirectoryForAction"));return}const me=wr(pe,re.id),ge=k[me];if(!(ge&&ge.status==="running")&&!te.current.has(me)){te.current.add(me);try{const $=re.id===Mn?await(async()=>{const[wt,bt]=await Promise.all([Ic({id:se?.id??"",path:pe}),wb(pe)]),Dt=await hb(pe,wt.actions,bt);if(!Dt)throw new Error(i("contextPanel.preview.noDevServer"));return{id:Mn,name:i("projectActions.actions.autoDiscover"),command:Dt.command,icon:"scan-2",autoOpenUrl:!0,openUrl:Dt.previewUrlHint||""}})():re,B=$.autoOpenUrl===!0&&($.openUrl||"").trim().length>0,xe=!B&&re.id!==Mn,{key:be,tabId:Le,sessionId:Ke}=await ce($,{revealTerminal:xe});let st=Ke;if(!st){v(pe,Le,!0);try{st=(await l.createSession({cwd:pe,sessionId:Le,shell:x,loginShell:b,themeMode:c.metadata.variant==="light"?"light":"dark",terminalBackground:c.colors.surface.background,terminalForeground:c.colors.syntax.base.foreground})).sessionId,P(pe,Le,st)}finally{v(pe,Le,!1)}}if(!st)throw new Error(i("projectActions.error.failedToCreateTerminalSession"));J.current[be]?.(),v(pe,Le,!0);const ut=l.connect(st,{onEvent:wt=>{wt.type==="snapshot"&&(gs.getState().replaceBuffer(pe,Le,wt.data??"",wt.sequence??0),gs.getState().setConnecting(pe,Le,!1)),wt.type==="data"&&typeof wt.data=="string"&&wt.data.length>0&&gs.getState().appendToBuffer(pe,Le,wt.data,wt.sequence,wt.replayData),wt.type==="exit"&&(gs.getState().setTabLifecycle(pe,Le,"exited"),gs.getState().setConnecting(pe,Le,!1),gs.getState().removeProjectActionRun(be),delete W.current[be],J.current[be]?.(),delete J.current[be],window.clearTimeout(U.current[be]),delete U.current[be])},onError:(wt,bt)=>{gs.getState().setConnecting(pe,Le,!1),bt&&(gs.getState().setTabLifecycle(pe,Le,"exited"),gs.getState().setTabSessionId(pe,Le,null),gs.getState().removeProjectActionRun(be))}});J.current[be]=ut.close;const mt=$.autoOpenUrl===!0&&h&&($.desktopOpenSshForward||"").trim().length>0,pt=$.autoOpenUrl?Ab($.openUrl):null,ht=$.autoOpenUrl&&h?sx($.desktopOpenSshForward,f):null;E({key:be,directory:pe,actionId:$.id,tabId:Le,sessionId:st,status:$.id===Mn&&!pt?"waiting-for-preview":"running"}),window.clearTimeout(U.current[be]),delete U.current[be],$.id===Mn&&!pt&&(U.current[be]=window.setTimeout(()=>{const wt=gs.getState(),bt=wt.projectActionRuns[be];wt.updateProjectActionRunStatus(be,"running"),bt&&(wt.setActiveTab(bt.directory,bt.tabId),Re.getState().openContextPanelTab(bt.directory,{mode:"terminal"})),delete U.current[be]},Nb)),W.current[be]={lastSeenChunkId:null,openedUrl:!!ht||!!pt||B,tail:"",openInPreview:$.id===Mn};const xt=Cb($.command.trim().replace(/\r\n|\r/g,`
3
- `));await l.sendInput(st,`${xt}\r`),ht?(F(pe,Le,null,{locked:!0}),G(ht),fe.success(i("projectActions.toast.openedForwardedUrl"))):pt?(F(pe,Le,pt,{locked:!0,autoOpened:!0}),y(pe,pt),fe.success(i("projectActions.toast.openedActionUrl"))):B?(F(pe,Le,null,{locked:!0}),fe.error(i("projectActions.error.invalidCustomUrlFormat"))):mt?(F(pe,Le,null,{locked:!0}),fe.error(i("projectActions.error.selectedDesktopSshForwardUnavailable"))):F(pe,Le,null,{locked:!1,autoOpened:!1})}catch($){M(me),delete W.current[me],J.current[me]?.(),delete J.current[me],window.clearTimeout(U.current[me]),delete U.current[me],fe.error($ instanceof Error?$.message:i("projectActions.error.failedToRunAction"))}finally{te.current.delete(me)}}},[c.colors.surface.background,c.colors.syntax.base.foreground,c.metadata.variant,f,ce,o,u,h,pe,b,x,G,y,k,d.isVSCode,M,v,E,F,P,se?.id,i,l]),ye=a.useCallback(async re=>{const me=wr(pe,re.id),ge=k[me];if(!ge)return;O(me,"stopping");const $=vb(l,ge.sessionId,1e3);try{await l.sendInput(ge.sessionId,"")}catch{}const B=await $;if(gs.getState().getDirectoryState(ge.directory)?.tabs.find(Le=>Le.id===ge.tabId)?.terminalSessionId===ge.sessionId&&!B){if(typeof l.forceKill=="function")try{await l.forceKill({sessionId:ge.sessionId})}catch{}else try{await l.close(ge.sessionId)}catch{}P(ge.directory,ge.tabId,null)}M(me),delete W.current[me],J.current[me]?.(),delete J.current[me],window.clearTimeout(U.current[me]),delete U.current[me]},[pe,k,M,P,l,O]),he=a.useCallback(()=>{const re=V??oe[0];if(!re)return;const me=wr(pe,re.id),ge=k[me];if(ge?.status!=="stopping"){if(ge){ye(re);return}ke(re)}},[oe,pe,ke,k,V,ye]),Ee=a.useCallback((re,me=!1)=>{if(A(re.id),!me){ke(re);return}const ge=wr(pe,re.id),$=k[ge];if($?.status!=="stopping"){if($){ye(re);return}ke(re)}},[pe,ke,k,ye]),Ue=a.useCallback(()=>{se?.id&&(m(se.id),S("projects"),g(!0))},[g,S,m,se?.id]),Me=V??oe[0]??null,X=Me?k[wr(pe,Me.id)]:null,Ne=gs(re=>X?re.sessions.get(X.directory)?.tabs.find(me=>me.id===X.tabId)?.previewUrl??null:null);if(d.isVSCode||!o&&u||!se||!pe)return null;const Ae=V??oe[0]??null;if(!Ae)return null;const Se=Ae.icon||"play",le=Ae.id===Mn?"scan-2":Ba[Se]||"play",ee=wr(pe,Ae.id),ie=k[ee],ve=ie?.status==="stopping",K=ie?.status==="waiting-for-preview",de=!!(ie&&Ne),_e=()=>{!ie||!Ne||y(ie.directory,Ne)},Pe=Ae.id===Mn;return r?s.jsxs("div",{className:"inline-flex items-center",children:[s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",disabled:T||ve,className:De("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:he,"aria-label":ie?i("projectActions.actions.stopNamedAria",{name:Ae.name}):i("projectActions.actions.runNamedAria",{name:Ae.name}),children:ve||K?s.jsx(I,{name:"loader-4",className:"h-5 w-5 animate-spin text-[var(--status-warning)]"}):ie?s.jsx(I,{name:"stop",className:"h-5 w-5 text-[var(--status-warning)]"}):s.jsx(I,{name:le,className:"h-5 w-5"})})}),Pe?s.jsx(At,{sideOffset:6,children:i("projectActions.actions.autoDiscoverTooltip")}):null]}),de?s.jsxs(Nt,{children:[s.jsx(Ct,{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:_e,children:s.jsx(I,{name:"global",className:"h-4 w-4"})})}),s.jsx(At,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(Qs,{children:[s.jsx(qs,{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(Ys,{align:"end",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(is,{className:"flex items-center gap-2",onClick:Ue,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,{}),oe.map(re=>{const me=re.icon||"play",ge=re.id===Mn?"scan-2":Ba[me]||"play",$=wr(pe,re.id),B=k[$],xe=!!B,be=B?.status==="stopping";return s.jsxs(is,{className:"flex items-center gap-2",onClick:()=>{Ee(re,!0)},children:[s.jsx(I,{name:ge,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:re.name}),be||B?.status==="waiting-for-preview"?s.jsx(I,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):xe?s.jsx(I,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},re.id)})]})]})]}):s.jsxs("div",{className:De("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(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:he,disabled:T||ve,className:De("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":ie?i("projectActions.actions.stopNamedAria",{name:Ae.name}):i("projectActions.actions.runNamedAria",{name:Ae.name}),children:s.jsx("span",{className:"inline-flex h-4 w-4 shrink-0 items-center justify-center",children:ve||K?s.jsx(I,{name:"loader-4",className:"h-4 w-4 animate-spin text-[var(--status-warning)]"}):ie?s.jsx(I,{name:"stop",className:"h-4 w-4 text-[var(--status-warning)]"}):s.jsx(I,{name:le,className:"h-4 w-4"})})})}),Pe?s.jsx(At,{sideOffset:6,children:i("projectActions.actions.autoDiscoverTooltip")}):null]}),de?s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:_e,className:De(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(At,{sideOffset:6,children:i("projectActions.actions.openPreview")})]}):null,s.jsxs(Qs,{children:[s.jsx(qs,{asChild:!0,children:s.jsx("button",{type:"button",className:De(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(Ys,{align:"start",className:"w-52 max-h-[70vh] overflow-y-auto",children:[s.jsxs(is,{className:"flex items-center gap-2",onClick:Ue,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,{}),oe.map(re=>{const me=re.icon||"play",ge=re.id===Mn?"scan-2":Ba[me]||"play",$=wr(pe,re.id),B=k[$],xe=!!B,be=B?.status==="stopping";return s.jsxs(is,{className:"flex items-center gap-2",onClick:()=>{Ee(re,!0)},children:[s.jsx(I,{name:ge,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:re.name}),be||B?.status==="waiting-for-preview"?s.jsx(I,{name:"loader-4",className:"ml-auto h-4 w-4 animate-spin text-[var(--status-warning)]"}):xe?s.jsx(I,{name:"stop",className:"ml-auto h-4 w-4 text-[var(--status-warning)]"}):null]},re.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(ii(),{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 Ib(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 Rb(t){const e=t.info.role==="user"?"User":"Assistant",n=Pb(t.info.time?.created),r=Ib(t),o=n&&r?`${n} (${r})`:n||r;return o?`**${e}**
4
-
5
- *${o}*`:`**${e}**`}function Mb(t){return t.filter(e=>e.type==="text"&&typeof e.text=="string").map(e=>e.text).join("")}function Hf(t){const e=Rb(t),n=Mb(t.parts).trim();return n?`${e}
6
-
7
- ${n}`:""}function Kf(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(Hf).filter(Boolean).join(`
12
-
13
- ---
14
-
15
- `),c=[o+i];for(const l of t.children)c.push(Kf(l,e+1));return c.join(`
16
-
17
- ---
18
-
19
- `)}function Gf(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(Hf).filter(Boolean).join(`
26
-
27
- ---
28
-
29
- `);let l=i+c;if(n&&n.length>0){const d=n.map(u=>Kf(u,1)).join(`
30
-
31
- ---
32
-
33
- `);l+=`
34
-
35
- ---
36
-
37
- `+d}return l}function qf(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 Yf(t,e){const n=await yh(e,t);if(n)return n;if(!ir())return null;try{const r=await fa()?.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 Tb(t){const e=fa()?.files;if(e?.revealPath)try{return!!(await e.revealPath(t))?.success}catch{return!1}return await wh(t)?!0:Wu(t)}function Eb(){return Qu()}function Qf(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 sc=$o(()=>({pendingSessionIds:new Set})),Xf=t=>{const e=nt.c(2);let n;return e[0]!==t?(n=r=>r.pendingSessionIds.has(t),e[0]=t,e[1]=n):n=e[1],sc(n)},td=(t,e)=>{sc.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}})},Fb=async(t,e)=>{try{const d=(await Vh(t,{mode:"light"})).current?.trim();if(d)return d}catch{}const n=Vt(t),r=Vt(e)??e,o=et.getState().availableWorktreesByProject,c=(o.get(r)??o.get(e)??[]).find(l=>Vt(l.path)===n)?.branch?.trim();if(c)return c;throw new Error("Unable to determine the current branch")},sd=(t,e)=>{const n=zh(e);if(!n)throw new Error("Session status is unavailable");const r=n.session_status;if(t.some(i=>{const c=r[i.id]?.type;return c==="busy"||c==="retry"}))throw new Error("Session is not idle")},Ob=async(t,e,n,r,o)=>{const i=[];for(const c of[...t].reverse())try{await Xu(c,r,n,c.id===e),et.getState().setWorktreeMetadata(c.id,o.get(c.id)??null)}catch(l){i.push(l)}return i},Lb=async(t,e,n)=>{try{await Ju(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},Bb=async t=>{if(sc.getState().pendingSessionIds.has(t.root.id))throw new Error("Session move already in progress");td(t.root.id,!0);try{const e=Lh(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(l=>[l.id,et.getState().getWorktreeMetadata(l.id)]));sd(n,t.sourceDirectory);const o=await Fb(t.sourceDirectory,e.path),i=await Bh(e,{startRef:o}),c=[];try{await $h(i.path),sd(n,t.sourceDirectory);for(const[l,d]of n.entries())await Xu(d,t.sourceDirectory,i.path,l===0),c.push(d),et.getState().setWorktreeMetadata(d.id,_h(i))}catch(l){if((await Ob(c,t.root.id,t.sourceDirectory,i.path,r)).length>0)throw new Error(`Session move partially failed and could not be fully rolled back: ${l instanceof Error?l.message:String(l)}`);return Lb(e,i,l)}try{await Bi([t.sourceDirectory,i.path])}catch(l){console.warn("[session-worktree-move] Failed to refresh moved sessions",l)}return i.path}finally{td(t.root.id,!1)}},Jf=t=>{Bb(t).then(()=>fe.success(t.successMessage)).catch(e=>fe.error(t.failureMessage,{description:e instanceof Error?e.message:String(e)}))},Pa="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",$b="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",_b=a.memo(function(e){const n=nt.c(17),{visible:r,title:o,ariaLabel:i,onClick:c,className:l,Icon:d,iconClassName:u,pressed:h}=e,f=r===void 0?!0:r,p=h===void 0?!1:h;if(!f)return null;const x=l??Pa,b=p&&"bg-interactive-selection text-interactive-selection-foreground";let S;n[0]!==x||n[1]!==b?(S=De(x,b),n[0]=x,n[1]=b,n[2]=S):S=n[2];const g=u??"h-[18px] w-[18px]";let m;n[3]!==d||n[4]!==g?(m=s.jsx(I,{name:d,className:g}),n[3]=d,n[4]=g,n[5]=m):m=n[5];let y;n[6]!==i||n[7]!==c||n[8]!==p||n[9]!==S||n[10]!==m?(y=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,"aria-label":i,"aria-pressed":p,className:S,children:m})}),n[6]=i,n[7]=c,n[8]=p,n[9]=S,n[10]=m,n[11]=y):y=n[11];let C;n[12]!==o?(C=s.jsx(At,{children:s.jsx("p",{children:o})}),n[12]=o,n[13]=C):C=n[13];let j;return n[14]!==y||n[15]!==C?(j=s.jsxs(Nt,{children:[y,C]}),n[14]=y,n[15]=C,n[16]=j):j=n[16],j}),zb=a.memo(function(e){const n=nt.c(42),{isMobile:r,githubAuthStatus:o,githubAccounts:i,githubAvatarUrl:c,githubLogin:l,isSwitchingGitHubAccount:d,handleGitHubAccountSwitch:u}=e,{t:h}=ft();if(!o?.connected||r)return null;if(i.length>1){let b;n[0]===Symbol.for("react.memo_cache_sentinel")?(b=De(Pa,"h-7 w-7 overflow-hidden rounded-full border border-border/60 bg-muted/80 p-0"),n[0]=b):b=n[0];let S;n[1]!==l||n[2]!==h?(S=l?h("header.github.connectedWithLogin",{login:l}):h("header.github.connected"),n[1]=l,n[2]=h,n[3]=S):S=n[3];let g;n[4]!==c||n[5]!==l||n[6]!==h?(g=c?s.jsx("img",{src:c,alt:l?h("header.github.avatarWithLogin",{login:l}):h("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]=l,n[6]=h,n[7]=g):g=n[7];let m;n[8]!==d||n[9]!==S||n[10]!==g?(m=s.jsx(qs,{asChild:!0,children:s.jsx("button",{type:"button",className:b,title:S,disabled:d,children:g})}),n[8]=d,n[9]=S,n[10]=g,n[11]=m):m=n[11];let y;n[12]!==h?(y=h("header.github.accountsTitle"),n[12]=h,n[13]=y):y=n[13];let C;n[14]!==y?(C=s.jsx(So,{className:"typography-ui-header font-semibold text-foreground",children:y}),n[14]=y,n[15]=C):C=n[15];let j;n[16]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(Ln,{}),n[16]=j):j=n[16];let w;if(n[17]!==i||n[18]!==u||n[19]!==d||n[20]!==h){let P;n[22]!==u||n[23]!==d||n[24]!==h?(P=F=>{const k=F.user,E=!!F.current,O=F.source==="gh-cli"?h("header.github.accountSource.cli"):h("header.github.accountSource.oauth");return s.jsxs(is,{className:"gap-2",disabled:d,onSelect:()=>{E||u(F.id)},children:[k?.avatarUrl?s.jsx("img",{src:k.avatarUrl,alt:k.login?h("header.github.avatarWithLogin",{login:k.login}):h("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:k?.name?.trim()||k?.login||"GitHub"}),k?.login?s.jsxs("span",{className:"truncate typography-micro text-muted-foreground",children:[s.jsx("span",{className:"font-mono",children:k.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:O})]}):null]}),E?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]},F.id)},n[22]=u,n[23]=d,n[24]=h,n[25]=P):P=n[25],w=i.map(P),n[17]=i,n[18]=u,n[19]=d,n[20]=h,n[21]=w}else w=n[21];let N;n[26]!==C||n[27]!==w?(N=s.jsxs(Ys,{align:"end",className:"w-64",children:[C,j,w]}),n[26]=C,n[27]=w,n[28]=N):N=n[28];let v;return n[29]!==m||n[30]!==N?(v=s.jsxs(Qs,{children:[m,N]}),n[29]=m,n[30]=N,n[31]=v):v=n[31],v}let f;n[32]!==l||n[33]!==h?(f=l?h("header.github.connectedWithLogin",{login:l}):h("header.github.connected"),n[32]=l,n[33]=h,n[34]=f):f=n[34];let p;n[35]!==c||n[36]!==l||n[37]!==h?(p=c?s.jsx("img",{src:c,alt:l?h("header.github.avatarWithLogin",{login:l}):h("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]=l,n[37]=h,n[38]=p):p=n[38];let x;return n[39]!==f||n[40]!==p?(x=s.jsx("div",{className:"app-region-no-drag flex h-7 w-7 items-center justify-center overflow-hidden rounded-full border border-border/60 bg-muted/80",title:f,children:p}),n[39]=f,n[40]=p,n[41]=x):x=n[41],x}),Vb=a.memo(function(e){const n=nt.c(84),{isDesktopApp:r,currentInstanceLabel:o,compactCurrentInstanceLabel:i,currentInstanceIsLocal:c,isDesktopServicesOpen:l,setIsDesktopServicesOpen:d,refreshCurrentInstanceLabel:u,desktopServicesTab:h,setDesktopServicesTab:f,quotaResultsLength:p,fetchAllQuotas:x,servicesTabItems:b,quotaLastUpdated:S,quotaDisplayMode:g,quotaDisplayTabItems:m,handleDisplayModeChange:y,handleUsageRefresh:C,isQuotaLoading:j,isUsageRefreshSpinning:w,hasRateLimits:N,rateLimitGroups:v,expandedFamilies:P,toggleFamilyExpanded:F,shortcutLabel:k,showDevShutdown:E,isDevShutdownInFlight:O,onDevShutdown:M,remoteUpdateInfo:L,remoteUpdateChecking:_,remoteUpdateError:D,onOpenRemoteUpdate:A,showPredValues:T,timeFormatPreference:z}=e,{t:R}=ft();let W;n[0]!==h||n[1]!==x||n[2]!==p||n[3]!==u||n[4]!==d?(W=he=>{d(he),he&&(u(),h==="usage"&&p===0&&x())},n[0]=h,n[1]=x,n[2]=p,n[3]=u,n[4]=d,n[5]=W):W=n[5];let J;n[6]!==o||n[7]!==r||n[8]!==R?(J=r?R("header.services.openWithCurrent",{current:o}):R("header.services.open"),n[6]=o,n[7]=r,n[8]=R,n[9]=J):J=n[9];const U=r?"w-auto max-w-[14rem] justify-start gap-1.5 px-2.5":"h-8 w-8";let te;n[10]!==U?(te=De(Pa,U),n[10]=U,n[11]=te):te=n[11];let Z;n[12]===Symbol.for("react.memo_cache_sentinel")?(Z=s.jsx(I,{name:"stack",className:"h-[18px] w-[18px]"}),n[12]=Z):Z=n[12];let ue;n[13]!==i||n[14]!==r?(ue=r?s.jsx("span",{className:"truncate typography-ui-label font-medium text-foreground",children:i}):null,n[13]=i,n[14]=r,n[15]=ue):ue=n[15];let Oe;n[16]!==J||n[17]!==te||n[18]!==ue?(Oe=s.jsx(Ct,{asChild:!0,children:s.jsx(qs,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":J,className:te,children:[Z,ue]})})}),n[16]=J,n[17]=te,n[18]=ue,n[19]=Oe):Oe=n[19];let se;n[20]!==o||n[21]!==r||n[22]!==k||n[23]!==R?(se=r?R("header.services.tooltip.currentInstanceWithShortcuts",{current:o,toggle:k("toggle_services_menu"),nextTab:k("cycle_services_tab")}):R("header.services.tooltip.servicesWithShortcuts",{toggle:k("toggle_services_menu"),nextTab:k("cycle_services_tab")}),n[20]=o,n[21]=r,n[22]=k,n[23]=R,n[24]=se):se=n[24];let G;n[25]!==se?(G=s.jsx(At,{children:s.jsx("p",{children:se})}),n[25]=se,n[26]=G):G=n[26];let Ie;n[27]!==Oe||n[28]!==G?(Ie=s.jsxs(Nt,{children:[Oe,G]}),n[27]=Oe,n[28]=G,n[29]=Ie):Ie=n[29];let pe;n[30]!==x||n[31]!==p||n[32]!==f?(pe=he=>{const Ee=he;f(Ee),Ee==="usage"&&p===0&&x()},n[30]=x,n[31]=p,n[32]=f,n[33]=pe):pe=n[33];let V;n[34]!==h||n[35]!==b||n[36]!==pe?(V=s.jsx("div",{className:"sticky top-0 z-20 px-2 pt-1.5 pb-px",children:s.jsx("div",{className:"h-9",children:s.jsx(ui,{items:b,activeId:h,onSelect:pe,layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",activePillButtonClassName:"h-8",className:"h-full"})})}),n[34]=h,n[35]=b,n[36]=pe,n[37]=V):V=n[37];let Q;n[38]!==c||n[39]!==h||n[40]!==r||n[41]!==l||n[42]!==A||n[43]!==_||n[44]!==D||n[45]!==L||n[46]!==d||n[47]!==R?(Q=r&&h==="instance"?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:R("header.services.remoteUpdate.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:L?.available?R("header.services.remoteUpdate.available",{version:L.version||""}):_?R("header.services.remoteUpdate.checking"):D||R("header.services.remoteUpdate.upToDate")})]}),L?.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:A,children:R("header.services.remoteUpdate.actions.open")}):null]})}),s.jsx(Wh,{embedded:!0,open:l&&h==="instance",onOpenChange:Hb,onHostSwitched:()=>d(!1)})]}):null,n[38]=c,n[39]=h,n[40]=r,n[41]=l,n[42]=A,n[43]=_,n[44]=D,n[45]=L,n[46]=d,n[47]=R,n[48]=Q):Q=n[48];let ne;n[49]!==h||n[50]!==l?(ne=h==="mcp"?s.jsx(kf,{active:l&&h==="mcp"}):null,n[49]=h,n[50]=l,n[51]=ne):ne=n[51];let oe;n[52]!==h||n[53]!==P||n[54]!==y||n[55]!==C||n[56]!==N||n[57]!==j||n[58]!==w||n[59]!==g||n[60]!==m||n[61]!==S||n[62]!==v||n[63]!==T||n[64]!==R||n[65]!==z||n[66]!==F?(oe=h==="usage"?s.jsxs("div",{className:"overflow-x-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-[var(--interactive-border)] px-4 py-2.5",children:[s.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:R("header.services.rateLimits")}),s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Zf(S,z)})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("div",{className:"h-7 w-[10.5rem]",children:s.jsx(ui,{items:m,activeId:g,onSelect:he=>{y(he)},layoutMode:"fit",variant:"active-pill",activePillInsetClassName:"gap-0.5 px-px py-0",className:"h-full"})}),s.jsx("button",{type:"button",className:De("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:C,disabled:j||w,"aria-label":R("header.services.refreshRateLimitsAria"),children:s.jsx(I,{name:"refresh",className:De("h-4 w-4",w&&"animate-spin")})})]})]}),N?null:s.jsx("div",{className:"px-4 py-5 text-center",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:R("header.services.noRateLimits")})}),s.jsx("div",{className:"space-y-2 px-3 py-2.5",children:v.map(he=>{const Ee=P[he.providerId]??[];return s.jsxs("div",{className:"min-w-0 rounded-xl bg-[var(--surface-muted)] p-3",children:[s.jsxs("div",{className:"flex items-center gap-2 pb-2",children:[s.jsx(ai,{providerId:he.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:he.providerName})]}),he.entries.length===0&&(!he.modelFamilies||he.modelFamilies.length===0)?s.jsx("div",{children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:he.error??R("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3",children:[he.entries.map(Ue=>{const[Me,X]=Ue,Ne=g==="remaining"?X.remainingPercent:X.usedPercent,Ae=Ji(X.usedPercent,X.resetAt,X.windowSeconds,Me),Se=Ae?.dailyAllocationPercent!=null?g==="remaining"?100-_r(Ae.elapsedRatio):_r(Ae.elapsedRatio):null,le=li(X.valueLabel,Ne),ee=Zu(X.resetAt,X.resetAfterFormatted??X.resetAtFormatted,z);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:Ll(Me)}),ee?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:ee}):null]}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:le==="-"?"":le})]}),s.jsx(sa,{percent:Ne,tonePercent:X.usedPercent,className:"h-1.5",expectedMarkerPercent:Se}),Ae&&T?s.jsx(na,{paceInfo:Ae,compact:!0}):null]},`${he.providerId}-${Me}`)}),he.modelFamilies&&he.modelFamilies.length>0?s.jsx("div",{className:"space-y-0.5",children:he.modelFamilies.map(Ue=>{const Me=Ue.familyId??"other",X=Ee.includes(Me);return s.jsxs(To,{open:X,onOpenChange:()=>F(he.providerId,Me),children:[s.jsxs(xi,{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:Ue.familyLabel}),X?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(Eo,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:Ue.models.map(Ne=>{const[Ae,Se]=Ne,le=g==="remaining"?Se.remainingPercent:Se.usedPercent,ee=Ji(Se.usedPercent,Se.resetAt,Se.windowSeconds),ie=ee?.dailyAllocationPercent!=null?g==="remaining"?100-_r(ee.elapsedRatio):_r(ee.elapsedRatio):null,ve=li(Se.valueLabel,le);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:Sf(Ae)}),s.jsx("span",{className:"typography-ui-label tabular-nums text-foreground",children:ve==="-"?"":ve})]}),s.jsx(sa,{percent:le,tonePercent:Se.usedPercent,className:"h-1.5",expectedMarkerPercent:ie}),ee&&T?s.jsx(na,{paceInfo:ee,compact:!0}):null]},`${he.providerId}-${Ae}`)})})})]},Me)})}):null]})]},he.providerId)})})]}):null,n[52]=h,n[53]=P,n[54]=y,n[55]=C,n[56]=N,n[57]=j,n[58]=w,n[59]=g,n[60]=m,n[61]=S,n[62]=v,n[63]=T,n[64]=R,n[65]=z,n[66]=F,n[67]=oe):oe=n[67];let ce;n[68]!==O||n[69]!==M||n[70]!==E||n[71]!==R?(ce=E?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"mx-4 my-2 border-t border-[var(--interactive-border)]"}),s.jsx("div",{className:"px-2 pb-2",children:s.jsx(is,{disabled:O,onSelect:()=>{M()},children:R("header.services.shutdownDev")})})]}):null,n[68]=O,n[69]=M,n[70]=E,n[71]=R,n[72]=ce):ce=n[72];let ke;n[73]!==V||n[74]!==Q||n[75]!==ne||n[76]!==oe||n[77]!==ce?(ke=s.jsxs(Ys,{align:"end",className:"w-[min(27rem,calc(100vw-2rem))] max-h-[75vh] overflow-y-auto bg-[var(--surface-elevated)] p-0",children:[V,Q,ne,oe,ce]}),n[73]=V,n[74]=Q,n[75]=ne,n[76]=oe,n[77]=ce,n[78]=ke):ke=n[78];let ye;return n[79]!==l||n[80]!==W||n[81]!==Ie||n[82]!==ke?(ye=s.jsxs(Qs,{open:l,onOpenChange:W,children:[Ie,ke]}),n[79]=l,n[80]=W,n[81]=Ie,n[82]=ke,n[83]=ye):ye=n[83],ye}),Wb=(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??""),Ub=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},Zf=(t,e)=>{if(!t)return"-";try{return ef(t,e,{fallback:"-"})}catch{return"-"}},Zn=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},_a=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,nd=({onToggleLeftDrawer:t,onToggleRightDrawer:e,leftDrawerOpen:n,rightDrawerOpen:r})=>{sr("ui.header.render");const{t:o}=ft(),i=Re(H=>H.setSessionSwitcherOpen),c=Re(H=>H.toggleSidebar),l=Re(H=>H.isSidebarOpen),d=Re(H=>H.openContextOverview),u=Re(H=>H.openContextPlan),h=Re(H=>H.closeContextPanel),f=Re(H=>H.activeMainTab),p=Re(H=>H.setActiveMainTab),x=Re(H=>H.shortcutOverrides),b=Re(H=>H.timeFormatPreference),S=ts(H=>H.getCurrentModel),g=_n(),[m,y]=a.useState(!1),C=et(H=>H.getContextUsage),j=et(H=>!!H.newSessionDraft?.open),w=et(H=>H.currentSessionId),N=Uh(w??""),v=tf(w??""),P=Xf(w??""),F=pn(nr(a.useCallback(H=>{if(!w)return null;const Ge=H.activeSessions.find(jt=>jt.id===w);if(!Ge)return null;const ot=Ge;return{title:Ge.title??null,directory:ot.directory??null,created:Ge.time?.created??null,slug:ot.slug??null,shareUrl:Ge.share?.url??null,parentId:Ge.parentID??null}},[w]))),k=ms(nr(H=>{if(!H.activeProjectId)return null;const Ge=H.projects.find(ot=>ot.id===H.activeProjectId);return Ge?{id:Ge.id,path:Ge.path,label:Ge.label}:null})),E=a.useMemo(()=>{if(!k)return null;const H=k.label?.trim();if(H)return H;const Ge=k.path.split(/[\\/]/).filter(Boolean);return Ge[Ge.length-1]??null},[k]),O=Us(H=>H.results),M=Us(H=>H.fetchAllQuotas),L=Us(H=>H.isLoading),_=Us(H=>H.lastUpdated),D=Us(H=>H.displayMode),A=Us(H=>H.showPredValues),T=Us(H=>H.dropdownProviderIds),z=Us(H=>H.loadSettings),R=Us(H=>H.setDisplayMode),{isMobile:W}=Pr(),J=Dr(H=>H.status),U=Dr(H=>H.setStatus),te=a.useRef(null),[Z,ue]=a.useState(()=>typeof window>"u"?!1:hr()),Oe=a.useMemo(()=>ma(),[]),se=sf(),[G,Ie]=a.useState(!1),pe=a.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),{usesFramelessChrome:V,side:Q}=Lf(),ne=a.useMemo(()=>{if(typeof window>"u")return null;const H=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof H=="number"&&Number.isFinite(H)&&H>0)return H;if(typeof navigator>"u")return null;const Ge=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!Ge)return null;const ot=Number.parseInt(Ge[1],10),jt=Number.parseInt(Ge[2],10);return Number.isNaN(ot)?null:ot===10?jt:ot},[]);$e.useEffect(()=>{typeof window>"u"||ue(hr())},[]);const oe=S(),ce=oe&&typeof oe.limit=="object"&&oe.limit!==null?oe.limit:null,ke=ce&&typeof ce.context=="number"?ce.context:0,ye=ce&&typeof ce.output=="number"?ce.output:0,he=C(ke,ye),[Ee,Ue]=a.useState(null),Me=!w||N;$e.useEffect(()=>{if(!w){Ue(H=>H===null?H:null);return}if(he&&he.totalTokens>0){Ue(H=>Wb(H,he)?H:he);return}Me&&Ue(H=>H===null?H:null)},[he,w,Me]);const X=Re(H=>H.isSessionSwitcherOpen),Ne=J?.connected?J.user?.avatarUrl??null:null,Ae=J?.connected?J.user?.login??null:null,Se=J?.accounts??[],[le,ee]=a.useState(!1),[ie,ve]=a.useState(!1),[K,de]=a.useState(!1),[_e,Pe]=a.useState(!1),[re,me]=a.useState("Local"),[ge,$]=a.useState(!0),[B,xe]=a.useState(!1),[be,Le]=a.useState(null),[Ke,st]=a.useState(!1),[ut,mt]=a.useState(null),pt=a.useMemo(()=>Ub(re),[re]),[ht,xt]=a.useState(Z?"instance":"usage"),[wt,bt]=a.useState("usage");$e.useEffect(()=>{!Z&&ht==="instance"&&xt("usage")},[ht,Z]);const Dt=a.useMemo(()=>ir(),[]),qt=!Dt&&f==="chat"&&!!Ee&&Ee.totalTokens>0,Ut=Ee&&Ee.contextLimit>0?Math.min(999,Ee.totalTokens/Ee.contextLimit*100):0,We=a.useCallback(async()=>{if(!(typeof window>"u"||!Z))try{if(ua()){me("Local"),$(!0);return}$(!1);const H=await Uu(),Ge=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,ot=Cr();if(ot&&Qi(ot,Ge)){me("Local"),$(!0);return}const jt=H.hosts.find(Zt=>ot?Qi(ot,Hu(Zt)):!1);if(jt?.label?.trim()){me(Ku(jt.label.trim()));return}me("Instance")}catch{me("Local"),$(!0)}},[Z]);$e.useEffect(()=>{We()},[We]);const yt=a.useCallback(async()=>{if(ge){Le(null),mt(null);return}st(!0),mt(null);try{const H=new URLSearchParams({appType:"web",instanceMode:"remote",reportUsage:"false"}),Ge=await hs(`/api/openchamber/update-check?${H.toString()}`,{method:"GET",headers:{Accept:"application/json"}});if(!Ge.ok)throw new Error(`Server responded with ${Ge.status}`);const ot=await Ge.json();Le({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(H){Le(null),mt(H instanceof Error?H.message:o("header.services.remoteUpdate.error"))}finally{st(!1)}},[ge,o]);a.useEffect(()=>{Le(null),mt(null),xe(!1)},[ge,re]),a.useEffect(()=>{if(!Z||ge)return;const H=3e3,Ge=3600*1e3;let ot=!1,jt=null;const Zt=es=>{jt=window.setTimeout(()=>{if(ot||typeof document<"u"&&document.visibilityState!=="visible"){Zt(Ge);return}yt().finally(()=>{ot||Zt(Ge)})},es)};return Zt(H),()=>{ot=!0,jt!==null&&window.clearTimeout(jt)}},[yt,ge,re,Z]);const Qe=a.useCallback(()=>{if(be?.available){xe(!0);return}yt()},[yt,be?.available]);nx();const Rt=Us(H=>H.selectedModels),Ot=Us(H=>H.expandedFamilies),kt=Us(H=>H.toggleFamilyExpanded),Ft=a.useMemo(()=>{const H=[];for(const Ge of Nf){if(!T.includes(Ge.id))continue;const ot=O.find(ys=>ys.providerId===Ge.id),jt=ot?.usage?.windows??{},Zt=ot?.usage?.models,es=Object.entries(jt),rs={providerId:Ge.id,providerName:Ge.name,entries:es,error:ot&&!ot.ok&&ot.configured?ot.error:void 0};if(Zt&&Object.keys(Zt).length>0){const ys=Rt[Ge.id]??[],Rs=ys.length>0,Ns=rx(Zt,Ge.id),Ms=ox(Ge.id),Yn=ix(Ms);rs.modelFamilies=[];for(const jn of Yn){const Xn=Ns.get(jn.id)??[];if(Xn.length===0)continue;const Un=Rs?Xn.filter(fr=>ys.includes(fr)):Xn;if(Un.length===0)continue;const Rn=[];for(const fr of Un){const qr=Zt[fr];if(qr?.windows){const Yr=Object.entries(qr.windows);Yr.length>0&&Rn.push([fr,Yr[0][1]])}}Rn.length>0&&rs.modelFamilies.push({familyId:jn.id,familyLabel:jn.label,models:Rn})}const Gr=Ns.get(null)??[],Qn=Rs?Gr.filter(jn=>ys.includes(jn)):Gr;if(Qn.length>0){const jn=[];for(const Xn of Qn){const Un=Zt[Xn];if(Un?.windows){const Rn=Object.entries(Un.windows);Rn.length>0&&jn.push([Xn,Rn[0][1]])}}jn.length>0&&rs.modelFamilies.push({familyId:null,familyLabel:o("header.services.modelFamily.other"),models:jn})}}(es.length>0||rs.modelFamilies&&rs.modelFamilies.length>0||rs.error)&&H.push(rs)}return H},[T,O,Rt,o]),Ht=Ft.length>0;a.useEffect(()=>{z()},[z]);const Xt=a.useCallback(async H=>{R(H);try{await Fl({usageDisplayMode:H})}catch(Ge){console.warn("Failed to update usage display mode:",Ge)}},[R]),rt=a.useCallback(()=>{if(_e)return;Pe(!0);const H=new Promise(Ge=>setTimeout(Ge,500));Promise.all([M(),H]).finally(()=>{Pe(!1)})},[M,_e]),je=w?F??null:null,Fe=a.useRef(null),[Te,it]=a.useState(0);a.useEffect(()=>{if(!w){Fe.current&&(Fe.current=null,it(jt=>jt+1));return}if(je){Fe.current={sessionId:w,session:je,expiresAt:Date.now()+2e3};return}const H=Fe.current;if(!H||H.sessionId!==w)return;const Ge=H.expiresAt-Date.now();if(Ge<=0){Fe.current=null,it(jt=>jt+1);return}const ot=window.setTimeout(()=>{Fe.current?.sessionId===w&&(Fe.current=null),it(jt=>jt+1)},Ge);return()=>{window.clearTimeout(ot)}},[w,je]);const ct=(()=>{if(je)return je;if(!w)return null;const H=Fe.current;return H&&H.sessionId===w&&H.expiresAt>Date.now()?H.session:null})(),Kt=et(H=>w?H.worktreeMetadata.get(w)?.path??"":""),Lt=et(H=>w?H.worktreeMetadata.get(w)?.branch?.trim()??null:null),ze=Bl(H=>w?H.getAttachment(w):void 0),Xe=a.useMemo(()=>ze?Hh(ze,{pending:o("gitView.empty.worktreeSetupInProgress")}):null,[o,ze]),tt=a.useMemo(()=>ze?ze.legacy?"legacy":ze.degraded?"degraded":ze.worktreeStatus==="pending"?"pending":ze.worktreeStatus==="missing"?"missing":ze.worktreeStatus==="invalid"?"invalid":ze.attentionReason?"attention":null:null,[ze]),at=a.useMemo(()=>Zn(Kt||""),[Kt]),Ze=a.useMemo(()=>{const H=typeof ct?.directory=="string"?ct.directory:"";return Zn(H||"")},[ct?.directory]),Pt=et(H=>H.newSessionDraft?.open?Zn(H.newSessionDraft.bootstrapPendingDirectory??H.newSessionDraft.directoryOverride??""):""),Tt=a.useMemo(()=>at||Ze||Pt,[Pt,Ze,at]),Jt=Re(a.useCallback(H=>{const Ge=Zn(Tt||"");return Ge?_a(H.contextPanelByDirectory[Ge]):null},[Tt])),ls=et(H=>{const Ge=Zn(at||Ze||"");if(!Ge)return null;for(const ot of H.availableWorktreesByProject.values()){const Zt=ot.find(es=>Zn(es.path)===Ge)?.branch?.trim();if(Zt)return Zt}return null}),Bt=Kh(Tt||null)||Lt||ls,_t=a.useMemo(()=>{if(!w)return E??"OpenChamber";const H=ct?.title?.trim();return H&&H.length>0?H:"Untitled Session"},[E,ct?.title,w]),Mt=$l(Tt||void 0,{bootstrap:!1}),ps=pa(),_s=et(H=>H.updateSessionTitle),Wt=et(H=>H.shareSession),Fs=et(H=>H.unshareSession),cn=et(H=>H.archiveSessions),Gs=et(H=>H.deleteSessions),[as,Xs]=a.useState(!1),[Gn,qn]=a.useState(!1),dn=a.useRef(!1),[un,yn]=a.useState(""),[Os,zs]=a.useState(null),nn=a.useRef(null);a.useEffect(()=>{dn.current=!1,qn(!1),Xs(!1),yn(""),zs(null)},[w]);const zn=a.useCallback(()=>{w&&(yn(ct?.title?.trim()||_t),Xs(!0))},[ct?.title,w,_t]),rn=a.useCallback(async()=>{if(!w)return;const H=un.trim();H&&H!==ct?.title?.trim()&&await _s(w,H),Xs(!1)},[ct?.title,w,un,_s]);a.useEffect(()=>{if(!as)return;const H=Ge=>{const ot=Ge.target;(!ot||!nn.current?.contains(ot))&&rn()};return document.addEventListener("mousedown",H),()=>document.removeEventListener("mousedown",H)},[as,rn]);const pr=a.useCallback(()=>{w&&rr(w).then(H=>{fe[H.ok?"success":"error"](o(H.ok?"sessions.sidebar.session.copyId.success":"sessions.sidebar.session.copyId.error"))}).catch(()=>fe.error(o("sessions.sidebar.session.copyId.error")))},[w,o]),Dn=a.useCallback(async()=>{if(!w)return;const H=await Wt(w);if(H?.share?.url){const Ge=await rr(H.share.url);fe[Ge.ok?"success":"warning"](o("sessions.sidebar.session.share.successTitle"),{description:o(Ge.ok?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")});return}fe.error(o("sessions.sidebar.session.share.error"))},[w,Wt,o]),Ir=a.useCallback(()=>{const H=ct?.shareUrl;H&&rr(H).then(Ge=>{fe[Ge.ok?"success":"error"](o(Ge.ok?"sessions.sidebar.session.menu.copied":"sessions.sidebar.session.share.copyUrlError"))}).catch(()=>fe.error(o("sessions.sidebar.session.share.copyUrlError")))},[ct?.shareUrl,o]),Ss=a.useCallback(async()=>{if(!w)return;const H=await Fs(w);fe[H?"success":"error"](o(H?"sessions.sidebar.session.unshare.success":"sessions.sidebar.session.unshare.error"))},[w,o,Fs]),ae=a.useCallback(async()=>{if(!w||!Tt){fe.error(o("sessions.sidebar.session.export.nothingToExport"));return}try{await ps.loadCompleteHistory(w,Tt)}catch{fe.error(o("sessions.sidebar.session.export.failedLoadHistory"));return}const H=ul(Mt.getState(),w).list;if(H.length===0){fe.error(o("sessions.sidebar.session.export.nothingToExport"));return}const Ge=Gf(H,ct?.title??null),ot=Qf(ct?.title??null);await Yf(Ge,ot)||qf(Ge,ot),fe.success(o("sessions.sidebar.session.export.success"))},[ct?.title,w,Mt,Tt,ps,o]),qe=v?.type==="busy"||v?.type==="retry",lt=a.useCallback(()=>{if(!w||!Ze||qe||P)return;const H=pn.getState().activeSessions,Ge=H.find(Zt=>Zt.id===w);if(!Ge)return;const ot=[],jt=[w];for(let Zt=0;Zt<jt.length;Zt+=1){const es=jt[Zt];for(const rs of H)rs.parentID===es&&(ot.push(rs),jt.push(rs.id))}Jf({root:Ge,descendants:ot,sourceDirectory:Ze,successMessage:o("sessions.sidebar.session.moveToWorktree.success"),failureMessage:o("sessions.sidebar.session.moveToWorktree.failed")})},[w,qe,P,Ze,o]),gt=a.useCallback(async()=>{if(!w||!Os)return;const H=pn.getState().activeSessions,Ge=[w];for(let es=0;es<Ge.length;es+=1){const rs=Ge[es];for(const ys of H)ys.parentID===rs&&!Ge.includes(ys.id)&&Ge.push(ys.id)}const ot=Os;if(zs(null),(ot==="archive"?await cn(Ge):await Gs(Ge)).failedIds.length>0){fe.error(o(ot==="archive"?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error"));return}fe.success(o(ot==="archive"?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"))},[cn,w,Gs,Os,o]),Gt=Re(H=>H.isScheduledTasksDialogOpen),Et=Re(H=>H.isArchivePageOpen),St=Re(H=>H.worktreesPageProjectId),xs=Re(H=>H.isMultiRunLauncherOpen),As=ms(H=>{if(!St)return null;const Ge=H.projects.find(ot=>ot.id===St);return Ge?.label?.trim()||Ge?.path?.split("/").pop()||null}),ss=a.useMemo(()=>Gt?{title:o("sessions.scheduledTasks.dialog.title"),subtitle:null}:Et?{title:o("sessions.archivePage.title"),subtitle:null}:St?{title:o("sessions.worktreesPage.title",{project:As??""}),subtitle:null}:xs?{title:o("sessions.sidebar.header.actions.newMultiRun"),subtitle:null}:null,[Et,xs,Gt,o,St,As]),ks=a.useMemo(()=>Zn(Tt||k?.path||""),[k?.path,Tt]),Ls=a.useMemo(()=>k?{id:k.id,path:k.path}:null,[k]),Bs=a.useRef(null);a.useEffect(()=>{!Ls||!ks||(Bs.current={projectRef:Ls,directory:ks})},[ks,Ls]);const Be=a.useMemo(()=>Ls&&ks?{projectRef:Ls,directory:ks}:Bs.current,[ks,Ls]),It=_l(H=>H.planModeEnabled),ns=et(H=>H.isSessionPlanAvailable),ds=It&&w?ns(w):!1,ws=ds,Ds=a.useRef("");a.useEffect(()=>{if(!It){Re.getState().activeMainTab==="plan"&&Re.getState().setActiveMainTab("chat");return}if(!w)return;const H=`${w||"none"}:${Ze||"none"}:${ct?.created||0}:${ct?.slug||"none"}`;Ds.current!==H&&(Ds.current=H),!ds&&Re.getState().activeMainTab==="plan"&&Re.getState().setActiveMainTab("chat")},[It,ds,ct?.slug,ct?.created,w,Ze]);const on=a.useCallback(async H=>{if(!(!H||le)){ee(!0);try{const Ge=g.github?await g.github.authActivate(H):await(async()=>{const ot=await hs("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:H})}),jt=await ot.json().catch(()=>null);if(!ot.ok||!jt)throw new Error(jt?.error||ot.statusText);return jt})();U(Ge)}catch(Ge){console.error("Failed to switch GitHub account:",Ge)}finally{ee(!1)}}},[le,g.github,U]),Ps=a.useCallback(()=>{if(typeof document>"u")return;const H=document.activeElement;if(!H)return;const Ge=H.tagName;(Ge==="INPUT"||Ge==="TEXTAREA"||Ge==="SELECT"||H.isContentEditable)&&H.blur()},[]),fn=a.useCallback(()=>{if(W){Ps(),i(!X);return}c()},[Ps,W,X,i,c]),lr=a.useCallback(()=>{Ar("desktop_open_draft_mini_chat_window",{directory:Zn(Tt||k?.path||""),projectId:k?.id??null,apiBaseUrl:Cr(),clientToken:Xi()}).catch(H=>{console.warn("[header] failed to open draft mini chat window",H)})},[k?.id,k?.path,Tt]),vs=a.useCallback(()=>{if(j){lr();return}w&&Ar("desktop_open_session_mini_chat_window",{sessionId:w,directory:Zn(Tt||k?.path||""),apiBaseUrl:Cr(),clientToken:Xi()}).catch(H=>{console.warn("[header] failed to open session mini chat window",H)})},[k?.path,w,lr,j,Tt]),zt=a.useCallback(()=>{const H=Zn(Tt||"");if(!H)return;const Ge=Re.getState().contextPanelByDirectory[H];if(_a(Ge)==="context"){h(H);return}d(H)},[h,d,Tt]),us=Jt==="context",Rr=a.useCallback(()=>{const H=Zn(Tt||"");if(!H)return;const Ge=Re.getState().contextPanelByDirectory[H];if(_a(Ge)==="plan"){h(H);return}u(H)},[h,u,Tt]),Pn=Pa,Vs=$b,cr=a.useMemo(()=>ie?"services":n?"sessions":r?"git":f,[f,ie,n,r]),gr=a.useCallback(()=>{ve(!1),n&&t&&t(),r&&e&&e(),!t&&X&&i(!1)},[X,n,t,e,r,i]),Ur=a.useCallback(()=>{n||ve(!1),t?.()},[n,t]),Vo=a.useCallback(()=>{r||ve(!1),e?.()},[e,r]),Hr=a.useMemo(()=>Z&&pe&&!G?"5.5rem":se?"max(calc(0.75rem + var(--oc-wco-left-inset, 0px)), 5.5rem)":(!Z||V)&&!Dt?"calc(0.75rem + var(--oc-wco-left-inset, 0px))":"0.75rem",[Z,G,pe,se,Dt,V]);$e.useEffect(()=>{typeof document>"u"||document.documentElement.style.setProperty("--oc-titlebar-left-inset",Hr)},[Hr]);const Wo=l?"0.75rem":"var(--oc-titlebar-left-inset, 0.75rem)",Kr=l?"0px":"calc(var(--oc-titlebar-controls-width, 5.5rem) + 0.5rem)";$e.useEffect(()=>{if(!Z||!pe){Ie(!1);return}let H=!1;const Ge=async()=>{try{const jt=await Ar("desktop_is_window_fullscreen");H||Ie(jt===!0)}catch{H||Ie(!1)}},ot=()=>{Ge()};return Ge(),window.addEventListener("openchamber:window-resized",ot),()=>{H=!0,window.removeEventListener("openchamber:window-resized",ot)}},[Z,pe]);const uo=a.useMemo(()=>!Z||!pe||ne===null?"":ne>=26?"h-12":ne<=15?"h-14":"",[Z,pe,ne]),Uo=a.useMemo(()=>{if(!(Z&&!V||Dt))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))"}},[Z,Dt,V]),xr=a.useCallback(()=>{if(typeof document>"u")return;const H=te.current?.getBoundingClientRect().height;H&&document.documentElement.style.setProperty("--oc-header-height",`${H}px`)},[]);$e.useEffect(()=>{if(typeof window>"u")return;xr();const H=te.current;if(!H||typeof ResizeObserver>"u")return()=>{};let Ge=0;const ot=()=>{Ge||(Ge=requestAnimationFrame(()=>{Ge=0,xr()}))},jt=new ResizeObserver(ot);return jt.observe(H),window.addEventListener("resize",ot),window.addEventListener("orientationchange",ot),()=>{Ge&&cancelAnimationFrame(Ge),jt.disconnect(),window.removeEventListener("resize",ot),window.removeEventListener("orientationchange",ot)}},[xr]),$e.useEffect(()=>{xr()},[xr,W,uo]);const Ho=a.useCallback(async H=>{const Ge=H.target;Ge.closest(".app-region-no-drag")||Ge.closest("button, a, input, select, textarea")||H.button===0&&Z&&await vh()},[Z]),an=a.useMemo(()=>{if(W){const H=[{id:"chat",label:o("layout.mainTab.chat"),icon:"chat-4"}];return ws&&H.push({id:"plan",label:o("layout.mainTab.plan"),icon:"file-text"}),H.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"}),H}return[]},[W,ws,o]),In=a.useCallback(H=>ga(ro(H,x)),[x]);$e.useEffect(()=>{!W&&f!=="chat"&&f!=="terminal"&&f!=="diagram"&&p("chat")},[f,W,p]);const Is=a.useMemo(()=>{const H=[];return Z&&H.push({value:"instance",label:o("layout.services.instance"),icon:s.jsx(I,{name:"server",className:"h-3.5 w-3.5"})}),H.push({value:"usage",label:o("layout.services.usage"),icon:s.jsx(I,{name:"timer",className:"h-3.5 w-3.5"})},{value:"mcp",label:"MCP",icon:s.jsx(gl,{className:"h-3.5 w-3.5"})}),H},[Z,o]),Vn=a.useMemo(()=>Is.map(H=>({id:H.value,label:H.label,icon:H.icon})),[Is]),fo=a.useMemo(()=>{if(typeof window>"u"||Z||Dt)return!1;const H=window.location.hostname;return H==="localhost"||H==="127.0.0.1"||H==="::1"},[Z,Dt]),Ko=a.useCallback(async()=>{if(m)return;y(!0),de(!1);const H=[];let Ge=!1;try{try{for(const[,ot]of gs.getState().sessions.entries())for(const jt of ot.tabs)jt.previewUrl&&H.push(jt.previewUrl)}catch{}try{await g.terminal.forceKill?.({})}catch{}try{(await hs("/api/system/dev-shutdown",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({previewUrls:H})})).ok?Ge=!0:Ge=(await hs("/api/system/shutdown",{method:"POST"})).ok}catch{}}finally{Ge||y(!1)}},[m,g.terminal,de]),mo=a.useMemo(()=>[{value:"usage",label:o("header.services.used")},{value:"remaining",label:o("header.services.remaining")}],[o]),Go=a.useMemo(()=>mo.map(H=>({id:H.value,label:H.label})),[mo]),wn=a.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(gl,{className:"h-3.5 w-3.5"})}],[o]);$e.useEffect(()=>{const H=Ge=>{if(nf(Ge)&&!Ge.shiftKey&&!Ge.altKey){const ot=parseInt(Ge.key,10);ot>=1&&ot<=an.length&&(Ge.preventDefault(),W&&(Ps(),gr()),p(an[ot-1].id))}};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[Ps,gr,W,p,an]),$e.useEffect(()=>{const H=Ge=>{const ot=ro("toggle_services_menu",x);if(Ea(Ge,ot)){Ge.preventDefault(),K?de(!1):(de(!0),We(),ht==="usage"&&O.length===0&&M());return}const jt=ro("cycle_services_tab",x);if(Ea(Ge,jt)){Ge.preventDefault();const es=Is.map(Ns=>Ns.value);if(es.length===0)return;const rs=es.indexOf(ht),ys=rs===-1?0:(rs+1)%es.length,Rs=es[ys];xt(Rs),de(!0),We(),Rs==="usage"&&O.length===0&&M();return}const Zt=ro("toggle_context_plan",x);Ea(Ge,Zt)&&(Ge.preventDefault(),Rr())};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[x,K,ht,Is,O.length,M,We,Rr]);const dr=H=>{const Ge=f===H.id,ot=H.icon==="diff",jt=ot?null:H.icon,Zt=H.id==="chat",es=ys=>ot?s.jsx(Zc,{size:ys}):jt?s.jsx(I,{name:jt,className:`h-${ys/4} w-${ys/4}`}):null,rs=s.jsxs("button",{type:"button",onClick:()=>p(H.id),className:De("relative flex h-8 items-center gap-2 px-3 rounded-lg typography-ui-label font-medium transition-colors",Ge?"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",Zt&&!W&&"min-w-[100px] justify-center"),"aria-label":H.label,"aria-selected":Ge,role:"tab",children:[W?es(20):s.jsxs(s.Fragment,{children:[es(16),s.jsx("span",{className:"header-tab-label",children:H.label})]}),H.badge!==void 0&&H.badge>0&&s.jsx("span",{className:"header-tab-badge typography-micro text-status-info font-medium",children:H.badge})]});return s.jsx(a.Fragment,{children:rs},H.id)},br=s.jsxs(s.Fragment,{children:[s.jsx(nb,{directory:ks,className:"mr-1"}),s.jsx(Vb,{isDesktopApp:Z,currentInstanceLabel:re,compactCurrentInstanceLabel:pt,currentInstanceIsLocal:ge,isDesktopServicesOpen:K,setIsDesktopServicesOpen:de,refreshCurrentInstanceLabel:We,desktopServicesTab:ht,setDesktopServicesTab:xt,quotaResultsLength:O.length,fetchAllQuotas:M,servicesTabItems:Vn,quotaLastUpdated:_,quotaDisplayMode:D,showPredValues:A,quotaDisplayTabItems:Go,handleDisplayModeChange:Xt,handleUsageRefresh:rt,isQuotaLoading:L,isUsageRefreshSpinning:_e,hasRateLimits:Ht,rateLimitGroups:Ft,expandedFamilies:Ot,toggleFamilyExpanded:kt,shortcutLabel:In,showDevShutdown:fo,isDevShutdownInFlight:m,onDevShutdown:Ko,remoteUpdateInfo:be,remoteUpdateChecking:Ke,remoteUpdateError:ut,onOpenRemoteUpdate:Qe,timeFormatPreference:b}),s.jsx(zb,{isMobile:W,githubAuthStatus:J,githubAccounts:Se,githubAvatarUrl:Ne,githubLogin:Ae,isSwitchingGitHubAccount:le,handleGitHubAccountSwitch:on})]}),Mr=Oe&&(j||!!w),vn=()=>s.jsxs("div",{onMouseDown:Ho,className:De("app-region-drag relative flex h-12 select-none items-center pr-3",uo),style:Uo,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:Wo}}),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:Kr}}),s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[ss?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:ss.title}),ss.subtitle?s.jsx("span",{className:"truncate typography-micro text-[10.5px] font-normal leading-tight text-muted-foreground/75 max-w-full",children:ss.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:[l?null:s.jsx(Rx,{align:"start",children:s.jsx("button",{type:"button",className:Pn,"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:[as?s.jsxs("form",{ref:nn,className:"flex w-full min-w-0 items-center gap-2 leading-tight",onSubmit:H=>{H.preventDefault(),rn()},children:[s.jsx("input",{value:un,onChange:H=>yn(H.target.value),autoFocus:!0,onKeyDown:H=>{H.stopPropagation(),H.key==="Escape"&&Xs(!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:()=>Xs(!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:j?o("sessions.switcher.draftTitle"):_t}),E||Bt||!j&&tt?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:[E?s.jsx("span",{className:"truncate",children:E}):null,Bt?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:Bt})]}):null,!j&&tt?s.jsxs("span",{className:De("inline-flex min-w-0 items-center gap-0.5",tt==="attention"||tt==="invalid"||tt==="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:Xe})]}):null]}):null]}),s.jsx("div",{className:"flex h-[18px] shrink-0 items-center justify-center self-start",children:w&&!j&&!as?s.jsxs(Qs,{open:Gn,onOpenChange:qn,onOpenChangeComplete:H=>{!H&&dn.current&&(dn.current=!1,zn())},children:[s.jsx(qs,{asChild:!0,children:s.jsx(He,{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(Ys,{align:"end",className:"min-w-[190px]",children:[s.jsxs(is,{onClick:()=>{dn.current=!0},children:[s.jsx(I,{name:"pencil-ai",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.rename")]}),s.jsxs(is,{onClick:pr,children:[s.jsx(I,{name:"file-copy",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.copyId")]}),s.jsx(Ln,{}),ct?.shareUrl?s.jsxs(s.Fragment,{children:[s.jsxs(is,{onClick:Ir,children:[s.jsx(I,{name:"file-copy",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.copyLink")]}),s.jsxs(is,{onClick:()=>{Ss()},children:[s.jsx(I,{name:"link-unlink-m",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.unshare")]})]}):s.jsxs(is,{onClick:()=>{Dn()},children:[s.jsx(I,{name:"share-2",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.share")]}),s.jsxs(is,{onClick:()=>{ae()},children:[s.jsx(I,{name:"download",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.exportMarkdown")]}),!Dt&&ct&&!ct.parentId?s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(is,{disabled:!Ze||qe||P,onClick:lt,className:"w-full",children:[s.jsx(I,{name:"folder-shared",className:"mr-2 size-4"}),o("sessions.sidebar.session.menu.moveToWorktree")]})})}),s.jsx(At,{side:"right",className:"max-w-72",children:o(P?"sessions.sidebar.session.moveToWorktree.tooltipMoving":qe?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,s.jsx(Ln,{}),s.jsxs(is,{onClick:()=>zs("archive"),children:[s.jsx(I,{name:"inbox-archive",className:"mr-2 size-4"}),o("sessions.sidebar.bulkActions.archive")]}),s.jsxs(is,{className:"text-destructive focus:text-destructive",onClick:()=>zs("delete"),children:[s.jsx(I,{name:"delete-bin",className:"mr-2 size-4"}),o("sessions.sidebar.bulkActions.delete")]})]})]}):null})]}),an.length>0&&s.jsx("div",{className:"flex items-center gap-1 rounded-lg bg-[var(--surface-muted)]/50 p-1",children:an.map(H=>dr(H))}),s.jsx("div",{className:"flex-1"}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[qt&&Ee?s.jsx(Mx,{totalTokens:Ee.totalTokens,percentage:Ut,colorPercentage:Ee.percentage,contextLimit:Ee.contextLimit,outputLimit:Ee.outputLimit??0,size:"compact",hideIcon:!0,showPercentIcon:!0,onClick:zt,pressed:us,className:Mr?"":"mr-3.5",valueClassName:"typography-ui-label font-medium leading-none text-foreground",percentIconClassName:"h-4.5 w-4.5"}):null,s.jsx(_b,{visible:Mr,title:o(j?"header.actions.newMiniChat":"header.actions.openSessionMiniChat"),ariaLabel:o(j?"header.actions.newMiniChatAria":"header.actions.openSessionMiniChatAria"),onClick:vs,className:De(Pn,"mr-1"),Icon:"picture-in-picture-2"}),br,s.jsx(Bf,{visible:V&&Q==="right",position:"right"})]})]})]}),Wn=()=>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:Ur,className:De(Vs,cr==="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"})}):X?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:fn,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&&X&&s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:o("header.sessions.title")})]}),(!X||!!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:an.map(H=>{const Ge=f===H.id,ot=H.icon==="diff",jt=ot?null:H.icon;return s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>{W&&(Ps(),gr()),p(H.id)},"aria-label":H.label,"aria-selected":Ge,role:"tab",className:De(Vs,"relative rounded-lg",cr===H.id&&"bg-interactive-selection text-interactive-selection-foreground"),children:[ot?s.jsx(Zc,{className:"h-5 w-5"}):jt?s.jsx(I,{name:jt,className:"h-5 w-5"}):null,H.badge!==void 0&&H.badge>0&&s.jsx("span",{className:"absolute -top-1 -right-1 text-[10px] font-semibold text-primary",children:H.badge}),H.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(At,{children:s.jsx("p",{children:H.label})})]},H.id)})})})})}),s.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[Be&&s.jsx(Uf,{projectRef:Be.projectRef,directory:Be.directory,compact:!0,allowMobile:!0,className:"h-9"}),s.jsxs(Qs,{open:ie,onOpenChange:H=>{H&&(n&&t&&t(),r&&e&&e()),ve(H),H&&O.length===0&&M()},children:[s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(qs,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":o("header.services.viewAria"),className:De(Vs,cr==="services"&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(I,{name:"stack",className:"h-5 w-5"})})})}),s.jsx(At,{children:s.jsx("p",{children:o("header.services.title")})})]}),s.jsx(Ys,{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(ui,{items:wn,activeId:wt,onSelect:H=>{const Ge=H;bt(Ge),Ge==="usage"&&O.length===0&&M()},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:()=>ve(!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"})})]})}),wt==="mcp"&&s.jsx(kf,{active:ie&&wt==="mcp"}),wt==="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:Zf(_,b)})]}),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:()=>Xt("usage"),className:De("typography-ui-label px-1 pb-0.5 transition-colors",D==="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:()=>Xt("remaining"),className:De("typography-ui-label px-1 pb-0.5 transition-colors",D==="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:De("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:rt,disabled:L||_e,"aria-label":o("header.services.refreshRateLimitsAria"),children:s.jsx(I,{name:"refresh",className:De("h-4 w-4",_e&&"animate-spin")})})]})]})}),!Ht&&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:Ft.map((H,Ge)=>s.jsxs(a.Fragment,{children:[Ge>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(ai,{providerId:H.providerId,className:"h-4 w-4"}),s.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:H.providerName})]}),H.entries.length===0&&(!H.modelFamilies||H.modelFamilies.length===0)?s.jsx("div",{className:"px-4 pb-2",children:s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:H.error??o("header.services.noRateLimitsReported")})}):s.jsxs("div",{className:"space-y-3 px-4 pb-2",children:[H.entries.map(([ot,jt])=>{const Zt=D==="remaining"?jt.remainingPercent:jt.usedPercent,es=Ji(jt.usedPercent,jt.resetAt,jt.windowSeconds,ot),rs=es?.dailyAllocationPercent!=null?D==="remaining"?100-_r(es.elapsedRatio):_r(es.elapsedRatio):null,ys=li(jt.valueLabel,Zt),Rs=Zu(jt.resetAt,jt.resetAfterFormatted??jt.resetAtFormatted,b);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:Ll(ot)}),Rs?s.jsx("span",{className:"truncate typography-micro text-muted-foreground",children:Rs}):null]}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:ys==="-"?"":ys})]}),s.jsx(sa,{percent:Zt,tonePercent:jt.usedPercent,className:"h-1.5",expectedMarkerPercent:rs}),es&&A?s.jsx(na,{paceInfo:es,compact:!0}):null]},`${H.providerId}-${ot}`)}),H.modelFamilies&&H.modelFamilies.length>0&&s.jsx("div",{className:"space-y-0.5",children:H.modelFamilies.map(ot=>{const Zt=(Ot[H.providerId]??[]).includes(ot.familyId??"other");return s.jsxs(To,{open:Zt,onOpenChange:()=>kt(H.providerId,ot.familyId??"other"),children:[s.jsxs(xi,{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}),Zt?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(Eo,{children:s.jsx("div",{className:"space-y-2.5 pb-1 pl-1 pt-1",children:ot.models.map(([es,rs])=>{const ys=D==="remaining"?rs.remainingPercent:rs.usedPercent,Rs=Ji(rs.usedPercent,rs.resetAt,rs.windowSeconds),Ns=Rs?.dailyAllocationPercent!=null?D==="remaining"?100-_r(Rs.elapsedRatio):_r(Rs.elapsedRatio):null,Ms=li(rs.valueLabel,ys);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:Sf(es)}),s.jsx("span",{className:"typography-ui-label text-foreground tabular-nums",children:Ms==="-"?"":Ms})]}),s.jsx(sa,{percent:ys,tonePercent:rs.usedPercent,className:"h-1.5",expectedMarkerPercent:Ns}),Rs&&A?s.jsx(na,{paceInfo:Rs,compact:!0}):null]},`${H.providerId}-${es}`)})})})]},ot.familyId??"other")})})]})]},H.providerId))})]})]})})]}),e?s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Vo,className:De(Vs,"relative",cr==="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(At,{children:s.jsx("p",{children:r?"Close git sidebar":"Open git sidebar"})})]}):null]})]})]}),ur=De("header-safe-area relative z-10 bg-background",W&&"border-b border-border/50");return s.jsxs(s.Fragment,{children:[s.jsx("header",{ref:te,className:ur,style:{"--padding-scale":"1"},children:W?Wn():vn()}),s.jsx(Ts,{open:Os!==null,onOpenChange:H=>{H||zs(null)},children:s.jsxs(Es,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Hs,{children:[s.jsx($s,{children:o(Os==="delete"?"sessions.sidebar.dialogs.deleteSession.title":"sessions.sidebar.dialogs.archiveSession.title")}),s.jsx(Ks,{children:Os==="delete"?o("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:_t}):o("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:_t})})]}),s.jsxs(ar,{children:[s.jsx(He,{variant:"outline",size:"sm",onClick:()=>zs(null),children:o("sessions.sidebar.dialogs.cancel")}),s.jsx(He,{variant:"destructive",size:"sm",onClick:()=>{gt()},children:o(Os==="delete"?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive")})]})]})}),s.jsx(Cf,{open:B,onOpenChange:xe,info:be,downloading:!1,downloaded:!1,progress:null,error:ut,onDownload:()=>{},onRestart:()=>{},runtimeType:"web"})]})};function Hb(){}const rd=280,od=280,id=500,Kb=({isOpen:t,isMobile:e,children:n,className:r,topBar:o})=>{const{t:i}=ft(),c=Re(v=>v.sidebarWidth),l=Re(v=>v.setSidebarWidth),[d,u]=a.useState(!1),h=a.useRef(0),f=a.useRef(c||rd),p=a.useRef(null),x=a.useRef(null),b=a.useRef(null),S=a.useCallback(v=>Math.min(id,Math.max(od,v)),[]),g=a.useCallback(v=>{const P=b.current;P&&(P.style.width=`${v}px`,P.style.minWidth=`${v}px`,P.style.maxWidth=`${v}px`,P.style.setProperty("--oc-left-sidebar-width",`${v}px`))},[]);if(a.useEffect(()=>{e&&d&&u(!1)},[e,d]),a.useEffect(()=>{d||(p.current=null,x.current=null)},[d]),e)return null;const m=Math.min(id,Math.max(od,c||rd)),y=t?m:0,C=v=>{if(t){try{v.currentTarget.setPointerCapture(v.pointerId)}catch{}x.current=v.pointerId,u(!0),h.current=v.clientX,f.current=y,p.current=y,g(y),v.preventDefault()}},j=v=>{if(e||!d||x.current!==v.pointerId)return;const P=v.clientX-h.current,F=S(f.current+P);p.current!==F&&(p.current=F,g(F))},w=v=>{if(x.current!==v.pointerId||e)return;try{v.currentTarget.releasePointerCapture(v.pointerId)}catch{}const P=S(p.current??y);x.current=null,p.current=null,u(!1),l(P)},N=d?p.current??y:y;return s.jsxs("aside",{ref:b,className:De("relative flex h-full overflow-hidden border-r border-border will-change-[width] motion-reduce:transition-none","bg-sidebar oc-vibrancy-surface",t&&"shadow-[inset_-2px_0_10px_-2px_rgb(0_0_0_/_0.06)]",!t&&"border-r-0",r),style:{width:`${N}px`,minWidth:`${N}px`,maxWidth:`${N}px`,"--oc-left-sidebar-width":`${d?N:m}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||y===0,children:[t&&s.jsx("div",{className:De("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:C,onPointerMove:j,onPointerUp:w,onPointerCancel:w,role:"separator","aria-orientation":"vertical","aria-label":i("sidebar.resize.leftPanelAria")}),s.jsxs("div",{className:De("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(Cs,{children:n})})]})]})},Gb=()=>{const t=nt.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},ji=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function qb(){const t=ms(f=>f.activeProjectId?f.projects.find(p=>p.id===f.activeProjectId)??null:null),e=et(f=>f.currentSessionId),n=Gh(e??null),r=et(f=>e?f.worktreeMetadata.get(e)?.path??"":""),o=et(f=>f.newSessionDraft?.open?ji(f.newSessionDraft.bootstrapPendingDirectory??f.newSessionDraft.directoryOverride??""):""),i=a.useMemo(()=>ji(r||""),[r]),c=a.useMemo(()=>{const f=typeof n?.directory=="string"?n.directory:"";return ji(f||"")},[n?.directory]),l=i||c||o,d=a.useMemo(()=>ji(l||t?.path||""),[t?.path,l]),u=a.useMemo(()=>t?{id:t.id,path:t.path}:null,[t]),h=a.useRef(null);return a.useEffect(()=>{u&&d&&(h.current={projectRef:u,directory:d})},[d,u]),a.useMemo(()=>u&&d?{projectRef:u,directory:d}:h.current,[u,d])}const ad="app-region-no-drag inline-flex h-8 w-8 items-center justify-center gap-2 rounded-md typography-ui-label font-medium text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary hover:bg-interactive-hover transition-colors",Yb=()=>{const t=nt.c(36),{t:e}=ft(),n=Re(Qb),r=Re(Xb),o=Re(Jb),i=qb(),c=a.useRef(null),l=ga(ro("toggle_sidebar",o)),{usesFramelessChrome:d,side:u}=Lf(),h=ey;let f,p;t[0]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{if(typeof document>"u")return;const _=c.current;if(!_)return;const D=()=>{const T=Math.max(_.getBoundingClientRect().width,_.scrollWidth);document.documentElement.style.setProperty("--oc-titlebar-controls-width",`${Math.round(T)}px`)};if(D(),typeof ResizeObserver>"u")return;const A=new ResizeObserver(D);return A.observe(_),()=>{A.disconnect()}},p=[],t[0]=f,t[1]=p):(f=t[0],p=t[1]),a.useEffect(f,p);const x="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 S="flex items-center gap-2";let g;t[3]!==d||t[4]!==u?(g=d&&u==="left"?s.jsx(Bf,{visible:!0,position:"left"}):null,t[3]=d,t[4]=u,t[5]=g):g=t[5];let m;t[6]!==e||t[7]!==d?(m=d?s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:h,"aria-label":e("header.actions.openAppMenuAria"),className:De(ad,"shrink-0"),children:s.jsx(I,{name:"menu-2",className:"h-[18px] w-[18px]"})})}),s.jsx(At,{children:s.jsx("p",{children:e("header.actions.openAppMenu")})})]}):null,t[6]=e,t[7]=d,t[8]=m):m=t[8];const y=Nt;let C;t[9]!==e?(C=e("header.actions.openSessionsAria"),t[9]=e,t[10]=C):C=t[10];let j,w;t[11]===Symbol.for("react.memo_cache_sentinel")?(j=De(ad,"shrink-0"),w=s.jsx(I,{name:"layout-left",className:"h-[18px] w-[18px]"}),t[11]=j,t[12]=w):(j=t[11],w=t[12]);let N;t[13]!==C||t[14]!==n?(N=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,"aria-label":C,className:j,children:w})}),t[13]=C,t[14]=n,t[15]=N):N=t[15];const v=At,P=e("header.actions.openSessionsWithShortcut",{shortcut:l});let F;t[16]!==P?(F=s.jsx("p",{children:P}),t[16]=P,t[17]=F):F=t[17];let k;t[18]!==v||t[19]!==F?(k=s.jsx(v,{children:F}),t[18]=v,t[19]=F,t[20]=k):k=t[20];let E;t[21]!==y||t[22]!==N||t[23]!==k?(E=s.jsxs(y,{children:[N,k]}),t[21]=y,t[22]=N,t[23]=k,t[24]=E):E=t[24];let O;t[25]!==r||t[26]!==i?(O=i?s.jsx(Uf,{projectRef:i.projectRef,directory:i.directory,className:r?"oc-vibrancy-pill":void 0}):null,t[25]=r,t[26]=i,t[27]=O):O=t[27];let M;t[28]!==E||t[29]!==O||t[30]!==g||t[31]!==m?(M=s.jsxs("div",{ref:c,className:S,children:[g,m,E,O]}),t[28]=E,t[29]=O,t[30]=g,t[31]=m,t[32]=M):M=t[32];let L;return t[33]!==M||t[34]!==b?(L=s.jsx("div",{className:x,style:b,children:M}),t[33]=M,t[34]=b,t[35]=L):L=t[35],L};function Qb(t){return t.toggleSidebar}function Xb(t){return t.isSidebarOpen}function Jb(t){return t.shortcutOverrides}function Zb(t){console.warn("[titlebar] failed to open app menu",t)}function ey(t){const e=t.currentTarget.getBoundingClientRect();Ar("desktop_show_app_menu",{x:e.left,y:e.bottom}).catch(Zb)}const jl=5e3,ty=(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},Si=(t,e)=>Xh(Jh.getState().dictionary,t,e),sy=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"},ny=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 hs(`/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()},nc=async(t,e,n)=>{if(qh(e)||Yh(e)||ko(e))return{ok:!0};try{const r=await ny(t,e,n);return Qh(r)?{ok:!1,reason:"binary"}:ty(r,jl)>jl?{ok:!1,reason:"too-large"}:{ok:!0}}catch(r){return{ok:!1,reason:sy(r)}}},rc=t=>{if(t==="too-large"){const e=jl.toLocaleString(ii());return Si("contextFileOpen.failure.tooLarge",{count:e})}return Si(t==="missing"?"contextFileOpen.failure.missing":t==="binary"?"filesView.editor.cannotPreviewBinary":"contextFileOpen.failure.unreadable")},ld=(t,e)=>{if(e.length===0)return null;let n=null,r=null;for(const i of e)i.top<=t?(!n||i.top>n.top)&&(n=i):(!r||i.top<r.top)&&(r=i);const o=n??r;return o?{path:o.path,topOffset:o.top-t}:null},ry=(t,e,n,r)=>Math.min(Math.max(0,r),Math.max(0,t+n-e)),oy=64,iy=3,Jr=new Map,em=(t,e,n=iy)=>{const r=`${t}\0${n}\0${e}`,o=Jr.get(r);if(o)return Jr.delete(r),Jr.set(r,o),o;const i=ly(e),c=i?Ex(Fx(e,n),{oldFile:{name:t,contents:i.before},newFile:{name:t,contents:i.after}})??dd(t):Ox(ay(t,e))[0]?.files[0]??dd(t);for(Jr.set(r,c);Jr.size>oy;){const l=Jr.keys().next().value;if(!l)break;Jr.delete(l)}return c},ay=(t,e)=>!e.trim()||e.startsWith("diff --git ")||/^--- [^\n]*\r?\n\+\+\+ /m.test(e)?e:`Index: ${t}
38
- ===================================================================
39
- --- ${t}
40
- +++ ${t}
41
- ${e}`,ly=t=>{if(!t.startsWith("diff --git ")&&!/^--- [^\n]*\t?\r?\n\+\+\+ [^\n]*\t?(?:\r?\n|$)/m.test(t))return;const e=[...t.matchAll(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@[^\n]*(?:\r?\n|$)/gm)];if(e.length!==1)return;const n=e[0],r=Number.parseInt(n[1]??"",10),o=Number.parseInt(n[2]??"",10);if(r>1||o>1||!Number.isFinite(r)||!Number.isFinite(o))return;const i=(n.index??0)+n[0].length,c=t.slice(i),l=[],d=[];let u;for(const h of c.split(/\r?\n/)){if(h.startsWith("diff --git ")||h.startsWith("@@ "))break;if(h.startsWith("\\")){if(u==="-"||u===" "){const f=l.at(-1);f&&(f.newline=!1)}if(u==="+"||u===" "){const f=d.at(-1);f&&(f.newline=!1)}continue}if(h.startsWith("-")){l.push({text:h.slice(1),newline:!0}),u="-";continue}if(h.startsWith("+")){d.push({text:h.slice(1),newline:!0}),u="+";continue}h.startsWith(" ")&&(l.push({text:h.slice(1),newline:!0}),d.push({text:h.slice(1),newline:!0}),u=" ")}return{before:cd(l),after:cd(d)}},cd=t=>t.map(e=>e.text+(e.newline?`
42
- `:"")).join(""),dd=t=>Lx({name:t,contents:""},{name:t,contents:""}),oc="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)]";class tm 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 Ia="/api/walkthrough",ic=async(t,e)=>{const n=await t.json().catch(()=>null);throw new tm(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})};async function cy(t,e,n={}){const r=await hs(Ia,{query:{directory:t,source:JSON.stringify(e),...n.model?{model:n.model}:{},...n.language?{language:n.language}:{}},signal:n.signal});return r.ok?r.json():ic(r,"Failed to load walkthrough")}async function dy(t,e,n={}){const r=await hs(`${Ia}/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?r.json():ic(r,"Failed to generate walkthrough")}async function uy(t,e){const n=await hs(`${Ia}/cancel`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:t,source:e})});n.ok||await ic(n,"Failed to cancel walkthrough generation")}async function fy(t,e,n){const r=await hs(`${Ia}/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 Yo={status:"idle",stage:null,result:null,readiness:null,error:null},my=t=>t.kind==="working-tree"?`working-tree:${t.scope}`:t.kind==="branch"?`branch:${t.baseRef}...${t.headRef}`:`pr:${t.number}`,Or=(t,e)=>`${$n()}\0${t}\0${my(e)}`,ud=t=>t instanceof tm?{message:t.message,code:t.code,model:t.model,requiredChars:t.requiredChars,availableChars:t.availableChars}:{message:t instanceof Error?t.message:"Something went wrong"},Hn=new Map,Qo=new Map,hy=1e3,Tn=$o()(_f((t,e)=>({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{},selectLanguage:(n,r,o)=>{const i=Or(n,r);t(c=>{const l={...c.selectedLanguage};return o?l[i]=o:delete l[i],{selectedLanguage:l}})},getSelectedLanguage:(n,r)=>e().selectedLanguage[Or(n,r)],selectModel:(n,r,o)=>{const i=Or(n,r);t(c=>{const l={...c.selectedModel};return o?l[i]=o:delete l[i],{selectedModel:l}})},getSelectedModel:(n,r)=>e().selectedModel[Or(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[Or(n,r)]??Yo,load:async(n,r,o={})=>{if(!n)return;const i=Or(n,r);if(e().entries[i]?.status==="generating")return;Hn.get(i)?.abort();const l=new AbortController;Hn.set(i,l),t(d=>({entries:{...d.entries,[i]:{...d.entries[i]??Yo,status:"loading",error:null}}}));try{const d=await cy(n,r,{model:e().selectedModel[i],language:o.language,signal:l.signal});if(l.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(l.signal.aborted)return;t(u=>({entries:{...u.entries,[i]:{...u.entries[i]??Yo,status:"error",stage:null,error:ud(d)}}}))}finally{Hn.get(i)===l&&Hn.delete(i)}},generate:async(n,r,o={})=>{if(!n)return;const i=Or(n,r);Hn.get(i)?.abort();const c=new AbortController;Hn.set(i,c),t(d=>({entries:{...d.entries,[i]:{...d.entries[i]??Yo,status:"generating",stage:"collecting",error:null}}}));const l=()=>{const d=Qo.get(i);d!==void 0&&(clearInterval(d),Qo.delete(i))};l(),Qo.set(i,setInterval(()=>{fy(n,r).then(d=>{!d||c.signal.aborted||t(u=>{const h=u.entries[i];return!h||h.status!=="generating"||h.stage===d?u:{entries:{...u.entries,[i]:{...h,stage:d}}}})}).catch(()=>{})},hy));try{const d=await dy(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]??Yo,status:"error",stage:null,error:ud(d)}}}))}finally{l(),Hn.get(i)===c&&Hn.delete(i)}},cancel:(n,r)=>{const o=Or(n,r);uy(n,r).catch(()=>{}),Hn.get(o)?.abort(),Hn.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 Hn.values())n.abort();Hn.clear();for(const n of Qo.values())clearInterval(n);Qo.clear(),t({entries:{},requestedSource:{},selectedModel:{},selectedLanguage:{}})}}),{name:"walkthrough-store"})),fd=t=>{if(!t)return null;const e=t.split(`
43
- `);let n=null;for(const r of e){const o=r.match(/^@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/);if(o){const i=Number.parseInt(o[1]??"",10);n=Number.isFinite(i)&&i>=1?i:null;continue}if(n!==null){if(r.startsWith(" ")){n+=1;continue}if(r.startsWith("+"))return n;if(r.startsWith("-"))return Math.max(1,n)}}return null},py=1100,gy=15e3,md=500,hd=300,xy=1e6,by=3,yy=t=>t<=6?t:t<=12?6:t<=25?4:2,wy=a.memo(()=>{const t=nt.c(4),{t:e}=ft();let n;t[0]!==e?(n=e("diffView.binary.unavailable"),t[0]=e,t[1]=n):n=t[1];let r;return t[2]!==n?(r=s.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:s.jsx("div",{className:"typography-meta text-muted-foreground",children:n})}),t[2]=n,t[3]=r):r=t[3],r}),sm={"?":{code:"?",color:"var(--status-info)",descriptionKey:"diffView.change.untracked"},A:{code:"A",color:"var(--status-success)",descriptionKey:"diffView.change.new"},D:{code:"D",color:"var(--status-error)",descriptionKey:"diffView.change.deleted"},R:{code:"R",color:"var(--status-info)",descriptionKey:"diffView.change.renamed"},C:{code:"C",color:"var(--status-info)",descriptionKey:"diffView.change.copied"},M:{code:"M",color:"var(--status-warning)",descriptionKey:"diffView.change.modified"}},vy=sm.M,jy=t=>{const e=t.index?.trim(),n=t.working_dir?.trim();return e&&e!=="?"?e.charAt(0):n?n.charAt(0):e?.charAt(0)||n?.charAt(0)||"M"},nm=t=>{const e=jy(t);return sm[e]??vy},Sy=t=>{const{index:e,working_dir:n}=t;return e==="A"||n==="A"||e==="?"||n==="?"},pd=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},gd=t=>!!t.working_dir?.trim()||t.index==="?",ky=(t,e)=>sp(t,e),xd=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),bd=(t,e)=>{const n=t.split(`
44
- `),r=e.split(`
45
- `),o=Math.min(n.length,r.length);for(let i=0;i<o;i+=1)if(n[i]!==r[i])return i+1;return r.length>n.length?n.length+1:n.length>r.length?Math.max(1,r.length):1},Ny=t=>/^Binary files .+ differ$/m.test(t)||/^GIT binary patch$/m.test(t),Cy=t=>Array.isArray(t)?t.filter(e=>!e||typeof e!="object"?!1:typeof e.file=="string"):[],Ay=t=>t==="added"?"A":t==="deleted"?"D":"M",rm=(t,e,n)=>Ny(e)?{original:"",modified:"",isBinary:!0,patch:e,contextMode:n}:{original:"",modified:"",patch:e,fileDiff:em(t,e),contextMode:n},om=(t,e,n)=>{const r=t??0,o=e??0;return!r&&!o?null:s.jsxs("span",{className:De("typography-meta flex items-center gap-1 text-xs whitespace-nowrap","flex-shrink-0",n?.className),children:[r?s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",r]}):null,o?s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",o]}):null]})},Dy=a.memo(t=>{const e=nt.c(53),{scope:n,workingCount:r,stagedCount:o,turnCount:i,onScopeChange:c}=t,{t:l}=ft(),[d,u]=a.useState(!1),h=n==="staged"?o:n==="turn"?i:r;let f;e[0]!==n||e[1]!==l?(f=l(n==="staged"?"diffView.scope.staged":n==="turn"?"diffView.scope.lastTurn":"diffView.scope.changed"),e[0]=n,e[1]=l,e[2]=f):f=e[2];const p=f;let x;e[3]!==l?(x=l("diffView.scope.selectorAria"),e[3]=l,e[4]=x):x=e[4];let b;e[5]!==h?(b=s.jsxs("span",{className:"diff-toolbar__scope-count",children:[": ",h]}),e[5]=h,e[6]=b):b=e[6];let S;e[7]!==p||e[8]!==b?(S=s.jsxs("span",{className:"whitespace-nowrap",children:[p,b]}),e[7]=p,e[8]=b,e[9]=S):S=e[9];let g;e[10]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx(I,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-60"}),e[10]=g):g=e[10];let m;e[11]!==x||e[12]!==S?(m=s.jsx(qs,{asChild:!0,children:s.jsxs("button",{type:"button",className:"flex h-7 flex-shrink-0 items-center gap-1.5 rounded-md px-2 typography-ui-label font-semibold text-foreground outline-none hover:bg-interactive-hover focus-visible:ring-2 focus-visible:ring-ring","aria-label":x,children:[S,g]})}),e[11]=x,e[12]=S,e[13]=m):m=e[13];let y;e[14]!==c?(y=A=>{(A==="working"||A==="staged"||A==="turn")&&(c?.(A),u(!1))},e[14]=c,e[15]=y):y=e[15];let C;e[16]!==l?(C=l("diffView.scope.changed"),e[16]=l,e[17]=C):C=e[17];let j;e[18]!==C?(j=s.jsx("span",{children:C}),e[18]=C,e[19]=j):j=e[19];let w;e[20]!==r?(w=s.jsx("span",{className:"typography-meta text-muted-foreground",children:r}),e[20]=r,e[21]=w):w=e[21];let N;e[22]!==w||e[23]!==j?(N=s.jsx(oo,{value:"working",children:s.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[j,w]})}),e[22]=w,e[23]=j,e[24]=N):N=e[24];let v;e[25]!==l?(v=l("diffView.scope.staged"),e[25]=l,e[26]=v):v=e[26];let P;e[27]!==v?(P=s.jsx("span",{children:v}),e[27]=v,e[28]=P):P=e[28];let F;e[29]!==o?(F=s.jsx("span",{className:"typography-meta text-muted-foreground",children:o}),e[29]=o,e[30]=F):F=e[30];let k;e[31]!==P||e[32]!==F?(k=s.jsx(oo,{value:"staged",children:s.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[P,F]})}),e[31]=P,e[32]=F,e[33]=k):k=e[33];let E;e[34]!==l?(E=l("diffView.scope.lastTurn"),e[34]=l,e[35]=E):E=e[35];let O;e[36]!==E?(O=s.jsx("span",{children:E}),e[36]=E,e[37]=O):O=e[37];let M;e[38]!==i?(M=s.jsx("span",{className:"typography-meta text-muted-foreground",children:i}),e[38]=i,e[39]=M):M=e[39];let L;e[40]!==O||e[41]!==M?(L=s.jsx(oo,{value:"turn",children:s.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[O,M]})}),e[40]=O,e[41]=M,e[42]=L):L=e[42];let _;e[43]!==n||e[44]!==N||e[45]!==k||e[46]!==L||e[47]!==y?(_=s.jsx(Ys,{align:"start",className:"w-40",children:s.jsxs(fl,{value:n,onValueChange:y,children:[N,k,L]})}),e[43]=n,e[44]=N,e[45]=k,e[46]=L,e[47]=y,e[48]=_):_=e[48];let D;return e[49]!==d||e[50]!==_||e[51]!==m?(D=s.jsxs(Qs,{open:d,onOpenChange:u,children:[m,_]}),e[49]=d,e[50]=_,e[51]=m,e[52]=D):D=e[52],D}),Py=a.memo(t=>{const e=nt.c(11),{changedFiles:n,selectedFile:r,onSelectFile:o}=t,{t:i}=ft();if(n.length===0)return null;let c;if(e[0]!==n||e[1]!==o||e[2]!==r||e[3]!==i){let d;e[5]!==o||e[6]!==r||e[7]!==i?(d=u=>{const h=nm(u),f=r===u.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>o(u.path),className:De("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",f?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[s.jsx(Lo,{filePath:u.path,className:"h-3.5 w-3.5 flex-shrink-0"}),s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:h.color},title:i(h.descriptionKey),"aria-label":i(h.descriptionKey),children:h.code}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:u.path,children:u.path}),om(u.insertions,u.deletions)]})},u.path)},e[5]=o,e[6]=r,e[7]=i,e[8]=d):d=e[8],c=n.map(d),e[0]=n,e[1]=o,e[2]=r,e[3]=i,e[4]=c}else c=e[4];let l;return e[9]!==c?(l=s.jsx(On,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:s.jsx("ul",{className:"flex flex-col gap-1",children:c})}),e[9]=c,e[10]=l):l=e[10],l}),Iy=a.memo(t=>{const e=nt.c(20),{filePath:n,diff:r,renderSideBySide:o}=t,{t:i}=ft(),c=r.original.length>0,l=r.modified.length>0,d=o?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",u=o?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let h;e[0]===Symbol.for("react.memo_cache_sentinel")?(h={contain:"layout"},e[0]=h):h=e[0];let f;e[1]!==r.original||e[2]!==n||e[3]!==c||e[4]!==u||e[5]!==o||e[6]!==i?(f=c&&s.jsxs("div",{className:u,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i("diffView.image.original")}),s.jsx("img",{src:r.original,alt:i("diffView.image.originalAlt",{path:n}),className:o?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=r.original,e[2]=n,e[3]=c,e[4]=u,e[5]=o,e[6]=i,e[7]=f):f=e[7];let p;e[8]!==r.modified||e[9]!==n||e[10]!==l||e[11]!==c||e[12]!==u||e[13]!==o||e[14]!==i?(p=l&&s.jsxs("div",{className:u,children:[s.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:i(c?"diffView.image.modified":"diffView.image.new")}),s.jsx("img",{src:r.modified,alt:i("diffView.image.modifiedAlt",{path:n}),className:o?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=r.modified,e[9]=n,e[10]=l,e[11]=c,e[12]=u,e[13]=o,e[14]=i,e[15]=p):p=e[15];let x;return e[16]!==d||e[17]!==f||e[18]!==p?(x=s.jsx("div",{className:"w-full overflow-auto p-4",style:h,children:s.jsxs("div",{className:d,children:[f,p]})}),e[16]=d,e[17]=f,e[18]=p,e[19]=x):x=e[19],x}),Ry=a.memo(t=>{const e=nt.c(16),{filePath:n,diff:r,renderSideBySide:o,wrapLines:i}=t;let c;e[0]!==n?(c=zl(n)||"text",e[0]=n,e[1]=c):c=e[1];const l=c;if(r.isBinary){let h;return e[2]===Symbol.for("react.memo_cache_sentinel")?(h=s.jsx(wy,{}),e[2]=h):h=e[2],h}if(ko(n)){let h;return e[3]!==r||e[4]!==n||e[5]!==o?(h=s.jsx(Iy,{filePath:n,diff:r,renderSideBySide:o}),e[3]=r,e[4]=n,e[5]=o,e[6]=h):h=e[6],h}let d;e[7]===Symbol.for("react.memo_cache_sentinel")?(d={contain:"layout"},e[7]=d):d=e[7];let u;return e[8]!==r.fileDiff||e[9]!==r.modified||e[10]!==r.original||e[11]!==n||e[12]!==l||e[13]!==o||e[14]!==i?(u=s.jsx("div",{className:"w-full",style:d,children:s.jsx(Zl,{original:r.original,modified:r.modified,fileDiff:r.fileDiff,language:l,fileName:n,renderSideBySide:o,wrapLines:i,layout:"inline"})}),e[8]=r.fileDiff,e[9]=r.modified,e[10]=r.original,e[11]=n,e[12]=l,e[13]=o,e[14]=i,e[15]=u):u=e[15],u}),My=a.memo(t=>{const e=nt.c(7),{filePath:n,staged:r,busyAction:o,disabled:i,onAction:c}=t,{t:l}=ft();let d;return e[0]!==o||e[1]!==i||e[2]!==n||e[3]!==c||e[4]!==r||e[5]!==l?(d=s.jsx("div",{className:"flex items-center gap-0.5 rounded-full border border-[var(--interactive-border)]/45 bg-[var(--surface-background)]/95 px-1 py-0.5 shadow-lg backdrop-blur-md",children:r?s.jsx(za,{label:l("gitView.changes.unstageFileAria",{path:n}),icon:"arrow-go-back",loading:o==="unstage",disabled:i,onClick:()=>c("unstage")}):s.jsxs(s.Fragment,{children:[s.jsx(za,{label:l("gitView.changes.revertFileAria",{path:n}),icon:"arrow-go-back",loading:o==="discard",disabled:i,tone:"failure",onClick:()=>c("discard")}),s.jsx(za,{label:l("gitView.changes.stageFileAria",{path:n}),icon:"add",loading:o==="stage",disabled:i,tone:"success",onClick:()=>c("stage")})]})}),e[0]=o,e[1]=i,e[2]=n,e[3]=c,e[4]=r,e[5]=l,e[6]=d):d=e[6],d}),za=t=>{const e=nt.c(14),{label:n,icon:r,loading:o,disabled:i,tone:c,onClick:l}=t,d=c==="failure"&&"text-[var(--status-error)] hover:text-[var(--status-error)]",u=c==="success"&&"text-[var(--status-success)] hover:text-[var(--status-success)]";let h;e[0]!==d||e[1]!==u?(h=De("h-6 w-6 rounded-none bg-transparent p-0 text-muted-foreground opacity-70 hover:bg-transparent hover:text-foreground hover:opacity-100",d,u),e[0]=d,e[1]=u,e[2]=h):h=e[2];let f;e[3]!==l?(f=b=>{b.stopPropagation(),l()},e[3]=l,e[4]=f):f=e[4];let p;e[5]!==r||e[6]!==o?(p=o?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:r,className:r==="add"?"size-4":"size-3.5"}),e[5]=r,e[6]=o,e[7]=p):p=e[7];let x;return e[8]!==i||e[9]!==n||e[10]!==h||e[11]!==f||e[12]!==p?(x=s.jsx(He,{variant:"ghost",size:"sm",className:h,disabled:i,title:n,"aria-label":n,onClick:f,children:p}),e[8]=i,e[9]=n,e[10]=h,e[11]=f,e[12]=p,e[13]=x):x=e[13],x},Ty=a.memo(({directory:t,file:e,layout:n,wrapLines:r,isSelected:o,isExpanded:i,isMounted:c,onSelect:l,onExpandedChange:d,registerSectionRef:u,showOpenInEditorAction:h=!1,isOpeningInEditor:f=!1,onOpenInEditor:p,staged:x=!1,loadFullFiles:b=!1,initialDiffData:S=null})=>{const{t:g}=ft(),{git:m}=_n(),y=tn(a.useCallback(Q=>Q.directories.get(t)?.diffCache.get(e.path)??null,[t,e.path])),C=tn(Q=>Q.setDiff),j=tn(Q=>Q.fetchStatus),w=Re(Q=>Q.setDiffFileLayout),[N,v]=a.useState(0),[P,F]=a.useState(null),[k,E]=a.useState(!1),[O,M]=a.useState(null),[L,_]=a.useState(!1),[D,A]=a.useState(null),[T,z]=a.useState(null),R=a.useRef(null),W=a.useRef(null),J=a.useMemo(()=>nm(e),[e]),U=n==="side-by-side",te=b?"full":"patch",Z=`${e.index}:${e.working_dir}:${e.insertions}:${e.deletions}`,ue=a.useMemo(()=>S||(x?T:D||(y?{original:y.original,modified:y.modified,isBinary:y.isBinary,contextMode:"full"}:null)),[y,S,D,x,T]),Oe=ue?.contextMode===te,se=a.useCallback(Q=>{W.current=Q,u(e.path,Q)},[e.path,u]),G=a.useCallback(Q=>{d(e.path,Q)},[e.path,d]),Ie=a.useCallback(()=>{l(e.path)},[e.path,l]);a.useEffect(()=>{x?z(null):A(null),F(null),R.current=null},[Z,x]),a.useEffect(()=>{if(!i||!c)return;if(!t||S||ue&&Oe){R.current=null,E(!1);return}const Q=`${t}::${e.path}::${x?"staged":"unstaged"}::${Z}::${te}::${N}`;if(R.current===Q)return;R.current=Q,F(null),E(!0);let ne=!1;const oe=$n(),ce=b?xy:by,ke=ko(e.path)?m.getGitFileDiff(t,{path:e.path,staged:x}):m.getGitDiff(t,{path:e.path,staged:x,contextLines:ce}),ye=gy,he=new Promise((Ee,Ue)=>{setTimeout(()=>Ue(new Error(`Timed out after ${ye}ms`)),ye)});return Promise.race([ke,he]).then(Ee=>{if(!ne){if("diff"in Ee){const Ue=rm(e.path,Ee.diff,te);x?z(Ue):A(Ue)}else{const Ue={original:Ee.original??"",modified:Ee.modified??"",isBinary:Ee.isBinary,contextMode:"full"};x?z(Ue):C(t,e.path,Ue,oe)}E(!1)}}).catch(Ee=>{if(ne)return;const Ue=Ee instanceof Error?Ee.message:String(Ee);F(Ue),E(!1)}),()=>{ne=!0,R.current===Q&&(R.current=null)}},[te,ue,Oe,N,t,e.path,Z,m,S,i,c,b,C,x]);const pe=a.useCallback(()=>{G(!i),Ie()},[G,Ie,i]),V=a.useCallback(async Q=>{if(!(!t||O!==null)){M(Q);try{Q==="stage"?await m.stageGitFile(t,e.path):Q==="unstage"?await m.unstageGitFile(t,e.path):await m.revertGitFile(t,e.path,{scope:"working"}),v(ne=>ne+1),await j(t,m)}catch(ne){const oe=Q==="unstage"?"gitView.toast.unstageFileFailed":Q==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.revertFailed";fe.error(ne instanceof Error?ne.message:g(oe))}finally{M(ne=>ne===Q?null:ne)}}},[t,j,e.path,O,m,g]);return s.jsxs("div",{ref:se,className:"scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0",children:[s.jsx("div",{className:"sticky top-0 z-30 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80",children:s.jsxs("div",{role:"button",tabIndex:0,onClick:pe,onKeyDown:Q=>{Q.target===Q.currentTarget&&(Q.key==="Enter"||Q.key===" ")&&(Q.preventDefault(),pe())},className:De("cursor-pointer","group/header relative grid min-h-9 w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2 overflow-hidden px-3 py-2","bg-transparent","text-muted-foreground hover:text-foreground",o?"bg-[var(--interactive-selection)]/35":null),children:[s.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-[var(--interactive-hover)]/50"}),s.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[s.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:i?s.jsx(I,{name:"arrow-down-s",className:"size-4"}):s.jsx(I,{name:"arrow-right-s",className:"size-4"})}),s.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:{color:J.color},title:g(J.descriptionKey),"aria-label":g(J.descriptionKey),children:J.code}),s.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:e.path,children:s.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[s.jsx(Lo,{filePath:e.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),(()=>{const Q=e.path.lastIndexOf("/");if(Q===-1)return s.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:e.path});const ne=e.path.slice(0,Q),oe=e.path.slice(Q+1);return s.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:ne}),s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[s.jsx("span",{className:"text-muted-foreground",children:"/"}),s.jsx("span",{className:"text-foreground",children:oe})]})]})})()]})})]}),s.jsxs("div",{className:"relative flex shrink-0 items-center justify-self-end gap-2",children:[om(e.insertions,e.deletions),h&&p?s.jsx(He,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:g("diffView.actions.openFileInEditorAtChange"),onClick:Q=>{Q.stopPropagation(),p(e.path,ue)},disabled:f,children:f?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"edit",className:"size-3.5"})}):null,s.jsx(rf,{mode:U?"side-by-side":"unified",onModeChange:Q=>{const ne=Q==="side-by-side"?"side-by-side":"inline";w(e.path,ne)},className:"opacity-70"})]})]})}),i&&s.jsxs("div",{className:"relative bg-background overflow-hidden",children:[!c&&!P?s.jsx("div",{className:"h-40 border border-border/40 bg-background/40"}):null,P?s.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:g("diffView.state.failedToLoadDiff")}),s.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:P}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>v(Q=>Q+1),children:g("diffView.actions.retry")})]}):null,c&&k&&!ue&&!P?s.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),g("diffView.state.loadingDiff")]}):null,c&&ue&&!L&&e.insertions+e.deletions>md?s.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:g("diffView.state.largeDiff",{count:e.insertions+e.deletions})}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:g("diffView.state.largeDiffDescription")}),s.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>_(!0),children:g("diffView.actions.renderAnyway")})]}):null,c&&ue&&(L||e.insertions+e.deletions<=md)?s.jsxs(s.Fragment,{children:[s.jsx(Ry,{filePath:e.path,diff:ue,renderSideBySide:U,wrapLines:r}),s.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-20",children:s.jsx("div",{className:"pointer-events-auto",children:s.jsx(My,{filePath:e.path,staged:x,busyAction:O,disabled:O!==null,onAction:V})})})]}):null]})]})}),im=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:e=!1,pinSelectedFileHeaderToTopOnNavigate:n=!1,showOpenInEditorAction:r=!1,diffScope:o="all",onDiffScopeChange:i,targetFilePath:c=null,flushContent:l=!1})=>{const{t:d}=ft(),{git:u,files:h}=_n(),f=Wr(),p=Re(je=>je.openContextSurface),x=Tn(je=>je.requestSource),{screenWidth:b,isMobile:S}=Pr(),g=Vl(f??null),m=Bo(f??null),y=Wl(f??null),C=tn(je=>je.setActiveDirectory),j=tn(je=>je.ensureStatus),w=tn(je=>je.fetchStatus),N=tn(je=>je.clearDiffCache),v=tn(je=>je.setDiff),[P,F]=a.useState(null),[k,E]=a.useState(!1),[O,M]=a.useState(null),[L,_]=a.useState(()=>new Set),[D,A]=a.useState(()=>new Set),[T,z]=a.useState(!1),[R,W]=a.useState(0),[J,U]=a.useState(()=>new Map),[te,Z]=a.useState(!1),[ue,Oe]=a.useState(!1),[se,G]=a.useState(o);a.useEffect(()=>{G(o)},[o]);const Ie=Re(je=>je.pendingDiffFile),pe=Re(je=>je.pendingDiffStaged),V=Re(je=>je.pendingDiffScope),Q=Re(je=>je.setPendingDiffFile),ne=Re(je=>je.diffLayoutPreference),oe=Re(je=>je.diffFileLayout),ce=Re(je=>je.setDiffFileLayout),ke=Re(je=>je.diffWrapLines),ye=Re(je=>je.setDiffWrapLines),he=Re(je=>je.openContextFileAtLine),Ee=et(je=>je.currentSessionId),Ue=Zh(Ee??"",f??void 0),Me=ke,X=se==="staged"?!0:se==="working"?!1:null,Ne=X??k,Ae=S||b<=768,Se=!!Ee&&se!=="turn"&&!Ae&&!ir(),le=se!=="turn"&&!Ae&&!ir(),ee=!t&&!Ae&&b>=1024,ie=a.useRef(null),ve=a.useRef(new Map),K=a.useRef(null),de=a.useRef(null),_e=a.useRef(!1),Pe=a.useRef(null),re=a.useRef(null),me=a.useRef(null),ge=a.useRef(null),$=a.useCallback(()=>{const je=ie.current;if(!je)return null;const Fe=je.getBoundingClientRect().top,Te=[];for(const[it,ct]of ve.current)ct&&Te.push({path:it,top:ct.getBoundingClientRect().top});return ld(Fe,Te)},[]),B=a.useCallback(()=>{K.current=null,_e.current=!1,M(null),de.current!==null&&(window.cancelAnimationFrame(de.current),de.current=null)},[]),xe=a.useCallback(je=>{_(Fe=>{if(Fe.has(je))return Fe;const Te=new Set(Fe);return Te.add(je),Te})},[]),be=a.useMemo(()=>{for(let je=Ue.length-1;je>=0;je-=1){const Fe=Ue[je];if(Fe.role==="user")return Cy(Fe.summary?.diffs)}return[]},[Ue]),Le=a.useMemo(()=>{const je=new Map;for(const Fe of be)if(Fe.file){if(typeof Fe.patch=="string"){je.set(Fe.file,rm(Fe.file,Fe.patch,"patch"));continue}je.set(Fe.file,{original:Fe.before??"",modified:Fe.after??"",contextMode:"full"})}return je},[be]),Ke=a.useMemo(()=>{if(se==="turn")return be.map(Te=>({path:Te.file??"",index:"",working_dir:Ay(Te.status),insertions:Te.additions??0,deletions:Te.deletions??0,isNew:Te.status==="added"})).filter(Te=>Te.path).sort((Te,it)=>Te.path.localeCompare(it.path));if(!m?.files)return[];const je=m.diffStats??{},Fe=se==="staged"?pd:se==="working"?gd:()=>!0;return m.files.filter(Fe).map(Te=>({...Te,insertions:je[Te.path]?.insertions??0,deletions:je[Te.path]?.deletions??0,isNew:Sy(Te)})).sort((Te,it)=>Te.path.localeCompare(it.path))},[se,be,m]),st=a.useMemo(()=>m?.files?m.files.filter(gd).length:0,[m]),ut=a.useMemo(()=>m?.files?m.files.filter(pd).length:0,[m]),mt=be.length,pt=a.useMemo(()=>Ke.map(je=>je.path).join("\0"),[Ke]);a.useEffect(()=>{const je=pt?pt.split("\0"):[],Fe=new Set(je),Te=`${f??""}:${se}:${e?"collapsed":"default"}`,it=re.current!==Te;re.current=Te,_(ct=>{if(it){const ze=e?0:yy(je.length);return new Set(je.slice(0,ze))}let Kt=!1;const Lt=new Set;for(const ze of ct){if(!Fe.has(ze)){Kt=!0;continue}Lt.add(ze)}return Kt?Lt:ct}),A(ct=>{if(it)return new Set;let Kt=!1;const Lt=new Set;for(const ze of ct){if(!Fe.has(ze)){Kt=!0;continue}Lt.add(ze)}return Kt?Lt:ct})},[se,pt,f,e]);const ht=a.useCallback(()=>{Pe.current=null;const je=ie.current;if(!je)return;const Fe=je.getBoundingClientRect(),Te=Fe.top-hd,it=Fe.bottom+hd,ct={},Kt=[];for(const[Lt,ze]of ve.current){if(!ze)continue;const Xe=ze.getBoundingClientRect();Kt.push({path:Lt,top:Xe.top}),L.has(Lt)&&(Xe.bottom<Te||Xe.top>it||(ct[Lt]=!0))}me.current=ld(Fe.top,Kt),A(Lt=>{let ze=!1;const Xe=new Set(Lt);for(const tt of Object.keys(ct))Xe.has(tt)||(Xe.add(tt),ze=!0);return ze?Xe:Lt})},[L]),xt=a.useCallback(()=>{typeof window>"u"||Pe.current===null&&(Pe.current=window.requestAnimationFrame(ht))},[ht]);a.useEffect(()=>{const je=ie.current;if(je)return xt(),je.addEventListener("scroll",xt,{passive:!0}),window.addEventListener("resize",xt),()=>{je.removeEventListener("scroll",xt),window.removeEventListener("resize",xt),Pe.current!==null&&(window.cancelAnimationFrame(Pe.current),Pe.current=null)}},[Ke,L,xt]);const wt=a.useCallback(je=>{const Fe=oe[je.path];if(Fe)return Fe;if(ne==="inline")return"inline";if(ne==="side-by-side")return"side-by-side";const Te=b<py;return je.isNew||Te?"inline":"side-by-side"},[oe,ne,b]),bt=a.useMemo(()=>Ke.length===0?null:Ke.every(je=>wt(je)==="side-by-side")?"side-by-side":"inline",[Ke,wt]);a.useEffect(()=>{f&&(C(f),j(f,u))},[f,C,j,u]),a.useEffect(()=>{if(f)return Kn.onGitRefreshHint(je=>{xd(je.directory)===xd(f)&&(je.paths?.length&&(ge.current=$()??me.current,N(f,je.paths),U(Fe=>{const Te=new Map(Fe);for(const it of je.paths??[])Te.set(it,(Te.get(it)??0)+1);return Te})),w(f,u,{silent:!0}))})},[$,N,f,w,u]),a.useLayoutEffect(()=>{const je=ge.current;if(!je)return;ge.current=null;const Fe=ie.current,Te=ve.current.get(je.path);if(!Fe||!Te)return;const it=Fe.getBoundingClientRect().top,ct=Te.getBoundingClientRect().top-it;Fe.scrollTop=ry(Fe.scrollTop,je.topOffset,ct,Fe.scrollHeight-Fe.clientHeight),me.current=je},[J]),a.useEffect(()=>{se!=="all"&&!V||Ie&&(V&&G(V),F(Ie),E(V==="staged"||!V&&pe),Q(null),_e.current=!0,K.current=Ie,xe(Ie),W(je=>je+1))},[se,xe,Ie,V,pe,Q]),a.useEffect(()=>{if(se==="all")return;const je=c?.trim();je&&(F(je),E(se==="staged"),_e.current=!0,K.current=je,xe(je),W(Fe=>Fe+1))},[se,xe,c]),a.useEffect(()=>{if(!P)return;Ke.some(Fe=>Fe.path===P)||(F(null),E(!1))},[Ke,P]);const Dt=a.useCallback((je,Fe)=>{const Te=ve.current;Fe?Te.set(je,Fe):Te.delete(je),xt()},[xt]),qt=a.useCallback((je,Fe)=>{B(),_(Te=>{const it=Te.has(je);if(Fe===it)return Te;const ct=new Set(Te);return Fe?ct.add(je):ct.delete(je),ct}),Fe||A(Te=>{if(!Te.has(je))return Te;const it=new Set(Te);return it.delete(je),it}),xt()},[B,xt]),Ut=a.useCallback(()=>{B(),_(je=>je.size>0?new Set:new Set(Ke.map(Fe=>Fe.path))),A(new Set),xt()},[B,Ke,xt]),We=a.useCallback(async je=>{if(!Ee)return;const Fe=et.getState().getDirectoryForSession(Ee)||f||"";if(!Fe){fe.error(d("diffView.reviewDialog.toast.noSessionDirectory"));return}Oe(!0);try{await ep({originalSessionID:Ee,directory:Fe,providerID:je.providerID,modelID:je.modelID,agent:je.agent||void 0,variant:je.variant||void 0,generateHandoff:je.generateHandoff,returnAfterHandoffRequest:je.generateHandoff,autoReview:je.autoReview}),Z(!1)}catch(Te){console.error("[review-flow] failed to start review flow",Te),fe.error(Te instanceof Error?Te.message:d("diffView.reviewDialog.toast.startFailed"))}finally{Oe(!1)}},[Ee,f,d]),yt=a.useCallback(je=>{const Fe=ve.current.get(je),Te=ie.current;if(!Fe||!Te)return!1;const it=Fe.getBoundingClientRect().top-Te.getBoundingClientRect().top;return Te.scrollTo({top:Te.scrollTop+it,behavior:"auto"}),!0},[]);a.useEffect(()=>{if(!K.current)return;let Fe=0;const Te=20;let it=!1;const ct=(Lt=!0)=>{it||(it=!0,K.current=null,_e.current=!1,Lt&&M(null),de.current!==null&&(window.cancelAnimationFrame(de.current),de.current=null))},Kt=()=>{if(it){de.current=null;return}const Lt=K.current;if(!Lt){ct(),de.current=null;return}if(!yt(Lt)){Fe+=1,Fe<Te?de.current=window.requestAnimationFrame(Kt):(ct(),de.current=null);return}if(n&&_e.current){M(Lt),ct(!1);return}ct()};return de.current=window.requestAnimationFrame(Kt),()=>{it=!0,de.current!==null&&(window.cancelAnimationFrame(de.current),de.current=null)}},[n,R,yt]);const Qe=a.useCallback(je=>{},[]),Rt=a.useCallback(je=>{B(),F(je),E(!1),_e.current=!0,K.current=je,xe(je),W(Fe=>Fe+1),yt(je)},[B,xe,yt]),Ot=a.useCallback(je=>{const Fe=je==="side-by-side"?"side-by-side":"inline";Ke.forEach(Te=>{ce(Te.path,Fe)})},[Ke,ce]),[kt,Ft]=a.useState(null),Ht=a.useCallback(async(je,Fe)=>{if(!f||!je)return;Ft(je);const Te=$n();try{let it=null;if(Fe?.patch&&!Fe.isBinary&&!ko(je)?it=fd(Fe.patch):Fe&&Fe.contextMode==="full"&&!Fe.isBinary&&!ko(je)&&(it=bd(Fe.original,Fe.modified)),it===null)try{const Xe=await u.getGitDiff(f,{path:je,staged:Ne,contextLines:3});it=fd(Xe.diff)}catch{it=null}let ct=Fe;if(it===null||!ct){const Xe=await u.getGitFileDiff(f,{path:je,staged:Ne});ct={original:Xe.original??"",modified:Xe.modified??"",isBinary:Xe.isBinary},Ne||v(f,je,ct,Te)}const Kt=it??(ct.isBinary||ko(je)?1:bd(ct.original,ct.modified)),Lt=ky(f,je),ze=await nc(h,Lt,{directory:f});if(!ze.ok){fe.error(rc(ze.reason));return}he(f,Lt,Kt,1)}finally{Ft(it=>it===je?null:it)}},[Ne,f,h,u,he,v]),Xt=()=>{if(!f)return null;const je=Fe=>X!==null?X:k&&Fe===P;return s.jsxs("div",{className:De("flex min-w-0 flex-1 min-h-0 h-full",l?"gap-0":"gap-3 px-3 pb-3 pt-2"),children:[ee&&s.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[s.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:d("diffView.section.files")}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:Ke.length})]}),s.jsx(Py,{changedFiles:Ke,selectedFile:null,onSelectFile:Rt})]}),s.jsx("div",{className:"relative flex-1 min-w-0 min-h-0 h-full",children:s.jsx(On,{ref:ie,outerClassName:"min-h-0 h-full",className:"[overflow-anchor:none] pb-16",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,children:s.jsx("div",{className:"flex flex-col [overflow-anchor:none]","data-diff-virtual-content":!0,children:Ke.map(Fe=>s.jsx(Ty,{directory:f,file:Fe,layout:wt(Fe),wrapLines:Me,isSelected:!1,isExpanded:L.has(Fe.path),isMounted:D.has(Fe.path)||Fe.path===O,onSelect:Qe,onExpandedChange:qt,registerSectionRef:Dt,showOpenInEditorAction:r&&se!=="turn",isOpeningInEditor:kt===Fe.path,onOpenInEditor:(Te,it)=>{Ht(Te,it)},staged:je(Fe.path),loadFullFiles:T,initialDiffData:se==="turn"?Le.get(Fe.path)??null:null},`${Fe.path}:${J.get(Fe.path)??0}`))})})})]})},rt=()=>f?se!=="turn"&&y&&!m?s.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),d("diffView.state.loadingRepositoryStatus")]}):se!=="turn"&&g===!1?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:d("diffView.state.notGitRepository")}):Ke.length===0?s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:d(se==="turn"?"diffView.state.noLastTurnChanges":"diffView.state.cleanWorkingTree")}):Xt():s.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:d("diffView.state.selectSessionDirectory")});return s.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[s.jsxs("div",{className:"@container/diff-toolbar flex min-w-0 items-center gap-2 px-3 py-2 bg-background",children:[!S&&(se==="working"||se==="staged"||se==="turn"?s.jsx(Dy,{scope:se,workingCount:st,stagedCount:ut,turnCount:mt,onScopeChange:je=>{G(je),i?.(je)}}):s.jsx("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:s.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:y&&!m?d("diffView.state.loadingChanges"):Ke.length===1?d("diffView.summary.changedFilesSingle",{count:Ke.length}):d("diffView.summary.changedFilesPlural",{count:Ke.length})})})),Ke.length>0&&s.jsxs(He,{variant:"ghost",size:"sm",onClick:Ut,className:De("diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground","ml-auto"),title:L.size>0?d("diffView.actions.collapseAll"):d("diffView.actions.expandAll"),children:[s.jsx(I,{name:"expand-up-down",className:"size-4"}),s.jsx("span",{className:"diff-toolbar__expand-label typography-ui-label",children:L.size>0?d("diffView.actions.collapseAll"):d("diffView.actions.expandAll")})]}),Ke.length>0&&Se&&s.jsxs(He,{variant:"default",size:"sm",onClick:()=>Z(!0),disabled:ue,className:"diff-toolbar__review-button h-7 flex-shrink-0 gap-1.5 px-2","aria-label":d("diffView.actions.reviewAria"),children:[ue?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"search-eye",className:"size-4"}),s.jsx("span",{className:"diff-toolbar__review-label typography-ui-label",children:d("diffView.actions.review")})]}),Ke.length>0&&le&&s.jsxs(He,{variant:"outline",size:"sm",onClick:()=>{const je=f??"";x(je,{kind:"working-tree",scope:se==="staged"||se==="working"?se:"all"}),p(je,"walkthrough")},className:De("diff-toolbar__walkthrough-button h-7 flex-shrink-0 gap-1.5 px-2",oc),"aria-label":d("walkthrough.action.open"),children:[s.jsx(I,{name:"route",className:"size-4"}),s.jsx("span",{className:"diff-toolbar__walkthrough-label typography-ui-label",children:d("walkthrough.action.open")})]}),Ke.length>0&&s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(He,{variant:"ghost",size:"sm",onClick:()=>z(je=>!je),"aria-pressed":T,"aria-label":d(T?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles"),className:De("h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground",T&&"bg-interactive-selection text-interactive-selection-foreground"),children:s.jsx(I,{name:"file-download",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:d(T?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles")})})]}),Ke.length>0&&s.jsx(He,{variant:"ghost",size:"sm",onClick:()=>ye(!ke),className:De("h-5 w-5 p-0 transition-opacity",Me?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:d(Me?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:s.jsx(I,{name:"text-wrap",className:"size-4"})}),bt&&s.jsx(rf,{mode:bt==="side-by-side"?"side-by-side":"unified",onModeChange:Ot})]}),s.jsx(tp,{open:te,onOpenChange:Z,projectDirectory:f??null,submitting:ue,onConfirm:We}),rt()]})},am=12,Ey=[{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"}],Fy=t=>{const e=nt.c(18),{isActive:n,burstKey:r,className:o,durationMs:i,bursts:c,onComplete:l}=t,d=r===void 0?0:r,u=i===void 0?900:i,h=c===void 0?Ey:c,f=$e.useRef(!1);let p,x;e[0]!==n||e[1]!==l?(p=()=>{!n&&f.current&&l?.(),n&&(f.current=!0)},x=[n,l],e[0]=n,e[1]=l,e[2]=p,e[3]=x):(p=e[2],x=e[3]),$e.useEffect(p,x);let b;e[4]===Symbol.for("react.memo_cache_sentinel")?(b=Array.from({length:am},Oy),e[4]=b):b=e[4];const S=b;if(!n)return null;let g;e[5]!==o?(g=De("fireworks-overlay pointer-events-none",o),e[5]=o,e[6]=g):g=e[6];let m;if(e[7]!==d||e[8]!==h||e[9]!==u){let C;e[11]!==d||e[12]!==u?(C=j=>{const w={"--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:w,children:S.map((N,v)=>{const P=N.x*j.radius,F=N.y*j.radius,k={"--translate-x":`${P}px`,"--translate-y":`${F}px`,"--particle-delay":`${N.delay}ms`,color:`var(${j.colorVar})`};return s.jsx("span",{className:"firework-particle",style:k},`${j.id}-${v}-${d}`)})},`${j.id}-${d}`)},e[11]=d,e[12]=u,e[13]=C):C=e[13],m=h.map(C),e[7]=d,e[8]=h,e[9]=u,e[10]=m}else m=e[10];let y;return e[14]!==d||e[15]!==g||e[16]!==m?(y=s.jsx("div",{className:g,"aria-hidden":"true","data-burst-key":d,children:m}),e[14]=d,e[15]=g,e[16]=m,e[17]=y):y=e[17],y};function Oy(t,e){const n=Math.PI*2*e/am;return{x:Math.cos(n),y:Math.sin(n),delay:e*18}}const Ly=t=>{const e=nt.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,l]=$e.useState(i),d=$e.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 h=u;let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f=()=>{h(),l(By)},e[4]=f):f=e[4];const p=f;let x;e[5]!==o?(x=()=>{h(),l($y),d.current=window.setTimeout(()=>{l(_y),d.current=null},o)},e[5]=o,e[6]=x):x=e[6];const b=x;let S,g;e[7]===Symbol.for("react.memo_cache_sentinel")?(S=()=>()=>h(),g=[h],e[7]=S,e[8]=g):(S=e[7],g=e[8]),$e.useEffect(S,g);let m;return e[9]!==c.cycle||e[10]!==c.isActive||e[11]!==b?(m={isActive:c.isActive,burstKey:c.cycle,triggerFireworks:b,dismissFireworks:p},e[9]=c.cycle,e[10]=c.isActive,e[11]=b,e[12]=m):m=e[12],m};function By(t){return t.isActive?{...t,isActive:!1}:t}function $y(t){return{isActive:!0,cycle:t.cycle+1}}function _y(t){return t.isActive?{...t,isActive:!1}:t}const lm=a.createContext(void 0),zy=t=>{const e=nt.c(10),{children:n}=t,{isActive:r,burstKey:o,triggerFireworks:i,dismissFireworks:c}=Ly();let l;e[0]!==c||e[1]!==i?(l={triggerFireworks:i,dismissFireworks:c},e[0]=c,e[1]=i,e[2]=l):l=e[2];const d=l;let u;e[3]!==o||e[4]!==r?(u=s.jsx(Fy,{isActive:r,burstKey:o}),e[3]=o,e[4]=r,e[5]=u):u=e[5];let h;return e[6]!==n||e[7]!==u||e[8]!==d?(h=s.jsxs(lm.Provider,{value:d,children:[n,u]}),e[6]=n,e[7]=u,e[8]=d,e[9]=h):h=e[9],h},Vy=()=>{const t=a.useContext(lm);if(!t)throw new Error("useFireworksCelebration must be used within FireworksProvider");return t},cm="gitmojiCache",Wy=1e3*60*60*24*7,dm="1",Uy="https://raw.githubusercontent.com/carloscuesta/gitmoji/master/packages/gitmojis/src/gitmojis.json",um=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.emoji=="string"&&typeof e.code=="string"&&typeof e.description=="string"},Va=()=>{if(typeof window>"u")return null;try{const t=window.localStorage.getItem(cm);if(!t)return null;const e=JSON.parse(t);return!e||e.version!==dm||typeof e.fetchedAt!="number"||!Array.isArray(e.gitmojis)?null:{gitmojis:e.gitmojis.filter(um),fetchedAt:e.fetchedAt,version:e.version}}catch{return null}},Hy=t=>{if(!(typeof window>"u"))try{const e={gitmojis:t,fetchedAt:Date.now(),version:dm};window.localStorage.setItem(cm,JSON.stringify(e))}catch{return}},yd=t=>Date.now()-t.fetchedAt<Wy;let ki=null;const si=new Set,wd=async()=>{if(ki)return ki;const t=(async()=>{try{const e=await fetch(Uy);if(!e.ok)throw new Error(`Failed to load gitmojis: ${e.statusText}`);const n=await e.json(),r=Array.isArray(n.gitmojis)?n.gitmojis.filter(um):[];return Hy(r),si.forEach(o=>o(r)),r}catch(e){console.warn("Failed to load gitmoji list:",e);const n=[];return si.forEach(r=>r(n)),n}finally{ki=null}})();return ki=t,t},Ky=t=>{const[e,n]=a.useState(()=>t?Va()?.gitmojis??[]:[]),[r,o]=a.useState(!1),i=a.useRef(t);i.current=t,a.useEffect(()=>{if(!t){si.delete(n),n([]),o(!1);return}const l=Va();if(l&&(n(l.gitmojis),yd(l)))return;si.add(n),o(!0);let d=!1;return wd().finally(()=>{!d&&i.current&&o(!1)}),()=>{d=!0,si.delete(n)}},[t]);const c=a.useCallback(async()=>{if(!i.current)return[];if(e.length>0)return e;const l=Va();return l&&yd(l)?l.gitmojis:wd()},[e]);return{gitmojis:e,isLoading:r,ensureLoaded:c}},vd=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")};function fm(t,e,n){const r=nt.c(5),[o,i]=a.useState();let c,l;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,h]=await Promise.all([np(t),rp(t)]).catch(Gy);if(d)return;const f=vd(u),p=vd(h);if(!f||!p||p===f)return;const x=n||"",b=p.split("/").filter(Boolean).pop()||p;i({source:"sdk",path:p,projectDirectory:f,branch:x,label:x||b,name:b,worktreeRoot:p,worktreeStatus:"ready",headState:x?"branch":"unborn",worktreeSource:"existing"})})(),()=>{d=!0}},l=[t,e,n],r[0]=n,r[1]=t,r[2]=e,r[3]=c,r[4]=l):(c=r[3],l=r[4]),a.useEffect(c,l),e??o}function Gy(){return["",""]}const _o=async(t,e)=>{const n=await hs(`/api/git/integrate/${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!n.ok){const r=await n.json().catch(()=>null);throw new Error(r?.error||`Git integrate request failed: ${n.statusText}`)}return n.json()};async function Xo(t){return _o("plan",t)}async function qy(t){return _o("conflict-details",{tempWorktreePath:t})}async function Yy(t){return(await _o("cherry-pick-status",{tempWorktreePath:t})).inProgress}async function Qy(t){return _o("run",{plan:t})}async function Xy(t){await _o("abort",{state:t})}async function Jy(t){return _o("continue",{state:t})}const Zy=({repoRoot:t,sourceBranch:e,worktreeMetadata:n,localBranches:r,defaultTargetBranch:o,refreshKey:i,onRefresh:c,showHeader:l=!0})=>{const{t:d}=ft(),u=et(R=>R.currentSessionId),h=Re(R=>R.setActiveMainTab),[f,p]=$e.useState(!1),x=$e.useRef(null),[b,S]=$e.useState(o);$e.useEffect(()=>{S(o)},[o]),$e.useEffect(()=>{if(f){const R=setTimeout(()=>{x.current?.focus()},0);return()=>clearTimeout(R)}},[f]);const g=!!(t&&e&&b&&b!=="HEAD"&&e!==b),[m,y]=$e.useState({kind:"idle"}),[C,j]=$e.useState(!1),[w,N]=$e.useState([]),v=$e.useMemo(()=>u?`openchamber.integrate.conflict:${u}`:null,[u]);$e.useEffect(()=>{if(!v||typeof window>"u")return;const R=window.localStorage.getItem(v);if(!R)return;let W=!1;try{const J=JSON.parse(R);if(!J?.tempWorktreePath||J.repoRoot!==t){window.localStorage.removeItem(v);return}(async()=>{const U=await Yy(J.tempWorktreePath).catch(()=>!1);if(W)return;if(!U){window.localStorage.removeItem(v);return}const te=await qy(J.tempWorktreePath).catch(()=>null);W||te&&y({kind:"conflict",state:J,details:te})})()}catch{window.localStorage.removeItem(v)}return()=>{W=!0}},[v,t]),$e.useEffect(()=>{if(!g){y({kind:"idle"});return}let R=!1;return y({kind:"loading"}),(async()=>{try{const W=await Xo({repoRoot:t,sourceBranch:e,targetBranch:b});if(R)return;if(y({kind:"ready",plan:W}),W.commits.length>0){const U=W.commits.slice(-50).reverse(),te=await op(t,U);R||(N(te),j(!1))}else R||(N([]),j(!1))}catch{R||y({kind:"idle"})}})(),()=>{R=!0}},[g,t,e,b,i]);const P=$e.useCallback(R=>{u&&et.getState().setWorktreeMetadata(u,{...n,createdFromBranch:R})},[u,n]),F=et(R=>R.openNewSessionDraft),k=$e.useCallback(async R=>{const W=await Ro("git.integrate.cherrypick.resolve.visible",{current_commit:R.state.currentCommit,target_branch:R.state.targetBranch}),J=await Ro("git.integrate.cherrypick.resolve.instructions",{repo_root:R.state.repoRoot,temp_worktree_path:R.state.tempWorktreePath,source_branch:R.state.sourceBranch,target_branch:R.state.targetBranch,current_commit:R.state.currentCommit}),U=`Cherry-pick conflict context (JSON)
46
- ${JSON.stringify({repoRoot:R.state.repoRoot,tempWorktreePath:R.state.tempWorktreePath,sourceBranch:R.state.sourceBranch,targetBranch:R.state.targetBranch,currentCommit:R.state.currentCommit,remainingCommits:R.state.remainingCommits,statusPorcelain:R.details.statusPorcelain,unmergedFiles:R.details.unmergedFiles,currentPatchMeta:R.details.currentPatchMeta,currentPatch:R.details.currentPatch,diff:R.details.diff},null,2)}`;return{visibleText:W,instructionsText:J,payloadText:U}},[]),E=lo(R=>R.setPendingInputText),O=lo(R=>R.setPendingSyntheticParts),M=$e.useCallback(async(R,W)=>{const J=await k(R);if(W){F({directoryOverride:R.state.tempWorktreePath,initialPrompt:J.visibleText,syntheticParts:[{text:J.instructionsText,synthetic:!0},{text:J.payloadText,synthetic:!0}]}),h("chat");return}if(!u){fe.error(d("gitView.integrate.noActiveSession"),{description:d("gitView.integrate.noActiveSessionDescription")});return}E(J.visibleText,"replace"),O([{text:J.instructionsText,synthetic:!0},{text:J.payloadText,synthetic:!0}]),h("chat")},[u,h,k,F,E,O,d]),L=$e.useCallback(async()=>{if(m.kind==="ready"){if(m.plan.commits.length===0){fe.message(d("gitView.integrate.noCommitsToMoveToast"));return}y({kind:"running",plan:m.plan});try{const R=await Qy(m.plan);if(R.kind==="success"){fe.success(d("gitView.integrate.commitsMovedToast"),{description:R.moved===1?d("gitView.integrate.commitsMovedDescriptionSingle",{count:R.moved,branch:m.plan.targetBranch}):d("gitView.integrate.commitsMovedDescriptionPlural",{count:R.moved,branch:m.plan.targetBranch})});const W=await Xo(m.plan);y({kind:"ready",plan:W}),c?.();return}R.kind==="conflict"&&(fe.error(d("gitView.integrate.cherryPickConflictToast"),{description:d("gitView.integrate.cherryPickConflictDescription")}),y({kind:"conflict",state:R.state,details:R.details}),v&&typeof window<"u"&&window.localStorage.setItem(v,JSON.stringify(R.state)))}catch(R){const W=R instanceof Error?R.message:String(R);fe.error(d("gitView.integrate.failedToMoveToast"),{description:W});const J=await Xo({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);y(J?{kind:"ready",plan:J}:{kind:"idle"})}}},[m,c,t,e,b,v,d]),_=$e.useCallback(async()=>{if(m.kind==="conflict")try{await Xy(m.state),fe.message(d("gitView.integrate.cherryPickAbortedToast")),v&&typeof window<"u"&&window.localStorage.removeItem(v)}finally{const R=await Xo({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);y(R?{kind:"ready",plan:R}:{kind:"idle"})}},[m,t,e,b,v,d]),D=$e.useCallback(async()=>{if(m.kind==="conflict")try{const R=await Jy(m.state);if(R.kind==="success"){fe.success(d("gitView.integrate.cherryPickFinishedToast"));const W=await Xo({repoRoot:t,sourceBranch:e,targetBranch:b}).catch(()=>null);y(W?{kind:"ready",plan:W}:{kind:"idle"}),v&&typeof window<"u"&&window.localStorage.removeItem(v),c?.();return}R.kind==="conflict"&&(y({kind:"conflict",state:R.state,details:R.details}),v&&typeof window<"u"&&window.localStorage.setItem(v,JSON.stringify(R.state)))}catch(R){const W=R instanceof Error?R.message:String(R);fe.error(d("gitView.integrate.cherryPickContinueFailedToast"),{description:W})}},[m,t,e,b,c,v,d]);return!t||!e?null:s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[l?s.jsxs("div",{className:"px-0 py-3 border-b border-border/40 flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(I,{name:"split-cells-horizontal",className:"size-4 text-muted-foreground"}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:d("gitView.integrate.title")}),m.kind==="ready"&&m.plan.commits.length>0?s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:d("gitView.integrate.toMoveCount",{count:m.plan.commits.length})}):null]}),s.jsx("div",{className:"flex items-center gap-2",children:m.kind==="loading"||m.kind==="running"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null})]}):null,s.jsxs("div",{className:"flex flex-col gap-3 py-3",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:d("gitView.integrate.moveCommits")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," → ",b]})]}),s.jsx("div",{className:"flex-1"}),s.jsxs(Qs,{open:f,onOpenChange:p,children:[s.jsx(qs,{asChild:!0,children:s.jsxs("button",{type:"button",className:xa({size:"default"}),children:[d("gitView.integrate.target"),s.jsx("span",{className:"max-w-[160px] truncate font-mono text-xs text-muted-foreground",children:b}),s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60"})]})}),s.jsx(Ys,{align:"end",className:"w-72 p-0 max-h-[var(--available-height)] flex flex-col overflow-hidden",children:s.jsxs(ba,{className:"h-full min-h-0",children:[s.jsx(ya,{ref:x,placeholder:d("gitView.branch.searchPlaceholder"),onKeyDown:R=>R.stopPropagation()}),s.jsxs(wa,{className:"h-full min-h-0",scrollbarClassName:"overlay-scrollbar--flush overlay-scrollbar--dense overlay-scrollbar--zero",disableHorizontal:!0,children:[s.jsx(va,{children:d("gitView.branch.empty")}),s.jsx(kr,{heading:d("gitView.branch.localBranches"),children:r.map(R=>s.jsx(Nr,{value:R,onSelect:()=>{S(R),P(R),p(!1)},children:R},R))})]})]})})]}),m.kind==="ready"?s.jsx(He,{size:"sm",onClick:()=>{L()},disabled:!g||m.plan.commits.length===0,children:d("gitView.integrate.move")}):m.kind==="loading"?s.jsx(He,{size:"sm",variant:"outline",disabled:!0,children:d("gitView.integrate.checking")}):m.kind==="running"?s.jsx(He,{size:"sm",variant:"outline",disabled:!0,children:d("gitView.integrate.moving")}):null]}),m.kind==="ready"&&m.plan.commits.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:d("gitView.integrate.noCommitsToMove")}),m.kind==="ready"&&m.plan.commits.length>0&&s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("div",{className:"typography-meta text-foreground",children:[d("gitView.integrate.commitsToMove"),s.jsxs("span",{className:"text-muted-foreground",children:[" (",m.plan.commits.length,")"]})]}),w.length>0&&m.plan.commits.length>5&&s.jsx("button",{type:"button",onClick:()=>j(R=>!R),className:"typography-micro text-muted-foreground hover:text-foreground",children:d(C?"gitView.integrate.showLess":"gitView.integrate.showAll")})]}),s.jsxs("div",{className:"space-y-1",children:[(C?w:w.slice(0,5)).map(R=>s.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[s.jsx("span",{className:"font-mono text-xs text-muted-foreground flex-shrink-0",children:R.short}),s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:R.subject||R.sha})]},R.sha)),w.length===0&&s.jsx("div",{className:"typography-meta text-muted-foreground",children:d("gitView.integrate.previewUnavailable")}),m.plan.commits.length>w.length&&s.jsx("div",{className:"typography-micro text-muted-foreground/70",children:d("gitView.integrate.showingFirstCommits",{count:w.length})})]})]}),m.kind==="conflict"&&s.jsxs("div",{className:"rounded-md border border-border/60 bg-background/60 p-3 space-y-2",children:[s.jsx("div",{className:"typography-meta text-foreground",children:d("gitView.integrate.conflictsInFiles",{count:m.details.unmergedFiles.length})}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[d("gitView.integrate.currentCommit"),": ",s.jsx("span",{className:"font-mono",children:m.state.currentCommit.slice(0,7)})]}),s.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[m.details.unmergedFiles.slice(0,6).map(R=>s.jsx("span",{className:"font-mono text-xs px-2 py-0.5 rounded bg-muted/40 text-muted-foreground",children:R},R)),m.details.unmergedFiles.length>6&&s.jsx("span",{className:"text-xs text-muted-foreground",children:d("gitView.integrate.moreFiles",{count:m.details.unmergedFiles.length-6})})]}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(He,{size:"sm",variant:"ghost",className:"typography-meta",onClick:()=>{_()},children:d("gitView.operation.abort")}),s.jsxs(He,{size:"sm",variant:"secondary",className:"typography-meta gap-1",disabled:!u,onClick:()=>{M({state:m.state,details:m.details},!1)},children:[s.jsx(I,{name:"sparkling",className:"size-3.5"}),d("gitView.integrate.currentSession")]}),s.jsxs(He,{size:"sm",variant:"secondary",className:"typography-meta gap-1",onClick:()=>{M({state:m.state,details:m.details},!0)},children:[s.jsx(I,{name:"sparkling",className:"size-3.5"}),d("gitView.integrate.newSession")]}),s.jsx(He,{size:"sm",className:"typography-meta",onClick:()=>{D()},children:d("gitView.operation.continue")})]})]})]})]})},ew=({open:t,onOpenChange:e,directory:n,hasUncommittedChanges:r,hasStagedChanges:o=!1,uncommittedFileCount:i,onChanged:c})=>{const{t:l}=ft(),[d,u]=a.useState([]),[h,f]=a.useState(!1),[p,x]=a.useState(""),[b,S]=a.useState(""),[g,m]=a.useState(null),[y,C]=a.useState({}),j=a.useCallback(async()=>{if(n){f(!0);try{const k=await ip(n);u(k.stashes),C({})}catch(k){fe.error(k instanceof Error?k.message:l("gitView.stashes.toast.loadFailed"))}finally{f(!1)}}},[n,l]);a.useEffect(()=>{t&&j()},[j,t]),a.useEffect(()=>{if(!t||!n||d.length===0)return;let k=!1;const E=d.map(O=>O.ref);return ap(n,E).then(O=>{k||C(O.counts)}).catch(()=>{}),()=>{k=!0}},[n,t,d]);const w=a.useMemo(()=>{const k=p.trim().toLowerCase();return k?d.filter(E=>`${E.ref} ${E.message} ${E.relativeTime}`.toLowerCase().includes(k)):d},[p,d]),N=a.useCallback(async k=>{await j(),await c?.(k)},[j,c]),v=async()=>{if(!(!n||g)){m("create");try{const k=await lp(n,{message:b.trim()||void 0});k.created?(fe.success(l("gitView.stashes.toast.created")),S("")):fe.info(l("gitView.stashes.toast.noChanges")),await N({affectsIndex:!!(k.created&&o)})}catch(k){fe.error(k instanceof Error?k.message:l("gitView.stashes.toast.createFailed"))}finally{m(null)}}},P=async(k,E)=>{if(!(!n||g)&&!(E==="drop"&&!window.confirm(l("gitView.stashes.confirm.drop",{ref:k.ref})))){m(`${E}:${k.ref}`);try{E==="apply"&&await cp(n,{ref:k.ref}),E==="pop"&&await dp(n,{ref:k.ref}),E==="drop"&&await up(n,{ref:k.ref});const O=E==="apply"?"gitView.stashes.toast.applySuccess":E==="pop"?"gitView.stashes.toast.popSuccess":"gitView.stashes.toast.dropSuccess";fe.success(l(O)),await N({affectsIndex:E!=="drop"})}catch(O){const M=E==="apply"?"gitView.stashes.toast.applyFailed":E==="pop"?"gitView.stashes.toast.popFailed":"gitView.stashes.toast.dropFailed";fe.error(O instanceof Error?O.message:l(M)),await N({affectsIndex:E!=="drop"})}finally{m(null)}}},F=g!==null;return s.jsx(Ts,{open:t,onOpenChange:e,children:s.jsxs(Es,{className:"max-w-2xl max-h-[70vh] flex flex-col",children:[s.jsxs(Hs,{children:[s.jsxs($s,{className:"flex items-center gap-2",children:[s.jsx(I,{name:"archive-stack",className:"h-5 w-5"}),l("gitView.stashes.title")]}),s.jsx(Ks,{children:l("gitView.stashes.description")})]}),s.jsxs("div",{className:"mt-2 rounded-lg border border-border/60 bg-[var(--surface-elevated)] p-3",children:[s.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[s.jsx(or,{value:b,onChange:k=>S(k.target.value),placeholder:l("gitView.stashes.messagePlaceholder"),disabled:F||!r,className:"flex-1"}),s.jsxs(He,{onClick:v,disabled:!r||F||!n,children:[g==="create"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"inbox-archive",className:"size-4"}),l("gitView.stashes.actions.stashCurrentWithCount",{count:i})]})]}),s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:l("gitView.stashes.includeUntrackedHint")})]}),s.jsxs("div",{className:"relative mt-2",children:[s.jsx(I,{name:"search",className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),s.jsx(or,{value:p,onChange:k=>x(k.target.value),placeholder:l("gitView.stashes.searchPlaceholder"),className:"pl-9"})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:h?s.jsx("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:s.jsx(I,{name:"loader-4",className:"size-5 animate-spin"})}):w.length===0?s.jsx("div",{className:"py-8 text-center text-muted-foreground",children:l(p?"gitView.stashes.empty.search":"gitView.stashes.empty.list")}):w.map((k,E)=>s.jsxs("div",{className:"group flex items-center gap-2 rounded py-1.5 transition-colors hover:bg-interactive-hover/30",children:[s.jsxs("div",{className:"min-w-0 flex-1 pl-2",children:[s.jsx("p",{className:"typography-small truncate text-foreground",children:k.message||l("gitView.stashes.untitled")}),s.jsxs("p",{className:"typography-meta truncate text-muted-foreground",children:[s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{children:E===0&&!p.trim()?l("gitView.stashes.latestLabel"):l("gitView.stashes.itemNumber",{number:E+1})})}),s.jsx(At,{sideOffset:6,children:k.ref})]})," · ",k.relativeTime," · ",typeof y[k.ref]=="number"?l("gitView.stashes.fileCount",{count:y[k.ref]}):l("gitView.stashes.fileCountLoading")]})]}),s.jsxs("div",{className:"mr-2 flex shrink-0 items-center gap-1 opacity-100 sm:opacity-0 sm:group-hover:opacity-100",children:[s.jsx(Wa,{label:l("gitView.stashes.actions.apply"),loading:g===`apply:${k.ref}`,onClick:()=>P(k,"apply"),disabled:F,children:s.jsx(I,{name:"inbox-unarchive",className:"size-4"})}),s.jsx(Wa,{label:l("gitView.stashes.actions.pop"),loading:g===`pop:${k.ref}`,onClick:()=>P(k,"pop"),disabled:F,children:s.jsx(I,{name:"inbox-unarchive-fill",className:"size-4"})}),s.jsx(Wa,{label:l("gitView.stashes.actions.drop"),loading:g===`drop:${k.ref}`,onClick:()=>P(k,"drop"),disabled:F,destructive:!0,children:s.jsx(I,{name:"delete-bin",className:"size-4"})})]})]},k.ref))})]})})},Wa=t=>{const e=nt.c(17),{label:n,loading:r,disabled:o,destructive:i,onClick:c,children:l}=t,d=r||void 0,u=i?"text-[var(--status-error)] hover:text-[var(--status-error)]":"text-muted-foreground hover:text-foreground";let h;e[0]!==u?(h=De("flex h-6 w-6 items-center justify-center transition-colors disabled:opacity-50",u),e[0]=u,e[1]=h):h=e[1];let f;e[2]!==l||e[3]!==r?(f=r?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):l,e[2]=l,e[3]=r,e[4]=f):f=e[4];let p;e[5]!==o||e[6]!==n||e[7]!==c||e[8]!==d||e[9]!==h||e[10]!==f?(p=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button","aria-label":n,"aria-busy":d,className:h,onClick:c,disabled:o,children:f})}),e[5]=o,e[6]=n,e[7]=c,e[8]=d,e[9]=h,e[10]=f,e[11]=p):p=e[11];let x;e[12]!==n?(x=s.jsx(At,{sideOffset:6,children:n}),e[12]=n,e[13]=x):x=e[13];let b;return e[14]!==p||e[15]!==x?(b=s.jsxs(Nt,{children:[p,x]}),e[14]=p,e[15]=x,e[16]=b):b=e[16],b},tw=t=>{const e=nt.c(16),{onOpenStashes:n}=t,{t:r}=ft();let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o=s.jsx(I,{name:"git-commit",className:"size-10 text-muted-foreground/70 mb-4"}),e[0]=o):o=e[0];let i;e[1]!==r?(i=r("gitView.empty.cleanTitle"),e[1]=r,e[2]=i):i=e[2];let c;e[3]!==i?(c=s.jsx("p",{className:"typography-ui-label font-semibold text-foreground mb-1",children:i}),e[3]=i,e[4]=c):c=e[4];let l;e[5]!==r?(l=r("gitView.empty.cleanDescription"),e[5]=r,e[6]=l):l=e[6];let d;e[7]!==l?(d=s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:l}),e[7]=l,e[8]=d):d=e[8];let u;e[9]!==n||e[10]!==r?(u=n?s.jsxs(He,{type:"button",variant:"outline",size:"sm",onClick:n,className:"gap-1.5",children:[s.jsx(I,{name:"archive-stack",className:"size-4"}),r("gitView.stashes.title")]}):null,e[9]=n,e[10]=r,e[11]=u):u=e[11];let h;return e[12]!==c||e[13]!==d||e[14]!==u?(h=s.jsxs("div",{className:"flex flex-col items-center justify-center py-10 px-4 text-center",children:[o,c,d,u]}),e[12]=c,e[13]=d,e[14]=u,e[15]=h):h=e[15],h},Lr=8,sw=t=>{const e=nt.c(18),{laned:n,totalLanes:r,isExpanded:o}=t,{lane:i,color:c,connectors:l}=n,u=Math.max(r,i+1)*Lr+Lr/2,h=a.useRef(null),f=a.useRef(null);let p;e[0]!==c||e[1]!==l||e[2]!==i||e[3]!==u?(p=()=>{const m=h.current,y=f.current;if(!m||!y)return;const C=m.offsetHeight;if(C===0)return;const j=window.devicePixelRatio||1;y.width=u*j,y.height=C*j;const w=y.getContext("2d");if(!w)return;w.scale(j,j),w.clearRect(0,0,u,C);const N=C/2,v=i*Lr+Lr/2,P=getComputedStyle(y),F=P.getPropertyValue("--surface-muted-foreground").trim()||P.color,k=M=>{if(!M.startsWith("var("))return M;const L=M.slice(4,-1).trim();return P.getPropertyValue(L).trim()||F},E=[...l].sort(rw);for(const M of E){const L=M.fromLane*Lr+Lr/2,_=M.toLane*Lr+Lr/2,D=M.type==="passing"?.72:M.type==="branch-out"||M.type==="merge-in"?.95:1;w.beginPath(),w.strokeStyle=k(M.color),w.globalAlpha=D,w.lineWidth=1.25,w.lineCap="round";e:switch(M.type){case"passing":case"commit-lane":{w.moveTo(L,0),w.lineTo(L,C);break e}case"top-stub":{w.moveTo(L,0),w.lineTo(L,N);break e}case"bottom-stub":{w.moveTo(L,N),w.lineTo(L,C);break e}case"branch-out":{const A=(N+C)/2;w.moveTo(v,N),w.bezierCurveTo(v,A,_,A,_,C);break e}case"merge-in":{const A=N/2;w.moveTo(L,0),w.bezierCurveTo(L,A,v,A,v,N);break e}default:continue}w.stroke(),w.globalAlpha=1}const O=P.getPropertyValue("--background").trim()||P.getPropertyValue("--surface-background").trim();w.beginPath(),w.arc(v,N,4,0,Math.PI*2),w.fillStyle=k(c),w.fill(),w.beginPath(),w.arc(v,N,5,0,Math.PI*2),w.strokeStyle=O||F,w.lineWidth=2,w.stroke()},e[0]=c,e[1]=l,e[2]=i,e[3]=u,e[4]=p):p=e[4];let x;e[5]!==c||e[6]!==l||e[7]!==o||e[8]!==i||e[9]!==n||e[10]!==r||e[11]!==u?(x=[n,i,c,l,r,o,u],e[5]=c,e[6]=l,e[7]=o,e[8]=i,e[9]=n,e[10]=r,e[11]=u,e[12]=x):x=e[12],a.useLayoutEffect(p,x);let b;e[13]!==u?(b={width:u,height:"100%",position:"relative",flexShrink:0,overflow:"hidden"},e[13]=u,e[14]=b):b=e[14];let S;e[15]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx("canvas",{ref:f,style:{position:"absolute",inset:0,width:"100%",height:"100%",display:"block"}}),e[15]=S):S=e[15];let g;return e[16]!==b?(g=s.jsx("div",{ref:h,style:b,children:S}),e[16]=b,e[17]=g):g=e[17],g};function nw(t){return t==="branch-out"||t==="merge-in"}function rw(t,e){const n=nw;return(n(t.type)?1:0)-(n(e.type)?1:0)}const jd=15e3,Sd=500,kd=12,Nd=8*1024*1024,Cd=t=>typeof t=="string"?0:(t.original?.length??0)+(t.modified?.length??0),Ad=t=>{if(t.size<=kd){let o=0;for(const i of t.values())o+=Cd(i);if(o<=Nd)return t}const e=Array.from(t.entries()).reverse(),n=new Map;let r=0;for(const[o,i]of e){if(n.size>=kd)continue;const c=Cd(i);r+c>Nd&&n.size>0||(n.set(o,i),r+=c)}return new Map(Array.from(n.entries()).reverse())};function Dd(t,e){const n=new Date(t);return Number.isNaN(n.getTime())?t:Ul(n,e,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function ow(t){switch(t){case"A":return"text-[var(--status-success)]";case"D":return"text-[var(--status-error)]";case"M":return"text-[var(--status-warning)]";case"R":return"text-[var(--status-info)]";default:return"text-muted-foreground"}}function iw(t){return t?t.split(",").map(e=>e.trim()).filter(Boolean).map(e=>{const n=e.startsWith("HEAD ->");return{label:n?e.replace("HEAD -> ",""):e.replace("tag: ",""),isHead:n,isTag:e.startsWith("tag: ")}}):[]}const aw=a.memo(({entry:t,mode:e="history",laned:n,totalLanes:r,isExpanded:o,onToggle:i,files:c,isLoadingFiles:l,onCopyHash:d,directory:u,onConflict:h,onActionSuccess:f})=>{const{t:p}=ft(),x=Re(U=>U.timeFormatPreference),b=e==="graph",[S,g]=a.useState(null),[m,y]=a.useState(!1),[C,j]=a.useState(""),[w,N]=a.useState(null),[v,P]=a.useState(new Set),[F,k]=a.useState(new Map),[E,O]=a.useState(new Set),M=async()=>{if(u){g("checkout");try{await yp(u,t.hash),fe.success(p("gitView.history.actions.detachedHead")),f?.()}catch(U){fe.error(String(U.message))}finally{g(null)}}},L=async()=>{if(!(!u||!C.trim())){g("createBranch");try{await mp(u,C.trim(),t.hash),y(!1),j(""),f?.()}catch(U){fe.error(String(U.message))}finally{g(null)}}},_=async()=>{if(u){g("cherryPick");try{const U=await bp(u,t.hash);U.conflict?h?.({conflict:!0,conflictFiles:U.conflictFiles,operation:"cherry-pick"}):f?.()}catch(U){fe.error(String(U.message))}finally{g(null)}}},D=async()=>{if(u){g("revert");try{const U=await xp(u,t.hash);U.conflict?h?.({conflict:!0,conflictFiles:U.conflictFiles,operation:"revert"}):f?.()}catch(U){fe.error(String(U.message))}finally{g(null)}}},A=async(U,te=!1)=>{if(!(!u||S!==null)){g("reset");try{await hp(u,t.hash,U,te),f?.()}catch(Z){fe.error(String(Z.message))}finally{g(null)}}},T=async()=>{if(!w)return;const U=w;switch(N(null),U){case"checkout":return M();case"cherryPick":return _();case"revert":return D();case"merge":return z();case"rebase":return R();case"resetSoft":return A("soft");case"resetMixed":return A("mixed");case"resetHard":return A("hard",!0)}},z=async()=>{if(u){g("merge");try{const U=await gp(u,{branch:t.hash});U.conflict?h?.({conflict:!0,conflictFiles:U.conflictFiles,operation:"merge"}):f?.()}catch(U){fe.error(String(U.message))}finally{g(null)}}},R=async()=>{if(u){g("rebase");try{const U=await pp(u,{onto:t.hash});U.conflict?h?.({conflict:!0,conflictFiles:U.conflictFiles,operation:"rebase"}):f?.()}catch(U){fe.error(String(U.message))}finally{g(null)}}},W=a.useCallback(async U=>{const te=U.path;if(!u){k(Z=>new Map(Z).set(te,"error"));return}k(Z=>Ad(new Map(Z).set(te,"loading")));try{const Z=fp(u,t.hash,U.path,!1),ue=new Promise((se,G)=>{setTimeout(()=>G(new Error(`Timed out after ${jd}ms`)),jd)}),Oe=await Promise.race([Z,ue]);k(se=>Ad(new Map(se).set(te,Oe)))}catch{k(Z=>new Map(Z).set(te,"error"))}},[u,t.hash]),J=a.useCallback(async U=>{const te=U.path;if(U.changeType==="R"||U.isBinary){P(se=>{const G=new Set(se);return G.has(te)?G.delete(te):G.add(te),G});return}const Z=F.get(te);if(v.has(te)&&Z&&Z!=="error"){P(se=>{const G=new Set(se);return G.delete(te),G});return}P(se=>{const G=new Set(se);return G.add(te),G}),!(Z&&Z!=="error"||U.insertions+U.deletions>Sd&&!E.has(te))&&await W(U)},[F,E,W,v]);return s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:i,className:De("w-full flex items-start gap-3 px-3 py-2 text-left transition-colors",b?"hover:bg-[var(--interactive-hover)]/40":o?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[b&&n&&r!==void 0?s.jsx("div",{className:"-my-2 shrink-0 self-stretch",children:s.jsx(sw,{laned:n,totalLanes:r,isExpanded:o})}):s.jsx("div",{className:"h-2 w-2 translate-y-2 rounded-full shrink-0",style:{backgroundColor:"var(--status-success)"},"aria-hidden":!0}),s.jsxs("div",{className:"min-w-0 flex-1",children:[b?(()=>{const U=iw(t.refs);return U.length>0?s.jsx("div",{className:"flex flex-wrap gap-1 mb-0.5",children:U.map(te=>s.jsx("span",{className:De("inline-flex items-center px-1.5 py-0 typography-micro rounded font-medium",te.isHead?"bg-[var(--chart-1)] text-[var(--primary-foreground)]":te.isTag?"bg-[var(--chart-5)] text-[var(--primary-foreground)]":"bg-[var(--interactive-hover)] text-[var(--foreground)]"),children:te.label},te.label))}):null})():null,s.jsx("p",{className:"typography-ui-label font-medium text-foreground line-clamp-1",children:t.message}),s.jsxs("div",{className:"flex items-center gap-1 typography-meta text-muted-foreground",children:[s.jsxs("div",{className:"flex items-center gap-1 min-w-0 truncate",children:[s.jsx("span",{className:"truncate min-w-[3ch]",title:t.author_name,children:t.author_name}),s.jsx("span",{className:"shrink-0",children:"·"}),s.jsx("span",{className:"truncate min-w-0",title:Dd(t.date,x),children:Dd(t.date,x)})]}),s.jsx("span",{className:"shrink-0",children:"·"}),s.jsx("code",{className:"shrink-0 font-mono",children:t.hash.slice(0,8)}),s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(He,{variant:"ghost",size:"sm",className:"h-5 px-1 shrink-0",onClick:U=>{U.stopPropagation(),d(t.hash)},children:s.jsx(I,{name:"file-copy",className:"size-3"})})}),s.jsx(At,{sideOffset:8,children:p("gitView.history.copySha")})]})]})]})]}),o&&s.jsxs("div",{className:"px-3 pb-2 pl-8 border-t border-border/40",children:[b&&w?s.jsxs("div",{className:"flex items-center gap-2 py-2 border-b border-border/30 mb-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground flex-1 min-w-0",children:p(`gitView.history.actions.${w}Confirm`)}),s.jsxs(He,{variant:"destructive",size:"xs",className:"h-6 shrink-0",disabled:S!==null,onClick:U=>{U.stopPropagation(),T()},children:[S!==null?s.jsx(I,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,p("gitView.history.actions.confirmButton")]}),s.jsx(He,{variant:"ghost",size:"xs",className:"h-6 shrink-0",disabled:S!==null,onClick:U=>{U.stopPropagation(),N(null)},children:p("gitView.history.actions.cancelButton")})]}):b?s.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 py-2 border-b border-border/30 mb-2",children:[s.jsx(He,{variant:"outline",size:"xs",className:"h-6",disabled:S!==null,onClick:U=>{U.stopPropagation(),N("checkout")},children:p("gitView.history.actions.checkout")}),m?s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx("input",{autoFocus:!0,value:C,onChange:U=>j(U.target.value),onKeyDown:U=>{U.key==="Enter"&&L(),U.key==="Escape"&&(y(!1),j(""))},placeholder:p("gitView.history.actions.createBranchPlaceholder"),className:"h-6 text-xs px-2 rounded border border-border/60 bg-background min-w-0 w-32"}),s.jsxs(He,{variant:"outline",size:"xs",className:"h-6",disabled:!C.trim()||S!==null,onClick:U=>{U.stopPropagation(),L()},children:[S==="createBranch"?s.jsx(I,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,p("gitView.history.actions.createBranchConfirm")]})]}):s.jsx(He,{variant:"outline",size:"xs",className:"h-6",onClick:U=>{U.stopPropagation(),y(!0)},children:p("gitView.history.actions.createBranch")}),s.jsx(He,{variant:"outline",size:"xs",className:"h-6",disabled:S!==null,onClick:U=>{U.stopPropagation(),N("cherryPick")},children:p("gitView.history.actions.cherryPick")}),s.jsx(He,{variant:"outline",size:"xs",className:"h-6",disabled:S!==null,onClick:U=>{U.stopPropagation(),N("revert")},children:p("gitView.history.actions.revert")}),s.jsxs(Qs,{children:[s.jsx(qs,{asChild:!0,children:s.jsxs(He,{variant:"outline",size:"xs",className:"h-6",disabled:S!==null,onClick:U=>U.stopPropagation(),children:[S==="reset"?s.jsx(I,{name:"loader-4",className:"size-3 animate-spin mr-1"}):null,p("gitView.history.actions.reset")]})}),s.jsx(Ys,{align:"start",className:"min-w-max",children:["soft","mixed","hard"].map(U=>s.jsx(is,{disabled:S!==null,onSelect:te=>{te.stopPropagation(),N(`reset${U.charAt(0).toUpperCase()+U.slice(1)}`)},children:p(`gitView.history.actions.reset${U.charAt(0).toUpperCase()+U.slice(1)}`)},U))})]}),s.jsx(He,{variant:"outline",size:"xs",className:"h-6",disabled:S!==null,onClick:U=>{U.stopPropagation(),N("merge")},children:p("gitView.history.actions.merge")}),s.jsx(He,{variant:"outline",size:"xs",className:"h-6",disabled:S!==null,onClick:U=>{U.stopPropagation(),N("rebase")},children:p("gitView.history.actions.rebase")})]}):null,l?s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:p("gitView.history.loadingFiles")})]}):c.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground py-2",children:p("gitView.history.noFiles")}):s.jsx("ul",{className:"space-y-0.5 py-2",children:c.map(U=>s.jsxs("li",{children:[s.jsxs("button",{type:"button",onClick:()=>J(U),className:De("w-full flex items-center gap-2 typography-micro text-left cursor-pointer transition-colors rounded px-1",v.has(U.path)?"bg-sidebar/90":"hover:bg-sidebar/40"),children:[s.jsx("span",{className:De("font-semibold w-3 text-center shrink-0",ow(U.changeType)),children:U.changeType}),s.jsx("span",{className:"truncate text-foreground min-w-0",title:U.path,children:U.path}),!U.isBinary&&s.jsxs("span",{className:"shrink-0",children:[s.jsxs("span",{style:{color:"var(--status-success)"},children:["+",U.insertions]}),s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),s.jsxs("span",{style:{color:"var(--status-error)"},children:["-",U.deletions]})]}),U.isBinary&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:p("gitView.history.binary")}),s.jsx(I,{name:v.has(U.path)?"arrow-down-s":"arrow-right-s",className:"size-3 shrink-0 text-muted-foreground"})]}),v.has(U.path)&&s.jsx("div",{className:"max-h-[400px] overflow-y-auto rounded border border-border/40 mx-2 mb-1","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:U.changeType==="R"?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.renamedNoDiff")}):U.isBinary?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.binaryNoDiff")}):(()=>{const te=U.insertions+U.deletions;if(!E.has(U.path)&&te>Sd)return s.jsxs("div",{className:"flex flex-col items-start gap-1 px-3 py-2 text-sm text-muted-foreground",children:[s.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:p("gitView.history.largeDiffTitle",{count:te})}),s.jsx("div",{className:"typography-meta text-muted-foreground",children:p("gitView.history.largeDiffDescription")}),s.jsx(He,{type:"button",variant:"ghost",size:"xs",className:"h-6 px-0 text-primary hover:bg-transparent hover:underline",onClick:()=>{O(ue=>new Set(ue).add(U.path)),W(U)},children:p("gitView.history.renderDiffAnyway")})]});const Z=F.get(U.path);return Z==="loading"||Z===void 0?s.jsx("div",{className:"px-3 py-2 text-sm text-muted-foreground",children:p("gitView.history.loadingDiff")}):Z==="error"?s.jsx("button",{type:"button",onClick:()=>J(U),className:"w-full text-left px-3 py-2 text-sm text-muted-foreground hover:bg-[var(--interactive-hover)] transition-colors",children:p("gitView.history.diffError")}):s.jsx(Zl,{original:Z.original,modified:Z.modified,language:zl(U.path)||"",fileName:U.path,renderSideBySide:!1,layout:"inline",enableComments:!1})})()})]},U.path))})]})]})}),Pd=["var(--chart-1)","var(--chart-2)","var(--chart-3)","var(--chart-4)","var(--chart-5)","var(--syntax-keyword)","var(--syntax-string)","var(--status-info)"];function Ni(t){return Pd[t%Pd.length]}function lw(t){if(t.length===0)return[];const e=[],n=[];for(let r=0;r<t.length;r++){const o=t[r],i=[];for(let x=0;x<e.length;x++)e[x]===o.hash&&i.push(x);let c=i.length>0?i[0]:-1;if(c===-1){const x=e.indexOf(null);x!==-1?c=x:(c=e.length,e.push(null))}const l=i.slice(1),d=Ni(c),u=e[c]===o.hash,h=o.parents.length>0;h?e[c]=o.parents[0]:e[c]=null;const f=[];for(let x=1;x<o.parents.length;x++){const b=o.parents[x],S=e.indexOf(b);if(S!==-1)f.push(S);else{const g=e.indexOf(null),m=g!==-1?g:e.length;e[m]=b,m===e.length&&e.push(b),f.push(m)}}const p=[];u&&h?p.push({fromLane:c,toLane:c,color:d,type:"commit-lane"}):u&&!h?p.push({fromLane:c,toLane:c,color:d,type:"top-stub"}):!u&&h&&p.push({fromLane:c,toLane:c,color:d,type:"bottom-stub"});for(const x of l)p.push({fromLane:x,toLane:c,color:Ni(x),type:"merge-in"}),e[x]=null;for(const x of f)p.push({fromLane:c,toLane:x,color:Ni(x),type:"branch-out"});for(let x=0;x<e.length;x++)e[x]!==null&&x!==c&&(f.includes(x)||p.push({fromLane:x,toLane:x,color:Ni(x),type:"passing"}));n.push({commit:o,lane:c,color:d,connectors:p})}return n}const cw=[{labelKey:"gitView.history.logSize25",value:25},{labelKey:"gitView.history.logSize50",value:50},{labelKey:"gitView.history.logSize100",value:100}],dw=t=>{const e=nt.c(84),{mode:n,log:r,isLogLoading:o,logMaxCount:i,onLogMaxCountChange:c,expandedCommitHashes:l,onToggleCommit:d,commitFilesMap:u,loadingCommitHashes:h,onCopyHash:f,directory:p,showHeader:x,contentMaxHeightClassName:b,branchDivider:S,onConflict:g,onActionSuccess:m}=t,y=n===void 0?"history":n,C=x===void 0?!0:x,j=b===void 0?"max-h-[50vh]":b,w=S===void 0?null:S,{t:N}=ft(),[v,P]=a.useState(!0),F=y==="graph";let k;e[0]!==F||e[1]!==r?(k=F&&r?lw(r.all):[],e[0]=F,e[1]=r,e[2]=k):k=e[2];const E=k;let O;e[3]!==E?(O=Math.max(1,...E.map(uw)),e[3]=E,e[4]=O):O=e[4];const M=O;let L;e[5]!==E?(L=new Map(E.map(fw)),e[5]=E,e[6]=L):L=e[6];const _=L;if(!r)return null;const D=w!==null&&w.insertBeforeIndex>0&&w.insertBeforeIndex<r.all.length,A=w!==null&&w.insertBeforeIndex===r.all.length,T=D||A;let z;e[7]!==w||e[8]!==D||e[9]!==A||e[10]!==r.all?(z=D?r.all.slice(0,w.insertBeforeIndex):A?r.all:[],e[7]=w,e[8]=D,e[9]=A,e[10]=r.all,e[11]=z):z=e[11];const R=z;let W;if(e[12]!==w||e[13]!==u||e[14]!==j||e[15]!==p||e[16]!==l||e[17]!==D||e[18]!==T||e[19]!==F||e[20]!==o||e[21]!==_||e[22]!==h||e[23]!==r.all||e[24]!==i||e[25]!==M||e[26]!==y||e[27]!==m||e[28]!==g||e[29]!==f||e[30]!==c||e[31]!==d||e[32]!==N||e[33]!==R){const pe=D?r.all.slice(w.insertBeforeIndex):[];let V;e[35]!==w?.direction?(V=w?.direction==="down"?s.jsx(I,{name:"arrow-down-s",className:"size-3.5"}):s.jsx(I,{name:"arrow-up",className:"size-3.5"}),e[35]=w?.direction,e[36]=V):V=e[36];const Q=V;let ne;e[37]!==u||e[38]!==p||e[39]!==l||e[40]!==F||e[41]!==_||e[42]!==h||e[43]!==M||e[44]!==y||e[45]!==m||e[46]!==g||e[47]!==f||e[48]!==d?(ne=ye=>s.jsx("ul",{className:"divide-y divide-border/60",children:ye.map(he=>s.jsx(aw,{entry:he,mode:y,laned:F?_.get(he.hash):void 0,totalLanes:F?M:void 0,isExpanded:l.has(he.hash),onToggle:()=>d(he.hash),files:u.get(he.hash)??[],isLoadingFiles:h.has(he.hash),onCopyHash:f,directory:p,onConflict:g,onActionSuccess:m},he.hash))}),e[37]=u,e[38]=p,e[39]=l,e[40]=F,e[41]=_,e[42]=h,e[43]=M,e[44]=y,e[45]=m,e[46]=g,e[47]=f,e[48]=d,e[49]=ne):ne=e[49];const oe=ne;let ce;e[50]!==o||e[51]!==r.all.length||e[52]!==i||e[53]!==c||e[54]!==N?(ce=r.all.length>=i?s.jsx("div",{className:"flex justify-center py-2 border-t border-border/40",children:s.jsx(He,{type:"button",variant:"ghost",size:"xs",onClick:()=>c(i+25),disabled:o,className:"px-3 text-muted-foreground hover:text-foreground",children:o?s.jsxs("span",{className:"flex items-center gap-1",children:[s.jsx(I,{name:"loader-4",className:"size-3 animate-spin"}),N("gitView.history.loadingMore")]}):N("gitView.history.loadMore")})}):null,e[50]=o,e[51]=r.all.length,e[52]=i,e[53]=c,e[54]=N,e[55]=ce):ce=e[55];const ke=ce;W=s.jsx(On,{outerClassName:`min-h-0 ${j}`,className:"h-full w-full",children:r.all.length===0?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:N("gitView.history.noCommits")})}):T&&w?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex flex-col gap-0",children:[R.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:oe(R)}):null,s.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5","aria-hidden":!0,children:[s.jsx("span",{className:"h-px flex-1 bg-border/60"}),s.jsxs("span",{className:"inline-flex max-w-[80%] items-center gap-1 typography-micro text-muted-foreground",children:[s.jsx("span",{className:"truncate",title:w.branchName,children:w.branchName}),Q]}),s.jsx("span",{className:"h-px flex-1 bg-border/60"})]}),pe.length>0?s.jsx("div",{className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:oe(pe)}):null]}),ke]}):s.jsxs(s.Fragment,{children:[oe(r.all),ke]})}),e[12]=w,e[13]=u,e[14]=j,e[15]=p,e[16]=l,e[17]=D,e[18]=T,e[19]=F,e[20]=o,e[21]=_,e[22]=h,e[23]=r.all,e[24]=i,e[25]=M,e[26]=y,e[27]=m,e[28]=g,e[29]=f,e[30]=c,e[31]=d,e[32]=N,e[33]=R,e[34]=W}else W=e[34];const J=W;if(!C){if(T){let V;return e[56]!==J?(V=s.jsx("section",{className:"h-full min-h-0",children:J}),e[56]=J,e[57]=V):V=e[57],V}let pe;return e[58]!==J?(pe=s.jsx("section",{className:"h-full min-h-0 rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:J}),e[58]=J,e[59]=pe):pe=e[59],pe}let U;e[60]!==N?(U=N("gitView.history.title"),e[60]=N,e[61]=U):U=e[61];let te;e[62]!==U?(te=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:U}),e[62]=U,e[63]=te):te=e[63];let Z;e[64]!==o||e[65]!==v||e[66]!==i||e[67]!==c||e[68]!==N?(Z=v&&s.jsx("div",{onClick:mw,onPointerDown:hw,children:s.jsxs(gn,{value:String(i),onValueChange:pe=>c(Number(pe)),disabled:o,children:[s.jsx(xn,{size:"sm",className:"w-auto",disabled:o,children:s.jsx(sn,{placeholder:N("gitView.history.commitsPlaceholder")})}),s.jsx(bn,{children:cw.map(pe=>s.jsx(bs,{value:String(pe.value),children:N(pe.labelKey)},pe.value))})]})}),e[64]=o,e[65]=v,e[66]=i,e[67]=c,e[68]=N,e[69]=Z):Z=e[69];let ue;e[70]!==v?(ue=v?s.jsx(I,{name:"arrow-up-s",className:"size-4 text-muted-foreground"}):s.jsx(I,{name:"arrow-down-s",className:"size-4 text-muted-foreground"}),e[70]=v,e[71]=ue):ue=e[71];let Oe;e[72]!==Z||e[73]!==ue?(Oe=s.jsxs("div",{className:"flex items-center gap-2",children:[Z,ue]}),e[72]=Z,e[73]=ue,e[74]=Oe):Oe=e[74];let se;e[75]!==te||e[76]!==Oe?(se=s.jsxs(xi,{className:"flex w-full items-center justify-between px-3 h-10 hover:bg-transparent",children:[te,Oe]}),e[75]=te,e[76]=Oe,e[77]=se):se=e[77];let G;e[78]!==J?(G=s.jsx(Eo,{children:J}),e[78]=J,e[79]=G):G=e[79];let Ie;return e[80]!==v||e[81]!==se||e[82]!==G?(Ie=s.jsxs(To,{open:v,onOpenChange:P,className:"rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[se,G]}),e[80]=v,e[81]=se,e[82]=G,e[83]=Ie):Ie=e[83],Ie};function uw(t){return t.lane+1}function fw(t){return[t.commit.hash,t]}function mw(t){return t.stopPropagation()}function hw(t){return t.stopPropagation()}const pw=t=>{const e=nt.c(150),{open:n,onOpenChange:r,conflictFiles:o,directory:i,operation:c,onAbort:l,onClearState:d}=t;let u;e[0]!==o?(u=o===void 0?[]:o,e[0]=o,e[1]=u):u=e[1];const h=u,{t:f}=ft(),p=et(gw),x=et(xw),b=lo(bw),S=lo(yw),g=Re(ww),[m,y]=a.useState(!1),[C,j]=a.useState(null),[w,N]=a.useState(null);let v,P;e[2]!==i||e[3]!==n||e[4]!==f?(v=()=>{!n||!i||(y(!0),N(null),j(null),wp(i).then(le=>{j(le)}).catch(le=>{const ee=le instanceof Error?le.message:f("gitView.conflict.loadFailed");N(ee)}).finally(()=>{y(!1)}))},P=[n,i,f],e[2]=i,e[3]=n,e[4]=f,e[5]=v,e[6]=P):(v=e[5],P=e[6]),a.useEffect(v,P);let F;e[7]!==C||e[8]!==i||e[9]!==c?(F=async()=>{if(!C)return null;const le=c==="merge"?"merge":"rebase",ee=C.headInfo||(c==="merge"?"MERGE_HEAD":"REBASE_HEAD"),ie=c==="merge"?"git commit --no-edit":"git rebase --continue",ve=await Ro("git.conflict.resolve.visible",{operation_label:le,head_ref:ee}),K=await Ro("git.conflict.resolve.instructions",{operation_label:le,directory:i,operation:c,head_info:C.headInfo||"N/A",continue_cmd:ie}),de=`${le} conflict context (JSON)
47
- ${JSON.stringify({directory:i,operation:C.operation,headInfo:C.headInfo,statusPorcelain:C.statusPorcelain,unmergedFiles:C.unmergedFiles,diff:C.diff},null,2)}`;return{visibleText:ve,instructionsText:K,payloadText:de}},e[7]=C,e[8]=i,e[9]=c,e[10]=F):F=e[10];const k=F;let E;e[11]!==l||e[12]!==r?(E=()=>{l(),r(!1)},e[11]=l,e[12]=r,e[13]=E):E=e[13];const O=E;let M;e[14]!==d||e[15]!==r?(M=()=>{d?.(),r(!1)},e[14]=d,e[15]=r,e[16]=M):M=e[16];const L=M;let _;e[17]!==k||e[18]!==x||e[19]!==d||e[20]!==r||e[21]!==g||e[22]!==b||e[23]!==S||e[24]!==f?(_=async()=>{const le=await k();if(!le){fe.error(f("gitView.conflict.noDetailsAvailable"));return}if(!x){fe.error(f("gitView.conflict.noActiveSession"),{description:f("gitView.conflict.noActiveSessionDescription")});return}b(le.visibleText,"replace"),S([{text:le.instructionsText,synthetic:!0},{text:le.payloadText,synthetic:!0}]),g("chat"),d?.(),r(!1)},e[17]=k,e[18]=x,e[19]=d,e[20]=r,e[21]=g,e[22]=b,e[23]=S,e[24]=f,e[25]=_):_=e[25];const D=_;let A;e[26]!==k||e[27]!==i||e[28]!==d||e[29]!==r||e[30]!==p||e[31]!==g||e[32]!==f?(A=async()=>{const le=await k();if(!le){fe.error(f("gitView.conflict.noDetailsAvailable"));return}p({directoryOverride:i,initialPrompt:le.visibleText,syntheticParts:[{text:le.instructionsText,synthetic:!0},{text:le.payloadText,synthetic:!0}]}),g("chat"),d?.(),r(!1)},e[26]=k,e[27]=i,e[28]=d,e[29]=r,e[30]=p,e[31]=g,e[32]=f,e[33]=A):A=e[33];const T=A;let z,R,W,J,U,te,Z,ue,Oe,se,G,Ie,pe,V,Q,ne,oe,ce,ke,ye,he,Ee;if(e[34]!==C||e[35]!==h||e[36]!==x||e[37]!==O||e[38]!==L||e[39]!==D||e[40]!==T||e[41]!==m||e[42]!==w||e[43]!==r||e[44]!==n||e[45]!==c||e[46]!==f){const le=f(c==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),ee=C?.unmergedFiles||h;W=Ts,he=n,Ee=r,R=Es,ye="max-w-md w-[calc(100vw-2rem)]",V="flex flex-col gap-4 overflow-hidden";let ie;e[69]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsx(I,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),e[69]=ie):ie=e[69];const ve=s.jsxs("div",{className:"flex items-center gap-2",children:[ie,s.jsx($s,{children:f("gitView.conflict.detectedTitle",{operation:le})})]});let K;e[70]!==c||e[71]!==f?(K=f("gitView.conflict.detectedDescription",{operation:c}),e[70]=c,e[71]=f,e[72]=K):K=e[72];let de;e[73]!==K?(de=s.jsx(Ks,{children:K}),e[73]=K,e[74]=de):de=e[74],e[75]!==ve||e[76]!==de?(Q=s.jsxs(Hs,{children:[ve,de]}),e[75]=ve,e[76]=de,e[77]=Q):Q=e[77],e[78]!==m||e[79]!==f?(ne=m&&s.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:f("gitView.conflict.loading")})]}),e[78]=m,e[79]=f,e[80]=ne):ne=e[80],e[81]!==w||e[82]!==f?(oe=w&&s.jsx("div",{className:"rounded-lg bg-[var(--status-error-bg)] p-3 text-[var(--status-error)] typography-meta break-words",children:f("gitView.conflict.errorLoadingDetails",{message:w})}),e[81]=w,e[82]=f,e[83]=oe):oe=e[83],e[84]!==ee||e[85]!==f?(ce=ee.length>0&&s.jsxs("div",{className:"space-y-2 overflow-hidden",children:[s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:f("gitView.conflict.conflictedFiles")}),s.jsx("span",{className:"typography-micro px-1.5 py-0.5 rounded bg-[var(--surface-elevated)] text-muted-foreground",children:ee.length})]}),s.jsx("div",{className:"bg-[var(--surface-elevated)] rounded-lg p-3 max-h-40 overflow-y-auto overflow-x-hidden",children:s.jsx("ul",{className:"space-y-1",children:ee.map(vw)})})]}),e[84]=ee,e[85]=f,e[86]=ce):ce=e[86],e[87]!==C||e[88]!==f?(ke=C?.headInfo&&s.jsxs("div",{className:"space-y-1 overflow-hidden",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:f("gitView.conflict.headInfo")}),s.jsx("div",{className:"typography-micro text-foreground font-mono bg-[var(--surface-elevated)] rounded-lg p-3 max-h-24 overflow-y-auto break-words whitespace-pre-wrap",children:C.headInfo})]}),e[87]=C,e[88]=f,e[89]=ke):ke=e[89],G="flex flex-col gap-2 pt-2";let _e;e[90]!==T?(_e=()=>{T()},e[90]=T,e[91]=_e):_e=e[91];const Pe=m||!C;let re;e[92]!==m?(re=m?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"add",className:"size-4"}),e[92]=m,e[93]=re):re=e[93];let me;e[94]!==f?(me=f("gitView.conflict.resolveNewSession"),e[94]=f,e[95]=me):me=e[95],e[96]!==_e||e[97]!==Pe||e[98]!==re||e[99]!==me?(Ie=s.jsxs(He,{variant:"default",onClick:_e,disabled:Pe,className:"w-full gap-2",children:[re,me]}),e[96]=_e,e[97]=Pe,e[98]=re,e[99]=me,e[100]=Ie):Ie=e[100];let ge;e[101]!==D?(ge=()=>{D()},e[101]=D,e[102]=ge):ge=e[102];const $=m||!C||!x;let B;e[103]!==m?(B=m?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"chat-1",className:"size-4"}),e[103]=m,e[104]=B):B=e[104];let xe;e[105]!==f?(xe=f("gitView.conflict.resolveCurrentSession"),e[105]=f,e[106]=xe):xe=e[106],e[107]!==ge||e[108]!==$||e[109]!==B||e[110]!==xe?(pe=s.jsxs(He,{variant:"outline",onClick:ge,disabled:$,className:"w-full gap-2",children:[B,xe]}),e[107]=ge,e[108]=$,e[109]=B,e[110]=xe,e[111]=pe):pe=e[111],Oe="flex gap-2 pt-1";let be;e[112]!==f?(be=f("gitView.conflict.continueLater"),e[112]=f,e[113]=be):be=e[113],e[114]!==L||e[115]!==be?(se=s.jsx(He,{variant:"ghost",size:"sm",onClick:L,className:"flex-1",children:be}),e[114]=L,e[115]=be,e[116]=se):se=e[116],z=He,J="destructive",U="sm",te=O,Z="flex-1",ue=f("gitView.conflict.abortOperation",{operation:le}),e[34]=C,e[35]=h,e[36]=x,e[37]=O,e[38]=L,e[39]=D,e[40]=T,e[41]=m,e[42]=w,e[43]=r,e[44]=n,e[45]=c,e[46]=f,e[47]=z,e[48]=R,e[49]=W,e[50]=J,e[51]=U,e[52]=te,e[53]=Z,e[54]=ue,e[55]=Oe,e[56]=se,e[57]=G,e[58]=Ie,e[59]=pe,e[60]=V,e[61]=Q,e[62]=ne,e[63]=oe,e[64]=ce,e[65]=ke,e[66]=ye,e[67]=he,e[68]=Ee}else z=e[47],R=e[48],W=e[49],J=e[50],U=e[51],te=e[52],Z=e[53],ue=e[54],Oe=e[55],se=e[56],G=e[57],Ie=e[58],pe=e[59],V=e[60],Q=e[61],ne=e[62],oe=e[63],ce=e[64],ke=e[65],ye=e[66],he=e[67],Ee=e[68];let Ue;e[117]!==z||e[118]!==J||e[119]!==U||e[120]!==te||e[121]!==Z||e[122]!==ue?(Ue=s.jsx(z,{variant:J,size:U,onClick:te,className:Z,children:ue}),e[117]=z,e[118]=J,e[119]=U,e[120]=te,e[121]=Z,e[122]=ue,e[123]=Ue):Ue=e[123];let Me;e[124]!==Oe||e[125]!==se||e[126]!==Ue?(Me=s.jsxs("div",{className:Oe,children:[se,Ue]}),e[124]=Oe,e[125]=se,e[126]=Ue,e[127]=Me):Me=e[127];let X;e[128]!==G||e[129]!==Ie||e[130]!==pe||e[131]!==Me?(X=s.jsxs("div",{className:G,children:[Ie,pe,Me]}),e[128]=G,e[129]=Ie,e[130]=pe,e[131]=Me,e[132]=X):X=e[132];let Ne;e[133]!==V||e[134]!==Q||e[135]!==ne||e[136]!==oe||e[137]!==ce||e[138]!==ke||e[139]!==X?(Ne=s.jsxs("div",{className:V,children:[Q,ne,oe,ce,ke,X]}),e[133]=V,e[134]=Q,e[135]=ne,e[136]=oe,e[137]=ce,e[138]=ke,e[139]=X,e[140]=Ne):Ne=e[140];let Ae;e[141]!==R||e[142]!==ye||e[143]!==Ne?(Ae=s.jsx(R,{className:ye,children:Ne}),e[141]=R,e[142]=ye,e[143]=Ne,e[144]=Ae):Ae=e[144];let Se;return e[145]!==W||e[146]!==he||e[147]!==Ee||e[148]!==Ae?(Se=s.jsx(W,{open:he,onOpenChange:Ee,children:Ae}),e[145]=W,e[146]=he,e[147]=Ee,e[148]=Ae,e[149]=Se):Se=e[149],Se};function gw(t){return t.openNewSessionDraft}function xw(t){return t.currentSessionId}function bw(t){return t.setPendingInputText}function yw(t){return t.setPendingSyntheticParts}function ww(t){return t.setActiveMainTab}function vw(t){return s.jsx("li",{className:"typography-micro text-foreground font-mono truncate block",title:t,children:t},t)}const jw=({open:t,onOpenChange:e,operation:n,targetBranch:r,onConfirm:o})=>{const{t:i}=ft(),[c,l]=a.useState(!0),[d,u]=a.useState(!1),h=i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase"),f=async()=>{u(!0);try{await o(c),e(!1)}catch(x){const b=x instanceof Error?x.message:`Failed to ${n}`;fe.error(b)}finally{u(!1)}},p=()=>{d||e(!1)};return s.jsx(Ts,{open:t,onOpenChange:d?void 0:e,children:s.jsxs(Es,{className:"max-w-md",children:[s.jsxs(Hs,{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"alert",className:"size-5 text-[var(--status-warning)]"}),s.jsx($s,{children:i("gitView.stash.title")})]}),s.jsx(Ks,{children:i("gitView.stash.description",{operation:n})})]}),s.jsxs("div",{className:"py-2",children:[s.jsx("p",{className:"typography-meta text-muted-foreground mb-3",children:i("gitView.stash.thisWill")}),s.jsxs("ol",{className:"list-decimal list-inside space-y-1 typography-meta text-foreground",children:[s.jsx("li",{children:i("gitView.stash.stepStash")}),s.jsxs("li",{children:[i(n==="merge"?"gitView.operation.merge":"gitView.operation.rebase")," ",i(n==="merge"?"gitView.stash.mergeWith":"gitView.stash.rebaseOnto")," ",s.jsx("span",{className:"font-mono text-primary",children:r})]}),c&&s.jsx("li",{children:i("gitView.stash.stepRestore")})]})]}),s.jsxs("div",{className:"flex items-center gap-2 py-2",children:[s.jsx(ao,{checked:c,onChange:l,disabled:d,ariaLabel:i("gitView.stash.restoreAria")}),s.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!d&&l(!c),children:i("gitView.stash.restoreAfterOperation",{operation:n})})]}),s.jsxs(ar,{className:"gap-2",children:[s.jsx(He,{variant:"ghost",size:"sm",onClick:p,disabled:d,children:i("gitView.common.cancel")}),s.jsx(He,{variant:"default",size:"sm",onClick:f,disabled:d,className:"gap-1.5",children:d?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),i("gitView.common.processing")]}):i("gitView.stash.confirmButton",{operation:h})})]})]})})},Sw=({mergeInProgress:t,rebaseInProgress:e,onContinue:n,onAbort:r,onResolveWithAI:o,conflictCount:i=0,isLoading:c=!1})=>{const{t:l}=ft(),[d,u]=a.useState(null),h=t&&t.head,f=e&&(e.headName||e.onto),p=h?"merge":f?"rebase":null;if(!p)return null;const x=async()=>{u("continue");try{await n()}finally{u(null)}},b=async()=>{u("abort");try{await r()}finally{u(null)}},S=d!==null,g=i>0,m=l(p==="merge"?"gitView.operation.merge":"gitView.operation.rebase");let y="";t?y=t.message?l("gitView.operation.mergingMessage",{message:t.message}):l("gitView.operation.mergeInProgressWithHead",{head:t.head}):e&&(y=e.headName?l("gitView.operation.rebasingOnto",{headName:e.headName,onto:e.onto||""}):l("gitView.operation.rebaseInProgress"));const C=g?i===1?l("gitView.operation.inProgressTitleOneConflict",{operation:m,count:i}):l("gitView.operation.inProgressTitleManyConflicts",{operation:m,count:i}):l("gitView.operation.inProgressTitle",{operation:m}),j=l(g?"gitView.operation.resolveConflictsHint":"gitView.operation.readyToContinueHint");return s.jsx("div",{className:"mx-4 mt-3 overflow-hidden rounded-lg border border-[var(--status-warning-border)]",children:s.jsxs("div",{className:"flex flex-col gap-3 p-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-warning)]",children:C}),y&&s.jsx("p",{className:"typography-micro break-words text-muted-foreground",children:y})]}),s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[s.jsx("p",{className:"typography-micro min-w-0 flex-1 text-muted-foreground",children:j}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[s.jsxs(He,{variant:"ghost",size:"sm",onClick:b,disabled:S||c,className:"gap-1.5",children:[d==="abort"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"close",className:"size-4"}),l("gitView.operation.abort")]}),g?o&&s.jsx(He,{variant:"default",size:"sm",onClick:o,disabled:S||c,children:l("gitView.operation.resolveWithAi")}):s.jsxs(He,{variant:"default",size:"sm",onClick:x,disabled:S||c,className:"gap-1.5",children:[d==="continue"?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"check",className:"size-4"}),l("gitView.operation.continue")]})]})]})]})})},kw=t=>{const e=nt.c(104),{currentBranch:n,localBranches:r,remoteBranches:o,onMerge:i,onRebase:c,disabled:l,isOperating:d,operationLogs:u,onOperationComplete:h,mode:f,defaultTargetBranch:p}=t,x=l===void 0?!1:l,b=d===void 0?!1:d,S=u===void 0?[]:u,g=f===void 0?"dialog":f,{t:m}=ft(),[y,C]=a.useState(!1),[j,w]=a.useState("merge"),[N,v]=a.useState(null),[P,F]=a.useState(!1),[k,E]=a.useState(""),O=a.useRef(null),M=a.useRef(null),L=x||b,_=n||m("gitView.branch.currentBranchFallback"),D=S.length>0&&S.every(Nw),A=S.some(Cw);let T;e[0]===Symbol.for("react.memo_cache_sentinel")?(T=()=>{M.current&&(M.current.scrollTop=M.current.scrollHeight)},e[0]=T):T=e[0],a.useEffect(T,[S]);let z;if(e[1]!==k||e[2]!==n||e[3]!==r||e[4]!==o){e:{const ge=k.toLowerCase();let $;e[6]!==o?($=new Set(o.map(Aw).filter(Boolean)),e[6]=o,e[7]=$):$=e[7];const B=$;let xe;e[8]!==n||e[9]!==B?(xe=Le=>Le!==n&&!B.has(Le),e[8]=n,e[9]=B,e[10]=xe):xe=e[10];const be=r.filter(xe);if(!ge){z=be;break e}z=be.filter(Le=>Le.toLowerCase().includes(ge))}e[1]=k,e[2]=n,e[3]=r,e[4]=o,e[5]=z}else z=e[5];const R=z;let W;if(e[11]!==k||e[12]!==o){e:{const ge=k.toLowerCase();if(!ge){W=o;break e}W=o.filter($=>$.toLowerCase().includes(ge))}e[11]=k,e[12]=o,e[13]=W}else W=e[13];const J=W;let U;e[14]!==p||e[15]!==r||e[16]!==o?(U=()=>p&&(o.includes(p)||r.includes(p))?p:null,e[14]=p,e[15]=r,e[16]=o,e[17]=U):U=e[17];const te=U;let Z;e[18]!==te||e[19]!==C?(Z=()=>{C(!0),v(te()),w("merge"),E("")},e[18]=te,e[19]=C,e[20]=Z):Z=e[20];const ue=Z;let Oe;e[21]===Symbol.for("react.memo_cache_sentinel")?(Oe=ge=>{v(ge),F(!1),E("")},e[21]=Oe):Oe=e[21];const se=Oe;let G;e[22]!==i||e[23]!==c||e[24]!==j||e[25]!==N?(G=()=>{N&&(j==="merge"?i(N):c(N))},e[22]=i,e[23]=c,e[24]=j,e[25]=N,e[26]=G):G=e[26];const Ie=G;let pe;e[27]!==b||e[28]!==C?(pe=()=>{b||(v(null),w("merge"),E(""),C(!1))},e[27]=b,e[28]=C,e[29]=pe):pe=e[29];const V=pe,Q=()=>{b&&!D||(D&&h?.(),v(null),w("merge"),E(""),C(!1))};let ne,oe;e[30]!==P?(ne=()=>{P||E("")},oe=[P],e[30]=P,e[31]=ne,e[32]=oe):(ne=e[31],oe=e[32]),a.useEffect(ne,oe);let ce,ke;e[33]!==g||e[34]!==te||e[35]!==N?(ce=()=>{g==="dialog"||N||v(te())},ke=[g,te,N],e[33]=g,e[34]=te,e[35]=N,e[36]=ce,e[37]=ke):(ce=e[36],ke=e[37]),a.useEffect(ce,ke);const Ee=b?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{ref:M,className:"rounded-lg border border-border bg-muted/30 p-3 max-h-48 overflow-y-auto",children:s.jsx("div",{className:"space-y-2",children:S.map(Dw)})}),D?g==="dialog"?s.jsx(ar,{children:s.jsx(He,{variant:"default",size:"sm",onClick:Q,children:m(A?"gitView.common.close":"gitView.common.done")})}):s.jsx("div",{className:"flex justify-end",children:s.jsx(He,{variant:"default",size:"sm",onClick:Q,children:m(A?"gitView.common.close":"gitView.common.done")})}):null]}):s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:m("gitView.branch.operation")}),s.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>w("merge"),className:De("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",j==="merge"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-merge",className:De("size-4",j==="merge"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:De("typography-ui-label",j==="merge"?"text-foreground":"text-muted-foreground"),children:m("gitView.operation.merge")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:m("gitView.branch.mergeDescription")})]}),s.jsxs("button",{type:"button",onClick:()=>w("rebase"),className:De("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",j==="rebase"?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{name:"git-branch",className:De("size-4",j==="rebase"?"text-primary":"text-muted-foreground")}),s.jsx("span",{className:De("typography-ui-label",j==="rebase"?"text-foreground":"text-muted-foreground"),children:m("gitView.operation.rebase")})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:m("gitView.branch.rebaseDescription")})]})]})]}),s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("p",{className:"typography-meta text-muted-foreground",children:j==="merge"?m("gitView.branch.branchToMergeInto",{branch:_}):m("gitView.branch.branchToRebaseOnto")}),s.jsxs(Qs,{open:P,onOpenChange:F,modal:!1,children:[s.jsx(qs,{asChild:!0,children:s.jsxs("button",{type:"button",className:De(xa({size:"default"}),"w-full"),children:[s.jsx("span",{className:De("truncate",!N&&"text-muted-foreground"),children:N||m("gitView.branch.selectBranch")}),s.jsx(I,{name:"arrow-down-s",className:"size-4 opacity-60 shrink-0"})]})}),s.jsx(Ys,{align:"start",sideOffset:6,className:"w-[var(--anchor-width)] p-0 max-h-[min(var(--available-height),24rem)] flex flex-col overflow-hidden",children:s.jsxs(ba,{className:"h-full min-h-0",children:[s.jsx(ya,{ref:O,placeholder:m("gitView.branch.searchPlaceholder"),value:k,onValueChange:E,onKeyDown:Pw}),s.jsxs(wa,{className:"h-full min-h-0",disableHorizontal:!0,children:[s.jsx(va,{children:m("gitView.branch.empty")}),R.length>0&&s.jsx(kr,{heading:m("gitView.branch.localBranches"),children:R.map(ge=>s.jsx(Nr,{onSelect:()=>se(ge),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ge})},`local-${ge}`))}),R.length>0&&J.length>0?s.jsx(vp,{}):null,J.length>0&&s.jsx(kr,{heading:m("gitView.branch.remoteBranches"),children:J.map(ge=>s.jsx(Nr,{onSelect:()=>se(ge),children:s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ge})},`remote-${ge}`))})]})]})})]})]}),N?s.jsx("div",{className:"rounded-lg bg-muted/50 p-3",children:s.jsx("p",{className:"typography-meta text-muted-foreground",children:j==="merge"?s.jsxs(s.Fragment,{children:[m("gitView.branch.summaryMergePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:N})," ",m("gitView.branch.summaryMergeInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:_})]}):s.jsxs(s.Fragment,{children:[m("gitView.branch.summaryRebasePrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:_})," ",m("gitView.branch.summaryRebaseInfix")," ",s.jsx("span",{className:"font-mono text-foreground",children:N})]})})}):null,g==="dialog"?s.jsxs(ar,{className:"gap-2 pt-1",children:[s.jsx(He,{variant:"ghost",size:"sm",onClick:V,children:m("gitView.common.cancel")}),s.jsx(He,{variant:"default",size:"sm",onClick:Ie,disabled:!N,className:"gap-1.5",children:j==="merge"?s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"git-merge",className:"size-4"}),m("gitView.operation.merge")]}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"git-branch",className:"size-4"}),m("gitView.operation.rebase")]})})]}):s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsx(He,{variant:"destructive",size:"sm",onClick:V,disabled:L,children:m("gitView.common.reset")}),s.jsx("div",{className:"flex-1"}),s.jsx(He,{variant:"default",size:"sm",onClick:Ie,disabled:L||!N,children:m(j==="merge"?"gitView.operation.merge":"gitView.operation.rebase")})]})]});if(g==="bare")return Ee;if(g==="inline"){let ge;e[38]!==m?(ge=m("gitView.branch.updateTitle"),e[38]=m,e[39]=ge):ge=e[39];let $;e[40]!==ge?($=s.jsx("div",{className:"typography-ui-header font-semibold text-foreground",children:ge}),e[40]=ge,e[41]=$):$=e[41];let B;e[42]!==m?(B=m("gitView.branch.updateDescriptionPrefix"),e[42]=m,e[43]=B):B=e[43];let xe;e[44]!==_?(xe=s.jsx("span",{className:"font-mono text-foreground",children:_}),e[44]=_,e[45]=xe):xe=e[45];let be;e[46]!==B||e[47]!==xe?(be=s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[B," ",xe,"."]}),e[46]=B,e[47]=xe,e[48]=be):be=e[48];let Le;e[49]!==$||e[50]!==be?(Le=s.jsx("header",{className:"border-b border-border/40 px-0 py-3",children:s.jsxs("div",{className:"space-y-1",children:[$,be]})}),e[49]=$,e[50]=be,e[51]=Le):Le=e[51];let Ke;e[52]!==Ee?(Ke=s.jsx("div",{className:"pt-3",children:Ee}),e[52]=Ee,e[53]=Ke):Ke=e[53];let st;return e[54]!==Le||e[55]!==Ke?(st=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[Le,Ke]}),e[54]=Le,e[55]=Ke,e[56]=st):st=e[56],st}let Ue;e[57]!==b?(Ue=b?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-merge",className:"size-4"}),e[57]=b,e[58]=Ue):Ue=e[58];let Me;e[59]!==m?(Me=m("gitView.branch.mergeRebase"),e[59]=m,e[60]=Me):Me=e[60];let X;e[61]!==Me?(X=s.jsx("span",{children:Me}),e[61]=Me,e[62]=X):X=e[62];let Ne;e[63]!==ue||e[64]!==L||e[65]!==Ue||e[66]!==X?(Ne=s.jsx(Ct,{asChild:!0,children:s.jsxs(He,{variant:"outline",size:"sm",className:"gap-1.5",onClick:ue,disabled:L,children:[Ue,X]})}),e[63]=ue,e[64]=L,e[65]=Ue,e[66]=X,e[67]=Ne):Ne=e[67];let Ae;e[68]!==m?(Ae=m("gitView.branch.mergeRebaseTooltip"),e[68]=m,e[69]=Ae):Ae=e[69];let Se;e[70]!==Ae?(Se=s.jsx(At,{sideOffset:8,children:Ae}),e[70]=Ae,e[71]=Se):Se=e[71];let le;e[72]!==Ne||e[73]!==Se?(le=s.jsxs(Nt,{children:[Ne,Se]}),e[72]=Ne,e[73]=Se,e[74]=le):le=e[74];let ee;e[75]!==Q||e[76]!==C?(ee=ge=>{ge?C(!0):Q()},e[75]=Q,e[76]=C,e[77]=ee):ee=e[77];let ie;e[78]!==m?(ie=m("gitView.branch.updateTitle"),e[78]=m,e[79]=ie):ie=e[79];let ve;e[80]!==ie?(ve=s.jsx($s,{children:ie}),e[80]=ie,e[81]=ve):ve=e[81];let K;e[82]!==A||e[83]!==b||e[84]!==j||e[85]!==D||e[86]!==m||e[87]!==_?(K=b?m(D?A?"gitView.branch.operationFailed":"gitView.branch.operationCompleted":j==="merge"?"gitView.branch.mergingInProgress":"gitView.branch.rebasingInProgress"):s.jsxs(s.Fragment,{children:[m("gitView.branch.dialogDescriptionPrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:_}),"."]}),e[82]=A,e[83]=b,e[84]=j,e[85]=D,e[86]=m,e[87]=_,e[88]=K):K=e[88];let de;e[89]!==K?(de=s.jsx(Ks,{children:K}),e[89]=K,e[90]=de):de=e[90];let _e;e[91]!==ve||e[92]!==de?(_e=s.jsxs(Hs,{children:[ve,de]}),e[91]=ve,e[92]=de,e[93]=_e):_e=e[93];let Pe;e[94]!==Ee||e[95]!==_e?(Pe=s.jsxs(Es,{className:"max-w-md",children:[_e,Ee]}),e[94]=Ee,e[95]=_e,e[96]=Pe):Pe=e[96];let re;e[97]!==y||e[98]!==ee||e[99]!==Pe?(re=s.jsx(Ts,{open:y,onOpenChange:ee,children:Pe}),e[97]=y,e[98]=ee,e[99]=Pe,e[100]=re):re=e[100];let me;return e[101]!==le||e[102]!==re?(me=s.jsxs(s.Fragment,{children:[le,re]}),e[101]=le,e[102]=re,e[103]=me):me=e[103],me};function Nw(t){return t.status==="done"||t.status==="error"}function Cw(t){return t.status==="error"}function Aw(t){return t.slice(t.indexOf("/")+1)}function Dw(t,e){return s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsxs("div",{className:"mt-0.5 shrink-0",children:[t.status==="running"&&s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin text-primary"}),t.status==="done"&&s.jsx(I,{name:"check",className:"size-3.5 text-success"}),t.status==="error"&&s.jsx(I,{name:"close",className:"size-3.5 text-destructive"}),t.status==="pending"&&s.jsx("div",{className:"size-3.5 rounded-full border border-muted-foreground/30"})]}),s.jsx("span",{className:De("typography-micro",t.status==="error"&&"text-destructive",t.status==="done"&&"text-muted-foreground",t.status==="running"&&"text-foreground",t.status==="pending"&&"text-muted-foreground/60"),children:t.message})]},e)}function Pw(t){return t.stopPropagation()}const ac=t=>{const{remoteNames:e,localBranches:n,worktreeCreatedFromBranch:r,rootBranchHint:o}=t,i=d=>{if(!d)return"";let u=d.trim();if(!u||u==="HEAD")return"";if(n.includes(u))return u;u.startsWith("refs/heads/")&&(u=u.slice(11)),u.startsWith("heads/")&&(u=u.slice(6)),u.startsWith("remotes/")&&(u=u.slice(8));const h=u.indexOf("/");if(h>0){const f=u.slice(0,h);if(e.has(f)){const p=u.slice(h+1).trim();p&&(u=p)}}return u},c=i(typeof r=="string"?r:"");if(c)return c;const l=i(typeof o=="string"?o:"");return l||(n.includes("main")?"main":n.includes("master")?"master":n.includes("develop")?"develop":"main")},Iw=({runMutation:t,onMutationComplete:e,onMutationError:n,onPathsComplete:r,scheduleFlush:o})=>{const i=[];let c=!1;return{enqueue:d=>{const u=i[i.length-1];if(u?.directory===d.directory&&u.direction===d.direction){d.paths.forEach(h=>u.paths.add(h));return}i.push(d)},flush:()=>{if(c)return;const d=i.shift();if(!d)return;c=!0;const u={directory:d.directory,direction:d.direction,paths:Array.from(d.paths),rollback:d.rollback};(async()=>{try{await t(u),e(u)}catch(h){n(u,h)}finally{r(u.paths),c=!1,i.length>0&&o()}})()},clear:()=>{i.length=0},size:()=>i.length,isRunning:()=>c}},Rw=15e3,Mw=40,Tw=20,Id={feat:":sparkles:",feature:":sparkles:",fix:":bug:",bug:":bug:",hotfix:":ambulance:",docs:":memo:",documentation:":memo:",style:":lipstick:",refactor:":recycle:",perf:":zap:",performance:":zap:",test:":white_check_mark:",tests:":white_check_mark:",build:":construction_worker:",ci:":green_heart:",chore:":wrench:",revert:":rewind:",wip:":construction:",security:":lock:",release:":bookmark:",merge:":twisted_rightwards_arrows:",mv:":truck:",move:":truck:",rename:":truck:",remove:":fire:",delete:":fire:",add:":sparkles:",create:":sparkles:",implement:":sparkles:",update:":recycle:",improve:":zap:",optimize:":zap:",upgrade:":arrow_up:",downgrade:":arrow_down:",deploy:":rocket:",init:":tada:",initial:":tada:"},Ew=(t,e)=>{const n=t.toLowerCase(),r=/^([a-z]+)(?:\(.*\))?!?:/,o=n.match(r);if(o){const l=o[1],d=Id[l];if(d)return e.find(u=>u.code===d)||null}const i=n.split(" ")[0],c=Id[i];return c&&e.find(l=>l.code===c)||null},Fw=20,bo=new Map,Ow=(t,e)=>{if(bo.delete(t),bo.set(t,e),bo.size>Fw){const n=bo.keys().next().value;n!==void 0&&bo.delete(n)}},vr=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Rd=t=>{const e=t.index?.trim();return!!(e&&e!=="?")},Lw=t=>{const e=t.working_dir?.trim(),n=t.index?.trim();return!!(e||n==="?")},Sl=({isActive:t})=>{const{t:e}=ft(),{git:n}=_n(),r=Wr(),[o,i]=a.useState(null),[c,l]=a.useState(!1),d=et(q=>q.currentSessionId),u=et(q=>q.newSessionDraft),h=et(q=>q.setDraftBootstrapPendingDirectory),f=et(q=>q.worktreeMetadata),p=et(q=>q.availableWorktrees),x=vr(r),b=a.useMemo(()=>{if(!x)return;const q=p.find(we=>vr(we.path)===x);if(q)return q;for(const we of f.values())if(vr(we.path)===x)return we},[p,x,f]),S=a.useMemo(()=>{if(d)return f.get(d)??b;if(u?.open)return b},[d,b,u?.open,f]),{profiles:g,globalIdentity:m,defaultGitIdentityId:y,loadProfiles:C,loadGlobalIdentity:j,loadDefaultGitIdentityId:w}=ax(nr(q=>({profiles:q.profiles,globalIdentity:q.globalIdentity,defaultGitIdentityId:q.defaultGitIdentityId,loadProfiles:q.loadProfiles,loadGlobalIdentity:q.loadGlobalIdentity,loadDefaultGitIdentityId:q.loadDefaultGitIdentityId}))),N=Vl(r??null),v=Bo(r??null),P=Bl(q=>d?q.getAttachment(d):void 0),F=P?jp(P):[],k=P&&!P.degraded&&!P.legacy?P.worktreeRoot??void 0:void 0,E=fm(r,S,v?.current??void 0),O=ja(r??null),M=Sp(r??null),L=kp(r??null),_=Wl(r??null),D=Np(r??null),{setActiveDirectory:A,fetchAll:T,ensureAll:z,fetchStatus:R,fetchBranches:W,fetchLog:J,setLogMaxCount:U,fetchIdentity:te,prefetchDiffs:Z,clearDiffCache:ue,moveStatusPathsOptimistically:Oe,restoreStatus:se,bumpIndexRevision:G}=tn(nr(q=>({setActiveDirectory:q.setActiveDirectory,fetchAll:q.fetchAll,ensureAll:q.ensureAll,fetchStatus:q.fetchStatus,fetchBranches:q.fetchBranches,fetchLog:q.fetchLog,setLogMaxCount:q.setLogMaxCount,fetchIdentity:q.fetchIdentity,prefetchDiffs:q.prefetchDiffs,clearDiffCache:q.clearDiffCache,moveStatusPathsOptimistically:q.moveStatusPathsOptimistically,restoreStatus:q.restoreStatus,bumpIndexRevision:q.bumpIndexRevision}))),Ie=Re(q=>q.isMobile),pe=Re(q=>q.openContextDiff),V=Re(q=>q.openContextSurface),Q=v?.current??null,ne=en(q=>!r||!Q?null:Af(q.entries,r,Q)),oe=Re(q=>q.navigateToDiff),ce=a.useRef(null),ke=a.useRef(null),ye=a.useRef(null),he=a.useRef(null),Ee=a.useRef(!0);a.useEffect(()=>()=>{Ee.current=!1},[]);const Ue=a.useCallback(()=>{ke.current!==null&&(window.clearTimeout(ke.current),ke.current=null)},[]),Me=a.useCallback(q=>{Ue(),ke.current=window.setTimeout(()=>{ke.current=null,vr(q)===vr(r)&&R(q,n,{silent:!0})},Rw)},[Ue,r,R,n]);a.useEffect(()=>Ue,[Ue]);const X=a.useCallback(()=>{ye.current!==null&&(window.clearTimeout(ye.current),ye.current=null)},[]),Ne=a.useCallback(()=>{ye.current===null&&(ye.current=window.setTimeout(()=>{ye.current=null,he.current?.()},0))},[]),Ae=a.useCallback(async(q,we,Ce)=>{if(we==="stage"){if(n.stageGitFiles){await n.stageGitFiles(q,Ce);return}await Promise.all(Ce.map(Ve=>n.stageGitFile(q,Ve)));return}if(n.unstageGitFiles){await n.unstageGitFiles(q,Ce);return}await Promise.all(Ce.map(Ve=>n.unstageGitFile(q,Ve)))},[n]),Se=a.useMemo(()=>Iw({runMutation:({directory:q,direction:we,paths:Ce})=>Ae(q,we,Ce),onMutationComplete:({directory:q})=>{G(q),Me(q)},onMutationError:({directory:q,direction:we,rollback:Ce},Ve)=>{Ce?.(),G(q),Me(q);const dt=e(we==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.unstageFileFailed");fe.error(Ve instanceof Error?Ve.message:dt)},onPathsComplete:q=>{Ft(we=>{const Ce=new Set(we);return q.forEach(Ve=>Ce.delete(Ve)),Ce})},scheduleFlush:Ne}),[G,Ae,Ne,Me,e]);a.useEffect(()=>(he.current=Se.flush,()=>{he.current=null}),[Se]),a.useEffect(()=>()=>Se.clear(),[Se]),a.useEffect(()=>X,[X]),a.useEffect(()=>{if(!t)return;if(!r){i(null),l(!1);return}let q=!1,we=null;const Ce=async()=>{try{const Ve=await Ap(r);if(q)return;i(Ve.status),Ve.status==="pending"&&(we=window.setTimeout(()=>{Ce()},500))}catch{q||i(null)}};return Ce(),()=>{q=!0,we!==null&&window.clearTimeout(we)}},[t,r]),a.useEffect(()=>{const q=ce.current;ce.current=o,!(!r||!n)&&(q==="pending"&&o==="ready"&&(l(!0),T(r,n).finally(()=>{window.setTimeout(()=>{l(!1)},1200)})),o==="failed"&&(h(null),l(!1)))},[r,T,n,h,o]);const le=vr(u?.bootstrapPendingDirectory??null),ee=!!(r&&le&&le===vr(r)),ve=!!(r&&(o==="pending"||ee))||c,K=a.useMemo(()=>r?bo.get(r)??null:null,[r]),de=ts(q=>q.settingsGitmojiEnabled),[_e,Pe]=a.useState(null),{gitmojis:re}=Ky(de);a.useEffect(()=>{const q=k||E?.projectDirectory;if(!q){Pe(null);return}let we=!1;return pi(q).then(Ce=>{if(we)return;const Ve=Ce.trim();Pe(Ve&&Ve!=="HEAD"?Ve:null)}).catch(()=>{we||Pe(null)}),()=>{we=!0}},[k,E?.projectDirectory]);const[me,ge]=a.useState(K?.commitMessage??""),[$,B]=a.useState([]),[xe,be]=a.useState(!1),Le=a.useRef(null),[Ke,st]=a.useState(null),[ut,mt]=a.useState(!1),[pt,ht]=a.useState(null),[xt,wt]=a.useState(25),[bt,Dt]=a.useState(!1),{triggerFireworks:qt}=Vy(),Ut=a.useRef(new Map),We=a.useRef(0),yt=a.useCallback(()=>{We.current+=1,Ee.current&&Dt(!0)},[]),Qe=a.useCallback(()=>{We.current=Math.max(0,We.current-1),Ee.current&&We.current===0&&Dt(!1)},[]),[Rt,Ot]=a.useState(new Set),[kt,Ft]=a.useState(new Set),[Ht,Xt]=a.useState(!1),[rt,je]=a.useState(0),[Fe,Te]=a.useState(!1),[it,ct]=a.useState(K?.generatedHighlights??[]),Kt=kt.size>0||Se.size()>0||Se.isRunning(),Lt=a.useCallback(()=>{const q=Le.current;q&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{q.scrollTo({top:q.scrollHeight,behavior:"smooth"})})})},[]),ze=k||E?.projectDirectory||null,Xe=v?.current||null,tt=a.useMemo(()=>{const q=v?.tracking;return q?q.startsWith("origin/"):!0},[v?.tracking]),at=a.useMemo(()=>{const q=E?.createdFromBranch,we=typeof q=="string"?q.trim():"",Ce=typeof v?.current=="string"?v.current.trim():"",Ve=typeof _e=="string"?_e.trim():"";return we?we===Ce&&we.startsWith("opencode/")&&Ve.length>0&&Ve!==we?Ve:we:Ve||Ce||"HEAD"},[E?.createdFromBranch,v,_e]),Ze=a.useCallback(()=>{ct([])},[]),[Pt,Tt]=a.useState(new Set),[Jt,ls]=a.useState(new Map),[cs,Bt]=a.useState(new Set),_t=a.useRef(Jt),Mt=a.useRef(cs),[ps,_s]=a.useState(null),[Wt,Fs]=a.useState(null),[cn,Gs]=a.useState(""),[as,Xs]=a.useState(null),[Gn,qn]=a.useState(!1),[dn,un]=a.useState(!1),[yn,Os]=a.useState([]),[zs,nn]=a.useState(null),[zn,rn]=a.useState(null),[pr,Dn]=a.useState([]),[Ir,Ss]=a.useState(!1),[ae,qe]=a.useState([]),[lt,gt]=a.useState("merge"),[Gt,Et]=a.useState(null),[St,xs]=a.useState(!1),[As,ss]=a.useState(100),[ks,Ls]=a.useState(0),Bs=a.useMemo(()=>d?`openchamber.conflict:${d}`:null,[d]),Be=a.useCallback((q,we,Ce)=>{if(!Bs||typeof window>"u")return;const Ve={directory:q,conflictFiles:we,operation:Ce};window.localStorage.setItem(Bs,JSON.stringify(Ve))},[Bs]),It=a.useCallback(()=>{!Bs||typeof window>"u"||window.localStorage.removeItem(Bs)},[Bs]);a.useEffect(()=>{if(!Bs||typeof window>"u"||!r)return;const q=window.localStorage.getItem(Bs);if(q)try{const we=JSON.parse(q);if(we.directory!==r){window.localStorage.removeItem(Bs);return}qe(we.conflictFiles??[]),gt(we.operation??"merge"),Ss(!0)}catch{window.localStorage.removeItem(Bs)}},[Bs,r]);const[ns,ds]=a.useState(!1),[ws,Ds]=a.useState("merge"),[on,Ps]=a.useState(""),fn=a.useCallback(q=>{rr(q).then(we=>{if(we.ok){fe.success(e("gitView.toast.commitHashCopied"));return}fe.error(e("gitView.toast.copyFailed"))})},[e]),lr=a.useCallback(q=>{Tt(we=>{const Ce=new Set(we);return Ce.has(q)?Ce.delete(q):Ce.add(q),Ce})},[]);a.useEffect(()=>{_t.current=Jt},[Jt]),a.useEffect(()=>{Mt.current=cs},[cs]),a.useEffect(()=>{if(!r||!n)return;const q=Array.from(Pt).filter(Ce=>!_t.current.has(Ce)&&!Mt.current.has(Ce));if(q.length===0)return;let we=!1;return Bt(Ce=>{const Ve=new Set(Ce);for(const dt of q)Ve.add(dt);return Mt.current=Ve,Ve}),Promise.all(q.map(Ce=>n.getCommitFiles(r,Ce).then(Ve=>({hash:Ce,files:Ve.files})).catch(Ve=>(console.error("Failed to fetch commit files:",Ve),{hash:Ce,files:[]})))).then(Ce=>{we||(ls(Ve=>{const dt=new Map(Ve);for(const{hash:$t,files:os}of Ce)dt.set($t,os);return _t.current=dt,dt}),Bt(Ve=>{const dt=new Set(Ve);for(const{hash:$t}of Ce)dt.delete($t);return Mt.current=dt,dt}))}),()=>{we=!0,Bt(Ce=>{let Ve=!1;const dt=new Set(Ce);for(const $t of q)dt.delete($t)&&(Ve=!0);return Ve?(Mt.current=dt,dt):Ce})}},[Pt,r,n]),a.useEffect(()=>{r&&Ow(r,{directory:r,commitMessage:me,generatedHighlights:it})},[me,r,it]),a.useEffect(()=>{t&&(C(),j(),w())},[t,C,j,w]),a.useEffect(()=>{if(!t)return;if(!r||!n?.getRemoteUrl){Fs(null);return}let q=!1;return n.getRemoteUrl(r).then(we=>{q||Fs(we)}).catch(()=>{q||Fs(null)}),()=>{q=!0}},[t,r,n]);const vs=a.useCallback(async()=>{if(!r||!n?.getRemotes){Os([]);return}try{const q=await n.getRemotes(r);Ee.current&&Os(q)}catch{Ee.current&&Os([])}},[r,n]);a.useEffect(()=>{t&&vs()},[t,vs]),a.useEffect(()=>{t&&r&&(A(r),z(r,n))},[t,r,A,z,n]),a.useEffect(()=>{if(t&&r)return Kn.onGitRefreshHint(q=>{vr(q.directory)===vr(r)&&(q.paths?.length&&ue(r,q.paths),R(r,n,{silent:!0}))})},[t,ue,r,R,n]);const zt=a.useCallback(async(q=!0)=>{if(r)try{await Promise.all([R(r,n),W(r,n)])}catch(we){if(q){const Ce=we instanceof Error?we.message:e("gitView.toast.refreshRepositoryFailed");fe.error(Ce)}}},[r,n,R,W,e]),us=a.useCallback(async()=>{r&&await J(r,n,xt)},[r,n,J,xt]),Rr=a.useCallback(async()=>{r&&await te(r,n)},[r,n,te]);a.useEffect(()=>{if(!t||!r||!n?.hasLocalIdentity||N!==!0)return;const q=typeof y=="string"?y.trim():"";if(!q||q==="global"||Ut.current.get(r)===q)return;let Ce=!1;return(async()=>{try{const dt=await n.hasLocalIdentity?.(r);if(Ce||dt===!0)return;yt(),await n.setGitIdentity(r,q),Ut.current.set(r,q),await Rr()}catch(dt){console.warn("Failed to auto-apply default git identity:",dt)}finally{Ce||Qe()}})(),()=>{Ce=!0}},[t,yt,r,y,Qe,n,N,Rr]);const Pn=a.useMemo(()=>v?[...v.files??[]].sort((we,Ce)=>we.path.localeCompare(Ce.path)):[],[v]),Vs=a.useMemo(()=>Pn.filter(Rd),[Pn]),cr=a.useMemo(()=>Pn.filter(Lw),[Pn]);a.useEffect(()=>{if(!r||Pn.length===0)return;const q=[],we=new Set,Ce=dt=>{!dt||we.has(dt)||(we.add(dt),q.push(dt))};if(Vs.forEach(dt=>Ce(dt.path)),$.forEach(Ce),Pn.slice(0,Tw).forEach(dt=>Ce(dt.path)),q.length===0)return;const Ve=window.setTimeout(()=>{Z(r,n,q,{maxFiles:Mw})},120);return()=>{window.clearTimeout(Ve)}},[Pn,r,n,Z,Vs,$]);const gr=q=>q?.pushed[0]?.remote||v?.tracking?.split("/")[0]||Is.find(we=>we.name==="origin")?.name||Is[0]?.name||"origin",Ur=async(q,we)=>{if(r){st(q);try{const Ce=Ve=>{const dt=`${Ve.name}/`,$t=v?.tracking?.startsWith(dt)?v.tracking.slice(dt.length):void 0;return{remote:Ve.name,branch:$t,rebase:!0}};if(q==="fetch"){if(!we)throw new Error("No remote available for fetch");await n.gitFetch(r,{remote:we.name}),fe.success(e("gitView.toast.fetchedFromRemote",{name:we.name}))}else if(q==="pull"){if(!we)throw new Error("No remote available for pull");const Ve=await n.gitPull(r,Ce(we));fe.success(Ve.files.length===1?e("gitView.toast.pulledFilesSingle",{count:Ve.files.length,name:we.name}):e("gitView.toast.pulledFilesPlural",{count:Ve.files.length,name:we.name}))}else if(q==="push"){const Ve=await n.gitPush(r);fe.success(e("gitView.toast.pushedToUpstream",{name:gr(Ve)}))}else if(q==="sync"){if(!we)throw new Error("No remote available for sync");let Ve=0,dt=!1;await n.gitFetch(r,{remote:we.name});const $t=await n.getGitStatus(r);if(($t.behind??0)>0){if(($t.files?.length??0)>0){fe.error(e("gitView.toast.commitOrStashBeforeSync"));return}Ve=(await n.gitPull(r,Ce(we))).files.length}((await n.getGitStatus(r)).ahead??0)>0&&(await n.gitPush(r),dt=!0),Ve>0&&dt?fe.success(Ve===1?e("gitView.toast.syncedPulledSingleAndPushed",{count:Ve,name:we.name}):e("gitView.toast.syncedPulledPluralAndPushed",{count:Ve,name:we.name})):Ve>0?fe.success(Ve===1?e("gitView.toast.pulledFilesSingle",{count:Ve,name:we.name}):e("gitView.toast.pulledFilesPlural",{count:Ve,name:we.name})):dt?fe.success(e("gitView.toast.pushedToUpstream",{name:we.name})):fe.success(e("gitView.toast.alreadyUpToDate"))}await zt(!1),await us()}catch(Ce){const Ve=Ce instanceof Error?Ce.message:e("gitView.toast.syncActionFailed",{action:q==="sync"?e("gitView.sync.syncChanges"):q==="pull"?e("gitView.sync.pull"):q});fe.error(Ve)}finally{st(null)}}},Vo=a.useCallback(async q=>{if(!r)return;const we=q.name.trim();if(!we){fe.error(e("gitView.toast.remoteNameRequired"));return}if(we==="origin"){fe.error(e("gitView.toast.cannotRemoveOriginRemote"));return}nn(we);try{await n.removeRemote(r,{remote:we}),fe.success(e("gitView.toast.removedRemote",{name:we})),await Promise.all([zt(!1),vs()])}catch(Ce){const Ve=Ce instanceof Error?Ce.message:`Failed to remove ${we}`;fe.error(Ve)}finally{nn(null)}},[r,n,vs,zt,e]),Hr=async(q={})=>{if(!r)return;if(!me.trim()){fe.error(e("gitView.toast.enterCommitMessage"));return}const we=Vs.map(Ve=>Ve.path).sort();if(we.length===0){fe.error(e("gitView.toast.stageFileToCommit"));return}const Ce=q.pushAfter?"commitAndPush":"commit";ht(Ce);try{if(await n.createGitCommit(r,me.trim(),{files:we,stageFiles:[]}),G(r),fe.success(e("gitView.toast.commitCreated")),ge(""),Ze(),await zt(),q.pushAfter){const Ve=v?.tracking?.split("/")[0],dt=Is.find(vi=>vi.name===Ve)??Is[0];if(!dt)throw new Error(e("mobile.changes.noRemote"));st("sync");const $t=`${dt.name}/`,os=v?.tracking?.startsWith($t)?v.tracking.slice($t.length):void 0;await n.gitFetch(r,{remote:dt.name});const Yt=await n.getGitStatus(r);if((Yt.behind??0)>0){if((Yt.files?.length??0)>0){fe.error(e("gitView.toast.commitOrStashBeforeSync")),await zt(!1);return}await n.gitPull(r,{remote:dt.name,branch:os,rebase:!0})}const Js=await n.getGitStatus(r);let Qr;(Js.ahead??0)>0&&(Qr=await n.gitPush(r)),fe.success(e("gitView.toast.pushedToUpstream",{name:gr(Qr)})),qt(),await zt(!1)}else await zt(!1);await us(),je(Ve=>Ve+1)}catch(Ve){const dt=Ve instanceof Error?Ve.message:e("gitView.toast.createCommitFailed");fe.error(dt)}finally{ht(null),q.pushAfter&&st(null)}},Wo=a.useCallback(async()=>{if(!r)return;const q=Vs.map(we=>we.path).sort();if(q.length===0){fe.error(e("gitView.toast.stageFileToDescribe"));return}console.error("[git-generation][browser] generate button clicked",{directory:r,selectedFiles:q.length}),Te(!0);try{const{message:we}=await Cp(r,q),Ce=we.subject?.trim()??"",Ve=Array.isArray(we.highlights)?we.highlights:[];if(Ce){let dt=Ce;if(de&&re.length>0){const $t=Ew(Ce,re);if($t){const{code:os,emoji:Yt}=$t;!Ce.startsWith(os)&&!Ce.startsWith(Yt)&&(dt=`${os} ${Ce}`)}}ge(dt)}ct(Ve),Lt()}catch(we){console.error("[git-generation][browser] GitView generate handler failed",{message:we instanceof Error?we.message:String(we),error:we});const Ce=we instanceof Error?we.message:e("gitView.toast.generateCommitMessageFailed");fe.error(Ce)}finally{Te(!1)}},[r,Vs,de,re,Lt,e]),Kr=q=>q.reason==="attention"?`${q.attentionReason} in progress`:q.reason==="missing"?"worktree is missing":"worktree is invalid",uo=async(q,we)=>{if(!r||!v)return;const Ce=Fa(P);if(Ce.length>0){fe.error(e("gitView.toast.cannotCreateBranch",{reason:Kr(Ce[0])}));return}const Ve=v.current??null,dt=we?.name??"origin";try{await n.createBranch(r,q,Ve??"HEAD"),fe.success(e("gitView.toast.createdBranch",{name:q})),await n.checkoutBranch(r,q);let $t=!1;try{await n.gitPush(r,{remote:dt,branch:q,options:["--set-upstream"]}),$t=!0}catch(os){const Yt=os instanceof Error?os.message:`Unable to push new branch to ${dt}.`;fe.warning(e("gitView.toast.branchCreatedLocally"),{description:s.jsxs("span",{className:"text-foreground/80 dark:text-foreground/70",children:["Upstream setup failed: ",Yt]})})}await zt(),await us(),$t&&fe.success(e("gitView.toast.upstreamSet",{branch:q,remote:dt}))}catch($t){const os=$t instanceof Error?$t.message:e("gitView.toast.createBranchFailed");throw fe.error(os),$t}},Uo=async(q,we)=>{if(!r)return;const Ce=Fa(P);if(Ce.length>0){fe.error(e("gitView.toast.cannotRenameBranch",{reason:Kr(Ce[0])}));return}try{await n.renameBranch(r,q,we),fe.success(e("gitView.toast.renamedBranch",{oldName:q,newName:we})),await zt(),await us()}catch(Ve){const dt=Ve instanceof Error?Ve.message:e("gitView.toast.renameBranchFailed",{oldName:q,newName:we});fe.error(dt)}},xr=async q=>{if(!r)return;const we=Fa(P);if(we.length>0){fe.error(e("gitView.toast.cannotCheckout",{reason:Kr(we[0])}));return}const Ce=q.replace(/^remotes\//,"");if(v?.current!==Ce)try{await n.checkoutBranch(r,Ce),fe.success(e("gitView.toast.checkedOut",{name:Ce})),await zt(),await us()}catch(Ve){const dt=Ve instanceof Error?Ve.message:e("gitView.toast.checkoutFailed",{name:Ce});fe.error(dt)}},Ho=async q=>{if(r){yt();try{await n.setGitIdentity(r,q.id),fe.success(e("gitView.toast.appliedIdentity",{name:q.name})),await Rr()}catch(we){const Ce=we instanceof Error?we.message:e("gitView.toast.applyIdentityFailed");fe.error(Ce)}finally{Qe()}}},an=a.useMemo(()=>O?.all?O.all.filter(q=>!q.startsWith("remotes/")).sort():[],[O]),In=a.useMemo(()=>O?.all?O.all.filter(q=>q.startsWith("remotes/")).map(q=>q.replace(/^remotes\//,"")).sort():[],[O]),Is=a.useMemo(()=>{if(yn.length>0)return yn;const q=new Set,we=v?.tracking?.trim();we&&we.includes("/")&&q.add(we.split("/")[0]);for(const Ce of In){const Ve=Ce.indexOf("/");Ve>0&&q.add(Ce.slice(0,Ve))}return q.size===0&&Wt&&q.add("origin"),Array.from(q).map(Ce=>({name:Ce,fetchUrl:Wt??"",pushUrl:Wt??""}))},[yn,In,Wt,v?.tracking]),Vn=a.useMemo(()=>ac({remoteNames:new Set(Is.map(q=>q.name)),localBranches:an,worktreeCreatedFromBranch:E?.createdFromBranch,rootBranchHint:_e}),[Is,an,_e,E?.createdFromBranch]),fo=a.useMemo(()=>Is.map(Ce=>Ce.name).map(Ce=>`${Ce}/${Vn}`).find(Ce=>In.includes(Ce))??Vn,[Vn,Is,In]),Ko=a.useMemo(()=>{const q=new Map;m&&q.set(m.id,m);let we=null;if(Wt)try{let Ce=Wt.trim();Ce.startsWith("git@")&&(Ce=`https://${Ce.slice(4).replace(":","/")}`),Ce.endsWith(".git")&&(Ce=Ce.slice(0,-4));const Ve=new URL(Ce);we=Ve.hostname+Ve.pathname}catch{}for(const Ce of g){if(Ce.authType!=="token"){q.set(Ce.id,Ce);continue}const Ve=Ce.host;if(!Ve){q.set(Ce.id,Ce);continue}if(!Ve.includes("/")){q.set(Ce.id,Ce);continue}we&&we===Ve&&q.set(Ce.id,Ce)}return Array.from(q.values())},[g,m,Wt]),mo=a.useMemo(()=>{if(L?.userName&&L?.userEmail){const q=g.find(we=>we.userName===L.userName&&we.userEmail===L.userEmail);return q||(m&&m.userName===L.userName&&m.userEmail===L.userEmail?m:{id:"local-config",name:L.userName,userName:L.userName,userEmail:L.userEmail,sshKey:L.sshCommand?.replace("ssh -i ","")??null,color:"info",icon:"user"})}return m??null},[L,g,m]),Go=Vs.length,wn=_||Ke!==null||pt!==null,dr=v?.current??null,br=!!(E&&ze&&Xe&&tt),Mr=!!dr,vn=br&&ze&&Xe&&E?{repoRoot:ze,sourceBranch:Xe,worktreeMetadata:E}:null;a.useEffect(()=>{if(!r||!n||!M?.all?.length||!dr||!Vn||dr===Vn){_s(null);return}let q=!1;return(async()=>{try{const Ce=await n.getGitLog(r,{from:Vn,to:"HEAD",maxCount:xt});if(q)return;const Ve=new Set((Ce?.all??[]).map($t=>$t.hash).filter($t=>typeof $t=="string"&&$t.length>0));if(Ve.size===0){_s(null);return}const dt=M.all.findIndex($t=>!Ve.has($t.hash));if(dt===0){_s(null);return}if(dt===-1){_s({insertBeforeIndex:M.all.length,branchName:dr,direction:"up"});return}_s({insertBeforeIndex:dt,branchName:dr,direction:"up"})}catch{q||_s(null)}})(),()=>{q=!0}},[Vn,dr,r,n,M,xt]),a.useEffect(()=>{Et(null)},[r]),a.useEffect(()=>{if(as!=="graph"||!r){as!=="graph"&&Et(null);return}let q=!1;return xs(!0),n.getGitLog(r,{maxCount:As,all:!0}).then(we=>{q||Et(we)}).catch(we=>{console.error("Failed to fetch graph log:",we)}).finally(()=>{q||xs(!1)}),()=>{q=!0}},[as,r,As,ks,n]);const Wn=a.useCallback((q,we)=>{if(!r||q.length===0)return;const Ce=Array.from(new Set(q));Ft(dt=>{const $t=new Set(dt);return Ce.forEach(os=>$t.add(os)),$t});const Ve=Oe(r,Ce,we);Se.enqueue({directory:r,direction:we,paths:new Set(Ce),rollback:()=>se(r,Ve)}),Ne()},[r,Se,Oe,se,Ne]),ur=a.useCallback(async q=>{if(r){Ot(we=>{const Ce=new Set(we);return Ce.add(q),Ce});try{await n.revertGitFile(r,q,{scope:"working"}),fe.success(e("gitView.toast.revertedFile",{path:q})),await zt(!1)}catch(we){const Ce=we instanceof Error?we.message:e("gitView.toast.revertFailed");fe.error(Ce)}finally{Ot(we=>{const Ce=new Set(we);return Ce.delete(q),Ce})}}},[r,zt,n,e]),H=a.useCallback(async(q,we,Ce="all")=>{if(!r||q.length===0)return;const Ve=Array.from(new Set(q));if(Ht||Ve.some(Yt=>Rt.has(Yt)))return;const dt=new Set(Vs.map(Yt=>Yt.path)),$t=Ce==="all"&&Ve.some(Yt=>dt.has(Yt));we&&Xt(!0),Ot(Yt=>{const Js=new Set(Yt);return Ve.forEach(Qr=>Js.add(Qr)),Js});const os=[];try{if(await Promise.all(Ve.map(async Yt=>{try{await n.revertGitFile(r,Yt,{scope:Ce})}catch(Js){os.push({path:Yt,message:Js instanceof Error?Js.message:e("gitView.toast.revertFailed")})}})),$t&&os.length<Ve.length&&G(r),await zt(!1),os.length===0)fe.success(Ve.length===1?e("gitView.toast.revertedFilesSingle",{count:Ve.length}):e("gitView.toast.revertedFilesPlural",{count:Ve.length}));else if(os.length===Ve.length)fe.error(os[0]?.message||e("gitView.toast.revertFailed"));else{const Yt=Ve.length-os.length;fe.warning(Yt===1?e("gitView.toast.revertedSomeSingle",{success:Yt,failed:os.length}):e("gitView.toast.revertedSomePlural",{success:Yt,failed:os.length}))}}finally{Ot(Yt=>{const Js=new Set(Yt);return Ve.forEach(Qr=>Js.delete(Qr)),Js}),we&&Xt(!1)}},[G,r,n,Ht,zt,Rt,Vs,e]),Ge=a.useCallback(async q=>{await H(q,!0)},[H]),ot=a.useCallback(async q=>{await H(q,!1,"working")},[H]),jt=a.useCallback((q,we)=>{if(r&&!Ie){pe(r,q,we);return}oe(q,we)},[r,Ie,oe,pe]),Zt=a.useCallback(()=>mt(!0),[]),es=a.useMemo(()=>{const q=[];return Vs.length>0&&q.push({id:"staged",title:e("gitView.changes.stagedTitle"),entries:Vs,actionSymbol:"-",actionAllLabel:e("gitView.changes.unstageAllAria"),getActionLabel:we=>e("gitView.changes.unstageFileAria",{path:we}),onActionFile:we=>{Wn([we],"unstage")},onActionAll:we=>{Wn(we,"unstage")},onViewDiff:we=>jt(we,!0),onRevertFile:ur,showRevertActions:!1,accent:!0}),cr.length>0&&q.push({id:"unstaged",title:e("gitView.changes.title"),entries:cr,actionSymbol:"+",actionAllLabel:e("gitView.changes.stageAllAria"),getActionLabel:we=>e("gitView.changes.stageFileAria",{path:we}),onActionFile:we=>{Wn([we],"stage")},onActionAll:we=>{Wn(we,"stage")},onViewDiff:we=>jt(we,!1),onRevertFile:ur}),q},[ur,jt,Wn,Vs,e,cr]),rs=a.useCallback(q=>{if(q.length===0)return;const we=q.map(Ce=>Ce.trim()).filter(Boolean);if(we.length===0){Ze();return}ge(Ce=>{const Ve=Ce.trim(),dt=Ve.length>0?`
48
-
49
- `:"";return`${Ve}${dt}${we.join(`
50
- `)}`.trim()}),Ze()},[Ze]),ys=a.useCallback((q,we)=>{const Ce=we||q;ge(Ve=>{const dt=Ve.trimStart();return dt.startsWith(q)||we&&dt.startsWith(we)?Ve:`${Ce.endsWith(" ")?Ce:`${Ce} `}${Ve}`.trimStart()}),Gs(""),be(!1)},[]),Rs=a.useCallback(q=>{const we=q instanceof Error?q.message.toLowerCase():"";return we.includes("uncommitted changes")||we.includes("local changes")||we.includes("your local changes would be overwritten")||we.includes("please commit your changes or stash them")||we.includes("cannot rebase: you have unstaged changes")||we.includes("error: cannot pull with rebase")},[]),Ns=a.useCallback((q,we)=>{Dn(Ce=>[...Ce,{message:q,status:we,timestamp:Date.now()}])},[]),Ms=a.useCallback((q,we)=>{Dn(Ce=>{if(Ce.length===0)return Ce;const Ve=[...Ce];return Ve[Ve.length-1]={...Ve[Ve.length-1],status:q,...we?{message:we}:{}},Ve})},[]),Yn=a.useCallback(()=>{Dn([])},[]),Gr=a.useCallback(()=>{Dn([]),rn(null)},[]),Qn=a.useCallback(q=>{const we=q.trim(),Ce=new Set(Is.map(dt=>dt.name)),Ve=we.indexOf("/");if(Ve>0){const dt=we.slice(0,Ve),$t=we.slice(Ve+1);if(Ce.has(dt)&&$t)return{branch:we,remote:dt,remoteBranch:$t}}for(const dt of Is){const $t=`${dt.name}/${we}`;if(In.includes($t))return{branch:$t,remote:dt.name,remoteBranch:we}}return{branch:we,remote:null,remoteBranch:null}},[Is,In]),jn=a.useCallback(async q=>{if(!r)return;rn("merge"),Yn();const we=v?.current,Ce=Qn(q);try{Ce.remote&&Ce.remoteBranch&&(Ns(`Fetching ${Ce.remote}/${Ce.remoteBranch}...`,"running"),await n.gitFetch(r,{remote:Ce.remote,branch:Ce.remoteBranch}),Ms("done",`Fetched ${Ce.remote}/${Ce.remoteBranch}`)),Ns(`Merging ${Ce.branch} into ${we}...`,"running");const Ve=await n.merge(r,{branch:Ce.branch});Ve.conflict?(Ms("error","Merge conflicts detected"),qe(Ve.conflictFiles??[]),gt("merge"),Ss(!0),Be(r,Ve.conflictFiles??[],"merge")):(Ms("done",`Merged ${Ce.branch} into ${we}`),It(),Ns("Refreshing repository status...","running"),await zt(),await us(),Ms("done","Repository status updated"))}catch(Ve){if(Rs(Ve))Ms("error","Uncommitted changes detected"),Ds("merge"),Ps(Ce.branch),ds(!0);else{const dt=Ve instanceof Error?Ve.message:`Failed to merge ${Ce.branch}`;Ms("error",dt)}}},[r,n,v,Qn,zt,us,Rs,Be,It,Ns,Ms,Yn]),Xn=a.useCallback(async q=>{if(!r)return;rn("rebase"),Yn();const we=v?.current,Ce=Qn(q);try{Ce.remote&&Ce.remoteBranch&&(Ns(`Fetching ${Ce.remote}/${Ce.remoteBranch}...`,"running"),await n.gitFetch(r,{remote:Ce.remote,branch:Ce.remoteBranch}),Ms("done",`Fetched ${Ce.remote}/${Ce.remoteBranch}`)),Ns(`Rebasing ${we} onto ${Ce.branch}...`,"running");const Ve=await n.rebase(r,{onto:Ce.branch});Ve.conflict?(Ms("error","Rebase conflicts detected"),qe(Ve.conflictFiles??[]),gt("rebase"),Ss(!0),Be(r,Ve.conflictFiles??[],"rebase")):(Ms("done",`Rebased ${we} onto ${Ce.branch}`),It(),Ns("Refreshing repository status...","running"),await zt(),await us(),Ms("done","Repository status updated"))}catch(Ve){if(Rs(Ve))Ms("error","Uncommitted changes detected"),Ds("rebase"),Ps(Ce.branch),ds(!0);else{const dt=Ve instanceof Error?Ve.message:`Failed to rebase onto ${Ce.branch}`;Ms("error",dt)}}},[r,n,v,Qn,zt,us,Rs,Be,It,Ns,Ms,Yn]),Un=a.useCallback(async()=>{if(r)try{lt==="merge"?(await n.abortMerge(r),fe.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(r),fe.success(e("gitView.toast.rebaseAborted"))),It(),await zt(),await us()}catch(q){const we=q instanceof Error?q.message:`Failed to abort ${lt}`;fe.error(we)}},[r,n,lt,zt,us,It,e]),Rn=a.useMemo(()=>v?.files?v.files.filter(q=>q.index==="U"||q.working_dir==="U"||q.index==="A"&&q.working_dir==="A"||q.index==="D"&&q.working_dir==="D").length:0,[v?.files]),fr=a.useCallback(async()=>{if(r)try{const q=!!v?.mergeInProgress?.head,we=!!(v?.rebaseInProgress?.headName||v?.rebaseInProgress?.onto);if(q){const Ce=await n.continueMerge(r);Ce.conflict?(qe(Ce.conflictFiles??[]),gt("merge"),Ss(!0),Be(r,Ce.conflictFiles??[],"merge"),fe.error(e("gitView.toast.mergeConflictsDetected"))):(It(),fe.success(e("gitView.toast.mergeCompleted")),await zt(),await us())}else if(we){const Ce=await n.continueRebase(r);Ce.conflict?(qe(Ce.conflictFiles??[]),gt("rebase"),Ss(!0),Be(r,Ce.conflictFiles??[],"rebase"),fe.error(e("gitView.toast.rebaseConflictsDetected"))):(It(),fe.success(e("gitView.toast.rebaseStepCompleted")),await zt(),await us())}}catch(q){const we=q instanceof Error?q.message:e("gitView.toast.continueOperationFailed");fe.error(we)}},[r,n,v,zt,us,Be,It,e]),qr=a.useCallback(async()=>{if(r)try{!!v?.mergeInProgress?.head?(await n.abortMerge(r),fe.success(e("gitView.toast.mergeAborted"))):(await n.abortRebase(r),fe.success(e("gitView.toast.rebaseAborted"))),It(),await zt(),await us()}catch(q){const we=q instanceof Error?q.message:e("gitView.toast.abortOperationFailed");fe.error(we)}},[r,n,v,zt,us,It,e]),Yr=a.useCallback(()=>{if(!r)return;const we=!!v?.mergeInProgress?.head?"merge":"rebase",Ce=v?.files?.filter(Ve=>Ve.index==="U"||Ve.working_dir==="U").map(Ve=>Ve.path)??[];Ce.length>0&&qe(Ce),gt(we),Ss(!0)},[r,v]),Ma=a.useCallback(async q=>{if(!r)return;const we=v?.current,Ce=ws,Ve=on,dt=(v?.files??[]).some(Rd);try{await n.stash(r,{message:`Auto-stash before ${Ce} with ${Ve}`,includeUntracked:!0}),dt&&G(r)}catch(Yt){const Js=Yt instanceof Error?Yt.message:"Failed to stash changes";fe.error(Js);return}let $t=!1,os=!1;try{if(Ce==="merge"){const Yt=await n.merge(r,{branch:Ve});Yt.conflict?(os=!0,qe(Yt.conflictFiles??[]),gt("merge"),Ss(!0)):($t=!0,fe.success(e("gitView.toast.mergedIntoBranch",{branch:Ve,currentBranch:we||""})))}else{const Yt=await n.rebase(r,{onto:Ve});Yt.conflict?(os=!0,qe(Yt.conflictFiles??[]),gt("rebase"),Ss(!0)):($t=!0,fe.success(e("gitView.toast.rebasedOntoBranch",{currentBranch:we||"",branch:Ve})))}if(q&&$t)try{await n.stashPop(r),G(r),fe.success(e("gitView.toast.stashedRestored"))}catch(Yt){const Js=Yt instanceof Error?Yt.message:e("gitView.toast.restoreStashFailed");fe.error(Js)}else q&&os&&fe.info(e("gitView.toast.restoreStashManually"));await zt(),await us()}catch(Yt){if(q)try{await n.stashPop(r),G(r)}catch{}throw Yt}},[G,r,n,v,ws,on,zt,us,e]),Sn=a.useCallback(q=>{wt(q),r&&(U(r,q),J(r,n,q))},[r,J,n,U]),yi=a.useCallback(q=>{ss(q)},[]),wi=a.useCallback(()=>{Xs(null),r&&(R(r,n),W(r,n),J(r,n,xt))},[r,R,W,J,xt,n]),ho=a.useCallback(q=>{if(q.conflict){if(q.operation==="cherry-pick"||q.operation==="revert"){fe.error(e("gitView.history.actions.conflictToastTitle"),{description:e("gitView.history.actions.conflictToastDescription",{files:q.conflictFiles?.join(", ")??"unknown files"})}),r&&(R(r,n),W(r,n),J(r,n,xt));return}qe(q.conflictFiles??[]),gt(q.operation),Ss(!0),r&&Be(r,q.conflictFiles??[],q.operation)}},[e,qe,gt,Ss,Be,r,R,W,J,xt,n]);return r?N===null||N===!0&&!v?s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"typography-ui-label",children:e("gitView.loading.checkingRepository")})]})}):N===!1?ve?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(I,{name:"loader-4",className:"mb-3 size-6 animate-spin text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e("gitView.empty.worktreeSetupInProgress")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("gitView.empty.worktreeSetupDescription")})]}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center px-4 text-center",children:[s.jsx(I,{name:"git-branch",className:"mb-3 size-6 text-muted-foreground"}),s.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e("gitView.empty.notGitRepository")}),s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:e("gitView.empty.notGitRepositoryDescription")}),F.includes("open-without-worktree-features")?s.jsx("p",{className:"typography-meta mt-2 text-muted-foreground",children:e("gitView.empty.worktreeFeaturesUnavailable")}):null]}):s.jsxs("div",{className:De("flex h-full flex-col overflow-hidden"),children:[s.jsx(lx,{status:v,localBranches:an,remoteBranches:In,branchInfo:O?.branches,syncAction:Ke,remotes:Is,onFetch:q=>Ur("fetch",q),onSync:q=>Ur("sync",q),onRemoveRemote:Vo,removingRemoteName:zs,onCheckoutBranch:xr,onCreateBranch:uo,onRenameBranch:Uo,activeIdentityProfile:mo,availableIdentities:Ko,onSelectIdentity:Ho,isApplyingIdentity:bt,isWorktreeMode:!!E,onOpenHistory:()=>Xs("history"),onOpenGraph:()=>Xs("graph"),onOpenStashes:Zt,onOpenUpdateBranch:Mr?()=>qn(!0):void 0,onOpenReintegrateCommits:vn?()=>un(!0):void 0,pullRequest:ne?.pr??null,prChecks:ne?.checks??null,onOpenPullRequest:r?()=>V(r,"pr"):void 0}),r&&(v?.mergeInProgress?.head||v?.rebaseInProgress?.headName||v?.rebaseInProgress?.onto)&&s.jsx(Sw,{mergeInProgress:v?.mergeInProgress,rebaseInProgress:v?.rebaseInProgress,onContinue:fr,onAbort:qr,onResolveWithAI:Yr,conflictCount:Rn,isLoading:_}),s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:s.jsx("div",{className:"h-full min-h-0 flex flex-col",children:s.jsx("div",{className:De("min-w-0 min-h-0 h-full flex flex-col"),children:s.jsx(On,{as:Sa,ref:Le,outerClassName:"flex-1 min-h-0",className:De("px-4","pt-1 pb-4"),disableHorizontal:!0,preventOverscroll:!0,children:s.jsx("div",{className:"flex h-full min-h-0 flex-col gap-3",children:(Pn?.length??0)>0?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:s.jsx(cx,{groups:es,diffStats:v?.diffStats,revertingPaths:Rt,isRevertingAll:Ht,onVisiblePathsChange:B,onRevertAll:Ge,onRevertDirectory:ot,headerBackgroundClassName:"bg-background"})}),s.jsx(dx,{stagedCount:Go,commitMessage:me,onCommitMessageChange:ge,generatedHighlights:it,onInsertHighlights:rs,onGenerateMessage:Wo,isGeneratingMessage:Fe,onCommit:()=>Hr({pushAfter:!1}),onCommitAndPush:()=>Hr({pushAfter:!0}),commitAction:pt,hasPendingIndexMutation:Kt,gitmojiEnabled:de,onOpenGitmojiPicker:()=>be(!0)})]}):s.jsx(tw,{onOpenStashes:()=>mt(!0)})})})})})}),s.jsx(Ts,{open:Gn,onOpenChange:q=>{!q&&zn!==null||qn(q)},children:s.jsxs(Es,{className:"max-w-2xl min-h-[26rem]",children:[s.jsxs(Hs,{children:[s.jsx($s,{children:e("gitView.branch.updateTitle")}),s.jsxs(Ks,{children:[e("gitView.branch.updateDescriptionPrefix")," ",s.jsx("span",{className:"font-mono text-foreground",children:v?.current??""}),"."]})]}),Mr?s.jsx(kw,{mode:"bare",currentBranch:v?.current,localBranches:an,remoteBranches:In,defaultTargetBranch:fo,onMerge:jn,onRebase:Xn,disabled:wn,isOperating:zn!==null,operationLogs:pr,onOperationComplete:Gr}):s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("gitView.branch.actionsUnavailable")})]})}),s.jsx(Ts,{open:dn,onOpenChange:un,children:s.jsxs(Es,{className:"max-w-2xl min-h-[26rem]",children:[s.jsxs(Hs,{children:[s.jsx($s,{children:e("gitView.integrate.title")}),s.jsx(Ks,{children:vn?s.jsxs("span",{className:"font-mono text-foreground",children:[vn.sourceBranch," → ",at]}):null})]}),vn?s.jsx(Zy,{repoRoot:vn.repoRoot,sourceBranch:vn.sourceBranch,worktreeMetadata:vn.worktreeMetadata,localBranches:an,defaultTargetBranch:at,refreshKey:rt,showHeader:!1,onRefresh:()=>{r&&(R(r,n),W(r,n),J(r,n,xt))}},vn.worktreeMetadata.path):null]})}),s.jsx(Ts,{open:as!==null,onOpenChange:q=>{q||Xs(null)},children:s.jsxs(Es,{className:"max-w-5xl h-[90vh] max-h-[90vh] flex flex-col overflow-hidden",children:[s.jsxs(Hs,{children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx($s,{children:e(as==="graph"?"gitView.graph.title":"gitView.history.title")}),s.jsxs(He,{type:"button",variant:"ghost",size:"sm",className:"mr-6 h-7 shrink-0 gap-1.5 px-2",onClick:()=>{if(as==="graph"){Ls(q=>q+1);return}r&&J(r,n,xt)},disabled:as==="graph"?St:D,title:e("gitView.history.refresh"),"aria-label":e("gitView.history.refresh"),children:[s.jsx(I,{name:"refresh",className:De("size-4",(as==="graph"?St:D)&&"animate-spin")}),e("gitView.history.refresh")]})]}),s.jsx(Ks,{children:e("gitView.history.dialogDescription")})]}),s.jsx("div",{className:"flex-1 min-h-0",children:s.jsx(dw,{mode:as==="graph"?"graph":"history",log:as==="graph"?Gt??M:M,isLogLoading:as==="graph"&&St||D,logMaxCount:as==="graph"?As:xt,onLogMaxCountChange:as==="graph"?yi:Sn,expandedCommitHashes:Pt,onToggleCommit:lr,commitFilesMap:Jt,loadingCommitHashes:cs,onCopyHash:fn,directory:r??void 0,showHeader:!1,contentMaxHeightClassName:"h-full max-h-none",branchDivider:as==="graph"?null:ps,onConflict:as==="graph"?ho:void 0,onActionSuccess:as==="graph"?wi:void 0})})]})}),s.jsx(ew,{open:ut,onOpenChange:mt,directory:r,hasUncommittedChanges:(v?.files?.length??0)>0,hasStagedChanges:Vs.length>0,uncommittedFileCount:v?.files?.length??0,onChanged:async q=>{r&&q?.affectsIndex&&G(r),await zt(!1),await us()}}),s.jsx(Ts,{open:xe,onOpenChange:be,children:s.jsxs(Es,{className:"max-w-md p-0 overflow-hidden",children:[s.jsx(Hs,{className:"px-4 pt-4",children:s.jsx($s,{children:e("gitView.gitmoji.title")})}),s.jsxs(ba,{className:"h-[420px]",children:[s.jsx(ya,{placeholder:e("gitView.gitmoji.searchPlaceholder"),value:cn,onValueChange:Gs}),s.jsxs(wa,{children:[s.jsx(va,{children:e("gitView.gitmoji.empty")}),s.jsx(kr,{children:(re.length===0?[]:re.filter(q=>{const we=cn.trim().toLowerCase();return we?q.emoji.includes(we)||q.code.toLowerCase().includes(we)||q.description.toLowerCase().includes(we):!0})).map(q=>s.jsxs(Nr,{onSelect:()=>ys(q.emoji,q.code),children:[s.jsx("span",{className:"text-lg",children:q.emoji}),s.jsx("span",{className:"typography-ui-label text-foreground",children:q.code}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:q.description})]},q.code))})]})]})]})}),r&&s.jsx(pw,{open:Ir,onOpenChange:Ss,conflictFiles:ae,directory:r,operation:lt,onAbort:Un,onClearState:It}),s.jsx(jw,{open:ns,onOpenChange:ds,operation:ws,targetBranch:on,onConfirm:Ma})]}):s.jsx("div",{className:"flex h-full items-center justify-center px-4 text-center",children:s.jsx("p",{className:"typography-ui-label text-muted-foreground",children:e("gitView.empty.selectSessionOrDirectory")})})},Bw=3e4,Md=20,mm=(t,e)=>JSON.stringify([$n(),t,e]),$w=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}},Td=()=>({result:null,hasCheckDetails:!1,fetchedAt:0,isLoading:!1,error:null}),Ci=new Map,_w=t=>{const e=Object.entries(t);return e.length<=Md?t:Object.fromEntries(e.sort(([,n],[,r])=>r.fetchedAt-n.fetchedAt).slice(0,Md))},Ed=$o()((t,e)=>({entries:{},ensure:async(n,r,o,i)=>{const c=mm(r,o),l=i?.includeCheckDetails??!1,d=e().entries[c],u=d&&d.result&&Date.now()-d.fetchedAt<Bw&&(d.hasCheckDetails||!l);if(!i?.force&&u)return d.result;const h=`${c}::${l?"details":"plain"}`,p=Ci.get(`${c}::details`)??(l?null:Ci.get(h));if(p&&!i?.force)return p;const x=(async()=>{t(b=>({entries:{...b.entries,[c]:{...b.entries[c]??Td(),isLoading:!0,error:null}}}));try{const b=await n.prContext(r,o,{includeDiff:!1,includeCheckDetails:l,sourceRepo:i?.sourceRepo??null});return t(S=>({entries:_w({...S.entries,[c]:{result:b,hasCheckDetails:l,fetchedAt:Date.now(),isLoading:!1,error:null}})})),b}catch(b){const S=b instanceof Error?b.message:"Failed to load pull request context";return t(g=>({entries:{...g.entries,[c]:{...g.entries[c]??Td(),isLoading:!1,error:S}}})),null}finally{Ci.delete(h)}})();return Ci.set(h,x),x},invalidate:(n,r)=>{t(o=>{const i={};for(const[c,l]of Object.entries(o.entries)){const d=$w(c);d&&d.directory===n&&(r==null||d.number===r)||(i[c]=l)}return{entries:i}})}})),zw=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}:{}}},Vw=35e3,Ua=(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),l=i%60;return l>0?`${c}h ${l}m`:`${c}h`},Ha=t=>{const e=typeof t=="string"?t.toLowerCase():"";return!!e&&!["success","neutral","skipped"].includes(e)},Fd=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"}},Ww=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"},Uw=[2e3,5e3],Od=t=>t.replace(/^refs\/heads\//,"").replace(/[-_]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,e=>e.toUpperCase()),$r=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):""},Hw=(t,e)=>{const n=$r(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},Kw=(t,e)=>`${t}::${e}`,lc=t=>{const e=String(t||"").trim();if(!e)return"";const n=e.indexOf("/");return n<=0?"":e.slice(0,n).trim()},Ka=(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=lc(e.trackingBranch);if(r){const i=r==="origin"?t.find(l=>l.name==="upstream"):null;if(i)return i;const c=t.find(l=>l.name===r);if(c)return c}const o=t.find(i=>i.name==="origin");return o||(t[0]??null)},Gw=t=>t.startsWith("pr-"),qw=(t,e)=>{const n=lc(e),r=new Map(t.map(c=>[c.name,c])),o=[],i=c=>{c&&(o.some(l=>l.name===c.name)||o.push(c))};return n&&i(r.get(n)),i(r.get("upstream")),i(r.get("origin")),t.filter(c=>!Gw(c.name)).forEach(c=>i(c)),t.forEach(c=>i(c)),o},Jo=new Map,Ga=Io;function Yw(t,e){const[n,r]=a.useState(null),[o,i]=a.useState([]),c=a.useRef(null);return a.useEffect(()=>{r(null),i([])},[t]),a.useEffect(()=>{if(!t||!e?.repoUpstream||c.current===t)return;c.current=t;let l=!1;return(async()=>{try{const d=await e.repoUpstream(t);if(l||!d?.isFork||!d.upstream||(r(d.upstream),!e.repoBranches))return;try{const u=await e.repoBranches(d.upstream.owner,d.upstream.repo);l||i(u)}catch{}}catch{}})(),()=>{l=!0}},[t,e]),{detectedUpstream:n,upstreamBranches:o}}const Qw=({directory:t,branch:e,baseBranch:n,trackingBranch:r,remotes:o=[],remoteBranches:i=[],onGeneratedDescription:c})=>{const{t:l}=ft(),d=Re(ae=>ae.timeFormatPreference),{github:u}=_n(),h=Dr(ae=>ae.status),f=Dr(ae=>ae.hasChecked),p=Re(ae=>ae.setSettingsDialogOpen),x=Re(ae=>ae.setSettingsPage),b=Re(ae=>ae.setActiveMainTab),S=et(ae=>ae.currentSessionId),g=et(ae=>!!ae.newSessionDraft?.open),{isMobile:m,hasTouchInput:y,screenWidth:C}=Pr(),j=Re(ae=>ae.openContextSurface),w=Tn(ae=>ae.requestSource),N=!m&&C>=768&&!ir(),v=a.useCallback(()=>{x("github"),p(!0)},[p,x]),P=a.useMemo(()=>Kw(t,e),[t,e]),F=a.useMemo(()=>Jo.get(P)??null,[P]),k=en(ae=>ae.ensureEntry),E=en(ae=>ae.setParams),O=en(ae=>ae.startWatching),M=en(ae=>ae.stopWatching),L=en(ae=>ae.refresh),_=en(ae=>ae.updateStatus),[D,A]=a.useState(()=>F?.title??Od(e)),[T,z]=a.useState(()=>F?.body??""),[R,W]=a.useState(()=>F?.draft??!1),[J,U]=a.useState(()=>F?.additionalContext??""),[te,Z]=a.useState(()=>{const ae=typeof F?.targetBaseBranch=="string"?$r(F.targetBaseBranch):"";return ae||$r(n)}),[ue,Oe]=a.useState("squash"),[se,G]=a.useState(!1),[Ie,pe]=a.useState(!1),[V,Q]=a.useState(!1),[ne,oe]=a.useState(!1),[ce,ke]=a.useState(!1),[ye,he]=a.useState(!1),[Ee,Ue]=a.useState(null),[Me,X]=a.useState(""),[Ne,Ae]=a.useState(""),[Se,le]=a.useState(!1),[ee,ie]=a.useState(!1),[ve,K]=a.useState(()=>Ka(o,{selectedRemoteName:F?.selectedRemoteName,trackingBranch:r})),[de,_e]=a.useState(!1),{detectedUpstream:Pe,upstreamBranches:re}=Yw(t,u);a.useEffect(()=>{_e(!1)},[t]);const me=o.some(ae=>ae.name==="upstream"),$=!!(t&&e&&n&&(e!==n||(me||Pe!==null))),B=a.useMemo(()=>bi(t,e,ve?.name??null),[t,e,ve?.name]),xe=en(ae=>ae.entries[B]),be=xe?.isLoading??!1,Le=xe?.status??null,Ke=xe?.error??null,st=xe?.isInitialStatusResolved??!1,ut=a.useMemo(()=>{const ae=de?null:ve?.name?.trim()||null,qe=new Set;for(const Gt of i){const Et=Hw(Gt,ae);!Et||Et==="HEAD"||qe.add(Et)}if(de)for(const Gt of re)Gt&&Gt!=="HEAD"&&qe.add(Gt);const lt=$r(n);lt&&lt!=="HEAD"&&qe.add(lt);const gt=$r(te);return gt&&gt!=="HEAD"&&qe.add(gt),Array.from(qe).sort((Gt,Et)=>Gt.localeCompare(Et))},[n,i,ve?.name,te,re,de]);a.useEffect(()=>{if(o.length===0){ve&&K(null);return}(!ve||!o.some(ae=>ae.name===ve.name))&&K(Ka(o,{selectedRemoteName:F?.selectedRemoteName,trackingBranch:r}))},[F?.selectedRemoteName,o,ve,r]),a.useEffect(()=>{const ae=$r(n);if(!te&&ae){Z(ae);return}if(ut.length!==0&&!ut.includes(te)){const qe=ut.includes(ae)?ae:ut[0];qe&&Z(qe)}},[ut,n,te]);const[mt,pt]=a.useState(()=>F?.activeSegment??"overview"),[ht,xt]=a.useState(new Set),[wt,bt]=a.useState(new Set),Dt=a.useRef(new Set),qt=a.useRef(null),Ut=a.useRef(!1),We=a.useRef(new Set),yt=a.useRef([]);a.useEffect(()=>{Pe&&!me&&_e(!0)},[Pe,me]),a.useEffect(()=>{de&&Pe?.defaultBranch&&Z(Pe.defaultBranch)},[de,Pe?.defaultBranch]);const Qe=Le?.pr??null,Rt=Qe?mm(t,Qe.number):null,Ot=Ed(ae=>Rt?ae.entries[Rt]:void 0),kt=Ed(ae=>ae.ensure),Ft=Ot?.result??null,Ht=Ot?.isLoading??!1,Xt=a.useCallback(ae=>{pt(ae);const qe=Jo.get(P);qe&&Jo.set(P,{...qe,activeSegment:ae})},[P]);a.useEffect(()=>{!Qe||!u?.prContext||mt==="overview"||kt(u,t,Qe.number,{includeCheckDetails:mt==="checks",sourceRepo:Le?.repo??null})},[mt,t,kt,u,Qe,Le?.repo]);const rt=Le?.checks??null,je=(rt?.pending??0)>0,Fe=Ft?.checkRuns??null,Te=Ft?.fetchedAt;a.useEffect(()=>{if(!Fe||Fe.length===0)return;const ae=zw(Fe);_(B,qe=>{if(!qe?.pr||typeof Te=="number"&&typeof qe.fetchedAt=="number"&&Te<qe.fetchedAt)return qe;const lt=qe.checks;return lt&&lt.state===ae.state&&lt.total===ae.total&&lt.success===ae.success&&lt.failure===ae.failure&&lt.pending===ae.pending&&lt.inProgress===ae.inProgress&&lt.queued===ae.queued&&lt.startedAt===ae.startedAt?qe:{...qe,checks:ae,...typeof Te=="number"?{fetchedAt:Te}:{}}})},[Fe,Te,B,_]),a.useEffect(()=>{if(mt!=="checks"||!je||!Qe||!u?.prContext)return;const ae=window.setInterval(()=>{kt(u,t,Qe.number,{includeCheckDetails:!0,sourceRepo:Le?.repo??null,force:!0})},Vw);return()=>window.clearInterval(ae)},[mt,je,t,kt,u,Qe,Le?.repo]);const[it,ct]=a.useState(()=>Date.now());a.useEffect(()=>{if(!je)return;ct(Date.now());const ae=window.setInterval(()=>ct(Date.now()),3e4);return()=>window.clearInterval(ae)},[je]);const Kt=Qe?`${t}#${Qe.number}`:null,Lt=!!(Kt&&Ee===Kt);a.useEffect(()=>{if(!u?.prContext||!Qe||typeof Qe.body=="string"&&Qe.body.length>0)return;const ae=`${t}#${Qe.number}`;if(Dt.current.has(ae))return;Dt.current.add(ae),Ue(ae);let qe=!1;return kt(u,t,Qe.number,{sourceRepo:Le?.repo??null}).then(lt=>{if(qe)return;const gt=lt?.pr;gt&&_(B,Gt=>!Gt?.pr||Gt.pr.number!==Qe.number?Gt:{...Gt,pr:{...Gt.pr,body:gt.body||""}})}).catch(()=>{}).finally(()=>{qe||Ue(lt=>lt===ae?null:lt)}),()=>{qe=!0}},[t,kt,u,Qe,B,Le?.repo,_]),a.useEffect(()=>{if(!Qe){he(!1),X(""),Ae(""),qt.current=null;return}const ae=qt.current!==null&&qt.current!==Qe.number;ae&&he(!1),(!ye||ae)&&(X(Qe.title||""),Ae(Qe.body||"")),qt.current=Qe.number},[ye,Qe]);const ze=a.useCallback(ae=>{if(!ae)return"";const qe=Date.parse(ae);return Number.isFinite(qe)?Ul(qe,d,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):ae},[d]),Xe=a.useMemo(()=>{const ae=h?.user?.login;return typeof ae=="string"?ae.trim():""},[h]),tt=a.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)]",[]),at=a.useCallback(ae=>{const qe=Xe.toLowerCase(),lt=/(^|[^\w`])@([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,38}))/g;return ae.replace(lt,(gt,Gt,Et)=>{const St=`@${Et}`,xs=Et.toLowerCase();return`${Gt}[${St}](https://github.com/${xs}${qe&&xs===qe?"?oc-self-mention=1":""})`})},[Xe]),Ze=a.useMemo(()=>{const ae=(Ft?.issueComments??[]).map(gt=>({id:`issue-${gt.id}`,body:gt.body||"",authorName:gt.author?.name||gt.author?.login||l("gitView.pr.comments.unknownAuthor"),authorLogin:gt.author?.login||null,avatarUrl:gt.author?.avatarUrl||null,createdAt:gt.createdAt,context:l("gitView.pr.comments.generalContext"),path:null,line:null})),qe=(Ft?.reviewComments??[]).map(gt=>({id:`review-${gt.id}`,body:gt.body||"",authorName:gt.author?.name||gt.author?.login||l("gitView.pr.comments.unknownAuthor"),authorLogin:gt.author?.login||null,avatarUrl:gt.author?.avatarUrl||null,createdAt:gt.createdAt,context:l("gitView.pr.comments.reviewContext"),path:gt.path||null,line:gt.line??null})),lt=[...ae,...qe];return lt.sort((gt,Gt)=>{const Et=gt.createdAt?Date.parse(gt.createdAt):0,St=Gt.createdAt?Date.parse(Gt.createdAt):0,xs=Number.isFinite(Et)?Et:0,As=Number.isFinite(St)?St:0;return xs-As}),lt},[Ft,l]),Pt=a.useCallback(()=>{const ae=S??(g?"draft":null);return ae?{directory:t,sessionKey:ae}:(fe.error(l("gitView.pr.toast.noActiveSession"),{description:l("gitView.pr.toast.noActiveSessionDescription")}),null)},[S,t,g,l]),Tt=a.useCallback((ae,qe)=>{const lt=qe.authorLogin?`@${qe.authorLogin}`:qe.authorName,gt=qe.path?` · ${qe.path}${qe.line?`:${qe.line}`:""}`:"";ci.getState().addDraft(ae,{source:"pr-comment",fileLabel:`PR #${Qe?.number??""} ${lt}${gt}`,startLine:qe.line??0,endLine:qe.line??0,code:qe.body,language:"markdown",text:""})},[Qe?.number]),Jt=a.useCallback((ae,qe)=>{const lt=ae.status||"unknown",gt=ae.conclusion??void 0,Gt=gt?`${lt} / ${gt}`:lt,Et=ae.app?.name||ae.app?.slug;return s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:qe?.hideHeader?"flex items-start justify-end gap-3":"flex items-start justify-between gap-3",children:[qe?.hideHeader?null:s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:ae.name}),s.jsx("div",{className:"typography-micro text-muted-foreground truncate",children:Et?`${Et} · ${Gt}`:Gt})]}),ae.detailsUrl?s.jsx(He,{variant:"outline",size:"sm",asChild:!0,className:"flex-shrink-0",children:s.jsxs("a",{href:ae.detailsUrl,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),"Open"]})}):null]}),ae.output?.title?s.jsx("div",{className:"typography-micro text-foreground",children:ae.output.title}):null,ae.output?.summary?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words",children:ae.output.summary}):null,ae.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:ae.output.text}):null,Array.isArray(ae.annotations)&&ae.annotations.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsxs("div",{className:"typography-micro text-muted-foreground",children:["Failed annotations",ae.annotations.length>20?` (showing 20/${ae.annotations.length})`:""]}),s.jsx("div",{className:"space-y-1",children:ae.annotations.slice(0,20).map((St,xs)=>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:[St.title||St.level||"Issue",St.path?` · ${St.path}`:"",typeof St.startLine=="number"?`:${St.startLine}`:"",typeof St.endLine=="number"&&St.endLine!==St.startLine?`-${St.endLine}`:""]}),s.jsx("div",{className:"typography-micro text-foreground whitespace-pre-wrap break-words mt-1",children:St.message}),St.rawDetails?s.jsx("div",{className:"typography-micro text-muted-foreground whitespace-pre-wrap break-words mt-1",children:St.rawDetails}):null]},`${St.path||"file"}:${St.startLine||xs}:${xs}`))})]}):null,ae.job?.steps&&ae.job.steps.length>0?s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.checks.steps")}),s.jsx("div",{className:"space-y-1",children:ae.job.steps.map((St,xs)=>{const As=(St.conclusion||"").toLowerCase(),ss=As&&!["success","neutral","skipped"].includes(As),ks=`${ae.id??"run"}:${ae.job?.jobId??"job"}:${St.number??xs}:${St.name}`,Ls=ht.has(ks);return ss?s.jsxs(To,{open:Ls,children:[s.jsxs("button",{type:"button",onClick:()=>{xt(Bs=>{const Be=new Set(Bs);return Be.has(ks)?Be.delete(ks):Be.add(ks),Be})},className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-left "+(ss?"bg-destructive/10 text-destructive":"text-muted-foreground"),children:[Ls?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:St.name}),St.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:St.conclusion}):null]}),s.jsx(Eo,{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 St.number=="number"?s.jsxs("div",{children:[l("gitView.pr.checks.stepLabel"),": ",St.number]}):null,St.status?s.jsxs("div",{children:[l("gitView.pr.checks.statusLabel"),": ",St.status]}):null,St.conclusion?s.jsxs("div",{children:[l("gitView.pr.checks.conclusionLabel"),": ",St.conclusion]}):null,St.startedAt?s.jsxs("div",{children:[l("gitView.pr.checks.startedLabel"),": ",ze(St.startedAt)]}):null,St.completedAt?s.jsxs("div",{children:[l("gitView.pr.checks.completedLabel"),": ",ze(St.completedAt)]}):null]})})]},ks):s.jsxs("div",{className:"typography-micro flex w-full items-center gap-2 rounded px-2 py-1 text-muted-foreground",children:[s.jsx("span",{className:"truncate",children:St.name}),St.conclusion?s.jsx("span",{className:"ml-auto flex-shrink-0",children:St.conclusion}):null]},ks)})})]}):null]})},[ht,ze,l]),[ls,cs]=a.useState(!1),[Bt,_t]=a.useState(!1),Mt=a.useCallback(async()=>{if(!u?.prContext){fe.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!Qe)return;const ae=Pt();if(ae){cs(!0);try{const qe=await kt(u,t,Qe.number,{includeCheckDetails:!0,sourceRepo:Le?.repo??null});if(!qe){fe.error(l("gitView.pr.toast.loadChecksFailed"));return}const gt=(qe.checkRuns??[]).filter(Et=>Ha(Et.conclusion));if(gt.length===0){fe.message(l("gitView.pr.toast.noFailedChecks"));return}const Gt=ci.getState();for(const Et of gt){const St=(Et.annotations??[]).map(ss=>[[ss.level,ss.title].filter(Boolean).join(" "),ss.path?`${ss.path}${typeof ss.startLine=="number"?`:${ss.startLine}`:""}`:null,ss.message,ss.rawDetails].filter(Boolean).join(`
51
- `)),xs=(Et.job?.steps??[]).filter(ss=>Ha(ss.conclusion)).map(ss=>`step ${ss.number??"?"}: ${ss.name} → ${ss.conclusion}`),As=[`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:
52
- ${Et.output.summary}`:null,xs.length>0?`failed steps:
53
- ${xs.join(`
54
- `)}`:null,St.length>0?`annotations:
55
- ${St.join(`
56
- ---
57
- `)}`:null].filter(Boolean).join(`
58
-
59
- `);Gt.addDraft(ae,{source:"pr-check",fileLabel:`PR #${Qe.number} · ${Et.name}`,startLine:0,endLine:0,code:As,language:"text",text:""})}b("chat")}catch(qe){const lt=qe instanceof Error?qe.message:String(qe);fe.error(l("gitView.pr.toast.loadChecksFailed"),{description:lt})}finally{cs(!1)}}},[t,kt,u,Qe,Pt,b,Le?.repo,l]),ps=a.useCallback(async()=>{if(!u?.prContext){fe.error(l("gitView.pr.toast.githubApiUnavailable"));return}if(!t||!Qe)return;const ae=Pt();if(ae){_t(!0);try{if(!await kt(u,t,Qe.number,{sourceRepo:Le?.repo??null})){fe.error(l("gitView.pr.toast.loadPrCommentsFailed"));return}if(Ze.length===0){fe.message(l("gitView.pr.toast.noPrComments"));return}for(const lt of Ze)Tt(ae,lt);b("chat")}catch(qe){const lt=qe instanceof Error?qe.message:String(qe);fe.error(l("gitView.pr.toast.loadPrCommentsFailed"),{description:lt})}finally{_t(!1)}}},[Tt,t,kt,u,Qe,Pt,b,Le?.repo,l,Ze]),_s=a.useCallback(async ae=>{const qe=Pt();qe&&(Tt(qe,ae),b("chat"))},[Tt,Pt,b]),Wt=a.useCallback(async ae=>{await L(B,ae)},[B,L]),Fs=a.useCallback(()=>{yt.current.forEach(ae=>{window.clearTimeout(ae)}),yt.current=Uw.map(ae=>window.setTimeout(()=>{Wt({force:!0,silent:!0,markInitialResolved:!0})},ae))},[Wt]);a.useEffect(()=>{if(!u?.prStatus||!$||o.length<=1||Ut.current||Le?.pr)return;const ae=`${P}::${ve?.name??""}`;if(We.current.has(ae))return;We.current.add(ae);const qe=qw(o,r).filter(Gt=>Gt.name!==ve?.name);if(qe.length===0)return;let lt=!1;return(async()=>{for(const Gt of qe){if(lt)return;try{if(!(await u.prStatus(t,e,Gt.name))?.pr)continue;if(lt)return;K(St=>St?.name===Gt.name?St:Gt);return}catch{}}})(),()=>{lt=!0}},[e,$,t,u,o,ve?.name,P,Le?.pr,r]),a.useEffect(()=>{k(B),E(B,{directory:t,branch:e,remoteName:ve?.name??null,canShow:$,github:u,githubAuthChecked:f,githubConnected:h?.connected??null})},[e,$,t,k,u,f,h?.connected,B,ve?.name,E]),a.useEffect(()=>(O(B),()=>{M(B)}),[B,O,M]),a.useEffect(()=>{const ae=Jo.get(P)??null;A(ae?.title??Od(e)),z(ae?.body??""),W(ae?.draft??!1),Z(ae?.targetBaseBranch?$r(ae.targetBaseBranch):$r(n));const qe=Ka(o,{selectedRemoteName:ae?.selectedRemoteName,trackingBranch:r});K(lt=>lt?.name===qe?.name?lt:qe)},[n,e,o,P,r]),a.useEffect(()=>{Wt({markInitialResolved:!0})},[B,Wt]),a.useEffect(()=>{!$||!ve?.name||Wt({force:!0,silent:!0,markInitialResolved:!0})},[$,Wt,ve?.name]),a.useEffect(()=>{const ae=Le?.resolvedRemoteName?.trim();if(!ae||Ut.current)return;const qe=o.find(lt=>lt.name===ae);qe&&K(lt=>lt?.name===qe.name?lt:qe)},[o,Le?.resolvedRemoteName]),a.useEffect(()=>{const ae=Le?.pr?.state==="closed"||Le?.pr?.state==="merged",qe=xe?.lastRefreshAt??0,lt=Date.now()-qe>6e4,gt=!ae&&lt,Gt=()=>{gt&&Wt({force:!0,silent:!0})},Et=()=>{document.visibilityState==="visible"&&gt&&Wt({force:!0,silent:!0})};return window.addEventListener("focus",Gt),document.addEventListener("visibilitychange",Et),()=>{window.removeEventListener("focus",Gt),document.removeEventListener("visibilitychange",Et)}},[Wt,Le?.pr?.state,xe?.lastRefreshAt]),a.useEffect(()=>{f&&h?.connected===!1&&Wt({force:!0,silent:!0,markInitialResolved:!0})},[f,h,Wt]),a.useEffect(()=>{!t||!e||Jo.set(P,{title:D,body:T,draft:R,additionalContext:J,targetBaseBranch:te,selectedRemoteName:ve?.name,activeSegment:mt})},[P,D,T,R,J,te,ve?.name,t,e,mt]),a.useEffect(()=>{const ae=yt.current;return()=>{ae.forEach(qe=>{window.clearTimeout(qe)}),yt.current=[]}},[]);const cn=a.useCallback(async()=>{if(!se&&t){G(!0);try{const qe={base:de&&Pe?.defaultBranchSha?Pe.defaultBranchSha:te,head:e};J&&(qe.context=J);const lt=await Dp(t,qe);lt.title?.trim()&&A(lt.title.trim()),lt.body?.trim()&&z(lt.body.trim()),c?.()}catch(ae){const qe=ae instanceof Error?ae.message:String(ae);fe.error(l("gitView.pr.toast.generateDescriptionFailed"),{description:qe})}finally{G(!1)}}},[J,e,Pe?.defaultBranchSha,t,se,c,te,l,de]),Gs=a.useCallback(async()=>{if(!u?.prCreate){fe.error(l("gitView.pr.toast.githubApiUnavailable"));return}const ae=D.trim();if(!ae){fe.error(l("gitView.pr.toast.titleRequired"));return}const qe=te.trim();if(!qe){fe.error(l("gitView.pr.toast.baseBranchRequired"));return}if(!de&&qe===e){fe.error(l("gitView.pr.toast.baseMustDifferFromHead"));return}pe(!0);try{const lt=lc(r),gt=de&&Pe,Gt=await u.prCreate({directory:t,title:ae,head:e,base:qe,...T.trim()?{body:T}:{},draft:R,...gt?{targetRepo:{owner:Pe.owner,repo:Pe.repo},headRemote:"origin"}:{...ve?{remote:ve.name}:{},...lt&&lt!==ve?.name?{headRemote:lt}:{}}});fe.success(l("gitView.pr.toast.prCreated")),_(B,Et=>Et&&{...Et,pr:Gt}),await Wt({force:!0}),Fs()}catch(lt){const gt=lt instanceof Error?lt.message:String(lt);fe.error(l("gitView.pr.toast.createPrFailed"),{description:gt})}finally{pe(!1)}},[T,e,Pe,t,R,u,B,Wt,Fs,ve,te,D,r,_,de,l]),as=a.useCallback(async ae=>{if(!u?.prMerge){fe.error(l("gitView.pr.toast.githubApiUnavailable"));return}oe(!0);try{const qe=await u.prMerge({directory:t,number:ae.number,method:ue});qe.merged?fe.success(l("gitView.pr.toast.prMerged")):fe.message(l("gitView.pr.toast.prNotMerged"),{description:qe.message||l("gitView.pr.notMergeable")}),await Wt({force:!0}),Fs()}catch(qe){const lt=qe instanceof Error?qe.message:String(qe);fe.error(l("gitView.pr.toast.mergeFailed"),{description:lt}),ae.url&&Ga(ae.url)}finally{oe(!1)}},[t,u,ue,Wt,Fs,l]),Xs=a.useCallback(async ae=>{if(!u?.prReady){fe.error(l("gitView.pr.toast.githubApiUnavailable"));return}ke(!0);try{await u.prReady({directory:t,number:ae.number}),fe.success(l("gitView.pr.toast.markedReady")),await Wt({force:!0}),Fs()}catch(qe){const lt=qe instanceof Error?qe.message:String(qe);fe.error(l("gitView.pr.toast.markReadyFailed"),{description:lt}),ae.url&&Ga(ae.url)}finally{ke(!1)}},[t,u,Wt,Fs,l]),Gn=a.useCallback(async ae=>{if(!u?.prUpdate){fe.error(l("gitView.pr.toast.githubApiUnavailable"));return}const qe=Me.trim();if(!qe){fe.error(l("gitView.pr.toast.titleRequired"));return}Q(!0);try{const lt=await u.prUpdate({directory:t,number:ae.number,title:qe,body:Ne});_(B,gt=>gt&&{...gt,pr:{...gt.pr??ae,...lt}}),he(!1),fe.success(l("gitView.pr.toast.prUpdated")),await Wt({force:!0}),Fs()}catch(lt){const gt=lt instanceof Error?lt.message:String(lt);fe.error(l("gitView.pr.toast.updatePrFailed"),{description:gt})}finally{Q(!1)}},[t,Ne,Me,u,B,Wt,Fs,_,l]);if(!$)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:l("gitView.pullRequest.title")}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pullRequest.availableOnFeatureBranches")})]})});const qn=Le?.repo?.url||null,dn=de&&Pe?.url?Pe.url:qn,un=!!Le?.canMerge,yn=!!Le?.connected,Os=f&&Le?.connected===!1,zs=Ww(Le),nn=zs?`var(--pr-${zs})`:"var(--status-info)",zn=zs==="draft"?"git-pr-draft":zs==="merged"?"git-merge":zs==="closed"?"git-close-pull-request":"git-pull-request",rn=Qe?[`${Qe.state}${Qe.draft?" (draft)":""}`,Qe.mergeable===!1?l("gitView.pr.notMergeable"):null,Qe.state==="open"&&typeof Qe.mergeableState=="string"&&Qe.mergeableState&&Qe.mergeableState!=="unknown"?Qe.mergeableState:null].filter(Boolean).join(" · "):"",pr=rt?rt.total>0?`${rt.success}/${rt.total} ${l("gitView.pr.checks.label")}`:`${rt.state} ${l("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:[Qe?s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md border border-border/60 bg-background/70 hover:bg-interactive-hover/60",onClick:()=>{Ga(Qe.url)},"aria-label":l("gitView.pr.actions.openOnGitHubAria"),children:s.jsx(I,{name:zn,className:"size-4 shrink-0",style:{color:nn}})})}),s.jsx(At,{children:s.jsx("p",{children:l("gitView.pr.actions.openOnGitHub")})})]}):s.jsx(I,{name:zn,className:"size-4 shrink-0",style:{color:"var(--surface-muted-foreground)"}}),s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground truncate",children:l("gitView.pullRequest.title")}),Qe?s.jsxs("span",{className:"typography-meta text-muted-foreground truncate",children:["#",Qe.number]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[be?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin text-muted-foreground"}):null,s.jsxs(Nt,{children:[s.jsx(Ct,{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:be,onClick:()=>{Wt({force:!0})},"aria-label":l("gitView.pr.actions.refreshAria"),children:s.jsx(I,{name:"refresh",className:"size-3.5 text-muted-foreground"})})}),s.jsx(At,{children:s.jsx("p",{children:l("gitView.pr.actions.refresh")})})]})]})]}),Qe?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:nn},children:rn}),rt?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s.jsx("span",{className:`h-2 w-2 rounded-full ${Fd(rt.state)}`}),pr]}):null,r&&ve&&r.split("/")[0]!==ve.name?s.jsxs("span",{className:"min-w-0 truncate",children:[r.split("/")[0]," → ",ve.name]}):null]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[N?s.jsxs(He,{variant:"outline",size:"sm",className:De("pr-actions__walkthrough-button h-7 shrink-0 gap-1.5 px-2",oc),onClick:()=>{w(t,{kind:"pr",number:Qe.number}),j(t,"walkthrough")},"aria-label":l("walkthrough.action.open"),children:[s.jsx(I,{name:"route",className:"size-4"}),s.jsx("span",{className:"pr-actions__walkthrough-label typography-ui-label",children:l("walkthrough.action.open")})]}):null,un&&Qe.draft&&Qe.state==="open"?s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(He,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>Xs(Qe),disabled:ce||ne||V||ye,"aria-label":l("gitView.pr.actions.markReadyAria"),children:ce?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"checkbox-circle",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:l("gitView.pr.actions.markReady")})})]}):null,un?s.jsxs(s.Fragment,{children:[s.jsxs(gn,{value:ue,onValueChange:ae=>Oe(ae),disabled:ne||Qe.state!=="open",children:[s.jsx(xn,{size:"sm",className:"h-7 w-auto min-w-0",children:s.jsx(sn,{})}),s.jsxs(bn,{children:[s.jsx(bs,{value:"squash",children:l("gitView.pr.mergeMethod.squash")}),s.jsx(bs,{value:"merge",children:l("gitView.pr.mergeMethod.merge")}),s.jsx(bs,{value:"rebase",children:l("gitView.pr.mergeMethod.rebase")})]})]}),s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(He,{size:"sm",className:"h-7 w-7 px-0",onClick:()=>as(Qe),disabled:ne||ce||Qe.state!=="open"||Qe.draft||V||ye,"aria-label":l("gitView.pr.actions.mergePrAria"),children:ne?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"git-merge",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:l("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:l("gitView.pr.githubNotConnected")}),s.jsx(He,{variant:"outline",size:"sm",onClick:v,className:"w-fit",children:l("gitView.pr.actions.openSettings")})]}):null,Ke?s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:l("gitView.pr.statusUnavailable")}),s.jsx("div",{className:"typography-meta text-muted-foreground break-words",children:Ke}),dn?s.jsx(He,{variant:"outline",size:"sm",asChild:!0,className:"w-fit",children:s.jsxs("a",{href:dn,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),"Open Repo"]})}):null]}):null,!Qe&&!st&&!Ke&&!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"}),l("gitView.pr.checkingStatus")]}):Qe?s.jsxs("div",{className:"flex flex-col gap-3",children:[s.jsx("div",{className:"h-8 min-w-0",children:s.jsx(ui,{className:"h-full",items:[{id:"overview",label:l("gitView.pr.segment.overview")},{id:"checks",label:rt&&rt.total>0?`${l("gitView.pr.segment.checks")} ${rt.success}/${rt.total}`:l("gitView.pr.segment.checks"),icon:rt?s.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${Fd(rt.state)}`}):void 0},{id:"comments",label:Ft?`${l("gitView.pr.segment.comments")} ${(Ft.issueComments?.length??0)+(Ft.reviewComments?.length??0)}`:l("gitView.pr.segment.comments")}],activeId:mt,onSelect:ae=>Xt(ae),layoutMode:"fit",variant:"active-pill",activePillButtonClassName:"h-7"})}),mt==="overview"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[un&&Qe.draft?s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.draftMustBeReady")}):null,un?null:s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("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:ye?s.jsx(or,{value:Me,onChange:ae=>X(ae.target.value),placeholder:l("gitView.pr.placeholder.title"),autoCorrect:y?"on":"off",autoCapitalize:y?"sentences":"off",spellCheck:y}):s.jsx("div",{className:"typography-markdown text-xl font-semibold text-foreground break-words leading-snug",children:Qe.title})}),Qe.state==="open"?s.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:ye?s.jsxs(s.Fragment,{children:[s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(He,{variant:"outline",size:"sm",className:"h-9 w-9 px-0",onClick:()=>{he(!1),X(Qe.title||""),Ae(Qe.body||"")},disabled:V,"aria-label":l("gitView.pr.actions.cancelEditingAria"),children:s.jsx(I,{name:"close",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:l("gitView.pr.actions.cancelEditing")})})]}),s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(He,{size:"sm",className:"h-9 w-9 px-0",onClick:()=>Gn(Qe),disabled:V||!Me.trim(),"aria-label":l("gitView.pr.actions.savePrAria"),children:V?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"check",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:l("gitView.pr.actions.savePr")})})]})]}):s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(He,{variant:"outline",size:"sm",className:"h-7 w-7 px-0",onClick:()=>he(!0),"aria-label":l("gitView.pr.actions.editPrAria"),children:s.jsx(I,{name:"edit",className:"size-4"})})}),s.jsx(At,{children:s.jsx("p",{children:l("gitView.pr.actions.editPr")})})]})}):null]}),ye?s.jsx(wo,{value:Ne,onChange:ae=>Ae(ae.target.value),outerClassName:"min-h-[60vh]",placeholder:l("gitView.pr.placeholder.description"),autoCorrect:y?"on":"off",autoCapitalize:y?"sentences":"off",spellCheck:y}):null,ye?null:Qe.body?.trim()?s.jsx(Rc,{content:Qe.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:l(Lt?"gitView.pr.loadingDescription":"gitView.pr.noDescription")})]}):null,mt==="checks"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[rt&&rt.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:[rt.success>0?s.jsx("div",{className:"bg-[color:var(--status-success)]",style:{width:`${rt.success/rt.total*100}%`}}):null,rt.failure>0?s.jsx("div",{className:"bg-[color:var(--status-error)]",style:{width:`${rt.failure/rt.total*100}%`}}):null,rt.pending>0?s.jsx("div",{className:"bg-[color:var(--status-warning)]",style:{width:`${rt.pending/rt.total*100}%`}}):null]}),s.jsxs("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:[rt.success,"/",rt.total," ",l("gitView.pr.checks.label")]}),(rt.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"}),Ua(rt.startedAt,void 0,it)]}):null]}):null,rt?.failure?s.jsxs(He,{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:Mt,disabled:ls,"aria-label":l("gitView.pr.actions.resolveFailedChecksAria"),children:[ls?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"ai-generate-2",className:"size-4"}),l("gitView.pr.actions.resolveFailedChecks")]}):null,(Ft?.checkRuns?.length??0)>0?s.jsx("div",{className:"flex flex-col gap-1.5",children:(Ft?.checkRuns??[]).map((ae,qe)=>{const lt=`${ae.id??"run"}:${ae.name}:${qe}`,gt=ae.status==="in_progress",Gt=ae.status==="queued",Et=Ha(ae.conclusion),St=wt.has(lt),xs=!!(ae.output?.title||ae.output?.summary||ae.output?.text||(ae.annotations?.length??0)>0||(ae.job?.steps?.length??0)>0||ae.detailsUrl),As=ae.job?.workflowName,ss=gt?Ua(ae.startedAt,void 0,it):Ua(ae.startedAt,ae.completedAt);return s.jsxs("div",{className:De("rounded-md border border-border/40",Et&&"border-[var(--status-error-border)]"),children:[s.jsxs("button",{type:"button",disabled:!xs,onClick:()=>{bt(ks=>{const Ls=new Set(ks);return Ls.has(lt)?Ls.delete(lt):Ls.add(lt),Ls})},className:"flex w-full items-center gap-2 px-2.5 py-2 text-left disabled:cursor-default",children:[gt?s.jsx(I,{name:"loader-4",className:"size-4 shrink-0 animate-spin text-[var(--status-warning)]"}):Gt?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:As&&As!==ae.name?`${As} / ${ae.name}`:ae.name}),ss?s.jsx("span",{className:"shrink-0 typography-micro tabular-nums text-muted-foreground",children:ss}):null,xs?s.jsx(I,{name:"arrow-down-s",className:De("size-4 shrink-0 text-muted-foreground transition-transform",St&&"rotate-180")}):null]}),St&&xs?s.jsx("div",{className:"min-w-0 overflow-hidden border-t border-border/40 p-2.5",children:Jt(ae,{hideHeader:!0})}):null]},lt)})}):Ht?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"}),l("gitView.loading.loading")]}):s.jsx("div",{className:"py-6 text-center typography-micro text-muted-foreground",children:l("gitView.pr.checkDetails.empty")})]}):null,mt==="comments"?s.jsxs("div",{className:"flex min-w-0 flex-col gap-2",children:[Ze.length>0?s.jsx("div",{className:"flex items-center justify-end",children:s.jsxs(He,{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:ps,disabled:Bt,"aria-label":l("gitView.pr.actions.shareCommentsAria"),children:[Bt?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(I,{name:"ai-generate-2",className:"size-3.5"}),l("gitView.pr.comments.addAll")]})}):null,Ze.length>0?s.jsx("div",{className:"relative pl-3",children:s.jsx("div",{children:Ze.map((ae,qe)=>{const lt=(ae.authorName||"?").charAt(0).toUpperCase(),gt=qe===Ze.length-1;return s.jsxs("div",{className:"relative pl-10 pb-5 last:pb-0",children:[gt?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:ae.avatarUrl?s.jsx("img",{src:ae.avatarUrl,alt:ae.authorName,className:"h-full w-full object-cover"}):s.jsx("span",{children:lt})}),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:[ae.authorName,ae.authorLogin&&ae.authorLogin!==ae.authorName?` · @${ae.authorLogin}`:""]}),ae.createdAt?s.jsx("span",{className:"whitespace-nowrap",children:ze(ae.createdAt)}):null,s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs(He,{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:()=>{_s(ae)},"aria-label":l("gitView.pr.actions.sendCommentToAgentAria"),children:[s.jsx(I,{name:"ai-generate-2",className:"size-3.5"}),l("gitView.pr.actions.sendToAgent")]})}),s.jsx(At,{children:s.jsx("p",{children:l("gitView.pr.actions.sendCommentToAgent")})})]})]}),s.jsxs("div",{className:"typography-micro text-muted-foreground",children:[ae.context,ae.path?` · ${ae.path}`:"",ae.line?`:${ae.line}`:""]}),s.jsx(Rc,{content:at(ae.body),className:["typography-markdown-body text-foreground break-words [&_a]:no-underline [&_a:hover]:no-underline",tt].filter(Boolean).join(" "),enableFileReferences:!1})]})]},ae.id)})})}):Ht&&!Ft?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"}),l("gitView.loading.loading")]}):s.jsx("div",{className:"py-6 text-center typography-micro text-muted-foreground",children:l("gitView.pr.comments.empty")})]}):null]}):s.jsxs("div",{className:"flex flex-col gap-3",children:[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:l("gitView.pr.createTitle")}),s.jsxs("div",{className:"typography-micro text-muted-foreground truncate",children:[e," ",s.jsx("span",{className:"opacity-60",children:"(local)"})," → ",te," ",s.jsxs("span",{className:"opacity-60",children:["(",de&&Pe?"upstream":"remote",")"]})]})]}),dn?s.jsx(He,{variant:"outline",size:"sm",asChild:!0,children:s.jsxs("a",{href:dn,target:"_blank",rel:"noopener noreferrer",children:[s.jsx(I,{name:"external-link",className:"size-4"}),l("gitView.pr.actions.repo")]})}):null]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.field.title")}),s.jsx(or,{value:D,onChange:ae=>A(ae.target.value),placeholder:l("gitView.pr.placeholder.title"),autoCorrect:y?"on":"off",autoCapitalize:y?"sentences":"off",spellCheck:y})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.field.baseBranch")}),ut.length>0?s.jsxs(gn,{value:te,onValueChange:Z,children:[s.jsx(xn,{size:"lg",children:s.jsx(sn,{placeholder:l("gitView.pr.placeholder.selectBaseBranch")})}),s.jsx(bn,{children:ut.map(ae=>s.jsx(bs,{value:ae,children:ae},ae))})]}):s.jsx(or,{value:te,onChange:ae=>Z(ae.target.value),placeholder:l("gitView.pr.placeholder.main")})]}),s.jsxs("label",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.field.description")}),s.jsx(wo,{value:T,onChange:ae=>z(ae.target.value),className:"min-h-[110px]",placeholder:l("gitView.pr.placeholder.whatChanged"),autoCorrect:y?"on":"off",autoCapitalize:y?"sentences":"off",spellCheck:y})]}),s.jsxs("div",{className:"flex items-center gap-2 cursor-pointer",role:"button",tabIndex:0,"aria-pressed":R,onClick:()=>W(ae=>!ae),onKeyDown:ae=>{(ae.key===" "||ae.key==="Enter")&&(ae.preventDefault(),W(qe=>!qe))},children:[s.jsx(ao,{size:"sm",checked:R,onChange:ae=>W(ae),ariaLabel:l("gitView.pr.actions.toggleDraftAria")}),s.jsx("span",{className:"typography-ui-label text-foreground select-none",children:l("gitView.pr.field.draft")})]}),m?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:l("gitView.pr.additionalContext.optional")}),s.jsx(He,{variant:"outline",size:"sm",onClick:()=>ie(!0),children:J.trim()?l("gitView.pr.actions.edit"):l("gitView.pr.actions.add")})]}),J.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:l("gitView.pr.additionalContext.added")})})]}):s.jsxs(To,{open:Se,onOpenChange:le,children:[s.jsxs(xi,{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:l("gitView.pr.additionalContext.optional")}),s.jsx("span",{className:"typography-micro text-[var(--primary-base)]",children:Se?l("gitView.pr.actions.hide"):J.trim()?l("gitView.pr.actions.edit"):l("gitView.pr.actions.add")})]}),s.jsx(Eo,{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(wo,{value:J,onChange:ae=>U(ae.target.value),className:"min-h-[100px] bg-transparent",placeholder:l("gitView.pr.placeholder.additionalContext")}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.hint")})]})})]}),s.jsx(ka,{open:ee,onClose:()=>ie(!1),title:l("gitView.pr.additionalContext.title"),footer:s.jsx(He,{size:"sm",onClick:()=>ie(!1),className:"w-full",children:l("gitView.common.done")}),children:s.jsxs("div",{className:"space-y-3",children:[s.jsx(wo,{value:J,onChange:ae=>U(ae.target.value),className:"min-h-[200px] bg-transparent",placeholder:l("gitView.pr.placeholder.additionalContext"),autoFocus:!0}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:l("gitView.pr.additionalContext.hint")})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs(He,{variant:"outline",size:"sm",onClick:cn,disabled:se||Ie,children:[se?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(I,{name:"ai-generate-2",className:"size-4 text-primary"}),l("gitView.commit.generate")]}),s.jsx("div",{className:"flex-1"}),s.jsxs(He,{size:"sm",className:"min-w-[7.5rem] justify-center gap-2",onClick:Gs,disabled:Ie||!yn||!te.trim()||!de&&te.trim()===e,children:[s.jsx("span",{className:"inline-flex size-4 items-center justify-center",children:Ie?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:l("gitView.pr.actions.createPr")})]})]})]})]})]})},qa=t=>(t||"").replace(/\\/g,"/").replace(/\/+$/,""),Ai=new Map,Di=new Map,Br=t=>`${$n()}::${t}`,Xw=()=>{const t=nt.c(80),{t:e}=ft(),{git:n}=_n(),r=Wr(),o=Bo(r??null),i=ja(r??null),{ensureAll:c}=tn(nr(Jw)),l=et(Zw),d=et(ev),u=et(tv),h=et(sv);let f;t[0]!==r?(f=qa(r),t[0]=r,t[1]=f):f=t[1];const p=f;let x;if(t[2]!==h||t[3]!==p||t[4]!==u){e:{if(!p){x=void 0;break e}let oe;if(t[6]!==h||t[7]!==p){let ke;t[9]!==p?(ke=ye=>qa(ye.path)===p,t[9]=p,t[10]=ke):ke=t[10],oe=h.find(ke),t[6]=h,t[7]=p,t[8]=oe}else oe=t[8];const ce=oe;if(ce){x=ce;break e}for(const ke of u.values())if(qa(ke.path)===p){x=ke;break e}x=void 0}t[2]=h,t[3]=p,t[4]=u,t[5]=x}else x=t[5];const b=x;let S;t[11]!==l||t[12]!==b||t[13]!==d?.open||t[14]!==u?(S=()=>{if(l)return u.get(l)??b;if(d?.open)return b},t[11]=l,t[12]=b,t[13]=d?.open,t[14]=u,t[15]=S):S=t[15],d?.open;let g;t[16]!==S?(g=S(),t[16]=S,t[17]=g):g=t[17];const m=g;let y;t[18]!==l?(y=oe=>l?oe.getAttachment(l):void 0,t[18]=l,t[19]=y):y=t[19];const C=Bl(y),j=C&&!C.degraded&&!C.legacy?C.worktreeRoot??void 0:void 0,w=fm(r,m,o?.current??void 0);let N,v;t[20]!==r||t[21]!==c||t[22]!==n?(N=()=>{!r||!n||c(r,n)},v=[r,c,n],t[20]=r,t[21]=c,t[22]=n,t[23]=N,t[24]=v):(N=t[23],v=t[24]),a.useEffect(N,v);const[P,F]=a.useState(null);let k;t[25]!==j||t[26]!==w?.projectDirectory?(k=()=>{const oe=j||w?.projectDirectory;if(!oe){F(null);return}let ce=!1;return pi(oe).then(ke=>{if(ce)return;const ye=ke.trim();F(ye&&ye!=="HEAD"?ye:null)}).catch(()=>{ce||F(null)}),()=>{ce=!0}},t[25]=j,t[26]=w?.projectDirectory,t[27]=k):k=t[27];const E=w?.projectDirectory;let O;t[28]!==j||t[29]!==E?(O=[j,E],t[28]=j,t[29]=E,t[30]=O):O=t[30],a.useEffect(k,O);let M;t[31]!==r?(M=()=>(r?Ai.get(Br(r)):void 0)??[],t[31]=r,t[32]=M):M=t[32];const[L,_]=a.useState(M);let D;t[33]!==r?(D=()=>(r?Di.get(Br(r)):void 0)??null,t[33]=r,t[34]=D):D=t[34];const[A,T]=a.useState(D);let z,R;t[35]!==r||t[36]!==n?(z=()=>{if(!r||!n?.getRemotes){_([]);return}_(Ai.get(Br(r))??[]);let oe=!1;return n.getRemotes(r).then(ce=>{oe||(Ai.set(Br(r),ce??[]),_(ce??[]))}).catch(()=>{oe||_(Ai.get(Br(r))??[])}),()=>{oe=!0}},R=[r,n],t[35]=r,t[36]=n,t[37]=z,t[38]=R):(z=t[37],R=t[38]),a.useEffect(z,R);let W,J;t[39]!==r||t[40]!==n?(W=()=>{if(!r||!n?.getRemoteUrl){T(null);return}T(Di.get(Br(r))??null);let oe=!1;return n.getRemoteUrl(r).then(ce=>{oe||(Di.set(Br(r),ce),T(ce))}).catch(()=>{oe||T(Di.get(Br(r))??null)}),()=>{oe=!0}},J=[r,n],t[39]=r,t[40]=n,t[41]=W,t[42]=J):(W=t[41],J=t[42]),a.useEffect(W,J);let U;e:{if(!i?.all){let ce;t[43]===Symbol.for("react.memo_cache_sentinel")?(ce=[],t[43]=ce):ce=t[43],U=ce;break e}let oe;t[44]!==i.all?(oe=i.all.filter(nv).sort(),t[44]=i.all,t[45]=oe):oe=t[45],U=oe}const te=U;let Z;e:{if(!i?.all){let ce;t[46]===Symbol.for("react.memo_cache_sentinel")?(ce=[],t[46]=ce):ce=t[46],Z=ce;break e}let oe;t[47]!==i.all?(oe=i.all.filter(rv).map(ov).sort(),t[47]=i.all,t[48]=oe):oe=t[48],Z=oe}const ue=Z;let Oe;t[49]!==ue||t[50]!==A||t[51]!==L||t[52]!==o?.tracking?(Oe=()=>{if(L.length>0)return L;const oe=new Set,ce=o?.tracking?.trim();ce&&ce.includes("/")&&oe.add(ce.split("/")[0]);for(const ke of ue){const ye=ke.indexOf("/");ye>0&&oe.add(ke.slice(0,ye))}return oe.size===0&&A&&oe.add("origin"),Array.from(oe).map(ke=>({name:ke,fetchUrl:A??"",pushUrl:A??""}))},t[49]=ue,t[50]=A,t[51]=L,t[52]=o?.tracking,t[53]=Oe):Oe=t[53],o?.tracking;let se;t[54]!==Oe?(se=Oe(),t[54]=Oe,t[55]=se):se=t[55];const G=se;w?.createdFromBranch;let Ie;t[56]!==G||t[57]!==te||t[58]!==P||t[59]!==w?.createdFromBranch?(Ie=ac({remoteNames:new Set(G.map(iv)),localBranches:te,worktreeCreatedFromBranch:w?.createdFromBranch,rootBranchHint:P}),t[56]=G,t[57]=te,t[58]=P,t[59]=w?.createdFromBranch,t[60]=Ie):Ie=t[60];const pe=Ie,V=o?.current??null;if(!r||!V){let oe;t[61]===Symbol.for("react.memo_cache_sentinel")?(oe=s.jsx(I,{name:"git-pull-request",className:"h-12 w-12 text-muted-foreground/50"}),t[61]=oe):oe=t[61];let ce;t[62]!==e?(ce=e("gitView.pullRequest.title"),t[62]=e,t[63]=ce):ce=t[63];let ke;t[64]!==ce?(ke=s.jsx("div",{className:"typography-ui-header text-foreground",children:ce}),t[64]=ce,t[65]=ke):ke=t[65];let ye;t[66]!==e?(ye=e("gitView.pullRequest.createHint"),t[66]=e,t[67]=ye):ye=t[67];let he;t[68]!==ye?(he=s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:ye}),t[68]=ye,t[69]=he):he=t[69];let Ee;return t[70]!==ke||t[71]!==he?(Ee=s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[oe,ke,he]}),t[70]=ke,t[71]=he,t[72]=Ee):Ee=t[72],Ee}const Q=o?.tracking??void 0;let ne;return t[73]!==pe||t[74]!==V||t[75]!==r||t[76]!==ue||t[77]!==L||t[78]!==Q?(ne=s.jsx(On,{as:Sa,outerClassName:"h-full min-h-0",className:"px-4 py-3",disableHorizontal:!0,preventOverscroll:!0,children:s.jsx(Qw,{directory:r,branch:V,baseBranch:pe,trackingBranch:Q,remotes:L,remoteBranches:ue})}),t[73]=pe,t[74]=V,t[75]=r,t[76]=ue,t[77]=L,t[78]=Q,t[79]=ne):ne=t[79],ne};function Jw(t){return{ensureAll:t.ensureAll}}function Zw(t){return t.currentSessionId}function ev(t){return t.newSessionDraft}function tv(t){return t.worktreeMetadata}function sv(t){return t.availableWorktrees}function nv(t){return!t.startsWith("remotes/")}function rv(t){return t.startsWith("remotes/")}function ov(t){return t.replace(/^remotes\//,"")}function iv(t){return t.name}const av=t=>{if(!t?.walkthrough)return null;const e=new Map(t.hunks.map(i=>[i.id,i])),n=new Set,r=[],o=[];for(const[i,c]of t.walkthrough.chapters.entries()){const l=[];for(const d of c.stops){const u=[],h=[];for(const p of d.hunkIds){const x=e.get(p);x?(u.push(x),n.add(p)):h.push(p)}const f={stop:d,chapter:c,chapterIndex:i,position:r.length+1,hunks:u,missingHunkIds:h,isStale:h.length>0};r.push(f),l.push(f)}o.push({chapter:c,stops:l})}return{walkthrough:t.walkthrough,stops:r,chapters:o,uncoveredHunks:t.hunks.filter(i=>!n.has(i.id)),staleStopCount:r.filter(i=>i.isStale).length,isStale:r.some(i=>i.isStale)}},lv=t=>{const e=new Map;for(const n of t){const r=e.get(n.path);if(r){r.added+=n.added,r.deleted+=n.deleted;continue}e.set(n.path,{path:n.path,added:n.added,deleted:n.deleted})}return[...e.values()]},hm=t=>{const e=[];for(const n of t){const r=e.at(-1);if(r&&r.path===n.path){r.hunks.push(n);continue}e.push({path:n.path,hunks:[n]})}return e},cv=t=>{if(t.length===0)return"";if(t.length===1)return t[0].patch;const e=t[0].patch,n=e.indexOf(`
60
- @@`);if(n===-1)return e;const r=e.slice(0,n),o=t.map(i=>{const c=i.patch.indexOf(`
61
- @@`);return c===-1?"":i.patch.slice(c+1)});return`${r}
62
- ${o.join("")}`},dv=t=>t?`${t.providerID}/${t.modelID}`:"",uv=({reason:t,model:e,requiredChars:n,availableChars:r,onRetry:o})=>{const{t:i}=ft(),c=ts(m=>m.modelsMetadata),[l,d]=$e.useState(void 0),[u,h]=$e.useState(!1),f=t==="context-too-small"||t==="structured-output-unsupported"||t==="output-exhausted";$e.useEffect(()=>{if(!f||l!==void 0)return;let m=!1;return(async()=>{try{const y=await hs("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!y.ok)return;const C=await y.json().catch(()=>null);!m&&Array.isArray(C?.authenticatedProviders)&&d(C.authenticatedProviders.filter(j=>typeof j=="string"))}catch{}})(),()=>{m=!0}},[f,l]);const p=$e.useCallback(async(m,y)=>{if(!m||!y||u)return;const C=`${m}/${y}`;h(!0);try{await Fl({walkthroughModelOverride:C}),o()}catch(j){console.warn("Failed to save small model override:",j)}finally{h(!1)}},[o,u]),x=$e.useCallback((m,y)=>c.get(`${m}/${y}`)?.structured_output!==!1,[c]),b=dv(e),S=()=>{if(t==="no-model")return i("walkthrough.blocked.noModel.description");if(t==="empty-diff")return i("walkthrough.blocked.emptyDiff.description");if(t==="only-generated")return i("walkthrough.blocked.onlyGenerated.description");if(t==="output-exhausted")return b?i("walkthrough.blocked.outputExhausted.description",{model:b}):i("walkthrough.blocked.outputExhausted.descriptionUnknownModel");if(t==="structured-output-unsupported")return b?i("walkthrough.blocked.structuredOutput.description",{model:b}):i("walkthrough.blocked.structuredOutput.descriptionUnknownModel");const m=Math.ceil((n??0)/1e3),y=Math.ceil((r??0)/1e3);return b?i("walkthrough.blocked.contextTooSmall.description",{model:b,required:m,available:y}):i("walkthrough.blocked.contextTooSmall.descriptionUnknownModel",{required:m,available:y})},g=()=>i(t==="no-model"?"walkthrough.blocked.noModel.title":t==="empty-diff"?"walkthrough.blocked.emptyDiff.title":t==="only-generated"?"walkthrough.blocked.onlyGenerated.title":t==="output-exhausted"?"walkthrough.blocked.outputExhausted.title":t==="structured-output-unsupported"?"walkthrough.blocked.structuredOutput.title":"walkthrough.blocked.contextTooSmall.title");return s.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center",children:[s.jsx(I,{name:t==="empty-diff"||t==="only-generated"?"information":"error-warning",className:"size-6 text-muted-foreground"}),s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:g()}),s.jsx("p",{className:"typography-meta max-w-md text-muted-foreground",children:S()}),f&&s.jsxs("div",{className:"flex flex-col items-center gap-2 pt-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground",children:i("walkthrough.blocked.chooseModel")}),s.jsx(Hl,{providerId:e?.providerID??"",modelId:e?.modelID??"",onChange:(m,y)=>{p(m,y)},allowedProviderIds:l,isModelAllowed:x})]}),(t==="empty-diff"||t==="only-generated")&&s.jsx(He,{type:"button",variant:"outline",size:"sm",onClick:o,children:i("walkthrough.action.refresh")})]})},fv=[{labelKey:"walkthrough.stage.collecting"},{labelKey:"walkthrough.stage.asking"},{labelKey:"walkthrough.stage.assembling"}],mv=t=>{const e=nt.c(6),{progress:n}=t,{t:r}=ft(),{completedCount:o,activeIndex:i}=n;let c;e[0]!==i||e[1]!==o||e[2]!==r?(c=fv.map((d,u)=>{const h=u<o,f=i===u;return s.jsxs("li",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center",children:h?s.jsx(I,{name:"check",className:"size-3.5 text-status-success"}):f?s.jsx(I,{name:"loader-4",className:"size-3.5 animate-spin text-[var(--status-info)]"}):s.jsx("span",{className:"size-1.5 rounded-full bg-surface-muted"})}),s.jsx("span",{className:De("typography-meta",f?"text-foreground":h?"text-muted-foreground":"text-muted-foreground/60"),children:r(d.labelKey)})]},d.labelKey)}),e[0]=i,e[1]=o,e[2]=r,e[3]=c):c=e[3];let l;return e[4]!==c?(l=s.jsx("ul",{className:"flex flex-col gap-2 text-left",children:c}),e[4]=c,e[5]=l):l=e[5],l},vo=["collecting","asking","assembling"],Ya=450,hv=t=>t==="retrying"?vo.indexOf("asking"):t?vo.indexOf(t):-1,pv=(t,e)=>Math.min(t+1,e),gv=(t,e)=>{const n=nt.c(17),[r,o]=$e.useState(-1),i=$e.useRef(0);let c;n[0]!==e||n[1]!==r||n[2]!==t?(c=e?Math.max(hv(t),0):r<0?-1:vo.length,n[0]=e,n[1]=r,n[2]=t,n[3]=c):c=n[3];const l=c;let d,u;n[4]!==e||n[5]!==r||n[6]!==l?(d=()=>{if(l<=r){l<r&&e&&(o(l),i.current=Date.now());return}const m=Date.now()-i.current,y=()=>{i.current=Date.now(),o(j=>pv(j,l))};if(r<0||m>=Ya){y();return}const C=setTimeout(y,Ya-m);return()=>clearTimeout(C)},u=[e,r,l],n[4]=e,n[5]=r,n[6]=l,n[7]=d,n[8]=u):(d=n[7],u=n[8]),$e.useEffect(d,u);let h,f;n[9]!==e||n[10]!==r?(h=()=>{if(e||r<vo.length)return;const m=setTimeout(()=>o(-1),Ya);return()=>clearTimeout(m)},f=[e,r],n[9]=e,n[10]=r,n[11]=h,n[12]=f):(h=n[11],f=n[12]),$e.useEffect(h,f);const p=r>=vo.length,x=Math.max(0,Math.min(r,vo.length)),b=p||r<0?null:r,S=!e&&r>=0;let g;return n[13]!==x||n[14]!==b||n[15]!==S?(g={completedCount:x,activeIndex:b,holding:S},n[13]=x,n[14]=b,n[15]=S,n[16]=g):g=n[16],g},pm=$e.memo(function(e){const n=nt.c(11),{path:r,hunks:o,renderSideBySide:i,wrapLines:c}=e;let l;if(n[0]!==o||n[1]!==r){const f=cv(o);l=f?em(r,f):void 0,n[0]=o,n[1]=r,n[2]=l}else l=n[2];const d=l;if(!d)return null;let u;n[3]!==r?(u=zl(r)||"",n[3]=r,n[4]=u):u=n[4];let h;return n[5]!==d||n[6]!==r||n[7]!==i||n[8]!==u||n[9]!==c?(h=s.jsx(Zl,{original:"",modified:"",fileDiff:d,language:u,fileName:r,renderSideBySide:i,wrapLines:c,layout:"inline"}),n[5]=d,n[6]=r,n[7]=i,n[8]=u,n[9]=c,n[10]=h):h=n[10],h}),Qa=t=>`walkthrough-stop-${t}`,xv={critical:"bg-status-error/10 text-status-error",normal:"bg-surface-muted text-muted-foreground",context:"bg-surface-muted text-muted-foreground"},bv=t=>{const e=nt.c(22),{stopView:n}=t,{t:r}=ft(),{stop:o}=n;let i;e[0]!==n.position?(i=s.jsx("span",{className:"typography-micro flex h-5 min-w-5 shrink-0 items-center justify-center rounded-full bg-surface-muted px-1.5 tabular-nums text-muted-foreground",children:n.position}),e[0]=n.position,e[1]=i):i=e[1];let c;e[2]!==o.title?(c=s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:o.title}),e[2]=o.title,e[3]=c):c=e[3];let l;e[4]!==o.importance||e[5]!==r?(l=o.importance!=="normal"&&s.jsx("span",{className:De("typography-micro flex h-5 items-center rounded px-1.5 leading-none",xv[o.importance]),children:o.importance==="critical"?r("walkthrough.importance.critical"):r("walkthrough.importance.context")}),e[4]=o.importance,e[5]=r,e[6]=l):l=e[6];let d;e[7]!==i||e[8]!==c||e[9]!==l?(d=s.jsxs("div",{className:"flex items-center gap-2",children:[i,c,l]}),e[7]=i,e[8]=c,e[9]=l,e[10]=d):d=e[10];let u;e[11]!==o.prose?(u=s.jsx("p",{className:"typography-body text-muted-foreground",children:o.prose}),e[11]=o.prose,e[12]=u):u=e[12];let h;e[13]!==n.hunks||e[14]!==n.isStale||e[15]!==n.missingHunkIds||e[16]!==r?(h=n.isStale&&s.jsxs("p",{className:"typography-meta flex items-center gap-1.5 text-status-warning",children:[s.jsx(I,{name:"error-warning",className:"size-3.5 shrink-0"}),n.hunks.length===0?r("walkthrough.stop.staleAll"):r("walkthrough.stop.stalePartial",{count:n.missingHunkIds.length})]}),e[13]=n.hunks,e[14]=n.isStale,e[15]=n.missingHunkIds,e[16]=r,e[17]=h):h=e[17];let f;return e[18]!==d||e[19]!==u||e[20]!==h?(f=s.jsxs("header",{className:"flex flex-col gap-2 px-4 pt-5 pb-3",children:[d,u,h]}),e[18]=d,e[19]=u,e[20]=h,e[21]=f):f=e[21],f},gm=t=>{const e=nt.c(2),{path:n}=t;let r;return e[0]!==n?(r=s.jsxs("div",{className:"sticky top-0 z-10 flex items-center gap-1.5 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 px-4 py-1.5 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80",children:[s.jsx(Lo,{filePath:n,className:"size-3.5 shrink-0"}),s.jsx("span",{className:"typography-meta truncate font-mono text-foreground",children:n})]}),e[0]=n,e[1]=r):r=e[1],r},yv=t=>{const e=nt.c(11),{hunks:n,renderSideBySide:r,wrapLines:o}=t;let i;e[0]!==n?(i=hm(n),e[0]=n,e[1]=i):i=e[1];const c=i;let l;if(e[2]!==r||e[3]!==c||e[4]!==o){let u;e[6]!==r||e[7]!==o?(u=(h,f)=>s.jsxs("div",{children:[s.jsx(gm,{path:h.path}),s.jsx(pm,{path:h.path,hunks:h.hunks,renderSideBySide:r,wrapLines:o})]},`${h.path}-${f}`),e[6]=r,e[7]=o,e[8]=u):u=e[8],l=c.map(u),e[2]=r,e[3]=c,e[4]=o,e[5]=l}else l=e[5];let d;return e[9]!==l?(d=s.jsx(s.Fragment,{children:l}),e[9]=l,e[10]=d):d=e[10],d},wv=$e.memo(function(e){const n=nt.c(35),{view:r,activeStopId:o,scrollToStopId:i,onActiveStopChange:c,onScrollHandled:l,renderSideBySide:d,wrapLines:u}=e,{t:h}=ft(),f=$e.useRef(null),[p,x]=$e.useState(!1),b=$e.useRef(null),S=$e.useRef(null);let g,m;n[0]===Symbol.for("react.memo_cache_sentinel")?(g=()=>()=>{S.current!==null&&window.clearTimeout(S.current)},m=[],n[0]=g,n[1]=m):(g=n[0],m=n[1]),$e.useEffect(g,m);let y,C;n[2]!==l||n[3]!==i?(y=()=>{if(!i)return;const M=document.getElementById(Qa(i));M&&(b.current=i,M.scrollIntoView({behavior:"auto",block:"start"}),S.current!==null&&window.clearTimeout(S.current),S.current=window.setTimeout(()=>{b.current=null,S.current=null},250)),l()},C=[i,l],n[2]=l,n[3]=i,n[4]=y,n[5]=C):(y=n[4],C=n[5]),$e.useEffect(y,C);let j;n[6]!==c?(j=M=>{const L=M.filter(vv).sort(jv)[0];if(!L)return;const _=L.target.getAttribute("data-stop-id");if(!_)return;const D=b.current;if(D){_===D&&(b.current=null);return}c(_)},n[6]=c,n[7]=j):j=n[7];const w=j;let N,v;n[8]!==w||n[9]!==r.stops?(N=()=>{const M=f.current;if(!M)return;const L=new IntersectionObserver(w,{root:M,rootMargin:"0px 0px -70% 0px",threshold:0});for(const _ of r.stops){const D=document.getElementById(Qa(_.stop.id));D&&L.observe(D)}return()=>L.disconnect()},v=[w,r.stops],n[8]=w,n[9]=r.stops,n[10]=N,n[11]=v):(N=n[10],v=n[11]),$e.useEffect(N,v);let P;n[12]!==r.uncoveredHunks?(P=hm(r.uncoveredHunks),n[12]=r.uncoveredHunks,n[13]=P):P=n[13];const F=P;let k;if(n[14]!==o||n[15]!==d||n[16]!==h||n[17]!==r.stops||n[18]!==u){let M;n[20]!==o||n[21]!==d||n[22]!==h||n[23]!==u?(M=L=>s.jsxs("section",{id:Qa(L.stop.id),"data-stop-id":L.stop.id,className:De("border-b border-border/60",o===L.stop.id&&"bg-interactive-selection/5"),children:[s.jsx(bv,{stopView:L}),L.hunks.length>0?s.jsx(yv,{hunks:L.hunks,renderSideBySide:d,wrapLines:u}):s.jsx("p",{className:"typography-meta px-4 pb-4 text-muted-foreground",children:h("walkthrough.stop.noCode")})]},L.stop.id),n[20]=o,n[21]=d,n[22]=h,n[23]=u,n[24]=M):M=n[24],k=r.stops.map(M),n[14]=o,n[15]=d,n[16]=h,n[17]=r.stops,n[18]=u,n[19]=k}else k=n[19];let E;n[25]!==d||n[26]!==h||n[27]!==p||n[28]!==F||n[29]!==r.uncoveredHunks.length||n[30]!==u?(E=r.uncoveredHunks.length>0&&s.jsxs("section",{className:"border-b border-border/60",children:[s.jsxs(He,{type:"button",variant:"ghost",className:"h-auto w-full justify-start gap-2 px-4 py-3",onClick:()=>x(Sv),"aria-expanded":p,children:[s.jsx(I,{name:p?"arrow-down-s":"arrow-right-s",className:"size-4 shrink-0"}),s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:h("walkthrough.uncovered.title",{count:r.uncoveredHunks.length})})]}),!p&&s.jsx("p",{className:"typography-meta px-4 pb-3 pl-10 text-muted-foreground",children:h("walkthrough.uncovered.description")}),p&&F.map((M,L)=>s.jsxs("div",{children:[s.jsx(gm,{path:M.path}),s.jsx(pm,{path:M.path,hunks:M.hunks,renderSideBySide:d,wrapLines:u})]},`${M.path}-${L}`))]}),n[25]=d,n[26]=h,n[27]=p,n[28]=F,n[29]=r.uncoveredHunks.length,n[30]=u,n[31]=E):E=n[31];let O;return n[32]!==E||n[33]!==k?(O=s.jsxs("div",{ref:f,className:"min-h-0 flex-1 overflow-y-auto","data-diff-virtual-root":!0,"data-diff-virtual-content":!0,children:[k,E]}),n[32]=E,n[33]=k,n[34]=O):O=n[34],O});function vv(t){return t.isIntersecting}function jv(t,e){return t.boundingClientRect.top-e.boundingClientRect.top}function Sv(t){return!t}const kv={bug:"bug",wrench:"tools",path:"compass-3",flask:"flask",doc:"file-text",gear:"settings-3"},Nv=t=>{const e=nt.c(30),{stopView:n,isActive:r,isVisited:o,onSelect:i,activeRef:c}=t,{t:l}=ft();let d;if(e[0]!==c||e[1]!==r||e[2]!==o||e[3]!==i||e[4]!==n.hunks||e[5]!==n.isStale||e[6]!==n.position||e[7]!==n.stop.title||e[8]!==l){const u=lv(n.hunks),h=r&&"bg-interactive-selection text-interactive-selection-foreground";let f;e[10]!==h?(f=De("flex w-full flex-col gap-1 rounded px-2 py-1.5 text-left transition-colors","hover:bg-interactive-hover",h),e[10]=h,e[11]=f):f=e[11];const p=r?"bg-interactive-selection-foreground/20":o?"bg-status-success/15 text-status-success":"bg-surface-muted text-muted-foreground";let x;e[12]!==p?(x=De("typography-micro flex h-4 min-w-4 shrink-0 items-center justify-center rounded-full px-1 tabular-nums",p),e[12]=p,e[13]=x):x=e[13];let b;e[14]!==r||e[15]!==o||e[16]!==n.position?(b=o&&!r?s.jsx(I,{name:"check",className:"size-2.5"}):n.position,e[14]=r,e[15]=o,e[16]=n.position,e[17]=b):b=e[17];let S;e[18]!==x||e[19]!==b?(S=s.jsx("span",{className:x,children:b}),e[18]=x,e[19]=b,e[20]=S):S=e[20];let g;e[21]!==n.stop.title?(g=s.jsx("span",{className:"typography-meta truncate font-medium",children:n.stop.title}),e[21]=n.stop.title,e[22]=g):g=e[22];let m;e[23]!==n.isStale||e[24]!==l?(m=n.isStale&&s.jsx(I,{name:"error-warning",className:"size-3 shrink-0 text-status-warning","aria-label":l("walkthrough.stop.staleShort")}),e[23]=n.isStale,e[24]=l,e[25]=m):m=e[25];let y;e[26]!==S||e[27]!==g||e[28]!==m?(y=s.jsxs("span",{className:"flex items-center gap-2",children:[S,g,m]}),e[26]=S,e[27]=g,e[28]=m,e[29]=y):y=e[29],d=s.jsx("li",{children:s.jsxs("button",{ref:r?c:void 0,type:"button",onClick:i,"aria-current":r?"step":void 0,className:f,children:[y,u.length>0&&s.jsxs("span",{className:"typography-micro flex flex-col gap-0.5 pl-6 text-muted-foreground",children:[u.slice(0,3).map(Av),u.length>3&&s.jsx("span",{children:l("walkthrough.toc.moreFiles",{count:u.length-3})})]})]})}),e[0]=c,e[1]=r,e[2]=o,e[3]=i,e[4]=n.hunks,e[5]=n.isStale,e[6]=n.position,e[7]=n.stop.title,e[8]=l,e[9]=d}else d=e[9];return d},Cv=$e.memo(function(e){const n=nt.c(20),{view:r,activeStopId:o,visitedStopIds:i,onSelectStop:c,width:l}=e,{t:d}=ft(),u=$e.useRef(null);let h;n[0]===Symbol.for("react.memo_cache_sentinel")?(h=()=>{u.current?.scrollIntoView({block:"nearest"})},n[0]=h):h=n[0];let f;n[1]!==o?(f=[o],n[1]=o,n[2]=f):f=n[2],$e.useEffect(h,f);let p;n[3]!==l?(p={width:l},n[3]=l,n[4]=p):p=n[4];let x;n[5]!==r.walkthrough.focus?(x=r.walkthrough.focus&&s.jsx("p",{className:"typography-meta px-2 pb-3 pt-1 text-muted-foreground",children:r.walkthrough.focus}),n[5]=r.walkthrough.focus,n[6]=x):x=n[6];let b;n[7]!==o||n[8]!==c||n[9]!==r.chapters||n[10]!==i?(b=r.chapters.map(m=>{const{chapter:y,stops:C}=m;return s.jsxs("section",{className:"pb-3",children:[s.jsxs("h4",{className:"typography-micro flex items-center gap-1.5 px-2 py-1 font-semibold uppercase tracking-wide text-muted-foreground",children:[s.jsx(I,{name:kv[y.icon]??"file-text",className:"size-3 shrink-0"}),s.jsx("span",{className:"truncate",children:y.title})]}),s.jsx("ul",{className:"flex flex-col gap-0.5",children:C.map(j=>s.jsx(Nv,{stopView:j,isActive:o===j.stop.id,isVisited:i.has(j.stop.id),onSelect:()=>c(j.stop.id),activeRef:u},j.stop.id))})]},y.id)}),n[7]=o,n[8]=c,n[9]=r.chapters,n[10]=i,n[11]=b):b=n[11];let S;n[12]!==d||n[13]!==r.uncoveredHunks.length?(S=r.uncoveredHunks.length>0&&s.jsx("p",{className:"typography-micro mt-auto px-2 pt-3 text-muted-foreground",children:d("walkthrough.toc.uncovered",{count:r.uncoveredHunks.length})}),n[12]=d,n[13]=r.uncoveredHunks.length,n[14]=S):S=n[14];let g;return n[15]!==p||n[16]!==x||n[17]!==b||n[18]!==S?(g=s.jsxs("nav",{className:"flex shrink-0 flex-col overflow-y-auto border-r border-border/60 p-2",style:p,children:[x,b,S]}),n[15]=p,n[16]=x,n[17]=b,n[18]=S,n[19]=g):g=n[19],g});function Av(t){return s.jsx("span",{className:"truncate font-mono",children:t.path},t.path)}const Dv=["all","staged","working"],Xa="typography-meta font-normal text-muted-foreground",Ld=720,go=180,Ja=.5,Pv=680,Iv=({directory:t})=>{const{t:e,locale:n,locales:r,label:o}=ft(),i=$e.useRef(null),[c,l]=$e.useState(0);$e.useEffect(()=>{const We=i.current;if(!We||typeof ResizeObserver>"u")return;const yt=new ResizeObserver(Qe=>{l(Qe[0]?.contentRect.width??0)});return yt.observe(We),()=>yt.disconnect()},[]);const d=Re(We=>We.walkthroughTocWidth),u=Re(We=>We.setWalkthroughTocWidth),[h,f]=$e.useState(!1),p=c===0||c>=Ld,x=c>0&&c<Pv,b=Math.min(Math.max(d,go),Math.max(go,(c||Ld)*Ja)),S=$e.useCallback(We=>{We.preventDefault();const yt=We.clientX,Qe=b,Rt=Math.max(go,(i.current?.clientWidth??0)*Ja);f(!0);const Ot=Ft=>{const Ht=Math.min(Rt,Math.max(go,Qe+Ft.clientX-yt));u(Ht)},kt=()=>{f(!1),window.removeEventListener("pointermove",Ot),window.removeEventListener("pointerup",kt),window.removeEventListener("pointercancel",kt)};window.addEventListener("pointermove",Ot),window.addEventListener("pointerup",kt),window.addEventListener("pointercancel",kt)},[u,b]),g=$e.useCallback(We=>{const yt=We.shiftKey?40:10,Qe=We.key==="ArrowLeft"?-yt:We.key==="ArrowRight"?yt:0;if(Qe===0)return;We.preventDefault();const Rt=Math.max(go,(i.current?.clientWidth??0)*Ja);u(Math.min(Rt,Math.max(go,b+Qe)))},[u,b]),[m,y]=$e.useState("all"),[C,j]=$e.useState(null),[w,N]=$e.useState(null),[v,P]=$e.useState(()=>new Set),F=Re(We=>We.diffLayoutPreference),k=Re(We=>We.diffWrapLines),E=F==="side-by-side",O=Tn(We=>We.requestedSource[t]),M=Tn(We=>We.clearRequestedSource),L=Bo(t||null),_=ja(t||null),D=L?.current??null,A=$e.useMemo(()=>{const We=D;if(!We)return null;const yt=_?.all??[],Qe=yt.filter(kt=>!kt.startsWith("remotes/")),Rt=new Set(yt.filter(kt=>kt.startsWith("remotes/")).map(kt=>kt.slice(8).split("/")[0]).filter(Boolean)),Ot=ac({remoteNames:Rt,localBranches:Qe});return!Ot||Ot===We?null:{kind:"branch",baseRef:Ot,headRef:We}},[_,D]),{github:T}=_n(),z=Dr(We=>We.status?.connected??!1),R=Dr(We=>We.hasChecked),W=en(We=>We.ensureEntry),J=en(We=>We.setParams),U=en(We=>We.refreshTargets);$e.useEffect(()=>{if(!t||!D||!R||!z)return;const We=bi(t,D);W(We),J(We,{directory:t,branch:D,remoteName:null,canShow:!0,github:T,githubAuthChecked:R,githubConnected:z}),U([{directory:t,branch:D,remoteName:null}])},[D,t,W,T,R,z,U,J]);const te=en(We=>t&&D?Af(We.entries,t,D)?.pr?.number??null:null),Z=$e.useMemo(()=>O??{kind:"working-tree",scope:m},[O,m]),ue=$e.useMemo(()=>Z.kind==="pr"?Z:te?{kind:"pr",number:te}:null,[te,Z]),Oe=$e.useCallback(We=>{M(t),y(We)},[M,t]),se=Tn(We=>We.getEntry(t,Z)),G=Tn(We=>We.load),Ie=Tn(We=>We.generate),pe=Tn(We=>We.cancel),V=Tn(We=>We.requestSource),Q=Tn(We=>We.selectModel),ne=Tn(We=>We.getSelectedModel(t,Z)),oe=Tn(We=>We.selectLanguage),ce=Tn(We=>We.getSelectedLanguage(t,Z)),ke=se.result?.language,ye=ce&&r.includes(ce)?ce:ke&&r.includes(ke)?ke:n;$e.useEffect(()=>{G(t,Z,{language:ye})},[ye,t,G,Z,ne]);const he=$e.useMemo(()=>av(se.result),[se.result]),Ee=se.result?.generatedAt,Ue=$e.useRef(void 0);$e.useEffect(()=>{Ue.current!==Ee&&(Ue.current=Ee,P(new Set),j(he?.stops[0]?.stop.id??null))},[Ee,he]);const Me=$e.useCallback(We=>{j(We),P(yt=>{if(yt.has(We))return yt;const Qe=new Set(yt);return Qe.add(We),Qe})},[]),X=$e.useCallback(We=>{Me(We),N(We)},[Me]),Ne=$e.useCallback(We=>{if(!he||he.stops.length===0)return;const yt=he.stops.findIndex(Rt=>Rt.stop.id===C),Qe=Math.min(he.stops.length-1,Math.max(0,(yt<0?0:yt)+We));X(he.stops[Qe].stop.id)},[C,X,he]),[Ae,Se]=$e.useState(!1),[le,ee]=$e.useState(!1),ie=Z.kind==="working-tree"?Z.scope:Z.kind,ve=Z.kind==="branch"?e("walkthrough.scope.branch"):Z.kind==="pr"?e("walkthrough.scope.pullRequest",{number:Z.number}):e(m==="all"?"walkthrough.scope.all":m==="staged"?"walkthrough.scope.staged":"walkthrough.scope.working"),K=ne??(se.result?.model?`${se.result.model.providerID}/${se.result.model.modelID}`:void 0)??(se.readiness?.model?`${se.readiness.model.providerID}/${se.readiness.model.modelID}`:void 0),[de,..._e]=(K??"").split("/"),Pe=_e.join("/"),re=ts(We=>We.modelsMetadata),[me,ge]=$e.useState(void 0);$e.useEffect(()=>{if(me!==void 0)return;let We=!1;return(async()=>{try{const yt=await hs("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!yt.ok)return;const Qe=await yt.json().catch(()=>null);!We&&Array.isArray(Qe?.authenticatedProviders)&&ge(Qe.authenticatedProviders.filter(Rt=>typeof Rt=="string"))}catch{}})(),()=>{We=!0}},[me]);const $=$e.useCallback((We,yt)=>re.get(`${We}/${yt}`)?.structured_output!==!1,[re]),B=se.status==="generating",xe=se.result?.model?`${se.result.model.providerID}/${se.result.model.modelID}`:void 0,be=se.result?.language,Le=be&&r.includes(be)?be:void 0,Ke=se.status==="ready"&&!!he,st=Ke&&!!Le&&Le!==ye,ut=Ke&&!!xe&&!!K&&xe!==K,mt=gv(se.stage,se.status==="generating"),pt=$e.useRef(!1),ht=$e.useRef(se.status);$e.useEffect(()=>{ht.current!=="generating"&&se.status==="generating"&&(pt.current=!he),ht.current=se.status},[se.status,he]);const xt=pt.current&&(se.status==="generating"||mt.holding),wt=se.error?.code==="context-too-small"||se.error?.code==="structured-output-unsupported"||se.error?.code==="no-model"||se.error?.code==="empty-diff"||se.error?.code==="only-generated"||se.error?.code==="output-exhausted"?se.error.code:se.readiness&&!se.readiness.ready&&!he?se.readiness.reason:void 0,bt=se.error?.model??se.readiness?.model,Dt=se.error?.requiredChars??se.readiness?.requiredChars,qt=se.error?.availableChars??se.readiness?.availableChars,Ut=$e.useCallback(We=>{Ie(t,Z,{force:We,language:ye})},[ye,t,Ie,Z]);return s.jsxs("div",{ref:i,className:"flex h-full min-h-0 flex-col",children:[s.jsxs("header",{className:"flex shrink-0 flex-wrap items-center gap-2 border-b border-border/60 px-3 py-2",children:[s.jsxs(Qs,{open:Ae,onOpenChange:Se,children:[s.jsx(qs,{asChild:!0,children:s.jsxs("button",{type:"button",className:"flex h-8 flex-shrink-0 items-center gap-1.5 rounded-md px-2 typography-ui-label font-semibold text-foreground outline-none hover:bg-interactive-hover focus-visible:ring-2 focus-visible:ring-ring","aria-label":e("walkthrough.scope.selectorAria"),children:[s.jsx("span",{className:"whitespace-nowrap",children:ve}),s.jsx(I,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-60"})]})}),s.jsx(Ys,{align:"start",className:"w-48",children:s.jsxs(fl,{value:ie,onValueChange:We=>{if(Se(!1),We==="branch"){A&&V(t,A);return}if(We==="pr"){ue&&V(t,ue);return}Oe(We)},children:[s.jsx(So,{className:Xa,children:e("walkthrough.scope.group.workingTree")}),Dv.map(We=>s.jsx(oo,{value:We,children:e(We==="all"?"walkthrough.scope.all":We==="staged"?"walkthrough.scope.staged":"walkthrough.scope.working")},We)),(A||ue)&&s.jsxs(s.Fragment,{children:[s.jsx(Ln,{}),s.jsx(So,{className:Xa,children:e("walkthrough.scope.group.committed")})]}),A&&s.jsx(oo,{value:"branch",children:e("walkthrough.scope.branch")}),ue&&s.jsx(oo,{value:"pr",children:e("walkthrough.scope.pullRequest",{number:ue.number})})]})})]}),s.jsxs("div",{className:"ml-auto flex min-w-0 items-center gap-1",children:[s.jsxs(Qs,{open:le,onOpenChange:ee,children:[s.jsx(qs,{asChild:!0,children:s.jsxs("button",{type:"button",className:"flex h-8 min-w-0 flex-shrink items-center gap-1.5 rounded-md px-2 typography-ui-label text-muted-foreground outline-none hover:bg-interactive-hover hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring","aria-label":e("walkthrough.language.selectorAria"),title:x?o(ye):void 0,children:[s.jsx(I,{name:"global",className:"size-4 flex-shrink-0 opacity-70"}),!x&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"truncate",children:o(ye)}),s.jsx(I,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-60"})]})]})}),s.jsxs(Ys,{align:"end",className:"w-48",children:[s.jsx(So,{className:Xa,children:e("walkthrough.language.menuLabel")}),s.jsx(fl,{value:ye,onValueChange:We=>{ee(!1),oe(t,Z,We)},children:r.map(We=>s.jsx(oo,{value:We,children:o(We)},We))})]})]}),s.jsx(Hl,{providerId:de??"",modelId:Pe,onChange:(We,yt)=>{Q(t,Z,We&&yt?`${We}/${yt}`:null)},allowedProviderIds:me,isModelAllowed:$,tooltipsEnabled:!1,dropdownPortalToBody:!0,compact:x,className:De("h-8 min-w-0",!x&&"max-w-48")}),he&&s.jsxs(s.Fragment,{children:[s.jsx(He,{type:"button",variant:"ghost",size:"sm","aria-label":e("walkthrough.action.previous"),onClick:()=>Ne(-1),children:s.jsx(I,{name:"arrow-right-s",className:"size-4 rotate-180"})}),s.jsx(He,{type:"button",variant:"ghost",size:"sm","aria-label":e("walkthrough.action.next"),onClick:()=>Ne(1),children:s.jsx(I,{name:"arrow-right-s",className:"size-4"})})]}),B?s.jsx(He,{type:"button",variant:"outline",size:"sm","aria-label":x?e("walkthrough.action.cancel"):void 0,title:x?e("walkthrough.action.cancel"):void 0,onClick:()=>pe(t,Z),children:x?s.jsx(I,{name:"stop",className:"size-3.5"}):e("walkthrough.action.cancel")}):s.jsxs(He,{type:"button",variant:"outline",size:"sm",className:oc,"aria-label":x?e(he?"walkthrough.action.regenerate":"walkthrough.action.generate"):void 0,title:x?e(he?"walkthrough.action.regenerate":"walkthrough.action.generate"):void 0,onClick:()=>Ut(!!he),children:[s.jsx(I,{name:he?"refresh":"route",className:"size-3.5"}),!x&&e(he?"walkthrough.action.regenerate":"walkthrough.action.generate")]})]})]}),se.status==="generating"&&he&&s.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border/60 bg-[var(--status-info-background)] px-3 py-2",children:[s.jsx(I,{name:"loader-4",className:"size-4 shrink-0 animate-spin text-[var(--status-info)]"}),s.jsx("span",{className:"typography-meta text-foreground",children:se.stage==="collecting"?e("walkthrough.stage.collecting"):se.stage==="assembling"?e("walkthrough.stage.assembling"):e("walkthrough.stage.asking")})]}),(st||ut)&&s.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border/60 bg-[var(--status-info-background)] px-3 py-2",children:[s.jsx(I,{name:"information",className:"size-4 shrink-0 text-[var(--status-info)]"}),s.jsx("span",{className:"typography-meta text-foreground",children:st&&ut?e("walkthrough.missing.languageAndModel"):st?e("walkthrough.missing.language",{requested:o(ye),shown:o(Le)}):e("walkthrough.missing.model",{model:Pe})}),s.jsx(He,{type:"button",variant:"ghost",size:"xs",className:"ml-auto",onClick:()=>Ut(!1),children:e("walkthrough.action.generate")})]}),he?.isStale&&se.status!=="generating"&&s.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border/60 bg-status-warning/10 px-3 py-2",children:[s.jsx(I,{name:"error-warning",className:"size-4 shrink-0 text-status-warning"}),s.jsx("span",{className:"typography-meta text-foreground",children:e("walkthrough.stale.banner",{count:he.staleStopCount})}),s.jsx(He,{type:"button",variant:"ghost",size:"xs",className:"ml-auto",disabled:B,onClick:()=>Ut(!0),children:e("walkthrough.action.regenerate")})]}),se.error&&!wt&&s.jsxs("div",{className:"flex shrink-0 items-start gap-2 border-b border-border/60 bg-status-error/10 px-3 py-2",children:[s.jsx(I,{name:"error-warning",className:"mt-0.5 size-4 shrink-0 text-status-error"}),s.jsx("span",{className:"typography-meta line-clamp-2 text-foreground",title:se.error.message,children:se.error.message})]}),s.jsx("div",{className:De("flex min-h-0 flex-1",p?"flex-row":"flex-col"),children:wt?s.jsx(uv,{reason:wt,model:bt,requiredChars:Dt,availableChars:qt,onRetry:()=>{G(t,Z)}}):xt?s.jsx("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-8",children:s.jsx(mv,{progress:mt})}):he?s.jsxs(s.Fragment,{children:[p&&s.jsxs(s.Fragment,{children:[s.jsx(Cv,{view:he,activeStopId:C,visitedStopIds:v,onSelectStop:X,width:b}),s.jsx("div",{role:"separator","aria-orientation":"vertical","aria-label":e("walkthrough.toc.resize"),tabIndex:0,onPointerDown:S,onKeyDown:g,className:De("group relative w-1 shrink-0 cursor-col-resize","before:absolute before:inset-y-0 before:-left-1 before:-right-1 before:content-['']","hover:bg-interactive-selection focus-visible:bg-interactive-selection focus-visible:outline-none",h&&"bg-interactive-selection")})]}),s.jsx(wv,{view:he,activeStopId:C,scrollToStopId:w,onActiveStopChange:Me,onScrollHandled:()=>N(null),renderSideBySide:E,wrapLines:k})]}):s.jsx("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-8 text-center",children:se.status==="loading"?s.jsx(I,{name:"loader-4",className:"size-6 animate-spin text-muted-foreground"}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"route",className:"size-6 text-muted-foreground"}),s.jsx("h3",{className:"typography-ui-label font-semibold text-foreground",children:e("walkthrough.empty.title")}),s.jsx("p",{className:"typography-meta max-w-md text-muted-foreground",children:e("walkthrough.empty.description")})]})})})]})},Rv=t=>t.slice().sort((e,n)=>e.type!==n.type?e.type==="directory"?-1:1:e.name.localeCompare(n.name)),Zs=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},xm=(t,e)=>{const n=Zs(e),r=Zs(t).replace(/\/+$/,"");return n===r?".":!r||!n.startsWith(`${r}/`)?n:n.slice(r.length+1)},Mv=t=>t.startsWith("/")||t.startsWith("//")||/^[A-Za-z]:\//.test(t),Tv=new Set(["node_modules"]),Ev=t=>Tv.has(t),Fv=t=>{const e=Zs(t);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Ov=8,mr=new Map,cc=t=>JSON.stringify([$n(),t]),Lv=t=>{const e=cc(t),n=mr.get(e);return n?(n.touchedAt=Date.now(),mr.delete(e),mr.set(e,n),n):null},Za=t=>{const e=cc(t),n=mr.get(e);if(n)return n.touchedAt=Date.now(),n;if(mr.size>=Ov){const o=mr.keys().next().value;o!==void 0&&mr.delete(o)}const r={childrenByDir:{},loadErrorsByDir:{},loadedDirs:new Set,touchedAt:Date.now()};return mr.set(e,r),r},Bv=t=>{mr.delete(cc(t))},bm=(t,e)=>s.jsx(Lo,{filePath:t,extension:e}),$v=t=>{const e=nt.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},_v=t=>{const e=nt.c(66),{node:n,root:r,isExpanded:o,isActive:i,isBrowserClient:c,status:l,badge:d,permissions:u,downloadFile:h,onSelect:f,onToggle:p,onRevealPath:x,onOpenDialog:b}=t,{t:S}=ft(),g=n.type==="directory",{canRename:m,canCreateFile:y,canCreateFolder:C,canDelete:j,canReveal:w}=u,N=!g&&!!h,v=w&&!c,P=m||y||C||j||N||v,[F,k]=a.useState(!1),[E,O]=a.useState(!1);let M;e[0]!==P?(M=oe=>{P&&(oe?.preventDefault(),O(!0))},e[0]=P,e[1]=M):M=e[1];const L=M;let _;e[2]!==g||e[3]!==n||e[4]!==f||e[5]!==p?(_=()=>{g?p(n.path):f(n)},e[2]=g,e[3]=n,e[4]=f,e[5]=p,e[6]=_):_=e[6];const D=_;let A;e[7]===Symbol.for("react.memo_cache_sentinel")?(A=oe=>{oe.stopPropagation(),O(!1),k(!0)},e[7]=A):A=e[7];const T=A;let z;e[8]!==y||e[9]!==C||e[10]!==j||e[11]!==m||e[12]!==v||e[13]!==h||e[14]!==c||e[15]!==g||e[16]!==n||e[17]!==b||e[18]!==x||e[19]!==S?(z=oe=>{const{Item:ce,Separator:ke}=oe;return s.jsxs(s.Fragment,{children:[m&&s.jsxs(ce,{onClick:ye=>{ye.stopPropagation(),b("rename",n)},children:[s.jsx(I,{name:"edit",className:"mr-2 h-4 w-4"})," ",S("sidebarFilesTree.menu.rename")]}),s.jsxs(ce,{onClick:ye=>{ye.stopPropagation(),rr(n.path).then(he=>{if(he.ok){fe.success(S("sidebarFilesTree.toast.pathCopied"));return}fe.error(S("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(I,{name:"file-copy",className:"mr-2 h-4 w-4"})," ",S("sidebarFilesTree.menu.copyPath")]}),!g&&h&&s.jsxs(ce,{onClick:ye=>{ye.stopPropagation(),h(n.path).catch(he=>{console.error("Download failed:",he),fe.error(S("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(I,{name:"download",className:"mr-2 h-4 w-4"})," ",S(c?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),v&&s.jsxs(ce,{onClick:ye=>{ye.stopPropagation(),x(n.path)},children:[s.jsx(I,{name:"folder-received",className:"mr-2 h-4 w-4"})," ",S(Qu())]}),g&&(y||C)&&s.jsxs(s.Fragment,{children:[s.jsx(ke,{}),y&&s.jsxs(ce,{onClick:ye=>{ye.stopPropagation(),b("createFile",n)},children:[s.jsx(I,{name:"file-add",className:"mr-2 h-4 w-4"})," ",S("sidebarFilesTree.menu.newFile")]}),C&&s.jsxs(ce,{onClick:ye=>{ye.stopPropagation(),b("createFolder",n)},children:[s.jsx(I,{name:"folder-add",className:"mr-2 h-4 w-4"})," ",S("sidebarFilesTree.menu.newFolder")]})]}),j&&s.jsxs(s.Fragment,{children:[s.jsx(ke,{}),s.jsxs(ce,{onClick:ye=>{ye.stopPropagation(),b("delete",n)},className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"delete-bin",className:"mr-2 h-4 w-4"})," ",S("sidebarFilesTree.menu.delete")]})]})]})},e[8]=y,e[9]=C,e[10]=j,e[11]=m,e[12]=v,e[13]=h,e[14]=c,e[15]=g,e[16]=n,e[17]=b,e[18]=x,e[19]=S,e[20]=z):z=e[20];const R=z;let W;e[21]!==n.path||e[22]!==r?(W=oe=>{const ce=xm(r,n.path);!ce||ce==="."||(oe.dataTransfer.setData("application/x-openchamber-file-path",ce),oe.dataTransfer.effectAllowed="copy")},e[21]=n.path,e[22]=r,e[23]=W):W=e[23];const J=W;let U;e[24]!==L?(U=s.jsx("div",{className:"group relative flex items-center",onContextMenu:L}),e[24]=L,e[25]=U):U=e[25];const te=i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let Z;e[26]!==te?(Z=De("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",te,"cursor-grab active:cursor-grabbing"),e[26]=te,e[27]=Z):Z=e[27];let ue;e[28]!==g||e[29]!==o||e[30]!==n.extension||e[31]!==n.path?(ue=g?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"}):bm(n.path,n.extension),e[28]=g,e[29]=o,e[30]=n.extension,e[31]=n.path,e[32]=ue):ue=e[32];let Oe;e[33]!==n.name||e[34]!==n.path?(Oe=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:n.path,children:n.name}),e[33]=n.name,e[34]=n.path,e[35]=Oe):Oe=e[35];let se;e[36]!==g||e[37]!==l?(se=!g&&l&&s.jsx($v,{status:l}),e[36]=g,e[37]=l,e[38]=se):se=e[38];let G;e[39]!==d||e[40]!==g?(G=g&&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[39]=d,e[40]=g,e[41]=G):G=e[41];let Ie;e[42]!==L||e[43]!==J||e[44]!==D||e[45]!==Oe||e[46]!==se||e[47]!==G||e[48]!==Z||e[49]!==ue?(Ie=s.jsxs("button",{type:"button",onClick:D,onContextMenu:L,draggable:!0,onDragStart:J,className:Z,children:[ue,Oe,se,G]}),e[42]=L,e[43]=J,e[44]=D,e[45]=Oe,e[46]=se,e[47]=G,e[48]=Z,e[49]=ue,e[50]=Ie):Ie=e[50];let pe;e[51]!==F||e[52]!==P||e[53]!==R||e[54]!==S?(pe=P&&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(Qs,{open:F,onOpenChange:k,children:[s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(qs,{asChild:!0,children:s.jsx(He,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:T,title:S("sidebarFilesTree.actions.fileMenuTitle"),"aria-label":S("sidebarFilesTree.actions.fileMenuTitle"),children:s.jsx(I,{name:"more-2-fill",className:"h-4 w-4"})})})})}),s.jsx(At,{side:"bottom",sideOffset:6,children:S("sidebarFilesTree.actions.fileMenuTitle")})]}),s.jsx(Ys,{align:"end",side:"bottom",onCloseAutoFocus:()=>k(!1),children:R({Item:is,Separator:Ln})})]})}),e[51]=F,e[52]=P,e[53]=R,e[54]=S,e[55]=pe):pe=e[55];let V;e[56]!==Ie||e[57]!==pe||e[58]!==U?(V=s.jsxs(If,{render:U,children:[Ie,pe]}),e[56]=Ie,e[57]=pe,e[58]=U,e[59]=V):V=e[59];let Q;e[60]!==R?(Q=s.jsx(Df,{className:"min-w-[180px]",children:R({Item:Pf,Separator:ux})}),e[60]=R,e[61]=Q):Q=e[61];let ne;return e[62]!==E||e[63]!==V||e[64]!==Q?(ne=s.jsxs(Rf,{open:E,onOpenChange:O,children:[V,Q]}),e[62]=E,e[63]=V,e[64]=Q,e[65]=ne):ne=e[65],ne},zv=(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.permissions===e.permissions&&t.downloadFile===e.downloadFile&&t.onSelect===e.onSelect&&t.onToggle===e.onToggle&&t.onRevealPath===e.onRevealPath&&t.onOpenDialog===e.onOpenDialog,Vv=a.memo(_v,zv),Wv=()=>{const{t}=ft(),{files:e,runtime:n}=_n(),r=jh(n.platform),o=Wr()??"",i=Zs(o.trim()),c=Sh(),l=kh(),d=Gu(K=>K.searchFiles),u=Re(K=>K.openContextFile),h=Bo(o),[f,p]=a.useState(""),x=Kl(f,200),b=a.useRef(null),[S,g]=a.useState([]),[m,y]=a.useState(!1),[C,j]=a.useState({}),[w,N]=a.useState({}),v=a.useRef(new Set),P=a.useRef(new Set),F=a.useRef(null);a.useEffect(()=>{if(!i){j({}),N({}),v.current=new Set;return}const K=Lv(i);K?(j({...K.childrenByDir}),N({...K.loadErrorsByDir}),v.current=new Set(K.loadedDirs)):(j({}),N({}),v.current=new Set)},[i]),a.useEffect(()=>{if(!i)return;const K=Za(i);K.childrenByDir=C},[i,C]),a.useEffect(()=>{if(!i)return;const K=Za(i);K.loadErrorsByDir=w},[i,w]),a.useEffect(()=>{if(!i)return;const K=Za(i);K.loadedDirs=new Set(v.current)},[i,C,w]),a.useEffect(()=>()=>{if(!i)return;const K=mr.get(i);K&&K.loadedDirs.size===0&&Object.keys(K.childrenByDir).length===0&&Bv(i)},[i]);const k=a.useMemo(()=>[],[]),E=a.useMemo(()=>[],[]),O=jr(K=>i?K.byRoot[i]?.expandedPaths??k:k),M=jr(K=>i?K.byRoot[i]?.selectedPath??null:null),L=jr(K=>K.setSelectedPath),_=jr(K=>K.addOpenPath),D=jr(K=>K.removeOpenPathsByPrefix),A=jr(K=>K.toggleExpandedPath),T=jr(K=>K.collapseAllExpandedPaths),z=Re(K=>i?K.contextPanelByDirectory[i]?.tabs??E:E),R=a.useMemo(()=>new Set(z.map(K=>K.mode==="file"?K.targetPath:null).filter(K=>typeof K=="string"&&K.length>0).map(K=>Zs(K))),[z]),[W,J]=a.useState(null),[U,te]=a.useState(null),[Z,ue]=a.useState(""),[Oe,se]=a.useState(!1),G=!!e.writeFile,Ie=!!e.createDirectory,pe=!!e.rename,V=!!e.delete,Q=!!e.revealPath,ne=a.useMemo(()=>({canRename:pe,canCreateFile:G,canCreateFolder:Ie,canDelete:V,canReveal:Q}),[pe,G,Ie,V,Q]),oe=a.useCallback(K=>{e.revealPath&&e.revealPath(K).catch(()=>{fe.error(t("sidebarFilesTree.toast.revealFailed"))})},[e,t]),ce=a.useCallback((K,de)=>{J(K),te(de),ue(K==="rename"&&de.name||""),se(!1)},[]),ke=a.useCallback((K,de)=>{const _e=de.filter(Pe=>Pe&&typeof Pe.name=="string"&&Pe.name.length>0).filter(Pe=>c||!Pe.name.startsWith(".")).filter(Pe=>l||!Ev(Pe.name)).map(Pe=>{const re=Pe.name,me=Zs(Pe.path||""),ge=me?Mv(me)?me:Zs(`${K}/${me}`):Zs(`${K}/${re}`),$=Pe.isDirectory?"directory":"file",B=$==="file"&&re.includes(".")?re.split(".").pop()?.toLowerCase():void 0;return{name:re,path:ge,type:$,extension:B}});return Rv(_e)},[l,c]),ye=a.useCallback(async(K,de)=>{const _e=Zs(K.trim());if(!_e||v.current.has(_e)||P.current.has(_e))return;P.current=new Set(P.current),P.current.add(_e);const Pe=e.listDirectory?e.listDirectory(_e).then(re=>re.entries.map(me=>({name:me.name,path:me.path,isDirectory:me.isDirectory}))):Fn.listLocalDirectory(_e).then(re=>re.map(me=>({name:me.name,path:me.path,isDirectory:me.isDirectory})));try{const re=await Pe;if(de?.())return;const me=ke(_e,re);v.current=new Set(v.current),v.current.add(_e),N(ge=>{if(!ge[_e])return ge;const $={...ge};return delete $[_e],$}),j(ge=>({...ge,[_e]:me}))}catch(re){if(de?.())return;const me=re instanceof Error?re.message:String(re??"");console.error("Failed to load sidebar directory:",re),N(ge=>({...ge,[_e]:me}))}finally{P.current=new Set(P.current),P.current.delete(_e)}},[e,ke]),he=a.useCallback(async()=>{if(!i)return;F.current?.abort();const K=new AbortController;F.current=K;try{const _e=(jr.getState().byRoot[i]?.expandedPaths??[]).map(me=>Zs(me)).filter(me=>!!me&&me!==i&&me.startsWith(`${i}/`)),Pe=[i,..._e];v.current=new Set(v.current);for(const me of Pe)v.current.delete(me);N(me=>{if(Object.keys(me).length===0)return me;const ge={...me};let $=!1;for(const B of Pe)B in ge&&(delete ge[B],$=!0);return $?ge:me});const re=()=>K.signal.aborted;await ye(i,re);for(let me=0;me<_e.length&&!K.signal.aborted;me+=3){const ge=_e.slice(me,me+3);await Promise.all(ge.map($=>ye($,re)))}}catch(de){if(K.signal.aborted)return;console.error("Failed to refresh sidebar tree:",de)}finally{F.current===K&&(F.current=null)}},[ye,i]),Ee=a.useCallback(async K=>{if(!K){await he();return}const de=Zs(K);v.current=new Set(v.current),v.current.delete(de),P.current=new Set(P.current),P.current.delete(de),await ye(de)},[ye,he]);a.useEffect(()=>{i&&(F.current?.abort(),v.current=new Set,P.current=new Set,N({}),j(K=>Object.keys(K).length===0?K:{}),ye(i))},[ye,i,c,l]),a.useEffect(()=>{if(!i||O.length===0)return;const K=O.map(Pe=>Zs(Pe)).filter(Pe=>!!Pe&&Pe!==i&&Pe.startsWith(`${i}/`)&&!v.current.has(Pe)&&!P.current.has(Pe)).sort((Pe,re)=>Pe.split("/").length-re.split("/").length);if(K.length===0)return;let de=!1;const _e=()=>de;return(async()=>{for(let Pe=0;Pe<K.length&&!de;Pe+=3){const re=K.slice(Pe,Pe+3);await Promise.all(re.map(me=>ye(me,_e)))}})(),()=>{de=!0}},[O,ye,i]),a.useEffect(()=>{if(!o){g([]),y(!1);return}const K=x.trim();if(!K){g([]),y(!1);return}let de=!1;return y(!0),d(o,K,150,{includeHidden:c,respectGitignore:!l,type:"file"}).then(_e=>{if(de)return;const re=_e.filter(me=>l||!Fv(me.path)).map(me=>({name:me.name,path:Zs(me.path),type:"file",extension:me.extension,relativePath:me.relativePath}));g(re)}).catch(()=>{de||g([])}).finally(()=>{de||y(!1)}),()=>{de=!0}},[o,x,d,c,l]);const Ue=a.useMemo(()=>{const K=new Map;if(!h?.files)return K;for(const de of h.files)de.index==="A"||de.working_dir==="?"?K.set(de.path,"git-added"):de.index==="D"?K.set(de.path,"git-deleted"):(de.index==="M"||de.working_dir==="M")&&K.set(de.path,"git-modified");return K},[h]),Me=a.useMemo(()=>{const K=new Map;if(!h?.files||!i)return K;for(const de of h.files){const _e=de.index==="M"||de.working_dir==="M",Pe=de.index==="A"||de.working_dir==="?";if(!_e&&!Pe)continue;const re=de.path.split("/");if(re.length<=1)continue;let me=i;for(let ge=0;ge<re.length-1;ge++){me=`${me}/${re[ge]}`;let $=K.get(me);$||($={modified:0,added:0},K.set(me,$)),_e&&$.modified++,Pe&&$.added++}}return K},[h,i]),X=a.useCallback(K=>{if(R.has(K))return"open";if(Ue.size===0)return null;const de=K.startsWith(i+"/")?K.slice(i.length+1):K;return Ue.get(de)??null},[R,Ue,i]),Ne=a.useCallback(K=>{if(Me.size===0)return null;const de=Me.get(K);return de&&de.modified+de.added>0?de:null},[Me]),Ae=a.useCallback(async K=>{if(!i)return;const de=await nc(e,K.path,{directory:i});if(!de.ok){fe.error(rc(de.reason));return}L(i,K.path),_(i,K.path),u(i,K.path)},[_,e,u,i,L]),Se=a.useCallback(async K=>{const de=Zs(K);i&&(A(i,de),v.current.has(de)||await ye(de))},[ye,i,A]),le=a.useCallback(async K=>{if(K?.preventDefault(),!U||!W)return;se(!0);const de=()=>se(!1),_e=()=>J(null);if(W==="createFile"){if(!Z.trim()){fe.error(t("sidebarFilesTree.toast.filenameRequired")),de();return}if(!e.writeFile){fe.error(t("sidebarFilesTree.toast.writeNotSupported")),de();return}const Pe=U.path,re=Pe?`${Pe}/`:"",me=Zs(`${re}${Z.trim()}`);await e.writeFile(me,"").then(async ge=>{ge.success&&(fe.success(t("sidebarFilesTree.toast.fileCreated")),await Ee(Pe)),_e()}).catch(()=>fe.error(t("sidebarFilesTree.toast.operationFailed"))).finally(de);return}if(W==="createFolder"){if(!Z.trim()){fe.error(t("sidebarFilesTree.toast.folderNameRequired")),de();return}const Pe=U.path,re=Pe?`${Pe}/`:"",me=Zs(`${re}${Z.trim()}`);await e.createDirectory(me).then(async ge=>{ge.success&&(fe.success(t("sidebarFilesTree.toast.folderCreated")),await Ee(Pe)),_e()}).catch(()=>fe.error(t("sidebarFilesTree.toast.operationFailed"))).finally(de);return}if(W==="rename"){if(!Z.trim()){fe.error(t("sidebarFilesTree.toast.nameRequired")),de();return}if(!e.rename){fe.error(t("sidebarFilesTree.toast.renameNotSupported")),de();return}const Pe=U.path,re=Pe.split("/").slice(0,-1).join("/"),me=re?`${re}/`:"",ge=Zs(`${me}${Z.trim()}`);await e.rename(Pe,ge).then(async $=>{$.success&&(fe.success(t("sidebarFilesTree.toast.renamedSuccessfully")),await Ee(re),i&&D(i,Pe),(M===Pe||M&&M.startsWith(`${Pe}/`))&&L(i,null)),_e()}).catch(()=>fe.error(t("sidebarFilesTree.toast.operationFailed"))).finally(de);return}if(W==="delete"){if(!e.delete){fe.error(t("sidebarFilesTree.toast.deleteNotSupported")),de();return}const Pe=U.path,re=Pe.split("/").slice(0,-1).join("/");await e.delete(Pe).then(async me=>{me.success&&(fe.success(t("sidebarFilesTree.toast.deletedSuccessfully")),await Ee(re),i&&D(i,Pe),(M===Pe||M&&M.startsWith(Pe+"/"))&&L(i,null)),_e()}).catch(()=>fe.error(t("sidebarFilesTree.toast.operationFailed"))).finally(de);return}de()},[W,U,Z,e,Ee,D,i,M,L,t]);function ee(K,de){const _e=C[K]??[];return _e.map((Pe,re)=>{const me=Pe.type==="directory",ge=me&&O.includes(Pe.path),$=M===Pe.path,B=re===_e.length-1;return s.jsxs("li",{className:"relative",children:[de>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),B&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-sidebar/50"})]}),s.jsx(Vv,{node:Pe,root:i,isExpanded:ge,isActive:$,isBrowserClient:r,status:me?void 0:X(Pe.path),badge:me?Ne(Pe.path):void 0,permissions:ne,downloadFile:e.downloadFile,onSelect:Ae,onToggle:Se,onRevealPath:oe,onOpenDialog:ce}),me&&ge&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[w[Pe.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:w[Pe.path],children:w[Pe.path]}),s.jsxs(He,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{Ee(Pe.path)},children:[s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):null,ee(Pe.path,de+1)]})]},Pe.path)})}const ie=!!(i&&C[i]),ve=i?w[i]:null;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:[G&&s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(He,{variant:"ghost",size:"sm",onClick:()=>ce("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(At,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFileTitle")})]}),Ie&&s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(He,{variant:"ghost",size:"sm",onClick:()=>ce("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(At,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.newFolderTitle")})]}),s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(He,{variant:"ghost",size:"sm",onClick:()=>{he()},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(At,{side:"bottom",sideOffset:6,children:t("sidebarFilesTree.actions.refreshTitle")})]}),s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(He,{variant:"ghost",size:"sm",onClick:()=>{i&&T(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(At,{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(or,{ref:b,value:f,onChange:K=>p(K.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(""),b.current?.focus()},children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null]})]}),s.jsx(On,{outerClassName:"flex-1 min-h-0",className:"p-2",children:s.jsx("ul",{className:"flex flex-col",children:m?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")]}):S.length>0?S.map(K=>{const de=M===K.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>Ae(K),draggable:!0,onDragStart:_e=>{const Pe=K.relativePath||xm(i??"",K.path);!Pe||Pe==="."||(_e.dataTransfer.setData("application/x-openchamber-file-path",Pe),_e.dataTransfer.effectAllowed="copy")},className:De("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",de?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),title:K.path,children:[bm(K.path,K.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},children:K.relativePath??K.path})]})},K.path)}):ve?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{children:ve}),s.jsxs(He,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{he()},children:[s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"}),t("sidebarFilesTree.actions.refreshTitle")]})]}):ie&&i?ee(i,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:t("sidebarFilesTree.state.loading")})})}),s.jsx(Ts,{open:!!W,onOpenChange:K=>!K&&J(null),children:s.jsxs(Es,{children:[s.jsxs(Hs,{children:[s.jsxs($s,{children:[W==="createFile"&&t("sidebarFilesTree.dialog.createFile.title"),W==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.title"),W==="rename"&&t("sidebarFilesTree.dialog.rename.title"),W==="delete"&&t("sidebarFilesTree.dialog.delete.title")]}),s.jsxs(Ks,{children:[W==="createFile"&&t("sidebarFilesTree.dialog.createFile.description",{path:U?.path??t("sidebarFilesTree.dialog.rootFallback")}),W==="createFolder"&&t("sidebarFilesTree.dialog.createFolder.description",{path:U?.path??t("sidebarFilesTree.dialog.rootFallback")}),W==="rename"&&t("sidebarFilesTree.dialog.rename.description",{name:U?.name??""}),W==="delete"&&t("sidebarFilesTree.dialog.delete.description",{name:U?.name??""})]})]}),W!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(or,{value:Z,onChange:K=>ue(K.target.value),placeholder:t(W==="rename"?"sidebarFilesTree.dialog.rename.placeholder":"sidebarFilesTree.dialog.namePlaceholder"),onKeyDown:K=>{K.key==="Enter"&&le()},autoFocus:!0})}),s.jsxs(ar,{children:[s.jsx(He,{variant:"outline",onClick:()=>J(null),disabled:Oe,children:t("sidebarFilesTree.dialog.cancel")}),s.jsx(He,{variant:W==="delete"?"destructive":"default",onClick:()=>{le()},disabled:Oe||W!=="delete"&&!Z.trim(),children:Oe?s.jsx(I,{name:"loader-4",className:"size-4 animate-spin"}):t(W==="delete"?"sidebarFilesTree.dialog.delete.confirm":"sidebarFilesTree.dialog.confirm")})]})]})})]})},dc=t=>t,kl=t=>{const e=dc(t).type;return typeof e=="string"?e:""},Uv=t=>{const e=dc(t).tool;return typeof e=="string"?e:""},Hv=t=>{const e=dc(t).text;return typeof e=="string"?e:""},Kv=t=>{const e=kl(t);return e==="tool"?Uv(t).trim().toLowerCase()||"tool":e||"unknown"},Gv=t=>{if(t.length===0)return"";const e=[];for(const n of t){const r=Kv(n);e.includes(r)||e.push(r)}return e.join(" + ")},qv=t=>t.replace(/\s+/g," ").trim(),Yv=t=>{for(const n of t)if(kl(n)==="text"){const r=qv(Hv(n));if(r.length===0)continue;return r}const e=t.filter(n=>kl(n)!=="text").length;return e===0?"":`${e} attachment${e===1?"":"s"}`},Qv=(t,e,n)=>`${n(t)} / ${n(e)}`,Xv=t=>{if(t==="12h")return!0;if(t==="24h")return!1},Jv=(t,e)=>{if(!t||!Number.isFinite(t))return"-";const n=Xv(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}})},Nl={input:0,output:0,reasoning:0,cacheRead:0,cacheWrite:0,total:0},zi={user:0,assistant:0,tool:0,other:0},to=t=>typeof t!="number"||!Number.isFinite(t)||t<0?0:t,el=t=>{const e=t.info.tokens,n=e!==void 0?e:t.parts.find(u=>u.tokens!==void 0)?.tokens;if(typeof n=="number")return{...Nl,total:to(n)};if(!n||typeof n!="object")return Nl;const r=n,o=to(r.input),i=to(r.output),c=to(r.reasoning),l=to(r.cache?.read),d=to(r.cache?.write);return{input:o,output:i,reasoning:c,cacheRead:l,cacheWrite:d,total:o+i+c+l+d}},Zv=(...t)=>{for(const e of t)if(typeof e=="string"&&e.trim().length>0)return e;return""},En=t=>typeof t=="string"?t.length:typeof t=="number"||typeof t=="boolean"?String(t).length:Array.isArray(t)?t.reduce((e,n)=>e+En(n),0):t&&typeof t=="object"?Object.values(t).reduce((e,n)=>e+En(n),0):0,e1=(t,e)=>{const n=t,r=typeof n.type=="string"?n.type:"";if(r==="reasoning")return{...zi,assistant:En(n.text)+En(n.content)};const o=Zv(n.text,n.content,n.value,n.source?.value,n.source?.text?.value);return r==="tool"||e==="tool"?{user:0,assistant:0,tool:En(n.input)+En(n.output)+En(n.error)+En(n.call?.input)+En(n.call?.output)+En(n.call?.error)+En(n.raw)+Math.round(En(n.metadata)*.25)+Math.round(En(n.state)*.1),other:0}:e==="user"?{user:o.length,assistant:0,tool:0,other:0}:e==="assistant"?{user:0,assistant:o.length,tool:0,other:0}:{user:0,assistant:0,tool:0,other:o.length}},Bd=(t,e)=>({user:t.user+e.user,assistant:t.assistant+e.assistant,tool:t.tool+e.tool,other:t.other+e.other}),t1=t=>{const e=gi(t.info);return e.isUser?"user":e.role==="assistant"?"assistant":e.role==="tool"?"tool":"other"},s1=(t,e)=>{if(t.length===0)return{...zi};const n=t.reduce((r,o)=>{const i=t1(o);let c={...zi};for(const l of o.parts)c=Bd(c,e1(l,i));return Bd(r,c)},{...zi});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)}},so=t=>t.toLocaleString(ii()),n1=t=>!Number.isFinite(t)||t<=0?new Intl.NumberFormat(ii(),{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:2}).format(0):new Intl.NumberFormat(ii(),{style:"currency",currency:"USD",minimumFractionDigits:t<.01?4:2,maximumFractionDigits:t<.01?4:2}).format(t),r1=(t,e)=>!t||!Number.isFinite(t)?"-":Ul(t,e,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"}),o1=(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}},i1=()=>{const t=nt.c(203),{t:e}=ft(),n=Re(a1);let r;t[0]===Symbol.for("react.memo_cache_sentinel")?(r={},t[0]=r):r=t[0];const[o,i]=a.useState(r),[c,l]=a.useState(null),d=a.useRef(null),u=et(l1),h=et(c1),f=of(h??void 0),p=Pp(u??"",h??void 0),x=ts(d1);let b;t[1]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{d.current!==null&&(window.clearTimeout(d.current),d.current=null),i(u1),l(null)},t[1]=b):b=t[1];let S;t[2]!==h||t[3]!==u?(S=[h,u],t[2]=h,t[3]=u,t[4]=S):S=t[4],a.useEffect(b,S);let g,m;t[5]===Symbol.for("react.memo_cache_sentinel")?(g=()=>()=>{d.current!==null&&(window.clearTimeout(d.current),d.current=null)},m=[],t[5]=g,t[6]=m):(g=t[5],m=t[6]),a.useEffect(g,m);let y;t[7]===Symbol.for("react.memo_cache_sentinel")?(y=async(rt,je)=>{(await rr(je)).ok?(l(rt),d.current!==null&&window.clearTimeout(d.current),d.current=window.setTimeout(()=>{l(Te=>Te===rt?null:Te),d.current=null},2e3)):l(null)},t[7]=y):y=t[7];const C=y;let j;t[8]!==u||t[9]!==f?(j=u?f.find(rt=>rt.id===u)??null:null,t[8]=u,t[9]=f,t[10]=j):j=t[10];const w=j;let N,v,P,F,k,E;if(t[11]!==x||t[12]!==p){N=p.filter(f1);let rt;t[19]!==p?(rt=p.filter(m1),t[19]=p,t[20]=rt):rt=t[20],E=rt;let je=null;for(let Te=N.length-1;Te>=0;Te=Te-1,Te){const it=N[Te];if(el(it).total>0){je=it;break}}F=je?el(je):Nl,v=Ip({input:F.input,cache:{read:F.cacheRead,write:F.cacheWrite}}),k=N.reduce(h1,0);const Fe=je?.info??null;P=o1(x,Fe?.providerID||"",Fe?.modelID||""),t[11]=x,t[12]=p,t[13]=N,t[14]=v,t[15]=P,t[16]=F,t[17]=k,t[18]=E}else N=t[13],v=t[14],P=t[15],F=t[16],k=t[17],E=t[18];const O=P,M=O.contextLimit,L=M&&M>0?Math.min(999,F.total/M*100):0;let _;if(t[21]!==p){const rt=[...p].reverse().find(p1)?.info?.system||"";_=s1(p,rt),t[21]=p,t[22]=_}else _=t[22];const D=_,A=D.user,T=D.assistant,z=D.tool,R=Math.max(0,F.input-A-T-z),W=A+T+z+R,J=p[0]?.info?.time?.created,U=p.length>0?p[p.length-1]?.info?.time?.created:null;let te;t[23]!==w?.title||t[24]!==e?(te=w?.title||e("contextSidebar.session.untitled"),t[23]=w?.title,t[24]=e,t[25]=te):te=t[25];const Z=w?.time?.created??J??null,ue=U??w?.time?.created??null;let Oe;t[26]!==T||t[27]!==R||t[28]!==z||t[29]!==A?(Oe={user:A,assistant:T,tool:z,other:R},t[26]=T,t[27]=R,t[28]=z,t[29]=A,t[30]=Oe):Oe=t[30];let se;t[31]!==N.length||t[32]!==W||t[33]!==v||t[34]!==M||t[35]!==O||t[36]!==p.length||t[37]!==Z||t[38]!==ue||t[39]!==Oe||t[40]!==te||t[41]!==F||t[42]!==k||t[43]!==L||t[44]!==E.length?(se={sessionTitle:te,messagesCount:p.length,userMessagesCount:E.length,assistantMessagesCount:N.length,createdAt:Z,lastActivityAt:ue,providerModel:O,tokenBreakdown:F,usagePercent:L,cacheHitRate:v,totalAssistantCost:k,contextLimit:M,breakdown:Oe,breakdownTotal:W},t[31]=N.length,t[32]=W,t[33]=v,t[34]=M,t[35]=O,t[36]=p.length,t[37]=Z,t[38]=ue,t[39]=Oe,t[40]=te,t[41]=F,t[42]=k,t[43]=L,t[44]=E.length,t[45]=se):se=t[45];const G=se;if(!u){let rt;t[46]!==e?(rt=e("contextSidebar.empty.openSession"),t[46]=e,t[47]=rt):rt=t[47];let je;return t[48]!==rt?(je=s.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center typography-ui-label text-muted-foreground",children:rt}),t[48]=rt,t[49]=je):je=t[49],je}let Ie;t[50]!==e?(Ie=e("contextSidebar.breakdown.user"),t[50]=e,t[51]=Ie):Ie=t[51];let pe;t[52]!==Ie||t[53]!==G.breakdown.user?(pe={key:"user",label:Ie,value:G.breakdown.user,color:"var(--status-success)"},t[52]=Ie,t[53]=G.breakdown.user,t[54]=pe):pe=t[54];let V;t[55]!==e?(V=e("contextSidebar.breakdown.assistant"),t[55]=e,t[56]=V):V=t[56];let Q;t[57]!==V||t[58]!==G.breakdown.assistant?(Q={key:"assistant",label:V,value:G.breakdown.assistant,color:"var(--primary-base)"},t[57]=V,t[58]=G.breakdown.assistant,t[59]=Q):Q=t[59];let ne;t[60]!==e?(ne=e("contextSidebar.breakdown.toolCalls"),t[60]=e,t[61]=ne):ne=t[61];let oe;t[62]!==ne||t[63]!==G.breakdown.tool?(oe={key:"tool",label:ne,value:G.breakdown.tool,color:"var(--status-warning)"},t[62]=ne,t[63]=G.breakdown.tool,t[64]=oe):oe=t[64];let ce;t[65]!==e?(ce=e("contextSidebar.breakdown.other"),t[65]=e,t[66]=ce):ce=t[66];let ke;t[67]!==ce||t[68]!==G.breakdown.other?(ke={key:"other",label:ce,value:G.breakdown.other,color:"var(--surface-muted-foreground)"},t[67]=ce,t[68]=G.breakdown.other,t[69]=ke):ke=t[69];let ye;t[70]!==pe||t[71]!==Q||t[72]!==oe||t[73]!==ke?(ye=[pe,Q,oe,ke],t[70]=pe,t[71]=Q,t[72]=oe,t[73]=ke,t[74]=ye):ye=t[74];const he=ye;let Ee;t[75]!==G.sessionTitle?(Ee=s.jsx("h2",{className:"typography-ui-header font-semibold text-foreground truncate",children:G.sessionTitle}),t[75]=G.sessionTitle,t[76]=Ee):Ee=t[76];let Ue;t[77]!==G.providerModel.modelName||t[78]!==G.providerModel.providerName?(Ue=s.jsxs("span",{children:[G.providerModel.providerName," / ",G.providerModel.modelName]}),t[77]=G.providerModel.modelName,t[78]=G.providerModel.providerName,t[79]=Ue):Ue=t[79];let Me;t[80]!==n||t[81]!==G.createdAt?(Me=G.createdAt&&s.jsxs(s.Fragment,{children:[s.jsx("span",{children:"·"}),s.jsx("span",{children:r1(G.createdAt,n)})]}),t[80]=n,t[81]=G.createdAt,t[82]=Me):Me=t[82];let X;t[83]!==Ue||t[84]!==Me?(X=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:[Ue,Me]}),t[83]=Ue,t[84]=Me,t[85]=X):X=t[85];let Ne;t[86]!==Ee||t[87]!==X?(Ne=s.jsxs("div",{className:"mb-6",children:[Ee,X]}),t[86]=Ee,t[87]=X,t[88]=Ne):Ne=t[88];let Ae;t[89]!==e?(Ae=e("contextSidebar.section.context"),t[89]=e,t[90]=Ae):Ae=t[90];let Se;t[91]!==Ae?(Se=s.jsx("span",{className:"typography-micro text-muted-foreground",children:Ae}),t[91]=Ae,t[92]=Se):Se=t[92];let le;t[93]!==G.tokenBreakdown.total?(le=so(G.tokenBreakdown.total),t[93]=G.tokenBreakdown.total,t[94]=le):le=t[94];let ee;t[95]!==G.contextLimit?(ee=G.contextLimit?` / ${so(G.contextLimit)}`:"",t[95]=G.contextLimit,t[96]=ee):ee=t[96];let ie;t[97]!==le||t[98]!==ee?(ie=s.jsxs("span",{className:"typography-micro tabular-nums text-muted-foreground/70",children:[le,ee]}),t[97]=le,t[98]=ee,t[99]=ie):ie=t[99];let ve;t[100]!==Se||t[101]!==ie?(ve=s.jsxs("div",{className:"flex items-baseline justify-between",children:[Se,ie]}),t[100]=Se,t[101]=ie,t[102]=ve):ve=t[102];let K;t[103]!==G.usagePercent?(K=G.usagePercent>0&&s.jsx("div",{className:"rounded-full transition-all duration-300",style:{width:`${Math.max(.5,G.usagePercent)}%`,backgroundColor:G.usagePercent>80?"var(--status-warning)":"var(--primary-base)"}}),t[103]=G.usagePercent,t[104]=K):K=t[104];let de;t[105]!==K?(de=s.jsx("div",{className:"mt-2.5 flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:K}),t[105]=K,t[106]=de):de=t[106];let _e;t[107]!==e||t[108]!==G.usagePercent?(_e=e("contextSidebar.context.percentUsed",{percent:G.usagePercent.toFixed(1)}),t[107]=e,t[108]=G.usagePercent,t[109]=_e):_e=t[109];let Pe;t[110]!==_e?(Pe=s.jsx("div",{className:"mt-1.5 typography-micro font-medium tabular-nums text-foreground/80",children:_e}),t[110]=_e,t[111]=Pe):Pe=t[111];let re;t[112]!==ve||t[113]!==de||t[114]!==Pe?(re=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[ve,de,Pe]}),t[112]=ve,t[113]=de,t[114]=Pe,t[115]=re):re=t[115];let me;t[116]!==e?(me=e("contextSidebar.stats.messages"),t[116]=e,t[117]=me):me=t[117];let ge;t[118]!==G.messagesCount?(ge=so(G.messagesCount),t[118]=G.messagesCount,t[119]=ge):ge=t[119];let $;t[120]!==me||t[121]!==ge?($={label:me,value:ge},t[120]=me,t[121]=ge,t[122]=$):$=t[122];let B;t[123]!==e?(B=e("contextSidebar.stats.user"),t[123]=e,t[124]=B):B=t[124];let xe;t[125]!==G.userMessagesCount?(xe=so(G.userMessagesCount),t[125]=G.userMessagesCount,t[126]=xe):xe=t[126];let be;t[127]!==B||t[128]!==xe?(be={label:B,value:xe},t[127]=B,t[128]=xe,t[129]=be):be=t[129];let Le;t[130]!==e?(Le=e("contextSidebar.stats.assistant"),t[130]=e,t[131]=Le):Le=t[131];let Ke;t[132]!==G.assistantMessagesCount?(Ke=so(G.assistantMessagesCount),t[132]=G.assistantMessagesCount,t[133]=Ke):Ke=t[133];let st;t[134]!==Le||t[135]!==Ke?(st={label:Le,value:Ke},t[134]=Le,t[135]=Ke,t[136]=st):st=t[136];let ut;t[137]!==e?(ut=e("contextSidebar.stats.cost"),t[137]=e,t[138]=ut):ut=t[138];let mt;t[139]!==G.totalAssistantCost?(mt=n1(G.totalAssistantCost),t[139]=G.totalAssistantCost,t[140]=mt):mt=t[140];let pt;t[141]!==ut||t[142]!==mt?(pt={label:ut,value:mt},t[141]=ut,t[142]=mt,t[143]=pt):pt=t[143];let ht;t[144]!==$||t[145]!==be||t[146]!==st||t[147]!==pt?(ht=[$,be,st,pt],t[144]=$,t[145]=be,t[146]=st,t[147]=pt,t[148]=ht):ht=t[148];const xt=ht;let wt;t[149]!==xt?(wt=s.jsx("div",{className:"mb-5 grid grid-cols-2 gap-2",children:xt.map(g1)}),t[149]=xt,t[150]=wt):wt=t[150];let bt;t[151]!==e?(bt=e("contextSidebar.section.lastAssistantMessage"),t[151]=e,t[152]=bt):bt=t[152];let Dt;t[153]!==bt?(Dt=s.jsx("div",{className:"typography-micro text-muted-foreground mb-2.5",children:bt}),t[153]=bt,t[154]=Dt):Dt=t[154];let qt;t[155]!==e||t[156]!==G.cacheHitRate.hasInput||t[157]!==G.cacheHitRate.percent||t[158]!==G.tokenBreakdown.cacheRead||t[159]!==G.tokenBreakdown.cacheWrite||t[160]!==G.tokenBreakdown.input||t[161]!==G.tokenBreakdown.output||t[162]!==G.tokenBreakdown.reasoning?(qt=s.jsx("div",{className:"grid grid-cols-3 gap-x-4 gap-y-2.5",children:[{label:e("contextSidebar.tokens.input"),value:G.tokenBreakdown.input,format:"count"},{label:e("contextSidebar.tokens.output"),value:G.tokenBreakdown.output,format:"count"},{label:e("contextSidebar.tokens.reasoning"),value:G.tokenBreakdown.reasoning,format:"count"},{label:e("contextSidebar.tokens.cacheRead"),value:G.tokenBreakdown.cacheRead,format:"count"},{label:e("contextSidebar.tokens.cacheWrite"),value:G.tokenBreakdown.cacheWrite,format:"count"},{label:e("contextSidebar.tokens.cacheHit"),value:G.cacheHitRate.hasInput?G.cacheHitRate.percent:null,format:"percent"}].map(x1)}),t[155]=e,t[156]=G.cacheHitRate.hasInput,t[157]=G.cacheHitRate.percent,t[158]=G.tokenBreakdown.cacheRead,t[159]=G.tokenBreakdown.cacheWrite,t[160]=G.tokenBreakdown.input,t[161]=G.tokenBreakdown.output,t[162]=G.tokenBreakdown.reasoning,t[163]=qt):qt=t[163];let Ut;t[164]!==Dt||t[165]!==qt?(Ut=s.jsxs("div",{className:"mb-5 rounded-lg bg-[var(--surface-elevated)]/70 px-4 py-3.5",children:[Dt,qt]}),t[164]=Dt,t[165]=qt,t[166]=Ut):Ut=t[166];let We;t[167]!==he||t[168]!==G.breakdownTotal?(We=s.jsx("div",{className:"flex h-1 w-full overflow-hidden rounded-full bg-[var(--surface-subtle)]",children:he.map(rt=>rt.value<=0||G.breakdownTotal<=0?null:s.jsx("div",{style:{width:`${rt.value/G.breakdownTotal*100}%`,backgroundColor:rt.color}},rt.key))}),t[167]=he,t[168]=G.breakdownTotal,t[169]=We):We=t[169];let yt;t[170]!==he||t[171]!==G.breakdownTotal?(yt=s.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:he.map(rt=>{const je=G.breakdownTotal>0?rt.value/G.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:rt.color}}),s.jsxs("span",{className:"typography-micro text-muted-foreground/70",children:[rt.label," ",s.jsxs("span",{className:"tabular-nums",children:[je.toFixed(0),"%"]})]})]},rt.key)})}),t[170]=he,t[171]=G.breakdownTotal,t[172]=yt):yt=t[172];let Qe;t[173]!==We||t[174]!==yt?(Qe=s.jsxs("div",{className:"mb-6",children:[We,yt]}),t[173]=We,t[174]=yt,t[175]=Qe):Qe=t[175];let Rt;t[176]!==e?(Rt=e("contextSidebar.section.rawMessages"),t[176]=e,t[177]=Rt):Rt=t[177];let Ot;t[178]!==Rt?(Ot=s.jsx("div",{className:"typography-micro text-muted-foreground",children:Rt}),t[178]=Rt,t[179]=Ot):Ot=t[179];let kt;if(t[180]!==c||t[181]!==o||t[182]!==p||t[183]!==e||t[184]!==n){let rt;t[186]!==c||t[187]!==o||t[188]!==e||t[189]!==n?(rt=je=>{const Te=gi(je.info).role,it=Te==="assistant",ct=Te==="user",Kt=o[je.info.id]===!0,Lt=c===je.info.id,ze=je.info.time?.created??null,Xe=Gv(je.parts),tt=it?el({info:je.info,parts:je.parts}):null,at=ct?Yv(je.parts):"",Ze=Jv(ze,n),Pt=Xe||"—",Tt=tt?Qv(tt.input,tt.output,so):"",Jt=Te||"unknown",ls=Xe?`${Jt}: ${Xe}`:Jt,cs=Kt?JSON.stringify({info:je.info,parts:je.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":Kt,onClick:()=>{i(Bt=>({...Bt,[je.info.id]:Bt[je.info.id]!==!0}))},children:s.jsxs("div",{className:"grid items-center gap-x-2 whitespace-nowrap typography-micro",style:{gridTemplateColumns:it?"minmax(0, 1fr) 7.5rem max-content":"minmax(0, 1fr) max-content"},children:[ct?s.jsxs("span",{className:"min-w-0 truncate text-muted-foreground",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:"user:"})," ",at]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"min-w-0 truncate text-muted-foreground",children:it?Pt:ls}),it&&s.jsx("span",{className:"text-right text-muted-foreground tabular-nums",children:Tt})]}),s.jsx("span",{className:"text-right text-muted-foreground",children:Ze})]})}),Kt&&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:Bt=>{Bt.stopPropagation(),C(je.info.id,cs)},"aria-label":e(Lt?"contextSidebar.actions.copied":"contextSidebar.actions.copyJson"),title:e(Lt?"contextSidebar.actions.copied":"contextSidebar.actions.copy"),children:Lt?s.jsx(I,{name:"check",className:"size-3.5"}):s.jsx(I,{name:"file-copy",className:"size-3.5"})})}),s.jsx(Rp,{language:"json",code:cs,style:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"var(--text-micro)",lineHeight:"1.35"},wrap:!0})]})})]},je.info.id)},t[186]=c,t[187]=o,t[188]=e,t[189]=n,t[190]=rt):rt=t[190],kt=[...p].reverse().map(rt),t[180]=c,t[181]=o,t[182]=p,t[183]=e,t[184]=n,t[185]=kt}else kt=t[185];let Ft;t[191]!==kt?(Ft=s.jsx("div",{className:"mt-2.5 space-y-1",children:kt}),t[191]=kt,t[192]=Ft):Ft=t[192];let Ht;t[193]!==Ot||t[194]!==Ft?(Ht=s.jsxs("div",{children:[Ot,Ft]}),t[193]=Ot,t[194]=Ft,t[195]=Ht):Ht=t[195];let Xt;return t[196]!==Ne||t[197]!==re||t[198]!==wt||t[199]!==Ut||t[200]!==Qe||t[201]!==Ht?(Xt=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:[Ne,re,wt,Ut,Qe,Ht]})}),t[196]=Ne,t[197]=re,t[198]=wt,t[199]=Ut,t[200]=Qe,t[201]=Ht,t[202]=Xt):Xt=t[202],Xt};function a1(t){return t.timeFormatPreference}function l1(t){return t.currentSessionId}function c1(t){return t.currentSessionDirectory}function d1(t){return t.providers}function u1(t){return Object.keys(t).length>0?{}:t}function f1(t){return gi(t.info).role==="assistant"}function m1(t){return gi(t.info).isUser}function h1(t,e){const n=to(e.info.cost);return t+n}function p1(t){return gi(t.info).isUser&&typeof t.info.system=="string"}function g1(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 x1(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)}%`:so(t.value):"—"})]},t.label)}const b1="x-openchamber-preview-target-error",y1=t=>{const e=t.get(b1);return e==="missing"||e==="expired"||e==="invalid-token"?e:null},w1=(t,e)=>y1(t)?e?"stop-retrying":"retry-registration":"none",uc=[{id:"context",descriptionKey:"contextRail.surface.context.description",defaultWidthFraction:.45,mode:"context",icon:"donut-chart-fill",labelKey:"contextPanel.mode.context",availability:"always"},{id:"git",descriptionKey:"contextRail.surface.git.description",defaultWidthFraction:2/5,mode:"git",icon:"git-branch",labelKey:"layout.rightSidebar.git",availability:"always"},{id:"pr",descriptionKey:"contextRail.surface.pr.description",defaultWidthFraction:.45,mode:"pr",icon:"github",labelKey:"contextPanel.mode.pr",availability:"always"},{id:"diff",descriptionKey:"contextRail.surface.diff.description",defaultWidthFraction:3/5,mode:"diff",icon:"arrow-left-right",labelKey:"contextPanel.mode.diff",availability:"always"},{id:"walkthrough",descriptionKey:"contextRail.surface.walkthrough.description",defaultWidthFraction:3/5,mode:"walkthrough",icon:"route",labelKey:"contextPanel.mode.walkthrough",availability:"always"},{id:"editor",descriptionKey:"contextRail.surface.editor.description",defaultWidthFraction:3/5,mode:"file",icon:"braces",labelKey:"contextPanel.mode.files",availability:"always"},{id:"terminal",descriptionKey:"contextRail.surface.terminal.description",defaultWidthFraction:3/5,mode:"terminal",icon:"terminal-box",labelKey:"layout.mainTab.terminal",availability:"always"},{id:"notes",descriptionKey:"contextRail.surface.notes.description",defaultWidthFraction:1/3,mode:"notes",icon:"sticky-note",labelKey:"contextRail.surface.notes",availability:"always"},{id:"plan",descriptionKey:"contextRail.surface.plan.description",defaultWidthFraction:.45,mode:"plan",icon:"file-text",labelKey:"contextPanel.mode.plan",availability:"always"},{id:"browser",descriptionKey:"contextRail.surface.browser.description",defaultWidthFraction:.45,mode:"browser",icon:"global",labelKey:"contextPanel.mode.browser",availability:"always"},{id:"preview",descriptionKey:"contextRail.surface.preview.description",defaultWidthFraction:.45,mode:"preview",icon:"window",labelKey:"contextPanel.mode.preview",availability:"has-content"},{id:"chat",descriptionKey:"contextRail.surface.chat.description",defaultWidthFraction:.45,mode:"chat",icon:"chat-4",labelKey:"contextPanel.mode.chat",availability:"has-content"}],ym=new Map(uc.map(t=>[t.id,t])),v1=new Map(uc.map(t=>[t.mode,t.defaultWidthFraction])),j1=t=>v1.get(t)??1/2,S1=t=>typeof t=="string"&&ym.has(t),$d=t=>{const e=[],n=new Set;for(const r of t){if(!S1(r)||n.has(r))continue;const o=ym.get(r);o&&(n.add(r),e.push(o))}for(const r of uc)n.has(r.id)||e.push(r);return e},k1=t=>{if(!t||typeof t!="object")return!1;const e=t;return typeof e.x=="number"&&typeof e.y=="number"},_d=t=>!t||typeof t!="object"?!1:Object.values(t).every(e=>typeof e=="string"),Co=t=>{if(!t||typeof t!="object")return!1;const e=t,n=e.bounds;return typeof e.tag=="string"&&typeof e.text=="string"&&typeof e.selector=="string"&&typeof e.path=="string"&&!!n&&typeof n?.x=="number"&&typeof n?.y=="number"&&typeof n?.width=="number"&&typeof n?.height=="number"&&k1(e.center)&&_d(e.attributes)&&_d(e.computedStyle)&&Array.isArray(e.ancestry)},fc=({pageUrl:t,viewport:e,devicePixelRatio:n,target:r,screenshotAttached:o,intro:i})=>{const c=r.text.trim(),l=Object.entries(r.attributes).map(([x,b])=>`${x}="${b}"`).join(" "),d=r.computedStyle,u=r.bounds,h=r.center,f=i.replace(/[.:]+$/g,""),p=r.ancestry.map(x=>x.selectorPart).join(" > ");return[`${f}:`,`Page: ${t||"preview"}`,`Viewport: ${e.width}x${e.height}, DPR ${n}`,`Screenshot: ${o?"attached":"not attached"}`,`Element: ${r.tag}`,c?`Text: ${c}`:null,`- Selector: ${r.selector}`,`- Path: ${r.path}`,p?`- Ancestry: ${p}`:null,l?`- Attributes: ${l}`:null,`- Bounds: x=${Math.round(u.x)}, y=${Math.round(u.y)}, width=${Math.round(u.width)}, height=${Math.round(u.height)}`,`- Center: x=${Math.round(h.x)}, y=${Math.round(h.y)}`,`Styles: display=${d.display}; position=${d.position}; font=${d.fontWeight} ${d.fontSize} / ${d.lineHeight} ${d.fontFamily}; color=${d.color}; background=${d.backgroundColor}; z-index=${d.zIndex}`].filter(x=>typeof x=="string").join(`
63
- `)},wm=async(t,e)=>{if(typeof window<"u")try{const n=t.getBoundingClientRect(),r=await Ar("desktop_capture_page_rect",{x:n.left,y:n.top,width:n.width,height:n.height});if(!r)throw new Error("Desktop screenshot capture is not available");const o=new Image;await new Promise((b,S)=>{o.onload=()=>b(),o.onerror=()=>S(new Error("Failed to load desktop preview screenshot")),o.src=`data:${r.mime};base64,${r.base64}`});const i=Math.max(1,o.naturalWidth||r.width||Math.floor(n.width)),c=Math.max(1,o.naturalHeight||r.height||Math.floor(n.height)),d=Math.min(1,1200/i),u=document.createElement("canvas");u.width=Math.floor(i*d),u.height=Math.floor(c*d);const h=u.getContext("2d");if(!h)return null;h.scale(d,d),h.drawImage(o,0,0,i,c);const f=i/Math.max(1,n.width),p=c/Math.max(1,n.height);h.fillStyle="rgba(37, 99, 235, 0.28)",h.strokeStyle="rgb(37, 99, 235)",h.lineWidth=Math.max(2,2*f),h.fillRect(e.bounds.x*f,e.bounds.y*p,e.bounds.width*f,e.bounds.height*p),h.strokeRect(e.bounds.x*f,e.bounds.y*p,e.bounds.width*f,e.bounds.height*p);const x=await new Promise(b=>u.toBlob(b,"image/jpeg",.82));return x?new File([x],`preview-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch(n){return console.warn("[preview] failed to capture annotation screenshot:",n),null}return await $1(t,e)},mc=async(t,e,n,r,o,i)=>{if(!t)return null;try{const c=new Image;await new Promise((g,m)=>{c.onload=()=>g(),c.onerror=()=>m(new Error("Failed to load desktop browser screenshot")),c.src=`data:image/jpeg;base64,${t}`});const l=Math.max(1,c.naturalWidth||e),d=Math.max(1,c.naturalHeight||n),h=Math.min(1,1200/l),f=document.createElement("canvas");f.width=Math.floor(l*h),f.height=Math.floor(d*h);const p=f.getContext("2d");if(!p)return null;p.scale(h,h),p.drawImage(c,0,0,l,d);const x=l/Math.max(1,r||l),b=d/Math.max(1,o||d);p.fillStyle="rgba(37, 99, 235, 0.14)",p.strokeStyle="rgb(37, 99, 235)",p.lineWidth=Math.max(2,2*x),p.fillRect(i.bounds.x*x,i.bounds.y*b,i.bounds.width*x,i.bounds.height*b),p.strokeRect(i.bounds.x*x,i.bounds.y*b,i.bounds.width*x,i.bounds.height*b);const S=await new Promise(g=>f.toBlob(g,"image/jpeg",.82));return S?new File([S],`browser-annotation-${Date.now()}.jpg`,{type:"image/jpeg"}):null}catch{return null}},Ao="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/p9sAAAAASUVORK5CYII=",An=new Map,tl=new Map,N1=3e4,hc=t=>{const e=An.get(t);return e?e.expiresAt-Date.now()<=N1?(An.delete(t),null):e:null},C1=t=>{try{return new URL(t).origin}catch{return t}};function vm(t){const e="#ffffff",n=t.defaultView??window;try{const r=t.body?n.getComputedStyle(t.body).backgroundColor:"";if(r&&r!=="rgba(0, 0, 0, 0)"&&r!=="transparent")return r;const o=n.getComputedStyle(t.documentElement).backgroundColor;if(o&&o!=="rgba(0, 0, 0, 0)"&&o!=="transparent")return o}catch{}return e}const jm=t=>new Promise((e,n)=>{const r=new FileReader;r.onloadend=()=>e(typeof r.result=="string"?r.result:Ao),r.onerror=()=>n(r.error??new Error("Failed to read image blob")),r.readAsDataURL(t)}),A1=async(t,e=.82)=>{const n=await new Promise(r=>t.toBlob(r,"image/jpeg",e));return n&&(await jm(n)).split(",",2)[1]||""},D1=()=>{try{return!!window.__previewCaptureDebug}catch{return!1}},Vi=(...t)=>{D1()&&console.info("[preview-capture]",...t)},Sm=(t,e=8)=>{const n=[];try{const r=t.querySelectorAll("*");for(const o of r){const i=o.scrollTop||0,c=o.scrollLeft||0;if(i<=0&&c<=0)continue;const l=o.tagName.toLowerCase(),d=o.id?`#${o.id}`:"",u=typeof o.className=="string"&&o.className?`.${o.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";if(n.push({selector:`${l}${d}${u}`,scrollTop:i,scrollLeft:c,clientWidth:o.clientWidth,clientHeight:o.clientHeight,scrollWidth:o.scrollWidth,scrollHeight:o.scrollHeight}),n.length>=e)break}}catch{}return n},ni="data-oc-fixed-pin",P1=(t,e,n)=>{if(e<=0&&n<=0)return()=>{};const r=t.defaultView;if(!r)return()=>{};const o=[],i=[];try{for(const c of t.querySelectorAll("*")){if(r.getComputedStyle(c).position!=="fixed")continue;const l=c.getBoundingClientRect();if(!(l.width>0&&l.height>0))continue;c.setAttribute(ni,JSON.stringify({top:l.top+n,left:l.left+e,width:l.width,height:l.height})),o.push(c);const d=c.tagName.toLowerCase(),u=typeof c.className=="string"&&c.className?`.${c.className.trim().split(/\s+/).slice(0,2).join(".")}`:"";i.push({selector:`${d}${u}`,top:Math.round(l.top),left:Math.round(l.left),width:Math.round(l.width),height:Math.round(l.height)})}}catch{}return Vi("tagged fixed elements",i),()=>{for(const c of o)try{c.removeAttribute(ni)}catch{}}},I1={name:"oc-fixed-pin",afterClone(t){const e=t?.clone;if(!(!e||typeof e.querySelectorAll!="function"))for(const n of e.querySelectorAll(`[${ni}]`)){let r;try{r=JSON.parse(n.getAttribute(ni)||"")}catch{continue}n.style.setProperty("position","absolute","important"),n.style.setProperty("top",`${r.top}px`,"important"),n.style.setProperty("left",`${r.left}px`,"important"),n.style.setProperty("right","auto","important"),n.style.setProperty("bottom","auto","important"),n.style.setProperty("width",`${r.width}px`,"important"),n.style.setProperty("height",`${r.height}px`,"important"),n.removeAttribute(ni)}}},jo="data-oc-scroll-pin",R1=t=>{const e=[],n=Sm(t,64);try{const i=t.documentElement,c=t.body;for(const l of t.querySelectorAll("*")){const d=l.scrollTop||0,u=l.scrollLeft||0;if(d<=0&&u<=0)continue;const h=l!==i&&l!==c;h&&l.setAttribute(jo,JSON.stringify({top:d,left:u})),e.push({el:l,top:d,left:u,tagged:h})}}catch{}return{reapply:()=>{for(const i of e)try{i.el.scrollHeight,i.el.scrollTop!==i.top&&(i.el.scrollTop=i.top),i.el.scrollLeft!==i.left&&(i.el.scrollLeft=i.left)}catch{}},cleanup:()=>{for(const i of e)if(i.tagged)try{i.el.removeAttribute(jo)}catch{}},snapshot:n}},M1={name:"oc-nested-scroll",afterClone(t){const e=t?.clone;if(!e||typeof e.querySelectorAll!="function")return;const n=e.ownerDocument;if(n)for(const r of e.querySelectorAll(`[${jo}]`)){let o;try{o=JSON.parse(r.getAttribute(jo)||"")}catch{r.removeAttribute(jo);continue}const i=`translate(${-o.left}px, ${-o.top}px)`,c=r.children.length===1&&r.firstElementChild instanceof HTMLElement&&r.firstElementChild.style.willChange==="transform"?r.firstElementChild:null;if(c)c.style.transform=i;else{r.style.overflow="hidden";const l=n.createElement("div");for(l.style.transform=i,l.style.willChange="transform",l.style.display="inline-block",l.style.width="100%";r.firstChild;)l.appendChild(r.firstChild);r.appendChild(l)}r.removeAttribute(jo)}}},sl=async(t,e)=>{try{const n=await fetch(t,{credentials:e});return n.ok?await jm(await n.blob()):null}catch{return null}},T1=async t=>{if(t.protocol!=="http:"&&t.protocol!=="https:")return"";const e=t.origin,n=hc(e);if(n)return`${n.proxyBasePath}${t.pathname}${t.search}${t.hash}`;const r=tl.get(e),o=r??(async()=>{try{const c=await hs("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:t.toString(),allowExternal:!0})});if(!c.ok)return An.delete(e),null;const l=await c.json(),d=typeof l.proxyBasePath=="string"?l.proxyBasePath:"",u=typeof l.expiresAt=="number"?l.expiresAt:0;if(!d)return An.delete(e),null;const h={proxyBasePath:d,expiresAt:u};return An.set(e,h),h}catch{return An.delete(e),null}finally{tl.delete(e)}})();r||tl.set(e,o);const i=await o;return i?`${i.proxyBasePath}${t.pathname}${t.search}${t.hash}`:""},km=async(t,e)=>{if(!t||t.startsWith("data:"))return t;try{const n=new URL(t,e.baseURI);if(n.origin===window.location.origin||n.protocol!=="http:"&&n.protocol!=="https:")return await sl(n.toString(),"include")??Ao;const r=await T1(n),o=r?await sl(r,"include"):null;return o||(await sl(n.toString(),"omit")??Ao)}catch{return Ao}},E1=async(t,e)=>{if(!t||t==="none"||!t.includes("url("))return t;const n=Array.from(t.matchAll(/url\((['"]?)(.*?)\1\)/g));let r=t;for(const o of n){const i=o[2]||"";if(!i||i.startsWith("data:"))continue;const c=await km(i,e);r=r.replace(o[0],`url("${c}")`)}return r},zd=t=>t.complete?Promise.resolve():new Promise(e=>{t.addEventListener("load",()=>e(),{once:!0}),t.addEventListener("error",()=>e(),{once:!0})}),Nm=t=>{const e=t.style.cssText;return()=>{t.style.cssText=e}},F1=t=>{const e=Number.parseFloat(t.lineHeight);if(Number.isFinite(e)&&e>0)return e;const n=Number.parseFloat(t.fontSize);return Number.isFinite(n)&&n>0?n*1.2:16},O1=(t,e,n)=>{const r=[],o=t.defaultView??window,c=Array.from(t.querySelectorAll('button, a, summary, label, [role="button"], [role="link"], [role="menuitem"], [role="tab"], nav *, header *'));for(const l of c){const d=l.textContent?.replace(/\s+/g," ").trim()??"";if(!d||!d.includes(" "))continue;const u=l.getBoundingClientRect();if(u.width<=0||u.height<=0||u.right<0||u.bottom<0||u.left>e||u.top>n)continue;const h=o.getComputedStyle(l);if(h.display==="none"||h.visibility==="hidden"||Number(h.opacity)===0)continue;const f=h.getPropertyValue("text-wrap"),p=h.getPropertyValue("text-wrap-mode"),x=h.whiteSpace.includes("nowrap")||f==="nowrap"||p==="nowrap",b=u.height<=F1(h)*1.7;!x&&(!b||u.width>e*.72)||(r.push(Nm(l)),l.style.whiteSpace="nowrap",l.style.overflowWrap="normal",l.style.wordBreak="normal",l.style.setProperty("text-wrap","nowrap"),l.style.setProperty("text-wrap-mode","nowrap"))}return()=>{for(let l=r.length-1;l>=0;l-=1)r[l]?.()}},L1=(t,e,n,r)=>{const o=[],i=t.defaultView??window,c=i.scrollX||t.documentElement.scrollLeft||t.body?.scrollLeft||0,l=i.scrollY||t.documentElement.scrollTop||t.body?.scrollTop||0,d=Array.from(t.querySelectorAll("*")).filter(u=>{const h=i.getComputedStyle(u);if(h.position!=="fixed"||h.display==="none"||h.visibility==="hidden"||Number(h.opacity)===0)return!1;const f=u.getBoundingClientRect();return f.width>0&&f.height>0&&f.right>=0&&f.bottom>=0&&f.left<=e&&f.top<=n}).filter((u,h,f)=>!f.some((p,x)=>x<h&&p.contains(u)));for(const u of d){const h=u.getBoundingClientRect(),f=i.getComputedStyle(u),p=Math.ceil(h.width)+8,x=Math.ceil(h.height)+2;r?.add(u),o.push(Nm(u)),u.style.position="absolute",u.style.top=`${h.top+l}px`,u.style.left=`${h.left+c}px`,u.style.right="auto",u.style.bottom="auto",u.style.width=`${p}px`,u.style.minWidth=`${p}px`,u.style.height=`${x}px`,u.style.minHeight=`${x}px`,u.style.margin="0",u.style.boxSizing="border-box",u.style.transform="none",f.zIndex!=="auto"&&(u.style.zIndex=f.zIndex)}return()=>{for(let u=o.length-1;u>=0;u-=1)o[u]?.()}},Cm=async(t,e,n,r={})=>{const o=[],i=t.defaultView??window,c=f=>{if(f===t.documentElement||f===t.body)return!0;try{const p=f.getBoundingClientRect();return p.width>0&&p.height>0&&p.right>=0&&p.bottom>=0&&p.left<=e&&p.top<=n}catch{return!1}};if(r.applyLayoutWorkarounds){const f=new WeakSet;o.push(L1(t,e,n,f)),o.push(O1(t,e,n))}const l=new Map;for(const f of Array.from(t.images))l.set(f,f.currentSrc||f.src||f.getAttribute("src")||"");const d=Array.from(t.querySelectorAll("picture"));for(const f of d){const p=Array.from(f.querySelectorAll("source"));if(p.length===0)continue;const x=p.map(b=>({source:b,srcset:b.getAttribute("srcset"),sizes:b.getAttribute("sizes")}));o.push(()=>{for(const b of x)b.srcset===null?b.source.removeAttribute("srcset"):b.source.setAttribute("srcset",b.srcset),b.sizes===null?b.source.removeAttribute("sizes"):b.source.setAttribute("sizes",b.sizes)});for(const b of p)b.removeAttribute("srcset"),b.removeAttribute("sizes")}const u=Array.from(t.images).filter(f=>c(f));await Promise.all(u.map(async f=>{const p=l.get(f)||f.currentSrc||f.src||f.getAttribute("src")||"";if(!p)return;await zd(f);const x=await km(p,t),b={src:f.getAttribute("src"),srcset:f.getAttribute("srcset"),sizes:f.getAttribute("sizes")};o.push(()=>{b.src===null?f.removeAttribute("src"):f.setAttribute("src",b.src),b.srcset===null?f.removeAttribute("srcset"):f.setAttribute("srcset",b.srcset),b.sizes===null?f.removeAttribute("sizes"):f.setAttribute("sizes",b.sizes)}),f.removeAttribute("srcset"),f.removeAttribute("sizes"),f.setAttribute("src",x||Ao),await zd(f)}));const h=Array.from(t.querySelectorAll("*")).filter(c);return await Promise.all(h.map(async f=>{const p=i.getComputedStyle(f).backgroundImage;if(!p||p==="none"||!p.includes("url("))return;const x=await E1(p,t);if(x===p)return;const b=f.style.backgroundImage;o.push(()=>{f.style.backgroundImage=b}),f.style.backgroundImage=x})),()=>{for(let f=o.length-1;f>=0;f-=1)try{o[f]?.()}catch{}}};async function B1(t,e){try{const n=t.contentWindow,r=t.contentDocument??n?.document,o=r?.documentElement;if(!n||!r||!o)return null;const i=t.getBoundingClientRect(),c=Math.max(1,Math.ceil(n.innerWidth||t.clientWidth||i.width)),l=Math.max(1,Math.ceil(n.innerHeight||t.clientHeight||i.height)),d=r.body,u=r.scrollingElement instanceof HTMLElement?r.scrollingElement:null,h=n.scrollX||0,f=n.scrollY||0,p=n.pageXOffset||0,x=n.pageYOffset||0,b=n.visualViewport?.pageLeft||n.visualViewport?.offsetLeft||0,S=n.visualViewport?.pageTop||n.visualViewport?.offsetTop||0,g=o.scrollLeft||0,m=o.scrollTop||0,y=d?.scrollLeft||0,C=d?.scrollTop||0,j=u?.scrollLeft||0,w=u?.scrollTop||0,N=Math.max(h,p,b,g,y,j),v=Math.max(f,x,S,m,C,w);Vi("scroll sources",{windowScrollX:h,windowScrollY:f,pageScrollX:p,pageScrollY:x,visualViewportScrollX:b,visualViewportScrollY:S,rootScrollX:g,rootScrollY:m,bodyScrollX:y,bodyScrollY:C,scrollingElementScrollX:j,scrollingElementScrollY:w,scrollingElementTag:u?.tagName?.toLowerCase()??null,resolvedScrollX:N,resolvedScrollY:v,nestedScrolledElements:Sm(r)});const P=Math.max(c,o.scrollWidth||0,d?.scrollWidth||0,Math.ceil(o.getBoundingClientRect().width||0)),F=Math.max(l,o.scrollHeight||0,d?.scrollHeight||0,Math.ceil(o.getBoundingClientRect().height||0)),k=Math.min(2,Math.max(1,window.devicePixelRatio||1)),E=o.style.scrollBehavior,O=d?.style.scrollBehavior??"";o.style.scrollBehavior="auto",d&&(d.style.scrollBehavior="auto");const M=R1(r);Vi("nested scroll snapshot",M.snapshot);let L=()=>{},_=()=>{};try{await r.fonts?.ready.catch(()=>{}),L=await Cm(r,c,l,{applyLayoutWorkarounds:!1}),n.scrollTo(N,v),_=P1(r,N,v),M.reapply();const{snapdom:D}=await Oo(async()=>{const{snapdom:pe}=await import("./vendor-zumer-snapdom-Btyu_Xi2.js");return{snapdom:pe}},[]),A={backgroundColor:vm(r),cache:"disabled",dpr:k,embedFonts:!0,fast:!1,height:F,outerShadows:!0,outerTransforms:!0,placeholders:!0,plugins:[I1,M1],quality:.82,width:P},z=await(await D(o,A)).toCanvas();if(!z.width||!z.height)return null;const R=z.width/Math.max(1,P),W=z.height/Math.max(1,F),J=Math.min(z.width,Math.max(1,Math.round(c*R))),U=Math.min(z.height,Math.max(1,Math.round(l*W))),te=Math.max(0,z.width-J),Z=Math.max(0,z.height-U),ue=Math.min(te,Math.max(0,Math.round(N*R))),Oe=Math.min(Z,Math.max(0,Math.round(v*W)));Vi("capture geometry",{viewportWidth:c,viewportHeight:l,captureWidth:P,captureHeight:F,canvasWidth:z.width,canvasHeight:z.height,xScale:R,yScale:W,sourceX:ue,sourceY:Oe,sourceWidth:J,sourceHeight:U});const se=r.createElement("canvas");se.width=J,se.height=U;const G=se.getContext("2d");if(!G)return null;G.drawImage(z,ue,Oe,J,U,0,0,J,U);const Ie=await A1(se,.82);return Ie?await mc(Ie,c,l,c,l,e):null}finally{_(),M.cleanup(),L(),n.scrollTo(N,v),M.reapply(),o.style.scrollBehavior=E,d&&(d.style.scrollBehavior=O)}}catch(n){return console.warn("[preview] failed to capture iframe DOM screenshot with snapDOM:",n),null}}async function $1(t,e){const n=await B1(t,e);if(n)return n;try{const r=t.contentWindow,o=t.contentDocument??r?.document,i=o?.documentElement;if(!r||!o||!i)return null;const c=t.getBoundingClientRect(),l=Math.max(1,Math.ceil(r.innerWidth||t.clientWidth||c.width)),d=Math.max(1,Math.ceil(r.innerHeight||t.clientHeight||c.height)),u=r.scrollX||o.documentElement.scrollLeft||o.body?.scrollLeft||0,h=r.scrollY||o.documentElement.scrollTop||o.body?.scrollTop||0,f=o.body,p=Math.max(d,i.scrollHeight||0,f?.scrollHeight||0),x=Math.min(2,Math.max(1,window.devicePixelRatio||1)),b=i.style.scrollBehavior,S=f?.style.scrollBehavior??"";i.style.scrollBehavior="auto",f&&(f.style.scrollBehavior="auto");let g="",m=()=>{};try{await o.fonts?.ready.catch(()=>{}),m=await Cm(o,l,d,{applyLayoutWorkarounds:!0}),r.scrollTo(u,h);const{getFontEmbedCSS:C,toJpeg:j}=await Oo(async()=>{const{getFontEmbedCSS:N,toJpeg:v}=await import("./vendor-html-to-image-BeoRn2gJ.js");return{getFontEmbedCSS:N,toJpeg:v}},[]),w=await C(i).catch(()=>"");g=await j(i,{quality:.82,pixelRatio:x,width:l,height:d,backgroundColor:vm(o),imagePlaceholder:Ao,fontEmbedCSS:w||void 0,style:{transform:`translate(${-u}px, ${-h}px)`,transformOrigin:"top left",minWidth:`${l}px`,minHeight:`${p}px`},cacheBust:!0})}finally{m(),r.scrollTo(u,h),i.style.scrollBehavior=b,f&&(f.style.scrollBehavior=S)}const y=g.split(",",2)[1]||"";return y?await mc(y,l,d,l,d,e):null}catch(r){return console.warn("[preview] failed to capture iframe DOM screenshot:",r),null}}const _1=380,z1=1400,Am=600,V1=100,W1=24,la=new Map,Vd=200,U1=(t,e)=>e==="all"?!0:e==="errors"?t.level==="error"||t.level==="runtime"||t.level==="resource":e==="warnings"?t.level==="warn":t.level==="log"||t.level==="info"||t.level==="debug",H1=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},Wd=t=>Number.isFinite(t)?Math.min(z1,Math.max(_1,Math.round(t))):Am,K1=t=>{const e=t?.parentElement?.clientWidth;return!e||e<=0?null:e},G1=(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},Dm=(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==="preview"?"contextPanel.mode.preview":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"),q1=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=Wi(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")}if(t.label)return t.label;if(t.mode==="file")return q1(t.targetPath)||n("contextPanel.mode.files");if(t.mode==="preview"){const r=t.targetPath;if(r)try{const o=new URL(r);return o.host||o.hostname||n("contextPanel.mode.preview")}catch{}return n("contextPanel.mode.preview")}return t.mode==="diff"?n("contextPanel.mode.diff"):Dm(t.mode,n)},Ud=t=>{if(t.mode==="file")return t.targetPath?s.jsx(Lo,{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==="preview")return s.jsx(I,{name:"global",className:"h-3.5 w-3.5 text-[var(--status-info)]"});if(t.mode==="browser")return s.jsx(I,{name:"global",className:"h-3.5 w-3.5"})},Q1=200,X1=480,J1=({visible:t})=>{const{t:e}=ft(),n=Re(m=>m.contextEditorTreeWidth),r=Re(m=>m.setContextEditorTreeWidth),[o,i]=a.useState(!1),c=a.useRef(0),l=a.useRef(n),d=a.useRef(null),u=a.useRef(null),h=a.useRef(null),f=a.useCallback(m=>Math.min(X1,Math.max(Q1,Math.round(m))),[]),p=a.useCallback(m=>{const y=h.current;y&&(y.style.width=`${m}px`,y.style.setProperty("--oc-editor-tree-width",`${m}px`))},[]),x=m=>{if(t){try{m.currentTarget.setPointerCapture(m.pointerId)}catch{}u.current=m.pointerId,i(!0),c.current=m.clientX,l.current=n,d.current=n,m.preventDefault()}},b=m=>{if(!o||u.current!==m.pointerId)return;const y=c.current-m.clientX,C=f(l.current+y);d.current!==C&&(d.current=C,p(C))},S=m=>{if(u.current!==m.pointerId)return;try{m.currentTarget.releasePointerCapture(m.pointerId)}catch{}const y=f(d.current??n);u.current=null,d.current=null,i(!1),r(y)},g=t?n:0;return s.jsxs("div",{ref:h,className:De("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:De("absolute left-0 top-0 z-20 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",o&&"bg-[var(--interactive-border)]"),onPointerDown:x,onPointerMove:b,onPointerUp:S,onPointerCancel:S,role:"separator","aria-orientation":"vertical","aria-label":e("contextPanel.actions.resizePanelAria")}),s.jsx("div",{className:De("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(Wv,{})})]})},Wi=t=>!t||!t.startsWith("session:")?null:t.slice(8).trim()||null,Z1=(t,e)=>{if(t.size!==e.size)return!1;for(const[n,r]of t)if(e.get(n)!==r)return!1;return!0},ej=(t,e)=>{if(e.length===0)return la;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?la:r},tj=(t,e)=>{const n=$l(t),r=a.useRef(la),o=a.useRef(e);return o.current=e,a.useSyncExternalStore(n.subscribe,a.useCallback(()=>{const i=ej(n.getState().session,o.current);return Z1(r.current,i)?r.current:(r.current=i,i)},[n]),()=>la)},Pm=`new Promise((resolve) => {
64
- const existing = document.getElementById('__openchamber_desktop_browser_overlay');
65
- if (existing) existing.remove();
66
- if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
67
- try { window.__openchamberDesktopBrowserCancelInspect(); } catch { /* webview not ready */ }
68
- }
69
- const overlay = document.createElement('div');
70
- overlay.id = '__openchamber_desktop_browser_overlay';
71
- overlay.style.cssText = 'position:fixed;z-index:2147483647;pointer-events:none;border:2px solid #60a5fa;background:rgba(96,165,250,.24);border-radius:3px;display:none;box-sizing:border-box;';
72
- document.documentElement.appendChild(overlay);
73
- const cssEscape = (value) => {
74
- try { return CSS.escape(value); } catch { return String(value).replace(/[^a-zA-Z0-9_-]/g, '\\\\$&'); }
75
- };
76
- const selectorPart = (element) => {
77
- const tag = element.tagName.toLowerCase();
78
- if (element.id) return tag + '#' + cssEscape(element.id);
79
- const className = String(element.className || '').trim().split(/\\s+/).filter(Boolean).slice(0, 3).map((part) => '.' + cssEscape(part)).join('');
80
- return tag + className;
81
- };
82
- const metadata = (element) => {
83
- const rect = element.getBoundingClientRect();
84
- const style = getComputedStyle(element);
85
- const ancestry = [];
86
- let current = element;
87
- while (current && current.nodeType === Node.ELEMENT_NODE && ancestry.length < 8) {
88
- ancestry.unshift({ tag: current.tagName.toLowerCase(), id: current.id || undefined, className: typeof current.className === 'string' ? current.className : undefined, selectorPart: selectorPart(current) });
89
- current = current.parentElement;
90
- }
91
- const attrs = {};
92
- for (const attr of Array.from(element.attributes || []).slice(0, 16)) attrs[attr.name] = attr.value.slice(0, 300);
93
- const path = ancestry.map((entry) => entry.selectorPart).join(' > ');
94
- return {
95
- frame: 'top',
96
- tag: element.tagName.toLowerCase(),
97
- text: String(element.innerText || element.textContent || '').replace(/\\s+/g, ' ').trim().slice(0, 500),
98
- selector: element.id ? '#' + cssEscape(element.id) : path,
99
- path,
100
- bounds: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
101
- center: { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 },
102
- attributes: attrs,
103
- computedStyle: { display: style.display, position: style.position, fontWeight: style.fontWeight, fontSize: style.fontSize, lineHeight: style.lineHeight, fontFamily: style.fontFamily, color: style.color, backgroundColor: style.backgroundColor, zIndex: style.zIndex },
104
- ancestry,
105
- };
106
- };
107
- const move = (event) => {
108
- const element = document.elementFromPoint(event.clientX, event.clientY);
109
- if (!element || element === overlay || element === document.documentElement || element === document.body) return;
110
- const rect = element.getBoundingClientRect();
111
- overlay.style.display = 'block';
112
- overlay.style.left = rect.left + 'px';
113
- overlay.style.top = rect.top + 'px';
114
- overlay.style.width = rect.width + 'px';
115
- overlay.style.height = rect.height + 'px';
116
- };
117
- const cleanup = () => {
118
- window.removeEventListener('mousemove', move, true);
119
- window.removeEventListener('click', click, true);
120
- window.removeEventListener('keydown', keydown, true);
121
- if (window.__openchamberDesktopBrowserCancelInspect === cancel) {
122
- delete window.__openchamberDesktopBrowserCancelInspect;
123
- }
124
- };
125
- const cancel = () => {
126
- cleanup();
127
- overlay.remove();
128
- resolve(null);
129
- };
130
- const click = (event) => {
131
- event.preventDefault();
132
- event.stopPropagation();
133
- const element = document.elementFromPoint(event.clientX, event.clientY);
134
- const result = element ? metadata(element) : null;
135
- cleanup();
136
- overlay.remove();
137
- resolve(result);
138
- };
139
- const keydown = (event) => {
140
- if (event.key !== 'Escape') return;
141
- cancel();
142
- };
143
- window.__openchamberDesktopBrowserCancelInspect = cancel;
144
- window.addEventListener('mousemove', move, true);
145
- window.addEventListener('click', click, true);
146
- window.addEventListener('keydown', keydown, true);
147
- });`,Ui=`(() => {
148
- if (typeof window.__openchamberDesktopBrowserCancelInspect === 'function') {
149
- window.__openchamberDesktopBrowserCancelInspect();
150
- return;
151
- }
152
- const overlay = document.getElementById('__openchamber_desktop_browser_overlay');
153
- if (overlay) overlay.remove();
154
- })()`,sj=`(() => {
155
- if (window.__openchamberSameWebviewNavigationInstalled) return;
156
- window.__openchamberSameWebviewNavigationInstalled = true;
157
-
158
- const navigate = (rawUrl) => {
159
- if (typeof rawUrl !== 'string' || rawUrl.length === 0) return false;
160
- try {
161
- const url = new URL(rawUrl, window.location.href);
162
- if (url.protocol !== 'http:' && url.protocol !== 'https:') return false;
163
- window.location.assign(url.href);
164
- return true;
165
- } catch (_error) {
166
- return false;
167
- }
168
- };
169
-
170
- const originalOpen = window.open.bind(window);
171
- window.open = (url, target, features) => {
172
- if (navigate(url)) return null;
173
- return originalOpen(url, target, features);
174
- };
175
-
176
- document.addEventListener('click', (event) => {
177
- if (event.defaultPrevented) return;
178
- const target = event.target;
179
- if (!(target instanceof Element)) return;
180
- const anchor = target.closest('a[target="_blank"][href]');
181
- if (!(anchor instanceof HTMLAnchorElement)) return;
182
- if (!navigate(anchor.href)) return;
183
- event.preventDefault();
184
- event.stopPropagation();
185
- }, true);
186
- })()`,ri=t=>{const e=t.trim();if(!e)return"about:blank";try{const n=new URL(e.includes("://")?e:`https://${e}`);return n.protocol!=="http:"&&n.protocol!=="https:"?"about:blank":n.toString()}catch{return"about:blank"}},Hd=async(t,e)=>{const n=t.contentWindow;if(!n)throw new Error("Iframe window is not available");const o=n.eval.call(n,e);return await Promise.resolve(o)},nj=(t,e)=>t.length<=e?t:`${t.slice(0,e-3)}...`,Im=t=>{if(typeof window>"u")return"";try{return new URL(t||window.location.href,window.location.href).origin}catch{return window.location.origin}},Kd=(t,e,n)=>{const r=Im(e);t.postMessage(n,r)},rj=t=>{if(!t)return t;try{const e=new URL(t);return e.searchParams.delete("oc_preview_token"),e.searchParams.delete("oc_client_token"),e.searchParams.delete("oc_url_token"),e.toString()}catch{return t}},Gd=t=>{if(!t)return t;try{const e=new URL(t);return e.searchParams.delete("ocPreview"),e.searchParams.delete("oc_preview_token"),e.searchParams.delete("oc_client_token"),e.searchParams.delete("oc_url_token"),e.toString()}catch{return t}},oj=({rawUrl:t,onNavigate:e})=>{const{t:n}=ft(),{currentTheme:r}=co(),[o,i]=a.useReducer(X=>X+1,0),[c,l]=a.useReducer(X=>X+1,0),[d,u]=a.useState({status:"idle"}),[h,f]=a.useState(""),p=a.useRef(null),x=a.useRef(1),[b,S]=a.useState(!1),[g,m]=a.useState(!1),[y,C]=a.useState("all"),[j,w]=a.useState([]),[N,v]=a.useState(!1),[P,F]=a.useState(null),k=et(X=>X.currentSessionId),E=et(X=>X.newSessionDraft?.open),O=Wr(),M=ci(X=>X.addDraft),L=lo(X=>X.addAttachedFile);let _=null;try{_=t?new URL(t):null}catch{_=null}const D=_?_.hostname==="localhost"||_.hostname==="127.0.0.1"||_.hostname==="::1"||_.hostname==="[::1]"||_.hostname==="0.0.0.0":!1,A=_?_.hostname==="0.0.0.0"?new URL(_.toString().replace("0.0.0.0","127.0.0.1")):_:null,T=A?A.toString():"",z=T?`${Cr()||"same-origin"}|${T}`:"",R=r.metadata.variant;a.useEffect(()=>{if(!T||!D){u({status:"idle"});return}const X=hc(z);if(X?.previewToken){u({status:"ready",proxyBasePath:X.proxyBasePath,previewToken:X.previewToken,expiresAt:X.expiresAt});return}X&&An.delete(z);let Ne=!1;return u({status:"loading"}),(async()=>{try{const Ae=await hs("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:T})});if(!Ae.ok){An.delete(z);const ve=await Ae.json().catch(()=>({})),K=typeof ve?.error=="string"?ve.error:`HTTP ${Ae.status}`;Ne||u({status:"error",message:K});return}const Se=await Ae.json(),le=typeof Se.proxyBasePath=="string"?Se.proxyBasePath:"",ee=typeof Se.previewToken=="string"?Se.previewToken:"",ie=typeof Se.expiresAt=="number"?Se.expiresAt:0;if(!le||!ee){An.delete(z),Ne||u({status:"error",message:n("contextPanel.preview.proxyError")});return}An.set(z,{proxyBasePath:le,previewToken:ee,expiresAt:ie}),Ne||u({status:"ready",proxyBasePath:le,previewToken:ee,expiresAt:ie})}catch(Ae){if(An.delete(z),!Ne){const Se=Ae instanceof Error?Ae.message:String(Ae);u({status:"error",message:Se})}}})(),()=>{Ne=!0}},[D,z,c,n,T]);const W=A&&(A.protocol==="http:"||A.protocol==="https:")?A.toString():"",J=D&&d.status==="ready"?`${d.proxyBasePath}|${d.previewToken||""}|${o}`:"";a.useEffect(()=>{if(!J){f("");return}let X=!1;return f(""),qu(Cr()).then(Ne=>{!X&&Ne&&f(J)}).catch(()=>{}),()=>{X=!0}},[J]);const U=D&&d.status==="ready"&&A&&h===J?(()=>{const X=A.pathname||"/",Ne=new URLSearchParams(A.search);Ne.delete("oc_url_token"),Ne.delete("oc_client_token"),Ne.set("ocPreview",String(o)),Ne.set("oc_preview_token",d.previewToken||"");const Ae=Ne.toString(),Se=A.hash||"";return ha().authenticatedAsset(`${d.proxyBasePath}${X}${Ae?`?${Ae}`:""}${Se}`)})():"",te=D?U:W,Z=D?rj(U):W,ue=D&&(d.status==="loading"||d.status==="idle"||h!==J),Oe=D&&d.status==="error",se=a.useCallback(X=>{const Ne=k??(E?"draft":null);if(!Ne||!O){fe.error(n("contextPanel.preview.inspect.attachNoSession"));return}const Ae=t||te||"",Se=typeof window<"u"?{width:window.innerWidth,height:window.innerHeight}:{width:0,height:0},le=typeof window<"u"?window.devicePixelRatio:1;(async()=>{let ee=!1;try{const ie=p.current,ve=ie?await wm(ie,X):null;ve&&(await L(ve),ee=!0)}catch{ee=!1}M({directory:O,sessionKey:Ne},{source:"preview-annotation",fileLabel:Ae||"preview",startLine:1,endLine:1,code:fc({pageUrl:Ae,viewport:Se,devicePixelRatio:le,target:X,screenshotAttached:ee,intro:n("contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),fe.success(n("contextPanel.preview.inspect.attached"))})()},[L,M,k,O,te,E,t,n]);a.useEffect(()=>{S(!1),w([]),m(!1),C("all"),v(!1),F(null),x.current=1},[te]),a.useEffect(()=>{const X=p.current?.contentWindow;!b||!X||Kd(X,U,{source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:N})},[b,N,U]),a.useEffect(()=>{const X=p.current?.contentWindow;!b||!X||Kd(X,U,{source:"openchamber-preview-parent",version:1,type:"set-color-scheme",scheme:R})},[b,R,U]),a.useEffect(()=>{if(!N||typeof window>"u")return;const X=Ne=>{Ne.key==="Escape"&&(Ne.preventDefault(),Ne.stopImmediatePropagation(),v(!1))};return window.addEventListener("keydown",X,!0),()=>window.removeEventListener("keydown",X,!0)},[N]),a.useEffect(()=>{if(!D||typeof window>"u")return;const X=Se=>{if(typeof Se=="string")return Se;if(Se==null)return"";try{return JSON.stringify(Se)}catch{return String(Se)}},Ne=Se=>{const le=x.current;x.current+=1,w(ee=>{const ie=[...ee,{...Se,id:le}];return ie.length>Vd?ie.slice(ie.length-Vd):ie})},Ae=Se=>{if(Se.source!==p.current?.contentWindow)return;const le=Se.data;if(!(!le||le.source!=="openchamber-preview-bridge"||le.version!==1)){if(le.type==="ready"){S(!0);return}if(le.type==="console"){const ee=le.level==="error"||le.level==="warn"||le.level==="info"||le.level==="debug"?le.level:"log",ie=Array.isArray(le.args)?le.args.map(X).filter(Boolean):[];Ne({level:ee,message:ie.join(" "),ts:typeof le.ts=="number"?le.ts:Date.now()});return}if(le.type==="runtime-error"){const ee=X(le.filename),ie=typeof le.line=="number"?le.line:null,ve=typeof le.column=="number"?le.column:null,K=ee?`${ee}${ie!==null?`:${ie}${ve!==null?`:${ve}`:""}`:""}`:"",de=X(le.stack);Ne({level:"runtime",message:X(le.message)||n("contextPanel.preview.console.runtimeError"),details:[K,de].filter(Boolean).join(`
187
- `),ts:typeof le.ts=="number"?le.ts:Date.now()});return}if(le.type==="resource-error"){const ee=X(le.tag)||"resource",ie=X(le.url);Ne({level:"resource",message:ie?`${ee}: ${ie}`:ee,details:X(le.outerHTML),ts:typeof le.ts=="number"?le.ts:Date.now()});return}if(le.type==="hover"){F(Co(le.target)?le.target:null);return}if(le.type==="select"&&Co(le.target)){F(le.target),v(!1),se(le.target);return}if(le.type==="navigate-preview"){const ee=typeof le.url=="string"?le.url:"",ie=le.navigation==="external"?"external":"proxy";if(ee&&ie==="external"){Io(ee);return}ee&&e(ee)}}};return window.addEventListener("message",Ae),()=>{window.removeEventListener("message",Ae)}},[se,D,e,n]);const G=j.filter(X=>X.level==="error"||X.level==="runtime"||X.level==="resource").length,Ie=j.filter(X=>U1(X,y)),pe=a.useCallback(()=>{const X=[`Preview URL: ${t||te||""}`,`Events: ${j.length}`,""].join(`
188
- `),Ne=j.map(Ae=>{const Se=new Date(Ae.ts).toISOString(),le=Ae.details?`
189
- ${Ae.details}`:"";return`[${Se}] [${Ae.level}] ${Ae.message}${le}`}).join(`
190
- `);rr(`${X}${Ne}`).then(Ae=>{Ae.ok?fe.success(n("contextPanel.preview.console.copied")):fe.error(n("contextPanel.preview.console.copyFailed"))})},[j,te,t,n]),V=a.useCallback(()=>{const X=k??(E?"draft":null);if(!X||!O){fe.error(n("contextPanel.preview.console.attachNoSession"));return}const Ne=[`Preview URL: ${t||te||""}`,`Events: ${j.length}`,""].join(`
191
- `),Ae=j.map(Se=>{const le=new Date(Se.ts).toISOString(),ee=Se.details?`
192
- ${Se.details}`:"";return`[${le}] [${Se.level}] ${Se.message}${ee}`}).join(`
193
- `);M({directory:O,sessionKey:X},{source:"preview-console",fileLabel:t||te||"preview",startLine:1,endLine:Math.max(1,j.length),code:`${Ne}${Ae}`,language:"text",text:n("contextPanel.preview.console.attachAnnotation")}),fe.success(n("contextPanel.preview.console.attached"))},[M,j,k,O,te,E,t,n]),[Q,ne]=a.useState("unknown"),oe=a.useRef(0),ce=a.useRef(0),ke=a.useRef(""),ye=a.useRef(""),he=15e3;a.useEffect(()=>{if(!U){ne("unknown"),ke.current="",oe.current=0,ce.current=0;return}let X=!1,Ne=null;ke.current!==z&&(ke.current=z,oe.current=Date.now(),ce.current=0);const Ae=Se=>{Ne=setTimeout(()=>{X||i()},Se)};return ne("unknown"),(async()=>{const le=await(async()=>{try{return await hs(U,{method:"GET",credentials:"include",cache:"no-store",redirect:"manual"})}catch{return null}})();if(X)return;if(!le){ne("unreachable"),Ae(5e3);return}const ee=w1(le.headers,ye.current===z);if(ee!=="none"){if(An.delete(z),ee==="retry-registration")ye.current=z,u({status:"loading"}),l();else{const K=await le.json().catch(()=>({}));if(X)return;const de=typeof K?.error=="string"?K.error:`HTTP ${le.status}`;u({status:"error",message:de})}return}if(le.status!==502){ye.current="",ne("reachable");return}const ie=oe.current||Date.now();if(Date.now()-ie<he){ne("starting"),ce.current+=1;const K=ce.current,de=Math.min(2e3,250*Math.pow(2,Math.min(4,K)));Ae(de);return}ne("unreachable"),Ae(5e3)})(),()=>{X=!0,Ne&&clearTimeout(Ne)}},[z,U,o]);const Ee=D&&d.status==="ready"&&(Q==="unknown"||Q==="starting"),Ue=D&&d.status==="ready"&&Q==="unreachable",Me=a.useCallback(X=>{if(!D||d.status!=="ready"||typeof window>"u")return;const Ne=X.currentTarget.contentWindow;if(Ne)try{const Ae=Ne.location,Se=Im(U);if(Ae.origin!==Se||Ae.pathname.startsWith(d.proxyBasePath))return;const le=`${d.proxyBasePath}${Ae.pathname}${Ae.search}${Ae.hash}`;Ne.location.replace(le)}catch{}},[D,U,d]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[s.jsx("div",{className:"min-w-0 flex-1 truncate typography-micro text-muted-foreground",title:Z||t,children:Z||t||n("contextPanel.preview.empty")}),s.jsx(He,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>i(),title:n("contextPanel.preview.actions.reload"),"aria-label":n("contextPanel.preview.actions.reload"),disabled:!te,children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx(He,{type:"button",size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{W&&Io(W)},title:n("contextPanel.preview.actions.openExternal"),"aria-label":n("contextPanel.preview.actions.openExternal"),disabled:!W,children:s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"})}),D?s.jsx(He,{type:"button",size:"sm",variant:N?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>v(X=>!X),title:n("contextPanel.preview.inspect.toggle"),"aria-label":n("contextPanel.preview.inspect.toggle"),disabled:!b,children:s.jsx(I,{name:"cursor",className:"h-3.5 w-3.5"})}):null,D?s.jsxs(He,{type:"button",size:"sm",variant:g?"secondary":"ghost",className:"h-7 gap-1 px-2",onClick:()=>m(X=>!X),title:n(b?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),"aria-label":n(b?"contextPanel.preview.console.open":"contextPanel.preview.console.waiting"),disabled:!b&&j.length===0,children:[s.jsx(I,{name:"terminal-box",className:"h-3.5 w-3.5"}),G>0?s.jsx("span",{className:"typography-micro text-status-error",children:G}):null]}):null]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[Ee?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.startingServer")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.startingServerHint")})]}):Ue?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.upstreamUnreachable")}),s.jsx("div",{className:"text-xs opacity-70",children:n("contextPanel.preview.upstreamUnreachableHint")}),s.jsx(He,{type:"button",size:"sm",variant:"outline",onClick:()=>i(),children:n("contextPanel.preview.actions.retry")})]}):te&&(!D||Q==="reachable")?s.jsxs("div",{className:"relative h-full w-full",children:[s.jsx("iframe",{ref:p,src:te,title:n("contextPanel.preview.iframeTitle"),className:"h-full w-full border-0",style:{colorScheme:R},onLoad:Me,sandbox:D?"allow-scripts allow-same-origin allow-forms allow-popups allow-downloads":"allow-scripts allow-forms"},`${te}:${o}`),N&&P?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:P.bounds.x,top:P.bounds.y,width:P.bounds.width,height:P.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[P.tag,P.text?` · ${P.text}`:""]})}):null]}):ue?s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.loading")}):Oe?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 text-sm text-muted-foreground",children:[s.jsx("div",{children:n("contextPanel.preview.proxyError")}),d.status==="error"?s.jsx("div",{className:"text-center text-xs opacity-70",children:d.message}):null]}):s.jsx("div",{className:"flex h-full items-center justify-center px-6 text-sm text-muted-foreground",children:n("contextPanel.preview.invalidUrl")}),g?s.jsxs("div",{className:"absolute inset-x-3 bottom-3 z-10 max-h-[45%] overflow-hidden rounded-xl border border-border/70 bg-[var(--surface-elevated)] shadow-lg",children:[s.jsxs("div",{className:"flex items-center justify-between border-b border-border/50 px-3 py-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:n("contextPanel.preview.console.title")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(He,{type:"button",size:"xs",variant:"ghost",onClick:V,disabled:j.length===0,children:n("contextPanel.preview.console.attach")}),s.jsx(He,{type:"button",size:"xs",variant:"ghost",onClick:pe,disabled:j.length===0,children:n("contextPanel.preview.console.copy")}),s.jsx(He,{type:"button",size:"xs",variant:"ghost",onClick:()=>w([]),disabled:j.length===0,children:n("contextPanel.preview.console.clear")})]})]}),s.jsx("div",{className:"flex items-center gap-1 border-b border-border/30 px-3 py-1.5",children:["all","errors","warnings","logs"].map(X=>s.jsx(He,{type:"button",size:"xs",variant:y===X?"secondary":"ghost",onClick:()=>C(X),children:n(X==="all"?"contextPanel.preview.console.filter.all":X==="errors"?"contextPanel.preview.console.filter.errors":X==="warnings"?"contextPanel.preview.console.filter.warnings":"contextPanel.preview.console.filter.logs")},X))}),s.jsx("div",{className:"max-h-64 overflow-auto p-2 typography-code text-xs",children:j.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.empty")}):Ie.length===0?s.jsx("div",{className:"px-2 py-3 text-muted-foreground",children:n("contextPanel.preview.console.noFilteredEvents")}):Ie.map(X=>s.jsx("div",{className:"border-b border-border/30 px-2 py-1 last:border-b-0",children:s.jsxs("div",{className:"flex gap-2",children:[s.jsx("span",{className:De("shrink-0 uppercase",X.level==="error"||X.level==="runtime"||X.level==="resource"?"text-status-error":X.level==="warn"?"text-status-warning":"text-muted-foreground"),children:X.level}),s.jsx("span",{className:"min-w-0 break-words text-foreground",children:X.message})]})},X.id))})]}):null]})]})},ij=()=>typeof window<"u"&&!!window.__OPENCHAMBER_ELECTRON__,aj=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=ft(),o=a.useRef(null),i=Re(V=>V.setContextPanelTabTargetPath),c=ri(t),l=c!=="about:blank"?c:"",[d,u]=a.useState(l),[h,f]=a.useState(l),[p,x]=a.useState(l),[b,S]=a.useState(()=>l?[l]:[]),[g,m]=a.useState(()=>l?0:-1),[y,C]=a.useReducer(V=>V+1,0),[j,w]=a.useState(!!l),[N,v]=a.useState(!1),[P,F]=a.useState(null),[k,E]=a.useState({status:"idle"}),[O,M]=a.useState(""),L=et(V=>V.currentSessionId),_=et(V=>V.newSessionDraft?.open),D=ci(V=>V.addDraft),A=lo(V=>V.addAttachedFile),T=a.useCallback(V=>{!V||V==="about:blank"||!e||!n||i(e,n,V)},[e,n,i]),z=a.useCallback((V,Q)=>{const ne=ri(V),oe=ne!=="about:blank"?ne:"";f(oe),u(oe),Q?.inFrame?w(!1):(x(oe),w(!!oe)),T(oe),S(ce=>{if(!oe)return m(-1),[];if(Q?.replaceHistory)return ce;const ke=g>=0?ce.slice(0,g+1):[];if(ke[ke.length-1]===oe)return m(ke.length-1),ke;const he=[...ke,oe];return m(he.length-1),he})},[g,T]),R=a.useCallback(V=>{const Q=b[V];Q&&(m(V),f(Q),x(Q),u(Q),w(!0),T(Q))},[b,T]),W=a.useCallback(()=>{if(h){w(!0);try{o.current?.contentWindow?.location.reload()}catch{C()}}},[h]);a.useEffect(()=>{if(!p){E({status:"idle"});return}const V=C1(p),Q=hc(V);if(Q?.previewToken){E({status:"ready",proxyBasePath:Q.proxyBasePath,previewToken:Q.previewToken,expiresAt:Q.expiresAt});return}Q&&An.delete(V);let ne=!1;return E({status:"loading"}),w(!0),(async()=>{try{const oe=await hs("/api/preview/targets",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:p,allowExternal:!0})});if(!oe.ok){const Ee=await oe.json().catch(()=>({})),Ue=typeof Ee?.error=="string"?Ee.error:`HTTP ${oe.status}`;ne||E({status:"error",message:Ue});return}const ce=await oe.json(),ke=typeof ce.proxyBasePath=="string"?ce.proxyBasePath:"",ye=typeof ce.previewToken=="string"?ce.previewToken:"",he=typeof ce.expiresAt=="number"?ce.expiresAt:0;if(!ke||!ye){ne||E({status:"error",message:r("contextPanel.preview.proxyError")});return}An.set(V,{proxyBasePath:ke,previewToken:ye,expiresAt:he}),ne||E({status:"ready",proxyBasePath:ke,previewToken:ye,expiresAt:he})}catch(oe){if(!ne){const ce=oe instanceof Error?oe.message:String(oe);E({status:"error",message:ce})}}})(),()=>{ne=!0}},[p,r]);const J=p&&k.status==="ready"?`${k.proxyBasePath}|${k.previewToken||""}|${y}`:"";a.useEffect(()=>{if(!J){M("");return}let V=!1;return M(""),qu(Cr()).then(Q=>{!V&&Q&&M(J)}).catch(()=>{}),()=>{V=!0}},[J]);const U=a.useMemo(()=>{if(O!==J||!p||k.status!=="ready")return"";try{const V=new URL(p),Q=V.pathname||"/",ne=new URLSearchParams(V.search);ne.delete("oc_url_token"),ne.delete("oc_client_token"),ne.set("ocPreview",String(y)),ne.set("oc_preview_token",k.previewToken||"");const oe=ne.toString();return ha().authenticatedAsset(`${k.proxyBasePath}${Q}${oe?`?${oe}`:""}${V.hash}`)}catch{return""}},[p,k,J,y,O]),te=U||(k.status==="error"?p:""),Z=a.useCallback(V=>{if(!V||!p||k.status!=="ready")return"";try{const Q=new URL(V,window.location.origin),ne=k.proxyBasePath.endsWith("/")?k.proxyBasePath.slice(0,-1):k.proxyBasePath;if(Q.origin!==window.location.origin||!Q.pathname.startsWith(ne))return"";const oe=Q.pathname.slice(ne.length)||"/",ce=new URL(p).origin;return Gd(new URL(`${oe}${Q.search}${Q.hash}`,ce).toString())}catch{return""}},[p,k]),ue=a.useCallback(V=>{if(!V||!p||k.status!=="ready")return"";try{const Q=new URL(V,window.location.origin),ne=new URL(p).origin;if(Q.origin!==window.location.origin||ne===window.location.origin)return"";const oe=k.proxyBasePath.endsWith("/")?k.proxyBasePath.slice(0,-1):k.proxyBasePath;return Q.pathname.startsWith(oe)?"":Gd(new URL(`${Q.pathname}${Q.search}${Q.hash}`,ne).toString())}catch{return""}},[p,k]),Oe=a.useCallback(V=>{const Q=o.current?.contentWindow;Q&&Q.postMessage({source:"openchamber-preview-parent",version:1,type:"set-inspect-mode",enabled:V},window.location.origin)},[]),se=a.useCallback(async V=>{const Q=L??(_?"draft":null);if(!Q){fe.error(r("contextPanel.preview.inspect.attachNoSession"));return}const ne=o.current,oe=ne?.contentWindow,ce=ne?.getBoundingClientRect(),ke={width:Number.isFinite(oe?.innerWidth)?oe?.innerWidth??ce?.width??0:ce?.width??0,height:Number.isFinite(oe?.innerHeight)?oe?.innerHeight??ce?.height??0:ce?.height??0},ye=ne?await wm(ne,V):null,he=!!ye;ye&&await A(ye),D({directory:e,sessionKey:Q},{source:"preview-annotation",fileLabel:h||"browser",startLine:1,endLine:1,code:fc({pageUrl:h,viewport:ke,devicePixelRatio:window.devicePixelRatio||1,target:V,screenshotAttached:he,intro:r(he?"contextPanel.preview.inspect.attachAnnotationWithScreenshot":"contextPanel.preview.inspect.attachAnnotation")}),language:"markdown",text:""}),fe.success(r("contextPanel.preview.inspect.attached"))},[A,D,L,h,e,_,r]),G=a.useCallback(()=>{const V=o.current;F(null),Oe(!1),V&&Hd(V,Ui).catch(()=>{})},[Oe]);a.useEffect(()=>{if(!N)return;const V=Q=>{Q.key==="Escape"&&(Q.preventDefault(),Q.stopImmediatePropagation(),v(!1),G())};return window.addEventListener("keydown",V,!0),()=>window.removeEventListener("keydown",V,!0)},[G,N]),a.useEffect(()=>()=>G(),[G]),a.useEffect(()=>{const V=Q=>{if(Q.source!==o.current?.contentWindow)return;const ne=Q.data;if(!(!ne||ne.source!=="openchamber-preview-bridge"||ne.version!==1)){if(ne.type==="ready"){const oe=typeof ne.url=="string"?ne.url:"",ce=Z(oe);ce&&ce!==h&&z(ce,{inFrame:!0});return}if(ne.type==="hover"){F(Co(ne.target)?ne.target:null);return}if(ne.type==="select"&&Co(ne.target)){F(null),v(!1),Oe(!1),se(ne.target);return}if(ne.type==="navigate-preview"){const oe=typeof ne.url=="string"?ne.url:"",ce=ue(oe);if(ce){z(ce);return}oe&&z(oe)}}};return window.addEventListener("message",V),()=>window.removeEventListener("message",V)},[z,se,h,Z,ue,Oe]);const Ie=a.useCallback(()=>{const V=o.current;if(!(!V||!h)){if(N){v(!1),G();return}if(U){F(null),v(!0),Oe(!0);return}v(!0),(async()=>{try{const Q=await Hd(V,Pm);if(v(!1),!Q||!Co(Q))return;await se(Q)}catch{v(!1),fe.error(r("contextPanel.browser.inspectUnavailable"))}})()}},[se,G,h,N,Oe,U,r]),pe=a.useCallback(()=>{try{const V=o.current?.contentWindow?.location.href||"",Q=ue(V);if(Q){z(Q,{inFrame:!0});return}}catch{}w(!1),N&&U&&Oe(!0)},[z,ue,N,Oe,U]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[s.jsx(He,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:g<=0,onClick:()=>R(g-1),children:s.jsx(I,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(He,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:g<0||g>=b.length-1,onClick:()=>R(g+1),children:s.jsx(I,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(He,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!h,onClick:W,children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:V=>{V.preventDefault(),z(d)},children:s.jsx("input",{value:d,onChange:V=>u(V.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(He,{type:"button",variant:N?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!h,onClick:Ie,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(I,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(He,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",disabled:!h,onClick:()=>{Io(h)},children:s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[te?s.jsxs("div",{className:"absolute inset-0",children:[s.jsx("iframe",{ref:o,src:te,title:r("contextPanel.browser.empty"),className:"absolute inset-0 h-full w-full border-0 bg-background",allow:"clipboard-read; clipboard-write; fullscreen",allowFullScreen:!0,onLoad:pe},`${n}:${y}`),N&&P?s.jsx("div",{className:"pointer-events-none absolute rounded-sm border-2 border-[var(--interactive-focus-ring)] bg-[var(--interactive-focus-ring)]/35",style:{left:P.bounds.x,top:P.bounds.y,width:P.bounds.width,height:P.bounds.height},children:s.jsxs("div",{className:"absolute -top-6 left-0 max-w-64 truncate rounded bg-[var(--surface-elevated)] px-2 py-0.5 typography-micro text-foreground shadow",children:[P.tag,P.text?` · ${P.text}`:""]})}):null]}):s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx(Gl,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")}),s.jsx("span",{className:"max-w-sm typography-micro text-muted-foreground",children:r("contextPanel.browser.emptyHint")}),s.jsx("span",{className:"max-w-md typography-micro leading-relaxed text-status-warning/70",children:r("contextPanel.browser.trustNotice")})]}),j?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},lj=({initialUrl:t,directory:e,tabID:n})=>{const{t:r}=ft(),o=a.useRef(null),i=Re(k=>k.setContextPanelTabTargetPath),c=ri(t),l=c!=="about:blank"?c:"",d=a.useRef(ri(t)),[u,h]=a.useState(l),[f,p]=a.useState(l),[x,b]=a.useState(!1),[S,g]=a.useState(!0),m=a.useRef(null),y=S,C=a.useCallback(k=>{!k||k==="about:blank"||!e||!n||i(e,n,k)},[e,n,i]),j=et(k=>k.currentSessionId),w=et(k=>k.newSessionDraft?.open),N=ci(k=>k.addDraft),v=lo(k=>k.addAttachedFile);a.useEffect(()=>{const k=o.current;if(!k)return;const E=()=>{try{const A=k.getURL();A&&A!=="about:blank"&&(p(A),h(A),C(A))}catch{}},O=A=>{const T=A.detail;typeof T?.url=="string"&&T.url&&(p(T.url),h(T.url),C(T.url))},M=()=>{m.current&&clearTimeout(m.current),m.current=setTimeout(()=>g(!0),200)},L=()=>{m.current&&clearTimeout(m.current),g(!1),E()},_=A=>{const T=A.detail;if(T?.disposition==="new-window"||T?.disposition==="foreground-tab"||T?.disposition==="background-tab"){A.preventDefault();const z=o.current;typeof z?.loadURL=="function"&&T.url&&z.loadURL(T.url)}},D=()=>{try{k.executeJavaScript?.(sj,!0).catch(()=>{})}catch{}};k.addEventListener("did-navigate",O),k.addEventListener("did-navigate-in-page",O),k.addEventListener("did-start-loading",M),k.addEventListener("did-stop-loading",L),k.addEventListener("new-window",_),k.addEventListener("dom-ready",D);try{k.isLoading()||(g(!1),E())}catch{}return D(),()=>{m.current&&clearTimeout(m.current),k.removeEventListener("did-navigate",O),k.removeEventListener("did-navigate-in-page",O),k.removeEventListener("did-start-loading",M),k.removeEventListener("did-stop-loading",L),k.removeEventListener("new-window",_),k.removeEventListener("dom-ready",D)}},[C]),a.useEffect(()=>{const k=setTimeout(()=>g(!1),3e4);return()=>clearTimeout(k)},[]),a.useEffect(()=>{if(!x)return;const k=E=>{if(E.key!=="Escape")return;E.preventDefault(),E.stopImmediatePropagation(),b(!1);const O=o.current;try{O?.executeJavaScript?.(Ui).catch(()=>{})}catch{}};return window.addEventListener("keydown",k,!0),()=>window.removeEventListener("keydown",k,!0)},[x]),a.useEffect(()=>{const k=o.current;return()=>{try{const E=k?.getURL?.();E&&E!=="about:blank"&&i(e,n,E)}catch{}try{k?.executeJavaScript?.(Ui).catch(()=>{})}catch{}}},[e,n,i]);const P=a.useCallback(k=>{const E=o.current;if(typeof E?.loadURL!="function")return;const O=ri(k);try{E.loadURL(O)}catch{}},[]),F=a.useCallback(()=>{const k=o.current;if(k){if(x){b(!1);try{k.executeJavaScript?.(Ui).catch(()=>{})}catch{}return}b(!0),k.executeJavaScript?.(Pm,!0).then(async E=>{if(b(!1),!E||!Co(E))return;const O=j??(w?"draft":null);if(!O){fe.error(r("contextPanel.preview.inspect.attachNoSession"));return}const M=typeof k.getWebContentsId=="function"?k.getWebContentsId():null;if(M==null)return;const L=await Mp("desktop_browser_capture_page",{webContentsId:M}),_=await k.executeJavaScript?.("({ width: window.innerWidth, height: window.innerHeight })",!0).catch(()=>null),D=Number.isFinite(_?.width)?_.width:L.width,A=Number.isFinite(_?.height)?_.height:L.height,T=await mc(L.base64,L.width,L.height,D,A,E),z=!!T;T&&await v(T),N({directory:e,sessionKey:O},{source:"preview-annotation",fileLabel:f||"browser",startLine:1,endLine:1,code:fc({pageUrl:f,viewport:{width:D,height:A},devicePixelRatio:window.devicePixelRatio||1,target:E,screenshotAttached:z,intro:r("contextPanel.preview.inspect.attachAnnotationWithScreenshot")}),language:"markdown",text:""}),fe.success(r("contextPanel.preview.inspect.attached"))}).catch(()=>b(!1))}},[v,N,j,f,e,x,w,r]);return s.jsxs("div",{className:"absolute inset-0 flex flex-col bg-background",children:[s.jsxs("div",{className:"flex items-center gap-1 border-b border-border bg-[var(--surface-background)] px-2 py-1",children:[s.jsx(He,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.goBack?.()}catch{}},children:s.jsx(I,{name:"arrow-left",className:"h-3.5 w-3.5"})}),s.jsx(He,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.goForward?.()}catch{}},children:s.jsx(I,{name:"arrow-right",className:"h-3.5 w-3.5"})}),s.jsx(He,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{try{o.current?.reload?.()}catch{}},children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})}),s.jsx("form",{className:"min-w-0 flex-1",onSubmit:k=>{k.preventDefault(),P(u)},children:s.jsx("input",{value:u,onChange:k=>h(k.target.value),className:"h-7 w-full rounded-md border border-border/50 bg-[var(--surface-elevated)] px-2 typography-micro text-foreground outline-none focus:border-[var(--interactive-focus-ring)]","aria-label":r("contextPanel.browser.addressAria")})}),s.jsx(He,{type:"button",variant:x?"secondary":"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:F,title:r("contextPanel.preview.inspect.toggle"),"aria-label":r("contextPanel.preview.inspect.toggle"),children:s.jsx(I,{name:"cursor",className:"h-3.5 w-3.5"})}),s.jsx(He,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:()=>{Io(f)},children:s.jsx(I,{name:"external-link",className:"h-3.5 w-3.5"})})]}),s.jsxs("div",{className:"relative min-h-0 flex-1 bg-background",children:[s.jsx("webview",{ref:o,src:d.current,partition:"persist:openchamber-browser",allowpopups:!0,style:{width:"100%",height:"100%",border:"none"}}),(!f||f==="about:blank")&&!S?s.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-6 bg-background p-6 text-center",children:[s.jsx(Gl,{width:140,height:140,className:"opacity-20"}),s.jsx("span",{className:"typography-ui-header text-muted-foreground",children:r("contextPanel.browser.empty")})]}):null,y?s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/70 typography-micro text-muted-foreground",children:r("common.loading")}):null]})]})},cj=()=>{const{t}=ft(),e=Wr()??"",n=a.useMemo(()=>H1(e),[e]),r=Re(B=>n?B.contextPanelByDirectory[n]:void 0),o=Re(B=>B.closeContextPanel),i=Re(B=>B.closeContextPanelTab),c=Re(B=>B.openContextPanelTab),l=Re(B=>B.toggleContextPanelExpanded),d=Re(B=>B.setContextPanelWidth),u=Re(B=>B.setActiveContextPanelTab),h=Re(B=>B.reorderContextPanelTabs),f=jr(B=>B.setSelectedPath),p=Re(B=>B.openContextPreview),x=Re(B=>B.contextEditorTreeVisible),b=Re(B=>B.toggleContextEditorTree),S=Re(B=>B.allowPromptingSubagentSessions),{themeMode:g,setThemeMode:m,lightThemeId:y,darkThemeId:C,currentTheme:j}=co(),w=a.useMemo(()=>r?.tabs??[],[r?.tabs]),N=w.find(B=>B.id===r?.activeTabId)??w[w.length-1]??null,v=!!(r?.isOpen&&N),P=!!(v&&r?.expanded),[F,k]=a.useState(null),E=N?.mode??null,O=E?r?.widthByMode?.[E]:void 0,M=E?j1(E):.5,L=F??(typeof window<"u"?window.innerWidth:Am*2),_=Wd(O??Math.round(M*L)),D=a.useMemo(()=>{const B=[];for(const xe of w){if(xe.mode!=="chat")continue;const be=Wi(xe.dedupeKey);be&&!B.includes(be)&&B.push(be)}return B},[w]),A=tj(n||void 0,D),[T,z]=a.useState(!1),R=a.useRef(0),W=a.useRef(_),J=a.useRef(null),U=a.useRef(null),te=a.useRef(null),Z=a.useRef(new Map),ue=a.useRef(new Map),Oe=a.useRef(!1);a.useLayoutEffect(()=>{const B=te.current?.parentElement;if(!B||typeof ResizeObserver>"u")return;const xe=new ResizeObserver(()=>{k(B.clientWidth||null)});return xe.observe(B),k(B.clientWidth||null),()=>xe.disconnect()},[]),a.useEffect(()=>{if(!v||Oe.current){Oe.current=v;return}const B=window.requestAnimationFrame(()=>{te.current?.focus({preventScroll:!0})});return Oe.current=!0,()=>window.cancelAnimationFrame(B)},[v]);const se=a.useRef(null),G=a.useRef(null),Ie=a.useCallback(()=>{G.current=null;const B=te.current,xe=J.current;!B||xe===null||B.style.setProperty("--oc-context-panel-width",`${xe}px`)},[]);a.useEffect(()=>()=>{G.current!==null&&clearTimeout(G.current)},[]);const pe=a.useCallback(B=>{const xe=Wd(B),be=se.current;return be===null?xe:Math.min(xe,Math.max(1,be))},[]),V=a.useCallback(B=>{!v||P||!n||(U.current=B.pointerId,z(!0),R.current=B.clientX,W.current=_,J.current=_,se.current=K1(te.current),document.documentElement.style.cursor="col-resize",B.preventDefault())},[n,P,v,_]),Q=a.useCallback(()=>{const B=pe(J.current??_);J.current=null,se.current=null,G.current!==null&&(clearTimeout(G.current),G.current=null),document.documentElement.style.cursor="",n&&E&&d(n,E,B),z(!1),U.current=null},[E,pe,n,d,_]);a.useEffect(()=>{if(!T)return;const B=Le=>{if(U.current!==Le.pointerId)return;const Ke=R.current-Le.clientX,st=pe(W.current+Ke);J.current!==st&&(J.current=st,G.current===null&&(G.current=setTimeout(Ie,V1)))},xe=Le=>{U.current===Le.pointerId&&Q()},be=()=>{Q()};return window.addEventListener("pointermove",B),window.addEventListener("pointerup",xe),window.addEventListener("pointercancel",xe),window.addEventListener("blur",be),()=>{window.removeEventListener("pointermove",B),window.removeEventListener("pointerup",xe),window.removeEventListener("pointercancel",xe),window.removeEventListener("blur",be)}},[Ie,pe,Q,T]),a.useEffect(()=>{T||(J.current=null,document.documentElement.style.cursor="")},[T]);const ne=a.useCallback(()=>{n&&o(n)},[o,n]),oe=a.useCallback(()=>{n&&l(n)},[n,l]),ce=a.useCallback(B=>{B.key==="Escape"&&(B.preventDefault(),B.stopPropagation(),ne())},[ne]);a.useEffect(()=>{if(!(!n||!N)&&N.mode==="file"&&N.targetPath){f(n,N.targetPath,{allowOutsideRoot:!0});return}},[N,n,f]);const ke=N?.mode==="chat"?N.id:null,ye=N?.mode==="chat"?Wi(N.dedupeKey):null;a.useEffect(()=>{if(!v||!n||!ye||typeof window>"u")return;const B=()=>{if(document.visibilityState==="hidden"||!document.hasFocus()){Oa(n,ye,!1);return}af(ye),Oa(n,ye,!0)};B();const xe=window.setInterval(B,1e4);return window.addEventListener("focus",B),window.addEventListener("blur",B),document.addEventListener("visibilitychange",B),()=>{window.clearInterval(xe),window.removeEventListener("focus",B),window.removeEventListener("blur",B),document.removeEventListener("visibilitychange",B),Oa(n,ye,!1)}},[ye,n,v]);const he=a.useCallback((B,xe,be)=>Bx(ue.current,B,xe,n||null,be,{mode:g,lightThemeId:y,darkThemeId:C,currentTheme:j}),[j,C,n,y,g]);a.useEffect(()=>{const B=new Set(w.map(xe=>xe.id));for(const xe of ue.current.keys())B.has(xe)||ue.current.delete(xe)},[w]);const Ee=a.useCallback(B=>{!n||N?.mode!=="diff"||c(n,{mode:"diff",targetPath:N.targetPath,stagedDiff:B==="staged",diffScope:B})},[N,n,c]),Ue=a.useCallback(()=>{if(typeof window>"u")return;const B={themeMode:g,lightThemeId:y,darkThemeId:C,currentTheme:j};for(const xe of Z.current.values()){const be=xe.contentWindow;be&&be.postMessage({type:"openchamber:theme-sync",payload:B},window.location.origin)}},[j,C,y,g]),Me=a.useCallback(()=>{if(typeof window>"u")return;const B={allowPromptingSubagentSessions:S};for(const xe of Z.current.values()){const be=xe.contentWindow;be&&be.postMessage({type:"openchamber:chat-settings-sync",payload:B},window.location.origin)}},[S]),X=a.useCallback(()=>{if(!(typeof window>"u"))for(const[B,xe]of Z.current.entries()){const be=xe.contentWindow;if(!be)continue;const Le={visible:ke===B};be.postMessage({type:"openchamber:embedded-visibility",payload:Le},window.location.origin)}},[ke]);a.useEffect(()=>{if(typeof window>"u")return;const B=xe=>{if(xe.origin!==window.location.origin||!Array.from(Z.current.values()).some(mt=>mt.contentWindow===xe.source))return;const Le=xe.data;if(Le?.type===$x){if(typeof Le.requestId!="string"||!Le.requestId)return;const mt=$n(),pt={apiBaseUrl:Cr(),clientToken:Xi(),localOrigin:typeof window.__OPENCHAMBER_LOCAL_ORIGIN__=="string"?window.__OPENCHAMBER_LOCAL_ORIGIN__:"",runtimeHeaders:Ch(),relayHostId:mt.startsWith("host:")?mt.slice(5):"",relay:Nh()??void 0};xe.source?.postMessage({type:_x,requestId:Le.requestId,payload:pt},xe.origin);return}if(Le?.type==="openchamber:theme-sync-request"){Ue();return}if(Le?.type==="openchamber:chat-settings-request"){Me();return}if(Le?.type!=="openchamber:cycle-theme-request")return;const Ke=["light","dark","system"],ut=(Ke.indexOf(g)+1)%Ke.length;m(Ke[ut])};return window.addEventListener("message",B),()=>window.removeEventListener("message",B)},[Me,Ue,m,g]),a.useLayoutEffect(()=>{w.some(xe=>xe.mode==="chat")&&(Ue(),Me(),X())},[C,y,Me,X,Ue,w,g]);const Ne=N?.mode==="file"||N?.mode==="chat"||N?.mode==="preview",Ae=a.useMemo(()=>N?w.filter(B=>B.mode===N.mode):[],[N,w]),Se=a.useMemo(()=>Ae.map(B=>{const xe=Y1(B,A,t),be=nj(xe,W1),Le=G1(B.targetPath,e);return{id:B.id,label:be,icon:Ud(B),title:Le?`${xe}: ${Le}`:xe,closeLabel:t("contextPanel.tab.closeTabAria",{label:be})}}),[Ae,e,A,t]),le=N?.mode==="context"?s.jsx(i1,{}):N?.mode==="git"?s.jsx(Sl,{isActive:v}):N?.mode==="pr"?s.jsx(Xw,{}):N?.mode==="notes"?s.jsx(Mf,{}):N?.mode==="plan"?s.jsx(Tf,{targetPath:N.targetPath}):N?.mode==="preview"?s.jsx(oj,{rawUrl:N.targetPath??"",onNavigate:B=>p(e,B)}):s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx(I,{name:"global",className:"h-12 w-12 text-muted-foreground/50"}),s.jsx("div",{className:"typography-ui-header text-foreground",children:t("contextPanel.preview.title")}),s.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:t("contextPanel.preview.description")})]}),ee=a.useMemo(()=>w.filter(B=>B.mode==="chat"),[w]),ie=a.useMemo(()=>w.filter(B=>B.mode==="browser"),[w]),ve=a.useMemo(()=>w.filter(B=>B.mode==="diff"),[w]),K=a.useMemo(()=>w.some(B=>B.mode==="terminal"),[w]),de=a.useMemo(()=>w.some(B=>B.mode==="walkthrough"),[w]),_e=ij()?lj:aj,Pe=a.useMemo(()=>w.some(B=>B.mode==="file"),[w]),re=a.useMemo(()=>w.some(B=>B.mode==="file"&&B.targetPath),[w]),me=N?.mode==="file",ge=s.jsxs("header",{className:"flex h-10 items-stretch border-b border-border",children:[Ne?s.jsx(ui,{items:Se,activeId:N?.id??null,onSelect:B=>{n&&u(n,B)},onClose:B=>{n&&i(n,B)},onReorder:(B,xe)=>{n&&h(n,B,xe)},layoutMode:"scrollable",variant:"default"}):s.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 px-3",children:[N?Ud(N):null,s.jsx("span",{className:"truncate typography-ui-label text-foreground",children:N?Dm(N.mode,t):null})]}),s.jsxs("div",{className:"flex items-center gap-1 px-1.5",children:[me?s.jsx(He,{type:"button",variant:"ghost",size:"sm",onClick:b,className:"h-7 w-7 p-0",title:t("contextRail.editorTree.toggle"),"aria-label":t("contextRail.editorTree.toggle"),"aria-pressed":x,children:s.jsx(I,{name:"layout-right",className:"h-3.5 w-3.5"})}):null,s.jsx(He,{type:"button",variant:"ghost",size:"sm",onClick:oe,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(He,{type:"button",variant:"ghost",size:"sm",onClick:ne,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"})})]})]}),$=v?P?{"--oc-context-panel-width":F!==null?`${F}px`:"100%",width:F!==null?`${F}px`:"100%",maxWidth:"100%"}:{width:"min(var(--oc-context-panel-width), 100%)",maxWidth:"100%",overflowX:"clip","--oc-context-panel-width":`${_}px`}:{"--oc-context-panel-width":`${_}px`,width:0,maxWidth:"100%",overflowX:"clip"};return s.jsxs("aside",{ref:te,"data-context-panel":"true",tabIndex:-1,inert:!v||void 0,className:De("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",!v&&"pointer-events-none","will-change-[width] motion-reduce:transition-none","transition-[width] duration-200 ease-[cubic-bezier(0.22,1,0.36,1)]"),onKeyDownCapture:ce,style:$,children:[v&&!P&&s.jsx("div",{"aria-hidden":"true",className:"absolute left-0 top-0 z-40 h-full w-px bg-border"}),v&&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:De("absolute left-0 top-0 z-50 h-full w-[3px] cursor-col-resize transition-colors hover:bg-[var(--interactive-border)]/80",T&&"bg-[var(--interactive-border)]"),onPointerDown:V,role:"separator","aria-orientation":"vertical","aria-label":t("contextPanel.actions.resizePanelAria")}),s.jsxs("div",{className:De("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]",!v&&"pointer-events-none select-none opacity-0"),style:{width:P?F!==null?`${F}px`:"100%":"var(--oc-context-panel-width)"},"aria-hidden":!v,children:[ge,s.jsxs("div",{className:De("relative min-h-0 flex-1 overflow-hidden",T&&"pointer-events-none"),children:[Pe?s.jsxs("div",{className:De("absolute inset-0 flex",me?"flex":"hidden"),children:[s.jsx("div",{className:"h-full min-w-0 flex-1",children:re?s.jsx($f,{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:x})]}):null,ee.map(B=>{const xe=Wi(B.dedupeKey);if(!xe)return null;const be=he(B.id,xe,B.readOnly);return be?s.jsx("iframe",{ref:Le=>{if(!Le){Z.current.delete(B.id);return}Z.current.set(B.id,Le)},src:be,title:t("contextPanel.iframe.sessionChatTitle",{sessionID:xe}),className:De("absolute inset-0 h-full w-full border-0 bg-background",ke===B.id?"block":"hidden"),onLoad:()=>{Ue(),Me(),X()}},B.id):null}),ie.map(B=>s.jsx("div",{className:De("absolute inset-0",N?.id!==B.id&&"hidden"),children:s.jsx(_e,{initialUrl:B.targetPath??"",directory:n,tabID:B.id})},B.id)),ve.map(B=>s.jsx("div",{className:De("absolute inset-0",N?.id!==B.id&&"hidden"),children:s.jsx(im,{hideStackedFileSidebar:!0,stackedDefaultCollapsedAll:!0,pinSelectedFileHeaderToTopOnNavigate:!0,showOpenInEditorAction:!0,diffScope:B.diffScope??(B.stagedDiff?"staged":"working"),onDiffScopeChange:Ee,targetFilePath:B.targetPath,flushContent:!0})},B.id)),K?s.jsx("div",{className:De("absolute inset-0",N?.mode==="terminal"?"block":"hidden"),children:s.jsx(Ef,{visible:v&&N?.mode==="terminal"})}):null,de?s.jsx("div",{className:De("absolute inset-0",N?.mode==="walkthrough"?"block":"hidden"),children:s.jsx(Iv,{directory:e})}):null,N?.mode!=="chat"&&!me&&N?.mode!=="browser"&&N?.mode!=="diff"&&N?.mode!=="terminal"&&N?.mode!=="walkthrough"?le:null]})]})]})},dj=150,uj=768,fj=[],mj=t=>{const e=nt.c(43),{surface:n,isActive:r,showActivityDot:o,label:i,description:c,onSelect:l}=t;let d;e[0]!==n.id?(d={id:n.id},e[0]=n.id,e[1]=d):d=e[1];const{attributes:u,listeners:h,setNodeRef:f,transform:p,transition:x,isDragging:b}=ec(d);let S;e[2]!==p?(S=tc.Translate.toString(p),e[2]=p,e[3]=S):S=e[3];let g;e[4]!==S||e[5]!==x?(g={transform:S,transition:x},e[4]=S,e[5]=x,e[6]=g):g=e[6];const m=b&&"z-10 opacity-70";let y;e[7]!==m?(y=De("relative",m),e[7]=m,e[8]=y):y=e[8];let C;e[9]!==l||e[10]!==n?(C=()=>l(n),e[9]=l,e[10]=n,e[11]=C):C=e[11];const j=r?"text-primary":"text-muted-foreground hover:text-foreground";let w;e[12]!==j?(w=De("flex h-9 w-9 touch-none select-none items-center justify-center rounded-md transition-colors",j),e[12]=j,e[13]=w):w=e[13];let N;e[14]!==n.icon||e[15]!==n.id?(N=n.id==="diff"?s.jsx(Wf,{}):s.jsx(I,{name:n.icon,className:"h-[18px] w-[18px]"}),e[14]=n.icon,e[15]=n.id,e[16]=N):N=e[16];let v;e[17]!==o?(v=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[17]=o,e[18]=v):v=e[18];let P;e[19]!==u||e[20]!==r||e[21]!==i||e[22]!==h||e[23]!==v||e[24]!==C||e[25]!==w||e[26]!==N?(P=s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",...u,...h,onClick:C,"aria-label":i,"aria-pressed":r,className:w,children:[N,v]})}),e[19]=u,e[20]=r,e[21]=i,e[22]=h,e[23]=v,e[24]=C,e[25]=w,e[26]=N,e[27]=P):P=e[27];let F;e[28]!==i?(F=s.jsx("span",{children:i}),e[28]=i,e[29]=F):F=e[29];let k;e[30]!==c?(k=s.jsx("span",{className:"typography-micro text-muted-foreground",children:c}),e[30]=c,e[31]=k):k=e[31];let E;e[32]!==F||e[33]!==k?(E=s.jsx(At,{side:"left",sideOffset:8,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[F,k]})}),e[32]=F,e[33]=k,e[34]=E):E=e[34];let O;e[35]!==P||e[36]!==E?(O=s.jsxs(Nt,{delayDuration:dj,children:[P,E]}),e[35]=P,e[36]=E,e[37]=O):O=e[37];let M;return e[38]!==f||e[39]!==O||e[40]!==g||e[41]!==y?(M=s.jsx("div",{ref:f,style:g,className:y,children:O}),e[38]=f,e[39]=O,e[40]=g,e[41]=y,e[42]=M):M=e[42],M},hj=()=>{const t=nt.c(47),{t:e}=ft(),n=Wr();let r;t[0]!==n?(r=n?xo(n):"",t[0]=n,t[1]=r):r=t[1];const o=r;let i;t[2]!==o?(i=_=>o?_.contextPanelByDirectory[o]:void 0,t[2]=o,t[3]=i):i=t[3];const c=Re(i),l=Re(pj),d=Re(gj),u=Re(xj),h=_l(bj),{screenWidth:f}=Pr(),p=Bo(o||null);let x;t[4]===Symbol.for("react.memo_cache_sentinel")?(x={activationConstraint:{distance:8}},t[4]=x):x=t[4];let b;t[5]===Symbol.for("react.memo_cache_sentinel")?(b={activationConstraint:{delay:200,tolerance:6}},t[5]=b):b=t[5];const S=ra(No(Wx,x),No(Vx,b)),g=c?.tabs??fj;let m;t[6]!==c?.activeTabId||t[7]!==g?(m=g.find(_=>_.id===c?.activeTabId)??null,t[6]=c?.activeTabId,t[7]=g,t[8]=m):m=t[8];const y=m,C=c?.isOpen?y?.mode??null:null,j=p?.files.length??0;let w;if(t[9]!==l||t[10]!==h||t[11]!==f||t[12]!==g){let _;t[14]!==h||t[15]!==f||t[16]!==g?(_=D=>D.id==="plan"&&!h||D.id==="walkthrough"&&(ir()||f<uj)?!1:D.availability==="has-content"?g.some(A=>A.mode===D.mode):!0,t[14]=h,t[15]=f,t[16]=g,t[17]=_):_=t[17],w=$d(l).filter(_),t[9]=l,t[10]=h,t[11]=f,t[12]=g,t[13]=w}else w=t[13];const N=w;let v;t[18]!==d?(v=_=>{const{active:D,over:A}=_;if(!A||D.id===A.id)return;const T=$d(Re.getState().contextRailOrder).map(yj),z=T.indexOf(D.id),R=T.indexOf(A.id);z===-1||R===-1||d(zf(T,z,R))},t[18]=d,t[19]=v):v=t[19];const P=v;if(!o)return null;let F;t[20]!==e?(F=e("contextRail.aria.rail"),t[20]=e,t[21]=F):F=t[21];let k;t[22]!==N?(k=N.map(wj),t[22]=N,t[23]=k):k=t[23];let E;if(t[24]!==C||t[25]!==j||t[26]!==o||t[27]!==u||t[28]!==N||t[29]!==e){let _;t[31]!==C||t[32]!==j||t[33]!==o||t[34]!==u||t[35]!==e?(_=D=>s.jsx(mj,{surface:D,isActive:C===D.mode,showActivityDot:D.id==="git"&&j>0,label:e(D.labelKey),description:e(D.descriptionKey),onSelect:A=>u(o,A.mode)},D.id),t[31]=C,t[32]=j,t[33]=o,t[34]=u,t[35]=e,t[36]=_):_=t[36],E=N.map(_),t[24]=C,t[25]=j,t[26]=o,t[27]=u,t[28]=N,t[29]=e,t[30]=E}else E=t[30];let O;t[37]!==k||t[38]!==E?(O=s.jsx(wl,{items:k,strategy:vl,children:E}),t[37]=k,t[38]=E,t[39]=O):O=t[39];let M;t[40]!==P||t[41]!==S||t[42]!==O?(M=s.jsx(oa,{sensors:S,collisionDetection:ia,onDragEnd:P,children:O}),t[40]=P,t[41]=S,t[42]=O,t[43]=M):M=t[43];let L;return t[44]!==M||t[45]!==F?(L=s.jsx("nav",{"aria-label":F,className:"flex h-full w-11 flex-shrink-0 flex-col items-center gap-1 bg-background py-2",children:M}),t[44]=M,t[45]=F,t[46]=L):L=t[46],L};function pj(t){return t.contextRailOrder}function gj(t){return t.setContextRailOrder}function xj(t){return t.openContextSurface}function bj(t){return t.planModeEnabled}function yj(t){return t.id}function wj(t){return t.id}const vj=(t,e)=>!t||e.length===0?"":JSON.stringify([t,e]),jj=(t,e,n,r)=>!n||r!==n||t.length===0?[]:ei(t,e,o=>o.name,{limit:10,threshold:.4}),Sj=new Set,kj=[],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},Nj=()=>{const t=nt.c(178),{t:e}=ft(),n=Re(Cj),r=Re(Aj),o=Re(Dj),i=Re(Pj),c=Re(Ij),l=Re(Rj),d=Re(Mj),u=Re(Tj),h=Re(Ej),f=Re(Fj),p=Re(Oj),x=et(Lj),b=et(Bj);let S;t[0]!==n?(S=Fe=>n?Fe.activeSessions:kj,t[0]=n,t[1]=S):S=t[1];const g=pn(S);let m;t[2]!==n?(m=Fe=>n?Fe.ids:Sj,t[2]=n,t[3]=m):m=t[3];const y=di(m);let C;t[4]!==n?(C=Fe=>n?Fe.rankById:ql,t[4]=n,t[5]=C):C=t[5];const j=Na(C),w=js($j),N=ms(_j),v=ms(zj),P=Wr(),F=Gu(Vj),{files:k,git:E}=_n(),O=tn(Wj),{isMobile:M}=Pr();let L;t[6]!==P?(L=P?Cl(P):null,t[6]=P,t[7]=L):L=t[7];const _=L,[D,A]=a.useState(""),z=Kl(D,200).trim();let R;t[8]!==D?(R=D.trim(),t[8]=D,t[9]=R):R=t[9];const W=R;let J,U;t[10]!==n?(J=()=>{n&&A("")},U=[n],t[10]=n,t[11]=J,t[12]=U):(J=t[11],U=t[12]),a.useEffect(J,U);let te,Z;t[13]!==g||t[14]!==O||t[15]!==E||t[16]!==n?(te=()=>{if(!n||!E)return;const Fe=setTimeout(()=>{const Te=new Set;for(const it of g){const ct=Bn(it);!ct||Te.has(ct)||(Te.add(ct),O(ct,E))}},0);return()=>clearTimeout(Fe)},Z=[n,g,E,O],t[13]=g,t[14]=O,t[15]=E,t[16]=n,t[17]=te,t[18]=Z):(te=t[17],Z=t[18]),a.useEffect(te,Z);let ue;t[19]!==r?(ue=()=>r(!1),t[19]=r,t[20]=ue):ue=t[20];const Oe=ue;let se;t[21]!==Oe?(se=Fe=>()=>{Oe(),Fe()},t[21]=Oe,t[22]=se):se=t[22];const G=se;let Ie;t[23]!==N?.id||t[24]!==N?.path||t[25]!==w||t[26]!==M||t[27]!==u||t[28]!==h||t[29]!==x||t[30]!==G||t[31]!==o||t[32]!==l||t[33]!==i||t[34]!==e||t[35]!==d?(Ie=()=>{const Fe=[{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:G(()=>{o("chat"),l(!1),x()})},{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:G(Uj)},{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:G(Hj)},{id:"toggle-sidebar",title:e(M?"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(M?"commandPalette.item.showSessionSwitcher":"commandPalette.item.toggleSidebar"),onSelect:G(()=>{if(M){const{isSessionSwitcherOpen:Te}=Re.getState();l(!Te)}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:G(()=>{w&&h(w,"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:G(()=>{w&&u(w)})},{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:G(()=>i(!0))}];return ma()&&Fe.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:G(()=>{Ar("desktop_open_draft_mini_chat_window",{directory:Cl(w||N?.path||""),projectId:N?.id??null}).catch(Kj)})}),Fe},t[23]=N?.id,t[24]=N?.path,t[25]=w,t[26]=M,t[27]=u,t[28]=h,t[29]=x,t[30]=G,t[31]=o,t[32]=l,t[33]=i,t[34]=e,t[35]=d,t[36]=Ie):Ie=t[36],N?.id,N?.path;let pe;t[37]!==Ie?(pe=Ie(),t[37]=Ie,t[38]=pe):pe=t[38];const V=pe;let Q;t[39]===Symbol.for("react.memo_cache_sentinel")?(Q=hr(),t[39]=Q):Q=t[39];const ne=Q;let oe,ce;t[40]===Symbol.for("react.memo_cache_sentinel")?(oe=ir(),ce=!ne&&Ol(),t[40]=oe,t[41]=ce):(oe=t[40],ce=t[41]);let ke;t[42]!==M?(ke={isVSCode:oe,isWeb:ce,isDesktop:ne,isMobile:M},t[42]=M,t[43]=ke):ke=t[43];const ye=ke;let he;if(t[44]!==G||t[45]!==i||t[46]!==c||t[47]!==ye){let Fe;t[49]!==ye?(Fe=it=>it.isAvailable?it.isAvailable(ye):!0,t[49]=ye,t[50]=Fe):Fe=t[50];let Te;t[51]!==G||t[52]!==i||t[53]!==c?(Te=it=>{const ct=mx(it.slug)??"settings-3",Kt=(it.keywords??[]).join(" ");return{id:`settings:${it.slug}`,title:it.title,icon:it.slug==="mcp"?s.jsx(gl,{className:"mr-2 h-4 w-4"}):s.jsx(I,{name:ct,className:"mr-2 h-4 w-4"}),searchText:`${it.title} ${it.group} ${Kt}`,onSelect:G(()=>{c(it.slug),i(!0)})}},t[51]=G,t[52]=i,t[53]=c,t[54]=Te):Te=t[54],he=fx.filter(Gj).filter(Fe).map(Te),t[44]=G,t[45]=i,t[46]=c,t[47]=ye,t[48]=he}else he=t[48];const Ee=he;let Ue;t[55]!==g||t[56]!==y||t[57]!==j?(Ue=lf(g,y,j),t[55]=g,t[56]=y,t[57]=j,t[58]=Ue):Ue=t[58];const Me=Ue,X=cf(),Ne=et(qj);let Ae;t[59]!==X||t[60]!==Ne?(Ae=(Fe,Te)=>{const it=Ne.get(Fe);return it?.branch?it.branch.trim()||null:Te&&X.get(Te)?.trim()||null},t[59]=X,t[60]=Ne,t[61]=Ae):Ae=t[61];const Se=Ae;let le;t[62]===Symbol.for("react.memo_cache_sentinel")?(le=[],t[62]=le):le=t[62];const[ee,ie]=a.useState(le),[ve,K]=a.useState(""),de=vj(_,z);let _e;t[63]!==_||t[64]!==de||t[65]!==n||t[66]!==F||t[67]!==ie||t[68]!==K||t[69]!==z?(_e=()=>{if(!n){ie([]),K("");return}if(!de){ie([]),K("");return}if(!_){ie([]),K("");return}let Fe=!1;return F(_,z,10,{type:"file"}).then(Te=>{Fe||(ie(Te.map(Yj)),K(de))}).catch(()=>{Fe||(ie([]),K(de))}),()=>{Fe=!0}},t[63]=_,t[64]=de,t[65]=n,t[66]=F,t[67]=ie,t[68]=K,t[69]=z,t[70]=_e):_e=t[70];let Pe;t[71]!==_||t[72]!==de||t[73]!==n||t[74]!==F||t[75]!==z?(Pe=[n,_,z,de,F],t[71]=_,t[72]=de,t[73]=n,t[74]=F,t[75]=z,t[76]=Pe):Pe=t[76],a.useEffect(_e,Pe);const re=W.length>0;let me;e:{if(!re){let Te;t[77]!==V?(Te=V.map(Qj),t[77]=V,t[78]=Te):Te=t[78],me=Te;break e}let Fe;t[79]!==V||t[80]!==W?(Fe=ei(V,W,Xj,{limit:7,noFuzzy:!0}),t[79]=V,t[80]=W,t[81]=Fe):Fe=t[81],me=Fe}const ge=me;let $;e:{if(!re){let Te;t[82]===Symbol.for("react.memo_cache_sentinel")?(Te=[],t[82]=Te):Te=t[82],$=Te;break e}let Fe;t[83]!==W||t[84]!==Ee?(Fe=ei(Ee,W,Jj,{limit:7,noFuzzy:!0}),t[83]=W,t[84]=Ee,t[85]=Fe):Fe=t[85],$=Fe}const B=$;let xe;e:{if(!re){let Te;t[86]!==Me?(Te=Me.slice(0,5).map(Zj),t[86]=Me,t[87]=Te):Te=t[87],xe=Te;break e}let Fe;t[88]!==W||t[89]!==Me?(Fe=ei(Me,W,e0,{limit:7,threshold:.2}),t[88]=W,t[89]=Me,t[90]=Fe):Fe=t[90],xe=Fe}const be=xe;let Le;e:{if(!n){let Te;t[91]===Symbol.for("react.memo_cache_sentinel")?(Te=[],t[91]=Te):Te=t[91],Le=Te;break e}let Fe;t[92]!==ee||t[93]!==ve||t[94]!==de||t[95]!==z?(Fe=jj(ee,z,de,ve),t[92]=ee,t[93]=ve,t[94]=de,t[95]=z,t[96]=Fe):Fe=t[96],Le=Fe}const Ke=Le,st=n&&de.length>0&&ve!==de;let ut;e:{if(!re){let Te;t[97]===Symbol.for("react.memo_cache_sentinel")?(Te=[],t[97]=Te):Te=t[97],ut=Te;break e}let Fe;if(t[98]!==W||t[99]!==v){const Te=v.map(t0);Fe=ei(Te,W,s0,{limit:7,threshold:.4}),t[98]=W,t[99]=v,t[100]=Fe}else Fe=t[100];ut=Fe}const mt=ut;let pt,ht,xt,wt,bt,Dt,qt,Ut,We,yt,Qe,Rt,Ot,kt;if(t[101]!==Se||t[102]!==Oe||t[103]!==_||t[104]!==k||t[105]!==re||t[106]!==n||t[107]!==f||t[108]!==x||t[109]!==D||t[110]!==ge||t[111]!==Ke||t[112]!==mt||t[113]!==be||t[114]!==B||t[115]!==r||t[116]!==b||t[117]!==p||t[118]!==e){const Fe=ge.map(n0),Te=B.map(r0),it=be.map(o0),ct=re?Ke.map(i0):[],Kt=re?mt.map(a0):[];let Lt;e:{if(!re){Lt=["commands","sessions"];break e}const _t=l0,Mt=[{key:"commands",score:_t(ge)},{key:"settings",score:_t(B)},{key:"sessions",score:_t(be)},{key:"files",score:_t(Ke)},{key:"projects",score:_t(mt)}];Mt.sort(c0),Lt=Mt.map(d0)}const ze=Lt,Xe=_t=>{Oe(),b(_t.id,Bn(_t))},tt=async _t=>{if(!_)return;const Mt=await nc(k,_t,{directory:_});if(!Mt.ok){fe.error(rc(Mt.reason));return}f(_,_t),Oe()},at=(_t,Mt)=>{Oe(),x({selectedProjectId:_t,directoryOverride:Mt})},Ze=_t=>ga(ro(_t,p));wt=Ts,Rt=n,Ot=r;let Pt;t[133]!==e?(Pt=e("commandPalette.title"),t[133]=e,t[134]=Pt):Pt=t[134];let Tt;t[135]!==Pt?(Tt=s.jsx($s,{children:Pt}),t[135]=Pt,t[136]=Tt):Tt=t[136];let Jt;t[137]!==e?(Jt=e("commandPalette.description"),t[137]=e,t[138]=Jt):Jt=t[138];let ls;t[139]!==Jt?(ls=s.jsx(Ks,{children:Jt}),t[139]=Jt,t[140]=ls):ls=t[140],t[141]!==Tt||t[142]!==ls?(kt=s.jsxs(Hs,{className:"sr-only",children:[Tt,ls]}),t[141]=Tt,t[142]=ls,t[143]=kt):kt=t[143],xt=Es,yt="overflow-hidden p-0",Qe=!0,ht=ba,qt=!1,Ut="[&_[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 cs;t[144]!==e?(cs=e("commandPalette.input.placeholder"),t[144]=e,t[145]=cs):cs=t[145],t[146]!==D||t[147]!==cs?(We=s.jsx(ya,{value:D,onValueChange:A,placeholder:cs}),t[146]=D,t[147]=cs,t[148]=We):We=t[148],pt=wa;let Bt;t[149]!==e?(Bt=e("commandPalette.empty.noResults"),t[149]=e,t[150]=Bt):Bt=t[150],t[151]!==Bt?(bt=s.jsx(va,{children:Bt}),t[151]=Bt,t[152]=bt):bt=t[152],Dt=ze.map(_t=>_t==="commands"&&Fe.length>0?s.jsx(kr,{children:Fe.map(Mt=>s.jsxs(Nr,{value:Mt.id,onSelect:Mt.onSelect,children:[Mt.icon,s.jsx("span",{children:Mt.title}),Mt.shortcutId?s.jsx(Tp,{children:Ze(Mt.shortcutId)}):null]},Mt.id))},"commands"):_t==="settings"&&Te.length>0?s.jsx(kr,{children:Te.map(u0)},"settings"):_t==="sessions"&&it.length>0?s.jsx(kr,{children:it.map(Mt=>{const ps=Mt.title||e("commandPalette.session.untitled"),_s=Bn(Mt),Wt=Se(Mt.id,_s);return s.jsxs(Nr,{value:`session:${Mt.id}`,onSelect:()=>Xe(Mt),children:[s.jsx(I,{name:"chat-ai-3",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:ps}),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]},Mt.id)})},"sessions"):_t==="files"&&ct.length>0?s.jsx(kr,{children:ct.map(Mt=>{const ps=Ep(Mt.relativePath||Mt.name,{maxLength:80});return s.jsxs(Nr,{value:`file:${Mt.path}`,onSelect:()=>{tt(Mt.path)},children:[s.jsx(Lo,{filePath:Mt.path,className:"mr-2 size-4 shrink-0"}),s.jsx("span",{className:"truncate","aria-label":Mt.relativePath,children:ps})]},`file:${Mt.path}`)})},"files"):_t==="projects"&&Kt.length>0?s.jsx(kr,{children:Kt.map(Mt=>{const ps=Mt.displayName;return s.jsxs(Nr,{value:`project:${Mt.id}`,onSelect:()=>at(Mt.id,Mt.path),children:[s.jsx(I,{name:"folder",className:"mr-2 h-4 w-4"}),s.jsx("span",{className:"truncate",children:ps}),s.jsx("span",{className:"ml-auto inline-flex items-center text-muted-foreground typography-meta truncate max-w-[160px]",children:Mt.path})]},`project:${Mt.id}`)})},"projects"):null),t[101]=Se,t[102]=Oe,t[103]=_,t[104]=k,t[105]=re,t[106]=n,t[107]=f,t[108]=x,t[109]=D,t[110]=ge,t[111]=Ke,t[112]=mt,t[113]=be,t[114]=B,t[115]=r,t[116]=b,t[117]=p,t[118]=e,t[119]=pt,t[120]=ht,t[121]=xt,t[122]=wt,t[123]=bt,t[124]=Dt,t[125]=qt,t[126]=Ut,t[127]=We,t[128]=yt,t[129]=Qe,t[130]=Rt,t[131]=Ot,t[132]=kt}else pt=t[119],ht=t[120],xt=t[121],wt=t[122],bt=t[123],Dt=t[124],qt=t[125],Ut=t[126],We=t[127],yt=t[128],Qe=t[129],Rt=t[130],Ot=t[131],kt=t[132];let Ft;t[153]!==st||t[154]!==e?(Ft=st?s.jsx("div",{className:"px-3 py-2 typography-meta text-muted-foreground",children:e("commandPalette.empty.searchingFiles")}):null,t[153]=st,t[154]=e,t[155]=Ft):Ft=t[155];let Ht;t[156]!==pt||t[157]!==bt||t[158]!==Dt||t[159]!==Ft?(Ht=s.jsxs(pt,{children:[bt,Dt,Ft]}),t[156]=pt,t[157]=bt,t[158]=Dt,t[159]=Ft,t[160]=Ht):Ht=t[160];let Xt;t[161]!==ht||t[162]!==qt||t[163]!==Ut||t[164]!==We||t[165]!==Ht?(Xt=s.jsxs(ht,{shouldFilter:qt,className:Ut,children:[We,Ht]}),t[161]=ht,t[162]=qt,t[163]=Ut,t[164]=We,t[165]=Ht,t[166]=Xt):Xt=t[166];let rt;t[167]!==xt||t[168]!==yt||t[169]!==Qe||t[170]!==Xt?(rt=s.jsx(xt,{className:yt,showCloseButton:Qe,children:Xt}),t[167]=xt,t[168]=yt,t[169]=Qe,t[170]=Xt,t[171]=rt):rt=t[171];let je;return t[172]!==wt||t[173]!==Rt||t[174]!==Ot||t[175]!==kt||t[176]!==rt?(je=s.jsxs(wt,{open:Rt,onOpenChange:Ot,children:[kt,rt]}),t[172]=wt,t[173]=Rt,t[174]=Ot,t[175]=kt,t[176]=rt,t[177]=je):je=t[177],je};function Cj(t){return t.isCommandPaletteOpen}function Aj(t){return t.setCommandPaletteOpen}function Dj(t){return t.setActiveMainTab}function Pj(t){return t.setSettingsDialogOpen}function Ij(t){return t.setSettingsPage}function Rj(t){return t.setSessionSwitcherOpen}function Mj(t){return t.toggleSidebar}function Tj(t){return t.openContextOverview}function Ej(t){return t.openContextSurface}function Fj(t){return t.openContextFile}function Oj(t){return t.shortcutOverrides}function Lj(t){return t.openNewSessionDraft}function Bj(t){return t.setCurrentSession}function $j(t){return t.currentDirectory}function _j(t){return t.getActiveProject()}function zj(t){return t.projects}function Vj(t){return t.searchFiles}function Wj(t){return t.ensureStatus}function Uj(){df()}function Hj(){Kn.requestDirectoryDialog()}function Kj(t){console.warn("[command-palette] failed to open draft mini chat window",t)}function Gj(t){return t.slug!=="home"}function qj(t){return t.worktreeMetadata}function Yj(t){return{path:Cl(t.path),name:t.name,relativePath:t.relativePath}}function Qj(t){return{item:t,score:0}}function Xj(t){return t.searchText}function Jj(t){return t.searchText}function Zj(t){return{item:t,score:0}}function e0(t){return t.title||""}function t0(t){return{...t,displayName:t.label||t.path.split("/").pop()||t.path,searchText:`${t.label||""} ${t.path}`}}function s0(t){return t.searchText}function n0(t){return t.item}function r0(t){return t.item}function o0(t){return t.item}function i0(t){return t.item}function a0(t){return t.item}function l0(t){return t.length?t[0].score:1/0}function c0(t,e){return t.score-e.score}function d0(t){return t.key}function u0(t){return s.jsxs(Nr,{value:t.id,onSelect:t.onSelect,children:[t.icon,s.jsx("span",{children:t.title})]},t.id)}const qd=(t,e,n)=>Op(t)?ga(ro(t,n)):e,f0=()=>{const t=nt.c(69),{t:e}=ft(),n=Re(m0),r=Re(h0),o=Re(p0);let i;t[0]===Symbol.for("react.memo_cache_sentinel")?(i=Fp(),t[0]=i):i=t[0];const c=i;let l;t[1]===Symbol.for("react.memo_cache_sentinel")?(l=ir(),t[1]=l):l=t[1];const d=l;let u,h,f,p,x,b,S,g,m;if(t[2]!==n||t[3]!==r||t[4]!==o||t[5]!==e){const A=[{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:"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:""}]},{categoryKey:"helpDialog.section.interface",items:[{id:"cycle_theme",descriptionKey:"helpDialog.item.cycleTheme",icon:"palette",keys:""},{keys:[`${c} + 1...9`],descriptionKey:"helpDialog.item.switchProject",icon:"layout-left"},{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:""}]}];h=Ts,g=n,m=r,u=Es,b="max-w-2xl w-[min(42rem,calc(100vw-1.5rem))] max-h-[calc(100dvh-2rem)] flex flex-col overflow-hidden";let T;t[15]===Symbol.for("react.memo_cache_sentinel")?(T=s.jsx(I,{name:"settings-3",className:"h-5 w-5"}),t[15]=T):T=t[15];let z;t[16]!==e?(z=e("helpDialog.title"),t[16]=e,t[17]=z):z=t[17];let R;t[18]!==z?(R=s.jsxs($s,{className:"flex items-center gap-2",children:[T,z]}),t[18]=z,t[19]=R):R=t[19];let W;t[20]!==e?(W=e("helpDialog.description"),t[20]=e,t[21]=W):W=t[21];let J;t[22]!==W?(J=s.jsx(Ks,{children:W}),t[22]=W,t[23]=J):J=t[23],t[24]!==R||t[25]!==J?(S=s.jsxs(Hs,{children:[R,J]}),t[24]=R,t[25]=J,t[26]=S):S=t[26],x="flex-1 overflow-y-auto mt-3 pr-1",f="space-y-4",p=A.map(U=>s.jsxs("div",{children:[s.jsx("h3",{className:"typography-meta font-semibold text-muted-foreground uppercase tracking-wider mb-2",children:e(U.categoryKey)}),s.jsx("div",{className:"space-y-1",children:U.items.filter(te=>!(d&&te.id==="toggle_prompt_navigator")).map(te=>{const Z=te.id?qd(te.id,Array.isArray(te.keys)?te.keys[0]:te.keys,o):Array.isArray(te.keys)?te.keys:te.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:[te.icon&&s.jsx(I,{name:te.icon,className:"h-3.5 w-3.5 text-muted-foreground"}),s.jsx("span",{className:"typography-meta",children:e(te.descriptionKey)})]}),s.jsx("div",{className:"flex items-center gap-1",children:(Array.isArray(Z)?Z:[Z]).map((ue,Oe)=>s.jsxs(a.Fragment,{children:[Oe>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:ue})]},`${ue}-${Oe}`))})]},te.id||te.descriptionKey)})})]},U.categoryKey)),t[2]=n,t[3]=r,t[4]=o,t[5]=e,t[6]=u,t[7]=h,t[8]=f,t[9]=p,t[10]=x,t[11]=b,t[12]=S,t[13]=g,t[14]=m}else u=t[6],h=t[7],f=t[8],p=t[9],x=t[10],b=t[11],S=t[12],g=t[13],m=t[14];let y;t[27]!==f||t[28]!==p?(y=s.jsx("div",{className:f,children:p}),t[27]=f,t[28]=p,t[29]=y):y=t[29];let C;t[30]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(I,{name:"question",className:"h-3.5 w-3.5 text-muted-foreground mt-0.5"}),t[30]=C):C=t[30];let j;t[31]!==e?(j=e("helpDialog.proTips.title"),t[31]=e,t[32]=j):j=t[32];let w;t[33]!==j?(w=s.jsx("p",{className:"font-medium mb-1",children:j}),t[33]=j,t[34]=w):w=t[34];let N;t[35]!==o||t[36]!==e?(N=e("helpDialog.proTips.commandPalette",{shortcut:qd("open_command_palette",`${c} P`,o)}),t[35]=o,t[36]=e,t[37]=N):N=t[37];let v;t[38]!==N?(v=s.jsxs("li",{children:["• ",N]}),t[38]=N,t[39]=v):v=t[39];let P;t[40]!==e?(P=e("helpDialog.proTips.recentSessions"),t[40]=e,t[41]=P):P=t[41];let F;t[42]!==P?(F=s.jsxs("li",{children:["• ",P]}),t[42]=P,t[43]=F):F=t[43];let k;t[44]!==e?(k=e("helpDialog.proTips.themeCycling"),t[44]=e,t[45]=k):k=t[45];let E;t[46]!==k?(E=s.jsxs("li",{children:["• ",k]}),t[46]=k,t[47]=E):E=t[47];let O;t[48]!==v||t[49]!==F||t[50]!==E?(O=s.jsxs("ul",{className:"space-y-0.5 typography-meta",children:[v,F,E]}),t[48]=v,t[49]=F,t[50]=E,t[51]=O):O=t[51];let M;t[52]!==w||t[53]!==O?(M=s.jsx("div",{className:"mt-4 p-2 bg-muted/30 rounded-xl",children:s.jsxs("div",{className:"flex items-start gap-2",children:[C,s.jsxs("div",{className:"typography-meta text-muted-foreground",children:[w,O]})]})}),t[52]=w,t[53]=O,t[54]=M):M=t[54];let L;t[55]!==M||t[56]!==x||t[57]!==y?(L=s.jsxs("div",{className:x,children:[y,M]}),t[55]=M,t[56]=x,t[57]=y,t[58]=L):L=t[58];let _;t[59]!==u||t[60]!==L||t[61]!==b||t[62]!==S?(_=s.jsxs(u,{className:b,children:[S,L]}),t[59]=u,t[60]=L,t[61]=b,t[62]=S,t[63]=_):_=t[63];let D;return t[64]!==h||t[65]!==_||t[66]!==g||t[67]!==m?(D=s.jsx(h,{open:g,onOpenChange:m,children:_}),t[64]=h,t[65]=_,t[66]=g,t[67]=m,t[68]=D):D=t[68],D};function m0(t){return t.isHelpDialogOpen}function h0(t){return t.setHelpDialogOpen}function p0(t){return t.shortcutOverrides}const g0=()=>{const t=nt.c(32),{t:e}=ft(),n=Re(x0),r=Re(b0),o=Re(y0);let i;t[0]!==o||t[1]!==e?(i=async()=>{if(!o)return;if((await rr(o)).ok){fe.success(e("openCodeStatusDialog.toast.copiedTitle"),{description:e("openCodeStatusDialog.toast.copiedDescription")});return}fe.error(e("openCodeStatusDialog.toast.copyFailed"))},t[0]=o,t[1]=e,t[2]=i):i=t[2];const c=i;let l;t[3]!==e?(l=e("openCodeStatusDialog.title"),t[3]=e,t[4]=l):l=t[4];let d;t[5]!==l?(d=s.jsx($s,{children:l}),t[5]=l,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 h;t[9]!==u?(h=s.jsx(Ks,{children:u}),t[9]=u,t[10]=h):h=t[10];let f;t[11]!==d||t[12]!==h?(f=s.jsxs(Hs,{children:[d,h]}),t[11]=d,t[12]=h,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 x;t[16]!==c||t[17]!==p?(x=s.jsx("div",{className:"flex items-center justify-end",children:s.jsx("button",{type:"button",onClick:c,className:"app-region-no-drag inline-flex h-9 items-center justify-center rounded-md px-3 typography-ui-label font-medium text-muted-foreground transition-colors hover:bg-interactive-hover hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:p})}),t[16]=c,t[17]=p,t[18]=x):x=t[18];let b;t[19]!==o||t[20]!==e?(b=o||e("openCodeStatusDialog.empty.noData"),t[19]=o,t[20]=e,t[21]=b):b=t[21];let S;t[22]!==b?(S=s.jsx("pre",{className:"max-h-[60vh] overflow-auto rounded-lg bg-surface-muted p-4 typography-code text-foreground whitespace-pre-wrap",children:b}),t[22]=b,t[23]=S):S=t[23];let g;t[24]!==f||t[25]!==x||t[26]!==S?(g=s.jsxs(Es,{className:"max-w-2xl",children:[f,x,S]}),t[24]=f,t[25]=x,t[26]=S,t[27]=g):g=t[27];let m;return t[28]!==n||t[29]!==r||t[30]!==g?(m=s.jsx(Ts,{open:n,onOpenChange:r,children:g}),t[28]=n,t[29]=r,t[30]=g,t[31]=m):m=t[31],m};function x0(t){return t.isOpenCodeStatusDialogOpen}function b0(t){return t.setOpenCodeStatusDialogOpen}function y0(t){return t.openCodeStatusText}const w0=180,Yd=600,v0=1,j0=6,S0=t=>{const e=t?.directory;return typeof e=="string"&&e.trim()?e:null},k0=({enabled:t=!0,currentSessionId:e,sortedSessions:n,recentSessions:r=[],prefetchSession:o})=>{const i=a.useRef(new Map),c=a.useRef([]),l=a.useRef(new Set),d=a.useRef(0),u=a.useMemo(()=>ir(),[]),h=a.useCallback(b=>`${b.directory}
194
- ${b.sessionId}`,[]),f=a.useCallback(()=>{d.current+=1,c.current=[],i.current.forEach(b=>window.clearTimeout(b)),i.current.clear()},[]),p=a.useCallback(()=>{if(!(!t||u||typeof window>"u"))for(;l.current.size<v0&&c.current.length>0;){const b=c.current.shift();if(!b)break;if(b.generation!==d.current||et.getState().currentSessionId===b.sessionId||Mc(b.sessionId,b.directory).renderable)continue;const g=h(b);l.current.add(g),o(b.sessionId,b.directory).catch(()=>{}).finally(()=>{l.current.delete(g),p()})}},[t,u,o,h]),x=a.useCallback(b=>{const S=b?.id,g=S0(b);if(!t||u||!S||!g||S===e||typeof window>"u")return;const m={sessionId:S,directory:g,generation:d.current},y=h(m);if(Mc(S,g).renderable||l.current.has(y)||c.current.some(w=>h(w)===y))return;const C=i.current.get(y);C!==void 0&&window.clearTimeout(C);const j=window.setTimeout(()=>{if(i.current.delete(y),m.generation!==d.current)return;const w=c.current;w.length>=j0&&w.shift(),w.push(m),p()},w0);i.current.set(y,j)},[e,t,u,p,h]);a.useEffect(()=>{f()},[f,e,t,u]),a.useEffect(()=>{if(!t||u||!e||n.length===0)return;const b=window.setTimeout(()=>{const S=n.findIndex(g=>g.id===e);S<0||(x(n[S-1]),x(n[S+1]))},Yd);return()=>window.clearTimeout(b)},[e,t,u,x,n]),a.useEffect(()=>{if(!t||u||!e||r.length===0)return;const b=window.setTimeout(()=>{const S=r.findIndex(g=>g.id===e);S<0||(x(r[S-1]),x(r[S+1]))},Yd);return()=>window.clearTimeout(b)},[e,t,u,r,x]),a.useEffect(()=>f,[f])},N0=t=>{const e=nt.c(3),n=et(C0);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],k0(r),null};function C0(t){return t.currentSessionId}const A0=t=>{const e=nt.c(12),{normalizedProjects:n,enabled:r,ownership:o,isSessionsLoading:i,hasAuthoritativeGlobalSessions:c,isWorktreeTopologyLoading:l,unresolvedWorktreeProjectPaths:d,foldersMap:u,createFolder:h,addSessionToFolder:f}=t,p=r===void 0?!0:r;let x,b;e[0]!==f||e[1]!==h||e[2]!==p||e[3]!==u||e[4]!==c||e[5]!==i||e[6]!==l||e[7]!==n||e[8]!==o||e[9]!==d?(x=()=>{!p||i||!c||l||n.forEach(S=>{if(d.has(S.normalizedPath))return;const g=uf(S.normalizedPath),m=o.archivedSessionsByProject.get(S.id)??[],y=u[g]??[],C=new Map(y.map(D0));m.forEach(j=>{const w=Lp(j,S.normalizedPath),N=w.toLowerCase();let v=C.get(N);v||(v=h(g,w),C.set(N,v)),v.sessionIds.includes(j.id)||f(g,v.id,j.id)})})},b=[n,p,o,i,c,l,d,u,h,f],e[0]=f,e[1]=h,e[2]=p,e[3]=u,e[4]=c,e[5]=i,e[6]=l,e[7]=n,e[8]=o,e[9]=d,e[10]=x,e[11]=b):(x=e[10],b=e[11]),a.useEffect(x,b)};function D0(t){return[t.name.toLowerCase(),t]}const P0=t=>{const e=nt.c(4);let n;e[0]!==t?(n=(i,c)=>{const l=t.get(i);if(!l||l.length===0)return c;const d=new Map(c.map(I0)),u=[];l.forEach(p=>{const x=d.get(p);x&&(u.push(x),d.delete(p))});const h=[],f=[];return c.forEach(p=>{d.has(p.id)&&(p.isArchivedBucket?f.push(p):h.push(p))}),[...h,...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 I0(t){return[t.id,t]}const R0=[],M0=t=>{const{normalizedProjects:e,getSessionsForProject:n,getArchivedSessionsForProject:r,availableWorktreesByProject:o,projectRepoStatus:i,projectRootBranches:c,lastRepoStatus:l,buildGroupedSessions:d,hasSessionSearchQuery:u,normalizedSessionSearchQuery:h,filterSessionNodesForSearch:f,buildGroupSearchText:p,foldersMap:x}=t,b=a.useRef(new Map),S=a.useMemo(()=>{const v=b.current,P=new Map;let F=0,k=0;const E=(M,L)=>M.length===L.length&&M.every((_,D)=>_===L[D]),O=e.map(M=>{const L=n(M.id),_=r(M.id),D=o.get(M.normalizedPath)??R0,A=i.has(M.id)?!!i.get(M.id):l,T=c.get(M.id)??null,z=v.get(M.id);if(z&&z.project===M&&E(z.activeSessions,L)&&E(z.archivedSessions,_)&&z.availableWorktrees===D&&z.rootBranch===T&&z.isRepo===A&&z.buildGroupedSessions===d)return F+=1,P.set(M.id,z),z.section;k+=1;const R=ff([...L,..._]),W=d(R,M.normalizedPath,D,T,A),J={project:M,groups:W};return P.set(M.id,{project:M,activeSessions:L,archivedSessions:_,availableWorktrees:D,rootBranch:T,isRepo:A,buildGroupedSessions:d,section:J}),J});return b.current=P,F>0&&sr("ui.sidebar.project_section.reused",F),k>0&&sr("ui.sidebar.project_section.rebuilt",k),O},[e,n,r,o,i,l,d,c]),g=a.useMemo(()=>S,[S]),m=a.useMemo(()=>{const v=new WeakMap;if(!u)return v;const P=F=>F.reduce((k,E)=>k+1+P(E.children),0);return g.forEach(F=>{F.groups.forEach(k=>{const E=f(k.sessions,h),O=P(E),M=p(k).includes(h),L=Vt(k.directory??null),D=(L?x[L]??[]:[]).filter(A=>A.name.toLowerCase().includes(h)).length;v.set(k,{filteredNodes:E,matchedSessionCount:O,folderNameMatchCount:D,groupMatches:M,hasMatch:M||O>0||D>0})})}),v},[u,g,f,h,p,x]),y=a.useMemo(()=>u?g.map(v=>({...v,groups:v.groups.filter(P=>m.get(P)?.hasMatch===!0)})).filter(v=>v.groups.length>0):g,[u,g,m]),C=u?y:g,j=a.useRef(new WeakMap),w=a.useMemo(()=>{const v=j.current;return C.map(P=>{const F=v.get(P);if(F&&F.query===h)return F.section;const k=P.groups.filter(A=>!A.isArchivedBucket),E=P.groups.filter(A=>A.isArchivedBucket),O=k.flatMap(A=>u?m.get(A)?.filteredNodes??[]:A.sessions),M=k.map(A=>({scopeKey:A.folderScopeKey??Vt(A.directory??null),directory:A.directory??null})).filter(A=>!!A.scopeKey),L=k.find(A=>A.isMain)??null,_={id:"flat",label:L?.label??"",branch:L?.branch??null,description:L?.description??null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:L?.directory??P.project.normalizedPath,folderScopeKey:L?.folderScopeKey??P.project.normalizedPath,folderScopes:M,sessions:O};if(u){const A=k.map(T=>m.get(T)).filter(T=>!!T);m.set(_,{filteredNodes:O,matchedSessionCount:A.reduce((T,z)=>T+z.matchedSessionCount,0),folderNameMatchCount:A.reduce((T,z)=>T+z.folderNameMatchCount,0),groupMatches:A.some(T=>T.groupMatches),hasMatch:A.some(T=>T.hasMatch)})}const D={project:P.project,groups:[_,...E]};return v.set(P,{query:h,section:D}),D})},[m,u,h,C]),N=a.useMemo(()=>u?C.reduce((v,P)=>v+P.groups.reduce((F,k)=>{const E=m.get(k);if(!E)return F;const O=E.folderNameMatchCount+(E.groupMatches?1:0);return F+E.matchedSessionCount+O},0),0):0,[u,C,m]);return{projectSections:S,visibleProjectSections:g,groupSearchDataByGroup:m,searchableProjectSections:y,sectionsForRender:C,flatSectionsForRender:w,searchMatchCount:N}},T0=t=>{const e=nt.c(26),{projectSections:n,activeProjectId:r,activeSessionByProject:o,setActiveSessionByProject:i,currentSessionId:c,handleSessionSelect:l,newSessionDraftOpen:d,mobileVariant:u,openNewSessionDraft:h,setActiveMainTab:f,setSessionSwitcherOpen:p}=t;let x,b;if(e[0]!==n){b=new Map,x=new Map;const N=(v,P,F,k)=>{b.has(v)||b.set(v,new Map);const E=b.get(v);k.forEach(O=>{const M=Vt(O.worktree?.path??O.session.directory??F??P);E.set(O.session.id,{directory:M}),x.has(v)||x.set(v,{id:O.session.id,directory:M}),O.children.length>0&&N(v,P,M,O.children)})};n.forEach(v=>{v.groups.forEach(P=>{N(v.project.id,v.project.normalizedPath,P.directory,P.sessions)})}),e[0]=n,e[1]=x,e[2]=b}else x=e[1],b=e[2];let S;e[3]!==x||e[4]!==b?(S={metaByProject:b,firstSessionByProject:x},e[3]=x,e[4]=b,e[5]=S):S=e[5];const g=S,m=a.useRef(null);let y,C;e[6]!==r||e[7]!==o||e[8]!==c||e[9]!==l||e[10]!==u||e[11]!==d||e[12]!==h||e[13]!==n||e[14]!==g||e[15]!==f||e[16]!==i||e[17]!==p?(y=()=>{if(!r||d||Re.getState().isNewWorktreeDialogOpen||m.current===r)return;const N=n.find(M=>M.project.id===r);if(!N)return;m.current=r;const v=g.metaByProject.get(r);if(c&&v&&v.has(c)){i(M=>{if(M.get(r)===c)return M;const L=new Map(M);return L.set(r,c),L});return}if(c&&v)return;if(!v||v.size===0){f("chat"),u&&p(!1),h({selectedProjectId:N.project.id,directoryOverride:N.project.normalizedPath});return}const P=o.get(r),F=P&&v.has(P)?P:null,k=g.firstSessionByProject.get(r)?.id??null,E=F??k;if(!E||E===c)return;const O=v.get(E)?.directory??null;l(E,O)},C=[r,o,c,l,d,u,h,n,g,f,p,i],e[6]=r,e[7]=o,e[8]=c,e[9]=l,e[10]=u,e[11]=d,e[12]=h,e[13]=n,e[14]=g,e[15]=f,e[16]=i,e[17]=p,e[18]=y,e[19]=C):(y=e[18],C=e[19]),a.useLayoutEffect(y,C);let j,w;e[20]!==r||e[21]!==c||e[22]!==g||e[23]!==i?(j=()=>{if(!r||!c)return;const N=g.metaByProject.get(r);!N||!N.has(c)||i(v=>{if(v.get(r)===c)return v;const P=new Map(v);return P.set(r,c),P})},w=[r,c,g,i],e[20]=r,e[21]=c,e[22]=g,e[23]=i,e[24]=j,e[25]=w):(j=e[24],w=e[25]),a.useEffect(j,w)},E0=t=>{const e=nt.c(15);let n,r,o;e[0]!==t?({initialActiveSessionByProject:r,persistActiveSessionByProject:o,...n}=t,e[0]=t,e[1]=n,e[2]=r,e[3]=o):(n=e[1],r=e[2],o=e[3]);const i=et(F0),c=et(O0);let l;e[4]!==r?(l=()=>new Map(r),e[4]=r,e[5]=l):l=e[5];const[d,u]=a.useState(l);let h;e[6]!==d||e[7]!==n||e[8]!==i||e[9]!==c?(h={...n,activeSessionByProject:d,setActiveSessionByProject:u,currentSessionId:i,newSessionDraftOpen:c},e[6]=d,e[7]=n,e[8]=i,e[9]=c,e[10]=h):h=e[10],T0(h);let f,p;return e[11]!==d||e[12]!==o?(f=()=>{o(d)},p=[d,o],e[11]=d,e[12]=o,e[13]=f,e[14]=p):(f=e[13],p=e[14]),a.useEffect(f,p),null};function F0(t){return t.currentSessionId}function O0(t){return!!t.newSessionDraft?.open}const Al=new Map,L0=(t,e)=>{for(const n of t){const r=Vt(n??null);r&&!Al.has(r)&&Al.set(r,e)}},Qd=t=>{const e=Vt(t??null);return e?Al.get(e)??0:0},Pi=t=>!!t.time?.archived,B0=t=>{const{t:e}=ft(),n=a.useCallback(c=>[c.label,c.branch??"",c.description??"",c.directory??""].join(" ").toLowerCase(),[]),r=a.useCallback(c=>{const l=Vt(c.directory??null)??"";return`${(c.title||e("sessions.sidebar.session.untitled")).trim()} ${l}`.toLowerCase()},[e]),o=a.useCallback((c,l)=>l?c.flatMap(d=>{if(r(d.session).includes(l))return[d];const h=o(d.children,l);return h.length===0?[]:[{...d,children:h}]}):c,[r]),i=a.useCallback((c,l,d,u,h)=>{const f=Vt(l??null),p=ff(c).sort((O,M)=>Mo(O,M,t.pinnedSessionIds,t.sessionOrderRanks)),x=new Map(p.map(O=>[O.id,O])),b=new Map;p.forEach(O=>{const M=O.parentID;if(!M)return;const L=x.get(M);if(!L||Pi(L)!==Pi(O))return;const _=b.get(M)??[];_.push(O),b.set(M,_)}),b.forEach(O=>O.sort((M,L)=>Mo(M,L,t.pinnedSessionIds,t.sessionOrderRanks)));const S=new Map;d.forEach(O=>{if(O.path){const M=Vt(O.path)??O.path;S.set(M,O)}});const g=O=>{const M=Vt(O.directory??null),L=t.worktreeMetadata.get(O.id)??null;if(L)return L;if(M){const _=S.get(M)??null;if(_&&M!==f)return _}return null},m=O=>{const M=b.get(O.id)??[];return{session:O,children:M.map(L=>m(L)),worktree:g(O)}},y=p.filter(O=>{const M=O.parentID;if(!M)return!0;const L=x.get(M);return L?Pi(L)!==Pi(O):!0}),C=new Map,j="__archived__",w=O=>{if(O.time?.archived)return j;if(t.isVSCode)return f??"__project_root__";const L=Vt(t.worktreeMetadata.get(O.id)?.path??null)??Bn(O);return L?L!==f&&S.has(L)?L:L===f?f??"__project_root__":j:j};y.forEach(O=>{const M=m(O),L=w(O);C.has(L)||C.set(L,[]),C.get(L)?.push(M)});const N=f??"__project_root__",v=[{id:"root",label:h&&u&&u!=="HEAD"?e("sessions.sidebar.grouping.projectRootWithBranch",{branch:u}):e("sessions.sidebar.grouping.projectRoot"),branch:u??null,description:f?Zi(f,t.homeDirectory):null,isMain:!0,isArchivedBucket:!1,worktree:null,directory:f,folderScopeKey:f,sessions:C.get(N)??[]}],P=new Map;d.forEach(O=>{const M=Vt(O.path)??O.path,L=C.get(M)??[],_=L.length>0,D=L.reduce((A,T)=>{const z=Bp(T.session,t.sessionOrderRanks);return Number.isFinite(z)?Math.max(A,z):A},0);P.set(M,{hasActiveSession:_,lastUpdatedAt:D})});const F=[...d].sort((O,M)=>{const L=Vt(O.path)??O.path,_=Vt(M.path)??M.path,D=P.get(L)??{hasActiveSession:!1,lastUpdatedAt:0},A=P.get(_)??{hasActiveSession:!1,lastUpdatedAt:0};if(D.hasActiveSession!==A.hasActiveSession)return D.hasActiveSession?-1:1;if(D.hasActiveSession&&A.hasActiveSession)return A.lastUpdatedAt-D.lastUpdatedAt;const T=Qd(O.path),z=Qd(M.path);if(T!==z)return z-T;const R=(O.label||O.branch||O.name||O.path||"").toLowerCase(),W=(M.label||M.branch||M.name||M.path||"").toLowerCase();return R.localeCompare(W)});(t.isVSCode?[]:F).forEach(O=>{const M=Vt(O.path)??O.path,L=t.gitBranches.get(M)?.trim()||null,_=O.branch?.trim()||null,A=!!(L&&_&&O.label&&Tc(O.label)===Tc(_))?L:O.label||O.name||Vr(M,t.homeDirectory)||M;v.push({id:`worktree:${M}`,label:A,branch:L||_,description:Zi(M,t.homeDirectory),isMain:!1,isArchivedBucket:!1,worktree:O,directory:M,folderScopeKey:M,sessions:C.get(M)??[]})});const E=C.get(j)??[];return E.length>0&&v.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?uf(f):null,sessions:E}),v},[t.homeDirectory,t.worktreeMetadata,t.pinnedSessionIds,t.sessionOrderRanks,t.gitBranches,t.isVSCode,e]);return{buildGroupSearchText:n,buildSessionSearchText:r,filterSessionNodesForSearch:o,buildGroupedSessions:i}},$0=t=>{const e=nt.c(11),{enabled:n,isSessionSearchOpen:r,setIsSessionSearchOpen:o,sessionSearchInputRef:i,sessionSearchContainerRef:c}=t,l=n===void 0?!0:n;let d,u;e[0]!==l||e[1]!==r||e[2]!==i?(d=()=>{if(!l||!r||typeof window>"u")return;const p=window.requestAnimationFrame(()=>{i.current?.focus(),i.current?.select()});return()=>window.cancelAnimationFrame(p)},u=[l,r,i],e[0]=l,e[1]=r,e[2]=i,e[3]=d,e[4]=u):(d=e[3],u=e[4]),a.useEffect(d,u);let h,f;e[5]!==l||e[6]!==r||e[7]!==c||e[8]!==o?(h=()=>{if(!l||!r||typeof document>"u")return;const p=x=>{c.current&&(c.current.contains(x.target)||o(!1))};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},f=[l,r,o,c],e[5]=l,e[6]=r,e[7]=c,e[8]=o,e[9]=h,e[10]=f):(h=e[9],f=e[10]),a.useEffect(h,f)},_0=t=>{const e=nt.c(46),{t:n}=ft(),[r,o]=a.useState(null),i=a.useRef(null);let c,l;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=()=>()=>{i.current&&clearTimeout(i.current)},l=[],e[0]=c,e[1]=l):(c=e[0],l=e[1]),a.useEffect(c,l);let d;e[2]!==t?(d=(R,W)=>{dl("navigation.session_select"),Re.getState().closeMainSurfaces();const J=()=>{!t.isSessionSearchOpen&&t.sessionSearchQuery.length===0||(t.setSessionSearchQuery(""),t.setIsSessionSearchOpen(!1))};if(t.mobileVariant&&(t.setActiveMainTab("chat"),t.setSessionSwitcherOpen(!1)),R===et.getState().currentSessionId){t.allowReselect&&t.onSessionSelected?.(R),J();return}dl("navigation.session_state_set"),t.setCurrentSession(R,W??null),t.onSessionSelected?.(R),J()},e[2]=t,e[3]=d):d=e[3];const u=d;let h;e[4]!==t?(h=(R,W)=>{t.setEditingId(R),t.setEditTitle(W)},e[4]=t,e[5]=h):h=e[5];const f=h;let p;e[6]!==t?(p=async R=>{if(!t.editingId)return;const W=(R??t.editTitle).trim();W&&await t.updateSessionTitle(t.editingId,W),t.setEditingId(null),t.setEditTitle("")},e[6]=t,e[7]=p):p=e[7];const x=p;let b;e[8]!==t?(b=()=>{t.setEditingId(null),t.setEditTitle("")},e[8]=t,e[9]=b):b=e[9];const S=b;let g;e[10]===Symbol.for("react.memo_cache_sentinel")?(g=async(R,W)=>{try{return(await rr(R)).ok?(o(W),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 m=g;let y;e[11]!==t||e[12]!==n?(y=async R=>{const W=await t.shareSession(R.id);if(!W?.share?.url){fe.error(n("sessions.sidebar.session.share.error"));return}const J=await m(W.share.url,R.id);fe[J?"success":"warning"](n("sessions.sidebar.session.share.successTitle"),{description:n(J?"sessions.sidebar.session.share.successDescription":"sessions.sidebar.session.share.copyUrlError")})},e[11]=t,e[12]=n,e[13]=y):y=e[13];const C=y;let j;e[14]!==n?(j=(R,W)=>{m(R,W).then(J=>{J||fe.error(n("sessions.sidebar.session.share.copyUrlError"))})},e[14]=n,e[15]=j):j=e[15];const w=j;let N;e[16]!==n?(N=R=>{rr(R).then(W=>{if(W.ok){fe.success(n("sessions.sidebar.session.copyId.success"));return}fe.error(n("sessions.sidebar.session.copyId.error"))}).catch(()=>fe.error(n("sessions.sidebar.session.copyId.error")))},e[16]=n,e[17]=N):N=e[17];const v=N;let P;e[18]!==t||e[19]!==n?(P=async R=>{await t.unshareSession(R)?fe.success(n("sessions.sidebar.session.unshare.success")):fe.error(n("sessions.sidebar.session.unshare.error"))},e[18]=t,e[19]=n,e[20]=P):P=e[20];const F=P;let k;e[21]!==t.childrenMap?(k=R=>{const W=[],J=U=>{(t.childrenMap.get(U)??[]).forEach(Z=>{W.push(Z),J(Z.id)})};return J(R),W},e[21]=t.childrenMap,e[22]=k):k=e[22];const E=k,O=V0;let M;e[23]!==t||e[24]!==E||e[25]!==n?(M=async(R,W,J)=>{const U=W?.archivedBucket===!0||W?.hardDelete===!0,te=J?.descendantIds??O(E(R.id),U).map(W0);if(te.length===0){(U?await t.deleteSession(R.id):await t.archiveSession(R.id))?fe.success(n(U?"sessions.sidebar.session.delete.success":"sessions.sidebar.session.archive.success")):fe.error(n(U?"sessions.sidebar.session.delete.error":"sessions.sidebar.session.archive.error"));return}const Z=[R.id,...te];if(U){const{deletedIds:se,failedIds:G}=await t.deleteSessions(Z);if(G.length===0){const Ie=se.length;fe.success(Ie===1?n("sessions.sidebar.bulkActions.deletedSingle",{count:Ie}):n("sessions.sidebar.bulkActions.deletedPlural",{count:Ie}))}else fe.error(n("sessions.sidebar.session.delete.error"));return}const{archivedIds:ue,failedIds:Oe}=await t.archiveSessions(Z);ue.length>0&&fe.success(ue.length===1?n("sessions.sidebar.bulkActions.archivedSingle",{count:ue.length}):n("sessions.sidebar.bulkActions.archivedPlural",{count:ue.length})),Oe.length>0&&fe.error(Oe.length===1?n("sessions.sidebar.bulkActions.failedArchiveSingle",{count:Oe.length}):n("sessions.sidebar.bulkActions.failedArchivePlural",{count:Oe.length}))},e[23]=t,e[24]=E,e[25]=n,e[26]=M):M=e[26];const L=M;let _;e[27]!==t||e[28]!==E||e[29]!==L?(_=(R,W)=>{const J=W?.archivedBucket===!0||W?.hardDelete===!0,U=O(E(R.id),J).map(U0);if(!t.showDeletionDialog||W?.skipConfirm===!0){L(R,W,{descendantIds:U});return}t.setDeleteSessionConfirm({session:R,descendantCount:U.length,descendantIds:U,archivedBucket:J})},e[27]=t,e[28]=E,e[29]=L,e[30]=_):_=e[30];const D=_;let A;e[31]!==t||e[32]!==L?(A=async()=>{if(!t.deleteSessionConfirm)return;const{session:R,archivedBucket:W,descendantIds:J}=t.deleteSessionConfirm;t.setDeleteSessionConfirm(null),await L(R,{archivedBucket:W},{descendantIds:J})},e[31]=t,e[32]=L,e[33]=A):A=e[33];const T=A;let z;return e[34]!==T||e[35]!==r||e[36]!==S||e[37]!==v||e[38]!==w||e[39]!==D||e[40]!==x||e[41]!==f||e[42]!==u||e[43]!==C||e[44]!==F?(z={copiedSessionId:r,handleSessionSelect:u,handleSessionDoubleClick:f,handleSaveEdit:x,handleCancelEdit:S,handleShareSession:C,handleCopyShareUrl:w,handleCopySessionId:v,handleUnshareSession:F,handleDeleteSession:D,confirmDeleteSession:T},e[34]=T,e[35]=r,e[36]=S,e[37]=v,e[38]=w,e[39]=D,e[40]=x,e[41]=f,e[42]=u,e[43]=C,e[44]=F,e[45]=z):z=e[45],z};function z0(t){return!t.time?.archived}function V0(t,e){return e?t:t.filter(z0)}function W0(t){return t.id}function U0(t){return t.id}const H0=t=>{const e=nt.c(26),{isVSCode:n,safeStorage:r,keys:o,groupOrderByProject:i,collapsedGroups:c,setExpandedParents:l,setCollapsedProjects:d}=t,u=a.useRef(null),h=a.useRef(null);let f;e[0]!==n?(f=()=>{if(n)return;const P=h.current;if(h.current=null,u.current=null,!P)return;const{projects:F}=ms.getState(),k=F.map(E=>({...E,sidebarCollapsed:P.has(E.id)}));Fl({projects:k}).catch(K0)},e[0]=n,e[1]=f):f=e[1];const p=f;let x;e[2]!==p||e[3]!==n?(x=P=>{typeof window>"u"||n||(h.current=P,u.current!==null&&window.clearTimeout(u.current),u.current=window.setTimeout(()=>{p()},700))},e[2]=p,e[3]=n,e[4]=x):x=e[4];const b=x;let S,g;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=()=>()=>{typeof window<"u"&&u.current!==null&&window.clearTimeout(u.current),u.current=null,h.current=null},g=[],e[5]=S,e[6]=g):(S=e[5],g=e[6]),a.useEffect(S,g);let m,y;e[7]!==o.projectCollapse||e[8]!==o.sessionExpanded||e[9]!==r||e[10]!==d||e[11]!==l?(m=()=>{try{const P=r.getItem(o.sessionExpanded);if(P){const k=JSON.parse(P);Array.isArray(k)&&l(new Set(k.filter(G0)))}const F=r.getItem(o.projectCollapse);if(F){const k=JSON.parse(F);Array.isArray(k)&&d(new Set(k.filter(q0)))}}catch{}},y=[o.projectCollapse,o.sessionExpanded,r,d,l],e[7]=o.projectCollapse,e[8]=o.sessionExpanded,e[9]=r,e[10]=d,e[11]=l,e[12]=m,e[13]=y):(m=e[12],y=e[13]),a.useEffect(m,y);let C,j;e[14]!==i||e[15]!==o.groupOrder||e[16]!==r?(C=()=>{try{const P=Object.fromEntries(i.entries());r.setItem(o.groupOrder,JSON.stringify(P))}catch{}},j=[i,o.groupOrder,r],e[14]=i,e[15]=o.groupOrder,e[16]=r,e[17]=C,e[18]=j):(C=e[17],j=e[18]),a.useEffect(C,j);let w,N;e[19]!==c||e[20]!==o.groupCollapse||e[21]!==r?(w=()=>{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]=w,e[23]=N):(w=e[22],N=e[23]),a.useEffect(w,N);let v;return e[24]!==b?(v={scheduleCollapsedProjectsPersist:b},e[24]=b,e[25]=v):v=e[25],v};function K0(){}function G0(t){return typeof t=="string"}function q0(t){return typeof t=="string"}const Y0=5*6e4,Q0=t=>{const e=nt.c(31),{normalizedProjects:n,enabled:r,gitRepoStatus:o,setProjectRepoStatus:i,setProjectRootBranches:c}=t,l=r===void 0?!0:r,{git:d}=_n(),u=tn(X0);let h,f;e[0]!==l||e[1]!==u||e[2]!==d||e[3]!==n||e[4]!==i?(h=()=>{if(!l||!d||n.length===0){i(new Map);return}n.forEach(N=>{ml(()=>u(N.normalizedPath,d))})},f=[l,n,d,u,i],e[0]=l,e[1]=u,e[2]=d,e[3]=n,e[4]=i,e[5]=h,e[6]=f):(h=e[5],f=e[6]),a.useEffect(h,f);let p,x;e[7]!==l||e[8]!==o||e[9]!==n||e[10]!==i?(p=()=>{if(!l)return;const N=new Map;n.forEach(v=>{N.set(v.id,o.get(v.normalizedPath)?.isGitRepo??null)}),i(N)},x=[l,n,o,i],e[7]=l,e[8]=o,e[9]=n,e[10]=i,e[11]=p,e[12]=x):(p=e[11],x=e[12]),a.useEffect(p,x);let b;if(e[13]!==o||e[14]!==n){let N;e[16]!==o?(N=v=>{const P=o.get(v.normalizedPath)?.branch??"";return`${v.id}:${P}`},e[16]=o,e[17]=N):N=e[17],b=n.map(N).join("|"),e[13]=o,e[14]=n,e[15]=b}else b=e[15];const S=b;let g;e[18]===Symbol.for("react.memo_cache_sentinel")?(g=new Map,e[18]=g):g=e[18];const m=a.useRef(g);let y;e[19]===Symbol.for("react.memo_cache_sentinel")?(y=new Map,e[19]=y):y=e[19];const C=a.useRef(y);let j;e[20]!==l||e[21]!==o||e[22]!==n||e[23]!==c?(j=()=>{if(!l)return;let N=!1;const v=setTimeout(()=>{(async()=>{const F=new Set(n.map(J0));for(const _ of m.current.keys())F.has(_)||(m.current.delete(_),C.current.delete(_));const k=Date.now(),E=n.filter(_=>{const D=o.get(_.normalizedPath);if(D?.isGitRepo===!1)return m.current.delete(_.id),C.current.delete(_.id),!1;if(D?.isGitRepo!==!0||D.branch===null)return!1;const A=D.branch.trim(),T=`${_.normalizedPath}\0${A}`,z=m.current.get(_.id);if(z===T){const R=C.current.get(_.id);return R&&(R.at=k),!1}return!(z!==void 0&&k-(C.current.get(_.id)?.at??0)<Y0)});if(E.length===0)return;const O=await $p(E,2,async _=>{const D=o.get(_.normalizedPath)?.branch?.trim()??"",A=`${_.normalizedPath}\0${D}`,T=await ml(()=>pi(_.normalizedPath,D?{knownBranch:D}:void 0)).catch(Z0);return{id:_.id,inputKey:A,branch:T}});if(N)return;const M=O.filter(eS);if(M.length===0)return;const L=Date.now();c(_=>{const D=new Map(_);return M.forEach(A=>{const{id:T,branch:z}=A;z&&D.set(T,z)}),D}),M.forEach(_=>{const{id:D,inputKey:A,branch:T}=_;m.current.set(D,A),T&&C.current.set(D,{branch:T,at:L})})})()},150);return()=>{N=!0,clearTimeout(v)}},e[20]=l,e[21]=o,e[22]=n,e[23]=c,e[24]=j):j=e[24];let w;e[25]!==l||e[26]!==o||e[27]!==n||e[28]!==S||e[29]!==c?(w=[l,n,S,o,c],e[25]=l,e[26]=o,e[27]=n,e[28]=S,e[29]=c,e[30]=w):w=e[30],a.useEffect(j,w)};function X0(t){return t.ensureStatus}function J0(t){return t.id}function Z0(){return null}function eS(t){return t.branch}const tS=t=>{const e=nt.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 l;return e[4]!==c||e[5]!==o?(l={getSessionsForProject:o,getArchivedSessionsForProject:c},e[4]=c,e[5]=o,e[6]=l):l=e[6],l},sS=t=>{const e=new Map;for(const n of t){const r=Bn(n);r&&e.set(n.id,{directory:r,sessionId:n.id})}return e},nS=(t,e)=>{if(!t)return[];const n=[];return t.forEach((r,o)=>{e.has(o)||n.push(r)}),n},rS=t=>{const e=nt.c(5),{enabled:n,hasAuthoritativeGlobalSessions:r,sessions:o}=t,i=n===void 0?!0:n,c=a.useRef(null);let l,d;e[0]!==i||e[1]!==r||e[2]!==o?(l=()=>{if(!i||!r)return;const u=$n(),h=sS(o),f=c.current?.runtimeKey===u?c.current.identities:null;for(const p of nS(f,h))_p({runtimeKey:u,...p});c.current={runtimeKey:u,identities:h}},d=[i,r,o],e[0]=i,e[1]=r,e[2]=o,e[3]=l,e[4]=d):(l=e[3],d=e[4]),a.useEffect(l,d)},oS=(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,Xd=(t,e,n)=>{oS(t.get(e),n)&&t.set(e,n)},iS=t=>{const e=t;return Vt(e.directory)??Vt(e.project?.worktree)},aS=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)},lS=(t,e,n,r,o=[])=>{const i=new Map,c=new Map;for(const b of e){const S=Vt(b.normalizedPath);if(!S)continue;const g=c.get(S);(!g||b.id.localeCompare(g.id)<0)&&c.set(S,b),Xd(i,S,{projectId:b.id,projectRoot:S,scopeDirectory:S,kind:"project"})}if(!r)for(const[b,S]of n){const g=Vt(b),m=g?c.get(g):void 0;if(!(!m||!g))for(const y of S){const C=Vt(y.path);C&&Xd(i,C,{projectId:m.id,projectRoot:g,scopeDirectory:C,kind:"worktree"})}}const l=new Map,d=new Map,u=new Map,h=new Map,f=new Map,p=b=>{if(!b)return null;if(l.has(b))return l.get(b)??null;if(r){const y=i.get(b)??null;return l.set(b,y),y}const S=[];let g=b,m=null;for(;g;){if(l.has(g)){m=l.get(g)??null;break}if(S.push(g),m=i.get(g)??null,m)break;g=aS(g)}for(const y of S)l.set(y,m);return m},x=(b,S,g)=>{for(const m of b){const y=p(iS(m));if(!y)continue;d.set(m.id,y);const C=S.get(y.projectId);if(C?C.push(m):S.set(y.projectId,[m]),!g)continue;const j=g.get(y.scopeDirectory);j?j.add(m.id):g.set(y.scopeDirectory,new Set([m.id]))}};return x(t,u,f),x(o,h),{bySessionId:d,sessionsByProject:u,archivedSessionsByProject:h,sessionsByScope:f,directoryResolutions:l.size}},cS=t=>{const e=nt.c(10),{enabled:n,isDesktopShellRuntime:r,projectSections:o,projectHeaderSentinelRefs:i}=t,c=n===void 0?!0:n;let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l=new Set,e[0]=l):l=e[0];const[d,u]=a.useState(l);let h;e[1]!==c||e[2]!==r||e[3]!==i?(h=()=>{if(!c||!r){u(dS);return}const x=Array.from(i.current.values()).find(uS)?.closest(".oc-sidebar-scroller")??null;if(!x)return;const b=new IntersectionObserver(S=>{u(g=>{const m=new Set(g);let y=!1;for(const C of S){const j=C.target.dataset.projectId;if(!j)continue;const w=C.rootBounds?.top??x.getBoundingClientRect().top,N=!C.isIntersecting&&C.boundingClientRect.top<w;m.has(j)!==N&&(y=!0,N?m.add(j):m.delete(j))}return y?m:g})},{root:x,threshold:0});return i.current.forEach(S=>{S&&b.observe(S)}),()=>b.disconnect()},e[1]=c,e[2]=r,e[3]=i,e[4]=h):h=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],a.useEffect(h,f),d};function dS(t){return t.size===0?t:new Set}function uS(t){return t!==null}const fS=t=>{const e=nt.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(hx,{project:o,onIdentitySave:i,showWorktrees:!1}):null,e[0]=i,e[1]=n,e[2]=o,e[3]=c):c=e[3];let l;e[4]!==c?(l=s.jsx(Es,{className:"w-full max-w-2xl gap-0 overflow-hidden p-0",children:s.jsx(On,{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]=l):l=e[5];let d;return e[6]!==r||e[7]!==n||e[8]!==l?(d=s.jsx(Ts,{open:n,onOpenChange:r,children:l}),e[6]=r,e[7]=n,e[8]=l,e[9]=d):d=e[9],d};function Rm(t){const e=nt.c(10),{state:n,activeLabel:r,unreadLabel:o,className:i}=t,c=n==="active"?r:o;if(n==="active"){let u;e[0]!==i?(u=De("h-3 w-3 shrink-0 animate-spin text-primary",i),e[0]=i,e[1]=u):u=e[1];let h;return e[2]!==c||e[3]!==u?(h=s.jsx(I,{name:"loader-4",className:u,"aria-label":c}),e[2]=c,e[3]=u,e[4]=h):h=e[4],h}let l;e[5]!==i?(l=De("h-1.5 w-1.5 shrink-0 rounded-full","bg-[var(--status-info)]",i),e[5]=i,e[6]=l):l=e[6];let d;return e[7]!==c||e[8]!==l?(d=s.jsx("span",{className:l,"aria-label":c,title:c}),e[7]=c,e[8]=l,e[9]=d):d=e[9],d}const mS=t=>{const e=nt.c(86),{folder:n,displayName:r,sessions:o,subFolderItems:i,isCollapsed:c,collapsedActivityState:l,onToggle:d,onRename:u,onDelete:h,renderSessionNode:f,getRenderExtras:p,groupDirectory:x,projectId:b,mobileVariant:S,alwaysShowActions:g,isRenaming:m,renameDraft:y,onRenameDraftChange:C,onRenameSave:j,onRenameCancel:w,droppableRef:N,isDropTarget:v,onNewSession:P,depth:F,hideActions:k,archivedBucket:E}=t,O=l===void 0?null:l,L=g===void 0?S===void 0?!1:S:g,_=m===void 0?!1:m,D=y===void 0?"":y,A=v===void 0?!1:v,T=k===void 0?!1:k,z=E===void 0?!1:E,{t:R}=ft(),[W,J]=a.useState(!1),[U,te]=a.useState(""),Z=a.useRef(null),ue=_||W,Oe=_?D:U;let se;e[0]!==n.name?(se=()=>{te(n.name),J(!0)},e[0]=n.name,e[1]=se):se=e[1];const G=se;let Ie;e[2]!==Oe||e[3]!==n.name||e[4]!==_||e[5]!==u||e[6]!==j?(Ie=()=>{const ge=Oe.trim();ge&&ge!==n.name&&u(ge),_&&j&&j(),J(!1),te("")},e[2]=Oe,e[3]=n.name,e[4]=_,e[5]=u,e[6]=j,e[7]=Ie):Ie=e[7];const pe=Ie;let V;e[8]!==_||e[9]!==w?(V=()=>{_&&w&&w(),J(!1),te("")},e[8]=_,e[9]=w,e[10]=V):V=e[10];const Q=V;let ne;e[11]!==_||e[12]!==C?(ne=ge=>{_&&C?C(ge):te(ge)},e[11]=_,e[12]=C,e[13]=ne):ne=e[13];const oe=ne;let ce,ke;e[14]!==_?(ce=()=>{if(!_)return;const ge=()=>{const xe=Z.current;xe&&(xe.focus(),xe.select())},$=requestAnimationFrame(ge),B=window.setTimeout(ge,0);return()=>{cancelAnimationFrame($),window.clearTimeout(B)}},ke=[_],e[14]=_,e[15]=ce,e[16]=ke):(ce=e[15],ke=e[16]),a.useEffect(ce,ke);const ye=c?"folder":"folder-open",he=A&&"bg-primary/10 ring-1 ring-inset ring-primary/30";let Ee;e[17]!==he?(Ee=De("group/folder relative flex items-center justify-between gap-1.5 py-1 min-w-0 rounded-md","cursor-pointer",he),e[17]=he,e[18]=Ee):Ee=e[18];let Ue;e[19]!==d||e[20]!==ue?(Ue=ue?void 0:ge=>{ge.currentTarget.blur(),d()},e[19]=d,e[20]=ue,e[21]=Ue):Ue=e[21];const Me=ue?void 0:"button",X=ue?void 0:0;let Ne;e[22]!==d||e[23]!==ue?(Ne=ue?void 0:ge=>{(ge.key==="Enter"||ge.key===" ")&&(ge.preventDefault(),d())},e[22]=d,e[23]=ue,e[24]=Ne):Ne=e[24];let Ae;e[25]!==n.name||e[26]!==c||e[27]!==R?(Ae=c?R("sessions.sidebar.folderItem.expandAria",{folderName:n.name}):R("sessions.sidebar.folderItem.collapseAria",{folderName:n.name}),e[25]=n.name,e[26]=c,e[27]=R,e[28]=Ae):Ae=e[28];const Se=z?L?"pr-7":"group-hover/folder:pr-7 group-focus-within/folder:pr-7":L?"pr-20":"group-hover/folder:pr-20 group-focus-within/folder:pr-20";let le;e[29]!==Se?(le=De("min-w-0 flex items-center gap-1.5 pl-1.5 flex-1 transition-[padding]",Se),e[29]=Se,e[30]=le):le=e[30];const ee=A?"text-primary":"text-muted-foreground";let ie;e[31]!==ee?(ie=De("h-3.5 w-3.5 flex-shrink-0",ee),e[31]=ee,e[32]=ie):ie=e[32];let ve;e[33]!==ye||e[34]!==ie?(ve=s.jsx(I,{name:ye,className:ie}),e[33]=ye,e[34]=ie,e[35]=ve):ve=e[35];let K;e[36]!==O||e[37]!==r||e[38]!==Oe||e[39]!==n.name||e[40]!==Q||e[41]!==oe||e[42]!==pe||e[43]!==c||e[44]!==A||e[45]!==ue||e[46]!==o||e[47]!==R?(K=ue?s.jsxs("form",{className:"flex min-w-0 flex-1 items-center gap-1",onPointerDown:pS,onMouseDown:gS,onSubmit:ge=>{ge.preventDefault(),pe()},children:[s.jsx("input",{ref:Z,value:Oe,onChange:ge=>oe(ge.target.value),className:"flex-1 min-w-0 bg-transparent typography-ui-label outline-none placeholder:text-muted-foreground",autoFocus:!0,placeholder:R("sessions.sidebar.folderItem.namePlaceholder"),onClick:xS,onPointerDown:bS,onMouseDown:yS,onKeyDown:ge=>{if(ge.key==="Escape"){ge.stopPropagation(),Q();return}(ge.key===" "||ge.key==="Enter")&&ge.stopPropagation()}}),s.jsx("button",{type:"submit",className:"shrink-0 text-muted-foreground hover:text-foreground",onClick:wS,onPointerDown:vS,onMouseDown:jS,children:s.jsx(I,{name:"check",className:"size-4"})}),s.jsx("button",{type:"button",onClick:ge=>{ge.stopPropagation(),Q()},onPointerDown:SS,onMouseDown:kS,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(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:De("typography-ui-label font-semibold truncate",A?"text-primary":"text-muted-foreground"),children:r??n.name})}),s.jsx(At,{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]}),O?s.jsx(Rm,{state:O,activeLabel:R("sessions.sidebar.session.status.active"),unreadLabel:R("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]=O,e[37]=r,e[38]=Oe,e[39]=n.name,e[40]=Q,e[41]=oe,e[42]=pe,e[43]=c,e[44]=A,e[45]=ue,e[46]=o,e[47]=R,e[48]=K):K=e[48];let de;e[49]!==le||e[50]!==ve||e[51]!==K?(de=s.jsxs("div",{className:le,children:[ve,K]}),e[49]=le,e[50]=ve,e[51]=K,e[52]=de):de=e[52];let _e;e[53]!==L||e[54]!==z||e[55]!==n.name||e[56]!==G||e[57]!==T||e[58]!==h||e[59]!==P||e[60]!==ue||e[61]!==R?(_e=!ue&&(!T||z)?s.jsx("div",{className:De("absolute right-0.5 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",L?"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:[!z&&P?s.jsx("button",{type:"button",onClick:ge=>{ge.stopPropagation(),P()},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":R("sessions.sidebar.folderItem.newSessionAria",{folderName:n.name}),title:R("sessions.sidebar.project.actions.newSession"),children:s.jsx(I,{name:"add",className:"h-3.5 w-3.5"})}):null,z?null:s.jsx("button",{type:"button",onClick:ge=>{ge.stopPropagation(),G()},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":R("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:ge=>{ge.stopPropagation(),h()},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":z?R("sessions.sidebar.folderItem.deleteArchivedInFolderAria",{folderName:n.name}):R("sessions.sidebar.folderItem.deleteFolderAria",{folderName:n.name}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})}):null,e[53]=L,e[54]=z,e[55]=n.name,e[56]=G,e[57]=T,e[58]=h,e[59]=P,e[60]=ue,e[61]=R,e[62]=_e):_e=e[62];let Pe;e[63]!==N||e[64]!==Ee||e[65]!==Ue||e[66]!==Me||e[67]!==X||e[68]!==Ne||e[69]!==Ae||e[70]!==de||e[71]!==_e?(Pe=s.jsxs("div",{ref:N,className:Ee,onClick:Ue,role:Me,tabIndex:X,onKeyDown:Ne,"aria-label":Ae,children:[de,_e]}),e[63]=N,e[64]=Ee,e[65]=Ue,e[66]=Me,e[67]=X,e[68]=Ne,e[69]=Ae,e[70]=de,e[71]=_e,e[72]=Pe):Pe=e[72];let re;e[73]!==z||e[74]!==p||e[75]!==x||e[76]!==c||e[77]!==b||e[78]!==f||e[79]!==o||e[80]!==i||e[81]!==R?(re=c?null:s.jsxs("div",{className:"pb-1",children:[i,o.length>0?o.map(ge=>f(ge,0,x??null,b??null,z,void 0,"project",p?.(ge))):i?null:s.jsx("div",{className:"py-1 pl-1.5 text-left typography-micro text-muted-foreground/70",children:R("sessions.sidebar.folderItem.emptyFolder")})]}),e[73]=z,e[74]=p,e[75]=x,e[76]=c,e[77]=b,e[78]=f,e[79]=o,e[80]=i,e[81]=R,e[82]=re):re=e[82];let me;return e[83]!==Pe||e[84]!==re?(me=s.jsxs("div",{className:"oc-folder",children:[Pe,re]}),e[83]=Pe,e[84]=re,e[85]=me):me=e[85],me},hS=a.memo(mS);function pS(t){return t.stopPropagation()}function gS(t){return t.stopPropagation()}function xS(t){return t.stopPropagation()}function bS(t){return t.stopPropagation()}function yS(t){return t.stopPropagation()}function wS(t){return t.stopPropagation()}function vS(t){return t.stopPropagation()}function jS(t){return t.stopPropagation()}function SS(t){return t.stopPropagation()}function kS(t){return t.stopPropagation()}const NS=t=>{const e=nt.c(15),{sessionId:n,sessionDirectory:r,sessionTitle:o,children:i}=t,c=`session-drag:${n}`;let l;e[0]!==r||e[1]!==n||e[2]!==o?(l={type:"session",sessionId:n,sessionDirectory:r,sessionTitle:o},e[0]=r,e[1]=n,e[2]=o,e[3]=l):l=e[3];let d;e[4]!==c||e[5]!==l?(d={id:c,data:l},e[4]=c,e[5]=l,e[6]=d):d=e[6];const{attributes:u,listeners:h,setNodeRef:f,isDragging:p}=Hx(d);let x;e[7]!==h?(x=m=>{m.stopPropagation(),h?.onPointerDown&&h.onPointerDown(m)},e[7]=h,e[8]=x):x=e[8];const b=x,S=p?"opacity-30":void 0;let g;return e[9]!==u||e[10]!==i||e[11]!==b||e[12]!==f||e[13]!==S?(g=s.jsx("div",{ref:f,...u,onPointerDown:b,className:S,children:i}),e[9]=u,e[10]=i,e[11]=b,e[12]=f,e[13]=S,e[14]=g):g=e[14],g},CS=t=>{const e=nt.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:l,isOver:d}=Ux(c);let u;e[5]!==r||e[6]!==d||e[7]!==l?(u=r(l,d),e[5]=r,e[6]=d,e[7]=l,e[8]=u):u=e[8];let h;return e[9]!==u?(h=s.jsx(s.Fragment,{children:u}),e[9]=u,e[10]=h):h=e[10],h},AS=t=>{const e=nt.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 l=ra(No(bl,c)),[d,u]=a.useState(null),[h,f]=a.useState("Session"),[p,x]=a.useState(null),[b,S]=a.useState(null);if(!n){let v;return e[1]!==i?(v=s.jsx(s.Fragment,{children:i}),e[1]=i,e[2]=v):v=e[2],v}let g;e[3]!==o?(g=v=>{u(null),x(null),S(null);const{active:P,over:F}=v;if(!F)return;const k=P.data.current,E=F.data.current;k?.type==="session"&&k.sessionId&&E?.type==="folder"&&E.folderId&&o(k.sessionId,E.folderId)},e[3]=o,e[4]=g):g=e[4];const m=g;let y,C;e[5]===Symbol.for("react.memo_cache_sentinel")?(y=v=>{const P=v.active.data.current;if(P?.type==="session"&&P.sessionId){u(P.sessionId),f(P.sessionTitle??"Session");const F=v.active.rect.current.initial?.width,k=v.active.rect.current.initial?.height;x(typeof F=="number"?F:null),S(typeof k=="number"?k:null)}},C=()=>{u(null),x(null),S(null)},e[5]=y,e[6]=C):(y=e[5],C=e[6]);let j;e[7]!==b||e[8]!==d||e[9]!==h||e[10]!==p||e[11]!==r?(j=d&&r?s.jsxs("div",{style:{width:p?`${p}px`:"auto",height:b?`${b}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:h})]}):null,e[7]=b,e[8]=d,e[9]=h,e[10]=p,e[11]=r,e[12]=j):j=e[12];let w;e[13]!==j?(w=s.jsx(yl,{children:j}),e[13]=j,e[14]=w):w=e[14];let N;return e[15]!==i||e[16]!==m||e[17]!==l||e[18]!==w?(N=s.jsxs(oa,{sensors:l,collisionDetection:ia,onDragStart:y,onDragCancel:C,onDragEnd:m,children:[i,w]}),e[15]=i,e[16]=m,e[17]=l,e[18]=w,e[19]=N):N=e[19],N},Dl=(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)},Sr=(t,e)=>{if(!e)return!1;if(t.session.id===e)return!0;for(const n of t.children)if(Sr(n,e))return!0;return!1},DS=(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})},Jd=new WeakMap;let Zd=1;const PS=t=>{const e=Jd.get(t);if(e!==void 0)return e;const n=Zd;return Zd+=1,Jd.set(t,n),n},ca=t=>t.children.length===0?"":t.children.map(n=>{const r=PS(n.session);return n.children.length===0?`${n.session.id}@${r}`:`${n.session.id}@${r}:${ca(n)}`}).join("|"),Mm=(t,e,n,r,o,i)=>{const c=$n(),l=(d,u)=>{if(d.session.id!==u.session.id||d.children.length!==u.children.length)return!0;const h=d.session.directory??o,f=u.session.directory??i,p=Ec(c,h??"",d.session.id),x=Ec(c,f??"",u.session.id);return(p?n.has(p):!1)!==(x?r.has(x):!1)?!0:d.children.some((b,S)=>l(b,u.children[S]))};return l(t,e)},fi=(t,e,n,r)=>{if(!e)return null;const o=r?"archived":"active";let i=null;const c=l=>{if(`${n}:${o}:${l.session.id}`===e)return i=l.session.id,!0;for(const u of l.children)if(c(u))return!0;return!1};return t.forEach(l=>c(l)),i},pc=(t,e)=>t==="active"||e==="active"?"active":t==="unread"||e==="unread"?"unread":null,Tm=(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=pc(o,Tm(c,e,n,r)),o==="active")return o;return o},eu=(t,e,n,r)=>{let o=null;for(const i of t)if(o=pc(o,Tm(i,e,n,r)),o==="active")return o;return o},IS=50,RS=28,Ii=(t,e)=>e?t.sessions.some(n=>Sr(n,e)):!1,MS=(t,e,n)=>t.sessions.some(r=>Mm(r,r,e,n,t.directory,t.directory)),TS=(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)},tu=(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)},ES=(t,e)=>{const n=r=>e.has(r.session.id)?!0:r.children.some(n);return t.sessions.some(n)},FS=(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)},OS=(t,e)=>{if(t.group!==e.group||t.groupKey!==e.groupKey||t.projectId!==e.projectId||t.hideGroupLabel!==e.hideGroupLabel||t.compactBodyPadding!==e.compactBodyPadding||t.groupSearchDataByGroup!==e.groupSearchDataByGroup||t.visibleSessionCount!==e.visibleSessionCount||t.collapsedGroups!==e.collapsedGroups&&t.collapsedGroups.has(t.groupKey)!==e.collapsedGroups.has(e.groupKey)||t.pinnedSessionIds!==e.pinnedSessionIds&&MS(e.group,t.pinnedSessionIds,e.pinnedSessionIds)||t.expandedParents!==e.expandedParents&&FS(e.group,t.expandedParents,e.expandedParents)||t.sessionOrderIndex!==e.sessionOrderIndex&&TS(e.group,t.sessionOrderIndex,e.sessionOrderIndex)||t.editingId!==e.editingId&&(Ii(t.group,t.editingId)||Ii(e.group,e.editingId))||t.editTitle!==e.editTitle&&(Ii(t.group,t.editingId)||Ii(e.group,e.editingId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=fi(t.group.sessions,t.openSidebarMenuKey,"project",!!t.group.isArchivedBucket),r=fi(e.group.sessions,e.openSidebarMenuKey,"project",!!e.group.isArchivedBucket);if(n||r)return!1}return t.activeActivitySessionIds!==e.activeActivitySessionIds&&tu(e.group,t.activeActivitySessionIds,e.activeActivitySessionIds)||t.unreadActivitySessionIds!==e.unreadActivitySessionIds&&tu(e.group,t.unreadActivitySessionIds,e.unreadActivitySessionIds)||t.notifyOnSubtasks!==e.notifyOnSubtasks&&ES(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 LS(t){const{t:e}=ft(),{group:n,groupKey:r,projectId:o,hideGroupLabel:i,hasSessionSearchQuery:c,normalizedSessionSearchQuery:l,groupSearchDataByGroup:d,visibleSessionCount:u,collapsedGroups:h,hideDirectoryControls:f,collapsedFolderIds:p,toggleFolderCollapse:x,renameFolder:b,deleteFolder:S,showDeletionDialog:g,setDeleteFolderConfirm:m,renderSessionNode:y,showMoreGroupSessions:C,resetGroupSessionLimit:j,mobileVariant:w,alwaysShowActions:N,activeProjectId:v,setActiveProjectIdOnly:P,setActiveMainTab:F,setSessionSwitcherOpen:k,openNewSessionDraft:E,addSessionToFolder:O,createFolderAndStartRename:M,renamingFolderId:L,renameFolderDraft:_,setRenameFolderDraft:D,setRenamingFolderId:A,pinnedSessionIds:T,expandedParents:z,sessionOrderIndex:R,editingId:W,openSidebarMenuKey:J,activeActivitySessionIds:U,unreadActivitySessionIds:te,notifyOnSubtasks:Z,onToggleCollapsedGroup:ue,dragHandleProps:Oe,compactBodyPadding:se=!1,scrollContainerRef:G}=t,Ie=a.useCallback((ze,Xe)=>{const tt=R.get(ze.session.id),at=R.get(Xe.session.id);if(tt!==void 0||at!==void 0){if(tt===void 0)return 1;if(at===void 0)return-1;if(tt!==at)return tt-at}return Mo(ze.session,Xe.session,T,ql)},[T,R]),pe=c?d.get(n):null,V=Nn(ze=>ze.foldersMap),Q=c?!1:h.has(r),ne=a.useMemo(()=>{if(n.isMain||n.isArchivedBucket||i)return null;const ze=Vt(n.directory??null),Xe=n.branch?.trim();return ze&&Xe?bi(ze,Xe):null},[n.branch,n.directory,n.isArchivedBucket,n.isMain,i]),oe=Ff(ne),ce=oe?`var(--pr-${oe.visualState})`:void 0,ke=mf(),ye=Vt(n.directory??null),he=a.useSyncExternalStore(a.useCallback(ze=>ye?ke.subscribeBootstrap(ze):()=>{},[ye,ke]),a.useCallback(()=>ye?ke.getBootstrapState(ye):void 0,[ye,ke]),a.useCallback(()=>{},[])),Ee=f?10:5,Ue=Math.max(Ee,u??Ee),Me=c?pe?.groupMatches===!0:!1,X=c,Ne=a.useMemo(()=>[...X?pe?.filteredNodes??[]:n.sessions].sort(Ie),[Ie,n.sessions,pe?.filteredNodes,X]),Ae=n.folderScopeKey??Vt(n.directory??null),Se=a.useMemo(()=>n.folderScopes&&n.folderScopes.length>0?n.folderScopes:Ae?[{scopeKey:Ae,directory:n.directory??null}]:[],[Ae,n.directory,n.folderScopes]),le=a.useMemo(()=>Se.flatMap(({scopeKey:ze,directory:Xe})=>(V[ze]??[]).map(tt=>({folder:tt,scopeKey:ze,scopeDirectory:Xe}))),[Se,V]),ee=a.useMemo(()=>{const ze=new Map,Xe=tt=>{tt.forEach(at=>{ze.set(at.session.id,at),at.children.length>0&&Xe(at.children)})};return Xe(Ne),ze},[Ne]),ie=a.useMemo(()=>le.map(({folder:ze,scopeKey:Xe,scopeDirectory:tt})=>{const at=DS(ze.sessionIds,ee).sort(Ie);return{folder:ze,scopeKey:Xe,scopeDirectory:tt,nodes:at}}),[le,ee,Ie]),ve=a.useMemo(()=>{const ze=new Map(ie.map(Ze=>[Ze.folder.id,Ze])),Xe=new Map;for(const{folder:Ze}of ie){if(!Ze.parentId)continue;const Pt=Xe.get(Ze.parentId);Pt?Pt.push(Ze.id):Xe.set(Ze.parentId,[Ze.id])}const tt=new Map,at=Ze=>{const Pt=tt.get(Ze);if(Pt!==void 0)return Pt;const Tt=ze.get(Ze);if(!Tt)return tt.set(Ze,!1),!1;const Jt=Xe.get(Ze)??[];if(n.isArchivedBucket&&Tt.nodes.length===0){const Bt=Jt.some(_t=>at(_t));return tt.set(Ze,Bt),Bt}if(!c||Tt.folder.name.toLowerCase().includes(l)||Tt.nodes.length>0)return tt.set(Ze,!0),!0;const cs=Jt.some(Bt=>at(Bt));return tt.set(Ze,cs),cs};return ie.filter(({folder:Ze})=>at(Ze.id))},[ie,n.isArchivedBucket,c,l]),K=a.useMemo(()=>new Set(ve.flatMap(ze=>ze.folder.sessionIds)),[ve]),de=a.useMemo(()=>Ne.filter(ze=>!K.has(ze.session.id)),[Ne,K]),_e=a.useMemo(()=>ve.filter(({folder:ze})=>!ze.parentId),[ve]),Pe=a.useMemo(()=>{const ze=new Map;return ve.forEach(Xe=>{if(!Xe.folder.parentId)return;const tt=ze.get(Xe.folder.parentId)??[];tt.push(Xe),ze.set(Xe.folder.parentId,tt)}),ze},[ve]),re=a.useMemo(()=>{const ze=new Map(ve.map(at=>[at.folder.id,at])),Xe=new Map,tt=(at,Ze)=>{const Pt=Xe.get(at);if(Pt!==void 0)return Pt;if(Ze.has(at))return null;Ze.add(at);const Tt=ze.get(at);let Jt=Tt?eu(Tt.nodes,U,te,Z):null;for(const ls of Pe.get(at)??[])if(Jt=pc(Jt,tt(ls.folder.id,Ze)),Jt==="active")break;return Xe.set(at,Jt),Jt};return ve.forEach(({folder:at})=>tt(at.id,new Set)),Xe},[U,ve,Pe,Z,te]),me="project",ge=a.useMemo(()=>{const ze=new Set;return Dl(Ne,W,ze),ve.forEach(({nodes:Xe})=>{Dl(Xe,W,ze)}),ze},[Ne,ve,W]),$=a.useMemo(()=>{if(!J)return null;const ze=fi(Ne,J,me,!!n.isArchivedBucket);if(ze)return ze;for(const{nodes:Xe}of ve){const tt=fi(Xe,J,me,!!n.isArchivedBucket);if(tt)return tt}return null},[J,Ne,ve,n.isArchivedBucket]),B=a.useCallback(ze=>{const Xe=new WeakMap,tt=at=>{Xe.set(at,ca(at));for(const Ze of at.children)tt(Ze)};return ze.forEach(tt),Xe},[]),xe=a.useMemo(()=>B(Ne),[B,Ne]),be=a.useMemo(()=>{const ze=new WeakMap;return ve.forEach(({nodes:Xe})=>{Xe.forEach(tt=>ze.set(tt,ca(tt)))}),ze},[ve]),Le=a.useCallback(ze=>xe.get(ze)??be.get(ze)??"",[xe,be]),Ke=a.useCallback(ze=>({subtreeContainsEditing:ge,menuOpenSessionId:$,nodeStructureKey:Le(ze)}),[ge,$,Le]),st=de.length,ut=n.isArchivedBucket||c?de:de.slice(0,Ue),mt=st-ut.length,pt=!n.isArchivedBucket&&!c&&st>Ee&&mt===0,ht=n.isArchivedBucket===!0&&!c&&ut.length>=IS,xt=n.isArchivedBucket?"archived":"active",wt=ht&&ut.some(ze=>{if(ze.children.length===0)return!1;const Xe=`project:${xt}:${ze.session.id}`;return z.has(Xe)}),bt=a.useRef(null),[Dt,qt]=a.useState(null),[Ut,We]=a.useState(0),[,yt]=a.useState(0);a.useEffect(()=>{if(!ht)return;const ze=bt.current;if(!ze||typeof ResizeObserver>"u")return;const Xe=new ResizeObserver(()=>yt(tt=>tt+1));return Xe.observe(ze),()=>Xe.disconnect()},[ht]),a.useLayoutEffect(()=>{if(!ht){Dt!==null&&qt(null),Ut!==0&&We(0);return}const ze=bt.current;if(!ze)return;let Xe=Dt;const tt=G?.current??null;if(tt&&tt.contains(ze)){if(Xe=tt,Xe!==Dt){qt(Xe);return}}else if(!Xe||!Xe.contains(ze)){let Ze=ze.parentElement;for(;Ze;){const Pt=window.getComputedStyle(Ze);if(Pt.overflowY==="auto"||Pt.overflowY==="scroll"){Xe=Ze;break}Ze=Ze.parentElement}if(Xe!==Dt){qt(Xe);return}}if(!Xe)return;const at=ze.getBoundingClientRect().top-Xe.getBoundingClientRect().top+Xe.scrollTop;We(Ze=>Math.abs(Ze-at)<1?Ze:at)});const Qe=ht&&Dt!==null,Rt=qx({count:ut.length,enabled:Qe,getScrollElement:()=>Dt,initialOffset:()=>Dt?.scrollTop??0,estimateSize:()=>RS,overscan:wt?20:8,scrollMargin:Ut,getItemKey:ze=>ut[ze]?.session.id??ze}),Ot=a.useCallback(ze=>{const Xe=[],tt=at=>{at.forEach(Ze=>{Xe.push(Ze.session),Ze.children.length>0&&tt(Ze.children)})};return tt(ze),Xe},[]),kt=a.useMemo(()=>Ot(Ne),[Ot,Ne]),Ft=a.useMemo(()=>{if(!n.isArchivedBucket)return new Map;const ze=new Map,Xe=new Map;for(const{folder:at}of ve){if(!at.parentId)continue;const Ze=Xe.get(at.parentId)??[];Ze.push(at.id),Xe.set(at.parentId,Ze)}const tt=(at,Ze)=>{if(Ze.has(at))return[];Ze.add(at);const Pt=ve.find(({folder:ls})=>ls.id===at),Tt=Pt?Ot(Pt.nodes):[],Jt=Xe.get(at)??[];for(const ls of Jt)Tt.push(...tt(ls,Ze));return Tt};for(const{folder:at}of ve)ze.set(at.id,tt(at.id,new Set));return ze},[ve,Ot,n.isArchivedBucket]);if(c&&!Me&&_e.length===0&&de.length===0)return null;const Ht=!n.isMain&&!!n.branch,Xt=n.branch&&zp(n.branch,n.label)?{label:n.branch}:null,rt=Q?eu(Ne,U,te,Z):null,je=rt?s.jsx(Rm,{state:rt,activeLabel:e("sessions.sidebar.session.status.active"),unreadLabel:e("sessions.sidebar.session.status.unread")}):null,Fe=(ze,Xe)=>{const{folder:tt,scopeKey:at,scopeDirectory:Ze,nodes:Pt}=ze,Tt=Ft.get(tt.id)??[],Jt=c?!1:p.has(tt.id);return s.jsx(CS,{folderId:tt.id,children:(ls,cs)=>s.jsx(hS,{folder:tt,displayName:Xe,sessions:Pt,isCollapsed:Jt,collapsedActivityState:Jt?re.get(tt.id)??null:null,onToggle:()=>x(tt.id),onRename:Bt=>{b(at,tt.id,Bt)},onDelete:()=>{if(n.isArchivedBucket){Kn.requestDelete({sessions:Tt,mode:"session"});return}if(!g){S(at,tt.id);return}const Bt=ve.filter(({folder:Mt})=>Mt.parentId===tt.id).length,_t=Pt.length;m({scopeKey:at,folderId:tt.id,folderName:tt.name,subFolderCount:Bt,sessionCount:_t})},renderSessionNode:y,getRenderExtras:Le?Bt=>({subtreeContainsEditing:ge,menuOpenSessionId:$,nodeStructureKey:Le(Bt),childRenderExtrasFor:Ke}):void 0,groupDirectory:Ze??n.directory,projectId:o,mobileVariant:w,alwaysShowActions:N,isRenaming:L===tt.id,renameDraft:L===tt.id?_:void 0,onRenameDraftChange:Bt=>D(Bt),onRenameSave:()=>{const Bt=_.trim();Bt&&b(at,tt.id,Bt),A(null),D("")},onRenameCancel:()=>{A(null),D("")},droppableRef:ls,isDropTarget:cs,depth:0,onNewSession:()=>{o&&o!==v&&P(o),F("chat"),w&&k(!1),E({selectedProjectId:o,directoryOverride:Ze??n.directory,targetFolderId:tt.id})},hideActions:!1,archivedBucket:n.isArchivedBucket===!0})},tt.id)},Te=()=>{const ze=new Map;for(const at of ve){const Ze=at.folder.parentId;if(!Ze)continue;const Pt=ze.get(Ze);Pt?Pt.push(at):ze.set(Ze,[at])}const Xe=[],tt=(at,Ze)=>{const Pt=Ze?`${Ze} / ${at.folder.name}`:at.folder.name;Xe.push(Fe(at,Pt)),!(!c&&p.has(at.folder.id))&&(ze.get(at.folder.id)??[]).forEach(Jt=>tt(Jt,Pt))};return _e.forEach(at=>tt(at,"")),Xe},it=!!(!n.isMain&&n.worktree),ct=N?it?"pr-14":"pr-7":it?"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",Kt=s.jsxs(AS,{scopeKey:Se[0]?.scopeKey??Ae,hasFolders:ve.length>0,onSessionDroppedOnFolder:(ze,Xe)=>{const tt=ve.find(({folder:Ze})=>Ze.id===Xe);if(!tt)return;const at=Nn.getState();for(const{scopeKey:Ze}of Se)Ze!==tt.scopeKey&&at.getSessionFolderId(Ze,ze)&&at.removeSessionFromFolder(Ze,ze);O(tt.scopeKey,Xe,ze)},children:[Te(),ht?s.jsx("div",{ref:bt,children:Qe?s.jsx("div",{style:{height:Rt.getTotalSize(),position:"relative"},children:Rt.getVirtualItems().map(ze=>{const Xe=ut[ze.index];return Xe?s.jsx("div",{"data-index":ze.index,ref:Rt.measureElement,className:"[&_[data-session-row]]:my-px",style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${ze.start-Ut}px)`},children:y(Xe,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsEditing:ge,menuOpenSessionId:$,nodeStructureKey:Le(Xe),childRenderExtrasFor:Ke})},Xe.session.id):null})}):ut.map(ze=>y(ze,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsEditing:ge,menuOpenSessionId:$,nodeStructureKey:Le(ze),childRenderExtrasFor:Ke}))}):ut.map(ze=>y(ze,0,n.directory,o,n.isArchivedBucket===!0,void 0,"project",{subtreeContainsEditing:ge,menuOpenSessionId:$,nodeStructureKey:Le(ze),childRenderExtrasFor:Ke})),st===0&&ve.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"):he==="queued"||he==="running"?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")]}):he==="failed"&&ye?s.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e("sessions.sidebar.group.empty.loadFailed"),s.jsx("button",{type:"button",className:"text-foreground hover:underline",onClick:()=>ke.requestBootstrap({directory:ye,priority:Q?"visible":"expanded",reason:n.isMain?"project-expanded":"worktree-expanded",force:!0}),children:e("sessions.sidebar.group.empty.retry")})]}):e("sessions.sidebar.group.empty.noSessionsInWorkspace")}):null,mt>0?s.jsx("button",{type:"button",onClick:()=>C(r,ut.length),className:"mt-0.5 flex items-center justify-start rounded-md pl-[26px] pr-1.5 py-0.5 text-left text-xs text-muted-foreground/70 leading-tight hover:text-foreground hover:underline",children:e("sessions.sidebar.group.showMore")}):null,pt?s.jsx("button",{type:"button",onClick:()=>j(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]}),Lt="pb-2";return i?s.jsx("div",{className:"oc-group",children:s.jsx("div",{className:De("oc-group-body",Lt),children:Kt})}):s.jsxs("div",{className:"oc-group",children:[s.jsxs("div",{className:De("group/gh relative flex items-start justify-between gap-1 py-1 min-w-0 rounded-md","cursor-pointer"),onClick:()=>ue(r),role:"button",tabIndex:0,onKeyDown:ze=>{(ze.key==="Enter"||ze.key===" ")&&(ze.preventDefault(),ue(r))},"aria-label":Q?e("sessions.sidebar.group.expandAria",{label:n.label}):e("sessions.sidebar.group.collapseAria",{label:n.label}),"aria-expanded":!Q,children:[s.jsx("div",{ref:Oe?.setActivatorNodeRef,className:De("min-w-0 flex flex-1 items-start gap-1 overflow-hidden pl-1.5 transition-[padding]",ct),...Oe?.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:De("h-3.5 w-3.5 shrink-0 text-muted-foreground",N?"hidden":"group-hover/gh:hidden")}),s.jsx("span",{className:De("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Q?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:$i(n.label,l)}),je]}):!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:De("h-3.5 w-3.5 shrink-0",!ce&&"text-muted-foreground",N?"hidden":"group-hover/gh:hidden"),style:ce?{color:ce}:void 0}),s.jsx("span",{className:De("text-muted-foreground h-3.5 w-3.5 items-center justify-center",N?"inline-flex":"hidden group-hover/gh:inline-flex"),children:Q?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:$i(n.label,l)}),je,oe?s.jsxs("span",{className:"ml-auto flex-shrink-0 text-[0.72rem] font-medium leading-none",style:ce?{color:ce}: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:$i(n.label,l)}),je]})}),Ht&&Xt?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:Xt.label})]}):null]})}),n.isArchivedBucket&&kt.length>0?s.jsx("div",{className:De("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ze=>{ze.stopPropagation(),Kn.requestDelete({sessions:kt,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(At,{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:De("absolute right-7 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ze=>{ze.stopPropagation(),Kn.requestDelete({sessions:kt,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(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.group.actions.deleteWorktree")})})]})}):null,n.directory?s.jsx("div",{className:De("absolute right-0.5 top-1/2 -translate-y-1/2 z-10 transition-opacity",N?"opacity-100":"opacity-0 group-hover/gh:opacity-100 group-focus-within/gh:opacity-100"),children:s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:ze=>{ze.stopPropagation(),o&&o!==v&&P(o),F("chat"),w&&k(!1),E({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(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:e("sessions.sidebar.project.actions.newDraftSession")})})]})}):null]}),Q?null:s.jsx("div",{className:De("oc-group-body",Lt),children:Kt})]})}const BS=a.memo(LS,OS),$S=(t,e)=>{const n=t??{};return e<2&&(n.projectSortOrder="manual"),e<3&&n.projectSortOrder==="recent"&&(n.projectSortOrder="manual"),e<4&&delete n.displayMode,n},ln=$o()(Tx(t=>({sessionGroupingMode:"by-worktree",setSessionGroupingMode:e=>t({sessionGroupingMode:e}),stickyZoneHeaders:!0,toggleStickyZoneHeaders:()=>t(e=>({stickyZoneHeaders:!e.stickyZoneHeaders})),showRecentSection:!0,showArchivedSessions:!1,projectSortOrder:"manual",setShowRecentSection:e=>t({showRecentSection:e}),setShowArchivedSessions:e=>t({showArchivedSessions:e}),toggleRecentSection:()=>t(e=>({showRecentSection:!e.showRecentSection})),toggleArchivedSessions:()=>t(e=>({showArchivedSessions:!e.showArchivedSessions})),setProjectSortOrder:e=>t({projectSortOrder:e})}),{name:"session-display-mode",version:4,migrate:$S}));function _S(t){const e=nt.c(219),{t:n}=ft(),{hideDirectoryControls:r,showRecentControls:o,handleOpenDirectoryDialog:i,onOpenScheduled:c,onOpenMultiRun:l,canOpenMultiRun:d,onOpenArchive:u,headerActionIconClass:h,headerActionButtonClass:f,isSessionSearchOpen:p,setIsSessionSearchOpen:x,sessionSearchInputRef:b,sessionSearchQuery:S,setSessionSearchQuery:g,hasSessionSearchQuery:m,searchMatchCount:y,collapseAllProjects:C,expandAllProjects:j,selectionModeEnabled:w,onToggleSelectionMode:N}=t,v=ln(YS),P=ln(qS),F=ln(GS),k=ln(KS),E=ln(HS),O=ln(US),M=ln(WS),L=ln(VS);if(r)return null;let _;e[0]!==f?(_=De(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[0]=f,e[1]=_):_=e[1];let D;e[2]!==n?(D=n("sessions.sidebar.header.actions.addProject"),e[2]=n,e[3]=D):D=e[3];let A;e[4]!==h?(A=s.jsx(I,{name:"folder-add",className:h}),e[4]=h,e[5]=A):A=e[5];let T;e[6]!==i||e[7]!==_||e[8]!==D||e[9]!==A?(T=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:i,className:_,"aria-label":D,children:A})}),e[6]=i,e[7]=_,e[8]=D,e[9]=A,e[10]=T):T=e[10];let z;e[11]!==n?(z=n("sessions.sidebar.header.actions.addProject"),e[11]=n,e[12]=z):z=e[12];let R;e[13]!==z?(R=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:z})}),e[13]=z,e[14]=R):R=e[14];let W;e[15]!==T||e[16]!==R?(W=s.jsxs(Nt,{children:[T,R]}),e[15]=T,e[16]=R,e[17]=W):W=e[17];let J;e[18]!==f?(J=De(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[18]=f,e[19]=J):J=e[19];let U;e[20]!==n?(U=n("sessions.sidebar.header.actions.scheduledTasks"),e[20]=n,e[21]=U):U=e[21];let te;e[22]!==h?(te=s.jsx(I,{name:"calendar-schedule",className:h}),e[22]=h,e[23]=te):te=e[23];let Z;e[24]!==c||e[25]!==J||e[26]!==U||e[27]!==te?(Z=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:c,className:J,"aria-label":U,children:te})}),e[24]=c,e[25]=J,e[26]=U,e[27]=te,e[28]=Z):Z=e[28];let ue;e[29]!==n?(ue=n("sessions.sidebar.header.actions.scheduledTasks"),e[29]=n,e[30]=ue):ue=e[30];let Oe;e[31]!==ue?(Oe=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ue})}),e[31]=ue,e[32]=Oe):Oe=e[32];let se;e[33]!==Z||e[34]!==Oe?(se=s.jsxs(Nt,{children:[Z,Oe]}),e[33]=Z,e[34]=Oe,e[35]=se):se=e[35];let G;e[36]!==f?(G=De(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[36]=f,e[37]=G):G=e[37];let Ie;e[38]!==n?(Ie=n("sessions.sidebar.header.actions.newMultiRun"),e[38]=n,e[39]=Ie):Ie=e[39];const pe=!d;let V;e[40]!==h?(V=s.jsx(Vp,{className:h}),e[40]=h,e[41]=V):V=e[41];let Q;e[42]!==l||e[43]!==G||e[44]!==Ie||e[45]!==pe||e[46]!==V?(Q=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:l,className:G,"aria-label":Ie,disabled:pe,children:V})}),e[42]=l,e[43]=G,e[44]=Ie,e[45]=pe,e[46]=V,e[47]=Q):Q=e[47];let ne;e[48]!==n?(ne=n("sessions.sidebar.header.actions.newMultiRun"),e[48]=n,e[49]=ne):ne=e[49];let oe;e[50]!==ne?(oe=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ne})}),e[50]=ne,e[51]=oe):oe=e[51];let ce;e[52]!==Q||e[53]!==oe?(ce=s.jsxs(Nt,{children:[Q,oe]}),e[52]=Q,e[53]=oe,e[54]=ce):ce=e[54];let ke;e[55]!==f?(ke=De(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[55]=f,e[56]=ke):ke=e[56];let ye;e[57]!==n?(ye=n("sessions.sidebar.nav.archive"),e[57]=n,e[58]=ye):ye=e[58];let he;e[59]!==h?(he=s.jsx(I,{name:"archive",className:h}),e[59]=h,e[60]=he):he=e[60];let Ee;e[61]!==u||e[62]!==ke||e[63]!==ye||e[64]!==he?(Ee=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:u,className:ke,"aria-label":ye,children:he})}),e[61]=u,e[62]=ke,e[63]=ye,e[64]=he,e[65]=Ee):Ee=e[65];let Ue;e[66]!==n?(Ue=n("sessions.sidebar.nav.archive"),e[66]=n,e[67]=Ue):Ue=e[67];let Me;e[68]!==Ue?(Me=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:Ue})}),e[68]=Ue,e[69]=Me):Me=e[69];let X;e[70]!==Ee||e[71]!==Me?(X=s.jsxs(Nt,{children:[Ee,Me]}),e[70]=Ee,e[71]=Me,e[72]=X):X=e[72];let Ne;e[73]!==se||e[74]!==ce||e[75]!==X||e[76]!==W?(Ne=s.jsxs("div",{className:"ml-[3px] flex items-center gap-1.5",children:[W,se,ce,X]}),e[73]=se,e[74]=ce,e[75]=X,e[76]=W,e[77]=Ne):Ne=e[77];let Ae;e[78]!==x?(Ae=()=>x(zS),e[78]=x,e[79]=Ae):Ae=e[79];let Se;e[80]!==f?(Se=De(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[80]=f,e[81]=Se):Se=e[81];let le;e[82]!==n?(le=n("sessions.sidebar.header.actions.searchSessions"),e[82]=n,e[83]=le):le=e[83];let ee;e[84]!==h?(ee=s.jsx(I,{name:"search",className:h}),e[84]=h,e[85]=ee):ee=e[85];let ie;e[86]!==p||e[87]!==Ae||e[88]!==Se||e[89]!==le||e[90]!==ee?(ie=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:Ae,className:Se,"aria-label":le,"aria-expanded":p,children:ee})}),e[86]=p,e[87]=Ae,e[88]=Se,e[89]=le,e[90]=ee,e[91]=ie):ie=e[91];let ve;e[92]!==n?(ve=n("sessions.sidebar.header.actions.searchSessions"),e[92]=n,e[93]=ve):ve=e[93];let K;e[94]!==ve?(K=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ve})}),e[94]=ve,e[95]=K):K=e[95];let de;e[96]!==ie||e[97]!==K?(de=s.jsxs(Nt,{children:[ie,K]}),e[96]=ie,e[97]=K,e[98]=de):de=e[98];const _e=w&&"bg-interactive-hover text-primary";let Pe;e[99]!==f||e[100]!==_e?(Pe=De(f,"text-muted-foreground hover:text-foreground hover:bg-transparent",_e),e[99]=f,e[100]=_e,e[101]=Pe):Pe=e[101];let re;e[102]!==w||e[103]!==n?(re=n(w?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[102]=w,e[103]=n,e[104]=re):re=e[104];let me;e[105]!==h?(me=s.jsx(I,{name:"checkbox-multiple",className:h}),e[105]=h,e[106]=me):me=e[106];let ge;e[107]!==N||e[108]!==w||e[109]!==Pe||e[110]!==re||e[111]!==me?(ge=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:N,className:Pe,"aria-label":re,"aria-pressed":w,children:me})}),e[107]=N,e[108]=w,e[109]=Pe,e[110]=re,e[111]=me,e[112]=ge):ge=e[112];let $;e[113]!==w||e[114]!==n?($=n(w?"sessions.sidebar.header.actions.exitSelection":"sessions.sidebar.header.actions.selectSessions"),e[113]=w,e[114]=n,e[115]=$):$=e[115];let B;e[116]!==$?(B=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:$})}),e[116]=$,e[117]=B):B=e[117];let xe;e[118]!==ge||e[119]!==B?(xe=s.jsxs(Nt,{children:[ge,B]}),e[118]=ge,e[119]=B,e[120]=xe):xe=e[120];let be;e[121]!==f?(be=De(f,"text-muted-foreground hover:text-foreground hover:bg-transparent"),e[121]=f,e[122]=be):be=e[122];let Le;e[123]!==n?(Le=n("sessions.sidebar.header.displayMode.label"),e[123]=n,e[124]=Le):Le=e[124];let Ke;e[125]!==h?(Ke=s.jsx(I,{name:"equalizer-2",className:h}),e[125]=h,e[126]=Ke):Ke=e[126];let st;e[127]!==be||e[128]!==Le||e[129]!==Ke?(st=s.jsx(Ct,{asChild:!0,children:s.jsx(qs,{asChild:!0,children:s.jsx("button",{type:"button",className:be,"aria-label":Le,children:Ke})})}),e[127]=be,e[128]=Le,e[129]=Ke,e[130]=st):st=e[130];let ut;e[131]!==n?(ut=n("sessions.sidebar.header.displayMode.label"),e[131]=n,e[132]=ut):ut=e[132];let mt;e[133]!==ut?(mt=s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:ut})}),e[133]=ut,e[134]=mt):mt=e[134];let pt;e[135]!==st||e[136]!==mt?(pt=s.jsxs(Nt,{children:[st,mt]}),e[135]=st,e[136]=mt,e[137]=pt):pt=e[137];let ht;e[138]!==n?(ht=n("sessions.sidebar.header.actions.sortProjects"),e[138]=n,e[139]=ht):ht=e[139];let xt;e[140]!==ht?(xt=s.jsx(So,{children:ht}),e[140]=ht,e[141]=xt):xt=e[141];let wt;e[142]!==F||e[143]!==k||e[144]!==n?(wt=[["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(Ze=>{const[Pt,Tt]=Ze;return s.jsxs(is,{onClick:()=>k(Pt),className:"flex items-center justify-between",children:[s.jsx("span",{children:n(Tt)}),F===Pt?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]},Pt)}),e[142]=F,e[143]=k,e[144]=n,e[145]=wt):wt=e[145];let bt;e[146]===Symbol.for("react.memo_cache_sentinel")?(bt=s.jsx(Ln,{}),e[146]=bt):bt=e[146];let Dt;e[147]!==n?(Dt=n("sessions.sidebar.header.grouping.label"),e[147]=n,e[148]=Dt):Dt=e[148];let qt;e[149]!==Dt?(qt=s.jsx(So,{children:Dt}),e[149]=Dt,e[150]=qt):qt=e[150];let Ut;e[151]!==E||e[152]!==O||e[153]!==n?(Ut=[["by-worktree","sessions.sidebar.header.grouping.byWorktree"],["flat","sessions.sidebar.header.grouping.flat"]].map(Ze=>{const[Pt,Tt]=Ze;return s.jsxs(is,{onClick:()=>O(Pt),className:"flex items-center justify-between",children:[s.jsx("span",{children:n(Tt)}),E===Pt?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]},Pt)}),e[151]=E,e[152]=O,e[153]=n,e[154]=Ut):Ut=e[154];let We;e[155]===Symbol.for("react.memo_cache_sentinel")?(We=s.jsx(Ln,{}),e[155]=We):We=e[155];let yt;e[156]!==o||e[157]!==v||e[158]!==n||e[159]!==P?(yt=o?s.jsxs(is,{onClick:P,className:"flex items-center justify-between",children:[s.jsx("span",{children:n("sessions.sidebar.header.displayMode.showRecent")}),v?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null]}):null,e[156]=o,e[157]=v,e[158]=n,e[159]=P,e[160]=yt):yt=e[160];let Qe;e[161]!==n?(Qe=n("sessions.sidebar.header.displayMode.stickyHeaders"),e[161]=n,e[162]=Qe):Qe=e[162];let Rt;e[163]!==Qe?(Rt=s.jsx("span",{children:Qe}),e[163]=Qe,e[164]=Rt):Rt=e[164];let Ot;e[165]!==M?(Ot=M?s.jsx(I,{name:"check",className:"h-4 w-4 text-primary"}):null,e[165]=M,e[166]=Ot):Ot=e[166];let kt;e[167]!==Rt||e[168]!==Ot||e[169]!==L?(kt=s.jsxs(is,{onClick:L,className:"flex items-center justify-between",children:[Rt,Ot]}),e[167]=Rt,e[168]=Ot,e[169]=L,e[170]=kt):kt=e[170];let Ft;e[171]===Symbol.for("react.memo_cache_sentinel")?(Ft=s.jsx(Ln,{}),e[171]=Ft):Ft=e[171];let Ht;e[172]===Symbol.for("react.memo_cache_sentinel")?(Ht=s.jsx(I,{name:"contract-up-down",className:"h-4 w-4"}),e[172]=Ht):Ht=e[172];let Xt;e[173]!==n?(Xt=n("sessions.sidebar.header.displayMode.collapseAll"),e[173]=n,e[174]=Xt):Xt=e[174];let rt;e[175]!==Xt?(rt=s.jsx("span",{children:Xt}),e[175]=Xt,e[176]=rt):rt=e[176];let je;e[177]!==C||e[178]!==rt?(je=s.jsxs(is,{onClick:C,className:"flex items-center gap-2",children:[Ht,rt]}),e[177]=C,e[178]=rt,e[179]=je):je=e[179];let Fe;e[180]===Symbol.for("react.memo_cache_sentinel")?(Fe=s.jsx(I,{name:"expand-up-down",className:"h-4 w-4"}),e[180]=Fe):Fe=e[180];let Te;e[181]!==n?(Te=n("sessions.sidebar.header.displayMode.expandAll"),e[181]=n,e[182]=Te):Te=e[182];let it;e[183]!==Te?(it=s.jsx("span",{children:Te}),e[183]=Te,e[184]=it):it=e[184];let ct;e[185]!==j||e[186]!==it?(ct=s.jsxs(is,{onClick:j,className:"flex items-center gap-2",children:[Fe,it]}),e[185]=j,e[186]=it,e[187]=ct):ct=e[187];let Kt;e[188]!==xt||e[189]!==wt||e[190]!==qt||e[191]!==Ut||e[192]!==yt||e[193]!==kt||e[194]!==je||e[195]!==ct?(Kt=s.jsxs(Ys,{align:"end",className:"min-w-[180px]",children:[xt,wt,bt,qt,Ut,We,yt,kt,Ft,je,ct]}),e[188]=xt,e[189]=wt,e[190]=qt,e[191]=Ut,e[192]=yt,e[193]=kt,e[194]=je,e[195]=ct,e[196]=Kt):Kt=e[196];let Lt;e[197]!==pt||e[198]!==Kt?(Lt=s.jsxs(Qs,{children:[pt,Kt]}),e[197]=pt,e[198]=Kt,e[199]=Lt):Lt=e[199];let ze;e[200]!==de||e[201]!==xe||e[202]!==Lt?(ze=s.jsxs("div",{className:"flex items-center gap-1.5",children:[de,xe,Lt]}),e[200]=de,e[201]=xe,e[202]=Lt,e[203]=ze):ze=e[203];let Xe;e[204]!==Ne||e[205]!==ze?(Xe=s.jsxs("div",{className:"flex h-8 items-center justify-between gap-2",children:[Ne,ze]}),e[204]=Ne,e[205]=ze,e[206]=Xe):Xe=e[206];let tt;e[207]!==m||e[208]!==p||e[209]!==y||e[210]!==b||e[211]!==S||e[212]!==x||e[213]!==g||e[214]!==n?(tt=p?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:[m?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:b,value:S,onChange:Ze=>g(Ze.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:Ze=>{Ze.key==="Escape"&&(Ze.stopPropagation(),m?g(""):x(!1))}}),S.length>0?s.jsx("button",{type:"button",onClick:()=>g(""),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[207]=m,e[208]=p,e[209]=y,e[210]=b,e[211]=S,e[212]=x,e[213]=g,e[214]=n,e[215]=tt):tt=e[215];let at;return e[216]!==Xe||e[217]!==tt?(at=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:[Xe,tt]})}),e[216]=Xe,e[217]=tt,e[218]=at):at=e[218],at}function zS(t){return!t}function VS(t){return t.toggleStickyZoneHeaders}function WS(t){return t.stickyZoneHeaders}function US(t){return t.setSessionGroupingMode}function HS(t){return t.sessionGroupingMode}function KS(t){return t.setProjectSortOrder}function GS(t){return t.projectSortOrder}function qS(t){return t.toggleRecentSection}function YS(t){return t.showRecentSection}function QS(t){const e=nt.c(8),{t:n}=ft(),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 l;return e[5]!==t.onNewSession||e[6]!==c?(l=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]=l):l=e[7],l}const su=7;function XS(t){const{sections:e,renderSessionNode:n,editingId:r,openSidebarMenuKey:o,variant:i="section",initialVisibleCount:c=su,batchSize:l=su}=t,{t:d}=ft(),u=ln(j=>j.stickyZoneHeaders),[h,f]=a.useState(new Set),[p,x]=a.useState(new Map),b=i==="flat",S=a.useCallback(j=>{x(w=>{if(!w.has(j))return w;const N=new Map(w);return N.delete(j),N})},[]),g=a.useCallback(j=>{S(j),f(w=>{const N=new Set(w);return N.has(j)?N.delete(j):N.add(j),N})},[S]),m=a.useCallback((j,w,N)=>{x(v=>{const P=Math.min(N,w+l),F=new Map(v);return F.set(j,P),F})},[l]),y=a.useCallback(j=>{const w=new Set;Dl(j,r,w);const N=fi(j,o,"recent",!1),v=new WeakMap,P=k=>{v.set(k,ca(k)),k.children.forEach(P)};j.forEach(P);const F=k=>({subtreeContainsEditing:w,menuOpenSessionId:N,nodeStructureKey:v.get(k)??"",childRenderExtrasFor:F});return k=>({subtreeContainsEditing:w,menuOpenSessionId:N,nodeStructureKey:v.get(k)??"",childRenderExtrasFor:F})},[r,o]),C=e.filter(j=>j.items.length>0);return C.length===0?null:s.jsx("div",{className:De(b?"space-y-0.5 pb-2":"space-y-2 pb-2"),children:C.map(j=>{const w=h.has(j.key),N=Math.max(c,p.get(j.key)??c),v=j.items.slice(0,N),P=j.items.length-v.length,F=!b&&j.items.length>c&&P===0,k=y(v.map(O=>O.node)),E=O=>n(O.node,0,O.groupDirectory,O.projectId,!1,O.secondaryMeta,"recent",k(O.node));return b?s.jsxs("div",{className:"space-y-0.5",children:[v.map(E),P>0?s.jsx("button",{type:"button",onClick:()=>m(j.key,v.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:De("-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:"group flex w-full items-center gap-1.5 py-1 pl-4 pr-3.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50","aria-expanded":!w,children:[s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 items-center justify-center",children:[s.jsx(I,{name:"history",className:De("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:w?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})]})}),w?null:s.jsxs("div",{className:De("space-y-0.5"),children:[v.map(E),P>0?s.jsx("button",{type:"button",onClick:()=>m(j.key,v.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,F?s.jsx("button",{type:"button",onClick:()=>S(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 nl="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 JS(t){const e=nt.c(13),{onOpenSettings:n,onOpenShortcuts:r,onOpenAbout:o,onOpenUpdate:i,showRuntimeButtons:c,showUpdateButton:l}=t,d=c===void 0?!0:c,u=l===void 0?!0:l,{t:h}=ft();if(!d&&!u)return null;let f;e[0]!==o||e[1]!==n||e[2]!==r||e[3]!==d||e[4]!==h?(f=d?s.jsxs(s.Fragment,{children:[s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:n,className:nl,"aria-label":h("sessions.sidebar.footer.actions.settings"),children:s.jsx(I,{name:"settings-3",className:"h-4.5 w-4.5"})})}),s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.footer.actions.settings")})})]}),s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:r,className:nl,"aria-label":h("sessions.sidebar.footer.actions.shortcuts"),children:s.jsx(I,{name:"question",className:"h-4.5 w-4.5"})})}),s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.footer.actions.shortcuts")})})]}),s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:o,className:nl,"aria-label":h("sessions.sidebar.footer.actions.aboutOpenChamber"),children:s.jsx(I,{name:"information",className:"h-4.5 w-4.5"})})}),s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:h("sessions.sidebar.footer.actions.aboutOpenChamber")})})]})]}):null,e[0]=o,e[1]=n,e[2]=r,e[3]=d,e[4]=h,e[5]=f):f=e[5];let p;e[6]!==i||e[7]!==u||e[8]!==h?(p=u?s.jsx(He,{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:h("sessions.sidebar.footer.actions.update")}):null,e[6]=i,e[7]=u,e[8]=h,e[9]=p):p=e[9];let x;return e[10]!==f||e[11]!==p?(x=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]=x):x=e[12],x}const Em=t=>{const e=nt.c(22),{id:n,projectLabel:r,projectIcon:o,projectColor:i,projectIconImage:c,projectIconBackground:l,isCollapsed:d,alwaysShowActions:u}=t,h=u===void 0?!1:u,{currentTheme:f}=co(),p=o?Yl[o]:null,x=i?Ql[i]??null:null,b=d!==void 0,S=b?h?"hidden":"group-hover/project:hidden group-focus-within/project:hidden":void 0;let g;e[0]!==h||e[1]!==b||e[2]!==d?(g=b?s.jsx("span",{className:De("h-3.5 w-3.5 items-center justify-center text-muted-foreground",h?"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]=h,e[1]=b,e[2]=d,e[3]=g):g=e[3];let m;e[4]!==h||e[5]!==f||e[6]!==b||e[7]!==x||e[8]!==S||e[9]!==n||e[10]!==l||e[11]!==c||e[12]!==p?(m=c?s.jsx("span",{className:De("h-3.5 w-3.5 items-center justify-center overflow-hidden rounded-[3px]",b&&h?"hidden":"inline-flex",S),style:l?{backgroundColor:l}:void 0,children:s.jsx(Xl,{project:{id:n,iconImage:c},options:{themeVariant:f.metadata.variant,iconColor:f.colors.surface.foreground},className:"h-full w-full object-contain",fallback:p?s.jsx(I,{name:p,className:"h-3.5 w-3.5",style:x?{color:x}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 text-muted-foreground/80",style:x?{color:x}:void 0})})}):p?s.jsx(I,{name:p,className:De("h-3.5 w-3.5",S),style:x?{color:x}:void 0}):s.jsx(I,{name:"folder",className:De("h-3.5 w-3.5 text-muted-foreground/80",S),style:x?{color:x}:void 0}),e[4]=h,e[5]=f,e[6]=b,e[7]=x,e[8]=S,e[9]=n,e[10]=l,e[11]=c,e[12]=p,e[13]=m):m=e[13];let y;e[14]!==g||e[15]!==m?(y=s.jsxs("span",{className:"inline-flex h-3.5 w-3.5 flex-shrink-0 items-center justify-center",children:[g,m]}),e[14]=g,e[15]=m,e[16]=y):y=e[16];let C;e[17]!==r?(C=s.jsx("span",{className:"truncate text-[14px] font-semibold lowercase text-foreground",children:r}),e[17]=r,e[18]=C):C=e[18];let j;return e[19]!==y||e[20]!==C?(j=s.jsxs(s.Fragment,{children:[y,C]}),e[19]=y,e[20]=C,e[21]=j):j=e[21],j},ZS=t=>{const e=nt.c(59),{id:n,disabled:r,projectLabel:o,projectDescription:i,projectIcon:c,projectColor:l,projectIconImage:d,projectIconBackground:u,isCollapsed:h,isRepo:f,isDesktopShell:p,hideDirectoryControls:x,alwaysShowActions:b,onToggle:S,onNewSession:g,onNewWorktreeSession:m,onManageWorktrees:y,onRenameStart:C,onClose:j,sentinelRef:w,children:N,showCreateButtons:v,hideHeader:P,openSidebarMenuKey:F,setOpenSidebarMenuKey:k,statusIndicator:E}=t,O=r===void 0?!1:r,M=v===void 0?!0:v,L=P===void 0?!1:P,_=E===void 0?null:E,{t:D}=ft(),A=ln(sk);let T;e[0]!==O||e[1]!==n?(T={id:n,disabled:O},e[0]=O,e[1]=n,e[2]=T):T=e[2];const{attributes:z,listeners:R,setNodeRef:W,transform:J,transition:U,isDragging:te}=ec(T),Z=a.useRef(!1),ue=`project:${n}`,Oe=F===ue,[se,G]=a.useState(!1);let Ie;e[3]!==ue||e[4]!==k?(Ie=le=>{le&&G(!1),k(le?ue:null)},e[3]=ue,e[4]=k,e[5]=Ie):Ie=e[5];const pe=Ie;let V;e[6]!==x||e[7]!==f||e[8]!==j||e[9]!==y||e[10]!==g||e[11]!==C||e[12]!==M||e[13]!==D?(V=le=>s.jsxs(s.Fragment,{children:[M&&!f&&!x&&g&&s.jsxs(le,{onClick:g,children:[s.jsx(I,{name:"add",className:"mr-1.5 h-4 w-4"}),D("sessions.sidebar.project.actions.newSession")]}),f&&!x&&y&&s.jsxs(le,{onClick:y,children:[s.jsx(I,{name:"node-tree",className:"mr-1.5 h-4 w-4"}),D("sessions.sidebar.project.actions.manageWorktrees")]}),s.jsxs(le,{onClick:C,children:[s.jsx(I,{name:"pencil-ai",className:"mr-1.5 h-4 w-4"}),D("sessions.sidebar.project.actions.edit")]}),s.jsxs(le,{onClick:j,className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1.5 h-4 w-4"}),D("sessions.sidebar.project.actions.closeProject")]})]}),e[6]=x,e[7]=f,e[8]=j,e[9]=y,e[10]=g,e[11]=C,e[12]=M,e[13]=D,e[14]=V):V=e[14];const Q=V,ne=nk,oe=rk,ce=ok;let ke;e[15]===Symbol.for("react.memo_cache_sentinel")?(ke=le=>{(le.button===2||le.button===0&&le.ctrlKey)&&(Z.current=!0)},e[15]=ke):ke=e[15];const ye=ke;let he;e[16]!==S?(he=le=>{if(le.currentTarget.blur(),Z.current){Z.current=!1;return}S()},e[16]=S,e[17]=he):he=e[17];const Ee=he;let Ue;e[18]!==J?(Ue=tc.Transform.toString(J),e[18]=J,e[19]=Ue):Ue=e[19];let Me;e[20]!==Ue||e[21]!==U?(Me={transform:Ue,transition:U},e[20]=Ue,e[21]=U,e[22]=Me):Me=e[22];const X=te&&"opacity-30";let Ne;e[23]!==X?(Ne=De("relative",X),e[23]=X,e[24]=Ne):Ne=e[24];let Ae;e[25]!==b||e[26]!==z||e[27]!==pe||e[28]!==Ee||e[29]!==x||e[30]!==L||e[31]!==n||e[32]!==h||e[33]!==se||e[34]!==p||e[35]!==Oe||e[36]!==f||e[37]!==R||e[38]!==g||e[39]!==m||e[40]!==l||e[41]!==i||e[42]!==c||e[43]!==u||e[44]!==d||e[45]!==o||e[46]!==Q||e[47]!==w||e[48]!==M||e[49]!==_||e[50]!==A||e[51]!==D?(Ae=L?null:s.jsxs(s.Fragment,{children:[p&&s.jsx("div",{ref:w,"data-project-id":n,className:"absolute top-0 h-px w-full pointer-events-none","aria-hidden":"true"}),s.jsxs(Rf,{open:se,onOpenChange:G,children:[s.jsx(If,{render:s.jsx("div",{className:De("-ml-2.5 -mr-2 text-left group/project select-none",A&&"sticky top-0 z-20 bg-sidebar"),"data-sidebar-sticky-header":A?"true":void 0,onContextMenu:le=>{x||(le.preventDefault(),G(!0))}}),children:s.jsxs("div",{className:"relative flex items-center gap-1 py-1 pl-4 pr-3.5",...z,children:[s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",onMouseDown:ye,onClick:Ee,...R,className:De("flex-1 min-w-0 flex items-center gap-1.5 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 rounded-md cursor-grab active:cursor-grabbing transition-[padding]",f&&!x?b?"pr-20":"pr-7 group-hover/project:pr-20 group-focus-within/project:pr-20":b?"pr-14":"pr-7 group-hover/project:pr-14 group-focus-within/project:pr-14"),children:[s.jsx(Em,{id:n,projectLabel:o,projectIcon:c,projectColor:l,projectIconImage:d,projectIconBackground:u,isCollapsed:h,alwaysShowActions:b}),_?s.jsx("span",{className:"ml-1 inline-flex flex-shrink-0 items-center",children:_}):null]})}),s.jsx(At,{side:"right",sideOffset:8,children:i})]}),s.jsxs("div",{className:De("absolute top-1/2 z-10 flex -translate-y-1/2 items-center gap-1",M?"right-7":"right-0.5"),children:[M&&f&&!x&&m?s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:le=>{le.stopPropagation(),m()},className:De("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",b?"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":D("sessions.sidebar.project.actions.newWorktree"),children:s.jsx(I,{name:"node-tree",className:"h-4 w-4"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:D("sessions.sidebar.project.actions.newWorktreeEllipsis")})})]}):null,x?null:s.jsxs(Qs,{open:Oe,onOpenChange:pe,children:[s.jsx(qs,{asChild:!0,children:s.jsx("button",{type:"button",className:De("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",Oe?"opacity-100 pointer-events-auto":b?"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":D("sessions.sidebar.project.actions.projectMenu"),onPointerDown:oe,onMouseDown:ce,onClick:ne,children:s.jsx(I,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(Ys,{align:"end",className:"min-w-[180px]",children:Q(is)})]})]}),M&&g?s.jsx("div",{className:"absolute right-0.5 top-1/2 z-10 -translate-y-1/2",children:s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:le=>{le.stopPropagation(),g()},className:De("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",b?"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":D(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession"),children:s.jsx(I,{name:"add",className:"h-4 w-4"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:s.jsx("p",{children:D(f?"sessions.sidebar.project.actions.newDraftSession":"sessions.sidebar.project.actions.newSession")})})]})}):null]})}),s.jsx(Df,{className:"min-w-[180px]",children:Q(Pf)})]})]}),e[25]=b,e[26]=z,e[27]=pe,e[28]=Ee,e[29]=x,e[30]=L,e[31]=n,e[32]=h,e[33]=se,e[34]=p,e[35]=Oe,e[36]=f,e[37]=R,e[38]=g,e[39]=m,e[40]=l,e[41]=i,e[42]=c,e[43]=u,e[44]=d,e[45]=o,e[46]=Q,e[47]=w,e[48]=M,e[49]=_,e[50]=A,e[51]=D,e[52]=Ae):Ae=e[52];let Se;return e[53]!==N||e[54]!==W||e[55]!==Me||e[56]!==Ne||e[57]!==Ae?(Se=s.jsxs("div",{ref:W,style:Me,className:Ne,children:[Ae,N]}),e[53]=N,e[54]=W,e[55]=Me,e[56]=Ne,e[57]=Ae,e[58]=Se):Se=e[58],Se},ek=t=>{const e=nt.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:l,setNodeRef:d,setActivatorNodeRef:u,transform:h,transition:f,isDragging:p}=ec(c);let x;e[3]!==l||e[4]!==u?(x={listeners:l,setActivatorNodeRef:u},e[3]=l,e[4]=u,e[5]=x):x=e[5];const b=x;let S;e[6]!==h?(S=tc.Transform.toString(h),e[6]=h,e[7]=S):S=e[7];let g;e[8]!==S||e[9]!==f?(g={transform:S,transition:f},e[8]=S,e[9]=f,e[10]=g):g=e[10];const m=p&&"opacity-50";let y;e[11]!==m?(y=De("space-y-0.5 rounded-md",m),e[11]=m,e[12]=y):y=e[12];let C;e[13]!==o||e[14]!==b?(C=typeof o=="function"?o(b):o,e[13]=o,e[14]=b,e[15]=C):C=e[15];let j;return e[16]!==d||e[17]!==g||e[18]!==y||e[19]!==C?(j=s.jsx("div",{ref:d,style:g,className:y,children:C}),e[16]=d,e[17]=g,e[18]=y,e[19]=C,e[20]=j):j=e[20],j},tk=a.memo(ek);function sk(t){return t.stickyZoneHeaders}function nk(t){t.stopPropagation()}function rk(t){t.stopPropagation()}function ok(t){t.stopPropagation()}const ik=48,ak=32,lk=24,nu=(t,e)=>Jl(t.label?.trim()||Vr(t.normalizedPath,e)||t.normalizedPath);function ck(t){sr("ui.sidebar_projects_list.render");const{t:e}=ft(),n=t.isDesktopShellRuntime&&t.stickyZoneHeaders,r=ra(No(bl,{activationConstraint:{distance:8}}),No(Kx,{coordinateGetter:Gx})),o=ra(No(bl,{activationConstraint:{distance:8}})),i=a.useRef(new Map),c=a.useRef(t.getOrderedGroups);c.current!==t.getOrderedGroups&&(c.current=t.getOrderedGroups,i.current.clear());const l=(g,m)=>{const y=i.current,C=y.get(g);if(C&&C.groups===m)return C.ordered;const j=t.getOrderedGroups(g,m);if(y.set(g,{groups:m,ordered:j}),y.size>256){const w=y.keys().next().value;w!==void 0&&y.delete(w)}return j},d=a.useRef(null),u=a.useRef(0),h=a.useCallback(g=>{const y=g.scrollTop>1?Math.min(ak+g.scrollTop,ik):0;u.current=y,g.style.setProperty("--scroll-shadow-top-size",`${y}px`),g.style.setProperty("--scroll-shadow-top-clear-size",`${Math.min(Math.max(y-8,0),lk)}px`)},[]),f=a.useCallback(g=>{g.target.closest("[data-overlay-scrollbar-thumb], [data-sidebar-sticky-header]")||g.clientY-g.currentTarget.getBoundingClientRect().top>=u.current||(g.preventDefault(),g.stopPropagation())},[]),p=t.projectSections.length>0&&t.sectionsForRender.length>0;a.useLayoutEffect(()=>{n&&p&&d.current&&h(d.current)},[n,p,h]);let x=null;for(const g of t.projectSections)t.stuckProjectHeaders.has(g.project.id)&&(x=g.project);const b=x??(t.hasSharedSessions?null:t.sectionsForRender[0]?.project??null),S=b?nu(b,t.homeDirectory):null;return t.sharedSessionsOnly?s.jsxs(On,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:De("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(On,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:De("space-y-1 pb-1 pl-2.5 pr-2",(t.mobileVariant,"")),children:[t.topContent,t.emptyState]}):t.sectionsForRender.length===0?s.jsx(On,{useScrollShadow:!0,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:De("space-y-1 pb-1 pl-2.5 pr-2",(t.mobileVariant,"")),children:t.searchEmptyState}):s.jsxs("div",{className:"oc-sticky-fade-root relative flex min-h-0 flex-1",onPointerDownCapture:n?f:void 0,onClickCapture:n?f:void 0,onContextMenuCapture:n?f:void 0,children:[s.jsxs(On,{ref:d,useScrollShadow:!0,hideTopScrollShadow:!n,scrollShadowSize:96,outerClassName:"flex-1 min-h-0",className:De("oc-sidebar-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?g=>h(g.currentTarget):void 0,children:[t.topContent,t.showOnlyMainWorkspace?s.jsx("div",{className:"space-y-[0.6rem] py-1",children:(()=>{const g=t.sectionsForRender.find(j=>j.project.id===t.activeProjectId)??t.sectionsForRender[0];if(!g)return t.hasSessionSearchQuery?t.searchEmptyState:t.emptyState;const m=g.groups.find(j=>j.isMain&&j.sessions.length>0)??g.groups.find(j=>j.sessions.length>0)??g.groups.find(j=>j.isMain)??g.groups[0];if(!m)return s.jsx("div",{className:"py-1 text-left typography-micro text-muted-foreground",children:e("sessions.sidebar.empty.noSessions.title")});const y=g.groups.find(j=>j.isArchivedBucket);return[m,...y&&y.id!==m.id?[y]:[]].map(j=>{const w=`${g.project.id}:${j.id}`,N=j.id===m.id;return s.jsx(a.Fragment,{children:t.renderGroupSessions(j,w,g.project.id,N,null,!0,d)},w)})})()}):s.jsxs(oa,{sensors:r,collisionDetection:ia,onDragEnd:g=>{if(t.isInlineEditing||t.projectSortOrder!=="manual")return;const{active:m,over:y}=g;if(!y||m.id===y.id)return;const C=t.sectionsForRender.findIndex(w=>w.project.id===m.id),j=t.sectionsForRender.findIndex(w=>w.project.id===y.id);C===-1||j===-1||C===j||t.reorderProjects(C,j)},children:[s.jsx(wl,{items:t.sectionsForRender.map(g=>g.project.id),strategy:vl,children:t.sectionsForRender.map(g=>{const m=g.project,y=m.id,C=nu(m,t.homeDirectory),j=Zi(m.normalizedPath,t.homeDirectory),w=t.collapsedProjects.has(y),N=t.projectRepoStatus.get(y);return s.jsx(ZS,{id:y,disabled:t.projectSortOrder!=="manual",projectLabel:C,projectDescription:j,projectIcon:m.icon,projectColor:m.color,projectIconImage:m.iconImage,projectIconBackground:m.iconBackground,isCollapsed:w,isRepo:!!N,isDesktopShell:t.isDesktopShellRuntime,hideDirectoryControls:t.hideDirectoryControls,mobileVariant:t.mobileVariant,alwaysShowActions:t.alwaysShowActions,statusIndicator:w?t.renderProjectStatusIndicator?.(y,g.groups):null,onToggle:()=>t.toggleProject(y),onNewSession:()=>{y!==t.activeProjectId&&t.setActiveProjectIdOnly(y),t.setActiveMainTab("chat"),t.mobileVariant&&t.setSessionSwitcherOpen(!1),t.openNewSessionDraft({selectedProjectId:y,directoryOverride:m.normalizedPath})},onNewWorktreeSession:()=>{y!==t.activeProjectId&&t.setActiveProjectIdOnly(y),t.setActiveMainTab("chat"),t.openNewWorktreeDialog()},onManageWorktrees:()=>t.openWorktreesPage(y),onRenameStart:()=>t.openProjectEditDialog(y),onClose:()=>t.removeProject(y),sentinelRef:v=>{t.projectHeaderSentinelRefs.current.set(y,v)},showCreateButtons:!0,openSidebarMenuKey:t.openSidebarMenuKey,setOpenSidebarMenuKey:t.setOpenSidebarMenuKey,children:w?null:s.jsx("div",{className:"space-y-0 pt-0.5 pb-0.5",children:(()=>{const v=l(y,g.groups),P=v.find(k=>k.isMain)??null,F=P?v.filter(k=>k.id!==P.id):v;return s.jsxs(oa,{sensors:o,collisionDetection:ia,onDragEnd:k=>{if(t.isInlineEditing)return;const{active:E,over:O}=k;if(!O||E.id===O.id)return;const M=F.findIndex(A=>A.id===E.id),L=F.findIndex(A=>A.id===O.id);if(M===-1||L===-1||M===L)return;const _=zf(F,M,L).map(A=>A.id),D=P?[P.id,..._]:_;t.setGroupOrderByProject(A=>{const T=new Map(A);return T.set(y,D),T})},children:[P?t.renderGroupSessions(P,`${y}:${P.id}`,y,!0,null,void 0,d):null,s.jsx(wl,{items:F.map(k=>k.id),strategy:vl,children:F.map(k=>{const E=`${y}:${k.id}`;return s.jsx(tk,{id:k.id,disabled:t.isInlineEditing,children:O=>t.renderGroupSessions(k,E,y,!1,O,void 0,d)},k.id)})}),s.jsx(yl,{dropAnimation:null})]})})()})},y)})}),s.jsx(yl,{dropAnimation:null})]})]}),n&&(b||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:b&&S?s.jsx(Em,{id:b.id,projectLabel:S,projectIcon:b.icon,projectColor:b.color,projectIconImage:b.iconImage,projectIconBackground:b.iconBackground}):s.jsxs(s.Fragment,{children:[s.jsx(I,{name:"history",className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground/80"}),s.jsx("span",{className:"truncate text-[14px] font-semibold lowercase text-foreground",children:e("sessions.sidebar.activity.recentTitle")})]})}):null]})}const dk=a.memo(ck),uk=(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},hn=$o()((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 l=i.scopeKey,d=i.anchorId;r!==null&&i.scopeKey!==null&&r!==i.scopeKey?(c.clear(),l=r,d=null):l===null&&r!==null&&(l=r);const h=o&&o.length>0?[n,...o]:[n];if(c.has(n)){for(const p of h)c.delete(p);d===n&&(d=null)}else{for(const p of h)c.add(p);d=n}c.size===0?t({selectedIds:c,scopeKey:null,anchorId:null}):t({selectedIds:c,scopeKey:l,anchorId:d})},setRange:(n,r,o,i,c)=>{const l=e();if(o.length===0)return;const d=n&&o.includes(n)?n:o[0],u=o.indexOf(d),h=o.indexOf(r);if(u<0||h<0)return;const[f,p]=u<=h?[u,h]:[h,u],x=o.slice(f,p+1),b=uk(x,c),g=i!==null&&l.scopeKey!==null&&i!==l.scopeKey?new Set:new Set(l.selectedIds);for(const m of b)g.add(m);t({selectedIds:g,scopeKey:i??l.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 Pl=!1;const Il=new Set;let ru=!1;function fk(){for(const t of Il)t()}function gc(t){Pl!==t&&(Pl=t,fk())}function mk(t){t.key==="Shift"&&gc(!0)}function hk(t){t.key==="Shift"&&gc(!1)}function pk(){gc(!1)}function gk(){ru||typeof window>"u"||(ru=!0,window.addEventListener("keydown",mk),window.addEventListener("keyup",hk),window.addEventListener("blur",pk))}function xk(t){return gk(),Il.add(t),()=>{Il.delete(t)}}function bk(){return Pl}function yk(){return!1}function wk(){return $e.useSyncExternalStore(xk,bk,yk)}const vk=/^[a-z0-9](?:[a-z0-9-]{0,48}[a-z0-9])?$/,Fm=/^g[1-9]\d*$/,Zo=(t,e,n,r,o)=>{if(!vk.test(t)||e!==void 0&&!Fm.test(e)||!n?.trim()||!r?.trim()||n!==n.trim()||r!==r.trim())return null;if(o===void 0)return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!1};if(o==="fusion")return{groupSlug:t,runGroup:e,providerID:n,modelID:r,fusion:!0};if(!/^\d+$/.test(o))return null;const i=Number.parseInt(o,10);return!Number.isSafeInteger(i)||i<=0?null:{groupSlug:t,runGroup:e,providerID:n,modelID:r,index:i,fusion:!1}},Hi=t=>{if(!t)return null;const e=t.split("/");if(e.length<3||e.length>5)return null;const[n]=e;if(e.length===3)return Zo(n,void 0,e[1],e[2],void 0);if(e.length===4){const[,l,d,u]=e;return Fm.test(l)?Zo(n,l,d,u,void 0):Zo(n,void 0,l,d,u)}const[,r,o,i,c]=e;return r===""?Zo(n,void 0,o,i,c):Zo(n,r,o,i,c)},jk=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("/")},Sk=(t,e,n,r)=>{const o=[t];return r&&o.push(r),o.push(e,n,"fusion"),o.join("/")},Om=t=>{const e=nt.c(36),{value:n,onChange:r,className:o,disabled:i,id:c,portalToBody:l}=t,{t:d}=ft(),u=ts(kk),h=ts(Nk),f=ts(Ck);let p;e[0]!==u?(p=u(),e[0]=u,e[1]=p):p=e[1];const x=p;let b;e[2]!==x?(b=x.filter(Ak),e[2]=x,e[3]=b):b=e[3];const S=b;let g,m;e[4]!==x.length||e[5]!==h?(g=()=>{x.length===0&&h()},m=[x.length,h],e[4]=x.length,e[5]=h,e[6]=g,e[7]=m):(g=e[6],m=e[7]),a.useEffect(g,m);let y,C;e[8]!==f||e[9]!==i||e[10]!==r||e[11]!==S||e[12]!==n?(y=()=>{if(i)return;const O=n.trim();if(O.length>0&&S.some(_=>_.name===O))return;const M=typeof f=="string"&&f.trim().length>0?f.trim():null;if(M&&S.some(_=>_.name===M)){r(M);return}const L=S[0]?.name;L&&r(L)},C=[f,i,r,S,n],e[8]=f,e[9]=i,e[10]=r,e[11]=S,e[12]=n,e[13]=y,e[14]=C):(y=e[13],C=e[14]),a.useEffect(y,C);const j=n.trim().length>0?n:void 0;let w;e[15]!==o?(w=De("max-w-full",o),e[15]=o,e[16]=w):w=e[16];let N;e[17]!==d?(N=d("multirun.agentSelector.placeholder"),e[17]=d,e[18]=N):N=e[18];let v;e[19]!==N?(v=s.jsx(sn,{placeholder:N}),e[19]=N,e[20]=v):v=e[20];let P;e[21]!==c||e[22]!==w||e[23]!==v?(P=s.jsx(xn,{id:c,size:"lg",className:w,children:v}),e[21]=c,e[22]=w,e[23]=v,e[24]=P):P=e[24];let F;e[25]!==S?(F=S.length>0&&s.jsx(hl,{children:S.map(Dk)}),e[25]=S,e[26]=F):F=e[26];let k;e[27]!==l||e[28]!==F?(k=s.jsx(bn,{fitContent:!0,portalToBody:l,children:F}),e[27]=l,e[28]=F,e[29]=k):k=e[29];let E;return e[30]!==i||e[31]!==r||e[32]!==j||e[33]!==P||e[34]!==k?(E=s.jsxs(gn,{value:j,onValueChange:r,disabled:i,children:[P,k]}),e[30]=i,e[31]=r,e[32]=j,e[33]=P,e[34]=k,e[35]=E):E=e[35],E};function kk(t){return t.getVisibleAgents}function Nk(t){return t.loadAgents}function Ck(t){return t.currentAgentName}function Ak(t){return hf(t.mode)}function Dk(t){return s.jsx(bs,{value:t.name,className:"w-auto whitespace-nowrap",children:t.name},t.name)}const Pk="h-7",oi=()=>`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,Ik=t=>{const e=nt.c(12),{model:n,instanceIndex:r,totalSameModel:o,onRemove:i}=t,c=n.displayName||`${n.providerID}/${n.modelID}`,l=o>1?`${c} (${r})`:c;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=De("flex items-center gap-1.5 px-2 rounded-md bg-interactive-selection/20 border border-border/30",Pk),e[0]=d):d=e[0];let u;e[1]!==n.providerID?(u=s.jsx(ai,{providerId:n.providerID,className:"h-3.5 w-3.5"}),e[1]=n.providerID,e[2]=u):u=e[2];let h;e[3]!==l?(h=s.jsx("span",{className:"typography-meta font-medium truncate max-w-[140px]",children:l}),e[3]=l,e[4]=h):h=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 x;return e[8]!==u||e[9]!==h||e[10]!==p?(x=s.jsxs("div",{className:d,children:[u,h,p]}),e[8]=u,e[9]=h,e[10]=p,e[11]=x):x=e[11],x},Lm=t=>{const e=nt.c(120),{selectedModels:n,onAdd:r,onRemove:o,onUpdate:i,minModels:c,addButtonLabel:l,showChips:d,maxModels:u,addButtonClassName:h,dropdownSide:f,dropdownClassName:p,containerClassName:x,triggerIcon:b}=t,S=d===void 0?!0:d,g=f===void 0?"top":f,{t:m}=ft(),y=ts(Rk),C=ts(Mk),j=Re(Tk),w=Re(Ek),{favoriteModelsList:N,recentModelsList:v}=Wp(),P=Re(Fk),F=Re(Ok),[k,E]=a.useState(!1),[O,M]=a.useState(""),[L,_]=a.useState(null),D=a.useRef(null),A=a.useRef(null),T=u===1,z=u===void 0||n.length<u||T;let R;if(e[0]!==n){R=new Map;for(const be of n){const Le=`${be.providerID}:${be.modelID}`;R.set(Le,(R.get(Le)||0)+1)}e[0]=n,e[1]=R}else R=e[1];const W=R;let J;e[2]!==n?(J=be=>n.filter(Ke=>Ke.providerID===be.providerID&&Ke.modelID===be.modelID).findIndex(Ke=>Ke.instanceId===be.instanceId)+1,e[2]=n,e[3]=J):J=e[3];const U=J;let te,Z;e[4]!==g||e[5]!==k?(te=()=>{if(!k||!A.current)return;const be=A.current.getBoundingClientRect();if(g==="bottom"){const pt=(window.visualViewport?.height??document.documentElement.clientHeight??window.innerHeight)-be.bottom-16-112;_(Math.max(160,Math.min(320,pt)));return}let Le=A.current.parentElement;for(;Le&&!(Le.getAttribute("role")==="dialog"||Le.hasAttribute("data-scroll-shadow"));){const ut=getComputedStyle(Le);if(ut.overflow==="auto"||ut.overflow==="hidden"||ut.overflowY==="auto"||ut.overflowY==="hidden")break;Le=Le.parentElement}const Ke=Le?Le.getBoundingClientRect().top:0,st=be.top-Ke-16;_(Math.max(150,Math.min(300,st)))},Z=[g,k],e[4]=g,e[5]=k,e[6]=te,e[7]=Z):(te=e[6],Z=e[7]),a.useEffect(te,Z);let ue,Oe;e[8]!==z||e[9]!==k?(ue=()=>{!z&&k&&(E(!1),M(""))},Oe=[z,k],e[8]=z,e[9]=k,e[10]=ue,e[11]=Oe):(ue=e[10],Oe=e[11]),a.useEffect(ue,Oe);let se,G;e[12]!==k?(se=()=>{if(!k)return;const be=Le=>{D.current&&!D.current.contains(Le.target)&&(E(!1),M(""))};return document.addEventListener("mousedown",be),()=>document.removeEventListener("mousedown",be)},G=[k],e[12]=k,e[13]=se,e[14]=G):(se=e[13],G=e[14]),a.useEffect(se,G);let Ie;e[15]!==T||e[16]!==r||e[17]!==i||e[18]!==n.length?(Ie=be=>{const Le={providerID:be.providerID,modelID:be.modelID,displayName:be.model.name||be.modelID,instanceId:oi()};T&&n.length>0&&i?i(0,Le):r(Le),T&&(E(!1),M(""))},e[15]=T,e[16]=r,e[17]=i,e[18]=n.length,e[19]=Ie):Ie=e[19];const pe=Ie;let V;e[20]!==m?(V=m("multirun.modelMultiSelect.search.placeholder"),e[20]=m,e[21]=V):V=e[21];let Q;e[22]!==m?(Q=m("multirun.modelMultiSelect.search.noResults"),e[22]=m,e[23]=Q):Q=e[23];let ne;e[24]!==m?(ne=m("multirun.modelMultiSelect.sections.favorites"),e[24]=m,e[25]=ne):ne=e[25];let oe;e[26]!==m?(oe=m("multirun.modelMultiSelect.sections.recent"),e[26]=m,e[27]=oe):oe=e[27];let ce;e[28]!==m?(ce=m("multirun.modelMultiSelect.keyboard.hint"),e[28]=m,e[29]=ce):ce=e[29];let ke;e[30]!==m?(ke=m("settings.agents.modelSelector.actions.favorite"),e[30]=m,e[31]=ke):ke=e[31];let ye;e[32]!==m?(ye=m("settings.agents.modelSelector.actions.unfavorite"),e[32]=m,e[33]=ye):ye=e[33];let he;e[34]!==m?(he=m("chat.modelControls.capabilities"),e[34]=m,e[35]=he):he=e[35];let Ee;e[36]!==m?(Ee=m("chat.modelControls.capability.toolCalling"),e[36]=m,e[37]=Ee):Ee=e[37];let Ue;e[38]!==m?(Ue=m("chat.modelControls.capability.reasoning"),e[38]=m,e[39]=Ue):Ue=e[39];let Me;e[40]!==m?(Me=m("chat.modelControls.input"),e[40]=m,e[41]=Me):Me=e[41];let X;e[42]!==m?(X=m("chat.modelControls.output"),e[42]=m,e[43]=X):X=e[43];let Ne;e[44]!==m?(Ne=m("chat.modelControls.costPerMillion"),e[44]=m,e[45]=Ne):Ne=e[45];let Ae;e[46]!==V||e[47]!==Q||e[48]!==ne||e[49]!==oe||e[50]!==ce||e[51]!==ke||e[52]!==ye||e[53]!==he||e[54]!==Ee||e[55]!==Ue||e[56]!==Me||e[57]!==X||e[58]!==Ne?(Ae={searchPlaceholder:V,noResults:Q,favorites:ne,recent:oe,keyboardHint:ce,favorite:ke,unfavorite:ye,capabilities:he,capabilityToolCalling:Ee,capabilityReasoning:Ue,input:Me,output:X,costPerMillion:Ne},e[46]=V,e[47]=Q,e[48]=ne,e[49]=oe,e[50]=ce,e[51]=ke,e[52]=ye,e[53]=he,e[54]=Ee,e[55]=Ue,e[56]=Me,e[57]=X,e[58]=Ne,e[59]=Ae):Ae=e[59];const Se=Ae;let le;e[60]!==x?(le=De("relative",x),e[60]=x,e[61]=le):le=e[61];const ee=k?"":void 0;let ie;e[62]!==h?(ie=De(xa({size:"default"}),"w-fit",h),e[62]=h,e[63]=ie):ie=e[63];const ve=!z;let K;e[64]!==k?(K=()=>{E(!k)},e[64]=k,e[65]=K):K=e[65];let de;e[66]!==b?(de=b??s.jsx(I,{name:"add",className:"h-3.5 w-3.5 mr-1"}),e[66]=b,e[67]=de):de=e[67];let _e;e[68]!==l||e[69]!==m?(_e=l??m("multirun.modelMultiSelect.actions.addModel"),e[68]=l,e[69]=m,e[70]=_e):_e=e[70];let Pe;e[71]!==ee||e[72]!==ie||e[73]!==ve||e[74]!==K||e[75]!==de||e[76]!==_e?(Pe=s.jsxs("button",{ref:A,type:"button","data-popup-open":ee,className:ie,disabled:ve,onClick:K,children:[de,_e]}),e[71]=ee,e[72]=ie,e[73]=ve,e[74]=K,e[75]=de,e[76]=_e,e[77]=Pe):Pe=e[77];let re;e[78]!==L||e[79]!==z||e[80]!==p||e[81]!==g||e[82]!==N||e[83]!==pe||e[84]!==P||e[85]!==w||e[86]!==k||e[87]!==Se||e[88]!==W||e[89]!==C||e[90]!==F||e[91]!==y||e[92]!==v||e[93]!==O||e[94]!==j?(re=k?s.jsx("div",{className:De("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(Up,{providers:y,providerOrder:F,favoriteModels:N,recentModels:v,modelsMetadata:C,hiddenModels:P,searchQuery:O,onSearchQueryChange:M,onSelect:pe,labels:Se,selectionCount:be=>W.get(`${be.providerID}:${be.modelID}`)||0,disabled:!z,maxHeightClassName:"flex-1",maxHeightStyle:{maxHeight:L?`${L}px`:"300px"},stickyHeaders:!0,tooltipsEnabled:k,isFavorite:be=>w(be.providerID,be.modelID),onToggleFavorite:be=>j(be.providerID,be.modelID),onEscape:()=>{E(!1),M("")}})}):null,e[78]=L,e[79]=z,e[80]=p,e[81]=g,e[82]=N,e[83]=pe,e[84]=P,e[85]=w,e[86]=k,e[87]=Se,e[88]=W,e[89]=C,e[90]=F,e[91]=y,e[92]=v,e[93]=O,e[94]=j,e[95]=re):re=e[95];let me;e[96]!==le||e[97]!==Pe||e[98]!==re?(me=s.jsxs("div",{className:le,ref:D,children:[Pe,re]}),e[96]=le,e[97]=Pe,e[98]=re,e[99]=me):me=e[99];let ge;e[100]!==U||e[101]!==W||e[102]!==o||e[103]!==i||e[104]!==y||e[105]!==n||e[106]!==S||e[107]!==m?(ge=S&&n.length>0&&s.jsx("div",{className:"flex flex-col gap-2 w-full",children:n.map((be,Le)=>{const Ke=`${be.providerID}:${be.modelID}`,st=W.get(Ke)||1,ut=U(be),pt=y.find(bt=>bt.id===be.providerID)?.models?.find(bt=>bt.id===be.modelID),ht=pt?.variants?Object.keys(pt.variants):[],xt=ht.length>0,wt=be.variant??"__default__";return s.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Ik,{model:be,instanceIndex:ut,totalSameModel:st,onRemove:()=>o(Le)}),xt&&s.jsxs(gn,{value:wt,onValueChange:bt=>{if(!i)return;i(Le,{...be,variant:bt==="__default__"?void 0:bt})},children:[s.jsxs(xn,{size:"sm",className:"gap-1.5",children:[s.jsx(I,{name:"brain-ai-3",className:De("h-3.5 w-3.5 flex-shrink-0",wt==="__default__"?"text-muted-foreground":"text-[color:var(--status-info)]")}),s.jsx(sn,{placeholder:m("multirun.modelMultiSelect.variant.placeholder"),children:bt=>bt==="__default__"?m("multirun.modelMultiSelect.variant.default"):bt})]}),s.jsxs(bn,{fitContent:!0,children:[s.jsx(bs,{value:"__default__",className:"pr-2 [&>span:first-child]:hidden",children:m("multirun.modelMultiSelect.variant.default")}),ht.map(Lk)]})]})]},be.instanceId)})}),e[100]=U,e[101]=W,e[102]=o,e[103]=i,e[104]=y,e[105]=n,e[106]=S,e[107]=m,e[108]=ge):ge=e[108];let $;e[109]!==me||e[110]!==ge?($=s.jsxs("div",{className:"flex flex-wrap gap-1.5 items-center",children:[me,ge]}),e[109]=me,e[110]=ge,e[111]=$):$=e[111];let B;e[112]!==u||e[113]!==c||e[114]!==n.length||e[115]!==m?(B=c!==void 0&&n.length<c&&s.jsx("p",{className:"typography-micro text-muted-foreground",children:u!==void 0?m("multirun.modelMultiSelect.validation.minToMax",{min:c,max:u}):m("multirun.modelMultiSelect.validation.minOnly",{min:c})}),e[112]=u,e[113]=c,e[114]=n.length,e[115]=m,e[116]=B):B=e[116];let xe;return e[117]!==$||e[118]!==B?(xe=s.jsxs("div",{className:"space-y-2",children:[$,B]}),e[117]=$,e[118]=B,e[119]=xe):xe=e[119],xe};function Rk(t){return t.providers}function Mk(t){return t.modelsMetadata}function Tk(t){return t.toggleFavoriteModel}function Ek(t){return t.isFavoriteModel}function Fk(t){return t.hiddenModels}function Ok(t){return t.providerOrder}function Lk(t){return s.jsx(bs,{value:t,className:"pr-2 [&>span:first-child]:hidden",children:t},t)}const Bk=(t,e,n)=>{const r=t.session.title?.trim()||t.session.id;return`
195
-
196
- --- RESULT ${n+1}: ${r} ---
197
- ${e.trim()}
198
- --- END RESULT ${n+1} ---`},ou=(t,e)=>et.getState().getWorktreeMetadata(t)?.projectDirectory??e,$k=async t=>{const e=t.directory??void 0,n=Kp(t.session.id,e);if(n.length===0&&t.directory){const o=(await Fn.withDirectory(t.directory,()=>Fn.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 Fc(c.parts??[]).trim()}return""}for(let r=n.length-1;r>=0;r-=1){const o=n[r];if(o.role==="assistant")return Fc(Gp(o.id,e)).trim()}return""};function _k({session:t,open:e,onOpenChange:n}){const{t:r}=ft(),o=Hp(),i=pn(T=>T.activeSessions),c=pn(T=>T.archivedSessions),l=ts(T=>T.providers),d=ts(T=>T.currentProviderId),u=ts(T=>T.currentModelId),h=ts(T=>T.currentAgentName),[f,p]=a.useState(d??""),[x,b]=a.useState(u??""),[S,g]=a.useState(()=>d&&u?[{providerID:d,modelID:u,instanceId:oi()}]:[]),[m,y]=a.useState(""),[C,j]=a.useState(h??""),[w,N]=a.useState([]),[v,P]=a.useState(!1),F=a.useMemo(()=>Hi(t.title),[t.title]),k=a.useMemo(()=>{const T=new Map;for(const z of o)T.set(z.id,z);for(const z of i)T.set(z.id,z);for(const z of c)T.set(z.id,z);return t.id&&T.set(t.id,t),Array.from(T.values())},[i,c,o,t]);a.useEffect(()=>{if(!e||!F)return;const T=et.getState().getDirectoryForSession(t.id),z=ou(t.id,T),R=k.map(W=>{const J=Hi(W.title);if(!J||J.groupSlug!==F.groupSlug||J.fusion||(J.runGroup??null)!==(F.runGroup??null))return null;const U=et.getState().getDirectoryForSession(W.id)??Bn(W),te=ou(W.id,U);return z&&te&&z!==te?null:{session:W,directory:U,projectDirectory:te}}).filter(W=>W!==null).sort((W,J)=>(W.session.time?.created??0)-(J.session.time?.created??0));N(R)},[k,e,F,t.id]);const O=l.find(T=>T.id===f)?.models.find(T=>T.id===x),M=O?.variants?Object.keys(O.variants):[],L=!!(F&&f&&x&&w.length>0&&!v),_=a.useCallback(T=>{g([T]),p(T.providerID),b(T.modelID),y("")},[]),D=S[0]?.displayName||S[0]?.modelID||r("multirun.fusion.model.placeholder"),A=async()=>{if(!(!F||!f||!x)){P(!0);try{const T=await Promise.all(w.map(Z=>$k(Z))),z=w.map((Z,ue)=>({source:Z,text:T[ue]??""})).filter(Z=>Z.text.trim().length>0);if(z.length===0){fe.error(r("multirun.fusion.toast.noOutputs"));return}const R=w[0]?.projectDirectory??w[0]?.directory??null,W=Sk(F.groupSlug,f,x,F.runGroup),[J,U]=await Promise.all([Ro("session.fusion.visible"),Ro("session.fusion.instructions")]),te=await et.getState().createSession(W,R,null);if(!te)throw new Error("Failed to create fusion session");et.getState().setCurrentSession(te.id,R),n(!1),await Fn.sendMessage({id:te.id,providerID:f,modelID:x,variant:m||void 0,agent:C||void 0,text:J,additionalParts:[{text:U,synthetic:!0},...z.map((Z,ue)=>({text:Bk(Z.source,Z.text,ue),synthetic:!0})),{text:`
199
-
200
- --- FUSION INPUTS END ---
201
- Now write the final fused answer.`,synthetic:!0}],directory:R??Fn.getDirectory()})}catch(T){console.error("[MultiRunFusion] Failed to start fusion",T),fe.error(r("multirun.fusion.toast.failed"))}finally{P(!1)}}};return s.jsx(Ts,{open:e,onOpenChange:n,children:s.jsxs(Es,{className:"max-w-xl overflow-visible",children:[s.jsxs(Hs,{children:[s.jsx($s,{children:r("multirun.fusion.title")}),s.jsx(Ks,{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(Lm,{selectedModels:S,onAdd:_,onUpdate:(T,z)=>_(z),onRemove:()=>{g([]),p(""),b(""),y("")},maxModels:1,addButtonLabel:D,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(ai,{providerId:f,className:"h-3.5 w-3.5 mr-1"}):void 0})}),M.length>0?s.jsxs(gn,{value:m||"__default__",onValueChange:T=>y(T==="__default__"?"":T),children:[s.jsxs(xn,{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(sn,{children:T=>T==="__default__"?r("multirun.modelMultiSelect.variant.default"):T})]}),s.jsxs(bn,{fitContent:!0,portalToBody:!0,children:[s.jsx(bs,{value:"__default__",children:r("multirun.modelMultiSelect.variant.default")}),M.map(T=>s.jsx(bs,{value:T,children:T},T))]})]}):null,s.jsx(Om,{value:C,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:w.length})}),s.jsx("div",{className:"max-h-56 space-y-1 overflow-auto rounded-lg border border-[var(--interactive-border)] p-1",children:w.map(T=>s.jsxs("div",{className:"flex items-center gap-2 rounded-md px-2 py-1.5 typography-meta",children:[s.jsx(ai,{providerId:Hi(T.session.title)?.providerID??"",className:"h-4 w-4"}),s.jsx("span",{className:"min-w-0 flex-1 truncate",children:T.session.title||T.session.id}),s.jsx("button",{type:"button",onClick:()=>N(z=>z.filter(R=>R.session.id!==T.session.id)),className:"text-muted-foreground hover:text-foreground",children:s.jsx(I,{name:"close",className:"h-4 w-4"})})]},T.session.id))})]}),s.jsxs(ar,{children:[s.jsx(He,{variant:"ghost",onClick:()=>n(!1),children:r("multirun.fusion.actions.cancel")}),s.jsx(He,{onClick:A,disabled:!L,children:r(v?"multirun.fusion.actions.starting":"multirun.fusion.actions.start")})]})]})})}function zk(t){const e=nt.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 l;return e[5]!==t?(l=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]=l):l=e[6],l}const Rl=6,Ri=14,iu=Rl+14+6,rl=new WeakMap,Vk=t=>{if(typeof window>"u")return;const e=t.closest("[data-session-row]"),n=e?.closest(".overlay-scrollbar-container");if(!e||!n)return;rl.get(n)?.();const r=e.getBoundingClientRect().top;let o=3,i=!1,c=null;const l=()=>{i=!0,c!==null&&window.cancelAnimationFrame(c),c=null,rl.delete(n),n.removeEventListener("wheel",l),n.removeEventListener("touchstart",l)},d=()=>{if(i||!e.isConnected||!n.isConnected){l();return}const u=e.getBoundingClientRect().top-r;if(Math.abs(u)>.5&&(n.scrollTop+=u,sr("ui.sidebar.selection_scroll_anchor_adjustment")),o-=1,o<=0){l();return}c=window.requestAnimationFrame(d)};n.addEventListener("wheel",l,{passive:!0}),n.addEventListener("touchstart",l,{passive:!0}),rl.set(n,l),c=window.requestAnimationFrame(d)},Wk=a.memo(function(e){const n=nt.c(22),{archiveLabel:r,deleteLabel:o,buttonSizeClass:i,iconSizeClass:c,onPointerDown:l,onMouseDown:d,onArchive:u,onDelete:h}=e,f=wk(),p=f?o:r;let x;n[0]!==u||n[1]!==h||n[2]!==f?(x=N=>{if(f||N.shiftKey){h(N);return}u(N)},n[0]=u,n[1]=h,n[2]=f,n[3]=x):x=n[3];const b=x,S=f?"text-destructive hover:text-destructive":"text-muted-foreground hover:text-foreground";let g;n[4]!==i||n[5]!==S?(g=De("inline-flex items-center justify-center rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 transition-opacity",S,i),n[4]=i,n[5]=S,n[6]=g):g=n[6];const m=f?"delete-bin":"archive";let y;n[7]!==c||n[8]!==m?(y=s.jsx(I,{name:m,className:c}),n[7]=c,n[8]=m,n[9]=y):y=n[9];let C;n[10]!==b||n[11]!==p||n[12]!==d||n[13]!==l||n[14]!==g||n[15]!==y?(C=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",className:g,"aria-label":p,onPointerDown:l,onMouseDown:d,onClick:b,onKeyDown:Qk,children:y})}),n[10]=b,n[11]=p,n[12]=d,n[13]=l,n[14]=g,n[15]=y,n[16]=C):C=n[16];let j;n[17]!==p?(j=s.jsx(At,{side:"left",sideOffset:8,children:p}),n[17]=p,n[18]=j):j=n[18];let w;return n[19]!==C||n[20]!==j?(w=s.jsxs(Nt,{children:[C,j]}),n[19]=C,n[20]=j,n[21]=w):w=n[21],w});function Uk(t){sr("ui.sidebar_session_node.render");const{t:e}=ft(),{node:n,depth:r=0,groupDirectory:o,projectId:i,archivedBucket:c=!1,pinnedSessionIds:l,expandedParents:d,hasSessionSearchQuery:u,normalizedSessionSearchQuery:h,notifyOnSubtasks:f,editingId:p,setEditingId:x,editTitle:b,setEditTitle:S,handleSaveEdit:g,handleCancelEdit:m,toggleParent:y,handleSessionSelect:C,handleSessionDoubleClick:j,togglePinnedSession:w,handleShareSession:N,copiedSessionId:v,handleCopyShareUrl:P,handleCopySessionId:F,handleUnshareSession:k,openSidebarMenuKey:E,setOpenSidebarMenuKey:O,renamingFolderId:M,getFoldersForScope:L,getSessionFolderId:_,removeSessionFromFolder:D,addSessionToFolder:A,createFolderAndStartRename:T,openContextPanelTab:z,handleDeleteSession:R,mobileVariant:W,alwaysShowActions:J,renderSessionNode:U,secondaryMeta:te,renderContext:Z="project",subtreeContainsEditing:ue,menuOpenSessionId:Oe,childRenderExtrasFor:se}=t,G=a.useMemo(()=>ir(),[]),Ie=a.useMemo(()=>ma(),[]),pe=a.useContext(qp),V=G?"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",Q=G?"group-hover:opacity-0":"group-hover:opacity-0 group-focus-within:opacity-0",ne=G,oe=!c&&!W,ce=G?oe&&ne?"group-hover:pr-18":oe||ne?"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",ke=oe?"pr-13":"pr-7",ye=a.useRef(!1),[he,Ee]=a.useState(!1),Ue=a.useRef(p);Ue.current=p;const Me=a.useRef(null),X=a.useRef(g);X.current=g;const[Ne,Ae]=a.useState(b),Se=a.useRef(Ne);Se.current=Ne;const le=a.useRef(null),ee=a.useRef(null),ie=n.session,ve=ie,K=ms(a.useCallback(Be=>{if(te?.projectLabel||!i)return null;const It=Be.projects.find(ns=>ns.id===i);return It?It.label?.trim()||Vr(Vt(It.path)??It.path,null)||It.path:null},[i,te?.projectLabel])),de=te?.projectLabel??(K?Jl(K):null),_e=te?.branchLabel??n.worktree?.branch??null,Pe=a.useMemo(()=>{if(G)return null;const Be=n.worktree?.branch?.trim(),It=Vt(n.worktree?.path??null);return Be&&It?bi(It,Be):null},[G,n.worktree]),re=Ff(Pe),me=re?`var(--pr-${re.visualState})`:void 0,ge=ln(Be=>Be.sessionGroupingMode),$=!!_e&&(Z==="recent"||ge==="flat"),B=a.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]),xe=et(Be=>Be.currentSessionId===ie.id),be=Vt(ie.directory??null)??Vt(o??null),Le=i??be??null,Ke=$l(be??void 0,{bootstrap:!1}),st=pa(),ut=hn(Be=>Be.enabled),mt=hn(a.useCallback(Be=>Be.selectedIds.has(ie.id),[ie.id])),pt=hn(Be=>Be.toggleSelected),ht=hn(Be=>Be.setRange),xt=a.useCallback(Be=>{const It=[],ns=ds=>{ds.children.forEach(ws=>{It.push(ws.session.id),ns(ws)})};return ns(Be),It},[]),wt=a.useCallback(Be=>{const It=[],ns=ds=>{ds.children.forEach(ws=>{It.push(ws.session),ns(ws)})};return ns(Be),It},[]),[bt,Dt]=a.useState(!1),[qt,Ut]=a.useState(!0),We=`${Z}:${c?"archived":"active"}:${ie.id}`,yt=pf(a.useCallback(Be=>!!Be.sessionMemoryState.get(Yp(ie.id))?.isZombie,[ie.id])),Qe=tf(ie.id),Rt=Xf(ie.id),Ot=Qp(ie.id,be??void 0,{bootstrap:!1}),kt=Xp(ve),Ft=kt?s.jsx("span",{className:"inline-flex flex-shrink-0 items-center",title:e(Oc[kt.status]),"aria-label":e(Oc[kt.status]),children:s.jsx(I,{name:"target",className:"h-3 w-3",style:{color:Jp[kt.status]}})}):null,Ht=ve.title||e("sessions.sidebar.session.untitled"),Xt=n.children.length>0,rt=Zp(l,be,ie.id),je=We,Fe=u?!0:d.has(je),Te=!!ve.parentID,ct=eg(ie.id)>0&&(!Te||f),Kt=ve.time?.updated||ve.time?.created||Date.now(),Lt=gf(Kt),ze=tg(Kt),Xe=E===We,[tt,at]=a.useState(!1),Ze=Xe||tt,Pt=a.useMemo(()=>Hi(ve.title)!==null,[ve.title]),[Tt,Jt]=a.useState(!1),ls=a.useMemo(()=>xt(n).length,[xt,n]),cs=a.useCallback(async Be=>{const It=[];let ns=0;for(const ds of Be)try{if(!be)throw new Error("Session directory is required for export");await st.loadCompleteHistory(ds.session.id,be);const ws=ul(Ke.getState(),ds.session.id).list,Ds=ds.session.title||e("sessions.sidebar.session.export.untitledSubagent"),on=ds.session.agent,Ps=await cs(ds.children);ns+=Ps.skipped,It.push({title:Ds,agent:on,records:ws,children:Ps.children})}catch{ns+=xt(ds).length+1}return{children:It,skipped:ns}},[xt,Ke,be,st,e]),Bt=a.useCallback(Be=>{Be<=0||fe.warning(Be===1?e("sessions.sidebar.session.export.skippedSubtaskSingle",{count:Be}):e("sessions.sidebar.session.export.skippedSubtaskMany",{count:Be}))},[e]),_t=a.useCallback(async Be=>{if(!be){fe.error(e("sessions.sidebar.session.export.nothingToExport"));return}try{await st.loadCompleteHistory(ie.id,be)}catch{fe.error(e("sessions.sidebar.session.export.failedLoadHistory"));return}const It=ul(Ke.getState(),ie.id).list;if(It.length===0){fe.error(e("sessions.sidebar.session.export.nothingToExport"));return}let ns,ds=0;if(Be&&n.children.length>0){const Ps=await cs(n.children);ns=Ps.children,ds=Ps.skipped}const ws=Gf(It,ve.title??null,ns),Ds=Qf(ve.title??null),on=await Yf(ws,Ds);if(on){fe.success(e("sessions.sidebar.session.export.success"),{action:{label:e(Eb()),onClick:()=>{Tb(on).then(Ps=>{Ps||fe.error(e("sessions.sidebar.session.export.failedRevealPath"))})}}}),Bt(ds);return}qf(ws,Ds),fe.success(e("sessions.sidebar.session.export.success")),Bt(ds)},[cs,Ke,n.children,ve.title,ie.id,be,Bt,st,e]),Mt=a.useCallback(async()=>{if(n.children.length>0){Ut(!0),Dt(!0);return}await _t(!1)},[_t,n.children.length]),ps=a.useCallback(()=>{be&&Ar("desktop_open_session_mini_chat_window",{sessionId:ie.id,directory:be,apiBaseUrl:Cr(),clientToken:Xi()}).catch(Be=>{console.warn("[session-sidebar] failed to open mini chat window",Be)})},[ie.id,be]);if(a.useEffect(()=>{if(p!==ie.id)return;const Be=It=>{const ds=It.target?.closest?.(`[data-session-rename-form="${CSS.escape(ie.id)}"]`);ee.current&&!ds&&X.current(Se.current)};return document.addEventListener("mousedown",Be),()=>document.removeEventListener("mousedown",Be)},[p,ie.id]),a.useLayoutEffect(()=>{if(p!==ie.id){le.current===ie.id&&(le.current=null);return}le.current!==ie.id&&(le.current=ie.id,Ae(b))},[p,b,ie.id]),p===ie.id)return s.jsx("div",{style:{paddingLeft:iu+r*Ri},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:ee,"data-session-rename-form":ie.id,className:"flex w-full items-center gap-2",onSubmit:Be=>{Be.preventDefault(),g(Ne)},children:[s.jsx("input",{value:Ne,onChange:Be=>Ae(Be.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:Be=>{if(Be.stopPropagation(),Be.key==="Escape"){m();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:m,"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"})})]})})},ie.id);const _s=Qe?.type??"idle",Wt=_s==="busy"||_s==="retry",Fs=Ot.length,Gs=Wt||!Rt&&!Wt&&ct&&!xe,as=Wt?s.jsx(I,{name:"loader-4",className:"h-3 w-3 animate-spin text-primary","aria-label":e("sessions.sidebar.session.status.active")}):s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--status-info)]","aria-label":e("sessions.sidebar.session.status.unread"),title:e("sessions.sidebar.session.status.unread")}),Xs=!J&&Xt&&(Rt||Gs||rt),Gn=rt&&!Rt&&!Gs,qn=s.jsx(I,{name:"pushpin",className:"h-3 w-3 flex-shrink-0 text-primary","aria-label":e("sessions.sidebar.session.status.pinned")}),dn=Rt||Gs||Gn?s.jsx("span",{style:{left:Rl+r*Ri},className:De("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",Xs?"opacity-100 group-hover:opacity-0 group-focus-within:opacity-0":""),children:Rt?s.jsx(I,{name:"loader-4",className:"h-3 w-3 animate-spin text-primary","aria-label":e("sessions.sidebar.session.status.movingToWorktree")}):Gs?as:Gn?qn:null}):null,un=Xt&&!J&&(Rt||Gs||rt),yn=Xt?s.jsx("span",{role:"button",tabIndex:0,onClick:Be=>{Be.stopPropagation(),Be.currentTarget.blur(),y(je)},onKeyDown:Be=>{(Be.key==="Enter"||Be.key===" ")&&(Be.preventDefault(),Be.stopPropagation(),y(je))},style:{minWidth:14,minHeight:14,left:Rl+r*Ri},className:De("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",un?"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(Fe?"sessions.sidebar.session.subsessions.collapse":"sessions.sidebar.session.subsessions.expand"),children:Fe?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,Os=yt?s.jsx(I,{name:"error-warning",className:"h-4 w-4 text-status-warning"}):null,zs=Be=>{Be&&at(!1),O(Be?We:null)},nn=Be=>{if(!Be&&Me.current){const{id:It,title:ns}=Me.current;Me.current=null,x(It),S(ns)}},zn=Be=>{at(Be)},rn=Be=>{Be.preventDefault(),Be.stopPropagation(),O(Xe?null:We)},pr=Be=>{Be.preventDefault(),Be.stopPropagation()},Dn=Be=>{Be.preventDefault(),Be.stopPropagation()},Ir=Be=>{Be.preventDefault(),Be.stopPropagation()},Ss=Be=>{Be.preventDefault(),Be.stopPropagation()},ae=Be=>{Be.preventDefault(),Be.stopPropagation(),O(null),R(ie,{archivedBucket:c})},qe=Be=>{Be.preventDefault(),Be.stopPropagation(),O(null),R(ie,{archivedBucket:c,hardDelete:!0,skipConfirm:!0})},lt=Be=>{Be.preventDefault(),Be.stopPropagation()},gt=Be=>{Be.preventDefault(),Be.stopPropagation()},Gt=Be=>{Be.preventDefault(),Be.stopPropagation(),pe?.vscode?.executeCommand("openchamber.openSessionInEditor",ie.id,Ht)},Et=Be=>{if(ye.current){ye.current=!1;return}if(ut){if(Be?.preventDefault(),Be?.stopPropagation(),Be?.shiftKey){const ns=(typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[]).map(Ds=>Ds.getAttribute("data-session-row")).filter(Ds=>typeof Ds=="string"&&Ds.length>0),ds=hn.getState().anchorId,ws=new Map;ws.set(ie.id,xt(n)),ht(ds,ie.id,ns,Le,ws);return}pt(ie.id,Le,xt(n));return}Be?.currentTarget&&Vk(Be.currentTarget),C(ie.id,be)},St=Be=>{Be.defaultPrevented||Be.target?.closest('button, a, input, [role="menuitem"], [role="menu"]')||Et(Be)},xs=Be=>{(Be.button===2||Be.button===0&&Be.ctrlKey&&!ut)&&(ye.current=!0)},As=Be=>{W&&Be.pointerType==="touch"&&Ee(!0)},ss=Be=>{W&&Be.pointerType==="touch"&&Ee(!1)},ks=({Item:Be,Separator:It,Sub:ns,SubTrigger:ds,SubContent:ws})=>s.jsxs(s.Fragment,{children:[s.jsxs(Be,{onClick:()=>{Me.current={id:ie.id,title:Ht}},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(Be,{onClick:()=>F(ie.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(Be,{onClick:()=>be&&w({directory:be,sessionId:ie.id}),className:"[&>svg]:mr-1",children:[rt?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(rt?"sessions.sidebar.session.menu.unpin":"sessions.sidebar.session.menu.pin")]}),ve.share?s.jsxs(s.Fragment,{children:[s.jsx(Be,{onClick:()=>{ve.share?.url&&P(ve.share.url,ie.id)},className:"[&>svg]:mr-1",children:v===ie.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(Be,{onClick:()=>k(ie.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(Be,{onClick:()=>N(ve),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(Be,{onClick:()=>{Mt()},className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"download",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.exportMarkdown")]}),!Te&&!c&&!G?s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("span",{className:"block",children:s.jsxs(Be,{disabled:!be||Wt||Rt,onClick:()=>{!be||Wt||Rt||Jf({root:ve,descendants:wt(n),sourceDirectory:be,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(At,{side:"right",className:"max-w-72",children:e(Rt?"sessions.sidebar.session.moveToWorktree.tooltipMoving":Wt?"sessions.sidebar.session.moveToWorktree.tooltipBusy":"sessions.sidebar.session.moveToWorktree.tooltip")})]}):null,Pt?s.jsxs(Be,{onClick:()=>Jt(!0),className:"[&>svg]:mr-1",children:[s.jsx(zk,{className:"mr-1 h-4 w-4"}),e("sessions.sidebar.session.menu.runFusion")]}):null,be&&!c?(()=>{const Ds=[],on=vs=>{const zt=Vt(vs??null);zt&&!Ds.includes(zt)&&Ds.push(zt)};if(i&&!G){const vs=ms.getState().projects.find(us=>us.id===i),zt=Vt(vs?.path??null);on(zt),zt&&(et.getState().availableWorktreesByProject.get(zt)??[]).forEach(us=>on(us.path))}on(be);const Ps=Ds.flatMap(vs=>L(vs).map(zt=>({scope:vs,folder:zt}))),fn=Ps.find(({scope:vs,folder:zt})=>_(vs,ie.id)===zt.id)??null,lr=Ds[0]??be;return s.jsxs(s.Fragment,{children:[s.jsx(It,{}),s.jsxs(ns,{children:[s.jsxs(ds,{className:"[&>svg]:mr-1",children:[s.jsx(I,{name:"folder",className:"h-4 w-4"}),e("sessions.sidebar.folders.moveToFolder")]}),s.jsxs(ws,{className:"min-w-[180px]",children:[Ps.length===0?s.jsx(Be,{disabled:!0,className:"text-muted-foreground",children:e("sessions.sidebar.folders.none")}):Ps.map(({scope:vs,folder:zt})=>{const us=fn?.folder.id===zt.id;return s.jsxs(Be,{onClick:()=>{if(us){D(vs,ie.id);return}fn&&fn.scope!==vs&&D(fn.scope,ie.id),A(vs,zt.id,ie.id)},children:[s.jsx("span",{className:"flex-1 truncate",children:zt.name}),us?s.jsx(I,{name:"check",className:"ml-2 h-3.5 w-3.5 text-primary flex-shrink-0"}):null]},zt.id)}),s.jsx(It,{}),s.jsxs(Be,{onClick:()=>{const vs=T(lr);vs&&(fn&&fn.scope!==lr&&D(fn.scope,ie.id),A(lr,vs.id,ie.id))},children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.folders.newFolderEllipsis")]}),fn?s.jsxs(Be,{onClick:()=>{D(fn.scope,ie.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,G?null:s.jsxs(Be,{disabled:!be,onClick:()=>{be&&z(be,{mode:"chat",dedupeKey:`session:${ie.id}`,label:Ht,sessionTitleFallback:Ht})},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")})]}),Ie?s.jsxs(Be,{disabled:!be,onClick:ps,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(It,{}),c?null:s.jsxs(Be,{className:"[&>svg]:mr-1",onClick:()=>R(ie,{archivedBucket:c}),children:[s.jsx(I,{name:"inbox-archive",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.archive")]}),s.jsxs(Be,{className:"text-destructive focus:text-destructive [&>svg]:mr-1",onClick:()=>R(ie,{archivedBucket:c,hardDelete:!0}),children:[s.jsx(I,{name:"delete-bin",className:"mr-1 h-4 w-4"}),e("sessions.sidebar.bulkActions.delete")]})]}),Ls=s.jsx(Ys,{align:"end",className:"min-w-[180px]",finalFocus:()=>!(M||Ue.current),children:ks({Item:is,Separator:Ln,Sub:og,SubTrigger:ig,SubContent:ag})}),Bs=s.jsx(Gc,{children:s.jsx(qc,{className:"app-region-no-drag z-50",children:s.jsx(Yc,{"data-slot":"dropdown-menu-content",finalFocus:()=>!(M||Ue.current),style:{backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)"},className:De(Lc,"min-w-[180px]"),children:ks({Item:({className:Be,...It})=>s.jsx(Xx,{className:De(sg,Be),...It}),Separator:({className:Be,...It})=>s.jsx(Jx,{className:De(ng,Be),...It}),Sub:Zx,SubTrigger:({className:Be,children:It,...ns})=>s.jsxs(eb,{className:De(rg,Be),...ns,children:[It,s.jsx(I,{name:"arrow-right-s",className:"ml-auto size-3.5"})]}),SubContent:({className:Be,children:It,...ns})=>s.jsx(Gc,{children:s.jsx(qc,{className:"app-region-no-drag z-50",children:s.jsx(Yc,{"data-slot":"dropdown-menu-sub-content",style:{backgroundColor:"var(--surface-elevated)",color:"var(--surface-elevated-foreground)"},className:De(Lc,Be),...ns,children:It})})})})})})});return s.jsxs(a.Fragment,{children:[s.jsx(NS,{sessionId:ie.id,sessionDirectory:be??null,sessionTitle:Ht,children:s.jsxs(Yx,{open:tt,onOpenChange:zn,onOpenChangeComplete:nn,children:[s.jsxs(Qx,{render:s.jsx("div",{"data-session-row":ie.id,"data-session-scope":Le??"","data-session-archived":c?"1":"0",onClick:St,style:{paddingLeft:iu+r*Ri},className:De("group relative my-0.5 flex cursor-pointer items-center rounded-md py-1 pr-1.5",xe&&!mt&&"bg-primary/10",mt&&"bg-interactive-selection")}),children:[dn,yn,s.jsx("div",{className:"flex min-w-0 flex-1 items-center",children:s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onPointerDown:As,onPointerUp:ss,onPointerCancel:ss,onMouseDown:xs,onClick:Be=>Et(Be),onDoubleClick:Be=>{Be.stopPropagation(),j(ie.id,Ht)},className:De("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]",he&&"bg-interactive-hover/70",J?G?ce:ke:ce),children:s.jsxs("div",{className:"flex w-full items-center min-w-0 flex-1 gap-1 overflow-hidden",children:[s.jsx("div",{className:De("block min-w-0 flex-1 truncate typography-ui-label font-normal",xe?"text-primary":ct?"text-foreground":"text-foreground/80"),children:$i(Ht,h)}),J?s.jsxs("span",{className:"ml-2 inline-flex flex-shrink-0 items-center gap-1 text-[0.72rem] text-muted-foreground/75",children:[Ft,$?s.jsx(I,{name:"git-branch",className:De("h-3 w-3",!me&&"text-muted-foreground/60"),style:me?{color:me}:void 0}):null,ze]}):Ft||$?s.jsx("div",{className:"relative ml-1 flex h-4 flex-shrink-0 items-center justify-end",children:s.jsxs("span",{className:De("inline-flex items-center gap-1 whitespace-nowrap text-right transition-opacity duration-150",Ze?"opacity-0":Q),children:[Ft,$?s.jsx(I,{name:"git-branch",className:De("h-3 w-3",!me&&"text-muted-foreground/60"),style:me?{color:me}:void 0}):null]})}):null,Fs>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:Fs})]}):null]})})}),G?null:s.jsx(At,{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:Ht}),s.jsx("span",{className:"flex-shrink-0 text-muted-foreground",title:Lt,children:ze})]}),de?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:de})]}):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:me?{color:me}:void 0}),s.jsx("span",{className:"min-w-0 truncate",children:_e})]}):null,re&&B?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:me?{color:me}:void 0}),s.jsxs("span",{className:"min-w-0 truncate",style:me?{color:me}:void 0,children:["#",re.number," · ",B]})]}):null]})})]})}),Os&&!W?s.jsx("div",{className:"absolute right-0 top-1/2 -translate-y-1/2 z-10",children:Os}):null,s.jsxs("div",{className:De("absolute right-0 top-1/2 z-10 flex -translate-y-1/2 items-center gap-0.5 transition-opacity",Ze||J&&!G?"opacity-100":De("opacity-0",V)),children:[oe?s.jsx(Wk,{archiveLabel:e("sessions.sidebar.bulkActions.archive"),deleteLabel:e("sessions.sidebar.bulkActions.delete"),buttonSizeClass:J?"h-6 w-6":"h-4 w-4",iconSizeClass:J?"h-3.5 w-3.5":"h-2.5 w-2.5",onPointerDown:Ir,onMouseDown:Ss,onArchive:ae,onDelete:qe}):null,ne?s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",className:De("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",J?"h-6 w-6":"h-4 w-4"),"aria-label":e("sessions.sidebar.session.actions.openInEditor"),onPointerDown:lt,onMouseDown:gt,onClick:Gt,onKeyDown:Be=>Be.stopPropagation(),children:s.jsx(I,{name:"external-link",className:De(J?"h-3.5 w-3.5":"h-2.5 w-2.5")})})}),s.jsx(At,{side:"left",sideOffset:8,children:e("sessions.sidebar.session.actions.openInEditor")})]}):null,s.jsxs(Qs,{open:Xe,onOpenChange:zs,onOpenChangeComplete:nn,children:[s.jsx(qs,{asChild:!0,children:s.jsx("button",{type:"button",className:De("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",J?"h-6 w-6 opacity-100":Ze?"h-4 w-4 opacity-100":De("h-4 w-4 opacity-0",V)),"aria-label":e("sessions.sidebar.session.menu.label"),onPointerDown:pr,onMouseDown:Dn,onClick:rn,onKeyDown:Be=>Be.stopPropagation(),children:s.jsx(I,{name:"more-2",className:De(J?"h-3.5 w-3.5":"h-2.5 w-2.5")})})}),Ls]})]})]}),Bs]})}),Xt&&Fe?n.children.map(Be=>{const It=se?se(Be):{subtreeContainsEditing:ue,menuOpenSessionId:Oe,nodeStructureKey:""};return U(Be,r+1,be??o,i,c,void 0,Z,It)}):null,s.jsx(Ts,{open:bt,onOpenChange:Dt,children:s.jsxs(Es,{showCloseButton:!1,className:"max-w-sm gap-5",children:[s.jsxs(Hs,{children:[s.jsx($s,{children:e("sessions.sidebar.session.export.dialog.title")}),s.jsx(Ks,{children:ls===1?e("sessions.sidebar.session.export.dialog.descriptionSingle",{count:ls}):e("sessions.sidebar.session.export.dialog.descriptionMany",{count:ls})})]}),s.jsxs("label",{className:"flex items-center gap-2 typography-ui-label cursor-pointer",children:[s.jsx("input",{type:"checkbox",checked:qt,onChange:Be=>Ut(Be.target.checked),className:"h-4 w-4 rounded border-border accent-primary"}),e("sessions.sidebar.session.export.dialog.includeSubtasks")]}),s.jsxs(ar,{children:[s.jsx(He,{type:"button",onClick:()=>Dt(!1),variant:"outline",size:"sm",children:e("sessions.sidebar.dialogs.cancel")}),s.jsx(He,{type:"button",onClick:()=>{Dt(!1),_t(qt)},size:"sm",children:e("sessions.sidebar.session.export.dialog.confirm")})]})]})}),Pt?s.jsx(_k,{session:ve,open:Tt,onOpenChange:Jt}):null]},ie.id)}const au=t=>Vt(t.session.directory??null),Hk=(t,e)=>(t?.projectLabel??null)===(e?.projectLabel??null)&&(t?.branchLabel??null)===(e?.branchLabel??null),Kk=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},Mi=t=>t.menuOpenSessionId??Kk(t),Ti=(t,e,n)=>e?n.has(t.node.session.id)?!0:Sr(t.node,e):!1,Ml=(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(Ml(t.children[c],e.children[c],n,r,o))return!0;return!1},Gk=(t,e)=>{if(t.hasSessionSearchQuery||e.hasSessionSearchQuery)return!1;const n=t.archivedBucket?"archived":"active",r=e.archivedBucket?"archived":"active";return Ml(t.node,e.node,t.expandedParents,e.expandedParents,o=>`${t.renderContext??"project"}:${n}:${o.session.id}`)||Ml(t.node,e.node,t.expandedParents,e.expandedParents,o=>`${e.renderContext??"project"}:${r}:${o.session.id}`)},qk=(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||au(t.node)!==au(e.node)||!Hk(t.secondaryMeta,e.secondaryMeta)||t.pinnedSessionIds!==e.pinnedSessionIds&&Mm(t.node,e.node,t.pinnedSessionIds,e.pinnedSessionIds,t.groupDirectory,e.groupDirectory)||t.expandedParents!==e.expandedParents&&Gk(t,e)||t.editingId!==e.editingId&&(Ti(t,t.editingId,t.subtreeContainsEditing)||Ti(e,e.editingId,e.subtreeContainsEditing))||t.editTitle!==e.editTitle&&(Ti(t,t.editingId,t.subtreeContainsEditing)||Ti(e,e.editingId,e.subtreeContainsEditing))||t.copiedSessionId!==e.copiedSessionId&&(Sr(t.node,t.copiedSessionId)||Sr(e.node,e.copiedSessionId)))return!1;if(t.openSidebarMenuKey!==e.openSidebarMenuKey){const n=Mi(t),r=Mi(e);if(Sr(t.node,n)||Sr(e.node,r))return!1}if(t.renamingFolderId!==e.renamingFolderId){const n=Mi(t),r=Mi(e);if(Sr(t.node,n)||Sr(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.renderSessionNode===e.renderSessionNode},Yk=a.memo(Uk,qk);function Qk(t){return t.stopPropagation()}function Xk(t){const e=nt.c(71),{t:n}=ft(),{value:r,setValue:o,showDeletionDialog:i,setShowDeletionDialog:c,onConfirm:l}=t;let d,u,h,f,p,x,b,S,g,m;if(e[0]!==o||e[1]!==n||e[2]!==r){const z=n("sessions.sidebar.session.untitled");f=Ts,g=!!r,e[13]!==o?(m=W=>{W||o(null)},e[13]=o,e[14]=m):m=e[14],h=Es,b=!1,S="max-w-sm gap-5",u=Hs;let R;e[15]!==n||e[16]!==r?.archivedBucket?(R=r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.title"):n("sessions.sidebar.dialogs.archiveSession.title"),e[15]=n,e[16]=r?.archivedBucket,e[17]=R):R=e[17],e[18]!==R?(x=s.jsx($s,{children:R}),e[18]=R,e[19]=x):x=e[19],d=Ks,p=r&&r.descendantCount>0?r.archivedBucket?r.descendantCount===1?n("sessions.sidebar.dialogs.deleteSession.withOneSubtask",{sessionTitle:r.session.title||z,count:r.descendantCount}):n("sessions.sidebar.dialogs.deleteSession.withManySubtasks",{sessionTitle:r.session.title||z,count:r.descendantCount}):r.descendantCount===1?n("sessions.sidebar.dialogs.archiveSession.withOneSubtask",{sessionTitle:r.session.title||z,count:r.descendantCount}):n("sessions.sidebar.dialogs.archiveSession.withManySubtasks",{sessionTitle:r.session.title||z,count:r.descendantCount}):r?.archivedBucket?n("sessions.sidebar.dialogs.deleteSession.single",{sessionTitle:r?.session.title||z}):n("sessions.sidebar.dialogs.archiveSession.single",{sessionTitle:r?.session.title||z}),e[0]=o,e[1]=n,e[2]=r,e[3]=d,e[4]=u,e[5]=h,e[6]=f,e[7]=p,e[8]=x,e[9]=b,e[10]=S,e[11]=g,e[12]=m}else d=e[3],u=e[4],h=e[5],f=e[6],p=e[7],x=e[8],b=e[9],S=e[10],g=e[11],m=e[12];let y;e[20]!==d||e[21]!==p?(y=s.jsx(d,{children:p}),e[20]=d,e[21]=p,e[22]=y):y=e[22];let C;e[23]!==u||e[24]!==x||e[25]!==y?(C=s.jsxs(u,{children:[x,y]}),e[23]=u,e[24]=x,e[25]=y,e[26]=C):C=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 w=!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 v;e[32]!==n?(v=n("sessions.sidebar.dialogs.neverAsk"),e[32]=n,e[33]=v):v=e[33];let P;e[34]!==N||e[35]!==v||e[36]!==j||e[37]!==w?(P=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":w,children:[N,v]}),e[34]=N,e[35]=v,e[36]=j,e[37]=w,e[38]=P):P=e[38];let F;e[39]!==o?(F=()=>o(null),e[39]=o,e[40]=F):F=e[40];let k;e[41]!==n?(k=n("sessions.sidebar.dialogs.cancel"),e[41]=n,e[42]=k):k=e[42];let E;e[43]!==F||e[44]!==k?(E=s.jsx("button",{type:"button",onClick:F,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[43]=F,e[44]=k,e[45]=E):E=e[45];let O;e[46]!==l?(O=()=>{l()},e[46]=l,e[47]=O):O=e[47];let M;e[48]!==n||e[49]!==r?.archivedBucket?(M=r?.archivedBucket?n("sessions.sidebar.bulkActions.delete"):n("sessions.sidebar.bulkActions.archive"),e[48]=n,e[49]=r?.archivedBucket,e[50]=M):M=e[50];let L;e[51]!==O||e[52]!==M?(L=s.jsx("button",{type:"button",onClick:O,className:"inline-flex h-8 items-center justify-center rounded-md bg-destructive px-3 typography-ui-label text-destructive-foreground hover:bg-destructive/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive/50",children:M}),e[51]=O,e[52]=M,e[53]=L):L=e[53];let _;e[54]!==E||e[55]!==L?(_=s.jsxs("div",{className:"flex items-center gap-2",children:[E,L]}),e[54]=E,e[55]=L,e[56]=_):_=e[56];let D;e[57]!==P||e[58]!==_?(D=s.jsxs(ar,{className:"w-full sm:items-center sm:justify-between",children:[P,_]}),e[57]=P,e[58]=_,e[59]=D):D=e[59];let A;e[60]!==h||e[61]!==b||e[62]!==D||e[63]!==S||e[64]!==C?(A=s.jsxs(h,{showCloseButton:b,className:S,children:[C,D]}),e[60]=h,e[61]=b,e[62]=D,e[63]=S,e[64]=C,e[65]=A):A=e[65];let T;return e[66]!==f||e[67]!==A||e[68]!==g||e[69]!==m?(T=s.jsx(f,{open:g,onOpenChange:m,children:A}),e[66]=f,e[67]=A,e[68]=g,e[69]=m,e[70]=T):T=e[70],T}function Jk(t){const e=nt.c(57),{t:n}=ft(),{value:r,setValue:o,showDeletionDialog:i,setShowDeletionDialog:c,onConfirm:l}=t,d=r?.archivedBucket===!0,u=r?.sessionCount??0;let h;e[0]!==d||e[1]!==u||e[2]!==n?(h=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]=h):h=e[3];const f=h;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 x=p,b=!!r;let S;e[8]!==o?(S=T=>{T||o(null)},e[8]=o,e[9]=S):S=e[9];let g;e[10]!==f?(g=s.jsx($s,{children:f}),e[10]=f,e[11]=g):g=e[11];let m;e[12]!==x?(m=s.jsx(Ks,{children:x}),e[12]=x,e[13]=m):m=e[13];let y;e[14]!==g||e[15]!==m?(y=s.jsxs(Hs,{children:[g,m]}),e[14]=g,e[15]=m,e[16]=y):y=e[16];let C;e[17]!==c||e[18]!==i?(C=()=>c(!i),e[17]=c,e[18]=i,e[19]=C):C=e[19];const j=!i;let w;e[20]!==i?(w=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]=w):w=e[21];let N;e[22]!==n?(N=n("sessions.sidebar.dialogs.neverAsk"),e[22]=n,e[23]=N):N=e[23];let v;e[24]!==N||e[25]!==C||e[26]!==j||e[27]!==w?(v=s.jsxs("button",{type:"button",onClick:C,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:[w,N]}),e[24]=N,e[25]=C,e[26]=j,e[27]=w,e[28]=v):v=e[28];let P;e[29]!==o?(P=()=>o(null),e[29]=o,e[30]=P):P=e[30];let F;e[31]!==n?(F=n("sessions.sidebar.dialogs.cancel"),e[31]=n,e[32]=F):F=e[32];let k;e[33]!==P||e[34]!==F?(k=s.jsx("button",{type:"button",onClick:P,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:F}),e[33]=P,e[34]=F,e[35]=k):k=e[35];let E;e[36]!==l?(E=()=>{l()},e[36]=l,e[37]=E):E=e[37];let O;e[38]!==d||e[39]!==n?(O=n(d?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[38]=d,e[39]=n,e[40]=O):O=e[40];let M;e[41]!==E||e[42]!==O?(M=s.jsx("button",{type:"button",onClick:E,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:O}),e[41]=E,e[42]=O,e[43]=M):M=e[43];let L;e[44]!==k||e[45]!==M?(L=s.jsxs("div",{className:"flex items-center gap-2",children:[k,M]}),e[44]=k,e[45]=M,e[46]=L):L=e[46];let _;e[47]!==v||e[48]!==L?(_=s.jsxs(ar,{className:"w-full sm:items-center sm:justify-between",children:[v,L]}),e[47]=v,e[48]=L,e[49]=_):_=e[49];let D;e[50]!==_||e[51]!==y?(D=s.jsxs(Es,{showCloseButton:!1,className:"max-w-sm gap-5",children:[y,_]}),e[50]=_,e[51]=y,e[52]=D):D=e[52];let A;return e[53]!==b||e[54]!==D||e[55]!==S?(A=s.jsx(Ts,{open:b,onOpenChange:S,children:D}),e[53]=b,e[54]=D,e[55]=S,e[56]=A):A=e[56],A}function Zk(t){const e=nt.c(36),{t:n}=ft(),{value:r,setValue:o,onConfirm:i}=t,c=!!r;let l;e[0]!==o?(l=w=>{w||o(null)},e[0]=o,e[1]=l):l=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($s,{children:d}),e[4]=d,e[5]=u):u=e[5];let h;e[6]!==n||e[7]!==r?(h=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]=h):h=e[8];let f;e[9]!==h?(f=s.jsx(Ks,{children:h}),e[9]=h,e[10]=f):f=e[10];let p;e[11]!==u||e[12]!==f?(p=s.jsxs(Hs,{children:[u,f]}),e[11]=u,e[12]=f,e[13]=p):p=e[13];let x;e[14]!==o?(x=()=>o(null),e[14]=o,e[15]=x):x=e[15];let b;e[16]!==n?(b=n("sessions.sidebar.dialogs.cancel"),e[16]=n,e[17]=b):b=e[17];let S;e[18]!==x||e[19]!==b?(S=s.jsx("button",{type:"button",onClick:x,className:"inline-flex h-8 items-center justify-center rounded-md border border-border px-3 typography-ui-label text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:b}),e[18]=x,e[19]=b,e[20]=S):S=e[20];let g;e[21]!==n?(g=n("sessions.sidebar.bulkActions.delete"),e[21]=n,e[22]=g):g=e[22];let m;e[23]!==i||e[24]!==g?(m=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]=m):m=e[25];let y;e[26]!==m||e[27]!==S?(y=s.jsxs(ar,{children:[S,m]}),e[26]=m,e[27]=S,e[28]=y):y=e[28];let C;e[29]!==y||e[30]!==p?(C=s.jsxs(Es,{showCloseButton:!1,className:"max-w-sm gap-5",children:[p,y]}),e[29]=y,e[30]=p,e[31]=C):C=e[31];let j;return e[32]!==c||e[33]!==l||e[34]!==C?(j=s.jsx(Ts,{open:c,onOpenChange:l,children:C}),e[32]=c,e[33]=l,e[34]=C,e[35]=j):j=e[35],j}const e2=t=>{const e=nt.c(46),{selectedCount:n,scopeKey:r,scopeFolders:o,archivedBucket:i,onMoveToFolder:c,onCreateFolderAndMove:l,onRemoveFromFolder:d,canRemoveFromFolder:u,onDelete:h,onDone:f}=t,{t:p}=ft(),x=!!r&&!i;let b;e[0]!==i||e[1]!==p?(b=p(i?"sessions.sidebar.bulkActions.delete":"sessions.sidebar.bulkActions.archive"),e[0]=i,e[1]=p,e[2]=b):b=e[2];const S=b;let g;e[3]!==n||e[4]!==p?(g=p("sessions.sidebar.bulkActions.selectedCount",{count:n}),e[3]=n,e[4]=p,e[5]=g):g=e[5];let m;e[6]!==g?(m=s.jsx("span",{className:"typography-ui-label text-muted-foreground whitespace-nowrap",children:g}),e[6]=g,e[7]=m):m=e[7];let y;e[8]!==x||e[9]!==u||e[10]!==l||e[11]!==c||e[12]!==d||e[13]!==o||e[14]!==p?(y=x?s.jsxs(Qs,{children:[s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(qs,{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":p("sessions.sidebar.bulkActions.moveToFolder"),children:s.jsx(I,{name:"folder",className:"h-4 w-4"})})})}),s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:p("sessions.sidebar.bulkActions.moveToFolder")})})]}),s.jsxs(Ys,{align:"end",className:"min-w-[180px]",children:[o.length===0?s.jsx(is,{disabled:!0,className:"text-muted-foreground",children:p("sessions.sidebar.folders.none")}):o.map(D=>s.jsx(is,{onClick:()=>c(D.id),children:s.jsx("span",{className:"flex-1 truncate",children:D.name})},D.id)),s.jsx(Ln,{}),s.jsxs(is,{onClick:l,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"}),p("sessions.sidebar.folders.newFolderEllipsis")]}),u?s.jsxs(is,{onClick:d,className:"text-destructive focus:text-destructive",children:[s.jsx(I,{name:"close",className:"mr-1 h-4 w-4"}),p("sessions.sidebar.folders.removeFromFolder")]}):null]})]}):null,e[8]=x,e[9]=u,e[10]=l,e[11]=c,e[12]=d,e[13]=o,e[14]=p,e[15]=y):y=e[15];let C;e[16]===Symbol.for("react.memo_cache_sentinel")?(C=De("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[16]=C):C=e[16];let j;e[17]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(I,{name:"delete-bin",className:"h-4 w-4"}),e[17]=j):j=e[17];let w;e[18]!==S||e[19]!==h?(w=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:h,className:C,"aria-label":S,children:j})}),e[18]=S,e[19]=h,e[20]=w):w=e[20];let N;e[21]!==S?(N=s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:S})}),e[21]=S,e[22]=N):N=e[22];let v;e[23]!==w||e[24]!==N?(v=s.jsxs(Nt,{children:[w,N]}),e[23]=w,e[24]=N,e[25]=v):v=e[25];let P;e[26]!==p?(P=p("sessions.sidebar.header.actions.exitSelection"),e[26]=p,e[27]=P):P=e[27];let F;e[28]===Symbol.for("react.memo_cache_sentinel")?(F=s.jsx(I,{name:"close",className:"h-4 w-4"}),e[28]=F):F=e[28];let k;e[29]!==f||e[30]!==P?(k=s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:f,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:F})}),e[29]=f,e[30]=P,e[31]=k):k=e[31];let E;e[32]!==p?(E=p("sessions.sidebar.header.actions.exitSelection"),e[32]=p,e[33]=E):E=e[33];let O;e[34]!==E?(O=s.jsx(At,{side:"top",sideOffset:4,children:s.jsx("p",{children:E})}),e[34]=E,e[35]=O):O=e[35];let M;e[36]!==k||e[37]!==O?(M=s.jsxs(Nt,{children:[k,O]}),e[36]=k,e[37]=O,e[38]=M):M=e[38];let L;e[39]!==M||e[40]!==y||e[41]!==v?(L=s.jsxs("div",{className:"ml-auto flex items-center gap-0.5",children:[y,v,M]}),e[39]=M,e[40]=y,e[41]=v,e[42]=L):L=e[42];let _;return e[43]!==L||e[44]!==m?(_=s.jsxs("div",{className:"flex shrink-0 items-center gap-1 border-t border-border px-2.5 py-1.5",children:[m,L]}),e[43]=L,e[44]=m,e[45]=_):_=e[45],_},t2=t=>{const{t:e}=ft(),{isInlineEditing:n,showDeletionDialog:r,foldersMap:o,folderScopesByProject:i,addSessionsToFolder:c,removeSessionsFromFolders:l,createFolderAndStartRename:d,archiveSessions:u,deleteSessions:h,setBulkDeleteConfirm:f}=t,p=hn(D=>D.enabled),x=hn(D=>D.selectedIds.size),b=x>0,S=hn(D=>D.selectedIds),g=hn(D=>D.scopeKey),m=a.useCallback(()=>{hn.getState().toggleMode()},[]),y=a.useCallback(()=>{hn.getState().disable()},[]),C=a.useMemo(()=>{if(!b||typeof document>"u")return!1;let D=!1,A=!1;for(const T of S){const z=document.querySelectorAll(`[data-session-row="${CSS.escape(T)}"]`);for(const R of z)R.getAttribute("data-session-archived")==="1"?A=!0:D=!0}return A&&!D},[b,S]),j=a.useMemo(()=>{if(g)return g;if(!b||typeof document>"u")return null;for(const D of S){const T=document.querySelector(`[data-session-row="${CSS.escape(D)}"]`)?.getAttribute("data-session-scope");if(T&&T.length>0)return T}return null},[b,S,g]),w=a.useMemo(()=>{if(!j)return[];const D=i.get(j);return D&&D.length>0?D.map(A=>A.scopeKey):[j]},[j,i]),N=a.useMemo(()=>w.flatMap(D=>o[D]??[]),[o,w]),v=a.useCallback(D=>{for(const A of w)if((o[A]??[]).some(T=>T.id===D))return A;return null},[o,w]),P=a.useMemo(()=>{if(!b)return!1;for(const D of w)for(const A of o[D]??[])for(const T of A.sessionIds)if(S.has(T))return!0;return!1},[o,w,b,S]),F=a.useCallback((D,A)=>{const T=Array.from(S);for(const z of w)z!==D&&l(z,T);c(D,A,T)},[c,l,S,w]),k=a.useCallback(D=>{if(!b)return;const A=v(D);A&&F(A,D)},[b,F,v]),E=a.useCallback(()=>{const D=w[0];if(!D||!b)return;const A=d(D);A&&F(D,A.id)},[d,b,F,w]),O=a.useCallback(()=>{if(!b)return;const D=Array.from(S);for(const A of w)l(A,D)},[l,S,w,b]),M=a.useCallback(async()=>{const D=Array.from(S);if(D.length!==0){if(C){const{deletedIds:A,failedIds:T}=await h(D);A.length>0&&fe.success(A.length===1?e("sessions.sidebar.bulkActions.deletedSingle",{count:A.length}):e("sessions.sidebar.bulkActions.deletedPlural",{count:A.length})),T.length>0&&fe.error(T.length===1?e("sessions.sidebar.bulkActions.failedDeleteSingle",{count:T.length}):e("sessions.sidebar.bulkActions.failedDeletePlural",{count:T.length}))}else{const{archivedIds:A,failedIds:T}=await u(D);A.length>0&&fe.success(A.length===1?e("sessions.sidebar.bulkActions.archivedSingle",{count:A.length}):e("sessions.sidebar.bulkActions.archivedPlural",{count:A.length})),T.length>0&&fe.error(T.length===1?e("sessions.sidebar.bulkActions.failedArchiveSingle",{count:T.length}):e("sessions.sidebar.bulkActions.failedArchivePlural",{count:T.length}))}hn.getState().clear()}},[u,C,h,S,e]),L=a.useCallback(()=>{if(!b)return;const D=S.size;if(!r){M();return}f({sessionCount:D,archivedBucket:C})},[C,M,S,r,f,b]),_=a.useCallback(async()=>{f(null),await M()},[M]);return a.useEffect(()=>{if(!p)return;const D=typeof navigator<"u"&&/Macintosh|Mac OS X/.test(navigator.userAgent||""),A=T=>{if(n)return;const z=T.target;if(z&&(z.tagName==="INPUT"||z.tagName==="TEXTAREA"||z.isContentEditable))return;const R=D?T.metaKey:T.ctrlKey;if(T.key==="Escape"){T.preventDefault(),hn.getState().disable();return}if(R&&T.key==="Backspace"){T.preventDefault(),L();return}if(R&&(T.key==="a"||T.key==="A")){const W=typeof document<"u"?Array.from(document.querySelectorAll("[data-session-row]")):[];if(W.length===0)return;T.preventDefault();const U=hn.getState().scopeKey??W[0]?.getAttribute("data-session-scope")??null,te=ue=>U?ue.getAttribute("data-session-scope")===U:!0,Z=W.filter(te).map(ue=>ue.getAttribute("data-session-row")).filter(ue=>typeof ue=="string"&&ue.length>0);if(Z.length===0)return;hn.getState().replaceAll(Z,U||null)}};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[L,n,p]),{selectionModeEnabled:p,hasSelection:b,selectedIdsSize:x,bulkScopeIsArchived:C,derivedSelectionScope:j,bulkScopeFolders:N,bulkCanRemoveFromFolder:P,handleToggleSelectionMode:m,handleExitSelectionMode:y,handleBulkMoveToFolder:k,handleBulkCreateFolderAndMove:E,handleBulkRemoveFromFolder:O,handleBulkDelete:L,confirmBulkDelete:_}},s2=2880*60*1e3,n2=t=>!!t.parentID,r2=t=>!!t.time?.archived,o2=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},i2=(t,e,n=Date.now())=>{const r=n-s2;return t.filter(o=>r2(o)||n2(o)?!1:e.has(o.id)||o2(o)>=r)};let Do=null,Po=null,Ki=null,mi=0,da=null;const zr=new Set,a2=3e4,l2=45e3,Bm=()=>{Ki&&(clearTimeout(Ki),Ki=null)},$m=()=>{if(Po||zr.size===0)return;const t=Math.min(1e3*Math.pow(2,Math.min(mi,5)),a2);Po=setTimeout(()=>{Po=null,mi+=1,xc()},t)},hi=()=>{Bm(),Do&&Do.close(),Do=null},lu=()=>{Bm(),zr.size!==0&&(Ki=setTimeout(()=>{hi(),$m()},l2))},c2=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}},cu=t=>!t||typeof t!="object"?null:t,d2=t=>{if(t.type==="openchamber:event-stream-ready"){mi=0;return}if(t.type==="openchamber:heartbeat")return;if(t.type==="openchamber:session-created"){const d=cu(t.properties),u=typeof d?.sessionId=="string"?d.sessionId:"",h=typeof d?.directory=="string"?d.directory:"";if(!u||!h)return;const f={type:"session-created",sessionId:u,directory:h,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 zr)p(f);return}if(t.type!=="openchamber:scheduled-task-ran")return;const e=cu(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 l={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 zr)d(l)},xc=()=>{if(typeof window>"u"||zr.size===0||typeof EventSource!="function"||Do&&Do.readyState!==EventSource.CLOSED)return;hi();const t=new EventSource(ha().sse("/api/openchamber/events"));t.onopen=()=>{lu()},t.onmessage=e=>{lu();const n=c2(e.data);n&&d2(n)},t.onerror=()=>{hi(),$m()},Do=t},u2=()=>{da||typeof window>"u"||(da=Yu(()=>{hi(),mi=0,xc()}))},f2=()=>{da?.(),da=null},_m=t=>(zr.add(t),u2(),xc(),()=>{zr.delete(t),zr.size===0&&(Po&&(clearTimeout(Po),Po=null),mi=0,hi(),f2())}),du={selected:0,"active-project":1,expanded:2,visible:3,background:4};function m2(t){const e=new Map,n=(r,o,i)=>{const c=Vt(r??null);if(!c)return;const l=e.get(c);l&&du[l.priority]<=du[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 l=o&&!t.collapsedGroups.has(`${r.project.id}:${c.id}`);let d="background";l?d="expanded":o&&(d="visible"),n(c.directory,d,l?"worktree-expanded":"known-worktree")}}return n(t.currentDirectory,"selected","current-directory"),n(t.currentSessionDirectory,"selected","selected-session"),[...e.values()]}const Ei="oc.sessions.projectCollapse",uu="oc.sessions.groupOrder",fu="oc.sessions.groupCollapse",mu="oc.sessions.activeSessionByProject",hu="oc.sessions.expandedParents.v3",h2=(t,e,n)=>{const r=new Set;for(const o of t){const i=Vt(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=Vt(i.path)?.toLowerCase();c&&r.add(c)}return r},p2=(t,e,n)=>{if(t.time?.archived)return!0;const r=Vt(Bn(t))?.toLowerCase();return r?e.size===0?n?.allowEmptyDirectorySet??!0:e.has(r):n?.allowUnknownDirectory??!0},g2=5*6e4,x2=new Set,ol=[],er=t=>{const e=a.useRef(t);return e.current=t,a.useCallback((...n)=>e.current(...n),[])},b2=t=>{const e=nt.c(14),{owner:n,childStores:r,projectSections:o,activeProjectId:i,collapsedProjects:c,collapsedGroups:l,currentDirectory:d}=t,u=et(v2);let h,f;e[0]!==i||e[1]!==r||e[2]!==l||e[3]!==c||e[4]!==d||e[5]!==u||e[6]!==n||e[7]!==o?(h=()=>{r.setBootstrapDemand(n,m2({projectSections:o,activeProjectId:i,collapsedProjects:c,collapsedGroups:l,currentDirectory:d,currentSessionDirectory:u}))},f=[i,r,l,c,d,u,n,o],e[0]=i,e[1]=r,e[2]=l,e[3]=c,e[4]=d,e[5]=u,e[6]=n,e[7]=o,e[8]=h,e[9]=f):(h=e[8],f=e[9]),a.useEffect(h,f);let p,x;return e[10]!==r||e[11]!==n?(p=()=>()=>r.clearBootstrapDemand(n),x=[r,n],e[10]=r,e[11]=n,e[12]=p,e[13]=x):(p=e[12],x=e[13]),a.useEffect(p,x),null},y2=t=>{const e=nt.c(17),{directories:n}=t,{t:r}=ft();let o;e[0]!==n?(o=new Set,n.forEach(h=>{const f=Vt(h)?.toLowerCase();f&&o.add(f)}),e[0]=n,e[1]=o):o=e[1];const i=o;let c;e[2]!==i?(c=h=>{for(const f of h.statusById.values()){if(f.status.type!=="busy"&&f.status.type!=="retry")continue;const p=Vt(f.directory)?.toLowerCase();if(p&&i.has(p))return!0}return!1},e[2]=i,e[3]=c):c=e[3];const l=Ca(c);let d;e[4]!==i?(d=h=>{for(const[f,p]of Object.entries(h.index.project.unseenCount)){if(!p)continue;const x=Vt(f)?.toLowerCase();if(x&&i.has(x))return!0}return!1},e[4]=i,e[5]=d):d=e[5];const u=Aa(d);if(l){let h;e[6]!==r?(h=r("sessions.sidebar.session.status.active"),e[6]=r,e[7]=h):h=e[7];let f;return e[8]!==h?(f=s.jsx(I,{name:"loader-4",className:"h-3 w-3 animate-spin text-primary","aria-label":h}),e[8]=h,e[9]=f):f=e[9],f}if(u){let h;e[10]!==r?(h=r("sessions.sidebar.session.status.unread"),e[10]=r,e[11]=h):h=e[11];let f;e[12]!==r?(f=r("sessions.sidebar.session.status.unread"),e[12]=r,e[13]=f):f=e[13];let p;return e[14]!==h||e[15]!==f?(p=s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[var(--status-info)]","aria-label":h,title:f}),e[14]=h,e[15]=f,e[16]=p):p=e[16],p}return null},w2=({isVisible:t=!0,mobileVariant:e=!1,onSessionSelected:n,allowReselect:r=!1,hideDirectoryControls:o=!1,showOnlyMainWorkspace:i=!1})=>{dl("react.session_sidebar_render"),sr("ui.session_sidebar.render"),sr(`ui.session_sidebar.render.${e?"mobile":"desktop"}`),sr(`ui.session_sidebar.render.${t?"visible":"hidden"}`);const{t:c}=ft(),[l,d]=a.useState(!1),[u,h]=a.useState(""),f=a.useRef(null),p=a.useRef(null),[x,b]=a.useState(null),[S,g]=a.useState(""),[m,y]=a.useState(null),[C,j]=a.useState(new Set),w=a.useMemo(()=>yo(),[]),[N,v]=a.useState(new Set),[P,F]=a.useState(new Map),[k,E]=a.useState(new Map),O=Re(Y=>Y.isNewWorktreeDialogOpen),M=Re(Y=>Y.setNewWorktreeDialogOpen),[L,_]=a.useState(!1),[D,A]=a.useState(null),[T,z]=a.useState(null),[R,W]=a.useState(""),[J,U]=a.useState(null),[te,Z]=a.useState(null),[ue,Oe]=a.useState(null),se=di(Y=>Y.ids),G=Na(a.useCallback(Y=>t?Y.rankById:ql,[t])),Ie=Ca(nr(Y=>t?[...Y.statusById.keys()].sort():ol)),pe=a.useMemo(()=>new Set(Ie),[Ie]),V=Aa(nr(Y=>t?Object.entries(Y.index.session.unseenCount).filter(([,Je])=>Je>0).map(([Je])=>Je).sort():ol)),Q=a.useMemo(()=>new Set(V),[V]),ne=di(Y=>Y.toggle),[oe,ce]=a.useState(()=>{try{const Y=yo().getItem(fu);if(!Y)return new Set;const Je=JSON.parse(Y);return new Set(Array.isArray(Je)?Je.filter(Ye=>typeof Ye=="string"):[])}catch{return new Set}}),[ke,ye]=a.useState(()=>{try{const Y=yo().getItem(uu);if(!Y)return new Map;const Je=JSON.parse(Y),Ye=new Map;return Object.entries(Je).forEach(([vt,Qt])=>{Array.isArray(Qt)&&Ye.set(vt,Qt.filter(fs=>typeof fs=="string"))}),Ye}catch{return new Map}}),he=a.useMemo(()=>{try{const Y=yo().getItem(mu);if(!Y)return new Map;const Je=JSON.parse(Y),Ye=new Map;return Object.entries(Je).forEach(([vt,Qt])=>{typeof Qt=="string"&&Qt.length>0&&Ye.set(vt,Qt)}),Ye}catch{return new Map}},[]),Ee=a.useCallback(Y=>{try{w.setItem(mu,JSON.stringify(Object.fromEntries(Y.entries())))}catch{}},[w]),[Ue,Me]=a.useState(new Map),X=a.useRef(new Map),Ne=a.useRef(0),Ae=js(Y=>Y.homeDirectory),Se=js(Y=>Y.currentDirectory),le=ms(Y=>Y.projects),ee=ms(Y=>Y.activeProjectId),ie=ms(Y=>Y.removeProject),ve=ms(Y=>Y.setActiveProjectIdOnly),K=ms(Y=>Y.updateProjectMeta),de=ms(Y=>Y.reorderProjects),_e=Re(Y=>Y.setActiveMainTab),Pe=Re(Y=>Y.openContextPanelTab),re=Re(Y=>Y.setSettingsDialogOpen),me=Re(Y=>Y.toggleHelpDialog),ge=Re(Y=>Y.setAboutDialogOpen),$=Re(Y=>Y.setSessionSwitcherOpen),B=Re(Y=>Y.setScheduledTasksDialogOpen),xe=Re(Y=>Y.setArchivePageOpen),be=Re(Y=>Y.setWorktreesPageProjectId),Le=Re(Y=>Y.openMultiRunLauncher),Ke=Re(Y=>Y.notifyOnSubtasks),st=Re(Y=>Y.showDeletionDialog),ut=Re(Y=>Y.setShowDeletionDialog),mt=Kl(u,120),pt=a.useMemo(()=>mt.trim().toLowerCase(),[mt]),ht=pt.length>0,xt=Nn(Y=>Y.collapsedFolderIds),wt=Nn(Y=>Y.foldersMap),bt=Nn(Y=>Y.getFoldersForScope),Dt=Nn(Y=>Y.createFolder),qt=Nn(Y=>Y.renameFolder),Ut=Nn(Y=>Y.deleteFolder),We=Nn(Y=>Y.addSessionToFolder),yt=Nn(Y=>Y.addSessionsToFolder),Qe=Nn(Y=>Y.removeSessionFromFolder),Rt=Nn(Y=>Y.removeSessionsFromFolders),Ot=Nn(Y=>Y.toggleFolderCollapse),kt=Nn(Y=>Y.getSessionFolderId);$0({enabled:t,isSessionSearchOpen:l,setIsSessionSearchOpen:d,sessionSearchInputRef:p,sessionSearchContainerRef:f});const Ft=cf(t),Ht=pa(),Xt=mf(),rt=`session-sidebar:${a.useId()}`,je=lg(),Fe=a.useMemo(()=>Array.from(je.values()),[je]),Te=a.useMemo(()=>ir(),[]),it=pn(Y=>Y.status==="ready"),ct=pn(nr(Y=>Y.activeSessions.map(La).sort())),Kt=pn(nr(Y=>Y.archivedSessions.map(La).sort())),Lt=pn.getState(),ze=Lt.activeSessions,Xe=Lt.archivedSessions,tt=a.useRef({signature:"",sessions:[]}),at=a.useMemo(()=>new Set(ze.map(Y=>Y.id)),[ze]),Ze=(()=>{const Y=Fe.filter(Ye=>!at.has(Ye.id)),Je=Y.map(La).sort().join(`
202
- `);return tt.current.signature===Je?tt.current.sessions:(tt.current={signature:Je,sessions:Y},Y)})(),Pt=et(Y=>Y.setCurrentSession),Tt=et(Y=>Y.updateSessionTitle),Jt=et(Y=>Y.shareSession),ls=et(Y=>Y.unshareSession),cs=et(Y=>Y.worktreeMetadata),Bt=et(Y=>Y.availableWorktreesByProject),_t=et(Y=>Y.openNewSessionDraft),Mt=a.useCallback(Y=>{Re.getState().closeMainSurfaces(),_t(Y),Te&&window.dispatchEvent(new CustomEvent("openchamber:navigate",{detail:{view:"chat"}}))},[Te,_t]),ps=ti(nr(Y=>({checkForUpdates:Y.checkForUpdates,available:Y.available,runtimeType:Y.runtimeType,info:Y.info,downloading:Y.downloading,downloaded:Y.downloaded,progress:Y.progress,error:Y.error,downloadUpdate:Y.downloadUpdate,restartToUpdate:Y.restartToUpdate}))),_s=a.useMemo(()=>h2(le,Bt,{includeWorktrees:!Te}),[Bt,Te,le]),Wt=a.useMemo(()=>{const Y=[...ze],Je=new Set(Y.map(Ye=>Ye.id));return Ze.forEach(Ye=>{Je.has(Ye.id)||Y.push(Ye)}),Y.filter(Ye=>p2(Ye,_s,{allowUnknownDirectory:!Te,allowEmptyDirectorySet:!Te}))},[ze,Te,_s,Ze]),Fs=a.useMemo(()=>[...ze,...Xe],[Xe,ze]),cn=a.useRef(Fe);a.useEffect(()=>{cn.current=Fe},[Fe]);const Gs=$n(),as=a.useMemo(()=>`${Gs}|${le.map(Y=>`${Y.id}:${Vt(Y.path)??""}`).join("|")}`,[le,Gs]),[Xs,Gn]=a.useState(Te?as:null),[qn,dn]=a.useReducer(Y=>Y+1,0),un=!Te&&Xs!==as,[yn,Os]=a.useState(new Set),zs=a.useRef(!1);a.useEffect(()=>{zs.current||(zs.current=!0,ea(cn.current))},[]),a.useEffect(()=>{let Y=!1;return(async()=>{const Ye=Gs,vt=ms.getState().projects;if(vt.length===0||Te){Y||(Os(new Set),Gn(as));return}const Qt=et.getState().availableWorktreesByProject,fs=new Map(Qt),kn=new Set,Ws=3;let Tr=0;const Jn=Array.from({length:Ws},async()=>{for(;;){const yr=Tr;if(Tr+=1,yr>=vt.length)return;const Sc=vt[yr],Fr=Vt(Sc.path);if(Fr)try{const Ta=await ml(async()=>tn.getState().directories.get(Fr)?.isGitRepo??await xf(Fr)?ug({id:Sc.id,path:Fr}):null);if(Ta===null){fs.delete(Fr);continue}if(Y)return;Ta.length===0?fs.delete(Fr):fs.set(Fr,Ta)}catch{kn.add(Fr)}}});if(await Promise.all(Jn),Y||$n()!==Ye)return;const po=new Set(vt.map(yr=>Vt(yr.path)).filter(Boolean));for(const yr of fs.keys())po.has(yr)||fs.delete(yr);const Er=fg(vt,fs),jc=[...Er.values()].flat();L0(jc.map(yr=>yr.path),Date.now()),mg(Er,Qt)||et.setState({availableWorktrees:jc,availableWorktreesByProject:Er}),Os(kn),Gn(as)})(),()=>{Y=!0}},[Te,as,Gs,qn]),a.useEffect(()=>{let Y=null,Je=!1;const Ye=new Set,vt=_m(Qt=>{Qt.type==="scheduled-task-ran"?Je=!0:(Ye.add(Qt.directory),dn()),Y&&clearTimeout(Y),Y=setTimeout(()=>{if(Y=null,Je){Je=!1,Ye.clear(),ea(cn.current);return}const fs=[...Ye];Ye.clear(),fs.length>0&&Bi(fs,cn.current)},500)});return()=>{Y&&clearTimeout(Y),vt()}},[]);const nn=a.useMemo(()=>hr(),[]),{isTablet:zn}=Pr(),rn=e||zn,{buildGroupSearchText:pr,filterSessionNodesForSearch:Dn,buildGroupedSessions:Ir}=B0({homeDirectory:Ae,worktreeMetadata:cs,pinnedSessionIds:se,sessionOrderRanks:G,gitBranches:Ft,isVSCode:Te}),{scheduleCollapsedProjectsPersist:Ss}=H0({isVSCode:Te,safeStorage:w,keys:{sessionExpanded:hu,projectCollapse:Ei,groupOrder:uu,groupCollapse:fu},groupOrderByProject:ke,collapsedGroups:oe,setExpandedParents:j,setCollapsedProjects:v}),ae=a.useMemo(()=>lf(Wt,se,G),[se,G,Wt]),qe=a.useMemo(()=>ae.map(Y=>Y.id).join("|"),[ae]),lt=a.useRef(null),gt=a.useMemo(()=>{const Y=lt.current;if(Y&&Y.signature===qe)return Y.map;const Je=new Map(ae.map((Ye,vt)=>[Ye.id,vt]));return lt.current={signature:qe,map:Je},Je},[ae,qe]),Gt=a.useMemo(()=>{const Y=new Map;return ae.forEach(Je=>{const Ye=Je.parentID;if(!Ye)return;const vt=Y.get(Ye)??[];vt.push(Je),Y.set(Ye,vt)}),Y.forEach(Je=>Je.sort((Ye,vt)=>Mo(Ye,vt,se,G))),Y},[ae,se,G]),Et=a.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]),St=a.useMemo(()=>le.find(Y=>Y.id===m)??null,[le,m]),xs=a.useCallback(Y=>{m&&K(m,{label:Y.label,icon:Y.icon,color:Y.color,iconBackground:Y.iconBackground,defaultModel:Y.defaultModel??null})},[m,K]),As=a.useCallback(()=>{M(!0)},[M]),ss=a.useCallback(()=>{const Y=ti.getState();if(Y.available&&Y.info){_(!0);return}ps.checkForUpdates().then(()=>{const{available:Je,error:Ye}=ti.getState();if(Ye){fe.error(c("sessions.sidebar.updateCheck.errorTitle"),{description:Ye});return}if(!Je){fe.success(c("sessions.sidebar.updateCheck.latestVersion"));return}_(!0)})},[c,ps]),ks=a.useCallback(()=>{e&&$(!1),re(!0)},[e,$,re]),Ls=ps.available&&(ps.runtimeType==="desktop"||ps.runtimeType==="web"),Bs=et(Y=>Y.deleteSession),Be=et(Y=>Y.deleteSessions),It=et(Y=>Y.archiveSession),ns=et(Y=>Y.archiveSessions),{copiedSessionId:ds,handleSessionSelect:ws,handleSessionDoubleClick:Ds,handleSaveEdit:on,handleCancelEdit:Ps,handleShareSession:fn,handleCopyShareUrl:lr,handleCopySessionId:vs,handleUnshareSession:zt,handleDeleteSession:us,confirmDeleteSession:Rr}=_0({mobileVariant:e,allowReselect:r,onSessionSelected:n,isSessionSearchOpen:l,sessionSearchQuery:u,setSessionSearchQuery:h,setIsSessionSearchOpen:d,setActiveMainTab:_e,setSessionSwitcherOpen:$,setCurrentSession:Pt,updateSessionTitle:Tt,shareSession:Jt,unshareSession:ls,deleteSession:Bs,deleteSessions:Be,archiveSession:It,archiveSessions:ns,childrenMap:Gt,showDeletionDialog:st,setDeleteSessionConfirm:U,deleteSessionConfirm:J,setEditingId:b,setEditTitle:g,editingId:x,editTitle:S}),Pn=a.useCallback(()=>{if(!te)return;const{scopeKey:Y,folderId:Je}=te;Z(null),Ut(Y,Je)},[te,Ut]),Vs=a.useCallback(()=>{Kn.requestDirectoryDialog()},[]),cr=a.useCallback(Y=>{j(Je=>{const Ye=cg(Je,Y);try{w.setItem(hu,JSON.stringify(Array.from(Ye)))}catch{}return Ye})},[w]),gr=a.useCallback((Y,Je)=>{if(!Y)return null;Je&&xt.has(Je)&&Ot(Je);const Ye=Dt(Y,c("sessions.sidebar.folder.newFolderName"),Je);return z(Ye.id),W(Ye.name),Ye},[xt,Ot,Dt,c]),Ur=er(ws),Vo=er(Ds),Hr=er(on),Wo=er(Ps),Kr=er(fn),uo=er(lr),Uo=er(vs),xr=er(zt),Ho=er(us),an=er(gr),In=a.useCallback((Y,Je)=>{E(Ye=>{const vt=new Map(Ye);return vt.set(Y,Je+7),vt})},[]),Is=a.useCallback(Y=>{E(Je=>{if(!Je.has(Y))return Je;const Ye=new Map(Je);return Ye.delete(Y),Ye})},[]),Vn=a.useCallback(Y=>{E(Je=>{let Ye=!1;const vt=new Map(Je),Qt=`${Y}:`;for(const fs of vt.keys())fs.startsWith(Qt)&&(vt.delete(fs),Ye=!0);return Ye?vt:Je})},[]),fo=a.useRef([]),Ko=a.useCallback(()=>{Ne.current=Date.now()+150,E(new Map),ce(()=>{const Y=new Set;return fo.current.forEach(Je=>{Je.groups.forEach(Ye=>{Ye.isMain||Y.add(`${Je.project.id}:${Ye.id}`)})}),Y}),v(()=>{const Y=new Set(le.map(Je=>Je.id));try{w.setItem(Ei,JSON.stringify(Array.from(Y)))}catch{}return Te||Ss(Y),Y})},[le,Te,w,Ss]),mo=a.useCallback(()=>{Ne.current=Date.now()+150,E(new Map),ce(new Set),v(()=>{const Y=new Set;try{w.setItem(Ei,JSON.stringify([]))}catch{}return Te||Ss(Y),Y})},[Te,w,Ss]),Go=a.useCallback(Y=>{Ne.current=Date.now()+150,Vn(Y),v(Je=>{const Ye=new Set(Je);Ye.has(Y)?Ye.delete(Y):Ye.add(Y);try{w.setItem(Ei,JSON.stringify(Array.from(Ye)))}catch{}return Te||Ss(Ye),Ye})},[Te,Vn,w,Ss]),wn=a.useMemo(()=>le.map(Y=>({...Y,normalizedPath:Vt(Y.path)})).filter(Y=>!!Y.normalizedPath),[le]),dr=a.useMemo(()=>wn.map(Y=>Y.normalizedPath),[wn]),br=a.useMemo(()=>{const Y=new Set(wn.map(Je=>Je.normalizedPath));if(!Te)for(const Je of Bt.values())for(const Ye of Je){const vt=Vt(Ye.path);vt&&Y.add(vt)}return[...Y].sort()},[Bt,Te,wn]),Mr=a.useRef(null);a.useEffect(()=>{const Y=new Set(br),Je=Mr.current;if(Mr.current=Y,!Je){Te&&br.length>0&&Bi(br,cn.current);return}const Ye=br.filter(vt=>!Je.has(vt));Ye.length!==0&&Bi(Ye,cn.current)},[Te,br]);const{github:vn}=_n(),Wn=Dr(Y=>Y.status),ur=Dr(Y=>Y.hasChecked),H=dg(t?dr:ol),Ge=en(Y=>Y.ensureEntry),ot=en(Y=>Y.setParams),jt=en(Y=>Y.refreshTargets);Q0({enabled:t,normalizedProjects:wn,gitRepoStatus:H,setProjectRepoStatus:F,setProjectRootBranches:Me});const Zt=et(Y=>Y.isLoading),es=a.useMemo(()=>lS(Wt,wn,Bt,Te,Xe),[Xe,Bt,Te,wn,Wt]);rS({enabled:t,hasAuthoritativeGlobalSessions:it,sessions:Fs});const{getSessionsForProject:rs,getArchivedSessionsForProject:ys}=tS({ownership:es});A0({enabled:t,normalizedProjects:wn,ownership:es,isSessionsLoading:Zt,hasAuthoritativeGlobalSessions:it,isWorktreeTopologyLoading:un,unresolvedWorktreeProjectPaths:yn,foldersMap:wt,createFolder:Dt,addSessionToFolder:We});const Rs=a.useRef(!1);ee&&P.has(ee)&&(Rs.current=!!P.get(ee));const Ns=ln(Y=>Y.showRecentSection),Ms=ln(Y=>Y.showArchivedSessions),Yn=ln(Y=>Y.projectSortOrder),Gr=ln(Y=>Y.stickyZoneHeaders),Qn=ms(Y=>Y.manualProjectOrder),jn=a.useRef(new Set),Xn=a.useRef(new Set),Un=Bc(jn.current,C,"project"),Rn=Bc(Xn.current,C,"recent");jn.current=Un,Xn.current=Rn;const fr={isVisible:t,mobileVariant:e,onSessionSelected:n,allowReselect:r,hideDirectoryControls:o,showOnlyMainWorkspace:i,t:c,isTablet:zn,liveSessions:Fe,activeSessionStructure:ct,archivedSessionStructure:Kt,globalActiveSessions:ze,archivedSessions:Xe,projects:le,activeProjectId:ee,manualProjectOrder:Qn,currentDirectory:Se,worktreeMetadata:cs,availableWorktreesByProject:Bt,pinnedSessionIds:se,sessionOrderRanks:G,foldersMap:wt,collapsedFolderIds:xt,gitBranches:Ft,gitRepoStatus:H,githubAuthStatus:Wn,githubAuthChecked:ur,updateStore:ps,showRecentSection:Ns,showArchivedSessions:Ms,projectSortOrder:Yn,projectRepoStatus:P,projectRootBranches:Ue,resolvedWorktreeTopologyKey:Xs,unresolvedWorktreeProjectPaths:yn,isSessionSearchOpen:l,sessionSearchQuery:u,editingId:x,editTitle:S,editingProjectDialogId:m,expandedParents:C,collapsedProjects:N,visibleSessionCountByGroup:k,updateDialogOpen:L,openSidebarMenuKey:D,renamingFolderId:T,renameFolderDraft:R,deleteSessionConfirm:J,deleteFolderConfirm:te,bulkDeleteConfirm:ue,collapsedGroups:oe},qr=a.useRef(null),Yr=qr.current;if(Yr){let Y=!1;for(const Je of Object.keys(fr))Object.is(Yr[Je],fr[Je])||(sr(`ui.session_sidebar.source.${Je}`),Y=!0);Y||sr("ui.session_sidebar.source.parent_or_context")}qr.current=fr;const Ma=a.useMemo(()=>{const Y=[...wn];switch(Yn){case"a-z":Y.sort((Je,Ye)=>{const vt=(Je.label||Je.path).toLowerCase(),Qt=(Ye.label||Ye.path).toLowerCase();return vt.localeCompare(Qt)});break;case"z-a":Y.sort((Je,Ye)=>{const vt=(Je.label||Je.path).toLowerCase();return(Ye.label||Ye.path).toLowerCase().localeCompare(vt)});break;case"date-added":Y.sort((Je,Ye)=>(Ye.addedAt??0)-(Je.addedAt??0));break;case"recent":Y.sort((Je,Ye)=>(Ye.lastOpenedAt??0)-(Je.lastOpenedAt??0));break;case"manual":{const Je=new Map(Qn.map((Ye,vt)=>[Ye,vt]));Y.sort((Ye,vt)=>{const Qt=Je.get(Ye.id)??1/0,fs=Je.get(vt.id)??1/0;return Qt-fs});break}}return Y},[wn,Yn,Qn]),{projectSections:Sn,groupSearchDataByGroup:yi,sectionsForRender:wi,flatSectionsForRender:ho,searchMatchCount:q}=M0({normalizedProjects:Ma,getSessionsForProject:rs,getArchivedSessionsForProject:ys,availableWorktreesByProject:Bt,projectRepoStatus:P,projectRootBranches:Ue,lastRepoStatus:Rs.current,buildGroupedSessions:Ir,hasSessionSearchQuery:ht,normalizedSessionSearchQuery:pt,filterSessionNodesForSearch:Dn,buildGroupSearchText:pr,foldersMap:wt});fo.current=Sn;const we=a.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:Ce}=P0(ke),Ve=a.useRef(!1);a.useEffect(()=>{if(Ve.current||Sn.length===0)return;const Y=Sn.flatMap(Je=>Je.groups.filter(Ye=>Ye.isArchivedBucket).map(Ye=>`${Je.project.id}:${Ye.id}`));Y.length>0&&ce(Je=>new Set([...Je,...Y])),Ve.current=!0},[Sn]);const dt=a.useMemo(()=>{const Y=new Map,Je=new Map;return Sn.forEach(Ye=>{const vt=Jl(Ye.project.label?.trim()||Vr(Ye.project.normalizedPath,Ae)||Ye.project.normalizedPath);Ye.groups.forEach(Qt=>{const fs=Qt.branch&&Qt.branch!=="HEAD"&&Qt.branch!==vt?Qt.branch:null,kn={projectLabel:vt,branchLabel:fs},Ws=Tr=>{Tr.forEach(Jn=>{const po=Ye.project.normalizedPath.length,Er=Je.get(Jn.session.id)??-1;po<Er||(Y.set(Jn.session.id,{node:Jn,projectId:Ye.project.id,groupDirectory:Qt.directory,secondaryMeta:kn}),Je.set(Jn.session.id,po),Jn.children.length>0&&Ws(Jn.children))})};Ws(Qt.sessions)})}),Y},[Sn,Ae]),$t=a.useMemo(()=>!Ns||Te?[]:i2(Wt,pe).sort((Y,Je)=>Mo(Y,Je,se,G)),[pe,Te,se,G,Wt,Ns]),os=a.useMemo(()=>{if(Te||!Ns)return[];const Y=Ye=>{const vt=dt.get(Ye.id),Qt=Vt(Ye.directory??null),fs=vt?.node??{session:Ye,children:[],worktree:null},Ws=(ht?Dn([fs],pt):[fs])[0];if(!Ws)return null;const Tr=vt?.secondaryMeta?{projectLabel:vt.secondaryMeta.projectLabel,branchLabel:Te?null:vt.secondaryMeta.branchLabel}:null;return{node:Ws,projectId:vt?.projectId??null,groupDirectory:vt?.groupDirectory??Qt,secondaryMeta:Tr}},Je=$t.map(Y).filter(Ye=>Ye!==null);return[{key:"active-now",title:c("sessions.sidebar.activity.recentTitle"),items:Je}]},[Dn,ht,Te,pt,$t,dt,Ns,c]),Yt=a.useMemo(()=>os.some(Y=>Y.items.length>0),[os]),Js=Te&&Ms,vi=ln(Y=>Y.sessionGroupingMode)==="by-worktree"&&!Te,Gm=a.useMemo(()=>{const Y=vi?wi:ho;return Js?Y:Y.map(Je=>Je.groups.some(Ye=>Ye.isArchivedBucket)?{...Je,groups:Je.groups.filter(Ye=>!Ye.isArchivedBucket)}:Je)},[ho,wi,Js,vi]),bc=a.useRef(new Set);a.useEffect(()=>{if(!t||!ur||!Wn?.connected||!vn)return;const Y=new Map,Je=Date.now();Sn.forEach(Ye=>{N.has(Ye.project.id)||Ye.groups.forEach(vt=>{if(vt.isArchivedBucket||vt.isMain)return;const Qt=Vt(vt.directory??null),fs=vt.branch?.trim()||Ft.get(Qt||"")?.trim();if(!Qt||!fs)return;const kn=bi(Qt,fs),Ws=en.getState().entries[kn],Tr=!!Ws?.status?.pr,Jn=`${Qt}::${fs}`,po=Math.max(Ws?.lastRefreshAt??0,Ws?.lastDiscoveryPollAt??0),Er=!!(Ws?.isInitialStatusResolved&&!Tr&&(!bc.current.has(Jn)||Je-po>=g2));(!Ws||!Ws.isInitialStatusResolved||Er)&&(Er&&bc.current.add(Jn),Y.has(kn)||Y.set(kn,{directory:Qt,branch:fs}))})}),Y.size!==0&&(Y.forEach((Ye,vt)=>{Ge(vt),ot(vt,{directory:Ye.directory,branch:Ye.branch,remoteName:null,canShow:!0,github:vn,githubAuthChecked:ur,githubConnected:Wn.connected})}),jt([...Y.values()],{silent:!0,markInitialResolved:!0}))},[N,Ge,vn,ur,Wn?.connected,t,Ft,Sn,jt,ot]);const qm=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",Ym="h-4.5 w-4.5",Qm=cS({enabled:t&&Gr,isDesktopShellRuntime:nn,projectSections:Sn,projectHeaderSentinelRefs:X}),qo=er((Y,Je=0,Ye,vt,Qt=!1,fs,kn="project",Ws)=>s.jsx(Yk,{node:Y,depth:Je,groupDirectory:Ye,projectId:vt,archivedBucket:Qt,pinnedSessionIds:se,expandedParents:kn==="recent"?Rn:Un,hasSessionSearchQuery:ht,normalizedSessionSearchQuery:pt,notifyOnSubtasks:Ke,editingId:x,setEditingId:b,editTitle:S,setEditTitle:g,handleSaveEdit:Hr,handleCancelEdit:Wo,toggleParent:cr,handleSessionSelect:Ur,handleSessionDoubleClick:Vo,togglePinnedSession:ne,handleShareSession:Kr,copiedSessionId:ds,handleCopyShareUrl:uo,handleCopySessionId:Uo,handleUnshareSession:xr,openSidebarMenuKey:D,setOpenSidebarMenuKey:A,renamingFolderId:T,getFoldersForScope:bt,getSessionFolderId:kt,removeSessionFromFolder:Qe,addSessionToFolder:We,createFolderAndStartRename:an,openContextPanelTab:Pe,handleDeleteSession:Ho,mobileVariant:e,alwaysShowActions:rn,renderSessionNode:qo,secondaryMeta:fs,renderContext:kn,subtreeContainsEditing:Ws?.subtreeContainsEditing??x2,menuOpenSessionId:Ws?.menuOpenSessionId??null,nodeStructureKey:Ws?.nodeStructureKey??"",childRenderExtrasFor:Ws?.childRenderExtrasFor})),Xm=a.useMemo(()=>{const Y=new Map;return ho.forEach(Je=>{const Ye=Je.groups.find(vt=>!vt.isArchivedBucket);Ye?.folderScopes&&Ye.folderScopes.length>0&&Y.set(Je.project.id,Ye.folderScopes)}),Y},[ho]),Jm=a.useCallback((Y,Je)=>{const Ye=[];return Je.forEach(vt=>{vt.isArchivedBucket||(Ye.push(vt.directory),vt.folderScopes?.forEach(Qt=>Ye.push(Qt.directory)))}),s.jsx(y2,{directories:Ye})},[]),yc=a.useCallback(Y=>{Is(Y),ce(Je=>{const Ye=new Set(Je);return Ye.has(Y)?Ye.delete(Y):Ye.add(Y),Ye})},[Is]),Zm=a.useCallback((Y,Je,Ye,vt,Qt,fs,kn)=>s.jsx(BS,{group:Y,groupKey:Je,projectId:Ye,hideGroupLabel:vt,dragHandleProps:Qt,compactBodyPadding:fs,hasSessionSearchQuery:ht,normalizedSessionSearchQuery:pt,groupSearchDataByGroup:yi,visibleSessionCount:k.get(Je),collapsedGroups:oe,hideDirectoryControls:o,collapsedFolderIds:xt,toggleFolderCollapse:Ot,renameFolder:qt,deleteFolder:Ut,showDeletionDialog:st,setDeleteFolderConfirm:Z,renderSessionNode:qo,showMoreGroupSessions:In,resetGroupSessionLimit:Is,mobileVariant:e,alwaysShowActions:rn,activeProjectId:ee,setActiveProjectIdOnly:ve,setActiveMainTab:_e,setSessionSwitcherOpen:$,openNewSessionDraft:Mt,addSessionToFolder:We,createFolderAndStartRename:an,renamingFolderId:T,renameFolderDraft:R,setRenameFolderDraft:W,setRenamingFolderId:z,pinnedSessionIds:se,expandedParents:Un,sessionOrderIndex:gt,editingId:x,editTitle:S,openSidebarMenuKey:D,activeActivitySessionIds:pe,unreadActivitySessionIds:Q,notifyOnSubtasks:Ke,onToggleCollapsedGroup:yc,scrollContainerRef:kn}),[ht,pt,yi,k,oe,o,xt,Ot,qt,Ut,st,qo,In,Is,e,rn,ee,ve,_e,$,Mt,We,an,T,R,se,Un,gt,x,S,D,pe,Q,Ke,yc]),eh=a.useMemo(()=>!Te&&Ns&&!ht?s.jsx(XS,{sections:os,renderSessionNode:qo,editingId:x,openSidebarMenuKey:D,expansionState:Rn,variant:"section",isDesktopShellRuntime:nn}):null,[os,x,ht,nn,Te,D,Rn,qo,Ns]),wc=!!(T||x||m),{selectionModeEnabled:vc,hasSelection:th,selectedIdsSize:sh,bulkScopeIsArchived:nh,derivedSelectionScope:rh,bulkScopeFolders:oh,bulkCanRemoveFromFolder:ih,handleToggleSelectionMode:ah,handleExitSelectionMode:lh,handleBulkMoveToFolder:ch,handleBulkCreateFolderAndMove:dh,handleBulkRemoveFromFolder:uh,handleBulkDelete:fh,confirmBulkDelete:mh}=t2({isInlineEditing:wc,showDeletionDialog:st,foldersMap:wt,folderScopesByProject:Xm,addSessionsToFolder:yt,removeSessionsFromFolders:Rt,createFolderAndStartRename:gr,archiveSessions:ns,deleteSessions:Be,setBulkDeleteConfirm:Oe}),hh=a.useCallback(()=>{_e("chat"),e&&$(!1),Le()},[e,Le,_e,$]),ph=a.useCallback(()=>{Re.getState().closeMainSurfaces(),_e("chat"),e&&$(!1),_t()},[e,_t,_e,$]);return s.jsx(pl,{delay:0,closeDelay:150,timeout:600,children:s.jsxs("div",{ref:f,className:De("relative flex h-full flex-col text-foreground overflow-x-hidden",e?"":"bg-transparent"),children:[s.jsx(b2,{owner:rt,childStores:Xt,projectSections:Sn,activeProjectId:ee,collapsedProjects:N,collapsedGroups:oe,currentDirectory:Se}),s.jsx(E0,{projectSections:Sn,activeProjectId:ee,initialActiveSessionByProject:he,persistActiveSessionByProject:Ee,handleSessionSelect:Ur,mobileVariant:e,openNewSessionDraft:_t,setActiveMainTab:_e,setSessionSwitcherOpen:$}),s.jsx(N0,{enabled:t,sortedSessions:ae,recentSessions:$t,prefetchSession:Ht.prefetchSession}),!o&&!Te?s.jsx(QS,{onNewSession:ph}):null,s.jsx(_S,{hideDirectoryControls:o,showRecentControls:!Te,handleOpenDirectoryDialog:Vs,onOpenScheduled:()=>{e&&$(!1),B(!0)},onOpenMultiRun:hh,canOpenMultiRun:le.length>0,onOpenArchive:()=>{e&&$(!1),xe(!0)},headerActionIconClass:Ym,headerActionButtonClass:qm,isSessionSearchOpen:l,setIsSessionSearchOpen:d,sessionSearchInputRef:p,sessionSearchQuery:u,setSessionSearchQuery:h,hasSessionSearchQuery:ht,searchMatchCount:q,collapseAllProjects:Ko,expandAllProjects:mo,selectionModeEnabled:vc,onToggleSelectionMode:ah}),t?s.jsx(dk,{topContent:eh,hasSharedSessions:Yt,sectionsForRender:Gm,projectSections:Sn,activeProjectId:ee,showOnlyMainWorkspace:i,hasSessionSearchQuery:ht,emptyState:Et,searchEmptyState:we,renderGroupSessions:Zm,homeDirectory:Ae,collapsedProjects:N,hideDirectoryControls:o,projectRepoStatus:P,isDesktopShellRuntime:nn,stickyZoneHeaders:Gr,stuckProjectHeaders:Qm,mobileVariant:e,alwaysShowActions:rn,toggleProject:Go,setActiveProjectIdOnly:ve,setActiveMainTab:_e,setSessionSwitcherOpen:$,openNewSessionDraft:Mt,openNewWorktreeDialog:As,openWorktreesPage:Y=>{e&&$(!1),be(Y)},openProjectEditDialog:y,removeProject:ie,projectHeaderSentinelRefs:X,reorderProjects:de,projectSortOrder:Yn,getOrderedGroups:Ce,setGroupOrderByProject:ye,renderProjectStatusIndicator:Jm,openSidebarMenuKey:D,setOpenSidebarMenuKey:A,isInlineEditing:wc}):null,vc&&th?s.jsx(e2,{selectedCount:sh,scopeKey:rh,scopeFolders:oh,archivedBucket:nh,onMoveToFolder:ch,onCreateFolderAndMove:dh,onRemoveFromFolder:uh,canRemoveFromFolder:ih,onDelete:fh,onDone:lh}):null,s.jsx(JS,{onOpenSettings:ks,onOpenShortcuts:me,onOpenAbout:()=>ge(!0),onOpenUpdate:ss,showRuntimeButtons:!Te,showUpdateButton:Ls}),s.jsx(Cf,{open:L,onOpenChange:_,info:ps.info,downloading:ps.downloading,downloaded:ps.downloaded,progress:ps.progress,error:ps.error,onDownload:ps.downloadUpdate,onRestart:ps.restartToUpdate,runtimeType:ps.runtimeType}),s.jsx(fS,{open:!!St,onOpenChange:Y=>{Y||y(null)},project:St,onSave:xs}),s.jsx(px,{open:O,onOpenChange:M,onWorktreeCreated:(Y,Je)=>{if(_e("chat"),e&&$(!1),Je?.sessionId){Pt(Je.sessionId,Y);return}_t({directoryOverride:Y,preserveDirectoryOverride:!0})}}),s.jsx(Xk,{value:J,setValue:U,showDeletionDialog:st,setShowDeletionDialog:ut,onConfirm:Rr}),s.jsx(Zk,{value:te,setValue:Z,onConfirm:Pn}),s.jsx(Jk,{value:ue,setValue:Oe,showDeletionDialog:st,setShowDeletionDialog:ut,onConfirm:mh})]})})},pu=a.memo(w2);function v2(t){return t.currentSessionDirectory}const Zr=t=>t?s.jsx("span",{className:"text-foreground/80 dark:text-foreground/70",children:t}):void 0,tr=t=>{if(!t)return"";const e=t.replace(/\\/g,"/");return e==="/"?"/":e.replace(/\/+$/,"")},j2=()=>{const{t}=ft(),[e,n]=a.useState(!1),[r,o]=a.useState(!1),[i,c]=a.useState(null),[l,d]=a.useState([]),[u,h]=a.useState(!1),[f,p]=a.useState(!1),[x,b]=a.useState(!1),[S,g]=a.useState(!1),[m,y]=a.useState(new Set),C=et(X=>X.getWorktreeMetadata),j=et(X=>X.newSessionDraft),w=et(X=>X.setNewSessionDraftTarget),N=et(X=>X.setDraftBootstrapPendingDirectory),v=hg,P=gg,F=et(X=>X.deleteSessions),k=et(X=>X.archiveSessions),E=Re(X=>X.showDeletionDialog),O=Re(X=>X.setShowDeletionDialog),M=js(X=>X.currentDirectory),L=js(X=>X.homeDirectory),_=js(X=>X.isHomeReady),D=ms(X=>X.projects),A=ms(X=>X.activeProjectId),{isMobile:T,isTablet:z,hasTouchInput:R}=Pr(),W=T||z||R,J=a.useMemo(()=>{const Ne=(A?D.find(Ae=>Ae.id===A)??null:null)?.path??M;return tr(Ne)},[A,M,D]),U=a.useCallback(X=>{const Ae=tr(X.projectDirectory)||J;return{id:(D.find(le=>tr(le.path)===Ae)??null)?.id??`path:${Ae}`,path:Ae}},[J,D]),te=S&&m.size>0,Z=a.useMemo(()=>{const X=i?.worktree;return X&&typeof X.branch=="string"&&X.branch.trim().length>0?!0:l.length>0&&l.every(({metadata:Ne})=>typeof Ne.branch=="string"&&Ne.branch.trim().length>0)},[i?.worktree,l]),ue=i?.mode==="worktree",Oe=ue,se=x||!ue||!Z,G=x||!ue;a.useEffect(()=>{r||!_||D.length>0||(o(!0),n(!0))},[r,_,D.length]);const Ie=a.useCallback(X=>{c({sessions:X.sessions,dateLabel:X.dateLabel,mode:X.mode??"session",worktree:X.worktree??null})},[]),pe=a.useCallback(()=>{c(null),d([]),h(!1),p(!1),b(!1),g(!1),y(new Set)},[]),V=a.useCallback(async X=>{if(X.sessions.length===0)return;if(X.sessions.length===1){const le=X.sessions[0];await v(le.id)?fe.success(t("sessions.sidebar.session.delete.success")):fe.error(t("sessions.sidebar.session.delete.error"));return}const Ne=X.sessions.map(le=>le.id),{deletedIds:Ae,failedIds:Se}=await F(Ne);if(Ae.length>0){const le=Se.length>0?Se.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:Se.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:Se.length}):X.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:X.dateLabel}):void 0;fe.success(Ae.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:Ae.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:Ae.length}),{description:Zr(le)})}Se.length>0&&fe.error(Se.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:Se.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:Se.length}),{description:Zr(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))})},[v,F,t]);a.useEffect(()=>Kn.onDeleteRequest(X=>{if(!E&&(X.mode??"session")==="session"){V(X);return}Ie(X)}),[Ie,E,V]),a.useEffect(()=>Kn.onDirectoryRequest(()=>{n(!0)}),[]),a.useEffect(()=>{if(!i){d([]),h(!1),p(!1),g(!1),y(new Set);return}const X=i.sessions.map(Se=>{const le=C(Se.id);return le?{session:Se,metadata:le}:null}).filter(Se=>!!Se);d(X),h(!1),g(!1),y(new Set);const Ne=new Map;if(i.worktree?.path&&Ne.set(tr(i.worktree.path),i.worktree),X.forEach(({metadata:Se})=>{Se.path&&Ne.set(tr(Se.path),Se)}),Ne.size===0){g(!0);return}let Ae=!1;return(async()=>{const Se=new Map,le=new Set;await Promise.all(Array.from(Ne.entries()).map(async([ee,ie])=>{try{const ve=await pg(ie.path);Se.set(ee,ve),ve?.isDirty&&le.add(ee)}catch{ie.status&&(Se.set(ee,ie.status),ie.status.isDirty&&le.add(ee))}})).catch(ee=>{console.warn("Failed to inspect worktree status before deletion:",ee)}),!Ae&&(y(le),g(!0),c(ee=>{if(!ee?.worktree?.path)return ee;const ie=tr(ee.worktree.path),ve=Se.get(ie);if(!ve)return ee;const K=ee.worktree.status;return K?.isDirty===ve.isDirty&&K?.ahead===ve.ahead&&K?.behind===ve.behind&&K?.upstream===ve.upstream?ee:{...ee,worktree:{...ee.worktree,status:ve}}}),d(ee=>ee.map(ie=>{const ve=tr(ie.metadata.path),K=Se.get(ve);return K?{session:ie.session,metadata:{...ie.metadata,status:K}}:ie})))})(),()=>{Ae=!0}},[i,C]),a.useEffect(()=>{Z||h(!1)},[Z]);const Q=a.useCallback(async(X,Ne)=>{const Ae=u&&Z,Se=U(X),le=tr(X.path),ee=tr(Se.path);try{await Ju(Se,X,{deleteRemoteBranch:Ae,deleteLocalBranch:Ne});const ie=tr(j?.directoryOverride);return j?.open&&le&&ie===le&&ee&&(N(null),w({projectId:Se.id,directoryOverride:ee},{force:!0})),tr(M)===le&&ee&&js.getState().setDirectory(ee,{showOverlay:!1}),!0}catch(ie){return fe.error(t("sessions.sidebar.sessionDialogs.worktree.errorRemoveTitle"),{description:Zr(ie instanceof Error?ie.message:t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),!1}},[Z,M,u,U,j?.directoryOverride,j?.open,N,w,t]),ne=a.useCallback((X,Ne)=>{const Ae=u&&Z;(async()=>{if(!await Q(X,Ne))return;const le=t(Ae?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.removed");fe.success(t("sessions.sidebar.sessionDialogs.worktree.removedTitle"),{description:Zr(le)})})()},[Z,u,Q,t]),oe=a.useCallback(async()=>{if(i){b(!0);try{const X=Oe,Ne=X&&u,Ae=X&&f;if(i.sessions.length===0&&ue&&i.worktree){ne(i.worktree,Ae),pe();return}if(i.sessions.length===1){const Se=i.sessions[0];if(!(ue?await P(Se.id):await v(Se.id))){fe.error(t(ue?"sessions.sidebar.session.archive.error":"sessions.sidebar.session.delete.error")),b(!1);return}const ee=!ue&&X?t(Ne?"sessions.sidebar.sessionDialogs.worktree.removedWithRemote":"sessions.sidebar.sessionDialogs.worktree.attachedArchived"):void 0;fe.success(t(ue?"sessions.sidebar.session.archive.success":"sessions.sidebar.session.delete.success"),{description:Zr(ee),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}else{const Se=i.sessions.map(ie=>ie.id);let le=[],ee=[];if(ue){const ie=await k(Se);le=ie.archivedIds,ee=ie.failedIds}else{const ie=await F(Se);le=ie.deletedIds,ee=ie.failedIds}if(ue&&i.worktree&&ee.length===0&&ne(i.worktree,Ae),le.length>0){const ie=!ue&&X?t(Ne?"sessions.sidebar.sessionDialogs.worktree.archivedAndRemoteRemoved":"sessions.sidebar.sessionDialogs.worktree.attachedArchivedPlural"):void 0,K=[ee.length>0?ue?ee.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToArchive",{count:ee.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToArchive",{count:ee.length}):ee.length===1?t("sessions.sidebar.dialogs.deleteResult.singleFailedToDelete",{count:ee.length}):t("sessions.sidebar.dialogs.deleteResult.manyFailedToDelete",{count:ee.length}):i.dateLabel?t("sessions.sidebar.dialogs.deleteResult.removedFromDate",{dateLabel:i.dateLabel}):void 0,ie].filter(Boolean).join(" ");fe.success(ue?le.length===1?t("sessions.sidebar.bulkActions.archivedSingle",{count:le.length}):t("sessions.sidebar.bulkActions.archivedPlural",{count:le.length}):le.length===1?t("sessions.sidebar.bulkActions.deletedSingle",{count:le.length}):t("sessions.sidebar.bulkActions.deletedPlural",{count:le.length}),{description:Zr(K||void 0),action:{label:t("sessions.sidebar.sessionDialogs.ok"),onClick:()=>{}}})}if(ee.length>0&&(fe.error(ue?ee.length===1?t("sessions.sidebar.bulkActions.failedArchiveSingle",{count:ee.length}):t("sessions.sidebar.bulkActions.failedArchivePlural",{count:ee.length}):ee.length===1?t("sessions.sidebar.bulkActions.failedDeleteSingle",{count:ee.length}):t("sessions.sidebar.bulkActions.failedDeletePlural",{count:ee.length}),{description:Zr(t("sessions.sidebar.dialogs.deleteResult.tryAgain"))}),le.length===0)){b(!1);return}}ue&&i.sessions.length===1&&i.worktree&&ne(i.worktree,Ae),pe()}finally{b(!1)}}},[i,u,f,v,F,P,k,pe,Oe,ue,ne,t]),ce=i?.worktree??l[0]?.metadata??null,ke=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}):"",ye=i?s.jsxs("div",{className:De(ue?"space-y-3":"space-y-2"),children:[i.sessions.length>0&&s.jsxs("div",{className:De(ue?"rounded-lg bg-muted/30 p-3":"space-y-1.5 rounded-xl border border-border/40 bg-sidebar/60 p-3"),children:[ue&&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:De(ue?"mt-2 space-y-1":"space-y-0.5"),children:[i.sessions.slice(0,5).map(X=>s.jsxs("li",{className:De(ue?"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:De(!ue&&"hidden"),children:"•"}),s.jsx("span",{className:"truncate",children:X.title||t("sessions.sidebar.session.untitled")})]},X.id)),i.sessions.length>5&&s.jsx("li",{className:De(ue?"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})})]})]}),ue?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")}),ce?.label?s.jsx("span",{className:"typography-micro text-muted-foreground/70",children:ce.label}):null]}),s.jsx("p",{className:"typography-micro text-muted-foreground/80 break-all",children:ce?Zi(ce.path,L):t("sessions.sidebar.sessionDialogs.worktree.pathUnavailable")}),te&&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,he=ue?Z?s.jsxs("button",{type:"button",onClick:()=>{se||h(X=>!X)},disabled:se,className:De("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",se?"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,Ee=ue?s.jsxs("button",{type:"button",onClick:()=>{G||p(X=>!X)},disabled:G,className:De("flex items-center gap-2 rounded-md px-2 py-1 text-sm text-muted-foreground transition-colors",G?"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,Ue=ue?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:[Ee,he]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(He,{variant:"ghost",onClick:pe,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(He,{variant:"destructive",onClick:oe,disabled:x,children:t(x?"sessions.sidebar.sessionDialogs.actions.deleting":"sessions.sidebar.sessionDialogs.actions.deleteWorktree")})]})]}):s.jsxs("div",{className:"flex w-full items-center justify-between gap-3",children:[s.jsxs("button",{type:"button",onClick:()=>O(!E),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":!E,children:[E?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(He,{variant:"ghost",onClick:pe,disabled:x,children:t("sessions.sidebar.dialogs.cancel")}),s.jsx(He,{variant:"destructive",onClick:oe,disabled:x,children:x?t("sessions.sidebar.sessionDialogs.actions.deleting"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction")})]})]}),Me=ue?t("sessions.sidebar.sessionDialogs.actions.deleteWorktree"):i?.sessions.length===1?t("sessions.sidebar.dialogs.deleteSession.titleAction"):t("sessions.sidebar.dialogs.deleteSessions.titleAction");return s.jsxs(s.Fragment,{children:[W?s.jsx(ka,{open:!!i,onClose:()=>{x||pe()},title:Me,footer:s.jsx("div",{className:"flex justify-end gap-2",children:Ue}),children:s.jsxs("div",{className:"space-y-2 pb-2",children:[ke&&s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:ke}),ye]})}):s.jsx(Ts,{open:!!i,onOpenChange:X=>{if(!X){if(x)return;pe()}},children:s.jsxs(Es,{className:De(ue?"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(Hs,{children:[s.jsxs($s,{className:De(ue&&"flex items-center gap-2"),children:[ue&&s.jsx(I,{name:"delete-bin",className:"h-5 w-5"}),Me]}),ke&&s.jsx(Ks,{children:ke})]}),s.jsx("div",{className:De(ue&&"flex-1 min-h-0 overflow-y-auto space-y-2"),children:ye}),s.jsx(ar,{className:"mt-2 gap-2 pt-1 pb-1",children:Ue})]})}),s.jsx(gx,{open:e,onOpenChange:n})]})},Ra=async(t,e)=>{try{const n=await t.json();if(n&&typeof n.error=="string"&&n.error.trim().length>0)return n.error}catch{return e}return e},Fo=t=>{const e=typeof t=="string"?t.trim():"";if(!e)throw new Error("projectId is required");return e},S2=async t=>{const e=Fo(t),n=await hs(`/api/projects/${encodeURIComponent(e)}/scheduled-tasks`);if(!n.ok)throw new Error(await Ra(n,"Failed to load scheduled tasks"));const r=await n.json().catch(()=>null);return!r||!Array.isArray(r.tasks)?[]:r.tasks},gu=async(t,e)=>{const n=Fo(t),r=await hs(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks`,{method:"PUT",headers:{"content-type":"application/json",accept:"application/json"},body:JSON.stringify({task:e})});if(!r.ok)throw new Error(await Ra(r,"Failed to save scheduled task"));const o=await r.json().catch(()=>null);return!o||!Array.isArray(o.tasks)?[]:o.tasks},k2=async(t,e)=>{const n=Fo(t),r=Fo(e),o=await hs(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}`,{method:"DELETE",headers:{accept:"application/json"}});if(!o.ok)throw new Error(await Ra(o,"Failed to delete scheduled task"));const i=await o.json().catch(()=>null);return!i||!Array.isArray(i.tasks)?[]:i.tasks},N2=async(t,e)=>{const n=Fo(t),r=Fo(e),o=await hs(`/api/projects/${encodeURIComponent(n)}/scheduled-tasks/${encodeURIComponent(r)}/run`,{method:"POST",headers:{accept:"application/json"}});if(!o.ok)throw new Error(await Ra(o,"Failed to run scheduled task"));const i=await o.json().catch(()=>null);return{sessionId:typeof i?.sessionId=="string"&&i.sessionId.length>0?i.sessionId:void 0}};function zm(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 C2(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 l=o.next();l&&i.push(l.toDate())}return i}catch{return[]}}const A2=[{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"}],D2={"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"},io=t=>D2[t]??t,Vm=[0,1,2,3,4,5,6],xu="flex h-6 w-6 cursor-pointer items-center justify-center text-foreground transition-none outline-none focus:outline-none flex-shrink-0",Tl=typeof Intl<"u"&&typeof Intl.supportedValuesOf=="function"?[...new Set(Intl.supportedValuesOf("timeZone").map(io))]:["UTC","Europe/Kyiv","Europe/London","Europe/Berlin","America/New_York","America/Los_Angeles","Asia/Tokyo"],bu=()=>{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}`},Gi=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},yu=t=>{const e=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),r=String(t.getDate()).padStart(2,"0");return`${e}-${n}-${r}`},P2=(t,e,n)=>{const r=Gi(t);return r?new Intl.DateTimeFormat(n,{month:"short",day:"numeric",year:"numeric"}).format(r):e},wu=(t,e)=>new Date(t.getFullYear(),t.getMonth()+e,1),I2=(t,e)=>{const n=t.getFullYear(),r=t.getMonth(),c=(new Date(n,r,1).getDay()-e+7)%7,l=new Date(n,r+1,0).getDate(),d=new Date(n,r,0).getDate(),u=[];for(let h=0;h<42;h+=1){const f=h-c+1;if(f<=0){const p=d+f;u.push({date:new Date(n,r-1,p),inCurrentMonth:!1});continue}if(f>l){u.push({date:new Date(n,r+1,f-l),inCurrentMonth:!1});continue}u.push({date:new Date(n,r,f),inCurrentMonth:!0})}return u},R2=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}},eo=(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 l=i%12;return n==="PM"&&(l+=12),`${String(l).padStart(2,"0")}:${String(c).padStart(2,"0")}`},zo=(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"},vu=t=>/^(0[1-9]|1[0-2])$/.test(t)?t:zo(t,{min:1,max:12}),Fi=t=>/^[0-5][0-9]$/.test(t)?t:zo(t,{max:59}),M2=(t,e)=>zo(String(Number.parseInt(t,10)+e),{min:1,max:12,loop:!0}),ju=(t,e)=>zo(String(Number.parseInt(t,10)+e),{min:0,max:59,loop:!0}),T2=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}},E2=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}},F2=t=>{const e=new Intl.DateTimeFormat(t,{weekday:"short"}),n=new Date(2023,0,1);return Vm.map(r=>e.format(new Date(n.getFullYear(),n.getMonth(),n.getDate()+r)))},O2=(t,e)=>[...t.slice(e),...t.slice(0,e)],Cn=t=>{const e=nt.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},Su=t=>{const e=nt.c(84),{value:n,onChange:r,use24Hour:o,hourAriaLabel:i,minuteAriaLabel:c,periodAriaLabel:l,amLabel:d,pmLabel:u}=t;let h;e[0]!==n?(h=R2(n),e[0]=n,e[1]=h):h=e[1];const f=h,p=$e.useRef(null),x=$e.useRef(null),[b,S]=$e.useState(null),[g,m]=$e.useState(null),y=$e.useRef(null),C=$e.useRef(null);let j;e[2]===Symbol.for("react.memo_cache_sentinel")?(j=Me=>{y.current=Me,S(Me)},e[2]=j):j=e[2];const w=j;let N;e[3]===Symbol.for("react.memo_cache_sentinel")?(N=Me=>{C.current=Me,m(Me)},e[3]=N):N=e[3];const v=N,P=W2,F=U2,k=H2;let E;e[4]!==r||e[5]!==f.meridiem||e[6]!==f.minute||e[7]!==o?(E=Me=>{const X=Me.replace(/\D/g,"").slice(0,2);w(X),X.length===2&&(r(o?k(P(X),f.minute):eo(vu(X),f.minute,f.meridiem)),w(null),x.current?.focus())},e[4]=r,e[5]=f.meridiem,e[6]=f.minute,e[7]=o,e[8]=E):E=e[8];const O=E;let M;e[9]!==r||e[10]!==f.meridiem||e[11]!==f.minute||e[12]!==o?(M=()=>{const Me=y.current;if(Me!==null&&(w(null),Me.length!==0)){if(o){r(k(P(Me.padStart(2,"0")),f.minute));return}r(eo(vu(Me.padStart(2,"0")),f.minute,f.meridiem))}},e[9]=r,e[10]=f.meridiem,e[11]=f.minute,e[12]=o,e[13]=M):M=e[13];const L=M;let _;e[14]!==r||e[15]!==f.hour12||e[16]!==f.hour24||e[17]!==f.meridiem||e[18]!==o?(_=Me=>{const X=Me.replace(/\D/g,"").slice(0,2);v(X),X.length===2&&(r(o?k(f.hour24,Fi(X)):eo(f.hour12,Fi(X),f.meridiem)),v(null))},e[14]=r,e[15]=f.hour12,e[16]=f.hour24,e[17]=f.meridiem,e[18]=o,e[19]=_):_=e[19];const D=_;let A;e[20]!==r||e[21]!==f.hour12||e[22]!==f.hour24||e[23]!==f.meridiem||e[24]!==o?(A=()=>{const Me=C.current;Me!==null&&(v(null),Me.length!==0&&r(o?k(f.hour24,Fi(Me.padStart(2,"0"))):eo(f.hour12,Fi(Me.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]=A):A=e[25];const T=A;let z;e[26]!==r||e[27]!==f.hour12||e[28]!==f.hour24||e[29]!==f.meridiem||e[30]!==f.minute||e[31]!==o?(z=Me=>r(o?k(F(f.hour24,Me),f.minute):eo(M2(f.hour12,Me),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]=z):z=e[32];const R=z;let W;e[33]!==r||e[34]!==f.hour12||e[35]!==f.hour24||e[36]!==f.meridiem||e[37]!==f.minute||e[38]!==o?(W=Me=>r(o?k(f.hour24,ju(f.minute,Me)):eo(f.hour12,ju(f.minute,Me),f.meridiem)),e[33]=r,e[34]=f.hour12,e[35]=f.hour24,e[36]=f.meridiem,e[37]=f.minute,e[38]=o,e[39]=W):W=e[39];const J=W;let U;e[40]!==r||e[41]!==f.hour12||e[42]!==f.meridiem||e[43]!==f.minute?(U=Me=>{Me!==f.meridiem&&r(eo(f.hour12,f.minute,Me))},e[40]=r,e[41]=f.hour12,e[42]=f.meridiem,e[43]=f.minute,e[44]=U):U=e[44];const te=U;let Z;e[45]!==L||e[46]!==R?(Z=Me=>{if(Me.key==="ArrowRight"){Me.preventDefault(),L(),x.current?.focus();return}(Me.key==="ArrowUp"||Me.key==="ArrowDown")&&(Me.preventDefault(),w(null),R(Me.key==="ArrowUp"?1:-1))},e[45]=L,e[46]=R,e[47]=Z):Z=e[47];const ue=Z;let Oe;e[48]!==T||e[49]!==J?(Oe=Me=>{if(Me.key==="ArrowLeft"&&(Me.currentTarget.selectionStart??0)===0){Me.preventDefault(),T(),p.current?.focus();return}(Me.key==="ArrowUp"||Me.key==="ArrowDown")&&(Me.preventDefault(),v(null),J(Me.key==="ArrowUp"?1:-1))},e[48]=T,e[49]=J,e[50]=Oe):Oe=e[50];const se=Oe,G=o?"px-2":"pl-2 pr-1";let Ie;e[51]!==G?(Ie=De("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",G),e[51]=G,e[52]=Ie):Ie=e[52];const pe=b??(o?f.hour24:f.hour12);let V;e[53]!==O?(V=Me=>O(Me.target.value),e[53]=O,e[54]=V):V=e[54];let Q;e[55]===Symbol.for("react.memo_cache_sentinel")?(Q=()=>w(""),e[55]=Q):Q=e[55];let ne;e[56]!==L||e[57]!==i||e[58]!==ue||e[59]!==pe||e[60]!==V?(ne=s.jsx("input",{ref:p,inputMode:"numeric",value:pe,onChange:V,onKeyDown:ue,onFocus:Q,onBlur:L,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]=L,e[57]=i,e[58]=ue,e[59]=pe,e[60]=V,e[61]=ne):ne=e[61];let oe;e[62]===Symbol.for("react.memo_cache_sentinel")?(oe=s.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:":"}),e[62]=oe):oe=e[62];const ce=g??f.minute;let ke;e[63]!==D?(ke=Me=>D(Me.target.value),e[63]=D,e[64]=ke):ke=e[64];let ye;e[65]===Symbol.for("react.memo_cache_sentinel")?(ye=()=>v(""),e[65]=ye):ye=e[65];let he;e[66]!==T||e[67]!==c||e[68]!==se||e[69]!==ce||e[70]!==ke?(he=s.jsx("input",{ref:x,inputMode:"numeric",value:ce,onChange:ke,onKeyDown:se,onFocus:ye,onBlur:T,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]=T,e[67]=c,e[68]=se,e[69]=ce,e[70]=ke,e[71]=he):he=e[71];let Ee;e[72]!==d||e[73]!==f.meridiem||e[74]!==l||e[75]!==u||e[76]!==te||e[77]!==o?(Ee=o?null:s.jsxs(gn,{value:f.meridiem,onValueChange:Me=>te(Me),children:[s.jsx(xn,{"aria-label":l,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(sn,{})}),s.jsxs(bn,{children:[s.jsx(bs,{value:"AM",children:d}),s.jsx(bs,{value:"PM",children:u})]})]}),e[72]=d,e[73]=f.meridiem,e[74]=l,e[75]=u,e[76]=te,e[77]=o,e[78]=Ee):Ee=e[78];let Ue;return e[79]!==Ie||e[80]!==ne||e[81]!==he||e[82]!==Ee?(Ue=s.jsxs("div",{className:Ie,children:[ne,oe,he,Ee]}),e[79]=Ie,e[80]=ne,e[81]=he,e[82]=Ee,e[83]=Ue):Ue=e[83],Ue},ku=t=>new Date(t.getFullYear(),t.getMonth(),1),L2=()=>{const t=new Date;return new Date(t.getFullYear(),t.getMonth(),t.getDate())},Nu=(t,e)=>t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate(),B2=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"]},Cu=(t,e)=>{const n=io(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:B2(t),onceDate:typeof t.schedule.date=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t.schedule.date)?t.schedule.date:bu(),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:io(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:bu(),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}}},$2=(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(!zm(t.schedule.cronExpression).valid)return e("sessions.scheduledTasks.editor.validation.cronInvalid")}else if(t.schedule.times.filter(r=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(r)).length===0)return e("sessions.scheduledTasks.editor.validation.atLeastOneTime");return t.schedule.kind==="weekly"&&t.schedule.weekdays.length===0?e("sessions.scheduledTasks.editor.validation.atLeastOneWeekday"):t.schedule.timezone.trim()?null:e("sessions.scheduledTasks.editor.validation.timezoneRequired")},_2=t=>{const e=t.filter(n=>/^([01]\d|2[0-3]):([0-5]\d)$/.test(n));return Array.from(new Set(e)).sort((n,r)=>n.localeCompare(r))},z2=t=>{const e=nt.c(64),{draft:n,setDraft:r,locale:o,t:i}=t,c=n.schedule.cronExpression;let l;e[0]!==c?(l=c.trim()?zm(c):null,e[0]=c,e[1]=l):l=e[1];const d=l;let u;e:{if(!d?.valid||!c.trim()){let z;e[2]===Symbol.for("react.memo_cache_sentinel")?(z=[],e[2]=z):z=e[2],u=z;break e}let T;e[3]!==c||e[4]!==n.schedule.timezone?(T=C2(c,n.schedule.timezone),e[3]=c,e[4]=n.schedule.timezone,e[5]=T):T=e[5],u=T}const h=u;let f;e[6]!==n.schedule.timezone||e[7]!==o?(f=T=>new Intl.DateTimeFormat(o,{timeZone:n.schedule.timezone,month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}).format(T),e[6]=n.schedule.timezone,e[7]=o,e[8]=f):f=e[8];const p=f;let x;e[9]!==i?(x=i("sessions.scheduledTasks.editor.cronExpression.label"),e[9]=i,e[10]=x):x=e[10];let b;e[11]!==x?(b=s.jsx(Cn,{htmlFor:"sched-cron",required:!0,children:x}),e[11]=x,e[12]=b):b=e[12];let S;e[13]!==r?(S=T=>r(z=>({...z,schedule:{...z.schedule,cronExpression:T.target.value}})),e[13]=r,e[14]=S):S=e[14];let g;e[15]!==i?(g=i("sessions.scheduledTasks.editor.cronExpression.placeholder"),e[15]=i,e[16]=g):g=e[16];let m;e[17]!==c||e[18]!==S||e[19]!==g?(m=s.jsx(or,{id:"sched-cron",value:c,onChange:S,placeholder:g,className:"w-full max-w-xs font-mono"}),e[17]=c,e[18]=S,e[19]=g,e[20]=m):m=e[20];let y;e[21]!==c||e[22]!==d||e[23]!==i?(y=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]=y):y=e[24];let C;e[25]!==b||e[26]!==m||e[27]!==y?(C=s.jsxs("div",{className:"flex flex-col gap-1",children:[b,m,y]}),e[25]=b,e[26]=m,e[27]=y,e[28]=C):C=e[28];let j;e[29]!==p||e[30]!==h||e[31]!==i?(j=h.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:h.map(p).join(", ")})]}):null,e[29]=p,e[30]=h,e[31]=i,e[32]=j):j=e[32];let w;e[33]!==i?(w=i("sessions.scheduledTasks.editor.cronExpression.examples"),e[33]=i,e[34]=w):w=e[34];let N;e[35]!==w?(N=s.jsx("span",{className:"typography-meta text-muted-foreground",children:w}),e[35]=w,e[36]=N):N=e[36];let v;e[37]!==r||e[38]!==i?(v=A2.map(T=>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(z=>({...z,schedule:{...z.schedule,cronExpression:T.expression}})),children:[s.jsx("span",{className:"font-mono",children:T.expression}),s.jsx("span",{className:"text-muted-foreground",children:i(T.labelKey)})]},T.expression)),e[37]=r,e[38]=i,e[39]=v):v=e[39];let P;e[40]!==v?(P=s.jsx("div",{className:"flex flex-wrap gap-1.5",children:v}),e[40]=v,e[41]=P):P=e[41];let F;e[42]!==N||e[43]!==P?(F=s.jsxs("div",{className:"flex flex-col gap-1",children:[N,P]}),e[42]=N,e[43]=P,e[44]=F):F=e[44];let k;e[45]!==i?(k=i("sessions.scheduledTasks.editor.timezone.label"),e[45]=i,e[46]=k):k=e[46];let E;e[47]!==k?(E=s.jsx(Cn,{children:k}),e[47]=k,e[48]=E):E=e[48];let O;e[49]!==r?(O=T=>{r(z=>({...z,schedule:{...z.schedule,timezone:T}}))},e[49]=r,e[50]=O):O=e[50];let M;e[51]===Symbol.for("react.memo_cache_sentinel")?(M=s.jsx(xn,{size:"lg",className:"w-fit max-w-full",children:s.jsx(sn,{})}),e[51]=M):M=e[51];let L;e[52]===Symbol.for("react.memo_cache_sentinel")?(L=s.jsx(bn,{children:Tl.map(K2)}),e[52]=L):L=e[52];let _;e[53]!==n.schedule.timezone||e[54]!==O?(_=s.jsxs(gn,{value:n.schedule.timezone,onValueChange:O,children:[M,L]}),e[53]=n.schedule.timezone,e[54]=O,e[55]=_):_=e[55];let D;e[56]!==E||e[57]!==_?(D=s.jsxs("div",{className:"flex flex-col gap-1",children:[E,_]}),e[56]=E,e[57]=_,e[58]=D):D=e[58];let A;return e[59]!==C||e[60]!==j||e[61]!==F||e[62]!==D?(A=s.jsxs("div",{className:"flex flex-col gap-3",children:[C,j,F,D]}),e[59]=C,e[60]=j,e[61]=F,e[62]=D,e[63]=A):A=e[63],A};function V2(t){const{open:e,task:n,onOpenChange:r,onSave:o}=t,{t:i,locale:c}=ft(),l=ts($=>$.loadProviders),d=ts($=>$.loadAgents),u=ts($=>$.providers),h=ts($=>$.currentProviderId),f=ts($=>$.currentModelId),p=ts($=>$.currentVariant||""),x=ts($=>$.currentAgentName||""),b=Re($=>$.timeFormatPreference),S=Re($=>$.weekStartPreference),g=Re($=>$.isMobile),[m,y]=$e.useState(()=>Cu(n,{providerID:h,modelID:f,variant:p,agent:x})),[C,j]=$e.useState(!1),[w,N]=$e.useState(!1),[v,P]=$e.useState(!1),[F,k]=$e.useState(""),[E,O]=$e.useState(!1),[M,L]=$e.useState(""),[_,D]=$e.useState(!1),[A,T]=$e.useState(""),[z,R]=$e.useState(()=>{const $=Gi(n?.schedule?.date||"")||new Date;return new Date($.getFullYear(),$.getMonth(),1)}),W=$e.useRef(null),J=$e.useRef(null),U=$e.useRef(null),te=$e.useRef(null),Z=$e.useRef(null),ue=$e.useMemo(()=>E2(c),[c]),Oe=$e.useMemo(()=>T2(c),[c]),se=$e.useMemo(()=>b==="24h"?!0:b==="12h"?!1:ue,[b,ue]),G=$e.useMemo(()=>S==="sunday"?0:S==="monday"?1:Oe,[S,Oe]),Ie=$e.useMemo(()=>{const $=F2(c);return O2(Vm.map(B=>({value:B,label:$[B]||""})),G)},[c,G]);$e.useEffect(()=>{e&&(l({source:"scheduledTaskEditor"}),d({source:"scheduledTaskEditor"}))},[e,l,d]),$e.useEffect(()=>{if(!e)return;y(Cu(n,{providerID:h,modelID:f,variant:p,agent:x}));const $=Gi(n?.schedule?.date||"")||new Date;R(new Date($.getFullYear(),$.getMonth(),1)),N(!1),O(!1),P(!1),L(""),k("")},[e,n,h,f,p,x]),$e.useEffect(()=>{if(!w)return;const $=B=>{W.current&&!W.current.contains(B.target)&&N(!1)};return document.addEventListener("mousedown",$),()=>{document.removeEventListener("mousedown",$)}},[w]);const pe=$e.useMemo(()=>{const B=u.find(xe=>xe.id===m.execution.providerID)?.models?.find(xe=>xe.id===m.execution.modelID);return B?.variants?Object.keys(B.variants):[]},[u,m.execution.providerID,m.execution.modelID]),V=pe.length>0,Q=$e.useMemo(()=>!V||!m.execution.variant?"__default":pe.includes(m.execution.variant)?m.execution.variant:"__default",[m.execution.variant,V,pe]);$e.useEffect(()=>{V||!m.execution.variant||y($=>({...$,execution:{...$.execution,variant:""}}))},[V,m.execution.variant]);const ne=$e.useCallback(($,B)=>{y(xe=>{const be=new Set(xe.schedule.weekdays);return B?be.add($):be.delete($),{...xe,schedule:{...xe.schedule,weekdays:Array.from(be).sort((Le,Ke)=>Le-Ke)}}})},[]),oe=$e.useCallback(($,B)=>{y(xe=>{const be=xe.schedule.times.slice();return be[$]=B,{...xe,schedule:{...xe.schedule,times:be}}})},[]),ce=$e.useCallback($=>{y(B=>{const xe=B.schedule.times.filter((be,Le)=>Le!==$);return{...B,schedule:{...B.schedule,times:xe.length>0?xe:["09:00"]}}})},[]),ke=$e.useCallback(()=>{y($=>({...$,schedule:{...$.schedule,times:[...$.schedule.times,"12:00"]}}))},[]),ye=$e.useMemo(()=>L2(),[]),he=$e.useMemo(()=>ku(ye),[ye]),Ee=$e.useMemo(()=>{const $=Gi(m.schedule.onceDate);return $?Nu($,ye)?i("sessions.scheduledTasks.editor.date.today"):new Intl.DateTimeFormat(c,{weekday:"short"}).format($):null},[m.schedule.onceDate,c,i,ye]),Ue=$e.useMemo(()=>ku(z).getTime()<=he.getTime(),[z,he]),Me=$e.useMemo(()=>Ie.map($=>$.label),[Ie]),X=$e.useCallback($=>{y(B=>({...B,schedule:{...B.schedule,onceDate:$}}))},[]),Ne=$e.useCallback(($,B)=>{if($.startsWith("/")){const Ke=$.indexOf(" "),st=$.indexOf(`
203
- `),ut=Math.min(Ke===-1?$.length:Ke,st===-1?$.length:st);if(B<=ut&&Ke===-1){L($.substring(1,ut)),O(!0),P(!1),D(!1);return}}O(!1);const xe=$.substring(0,B),be=xe.lastIndexOf("#");if(be!==-1){const Ke=be>0?xe[be-1]:null,st=xe.substring(be+1);if((!Ke||/\s/.test(Ke))&&!st.includes(" ")&&!st.includes(`
204
- `)){T(st),D(!0),P(!1);return}}D(!1);const Le=xe.lastIndexOf("@");if(Le!==-1){const Ke=Le>0?xe[Le-1]:null,st=xe.substring(Le+1);(!Ke||/\s/.test(Ke))&&!st.includes(" ")&&!st.includes(`
205
- `)?(k(st),P(!0)):P(!1);return}P(!1)},[]),Ae=$e.useCallback($=>{y(B=>({...B,execution:{...B.execution,prompt:$}}))},[]),Se=$e.useCallback($=>{const B=m.execution.prompt,be=J.current?.selectionStart??B.length,Ke=B.substring(0,be).lastIndexOf("@"),st=$.relativePath&&$.relativePath.trim().length>0?$.relativePath.trim():$.path||$.name,ut=Ke!==-1?Ke:be,mt=`${B.substring(0,ut)}@${st} ${B.substring(be)}`,pt=ut+st.length+2;Ae(mt),P(!1),k(""),requestAnimationFrame(()=>{const ht=J.current;ht&&(ht.selectionStart=pt,ht.selectionEnd=pt,ht.focus()),Ne(mt,pt)})},[m.execution.prompt,Ae,Ne]),le=$e.useCallback($=>{const B=m.execution.prompt,be=J.current?.selectionStart??B.length,Ke=B.substring(0,be).lastIndexOf("@"),st=Ke!==-1?Ke:be,ut=`${B.substring(0,st)}@${$} ${B.substring(be)}`,mt=st+$.length+2;Ae(ut),P(!1),k(""),requestAnimationFrame(()=>{const pt=J.current;pt&&(pt.selectionStart=mt,pt.selectionEnd=mt,pt.focus()),Ne(ut,mt)})},[m.execution.prompt,Ae,Ne]),ee=$e.useCallback($=>{const B=`/${$.name} `;Ae(B),O(!1),L(""),D(!1),requestAnimationFrame(()=>{const xe=J.current;xe&&(xe.focus(),xe.selectionStart=xe.value.length,xe.selectionEnd=xe.value.length),Ne(B,B.length)})},[Ae,Ne]),ie=$e.useCallback(($,B)=>{const xe=m.execution.prompt,Le=J.current?.selectionStart??xe.length,st=xe.substring(0,Le).lastIndexOf("#"),ut=st!==-1?st:Le,mt=`${xe.substring(0,ut)}#${B} ${xe.substring(Le)}`,pt=ut+B.length+2;Ae(mt),D(!1),T(""),requestAnimationFrame(()=>{const ht=J.current;ht&&(ht.selectionStart=pt,ht.selectionEnd=pt,ht.focus()),Ne(mt,pt)})},[m.execution.prompt,Ae,Ne]),ve=$e.useCallback($=>{if(E&&te.current&&($.key==="Enter"||$.key==="ArrowUp"||$.key==="ArrowDown"||$.key==="Escape"||$.key==="Tab")){$.preventDefault(),te.current.handleKeyDown($.key);return}v&&U.current&&($.key==="Enter"||$.key==="ArrowUp"||$.key==="ArrowDown"||$.key==="Escape"||$.key==="Tab")&&($.preventDefault(),U.current.handleKeyDown($.key)),_&&Z.current&&($.key==="Enter"||$.key==="ArrowUp"||$.key==="ArrowDown"||$.key==="Escape"||$.key==="Tab")&&($.preventDefault(),Z.current.handleKeyDown($.key))},[E,v,_]),K=$e.useCallback(async()=>{const $=$2(m,i);if($){fe.error($);return}const B={...m.id?{id:m.id}:{},name:m.name.trim(),enabled:m.enabled,schedule:{kind:m.schedule.kind,timezone:m.schedule.timezone.trim(),...m.schedule.kind==="cron"?{cron:m.schedule.cronExpression.trim()}:m.schedule.kind==="once"?{date:m.schedule.onceDate,time:m.schedule.onceTime}:{times:_2(m.schedule.times),...m.schedule.kind==="weekly"?{weekdays:m.schedule.weekdays}:{}}},execution:{prompt:m.execution.prompt,providerID:m.execution.providerID,modelID:m.execution.modelID,...m.execution.variant.trim()?{variant:m.execution.variant.trim()}:{},...m.execution.agent.trim()?{agent:m.execution.agent.trim()}:{},...m.execution.permissionAutoAccept?{permissionAutoAccept:!0}:{},...m.execution.goalEnabled?{goalEnabled:!0}:{},...m.execution.goalEnabled&&m.execution.goalTokenBudget?{goalTokenBudget:m.execution.goalTokenBudget}:{}},...m.state?{state:m.state}:{}};j(!0);try{await o(B),r(!1)}catch(xe){fe.error(xe instanceof Error?xe.message:i("sessions.scheduledTasks.editor.toast.saveFailed"))}finally{j(!1)}},[m,r,o,i]),de=$e.useId(),_e=$e.useCallback(()=>typeof document>"u"?!1:!!document.querySelector('[data-slot="dropdown-menu-content"][data-open], [data-slot="select-content"][data-open]'),[]),Pe=i(n?"sessions.scheduledTasks.editor.title.edit":"sessions.scheduledTasks.editor.title.new"),re=i("sessions.scheduledTasks.editor.description"),me=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(Cn,{htmlFor:"sched-name",required:!0,children:i("sessions.scheduledTasks.editor.taskName.label")}),s.jsx(or,{id:"sched-name",value:m.name,onChange:$=>y(B=>({...B,name:$.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(Cn,{children:i("sessions.scheduledTasks.editor.scheduleType.label")}),s.jsxs(gn,{value:m.schedule.kind,onValueChange:$=>{y(B=>({...B,schedule:{...B.schedule,kind:$,...$==="cron"&&!B.schedule.cronExpression?{cronExpression:"0 * * * *"}:{}}}))},children:[s.jsx(xn,{size:"lg",className:"w-fit max-w-full",children:s.jsx(sn,{children:$=>i($==="daily"?"sessions.scheduledTasks.editor.scheduleType.daily":$==="weekly"?"sessions.scheduledTasks.editor.scheduleType.weekly":$==="cron"?"sessions.scheduledTasks.editor.scheduleType.cron":"sessions.scheduledTasks.editor.scheduleType.once")})}),s.jsxs(bn,{children:[s.jsx(bs,{value:"daily",children:i("sessions.scheduledTasks.editor.scheduleType.daily")}),s.jsx(bs,{value:"weekly",children:i("sessions.scheduledTasks.editor.scheduleType.weekly")}),s.jsx(bs,{value:"once",children:i("sessions.scheduledTasks.editor.scheduleType.once")}),s.jsx(bs,{value:"cron",children:i("sessions.scheduledTasks.editor.scheduleType.cron")})]})]})]})]}),m.schedule.kind==="cron"?s.jsx(z2,{draft:m,setDraft:y,locale:c,t:i}):m.schedule.kind==="once"?s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[s.jsxs("div",{className:"flex flex-col gap-1",ref:W,children:[s.jsx(Cn,{children:i("sessions.scheduledTasks.editor.date.label")}),s.jsxs("div",{className:"relative",children:[s.jsxs("button",{type:"button",className:De(xa({size:"default"}),"w-fit max-w-full"),onClick:()=>N($=>!$),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:P2(m.schedule.onceDate,i("sessions.scheduledTasks.editor.date.placeholder"),c)})]}),s.jsx(I,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),w?s.jsxs("div",{className:"absolute left-0 top-[calc(100%+6px)] z-50 w-[288px] rounded-xl border border-border bg-background p-3 shadow-sm",children:[s.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover disabled:cursor-not-allowed disabled:opacity-40",onClick:()=>R($=>wu($,-1)),"aria-label":i("sessions.scheduledTasks.editor.date.previousMonth"),disabled:Ue,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(z)}),s.jsx("button",{type:"button",className:"inline-flex h-8 w-8 items-center justify-center rounded-md hover:bg-interactive-hover",onClick:()=>R($=>wu($,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:Me.map(($,B)=>s.jsx("div",{className:"py-1 text-center typography-micro text-muted-foreground",children:$},`${$}-${B}`))}),s.jsx("div",{className:"grid grid-cols-7 gap-1",children:I2(z,G).map(({date:$,inCurrentMonth:B})=>{const xe=yu($),be=xe===m.schedule.onceDate,Le=Nu($,ye),Ke=$.getTime()<ye.getTime(),st=be?"bg-interactive-selection text-interactive-selection-foreground":Ke?"text-muted-foreground/40":B?"text-foreground hover:bg-interactive-hover":"text-muted-foreground/60 hover:bg-interactive-hover";return s.jsx("button",{type:"button",onClick:()=>{Ke||(X(xe),N(!1))},disabled:Ke,className:["h-8 rounded-md typography-ui-label",st,Le&&!be?"ring-1 ring-inset ring-interactive-focusRing bg-interactive-hover/50":"",Ke?"cursor-not-allowed opacity-45":""].join(" "),children:$.getDate()},xe)})}),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:Ee||""}),s.jsx(He,{type:"button",size:"xs",variant:"ghost",onClick:()=>{X(yu(ye)),R(new Date(ye.getFullYear(),ye.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(Cn,{children:i("sessions.scheduledTasks.editor.time.label")}),s.jsx(Su,{value:m.schedule.onceTime,use24Hour:se,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:$=>y(B=>({...B,schedule:{...B.schedule,onceTime:$}}))}),s.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[s.jsx(Cn,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(gn,{value:m.schedule.timezone,onValueChange:$=>{y(B=>({...B,schedule:{...B.schedule,timezone:$}}))},children:[s.jsx(xn,{size:"lg",className:"w-fit max-w-full",children:s.jsx(sn,{})}),s.jsx(bn,{children:Tl.map($=>s.jsx(bs,{value:$,children:$},$))})]})]})]})]}):s.jsxs("div",{className:"grid grid-cols-1 gap-x-4 gap-y-3 sm:grid-cols-2",children:[m.schedule.kind==="weekly"?s.jsxs("div",{className:"flex flex-col gap-1 sm:col-span-2",children:[s.jsx(Cn,{children:i("sessions.scheduledTasks.editor.weekdays.label")}),s.jsx("div",{className:"flex flex-wrap gap-x-3 gap-y-2",children:Ie.map($=>{const B=m.schedule.weekdays.includes($.value);return s.jsxs("div",{className:["group inline-flex items-center gap-1.5 px-0.5 py-0.5 typography-meta",B?"text-foreground":"text-muted-foreground"].join(" "),children:[s.jsx(ao,{checked:B,onChange:xe=>ne($.value,xe),ariaLabel:$.label}),s.jsx("button",{type:"button",onClick:()=>ne($.value,!B),className:"group-hover:text-foreground",children:$.label})]},$.value)})})]}):null,s.jsxs("div",{className:"flex flex-col gap-2",children:[s.jsx(Cn,{children:i("sessions.scheduledTasks.editor.times.label")}),s.jsx("div",{className:"flex flex-col gap-2",children:m.schedule.times.map(($,B)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Su,{value:$,use24Hour:se,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:xe=>oe(B,xe)}),m.schedule.times.length>1?s.jsx(He,{type:"button",size:"icon",variant:"ghost",onClick:()=>ce(B),"aria-label":i("sessions.scheduledTasks.editor.times.removeAria"),children:s.jsx(I,{name:"close",className:"h-4 w-4"})}):null]},B))}),s.jsx("div",{children:s.jsxs(He,{type:"button",size:"sm",variant:"outline",onClick:ke,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(Cn,{children:i("sessions.scheduledTasks.editor.timezone.label")}),s.jsxs(gn,{value:m.schedule.timezone,onValueChange:$=>{y(B=>({...B,schedule:{...B.schedule,timezone:$}}))},children:[s.jsx(xn,{size:"lg",className:"w-fit max-w-full",children:s.jsx(sn,{})}),s.jsx(bn,{children:Tl.map($=>s.jsx(bs,{value:$,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 min-w-0 flex-col gap-1",children:[s.jsx(Cn,{required:!0,children:i("sessions.scheduledTasks.editor.model.label")}),s.jsx(Hl,{providerId:m.execution.providerID,modelId:m.execution.modelID,onChange:($,B)=>{y(xe=>({...xe,execution:{...xe.execution,providerID:$,modelID:B,variant:""}}))}})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Cn,{children:i("sessions.scheduledTasks.editor.thinkingLevel.label")}),s.jsxs(gn,{value:Q,disabled:!V,onValueChange:$=>{y(B=>({...B,execution:{...B.execution,variant:$==="__default"?"":$}}))},children:[s.jsx(xn,{size:"lg",className:"w-fit max-w-full",children:s.jsx(sn,{children:$=>$==="__default"?i("sessions.scheduledTasks.editor.thinkingLevel.default"):$})}),s.jsxs(bn,{children:[s.jsx(bs,{value:"__default",children:i("sessions.scheduledTasks.editor.thinkingLevel.default")}),pe.map($=>s.jsx(bs,{value:$,children:$},$))]})]})]})]}),s.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[s.jsx(Cn,{children:i("sessions.scheduledTasks.editor.agent.label")}),s.jsx(xg,{agentName:m.execution.agent,filter:$=>hf($.mode),onChange:$=>y(B=>({...B,execution:{...B.execution,agent:$}}))})]}),s.jsxs("div",{className:"flex flex-col gap-1",children:[s.jsx(Cn,{htmlFor:"sched-prompt",required:!0,children:i("sessions.scheduledTasks.editor.prompt.label")}),s.jsxs("div",{className:"relative",children:[s.jsx(wo,{id:"sched-prompt",ref:J,value:m.execution.prompt,onChange:$=>{const B=$.target.value;Ae(B);const xe=$.target.selectionStart??B.length;Ne(B,xe)},onKeyDown:ve,rows:8,placeholder:i("sessions.scheduledTasks.editor.prompt.placeholder"),className:"typography-meta min-h-[120px] max-h-[300px] resize-none overflow-y-auto"}),E?s.jsx(bf,{ref:te,searchQuery:M,onCommandSelect:ee,onClose:()=>O(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,v?s.jsx(yf,{ref:U,searchQuery:F,onFileSelect:Se,onAgentSelect:le,onClose:()=>P(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,_?s.jsx(wf,{ref:Z,searchQuery:A,onSnippetSelect:ie,onClose:()=>D(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null]})]}),m.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(ao,{checked:m.execution.goalTokenBudget!==null,onChange:$=>y(B=>({...B,execution:{...B.execution,goalTokenBudget:$?2e5:null}})),ariaLabel:i("sessions.scheduledTasks.editor.goal.budgetAria")}),s.jsx("span",{className:"typography-meta",children:i("sessions.scheduledTasks.editor.goal.budgetLabel")})]}),m.execution.goalTokenBudget!==null?s.jsx(bg,{value:m.execution.goalTokenBudget,onValueChange:$=>{typeof $=="number"&&Number.isFinite($)&&$>0&&y(B=>({...B,execution:{...B.execution,goalTokenBudget:Math.floor($)}}))},min:1e3,max:1e8,step:5e4}):null]}):null]}),ge=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(ao,{checked:m.enabled,onChange:$=>y(B=>({...B,enabled:$})),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(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",className:De(xu),onClick:()=>y($=>({...$,execution:{...$.execution,permissionAutoAccept:!$.execution.permissionAutoAccept}})),"aria-pressed":m.execution.permissionAutoAccept,"aria-label":i("sessions.scheduledTasks.editor.permissionAutoAccept.aria"),children:m.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(At,{side:"top",sideOffset:6,children:i("sessions.scheduledTasks.editor.permissionAutoAccept.label")})]}),s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",className:De(xu,m.execution.goalEnabled&&"text-[var(--status-info)]"),onClick:()=>y($=>({...$,execution:{...$.execution,goalEnabled:!$.execution.goalEnabled}})),"aria-pressed":m.execution.goalEnabled,"aria-label":i("sessions.scheduledTasks.editor.goal.aria"),children:m.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(At,{side:"top",sideOffset:6,children:i("sessions.scheduledTasks.editor.goal.label")})]}),s.jsx(He,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!1),disabled:C,children:i("sessions.scheduledTasks.editor.actions.cancel")}),s.jsx(He,{type:"button",size:"sm",onClick:K,disabled:C,children:i(C?"sessions.scheduledTasks.editor.actions.saving":"sessions.scheduledTasks.editor.actions.save")})]})]});return g?s.jsx(ka,{open:e,title:Pe,onClose:()=>r(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:$=>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:Pe}),$]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:re})]}),footer:ge,children:me}):s.jsx(Ts,{open:e,onOpenChange:$=>{!$&&_e()||r($)},children:s.jsxs(Es,{"aria-describedby":de,className:"!max-w-[720px] w-[90vw] h-[680px] max-h-[85vh] gap-0 p-0 overflow-hidden",children:[s.jsx(Ks,{id:de,className:"sr-only",children:re}),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($s,{className:"typography-ui-label font-medium text-foreground",children:Pe}),s.jsx("p",{className:"typography-meta mt-0.5 text-muted-foreground",children:re})]})}),s.jsx(Sa,{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:me})}),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:ge})})]})})}function W2(t){return zo(t,{min:0,max:23})}function U2(t,e){return zo(String(Number.parseInt(t,10)+e),{min:0,max:23,loop:!0})}function H2(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 K2(t){return s.jsx(bs,{value:t,children:t},t)}const G2=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))},q2=(t,e)=>{const n=G2(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:io(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:io(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:io(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:io(t.schedule.timezone)}):e("sessions.scheduledTasks.dialog.schedule.cron",{cron:t.schedule.cron||""})},Y2=(t,e)=>!t||!Number.isFinite(t)?"":ef(t,e),Au=(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,l=n>=0;if(r<o)return e(l?"sessions.scheduledTasks.dialog.relativeTime.inLessThanOneMinute":"sessions.scheduledTasks.dialog.relativeTime.justNow");if(r<i){const f=Math.round(r/o);return l?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),x=p>0?`${f}h ${p}m`:`${f}h`;return l?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:x}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:x})}const d=Math.floor(r/c),u=Math.round(r%c/i),h=u>0?`${d}d ${u}h`:`${d}d`;return l?e("sessions.scheduledTasks.dialog.relativeTime.inDuration",{duration:h}):e("sessions.scheduledTasks.dialog.relativeTime.durationAgo",{duration:h})},Q2={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"}},X2=t=>({color:`var(--status-${t})`,backgroundColor:`var(--status-${t}-background)`,borderColor:`var(--status-${t}-border)`});function Du(){const{t}=ft(),e=Re(A=>A.isScheduledTasksDialogOpen),n=Re(A=>A.setScheduledTasksDialogOpen),r=Re(A=>A.isMobile),o=Re(A=>A.timeFormatPreference),i=ms(A=>A.projects),c=ms(A=>A.getActiveProject()),l=js(A=>A.homeDirectory),{currentTheme:d}=co(),[u,h]=$e.useState(""),[f,p]=$e.useState([]),[x,b]=$e.useState(!0),[S,g]=$e.useState(!1),[m,y]=$e.useState(null),[C,j]=$e.useState(null),w=$e.useMemo(()=>i.find(A=>A.id===u)||null,[i,u]),N=$e.useCallback(A=>{const T=A.label?.trim()||Vr(A.path,l||void 0),z=A.icon?Yl[A.icon]:null,R=A.color?Ql[A.color]:void 0,W=z?s.jsx(I,{name:z,className:"h-3.5 w-3.5 shrink-0",style:R?{color:R}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:R?{color:R}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[A.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:A.iconBackground?{backgroundColor:A.iconBackground}:void 0,children:s.jsx(Xl,{project:{id:A.id,iconImage:A.iconImage??null},options:{themeVariant:d.metadata.variant,iconColor:d.colors.surface.foreground},className:"h-full w-full object-contain",fallback:W})}):W,s.jsx("span",{className:"truncate",children:T})]})},[l,d.metadata.variant,d.colors.surface.foreground]),v=$e.useCallback(async(A,T)=>{if(!A){p([]);return}T?.silent||b(!0);try{const z=await S2(A);z.sort((R,W)=>{if(R.enabled!==W.enabled)return R.enabled?-1:1;const J=R.name.localeCompare(W.name);return J!==0?J:(R.state?.nextRunAt||Number.MAX_SAFE_INTEGER)-(W.state?.nextRunAt||Number.MAX_SAFE_INTEGER)}),p(z)}catch(z){fe.error(z instanceof Error?z.message:t("sessions.scheduledTasks.dialog.toast.loadFailed")),T?.silent||p([])}finally{T?.silent||b(!1)}},[t]);$e.useEffect(()=>{if(!e)return;const A=c?.id||i[0]?.id||"";h(A),A?v(A):(p([]),b(!1))},[e,c,i,v]),$e.useEffect(()=>{if(!e)return;let A=null;const T=_m(z=>{z.type==="scheduled-task-ran"&&z.projectId===u&&(A&&clearTimeout(A),A=setTimeout(()=>{v(u,{silent:!0})},400))});return()=>{A&&clearTimeout(A),T()}},[e,u,v]);const P=$e.useCallback(async A=>{if(!u)throw new Error(t("sessions.scheduledTasks.dialog.error.chooseProjectFirst"));await gu(u,A),await v(u),fe.success(t("sessions.scheduledTasks.dialog.toast.saved"))},[u,v,t]),F=$e.useCallback(async(A,T)=>{if(u){j(A.id),p(z=>z.map(R=>R.id===A.id?{...R,enabled:T}:R));try{await gu(u,{...A,enabled:T}),await v(u,{silent:!0})}catch(z){fe.error(z instanceof Error?z.message:t("sessions.scheduledTasks.dialog.toast.updateFailed")),await v(u,{silent:!0})}finally{j(null)}}},[u,v,t]),k=$e.useCallback(async A=>{if(!(!u||!window.confirm(t("sessions.scheduledTasks.dialog.confirm.deleteTask",{taskName:A.name})))){j(A.id);try{await k2(u,A.id),await v(u,{silent:!0}),fe.success(t("sessions.scheduledTasks.dialog.toast.deleted"))}catch(z){fe.error(z instanceof Error?z.message:t("sessions.scheduledTasks.dialog.toast.deleteFailed"))}finally{j(null)}}},[u,v,t]),E=$e.useCallback(async A=>{if(u){j(A.id);try{const{sessionId:T}=await N2(u,A.id);if(await Promise.all([v(u,{silent:!0}),ea()]),fe.success(t("sessions.scheduledTasks.dialog.toast.started")),T){const z=i.find(R=>R.id===u);et.getState().setCurrentSession(T,z?.path??null),Re.getState().setActiveMainTab("chat")}}catch(T){fe.error(T instanceof Error?T.message:t("sessions.scheduledTasks.dialog.toast.runFailed"))}finally{j(null)}}},[u,i,v,t]),O=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(gn,{value:u||"__none",onValueChange:A=>{const T=A==="__none"?"":A;h(T),T?v(T):p([])},children:[s.jsx(xn,{size:"lg",className:r?"w-full":void 0,children:w?s.jsx(sn,{children:N(w)}):s.jsx(sn,{placeholder:t("sessions.scheduledTasks.dialog.project.placeholder")})}),s.jsxs(bn,{children:[i.length===0?s.jsx(bs,{value:"__none",children:t("sessions.scheduledTasks.dialog.project.empty")}):null,i.map(A=>s.jsx(bs,{value:A.id,children:N(A)},A.id))]})]})]}),M=()=>{y(null),g(!0)},L=A=>{h(A),A?v(A):p([])},_=s.jsx("div",{className:"min-h-[280px]",children:x?s.jsxs("div",{className:"flex items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx(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(A=>{const T=C===A.id,z=A.state?.lastStatus||"idle",R=Q2[z],W=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"),J=A.state?.nextRunAt,U=A.state?.lastRunAt;return s.jsxs("div",{className:De("rounded-lg border border-border p-4 transition-opacity",!A.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:A.name}),s.jsx("div",{className:"typography-micro truncate text-muted-foreground",children:q2(A,t)})]}),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")}),J?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"text-foreground",children:Au(J,t)}),s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:Y2(J,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")]}):U?s.jsxs(s.Fragment,{children:[R.tone!=="muted"?s.jsxs("span",{className:"inline-flex items-center gap-1",style:{color:`var(--status-${R.tone})`},children:[s.jsx(I,{name:R.Icon,className:"h-3.5 w-3.5"}),W]}):null,s.jsx("span",{className:"text-muted-foreground/50",children:"·"}),s.jsx("span",{children:Au(U,t)})]}):s.jsx("span",{children:t("sessions.scheduledTasks.dialog.lastRun.never")})]})]}),A.state?.lastError?s.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-md border p-2 typography-micro",style:X2("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:A.state.lastError})]}):null,s.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-between gap-2",children:[s.jsxs("label",{className:De("inline-flex cursor-pointer items-center gap-2 typography-micro font-medium",A.enabled?"text-foreground":"text-muted-foreground",T&&"cursor-not-allowed opacity-50"),children:[s.jsx(ao,{checked:A.enabled,onChange:te=>{F(A,te)},ariaLabel:A.enabled?t("sessions.scheduledTasks.dialog.taskToggle.pauseAria",{taskName:A.name}):t("sessions.scheduledTasks.dialog.taskToggle.enableAria",{taskName:A.name}),disabled:T}),A.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(He,{variant:"outline",size:"sm",onClick:()=>{E(A)},disabled:T,children:[s.jsx(I,{name:"play",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.runNow")]}),s.jsxs(He,{variant:"outline",size:"sm",onClick:()=>{y(A),g(!0)},disabled:T,"aria-label":t("sessions.scheduledTasks.dialog.actions.editAria",{taskName:A.name}),children:[s.jsx(I,{name:"edit-2",className:"h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.edit")]}),s.jsx(He,{variant:"destructive",size:"sm",onClick:()=>{k(A)},disabled:T,"aria-label":t("sessions.scheduledTasks.dialog.actions.deleteAria",{taskName:A.name}),children:s.jsx(I,{name:"delete-bin",className:"h-4 w-4"})})]})]})]},A.id)})})}),D=s.jsxs("div",{className:"space-y-4",children:[O,_]});return s.jsxs(s.Fragment,{children:[r?s.jsx(ka,{open:e,title:t("sessions.scheduledTasks.dialog.title"),onClose:()=>n(!1),contentMaxHeightClassName:"max-h-[min(80vh,640px)]",renderHeader:A=>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")}),A]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("sessions.scheduledTasks.dialog.description")})]}),footer:s.jsxs(He,{className:"w-full",onClick:M,disabled:!u,children:[s.jsx(I,{name:"add",className:"mr-1 h-4 w-4"})," ",t("sessions.scheduledTasks.dialog.actions.newTask")]}),children:D}):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(A=>s.jsx("button",{type:"button",onClick:()=>L(A.id),className:De("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===A.id?"bg-interactive-selection text-foreground":"text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground"),children:N(A)},A.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(He,{size:"sm",onClick:M,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:_})})]})]})}):null,s.jsx(V2,{open:S,task:m,onOpenChange:g,onSave:P})]})}const qi=100;function Pu(){const t=nt.c(101),{t:e}=ft(),n=Re(oN),r=Re(rN),o=Re(nN),i=et(sN),c=js(tN);let l;t[0]!==n?(l=U=>n?U.archivedSessions:[],t[0]=n,t[1]=l):l=t[1];const d=pn(nr(l)),[u,h]=a.useState(""),[f,p]=a.useState(null),[x,b]=a.useState(qi);let S;t[2]!==u?(S=u.trim().toLowerCase(),t[2]=u,t[3]=S):S=t[3];const g=S;let m;e:{if(!n){let te;t[4]===Symbol.for("react.memo_cache_sentinel")?(te=[],t[4]=te):te=t[4],m=te;break e}let U;t[5]!==d?(U=[...d].sort(eN),t[5]=d,t[6]=U):U=t[6],m=U}const y=m;let C;if(t[7]!==c||t[8]!==y||t[9]!==e){const U=new Map;for(const te of y){const Z=Vt(Bn(te))??"",ue=U.get(Z);if(ue){ue.sessions.push(te);continue}U.set(Z,{directory:Z,label:Z?Vr(Z,c)||Z:e("sessions.archivePage.otherProjects"),sessions:[te]})}C=[...U.values()].sort(Z2),t[7]=c,t[8]=y,t[9]=e,t[10]=C}else C=t[10];const j=C;let w;e:{if(g){let te;if(t[11]!==g||t[12]!==y){let Z;t[14]!==g?(Z=ue=>(ue.title??"").toLowerCase().includes(g),t[14]=g,t[15]=Z):Z=t[15],te=y.filter(Z),t[11]=g,t[12]=y,t[13]=te}else te=t[13];w=te;break e}if(f===null){w=y;break e}let U;t[16]!==j||t[17]!==f?(U=j.find(te=>te.directory===f)?.sessions??[],t[16]=j,t[17]=f,t[18]=U):U=t[18],w=U}const N=w;let v,P,F,k,E,O,M,L,_,D;if(t[19]!==d.length||t[20]!==j||t[21]!==N||t[22]!==c||t[23]!==g||t[24]!==n||t[25]!==u||t[26]!==f||t[27]!==o||t[28]!==i||t[29]!==r||t[30]!==e||t[31]!==x){E=Symbol.for("react.early_return_sentinel");e:{const U=N.slice(0,x);v=N.length-U.length;const te=d.length;let Z;t[42]===Symbol.for("react.memo_cache_sentinel")?(Z=he=>{p(he),b(qi)},t[42]=Z):Z=t[42];const ue=Z;let Oe;t[43]!==o||t[44]!==i||t[45]!==r?(Oe=he=>{const Ee=Vt(Bn(he));i(he.id,Ee??void 0),o("chat"),r(!1)},t[43]=o,t[44]=i,t[45]=r,t[46]=Oe):Oe=t[46];const se=Oe;if(!n){E=null;break e}let G;t[47]!==e?(G=(he,Ee,Ue,Me,X,Ne,Ae)=>s.jsxs("div",{className:"group/dir relative",children:[s.jsxs("button",{type:"button",onClick:X,title:Ne,className:De("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",Ae?"group-hover/dir:pr-8 group-focus-within/dir:pr-8":"",Me?"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:Ee}),s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground/70",children:Ue})]}),Ae?s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx("button",{type:"button",onClick:()=>Kn.requestDelete({sessions:Ae,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:Ee}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})}),s.jsx(At,{side:"bottom",sideOffset:4,children:e("sessions.archivePage.deleteProject")})]}):null]},he),t[47]=e,t[48]=G):G=t[48];const Ie=G;k="absolute inset-0 z-10 flex flex-col bg-background",P="flex min-h-0 flex-1";let pe;if(t[49]!==Ie||t[50]!==f||t[51]!==e||t[52]!==te){let he;t[54]===Symbol.for("react.memo_cache_sentinel")?(he=()=>ue(null),t[54]=he):he=t[54],pe=Ie("__all__",e("sessions.archivePage.allDirectories"),te,f===null,he),t[49]=Ie,t[50]=f,t[51]=e,t[52]=te,t[53]=pe}else pe=t[53];let V;if(t[55]!==j||t[56]!==Ie||t[57]!==f){let he;t[59]!==Ie||t[60]!==f?(he=Ee=>Ie(Ee.directory||"__none__",Ee.label,Ee.sessions.length,f===Ee.directory,()=>ue(Ee.directory),Ee.directory||void 0,Ee.sessions),t[59]=Ie,t[60]=f,t[61]=he):he=t[61],V=j.map(he),t[55]=j,t[56]=Ie,t[57]=f,t[58]=V}else V=t[58];t[62]!==pe||t[63]!==V?(F=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,V]})}),t[62]=pe,t[63]=V,t[64]=F):F=t[64],_="flex min-w-0 flex-1 flex-col";let Q;t[65]===Symbol.for("react.memo_cache_sentinel")?(Q=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[65]=Q):Q=t[65];let ne;t[66]===Symbol.for("react.memo_cache_sentinel")?(ne=he=>{h(he.target.value),b(qi)},t[66]=ne):ne=t[66];let oe;t[67]!==e?(oe=e("sessions.archivePage.searchPlaceholder"),t[67]=e,t[68]=oe):oe=t[68];let ce;t[69]!==u||t[70]!==oe?(ce=s.jsxs("div",{className:"relative min-w-0 flex-1",children:[Q,s.jsx("input",{value:u,onChange:ne,placeholder:oe,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[69]=u,t[70]=oe,t[71]=ce):ce=t[71];let ke;t[72]!==N.length||t[73]!==e?(ke=N.length===1?e("sessions.archivePage.countSingle",{count:N.length}):e("sessions.archivePage.countPlural",{count:N.length}),t[72]=N.length,t[73]=e,t[74]=ke):ke=t[74];let ye;t[75]!==ke?(ye=s.jsx("span",{className:"flex-shrink-0 typography-micro text-muted-foreground",children:ke}),t[75]=ke,t[76]=ye):ye=t[76],t[77]!==ce||t[78]!==ye?(D=s.jsxs("div",{className:"flex items-center gap-3 px-6 pt-3",children:[ce,ye]}),t[77]=ce,t[78]=ye,t[79]=D):D=t[79],L="min-h-0 flex-1 overflow-y-auto px-6 py-3",O="mx-auto w-full max-w-3xl space-y-0.5",M=U.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(g?"sessions.archivePage.empty.noMatches":"sessions.archivePage.empty.noArchived")})}):U.map(he=>{const Ee=Vt(Bn(he))??"",Ue=Ee?Vr(Ee,c)||Ee: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-8 focus-within:pr-8",onClick:()=>se(he),role:"button",tabIndex:0,onKeyDown:Me=>{(Me.key==="Enter"||Me.key===" ")&&(Me.preventDefault(),se(he))},children:[s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",children:he.title||e("sessions.sidebar.session.untitled")}),g&&Ue?s.jsx("span",{className:"max-w-40 flex-shrink-0 truncate text-[0.72rem] text-muted-foreground/70",title:Ee,children:Ue}):null,s.jsx("span",{className:"flex-shrink-0 text-[0.72rem] text-muted-foreground/75",children:gf(he.time?.archived??he.time?.updated??he.time?.created??Date.now())}),s.jsx("button",{type:"button",onClick:Me=>{Me.stopPropagation(),Kn.requestDelete({sessions:[he],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:he.title||e("sessions.sidebar.session.untitled")}),children:s.jsx(I,{name:"delete-bin",className:"h-3.5 w-3.5"})})]},he.id)})}t[19]=d.length,t[20]=j,t[21]=N,t[22]=c,t[23]=g,t[24]=n,t[25]=u,t[26]=f,t[27]=o,t[28]=i,t[29]=r,t[30]=e,t[31]=x,t[32]=v,t[33]=P,t[34]=F,t[35]=k,t[36]=E,t[37]=O,t[38]=M,t[39]=L,t[40]=_,t[41]=D}else v=t[32],P=t[33],F=t[34],k=t[35],E=t[36],O=t[37],M=t[38],L=t[39],_=t[40],D=t[41];if(E!==Symbol.for("react.early_return_sentinel"))return E;let A;t[80]!==v||t[81]!==e?(A=v>0?s.jsx("button",{type:"button",onClick:()=>b(J2),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[80]=v,t[81]=e,t[82]=A):A=t[82];let T;t[83]!==A||t[84]!==O||t[85]!==M?(T=s.jsxs("div",{className:O,children:[M,A]}),t[83]=A,t[84]=O,t[85]=M,t[86]=T):T=t[86];let z;t[87]!==T||t[88]!==L?(z=s.jsx("div",{className:L,children:T}),t[87]=T,t[88]=L,t[89]=z):z=t[89];let R;t[90]!==z||t[91]!==_||t[92]!==D?(R=s.jsxs("div",{className:_,children:[D,z]}),t[90]=z,t[91]=_,t[92]=D,t[93]=R):R=t[93];let W;t[94]!==P||t[95]!==F||t[96]!==R?(W=s.jsxs("div",{className:P,children:[F,R]}),t[94]=P,t[95]=F,t[96]=R,t[97]=W):W=t[97];let J;return t[98]!==k||t[99]!==W?(J=s.jsx("div",{className:k,children:W}),t[98]=k,t[99]=W,t[100]=J):J=t[100],J}function J2(t){return t+qi}function Z2(t,e){return e.sessions.length-t.sessions.length}function eN(t,e){return(e.time?.archived??0)-(t.time?.archived??0)}function tN(t){return t.homeDirectory}function sN(t){return t.setCurrentSession}function nN(t){return t.setActiveMainTab}function rN(t){return t.setArchivePageOpen}function oN(t){return t.isArchivePageOpen}function Iu(){const t=nt.c(18),{t:e}=ft(),n=Re(lN),r=Re(aN),o=ms(iN);let i;t[0]!==n?(i=x=>x.projects.find(b=>b.id===n)??null,t[0]=n,t[1]=i):i=t[1];const c=ms(i);if(!n||!c)return null;let l;t[2]!==c.id||t[3]!==o||t[4]!==r?(l=()=>{o(c.id),r(!0)},t[2]=c.id,t[3]=o,t[4]=r,t[5]=l):l=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 h;t[9]!==l||t[10]!==u?(h=s.jsx("div",{className:"flex items-center",children:s.jsxs(He,{size:"sm",onClick:l,children:[d,u]})}),t[9]=l,t[10]=u,t[11]=h):h=t[11];let f;t[12]!==c.id||t[13]!==c.path?(f=s.jsx(xx,{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]!==h||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:[h,f]})})}),t[15]=h,t[16]=f,t[17]=p):p=t[17],p}function iN(t){return t.setActiveProjectIdOnly}function aN(t){return t.setNewWorktreeDialogOpen}function lN(t){return t.worktreesPageProjectId}const El=t=>t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").substring(0,50),cN=(t,e)=>{const n=El(t),r=El(e);return`${n}-${r}`.substring(0,60)},Ru=(t,e)=>`${t}/${e}`,dN=t=>{const e=t.replace(/\\/g,"/");return e==="/"?"/":e.length>1?e.replace(/\/+$/,""):e},Mu=(t,e)=>{const n=dN(e),r=t.directory,o=typeof r=="string"&&r.trim().length>0?t:{...t,directory:n};Cg(t.id,n),et.getState().markSessionAsOpenChamberCreated(t.id),pn.getState().upsertSession(o);try{ta().ensureChild(n,{bootstrap:!1}).setState(c=>{const l=c.session.findIndex(u=>u.id===t.id);if(l>=0&&c.session[l]===o)return c;const d=l>=0?c.session.map((u,h)=>h===l?o:u):[...c.session,o].sort((u,h)=>u.id.localeCompare(h.id));return{session:d,sessionTotal:Math.max(c.sessionTotal,d.length),limit:Math.max(c.limit,d.length)}})}catch{}return o},uN=()=>{const t=ms.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=js.getState().currentDirectory??null;if(r&&r.trim().length>0){const o=r.replace(/\\/g,"/").replace(/\/+$/,"")||r;return{id:`path:${o}`,path:o}}return null},il=$o()(_f(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 l=0;l<r.length;l++){if(!r[l].prompt.trim())return t({error:`Group ${l+1}: prompt is required`}),null;if(r[l].models.length<1)return t({error:`Group ${l+1}: select at least 1 model`}),null;if(r[l].models.length>5)return t({error:`Group ${l+1}: maximum 5 models allowed`}),null}t({isLoading:!0,error:null});try{const l=uN();if(!l)return t({error:"Select a project",isLoading:!1}),null;const d=l.path,h=await xf(d)&&e.isolateRuns!==!1,f=El(n),p=h?await pi(d):void 0,x=h?await yg(d):null,b=[],S=c?.filter(j=>j.trim().length>0)??[];for(let j=0;j<r.length;j++){const w=r[j],N=w.prompt,v=new Map;for(const F of w.models){const k=`${F.providerID}:${F.modelID}`;v.set(k,(v.get(k)||0)+1)}const P=new Map;for(const F of w.models){const k=`${F.providerID}:${F.modelID}`,E=v.get(k)||1,O=(P.get(k)||0)+1;P.set(k,O);const M=cN(F.providerID,F.modelID),L=r.length>1?`g${j+1}`:void 0,_=E>1?Ru(f,`${M}/${O}`):Ru(f,M),D=L?`${L}/${_}`:_,A=jk({groupSlug:f,runGroup:L,providerID:F.providerID,modelID:F.modelID,index:E>1?O:void 0});try{if(!h){const W=await Fn.withDirectory(d,()=>Fn.createSession({title:A}));Mu(W,d),b.push({sessionId:W.id,worktreePath:d,providerID:F.providerID,modelID:F.modelID,variant:F.variant,prompt:N});continue}const T=await wg(l,{preferredName:D,mode:"new",branchName:D,worktreeName:D,startRef:e.worktreeBaseBranch||"HEAD",setupCommands:S,returnAfterDirectoryCreated:!0},{resolvedRootTrackingRemote:x}),z={...T,createdFromBranch:p,kind:"standard"};await vg(l)&&await jg(T.path);const R=await Fn.withDirectory(T.path,()=>Fn.createSession({title:A}));Mu(R,T.path),et.getState().setWorktreeMetadata(R.id,z),b.push({sessionId:R.id,worktreePath:T.path,providerID:F.providerID,modelID:F.modelID,variant:F.variant,prompt:N})}catch(T){console.warn("[MultiRun] Failed to create session:",T)}}}const g=c?.filter(j=>j.trim().length>0)??[];g.length>0&&Sg(l,g).catch(()=>{console.warn("[MultiRun] Failed to save worktree setup commands")});const m=b.map(j=>j.sessionId),y=b[0]?.sessionId??null;if(m.length===0)return t({error:"Failed to create any sessions",isLoading:!1}),null;const C=i?.map(j=>({type:"file",mime:j.mime,filename:j.filename,url:j.url}));return(async()=>{try{const j=kg.getState().expandText;await Promise.allSettled(b.map(async w=>{try{const N=await j(w.prompt).catch(()=>w.prompt);await Ng({sessionId:w.sessionId,directory:w.worktreePath,content:N,providerID:w.providerID,modelID:w.modelID,variant:w.variant,agent:o,files:C})}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:m,firstSessionId:y}}catch(l){return t({error:l instanceof Error?l.message:"Failed to create Multi-Run",isLoading:!1}),null}},clearError:()=>{t({error:null})}}),{name:"multirun-store"}));function Wm(t){const e=nt.c(30),{git:n}=_n(),r=ja(t),o=Vl(t),i=Wl(t),c=Ag(t),l=tn(gN),d=tn(pN);let u,h;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})},h=[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]=h):(u=e[5],h=e[6]),a.useEffect(u,h);let f;e[7]!==r?.all||e[8]!==t||e[9]!==l||e[10]!==n||e[11]!==o?(f=()=>{!t||!n||o===!0&&(r?.all||l(t,n))},e[7]=r?.all,e[8]=t,e[9]=l,e[10]=n,e[11]=o,e[12]=f):f=e[12];const p=r?.all;let x;e[13]!==t||e[14]!==l||e[15]!==n||e[16]!==o||e[17]!==p?(x=[t,n,o,p,l],e[13]=t,e[14]=l,e[15]=n,e[16]=o,e[17]=p,e[18]=x):x=e[18],a.useEffect(f,x);const b=i||o===!0&&c;let S;e:{if(!r?.all){let v;e[19]===Symbol.for("react.memo_cache_sentinel")?(v=[],e[19]=v):v=e[19],S=v;break e}let N;e[20]!==r.all?(N=r.all.filter(hN).sort(),e[20]=r.all,e[21]=N):N=e[21],S=N}const g=S;let m;e:{if(!r?.all){let v;e[22]===Symbol.for("react.memo_cache_sentinel")?(v=[],e[22]=v):v=e[22],m=v;break e}let N;e[23]!==r.all?(N=r.all.filter(mN).map(fN).sort(),e[23]=r.all,e[24]=N):N=e[24],m=N}const y=m;let C;e:{if(!t){C=null;break e}if(o!==null){C=o;break e}if(b){C=null;break e}C=r?.all?!0:null}const j=C;let w;return e[25]!==j||e[26]!==b||e[27]!==g||e[28]!==y?(w={localBranches:g,remoteBranches:y,isLoading:b,isGitRepository:j},e[25]=j,e[26]=b,e[27]=g,e[28]=y,e[29]=w):w=e[29],w}function fN(t){return t.replace(/^remotes\//,"")}function mN(t){return t.startsWith("remotes/")}function hN(t){return!t.startsWith("remotes/")}function pN(t){return t.fetchStatus}function gN(t){return t.fetchBranches}const xN=({directory:t,value:e,onChange:n,className:r,disabled:o,id:i})=>{const{t:c}=ft(),{localBranches:l,remoteBranches:d,isLoading:u,isGitRepository:h}=Wm(t),f=a.useMemo(()=>[...l,...d.map(x=>`remotes/${x}`)],[l,d]);a.useEffect(()=>{if(o||u||f.length===0||e&&f.includes(e))return;const x=e;let b=!1;return(async()=>{try{const g=t?await pi(t).catch(()=>null):null;if(b)return;const m=localStorage.getItem(Kc),{sourceBranch:y,shouldClearSavedSourceBranch:C}=bx({branches:f,savedSourceBranch:m,rootBranch:g});if(C&&localStorage.removeItem(Kc),b||x&&f.includes(x))return;y&&n(y)}catch{}})(),()=>{b=!0}},[f,t,o,u,n,e]);const p=o||!h||u;return s.jsxs("div",{children:[s.jsxs(gn,{value:e,onValueChange:n,disabled:p,children:[s.jsx(xn,{id:i,size:"lg",className:De("min-w-0 max-w-full *:data-[slot=select-value]:truncate",r??"w-fit"),children:s.jsx(sn,{placeholder:c(u?"multiRun.branchSelector.status.loadingBranches":"multiRun.branchSelector.placeholder.selectSourceBranch")})}),s.jsx(bn,{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")}):l.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:[l.length>0&&s.jsxs(hl,{children:[s.jsx($c,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.localBranches")}),l.map(x=>s.jsx(bs,{value:x,className:"whitespace-normal break-all",children:x},x))]}),l.length>0&&d.length>0&&s.jsx(Dg,{}),d.length>0&&s.jsxs(hl,{children:[s.jsx($c,{className:"font-semibold text-foreground",children:c("multiRun.branchSelector.groups.remoteBranches")}),d.map(x=>s.jsx(bs,{value:`remotes/${x}`,className:"whitespace-normal break-all",children:x},`remotes/${x}`))]})]})})]}),h===!1&&s.jsx("p",{className:"typography-micro text-muted-foreground/70 mt-2",children:c("multiRun.branchSelector.status.notInGitRepository")})]})},bN=10*1024*1024,al=5,Yi=t=>{const e=nt.c(3),{children:n}=t;let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=s.jsx(Ct,{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(Nt,{children:[r,s.jsx(At,{side:"top",className:"max-w-[240px]",children:n})]}),e[1]=n,e[2]=o):o=e[2],o},no=t=>{const e=nt.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 l;e[2]!==o||e[3]!==n||e[4]!==c?(l=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]=l):l=e[5];const d=i&&i;let u;return e[6]!==l||e[7]!==d?(u=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,d]}),e[6]=l,e[7]=d,e[8]=u):u=e[8],u},Tu=({initialPrompt:t,onCreated:e,onCancel:n,isWindowed:r=!1})=>{const{t:o}=ft(),[i,c]=a.useState(""),[l,d]=a.useState(()=>[{id:oi(),prompt:"",models:[]}]),[u,h]=a.useState(""),[f,p]=a.useState([]),[x,b]=a.useState(!1),[S,g]=a.useState([]),[m,y]=a.useState(!1),[C,j]=a.useState(!1),[w,N]=a.useState(!0),v=a.useRef(null),P=js(ee=>ee.currentDirectory??null),F=js(ee=>ee.homeDirectory??null),k=a.useMemo(()=>{if(typeof window>"u")return null;const ee=window.__VSCODE_CONFIG__?.workspaceFolder;return typeof ee=="string"&&ee.trim().length>0?ee.trim():null},[]),E=ms(ee=>ee.activeProjectId),O=ms(ee=>ee.setActiveProjectIdOnly),M=ms(ee=>ee.projects),[L,_]=a.useState(()=>E??null);a.useEffect(()=>{if(E){_(E);return}!L&&M.length>0&&_(M[0].id)},[E,M,L]);const D=a.useMemo(()=>L?M.find(ee=>ee.id===L)??null:null,[M,L]),A=D?.path??P,T=a.useCallback(ee=>{_(ee),ee!==E&&O(ee)},[E,O]),{currentTheme:z}=co(),R=a.useCallback(ee=>{const ie=ee.label?.trim()||Vr(ee.path,F),ve=ee.icon?Yl[ee.icon]:null,K=ee.color?Ql[ee.color]:void 0,de=ve?s.jsx(I,{name:ve,className:"h-3.5 w-3.5 shrink-0",style:K?{color:K}:void 0}):s.jsx(I,{name:"folder",className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/80",style:K?{color:K}:void 0});return s.jsxs("span",{className:"inline-flex min-w-0 items-center gap-1.5",children:[ee.iconImage?s.jsx("span",{className:"inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center overflow-hidden rounded-[3px]",style:ee.iconBackground?{backgroundColor:ee.iconBackground}:void 0,children:s.jsx(Xl,{project:{id:ee.id,iconImage:ee.iconImage??null},options:{themeVariant:z.metadata.variant,iconColor:z.colors.surface.foreground},className:"h-full w-full object-contain",fallback:de})}):de,s.jsx("span",{className:"truncate",children:ie})]})},[F,z.metadata.variant,z.colors.surface.foreground]),W=a.useMemo(()=>{if(D?.path)return{id:D.id,path:D.path};const ee=P??k;return ee?{id:`path:${ee}`,path:ee}:null},[D,P,k]),[J]=a.useState(()=>typeof window<"u"?hr():!1),U=a.useMemo(()=>typeof navigator>"u"?!1:/Macintosh|Mac OS X/.test(navigator.userAgent||""),[]),te=sf(),Z=a.useMemo(()=>{if(typeof window>"u")return null;const ee=window.__OPENCHAMBER_MACOS_MAJOR__;if(typeof ee=="number"&&Number.isFinite(ee)&&ee>0)return ee;if(typeof navigator>"u")return null;const ie=(navigator.userAgent||"").match(/Mac OS X (\d+)[._](\d+)/);if(!ie)return null;const ve=Number.parseInt(ie[1],10),K=Number.parseInt(ie[2],10);return Number.isNaN(ve)?null:ve===10?K:ve},[]),ue=a.useMemo(()=>J&&U||te?"pl-[5.5rem]":"pl-3",[J,U,te]),Oe=a.useMemo(()=>!J||!U||Z===null?"":Z>=26?"h-12":Z<=15?"h-14":"",[J,U,Z]),se=a.useCallback(async ee=>{ee.target.closest("button, a, input, select, textarea")||ee.button===0&&J&&await Pg()},[J]);a.useEffect(()=>{if(!n)return;const ee=ie=>{ie.key==="Escape"&&(ie.preventDefault(),ie.stopPropagation(),n())};return window.addEventListener("keydown",ee,!0),()=>window.removeEventListener("keydown",ee,!0)},[n]);const[G,Ie]=a.useState(""),{isLoading:pe,isGitRepository:V}=Wm(A),Q=a.useRef(!1),ne=V===!0,oe=ne&&w;a.useEffect(()=>{if(V===!1){Q.current=!0,N(!1);return}V===!0&&Q.current&&(Q.current=!1,N(!0))},[V]);const ce=il(ee=>ee.createMultiRun),ke=il(ee=>ee.error),ye=il(ee=>ee.clearError);a.useEffect(()=>{typeof t=="string"&&t.trim().length>0&&d(ee=>{const ie=[...ee];return ie.length>0&&!ie[0].prompt.trim()&&(ie[0]={...ie[0],prompt:t}),ie})},[t]),a.useEffect(()=>{if(!W)return;let ee=!1;return j(!0),(async()=>{try{const ie=await Ig(W);ee||g(ie)}catch{}finally{ee||j(!1)}})(),()=>{ee=!0}},[W]);const he=a.useCallback((ee,ie)=>{d(ve=>ve.map(K=>K.id===ee?{...K,...ie}:K))},[]),Ee=a.useCallback(ee=>{d(ie=>ie.filter(ve=>ve.id!==ee))},[]),Ue=a.useCallback(()=>{d(ee=>[...ee,{id:oi(),prompt:"",models:[]}])},[]),Me=async ee=>{const ie=ee.target.files;if(!ie)return;let ve=0;for(let K=0;K<ie.length;K++){const de=ie[K];if(de.size>bN){fe.error(o("multirun.launcher.toast.fileTooLarge",{fileName:de.name}));continue}try{const _e=await new Promise((Pe,re)=>{const me=new FileReader;me.onload=()=>Pe(me.result),me.onerror=re,me.readAsDataURL(de)});p(Pe=>[...Pe,{id:oi(),filename:de.name,mimeType:de.type||"application/octet-stream",size:de.size,dataUrl:_e}]),ve++}catch(_e){console.error("File attach failed",_e),fe.error(o("multirun.launcher.toast.attachFailed",{fileName:de.name}))}}ve>0&&fe.success(ve===1?o("multirun.launcher.toast.attachedSingle",{count:ve}):o("multirun.launcher.toast.attachedPlural",{count:ve})),v.current&&(v.current.value="")},X=ee=>{p(ie=>ie.filter(ve=>ve.id!==ee))},Ne=a.useMemo(()=>l.reduce((ee,ie)=>ee+ie.models.length,0),[l]),Ae=async ee=>{ee.preventDefault();const ie=l.filter(ve=>ve.prompt.trim()&&ve.models.length>=1);if(ie.length!==0&&!(Ne<1)){b(!0),ye();try{L&&L!==E&&O(L);const ve=f.map(re=>({mime:re.mimeType,filename:re.filename,url:re.dataUrl})),K=S.filter(re=>re.trim().length>0),de=ie.map(re=>({prompt:re.prompt.trim(),models:re.models.map(me=>({providerID:me.providerID,modelID:me.modelID,displayName:me.displayName,variant:me.variant}))})),_e={name:i.trim(),groups:de,agent:u||void 0,worktreeBaseBranch:oe?G:void 0,isolateRuns:oe,files:ve.length>0?ve:void 0,setupCommands:K.length>0?K:void 0},Pe=await ce(_e);Pe&&(Pe.firstSessionId&&et.getState().setCurrentSession(Pe.firstSessionId),e?.())}finally{b(!1)}}},Se=!!(i.trim()&&l.some(ee=>ee.prompt.trim()&&ee.models.length>=1)&&Ne>=1&&A&&!pe&&(V===!1||!oe||G)),le=S.filter(ee=>ee.trim()).length;return s.jsxs("form",{onSubmit:Ae,className:"flex flex-col h-full bg-background",children:[r?null:s.jsxs("header",{onMouseDown:se,className:De("relative flex h-12 shrink-0 items-center justify-center border-b app-region-drag select-none",ue,Oe),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(Nt,{children:[s.jsx(Ct,{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(At,{children:s.jsx("p",{children:o("multirun.launcher.actions.closeEsc")})})]})})]}),s.jsx(Sa,{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(no,{htmlFor:"multirun-project",required:!0,children:o("multirun.launcher.project.label")}),M.length>0?s.jsxs(gn,{value:L??void 0,onValueChange:T,children:[s.jsx(xn,{id:"multirun-project",size:"lg",className:"w-fit max-w-full",children:D?s.jsx(sn,{children:R(D)}):s.jsx(sn,{placeholder:o("multirun.launcher.project.placeholder")})}),s.jsx(bn,{fitContent:!0,children:M.map(ee=>s.jsx(bs,{value:ee.id,className:"max-w-[24rem]",children:R(ee)},ee.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(no,{htmlFor:"group-name",required:!0,info:s.jsx(Yi,{children:o("multirun.launcher.groupName.info")}),children:o("multirun.launcher.groupName.label")}),s.jsx(or,{id:"group-name",value:i,onChange:ee=>c(ee.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(no,{htmlFor:"multirun-worktree-base-branch",info:s.jsx(Yi,{children:o("multirun.launcher.baseBranch.info")}),children:o("multirun.launcher.baseBranch.label")}),s.jsx(xN,{directory:A,value:G,onChange:Ie,disabled:!oe,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(ao,{checked:w,onChange:N,disabled:!ne,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(no,{htmlFor:"multirun-agent",info:s.jsx(Yi,{children:o("multirun.launcher.agent.info")}),children:o("multirun.launcher.agent.label")}),s.jsx(Om,{value:u,onChange:h,id:"multirun-agent"})]})]}),s.jsxs(To,{open:m,onOpenChange:y,children:[s.jsxs(xi,{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")}),le>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:le}),s.jsx(I,{name:"arrow-down-s",className:De("h-3.5 w-3.5 text-muted-foreground/50 transition-transform duration-200 ml-auto",m&&"rotate-180")})]}),s.jsx(Eo,{children:s.jsx("div",{className:"pt-2 space-y-1.5",children:C?s.jsx("p",{className:"typography-meta text-muted-foreground/70 px-2",children:o("multirun.launcher.setupCommands.loading")}):s.jsxs(s.Fragment,{children:[S.map((ee,ie)=>s.jsxs("div",{className:"flex gap-1.5",children:[s.jsx(or,{value:ee,onChange:ve=>{const K=[...S];K[ie]=ve.target.value,g(K)},placeholder:o("multirun.launcher.setupCommands.commandPlaceholder"),className:"h-8 flex-1 font-mono text-xs"}),s.jsx("button",{type:"button",onClick:()=>g(S.filter((ve,K)=>K!==ie)),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"})})]},`${ee}-${ie}`)),s.jsxs("button",{type:"button",onClick:()=>g([...S,""]),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(no,{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:v,type:"file",multiple:!0,className:"hidden",onChange:Me,accept:"*/*"}),s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>v.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(At,{children:o("multirun.launcher.attachments.tooltip")})]}),f.map(ee=>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:[ee.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:ee.filename,children:ee.filename}),s.jsx("button",{type:"button",onClick:()=>X(ee.id),className:"text-muted-foreground hover:text-destructive",children:s.jsx(I,{name:"close",className:"h-3 w-3"})})]},ee.id))]})]}),l.map((ee,ie)=>s.jsx(yN,{group:ee,groupIndex:ie,canRemove:l.length>1,onUpdate:he,onRemove:Ee},ee.id)),s.jsxs("button",{type:"button",onClick:Ue,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")]}),ke&&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:ke})]})})}),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:[!oe&&V!==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(He,{type:"button",variant:"ghost",size:"sm",onClick:n,children:o("multirun.launcher.actions.cancel")}):null,s.jsx(He,{type:"submit",size:"sm",disabled:!Se||x,children:x?o("multirun.launcher.actions.creating"):s.jsx(s.Fragment,{children:o("multirun.launcher.actions.startWithRunCount",{count:Ne})})})]})})]})},yN=t=>{const e=nt.c(99),{group:n,groupIndex:r,canRemove:o,onUpdate:i,onRemove:c}=t,{t:l}=ft(),[d,u]=a.useState(!1),[h,f]=a.useState(""),[p,x]=a.useState(!1),[b,S]=a.useState(""),[g,m]=a.useState(!1),[y,C]=a.useState(""),j=a.useRef(null),w=a.useRef(null),N=a.useRef(null),v=a.useRef(null);let P;e[0]!==n.id||e[1]!==n.models||e[2]!==i?(P=K=>{n.models.length>=al||i(n.id,{models:[...n.models,K]})},e[0]=n.id,e[1]=n.models,e[2]=i,e[3]=P):P=e[3];const F=P;let k;e[4]!==n.id||e[5]!==n.models||e[6]!==i?(k=K=>{i(n.id,{models:n.models.filter((de,_e)=>_e!==K)})},e[4]=n.id,e[5]=n.models,e[6]=i,e[7]=k):k=e[7];const E=k;let O;e[8]!==n.id||e[9]!==n.models||e[10]!==i?(O=(K,de)=>{i(n.id,{models:n.models.map((_e,Pe)=>Pe===K?de:_e)})},e[8]=n.id,e[9]=n.models,e[10]=i,e[11]=O):O=e[11];const M=O;let L;e[12]===Symbol.for("react.memo_cache_sentinel")?(L=(K,de)=>{if(K.startsWith("/")){const me=K.indexOf(" "),ge=K.indexOf(`
206
- `),$=Math.min(me===-1?K.length:me,ge===-1?K.length:ge);if(de<=$&&me===-1){S(K.substring(1,$)),x(!0),u(!1),m(!1);return}}x(!1);const _e=K.substring(0,de),Pe=_e.lastIndexOf("#");if(Pe!==-1){const me=Pe>0?_e[Pe-1]:null,ge=_e.substring(Pe+1);if((!me||/\s/.test(me))&&!ge.includes(" ")&&!ge.includes(`
207
- `)){C(ge),m(!0),u(!1);return}}m(!1);const re=_e.lastIndexOf("@");if(re!==-1){const me=re>0?_e[re-1]:null,ge=_e.substring(re+1);(!me||/\s/.test(me))&&!ge.includes(" ")&&!ge.includes(`
208
- `)?(f(ge),u(!0)):u(!1);return}u(!1)},e[12]=L):L=e[12];const _=L;let D;e[13]!==n.id||e[14]!==i?(D=K=>{i(n.id,{prompt:K})},e[13]=n.id,e[14]=i,e[15]=D):D=e[15];const A=D;let T;e[16]!==n.prompt||e[17]!==A?(T=K=>{const de=n.prompt,Pe=j.current?.selectionStart??de.length,me=de.substring(0,Pe).lastIndexOf("@"),ge=K.relativePath&&K.relativePath.trim().length>0?K.relativePath.trim():K.path||K.name,$=me!==-1?me:Pe,B=`${de.substring(0,$)}@${ge} ${de.substring(Pe)}`,xe=$+ge.length+2;A(B),u(!1),f(""),requestAnimationFrame(()=>{const be=j.current;be&&(be.selectionStart=xe,be.selectionEnd=xe,be.focus()),_(B,xe)})},e[16]=n.prompt,e[17]=A,e[18]=T):T=e[18];const z=T;let R;e[19]!==n.prompt||e[20]!==A?(R=K=>{const de=n.prompt,Pe=j.current?.selectionStart??de.length,me=de.substring(0,Pe).lastIndexOf("@"),ge=me!==-1?me:Pe,$=`${de.substring(0,ge)}@${K} ${de.substring(Pe)}`,B=ge+K.length+2;A($),u(!1),f(""),requestAnimationFrame(()=>{const xe=j.current;xe&&(xe.selectionStart=B,xe.selectionEnd=B,xe.focus()),_($,B)})},e[19]=n.prompt,e[20]=A,e[21]=R):R=e[21];const W=R;let J;e[22]!==A?(J=K=>{const de=`/${K.name} `;A(de),x(!1),S(""),m(!1),requestAnimationFrame(()=>{const _e=j.current;_e&&(_e.focus(),_e.selectionStart=_e.value.length,_e.selectionEnd=_e.value.length),_(de,de.length)})},e[22]=A,e[23]=J):J=e[23];const U=J;let te;e[24]!==n.prompt||e[25]!==A?(te=(K,de)=>{const _e=n.prompt,re=j.current?.selectionStart??_e.length,ge=_e.substring(0,re).lastIndexOf("#"),$=ge!==-1?ge:re,B=`${_e.substring(0,$)}#${de} ${_e.substring(re)}`,xe=$+de.length+2;A(B),m(!1),C(""),requestAnimationFrame(()=>{const be=j.current;be&&(be.selectionStart=xe,be.selectionEnd=xe,be.focus()),_(B,xe)})},e[24]=n.prompt,e[25]=A,e[26]=te):te=e[26];const Z=te;let ue;e[27]!==p||e[28]!==d||e[29]!==g?(ue=K=>{if(p&&N.current&&(K.key==="Enter"||K.key==="ArrowUp"||K.key==="ArrowDown"||K.key==="Escape"||K.key==="Tab")){K.preventDefault(),N.current.handleKeyDown(K.key);return}d&&w.current&&(K.key==="Enter"||K.key==="ArrowUp"||K.key==="ArrowDown"||K.key==="Escape"||K.key==="Tab")&&(K.preventDefault(),w.current.handleKeyDown(K.key)),g&&v.current&&(K.key==="Enter"||K.key==="ArrowUp"||K.key==="ArrowDown"||K.key==="Escape"||K.key==="Tab")&&(K.preventDefault(),v.current.handleKeyDown(K.key))},e[27]=p,e[28]=d,e[29]=g,e[30]=ue):ue=e[30];const Oe=ue,se=r+1;let G;e[31]!==l||e[32]!==se?(G=l("multirun.launcher.groups.groupLabel",{index:se}),e[31]=l,e[32]=se,e[33]=G):G=e[33];let Ie;e[34]!==G?(Ie=s.jsx("span",{className:"typography-meta font-medium text-foreground",children:G}),e[34]=G,e[35]=Ie):Ie=e[35];let pe;e[36]!==o||e[37]!==n.id||e[38]!==c||e[39]!==l?(pe=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":l("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]=l,e[40]=pe):pe=e[40];let V;e[41]!==Ie||e[42]!==pe?(V=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ie,pe]}),e[41]=Ie,e[42]=pe,e[43]=V):V=e[43];let Q;e[44]!==l?(Q=l("multirun.launcher.groups.prompt.label"),e[44]=l,e[45]=Q):Q=e[45];let ne;e[46]!==Q?(ne=s.jsx(no,{required:!0,children:Q}),e[46]=Q,e[47]=ne):ne=e[47];const oe=n.prompt;let ce;e[48]!==A?(ce=K=>{const de=K.target.value;A(de);const _e=K.target.selectionStart??de.length;_(de,_e)},e[48]=A,e[49]=ce):ce=e[49];let ke;e[50]!==l?(ke=l("multirun.launcher.groups.prompt.placeholder"),e[50]=l,e[51]=ke):ke=e[51];let ye;e[52]!==n.prompt||e[53]!==Oe||e[54]!==ce||e[55]!==ke?(ye=s.jsx(wo,{ref:j,value:oe,onChange:ce,onKeyDown:Oe,placeholder:ke,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]=Oe,e[54]=ce,e[55]=ke,e[56]=ye):ye=e[56];let he;e[57]!==b||e[58]!==U||e[59]!==p?(he=p?s.jsx(bf,{ref:N,searchQuery:b,onCommandSelect:U,onClose:()=>x(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[57]=b,e[58]=U,e[59]=p,e[60]=he):he=e[60];let Ee;e[61]!==W||e[62]!==z||e[63]!==h||e[64]!==d?(Ee=d?s.jsx(yf,{ref:w,searchQuery:h,onFileSelect:z,onAgentSelect:W,onClose:()=>u(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[61]=W,e[62]=z,e[63]=h,e[64]=d,e[65]=Ee):Ee=e[65];let Ue;e[66]!==Z||e[67]!==g||e[68]!==y?(Ue=g?s.jsx(wf,{ref:v,searchQuery:y,onSnippetSelect:Z,onClose:()=>m(!1),style:{left:0,top:"auto",bottom:"calc(100% + 6px)",marginBottom:0,maxWidth:"100%"}}):null,e[66]=Z,e[67]=g,e[68]=y,e[69]=Ue):Ue=e[69];let Me;e[70]!==ye||e[71]!==he||e[72]!==Ee||e[73]!==Ue?(Me=s.jsxs("div",{className:"relative",children:[ye,he,Ee,Ue]}),e[70]=ye,e[71]=he,e[72]=Ee,e[73]=Ue,e[74]=Me):Me=e[74];let X;e[75]!==ne||e[76]!==Me?(X=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[ne,Me]}),e[75]=ne,e[76]=Me,e[77]=X):X=e[77];let Ne;e[78]!==l?(Ne=l("multirun.launcher.models.info",{max:al}),e[78]=l,e[79]=Ne):Ne=e[79];let Ae;e[80]!==Ne?(Ae=s.jsx(Yi,{children:Ne}),e[80]=Ne,e[81]=Ae):Ae=e[81];let Se;e[82]!==l?(Se=l("multirun.launcher.models.label"),e[82]=l,e[83]=Se):Se=e[83];let le;e[84]!==Ae||e[85]!==Se?(le=s.jsx(no,{required:!0,info:Ae,children:Se}),e[84]=Ae,e[85]=Se,e[86]=le):le=e[86];let ee;e[87]!==n.models||e[88]!==F||e[89]!==E||e[90]!==M?(ee=s.jsx(Lm,{selectedModels:n.models,onAdd:F,onRemove:E,onUpdate:M,minModels:1,maxModels:al}),e[87]=n.models,e[88]=F,e[89]=E,e[90]=M,e[91]=ee):ee=e[91];let ie;e[92]!==le||e[93]!==ee?(ie=s.jsxs("div",{className:"flex flex-col gap-1.5",children:[le,ee]}),e[92]=le,e[93]=ee,e[94]=ie):ie=e[94];let ve;return e[95]!==V||e[96]!==X||e[97]!==ie?(ve=s.jsxs("div",{className:"rounded-lg border border-border p-3 space-y-3",children:[V,X,ie]}),e[95]=V,e[96]=X,e[97]=ie,e[98]=ve):ve=e[98],ve},wN=a.createContext(null),vN=t=>{const e=nt.c(3),{children:n,value:r}=t;let o;return e[0]!==n||e[1]!==r?(o=s.jsx(wN.Provider,{value:r,children:n}),e[0]=n,e[1]=r,e[2]=o):o=e[2],o},jN=Da(()=>Oo(()=>import("./DiagramView-1-LZVuzn.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])).then(t=>({default:t.DiagramView}))),SN=Da(()=>Oo(()=>import("./runtimeEndpointReset-DL5z84w2.js").then(t=>t.al),__vite__mapDeps([110,1,2,8,3,4,5,6,7,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,111,112,113,114,115,116])).then(t=>({default:t.SettingsView}))),kN=Da(()=>Oo(()=>import("./SettingsWindow-CozowJLm.js"),__vite__mapDeps([118,1,2,8,3,4,5,6,7,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,110,111,112,113,114,115,116])).then(t=>({default:t.SettingsWindow}))),NN=()=>{const t=Re(D=>D.isSidebarOpen),e=Re(D=>D.activeMainTab),n=Re(D=>D.setIsMobile),r=Re(D=>D.isSessionSwitcherOpen),o=Re(D=>D.isSettingsDialogOpen),i=Re(D=>D.setSettingsDialogOpen),c=Re(D=>D.isMultiRunLauncherOpen),l=Re(D=>D.setMultiRunLauncherOpen),d=Re(D=>D.multiRunLauncherPrefillPrompt),u=Re(D=>D.isScheduledTasksDialogOpen),h=Re(D=>D.isArchivePageOpen),f=Re(D=>D.worktreesPageProjectId),p=u||h||!!f||c;a.useEffect(()=>{const D=()=>Re.getState().closeMainSurfaces(),A=et.subscribe((z,R)=>{const W=!!z.currentSessionId&&z.currentSessionId!==R.currentSessionId,J=!!z.newSessionDraft?.open&&z.newSessionDraft!==R.newSessionDraft;(W||J)&&D()}),T=Re.subscribe((z,R)=>{z.activeMainTab!==R.activeMainTab&&D()});return()=>{A(),T()}},[]);const{isMobile:x}=Pr(),b=a.useRef(!1),[S,g]=a.useState(!1),[m,y]=a.useState(!1),[C,j]=a.useState(!1),[w,N]=a.useState(!1),v=a.useCallback(D=>{g(D),Re.getState().setSessionSwitcherOpen(D)},[]),P=a.useRef(typeof window>"u"?0:window.innerWidth),F=Qc(-P.current),k=$e.useRef(0),E=Qc(P.current),O=$e.useRef(0);$e.useEffect(()=>{x&&(k.current=window.innerWidth,O.current=window.innerWidth)},[x]),$e.useEffect(()=>{if(!x){j(!1);return}S&&j(!0),Xc(F,S?0:-k.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[S,x,F]),$e.useEffect(()=>{if(!x){N(!1);return}m&&N(!0),Xc(E,m?0:O.current,{type:"spring",stiffness:400,damping:35,mass:.8})},[x,m,E]),$e.useEffect(()=>{if(x)return F.on("change",D=>{const A=k.current||P.current,T=S||D>-A+.5;j(z=>z===T?z:T)})},[x,F,S]),$e.useEffect(()=>{if(x)return E.on("change",D=>{const A=O.current||P.current,T=m||D<A-.5;N(z=>z===T?z:T)})},[x,m,E]),$e.useEffect(()=>{x&&!r&&S&&v(!1)},[r,x,S,v]),$e.useEffect(()=>{if(!x){b.current=!1;return}b.current||(b.current=!0,v(!1),y(!1))},[x,v]),$e.useEffect(()=>{if(!x||e!=="chat"||S||m||o)return;let D=!1,A;const T=z=>{A=window.setTimeout(()=>{if(D)return;const R=et.getState(),W=Re.getState();if(!(W.activeMainTab!=="chat"||W.isSettingsDialogOpen||R.currentSessionId||R.newSessionDraft?.open)){if(R.isLoading){T(250);return}R.openNewSessionDraft({automatic:!0})}},z)};return T(500),()=>{D=!0,A!==void 0&&window.clearTimeout(A)}},[e,x,o,S,m]),$e.useEffect(()=>{!x||!o||(v(!1),y(!1))},[x,o,v]),yx(),a.useEffect(()=>{Re.getState().isMobile!==x&&n(x)},[x,n]);const M=a.useCallback(()=>{S&&v(!1),y(!m)},[S,m,v]),L=a.useMemo(()=>{if(!x&&e!=="terminal"&&e!=="diagram")return null;switch(e){case"plan":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(Tf,{})});case"git":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(Sl,{isActive:!m})});case"diff":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(im,{})});case"terminal":return s.jsx(Ef,{});case"files":return s.jsx(a.Suspense,{fallback:null,children:s.jsx($f,{})});case"context":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(Mf,{})});case"diagram":return s.jsx(a.Suspense,{fallback:null,children:s.jsx(jN,{})});default:return null}},[e,x,m]),_=e==="chat";return s.jsx(wx,{children:s.jsxs("div",{"data-page-scroll-lock":"true",className:De("main-content-safe-area",x?"flex h-[100dvh] flex-col":"relative flex h-[100dvh]","bg-background"),children:[s.jsx(Nj,{}),s.jsx(f0,{}),s.jsx(g0,{}),s.jsx(j2,{}),x?s.jsxs(vN,{value:{leftDrawerOpen:S,rightDrawerOpen:m,toggleLeftDrawer:()=>{const D=!S;m&&y(!1),v(D)},toggleRightDrawer:M,leftDrawerX:F,rightDrawerX:E,leftDrawerWidth:k,rightDrawerWidth:O,setMobileLeftDrawerOpen:v,setRightSidebarOpen:y},children:[!o&&s.jsx(nd,{onToggleLeftDrawer:()=>{const D=!S;m&&y(!1),v(D)},onToggleRightDrawer:()=>{M()},leftDrawerOpen:S,rightDrawerOpen:m}),s.jsx("div",{"data-page-scroll-lock":"true",className:De("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:De("absolute inset-0",(!_||p)&&"invisible"),children:s.jsx(Cs,{children:s.jsx(xl,{active:_&&!o&&!p})})}),L&&s.jsx("div",{className:De("absolute inset-0",p&&"invisible"),children:s.jsx(Cs,{children:L})}),c&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Cs,{children:s.jsx(Tu,{initialPrompt:d,onCreated:()=>l(!1),onCancel:()=>l(!1)})})}),s.jsx(Cs,{children:s.jsx(Du,{})}),s.jsx(Cs,{children:s.jsx(Pu,{})}),s.jsx(Cs,{children:s.jsx(Iu,{})}),s.jsx(Jc.div,{className:De("absolute inset-0 z-20 bg-sidebar",!C&&"pointer-events-none invisible"),"data-page-scroll-lock":"true",style:{x:F},"aria-hidden":!S,children:s.jsx(Cs,{children:s.jsx(pu,{mobileVariant:!0,isVisible:C})})}),w&&s.jsx(Jc.div,{className:"absolute inset-0 z-20 bg-sidebar","data-page-scroll-lock":"true",style:{x:E},"aria-hidden":!m,children:s.jsx(Cs,{children:s.jsx(a.Suspense,{fallback:null,children:s.jsx(Sl,{isActive:m})})})})]})}),o&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",style:{paddingTop:"var(--oc-safe-area-top, 0px)"},children:s.jsx(Cs,{children:s.jsx(a.Suspense,{fallback:null,children:s.jsx(SN,{onClose:()=>i(!1)})})})})]}):s.jsxs(s.Fragment,{children:[s.jsx(Yb,{}),s.jsxs("div",{className:"flex flex-1 overflow-hidden","data-page-scroll-lock":"true",children:[s.jsx(Kb,{isOpen:t,isMobile:x,className:"border-border",topBar:s.jsx(Gb,{}),children:s.jsx(pu,{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(nd,{}),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",children:[s.jsxs("main",{className:"flex-1 overflow-hidden bg-background relative","data-page-scroll-lock":"true",children:[s.jsx("div",{className:De("absolute inset-0",(!_||p)&&"invisible"),children:s.jsx(Cs,{children:s.jsx(xl,{active:_&&!o&&!p})})}),L&&s.jsx("div",{className:De("absolute inset-0",p&&"invisible"),children:s.jsx(Cs,{children:L})}),c&&s.jsx("div",{className:"absolute inset-0 z-10 bg-background",children:s.jsx(Cs,{children:s.jsx(Tu,{isWindowed:!0,initialPrompt:d,onCreated:()=>l(!1),onCancel:()=>l(!1)})})}),s.jsx(Cs,{children:s.jsx(Du,{})}),s.jsx(Cs,{children:s.jsx(Pu,{})}),s.jsx(Cs,{children:s.jsx(Iu,{})})]}),s.jsx(cj,{})]})})}),s.jsx("div",{className:"border-t border-border","data-page-scroll-lock":"true",children:s.jsx(Cs,{children:s.jsx(hj,{})})})]})]})]}),s.jsx(a.Suspense,{fallback:null,children:s.jsx(kN,{open:o,onOpenChange:i})})]})]})})},CN=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`},mn=t=>{const e=nt.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 l;return e[5]!==i||e[6]!==c?(l=s.jsxs("div",{className:"rounded-md p-2",style:o,children:[i,c]}),e[5]=i,e[6]=c,e[7]=l):l=e[7],l},Eu=t=>{const e=nt.c(43),{title:n,snapshot:r,emptyLabel:o}=t,{t:i}=ft();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 l=r.entries.slice(0,12);let d;e[8]!==r.entries?(d=r.entries.reduce(PN,0),e[8]=r.entries,e[9]=d):d=e[9];const u=d;let h;e[10]!==n?(h=s.jsx("div",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:n}),e[10]=n,e[11]=h):h=e[11];let f;e[12]!==r.durationMs||e[13]!==r.startedAt||e[14]!==i?(f=r.startedAt?CN(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 x;e[18]!==h||e[19]!==p?(x=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[h,p]}),e[18]=h,e[19]=p,e[20]=x):x=e[20];let b;e[21]!==i?(b=i("memoryDebugPanel.metric.metrics"),e[21]=i,e[22]=b):b=e[22];let S;e[23]!==r.entries.length||e[24]!==b?(S=s.jsx(mn,{label:b,value:r.entries.length}),e[23]=r.entries.length,e[24]=b,e[25]=S):S=e[25];let g;e[26]!==i?(g=i("memoryDebugPanel.metric.samples"),e[26]=i,e[27]=g):g=e[27];let m;e[28]!==g||e[29]!==u?(m=s.jsx(mn,{label:g,value:u}),e[28]=g,e[29]=u,e[30]=m):m=e[30];let y;e[31]!==i?(y=i("memoryDebugPanel.metric.lastUpdate"),e[31]=i,e[32]=y):y=e[32];let C;e[33]!==r.lastUpdatedAt||e[34]!==i?(C=r.lastUpdatedAt?i("memoryDebugPanel.common.live"):i("memoryDebugPanel.common.notAvailable"),e[33]=r.lastUpdatedAt,e[34]=i,e[35]=C):C=e[35];let j;e[36]!==y||e[37]!==C?(j=s.jsx(mn,{label:y,value:C}),e[36]=y,e[37]=C,e[38]=j):j=e[38];let w;e[39]!==m||e[40]!==j||e[41]!==S?(w=s.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[S,m,j]}),e[39]=m,e[40]=j,e[41]=S,e[42]=w):w=e[42],c=s.jsxs("div",{className:"space-y-2 border-t border-[var(--interactive-border)] pt-2 first:border-t-0 first:pt-0",children:[x,w,l.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(On,{outerClassName:"max-h-64",className:"pr-1",children:s.jsx("div",{className:"space-y-1",children:l.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},AN=t=>{const e=nt.c(99),{onClose:n}=t,{t:r}=ft(),[o,i]=a.useState("memory"),[c,l]=a.useState("idle"),d=et(IN),u=pf(RN),h=of(),f=Rg(MN),p=en(TN),[x,b]=a.useState(EN),[S,g]=a.useState(FN);let m;e[0]!==x.entries?(m=new Map,x.entries.forEach(Se=>{m.set(Se.metric,Se.count)}),e[0]=x.entries,e[1]=m):m=e[1];let y;e[2]!==m?(y=m.get("ui.message_list.render")??0,e[2]=m,e[3]=y):y=e[3];let C;e[4]!==m?(C=m.get("ui.message_list.render.streaming")??0,e[4]=m,e[5]=C):C=e[5];let j;e[6]!==m?(j=m.get("ui.chat_message.render")??0,e[6]=m,e[7]=j):j=e[7];let w;e[8]!==m?(w=m.get("ui.chat_message.render.streaming")??0,e[8]=m,e[9]=w):w=e[9];let N;e[10]!==m?(N=m.get("ui.chat_message.render.static_during_stream")??0,e[10]=m,e[11]=N):N=e[11];let v;e[12]!==m?(v=m.get("ui.chat_message.render.static_outside_active_turn_during_stream")??0,e[12]=m,e[13]=v):v=e[13];let P;e[14]!==y||e[15]!==C||e[16]!==j||e[17]!==w||e[18]!==N||e[19]!==v?(P={messageListRender:y,messageListRenderStreaming:C,chatMessageRender:j,chatMessageRenderStreaming:w,chatMessageRenderStaticDuringStream:N,chatMessageRenderStaticOutsideActiveTurnDuringStream:v},e[14]=y,e[15]=C,e[16]=j,e[17]=w,e[18]=N,e[19]=v,e[20]=P):P=e[20];const F=P;let k,E;e[21]===Symbol.for("react.memo_cache_sentinel")?(k=()=>{const Se=()=>{b(Oi()),g(Li())};Se();const le=window.setInterval(Se,500);return()=>window.clearInterval(le)},E=[],e[21]=k,e[22]=E):(k=e[21],E=e[22]),a.useEffect(k,E);let O,M;e[23]!==c?(O=()=>{if(c==="idle")return;const Se=window.setTimeout(()=>{l("idle")},1500);return()=>window.clearTimeout(Se)},M=[c],e[23]=c,e[24]=O,e[25]=M):(O=e[24],M=e[25]),a.useEffect(O,M);let L=0,_=0,D=0;for(const Se of Object.keys(f)){const le=f[Se]??[];_=_+le.length;for(const ee of le)ee.role==="user"?D=D+1:ee.role==="assistant"&&(L=L+1)}let A;e[26]!==L||e[27]!==_||e[28]!==D?(A={assistant:L,total:_,user:D},e[26]=L,e[27]=_,e[28]=D,e[29]=A):A=e[29];const T=A;let z;if(e[30]!==d||e[31]!==f||e[32]!==u||e[33]!==h||e[34]!==r){let Se;e[36]!==d||e[37]!==f||e[38]!==u||e[39]!==r?(Se=le=>{const ee=f[le.id]??[];let ie=0,ve=0;for(const de of ee)de.role==="user"?ve=ve+1:de.role==="assistant"&&(ie=ie+1);const K=u.get(le.id);return{id:le.id,title:le.title||r("memoryDebugPanel.common.untitled"),assistantMessageCount:ie,messageCount:ee.length,userMessageCount:ve,isStreaming:K?.isStreaming||!1,isZombie:K?.isZombie||!1,backgroundCount:K?.backgroundMessageCount||0,lastAccessed:K?.lastAccessedAt||0,isCurrent:le.id===d}},e[36]=d,e[37]=f,e[38]=u,e[39]=r,e[40]=Se):Se=e[40],z=h.map(Se).sort(ON),e[30]=d,e[31]=f,e[32]=u,e[33]=h,e[34]=r,e[35]=z}else z=e[35];const R=z;let W;e[41]!==f?(W=Object.keys(f),e[41]=f,e[42]=W):W=e[42];const J=W.length;let U;e[43]===Symbol.for("react.memo_cache_sentinel")?(U=async()=>{try{const Se={generatedAt:new Date().toISOString(),ui:Oi(),vscode:Li()};await navigator.clipboard.writeText(JSON.stringify(Se,null,2)),l("copied")}catch{l("error")}},e[43]=U):U=e[43];const te=U;let Z;e[44]===Symbol.for("react.memo_cache_sentinel")?(Z={backgroundColor:"color-mix(in srgb, var(--surface-background) 94%, transparent)"},e[44]=Z):Z=e[44];let ue;e[45]!==o?(ue=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]=ue):ue=e[46];let Oe;e[47]!==r?(Oe=r("memoryDebugPanel.title"),e[47]=r,e[48]=Oe):Oe=e[48];let se;e[49]!==Oe?(se=s.jsx("h3",{className:"typography-ui-label font-semibold text-[var(--surface-foreground)]",children:Oe}),e[49]=Oe,e[50]=se):se=e[50];let G;e[51]!==ue||e[52]!==se?(G=s.jsxs("div",{className:"flex items-center gap-2",children:[ue,se]}),e[51]=ue,e[52]=se,e[53]=G):G=e[53];let Ie;e[54]!==o?(Ie=o==="streaming"?s.jsxs(s.Fragment,{children:[s.jsx(He,{size:"xs",variant:"ghost",onClick:te,children:s.jsx(I,{name:"file-copy",className:"h-3.5 w-3.5"})}),s.jsx(He,{size:"xs",variant:"ghost",onClick:()=>{Ah(),b(Oi()),g(Li())},children:s.jsx(I,{name:"refresh",className:"h-3.5 w-3.5"})})]}):null,e[54]=o,e[55]=Ie):Ie=e[55];let pe;e[56]!==n?(pe=n?s.jsx(He,{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]=pe):pe=e[57];let V;e[58]!==Ie||e[59]!==pe?(V=s.jsxs("div",{className:"flex items-center gap-1",children:[Ie,pe]}),e[58]=Ie,e[59]=pe,e[60]=V):V=e[60];let Q;e[61]!==G||e[62]!==V?(Q=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[G,V]}),e[61]=G,e[62]=V,e[63]=Q):Q=e[63];let ne;e[64]===Symbol.for("react.memo_cache_sentinel")?(ne={backgroundColor:"color-mix(in srgb, var(--surface-muted) 55%, transparent)"},e[64]=ne):ne=e[64];const oe=o==="memory"?"secondary":"ghost";let ce;e[65]===Symbol.for("react.memo_cache_sentinel")?(ce=()=>i("memory"),e[65]=ce):ce=e[65];let ke;e[66]!==r?(ke=r("memoryDebugPanel.tabs.memory"),e[66]=r,e[67]=ke):ke=e[67];let ye;e[68]!==oe||e[69]!==ke?(ye=s.jsx(He,{size:"sm",variant:oe,className:"flex-1",onClick:ce,children:ke}),e[68]=oe,e[69]=ke,e[70]=ye):ye=e[70];const he=o==="streaming"?"secondary":"ghost";let Ee;e[71]===Symbol.for("react.memo_cache_sentinel")?(Ee=()=>i("streaming"),e[71]=Ee):Ee=e[71];let Ue;e[72]!==r?(Ue=r("memoryDebugPanel.tabs.streaming"),e[72]=r,e[73]=Ue):Ue=e[73];let Me;e[74]!==he||e[75]!==Ue?(Me=s.jsx(He,{size:"sm",variant:he,className:"flex-1",onClick:Ee,children:Ue}),e[74]=he,e[75]=Ue,e[76]=Me):Me=e[76];let X;e[77]!==ye||e[78]!==Me?(X=s.jsxs("div",{className:"mb-3 flex gap-1 rounded-md p-1",style:ne,children:[ye,Me]}),e[77]=ye,e[78]=Me,e[79]=X):X=e[79];let Ne;e[80]!==o||e[81]!==J||e[82]!==c||e[83]!==d||e[84]!==f||e[85]!==T||e[86]!==u||e[87]!==R||e[88]!==h||e[89]!==F||e[90]!==x||e[91]!==r||e[92]!==p||e[93]!==S?(Ne=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(mn,{label:r("memoryDebugPanel.metric.totalMessages"),value:T.total}),s.jsx(mn,{label:r("memoryDebugPanel.metric.cachedSessions"),value:`${J} / ${_c.MAX_SESSIONS}`}),s.jsx(mn,{label:r("memoryDebugPanel.metric.userMessages"),value:T.user}),s.jsx(mn,{label:r("memoryDebugPanel.metric.assistantMessages"),value:T.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:_c.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(On,{outerClassName:"max-h-48",className:"space-y-1 pr-1",children:R.map(Se=>s.jsxs("div",{className:"typography-meta flex items-center justify-between rounded p-1.5",style:{backgroundColor:Se.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:Se.title}),Se.isStreaming?s.jsx(I,{name:"pulse",className:"h-3 w-3 animate-pulse text-[var(--status-info)]"}):null,Se.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:Se.assistantMessageCount,user:Se.userMessageCount})}),s.jsx("span",{className:"font-mono text-[var(--surface-foreground)]",children:r("memoryDebugPanel.metric.msgsValue",{count:Se.messageCount})}),Se.backgroundCount>0?s.jsxs("span",{className:"text-[var(--status-info)]",children:["+",Se.backgroundCount]}):null]})]},Se.id))})]}),s.jsx("div",{className:"flex gap-2 border-t border-[var(--interactive-border)] pt-2",children:s.jsxs(Nt,{children:[s.jsx(Ct,{asChild:!0,children:s.jsx(He,{size:"sm",variant:"outline",className:"typography-meta",onClick:()=>{console.log("[DebugPanel] Session store state:",{sessions:h.map(LN),currentSessionId:d,cachedSessions:Object.keys(f),messageRoleCounts:T,sessionMessageRoleCounts:R.map(BN),memoryStates:Object.fromEntries(u)})},children:r("memoryDebugPanel.actions.logState")})}),s.jsx(At,{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(He,{size:"xs",variant:"outline",onClick:te,children:r("memoryDebugPanel.actions.copyJson")})]}),s.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[s.jsx(mn,{label:r("memoryDebugPanel.metric.uiMetrics"),value:x.entries.length}),s.jsx(mn,{label:r("memoryDebugPanel.metric.vscodeMetrics"),value:S.entries.length}),s.jsx(mn,{label:r("memoryDebugPanel.metric.messageListRenders"),value:F.messageListRender}),s.jsx(mn,{label:r("memoryDebugPanel.metric.messageListStreamRenders"),value:F.messageListRenderStreaming}),s.jsx(mn,{label:r("memoryDebugPanel.metric.chatMessageRenders"),value:F.chatMessageRender}),s.jsx(mn,{label:r("memoryDebugPanel.metric.chatMessageStreamRenders"),value:F.chatMessageRenderStreaming}),s.jsx(mn,{label:r("memoryDebugPanel.metric.chatMessageStaticDuringStream"),value:F.chatMessageRenderStaticDuringStream}),s.jsx(mn,{label:r("memoryDebugPanel.metric.chatMessageStaticOutsideActiveTurn"),value:F.chatMessageRenderStaticOutsideActiveTurnDuringStream})]}),s.jsx(Eu,{title:r("memoryDebugPanel.section.uiStreamingMetrics"),snapshot:x,emptyLabel:r("memoryDebugPanel.section.noUiSamples")}),S.entries.length>0?s.jsx(Eu,{title:r("memoryDebugPanel.section.vscodeBridgeMetrics"),snapshot:S,emptyLabel:r("memoryDebugPanel.section.noVscodeSamples")}):null]}),e[80]=o,e[81]=J,e[82]=c,e[83]=d,e[84]=f,e[85]=T,e[86]=u,e[87]=R,e[88]=h,e[89]=F,e[90]=x,e[91]=r,e[92]=p,e[93]=S,e[94]=Ne):Ne=e[94];let Ae;return e[95]!==Q||e[96]!==X||e[97]!==Ne?(Ae=s.jsxs(Tg,{className:"fixed bottom-4 right-4 z-50 w-[28rem] p-4 shadow-none bottom-safe-area",style:Z,children:[Q,X,Ne]}),e[95]=Q,e[96]=X,e[97]=Ne,e[98]=Ae):Ae=e[98],Ae},DN=AN;function PN(t,e){return t+e.count}function IN(t){return t.currentSessionId}function RN(t){return t.sessionMemoryState}function MN(t){return t.message}function TN(t){return t.totalRequestCount}function EN(){return Oi()}function FN(){return Li()}function ON(t,e){return e.lastAccessed-t.lastAccessed}function LN(t){return{id:t.id,title:t.title}}function BN(t){return{id:t.id,title:t.title,total:t.messageCount,user:t.userMessageCount,assistant:t.assistantMessageCount}}const $N=()=>{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()??"":""},_N=async()=>{const t=$N()||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")},Fu="openchamber:menu-action",ll="openchamber:check-for-updates",zN=t=>{const e=et(y=>y.openNewSessionDraft),n=Re(y=>y.toggleCommandPalette),r=Re(y=>y.setCommandPaletteOpen),o=Re(y=>y.toggleHelpDialog),i=Re(y=>y.toggleSidebar),c=Re(y=>y.setSessionSwitcherOpen),l=Re(y=>y.setActiveMainTab),d=Re(y=>y.setSettingsDialogOpen),u=Re(y=>y.setAboutDialogOpen),h=ti(y=>y.checkForUpdates),{setThemeMode:f}=co(),p=a.useRef(!1),x=a.useCallback(()=>{p.current||(p.current=!0,h().then(()=>{const{available:y,error:C}=ti.getState();if(C){fe.error("Failed to check for updates",{description:C});return}y||fe.success("You are on the latest version")}).finally(()=>{p.current=!1}))},[h]),b=a.useCallback(()=>{Kn.requestDirectoryDialog()},[]),S=a.useCallback(y=>{const C=Eg();if(C.length===0)return;const j=et.getState().currentSessionId,w=C.findIndex(P=>P.id===j);let N=y>0?0:C.length-1;w>=0&&(N=(w+y+C.length)%C.length);const v=C[N];v&&(l("chat"),c(!1),et.getState().setCurrentSession(v.id))},[l,c]),g=a.useCallback(y=>{const{activeProjectId:C,projects:j,setActiveProject:w}=ms.getState();if(j.length===0)return;const N=j.findIndex(F=>F.id===C);let v=y>0?0:j.length-1;N>=0&&(v=(N+y+j.length)%j.length);const P=j[v];P&&w(P.id)},[]),m=a.useCallback(y=>{switch(y){case"about":u(!0);break;case"settings":d(!0);break;case"command-palette":n();break;case"quick-open":r(!0);break;case"new-session":l("chat"),c(!1),e();break;case"new-worktree-session":l("chat"),c(!1),df();break;case"change-workspace":b();break;case"toggle-right-sidebar":{const C=js.getState().currentDirectory;if(!C)break;const j=Re.getState(),w=xo(C),N=j.contextPanelByDirectory[w];N?.isOpen?j.closeContextPanel(w):N?.activeTabId?j.setActiveContextPanelTab(w,N.activeTabId):j.openContextSurface(w,"git");break}case"open-right-sidebar-git":{const C=js.getState().currentDirectory;if(!C)break;Re.getState().openContextSurface(xo(C),"git");break}case"open-right-sidebar-files":{const C=js.getState().currentDirectory;if(!C)break;Re.getState().openContextSurface(xo(C),"file");break}case"toggle-terminal":{const C=js.getState().currentDirectory;if(!C)break;Re.getState().openContextSurface(xo(C),"terminal");break}case"toggle-terminal-expanded":{const C=js.getState().currentDirectory;if(!C)break;const j=xo(C),w=Re.getState(),N=w.contextPanelByDirectory[j];(N?.isOpen?N.tabs.find(P=>P.id===N.activeTabId)?.mode:null)!=="terminal"&&w.openContextSurface(j,"terminal"),w.toggleContextPanelExpanded(j);break}case"copy":{const C=new Event("openchamber:copy",{cancelable:!0});!window.dispatchEvent(C)||_N();break}case"theme-light":f("light");break;case"theme-dark":f("dark");break;case"theme-system":f("system");break;case"toggle-sidebar":i();break;case"toggle-memory-debug":t?.();break;case"go-back":js.getState().goBack();break;case"go-forward":js.getState().goForward();break;case"previous-session":S(-1);break;case"next-session":S(1);break;case"previous-project":g(-1);break;case"next-project":g(1);break;case"help-dialog":o();break;case"download-logs":{Fg().catch(()=>{fe.error("Failed to collect OpenCode status")});break}}},[b,g,S,t,e,u,l,c,r,d,f,n,o,i]);a.useEffect(()=>{const y=j=>{const w=j.detail;w&&m(w)},C=()=>{x()};return window.addEventListener(Fu,y),window.addEventListener(ll,C),()=>{window.removeEventListener(Fu,y),window.removeEventListener(ll,C)}},[m,x]),a.useEffect(()=>{if(typeof window>"u")return;const C=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof C!="function")return;let j=null,w=null;return C("openchamber:menu-action",N=>{const v=N?.payload;typeof v=="string"&&m(v)}).then(N=>{j=N}).catch(()=>{}),C("openchamber:check-for-updates",()=>{window.dispatchEvent(new Event(ll))}).then(N=>{w=N}).catch(()=>{}),()=>{(async()=>{try{const v=j?.();v instanceof Promise&&await v}catch{}try{const v=w?.();v instanceof Promise&&await v}catch{}})()}},[m])},VN="openchamber:tray-action",Ou=5e3,WN=500,UN=45e3,Um=20,Lu=()=>{if(typeof window>"u")return!1;const t=window.__OPENCHAMBER_PLATFORM__;return t==="darwin"||t==="win32"||t==="linux"},Bu=()=>typeof window<"u"&&window.__OPENCHAMBER_ELECTRON__?.trayEnabled!==!1,HN=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},KN=t=>{const e=Array.isArray(t.questions)?t.questions[0]:void 0;return e?.header||e?.question||"Question"},Hm=(t,e)=>Mo(t,e,di.getState().ids,Na.getState().rankById),GN=t=>{const e=t.replace(/\\/g,"/").replace(/\/+$/,""),n=e.lastIndexOf("/");return n>=0?e.slice(n+1):e},qN=(t,e,n,r,o)=>{if(!t)return"";const i=_g(n,r,t),c=e.project?.name,l=i?.label?.trim()||c?.trim()||GN(t),d=_i(t);let u=d&&o.get(d)||"";if(!u){for(const[h,f]of tn.getState().directories)if(_i(h)===d){u=f.status?.current??"";break}}if(!u)for(const h of r.values()){const f=h.find(p=>_i(p.path)===d);if(f?.branch){u=f.branch;break}}return u?`${l} · ${u}`:l},YN=()=>{const{results:t,dropdownProviderIds:e,displayMode:n}=Us.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 Nf){if(!e.includes(c.id))continue;const l=o.get(c.id);if(!l||l.configured!==!0)continue;const d=[];for(const[h,f]of Object.entries(l.usage?.windows??{})){const p=r==="remaining"?f.remainingPercent:f.usedPercent;d.push({label:Ll(h),value:li(f.valueLabel,p)})}const u=!l.ok&&l.error?l.error:d.length===0?"No rate limits reported":null;i.push({provider:c.name,rows:d,status:u})}return{mode:r,groups:i}},QN=async()=>{try{if(ua())return"Local OpenChamber";const t=window.__OPENCHAMBER_LOCAL_ORIGIN__||window.location.origin,e=Cr();if(e&&Qi(e,t))return"Local OpenChamber";const r=(await Uu()).hosts.find(o=>e?Qi(e,Hu(o)):!1);return r?.label?.trim()?Ku(r.label.trim()):"Instance"}catch{return""}},XN=()=>{const t=new Map,e=new Map,n=[],r=new Map;let o;try{o=ta()}catch{return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}}for(const[i,c]of o.children.entries()){const l=c.getState();l.vcs?.branch&&e.set(_i(i)??i,l.vcs.branch);for(const d of l.session)d?.id&&r.set(d.id,d.title);for(const[d,u]of Object.entries(l.session_status??{})){const h=u?.type,f=h==="busy"?"busy":h==="retry"?"retry":"idle",p=t.get(d);(!p||p==="idle")&&t.set(d,f)}for(const[d,u]of Object.entries(l.permission??{}))for(const h of u??[]){if(!h?.id)continue;const f=h.sessionID||d;n.push({kind:"permission",id:h.id,sessionId:f,sessionTitle:"",label:HN(h),directory:i})}for(const[d,u]of Object.entries(l.question??{}))for(const h of u??[]){if(!h?.id)continue;const f=h.sessionID||d;n.push({kind:"question",id:h.id,sessionId:f,sessionTitle:"",label:KN(h),directory:i})}}return{statusById:t,branchByDirectory:e,approvals:n,titleById:r}},JN=()=>{const t=pn.getState().activeSessions,e=new Set;t.filter(r=>r?.id&&!r.parentID).slice().sort(Hm).slice(0,Um).forEach(r=>{const o=Bn(r);o&&e.add(o)});const n=new Map;for(const r of t){if(!r?.id)continue;const o=Bn(r);if(!o||!e.has(o))continue;const i=n.get(o)??[];i.push(r.id),n.set(o,i)}return n},ZN=t=>{const e=XN(),n=Aa.getState().index.session,r=pn.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 m=i.get(g.parentID)??[];m.push(g.id),i.set(g.parentID,m)}const c=g=>{const m=[],y=[...i.get(g)??[]],C=new Set;for(;y.length;){const j=y.pop();C.has(j)||(C.add(j),m.push(j),y.push(...i.get(j)??[]))}return m},l=Ca.getState().statusById,d=g=>{const m=e.statusById.get(g);return m&&m!=="idle"?m:l.get(g)?.status.type??m??"idle"},u=g=>{const m=g.map(y=>d(y));return m.includes("busy")?"busy":m.includes("retry")?"retry":"idle"},h=ms.getState().projects,f=et.getState().availableWorktreesByProject,p=r.filter(g=>g?.id&&!g.parentID).slice().sort(Hm).slice(0,Um).map(g=>{const m=[g.id,...c(g.id)],y=Bn(g)??"";return{id:g.id,title:g.title||"Untitled session",status:u(m),branch:y?e.branchByDirectory.get(y)??"":"",unseen:m.reduce((C,j)=>C+(n.unseenCount[j]??0),0),hasError:m.some(C=>n.unseenHasError[C]??!1),directory:y,subtitle:qN(y,g,h,f,e.branchByDirectory)}}),x=e.approvals.map(g=>({...g,sessionTitle:o.get(g.sessionId)||""})),b=Re.getState();let S=0;if(b.dockBadgeEnabled)for(const g of r){if(!g?.id||g.parentID)continue;let m=n.unseenCount[g.id]??0;m===0&&b.notifyOnSubtasks&&(m=c(g.id).reduce((y,C)=>y+(n.unseenCount[C]??0),0)),m>0&&(S+=1)}return{sessions:p,approvals:x,instanceName:t,usage:YN(),dockBadgeCount:S}},eC=()=>{a.useEffect(()=>{if(!Lu()||!Bu()||!ma())return;let t=!1,e="",n=null,r="";const o=()=>{if(t)return;const P=ZN(r),F=JSON.stringify(P);F!==e&&(e=F,Ar("desktop_tray_update",P))};QN().then(P=>{t||(r=P,o())});const i=async()=>{const P=JN();await Promise.all([...P.entries()].map(async([F,k])=>{const E=await Fn.getSessionStatusForDirectory(F).catch(()=>null);t||E===null||Bg(F,E,k)}))},c=()=>{t||n!==null||(n=window.setTimeout(()=>{n=null,o()},WN))},l=new Map,d=()=>{if(t)return;let P;try{P=ta()}catch{return}const F=new Set;for(const[k,E]of P.children.entries())F.add(k),l.has(k)||l.set(k,E.subscribe(()=>c()));for(const[k,E]of l)F.has(k)||(E(),l.delete(k))};let u=null;try{u=ta().subscribeRegistry(()=>{d(),c()})}catch{}d();const h=Aa.subscribe(()=>c()),f=pn.subscribe(()=>c()),p=ms.subscribe(()=>c()),x=et.subscribe(()=>c()),b=tn.subscribe(()=>c()),S=Re.subscribe(()=>c()),g=Ca.subscribe(()=>c()),m=Na.subscribe(()=>c()),y=di.subscribe(()=>c());Og(Lg());const C=window.setInterval(()=>{ea()},UN);i();const j=window.setInterval(()=>{i()},Ou),w=Us.subscribe(()=>c());Us.getState().loadSettings().then(()=>{if(t)return;const{dropdownProviderIds:P,results:F}=Us.getState();P.length>0&&P.some(E=>!F.some(O=>O.providerId===E))&&Us.getState().fetchAllQuotas()});const N=window.setInterval(()=>{const P=Us.getState();P.autoRefresh&&P.dropdownProviderIds.length>0&&P.fetchAllQuotas()},Math.max(3e4,Us.getState().refreshIntervalMs||6e4)),v=window.setInterval(()=>{d(),o()},Ou);return o(),()=>{t=!0,n!==null&&window.clearTimeout(n),window.clearInterval(v),window.clearInterval(C),window.clearInterval(j),window.clearInterval(N),h(),f(),p(),x(),b(),S(),g(),m(),y(),w(),u?.();for(const P of l.values())P();l.clear()}},[]),a.useEffect(()=>{if(!Lu()||!Bu()||typeof window>"u")return;const e=window.__OPENCHAMBER_DESKTOP__?.listen;if(typeof e!="function")return;const n=o=>{o.type==="respond-permission"&&$g(o.sessionId,o.id,o.response).catch(()=>{fe.error("Failed to respond to permission request")})};let r=null;return e(VN,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="/api/notifications/stream",sC=()=>typeof document>"u"?!0:document.visibilityState==="visible"&&document.hasFocus(),nC=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}},rC=t=>{const e=nt.c(3),n=t?.enabled??!0;let r,o;e[0]!==n?(r=()=>{if(!n||hr()||!Ol()||typeof window>"u"||typeof EventSource>"u")return;const i=new EventSource(ha().sse(tC));return i.onmessage=oC,()=>{i.close()}},o=[n],e[0]=n,e[1]=r,e[2]=o):(r=e[1],o=e[2]),a.useEffect(r,o)};function oC(t){let e;try{e=JSON.parse(t.data)}catch{return}const n=Re.getState();if(!n.nativeNotificationsEnabled||n.notificationMode!=="always"&&sC())return;const r=nC(e);if(!r)return;fa()?.notifications?.notifyAgentCompletion(r)}const $u="pwa-install-toast-shown",_u="pwa-install-toast-dismissed",iC=()=>{const t=nt.c(6),{browserTab:e}=vx(),{t:n}=ft(),r=a.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]),a.useEffect(o,i);let c,l;t[3]!==e?(c=()=>{if(typeof window>"u"||!Ol()||!e)return;let d=null,u=null;const h=()=>{u!==null&&(fe.dismiss(u),u=null)},f=async()=>{if(!d)return;const b=d;d=null,h(),await b.prompt();const{outcome:S}=await b.userChoice;S==="accepted"&&fe.success(r.current("pwa.installPrompt.started"))},p=b=>{const S=b;if(typeof S.prompt!="function")return;S.preventDefault(),d=S;const g=yo(),m=Dh();jx({dismissed:g.getItem(_u),sessionShown:m.getItem($u),hasActiveToast:u!==null})&&(m.setItem($u,"true"),u=fe.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:()=>{yo().setItem(_u,"true"),h()}}}))},x=()=>{d=null,h(),fe.success(r.current("pwa.installPrompt.installed"))};return window.addEventListener("beforeinstallprompt",p),window.addEventListener("appinstalled",x),()=>{h(),window.removeEventListener("beforeinstallprompt",p),window.removeEventListener("appinstalled",x)}},l=[e],t[3]=e,t[4]=c,t[5]=l):(c=t[4],l=t[5]),a.useEffect(c,l)},aC=({open:t,onOpenChange:e})=>{const{t:n}=ft(),r=!1,[o,i]=a.useState(null),[c,l]=a.useState(null),[d,u]=a.useState(!1),[h,f]=a.useState(!1),[p,x]=a.useState(null),[b,S]=a.useState(!1);a.useCallback(async()=>{},[p,d,r,n]),a.useEffect(()=>{if(!t)return;(async()=>{try{const y=await hs("/api/system/info");if(y.ok){const C=await y.json();if(typeof C.openchamberVersion=="string"&&C.openchamberVersion.trim()){i(C.openchamberVersion);return}}}catch{}i(await zg())})()},[t]),a.useEffect(()=>{if(!t)return;let m=!1;return(async()=>{try{const C=await hs("/api/opencode/upgrade-status",{headers:{Accept:"application/json"}});if(!C.ok)return;const j=await C.json().catch(()=>null),w=typeof j?.currentVersion=="string"?j.currentVersion.trim():"";!m&&w&&l(w)}catch{}})(),()=>{m=!0}},[t]),a.useEffect(()=>{{x(null),S(!1);return}},[t,r]);const g=o;return s.jsx(Ts,{open:t,onOpenChange:e,children:s.jsx(Es,{className:"max-w-xs p-6",children:s.jsxs("div",{className:"flex flex-col items-center text-center space-y-4",children:[s.jsx(Gl,{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")})]})})})},cl=(t,e)=>{const n=t.get(e);return typeof n!="string"?null:n.trim()||null},lC=(t,e)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?"Authorization session expired or was cleared during reload. Return to OpenChamber and click Authorize again.":n},cC=()=>{const t=Sx(i=>i.completeAuth),[e,n]=a.useState("working"),[r,o]=a.useState("Completing MCP authorization...");return a.useEffect(()=>{if(typeof window>"u"){n("error"),o("Browser context unavailable.");return}const i=new URLSearchParams(window.location.search),c=cl(i,"code"),l=kx(i),d=Nx(i),u=cl(i,"error"),h=cl(i,"error_description");if(u){d&&hs(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),o(h??u);return}(async()=>{try{if(!c)throw new Error("Missing OAuth authorization code. Start authorization again from MCP Settings or paste the returned code into OpenChamber manually.");let f=l;if(!f&&d){const p=await hs(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`);if(p.ok){const x=await p.json().catch(()=>null);x?.name?.trim()&&(f={name:x.name.trim(),directory:typeof x.directory=="string"&&x.directory.trim()?x.directory.trim():null})}}if(!f?.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(f.name,c,f.directory),d&&await hs(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("success"),o("Authorization completed. You can close this tab and return to OpenChamber.")}catch(f){d&&await hs(`/api/mcp/auth/pending?state=${encodeURIComponent(d)}`,{method:"DELETE"}).catch(()=>{}),n("error"),o(lC(f,"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:Cx,children:e==="working"?"Completing Authorization":e==="success"?"Authorization Complete":"Authorization Failed"}),s.jsx("p",{className:De("typography-body",e==="error"?"text-[var(--status-error)]":e==="success"?"text-[var(--status-success)]":"text-[var(--status-info)]"),children:r})]}),e!=="working"&&s.jsx("div",{className:"mt-8 flex justify-center",children:s.jsx(He,{type:"button",onClick:()=>{typeof window>"u"||window.location.replace("/")},children:"Return to OpenChamber"})})]})})},zu=Da(()=>Oo(()=>import("./OnboardingScreen-D81UrlA4.js"),__vite__mapDeps([119,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])).then(t=>({default:t.OnboardingScreen}))),dC=()=>{const t=nt.c(3),e=Re(gC),n=Re(xC);let r;return t[0]!==e||t[1]!==n?(r=s.jsx(aC,{open:e,onOpenChange:n}),t[0]=e,t[1]=n,t[2]=r):r=t[2],r},uC=t=>{const e=nt.c(21),{onRetry:n,isRetrying:r}=t,{t:o}=ft();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 l;e[4]!==o?(l=o("startup.initRecovery.description"),e[4]=o,e[5]=l):l=e[5];let d;e[6]!==l?(d=s.jsx("p",{className:"typography-body text-muted-foreground",children:l}),e[6]=l,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 h;e[11]!==r||e[12]!==o?(h=o(r?"startup.initRecovery.retrying":"startup.initRecovery.retry"),e[11]=r,e[12]=o,e[13]=h):h=e[13];let f;e[14]!==r||e[15]!==n||e[16]!==h?(f=s.jsx(He,{type:"button",onClick:n,disabled:r,children:h}),e[14]=r,e[15]=n,e[16]=h,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},Vu=t=>t?t.replace(/\\/g,"/").replace(/\/+$/g,""):"",fC=()=>{if(typeof window>"u"||!zx())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"}},mC=()=>typeof window>"u"?!1:window.location.pathname===Ix,hC=t=>{const e=nt.c(23),{embeddedSessionChat:n,isVSCodeRuntime:r,embeddedBackgroundWorkEnabled:o}=t,i=js(bC),c=et(yC),l=et(wC),d=pa(),u=a.useRef(null);let h;e[0]!==n.directory?(h=Vu(n.directory),e[0]=n.directory,e[1]=h):h=e[1];const f=h;let p;e[2]!==i?(p=Vu(i),e[2]=i,e[3]=p):p=e[3];const x=p;let b,S;if(e[4]!==x||e[5]!==c||e[6]!==n.directory||e[7]!==n.sessionId||e[8]!==f||e[9]!==r||e[10]!==l||e[11]!==d?(b=()=>{if(r||f&&x!==f)return;const w=`${f}
209
- ${n.sessionId}`;u.current===w&&c||(u.current=w,l(n.sessionId,n.directory),d.ensureSessionRenderable(n.sessionId,!0))},S=[x,c,n.directory,n.sessionId,f,r,l,d],e[4]=x,e[5]=c,e[6]=n.directory,e[7]=n.sessionId,e[8]=f,e[9]=r,e[10]=l,e[11]=d,e[12]=b,e[13]=S):(b=e[12],S=e[13]),a.useEffect(b,S),f&&x!==f)return null;let g;e[14]!==o?(g=s.jsx(vf,{embeddedBackgroundWorkEnabled:o}),e[14]=o,e[15]=g):g=e[15];let m;e[16]===Symbol.for("react.memo_cache_sentinel")?(m=s.jsx(Of,{}),e[16]=m):m=e[16];let y;e[17]!==n.readOnly?(y=s.jsx(xl,{readOnly:n.readOnly}),e[17]=n.readOnly,e[18]=y):y=e[18];let C;e[19]===Symbol.for("react.memo_cache_sentinel")?(C=s.jsx(jf,{}),e[19]=C):C=e[19];let j;return e[20]!==g||e[21]!==y?(j=s.jsxs(s.Fragment,{children:[g,m,y,C]}),e[20]=g,e[21]=y,e[22]=j):j=e[22],j};function pC({apis:t}){a.useEffect(()=>{Ph("App:mounted"),Ih()&&console.info("[startup-trace] enabled. Run console.table(window.__OPENCHAMBER_STARTUP_TRACE__) after startup.")},[]);const e=ts(V=>V.initializeApp),n=ts(V=>V.isInitialized),r=ts(V=>V.isConnected),o=ts(V=>V.providers.length),i=ts(V=>V.agents.length),c=ts(V=>V.loadProviders),l=ts(V=>V.loadAgents),d=et(V=>V.error),u=et(V=>V.clearError),h=js(V=>V.currentDirectory),f=js(V=>V.setDirectory),p=js(V=>V.isSwitchingDirectory),[x,b]=a.useState(!1),S=Dr(V=>V.refreshStatus),[g,m]=a.useState(()=>t.runtime.isVSCode),[y,C]=a.useState(!0),[j,w]=a.useState(!1),[N,v]=a.useState(0),[P,F]=a.useState(0),[k,E]=a.useState(!1),O=Re(V=>V.wideChatLayoutEnabled),M=Re(V=>V.mobileKeyboardMode),L=a.useMemo(()=>hr(),[]),_=_l(V=>V.setPlanModeEnabled),[D,A]=a.useState(()=>Nc()),[T,z]=a.useState(()=>{const V=Cc();return V!==null?Ac({isDesktopShell:!0,bootOutcome:V}):null}),R=a.useRef(!1),W=a.useMemo(()=>fC(),[]),J=!W||y,U=a.useMemo(()=>mC(),[]);a.useEffect(()=>(Dc(x),()=>{Dc(!1)}),[x]),a.useEffect(()=>{Rh(M)},[M]),a.useEffect(()=>{m(t.runtime.isVSCode)},[t.runtime.isVSCode]),a.useEffect(()=>Yu(V=>{Ax(V),F(Q=>Q+1),w(!1),v(Q=>Q+1)}),[]);const te=zc(V=>{const Q=$n();return Object.values(V.runsByOriginalSessionID).filter(ne=>ne.status==="running"&&ne.runtimeKey===Q).map(ne=>`${ne.originalSessionID}:${ne.phase}:${ne.lastForwardedMessageID??""}:${ne.expectedAssistantParentID??""}`).sort().join("|")});a.useEffect(()=>{if(W)return;const V=$n(),Q=Object.values(zc.getState().runsByOriginalSessionID).filter(ne=>ne.status==="running"&&ne.runtimeKey===V);for(const ne of Q)Vg(ne.originalSessionID)},[te,W,P]),a.useEffect(()=>(document.documentElement.classList.toggle("wide-chat-layout",O),()=>{document.documentElement.classList.remove("wide-chat-layout")}),[O]),a.useEffect(()=>(Pc(t),()=>Pc(null)),[t]),a.useEffect(()=>{W||S(t.github,{force:!0})},[t.github,W,S]),Wg();const Z=D==="valid",ue=T?.screen==="main";a.useEffect(()=>{if(!Mh({isDesktopShell:L,isInitialized:n,bootOutcomeKnown:Z,bootViewIsMain:ue}))return;const V=setTimeout(()=>{const Q=document.getElementById("initial-loading");Q&&(Q.classList.add("fade-out"),setTimeout(()=>{Q.remove()},300))},150);return()=>clearTimeout(V)},[L,n,Z,ue]),a.useEffect(()=>{if(!L||D!=="malformed")return;const V=document.getElementById("initial-loading");V&&(V.textContent="Desktop startup failed — please restart the app.")},[L,D]),a.useEffect(()=>{if(L)return;const V=setTimeout(()=>{const Q=document.getElementById("initial-loading");Q&&!n&&(Q.classList.add("fade-out"),setTimeout(()=>{Q.remove()},300))},5e3);return()=>clearTimeout(V)},[L,n]),a.useEffect(()=>{let V=!1;return(async()=>{const ne=await hs("/health",{method:"GET"}).catch(()=>null);if(!ne||!ne.ok||V)return;const oe=await ne.json().catch(()=>null);if(!oe||V)return;const ce=oe.planModeExperimentalEnabled;_(ce===!0||ce===1||ce==="1"||ce==="true")})(),()=>{V=!0}},[_]),a.useEffect(()=>{g||e()},[e,g]),a.useEffect(()=>{if(g||n)return;let V=!0,Q,ne=0;const oe=10,ce=1e3,ke=async()=>{if(!V)return;if(ne>=oe){w(!0);return}const ye=ts.getState();if(ye.isInitialized){w(!1);return}ne+=1,await ye.initializeApp();const he=ts.getState();if(!V)return;if(he.isInitialized){w(!1);return}if(ne>=oe){w(!0);return}const Ee=Math.min(ce*Math.pow(2,ne-1),16e3);Q=setTimeout(ke,Ee)};return Q=setTimeout(ke,ce),()=>{V=!1,Q&&clearTimeout(Q)}},[N,n,g]),a.useEffect(()=>{n&&w(!1)},[n]),a.useEffect(()=>{if(!j)return;const V=document.getElementById("initial-loading");V&&(V.classList.add("fade-out"),setTimeout(()=>{V.remove()},300))},[j]),a.useEffect(()=>{if(g||!r||o>0&&i>0)return;let V=!0,Q=0;const ne=15,oe=async()=>{const ke=ts.getState();if(!(ke.providers.length>0&&ke.agents.length>0))try{ke.providers.length===0&&await c({source:"startupRecovery"}),ts.getState().agents.length===0&&await l({source:"startupRecovery"})}catch{}};oe();const ce=setInterval(()=>{if(V){if(++Q>=ne){clearInterval(ce);return}oe()}},2e3);return()=>{V=!1,clearInterval(ce)}},[r,g,l,c,o,i]),a.useEffect(()=>{p||g||r&&Fn.setDirectory(h)},[h,p,r,g]),a.useEffect(()=>{if(!W||typeof window>"u")return;const V=oe=>{const ce=oe?.visible===!0;C(ce)},Q=oe=>{if(oe.origin!==window.location.origin)return;const ce=oe.data;ce?.type==="openchamber:embedded-visibility"&&V(ce.payload)},ne=window;return ne.__openchamberSetEmbeddedVisibility=V,window.addEventListener("message",Q),()=>{window.removeEventListener("message",Q),ne.__openchamberSetEmbeddedVisibility===V&&delete ne.__openchamberSetEmbeddedVisibility}},[W]),a.useEffect(()=>{!W?.directory||g||h!==W.directory&&f(W.directory,{showOverlay:!1})},[h,W,g,f]),a.useEffect(()=>{if(!W||typeof window>"u")return;const V=Q=>{Q.storageArea===window.localStorage&&Q.key==="ui-store"&&Re.persist.rehydrate()};return window.addEventListener("storage",V),()=>{window.removeEventListener("storage",V)}},[W]),a.useEffect(()=>{if(typeof window>"u")return;const V=Q=>{const ne=Q.detail,oe=typeof ne?.sessionId=="string"?ne.sessionId.trim():"";if(!oe)return;const ce=typeof ne?.directory=="string"&&ne.directory.trim().length>0?ne.directory.trim():null;Re.getState().setActiveMainTab("chat"),et.getState().setCurrentSession(oe,ce)};return window.addEventListener("openchamber:open-session",V),()=>window.removeEventListener("openchamber:open-session",V)},[]),a.useEffect(()=>{if(typeof window>"u")return;const V=()=>{const Q=js.getState().currentDirectory,{activeProjectId:ne,projects:oe}=ms.getState(),ce=oe.find(ke=>ke.id===ne)??null;Ar("desktop_open_draft_mini_chat_window",{directory:Q||ce?.path||"",projectId:ce?.id??null})};return window.addEventListener("openchamber:open-mini-chat",V),()=>window.removeEventListener("openchamber:open-mini-chat",V)},[]),a.useEffect(()=>{if(typeof window>"u")return;const V=()=>{const Q=et.getState().currentSessionId;Q&&af(Q)};return window.addEventListener("focus",V),()=>window.removeEventListener("focus",V)},[]),a.useEffect(()=>{if(typeof window>"u")return;const V=Q=>{const ne=Q.detail,oe=typeof ne?.directory=="string"&&ne.directory.trim().length>0?ne.directory.trim():null,ce=typeof ne?.projectId=="string"&&ne.projectId.trim().length>0?ne.projectId.trim():null;Re.getState().setActiveMainTab("chat"),Re.getState().setSessionSwitcherOpen(!1),et.getState().openNewSessionDraft({selectedProjectId:ce,directoryOverride:oe,preserveDirectoryOverride:!!oe})};return window.addEventListener("openchamber:open-draft-session",V),()=>window.removeEventListener("openchamber:open-draft-session",V)},[]),a.useEffect(()=>{typeof window>"u"||!n||p||R.current||(R.current=!0,window.__openchamberAppReady=!0,window.dispatchEvent(new Event("openchamber:app-ready")))},[n,p]),Ug({enabled:J}),rC({enabled:J}),iC(),Hg(),Dx();const Oe=a.useCallback(()=>{b(V=>!V)},[]);zN(Oe),eC(),a.useEffect(()=>{if(W)return;const V=Q=>{nf(Q)&&Q.shiftKey&&!Q.altKey&&(Q.code==="KeyD"||Q.key.toLowerCase()==="d")&&(Q.preventDefault(),b(oe=>!oe))};return window.addEventListener("keydown",V,!0),()=>window.removeEventListener("keydown",V,!0)},[W]),a.useEffect(()=>{W||d&&setTimeout(()=>u(),5e3)},[u,W,d]),a.useEffect(()=>{if(!L||D!=="not-injected")return;let V=!1,Q=0;const ne=200,oe=2e3,ce=50,ke=()=>{if(V)return;Q++;const ye=Nc();if(ye!=="not-injected"){if(V=!0,A(ye),ye==="valid"){const Ee=Cc();Ee&&z(Ac({isDesktopShell:!0,bootOutcome:Ee}))}return}const he=Math.min(ne*Math.pow(1.1,Q),oe);if(Q>=ce){const Ee=document.getElementById("initial-loading");Ee&&!Ee.textContent?.includes("taking longer")&&(Ee.textContent="Desktop startup is taking longer than expected...")}window.setTimeout(ke,he)};return window.setTimeout(ke,ne),()=>{V=!0}},[L,D]);const se=a.useCallback(async()=>{if(Th({isDesktopShell:hr(),isDesktopLocalOriginActive:ua()})){await Eh();return}window.location.reload()},[]),G=a.useCallback(async()=>{if(!k){w(!1),E(!0);try{await ts.getState().initializeApp()}finally{E(!1)}ts.getState().isInitialized||v(V=>V+1)}},[k]),Ie=V=>{if(V.screen==="recovery")return V.variant};if(L&&T&&T.screen!=="main"){if(T.screen==="chooser")return s.jsx(Cs,{children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(a.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(zu,{mode:"first-launch",localAvailable:T.localAvailable!==!1,onCliAvailable:se,onChooseRemote:()=>{}})})})});const V=Ie(T),Q=T.screen==="recovery"&&"url"in T?T.url:void 0;return s.jsx(Cs,{children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(a.Suspense,{fallback:s.jsx("div",{className:"h-full"}),children:s.jsx(zu,{mode:"recovery",recoveryVariant:V,recoveryHostUrl:Q,recoveryHostLabel:void 0,localAvailable:T.localAvailable!==!1,onCliAvailable:se})})})})}if(W)return s.jsx(Cs,{children:s.jsx(Vc,{sdk:Fn.getSdkClient(),directory:h||"",children:s.jsx(Wc,{apis:t,children:s.jsx(pl,{delayDuration:300,skipDelayDuration:150,children:s.jsx("div",{className:"h-full text-foreground bg-background",children:s.jsx(hC,{embeddedSessionChat:W,isVSCodeRuntime:g,embeddedBackgroundWorkEnabled:J})})})})},P)});if(U)return s.jsx(Cs,{children:s.jsx(cC,{})});if(j&&!n&&!g&&!W)return s.jsx(Cs,{children:s.jsx(uC,{onRetry:()=>{G()},isRetrying:k})});const pe=!n&&!L;return s.jsx(Cs,{children:s.jsx(Vc,{sdk:Fn.getSdkClient(),directory:h||"",children:s.jsx(Wc,{apis:t,children:s.jsx(zy,{children:s.jsx(pl,{delayDuration:300,skipDelayDuration:150,children:s.jsxs("div",{className:L?"h-full text-foreground bg-transparent":"h-full text-foreground bg-background",children:[s.jsx(vf,{embeddedBackgroundWorkEnabled:J}),s.jsx(Of,{}),s.jsx(NN,{}),s.jsx(jf,{}),!pe&&s.jsxs(s.Fragment,{children:[s.jsx(Px,{}),s.jsx(dC,{}),x&&s.jsx(DN,{onClose:()=>b(!1)})]})]})})})})},P)})}function gC(t){return t.isAboutDialogOpen}function xC(t){return t.setAboutDialogOpen}function bC(t){return t.currentDirectory}function yC(t){return t.currentSessionId}function wC(t){return t.setCurrentSession}const vC=typeof window<"u"&&window.__OPENCHAMBER_RUNTIME_APIS__||(()=>{throw new Error("Runtime APIs not provided for legacy UI entrypoint.")})();Kg();Fh().then(()=>{Promise.all([Oh(),Gg()]).catch(t=>{console.error("[main] settings init failed:",t)}),qg(),Yg(),Qg()}).catch(t=>{console.error("[main] appearance init failed:",t)});const Km=document.getElementById("root");if(!Km)throw new Error("Root element not found");gh.createRoot(Km).render(s.jsx($e.StrictMode,{children:s.jsx(Xg,{children:s.jsx(Jg,{children:s.jsx(Zg,{children:s.jsx(ex,{children:s.jsx(pC,{apis:vC})})})})})}));